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_tx.c - Routines used to perform data transmission. |
| 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_tx.h" |
Alan Cox | 69ea5fc | 2010-01-18 15:34:24 +0000 | [diff] [blame] | 89 | #include "et131x.h" |
Alan Cox | c255717 | 2009-08-27 10:59:56 +0100 | [diff] [blame] | 90 | |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 91 | static inline void et131x_free_send_packet(struct et131x_adapter *etdev, |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 92 | struct tcb *tcb); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 93 | static int et131x_send_packet(struct sk_buff *skb, |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 94 | struct et131x_adapter *etdev); |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 95 | static int nic_send_packet(struct et131x_adapter *etdev, struct tcb *tcb); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 96 | |
| 97 | /** |
| 98 | * et131x_tx_dma_memory_alloc |
| 99 | * @adapter: pointer to our private adapter structure |
| 100 | * |
| 101 | * Returns 0 on success and errno on failure (as defined in errno.h). |
| 102 | * |
| 103 | * Allocates memory that will be visible both to the device and to the CPU. |
| 104 | * The OS will pass us packets, pointers to which we will insert in the Tx |
| 105 | * Descriptor queue. The device will read this queue to find the packets in |
| 106 | * memory. The device will update the "status" in memory each time it xmits a |
| 107 | * packet. |
| 108 | */ |
| 109 | int et131x_tx_dma_memory_alloc(struct et131x_adapter *adapter) |
| 110 | { |
| 111 | int desc_size = 0; |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 112 | struct tx_ring *tx_ring = &adapter->tx_ring; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 113 | |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 114 | /* Allocate memory for the TCB's (Transmit Control Block) */ |
Julia Lawall | 3241487 | 2010-05-11 20:26:57 +0200 | [diff] [blame] | 115 | adapter->tx_ring.tcb_ring = |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 116 | kcalloc(NUM_TCB, sizeof(struct tcb), GFP_ATOMIC | GFP_DMA); |
Alan Cox | c78732a | 2009-10-06 15:49:45 +0100 | [diff] [blame] | 117 | if (!adapter->tx_ring.tcb_ring) { |
Alan Cox | 1570003 | 2009-08-27 11:03:09 +0100 | [diff] [blame] | 118 | dev_err(&adapter->pdev->dev, "Cannot alloc memory for TCBs\n"); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 119 | return -ENOMEM; |
| 120 | } |
| 121 | |
| 122 | /* Allocate enough memory for the Tx descriptor ring, and allocate |
| 123 | * some extra so that the ring can be aligned on a 4k boundary. |
| 124 | */ |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 125 | desc_size = (sizeof(struct tx_desc) * NUM_DESC_PER_RING_TX) + 4096 - 1; |
| 126 | tx_ring->tx_desc_ring = |
| 127 | (struct tx_desc *) pci_alloc_consistent(adapter->pdev, desc_size, |
| 128 | &tx_ring->tx_desc_ring_pa); |
| 129 | if (!adapter->tx_ring.tx_desc_ring) { |
Alan Cox | 1458d82 | 2009-10-06 15:49:58 +0100 | [diff] [blame] | 130 | dev_err(&adapter->pdev->dev, |
| 131 | "Cannot alloc memory for Tx Ring\n"); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 132 | return -ENOMEM; |
| 133 | } |
| 134 | |
| 135 | /* Save physical address |
| 136 | * |
| 137 | * NOTE: pci_alloc_consistent(), used above to alloc DMA regions, |
| 138 | * ALWAYS returns SAC (32-bit) addresses. If DAC (64-bit) addresses |
| 139 | * are ever returned, make sure the high part is retrieved here before |
| 140 | * storing the adjusted address. |
| 141 | */ |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 142 | /* Allocate memory for the Tx status block */ |
Alan Cox | c78732a | 2009-10-06 15:49:45 +0100 | [diff] [blame] | 143 | tx_ring->tx_status = pci_alloc_consistent(adapter->pdev, |
| 144 | sizeof(u32), |
| 145 | &tx_ring->tx_status_pa); |
| 146 | if (!adapter->tx_ring.tx_status_pa) { |
Alan Cox | 1570003 | 2009-08-27 11:03:09 +0100 | [diff] [blame] | 147 | dev_err(&adapter->pdev->dev, |
| 148 | "Cannot alloc memory for Tx status block\n"); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 149 | return -ENOMEM; |
| 150 | } |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 151 | return 0; |
| 152 | } |
| 153 | |
| 154 | /** |
| 155 | * et131x_tx_dma_memory_free - Free all memory allocated within this module |
| 156 | * @adapter: pointer to our private adapter structure |
| 157 | * |
| 158 | * Returns 0 on success and errno on failure (as defined in errno.h). |
| 159 | */ |
| 160 | void et131x_tx_dma_memory_free(struct et131x_adapter *adapter) |
| 161 | { |
| 162 | int desc_size = 0; |
| 163 | |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 164 | if (adapter->tx_ring.tx_desc_ring) { |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 165 | /* Free memory relating to Tx rings here */ |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 166 | desc_size = (sizeof(struct tx_desc) * NUM_DESC_PER_RING_TX) |
Alan Cox | 1458d82 | 2009-10-06 15:49:58 +0100 | [diff] [blame] | 167 | + 4096 - 1; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 168 | pci_free_consistent(adapter->pdev, |
| 169 | desc_size, |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 170 | adapter->tx_ring.tx_desc_ring, |
| 171 | adapter->tx_ring.tx_desc_ring_pa); |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 172 | adapter->tx_ring.tx_desc_ring = NULL; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | /* Free memory for the Tx status block */ |
Alan Cox | c78732a | 2009-10-06 15:49:45 +0100 | [diff] [blame] | 176 | if (adapter->tx_ring.tx_status) { |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 177 | pci_free_consistent(adapter->pdev, |
Alan Cox | c78732a | 2009-10-06 15:49:45 +0100 | [diff] [blame] | 178 | sizeof(u32), |
| 179 | adapter->tx_ring.tx_status, |
| 180 | adapter->tx_ring.tx_status_pa); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 181 | |
Alan Cox | c78732a | 2009-10-06 15:49:45 +0100 | [diff] [blame] | 182 | adapter->tx_ring.tx_status = NULL; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 183 | } |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 184 | /* Free the memory for the tcb structures */ |
Alan Cox | c78732a | 2009-10-06 15:49:45 +0100 | [diff] [blame] | 185 | kfree(adapter->tx_ring.tcb_ring); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | /** |
| 189 | * ConfigTxDmaRegs - Set up the tx dma section of the JAGCore. |
Alan Cox | 9fa8109 | 2009-08-27 11:00:36 +0100 | [diff] [blame] | 190 | * @etdev: pointer to our private adapter structure |
Alan Cox | 1458d82 | 2009-10-06 15:49:58 +0100 | [diff] [blame] | 191 | * |
| 192 | * Configure the transmit engine with the ring buffers we have created |
| 193 | * and prepare it for use. |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 194 | */ |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 195 | void ConfigTxDmaRegs(struct et131x_adapter *etdev) |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 196 | { |
Alan Cox | 060a78a | 2010-01-18 15:33:18 +0000 | [diff] [blame] | 197 | struct txdma_regs __iomem *txdma = &etdev->regs->txdma; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 198 | |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 199 | /* Load the hardware with the start of the transmit descriptor ring. */ |
Alan Cox | 9c60684b | 2009-10-06 15:48:49 +0100 | [diff] [blame] | 200 | writel((u32) ((u64)etdev->tx_ring.tx_desc_ring_pa >> 32), |
Alan Cox | 9fa8109 | 2009-08-27 11:00:36 +0100 | [diff] [blame] | 201 | &txdma->pr_base_hi); |
Alan Cox | 9c60684b | 2009-10-06 15:48:49 +0100 | [diff] [blame] | 202 | writel((u32) etdev->tx_ring.tx_desc_ring_pa, |
Alan Cox | 9fa8109 | 2009-08-27 11:00:36 +0100 | [diff] [blame] | 203 | &txdma->pr_base_lo); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 204 | |
| 205 | /* Initialise the transmit DMA engine */ |
Alan Cox | 42a03e9 | 2009-11-18 14:07:21 +0000 | [diff] [blame] | 206 | writel(NUM_DESC_PER_RING_TX - 1, &txdma->pr_num_des); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 207 | |
Alan Cox | c1996fc | 2009-10-06 15:49:29 +0100 | [diff] [blame] | 208 | /* Load the completion writeback physical address */ |
Alan Cox | c78732a | 2009-10-06 15:49:45 +0100 | [diff] [blame] | 209 | writel((u32)((u64)etdev->tx_ring.tx_status_pa >> 32), |
Alan Cox | c1996fc | 2009-10-06 15:49:29 +0100 | [diff] [blame] | 210 | &txdma->dma_wb_base_hi); |
Alan Cox | c78732a | 2009-10-06 15:49:45 +0100 | [diff] [blame] | 211 | writel((u32)etdev->tx_ring.tx_status_pa, &txdma->dma_wb_base_lo); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 212 | |
Alan Cox | c78732a | 2009-10-06 15:49:45 +0100 | [diff] [blame] | 213 | *etdev->tx_ring.tx_status = 0; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 214 | |
Alan Cox | 356c74b | 2009-08-27 11:01:57 +0100 | [diff] [blame] | 215 | writel(0, &txdma->service_request); |
Alan Cox | c78732a | 2009-10-06 15:49:45 +0100 | [diff] [blame] | 216 | etdev->tx_ring.send_idx = 0; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | /** |
| 220 | * et131x_tx_dma_disable - Stop of Tx_DMA on the ET1310 |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 221 | * @etdev: pointer to our adapter structure |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 222 | */ |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 223 | void et131x_tx_dma_disable(struct et131x_adapter *etdev) |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 224 | { |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 225 | /* Setup the tramsmit dma configuration register */ |
Alan Cox | bcb903f | 2009-08-27 11:03:38 +0100 | [diff] [blame] | 226 | writel(ET_TXDMA_CSR_HALT|ET_TXDMA_SNGL_EPKT, |
| 227 | &etdev->regs->txdma.csr); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | /** |
| 231 | * et131x_tx_dma_enable - re-start of Tx_DMA on the ET1310. |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 232 | * @etdev: pointer to our adapter structure |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 233 | * |
| 234 | * Mainly used after a return to the D0 (full-power) state from a lower state. |
| 235 | */ |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 236 | void et131x_tx_dma_enable(struct et131x_adapter *etdev) |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 237 | { |
Alan Cox | 5f1377d | 2009-10-06 15:47:55 +0100 | [diff] [blame] | 238 | /* Setup the transmit dma configuration register for normal |
| 239 | * operation |
| 240 | */ |
| 241 | writel(ET_TXDMA_SNGL_EPKT|(PARM_DMA_CACHE_DEF << ET_TXDMA_CACHE_SHIFT), |
| 242 | &etdev->regs->txdma.csr); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | /** |
| 246 | * et131x_init_send - Initialize send data structures |
| 247 | * @adapter: pointer to our private adapter structure |
| 248 | */ |
| 249 | void et131x_init_send(struct et131x_adapter *adapter) |
| 250 | { |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 251 | struct tcb *tcb; |
Alan Cox | c1996fc | 2009-10-06 15:49:29 +0100 | [diff] [blame] | 252 | u32 ct; |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 253 | struct tx_ring *tx_ring; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 254 | |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 255 | /* Setup some convenience pointers */ |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 256 | tx_ring = &adapter->tx_ring; |
Alan Cox | c78732a | 2009-10-06 15:49:45 +0100 | [diff] [blame] | 257 | tcb = adapter->tx_ring.tcb_ring; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 258 | |
Alan Cox | c78732a | 2009-10-06 15:49:45 +0100 | [diff] [blame] | 259 | tx_ring->tcb_qhead = tcb; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 260 | |
Alan Cox | 9251d71 | 2009-10-06 15:49:36 +0100 | [diff] [blame] | 261 | memset(tcb, 0, sizeof(struct tcb) * NUM_TCB); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 262 | |
Alan Cox | 9251d71 | 2009-10-06 15:49:36 +0100 | [diff] [blame] | 263 | /* Go through and set up each TCB */ |
Alan Cox | c78732a | 2009-10-06 15:49:45 +0100 | [diff] [blame] | 264 | for (ct = 0; ct++ < NUM_TCB; tcb++) |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 265 | /* Set the link pointer in HW TCB to the next TCB in the |
Alan Cox | 1458d82 | 2009-10-06 15:49:58 +0100 | [diff] [blame] | 266 | * chain |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 267 | */ |
Alan Cox | c78732a | 2009-10-06 15:49:45 +0100 | [diff] [blame] | 268 | tcb->next = tcb + 1; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 269 | |
Alan Cox | 1458d82 | 2009-10-06 15:49:58 +0100 | [diff] [blame] | 270 | /* Set the tail pointer */ |
Alan Cox | 9251d71 | 2009-10-06 15:49:36 +0100 | [diff] [blame] | 271 | tcb--; |
Alan Cox | c78732a | 2009-10-06 15:49:45 +0100 | [diff] [blame] | 272 | tx_ring->tcb_qtail = tcb; |
| 273 | tcb->next = NULL; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 274 | /* Curr send queue should now be empty */ |
Alan Cox | c78732a | 2009-10-06 15:49:45 +0100 | [diff] [blame] | 275 | tx_ring->send_head = NULL; |
| 276 | tx_ring->send_tail = NULL; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | /** |
| 280 | * et131x_send_packets - This function is called by the OS to send packets |
| 281 | * @skb: the packet(s) to send |
| 282 | * @netdev:device on which to TX the above packet(s) |
| 283 | * |
| 284 | * Return 0 in almost all cases; non-zero value in extreme hard failure only |
| 285 | */ |
| 286 | int et131x_send_packets(struct sk_buff *skb, struct net_device *netdev) |
| 287 | { |
| 288 | int status = 0; |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 289 | struct et131x_adapter *etdev = NULL; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 290 | |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 291 | etdev = netdev_priv(netdev); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 292 | |
| 293 | /* Send these packets |
| 294 | * |
| 295 | * NOTE: The Linux Tx entry point is only given one packet at a time |
| 296 | * to Tx, so the PacketCount and it's array used makes no sense here |
| 297 | */ |
| 298 | |
Alan Cox | 116badf | 2009-10-06 15:49:21 +0100 | [diff] [blame] | 299 | /* TCB is not available */ |
Alan Cox | c78732a | 2009-10-06 15:49:45 +0100 | [diff] [blame] | 300 | if (etdev->tx_ring.used >= NUM_TCB) { |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 301 | /* NOTE: If there's an error on send, no need to queue the |
| 302 | * packet under Linux; if we just send an error up to the |
| 303 | * netif layer, it will resend the skb to us. |
| 304 | */ |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 305 | status = -ENOMEM; |
| 306 | } else { |
| 307 | /* We need to see if the link is up; if it's not, make the |
| 308 | * netif layer think we're good and drop the packet |
| 309 | */ |
Alan Cox | c1996fc | 2009-10-06 15:49:29 +0100 | [diff] [blame] | 310 | if ((etdev->Flags & fMP_ADAPTER_FAIL_SEND_MASK) || |
| 311 | !netif_carrier_ok(netdev)) { |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 312 | dev_kfree_skb_any(skb); |
| 313 | skb = NULL; |
| 314 | |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 315 | etdev->net_stats.tx_dropped++; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 316 | } else { |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 317 | status = et131x_send_packet(skb, etdev); |
Alan Cox | c1996fc | 2009-10-06 15:49:29 +0100 | [diff] [blame] | 318 | if (status != 0 && status != -ENOMEM) { |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 319 | /* On any other error, make netif think we're |
| 320 | * OK and drop the packet |
| 321 | */ |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 322 | dev_kfree_skb_any(skb); |
| 323 | skb = NULL; |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 324 | etdev->net_stats.tx_dropped++; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 325 | } |
| 326 | } |
| 327 | } |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 328 | return status; |
| 329 | } |
| 330 | |
| 331 | /** |
| 332 | * et131x_send_packet - Do the work to send a packet |
| 333 | * @skb: the packet(s) to send |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 334 | * @etdev: a pointer to the device's private adapter structure |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 335 | * |
| 336 | * Return 0 in almost all cases; non-zero value in extreme hard failure only. |
| 337 | * |
| 338 | * Assumption: Send spinlock has been acquired |
| 339 | */ |
| 340 | static int et131x_send_packet(struct sk_buff *skb, |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 341 | struct et131x_adapter *etdev) |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 342 | { |
Alan Cox | c1996fc | 2009-10-06 15:49:29 +0100 | [diff] [blame] | 343 | int status; |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 344 | struct tcb *tcb = NULL; |
Alan Cox | 116badf | 2009-10-06 15:49:21 +0100 | [diff] [blame] | 345 | u16 *shbufva; |
Alan Cox | 3762860 | 2009-08-19 18:21:50 +0100 | [diff] [blame] | 346 | unsigned long flags; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 347 | |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 348 | /* All packets must have at least a MAC address and a protocol type */ |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 349 | if (skb->len < ETH_HLEN) |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 350 | return -EIO; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 351 | |
| 352 | /* Get a TCB for this packet */ |
Alan Cox | 3762860 | 2009-08-19 18:21:50 +0100 | [diff] [blame] | 353 | spin_lock_irqsave(&etdev->TCBReadyQLock, flags); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 354 | |
Alan Cox | c78732a | 2009-10-06 15:49:45 +0100 | [diff] [blame] | 355 | tcb = etdev->tx_ring.tcb_qhead; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 356 | |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 357 | if (tcb == NULL) { |
Alan Cox | 3762860 | 2009-08-19 18:21:50 +0100 | [diff] [blame] | 358 | spin_unlock_irqrestore(&etdev->TCBReadyQLock, flags); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 359 | return -ENOMEM; |
| 360 | } |
| 361 | |
Alan Cox | c78732a | 2009-10-06 15:49:45 +0100 | [diff] [blame] | 362 | etdev->tx_ring.tcb_qhead = tcb->next; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 363 | |
Alan Cox | c78732a | 2009-10-06 15:49:45 +0100 | [diff] [blame] | 364 | if (etdev->tx_ring.tcb_qhead == NULL) |
| 365 | etdev->tx_ring.tcb_qtail = NULL; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 366 | |
Alan Cox | 3762860 | 2009-08-19 18:21:50 +0100 | [diff] [blame] | 367 | spin_unlock_irqrestore(&etdev->TCBReadyQLock, flags); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 368 | |
Alan Cox | c78732a | 2009-10-06 15:49:45 +0100 | [diff] [blame] | 369 | tcb->skb = skb; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 370 | |
Alan Cox | 1458d82 | 2009-10-06 15:49:58 +0100 | [diff] [blame] | 371 | if (skb->data != NULL && skb->len - skb->data_len >= 6) { |
Alan Cox | 116badf | 2009-10-06 15:49:21 +0100 | [diff] [blame] | 372 | shbufva = (u16 *) skb->data; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 373 | |
Alan Cox | 9fa8109 | 2009-08-27 11:00:36 +0100 | [diff] [blame] | 374 | if ((shbufva[0] == 0xffff) && |
| 375 | (shbufva[1] == 0xffff) && (shbufva[2] == 0xffff)) { |
Alan Cox | c78732a | 2009-10-06 15:49:45 +0100 | [diff] [blame] | 376 | tcb->flags |= fMP_DEST_BROAD; |
Alan Cox | 9fa8109 | 2009-08-27 11:00:36 +0100 | [diff] [blame] | 377 | } else if ((shbufva[0] & 0x3) == 0x0001) { |
Alan Cox | c78732a | 2009-10-06 15:49:45 +0100 | [diff] [blame] | 378 | tcb->flags |= fMP_DEST_MULTI; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 379 | } |
| 380 | } |
| 381 | |
Alan Cox | c78732a | 2009-10-06 15:49:45 +0100 | [diff] [blame] | 382 | tcb->next = NULL; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 383 | |
| 384 | /* Call the NIC specific send handler. */ |
Alan Cox | c1996fc | 2009-10-06 15:49:29 +0100 | [diff] [blame] | 385 | status = nic_send_packet(etdev, tcb); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 386 | |
| 387 | if (status != 0) { |
Alan Cox | 3762860 | 2009-08-19 18:21:50 +0100 | [diff] [blame] | 388 | spin_lock_irqsave(&etdev->TCBReadyQLock, flags); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 389 | |
Alan Cox | 1458d82 | 2009-10-06 15:49:58 +0100 | [diff] [blame] | 390 | if (etdev->tx_ring.tcb_qtail) |
Alan Cox | c78732a | 2009-10-06 15:49:45 +0100 | [diff] [blame] | 391 | etdev->tx_ring.tcb_qtail->next = tcb; |
Alan Cox | 1458d82 | 2009-10-06 15:49:58 +0100 | [diff] [blame] | 392 | else |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 393 | /* Apparently ready Q is empty. */ |
Alan Cox | c78732a | 2009-10-06 15:49:45 +0100 | [diff] [blame] | 394 | etdev->tx_ring.tcb_qhead = tcb; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 395 | |
Alan Cox | c78732a | 2009-10-06 15:49:45 +0100 | [diff] [blame] | 396 | etdev->tx_ring.tcb_qtail = tcb; |
Alan Cox | 3762860 | 2009-08-19 18:21:50 +0100 | [diff] [blame] | 397 | spin_unlock_irqrestore(&etdev->TCBReadyQLock, flags); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 398 | return status; |
| 399 | } |
Alan Cox | c78732a | 2009-10-06 15:49:45 +0100 | [diff] [blame] | 400 | WARN_ON(etdev->tx_ring.used > NUM_TCB); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 401 | return 0; |
| 402 | } |
| 403 | |
| 404 | /** |
| 405 | * nic_send_packet - NIC specific send handler for version B silicon. |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 406 | * @etdev: pointer to our adapter |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 407 | * @tcb: pointer to struct tcb |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 408 | * |
| 409 | * Returns 0 or errno. |
| 410 | */ |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 411 | static int nic_send_packet(struct et131x_adapter *etdev, struct tcb *tcb) |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 412 | { |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 413 | u32 i; |
| 414 | struct tx_desc desc[24]; /* 24 x 16 byte */ |
| 415 | u32 frag = 0; |
| 416 | u32 thiscopy, remainder; |
Alan Cox | c78732a | 2009-10-06 15:49:45 +0100 | [diff] [blame] | 417 | struct sk_buff *skb = tcb->skb; |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 418 | u32 nr_frags = skb_shinfo(skb)->nr_frags + 1; |
| 419 | struct skb_frag_struct *frags = &skb_shinfo(skb)->frags[0]; |
Alan Cox | 3762860 | 2009-08-19 18:21:50 +0100 | [diff] [blame] | 420 | unsigned long flags; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 421 | |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 422 | /* Part of the optimizations of this send routine restrict us to |
| 423 | * sending 24 fragments at a pass. In practice we should never see |
| 424 | * more than 5 fragments. |
| 425 | * |
| 426 | * NOTE: The older version of this function (below) can handle any |
| 427 | * number of fragments. If needed, we can call this function, |
| 428 | * although it is less efficient. |
| 429 | */ |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 430 | if (nr_frags > 23) |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 431 | return -EIO; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 432 | |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 433 | memset(desc, 0, sizeof(struct tx_desc) * (nr_frags + 1)); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 434 | |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 435 | for (i = 0; i < nr_frags; i++) { |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 436 | /* If there is something in this element, lets get a |
| 437 | * descriptor from the ring and get the necessary data |
| 438 | */ |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 439 | if (i == 0) { |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 440 | /* If the fragments are smaller than a standard MTU, |
| 441 | * then map them to a single descriptor in the Tx |
| 442 | * Desc ring. However, if they're larger, as is |
| 443 | * possible with support for jumbo packets, then |
| 444 | * split them each across 2 descriptors. |
| 445 | * |
| 446 | * This will work until we determine why the hardware |
| 447 | * doesn't seem to like large fragments. |
| 448 | */ |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 449 | if ((skb->len - skb->data_len) <= 1514) { |
| 450 | desc[frag].addr_hi = 0; |
Alan Cox | fb70ed6 | 2009-10-06 15:48:25 +0100 | [diff] [blame] | 451 | /* Low 16bits are length, high is vlan and |
| 452 | unused currently so zero */ |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 453 | desc[frag].len_vlan = |
| 454 | skb->len - skb->data_len; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 455 | |
| 456 | /* NOTE: Here, the dma_addr_t returned from |
| 457 | * pci_map_single() is implicitly cast as a |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 458 | * u32. Although dma_addr_t can be |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 459 | * 64-bit, the address returned by |
| 460 | * pci_map_single() is always 32-bit |
| 461 | * addressable (as defined by the pci/dma |
| 462 | * subsystem) |
| 463 | */ |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 464 | desc[frag++].addr_lo = |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 465 | pci_map_single(etdev->pdev, |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 466 | skb->data, |
| 467 | skb->len - |
| 468 | skb->data_len, |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 469 | PCI_DMA_TODEVICE); |
| 470 | } else { |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 471 | desc[frag].addr_hi = 0; |
| 472 | desc[frag].len_vlan = |
| 473 | (skb->len - skb->data_len) / 2; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 474 | |
| 475 | /* NOTE: Here, the dma_addr_t returned from |
| 476 | * pci_map_single() is implicitly cast as a |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 477 | * u32. Although dma_addr_t can be |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 478 | * 64-bit, the address returned by |
| 479 | * pci_map_single() is always 32-bit |
| 480 | * addressable (as defined by the pci/dma |
| 481 | * subsystem) |
| 482 | */ |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 483 | desc[frag++].addr_lo = |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 484 | pci_map_single(etdev->pdev, |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 485 | skb->data, |
| 486 | ((skb->len - |
| 487 | skb->data_len) / 2), |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 488 | PCI_DMA_TODEVICE); |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 489 | desc[frag].addr_hi = 0; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 490 | |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 491 | desc[frag].len_vlan = |
| 492 | (skb->len - skb->data_len) / 2; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 493 | |
| 494 | /* NOTE: Here, the dma_addr_t returned from |
| 495 | * pci_map_single() is implicitly cast as a |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 496 | * u32. Although dma_addr_t can be |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 497 | * 64-bit, the address returned by |
| 498 | * pci_map_single() is always 32-bit |
| 499 | * addressable (as defined by the pci/dma |
| 500 | * subsystem) |
| 501 | */ |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 502 | desc[frag++].addr_lo = |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 503 | pci_map_single(etdev->pdev, |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 504 | skb->data + |
| 505 | ((skb->len - |
| 506 | skb->data_len) / 2), |
| 507 | ((skb->len - |
| 508 | skb->data_len) / 2), |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 509 | PCI_DMA_TODEVICE); |
| 510 | } |
| 511 | } else { |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 512 | desc[frag].addr_hi = 0; |
| 513 | desc[frag].len_vlan = |
| 514 | frags[i - 1].size; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 515 | |
| 516 | /* NOTE: Here, the dma_addr_t returned from |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 517 | * pci_map_page() is implicitly cast as a u32. |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 518 | * Although dma_addr_t can be 64-bit, the address |
| 519 | * returned by pci_map_page() is always 32-bit |
| 520 | * addressable (as defined by the pci/dma subsystem) |
| 521 | */ |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 522 | desc[frag++].addr_lo = |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 523 | pci_map_page(etdev->pdev, |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 524 | frags[i - 1].page, |
| 525 | frags[i - 1].page_offset, |
| 526 | frags[i - 1].size, |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 527 | PCI_DMA_TODEVICE); |
| 528 | } |
| 529 | } |
| 530 | |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 531 | if (frag == 0) |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 532 | return -EIO; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 533 | |
Alan Cox | 9fa8109 | 2009-08-27 11:00:36 +0100 | [diff] [blame] | 534 | if (etdev->linkspeed == TRUEPHY_SPEED_1000MBPS) { |
Alan Cox | 1458d82 | 2009-10-06 15:49:58 +0100 | [diff] [blame] | 535 | if (++etdev->tx_ring.since_irq == PARM_TX_NUM_BUFS_DEF) { |
| 536 | /* Last element & Interrupt flag */ |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 537 | desc[frag - 1].flags = 0x5; |
Alan Cox | c78732a | 2009-10-06 15:49:45 +0100 | [diff] [blame] | 538 | etdev->tx_ring.since_irq = 0; |
Alan Cox | b44207a | 2009-10-06 15:48:16 +0100 | [diff] [blame] | 539 | } else { /* Last element */ |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 540 | desc[frag - 1].flags = 0x1; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 541 | } |
Alan Cox | c78732a | 2009-10-06 15:49:45 +0100 | [diff] [blame] | 542 | } else |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 543 | desc[frag - 1].flags = 0x5; |
Alan Cox | c78732a | 2009-10-06 15:49:45 +0100 | [diff] [blame] | 544 | |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 545 | desc[0].flags |= 2; /* First element flag */ |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 546 | |
Alan Cox | c78732a | 2009-10-06 15:49:45 +0100 | [diff] [blame] | 547 | tcb->index_start = etdev->tx_ring.send_idx; |
| 548 | tcb->stale = 0; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 549 | |
Alan Cox | 3762860 | 2009-08-19 18:21:50 +0100 | [diff] [blame] | 550 | spin_lock_irqsave(&etdev->SendHWLock, flags); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 551 | |
Alan Cox | 356c74b | 2009-08-27 11:01:57 +0100 | [diff] [blame] | 552 | thiscopy = NUM_DESC_PER_RING_TX - |
Alan Cox | c78732a | 2009-10-06 15:49:45 +0100 | [diff] [blame] | 553 | INDEX10(etdev->tx_ring.send_idx); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 554 | |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 555 | if (thiscopy >= frag) { |
Alan Cox | 9fa8109 | 2009-08-27 11:00:36 +0100 | [diff] [blame] | 556 | remainder = 0; |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 557 | thiscopy = frag; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 558 | } else { |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 559 | remainder = frag - thiscopy; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 560 | } |
| 561 | |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 562 | memcpy(etdev->tx_ring.tx_desc_ring + |
Alan Cox | c78732a | 2009-10-06 15:49:45 +0100 | [diff] [blame] | 563 | INDEX10(etdev->tx_ring.send_idx), desc, |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 564 | sizeof(struct tx_desc) * thiscopy); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 565 | |
Alan Cox | c78732a | 2009-10-06 15:49:45 +0100 | [diff] [blame] | 566 | add_10bit(&etdev->tx_ring.send_idx, thiscopy); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 567 | |
Alan Cox | 1458d82 | 2009-10-06 15:49:58 +0100 | [diff] [blame] | 568 | if (INDEX10(etdev->tx_ring.send_idx) == 0 || |
| 569 | INDEX10(etdev->tx_ring.send_idx) == NUM_DESC_PER_RING_TX) { |
| 570 | etdev->tx_ring.send_idx &= ~ET_DMA10_MASK; |
| 571 | etdev->tx_ring.send_idx ^= ET_DMA10_WRAP; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 572 | } |
| 573 | |
Alan Cox | 9fa8109 | 2009-08-27 11:00:36 +0100 | [diff] [blame] | 574 | if (remainder) { |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 575 | memcpy(etdev->tx_ring.tx_desc_ring, |
| 576 | desc + thiscopy, |
| 577 | sizeof(struct tx_desc) * remainder); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 578 | |
Alan Cox | c78732a | 2009-10-06 15:49:45 +0100 | [diff] [blame] | 579 | add_10bit(&etdev->tx_ring.send_idx, remainder); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 580 | } |
| 581 | |
Alan Cox | c78732a | 2009-10-06 15:49:45 +0100 | [diff] [blame] | 582 | if (INDEX10(etdev->tx_ring.send_idx) == 0) { |
| 583 | if (etdev->tx_ring.send_idx) |
| 584 | tcb->index = NUM_DESC_PER_RING_TX - 1; |
Alan Cox | 64f9303 | 2009-06-10 17:30:41 +0100 | [diff] [blame] | 585 | else |
Alan Cox | 1458d82 | 2009-10-06 15:49:58 +0100 | [diff] [blame] | 586 | tcb->index = ET_DMA10_WRAP|(NUM_DESC_PER_RING_TX - 1); |
Alan Cox | 64f9303 | 2009-06-10 17:30:41 +0100 | [diff] [blame] | 587 | } else |
Alan Cox | c78732a | 2009-10-06 15:49:45 +0100 | [diff] [blame] | 588 | tcb->index = etdev->tx_ring.send_idx - 1; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 589 | |
Alan Cox | 3762860 | 2009-08-19 18:21:50 +0100 | [diff] [blame] | 590 | spin_lock(&etdev->TCBSendQLock); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 591 | |
Alan Cox | c78732a | 2009-10-06 15:49:45 +0100 | [diff] [blame] | 592 | if (etdev->tx_ring.send_tail) |
| 593 | etdev->tx_ring.send_tail->next = tcb; |
Alan Cox | 64f9303 | 2009-06-10 17:30:41 +0100 | [diff] [blame] | 594 | else |
Alan Cox | c78732a | 2009-10-06 15:49:45 +0100 | [diff] [blame] | 595 | etdev->tx_ring.send_head = tcb; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 596 | |
Alan Cox | c78732a | 2009-10-06 15:49:45 +0100 | [diff] [blame] | 597 | etdev->tx_ring.send_tail = tcb; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 598 | |
Alan Cox | c78732a | 2009-10-06 15:49:45 +0100 | [diff] [blame] | 599 | WARN_ON(tcb->next != NULL); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 600 | |
Alan Cox | c78732a | 2009-10-06 15:49:45 +0100 | [diff] [blame] | 601 | etdev->tx_ring.used++; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 602 | |
Alan Cox | 3762860 | 2009-08-19 18:21:50 +0100 | [diff] [blame] | 603 | spin_unlock(&etdev->TCBSendQLock); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 604 | |
| 605 | /* Write the new write pointer back to the device. */ |
Alan Cox | c78732a | 2009-10-06 15:49:45 +0100 | [diff] [blame] | 606 | writel(etdev->tx_ring.send_idx, |
Alan Cox | 356c74b | 2009-08-27 11:01:57 +0100 | [diff] [blame] | 607 | &etdev->regs->txdma.service_request); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 608 | |
| 609 | /* For Gig only, we use Tx Interrupt coalescing. Enable the software |
| 610 | * timer to wake us up if this packet isn't followed by N more. |
| 611 | */ |
Alan Cox | 9fa8109 | 2009-08-27 11:00:36 +0100 | [diff] [blame] | 612 | if (etdev->linkspeed == TRUEPHY_SPEED_1000MBPS) { |
Alan Cox | c255717 | 2009-08-27 10:59:56 +0100 | [diff] [blame] | 613 | writel(PARM_TX_TIME_INT_DEF * NANO_IN_A_MICRO, |
Alan Cox | f3f415a | 2009-08-27 10:59:30 +0100 | [diff] [blame] | 614 | &etdev->regs->global.watchdog_timer); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 615 | } |
Alan Cox | 3762860 | 2009-08-19 18:21:50 +0100 | [diff] [blame] | 616 | spin_unlock_irqrestore(&etdev->SendHWLock, flags); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 617 | |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 618 | return 0; |
| 619 | } |
| 620 | |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 621 | |
| 622 | /** |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 623 | * et131x_free_send_packet - Recycle a struct tcb |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 624 | * @etdev: pointer to our adapter |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 625 | * @tcb: pointer to struct tcb |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 626 | * |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 627 | * Complete the packet if necessary |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 628 | * Assumption - Send spinlock has been acquired |
| 629 | */ |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 630 | inline void et131x_free_send_packet(struct et131x_adapter *etdev, |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 631 | struct tcb *tcb) |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 632 | { |
Alan Cox | 3762860 | 2009-08-19 18:21:50 +0100 | [diff] [blame] | 633 | unsigned long flags; |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 634 | struct tx_desc *desc = NULL; |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 635 | struct net_device_stats *stats = &etdev->net_stats; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 636 | |
Alan Cox | c78732a | 2009-10-06 15:49:45 +0100 | [diff] [blame] | 637 | if (tcb->flags & fMP_DEST_BROAD) |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 638 | atomic_inc(&etdev->Stats.brdcstxmt); |
Alan Cox | c78732a | 2009-10-06 15:49:45 +0100 | [diff] [blame] | 639 | else if (tcb->flags & fMP_DEST_MULTI) |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 640 | atomic_inc(&etdev->Stats.multixmt); |
Alan Cox | 64f9303 | 2009-06-10 17:30:41 +0100 | [diff] [blame] | 641 | else |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 642 | atomic_inc(&etdev->Stats.unixmt); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 643 | |
Alan Cox | c78732a | 2009-10-06 15:49:45 +0100 | [diff] [blame] | 644 | if (tcb->skb) { |
| 645 | stats->tx_bytes += tcb->skb->len; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 646 | |
| 647 | /* Iterate through the TX descriptors on the ring |
| 648 | * corresponding to this packet and umap the fragments |
| 649 | * they point to |
| 650 | */ |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 651 | do { |
Alan Cox | 1458d82 | 2009-10-06 15:49:58 +0100 | [diff] [blame] | 652 | desc = (struct tx_desc *)(etdev->tx_ring.tx_desc_ring + |
| 653 | INDEX10(tcb->index_start)); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 654 | |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 655 | pci_unmap_single(etdev->pdev, |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 656 | desc->addr_lo, |
| 657 | desc->len_vlan, PCI_DMA_TODEVICE); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 658 | |
Alan Cox | c78732a | 2009-10-06 15:49:45 +0100 | [diff] [blame] | 659 | add_10bit(&tcb->index_start, 1); |
| 660 | if (INDEX10(tcb->index_start) >= |
Alan Cox | 1458d82 | 2009-10-06 15:49:58 +0100 | [diff] [blame] | 661 | NUM_DESC_PER_RING_TX) { |
| 662 | tcb->index_start &= ~ET_DMA10_MASK; |
| 663 | tcb->index_start ^= ET_DMA10_WRAP; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 664 | } |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 665 | } while (desc != (etdev->tx_ring.tx_desc_ring + |
Alan Cox | c78732a | 2009-10-06 15:49:45 +0100 | [diff] [blame] | 666 | INDEX10(tcb->index))); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 667 | |
Alan Cox | c78732a | 2009-10-06 15:49:45 +0100 | [diff] [blame] | 668 | dev_kfree_skb_any(tcb->skb); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 669 | } |
| 670 | |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 671 | memset(tcb, 0, sizeof(struct tcb)); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 672 | |
| 673 | /* Add the TCB to the Ready Q */ |
Alan Cox | 3762860 | 2009-08-19 18:21:50 +0100 | [diff] [blame] | 674 | spin_lock_irqsave(&etdev->TCBReadyQLock, flags); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 675 | |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 676 | etdev->Stats.opackets++; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 677 | |
Alan Cox | c78732a | 2009-10-06 15:49:45 +0100 | [diff] [blame] | 678 | if (etdev->tx_ring.tcb_qtail) |
| 679 | etdev->tx_ring.tcb_qtail->next = tcb; |
Alan Cox | c1996fc | 2009-10-06 15:49:29 +0100 | [diff] [blame] | 680 | else |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 681 | /* Apparently ready Q is empty. */ |
Alan Cox | c78732a | 2009-10-06 15:49:45 +0100 | [diff] [blame] | 682 | etdev->tx_ring.tcb_qhead = tcb; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 683 | |
Alan Cox | c78732a | 2009-10-06 15:49:45 +0100 | [diff] [blame] | 684 | etdev->tx_ring.tcb_qtail = tcb; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 685 | |
Alan Cox | 3762860 | 2009-08-19 18:21:50 +0100 | [diff] [blame] | 686 | spin_unlock_irqrestore(&etdev->TCBReadyQLock, flags); |
Alan Cox | c78732a | 2009-10-06 15:49:45 +0100 | [diff] [blame] | 687 | WARN_ON(etdev->tx_ring.used < 0); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 688 | } |
| 689 | |
| 690 | /** |
| 691 | * et131x_free_busy_send_packets - Free and complete the stopped active sends |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 692 | * @etdev: pointer to our adapter |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 693 | * |
| 694 | * Assumption - Send spinlock has been acquired |
| 695 | */ |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 696 | void et131x_free_busy_send_packets(struct et131x_adapter *etdev) |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 697 | { |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 698 | struct tcb *tcb; |
Alan Cox | 3762860 | 2009-08-19 18:21:50 +0100 | [diff] [blame] | 699 | unsigned long flags; |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 700 | u32 freed = 0; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 701 | |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 702 | /* Any packets being sent? Check the first TCB on the send list */ |
Alan Cox | 3762860 | 2009-08-19 18:21:50 +0100 | [diff] [blame] | 703 | spin_lock_irqsave(&etdev->TCBSendQLock, flags); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 704 | |
Alan Cox | c78732a | 2009-10-06 15:49:45 +0100 | [diff] [blame] | 705 | tcb = etdev->tx_ring.send_head; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 706 | |
Alan Cox | 1458d82 | 2009-10-06 15:49:58 +0100 | [diff] [blame] | 707 | while (tcb != NULL && freed < NUM_TCB) { |
Alan Cox | c78732a | 2009-10-06 15:49:45 +0100 | [diff] [blame] | 708 | struct tcb *next = tcb->next; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 709 | |
Alan Cox | c78732a | 2009-10-06 15:49:45 +0100 | [diff] [blame] | 710 | etdev->tx_ring.send_head = next; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 711 | |
Alan Cox | c78732a | 2009-10-06 15:49:45 +0100 | [diff] [blame] | 712 | if (next == NULL) |
| 713 | etdev->tx_ring.send_tail = NULL; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 714 | |
Alan Cox | c78732a | 2009-10-06 15:49:45 +0100 | [diff] [blame] | 715 | etdev->tx_ring.used--; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 716 | |
Alan Cox | 3762860 | 2009-08-19 18:21:50 +0100 | [diff] [blame] | 717 | spin_unlock_irqrestore(&etdev->TCBSendQLock, flags); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 718 | |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 719 | freed++; |
| 720 | et131x_free_send_packet(etdev, tcb); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 721 | |
Alan Cox | 3762860 | 2009-08-19 18:21:50 +0100 | [diff] [blame] | 722 | spin_lock_irqsave(&etdev->TCBSendQLock, flags); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 723 | |
Alan Cox | c78732a | 2009-10-06 15:49:45 +0100 | [diff] [blame] | 724 | tcb = etdev->tx_ring.send_head; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 725 | } |
| 726 | |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 727 | WARN_ON(freed == NUM_TCB); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 728 | |
Alan Cox | 3762860 | 2009-08-19 18:21:50 +0100 | [diff] [blame] | 729 | spin_unlock_irqrestore(&etdev->TCBSendQLock, flags); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 730 | |
Alan Cox | c78732a | 2009-10-06 15:49:45 +0100 | [diff] [blame] | 731 | etdev->tx_ring.used = 0; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 732 | } |
| 733 | |
| 734 | /** |
| 735 | * et131x_handle_send_interrupt - Interrupt handler for sending processing |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 736 | * @etdev: pointer to our adapter |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 737 | * |
| 738 | * Re-claim the send resources, complete sends and get more to send from |
| 739 | * the send wait queue. |
| 740 | * |
| 741 | * Assumption - Send spinlock has been acquired |
| 742 | */ |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 743 | void et131x_handle_send_interrupt(struct et131x_adapter *etdev) |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 744 | { |
Alan Cox | 3762860 | 2009-08-19 18:21:50 +0100 | [diff] [blame] | 745 | unsigned long flags; |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 746 | u32 serviced; |
Alan Cox | 1458d82 | 2009-10-06 15:49:58 +0100 | [diff] [blame] | 747 | struct tcb *tcb; |
Alan Cox | 356c74b | 2009-08-27 11:01:57 +0100 | [diff] [blame] | 748 | u32 index; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 749 | |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 750 | serviced = readl(&etdev->regs->txdma.NewServiceComplete); |
| 751 | index = INDEX10(serviced); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 752 | |
| 753 | /* Has the ring wrapped? Process any descriptors that do not have |
| 754 | * the same "wrap" indicator as the current completion indicator |
| 755 | */ |
Alan Cox | 3762860 | 2009-08-19 18:21:50 +0100 | [diff] [blame] | 756 | spin_lock_irqsave(&etdev->TCBSendQLock, flags); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 757 | |
Alan Cox | c78732a | 2009-10-06 15:49:45 +0100 | [diff] [blame] | 758 | tcb = etdev->tx_ring.send_head; |
Alan Cox | 356c74b | 2009-08-27 11:01:57 +0100 | [diff] [blame] | 759 | |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 760 | while (tcb && |
Alan Cox | c78732a | 2009-10-06 15:49:45 +0100 | [diff] [blame] | 761 | ((serviced ^ tcb->index) & ET_DMA10_WRAP) && |
| 762 | index < INDEX10(tcb->index)) { |
| 763 | etdev->tx_ring.used--; |
| 764 | etdev->tx_ring.send_head = tcb->next; |
| 765 | if (tcb->next == NULL) |
| 766 | etdev->tx_ring.send_tail = NULL; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 767 | |
Alan Cox | 3762860 | 2009-08-19 18:21:50 +0100 | [diff] [blame] | 768 | spin_unlock_irqrestore(&etdev->TCBSendQLock, flags); |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 769 | et131x_free_send_packet(etdev, tcb); |
Alan Cox | 3762860 | 2009-08-19 18:21:50 +0100 | [diff] [blame] | 770 | spin_lock_irqsave(&etdev->TCBSendQLock, flags); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 771 | |
| 772 | /* Goto the next packet */ |
Alan Cox | c78732a | 2009-10-06 15:49:45 +0100 | [diff] [blame] | 773 | tcb = etdev->tx_ring.send_head; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 774 | } |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 775 | while (tcb && |
Alan Cox | c78732a | 2009-10-06 15:49:45 +0100 | [diff] [blame] | 776 | !((serviced ^ tcb->index) & ET_DMA10_WRAP) |
| 777 | && index > (tcb->index & ET_DMA10_MASK)) { |
| 778 | etdev->tx_ring.used--; |
| 779 | etdev->tx_ring.send_head = tcb->next; |
| 780 | if (tcb->next == NULL) |
| 781 | etdev->tx_ring.send_tail = NULL; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 782 | |
Alan Cox | 3762860 | 2009-08-19 18:21:50 +0100 | [diff] [blame] | 783 | spin_unlock_irqrestore(&etdev->TCBSendQLock, flags); |
Alan Cox | b711b2e | 2009-10-06 15:48:33 +0100 | [diff] [blame] | 784 | et131x_free_send_packet(etdev, tcb); |
Alan Cox | 3762860 | 2009-08-19 18:21:50 +0100 | [diff] [blame] | 785 | spin_lock_irqsave(&etdev->TCBSendQLock, flags); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 786 | |
| 787 | /* Goto the next packet */ |
Alan Cox | c78732a | 2009-10-06 15:49:45 +0100 | [diff] [blame] | 788 | tcb = etdev->tx_ring.send_head; |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 789 | } |
| 790 | |
| 791 | /* Wake up the queue when we hit a low-water mark */ |
Alan Cox | 1458d82 | 2009-10-06 15:49:58 +0100 | [diff] [blame] | 792 | if (etdev->tx_ring.used <= NUM_TCB / 3) |
Alan Cox | 25ad00b | 2009-08-19 18:21:44 +0100 | [diff] [blame] | 793 | netif_wake_queue(etdev->netdev); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 794 | |
Alan Cox | 3762860 | 2009-08-19 18:21:50 +0100 | [diff] [blame] | 795 | spin_unlock_irqrestore(&etdev->TCBSendQLock, flags); |
Greg Kroah-Hartman | cfb739b | 2008-04-03 17:30:53 -0700 | [diff] [blame] | 796 | } |
| 797 | |