Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Agere Systems Inc. |
| 3 | * 10/100/1000 Base-T Ethernet Driver for the ET1301 and ET131x series MACs |
| 4 | * |
Alan Cox | 64f9303 | 2009-06-10 17:30:41 +0100 | [diff] [blame] | 5 | * Copyright © 2005 Agere Systems Inc. |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 6 | * All rights reserved. |
| 7 | * http://www.agere.com |
| 8 | * |
| 9 | *------------------------------------------------------------------------------ |
| 10 | * |
| 11 | * et1310_rx.c - Routines used to perform data reception |
| 12 | * |
| 13 | *------------------------------------------------------------------------------ |
| 14 | * |
| 15 | * SOFTWARE LICENSE |
| 16 | * |
| 17 | * This software is provided subject to the following terms and conditions, |
| 18 | * which you should read carefully before using the software. Using this |
| 19 | * software indicates your acceptance of these terms and conditions. If you do |
| 20 | * not agree with these terms and conditions, do not use the software. |
| 21 | * |
Alan Cox | 64f9303 | 2009-06-10 17:30:41 +0100 | [diff] [blame] | 22 | * Copyright © 2005 Agere Systems Inc. |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 23 | * All rights reserved. |
| 24 | * |
| 25 | * Redistribution and use in source or binary forms, with or without |
| 26 | * modifications, are permitted provided that the following conditions are met: |
| 27 | * |
| 28 | * . Redistributions of source code must retain the above copyright notice, this |
| 29 | * list of conditions and the following Disclaimer as comments in the code as |
| 30 | * well as in the documentation and/or other materials provided with the |
| 31 | * distribution. |
| 32 | * |
| 33 | * . Redistributions in binary form must reproduce the above copyright notice, |
| 34 | * this list of conditions and the following Disclaimer in the documentation |
| 35 | * and/or other materials provided with the distribution. |
| 36 | * |
| 37 | * . Neither the name of Agere Systems Inc. nor the names of the contributors |
| 38 | * may be used to endorse or promote products derived from this software |
| 39 | * without specific prior written permission. |
| 40 | * |
| 41 | * Disclaimer |
| 42 | * |
Alan Cox | 64f9303 | 2009-06-10 17:30:41 +0100 | [diff] [blame] | 43 | * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 44 | * INCLUDING, BUT NOT LIMITED TO, INFRINGEMENT AND THE IMPLIED WARRANTIES OF |
| 45 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ANY |
| 46 | * USE, MODIFICATION OR DISTRIBUTION OF THIS SOFTWARE IS SOLELY AT THE USERS OWN |
| 47 | * RISK. IN NO EVENT SHALL AGERE SYSTEMS INC. OR CONTRIBUTORS BE LIABLE FOR ANY |
| 48 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 49 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 50 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 51 | * ON ANY THEORY OF LIABILITY, INCLUDING, BUT NOT LIMITED TO, CONTRACT, STRICT |
| 52 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
| 53 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH |
| 54 | * DAMAGE. |
| 55 | * |
| 56 | */ |
| 57 | |
| 58 | #include "et131x_version.h" |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 59 | #include "et131x_defs.h" |
| 60 | |
| 61 | #include <linux/pci.h> |
| 62 | #include <linux/init.h> |
| 63 | #include <linux/module.h> |
| 64 | #include <linux/types.h> |
| 65 | #include <linux/kernel.h> |
| 66 | |
| 67 | #include <linux/sched.h> |
| 68 | #include <linux/ptrace.h> |
| 69 | #include <linux/slab.h> |
| 70 | #include <linux/ctype.h> |
| 71 | #include <linux/string.h> |
| 72 | #include <linux/timer.h> |
| 73 | #include <linux/interrupt.h> |
| 74 | #include <linux/in.h> |
| 75 | #include <linux/delay.h> |
Alan Cox | 64f9303 | 2009-06-10 17:30:41 +0100 | [diff] [blame] | 76 | #include <linux/io.h> |
| 77 | #include <linux/bitops.h> |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 78 | #include <asm/system.h> |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 79 | |
| 80 | #include <linux/netdevice.h> |
| 81 | #include <linux/etherdevice.h> |
| 82 | #include <linux/skbuff.h> |
| 83 | #include <linux/if_arp.h> |
| 84 | #include <linux/ioport.h> |
| 85 | |
| 86 | #include "et1310_phy.h" |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 87 | #include "et131x_adapter.h" |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 88 | #include "et1310_rx.h" |
Alan Cox | 69ea5fc | 2010-01-18 15:34:24 +0000 | [diff] [blame] | 89 | #include "et131x.h" |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 90 | |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 91 | void nic_return_rfd(struct et131x_adapter *etdev, PMP_RFD pMpRfd); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 92 | |
| 93 | /** |
| 94 | * et131x_rx_dma_memory_alloc |
| 95 | * @adapter: pointer to our private adapter structure |
| 96 | * |
| 97 | * Returns 0 on success and errno on failure (as defined in errno.h) |
| 98 | * |
| 99 | * Allocates Free buffer ring 1 for sure, free buffer ring 0 if required, |
| 100 | * and the Packet Status Ring. |
| 101 | */ |
| 102 | int et131x_rx_dma_memory_alloc(struct et131x_adapter *adapter) |
| 103 | { |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 104 | u32 i, j; |
| 105 | u32 bufsize; |
| 106 | u32 pktStatRingSize, FBRChunkSize; |
Alan Cox | 8f12785 | 2010-01-18 15:34:07 +0000 | [diff] [blame] | 107 | struct rx_ring *rx_ring; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 108 | |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 109 | /* Setup some convenience pointers */ |
Alan Cox | 8f12785 | 2010-01-18 15:34:07 +0000 | [diff] [blame] | 110 | rx_ring = &adapter->rx_ring; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 111 | |
| 112 | /* Alloc memory for the lookup table */ |
| 113 | #ifdef USE_FBR0 |
Alan Cox | 8a66278 | 2010-01-18 15:33:56 +0000 | [diff] [blame] | 114 | rx_ring->fbr[0] = kmalloc(sizeof(struct fbr_lookup), GFP_KERNEL); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 115 | #endif |
Alan Cox | 8a66278 | 2010-01-18 15:33:56 +0000 | [diff] [blame] | 116 | rx_ring->fbr[1] = kmalloc(sizeof(struct fbr_lookup), GFP_KERNEL); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 117 | |
| 118 | /* The first thing we will do is configure the sizes of the buffer |
| 119 | * rings. These will change based on jumbo packet support. Larger |
| 120 | * jumbo packets increases the size of each entry in FBR0, and the |
| 121 | * number of entries in FBR0, while at the same time decreasing the |
| 122 | * number of entries in FBR1. |
| 123 | * |
| 124 | * FBR1 holds "large" frames, FBR0 holds "small" frames. If FBR1 |
| 125 | * entries are huge in order to accomodate a "jumbo" frame, then it |
| 126 | * will have less entries. Conversely, FBR1 will now be relied upon |
| 127 | * to carry more "normal" frames, thus it's entry size also increases |
| 128 | * and the number of entries goes up too (since it now carries |
| 129 | * "small" + "regular" packets. |
| 130 | * |
| 131 | * In this scheme, we try to maintain 512 entries between the two |
| 132 | * rings. Also, FBR1 remains a constant size - when it's size doubles |
| 133 | * the number of entries halves. FBR0 increases in size, however. |
| 134 | */ |
| 135 | |
| 136 | if (adapter->RegistryJumboPacket < 2048) { |
| 137 | #ifdef USE_FBR0 |
| 138 | rx_ring->Fbr0BufferSize = 256; |
| 139 | rx_ring->Fbr0NumEntries = 512; |
| 140 | #endif |
| 141 | rx_ring->Fbr1BufferSize = 2048; |
| 142 | rx_ring->Fbr1NumEntries = 512; |
| 143 | } else if (adapter->RegistryJumboPacket < 4096) { |
| 144 | #ifdef USE_FBR0 |
| 145 | rx_ring->Fbr0BufferSize = 512; |
| 146 | rx_ring->Fbr0NumEntries = 1024; |
| 147 | #endif |
| 148 | rx_ring->Fbr1BufferSize = 4096; |
| 149 | rx_ring->Fbr1NumEntries = 512; |
| 150 | } else { |
| 151 | #ifdef USE_FBR0 |
| 152 | rx_ring->Fbr0BufferSize = 1024; |
| 153 | rx_ring->Fbr0NumEntries = 768; |
| 154 | #endif |
| 155 | rx_ring->Fbr1BufferSize = 16384; |
| 156 | rx_ring->Fbr1NumEntries = 128; |
| 157 | } |
| 158 | |
| 159 | #ifdef USE_FBR0 |
Alan Cox | 8f12785 | 2010-01-18 15:34:07 +0000 | [diff] [blame] | 160 | adapter->rx_ring.PsrNumEntries = adapter->rx_ring.Fbr0NumEntries + |
| 161 | adapter->rx_ring.Fbr1NumEntries; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 162 | #else |
Alan Cox | 8f12785 | 2010-01-18 15:34:07 +0000 | [diff] [blame] | 163 | adapter->rx_ring.PsrNumEntries = adapter->rx_ring.Fbr1NumEntries; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 164 | #endif |
| 165 | |
| 166 | /* Allocate an area of memory for Free Buffer Ring 1 */ |
Alan Cox | 13a79c6 | 2010-01-18 15:32:50 +0000 | [diff] [blame] | 167 | bufsize = (sizeof(struct fbr_desc) * rx_ring->Fbr1NumEntries) + 0xfff; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 168 | rx_ring->pFbr1RingVa = pci_alloc_consistent(adapter->pdev, |
| 169 | bufsize, |
| 170 | &rx_ring->pFbr1RingPa); |
| 171 | if (!rx_ring->pFbr1RingVa) { |
Alan Cox | 1570003 | 2009-08-27 11:03:09 +0100 | [diff] [blame] | 172 | dev_err(&adapter->pdev->dev, |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 173 | "Cannot alloc memory for Free Buffer Ring 1\n"); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 174 | return -ENOMEM; |
| 175 | } |
| 176 | |
| 177 | /* Save physical address |
| 178 | * |
| 179 | * NOTE: pci_alloc_consistent(), used above to alloc DMA regions, |
| 180 | * ALWAYS returns SAC (32-bit) addresses. If DAC (64-bit) addresses |
| 181 | * are ever returned, make sure the high part is retrieved here |
| 182 | * before storing the adjusted address. |
| 183 | */ |
| 184 | rx_ring->Fbr1Realpa = rx_ring->pFbr1RingPa; |
| 185 | |
| 186 | /* Align Free Buffer Ring 1 on a 4K boundary */ |
| 187 | et131x_align_allocated_memory(adapter, |
| 188 | &rx_ring->Fbr1Realpa, |
| 189 | &rx_ring->Fbr1offset, 0x0FFF); |
| 190 | |
Alan Cox | 4ba64c1 | 2010-01-18 15:34:02 +0000 | [diff] [blame] | 191 | rx_ring->pFbr1RingVa = (void *)((u8 *) rx_ring->pFbr1RingVa + |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 192 | rx_ring->Fbr1offset); |
| 193 | |
| 194 | #ifdef USE_FBR0 |
| 195 | /* Allocate an area of memory for Free Buffer Ring 0 */ |
Alan Cox | 13a79c6 | 2010-01-18 15:32:50 +0000 | [diff] [blame] | 196 | bufsize = (sizeof(struct fbr_desc) * rx_ring->Fbr0NumEntries) + 0xfff; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 197 | rx_ring->pFbr0RingVa = pci_alloc_consistent(adapter->pdev, |
| 198 | bufsize, |
| 199 | &rx_ring->pFbr0RingPa); |
| 200 | if (!rx_ring->pFbr0RingVa) { |
Alan Cox | 1570003 | 2009-08-27 11:03:09 +0100 | [diff] [blame] | 201 | dev_err(&adapter->pdev->dev, |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 202 | "Cannot alloc memory for Free Buffer Ring 0\n"); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 203 | return -ENOMEM; |
| 204 | } |
| 205 | |
| 206 | /* Save physical address |
| 207 | * |
| 208 | * NOTE: pci_alloc_consistent(), used above to alloc DMA regions, |
| 209 | * ALWAYS returns SAC (32-bit) addresses. If DAC (64-bit) addresses |
| 210 | * are ever returned, make sure the high part is retrieved here before |
| 211 | * storing the adjusted address. |
| 212 | */ |
| 213 | rx_ring->Fbr0Realpa = rx_ring->pFbr0RingPa; |
| 214 | |
| 215 | /* Align Free Buffer Ring 0 on a 4K boundary */ |
| 216 | et131x_align_allocated_memory(adapter, |
| 217 | &rx_ring->Fbr0Realpa, |
| 218 | &rx_ring->Fbr0offset, 0x0FFF); |
| 219 | |
Alan Cox | 4ba64c1 | 2010-01-18 15:34:02 +0000 | [diff] [blame] | 220 | rx_ring->pFbr0RingVa = (void *)((u8 *) rx_ring->pFbr0RingVa + |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 221 | rx_ring->Fbr0offset); |
| 222 | #endif |
| 223 | |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 224 | for (i = 0; i < (rx_ring->Fbr1NumEntries / FBR_CHUNKS); |
| 225 | i++) { |
| 226 | u64 Fbr1Offset; |
| 227 | u64 Fbr1TempPa; |
| 228 | u32 Fbr1Align; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 229 | |
| 230 | /* This code allocates an area of memory big enough for N |
| 231 | * free buffers + (buffer_size - 1) so that the buffers can |
| 232 | * be aligned on 4k boundaries. If each buffer were aligned |
| 233 | * to a buffer_size boundary, the effect would be to double |
| 234 | * the size of FBR0. By allocating N buffers at once, we |
| 235 | * reduce this overhead. |
| 236 | */ |
Alan Cox | 64f9303 | 2009-06-10 17:30:41 +0100 | [diff] [blame] | 237 | if (rx_ring->Fbr1BufferSize > 4096) |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 238 | Fbr1Align = 4096; |
Alan Cox | 64f9303 | 2009-06-10 17:30:41 +0100 | [diff] [blame] | 239 | else |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 240 | Fbr1Align = rx_ring->Fbr1BufferSize; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 241 | |
| 242 | FBRChunkSize = |
| 243 | (FBR_CHUNKS * rx_ring->Fbr1BufferSize) + Fbr1Align - 1; |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 244 | rx_ring->Fbr1MemVa[i] = |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 245 | pci_alloc_consistent(adapter->pdev, FBRChunkSize, |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 246 | &rx_ring->Fbr1MemPa[i]); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 247 | |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 248 | if (!rx_ring->Fbr1MemVa[i]) { |
Alan Cox | 1570003 | 2009-08-27 11:03:09 +0100 | [diff] [blame] | 249 | dev_err(&adapter->pdev->dev, |
| 250 | "Could not alloc memory\n"); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 251 | return -ENOMEM; |
| 252 | } |
| 253 | |
| 254 | /* See NOTE in "Save Physical Address" comment above */ |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 255 | Fbr1TempPa = rx_ring->Fbr1MemPa[i]; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 256 | |
| 257 | et131x_align_allocated_memory(adapter, |
| 258 | &Fbr1TempPa, |
| 259 | &Fbr1Offset, (Fbr1Align - 1)); |
| 260 | |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 261 | for (j = 0; j < FBR_CHUNKS; j++) { |
| 262 | u32 index = (i * FBR_CHUNKS) + j; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 263 | |
| 264 | /* Save the Virtual address of this index for quick |
| 265 | * access later |
| 266 | */ |
Alan Cox | 8a66278 | 2010-01-18 15:33:56 +0000 | [diff] [blame] | 267 | rx_ring->fbr[1]->virt[index] = |
Alan Cox | 4ba64c1 | 2010-01-18 15:34:02 +0000 | [diff] [blame] | 268 | (u8 *) rx_ring->Fbr1MemVa[i] + |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 269 | (j * rx_ring->Fbr1BufferSize) + Fbr1Offset; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 270 | |
| 271 | /* now store the physical address in the descriptor |
| 272 | * so the device can access it |
| 273 | */ |
Alan Cox | 8a66278 | 2010-01-18 15:33:56 +0000 | [diff] [blame] | 274 | rx_ring->fbr[1]->bus_high[index] = |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 275 | (u32) (Fbr1TempPa >> 32); |
Alan Cox | 8a66278 | 2010-01-18 15:33:56 +0000 | [diff] [blame] | 276 | rx_ring->fbr[1]->bus_low[index] = (u32) Fbr1TempPa; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 277 | |
| 278 | Fbr1TempPa += rx_ring->Fbr1BufferSize; |
| 279 | |
Alan Cox | 8a66278 | 2010-01-18 15:33:56 +0000 | [diff] [blame] | 280 | rx_ring->fbr[1]->buffer1[index] = |
| 281 | rx_ring->fbr[1]->virt[index]; |
| 282 | rx_ring->fbr[1]->buffer2[index] = |
| 283 | rx_ring->fbr[1]->virt[index] - 4; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 284 | } |
| 285 | } |
| 286 | |
| 287 | #ifdef USE_FBR0 |
| 288 | /* Same for FBR0 (if in use) */ |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 289 | for (i = 0; i < (rx_ring->Fbr0NumEntries / FBR_CHUNKS); |
| 290 | i++) { |
| 291 | u64 Fbr0Offset; |
| 292 | u64 Fbr0TempPa; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 293 | |
| 294 | FBRChunkSize = ((FBR_CHUNKS + 1) * rx_ring->Fbr0BufferSize) - 1; |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 295 | rx_ring->Fbr0MemVa[i] = |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 296 | pci_alloc_consistent(adapter->pdev, FBRChunkSize, |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 297 | &rx_ring->Fbr0MemPa[i]); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 298 | |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 299 | if (!rx_ring->Fbr0MemVa[i]) { |
Alan Cox | 1570003 | 2009-08-27 11:03:09 +0100 | [diff] [blame] | 300 | dev_err(&adapter->pdev->dev, |
| 301 | "Could not alloc memory\n"); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 302 | return -ENOMEM; |
| 303 | } |
| 304 | |
| 305 | /* See NOTE in "Save Physical Address" comment above */ |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 306 | Fbr0TempPa = rx_ring->Fbr0MemPa[i]; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 307 | |
| 308 | et131x_align_allocated_memory(adapter, |
| 309 | &Fbr0TempPa, |
| 310 | &Fbr0Offset, |
| 311 | rx_ring->Fbr0BufferSize - 1); |
| 312 | |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 313 | for (j = 0; j < FBR_CHUNKS; j++) { |
| 314 | u32 index = (i * FBR_CHUNKS) + j; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 315 | |
Alan Cox | 8a66278 | 2010-01-18 15:33:56 +0000 | [diff] [blame] | 316 | rx_ring->fbr[0]->virt[index] = |
Alan Cox | 4ba64c1 | 2010-01-18 15:34:02 +0000 | [diff] [blame] | 317 | (u8 *) rx_ring->Fbr0MemVa[i] + |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 318 | (j * rx_ring->Fbr0BufferSize) + Fbr0Offset; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 319 | |
Alan Cox | 8a66278 | 2010-01-18 15:33:56 +0000 | [diff] [blame] | 320 | rx_ring->fbr[0]->bus_high[index] = |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 321 | (u32) (Fbr0TempPa >> 32); |
Alan Cox | 8a66278 | 2010-01-18 15:33:56 +0000 | [diff] [blame] | 322 | rx_ring->fbr[0]->bus_low[index] = (u32) Fbr0TempPa; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 323 | |
| 324 | Fbr0TempPa += rx_ring->Fbr0BufferSize; |
| 325 | |
Alan Cox | 8a66278 | 2010-01-18 15:33:56 +0000 | [diff] [blame] | 326 | rx_ring->fbr[0]->buffer1[index] = |
| 327 | rx_ring->fbr[0]->virt[index]; |
| 328 | rx_ring->fbr[0]->buffer2[index] = |
| 329 | rx_ring->fbr[0]->virt[index] - 4; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 330 | } |
| 331 | } |
| 332 | #endif |
| 333 | |
| 334 | /* Allocate an area of memory for FIFO of Packet Status ring entries */ |
| 335 | pktStatRingSize = |
Alan Cox | 8f12785 | 2010-01-18 15:34:07 +0000 | [diff] [blame] | 336 | sizeof(struct pkt_stat_desc) * adapter->rx_ring.PsrNumEntries; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 337 | |
| 338 | rx_ring->pPSRingVa = pci_alloc_consistent(adapter->pdev, |
Alan Cox | 9c60684b | 2009-10-06 15:48:49 +0100 | [diff] [blame] | 339 | pktStatRingSize, |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 340 | &rx_ring->pPSRingPa); |
| 341 | |
| 342 | if (!rx_ring->pPSRingVa) { |
Alan Cox | 1570003 | 2009-08-27 11:03:09 +0100 | [diff] [blame] | 343 | dev_err(&adapter->pdev->dev, |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 344 | "Cannot alloc memory for Packet Status Ring\n"); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 345 | return -ENOMEM; |
| 346 | } |
Michael Sprecher | f3fd4cd | 2010-03-10 13:15:35 +0100 | [diff] [blame] | 347 | printk(KERN_INFO "PSR %lx\n", (unsigned long) rx_ring->pPSRingPa); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 348 | |
Alan Cox | 9c60684b | 2009-10-06 15:48:49 +0100 | [diff] [blame] | 349 | /* |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 350 | * NOTE : pci_alloc_consistent(), used above to alloc DMA regions, |
| 351 | * ALWAYS returns SAC (32-bit) addresses. If DAC (64-bit) addresses |
| 352 | * are ever returned, make sure the high part is retrieved here before |
| 353 | * storing the adjusted address. |
| 354 | */ |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 355 | |
| 356 | /* Allocate an area of memory for writeback of status information */ |
Alan Cox | 07563ac | 2010-01-18 15:33:51 +0000 | [diff] [blame] | 357 | rx_ring->rx_status_block = pci_alloc_consistent(adapter->pdev, |
Alan Cox | f926d21 | 2010-01-18 15:33:45 +0000 | [diff] [blame] | 358 | sizeof(struct rx_status_block), |
Alan Cox | 07563ac | 2010-01-18 15:33:51 +0000 | [diff] [blame] | 359 | &rx_ring->rx_status_bus); |
| 360 | if (!rx_ring->rx_status_block) { |
Alan Cox | 1570003 | 2009-08-27 11:03:09 +0100 | [diff] [blame] | 361 | dev_err(&adapter->pdev->dev, |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 362 | "Cannot alloc memory for Status Block\n"); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 363 | return -ENOMEM; |
| 364 | } |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 365 | rx_ring->NumRfd = NIC_DEFAULT_NUM_RFD; |
Michael Sprecher | f3fd4cd | 2010-03-10 13:15:35 +0100 | [diff] [blame] | 366 | printk(KERN_INFO "PRS %lx\n", (unsigned long)rx_ring->rx_status_bus); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 367 | |
| 368 | /* Recv |
| 369 | * pci_pool_create initializes a lookaside list. After successful |
| 370 | * creation, nonpaged fixed-size blocks can be allocated from and |
| 371 | * freed to the lookaside list. |
| 372 | * RFDs will be allocated from this pool. |
| 373 | */ |
| 374 | rx_ring->RecvLookaside = kmem_cache_create(adapter->netdev->name, |
| 375 | sizeof(MP_RFD), |
| 376 | 0, |
| 377 | SLAB_CACHE_DMA | |
| 378 | SLAB_HWCACHE_ALIGN, |
| 379 | NULL); |
| 380 | |
Alan Cox | f6b35d6 | 2009-08-27 11:02:05 +0100 | [diff] [blame] | 381 | adapter->Flags |= fMP_ADAPTER_RECV_LOOKASIDE; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 382 | |
| 383 | /* The RFDs are going to be put on lists later on, so initialize the |
| 384 | * lists now. |
| 385 | */ |
| 386 | INIT_LIST_HEAD(&rx_ring->RecvList); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 387 | return 0; |
| 388 | } |
| 389 | |
| 390 | /** |
| 391 | * et131x_rx_dma_memory_free - Free all memory allocated within this module. |
| 392 | * @adapter: pointer to our private adapter structure |
| 393 | */ |
| 394 | void et131x_rx_dma_memory_free(struct et131x_adapter *adapter) |
| 395 | { |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 396 | u32 index; |
| 397 | u32 bufsize; |
| 398 | u32 pktStatRingSize; |
| 399 | PMP_RFD rfd; |
Alan Cox | 8f12785 | 2010-01-18 15:34:07 +0000 | [diff] [blame] | 400 | struct rx_ring *rx_ring; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 401 | |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 402 | /* Setup some convenience pointers */ |
Alan Cox | 8f12785 | 2010-01-18 15:34:07 +0000 | [diff] [blame] | 403 | rx_ring = &adapter->rx_ring; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 404 | |
| 405 | /* Free RFDs and associated packet descriptors */ |
Alan Cox | 1570003 | 2009-08-27 11:03:09 +0100 | [diff] [blame] | 406 | WARN_ON(rx_ring->nReadyRecv != rx_ring->NumRfd); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 407 | |
| 408 | while (!list_empty(&rx_ring->RecvList)) { |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 409 | rfd = (MP_RFD *) list_entry(rx_ring->RecvList.next, |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 410 | MP_RFD, list_node); |
| 411 | |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 412 | list_del(&rfd->list_node); |
Alan Cox | f432c55 | 2009-10-06 15:49:13 +0100 | [diff] [blame] | 413 | rfd->Packet = NULL; |
Alan Cox | 8f12785 | 2010-01-18 15:34:07 +0000 | [diff] [blame] | 414 | kmem_cache_free(adapter->rx_ring.RecvLookaside, rfd); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 415 | } |
| 416 | |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 417 | /* Free Free Buffer Ring 1 */ |
| 418 | if (rx_ring->pFbr1RingVa) { |
| 419 | /* First the packet memory */ |
| 420 | for (index = 0; index < |
| 421 | (rx_ring->Fbr1NumEntries / FBR_CHUNKS); index++) { |
| 422 | if (rx_ring->Fbr1MemVa[index]) { |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 423 | u32 Fbr1Align; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 424 | |
Alan Cox | 64f9303 | 2009-06-10 17:30:41 +0100 | [diff] [blame] | 425 | if (rx_ring->Fbr1BufferSize > 4096) |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 426 | Fbr1Align = 4096; |
Alan Cox | 64f9303 | 2009-06-10 17:30:41 +0100 | [diff] [blame] | 427 | else |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 428 | Fbr1Align = rx_ring->Fbr1BufferSize; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 429 | |
| 430 | bufsize = |
| 431 | (rx_ring->Fbr1BufferSize * FBR_CHUNKS) + |
| 432 | Fbr1Align - 1; |
| 433 | |
| 434 | pci_free_consistent(adapter->pdev, |
| 435 | bufsize, |
| 436 | rx_ring->Fbr1MemVa[index], |
| 437 | rx_ring->Fbr1MemPa[index]); |
| 438 | |
| 439 | rx_ring->Fbr1MemVa[index] = NULL; |
| 440 | } |
| 441 | } |
| 442 | |
| 443 | /* Now the FIFO itself */ |
Alan Cox | 4ba64c1 | 2010-01-18 15:34:02 +0000 | [diff] [blame] | 444 | rx_ring->pFbr1RingVa = (void *)((u8 *) |
Alan Cox | 64f9303 | 2009-06-10 17:30:41 +0100 | [diff] [blame] | 445 | rx_ring->pFbr1RingVa - rx_ring->Fbr1offset); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 446 | |
Alan Cox | 13a79c6 | 2010-01-18 15:32:50 +0000 | [diff] [blame] | 447 | bufsize = (sizeof(struct fbr_desc) * rx_ring->Fbr1NumEntries) |
Michael Sprecher | f3fd4cd | 2010-03-10 13:15:35 +0100 | [diff] [blame] | 448 | + 0xfff; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 449 | |
Alan Cox | 13a79c6 | 2010-01-18 15:32:50 +0000 | [diff] [blame] | 450 | pci_free_consistent(adapter->pdev, bufsize, |
Michael Sprecher | f3fd4cd | 2010-03-10 13:15:35 +0100 | [diff] [blame] | 451 | rx_ring->pFbr1RingVa, rx_ring->pFbr1RingPa); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 452 | |
| 453 | rx_ring->pFbr1RingVa = NULL; |
| 454 | } |
| 455 | |
| 456 | #ifdef USE_FBR0 |
| 457 | /* Now the same for Free Buffer Ring 0 */ |
| 458 | if (rx_ring->pFbr0RingVa) { |
| 459 | /* First the packet memory */ |
| 460 | for (index = 0; index < |
| 461 | (rx_ring->Fbr0NumEntries / FBR_CHUNKS); index++) { |
| 462 | if (rx_ring->Fbr0MemVa[index]) { |
| 463 | bufsize = |
| 464 | (rx_ring->Fbr0BufferSize * |
| 465 | (FBR_CHUNKS + 1)) - 1; |
| 466 | |
| 467 | pci_free_consistent(adapter->pdev, |
| 468 | bufsize, |
| 469 | rx_ring->Fbr0MemVa[index], |
| 470 | rx_ring->Fbr0MemPa[index]); |
| 471 | |
| 472 | rx_ring->Fbr0MemVa[index] = NULL; |
| 473 | } |
| 474 | } |
| 475 | |
| 476 | /* Now the FIFO itself */ |
Alan Cox | 4ba64c1 | 2010-01-18 15:34:02 +0000 | [diff] [blame] | 477 | rx_ring->pFbr0RingVa = (void *)((u8 *) |
Alan Cox | 64f9303 | 2009-06-10 17:30:41 +0100 | [diff] [blame] | 478 | rx_ring->pFbr0RingVa - rx_ring->Fbr0offset); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 479 | |
Alan Cox | 13a79c6 | 2010-01-18 15:32:50 +0000 | [diff] [blame] | 480 | bufsize = (sizeof(struct fbr_desc) * rx_ring->Fbr0NumEntries) |
Michael Sprecher | f3fd4cd | 2010-03-10 13:15:35 +0100 | [diff] [blame] | 481 | + 0xfff; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 482 | |
| 483 | pci_free_consistent(adapter->pdev, |
| 484 | bufsize, |
| 485 | rx_ring->pFbr0RingVa, rx_ring->pFbr0RingPa); |
| 486 | |
| 487 | rx_ring->pFbr0RingVa = NULL; |
| 488 | } |
| 489 | #endif |
| 490 | |
| 491 | /* Free Packet Status Ring */ |
| 492 | if (rx_ring->pPSRingVa) { |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 493 | pktStatRingSize = |
Alan Cox | 8f12785 | 2010-01-18 15:34:07 +0000 | [diff] [blame] | 494 | sizeof(struct pkt_stat_desc) * adapter->rx_ring.PsrNumEntries; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 495 | |
Alan Cox | 9c60684b | 2009-10-06 15:48:49 +0100 | [diff] [blame] | 496 | pci_free_consistent(adapter->pdev, pktStatRingSize, |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 497 | rx_ring->pPSRingVa, rx_ring->pPSRingPa); |
| 498 | |
| 499 | rx_ring->pPSRingVa = NULL; |
| 500 | } |
| 501 | |
| 502 | /* Free area of memory for the writeback of status information */ |
Alan Cox | 07563ac | 2010-01-18 15:33:51 +0000 | [diff] [blame] | 503 | if (rx_ring->rx_status_block) { |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 504 | pci_free_consistent(adapter->pdev, |
Alan Cox | 07563ac | 2010-01-18 15:33:51 +0000 | [diff] [blame] | 505 | sizeof(struct rx_status_block), |
| 506 | rx_ring->rx_status_block, rx_ring->rx_status_bus); |
Michael Sprecher | f3fd4cd | 2010-03-10 13:15:35 +0100 | [diff] [blame] | 507 | rx_ring->rx_status_block = NULL; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | /* Free receive buffer pool */ |
| 511 | |
| 512 | /* Free receive packet pool */ |
| 513 | |
| 514 | /* Destroy the lookaside (RFD) pool */ |
Alan Cox | f6b35d6 | 2009-08-27 11:02:05 +0100 | [diff] [blame] | 515 | if (adapter->Flags & fMP_ADAPTER_RECV_LOOKASIDE) { |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 516 | kmem_cache_destroy(rx_ring->RecvLookaside); |
Alan Cox | f6b35d6 | 2009-08-27 11:02:05 +0100 | [diff] [blame] | 517 | adapter->Flags &= ~fMP_ADAPTER_RECV_LOOKASIDE; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | /* Free the FBR Lookup Table */ |
| 521 | #ifdef USE_FBR0 |
Alan Cox | 8a66278 | 2010-01-18 15:33:56 +0000 | [diff] [blame] | 522 | kfree(rx_ring->fbr[0]); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 523 | #endif |
| 524 | |
Alan Cox | 8a66278 | 2010-01-18 15:33:56 +0000 | [diff] [blame] | 525 | kfree(rx_ring->fbr[1]); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 526 | |
| 527 | /* Reset Counters */ |
| 528 | rx_ring->nReadyRecv = 0; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 529 | } |
| 530 | |
| 531 | /** |
| 532 | * et131x_init_recv - Initialize receive data structures. |
| 533 | * @adapter: pointer to our private adapter structure |
| 534 | * |
| 535 | * Returns 0 on success and errno on failure (as defined in errno.h) |
| 536 | */ |
| 537 | int et131x_init_recv(struct et131x_adapter *adapter) |
| 538 | { |
| 539 | int status = -ENOMEM; |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 540 | PMP_RFD rfd = NULL; |
| 541 | u32 rfdct; |
| 542 | u32 numrfd = 0; |
Alan Cox | 8f12785 | 2010-01-18 15:34:07 +0000 | [diff] [blame] | 543 | struct rx_ring *rx_ring; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 544 | |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 545 | /* Setup some convenience pointers */ |
Alan Cox | 8f12785 | 2010-01-18 15:34:07 +0000 | [diff] [blame] | 546 | rx_ring = &adapter->rx_ring; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 547 | |
| 548 | /* Setup each RFD */ |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 549 | for (rfdct = 0; rfdct < rx_ring->NumRfd; rfdct++) { |
Julia Lawall | 3241487 | 2010-05-11 20:26:57 +0200 | [diff] [blame] | 550 | rfd = kmem_cache_alloc(rx_ring->RecvLookaside, |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 551 | GFP_ATOMIC | GFP_DMA); |
| 552 | |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 553 | if (!rfd) { |
Alan Cox | 1570003 | 2009-08-27 11:03:09 +0100 | [diff] [blame] | 554 | dev_err(&adapter->pdev->dev, |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 555 | "Couldn't alloc RFD out of kmem_cache\n"); |
| 556 | status = -ENOMEM; |
| 557 | continue; |
| 558 | } |
| 559 | |
Alan Cox | f432c55 | 2009-10-06 15:49:13 +0100 | [diff] [blame] | 560 | rfd->Packet = NULL; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 561 | |
| 562 | /* Add this RFD to the RecvList */ |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 563 | list_add_tail(&rfd->list_node, &rx_ring->RecvList); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 564 | |
| 565 | /* Increment both the available RFD's, and the total RFD's. */ |
| 566 | rx_ring->nReadyRecv++; |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 567 | numrfd++; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 568 | } |
| 569 | |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 570 | if (numrfd > NIC_MIN_NUM_RFD) |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 571 | status = 0; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 572 | |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 573 | rx_ring->NumRfd = numrfd; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 574 | |
| 575 | if (status != 0) { |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 576 | kmem_cache_free(rx_ring->RecvLookaside, rfd); |
Alan Cox | 1570003 | 2009-08-27 11:03:09 +0100 | [diff] [blame] | 577 | dev_err(&adapter->pdev->dev, |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 578 | "Allocation problems in et131x_init_recv\n"); |
| 579 | } |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 580 | return status; |
| 581 | } |
| 582 | |
| 583 | /** |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 584 | * ConfigRxDmaRegs - Start of Rx_DMA init sequence |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 585 | * @etdev: pointer to our adapter structure |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 586 | */ |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 587 | void ConfigRxDmaRegs(struct et131x_adapter *etdev) |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 588 | { |
Alan Cox | 61d5ed8 | 2010-01-18 15:33:01 +0000 | [diff] [blame] | 589 | struct rxdma_regs __iomem *rx_dma = &etdev->regs->rxdma; |
Alan Cox | 8f12785 | 2010-01-18 15:34:07 +0000 | [diff] [blame] | 590 | struct rx_ring *rx_local = &etdev->rx_ring; |
Alan Cox | 13a79c6 | 2010-01-18 15:32:50 +0000 | [diff] [blame] | 591 | struct fbr_desc *fbr_entry; |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 592 | u32 entry; |
Alan Cox | 2e5e0b8 | 2009-11-18 14:07:48 +0000 | [diff] [blame] | 593 | u32 psr_num_des; |
Alan Cox | 3762860 | 2009-08-19 18:21:50 +0100 | [diff] [blame] | 594 | unsigned long flags; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 595 | |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 596 | /* Halt RXDMA to perform the reconfigure. */ |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 597 | et131x_rx_dma_disable(etdev); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 598 | |
| 599 | /* Load the completion writeback physical address |
| 600 | * |
| 601 | * NOTE : pci_alloc_consistent(), used above to alloc DMA regions, |
| 602 | * ALWAYS returns SAC (32-bit) addresses. If DAC (64-bit) addresses |
| 603 | * are ever returned, make sure the high part is retrieved here |
| 604 | * before storing the adjusted address. |
| 605 | */ |
Alan Cox | 8a66278 | 2010-01-18 15:33:56 +0000 | [diff] [blame] | 606 | writel((u32) ((u64)rx_local->rx_status_bus >> 32), |
Alan Cox | 9fa8109 | 2009-08-27 11:00:36 +0100 | [diff] [blame] | 607 | &rx_dma->dma_wb_base_hi); |
Alan Cox | 8a66278 | 2010-01-18 15:33:56 +0000 | [diff] [blame] | 608 | writel((u32) rx_local->rx_status_bus, &rx_dma->dma_wb_base_lo); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 609 | |
Alan Cox | 07563ac | 2010-01-18 15:33:51 +0000 | [diff] [blame] | 610 | memset(rx_local->rx_status_block, 0, sizeof(struct rx_status_block)); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 611 | |
| 612 | /* Set the address and parameters of the packet status ring into the |
| 613 | * 1310's registers |
| 614 | */ |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 615 | writel((u32) ((u64)rx_local->pPSRingPa >> 32), |
Alan Cox | 9fa8109 | 2009-08-27 11:00:36 +0100 | [diff] [blame] | 616 | &rx_dma->psr_base_hi); |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 617 | writel((u32) rx_local->pPSRingPa, &rx_dma->psr_base_lo); |
Alan Cox | 2e5e0b8 | 2009-11-18 14:07:48 +0000 | [diff] [blame] | 618 | writel(rx_local->PsrNumEntries - 1, &rx_dma->psr_num_des); |
Alan Cox | 99fd99f | 2009-11-18 14:07:58 +0000 | [diff] [blame] | 619 | writel(0, &rx_dma->psr_full_offset); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 620 | |
Alan Cox | 2e5e0b8 | 2009-11-18 14:07:48 +0000 | [diff] [blame] | 621 | psr_num_des = readl(&rx_dma->psr_num_des) & 0xFFF; |
| 622 | writel((psr_num_des * LO_MARK_PERCENT_FOR_PSR) / 100, |
| 623 | &rx_dma->psr_min_des); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 624 | |
Alan Cox | 3762860 | 2009-08-19 18:21:50 +0100 | [diff] [blame] | 625 | spin_lock_irqsave(&etdev->RcvLock, flags); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 626 | |
| 627 | /* These local variables track the PSR in the adapter structure */ |
Alan Cox | 99fd99f | 2009-11-18 14:07:58 +0000 | [diff] [blame] | 628 | rx_local->local_psr_full = 0; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 629 | |
| 630 | /* Now's the best time to initialize FBR1 contents */ |
Alan Cox | 13a79c6 | 2010-01-18 15:32:50 +0000 | [diff] [blame] | 631 | fbr_entry = (struct fbr_desc *) rx_local->pFbr1RingVa; |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 632 | for (entry = 0; entry < rx_local->Fbr1NumEntries; entry++) { |
Alan Cox | 8a66278 | 2010-01-18 15:33:56 +0000 | [diff] [blame] | 633 | fbr_entry->addr_hi = rx_local->fbr[1]->bus_high[entry]; |
| 634 | fbr_entry->addr_lo = rx_local->fbr[1]->bus_low[entry]; |
Alan Cox | 7d9e15e | 2010-01-18 15:32:44 +0000 | [diff] [blame] | 635 | fbr_entry->word2 = entry; |
Alan Cox | 9fa8109 | 2009-08-27 11:00:36 +0100 | [diff] [blame] | 636 | fbr_entry++; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 637 | } |
| 638 | |
| 639 | /* Set the address and parameters of Free buffer ring 1 (and 0 if |
| 640 | * required) into the 1310's registers |
| 641 | */ |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 642 | writel((u32) (rx_local->Fbr1Realpa >> 32), &rx_dma->fbr1_base_hi); |
| 643 | writel((u32) rx_local->Fbr1Realpa, &rx_dma->fbr1_base_lo); |
Alan Cox | 2e5e0b8 | 2009-11-18 14:07:48 +0000 | [diff] [blame] | 644 | writel(rx_local->Fbr1NumEntries - 1, &rx_dma->fbr1_num_des); |
Alan Cox | 356c74b | 2009-08-27 11:01:57 +0100 | [diff] [blame] | 645 | writel(ET_DMA10_WRAP, &rx_dma->fbr1_full_offset); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 646 | |
| 647 | /* This variable tracks the free buffer ring 1 full position, so it |
| 648 | * has to match the above. |
| 649 | */ |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 650 | rx_local->local_Fbr1_full = ET_DMA10_WRAP; |
| 651 | writel(((rx_local->Fbr1NumEntries * LO_MARK_PERCENT_FOR_RX) / 100) - 1, |
Alan Cox | 2e5e0b8 | 2009-11-18 14:07:48 +0000 | [diff] [blame] | 652 | &rx_dma->fbr1_min_des); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 653 | |
| 654 | #ifdef USE_FBR0 |
| 655 | /* Now's the best time to initialize FBR0 contents */ |
Alan Cox | 13a79c6 | 2010-01-18 15:32:50 +0000 | [diff] [blame] | 656 | fbr_entry = (struct fbr_desc *) rx_local->pFbr0RingVa; |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 657 | for (entry = 0; entry < rx_local->Fbr0NumEntries; entry++) { |
Alan Cox | 8a66278 | 2010-01-18 15:33:56 +0000 | [diff] [blame] | 658 | fbr_entry->addr_hi = rx_local->fbr[0]->bus_high[entry]; |
| 659 | fbr_entry->addr_lo = rx_local->fbr[0]->bus_low[entry]; |
Alan Cox | 7d9e15e | 2010-01-18 15:32:44 +0000 | [diff] [blame] | 660 | fbr_entry->word2 = entry; |
Alan Cox | 9fa8109 | 2009-08-27 11:00:36 +0100 | [diff] [blame] | 661 | fbr_entry++; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 662 | } |
| 663 | |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 664 | writel((u32) (rx_local->Fbr0Realpa >> 32), &rx_dma->fbr0_base_hi); |
| 665 | writel((u32) rx_local->Fbr0Realpa, &rx_dma->fbr0_base_lo); |
Alan Cox | 2e5e0b8 | 2009-11-18 14:07:48 +0000 | [diff] [blame] | 666 | writel(rx_local->Fbr0NumEntries - 1, &rx_dma->fbr0_num_des); |
Alan Cox | 356c74b | 2009-08-27 11:01:57 +0100 | [diff] [blame] | 667 | writel(ET_DMA10_WRAP, &rx_dma->fbr0_full_offset); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 668 | |
| 669 | /* This variable tracks the free buffer ring 0 full position, so it |
| 670 | * has to match the above. |
| 671 | */ |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 672 | rx_local->local_Fbr0_full = ET_DMA10_WRAP; |
| 673 | writel(((rx_local->Fbr0NumEntries * LO_MARK_PERCENT_FOR_RX) / 100) - 1, |
Alan Cox | 2e5e0b8 | 2009-11-18 14:07:48 +0000 | [diff] [blame] | 674 | &rx_dma->fbr0_min_des); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 675 | #endif |
| 676 | |
| 677 | /* Program the number of packets we will receive before generating an |
| 678 | * interrupt. |
| 679 | * For version B silicon, this value gets updated once autoneg is |
| 680 | *complete. |
| 681 | */ |
Alan Cox | 2e5e0b8 | 2009-11-18 14:07:48 +0000 | [diff] [blame] | 682 | writel(PARM_RX_NUM_BUFS_DEF, &rx_dma->num_pkt_done); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 683 | |
| 684 | /* The "time_done" is not working correctly to coalesce interrupts |
| 685 | * after a given time period, but rather is giving us an interrupt |
| 686 | * regardless of whether we have received packets. |
| 687 | * This value gets updated once autoneg is complete. |
| 688 | */ |
Alan Cox | 6794712 | 2009-11-18 14:07:41 +0000 | [diff] [blame] | 689 | writel(PARM_RX_TIME_INT_DEF, &rx_dma->max_pkt_time); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 690 | |
Alan Cox | 3762860 | 2009-08-19 18:21:50 +0100 | [diff] [blame] | 691 | spin_unlock_irqrestore(&etdev->RcvLock, flags); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | /** |
| 695 | * SetRxDmaTimer - Set the heartbeat timer according to line rate. |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 696 | * @etdev: pointer to our adapter structure |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 697 | */ |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 698 | void SetRxDmaTimer(struct et131x_adapter *etdev) |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 699 | { |
| 700 | /* For version B silicon, we do not use the RxDMA timer for 10 and 100 |
| 701 | * Mbits/s line rates. We do not enable and RxDMA interrupt coalescing. |
| 702 | */ |
Alan Cox | 9fa8109 | 2009-08-27 11:00:36 +0100 | [diff] [blame] | 703 | if ((etdev->linkspeed == TRUEPHY_SPEED_100MBPS) || |
| 704 | (etdev->linkspeed == TRUEPHY_SPEED_10MBPS)) { |
Alan Cox | 6794712 | 2009-11-18 14:07:41 +0000 | [diff] [blame] | 705 | writel(0, &etdev->regs->rxdma.max_pkt_time); |
Alan Cox | 2e5e0b8 | 2009-11-18 14:07:48 +0000 | [diff] [blame] | 706 | writel(1, &etdev->regs->rxdma.num_pkt_done); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 707 | } |
| 708 | } |
| 709 | |
| 710 | /** |
| 711 | * et131x_rx_dma_disable - Stop of Rx_DMA on the ET1310 |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 712 | * @etdev: pointer to our adapter structure |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 713 | */ |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 714 | void et131x_rx_dma_disable(struct et131x_adapter *etdev) |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 715 | { |
Michael Sprecher | f3fd4cd | 2010-03-10 13:15:35 +0100 | [diff] [blame] | 716 | u32 csr; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 717 | /* Setup the receive dma configuration register */ |
Alan Cox | 1bd751c | 2010-01-18 15:32:55 +0000 | [diff] [blame] | 718 | writel(0x00002001, &etdev->regs->rxdma.csr); |
| 719 | csr = readl(&etdev->regs->rxdma.csr); |
| 720 | if ((csr & 0x00020000) != 1) { /* Check halt status (bit 17) */ |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 721 | udelay(5); |
Alan Cox | 1bd751c | 2010-01-18 15:32:55 +0000 | [diff] [blame] | 722 | csr = readl(&etdev->regs->rxdma.csr); |
| 723 | if ((csr & 0x00020000) != 1) |
Alan Cox | 1570003 | 2009-08-27 11:03:09 +0100 | [diff] [blame] | 724 | dev_err(&etdev->pdev->dev, |
Alan Cox | 1bd751c | 2010-01-18 15:32:55 +0000 | [diff] [blame] | 725 | "RX Dma failed to enter halt state. CSR 0x%08x\n", |
| 726 | csr); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 727 | } |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 728 | } |
| 729 | |
| 730 | /** |
| 731 | * et131x_rx_dma_enable - re-start of Rx_DMA on the ET1310. |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 732 | * @etdev: pointer to our adapter structure |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 733 | */ |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 734 | void et131x_rx_dma_enable(struct et131x_adapter *etdev) |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 735 | { |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 736 | /* Setup the receive dma configuration register for normal operation */ |
Alan Cox | 1bd751c | 2010-01-18 15:32:55 +0000 | [diff] [blame] | 737 | u32 csr = 0x2000; /* FBR1 enable */ |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 738 | |
Alan Cox | 8f12785 | 2010-01-18 15:34:07 +0000 | [diff] [blame] | 739 | if (etdev->rx_ring.Fbr1BufferSize == 4096) |
Alan Cox | 1bd751c | 2010-01-18 15:32:55 +0000 | [diff] [blame] | 740 | csr |= 0x0800; |
Alan Cox | 8f12785 | 2010-01-18 15:34:07 +0000 | [diff] [blame] | 741 | else if (etdev->rx_ring.Fbr1BufferSize == 8192) |
Alan Cox | 1bd751c | 2010-01-18 15:32:55 +0000 | [diff] [blame] | 742 | csr |= 0x1000; |
Alan Cox | 8f12785 | 2010-01-18 15:34:07 +0000 | [diff] [blame] | 743 | else if (etdev->rx_ring.Fbr1BufferSize == 16384) |
Alan Cox | 1bd751c | 2010-01-18 15:32:55 +0000 | [diff] [blame] | 744 | csr |= 0x1800; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 745 | #ifdef USE_FBR0 |
Michael Sprecher | f3fd4cd | 2010-03-10 13:15:35 +0100 | [diff] [blame] | 746 | csr |= 0x0400; /* FBR0 enable */ |
Alan Cox | 8f12785 | 2010-01-18 15:34:07 +0000 | [diff] [blame] | 747 | if (etdev->rx_ring.Fbr0BufferSize == 256) |
Michael Sprecher | f3fd4cd | 2010-03-10 13:15:35 +0100 | [diff] [blame] | 748 | csr |= 0x0100; |
Alan Cox | 8f12785 | 2010-01-18 15:34:07 +0000 | [diff] [blame] | 749 | else if (etdev->rx_ring.Fbr0BufferSize == 512) |
Alan Cox | 1bd751c | 2010-01-18 15:32:55 +0000 | [diff] [blame] | 750 | csr |= 0x0200; |
Alan Cox | 8f12785 | 2010-01-18 15:34:07 +0000 | [diff] [blame] | 751 | else if (etdev->rx_ring.Fbr0BufferSize == 1024) |
Alan Cox | 1bd751c | 2010-01-18 15:32:55 +0000 | [diff] [blame] | 752 | csr |= 0x0300; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 753 | #endif |
Alan Cox | 1bd751c | 2010-01-18 15:32:55 +0000 | [diff] [blame] | 754 | writel(csr, &etdev->regs->rxdma.csr); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 755 | |
Alan Cox | 1bd751c | 2010-01-18 15:32:55 +0000 | [diff] [blame] | 756 | csr = readl(&etdev->regs->rxdma.csr); |
| 757 | if ((csr & 0x00020000) != 0) { |
Alan Cox | 5f1377d | 2009-10-06 15:47:55 +0100 | [diff] [blame] | 758 | udelay(5); |
Alan Cox | 1bd751c | 2010-01-18 15:32:55 +0000 | [diff] [blame] | 759 | csr = readl(&etdev->regs->rxdma.csr); |
Michael Sprecher | f3fd4cd | 2010-03-10 13:15:35 +0100 | [diff] [blame] | 760 | if ((csr & 0x00020000) != 0) { |
Alan Cox | 5f1377d | 2009-10-06 15:47:55 +0100 | [diff] [blame] | 761 | dev_err(&etdev->pdev->dev, |
| 762 | "RX Dma failed to exit halt state. CSR 0x%08x\n", |
Alan Cox | 1bd751c | 2010-01-18 15:32:55 +0000 | [diff] [blame] | 763 | csr); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 764 | } |
| 765 | } |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 766 | } |
| 767 | |
| 768 | /** |
| 769 | * nic_rx_pkts - Checks the hardware for available packets |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 770 | * @etdev: pointer to our adapter |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 771 | * |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 772 | * Returns rfd, a pointer to our MPRFD. |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 773 | * |
| 774 | * Checks the hardware for available packets, using completion ring |
| 775 | * If packets are available, it gets an RFD from the RecvList, attaches |
| 776 | * the packet to it, puts the RFD in the RecvPendList, and also returns |
| 777 | * the pointer to the RFD. |
| 778 | */ |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 779 | PMP_RFD nic_rx_pkts(struct et131x_adapter *etdev) |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 780 | { |
Alan Cox | 8f12785 | 2010-01-18 15:34:07 +0000 | [diff] [blame] | 781 | struct rx_ring *rx_local = &etdev->rx_ring; |
Alan Cox | f926d21 | 2010-01-18 15:33:45 +0000 | [diff] [blame] | 782 | struct rx_status_block *status; |
Alan Cox | 4ba64c1 | 2010-01-18 15:34:02 +0000 | [diff] [blame] | 783 | struct pkt_stat_desc *psr; |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 784 | PMP_RFD rfd; |
| 785 | u32 i; |
Alan Cox | 4ba64c1 | 2010-01-18 15:34:02 +0000 | [diff] [blame] | 786 | u8 *buf; |
Alan Cox | 3762860 | 2009-08-19 18:21:50 +0100 | [diff] [blame] | 787 | unsigned long flags; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 788 | struct list_head *element; |
Alan Cox | 4ba64c1 | 2010-01-18 15:34:02 +0000 | [diff] [blame] | 789 | u8 rindex; |
| 790 | u16 bindex; |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 791 | u32 len; |
Alan Cox | 4ba64c1 | 2010-01-18 15:34:02 +0000 | [diff] [blame] | 792 | u32 word0; |
Alan Cox | 61aa21f | 2010-01-18 15:33:34 +0000 | [diff] [blame] | 793 | u32 word1; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 794 | |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 795 | /* RX Status block is written by the DMA engine prior to every |
| 796 | * interrupt. It contains the next to be used entry in the Packet |
| 797 | * Status Ring, and also the two Free Buffer rings. |
| 798 | */ |
Alan Cox | 07563ac | 2010-01-18 15:33:51 +0000 | [diff] [blame] | 799 | status = rx_local->rx_status_block; |
Alan Cox | 61aa21f | 2010-01-18 15:33:34 +0000 | [diff] [blame] | 800 | word1 = status->Word1 >> 16; /* Get the useful bits */ |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 801 | |
Alan Cox | 61aa21f | 2010-01-18 15:33:34 +0000 | [diff] [blame] | 802 | /* Check the PSR and wrap bits do not match */ |
| 803 | if ((word1 & 0x1FFF) == (rx_local->local_psr_full & 0x1FFF)) |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 804 | /* Looks like this ring is not updated yet */ |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 805 | return NULL; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 806 | |
| 807 | /* The packet status ring indicates that data is available. */ |
Alan Cox | 4ba64c1 | 2010-01-18 15:34:02 +0000 | [diff] [blame] | 808 | psr = (struct pkt_stat_desc *) (rx_local->pPSRingVa) + |
Alan Cox | 99fd99f | 2009-11-18 14:07:58 +0000 | [diff] [blame] | 809 | (rx_local->local_psr_full & 0xFFF); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 810 | |
| 811 | /* Grab any information that is required once the PSR is |
| 812 | * advanced, since we can no longer rely on the memory being |
| 813 | * accurate |
| 814 | */ |
Alan Cox | 4ba64c1 | 2010-01-18 15:34:02 +0000 | [diff] [blame] | 815 | len = psr->word1 & 0xFFFF; |
| 816 | rindex = (psr->word1 >> 26) & 0x03; |
| 817 | bindex = (psr->word1 >> 16) & 0x3FF; |
| 818 | word0 = psr->word0; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 819 | |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 820 | /* Indicate that we have used this PSR entry. */ |
Alan Cox | 99fd99f | 2009-11-18 14:07:58 +0000 | [diff] [blame] | 821 | /* FIXME wrap 12 */ |
Alan Cox | d31a2ff | 2010-01-06 14:01:26 +0000 | [diff] [blame] | 822 | add_12bit(&rx_local->local_psr_full, 1); |
| 823 | if ((rx_local->local_psr_full & 0xFFF) > rx_local->PsrNumEntries - 1) { |
Alan Cox | 99fd99f | 2009-11-18 14:07:58 +0000 | [diff] [blame] | 824 | /* Clear psr full and toggle the wrap bit */ |
Alan Cox | d31a2ff | 2010-01-06 14:01:26 +0000 | [diff] [blame] | 825 | rx_local->local_psr_full &= ~0xFFF; |
Alan Cox | 99fd99f | 2009-11-18 14:07:58 +0000 | [diff] [blame] | 826 | rx_local->local_psr_full ^= 0x1000; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 827 | } |
| 828 | |
Alan Cox | 99fd99f | 2009-11-18 14:07:58 +0000 | [diff] [blame] | 829 | writel(rx_local->local_psr_full, |
| 830 | &etdev->regs->rxdma.psr_full_offset); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 831 | |
| 832 | #ifndef USE_FBR0 |
Alan Cox | 4ba64c1 | 2010-01-18 15:34:02 +0000 | [diff] [blame] | 833 | if (rindex != 1) |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 834 | return NULL; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 835 | #endif |
| 836 | |
| 837 | #ifdef USE_FBR0 |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 838 | if (rindex > 1 || |
| 839 | (rindex == 0 && |
| 840 | bindex > rx_local->Fbr0NumEntries - 1) || |
| 841 | (rindex == 1 && |
| 842 | bindex > rx_local->Fbr1NumEntries - 1)) |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 843 | #else |
Michael Sprecher | f3fd4cd | 2010-03-10 13:15:35 +0100 | [diff] [blame] | 844 | if (rindex != 1 || bindex > rx_local->Fbr1NumEntries - 1) |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 845 | #endif |
| 846 | { |
| 847 | /* Illegal buffer or ring index cannot be used by S/W*/ |
Alan Cox | 1570003 | 2009-08-27 11:03:09 +0100 | [diff] [blame] | 848 | dev_err(&etdev->pdev->dev, |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 849 | "NICRxPkts PSR Entry %d indicates " |
| 850 | "length of %d and/or bad bi(%d)\n", |
Alan Cox | 99fd99f | 2009-11-18 14:07:58 +0000 | [diff] [blame] | 851 | rx_local->local_psr_full & 0xFFF, |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 852 | len, bindex); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 853 | return NULL; |
| 854 | } |
| 855 | |
| 856 | /* Get and fill the RFD. */ |
Alan Cox | 3762860 | 2009-08-19 18:21:50 +0100 | [diff] [blame] | 857 | spin_lock_irqsave(&etdev->RcvLock, flags); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 858 | |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 859 | rfd = NULL; |
| 860 | element = rx_local->RecvList.next; |
| 861 | rfd = (PMP_RFD) list_entry(element, MP_RFD, list_node); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 862 | |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 863 | if (rfd == NULL) { |
Alan Cox | 3762860 | 2009-08-19 18:21:50 +0100 | [diff] [blame] | 864 | spin_unlock_irqrestore(&etdev->RcvLock, flags); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 865 | return NULL; |
| 866 | } |
| 867 | |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 868 | list_del(&rfd->list_node); |
| 869 | rx_local->nReadyRecv--; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 870 | |
Alan Cox | 3762860 | 2009-08-19 18:21:50 +0100 | [diff] [blame] | 871 | spin_unlock_irqrestore(&etdev->RcvLock, flags); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 872 | |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 873 | rfd->bufferindex = bindex; |
| 874 | rfd->ringindex = rindex; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 875 | |
| 876 | /* In V1 silicon, there is a bug which screws up filtering of |
| 877 | * runt packets. Therefore runt packet filtering is disabled |
| 878 | * in the MAC and the packets are dropped here. They are |
| 879 | * also counted here. |
| 880 | */ |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 881 | if (len < (NIC_MIN_PACKET_SIZE + 4)) { |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 882 | etdev->Stats.other_errors++; |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 883 | len = 0; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 884 | } |
| 885 | |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 886 | if (len) { |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 887 | if (etdev->ReplicaPhyLoopbk == 1) { |
Alan Cox | 8a66278 | 2010-01-18 15:33:56 +0000 | [diff] [blame] | 888 | buf = rx_local->fbr[rindex]->virt[bindex]; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 889 | |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 890 | if (memcmp(&buf[6], &etdev->CurrentAddress[0], |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 891 | ETH_ALEN) == 0) { |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 892 | if (memcmp(&buf[42], "Replica packet", |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 893 | ETH_HLEN)) { |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 894 | etdev->ReplicaPhyLoopbkPF = 1; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 895 | } |
| 896 | } |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 897 | } |
| 898 | |
| 899 | /* Determine if this is a multicast packet coming in */ |
Alan Cox | 4ba64c1 | 2010-01-18 15:34:02 +0000 | [diff] [blame] | 900 | if ((word0 & ALCATEL_MULTICAST_PKT) && |
| 901 | !(word0 & ALCATEL_BROADCAST_PKT)) { |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 902 | /* Promiscuous mode and Multicast mode are |
| 903 | * not mutually exclusive as was first |
| 904 | * thought. I guess Promiscuous is just |
| 905 | * considered a super-set of the other |
| 906 | * filters. Generally filter is 0x2b when in |
| 907 | * promiscuous mode. |
| 908 | */ |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 909 | if ((etdev->PacketFilter & ET131X_PACKET_TYPE_MULTICAST) |
| 910 | && !(etdev->PacketFilter & ET131X_PACKET_TYPE_PROMISCUOUS) |
| 911 | && !(etdev->PacketFilter & ET131X_PACKET_TYPE_ALL_MULTICAST)) { |
Alan Cox | 8a66278 | 2010-01-18 15:33:56 +0000 | [diff] [blame] | 912 | buf = rx_local->fbr[rindex]-> |
| 913 | virt[bindex]; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 914 | |
| 915 | /* Loop through our list to see if the |
| 916 | * destination address of this packet |
| 917 | * matches one in our list. |
| 918 | */ |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 919 | for (i = 0; |
| 920 | i < etdev->MCAddressCount; |
| 921 | i++) { |
| 922 | if (buf[0] == |
| 923 | etdev->MCList[i][0] |
| 924 | && buf[1] == |
| 925 | etdev->MCList[i][1] |
| 926 | && buf[2] == |
| 927 | etdev->MCList[i][2] |
| 928 | && buf[3] == |
| 929 | etdev->MCList[i][3] |
| 930 | && buf[4] == |
| 931 | etdev->MCList[i][4] |
| 932 | && buf[5] == |
| 933 | etdev->MCList[i][5]) { |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 934 | break; |
| 935 | } |
| 936 | } |
| 937 | |
| 938 | /* If our index is equal to the number |
| 939 | * of Multicast address we have, then |
| 940 | * this means we did not find this |
| 941 | * packet's matching address in our |
| 942 | * list. Set the PacketSize to zero, |
| 943 | * so we free our RFD when we return |
| 944 | * from this function. |
| 945 | */ |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 946 | if (i == etdev->MCAddressCount) |
| 947 | len = 0; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 948 | } |
| 949 | |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 950 | if (len > 0) |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 951 | etdev->Stats.multircv++; |
Alan Cox | 4ba64c1 | 2010-01-18 15:34:02 +0000 | [diff] [blame] | 952 | } else if (word0 & ALCATEL_BROADCAST_PKT) |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 953 | etdev->Stats.brdcstrcv++; |
Alan Cox | 64f9303 | 2009-06-10 17:30:41 +0100 | [diff] [blame] | 954 | else |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 955 | /* Not sure what this counter measures in |
| 956 | * promiscuous mode. Perhaps we should check |
| 957 | * the MAC address to see if it is directed |
| 958 | * to us in promiscuous mode. |
| 959 | */ |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 960 | etdev->Stats.unircv++; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 961 | } |
| 962 | |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 963 | if (len > 0) { |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 964 | struct sk_buff *skb = NULL; |
| 965 | |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 966 | /* rfd->PacketSize = len - 4; */ |
| 967 | rfd->PacketSize = len; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 968 | |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 969 | skb = dev_alloc_skb(rfd->PacketSize + 2); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 970 | if (!skb) { |
Alan Cox | 1570003 | 2009-08-27 11:03:09 +0100 | [diff] [blame] | 971 | dev_err(&etdev->pdev->dev, |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 972 | "Couldn't alloc an SKB for Rx\n"); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 973 | return NULL; |
| 974 | } |
| 975 | |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 976 | etdev->net_stats.rx_bytes += rfd->PacketSize; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 977 | |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 978 | memcpy(skb_put(skb, rfd->PacketSize), |
Alan Cox | 8a66278 | 2010-01-18 15:33:56 +0000 | [diff] [blame] | 979 | rx_local->fbr[rindex]->virt[bindex], |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 980 | rfd->PacketSize); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 981 | |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 982 | skb->dev = etdev->netdev; |
| 983 | skb->protocol = eth_type_trans(skb, etdev->netdev); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 984 | skb->ip_summed = CHECKSUM_NONE; |
| 985 | |
| 986 | netif_rx(skb); |
| 987 | } else { |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 988 | rfd->PacketSize = 0; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 989 | } |
| 990 | |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 991 | nic_return_rfd(etdev, rfd); |
| 992 | return rfd; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 993 | } |
| 994 | |
| 995 | /** |
| 996 | * et131x_reset_recv - Reset the receive list |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 997 | * @etdev: pointer to our adapter |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 998 | * |
| 999 | * Assumption, Rcv spinlock has been acquired. |
| 1000 | */ |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 1001 | void et131x_reset_recv(struct et131x_adapter *etdev) |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 1002 | { |
Alan Cox | 8f12785 | 2010-01-18 15:34:07 +0000 | [diff] [blame] | 1003 | WARN_ON(list_empty(&etdev->rx_ring.RecvList)); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 1004 | |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 1005 | } |
| 1006 | |
| 1007 | /** |
| 1008 | * et131x_handle_recv_interrupt - Interrupt handler for receive processing |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 1009 | * @etdev: pointer to our adapter |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 1010 | * |
| 1011 | * Assumption, Rcv spinlock has been acquired. |
| 1012 | */ |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 1013 | void et131x_handle_recv_interrupt(struct et131x_adapter *etdev) |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 1014 | { |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 1015 | PMP_RFD rfd = NULL; |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 1016 | u32 count = 0; |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 1017 | bool done = true; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 1018 | |
| 1019 | /* Process up to available RFD's */ |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 1020 | while (count < NUM_PACKETS_HANDLED) { |
Alan Cox | 8f12785 | 2010-01-18 15:34:07 +0000 | [diff] [blame] | 1021 | if (list_empty(&etdev->rx_ring.RecvList)) { |
| 1022 | WARN_ON(etdev->rx_ring.nReadyRecv != 0); |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 1023 | done = false; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 1024 | break; |
| 1025 | } |
| 1026 | |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 1027 | rfd = nic_rx_pkts(etdev); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 1028 | |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 1029 | if (rfd == NULL) |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 1030 | break; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 1031 | |
| 1032 | /* Do not receive any packets until a filter has been set. |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 1033 | * Do not receive any packets until we have link. |
| 1034 | * If length is zero, return the RFD in order to advance the |
| 1035 | * Free buffer ring. |
| 1036 | */ |
Alan Cox | f6b35d6 | 2009-08-27 11:02:05 +0100 | [diff] [blame] | 1037 | if (!etdev->PacketFilter || |
| 1038 | !(etdev->Flags & fMP_ADAPTER_LINK_DETECTION) || |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 1039 | rfd->PacketSize == 0) { |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 1040 | continue; |
| 1041 | } |
| 1042 | |
| 1043 | /* Increment the number of packets we received */ |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 1044 | etdev->Stats.ipackets++; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 1045 | |
| 1046 | /* Set the status on the packet, either resources or success */ |
Alan Cox | 8f12785 | 2010-01-18 15:34:07 +0000 | [diff] [blame] | 1047 | if (etdev->rx_ring.nReadyRecv < RFD_LOW_WATER_MARK) { |
Alan Cox | 1570003 | 2009-08-27 11:03:09 +0100 | [diff] [blame] | 1048 | dev_warn(&etdev->pdev->dev, |
| 1049 | "RFD's are running out\n"); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 1050 | } |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 1051 | count++; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 1052 | } |
| 1053 | |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 1054 | if (count == NUM_PACKETS_HANDLED || !done) { |
Alan Cox | 8f12785 | 2010-01-18 15:34:07 +0000 | [diff] [blame] | 1055 | etdev->rx_ring.UnfinishedReceives = true; |
Alan Cox | c255717 | 2009-08-27 10:59:56 +0100 | [diff] [blame] | 1056 | writel(PARM_TX_TIME_INT_DEF * NANO_IN_A_MICRO, |
Alan Cox | f3f415a | 2009-08-27 10:59:30 +0100 | [diff] [blame] | 1057 | &etdev->regs->global.watchdog_timer); |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 1058 | } else |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 1059 | /* Watchdog timer will disable itself if appropriate. */ |
Alan Cox | 8f12785 | 2010-01-18 15:34:07 +0000 | [diff] [blame] | 1060 | etdev->rx_ring.UnfinishedReceives = false; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 1061 | } |
| 1062 | |
Alan Cox | 356c74b | 2009-08-27 11:01:57 +0100 | [diff] [blame] | 1063 | static inline u32 bump_fbr(u32 *fbr, u32 limit) |
| 1064 | { |
Michael Sprecher | f3fd4cd | 2010-03-10 13:15:35 +0100 | [diff] [blame] | 1065 | u32 v = *fbr; |
| 1066 | v++; |
| 1067 | /* This works for all cases where limit < 1024. The 1023 case |
| 1068 | works because 1023++ is 1024 which means the if condition is not |
| 1069 | taken but the carry of the bit into the wrap bit toggles the wrap |
| 1070 | value correctly */ |
| 1071 | if ((v & ET_DMA10_MASK) > limit) { |
| 1072 | v &= ~ET_DMA10_MASK; |
| 1073 | v ^= ET_DMA10_WRAP; |
| 1074 | } |
| 1075 | /* For the 1023 case */ |
| 1076 | v &= (ET_DMA10_MASK|ET_DMA10_WRAP); |
| 1077 | *fbr = v; |
| 1078 | return v; |
Alan Cox | 356c74b | 2009-08-27 11:01:57 +0100 | [diff] [blame] | 1079 | } |
| 1080 | |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 1081 | /** |
| 1082 | * NICReturnRFD - Recycle a RFD and put it back onto the receive list |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 1083 | * @etdev: pointer to our adapter |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 1084 | * @rfd: pointer to the RFD |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 1085 | */ |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 1086 | void nic_return_rfd(struct et131x_adapter *etdev, PMP_RFD rfd) |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 1087 | { |
Alan Cox | 8f12785 | 2010-01-18 15:34:07 +0000 | [diff] [blame] | 1088 | struct rx_ring *rx_local = &etdev->rx_ring; |
Alan Cox | 61d5ed8 | 2010-01-18 15:33:01 +0000 | [diff] [blame] | 1089 | struct rxdma_regs __iomem *rx_dma = &etdev->regs->rxdma; |
Alan Cox | 4ba64c1 | 2010-01-18 15:34:02 +0000 | [diff] [blame] | 1090 | u16 bi = rfd->bufferindex; |
| 1091 | u8 ri = rfd->ringindex; |
Alan Cox | 3762860 | 2009-08-19 18:21:50 +0100 | [diff] [blame] | 1092 | unsigned long flags; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 1093 | |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 1094 | /* We don't use any of the OOB data besides status. Otherwise, we |
| 1095 | * need to clean up OOB data |
| 1096 | */ |
| 1097 | if ( |
| 1098 | #ifdef USE_FBR0 |
Alan Cox | 9fa8109 | 2009-08-27 11:00:36 +0100 | [diff] [blame] | 1099 | (ri == 0 && bi < rx_local->Fbr0NumEntries) || |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 1100 | #endif |
Alan Cox | 9fa8109 | 2009-08-27 11:00:36 +0100 | [diff] [blame] | 1101 | (ri == 1 && bi < rx_local->Fbr1NumEntries)) { |
Alan Cox | 3762860 | 2009-08-19 18:21:50 +0100 | [diff] [blame] | 1102 | spin_lock_irqsave(&etdev->FbrLock, flags); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 1103 | |
| 1104 | if (ri == 1) { |
Alan Cox | 13a79c6 | 2010-01-18 15:32:50 +0000 | [diff] [blame] | 1105 | struct fbr_desc *next = |
| 1106 | (struct fbr_desc *) (rx_local->pFbr1RingVa) + |
Michael Sprecher | f3fd4cd | 2010-03-10 13:15:35 +0100 | [diff] [blame] | 1107 | INDEX10(rx_local->local_Fbr1_full); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 1108 | |
| 1109 | /* Handle the Free Buffer Ring advancement here. Write |
| 1110 | * the PA / Buffer Index for the returned buffer into |
| 1111 | * the oldest (next to be freed)FBR entry |
| 1112 | */ |
Alan Cox | 8a66278 | 2010-01-18 15:33:56 +0000 | [diff] [blame] | 1113 | next->addr_hi = rx_local->fbr[1]->bus_high[bi]; |
| 1114 | next->addr_lo = rx_local->fbr[1]->bus_low[bi]; |
Alan Cox | 7d9e15e | 2010-01-18 15:32:44 +0000 | [diff] [blame] | 1115 | next->word2 = bi; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 1116 | |
Alan Cox | 356c74b | 2009-08-27 11:01:57 +0100 | [diff] [blame] | 1117 | writel(bump_fbr(&rx_local->local_Fbr1_full, |
| 1118 | rx_local->Fbr1NumEntries - 1), |
| 1119 | &rx_dma->fbr1_full_offset); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 1120 | } |
| 1121 | #ifdef USE_FBR0 |
| 1122 | else { |
Alan Cox | 13a79c6 | 2010-01-18 15:32:50 +0000 | [diff] [blame] | 1123 | struct fbr_desc *next = (struct fbr_desc *) |
| 1124 | rx_local->pFbr0RingVa + |
| 1125 | INDEX10(rx_local->local_Fbr0_full); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 1126 | |
| 1127 | /* Handle the Free Buffer Ring advancement here. Write |
| 1128 | * the PA / Buffer Index for the returned buffer into |
| 1129 | * the oldest (next to be freed) FBR entry |
| 1130 | */ |
Alan Cox | 8a66278 | 2010-01-18 15:33:56 +0000 | [diff] [blame] | 1131 | next->addr_hi = rx_local->fbr[0]->bus_high[bi]; |
| 1132 | next->addr_lo = rx_local->fbr[0]->bus_low[bi]; |
Alan Cox | 7d9e15e | 2010-01-18 15:32:44 +0000 | [diff] [blame] | 1133 | next->word2 = bi; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 1134 | |
Alan Cox | 356c74b | 2009-08-27 11:01:57 +0100 | [diff] [blame] | 1135 | writel(bump_fbr(&rx_local->local_Fbr0_full, |
| 1136 | rx_local->Fbr0NumEntries - 1), |
| 1137 | &rx_dma->fbr0_full_offset); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 1138 | } |
| 1139 | #endif |
Alan Cox | 3762860 | 2009-08-19 18:21:50 +0100 | [diff] [blame] | 1140 | spin_unlock_irqrestore(&etdev->FbrLock, flags); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 1141 | } else { |
Alan Cox | 1570003 | 2009-08-27 11:03:09 +0100 | [diff] [blame] | 1142 | dev_err(&etdev->pdev->dev, |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 1143 | "NICReturnRFD illegal Buffer Index returned\n"); |
| 1144 | } |
| 1145 | |
| 1146 | /* The processing on this RFD is done, so put it back on the tail of |
| 1147 | * our list |
| 1148 | */ |
Alan Cox | 3762860 | 2009-08-19 18:21:50 +0100 | [diff] [blame] | 1149 | spin_lock_irqsave(&etdev->RcvLock, flags); |
Alan Cox | 4fbdf81 | 2009-10-06 15:48:57 +0100 | [diff] [blame] | 1150 | list_add_tail(&rfd->list_node, &rx_local->RecvList); |
Alan Cox | 9fa8109 | 2009-08-27 11:00:36 +0100 | [diff] [blame] | 1151 | rx_local->nReadyRecv++; |
Alan Cox | 3762860 | 2009-08-19 18:21:50 +0100 | [diff] [blame] | 1152 | spin_unlock_irqrestore(&etdev->RcvLock, flags); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 1153 | |
Alan Cox | 1570003 | 2009-08-27 11:03:09 +0100 | [diff] [blame] | 1154 | WARN_ON(rx_local->nReadyRecv > rx_local->NumRfd); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 1155 | } |