2008-04-04 00:30:53 +00:00
|
|
|
/*
|
|
|
|
* Agere Systems Inc.
|
|
|
|
* 10/100/1000 Base-T Ethernet Driver for the ET1301 and ET131x series MACs
|
|
|
|
*
|
2009-06-10 16:30:41 +00:00
|
|
|
* Copyright © 2005 Agere Systems Inc.
|
2008-04-04 00:30:53 +00:00
|
|
|
* All rights reserved.
|
|
|
|
* http://www.agere.com
|
|
|
|
*
|
|
|
|
*------------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* et1310_rx.c - Routines used to perform data reception
|
|
|
|
*
|
|
|
|
*------------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* SOFTWARE LICENSE
|
|
|
|
*
|
|
|
|
* This software is provided subject to the following terms and conditions,
|
|
|
|
* which you should read carefully before using the software. Using this
|
|
|
|
* software indicates your acceptance of these terms and conditions. If you do
|
|
|
|
* not agree with these terms and conditions, do not use the software.
|
|
|
|
*
|
2009-06-10 16:30:41 +00:00
|
|
|
* Copyright © 2005 Agere Systems Inc.
|
2008-04-04 00:30:53 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source or binary forms, with or without
|
|
|
|
* modifications, 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 as comments in the code as
|
|
|
|
* well as in the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
*
|
|
|
|
* . 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 Agere Systems Inc. nor the names of the contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* Disclaimer
|
|
|
|
*
|
2009-06-10 16:30:41 +00:00
|
|
|
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
2008-04-04 00:30:53 +00:00
|
|
|
* INCLUDING, BUT NOT LIMITED TO, INFRINGEMENT AND THE IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ANY
|
|
|
|
* USE, MODIFICATION OR DISTRIBUTION OF THIS SOFTWARE IS SOLELY AT THE USERS OWN
|
|
|
|
* RISK. IN NO EVENT SHALL AGERE SYSTEMS INC. 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, INCLUDING, BUT NOT LIMITED TO, 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "et131x_version.h"
|
|
|
|
#include "et131x_defs.h"
|
|
|
|
|
|
|
|
#include <linux/pci.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/ptrace.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/ctype.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/timer.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/in.h>
|
|
|
|
#include <linux/delay.h>
|
2009-06-10 16:30:41 +00:00
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/bitops.h>
|
2008-04-04 00:30:53 +00:00
|
|
|
#include <asm/system.h>
|
|
|
|
|
|
|
|
#include <linux/netdevice.h>
|
|
|
|
#include <linux/etherdevice.h>
|
|
|
|
#include <linux/skbuff.h>
|
|
|
|
#include <linux/if_arp.h>
|
|
|
|
#include <linux/ioport.h>
|
|
|
|
|
|
|
|
#include "et1310_phy.h"
|
|
|
|
#include "et1310_pm.h"
|
|
|
|
#include "et1310_jagcore.h"
|
|
|
|
|
|
|
|
#include "et131x_adapter.h"
|
|
|
|
#include "et131x_initpci.h"
|
|
|
|
|
|
|
|
#include "et1310_rx.h"
|
|
|
|
|
|
|
|
|
2009-08-19 17:21:44 +00:00
|
|
|
void nic_return_rfd(struct et131x_adapter *etdev, PMP_RFD pMpRfd);
|
2008-04-04 00:30:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* et131x_rx_dma_memory_alloc
|
|
|
|
* @adapter: pointer to our private adapter structure
|
|
|
|
*
|
|
|
|
* Returns 0 on success and errno on failure (as defined in errno.h)
|
|
|
|
*
|
|
|
|
* Allocates Free buffer ring 1 for sure, free buffer ring 0 if required,
|
|
|
|
* and the Packet Status Ring.
|
|
|
|
*/
|
|
|
|
int et131x_rx_dma_memory_alloc(struct et131x_adapter *adapter)
|
|
|
|
{
|
2009-10-06 14:48:57 +00:00
|
|
|
u32 i, j;
|
|
|
|
u32 bufsize;
|
|
|
|
u32 pktStatRingSize, FBRChunkSize;
|
2008-04-04 00:30:53 +00:00
|
|
|
RX_RING_t *rx_ring;
|
|
|
|
|
|
|
|
/* Setup some convenience pointers */
|
2009-06-10 16:30:41 +00:00
|
|
|
rx_ring = (RX_RING_t *) &adapter->RxRing;
|
2008-04-04 00:30:53 +00:00
|
|
|
|
|
|
|
/* Alloc memory for the lookup table */
|
|
|
|
#ifdef USE_FBR0
|
|
|
|
rx_ring->Fbr[0] = kmalloc(sizeof(FBRLOOKUPTABLE), GFP_KERNEL);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
rx_ring->Fbr[1] = kmalloc(sizeof(FBRLOOKUPTABLE), GFP_KERNEL);
|
|
|
|
|
|
|
|
/* The first thing we will do is configure the sizes of the buffer
|
|
|
|
* rings. These will change based on jumbo packet support. Larger
|
|
|
|
* jumbo packets increases the size of each entry in FBR0, and the
|
|
|
|
* number of entries in FBR0, while at the same time decreasing the
|
|
|
|
* number of entries in FBR1.
|
|
|
|
*
|
|
|
|
* FBR1 holds "large" frames, FBR0 holds "small" frames. If FBR1
|
|
|
|
* entries are huge in order to accomodate a "jumbo" frame, then it
|
|
|
|
* will have less entries. Conversely, FBR1 will now be relied upon
|
|
|
|
* to carry more "normal" frames, thus it's entry size also increases
|
|
|
|
* and the number of entries goes up too (since it now carries
|
|
|
|
* "small" + "regular" packets.
|
|
|
|
*
|
|
|
|
* In this scheme, we try to maintain 512 entries between the two
|
|
|
|
* rings. Also, FBR1 remains a constant size - when it's size doubles
|
|
|
|
* the number of entries halves. FBR0 increases in size, however.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (adapter->RegistryJumboPacket < 2048) {
|
|
|
|
#ifdef USE_FBR0
|
|
|
|
rx_ring->Fbr0BufferSize = 256;
|
|
|
|
rx_ring->Fbr0NumEntries = 512;
|
|
|
|
#endif
|
|
|
|
rx_ring->Fbr1BufferSize = 2048;
|
|
|
|
rx_ring->Fbr1NumEntries = 512;
|
|
|
|
} else if (adapter->RegistryJumboPacket < 4096) {
|
|
|
|
#ifdef USE_FBR0
|
|
|
|
rx_ring->Fbr0BufferSize = 512;
|
|
|
|
rx_ring->Fbr0NumEntries = 1024;
|
|
|
|
#endif
|
|
|
|
rx_ring->Fbr1BufferSize = 4096;
|
|
|
|
rx_ring->Fbr1NumEntries = 512;
|
|
|
|
} else {
|
|
|
|
#ifdef USE_FBR0
|
|
|
|
rx_ring->Fbr0BufferSize = 1024;
|
|
|
|
rx_ring->Fbr0NumEntries = 768;
|
|
|
|
#endif
|
|
|
|
rx_ring->Fbr1BufferSize = 16384;
|
|
|
|
rx_ring->Fbr1NumEntries = 128;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef USE_FBR0
|
|
|
|
adapter->RxRing.PsrNumEntries = adapter->RxRing.Fbr0NumEntries +
|
|
|
|
adapter->RxRing.Fbr1NumEntries;
|
|
|
|
#else
|
|
|
|
adapter->RxRing.PsrNumEntries = adapter->RxRing.Fbr1NumEntries;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Allocate an area of memory for Free Buffer Ring 1 */
|
|
|
|
bufsize = (sizeof(FBR_DESC_t) * rx_ring->Fbr1NumEntries) + 0xfff;
|
|
|
|
rx_ring->pFbr1RingVa = pci_alloc_consistent(adapter->pdev,
|
|
|
|
bufsize,
|
|
|
|
&rx_ring->pFbr1RingPa);
|
|
|
|
if (!rx_ring->pFbr1RingVa) {
|
2009-08-27 10:03:09 +00:00
|
|
|
dev_err(&adapter->pdev->dev,
|
2008-04-04 00:30:53 +00:00
|
|
|
"Cannot alloc memory for Free Buffer Ring 1\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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->Fbr1Realpa = rx_ring->pFbr1RingPa;
|
|
|
|
|
|
|
|
/* Align Free Buffer Ring 1 on a 4K boundary */
|
|
|
|
et131x_align_allocated_memory(adapter,
|
|
|
|
&rx_ring->Fbr1Realpa,
|
|
|
|
&rx_ring->Fbr1offset, 0x0FFF);
|
|
|
|
|
|
|
|
rx_ring->pFbr1RingVa = (void *)((uint8_t *) rx_ring->pFbr1RingVa +
|
|
|
|
rx_ring->Fbr1offset);
|
|
|
|
|
|
|
|
#ifdef USE_FBR0
|
|
|
|
/* Allocate an area of memory for Free Buffer Ring 0 */
|
|
|
|
bufsize = (sizeof(FBR_DESC_t) * rx_ring->Fbr0NumEntries) + 0xfff;
|
|
|
|
rx_ring->pFbr0RingVa = pci_alloc_consistent(adapter->pdev,
|
|
|
|
bufsize,
|
|
|
|
&rx_ring->pFbr0RingPa);
|
|
|
|
if (!rx_ring->pFbr0RingVa) {
|
2009-08-27 10:03:09 +00:00
|
|
|
dev_err(&adapter->pdev->dev,
|
2008-04-04 00:30:53 +00:00
|
|
|
"Cannot alloc memory for Free Buffer Ring 0\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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->Fbr0Realpa = rx_ring->pFbr0RingPa;
|
|
|
|
|
|
|
|
/* Align Free Buffer Ring 0 on a 4K boundary */
|
|
|
|
et131x_align_allocated_memory(adapter,
|
|
|
|
&rx_ring->Fbr0Realpa,
|
|
|
|
&rx_ring->Fbr0offset, 0x0FFF);
|
|
|
|
|
|
|
|
rx_ring->pFbr0RingVa = (void *)((uint8_t *) rx_ring->pFbr0RingVa +
|
|
|
|
rx_ring->Fbr0offset);
|
|
|
|
#endif
|
|
|
|
|
2009-10-06 14:48:57 +00:00
|
|
|
for (i = 0; i < (rx_ring->Fbr1NumEntries / FBR_CHUNKS);
|
|
|
|
i++) {
|
|
|
|
u64 Fbr1Offset;
|
|
|
|
u64 Fbr1TempPa;
|
|
|
|
u32 Fbr1Align;
|
2008-04-04 00:30:53 +00:00
|
|
|
|
|
|
|
/* This code allocates an area of memory big enough for N
|
|
|
|
* free buffers + (buffer_size - 1) so that the buffers can
|
|
|
|
* be aligned on 4k boundaries. If each buffer were aligned
|
|
|
|
* to a buffer_size boundary, the effect would be to double
|
|
|
|
* the size of FBR0. By allocating N buffers at once, we
|
|
|
|
* reduce this overhead.
|
|
|
|
*/
|
2009-06-10 16:30:41 +00:00
|
|
|
if (rx_ring->Fbr1BufferSize > 4096)
|
2008-04-04 00:30:53 +00:00
|
|
|
Fbr1Align = 4096;
|
2009-06-10 16:30:41 +00:00
|
|
|
else
|
2008-04-04 00:30:53 +00:00
|
|
|
Fbr1Align = rx_ring->Fbr1BufferSize;
|
|
|
|
|
|
|
|
FBRChunkSize =
|
|
|
|
(FBR_CHUNKS * rx_ring->Fbr1BufferSize) + Fbr1Align - 1;
|
2009-10-06 14:48:57 +00:00
|
|
|
rx_ring->Fbr1MemVa[i] =
|
2008-04-04 00:30:53 +00:00
|
|
|
pci_alloc_consistent(adapter->pdev, FBRChunkSize,
|
2009-10-06 14:48:57 +00:00
|
|
|
&rx_ring->Fbr1MemPa[i]);
|
2008-04-04 00:30:53 +00:00
|
|
|
|
2009-10-06 14:48:57 +00:00
|
|
|
if (!rx_ring->Fbr1MemVa[i]) {
|
2009-08-27 10:03:09 +00:00
|
|
|
dev_err(&adapter->pdev->dev,
|
|
|
|
"Could not alloc memory\n");
|
2008-04-04 00:30:53 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* See NOTE in "Save Physical Address" comment above */
|
2009-10-06 14:48:57 +00:00
|
|
|
Fbr1TempPa = rx_ring->Fbr1MemPa[i];
|
2008-04-04 00:30:53 +00:00
|
|
|
|
|
|
|
et131x_align_allocated_memory(adapter,
|
|
|
|
&Fbr1TempPa,
|
|
|
|
&Fbr1Offset, (Fbr1Align - 1));
|
|
|
|
|
2009-10-06 14:48:57 +00:00
|
|
|
for (j = 0; j < FBR_CHUNKS; j++) {
|
|
|
|
u32 index = (i * FBR_CHUNKS) + j;
|
2008-04-04 00:30:53 +00:00
|
|
|
|
|
|
|
/* Save the Virtual address of this index for quick
|
|
|
|
* access later
|
|
|
|
*/
|
|
|
|
rx_ring->Fbr[1]->Va[index] =
|
2009-10-06 14:48:57 +00:00
|
|
|
(uint8_t *) rx_ring->Fbr1MemVa[i] +
|
|
|
|
(j * rx_ring->Fbr1BufferSize) + Fbr1Offset;
|
2008-04-04 00:30:53 +00:00
|
|
|
|
|
|
|
/* now store the physical address in the descriptor
|
|
|
|
* so the device can access it
|
|
|
|
*/
|
|
|
|
rx_ring->Fbr[1]->PAHigh[index] =
|
2009-10-06 14:48:57 +00:00
|
|
|
(u32) (Fbr1TempPa >> 32);
|
|
|
|
rx_ring->Fbr[1]->PALow[index] = (u32) Fbr1TempPa;
|
2008-04-04 00:30:53 +00:00
|
|
|
|
|
|
|
Fbr1TempPa += rx_ring->Fbr1BufferSize;
|
|
|
|
|
|
|
|
rx_ring->Fbr[1]->Buffer1[index] =
|
|
|
|
rx_ring->Fbr[1]->Va[index];
|
|
|
|
rx_ring->Fbr[1]->Buffer2[index] =
|
|
|
|
rx_ring->Fbr[1]->Va[index] - 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef USE_FBR0
|
|
|
|
/* Same for FBR0 (if in use) */
|
2009-10-06 14:48:57 +00:00
|
|
|
for (i = 0; i < (rx_ring->Fbr0NumEntries / FBR_CHUNKS);
|
|
|
|
i++) {
|
|
|
|
u64 Fbr0Offset;
|
|
|
|
u64 Fbr0TempPa;
|
2008-04-04 00:30:53 +00:00
|
|
|
|
|
|
|
FBRChunkSize = ((FBR_CHUNKS + 1) * rx_ring->Fbr0BufferSize) - 1;
|
2009-10-06 14:48:57 +00:00
|
|
|
rx_ring->Fbr0MemVa[i] =
|
2008-04-04 00:30:53 +00:00
|
|
|
pci_alloc_consistent(adapter->pdev, FBRChunkSize,
|
2009-10-06 14:48:57 +00:00
|
|
|
&rx_ring->Fbr0MemPa[i]);
|
2008-04-04 00:30:53 +00:00
|
|
|
|
2009-10-06 14:48:57 +00:00
|
|
|
if (!rx_ring->Fbr0MemVa[i]) {
|
2009-08-27 10:03:09 +00:00
|
|
|
dev_err(&adapter->pdev->dev,
|
|
|
|
"Could not alloc memory\n");
|
2008-04-04 00:30:53 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* See NOTE in "Save Physical Address" comment above */
|
2009-10-06 14:48:57 +00:00
|
|
|
Fbr0TempPa = rx_ring->Fbr0MemPa[i];
|
2008-04-04 00:30:53 +00:00
|
|
|
|
|
|
|
et131x_align_allocated_memory(adapter,
|
|
|
|
&Fbr0TempPa,
|
|
|
|
&Fbr0Offset,
|
|
|
|
rx_ring->Fbr0BufferSize - 1);
|
|
|
|
|
2009-10-06 14:48:57 +00:00
|
|
|
for (j = 0; j < FBR_CHUNKS; j++) {
|
|
|
|
u32 index = (i * FBR_CHUNKS) + j;
|
2008-04-04 00:30:53 +00:00
|
|
|
|
|
|
|
rx_ring->Fbr[0]->Va[index] =
|
2009-10-06 14:48:57 +00:00
|
|
|
(uint8_t *) rx_ring->Fbr0MemVa[i] +
|
|
|
|
(j * rx_ring->Fbr0BufferSize) + Fbr0Offset;
|
2008-04-04 00:30:53 +00:00
|
|
|
|
|
|
|
rx_ring->Fbr[0]->PAHigh[index] =
|
2009-10-06 14:48:57 +00:00
|
|
|
(u32) (Fbr0TempPa >> 32);
|
|
|
|
rx_ring->Fbr[0]->PALow[index] = (u32) Fbr0TempPa;
|
2008-04-04 00:30:53 +00:00
|
|
|
|
|
|
|
Fbr0TempPa += rx_ring->Fbr0BufferSize;
|
|
|
|
|
|
|
|
rx_ring->Fbr[0]->Buffer1[index] =
|
|
|
|
rx_ring->Fbr[0]->Va[index];
|
|
|
|
rx_ring->Fbr[0]->Buffer2[index] =
|
|
|
|
rx_ring->Fbr[0]->Va[index] - 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Allocate an area of memory for FIFO of Packet Status ring entries */
|
|
|
|
pktStatRingSize =
|
|
|
|
sizeof(PKT_STAT_DESC_t) * adapter->RxRing.PsrNumEntries;
|
|
|
|
|
|
|
|
rx_ring->pPSRingVa = pci_alloc_consistent(adapter->pdev,
|
2009-10-06 14:48:49 +00:00
|
|
|
pktStatRingSize,
|
2008-04-04 00:30:53 +00:00
|
|
|
&rx_ring->pPSRingPa);
|
|
|
|
|
|
|
|
if (!rx_ring->pPSRingVa) {
|
2009-08-27 10:03:09 +00:00
|
|
|
dev_err(&adapter->pdev->dev,
|
2008-04-04 00:30:53 +00:00
|
|
|
"Cannot alloc memory for Packet Status Ring\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2009-10-06 14:48:49 +00:00
|
|
|
printk("PSR %lx\n", (unsigned long) rx_ring->pPSRingPa);
|
2008-04-04 00:30:53 +00:00
|
|
|
|
2009-10-06 14:48:49 +00:00
|
|
|
/*
|
2008-04-04 00:30:53 +00:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Allocate an area of memory for writeback of status information */
|
|
|
|
rx_ring->pRxStatusVa = pci_alloc_consistent(adapter->pdev,
|
2009-10-06 14:48:49 +00:00
|
|
|
sizeof(RX_STATUS_BLOCK_t),
|
|
|
|
&rx_ring->pRxStatusPa);
|
2008-04-04 00:30:53 +00:00
|
|
|
if (!rx_ring->pRxStatusVa) {
|
2009-08-27 10:03:09 +00:00
|
|
|
dev_err(&adapter->pdev->dev,
|
2008-04-04 00:30:53 +00:00
|
|
|
"Cannot alloc memory for Status Block\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
rx_ring->NumRfd = NIC_DEFAULT_NUM_RFD;
|
2009-10-06 14:48:49 +00:00
|
|
|
printk("PRS %lx\n", (unsigned long)rx_ring->pRxStatusPa);
|
2008-04-04 00:30:53 +00:00
|
|
|
|
|
|
|
/* Recv
|
|
|
|
* pci_pool_create initializes a lookaside list. After successful
|
|
|
|
* creation, nonpaged fixed-size blocks can be allocated from and
|
|
|
|
* freed to the lookaside list.
|
|
|
|
* RFDs will be allocated from this pool.
|
|
|
|
*/
|
|
|
|
rx_ring->RecvLookaside = kmem_cache_create(adapter->netdev->name,
|
|
|
|
sizeof(MP_RFD),
|
|
|
|
0,
|
|
|
|
SLAB_CACHE_DMA |
|
|
|
|
SLAB_HWCACHE_ALIGN,
|
|
|
|
NULL);
|
|
|
|
|
2009-08-27 10:02:05 +00:00
|
|
|
adapter->Flags |= fMP_ADAPTER_RECV_LOOKASIDE;
|
2008-04-04 00:30:53 +00:00
|
|
|
|
|
|
|
/* The RFDs are going to be put on lists later on, so initialize the
|
|
|
|
* lists now.
|
|
|
|
*/
|
|
|
|
INIT_LIST_HEAD(&rx_ring->RecvList);
|
|
|
|
INIT_LIST_HEAD(&rx_ring->RecvPendingList);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* et131x_rx_dma_memory_free - Free all memory allocated within this module.
|
|
|
|
* @adapter: pointer to our private adapter structure
|
|
|
|
*/
|
|
|
|
void et131x_rx_dma_memory_free(struct et131x_adapter *adapter)
|
|
|
|
{
|
2009-10-06 14:48:57 +00:00
|
|
|
u32 index;
|
|
|
|
u32 bufsize;
|
|
|
|
u32 pktStatRingSize;
|
|
|
|
PMP_RFD rfd;
|
2008-04-04 00:30:53 +00:00
|
|
|
RX_RING_t *rx_ring;
|
|
|
|
|
|
|
|
/* Setup some convenience pointers */
|
2009-06-10 16:30:41 +00:00
|
|
|
rx_ring = (RX_RING_t *) &adapter->RxRing;
|
2008-04-04 00:30:53 +00:00
|
|
|
|
|
|
|
/* Free RFDs and associated packet descriptors */
|
2009-08-27 10:03:09 +00:00
|
|
|
WARN_ON(rx_ring->nReadyRecv != rx_ring->NumRfd);
|
2008-04-04 00:30:53 +00:00
|
|
|
|
|
|
|
while (!list_empty(&rx_ring->RecvList)) {
|
2009-10-06 14:48:57 +00:00
|
|
|
rfd = (MP_RFD *) list_entry(rx_ring->RecvList.next,
|
2008-04-04 00:30:53 +00:00
|
|
|
MP_RFD, list_node);
|
|
|
|
|
2009-10-06 14:48:57 +00:00
|
|
|
list_del(&rfd->list_node);
|
|
|
|
et131x_rfd_resources_free(adapter, rfd);
|
2008-04-04 00:30:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
while (!list_empty(&rx_ring->RecvPendingList)) {
|
2009-10-06 14:48:57 +00:00
|
|
|
rfd = (MP_RFD *) list_entry(rx_ring->RecvPendingList.next,
|
2008-04-04 00:30:53 +00:00
|
|
|
MP_RFD, list_node);
|
2009-10-06 14:48:57 +00:00
|
|
|
list_del(&rfd->list_node);
|
|
|
|
et131x_rfd_resources_free(adapter, rfd);
|
2008-04-04 00:30:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Free Free Buffer Ring 1 */
|
|
|
|
if (rx_ring->pFbr1RingVa) {
|
|
|
|
/* First the packet memory */
|
|
|
|
for (index = 0; index <
|
|
|
|
(rx_ring->Fbr1NumEntries / FBR_CHUNKS); index++) {
|
|
|
|
if (rx_ring->Fbr1MemVa[index]) {
|
2009-10-06 14:48:57 +00:00
|
|
|
u32 Fbr1Align;
|
2008-04-04 00:30:53 +00:00
|
|
|
|
2009-06-10 16:30:41 +00:00
|
|
|
if (rx_ring->Fbr1BufferSize > 4096)
|
2008-04-04 00:30:53 +00:00
|
|
|
Fbr1Align = 4096;
|
2009-06-10 16:30:41 +00:00
|
|
|
else
|
2008-04-04 00:30:53 +00:00
|
|
|
Fbr1Align = rx_ring->Fbr1BufferSize;
|
|
|
|
|
|
|
|
bufsize =
|
|
|
|
(rx_ring->Fbr1BufferSize * FBR_CHUNKS) +
|
|
|
|
Fbr1Align - 1;
|
|
|
|
|
|
|
|
pci_free_consistent(adapter->pdev,
|
|
|
|
bufsize,
|
|
|
|
rx_ring->Fbr1MemVa[index],
|
|
|
|
rx_ring->Fbr1MemPa[index]);
|
|
|
|
|
|
|
|
rx_ring->Fbr1MemVa[index] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now the FIFO itself */
|
2009-06-10 16:30:41 +00:00
|
|
|
rx_ring->pFbr1RingVa = (void *)((uint8_t *)
|
|
|
|
rx_ring->pFbr1RingVa - rx_ring->Fbr1offset);
|
2008-04-04 00:30:53 +00:00
|
|
|
|
|
|
|
bufsize =
|
|
|
|
(sizeof(FBR_DESC_t) * rx_ring->Fbr1NumEntries) + 0xfff;
|
|
|
|
|
|
|
|
pci_free_consistent(adapter->pdev,
|
|
|
|
bufsize,
|
|
|
|
rx_ring->pFbr1RingVa, rx_ring->pFbr1RingPa);
|
|
|
|
|
|
|
|
rx_ring->pFbr1RingVa = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef USE_FBR0
|
|
|
|
/* Now the same for Free Buffer Ring 0 */
|
|
|
|
if (rx_ring->pFbr0RingVa) {
|
|
|
|
/* First the packet memory */
|
|
|
|
for (index = 0; index <
|
|
|
|
(rx_ring->Fbr0NumEntries / FBR_CHUNKS); index++) {
|
|
|
|
if (rx_ring->Fbr0MemVa[index]) {
|
|
|
|
bufsize =
|
|
|
|
(rx_ring->Fbr0BufferSize *
|
|
|
|
(FBR_CHUNKS + 1)) - 1;
|
|
|
|
|
|
|
|
pci_free_consistent(adapter->pdev,
|
|
|
|
bufsize,
|
|
|
|
rx_ring->Fbr0MemVa[index],
|
|
|
|
rx_ring->Fbr0MemPa[index]);
|
|
|
|
|
|
|
|
rx_ring->Fbr0MemVa[index] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now the FIFO itself */
|
2009-06-10 16:30:41 +00:00
|
|
|
rx_ring->pFbr0RingVa = (void *)((uint8_t *)
|
|
|
|
rx_ring->pFbr0RingVa - rx_ring->Fbr0offset);
|
2008-04-04 00:30:53 +00:00
|
|
|
|
|
|
|
bufsize =
|
|
|
|
(sizeof(FBR_DESC_t) * rx_ring->Fbr0NumEntries) + 0xfff;
|
|
|
|
|
|
|
|
pci_free_consistent(adapter->pdev,
|
|
|
|
bufsize,
|
|
|
|
rx_ring->pFbr0RingVa, rx_ring->pFbr0RingPa);
|
|
|
|
|
|
|
|
rx_ring->pFbr0RingVa = NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Free Packet Status Ring */
|
|
|
|
if (rx_ring->pPSRingVa) {
|
|
|
|
pktStatRingSize =
|
|
|
|
sizeof(PKT_STAT_DESC_t) * adapter->RxRing.PsrNumEntries;
|
|
|
|
|
2009-10-06 14:48:49 +00:00
|
|
|
pci_free_consistent(adapter->pdev, pktStatRingSize,
|
2008-04-04 00:30:53 +00:00
|
|
|
rx_ring->pPSRingVa, rx_ring->pPSRingPa);
|
|
|
|
|
|
|
|
rx_ring->pPSRingVa = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Free area of memory for the writeback of status information */
|
|
|
|
if (rx_ring->pRxStatusVa) {
|
|
|
|
pci_free_consistent(adapter->pdev,
|
2009-10-06 14:48:49 +00:00
|
|
|
sizeof(RX_STATUS_BLOCK_t),
|
2009-06-10 16:30:41 +00:00
|
|
|
rx_ring->pRxStatusVa, rx_ring->pRxStatusPa);
|
2008-04-04 00:30:53 +00:00
|
|
|
|
|
|
|
rx_ring->pRxStatusVa = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Free receive buffer pool */
|
|
|
|
|
|
|
|
/* Free receive packet pool */
|
|
|
|
|
|
|
|
/* Destroy the lookaside (RFD) pool */
|
2009-08-27 10:02:05 +00:00
|
|
|
if (adapter->Flags & fMP_ADAPTER_RECV_LOOKASIDE) {
|
2008-04-04 00:30:53 +00:00
|
|
|
kmem_cache_destroy(rx_ring->RecvLookaside);
|
2009-08-27 10:02:05 +00:00
|
|
|
adapter->Flags &= ~fMP_ADAPTER_RECV_LOOKASIDE;
|
2008-04-04 00:30:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Free the FBR Lookup Table */
|
|
|
|
#ifdef USE_FBR0
|
|
|
|
kfree(rx_ring->Fbr[0]);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
kfree(rx_ring->Fbr[1]);
|
|
|
|
|
|
|
|
/* Reset Counters */
|
|
|
|
rx_ring->nReadyRecv = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* et131x_init_recv - Initialize receive data structures.
|
|
|
|
* @adapter: pointer to our private adapter structure
|
|
|
|
*
|
|
|
|
* Returns 0 on success and errno on failure (as defined in errno.h)
|
|
|
|
*/
|
|
|
|
int et131x_init_recv(struct et131x_adapter *adapter)
|
|
|
|
{
|
|
|
|
int status = -ENOMEM;
|
2009-10-06 14:48:57 +00:00
|
|
|
PMP_RFD rfd = NULL;
|
|
|
|
u32 rfdct;
|
|
|
|
u32 numrfd = 0;
|
2008-04-04 00:30:53 +00:00
|
|
|
RX_RING_t *rx_ring = NULL;
|
|
|
|
|
|
|
|
/* Setup some convenience pointers */
|
2009-06-10 16:30:41 +00:00
|
|
|
rx_ring = (RX_RING_t *) &adapter->RxRing;
|
2008-04-04 00:30:53 +00:00
|
|
|
|
|
|
|
/* Setup each RFD */
|
2009-10-06 14:48:57 +00:00
|
|
|
for (rfdct = 0; rfdct < rx_ring->NumRfd; rfdct++) {
|
|
|
|
rfd = (MP_RFD *) kmem_cache_alloc(rx_ring->RecvLookaside,
|
2008-04-04 00:30:53 +00:00
|
|
|
GFP_ATOMIC | GFP_DMA);
|
|
|
|
|
2009-10-06 14:48:57 +00:00
|
|
|
if (!rfd) {
|
2009-08-27 10:03:09 +00:00
|
|
|
dev_err(&adapter->pdev->dev,
|
2008-04-04 00:30:53 +00:00
|
|
|
"Couldn't alloc RFD out of kmem_cache\n");
|
|
|
|
status = -ENOMEM;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2009-10-06 14:48:57 +00:00
|
|
|
status = et131x_rfd_resources_alloc(adapter, rfd);
|
2008-04-04 00:30:53 +00:00
|
|
|
if (status != 0) {
|
2009-08-27 10:03:09 +00:00
|
|
|
dev_err(&adapter->pdev->dev,
|
2008-04-04 00:30:53 +00:00
|
|
|
"Couldn't alloc packet for RFD\n");
|
2009-10-06 14:48:57 +00:00
|
|
|
kmem_cache_free(rx_ring->RecvLookaside, rfd);
|
2008-04-04 00:30:53 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add this RFD to the RecvList */
|
2009-10-06 14:48:57 +00:00
|
|
|
list_add_tail(&rfd->list_node, &rx_ring->RecvList);
|
2008-04-04 00:30:53 +00:00
|
|
|
|
|
|
|
/* Increment both the available RFD's, and the total RFD's. */
|
|
|
|
rx_ring->nReadyRecv++;
|
2009-10-06 14:48:57 +00:00
|
|
|
numrfd++;
|
2008-04-04 00:30:53 +00:00
|
|
|
}
|
|
|
|
|
2009-10-06 14:48:57 +00:00
|
|
|
if (numrfd > NIC_MIN_NUM_RFD)
|
2008-04-04 00:30:53 +00:00
|
|
|
status = 0;
|
|
|
|
|
2009-10-06 14:48:57 +00:00
|
|
|
rx_ring->NumRfd = numrfd;
|
2008-04-04 00:30:53 +00:00
|
|
|
|
|
|
|
if (status != 0) {
|
2009-10-06 14:48:57 +00:00
|
|
|
kmem_cache_free(rx_ring->RecvLookaside, rfd);
|
2009-08-27 10:03:09 +00:00
|
|
|
dev_err(&adapter->pdev->dev,
|
2008-04-04 00:30:53 +00:00
|
|
|
"Allocation problems in et131x_init_recv\n");
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* et131x_rfd_resources_alloc
|
|
|
|
* @adapter: pointer to our private adapter structure
|
2009-10-06 14:48:57 +00:00
|
|
|
* @rfd: pointer to a RFD
|
2008-04-04 00:30:53 +00:00
|
|
|
*
|
|
|
|
* Returns 0 on success and errno on failure (as defined in errno.h)
|
|
|
|
*/
|
2009-10-06 14:48:57 +00:00
|
|
|
int et131x_rfd_resources_alloc(struct et131x_adapter *adapter, MP_RFD *rfd)
|
2008-04-04 00:30:53 +00:00
|
|
|
{
|
2009-10-06 14:48:57 +00:00
|
|
|
rfd->Packet = NULL;
|
2008-04-04 00:30:53 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* et131x_rfd_resources_free - Free the packet allocated for the given RFD
|
|
|
|
* @adapter: pointer to our private adapter structure
|
2009-10-06 14:48:57 +00:00
|
|
|
* @rfd: pointer to a RFD
|
2008-04-04 00:30:53 +00:00
|
|
|
*/
|
2009-10-06 14:48:57 +00:00
|
|
|
void et131x_rfd_resources_free(struct et131x_adapter *adapter, MP_RFD *rfd)
|
2008-04-04 00:30:53 +00:00
|
|
|
{
|
2009-10-06 14:48:57 +00:00
|
|
|
rfd->Packet = NULL;
|
|
|
|
kmem_cache_free(adapter->RxRing.RecvLookaside, rfd);
|
2008-04-04 00:30:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ConfigRxDmaRegs - Start of Rx_DMA init sequence
|
2009-08-19 17:21:44 +00:00
|
|
|
* @etdev: pointer to our adapter structure
|
2008-04-04 00:30:53 +00:00
|
|
|
*/
|
2009-08-19 17:21:44 +00:00
|
|
|
void ConfigRxDmaRegs(struct et131x_adapter *etdev)
|
2008-04-04 00:30:53 +00:00
|
|
|
{
|
2009-08-27 10:00:36 +00:00
|
|
|
struct _RXDMA_t __iomem *rx_dma = &etdev->regs->rxdma;
|
2009-10-06 14:48:57 +00:00
|
|
|
struct _rx_ring_t *rx_local = &etdev->RxRing;
|
2009-08-27 10:00:36 +00:00
|
|
|
PFBR_DESC_t fbr_entry;
|
2009-10-06 14:48:57 +00:00
|
|
|
u32 entry;
|
2008-04-04 00:30:53 +00:00
|
|
|
RXDMA_PSR_NUM_DES_t psr_num_des;
|
2009-08-19 17:21:50 +00:00
|
|
|
unsigned long flags;
|
2008-04-04 00:30:53 +00:00
|
|
|
|
|
|
|
/* Halt RXDMA to perform the reconfigure. */
|
2009-08-19 17:21:44 +00:00
|
|
|
et131x_rx_dma_disable(etdev);
|
2008-04-04 00:30:53 +00:00
|
|
|
|
|
|
|
/* Load the completion writeback 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.
|
|
|
|
*/
|
2009-10-06 14:48:57 +00:00
|
|
|
writel((u32) ((u64)rx_local->pRxStatusPa >> 32),
|
2009-08-27 10:00:36 +00:00
|
|
|
&rx_dma->dma_wb_base_hi);
|
2009-10-06 14:48:57 +00:00
|
|
|
writel((u32) rx_local->pRxStatusPa, &rx_dma->dma_wb_base_lo);
|
2008-04-04 00:30:53 +00:00
|
|
|
|
2009-10-06 14:48:57 +00:00
|
|
|
memset(rx_local->pRxStatusVa, 0, sizeof(RX_STATUS_BLOCK_t));
|
2008-04-04 00:30:53 +00:00
|
|
|
|
|
|
|
/* Set the address and parameters of the packet status ring into the
|
|
|
|
* 1310's registers
|
|
|
|
*/
|
2009-10-06 14:48:57 +00:00
|
|
|
writel((u32) ((u64)rx_local->pPSRingPa >> 32),
|
2009-08-27 10:00:36 +00:00
|
|
|
&rx_dma->psr_base_hi);
|
2009-10-06 14:48:57 +00:00
|
|
|
writel((u32) rx_local->pPSRingPa, &rx_dma->psr_base_lo);
|
|
|
|
writel(rx_local->PsrNumEntries - 1, &rx_dma->psr_num_des.value);
|
2009-08-27 10:00:36 +00:00
|
|
|
writel(0, &rx_dma->psr_full_offset.value);
|
2008-04-04 00:30:53 +00:00
|
|
|
|
2009-08-27 10:00:36 +00:00
|
|
|
psr_num_des.value = readl(&rx_dma->psr_num_des.value);
|
2008-04-04 00:30:53 +00:00
|
|
|
writel((psr_num_des.bits.psr_ndes * LO_MARK_PERCENT_FOR_PSR) / 100,
|
2009-08-27 10:00:36 +00:00
|
|
|
&rx_dma->psr_min_des.value);
|
2008-04-04 00:30:53 +00:00
|
|
|
|
2009-08-19 17:21:50 +00:00
|
|
|
spin_lock_irqsave(&etdev->RcvLock, flags);
|
2008-04-04 00:30:53 +00:00
|
|
|
|
|
|
|
/* These local variables track the PSR in the adapter structure */
|
2009-10-06 14:48:57 +00:00
|
|
|
rx_local->local_psr_full.bits.psr_full = 0;
|
|
|
|
rx_local->local_psr_full.bits.psr_full_wrap = 0;
|
2008-04-04 00:30:53 +00:00
|
|
|
|
|
|
|
/* Now's the best time to initialize FBR1 contents */
|
2009-10-06 14:48:57 +00:00
|
|
|
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];
|
2009-08-27 10:00:36 +00:00
|
|
|
fbr_entry->word2.bits.bi = entry;
|
|
|
|
fbr_entry++;
|
2008-04-04 00:30:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the address and parameters of Free buffer ring 1 (and 0 if
|
|
|
|
* required) into the 1310's registers
|
|
|
|
*/
|
2009-10-06 14:48:57 +00:00
|
|
|
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.value);
|
2009-08-27 10:01:57 +00:00
|
|
|
writel(ET_DMA10_WRAP, &rx_dma->fbr1_full_offset);
|
2008-04-04 00:30:53 +00:00
|
|
|
|
|
|
|
/* This variable tracks the free buffer ring 1 full position, so it
|
|
|
|
* has to match the above.
|
|
|
|
*/
|
2009-10-06 14:48:57 +00:00
|
|
|
rx_local->local_Fbr1_full = ET_DMA10_WRAP;
|
|
|
|
writel(((rx_local->Fbr1NumEntries * LO_MARK_PERCENT_FOR_RX) / 100) - 1,
|
2009-08-27 10:00:36 +00:00
|
|
|
&rx_dma->fbr1_min_des.value);
|
2008-04-04 00:30:53 +00:00
|
|
|
|
|
|
|
#ifdef USE_FBR0
|
|
|
|
/* Now's the best time to initialize FBR0 contents */
|
2009-10-06 14:48:57 +00:00
|
|
|
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];
|
2009-08-27 10:00:36 +00:00
|
|
|
fbr_entry->word2.bits.bi = entry;
|
|
|
|
fbr_entry++;
|
2008-04-04 00:30:53 +00:00
|
|
|
}
|
|
|
|
|
2009-10-06 14:48:57 +00:00
|
|
|
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.value);
|
2009-08-27 10:01:57 +00:00
|
|
|
writel(ET_DMA10_WRAP, &rx_dma->fbr0_full_offset);
|
2008-04-04 00:30:53 +00:00
|
|
|
|
|
|
|
/* This variable tracks the free buffer ring 0 full position, so it
|
|
|
|
* has to match the above.
|
|
|
|
*/
|
2009-10-06 14:48:57 +00:00
|
|
|
rx_local->local_Fbr0_full = ET_DMA10_WRAP;
|
|
|
|
writel(((rx_local->Fbr0NumEntries * LO_MARK_PERCENT_FOR_RX) / 100) - 1,
|
2009-08-27 10:00:36 +00:00
|
|
|
&rx_dma->fbr0_min_des.value);
|
2008-04-04 00:30:53 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Program the number of packets we will receive before generating an
|
|
|
|
* interrupt.
|
|
|
|
* For version B silicon, this value gets updated once autoneg is
|
|
|
|
*complete.
|
|
|
|
*/
|
2009-08-27 10:00:36 +00:00
|
|
|
writel(PARM_RX_NUM_BUFS_DEF, &rx_dma->num_pkt_done.value);
|
2008-04-04 00:30:53 +00:00
|
|
|
|
|
|
|
/* 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.
|
|
|
|
*/
|
2009-08-27 10:00:36 +00:00
|
|
|
writel(PARM_RX_TIME_INT_DEF, &rx_dma->max_pkt_time.value);
|
2008-04-04 00:30:53 +00:00
|
|
|
|
2009-08-19 17:21:50 +00:00
|
|
|
spin_unlock_irqrestore(&etdev->RcvLock, flags);
|
2008-04-04 00:30:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SetRxDmaTimer - Set the heartbeat timer according to line rate.
|
2009-08-19 17:21:44 +00:00
|
|
|
* @etdev: pointer to our adapter structure
|
2008-04-04 00:30:53 +00:00
|
|
|
*/
|
2009-08-19 17:21:44 +00:00
|
|
|
void SetRxDmaTimer(struct et131x_adapter *etdev)
|
2008-04-04 00:30:53 +00:00
|
|
|
{
|
|
|
|
/* For version B silicon, we do not use the RxDMA timer for 10 and 100
|
|
|
|
* Mbits/s line rates. We do not enable and RxDMA interrupt coalescing.
|
|
|
|
*/
|
2009-08-27 10:00:36 +00:00
|
|
|
if ((etdev->linkspeed == TRUEPHY_SPEED_100MBPS) ||
|
|
|
|
(etdev->linkspeed == TRUEPHY_SPEED_10MBPS)) {
|
2009-08-27 09:59:30 +00:00
|
|
|
writel(0, &etdev->regs->rxdma.max_pkt_time.value);
|
|
|
|
writel(1, &etdev->regs->rxdma.num_pkt_done.value);
|
2008-04-04 00:30:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* et131x_rx_dma_disable - Stop of Rx_DMA on the ET1310
|
2009-08-19 17:21:44 +00:00
|
|
|
* @etdev: pointer to our adapter structure
|
2008-04-04 00:30:53 +00:00
|
|
|
*/
|
2009-08-19 17:21:44 +00:00
|
|
|
void et131x_rx_dma_disable(struct et131x_adapter *etdev)
|
2008-04-04 00:30:53 +00:00
|
|
|
{
|
|
|
|
RXDMA_CSR_t csr;
|
|
|
|
|
|
|
|
/* Setup the receive dma configuration register */
|
2009-08-27 09:59:30 +00:00
|
|
|
writel(0x00002001, &etdev->regs->rxdma.csr.value);
|
|
|
|
csr.value = readl(&etdev->regs->rxdma.csr.value);
|
2008-04-04 00:30:53 +00:00
|
|
|
if (csr.bits.halt_status != 1) {
|
|
|
|
udelay(5);
|
2009-08-27 09:59:30 +00:00
|
|
|
csr.value = readl(&etdev->regs->rxdma.csr.value);
|
2009-06-10 16:30:41 +00:00
|
|
|
if (csr.bits.halt_status != 1)
|
2009-08-27 10:03:09 +00:00
|
|
|
dev_err(&etdev->pdev->dev,
|
2009-06-10 16:30:41 +00:00
|
|
|
"RX Dma failed to enter halt state. CSR 0x%08x\n",
|
|
|
|
csr.value);
|
2008-04-04 00:30:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* et131x_rx_dma_enable - re-start of Rx_DMA on the ET1310.
|
2009-08-19 17:21:44 +00:00
|
|
|
* @etdev: pointer to our adapter structure
|
2008-04-04 00:30:53 +00:00
|
|
|
*/
|
2009-08-19 17:21:44 +00:00
|
|
|
void et131x_rx_dma_enable(struct et131x_adapter *etdev)
|
2008-04-04 00:30:53 +00:00
|
|
|
{
|
|
|
|
/* Setup the receive dma configuration register for normal operation */
|
2009-10-06 14:47:55 +00:00
|
|
|
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;
|
2008-04-04 00:30:53 +00:00
|
|
|
#ifdef USE_FBR0
|
2009-10-06 14:47:55 +00:00
|
|
|
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;
|
2008-04-04 00:30:53 +00:00
|
|
|
#endif
|
2009-10-06 14:47:55 +00:00
|
|
|
writel(csr.value, &etdev->regs->rxdma.csr.value);
|
2008-04-04 00:30:53 +00:00
|
|
|
|
2009-10-06 14:47:55 +00:00
|
|
|
csr.value = readl(&etdev->regs->rxdma.csr.value);
|
|
|
|
if (csr.bits.halt_status != 0) {
|
|
|
|
udelay(5);
|
2009-08-27 09:59:30 +00:00
|
|
|
csr.value = readl(&etdev->regs->rxdma.csr.value);
|
2008-04-04 00:30:53 +00:00
|
|
|
if (csr.bits.halt_status != 0) {
|
2009-10-06 14:47:55 +00:00
|
|
|
dev_err(&etdev->pdev->dev,
|
|
|
|
"RX Dma failed to exit halt state. CSR 0x%08x\n",
|
|
|
|
csr.value);
|
2008-04-04 00:30:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* nic_rx_pkts - Checks the hardware for available packets
|
2009-08-19 17:21:44 +00:00
|
|
|
* @etdev: pointer to our adapter
|
2008-04-04 00:30:53 +00:00
|
|
|
*
|
2009-10-06 14:48:57 +00:00
|
|
|
* Returns rfd, a pointer to our MPRFD.
|
2008-04-04 00:30:53 +00:00
|
|
|
*
|
|
|
|
* Checks the hardware for available packets, using completion ring
|
|
|
|
* If packets are available, it gets an RFD from the RecvList, attaches
|
|
|
|
* the packet to it, puts the RFD in the RecvPendList, and also returns
|
|
|
|
* the pointer to the RFD.
|
|
|
|
*/
|
2009-08-19 17:21:44 +00:00
|
|
|
PMP_RFD nic_rx_pkts(struct et131x_adapter *etdev)
|
2008-04-04 00:30:53 +00:00
|
|
|
{
|
2009-10-06 14:48:57 +00:00
|
|
|
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;
|
2009-08-19 17:21:50 +00:00
|
|
|
unsigned long flags;
|
2008-04-04 00:30:53 +00:00
|
|
|
struct list_head *element;
|
2009-10-06 14:48:57 +00:00
|
|
|
uint8_t rindex;
|
|
|
|
uint16_t bindex;
|
|
|
|
u32 len;
|
2008-04-04 00:30:53 +00:00
|
|
|
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.
|
|
|
|
*/
|
2009-10-06 14:48:57 +00:00
|
|
|
status = (PRX_STATUS_BLOCK_t) rx_local->pRxStatusVa;
|
2008-04-04 00:30:53 +00:00
|
|
|
|
2009-10-06 14:48:57 +00:00
|
|
|
if (status->Word1.bits.PSRoffset ==
|
|
|
|
rx_local->local_psr_full.bits.psr_full &&
|
|
|
|
status->Word1.bits.PSRwrap ==
|
|
|
|
rx_local->local_psr_full.bits.psr_full_wrap) {
|
2008-04-04 00:30:53 +00:00
|
|
|
/* Looks like this ring is not updated yet */
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The packet status ring indicates that data is available. */
|
2009-10-06 14:48:57 +00:00
|
|
|
psr = (PPKT_STAT_DESC_t) (rx_local->pPSRingVa) +
|
|
|
|
rx_local->local_psr_full.bits.psr_full;
|
2008-04-04 00:30:53 +00:00
|
|
|
|
|
|
|
/* Grab any information that is required once the PSR is
|
|
|
|
* advanced, since we can no longer rely on the memory being
|
|
|
|
* accurate
|
|
|
|
*/
|
2009-10-06 14:48:57 +00:00
|
|
|
len = psr->word1.bits.length;
|
|
|
|
rindex = (uint8_t) psr->word1.bits.ri;
|
|
|
|
bindex = (uint16_t) psr->word1.bits.bi;
|
|
|
|
Word0 = psr->word0;
|
2008-04-04 00:30:53 +00:00
|
|
|
|
|
|
|
/* Indicate that we have used this PSR entry. */
|
2009-10-06 14:48:57 +00:00
|
|
|
if (++rx_local->local_psr_full.bits.psr_full >
|
|
|
|
rx_local->PsrNumEntries - 1) {
|
|
|
|
rx_local->local_psr_full.bits.psr_full = 0;
|
|
|
|
rx_local->local_psr_full.bits.psr_full_wrap ^= 1;
|
2008-04-04 00:30:53 +00:00
|
|
|
}
|
|
|
|
|
2009-10-06 14:48:57 +00:00
|
|
|
writel(rx_local->local_psr_full.value,
|
2009-08-27 09:59:30 +00:00
|
|
|
&etdev->regs->rxdma.psr_full_offset.value);
|
2008-04-04 00:30:53 +00:00
|
|
|
|
|
|
|
#ifndef USE_FBR0
|
2009-10-06 14:48:57 +00:00
|
|
|
if (rindex != 1) {
|
2008-04-04 00:30:53 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USE_FBR0
|
2009-10-06 14:48:57 +00:00
|
|
|
if (rindex > 1 ||
|
|
|
|
(rindex == 0 &&
|
|
|
|
bindex > rx_local->Fbr0NumEntries - 1) ||
|
|
|
|
(rindex == 1 &&
|
|
|
|
bindex > rx_local->Fbr1NumEntries - 1))
|
2008-04-04 00:30:53 +00:00
|
|
|
#else
|
2009-10-06 14:48:57 +00:00
|
|
|
if (rindex != 1 ||
|
|
|
|
bindex > rx_local->Fbr1NumEntries - 1)
|
2008-04-04 00:30:53 +00:00
|
|
|
#endif
|
|
|
|
{
|
|
|
|
/* Illegal buffer or ring index cannot be used by S/W*/
|
2009-08-27 10:03:09 +00:00
|
|
|
dev_err(&etdev->pdev->dev,
|
2008-04-04 00:30:53 +00:00
|
|
|
"NICRxPkts PSR Entry %d indicates "
|
|
|
|
"length of %d and/or bad bi(%d)\n",
|
2009-10-06 14:48:57 +00:00
|
|
|
rx_local->local_psr_full.bits.psr_full,
|
|
|
|
len, bindex);
|
2008-04-04 00:30:53 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get and fill the RFD. */
|
2009-08-19 17:21:50 +00:00
|
|
|
spin_lock_irqsave(&etdev->RcvLock, flags);
|
2008-04-04 00:30:53 +00:00
|
|
|
|
2009-10-06 14:48:57 +00:00
|
|
|
rfd = NULL;
|
|
|
|
element = rx_local->RecvList.next;
|
|
|
|
rfd = (PMP_RFD) list_entry(element, MP_RFD, list_node);
|
2008-04-04 00:30:53 +00:00
|
|
|
|
2009-10-06 14:48:57 +00:00
|
|
|
if (rfd == NULL) {
|
2009-08-19 17:21:50 +00:00
|
|
|
spin_unlock_irqrestore(&etdev->RcvLock, flags);
|
2008-04-04 00:30:53 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-10-06 14:48:57 +00:00
|
|
|
list_del(&rfd->list_node);
|
|
|
|
rx_local->nReadyRecv--;
|
2008-04-04 00:30:53 +00:00
|
|
|
|
2009-08-19 17:21:50 +00:00
|
|
|
spin_unlock_irqrestore(&etdev->RcvLock, flags);
|
2008-04-04 00:30:53 +00:00
|
|
|
|
2009-10-06 14:48:57 +00:00
|
|
|
rfd->bufferindex = bindex;
|
|
|
|
rfd->ringindex = rindex;
|
2008-04-04 00:30:53 +00:00
|
|
|
|
|
|
|
/* 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.
|
|
|
|
*/
|
2009-10-06 14:48:57 +00:00
|
|
|
if (len < (NIC_MIN_PACKET_SIZE + 4)) {
|
2009-08-19 17:21:44 +00:00
|
|
|
etdev->Stats.other_errors++;
|
2009-10-06 14:48:57 +00:00
|
|
|
len = 0;
|
2008-04-04 00:30:53 +00:00
|
|
|
}
|
|
|
|
|
2009-10-06 14:48:57 +00:00
|
|
|
if (len) {
|
2009-08-19 17:21:44 +00:00
|
|
|
if (etdev->ReplicaPhyLoopbk == 1) {
|
2009-10-06 14:48:57 +00:00
|
|
|
buf = rx_local->Fbr[rindex]->Va[bindex];
|
2008-04-04 00:30:53 +00:00
|
|
|
|
2009-10-06 14:48:57 +00:00
|
|
|
if (memcmp(&buf[6], &etdev->CurrentAddress[0],
|
2008-04-04 00:30:53 +00:00
|
|
|
ETH_ALEN) == 0) {
|
2009-10-06 14:48:57 +00:00
|
|
|
if (memcmp(&buf[42], "Replica packet",
|
2008-04-04 00:30:53 +00:00
|
|
|
ETH_HLEN)) {
|
2009-08-19 17:21:44 +00:00
|
|
|
etdev->ReplicaPhyLoopbkPF = 1;
|
2008-04-04 00:30:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Determine if this is a multicast packet coming in */
|
|
|
|
if ((Word0.value & ALCATEL_MULTICAST_PKT) &&
|
|
|
|
!(Word0.value & ALCATEL_BROADCAST_PKT)) {
|
|
|
|
/* Promiscuous mode and Multicast mode are
|
|
|
|
* not mutually exclusive as was first
|
|
|
|
* thought. I guess Promiscuous is just
|
|
|
|
* considered a super-set of the other
|
|
|
|
* filters. Generally filter is 0x2b when in
|
|
|
|
* promiscuous mode.
|
|
|
|
*/
|
2009-08-19 17:21:44 +00:00
|
|
|
if ((etdev->PacketFilter & ET131X_PACKET_TYPE_MULTICAST)
|
|
|
|
&& !(etdev->PacketFilter & ET131X_PACKET_TYPE_PROMISCUOUS)
|
|
|
|
&& !(etdev->PacketFilter & ET131X_PACKET_TYPE_ALL_MULTICAST)) {
|
2009-10-06 14:48:57 +00:00
|
|
|
buf = rx_local->Fbr[rindex]->
|
|
|
|
Va[bindex];
|
2008-04-04 00:30:53 +00:00
|
|
|
|
|
|
|
/* Loop through our list to see if the
|
|
|
|
* destination address of this packet
|
|
|
|
* matches one in our list.
|
|
|
|
*/
|
2009-10-06 14:48:57 +00:00
|
|
|
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]) {
|
2008-04-04 00:30:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If our index is equal to the number
|
|
|
|
* of Multicast address we have, then
|
|
|
|
* this means we did not find this
|
|
|
|
* packet's matching address in our
|
|
|
|
* list. Set the PacketSize to zero,
|
|
|
|
* so we free our RFD when we return
|
|
|
|
* from this function.
|
|
|
|
*/
|
2009-10-06 14:48:57 +00:00
|
|
|
if (i == etdev->MCAddressCount)
|
|
|
|
len = 0;
|
2008-04-04 00:30:53 +00:00
|
|
|
}
|
|
|
|
|
2009-10-06 14:48:57 +00:00
|
|
|
if (len > 0)
|
2009-08-19 17:21:44 +00:00
|
|
|
etdev->Stats.multircv++;
|
2009-06-10 16:30:41 +00:00
|
|
|
} else if (Word0.value & ALCATEL_BROADCAST_PKT)
|
2009-08-19 17:21:44 +00:00
|
|
|
etdev->Stats.brdcstrcv++;
|
2009-06-10 16:30:41 +00:00
|
|
|
else
|
2008-04-04 00:30:53 +00:00
|
|
|
/* Not sure what this counter measures in
|
|
|
|
* promiscuous mode. Perhaps we should check
|
|
|
|
* the MAC address to see if it is directed
|
|
|
|
* to us in promiscuous mode.
|
|
|
|
*/
|
2009-08-19 17:21:44 +00:00
|
|
|
etdev->Stats.unircv++;
|
2008-04-04 00:30:53 +00:00
|
|
|
}
|
|
|
|
|
2009-10-06 14:48:57 +00:00
|
|
|
if (len > 0) {
|
2008-04-04 00:30:53 +00:00
|
|
|
struct sk_buff *skb = NULL;
|
|
|
|
|
2009-10-06 14:48:57 +00:00
|
|
|
/* rfd->PacketSize = len - 4; */
|
|
|
|
rfd->PacketSize = len;
|
2008-04-04 00:30:53 +00:00
|
|
|
|
2009-10-06 14:48:57 +00:00
|
|
|
skb = dev_alloc_skb(rfd->PacketSize + 2);
|
2008-04-04 00:30:53 +00:00
|
|
|
if (!skb) {
|
2009-08-27 10:03:09 +00:00
|
|
|
dev_err(&etdev->pdev->dev,
|
2008-04-04 00:30:53 +00:00
|
|
|
"Couldn't alloc an SKB for Rx\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-10-06 14:48:57 +00:00
|
|
|
etdev->net_stats.rx_bytes += rfd->PacketSize;
|
2008-04-04 00:30:53 +00:00
|
|
|
|
2009-10-06 14:48:57 +00:00
|
|
|
memcpy(skb_put(skb, rfd->PacketSize),
|
|
|
|
rx_local->Fbr[rindex]->Va[bindex],
|
|
|
|
rfd->PacketSize);
|
2008-04-04 00:30:53 +00:00
|
|
|
|
2009-08-19 17:21:44 +00:00
|
|
|
skb->dev = etdev->netdev;
|
|
|
|
skb->protocol = eth_type_trans(skb, etdev->netdev);
|
2008-04-04 00:30:53 +00:00
|
|
|
skb->ip_summed = CHECKSUM_NONE;
|
|
|
|
|
|
|
|
netif_rx(skb);
|
|
|
|
} else {
|
2009-10-06 14:48:57 +00:00
|
|
|
rfd->PacketSize = 0;
|
2008-04-04 00:30:53 +00:00
|
|
|
}
|
|
|
|
|
2009-10-06 14:48:57 +00:00
|
|
|
nic_return_rfd(etdev, rfd);
|
|
|
|
return rfd;
|
2008-04-04 00:30:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* et131x_reset_recv - Reset the receive list
|
2009-08-19 17:21:44 +00:00
|
|
|
* @etdev: pointer to our adapter
|
2008-04-04 00:30:53 +00:00
|
|
|
*
|
|
|
|
* Assumption, Rcv spinlock has been acquired.
|
|
|
|
*/
|
2009-08-19 17:21:44 +00:00
|
|
|
void et131x_reset_recv(struct et131x_adapter *etdev)
|
2008-04-04 00:30:53 +00:00
|
|
|
{
|
2009-10-06 14:48:57 +00:00
|
|
|
PMP_RFD rfd;
|
2008-04-04 00:30:53 +00:00
|
|
|
struct list_head *element;
|
|
|
|
|
2009-08-27 10:03:09 +00:00
|
|
|
WARN_ON(list_empty(&etdev->RxRing.RecvList));
|
2008-04-04 00:30:53 +00:00
|
|
|
|
|
|
|
/* Take all the RFD's from the pending list, and stick them on the
|
|
|
|
* RecvList.
|
|
|
|
*/
|
2009-08-19 17:21:44 +00:00
|
|
|
while (!list_empty(&etdev->RxRing.RecvPendingList)) {
|
|
|
|
element = etdev->RxRing.RecvPendingList.next;
|
2008-04-04 00:30:53 +00:00
|
|
|
|
2009-10-06 14:48:57 +00:00
|
|
|
rfd = (PMP_RFD) list_entry(element, MP_RFD, list_node);
|
2008-04-04 00:30:53 +00:00
|
|
|
|
2009-10-06 14:48:57 +00:00
|
|
|
list_move_tail(&rfd->list_node, &etdev->RxRing.RecvList);
|
2008-04-04 00:30:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* et131x_handle_recv_interrupt - Interrupt handler for receive processing
|
2009-08-19 17:21:44 +00:00
|
|
|
* @etdev: pointer to our adapter
|
2008-04-04 00:30:53 +00:00
|
|
|
*
|
|
|
|
* Assumption, Rcv spinlock has been acquired.
|
|
|
|
*/
|
2009-08-19 17:21:44 +00:00
|
|
|
void et131x_handle_recv_interrupt(struct et131x_adapter *etdev)
|
2008-04-04 00:30:53 +00:00
|
|
|
{
|
2009-10-06 14:48:57 +00:00
|
|
|
PMP_RFD rfd = NULL;
|
|
|
|
struct sk_buff *packets[NUM_PACKETS_HANDLED];
|
|
|
|
PMP_RFD freed[NUM_PACKETS_HANDLED];
|
|
|
|
u32 count = 0;
|
|
|
|
u32 nfree = 0;
|
|
|
|
bool done = true;
|
2008-04-04 00:30:53 +00:00
|
|
|
|
|
|
|
/* Process up to available RFD's */
|
2009-10-06 14:48:57 +00:00
|
|
|
while (count < NUM_PACKETS_HANDLED) {
|
2009-08-19 17:21:44 +00:00
|
|
|
if (list_empty(&etdev->RxRing.RecvList)) {
|
2009-08-27 10:03:09 +00:00
|
|
|
WARN_ON(etdev->RxRing.nReadyRecv != 0);
|
2009-10-06 14:48:57 +00:00
|
|
|
done = false;
|
2008-04-04 00:30:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-10-06 14:48:57 +00:00
|
|
|
rfd = nic_rx_pkts(etdev);
|
2008-04-04 00:30:53 +00:00
|
|
|
|
2009-10-06 14:48:57 +00:00
|
|
|
if (rfd == NULL)
|
2008-04-04 00:30:53 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* Do not receive any packets until a filter has been set.
|
|
|
|
* Do not receive any packets until we have link.
|
|
|
|
* If length is zero, return the RFD in order to advance the
|
|
|
|
* Free buffer ring.
|
|
|
|
*/
|
2009-08-27 10:02:05 +00:00
|
|
|
if (!etdev->PacketFilter ||
|
|
|
|
!(etdev->Flags & fMP_ADAPTER_LINK_DETECTION) ||
|
2009-10-06 14:48:57 +00:00
|
|
|
rfd->PacketSize == 0) {
|
2008-04-04 00:30:53 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Increment the number of packets we received */
|
2009-08-19 17:21:44 +00:00
|
|
|
etdev->Stats.ipackets++;
|
2008-04-04 00:30:53 +00:00
|
|
|
|
|
|
|
/* Set the status on the packet, either resources or success */
|
2009-08-19 17:21:44 +00:00
|
|
|
if (etdev->RxRing.nReadyRecv >= RFD_LOW_WATER_MARK) {
|
2008-04-04 00:30:53 +00:00
|
|
|
/* 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 {
|
2009-10-06 14:48:57 +00:00
|
|
|
freed[nfree] = rfd;
|
|
|
|
nfree++;
|
2008-04-04 00:30:53 +00:00
|
|
|
|
2009-08-27 10:03:09 +00:00
|
|
|
dev_warn(&etdev->pdev->dev,
|
|
|
|
"RFD's are running out\n");
|
2008-04-04 00:30:53 +00:00
|
|
|
}
|
|
|
|
|
2009-10-06 14:48:57 +00:00
|
|
|
packets[count] = rfd->Packet;
|
|
|
|
count++;
|
2008-04-04 00:30:53 +00:00
|
|
|
}
|
|
|
|
|
2009-10-06 14:48:57 +00:00
|
|
|
if (count == NUM_PACKETS_HANDLED || !done) {
|
2009-08-19 17:21:44 +00:00
|
|
|
etdev->RxRing.UnfinishedReceives = true;
|
2009-08-27 09:59:56 +00:00
|
|
|
writel(PARM_TX_TIME_INT_DEF * NANO_IN_A_MICRO,
|
2009-08-27 09:59:30 +00:00
|
|
|
&etdev->regs->global.watchdog_timer);
|
2009-10-06 14:48:57 +00:00
|
|
|
} else
|
2008-04-04 00:30:53 +00:00
|
|
|
/* Watchdog timer will disable itself if appropriate. */
|
2009-08-19 17:21:44 +00:00
|
|
|
etdev->RxRing.UnfinishedReceives = false;
|
2008-04-04 00:30:53 +00:00
|
|
|
}
|
|
|
|
|
2009-08-27 10:01:57 +00:00
|
|
|
static inline u32 bump_fbr(u32 *fbr, u32 limit)
|
|
|
|
{
|
2009-10-12 14:38:17 +00:00
|
|
|
u32 v = *fbr;
|
|
|
|
v++;
|
|
|
|
/* This works for all cases where limit < 1024. The 1023 case
|
|
|
|
works because 1023++ is 1024 which means the if condition is not
|
|
|
|
taken but the carry of the bit into the wrap bit toggles the wrap
|
|
|
|
value correctly */
|
|
|
|
if ((v & ET_DMA10_MASK) > limit) {
|
|
|
|
v &= ~ET_DMA10_MASK;
|
|
|
|
v ^= ET_DMA10_WRAP;
|
|
|
|
}
|
|
|
|
/* For the 1023 case */
|
|
|
|
v &= (ET_DMA10_MASK|ET_DMA10_WRAP);
|
|
|
|
*fbr = v;
|
|
|
|
return v;
|
2009-08-27 10:01:57 +00:00
|
|
|
}
|
|
|
|
|
2008-04-04 00:30:53 +00:00
|
|
|
/**
|
|
|
|
* NICReturnRFD - Recycle a RFD and put it back onto the receive list
|
2009-08-19 17:21:44 +00:00
|
|
|
* @etdev: pointer to our adapter
|
2009-10-06 14:48:57 +00:00
|
|
|
* @rfd: pointer to the RFD
|
2008-04-04 00:30:53 +00:00
|
|
|
*/
|
2009-10-06 14:48:57 +00:00
|
|
|
void nic_return_rfd(struct et131x_adapter *etdev, PMP_RFD rfd)
|
2008-04-04 00:30:53 +00:00
|
|
|
{
|
2009-08-27 10:00:36 +00:00
|
|
|
struct _rx_ring_t *rx_local = &etdev->RxRing;
|
|
|
|
struct _RXDMA_t __iomem *rx_dma = &etdev->regs->rxdma;
|
2009-10-06 14:48:57 +00:00
|
|
|
uint16_t bi = rfd->bufferindex;
|
|
|
|
uint8_t ri = rfd->ringindex;
|
2009-08-19 17:21:50 +00:00
|
|
|
unsigned long flags;
|
2008-04-04 00:30:53 +00:00
|
|
|
|
|
|
|
/* We don't use any of the OOB data besides status. Otherwise, we
|
|
|
|
* need to clean up OOB data
|
|
|
|
*/
|
|
|
|
if (
|
|
|
|
#ifdef USE_FBR0
|
2009-08-27 10:00:36 +00:00
|
|
|
(ri == 0 && bi < rx_local->Fbr0NumEntries) ||
|
2008-04-04 00:30:53 +00:00
|
|
|
#endif
|
2009-08-27 10:00:36 +00:00
|
|
|
(ri == 1 && bi < rx_local->Fbr1NumEntries)) {
|
2009-08-19 17:21:50 +00:00
|
|
|
spin_lock_irqsave(&etdev->FbrLock, flags);
|
2008-04-04 00:30:53 +00:00
|
|
|
|
|
|
|
if (ri == 1) {
|
2009-10-06 14:48:57 +00:00
|
|
|
PFBR_DESC_t next =
|
2009-08-27 10:00:36 +00:00
|
|
|
(PFBR_DESC_t) (rx_local->pFbr1RingVa) +
|
2009-08-27 10:01:57 +00:00
|
|
|
INDEX10(rx_local->local_Fbr1_full);
|
2008-04-04 00:30:53 +00:00
|
|
|
|
|
|
|
/* Handle the Free Buffer Ring advancement here. Write
|
|
|
|
* the PA / Buffer Index for the returned buffer into
|
|
|
|
* the oldest (next to be freed)FBR entry
|
|
|
|
*/
|
2009-10-06 14:48:57 +00:00
|
|
|
next->addr_hi = rx_local->Fbr[1]->PAHigh[bi];
|
|
|
|
next->addr_lo = rx_local->Fbr[1]->PALow[bi];
|
|
|
|
next->word2.value = bi;
|
2008-04-04 00:30:53 +00:00
|
|
|
|
2009-08-27 10:01:57 +00:00
|
|
|
writel(bump_fbr(&rx_local->local_Fbr1_full,
|
|
|
|
rx_local->Fbr1NumEntries - 1),
|
|
|
|
&rx_dma->fbr1_full_offset);
|
2008-04-04 00:30:53 +00:00
|
|
|
}
|
|
|
|
#ifdef USE_FBR0
|
|
|
|
else {
|
2009-10-06 14:48:57 +00:00
|
|
|
PFBR_DESC_t next =
|
2009-08-27 10:00:36 +00:00
|
|
|
(PFBR_DESC_t) rx_local->pFbr0RingVa +
|
2009-08-27 10:01:57 +00:00
|
|
|
INDEX10(rx_local->local_Fbr0_full);
|
2008-04-04 00:30:53 +00:00
|
|
|
|
|
|
|
/* Handle the Free Buffer Ring advancement here. Write
|
|
|
|
* the PA / Buffer Index for the returned buffer into
|
|
|
|
* the oldest (next to be freed) FBR entry
|
|
|
|
*/
|
2009-10-06 14:48:57 +00:00
|
|
|
next->addr_hi = rx_local->Fbr[0]->PAHigh[bi];
|
|
|
|
next->addr_lo = rx_local->Fbr[0]->PALow[bi];
|
|
|
|
next->word2.value = bi;
|
2008-04-04 00:30:53 +00:00
|
|
|
|
2009-08-27 10:01:57 +00:00
|
|
|
writel(bump_fbr(&rx_local->local_Fbr0_full,
|
|
|
|
rx_local->Fbr0NumEntries - 1),
|
|
|
|
&rx_dma->fbr0_full_offset);
|
2008-04-04 00:30:53 +00:00
|
|
|
}
|
|
|
|
#endif
|
2009-08-19 17:21:50 +00:00
|
|
|
spin_unlock_irqrestore(&etdev->FbrLock, flags);
|
2008-04-04 00:30:53 +00:00
|
|
|
} else {
|
2009-08-27 10:03:09 +00:00
|
|
|
dev_err(&etdev->pdev->dev,
|
2008-04-04 00:30:53 +00:00
|
|
|
"NICReturnRFD illegal Buffer Index returned\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The processing on this RFD is done, so put it back on the tail of
|
|
|
|
* our list
|
|
|
|
*/
|
2009-08-19 17:21:50 +00:00
|
|
|
spin_lock_irqsave(&etdev->RcvLock, flags);
|
2009-10-06 14:48:57 +00:00
|
|
|
list_add_tail(&rfd->list_node, &rx_local->RecvList);
|
2009-08-27 10:00:36 +00:00
|
|
|
rx_local->nReadyRecv++;
|
2009-08-19 17:21:50 +00:00
|
|
|
spin_unlock_irqrestore(&etdev->RcvLock, flags);
|
2008-04-04 00:30:53 +00:00
|
|
|
|
2009-08-27 10:03:09 +00:00
|
|
|
WARN_ON(rx_local->nReadyRecv > rx_local->NumRfd);
|
2008-04-04 00:30:53 +00:00
|
|
|
}
|