1 /*******************************************************************************
3 *Copyright (c) 2014 PMC-Sierra, Inc. All rights reserved.
5 *Redistribution and use in source and binary forms, with or without modification, are permitted provided
6 *that the following conditions are met:
7 *1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
9 *2. Redistributions in binary form must reproduce the above copyright notice,
10 *this list of conditions and the following disclaimer in the documentation and/or other materials provided
11 *with the distribution.
13 *THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED
14 *WARRANTIES,INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
15 *FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
16 *FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
17 *NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
18 *BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
19 *LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
20 *SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
22 ********************************************************************************/
24 /*******************************************************************************/
26 * \brief The file is a MPI Libraries to implement the MPI functions
28 * The file implements the MPI Library functions.
31 /*******************************************************************************/
32 #include <sys/cdefs.h>
33 __FBSDID("$FreeBSD$");
34 #include <dev/pms/config.h>
36 #include <dev/pms/RefTisa/sallsdk/spc/saglobal.h>
38 #ifdef SA_ENABLE_TRACE_FUNCTIONS
42 #define siTraceFileID 'A'
48 /*******************************************************************************/
50 /*******************************************************************************/
51 /*******************************************************************************/
53 /*******************************************************************************/
54 /*******************************************************************************/
55 /** \fn void mpiRequirementsGet(mpiConfig_t* config, mpiMemReq_t* memoryRequirement)
56 * \brief Retrieves the MPI layer resource requirements
57 * \param config MPI configuration for the Host MPI Message Unit
58 * \param memoryRequirement Returned data structure as defined by mpiMemReq_t
59 * that holds the different chunks of memory that are required
61 * The mpiRequirementsGet() function is used to determine the resource requirements
62 * for the SPC device interface
66 /*******************************************************************************/
67 void mpiRequirementsGet(mpiConfig_t* config, mpiMemReq_t* memoryRequirement)
70 mpiMemReq_t* memoryMap;
71 SA_DBG2(("Entering function:mpiRequirementsGet\n"));
72 SA_ASSERT((NULL != config), "config argument cannot be null");
74 memoryMap = memoryRequirement;
77 /* MPI Memory region 0 for MSGU(AAP1) Event Log for fw */
78 memoryMap->region[memoryMap->count].numElements = 1;
79 memoryMap->region[memoryMap->count].elementSize = sizeof(bit8) * config->mainConfig.eventLogSize;
80 memoryMap->region[memoryMap->count].totalLength = sizeof(bit8) * config->mainConfig.eventLogSize;
81 memoryMap->region[memoryMap->count].alignment = 32;
82 memoryMap->region[memoryMap->count].type = AGSA_DMA_MEM;
83 SA_DBG2(("mpiRequirementsGet:eventLogSize region[%d] 0x%X\n",memoryMap->count,memoryMap->region[memoryMap->count].totalLength ));
86 SA_DBG2(("mpiRequirementsGet:eventLogSize region[%d] 0x%X\n",memoryMap->count,memoryMap->region[memoryMap->count].totalLength ));
87 /* MPI Memory region 1 for IOP Event Log for fw */
88 memoryMap->region[memoryMap->count].numElements = 1;
89 memoryMap->region[memoryMap->count].elementSize = sizeof(bit8) * config->mainConfig.IOPeventLogSize;
90 memoryMap->region[memoryMap->count].totalLength = sizeof(bit8) * config->mainConfig.IOPeventLogSize;
91 memoryMap->region[memoryMap->count].alignment = 32;
92 memoryMap->region[memoryMap->count].type = AGSA_DMA_MEM;
93 SA_DBG2(("mpiRequirementsGet:IOPeventLogSize region[%d] 0x%X\n",memoryMap->count,memoryMap->region[memoryMap->count].totalLength ));
96 /* MPI Memory region 2 for consumer Index of inbound queues */
97 memoryMap->region[memoryMap->count].numElements = 1;
98 memoryMap->region[memoryMap->count].elementSize = sizeof(bit32) * config->numInboundQueues;
99 memoryMap->region[memoryMap->count].totalLength = sizeof(bit32) * config->numInboundQueues;
100 memoryMap->region[memoryMap->count].alignment = 4;
101 memoryMap->region[memoryMap->count].type = AGSA_DMA_MEM;
102 SA_DBG2(("mpiRequirementsGet:numInboundQueues region[%d] 0x%X\n",memoryMap->count,memoryMap->region[memoryMap->count].totalLength ));
105 /* MPI Memory region 3 for producer Index of outbound queues */
106 memoryMap->region[memoryMap->count].numElements = 1;
107 memoryMap->region[memoryMap->count].elementSize = sizeof(bit32) * config->numOutboundQueues;
108 memoryMap->region[memoryMap->count].totalLength = sizeof(bit32) * config->numOutboundQueues;
109 memoryMap->region[memoryMap->count].alignment = 4;
110 memoryMap->region[memoryMap->count].type = AGSA_DMA_MEM;
111 SA_DBG2(("mpiRequirementsGet:numOutboundQueues region[%d] 0x%X\n",memoryMap->count,memoryMap->region[memoryMap->count].totalLength ));
114 /* MPI Memory regions 4, ... for the inbound queues - depends on configuration */
116 for(qIdx = 0; qIdx < config->numInboundQueues; qIdx++)
118 if(0 != config->inboundQueues[qIdx].numElements)
120 bit32 memSize = config->inboundQueues[qIdx].numElements * config->inboundQueues[qIdx].elementSize;
121 bit32 remainder = memSize & 127;
123 /* Calculate the size of this queue padded to 128 bytes */
126 memSize += (128 - remainder);
131 memoryMap->region[memoryMap->count].numElements = 1;
132 memoryMap->region[memoryMap->count].elementSize = memSize;
133 memoryMap->region[memoryMap->count].totalLength = memSize;
134 memoryMap->region[memoryMap->count].alignment = 128;
135 memoryMap->region[memoryMap->count].type = AGSA_CACHED_DMA_MEM;
139 memoryMap->region[memoryMap->count].elementSize += memSize;
140 memoryMap->region[memoryMap->count].totalLength += memSize;
145 if ((0 == ((qIdx + 1) % MAX_QUEUE_EACH_MEM)) ||
146 (qIdx == (bit32)(config->numInboundQueues - 1)))
148 SA_DBG2(("mpiRequirementsGet: (inboundQueues) memoryMap->region[%d].elementSize = %d\n",
149 memoryMap->count, memoryMap->region[memoryMap->count].elementSize));
150 SA_DBG2(("mpiRequirementsGet: (inboundQueues) memoryMap->region[%d].numElements = %d\n",
151 memoryMap->count, memoryMap->region[memoryMap->count].numElements));
159 /* MPI Memory regions for the outbound queues - depends on configuration */
161 for(qIdx = 0; qIdx < config->numOutboundQueues; qIdx++)
163 if(0 != config->outboundQueues[qIdx].numElements)
165 bit32 memSize = config->outboundQueues[qIdx].numElements * config->outboundQueues[qIdx].elementSize;
166 bit32 remainder = memSize & 127;
168 /* Calculate the size of this queue padded to 128 bytes */
171 memSize += (128 - remainder);
176 memoryMap->region[memoryMap->count].numElements = 1;
177 memoryMap->region[memoryMap->count].elementSize = memSize;
178 memoryMap->region[memoryMap->count].totalLength = memSize;
179 memoryMap->region[memoryMap->count].alignment = 128;
180 memoryMap->region[memoryMap->count].type = AGSA_CACHED_DMA_MEM;
184 memoryMap->region[memoryMap->count].elementSize += memSize;
185 memoryMap->region[memoryMap->count].totalLength += memSize;
190 if ((0 == ((qIdx + 1) % MAX_QUEUE_EACH_MEM)) ||
191 (qIdx == (bit32)(config->numOutboundQueues - 1)))
193 SA_DBG2(("mpiRequirementsGet: (outboundQueues) memoryMap->region[%d].elementSize = %d\n",
194 memoryMap->count, memoryMap->region[memoryMap->count].elementSize));
195 SA_DBG2(("mpiRequirementsGet: (outboundQueues) memoryMap->region[%d].numElements = %d\n",
196 memoryMap->count, memoryMap->region[memoryMap->count].numElements));
207 /*******************************************************************************/
208 /** \fn mpiMsgFreeGet(mpiICQueue_t *circularQ, bit16 messageSize, void** messagePtr)
209 * \brief Retrieves a free message buffer from an inbound queue
210 * \param circularQ Pointer to an inbound circular queue
211 * \param messageSize Requested message size in bytes - only support 64 bytes/element
212 * \param messagePtr Pointer to the free message buffer payload (not including message header) or NULL if no free message buffers are available
214 * This function is used to retrieve a free message buffer for the given inbound queue of at least
216 * The caller can use the returned buffer to construct the message and then call mpiMsgProduce()
217 * to deliver the message to the device message unit or mpiMsgInvalidate() if the message buffer
218 * is not going to be used
221 * AGSA_RC_SUCCESS if messagePtr contains a valid message buffer pointer
222 * AGSA_RC_FAILURE if messageSize larger than the elementSize of queue
223 * AGSA_RC_BUSY if there are not free message buffers (Queue full)
225 /*******************************************************************************/
229 mpiICQueue_t *circularQ,
235 agsaRoot_t *agRoot=circularQ->agRoot;
236 mpiMsgHeader_t *msgHeader;
237 bit8 bcCount = 1; /* only support single buffer */
239 SA_DBG4(("Entering function:mpiMsgFreeGet\n"));
240 SA_ASSERT(NULL != circularQ, "circularQ cannot be null");
241 SA_ASSERT(NULL != messagePtr, "messagePtr argument cannot be null");
242 SA_ASSERT(0 != circularQ->numElements, "The number of elements in this queue is 0");
244 /* Checks is the requested message size can be allocated in this queue */
245 if(messageSize > circularQ->elementSize)
247 SA_DBG1(("mpiMsgFreeGet: Message Size (%d) is larger than Q element size (%d)\n",messageSize,circularQ->elementSize));
248 return AGSA_RC_FAILURE;
251 /* Stores the new consumer index */
252 OSSA_READ_LE_32(circularQ->agRoot, &circularQ->consumerIdx, circularQ->ciPointer, 0);
253 /* if inbound queue is full, return busy */
254 /* This queue full logic may only works for bc == 1 ( == ) */
255 /* ( pi + bc ) % size > ci not fully works for bc > 1 */
256 /* To do - support bc > 1 case and wrap around case */
257 if (((circularQ->producerIdx + bcCount) % circularQ->numElements) == circularQ->consumerIdx)
260 smTrace(hpDBG_VERY_LOUD,"Za", (((circularQ->producerIdx & 0xFFF) << 16) | (circularQ->consumerIdx & 0xFFF) ));
262 ossaHwRegRead(agRoot, MSGU_HOST_SCRATCH_PAD_0);
263 SA_DBG1(("mpiMsgFreeGet: %d + %d == %d AGSA_RC_BUSY\n",circularQ->producerIdx,bcCount,circularQ->consumerIdx));
268 smTrace(hpDBG_VERY_LOUD,"Zb", (((circularQ->producerIdx & 0xFFF) << 16) | (circularQ->consumerIdx & 0xFFF) ));
272 /* get memory IOMB buffer address */
273 offset = circularQ->producerIdx * circularQ->elementSize;
274 /* increment to next bcCount element */
275 circularQ->producerIdx = (circularQ->producerIdx + bcCount) % circularQ->numElements;
277 /* Adds that distance to the base of the region virtual address plus the message header size*/
278 msgHeader = (mpiMsgHeader_t*) (((bit8 *)(circularQ->memoryRegion.virtPtr)) + offset);
280 SA_DBG3(("mpiMsgFreeGet: msgHeader = %p Offset = 0x%x\n", (void *)msgHeader, offset));
282 /* Sets the message buffer in "allocated" state */
283 /* bc always is 1 for inbound queue */
284 /* temporarily store it in the native endian format, when the rest of the */
285 /* header is filled, this would be converted to Little Endian */
286 msgHeader->Header = (1<<24);
287 *messagePtr = ((bit8*)msgHeader) + sizeof(mpiMsgHeader_t);
289 return AGSA_RC_SUCCESS;
293 GLOBAL bit32 mpiMsgFreeGetOQ(mpiOCQueue_t *circularQ, bit16 messageSize, void** messagePtr)
296 mpiMsgHeader_t *msgHeader;
297 bit8 bcCount = 1; /* only support single buffer */
299 SA_DBG4(("Entering function:mpiMsgFreeGet\n"));
300 SA_ASSERT(NULL != circularQ, "circularQ cannot be null");
301 SA_ASSERT(NULL != messagePtr, "messagePtr argument cannot be null");
302 SA_ASSERT(0 != circularQ->numElements, "The number of elements in this queue is 0");
304 /* Checks is the requested message size can be allocated in this queue */
305 if(messageSize > circularQ->elementSize)
307 SA_DBG1(("mpiMsgFreeGet: Message Size is not fit in\n"));
308 return AGSA_RC_FAILURE;
311 /* Stores the new consumer index */
312 //OSSA_READ_LE_32(circularQ->agRoot, &circularQ->consumerIdx, circularQ->ciPointer, 0);
313 /* if inbound queue is full, return busy */
314 /* This queue full logic may only works for bc == 1 ( == ) */
315 /* ( pi + bc ) % size > ci not fully works for bc > 1 */
316 /* To do - support bc > 1 case and wrap around case */
317 if (((circularQ->producerIdx + bcCount) % circularQ->numElements) == circularQ->consumerIdx)
323 /* get memory IOMB buffer address */
324 offset = circularQ->producerIdx * circularQ->elementSize;
325 /* increment to next bcCount element */
326 circularQ->producerIdx = (circularQ->producerIdx + bcCount) % circularQ->numElements;
328 /* Adds that distance to the base of the region virtual address plus the message header size*/
329 msgHeader = (mpiMsgHeader_t*) (((bit8 *)(circularQ->memoryRegion.virtPtr)) + offset);
331 SA_DBG3(("mpiMsgFreeGet: msgHeader = %p Offset = 0x%x\n", (void *)msgHeader, offset));
333 /* Sets the message buffer in "allocated" state */
334 /* bc always is 1 for inbound queue */
335 /* temporarily store it in the native endian format, when the rest of the */
336 /* header is filled, this would be converted to Little Endian */
337 msgHeader->Header = (1<<24);
338 *messagePtr = ((bit8*)msgHeader) + sizeof(mpiMsgHeader_t);
340 return AGSA_RC_SUCCESS;
344 /*******************************************************************************/
345 /** \fn mpiMsgProduce(mpiICQueue_t *circularQ, void *messagePtr, mpiMsgCategory_t category, bit16 opCode, bit8 responseQueue)
346 * \brief Add a header of IOMB then send to a inbound queue and update the Producer index
347 * \param circularQ Pointer to an inbound queue
348 * \param messagePtr Pointer to the message buffer payload (not including message header))
349 * \param category Message category (ETHERNET, FC, SAS-SATA, SCSI)
350 * \param opCode Message operation code
351 * \param responseQueue If the message requires response, this paramater indicates the outbound queue for the response
353 * This function is used to sumit a message buffer, previously obtained from mpiMsgFreeGet()
354 * function call, to the given Inbound queue
357 * AGSA_RC_SUCCESS if the message has been posted succesfully
359 /*******************************************************************************/
361 GLOBAL bit32 mpiMsgPrepare(
362 mpiICQueue_t *circularQ,
364 mpiMsgCategory_t category,
370 mpiMsgHeader_t *msgHeader;
375 SA_DBG4(("Entering function:mpiMsgProduce\n"));
376 SA_ASSERT(NULL != circularQ, "circularQ argument cannot be null");
377 SA_ASSERT(NULL != messagePtr, "messagePtr argument cannot be null");
378 SA_ASSERT(0 != circularQ->numElements, "The number of elements in this queue"
380 SA_ASSERT(MPI_MAX_OUTBOUND_QUEUES > responseQueue, "oQueue ID is wrong");
382 /* Obtains the address of the entire message buffer, including the header */
383 msgHeader = (mpiMsgHeader_t*)(((bit8*)messagePtr) - sizeof(mpiMsgHeader_t));
384 /* Read the BC from header, its stored in native endian format when message
387 bc = (((msgHeader->Header) >> SHIFT24) & BC_MASK);
388 SA_DBG6(("mpiMsgProduce: msgHeader bc %d\n", bc));
389 if (circularQ->priority)
392 /* Checks the message is in "allocated" state */
393 SA_ASSERT(0 != bc, "The message buffer is not in \"allocated\" state "
396 Header = ((V_BIT << SHIFT31) | (hpriority << SHIFT30) |
397 ((bc & BC_MASK) << SHIFT24) |
398 ((responseQueue & OBID_MASK) << SHIFT16) |
399 ((category & CAT_MASK) << SHIFT12 ) | (opCode & OPCODE_MASK));
401 /* pre flush the IOMB cache line */
402 ossaCachePreFlush(circularQ->agRoot,
403 (void *)circularQ->memoryRegion.appHandle,
404 (void *)msgHeader, circularQ->elementSize * bc);
405 OSSA_WRITE_LE_32(circularQ->agRoot, msgHeader, OSSA_OFFSET_OF(mpiMsgHeader_t,
407 /* flush the IOMB cache line */
408 ossaCacheFlush(circularQ->agRoot, (void *)circularQ->memoryRegion.appHandle,
409 (void *)msgHeader, circularQ->elementSize * bc);
411 MPI_DEBUG_TRACE( circularQ->qNumber,
412 ((circularQ->producerIdx << 16 ) | circularQ->consumerIdx),
415 circularQ->elementSize);
417 ossaLogIomb(circularQ->agRoot,
421 circularQ->elementSize);
423 return AGSA_RC_SUCCESS;
424 } /* mpiMsgPrepare */
426 GLOBAL bit32 mpiMsgProduce(
427 mpiICQueue_t *circularQ,
429 mpiMsgCategory_t category,
437 ret = mpiMsgPrepare(circularQ, messagePtr, category, opCode, responseQueue,
439 if (ret == AGSA_RC_SUCCESS)
441 /* update PI of inbound queue */
442 ossaHwRegWriteExt(circularQ->agRoot,
444 circularQ->PIPCIOffset,
445 circularQ->producerIdx);
450 GLOBAL void mpiIBQMsgSend(mpiICQueue_t *circularQ)
452 ossaHwRegWriteExt(circularQ->agRoot,
454 circularQ->PIPCIOffset,
455 circularQ->producerIdx);
457 #else /* FAST_IO_TEST */
462 mpiICQueue_t *circularQ,
464 mpiMsgCategory_t category,
470 mpiMsgHeader_t *msgHeader;
475 #ifdef SA_FW_TEST_BUNCH_STARTS
476 #define Need_agRootDefined 1
477 #endif /* SA_FW_TEST_BUNCH_STARTS */
479 #ifdef SA_ENABLE_TRACE_FUNCTIONS
481 #define Need_agRootDefined 1
482 #endif /* SA_ENABLE_TRACE_FUNCTIONS */
484 #ifdef MPI_DEBUG_TRACE_ENABLE
485 #define Need_agRootDefined 1
486 #endif /* MPI_DEBUG_TRACE_ENABLE */
488 #ifdef Need_agRootDefined
489 agsaRoot_t *agRoot=circularQ->agRoot;
490 #ifdef SA_FW_TEST_BUNCH_STARTS
491 agsaLLRoot_t *saRoot = agNULL;
492 saRoot = agRoot->sdkData;
493 #endif /* SA_FW_TEST_BUNCH_STARTS */
495 #undef Need_agRootDefined
496 #endif /* Need_agRootDefined */
498 SA_DBG4(("Entering function:mpiMsgProduce\n"));
499 SA_ASSERT(NULL != circularQ, "circularQ argument cannot be null");
500 SA_ASSERT(NULL != messagePtr, "messagePtr argument cannot be null");
501 SA_ASSERT(0 != circularQ->numElements, "The number of elements in this queue is 0");
502 SA_ASSERT(MPI_MAX_OUTBOUND_QUEUES > responseQueue, "oQueue ID is wrong");
504 /* REB Start extra trace */
505 smTraceFuncEnter(hpDBG_VERY_LOUD,"22");
506 /* REB End extra trace */
508 /* Obtains the address of the entire message buffer, including the header */
509 msgHeader = (mpiMsgHeader_t*)(((bit8*)messagePtr) - sizeof(mpiMsgHeader_t));
510 /* Read the BC from header, its stored in native endian format when message was allocated */
512 bc = (((msgHeader->Header) >> SHIFT24) & BC_MASK);
513 SA_DBG6(("mpiMsgProduce: msgHeader bc %d\n", bc));
514 if (circularQ->priority)
519 /* Checks the message is in "allocated" state */
520 SA_ASSERT(0 != bc, "The message buffer is not in \"allocated\" state (bc == 0)");
522 Header = ((V_BIT << SHIFT31) |
523 (hpriority << SHIFT30) |
524 ((bc & BC_MASK) << SHIFT24) |
525 ((responseQueue & OBID_MASK) << SHIFT16) |
526 ((category & CAT_MASK) << SHIFT12 ) |
527 (opCode & OPCODE_MASK));
529 /* pre flush the cache line */
530 ossaCachePreFlush(circularQ->agRoot, (void *)circularQ->memoryRegion.appHandle, (void *)msgHeader, circularQ->elementSize * bc);
531 OSSA_WRITE_LE_32(circularQ->agRoot, msgHeader, OSSA_OFFSET_OF(mpiMsgHeader_t, Header), Header);
532 /* flush the cache line for IOMB */
533 ossaCacheFlush(circularQ->agRoot, (void *)circularQ->memoryRegion.appHandle, (void *)msgHeader, circularQ->elementSize * bc);
535 MPI_DEBUG_TRACE( circularQ->qNumber,
536 ((circularQ->producerIdx << 16 ) | circularQ->consumerIdx),
539 circularQ->elementSize);
541 ossaLogIomb(circularQ->agRoot,
545 circularQ->elementSize);
547 #if defined(SALLSDK_DEBUG)
548 MPI_IBQ_IOMB_LOG(circularQ->qNumber, (void *)msgHeader, circularQ->elementSize);
549 #endif /* SALLSDK_DEBUG */
550 /* REB Start extra trace */
551 #ifdef SA_ENABLE_TRACE_FUNCTIONS
552 smTrace(hpDBG_IOMB,"M1",circularQ->qNumber);
553 /* TP:M1 circularQ->qNumber */
554 for (i=0; i<((bit32)bc*(circularQ->elementSize/4)); i++)
556 /* The -sizeof(mpiMsgHeader_t) is to account for mpiMsgProduce adding the header to the pMessage pointer */
557 smTrace(hpDBG_IOMB,"MD",*( ((bit32 *)((bit8 *)messagePtr - sizeof(mpiMsgHeader_t))) + i));
558 /* TP:MD Inbound IOMB Dword */
560 #endif /* SA_ENABLE_TRACE_FUNCTIONS */
562 /* update PI of inbound queue */
564 #ifdef SA_FW_TEST_BUNCH_STARTS
565 if(saRoot->BunchStarts_Enable)
567 if (circularQ->BunchStarts_QPending == 0)
569 // store tick value for 1st deferred IO only
570 circularQ->BunchStarts_QPendingTick = saRoot->timeTick;
572 // update queue's pending count
573 circularQ->BunchStarts_QPending++;
575 // update global pending count
576 saRoot->BunchStarts_Pending++;
578 SA_DBG1(("mpiMsgProduce: BunchStarts - Global Pending %d\n", saRoot->BunchStarts_Pending));
579 SA_DBG1(("mpiMsgProduce: BunchStarts - QPending %d, Q-%d\n", circularQ->BunchStarts_QPending, circularQ->qNumber));
580 smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "22");
582 return AGSA_RC_SUCCESS;
585 saRoot->BunchStarts_Pending = 0;
586 circularQ->BunchStarts_QPending = 0;
587 #endif /* SA_FW_TEST_BUNCH_STARTS */
588 ossaHwRegWriteExt(circularQ->agRoot,
590 circularQ->PIPCIOffset,
591 circularQ->producerIdx);
593 smTraceFuncExit(hpDBG_VERY_LOUD, 'b', "22");
595 return AGSA_RC_SUCCESS;
596 } /* mpiMsgProduce */
597 #endif /* FAST_IO_TEST */
599 #ifdef SA_FW_TEST_BUNCH_STARTS
601 void mpiMsgProduceBunch( agsaLLRoot_t *saRoot)
603 mpiICQueue_t *circularQ;
606 for(inq=0; ((inq < saRoot->QueueConfig.numInboundQueues) && saRoot->BunchStarts_Pending); inq++)
608 circularQ= &saRoot->inboundQueue[inq];
609 /* If any pending IOs present then either process if BunchStarts_Threshold
610 * IO limit reached or if the timer has popped
612 if (circularQ->BunchStarts_QPending &&
613 ((circularQ->BunchStarts_QPending >= saRoot->BunchStarts_Threshold) ||
614 ((saRoot->timeTick - circularQ->BunchStarts_QPendingTick) >= saRoot->BunchStarts_TimeoutTicks))
617 if(circularQ->qNumber != inq)
619 SA_DBG1(("mpiMsgProduceBunch:circularQ->qNumber(%d) != inq(%d)\n",circularQ->qNumber, inq));
622 SA_DBG1(("mpiMsgProduceBunch: IQ=%d, PI=%d\n", inq, circularQ->producerIdx));
623 SA_DBG1(("mpiMsgProduceBunch: Qpending=%d, TotPending=%d\n", circularQ->BunchStarts_QPending, saRoot->BunchStarts_Pending));
625 ossaHwRegWriteExt(circularQ->agRoot,
627 circularQ->PIPCIOffset,
628 circularQ->producerIdx);
630 // update global pending count
631 saRoot->BunchStarts_Pending -= circularQ->BunchStarts_QPending;
633 // clear current queue's pending count after processing
634 circularQ->BunchStarts_QPending = 0;
635 circularQ->BunchStarts_QPendingTick = saRoot->timeTick;
639 #endif /* SA_FW_TEST_BUNCH_STARTS */
641 /*******************************************************************************/
642 /** \fn mpiMsgConsume(mpiOCQueue_t *circularQ, void *messagePtr1,
643 * mpiMsgCategory_t * pCategory, bit16 * pOpCode, bit8 * pBC)
644 * \brief Get a received message
645 * \param circularQ Pointer to a outbound queue
646 * \param messagePtr1 Pointer to the returned message buffer or NULL if no valid message
647 * \param pCategory Pointer to Message category (ETHERNET, FC, SAS-SATA, SCSI)
648 * \param pOpCode Pointer to Message operation code
649 * \param pBC Pointer to buffer count
651 * Consume a receive message in the specified outbound queue
654 * AGSA_RC_SUCCESS if the message has been retrieved succesfully
655 * AGSA_RC_BUSY if the circular is empty
657 /*******************************************************************************/
661 mpiOCQueue_t *circularQ,
663 mpiMsgCategory_t *pCategory,
668 mpiMsgHeader_t *msgHeader;
671 SA_ASSERT(NULL != circularQ, "circularQ argument cannot be null");
672 SA_ASSERT(NULL != messagePtr1, "messagePtr1 argument cannot be null");
673 SA_ASSERT(NULL != pCategory, "pCategory argument cannot be null");
674 SA_ASSERT(NULL != pOpCode, "pOpCode argument cannot be null");
675 SA_ASSERT(NULL != pBC, "pBC argument cannot be null");
676 SA_ASSERT(0 != circularQ->numElements, "The number of elements in this queue is 0");
680 /* If there are not-yet-delivered messages ... */
681 if(circularQ->producerIdx != circularQ->consumerIdx)
683 /* Get the pointer to the circular queue buffer element */
684 msgHeader = (mpiMsgHeader_t*) ((bit8 *)(circularQ->memoryRegion.virtPtr) + circularQ->consumerIdx * circularQ->elementSize);
689 /* invalidate the cache line of IOMB */
690 ossaCacheInvalidate(circularQ->agRoot, (void *)circularQ->memoryRegion.appHandle, (void *)msgHeader, circularQ->elementSize);
694 OSSA_READ_LE_32(circularQ->agRoot, &msgHeader_tmp, msgHeader, 0);
696 SA_DBG4(("mpiMsgConsume: process an IOMB, header=0x%x\n", msgHeader_tmp));
698 SA_ASSERT(0 != (msgHeader_tmp & HEADER_BC_MASK), "The bc field in the header is 0");
701 if (0 == (msgHeader_tmp & HEADER_BC_MASK))
703 SA_DBG1(("mpiMsgConsume: CI=%d PI=%d msgHeader=%p\n", circularQ->consumerIdx, circularQ->producerIdx, (void *)msgHeader));
704 circularQ->consumerIdx = (circularQ->consumerIdx + 1) % circularQ->numElements;
705 /* update the CI of outbound queue - skip this blank IOMB, for test only */
706 ossaHwRegWriteExt(circularQ->agRoot,
708 circularQ->CIPCIOffset,
709 circularQ->consumerIdx);
710 return AGSA_RC_FAILURE;
713 /* get message pointer of valid entry */
714 if (0 != (msgHeader_tmp & HEADER_V_MASK))
716 SA_ASSERT(circularQ->consumerIdx <= circularQ->numElements, "Multi-buffer messages cannot wrap around");
718 if (OPC_OUB_SKIP_ENTRY != (msgHeader_tmp & OPCODE_MASK))
720 /* ... return the message payload */
721 *messagePtr1 = ((bit8*)msgHeader) + sizeof(mpiMsgHeader_t);
722 *pCategory = (mpiMsgCategory_t)(msgHeader_tmp >> SHIFT12) & CAT_MASK;
723 *pOpCode = (bit16)(msgHeader_tmp & OPCODE_MASK);
724 *pBC = (bit8)((msgHeader_tmp >> SHIFT24) & BC_MASK);
726 /* invalidate the cache line for IOMB */
730 ossaCacheInvalidate(circularQ->agRoot, (void *)circularQ->memoryRegion.appHandle, (void *)msgHeader, (*pBC - 1) * circularQ->elementSize);
732 #if defined(SALLSDK_DEBUG)
733 SA_DBG3(("mpiMsgConsume: CI=%d PI=%d msgHeader=%p\n", circularQ->consumerIdx, circularQ->producerIdx, (void *)msgHeader));
734 MPI_OBQ_IOMB_LOG(circularQ->qNumber, (void *)msgHeader, circularQ->elementSize);
736 return AGSA_RC_SUCCESS;
740 SA_DBG3(("mpiMsgConsume: SKIP_ENTRIES_IOMB BC=%d\n", (msgHeader_tmp >> SHIFT24) & BC_MASK));
741 /* Updated comsumerIdx and skip it */
742 circularQ->consumerIdx = (circularQ->consumerIdx + ((msgHeader_tmp >> SHIFT24) & BC_MASK)) % circularQ->numElements;
743 /* clean header to 0 */
745 /*ossaSingleThreadedEnter(agRoot, LL_IOREQ_OBQ_LOCK);*/
747 OSSA_WRITE_LE_32(circularQ->agRoot, msgHeader, OSSA_OFFSET_OF(mpiMsgHeader_t, Header), msgHeader_tmp);
749 /* update the CI of outbound queue */
750 ossaHwRegWriteExt(circularQ->agRoot,
752 circularQ->CIPCIOffset,
753 circularQ->consumerIdx);
754 /* Update the producer index */
755 OSSA_READ_LE_32(circularQ->agRoot, &circularQ->producerIdx, circularQ->piPointer, 0);
756 /*ossaSingleThreadedLeave(agRoot, LL_IOREQ_OBQ_LOCK); */
761 /* V bit is not set */
762 #if defined(SALLSDK_DEBUG)
763 agsaRoot_t *agRoot=circularQ->agRoot;
764 SA_DBG1(("mpiMsgConsume: V bit not set, PI=%d CI=%d msgHeader=%p\n", circularQ->producerIdx, circularQ->consumerIdx,(void *)msgHeader));
765 SA_DBG1(("mpiMsgConsume: V bit not set, 0x%08X Q=%d \n", msgHeader_tmp, circularQ->qNumber));
767 MPI_DEBUG_TRACE(MPI_DEBUG_TRACE_QNUM_ERROR + circularQ->qNumber,
768 ((circularQ->producerIdx << 16 ) | circularQ->consumerIdx),
770 (void *)(((bit8*)msgHeader) - sizeof(mpiMsgHeader_t)),
771 circularQ->elementSize);
773 circularQ->consumerIdx = circularQ->consumerIdx % circularQ->numElements;
774 circularQ->consumerIdx ++;
775 OSSA_WRITE_LE_32(circularQ->agRoot, msgHeader, OSSA_OFFSET_OF(mpiMsgHeader_t, Header), msgHeader_tmp);
776 ossaHwRegWriteExt(agRoot,
778 circularQ->CIPCIOffset,
779 circularQ->consumerIdx);
780 MPI_OBQ_IOMB_LOG(circularQ->qNumber, (void *)msgHeader, circularQ->elementSize);
782 SA_DBG1(("mpiMsgConsume: V bit is not set!!!!! HW CI=%d\n", ossaHwRegReadExt(circularQ->agRoot, circularQ->CIPCIBar, circularQ->CIPCIOffset) ));
783 SA_ASSERT(0, "V bit is not set");
784 return AGSA_RC_FAILURE;
789 /* Update the producer index from SPC */
790 OSSA_READ_LE_32(circularQ->agRoot, &circularQ->producerIdx, circularQ->piPointer, 0);
792 } while(circularQ->producerIdx != circularQ->consumerIdx); /* while we don't have any more not-yet-delivered message */
795 SA_DBG4(("mpiMsgConsume: Outbound queue is empty.\n"));
802 /*******************************************************************************/
803 /** \fn mpiMsgFreeSet(mpiOCQueue_t *circularQ, void *messagePtr)
804 * \brief Returns a received message to the outbound queue
805 * \param circularQ Pointer to an outbound queue
806 * \param messagePtr1 Pointer to the returned message buffer to free
807 * \param messagePtr2 Pointer to the returned message buffer to free if bc > 1
809 * Returns consumed and processed message to the specified outbounf queue
812 * AGSA_RC_SUCCESS if the message has been returned succesfully
814 /*******************************************************************************/
818 mpiOCQueue_t *circularQ,
823 mpiMsgHeader_t *msgHeader;
825 SA_DBG4(("Entering function:mpiMsgFreeSet\n"));
826 SA_ASSERT(NULL != circularQ, "circularQ argument cannot be null");
827 SA_ASSERT(NULL != messagePtr1, "messagePtr1 argument cannot be null");
828 SA_ASSERT(0 != circularQ->numElements, "The number of elements in this queue is 0");
830 /* Obtains the address of the entire message buffer, including the header */
831 msgHeader = (mpiMsgHeader_t*)(((bit8*)messagePtr1) - sizeof(mpiMsgHeader_t));
833 if ( ((mpiMsgHeader_t*)((bit8*)circularQ->memoryRegion.virtPtr + circularQ->consumerIdx * circularQ->elementSize)) != msgHeader)
835 /* IOMB of CI points mismatch with Message Header - should never happened */
836 SA_DBG1(("mpiMsgFreeSet: Wrong CI, Q %d ConsumeIdx = %d msgHeader 0x%08x\n",circularQ->qNumber, circularQ->consumerIdx ,msgHeader->Header));
837 SA_DBG1(("mpiMsgFreeSet: msgHeader %p != %p\n", msgHeader,((mpiMsgHeader_t*)((bit8*)circularQ->memoryRegion.virtPtr + circularQ->consumerIdx * circularQ->elementSize))));
842 /* Update the producer index from SPC */
843 OSSA_READ_LE_32(circularQ->agRoot, &circularQ->producerIdx, circularQ->piPointer, 0);
844 #if defined(SALLSDK_DEBUG)
845 SA_DBG3(("mpiMsgFreeSet: ProducerIdx = %d\n", circularQ->producerIdx));
847 return AGSA_RC_SUCCESS;
850 /* ... free the circular queue buffer elements associated with the message ... */
851 /*... by incrementing the consumer index (with wrap arround) */
852 circularQ->consumerIdx = (circularQ->consumerIdx + bc) % circularQ->numElements;
854 /* Invalidates this circular queue buffer element */
856 msgHeader->Header &= ~HEADER_V_MASK; /* Clear Valid bit to indicate IOMB consumed by host */
857 SA_ASSERT(circularQ->consumerIdx <= circularQ->numElements, "Multi-buffer messages cannot wrap arround");
859 /* update the CI of outbound queue */
864 ossaHwRegWriteExt(circularQ->agRoot,
866 circularQ->CIPCIOffset,
867 circularQ->consumerIdx);
869 /* Update the producer index from SPC */
870 OSSA_READ_LE_32(circularQ->agRoot, &circularQ->producerIdx, circularQ->piPointer, 0);
872 #if defined(SALLSDK_DEBUG)
873 SA_DBG5(("mpiMsgFreeSet: CI=%d PI=%d\n", circularQ->consumerIdx, circularQ->producerIdx));
875 return AGSA_RC_SUCCESS;
879 GLOBAL bit32 mpiRotateQnumber(agsaRoot_t *agRoot)
881 agsaLLRoot_t *saRoot = (agsaLLRoot_t *) (agRoot->sdkData);
885 /* inbound queue number */
887 denom = saRoot->QueueConfig.numInboundQueues;
888 if (saRoot->IBQnumber % denom == 0) /* % Qnumber*/
890 saRoot->IBQnumber = 0;
892 SA_DBG3(("mpiRotateQnumber: IBQnumber %d\n", saRoot->IBQnumber));
894 /* outbound queue number */
896 denom = saRoot->QueueConfig.numOutboundQueues;
897 if (saRoot->OBQnumber % denom == 0) /* % Qnumber*/
899 saRoot->OBQnumber = 0;
901 SA_DBG3(("mpiRotateQnumber: OBQnumber %d\n", saRoot->OBQnumber));
903 ret = (saRoot->OBQnumber << SHIFT16) | saRoot->IBQnumber;
909 GLOBAL bit32 mpiMsgProduceOQ(
910 mpiOCQueue_t *circularQ,
912 mpiMsgCategory_t category,
918 mpiMsgHeader_t *msgHeader;
923 SA_DBG4(("Entering function:mpiMsgProduceOQ\n"));
924 SA_ASSERT(NULL != circularQ, "circularQ argument cannot be null");
925 SA_ASSERT(NULL != messagePtr, "messagePtr argument cannot be null");
926 SA_ASSERT(0 != circularQ->numElements, "The number of elements in this queue"
928 SA_ASSERT(MPI_MAX_OUTBOUND_QUEUES > responseQueue, "oQueue ID is wrong");
930 /* REB Start extra trace */
931 smTraceFuncEnter(hpDBG_VERY_LOUD, "2I");
932 /* REB End extra trace */
934 /* Obtains the address of the entire message buffer, including the header */
935 msgHeader = (mpiMsgHeader_t*)(((bit8*)messagePtr) - sizeof(mpiMsgHeader_t));
936 /* Read the BC from header, its stored in native endian format when message
939 SA_DBG4(("mpiMsgProduceOQ: msgHeader %p opcode %d pi/ci %d / %d\n", msgHeader, opCode, circularQ->producerIdx, circularQ->consumerIdx));
940 bc = (((msgHeader->Header) >> SHIFT24) & BC_MASK);
941 SA_DBG6(("mpiMsgProduceOQ: msgHeader bc %d\n", bc));
942 if (circularQ->priority)
945 /* Checks the message is in "allocated" state */
946 SA_ASSERT(0 != bc, "The message buffer is not in \"allocated\" state "
949 Header = ((V_BIT << SHIFT31) | (hpriority << SHIFT30) |
950 ((bc & BC_MASK) << SHIFT24) |
951 ((responseQueue & OBID_MASK) << SHIFT16) |
952 ((category & CAT_MASK) << SHIFT12 ) | (opCode & OPCODE_MASK));
953 /* pre flush the IOMB cache line */
954 //ossaCachePreFlush(circularQ->agRoot,
955 // (void *)circularQ->memoryRegion.appHandle,
956 // (void *)msgHeader, circularQ->elementSize * bc);
957 OSSA_WRITE_LE_32(circularQ->agRoot, msgHeader, OSSA_OFFSET_OF(mpiMsgHeader_t,
960 /* flush the IOMB cache line */
961 //ossaCacheFlush(circularQ->agRoot, (void *)circularQ->memoryRegion.appHandle,
962 // (void *)msgHeader, circularQ->elementSize * bc);
964 MPI_DEBUG_TRACE( circularQ->qNumber,
965 ((circularQ->producerIdx << 16 ) | circularQ->consumerIdx),
968 circularQ->elementSize);
970 ossaLogIomb(circularQ->agRoot,
974 circularQ->elementSize);
976 smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "2I");
977 return AGSA_RC_SUCCESS;
978 } /* mpiMsgProduceOQ */