/** * @b Description * @n * This function is used to obtain previously allocated descriptors. * The function opens a destination queue as specified in the input parameters * and pushes the requested number of descriptors if available onto it. * * @param[in] descCfg * Specifies the number of descriptors, memory region from where it should be allocated * and the destination queue to push to. * * @param[out] numAllocated * Number of descriptors actually allocated. * * @pre * Qmss_init function should be called before calling this function. * * @retval * Success - Destination queue handle on which the allocated descriptors are stored. * The queue must be closed by the caller using Qmss_queueClose() when done. * @retval * Failure - QMSS_NOT_INITIALIZED * @retval * Failure - QMSS_INVALID_PARAM * @retval * Failure - QMSS_MEMREGION_NOT_INITIALIZED * @retval * Failure - QMSS_QUEUE_OPEN_ERROR */ Qmss_QueueHnd Qmss_initDescriptor (Qmss_DescCfg *descCfg, uint32_t *numAllocated) { uint32_t count; uint32_t *descPtr; uint8_t isAllocated; int32_t srcQueNum, srcQueHnd, destQueHnd; /* Get the descriptor from the source queue */ if (qmssLObjIsValid == 0) { return QMSS_NOT_INITIALIZED; } if (descCfg == NULL) { return QMSS_INVALID_PARAM; } /* Find the source queue given the memory region */ if ((srcQueNum = Qmss_getMemRegQueueHandle (descCfg->memRegion)) < 0) { return QMSS_MEMREGION_NOT_INITIALIZED; } /* Find the descriptor size in the given the memory region */ if ((Qmss_getMemRegDescSize (descCfg->memRegion)) == 0) { return QMSS_MEMREGION_NOT_INITIALIZED; } /* Open destination queue specified in the configuration */ if ((destQueHnd = Qmss_queueOpen (descCfg->queueType, descCfg->destQueueNum, &isAllocated)) < 0) { return QMSS_QUEUE_OPEN_ERROR; } /* Open general purpose queue on which descriptors are stored */ srcQueHnd = Qmss_queueOpen (Qmss_QueueType_GENERAL_PURPOSE_QUEUE, srcQueNum, &isAllocated); *numAllocated = 0; for (count = 0; count < descCfg->descNum; count++) { /* Pop descriptor from source queue */ if ((descPtr = Qmss_queuePop (srcQueHnd)) == NULL) { break; } /* Push descriptor to the specified destination queue */ /* TODO QueueProxy is not working add this later * Qmss_queuePushDesc (destQueHnd, descPtr, descSize); */ Qmss_queuePushDesc (destQueHnd, descPtr); *numAllocated += 1; } return destQueHnd; }
/** ============================================================================ * @n@b Setup_Rx * * @b Description * @n This API sets up all relevant data structures and configuration required * for receiving data from PASS/Ethernet. It sets up a Rx free descriptor queue * with some empty pre-allocated buffers to receive data, and an Rx queue * to which the Rxed data is streamed for the example application. This API * also sets up the QM high priority accumulation interrupts required to * receive data from the Rx queue. * * @param[in] * @n None * * @return Int32 * -1 - Error * 0 - Success * ============================================================================= */ Int32 Setup_Rx (Ethernet *pThis) { Int32 result; UInt8 isAllocated, accChannelNum; UInt16 numAccEntries, intThreshold, i; Qmss_Queue rxFreeQInfo, rxQInfo; Ptr pCppiDesc; Qmss_AccCmdCfg accCfg; Cppi_RxFlowCfg rxFlowCfg; Ptr pDataBuffer; Error_Block eb; Uint32 mySWInfo[] = {0x11112222, 0x33334444}; /* Open a Receive (Rx) queue. * * This queue will be used to hold all the packets received by PASS/CPSW * * Open the next available High Priority Accumulation queue for Rx. */ if ((gRxQHnd = Qmss_queueOpen (Qmss_QueueType_HIGH_PRIORITY_QUEUE, QMSS_PARAM_NOT_SPECIFIED, &isAllocated)) < 0) { uart_write ("Error opening a High Priority Accumulation Rx queue \n"); return -1; } rxQInfo = Qmss_getQueueNumber (gRxQHnd); uart_write ("Opened RX queue Number %d \n",rxQInfo.qNum); /* Setup high priority accumulation interrupts on the Rx queue. * * Let's configure the accumulator with the following settings: * (1) Interrupt pacing disabled. * (2) Interrupt on every received packet */ intThreshold = RX_INT_THRESHOLD; numAccEntries = (intThreshold + 1) * 2; accChannelNum = PA_ACC_CHANNEL_NUM; /* Initialize the accumulator list memory */ memset ((Void *) gHiPriAccumList, 0, numAccEntries * 4); /* Ensure that the accumulator channel we are programming is not * in use currently. */ result = Qmss_disableAccumulator (Qmss_PdspId_PDSP1, accChannelNum); if (result != QMSS_ACC_SOK && result != QMSS_ACC_CHANNEL_NOT_ACTIVE) { uart_write ("Error Disabling high priority accumulator for channel : %d error code: %d\n", accChannelNum, result); return -1; } /* Setup the accumulator settings */ accCfg.channel = accChannelNum; accCfg.command = Qmss_AccCmd_ENABLE_CHANNEL; accCfg.queueEnMask = 0; accCfg.listAddress = Convert_CoreLocal2GlobalAddr((Uint32) gHiPriAccumList); // accCfg.listAddress = gHiPriAccumList; accCfg.queMgrIndex = gRxQHnd; accCfg.maxPageEntries = (intThreshold + 1); /* Add an extra entry for holding the entry count */ accCfg.timerLoadCount = 0; accCfg.interruptPacingMode = Qmss_AccPacingMode_LAST_INTERRUPT; accCfg.listEntrySize = Qmss_AccEntrySize_REG_D; accCfg.listCountMode = Qmss_AccCountMode_ENTRY_COUNT; accCfg.multiQueueMode = Qmss_AccQueueMode_SINGLE_QUEUE; /* Program the accumulator */ if ((result = Qmss_programAccumulator (Qmss_PdspId_PDSP1, &accCfg)) != QMSS_ACC_SOK) { uart_write ("Error Programming high priority accumulator for channel : %d queue : %d error code : %d\n", accCfg.channel, accCfg.queMgrIndex, result); return -1; } Error_init(&eb); pThis->RxEventHandle = Event_create(NULL,&eb); if (pThis->RxEventHandle == NULL) { uart_write("Event create failed"); return -1; } memset(pThis->pRxDataPtr,0,sizeof(pThis->pRxDataPtr)); pThis->RxDataHead = 0; pThis->RxDataTail = 0; Intr_Init(&pThis->oEthIntr, INTR_ITEM_ETH_RX,(Intr_Handler)Cpsw_RxISR, (void*)pThis); /* Open a Rx Free Descriptor Queue (Rx FDQ). * * This queue will hold all the Rx free decriptors. These descriptors will be * used by the PASS CPDMA to hold data received via CPSW. */ if ((gRxFreeQHnd = Qmss_queueOpen (Qmss_QueueType_STARVATION_COUNTER_QUEUE, QMSS_PARAM_NOT_SPECIFIED, &isAllocated)) < 0) { uart_write ("Error opening Rx Free descriptor queue \n"); return -1; } rxFreeQInfo = Qmss_getQueueNumber (gRxFreeQHnd); uart_write("Opened RX Free queue Number %d\n",gRxFreeQHnd); /* Attach some free descriptors to the Rx free queue we just opened. */ for (i = 0; i < NUM_RX_DESC; i++) { /* Get a free descriptor from the global free queue we setup * during initialization. */ if ((pCppiDesc = Qmss_queuePop (gGlobalFreeQHnd)) == NULL) { break; } /* The descriptor address returned from the hardware has the * descriptor size appended to the address in the last 4 bits. * * To get the true descriptor size, always mask off the last * 4 bits of the address. */ pCppiDesc = (Ptr) ((UInt32) pCppiDesc & 0xFFFFFFF0); if ((pDataBuffer = (Ptr) Memory_alloc((IHeap_Handle)heap2, ETHER_MAX_SIZE, 0, NULL)) == NULL) { uart_write ("Error allocating memory for Rx data buffer \n"); break; } /* Populate the Rx free descriptor with the buffer we just allocated. */ Cppi_setData (Cppi_DescType_HOST, pCppiDesc, (UInt8 *)Convert_CoreLocal2GlobalAddr((UInt32)pDataBuffer), ETHER_MAX_SIZE); /* Save original buffer information */ Cppi_setOriginalBufInfo (Cppi_DescType_HOST, pCppiDesc, (UInt8 *)Convert_CoreLocal2GlobalAddr((UInt32)pDataBuffer), ETHER_MAX_SIZE); /* Setup the Completion queue: * * Setup the return policy for this desc to return to the free q we just * setup instead of the global free queue. */ Cppi_setReturnQueue (Cppi_DescType_HOST, pCppiDesc, rxFreeQInfo); Cppi_setSoftwareInfo (Cppi_DescType_HOST, pCppiDesc, (UInt8 *) mySWInfo); Cppi_setPacketLen (Cppi_DescType_HOST, pCppiDesc, ETHER_MAX_SIZE); /* Push descriptor to Tx free queue */ Qmss_queuePushDescSize (gRxFreeQHnd, pCppiDesc, SIZE_CPSW_HOST_DESC); } if (i != NUM_RX_DESC) { uart_write ("Error allocating Rx free descriptors \n"); return -1; } //count=Qmss_getQueueEntryCount(gRxFreeQHnd); //platform_write("Total %d entries in queue %d\n",count,gRxFreeQHnd); /* Setup a Rx Flow. * * A Rx flow encapsulates all relevant data properties that CPDMA would * have to know in order to succefully receive data. */ /* Initialize the flow configuration */ memset (&rxFlowCfg, 0, sizeof(Cppi_RxFlowCfg)); /* Let CPPI pick the next available flow */ rxFlowCfg.flowIdNum = CPPI_PARAM_NOT_SPECIFIED; rxFlowCfg.rx_dest_qmgr = rxQInfo.qMgr; rxFlowCfg.rx_dest_qnum = rxQInfo.qNum; rxFlowCfg.rx_desc_type = Cppi_DescType_HOST; rxFlowCfg.rx_ps_location = Cppi_PSLoc_PS_IN_DESC; rxFlowCfg.rx_psinfo_present = 1; /* Enable PS info */ rxFlowCfg.rx_error_handling = 0; /* Drop the packet, do not retry on starvation by default */ rxFlowCfg.rx_einfo_present = 1; /* EPIB info present */ rxFlowCfg.rx_dest_tag_lo_sel = 0; /* Disable tagging */ rxFlowCfg.rx_dest_tag_hi_sel = 0; rxFlowCfg.rx_src_tag_lo_sel = 0; rxFlowCfg.rx_src_tag_hi_sel = 0; rxFlowCfg.rx_size_thresh0_en = 0; /* By default, we disable Rx Thresholds */ rxFlowCfg.rx_size_thresh1_en = 0; /* By default, we disable Rx Thresholds */ rxFlowCfg.rx_size_thresh2_en = 0; /* By default, we disable Rx Thresholds */ rxFlowCfg.rx_size_thresh0 = 0x0; rxFlowCfg.rx_size_thresh1 = 0x0; rxFlowCfg.rx_size_thresh2 = 0x0; rxFlowCfg.rx_fdq0_sz0_qmgr = rxFreeQInfo.qMgr; /* Setup the Receive free queue for the flow */ rxFlowCfg.rx_fdq0_sz0_qnum = rxFreeQInfo.qNum; rxFlowCfg.rx_fdq0_sz1_qnum = 0x0; rxFlowCfg.rx_fdq0_sz1_qmgr = 0x0; rxFlowCfg.rx_fdq0_sz2_qnum = 0x0; rxFlowCfg.rx_fdq0_sz2_qmgr = 0x0; rxFlowCfg.rx_fdq0_sz3_qnum = 0x0; rxFlowCfg.rx_fdq0_sz3_qmgr = 0x0; rxFlowCfg.rx_fdq1_qnum = rxFreeQInfo.qNum; /* Use the Rx Queue to pick descriptors */ rxFlowCfg.rx_fdq1_qmgr = rxFreeQInfo.qMgr; rxFlowCfg.rx_fdq2_qnum = rxFreeQInfo.qNum; /* Use the Rx Queue to pick descriptors */ rxFlowCfg.rx_fdq2_qmgr = rxFreeQInfo.qMgr; rxFlowCfg.rx_fdq3_qnum = rxFreeQInfo.qNum; /* Use the Rx Queue to pick descriptors */ rxFlowCfg.rx_fdq3_qmgr = rxFreeQInfo.qMgr; /* Configure the Rx flow */ if ((gRxFlowHnd = Cppi_configureRxFlow (gCpdmaHnd, &rxFlowCfg, &isAllocated)) == NULL) { uart_write ("Error configuring Rx flow \n"); return -1; } else { //platform_write("Rx flow configured. handle %p Id %d \n",gRxFlowHnd,Cppi_getFlowId (gRxFlowHnd)); } /* All done with Rx configuration. Return success. */ return 0; }
/** ============================================================================ * @n@b Setup_Tx * * @b Description * @n This API sets up all relevant data structures and configuration required * for sending data to PASS/Ethernet. It sets up a Tx free descriptor queue, * PASS Tx queues required for send. * * @param[in] * @n None * * @return Int32 * -1 - Error * 0 - Success * ============================================================================= */ Int32 Setup_Tx (Void) { UInt8 isAllocated; Qmss_Queue qInfo; Ptr pCppiDesc; UInt32 i; /* Open all Transmit (Tx) queues. * * These queues are used to send data to PA PDSP/CPSW. */ for (i = 0; i < NUM_PA_TX_QUEUES; i ++) { if ((gPaTxQHnd[i] = Qmss_queueOpen (Qmss_QueueType_PASS_QUEUE, QMSS_PARAM_NOT_SPECIFIED, &isAllocated)) < 0) { uart_write ("Error opening PA Tx queue \n"); return -1; } else { //platform_write("opened TX queue for PA %d\n",gPaTxQHnd[i]); } } /* Open a Tx Free Descriptor Queue (Tx FDQ). * * This queue will be used to hold Tx free decriptors that can be filled * later with data buffers for transmission onto wire. */ if ((gTxFreeQHnd = Qmss_queueOpen (Qmss_QueueType_STARVATION_COUNTER_QUEUE, QMSS_PARAM_NOT_SPECIFIED, &isAllocated)) < 0) { uart_write ("Error opening Tx Free descriptor queue \n"); return -1; } else { //platform_write("opened TX Free queue for PA %d\n",gTxFreeQHnd); } qInfo = Qmss_getQueueNumber (gTxFreeQHnd); /* Attach some free descriptors to the Tx free queue we just opened. */ for (i = 0; i < NUM_TX_DESC; i++) { /* Get a free descriptor from the global free queue we setup * during initialization. */ if ((pCppiDesc = Qmss_queuePop (gGlobalFreeQHnd)) == NULL) { break; } /* The descriptor address returned from the hardware has the * descriptor size appended to the address in the last 4 bits. * * To get the true descriptor size, always mask off the last * 4 bits of the address. */ pCppiDesc = (Ptr) ((UInt32) pCppiDesc & 0xFFFFFFF0); /* Setup the Completion queue: * * Setup the return policy for this desc to return to the free q we just * setup instead of the global free queue. */ Cppi_setReturnQueue ((Cppi_DescType) Cppi_DescType_HOST, pCppiDesc, qInfo); /* Push descriptor to Tx free queue */ Qmss_queuePushDescSize (gTxFreeQHnd, pCppiDesc, SIZE_CPSW_HOST_DESC); } if (i != NUM_TX_DESC) { uart_write ("Error allocating Tx free descriptors. only %d queues allotted \n",Qmss_getQueueEntryCount(gTxFreeQHnd)); return -1; } //count=Qmss_getQueueEntryCount(gTxFreeQHnd); //platform_write("Total %d found entries in queue %d\n",count,gTxFreeQHnd); /* All done with Rx configuration. Return success. */ return 0; }