diff options
Diffstat (limited to 'drivers/staging/et131x/et1310_rx.c')
-rw-r--r-- | drivers/staging/et131x/et1310_rx.c | 565 |
1 files changed, 232 insertions, 333 deletions
diff --git a/drivers/staging/et131x/et1310_rx.c b/drivers/staging/et131x/et1310_rx.c index 10e21db..3ddc9b1 100644 --- a/drivers/staging/et131x/et1310_rx.c +++ b/drivers/staging/et131x/et1310_rx.c @@ -106,9 +106,9 @@ void nic_return_rfd(struct et131x_adapter *etdev, PMP_RFD pMpRfd); */ int et131x_rx_dma_memory_alloc(struct et131x_adapter *adapter) { - uint32_t OuterLoop, InnerLoop; - uint32_t bufsize; - uint32_t pktStatRingSize, FBRChunkSize; + u32 i, j; + u32 bufsize; + u32 pktStatRingSize, FBRChunkSize; RX_RING_t *rx_ring; /* Setup some convenience pointers */ @@ -227,11 +227,11 @@ int et131x_rx_dma_memory_alloc(struct et131x_adapter *adapter) rx_ring->Fbr0offset); #endif - for (OuterLoop = 0; OuterLoop < (rx_ring->Fbr1NumEntries / FBR_CHUNKS); - OuterLoop++) { - uint64_t Fbr1Offset; - uint64_t Fbr1TempPa; - uint32_t Fbr1Align; + for (i = 0; i < (rx_ring->Fbr1NumEntries / FBR_CHUNKS); + i++) { + u64 Fbr1Offset; + u64 Fbr1TempPa; + u32 Fbr1Align; /* This code allocates an area of memory big enough for N * free buffers + (buffer_size - 1) so that the buffers can @@ -247,39 +247,39 @@ int et131x_rx_dma_memory_alloc(struct et131x_adapter *adapter) FBRChunkSize = (FBR_CHUNKS * rx_ring->Fbr1BufferSize) + Fbr1Align - 1; - rx_ring->Fbr1MemVa[OuterLoop] = + rx_ring->Fbr1MemVa[i] = pci_alloc_consistent(adapter->pdev, FBRChunkSize, - &rx_ring->Fbr1MemPa[OuterLoop]); + &rx_ring->Fbr1MemPa[i]); - if (!rx_ring->Fbr1MemVa[OuterLoop]) { + if (!rx_ring->Fbr1MemVa[i]) { dev_err(&adapter->pdev->dev, "Could not alloc memory\n"); return -ENOMEM; } /* See NOTE in "Save Physical Address" comment above */ - Fbr1TempPa = rx_ring->Fbr1MemPa[OuterLoop]; + Fbr1TempPa = rx_ring->Fbr1MemPa[i]; et131x_align_allocated_memory(adapter, &Fbr1TempPa, &Fbr1Offset, (Fbr1Align - 1)); - for (InnerLoop = 0; InnerLoop < FBR_CHUNKS; InnerLoop++) { - uint32_t index = (OuterLoop * FBR_CHUNKS) + InnerLoop; + for (j = 0; j < FBR_CHUNKS; j++) { + u32 index = (i * FBR_CHUNKS) + j; /* Save the Virtual address of this index for quick * access later */ rx_ring->Fbr[1]->Va[index] = - (uint8_t *) rx_ring->Fbr1MemVa[OuterLoop] + - (InnerLoop * rx_ring->Fbr1BufferSize) + Fbr1Offset; + (uint8_t *) rx_ring->Fbr1MemVa[i] + + (j * rx_ring->Fbr1BufferSize) + Fbr1Offset; /* now store the physical address in the descriptor * so the device can access it */ rx_ring->Fbr[1]->PAHigh[index] = - (uint32_t) (Fbr1TempPa >> 32); - rx_ring->Fbr[1]->PALow[index] = (uint32_t) Fbr1TempPa; + (u32) (Fbr1TempPa >> 32); + rx_ring->Fbr[1]->PALow[index] = (u32) Fbr1TempPa; Fbr1TempPa += rx_ring->Fbr1BufferSize; @@ -292,40 +292,40 @@ int et131x_rx_dma_memory_alloc(struct et131x_adapter *adapter) #ifdef USE_FBR0 /* Same for FBR0 (if in use) */ - for (OuterLoop = 0; OuterLoop < (rx_ring->Fbr0NumEntries / FBR_CHUNKS); - OuterLoop++) { - uint64_t Fbr0Offset; - uint64_t Fbr0TempPa; + for (i = 0; i < (rx_ring->Fbr0NumEntries / FBR_CHUNKS); + i++) { + u64 Fbr0Offset; + u64 Fbr0TempPa; FBRChunkSize = ((FBR_CHUNKS + 1) * rx_ring->Fbr0BufferSize) - 1; - rx_ring->Fbr0MemVa[OuterLoop] = + rx_ring->Fbr0MemVa[i] = pci_alloc_consistent(adapter->pdev, FBRChunkSize, - &rx_ring->Fbr0MemPa[OuterLoop]); + &rx_ring->Fbr0MemPa[i]); - if (!rx_ring->Fbr0MemVa[OuterLoop]) { + if (!rx_ring->Fbr0MemVa[i]) { dev_err(&adapter->pdev->dev, "Could not alloc memory\n"); return -ENOMEM; } /* See NOTE in "Save Physical Address" comment above */ - Fbr0TempPa = rx_ring->Fbr0MemPa[OuterLoop]; + Fbr0TempPa = rx_ring->Fbr0MemPa[i]; et131x_align_allocated_memory(adapter, &Fbr0TempPa, &Fbr0Offset, rx_ring->Fbr0BufferSize - 1); - for (InnerLoop = 0; InnerLoop < FBR_CHUNKS; InnerLoop++) { - uint32_t index = (OuterLoop * FBR_CHUNKS) + InnerLoop; + for (j = 0; j < FBR_CHUNKS; j++) { + u32 index = (i * FBR_CHUNKS) + j; rx_ring->Fbr[0]->Va[index] = - (uint8_t *) rx_ring->Fbr0MemVa[OuterLoop] + - (InnerLoop * rx_ring->Fbr0BufferSize) + Fbr0Offset; + (uint8_t *) rx_ring->Fbr0MemVa[i] + + (j * rx_ring->Fbr0BufferSize) + Fbr0Offset; rx_ring->Fbr[0]->PAHigh[index] = - (uint32_t) (Fbr0TempPa >> 32); - rx_ring->Fbr[0]->PALow[index] = (uint32_t) Fbr0TempPa; + (u32) (Fbr0TempPa >> 32); + rx_ring->Fbr[0]->PALow[index] = (u32) Fbr0TempPa; Fbr0TempPa += rx_ring->Fbr0BufferSize; @@ -342,7 +342,7 @@ int et131x_rx_dma_memory_alloc(struct et131x_adapter *adapter) sizeof(PKT_STAT_DESC_t) * adapter->RxRing.PsrNumEntries; rx_ring->pPSRingVa = pci_alloc_consistent(adapter->pdev, - pktStatRingSize + 0x0fff, + pktStatRingSize, &rx_ring->pPSRingPa); if (!rx_ring->pPSRingVa) { @@ -350,45 +350,26 @@ int et131x_rx_dma_memory_alloc(struct et131x_adapter *adapter) "Cannot alloc memory for Packet Status Ring\n"); return -ENOMEM; } + printk("PSR %lx\n", (unsigned long) rx_ring->pPSRingPa); - /* Save physical address - * + /* * NOTE : pci_alloc_consistent(), used above to alloc DMA regions, * ALWAYS returns SAC (32-bit) addresses. If DAC (64-bit) addresses * are ever returned, make sure the high part is retrieved here before * storing the adjusted address. */ - rx_ring->pPSRingRealPa = rx_ring->pPSRingPa; - - /* Align Packet Status Ring on a 4K boundary */ - et131x_align_allocated_memory(adapter, - &rx_ring->pPSRingRealPa, - &rx_ring->pPSRingOffset, 0x0FFF); - - rx_ring->pPSRingVa = (void *)((uint8_t *) rx_ring->pPSRingVa + - rx_ring->pPSRingOffset); /* Allocate an area of memory for writeback of status information */ rx_ring->pRxStatusVa = pci_alloc_consistent(adapter->pdev, - sizeof(RX_STATUS_BLOCK_t) + - 0x7, &rx_ring->pRxStatusPa); + sizeof(RX_STATUS_BLOCK_t), + &rx_ring->pRxStatusPa); if (!rx_ring->pRxStatusVa) { dev_err(&adapter->pdev->dev, "Cannot alloc memory for Status Block\n"); return -ENOMEM; } - - /* Save physical address */ - rx_ring->RxStatusRealPA = rx_ring->pRxStatusPa; - - /* Align write back on an 8 byte boundary */ - et131x_align_allocated_memory(adapter, - &rx_ring->RxStatusRealPA, - &rx_ring->RxStatusOffset, 0x07); - - rx_ring->pRxStatusVa = (void *)((uint8_t *) rx_ring->pRxStatusVa + - rx_ring->RxStatusOffset); rx_ring->NumRfd = NIC_DEFAULT_NUM_RFD; + printk("PRS %lx\n", (unsigned long)rx_ring->pRxStatusPa); /* Recv * pci_pool_create initializes a lookaside list. After successful @@ -409,7 +390,6 @@ int et131x_rx_dma_memory_alloc(struct et131x_adapter *adapter) * lists now. */ INIT_LIST_HEAD(&rx_ring->RecvList); - INIT_LIST_HEAD(&rx_ring->RecvPendingList); return 0; } @@ -419,10 +399,10 @@ int et131x_rx_dma_memory_alloc(struct et131x_adapter *adapter) */ void et131x_rx_dma_memory_free(struct et131x_adapter *adapter) { - uint32_t index; - uint32_t bufsize; - uint32_t pktStatRingSize; - PMP_RFD pMpRfd; + u32 index; + u32 bufsize; + u32 pktStatRingSize; + PMP_RFD rfd; RX_RING_t *rx_ring; /* Setup some convenience pointers */ @@ -432,18 +412,12 @@ void et131x_rx_dma_memory_free(struct et131x_adapter *adapter) WARN_ON(rx_ring->nReadyRecv != rx_ring->NumRfd); while (!list_empty(&rx_ring->RecvList)) { - pMpRfd = (MP_RFD *) list_entry(rx_ring->RecvList.next, + rfd = (MP_RFD *) list_entry(rx_ring->RecvList.next, MP_RFD, list_node); - list_del(&pMpRfd->list_node); - et131x_rfd_resources_free(adapter, pMpRfd); - } - - while (!list_empty(&rx_ring->RecvPendingList)) { - pMpRfd = (MP_RFD *) list_entry(rx_ring->RecvPendingList.next, - MP_RFD, list_node); - list_del(&pMpRfd->list_node); - et131x_rfd_resources_free(adapter, pMpRfd); + list_del(&rfd->list_node); + rfd->Packet = NULL; + kmem_cache_free(adapter->RxRing.RecvLookaside, rfd); } /* Free Free Buffer Ring 1 */ @@ -452,7 +426,7 @@ void et131x_rx_dma_memory_free(struct et131x_adapter *adapter) for (index = 0; index < (rx_ring->Fbr1NumEntries / FBR_CHUNKS); index++) { if (rx_ring->Fbr1MemVa[index]) { - uint32_t Fbr1Align; + u32 Fbr1Align; if (rx_ring->Fbr1BufferSize > 4096) Fbr1Align = 4096; @@ -523,14 +497,10 @@ void et131x_rx_dma_memory_free(struct et131x_adapter *adapter) /* Free Packet Status Ring */ if (rx_ring->pPSRingVa) { - rx_ring->pPSRingVa = (void *)((uint8_t *) rx_ring->pPSRingVa - - rx_ring->pPSRingOffset); - pktStatRingSize = sizeof(PKT_STAT_DESC_t) * adapter->RxRing.PsrNumEntries; - pci_free_consistent(adapter->pdev, - pktStatRingSize + 0x0fff, + pci_free_consistent(adapter->pdev, pktStatRingSize, rx_ring->pPSRingVa, rx_ring->pPSRingPa); rx_ring->pPSRingVa = NULL; @@ -538,11 +508,8 @@ void et131x_rx_dma_memory_free(struct et131x_adapter *adapter) /* Free area of memory for the writeback of status information */ if (rx_ring->pRxStatusVa) { - rx_ring->pRxStatusVa = (void *)((uint8_t *) - rx_ring->pRxStatusVa - rx_ring->RxStatusOffset); - pci_free_consistent(adapter->pdev, - sizeof(RX_STATUS_BLOCK_t) + 0x7, + sizeof(RX_STATUS_BLOCK_t), rx_ring->pRxStatusVa, rx_ring->pRxStatusPa); rx_ring->pRxStatusVa = NULL; @@ -578,49 +545,43 @@ void et131x_rx_dma_memory_free(struct et131x_adapter *adapter) int et131x_init_recv(struct et131x_adapter *adapter) { int status = -ENOMEM; - PMP_RFD pMpRfd = NULL; - uint32_t RfdCount; - uint32_t TotalNumRfd = 0; + PMP_RFD rfd = NULL; + u32 rfdct; + u32 numrfd = 0; RX_RING_t *rx_ring = NULL; /* Setup some convenience pointers */ rx_ring = (RX_RING_t *) &adapter->RxRing; /* Setup each RFD */ - for (RfdCount = 0; RfdCount < rx_ring->NumRfd; RfdCount++) { - pMpRfd = (MP_RFD *) kmem_cache_alloc(rx_ring->RecvLookaside, + for (rfdct = 0; rfdct < rx_ring->NumRfd; rfdct++) { + rfd = (MP_RFD *) kmem_cache_alloc(rx_ring->RecvLookaside, GFP_ATOMIC | GFP_DMA); - if (!pMpRfd) { + if (!rfd) { dev_err(&adapter->pdev->dev, "Couldn't alloc RFD out of kmem_cache\n"); status = -ENOMEM; continue; } - status = et131x_rfd_resources_alloc(adapter, pMpRfd); - if (status != 0) { - dev_err(&adapter->pdev->dev, - "Couldn't alloc packet for RFD\n"); - kmem_cache_free(rx_ring->RecvLookaside, pMpRfd); - continue; - } + rfd->Packet = NULL; /* Add this RFD to the RecvList */ - list_add_tail(&pMpRfd->list_node, &rx_ring->RecvList); + list_add_tail(&rfd->list_node, &rx_ring->RecvList); /* Increment both the available RFD's, and the total RFD's. */ rx_ring->nReadyRecv++; - TotalNumRfd++; + numrfd++; } - if (TotalNumRfd > NIC_MIN_NUM_RFD) + if (numrfd > NIC_MIN_NUM_RFD) status = 0; - rx_ring->NumRfd = TotalNumRfd; + rx_ring->NumRfd = numrfd; if (status != 0) { - kmem_cache_free(rx_ring->RecvLookaside, pMpRfd); + kmem_cache_free(rx_ring->RecvLookaside, rfd); dev_err(&adapter->pdev->dev, "Allocation problems in et131x_init_recv\n"); } @@ -628,41 +589,16 @@ int et131x_init_recv(struct et131x_adapter *adapter) } /** - * et131x_rfd_resources_alloc - * @adapter: pointer to our private adapter structure - * @pMpRfd: pointer to a RFD - * - * Returns 0 on success and errno on failure (as defined in errno.h) - */ -int et131x_rfd_resources_alloc(struct et131x_adapter *adapter, MP_RFD *pMpRfd) -{ - pMpRfd->Packet = NULL; - - return 0; -} - -/** - * et131x_rfd_resources_free - Free the packet allocated for the given RFD - * @adapter: pointer to our private adapter structure - * @pMpRfd: pointer to a RFD - */ -void et131x_rfd_resources_free(struct et131x_adapter *adapter, MP_RFD *pMpRfd) -{ - pMpRfd->Packet = NULL; - kmem_cache_free(adapter->RxRing.RecvLookaside, pMpRfd); -} - -/** * ConfigRxDmaRegs - Start of Rx_DMA init sequence * @etdev: pointer to our adapter structure */ void ConfigRxDmaRegs(struct et131x_adapter *etdev) { struct _RXDMA_t __iomem *rx_dma = &etdev->regs->rxdma; - struct _rx_ring_t *pRxLocal = &etdev->RxRing; + struct _rx_ring_t *rx_local = &etdev->RxRing; PFBR_DESC_t fbr_entry; - uint32_t entry; - RXDMA_PSR_NUM_DES_t psr_num_des; + u32 entry; + u32 psr_num_des; unsigned long flags; /* Halt RXDMA to perform the reconfigure. */ @@ -675,36 +611,35 @@ void ConfigRxDmaRegs(struct et131x_adapter *etdev) * are ever returned, make sure the high part is retrieved here * before storing the adjusted address. */ - writel((uint32_t) (pRxLocal->RxStatusRealPA >> 32), + writel((u32) ((u64)rx_local->pRxStatusPa >> 32), &rx_dma->dma_wb_base_hi); - writel((uint32_t) pRxLocal->RxStatusRealPA, &rx_dma->dma_wb_base_lo); + writel((u32) rx_local->pRxStatusPa, &rx_dma->dma_wb_base_lo); - memset(pRxLocal->pRxStatusVa, 0, sizeof(RX_STATUS_BLOCK_t)); + memset(rx_local->pRxStatusVa, 0, sizeof(RX_STATUS_BLOCK_t)); /* Set the address and parameters of the packet status ring into the * 1310's registers */ - writel((uint32_t) (pRxLocal->pPSRingRealPa >> 32), + writel((u32) ((u64)rx_local->pPSRingPa >> 32), &rx_dma->psr_base_hi); - writel((uint32_t) pRxLocal->pPSRingRealPa, &rx_dma->psr_base_lo); - writel(pRxLocal->PsrNumEntries - 1, &rx_dma->psr_num_des.value); - writel(0, &rx_dma->psr_full_offset.value); + writel((u32) rx_local->pPSRingPa, &rx_dma->psr_base_lo); + writel(rx_local->PsrNumEntries - 1, &rx_dma->psr_num_des); + writel(0, &rx_dma->psr_full_offset); - psr_num_des.value = readl(&rx_dma->psr_num_des.value); - writel((psr_num_des.bits.psr_ndes * LO_MARK_PERCENT_FOR_PSR) / 100, - &rx_dma->psr_min_des.value); + psr_num_des = readl(&rx_dma->psr_num_des) & 0xFFF; + writel((psr_num_des * LO_MARK_PERCENT_FOR_PSR) / 100, + &rx_dma->psr_min_des); spin_lock_irqsave(&etdev->RcvLock, flags); /* These local variables track the PSR in the adapter structure */ - pRxLocal->local_psr_full.bits.psr_full = 0; - pRxLocal->local_psr_full.bits.psr_full_wrap = 0; + rx_local->local_psr_full = 0; /* Now's the best time to initialize FBR1 contents */ - fbr_entry = (PFBR_DESC_t) pRxLocal->pFbr1RingVa; - for (entry = 0; entry < pRxLocal->Fbr1NumEntries; entry++) { - fbr_entry->addr_hi = pRxLocal->Fbr[1]->PAHigh[entry]; - fbr_entry->addr_lo = pRxLocal->Fbr[1]->PALow[entry]; + fbr_entry = (PFBR_DESC_t) rx_local->pFbr1RingVa; + for (entry = 0; entry < rx_local->Fbr1NumEntries; entry++) { + fbr_entry->addr_hi = rx_local->Fbr[1]->PAHigh[entry]; + fbr_entry->addr_lo = rx_local->Fbr[1]->PALow[entry]; fbr_entry->word2.bits.bi = entry; fbr_entry++; } @@ -712,39 +647,39 @@ void ConfigRxDmaRegs(struct et131x_adapter *etdev) /* Set the address and parameters of Free buffer ring 1 (and 0 if * required) into the 1310's registers */ - writel((uint32_t) (pRxLocal->Fbr1Realpa >> 32), &rx_dma->fbr1_base_hi); - writel((uint32_t) pRxLocal->Fbr1Realpa, &rx_dma->fbr1_base_lo); - writel(pRxLocal->Fbr1NumEntries - 1, &rx_dma->fbr1_num_des.value); + writel((u32) (rx_local->Fbr1Realpa >> 32), &rx_dma->fbr1_base_hi); + writel((u32) rx_local->Fbr1Realpa, &rx_dma->fbr1_base_lo); + writel(rx_local->Fbr1NumEntries - 1, &rx_dma->fbr1_num_des); writel(ET_DMA10_WRAP, &rx_dma->fbr1_full_offset); /* This variable tracks the free buffer ring 1 full position, so it * has to match the above. */ - pRxLocal->local_Fbr1_full = ET_DMA10_WRAP; - writel(((pRxLocal->Fbr1NumEntries * LO_MARK_PERCENT_FOR_RX) / 100) - 1, - &rx_dma->fbr1_min_des.value); + rx_local->local_Fbr1_full = ET_DMA10_WRAP; + writel(((rx_local->Fbr1NumEntries * LO_MARK_PERCENT_FOR_RX) / 100) - 1, + &rx_dma->fbr1_min_des); #ifdef USE_FBR0 /* Now's the best time to initialize FBR0 contents */ - fbr_entry = (PFBR_DESC_t) pRxLocal->pFbr0RingVa; - for (entry = 0; entry < pRxLocal->Fbr0NumEntries; entry++) { - fbr_entry->addr_hi = pRxLocal->Fbr[0]->PAHigh[entry]; - fbr_entry->addr_lo = pRxLocal->Fbr[0]->PALow[entry]; + fbr_entry = (PFBR_DESC_t) rx_local->pFbr0RingVa; + for (entry = 0; entry < rx_local->Fbr0NumEntries; entry++) { + fbr_entry->addr_hi = rx_local->Fbr[0]->PAHigh[entry]; + fbr_entry->addr_lo = rx_local->Fbr[0]->PALow[entry]; fbr_entry->word2.bits.bi = entry; fbr_entry++; } - writel((uint32_t) (pRxLocal->Fbr0Realpa >> 32), &rx_dma->fbr0_base_hi); - writel((uint32_t) pRxLocal->Fbr0Realpa, &rx_dma->fbr0_base_lo); - writel(pRxLocal->Fbr0NumEntries - 1, &rx_dma->fbr0_num_des.value); + writel((u32) (rx_local->Fbr0Realpa >> 32), &rx_dma->fbr0_base_hi); + writel((u32) rx_local->Fbr0Realpa, &rx_dma->fbr0_base_lo); + writel(rx_local->Fbr0NumEntries - 1, &rx_dma->fbr0_num_des); writel(ET_DMA10_WRAP, &rx_dma->fbr0_full_offset); /* This variable tracks the free buffer ring 0 full position, so it * has to match the above. */ - pRxLocal->local_Fbr0_full = ET_DMA10_WRAP; - writel(((pRxLocal->Fbr0NumEntries * LO_MARK_PERCENT_FOR_RX) / 100) - 1, - &rx_dma->fbr0_min_des.value); + rx_local->local_Fbr0_full = ET_DMA10_WRAP; + writel(((rx_local->Fbr0NumEntries * LO_MARK_PERCENT_FOR_RX) / 100) - 1, + &rx_dma->fbr0_min_des); #endif /* Program the number of packets we will receive before generating an @@ -752,14 +687,14 @@ void ConfigRxDmaRegs(struct et131x_adapter *etdev) * For version B silicon, this value gets updated once autoneg is *complete. */ - writel(PARM_RX_NUM_BUFS_DEF, &rx_dma->num_pkt_done.value); + writel(PARM_RX_NUM_BUFS_DEF, &rx_dma->num_pkt_done); /* The "time_done" is not working correctly to coalesce interrupts * after a given time period, but rather is giving us an interrupt * regardless of whether we have received packets. * This value gets updated once autoneg is complete. */ - writel(PARM_RX_TIME_INT_DEF, &rx_dma->max_pkt_time.value); + writel(PARM_RX_TIME_INT_DEF, &rx_dma->max_pkt_time); spin_unlock_irqrestore(&etdev->RcvLock, flags); } @@ -775,8 +710,8 @@ void SetRxDmaTimer(struct et131x_adapter *etdev) */ if ((etdev->linkspeed == TRUEPHY_SPEED_100MBPS) || (etdev->linkspeed == TRUEPHY_SPEED_10MBPS)) { - writel(0, &etdev->regs->rxdma.max_pkt_time.value); - writel(1, &etdev->regs->rxdma.num_pkt_done.value); + writel(0, &etdev->regs->rxdma.max_pkt_time); + writel(1, &etdev->regs->rxdma.num_pkt_done); } } @@ -807,40 +742,35 @@ void et131x_rx_dma_disable(struct et131x_adapter *etdev) */ void et131x_rx_dma_enable(struct et131x_adapter *etdev) { - if (etdev->RegistryPhyLoopbk) - /* RxDMA is disabled for loopback operation. */ - writel(0x1, &etdev->regs->rxdma.csr.value); - else { /* Setup the receive dma configuration register for normal operation */ - RXDMA_CSR_t csr = { 0 }; - - csr.bits.fbr1_enable = 1; - if (etdev->RxRing.Fbr1BufferSize == 4096) - csr.bits.fbr1_size = 1; - else if (etdev->RxRing.Fbr1BufferSize == 8192) - csr.bits.fbr1_size = 2; - else if (etdev->RxRing.Fbr1BufferSize == 16384) - csr.bits.fbr1_size = 3; + RXDMA_CSR_t csr = { 0 }; + + csr.bits.fbr1_enable = 1; + if (etdev->RxRing.Fbr1BufferSize == 4096) + csr.bits.fbr1_size = 1; + else if (etdev->RxRing.Fbr1BufferSize == 8192) + csr.bits.fbr1_size = 2; + else if (etdev->RxRing.Fbr1BufferSize == 16384) + csr.bits.fbr1_size = 3; #ifdef USE_FBR0 - csr.bits.fbr0_enable = 1; - if (etdev->RxRing.Fbr0BufferSize == 256) - csr.bits.fbr0_size = 1; - else if (etdev->RxRing.Fbr0BufferSize == 512) - csr.bits.fbr0_size = 2; - else if (etdev->RxRing.Fbr0BufferSize == 1024) - csr.bits.fbr0_size = 3; + csr.bits.fbr0_enable = 1; + if (etdev->RxRing.Fbr0BufferSize == 256) + csr.bits.fbr0_size = 1; + else if (etdev->RxRing.Fbr0BufferSize == 512) + csr.bits.fbr0_size = 2; + else if (etdev->RxRing.Fbr0BufferSize == 1024) + csr.bits.fbr0_size = 3; #endif - writel(csr.value, &etdev->regs->rxdma.csr.value); + writel(csr.value, &etdev->regs->rxdma.csr.value); + csr.value = readl(&etdev->regs->rxdma.csr.value); + if (csr.bits.halt_status != 0) { + udelay(5); csr.value = readl(&etdev->regs->rxdma.csr.value); if (csr.bits.halt_status != 0) { - udelay(5); - csr.value = readl(&etdev->regs->rxdma.csr.value); - if (csr.bits.halt_status != 0) { - dev_err(&etdev->pdev->dev, - "RX Dma failed to exit halt state. CSR 0x%08x\n", - csr.value); - } + dev_err(&etdev->pdev->dev, + "RX Dma failed to exit halt state. CSR 0x%08x\n", + csr.value); } } } @@ -849,7 +779,7 @@ void et131x_rx_dma_enable(struct et131x_adapter *etdev) * nic_rx_pkts - Checks the hardware for available packets * @etdev: pointer to our adapter * - * Returns pMpRfd, a pointer to our MPRFD. + * Returns rfd, a pointer to our MPRFD. * * Checks the hardware for available packets, using completion ring * If packets are available, it gets an RFD from the RecvList, attaches @@ -858,119 +788,122 @@ void et131x_rx_dma_enable(struct et131x_adapter *etdev) */ PMP_RFD nic_rx_pkts(struct et131x_adapter *etdev) { - struct _rx_ring_t *pRxLocal = &etdev->RxRing; - PRX_STATUS_BLOCK_t pRxStatusBlock; - PPKT_STAT_DESC_t pPSREntry; - PMP_RFD pMpRfd; - uint32_t nIndex; - uint8_t *pBufVa; + struct _rx_ring_t *rx_local = &etdev->RxRing; + PRX_STATUS_BLOCK_t status; + PPKT_STAT_DESC_t psr; + PMP_RFD rfd; + u32 i; + uint8_t *buf; unsigned long flags; struct list_head *element; - uint8_t ringIndex; - uint16_t bufferIndex; - uint32_t localLen; + uint8_t rindex; + uint16_t bindex; + u32 len; PKT_STAT_DESC_WORD0_t Word0; /* RX Status block is written by the DMA engine prior to every * interrupt. It contains the next to be used entry in the Packet * Status Ring, and also the two Free Buffer rings. */ - pRxStatusBlock = (PRX_STATUS_BLOCK_t) pRxLocal->pRxStatusVa; + status = (PRX_STATUS_BLOCK_t) rx_local->pRxStatusVa; - if (pRxStatusBlock->Word1.bits.PSRoffset == - pRxLocal->local_psr_full.bits.psr_full && - pRxStatusBlock->Word1.bits.PSRwrap == - pRxLocal->local_psr_full.bits.psr_full_wrap) { + /* FIXME: tidy later when conversions complete */ + if (status->Word1.bits.PSRoffset == + (rx_local->local_psr_full & 0xFFF) && + status->Word1.bits.PSRwrap == + ((rx_local->local_psr_full >> 12) & 1)) { /* Looks like this ring is not updated yet */ return NULL; } /* The packet status ring indicates that data is available. */ - pPSREntry = (PPKT_STAT_DESC_t) (pRxLocal->pPSRingVa) + - pRxLocal->local_psr_full.bits.psr_full; + psr = (PPKT_STAT_DESC_t) (rx_local->pPSRingVa) + + (rx_local->local_psr_full & 0xFFF); /* Grab any information that is required once the PSR is * advanced, since we can no longer rely on the memory being * accurate */ - localLen = pPSREntry->word1.bits.length; - ringIndex = (uint8_t) pPSREntry->word1.bits.ri; - bufferIndex = (uint16_t) pPSREntry->word1.bits.bi; - Word0 = pPSREntry->word0; + len = psr->word1.bits.length; + rindex = (uint8_t) psr->word1.bits.ri; + bindex = (uint16_t) psr->word1.bits.bi; + Word0 = psr->word0; /* Indicate that we have used this PSR entry. */ - if (++pRxLocal->local_psr_full.bits.psr_full > - pRxLocal->PsrNumEntries - 1) { - pRxLocal->local_psr_full.bits.psr_full = 0; - pRxLocal->local_psr_full.bits.psr_full_wrap ^= 1; + /* FIXME wrap 12 */ + rx_local->local_psr_full = (rx_local->local_psr_full + 1) & 0xFFF; + if (rx_local->local_psr_full > rx_local->PsrNumEntries - 1) { + /* Clear psr full and toggle the wrap bit */ + rx_local->local_psr_full &= 0xFFF; + rx_local->local_psr_full ^= 0x1000; } - writel(pRxLocal->local_psr_full.value, - &etdev->regs->rxdma.psr_full_offset.value); + writel(rx_local->local_psr_full, + &etdev->regs->rxdma.psr_full_offset); #ifndef USE_FBR0 - if (ringIndex != 1) { + if (rindex != 1) { return NULL; } #endif #ifdef USE_FBR0 - if (ringIndex > 1 || - (ringIndex == 0 && - bufferIndex > pRxLocal->Fbr0NumEntries - 1) || - (ringIndex == 1 && - bufferIndex > pRxLocal->Fbr1NumEntries - 1)) + if (rindex > 1 || + (rindex == 0 && + bindex > rx_local->Fbr0NumEntries - 1) || + (rindex == 1 && + bindex > rx_local->Fbr1NumEntries - 1)) #else - if (ringIndex != 1 || - bufferIndex > pRxLocal->Fbr1NumEntries - 1) + if (rindex != 1 || + bindex > rx_local->Fbr1NumEntries - 1) #endif { /* Illegal buffer or ring index cannot be used by S/W*/ dev_err(&etdev->pdev->dev, "NICRxPkts PSR Entry %d indicates " "length of %d and/or bad bi(%d)\n", - pRxLocal->local_psr_full.bits.psr_full, - localLen, bufferIndex); + rx_local->local_psr_full & 0xFFF, + len, bindex); return NULL; } /* Get and fill the RFD. */ spin_lock_irqsave(&etdev->RcvLock, flags); - pMpRfd = NULL; - element = pRxLocal->RecvList.next; - pMpRfd = (PMP_RFD) list_entry(element, MP_RFD, list_node); + rfd = NULL; + element = rx_local->RecvList.next; + rfd = (PMP_RFD) list_entry(element, MP_RFD, list_node); - if (pMpRfd == NULL) { + if (rfd == NULL) { spin_unlock_irqrestore(&etdev->RcvLock, flags); return NULL; } - list_del(&pMpRfd->list_node); - pRxLocal->nReadyRecv--; + list_del(&rfd->list_node); + rx_local->nReadyRecv--; spin_unlock_irqrestore(&etdev->RcvLock, flags); - pMpRfd->bufferindex = bufferIndex; - pMpRfd->ringindex = ringIndex; + rfd->bufferindex = bindex; + rfd->ringindex = rindex; /* In V1 silicon, there is a bug which screws up filtering of * runt packets. Therefore runt packet filtering is disabled * in the MAC and the packets are dropped here. They are * also counted here. */ - if (localLen < (NIC_MIN_PACKET_SIZE + 4)) { + if (len < (NIC_MIN_PACKET_SIZE + 4)) { etdev->Stats.other_errors++; - localLen = 0; + len = 0; } - if (localLen) { + if (len) { if (etdev->ReplicaPhyLoopbk == 1) { - pBufVa = pRxLocal->Fbr[ringIndex]->Va[bufferIndex]; + buf = rx_local->Fbr[rindex]->Va[bindex]; - if (memcmp(&pBufVa[6], &etdev->CurrentAddress[0], + if (memcmp(&buf[6], &etdev->CurrentAddress[0], ETH_ALEN) == 0) { - if (memcmp(&pBufVa[42], "Replica packet", + if (memcmp(&buf[42], "Replica packet", ETH_HLEN)) { etdev->ReplicaPhyLoopbkPF = 1; } @@ -990,28 +923,28 @@ PMP_RFD nic_rx_pkts(struct et131x_adapter *etdev) if ((etdev->PacketFilter & ET131X_PACKET_TYPE_MULTICAST) && !(etdev->PacketFilter & ET131X_PACKET_TYPE_PROMISCUOUS) && !(etdev->PacketFilter & ET131X_PACKET_TYPE_ALL_MULTICAST)) { - pBufVa = pRxLocal->Fbr[ringIndex]-> - Va[bufferIndex]; + buf = rx_local->Fbr[rindex]-> + Va[bindex]; /* Loop through our list to see if the * destination address of this packet * matches one in our list. */ - for (nIndex = 0; - nIndex < etdev->MCAddressCount; - nIndex++) { - if (pBufVa[0] == - etdev->MCList[nIndex][0] - && pBufVa[1] == - etdev->MCList[nIndex][1] - && pBufVa[2] == - etdev->MCList[nIndex][2] - && pBufVa[3] == - etdev->MCList[nIndex][3] - && pBufVa[4] == - etdev->MCList[nIndex][4] - && pBufVa[5] == - etdev->MCList[nIndex][5]) { + for (i = 0; + i < etdev->MCAddressCount; + i++) { + if (buf[0] == + etdev->MCList[i][0] + && buf[1] == + etdev->MCList[i][1] + && buf[2] == + etdev->MCList[i][2] + && buf[3] == + etdev->MCList[i][3] + && buf[4] == + etdev->MCList[i][4] + && buf[5] == + etdev->MCList[i][5]) { break; } } @@ -1024,11 +957,11 @@ PMP_RFD nic_rx_pkts(struct et131x_adapter *etdev) * so we free our RFD when we return * from this function. */ - if (nIndex == etdev->MCAddressCount) - localLen = 0; + if (i == etdev->MCAddressCount) + len = 0; } - if (localLen > 0) + if (len > 0) etdev->Stats.multircv++; } else if (Word0.value & ALCATEL_BROADCAST_PKT) etdev->Stats.brdcstrcv++; @@ -1041,24 +974,24 @@ PMP_RFD nic_rx_pkts(struct et131x_adapter *etdev) etdev->Stats.unircv++; } - if (localLen > 0) { + if (len > 0) { struct sk_buff *skb = NULL; - /* pMpRfd->PacketSize = localLen - 4; */ - pMpRfd->PacketSize = localLen; + /* rfd->PacketSize = len - 4; */ + rfd->PacketSize = len; - skb = dev_alloc_skb(pMpRfd->PacketSize + 2); + skb = dev_alloc_skb(rfd->PacketSize + 2); if (!skb) { dev_err(&etdev->pdev->dev, "Couldn't alloc an SKB for Rx\n"); return NULL; } - etdev->net_stats.rx_bytes += pMpRfd->PacketSize; + etdev->net_stats.rx_bytes += rfd->PacketSize; - memcpy(skb_put(skb, pMpRfd->PacketSize), - pRxLocal->Fbr[ringIndex]->Va[bufferIndex], - pMpRfd->PacketSize); + memcpy(skb_put(skb, rfd->PacketSize), + rx_local->Fbr[rindex]->Va[bindex], + rfd->PacketSize); skb->dev = etdev->netdev; skb->protocol = eth_type_trans(skb, etdev->netdev); @@ -1066,11 +999,11 @@ PMP_RFD nic_rx_pkts(struct et131x_adapter *etdev) netif_rx(skb); } else { - pMpRfd->PacketSize = 0; + rfd->PacketSize = 0; } - nic_return_rfd(etdev, pMpRfd); - return pMpRfd; + nic_return_rfd(etdev, rfd); + return rfd; } /** @@ -1081,21 +1014,8 @@ PMP_RFD nic_rx_pkts(struct et131x_adapter *etdev) */ void et131x_reset_recv(struct et131x_adapter *etdev) { - PMP_RFD pMpRfd; - struct list_head *element; - WARN_ON(list_empty(&etdev->RxRing.RecvList)); - /* Take all the RFD's from the pending list, and stick them on the - * RecvList. - */ - while (!list_empty(&etdev->RxRing.RecvPendingList)) { - element = etdev->RxRing.RecvPendingList.next; - - pMpRfd = (PMP_RFD) list_entry(element, MP_RFD, list_node); - - list_move_tail(&pMpRfd->list_node, &etdev->RxRing.RecvList); - } } /** @@ -1106,27 +1026,21 @@ void et131x_reset_recv(struct et131x_adapter *etdev) */ void et131x_handle_recv_interrupt(struct et131x_adapter *etdev) { - PMP_RFD pMpRfd = NULL; - struct sk_buff *PacketArray[NUM_PACKETS_HANDLED]; - PMP_RFD RFDFreeArray[NUM_PACKETS_HANDLED]; - uint32_t PacketArrayCount = 0; - uint32_t PacketsToHandle; - uint32_t PacketFreeCount = 0; - bool TempUnfinishedRec = false; - - PacketsToHandle = NUM_PACKETS_HANDLED; + PMP_RFD rfd = NULL; + u32 count = 0; + bool done = true; /* Process up to available RFD's */ - while (PacketArrayCount < PacketsToHandle) { + while (count < NUM_PACKETS_HANDLED) { if (list_empty(&etdev->RxRing.RecvList)) { WARN_ON(etdev->RxRing.nReadyRecv != 0); - TempUnfinishedRec = true; + done = false; break; } - pMpRfd = nic_rx_pkts(etdev); + rfd = nic_rx_pkts(etdev); - if (pMpRfd == NULL) + if (rfd == NULL) break; /* Do not receive any packets until a filter has been set. @@ -1136,7 +1050,7 @@ void et131x_handle_recv_interrupt(struct et131x_adapter *etdev) */ if (!etdev->PacketFilter || !(etdev->Flags & fMP_ADAPTER_LINK_DETECTION) || - pMpRfd->PacketSize == 0) { + rfd->PacketSize == 0) { continue; } @@ -1144,35 +1058,20 @@ void et131x_handle_recv_interrupt(struct et131x_adapter *etdev) etdev->Stats.ipackets++; /* Set the status on the packet, either resources or success */ - if (etdev->RxRing.nReadyRecv >= RFD_LOW_WATER_MARK) { - /* Put this RFD on the pending list - * - * NOTE: nic_rx_pkts() above is already returning the - * RFD to the RecvList, so don't additionally do that - * here. - * Besides, we don't really need (at this point) the - * pending list anyway. - */ - } else { - RFDFreeArray[PacketFreeCount] = pMpRfd; - PacketFreeCount++; - + if (etdev->RxRing.nReadyRecv < RFD_LOW_WATER_MARK) { dev_warn(&etdev->pdev->dev, "RFD's are running out\n"); } - - PacketArray[PacketArrayCount] = pMpRfd->Packet; - PacketArrayCount++; + count++; } - if ((PacketArrayCount == NUM_PACKETS_HANDLED) || TempUnfinishedRec) { + if (count == NUM_PACKETS_HANDLED || !done) { etdev->RxRing.UnfinishedReceives = true; writel(PARM_TX_TIME_INT_DEF * NANO_IN_A_MICRO, &etdev->regs->global.watchdog_timer); - } else { + } else /* Watchdog timer will disable itself if appropriate. */ etdev->RxRing.UnfinishedReceives = false; - } } static inline u32 bump_fbr(u32 *fbr, u32 limit) @@ -1196,14 +1095,14 @@ static inline u32 bump_fbr(u32 *fbr, u32 limit) /** * NICReturnRFD - Recycle a RFD and put it back onto the receive list * @etdev: pointer to our adapter - * @pMpRfd: pointer to the RFD + * @rfd: pointer to the RFD */ -void nic_return_rfd(struct et131x_adapter *etdev, PMP_RFD pMpRfd) +void nic_return_rfd(struct et131x_adapter *etdev, PMP_RFD rfd) { struct _rx_ring_t *rx_local = &etdev->RxRing; struct _RXDMA_t __iomem *rx_dma = &etdev->regs->rxdma; - uint16_t bi = pMpRfd->bufferindex; - uint8_t ri = pMpRfd->ringindex; + uint16_t bi = rfd->bufferindex; + uint8_t ri = rfd->ringindex; unsigned long flags; /* We don't use any of the OOB data besides status. Otherwise, we @@ -1217,7 +1116,7 @@ void nic_return_rfd(struct et131x_adapter *etdev, PMP_RFD pMpRfd) spin_lock_irqsave(&etdev->FbrLock, flags); if (ri == 1) { - PFBR_DESC_t pNextDesc = + PFBR_DESC_t next = (PFBR_DESC_t) (rx_local->pFbr1RingVa) + INDEX10(rx_local->local_Fbr1_full); @@ -1225,9 +1124,9 @@ void nic_return_rfd(struct et131x_adapter *etdev, PMP_RFD pMpRfd) * the PA / Buffer Index for the returned buffer into * the oldest (next to be freed)FBR entry */ - pNextDesc->addr_hi = rx_local->Fbr[1]->PAHigh[bi]; - pNextDesc->addr_lo = rx_local->Fbr[1]->PALow[bi]; - pNextDesc->word2.value = bi; + next->addr_hi = rx_local->Fbr[1]->PAHigh[bi]; + next->addr_lo = rx_local->Fbr[1]->PALow[bi]; + next->word2.value = bi; writel(bump_fbr(&rx_local->local_Fbr1_full, rx_local->Fbr1NumEntries - 1), @@ -1235,7 +1134,7 @@ void nic_return_rfd(struct et131x_adapter *etdev, PMP_RFD pMpRfd) } #ifdef USE_FBR0 else { - PFBR_DESC_t pNextDesc = + PFBR_DESC_t next = (PFBR_DESC_t) rx_local->pFbr0RingVa + INDEX10(rx_local->local_Fbr0_full); @@ -1243,9 +1142,9 @@ void nic_return_rfd(struct et131x_adapter *etdev, PMP_RFD pMpRfd) * the PA / Buffer Index for the returned buffer into * the oldest (next to be freed) FBR entry */ - pNextDesc->addr_hi = rx_local->Fbr[0]->PAHigh[bi]; - pNextDesc->addr_lo = rx_local->Fbr[0]->PALow[bi]; - pNextDesc->word2.value = bi; + next->addr_hi = rx_local->Fbr[0]->PAHigh[bi]; + next->addr_lo = rx_local->Fbr[0]->PALow[bi]; + next->word2.value = bi; writel(bump_fbr(&rx_local->local_Fbr0_full, rx_local->Fbr0NumEntries - 1), @@ -1262,7 +1161,7 @@ void nic_return_rfd(struct et131x_adapter *etdev, PMP_RFD pMpRfd) * our list */ spin_lock_irqsave(&etdev->RcvLock, flags); - list_add_tail(&pMpRfd->list_node, &rx_local->RecvList); + list_add_tail(&rfd->list_node, &rx_local->RecvList); rx_local->nReadyRecv++; spin_unlock_irqrestore(&etdev->RcvLock, flags); |