/** * @file IxPiuMhSend.c * * @author Intel Corporation * @date 18 Jan 2002 * * @description Contents are the implementation of the private API for * the Send module. * * * @par * This file is provided under a dual BSD/GPLv2 license. When using or * redistributing this file, you may do so under either license. * * GPL LICENSE SUMMARY * * Copyright(c) 2007,2008,2009 Intel Corporation. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. * The full GNU General Public License is included in this distribution * in the file called LICENSE.GPL. * * Contact Information: * Intel Corporation * * BSD LICENSE * * Copyright(c) 2007,2008,2009 Intel Corporation. All rights reserved. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * Neither the name of Intel Corporation nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * * */ /* * Put the system defined include files required. */ /* * Put the user defined include files required. */ #include "IxPiuMhMacros_p.h" #include "IxPiuMhConfig_p.h" #include "IxPiuMhSend_p.h" #include "IxPiuMhSolicitedCbMgr_p.h" /* * #defines and macros used in this file. */ /** * @def IX_PIUMH_INFIFO_RETRY_DELAY_US * * @brief Amount of time (uSecs) to delay between retries * while inFIFO is Full when attempting to send a message */ #define IX_PIUMH_INFIFO_RETRY_DELAY_US (1) /* * Typedefs whose scope is limited to this file. */ /** * @struct IxPiuMhSendStats * * @brief This structure is used to maintain statistics for the Send * module. */ typedef struct { UINT32 sends; /**< send invocations */ UINT32 sendWithResponses; /**< send with response invocations */ UINT32 queueFulls; /**< fifo queue full occurrences */ UINT32 queueFullRetries; /**< fifo queue full retry occurrences */ UINT32 maxQueueFullRetries; /**< max fifo queue full retries */ UINT32 callbackFulls; /**< callback list full occurrences */ } IxPiuMhSendStats; /* * Variable declarations global to this file only. Externs are followed by * static variables. */ PRIVATE IxPiuMhSendStats ixPiuMhSendStats[IX_PIUMH_NUM_PIUS]; /* * Extern function prototypes. */ /* * Static function prototypes. */ PRIVATE BOOL ixPiuMhSendInFifoIsFull( IxPiuMhPiuId piuId, UINT32 maxSendRetries); /* * Function definition: ixPiuMhSendInFifoIsFull */ PRIVATE BOOL ixPiuMhSendInFifoIsFull( IxPiuMhPiuId piuId, UINT32 maxSendRetries) { BOOL isFull = FALSE; UINT32 numRetries = 0; /* check the PIU's inFIFO */ isFull = ixPiuMhConfigInFifoIsFull (piuId); /* we retry a few times, just to give the PIU a chance to read from */ /* the FIFO if the FIFO is currently full */ while (isFull && (numRetries < maxSendRetries)) { numRetries++; if (numRetries >= IX_PIUMH_SEND_RETRIES_DEFAULT) { /* Delay here for as short a time as possible (1 us). */ /* Adding a delay here should ensure we are not hogging */ /* the AHB bus while we are retrying */ ixOsalBusySleep (IX_PIUMH_INFIFO_RETRY_DELAY_US); } /* re-check the PIU's inFIFO */ isFull = ixPiuMhConfigInFifoIsFull (piuId); /* update statistical info */ ixPiuMhSendStats[piuId].queueFullRetries++; } /* record the highest number of retries that occurred */ if (ixPiuMhSendStats[piuId].maxQueueFullRetries < numRetries) { ixPiuMhSendStats[piuId].maxQueueFullRetries = numRetries; } if (isFull) { /* update statistical info */ ixPiuMhSendStats[piuId].queueFulls++; } return isFull; } /* * Function definition: ixPiuMhSendMessageSend */ IX_STATUS ixPiuMhSendMessageSend ( IxPiuMhPiuId piuId, IxPiuMhMessage message, UINT32 maxSendRetries) { IX_STATUS status; IX_PIUMH_TRACE0 (IX_PIUMH_FN_ENTRY_EXIT, "Entering " "ixPiuMhSendMessageSend\n"); /* update statistical info */ ixPiuMhSendStats[piuId].sends++; /* check if the PIU's inFIFO is full - if so return an error */ if (ixPiuMhSendInFifoIsFull (piuId, maxSendRetries)) { IX_PIUMH_TRACE0 (IX_PIUMH_WARNING, "PIU's inFIFO is full\n"); return IX_FAIL; } /* write the message to the PIU's inFIFO */ status = ixPiuMhConfigInFifoWrite (piuId, message); IX_PIUMH_TRACE0 (IX_PIUMH_FN_ENTRY_EXIT, "Exiting " "ixPiuMhSendMessageSend\n"); return status; } /* * Function definition: ixPiuMhSendMessageWithResponseSend */ IX_STATUS ixPiuMhSendMessageWithResponseSend ( IxPiuMhPiuId piuId, IxPiuMhMessage message, IxPiuMhMessageId solicitedMessageId, IxPiuMhCallback solicitedCallback, UINT32 maxSendRetries) { IX_STATUS status = IX_SUCCESS; IX_PIUMH_TRACE0 (IX_PIUMH_FN_ENTRY_EXIT, "Entering " "ixPiuMhSendMessageWithResponseSend\n"); /* update statistical info */ ixPiuMhSendStats[piuId].sendWithResponses++; /* check if the PIU's inFIFO is full - if so return an error */ if (ixPiuMhSendInFifoIsFull (piuId, maxSendRetries)) { IX_PIUMH_TRACE0 (IX_PIUMH_WARNING, "PIU's inFIFO is full\n"); return IX_FAIL; } /* save the solicited callback */ status = ixPiuMhSolicitedCbMgrCallbackSave ( piuId, solicitedMessageId, solicitedCallback); if (status != IX_SUCCESS) { IX_PIUMH_ERROR_REPORT ("Failed to save solicited callback\n"); /* update statistical info */ ixPiuMhSendStats[piuId].callbackFulls++; return status; } /* write the message to the PIU's inFIFO */ status = ixPiuMhConfigInFifoWrite (piuId, message); IX_PIUMH_TRACE0 (IX_PIUMH_FN_ENTRY_EXIT, "Exiting " "ixPiuMhSendMessageWithResponseSend\n"); return status; } /* * Function definition: ixPiuMhSendShow */ void ixPiuMhSendShow ( IxPiuMhPiuId piuId) { /* show the message send invocation counter */ IX_PIUMH_SHOW ("Send invocations", ixPiuMhSendStats[piuId].sends); /* show the message send with response invocation counter */ IX_PIUMH_SHOW ("Send with response invocations", ixPiuMhSendStats[piuId].sendWithResponses); /* show the fifo queue full occurrence counter */ IX_PIUMH_SHOW ("Fifo queue full occurrences", ixPiuMhSendStats[piuId].queueFulls); /* show the fifo queue full retry occurrence counter */ IX_PIUMH_SHOW ("Fifo queue full retry occurrences", ixPiuMhSendStats[piuId].queueFullRetries); /* show the fifo queue full maximum retries counter */ IX_PIUMH_SHOW ("Maximum fifo queue full retries", ixPiuMhSendStats[piuId].maxQueueFullRetries); /* show the callback list full occurrence counter */ IX_PIUMH_SHOW ("Solicited callback list full occurrences", ixPiuMhSendStats[piuId].callbackFulls); } /* * Function definition: ixPiuMhSendShowReset */ void ixPiuMhSendShowReset ( IxPiuMhPiuId piuId) { /* reset the message send invocation counter */ ixPiuMhSendStats[piuId].sends = 0; /* reset the message send with response invocation counter */ ixPiuMhSendStats[piuId].sendWithResponses = 0; /* reset the fifo queue full occurrence counter */ ixPiuMhSendStats[piuId].queueFulls = 0; /* reset the fifo queue full retry occurrence counter */ ixPiuMhSendStats[piuId].queueFullRetries = 0; /* reset the max fifo queue full retries counter */ ixPiuMhSendStats[piuId].maxQueueFullRetries = 0; /* reset the callback list full occurrence counter */ ixPiuMhSendStats[piuId].callbackFulls = 0; }