blob: 0f3473d758e49f784f2ee8cc9b59001d03171f05 [file] [log] [blame]
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -07001/*
2 * Agere Systems Inc.
3 * 10/100/1000 Base-T Ethernet Driver for the ET1301 and ET131x series MACs
4 *
Alan Cox64f93032009-06-10 17:30:41 +01005 * Copyright © 2005 Agere Systems Inc.
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -07006 * 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 Cox64f93032009-06-10 17:30:41 +010022 * Copyright © 2005 Agere Systems Inc.
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -070023 * 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 Cox64f93032009-06-10 17:30:41 +010043 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -070044 * 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-Hartmancfb739b2008-04-03 17:30:53 -070059#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 Cox64f93032009-06-10 17:30:41 +010076#include <linux/io.h>
77#include <linux/bitops.h>
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -070078#include <asm/system.h>
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -070079
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-Hartmancfb739b2008-04-03 17:30:53 -070087#include "et131x_adapter.h"
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -070088#include "et1310_tx.h"
Alan Cox69ea5fc2010-01-18 15:34:24 +000089#include "et131x.h"
Alan Coxc2557172009-08-27 10:59:56 +010090
Alan Cox25ad00b2009-08-19 18:21:44 +010091static inline void et131x_free_send_packet(struct et131x_adapter *etdev,
Alan Coxb711b2e2009-10-06 15:48:33 +010092 struct tcb *tcb);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -070093static int et131x_send_packet(struct sk_buff *skb,
Alan Cox25ad00b2009-08-19 18:21:44 +010094 struct et131x_adapter *etdev);
Alan Coxb711b2e2009-10-06 15:48:33 +010095static int nic_send_packet(struct et131x_adapter *etdev, struct tcb *tcb);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -070096
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 */
109int et131x_tx_dma_memory_alloc(struct et131x_adapter *adapter)
110{
111 int desc_size = 0;
Alan Coxb711b2e2009-10-06 15:48:33 +0100112 struct tx_ring *tx_ring = &adapter->tx_ring;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700113
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700114 /* Allocate memory for the TCB's (Transmit Control Block) */
Julia Lawall32414872010-05-11 20:26:57 +0200115 adapter->tx_ring.tcb_ring =
Alan Coxb711b2e2009-10-06 15:48:33 +0100116 kcalloc(NUM_TCB, sizeof(struct tcb), GFP_ATOMIC | GFP_DMA);
Alan Coxc78732a2009-10-06 15:49:45 +0100117 if (!adapter->tx_ring.tcb_ring) {
Alan Cox15700032009-08-27 11:03:09 +0100118 dev_err(&adapter->pdev->dev, "Cannot alloc memory for TCBs\n");
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700119 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 Coxb711b2e2009-10-06 15:48:33 +0100125 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 Cox1458d822009-10-06 15:49:58 +0100130 dev_err(&adapter->pdev->dev,
131 "Cannot alloc memory for Tx Ring\n");
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700132 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-Hartmancfb739b2008-04-03 17:30:53 -0700142 /* Allocate memory for the Tx status block */
Alan Coxc78732a2009-10-06 15:49:45 +0100143 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 Cox15700032009-08-27 11:03:09 +0100147 dev_err(&adapter->pdev->dev,
148 "Cannot alloc memory for Tx status block\n");
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700149 return -ENOMEM;
150 }
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700151 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 */
160void et131x_tx_dma_memory_free(struct et131x_adapter *adapter)
161{
162 int desc_size = 0;
163
Alan Coxb711b2e2009-10-06 15:48:33 +0100164 if (adapter->tx_ring.tx_desc_ring) {
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700165 /* Free memory relating to Tx rings here */
Alan Coxb711b2e2009-10-06 15:48:33 +0100166 desc_size = (sizeof(struct tx_desc) * NUM_DESC_PER_RING_TX)
Alan Cox1458d822009-10-06 15:49:58 +0100167 + 4096 - 1;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700168 pci_free_consistent(adapter->pdev,
169 desc_size,
Alan Coxb711b2e2009-10-06 15:48:33 +0100170 adapter->tx_ring.tx_desc_ring,
171 adapter->tx_ring.tx_desc_ring_pa);
Alan Coxb711b2e2009-10-06 15:48:33 +0100172 adapter->tx_ring.tx_desc_ring = NULL;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700173 }
174
175 /* Free memory for the Tx status block */
Alan Coxc78732a2009-10-06 15:49:45 +0100176 if (adapter->tx_ring.tx_status) {
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700177 pci_free_consistent(adapter->pdev,
Alan Coxc78732a2009-10-06 15:49:45 +0100178 sizeof(u32),
179 adapter->tx_ring.tx_status,
180 adapter->tx_ring.tx_status_pa);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700181
Alan Coxc78732a2009-10-06 15:49:45 +0100182 adapter->tx_ring.tx_status = NULL;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700183 }
Alan Coxb711b2e2009-10-06 15:48:33 +0100184 /* Free the memory for the tcb structures */
Alan Coxc78732a2009-10-06 15:49:45 +0100185 kfree(adapter->tx_ring.tcb_ring);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700186}
187
188/**
189 * ConfigTxDmaRegs - Set up the tx dma section of the JAGCore.
Alan Cox9fa81092009-08-27 11:00:36 +0100190 * @etdev: pointer to our private adapter structure
Alan Cox1458d822009-10-06 15:49:58 +0100191 *
192 * Configure the transmit engine with the ring buffers we have created
193 * and prepare it for use.
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700194 */
Alan Cox25ad00b2009-08-19 18:21:44 +0100195void ConfigTxDmaRegs(struct et131x_adapter *etdev)
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700196{
Alan Cox060a78a2010-01-18 15:33:18 +0000197 struct txdma_regs __iomem *txdma = &etdev->regs->txdma;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700198
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700199 /* Load the hardware with the start of the transmit descriptor ring. */
Alan Cox9c60684b2009-10-06 15:48:49 +0100200 writel((u32) ((u64)etdev->tx_ring.tx_desc_ring_pa >> 32),
Alan Cox9fa81092009-08-27 11:00:36 +0100201 &txdma->pr_base_hi);
Alan Cox9c60684b2009-10-06 15:48:49 +0100202 writel((u32) etdev->tx_ring.tx_desc_ring_pa,
Alan Cox9fa81092009-08-27 11:00:36 +0100203 &txdma->pr_base_lo);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700204
205 /* Initialise the transmit DMA engine */
Alan Cox42a03e92009-11-18 14:07:21 +0000206 writel(NUM_DESC_PER_RING_TX - 1, &txdma->pr_num_des);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700207
Alan Coxc1996fc2009-10-06 15:49:29 +0100208 /* Load the completion writeback physical address */
Alan Coxc78732a2009-10-06 15:49:45 +0100209 writel((u32)((u64)etdev->tx_ring.tx_status_pa >> 32),
Alan Coxc1996fc2009-10-06 15:49:29 +0100210 &txdma->dma_wb_base_hi);
Alan Coxc78732a2009-10-06 15:49:45 +0100211 writel((u32)etdev->tx_ring.tx_status_pa, &txdma->dma_wb_base_lo);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700212
Alan Coxc78732a2009-10-06 15:49:45 +0100213 *etdev->tx_ring.tx_status = 0;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700214
Alan Cox356c74b2009-08-27 11:01:57 +0100215 writel(0, &txdma->service_request);
Alan Coxc78732a2009-10-06 15:49:45 +0100216 etdev->tx_ring.send_idx = 0;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700217}
218
219/**
220 * et131x_tx_dma_disable - Stop of Tx_DMA on the ET1310
Alan Cox25ad00b2009-08-19 18:21:44 +0100221 * @etdev: pointer to our adapter structure
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700222 */
Alan Cox25ad00b2009-08-19 18:21:44 +0100223void et131x_tx_dma_disable(struct et131x_adapter *etdev)
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700224{
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700225 /* Setup the tramsmit dma configuration register */
Alan Coxbcb903f2009-08-27 11:03:38 +0100226 writel(ET_TXDMA_CSR_HALT|ET_TXDMA_SNGL_EPKT,
227 &etdev->regs->txdma.csr);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700228}
229
230/**
231 * et131x_tx_dma_enable - re-start of Tx_DMA on the ET1310.
Alan Cox25ad00b2009-08-19 18:21:44 +0100232 * @etdev: pointer to our adapter structure
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700233 *
234 * Mainly used after a return to the D0 (full-power) state from a lower state.
235 */
Alan Cox25ad00b2009-08-19 18:21:44 +0100236void et131x_tx_dma_enable(struct et131x_adapter *etdev)
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700237{
Alan Cox5f1377d2009-10-06 15:47:55 +0100238 /* 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-Hartmancfb739b2008-04-03 17:30:53 -0700243}
244
245/**
246 * et131x_init_send - Initialize send data structures
247 * @adapter: pointer to our private adapter structure
248 */
249void et131x_init_send(struct et131x_adapter *adapter)
250{
Alan Coxb711b2e2009-10-06 15:48:33 +0100251 struct tcb *tcb;
Alan Coxc1996fc2009-10-06 15:49:29 +0100252 u32 ct;
Alan Coxb711b2e2009-10-06 15:48:33 +0100253 struct tx_ring *tx_ring;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700254
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700255 /* Setup some convenience pointers */
Alan Coxb711b2e2009-10-06 15:48:33 +0100256 tx_ring = &adapter->tx_ring;
Alan Coxc78732a2009-10-06 15:49:45 +0100257 tcb = adapter->tx_ring.tcb_ring;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700258
Alan Coxc78732a2009-10-06 15:49:45 +0100259 tx_ring->tcb_qhead = tcb;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700260
Alan Cox9251d712009-10-06 15:49:36 +0100261 memset(tcb, 0, sizeof(struct tcb) * NUM_TCB);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700262
Alan Cox9251d712009-10-06 15:49:36 +0100263 /* Go through and set up each TCB */
Alan Coxc78732a2009-10-06 15:49:45 +0100264 for (ct = 0; ct++ < NUM_TCB; tcb++)
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700265 /* Set the link pointer in HW TCB to the next TCB in the
Alan Cox1458d822009-10-06 15:49:58 +0100266 * chain
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700267 */
Alan Coxc78732a2009-10-06 15:49:45 +0100268 tcb->next = tcb + 1;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700269
Alan Cox1458d822009-10-06 15:49:58 +0100270 /* Set the tail pointer */
Alan Cox9251d712009-10-06 15:49:36 +0100271 tcb--;
Alan Coxc78732a2009-10-06 15:49:45 +0100272 tx_ring->tcb_qtail = tcb;
273 tcb->next = NULL;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700274 /* Curr send queue should now be empty */
Alan Coxc78732a2009-10-06 15:49:45 +0100275 tx_ring->send_head = NULL;
276 tx_ring->send_tail = NULL;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700277}
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 */
286int et131x_send_packets(struct sk_buff *skb, struct net_device *netdev)
287{
288 int status = 0;
Alan Cox25ad00b2009-08-19 18:21:44 +0100289 struct et131x_adapter *etdev = NULL;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700290
Alan Cox25ad00b2009-08-19 18:21:44 +0100291 etdev = netdev_priv(netdev);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700292
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 Cox116badf2009-10-06 15:49:21 +0100299 /* TCB is not available */
Alan Coxc78732a2009-10-06 15:49:45 +0100300 if (etdev->tx_ring.used >= NUM_TCB) {
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700301 /* 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-Hartmancfb739b2008-04-03 17:30:53 -0700305 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 Coxc1996fc2009-10-06 15:49:29 +0100310 if ((etdev->Flags & fMP_ADAPTER_FAIL_SEND_MASK) ||
311 !netif_carrier_ok(netdev)) {
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700312 dev_kfree_skb_any(skb);
313 skb = NULL;
314
Alan Cox25ad00b2009-08-19 18:21:44 +0100315 etdev->net_stats.tx_dropped++;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700316 } else {
Alan Cox25ad00b2009-08-19 18:21:44 +0100317 status = et131x_send_packet(skb, etdev);
Alan Coxc1996fc2009-10-06 15:49:29 +0100318 if (status != 0 && status != -ENOMEM) {
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700319 /* On any other error, make netif think we're
320 * OK and drop the packet
321 */
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700322 dev_kfree_skb_any(skb);
323 skb = NULL;
Alan Cox25ad00b2009-08-19 18:21:44 +0100324 etdev->net_stats.tx_dropped++;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700325 }
326 }
327 }
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700328 return status;
329}
330
331/**
332 * et131x_send_packet - Do the work to send a packet
333 * @skb: the packet(s) to send
Alan Cox25ad00b2009-08-19 18:21:44 +0100334 * @etdev: a pointer to the device's private adapter structure
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700335 *
336 * Return 0 in almost all cases; non-zero value in extreme hard failure only.
337 *
338 * Assumption: Send spinlock has been acquired
339 */
340static int et131x_send_packet(struct sk_buff *skb,
Alan Cox25ad00b2009-08-19 18:21:44 +0100341 struct et131x_adapter *etdev)
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700342{
Alan Coxc1996fc2009-10-06 15:49:29 +0100343 int status;
Alan Coxb711b2e2009-10-06 15:48:33 +0100344 struct tcb *tcb = NULL;
Alan Cox116badf2009-10-06 15:49:21 +0100345 u16 *shbufva;
Alan Cox37628602009-08-19 18:21:50 +0100346 unsigned long flags;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700347
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700348 /* All packets must have at least a MAC address and a protocol type */
Alan Coxb711b2e2009-10-06 15:48:33 +0100349 if (skb->len < ETH_HLEN)
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700350 return -EIO;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700351
352 /* Get a TCB for this packet */
Alan Cox37628602009-08-19 18:21:50 +0100353 spin_lock_irqsave(&etdev->TCBReadyQLock, flags);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700354
Alan Coxc78732a2009-10-06 15:49:45 +0100355 tcb = etdev->tx_ring.tcb_qhead;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700356
Alan Coxb711b2e2009-10-06 15:48:33 +0100357 if (tcb == NULL) {
Alan Cox37628602009-08-19 18:21:50 +0100358 spin_unlock_irqrestore(&etdev->TCBReadyQLock, flags);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700359 return -ENOMEM;
360 }
361
Alan Coxc78732a2009-10-06 15:49:45 +0100362 etdev->tx_ring.tcb_qhead = tcb->next;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700363
Alan Coxc78732a2009-10-06 15:49:45 +0100364 if (etdev->tx_ring.tcb_qhead == NULL)
365 etdev->tx_ring.tcb_qtail = NULL;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700366
Alan Cox37628602009-08-19 18:21:50 +0100367 spin_unlock_irqrestore(&etdev->TCBReadyQLock, flags);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700368
Alan Coxc78732a2009-10-06 15:49:45 +0100369 tcb->skb = skb;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700370
Alan Cox1458d822009-10-06 15:49:58 +0100371 if (skb->data != NULL && skb->len - skb->data_len >= 6) {
Alan Cox116badf2009-10-06 15:49:21 +0100372 shbufva = (u16 *) skb->data;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700373
Alan Cox9fa81092009-08-27 11:00:36 +0100374 if ((shbufva[0] == 0xffff) &&
375 (shbufva[1] == 0xffff) && (shbufva[2] == 0xffff)) {
Alan Coxc78732a2009-10-06 15:49:45 +0100376 tcb->flags |= fMP_DEST_BROAD;
Alan Cox9fa81092009-08-27 11:00:36 +0100377 } else if ((shbufva[0] & 0x3) == 0x0001) {
Alan Coxc78732a2009-10-06 15:49:45 +0100378 tcb->flags |= fMP_DEST_MULTI;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700379 }
380 }
381
Alan Coxc78732a2009-10-06 15:49:45 +0100382 tcb->next = NULL;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700383
384 /* Call the NIC specific send handler. */
Alan Coxc1996fc2009-10-06 15:49:29 +0100385 status = nic_send_packet(etdev, tcb);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700386
387 if (status != 0) {
Alan Cox37628602009-08-19 18:21:50 +0100388 spin_lock_irqsave(&etdev->TCBReadyQLock, flags);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700389
Alan Cox1458d822009-10-06 15:49:58 +0100390 if (etdev->tx_ring.tcb_qtail)
Alan Coxc78732a2009-10-06 15:49:45 +0100391 etdev->tx_ring.tcb_qtail->next = tcb;
Alan Cox1458d822009-10-06 15:49:58 +0100392 else
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700393 /* Apparently ready Q is empty. */
Alan Coxc78732a2009-10-06 15:49:45 +0100394 etdev->tx_ring.tcb_qhead = tcb;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700395
Alan Coxc78732a2009-10-06 15:49:45 +0100396 etdev->tx_ring.tcb_qtail = tcb;
Alan Cox37628602009-08-19 18:21:50 +0100397 spin_unlock_irqrestore(&etdev->TCBReadyQLock, flags);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700398 return status;
399 }
Alan Coxc78732a2009-10-06 15:49:45 +0100400 WARN_ON(etdev->tx_ring.used > NUM_TCB);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700401 return 0;
402}
403
404/**
405 * nic_send_packet - NIC specific send handler for version B silicon.
Alan Cox25ad00b2009-08-19 18:21:44 +0100406 * @etdev: pointer to our adapter
Alan Coxb711b2e2009-10-06 15:48:33 +0100407 * @tcb: pointer to struct tcb
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700408 *
409 * Returns 0 or errno.
410 */
Alan Coxb711b2e2009-10-06 15:48:33 +0100411static int nic_send_packet(struct et131x_adapter *etdev, struct tcb *tcb)
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700412{
Alan Coxb711b2e2009-10-06 15:48:33 +0100413 u32 i;
414 struct tx_desc desc[24]; /* 24 x 16 byte */
415 u32 frag = 0;
416 u32 thiscopy, remainder;
Alan Coxc78732a2009-10-06 15:49:45 +0100417 struct sk_buff *skb = tcb->skb;
Alan Coxb711b2e2009-10-06 15:48:33 +0100418 u32 nr_frags = skb_shinfo(skb)->nr_frags + 1;
419 struct skb_frag_struct *frags = &skb_shinfo(skb)->frags[0];
Alan Cox37628602009-08-19 18:21:50 +0100420 unsigned long flags;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700421
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700422 /* 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 Coxb711b2e2009-10-06 15:48:33 +0100430 if (nr_frags > 23)
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700431 return -EIO;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700432
Alan Coxb711b2e2009-10-06 15:48:33 +0100433 memset(desc, 0, sizeof(struct tx_desc) * (nr_frags + 1));
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700434
Alan Coxb711b2e2009-10-06 15:48:33 +0100435 for (i = 0; i < nr_frags; i++) {
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700436 /* If there is something in this element, lets get a
437 * descriptor from the ring and get the necessary data
438 */
Alan Coxb711b2e2009-10-06 15:48:33 +0100439 if (i == 0) {
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700440 /* 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 Coxb711b2e2009-10-06 15:48:33 +0100449 if ((skb->len - skb->data_len) <= 1514) {
450 desc[frag].addr_hi = 0;
Alan Coxfb70ed62009-10-06 15:48:25 +0100451 /* Low 16bits are length, high is vlan and
452 unused currently so zero */
Alan Coxb711b2e2009-10-06 15:48:33 +0100453 desc[frag].len_vlan =
454 skb->len - skb->data_len;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700455
456 /* NOTE: Here, the dma_addr_t returned from
457 * pci_map_single() is implicitly cast as a
Alan Coxb711b2e2009-10-06 15:48:33 +0100458 * u32. Although dma_addr_t can be
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700459 * 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 Coxb711b2e2009-10-06 15:48:33 +0100464 desc[frag++].addr_lo =
Alan Cox25ad00b2009-08-19 18:21:44 +0100465 pci_map_single(etdev->pdev,
Alan Coxb711b2e2009-10-06 15:48:33 +0100466 skb->data,
467 skb->len -
468 skb->data_len,
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700469 PCI_DMA_TODEVICE);
470 } else {
Alan Coxb711b2e2009-10-06 15:48:33 +0100471 desc[frag].addr_hi = 0;
472 desc[frag].len_vlan =
473 (skb->len - skb->data_len) / 2;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700474
475 /* NOTE: Here, the dma_addr_t returned from
476 * pci_map_single() is implicitly cast as a
Alan Coxb711b2e2009-10-06 15:48:33 +0100477 * u32. Although dma_addr_t can be
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700478 * 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 Coxb711b2e2009-10-06 15:48:33 +0100483 desc[frag++].addr_lo =
Alan Cox25ad00b2009-08-19 18:21:44 +0100484 pci_map_single(etdev->pdev,
Alan Coxb711b2e2009-10-06 15:48:33 +0100485 skb->data,
486 ((skb->len -
487 skb->data_len) / 2),
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700488 PCI_DMA_TODEVICE);
Alan Coxb711b2e2009-10-06 15:48:33 +0100489 desc[frag].addr_hi = 0;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700490
Alan Coxb711b2e2009-10-06 15:48:33 +0100491 desc[frag].len_vlan =
492 (skb->len - skb->data_len) / 2;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700493
494 /* NOTE: Here, the dma_addr_t returned from
495 * pci_map_single() is implicitly cast as a
Alan Coxb711b2e2009-10-06 15:48:33 +0100496 * u32. Although dma_addr_t can be
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700497 * 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 Coxb711b2e2009-10-06 15:48:33 +0100502 desc[frag++].addr_lo =
Alan Cox25ad00b2009-08-19 18:21:44 +0100503 pci_map_single(etdev->pdev,
Alan Coxb711b2e2009-10-06 15:48:33 +0100504 skb->data +
505 ((skb->len -
506 skb->data_len) / 2),
507 ((skb->len -
508 skb->data_len) / 2),
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700509 PCI_DMA_TODEVICE);
510 }
511 } else {
Alan Coxb711b2e2009-10-06 15:48:33 +0100512 desc[frag].addr_hi = 0;
513 desc[frag].len_vlan =
514 frags[i - 1].size;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700515
516 /* NOTE: Here, the dma_addr_t returned from
Alan Coxb711b2e2009-10-06 15:48:33 +0100517 * pci_map_page() is implicitly cast as a u32.
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700518 * 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 Coxb711b2e2009-10-06 15:48:33 +0100522 desc[frag++].addr_lo =
Alan Cox25ad00b2009-08-19 18:21:44 +0100523 pci_map_page(etdev->pdev,
Alan Coxb711b2e2009-10-06 15:48:33 +0100524 frags[i - 1].page,
525 frags[i - 1].page_offset,
526 frags[i - 1].size,
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700527 PCI_DMA_TODEVICE);
528 }
529 }
530
Alan Coxb711b2e2009-10-06 15:48:33 +0100531 if (frag == 0)
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700532 return -EIO;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700533
Alan Cox9fa81092009-08-27 11:00:36 +0100534 if (etdev->linkspeed == TRUEPHY_SPEED_1000MBPS) {
Alan Cox1458d822009-10-06 15:49:58 +0100535 if (++etdev->tx_ring.since_irq == PARM_TX_NUM_BUFS_DEF) {
536 /* Last element & Interrupt flag */
Alan Coxb711b2e2009-10-06 15:48:33 +0100537 desc[frag - 1].flags = 0x5;
Alan Coxc78732a2009-10-06 15:49:45 +0100538 etdev->tx_ring.since_irq = 0;
Alan Coxb44207a2009-10-06 15:48:16 +0100539 } else { /* Last element */
Alan Coxb711b2e2009-10-06 15:48:33 +0100540 desc[frag - 1].flags = 0x1;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700541 }
Alan Coxc78732a2009-10-06 15:49:45 +0100542 } else
Alan Coxb711b2e2009-10-06 15:48:33 +0100543 desc[frag - 1].flags = 0x5;
Alan Coxc78732a2009-10-06 15:49:45 +0100544
Alan Coxb711b2e2009-10-06 15:48:33 +0100545 desc[0].flags |= 2; /* First element flag */
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700546
Alan Coxc78732a2009-10-06 15:49:45 +0100547 tcb->index_start = etdev->tx_ring.send_idx;
548 tcb->stale = 0;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700549
Alan Cox37628602009-08-19 18:21:50 +0100550 spin_lock_irqsave(&etdev->SendHWLock, flags);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700551
Alan Cox356c74b2009-08-27 11:01:57 +0100552 thiscopy = NUM_DESC_PER_RING_TX -
Alan Coxc78732a2009-10-06 15:49:45 +0100553 INDEX10(etdev->tx_ring.send_idx);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700554
Alan Coxb711b2e2009-10-06 15:48:33 +0100555 if (thiscopy >= frag) {
Alan Cox9fa81092009-08-27 11:00:36 +0100556 remainder = 0;
Alan Coxb711b2e2009-10-06 15:48:33 +0100557 thiscopy = frag;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700558 } else {
Alan Coxb711b2e2009-10-06 15:48:33 +0100559 remainder = frag - thiscopy;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700560 }
561
Alan Coxb711b2e2009-10-06 15:48:33 +0100562 memcpy(etdev->tx_ring.tx_desc_ring +
Alan Coxc78732a2009-10-06 15:49:45 +0100563 INDEX10(etdev->tx_ring.send_idx), desc,
Alan Coxb711b2e2009-10-06 15:48:33 +0100564 sizeof(struct tx_desc) * thiscopy);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700565
Alan Coxc78732a2009-10-06 15:49:45 +0100566 add_10bit(&etdev->tx_ring.send_idx, thiscopy);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700567
Alan Cox1458d822009-10-06 15:49:58 +0100568 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-Hartmancfb739b2008-04-03 17:30:53 -0700572 }
573
Alan Cox9fa81092009-08-27 11:00:36 +0100574 if (remainder) {
Alan Coxb711b2e2009-10-06 15:48:33 +0100575 memcpy(etdev->tx_ring.tx_desc_ring,
576 desc + thiscopy,
577 sizeof(struct tx_desc) * remainder);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700578
Alan Coxc78732a2009-10-06 15:49:45 +0100579 add_10bit(&etdev->tx_ring.send_idx, remainder);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700580 }
581
Alan Coxc78732a2009-10-06 15:49:45 +0100582 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 Cox64f93032009-06-10 17:30:41 +0100585 else
Alan Cox1458d822009-10-06 15:49:58 +0100586 tcb->index = ET_DMA10_WRAP|(NUM_DESC_PER_RING_TX - 1);
Alan Cox64f93032009-06-10 17:30:41 +0100587 } else
Alan Coxc78732a2009-10-06 15:49:45 +0100588 tcb->index = etdev->tx_ring.send_idx - 1;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700589
Alan Cox37628602009-08-19 18:21:50 +0100590 spin_lock(&etdev->TCBSendQLock);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700591
Alan Coxc78732a2009-10-06 15:49:45 +0100592 if (etdev->tx_ring.send_tail)
593 etdev->tx_ring.send_tail->next = tcb;
Alan Cox64f93032009-06-10 17:30:41 +0100594 else
Alan Coxc78732a2009-10-06 15:49:45 +0100595 etdev->tx_ring.send_head = tcb;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700596
Alan Coxc78732a2009-10-06 15:49:45 +0100597 etdev->tx_ring.send_tail = tcb;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700598
Alan Coxc78732a2009-10-06 15:49:45 +0100599 WARN_ON(tcb->next != NULL);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700600
Alan Coxc78732a2009-10-06 15:49:45 +0100601 etdev->tx_ring.used++;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700602
Alan Cox37628602009-08-19 18:21:50 +0100603 spin_unlock(&etdev->TCBSendQLock);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700604
605 /* Write the new write pointer back to the device. */
Alan Coxc78732a2009-10-06 15:49:45 +0100606 writel(etdev->tx_ring.send_idx,
Alan Cox356c74b2009-08-27 11:01:57 +0100607 &etdev->regs->txdma.service_request);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700608
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 Cox9fa81092009-08-27 11:00:36 +0100612 if (etdev->linkspeed == TRUEPHY_SPEED_1000MBPS) {
Alan Coxc2557172009-08-27 10:59:56 +0100613 writel(PARM_TX_TIME_INT_DEF * NANO_IN_A_MICRO,
Alan Coxf3f415a2009-08-27 10:59:30 +0100614 &etdev->regs->global.watchdog_timer);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700615 }
Alan Cox37628602009-08-19 18:21:50 +0100616 spin_unlock_irqrestore(&etdev->SendHWLock, flags);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700617
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700618 return 0;
619}
620
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700621
622/**
Alan Coxb711b2e2009-10-06 15:48:33 +0100623 * et131x_free_send_packet - Recycle a struct tcb
Alan Cox25ad00b2009-08-19 18:21:44 +0100624 * @etdev: pointer to our adapter
Alan Coxb711b2e2009-10-06 15:48:33 +0100625 * @tcb: pointer to struct tcb
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700626 *
Alan Coxb711b2e2009-10-06 15:48:33 +0100627 * Complete the packet if necessary
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700628 * Assumption - Send spinlock has been acquired
629 */
Alan Cox25ad00b2009-08-19 18:21:44 +0100630inline void et131x_free_send_packet(struct et131x_adapter *etdev,
Alan Coxb711b2e2009-10-06 15:48:33 +0100631 struct tcb *tcb)
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700632{
Alan Cox37628602009-08-19 18:21:50 +0100633 unsigned long flags;
Alan Coxb711b2e2009-10-06 15:48:33 +0100634 struct tx_desc *desc = NULL;
Alan Cox25ad00b2009-08-19 18:21:44 +0100635 struct net_device_stats *stats = &etdev->net_stats;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700636
Alan Coxc78732a2009-10-06 15:49:45 +0100637 if (tcb->flags & fMP_DEST_BROAD)
Alan Cox25ad00b2009-08-19 18:21:44 +0100638 atomic_inc(&etdev->Stats.brdcstxmt);
Alan Coxc78732a2009-10-06 15:49:45 +0100639 else if (tcb->flags & fMP_DEST_MULTI)
Alan Cox25ad00b2009-08-19 18:21:44 +0100640 atomic_inc(&etdev->Stats.multixmt);
Alan Cox64f93032009-06-10 17:30:41 +0100641 else
Alan Cox25ad00b2009-08-19 18:21:44 +0100642 atomic_inc(&etdev->Stats.unixmt);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700643
Alan Coxc78732a2009-10-06 15:49:45 +0100644 if (tcb->skb) {
645 stats->tx_bytes += tcb->skb->len;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700646
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-Hartmancfb739b2008-04-03 17:30:53 -0700651 do {
Alan Cox1458d822009-10-06 15:49:58 +0100652 desc = (struct tx_desc *)(etdev->tx_ring.tx_desc_ring +
653 INDEX10(tcb->index_start));
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700654
Alan Cox25ad00b2009-08-19 18:21:44 +0100655 pci_unmap_single(etdev->pdev,
Alan Coxb711b2e2009-10-06 15:48:33 +0100656 desc->addr_lo,
657 desc->len_vlan, PCI_DMA_TODEVICE);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700658
Alan Coxc78732a2009-10-06 15:49:45 +0100659 add_10bit(&tcb->index_start, 1);
660 if (INDEX10(tcb->index_start) >=
Alan Cox1458d822009-10-06 15:49:58 +0100661 NUM_DESC_PER_RING_TX) {
662 tcb->index_start &= ~ET_DMA10_MASK;
663 tcb->index_start ^= ET_DMA10_WRAP;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700664 }
Alan Coxb711b2e2009-10-06 15:48:33 +0100665 } while (desc != (etdev->tx_ring.tx_desc_ring +
Alan Coxc78732a2009-10-06 15:49:45 +0100666 INDEX10(tcb->index)));
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700667
Alan Coxc78732a2009-10-06 15:49:45 +0100668 dev_kfree_skb_any(tcb->skb);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700669 }
670
Alan Coxb711b2e2009-10-06 15:48:33 +0100671 memset(tcb, 0, sizeof(struct tcb));
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700672
673 /* Add the TCB to the Ready Q */
Alan Cox37628602009-08-19 18:21:50 +0100674 spin_lock_irqsave(&etdev->TCBReadyQLock, flags);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700675
Alan Cox25ad00b2009-08-19 18:21:44 +0100676 etdev->Stats.opackets++;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700677
Alan Coxc78732a2009-10-06 15:49:45 +0100678 if (etdev->tx_ring.tcb_qtail)
679 etdev->tx_ring.tcb_qtail->next = tcb;
Alan Coxc1996fc2009-10-06 15:49:29 +0100680 else
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700681 /* Apparently ready Q is empty. */
Alan Coxc78732a2009-10-06 15:49:45 +0100682 etdev->tx_ring.tcb_qhead = tcb;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700683
Alan Coxc78732a2009-10-06 15:49:45 +0100684 etdev->tx_ring.tcb_qtail = tcb;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700685
Alan Cox37628602009-08-19 18:21:50 +0100686 spin_unlock_irqrestore(&etdev->TCBReadyQLock, flags);
Alan Coxc78732a2009-10-06 15:49:45 +0100687 WARN_ON(etdev->tx_ring.used < 0);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700688}
689
690/**
691 * et131x_free_busy_send_packets - Free and complete the stopped active sends
Alan Cox25ad00b2009-08-19 18:21:44 +0100692 * @etdev: pointer to our adapter
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700693 *
694 * Assumption - Send spinlock has been acquired
695 */
Alan Cox25ad00b2009-08-19 18:21:44 +0100696void et131x_free_busy_send_packets(struct et131x_adapter *etdev)
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700697{
Alan Coxb711b2e2009-10-06 15:48:33 +0100698 struct tcb *tcb;
Alan Cox37628602009-08-19 18:21:50 +0100699 unsigned long flags;
Alan Coxb711b2e2009-10-06 15:48:33 +0100700 u32 freed = 0;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700701
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700702 /* Any packets being sent? Check the first TCB on the send list */
Alan Cox37628602009-08-19 18:21:50 +0100703 spin_lock_irqsave(&etdev->TCBSendQLock, flags);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700704
Alan Coxc78732a2009-10-06 15:49:45 +0100705 tcb = etdev->tx_ring.send_head;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700706
Alan Cox1458d822009-10-06 15:49:58 +0100707 while (tcb != NULL && freed < NUM_TCB) {
Alan Coxc78732a2009-10-06 15:49:45 +0100708 struct tcb *next = tcb->next;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700709
Alan Coxc78732a2009-10-06 15:49:45 +0100710 etdev->tx_ring.send_head = next;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700711
Alan Coxc78732a2009-10-06 15:49:45 +0100712 if (next == NULL)
713 etdev->tx_ring.send_tail = NULL;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700714
Alan Coxc78732a2009-10-06 15:49:45 +0100715 etdev->tx_ring.used--;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700716
Alan Cox37628602009-08-19 18:21:50 +0100717 spin_unlock_irqrestore(&etdev->TCBSendQLock, flags);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700718
Alan Coxb711b2e2009-10-06 15:48:33 +0100719 freed++;
720 et131x_free_send_packet(etdev, tcb);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700721
Alan Cox37628602009-08-19 18:21:50 +0100722 spin_lock_irqsave(&etdev->TCBSendQLock, flags);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700723
Alan Coxc78732a2009-10-06 15:49:45 +0100724 tcb = etdev->tx_ring.send_head;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700725 }
726
Alan Coxb711b2e2009-10-06 15:48:33 +0100727 WARN_ON(freed == NUM_TCB);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700728
Alan Cox37628602009-08-19 18:21:50 +0100729 spin_unlock_irqrestore(&etdev->TCBSendQLock, flags);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700730
Alan Coxc78732a2009-10-06 15:49:45 +0100731 etdev->tx_ring.used = 0;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700732}
733
734/**
735 * et131x_handle_send_interrupt - Interrupt handler for sending processing
Alan Cox25ad00b2009-08-19 18:21:44 +0100736 * @etdev: pointer to our adapter
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700737 *
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 Cox25ad00b2009-08-19 18:21:44 +0100743void et131x_handle_send_interrupt(struct et131x_adapter *etdev)
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700744{
Alan Cox37628602009-08-19 18:21:50 +0100745 unsigned long flags;
Alan Coxb711b2e2009-10-06 15:48:33 +0100746 u32 serviced;
Alan Cox1458d822009-10-06 15:49:58 +0100747 struct tcb *tcb;
Alan Cox356c74b2009-08-27 11:01:57 +0100748 u32 index;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700749
Alan Coxb711b2e2009-10-06 15:48:33 +0100750 serviced = readl(&etdev->regs->txdma.NewServiceComplete);
751 index = INDEX10(serviced);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700752
753 /* Has the ring wrapped? Process any descriptors that do not have
754 * the same "wrap" indicator as the current completion indicator
755 */
Alan Cox37628602009-08-19 18:21:50 +0100756 spin_lock_irqsave(&etdev->TCBSendQLock, flags);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700757
Alan Coxc78732a2009-10-06 15:49:45 +0100758 tcb = etdev->tx_ring.send_head;
Alan Cox356c74b2009-08-27 11:01:57 +0100759
Alan Coxb711b2e2009-10-06 15:48:33 +0100760 while (tcb &&
Alan Coxc78732a2009-10-06 15:49:45 +0100761 ((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-Hartmancfb739b2008-04-03 17:30:53 -0700767
Alan Cox37628602009-08-19 18:21:50 +0100768 spin_unlock_irqrestore(&etdev->TCBSendQLock, flags);
Alan Coxb711b2e2009-10-06 15:48:33 +0100769 et131x_free_send_packet(etdev, tcb);
Alan Cox37628602009-08-19 18:21:50 +0100770 spin_lock_irqsave(&etdev->TCBSendQLock, flags);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700771
772 /* Goto the next packet */
Alan Coxc78732a2009-10-06 15:49:45 +0100773 tcb = etdev->tx_ring.send_head;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700774 }
Alan Coxb711b2e2009-10-06 15:48:33 +0100775 while (tcb &&
Alan Coxc78732a2009-10-06 15:49:45 +0100776 !((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-Hartmancfb739b2008-04-03 17:30:53 -0700782
Alan Cox37628602009-08-19 18:21:50 +0100783 spin_unlock_irqrestore(&etdev->TCBSendQLock, flags);
Alan Coxb711b2e2009-10-06 15:48:33 +0100784 et131x_free_send_packet(etdev, tcb);
Alan Cox37628602009-08-19 18:21:50 +0100785 spin_lock_irqsave(&etdev->TCBSendQLock, flags);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700786
787 /* Goto the next packet */
Alan Coxc78732a2009-10-06 15:49:45 +0100788 tcb = etdev->tx_ring.send_head;
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700789 }
790
791 /* Wake up the queue when we hit a low-water mark */
Alan Cox1458d822009-10-06 15:49:58 +0100792 if (etdev->tx_ring.used <= NUM_TCB / 3)
Alan Cox25ad00b2009-08-19 18:21:44 +0100793 netif_wake_queue(etdev->netdev);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700794
Alan Cox37628602009-08-19 18:21:50 +0100795 spin_unlock_irqrestore(&etdev->TCBSendQLock, flags);
Greg Kroah-Hartmancfb739b2008-04-03 17:30:53 -0700796}
797