1
2
3
4
5
6
7
8#include <linux/kernel.h>
9#include <linux/init.h>
10#include <linux/bitops.h>
11#include <linux/types.h>
12#include <linux/module.h>
13#include <linux/list.h>
14#include <linux/pci.h>
15#include <linux/dma-mapping.h>
16#include <linux/pagemap.h>
17#include <linux/sched.h>
18#include <linux/slab.h>
19#include <linux/dmapool.h>
20#include <linux/mempool.h>
21#include <linux/spinlock.h>
22#include <linux/kthread.h>
23#include <linux/interrupt.h>
24#include <linux/errno.h>
25#include <linux/ioport.h>
26#include <linux/in.h>
27#include <linux/ip.h>
28#include <linux/ipv6.h>
29#include <net/ipv6.h>
30#include <linux/tcp.h>
31#include <linux/udp.h>
32#include <linux/if_arp.h>
33#include <linux/if_ether.h>
34#include <linux/netdevice.h>
35#include <linux/etherdevice.h>
36#include <linux/ethtool.h>
37#include <linux/if_vlan.h>
38#include <linux/skbuff.h>
39#include <linux/delay.h>
40#include <linux/mm.h>
41#include <linux/vmalloc.h>
42#include <linux/prefetch.h>
43#include <net/ip6_checksum.h>
44
45#include "qlge.h"
46
47char qlge_driver_name[] = DRV_NAME;
48const char qlge_driver_version[] = DRV_VERSION;
49
50MODULE_AUTHOR("Ron Mercer <ron.mercer@qlogic.com>");
51MODULE_DESCRIPTION(DRV_STRING " ");
52MODULE_LICENSE("GPL");
53MODULE_VERSION(DRV_VERSION);
54
55static const u32 default_msg =
56 NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK |
57
58 NETIF_MSG_IFDOWN |
59 NETIF_MSG_IFUP |
60 NETIF_MSG_RX_ERR |
61 NETIF_MSG_TX_ERR |
62
63
64
65 NETIF_MSG_HW | NETIF_MSG_WOL | 0;
66
67static int debug = -1;
68module_param(debug, int, 0664);
69MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
70
71#define MSIX_IRQ 0
72#define MSI_IRQ 1
73#define LEG_IRQ 2
74static int qlge_irq_type = MSIX_IRQ;
75module_param(qlge_irq_type, int, 0664);
76MODULE_PARM_DESC(qlge_irq_type, "0 = MSI-X, 1 = MSI, 2 = Legacy.");
77
78static int qlge_mpi_coredump;
79module_param(qlge_mpi_coredump, int, 0);
80MODULE_PARM_DESC(qlge_mpi_coredump,
81 "Option to enable MPI firmware dump. "
82 "Default is OFF - Do Not allocate memory. ");
83
84static int qlge_force_coredump;
85module_param(qlge_force_coredump, int, 0);
86MODULE_PARM_DESC(qlge_force_coredump,
87 "Option to allow force of firmware core dump. "
88 "Default is OFF - Do not allow.");
89
90static DEFINE_PCI_DEVICE_TABLE(qlge_pci_tbl) = {
91 {PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, QLGE_DEVICE_ID_8012)},
92 {PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, QLGE_DEVICE_ID_8000)},
93
94 {0,}
95};
96
97MODULE_DEVICE_TABLE(pci, qlge_pci_tbl);
98
99static int ql_wol(struct ql_adapter *qdev);
100static void qlge_set_multicast_list(struct net_device *ndev);
101
102
103
104
105
106static int ql_sem_trylock(struct ql_adapter *qdev, u32 sem_mask)
107{
108 u32 sem_bits = 0;
109
110 switch (sem_mask) {
111 case SEM_XGMAC0_MASK:
112 sem_bits = SEM_SET << SEM_XGMAC0_SHIFT;
113 break;
114 case SEM_XGMAC1_MASK:
115 sem_bits = SEM_SET << SEM_XGMAC1_SHIFT;
116 break;
117 case SEM_ICB_MASK:
118 sem_bits = SEM_SET << SEM_ICB_SHIFT;
119 break;
120 case SEM_MAC_ADDR_MASK:
121 sem_bits = SEM_SET << SEM_MAC_ADDR_SHIFT;
122 break;
123 case SEM_FLASH_MASK:
124 sem_bits = SEM_SET << SEM_FLASH_SHIFT;
125 break;
126 case SEM_PROBE_MASK:
127 sem_bits = SEM_SET << SEM_PROBE_SHIFT;
128 break;
129 case SEM_RT_IDX_MASK:
130 sem_bits = SEM_SET << SEM_RT_IDX_SHIFT;
131 break;
132 case SEM_PROC_REG_MASK:
133 sem_bits = SEM_SET << SEM_PROC_REG_SHIFT;
134 break;
135 default:
136 netif_alert(qdev, probe, qdev->ndev, "bad Semaphore mask!.\n");
137 return -EINVAL;
138 }
139
140 ql_write32(qdev, SEM, sem_bits | sem_mask);
141 return !(ql_read32(qdev, SEM) & sem_bits);
142}
143
144int ql_sem_spinlock(struct ql_adapter *qdev, u32 sem_mask)
145{
146 unsigned int wait_count = 30;
147 do {
148 if (!ql_sem_trylock(qdev, sem_mask))
149 return 0;
150 udelay(100);
151 } while (--wait_count);
152 return -ETIMEDOUT;
153}
154
155void ql_sem_unlock(struct ql_adapter *qdev, u32 sem_mask)
156{
157 ql_write32(qdev, SEM, sem_mask);
158 ql_read32(qdev, SEM);
159}
160
161
162
163
164
165
166int ql_wait_reg_rdy(struct ql_adapter *qdev, u32 reg, u32 bit, u32 err_bit)
167{
168 u32 temp;
169 int count = UDELAY_COUNT;
170
171 while (count) {
172 temp = ql_read32(qdev, reg);
173
174
175 if (temp & err_bit) {
176 netif_alert(qdev, probe, qdev->ndev,
177 "register 0x%.08x access error, value = 0x%.08x!.\n",
178 reg, temp);
179 return -EIO;
180 } else if (temp & bit)
181 return 0;
182 udelay(UDELAY_DELAY);
183 count--;
184 }
185 netif_alert(qdev, probe, qdev->ndev,
186 "Timed out waiting for reg %x to come ready.\n", reg);
187 return -ETIMEDOUT;
188}
189
190
191
192
193static int ql_wait_cfg(struct ql_adapter *qdev, u32 bit)
194{
195 int count = UDELAY_COUNT;
196 u32 temp;
197
198 while (count) {
199 temp = ql_read32(qdev, CFG);
200 if (temp & CFG_LE)
201 return -EIO;
202 if (!(temp & bit))
203 return 0;
204 udelay(UDELAY_DELAY);
205 count--;
206 }
207 return -ETIMEDOUT;
208}
209
210
211
212
213
214int ql_write_cfg(struct ql_adapter *qdev, void *ptr, int size, u32 bit,
215 u16 q_id)
216{
217 u64 map;
218 int status = 0;
219 int direction;
220 u32 mask;
221 u32 value;
222
223 direction =
224 (bit & (CFG_LRQ | CFG_LR | CFG_LCQ)) ? PCI_DMA_TODEVICE :
225 PCI_DMA_FROMDEVICE;
226
227 map = pci_map_single(qdev->pdev, ptr, size, direction);
228 if (pci_dma_mapping_error(qdev->pdev, map)) {
229 netif_err(qdev, ifup, qdev->ndev, "Couldn't map DMA area.\n");
230 return -ENOMEM;
231 }
232
233 status = ql_sem_spinlock(qdev, SEM_ICB_MASK);
234 if (status)
235 return status;
236
237 status = ql_wait_cfg(qdev, bit);
238 if (status) {
239 netif_err(qdev, ifup, qdev->ndev,
240 "Timed out waiting for CFG to come ready.\n");
241 goto exit;
242 }
243
244 ql_write32(qdev, ICB_L, (u32) map);
245 ql_write32(qdev, ICB_H, (u32) (map >> 32));
246
247 mask = CFG_Q_MASK | (bit << 16);
248 value = bit | (q_id << CFG_Q_SHIFT);
249 ql_write32(qdev, CFG, (mask | value));
250
251
252
253
254 status = ql_wait_cfg(qdev, bit);
255exit:
256 ql_sem_unlock(qdev, SEM_ICB_MASK);
257 pci_unmap_single(qdev->pdev, map, size, direction);
258 return status;
259}
260
261
262int ql_get_mac_addr_reg(struct ql_adapter *qdev, u32 type, u16 index,
263 u32 *value)
264{
265 u32 offset = 0;
266 int status;
267
268 switch (type) {
269 case MAC_ADDR_TYPE_MULTI_MAC:
270 case MAC_ADDR_TYPE_CAM_MAC:
271 {
272 status =
273 ql_wait_reg_rdy(qdev,
274 MAC_ADDR_IDX, MAC_ADDR_MW, 0);
275 if (status)
276 goto exit;
277 ql_write32(qdev, MAC_ADDR_IDX, (offset++) |
278 (index << MAC_ADDR_IDX_SHIFT) |
279 MAC_ADDR_ADR | MAC_ADDR_RS | type);
280 status =
281 ql_wait_reg_rdy(qdev,
282 MAC_ADDR_IDX, MAC_ADDR_MR, 0);
283 if (status)
284 goto exit;
285 *value++ = ql_read32(qdev, MAC_ADDR_DATA);
286 status =
287 ql_wait_reg_rdy(qdev,
288 MAC_ADDR_IDX, MAC_ADDR_MW, 0);
289 if (status)
290 goto exit;
291 ql_write32(qdev, MAC_ADDR_IDX, (offset++) |
292 (index << MAC_ADDR_IDX_SHIFT) |
293 MAC_ADDR_ADR | MAC_ADDR_RS | type);
294 status =
295 ql_wait_reg_rdy(qdev,
296 MAC_ADDR_IDX, MAC_ADDR_MR, 0);
297 if (status)
298 goto exit;
299 *value++ = ql_read32(qdev, MAC_ADDR_DATA);
300 if (type == MAC_ADDR_TYPE_CAM_MAC) {
301 status =
302 ql_wait_reg_rdy(qdev,
303 MAC_ADDR_IDX, MAC_ADDR_MW, 0);
304 if (status)
305 goto exit;
306 ql_write32(qdev, MAC_ADDR_IDX, (offset++) |
307 (index << MAC_ADDR_IDX_SHIFT) |
308 MAC_ADDR_ADR | MAC_ADDR_RS | type);
309 status =
310 ql_wait_reg_rdy(qdev, MAC_ADDR_IDX,
311 MAC_ADDR_MR, 0);
312 if (status)
313 goto exit;
314 *value++ = ql_read32(qdev, MAC_ADDR_DATA);
315 }
316 break;
317 }
318 case MAC_ADDR_TYPE_VLAN:
319 case MAC_ADDR_TYPE_MULTI_FLTR:
320 default:
321 netif_crit(qdev, ifup, qdev->ndev,
322 "Address type %d not yet supported.\n", type);
323 status = -EPERM;
324 }
325exit:
326 return status;
327}
328
329
330
331
332static int ql_set_mac_addr_reg(struct ql_adapter *qdev, u8 *addr, u32 type,
333 u16 index)
334{
335 u32 offset = 0;
336 int status = 0;
337
338 switch (type) {
339 case MAC_ADDR_TYPE_MULTI_MAC:
340 {
341 u32 upper = (addr[0] << 8) | addr[1];
342 u32 lower = (addr[2] << 24) | (addr[3] << 16) |
343 (addr[4] << 8) | (addr[5]);
344
345 status =
346 ql_wait_reg_rdy(qdev,
347 MAC_ADDR_IDX, MAC_ADDR_MW, 0);
348 if (status)
349 goto exit;
350 ql_write32(qdev, MAC_ADDR_IDX, (offset++) |
351 (index << MAC_ADDR_IDX_SHIFT) |
352 type | MAC_ADDR_E);
353 ql_write32(qdev, MAC_ADDR_DATA, lower);
354 status =
355 ql_wait_reg_rdy(qdev,
356 MAC_ADDR_IDX, MAC_ADDR_MW, 0);
357 if (status)
358 goto exit;
359 ql_write32(qdev, MAC_ADDR_IDX, (offset++) |
360 (index << MAC_ADDR_IDX_SHIFT) |
361 type | MAC_ADDR_E);
362
363 ql_write32(qdev, MAC_ADDR_DATA, upper);
364 status =
365 ql_wait_reg_rdy(qdev,
366 MAC_ADDR_IDX, MAC_ADDR_MW, 0);
367 if (status)
368 goto exit;
369 break;
370 }
371 case MAC_ADDR_TYPE_CAM_MAC:
372 {
373 u32 cam_output;
374 u32 upper = (addr[0] << 8) | addr[1];
375 u32 lower =
376 (addr[2] << 24) | (addr[3] << 16) | (addr[4] << 8) |
377 (addr[5]);
378 status =
379 ql_wait_reg_rdy(qdev,
380 MAC_ADDR_IDX, MAC_ADDR_MW, 0);
381 if (status)
382 goto exit;
383 ql_write32(qdev, MAC_ADDR_IDX, (offset++) |
384 (index << MAC_ADDR_IDX_SHIFT) |
385 type);
386 ql_write32(qdev, MAC_ADDR_DATA, lower);
387 status =
388 ql_wait_reg_rdy(qdev,
389 MAC_ADDR_IDX, MAC_ADDR_MW, 0);
390 if (status)
391 goto exit;
392 ql_write32(qdev, MAC_ADDR_IDX, (offset++) |
393 (index << MAC_ADDR_IDX_SHIFT) |
394 type);
395 ql_write32(qdev, MAC_ADDR_DATA, upper);
396 status =
397 ql_wait_reg_rdy(qdev,
398 MAC_ADDR_IDX, MAC_ADDR_MW, 0);
399 if (status)
400 goto exit;
401 ql_write32(qdev, MAC_ADDR_IDX, (offset) |
402 (index << MAC_ADDR_IDX_SHIFT) |
403 type);
404
405
406
407
408 cam_output = (CAM_OUT_ROUTE_NIC |
409 (qdev->
410 func << CAM_OUT_FUNC_SHIFT) |
411 (0 << CAM_OUT_CQ_ID_SHIFT));
412 if (qdev->ndev->features & NETIF_F_HW_VLAN_RX)
413 cam_output |= CAM_OUT_RV;
414
415 ql_write32(qdev, MAC_ADDR_DATA, cam_output);
416 break;
417 }
418 case MAC_ADDR_TYPE_VLAN:
419 {
420 u32 enable_bit = *((u32 *) &addr[0]);
421
422
423
424
425
426 status =
427 ql_wait_reg_rdy(qdev,
428 MAC_ADDR_IDX, MAC_ADDR_MW, 0);
429 if (status)
430 goto exit;
431 ql_write32(qdev, MAC_ADDR_IDX, offset |
432 (index << MAC_ADDR_IDX_SHIFT) |
433 type |
434 enable_bit);
435 break;
436 }
437 case MAC_ADDR_TYPE_MULTI_FLTR:
438 default:
439 netif_crit(qdev, ifup, qdev->ndev,
440 "Address type %d not yet supported.\n", type);
441 status = -EPERM;
442 }
443exit:
444 return status;
445}
446
447
448
449
450
451static int ql_set_mac_addr(struct ql_adapter *qdev, int set)
452{
453 int status;
454 char zero_mac_addr[ETH_ALEN];
455 char *addr;
456
457 if (set) {
458 addr = &qdev->current_mac_addr[0];
459 netif_printk(qdev, ifup, KERN_DEBUG, qdev->ndev,
460 "Set Mac addr %pM\n", addr);
461 } else {
462 memset(zero_mac_addr, 0, ETH_ALEN);
463 addr = &zero_mac_addr[0];
464 netif_printk(qdev, ifup, KERN_DEBUG, qdev->ndev,
465 "Clearing MAC address\n");
466 }
467 status = ql_sem_spinlock(qdev, SEM_MAC_ADDR_MASK);
468 if (status)
469 return status;
470 status = ql_set_mac_addr_reg(qdev, (u8 *) addr,
471 MAC_ADDR_TYPE_CAM_MAC, qdev->func * MAX_CQ);
472 ql_sem_unlock(qdev, SEM_MAC_ADDR_MASK);
473 if (status)
474 netif_err(qdev, ifup, qdev->ndev,
475 "Failed to init mac address.\n");
476 return status;
477}
478
479void ql_link_on(struct ql_adapter *qdev)
480{
481 netif_err(qdev, link, qdev->ndev, "Link is up.\n");
482 netif_carrier_on(qdev->ndev);
483 ql_set_mac_addr(qdev, 1);
484}
485
486void ql_link_off(struct ql_adapter *qdev)
487{
488 netif_err(qdev, link, qdev->ndev, "Link is down.\n");
489 netif_carrier_off(qdev->ndev);
490 ql_set_mac_addr(qdev, 0);
491}
492
493
494
495
496int ql_get_routing_reg(struct ql_adapter *qdev, u32 index, u32 *value)
497{
498 int status = 0;
499
500 status = ql_wait_reg_rdy(qdev, RT_IDX, RT_IDX_MW, 0);
501 if (status)
502 goto exit;
503
504 ql_write32(qdev, RT_IDX,
505 RT_IDX_TYPE_NICQ | RT_IDX_RS | (index << RT_IDX_IDX_SHIFT));
506 status = ql_wait_reg_rdy(qdev, RT_IDX, RT_IDX_MR, 0);
507 if (status)
508 goto exit;
509 *value = ql_read32(qdev, RT_DATA);
510exit:
511 return status;
512}
513
514
515
516
517
518
519static int ql_set_routing_reg(struct ql_adapter *qdev, u32 index, u32 mask,
520 int enable)
521{
522 int status = -EINVAL;
523 u32 value = 0;
524
525 switch (mask) {
526 case RT_IDX_CAM_HIT:
527 {
528 value = RT_IDX_DST_CAM_Q |
529 RT_IDX_TYPE_NICQ |
530 (RT_IDX_CAM_HIT_SLOT << RT_IDX_IDX_SHIFT);
531 break;
532 }
533 case RT_IDX_VALID:
534 {
535 value = RT_IDX_DST_DFLT_Q |
536 RT_IDX_TYPE_NICQ |
537 (RT_IDX_PROMISCUOUS_SLOT << RT_IDX_IDX_SHIFT);
538 break;
539 }
540 case RT_IDX_ERR:
541 {
542 value = RT_IDX_DST_DFLT_Q |
543 RT_IDX_TYPE_NICQ |
544 (RT_IDX_ALL_ERR_SLOT << RT_IDX_IDX_SHIFT);
545 break;
546 }
547 case RT_IDX_IP_CSUM_ERR:
548 {
549 value = RT_IDX_DST_DFLT_Q |
550 RT_IDX_TYPE_NICQ |
551 (RT_IDX_IP_CSUM_ERR_SLOT <<
552 RT_IDX_IDX_SHIFT);
553 break;
554 }
555 case RT_IDX_TU_CSUM_ERR:
556 {
557 value = RT_IDX_DST_DFLT_Q |
558 RT_IDX_TYPE_NICQ |
559 (RT_IDX_TCP_UDP_CSUM_ERR_SLOT <<
560 RT_IDX_IDX_SHIFT);
561 break;
562 }
563 case RT_IDX_BCAST:
564 {
565 value = RT_IDX_DST_DFLT_Q |
566 RT_IDX_TYPE_NICQ |
567 (RT_IDX_BCAST_SLOT << RT_IDX_IDX_SHIFT);
568 break;
569 }
570 case RT_IDX_MCAST:
571 {
572 value = RT_IDX_DST_DFLT_Q |
573 RT_IDX_TYPE_NICQ |
574 (RT_IDX_ALLMULTI_SLOT << RT_IDX_IDX_SHIFT);
575 break;
576 }
577 case RT_IDX_MCAST_MATCH:
578 {
579 value = RT_IDX_DST_DFLT_Q |
580 RT_IDX_TYPE_NICQ |
581 (RT_IDX_MCAST_MATCH_SLOT << RT_IDX_IDX_SHIFT);
582 break;
583 }
584 case RT_IDX_RSS_MATCH:
585 {
586 value = RT_IDX_DST_RSS |
587 RT_IDX_TYPE_NICQ |
588 (RT_IDX_RSS_MATCH_SLOT << RT_IDX_IDX_SHIFT);
589 break;
590 }
591 case 0:
592 {
593 value = RT_IDX_DST_DFLT_Q |
594 RT_IDX_TYPE_NICQ |
595 (index << RT_IDX_IDX_SHIFT);
596 break;
597 }
598 default:
599 netif_err(qdev, ifup, qdev->ndev,
600 "Mask type %d not yet supported.\n", mask);
601 status = -EPERM;
602 goto exit;
603 }
604
605 if (value) {
606 status = ql_wait_reg_rdy(qdev, RT_IDX, RT_IDX_MW, 0);
607 if (status)
608 goto exit;
609 value |= (enable ? RT_IDX_E : 0);
610 ql_write32(qdev, RT_IDX, value);
611 ql_write32(qdev, RT_DATA, enable ? mask : 0);
612 }
613exit:
614 return status;
615}
616
617static void ql_enable_interrupts(struct ql_adapter *qdev)
618{
619 ql_write32(qdev, INTR_EN, (INTR_EN_EI << 16) | INTR_EN_EI);
620}
621
622static void ql_disable_interrupts(struct ql_adapter *qdev)
623{
624 ql_write32(qdev, INTR_EN, (INTR_EN_EI << 16));
625}
626
627
628
629
630
631
632
633u32 ql_enable_completion_interrupt(struct ql_adapter *qdev, u32 intr)
634{
635 u32 var = 0;
636 unsigned long hw_flags = 0;
637 struct intr_context *ctx = qdev->intr_context + intr;
638
639 if (likely(test_bit(QL_MSIX_ENABLED, &qdev->flags) && intr)) {
640
641
642
643 ql_write32(qdev, INTR_EN,
644 ctx->intr_en_mask);
645 var = ql_read32(qdev, STS);
646 return var;
647 }
648
649 spin_lock_irqsave(&qdev->hw_lock, hw_flags);
650 if (atomic_dec_and_test(&ctx->irq_cnt)) {
651 ql_write32(qdev, INTR_EN,
652 ctx->intr_en_mask);
653 var = ql_read32(qdev, STS);
654 }
655 spin_unlock_irqrestore(&qdev->hw_lock, hw_flags);
656 return var;
657}
658
659static u32 ql_disable_completion_interrupt(struct ql_adapter *qdev, u32 intr)
660{
661 u32 var = 0;
662 struct intr_context *ctx;
663
664
665
666
667 if (likely(test_bit(QL_MSIX_ENABLED, &qdev->flags) && intr))
668 return 0;
669
670 ctx = qdev->intr_context + intr;
671 spin_lock(&qdev->hw_lock);
672 if (!atomic_read(&ctx->irq_cnt)) {
673 ql_write32(qdev, INTR_EN,
674 ctx->intr_dis_mask);
675 var = ql_read32(qdev, STS);
676 }
677 atomic_inc(&ctx->irq_cnt);
678 spin_unlock(&qdev->hw_lock);
679 return var;
680}
681
682static void ql_enable_all_completion_interrupts(struct ql_adapter *qdev)
683{
684 int i;
685 for (i = 0; i < qdev->intr_count; i++) {
686
687
688
689
690 if (unlikely(!test_bit(QL_MSIX_ENABLED, &qdev->flags) ||
691 i == 0))
692 atomic_set(&qdev->intr_context[i].irq_cnt, 1);
693 ql_enable_completion_interrupt(qdev, i);
694 }
695
696}
697
698static int ql_validate_flash(struct ql_adapter *qdev, u32 size, const char *str)
699{
700 int status, i;
701 u16 csum = 0;
702 __le16 *flash = (__le16 *)&qdev->flash;
703
704 status = strncmp((char *)&qdev->flash, str, 4);
705 if (status) {
706 netif_err(qdev, ifup, qdev->ndev, "Invalid flash signature.\n");
707 return status;
708 }
709
710 for (i = 0; i < size; i++)
711 csum += le16_to_cpu(*flash++);
712
713 if (csum)
714 netif_err(qdev, ifup, qdev->ndev,
715 "Invalid flash checksum, csum = 0x%.04x.\n", csum);
716
717 return csum;
718}
719
720static int ql_read_flash_word(struct ql_adapter *qdev, int offset, __le32 *data)
721{
722 int status = 0;
723
724 status = ql_wait_reg_rdy(qdev,
725 FLASH_ADDR, FLASH_ADDR_RDY, FLASH_ADDR_ERR);
726 if (status)
727 goto exit;
728
729 ql_write32(qdev, FLASH_ADDR, FLASH_ADDR_R | offset);
730
731 status = ql_wait_reg_rdy(qdev,
732 FLASH_ADDR, FLASH_ADDR_RDY, FLASH_ADDR_ERR);
733 if (status)
734 goto exit;
735
736
737
738
739 *data = cpu_to_le32(ql_read32(qdev, FLASH_DATA));
740exit:
741 return status;
742}
743
744static int ql_get_8000_flash_params(struct ql_adapter *qdev)
745{
746 u32 i, size;
747 int status;
748 __le32 *p = (__le32 *)&qdev->flash;
749 u32 offset;
750 u8 mac_addr[6];
751
752
753
754
755 if (!qdev->port)
756 offset = FUNC0_FLASH_OFFSET / sizeof(u32);
757 else
758 offset = FUNC1_FLASH_OFFSET / sizeof(u32);
759
760 if (ql_sem_spinlock(qdev, SEM_FLASH_MASK))
761 return -ETIMEDOUT;
762
763 size = sizeof(struct flash_params_8000) / sizeof(u32);
764 for (i = 0; i < size; i++, p++) {
765 status = ql_read_flash_word(qdev, i+offset, p);
766 if (status) {
767 netif_err(qdev, ifup, qdev->ndev,
768 "Error reading flash.\n");
769 goto exit;
770 }
771 }
772
773 status = ql_validate_flash(qdev,
774 sizeof(struct flash_params_8000) / sizeof(u16),
775 "8000");
776 if (status) {
777 netif_err(qdev, ifup, qdev->ndev, "Invalid flash.\n");
778 status = -EINVAL;
779 goto exit;
780 }
781
782
783
784
785 if (qdev->flash.flash_params_8000.data_type1 == 2)
786 memcpy(mac_addr,
787 qdev->flash.flash_params_8000.mac_addr1,
788 qdev->ndev->addr_len);
789 else
790 memcpy(mac_addr,
791 qdev->flash.flash_params_8000.mac_addr,
792 qdev->ndev->addr_len);
793
794 if (!is_valid_ether_addr(mac_addr)) {
795 netif_err(qdev, ifup, qdev->ndev, "Invalid MAC address.\n");
796 status = -EINVAL;
797 goto exit;
798 }
799
800 memcpy(qdev->ndev->dev_addr,
801 mac_addr,
802 qdev->ndev->addr_len);
803
804exit:
805 ql_sem_unlock(qdev, SEM_FLASH_MASK);
806 return status;
807}
808
809static int ql_get_8012_flash_params(struct ql_adapter *qdev)
810{
811 int i;
812 int status;
813 __le32 *p = (__le32 *)&qdev->flash;
814 u32 offset = 0;
815 u32 size = sizeof(struct flash_params_8012) / sizeof(u32);
816
817
818
819
820 if (qdev->port)
821 offset = size;
822
823 if (ql_sem_spinlock(qdev, SEM_FLASH_MASK))
824 return -ETIMEDOUT;
825
826 for (i = 0; i < size; i++, p++) {
827 status = ql_read_flash_word(qdev, i+offset, p);
828 if (status) {
829 netif_err(qdev, ifup, qdev->ndev,
830 "Error reading flash.\n");
831 goto exit;
832 }
833
834 }
835
836 status = ql_validate_flash(qdev,
837 sizeof(struct flash_params_8012) / sizeof(u16),
838 "8012");
839 if (status) {
840 netif_err(qdev, ifup, qdev->ndev, "Invalid flash.\n");
841 status = -EINVAL;
842 goto exit;
843 }
844
845 if (!is_valid_ether_addr(qdev->flash.flash_params_8012.mac_addr)) {
846 status = -EINVAL;
847 goto exit;
848 }
849
850 memcpy(qdev->ndev->dev_addr,
851 qdev->flash.flash_params_8012.mac_addr,
852 qdev->ndev->addr_len);
853
854exit:
855 ql_sem_unlock(qdev, SEM_FLASH_MASK);
856 return status;
857}
858
859
860
861
862
863static int ql_write_xgmac_reg(struct ql_adapter *qdev, u32 reg, u32 data)
864{
865 int status;
866
867 status = ql_wait_reg_rdy(qdev,
868 XGMAC_ADDR, XGMAC_ADDR_RDY, XGMAC_ADDR_XME);
869 if (status)
870 return status;
871
872 ql_write32(qdev, XGMAC_DATA, data);
873
874 ql_write32(qdev, XGMAC_ADDR, reg);
875 return status;
876}
877
878
879
880
881
882int ql_read_xgmac_reg(struct ql_adapter *qdev, u32 reg, u32 *data)
883{
884 int status = 0;
885
886 status = ql_wait_reg_rdy(qdev,
887 XGMAC_ADDR, XGMAC_ADDR_RDY, XGMAC_ADDR_XME);
888 if (status)
889 goto exit;
890
891 ql_write32(qdev, XGMAC_ADDR, reg | XGMAC_ADDR_R);
892
893 status = ql_wait_reg_rdy(qdev,
894 XGMAC_ADDR, XGMAC_ADDR_RDY, XGMAC_ADDR_XME);
895 if (status)
896 goto exit;
897
898 *data = ql_read32(qdev, XGMAC_DATA);
899exit:
900 return status;
901}
902
903
904int ql_read_xgmac_reg64(struct ql_adapter *qdev, u32 reg, u64 *data)
905{
906 int status = 0;
907 u32 hi = 0;
908 u32 lo = 0;
909
910 status = ql_read_xgmac_reg(qdev, reg, &lo);
911 if (status)
912 goto exit;
913
914 status = ql_read_xgmac_reg(qdev, reg + 4, &hi);
915 if (status)
916 goto exit;
917
918 *data = (u64) lo | ((u64) hi << 32);
919
920exit:
921 return status;
922}
923
924static int ql_8000_port_initialize(struct ql_adapter *qdev)
925{
926 int status;
927
928
929
930
931 status = ql_mb_about_fw(qdev);
932 if (status)
933 goto exit;
934 status = ql_mb_get_fw_state(qdev);
935 if (status)
936 goto exit;
937
938 queue_delayed_work(qdev->workqueue, &qdev->mpi_port_cfg_work, 0);
939exit:
940 return status;
941}
942
943
944
945
946
947
948
949static int ql_8012_port_initialize(struct ql_adapter *qdev)
950{
951 int status = 0;
952 u32 data;
953
954 if (ql_sem_trylock(qdev, qdev->xg_sem_mask)) {
955
956
957
958 netif_info(qdev, link, qdev->ndev,
959 "Another function has the semaphore, so wait for the port init bit to come ready.\n");
960 status = ql_wait_reg_rdy(qdev, STS, qdev->port_init, 0);
961 if (status) {
962 netif_crit(qdev, link, qdev->ndev,
963 "Port initialize timed out.\n");
964 }
965 return status;
966 }
967
968 netif_info(qdev, link, qdev->ndev, "Got xgmac semaphore!.\n");
969
970 status = ql_read_xgmac_reg(qdev, GLOBAL_CFG, &data);
971 if (status)
972 goto end;
973 data |= GLOBAL_CFG_RESET;
974 status = ql_write_xgmac_reg(qdev, GLOBAL_CFG, data);
975 if (status)
976 goto end;
977
978
979 data &= ~GLOBAL_CFG_RESET;
980 data |= GLOBAL_CFG_JUMBO;
981 data |= GLOBAL_CFG_TX_STAT_EN;
982 data |= GLOBAL_CFG_RX_STAT_EN;
983 status = ql_write_xgmac_reg(qdev, GLOBAL_CFG, data);
984 if (status)
985 goto end;
986
987
988 status = ql_read_xgmac_reg(qdev, TX_CFG, &data);
989 if (status)
990 goto end;
991 data &= ~TX_CFG_RESET;
992 data |= TX_CFG_EN;
993 status = ql_write_xgmac_reg(qdev, TX_CFG, data);
994 if (status)
995 goto end;
996
997
998 status = ql_read_xgmac_reg(qdev, RX_CFG, &data);
999 if (status)
1000 goto end;
1001 data &= ~RX_CFG_RESET;
1002 data |= RX_CFG_EN;
1003 status = ql_write_xgmac_reg(qdev, RX_CFG, data);
1004 if (status)
1005 goto end;
1006
1007
1008 status =
1009 ql_write_xgmac_reg(qdev, MAC_TX_PARAMS, MAC_TX_PARAMS_JUMBO | (0x2580 << 16));
1010 if (status)
1011 goto end;
1012 status =
1013 ql_write_xgmac_reg(qdev, MAC_RX_PARAMS, 0x2580);
1014 if (status)
1015 goto end;
1016
1017
1018 ql_write32(qdev, STS, ((qdev->port_init << 16) | qdev->port_init));
1019end:
1020 ql_sem_unlock(qdev, qdev->xg_sem_mask);
1021 return status;
1022}
1023
1024static inline unsigned int ql_lbq_block_size(struct ql_adapter *qdev)
1025{
1026 return PAGE_SIZE << qdev->lbq_buf_order;
1027}
1028
1029
1030static struct bq_desc *ql_get_curr_lbuf(struct rx_ring *rx_ring)
1031{
1032 struct bq_desc *lbq_desc = &rx_ring->lbq[rx_ring->lbq_curr_idx];
1033 rx_ring->lbq_curr_idx++;
1034 if (rx_ring->lbq_curr_idx == rx_ring->lbq_len)
1035 rx_ring->lbq_curr_idx = 0;
1036 rx_ring->lbq_free_cnt++;
1037 return lbq_desc;
1038}
1039
1040static struct bq_desc *ql_get_curr_lchunk(struct ql_adapter *qdev,
1041 struct rx_ring *rx_ring)
1042{
1043 struct bq_desc *lbq_desc = ql_get_curr_lbuf(rx_ring);
1044
1045 pci_dma_sync_single_for_cpu(qdev->pdev,
1046 dma_unmap_addr(lbq_desc, mapaddr),
1047 rx_ring->lbq_buf_size,
1048 PCI_DMA_FROMDEVICE);
1049
1050
1051
1052
1053 if ((lbq_desc->p.pg_chunk.offset + rx_ring->lbq_buf_size)
1054 == ql_lbq_block_size(qdev))
1055 pci_unmap_page(qdev->pdev,
1056 lbq_desc->p.pg_chunk.map,
1057 ql_lbq_block_size(qdev),
1058 PCI_DMA_FROMDEVICE);
1059 return lbq_desc;
1060}
1061
1062
1063static struct bq_desc *ql_get_curr_sbuf(struct rx_ring *rx_ring)
1064{
1065 struct bq_desc *sbq_desc = &rx_ring->sbq[rx_ring->sbq_curr_idx];
1066 rx_ring->sbq_curr_idx++;
1067 if (rx_ring->sbq_curr_idx == rx_ring->sbq_len)
1068 rx_ring->sbq_curr_idx = 0;
1069 rx_ring->sbq_free_cnt++;
1070 return sbq_desc;
1071}
1072
1073
1074static void ql_update_cq(struct rx_ring *rx_ring)
1075{
1076 rx_ring->cnsmr_idx++;
1077 rx_ring->curr_entry++;
1078 if (unlikely(rx_ring->cnsmr_idx == rx_ring->cq_len)) {
1079 rx_ring->cnsmr_idx = 0;
1080 rx_ring->curr_entry = rx_ring->cq_base;
1081 }
1082}
1083
1084static void ql_write_cq_idx(struct rx_ring *rx_ring)
1085{
1086 ql_write_db_reg(rx_ring->cnsmr_idx, rx_ring->cnsmr_idx_db_reg);
1087}
1088
1089static int ql_get_next_chunk(struct ql_adapter *qdev, struct rx_ring *rx_ring,
1090 struct bq_desc *lbq_desc)
1091{
1092 if (!rx_ring->pg_chunk.page) {
1093 u64 map;
1094 rx_ring->pg_chunk.page = alloc_pages(__GFP_COLD | __GFP_COMP |
1095 GFP_ATOMIC,
1096 qdev->lbq_buf_order);
1097 if (unlikely(!rx_ring->pg_chunk.page)) {
1098 netif_err(qdev, drv, qdev->ndev,
1099 "page allocation failed.\n");
1100 return -ENOMEM;
1101 }
1102 rx_ring->pg_chunk.offset = 0;
1103 map = pci_map_page(qdev->pdev, rx_ring->pg_chunk.page,
1104 0, ql_lbq_block_size(qdev),
1105 PCI_DMA_FROMDEVICE);
1106 if (pci_dma_mapping_error(qdev->pdev, map)) {
1107 __free_pages(rx_ring->pg_chunk.page,
1108 qdev->lbq_buf_order);
1109 netif_err(qdev, drv, qdev->ndev,
1110 "PCI mapping failed.\n");
1111 return -ENOMEM;
1112 }
1113 rx_ring->pg_chunk.map = map;
1114 rx_ring->pg_chunk.va = page_address(rx_ring->pg_chunk.page);
1115 }
1116
1117
1118
1119
1120 lbq_desc->p.pg_chunk = rx_ring->pg_chunk;
1121
1122
1123
1124
1125 rx_ring->pg_chunk.offset += rx_ring->lbq_buf_size;
1126 if (rx_ring->pg_chunk.offset == ql_lbq_block_size(qdev)) {
1127 rx_ring->pg_chunk.page = NULL;
1128 lbq_desc->p.pg_chunk.last_flag = 1;
1129 } else {
1130 rx_ring->pg_chunk.va += rx_ring->lbq_buf_size;
1131 get_page(rx_ring->pg_chunk.page);
1132 lbq_desc->p.pg_chunk.last_flag = 0;
1133 }
1134 return 0;
1135}
1136
1137static void ql_update_lbq(struct ql_adapter *qdev, struct rx_ring *rx_ring)
1138{
1139 u32 clean_idx = rx_ring->lbq_clean_idx;
1140 u32 start_idx = clean_idx;
1141 struct bq_desc *lbq_desc;
1142 u64 map;
1143 int i;
1144
1145 while (rx_ring->lbq_free_cnt > 32) {
1146 for (i = (rx_ring->lbq_clean_idx % 16); i < 16; i++) {
1147 netif_printk(qdev, rx_status, KERN_DEBUG, qdev->ndev,
1148 "lbq: try cleaning clean_idx = %d.\n",
1149 clean_idx);
1150 lbq_desc = &rx_ring->lbq[clean_idx];
1151 if (ql_get_next_chunk(qdev, rx_ring, lbq_desc)) {
1152 rx_ring->lbq_clean_idx = clean_idx;
1153 netif_err(qdev, ifup, qdev->ndev,
1154 "Could not get a page chunk, i=%d, clean_idx =%d .\n",
1155 i, clean_idx);
1156 return;
1157 }
1158
1159 map = lbq_desc->p.pg_chunk.map +
1160 lbq_desc->p.pg_chunk.offset;
1161 dma_unmap_addr_set(lbq_desc, mapaddr, map);
1162 dma_unmap_len_set(lbq_desc, maplen,
1163 rx_ring->lbq_buf_size);
1164 *lbq_desc->addr = cpu_to_le64(map);
1165
1166 pci_dma_sync_single_for_device(qdev->pdev, map,
1167 rx_ring->lbq_buf_size,
1168 PCI_DMA_FROMDEVICE);
1169 clean_idx++;
1170 if (clean_idx == rx_ring->lbq_len)
1171 clean_idx = 0;
1172 }
1173
1174 rx_ring->lbq_clean_idx = clean_idx;
1175 rx_ring->lbq_prod_idx += 16;
1176 if (rx_ring->lbq_prod_idx == rx_ring->lbq_len)
1177 rx_ring->lbq_prod_idx = 0;
1178 rx_ring->lbq_free_cnt -= 16;
1179 }
1180
1181 if (start_idx != clean_idx) {
1182 netif_printk(qdev, rx_status, KERN_DEBUG, qdev->ndev,
1183 "lbq: updating prod idx = %d.\n",
1184 rx_ring->lbq_prod_idx);
1185 ql_write_db_reg(rx_ring->lbq_prod_idx,
1186 rx_ring->lbq_prod_idx_db_reg);
1187 }
1188}
1189
1190
1191static void ql_update_sbq(struct ql_adapter *qdev, struct rx_ring *rx_ring)
1192{
1193 u32 clean_idx = rx_ring->sbq_clean_idx;
1194 u32 start_idx = clean_idx;
1195 struct bq_desc *sbq_desc;
1196 u64 map;
1197 int i;
1198
1199 while (rx_ring->sbq_free_cnt > 16) {
1200 for (i = (rx_ring->sbq_clean_idx % 16); i < 16; i++) {
1201 sbq_desc = &rx_ring->sbq[clean_idx];
1202 netif_printk(qdev, rx_status, KERN_DEBUG, qdev->ndev,
1203 "sbq: try cleaning clean_idx = %d.\n",
1204 clean_idx);
1205 if (sbq_desc->p.skb == NULL) {
1206 netif_printk(qdev, rx_status, KERN_DEBUG,
1207 qdev->ndev,
1208 "sbq: getting new skb for index %d.\n",
1209 sbq_desc->index);
1210 sbq_desc->p.skb =
1211 netdev_alloc_skb(qdev->ndev,
1212 SMALL_BUFFER_SIZE);
1213 if (sbq_desc->p.skb == NULL) {
1214 netif_err(qdev, probe, qdev->ndev,
1215 "Couldn't get an skb.\n");
1216 rx_ring->sbq_clean_idx = clean_idx;
1217 return;
1218 }
1219 skb_reserve(sbq_desc->p.skb, QLGE_SB_PAD);
1220 map = pci_map_single(qdev->pdev,
1221 sbq_desc->p.skb->data,
1222 rx_ring->sbq_buf_size,
1223 PCI_DMA_FROMDEVICE);
1224 if (pci_dma_mapping_error(qdev->pdev, map)) {
1225 netif_err(qdev, ifup, qdev->ndev,
1226 "PCI mapping failed.\n");
1227 rx_ring->sbq_clean_idx = clean_idx;
1228 dev_kfree_skb_any(sbq_desc->p.skb);
1229 sbq_desc->p.skb = NULL;
1230 return;
1231 }
1232 dma_unmap_addr_set(sbq_desc, mapaddr, map);
1233 dma_unmap_len_set(sbq_desc, maplen,
1234 rx_ring->sbq_buf_size);
1235 *sbq_desc->addr = cpu_to_le64(map);
1236 }
1237
1238 clean_idx++;
1239 if (clean_idx == rx_ring->sbq_len)
1240 clean_idx = 0;
1241 }
1242 rx_ring->sbq_clean_idx = clean_idx;
1243 rx_ring->sbq_prod_idx += 16;
1244 if (rx_ring->sbq_prod_idx == rx_ring->sbq_len)
1245 rx_ring->sbq_prod_idx = 0;
1246 rx_ring->sbq_free_cnt -= 16;
1247 }
1248
1249 if (start_idx != clean_idx) {
1250 netif_printk(qdev, rx_status, KERN_DEBUG, qdev->ndev,
1251 "sbq: updating prod idx = %d.\n",
1252 rx_ring->sbq_prod_idx);
1253 ql_write_db_reg(rx_ring->sbq_prod_idx,
1254 rx_ring->sbq_prod_idx_db_reg);
1255 }
1256}
1257
1258static void ql_update_buffer_queues(struct ql_adapter *qdev,
1259 struct rx_ring *rx_ring)
1260{
1261 ql_update_sbq(qdev, rx_ring);
1262 ql_update_lbq(qdev, rx_ring);
1263}
1264
1265
1266
1267
1268static void ql_unmap_send(struct ql_adapter *qdev,
1269 struct tx_ring_desc *tx_ring_desc, int mapped)
1270{
1271 int i;
1272 for (i = 0; i < mapped; i++) {
1273 if (i == 0 || (i == 7 && mapped > 7)) {
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283 if (i == 7) {
1284 netif_printk(qdev, tx_done, KERN_DEBUG,
1285 qdev->ndev,
1286 "unmapping OAL area.\n");
1287 }
1288 pci_unmap_single(qdev->pdev,
1289 dma_unmap_addr(&tx_ring_desc->map[i],
1290 mapaddr),
1291 dma_unmap_len(&tx_ring_desc->map[i],
1292 maplen),
1293 PCI_DMA_TODEVICE);
1294 } else {
1295 netif_printk(qdev, tx_done, KERN_DEBUG, qdev->ndev,
1296 "unmapping frag %d.\n", i);
1297 pci_unmap_page(qdev->pdev,
1298 dma_unmap_addr(&tx_ring_desc->map[i],
1299 mapaddr),
1300 dma_unmap_len(&tx_ring_desc->map[i],
1301 maplen), PCI_DMA_TODEVICE);
1302 }
1303 }
1304
1305}
1306
1307
1308
1309
1310static int ql_map_send(struct ql_adapter *qdev,
1311 struct ob_mac_iocb_req *mac_iocb_ptr,
1312 struct sk_buff *skb, struct tx_ring_desc *tx_ring_desc)
1313{
1314 int len = skb_headlen(skb);
1315 dma_addr_t map;
1316 int frag_idx, err, map_idx = 0;
1317 struct tx_buf_desc *tbd = mac_iocb_ptr->tbd;
1318 int frag_cnt = skb_shinfo(skb)->nr_frags;
1319
1320 if (frag_cnt) {
1321 netif_printk(qdev, tx_queued, KERN_DEBUG, qdev->ndev,
1322 "frag_cnt = %d.\n", frag_cnt);
1323 }
1324
1325
1326
1327 map = pci_map_single(qdev->pdev, skb->data, len, PCI_DMA_TODEVICE);
1328
1329 err = pci_dma_mapping_error(qdev->pdev, map);
1330 if (err) {
1331 netif_err(qdev, tx_queued, qdev->ndev,
1332 "PCI mapping failed with error: %d\n", err);
1333
1334 return NETDEV_TX_BUSY;
1335 }
1336
1337 tbd->len = cpu_to_le32(len);
1338 tbd->addr = cpu_to_le64(map);
1339 dma_unmap_addr_set(&tx_ring_desc->map[map_idx], mapaddr, map);
1340 dma_unmap_len_set(&tx_ring_desc->map[map_idx], maplen, len);
1341 map_idx++;
1342
1343
1344
1345
1346
1347
1348
1349
1350 for (frag_idx = 0; frag_idx < frag_cnt; frag_idx++, map_idx++) {
1351 skb_frag_t *frag = &skb_shinfo(skb)->frags[frag_idx];
1352 tbd++;
1353 if (frag_idx == 6 && frag_cnt > 7) {
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373 map = pci_map_single(qdev->pdev, &tx_ring_desc->oal,
1374 sizeof(struct oal),
1375 PCI_DMA_TODEVICE);
1376 err = pci_dma_mapping_error(qdev->pdev, map);
1377 if (err) {
1378 netif_err(qdev, tx_queued, qdev->ndev,
1379 "PCI mapping outbound address list with error: %d\n",
1380 err);
1381 goto map_error;
1382 }
1383
1384 tbd->addr = cpu_to_le64(map);
1385
1386
1387
1388
1389
1390 tbd->len =
1391 cpu_to_le32((sizeof(struct tx_buf_desc) *
1392 (frag_cnt - frag_idx)) | TX_DESC_C);
1393 dma_unmap_addr_set(&tx_ring_desc->map[map_idx], mapaddr,
1394 map);
1395 dma_unmap_len_set(&tx_ring_desc->map[map_idx], maplen,
1396 sizeof(struct oal));
1397 tbd = (struct tx_buf_desc *)&tx_ring_desc->oal;
1398 map_idx++;
1399 }
1400
1401 map = skb_frag_dma_map(&qdev->pdev->dev, frag, 0, skb_frag_size(frag),
1402 DMA_TO_DEVICE);
1403
1404 err = dma_mapping_error(&qdev->pdev->dev, map);
1405 if (err) {
1406 netif_err(qdev, tx_queued, qdev->ndev,
1407 "PCI mapping frags failed with error: %d.\n",
1408 err);
1409 goto map_error;
1410 }
1411
1412 tbd->addr = cpu_to_le64(map);
1413 tbd->len = cpu_to_le32(skb_frag_size(frag));
1414 dma_unmap_addr_set(&tx_ring_desc->map[map_idx], mapaddr, map);
1415 dma_unmap_len_set(&tx_ring_desc->map[map_idx], maplen,
1416 skb_frag_size(frag));
1417
1418 }
1419
1420 tx_ring_desc->map_cnt = map_idx;
1421
1422 tbd->len = cpu_to_le32(le32_to_cpu(tbd->len) | TX_DESC_E);
1423 return NETDEV_TX_OK;
1424
1425map_error:
1426
1427
1428
1429
1430
1431
1432 ql_unmap_send(qdev, tx_ring_desc, map_idx);
1433 return NETDEV_TX_BUSY;
1434}
1435
1436
1437static void ql_categorize_rx_err(struct ql_adapter *qdev, u8 rx_err)
1438{
1439 struct nic_stats *stats = &qdev->nic_stats;
1440
1441 stats->rx_err_count++;
1442
1443 switch (rx_err & IB_MAC_IOCB_RSP_ERR_MASK) {
1444 case IB_MAC_IOCB_RSP_ERR_CODE_ERR:
1445 stats->rx_code_err++;
1446 break;
1447 case IB_MAC_IOCB_RSP_ERR_OVERSIZE:
1448 stats->rx_oversize_err++;
1449 break;
1450 case IB_MAC_IOCB_RSP_ERR_UNDERSIZE:
1451 stats->rx_undersize_err++;
1452 break;
1453 case IB_MAC_IOCB_RSP_ERR_PREAMBLE:
1454 stats->rx_preamble_err++;
1455 break;
1456 case IB_MAC_IOCB_RSP_ERR_FRAME_LEN:
1457 stats->rx_frame_len_err++;
1458 break;
1459 case IB_MAC_IOCB_RSP_ERR_CRC:
1460 stats->rx_crc_err++;
1461 default:
1462 break;
1463 }
1464}
1465
1466
1467static void ql_process_mac_rx_gro_page(struct ql_adapter *qdev,
1468 struct rx_ring *rx_ring,
1469 struct ib_mac_iocb_rsp *ib_mac_rsp,
1470 u32 length,
1471 u16 vlan_id)
1472{
1473 struct sk_buff *skb;
1474 struct bq_desc *lbq_desc = ql_get_curr_lchunk(qdev, rx_ring);
1475 struct napi_struct *napi = &rx_ring->napi;
1476
1477 napi->dev = qdev->ndev;
1478
1479 skb = napi_get_frags(napi);
1480 if (!skb) {
1481 netif_err(qdev, drv, qdev->ndev,
1482 "Couldn't get an skb, exiting.\n");
1483 rx_ring->rx_dropped++;
1484 put_page(lbq_desc->p.pg_chunk.page);
1485 return;
1486 }
1487 prefetch(lbq_desc->p.pg_chunk.va);
1488 __skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
1489 lbq_desc->p.pg_chunk.page,
1490 lbq_desc->p.pg_chunk.offset,
1491 length);
1492
1493 skb->len += length;
1494 skb->data_len += length;
1495 skb->truesize += length;
1496 skb_shinfo(skb)->nr_frags++;
1497
1498 rx_ring->rx_packets++;
1499 rx_ring->rx_bytes += length;
1500 skb->ip_summed = CHECKSUM_UNNECESSARY;
1501 skb_record_rx_queue(skb, rx_ring->cq_id);
1502 if (vlan_id != 0xffff)
1503 __vlan_hwaccel_put_tag(skb, vlan_id);
1504 napi_gro_frags(napi);
1505}
1506
1507
1508static void ql_process_mac_rx_page(struct ql_adapter *qdev,
1509 struct rx_ring *rx_ring,
1510 struct ib_mac_iocb_rsp *ib_mac_rsp,
1511 u32 length,
1512 u16 vlan_id)
1513{
1514 struct net_device *ndev = qdev->ndev;
1515 struct sk_buff *skb = NULL;
1516 void *addr;
1517 struct bq_desc *lbq_desc = ql_get_curr_lchunk(qdev, rx_ring);
1518 struct napi_struct *napi = &rx_ring->napi;
1519
1520 skb = netdev_alloc_skb(ndev, length);
1521 if (!skb) {
1522 netif_err(qdev, drv, qdev->ndev,
1523 "Couldn't get an skb, need to unwind!.\n");
1524 rx_ring->rx_dropped++;
1525 put_page(lbq_desc->p.pg_chunk.page);
1526 return;
1527 }
1528
1529 addr = lbq_desc->p.pg_chunk.va;
1530 prefetch(addr);
1531
1532
1533
1534
1535 if (skb->len > ndev->mtu + ETH_HLEN) {
1536 netif_err(qdev, drv, qdev->ndev,
1537 "Segment too small, dropping.\n");
1538 rx_ring->rx_dropped++;
1539 goto err_out;
1540 }
1541 memcpy(skb_put(skb, ETH_HLEN), addr, ETH_HLEN);
1542 netif_printk(qdev, rx_status, KERN_DEBUG, qdev->ndev,
1543 "%d bytes of headers and data in large. Chain page to new skb and pull tail.\n",
1544 length);
1545 skb_fill_page_desc(skb, 0, lbq_desc->p.pg_chunk.page,
1546 lbq_desc->p.pg_chunk.offset+ETH_HLEN,
1547 length-ETH_HLEN);
1548 skb->len += length-ETH_HLEN;
1549 skb->data_len += length-ETH_HLEN;
1550 skb->truesize += length-ETH_HLEN;
1551
1552 rx_ring->rx_packets++;
1553 rx_ring->rx_bytes += skb->len;
1554 skb->protocol = eth_type_trans(skb, ndev);
1555 skb_checksum_none_assert(skb);
1556
1557 if ((ndev->features & NETIF_F_RXCSUM) &&
1558 !(ib_mac_rsp->flags1 & IB_MAC_CSUM_ERR_MASK)) {
1559
1560 if (ib_mac_rsp->flags2 & IB_MAC_IOCB_RSP_T) {
1561 netif_printk(qdev, rx_status, KERN_DEBUG, qdev->ndev,
1562 "TCP checksum done!\n");
1563 skb->ip_summed = CHECKSUM_UNNECESSARY;
1564 } else if ((ib_mac_rsp->flags2 & IB_MAC_IOCB_RSP_U) &&
1565 (ib_mac_rsp->flags3 & IB_MAC_IOCB_RSP_V4)) {
1566
1567 struct iphdr *iph =
1568 (struct iphdr *) ((u8 *)addr + ETH_HLEN);
1569 if (!(iph->frag_off &
1570 htons(IP_MF|IP_OFFSET))) {
1571 skb->ip_summed = CHECKSUM_UNNECESSARY;
1572 netif_printk(qdev, rx_status, KERN_DEBUG,
1573 qdev->ndev,
1574 "UDP checksum done!\n");
1575 }
1576 }
1577 }
1578
1579 skb_record_rx_queue(skb, rx_ring->cq_id);
1580 if (vlan_id != 0xffff)
1581 __vlan_hwaccel_put_tag(skb, vlan_id);
1582 if (skb->ip_summed == CHECKSUM_UNNECESSARY)
1583 napi_gro_receive(napi, skb);
1584 else
1585 netif_receive_skb(skb);
1586 return;
1587err_out:
1588 dev_kfree_skb_any(skb);
1589 put_page(lbq_desc->p.pg_chunk.page);
1590}
1591
1592
1593static void ql_process_mac_rx_skb(struct ql_adapter *qdev,
1594 struct rx_ring *rx_ring,
1595 struct ib_mac_iocb_rsp *ib_mac_rsp,
1596 u32 length,
1597 u16 vlan_id)
1598{
1599 struct net_device *ndev = qdev->ndev;
1600 struct sk_buff *skb = NULL;
1601 struct sk_buff *new_skb = NULL;
1602 struct bq_desc *sbq_desc = ql_get_curr_sbuf(rx_ring);
1603
1604 skb = sbq_desc->p.skb;
1605
1606 new_skb = netdev_alloc_skb(qdev->ndev, length + NET_IP_ALIGN);
1607 if (new_skb == NULL) {
1608 netif_err(qdev, probe, qdev->ndev,
1609 "No skb available, drop the packet.\n");
1610 rx_ring->rx_dropped++;
1611 return;
1612 }
1613 skb_reserve(new_skb, NET_IP_ALIGN);
1614 memcpy(skb_put(new_skb, length), skb->data, length);
1615 skb = new_skb;
1616
1617
1618 if (test_bit(QL_SELFTEST, &qdev->flags)) {
1619 ql_check_lb_frame(qdev, skb);
1620 dev_kfree_skb_any(skb);
1621 return;
1622 }
1623
1624
1625
1626
1627 if (skb->len > ndev->mtu + ETH_HLEN) {
1628 dev_kfree_skb_any(skb);
1629 rx_ring->rx_dropped++;
1630 return;
1631 }
1632
1633 prefetch(skb->data);
1634 if (ib_mac_rsp->flags1 & IB_MAC_IOCB_RSP_M_MASK) {
1635 netif_printk(qdev, rx_status, KERN_DEBUG, qdev->ndev,
1636 "%s Multicast.\n",
1637 (ib_mac_rsp->flags1 & IB_MAC_IOCB_RSP_M_MASK) ==
1638 IB_MAC_IOCB_RSP_M_HASH ? "Hash" :
1639 (ib_mac_rsp->flags1 & IB_MAC_IOCB_RSP_M_MASK) ==
1640 IB_MAC_IOCB_RSP_M_REG ? "Registered" :
1641 (ib_mac_rsp->flags1 & IB_MAC_IOCB_RSP_M_MASK) ==
1642 IB_MAC_IOCB_RSP_M_PROM ? "Promiscuous" : "");
1643 }
1644 if (ib_mac_rsp->flags2 & IB_MAC_IOCB_RSP_P)
1645 netif_printk(qdev, rx_status, KERN_DEBUG, qdev->ndev,
1646 "Promiscuous Packet.\n");
1647
1648 rx_ring->rx_packets++;
1649 rx_ring->rx_bytes += skb->len;
1650 skb->protocol = eth_type_trans(skb, ndev);
1651 skb_checksum_none_assert(skb);
1652
1653
1654
1655
1656 if ((ndev->features & NETIF_F_RXCSUM) &&
1657 !(ib_mac_rsp->flags1 & IB_MAC_CSUM_ERR_MASK)) {
1658
1659 if (ib_mac_rsp->flags2 & IB_MAC_IOCB_RSP_T) {
1660 netif_printk(qdev, rx_status, KERN_DEBUG, qdev->ndev,
1661 "TCP checksum done!\n");
1662 skb->ip_summed = CHECKSUM_UNNECESSARY;
1663 } else if ((ib_mac_rsp->flags2 & IB_MAC_IOCB_RSP_U) &&
1664 (ib_mac_rsp->flags3 & IB_MAC_IOCB_RSP_V4)) {
1665
1666 struct iphdr *iph = (struct iphdr *) skb->data;
1667 if (!(iph->frag_off &
1668 htons(IP_MF|IP_OFFSET))) {
1669 skb->ip_summed = CHECKSUM_UNNECESSARY;
1670 netif_printk(qdev, rx_status, KERN_DEBUG,
1671 qdev->ndev,
1672 "UDP checksum done!\n");
1673 }
1674 }
1675 }
1676
1677 skb_record_rx_queue(skb, rx_ring->cq_id);
1678 if (vlan_id != 0xffff)
1679 __vlan_hwaccel_put_tag(skb, vlan_id);
1680 if (skb->ip_summed == CHECKSUM_UNNECESSARY)
1681 napi_gro_receive(&rx_ring->napi, skb);
1682 else
1683 netif_receive_skb(skb);
1684}
1685
1686static void ql_realign_skb(struct sk_buff *skb, int len)
1687{
1688 void *temp_addr = skb->data;
1689
1690
1691
1692
1693
1694 skb->data -= QLGE_SB_PAD - NET_IP_ALIGN;
1695 skb->tail -= QLGE_SB_PAD - NET_IP_ALIGN;
1696 skb_copy_to_linear_data(skb, temp_addr,
1697 (unsigned int)len);
1698}
1699
1700
1701
1702
1703
1704
1705static struct sk_buff *ql_build_rx_skb(struct ql_adapter *qdev,
1706 struct rx_ring *rx_ring,
1707 struct ib_mac_iocb_rsp *ib_mac_rsp)
1708{
1709 struct bq_desc *lbq_desc;
1710 struct bq_desc *sbq_desc;
1711 struct sk_buff *skb = NULL;
1712 u32 length = le32_to_cpu(ib_mac_rsp->data_len);
1713 u32 hdr_len = le32_to_cpu(ib_mac_rsp->hdr_len);
1714
1715
1716
1717
1718 if (ib_mac_rsp->flags4 & IB_MAC_IOCB_RSP_HV &&
1719 ib_mac_rsp->flags4 & IB_MAC_IOCB_RSP_HS) {
1720 netif_printk(qdev, rx_status, KERN_DEBUG, qdev->ndev,
1721 "Header of %d bytes in small buffer.\n", hdr_len);
1722
1723
1724
1725 sbq_desc = ql_get_curr_sbuf(rx_ring);
1726 pci_unmap_single(qdev->pdev,
1727 dma_unmap_addr(sbq_desc, mapaddr),
1728 dma_unmap_len(sbq_desc, maplen),
1729 PCI_DMA_FROMDEVICE);
1730 skb = sbq_desc->p.skb;
1731 ql_realign_skb(skb, hdr_len);
1732 skb_put(skb, hdr_len);
1733 sbq_desc->p.skb = NULL;
1734 }
1735
1736
1737
1738
1739 if (unlikely(!length)) {
1740 netif_printk(qdev, rx_status, KERN_DEBUG, qdev->ndev,
1741 "No Data buffer in this packet.\n");
1742 return skb;
1743 }
1744
1745 if (ib_mac_rsp->flags3 & IB_MAC_IOCB_RSP_DS) {
1746 if (ib_mac_rsp->flags4 & IB_MAC_IOCB_RSP_HS) {
1747 netif_printk(qdev, rx_status, KERN_DEBUG, qdev->ndev,
1748 "Headers in small, data of %d bytes in small, combine them.\n",
1749 length);
1750
1751
1752
1753
1754
1755
1756
1757 sbq_desc = ql_get_curr_sbuf(rx_ring);
1758 pci_dma_sync_single_for_cpu(qdev->pdev,
1759 dma_unmap_addr
1760 (sbq_desc, mapaddr),
1761 dma_unmap_len
1762 (sbq_desc, maplen),
1763 PCI_DMA_FROMDEVICE);
1764 memcpy(skb_put(skb, length),
1765 sbq_desc->p.skb->data, length);
1766 pci_dma_sync_single_for_device(qdev->pdev,
1767 dma_unmap_addr
1768 (sbq_desc,
1769 mapaddr),
1770 dma_unmap_len
1771 (sbq_desc,
1772 maplen),
1773 PCI_DMA_FROMDEVICE);
1774 } else {
1775 netif_printk(qdev, rx_status, KERN_DEBUG, qdev->ndev,
1776 "%d bytes in a single small buffer.\n",
1777 length);
1778 sbq_desc = ql_get_curr_sbuf(rx_ring);
1779 skb = sbq_desc->p.skb;
1780 ql_realign_skb(skb, length);
1781 skb_put(skb, length);
1782 pci_unmap_single(qdev->pdev,
1783 dma_unmap_addr(sbq_desc,
1784 mapaddr),
1785 dma_unmap_len(sbq_desc,
1786 maplen),
1787 PCI_DMA_FROMDEVICE);
1788 sbq_desc->p.skb = NULL;
1789 }
1790 } else if (ib_mac_rsp->flags3 & IB_MAC_IOCB_RSP_DL) {
1791 if (ib_mac_rsp->flags4 & IB_MAC_IOCB_RSP_HS) {
1792 netif_printk(qdev, rx_status, KERN_DEBUG, qdev->ndev,
1793 "Header in small, %d bytes in large. Chain large to small!\n",
1794 length);
1795
1796
1797
1798
1799
1800 lbq_desc = ql_get_curr_lchunk(qdev, rx_ring);
1801 netif_printk(qdev, rx_status, KERN_DEBUG, qdev->ndev,
1802 "Chaining page at offset = %d, for %d bytes to skb.\n",
1803 lbq_desc->p.pg_chunk.offset, length);
1804 skb_fill_page_desc(skb, 0, lbq_desc->p.pg_chunk.page,
1805 lbq_desc->p.pg_chunk.offset,
1806 length);
1807 skb->len += length;
1808 skb->data_len += length;
1809 skb->truesize += length;
1810 } else {
1811
1812
1813
1814
1815
1816 lbq_desc = ql_get_curr_lchunk(qdev, rx_ring);
1817 skb = netdev_alloc_skb(qdev->ndev, length);
1818 if (skb == NULL) {
1819 netif_printk(qdev, probe, KERN_DEBUG, qdev->ndev,
1820 "No skb available, drop the packet.\n");
1821 return NULL;
1822 }
1823 pci_unmap_page(qdev->pdev,
1824 dma_unmap_addr(lbq_desc,
1825 mapaddr),
1826 dma_unmap_len(lbq_desc, maplen),
1827 PCI_DMA_FROMDEVICE);
1828 skb_reserve(skb, NET_IP_ALIGN);
1829 netif_printk(qdev, rx_status, KERN_DEBUG, qdev->ndev,
1830 "%d bytes of headers and data in large. Chain page to new skb and pull tail.\n",
1831 length);
1832 skb_fill_page_desc(skb, 0,
1833 lbq_desc->p.pg_chunk.page,
1834 lbq_desc->p.pg_chunk.offset,
1835 length);
1836 skb->len += length;
1837 skb->data_len += length;
1838 skb->truesize += length;
1839 length -= length;
1840 __pskb_pull_tail(skb,
1841 (ib_mac_rsp->flags2 & IB_MAC_IOCB_RSP_V) ?
1842 VLAN_ETH_HLEN : ETH_HLEN);
1843 }
1844 } else {
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856 int size, i = 0;
1857 sbq_desc = ql_get_curr_sbuf(rx_ring);
1858 pci_unmap_single(qdev->pdev,
1859 dma_unmap_addr(sbq_desc, mapaddr),
1860 dma_unmap_len(sbq_desc, maplen),
1861 PCI_DMA_FROMDEVICE);
1862 if (!(ib_mac_rsp->flags4 & IB_MAC_IOCB_RSP_HS)) {
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872 netif_printk(qdev, rx_status, KERN_DEBUG, qdev->ndev,
1873 "%d bytes of headers & data in chain of large.\n",
1874 length);
1875 skb = sbq_desc->p.skb;
1876 sbq_desc->p.skb = NULL;
1877 skb_reserve(skb, NET_IP_ALIGN);
1878 }
1879 while (length > 0) {
1880 lbq_desc = ql_get_curr_lchunk(qdev, rx_ring);
1881 size = (length < rx_ring->lbq_buf_size) ? length :
1882 rx_ring->lbq_buf_size;
1883
1884 netif_printk(qdev, rx_status, KERN_DEBUG, qdev->ndev,
1885 "Adding page %d to skb for %d bytes.\n",
1886 i, size);
1887 skb_fill_page_desc(skb, i,
1888 lbq_desc->p.pg_chunk.page,
1889 lbq_desc->p.pg_chunk.offset,
1890 size);
1891 skb->len += size;
1892 skb->data_len += size;
1893 skb->truesize += size;
1894 length -= size;
1895 i++;
1896 }
1897 __pskb_pull_tail(skb, (ib_mac_rsp->flags2 & IB_MAC_IOCB_RSP_V) ?
1898 VLAN_ETH_HLEN : ETH_HLEN);
1899 }
1900 return skb;
1901}
1902
1903
1904static void ql_process_mac_split_rx_intr(struct ql_adapter *qdev,
1905 struct rx_ring *rx_ring,
1906 struct ib_mac_iocb_rsp *ib_mac_rsp,
1907 u16 vlan_id)
1908{
1909 struct net_device *ndev = qdev->ndev;
1910 struct sk_buff *skb = NULL;
1911
1912 QL_DUMP_IB_MAC_RSP(ib_mac_rsp);
1913
1914 skb = ql_build_rx_skb(qdev, rx_ring, ib_mac_rsp);
1915 if (unlikely(!skb)) {
1916 netif_printk(qdev, rx_status, KERN_DEBUG, qdev->ndev,
1917 "No skb available, drop packet.\n");
1918 rx_ring->rx_dropped++;
1919 return;
1920 }
1921
1922
1923
1924
1925 if (skb->len > ndev->mtu + ETH_HLEN) {
1926 dev_kfree_skb_any(skb);
1927 rx_ring->rx_dropped++;
1928 return;
1929 }
1930
1931
1932 if (test_bit(QL_SELFTEST, &qdev->flags)) {
1933 ql_check_lb_frame(qdev, skb);
1934 dev_kfree_skb_any(skb);
1935 return;
1936 }
1937
1938 prefetch(skb->data);
1939 if (ib_mac_rsp->flags1 & IB_MAC_IOCB_RSP_M_MASK) {
1940 netif_printk(qdev, rx_status, KERN_DEBUG, qdev->ndev, "%s Multicast.\n",
1941 (ib_mac_rsp->flags1 & IB_MAC_IOCB_RSP_M_MASK) ==
1942 IB_MAC_IOCB_RSP_M_HASH ? "Hash" :
1943 (ib_mac_rsp->flags1 & IB_MAC_IOCB_RSP_M_MASK) ==
1944 IB_MAC_IOCB_RSP_M_REG ? "Registered" :
1945 (ib_mac_rsp->flags1 & IB_MAC_IOCB_RSP_M_MASK) ==
1946 IB_MAC_IOCB_RSP_M_PROM ? "Promiscuous" : "");
1947 rx_ring->rx_multicast++;
1948 }
1949 if (ib_mac_rsp->flags2 & IB_MAC_IOCB_RSP_P) {
1950 netif_printk(qdev, rx_status, KERN_DEBUG, qdev->ndev,
1951 "Promiscuous Packet.\n");
1952 }
1953
1954 skb->protocol = eth_type_trans(skb, ndev);
1955 skb_checksum_none_assert(skb);
1956
1957
1958
1959
1960 if ((ndev->features & NETIF_F_RXCSUM) &&
1961 !(ib_mac_rsp->flags1 & IB_MAC_CSUM_ERR_MASK)) {
1962
1963 if (ib_mac_rsp->flags2 & IB_MAC_IOCB_RSP_T) {
1964 netif_printk(qdev, rx_status, KERN_DEBUG, qdev->ndev,
1965 "TCP checksum done!\n");
1966 skb->ip_summed = CHECKSUM_UNNECESSARY;
1967 } else if ((ib_mac_rsp->flags2 & IB_MAC_IOCB_RSP_U) &&
1968 (ib_mac_rsp->flags3 & IB_MAC_IOCB_RSP_V4)) {
1969
1970 struct iphdr *iph = (struct iphdr *) skb->data;
1971 if (!(iph->frag_off &
1972 htons(IP_MF|IP_OFFSET))) {
1973 skb->ip_summed = CHECKSUM_UNNECESSARY;
1974 netif_printk(qdev, rx_status, KERN_DEBUG, qdev->ndev,
1975 "TCP checksum done!\n");
1976 }
1977 }
1978 }
1979
1980 rx_ring->rx_packets++;
1981 rx_ring->rx_bytes += skb->len;
1982 skb_record_rx_queue(skb, rx_ring->cq_id);
1983 if ((ib_mac_rsp->flags2 & IB_MAC_IOCB_RSP_V) && (vlan_id != 0))
1984 __vlan_hwaccel_put_tag(skb, vlan_id);
1985 if (skb->ip_summed == CHECKSUM_UNNECESSARY)
1986 napi_gro_receive(&rx_ring->napi, skb);
1987 else
1988 netif_receive_skb(skb);
1989}
1990
1991
1992static unsigned long ql_process_mac_rx_intr(struct ql_adapter *qdev,
1993 struct rx_ring *rx_ring,
1994 struct ib_mac_iocb_rsp *ib_mac_rsp)
1995{
1996 u32 length = le32_to_cpu(ib_mac_rsp->data_len);
1997 u16 vlan_id = (ib_mac_rsp->flags2 & IB_MAC_IOCB_RSP_V) ?
1998 ((le16_to_cpu(ib_mac_rsp->vlan_id) &
1999 IB_MAC_IOCB_RSP_VLAN_MASK)) : 0xffff;
2000
2001 QL_DUMP_IB_MAC_RSP(ib_mac_rsp);
2002
2003
2004 if (ib_mac_rsp->flags2 & IB_MAC_IOCB_RSP_ERR_MASK) {
2005 ql_categorize_rx_err(qdev, ib_mac_rsp->flags2);
2006 return (unsigned long)length;
2007 }
2008
2009 if (ib_mac_rsp->flags4 & IB_MAC_IOCB_RSP_HV) {
2010
2011
2012
2013 ql_process_mac_split_rx_intr(qdev, rx_ring, ib_mac_rsp,
2014 vlan_id);
2015 } else if (ib_mac_rsp->flags3 & IB_MAC_IOCB_RSP_DS) {
2016
2017
2018
2019
2020 ql_process_mac_rx_skb(qdev, rx_ring, ib_mac_rsp,
2021 length, vlan_id);
2022 } else if ((ib_mac_rsp->flags3 & IB_MAC_IOCB_RSP_DL) &&
2023 !(ib_mac_rsp->flags1 & IB_MAC_CSUM_ERR_MASK) &&
2024 (ib_mac_rsp->flags2 & IB_MAC_IOCB_RSP_T)) {
2025
2026
2027
2028 ql_process_mac_rx_gro_page(qdev, rx_ring, ib_mac_rsp,
2029 length, vlan_id);
2030 } else if (ib_mac_rsp->flags3 & IB_MAC_IOCB_RSP_DL) {
2031
2032
2033
2034 ql_process_mac_rx_page(qdev, rx_ring, ib_mac_rsp,
2035 length, vlan_id);
2036 } else {
2037
2038
2039
2040 ql_process_mac_split_rx_intr(qdev, rx_ring, ib_mac_rsp,
2041 vlan_id);
2042 }
2043
2044 return (unsigned long)length;
2045}
2046
2047
2048static void ql_process_mac_tx_intr(struct ql_adapter *qdev,
2049 struct ob_mac_iocb_rsp *mac_rsp)
2050{
2051 struct tx_ring *tx_ring;
2052 struct tx_ring_desc *tx_ring_desc;
2053
2054 QL_DUMP_OB_MAC_RSP(mac_rsp);
2055 tx_ring = &qdev->tx_ring[mac_rsp->txq_idx];
2056 tx_ring_desc = &tx_ring->q[mac_rsp->tid];
2057 ql_unmap_send(qdev, tx_ring_desc, tx_ring_desc->map_cnt);
2058 tx_ring->tx_bytes += (tx_ring_desc->skb)->len;
2059 tx_ring->tx_packets++;
2060 dev_kfree_skb(tx_ring_desc->skb);
2061 tx_ring_desc->skb = NULL;
2062
2063 if (unlikely(mac_rsp->flags1 & (OB_MAC_IOCB_RSP_E |
2064 OB_MAC_IOCB_RSP_S |
2065 OB_MAC_IOCB_RSP_L |
2066 OB_MAC_IOCB_RSP_P | OB_MAC_IOCB_RSP_B))) {
2067 if (mac_rsp->flags1 & OB_MAC_IOCB_RSP_E) {
2068 netif_warn(qdev, tx_done, qdev->ndev,
2069 "Total descriptor length did not match transfer length.\n");
2070 }
2071 if (mac_rsp->flags1 & OB_MAC_IOCB_RSP_S) {
2072 netif_warn(qdev, tx_done, qdev->ndev,
2073 "Frame too short to be valid, not sent.\n");
2074 }
2075 if (mac_rsp->flags1 & OB_MAC_IOCB_RSP_L) {
2076 netif_warn(qdev, tx_done, qdev->ndev,
2077 "Frame too long, but sent anyway.\n");
2078 }
2079 if (mac_rsp->flags1 & OB_MAC_IOCB_RSP_B) {
2080 netif_warn(qdev, tx_done, qdev->ndev,
2081 "PCI backplane error. Frame not sent.\n");
2082 }
2083 }
2084 atomic_inc(&tx_ring->tx_count);
2085}
2086
2087
2088void ql_queue_fw_error(struct ql_adapter *qdev)
2089{
2090 ql_link_off(qdev);
2091 queue_delayed_work(qdev->workqueue, &qdev->mpi_reset_work, 0);
2092}
2093
2094void ql_queue_asic_error(struct ql_adapter *qdev)
2095{
2096 ql_link_off(qdev);
2097 ql_disable_interrupts(qdev);
2098
2099
2100
2101
2102 clear_bit(QL_ADAPTER_UP, &qdev->flags);
2103
2104
2105
2106 set_bit(QL_ASIC_RECOVERY, &qdev->flags);
2107 queue_delayed_work(qdev->workqueue, &qdev->asic_reset_work, 0);
2108}
2109
2110static void ql_process_chip_ae_intr(struct ql_adapter *qdev,
2111 struct ib_ae_iocb_rsp *ib_ae_rsp)
2112{
2113 switch (ib_ae_rsp->event) {
2114 case MGMT_ERR_EVENT:
2115 netif_err(qdev, rx_err, qdev->ndev,
2116 "Management Processor Fatal Error.\n");
2117 ql_queue_fw_error(qdev);
2118 return;
2119
2120 case CAM_LOOKUP_ERR_EVENT:
2121 netdev_err(qdev->ndev, "Multiple CAM hits lookup occurred.\n");
2122 netdev_err(qdev->ndev, "This event shouldn't occur.\n");
2123 ql_queue_asic_error(qdev);
2124 return;
2125
2126 case SOFT_ECC_ERROR_EVENT:
2127 netdev_err(qdev->ndev, "Soft ECC error detected.\n");
2128 ql_queue_asic_error(qdev);
2129 break;
2130
2131 case PCI_ERR_ANON_BUF_RD:
2132 netdev_err(qdev->ndev, "PCI error occurred when reading "
2133 "anonymous buffers from rx_ring %d.\n",
2134 ib_ae_rsp->q_id);
2135 ql_queue_asic_error(qdev);
2136 break;
2137
2138 default:
2139 netif_err(qdev, drv, qdev->ndev, "Unexpected event %d.\n",
2140 ib_ae_rsp->event);
2141 ql_queue_asic_error(qdev);
2142 break;
2143 }
2144}
2145
2146static int ql_clean_outbound_rx_ring(struct rx_ring *rx_ring)
2147{
2148 struct ql_adapter *qdev = rx_ring->qdev;
2149 u32 prod = ql_read_sh_reg(rx_ring->prod_idx_sh_reg);
2150 struct ob_mac_iocb_rsp *net_rsp = NULL;
2151 int count = 0;
2152
2153 struct tx_ring *tx_ring;
2154
2155 while (prod != rx_ring->cnsmr_idx) {
2156
2157 netif_printk(qdev, rx_status, KERN_DEBUG, qdev->ndev,
2158 "cq_id = %d, prod = %d, cnsmr = %d.\n.",
2159 rx_ring->cq_id, prod, rx_ring->cnsmr_idx);
2160
2161 net_rsp = (struct ob_mac_iocb_rsp *)rx_ring->curr_entry;
2162 rmb();
2163 switch (net_rsp->opcode) {
2164
2165 case OPCODE_OB_MAC_TSO_IOCB:
2166 case OPCODE_OB_MAC_IOCB:
2167 ql_process_mac_tx_intr(qdev, net_rsp);
2168 break;
2169 default:
2170 netif_printk(qdev, rx_status, KERN_DEBUG, qdev->ndev,
2171 "Hit default case, not handled! dropping the packet, opcode = %x.\n",
2172 net_rsp->opcode);
2173 }
2174 count++;
2175 ql_update_cq(rx_ring);
2176 prod = ql_read_sh_reg(rx_ring->prod_idx_sh_reg);
2177 }
2178 if (!net_rsp)
2179 return 0;
2180 ql_write_cq_idx(rx_ring);
2181 tx_ring = &qdev->tx_ring[net_rsp->txq_idx];
2182 if (__netif_subqueue_stopped(qdev->ndev, tx_ring->wq_id)) {
2183 if ((atomic_read(&tx_ring->tx_count) > (tx_ring->wq_len / 4)))
2184
2185
2186
2187
2188 netif_wake_subqueue(qdev->ndev, tx_ring->wq_id);
2189 }
2190
2191 return count;
2192}
2193
2194static int ql_clean_inbound_rx_ring(struct rx_ring *rx_ring, int budget)
2195{
2196 struct ql_adapter *qdev = rx_ring->qdev;
2197 u32 prod = ql_read_sh_reg(rx_ring->prod_idx_sh_reg);
2198 struct ql_net_rsp_iocb *net_rsp;
2199 int count = 0;
2200
2201
2202 while (prod != rx_ring->cnsmr_idx) {
2203
2204 netif_printk(qdev, rx_status, KERN_DEBUG, qdev->ndev,
2205 "cq_id = %d, prod = %d, cnsmr = %d.\n.",
2206 rx_ring->cq_id, prod, rx_ring->cnsmr_idx);
2207
2208 net_rsp = rx_ring->curr_entry;
2209 rmb();
2210 switch (net_rsp->opcode) {
2211 case OPCODE_IB_MAC_IOCB:
2212 ql_process_mac_rx_intr(qdev, rx_ring,
2213 (struct ib_mac_iocb_rsp *)
2214 net_rsp);
2215 break;
2216
2217 case OPCODE_IB_AE_IOCB:
2218 ql_process_chip_ae_intr(qdev, (struct ib_ae_iocb_rsp *)
2219 net_rsp);
2220 break;
2221 default:
2222 netif_printk(qdev, rx_status, KERN_DEBUG, qdev->ndev,
2223 "Hit default case, not handled! dropping the packet, opcode = %x.\n",
2224 net_rsp->opcode);
2225 break;
2226 }
2227 count++;
2228 ql_update_cq(rx_ring);
2229 prod = ql_read_sh_reg(rx_ring->prod_idx_sh_reg);
2230 if (count == budget)
2231 break;
2232 }
2233 ql_update_buffer_queues(qdev, rx_ring);
2234 ql_write_cq_idx(rx_ring);
2235 return count;
2236}
2237
2238static int ql_napi_poll_msix(struct napi_struct *napi, int budget)
2239{
2240 struct rx_ring *rx_ring = container_of(napi, struct rx_ring, napi);
2241 struct ql_adapter *qdev = rx_ring->qdev;
2242 struct rx_ring *trx_ring;
2243 int i, work_done = 0;
2244 struct intr_context *ctx = &qdev->intr_context[rx_ring->cq_id];
2245
2246 netif_printk(qdev, rx_status, KERN_DEBUG, qdev->ndev,
2247 "Enter, NAPI POLL cq_id = %d.\n", rx_ring->cq_id);
2248
2249
2250
2251 for (i = qdev->rss_ring_count; i < qdev->rx_ring_count; i++) {
2252 trx_ring = &qdev->rx_ring[i];
2253
2254
2255
2256 if ((ctx->irq_mask & (1 << trx_ring->cq_id)) &&
2257 (ql_read_sh_reg(trx_ring->prod_idx_sh_reg) !=
2258 trx_ring->cnsmr_idx)) {
2259 netif_printk(qdev, intr, KERN_DEBUG, qdev->ndev,
2260 "%s: Servicing TX completion ring %d.\n",
2261 __func__, trx_ring->cq_id);
2262 ql_clean_outbound_rx_ring(trx_ring);
2263 }
2264 }
2265
2266
2267
2268
2269 if (ql_read_sh_reg(rx_ring->prod_idx_sh_reg) !=
2270 rx_ring->cnsmr_idx) {
2271 netif_printk(qdev, intr, KERN_DEBUG, qdev->ndev,
2272 "%s: Servicing RX completion ring %d.\n",
2273 __func__, rx_ring->cq_id);
2274 work_done = ql_clean_inbound_rx_ring(rx_ring, budget);
2275 }
2276
2277 if (work_done < budget) {
2278 napi_complete(napi);
2279 ql_enable_completion_interrupt(qdev, rx_ring->irq);
2280 }
2281 return work_done;
2282}
2283
2284static void qlge_vlan_mode(struct net_device *ndev, netdev_features_t features)
2285{
2286 struct ql_adapter *qdev = netdev_priv(ndev);
2287
2288 if (features & NETIF_F_HW_VLAN_RX) {
2289 ql_write32(qdev, NIC_RCV_CFG, NIC_RCV_CFG_VLAN_MASK |
2290 NIC_RCV_CFG_VLAN_MATCH_AND_NON);
2291 } else {
2292 ql_write32(qdev, NIC_RCV_CFG, NIC_RCV_CFG_VLAN_MASK);
2293 }
2294}
2295
2296static netdev_features_t qlge_fix_features(struct net_device *ndev,
2297 netdev_features_t features)
2298{
2299
2300
2301
2302
2303 if (features & NETIF_F_HW_VLAN_RX)
2304 features |= NETIF_F_HW_VLAN_TX;
2305 else
2306 features &= ~NETIF_F_HW_VLAN_TX;
2307
2308 return features;
2309}
2310
2311static int qlge_set_features(struct net_device *ndev,
2312 netdev_features_t features)
2313{
2314 netdev_features_t changed = ndev->features ^ features;
2315
2316 if (changed & NETIF_F_HW_VLAN_RX)
2317 qlge_vlan_mode(ndev, features);
2318
2319 return 0;
2320}
2321
2322static int __qlge_vlan_rx_add_vid(struct ql_adapter *qdev, u16 vid)
2323{
2324 u32 enable_bit = MAC_ADDR_E;
2325 int err;
2326
2327 err = ql_set_mac_addr_reg(qdev, (u8 *) &enable_bit,
2328 MAC_ADDR_TYPE_VLAN, vid);
2329 if (err)
2330 netif_err(qdev, ifup, qdev->ndev,
2331 "Failed to init vlan address.\n");
2332 return err;
2333}
2334
2335static int qlge_vlan_rx_add_vid(struct net_device *ndev, u16 vid)
2336{
2337 struct ql_adapter *qdev = netdev_priv(ndev);
2338 int status;
2339 int err;
2340
2341 status = ql_sem_spinlock(qdev, SEM_MAC_ADDR_MASK);
2342 if (status)
2343 return status;
2344
2345 err = __qlge_vlan_rx_add_vid(qdev, vid);
2346 set_bit(vid, qdev->active_vlans);
2347
2348 ql_sem_unlock(qdev, SEM_MAC_ADDR_MASK);
2349
2350 return err;
2351}
2352
2353static int __qlge_vlan_rx_kill_vid(struct ql_adapter *qdev, u16 vid)
2354{
2355 u32 enable_bit = 0;
2356 int err;
2357
2358 err = ql_set_mac_addr_reg(qdev, (u8 *) &enable_bit,
2359 MAC_ADDR_TYPE_VLAN, vid);
2360 if (err)
2361 netif_err(qdev, ifup, qdev->ndev,
2362 "Failed to clear vlan address.\n");
2363 return err;
2364}
2365
2366static int qlge_vlan_rx_kill_vid(struct net_device *ndev, u16 vid)
2367{
2368 struct ql_adapter *qdev = netdev_priv(ndev);
2369 int status;
2370 int err;
2371
2372 status = ql_sem_spinlock(qdev, SEM_MAC_ADDR_MASK);
2373 if (status)
2374 return status;
2375
2376 err = __qlge_vlan_rx_kill_vid(qdev, vid);
2377 clear_bit(vid, qdev->active_vlans);
2378
2379 ql_sem_unlock(qdev, SEM_MAC_ADDR_MASK);
2380
2381 return err;
2382}
2383
2384static void qlge_restore_vlan(struct ql_adapter *qdev)
2385{
2386 int status;
2387 u16 vid;
2388
2389 status = ql_sem_spinlock(qdev, SEM_MAC_ADDR_MASK);
2390 if (status)
2391 return;
2392
2393 for_each_set_bit(vid, qdev->active_vlans, VLAN_N_VID)
2394 __qlge_vlan_rx_add_vid(qdev, vid);
2395
2396 ql_sem_unlock(qdev, SEM_MAC_ADDR_MASK);
2397}
2398
2399
2400static irqreturn_t qlge_msix_rx_isr(int irq, void *dev_id)
2401{
2402 struct rx_ring *rx_ring = dev_id;
2403 napi_schedule(&rx_ring->napi);
2404 return IRQ_HANDLED;
2405}
2406
2407
2408
2409
2410
2411
2412static irqreturn_t qlge_isr(int irq, void *dev_id)
2413{
2414 struct rx_ring *rx_ring = dev_id;
2415 struct ql_adapter *qdev = rx_ring->qdev;
2416 struct intr_context *intr_context = &qdev->intr_context[0];
2417 u32 var;
2418 int work_done = 0;
2419
2420 spin_lock(&qdev->hw_lock);
2421 if (atomic_read(&qdev->intr_context[0].irq_cnt)) {
2422 netif_printk(qdev, intr, KERN_DEBUG, qdev->ndev,
2423 "Shared Interrupt, Not ours!\n");
2424 spin_unlock(&qdev->hw_lock);
2425 return IRQ_NONE;
2426 }
2427 spin_unlock(&qdev->hw_lock);
2428
2429 var = ql_disable_completion_interrupt(qdev, intr_context->intr);
2430
2431
2432
2433
2434 if (var & STS_FE) {
2435 ql_queue_asic_error(qdev);
2436 netdev_err(qdev->ndev, "Got fatal error, STS = %x.\n", var);
2437 var = ql_read32(qdev, ERR_STS);
2438 netdev_err(qdev->ndev, "Resetting chip. "
2439 "Error Status Register = 0x%x\n", var);
2440 return IRQ_HANDLED;
2441 }
2442
2443
2444
2445
2446 if ((var & STS_PI) &&
2447 (ql_read32(qdev, INTR_MASK) & INTR_MASK_PI)) {
2448
2449
2450
2451
2452 netif_err(qdev, intr, qdev->ndev,
2453 "Got MPI processor interrupt.\n");
2454 ql_disable_completion_interrupt(qdev, intr_context->intr);
2455 ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16));
2456 queue_delayed_work_on(smp_processor_id(),
2457 qdev->workqueue, &qdev->mpi_work, 0);
2458 work_done++;
2459 }
2460
2461
2462
2463
2464
2465
2466 var = ql_read32(qdev, ISR1);
2467 if (var & intr_context->irq_mask) {
2468 netif_info(qdev, intr, qdev->ndev,
2469 "Waking handler for rx_ring[0].\n");
2470 ql_disable_completion_interrupt(qdev, intr_context->intr);
2471 napi_schedule(&rx_ring->napi);
2472 work_done++;
2473 }
2474 ql_enable_completion_interrupt(qdev, intr_context->intr);
2475 return work_done ? IRQ_HANDLED : IRQ_NONE;
2476}
2477
2478static int ql_tso(struct sk_buff *skb, struct ob_mac_tso_iocb_req *mac_iocb_ptr)
2479{
2480
2481 if (skb_is_gso(skb)) {
2482 int err;
2483 if (skb_header_cloned(skb)) {
2484 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
2485 if (err)
2486 return err;
2487 }
2488
2489 mac_iocb_ptr->opcode = OPCODE_OB_MAC_TSO_IOCB;
2490 mac_iocb_ptr->flags3 |= OB_MAC_TSO_IOCB_IC;
2491 mac_iocb_ptr->frame_len = cpu_to_le32((u32) skb->len);
2492 mac_iocb_ptr->total_hdrs_len =
2493 cpu_to_le16(skb_transport_offset(skb) + tcp_hdrlen(skb));
2494 mac_iocb_ptr->net_trans_offset =
2495 cpu_to_le16(skb_network_offset(skb) |
2496 skb_transport_offset(skb)
2497 << OB_MAC_TRANSPORT_HDR_SHIFT);
2498 mac_iocb_ptr->mss = cpu_to_le16(skb_shinfo(skb)->gso_size);
2499 mac_iocb_ptr->flags2 |= OB_MAC_TSO_IOCB_LSO;
2500 if (likely(skb->protocol == htons(ETH_P_IP))) {
2501 struct iphdr *iph = ip_hdr(skb);
2502 iph->check = 0;
2503 mac_iocb_ptr->flags1 |= OB_MAC_TSO_IOCB_IP4;
2504 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
2505 iph->daddr, 0,
2506 IPPROTO_TCP,
2507 0);
2508 } else if (skb->protocol == htons(ETH_P_IPV6)) {
2509 mac_iocb_ptr->flags1 |= OB_MAC_TSO_IOCB_IP6;
2510 tcp_hdr(skb)->check =
2511 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
2512 &ipv6_hdr(skb)->daddr,
2513 0, IPPROTO_TCP, 0);
2514 }
2515 return 1;
2516 }
2517 return 0;
2518}
2519
2520static void ql_hw_csum_setup(struct sk_buff *skb,
2521 struct ob_mac_tso_iocb_req *mac_iocb_ptr)
2522{
2523 int len;
2524 struct iphdr *iph = ip_hdr(skb);
2525 __sum16 *check;
2526 mac_iocb_ptr->opcode = OPCODE_OB_MAC_TSO_IOCB;
2527 mac_iocb_ptr->frame_len = cpu_to_le32((u32) skb->len);
2528 mac_iocb_ptr->net_trans_offset =
2529 cpu_to_le16(skb_network_offset(skb) |
2530 skb_transport_offset(skb) << OB_MAC_TRANSPORT_HDR_SHIFT);
2531
2532 mac_iocb_ptr->flags1 |= OB_MAC_TSO_IOCB_IP4;
2533 len = (ntohs(iph->tot_len) - (iph->ihl << 2));
2534 if (likely(iph->protocol == IPPROTO_TCP)) {
2535 check = &(tcp_hdr(skb)->check);
2536 mac_iocb_ptr->flags2 |= OB_MAC_TSO_IOCB_TC;
2537 mac_iocb_ptr->total_hdrs_len =
2538 cpu_to_le16(skb_transport_offset(skb) +
2539 (tcp_hdr(skb)->doff << 2));
2540 } else {
2541 check = &(udp_hdr(skb)->check);
2542 mac_iocb_ptr->flags2 |= OB_MAC_TSO_IOCB_UC;
2543 mac_iocb_ptr->total_hdrs_len =
2544 cpu_to_le16(skb_transport_offset(skb) +
2545 sizeof(struct udphdr));
2546 }
2547 *check = ~csum_tcpudp_magic(iph->saddr,
2548 iph->daddr, len, iph->protocol, 0);
2549}
2550
2551static netdev_tx_t qlge_send(struct sk_buff *skb, struct net_device *ndev)
2552{
2553 struct tx_ring_desc *tx_ring_desc;
2554 struct ob_mac_iocb_req *mac_iocb_ptr;
2555 struct ql_adapter *qdev = netdev_priv(ndev);
2556 int tso;
2557 struct tx_ring *tx_ring;
2558 u32 tx_ring_idx = (u32) skb->queue_mapping;
2559
2560 tx_ring = &qdev->tx_ring[tx_ring_idx];
2561
2562 if (skb_padto(skb, ETH_ZLEN))
2563 return NETDEV_TX_OK;
2564
2565 if (unlikely(atomic_read(&tx_ring->tx_count) < 2)) {
2566 netif_info(qdev, tx_queued, qdev->ndev,
2567 "%s: BUG! shutting down tx queue %d due to lack of resources.\n",
2568 __func__, tx_ring_idx);
2569 netif_stop_subqueue(ndev, tx_ring->wq_id);
2570 tx_ring->tx_errors++;
2571 return NETDEV_TX_BUSY;
2572 }
2573 tx_ring_desc = &tx_ring->q[tx_ring->prod_idx];
2574 mac_iocb_ptr = tx_ring_desc->queue_entry;
2575 memset((void *)mac_iocb_ptr, 0, sizeof(*mac_iocb_ptr));
2576
2577 mac_iocb_ptr->opcode = OPCODE_OB_MAC_IOCB;
2578 mac_iocb_ptr->tid = tx_ring_desc->index;
2579
2580
2581
2582 mac_iocb_ptr->txq_idx = tx_ring_idx;
2583 tx_ring_desc->skb = skb;
2584
2585 mac_iocb_ptr->frame_len = cpu_to_le16((u16) skb->len);
2586
2587 if (vlan_tx_tag_present(skb)) {
2588 netif_printk(qdev, tx_queued, KERN_DEBUG, qdev->ndev,
2589 "Adding a vlan tag %d.\n", vlan_tx_tag_get(skb));
2590 mac_iocb_ptr->flags3 |= OB_MAC_IOCB_V;
2591 mac_iocb_ptr->vlan_tci = cpu_to_le16(vlan_tx_tag_get(skb));
2592 }
2593 tso = ql_tso(skb, (struct ob_mac_tso_iocb_req *)mac_iocb_ptr);
2594 if (tso < 0) {
2595 dev_kfree_skb_any(skb);
2596 return NETDEV_TX_OK;
2597 } else if (unlikely(!tso) && (skb->ip_summed == CHECKSUM_PARTIAL)) {
2598 ql_hw_csum_setup(skb,
2599 (struct ob_mac_tso_iocb_req *)mac_iocb_ptr);
2600 }
2601 if (ql_map_send(qdev, mac_iocb_ptr, skb, tx_ring_desc) !=
2602 NETDEV_TX_OK) {
2603 netif_err(qdev, tx_queued, qdev->ndev,
2604 "Could not map the segments.\n");
2605 tx_ring->tx_errors++;
2606 return NETDEV_TX_BUSY;
2607 }
2608 QL_DUMP_OB_MAC_IOCB(mac_iocb_ptr);
2609 tx_ring->prod_idx++;
2610 if (tx_ring->prod_idx == tx_ring->wq_len)
2611 tx_ring->prod_idx = 0;
2612 wmb();
2613
2614 ql_write_db_reg(tx_ring->prod_idx, tx_ring->prod_idx_db_reg);
2615 netif_printk(qdev, tx_queued, KERN_DEBUG, qdev->ndev,
2616 "tx queued, slot %d, len %d\n",
2617 tx_ring->prod_idx, skb->len);
2618
2619 atomic_dec(&tx_ring->tx_count);
2620
2621 if (unlikely(atomic_read(&tx_ring->tx_count) < 2)) {
2622 netif_stop_subqueue(ndev, tx_ring->wq_id);
2623 if ((atomic_read(&tx_ring->tx_count) > (tx_ring->wq_len / 4)))
2624
2625
2626
2627
2628 netif_wake_subqueue(qdev->ndev, tx_ring->wq_id);
2629 }
2630 return NETDEV_TX_OK;
2631}
2632
2633
2634static void ql_free_shadow_space(struct ql_adapter *qdev)
2635{
2636 if (qdev->rx_ring_shadow_reg_area) {
2637 pci_free_consistent(qdev->pdev,
2638 PAGE_SIZE,
2639 qdev->rx_ring_shadow_reg_area,
2640 qdev->rx_ring_shadow_reg_dma);
2641 qdev->rx_ring_shadow_reg_area = NULL;
2642 }
2643 if (qdev->tx_ring_shadow_reg_area) {
2644 pci_free_consistent(qdev->pdev,
2645 PAGE_SIZE,
2646 qdev->tx_ring_shadow_reg_area,
2647 qdev->tx_ring_shadow_reg_dma);
2648 qdev->tx_ring_shadow_reg_area = NULL;
2649 }
2650}
2651
2652static int ql_alloc_shadow_space(struct ql_adapter *qdev)
2653{
2654 qdev->rx_ring_shadow_reg_area =
2655 pci_alloc_consistent(qdev->pdev,
2656 PAGE_SIZE, &qdev->rx_ring_shadow_reg_dma);
2657 if (qdev->rx_ring_shadow_reg_area == NULL) {
2658 netif_err(qdev, ifup, qdev->ndev,
2659 "Allocation of RX shadow space failed.\n");
2660 return -ENOMEM;
2661 }
2662 memset(qdev->rx_ring_shadow_reg_area, 0, PAGE_SIZE);
2663 qdev->tx_ring_shadow_reg_area =
2664 pci_alloc_consistent(qdev->pdev, PAGE_SIZE,
2665 &qdev->tx_ring_shadow_reg_dma);
2666 if (qdev->tx_ring_shadow_reg_area == NULL) {
2667 netif_err(qdev, ifup, qdev->ndev,
2668 "Allocation of TX shadow space failed.\n");
2669 goto err_wqp_sh_area;
2670 }
2671 memset(qdev->tx_ring_shadow_reg_area, 0, PAGE_SIZE);
2672 return 0;
2673
2674err_wqp_sh_area:
2675 pci_free_consistent(qdev->pdev,
2676 PAGE_SIZE,
2677 qdev->rx_ring_shadow_reg_area,
2678 qdev->rx_ring_shadow_reg_dma);
2679 return -ENOMEM;
2680}
2681
2682static void ql_init_tx_ring(struct ql_adapter *qdev, struct tx_ring *tx_ring)
2683{
2684 struct tx_ring_desc *tx_ring_desc;
2685 int i;
2686 struct ob_mac_iocb_req *mac_iocb_ptr;
2687
2688 mac_iocb_ptr = tx_ring->wq_base;
2689 tx_ring_desc = tx_ring->q;
2690 for (i = 0; i < tx_ring->wq_len; i++) {
2691 tx_ring_desc->index = i;
2692 tx_ring_desc->skb = NULL;
2693 tx_ring_desc->queue_entry = mac_iocb_ptr;
2694 mac_iocb_ptr++;
2695 tx_ring_desc++;
2696 }
2697 atomic_set(&tx_ring->tx_count, tx_ring->wq_len);
2698}
2699
2700static void ql_free_tx_resources(struct ql_adapter *qdev,
2701 struct tx_ring *tx_ring)
2702{
2703 if (tx_ring->wq_base) {
2704 pci_free_consistent(qdev->pdev, tx_ring->wq_size,
2705 tx_ring->wq_base, tx_ring->wq_base_dma);
2706 tx_ring->wq_base = NULL;
2707 }
2708 kfree(tx_ring->q);
2709 tx_ring->q = NULL;
2710}
2711
2712static int ql_alloc_tx_resources(struct ql_adapter *qdev,
2713 struct tx_ring *tx_ring)
2714{
2715 tx_ring->wq_base =
2716 pci_alloc_consistent(qdev->pdev, tx_ring->wq_size,
2717 &tx_ring->wq_base_dma);
2718
2719 if ((tx_ring->wq_base == NULL) ||
2720 tx_ring->wq_base_dma & WQ_ADDR_ALIGN)
2721 goto pci_alloc_err;
2722
2723 tx_ring->q =
2724 kmalloc(tx_ring->wq_len * sizeof(struct tx_ring_desc), GFP_KERNEL);
2725 if (tx_ring->q == NULL)
2726 goto err;
2727
2728 return 0;
2729err:
2730 pci_free_consistent(qdev->pdev, tx_ring->wq_size,
2731 tx_ring->wq_base, tx_ring->wq_base_dma);
2732 tx_ring->wq_base = NULL;
2733pci_alloc_err:
2734 netif_err(qdev, ifup, qdev->ndev, "tx_ring alloc failed.\n");
2735 return -ENOMEM;
2736}
2737
2738static void ql_free_lbq_buffers(struct ql_adapter *qdev, struct rx_ring *rx_ring)
2739{
2740 struct bq_desc *lbq_desc;
2741
2742 uint32_t curr_idx, clean_idx;
2743
2744 curr_idx = rx_ring->lbq_curr_idx;
2745 clean_idx = rx_ring->lbq_clean_idx;
2746 while (curr_idx != clean_idx) {
2747 lbq_desc = &rx_ring->lbq[curr_idx];
2748
2749 if (lbq_desc->p.pg_chunk.last_flag) {
2750 pci_unmap_page(qdev->pdev,
2751 lbq_desc->p.pg_chunk.map,
2752 ql_lbq_block_size(qdev),
2753 PCI_DMA_FROMDEVICE);
2754 lbq_desc->p.pg_chunk.last_flag = 0;
2755 }
2756
2757 put_page(lbq_desc->p.pg_chunk.page);
2758 lbq_desc->p.pg_chunk.page = NULL;
2759
2760 if (++curr_idx == rx_ring->lbq_len)
2761 curr_idx = 0;
2762
2763 }
2764}
2765
2766static void ql_free_sbq_buffers(struct ql_adapter *qdev, struct rx_ring *rx_ring)
2767{
2768 int i;
2769 struct bq_desc *sbq_desc;
2770
2771 for (i = 0; i < rx_ring->sbq_len; i++) {
2772 sbq_desc = &rx_ring->sbq[i];
2773 if (sbq_desc == NULL) {
2774 netif_err(qdev, ifup, qdev->ndev,
2775 "sbq_desc %d is NULL.\n", i);
2776 return;
2777 }
2778 if (sbq_desc->p.skb) {
2779 pci_unmap_single(qdev->pdev,
2780 dma_unmap_addr(sbq_desc, mapaddr),
2781 dma_unmap_len(sbq_desc, maplen),
2782 PCI_DMA_FROMDEVICE);
2783 dev_kfree_skb(sbq_desc->p.skb);
2784 sbq_desc->p.skb = NULL;
2785 }
2786 }
2787}
2788
2789
2790
2791
2792static void ql_free_rx_buffers(struct ql_adapter *qdev)
2793{
2794 int i;
2795 struct rx_ring *rx_ring;
2796
2797 for (i = 0; i < qdev->rx_ring_count; i++) {
2798 rx_ring = &qdev->rx_ring[i];
2799 if (rx_ring->lbq)
2800 ql_free_lbq_buffers(qdev, rx_ring);
2801 if (rx_ring->sbq)
2802 ql_free_sbq_buffers(qdev, rx_ring);
2803 }
2804}
2805
2806static void ql_alloc_rx_buffers(struct ql_adapter *qdev)
2807{
2808 struct rx_ring *rx_ring;
2809 int i;
2810
2811 for (i = 0; i < qdev->rx_ring_count; i++) {
2812 rx_ring = &qdev->rx_ring[i];
2813 if (rx_ring->type != TX_Q)
2814 ql_update_buffer_queues(qdev, rx_ring);
2815 }
2816}
2817
2818static void ql_init_lbq_ring(struct ql_adapter *qdev,
2819 struct rx_ring *rx_ring)
2820{
2821 int i;
2822 struct bq_desc *lbq_desc;
2823 __le64 *bq = rx_ring->lbq_base;
2824
2825 memset(rx_ring->lbq, 0, rx_ring->lbq_len * sizeof(struct bq_desc));
2826 for (i = 0; i < rx_ring->lbq_len; i++) {
2827 lbq_desc = &rx_ring->lbq[i];
2828 memset(lbq_desc, 0, sizeof(*lbq_desc));
2829 lbq_desc->index = i;
2830 lbq_desc->addr = bq;
2831 bq++;
2832 }
2833}
2834
2835static void ql_init_sbq_ring(struct ql_adapter *qdev,
2836 struct rx_ring *rx_ring)
2837{
2838 int i;
2839 struct bq_desc *sbq_desc;
2840 __le64 *bq = rx_ring->sbq_base;
2841
2842 memset(rx_ring->sbq, 0, rx_ring->sbq_len * sizeof(struct bq_desc));
2843 for (i = 0; i < rx_ring->sbq_len; i++) {
2844 sbq_desc = &rx_ring->sbq[i];
2845 memset(sbq_desc, 0, sizeof(*sbq_desc));
2846 sbq_desc->index = i;
2847 sbq_desc->addr = bq;
2848 bq++;
2849 }
2850}
2851
2852static void ql_free_rx_resources(struct ql_adapter *qdev,
2853 struct rx_ring *rx_ring)
2854{
2855
2856 if (rx_ring->sbq_base) {
2857 pci_free_consistent(qdev->pdev,
2858 rx_ring->sbq_size,
2859 rx_ring->sbq_base, rx_ring->sbq_base_dma);
2860 rx_ring->sbq_base = NULL;
2861 }
2862
2863
2864 kfree(rx_ring->sbq);
2865 rx_ring->sbq = NULL;
2866
2867
2868 if (rx_ring->lbq_base) {
2869 pci_free_consistent(qdev->pdev,
2870 rx_ring->lbq_size,
2871 rx_ring->lbq_base, rx_ring->lbq_base_dma);
2872 rx_ring->lbq_base = NULL;
2873 }
2874
2875
2876 kfree(rx_ring->lbq);
2877 rx_ring->lbq = NULL;
2878
2879
2880 if (rx_ring->cq_base) {
2881 pci_free_consistent(qdev->pdev,
2882 rx_ring->cq_size,
2883 rx_ring->cq_base, rx_ring->cq_base_dma);
2884 rx_ring->cq_base = NULL;
2885 }
2886}
2887
2888
2889
2890static int ql_alloc_rx_resources(struct ql_adapter *qdev,
2891 struct rx_ring *rx_ring)
2892{
2893
2894
2895
2896
2897 rx_ring->cq_base =
2898 pci_alloc_consistent(qdev->pdev, rx_ring->cq_size,
2899 &rx_ring->cq_base_dma);
2900
2901 if (rx_ring->cq_base == NULL) {
2902 netif_err(qdev, ifup, qdev->ndev, "rx_ring alloc failed.\n");
2903 return -ENOMEM;
2904 }
2905
2906 if (rx_ring->sbq_len) {
2907
2908
2909
2910 rx_ring->sbq_base =
2911 pci_alloc_consistent(qdev->pdev, rx_ring->sbq_size,
2912 &rx_ring->sbq_base_dma);
2913
2914 if (rx_ring->sbq_base == NULL) {
2915 netif_err(qdev, ifup, qdev->ndev,
2916 "Small buffer queue allocation failed.\n");
2917 goto err_mem;
2918 }
2919
2920
2921
2922
2923 rx_ring->sbq =
2924 kmalloc(rx_ring->sbq_len * sizeof(struct bq_desc),
2925 GFP_KERNEL);
2926 if (rx_ring->sbq == NULL) {
2927 netif_err(qdev, ifup, qdev->ndev,
2928 "Small buffer queue control block allocation failed.\n");
2929 goto err_mem;
2930 }
2931
2932 ql_init_sbq_ring(qdev, rx_ring);
2933 }
2934
2935 if (rx_ring->lbq_len) {
2936
2937
2938
2939 rx_ring->lbq_base =
2940 pci_alloc_consistent(qdev->pdev, rx_ring->lbq_size,
2941 &rx_ring->lbq_base_dma);
2942
2943 if (rx_ring->lbq_base == NULL) {
2944 netif_err(qdev, ifup, qdev->ndev,
2945 "Large buffer queue allocation failed.\n");
2946 goto err_mem;
2947 }
2948
2949
2950
2951 rx_ring->lbq =
2952 kmalloc(rx_ring->lbq_len * sizeof(struct bq_desc),
2953 GFP_KERNEL);
2954 if (rx_ring->lbq == NULL) {
2955 netif_err(qdev, ifup, qdev->ndev,
2956 "Large buffer queue control block allocation failed.\n");
2957 goto err_mem;
2958 }
2959
2960 ql_init_lbq_ring(qdev, rx_ring);
2961 }
2962
2963 return 0;
2964
2965err_mem:
2966 ql_free_rx_resources(qdev, rx_ring);
2967 return -ENOMEM;
2968}
2969
2970static void ql_tx_ring_clean(struct ql_adapter *qdev)
2971{
2972 struct tx_ring *tx_ring;
2973 struct tx_ring_desc *tx_ring_desc;
2974 int i, j;
2975
2976
2977
2978
2979
2980 for (j = 0; j < qdev->tx_ring_count; j++) {
2981 tx_ring = &qdev->tx_ring[j];
2982 for (i = 0; i < tx_ring->wq_len; i++) {
2983 tx_ring_desc = &tx_ring->q[i];
2984 if (tx_ring_desc && tx_ring_desc->skb) {
2985 netif_err(qdev, ifdown, qdev->ndev,
2986 "Freeing lost SKB %p, from queue %d, index %d.\n",
2987 tx_ring_desc->skb, j,
2988 tx_ring_desc->index);
2989 ql_unmap_send(qdev, tx_ring_desc,
2990 tx_ring_desc->map_cnt);
2991 dev_kfree_skb(tx_ring_desc->skb);
2992 tx_ring_desc->skb = NULL;
2993 }
2994 }
2995 }
2996}
2997
2998static void ql_free_mem_resources(struct ql_adapter *qdev)
2999{
3000 int i;
3001
3002 for (i = 0; i < qdev->tx_ring_count; i++)
3003 ql_free_tx_resources(qdev, &qdev->tx_ring[i]);
3004 for (i = 0; i < qdev->rx_ring_count; i++)
3005 ql_free_rx_resources(qdev, &qdev->rx_ring[i]);
3006 ql_free_shadow_space(qdev);
3007}
3008
3009static int ql_alloc_mem_resources(struct ql_adapter *qdev)
3010{
3011 int i;
3012
3013
3014 if (ql_alloc_shadow_space(qdev))
3015 return -ENOMEM;
3016
3017 for (i = 0; i < qdev->rx_ring_count; i++) {
3018 if (ql_alloc_rx_resources(qdev, &qdev->rx_ring[i]) != 0) {
3019 netif_err(qdev, ifup, qdev->ndev,
3020 "RX resource allocation failed.\n");
3021 goto err_mem;
3022 }
3023 }
3024
3025 for (i = 0; i < qdev->tx_ring_count; i++) {
3026 if (ql_alloc_tx_resources(qdev, &qdev->tx_ring[i]) != 0) {
3027 netif_err(qdev, ifup, qdev->ndev,
3028 "TX resource allocation failed.\n");
3029 goto err_mem;
3030 }
3031 }
3032 return 0;
3033
3034err_mem:
3035 ql_free_mem_resources(qdev);
3036 return -ENOMEM;
3037}
3038
3039
3040
3041
3042
3043static int ql_start_rx_ring(struct ql_adapter *qdev, struct rx_ring *rx_ring)
3044{
3045 struct cqicb *cqicb = &rx_ring->cqicb;
3046 void *shadow_reg = qdev->rx_ring_shadow_reg_area +
3047 (rx_ring->cq_id * RX_RING_SHADOW_SPACE);
3048 u64 shadow_reg_dma = qdev->rx_ring_shadow_reg_dma +
3049 (rx_ring->cq_id * RX_RING_SHADOW_SPACE);
3050 void __iomem *doorbell_area =
3051 qdev->doorbell_area + (DB_PAGE_SIZE * (128 + rx_ring->cq_id));
3052 int err = 0;
3053 u16 bq_len;
3054 u64 tmp;
3055 __le64 *base_indirect_ptr;
3056 int page_entries;
3057
3058
3059 rx_ring->prod_idx_sh_reg = shadow_reg;
3060 rx_ring->prod_idx_sh_reg_dma = shadow_reg_dma;
3061 *rx_ring->prod_idx_sh_reg = 0;
3062 shadow_reg += sizeof(u64);
3063 shadow_reg_dma += sizeof(u64);
3064 rx_ring->lbq_base_indirect = shadow_reg;
3065 rx_ring->lbq_base_indirect_dma = shadow_reg_dma;
3066 shadow_reg += (sizeof(u64) * MAX_DB_PAGES_PER_BQ(rx_ring->lbq_len));
3067 shadow_reg_dma += (sizeof(u64) * MAX_DB_PAGES_PER_BQ(rx_ring->lbq_len));
3068 rx_ring->sbq_base_indirect = shadow_reg;
3069 rx_ring->sbq_base_indirect_dma = shadow_reg_dma;
3070
3071
3072 rx_ring->cnsmr_idx_db_reg = (u32 __iomem *) doorbell_area;
3073 rx_ring->cnsmr_idx = 0;
3074 rx_ring->curr_entry = rx_ring->cq_base;
3075
3076
3077 rx_ring->valid_db_reg = doorbell_area + 0x04;
3078
3079
3080 rx_ring->lbq_prod_idx_db_reg = (u32 __iomem *) (doorbell_area + 0x18);
3081
3082
3083 rx_ring->sbq_prod_idx_db_reg = (u32 __iomem *) (doorbell_area + 0x1c);
3084
3085 memset((void *)cqicb, 0, sizeof(struct cqicb));
3086 cqicb->msix_vect = rx_ring->irq;
3087
3088 bq_len = (rx_ring->cq_len == 65536) ? 0 : (u16) rx_ring->cq_len;
3089 cqicb->len = cpu_to_le16(bq_len | LEN_V | LEN_CPP_CONT);
3090
3091 cqicb->addr = cpu_to_le64(rx_ring->cq_base_dma);
3092
3093 cqicb->prod_idx_addr = cpu_to_le64(rx_ring->prod_idx_sh_reg_dma);
3094
3095
3096
3097
3098 cqicb->flags = FLAGS_LC |
3099 FLAGS_LV |
3100 FLAGS_LI;
3101 if (rx_ring->lbq_len) {
3102 cqicb->flags |= FLAGS_LL;
3103 tmp = (u64)rx_ring->lbq_base_dma;
3104 base_indirect_ptr = rx_ring->lbq_base_indirect;
3105 page_entries = 0;
3106 do {
3107 *base_indirect_ptr = cpu_to_le64(tmp);
3108 tmp += DB_PAGE_SIZE;
3109 base_indirect_ptr++;
3110 page_entries++;
3111 } while (page_entries < MAX_DB_PAGES_PER_BQ(rx_ring->lbq_len));
3112 cqicb->lbq_addr =
3113 cpu_to_le64(rx_ring->lbq_base_indirect_dma);
3114 bq_len = (rx_ring->lbq_buf_size == 65536) ? 0 :
3115 (u16) rx_ring->lbq_buf_size;
3116 cqicb->lbq_buf_size = cpu_to_le16(bq_len);
3117 bq_len = (rx_ring->lbq_len == 65536) ? 0 :
3118 (u16) rx_ring->lbq_len;
3119 cqicb->lbq_len = cpu_to_le16(bq_len);
3120 rx_ring->lbq_prod_idx = 0;
3121 rx_ring->lbq_curr_idx = 0;
3122 rx_ring->lbq_clean_idx = 0;
3123 rx_ring->lbq_free_cnt = rx_ring->lbq_len;
3124 }
3125 if (rx_ring->sbq_len) {
3126 cqicb->flags |= FLAGS_LS;
3127 tmp = (u64)rx_ring->sbq_base_dma;
3128 base_indirect_ptr = rx_ring->sbq_base_indirect;
3129 page_entries = 0;
3130 do {
3131 *base_indirect_ptr = cpu_to_le64(tmp);
3132 tmp += DB_PAGE_SIZE;
3133 base_indirect_ptr++;
3134 page_entries++;
3135 } while (page_entries < MAX_DB_PAGES_PER_BQ(rx_ring->sbq_len));
3136 cqicb->sbq_addr =
3137 cpu_to_le64(rx_ring->sbq_base_indirect_dma);
3138 cqicb->sbq_buf_size =
3139 cpu_to_le16((u16)(rx_ring->sbq_buf_size));
3140 bq_len = (rx_ring->sbq_len == 65536) ? 0 :
3141 (u16) rx_ring->sbq_len;
3142 cqicb->sbq_len = cpu_to_le16(bq_len);
3143 rx_ring->sbq_prod_idx = 0;
3144 rx_ring->sbq_curr_idx = 0;
3145 rx_ring->sbq_clean_idx = 0;
3146 rx_ring->sbq_free_cnt = rx_ring->sbq_len;
3147 }
3148 switch (rx_ring->type) {
3149 case TX_Q:
3150 cqicb->irq_delay = cpu_to_le16(qdev->tx_coalesce_usecs);
3151 cqicb->pkt_delay = cpu_to_le16(qdev->tx_max_coalesced_frames);
3152 break;
3153 case RX_Q:
3154
3155
3156
3157 netif_napi_add(qdev->ndev, &rx_ring->napi, ql_napi_poll_msix,
3158 64);
3159 cqicb->irq_delay = cpu_to_le16(qdev->rx_coalesce_usecs);
3160 cqicb->pkt_delay = cpu_to_le16(qdev->rx_max_coalesced_frames);
3161 break;
3162 default:
3163 netif_printk(qdev, ifup, KERN_DEBUG, qdev->ndev,
3164 "Invalid rx_ring->type = %d.\n", rx_ring->type);
3165 }
3166 err = ql_write_cfg(qdev, cqicb, sizeof(struct cqicb),
3167 CFG_LCQ, rx_ring->cq_id);
3168 if (err) {
3169 netif_err(qdev, ifup, qdev->ndev, "Failed to load CQICB.\n");
3170 return err;
3171 }
3172 return err;
3173}
3174
3175static int ql_start_tx_ring(struct ql_adapter *qdev, struct tx_ring *tx_ring)
3176{
3177 struct wqicb *wqicb = (struct wqicb *)tx_ring;
3178 void __iomem *doorbell_area =
3179 qdev->doorbell_area + (DB_PAGE_SIZE * tx_ring->wq_id);
3180 void *shadow_reg = qdev->tx_ring_shadow_reg_area +
3181 (tx_ring->wq_id * sizeof(u64));
3182 u64 shadow_reg_dma = qdev->tx_ring_shadow_reg_dma +
3183 (tx_ring->wq_id * sizeof(u64));
3184 int err = 0;
3185
3186
3187
3188
3189
3190 tx_ring->prod_idx_db_reg = (u32 __iomem *) doorbell_area;
3191 tx_ring->prod_idx = 0;
3192
3193 tx_ring->valid_db_reg = doorbell_area + 0x04;
3194
3195
3196
3197
3198 tx_ring->cnsmr_idx_sh_reg = shadow_reg;
3199 tx_ring->cnsmr_idx_sh_reg_dma = shadow_reg_dma;
3200
3201 wqicb->len = cpu_to_le16(tx_ring->wq_len | Q_LEN_V | Q_LEN_CPP_CONT);
3202 wqicb->flags = cpu_to_le16(Q_FLAGS_LC |
3203 Q_FLAGS_LB | Q_FLAGS_LI | Q_FLAGS_LO);
3204 wqicb->cq_id_rss = cpu_to_le16(tx_ring->cq_id);
3205 wqicb->rid = 0;
3206 wqicb->addr = cpu_to_le64(tx_ring->wq_base_dma);
3207
3208 wqicb->cnsmr_idx_addr = cpu_to_le64(tx_ring->cnsmr_idx_sh_reg_dma);
3209
3210 ql_init_tx_ring(qdev, tx_ring);
3211
3212 err = ql_write_cfg(qdev, wqicb, sizeof(*wqicb), CFG_LRQ,
3213 (u16) tx_ring->wq_id);
3214 if (err) {
3215 netif_err(qdev, ifup, qdev->ndev, "Failed to load tx_ring.\n");
3216 return err;
3217 }
3218 return err;
3219}
3220
3221static void ql_disable_msix(struct ql_adapter *qdev)
3222{
3223 if (test_bit(QL_MSIX_ENABLED, &qdev->flags)) {
3224 pci_disable_msix(qdev->pdev);
3225 clear_bit(QL_MSIX_ENABLED, &qdev->flags);
3226 kfree(qdev->msi_x_entry);
3227 qdev->msi_x_entry = NULL;
3228 } else if (test_bit(QL_MSI_ENABLED, &qdev->flags)) {
3229 pci_disable_msi(qdev->pdev);
3230 clear_bit(QL_MSI_ENABLED, &qdev->flags);
3231 }
3232}
3233
3234
3235
3236
3237
3238static void ql_enable_msix(struct ql_adapter *qdev)
3239{
3240 int i, err;
3241
3242
3243 if (qlge_irq_type == MSIX_IRQ) {
3244
3245
3246
3247 qdev->msi_x_entry = kcalloc(qdev->intr_count,
3248 sizeof(struct msix_entry),
3249 GFP_KERNEL);
3250 if (!qdev->msi_x_entry) {
3251 qlge_irq_type = MSI_IRQ;
3252 goto msi;
3253 }
3254
3255 for (i = 0; i < qdev->intr_count; i++)
3256 qdev->msi_x_entry[i].entry = i;
3257
3258
3259
3260
3261 do {
3262 err = pci_enable_msix(qdev->pdev,
3263 qdev->msi_x_entry, qdev->intr_count);
3264 if (err > 0)
3265 qdev->intr_count = err;
3266 } while (err > 0);
3267
3268 if (err < 0) {
3269 kfree(qdev->msi_x_entry);
3270 qdev->msi_x_entry = NULL;
3271 netif_warn(qdev, ifup, qdev->ndev,
3272 "MSI-X Enable failed, trying MSI.\n");
3273 qdev->intr_count = 1;
3274 qlge_irq_type = MSI_IRQ;
3275 } else if (err == 0) {
3276 set_bit(QL_MSIX_ENABLED, &qdev->flags);
3277 netif_info(qdev, ifup, qdev->ndev,
3278 "MSI-X Enabled, got %d vectors.\n",
3279 qdev->intr_count);
3280 return;
3281 }
3282 }
3283msi:
3284 qdev->intr_count = 1;
3285 if (qlge_irq_type == MSI_IRQ) {
3286 if (!pci_enable_msi(qdev->pdev)) {
3287 set_bit(QL_MSI_ENABLED, &qdev->flags);
3288 netif_info(qdev, ifup, qdev->ndev,
3289 "Running with MSI interrupts.\n");
3290 return;
3291 }
3292 }
3293 qlge_irq_type = LEG_IRQ;
3294 netif_printk(qdev, ifup, KERN_DEBUG, qdev->ndev,
3295 "Running with legacy interrupts.\n");
3296}
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307static void ql_set_tx_vect(struct ql_adapter *qdev)
3308{
3309 int i, j, vect;
3310 u32 tx_rings_per_vector = qdev->tx_ring_count / qdev->intr_count;
3311
3312 if (likely(test_bit(QL_MSIX_ENABLED, &qdev->flags))) {
3313
3314 for (vect = 0, j = 0, i = qdev->rss_ring_count;
3315 i < qdev->rx_ring_count; i++) {
3316 if (j == tx_rings_per_vector) {
3317 vect++;
3318 j = 0;
3319 }
3320 qdev->rx_ring[i].irq = vect;
3321 j++;
3322 }
3323 } else {
3324
3325
3326
3327 for (i = 0; i < qdev->rx_ring_count; i++)
3328 qdev->rx_ring[i].irq = 0;
3329 }
3330}
3331
3332
3333
3334
3335
3336
3337static void ql_set_irq_mask(struct ql_adapter *qdev, struct intr_context *ctx)
3338{
3339 int j, vect = ctx->intr;
3340 u32 tx_rings_per_vector = qdev->tx_ring_count / qdev->intr_count;
3341
3342 if (likely(test_bit(QL_MSIX_ENABLED, &qdev->flags))) {
3343
3344
3345
3346 ctx->irq_mask = (1 << qdev->rx_ring[vect].cq_id);
3347
3348
3349 for (j = 0; j < tx_rings_per_vector; j++) {
3350 ctx->irq_mask |=
3351 (1 << qdev->rx_ring[qdev->rss_ring_count +
3352 (vect * tx_rings_per_vector) + j].cq_id);
3353 }
3354 } else {
3355
3356
3357
3358 for (j = 0; j < qdev->rx_ring_count; j++)
3359 ctx->irq_mask |= (1 << qdev->rx_ring[j].cq_id);
3360 }
3361}
3362
3363
3364
3365
3366
3367
3368
3369static void ql_resolve_queues_to_irqs(struct ql_adapter *qdev)
3370{
3371 int i = 0;
3372 struct intr_context *intr_context = &qdev->intr_context[0];
3373
3374 if (likely(test_bit(QL_MSIX_ENABLED, &qdev->flags))) {
3375
3376
3377
3378
3379 for (i = 0; i < qdev->intr_count; i++, intr_context++) {
3380 qdev->rx_ring[i].irq = i;
3381 intr_context->intr = i;
3382 intr_context->qdev = qdev;
3383
3384
3385
3386 ql_set_irq_mask(qdev, intr_context);
3387
3388
3389
3390
3391 intr_context->intr_en_mask =
3392 INTR_EN_TYPE_MASK | INTR_EN_INTR_MASK |
3393 INTR_EN_TYPE_ENABLE | INTR_EN_IHD_MASK | INTR_EN_IHD
3394 | i;
3395 intr_context->intr_dis_mask =
3396 INTR_EN_TYPE_MASK | INTR_EN_INTR_MASK |
3397 INTR_EN_TYPE_DISABLE | INTR_EN_IHD_MASK |
3398 INTR_EN_IHD | i;
3399 intr_context->intr_read_mask =
3400 INTR_EN_TYPE_MASK | INTR_EN_INTR_MASK |
3401 INTR_EN_TYPE_READ | INTR_EN_IHD_MASK | INTR_EN_IHD |
3402 i;
3403 if (i == 0) {
3404
3405
3406
3407
3408
3409 intr_context->handler = qlge_isr;
3410 sprintf(intr_context->name, "%s-rx-%d",
3411 qdev->ndev->name, i);
3412 } else {
3413
3414
3415
3416 intr_context->handler = qlge_msix_rx_isr;
3417 sprintf(intr_context->name, "%s-rx-%d",
3418 qdev->ndev->name, i);
3419 }
3420 }
3421 } else {
3422
3423
3424
3425
3426 intr_context->intr = 0;
3427 intr_context->qdev = qdev;
3428
3429
3430
3431
3432 intr_context->intr_en_mask =
3433 INTR_EN_TYPE_MASK | INTR_EN_INTR_MASK | INTR_EN_TYPE_ENABLE;
3434 intr_context->intr_dis_mask =
3435 INTR_EN_TYPE_MASK | INTR_EN_INTR_MASK |
3436 INTR_EN_TYPE_DISABLE;
3437 intr_context->intr_read_mask =
3438 INTR_EN_TYPE_MASK | INTR_EN_INTR_MASK | INTR_EN_TYPE_READ;
3439
3440
3441
3442 intr_context->handler = qlge_isr;
3443 sprintf(intr_context->name, "%s-single_irq", qdev->ndev->name);
3444
3445
3446
3447
3448
3449 ql_set_irq_mask(qdev, intr_context);
3450 }
3451
3452
3453
3454 ql_set_tx_vect(qdev);
3455}
3456
3457static void ql_free_irq(struct ql_adapter *qdev)
3458{
3459 int i;
3460 struct intr_context *intr_context = &qdev->intr_context[0];
3461
3462 for (i = 0; i < qdev->intr_count; i++, intr_context++) {
3463 if (intr_context->hooked) {
3464 if (test_bit(QL_MSIX_ENABLED, &qdev->flags)) {
3465 free_irq(qdev->msi_x_entry[i].vector,
3466 &qdev->rx_ring[i]);
3467 } else {
3468 free_irq(qdev->pdev->irq, &qdev->rx_ring[0]);
3469 }
3470 }
3471 }
3472 ql_disable_msix(qdev);
3473}
3474
3475static int ql_request_irq(struct ql_adapter *qdev)
3476{
3477 int i;
3478 int status = 0;
3479 struct pci_dev *pdev = qdev->pdev;
3480 struct intr_context *intr_context = &qdev->intr_context[0];
3481
3482 ql_resolve_queues_to_irqs(qdev);
3483
3484 for (i = 0; i < qdev->intr_count; i++, intr_context++) {
3485 atomic_set(&intr_context->irq_cnt, 0);
3486 if (test_bit(QL_MSIX_ENABLED, &qdev->flags)) {
3487 status = request_irq(qdev->msi_x_entry[i].vector,
3488 intr_context->handler,
3489 0,
3490 intr_context->name,
3491 &qdev->rx_ring[i]);
3492 if (status) {
3493 netif_err(qdev, ifup, qdev->ndev,
3494 "Failed request for MSIX interrupt %d.\n",
3495 i);
3496 goto err_irq;
3497 }
3498 } else {
3499 netif_printk(qdev, ifup, KERN_DEBUG, qdev->ndev,
3500 "trying msi or legacy interrupts.\n");
3501 netif_printk(qdev, ifup, KERN_DEBUG, qdev->ndev,
3502 "%s: irq = %d.\n", __func__, pdev->irq);
3503 netif_printk(qdev, ifup, KERN_DEBUG, qdev->ndev,
3504 "%s: context->name = %s.\n", __func__,
3505 intr_context->name);
3506 netif_printk(qdev, ifup, KERN_DEBUG, qdev->ndev,
3507 "%s: dev_id = 0x%p.\n", __func__,
3508 &qdev->rx_ring[0]);
3509 status =
3510 request_irq(pdev->irq, qlge_isr,
3511 test_bit(QL_MSI_ENABLED,
3512 &qdev->
3513 flags) ? 0 : IRQF_SHARED,
3514 intr_context->name, &qdev->rx_ring[0]);
3515 if (status)
3516 goto err_irq;
3517
3518 netif_err(qdev, ifup, qdev->ndev,
3519 "Hooked intr %d, queue type %s, with name %s.\n",
3520 i,
3521 qdev->rx_ring[0].type == DEFAULT_Q ?
3522 "DEFAULT_Q" :
3523 qdev->rx_ring[0].type == TX_Q ? "TX_Q" :
3524 qdev->rx_ring[0].type == RX_Q ? "RX_Q" : "",
3525 intr_context->name);
3526 }
3527 intr_context->hooked = 1;
3528 }
3529 return status;
3530err_irq:
3531 netif_err(qdev, ifup, qdev->ndev, "Failed to get the interrupts!!!/n");
3532 ql_free_irq(qdev);
3533 return status;
3534}
3535
3536static int ql_start_rss(struct ql_adapter *qdev)
3537{
3538 static const u8 init_hash_seed[] = {
3539 0x6d, 0x5a, 0x56, 0xda, 0x25, 0x5b, 0x0e, 0xc2,
3540 0x41, 0x67, 0x25, 0x3d, 0x43, 0xa3, 0x8f, 0xb0,
3541 0xd0, 0xca, 0x2b, 0xcb, 0xae, 0x7b, 0x30, 0xb4,
3542 0x77, 0xcb, 0x2d, 0xa3, 0x80, 0x30, 0xf2, 0x0c,
3543 0x6a, 0x42, 0xb7, 0x3b, 0xbe, 0xac, 0x01, 0xfa
3544 };
3545 struct ricb *ricb = &qdev->ricb;
3546 int status = 0;
3547 int i;
3548 u8 *hash_id = (u8 *) ricb->hash_cq_id;
3549
3550 memset((void *)ricb, 0, sizeof(*ricb));
3551
3552 ricb->base_cq = RSS_L4K;
3553 ricb->flags =
3554 (RSS_L6K | RSS_LI | RSS_LB | RSS_LM | RSS_RT4 | RSS_RT6);
3555 ricb->mask = cpu_to_le16((u16)(0x3ff));
3556
3557
3558
3559
3560 for (i = 0; i < 1024; i++)
3561 hash_id[i] = (i & (qdev->rss_ring_count - 1));
3562
3563 memcpy((void *)&ricb->ipv6_hash_key[0], init_hash_seed, 40);
3564 memcpy((void *)&ricb->ipv4_hash_key[0], init_hash_seed, 16);
3565
3566 status = ql_write_cfg(qdev, ricb, sizeof(*ricb), CFG_LR, 0);
3567 if (status) {
3568 netif_err(qdev, ifup, qdev->ndev, "Failed to load RICB.\n");
3569 return status;
3570 }
3571 return status;
3572}
3573
3574static int ql_clear_routing_entries(struct ql_adapter *qdev)
3575{
3576 int i, status = 0;
3577
3578 status = ql_sem_spinlock(qdev, SEM_RT_IDX_MASK);
3579 if (status)
3580 return status;
3581
3582 for (i = 0; i < 16; i++) {
3583 status = ql_set_routing_reg(qdev, i, 0, 0);
3584 if (status) {
3585 netif_err(qdev, ifup, qdev->ndev,
3586 "Failed to init routing register for CAM packets.\n");
3587 break;
3588 }
3589 }
3590 ql_sem_unlock(qdev, SEM_RT_IDX_MASK);
3591 return status;
3592}
3593
3594
3595static int ql_route_initialize(struct ql_adapter *qdev)
3596{
3597 int status = 0;
3598
3599
3600 status = ql_clear_routing_entries(qdev);
3601 if (status)
3602 return status;
3603
3604 status = ql_sem_spinlock(qdev, SEM_RT_IDX_MASK);
3605 if (status)
3606 return status;
3607
3608 status = ql_set_routing_reg(qdev, RT_IDX_IP_CSUM_ERR_SLOT,
3609 RT_IDX_IP_CSUM_ERR, 1);
3610 if (status) {
3611 netif_err(qdev, ifup, qdev->ndev,
3612 "Failed to init routing register "
3613 "for IP CSUM error packets.\n");
3614 goto exit;
3615 }
3616 status = ql_set_routing_reg(qdev, RT_IDX_TCP_UDP_CSUM_ERR_SLOT,
3617 RT_IDX_TU_CSUM_ERR, 1);
3618 if (status) {
3619 netif_err(qdev, ifup, qdev->ndev,
3620 "Failed to init routing register "
3621 "for TCP/UDP CSUM error packets.\n");
3622 goto exit;
3623 }
3624 status = ql_set_routing_reg(qdev, RT_IDX_BCAST_SLOT, RT_IDX_BCAST, 1);
3625 if (status) {
3626 netif_err(qdev, ifup, qdev->ndev,
3627 "Failed to init routing register for broadcast packets.\n");
3628 goto exit;
3629 }
3630
3631
3632
3633 if (qdev->rss_ring_count > 1) {
3634 status = ql_set_routing_reg(qdev, RT_IDX_RSS_MATCH_SLOT,
3635 RT_IDX_RSS_MATCH, 1);
3636 if (status) {
3637 netif_err(qdev, ifup, qdev->ndev,
3638 "Failed to init routing register for MATCH RSS packets.\n");
3639 goto exit;
3640 }
3641 }
3642
3643 status = ql_set_routing_reg(qdev, RT_IDX_CAM_HIT_SLOT,
3644 RT_IDX_CAM_HIT, 1);
3645 if (status)
3646 netif_err(qdev, ifup, qdev->ndev,
3647 "Failed to init routing register for CAM packets.\n");
3648exit:
3649 ql_sem_unlock(qdev, SEM_RT_IDX_MASK);
3650 return status;
3651}
3652
3653int ql_cam_route_initialize(struct ql_adapter *qdev)
3654{
3655 int status, set;
3656
3657
3658
3659
3660
3661 set = ql_read32(qdev, STS);
3662 set &= qdev->port_link_up;
3663 status = ql_set_mac_addr(qdev, set);
3664 if (status) {
3665 netif_err(qdev, ifup, qdev->ndev, "Failed to init mac address.\n");
3666 return status;
3667 }
3668
3669 status = ql_route_initialize(qdev);
3670 if (status)
3671 netif_err(qdev, ifup, qdev->ndev, "Failed to init routing table.\n");
3672
3673 return status;
3674}
3675
3676static int ql_adapter_initialize(struct ql_adapter *qdev)
3677{
3678 u32 value, mask;
3679 int i;
3680 int status = 0;
3681
3682
3683
3684
3685 value = SYS_EFE | SYS_FAE;
3686 mask = value << 16;
3687 ql_write32(qdev, SYS, mask | value);
3688
3689
3690 value = NIC_RCV_CFG_DFQ | NIC_RCV_CFG_RV;
3691 mask = NIC_RCV_CFG_DFQ_MASK | (NIC_RCV_CFG_RV << 16);
3692 ql_write32(qdev, NIC_RCV_CFG, (mask | value));
3693
3694
3695 ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16) | INTR_MASK_PI);
3696
3697
3698 value = FSC_FE | FSC_EPC_INBOUND | FSC_EPC_OUTBOUND |
3699 FSC_EC | FSC_VM_PAGE_4K;
3700 value |= SPLT_SETTING;
3701
3702
3703 mask = FSC_VM_PAGESIZE_MASK |
3704 FSC_DBL_MASK | FSC_DBRST_MASK | (value << 16);
3705 ql_write32(qdev, FSC, mask | value);
3706
3707 ql_write32(qdev, SPLT_HDR, SPLT_LEN);
3708
3709
3710
3711
3712
3713
3714 ql_write32(qdev, RST_FO, RST_FO_RR_MASK | RST_FO_RR_RCV_FUNC_CQ);
3715
3716
3717
3718
3719 value = ql_read32(qdev, MGMT_RCV_CFG);
3720 value &= ~MGMT_RCV_CFG_RM;
3721 mask = 0xffff0000;
3722
3723
3724 ql_write32(qdev, MGMT_RCV_CFG, mask);
3725 ql_write32(qdev, MGMT_RCV_CFG, mask | value);
3726
3727
3728 if (qdev->pdev->subsystem_device == 0x0068 ||
3729 qdev->pdev->subsystem_device == 0x0180)
3730 qdev->wol = WAKE_MAGIC;
3731
3732
3733 for (i = 0; i < qdev->rx_ring_count; i++) {
3734 status = ql_start_rx_ring(qdev, &qdev->rx_ring[i]);
3735 if (status) {
3736 netif_err(qdev, ifup, qdev->ndev,
3737 "Failed to start rx ring[%d].\n", i);
3738 return status;
3739 }
3740 }
3741
3742
3743
3744
3745 if (qdev->rss_ring_count > 1) {
3746 status = ql_start_rss(qdev);
3747 if (status) {
3748 netif_err(qdev, ifup, qdev->ndev, "Failed to start RSS.\n");
3749 return status;
3750 }
3751 }
3752
3753
3754 for (i = 0; i < qdev->tx_ring_count; i++) {
3755 status = ql_start_tx_ring(qdev, &qdev->tx_ring[i]);
3756 if (status) {
3757 netif_err(qdev, ifup, qdev->ndev,
3758 "Failed to start tx ring[%d].\n", i);
3759 return status;
3760 }
3761 }
3762
3763
3764 status = qdev->nic_ops->port_initialize(qdev);
3765 if (status)
3766 netif_err(qdev, ifup, qdev->ndev, "Failed to start port.\n");
3767
3768
3769 status = ql_cam_route_initialize(qdev);
3770 if (status) {
3771 netif_err(qdev, ifup, qdev->ndev,
3772 "Failed to init CAM/Routing tables.\n");
3773 return status;
3774 }
3775
3776
3777 for (i = 0; i < qdev->rss_ring_count; i++)
3778 napi_enable(&qdev->rx_ring[i].napi);
3779
3780 return status;
3781}
3782
3783
3784static int ql_adapter_reset(struct ql_adapter *qdev)
3785{
3786 u32 value;
3787 int status = 0;
3788 unsigned long end_jiffies;
3789
3790
3791 status = ql_clear_routing_entries(qdev);
3792 if (status) {
3793 netif_err(qdev, ifup, qdev->ndev, "Failed to clear routing bits.\n");
3794 return status;
3795 }
3796
3797 end_jiffies = jiffies +
3798 max((unsigned long)1, usecs_to_jiffies(30));
3799
3800
3801
3802
3803 if (!test_bit(QL_ASIC_RECOVERY, &qdev->flags)) {
3804
3805 ql_mb_set_mgmnt_traffic_ctl(qdev, MB_SET_MPI_TFK_STOP);
3806
3807
3808 ql_wait_fifo_empty(qdev);
3809 } else
3810 clear_bit(QL_ASIC_RECOVERY, &qdev->flags);
3811
3812 ql_write32(qdev, RST_FO, (RST_FO_FR << 16) | RST_FO_FR);
3813
3814 do {
3815 value = ql_read32(qdev, RST_FO);
3816 if ((value & RST_FO_FR) == 0)
3817 break;
3818 cpu_relax();
3819 } while (time_before(jiffies, end_jiffies));
3820
3821 if (value & RST_FO_FR) {
3822 netif_err(qdev, ifdown, qdev->ndev,
3823 "ETIMEDOUT!!! errored out of resetting the chip!\n");
3824 status = -ETIMEDOUT;
3825 }
3826
3827
3828 ql_mb_set_mgmnt_traffic_ctl(qdev, MB_SET_MPI_TFK_RESUME);
3829 return status;
3830}
3831
3832static void ql_display_dev_info(struct net_device *ndev)
3833{
3834 struct ql_adapter *qdev = netdev_priv(ndev);
3835
3836 netif_info(qdev, probe, qdev->ndev,
3837 "Function #%d, Port %d, NIC Roll %d, NIC Rev = %d, "
3838 "XG Roll = %d, XG Rev = %d.\n",
3839 qdev->func,
3840 qdev->port,
3841 qdev->chip_rev_id & 0x0000000f,
3842 qdev->chip_rev_id >> 4 & 0x0000000f,
3843 qdev->chip_rev_id >> 8 & 0x0000000f,
3844 qdev->chip_rev_id >> 12 & 0x0000000f);
3845 netif_info(qdev, probe, qdev->ndev,
3846 "MAC address %pM\n", ndev->dev_addr);
3847}
3848
3849static int ql_wol(struct ql_adapter *qdev)
3850{
3851 int status = 0;
3852 u32 wol = MB_WOL_DISABLE;
3853
3854
3855
3856
3857
3858
3859
3860
3861 if (qdev->wol & (WAKE_ARP | WAKE_MAGICSECURE | WAKE_PHY | WAKE_UCAST |
3862 WAKE_MCAST | WAKE_BCAST)) {
3863 netif_err(qdev, ifdown, qdev->ndev,
3864 "Unsupported WOL parameter. qdev->wol = 0x%x.\n",
3865 qdev->wol);
3866 return -EINVAL;
3867 }
3868
3869 if (qdev->wol & WAKE_MAGIC) {
3870 status = ql_mb_wol_set_magic(qdev, 1);
3871 if (status) {
3872 netif_err(qdev, ifdown, qdev->ndev,
3873 "Failed to set magic packet on %s.\n",
3874 qdev->ndev->name);
3875 return status;
3876 } else
3877 netif_info(qdev, drv, qdev->ndev,
3878 "Enabled magic packet successfully on %s.\n",
3879 qdev->ndev->name);
3880
3881 wol |= MB_WOL_MAGIC_PKT;
3882 }
3883
3884 if (qdev->wol) {
3885 wol |= MB_WOL_MODE_ON;
3886 status = ql_mb_wol_mode(qdev, wol);
3887 netif_err(qdev, drv, qdev->ndev,
3888 "WOL %s (wol code 0x%x) on %s\n",
3889 (status == 0) ? "Successfully set" : "Failed",
3890 wol, qdev->ndev->name);
3891 }
3892
3893 return status;
3894}
3895
3896static void ql_cancel_all_work_sync(struct ql_adapter *qdev)
3897{
3898
3899
3900
3901
3902 if (test_bit(QL_ADAPTER_UP, &qdev->flags))
3903 cancel_delayed_work_sync(&qdev->asic_reset_work);
3904 cancel_delayed_work_sync(&qdev->mpi_reset_work);
3905 cancel_delayed_work_sync(&qdev->mpi_work);
3906 cancel_delayed_work_sync(&qdev->mpi_idc_work);
3907 cancel_delayed_work_sync(&qdev->mpi_core_to_log);
3908 cancel_delayed_work_sync(&qdev->mpi_port_cfg_work);
3909}
3910
3911static int ql_adapter_down(struct ql_adapter *qdev)
3912{
3913 int i, status = 0;
3914
3915 ql_link_off(qdev);
3916
3917 ql_cancel_all_work_sync(qdev);
3918
3919 for (i = 0; i < qdev->rss_ring_count; i++)
3920 napi_disable(&qdev->rx_ring[i].napi);
3921
3922 clear_bit(QL_ADAPTER_UP, &qdev->flags);
3923
3924 ql_disable_interrupts(qdev);
3925
3926 ql_tx_ring_clean(qdev);
3927
3928
3929
3930 for (i = 0; i < qdev->rss_ring_count; i++)
3931 netif_napi_del(&qdev->rx_ring[i].napi);
3932
3933 status = ql_adapter_reset(qdev);
3934 if (status)
3935 netif_err(qdev, ifdown, qdev->ndev, "reset(func #%d) FAILED!\n",
3936 qdev->func);
3937 ql_free_rx_buffers(qdev);
3938
3939 return status;
3940}
3941
3942static int ql_adapter_up(struct ql_adapter *qdev)
3943{
3944 int err = 0;
3945
3946 err = ql_adapter_initialize(qdev);
3947 if (err) {
3948 netif_info(qdev, ifup, qdev->ndev, "Unable to initialize adapter.\n");
3949 goto err_init;
3950 }
3951 set_bit(QL_ADAPTER_UP, &qdev->flags);
3952 ql_alloc_rx_buffers(qdev);
3953
3954
3955
3956 if ((ql_read32(qdev, STS) & qdev->port_init) &&
3957 (ql_read32(qdev, STS) & qdev->port_link_up))
3958 ql_link_on(qdev);
3959
3960 clear_bit(QL_ALLMULTI, &qdev->flags);
3961 clear_bit(QL_PROMISCUOUS, &qdev->flags);
3962 qlge_set_multicast_list(qdev->ndev);
3963
3964
3965 qlge_restore_vlan(qdev);
3966
3967 ql_enable_interrupts(qdev);
3968 ql_enable_all_completion_interrupts(qdev);
3969 netif_tx_start_all_queues(qdev->ndev);
3970
3971 return 0;
3972err_init:
3973 ql_adapter_reset(qdev);
3974 return err;
3975}
3976
3977static void ql_release_adapter_resources(struct ql_adapter *qdev)
3978{
3979 ql_free_mem_resources(qdev);
3980 ql_free_irq(qdev);
3981}
3982
3983static int ql_get_adapter_resources(struct ql_adapter *qdev)
3984{
3985 int status = 0;
3986
3987 if (ql_alloc_mem_resources(qdev)) {
3988 netif_err(qdev, ifup, qdev->ndev, "Unable to allocate memory.\n");
3989 return -ENOMEM;
3990 }
3991 status = ql_request_irq(qdev);
3992 return status;
3993}
3994
3995static int qlge_close(struct net_device *ndev)
3996{
3997 struct ql_adapter *qdev = netdev_priv(ndev);
3998
3999
4000
4001
4002
4003 if (test_bit(QL_EEH_FATAL, &qdev->flags)) {
4004 netif_err(qdev, drv, qdev->ndev, "EEH fatal did unload.\n");
4005 clear_bit(QL_EEH_FATAL, &qdev->flags);
4006 return 0;
4007 }
4008
4009
4010
4011
4012
4013 while (!test_bit(QL_ADAPTER_UP, &qdev->flags))
4014 msleep(1);
4015 ql_adapter_down(qdev);
4016 ql_release_adapter_resources(qdev);
4017 return 0;
4018}
4019
4020static int ql_configure_rings(struct ql_adapter *qdev)
4021{
4022 int i;
4023 struct rx_ring *rx_ring;
4024 struct tx_ring *tx_ring;
4025 int cpu_cnt = min(MAX_CPUS, (int)num_online_cpus());
4026 unsigned int lbq_buf_len = (qdev->ndev->mtu > 1500) ?
4027 LARGE_BUFFER_MAX_SIZE : LARGE_BUFFER_MIN_SIZE;
4028
4029 qdev->lbq_buf_order = get_order(lbq_buf_len);
4030
4031
4032
4033
4034
4035
4036
4037
4038 qdev->intr_count = cpu_cnt;
4039 ql_enable_msix(qdev);
4040
4041 qdev->rss_ring_count = qdev->intr_count;
4042 qdev->tx_ring_count = cpu_cnt;
4043 qdev->rx_ring_count = qdev->tx_ring_count + qdev->rss_ring_count;
4044
4045 for (i = 0; i < qdev->tx_ring_count; i++) {
4046 tx_ring = &qdev->tx_ring[i];
4047 memset((void *)tx_ring, 0, sizeof(*tx_ring));
4048 tx_ring->qdev = qdev;
4049 tx_ring->wq_id = i;
4050 tx_ring->wq_len = qdev->tx_ring_size;
4051 tx_ring->wq_size =
4052 tx_ring->wq_len * sizeof(struct ob_mac_iocb_req);
4053
4054
4055
4056
4057
4058 tx_ring->cq_id = qdev->rss_ring_count + i;
4059 }
4060
4061 for (i = 0; i < qdev->rx_ring_count; i++) {
4062 rx_ring = &qdev->rx_ring[i];
4063 memset((void *)rx_ring, 0, sizeof(*rx_ring));
4064 rx_ring->qdev = qdev;
4065 rx_ring->cq_id = i;
4066 rx_ring->cpu = i % cpu_cnt;
4067 if (i < qdev->rss_ring_count) {
4068
4069
4070
4071 rx_ring->cq_len = qdev->rx_ring_size;
4072 rx_ring->cq_size =
4073 rx_ring->cq_len * sizeof(struct ql_net_rsp_iocb);
4074 rx_ring->lbq_len = NUM_LARGE_BUFFERS;
4075 rx_ring->lbq_size =
4076 rx_ring->lbq_len * sizeof(__le64);
4077 rx_ring->lbq_buf_size = (u16)lbq_buf_len;
4078 rx_ring->sbq_len = NUM_SMALL_BUFFERS;
4079 rx_ring->sbq_size =
4080 rx_ring->sbq_len * sizeof(__le64);
4081 rx_ring->sbq_buf_size = SMALL_BUF_MAP_SIZE;
4082 rx_ring->type = RX_Q;
4083 } else {
4084
4085
4086
4087
4088 rx_ring->cq_len = qdev->tx_ring_size;
4089 rx_ring->cq_size =
4090 rx_ring->cq_len * sizeof(struct ql_net_rsp_iocb);
4091 rx_ring->lbq_len = 0;
4092 rx_ring->lbq_size = 0;
4093 rx_ring->lbq_buf_size = 0;
4094 rx_ring->sbq_len = 0;
4095 rx_ring->sbq_size = 0;
4096 rx_ring->sbq_buf_size = 0;
4097 rx_ring->type = TX_Q;
4098 }
4099 }
4100 return 0;
4101}
4102
4103static int qlge_open(struct net_device *ndev)
4104{
4105 int err = 0;
4106 struct ql_adapter *qdev = netdev_priv(ndev);
4107
4108 err = ql_adapter_reset(qdev);
4109 if (err)
4110 return err;
4111
4112 err = ql_configure_rings(qdev);
4113 if (err)
4114 return err;
4115
4116 err = ql_get_adapter_resources(qdev);
4117 if (err)
4118 goto error_up;
4119
4120 err = ql_adapter_up(qdev);
4121 if (err)
4122 goto error_up;
4123
4124 return err;
4125
4126error_up:
4127 ql_release_adapter_resources(qdev);
4128 return err;
4129}
4130
4131static int ql_change_rx_buffers(struct ql_adapter *qdev)
4132{
4133 struct rx_ring *rx_ring;
4134 int i, status;
4135 u32 lbq_buf_len;
4136
4137
4138 if (!test_bit(QL_ADAPTER_UP, &qdev->flags)) {
4139 int i = 3;
4140 while (i-- && !test_bit(QL_ADAPTER_UP, &qdev->flags)) {
4141 netif_err(qdev, ifup, qdev->ndev,
4142 "Waiting for adapter UP...\n");
4143 ssleep(1);
4144 }
4145
4146 if (!i) {
4147 netif_err(qdev, ifup, qdev->ndev,
4148 "Timed out waiting for adapter UP\n");
4149 return -ETIMEDOUT;
4150 }
4151 }
4152
4153 status = ql_adapter_down(qdev);
4154 if (status)
4155 goto error;
4156
4157
4158 lbq_buf_len = (qdev->ndev->mtu > 1500) ?
4159 LARGE_BUFFER_MAX_SIZE : LARGE_BUFFER_MIN_SIZE;
4160 qdev->lbq_buf_order = get_order(lbq_buf_len);
4161
4162 for (i = 0; i < qdev->rss_ring_count; i++) {
4163 rx_ring = &qdev->rx_ring[i];
4164
4165 rx_ring->lbq_buf_size = lbq_buf_len;
4166 }
4167
4168 status = ql_adapter_up(qdev);
4169 if (status)
4170 goto error;
4171
4172 return status;
4173error:
4174 netif_alert(qdev, ifup, qdev->ndev,
4175 "Driver up/down cycle failed, closing device.\n");
4176 set_bit(QL_ADAPTER_UP, &qdev->flags);
4177 dev_close(qdev->ndev);
4178 return status;
4179}
4180
4181static int qlge_change_mtu(struct net_device *ndev, int new_mtu)
4182{
4183 struct ql_adapter *qdev = netdev_priv(ndev);
4184 int status;
4185
4186 if (ndev->mtu == 1500 && new_mtu == 9000) {
4187 netif_err(qdev, ifup, qdev->ndev, "Changing to jumbo MTU.\n");
4188 } else if (ndev->mtu == 9000 && new_mtu == 1500) {
4189 netif_err(qdev, ifup, qdev->ndev, "Changing to normal MTU.\n");
4190 } else
4191 return -EINVAL;
4192
4193 queue_delayed_work(qdev->workqueue,
4194 &qdev->mpi_port_cfg_work, 3*HZ);
4195
4196 ndev->mtu = new_mtu;
4197
4198 if (!netif_running(qdev->ndev)) {
4199 return 0;
4200 }
4201
4202 status = ql_change_rx_buffers(qdev);
4203 if (status) {
4204 netif_err(qdev, ifup, qdev->ndev,
4205 "Changing MTU failed.\n");
4206 }
4207
4208 return status;
4209}
4210
4211static struct net_device_stats *qlge_get_stats(struct net_device
4212 *ndev)
4213{
4214 struct ql_adapter *qdev = netdev_priv(ndev);
4215 struct rx_ring *rx_ring = &qdev->rx_ring[0];
4216 struct tx_ring *tx_ring = &qdev->tx_ring[0];
4217 unsigned long pkts, mcast, dropped, errors, bytes;
4218 int i;
4219
4220
4221 pkts = mcast = dropped = errors = bytes = 0;
4222 for (i = 0; i < qdev->rss_ring_count; i++, rx_ring++) {
4223 pkts += rx_ring->rx_packets;
4224 bytes += rx_ring->rx_bytes;
4225 dropped += rx_ring->rx_dropped;
4226 errors += rx_ring->rx_errors;
4227 mcast += rx_ring->rx_multicast;
4228 }
4229 ndev->stats.rx_packets = pkts;
4230 ndev->stats.rx_bytes = bytes;
4231 ndev->stats.rx_dropped = dropped;
4232 ndev->stats.rx_errors = errors;
4233 ndev->stats.multicast = mcast;
4234
4235
4236 pkts = errors = bytes = 0;
4237 for (i = 0; i < qdev->tx_ring_count; i++, tx_ring++) {
4238 pkts += tx_ring->tx_packets;
4239 bytes += tx_ring->tx_bytes;
4240 errors += tx_ring->tx_errors;
4241 }
4242 ndev->stats.tx_packets = pkts;
4243 ndev->stats.tx_bytes = bytes;
4244 ndev->stats.tx_errors = errors;
4245 return &ndev->stats;
4246}
4247
4248static void qlge_set_multicast_list(struct net_device *ndev)
4249{
4250 struct ql_adapter *qdev = netdev_priv(ndev);
4251 struct netdev_hw_addr *ha;
4252 int i, status;
4253
4254 status = ql_sem_spinlock(qdev, SEM_RT_IDX_MASK);
4255 if (status)
4256 return;
4257
4258
4259
4260
4261 if (ndev->flags & IFF_PROMISC) {
4262 if (!test_bit(QL_PROMISCUOUS, &qdev->flags)) {
4263 if (ql_set_routing_reg
4264 (qdev, RT_IDX_PROMISCUOUS_SLOT, RT_IDX_VALID, 1)) {
4265 netif_err(qdev, hw, qdev->ndev,
4266 "Failed to set promiscuous mode.\n");
4267 } else {
4268 set_bit(QL_PROMISCUOUS, &qdev->flags);
4269 }
4270 }
4271 } else {
4272 if (test_bit(QL_PROMISCUOUS, &qdev->flags)) {
4273 if (ql_set_routing_reg
4274 (qdev, RT_IDX_PROMISCUOUS_SLOT, RT_IDX_VALID, 0)) {
4275 netif_err(qdev, hw, qdev->ndev,
4276 "Failed to clear promiscuous mode.\n");
4277 } else {
4278 clear_bit(QL_PROMISCUOUS, &qdev->flags);
4279 }
4280 }
4281 }
4282
4283
4284
4285
4286
4287 if ((ndev->flags & IFF_ALLMULTI) ||
4288 (netdev_mc_count(ndev) > MAX_MULTICAST_ENTRIES)) {
4289 if (!test_bit(QL_ALLMULTI, &qdev->flags)) {
4290 if (ql_set_routing_reg
4291 (qdev, RT_IDX_ALLMULTI_SLOT, RT_IDX_MCAST, 1)) {
4292 netif_err(qdev, hw, qdev->ndev,
4293 "Failed to set all-multi mode.\n");
4294 } else {
4295 set_bit(QL_ALLMULTI, &qdev->flags);
4296 }
4297 }
4298 } else {
4299 if (test_bit(QL_ALLMULTI, &qdev->flags)) {
4300 if (ql_set_routing_reg
4301 (qdev, RT_IDX_ALLMULTI_SLOT, RT_IDX_MCAST, 0)) {
4302 netif_err(qdev, hw, qdev->ndev,
4303 "Failed to clear all-multi mode.\n");
4304 } else {
4305 clear_bit(QL_ALLMULTI, &qdev->flags);
4306 }
4307 }
4308 }
4309
4310 if (!netdev_mc_empty(ndev)) {
4311 status = ql_sem_spinlock(qdev, SEM_MAC_ADDR_MASK);
4312 if (status)
4313 goto exit;
4314 i = 0;
4315 netdev_for_each_mc_addr(ha, ndev) {
4316 if (ql_set_mac_addr_reg(qdev, (u8 *) ha->addr,
4317 MAC_ADDR_TYPE_MULTI_MAC, i)) {
4318 netif_err(qdev, hw, qdev->ndev,
4319 "Failed to loadmulticast address.\n");
4320 ql_sem_unlock(qdev, SEM_MAC_ADDR_MASK);
4321 goto exit;
4322 }
4323 i++;
4324 }
4325 ql_sem_unlock(qdev, SEM_MAC_ADDR_MASK);
4326 if (ql_set_routing_reg
4327 (qdev, RT_IDX_MCAST_MATCH_SLOT, RT_IDX_MCAST_MATCH, 1)) {
4328 netif_err(qdev, hw, qdev->ndev,
4329 "Failed to set multicast match mode.\n");
4330 } else {
4331 set_bit(QL_ALLMULTI, &qdev->flags);
4332 }
4333 }
4334exit:
4335 ql_sem_unlock(qdev, SEM_RT_IDX_MASK);
4336}
4337
4338static int qlge_set_mac_address(struct net_device *ndev, void *p)
4339{
4340 struct ql_adapter *qdev = netdev_priv(ndev);
4341 struct sockaddr *addr = p;
4342 int status;
4343
4344 if (!is_valid_ether_addr(addr->sa_data))
4345 return -EADDRNOTAVAIL;
4346 memcpy(ndev->dev_addr, addr->sa_data, ndev->addr_len);
4347
4348 memcpy(qdev->current_mac_addr, ndev->dev_addr, ndev->addr_len);
4349
4350 status = ql_sem_spinlock(qdev, SEM_MAC_ADDR_MASK);
4351 if (status)
4352 return status;
4353 status = ql_set_mac_addr_reg(qdev, (u8 *) ndev->dev_addr,
4354 MAC_ADDR_TYPE_CAM_MAC, qdev->func * MAX_CQ);
4355 if (status)
4356 netif_err(qdev, hw, qdev->ndev, "Failed to load MAC address.\n");
4357 ql_sem_unlock(qdev, SEM_MAC_ADDR_MASK);
4358 return status;
4359}
4360
4361static void qlge_tx_timeout(struct net_device *ndev)
4362{
4363 struct ql_adapter *qdev = netdev_priv(ndev);
4364 ql_queue_asic_error(qdev);
4365}
4366
4367static void ql_asic_reset_work(struct work_struct *work)
4368{
4369 struct ql_adapter *qdev =
4370 container_of(work, struct ql_adapter, asic_reset_work.work);
4371 int status;
4372 rtnl_lock();
4373 status = ql_adapter_down(qdev);
4374 if (status)
4375 goto error;
4376
4377 status = ql_adapter_up(qdev);
4378 if (status)
4379 goto error;
4380
4381
4382 clear_bit(QL_ALLMULTI, &qdev->flags);
4383 clear_bit(QL_PROMISCUOUS, &qdev->flags);
4384 qlge_set_multicast_list(qdev->ndev);
4385
4386 rtnl_unlock();
4387 return;
4388error:
4389 netif_alert(qdev, ifup, qdev->ndev,
4390 "Driver up/down cycle failed, closing device\n");
4391
4392 set_bit(QL_ADAPTER_UP, &qdev->flags);
4393 dev_close(qdev->ndev);
4394 rtnl_unlock();
4395}
4396
4397static const struct nic_operations qla8012_nic_ops = {
4398 .get_flash = ql_get_8012_flash_params,
4399 .port_initialize = ql_8012_port_initialize,
4400};
4401
4402static const struct nic_operations qla8000_nic_ops = {
4403 .get_flash = ql_get_8000_flash_params,
4404 .port_initialize = ql_8000_port_initialize,
4405};
4406
4407
4408
4409
4410
4411
4412
4413
4414static int ql_get_alt_pcie_func(struct ql_adapter *qdev)
4415{
4416 int status = 0;
4417 u32 temp;
4418 u32 nic_func1, nic_func2;
4419
4420 status = ql_read_mpi_reg(qdev, MPI_TEST_FUNC_PORT_CFG,
4421 &temp);
4422 if (status)
4423 return status;
4424
4425 nic_func1 = ((temp >> MPI_TEST_NIC1_FUNC_SHIFT) &
4426 MPI_TEST_NIC_FUNC_MASK);
4427 nic_func2 = ((temp >> MPI_TEST_NIC2_FUNC_SHIFT) &
4428 MPI_TEST_NIC_FUNC_MASK);
4429
4430 if (qdev->func == nic_func1)
4431 qdev->alt_func = nic_func2;
4432 else if (qdev->func == nic_func2)
4433 qdev->alt_func = nic_func1;
4434 else
4435 status = -EIO;
4436
4437 return status;
4438}
4439
4440static int ql_get_board_info(struct ql_adapter *qdev)
4441{
4442 int status;
4443 qdev->func =
4444 (ql_read32(qdev, STS) & STS_FUNC_ID_MASK) >> STS_FUNC_ID_SHIFT;
4445 if (qdev->func > 3)
4446 return -EIO;
4447
4448 status = ql_get_alt_pcie_func(qdev);
4449 if (status)
4450 return status;
4451
4452 qdev->port = (qdev->func < qdev->alt_func) ? 0 : 1;
4453 if (qdev->port) {
4454 qdev->xg_sem_mask = SEM_XGMAC1_MASK;
4455 qdev->port_link_up = STS_PL1;
4456 qdev->port_init = STS_PI1;
4457 qdev->mailbox_in = PROC_ADDR_MPI_RISC | PROC_ADDR_FUNC2_MBI;
4458 qdev->mailbox_out = PROC_ADDR_MPI_RISC | PROC_ADDR_FUNC2_MBO;
4459 } else {
4460 qdev->xg_sem_mask = SEM_XGMAC0_MASK;
4461 qdev->port_link_up = STS_PL0;
4462 qdev->port_init = STS_PI0;
4463 qdev->mailbox_in = PROC_ADDR_MPI_RISC | PROC_ADDR_FUNC0_MBI;
4464 qdev->mailbox_out = PROC_ADDR_MPI_RISC | PROC_ADDR_FUNC0_MBO;
4465 }
4466 qdev->chip_rev_id = ql_read32(qdev, REV_ID);
4467 qdev->device_id = qdev->pdev->device;
4468 if (qdev->device_id == QLGE_DEVICE_ID_8012)
4469 qdev->nic_ops = &qla8012_nic_ops;
4470 else if (qdev->device_id == QLGE_DEVICE_ID_8000)
4471 qdev->nic_ops = &qla8000_nic_ops;
4472 return status;
4473}
4474
4475static void ql_release_all(struct pci_dev *pdev)
4476{
4477 struct net_device *ndev = pci_get_drvdata(pdev);
4478 struct ql_adapter *qdev = netdev_priv(ndev);
4479
4480 if (qdev->workqueue) {
4481 destroy_workqueue(qdev->workqueue);
4482 qdev->workqueue = NULL;
4483 }
4484
4485 if (qdev->reg_base)
4486 iounmap(qdev->reg_base);
4487 if (qdev->doorbell_area)
4488 iounmap(qdev->doorbell_area);
4489 vfree(qdev->mpi_coredump);
4490 pci_release_regions(pdev);
4491 pci_set_drvdata(pdev, NULL);
4492}
4493
4494static int __devinit ql_init_device(struct pci_dev *pdev,
4495 struct net_device *ndev, int cards_found)
4496{
4497 struct ql_adapter *qdev = netdev_priv(ndev);
4498 int err = 0;
4499
4500 memset((void *)qdev, 0, sizeof(*qdev));
4501 err = pci_enable_device(pdev);
4502 if (err) {
4503 dev_err(&pdev->dev, "PCI device enable failed.\n");
4504 return err;
4505 }
4506
4507 qdev->ndev = ndev;
4508 qdev->pdev = pdev;
4509 pci_set_drvdata(pdev, ndev);
4510
4511
4512 err = pcie_set_readrq(pdev, 4096);
4513 if (err) {
4514 dev_err(&pdev->dev, "Set readrq failed.\n");
4515 goto err_out1;
4516 }
4517
4518 err = pci_request_regions(pdev, DRV_NAME);
4519 if (err) {
4520 dev_err(&pdev->dev, "PCI region request failed.\n");
4521 return err;
4522 }
4523
4524 pci_set_master(pdev);
4525 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) {
4526 set_bit(QL_DMA64, &qdev->flags);
4527 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
4528 } else {
4529 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
4530 if (!err)
4531 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
4532 }
4533
4534 if (err) {
4535 dev_err(&pdev->dev, "No usable DMA configuration.\n");
4536 goto err_out2;
4537 }
4538
4539
4540 pdev->needs_freset = 1;
4541 pci_save_state(pdev);
4542 qdev->reg_base =
4543 ioremap_nocache(pci_resource_start(pdev, 1),
4544 pci_resource_len(pdev, 1));
4545 if (!qdev->reg_base) {
4546 dev_err(&pdev->dev, "Register mapping failed.\n");
4547 err = -ENOMEM;
4548 goto err_out2;
4549 }
4550
4551 qdev->doorbell_area_size = pci_resource_len(pdev, 3);
4552 qdev->doorbell_area =
4553 ioremap_nocache(pci_resource_start(pdev, 3),
4554 pci_resource_len(pdev, 3));
4555 if (!qdev->doorbell_area) {
4556 dev_err(&pdev->dev, "Doorbell register mapping failed.\n");
4557 err = -ENOMEM;
4558 goto err_out2;
4559 }
4560
4561 err = ql_get_board_info(qdev);
4562 if (err) {
4563 dev_err(&pdev->dev, "Register access failed.\n");
4564 err = -EIO;
4565 goto err_out2;
4566 }
4567 qdev->msg_enable = netif_msg_init(debug, default_msg);
4568 spin_lock_init(&qdev->hw_lock);
4569 spin_lock_init(&qdev->stats_lock);
4570
4571 if (qlge_mpi_coredump) {
4572 qdev->mpi_coredump =
4573 vmalloc(sizeof(struct ql_mpi_coredump));
4574 if (qdev->mpi_coredump == NULL) {
4575 dev_err(&pdev->dev, "Coredump alloc failed.\n");
4576 err = -ENOMEM;
4577 goto err_out2;
4578 }
4579 if (qlge_force_coredump)
4580 set_bit(QL_FRC_COREDUMP, &qdev->flags);
4581 }
4582
4583 err = qdev->nic_ops->get_flash(qdev);
4584 if (err) {
4585 dev_err(&pdev->dev, "Invalid FLASH.\n");
4586 goto err_out2;
4587 }
4588
4589 memcpy(ndev->perm_addr, ndev->dev_addr, ndev->addr_len);
4590
4591 memcpy(qdev->current_mac_addr, ndev->dev_addr, ndev->addr_len);
4592
4593
4594 qdev->tx_ring_size = NUM_TX_RING_ENTRIES;
4595 qdev->rx_ring_size = NUM_RX_RING_ENTRIES;
4596
4597
4598 qdev->rx_coalesce_usecs = DFLT_COALESCE_WAIT;
4599 qdev->tx_coalesce_usecs = DFLT_COALESCE_WAIT;
4600 qdev->rx_max_coalesced_frames = DFLT_INTER_FRAME_WAIT;
4601 qdev->tx_max_coalesced_frames = DFLT_INTER_FRAME_WAIT;
4602
4603
4604
4605
4606 qdev->workqueue = create_singlethread_workqueue(ndev->name);
4607 INIT_DELAYED_WORK(&qdev->asic_reset_work, ql_asic_reset_work);
4608 INIT_DELAYED_WORK(&qdev->mpi_reset_work, ql_mpi_reset_work);
4609 INIT_DELAYED_WORK(&qdev->mpi_work, ql_mpi_work);
4610 INIT_DELAYED_WORK(&qdev->mpi_port_cfg_work, ql_mpi_port_cfg_work);
4611 INIT_DELAYED_WORK(&qdev->mpi_idc_work, ql_mpi_idc_work);
4612 INIT_DELAYED_WORK(&qdev->mpi_core_to_log, ql_mpi_core_to_log);
4613 init_completion(&qdev->ide_completion);
4614 mutex_init(&qdev->mpi_mutex);
4615
4616 if (!cards_found) {
4617 dev_info(&pdev->dev, "%s\n", DRV_STRING);
4618 dev_info(&pdev->dev, "Driver name: %s, Version: %s.\n",
4619 DRV_NAME, DRV_VERSION);
4620 }
4621 return 0;
4622err_out2:
4623 ql_release_all(pdev);
4624err_out1:
4625 pci_disable_device(pdev);
4626 return err;
4627}
4628
4629static const struct net_device_ops qlge_netdev_ops = {
4630 .ndo_open = qlge_open,
4631 .ndo_stop = qlge_close,
4632 .ndo_start_xmit = qlge_send,
4633 .ndo_change_mtu = qlge_change_mtu,
4634 .ndo_get_stats = qlge_get_stats,
4635 .ndo_set_rx_mode = qlge_set_multicast_list,
4636 .ndo_set_mac_address = qlge_set_mac_address,
4637 .ndo_validate_addr = eth_validate_addr,
4638 .ndo_tx_timeout = qlge_tx_timeout,
4639 .ndo_fix_features = qlge_fix_features,
4640 .ndo_set_features = qlge_set_features,
4641 .ndo_vlan_rx_add_vid = qlge_vlan_rx_add_vid,
4642 .ndo_vlan_rx_kill_vid = qlge_vlan_rx_kill_vid,
4643};
4644
4645static void ql_timer(unsigned long data)
4646{
4647 struct ql_adapter *qdev = (struct ql_adapter *)data;
4648 u32 var = 0;
4649
4650 var = ql_read32(qdev, STS);
4651 if (pci_channel_offline(qdev->pdev)) {
4652 netif_err(qdev, ifup, qdev->ndev, "EEH STS = 0x%.08x.\n", var);
4653 return;
4654 }
4655
4656 mod_timer(&qdev->timer, jiffies + (5*HZ));
4657}
4658
4659static int __devinit qlge_probe(struct pci_dev *pdev,
4660 const struct pci_device_id *pci_entry)
4661{
4662 struct net_device *ndev = NULL;
4663 struct ql_adapter *qdev = NULL;
4664 static int cards_found = 0;
4665 int err = 0;
4666
4667 ndev = alloc_etherdev_mq(sizeof(struct ql_adapter),
4668 min(MAX_CPUS, netif_get_num_default_rss_queues()));
4669 if (!ndev)
4670 return -ENOMEM;
4671
4672 err = ql_init_device(pdev, ndev, cards_found);
4673 if (err < 0) {
4674 free_netdev(ndev);
4675 return err;
4676 }
4677
4678 qdev = netdev_priv(ndev);
4679 SET_NETDEV_DEV(ndev, &pdev->dev);
4680 ndev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM |
4681 NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_TSO_ECN |
4682 NETIF_F_HW_VLAN_TX | NETIF_F_RXCSUM;
4683 ndev->features = ndev->hw_features |
4684 NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER;
4685 ndev->vlan_features = ndev->hw_features;
4686
4687 if (test_bit(QL_DMA64, &qdev->flags))
4688 ndev->features |= NETIF_F_HIGHDMA;
4689
4690
4691
4692
4693 ndev->tx_queue_len = qdev->tx_ring_size;
4694 ndev->irq = pdev->irq;
4695
4696 ndev->netdev_ops = &qlge_netdev_ops;
4697 SET_ETHTOOL_OPS(ndev, &qlge_ethtool_ops);
4698 ndev->watchdog_timeo = 10 * HZ;
4699
4700 err = register_netdev(ndev);
4701 if (err) {
4702 dev_err(&pdev->dev, "net device registration failed.\n");
4703 ql_release_all(pdev);
4704 pci_disable_device(pdev);
4705 return err;
4706 }
4707
4708
4709
4710 init_timer_deferrable(&qdev->timer);
4711 qdev->timer.data = (unsigned long)qdev;
4712 qdev->timer.function = ql_timer;
4713 qdev->timer.expires = jiffies + (5*HZ);
4714 add_timer(&qdev->timer);
4715 ql_link_off(qdev);
4716 ql_display_dev_info(ndev);
4717 atomic_set(&qdev->lb_count, 0);
4718 cards_found++;
4719 return 0;
4720}
4721
4722netdev_tx_t ql_lb_send(struct sk_buff *skb, struct net_device *ndev)
4723{
4724 return qlge_send(skb, ndev);
4725}
4726
4727int ql_clean_lb_rx_ring(struct rx_ring *rx_ring, int budget)
4728{
4729 return ql_clean_inbound_rx_ring(rx_ring, budget);
4730}
4731
4732static void __devexit qlge_remove(struct pci_dev *pdev)
4733{
4734 struct net_device *ndev = pci_get_drvdata(pdev);
4735 struct ql_adapter *qdev = netdev_priv(ndev);
4736 del_timer_sync(&qdev->timer);
4737 ql_cancel_all_work_sync(qdev);
4738 unregister_netdev(ndev);
4739 ql_release_all(pdev);
4740 pci_disable_device(pdev);
4741 free_netdev(ndev);
4742}
4743
4744
4745static void ql_eeh_close(struct net_device *ndev)
4746{
4747 int i;
4748 struct ql_adapter *qdev = netdev_priv(ndev);
4749
4750 if (netif_carrier_ok(ndev)) {
4751 netif_carrier_off(ndev);
4752 netif_stop_queue(ndev);
4753 }
4754
4755
4756 del_timer_sync(&qdev->timer);
4757 ql_cancel_all_work_sync(qdev);
4758
4759 for (i = 0; i < qdev->rss_ring_count; i++)
4760 netif_napi_del(&qdev->rx_ring[i].napi);
4761
4762 clear_bit(QL_ADAPTER_UP, &qdev->flags);
4763 ql_tx_ring_clean(qdev);
4764 ql_free_rx_buffers(qdev);
4765 ql_release_adapter_resources(qdev);
4766}
4767
4768
4769
4770
4771
4772static pci_ers_result_t qlge_io_error_detected(struct pci_dev *pdev,
4773 enum pci_channel_state state)
4774{
4775 struct net_device *ndev = pci_get_drvdata(pdev);
4776 struct ql_adapter *qdev = netdev_priv(ndev);
4777
4778 switch (state) {
4779 case pci_channel_io_normal:
4780 return PCI_ERS_RESULT_CAN_RECOVER;
4781 case pci_channel_io_frozen:
4782 netif_device_detach(ndev);
4783 if (netif_running(ndev))
4784 ql_eeh_close(ndev);
4785 pci_disable_device(pdev);
4786 return PCI_ERS_RESULT_NEED_RESET;
4787 case pci_channel_io_perm_failure:
4788 dev_err(&pdev->dev,
4789 "%s: pci_channel_io_perm_failure.\n", __func__);
4790 ql_eeh_close(ndev);
4791 set_bit(QL_EEH_FATAL, &qdev->flags);
4792 return PCI_ERS_RESULT_DISCONNECT;
4793 }
4794
4795
4796 return PCI_ERS_RESULT_NEED_RESET;
4797}
4798
4799
4800
4801
4802
4803
4804
4805static pci_ers_result_t qlge_io_slot_reset(struct pci_dev *pdev)
4806{
4807 struct net_device *ndev = pci_get_drvdata(pdev);
4808 struct ql_adapter *qdev = netdev_priv(ndev);
4809
4810 pdev->error_state = pci_channel_io_normal;
4811
4812 pci_restore_state(pdev);
4813 if (pci_enable_device(pdev)) {
4814 netif_err(qdev, ifup, qdev->ndev,
4815 "Cannot re-enable PCI device after reset.\n");
4816 return PCI_ERS_RESULT_DISCONNECT;
4817 }
4818 pci_set_master(pdev);
4819
4820 if (ql_adapter_reset(qdev)) {
4821 netif_err(qdev, drv, qdev->ndev, "reset FAILED!\n");
4822 set_bit(QL_EEH_FATAL, &qdev->flags);
4823 return PCI_ERS_RESULT_DISCONNECT;
4824 }
4825
4826 return PCI_ERS_RESULT_RECOVERED;
4827}
4828
4829static void qlge_io_resume(struct pci_dev *pdev)
4830{
4831 struct net_device *ndev = pci_get_drvdata(pdev);
4832 struct ql_adapter *qdev = netdev_priv(ndev);
4833 int err = 0;
4834
4835 if (netif_running(ndev)) {
4836 err = qlge_open(ndev);
4837 if (err) {
4838 netif_err(qdev, ifup, qdev->ndev,
4839 "Device initialization failed after reset.\n");
4840 return;
4841 }
4842 } else {
4843 netif_err(qdev, ifup, qdev->ndev,
4844 "Device was not running prior to EEH.\n");
4845 }
4846 mod_timer(&qdev->timer, jiffies + (5*HZ));
4847 netif_device_attach(ndev);
4848}
4849
4850static const struct pci_error_handlers qlge_err_handler = {
4851 .error_detected = qlge_io_error_detected,
4852 .slot_reset = qlge_io_slot_reset,
4853 .resume = qlge_io_resume,
4854};
4855
4856static int qlge_suspend(struct pci_dev *pdev, pm_message_t state)
4857{
4858 struct net_device *ndev = pci_get_drvdata(pdev);
4859 struct ql_adapter *qdev = netdev_priv(ndev);
4860 int err;
4861
4862 netif_device_detach(ndev);
4863 del_timer_sync(&qdev->timer);
4864
4865 if (netif_running(ndev)) {
4866 err = ql_adapter_down(qdev);
4867 if (!err)
4868 return err;
4869 }
4870
4871 ql_wol(qdev);
4872 err = pci_save_state(pdev);
4873 if (err)
4874 return err;
4875
4876 pci_disable_device(pdev);
4877
4878 pci_set_power_state(pdev, pci_choose_state(pdev, state));
4879
4880 return 0;
4881}
4882
4883#ifdef CONFIG_PM
4884static int qlge_resume(struct pci_dev *pdev)
4885{
4886 struct net_device *ndev = pci_get_drvdata(pdev);
4887 struct ql_adapter *qdev = netdev_priv(ndev);
4888 int err;
4889
4890 pci_set_power_state(pdev, PCI_D0);
4891 pci_restore_state(pdev);
4892 err = pci_enable_device(pdev);
4893 if (err) {
4894 netif_err(qdev, ifup, qdev->ndev, "Cannot enable PCI device from suspend\n");
4895 return err;
4896 }
4897 pci_set_master(pdev);
4898
4899 pci_enable_wake(pdev, PCI_D3hot, 0);
4900 pci_enable_wake(pdev, PCI_D3cold, 0);
4901
4902 if (netif_running(ndev)) {
4903 err = ql_adapter_up(qdev);
4904 if (err)
4905 return err;
4906 }
4907
4908 mod_timer(&qdev->timer, jiffies + (5*HZ));
4909 netif_device_attach(ndev);
4910
4911 return 0;
4912}
4913#endif
4914
4915static void qlge_shutdown(struct pci_dev *pdev)
4916{
4917 qlge_suspend(pdev, PMSG_SUSPEND);
4918}
4919
4920static struct pci_driver qlge_driver = {
4921 .name = DRV_NAME,
4922 .id_table = qlge_pci_tbl,
4923 .probe = qlge_probe,
4924 .remove = __devexit_p(qlge_remove),
4925#ifdef CONFIG_PM
4926 .suspend = qlge_suspend,
4927 .resume = qlge_resume,
4928#endif
4929 .shutdown = qlge_shutdown,
4930 .err_handler = &qlge_err_handler
4931};
4932
4933static int __init qlge_init_module(void)
4934{
4935 return pci_register_driver(&qlge_driver);
4936}
4937
4938static void __exit qlge_exit(void)
4939{
4940 pci_unregister_driver(&qlge_driver);
4941}
4942
4943module_init(qlge_init_module);
4944module_exit(qlge_exit);
4945