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
= AUTO_FW_RESET_ENABLED
;
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
;
2105 int frag_count
, no_of_desc
;
2106 u32 num_txd
= tx_ring
->num_desc
;
2108 if (!test_bit(__QLCNIC_DEV_UP
, &adapter
->state
)) {
2109 netif_stop_queue(netdev
);
2110 return NETDEV_TX_BUSY
;
2113 if (adapter
->flags
& QLCNIC_MACSPOOF
) {
2114 phdr
= (struct ethhdr
*)skb
->data
;
2115 if (compare_ether_addr(phdr
->h_source
,
2120 frag_count
= skb_shinfo(skb
)->nr_frags
+ 1;
2122 /* 4 fragments per cmd des */
2123 no_of_desc
= (frag_count
+ 3) >> 2;
2125 if (unlikely(qlcnic_tx_avail(tx_ring
) <= TX_STOP_THRESH
)) {
2126 netif_stop_queue(netdev
);
2128 if (qlcnic_tx_avail(tx_ring
) > TX_STOP_THRESH
)
2129 netif_start_queue(netdev
);
2131 adapter
->stats
.xmit_off
++;
2132 return NETDEV_TX_BUSY
;
2136 producer
= tx_ring
->producer
;
2137 pbuf
= &tx_ring
->cmd_buf_arr
[producer
];
2139 pdev
= adapter
->pdev
;
2141 first_desc
= hwdesc
= &tx_ring
->desc_head
[producer
];
2142 qlcnic_clear_cmddesc((u64
*)hwdesc
);
2144 if (qlcnic_check_tx_tagging(adapter
, skb
, first_desc
))
2147 if (qlcnic_map_tx_skb(pdev
, skb
, pbuf
)) {
2148 adapter
->stats
.tx_dma_map_error
++;
2153 pbuf
->frag_count
= frag_count
;
2155 qlcnic_set_tx_frags_len(first_desc
, frag_count
, skb
->len
);
2156 qlcnic_set_tx_port(first_desc
, adapter
->portnum
);
2158 for (i
= 0; i
< frag_count
; i
++) {
2162 if ((k
== 0) && (i
> 0)) {
2163 /* move to next desc.*/
2164 producer
= get_next_index(producer
, num_txd
);
2165 hwdesc
= &tx_ring
->desc_head
[producer
];
2166 qlcnic_clear_cmddesc((u64
*)hwdesc
);
2167 tx_ring
->cmd_buf_arr
[producer
].skb
= NULL
;
2170 buffrag
= &pbuf
->frag_array
[i
];
2172 hwdesc
->buffer_length
[k
] = cpu_to_le16(buffrag
->length
);
2175 hwdesc
->addr_buffer1
= cpu_to_le64(buffrag
->dma
);
2178 hwdesc
->addr_buffer2
= cpu_to_le64(buffrag
->dma
);
2181 hwdesc
->addr_buffer3
= cpu_to_le64(buffrag
->dma
);
2184 hwdesc
->addr_buffer4
= cpu_to_le64(buffrag
->dma
);
2189 tx_ring
->producer
= get_next_index(producer
, num_txd
);
2191 qlcnic_tso_check(netdev
, tx_ring
, first_desc
, skb
);
2193 if (qlcnic_mac_learn
)
2194 qlcnic_send_filter(adapter
, tx_ring
, first_desc
, skb
);
2196 qlcnic_update_cmd_producer(adapter
, tx_ring
);
2198 adapter
->stats
.txbytes
+= skb
->len
;
2199 adapter
->stats
.xmitcalled
++;
2201 return NETDEV_TX_OK
;
2204 adapter
->stats
.txdropped
++;
2205 dev_kfree_skb_any(skb
);
2206 return NETDEV_TX_OK
;
2209 static int qlcnic_check_temp(struct qlcnic_adapter
*adapter
)
2211 struct net_device
*netdev
= adapter
->netdev
;
2212 u32 temp
, temp_state
, temp_val
;
2215 temp
= QLCRD32(adapter
, CRB_TEMP_STATE
);
2217 temp_state
= qlcnic_get_temp_state(temp
);
2218 temp_val
= qlcnic_get_temp_val(temp
);
2220 if (temp_state
== QLCNIC_TEMP_PANIC
) {
2221 dev_err(&netdev
->dev
,
2222 "Device temperature %d degrees C exceeds"
2223 " maximum allowed. Hardware has been shut down.\n",
2226 } else if (temp_state
== QLCNIC_TEMP_WARN
) {
2227 if (adapter
->temp
== QLCNIC_TEMP_NORMAL
) {
2228 dev_err(&netdev
->dev
,
2229 "Device temperature %d degrees C "
2230 "exceeds operating range."
2231 " Immediate action needed.\n",
2235 if (adapter
->temp
== QLCNIC_TEMP_WARN
) {
2236 dev_info(&netdev
->dev
,
2237 "Device temperature is now %d degrees C"
2238 " in normal range.\n", temp_val
);
2241 adapter
->temp
= temp_state
;
2245 void qlcnic_advert_link_change(struct qlcnic_adapter
*adapter
, int linkup
)
2247 struct net_device
*netdev
= adapter
->netdev
;
2249 if (adapter
->ahw
.linkup
&& !linkup
) {
2250 netdev_info(netdev
, "NIC Link is down\n");
2251 adapter
->ahw
.linkup
= 0;
2252 if (netif_running(netdev
)) {
2253 netif_carrier_off(netdev
);
2254 netif_stop_queue(netdev
);
2256 } else if (!adapter
->ahw
.linkup
&& linkup
) {
2257 netdev_info(netdev
, "NIC Link is up\n");
2258 adapter
->ahw
.linkup
= 1;
2259 if (netif_running(netdev
)) {
2260 netif_carrier_on(netdev
);
2261 netif_wake_queue(netdev
);
2266 static void qlcnic_tx_timeout(struct net_device
*netdev
)
2268 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
2270 if (test_bit(__QLCNIC_RESETTING
, &adapter
->state
))
2273 dev_err(&netdev
->dev
, "transmit timeout, resetting.\n");
2275 if (++adapter
->tx_timeo_cnt
>= QLCNIC_MAX_TX_TIMEOUTS
)
2276 adapter
->need_fw_reset
= 1;
2278 adapter
->reset_context
= 1;
2281 static struct net_device_stats
*qlcnic_get_stats(struct net_device
*netdev
)
2283 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
2284 struct net_device_stats
*stats
= &netdev
->stats
;
2286 stats
->rx_packets
= adapter
->stats
.rx_pkts
+ adapter
->stats
.lro_pkts
;
2287 stats
->tx_packets
= adapter
->stats
.xmitfinished
;
2288 stats
->rx_bytes
= adapter
->stats
.rxbytes
+ adapter
->stats
.lrobytes
;
2289 stats
->tx_bytes
= adapter
->stats
.txbytes
;
2290 stats
->rx_dropped
= adapter
->stats
.rxdropped
;
2291 stats
->tx_dropped
= adapter
->stats
.txdropped
;
2296 static irqreturn_t
qlcnic_clear_legacy_intr(struct qlcnic_adapter
*adapter
)
2300 status
= readl(adapter
->isr_int_vec
);
2302 if (!(status
& adapter
->int_vec_bit
))
2305 /* check interrupt state machine, to be sure */
2306 status
= readl(adapter
->crb_int_state_reg
);
2307 if (!ISR_LEGACY_INT_TRIGGERED(status
))
2310 writel(0xffffffff, adapter
->tgt_status_reg
);
2311 /* read twice to ensure write is flushed */
2312 readl(adapter
->isr_int_vec
);
2313 readl(adapter
->isr_int_vec
);
2318 static irqreturn_t
qlcnic_tmp_intr(int irq
, void *data
)
2320 struct qlcnic_host_sds_ring
*sds_ring
= data
;
2321 struct qlcnic_adapter
*adapter
= sds_ring
->adapter
;
2323 if (adapter
->flags
& QLCNIC_MSIX_ENABLED
)
2325 else if (adapter
->flags
& QLCNIC_MSI_ENABLED
) {
2326 writel(0xffffffff, adapter
->tgt_status_reg
);
2330 if (qlcnic_clear_legacy_intr(adapter
) == IRQ_NONE
)
2334 adapter
->diag_cnt
++;
2335 qlcnic_enable_int(sds_ring
);
2339 static irqreturn_t
qlcnic_intr(int irq
, void *data
)
2341 struct qlcnic_host_sds_ring
*sds_ring
= data
;
2342 struct qlcnic_adapter
*adapter
= sds_ring
->adapter
;
2344 if (qlcnic_clear_legacy_intr(adapter
) == IRQ_NONE
)
2347 napi_schedule(&sds_ring
->napi
);
2352 static irqreturn_t
qlcnic_msi_intr(int irq
, void *data
)
2354 struct qlcnic_host_sds_ring
*sds_ring
= data
;
2355 struct qlcnic_adapter
*adapter
= sds_ring
->adapter
;
2357 /* clear interrupt */
2358 writel(0xffffffff, adapter
->tgt_status_reg
);
2360 napi_schedule(&sds_ring
->napi
);
2364 static irqreturn_t
qlcnic_msix_intr(int irq
, void *data
)
2366 struct qlcnic_host_sds_ring
*sds_ring
= data
;
2368 napi_schedule(&sds_ring
->napi
);
2372 static int qlcnic_process_cmd_ring(struct qlcnic_adapter
*adapter
)
2374 u32 sw_consumer
, hw_consumer
;
2376 struct qlcnic_cmd_buffer
*buffer
;
2377 struct pci_dev
*pdev
= adapter
->pdev
;
2378 struct net_device
*netdev
= adapter
->netdev
;
2379 struct qlcnic_skb_frag
*frag
;
2381 struct qlcnic_host_tx_ring
*tx_ring
= adapter
->tx_ring
;
2383 if (!spin_trylock(&adapter
->tx_clean_lock
))
2386 sw_consumer
= tx_ring
->sw_consumer
;
2387 hw_consumer
= le32_to_cpu(*(tx_ring
->hw_consumer
));
2389 while (sw_consumer
!= hw_consumer
) {
2390 buffer
= &tx_ring
->cmd_buf_arr
[sw_consumer
];
2392 frag
= &buffer
->frag_array
[0];
2393 pci_unmap_single(pdev
, frag
->dma
, frag
->length
,
2396 for (i
= 1; i
< buffer
->frag_count
; i
++) {
2398 pci_unmap_page(pdev
, frag
->dma
, frag
->length
,
2403 adapter
->stats
.xmitfinished
++;
2404 dev_kfree_skb_any(buffer
->skb
);
2408 sw_consumer
= get_next_index(sw_consumer
, tx_ring
->num_desc
);
2409 if (++count
>= MAX_STATUS_HANDLE
)
2413 if (count
&& netif_running(netdev
)) {
2414 tx_ring
->sw_consumer
= sw_consumer
;
2418 if (netif_queue_stopped(netdev
) && netif_carrier_ok(netdev
)) {
2419 if (qlcnic_tx_avail(tx_ring
) > TX_STOP_THRESH
) {
2420 netif_wake_queue(netdev
);
2421 adapter
->stats
.xmit_on
++;
2424 adapter
->tx_timeo_cnt
= 0;
2427 * If everything is freed up to consumer then check if the ring is full
2428 * If the ring is full then check if more needs to be freed and
2429 * schedule the call back again.
2431 * This happens when there are 2 CPUs. One could be freeing and the
2432 * other filling it. If the ring is full when we get out of here and
2433 * the card has already interrupted the host then the host can miss the
2436 * There is still a possible race condition and the host could miss an
2437 * interrupt. The card has to take care of this.
2439 hw_consumer
= le32_to_cpu(*(tx_ring
->hw_consumer
));
2440 done
= (sw_consumer
== hw_consumer
);
2441 spin_unlock(&adapter
->tx_clean_lock
);
2446 static int qlcnic_poll(struct napi_struct
*napi
, int budget
)
2448 struct qlcnic_host_sds_ring
*sds_ring
=
2449 container_of(napi
, struct qlcnic_host_sds_ring
, napi
);
2451 struct qlcnic_adapter
*adapter
= sds_ring
->adapter
;
2456 tx_complete
= qlcnic_process_cmd_ring(adapter
);
2458 work_done
= qlcnic_process_rcv_ring(sds_ring
, budget
);
2460 if ((work_done
< budget
) && tx_complete
) {
2461 napi_complete(&sds_ring
->napi
);
2462 if (test_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
2463 qlcnic_enable_int(sds_ring
);
2469 static int qlcnic_rx_poll(struct napi_struct
*napi
, int budget
)
2471 struct qlcnic_host_sds_ring
*sds_ring
=
2472 container_of(napi
, struct qlcnic_host_sds_ring
, napi
);
2474 struct qlcnic_adapter
*adapter
= sds_ring
->adapter
;
2477 work_done
= qlcnic_process_rcv_ring(sds_ring
, budget
);
2479 if (work_done
< budget
) {
2480 napi_complete(&sds_ring
->napi
);
2481 if (test_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
2482 qlcnic_enable_int(sds_ring
);
2488 #ifdef CONFIG_NET_POLL_CONTROLLER
2489 static void qlcnic_poll_controller(struct net_device
*netdev
)
2492 struct qlcnic_host_sds_ring
*sds_ring
;
2493 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
2494 struct qlcnic_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
2496 disable_irq(adapter
->irq
);
2497 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
2498 sds_ring
= &recv_ctx
->sds_rings
[ring
];
2499 qlcnic_intr(adapter
->irq
, sds_ring
);
2501 enable_irq(adapter
->irq
);
2506 qlcnic_idc_debug_info(struct qlcnic_adapter
*adapter
, u8 encoding
)
2510 val
= adapter
->portnum
& 0xf;
2511 val
|= encoding
<< 7;
2512 val
|= (jiffies
- adapter
->dev_rst_time
) << 8;
2514 QLCWR32(adapter
, QLCNIC_CRB_DRV_SCRATCH
, val
);
2515 adapter
->dev_rst_time
= jiffies
;
2519 qlcnic_set_drv_state(struct qlcnic_adapter
*adapter
, u8 state
)
2523 WARN_ON(state
!= QLCNIC_DEV_NEED_RESET
&&
2524 state
!= QLCNIC_DEV_NEED_QUISCENT
);
2526 if (qlcnic_api_lock(adapter
))
2529 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_STATE
);
2531 if (state
== QLCNIC_DEV_NEED_RESET
)
2532 QLC_DEV_SET_RST_RDY(val
, adapter
->portnum
);
2533 else if (state
== QLCNIC_DEV_NEED_QUISCENT
)
2534 QLC_DEV_SET_QSCNT_RDY(val
, adapter
->portnum
);
2536 QLCWR32(adapter
, QLCNIC_CRB_DRV_STATE
, val
);
2538 qlcnic_api_unlock(adapter
);
2544 qlcnic_clr_drv_state(struct qlcnic_adapter
*adapter
)
2548 if (qlcnic_api_lock(adapter
))
2551 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_STATE
);
2552 QLC_DEV_CLR_RST_QSCNT(val
, adapter
->portnum
);
2553 QLCWR32(adapter
, QLCNIC_CRB_DRV_STATE
, val
);
2555 qlcnic_api_unlock(adapter
);
2561 qlcnic_clr_all_drv_state(struct qlcnic_adapter
*adapter
, u8 failed
)
2565 if (qlcnic_api_lock(adapter
))
2568 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_ACTIVE
);
2569 QLC_DEV_CLR_REF_CNT(val
, adapter
->portnum
);
2570 QLCWR32(adapter
, QLCNIC_CRB_DRV_ACTIVE
, val
);
2573 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
, QLCNIC_DEV_FAILED
);
2574 dev_info(&adapter
->pdev
->dev
,
2575 "Device state set to Failed. Please Reboot\n");
2576 } else if (!(val
& 0x11111111))
2577 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
, QLCNIC_DEV_COLD
);
2579 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_STATE
);
2580 QLC_DEV_CLR_RST_QSCNT(val
, adapter
->portnum
);
2581 QLCWR32(adapter
, QLCNIC_CRB_DRV_STATE
, val
);
2583 qlcnic_api_unlock(adapter
);
2585 adapter
->fw_fail_cnt
= 0;
2586 clear_bit(__QLCNIC_START_FW
, &adapter
->state
);
2587 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
2590 /* Grab api lock, before checking state */
2592 qlcnic_check_drv_state(struct qlcnic_adapter
*adapter
)
2596 state
= QLCRD32(adapter
, QLCNIC_CRB_DRV_STATE
);
2597 act
= QLCRD32(adapter
, QLCNIC_CRB_DRV_ACTIVE
);
2599 if (((state
& 0x11111111) == (act
& 0x11111111)) ||
2600 ((act
& 0x11111111) == ((state
>> 1) & 0x11111111)))
2606 static int qlcnic_check_idc_ver(struct qlcnic_adapter
*adapter
)
2608 u32 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_IDC_VER
);
2610 if (val
!= QLCNIC_DRV_IDC_VER
) {
2611 dev_warn(&adapter
->pdev
->dev
, "IDC Version mismatch, driver's"
2612 " idc ver = %x; reqd = %x\n", QLCNIC_DRV_IDC_VER
, val
);
2619 qlcnic_can_start_firmware(struct qlcnic_adapter
*adapter
)
2621 u32 val
, prev_state
;
2622 u8 dev_init_timeo
= adapter
->dev_init_timeo
;
2623 u8 portnum
= adapter
->portnum
;
2626 if (test_and_clear_bit(__QLCNIC_START_FW
, &adapter
->state
))
2629 if (qlcnic_api_lock(adapter
))
2632 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_ACTIVE
);
2633 if (!(val
& (1 << (portnum
* 4)))) {
2634 QLC_DEV_SET_REF_CNT(val
, portnum
);
2635 QLCWR32(adapter
, QLCNIC_CRB_DRV_ACTIVE
, val
);
2638 prev_state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
);
2639 QLCDB(adapter
, HW
, "Device state = %u\n", prev_state
);
2641 switch (prev_state
) {
2642 case QLCNIC_DEV_COLD
:
2643 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
, QLCNIC_DEV_INITIALIZING
);
2644 QLCWR32(adapter
, QLCNIC_CRB_DRV_IDC_VER
, QLCNIC_DRV_IDC_VER
);
2645 qlcnic_idc_debug_info(adapter
, 0);
2646 qlcnic_api_unlock(adapter
);
2649 case QLCNIC_DEV_READY
:
2650 ret
= qlcnic_check_idc_ver(adapter
);
2651 qlcnic_api_unlock(adapter
);
2654 case QLCNIC_DEV_NEED_RESET
:
2655 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_STATE
);
2656 QLC_DEV_SET_RST_RDY(val
, portnum
);
2657 QLCWR32(adapter
, QLCNIC_CRB_DRV_STATE
, val
);
2660 case QLCNIC_DEV_NEED_QUISCENT
:
2661 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_STATE
);
2662 QLC_DEV_SET_QSCNT_RDY(val
, portnum
);
2663 QLCWR32(adapter
, QLCNIC_CRB_DRV_STATE
, val
);
2666 case QLCNIC_DEV_FAILED
:
2667 dev_err(&adapter
->pdev
->dev
, "Device in failed state.\n");
2668 qlcnic_api_unlock(adapter
);
2671 case QLCNIC_DEV_INITIALIZING
:
2672 case QLCNIC_DEV_QUISCENT
:
2676 qlcnic_api_unlock(adapter
);
2680 prev_state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
);
2682 if (prev_state
== QLCNIC_DEV_QUISCENT
)
2684 } while ((prev_state
!= QLCNIC_DEV_READY
) && --dev_init_timeo
);
2686 if (!dev_init_timeo
) {
2687 dev_err(&adapter
->pdev
->dev
,
2688 "Waiting for device to initialize timeout\n");
2692 if (qlcnic_api_lock(adapter
))
2695 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_STATE
);
2696 QLC_DEV_CLR_RST_QSCNT(val
, portnum
);
2697 QLCWR32(adapter
, QLCNIC_CRB_DRV_STATE
, val
);
2699 ret
= qlcnic_check_idc_ver(adapter
);
2700 qlcnic_api_unlock(adapter
);
2706 qlcnic_fwinit_work(struct work_struct
*work
)
2708 struct qlcnic_adapter
*adapter
= container_of(work
,
2709 struct qlcnic_adapter
, fw_work
.work
);
2710 u32 dev_state
= 0xf;
2712 if (qlcnic_api_lock(adapter
))
2715 dev_state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
);
2716 if (dev_state
== QLCNIC_DEV_QUISCENT
||
2717 dev_state
== QLCNIC_DEV_NEED_QUISCENT
) {
2718 qlcnic_api_unlock(adapter
);
2719 qlcnic_schedule_work(adapter
, qlcnic_fwinit_work
,
2724 if (adapter
->op_mode
== QLCNIC_NON_PRIV_FUNC
) {
2725 qlcnic_api_unlock(adapter
);
2729 if (adapter
->fw_wait_cnt
++ > adapter
->reset_ack_timeo
) {
2730 dev_err(&adapter
->pdev
->dev
, "Reset:Failed to get ack %d sec\n",
2731 adapter
->reset_ack_timeo
);
2732 goto skip_ack_check
;
2735 if (!qlcnic_check_drv_state(adapter
)) {
2737 dev_state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
);
2739 if (dev_state
== QLCNIC_DEV_NEED_RESET
) {
2740 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
,
2741 QLCNIC_DEV_INITIALIZING
);
2742 set_bit(__QLCNIC_START_FW
, &adapter
->state
);
2743 QLCDB(adapter
, DRV
, "Restarting fw\n");
2744 qlcnic_idc_debug_info(adapter
, 0);
2747 qlcnic_api_unlock(adapter
);
2749 if (!adapter
->nic_ops
->start_firmware(adapter
)) {
2750 qlcnic_schedule_work(adapter
, qlcnic_attach_work
, 0);
2751 adapter
->fw_wait_cnt
= 0;
2757 qlcnic_api_unlock(adapter
);
2760 dev_state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
);
2761 QLCDB(adapter
, HW
, "Func waiting: Device state=%u\n", dev_state
);
2763 switch (dev_state
) {
2764 case QLCNIC_DEV_READY
:
2765 if (!adapter
->nic_ops
->start_firmware(adapter
)) {
2766 qlcnic_schedule_work(adapter
, qlcnic_attach_work
, 0);
2767 adapter
->fw_wait_cnt
= 0;
2770 case QLCNIC_DEV_FAILED
:
2773 qlcnic_schedule_work(adapter
,
2774 qlcnic_fwinit_work
, FW_POLL_DELAY
);
2779 dev_err(&adapter
->pdev
->dev
, "Fwinit work failed state=%u "
2780 "fw_wait_cnt=%u\n", dev_state
, adapter
->fw_wait_cnt
);
2781 netif_device_attach(adapter
->netdev
);
2782 qlcnic_clr_all_drv_state(adapter
, 0);
2786 qlcnic_detach_work(struct work_struct
*work
)
2788 struct qlcnic_adapter
*adapter
= container_of(work
,
2789 struct qlcnic_adapter
, fw_work
.work
);
2790 struct net_device
*netdev
= adapter
->netdev
;
2793 netif_device_detach(netdev
);
2795 /* Dont grab rtnl lock during Quiscent mode */
2796 if (adapter
->dev_state
== QLCNIC_DEV_NEED_QUISCENT
) {
2797 if (netif_running(netdev
))
2798 __qlcnic_down(adapter
, netdev
);
2800 qlcnic_down(adapter
, netdev
);
2802 status
= QLCRD32(adapter
, QLCNIC_PEG_HALT_STATUS1
);
2804 if (status
& QLCNIC_RCODE_FATAL_ERROR
)
2807 if (adapter
->temp
== QLCNIC_TEMP_PANIC
)
2810 if (qlcnic_set_drv_state(adapter
, adapter
->dev_state
))
2813 adapter
->fw_wait_cnt
= 0;
2815 qlcnic_schedule_work(adapter
, qlcnic_fwinit_work
, FW_POLL_DELAY
);
2820 dev_err(&adapter
->pdev
->dev
, "detach failed; status=%d temp=%d\n",
2821 status
, adapter
->temp
);
2822 netif_device_attach(netdev
);
2823 qlcnic_clr_all_drv_state(adapter
, 1);
2826 /*Transit NPAR state to NON Operational */
2828 qlcnic_set_npar_non_operational(struct qlcnic_adapter
*adapter
)
2832 state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_NPAR_STATE
);
2833 if (state
== QLCNIC_DEV_NPAR_NON_OPER
)
2836 if (qlcnic_api_lock(adapter
))
2838 QLCWR32(adapter
, QLCNIC_CRB_DEV_NPAR_STATE
, QLCNIC_DEV_NPAR_NON_OPER
);
2839 qlcnic_api_unlock(adapter
);
2842 /*Transit to RESET state from READY state only */
2844 qlcnic_dev_request_reset(struct qlcnic_adapter
*adapter
)
2848 adapter
->need_fw_reset
= 1;
2849 if (qlcnic_api_lock(adapter
))
2852 state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
);
2854 if (state
== QLCNIC_DEV_READY
) {
2855 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
, QLCNIC_DEV_NEED_RESET
);
2856 QLCDB(adapter
, DRV
, "NEED_RESET state set\n");
2857 qlcnic_idc_debug_info(adapter
, 0);
2860 QLCWR32(adapter
, QLCNIC_CRB_DEV_NPAR_STATE
, QLCNIC_DEV_NPAR_NON_OPER
);
2861 qlcnic_api_unlock(adapter
);
2864 /* Transit to NPAR READY state from NPAR NOT READY state */
2866 qlcnic_dev_set_npar_ready(struct qlcnic_adapter
*adapter
)
2868 if (qlcnic_api_lock(adapter
))
2871 QLCWR32(adapter
, QLCNIC_CRB_DEV_NPAR_STATE
, QLCNIC_DEV_NPAR_OPER
);
2872 QLCDB(adapter
, DRV
, "NPAR operational state set\n");
2874 qlcnic_api_unlock(adapter
);
2878 qlcnic_schedule_work(struct qlcnic_adapter
*adapter
,
2879 work_func_t func
, int delay
)
2881 if (test_bit(__QLCNIC_AER
, &adapter
->state
))
2884 INIT_DELAYED_WORK(&adapter
->fw_work
, func
);
2885 queue_delayed_work(qlcnic_wq
, &adapter
->fw_work
,
2886 round_jiffies_relative(delay
));
2890 qlcnic_cancel_fw_work(struct qlcnic_adapter
*adapter
)
2892 while (test_and_set_bit(__QLCNIC_RESETTING
, &adapter
->state
))
2895 cancel_delayed_work_sync(&adapter
->fw_work
);
2899 qlcnic_attach_work(struct work_struct
*work
)
2901 struct qlcnic_adapter
*adapter
= container_of(work
,
2902 struct qlcnic_adapter
, fw_work
.work
);
2903 struct net_device
*netdev
= adapter
->netdev
;
2906 if (adapter
->op_mode
!= QLCNIC_MGMT_FUNC
) {
2907 npar_state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_NPAR_STATE
);
2908 if (adapter
->fw_wait_cnt
++ > QLCNIC_DEV_NPAR_OPER_TIMEO
)
2909 qlcnic_clr_all_drv_state(adapter
, 0);
2910 else if (npar_state
!= QLCNIC_DEV_NPAR_OPER
)
2911 qlcnic_schedule_work(adapter
, qlcnic_attach_work
,
2915 QLCDB(adapter
, DRV
, "Waiting for NPAR state to operational\n");
2919 if (netif_running(netdev
)) {
2920 if (qlcnic_up(adapter
, netdev
))
2923 qlcnic_restore_indev_addr(netdev
, NETDEV_UP
);
2927 netif_device_attach(netdev
);
2928 adapter
->fw_fail_cnt
= 0;
2929 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
2931 if (!qlcnic_clr_drv_state(adapter
))
2932 qlcnic_schedule_work(adapter
, qlcnic_fw_poll_work
,
2937 qlcnic_check_health(struct qlcnic_adapter
*adapter
)
2939 u32 state
= 0, heartbeat
;
2940 struct net_device
*netdev
= adapter
->netdev
;
2942 if (qlcnic_check_temp(adapter
))
2945 if (adapter
->need_fw_reset
)
2946 qlcnic_dev_request_reset(adapter
);
2948 state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
);
2949 if (state
== QLCNIC_DEV_NEED_RESET
) {
2950 qlcnic_set_npar_non_operational(adapter
);
2951 adapter
->need_fw_reset
= 1;
2952 } else if (state
== QLCNIC_DEV_NEED_QUISCENT
)
2955 heartbeat
= QLCRD32(adapter
, QLCNIC_PEG_ALIVE_COUNTER
);
2956 if (heartbeat
!= adapter
->heartbeat
) {
2957 adapter
->heartbeat
= heartbeat
;
2958 adapter
->fw_fail_cnt
= 0;
2959 if (adapter
->need_fw_reset
)
2962 if (adapter
->reset_context
&&
2963 auto_fw_reset
== AUTO_FW_RESET_ENABLED
) {
2964 qlcnic_reset_hw_context(adapter
);
2965 adapter
->netdev
->trans_start
= jiffies
;
2971 if (++adapter
->fw_fail_cnt
< FW_FAIL_THRESH
)
2974 qlcnic_dev_request_reset(adapter
);
2976 if ((auto_fw_reset
== AUTO_FW_RESET_ENABLED
))
2977 clear_bit(__QLCNIC_FW_ATTACHED
, &adapter
->state
);
2979 dev_info(&netdev
->dev
, "firmware hang detected\n");
2982 adapter
->dev_state
= (state
== QLCNIC_DEV_NEED_QUISCENT
) ? state
:
2983 QLCNIC_DEV_NEED_RESET
;
2985 if ((auto_fw_reset
== AUTO_FW_RESET_ENABLED
) &&
2986 !test_and_set_bit(__QLCNIC_RESETTING
, &adapter
->state
)) {
2988 qlcnic_schedule_work(adapter
, qlcnic_detach_work
, 0);
2989 QLCDB(adapter
, DRV
, "fw recovery scheduled.\n");
2996 qlcnic_fw_poll_work(struct work_struct
*work
)
2998 struct qlcnic_adapter
*adapter
= container_of(work
,
2999 struct qlcnic_adapter
, fw_work
.work
);
3001 if (test_bit(__QLCNIC_RESETTING
, &adapter
->state
))
3005 if (qlcnic_check_health(adapter
))
3008 if (adapter
->fhash
.fnum
)
3009 qlcnic_prune_lb_filters(adapter
);
3012 qlcnic_schedule_work(adapter
, qlcnic_fw_poll_work
, FW_POLL_DELAY
);
3015 static int qlcnic_is_first_func(struct pci_dev
*pdev
)
3017 struct pci_dev
*oth_pdev
;
3018 int val
= pdev
->devfn
;
3021 oth_pdev
= pci_get_domain_bus_and_slot(pci_domain_nr
3022 (pdev
->bus
), pdev
->bus
->number
,
3023 PCI_DEVFN(PCI_SLOT(pdev
->devfn
), val
));
3027 if (oth_pdev
->current_state
!= PCI_D3cold
) {
3028 pci_dev_put(oth_pdev
);
3031 pci_dev_put(oth_pdev
);
3036 static int qlcnic_attach_func(struct pci_dev
*pdev
)
3038 int err
, first_func
;
3039 struct qlcnic_adapter
*adapter
= pci_get_drvdata(pdev
);
3040 struct net_device
*netdev
= adapter
->netdev
;
3042 pdev
->error_state
= pci_channel_io_normal
;
3044 err
= pci_enable_device(pdev
);
3048 pci_set_power_state(pdev
, PCI_D0
);
3049 pci_set_master(pdev
);
3050 pci_restore_state(pdev
);
3052 first_func
= qlcnic_is_first_func(pdev
);
3054 if (qlcnic_api_lock(adapter
))
3057 if (adapter
->op_mode
!= QLCNIC_NON_PRIV_FUNC
&& first_func
) {
3058 adapter
->need_fw_reset
= 1;
3059 set_bit(__QLCNIC_START_FW
, &adapter
->state
);
3060 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
, QLCNIC_DEV_INITIALIZING
);
3061 QLCDB(adapter
, DRV
, "Restarting fw\n");
3063 qlcnic_api_unlock(adapter
);
3065 err
= adapter
->nic_ops
->start_firmware(adapter
);
3069 qlcnic_clr_drv_state(adapter
);
3070 qlcnic_setup_intr(adapter
);
3072 if (netif_running(netdev
)) {
3073 err
= qlcnic_attach(adapter
);
3075 qlcnic_clr_all_drv_state(adapter
, 1);
3076 clear_bit(__QLCNIC_AER
, &adapter
->state
);
3077 netif_device_attach(netdev
);
3081 err
= qlcnic_up(adapter
, netdev
);
3085 qlcnic_restore_indev_addr(netdev
, NETDEV_UP
);
3088 netif_device_attach(netdev
);
3092 static pci_ers_result_t
qlcnic_io_error_detected(struct pci_dev
*pdev
,
3093 pci_channel_state_t state
)
3095 struct qlcnic_adapter
*adapter
= pci_get_drvdata(pdev
);
3096 struct net_device
*netdev
= adapter
->netdev
;
3098 if (state
== pci_channel_io_perm_failure
)
3099 return PCI_ERS_RESULT_DISCONNECT
;
3101 if (state
== pci_channel_io_normal
)
3102 return PCI_ERS_RESULT_RECOVERED
;
3104 set_bit(__QLCNIC_AER
, &adapter
->state
);
3105 netif_device_detach(netdev
);
3107 cancel_delayed_work_sync(&adapter
->fw_work
);
3109 if (netif_running(netdev
))
3110 qlcnic_down(adapter
, netdev
);
3112 qlcnic_detach(adapter
);
3113 qlcnic_teardown_intr(adapter
);
3115 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
3117 pci_save_state(pdev
);
3118 pci_disable_device(pdev
);
3120 return PCI_ERS_RESULT_NEED_RESET
;
3123 static pci_ers_result_t
qlcnic_io_slot_reset(struct pci_dev
*pdev
)
3125 return qlcnic_attach_func(pdev
) ? PCI_ERS_RESULT_DISCONNECT
:
3126 PCI_ERS_RESULT_RECOVERED
;
3129 static void qlcnic_io_resume(struct pci_dev
*pdev
)
3131 struct qlcnic_adapter
*adapter
= pci_get_drvdata(pdev
);
3133 pci_cleanup_aer_uncorrect_error_status(pdev
);
3135 if (QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
) == QLCNIC_DEV_READY
&&
3136 test_and_clear_bit(__QLCNIC_AER
, &adapter
->state
))
3137 qlcnic_schedule_work(adapter
, qlcnic_fw_poll_work
,
3142 qlcnicvf_start_firmware(struct qlcnic_adapter
*adapter
)
3146 err
= qlcnic_can_start_firmware(adapter
);
3150 err
= qlcnic_check_npar_opertional(adapter
);
3154 err
= qlcnic_initialize_nic(adapter
);
3158 qlcnic_check_options(adapter
);
3160 err
= qlcnic_set_eswitch_port_config(adapter
);
3164 adapter
->need_fw_reset
= 0;
3170 qlcnicvf_config_bridged_mode(struct qlcnic_adapter
*adapter
, u32 enable
)
3176 qlcnicvf_config_led(struct qlcnic_adapter
*adapter
, u32 state
, u32 rate
)
3182 qlcnic_store_bridged_mode(struct device
*dev
,
3183 struct device_attribute
*attr
, const char *buf
, size_t len
)
3185 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3189 if (!(adapter
->capabilities
& QLCNIC_FW_CAPABILITY_BDG
))
3192 if (!test_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
3195 if (strict_strtoul(buf
, 2, &new))
3198 if (!adapter
->nic_ops
->config_bridged_mode(adapter
, !!new))
3206 qlcnic_show_bridged_mode(struct device
*dev
,
3207 struct device_attribute
*attr
, char *buf
)
3209 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3210 int bridged_mode
= 0;
3212 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_BDG
)
3213 bridged_mode
= !!(adapter
->flags
& QLCNIC_BRIDGE_ENABLED
);
3215 return sprintf(buf
, "%d\n", bridged_mode
);
3218 static struct device_attribute dev_attr_bridged_mode
= {
3219 .attr
= {.name
= "bridged_mode", .mode
= (S_IRUGO
| S_IWUSR
)},
3220 .show
= qlcnic_show_bridged_mode
,
3221 .store
= qlcnic_store_bridged_mode
,
3225 qlcnic_store_diag_mode(struct device
*dev
,
3226 struct device_attribute
*attr
, const char *buf
, size_t len
)
3228 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3231 if (strict_strtoul(buf
, 2, &new))
3234 if (!!new != !!(adapter
->flags
& QLCNIC_DIAG_ENABLED
))
3235 adapter
->flags
^= QLCNIC_DIAG_ENABLED
;
3241 qlcnic_show_diag_mode(struct device
*dev
,
3242 struct device_attribute
*attr
, char *buf
)
3244 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3246 return sprintf(buf
, "%d\n",
3247 !!(adapter
->flags
& QLCNIC_DIAG_ENABLED
));
3250 static struct device_attribute dev_attr_diag_mode
= {
3251 .attr
= {.name
= "diag_mode", .mode
= (S_IRUGO
| S_IWUSR
)},
3252 .show
= qlcnic_show_diag_mode
,
3253 .store
= qlcnic_store_diag_mode
,
3257 qlcnic_sysfs_validate_crb(struct qlcnic_adapter
*adapter
,
3258 loff_t offset
, size_t size
)
3260 size_t crb_size
= 4;
3262 if (!(adapter
->flags
& QLCNIC_DIAG_ENABLED
))
3265 if (offset
< QLCNIC_PCI_CRBSPACE
) {
3266 if (ADDR_IN_RANGE(offset
, QLCNIC_PCI_CAMQM
,
3267 QLCNIC_PCI_CAMQM_END
))
3273 if ((size
!= crb_size
) || (offset
& (crb_size
-1)))
3280 qlcnic_sysfs_read_crb(struct file
*filp
, struct kobject
*kobj
,
3281 struct bin_attribute
*attr
,
3282 char *buf
, loff_t offset
, size_t size
)
3284 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3285 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3290 ret
= qlcnic_sysfs_validate_crb(adapter
, offset
, size
);
3294 if (ADDR_IN_RANGE(offset
, QLCNIC_PCI_CAMQM
, QLCNIC_PCI_CAMQM_END
)) {
3295 qlcnic_pci_camqm_read_2M(adapter
, offset
, &qmdata
);
3296 memcpy(buf
, &qmdata
, size
);
3298 data
= QLCRD32(adapter
, offset
);
3299 memcpy(buf
, &data
, size
);
3305 qlcnic_sysfs_write_crb(struct file
*filp
, struct kobject
*kobj
,
3306 struct bin_attribute
*attr
,
3307 char *buf
, loff_t offset
, size_t size
)
3309 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3310 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3315 ret
= qlcnic_sysfs_validate_crb(adapter
, offset
, size
);
3319 if (ADDR_IN_RANGE(offset
, QLCNIC_PCI_CAMQM
, QLCNIC_PCI_CAMQM_END
)) {
3320 memcpy(&qmdata
, buf
, size
);
3321 qlcnic_pci_camqm_write_2M(adapter
, offset
, qmdata
);
3323 memcpy(&data
, buf
, size
);
3324 QLCWR32(adapter
, offset
, data
);
3330 qlcnic_sysfs_validate_mem(struct qlcnic_adapter
*adapter
,
3331 loff_t offset
, size_t size
)
3333 if (!(adapter
->flags
& QLCNIC_DIAG_ENABLED
))
3336 if ((size
!= 8) || (offset
& 0x7))
3343 qlcnic_sysfs_read_mem(struct file
*filp
, struct kobject
*kobj
,
3344 struct bin_attribute
*attr
,
3345 char *buf
, loff_t offset
, size_t size
)
3347 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3348 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3352 ret
= qlcnic_sysfs_validate_mem(adapter
, offset
, size
);
3356 if (qlcnic_pci_mem_read_2M(adapter
, offset
, &data
))
3359 memcpy(buf
, &data
, size
);
3365 qlcnic_sysfs_write_mem(struct file
*filp
, struct kobject
*kobj
,
3366 struct bin_attribute
*attr
,
3367 char *buf
, loff_t offset
, size_t size
)
3369 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3370 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3374 ret
= qlcnic_sysfs_validate_mem(adapter
, offset
, size
);
3378 memcpy(&data
, buf
, size
);
3380 if (qlcnic_pci_mem_write_2M(adapter
, offset
, data
))
3387 static struct bin_attribute bin_attr_crb
= {
3388 .attr
= {.name
= "crb", .mode
= (S_IRUGO
| S_IWUSR
)},
3390 .read
= qlcnic_sysfs_read_crb
,
3391 .write
= qlcnic_sysfs_write_crb
,
3394 static struct bin_attribute bin_attr_mem
= {
3395 .attr
= {.name
= "mem", .mode
= (S_IRUGO
| S_IWUSR
)},
3397 .read
= qlcnic_sysfs_read_mem
,
3398 .write
= qlcnic_sysfs_write_mem
,
3402 validate_pm_config(struct qlcnic_adapter
*adapter
,
3403 struct qlcnic_pm_func_cfg
*pm_cfg
, int count
)
3406 u8 src_pci_func
, s_esw_id
, d_esw_id
;
3410 for (i
= 0; i
< count
; i
++) {
3411 src_pci_func
= pm_cfg
[i
].pci_func
;
3412 dest_pci_func
= pm_cfg
[i
].dest_npar
;
3413 if (src_pci_func
>= QLCNIC_MAX_PCI_FUNC
3414 || dest_pci_func
>= QLCNIC_MAX_PCI_FUNC
)
3415 return QL_STATUS_INVALID_PARAM
;
3417 if (adapter
->npars
[src_pci_func
].type
!= QLCNIC_TYPE_NIC
)
3418 return QL_STATUS_INVALID_PARAM
;
3420 if (adapter
->npars
[dest_pci_func
].type
!= QLCNIC_TYPE_NIC
)
3421 return QL_STATUS_INVALID_PARAM
;
3423 s_esw_id
= adapter
->npars
[src_pci_func
].phy_port
;
3424 d_esw_id
= adapter
->npars
[dest_pci_func
].phy_port
;
3426 if (s_esw_id
!= d_esw_id
)
3427 return QL_STATUS_INVALID_PARAM
;
3435 qlcnic_sysfs_write_pm_config(struct file
*filp
, struct kobject
*kobj
,
3436 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3438 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3439 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3440 struct qlcnic_pm_func_cfg
*pm_cfg
;
3441 u32 id
, action
, pci_func
;
3442 int count
, rem
, i
, ret
;
3444 count
= size
/ sizeof(struct qlcnic_pm_func_cfg
);
3445 rem
= size
% sizeof(struct qlcnic_pm_func_cfg
);
3447 return QL_STATUS_INVALID_PARAM
;
3449 pm_cfg
= (struct qlcnic_pm_func_cfg
*) buf
;
3451 ret
= validate_pm_config(adapter
, pm_cfg
, count
);
3454 for (i
= 0; i
< count
; i
++) {
3455 pci_func
= pm_cfg
[i
].pci_func
;
3456 action
= !!pm_cfg
[i
].action
;
3457 id
= adapter
->npars
[pci_func
].phy_port
;
3458 ret
= qlcnic_config_port_mirroring(adapter
, id
,
3464 for (i
= 0; i
< count
; i
++) {
3465 pci_func
= pm_cfg
[i
].pci_func
;
3466 id
= adapter
->npars
[pci_func
].phy_port
;
3467 adapter
->npars
[pci_func
].enable_pm
= !!pm_cfg
[i
].action
;
3468 adapter
->npars
[pci_func
].dest_npar
= id
;
3474 qlcnic_sysfs_read_pm_config(struct file
*filp
, struct kobject
*kobj
,
3475 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3477 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3478 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3479 struct qlcnic_pm_func_cfg pm_cfg
[QLCNIC_MAX_PCI_FUNC
];
3482 if (size
!= sizeof(pm_cfg
))
3483 return QL_STATUS_INVALID_PARAM
;
3485 for (i
= 0; i
< QLCNIC_MAX_PCI_FUNC
; i
++) {
3486 if (adapter
->npars
[i
].type
!= QLCNIC_TYPE_NIC
)
3488 pm_cfg
[i
].action
= adapter
->npars
[i
].enable_pm
;
3489 pm_cfg
[i
].dest_npar
= 0;
3490 pm_cfg
[i
].pci_func
= i
;
3492 memcpy(buf
, &pm_cfg
, size
);
3498 validate_esw_config(struct qlcnic_adapter
*adapter
,
3499 struct qlcnic_esw_func_cfg
*esw_cfg
, int count
)
3505 op_mode
= readl(adapter
->ahw
.pci_base0
+ QLCNIC_DRV_OP_MODE
);
3507 for (i
= 0; i
< count
; i
++) {
3508 pci_func
= esw_cfg
[i
].pci_func
;
3509 if (pci_func
>= QLCNIC_MAX_PCI_FUNC
)
3510 return QL_STATUS_INVALID_PARAM
;
3512 if (adapter
->op_mode
== QLCNIC_MGMT_FUNC
)
3513 if (adapter
->npars
[pci_func
].type
!= QLCNIC_TYPE_NIC
)
3514 return QL_STATUS_INVALID_PARAM
;
3516 switch (esw_cfg
[i
].op_mode
) {
3517 case QLCNIC_PORT_DEFAULTS
:
3518 if (QLC_DEV_GET_DRV(op_mode
, pci_func
) !=
3519 QLCNIC_NON_PRIV_FUNC
) {
3520 if (esw_cfg
[i
].mac_anti_spoof
!= 0)
3521 return QL_STATUS_INVALID_PARAM
;
3522 if (esw_cfg
[i
].mac_override
!= 1)
3523 return QL_STATUS_INVALID_PARAM
;
3524 if (esw_cfg
[i
].promisc_mode
!= 1)
3525 return QL_STATUS_INVALID_PARAM
;
3528 case QLCNIC_ADD_VLAN
:
3529 if (!IS_VALID_VLAN(esw_cfg
[i
].vlan_id
))
3530 return QL_STATUS_INVALID_PARAM
;
3531 if (!esw_cfg
[i
].op_type
)
3532 return QL_STATUS_INVALID_PARAM
;
3534 case QLCNIC_DEL_VLAN
:
3535 if (!esw_cfg
[i
].op_type
)
3536 return QL_STATUS_INVALID_PARAM
;
3539 return QL_STATUS_INVALID_PARAM
;
3546 qlcnic_sysfs_write_esw_config(struct file
*file
, struct kobject
*kobj
,
3547 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3549 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3550 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3551 struct qlcnic_esw_func_cfg
*esw_cfg
;
3552 struct qlcnic_npar_info
*npar
;
3553 int count
, rem
, i
, ret
;
3554 u8 pci_func
, op_mode
= 0;
3556 count
= size
/ sizeof(struct qlcnic_esw_func_cfg
);
3557 rem
= size
% sizeof(struct qlcnic_esw_func_cfg
);
3559 return QL_STATUS_INVALID_PARAM
;
3561 esw_cfg
= (struct qlcnic_esw_func_cfg
*) buf
;
3562 ret
= validate_esw_config(adapter
, esw_cfg
, count
);
3566 for (i
= 0; i
< count
; i
++) {
3567 if (adapter
->op_mode
== QLCNIC_MGMT_FUNC
)
3568 if (qlcnic_config_switch_port(adapter
, &esw_cfg
[i
]))
3569 return QL_STATUS_INVALID_PARAM
;
3571 if (adapter
->ahw
.pci_func
!= esw_cfg
[i
].pci_func
)
3574 op_mode
= esw_cfg
[i
].op_mode
;
3575 qlcnic_get_eswitch_port_config(adapter
, &esw_cfg
[i
]);
3576 esw_cfg
[i
].op_mode
= op_mode
;
3577 esw_cfg
[i
].pci_func
= adapter
->ahw
.pci_func
;
3579 switch (esw_cfg
[i
].op_mode
) {
3580 case QLCNIC_PORT_DEFAULTS
:
3581 qlcnic_set_eswitch_port_features(adapter
, &esw_cfg
[i
]);
3583 case QLCNIC_ADD_VLAN
:
3584 qlcnic_set_vlan_config(adapter
, &esw_cfg
[i
]);
3586 case QLCNIC_DEL_VLAN
:
3587 esw_cfg
[i
].vlan_id
= 0;
3588 qlcnic_set_vlan_config(adapter
, &esw_cfg
[i
]);
3593 if (adapter
->op_mode
!= QLCNIC_MGMT_FUNC
)
3596 for (i
= 0; i
< count
; i
++) {
3597 pci_func
= esw_cfg
[i
].pci_func
;
3598 npar
= &adapter
->npars
[pci_func
];
3599 switch (esw_cfg
[i
].op_mode
) {
3600 case QLCNIC_PORT_DEFAULTS
:
3601 npar
->promisc_mode
= esw_cfg
[i
].promisc_mode
;
3602 npar
->mac_override
= esw_cfg
[i
].mac_override
;
3603 npar
->offload_flags
= esw_cfg
[i
].offload_flags
;
3604 npar
->mac_anti_spoof
= esw_cfg
[i
].mac_anti_spoof
;
3605 npar
->discard_tagged
= esw_cfg
[i
].discard_tagged
;
3607 case QLCNIC_ADD_VLAN
:
3608 npar
->pvid
= esw_cfg
[i
].vlan_id
;
3610 case QLCNIC_DEL_VLAN
:
3620 qlcnic_sysfs_read_esw_config(struct file
*file
, struct kobject
*kobj
,
3621 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3623 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3624 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3625 struct qlcnic_esw_func_cfg esw_cfg
[QLCNIC_MAX_PCI_FUNC
];
3628 if (size
!= sizeof(esw_cfg
))
3629 return QL_STATUS_INVALID_PARAM
;
3631 for (i
= 0; i
< QLCNIC_MAX_PCI_FUNC
; i
++) {
3632 if (adapter
->npars
[i
].type
!= QLCNIC_TYPE_NIC
)
3634 esw_cfg
[i
].pci_func
= i
;
3635 if (qlcnic_get_eswitch_port_config(adapter
, &esw_cfg
[i
]))
3636 return QL_STATUS_INVALID_PARAM
;
3638 memcpy(buf
, &esw_cfg
, size
);
3644 validate_npar_config(struct qlcnic_adapter
*adapter
,
3645 struct qlcnic_npar_func_cfg
*np_cfg
, int count
)
3649 for (i
= 0; i
< count
; i
++) {
3650 pci_func
= np_cfg
[i
].pci_func
;
3651 if (pci_func
>= QLCNIC_MAX_PCI_FUNC
)
3652 return QL_STATUS_INVALID_PARAM
;
3654 if (adapter
->npars
[pci_func
].type
!= QLCNIC_TYPE_NIC
)
3655 return QL_STATUS_INVALID_PARAM
;
3657 if (!IS_VALID_BW(np_cfg
[i
].min_bw
)
3658 || !IS_VALID_BW(np_cfg
[i
].max_bw
)
3659 || !IS_VALID_RX_QUEUES(np_cfg
[i
].max_rx_queues
)
3660 || !IS_VALID_TX_QUEUES(np_cfg
[i
].max_tx_queues
))
3661 return QL_STATUS_INVALID_PARAM
;
3667 qlcnic_sysfs_write_npar_config(struct file
*file
, struct kobject
*kobj
,
3668 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3670 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3671 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3672 struct qlcnic_info nic_info
;
3673 struct qlcnic_npar_func_cfg
*np_cfg
;
3674 int i
, count
, rem
, ret
;
3677 count
= size
/ sizeof(struct qlcnic_npar_func_cfg
);
3678 rem
= size
% sizeof(struct qlcnic_npar_func_cfg
);
3680 return QL_STATUS_INVALID_PARAM
;
3682 np_cfg
= (struct qlcnic_npar_func_cfg
*) buf
;
3683 ret
= validate_npar_config(adapter
, np_cfg
, count
);
3687 for (i
= 0; i
< count
; i
++) {
3688 pci_func
= np_cfg
[i
].pci_func
;
3689 ret
= qlcnic_get_nic_info(adapter
, &nic_info
, pci_func
);
3692 nic_info
.pci_func
= pci_func
;
3693 nic_info
.min_tx_bw
= np_cfg
[i
].min_bw
;
3694 nic_info
.max_tx_bw
= np_cfg
[i
].max_bw
;
3695 ret
= qlcnic_set_nic_info(adapter
, &nic_info
);
3698 adapter
->npars
[i
].min_bw
= nic_info
.min_tx_bw
;
3699 adapter
->npars
[i
].max_bw
= nic_info
.max_tx_bw
;
3706 qlcnic_sysfs_read_npar_config(struct file
*file
, struct kobject
*kobj
,
3707 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3709 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3710 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3711 struct qlcnic_info nic_info
;
3712 struct qlcnic_npar_func_cfg np_cfg
[QLCNIC_MAX_PCI_FUNC
];
3715 if (size
!= sizeof(np_cfg
))
3716 return QL_STATUS_INVALID_PARAM
;
3718 for (i
= 0; i
< QLCNIC_MAX_PCI_FUNC
; i
++) {
3719 if (adapter
->npars
[i
].type
!= QLCNIC_TYPE_NIC
)
3721 ret
= qlcnic_get_nic_info(adapter
, &nic_info
, i
);
3725 np_cfg
[i
].pci_func
= i
;
3726 np_cfg
[i
].op_mode
= (u8
)nic_info
.op_mode
;
3727 np_cfg
[i
].port_num
= nic_info
.phys_port
;
3728 np_cfg
[i
].fw_capab
= nic_info
.capabilities
;
3729 np_cfg
[i
].min_bw
= nic_info
.min_tx_bw
;
3730 np_cfg
[i
].max_bw
= nic_info
.max_tx_bw
;
3731 np_cfg
[i
].max_tx_queues
= nic_info
.max_tx_ques
;
3732 np_cfg
[i
].max_rx_queues
= nic_info
.max_rx_ques
;
3734 memcpy(buf
, &np_cfg
, size
);
3739 qlcnic_sysfs_get_port_stats(struct file
*file
, struct kobject
*kobj
,
3740 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3742 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3743 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3744 struct qlcnic_esw_statistics port_stats
;
3747 if (size
!= sizeof(struct qlcnic_esw_statistics
))
3748 return QL_STATUS_INVALID_PARAM
;
3750 if (offset
>= QLCNIC_MAX_PCI_FUNC
)
3751 return QL_STATUS_INVALID_PARAM
;
3753 memset(&port_stats
, 0, size
);
3754 ret
= qlcnic_get_port_stats(adapter
, offset
, QLCNIC_QUERY_RX_COUNTER
,
3759 ret
= qlcnic_get_port_stats(adapter
, offset
, QLCNIC_QUERY_TX_COUNTER
,
3764 memcpy(buf
, &port_stats
, size
);
3769 qlcnic_sysfs_get_esw_stats(struct file
*file
, struct kobject
*kobj
,
3770 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3772 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3773 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3774 struct qlcnic_esw_statistics esw_stats
;
3777 if (size
!= sizeof(struct qlcnic_esw_statistics
))
3778 return QL_STATUS_INVALID_PARAM
;
3780 if (offset
>= QLCNIC_NIU_MAX_XG_PORTS
)
3781 return QL_STATUS_INVALID_PARAM
;
3783 memset(&esw_stats
, 0, size
);
3784 ret
= qlcnic_get_eswitch_stats(adapter
, offset
, QLCNIC_QUERY_RX_COUNTER
,
3789 ret
= qlcnic_get_eswitch_stats(adapter
, offset
, QLCNIC_QUERY_TX_COUNTER
,
3794 memcpy(buf
, &esw_stats
, size
);
3799 qlcnic_sysfs_clear_esw_stats(struct file
*file
, struct kobject
*kobj
,
3800 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3802 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3803 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3806 if (offset
>= QLCNIC_NIU_MAX_XG_PORTS
)
3807 return QL_STATUS_INVALID_PARAM
;
3809 ret
= qlcnic_clear_esw_stats(adapter
, QLCNIC_STATS_ESWITCH
, offset
,
3810 QLCNIC_QUERY_RX_COUNTER
);
3814 ret
= qlcnic_clear_esw_stats(adapter
, QLCNIC_STATS_ESWITCH
, offset
,
3815 QLCNIC_QUERY_TX_COUNTER
);
3823 qlcnic_sysfs_clear_port_stats(struct file
*file
, struct kobject
*kobj
,
3824 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3827 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3828 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3831 if (offset
>= QLCNIC_MAX_PCI_FUNC
)
3832 return QL_STATUS_INVALID_PARAM
;
3834 ret
= qlcnic_clear_esw_stats(adapter
, QLCNIC_STATS_PORT
, offset
,
3835 QLCNIC_QUERY_RX_COUNTER
);
3839 ret
= qlcnic_clear_esw_stats(adapter
, QLCNIC_STATS_PORT
, offset
,
3840 QLCNIC_QUERY_TX_COUNTER
);
3848 qlcnic_sysfs_read_pci_config(struct file
*file
, struct kobject
*kobj
,
3849 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3851 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3852 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3853 struct qlcnic_pci_func_cfg pci_cfg
[QLCNIC_MAX_PCI_FUNC
];
3854 struct qlcnic_pci_info
*pci_info
;
3857 if (size
!= sizeof(pci_cfg
))
3858 return QL_STATUS_INVALID_PARAM
;
3860 pci_info
= kcalloc(QLCNIC_MAX_PCI_FUNC
, sizeof(*pci_info
), GFP_KERNEL
);
3864 ret
= qlcnic_get_pci_info(adapter
, pci_info
);
3870 for (i
= 0; i
< QLCNIC_MAX_PCI_FUNC
; i
++) {
3871 pci_cfg
[i
].pci_func
= pci_info
[i
].id
;
3872 pci_cfg
[i
].func_type
= pci_info
[i
].type
;
3873 pci_cfg
[i
].port_num
= pci_info
[i
].default_port
;
3874 pci_cfg
[i
].min_bw
= pci_info
[i
].tx_min_bw
;
3875 pci_cfg
[i
].max_bw
= pci_info
[i
].tx_max_bw
;
3876 memcpy(&pci_cfg
[i
].def_mac_addr
, &pci_info
[i
].mac
, ETH_ALEN
);
3878 memcpy(buf
, &pci_cfg
, size
);
3882 static struct bin_attribute bin_attr_npar_config
= {
3883 .attr
= {.name
= "npar_config", .mode
= (S_IRUGO
| S_IWUSR
)},
3885 .read
= qlcnic_sysfs_read_npar_config
,
3886 .write
= qlcnic_sysfs_write_npar_config
,
3889 static struct bin_attribute bin_attr_pci_config
= {
3890 .attr
= {.name
= "pci_config", .mode
= (S_IRUGO
| S_IWUSR
)},
3892 .read
= qlcnic_sysfs_read_pci_config
,
3896 static struct bin_attribute bin_attr_port_stats
= {
3897 .attr
= {.name
= "port_stats", .mode
= (S_IRUGO
| S_IWUSR
)},
3899 .read
= qlcnic_sysfs_get_port_stats
,
3900 .write
= qlcnic_sysfs_clear_port_stats
,
3903 static struct bin_attribute bin_attr_esw_stats
= {
3904 .attr
= {.name
= "esw_stats", .mode
= (S_IRUGO
| S_IWUSR
)},
3906 .read
= qlcnic_sysfs_get_esw_stats
,
3907 .write
= qlcnic_sysfs_clear_esw_stats
,
3910 static struct bin_attribute bin_attr_esw_config
= {
3911 .attr
= {.name
= "esw_config", .mode
= (S_IRUGO
| S_IWUSR
)},
3913 .read
= qlcnic_sysfs_read_esw_config
,
3914 .write
= qlcnic_sysfs_write_esw_config
,
3917 static struct bin_attribute bin_attr_pm_config
= {
3918 .attr
= {.name
= "pm_config", .mode
= (S_IRUGO
| S_IWUSR
)},
3920 .read
= qlcnic_sysfs_read_pm_config
,
3921 .write
= qlcnic_sysfs_write_pm_config
,
3925 qlcnic_create_sysfs_entries(struct qlcnic_adapter
*adapter
)
3927 struct device
*dev
= &adapter
->pdev
->dev
;
3929 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_BDG
)
3930 if (device_create_file(dev
, &dev_attr_bridged_mode
))
3932 "failed to create bridged_mode sysfs entry\n");
3936 qlcnic_remove_sysfs_entries(struct qlcnic_adapter
*adapter
)
3938 struct device
*dev
= &adapter
->pdev
->dev
;
3940 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_BDG
)
3941 device_remove_file(dev
, &dev_attr_bridged_mode
);
3945 qlcnic_create_diag_entries(struct qlcnic_adapter
*adapter
)
3947 struct device
*dev
= &adapter
->pdev
->dev
;
3949 if (device_create_bin_file(dev
, &bin_attr_port_stats
))
3950 dev_info(dev
, "failed to create port stats sysfs entry");
3952 if (adapter
->op_mode
== QLCNIC_NON_PRIV_FUNC
)
3954 if (device_create_file(dev
, &dev_attr_diag_mode
))
3955 dev_info(dev
, "failed to create diag_mode sysfs entry\n");
3956 if (device_create_bin_file(dev
, &bin_attr_crb
))
3957 dev_info(dev
, "failed to create crb sysfs entry\n");
3958 if (device_create_bin_file(dev
, &bin_attr_mem
))
3959 dev_info(dev
, "failed to create mem sysfs entry\n");
3960 if (!(adapter
->flags
& QLCNIC_ESWITCH_ENABLED
))
3962 if (device_create_bin_file(dev
, &bin_attr_esw_config
))
3963 dev_info(dev
, "failed to create esw config sysfs entry");
3964 if (adapter
->op_mode
!= QLCNIC_MGMT_FUNC
)
3966 if (device_create_bin_file(dev
, &bin_attr_pci_config
))
3967 dev_info(dev
, "failed to create pci config sysfs entry");
3968 if (device_create_bin_file(dev
, &bin_attr_npar_config
))
3969 dev_info(dev
, "failed to create npar config sysfs entry");
3970 if (device_create_bin_file(dev
, &bin_attr_pm_config
))
3971 dev_info(dev
, "failed to create pm config sysfs entry");
3972 if (device_create_bin_file(dev
, &bin_attr_esw_stats
))
3973 dev_info(dev
, "failed to create eswitch stats sysfs entry");
3977 qlcnic_remove_diag_entries(struct qlcnic_adapter
*adapter
)
3979 struct device
*dev
= &adapter
->pdev
->dev
;
3981 device_remove_bin_file(dev
, &bin_attr_port_stats
);
3983 if (adapter
->op_mode
== QLCNIC_NON_PRIV_FUNC
)
3985 device_remove_file(dev
, &dev_attr_diag_mode
);
3986 device_remove_bin_file(dev
, &bin_attr_crb
);
3987 device_remove_bin_file(dev
, &bin_attr_mem
);
3988 if (!(adapter
->flags
& QLCNIC_ESWITCH_ENABLED
))
3990 device_remove_bin_file(dev
, &bin_attr_esw_config
);
3991 if (adapter
->op_mode
!= QLCNIC_MGMT_FUNC
)
3993 device_remove_bin_file(dev
, &bin_attr_pci_config
);
3994 device_remove_bin_file(dev
, &bin_attr_npar_config
);
3995 device_remove_bin_file(dev
, &bin_attr_pm_config
);
3996 device_remove_bin_file(dev
, &bin_attr_esw_stats
);
4001 #define is_qlcnic_netdev(dev) (dev->netdev_ops == &qlcnic_netdev_ops)
4004 qlcnic_config_indev_addr(struct qlcnic_adapter
*adapter
,
4005 struct net_device
*dev
, unsigned long event
)
4007 struct in_device
*indev
;
4009 indev
= in_dev_get(dev
);
4016 qlcnic_config_ipaddr(adapter
,
4017 ifa
->ifa_address
, QLCNIC_IP_UP
);
4020 qlcnic_config_ipaddr(adapter
,
4021 ifa
->ifa_address
, QLCNIC_IP_DOWN
);
4026 } endfor_ifa(indev
);
4032 qlcnic_restore_indev_addr(struct net_device
*netdev
, unsigned long event
)
4034 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
4035 struct net_device
*dev
;
4038 qlcnic_config_indev_addr(adapter
, netdev
, event
);
4040 if (!adapter
->vlgrp
)
4043 for (vid
= 0; vid
< VLAN_N_VID
; vid
++) {
4044 dev
= vlan_group_get_device(adapter
->vlgrp
, vid
);
4048 qlcnic_config_indev_addr(adapter
, dev
, event
);
4052 static int qlcnic_netdev_event(struct notifier_block
*this,
4053 unsigned long event
, void *ptr
)
4055 struct qlcnic_adapter
*adapter
;
4056 struct net_device
*dev
= (struct net_device
*)ptr
;
4062 if (dev
->priv_flags
& IFF_802_1Q_VLAN
) {
4063 dev
= vlan_dev_real_dev(dev
);
4067 if (!is_qlcnic_netdev(dev
))
4070 adapter
= netdev_priv(dev
);
4075 if (!test_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
4078 qlcnic_config_indev_addr(adapter
, dev
, event
);
4084 qlcnic_inetaddr_event(struct notifier_block
*this,
4085 unsigned long event
, void *ptr
)
4087 struct qlcnic_adapter
*adapter
;
4088 struct net_device
*dev
;
4090 struct in_ifaddr
*ifa
= (struct in_ifaddr
*)ptr
;
4092 dev
= ifa
->ifa_dev
? ifa
->ifa_dev
->dev
: NULL
;
4098 if (dev
->priv_flags
& IFF_802_1Q_VLAN
) {
4099 dev
= vlan_dev_real_dev(dev
);
4103 if (!is_qlcnic_netdev(dev
))
4106 adapter
= netdev_priv(dev
);
4111 if (!test_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
4116 qlcnic_config_ipaddr(adapter
, ifa
->ifa_address
, QLCNIC_IP_UP
);
4119 qlcnic_config_ipaddr(adapter
, ifa
->ifa_address
, QLCNIC_IP_DOWN
);
4129 static struct notifier_block qlcnic_netdev_cb
= {
4130 .notifier_call
= qlcnic_netdev_event
,
4133 static struct notifier_block qlcnic_inetaddr_cb
= {
4134 .notifier_call
= qlcnic_inetaddr_event
,
4138 qlcnic_restore_indev_addr(struct net_device
*dev
, unsigned long event
)
4141 static struct pci_error_handlers qlcnic_err_handler
= {
4142 .error_detected
= qlcnic_io_error_detected
,
4143 .slot_reset
= qlcnic_io_slot_reset
,
4144 .resume
= qlcnic_io_resume
,
4147 static struct pci_driver qlcnic_driver
= {
4148 .name
= qlcnic_driver_name
,
4149 .id_table
= qlcnic_pci_tbl
,
4150 .probe
= qlcnic_probe
,
4151 .remove
= __devexit_p(qlcnic_remove
),
4153 .suspend
= qlcnic_suspend
,
4154 .resume
= qlcnic_resume
,
4156 .shutdown
= qlcnic_shutdown
,
4157 .err_handler
= &qlcnic_err_handler
4161 static int __init
qlcnic_init_module(void)
4165 printk(KERN_INFO
"%s\n", qlcnic_driver_string
);
4167 qlcnic_wq
= create_singlethread_workqueue("qlcnic");
4168 if (qlcnic_wq
== NULL
) {
4169 printk(KERN_ERR
"qlcnic: cannot create workqueue\n");
4174 register_netdevice_notifier(&qlcnic_netdev_cb
);
4175 register_inetaddr_notifier(&qlcnic_inetaddr_cb
);
4178 ret
= pci_register_driver(&qlcnic_driver
);
4181 unregister_inetaddr_notifier(&qlcnic_inetaddr_cb
);
4182 unregister_netdevice_notifier(&qlcnic_netdev_cb
);
4184 destroy_workqueue(qlcnic_wq
);
4190 module_init(qlcnic_init_module
);
4192 static void __exit
qlcnic_exit_module(void)
4195 pci_unregister_driver(&qlcnic_driver
);
4198 unregister_inetaddr_notifier(&qlcnic_inetaddr_cb
);
4199 unregister_netdevice_notifier(&qlcnic_netdev_cb
);
4201 destroy_workqueue(qlcnic_wq
);
4204 module_exit(qlcnic_exit_module
);