3 * 10/100/1000 Base-T Ethernet Driver for the ET1301 and ET131x series MACs
5 * Copyright © 2005 Agere Systems Inc.
9 *------------------------------------------------------------------------------
11 * et1310_tx.c - Routines used to perform data transmission.
13 *------------------------------------------------------------------------------
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.
22 * Copyright © 2005 Agere Systems Inc.
23 * All rights reserved.
25 * Redistribution and use in source or binary forms, with or without
26 * modifications, are permitted provided that the following conditions are met:
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
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.
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.
43 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
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
58 #include "et131x_version.h"
59 #include "et131x_debug.h"
60 #include "et131x_defs.h"
62 #include <linux/pci.h>
63 #include <linux/init.h>
64 #include <linux/module.h>
65 #include <linux/types.h>
66 #include <linux/kernel.h>
68 #include <linux/sched.h>
69 #include <linux/ptrace.h>
70 #include <linux/slab.h>
71 #include <linux/ctype.h>
72 #include <linux/string.h>
73 #include <linux/timer.h>
74 #include <linux/interrupt.h>
76 #include <linux/delay.h>
78 #include <linux/bitops.h>
79 #include <asm/system.h>
81 #include <linux/netdevice.h>
82 #include <linux/etherdevice.h>
83 #include <linux/skbuff.h>
84 #include <linux/if_arp.h>
85 #include <linux/ioport.h>
87 #include "et1310_phy.h"
88 #include "et1310_pm.h"
89 #include "et1310_jagcore.h"
91 #include "et131x_adapter.h"
92 #include "et131x_initpci.h"
93 #include "et131x_isr.h"
95 #include "et1310_tx.h"
97 /* Data for debugging facilities */
98 #ifdef CONFIG_ET131X_DEBUG
99 extern dbg_info_t
*et131x_dbginfo
;
100 #endif /* CONFIG_ET131X_DEBUG */
102 static void et131x_update_tcb_list(struct et131x_adapter
*etdev
);
103 static void et131x_check_send_wait_list(struct et131x_adapter
*etdev
);
104 static inline void et131x_free_send_packet(struct et131x_adapter
*etdev
,
106 static int et131x_send_packet(struct sk_buff
*skb
,
107 struct et131x_adapter
*etdev
);
108 static int nic_send_packet(struct et131x_adapter
*etdev
, PMP_TCB pMpTcb
);
111 * et131x_tx_dma_memory_alloc
112 * @adapter: pointer to our private adapter structure
114 * Returns 0 on success and errno on failure (as defined in errno.h).
116 * Allocates memory that will be visible both to the device and to the CPU.
117 * The OS will pass us packets, pointers to which we will insert in the Tx
118 * Descriptor queue. The device will read this queue to find the packets in
119 * memory. The device will update the "status" in memory each time it xmits a
122 int et131x_tx_dma_memory_alloc(struct et131x_adapter
*adapter
)
125 TX_RING_t
*tx_ring
= &adapter
->TxRing
;
127 DBG_ENTER(et131x_dbginfo
);
129 /* Allocate memory for the TCB's (Transmit Control Block) */
130 adapter
->TxRing
.MpTcbMem
= (MP_TCB
*)kcalloc(NUM_TCB
, sizeof(MP_TCB
),
131 GFP_ATOMIC
| GFP_DMA
);
132 if (!adapter
->TxRing
.MpTcbMem
) {
133 DBG_ERROR(et131x_dbginfo
, "Cannot alloc memory for TCBs\n");
134 DBG_LEAVE(et131x_dbginfo
);
138 /* Allocate enough memory for the Tx descriptor ring, and allocate
139 * some extra so that the ring can be aligned on a 4k boundary.
141 desc_size
= (sizeof(TX_DESC_ENTRY_t
) * NUM_DESC_PER_RING_TX
) + 4096 - 1;
142 tx_ring
->pTxDescRingVa
=
143 (PTX_DESC_ENTRY_t
) pci_alloc_consistent(adapter
->pdev
, desc_size
,
144 &tx_ring
->pTxDescRingPa
);
145 if (!adapter
->TxRing
.pTxDescRingVa
) {
146 DBG_ERROR(et131x_dbginfo
, "Cannot alloc memory for Tx Ring\n");
147 DBG_LEAVE(et131x_dbginfo
);
151 /* Save physical address
153 * NOTE: pci_alloc_consistent(), used above to alloc DMA regions,
154 * ALWAYS returns SAC (32-bit) addresses. If DAC (64-bit) addresses
155 * are ever returned, make sure the high part is retrieved here before
156 * storing the adjusted address.
158 tx_ring
->pTxDescRingAdjustedPa
= tx_ring
->pTxDescRingPa
;
160 /* Align Tx Descriptor Ring on a 4k (0x1000) byte boundary */
161 et131x_align_allocated_memory(adapter
,
162 &tx_ring
->pTxDescRingAdjustedPa
,
163 &tx_ring
->TxDescOffset
, 0x0FFF);
165 tx_ring
->pTxDescRingVa
+= tx_ring
->TxDescOffset
;
167 /* Allocate memory for the Tx status block */
168 tx_ring
->pTxStatusVa
= pci_alloc_consistent(adapter
->pdev
,
169 sizeof(TX_STATUS_BLOCK_t
),
170 &tx_ring
->pTxStatusPa
);
171 if (!adapter
->TxRing
.pTxStatusPa
) {
172 DBG_ERROR(et131x_dbginfo
,
173 "Cannot alloc memory for Tx status block\n");
174 DBG_LEAVE(et131x_dbginfo
);
178 /* Allocate memory for a dummy buffer */
179 tx_ring
->pTxDummyBlkVa
= pci_alloc_consistent(adapter
->pdev
,
181 &tx_ring
->pTxDummyBlkPa
);
182 if (!adapter
->TxRing
.pTxDummyBlkPa
) {
183 DBG_ERROR(et131x_dbginfo
,
184 "Cannot alloc memory for Tx dummy buffer\n");
185 DBG_LEAVE(et131x_dbginfo
);
189 DBG_LEAVE(et131x_dbginfo
);
194 * et131x_tx_dma_memory_free - Free all memory allocated within this module
195 * @adapter: pointer to our private adapter structure
197 * Returns 0 on success and errno on failure (as defined in errno.h).
199 void et131x_tx_dma_memory_free(struct et131x_adapter
*adapter
)
203 DBG_ENTER(et131x_dbginfo
);
205 if (adapter
->TxRing
.pTxDescRingVa
) {
206 /* Free memory relating to Tx rings here */
207 adapter
->TxRing
.pTxDescRingVa
-= adapter
->TxRing
.TxDescOffset
;
210 (sizeof(TX_DESC_ENTRY_t
) * NUM_DESC_PER_RING_TX
) + 4096 - 1;
212 pci_free_consistent(adapter
->pdev
,
214 adapter
->TxRing
.pTxDescRingVa
,
215 adapter
->TxRing
.pTxDescRingPa
);
217 adapter
->TxRing
.pTxDescRingVa
= NULL
;
220 /* Free memory for the Tx status block */
221 if (adapter
->TxRing
.pTxStatusVa
) {
222 pci_free_consistent(adapter
->pdev
,
223 sizeof(TX_STATUS_BLOCK_t
),
224 adapter
->TxRing
.pTxStatusVa
,
225 adapter
->TxRing
.pTxStatusPa
);
227 adapter
->TxRing
.pTxStatusVa
= NULL
;
230 /* Free memory for the dummy buffer */
231 if (adapter
->TxRing
.pTxDummyBlkVa
) {
232 pci_free_consistent(adapter
->pdev
,
234 adapter
->TxRing
.pTxDummyBlkVa
,
235 adapter
->TxRing
.pTxDummyBlkPa
);
237 adapter
->TxRing
.pTxDummyBlkVa
= NULL
;
240 /* Free the memory for MP_TCB structures */
241 kfree(adapter
->TxRing
.MpTcbMem
);
243 DBG_LEAVE(et131x_dbginfo
);
247 * ConfigTxDmaRegs - Set up the tx dma section of the JAGCore.
248 * @adapter: pointer to our private adapter structure
250 void ConfigTxDmaRegs(struct et131x_adapter
*etdev
)
252 struct _TXDMA_t __iomem
*pTxDma
= &etdev
->regs
->txdma
;
254 DBG_ENTER(et131x_dbginfo
);
256 /* Load the hardware with the start of the transmit descriptor ring. */
257 writel((uint32_t) (etdev
->TxRing
.pTxDescRingAdjustedPa
>> 32),
258 &pTxDma
->pr_base_hi
);
259 writel((uint32_t) etdev
->TxRing
.pTxDescRingAdjustedPa
,
260 &pTxDma
->pr_base_lo
);
262 /* Initialise the transmit DMA engine */
263 writel(NUM_DESC_PER_RING_TX
- 1, &pTxDma
->pr_num_des
.value
);
265 /* Load the completion writeback physical address
267 * NOTE: pci_alloc_consistent(), used above to alloc DMA regions,
268 * ALWAYS returns SAC (32-bit) addresses. If DAC (64-bit) addresses
269 * are ever returned, make sure the high part is retrieved here before
270 * storing the adjusted address.
272 writel(0, &pTxDma
->dma_wb_base_hi
);
273 writel(etdev
->TxRing
.pTxStatusPa
, &pTxDma
->dma_wb_base_lo
);
275 memset(etdev
->TxRing
.pTxStatusVa
, 0, sizeof(TX_STATUS_BLOCK_t
));
277 writel(0, &pTxDma
->service_request
.value
);
278 etdev
->TxRing
.txDmaReadyToSend
.value
= 0;
280 DBG_LEAVE(et131x_dbginfo
);
284 * et131x_tx_dma_disable - Stop of Tx_DMA on the ET1310
285 * @etdev: pointer to our adapter structure
287 void et131x_tx_dma_disable(struct et131x_adapter
*etdev
)
289 DBG_ENTER(et131x_dbginfo
);
291 /* Setup the tramsmit dma configuration register */
292 writel(0x101, &etdev
->regs
->txdma
.csr
.value
);
294 DBG_LEAVE(et131x_dbginfo
);
298 * et131x_tx_dma_enable - re-start of Tx_DMA on the ET1310.
299 * @etdev: pointer to our adapter structure
301 * Mainly used after a return to the D0 (full-power) state from a lower state.
303 void et131x_tx_dma_enable(struct et131x_adapter
*etdev
)
305 DBG_ENTER(et131x_dbginfo
);
307 if (etdev
->RegistryPhyLoopbk
) {
308 /* TxDMA is disabled for loopback operation. */
309 writel(0x101, &etdev
->regs
->txdma
.csr
.value
);
311 TXDMA_CSR_t csr
= { 0 };
313 /* Setup the transmit dma configuration register for normal
316 csr
.bits
.sngl_epkt_mode
= 1;
318 csr
.bits
.cache_thrshld
= PARM_DMA_CACHE_DEF
;
319 writel(csr
.value
, &etdev
->regs
->txdma
.csr
.value
);
322 DBG_LEAVE(et131x_dbginfo
);
326 * et131x_init_send - Initialize send data structures
327 * @adapter: pointer to our private adapter structure
329 void et131x_init_send(struct et131x_adapter
*adapter
)
335 DBG_ENTER(et131x_dbginfo
);
337 /* Setup some convenience pointers */
338 tx_ring
= &adapter
->TxRing
;
339 pMpTcb
= adapter
->TxRing
.MpTcbMem
;
341 tx_ring
->TCBReadyQueueHead
= pMpTcb
;
343 /* Go through and set up each TCB */
344 for (TcbCount
= 0; TcbCount
< NUM_TCB
; TcbCount
++) {
345 memset(pMpTcb
, 0, sizeof(MP_TCB
));
347 /* Set the link pointer in HW TCB to the next TCB in the
348 * chain. If this is the last TCB in the chain, also set the
351 if (TcbCount
< NUM_TCB
- 1) {
352 pMpTcb
->Next
= pMpTcb
+ 1;
354 tx_ring
->TCBReadyQueueTail
= pMpTcb
;
355 pMpTcb
->Next
= (PMP_TCB
) NULL
;
361 /* Curr send queue should now be empty */
362 tx_ring
->CurrSendHead
= (PMP_TCB
) NULL
;
363 tx_ring
->CurrSendTail
= (PMP_TCB
) NULL
;
365 INIT_LIST_HEAD(&adapter
->TxRing
.SendWaitQueue
);
367 DBG_LEAVE(et131x_dbginfo
);
371 * et131x_send_packets - This function is called by the OS to send packets
372 * @skb: the packet(s) to send
373 * @netdev:device on which to TX the above packet(s)
375 * Return 0 in almost all cases; non-zero value in extreme hard failure only
377 int et131x_send_packets(struct sk_buff
*skb
, struct net_device
*netdev
)
380 struct et131x_adapter
*etdev
= NULL
;
382 DBG_TX_ENTER(et131x_dbginfo
);
384 etdev
= netdev_priv(netdev
);
386 /* Send these packets
388 * NOTE: The Linux Tx entry point is only given one packet at a time
389 * to Tx, so the PacketCount and it's array used makes no sense here
392 /* Queue is not empty or TCB is not available */
393 if (!list_empty(&etdev
->TxRing
.SendWaitQueue
) ||
394 MP_TCB_RESOURCES_NOT_AVAILABLE(etdev
)) {
395 /* NOTE: If there's an error on send, no need to queue the
396 * packet under Linux; if we just send an error up to the
397 * netif layer, it will resend the skb to us.
399 DBG_VERBOSE(et131x_dbginfo
, "TCB Resources Not Available\n");
402 /* We need to see if the link is up; if it's not, make the
403 * netif layer think we're good and drop the packet
406 * if( MP_SHOULD_FAIL_SEND( etdev ) ||
407 * etdev->DriverNoPhyAccess )
409 if (MP_SHOULD_FAIL_SEND(etdev
) || etdev
->DriverNoPhyAccess
410 || !netif_carrier_ok(netdev
)) {
411 DBG_VERBOSE(et131x_dbginfo
,
412 "Can't Tx, Link is DOWN; drop the packet\n");
414 dev_kfree_skb_any(skb
);
417 etdev
->net_stats
.tx_dropped
++;
419 status
= et131x_send_packet(skb
, etdev
);
421 if (status
== -ENOMEM
) {
423 /* NOTE: If there's an error on send, no need
424 * to queue the packet under Linux; if we just
425 * send an error up to the netif layer, it
426 * will resend the skb to us.
428 DBG_WARNING(et131x_dbginfo
,
429 "Resources problem, Queue tx packet\n");
430 } else if (status
!= 0) {
431 /* On any other error, make netif think we're
432 * OK and drop the packet
434 DBG_WARNING(et131x_dbginfo
,
435 "General error, drop packet\n");
437 dev_kfree_skb_any(skb
);
440 etdev
->net_stats
.tx_dropped
++;
445 DBG_TX_LEAVE(et131x_dbginfo
);
450 * et131x_send_packet - Do the work to send a packet
451 * @skb: the packet(s) to send
452 * @etdev: a pointer to the device's private adapter structure
454 * Return 0 in almost all cases; non-zero value in extreme hard failure only.
456 * Assumption: Send spinlock has been acquired
458 static int et131x_send_packet(struct sk_buff
*skb
,
459 struct et131x_adapter
*etdev
)
462 PMP_TCB pMpTcb
= NULL
;
466 DBG_TX_ENTER(et131x_dbginfo
);
468 /* Is our buffer scattered, or continuous? */
469 if (skb_shinfo(skb
)->nr_frags
== 0) {
470 DBG_TX(et131x_dbginfo
, "Scattered buffer: NO\n");
472 DBG_TX(et131x_dbginfo
, "Scattered buffer: YES, Num Frags: %d\n",
473 skb_shinfo(skb
)->nr_frags
);
476 /* All packets must have at least a MAC address and a protocol type */
477 if (skb
->len
< ETH_HLEN
) {
478 DBG_ERROR(et131x_dbginfo
,
479 "Packet size < ETH_HLEN (14 bytes)\n");
480 DBG_LEAVE(et131x_dbginfo
);
484 /* Get a TCB for this packet */
485 spin_lock_irqsave(&etdev
->TCBReadyQLock
, flags
);
487 pMpTcb
= etdev
->TxRing
.TCBReadyQueueHead
;
489 if (pMpTcb
== NULL
) {
490 spin_unlock_irqrestore(&etdev
->TCBReadyQLock
, flags
);
492 DBG_WARNING(et131x_dbginfo
, "Can't obtain a TCB\n");
493 DBG_TX_LEAVE(et131x_dbginfo
);
497 etdev
->TxRing
.TCBReadyQueueHead
= pMpTcb
->Next
;
499 if (etdev
->TxRing
.TCBReadyQueueHead
== NULL
)
500 etdev
->TxRing
.TCBReadyQueueTail
= NULL
;
502 spin_unlock_irqrestore(&etdev
->TCBReadyQLock
, flags
);
504 pMpTcb
->PacketLength
= skb
->len
;
505 pMpTcb
->Packet
= skb
;
507 if ((skb
->data
!= NULL
) && ((skb
->len
- skb
->data_len
) >= 6)) {
508 pShBufVa
= (uint16_t *) skb
->data
;
510 if ((pShBufVa
[0] == 0xffff) &&
511 (pShBufVa
[1] == 0xffff) && (pShBufVa
[2] == 0xffff)) {
512 MP_SET_FLAG(pMpTcb
, fMP_DEST_BROAD
);
513 } else if ((pShBufVa
[0] & 0x3) == 0x0001) {
514 MP_SET_FLAG(pMpTcb
, fMP_DEST_MULTI
);
520 /* Call the NIC specific send handler. */
522 status
= nic_send_packet(etdev
, pMpTcb
);
525 spin_lock_irqsave(&etdev
->TCBReadyQLock
, flags
);
527 if (etdev
->TxRing
.TCBReadyQueueTail
) {
528 etdev
->TxRing
.TCBReadyQueueTail
->Next
= pMpTcb
;
530 /* Apparently ready Q is empty. */
531 etdev
->TxRing
.TCBReadyQueueHead
= pMpTcb
;
534 etdev
->TxRing
.TCBReadyQueueTail
= pMpTcb
;
536 spin_unlock_irqrestore(&etdev
->TCBReadyQLock
, flags
);
538 DBG_TX_LEAVE(et131x_dbginfo
);
542 DBG_ASSERT(etdev
->TxRing
.nBusySend
<= NUM_TCB
);
544 DBG_TX_LEAVE(et131x_dbginfo
);
549 * nic_send_packet - NIC specific send handler for version B silicon.
550 * @etdev: pointer to our adapter
551 * @pMpTcb: pointer to MP_TCB
553 * Returns 0 or errno.
555 static int nic_send_packet(struct et131x_adapter
*etdev
, PMP_TCB pMpTcb
)
558 TX_DESC_ENTRY_t CurDesc
[24];
559 uint32_t FragmentNumber
= 0;
560 uint32_t iThisCopy
, iRemainder
;
561 struct sk_buff
*pPacket
= pMpTcb
->Packet
;
562 uint32_t FragListCount
= skb_shinfo(pPacket
)->nr_frags
+ 1;
563 struct skb_frag_struct
*pFragList
= &skb_shinfo(pPacket
)->frags
[0];
566 DBG_TX_ENTER(et131x_dbginfo
);
568 /* Part of the optimizations of this send routine restrict us to
569 * sending 24 fragments at a pass. In practice we should never see
570 * more than 5 fragments.
572 * NOTE: The older version of this function (below) can handle any
573 * number of fragments. If needed, we can call this function,
574 * although it is less efficient.
576 if (FragListCount
> 23) {
577 DBG_TX_LEAVE(et131x_dbginfo
);
581 memset(CurDesc
, 0, sizeof(TX_DESC_ENTRY_t
) * (FragListCount
+ 1));
583 for (loopIndex
= 0; loopIndex
< FragListCount
; loopIndex
++) {
584 /* If there is something in this element, lets get a
585 * descriptor from the ring and get the necessary data
587 if (loopIndex
== 0) {
588 /* If the fragments are smaller than a standard MTU,
589 * then map them to a single descriptor in the Tx
590 * Desc ring. However, if they're larger, as is
591 * possible with support for jumbo packets, then
592 * split them each across 2 descriptors.
594 * This will work until we determine why the hardware
595 * doesn't seem to like large fragments.
597 if ((pPacket
->len
- pPacket
->data_len
) <= 1514) {
598 DBG_TX(et131x_dbginfo
,
599 "Got packet of length %d, "
600 "filling desc entry %d, "
602 (pPacket
->len
- pPacket
->data_len
),
603 etdev
->TxRing
.txDmaReadyToSend
.bits
.
606 CurDesc
[FragmentNumber
].DataBufferPtrHigh
= 0;
608 CurDesc
[FragmentNumber
].word2
.bits
.
610 pPacket
->len
- pPacket
->data_len
;
612 /* NOTE: Here, the dma_addr_t returned from
613 * pci_map_single() is implicitly cast as a
614 * uint32_t. Although dma_addr_t can be
615 * 64-bit, the address returned by
616 * pci_map_single() is always 32-bit
617 * addressable (as defined by the pci/dma
620 CurDesc
[FragmentNumber
++].DataBufferPtrLow
=
621 pci_map_single(etdev
->pdev
,
627 DBG_TX(et131x_dbginfo
,
628 "Got packet of length %d, "
629 "filling desc entry %d, "
631 (pPacket
->len
- pPacket
->data_len
),
632 etdev
->TxRing
.txDmaReadyToSend
.bits
.
635 CurDesc
[FragmentNumber
].DataBufferPtrHigh
= 0;
637 CurDesc
[FragmentNumber
].word2
.bits
.
639 ((pPacket
->len
- pPacket
->data_len
) / 2);
641 /* NOTE: Here, the dma_addr_t returned from
642 * pci_map_single() is implicitly cast as a
643 * uint32_t. Although dma_addr_t can be
644 * 64-bit, the address returned by
645 * pci_map_single() is always 32-bit
646 * addressable (as defined by the pci/dma
649 CurDesc
[FragmentNumber
++].DataBufferPtrLow
=
650 pci_map_single(etdev
->pdev
,
653 pPacket
->data_len
) / 2),
655 CurDesc
[FragmentNumber
].DataBufferPtrHigh
= 0;
657 CurDesc
[FragmentNumber
].word2
.bits
.
659 ((pPacket
->len
- pPacket
->data_len
) / 2);
661 /* NOTE: Here, the dma_addr_t returned from
662 * pci_map_single() is implicitly cast as a
663 * uint32_t. Although dma_addr_t can be
664 * 64-bit, the address returned by
665 * pci_map_single() is always 32-bit
666 * addressable (as defined by the pci/dma
669 CurDesc
[FragmentNumber
++].DataBufferPtrLow
=
670 pci_map_single(etdev
->pdev
,
673 pPacket
->data_len
) / 2),
675 pPacket
->data_len
) / 2),
679 DBG_TX(et131x_dbginfo
,
680 "Got packet of length %d,"
681 "filling desc entry %d\n"
683 pFragList
[loopIndex
].size
,
684 etdev
->TxRing
.txDmaReadyToSend
.bits
.val
,
687 CurDesc
[FragmentNumber
].DataBufferPtrHigh
= 0;
689 CurDesc
[FragmentNumber
].word2
.bits
.length_in_bytes
=
690 pFragList
[loopIndex
- 1].size
;
692 /* NOTE: Here, the dma_addr_t returned from
693 * pci_map_page() is implicitly cast as a uint32_t.
694 * Although dma_addr_t can be 64-bit, the address
695 * returned by pci_map_page() is always 32-bit
696 * addressable (as defined by the pci/dma subsystem)
698 CurDesc
[FragmentNumber
++].DataBufferPtrLow
=
699 pci_map_page(etdev
->pdev
,
700 pFragList
[loopIndex
- 1].page
,
701 pFragList
[loopIndex
- 1].page_offset
,
702 pFragList
[loopIndex
- 1].size
,
707 if (FragmentNumber
== 0) {
708 DBG_WARNING(et131x_dbginfo
, "No. frags is 0\n");
712 if (etdev
->uiLinkSpeed
== TRUEPHY_SPEED_1000MBPS
) {
713 if (++etdev
->TxRing
.TxPacketsSinceLastinterrupt
==
714 etdev
->RegistryTxNumBuffers
) {
715 CurDesc
[FragmentNumber
- 1].word3
.value
= 0x5;
716 etdev
->TxRing
.TxPacketsSinceLastinterrupt
= 0;
718 CurDesc
[FragmentNumber
- 1].word3
.value
= 0x1;
721 CurDesc
[FragmentNumber
- 1].word3
.value
= 0x5;
724 CurDesc
[0].word3
.bits
.f
= 1;
726 pMpTcb
->WrIndexStart
= etdev
->TxRing
.txDmaReadyToSend
;
727 pMpTcb
->PacketStaleCount
= 0;
729 spin_lock_irqsave(&etdev
->SendHWLock
, flags
);
732 NUM_DESC_PER_RING_TX
- etdev
->TxRing
.txDmaReadyToSend
.bits
.val
;
734 if (iThisCopy
>= FragmentNumber
) {
736 iThisCopy
= FragmentNumber
;
738 iRemainder
= FragmentNumber
- iThisCopy
;
741 memcpy(etdev
->TxRing
.pTxDescRingVa
+
742 etdev
->TxRing
.txDmaReadyToSend
.bits
.val
, CurDesc
,
743 sizeof(TX_DESC_ENTRY_t
) * iThisCopy
);
745 etdev
->TxRing
.txDmaReadyToSend
.bits
.val
+= iThisCopy
;
747 if ((etdev
->TxRing
.txDmaReadyToSend
.bits
.val
== 0) ||
748 (etdev
->TxRing
.txDmaReadyToSend
.bits
.val
==
749 NUM_DESC_PER_RING_TX
)) {
750 if (etdev
->TxRing
.txDmaReadyToSend
.bits
.wrap
)
751 etdev
->TxRing
.txDmaReadyToSend
.value
= 0;
753 etdev
->TxRing
.txDmaReadyToSend
.value
= 0x400;
757 memcpy(etdev
->TxRing
.pTxDescRingVa
,
759 sizeof(TX_DESC_ENTRY_t
) * iRemainder
);
761 etdev
->TxRing
.txDmaReadyToSend
.bits
.val
+= iRemainder
;
764 if (etdev
->TxRing
.txDmaReadyToSend
.bits
.val
== 0) {
765 if (etdev
->TxRing
.txDmaReadyToSend
.value
)
766 pMpTcb
->WrIndex
.value
= NUM_DESC_PER_RING_TX
- 1;
768 pMpTcb
->WrIndex
.value
=
769 0x400 | (NUM_DESC_PER_RING_TX
- 1);
771 pMpTcb
->WrIndex
.value
=
772 etdev
->TxRing
.txDmaReadyToSend
.value
- 1;
774 spin_lock(&etdev
->TCBSendQLock
);
776 if (etdev
->TxRing
.CurrSendTail
)
777 etdev
->TxRing
.CurrSendTail
->Next
= pMpTcb
;
779 etdev
->TxRing
.CurrSendHead
= pMpTcb
;
781 etdev
->TxRing
.CurrSendTail
= pMpTcb
;
783 DBG_ASSERT(pMpTcb
->Next
== NULL
);
785 etdev
->TxRing
.nBusySend
++;
787 spin_unlock(&etdev
->TCBSendQLock
);
789 /* Write the new write pointer back to the device. */
790 writel(etdev
->TxRing
.txDmaReadyToSend
.value
,
791 &etdev
->regs
->txdma
.service_request
.value
);
793 /* For Gig only, we use Tx Interrupt coalescing. Enable the software
794 * timer to wake us up if this packet isn't followed by N more.
796 if (etdev
->uiLinkSpeed
== TRUEPHY_SPEED_1000MBPS
) {
797 writel(etdev
->RegistryTxTimeInterval
* NANO_IN_A_MICRO
,
798 &etdev
->regs
->global
.watchdog_timer
);
801 spin_unlock_irqrestore(&etdev
->SendHWLock
, flags
);
803 DBG_TX_LEAVE(et131x_dbginfo
);
808 * NOTE: For now, keep this older version of NICSendPacket around for
809 * reference, even though it's not used
814 * NICSendPacket - NIC specific send handler.
815 * @etdev: pointer to our adapter
816 * @pMpTcb: pointer to MP_TCB
818 * Returns 0 on succes, errno on failure.
820 * This version of the send routine is designed for version A silicon.
821 * Assumption - Send spinlock has been acquired.
823 static int nic_send_packet(struct et131x_adapter
*etdev
, PMP_TCB pMpTcb
)
825 uint32_t loopIndex
, fragIndex
, loopEnd
;
826 uint32_t iSplitFirstElement
= 0;
827 uint32_t SegmentSize
= 0;
828 TX_DESC_ENTRY_t CurDesc
;
829 TX_DESC_ENTRY_t
*CurDescPostCopy
= NULL
;
830 uint32_t SlotsAvailable
;
831 DMA10W_t ServiceComplete
;
833 struct sk_buff
*pPacket
= pMpTcb
->Packet
;
834 uint32_t FragListCount
= skb_shinfo(pPacket
)->nr_frags
+ 1;
835 struct skb_frag_struct
*pFragList
= &skb_shinfo(pPacket
)->frags
[0];
837 DBG_TX_ENTER(et131x_dbginfo
);
839 ServiceComplete
.value
=
840 readl(&etdev
->regs
->txdma
.NewServiceComplete
.value
);
843 * Attempt to fix TWO hardware bugs:
844 * 1) NEVER write an odd number of descriptors.
845 * 2) If packet length is less than NIC_MIN_PACKET_SIZE, then pad the
846 * packet to NIC_MIN_PACKET_SIZE bytes by adding a new last
847 * descriptor IN HALF DUPLEX MODE ONLY
848 * NOTE that (2) interacts with (1). If the packet is less than
849 * NIC_MIN_PACKET_SIZE bytes then we will append a descriptor.
850 * Therefore if it is even now, it will eventually end up odd, and
851 * so will need adjusting.
853 * VLAN tags get involved since VLAN tags add another one or two
856 DBG_TX(et131x_dbginfo
,
857 "pMpTcb->PacketLength: %d\n", pMpTcb
->PacketLength
);
859 if ((etdev
->uiDuplexMode
== 0)
860 && (pMpTcb
->PacketLength
< NIC_MIN_PACKET_SIZE
)) {
861 DBG_TX(et131x_dbginfo
,
862 "HALF DUPLEX mode AND len < MIN_PKT_SIZE\n");
863 if ((FragListCount
& 0x1) == 0) {
864 DBG_TX(et131x_dbginfo
,
865 "Even number of descs, split 1st elem\n");
866 iSplitFirstElement
= 1;
867 /* SegmentSize = pFragList[0].size / 2; */
868 SegmentSize
= (pPacket
->len
- pPacket
->data_len
) / 2;
870 } else if (FragListCount
& 0x1) {
871 DBG_TX(et131x_dbginfo
, "Odd number of descs, split 1st elem\n");
873 iSplitFirstElement
= 1;
874 /* SegmentSize = pFragList[0].size / 2; */
875 SegmentSize
= (pPacket
->len
- pPacket
->data_len
) / 2;
878 spin_lock_irqsave(&etdev
->SendHWLock
, flags
);
880 if (etdev
->TxRing
.txDmaReadyToSend
.bits
.serv_req_wrap
==
881 ServiceComplete
.bits
.serv_cpl_wrap
) {
882 /* The ring hasn't wrapped. Slots available should be
883 * (RING_SIZE) - the difference between the two pointers.
885 SlotsAvailable
= NUM_DESC_PER_RING_TX
-
886 (etdev
->TxRing
.txDmaReadyToSend
.bits
.serv_req
-
887 ServiceComplete
.bits
.serv_cpl
);
889 /* The ring has wrapped. Slots available should be the
890 * difference between the two pointers.
892 SlotsAvailable
= ServiceComplete
.bits
.serv_cpl
-
893 etdev
->TxRing
.txDmaReadyToSend
.bits
.serv_req
;
896 if ((FragListCount
+ iSplitFirstElement
) > SlotsAvailable
) {
897 DBG_WARNING(et131x_dbginfo
,
898 "Not Enough Space in Tx Desc Ring\n");
899 spin_unlock_irqrestore(&etdev
->SendHWLock
, flags
);
903 loopEnd
= (FragListCount
) + iSplitFirstElement
;
906 DBG_TX(et131x_dbginfo
,
908 "Packet (SKB) : 0x%p\t Packet->len: %d\t Packet->data_len: %d\n"
909 "FragListCount : %d\t iSplitFirstElement: %d\t loopEnd:%d\n",
911 pPacket
, pPacket
->len
, pPacket
->data_len
,
912 FragListCount
, iSplitFirstElement
, loopEnd
);
914 for (loopIndex
= 0; loopIndex
< loopEnd
; loopIndex
++) {
915 if (loopIndex
> iSplitFirstElement
)
918 DBG_TX(et131x_dbginfo
,
919 "In loop, loopIndex: %d\t fragIndex: %d\n", loopIndex
,
922 /* If there is something in this element, let's get a
923 * descriptor from the ring and get the necessary data
925 DBG_TX(et131x_dbginfo
,
927 "filling desc entry %d\n",
929 etdev
->TxRing
.txDmaReadyToSend
.bits
.serv_req
);
932 * NOTE - Should we do a paranoia check here to make sure the fragment
933 * actually has a length? It's HIGHLY unlikely the fragment would
937 /* NOTE - Currently always getting 32-bit addrs, and
938 * dma_addr_t is only 32-bit, so leave "high" ptr
940 * CurDesc.DataBufferPtrHigh = 0;
943 CurDesc
.word2
.value
= 0;
944 CurDesc
.word3
.value
= 0;
946 if (fragIndex
== 0) {
947 if (iSplitFirstElement
) {
948 DBG_TX(et131x_dbginfo
,
949 "Split first element: YES\n");
951 if (loopIndex
== 0) {
952 DBG_TX(et131x_dbginfo
,
953 "Got fragment of length %d, fragIndex: %d\n",
957 DBG_TX(et131x_dbginfo
,
964 CurDesc
.DataBufferPtrLow
=
965 pci_map_single(etdev
->
971 DBG_TX(et131x_dbginfo
,
972 "pci_map_single() returns: 0x%08x\n",
976 DBG_TX(et131x_dbginfo
,
977 "Got fragment of length %d, fragIndex: %d\n",
981 DBG_TX(et131x_dbginfo
,
982 "Leftover Size: %d\n",
992 CurDesc
.DataBufferPtrLow
=
993 pci_map_single(etdev
->
1004 DBG_TX(et131x_dbginfo
,
1005 "pci_map_single() returns: 0x%08x\n",
1010 DBG_TX(et131x_dbginfo
,
1011 "Split first element: NO\n");
1013 CurDesc
.word2
.bits
.length_in_bytes
=
1014 pPacket
->len
- pPacket
->data_len
;
1016 CurDesc
.DataBufferPtrLow
=
1017 pci_map_single(etdev
->pdev
,
1022 DBG_TX(et131x_dbginfo
,
1023 "pci_map_single() returns: 0x%08x\n",
1024 CurDesc
.DataBufferPtrLow
);
1028 CurDesc
.word2
.bits
.length_in_bytes
=
1029 pFragList
[fragIndex
- 1].size
;
1030 CurDesc
.DataBufferPtrLow
=
1031 pci_map_page(etdev
->pdev
,
1032 pFragList
[fragIndex
- 1].page
,
1033 pFragList
[fragIndex
-
1035 pFragList
[fragIndex
- 1].size
,
1037 DBG_TX(et131x_dbginfo
,
1038 "pci_map_page() returns: 0x%08x\n",
1039 CurDesc
.DataBufferPtrLow
);
1042 if (loopIndex
== 0) {
1043 /* This is the first descriptor of the packet
1045 * Set the "f" bit to indicate this is the
1046 * first descriptor in the packet.
1048 DBG_TX(et131x_dbginfo
,
1049 "This is our FIRST descriptor\n");
1050 CurDesc
.word3
.bits
.f
= 1;
1052 pMpTcb
->WrIndexStart
=
1053 etdev
->TxRing
.txDmaReadyToSend
;
1056 if ((loopIndex
== (loopEnd
- 1)) &&
1057 (etdev
->uiDuplexMode
||
1058 (pMpTcb
->PacketLength
>= NIC_MIN_PACKET_SIZE
))) {
1059 /* This is the Last descriptor of the packet */
1060 DBG_TX(et131x_dbginfo
,
1061 "THIS is our LAST descriptor\n");
1063 if (etdev
->uiLinkSpeed
==
1064 TRUEPHY_SPEED_1000MBPS
) {
1065 if (++etdev
->TxRing
.
1066 TxPacketsSinceLastinterrupt
>=
1067 etdev
->RegistryTxNumBuffers
) {
1068 CurDesc
.word3
.value
= 0x5;
1070 TxPacketsSinceLastinterrupt
1073 CurDesc
.word3
.value
= 0x1;
1076 CurDesc
.word3
.value
= 0x5;
1079 /* Following index will be used during freeing
1083 etdev
->TxRing
.txDmaReadyToSend
;
1084 pMpTcb
->PacketStaleCount
= 0;
1087 /* Copy the descriptor (filled above) into the
1088 * descriptor ring at the next free entry. Advance
1089 * the "next free entry" variable
1091 memcpy(etdev
->TxRing
.pTxDescRingVa
+
1092 etdev
->TxRing
.txDmaReadyToSend
.bits
.serv_req
,
1093 &CurDesc
, sizeof(TX_DESC_ENTRY_t
));
1096 etdev
->TxRing
.pTxDescRingVa
+
1097 etdev
->TxRing
.txDmaReadyToSend
.bits
.serv_req
;
1099 DBG_TX(et131x_dbginfo
,
1100 "CURRENT DESCRIPTOR\n"
1101 "\tAddress : 0x%p\n"
1102 "\tDataBufferPtrHigh : 0x%08x\n"
1103 "\tDataBufferPtrLow : 0x%08x\n"
1104 "\tword2 : 0x%08x\n"
1105 "\tword3 : 0x%08x\n",
1107 CurDescPostCopy
->DataBufferPtrHigh
,
1108 CurDescPostCopy
->DataBufferPtrLow
,
1109 CurDescPostCopy
->word2
.value
,
1110 CurDescPostCopy
->word3
.value
);
1112 if (++etdev
->TxRing
.txDmaReadyToSend
.bits
.serv_req
>=
1113 NUM_DESC_PER_RING_TX
) {
1114 if (etdev
->TxRing
.txDmaReadyToSend
.bits
.
1116 etdev
->TxRing
.txDmaReadyToSend
.
1119 etdev
->TxRing
.txDmaReadyToSend
.
1126 if (etdev
->uiDuplexMode
== 0 &&
1127 pMpTcb
->PacketLength
< NIC_MIN_PACKET_SIZE
) {
1128 /* NOTE - Same 32/64-bit issue as above... */
1129 CurDesc
.DataBufferPtrHigh
= 0x0;
1130 CurDesc
.DataBufferPtrLow
= etdev
->TxRing
.pTxDummyBlkPa
;
1131 CurDesc
.word2
.value
= 0;
1133 if (etdev
->uiLinkSpeed
== TRUEPHY_SPEED_1000MBPS
) {
1134 if (++etdev
->TxRing
.TxPacketsSinceLastinterrupt
>=
1135 etdev
->RegistryTxNumBuffers
) {
1136 CurDesc
.word3
.value
= 0x5;
1137 etdev
->TxRing
.TxPacketsSinceLastinterrupt
=
1140 CurDesc
.word3
.value
= 0x1;
1143 CurDesc
.word3
.value
= 0x5;
1146 CurDesc
.word2
.bits
.length_in_bytes
=
1147 NIC_MIN_PACKET_SIZE
- pMpTcb
->PacketLength
;
1149 pMpTcb
->WrIndex
= etdev
->TxRing
.txDmaReadyToSend
;
1151 memcpy(etdev
->TxRing
.pTxDescRingVa
+
1152 etdev
->TxRing
.txDmaReadyToSend
.bits
.serv_req
,
1153 &CurDesc
, sizeof(TX_DESC_ENTRY_t
));
1156 etdev
->TxRing
.pTxDescRingVa
+
1157 etdev
->TxRing
.txDmaReadyToSend
.bits
.serv_req
;
1159 DBG_TX(et131x_dbginfo
,
1160 "CURRENT DESCRIPTOR\n"
1161 "\tAddress : 0x%p\n"
1162 "\tDataBufferPtrHigh : 0x%08x\n"
1163 "\tDataBufferPtrLow : 0x%08x\n"
1164 "\tword2 : 0x%08x\n"
1165 "\tword3 : 0x%08x\n",
1167 CurDescPostCopy
->DataBufferPtrHigh
,
1168 CurDescPostCopy
->DataBufferPtrLow
,
1169 CurDescPostCopy
->word2
.value
,
1170 CurDescPostCopy
->word3
.value
);
1172 if (++etdev
->TxRing
.txDmaReadyToSend
.bits
.serv_req
>=
1173 NUM_DESC_PER_RING_TX
) {
1174 if (etdev
->TxRing
.txDmaReadyToSend
.bits
.
1176 etdev
->TxRing
.txDmaReadyToSend
.value
= 0;
1178 etdev
->TxRing
.txDmaReadyToSend
.value
= 0x400;
1182 DBG_TX(et131x_dbginfo
, "Padding descriptor %d by %d bytes\n",
1183 /* etdev->TxRing.txDmaReadyToSend.value, */
1184 etdev
->TxRing
.txDmaReadyToSend
.bits
.serv_req
,
1185 NIC_MIN_PACKET_SIZE
- pMpTcb
->PacketLength
);
1188 spin_lock(&etdev
->TCBSendQLock
);
1190 if (etdev
->TxRing
.CurrSendTail
)
1191 etdev
->TxRing
.CurrSendTail
->Next
= pMpTcb
;
1193 etdev
->TxRing
.CurrSendHead
= pMpTcb
;
1195 etdev
->TxRing
.CurrSendTail
= pMpTcb
;
1197 DBG_ASSERT(pMpTcb
->Next
== NULL
);
1199 etdev
->TxRing
.nBusySend
++;
1201 spin_unlock(&etdev
->TCBSendQLock
);
1203 /* Write the new write pointer back to the device. */
1204 writel(etdev
->TxRing
.txDmaReadyToSend
.value
,
1205 &etdev
->regs
->txdma
.service_request
.value
);
1207 #ifdef CONFIG_ET131X_DEBUG
1208 DumpDeviceBlock(DBG_TX_ON
, etdev
, 1);
1211 /* For Gig only, we use Tx Interrupt coalescing. Enable the software
1212 * timer to wake us up if this packet isn't followed by N more.
1214 if (etdev
->uiLinkSpeed
== TRUEPHY_SPEED_1000MBPS
) {
1215 writel(etdev
->RegistryTxTimeInterval
* NANO_IN_A_MICRO
,
1216 &etdev
->regs
->global
.watchdog_timer
);
1219 spin_unlock_irqrestore(&etdev
->SendHWLock
, flags
);
1221 DBG_TX_LEAVE(et131x_dbginfo
);
1228 * et131x_free_send_packet - Recycle a MP_TCB, complete the packet if necessary
1229 * @etdev: pointer to our adapter
1230 * @pMpTcb: pointer to MP_TCB
1232 * Assumption - Send spinlock has been acquired
1234 inline void et131x_free_send_packet(struct et131x_adapter
*etdev
,
1237 unsigned long flags
;
1238 TX_DESC_ENTRY_t
*desc
= NULL
;
1239 struct net_device_stats
*stats
= &etdev
->net_stats
;
1241 if (MP_TEST_FLAG(pMpTcb
, fMP_DEST_BROAD
))
1242 atomic_inc(&etdev
->Stats
.brdcstxmt
);
1243 else if (MP_TEST_FLAG(pMpTcb
, fMP_DEST_MULTI
))
1244 atomic_inc(&etdev
->Stats
.multixmt
);
1246 atomic_inc(&etdev
->Stats
.unixmt
);
1248 if (pMpTcb
->Packet
) {
1249 stats
->tx_bytes
+= pMpTcb
->Packet
->len
;
1251 /* Iterate through the TX descriptors on the ring
1252 * corresponding to this packet and umap the fragments
1255 DBG_TX(et131x_dbginfo
,
1256 "Unmap descriptors Here\n"
1259 "TCB PacketLength : %d\n"
1260 "TCB WrIndex.value : 0x%08x\n"
1261 "TCB WrIndex.bits.val : %d\n"
1262 "TCB WrIndex.value : 0x%08x\n"
1263 "TCB WrIndex.bits.val : %d\n",
1266 pMpTcb
->PacketLength
,
1267 pMpTcb
->WrIndexStart
.value
,
1268 pMpTcb
->WrIndexStart
.bits
.val
,
1269 pMpTcb
->WrIndex
.value
,
1270 pMpTcb
->WrIndex
.bits
.val
);
1274 (TX_DESC_ENTRY_t
*) (etdev
->TxRing
.
1276 pMpTcb
->WrIndexStart
.bits
.val
);
1278 DBG_TX(et131x_dbginfo
,
1279 "CURRENT DESCRIPTOR\n"
1280 "\tAddress : 0x%p\n"
1281 "\tDataBufferPtrHigh : 0x%08x\n"
1282 "\tDataBufferPtrLow : 0x%08x\n"
1283 "\tword2 : 0x%08x\n"
1284 "\tword3 : 0x%08x\n",
1286 desc
->DataBufferPtrHigh
,
1287 desc
->DataBufferPtrLow
,
1291 pci_unmap_single(etdev
->pdev
,
1292 desc
->DataBufferPtrLow
,
1293 desc
->word2
.value
, PCI_DMA_TODEVICE
);
1295 if (++pMpTcb
->WrIndexStart
.bits
.val
>=
1296 NUM_DESC_PER_RING_TX
) {
1297 if (pMpTcb
->WrIndexStart
.bits
.wrap
)
1298 pMpTcb
->WrIndexStart
.value
= 0;
1300 pMpTcb
->WrIndexStart
.value
= 0x400;
1302 } while (desc
!= (etdev
->TxRing
.pTxDescRingVa
+
1303 pMpTcb
->WrIndex
.bits
.val
));
1305 DBG_TX(et131x_dbginfo
,
1306 "Free Packet (SKB) : 0x%p\n", pMpTcb
->Packet
);
1308 dev_kfree_skb_any(pMpTcb
->Packet
);
1311 memset(pMpTcb
, 0, sizeof(MP_TCB
));
1313 /* Add the TCB to the Ready Q */
1314 spin_lock_irqsave(&etdev
->TCBReadyQLock
, flags
);
1316 etdev
->Stats
.opackets
++;
1318 if (etdev
->TxRing
.TCBReadyQueueTail
) {
1319 etdev
->TxRing
.TCBReadyQueueTail
->Next
= pMpTcb
;
1321 /* Apparently ready Q is empty. */
1322 etdev
->TxRing
.TCBReadyQueueHead
= pMpTcb
;
1325 etdev
->TxRing
.TCBReadyQueueTail
= pMpTcb
;
1327 spin_unlock_irqrestore(&etdev
->TCBReadyQLock
, flags
);
1329 DBG_ASSERT(etdev
->TxRing
.nBusySend
>= 0);
1333 * et131x_free_busy_send_packets - Free and complete the stopped active sends
1334 * @etdev: pointer to our adapter
1336 * Assumption - Send spinlock has been acquired
1338 void et131x_free_busy_send_packets(struct et131x_adapter
*etdev
)
1341 struct list_head
*pEntry
;
1342 unsigned long flags
;
1343 uint32_t FreeCounter
= 0;
1345 DBG_ENTER(et131x_dbginfo
);
1347 while (!list_empty(&etdev
->TxRing
.SendWaitQueue
)) {
1348 spin_lock_irqsave(&etdev
->SendWaitLock
, flags
);
1350 etdev
->TxRing
.nWaitSend
--;
1351 spin_unlock_irqrestore(&etdev
->SendWaitLock
, flags
);
1353 pEntry
= etdev
->TxRing
.SendWaitQueue
.next
;
1356 etdev
->TxRing
.nWaitSend
= 0;
1358 /* Any packets being sent? Check the first TCB on the send list */
1359 spin_lock_irqsave(&etdev
->TCBSendQLock
, flags
);
1361 pMpTcb
= etdev
->TxRing
.CurrSendHead
;
1363 while ((pMpTcb
!= NULL
) && (FreeCounter
< NUM_TCB
)) {
1364 PMP_TCB pNext
= pMpTcb
->Next
;
1366 etdev
->TxRing
.CurrSendHead
= pNext
;
1369 etdev
->TxRing
.CurrSendTail
= NULL
;
1371 etdev
->TxRing
.nBusySend
--;
1373 spin_unlock_irqrestore(&etdev
->TCBSendQLock
, flags
);
1375 DBG_VERBOSE(et131x_dbginfo
, "pMpTcb = 0x%p\n", pMpTcb
);
1378 et131x_free_send_packet(etdev
, pMpTcb
);
1380 spin_lock_irqsave(&etdev
->TCBSendQLock
, flags
);
1382 pMpTcb
= etdev
->TxRing
.CurrSendHead
;
1385 if (FreeCounter
== NUM_TCB
) {
1386 DBG_ERROR(et131x_dbginfo
,
1387 "MpFreeBusySendPackets exited loop for a bad reason\n");
1391 spin_unlock_irqrestore(&etdev
->TCBSendQLock
, flags
);
1393 etdev
->TxRing
.nBusySend
= 0;
1395 DBG_LEAVE(et131x_dbginfo
);
1399 * et131x_handle_send_interrupt - Interrupt handler for sending processing
1400 * @etdev: pointer to our adapter
1402 * Re-claim the send resources, complete sends and get more to send from
1403 * the send wait queue.
1405 * Assumption - Send spinlock has been acquired
1407 void et131x_handle_send_interrupt(struct et131x_adapter
*etdev
)
1409 DBG_TX_ENTER(et131x_dbginfo
);
1411 /* Mark as completed any packets which have been sent by the device. */
1412 et131x_update_tcb_list(etdev
);
1414 /* If we queued any transmits because we didn't have any TCBs earlier,
1415 * dequeue and send those packets now, as long as we have free TCBs.
1417 et131x_check_send_wait_list(etdev
);
1419 DBG_TX_LEAVE(et131x_dbginfo
);
1423 * et131x_update_tcb_list - Helper routine for Send Interrupt handler
1424 * @etdev: pointer to our adapter
1426 * Re-claims the send resources and completes sends. Can also be called as
1427 * part of the NIC send routine when the "ServiceComplete" indication has
1430 static void et131x_update_tcb_list(struct et131x_adapter
*etdev
)
1432 unsigned long flags
;
1433 DMA10W_t ServiceComplete
;
1436 ServiceComplete
.value
=
1437 readl(&etdev
->regs
->txdma
.NewServiceComplete
.value
);
1439 /* Has the ring wrapped? Process any descriptors that do not have
1440 * the same "wrap" indicator as the current completion indicator
1442 spin_lock_irqsave(&etdev
->TCBSendQLock
, flags
);
1444 pMpTcb
= etdev
->TxRing
.CurrSendHead
;
1446 ServiceComplete
.bits
.wrap
!= pMpTcb
->WrIndex
.bits
.wrap
&&
1447 ServiceComplete
.bits
.val
< pMpTcb
->WrIndex
.bits
.val
) {
1448 etdev
->TxRing
.nBusySend
--;
1449 etdev
->TxRing
.CurrSendHead
= pMpTcb
->Next
;
1450 if (pMpTcb
->Next
== NULL
)
1451 etdev
->TxRing
.CurrSendTail
= NULL
;
1453 spin_unlock_irqrestore(&etdev
->TCBSendQLock
, flags
);
1454 et131x_free_send_packet(etdev
, pMpTcb
);
1455 spin_lock_irqsave(&etdev
->TCBSendQLock
, flags
);
1457 /* Goto the next packet */
1458 pMpTcb
= etdev
->TxRing
.CurrSendHead
;
1461 ServiceComplete
.bits
.wrap
== pMpTcb
->WrIndex
.bits
.wrap
&&
1462 ServiceComplete
.bits
.val
> pMpTcb
->WrIndex
.bits
.val
) {
1463 etdev
->TxRing
.nBusySend
--;
1464 etdev
->TxRing
.CurrSendHead
= pMpTcb
->Next
;
1465 if (pMpTcb
->Next
== NULL
)
1466 etdev
->TxRing
.CurrSendTail
= NULL
;
1468 spin_unlock_irqrestore(&etdev
->TCBSendQLock
, flags
);
1469 et131x_free_send_packet(etdev
, pMpTcb
);
1470 spin_lock_irqsave(&etdev
->TCBSendQLock
, flags
);
1472 /* Goto the next packet */
1473 pMpTcb
= etdev
->TxRing
.CurrSendHead
;
1476 /* Wake up the queue when we hit a low-water mark */
1477 if (etdev
->TxRing
.nBusySend
<= (NUM_TCB
/ 3))
1478 netif_wake_queue(etdev
->netdev
);
1480 spin_unlock_irqrestore(&etdev
->TCBSendQLock
, flags
);
1484 * et131x_check_send_wait_list - Helper routine for the interrupt handler
1485 * @etdev: pointer to our adapter
1487 * Takes packets from the send wait queue and posts them to the device (if
1490 static void et131x_check_send_wait_list(struct et131x_adapter
*etdev
)
1492 unsigned long flags
;
1494 spin_lock_irqsave(&etdev
->SendWaitLock
, flags
);
1496 while (!list_empty(&etdev
->TxRing
.SendWaitQueue
) &&
1497 MP_TCB_RESOURCES_AVAILABLE(etdev
)) {
1498 struct list_head
*pEntry
;
1500 DBG_VERBOSE(et131x_dbginfo
, "Tx packets on the wait queue\n");
1502 pEntry
= etdev
->TxRing
.SendWaitQueue
.next
;
1504 etdev
->TxRing
.nWaitSend
--;
1506 DBG_WARNING(et131x_dbginfo
,
1507 "MpHandleSendInterrupt - sent a queued pkt. Waiting %d\n",
1508 etdev
->TxRing
.nWaitSend
);
1511 spin_unlock_irqrestore(&etdev
->SendWaitLock
, flags
);