2 * QLogic qlcnic NIC Driver
3 * Copyright (c) 2009-2010 QLogic Corporation
5 * See LICENSE.qlcnic for copyright and licensing details.
8 #include <linux/slab.h>
9 #include <linux/vmalloc.h>
10 #include <linux/interrupt.h>
14 #include <linux/swab.h>
15 #include <linux/dma-mapping.h>
16 #include <linux/if_vlan.h>
18 #include <linux/ipv6.h>
19 #include <linux/inetdevice.h>
20 #include <linux/sysfs.h>
21 #include <linux/aer.h>
23 MODULE_DESCRIPTION("QLogic 1/10 GbE Converged/Intelligent Ethernet Driver");
24 MODULE_LICENSE("GPL");
25 MODULE_VERSION(QLCNIC_LINUX_VERSIONID
);
26 MODULE_FIRMWARE(QLCNIC_UNIFIED_ROMIMAGE_NAME
);
28 char qlcnic_driver_name
[] = "qlcnic";
29 static const char qlcnic_driver_string
[] = "QLogic 1/10 GbE "
30 "Converged/Intelligent Ethernet Driver v" QLCNIC_LINUX_VERSIONID
;
32 static struct workqueue_struct
*qlcnic_wq
;
33 static int qlcnic_mac_learn
;
34 module_param(qlcnic_mac_learn
, int, 0444);
35 MODULE_PARM_DESC(qlcnic_mac_learn
, "Mac Filter (0=disabled, 1=enabled)");
37 static int use_msi
= 1;
38 module_param(use_msi
, int, 0444);
39 MODULE_PARM_DESC(use_msi
, "MSI interrupt (0=disabled, 1=enabled");
41 static int use_msi_x
= 1;
42 module_param(use_msi_x
, int, 0444);
43 MODULE_PARM_DESC(use_msi_x
, "MSI-X interrupt (0=disabled, 1=enabled");
45 static int auto_fw_reset
= 1;
46 module_param(auto_fw_reset
, int, 0644);
47 MODULE_PARM_DESC(auto_fw_reset
, "Auto firmware reset (0=disabled, 1=enabled");
49 static int load_fw_file
;
50 module_param(load_fw_file
, int, 0444);
51 MODULE_PARM_DESC(load_fw_file
, "Load firmware from (0=flash, 1=file");
53 static int qlcnic_config_npars
;
54 module_param(qlcnic_config_npars
, int, 0444);
55 MODULE_PARM_DESC(qlcnic_config_npars
, "Configure NPARs (0=disabled, 1=enabled");
57 static int __devinit
qlcnic_probe(struct pci_dev
*pdev
,
58 const struct pci_device_id
*ent
);
59 static void __devexit
qlcnic_remove(struct pci_dev
*pdev
);
60 static int qlcnic_open(struct net_device
*netdev
);
61 static int qlcnic_close(struct net_device
*netdev
);
62 static void qlcnic_tx_timeout(struct net_device
*netdev
);
63 static void qlcnic_attach_work(struct work_struct
*work
);
64 static void qlcnic_fwinit_work(struct work_struct
*work
);
65 static void qlcnic_fw_poll_work(struct work_struct
*work
);
66 static void qlcnic_schedule_work(struct qlcnic_adapter
*adapter
,
67 work_func_t func
, int delay
);
68 static void qlcnic_cancel_fw_work(struct qlcnic_adapter
*adapter
);
69 static int qlcnic_poll(struct napi_struct
*napi
, int budget
);
70 static int qlcnic_rx_poll(struct napi_struct
*napi
, int budget
);
71 #ifdef CONFIG_NET_POLL_CONTROLLER
72 static void qlcnic_poll_controller(struct net_device
*netdev
);
75 static void qlcnic_create_sysfs_entries(struct qlcnic_adapter
*adapter
);
76 static void qlcnic_remove_sysfs_entries(struct qlcnic_adapter
*adapter
);
77 static void qlcnic_create_diag_entries(struct qlcnic_adapter
*adapter
);
78 static void qlcnic_remove_diag_entries(struct qlcnic_adapter
*adapter
);
80 static void qlcnic_idc_debug_info(struct qlcnic_adapter
*adapter
, u8 encoding
);
81 static void qlcnic_clr_all_drv_state(struct qlcnic_adapter
*adapter
, u8
);
82 static int qlcnic_can_start_firmware(struct qlcnic_adapter
*adapter
);
84 static irqreturn_t
qlcnic_tmp_intr(int irq
, void *data
);
85 static irqreturn_t
qlcnic_intr(int irq
, void *data
);
86 static irqreturn_t
qlcnic_msi_intr(int irq
, void *data
);
87 static irqreturn_t
qlcnic_msix_intr(int irq
, void *data
);
89 static struct net_device_stats
*qlcnic_get_stats(struct net_device
*netdev
);
90 static void qlcnic_restore_indev_addr(struct net_device
*dev
, unsigned long);
91 static int qlcnic_start_firmware(struct qlcnic_adapter
*);
93 static void qlcnic_alloc_lb_filters_mem(struct qlcnic_adapter
*adapter
);
94 static void qlcnic_free_lb_filters_mem(struct qlcnic_adapter
*adapter
);
95 static void qlcnic_dev_set_npar_ready(struct qlcnic_adapter
*);
96 static int qlcnicvf_config_led(struct qlcnic_adapter
*, u32
, u32
);
97 static int qlcnicvf_config_bridged_mode(struct qlcnic_adapter
*, u32
);
98 static int qlcnicvf_start_firmware(struct qlcnic_adapter
*);
99 static void qlcnic_set_netdev_features(struct qlcnic_adapter
*,
100 struct qlcnic_esw_func_cfg
*);
101 /* PCI Device ID Table */
102 #define ENTRY(device) \
103 {PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, (device)), \
104 .class = PCI_CLASS_NETWORK_ETHERNET << 8, .class_mask = ~0}
106 #define PCI_DEVICE_ID_QLOGIC_QLE824X 0x8020
108 static DEFINE_PCI_DEVICE_TABLE(qlcnic_pci_tbl
) = {
109 ENTRY(PCI_DEVICE_ID_QLOGIC_QLE824X
),
113 MODULE_DEVICE_TABLE(pci
, qlcnic_pci_tbl
);
117 qlcnic_update_cmd_producer(struct qlcnic_adapter
*adapter
,
118 struct qlcnic_host_tx_ring
*tx_ring
)
120 writel(tx_ring
->producer
, tx_ring
->crb_cmd_producer
);
123 static const u32 msi_tgt_status
[8] = {
124 ISR_INT_TARGET_STATUS
, ISR_INT_TARGET_STATUS_F1
,
125 ISR_INT_TARGET_STATUS_F2
, ISR_INT_TARGET_STATUS_F3
,
126 ISR_INT_TARGET_STATUS_F4
, ISR_INT_TARGET_STATUS_F5
,
127 ISR_INT_TARGET_STATUS_F6
, ISR_INT_TARGET_STATUS_F7
131 struct qlcnic_legacy_intr_set legacy_intr
[] = QLCNIC_LEGACY_INTR_CONFIG
;
133 static inline void qlcnic_disable_int(struct qlcnic_host_sds_ring
*sds_ring
)
135 writel(0, sds_ring
->crb_intr_mask
);
138 static inline void qlcnic_enable_int(struct qlcnic_host_sds_ring
*sds_ring
)
140 struct qlcnic_adapter
*adapter
= sds_ring
->adapter
;
142 writel(0x1, sds_ring
->crb_intr_mask
);
144 if (!QLCNIC_IS_MSI_FAMILY(adapter
))
145 writel(0xfbff, adapter
->tgt_mask_reg
);
149 qlcnic_alloc_sds_rings(struct qlcnic_recv_context
*recv_ctx
, int count
)
151 int size
= sizeof(struct qlcnic_host_sds_ring
) * count
;
153 recv_ctx
->sds_rings
= kzalloc(size
, GFP_KERNEL
);
155 return recv_ctx
->sds_rings
== NULL
;
159 qlcnic_free_sds_rings(struct qlcnic_recv_context
*recv_ctx
)
161 if (recv_ctx
->sds_rings
!= NULL
)
162 kfree(recv_ctx
->sds_rings
);
164 recv_ctx
->sds_rings
= NULL
;
168 qlcnic_napi_add(struct qlcnic_adapter
*adapter
, struct net_device
*netdev
)
171 struct qlcnic_host_sds_ring
*sds_ring
;
172 struct qlcnic_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
174 if (qlcnic_alloc_sds_rings(recv_ctx
, adapter
->max_sds_rings
))
177 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
178 sds_ring
= &recv_ctx
->sds_rings
[ring
];
180 if (ring
== adapter
->max_sds_rings
- 1)
181 netif_napi_add(netdev
, &sds_ring
->napi
, qlcnic_poll
,
182 QLCNIC_NETDEV_WEIGHT
/adapter
->max_sds_rings
);
184 netif_napi_add(netdev
, &sds_ring
->napi
,
185 qlcnic_rx_poll
, QLCNIC_NETDEV_WEIGHT
*2);
192 qlcnic_napi_del(struct qlcnic_adapter
*adapter
)
195 struct qlcnic_host_sds_ring
*sds_ring
;
196 struct qlcnic_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
198 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
199 sds_ring
= &recv_ctx
->sds_rings
[ring
];
200 netif_napi_del(&sds_ring
->napi
);
203 qlcnic_free_sds_rings(&adapter
->recv_ctx
);
207 qlcnic_napi_enable(struct qlcnic_adapter
*adapter
)
210 struct qlcnic_host_sds_ring
*sds_ring
;
211 struct qlcnic_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
213 if (adapter
->is_up
!= QLCNIC_ADAPTER_UP_MAGIC
)
216 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
217 sds_ring
= &recv_ctx
->sds_rings
[ring
];
218 napi_enable(&sds_ring
->napi
);
219 qlcnic_enable_int(sds_ring
);
224 qlcnic_napi_disable(struct qlcnic_adapter
*adapter
)
227 struct qlcnic_host_sds_ring
*sds_ring
;
228 struct qlcnic_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
230 if (adapter
->is_up
!= QLCNIC_ADAPTER_UP_MAGIC
)
233 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
234 sds_ring
= &recv_ctx
->sds_rings
[ring
];
235 qlcnic_disable_int(sds_ring
);
236 napi_synchronize(&sds_ring
->napi
);
237 napi_disable(&sds_ring
->napi
);
241 static void qlcnic_clear_stats(struct qlcnic_adapter
*adapter
)
243 memset(&adapter
->stats
, 0, sizeof(adapter
->stats
));
246 static void qlcnic_set_msix_bit(struct pci_dev
*pdev
, int enable
)
251 pos
= pci_find_capability(pdev
, PCI_CAP_ID_MSIX
);
253 pci_read_config_dword(pdev
, pos
, &control
);
255 control
|= PCI_MSIX_FLAGS_ENABLE
;
258 pci_write_config_dword(pdev
, pos
, control
);
262 static void qlcnic_init_msix_entries(struct qlcnic_adapter
*adapter
, int count
)
266 for (i
= 0; i
< count
; i
++)
267 adapter
->msix_entries
[i
].entry
= i
;
271 qlcnic_read_mac_addr(struct qlcnic_adapter
*adapter
)
273 u8 mac_addr
[ETH_ALEN
];
274 struct net_device
*netdev
= adapter
->netdev
;
275 struct pci_dev
*pdev
= adapter
->pdev
;
277 if (qlcnic_get_mac_address(adapter
, mac_addr
) != 0)
280 memcpy(netdev
->dev_addr
, mac_addr
, ETH_ALEN
);
281 memcpy(netdev
->perm_addr
, netdev
->dev_addr
, netdev
->addr_len
);
282 memcpy(adapter
->mac_addr
, netdev
->dev_addr
, netdev
->addr_len
);
284 /* set station address */
286 if (!is_valid_ether_addr(netdev
->perm_addr
))
287 dev_warn(&pdev
->dev
, "Bad MAC address %pM.\n",
293 static int qlcnic_set_mac(struct net_device
*netdev
, void *p
)
295 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
296 struct sockaddr
*addr
= p
;
298 if ((adapter
->flags
& QLCNIC_MAC_OVERRIDE_DISABLED
))
301 if (!is_valid_ether_addr(addr
->sa_data
))
304 if (test_bit(__QLCNIC_DEV_UP
, &adapter
->state
)) {
305 netif_device_detach(netdev
);
306 qlcnic_napi_disable(adapter
);
309 memcpy(adapter
->mac_addr
, addr
->sa_data
, netdev
->addr_len
);
310 memcpy(netdev
->dev_addr
, addr
->sa_data
, netdev
->addr_len
);
311 qlcnic_set_multi(adapter
->netdev
);
313 if (test_bit(__QLCNIC_DEV_UP
, &adapter
->state
)) {
314 netif_device_attach(netdev
);
315 qlcnic_napi_enable(adapter
);
320 static void qlcnic_vlan_rx_register(struct net_device
*netdev
,
321 struct vlan_group
*grp
)
323 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
324 adapter
->vlgrp
= grp
;
327 static const struct net_device_ops qlcnic_netdev_ops
= {
328 .ndo_open
= qlcnic_open
,
329 .ndo_stop
= qlcnic_close
,
330 .ndo_start_xmit
= qlcnic_xmit_frame
,
331 .ndo_get_stats
= qlcnic_get_stats
,
332 .ndo_validate_addr
= eth_validate_addr
,
333 .ndo_set_multicast_list
= qlcnic_set_multi
,
334 .ndo_set_mac_address
= qlcnic_set_mac
,
335 .ndo_change_mtu
= qlcnic_change_mtu
,
336 .ndo_tx_timeout
= qlcnic_tx_timeout
,
337 .ndo_vlan_rx_register
= qlcnic_vlan_rx_register
,
338 #ifdef CONFIG_NET_POLL_CONTROLLER
339 .ndo_poll_controller
= qlcnic_poll_controller
,
343 static struct qlcnic_nic_template qlcnic_ops
= {
344 .config_bridged_mode
= qlcnic_config_bridged_mode
,
345 .config_led
= qlcnic_config_led
,
346 .start_firmware
= qlcnic_start_firmware
349 static struct qlcnic_nic_template qlcnic_vf_ops
= {
350 .config_bridged_mode
= qlcnicvf_config_bridged_mode
,
351 .config_led
= qlcnicvf_config_led
,
352 .start_firmware
= qlcnicvf_start_firmware
356 qlcnic_setup_intr(struct qlcnic_adapter
*adapter
)
358 const struct qlcnic_legacy_intr_set
*legacy_intrp
;
359 struct pci_dev
*pdev
= adapter
->pdev
;
362 if (adapter
->rss_supported
) {
363 num_msix
= (num_online_cpus() >= MSIX_ENTRIES_PER_ADAPTER
) ?
364 MSIX_ENTRIES_PER_ADAPTER
: 2;
368 adapter
->max_sds_rings
= 1;
370 adapter
->flags
&= ~(QLCNIC_MSI_ENABLED
| QLCNIC_MSIX_ENABLED
);
372 legacy_intrp
= &legacy_intr
[adapter
->ahw
.pci_func
];
374 adapter
->int_vec_bit
= legacy_intrp
->int_vec_bit
;
375 adapter
->tgt_status_reg
= qlcnic_get_ioaddr(adapter
,
376 legacy_intrp
->tgt_status_reg
);
377 adapter
->tgt_mask_reg
= qlcnic_get_ioaddr(adapter
,
378 legacy_intrp
->tgt_mask_reg
);
379 adapter
->isr_int_vec
= qlcnic_get_ioaddr(adapter
, ISR_INT_VECTOR
);
381 adapter
->crb_int_state_reg
= qlcnic_get_ioaddr(adapter
,
384 qlcnic_set_msix_bit(pdev
, 0);
386 if (adapter
->msix_supported
) {
388 qlcnic_init_msix_entries(adapter
, num_msix
);
389 err
= pci_enable_msix(pdev
, adapter
->msix_entries
, num_msix
);
391 adapter
->flags
|= QLCNIC_MSIX_ENABLED
;
392 qlcnic_set_msix_bit(pdev
, 1);
394 if (adapter
->rss_supported
)
395 adapter
->max_sds_rings
= num_msix
;
397 dev_info(&pdev
->dev
, "using msi-x interrupts\n");
402 pci_disable_msix(pdev
);
404 /* fall through for msi */
407 if (use_msi
&& !pci_enable_msi(pdev
)) {
408 adapter
->flags
|= QLCNIC_MSI_ENABLED
;
409 adapter
->tgt_status_reg
= qlcnic_get_ioaddr(adapter
,
410 msi_tgt_status
[adapter
->ahw
.pci_func
]);
411 dev_info(&pdev
->dev
, "using msi interrupts\n");
412 adapter
->msix_entries
[0].vector
= pdev
->irq
;
416 dev_info(&pdev
->dev
, "using legacy interrupts\n");
417 adapter
->msix_entries
[0].vector
= pdev
->irq
;
421 qlcnic_teardown_intr(struct qlcnic_adapter
*adapter
)
423 if (adapter
->flags
& QLCNIC_MSIX_ENABLED
)
424 pci_disable_msix(adapter
->pdev
);
425 if (adapter
->flags
& QLCNIC_MSI_ENABLED
)
426 pci_disable_msi(adapter
->pdev
);
430 qlcnic_cleanup_pci_map(struct qlcnic_adapter
*adapter
)
432 if (adapter
->ahw
.pci_base0
!= NULL
)
433 iounmap(adapter
->ahw
.pci_base0
);
437 qlcnic_init_pci_info(struct qlcnic_adapter
*adapter
)
439 struct qlcnic_pci_info
*pci_info
;
443 pci_info
= kcalloc(QLCNIC_MAX_PCI_FUNC
, sizeof(*pci_info
), GFP_KERNEL
);
447 adapter
->npars
= kzalloc(sizeof(struct qlcnic_npar_info
) *
448 QLCNIC_MAX_PCI_FUNC
, GFP_KERNEL
);
449 if (!adapter
->npars
) {
454 adapter
->eswitch
= kzalloc(sizeof(struct qlcnic_eswitch
) *
455 QLCNIC_NIU_MAX_XG_PORTS
, GFP_KERNEL
);
456 if (!adapter
->eswitch
) {
461 ret
= qlcnic_get_pci_info(adapter
, pci_info
);
465 for (i
= 0; i
< QLCNIC_MAX_PCI_FUNC
; i
++) {
466 pfn
= pci_info
[i
].id
;
467 if (pfn
> QLCNIC_MAX_PCI_FUNC
)
468 return QL_STATUS_INVALID_PARAM
;
469 adapter
->npars
[pfn
].active
= (u8
)pci_info
[i
].active
;
470 adapter
->npars
[pfn
].type
= (u8
)pci_info
[i
].type
;
471 adapter
->npars
[pfn
].phy_port
= (u8
)pci_info
[i
].default_port
;
472 adapter
->npars
[pfn
].min_bw
= pci_info
[i
].tx_min_bw
;
473 adapter
->npars
[pfn
].max_bw
= pci_info
[i
].tx_max_bw
;
476 for (i
= 0; i
< QLCNIC_NIU_MAX_XG_PORTS
; i
++)
477 adapter
->eswitch
[i
].flags
|= QLCNIC_SWITCH_ENABLE
;
483 kfree(adapter
->eswitch
);
484 adapter
->eswitch
= NULL
;
486 kfree(adapter
->npars
);
487 adapter
->npars
= NULL
;
495 qlcnic_set_function_modes(struct qlcnic_adapter
*adapter
)
500 u32 data
= QLCNIC_MGMT_FUNC
;
501 void __iomem
*priv_op
= adapter
->ahw
.pci_base0
+ QLCNIC_DRV_OP_MODE
;
503 /* If other drivers are not in use set their privilege level */
504 ref_count
= QLCRD32(adapter
, QLCNIC_CRB_DRV_ACTIVE
);
505 ret
= qlcnic_api_lock(adapter
);
509 if (qlcnic_config_npars
) {
510 for (i
= 0; i
< QLCNIC_MAX_PCI_FUNC
; i
++) {
512 if (adapter
->npars
[i
].type
!= QLCNIC_TYPE_NIC
||
513 id
== adapter
->ahw
.pci_func
)
515 data
|= (qlcnic_config_npars
&
516 QLC_DEV_SET_DRV(0xf, id
));
519 data
= readl(priv_op
);
520 data
= (data
& ~QLC_DEV_SET_DRV(0xf, adapter
->ahw
.pci_func
)) |
521 (QLC_DEV_SET_DRV(QLCNIC_MGMT_FUNC
,
522 adapter
->ahw
.pci_func
));
524 writel(data
, priv_op
);
525 qlcnic_api_unlock(adapter
);
531 qlcnic_check_vf(struct qlcnic_adapter
*adapter
)
533 void __iomem
*msix_base_addr
;
534 void __iomem
*priv_op
;
537 u32 op_mode
, priv_level
;
539 /* Determine FW API version */
540 adapter
->fw_hal_version
= readl(adapter
->ahw
.pci_base0
+ QLCNIC_FW_API
);
542 /* Find PCI function number */
543 pci_read_config_dword(adapter
->pdev
, QLCNIC_MSIX_TABLE_OFFSET
, &func
);
544 msix_base_addr
= adapter
->ahw
.pci_base0
+ QLCNIC_MSIX_BASE
;
545 msix_base
= readl(msix_base_addr
);
546 func
= (func
- msix_base
)/QLCNIC_MSIX_TBL_PGSIZE
;
547 adapter
->ahw
.pci_func
= func
;
549 /* Determine function privilege level */
550 priv_op
= adapter
->ahw
.pci_base0
+ QLCNIC_DRV_OP_MODE
;
551 op_mode
= readl(priv_op
);
552 if (op_mode
== QLC_DEV_DRV_DEFAULT
)
553 priv_level
= QLCNIC_MGMT_FUNC
;
555 priv_level
= QLC_DEV_GET_DRV(op_mode
, adapter
->ahw
.pci_func
);
557 if (priv_level
== QLCNIC_NON_PRIV_FUNC
) {
558 adapter
->op_mode
= QLCNIC_NON_PRIV_FUNC
;
559 dev_info(&adapter
->pdev
->dev
,
560 "HAL Version: %d Non Privileged function\n",
561 adapter
->fw_hal_version
);
562 adapter
->nic_ops
= &qlcnic_vf_ops
;
564 adapter
->nic_ops
= &qlcnic_ops
;
568 qlcnic_setup_pci_map(struct qlcnic_adapter
*adapter
)
570 void __iomem
*mem_ptr0
= NULL
;
571 resource_size_t mem_base
;
572 unsigned long mem_len
, pci_len0
= 0;
574 struct pci_dev
*pdev
= adapter
->pdev
;
576 /* remap phys address */
577 mem_base
= pci_resource_start(pdev
, 0); /* 0 is for BAR 0 */
578 mem_len
= pci_resource_len(pdev
, 0);
580 if (mem_len
== QLCNIC_PCI_2MB_SIZE
) {
582 mem_ptr0
= pci_ioremap_bar(pdev
, 0);
583 if (mem_ptr0
== NULL
) {
584 dev_err(&pdev
->dev
, "failed to map PCI bar 0\n");
592 dev_info(&pdev
->dev
, "%dMB memory map\n", (int)(mem_len
>>20));
594 adapter
->ahw
.pci_base0
= mem_ptr0
;
595 adapter
->ahw
.pci_len0
= pci_len0
;
597 qlcnic_check_vf(adapter
);
599 adapter
->ahw
.ocm_win_crb
= qlcnic_get_ioaddr(adapter
,
600 QLCNIC_PCIX_PS_REG(PCIX_OCM_WINDOW_REG(adapter
->ahw
.pci_func
)));
605 static void get_brd_name(struct qlcnic_adapter
*adapter
, char *name
)
607 struct pci_dev
*pdev
= adapter
->pdev
;
610 for (i
= 0; i
< NUM_SUPPORTED_BOARDS
; ++i
) {
611 if (qlcnic_boards
[i
].vendor
== pdev
->vendor
&&
612 qlcnic_boards
[i
].device
== pdev
->device
&&
613 qlcnic_boards
[i
].sub_vendor
== pdev
->subsystem_vendor
&&
614 qlcnic_boards
[i
].sub_device
== pdev
->subsystem_device
) {
615 sprintf(name
, "%pM: %s" ,
617 qlcnic_boards
[i
].short_name
);
625 sprintf(name
, "%pM Gigabit Ethernet", adapter
->mac_addr
);
629 qlcnic_check_options(struct qlcnic_adapter
*adapter
)
631 u32 fw_major
, fw_minor
, fw_build
;
632 struct pci_dev
*pdev
= adapter
->pdev
;
634 fw_major
= QLCRD32(adapter
, QLCNIC_FW_VERSION_MAJOR
);
635 fw_minor
= QLCRD32(adapter
, QLCNIC_FW_VERSION_MINOR
);
636 fw_build
= QLCRD32(adapter
, QLCNIC_FW_VERSION_SUB
);
638 adapter
->fw_version
= QLCNIC_VERSION_CODE(fw_major
, fw_minor
, fw_build
);
640 dev_info(&pdev
->dev
, "firmware v%d.%d.%d\n",
641 fw_major
, fw_minor
, fw_build
);
642 if (adapter
->ahw
.port_type
== QLCNIC_XGBE
) {
643 if (adapter
->flags
& QLCNIC_ESWITCH_ENABLED
) {
644 adapter
->num_rxd
= DEFAULT_RCV_DESCRIPTORS_VF
;
645 adapter
->max_rxd
= MAX_RCV_DESCRIPTORS_VF
;
647 adapter
->num_rxd
= DEFAULT_RCV_DESCRIPTORS_10G
;
648 adapter
->max_rxd
= MAX_RCV_DESCRIPTORS_10G
;
651 adapter
->num_jumbo_rxd
= MAX_JUMBO_RCV_DESCRIPTORS_10G
;
652 adapter
->max_jumbo_rxd
= MAX_JUMBO_RCV_DESCRIPTORS_10G
;
654 } else if (adapter
->ahw
.port_type
== QLCNIC_GBE
) {
655 adapter
->num_rxd
= DEFAULT_RCV_DESCRIPTORS_1G
;
656 adapter
->num_jumbo_rxd
= MAX_JUMBO_RCV_DESCRIPTORS_1G
;
657 adapter
->max_jumbo_rxd
= MAX_JUMBO_RCV_DESCRIPTORS_1G
;
658 adapter
->max_rxd
= MAX_RCV_DESCRIPTORS_1G
;
661 adapter
->msix_supported
= !!use_msi_x
;
662 adapter
->rss_supported
= !!use_msi_x
;
664 adapter
->num_txd
= MAX_CMD_DESCRIPTORS
;
666 adapter
->max_rds_rings
= MAX_RDS_RINGS
;
670 qlcnic_initialize_nic(struct qlcnic_adapter
*adapter
)
673 struct qlcnic_info nic_info
;
675 err
= qlcnic_get_nic_info(adapter
, &nic_info
, adapter
->ahw
.pci_func
);
679 adapter
->physical_port
= (u8
)nic_info
.phys_port
;
680 adapter
->switch_mode
= nic_info
.switch_mode
;
681 adapter
->max_tx_ques
= nic_info
.max_tx_ques
;
682 adapter
->max_rx_ques
= nic_info
.max_rx_ques
;
683 adapter
->capabilities
= nic_info
.capabilities
;
684 adapter
->max_mac_filters
= nic_info
.max_mac_filters
;
685 adapter
->max_mtu
= nic_info
.max_mtu
;
687 if (adapter
->capabilities
& BIT_6
)
688 adapter
->flags
|= QLCNIC_ESWITCH_ENABLED
;
690 adapter
->flags
&= ~QLCNIC_ESWITCH_ENABLED
;
696 qlcnic_set_vlan_config(struct qlcnic_adapter
*adapter
,
697 struct qlcnic_esw_func_cfg
*esw_cfg
)
699 if (esw_cfg
->discard_tagged
)
700 adapter
->flags
&= ~QLCNIC_TAGGING_ENABLED
;
702 adapter
->flags
|= QLCNIC_TAGGING_ENABLED
;
704 if (esw_cfg
->vlan_id
)
705 adapter
->pvid
= esw_cfg
->vlan_id
;
711 qlcnic_set_eswitch_port_features(struct qlcnic_adapter
*adapter
,
712 struct qlcnic_esw_func_cfg
*esw_cfg
)
714 adapter
->flags
&= ~(QLCNIC_MACSPOOF
| QLCNIC_MAC_OVERRIDE_DISABLED
|
715 QLCNIC_PROMISC_DISABLED
);
717 if (esw_cfg
->mac_anti_spoof
)
718 adapter
->flags
|= QLCNIC_MACSPOOF
;
720 if (!esw_cfg
->mac_override
)
721 adapter
->flags
|= QLCNIC_MAC_OVERRIDE_DISABLED
;
723 if (!esw_cfg
->promisc_mode
)
724 adapter
->flags
|= QLCNIC_PROMISC_DISABLED
;
726 qlcnic_set_netdev_features(adapter
, esw_cfg
);
730 qlcnic_set_eswitch_port_config(struct qlcnic_adapter
*adapter
)
732 struct qlcnic_esw_func_cfg esw_cfg
;
734 if (!(adapter
->flags
& QLCNIC_ESWITCH_ENABLED
))
737 esw_cfg
.pci_func
= adapter
->ahw
.pci_func
;
738 if (qlcnic_get_eswitch_port_config(adapter
, &esw_cfg
))
740 qlcnic_set_vlan_config(adapter
, &esw_cfg
);
741 qlcnic_set_eswitch_port_features(adapter
, &esw_cfg
);
747 qlcnic_set_netdev_features(struct qlcnic_adapter
*adapter
,
748 struct qlcnic_esw_func_cfg
*esw_cfg
)
750 struct net_device
*netdev
= adapter
->netdev
;
751 unsigned long features
, vlan_features
;
753 features
= (NETIF_F_SG
| NETIF_F_IP_CSUM
|
754 NETIF_F_IPV6_CSUM
| NETIF_F_GRO
);
755 vlan_features
= (NETIF_F_SG
| NETIF_F_IP_CSUM
|
758 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_TSO
) {
759 features
|= (NETIF_F_TSO
| NETIF_F_TSO6
);
760 vlan_features
|= (NETIF_F_TSO
| NETIF_F_TSO6
);
762 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_HW_LRO
)
763 features
|= NETIF_F_LRO
;
765 if (esw_cfg
->offload_flags
& BIT_0
) {
766 netdev
->features
|= features
;
767 adapter
->rx_csum
= 1;
768 if (!(esw_cfg
->offload_flags
& BIT_1
))
769 netdev
->features
&= ~NETIF_F_TSO
;
770 if (!(esw_cfg
->offload_flags
& BIT_2
))
771 netdev
->features
&= ~NETIF_F_TSO6
;
773 netdev
->features
&= ~features
;
774 adapter
->rx_csum
= 0;
777 netdev
->vlan_features
= (features
& vlan_features
);
781 qlcnic_check_eswitch_mode(struct qlcnic_adapter
*adapter
)
783 void __iomem
*priv_op
;
784 u32 op_mode
, priv_level
;
787 err
= qlcnic_initialize_nic(adapter
);
791 if (adapter
->flags
& QLCNIC_ADAPTER_INITIALIZED
)
794 priv_op
= adapter
->ahw
.pci_base0
+ QLCNIC_DRV_OP_MODE
;
795 op_mode
= readl(priv_op
);
796 priv_level
= QLC_DEV_GET_DRV(op_mode
, adapter
->ahw
.pci_func
);
798 if (op_mode
== QLC_DEV_DRV_DEFAULT
)
799 priv_level
= QLCNIC_MGMT_FUNC
;
801 priv_level
= QLC_DEV_GET_DRV(op_mode
, adapter
->ahw
.pci_func
);
803 if (adapter
->flags
& QLCNIC_ESWITCH_ENABLED
) {
804 if (priv_level
== QLCNIC_MGMT_FUNC
) {
805 adapter
->op_mode
= QLCNIC_MGMT_FUNC
;
806 err
= qlcnic_init_pci_info(adapter
);
809 /* Set privilege level for other functions */
810 qlcnic_set_function_modes(adapter
);
811 dev_info(&adapter
->pdev
->dev
,
812 "HAL Version: %d, Management function\n",
813 adapter
->fw_hal_version
);
814 } else if (priv_level
== QLCNIC_PRIV_FUNC
) {
815 adapter
->op_mode
= QLCNIC_PRIV_FUNC
;
816 dev_info(&adapter
->pdev
->dev
,
817 "HAL Version: %d, Privileged function\n",
818 adapter
->fw_hal_version
);
822 adapter
->flags
|= QLCNIC_ADAPTER_INITIALIZED
;
828 qlcnic_set_default_offload_settings(struct qlcnic_adapter
*adapter
)
830 struct qlcnic_esw_func_cfg esw_cfg
;
831 struct qlcnic_npar_info
*npar
;
834 if (adapter
->need_fw_reset
)
837 for (i
= 0; i
< QLCNIC_MAX_PCI_FUNC
; i
++) {
838 if (adapter
->npars
[i
].type
!= QLCNIC_TYPE_NIC
)
840 memset(&esw_cfg
, 0, sizeof(struct qlcnic_esw_func_cfg
));
841 esw_cfg
.pci_func
= i
;
842 esw_cfg
.offload_flags
= BIT_0
;
843 esw_cfg
.mac_override
= BIT_0
;
844 esw_cfg
.promisc_mode
= BIT_0
;
845 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_TSO
)
846 esw_cfg
.offload_flags
|= (BIT_1
| BIT_2
);
847 if (qlcnic_config_switch_port(adapter
, &esw_cfg
))
849 npar
= &adapter
->npars
[i
];
850 npar
->pvid
= esw_cfg
.vlan_id
;
851 npar
->mac_override
= esw_cfg
.mac_override
;
852 npar
->mac_anti_spoof
= esw_cfg
.mac_anti_spoof
;
853 npar
->discard_tagged
= esw_cfg
.discard_tagged
;
854 npar
->promisc_mode
= esw_cfg
.promisc_mode
;
855 npar
->offload_flags
= esw_cfg
.offload_flags
;
862 qlcnic_reset_eswitch_config(struct qlcnic_adapter
*adapter
,
863 struct qlcnic_npar_info
*npar
, int pci_func
)
865 struct qlcnic_esw_func_cfg esw_cfg
;
866 esw_cfg
.op_mode
= QLCNIC_PORT_DEFAULTS
;
867 esw_cfg
.pci_func
= pci_func
;
868 esw_cfg
.vlan_id
= npar
->pvid
;
869 esw_cfg
.mac_override
= npar
->mac_override
;
870 esw_cfg
.discard_tagged
= npar
->discard_tagged
;
871 esw_cfg
.mac_anti_spoof
= npar
->mac_anti_spoof
;
872 esw_cfg
.offload_flags
= npar
->offload_flags
;
873 esw_cfg
.promisc_mode
= npar
->promisc_mode
;
874 if (qlcnic_config_switch_port(adapter
, &esw_cfg
))
877 esw_cfg
.op_mode
= QLCNIC_ADD_VLAN
;
878 if (qlcnic_config_switch_port(adapter
, &esw_cfg
))
885 qlcnic_reset_npar_config(struct qlcnic_adapter
*adapter
)
888 struct qlcnic_npar_info
*npar
;
889 struct qlcnic_info nic_info
;
891 if (!adapter
->need_fw_reset
)
894 /* Set the NPAR config data after FW reset */
895 for (i
= 0; i
< QLCNIC_MAX_PCI_FUNC
; i
++) {
896 npar
= &adapter
->npars
[i
];
897 if (npar
->type
!= QLCNIC_TYPE_NIC
)
899 err
= qlcnic_get_nic_info(adapter
, &nic_info
, i
);
902 nic_info
.min_tx_bw
= npar
->min_bw
;
903 nic_info
.max_tx_bw
= npar
->max_bw
;
904 err
= qlcnic_set_nic_info(adapter
, &nic_info
);
908 if (npar
->enable_pm
) {
909 err
= qlcnic_config_port_mirroring(adapter
,
910 npar
->dest_npar
, 1, i
);
914 err
= qlcnic_reset_eswitch_config(adapter
, npar
, i
);
921 static int qlcnic_check_npar_opertional(struct qlcnic_adapter
*adapter
)
923 u8 npar_opt_timeo
= QLCNIC_DEV_NPAR_OPER_TIMEO
;
926 if (adapter
->op_mode
== QLCNIC_MGMT_FUNC
)
929 npar_state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_NPAR_STATE
);
930 while (npar_state
!= QLCNIC_DEV_NPAR_OPER
&& --npar_opt_timeo
) {
932 npar_state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_NPAR_STATE
);
934 if (!npar_opt_timeo
) {
935 dev_err(&adapter
->pdev
->dev
,
936 "Waiting for NPAR state to opertional timeout\n");
943 qlcnic_set_mgmt_operations(struct qlcnic_adapter
*adapter
)
947 if (!(adapter
->flags
& QLCNIC_ESWITCH_ENABLED
) ||
948 adapter
->op_mode
!= QLCNIC_MGMT_FUNC
)
951 err
= qlcnic_set_default_offload_settings(adapter
);
955 err
= qlcnic_reset_npar_config(adapter
);
959 qlcnic_dev_set_npar_ready(adapter
);
965 qlcnic_start_firmware(struct qlcnic_adapter
*adapter
)
969 err
= qlcnic_can_start_firmware(adapter
);
973 goto check_fw_status
;
976 qlcnic_request_firmware(adapter
);
978 err
= qlcnic_check_flash_fw_ver(adapter
);
982 adapter
->fw_type
= QLCNIC_FLASH_ROMIMAGE
;
985 err
= qlcnic_need_fw_reset(adapter
);
987 goto check_fw_status
;
989 err
= qlcnic_pinit_from_rom(adapter
);
993 err
= qlcnic_load_firmware(adapter
);
997 qlcnic_release_firmware(adapter
);
998 QLCWR32(adapter
, CRB_DRIVER_VERSION
, QLCNIC_DRIVER_VERSION
);
1001 err
= qlcnic_check_fw_status(adapter
);
1005 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
, QLCNIC_DEV_READY
);
1006 qlcnic_idc_debug_info(adapter
, 1);
1008 err
= qlcnic_check_eswitch_mode(adapter
);
1010 dev_err(&adapter
->pdev
->dev
,
1011 "Memory allocation failed for eswitch\n");
1014 err
= qlcnic_set_mgmt_operations(adapter
);
1018 qlcnic_check_options(adapter
);
1019 adapter
->need_fw_reset
= 0;
1021 qlcnic_release_firmware(adapter
);
1025 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
, QLCNIC_DEV_FAILED
);
1026 dev_err(&adapter
->pdev
->dev
, "Device state set to failed\n");
1028 qlcnic_release_firmware(adapter
);
1033 qlcnic_request_irq(struct qlcnic_adapter
*adapter
)
1035 irq_handler_t handler
;
1036 struct qlcnic_host_sds_ring
*sds_ring
;
1039 unsigned long flags
= 0;
1040 struct net_device
*netdev
= adapter
->netdev
;
1041 struct qlcnic_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
1043 if (adapter
->diag_test
== QLCNIC_INTERRUPT_TEST
) {
1044 handler
= qlcnic_tmp_intr
;
1045 if (!QLCNIC_IS_MSI_FAMILY(adapter
))
1046 flags
|= IRQF_SHARED
;
1049 if (adapter
->flags
& QLCNIC_MSIX_ENABLED
)
1050 handler
= qlcnic_msix_intr
;
1051 else if (adapter
->flags
& QLCNIC_MSI_ENABLED
)
1052 handler
= qlcnic_msi_intr
;
1054 flags
|= IRQF_SHARED
;
1055 handler
= qlcnic_intr
;
1058 adapter
->irq
= netdev
->irq
;
1060 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
1061 sds_ring
= &recv_ctx
->sds_rings
[ring
];
1062 sprintf(sds_ring
->name
, "%s[%d]", netdev
->name
, ring
);
1063 err
= request_irq(sds_ring
->irq
, handler
,
1064 flags
, sds_ring
->name
, sds_ring
);
1073 qlcnic_free_irq(struct qlcnic_adapter
*adapter
)
1076 struct qlcnic_host_sds_ring
*sds_ring
;
1078 struct qlcnic_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
1080 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
1081 sds_ring
= &recv_ctx
->sds_rings
[ring
];
1082 free_irq(sds_ring
->irq
, sds_ring
);
1087 qlcnic_init_coalesce_defaults(struct qlcnic_adapter
*adapter
)
1089 adapter
->coal
.flags
= QLCNIC_INTR_DEFAULT
;
1090 adapter
->coal
.normal
.data
.rx_time_us
=
1091 QLCNIC_DEFAULT_INTR_COALESCE_RX_TIME_US
;
1092 adapter
->coal
.normal
.data
.rx_packets
=
1093 QLCNIC_DEFAULT_INTR_COALESCE_RX_PACKETS
;
1094 adapter
->coal
.normal
.data
.tx_time_us
=
1095 QLCNIC_DEFAULT_INTR_COALESCE_TX_TIME_US
;
1096 adapter
->coal
.normal
.data
.tx_packets
=
1097 QLCNIC_DEFAULT_INTR_COALESCE_TX_PACKETS
;
1101 __qlcnic_up(struct qlcnic_adapter
*adapter
, struct net_device
*netdev
)
1104 struct qlcnic_host_rds_ring
*rds_ring
;
1106 if (adapter
->is_up
!= QLCNIC_ADAPTER_UP_MAGIC
)
1109 if (test_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
1111 if (qlcnic_set_eswitch_port_config(adapter
))
1114 if (qlcnic_fw_create_ctx(adapter
))
1117 for (ring
= 0; ring
< adapter
->max_rds_rings
; ring
++) {
1118 rds_ring
= &adapter
->recv_ctx
.rds_rings
[ring
];
1119 qlcnic_post_rx_buffers(adapter
, ring
, rds_ring
);
1122 qlcnic_set_multi(netdev
);
1123 qlcnic_fw_cmd_set_mtu(adapter
, netdev
->mtu
);
1125 adapter
->ahw
.linkup
= 0;
1127 if (adapter
->max_sds_rings
> 1)
1128 qlcnic_config_rss(adapter
, 1);
1130 qlcnic_config_intr_coalesce(adapter
);
1132 if (netdev
->features
& NETIF_F_LRO
)
1133 qlcnic_config_hw_lro(adapter
, QLCNIC_LRO_ENABLED
);
1135 qlcnic_napi_enable(adapter
);
1137 qlcnic_linkevent_request(adapter
, 1);
1139 adapter
->reset_context
= 0;
1140 set_bit(__QLCNIC_DEV_UP
, &adapter
->state
);
1144 /* Usage: During resume and firmware recovery module.*/
1147 qlcnic_up(struct qlcnic_adapter
*adapter
, struct net_device
*netdev
)
1152 if (netif_running(netdev
))
1153 err
= __qlcnic_up(adapter
, netdev
);
1160 __qlcnic_down(struct qlcnic_adapter
*adapter
, struct net_device
*netdev
)
1162 if (adapter
->is_up
!= QLCNIC_ADAPTER_UP_MAGIC
)
1165 if (!test_and_clear_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
1169 spin_lock(&adapter
->tx_clean_lock
);
1170 netif_carrier_off(netdev
);
1171 netif_tx_disable(netdev
);
1173 qlcnic_free_mac_list(adapter
);
1175 if (adapter
->fhash
.fnum
)
1176 qlcnic_delete_lb_filters(adapter
);
1178 qlcnic_nic_set_promisc(adapter
, QLCNIC_NIU_NON_PROMISC_MODE
);
1180 qlcnic_napi_disable(adapter
);
1182 qlcnic_fw_destroy_ctx(adapter
);
1184 qlcnic_reset_rx_buffers_list(adapter
);
1185 qlcnic_release_tx_buffers(adapter
);
1186 spin_unlock(&adapter
->tx_clean_lock
);
1189 /* Usage: During suspend and firmware recovery module */
1192 qlcnic_down(struct qlcnic_adapter
*adapter
, struct net_device
*netdev
)
1195 if (netif_running(netdev
))
1196 __qlcnic_down(adapter
, netdev
);
1202 qlcnic_attach(struct qlcnic_adapter
*adapter
)
1204 struct net_device
*netdev
= adapter
->netdev
;
1205 struct pci_dev
*pdev
= adapter
->pdev
;
1208 if (adapter
->is_up
== QLCNIC_ADAPTER_UP_MAGIC
)
1211 err
= qlcnic_napi_add(adapter
, netdev
);
1215 err
= qlcnic_alloc_sw_resources(adapter
);
1217 dev_err(&pdev
->dev
, "Error in setting sw resources\n");
1218 goto err_out_napi_del
;
1221 err
= qlcnic_alloc_hw_resources(adapter
);
1223 dev_err(&pdev
->dev
, "Error in setting hw resources\n");
1224 goto err_out_free_sw
;
1227 err
= qlcnic_request_irq(adapter
);
1229 dev_err(&pdev
->dev
, "failed to setup interrupt\n");
1230 goto err_out_free_hw
;
1233 qlcnic_init_coalesce_defaults(adapter
);
1235 qlcnic_create_sysfs_entries(adapter
);
1237 adapter
->is_up
= QLCNIC_ADAPTER_UP_MAGIC
;
1241 qlcnic_free_hw_resources(adapter
);
1243 qlcnic_free_sw_resources(adapter
);
1245 qlcnic_napi_del(adapter
);
1250 qlcnic_detach(struct qlcnic_adapter
*adapter
)
1252 if (adapter
->is_up
!= QLCNIC_ADAPTER_UP_MAGIC
)
1255 qlcnic_remove_sysfs_entries(adapter
);
1257 qlcnic_free_hw_resources(adapter
);
1258 qlcnic_release_rx_buffers(adapter
);
1259 qlcnic_free_irq(adapter
);
1260 qlcnic_napi_del(adapter
);
1261 qlcnic_free_sw_resources(adapter
);
1266 void qlcnic_diag_free_res(struct net_device
*netdev
, int max_sds_rings
)
1268 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
1269 struct qlcnic_host_sds_ring
*sds_ring
;
1272 clear_bit(__QLCNIC_DEV_UP
, &adapter
->state
);
1273 if (adapter
->diag_test
== QLCNIC_INTERRUPT_TEST
) {
1274 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
1275 sds_ring
= &adapter
->recv_ctx
.sds_rings
[ring
];
1276 qlcnic_disable_int(sds_ring
);
1280 qlcnic_fw_destroy_ctx(adapter
);
1282 qlcnic_detach(adapter
);
1284 adapter
->diag_test
= 0;
1285 adapter
->max_sds_rings
= max_sds_rings
;
1287 if (qlcnic_attach(adapter
))
1290 if (netif_running(netdev
))
1291 __qlcnic_up(adapter
, netdev
);
1293 netif_device_attach(netdev
);
1296 int qlcnic_diag_alloc_res(struct net_device
*netdev
, int test
)
1298 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
1299 struct qlcnic_host_sds_ring
*sds_ring
;
1300 struct qlcnic_host_rds_ring
*rds_ring
;
1304 netif_device_detach(netdev
);
1306 if (netif_running(netdev
))
1307 __qlcnic_down(adapter
, netdev
);
1309 qlcnic_detach(adapter
);
1311 adapter
->max_sds_rings
= 1;
1312 adapter
->diag_test
= test
;
1314 ret
= qlcnic_attach(adapter
);
1316 netif_device_attach(netdev
);
1320 ret
= qlcnic_fw_create_ctx(adapter
);
1322 qlcnic_detach(adapter
);
1323 netif_device_attach(netdev
);
1327 for (ring
= 0; ring
< adapter
->max_rds_rings
; ring
++) {
1328 rds_ring
= &adapter
->recv_ctx
.rds_rings
[ring
];
1329 qlcnic_post_rx_buffers(adapter
, ring
, rds_ring
);
1332 if (adapter
->diag_test
== QLCNIC_INTERRUPT_TEST
) {
1333 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
1334 sds_ring
= &adapter
->recv_ctx
.sds_rings
[ring
];
1335 qlcnic_enable_int(sds_ring
);
1338 set_bit(__QLCNIC_DEV_UP
, &adapter
->state
);
1343 /* Reset context in hardware only */
1345 qlcnic_reset_hw_context(struct qlcnic_adapter
*adapter
)
1347 struct net_device
*netdev
= adapter
->netdev
;
1349 if (test_and_set_bit(__QLCNIC_RESETTING
, &adapter
->state
))
1352 netif_device_detach(netdev
);
1354 qlcnic_down(adapter
, netdev
);
1356 qlcnic_up(adapter
, netdev
);
1358 netif_device_attach(netdev
);
1360 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
1365 qlcnic_reset_context(struct qlcnic_adapter
*adapter
)
1368 struct net_device
*netdev
= adapter
->netdev
;
1370 if (test_and_set_bit(__QLCNIC_RESETTING
, &adapter
->state
))
1373 if (adapter
->is_up
== QLCNIC_ADAPTER_UP_MAGIC
) {
1375 netif_device_detach(netdev
);
1377 if (netif_running(netdev
))
1378 __qlcnic_down(adapter
, netdev
);
1380 qlcnic_detach(adapter
);
1382 if (netif_running(netdev
)) {
1383 err
= qlcnic_attach(adapter
);
1385 __qlcnic_up(adapter
, netdev
);
1388 netif_device_attach(netdev
);
1391 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
1396 qlcnic_setup_netdev(struct qlcnic_adapter
*adapter
,
1397 struct net_device
*netdev
, u8 pci_using_dac
)
1400 struct pci_dev
*pdev
= adapter
->pdev
;
1402 adapter
->rx_csum
= 1;
1403 adapter
->mc_enabled
= 0;
1404 adapter
->max_mc_count
= 38;
1406 netdev
->netdev_ops
= &qlcnic_netdev_ops
;
1407 netdev
->watchdog_timeo
= 5*HZ
;
1409 qlcnic_change_mtu(netdev
, netdev
->mtu
);
1411 SET_ETHTOOL_OPS(netdev
, &qlcnic_ethtool_ops
);
1413 netdev
->features
|= (NETIF_F_SG
| NETIF_F_IP_CSUM
|
1414 NETIF_F_IPV6_CSUM
| NETIF_F_GRO
| NETIF_F_HW_VLAN_RX
);
1415 netdev
->vlan_features
|= (NETIF_F_SG
| NETIF_F_IP_CSUM
|
1418 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_TSO
) {
1419 netdev
->features
|= (NETIF_F_TSO
| NETIF_F_TSO6
);
1420 netdev
->vlan_features
|= (NETIF_F_TSO
| NETIF_F_TSO6
);
1423 if (pci_using_dac
) {
1424 netdev
->features
|= NETIF_F_HIGHDMA
;
1425 netdev
->vlan_features
|= NETIF_F_HIGHDMA
;
1428 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_FVLANTX
)
1429 netdev
->features
|= (NETIF_F_HW_VLAN_TX
);
1431 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_HW_LRO
)
1432 netdev
->features
|= NETIF_F_LRO
;
1433 netdev
->irq
= adapter
->msix_entries
[0].vector
;
1435 netif_carrier_off(netdev
);
1437 err
= register_netdev(netdev
);
1439 dev_err(&pdev
->dev
, "failed to register net device\n");
1446 static int qlcnic_set_dma_mask(struct pci_dev
*pdev
, u8
*pci_using_dac
)
1448 if (!pci_set_dma_mask(pdev
, DMA_BIT_MASK(64)) &&
1449 !pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(64)))
1451 else if (!pci_set_dma_mask(pdev
, DMA_BIT_MASK(32)) &&
1452 !pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(32)))
1455 dev_err(&pdev
->dev
, "Unable to set DMA mask, aborting\n");
1462 static int __devinit
1463 qlcnic_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
1465 struct net_device
*netdev
= NULL
;
1466 struct qlcnic_adapter
*adapter
= NULL
;
1468 uint8_t revision_id
;
1469 uint8_t pci_using_dac
;
1470 char brd_name
[QLCNIC_MAX_BOARD_NAME_LEN
];
1472 err
= pci_enable_device(pdev
);
1476 if (!(pci_resource_flags(pdev
, 0) & IORESOURCE_MEM
)) {
1478 goto err_out_disable_pdev
;
1481 err
= qlcnic_set_dma_mask(pdev
, &pci_using_dac
);
1483 goto err_out_disable_pdev
;
1485 err
= pci_request_regions(pdev
, qlcnic_driver_name
);
1487 goto err_out_disable_pdev
;
1489 pci_set_master(pdev
);
1490 pci_enable_pcie_error_reporting(pdev
);
1492 netdev
= alloc_etherdev(sizeof(struct qlcnic_adapter
));
1494 dev_err(&pdev
->dev
, "failed to allocate net_device\n");
1496 goto err_out_free_res
;
1499 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
1501 adapter
= netdev_priv(netdev
);
1502 adapter
->netdev
= netdev
;
1503 adapter
->pdev
= pdev
;
1504 adapter
->dev_rst_time
= jiffies
;
1506 revision_id
= pdev
->revision
;
1507 adapter
->ahw
.revision_id
= revision_id
;
1509 rwlock_init(&adapter
->ahw
.crb_lock
);
1510 mutex_init(&adapter
->ahw
.mem_lock
);
1512 spin_lock_init(&adapter
->tx_clean_lock
);
1513 INIT_LIST_HEAD(&adapter
->mac_list
);
1515 err
= qlcnic_setup_pci_map(adapter
);
1517 goto err_out_free_netdev
;
1519 /* This will be reset for mezz cards */
1520 adapter
->portnum
= adapter
->ahw
.pci_func
;
1522 err
= qlcnic_get_board_info(adapter
);
1524 dev_err(&pdev
->dev
, "Error getting board config info.\n");
1525 goto err_out_iounmap
;
1528 err
= qlcnic_setup_idc_param(adapter
);
1530 goto err_out_iounmap
;
1532 adapter
->flags
|= QLCNIC_NEED_FLR
;
1534 err
= adapter
->nic_ops
->start_firmware(adapter
);
1536 dev_err(&pdev
->dev
, "Loading fw failed.Please Reboot\n");
1537 goto err_out_decr_ref
;
1540 if (qlcnic_read_mac_addr(adapter
))
1541 dev_warn(&pdev
->dev
, "failed to read mac addr\n");
1543 if (adapter
->portnum
== 0) {
1544 get_brd_name(adapter
, brd_name
);
1546 pr_info("%s: %s Board Chip rev 0x%x\n",
1547 module_name(THIS_MODULE
),
1548 brd_name
, adapter
->ahw
.revision_id
);
1551 qlcnic_clear_stats(adapter
);
1553 qlcnic_setup_intr(adapter
);
1555 err
= qlcnic_setup_netdev(adapter
, netdev
, pci_using_dac
);
1557 goto err_out_disable_msi
;
1559 pci_set_drvdata(pdev
, adapter
);
1561 qlcnic_schedule_work(adapter
, qlcnic_fw_poll_work
, FW_POLL_DELAY
);
1563 switch (adapter
->ahw
.port_type
) {
1565 dev_info(&adapter
->pdev
->dev
, "%s: GbE port initialized\n",
1566 adapter
->netdev
->name
);
1569 dev_info(&adapter
->pdev
->dev
, "%s: XGbE port initialized\n",
1570 adapter
->netdev
->name
);
1574 qlcnic_alloc_lb_filters_mem(adapter
);
1575 qlcnic_create_diag_entries(adapter
);
1579 err_out_disable_msi
:
1580 qlcnic_teardown_intr(adapter
);
1583 qlcnic_clr_all_drv_state(adapter
, 0);
1586 qlcnic_cleanup_pci_map(adapter
);
1588 err_out_free_netdev
:
1589 free_netdev(netdev
);
1592 pci_release_regions(pdev
);
1594 err_out_disable_pdev
:
1595 pci_set_drvdata(pdev
, NULL
);
1596 pci_disable_device(pdev
);
1600 static void __devexit
qlcnic_remove(struct pci_dev
*pdev
)
1602 struct qlcnic_adapter
*adapter
;
1603 struct net_device
*netdev
;
1605 adapter
= pci_get_drvdata(pdev
);
1606 if (adapter
== NULL
)
1609 netdev
= adapter
->netdev
;
1611 qlcnic_cancel_fw_work(adapter
);
1613 unregister_netdev(netdev
);
1615 qlcnic_detach(adapter
);
1617 if (adapter
->npars
!= NULL
)
1618 kfree(adapter
->npars
);
1619 if (adapter
->eswitch
!= NULL
)
1620 kfree(adapter
->eswitch
);
1622 qlcnic_clr_all_drv_state(adapter
, 0);
1624 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
1626 qlcnic_free_lb_filters_mem(adapter
);
1628 qlcnic_teardown_intr(adapter
);
1630 qlcnic_remove_diag_entries(adapter
);
1632 qlcnic_cleanup_pci_map(adapter
);
1634 qlcnic_release_firmware(adapter
);
1636 pci_disable_pcie_error_reporting(pdev
);
1637 pci_release_regions(pdev
);
1638 pci_disable_device(pdev
);
1639 pci_set_drvdata(pdev
, NULL
);
1641 free_netdev(netdev
);
1643 static int __qlcnic_shutdown(struct pci_dev
*pdev
)
1645 struct qlcnic_adapter
*adapter
= pci_get_drvdata(pdev
);
1646 struct net_device
*netdev
= adapter
->netdev
;
1649 netif_device_detach(netdev
);
1651 qlcnic_cancel_fw_work(adapter
);
1653 if (netif_running(netdev
))
1654 qlcnic_down(adapter
, netdev
);
1656 qlcnic_clr_all_drv_state(adapter
, 0);
1658 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
1660 retval
= pci_save_state(pdev
);
1664 if (qlcnic_wol_supported(adapter
)) {
1665 pci_enable_wake(pdev
, PCI_D3cold
, 1);
1666 pci_enable_wake(pdev
, PCI_D3hot
, 1);
1672 static void qlcnic_shutdown(struct pci_dev
*pdev
)
1674 if (__qlcnic_shutdown(pdev
))
1677 pci_disable_device(pdev
);
1682 qlcnic_suspend(struct pci_dev
*pdev
, pm_message_t state
)
1686 retval
= __qlcnic_shutdown(pdev
);
1690 pci_set_power_state(pdev
, pci_choose_state(pdev
, state
));
1695 qlcnic_resume(struct pci_dev
*pdev
)
1697 struct qlcnic_adapter
*adapter
= pci_get_drvdata(pdev
);
1698 struct net_device
*netdev
= adapter
->netdev
;
1701 err
= pci_enable_device(pdev
);
1705 pci_set_power_state(pdev
, PCI_D0
);
1706 pci_set_master(pdev
);
1707 pci_restore_state(pdev
);
1709 err
= adapter
->nic_ops
->start_firmware(adapter
);
1711 dev_err(&pdev
->dev
, "failed to start firmware\n");
1715 if (netif_running(netdev
)) {
1716 err
= qlcnic_up(adapter
, netdev
);
1720 qlcnic_restore_indev_addr(netdev
, NETDEV_UP
);
1723 netif_device_attach(netdev
);
1724 qlcnic_schedule_work(adapter
, qlcnic_fw_poll_work
, FW_POLL_DELAY
);
1729 static int qlcnic_open(struct net_device
*netdev
)
1731 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
1734 err
= qlcnic_attach(adapter
);
1738 err
= __qlcnic_up(adapter
, netdev
);
1742 netif_start_queue(netdev
);
1747 qlcnic_detach(adapter
);
1752 * qlcnic_close - Disables a network interface entry point
1754 static int qlcnic_close(struct net_device
*netdev
)
1756 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
1758 __qlcnic_down(adapter
, netdev
);
1763 qlcnic_alloc_lb_filters_mem(struct qlcnic_adapter
*adapter
)
1768 if (!qlcnic_mac_learn
)
1771 spin_lock_init(&adapter
->mac_learn_lock
);
1773 head
= kcalloc(QLCNIC_LB_MAX_FILTERS
, sizeof(struct hlist_head
),
1778 adapter
->fhash
.fmax
= QLCNIC_LB_MAX_FILTERS
;
1779 adapter
->fhash
.fhead
= (struct hlist_head
*)head
;
1781 for (i
= 0; i
< adapter
->fhash
.fmax
; i
++)
1782 INIT_HLIST_HEAD(&adapter
->fhash
.fhead
[i
]);
1785 static void qlcnic_free_lb_filters_mem(struct qlcnic_adapter
*adapter
)
1787 if (adapter
->fhash
.fmax
&& adapter
->fhash
.fhead
)
1788 kfree(adapter
->fhash
.fhead
);
1790 adapter
->fhash
.fhead
= NULL
;
1791 adapter
->fhash
.fmax
= 0;
1794 static void qlcnic_change_filter(struct qlcnic_adapter
*adapter
,
1795 u64 uaddr
, __le16 vlan_id
, struct qlcnic_host_tx_ring
*tx_ring
)
1797 struct cmd_desc_type0
*hwdesc
;
1798 struct qlcnic_nic_req
*req
;
1799 struct qlcnic_mac_req
*mac_req
;
1800 struct qlcnic_vlan_req
*vlan_req
;
1804 producer
= tx_ring
->producer
;
1805 hwdesc
= &tx_ring
->desc_head
[tx_ring
->producer
];
1807 req
= (struct qlcnic_nic_req
*)hwdesc
;
1808 memset(req
, 0, sizeof(struct qlcnic_nic_req
));
1809 req
->qhdr
= cpu_to_le64(QLCNIC_REQUEST
<< 23);
1811 word
= QLCNIC_MAC_EVENT
| ((u64
)(adapter
->portnum
) << 16);
1812 req
->req_hdr
= cpu_to_le64(word
);
1814 mac_req
= (struct qlcnic_mac_req
*)&(req
->words
[0]);
1815 mac_req
->op
= vlan_id
? QLCNIC_MAC_VLAN_ADD
: QLCNIC_MAC_ADD
;
1816 memcpy(mac_req
->mac_addr
, &uaddr
, ETH_ALEN
);
1818 vlan_req
= (struct qlcnic_vlan_req
*)&req
->words
[1];
1819 vlan_req
->vlan_id
= vlan_id
;
1821 tx_ring
->producer
= get_next_index(producer
, tx_ring
->num_desc
);
1824 #define QLCNIC_MAC_HASH(MAC)\
1825 ((((MAC) & 0x70000) >> 0x10) | (((MAC) & 0x70000000000ULL) >> 0x25))
1828 qlcnic_send_filter(struct qlcnic_adapter
*adapter
,
1829 struct qlcnic_host_tx_ring
*tx_ring
,
1830 struct cmd_desc_type0
*first_desc
,
1831 struct sk_buff
*skb
)
1833 struct ethhdr
*phdr
= (struct ethhdr
*)(skb
->data
);
1834 struct qlcnic_filter
*fil
, *tmp_fil
;
1835 struct hlist_node
*tmp_hnode
, *n
;
1836 struct hlist_head
*head
;
1841 if (!compare_ether_addr(phdr
->h_source
, adapter
->mac_addr
))
1844 if (adapter
->fhash
.fnum
>= adapter
->fhash
.fmax
)
1847 /* Only NPAR capable devices support vlan based learning*/
1848 if (adapter
->flags
& QLCNIC_ESWITCH_ENABLED
)
1849 vlan_id
= first_desc
->vlan_TCI
;
1850 memcpy(&src_addr
, phdr
->h_source
, ETH_ALEN
);
1851 hindex
= QLCNIC_MAC_HASH(src_addr
) & (QLCNIC_LB_MAX_FILTERS
- 1);
1852 head
= &(adapter
->fhash
.fhead
[hindex
]);
1854 hlist_for_each_entry_safe(tmp_fil
, tmp_hnode
, n
, head
, fnode
) {
1855 if (!memcmp(tmp_fil
->faddr
, &src_addr
, ETH_ALEN
) &&
1856 tmp_fil
->vlan_id
== vlan_id
) {
1859 (QLCNIC_READD_AGE
* HZ
+ tmp_fil
->ftime
))
1860 qlcnic_change_filter(adapter
, src_addr
, vlan_id
,
1862 tmp_fil
->ftime
= jiffies
;
1867 fil
= kzalloc(sizeof(struct qlcnic_filter
), GFP_ATOMIC
);
1871 qlcnic_change_filter(adapter
, src_addr
, vlan_id
, tx_ring
);
1873 fil
->ftime
= jiffies
;
1874 fil
->vlan_id
= vlan_id
;
1875 memcpy(fil
->faddr
, &src_addr
, ETH_ALEN
);
1876 spin_lock(&adapter
->mac_learn_lock
);
1877 hlist_add_head(&(fil
->fnode
), head
);
1878 adapter
->fhash
.fnum
++;
1879 spin_unlock(&adapter
->mac_learn_lock
);
1883 qlcnic_tso_check(struct net_device
*netdev
,
1884 struct qlcnic_host_tx_ring
*tx_ring
,
1885 struct cmd_desc_type0
*first_desc
,
1886 struct sk_buff
*skb
)
1888 u8 opcode
= TX_ETHER_PKT
;
1889 __be16 protocol
= skb
->protocol
;
1891 int copied
, offset
, copy_len
, hdr_len
= 0, tso
= 0;
1892 struct cmd_desc_type0
*hwdesc
;
1893 struct vlan_ethhdr
*vh
;
1894 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
1895 u32 producer
= tx_ring
->producer
;
1896 __le16 vlan_oob
= first_desc
->flags_opcode
&
1897 cpu_to_le16(FLAGS_VLAN_OOB
);
1899 if (*(skb
->data
) & BIT_0
) {
1901 memcpy(&first_desc
->eth_addr
, skb
->data
, ETH_ALEN
);
1904 if ((netdev
->features
& (NETIF_F_TSO
| NETIF_F_TSO6
)) &&
1905 skb_shinfo(skb
)->gso_size
> 0) {
1907 hdr_len
= skb_transport_offset(skb
) + tcp_hdrlen(skb
);
1909 first_desc
->mss
= cpu_to_le16(skb_shinfo(skb
)->gso_size
);
1910 first_desc
->total_hdr_length
= hdr_len
;
1912 first_desc
->total_hdr_length
+= VLAN_HLEN
;
1913 first_desc
->tcp_hdr_offset
= VLAN_HLEN
;
1914 first_desc
->ip_hdr_offset
= VLAN_HLEN
;
1915 /* Only in case of TSO on vlan device */
1916 flags
|= FLAGS_VLAN_TAGGED
;
1919 opcode
= (protocol
== cpu_to_be16(ETH_P_IPV6
)) ?
1920 TX_TCP_LSO6
: TX_TCP_LSO
;
1923 } else if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
1926 if (protocol
== cpu_to_be16(ETH_P_IP
)) {
1927 l4proto
= ip_hdr(skb
)->protocol
;
1929 if (l4proto
== IPPROTO_TCP
)
1930 opcode
= TX_TCP_PKT
;
1931 else if (l4proto
== IPPROTO_UDP
)
1932 opcode
= TX_UDP_PKT
;
1933 } else if (protocol
== cpu_to_be16(ETH_P_IPV6
)) {
1934 l4proto
= ipv6_hdr(skb
)->nexthdr
;
1936 if (l4proto
== IPPROTO_TCP
)
1937 opcode
= TX_TCPV6_PKT
;
1938 else if (l4proto
== IPPROTO_UDP
)
1939 opcode
= TX_UDPV6_PKT
;
1943 first_desc
->tcp_hdr_offset
+= skb_transport_offset(skb
);
1944 first_desc
->ip_hdr_offset
+= skb_network_offset(skb
);
1945 qlcnic_set_tx_flags_opcode(first_desc
, flags
, opcode
);
1950 /* For LSO, we need to copy the MAC/IP/TCP headers into
1951 * the descriptor ring
1957 /* Create a TSO vlan header template for firmware */
1959 hwdesc
= &tx_ring
->desc_head
[producer
];
1960 tx_ring
->cmd_buf_arr
[producer
].skb
= NULL
;
1962 copy_len
= min((int)sizeof(struct cmd_desc_type0
) - offset
,
1963 hdr_len
+ VLAN_HLEN
);
1965 vh
= (struct vlan_ethhdr
*)((char *)hwdesc
+ 2);
1966 skb_copy_from_linear_data(skb
, vh
, 12);
1967 vh
->h_vlan_proto
= htons(ETH_P_8021Q
);
1968 vh
->h_vlan_TCI
= (__be16
)swab16((u16
)first_desc
->vlan_TCI
);
1970 skb_copy_from_linear_data_offset(skb
, 12,
1971 (char *)vh
+ 16, copy_len
- 16);
1973 copied
= copy_len
- VLAN_HLEN
;
1976 producer
= get_next_index(producer
, tx_ring
->num_desc
);
1979 while (copied
< hdr_len
) {
1981 copy_len
= min((int)sizeof(struct cmd_desc_type0
) - offset
,
1982 (hdr_len
- copied
));
1984 hwdesc
= &tx_ring
->desc_head
[producer
];
1985 tx_ring
->cmd_buf_arr
[producer
].skb
= NULL
;
1987 skb_copy_from_linear_data_offset(skb
, copied
,
1988 (char *)hwdesc
+ offset
, copy_len
);
1993 producer
= get_next_index(producer
, tx_ring
->num_desc
);
1996 tx_ring
->producer
= producer
;
1998 adapter
->stats
.lso_frames
++;
2002 qlcnic_map_tx_skb(struct pci_dev
*pdev
,
2003 struct sk_buff
*skb
, struct qlcnic_cmd_buffer
*pbuf
)
2005 struct qlcnic_skb_frag
*nf
;
2006 struct skb_frag_struct
*frag
;
2010 nr_frags
= skb_shinfo(skb
)->nr_frags
;
2011 nf
= &pbuf
->frag_array
[0];
2013 map
= pci_map_single(pdev
, skb
->data
,
2014 skb_headlen(skb
), PCI_DMA_TODEVICE
);
2015 if (pci_dma_mapping_error(pdev
, map
))
2019 nf
->length
= skb_headlen(skb
);
2021 for (i
= 0; i
< nr_frags
; i
++) {
2022 frag
= &skb_shinfo(skb
)->frags
[i
];
2023 nf
= &pbuf
->frag_array
[i
+1];
2025 map
= pci_map_page(pdev
, frag
->page
, frag
->page_offset
,
2026 frag
->size
, PCI_DMA_TODEVICE
);
2027 if (pci_dma_mapping_error(pdev
, map
))
2031 nf
->length
= frag
->size
;
2038 nf
= &pbuf
->frag_array
[i
+1];
2039 pci_unmap_page(pdev
, nf
->dma
, nf
->length
, PCI_DMA_TODEVICE
);
2042 nf
= &pbuf
->frag_array
[0];
2043 pci_unmap_single(pdev
, nf
->dma
, skb_headlen(skb
), PCI_DMA_TODEVICE
);
2050 qlcnic_check_tx_tagging(struct qlcnic_adapter
*adapter
,
2051 struct sk_buff
*skb
,
2052 struct cmd_desc_type0
*first_desc
)
2056 __be16 protocol
= skb
->protocol
;
2057 struct vlan_ethhdr
*vh
;
2059 if (protocol
== cpu_to_be16(ETH_P_8021Q
)) {
2060 vh
= (struct vlan_ethhdr
*)skb
->data
;
2061 protocol
= vh
->h_vlan_encapsulated_proto
;
2062 flags
= FLAGS_VLAN_TAGGED
;
2063 qlcnic_set_tx_vlan_tci(first_desc
, ntohs(vh
->h_vlan_TCI
));
2064 } else if (vlan_tx_tag_present(skb
)) {
2065 flags
= FLAGS_VLAN_OOB
;
2066 qlcnic_set_tx_vlan_tci(first_desc
, vlan_tx_tag_get(skb
));
2068 if (unlikely(adapter
->pvid
)) {
2069 if (first_desc
->vlan_TCI
&&
2070 !(adapter
->flags
& QLCNIC_TAGGING_ENABLED
))
2072 if (first_desc
->vlan_TCI
&&
2073 (adapter
->flags
& QLCNIC_TAGGING_ENABLED
))
2076 flags
= FLAGS_VLAN_OOB
;
2077 qlcnic_set_tx_vlan_tci(first_desc
, adapter
->pvid
);
2080 qlcnic_set_tx_flags_opcode(first_desc
, flags
, opcode
);
2085 qlcnic_clear_cmddesc(u64
*desc
)
2093 qlcnic_xmit_frame(struct sk_buff
*skb
, struct net_device
*netdev
)
2095 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
2096 struct qlcnic_host_tx_ring
*tx_ring
= adapter
->tx_ring
;
2097 struct qlcnic_cmd_buffer
*pbuf
;
2098 struct qlcnic_skb_frag
*buffrag
;
2099 struct cmd_desc_type0
*hwdesc
, *first_desc
;
2100 struct pci_dev
*pdev
;
2101 struct ethhdr
*phdr
;
2106 int frag_count
, no_of_desc
;
2107 u32 num_txd
= tx_ring
->num_desc
;
2109 if (!test_bit(__QLCNIC_DEV_UP
, &adapter
->state
)) {
2110 netif_stop_queue(netdev
);
2111 return NETDEV_TX_BUSY
;
2114 if (adapter
->flags
& QLCNIC_MACSPOOF
) {
2115 phdr
= (struct ethhdr
*)skb
->data
;
2116 if (compare_ether_addr(phdr
->h_source
,
2121 frag_count
= skb_shinfo(skb
)->nr_frags
+ 1;
2122 /* 14 frags supported for normal packet and
2123 * 32 frags supported for TSO packet
2125 if (!skb_is_gso(skb
) && frag_count
> QLCNIC_MAX_FRAGS_PER_TX
) {
2127 for (i
= 0; i
< (frag_count
- QLCNIC_MAX_FRAGS_PER_TX
); i
++)
2128 delta
+= skb_shinfo(skb
)->frags
[i
].size
;
2130 if (!__pskb_pull_tail(skb
, delta
))
2133 frag_count
= 1 + skb_shinfo(skb
)->nr_frags
;
2136 /* 4 fragments per cmd des */
2137 no_of_desc
= (frag_count
+ 3) >> 2;
2139 if (unlikely(qlcnic_tx_avail(tx_ring
) <= TX_STOP_THRESH
)) {
2140 netif_stop_queue(netdev
);
2142 if (qlcnic_tx_avail(tx_ring
) > TX_STOP_THRESH
)
2143 netif_start_queue(netdev
);
2145 adapter
->stats
.xmit_off
++;
2146 return NETDEV_TX_BUSY
;
2150 producer
= tx_ring
->producer
;
2151 pbuf
= &tx_ring
->cmd_buf_arr
[producer
];
2153 pdev
= adapter
->pdev
;
2155 first_desc
= hwdesc
= &tx_ring
->desc_head
[producer
];
2156 qlcnic_clear_cmddesc((u64
*)hwdesc
);
2158 if (qlcnic_check_tx_tagging(adapter
, skb
, first_desc
))
2161 if (qlcnic_map_tx_skb(pdev
, skb
, pbuf
)) {
2162 adapter
->stats
.tx_dma_map_error
++;
2167 pbuf
->frag_count
= frag_count
;
2169 qlcnic_set_tx_frags_len(first_desc
, frag_count
, skb
->len
);
2170 qlcnic_set_tx_port(first_desc
, adapter
->portnum
);
2172 for (i
= 0; i
< frag_count
; i
++) {
2176 if ((k
== 0) && (i
> 0)) {
2177 /* move to next desc.*/
2178 producer
= get_next_index(producer
, num_txd
);
2179 hwdesc
= &tx_ring
->desc_head
[producer
];
2180 qlcnic_clear_cmddesc((u64
*)hwdesc
);
2181 tx_ring
->cmd_buf_arr
[producer
].skb
= NULL
;
2184 buffrag
= &pbuf
->frag_array
[i
];
2186 hwdesc
->buffer_length
[k
] = cpu_to_le16(buffrag
->length
);
2189 hwdesc
->addr_buffer1
= cpu_to_le64(buffrag
->dma
);
2192 hwdesc
->addr_buffer2
= cpu_to_le64(buffrag
->dma
);
2195 hwdesc
->addr_buffer3
= cpu_to_le64(buffrag
->dma
);
2198 hwdesc
->addr_buffer4
= cpu_to_le64(buffrag
->dma
);
2203 tx_ring
->producer
= get_next_index(producer
, num_txd
);
2205 qlcnic_tso_check(netdev
, tx_ring
, first_desc
, skb
);
2207 if (qlcnic_mac_learn
)
2208 qlcnic_send_filter(adapter
, tx_ring
, first_desc
, skb
);
2210 qlcnic_update_cmd_producer(adapter
, tx_ring
);
2212 adapter
->stats
.txbytes
+= skb
->len
;
2213 adapter
->stats
.xmitcalled
++;
2215 return NETDEV_TX_OK
;
2218 adapter
->stats
.txdropped
++;
2219 dev_kfree_skb_any(skb
);
2220 return NETDEV_TX_OK
;
2223 static int qlcnic_check_temp(struct qlcnic_adapter
*adapter
)
2225 struct net_device
*netdev
= adapter
->netdev
;
2226 u32 temp
, temp_state
, temp_val
;
2229 temp
= QLCRD32(adapter
, CRB_TEMP_STATE
);
2231 temp_state
= qlcnic_get_temp_state(temp
);
2232 temp_val
= qlcnic_get_temp_val(temp
);
2234 if (temp_state
== QLCNIC_TEMP_PANIC
) {
2235 dev_err(&netdev
->dev
,
2236 "Device temperature %d degrees C exceeds"
2237 " maximum allowed. Hardware has been shut down.\n",
2240 } else if (temp_state
== QLCNIC_TEMP_WARN
) {
2241 if (adapter
->temp
== QLCNIC_TEMP_NORMAL
) {
2242 dev_err(&netdev
->dev
,
2243 "Device temperature %d degrees C "
2244 "exceeds operating range."
2245 " Immediate action needed.\n",
2249 if (adapter
->temp
== QLCNIC_TEMP_WARN
) {
2250 dev_info(&netdev
->dev
,
2251 "Device temperature is now %d degrees C"
2252 " in normal range.\n", temp_val
);
2255 adapter
->temp
= temp_state
;
2259 void qlcnic_advert_link_change(struct qlcnic_adapter
*adapter
, int linkup
)
2261 struct net_device
*netdev
= adapter
->netdev
;
2263 if (adapter
->ahw
.linkup
&& !linkup
) {
2264 netdev_info(netdev
, "NIC Link is down\n");
2265 adapter
->ahw
.linkup
= 0;
2266 if (netif_running(netdev
)) {
2267 netif_carrier_off(netdev
);
2268 netif_stop_queue(netdev
);
2270 } else if (!adapter
->ahw
.linkup
&& linkup
) {
2271 netdev_info(netdev
, "NIC Link is up\n");
2272 adapter
->ahw
.linkup
= 1;
2273 if (netif_running(netdev
)) {
2274 netif_carrier_on(netdev
);
2275 netif_wake_queue(netdev
);
2280 static void qlcnic_tx_timeout(struct net_device
*netdev
)
2282 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
2284 if (test_bit(__QLCNIC_RESETTING
, &adapter
->state
))
2287 dev_err(&netdev
->dev
, "transmit timeout, resetting.\n");
2289 if (++adapter
->tx_timeo_cnt
>= QLCNIC_MAX_TX_TIMEOUTS
)
2290 adapter
->need_fw_reset
= 1;
2292 adapter
->reset_context
= 1;
2295 static struct net_device_stats
*qlcnic_get_stats(struct net_device
*netdev
)
2297 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
2298 struct net_device_stats
*stats
= &netdev
->stats
;
2300 stats
->rx_packets
= adapter
->stats
.rx_pkts
+ adapter
->stats
.lro_pkts
;
2301 stats
->tx_packets
= adapter
->stats
.xmitfinished
;
2302 stats
->rx_bytes
= adapter
->stats
.rxbytes
+ adapter
->stats
.lrobytes
;
2303 stats
->tx_bytes
= adapter
->stats
.txbytes
;
2304 stats
->rx_dropped
= adapter
->stats
.rxdropped
;
2305 stats
->tx_dropped
= adapter
->stats
.txdropped
;
2310 static irqreturn_t
qlcnic_clear_legacy_intr(struct qlcnic_adapter
*adapter
)
2314 status
= readl(adapter
->isr_int_vec
);
2316 if (!(status
& adapter
->int_vec_bit
))
2319 /* check interrupt state machine, to be sure */
2320 status
= readl(adapter
->crb_int_state_reg
);
2321 if (!ISR_LEGACY_INT_TRIGGERED(status
))
2324 writel(0xffffffff, adapter
->tgt_status_reg
);
2325 /* read twice to ensure write is flushed */
2326 readl(adapter
->isr_int_vec
);
2327 readl(adapter
->isr_int_vec
);
2332 static irqreturn_t
qlcnic_tmp_intr(int irq
, void *data
)
2334 struct qlcnic_host_sds_ring
*sds_ring
= data
;
2335 struct qlcnic_adapter
*adapter
= sds_ring
->adapter
;
2337 if (adapter
->flags
& QLCNIC_MSIX_ENABLED
)
2339 else if (adapter
->flags
& QLCNIC_MSI_ENABLED
) {
2340 writel(0xffffffff, adapter
->tgt_status_reg
);
2344 if (qlcnic_clear_legacy_intr(adapter
) == IRQ_NONE
)
2348 adapter
->diag_cnt
++;
2349 qlcnic_enable_int(sds_ring
);
2353 static irqreturn_t
qlcnic_intr(int irq
, void *data
)
2355 struct qlcnic_host_sds_ring
*sds_ring
= data
;
2356 struct qlcnic_adapter
*adapter
= sds_ring
->adapter
;
2358 if (qlcnic_clear_legacy_intr(adapter
) == IRQ_NONE
)
2361 napi_schedule(&sds_ring
->napi
);
2366 static irqreturn_t
qlcnic_msi_intr(int irq
, void *data
)
2368 struct qlcnic_host_sds_ring
*sds_ring
= data
;
2369 struct qlcnic_adapter
*adapter
= sds_ring
->adapter
;
2371 /* clear interrupt */
2372 writel(0xffffffff, adapter
->tgt_status_reg
);
2374 napi_schedule(&sds_ring
->napi
);
2378 static irqreturn_t
qlcnic_msix_intr(int irq
, void *data
)
2380 struct qlcnic_host_sds_ring
*sds_ring
= data
;
2382 napi_schedule(&sds_ring
->napi
);
2386 static int qlcnic_process_cmd_ring(struct qlcnic_adapter
*adapter
)
2388 u32 sw_consumer
, hw_consumer
;
2390 struct qlcnic_cmd_buffer
*buffer
;
2391 struct pci_dev
*pdev
= adapter
->pdev
;
2392 struct net_device
*netdev
= adapter
->netdev
;
2393 struct qlcnic_skb_frag
*frag
;
2395 struct qlcnic_host_tx_ring
*tx_ring
= adapter
->tx_ring
;
2397 if (!spin_trylock(&adapter
->tx_clean_lock
))
2400 sw_consumer
= tx_ring
->sw_consumer
;
2401 hw_consumer
= le32_to_cpu(*(tx_ring
->hw_consumer
));
2403 while (sw_consumer
!= hw_consumer
) {
2404 buffer
= &tx_ring
->cmd_buf_arr
[sw_consumer
];
2406 frag
= &buffer
->frag_array
[0];
2407 pci_unmap_single(pdev
, frag
->dma
, frag
->length
,
2410 for (i
= 1; i
< buffer
->frag_count
; i
++) {
2412 pci_unmap_page(pdev
, frag
->dma
, frag
->length
,
2417 adapter
->stats
.xmitfinished
++;
2418 dev_kfree_skb_any(buffer
->skb
);
2422 sw_consumer
= get_next_index(sw_consumer
, tx_ring
->num_desc
);
2423 if (++count
>= MAX_STATUS_HANDLE
)
2427 if (count
&& netif_running(netdev
)) {
2428 tx_ring
->sw_consumer
= sw_consumer
;
2432 if (netif_queue_stopped(netdev
) && netif_carrier_ok(netdev
)) {
2433 if (qlcnic_tx_avail(tx_ring
) > TX_STOP_THRESH
) {
2434 netif_wake_queue(netdev
);
2435 adapter
->stats
.xmit_on
++;
2438 adapter
->tx_timeo_cnt
= 0;
2441 * If everything is freed up to consumer then check if the ring is full
2442 * If the ring is full then check if more needs to be freed and
2443 * schedule the call back again.
2445 * This happens when there are 2 CPUs. One could be freeing and the
2446 * other filling it. If the ring is full when we get out of here and
2447 * the card has already interrupted the host then the host can miss the
2450 * There is still a possible race condition and the host could miss an
2451 * interrupt. The card has to take care of this.
2453 hw_consumer
= le32_to_cpu(*(tx_ring
->hw_consumer
));
2454 done
= (sw_consumer
== hw_consumer
);
2455 spin_unlock(&adapter
->tx_clean_lock
);
2460 static int qlcnic_poll(struct napi_struct
*napi
, int budget
)
2462 struct qlcnic_host_sds_ring
*sds_ring
=
2463 container_of(napi
, struct qlcnic_host_sds_ring
, napi
);
2465 struct qlcnic_adapter
*adapter
= sds_ring
->adapter
;
2470 tx_complete
= qlcnic_process_cmd_ring(adapter
);
2472 work_done
= qlcnic_process_rcv_ring(sds_ring
, budget
);
2474 if ((work_done
< budget
) && tx_complete
) {
2475 napi_complete(&sds_ring
->napi
);
2476 if (test_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
2477 qlcnic_enable_int(sds_ring
);
2483 static int qlcnic_rx_poll(struct napi_struct
*napi
, int budget
)
2485 struct qlcnic_host_sds_ring
*sds_ring
=
2486 container_of(napi
, struct qlcnic_host_sds_ring
, napi
);
2488 struct qlcnic_adapter
*adapter
= sds_ring
->adapter
;
2491 work_done
= qlcnic_process_rcv_ring(sds_ring
, budget
);
2493 if (work_done
< budget
) {
2494 napi_complete(&sds_ring
->napi
);
2495 if (test_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
2496 qlcnic_enable_int(sds_ring
);
2502 #ifdef CONFIG_NET_POLL_CONTROLLER
2503 static void qlcnic_poll_controller(struct net_device
*netdev
)
2506 struct qlcnic_host_sds_ring
*sds_ring
;
2507 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
2508 struct qlcnic_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
2510 disable_irq(adapter
->irq
);
2511 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
2512 sds_ring
= &recv_ctx
->sds_rings
[ring
];
2513 qlcnic_intr(adapter
->irq
, sds_ring
);
2515 enable_irq(adapter
->irq
);
2520 qlcnic_idc_debug_info(struct qlcnic_adapter
*adapter
, u8 encoding
)
2524 val
= adapter
->portnum
& 0xf;
2525 val
|= encoding
<< 7;
2526 val
|= (jiffies
- adapter
->dev_rst_time
) << 8;
2528 QLCWR32(adapter
, QLCNIC_CRB_DRV_SCRATCH
, val
);
2529 adapter
->dev_rst_time
= jiffies
;
2533 qlcnic_set_drv_state(struct qlcnic_adapter
*adapter
, u8 state
)
2537 WARN_ON(state
!= QLCNIC_DEV_NEED_RESET
&&
2538 state
!= QLCNIC_DEV_NEED_QUISCENT
);
2540 if (qlcnic_api_lock(adapter
))
2543 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_STATE
);
2545 if (state
== QLCNIC_DEV_NEED_RESET
)
2546 QLC_DEV_SET_RST_RDY(val
, adapter
->portnum
);
2547 else if (state
== QLCNIC_DEV_NEED_QUISCENT
)
2548 QLC_DEV_SET_QSCNT_RDY(val
, adapter
->portnum
);
2550 QLCWR32(adapter
, QLCNIC_CRB_DRV_STATE
, val
);
2552 qlcnic_api_unlock(adapter
);
2558 qlcnic_clr_drv_state(struct qlcnic_adapter
*adapter
)
2562 if (qlcnic_api_lock(adapter
))
2565 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_STATE
);
2566 QLC_DEV_CLR_RST_QSCNT(val
, adapter
->portnum
);
2567 QLCWR32(adapter
, QLCNIC_CRB_DRV_STATE
, val
);
2569 qlcnic_api_unlock(adapter
);
2575 qlcnic_clr_all_drv_state(struct qlcnic_adapter
*adapter
, u8 failed
)
2579 if (qlcnic_api_lock(adapter
))
2582 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_ACTIVE
);
2583 QLC_DEV_CLR_REF_CNT(val
, adapter
->portnum
);
2584 QLCWR32(adapter
, QLCNIC_CRB_DRV_ACTIVE
, val
);
2587 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
, QLCNIC_DEV_FAILED
);
2588 dev_info(&adapter
->pdev
->dev
,
2589 "Device state set to Failed. Please Reboot\n");
2590 } else if (!(val
& 0x11111111))
2591 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
, QLCNIC_DEV_COLD
);
2593 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_STATE
);
2594 QLC_DEV_CLR_RST_QSCNT(val
, adapter
->portnum
);
2595 QLCWR32(adapter
, QLCNIC_CRB_DRV_STATE
, val
);
2597 qlcnic_api_unlock(adapter
);
2599 adapter
->fw_fail_cnt
= 0;
2600 clear_bit(__QLCNIC_START_FW
, &adapter
->state
);
2601 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
2604 /* Grab api lock, before checking state */
2606 qlcnic_check_drv_state(struct qlcnic_adapter
*adapter
)
2610 state
= QLCRD32(adapter
, QLCNIC_CRB_DRV_STATE
);
2611 act
= QLCRD32(adapter
, QLCNIC_CRB_DRV_ACTIVE
);
2613 if (((state
& 0x11111111) == (act
& 0x11111111)) ||
2614 ((act
& 0x11111111) == ((state
>> 1) & 0x11111111)))
2620 static int qlcnic_check_idc_ver(struct qlcnic_adapter
*adapter
)
2622 u32 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_IDC_VER
);
2624 if (val
!= QLCNIC_DRV_IDC_VER
) {
2625 dev_warn(&adapter
->pdev
->dev
, "IDC Version mismatch, driver's"
2626 " idc ver = %x; reqd = %x\n", QLCNIC_DRV_IDC_VER
, val
);
2633 qlcnic_can_start_firmware(struct qlcnic_adapter
*adapter
)
2635 u32 val
, prev_state
;
2636 u8 dev_init_timeo
= adapter
->dev_init_timeo
;
2637 u8 portnum
= adapter
->portnum
;
2640 if (test_and_clear_bit(__QLCNIC_START_FW
, &adapter
->state
))
2643 if (qlcnic_api_lock(adapter
))
2646 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_ACTIVE
);
2647 if (!(val
& (1 << (portnum
* 4)))) {
2648 QLC_DEV_SET_REF_CNT(val
, portnum
);
2649 QLCWR32(adapter
, QLCNIC_CRB_DRV_ACTIVE
, val
);
2652 prev_state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
);
2653 QLCDB(adapter
, HW
, "Device state = %u\n", prev_state
);
2655 switch (prev_state
) {
2656 case QLCNIC_DEV_COLD
:
2657 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
, QLCNIC_DEV_INITIALIZING
);
2658 QLCWR32(adapter
, QLCNIC_CRB_DRV_IDC_VER
, QLCNIC_DRV_IDC_VER
);
2659 qlcnic_idc_debug_info(adapter
, 0);
2660 qlcnic_api_unlock(adapter
);
2663 case QLCNIC_DEV_READY
:
2664 ret
= qlcnic_check_idc_ver(adapter
);
2665 qlcnic_api_unlock(adapter
);
2668 case QLCNIC_DEV_NEED_RESET
:
2669 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_STATE
);
2670 QLC_DEV_SET_RST_RDY(val
, portnum
);
2671 QLCWR32(adapter
, QLCNIC_CRB_DRV_STATE
, val
);
2674 case QLCNIC_DEV_NEED_QUISCENT
:
2675 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_STATE
);
2676 QLC_DEV_SET_QSCNT_RDY(val
, portnum
);
2677 QLCWR32(adapter
, QLCNIC_CRB_DRV_STATE
, val
);
2680 case QLCNIC_DEV_FAILED
:
2681 dev_err(&adapter
->pdev
->dev
, "Device in failed state.\n");
2682 qlcnic_api_unlock(adapter
);
2685 case QLCNIC_DEV_INITIALIZING
:
2686 case QLCNIC_DEV_QUISCENT
:
2690 qlcnic_api_unlock(adapter
);
2694 prev_state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
);
2696 if (prev_state
== QLCNIC_DEV_QUISCENT
)
2698 } while ((prev_state
!= QLCNIC_DEV_READY
) && --dev_init_timeo
);
2700 if (!dev_init_timeo
) {
2701 dev_err(&adapter
->pdev
->dev
,
2702 "Waiting for device to initialize timeout\n");
2706 if (qlcnic_api_lock(adapter
))
2709 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_STATE
);
2710 QLC_DEV_CLR_RST_QSCNT(val
, portnum
);
2711 QLCWR32(adapter
, QLCNIC_CRB_DRV_STATE
, val
);
2713 ret
= qlcnic_check_idc_ver(adapter
);
2714 qlcnic_api_unlock(adapter
);
2720 qlcnic_fwinit_work(struct work_struct
*work
)
2722 struct qlcnic_adapter
*adapter
= container_of(work
,
2723 struct qlcnic_adapter
, fw_work
.work
);
2724 u32 dev_state
= 0xf;
2726 if (qlcnic_api_lock(adapter
))
2729 dev_state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
);
2730 if (dev_state
== QLCNIC_DEV_QUISCENT
||
2731 dev_state
== QLCNIC_DEV_NEED_QUISCENT
) {
2732 qlcnic_api_unlock(adapter
);
2733 qlcnic_schedule_work(adapter
, qlcnic_fwinit_work
,
2738 if (adapter
->op_mode
== QLCNIC_NON_PRIV_FUNC
) {
2739 qlcnic_api_unlock(adapter
);
2743 if (adapter
->fw_wait_cnt
++ > adapter
->reset_ack_timeo
) {
2744 dev_err(&adapter
->pdev
->dev
, "Reset:Failed to get ack %d sec\n",
2745 adapter
->reset_ack_timeo
);
2746 goto skip_ack_check
;
2749 if (!qlcnic_check_drv_state(adapter
)) {
2751 dev_state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
);
2753 if (dev_state
== QLCNIC_DEV_NEED_RESET
) {
2754 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
,
2755 QLCNIC_DEV_INITIALIZING
);
2756 set_bit(__QLCNIC_START_FW
, &adapter
->state
);
2757 QLCDB(adapter
, DRV
, "Restarting fw\n");
2758 qlcnic_idc_debug_info(adapter
, 0);
2761 qlcnic_api_unlock(adapter
);
2763 if (!adapter
->nic_ops
->start_firmware(adapter
)) {
2764 qlcnic_schedule_work(adapter
, qlcnic_attach_work
, 0);
2765 adapter
->fw_wait_cnt
= 0;
2771 qlcnic_api_unlock(adapter
);
2774 dev_state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
);
2775 QLCDB(adapter
, HW
, "Func waiting: Device state=%u\n", dev_state
);
2777 switch (dev_state
) {
2778 case QLCNIC_DEV_READY
:
2779 if (!adapter
->nic_ops
->start_firmware(adapter
)) {
2780 qlcnic_schedule_work(adapter
, qlcnic_attach_work
, 0);
2781 adapter
->fw_wait_cnt
= 0;
2784 case QLCNIC_DEV_FAILED
:
2787 qlcnic_schedule_work(adapter
,
2788 qlcnic_fwinit_work
, FW_POLL_DELAY
);
2793 dev_err(&adapter
->pdev
->dev
, "Fwinit work failed state=%u "
2794 "fw_wait_cnt=%u\n", dev_state
, adapter
->fw_wait_cnt
);
2795 netif_device_attach(adapter
->netdev
);
2796 qlcnic_clr_all_drv_state(adapter
, 0);
2800 qlcnic_detach_work(struct work_struct
*work
)
2802 struct qlcnic_adapter
*adapter
= container_of(work
,
2803 struct qlcnic_adapter
, fw_work
.work
);
2804 struct net_device
*netdev
= adapter
->netdev
;
2807 netif_device_detach(netdev
);
2809 /* Dont grab rtnl lock during Quiscent mode */
2810 if (adapter
->dev_state
== QLCNIC_DEV_NEED_QUISCENT
) {
2811 if (netif_running(netdev
))
2812 __qlcnic_down(adapter
, netdev
);
2814 qlcnic_down(adapter
, netdev
);
2816 status
= QLCRD32(adapter
, QLCNIC_PEG_HALT_STATUS1
);
2818 if (status
& QLCNIC_RCODE_FATAL_ERROR
)
2821 if (adapter
->temp
== QLCNIC_TEMP_PANIC
)
2824 if (qlcnic_set_drv_state(adapter
, adapter
->dev_state
))
2827 adapter
->fw_wait_cnt
= 0;
2829 qlcnic_schedule_work(adapter
, qlcnic_fwinit_work
, FW_POLL_DELAY
);
2834 dev_err(&adapter
->pdev
->dev
, "detach failed; status=%d temp=%d\n",
2835 status
, adapter
->temp
);
2836 netif_device_attach(netdev
);
2837 qlcnic_clr_all_drv_state(adapter
, 1);
2840 /*Transit NPAR state to NON Operational */
2842 qlcnic_set_npar_non_operational(struct qlcnic_adapter
*adapter
)
2846 state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_NPAR_STATE
);
2847 if (state
== QLCNIC_DEV_NPAR_NON_OPER
)
2850 if (qlcnic_api_lock(adapter
))
2852 QLCWR32(adapter
, QLCNIC_CRB_DEV_NPAR_STATE
, QLCNIC_DEV_NPAR_NON_OPER
);
2853 qlcnic_api_unlock(adapter
);
2856 /*Transit to RESET state from READY state only */
2858 qlcnic_dev_request_reset(struct qlcnic_adapter
*adapter
)
2862 adapter
->need_fw_reset
= 1;
2863 if (qlcnic_api_lock(adapter
))
2866 state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
);
2868 if (state
== QLCNIC_DEV_READY
) {
2869 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
, QLCNIC_DEV_NEED_RESET
);
2870 QLCDB(adapter
, DRV
, "NEED_RESET state set\n");
2871 qlcnic_idc_debug_info(adapter
, 0);
2874 QLCWR32(adapter
, QLCNIC_CRB_DEV_NPAR_STATE
, QLCNIC_DEV_NPAR_NON_OPER
);
2875 qlcnic_api_unlock(adapter
);
2878 /* Transit to NPAR READY state from NPAR NOT READY state */
2880 qlcnic_dev_set_npar_ready(struct qlcnic_adapter
*adapter
)
2882 if (qlcnic_api_lock(adapter
))
2885 QLCWR32(adapter
, QLCNIC_CRB_DEV_NPAR_STATE
, QLCNIC_DEV_NPAR_OPER
);
2886 QLCDB(adapter
, DRV
, "NPAR operational state set\n");
2888 qlcnic_api_unlock(adapter
);
2892 qlcnic_schedule_work(struct qlcnic_adapter
*adapter
,
2893 work_func_t func
, int delay
)
2895 if (test_bit(__QLCNIC_AER
, &adapter
->state
))
2898 INIT_DELAYED_WORK(&adapter
->fw_work
, func
);
2899 queue_delayed_work(qlcnic_wq
, &adapter
->fw_work
,
2900 round_jiffies_relative(delay
));
2904 qlcnic_cancel_fw_work(struct qlcnic_adapter
*adapter
)
2906 while (test_and_set_bit(__QLCNIC_RESETTING
, &adapter
->state
))
2909 cancel_delayed_work_sync(&adapter
->fw_work
);
2913 qlcnic_attach_work(struct work_struct
*work
)
2915 struct qlcnic_adapter
*adapter
= container_of(work
,
2916 struct qlcnic_adapter
, fw_work
.work
);
2917 struct net_device
*netdev
= adapter
->netdev
;
2920 if (adapter
->op_mode
!= QLCNIC_MGMT_FUNC
) {
2921 npar_state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_NPAR_STATE
);
2922 if (adapter
->fw_wait_cnt
++ > QLCNIC_DEV_NPAR_OPER_TIMEO
)
2923 qlcnic_clr_all_drv_state(adapter
, 0);
2924 else if (npar_state
!= QLCNIC_DEV_NPAR_OPER
)
2925 qlcnic_schedule_work(adapter
, qlcnic_attach_work
,
2929 QLCDB(adapter
, DRV
, "Waiting for NPAR state to operational\n");
2933 if (netif_running(netdev
)) {
2934 if (qlcnic_up(adapter
, netdev
))
2937 qlcnic_restore_indev_addr(netdev
, NETDEV_UP
);
2941 netif_device_attach(netdev
);
2942 adapter
->fw_fail_cnt
= 0;
2943 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
2945 if (!qlcnic_clr_drv_state(adapter
))
2946 qlcnic_schedule_work(adapter
, qlcnic_fw_poll_work
,
2951 qlcnic_check_health(struct qlcnic_adapter
*adapter
)
2953 u32 state
= 0, heartbeat
;
2954 struct net_device
*netdev
= adapter
->netdev
;
2956 if (qlcnic_check_temp(adapter
))
2959 if (adapter
->need_fw_reset
)
2960 qlcnic_dev_request_reset(adapter
);
2962 state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
);
2963 if (state
== QLCNIC_DEV_NEED_RESET
) {
2964 qlcnic_set_npar_non_operational(adapter
);
2965 adapter
->need_fw_reset
= 1;
2966 } else if (state
== QLCNIC_DEV_NEED_QUISCENT
)
2969 heartbeat
= QLCRD32(adapter
, QLCNIC_PEG_ALIVE_COUNTER
);
2970 if (heartbeat
!= adapter
->heartbeat
) {
2971 adapter
->heartbeat
= heartbeat
;
2972 adapter
->fw_fail_cnt
= 0;
2973 if (adapter
->need_fw_reset
)
2976 if (adapter
->reset_context
&& auto_fw_reset
) {
2977 qlcnic_reset_hw_context(adapter
);
2978 adapter
->netdev
->trans_start
= jiffies
;
2984 if (++adapter
->fw_fail_cnt
< FW_FAIL_THRESH
)
2987 qlcnic_dev_request_reset(adapter
);
2990 clear_bit(__QLCNIC_FW_ATTACHED
, &adapter
->state
);
2992 dev_info(&netdev
->dev
, "firmware hang detected\n");
2995 adapter
->dev_state
= (state
== QLCNIC_DEV_NEED_QUISCENT
) ? state
:
2996 QLCNIC_DEV_NEED_RESET
;
2998 if (auto_fw_reset
&&
2999 !test_and_set_bit(__QLCNIC_RESETTING
, &adapter
->state
)) {
3001 qlcnic_schedule_work(adapter
, qlcnic_detach_work
, 0);
3002 QLCDB(adapter
, DRV
, "fw recovery scheduled.\n");
3009 qlcnic_fw_poll_work(struct work_struct
*work
)
3011 struct qlcnic_adapter
*adapter
= container_of(work
,
3012 struct qlcnic_adapter
, fw_work
.work
);
3014 if (test_bit(__QLCNIC_RESETTING
, &adapter
->state
))
3018 if (qlcnic_check_health(adapter
))
3021 if (adapter
->fhash
.fnum
)
3022 qlcnic_prune_lb_filters(adapter
);
3025 qlcnic_schedule_work(adapter
, qlcnic_fw_poll_work
, FW_POLL_DELAY
);
3028 static int qlcnic_is_first_func(struct pci_dev
*pdev
)
3030 struct pci_dev
*oth_pdev
;
3031 int val
= pdev
->devfn
;
3034 oth_pdev
= pci_get_domain_bus_and_slot(pci_domain_nr
3035 (pdev
->bus
), pdev
->bus
->number
,
3036 PCI_DEVFN(PCI_SLOT(pdev
->devfn
), val
));
3040 if (oth_pdev
->current_state
!= PCI_D3cold
) {
3041 pci_dev_put(oth_pdev
);
3044 pci_dev_put(oth_pdev
);
3049 static int qlcnic_attach_func(struct pci_dev
*pdev
)
3051 int err
, first_func
;
3052 struct qlcnic_adapter
*adapter
= pci_get_drvdata(pdev
);
3053 struct net_device
*netdev
= adapter
->netdev
;
3055 pdev
->error_state
= pci_channel_io_normal
;
3057 err
= pci_enable_device(pdev
);
3061 pci_set_power_state(pdev
, PCI_D0
);
3062 pci_set_master(pdev
);
3063 pci_restore_state(pdev
);
3065 first_func
= qlcnic_is_first_func(pdev
);
3067 if (qlcnic_api_lock(adapter
))
3070 if (adapter
->op_mode
!= QLCNIC_NON_PRIV_FUNC
&& first_func
) {
3071 adapter
->need_fw_reset
= 1;
3072 set_bit(__QLCNIC_START_FW
, &adapter
->state
);
3073 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
, QLCNIC_DEV_INITIALIZING
);
3074 QLCDB(adapter
, DRV
, "Restarting fw\n");
3076 qlcnic_api_unlock(adapter
);
3078 err
= adapter
->nic_ops
->start_firmware(adapter
);
3082 qlcnic_clr_drv_state(adapter
);
3083 qlcnic_setup_intr(adapter
);
3085 if (netif_running(netdev
)) {
3086 err
= qlcnic_attach(adapter
);
3088 qlcnic_clr_all_drv_state(adapter
, 1);
3089 clear_bit(__QLCNIC_AER
, &adapter
->state
);
3090 netif_device_attach(netdev
);
3094 err
= qlcnic_up(adapter
, netdev
);
3098 qlcnic_restore_indev_addr(netdev
, NETDEV_UP
);
3101 netif_device_attach(netdev
);
3105 static pci_ers_result_t
qlcnic_io_error_detected(struct pci_dev
*pdev
,
3106 pci_channel_state_t state
)
3108 struct qlcnic_adapter
*adapter
= pci_get_drvdata(pdev
);
3109 struct net_device
*netdev
= adapter
->netdev
;
3111 if (state
== pci_channel_io_perm_failure
)
3112 return PCI_ERS_RESULT_DISCONNECT
;
3114 if (state
== pci_channel_io_normal
)
3115 return PCI_ERS_RESULT_RECOVERED
;
3117 set_bit(__QLCNIC_AER
, &adapter
->state
);
3118 netif_device_detach(netdev
);
3120 cancel_delayed_work_sync(&adapter
->fw_work
);
3122 if (netif_running(netdev
))
3123 qlcnic_down(adapter
, netdev
);
3125 qlcnic_detach(adapter
);
3126 qlcnic_teardown_intr(adapter
);
3128 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
3130 pci_save_state(pdev
);
3131 pci_disable_device(pdev
);
3133 return PCI_ERS_RESULT_NEED_RESET
;
3136 static pci_ers_result_t
qlcnic_io_slot_reset(struct pci_dev
*pdev
)
3138 return qlcnic_attach_func(pdev
) ? PCI_ERS_RESULT_DISCONNECT
:
3139 PCI_ERS_RESULT_RECOVERED
;
3142 static void qlcnic_io_resume(struct pci_dev
*pdev
)
3144 struct qlcnic_adapter
*adapter
= pci_get_drvdata(pdev
);
3146 pci_cleanup_aer_uncorrect_error_status(pdev
);
3148 if (QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
) == QLCNIC_DEV_READY
&&
3149 test_and_clear_bit(__QLCNIC_AER
, &adapter
->state
))
3150 qlcnic_schedule_work(adapter
, qlcnic_fw_poll_work
,
3155 qlcnicvf_start_firmware(struct qlcnic_adapter
*adapter
)
3159 err
= qlcnic_can_start_firmware(adapter
);
3163 err
= qlcnic_check_npar_opertional(adapter
);
3167 err
= qlcnic_initialize_nic(adapter
);
3171 qlcnic_check_options(adapter
);
3173 err
= qlcnic_set_eswitch_port_config(adapter
);
3177 adapter
->need_fw_reset
= 0;
3183 qlcnicvf_config_bridged_mode(struct qlcnic_adapter
*adapter
, u32 enable
)
3189 qlcnicvf_config_led(struct qlcnic_adapter
*adapter
, u32 state
, u32 rate
)
3195 qlcnic_store_bridged_mode(struct device
*dev
,
3196 struct device_attribute
*attr
, const char *buf
, size_t len
)
3198 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3202 if (!(adapter
->capabilities
& QLCNIC_FW_CAPABILITY_BDG
))
3205 if (!test_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
3208 if (strict_strtoul(buf
, 2, &new))
3211 if (!adapter
->nic_ops
->config_bridged_mode(adapter
, !!new))
3219 qlcnic_show_bridged_mode(struct device
*dev
,
3220 struct device_attribute
*attr
, char *buf
)
3222 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3223 int bridged_mode
= 0;
3225 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_BDG
)
3226 bridged_mode
= !!(adapter
->flags
& QLCNIC_BRIDGE_ENABLED
);
3228 return sprintf(buf
, "%d\n", bridged_mode
);
3231 static struct device_attribute dev_attr_bridged_mode
= {
3232 .attr
= {.name
= "bridged_mode", .mode
= (S_IRUGO
| S_IWUSR
)},
3233 .show
= qlcnic_show_bridged_mode
,
3234 .store
= qlcnic_store_bridged_mode
,
3238 qlcnic_store_diag_mode(struct device
*dev
,
3239 struct device_attribute
*attr
, const char *buf
, size_t len
)
3241 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3244 if (strict_strtoul(buf
, 2, &new))
3247 if (!!new != !!(adapter
->flags
& QLCNIC_DIAG_ENABLED
))
3248 adapter
->flags
^= QLCNIC_DIAG_ENABLED
;
3254 qlcnic_show_diag_mode(struct device
*dev
,
3255 struct device_attribute
*attr
, char *buf
)
3257 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3259 return sprintf(buf
, "%d\n",
3260 !!(adapter
->flags
& QLCNIC_DIAG_ENABLED
));
3263 static struct device_attribute dev_attr_diag_mode
= {
3264 .attr
= {.name
= "diag_mode", .mode
= (S_IRUGO
| S_IWUSR
)},
3265 .show
= qlcnic_show_diag_mode
,
3266 .store
= qlcnic_store_diag_mode
,
3270 qlcnic_sysfs_validate_crb(struct qlcnic_adapter
*adapter
,
3271 loff_t offset
, size_t size
)
3273 size_t crb_size
= 4;
3275 if (!(adapter
->flags
& QLCNIC_DIAG_ENABLED
))
3278 if (offset
< QLCNIC_PCI_CRBSPACE
) {
3279 if (ADDR_IN_RANGE(offset
, QLCNIC_PCI_CAMQM
,
3280 QLCNIC_PCI_CAMQM_END
))
3286 if ((size
!= crb_size
) || (offset
& (crb_size
-1)))
3293 qlcnic_sysfs_read_crb(struct file
*filp
, struct kobject
*kobj
,
3294 struct bin_attribute
*attr
,
3295 char *buf
, loff_t offset
, size_t size
)
3297 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3298 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3303 ret
= qlcnic_sysfs_validate_crb(adapter
, offset
, size
);
3307 if (ADDR_IN_RANGE(offset
, QLCNIC_PCI_CAMQM
, QLCNIC_PCI_CAMQM_END
)) {
3308 qlcnic_pci_camqm_read_2M(adapter
, offset
, &qmdata
);
3309 memcpy(buf
, &qmdata
, size
);
3311 data
= QLCRD32(adapter
, offset
);
3312 memcpy(buf
, &data
, size
);
3318 qlcnic_sysfs_write_crb(struct file
*filp
, struct kobject
*kobj
,
3319 struct bin_attribute
*attr
,
3320 char *buf
, loff_t offset
, size_t size
)
3322 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3323 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3328 ret
= qlcnic_sysfs_validate_crb(adapter
, offset
, size
);
3332 if (ADDR_IN_RANGE(offset
, QLCNIC_PCI_CAMQM
, QLCNIC_PCI_CAMQM_END
)) {
3333 memcpy(&qmdata
, buf
, size
);
3334 qlcnic_pci_camqm_write_2M(adapter
, offset
, qmdata
);
3336 memcpy(&data
, buf
, size
);
3337 QLCWR32(adapter
, offset
, data
);
3343 qlcnic_sysfs_validate_mem(struct qlcnic_adapter
*adapter
,
3344 loff_t offset
, size_t size
)
3346 if (!(adapter
->flags
& QLCNIC_DIAG_ENABLED
))
3349 if ((size
!= 8) || (offset
& 0x7))
3356 qlcnic_sysfs_read_mem(struct file
*filp
, struct kobject
*kobj
,
3357 struct bin_attribute
*attr
,
3358 char *buf
, loff_t offset
, size_t size
)
3360 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3361 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3365 ret
= qlcnic_sysfs_validate_mem(adapter
, offset
, size
);
3369 if (qlcnic_pci_mem_read_2M(adapter
, offset
, &data
))
3372 memcpy(buf
, &data
, size
);
3378 qlcnic_sysfs_write_mem(struct file
*filp
, struct kobject
*kobj
,
3379 struct bin_attribute
*attr
,
3380 char *buf
, loff_t offset
, size_t size
)
3382 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3383 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3387 ret
= qlcnic_sysfs_validate_mem(adapter
, offset
, size
);
3391 memcpy(&data
, buf
, size
);
3393 if (qlcnic_pci_mem_write_2M(adapter
, offset
, data
))
3400 static struct bin_attribute bin_attr_crb
= {
3401 .attr
= {.name
= "crb", .mode
= (S_IRUGO
| S_IWUSR
)},
3403 .read
= qlcnic_sysfs_read_crb
,
3404 .write
= qlcnic_sysfs_write_crb
,
3407 static struct bin_attribute bin_attr_mem
= {
3408 .attr
= {.name
= "mem", .mode
= (S_IRUGO
| S_IWUSR
)},
3410 .read
= qlcnic_sysfs_read_mem
,
3411 .write
= qlcnic_sysfs_write_mem
,
3415 validate_pm_config(struct qlcnic_adapter
*adapter
,
3416 struct qlcnic_pm_func_cfg
*pm_cfg
, int count
)
3419 u8 src_pci_func
, s_esw_id
, d_esw_id
;
3423 for (i
= 0; i
< count
; i
++) {
3424 src_pci_func
= pm_cfg
[i
].pci_func
;
3425 dest_pci_func
= pm_cfg
[i
].dest_npar
;
3426 if (src_pci_func
>= QLCNIC_MAX_PCI_FUNC
3427 || dest_pci_func
>= QLCNIC_MAX_PCI_FUNC
)
3428 return QL_STATUS_INVALID_PARAM
;
3430 if (adapter
->npars
[src_pci_func
].type
!= QLCNIC_TYPE_NIC
)
3431 return QL_STATUS_INVALID_PARAM
;
3433 if (adapter
->npars
[dest_pci_func
].type
!= QLCNIC_TYPE_NIC
)
3434 return QL_STATUS_INVALID_PARAM
;
3436 s_esw_id
= adapter
->npars
[src_pci_func
].phy_port
;
3437 d_esw_id
= adapter
->npars
[dest_pci_func
].phy_port
;
3439 if (s_esw_id
!= d_esw_id
)
3440 return QL_STATUS_INVALID_PARAM
;
3448 qlcnic_sysfs_write_pm_config(struct file
*filp
, struct kobject
*kobj
,
3449 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3451 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3452 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3453 struct qlcnic_pm_func_cfg
*pm_cfg
;
3454 u32 id
, action
, pci_func
;
3455 int count
, rem
, i
, ret
;
3457 count
= size
/ sizeof(struct qlcnic_pm_func_cfg
);
3458 rem
= size
% sizeof(struct qlcnic_pm_func_cfg
);
3460 return QL_STATUS_INVALID_PARAM
;
3462 pm_cfg
= (struct qlcnic_pm_func_cfg
*) buf
;
3464 ret
= validate_pm_config(adapter
, pm_cfg
, count
);
3467 for (i
= 0; i
< count
; i
++) {
3468 pci_func
= pm_cfg
[i
].pci_func
;
3469 action
= !!pm_cfg
[i
].action
;
3470 id
= adapter
->npars
[pci_func
].phy_port
;
3471 ret
= qlcnic_config_port_mirroring(adapter
, id
,
3477 for (i
= 0; i
< count
; i
++) {
3478 pci_func
= pm_cfg
[i
].pci_func
;
3479 id
= adapter
->npars
[pci_func
].phy_port
;
3480 adapter
->npars
[pci_func
].enable_pm
= !!pm_cfg
[i
].action
;
3481 adapter
->npars
[pci_func
].dest_npar
= id
;
3487 qlcnic_sysfs_read_pm_config(struct file
*filp
, struct kobject
*kobj
,
3488 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3490 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3491 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3492 struct qlcnic_pm_func_cfg pm_cfg
[QLCNIC_MAX_PCI_FUNC
];
3495 if (size
!= sizeof(pm_cfg
))
3496 return QL_STATUS_INVALID_PARAM
;
3498 for (i
= 0; i
< QLCNIC_MAX_PCI_FUNC
; i
++) {
3499 if (adapter
->npars
[i
].type
!= QLCNIC_TYPE_NIC
)
3501 pm_cfg
[i
].action
= adapter
->npars
[i
].enable_pm
;
3502 pm_cfg
[i
].dest_npar
= 0;
3503 pm_cfg
[i
].pci_func
= i
;
3505 memcpy(buf
, &pm_cfg
, size
);
3511 validate_esw_config(struct qlcnic_adapter
*adapter
,
3512 struct qlcnic_esw_func_cfg
*esw_cfg
, int count
)
3518 op_mode
= readl(adapter
->ahw
.pci_base0
+ QLCNIC_DRV_OP_MODE
);
3520 for (i
= 0; i
< count
; i
++) {
3521 pci_func
= esw_cfg
[i
].pci_func
;
3522 if (pci_func
>= QLCNIC_MAX_PCI_FUNC
)
3523 return QL_STATUS_INVALID_PARAM
;
3525 if (adapter
->op_mode
== QLCNIC_MGMT_FUNC
)
3526 if (adapter
->npars
[pci_func
].type
!= QLCNIC_TYPE_NIC
)
3527 return QL_STATUS_INVALID_PARAM
;
3529 switch (esw_cfg
[i
].op_mode
) {
3530 case QLCNIC_PORT_DEFAULTS
:
3531 if (QLC_DEV_GET_DRV(op_mode
, pci_func
) !=
3532 QLCNIC_NON_PRIV_FUNC
) {
3533 if (esw_cfg
[i
].mac_anti_spoof
!= 0)
3534 return QL_STATUS_INVALID_PARAM
;
3535 if (esw_cfg
[i
].mac_override
!= 1)
3536 return QL_STATUS_INVALID_PARAM
;
3537 if (esw_cfg
[i
].promisc_mode
!= 1)
3538 return QL_STATUS_INVALID_PARAM
;
3541 case QLCNIC_ADD_VLAN
:
3542 if (!IS_VALID_VLAN(esw_cfg
[i
].vlan_id
))
3543 return QL_STATUS_INVALID_PARAM
;
3544 if (!esw_cfg
[i
].op_type
)
3545 return QL_STATUS_INVALID_PARAM
;
3547 case QLCNIC_DEL_VLAN
:
3548 if (!esw_cfg
[i
].op_type
)
3549 return QL_STATUS_INVALID_PARAM
;
3552 return QL_STATUS_INVALID_PARAM
;
3559 qlcnic_sysfs_write_esw_config(struct file
*file
, struct kobject
*kobj
,
3560 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3562 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3563 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3564 struct qlcnic_esw_func_cfg
*esw_cfg
;
3565 struct qlcnic_npar_info
*npar
;
3566 int count
, rem
, i
, ret
;
3567 u8 pci_func
, op_mode
= 0;
3569 count
= size
/ sizeof(struct qlcnic_esw_func_cfg
);
3570 rem
= size
% sizeof(struct qlcnic_esw_func_cfg
);
3572 return QL_STATUS_INVALID_PARAM
;
3574 esw_cfg
= (struct qlcnic_esw_func_cfg
*) buf
;
3575 ret
= validate_esw_config(adapter
, esw_cfg
, count
);
3579 for (i
= 0; i
< count
; i
++) {
3580 if (adapter
->op_mode
== QLCNIC_MGMT_FUNC
)
3581 if (qlcnic_config_switch_port(adapter
, &esw_cfg
[i
]))
3582 return QL_STATUS_INVALID_PARAM
;
3584 if (adapter
->ahw
.pci_func
!= esw_cfg
[i
].pci_func
)
3587 op_mode
= esw_cfg
[i
].op_mode
;
3588 qlcnic_get_eswitch_port_config(adapter
, &esw_cfg
[i
]);
3589 esw_cfg
[i
].op_mode
= op_mode
;
3590 esw_cfg
[i
].pci_func
= adapter
->ahw
.pci_func
;
3592 switch (esw_cfg
[i
].op_mode
) {
3593 case QLCNIC_PORT_DEFAULTS
:
3594 qlcnic_set_eswitch_port_features(adapter
, &esw_cfg
[i
]);
3596 case QLCNIC_ADD_VLAN
:
3597 qlcnic_set_vlan_config(adapter
, &esw_cfg
[i
]);
3599 case QLCNIC_DEL_VLAN
:
3600 esw_cfg
[i
].vlan_id
= 0;
3601 qlcnic_set_vlan_config(adapter
, &esw_cfg
[i
]);
3606 if (adapter
->op_mode
!= QLCNIC_MGMT_FUNC
)
3609 for (i
= 0; i
< count
; i
++) {
3610 pci_func
= esw_cfg
[i
].pci_func
;
3611 npar
= &adapter
->npars
[pci_func
];
3612 switch (esw_cfg
[i
].op_mode
) {
3613 case QLCNIC_PORT_DEFAULTS
:
3614 npar
->promisc_mode
= esw_cfg
[i
].promisc_mode
;
3615 npar
->mac_override
= esw_cfg
[i
].mac_override
;
3616 npar
->offload_flags
= esw_cfg
[i
].offload_flags
;
3617 npar
->mac_anti_spoof
= esw_cfg
[i
].mac_anti_spoof
;
3618 npar
->discard_tagged
= esw_cfg
[i
].discard_tagged
;
3620 case QLCNIC_ADD_VLAN
:
3621 npar
->pvid
= esw_cfg
[i
].vlan_id
;
3623 case QLCNIC_DEL_VLAN
:
3633 qlcnic_sysfs_read_esw_config(struct file
*file
, struct kobject
*kobj
,
3634 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3636 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3637 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3638 struct qlcnic_esw_func_cfg esw_cfg
[QLCNIC_MAX_PCI_FUNC
];
3641 if (size
!= sizeof(esw_cfg
))
3642 return QL_STATUS_INVALID_PARAM
;
3644 for (i
= 0; i
< QLCNIC_MAX_PCI_FUNC
; i
++) {
3645 if (adapter
->npars
[i
].type
!= QLCNIC_TYPE_NIC
)
3647 esw_cfg
[i
].pci_func
= i
;
3648 if (qlcnic_get_eswitch_port_config(adapter
, &esw_cfg
[i
]))
3649 return QL_STATUS_INVALID_PARAM
;
3651 memcpy(buf
, &esw_cfg
, size
);
3657 validate_npar_config(struct qlcnic_adapter
*adapter
,
3658 struct qlcnic_npar_func_cfg
*np_cfg
, int count
)
3662 for (i
= 0; i
< count
; i
++) {
3663 pci_func
= np_cfg
[i
].pci_func
;
3664 if (pci_func
>= QLCNIC_MAX_PCI_FUNC
)
3665 return QL_STATUS_INVALID_PARAM
;
3667 if (adapter
->npars
[pci_func
].type
!= QLCNIC_TYPE_NIC
)
3668 return QL_STATUS_INVALID_PARAM
;
3670 if (!IS_VALID_BW(np_cfg
[i
].min_bw
) ||
3671 !IS_VALID_BW(np_cfg
[i
].max_bw
))
3672 return QL_STATUS_INVALID_PARAM
;
3678 qlcnic_sysfs_write_npar_config(struct file
*file
, struct kobject
*kobj
,
3679 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3681 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3682 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3683 struct qlcnic_info nic_info
;
3684 struct qlcnic_npar_func_cfg
*np_cfg
;
3685 int i
, count
, rem
, ret
;
3688 count
= size
/ sizeof(struct qlcnic_npar_func_cfg
);
3689 rem
= size
% sizeof(struct qlcnic_npar_func_cfg
);
3691 return QL_STATUS_INVALID_PARAM
;
3693 np_cfg
= (struct qlcnic_npar_func_cfg
*) buf
;
3694 ret
= validate_npar_config(adapter
, np_cfg
, count
);
3698 for (i
= 0; i
< count
; i
++) {
3699 pci_func
= np_cfg
[i
].pci_func
;
3700 ret
= qlcnic_get_nic_info(adapter
, &nic_info
, pci_func
);
3703 nic_info
.pci_func
= pci_func
;
3704 nic_info
.min_tx_bw
= np_cfg
[i
].min_bw
;
3705 nic_info
.max_tx_bw
= np_cfg
[i
].max_bw
;
3706 ret
= qlcnic_set_nic_info(adapter
, &nic_info
);
3709 adapter
->npars
[i
].min_bw
= nic_info
.min_tx_bw
;
3710 adapter
->npars
[i
].max_bw
= nic_info
.max_tx_bw
;
3717 qlcnic_sysfs_read_npar_config(struct file
*file
, struct kobject
*kobj
,
3718 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3720 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3721 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3722 struct qlcnic_info nic_info
;
3723 struct qlcnic_npar_func_cfg np_cfg
[QLCNIC_MAX_PCI_FUNC
];
3726 if (size
!= sizeof(np_cfg
))
3727 return QL_STATUS_INVALID_PARAM
;
3729 for (i
= 0; i
< QLCNIC_MAX_PCI_FUNC
; i
++) {
3730 if (adapter
->npars
[i
].type
!= QLCNIC_TYPE_NIC
)
3732 ret
= qlcnic_get_nic_info(adapter
, &nic_info
, i
);
3736 np_cfg
[i
].pci_func
= i
;
3737 np_cfg
[i
].op_mode
= (u8
)nic_info
.op_mode
;
3738 np_cfg
[i
].port_num
= nic_info
.phys_port
;
3739 np_cfg
[i
].fw_capab
= nic_info
.capabilities
;
3740 np_cfg
[i
].min_bw
= nic_info
.min_tx_bw
;
3741 np_cfg
[i
].max_bw
= nic_info
.max_tx_bw
;
3742 np_cfg
[i
].max_tx_queues
= nic_info
.max_tx_ques
;
3743 np_cfg
[i
].max_rx_queues
= nic_info
.max_rx_ques
;
3745 memcpy(buf
, &np_cfg
, size
);
3750 qlcnic_sysfs_get_port_stats(struct file
*file
, struct kobject
*kobj
,
3751 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3753 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3754 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3755 struct qlcnic_esw_statistics port_stats
;
3758 if (size
!= sizeof(struct qlcnic_esw_statistics
))
3759 return QL_STATUS_INVALID_PARAM
;
3761 if (offset
>= QLCNIC_MAX_PCI_FUNC
)
3762 return QL_STATUS_INVALID_PARAM
;
3764 memset(&port_stats
, 0, size
);
3765 ret
= qlcnic_get_port_stats(adapter
, offset
, QLCNIC_QUERY_RX_COUNTER
,
3770 ret
= qlcnic_get_port_stats(adapter
, offset
, QLCNIC_QUERY_TX_COUNTER
,
3775 memcpy(buf
, &port_stats
, size
);
3780 qlcnic_sysfs_get_esw_stats(struct file
*file
, struct kobject
*kobj
,
3781 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3783 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3784 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3785 struct qlcnic_esw_statistics esw_stats
;
3788 if (size
!= sizeof(struct qlcnic_esw_statistics
))
3789 return QL_STATUS_INVALID_PARAM
;
3791 if (offset
>= QLCNIC_NIU_MAX_XG_PORTS
)
3792 return QL_STATUS_INVALID_PARAM
;
3794 memset(&esw_stats
, 0, size
);
3795 ret
= qlcnic_get_eswitch_stats(adapter
, offset
, QLCNIC_QUERY_RX_COUNTER
,
3800 ret
= qlcnic_get_eswitch_stats(adapter
, offset
, QLCNIC_QUERY_TX_COUNTER
,
3805 memcpy(buf
, &esw_stats
, size
);
3810 qlcnic_sysfs_clear_esw_stats(struct file
*file
, struct kobject
*kobj
,
3811 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3813 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3814 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3817 if (offset
>= QLCNIC_NIU_MAX_XG_PORTS
)
3818 return QL_STATUS_INVALID_PARAM
;
3820 ret
= qlcnic_clear_esw_stats(adapter
, QLCNIC_STATS_ESWITCH
, offset
,
3821 QLCNIC_QUERY_RX_COUNTER
);
3825 ret
= qlcnic_clear_esw_stats(adapter
, QLCNIC_STATS_ESWITCH
, offset
,
3826 QLCNIC_QUERY_TX_COUNTER
);
3834 qlcnic_sysfs_clear_port_stats(struct file
*file
, struct kobject
*kobj
,
3835 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3838 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3839 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3842 if (offset
>= QLCNIC_MAX_PCI_FUNC
)
3843 return QL_STATUS_INVALID_PARAM
;
3845 ret
= qlcnic_clear_esw_stats(adapter
, QLCNIC_STATS_PORT
, offset
,
3846 QLCNIC_QUERY_RX_COUNTER
);
3850 ret
= qlcnic_clear_esw_stats(adapter
, QLCNIC_STATS_PORT
, offset
,
3851 QLCNIC_QUERY_TX_COUNTER
);
3859 qlcnic_sysfs_read_pci_config(struct file
*file
, struct kobject
*kobj
,
3860 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3862 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3863 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3864 struct qlcnic_pci_func_cfg pci_cfg
[QLCNIC_MAX_PCI_FUNC
];
3865 struct qlcnic_pci_info
*pci_info
;
3868 if (size
!= sizeof(pci_cfg
))
3869 return QL_STATUS_INVALID_PARAM
;
3871 pci_info
= kcalloc(QLCNIC_MAX_PCI_FUNC
, sizeof(*pci_info
), GFP_KERNEL
);
3875 ret
= qlcnic_get_pci_info(adapter
, pci_info
);
3881 for (i
= 0; i
< QLCNIC_MAX_PCI_FUNC
; i
++) {
3882 pci_cfg
[i
].pci_func
= pci_info
[i
].id
;
3883 pci_cfg
[i
].func_type
= pci_info
[i
].type
;
3884 pci_cfg
[i
].port_num
= pci_info
[i
].default_port
;
3885 pci_cfg
[i
].min_bw
= pci_info
[i
].tx_min_bw
;
3886 pci_cfg
[i
].max_bw
= pci_info
[i
].tx_max_bw
;
3887 memcpy(&pci_cfg
[i
].def_mac_addr
, &pci_info
[i
].mac
, ETH_ALEN
);
3889 memcpy(buf
, &pci_cfg
, size
);
3893 static struct bin_attribute bin_attr_npar_config
= {
3894 .attr
= {.name
= "npar_config", .mode
= (S_IRUGO
| S_IWUSR
)},
3896 .read
= qlcnic_sysfs_read_npar_config
,
3897 .write
= qlcnic_sysfs_write_npar_config
,
3900 static struct bin_attribute bin_attr_pci_config
= {
3901 .attr
= {.name
= "pci_config", .mode
= (S_IRUGO
| S_IWUSR
)},
3903 .read
= qlcnic_sysfs_read_pci_config
,
3907 static struct bin_attribute bin_attr_port_stats
= {
3908 .attr
= {.name
= "port_stats", .mode
= (S_IRUGO
| S_IWUSR
)},
3910 .read
= qlcnic_sysfs_get_port_stats
,
3911 .write
= qlcnic_sysfs_clear_port_stats
,
3914 static struct bin_attribute bin_attr_esw_stats
= {
3915 .attr
= {.name
= "esw_stats", .mode
= (S_IRUGO
| S_IWUSR
)},
3917 .read
= qlcnic_sysfs_get_esw_stats
,
3918 .write
= qlcnic_sysfs_clear_esw_stats
,
3921 static struct bin_attribute bin_attr_esw_config
= {
3922 .attr
= {.name
= "esw_config", .mode
= (S_IRUGO
| S_IWUSR
)},
3924 .read
= qlcnic_sysfs_read_esw_config
,
3925 .write
= qlcnic_sysfs_write_esw_config
,
3928 static struct bin_attribute bin_attr_pm_config
= {
3929 .attr
= {.name
= "pm_config", .mode
= (S_IRUGO
| S_IWUSR
)},
3931 .read
= qlcnic_sysfs_read_pm_config
,
3932 .write
= qlcnic_sysfs_write_pm_config
,
3936 qlcnic_create_sysfs_entries(struct qlcnic_adapter
*adapter
)
3938 struct device
*dev
= &adapter
->pdev
->dev
;
3940 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_BDG
)
3941 if (device_create_file(dev
, &dev_attr_bridged_mode
))
3943 "failed to create bridged_mode sysfs entry\n");
3947 qlcnic_remove_sysfs_entries(struct qlcnic_adapter
*adapter
)
3949 struct device
*dev
= &adapter
->pdev
->dev
;
3951 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_BDG
)
3952 device_remove_file(dev
, &dev_attr_bridged_mode
);
3956 qlcnic_create_diag_entries(struct qlcnic_adapter
*adapter
)
3958 struct device
*dev
= &adapter
->pdev
->dev
;
3960 if (device_create_bin_file(dev
, &bin_attr_port_stats
))
3961 dev_info(dev
, "failed to create port stats sysfs entry");
3963 if (adapter
->op_mode
== QLCNIC_NON_PRIV_FUNC
)
3965 if (device_create_file(dev
, &dev_attr_diag_mode
))
3966 dev_info(dev
, "failed to create diag_mode sysfs entry\n");
3967 if (device_create_bin_file(dev
, &bin_attr_crb
))
3968 dev_info(dev
, "failed to create crb sysfs entry\n");
3969 if (device_create_bin_file(dev
, &bin_attr_mem
))
3970 dev_info(dev
, "failed to create mem sysfs entry\n");
3971 if (!(adapter
->flags
& QLCNIC_ESWITCH_ENABLED
))
3973 if (device_create_bin_file(dev
, &bin_attr_esw_config
))
3974 dev_info(dev
, "failed to create esw config sysfs entry");
3975 if (adapter
->op_mode
!= QLCNIC_MGMT_FUNC
)
3977 if (device_create_bin_file(dev
, &bin_attr_pci_config
))
3978 dev_info(dev
, "failed to create pci config sysfs entry");
3979 if (device_create_bin_file(dev
, &bin_attr_npar_config
))
3980 dev_info(dev
, "failed to create npar config sysfs entry");
3981 if (device_create_bin_file(dev
, &bin_attr_pm_config
))
3982 dev_info(dev
, "failed to create pm config sysfs entry");
3983 if (device_create_bin_file(dev
, &bin_attr_esw_stats
))
3984 dev_info(dev
, "failed to create eswitch stats sysfs entry");
3988 qlcnic_remove_diag_entries(struct qlcnic_adapter
*adapter
)
3990 struct device
*dev
= &adapter
->pdev
->dev
;
3992 device_remove_bin_file(dev
, &bin_attr_port_stats
);
3994 if (adapter
->op_mode
== QLCNIC_NON_PRIV_FUNC
)
3996 device_remove_file(dev
, &dev_attr_diag_mode
);
3997 device_remove_bin_file(dev
, &bin_attr_crb
);
3998 device_remove_bin_file(dev
, &bin_attr_mem
);
3999 if (!(adapter
->flags
& QLCNIC_ESWITCH_ENABLED
))
4001 device_remove_bin_file(dev
, &bin_attr_esw_config
);
4002 if (adapter
->op_mode
!= QLCNIC_MGMT_FUNC
)
4004 device_remove_bin_file(dev
, &bin_attr_pci_config
);
4005 device_remove_bin_file(dev
, &bin_attr_npar_config
);
4006 device_remove_bin_file(dev
, &bin_attr_pm_config
);
4007 device_remove_bin_file(dev
, &bin_attr_esw_stats
);
4012 #define is_qlcnic_netdev(dev) (dev->netdev_ops == &qlcnic_netdev_ops)
4015 qlcnic_config_indev_addr(struct qlcnic_adapter
*adapter
,
4016 struct net_device
*dev
, unsigned long event
)
4018 struct in_device
*indev
;
4020 indev
= in_dev_get(dev
);
4027 qlcnic_config_ipaddr(adapter
,
4028 ifa
->ifa_address
, QLCNIC_IP_UP
);
4031 qlcnic_config_ipaddr(adapter
,
4032 ifa
->ifa_address
, QLCNIC_IP_DOWN
);
4037 } endfor_ifa(indev
);
4043 qlcnic_restore_indev_addr(struct net_device
*netdev
, unsigned long event
)
4045 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
4046 struct net_device
*dev
;
4049 qlcnic_config_indev_addr(adapter
, netdev
, event
);
4051 if (!adapter
->vlgrp
)
4054 for (vid
= 0; vid
< VLAN_N_VID
; vid
++) {
4055 dev
= vlan_group_get_device(adapter
->vlgrp
, vid
);
4059 qlcnic_config_indev_addr(adapter
, dev
, event
);
4063 static int qlcnic_netdev_event(struct notifier_block
*this,
4064 unsigned long event
, void *ptr
)
4066 struct qlcnic_adapter
*adapter
;
4067 struct net_device
*dev
= (struct net_device
*)ptr
;
4073 if (dev
->priv_flags
& IFF_802_1Q_VLAN
) {
4074 dev
= vlan_dev_real_dev(dev
);
4078 if (!is_qlcnic_netdev(dev
))
4081 adapter
= netdev_priv(dev
);
4086 if (!test_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
4089 qlcnic_config_indev_addr(adapter
, dev
, event
);
4095 qlcnic_inetaddr_event(struct notifier_block
*this,
4096 unsigned long event
, void *ptr
)
4098 struct qlcnic_adapter
*adapter
;
4099 struct net_device
*dev
;
4101 struct in_ifaddr
*ifa
= (struct in_ifaddr
*)ptr
;
4103 dev
= ifa
->ifa_dev
? ifa
->ifa_dev
->dev
: NULL
;
4109 if (dev
->priv_flags
& IFF_802_1Q_VLAN
) {
4110 dev
= vlan_dev_real_dev(dev
);
4114 if (!is_qlcnic_netdev(dev
))
4117 adapter
= netdev_priv(dev
);
4122 if (!test_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
4127 qlcnic_config_ipaddr(adapter
, ifa
->ifa_address
, QLCNIC_IP_UP
);
4130 qlcnic_config_ipaddr(adapter
, ifa
->ifa_address
, QLCNIC_IP_DOWN
);
4140 static struct notifier_block qlcnic_netdev_cb
= {
4141 .notifier_call
= qlcnic_netdev_event
,
4144 static struct notifier_block qlcnic_inetaddr_cb
= {
4145 .notifier_call
= qlcnic_inetaddr_event
,
4149 qlcnic_restore_indev_addr(struct net_device
*dev
, unsigned long event
)
4152 static struct pci_error_handlers qlcnic_err_handler
= {
4153 .error_detected
= qlcnic_io_error_detected
,
4154 .slot_reset
= qlcnic_io_slot_reset
,
4155 .resume
= qlcnic_io_resume
,
4158 static struct pci_driver qlcnic_driver
= {
4159 .name
= qlcnic_driver_name
,
4160 .id_table
= qlcnic_pci_tbl
,
4161 .probe
= qlcnic_probe
,
4162 .remove
= __devexit_p(qlcnic_remove
),
4164 .suspend
= qlcnic_suspend
,
4165 .resume
= qlcnic_resume
,
4167 .shutdown
= qlcnic_shutdown
,
4168 .err_handler
= &qlcnic_err_handler
4172 static int __init
qlcnic_init_module(void)
4176 printk(KERN_INFO
"%s\n", qlcnic_driver_string
);
4178 qlcnic_wq
= create_singlethread_workqueue("qlcnic");
4179 if (qlcnic_wq
== NULL
) {
4180 printk(KERN_ERR
"qlcnic: cannot create workqueue\n");
4185 register_netdevice_notifier(&qlcnic_netdev_cb
);
4186 register_inetaddr_notifier(&qlcnic_inetaddr_cb
);
4189 ret
= pci_register_driver(&qlcnic_driver
);
4192 unregister_inetaddr_notifier(&qlcnic_inetaddr_cb
);
4193 unregister_netdevice_notifier(&qlcnic_netdev_cb
);
4195 destroy_workqueue(qlcnic_wq
);
4201 module_init(qlcnic_init_module
);
4203 static void __exit
qlcnic_exit_module(void)
4206 pci_unregister_driver(&qlcnic_driver
);
4209 unregister_inetaddr_notifier(&qlcnic_inetaddr_cb
);
4210 unregister_netdevice_notifier(&qlcnic_netdev_cb
);
4212 destroy_workqueue(qlcnic_wq
);
4215 module_exit(qlcnic_exit_module
);