aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/chelsio/sge.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/chelsio/sge.c')
-rw-r--r--drivers/net/chelsio/sge.c770
1 files changed, 652 insertions, 118 deletions
diff --git a/drivers/net/chelsio/sge.c b/drivers/net/chelsio/sge.c
index 9fb77c6d6c6b..26df2049d849 100644
--- a/drivers/net/chelsio/sge.c
+++ b/drivers/net/chelsio/sge.c
@@ -42,12 +42,14 @@
42#include <linux/types.h> 42#include <linux/types.h>
43#include <linux/errno.h> 43#include <linux/errno.h>
44#include <linux/pci.h> 44#include <linux/pci.h>
45#include <linux/ktime.h>
45#include <linux/netdevice.h> 46#include <linux/netdevice.h>
46#include <linux/etherdevice.h> 47#include <linux/etherdevice.h>
47#include <linux/if_vlan.h> 48#include <linux/if_vlan.h>
48#include <linux/skbuff.h> 49#include <linux/skbuff.h>
49#include <linux/init.h> 50#include <linux/init.h>
50#include <linux/mm.h> 51#include <linux/mm.h>
52#include <linux/tcp.h>
51#include <linux/ip.h> 53#include <linux/ip.h>
52#include <linux/in.h> 54#include <linux/in.h>
53#include <linux/if_arp.h> 55#include <linux/if_arp.h>
@@ -57,10 +59,8 @@
57#include "regs.h" 59#include "regs.h"
58#include "espi.h" 60#include "espi.h"
59 61
60 62/* This belongs in if_ether.h */
61#ifdef NETIF_F_TSO 63#define ETH_P_CPL5 0xf
62#include <linux/tcp.h>
63#endif
64 64
65#define SGE_CMDQ_N 2 65#define SGE_CMDQ_N 2
66#define SGE_FREELQ_N 2 66#define SGE_FREELQ_N 2
@@ -73,6 +73,7 @@
73#define SGE_INTRTIMER_NRES 1000 73#define SGE_INTRTIMER_NRES 1000
74#define SGE_RX_COPY_THRES 256 74#define SGE_RX_COPY_THRES 256
75#define SGE_RX_SM_BUF_SIZE 1536 75#define SGE_RX_SM_BUF_SIZE 1536
76#define SGE_TX_DESC_MAX_PLEN 16384
76 77
77# define SGE_RX_DROP_THRES 2 78# define SGE_RX_DROP_THRES 2
78 79
@@ -184,17 +185,17 @@ struct cmdQ {
184 unsigned long status; /* HW DMA fetch status */ 185 unsigned long status; /* HW DMA fetch status */
185 unsigned int in_use; /* # of in-use command descriptors */ 186 unsigned int in_use; /* # of in-use command descriptors */
186 unsigned int size; /* # of descriptors */ 187 unsigned int size; /* # of descriptors */
187 unsigned int processed; /* total # of descs HW has processed */ 188 unsigned int processed; /* total # of descs HW has processed */
188 unsigned int cleaned; /* total # of descs SW has reclaimed */ 189 unsigned int cleaned; /* total # of descs SW has reclaimed */
189 unsigned int stop_thres; /* SW TX queue suspend threshold */ 190 unsigned int stop_thres; /* SW TX queue suspend threshold */
190 u16 pidx; /* producer index (SW) */ 191 u16 pidx; /* producer index (SW) */
191 u16 cidx; /* consumer index (HW) */ 192 u16 cidx; /* consumer index (HW) */
192 u8 genbit; /* current generation (=valid) bit */ 193 u8 genbit; /* current generation (=valid) bit */
193 u8 sop; /* is next entry start of packet? */ 194 u8 sop; /* is next entry start of packet? */
194 struct cmdQ_e *entries; /* HW command descriptor Q */ 195 struct cmdQ_e *entries; /* HW command descriptor Q */
195 struct cmdQ_ce *centries; /* SW command context descriptor Q */ 196 struct cmdQ_ce *centries; /* SW command context descriptor Q */
196 spinlock_t lock; /* Lock to protect cmdQ enqueuing */
197 dma_addr_t dma_addr; /* DMA addr HW command descriptor Q */ 197 dma_addr_t dma_addr; /* DMA addr HW command descriptor Q */
198 spinlock_t lock; /* Lock to protect cmdQ enqueuing */
198}; 199};
199 200
200struct freelQ { 201struct freelQ {
@@ -203,8 +204,8 @@ struct freelQ {
203 u16 pidx; /* producer index (SW) */ 204 u16 pidx; /* producer index (SW) */
204 u16 cidx; /* consumer index (HW) */ 205 u16 cidx; /* consumer index (HW) */
205 u16 rx_buffer_size; /* Buffer size on this free list */ 206 u16 rx_buffer_size; /* Buffer size on this free list */
206 u16 dma_offset; /* DMA offset to align IP headers */ 207 u16 dma_offset; /* DMA offset to align IP headers */
207 u16 recycleq_idx; /* skb recycle q to use */ 208 u16 recycleq_idx; /* skb recycle q to use */
208 u8 genbit; /* current generation (=valid) bit */ 209 u8 genbit; /* current generation (=valid) bit */
209 struct freelQ_e *entries; /* HW freelist descriptor Q */ 210 struct freelQ_e *entries; /* HW freelist descriptor Q */
210 struct freelQ_ce *centries; /* SW freelist context descriptor Q */ 211 struct freelQ_ce *centries; /* SW freelist context descriptor Q */
@@ -226,6 +227,29 @@ enum {
226 CMDQ_STAT_LAST_PKT_DB = 2 /* last packet rung the doorbell */ 227 CMDQ_STAT_LAST_PKT_DB = 2 /* last packet rung the doorbell */
227}; 228};
228 229
230/* T204 TX SW scheduler */
231
232/* Per T204 TX port */
233struct sched_port {
234 unsigned int avail; /* available bits - quota */
235 unsigned int drain_bits_per_1024ns; /* drain rate */
236 unsigned int speed; /* drain rate, mbps */
237 unsigned int mtu; /* mtu size */
238 struct sk_buff_head skbq; /* pending skbs */
239};
240
241/* Per T204 device */
242struct sched {
243 ktime_t last_updated; /* last time quotas were computed */
244 unsigned int max_avail; /* max bits to be sent to any port */
245 unsigned int port; /* port index (round robin ports) */
246 unsigned int num; /* num skbs in per port queues */
247 struct sched_port p[MAX_NPORTS];
248 struct tasklet_struct sched_tsk;/* tasklet used to run scheduler */
249};
250static void restart_sched(unsigned long);
251
252
229/* 253/*
230 * Main SGE data structure 254 * Main SGE data structure
231 * 255 *
@@ -243,18 +267,240 @@ struct sge {
243 unsigned int rx_pkt_pad; /* RX padding for L2 packets */ 267 unsigned int rx_pkt_pad; /* RX padding for L2 packets */
244 unsigned int jumbo_fl; /* jumbo freelist Q index */ 268 unsigned int jumbo_fl; /* jumbo freelist Q index */
245 unsigned int intrtimer_nres; /* no-resource interrupt timer */ 269 unsigned int intrtimer_nres; /* no-resource interrupt timer */
246 unsigned int fixed_intrtimer;/* non-adaptive interrupt timer */ 270 unsigned int fixed_intrtimer;/* non-adaptive interrupt timer */
247 struct timer_list tx_reclaim_timer; /* reclaims TX buffers */ 271 struct timer_list tx_reclaim_timer; /* reclaims TX buffers */
248 struct timer_list espibug_timer; 272 struct timer_list espibug_timer;
249 unsigned int espibug_timeout; 273 unsigned long espibug_timeout;
250 struct sk_buff *espibug_skb; 274 struct sk_buff *espibug_skb[MAX_NPORTS];
251 u32 sge_control; /* shadow value of sge control reg */ 275 u32 sge_control; /* shadow value of sge control reg */
252 struct sge_intr_counts stats; 276 struct sge_intr_counts stats;
253 struct sge_port_stats port_stats[MAX_NPORTS]; 277 struct sge_port_stats port_stats[MAX_NPORTS];
278 struct sched *tx_sched;
254 struct cmdQ cmdQ[SGE_CMDQ_N] ____cacheline_aligned_in_smp; 279 struct cmdQ cmdQ[SGE_CMDQ_N] ____cacheline_aligned_in_smp;
255}; 280};
256 281
257/* 282/*
283 * stop tasklet and free all pending skb's
284 */
285static void tx_sched_stop(struct sge *sge)
286{
287 struct sched *s = sge->tx_sched;
288 int i;
289
290 tasklet_kill(&s->sched_tsk);
291
292 for (i = 0; i < MAX_NPORTS; i++)
293 __skb_queue_purge(&s->p[s->port].skbq);
294}
295
296/*
297 * t1_sched_update_parms() is called when the MTU or link speed changes. It
298 * re-computes scheduler parameters to scope with the change.
299 */
300unsigned int t1_sched_update_parms(struct sge *sge, unsigned int port,
301 unsigned int mtu, unsigned int speed)
302{
303 struct sched *s = sge->tx_sched;
304 struct sched_port *p = &s->p[port];
305 unsigned int max_avail_segs;
306
307 pr_debug("t1_sched_update_params mtu=%d speed=%d\n", mtu, speed);
308 if (speed)
309 p->speed = speed;
310 if (mtu)
311 p->mtu = mtu;
312
313 if (speed || mtu) {
314 unsigned long long drain = 1024ULL * p->speed * (p->mtu - 40);
315 do_div(drain, (p->mtu + 50) * 1000);
316 p->drain_bits_per_1024ns = (unsigned int) drain;
317
318 if (p->speed < 1000)
319 p->drain_bits_per_1024ns =
320 90 * p->drain_bits_per_1024ns / 100;
321 }
322
323 if (board_info(sge->adapter)->board == CHBT_BOARD_CHT204) {
324 p->drain_bits_per_1024ns -= 16;
325 s->max_avail = max(4096U, p->mtu + 16 + 14 + 4);
326 max_avail_segs = max(1U, 4096 / (p->mtu - 40));
327 } else {
328 s->max_avail = 16384;
329 max_avail_segs = max(1U, 9000 / (p->mtu - 40));
330 }
331
332 pr_debug("t1_sched_update_parms: mtu %u speed %u max_avail %u "
333 "max_avail_segs %u drain_bits_per_1024ns %u\n", p->mtu,
334 p->speed, s->max_avail, max_avail_segs,
335 p->drain_bits_per_1024ns);
336
337 return max_avail_segs * (p->mtu - 40);
338}
339
340/*
341 * t1_sched_max_avail_bytes() tells the scheduler the maximum amount of
342 * data that can be pushed per port.
343 */
344void t1_sched_set_max_avail_bytes(struct sge *sge, unsigned int val)
345{
346 struct sched *s = sge->tx_sched;
347 unsigned int i;
348
349 s->max_avail = val;
350 for (i = 0; i < MAX_NPORTS; i++)
351 t1_sched_update_parms(sge, i, 0, 0);
352}
353
354/*
355 * t1_sched_set_drain_bits_per_us() tells the scheduler at which rate a port
356 * is draining.
357 */
358void t1_sched_set_drain_bits_per_us(struct sge *sge, unsigned int port,
359 unsigned int val)
360{
361 struct sched *s = sge->tx_sched;
362 struct sched_port *p = &s->p[port];
363 p->drain_bits_per_1024ns = val * 1024 / 1000;
364 t1_sched_update_parms(sge, port, 0, 0);
365}
366
367
368/*
369 * get_clock() implements a ns clock (see ktime_get)
370 */
371static inline ktime_t get_clock(void)
372{
373 struct timespec ts;
374
375 ktime_get_ts(&ts);
376 return timespec_to_ktime(ts);
377}
378
379/*
380 * tx_sched_init() allocates resources and does basic initialization.
381 */
382static int tx_sched_init(struct sge *sge)
383{
384 struct sched *s;
385 int i;
386
387 s = kzalloc(sizeof (struct sched), GFP_KERNEL);
388 if (!s)
389 return -ENOMEM;
390
391 pr_debug("tx_sched_init\n");
392 tasklet_init(&s->sched_tsk, restart_sched, (unsigned long) sge);
393 sge->tx_sched = s;
394
395 for (i = 0; i < MAX_NPORTS; i++) {
396 skb_queue_head_init(&s->p[i].skbq);
397 t1_sched_update_parms(sge, i, 1500, 1000);
398 }
399
400 return 0;
401}
402
403/*
404 * sched_update_avail() computes the delta since the last time it was called
405 * and updates the per port quota (number of bits that can be sent to the any
406 * port).
407 */
408static inline int sched_update_avail(struct sge *sge)
409{
410 struct sched *s = sge->tx_sched;
411 ktime_t now = get_clock();
412 unsigned int i;
413 long long delta_time_ns;
414
415 delta_time_ns = ktime_to_ns(ktime_sub(now, s->last_updated));
416
417 pr_debug("sched_update_avail delta=%lld\n", delta_time_ns);
418 if (delta_time_ns < 15000)
419 return 0;
420
421 for (i = 0; i < MAX_NPORTS; i++) {
422 struct sched_port *p = &s->p[i];
423 unsigned int delta_avail;
424
425 delta_avail = (p->drain_bits_per_1024ns * delta_time_ns) >> 13;
426 p->avail = min(p->avail + delta_avail, s->max_avail);
427 }
428
429 s->last_updated = now;
430
431 return 1;
432}
433
434/*
435 * sched_skb() is called from two different places. In the tx path, any
436 * packet generating load on an output port will call sched_skb()
437 * (skb != NULL). In addition, sched_skb() is called from the irq/soft irq
438 * context (skb == NULL).
439 * The scheduler only returns a skb (which will then be sent) if the
440 * length of the skb is <= the current quota of the output port.
441 */
442static struct sk_buff *sched_skb(struct sge *sge, struct sk_buff *skb,
443 unsigned int credits)
444{
445 struct sched *s = sge->tx_sched;
446 struct sk_buff_head *skbq;
447 unsigned int i, len, update = 1;
448
449 pr_debug("sched_skb %p\n", skb);
450 if (!skb) {
451 if (!s->num)
452 return NULL;
453 } else {
454 skbq = &s->p[skb->dev->if_port].skbq;
455 __skb_queue_tail(skbq, skb);
456 s->num++;
457 skb = NULL;
458 }
459
460 if (credits < MAX_SKB_FRAGS + 1)
461 goto out;
462
463 again:
464 for (i = 0; i < MAX_NPORTS; i++) {
465 s->port = ++s->port & (MAX_NPORTS - 1);
466 skbq = &s->p[s->port].skbq;
467
468 skb = skb_peek(skbq);
469
470 if (!skb)
471 continue;
472
473 len = skb->len;
474 if (len <= s->p[s->port].avail) {
475 s->p[s->port].avail -= len;
476 s->num--;
477 __skb_unlink(skb, skbq);
478 goto out;
479 }
480 skb = NULL;
481 }
482
483 if (update-- && sched_update_avail(sge))
484 goto again;
485
486 out:
487 /* If there are more pending skbs, we use the hardware to schedule us
488 * again.
489 */
490 if (s->num && !skb) {
491 struct cmdQ *q = &sge->cmdQ[0];
492 clear_bit(CMDQ_STAT_LAST_PKT_DB, &q->status);
493 if (test_and_set_bit(CMDQ_STAT_RUNNING, &q->status) == 0) {
494 set_bit(CMDQ_STAT_LAST_PKT_DB, &q->status);
495 writel(F_CMDQ0_ENABLE, sge->adapter->regs + A_SG_DOORBELL);
496 }
497 }
498 pr_debug("sched_skb ret %p\n", skb);
499
500 return skb;
501}
502
503/*
258 * PIO to indicate that memory mapped Q contains valid descriptor(s). 504 * PIO to indicate that memory mapped Q contains valid descriptor(s).
259 */ 505 */
260static inline void doorbell_pio(struct adapter *adapter, u32 val) 506static inline void doorbell_pio(struct adapter *adapter, u32 val)
@@ -350,8 +596,11 @@ static int alloc_rx_resources(struct sge *sge, struct sge_params *p)
350 sge->freelQ[!sge->jumbo_fl].rx_buffer_size = SGE_RX_SM_BUF_SIZE + 596 sge->freelQ[!sge->jumbo_fl].rx_buffer_size = SGE_RX_SM_BUF_SIZE +
351 sizeof(struct cpl_rx_data) + 597 sizeof(struct cpl_rx_data) +
352 sge->freelQ[!sge->jumbo_fl].dma_offset; 598 sge->freelQ[!sge->jumbo_fl].dma_offset;
353 sge->freelQ[sge->jumbo_fl].rx_buffer_size = (16 * 1024) - 599
354 SKB_DATA_ALIGN(sizeof(struct skb_shared_info)); 600 size = (16 * 1024) -
601 SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
602
603 sge->freelQ[sge->jumbo_fl].rx_buffer_size = size;
355 604
356 /* 605 /*
357 * Setup which skb recycle Q should be used when recycling buffers from 606 * Setup which skb recycle Q should be used when recycling buffers from
@@ -388,17 +637,23 @@ static void free_cmdQ_buffers(struct sge *sge, struct cmdQ *q, unsigned int n)
388 q->in_use -= n; 637 q->in_use -= n;
389 ce = &q->centries[cidx]; 638 ce = &q->centries[cidx];
390 while (n--) { 639 while (n--) {
391 if (q->sop) 640 if (q->sop) {
392 pci_unmap_single(pdev, pci_unmap_addr(ce, dma_addr), 641 if (likely(pci_unmap_len(ce, dma_len))) {
393 pci_unmap_len(ce, dma_len), 642 pci_unmap_single(pdev,
394 PCI_DMA_TODEVICE); 643 pci_unmap_addr(ce, dma_addr),
395 else 644 pci_unmap_len(ce, dma_len),
396 pci_unmap_page(pdev, pci_unmap_addr(ce, dma_addr), 645 PCI_DMA_TODEVICE);
397 pci_unmap_len(ce, dma_len), 646 q->sop = 0;
398 PCI_DMA_TODEVICE); 647 }
399 q->sop = 0; 648 } else {
649 if (likely(pci_unmap_len(ce, dma_len))) {
650 pci_unmap_page(pdev, pci_unmap_addr(ce, dma_addr),
651 pci_unmap_len(ce, dma_len),
652 PCI_DMA_TODEVICE);
653 }
654 }
400 if (ce->skb) { 655 if (ce->skb) {
401 dev_kfree_skb(ce->skb); 656 dev_kfree_skb_any(ce->skb);
402 q->sop = 1; 657 q->sop = 1;
403 } 658 }
404 ce++; 659 ce++;
@@ -504,7 +759,7 @@ void t1_set_vlan_accel(struct adapter *adapter, int on_off)
504 sge->sge_control |= F_VLAN_XTRACT; 759 sge->sge_control |= F_VLAN_XTRACT;
505 if (adapter->open_device_map) { 760 if (adapter->open_device_map) {
506 writel(sge->sge_control, adapter->regs + A_SG_CONTROL); 761 writel(sge->sge_control, adapter->regs + A_SG_CONTROL);
507 readl(adapter->regs + A_SG_CONTROL); /* flush */ 762 readl(adapter->regs + A_SG_CONTROL); /* flush */
508 } 763 }
509} 764}
510 765
@@ -538,7 +793,6 @@ static void configure_sge(struct sge *sge, struct sge_params *p)
538 sge->sge_control = F_CMDQ0_ENABLE | F_CMDQ1_ENABLE | F_FL0_ENABLE | 793 sge->sge_control = F_CMDQ0_ENABLE | F_CMDQ1_ENABLE | F_FL0_ENABLE |
539 F_FL1_ENABLE | F_CPL_ENABLE | F_RESPONSE_QUEUE_ENABLE | 794 F_FL1_ENABLE | F_CPL_ENABLE | F_RESPONSE_QUEUE_ENABLE |
540 V_CMDQ_PRIORITY(2) | F_DISABLE_CMDQ1_GTS | F_ISCSI_COALESCE | 795 V_CMDQ_PRIORITY(2) | F_DISABLE_CMDQ1_GTS | F_ISCSI_COALESCE |
541 F_DISABLE_FL0_GTS | F_DISABLE_FL1_GTS |
542 V_RX_PKT_OFFSET(sge->rx_pkt_pad); 796 V_RX_PKT_OFFSET(sge->rx_pkt_pad);
543 797
544#if defined(__BIG_ENDIAN_BITFIELD) 798#if defined(__BIG_ENDIAN_BITFIELD)
@@ -566,9 +820,7 @@ static inline unsigned int jumbo_payload_capacity(const struct sge *sge)
566 */ 820 */
567void t1_sge_destroy(struct sge *sge) 821void t1_sge_destroy(struct sge *sge)
568{ 822{
569 if (sge->espibug_skb) 823 kfree(sge->tx_sched);
570 kfree_skb(sge->espibug_skb);
571
572 free_tx_resources(sge); 824 free_tx_resources(sge);
573 free_rx_resources(sge); 825 free_rx_resources(sge);
574 kfree(sge); 826 kfree(sge);
@@ -854,6 +1106,99 @@ static void unexpected_offload(struct adapter *adapter, struct freelQ *fl)
854} 1106}
855 1107
856/* 1108/*
1109 * T1/T2 SGE limits the maximum DMA size per TX descriptor to
1110 * SGE_TX_DESC_MAX_PLEN (16KB). If the PAGE_SIZE is larger than 16KB, the
1111 * stack might send more than SGE_TX_DESC_MAX_PLEN in a contiguous manner.
1112 * Note that the *_large_page_tx_descs stuff will be optimized out when
1113 * PAGE_SIZE <= SGE_TX_DESC_MAX_PLEN.
1114 *
1115 * compute_large_page_descs() computes how many additional descriptors are
1116 * required to break down the stack's request.
1117 */
1118static inline unsigned int compute_large_page_tx_descs(struct sk_buff *skb)
1119{
1120 unsigned int count = 0;
1121 if (PAGE_SIZE > SGE_TX_DESC_MAX_PLEN) {
1122 unsigned int nfrags = skb_shinfo(skb)->nr_frags;
1123 unsigned int i, len = skb->len - skb->data_len;
1124 while (len > SGE_TX_DESC_MAX_PLEN) {
1125 count++;
1126 len -= SGE_TX_DESC_MAX_PLEN;
1127 }
1128 for (i = 0; nfrags--; i++) {
1129 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
1130 len = frag->size;
1131 while (len > SGE_TX_DESC_MAX_PLEN) {
1132 count++;
1133 len -= SGE_TX_DESC_MAX_PLEN;
1134 }
1135 }
1136 }
1137 return count;
1138}
1139
1140/*
1141 * Write a cmdQ entry.
1142 *
1143 * Since this function writes the 'flags' field, it must not be used to
1144 * write the first cmdQ entry.
1145 */
1146static inline void write_tx_desc(struct cmdQ_e *e, dma_addr_t mapping,
1147 unsigned int len, unsigned int gen,
1148 unsigned int eop)
1149{
1150 if (unlikely(len > SGE_TX_DESC_MAX_PLEN))
1151 BUG();
1152 e->addr_lo = (u32)mapping;
1153 e->addr_hi = (u64)mapping >> 32;
1154 e->len_gen = V_CMD_LEN(len) | V_CMD_GEN1(gen);
1155 e->flags = F_CMD_DATAVALID | V_CMD_EOP(eop) | V_CMD_GEN2(gen);
1156}
1157
1158/*
1159 * See comment for previous function.
1160 *
1161 * write_tx_descs_large_page() writes additional SGE tx descriptors if
1162 * *desc_len exceeds HW's capability.
1163 */
1164static inline unsigned int write_large_page_tx_descs(unsigned int pidx,
1165 struct cmdQ_e **e,
1166 struct cmdQ_ce **ce,
1167 unsigned int *gen,
1168 dma_addr_t *desc_mapping,
1169 unsigned int *desc_len,
1170 unsigned int nfrags,
1171 struct cmdQ *q)
1172{
1173 if (PAGE_SIZE > SGE_TX_DESC_MAX_PLEN) {
1174 struct cmdQ_e *e1 = *e;
1175 struct cmdQ_ce *ce1 = *ce;
1176
1177 while (*desc_len > SGE_TX_DESC_MAX_PLEN) {
1178 *desc_len -= SGE_TX_DESC_MAX_PLEN;
1179 write_tx_desc(e1, *desc_mapping, SGE_TX_DESC_MAX_PLEN,
1180 *gen, nfrags == 0 && *desc_len == 0);
1181 ce1->skb = NULL;
1182 pci_unmap_len_set(ce1, dma_len, 0);
1183 *desc_mapping += SGE_TX_DESC_MAX_PLEN;
1184 if (*desc_len) {
1185 ce1++;
1186 e1++;
1187 if (++pidx == q->size) {
1188 pidx = 0;
1189 *gen ^= 1;
1190 ce1 = q->centries;
1191 e1 = q->entries;
1192 }
1193 }
1194 }
1195 *e = e1;
1196 *ce = ce1;
1197 }
1198 return pidx;
1199}
1200
1201/*
857 * Write the command descriptors to transmit the given skb starting at 1202 * Write the command descriptors to transmit the given skb starting at
858 * descriptor pidx with the given generation. 1203 * descriptor pidx with the given generation.
859 */ 1204 */
@@ -861,50 +1206,84 @@ static inline void write_tx_descs(struct adapter *adapter, struct sk_buff *skb,
861 unsigned int pidx, unsigned int gen, 1206 unsigned int pidx, unsigned int gen,
862 struct cmdQ *q) 1207 struct cmdQ *q)
863{ 1208{
864 dma_addr_t mapping; 1209 dma_addr_t mapping, desc_mapping;
865 struct cmdQ_e *e, *e1; 1210 struct cmdQ_e *e, *e1;
866 struct cmdQ_ce *ce; 1211 struct cmdQ_ce *ce;
867 unsigned int i, flags, nfrags = skb_shinfo(skb)->nr_frags; 1212 unsigned int i, flags, first_desc_len, desc_len,
1213 nfrags = skb_shinfo(skb)->nr_frags;
868 1214
869 mapping = pci_map_single(adapter->pdev, skb->data, 1215 e = e1 = &q->entries[pidx];
870 skb->len - skb->data_len, PCI_DMA_TODEVICE);
871 ce = &q->centries[pidx]; 1216 ce = &q->centries[pidx];
1217
1218 mapping = pci_map_single(adapter->pdev, skb->data,
1219 skb->len - skb->data_len, PCI_DMA_TODEVICE);
1220
1221 desc_mapping = mapping;
1222 desc_len = skb->len - skb->data_len;
1223
1224 flags = F_CMD_DATAVALID | F_CMD_SOP |
1225 V_CMD_EOP(nfrags == 0 && desc_len <= SGE_TX_DESC_MAX_PLEN) |
1226 V_CMD_GEN2(gen);
1227 first_desc_len = (desc_len <= SGE_TX_DESC_MAX_PLEN) ?
1228 desc_len : SGE_TX_DESC_MAX_PLEN;
1229 e->addr_lo = (u32)desc_mapping;
1230 e->addr_hi = (u64)desc_mapping >> 32;
1231 e->len_gen = V_CMD_LEN(first_desc_len) | V_CMD_GEN1(gen);
1232 ce->skb = NULL;
1233 pci_unmap_len_set(ce, dma_len, 0);
1234
1235 if (PAGE_SIZE > SGE_TX_DESC_MAX_PLEN &&
1236 desc_len > SGE_TX_DESC_MAX_PLEN) {
1237 desc_mapping += first_desc_len;
1238 desc_len -= first_desc_len;
1239 e1++;
1240 ce++;
1241 if (++pidx == q->size) {
1242 pidx = 0;
1243 gen ^= 1;
1244 e1 = q->entries;
1245 ce = q->centries;
1246 }
1247 pidx = write_large_page_tx_descs(pidx, &e1, &ce, &gen,
1248 &desc_mapping, &desc_len,
1249 nfrags, q);
1250
1251 if (likely(desc_len))
1252 write_tx_desc(e1, desc_mapping, desc_len, gen,
1253 nfrags == 0);
1254 }
1255
872 ce->skb = NULL; 1256 ce->skb = NULL;
873 pci_unmap_addr_set(ce, dma_addr, mapping); 1257 pci_unmap_addr_set(ce, dma_addr, mapping);
874 pci_unmap_len_set(ce, dma_len, skb->len - skb->data_len); 1258 pci_unmap_len_set(ce, dma_len, skb->len - skb->data_len);
875 1259
876 flags = F_CMD_DATAVALID | F_CMD_SOP | V_CMD_EOP(nfrags == 0) | 1260 for (i = 0; nfrags--; i++) {
877 V_CMD_GEN2(gen);
878 e = &q->entries[pidx];
879 e->addr_lo = (u32)mapping;
880 e->addr_hi = (u64)mapping >> 32;
881 e->len_gen = V_CMD_LEN(skb->len - skb->data_len) | V_CMD_GEN1(gen);
882 for (e1 = e, i = 0; nfrags--; i++) {
883 skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; 1261 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
884
885 ce++;
886 e1++; 1262 e1++;
1263 ce++;
887 if (++pidx == q->size) { 1264 if (++pidx == q->size) {
888 pidx = 0; 1265 pidx = 0;
889 gen ^= 1; 1266 gen ^= 1;
890 ce = q->centries;
891 e1 = q->entries; 1267 e1 = q->entries;
1268 ce = q->centries;
892 } 1269 }
893 1270
894 mapping = pci_map_page(adapter->pdev, frag->page, 1271 mapping = pci_map_page(adapter->pdev, frag->page,
895 frag->page_offset, frag->size, 1272 frag->page_offset, frag->size,
896 PCI_DMA_TODEVICE); 1273 PCI_DMA_TODEVICE);
1274 desc_mapping = mapping;
1275 desc_len = frag->size;
1276
1277 pidx = write_large_page_tx_descs(pidx, &e1, &ce, &gen,
1278 &desc_mapping, &desc_len,
1279 nfrags, q);
1280 if (likely(desc_len))
1281 write_tx_desc(e1, desc_mapping, desc_len, gen,
1282 nfrags == 0);
897 ce->skb = NULL; 1283 ce->skb = NULL;
898 pci_unmap_addr_set(ce, dma_addr, mapping); 1284 pci_unmap_addr_set(ce, dma_addr, mapping);
899 pci_unmap_len_set(ce, dma_len, frag->size); 1285 pci_unmap_len_set(ce, dma_len, frag->size);
900
901 e1->addr_lo = (u32)mapping;
902 e1->addr_hi = (u64)mapping >> 32;
903 e1->len_gen = V_CMD_LEN(frag->size) | V_CMD_GEN1(gen);
904 e1->flags = F_CMD_DATAVALID | V_CMD_EOP(nfrags == 0) |
905 V_CMD_GEN2(gen);
906 } 1286 }
907
908 ce->skb = skb; 1287 ce->skb = skb;
909 wmb(); 1288 wmb();
910 e->flags = flags; 1289 e->flags = flags;
@@ -918,14 +1297,56 @@ static inline void reclaim_completed_tx(struct sge *sge, struct cmdQ *q)
918 unsigned int reclaim = q->processed - q->cleaned; 1297 unsigned int reclaim = q->processed - q->cleaned;
919 1298
920 if (reclaim) { 1299 if (reclaim) {
1300 pr_debug("reclaim_completed_tx processed:%d cleaned:%d\n",
1301 q->processed, q->cleaned);
921 free_cmdQ_buffers(sge, q, reclaim); 1302 free_cmdQ_buffers(sge, q, reclaim);
922 q->cleaned += reclaim; 1303 q->cleaned += reclaim;
923 } 1304 }
924} 1305}
925 1306
926#ifndef SET_ETHTOOL_OPS 1307/*
927# define __netif_rx_complete(dev) netif_rx_complete(dev) 1308 * Called from tasklet. Checks the scheduler for any
928#endif 1309 * pending skbs that can be sent.
1310 */
1311static void restart_sched(unsigned long arg)
1312{
1313 struct sge *sge = (struct sge *) arg;
1314 struct adapter *adapter = sge->adapter;
1315 struct cmdQ *q = &sge->cmdQ[0];
1316 struct sk_buff *skb;
1317 unsigned int credits, queued_skb = 0;
1318
1319 spin_lock(&q->lock);
1320 reclaim_completed_tx(sge, q);
1321
1322 credits = q->size - q->in_use;
1323 pr_debug("restart_sched credits=%d\n", credits);
1324 while ((skb = sched_skb(sge, NULL, credits)) != NULL) {
1325 unsigned int genbit, pidx, count;
1326 count = 1 + skb_shinfo(skb)->nr_frags;
1327 count += compute_large_page_tx_descs(skb);
1328 q->in_use += count;
1329 genbit = q->genbit;
1330 pidx = q->pidx;
1331 q->pidx += count;
1332 if (q->pidx >= q->size) {
1333 q->pidx -= q->size;
1334 q->genbit ^= 1;
1335 }
1336 write_tx_descs(adapter, skb, pidx, genbit, q);
1337 credits = q->size - q->in_use;
1338 queued_skb = 1;
1339 }
1340
1341 if (queued_skb) {
1342 clear_bit(CMDQ_STAT_LAST_PKT_DB, &q->status);
1343 if (test_and_set_bit(CMDQ_STAT_RUNNING, &q->status) == 0) {
1344 set_bit(CMDQ_STAT_LAST_PKT_DB, &q->status);
1345 writel(F_CMDQ0_ENABLE, adapter->regs + A_SG_DOORBELL);
1346 }
1347 }
1348 spin_unlock(&q->lock);
1349}
929 1350
930/** 1351/**
931 * sge_rx - process an ingress ethernet packet 1352 * sge_rx - process an ingress ethernet packet
@@ -953,6 +1374,11 @@ static int sge_rx(struct sge *sge, struct freelQ *fl, unsigned int len)
953 p = (struct cpl_rx_pkt *)skb->data; 1374 p = (struct cpl_rx_pkt *)skb->data;
954 skb_pull(skb, sizeof(*p)); 1375 skb_pull(skb, sizeof(*p));
955 skb->dev = adapter->port[p->iff].dev; 1376 skb->dev = adapter->port[p->iff].dev;
1377 if (p->iff >= adapter->params.nports) {
1378 kfree_skb(skb);
1379 return 0;
1380 }
1381
956 skb->dev->last_rx = jiffies; 1382 skb->dev->last_rx = jiffies;
957 skb->protocol = eth_type_trans(skb, skb->dev); 1383 skb->protocol = eth_type_trans(skb, skb->dev);
958 if ((adapter->flags & RX_CSUM_ENABLED) && p->csum == 0xffff && 1384 if ((adapter->flags & RX_CSUM_ENABLED) && p->csum == 0xffff &&
@@ -1025,18 +1451,24 @@ static unsigned int update_tx_info(struct adapter *adapter,
1025 struct cmdQ *cmdq = &sge->cmdQ[0]; 1451 struct cmdQ *cmdq = &sge->cmdQ[0];
1026 1452
1027 cmdq->processed += pr0; 1453 cmdq->processed += pr0;
1028 1454 if (flags & (F_FL0_ENABLE | F_FL1_ENABLE)) {
1455 freelQs_empty(sge);
1456 flags &= ~(F_FL0_ENABLE | F_FL1_ENABLE);
1457 }
1029 if (flags & F_CMDQ0_ENABLE) { 1458 if (flags & F_CMDQ0_ENABLE) {
1030 clear_bit(CMDQ_STAT_RUNNING, &cmdq->status); 1459 clear_bit(CMDQ_STAT_RUNNING, &cmdq->status);
1031 1460
1032 if (cmdq->cleaned + cmdq->in_use != cmdq->processed && 1461 if (cmdq->cleaned + cmdq->in_use != cmdq->processed &&
1033 !test_and_set_bit(CMDQ_STAT_LAST_PKT_DB, &cmdq->status)) { 1462 !test_and_set_bit(CMDQ_STAT_LAST_PKT_DB, &cmdq->status)) {
1034 set_bit(CMDQ_STAT_RUNNING, &cmdq->status); 1463 set_bit(CMDQ_STAT_RUNNING, &cmdq->status);
1035 writel(F_CMDQ0_ENABLE, adapter->regs + A_SG_DOORBELL); 1464 writel(F_CMDQ0_ENABLE, adapter->regs + A_SG_DOORBELL);
1036 } 1465 }
1037 flags &= ~F_CMDQ0_ENABLE; 1466 if (sge->tx_sched)
1467 tasklet_hi_schedule(&sge->tx_sched->sched_tsk);
1468
1469 flags &= ~F_CMDQ0_ENABLE;
1038 } 1470 }
1039 1471
1040 if (unlikely(sge->stopped_tx_queues != 0)) 1472 if (unlikely(sge->stopped_tx_queues != 0))
1041 restart_tx_queues(sge); 1473 restart_tx_queues(sge);
1042 1474
@@ -1233,14 +1665,15 @@ static irqreturn_t t1_interrupt_napi(int irq, void *data)
1233 printk(KERN_INFO 1665 printk(KERN_INFO
1234 "NAPI schedule failure!\n"); 1666 "NAPI schedule failure!\n");
1235 } else 1667 } else
1236 writel(q->cidx, adapter->regs + A_SG_SLEEPING); 1668 writel(q->cidx, adapter->regs + A_SG_SLEEPING);
1669
1237 handled = 1; 1670 handled = 1;
1238 goto unlock; 1671 goto unlock;
1239 } else 1672 } else
1240 writel(q->cidx, adapter->regs + A_SG_SLEEPING); 1673 writel(q->cidx, adapter->regs + A_SG_SLEEPING);
1241 } else 1674 } else if (readl(adapter->regs + A_PL_CAUSE) & F_PL_INTR_SGE_DATA) {
1242 if (readl(adapter->regs + A_PL_CAUSE) & F_PL_INTR_SGE_DATA) 1675 printk(KERN_ERR "data interrupt while NAPI running\n");
1243 printk(KERN_ERR "data interrupt while NAPI running\n"); 1676 }
1244 1677
1245 handled = t1_slow_intr_handler(adapter); 1678 handled = t1_slow_intr_handler(adapter);
1246 if (!handled) 1679 if (!handled)
@@ -1321,7 +1754,7 @@ static int t1_sge_tx(struct sk_buff *skb, struct adapter *adapter,
1321{ 1754{
1322 struct sge *sge = adapter->sge; 1755 struct sge *sge = adapter->sge;
1323 struct cmdQ *q = &sge->cmdQ[qid]; 1756 struct cmdQ *q = &sge->cmdQ[qid];
1324 unsigned int credits, pidx, genbit, count; 1757 unsigned int credits, pidx, genbit, count, use_sched_skb = 0;
1325 1758
1326 spin_lock(&q->lock); 1759 spin_lock(&q->lock);
1327 reclaim_completed_tx(sge, q); 1760 reclaim_completed_tx(sge, q);
@@ -1329,26 +1762,49 @@ static int t1_sge_tx(struct sk_buff *skb, struct adapter *adapter,
1329 pidx = q->pidx; 1762 pidx = q->pidx;
1330 credits = q->size - q->in_use; 1763 credits = q->size - q->in_use;
1331 count = 1 + skb_shinfo(skb)->nr_frags; 1764 count = 1 + skb_shinfo(skb)->nr_frags;
1765 count += compute_large_page_tx_descs(skb);
1332 1766
1333 { /* Ethernet packet */ 1767 /* Ethernet packet */
1334 if (unlikely(credits < count)) { 1768 if (unlikely(credits < count)) {
1769 if (!netif_queue_stopped(dev)) {
1335 netif_stop_queue(dev); 1770 netif_stop_queue(dev);
1336 set_bit(dev->if_port, &sge->stopped_tx_queues); 1771 set_bit(dev->if_port, &sge->stopped_tx_queues);
1337 sge->stats.cmdQ_full[2]++; 1772 sge->stats.cmdQ_full[2]++;
1338 spin_unlock(&q->lock); 1773 CH_ERR("%s: Tx ring full while queue awake!\n",
1339 if (!netif_queue_stopped(dev)) 1774 adapter->name);
1340 CH_ERR("%s: Tx ring full while queue awake!\n",
1341 adapter->name);
1342 return NETDEV_TX_BUSY;
1343 } 1775 }
1344 if (unlikely(credits - count < q->stop_thres)) { 1776 spin_unlock(&q->lock);
1345 sge->stats.cmdQ_full[2]++; 1777 return NETDEV_TX_BUSY;
1346 netif_stop_queue(dev); 1778 }
1347 set_bit(dev->if_port, &sge->stopped_tx_queues); 1779
1780 if (unlikely(credits - count < q->stop_thres)) {
1781 netif_stop_queue(dev);
1782 set_bit(dev->if_port, &sge->stopped_tx_queues);
1783 sge->stats.cmdQ_full[2]++;
1784 }
1785
1786 /* T204 cmdQ0 skbs that are destined for a certain port have to go
1787 * through the scheduler.
1788 */
1789 if (sge->tx_sched && !qid && skb->dev) {
1790 use_sched:
1791 use_sched_skb = 1;
1792 /* Note that the scheduler might return a different skb than
1793 * the one passed in.
1794 */
1795 skb = sched_skb(sge, skb, credits);
1796 if (!skb) {
1797 spin_unlock(&q->lock);
1798 return NETDEV_TX_OK;
1348 } 1799 }
1800 pidx = q->pidx;
1801 count = 1 + skb_shinfo(skb)->nr_frags;
1802 count += compute_large_page_tx_descs(skb);
1349 } 1803 }
1804
1350 q->in_use += count; 1805 q->in_use += count;
1351 genbit = q->genbit; 1806 genbit = q->genbit;
1807 pidx = q->pidx;
1352 q->pidx += count; 1808 q->pidx += count;
1353 if (q->pidx >= q->size) { 1809 if (q->pidx >= q->size) {
1354 q->pidx -= q->size; 1810 q->pidx -= q->size;
@@ -1374,6 +1830,14 @@ static int t1_sge_tx(struct sk_buff *skb, struct adapter *adapter,
1374 writel(F_CMDQ0_ENABLE, adapter->regs + A_SG_DOORBELL); 1830 writel(F_CMDQ0_ENABLE, adapter->regs + A_SG_DOORBELL);
1375 } 1831 }
1376 } 1832 }
1833
1834 if (use_sched_skb) {
1835 if (spin_trylock(&q->lock)) {
1836 credits = q->size - q->in_use;
1837 skb = NULL;
1838 goto use_sched;
1839 }
1840 }
1377 return NETDEV_TX_OK; 1841 return NETDEV_TX_OK;
1378} 1842}
1379 1843
@@ -1402,8 +1866,10 @@ int t1_start_xmit(struct sk_buff *skb, struct net_device *dev)
1402 struct sge *sge = adapter->sge; 1866 struct sge *sge = adapter->sge;
1403 struct cpl_tx_pkt *cpl; 1867 struct cpl_tx_pkt *cpl;
1404 1868
1405#ifdef NETIF_F_TSO 1869 if (skb->protocol == htons(ETH_P_CPL5))
1406 if (skb_is_gso(skb)) { 1870 goto send;
1871
1872 if (skb_shinfo(skb)->gso_size) {
1407 int eth_type; 1873 int eth_type;
1408 struct cpl_tx_pkt_lso *hdr; 1874 struct cpl_tx_pkt_lso *hdr;
1409 1875
@@ -1418,13 +1884,11 @@ int t1_start_xmit(struct sk_buff *skb, struct net_device *dev)
1418 hdr->ip_hdr_words = skb->nh.iph->ihl; 1884 hdr->ip_hdr_words = skb->nh.iph->ihl;
1419 hdr->tcp_hdr_words = skb->h.th->doff; 1885 hdr->tcp_hdr_words = skb->h.th->doff;
1420 hdr->eth_type_mss = htons(MK_ETH_TYPE_MSS(eth_type, 1886 hdr->eth_type_mss = htons(MK_ETH_TYPE_MSS(eth_type,
1421 skb_shinfo(skb)->gso_size)); 1887 skb_shinfo(skb)->gso_size));
1422 hdr->len = htonl(skb->len - sizeof(*hdr)); 1888 hdr->len = htonl(skb->len - sizeof(*hdr));
1423 cpl = (struct cpl_tx_pkt *)hdr; 1889 cpl = (struct cpl_tx_pkt *)hdr;
1424 sge->stats.tx_lso_pkts++; 1890 sge->stats.tx_lso_pkts++;
1425 } else 1891 } else {
1426#endif
1427 {
1428 /* 1892 /*
1429 * Packets shorter than ETH_HLEN can break the MAC, drop them 1893 * Packets shorter than ETH_HLEN can break the MAC, drop them
1430 * early. Also, we may get oversized packets because some 1894 * early. Also, we may get oversized packets because some
@@ -1433,6 +1897,8 @@ int t1_start_xmit(struct sk_buff *skb, struct net_device *dev)
1433 */ 1897 */
1434 if (unlikely(skb->len < ETH_HLEN || 1898 if (unlikely(skb->len < ETH_HLEN ||
1435 skb->len > dev->mtu + eth_hdr_len(skb->data))) { 1899 skb->len > dev->mtu + eth_hdr_len(skb->data))) {
1900 pr_debug("%s: packet size %d hdr %d mtu%d\n", dev->name,
1901 skb->len, eth_hdr_len(skb->data), dev->mtu);
1436 dev_kfree_skb_any(skb); 1902 dev_kfree_skb_any(skb);
1437 return NETDEV_TX_OK; 1903 return NETDEV_TX_OK;
1438 } 1904 }
@@ -1442,10 +1908,12 @@ int t1_start_xmit(struct sk_buff *skb, struct net_device *dev)
1442 * components, such as pktgen, do not handle it right. 1908 * components, such as pktgen, do not handle it right.
1443 * Complain when this happens but try to fix things up. 1909 * Complain when this happens but try to fix things up.
1444 */ 1910 */
1445 if (unlikely(skb_headroom(skb) < 1911 if (unlikely(skb_headroom(skb) < dev->hard_header_len - ETH_HLEN)) {
1446 dev->hard_header_len - ETH_HLEN)) {
1447 struct sk_buff *orig_skb = skb; 1912 struct sk_buff *orig_skb = skb;
1448 1913
1914 pr_debug("%s: headroom %d header_len %d\n", dev->name,
1915 skb_headroom(skb), dev->hard_header_len);
1916
1449 if (net_ratelimit()) 1917 if (net_ratelimit())
1450 printk(KERN_ERR "%s: inadequate headroom in " 1918 printk(KERN_ERR "%s: inadequate headroom in "
1451 "Tx packet\n", dev->name); 1919 "Tx packet\n", dev->name);
@@ -1457,19 +1925,21 @@ int t1_start_xmit(struct sk_buff *skb, struct net_device *dev)
1457 1925
1458 if (!(adapter->flags & UDP_CSUM_CAPABLE) && 1926 if (!(adapter->flags & UDP_CSUM_CAPABLE) &&
1459 skb->ip_summed == CHECKSUM_PARTIAL && 1927 skb->ip_summed == CHECKSUM_PARTIAL &&
1460 skb->nh.iph->protocol == IPPROTO_UDP) 1928 skb->nh.iph->protocol == IPPROTO_UDP) {
1461 if (unlikely(skb_checksum_help(skb))) { 1929 if (unlikely(skb_checksum_help(skb))) {
1930 pr_debug("%s: unable to do udp checksum\n", dev->name);
1462 dev_kfree_skb_any(skb); 1931 dev_kfree_skb_any(skb);
1463 return NETDEV_TX_OK; 1932 return NETDEV_TX_OK;
1464 } 1933 }
1934 }
1465 1935
1466 /* Hmmm, assuming to catch the gratious arp... and we'll use 1936 /* Hmmm, assuming to catch the gratious arp... and we'll use
1467 * it to flush out stuck espi packets... 1937 * it to flush out stuck espi packets...
1468 */ 1938 */
1469 if (unlikely(!adapter->sge->espibug_skb)) { 1939 if ((unlikely(!adapter->sge->espibug_skb[dev->if_port]))) {
1470 if (skb->protocol == htons(ETH_P_ARP) && 1940 if (skb->protocol == htons(ETH_P_ARP) &&
1471 skb->nh.arph->ar_op == htons(ARPOP_REQUEST)) { 1941 skb->nh.arph->ar_op == htons(ARPOP_REQUEST)) {
1472 adapter->sge->espibug_skb = skb; 1942 adapter->sge->espibug_skb[dev->if_port] = skb;
1473 /* We want to re-use this skb later. We 1943 /* We want to re-use this skb later. We
1474 * simply bump the reference count and it 1944 * simply bump the reference count and it
1475 * will not be freed... 1945 * will not be freed...
@@ -1499,6 +1969,7 @@ int t1_start_xmit(struct sk_buff *skb, struct net_device *dev)
1499#endif 1969#endif
1500 cpl->vlan_valid = 0; 1970 cpl->vlan_valid = 0;
1501 1971
1972send:
1502 dev->trans_start = jiffies; 1973 dev->trans_start = jiffies;
1503 return t1_sge_tx(skb, adapter, 0, dev); 1974 return t1_sge_tx(skb, adapter, 0, dev);
1504} 1975}
@@ -1518,10 +1989,9 @@ static void sge_tx_reclaim_cb(unsigned long data)
1518 continue; 1989 continue;
1519 1990
1520 reclaim_completed_tx(sge, q); 1991 reclaim_completed_tx(sge, q);
1521 if (i == 0 && q->in_use) /* flush pending credits */ 1992 if (i == 0 && q->in_use) { /* flush pending credits */
1522 writel(F_CMDQ0_ENABLE, 1993 writel(F_CMDQ0_ENABLE, sge->adapter->regs + A_SG_DOORBELL);
1523 sge->adapter->regs + A_SG_DOORBELL); 1994 }
1524
1525 spin_unlock(&q->lock); 1995 spin_unlock(&q->lock);
1526 } 1996 }
1527 mod_timer(&sge->tx_reclaim_timer, jiffies + TX_RECLAIM_PERIOD); 1997 mod_timer(&sge->tx_reclaim_timer, jiffies + TX_RECLAIM_PERIOD);
@@ -1568,11 +2038,20 @@ int t1_sge_configure(struct sge *sge, struct sge_params *p)
1568 */ 2038 */
1569void t1_sge_stop(struct sge *sge) 2039void t1_sge_stop(struct sge *sge)
1570{ 2040{
2041 int i;
1571 writel(0, sge->adapter->regs + A_SG_CONTROL); 2042 writel(0, sge->adapter->regs + A_SG_CONTROL);
1572 (void) readl(sge->adapter->regs + A_SG_CONTROL); /* flush */ 2043 readl(sge->adapter->regs + A_SG_CONTROL); /* flush */
2044
1573 if (is_T2(sge->adapter)) 2045 if (is_T2(sge->adapter))
1574 del_timer_sync(&sge->espibug_timer); 2046 del_timer_sync(&sge->espibug_timer);
2047
1575 del_timer_sync(&sge->tx_reclaim_timer); 2048 del_timer_sync(&sge->tx_reclaim_timer);
2049 if (sge->tx_sched)
2050 tx_sched_stop(sge);
2051
2052 for (i = 0; i < MAX_NPORTS; i++)
2053 if (sge->espibug_skb[i])
2054 kfree_skb(sge->espibug_skb[i]);
1576} 2055}
1577 2056
1578/* 2057/*
@@ -1585,48 +2064,86 @@ void t1_sge_start(struct sge *sge)
1585 2064
1586 writel(sge->sge_control, sge->adapter->regs + A_SG_CONTROL); 2065 writel(sge->sge_control, sge->adapter->regs + A_SG_CONTROL);
1587 doorbell_pio(sge->adapter, F_FL0_ENABLE | F_FL1_ENABLE); 2066 doorbell_pio(sge->adapter, F_FL0_ENABLE | F_FL1_ENABLE);
1588 (void) readl(sge->adapter->regs + A_SG_CONTROL); /* flush */ 2067 readl(sge->adapter->regs + A_SG_CONTROL); /* flush */
1589 2068
1590 mod_timer(&sge->tx_reclaim_timer, jiffies + TX_RECLAIM_PERIOD); 2069 mod_timer(&sge->tx_reclaim_timer, jiffies + TX_RECLAIM_PERIOD);
1591 2070
1592 if (is_T2(sge->adapter)) 2071 if (is_T2(sge->adapter))
1593 mod_timer(&sge->espibug_timer, jiffies + sge->espibug_timeout); 2072 mod_timer(&sge->espibug_timer, jiffies + sge->espibug_timeout);
1594} 2073}
1595 2074
1596/* 2075/*
1597 * Callback for the T2 ESPI 'stuck packet feature' workaorund 2076 * Callback for the T2 ESPI 'stuck packet feature' workaorund
1598 */ 2077 */
1599static void espibug_workaround(void *data) 2078static void espibug_workaround_t204(unsigned long data)
1600{ 2079{
1601 struct adapter *adapter = (struct adapter *)data; 2080 struct adapter *adapter = (struct adapter *)data;
1602 struct sge *sge = adapter->sge; 2081 struct sge *sge = adapter->sge;
2082 unsigned int nports = adapter->params.nports;
2083 u32 seop[MAX_NPORTS];
1603 2084
1604 if (netif_running(adapter->port[0].dev)) { 2085 if (adapter->open_device_map & PORT_MASK) {
1605 struct sk_buff *skb = sge->espibug_skb; 2086 int i;
1606 2087 if (t1_espi_get_mon_t204(adapter, &(seop[0]), 0) < 0) {
1607 u32 seop = t1_espi_get_mon(adapter, 0x930, 0); 2088 return;
1608 2089 }
1609 if ((seop & 0xfff0fff) == 0xfff && skb) { 2090 for (i = 0; i < nports; i++) {
1610 if (!skb->cb[0]) { 2091 struct sk_buff *skb = sge->espibug_skb[i];
1611 u8 ch_mac_addr[ETH_ALEN] = 2092 if ( (netif_running(adapter->port[i].dev)) &&
1612 {0x0, 0x7, 0x43, 0x0, 0x0, 0x0}; 2093 !(netif_queue_stopped(adapter->port[i].dev)) &&
1613 memcpy(skb->data + sizeof(struct cpl_tx_pkt), 2094 (seop[i] && ((seop[i] & 0xfff) == 0)) &&
1614 ch_mac_addr, ETH_ALEN); 2095 skb ) {
1615 memcpy(skb->data + skb->len - 10, ch_mac_addr, 2096 if (!skb->cb[0]) {
1616 ETH_ALEN); 2097 u8 ch_mac_addr[ETH_ALEN] =
1617 skb->cb[0] = 0xff; 2098 {0x0, 0x7, 0x43, 0x0, 0x0, 0x0};
2099 memcpy(skb->data + sizeof(struct cpl_tx_pkt),
2100 ch_mac_addr, ETH_ALEN);
2101 memcpy(skb->data + skb->len - 10,
2102 ch_mac_addr, ETH_ALEN);
2103 skb->cb[0] = 0xff;
2104 }
2105
2106 /* bump the reference count to avoid freeing of
2107 * the skb once the DMA has completed.
2108 */
2109 skb = skb_get(skb);
2110 t1_sge_tx(skb, adapter, 0, adapter->port[i].dev);
1618 } 2111 }
1619
1620 /* bump the reference count to avoid freeing of the
1621 * skb once the DMA has completed.
1622 */
1623 skb = skb_get(skb);
1624 t1_sge_tx(skb, adapter, 0, adapter->port[0].dev);
1625 } 2112 }
1626 } 2113 }
1627 mod_timer(&sge->espibug_timer, jiffies + sge->espibug_timeout); 2114 mod_timer(&sge->espibug_timer, jiffies + sge->espibug_timeout);
1628} 2115}
1629 2116
2117static void espibug_workaround(unsigned long data)
2118{
2119 struct adapter *adapter = (struct adapter *)data;
2120 struct sge *sge = adapter->sge;
2121
2122 if (netif_running(adapter->port[0].dev)) {
2123 struct sk_buff *skb = sge->espibug_skb[0];
2124 u32 seop = t1_espi_get_mon(adapter, 0x930, 0);
2125
2126 if ((seop & 0xfff0fff) == 0xfff && skb) {
2127 if (!skb->cb[0]) {
2128 u8 ch_mac_addr[ETH_ALEN] =
2129 {0x0, 0x7, 0x43, 0x0, 0x0, 0x0};
2130 memcpy(skb->data + sizeof(struct cpl_tx_pkt),
2131 ch_mac_addr, ETH_ALEN);
2132 memcpy(skb->data + skb->len - 10, ch_mac_addr,
2133 ETH_ALEN);
2134 skb->cb[0] = 0xff;
2135 }
2136
2137 /* bump the reference count to avoid freeing of the
2138 * skb once the DMA has completed.
2139 */
2140 skb = skb_get(skb);
2141 t1_sge_tx(skb, adapter, 0, adapter->port[0].dev);
2142 }
2143 }
2144 mod_timer(&sge->espibug_timer, jiffies + sge->espibug_timeout);
2145}
2146
1630/* 2147/*
1631 * Creates a t1_sge structure and returns suggested resource parameters. 2148 * Creates a t1_sge structure and returns suggested resource parameters.
1632 */ 2149 */
@@ -1649,9 +2166,19 @@ struct sge * __devinit t1_sge_create(struct adapter *adapter,
1649 2166
1650 if (is_T2(sge->adapter)) { 2167 if (is_T2(sge->adapter)) {
1651 init_timer(&sge->espibug_timer); 2168 init_timer(&sge->espibug_timer);
1652 sge->espibug_timer.function = (void *)&espibug_workaround; 2169
2170 if (adapter->params.nports > 1) {
2171 tx_sched_init(sge);
2172 sge->espibug_timer.function = espibug_workaround_t204;
2173 } else {
2174 sge->espibug_timer.function = espibug_workaround;
2175 }
1653 sge->espibug_timer.data = (unsigned long)sge->adapter; 2176 sge->espibug_timer.data = (unsigned long)sge->adapter;
2177
1654 sge->espibug_timeout = 1; 2178 sge->espibug_timeout = 1;
2179 /* for T204, every 10ms */
2180 if (adapter->params.nports > 1)
2181 sge->espibug_timeout = HZ/100;
1655 } 2182 }
1656 2183
1657 2184
@@ -1659,7 +2186,14 @@ struct sge * __devinit t1_sge_create(struct adapter *adapter,
1659 p->cmdQ_size[1] = SGE_CMDQ1_E_N; 2186 p->cmdQ_size[1] = SGE_CMDQ1_E_N;
1660 p->freelQ_size[!sge->jumbo_fl] = SGE_FREEL_SIZE; 2187 p->freelQ_size[!sge->jumbo_fl] = SGE_FREEL_SIZE;
1661 p->freelQ_size[sge->jumbo_fl] = SGE_JUMBO_FREEL_SIZE; 2188 p->freelQ_size[sge->jumbo_fl] = SGE_JUMBO_FREEL_SIZE;
1662 p->rx_coalesce_usecs = 50; 2189 if (sge->tx_sched) {
2190 if (board_info(sge->adapter)->board == CHBT_BOARD_CHT204)
2191 p->rx_coalesce_usecs = 15;
2192 else
2193 p->rx_coalesce_usecs = 50;
2194 } else
2195 p->rx_coalesce_usecs = 50;
2196
1663 p->coalesce_enable = 0; 2197 p->coalesce_enable = 0;
1664 p->sample_interval_usecs = 0; 2198 p->sample_interval_usecs = 0;
1665 p->polling = 0; 2199 p->polling = 0;