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>
17 #include <linux/ipv6.h>
18 #include <linux/inetdevice.h>
19 #include <linux/sysfs.h>
20 #include <linux/aer.h>
21 #include <linux/log2.h>
23 MODULE_DESCRIPTION("QLogic 1/10 GbE Converged/Intelligent Ethernet Driver");
24 MODULE_LICENSE("GPL");
25 MODULE_VERSION(QLCNIC_LINUX_VERSIONID
);
26 MODULE_FIRMWARE(QLCNIC_UNIFIED_ROMIMAGE_NAME
);
28 char qlcnic_driver_name
[] = "qlcnic";
29 static const char qlcnic_driver_string
[] = "QLogic 1/10 GbE "
30 "Converged/Intelligent Ethernet Driver v" QLCNIC_LINUX_VERSIONID
;
32 static struct workqueue_struct
*qlcnic_wq
;
33 static int qlcnic_mac_learn
;
34 module_param(qlcnic_mac_learn
, int, 0444);
35 MODULE_PARM_DESC(qlcnic_mac_learn
, "Mac Filter (0=disabled, 1=enabled)");
37 static int use_msi
= 1;
38 module_param(use_msi
, int, 0444);
39 MODULE_PARM_DESC(use_msi
, "MSI interrupt (0=disabled, 1=enabled");
41 static int use_msi_x
= 1;
42 module_param(use_msi_x
, int, 0444);
43 MODULE_PARM_DESC(use_msi_x
, "MSI-X interrupt (0=disabled, 1=enabled");
45 static int auto_fw_reset
= 1;
46 module_param(auto_fw_reset
, int, 0644);
47 MODULE_PARM_DESC(auto_fw_reset
, "Auto firmware reset (0=disabled, 1=enabled");
49 static int load_fw_file
;
50 module_param(load_fw_file
, int, 0444);
51 MODULE_PARM_DESC(load_fw_file
, "Load firmware from (0=flash, 1=file");
53 static int qlcnic_config_npars
;
54 module_param(qlcnic_config_npars
, int, 0444);
55 MODULE_PARM_DESC(qlcnic_config_npars
, "Configure NPARs (0=disabled, 1=enabled");
57 static int __devinit
qlcnic_probe(struct pci_dev
*pdev
,
58 const struct pci_device_id
*ent
);
59 static void __devexit
qlcnic_remove(struct pci_dev
*pdev
);
60 static int qlcnic_open(struct net_device
*netdev
);
61 static int qlcnic_close(struct net_device
*netdev
);
62 static void qlcnic_tx_timeout(struct net_device
*netdev
);
63 static void qlcnic_attach_work(struct work_struct
*work
);
64 static void qlcnic_fwinit_work(struct work_struct
*work
);
65 static void qlcnic_fw_poll_work(struct work_struct
*work
);
66 static void qlcnic_schedule_work(struct qlcnic_adapter
*adapter
,
67 work_func_t func
, int delay
);
68 static void qlcnic_cancel_fw_work(struct qlcnic_adapter
*adapter
);
69 static int qlcnic_poll(struct napi_struct
*napi
, int budget
);
70 static int qlcnic_rx_poll(struct napi_struct
*napi
, int budget
);
71 #ifdef CONFIG_NET_POLL_CONTROLLER
72 static void qlcnic_poll_controller(struct net_device
*netdev
);
75 static void qlcnic_create_sysfs_entries(struct qlcnic_adapter
*adapter
);
76 static void qlcnic_remove_sysfs_entries(struct qlcnic_adapter
*adapter
);
77 static void qlcnic_create_diag_entries(struct qlcnic_adapter
*adapter
);
78 static void qlcnic_remove_diag_entries(struct qlcnic_adapter
*adapter
);
80 static void qlcnic_idc_debug_info(struct qlcnic_adapter
*adapter
, u8 encoding
);
81 static void qlcnic_clr_all_drv_state(struct qlcnic_adapter
*adapter
, u8
);
82 static int qlcnic_can_start_firmware(struct qlcnic_adapter
*adapter
);
84 static irqreturn_t
qlcnic_tmp_intr(int irq
, void *data
);
85 static irqreturn_t
qlcnic_intr(int irq
, void *data
);
86 static irqreturn_t
qlcnic_msi_intr(int irq
, void *data
);
87 static irqreturn_t
qlcnic_msix_intr(int irq
, void *data
);
89 static struct net_device_stats
*qlcnic_get_stats(struct net_device
*netdev
);
90 static void qlcnic_restore_indev_addr(struct net_device
*dev
, unsigned long);
91 static int qlcnic_start_firmware(struct qlcnic_adapter
*);
93 static void qlcnic_free_lb_filters_mem(struct qlcnic_adapter
*adapter
);
94 static void qlcnic_dev_set_npar_ready(struct qlcnic_adapter
*);
95 static int qlcnicvf_config_led(struct qlcnic_adapter
*, u32
, u32
);
96 static int qlcnicvf_config_bridged_mode(struct qlcnic_adapter
*, u32
);
97 static int qlcnicvf_start_firmware(struct qlcnic_adapter
*);
98 static void qlcnic_set_netdev_features(struct qlcnic_adapter
*,
99 struct qlcnic_esw_func_cfg
*);
100 static void qlcnic_vlan_rx_add(struct net_device
*, u16
);
101 static void qlcnic_vlan_rx_del(struct net_device
*, u16
);
103 /* PCI Device ID Table */
104 #define ENTRY(device) \
105 {PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, (device)), \
106 .class = PCI_CLASS_NETWORK_ETHERNET << 8, .class_mask = ~0}
108 #define PCI_DEVICE_ID_QLOGIC_QLE824X 0x8020
110 static DEFINE_PCI_DEVICE_TABLE(qlcnic_pci_tbl
) = {
111 ENTRY(PCI_DEVICE_ID_QLOGIC_QLE824X
),
115 MODULE_DEVICE_TABLE(pci
, qlcnic_pci_tbl
);
119 qlcnic_update_cmd_producer(struct qlcnic_adapter
*adapter
,
120 struct qlcnic_host_tx_ring
*tx_ring
)
122 writel(tx_ring
->producer
, tx_ring
->crb_cmd_producer
);
125 static const u32 msi_tgt_status
[8] = {
126 ISR_INT_TARGET_STATUS
, ISR_INT_TARGET_STATUS_F1
,
127 ISR_INT_TARGET_STATUS_F2
, ISR_INT_TARGET_STATUS_F3
,
128 ISR_INT_TARGET_STATUS_F4
, ISR_INT_TARGET_STATUS_F5
,
129 ISR_INT_TARGET_STATUS_F6
, ISR_INT_TARGET_STATUS_F7
133 struct qlcnic_legacy_intr_set legacy_intr
[] = QLCNIC_LEGACY_INTR_CONFIG
;
135 static inline void qlcnic_disable_int(struct qlcnic_host_sds_ring
*sds_ring
)
137 writel(0, sds_ring
->crb_intr_mask
);
140 static inline void qlcnic_enable_int(struct qlcnic_host_sds_ring
*sds_ring
)
142 struct qlcnic_adapter
*adapter
= sds_ring
->adapter
;
144 writel(0x1, sds_ring
->crb_intr_mask
);
146 if (!QLCNIC_IS_MSI_FAMILY(adapter
))
147 writel(0xfbff, adapter
->tgt_mask_reg
);
151 qlcnic_alloc_sds_rings(struct qlcnic_recv_context
*recv_ctx
, int count
)
153 int size
= sizeof(struct qlcnic_host_sds_ring
) * count
;
155 recv_ctx
->sds_rings
= kzalloc(size
, GFP_KERNEL
);
157 return recv_ctx
->sds_rings
== NULL
;
161 qlcnic_free_sds_rings(struct qlcnic_recv_context
*recv_ctx
)
163 if (recv_ctx
->sds_rings
!= NULL
)
164 kfree(recv_ctx
->sds_rings
);
166 recv_ctx
->sds_rings
= NULL
;
170 qlcnic_napi_add(struct qlcnic_adapter
*adapter
, struct net_device
*netdev
)
173 struct qlcnic_host_sds_ring
*sds_ring
;
174 struct qlcnic_recv_context
*recv_ctx
= adapter
->recv_ctx
;
176 if (qlcnic_alloc_sds_rings(recv_ctx
, adapter
->max_sds_rings
))
179 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
180 sds_ring
= &recv_ctx
->sds_rings
[ring
];
182 if (ring
== adapter
->max_sds_rings
- 1)
183 netif_napi_add(netdev
, &sds_ring
->napi
, qlcnic_poll
,
184 QLCNIC_NETDEV_WEIGHT
/adapter
->max_sds_rings
);
186 netif_napi_add(netdev
, &sds_ring
->napi
,
187 qlcnic_rx_poll
, QLCNIC_NETDEV_WEIGHT
*2);
194 qlcnic_napi_del(struct qlcnic_adapter
*adapter
)
197 struct qlcnic_host_sds_ring
*sds_ring
;
198 struct qlcnic_recv_context
*recv_ctx
= adapter
->recv_ctx
;
200 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
201 sds_ring
= &recv_ctx
->sds_rings
[ring
];
202 netif_napi_del(&sds_ring
->napi
);
205 qlcnic_free_sds_rings(adapter
->recv_ctx
);
209 qlcnic_napi_enable(struct qlcnic_adapter
*adapter
)
212 struct qlcnic_host_sds_ring
*sds_ring
;
213 struct qlcnic_recv_context
*recv_ctx
= adapter
->recv_ctx
;
215 if (adapter
->is_up
!= QLCNIC_ADAPTER_UP_MAGIC
)
218 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
219 sds_ring
= &recv_ctx
->sds_rings
[ring
];
220 napi_enable(&sds_ring
->napi
);
221 qlcnic_enable_int(sds_ring
);
226 qlcnic_napi_disable(struct qlcnic_adapter
*adapter
)
229 struct qlcnic_host_sds_ring
*sds_ring
;
230 struct qlcnic_recv_context
*recv_ctx
= adapter
->recv_ctx
;
232 if (adapter
->is_up
!= QLCNIC_ADAPTER_UP_MAGIC
)
235 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
236 sds_ring
= &recv_ctx
->sds_rings
[ring
];
237 qlcnic_disable_int(sds_ring
);
238 napi_synchronize(&sds_ring
->napi
);
239 napi_disable(&sds_ring
->napi
);
243 static void qlcnic_clear_stats(struct qlcnic_adapter
*adapter
)
245 memset(&adapter
->stats
, 0, sizeof(adapter
->stats
));
248 static void qlcnic_set_msix_bit(struct pci_dev
*pdev
, int enable
)
253 pos
= pci_find_capability(pdev
, PCI_CAP_ID_MSIX
);
255 pci_read_config_dword(pdev
, pos
, &control
);
257 control
|= PCI_MSIX_FLAGS_ENABLE
;
260 pci_write_config_dword(pdev
, pos
, control
);
264 static void qlcnic_init_msix_entries(struct qlcnic_adapter
*adapter
, int count
)
268 for (i
= 0; i
< count
; i
++)
269 adapter
->msix_entries
[i
].entry
= i
;
273 qlcnic_read_mac_addr(struct qlcnic_adapter
*adapter
)
275 u8 mac_addr
[ETH_ALEN
];
276 struct net_device
*netdev
= adapter
->netdev
;
277 struct pci_dev
*pdev
= adapter
->pdev
;
279 if (qlcnic_get_mac_address(adapter
, mac_addr
) != 0)
282 memcpy(netdev
->dev_addr
, mac_addr
, ETH_ALEN
);
283 memcpy(netdev
->perm_addr
, netdev
->dev_addr
, netdev
->addr_len
);
284 memcpy(adapter
->mac_addr
, netdev
->dev_addr
, netdev
->addr_len
);
286 /* set station address */
288 if (!is_valid_ether_addr(netdev
->perm_addr
))
289 dev_warn(&pdev
->dev
, "Bad MAC address %pM.\n",
295 static int qlcnic_set_mac(struct net_device
*netdev
, void *p
)
297 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
298 struct sockaddr
*addr
= p
;
300 if ((adapter
->flags
& QLCNIC_MAC_OVERRIDE_DISABLED
))
303 if (!is_valid_ether_addr(addr
->sa_data
))
306 if (test_bit(__QLCNIC_DEV_UP
, &adapter
->state
)) {
307 netif_device_detach(netdev
);
308 qlcnic_napi_disable(adapter
);
311 memcpy(adapter
->mac_addr
, addr
->sa_data
, netdev
->addr_len
);
312 memcpy(netdev
->dev_addr
, addr
->sa_data
, netdev
->addr_len
);
313 qlcnic_set_multi(adapter
->netdev
);
315 if (test_bit(__QLCNIC_DEV_UP
, &adapter
->state
)) {
316 netif_device_attach(netdev
);
317 qlcnic_napi_enable(adapter
);
322 static const struct net_device_ops qlcnic_netdev_ops
= {
323 .ndo_open
= qlcnic_open
,
324 .ndo_stop
= qlcnic_close
,
325 .ndo_start_xmit
= qlcnic_xmit_frame
,
326 .ndo_get_stats
= qlcnic_get_stats
,
327 .ndo_validate_addr
= eth_validate_addr
,
328 .ndo_set_multicast_list
= qlcnic_set_multi
,
329 .ndo_set_mac_address
= qlcnic_set_mac
,
330 .ndo_change_mtu
= qlcnic_change_mtu
,
331 .ndo_fix_features
= qlcnic_fix_features
,
332 .ndo_set_features
= qlcnic_set_features
,
333 .ndo_tx_timeout
= qlcnic_tx_timeout
,
334 .ndo_vlan_rx_add_vid
= qlcnic_vlan_rx_add
,
335 .ndo_vlan_rx_kill_vid
= qlcnic_vlan_rx_del
,
336 #ifdef CONFIG_NET_POLL_CONTROLLER
337 .ndo_poll_controller
= qlcnic_poll_controller
,
341 static struct qlcnic_nic_template qlcnic_ops
= {
342 .config_bridged_mode
= qlcnic_config_bridged_mode
,
343 .config_led
= qlcnic_config_led
,
344 .start_firmware
= qlcnic_start_firmware
347 static struct qlcnic_nic_template qlcnic_vf_ops
= {
348 .config_bridged_mode
= qlcnicvf_config_bridged_mode
,
349 .config_led
= qlcnicvf_config_led
,
350 .start_firmware
= qlcnicvf_start_firmware
353 static int qlcnic_enable_msix(struct qlcnic_adapter
*adapter
, u32 num_msix
)
355 struct pci_dev
*pdev
= adapter
->pdev
;
358 adapter
->max_sds_rings
= 1;
359 adapter
->flags
&= ~(QLCNIC_MSI_ENABLED
| QLCNIC_MSIX_ENABLED
);
360 qlcnic_set_msix_bit(pdev
, 0);
362 if (adapter
->msix_supported
) {
364 qlcnic_init_msix_entries(adapter
, num_msix
);
365 err
= pci_enable_msix(pdev
, adapter
->msix_entries
, num_msix
);
367 adapter
->flags
|= QLCNIC_MSIX_ENABLED
;
368 qlcnic_set_msix_bit(pdev
, 1);
370 adapter
->max_sds_rings
= num_msix
;
372 dev_info(&pdev
->dev
, "using msi-x interrupts\n");
376 num_msix
= rounddown_pow_of_two(err
);
385 static void qlcnic_enable_msi_legacy(struct qlcnic_adapter
*adapter
)
387 const struct qlcnic_legacy_intr_set
*legacy_intrp
;
388 struct pci_dev
*pdev
= adapter
->pdev
;
390 if (use_msi
&& !pci_enable_msi(pdev
)) {
391 adapter
->flags
|= QLCNIC_MSI_ENABLED
;
392 adapter
->tgt_status_reg
= qlcnic_get_ioaddr(adapter
,
393 msi_tgt_status
[adapter
->ahw
->pci_func
]);
394 dev_info(&pdev
->dev
, "using msi interrupts\n");
395 adapter
->msix_entries
[0].vector
= pdev
->irq
;
399 legacy_intrp
= &legacy_intr
[adapter
->ahw
->pci_func
];
401 adapter
->int_vec_bit
= legacy_intrp
->int_vec_bit
;
402 adapter
->tgt_status_reg
= qlcnic_get_ioaddr(adapter
,
403 legacy_intrp
->tgt_status_reg
);
404 adapter
->tgt_mask_reg
= qlcnic_get_ioaddr(adapter
,
405 legacy_intrp
->tgt_mask_reg
);
406 adapter
->isr_int_vec
= qlcnic_get_ioaddr(adapter
, ISR_INT_VECTOR
);
408 adapter
->crb_int_state_reg
= qlcnic_get_ioaddr(adapter
,
410 dev_info(&pdev
->dev
, "using legacy interrupts\n");
411 adapter
->msix_entries
[0].vector
= pdev
->irq
;
415 qlcnic_setup_intr(struct qlcnic_adapter
*adapter
)
419 if (adapter
->msix_supported
) {
420 num_msix
= rounddown_pow_of_two(min_t(int, num_online_cpus(),
421 QLCNIC_DEF_NUM_STS_DESC_RINGS
));
425 if (!qlcnic_enable_msix(adapter
, num_msix
))
428 qlcnic_enable_msi_legacy(adapter
);
432 qlcnic_teardown_intr(struct qlcnic_adapter
*adapter
)
434 if (adapter
->flags
& QLCNIC_MSIX_ENABLED
)
435 pci_disable_msix(adapter
->pdev
);
436 if (adapter
->flags
& QLCNIC_MSI_ENABLED
)
437 pci_disable_msi(adapter
->pdev
);
441 qlcnic_cleanup_pci_map(struct qlcnic_adapter
*adapter
)
443 if (adapter
->ahw
->pci_base0
!= NULL
)
444 iounmap(adapter
->ahw
->pci_base0
);
448 qlcnic_init_pci_info(struct qlcnic_adapter
*adapter
)
450 struct qlcnic_pci_info
*pci_info
;
454 pci_info
= kcalloc(QLCNIC_MAX_PCI_FUNC
, sizeof(*pci_info
), GFP_KERNEL
);
458 adapter
->npars
= kzalloc(sizeof(struct qlcnic_npar_info
) *
459 QLCNIC_MAX_PCI_FUNC
, GFP_KERNEL
);
460 if (!adapter
->npars
) {
465 adapter
->eswitch
= kzalloc(sizeof(struct qlcnic_eswitch
) *
466 QLCNIC_NIU_MAX_XG_PORTS
, GFP_KERNEL
);
467 if (!adapter
->eswitch
) {
472 ret
= qlcnic_get_pci_info(adapter
, pci_info
);
476 for (i
= 0; i
< QLCNIC_MAX_PCI_FUNC
; i
++) {
477 pfn
= pci_info
[i
].id
;
478 if (pfn
> QLCNIC_MAX_PCI_FUNC
) {
479 ret
= QL_STATUS_INVALID_PARAM
;
482 adapter
->npars
[pfn
].active
= (u8
)pci_info
[i
].active
;
483 adapter
->npars
[pfn
].type
= (u8
)pci_info
[i
].type
;
484 adapter
->npars
[pfn
].phy_port
= (u8
)pci_info
[i
].default_port
;
485 adapter
->npars
[pfn
].min_bw
= pci_info
[i
].tx_min_bw
;
486 adapter
->npars
[pfn
].max_bw
= pci_info
[i
].tx_max_bw
;
489 for (i
= 0; i
< QLCNIC_NIU_MAX_XG_PORTS
; i
++)
490 adapter
->eswitch
[i
].flags
|= QLCNIC_SWITCH_ENABLE
;
496 kfree(adapter
->eswitch
);
497 adapter
->eswitch
= NULL
;
499 kfree(adapter
->npars
);
500 adapter
->npars
= NULL
;
508 qlcnic_set_function_modes(struct qlcnic_adapter
*adapter
)
513 u32 data
= QLCNIC_MGMT_FUNC
;
514 void __iomem
*priv_op
= adapter
->ahw
->pci_base0
+ QLCNIC_DRV_OP_MODE
;
516 /* If other drivers are not in use set their privilege level */
517 ref_count
= QLCRD32(adapter
, QLCNIC_CRB_DRV_ACTIVE
);
518 ret
= qlcnic_api_lock(adapter
);
522 if (qlcnic_config_npars
) {
523 for (i
= 0; i
< QLCNIC_MAX_PCI_FUNC
; i
++) {
525 if (adapter
->npars
[i
].type
!= QLCNIC_TYPE_NIC
||
526 id
== adapter
->ahw
->pci_func
)
528 data
|= (qlcnic_config_npars
&
529 QLC_DEV_SET_DRV(0xf, id
));
532 data
= readl(priv_op
);
533 data
= (data
& ~QLC_DEV_SET_DRV(0xf, adapter
->ahw
->pci_func
)) |
534 (QLC_DEV_SET_DRV(QLCNIC_MGMT_FUNC
,
535 adapter
->ahw
->pci_func
));
537 writel(data
, priv_op
);
538 qlcnic_api_unlock(adapter
);
544 qlcnic_check_vf(struct qlcnic_adapter
*adapter
)
546 void __iomem
*msix_base_addr
;
547 void __iomem
*priv_op
;
550 u32 op_mode
, priv_level
;
552 /* Determine FW API version */
553 adapter
->fw_hal_version
= readl(adapter
->ahw
->pci_base0
+
556 /* Find PCI function number */
557 pci_read_config_dword(adapter
->pdev
, QLCNIC_MSIX_TABLE_OFFSET
, &func
);
558 msix_base_addr
= adapter
->ahw
->pci_base0
+ QLCNIC_MSIX_BASE
;
559 msix_base
= readl(msix_base_addr
);
560 func
= (func
- msix_base
)/QLCNIC_MSIX_TBL_PGSIZE
;
561 adapter
->ahw
->pci_func
= func
;
563 /* Determine function privilege level */
564 priv_op
= adapter
->ahw
->pci_base0
+ QLCNIC_DRV_OP_MODE
;
565 op_mode
= readl(priv_op
);
566 if (op_mode
== QLC_DEV_DRV_DEFAULT
)
567 priv_level
= QLCNIC_MGMT_FUNC
;
569 priv_level
= QLC_DEV_GET_DRV(op_mode
, adapter
->ahw
->pci_func
);
571 if (priv_level
== QLCNIC_NON_PRIV_FUNC
) {
572 adapter
->op_mode
= QLCNIC_NON_PRIV_FUNC
;
573 dev_info(&adapter
->pdev
->dev
,
574 "HAL Version: %d Non Privileged function\n",
575 adapter
->fw_hal_version
);
576 adapter
->nic_ops
= &qlcnic_vf_ops
;
578 adapter
->nic_ops
= &qlcnic_ops
;
582 qlcnic_setup_pci_map(struct qlcnic_adapter
*adapter
)
584 void __iomem
*mem_ptr0
= NULL
;
585 resource_size_t mem_base
;
586 unsigned long mem_len
, pci_len0
= 0;
588 struct pci_dev
*pdev
= adapter
->pdev
;
590 /* remap phys address */
591 mem_base
= pci_resource_start(pdev
, 0); /* 0 is for BAR 0 */
592 mem_len
= pci_resource_len(pdev
, 0);
594 if (mem_len
== QLCNIC_PCI_2MB_SIZE
) {
596 mem_ptr0
= pci_ioremap_bar(pdev
, 0);
597 if (mem_ptr0
== NULL
) {
598 dev_err(&pdev
->dev
, "failed to map PCI bar 0\n");
606 dev_info(&pdev
->dev
, "%dMB memory map\n", (int)(mem_len
>>20));
608 adapter
->ahw
->pci_base0
= mem_ptr0
;
609 adapter
->ahw
->pci_len0
= pci_len0
;
611 qlcnic_check_vf(adapter
);
613 adapter
->ahw
->ocm_win_crb
= qlcnic_get_ioaddr(adapter
,
614 QLCNIC_PCIX_PS_REG(PCIX_OCM_WINDOW_REG(
615 adapter
->ahw
->pci_func
)));
620 static void get_brd_name(struct qlcnic_adapter
*adapter
, char *name
)
622 struct pci_dev
*pdev
= adapter
->pdev
;
625 for (i
= 0; i
< NUM_SUPPORTED_BOARDS
; ++i
) {
626 if (qlcnic_boards
[i
].vendor
== pdev
->vendor
&&
627 qlcnic_boards
[i
].device
== pdev
->device
&&
628 qlcnic_boards
[i
].sub_vendor
== pdev
->subsystem_vendor
&&
629 qlcnic_boards
[i
].sub_device
== pdev
->subsystem_device
) {
630 sprintf(name
, "%pM: %s" ,
632 qlcnic_boards
[i
].short_name
);
640 sprintf(name
, "%pM Gigabit Ethernet", adapter
->mac_addr
);
644 qlcnic_check_options(struct qlcnic_adapter
*adapter
)
646 u32 fw_major
, fw_minor
, fw_build
;
647 struct pci_dev
*pdev
= adapter
->pdev
;
649 fw_major
= QLCRD32(adapter
, QLCNIC_FW_VERSION_MAJOR
);
650 fw_minor
= QLCRD32(adapter
, QLCNIC_FW_VERSION_MINOR
);
651 fw_build
= QLCRD32(adapter
, QLCNIC_FW_VERSION_SUB
);
653 adapter
->fw_version
= QLCNIC_VERSION_CODE(fw_major
, fw_minor
, fw_build
);
655 dev_info(&pdev
->dev
, "firmware v%d.%d.%d\n",
656 fw_major
, fw_minor
, fw_build
);
657 if (adapter
->ahw
->port_type
== QLCNIC_XGBE
) {
658 if (adapter
->flags
& QLCNIC_ESWITCH_ENABLED
) {
659 adapter
->num_rxd
= DEFAULT_RCV_DESCRIPTORS_VF
;
660 adapter
->max_rxd
= MAX_RCV_DESCRIPTORS_VF
;
662 adapter
->num_rxd
= DEFAULT_RCV_DESCRIPTORS_10G
;
663 adapter
->max_rxd
= MAX_RCV_DESCRIPTORS_10G
;
666 adapter
->num_jumbo_rxd
= MAX_JUMBO_RCV_DESCRIPTORS_10G
;
667 adapter
->max_jumbo_rxd
= MAX_JUMBO_RCV_DESCRIPTORS_10G
;
669 } else if (adapter
->ahw
->port_type
== QLCNIC_GBE
) {
670 adapter
->num_rxd
= DEFAULT_RCV_DESCRIPTORS_1G
;
671 adapter
->num_jumbo_rxd
= MAX_JUMBO_RCV_DESCRIPTORS_1G
;
672 adapter
->max_jumbo_rxd
= MAX_JUMBO_RCV_DESCRIPTORS_1G
;
673 adapter
->max_rxd
= MAX_RCV_DESCRIPTORS_1G
;
676 adapter
->msix_supported
= !!use_msi_x
;
678 adapter
->num_txd
= MAX_CMD_DESCRIPTORS
;
680 adapter
->max_rds_rings
= MAX_RDS_RINGS
;
684 qlcnic_initialize_nic(struct qlcnic_adapter
*adapter
)
687 struct qlcnic_info nic_info
;
689 err
= qlcnic_get_nic_info(adapter
, &nic_info
, adapter
->ahw
->pci_func
);
693 adapter
->physical_port
= (u8
)nic_info
.phys_port
;
694 adapter
->switch_mode
= nic_info
.switch_mode
;
695 adapter
->max_tx_ques
= nic_info
.max_tx_ques
;
696 adapter
->max_rx_ques
= nic_info
.max_rx_ques
;
697 adapter
->capabilities
= nic_info
.capabilities
;
698 adapter
->max_mac_filters
= nic_info
.max_mac_filters
;
699 adapter
->max_mtu
= nic_info
.max_mtu
;
701 if (adapter
->capabilities
& BIT_6
)
702 adapter
->flags
|= QLCNIC_ESWITCH_ENABLED
;
704 adapter
->flags
&= ~QLCNIC_ESWITCH_ENABLED
;
710 qlcnic_set_vlan_config(struct qlcnic_adapter
*adapter
,
711 struct qlcnic_esw_func_cfg
*esw_cfg
)
713 if (esw_cfg
->discard_tagged
)
714 adapter
->flags
&= ~QLCNIC_TAGGING_ENABLED
;
716 adapter
->flags
|= QLCNIC_TAGGING_ENABLED
;
718 if (esw_cfg
->vlan_id
)
719 adapter
->pvid
= esw_cfg
->vlan_id
;
725 qlcnic_vlan_rx_add(struct net_device
*netdev
, u16 vid
)
727 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
728 set_bit(vid
, adapter
->vlans
);
732 qlcnic_vlan_rx_del(struct net_device
*netdev
, u16 vid
)
734 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
736 qlcnic_restore_indev_addr(netdev
, NETDEV_DOWN
);
737 clear_bit(vid
, adapter
->vlans
);
741 qlcnic_set_eswitch_port_features(struct qlcnic_adapter
*adapter
,
742 struct qlcnic_esw_func_cfg
*esw_cfg
)
744 adapter
->flags
&= ~(QLCNIC_MACSPOOF
| QLCNIC_MAC_OVERRIDE_DISABLED
|
745 QLCNIC_PROMISC_DISABLED
);
747 if (esw_cfg
->mac_anti_spoof
)
748 adapter
->flags
|= QLCNIC_MACSPOOF
;
750 if (!esw_cfg
->mac_override
)
751 adapter
->flags
|= QLCNIC_MAC_OVERRIDE_DISABLED
;
753 if (!esw_cfg
->promisc_mode
)
754 adapter
->flags
|= QLCNIC_PROMISC_DISABLED
;
756 qlcnic_set_netdev_features(adapter
, esw_cfg
);
760 qlcnic_set_eswitch_port_config(struct qlcnic_adapter
*adapter
)
762 struct qlcnic_esw_func_cfg esw_cfg
;
764 if (!(adapter
->flags
& QLCNIC_ESWITCH_ENABLED
))
767 esw_cfg
.pci_func
= adapter
->ahw
->pci_func
;
768 if (qlcnic_get_eswitch_port_config(adapter
, &esw_cfg
))
770 qlcnic_set_vlan_config(adapter
, &esw_cfg
);
771 qlcnic_set_eswitch_port_features(adapter
, &esw_cfg
);
777 qlcnic_set_netdev_features(struct qlcnic_adapter
*adapter
,
778 struct qlcnic_esw_func_cfg
*esw_cfg
)
780 struct net_device
*netdev
= adapter
->netdev
;
781 unsigned long features
, vlan_features
;
783 features
= (NETIF_F_SG
| NETIF_F_IP_CSUM
| NETIF_F_RXCSUM
|
784 NETIF_F_IPV6_CSUM
| NETIF_F_GRO
);
785 vlan_features
= (NETIF_F_SG
| NETIF_F_IP_CSUM
|
786 NETIF_F_IPV6_CSUM
| NETIF_F_HW_VLAN_FILTER
);
788 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_TSO
) {
789 features
|= (NETIF_F_TSO
| NETIF_F_TSO6
);
790 vlan_features
|= (NETIF_F_TSO
| NETIF_F_TSO6
);
793 if (netdev
->features
& NETIF_F_LRO
)
794 features
|= NETIF_F_LRO
;
796 if (esw_cfg
->offload_flags
& BIT_0
) {
797 netdev
->features
|= features
;
798 if (!(esw_cfg
->offload_flags
& BIT_1
))
799 netdev
->features
&= ~NETIF_F_TSO
;
800 if (!(esw_cfg
->offload_flags
& BIT_2
))
801 netdev
->features
&= ~NETIF_F_TSO6
;
803 netdev
->features
&= ~features
;
806 netdev
->vlan_features
= (features
& vlan_features
);
810 qlcnic_check_eswitch_mode(struct qlcnic_adapter
*adapter
)
812 void __iomem
*priv_op
;
813 u32 op_mode
, priv_level
;
816 err
= qlcnic_initialize_nic(adapter
);
820 if (adapter
->flags
& QLCNIC_ADAPTER_INITIALIZED
)
823 priv_op
= adapter
->ahw
->pci_base0
+ QLCNIC_DRV_OP_MODE
;
824 op_mode
= readl(priv_op
);
825 priv_level
= QLC_DEV_GET_DRV(op_mode
, adapter
->ahw
->pci_func
);
827 if (op_mode
== QLC_DEV_DRV_DEFAULT
)
828 priv_level
= QLCNIC_MGMT_FUNC
;
830 priv_level
= QLC_DEV_GET_DRV(op_mode
, adapter
->ahw
->pci_func
);
832 if (adapter
->flags
& QLCNIC_ESWITCH_ENABLED
) {
833 if (priv_level
== QLCNIC_MGMT_FUNC
) {
834 adapter
->op_mode
= QLCNIC_MGMT_FUNC
;
835 err
= qlcnic_init_pci_info(adapter
);
838 /* Set privilege level for other functions */
839 qlcnic_set_function_modes(adapter
);
840 dev_info(&adapter
->pdev
->dev
,
841 "HAL Version: %d, Management function\n",
842 adapter
->fw_hal_version
);
843 } else if (priv_level
== QLCNIC_PRIV_FUNC
) {
844 adapter
->op_mode
= QLCNIC_PRIV_FUNC
;
845 dev_info(&adapter
->pdev
->dev
,
846 "HAL Version: %d, Privileged function\n",
847 adapter
->fw_hal_version
);
851 adapter
->flags
|= QLCNIC_ADAPTER_INITIALIZED
;
857 qlcnic_set_default_offload_settings(struct qlcnic_adapter
*adapter
)
859 struct qlcnic_esw_func_cfg esw_cfg
;
860 struct qlcnic_npar_info
*npar
;
863 if (adapter
->need_fw_reset
)
866 for (i
= 0; i
< QLCNIC_MAX_PCI_FUNC
; i
++) {
867 if (adapter
->npars
[i
].type
!= QLCNIC_TYPE_NIC
)
869 memset(&esw_cfg
, 0, sizeof(struct qlcnic_esw_func_cfg
));
870 esw_cfg
.pci_func
= i
;
871 esw_cfg
.offload_flags
= BIT_0
;
872 esw_cfg
.mac_override
= BIT_0
;
873 esw_cfg
.promisc_mode
= BIT_0
;
874 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_TSO
)
875 esw_cfg
.offload_flags
|= (BIT_1
| BIT_2
);
876 if (qlcnic_config_switch_port(adapter
, &esw_cfg
))
878 npar
= &adapter
->npars
[i
];
879 npar
->pvid
= esw_cfg
.vlan_id
;
880 npar
->mac_override
= esw_cfg
.mac_override
;
881 npar
->mac_anti_spoof
= esw_cfg
.mac_anti_spoof
;
882 npar
->discard_tagged
= esw_cfg
.discard_tagged
;
883 npar
->promisc_mode
= esw_cfg
.promisc_mode
;
884 npar
->offload_flags
= esw_cfg
.offload_flags
;
891 qlcnic_reset_eswitch_config(struct qlcnic_adapter
*adapter
,
892 struct qlcnic_npar_info
*npar
, int pci_func
)
894 struct qlcnic_esw_func_cfg esw_cfg
;
895 esw_cfg
.op_mode
= QLCNIC_PORT_DEFAULTS
;
896 esw_cfg
.pci_func
= pci_func
;
897 esw_cfg
.vlan_id
= npar
->pvid
;
898 esw_cfg
.mac_override
= npar
->mac_override
;
899 esw_cfg
.discard_tagged
= npar
->discard_tagged
;
900 esw_cfg
.mac_anti_spoof
= npar
->mac_anti_spoof
;
901 esw_cfg
.offload_flags
= npar
->offload_flags
;
902 esw_cfg
.promisc_mode
= npar
->promisc_mode
;
903 if (qlcnic_config_switch_port(adapter
, &esw_cfg
))
906 esw_cfg
.op_mode
= QLCNIC_ADD_VLAN
;
907 if (qlcnic_config_switch_port(adapter
, &esw_cfg
))
914 qlcnic_reset_npar_config(struct qlcnic_adapter
*adapter
)
917 struct qlcnic_npar_info
*npar
;
918 struct qlcnic_info nic_info
;
920 if (!adapter
->need_fw_reset
)
923 /* Set the NPAR config data after FW reset */
924 for (i
= 0; i
< QLCNIC_MAX_PCI_FUNC
; i
++) {
925 npar
= &adapter
->npars
[i
];
926 if (npar
->type
!= QLCNIC_TYPE_NIC
)
928 err
= qlcnic_get_nic_info(adapter
, &nic_info
, i
);
931 nic_info
.min_tx_bw
= npar
->min_bw
;
932 nic_info
.max_tx_bw
= npar
->max_bw
;
933 err
= qlcnic_set_nic_info(adapter
, &nic_info
);
937 if (npar
->enable_pm
) {
938 err
= qlcnic_config_port_mirroring(adapter
,
939 npar
->dest_npar
, 1, i
);
943 err
= qlcnic_reset_eswitch_config(adapter
, npar
, i
);
950 static int qlcnic_check_npar_opertional(struct qlcnic_adapter
*adapter
)
952 u8 npar_opt_timeo
= QLCNIC_DEV_NPAR_OPER_TIMEO
;
955 if (adapter
->op_mode
== QLCNIC_MGMT_FUNC
)
958 npar_state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_NPAR_STATE
);
959 while (npar_state
!= QLCNIC_DEV_NPAR_OPER
&& --npar_opt_timeo
) {
961 npar_state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_NPAR_STATE
);
963 if (!npar_opt_timeo
) {
964 dev_err(&adapter
->pdev
->dev
,
965 "Waiting for NPAR state to opertional timeout\n");
972 qlcnic_set_mgmt_operations(struct qlcnic_adapter
*adapter
)
976 if (!(adapter
->flags
& QLCNIC_ESWITCH_ENABLED
) ||
977 adapter
->op_mode
!= QLCNIC_MGMT_FUNC
)
980 err
= qlcnic_set_default_offload_settings(adapter
);
984 err
= qlcnic_reset_npar_config(adapter
);
988 qlcnic_dev_set_npar_ready(adapter
);
994 qlcnic_start_firmware(struct qlcnic_adapter
*adapter
)
998 err
= qlcnic_can_start_firmware(adapter
);
1002 goto check_fw_status
;
1005 qlcnic_request_firmware(adapter
);
1007 err
= qlcnic_check_flash_fw_ver(adapter
);
1011 adapter
->fw_type
= QLCNIC_FLASH_ROMIMAGE
;
1014 err
= qlcnic_need_fw_reset(adapter
);
1016 goto check_fw_status
;
1018 err
= qlcnic_pinit_from_rom(adapter
);
1022 err
= qlcnic_load_firmware(adapter
);
1026 qlcnic_release_firmware(adapter
);
1027 QLCWR32(adapter
, CRB_DRIVER_VERSION
, QLCNIC_DRIVER_VERSION
);
1030 err
= qlcnic_check_fw_status(adapter
);
1034 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
, QLCNIC_DEV_READY
);
1035 qlcnic_idc_debug_info(adapter
, 1);
1037 err
= qlcnic_check_eswitch_mode(adapter
);
1039 dev_err(&adapter
->pdev
->dev
,
1040 "Memory allocation failed for eswitch\n");
1043 err
= qlcnic_set_mgmt_operations(adapter
);
1047 qlcnic_check_options(adapter
);
1048 adapter
->need_fw_reset
= 0;
1050 qlcnic_release_firmware(adapter
);
1054 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
, QLCNIC_DEV_FAILED
);
1055 dev_err(&adapter
->pdev
->dev
, "Device state set to failed\n");
1057 qlcnic_release_firmware(adapter
);
1062 qlcnic_request_irq(struct qlcnic_adapter
*adapter
)
1064 irq_handler_t handler
;
1065 struct qlcnic_host_sds_ring
*sds_ring
;
1068 unsigned long flags
= 0;
1069 struct net_device
*netdev
= adapter
->netdev
;
1070 struct qlcnic_recv_context
*recv_ctx
= adapter
->recv_ctx
;
1072 if (adapter
->diag_test
== QLCNIC_INTERRUPT_TEST
) {
1073 handler
= qlcnic_tmp_intr
;
1074 if (!QLCNIC_IS_MSI_FAMILY(adapter
))
1075 flags
|= IRQF_SHARED
;
1078 if (adapter
->flags
& QLCNIC_MSIX_ENABLED
)
1079 handler
= qlcnic_msix_intr
;
1080 else if (adapter
->flags
& QLCNIC_MSI_ENABLED
)
1081 handler
= qlcnic_msi_intr
;
1083 flags
|= IRQF_SHARED
;
1084 handler
= qlcnic_intr
;
1087 adapter
->irq
= netdev
->irq
;
1089 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
1090 sds_ring
= &recv_ctx
->sds_rings
[ring
];
1091 sprintf(sds_ring
->name
, "%s[%d]", netdev
->name
, ring
);
1092 err
= request_irq(sds_ring
->irq
, handler
,
1093 flags
, sds_ring
->name
, sds_ring
);
1102 qlcnic_free_irq(struct qlcnic_adapter
*adapter
)
1105 struct qlcnic_host_sds_ring
*sds_ring
;
1107 struct qlcnic_recv_context
*recv_ctx
= adapter
->recv_ctx
;
1109 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
1110 sds_ring
= &recv_ctx
->sds_rings
[ring
];
1111 free_irq(sds_ring
->irq
, sds_ring
);
1116 __qlcnic_up(struct qlcnic_adapter
*adapter
, struct net_device
*netdev
)
1119 struct qlcnic_host_rds_ring
*rds_ring
;
1121 if (adapter
->is_up
!= QLCNIC_ADAPTER_UP_MAGIC
)
1124 if (test_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
1126 if (qlcnic_set_eswitch_port_config(adapter
))
1129 if (qlcnic_fw_create_ctx(adapter
))
1132 for (ring
= 0; ring
< adapter
->max_rds_rings
; ring
++) {
1133 rds_ring
= &adapter
->recv_ctx
->rds_rings
[ring
];
1134 qlcnic_post_rx_buffers(adapter
, rds_ring
);
1137 qlcnic_set_multi(netdev
);
1138 qlcnic_fw_cmd_set_mtu(adapter
, netdev
->mtu
);
1140 adapter
->ahw
->linkup
= 0;
1142 if (adapter
->max_sds_rings
> 1)
1143 qlcnic_config_rss(adapter
, 1);
1145 qlcnic_config_intr_coalesce(adapter
);
1147 if (netdev
->features
& NETIF_F_LRO
)
1148 qlcnic_config_hw_lro(adapter
, QLCNIC_LRO_ENABLED
);
1150 qlcnic_napi_enable(adapter
);
1152 qlcnic_linkevent_request(adapter
, 1);
1154 adapter
->reset_context
= 0;
1155 set_bit(__QLCNIC_DEV_UP
, &adapter
->state
);
1159 /* Usage: During resume and firmware recovery module.*/
1162 qlcnic_up(struct qlcnic_adapter
*adapter
, struct net_device
*netdev
)
1167 if (netif_running(netdev
))
1168 err
= __qlcnic_up(adapter
, netdev
);
1175 __qlcnic_down(struct qlcnic_adapter
*adapter
, struct net_device
*netdev
)
1177 if (adapter
->is_up
!= QLCNIC_ADAPTER_UP_MAGIC
)
1180 if (!test_and_clear_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
1184 spin_lock(&adapter
->tx_clean_lock
);
1185 netif_carrier_off(netdev
);
1186 netif_tx_disable(netdev
);
1188 qlcnic_free_mac_list(adapter
);
1190 if (adapter
->fhash
.fnum
)
1191 qlcnic_delete_lb_filters(adapter
);
1193 qlcnic_nic_set_promisc(adapter
, QLCNIC_NIU_NON_PROMISC_MODE
);
1195 qlcnic_napi_disable(adapter
);
1197 qlcnic_fw_destroy_ctx(adapter
);
1199 qlcnic_reset_rx_buffers_list(adapter
);
1200 qlcnic_release_tx_buffers(adapter
);
1201 spin_unlock(&adapter
->tx_clean_lock
);
1204 /* Usage: During suspend and firmware recovery module */
1207 qlcnic_down(struct qlcnic_adapter
*adapter
, struct net_device
*netdev
)
1210 if (netif_running(netdev
))
1211 __qlcnic_down(adapter
, netdev
);
1217 qlcnic_attach(struct qlcnic_adapter
*adapter
)
1219 struct net_device
*netdev
= adapter
->netdev
;
1220 struct pci_dev
*pdev
= adapter
->pdev
;
1223 if (adapter
->is_up
== QLCNIC_ADAPTER_UP_MAGIC
)
1226 err
= qlcnic_napi_add(adapter
, netdev
);
1230 err
= qlcnic_alloc_sw_resources(adapter
);
1232 dev_err(&pdev
->dev
, "Error in setting sw resources\n");
1233 goto err_out_napi_del
;
1236 err
= qlcnic_alloc_hw_resources(adapter
);
1238 dev_err(&pdev
->dev
, "Error in setting hw resources\n");
1239 goto err_out_free_sw
;
1242 err
= qlcnic_request_irq(adapter
);
1244 dev_err(&pdev
->dev
, "failed to setup interrupt\n");
1245 goto err_out_free_hw
;
1248 qlcnic_create_sysfs_entries(adapter
);
1250 adapter
->is_up
= QLCNIC_ADAPTER_UP_MAGIC
;
1254 qlcnic_free_hw_resources(adapter
);
1256 qlcnic_free_sw_resources(adapter
);
1258 qlcnic_napi_del(adapter
);
1263 qlcnic_detach(struct qlcnic_adapter
*adapter
)
1265 if (adapter
->is_up
!= QLCNIC_ADAPTER_UP_MAGIC
)
1268 qlcnic_remove_sysfs_entries(adapter
);
1270 qlcnic_free_hw_resources(adapter
);
1271 qlcnic_release_rx_buffers(adapter
);
1272 qlcnic_free_irq(adapter
);
1273 qlcnic_napi_del(adapter
);
1274 qlcnic_free_sw_resources(adapter
);
1279 void qlcnic_diag_free_res(struct net_device
*netdev
, int max_sds_rings
)
1281 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
1282 struct qlcnic_host_sds_ring
*sds_ring
;
1285 clear_bit(__QLCNIC_DEV_UP
, &adapter
->state
);
1286 if (adapter
->diag_test
== QLCNIC_INTERRUPT_TEST
) {
1287 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
1288 sds_ring
= &adapter
->recv_ctx
->sds_rings
[ring
];
1289 qlcnic_disable_int(sds_ring
);
1293 qlcnic_fw_destroy_ctx(adapter
);
1295 qlcnic_detach(adapter
);
1297 adapter
->diag_test
= 0;
1298 adapter
->max_sds_rings
= max_sds_rings
;
1300 if (qlcnic_attach(adapter
))
1303 if (netif_running(netdev
))
1304 __qlcnic_up(adapter
, netdev
);
1306 netif_device_attach(netdev
);
1309 static int qlcnic_alloc_adapter_resources(struct qlcnic_adapter
*adapter
)
1312 adapter
->ahw
= kzalloc(sizeof(struct qlcnic_hardware_context
),
1314 if (!adapter
->ahw
) {
1315 dev_err(&adapter
->pdev
->dev
,
1316 "Failed to allocate recv ctx resources for adapter\n");
1320 adapter
->recv_ctx
= kzalloc(sizeof(struct qlcnic_recv_context
),
1322 if (!adapter
->recv_ctx
) {
1323 dev_err(&adapter
->pdev
->dev
,
1324 "Failed to allocate recv ctx resources for adapter\n");
1325 kfree(adapter
->ahw
);
1326 adapter
->ahw
= NULL
;
1330 /* Initialize interrupt coalesce parameters */
1331 adapter
->ahw
->coal
.flag
= QLCNIC_INTR_DEFAULT
;
1332 adapter
->ahw
->coal
.rx_time_us
= QLCNIC_DEFAULT_INTR_COALESCE_RX_TIME_US
;
1333 adapter
->ahw
->coal
.rx_packets
= QLCNIC_DEFAULT_INTR_COALESCE_RX_PACKETS
;
1338 static void qlcnic_free_adapter_resources(struct qlcnic_adapter
*adapter
)
1340 kfree(adapter
->recv_ctx
);
1341 adapter
->recv_ctx
= NULL
;
1343 if (adapter
->ahw
->fw_dump
.tmpl_hdr
) {
1344 vfree(adapter
->ahw
->fw_dump
.tmpl_hdr
);
1345 adapter
->ahw
->fw_dump
.tmpl_hdr
= NULL
;
1347 kfree(adapter
->ahw
);
1348 adapter
->ahw
= NULL
;
1351 int qlcnic_diag_alloc_res(struct net_device
*netdev
, int test
)
1353 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
1354 struct qlcnic_host_sds_ring
*sds_ring
;
1355 struct qlcnic_host_rds_ring
*rds_ring
;
1359 netif_device_detach(netdev
);
1361 if (netif_running(netdev
))
1362 __qlcnic_down(adapter
, netdev
);
1364 qlcnic_detach(adapter
);
1366 adapter
->max_sds_rings
= 1;
1367 adapter
->diag_test
= test
;
1369 ret
= qlcnic_attach(adapter
);
1371 netif_device_attach(netdev
);
1375 ret
= qlcnic_fw_create_ctx(adapter
);
1377 qlcnic_detach(adapter
);
1378 netif_device_attach(netdev
);
1382 for (ring
= 0; ring
< adapter
->max_rds_rings
; ring
++) {
1383 rds_ring
= &adapter
->recv_ctx
->rds_rings
[ring
];
1384 qlcnic_post_rx_buffers(adapter
, rds_ring
);
1387 if (adapter
->diag_test
== QLCNIC_INTERRUPT_TEST
) {
1388 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
1389 sds_ring
= &adapter
->recv_ctx
->sds_rings
[ring
];
1390 qlcnic_enable_int(sds_ring
);
1394 if (adapter
->diag_test
== QLCNIC_LOOPBACK_TEST
) {
1395 adapter
->ahw
->loopback_state
= 0;
1396 qlcnic_linkevent_request(adapter
, 1);
1399 set_bit(__QLCNIC_DEV_UP
, &adapter
->state
);
1404 /* Reset context in hardware only */
1406 qlcnic_reset_hw_context(struct qlcnic_adapter
*adapter
)
1408 struct net_device
*netdev
= adapter
->netdev
;
1410 if (test_and_set_bit(__QLCNIC_RESETTING
, &adapter
->state
))
1413 netif_device_detach(netdev
);
1415 qlcnic_down(adapter
, netdev
);
1417 qlcnic_up(adapter
, netdev
);
1419 netif_device_attach(netdev
);
1421 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
1426 qlcnic_reset_context(struct qlcnic_adapter
*adapter
)
1429 struct net_device
*netdev
= adapter
->netdev
;
1431 if (test_and_set_bit(__QLCNIC_RESETTING
, &adapter
->state
))
1434 if (adapter
->is_up
== QLCNIC_ADAPTER_UP_MAGIC
) {
1436 netif_device_detach(netdev
);
1438 if (netif_running(netdev
))
1439 __qlcnic_down(adapter
, netdev
);
1441 qlcnic_detach(adapter
);
1443 if (netif_running(netdev
)) {
1444 err
= qlcnic_attach(adapter
);
1446 __qlcnic_up(adapter
, netdev
);
1449 netif_device_attach(netdev
);
1452 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
1457 qlcnic_setup_netdev(struct qlcnic_adapter
*adapter
,
1458 struct net_device
*netdev
, u8 pci_using_dac
)
1461 struct pci_dev
*pdev
= adapter
->pdev
;
1463 adapter
->mc_enabled
= 0;
1464 adapter
->max_mc_count
= 38;
1466 netdev
->netdev_ops
= &qlcnic_netdev_ops
;
1467 netdev
->watchdog_timeo
= 5*HZ
;
1469 qlcnic_change_mtu(netdev
, netdev
->mtu
);
1471 SET_ETHTOOL_OPS(netdev
, &qlcnic_ethtool_ops
);
1473 netdev
->hw_features
= NETIF_F_SG
| NETIF_F_IP_CSUM
|
1474 NETIF_F_IPV6_CSUM
| NETIF_F_RXCSUM
;
1476 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_TSO
)
1477 netdev
->hw_features
|= NETIF_F_TSO
| NETIF_F_TSO6
;
1479 netdev
->hw_features
|= NETIF_F_HIGHDMA
;
1481 netdev
->vlan_features
= netdev
->hw_features
;
1483 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_FVLANTX
)
1484 netdev
->hw_features
|= NETIF_F_HW_VLAN_TX
;
1485 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_HW_LRO
)
1486 netdev
->hw_features
|= NETIF_F_LRO
;
1488 netdev
->features
|= netdev
->hw_features
|
1489 NETIF_F_HW_VLAN_RX
| NETIF_F_HW_VLAN_FILTER
;
1491 netdev
->irq
= adapter
->msix_entries
[0].vector
;
1493 err
= register_netdev(netdev
);
1495 dev_err(&pdev
->dev
, "failed to register net device\n");
1502 static int qlcnic_set_dma_mask(struct pci_dev
*pdev
, u8
*pci_using_dac
)
1504 if (!pci_set_dma_mask(pdev
, DMA_BIT_MASK(64)) &&
1505 !pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(64)))
1507 else if (!pci_set_dma_mask(pdev
, DMA_BIT_MASK(32)) &&
1508 !pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(32)))
1511 dev_err(&pdev
->dev
, "Unable to set DMA mask, aborting\n");
1519 qlcnic_alloc_msix_entries(struct qlcnic_adapter
*adapter
, u16 count
)
1521 adapter
->msix_entries
= kcalloc(count
, sizeof(struct msix_entry
),
1524 if (adapter
->msix_entries
)
1527 dev_err(&adapter
->pdev
->dev
, "failed allocating msix_entries\n");
1531 static int __devinit
1532 qlcnic_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
1534 struct net_device
*netdev
= NULL
;
1535 struct qlcnic_adapter
*adapter
= NULL
;
1537 uint8_t revision_id
;
1538 uint8_t pci_using_dac
;
1539 char brd_name
[QLCNIC_MAX_BOARD_NAME_LEN
];
1541 err
= pci_enable_device(pdev
);
1545 if (!(pci_resource_flags(pdev
, 0) & IORESOURCE_MEM
)) {
1547 goto err_out_disable_pdev
;
1550 err
= qlcnic_set_dma_mask(pdev
, &pci_using_dac
);
1552 goto err_out_disable_pdev
;
1554 err
= pci_request_regions(pdev
, qlcnic_driver_name
);
1556 goto err_out_disable_pdev
;
1558 pci_set_master(pdev
);
1559 pci_enable_pcie_error_reporting(pdev
);
1561 netdev
= alloc_etherdev(sizeof(struct qlcnic_adapter
));
1563 dev_err(&pdev
->dev
, "failed to allocate net_device\n");
1565 goto err_out_free_res
;
1568 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
1570 adapter
= netdev_priv(netdev
);
1571 adapter
->netdev
= netdev
;
1572 adapter
->pdev
= pdev
;
1574 if (qlcnic_alloc_adapter_resources(adapter
))
1575 goto err_out_free_netdev
;
1577 adapter
->dev_rst_time
= jiffies
;
1578 revision_id
= pdev
->revision
;
1579 adapter
->ahw
->revision_id
= revision_id
;
1580 adapter
->mac_learn
= qlcnic_mac_learn
;
1582 rwlock_init(&adapter
->ahw
->crb_lock
);
1583 mutex_init(&adapter
->ahw
->mem_lock
);
1585 spin_lock_init(&adapter
->tx_clean_lock
);
1586 INIT_LIST_HEAD(&adapter
->mac_list
);
1588 err
= qlcnic_setup_pci_map(adapter
);
1590 goto err_out_free_hw
;
1592 /* This will be reset for mezz cards */
1593 adapter
->portnum
= adapter
->ahw
->pci_func
;
1595 err
= qlcnic_get_board_info(adapter
);
1597 dev_err(&pdev
->dev
, "Error getting board config info.\n");
1598 goto err_out_iounmap
;
1601 err
= qlcnic_setup_idc_param(adapter
);
1603 goto err_out_iounmap
;
1605 adapter
->flags
|= QLCNIC_NEED_FLR
;
1607 err
= adapter
->nic_ops
->start_firmware(adapter
);
1609 dev_err(&pdev
->dev
, "Loading fw failed.Please Reboot\n");
1610 goto err_out_decr_ref
;
1613 /* Get FW dump template and store it */
1614 if (adapter
->op_mode
!= QLCNIC_NON_PRIV_FUNC
)
1615 if (!qlcnic_fw_cmd_get_minidump_temp(adapter
))
1616 dev_info(&pdev
->dev
,
1617 "Supports FW dump capability\n");
1619 if (qlcnic_read_mac_addr(adapter
))
1620 dev_warn(&pdev
->dev
, "failed to read mac addr\n");
1622 if (adapter
->portnum
== 0) {
1623 get_brd_name(adapter
, brd_name
);
1625 pr_info("%s: %s Board Chip rev 0x%x\n",
1626 module_name(THIS_MODULE
),
1627 brd_name
, adapter
->ahw
->revision_id
);
1630 qlcnic_clear_stats(adapter
);
1632 err
= qlcnic_alloc_msix_entries(adapter
, adapter
->max_rx_ques
);
1634 goto err_out_decr_ref
;
1636 qlcnic_setup_intr(adapter
);
1638 err
= qlcnic_setup_netdev(adapter
, netdev
, pci_using_dac
);
1640 goto err_out_disable_msi
;
1642 pci_set_drvdata(pdev
, adapter
);
1644 qlcnic_schedule_work(adapter
, qlcnic_fw_poll_work
, FW_POLL_DELAY
);
1646 switch (adapter
->ahw
->port_type
) {
1648 dev_info(&adapter
->pdev
->dev
, "%s: GbE port initialized\n",
1649 adapter
->netdev
->name
);
1652 dev_info(&adapter
->pdev
->dev
, "%s: XGbE port initialized\n",
1653 adapter
->netdev
->name
);
1657 if (adapter
->mac_learn
)
1658 qlcnic_alloc_lb_filters_mem(adapter
);
1660 qlcnic_create_diag_entries(adapter
);
1664 err_out_disable_msi
:
1665 qlcnic_teardown_intr(adapter
);
1666 kfree(adapter
->msix_entries
);
1669 qlcnic_clr_all_drv_state(adapter
, 0);
1672 qlcnic_cleanup_pci_map(adapter
);
1675 qlcnic_free_adapter_resources(adapter
);
1677 err_out_free_netdev
:
1678 free_netdev(netdev
);
1681 pci_release_regions(pdev
);
1683 err_out_disable_pdev
:
1684 pci_set_drvdata(pdev
, NULL
);
1685 pci_disable_device(pdev
);
1689 static void __devexit
qlcnic_remove(struct pci_dev
*pdev
)
1691 struct qlcnic_adapter
*adapter
;
1692 struct net_device
*netdev
;
1694 adapter
= pci_get_drvdata(pdev
);
1695 if (adapter
== NULL
)
1698 netdev
= adapter
->netdev
;
1700 qlcnic_cancel_fw_work(adapter
);
1702 unregister_netdev(netdev
);
1704 qlcnic_detach(adapter
);
1706 if (adapter
->npars
!= NULL
)
1707 kfree(adapter
->npars
);
1708 if (adapter
->eswitch
!= NULL
)
1709 kfree(adapter
->eswitch
);
1711 qlcnic_clr_all_drv_state(adapter
, 0);
1713 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
1715 qlcnic_free_lb_filters_mem(adapter
);
1717 qlcnic_teardown_intr(adapter
);
1718 kfree(adapter
->msix_entries
);
1720 qlcnic_remove_diag_entries(adapter
);
1722 qlcnic_cleanup_pci_map(adapter
);
1724 qlcnic_release_firmware(adapter
);
1726 pci_disable_pcie_error_reporting(pdev
);
1727 pci_release_regions(pdev
);
1728 pci_disable_device(pdev
);
1729 pci_set_drvdata(pdev
, NULL
);
1731 qlcnic_free_adapter_resources(adapter
);
1732 free_netdev(netdev
);
1734 static int __qlcnic_shutdown(struct pci_dev
*pdev
)
1736 struct qlcnic_adapter
*adapter
= pci_get_drvdata(pdev
);
1737 struct net_device
*netdev
= adapter
->netdev
;
1740 netif_device_detach(netdev
);
1742 qlcnic_cancel_fw_work(adapter
);
1744 if (netif_running(netdev
))
1745 qlcnic_down(adapter
, netdev
);
1747 qlcnic_clr_all_drv_state(adapter
, 0);
1749 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
1751 retval
= pci_save_state(pdev
);
1755 if (qlcnic_wol_supported(adapter
)) {
1756 pci_enable_wake(pdev
, PCI_D3cold
, 1);
1757 pci_enable_wake(pdev
, PCI_D3hot
, 1);
1763 static void qlcnic_shutdown(struct pci_dev
*pdev
)
1765 if (__qlcnic_shutdown(pdev
))
1768 pci_disable_device(pdev
);
1773 qlcnic_suspend(struct pci_dev
*pdev
, pm_message_t state
)
1777 retval
= __qlcnic_shutdown(pdev
);
1781 pci_set_power_state(pdev
, pci_choose_state(pdev
, state
));
1786 qlcnic_resume(struct pci_dev
*pdev
)
1788 struct qlcnic_adapter
*adapter
= pci_get_drvdata(pdev
);
1789 struct net_device
*netdev
= adapter
->netdev
;
1792 err
= pci_enable_device(pdev
);
1796 pci_set_power_state(pdev
, PCI_D0
);
1797 pci_set_master(pdev
);
1798 pci_restore_state(pdev
);
1800 err
= adapter
->nic_ops
->start_firmware(adapter
);
1802 dev_err(&pdev
->dev
, "failed to start firmware\n");
1806 if (netif_running(netdev
)) {
1807 err
= qlcnic_up(adapter
, netdev
);
1811 qlcnic_restore_indev_addr(netdev
, NETDEV_UP
);
1814 netif_device_attach(netdev
);
1815 qlcnic_schedule_work(adapter
, qlcnic_fw_poll_work
, FW_POLL_DELAY
);
1820 static int qlcnic_open(struct net_device
*netdev
)
1822 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
1825 netif_carrier_off(netdev
);
1827 err
= qlcnic_attach(adapter
);
1831 err
= __qlcnic_up(adapter
, netdev
);
1835 netif_start_queue(netdev
);
1840 qlcnic_detach(adapter
);
1845 * qlcnic_close - Disables a network interface entry point
1847 static int qlcnic_close(struct net_device
*netdev
)
1849 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
1851 __qlcnic_down(adapter
, netdev
);
1855 void qlcnic_alloc_lb_filters_mem(struct qlcnic_adapter
*adapter
)
1860 if (adapter
->fhash
.fmax
&& adapter
->fhash
.fhead
)
1863 spin_lock_init(&adapter
->mac_learn_lock
);
1865 head
= kcalloc(QLCNIC_LB_MAX_FILTERS
, sizeof(struct hlist_head
),
1870 adapter
->fhash
.fmax
= QLCNIC_LB_MAX_FILTERS
;
1871 adapter
->fhash
.fhead
= head
;
1873 for (i
= 0; i
< adapter
->fhash
.fmax
; i
++)
1874 INIT_HLIST_HEAD(&adapter
->fhash
.fhead
[i
]);
1877 static void qlcnic_free_lb_filters_mem(struct qlcnic_adapter
*adapter
)
1879 if (adapter
->fhash
.fmax
&& adapter
->fhash
.fhead
)
1880 kfree(adapter
->fhash
.fhead
);
1882 adapter
->fhash
.fhead
= NULL
;
1883 adapter
->fhash
.fmax
= 0;
1886 static void qlcnic_change_filter(struct qlcnic_adapter
*adapter
,
1887 u64 uaddr
, __le16 vlan_id
, struct qlcnic_host_tx_ring
*tx_ring
)
1889 struct cmd_desc_type0
*hwdesc
;
1890 struct qlcnic_nic_req
*req
;
1891 struct qlcnic_mac_req
*mac_req
;
1892 struct qlcnic_vlan_req
*vlan_req
;
1896 producer
= tx_ring
->producer
;
1897 hwdesc
= &tx_ring
->desc_head
[tx_ring
->producer
];
1899 req
= (struct qlcnic_nic_req
*)hwdesc
;
1900 memset(req
, 0, sizeof(struct qlcnic_nic_req
));
1901 req
->qhdr
= cpu_to_le64(QLCNIC_REQUEST
<< 23);
1903 word
= QLCNIC_MAC_EVENT
| ((u64
)(adapter
->portnum
) << 16);
1904 req
->req_hdr
= cpu_to_le64(word
);
1906 mac_req
= (struct qlcnic_mac_req
*)&(req
->words
[0]);
1907 mac_req
->op
= vlan_id
? QLCNIC_MAC_VLAN_ADD
: QLCNIC_MAC_ADD
;
1908 memcpy(mac_req
->mac_addr
, &uaddr
, ETH_ALEN
);
1910 vlan_req
= (struct qlcnic_vlan_req
*)&req
->words
[1];
1911 vlan_req
->vlan_id
= vlan_id
;
1913 tx_ring
->producer
= get_next_index(producer
, tx_ring
->num_desc
);
1917 #define QLCNIC_MAC_HASH(MAC)\
1918 ((((MAC) & 0x70000) >> 0x10) | (((MAC) & 0x70000000000ULL) >> 0x25))
1921 qlcnic_send_filter(struct qlcnic_adapter
*adapter
,
1922 struct qlcnic_host_tx_ring
*tx_ring
,
1923 struct cmd_desc_type0
*first_desc
,
1924 struct sk_buff
*skb
)
1926 struct ethhdr
*phdr
= (struct ethhdr
*)(skb
->data
);
1927 struct qlcnic_filter
*fil
, *tmp_fil
;
1928 struct hlist_node
*tmp_hnode
, *n
;
1929 struct hlist_head
*head
;
1934 if (!compare_ether_addr(phdr
->h_source
, adapter
->mac_addr
))
1937 if (adapter
->fhash
.fnum
>= adapter
->fhash
.fmax
)
1940 /* Only NPAR capable devices support vlan based learning*/
1941 if (adapter
->flags
& QLCNIC_ESWITCH_ENABLED
)
1942 vlan_id
= first_desc
->vlan_TCI
;
1943 memcpy(&src_addr
, phdr
->h_source
, ETH_ALEN
);
1944 hindex
= QLCNIC_MAC_HASH(src_addr
) & (QLCNIC_LB_MAX_FILTERS
- 1);
1945 head
= &(adapter
->fhash
.fhead
[hindex
]);
1947 hlist_for_each_entry_safe(tmp_fil
, tmp_hnode
, n
, head
, fnode
) {
1948 if (!memcmp(tmp_fil
->faddr
, &src_addr
, ETH_ALEN
) &&
1949 tmp_fil
->vlan_id
== vlan_id
) {
1952 (QLCNIC_READD_AGE
* HZ
+ tmp_fil
->ftime
))
1953 qlcnic_change_filter(adapter
, src_addr
, vlan_id
,
1955 tmp_fil
->ftime
= jiffies
;
1960 fil
= kzalloc(sizeof(struct qlcnic_filter
), GFP_ATOMIC
);
1964 qlcnic_change_filter(adapter
, src_addr
, vlan_id
, tx_ring
);
1966 fil
->ftime
= jiffies
;
1967 fil
->vlan_id
= vlan_id
;
1968 memcpy(fil
->faddr
, &src_addr
, ETH_ALEN
);
1969 spin_lock(&adapter
->mac_learn_lock
);
1970 hlist_add_head(&(fil
->fnode
), head
);
1971 adapter
->fhash
.fnum
++;
1972 spin_unlock(&adapter
->mac_learn_lock
);
1976 qlcnic_tx_pkt(struct qlcnic_adapter
*adapter
,
1977 struct cmd_desc_type0
*first_desc
,
1978 struct sk_buff
*skb
)
1980 u8 opcode
= 0, hdr_len
= 0;
1981 u16 flags
= 0, vlan_tci
= 0;
1982 int copied
, offset
, copy_len
;
1983 struct cmd_desc_type0
*hwdesc
;
1984 struct vlan_ethhdr
*vh
;
1985 struct qlcnic_host_tx_ring
*tx_ring
= adapter
->tx_ring
;
1986 u16 protocol
= ntohs(skb
->protocol
);
1987 u32 producer
= tx_ring
->producer
;
1989 if (protocol
== ETH_P_8021Q
) {
1990 vh
= (struct vlan_ethhdr
*)skb
->data
;
1991 flags
= FLAGS_VLAN_TAGGED
;
1992 vlan_tci
= vh
->h_vlan_TCI
;
1993 } else if (vlan_tx_tag_present(skb
)) {
1994 flags
= FLAGS_VLAN_OOB
;
1995 vlan_tci
= vlan_tx_tag_get(skb
);
1997 if (unlikely(adapter
->pvid
)) {
1998 if (vlan_tci
&& !(adapter
->flags
& QLCNIC_TAGGING_ENABLED
))
2000 if (vlan_tci
&& (adapter
->flags
& QLCNIC_TAGGING_ENABLED
))
2003 flags
= FLAGS_VLAN_OOB
;
2004 vlan_tci
= adapter
->pvid
;
2007 qlcnic_set_tx_vlan_tci(first_desc
, vlan_tci
);
2008 qlcnic_set_tx_flags_opcode(first_desc
, flags
, opcode
);
2010 if (*(skb
->data
) & BIT_0
) {
2012 memcpy(&first_desc
->eth_addr
, skb
->data
, ETH_ALEN
);
2014 opcode
= TX_ETHER_PKT
;
2015 if ((adapter
->netdev
->features
& (NETIF_F_TSO
| NETIF_F_TSO6
)) &&
2016 skb_shinfo(skb
)->gso_size
> 0) {
2018 hdr_len
= skb_transport_offset(skb
) + tcp_hdrlen(skb
);
2020 first_desc
->mss
= cpu_to_le16(skb_shinfo(skb
)->gso_size
);
2021 first_desc
->total_hdr_length
= hdr_len
;
2023 opcode
= (protocol
== ETH_P_IPV6
) ? TX_TCP_LSO6
: TX_TCP_LSO
;
2025 /* For LSO, we need to copy the MAC/IP/TCP headers into
2026 * the descriptor ring */
2030 if (flags
& FLAGS_VLAN_OOB
) {
2031 first_desc
->total_hdr_length
+= VLAN_HLEN
;
2032 first_desc
->tcp_hdr_offset
= VLAN_HLEN
;
2033 first_desc
->ip_hdr_offset
= VLAN_HLEN
;
2034 /* Only in case of TSO on vlan device */
2035 flags
|= FLAGS_VLAN_TAGGED
;
2037 /* Create a TSO vlan header template for firmware */
2039 hwdesc
= &tx_ring
->desc_head
[producer
];
2040 tx_ring
->cmd_buf_arr
[producer
].skb
= NULL
;
2042 copy_len
= min((int)sizeof(struct cmd_desc_type0
) -
2043 offset
, hdr_len
+ VLAN_HLEN
);
2045 vh
= (struct vlan_ethhdr
*)((char *) hwdesc
+ 2);
2046 skb_copy_from_linear_data(skb
, vh
, 12);
2047 vh
->h_vlan_proto
= htons(ETH_P_8021Q
);
2048 vh
->h_vlan_TCI
= htons(vlan_tci
);
2050 skb_copy_from_linear_data_offset(skb
, 12,
2051 (char *)vh
+ 16, copy_len
- 16);
2053 copied
= copy_len
- VLAN_HLEN
;
2056 producer
= get_next_index(producer
, tx_ring
->num_desc
);
2059 while (copied
< hdr_len
) {
2061 copy_len
= min((int)sizeof(struct cmd_desc_type0
) -
2062 offset
, (hdr_len
- copied
));
2064 hwdesc
= &tx_ring
->desc_head
[producer
];
2065 tx_ring
->cmd_buf_arr
[producer
].skb
= NULL
;
2067 skb_copy_from_linear_data_offset(skb
, copied
,
2068 (char *) hwdesc
+ offset
, copy_len
);
2073 producer
= get_next_index(producer
, tx_ring
->num_desc
);
2076 tx_ring
->producer
= producer
;
2078 adapter
->stats
.lso_frames
++;
2080 } else if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
2083 if (protocol
== ETH_P_IP
) {
2084 l4proto
= ip_hdr(skb
)->protocol
;
2086 if (l4proto
== IPPROTO_TCP
)
2087 opcode
= TX_TCP_PKT
;
2088 else if (l4proto
== IPPROTO_UDP
)
2089 opcode
= TX_UDP_PKT
;
2090 } else if (protocol
== ETH_P_IPV6
) {
2091 l4proto
= ipv6_hdr(skb
)->nexthdr
;
2093 if (l4proto
== IPPROTO_TCP
)
2094 opcode
= TX_TCPV6_PKT
;
2095 else if (l4proto
== IPPROTO_UDP
)
2096 opcode
= TX_UDPV6_PKT
;
2099 first_desc
->tcp_hdr_offset
+= skb_transport_offset(skb
);
2100 first_desc
->ip_hdr_offset
+= skb_network_offset(skb
);
2101 qlcnic_set_tx_flags_opcode(first_desc
, flags
, opcode
);
2107 qlcnic_map_tx_skb(struct pci_dev
*pdev
,
2108 struct sk_buff
*skb
, struct qlcnic_cmd_buffer
*pbuf
)
2110 struct qlcnic_skb_frag
*nf
;
2111 struct skb_frag_struct
*frag
;
2115 nr_frags
= skb_shinfo(skb
)->nr_frags
;
2116 nf
= &pbuf
->frag_array
[0];
2118 map
= pci_map_single(pdev
, skb
->data
,
2119 skb_headlen(skb
), PCI_DMA_TODEVICE
);
2120 if (pci_dma_mapping_error(pdev
, map
))
2124 nf
->length
= skb_headlen(skb
);
2126 for (i
= 0; i
< nr_frags
; i
++) {
2127 frag
= &skb_shinfo(skb
)->frags
[i
];
2128 nf
= &pbuf
->frag_array
[i
+1];
2130 map
= pci_map_page(pdev
, frag
->page
, frag
->page_offset
,
2131 frag
->size
, PCI_DMA_TODEVICE
);
2132 if (pci_dma_mapping_error(pdev
, map
))
2136 nf
->length
= frag
->size
;
2143 nf
= &pbuf
->frag_array
[i
+1];
2144 pci_unmap_page(pdev
, nf
->dma
, nf
->length
, PCI_DMA_TODEVICE
);
2147 nf
= &pbuf
->frag_array
[0];
2148 pci_unmap_single(pdev
, nf
->dma
, skb_headlen(skb
), PCI_DMA_TODEVICE
);
2155 qlcnic_unmap_buffers(struct pci_dev
*pdev
, struct sk_buff
*skb
,
2156 struct qlcnic_cmd_buffer
*pbuf
)
2158 struct qlcnic_skb_frag
*nf
= &pbuf
->frag_array
[0];
2159 int nr_frags
= skb_shinfo(skb
)->nr_frags
;
2162 for (i
= 0; i
< nr_frags
; i
++) {
2163 nf
= &pbuf
->frag_array
[i
+1];
2164 pci_unmap_page(pdev
, nf
->dma
, nf
->length
, PCI_DMA_TODEVICE
);
2167 nf
= &pbuf
->frag_array
[0];
2168 pci_unmap_single(pdev
, nf
->dma
, skb_headlen(skb
), PCI_DMA_TODEVICE
);
2173 qlcnic_clear_cmddesc(u64
*desc
)
2181 qlcnic_xmit_frame(struct sk_buff
*skb
, struct net_device
*netdev
)
2183 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
2184 struct qlcnic_host_tx_ring
*tx_ring
= adapter
->tx_ring
;
2185 struct qlcnic_cmd_buffer
*pbuf
;
2186 struct qlcnic_skb_frag
*buffrag
;
2187 struct cmd_desc_type0
*hwdesc
, *first_desc
;
2188 struct pci_dev
*pdev
;
2189 struct ethhdr
*phdr
;
2195 u32 num_txd
= tx_ring
->num_desc
;
2197 if (!test_bit(__QLCNIC_DEV_UP
, &adapter
->state
)) {
2198 netif_stop_queue(netdev
);
2199 return NETDEV_TX_BUSY
;
2202 if (adapter
->flags
& QLCNIC_MACSPOOF
) {
2203 phdr
= (struct ethhdr
*)skb
->data
;
2204 if (compare_ether_addr(phdr
->h_source
,
2209 frag_count
= skb_shinfo(skb
)->nr_frags
+ 1;
2210 /* 14 frags supported for normal packet and
2211 * 32 frags supported for TSO packet
2213 if (!skb_is_gso(skb
) && frag_count
> QLCNIC_MAX_FRAGS_PER_TX
) {
2215 for (i
= 0; i
< (frag_count
- QLCNIC_MAX_FRAGS_PER_TX
); i
++)
2216 delta
+= skb_shinfo(skb
)->frags
[i
].size
;
2218 if (!__pskb_pull_tail(skb
, delta
))
2221 frag_count
= 1 + skb_shinfo(skb
)->nr_frags
;
2224 if (unlikely(qlcnic_tx_avail(tx_ring
) <= TX_STOP_THRESH
)) {
2225 netif_stop_queue(netdev
);
2226 if (qlcnic_tx_avail(tx_ring
) > TX_STOP_THRESH
)
2227 netif_start_queue(netdev
);
2229 adapter
->stats
.xmit_off
++;
2230 return NETDEV_TX_BUSY
;
2234 producer
= tx_ring
->producer
;
2235 pbuf
= &tx_ring
->cmd_buf_arr
[producer
];
2237 pdev
= adapter
->pdev
;
2239 first_desc
= hwdesc
= &tx_ring
->desc_head
[producer
];
2240 qlcnic_clear_cmddesc((u64
*)hwdesc
);
2242 if (qlcnic_map_tx_skb(pdev
, skb
, pbuf
)) {
2243 adapter
->stats
.tx_dma_map_error
++;
2248 pbuf
->frag_count
= frag_count
;
2250 qlcnic_set_tx_frags_len(first_desc
, frag_count
, skb
->len
);
2251 qlcnic_set_tx_port(first_desc
, adapter
->portnum
);
2253 for (i
= 0; i
< frag_count
; i
++) {
2257 if ((k
== 0) && (i
> 0)) {
2258 /* move to next desc.*/
2259 producer
= get_next_index(producer
, num_txd
);
2260 hwdesc
= &tx_ring
->desc_head
[producer
];
2261 qlcnic_clear_cmddesc((u64
*)hwdesc
);
2262 tx_ring
->cmd_buf_arr
[producer
].skb
= NULL
;
2265 buffrag
= &pbuf
->frag_array
[i
];
2267 hwdesc
->buffer_length
[k
] = cpu_to_le16(buffrag
->length
);
2270 hwdesc
->addr_buffer1
= cpu_to_le64(buffrag
->dma
);
2273 hwdesc
->addr_buffer2
= cpu_to_le64(buffrag
->dma
);
2276 hwdesc
->addr_buffer3
= cpu_to_le64(buffrag
->dma
);
2279 hwdesc
->addr_buffer4
= cpu_to_le64(buffrag
->dma
);
2284 tx_ring
->producer
= get_next_index(producer
, num_txd
);
2287 if (unlikely(qlcnic_tx_pkt(adapter
, first_desc
, skb
)))
2290 if (adapter
->mac_learn
)
2291 qlcnic_send_filter(adapter
, tx_ring
, first_desc
, skb
);
2293 adapter
->stats
.txbytes
+= skb
->len
;
2294 adapter
->stats
.xmitcalled
++;
2296 qlcnic_update_cmd_producer(adapter
, tx_ring
);
2298 return NETDEV_TX_OK
;
2301 qlcnic_unmap_buffers(pdev
, skb
, pbuf
);
2303 adapter
->stats
.txdropped
++;
2304 dev_kfree_skb_any(skb
);
2305 return NETDEV_TX_OK
;
2308 static int qlcnic_check_temp(struct qlcnic_adapter
*adapter
)
2310 struct net_device
*netdev
= adapter
->netdev
;
2311 u32 temp
, temp_state
, temp_val
;
2314 temp
= QLCRD32(adapter
, CRB_TEMP_STATE
);
2316 temp_state
= qlcnic_get_temp_state(temp
);
2317 temp_val
= qlcnic_get_temp_val(temp
);
2319 if (temp_state
== QLCNIC_TEMP_PANIC
) {
2320 dev_err(&netdev
->dev
,
2321 "Device temperature %d degrees C exceeds"
2322 " maximum allowed. Hardware has been shut down.\n",
2325 } else if (temp_state
== QLCNIC_TEMP_WARN
) {
2326 if (adapter
->temp
== QLCNIC_TEMP_NORMAL
) {
2327 dev_err(&netdev
->dev
,
2328 "Device temperature %d degrees C "
2329 "exceeds operating range."
2330 " Immediate action needed.\n",
2334 if (adapter
->temp
== QLCNIC_TEMP_WARN
) {
2335 dev_info(&netdev
->dev
,
2336 "Device temperature is now %d degrees C"
2337 " in normal range.\n", temp_val
);
2340 adapter
->temp
= temp_state
;
2344 void qlcnic_advert_link_change(struct qlcnic_adapter
*adapter
, int linkup
)
2346 struct net_device
*netdev
= adapter
->netdev
;
2348 if (adapter
->ahw
->linkup
&& !linkup
) {
2349 netdev_info(netdev
, "NIC Link is down\n");
2350 adapter
->ahw
->linkup
= 0;
2351 if (netif_running(netdev
)) {
2352 netif_carrier_off(netdev
);
2353 netif_stop_queue(netdev
);
2355 } else if (!adapter
->ahw
->linkup
&& linkup
) {
2356 netdev_info(netdev
, "NIC Link is up\n");
2357 adapter
->ahw
->linkup
= 1;
2358 if (netif_running(netdev
)) {
2359 netif_carrier_on(netdev
);
2360 netif_wake_queue(netdev
);
2365 static void qlcnic_tx_timeout(struct net_device
*netdev
)
2367 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
2369 if (test_bit(__QLCNIC_RESETTING
, &adapter
->state
))
2372 dev_err(&netdev
->dev
, "transmit timeout, resetting.\n");
2374 if (++adapter
->tx_timeo_cnt
>= QLCNIC_MAX_TX_TIMEOUTS
)
2375 adapter
->need_fw_reset
= 1;
2377 adapter
->reset_context
= 1;
2380 static struct net_device_stats
*qlcnic_get_stats(struct net_device
*netdev
)
2382 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
2383 struct net_device_stats
*stats
= &netdev
->stats
;
2385 stats
->rx_packets
= adapter
->stats
.rx_pkts
+ adapter
->stats
.lro_pkts
;
2386 stats
->tx_packets
= adapter
->stats
.xmitfinished
;
2387 stats
->rx_bytes
= adapter
->stats
.rxbytes
+ adapter
->stats
.lrobytes
;
2388 stats
->tx_bytes
= adapter
->stats
.txbytes
;
2389 stats
->rx_dropped
= adapter
->stats
.rxdropped
;
2390 stats
->tx_dropped
= adapter
->stats
.txdropped
;
2395 static irqreturn_t
qlcnic_clear_legacy_intr(struct qlcnic_adapter
*adapter
)
2399 status
= readl(adapter
->isr_int_vec
);
2401 if (!(status
& adapter
->int_vec_bit
))
2404 /* check interrupt state machine, to be sure */
2405 status
= readl(adapter
->crb_int_state_reg
);
2406 if (!ISR_LEGACY_INT_TRIGGERED(status
))
2409 writel(0xffffffff, adapter
->tgt_status_reg
);
2410 /* read twice to ensure write is flushed */
2411 readl(adapter
->isr_int_vec
);
2412 readl(adapter
->isr_int_vec
);
2417 static irqreturn_t
qlcnic_tmp_intr(int irq
, void *data
)
2419 struct qlcnic_host_sds_ring
*sds_ring
= data
;
2420 struct qlcnic_adapter
*adapter
= sds_ring
->adapter
;
2422 if (adapter
->flags
& QLCNIC_MSIX_ENABLED
)
2424 else if (adapter
->flags
& QLCNIC_MSI_ENABLED
) {
2425 writel(0xffffffff, adapter
->tgt_status_reg
);
2429 if (qlcnic_clear_legacy_intr(adapter
) == IRQ_NONE
)
2433 adapter
->diag_cnt
++;
2434 qlcnic_enable_int(sds_ring
);
2438 static irqreturn_t
qlcnic_intr(int irq
, void *data
)
2440 struct qlcnic_host_sds_ring
*sds_ring
= data
;
2441 struct qlcnic_adapter
*adapter
= sds_ring
->adapter
;
2443 if (qlcnic_clear_legacy_intr(adapter
) == IRQ_NONE
)
2446 napi_schedule(&sds_ring
->napi
);
2451 static irqreturn_t
qlcnic_msi_intr(int irq
, void *data
)
2453 struct qlcnic_host_sds_ring
*sds_ring
= data
;
2454 struct qlcnic_adapter
*adapter
= sds_ring
->adapter
;
2456 /* clear interrupt */
2457 writel(0xffffffff, adapter
->tgt_status_reg
);
2459 napi_schedule(&sds_ring
->napi
);
2463 static irqreturn_t
qlcnic_msix_intr(int irq
, void *data
)
2465 struct qlcnic_host_sds_ring
*sds_ring
= data
;
2467 napi_schedule(&sds_ring
->napi
);
2471 static int qlcnic_process_cmd_ring(struct qlcnic_adapter
*adapter
)
2473 u32 sw_consumer
, hw_consumer
;
2475 struct qlcnic_cmd_buffer
*buffer
;
2476 struct pci_dev
*pdev
= adapter
->pdev
;
2477 struct net_device
*netdev
= adapter
->netdev
;
2478 struct qlcnic_skb_frag
*frag
;
2480 struct qlcnic_host_tx_ring
*tx_ring
= adapter
->tx_ring
;
2482 if (!spin_trylock(&adapter
->tx_clean_lock
))
2485 sw_consumer
= tx_ring
->sw_consumer
;
2486 hw_consumer
= le32_to_cpu(*(tx_ring
->hw_consumer
));
2488 while (sw_consumer
!= hw_consumer
) {
2489 buffer
= &tx_ring
->cmd_buf_arr
[sw_consumer
];
2491 frag
= &buffer
->frag_array
[0];
2492 pci_unmap_single(pdev
, frag
->dma
, frag
->length
,
2495 for (i
= 1; i
< buffer
->frag_count
; i
++) {
2497 pci_unmap_page(pdev
, frag
->dma
, frag
->length
,
2502 adapter
->stats
.xmitfinished
++;
2503 dev_kfree_skb_any(buffer
->skb
);
2507 sw_consumer
= get_next_index(sw_consumer
, tx_ring
->num_desc
);
2508 if (++count
>= MAX_STATUS_HANDLE
)
2512 if (count
&& netif_running(netdev
)) {
2513 tx_ring
->sw_consumer
= sw_consumer
;
2517 if (netif_queue_stopped(netdev
) && netif_carrier_ok(netdev
)) {
2518 if (qlcnic_tx_avail(tx_ring
) > TX_STOP_THRESH
) {
2519 netif_wake_queue(netdev
);
2520 adapter
->stats
.xmit_on
++;
2523 adapter
->tx_timeo_cnt
= 0;
2526 * If everything is freed up to consumer then check if the ring is full
2527 * If the ring is full then check if more needs to be freed and
2528 * schedule the call back again.
2530 * This happens when there are 2 CPUs. One could be freeing and the
2531 * other filling it. If the ring is full when we get out of here and
2532 * the card has already interrupted the host then the host can miss the
2535 * There is still a possible race condition and the host could miss an
2536 * interrupt. The card has to take care of this.
2538 hw_consumer
= le32_to_cpu(*(tx_ring
->hw_consumer
));
2539 done
= (sw_consumer
== hw_consumer
);
2540 spin_unlock(&adapter
->tx_clean_lock
);
2545 static int qlcnic_poll(struct napi_struct
*napi
, int budget
)
2547 struct qlcnic_host_sds_ring
*sds_ring
=
2548 container_of(napi
, struct qlcnic_host_sds_ring
, napi
);
2550 struct qlcnic_adapter
*adapter
= sds_ring
->adapter
;
2555 tx_complete
= qlcnic_process_cmd_ring(adapter
);
2557 work_done
= qlcnic_process_rcv_ring(sds_ring
, budget
);
2559 if ((work_done
< budget
) && tx_complete
) {
2560 napi_complete(&sds_ring
->napi
);
2561 if (test_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
2562 qlcnic_enable_int(sds_ring
);
2568 static int qlcnic_rx_poll(struct napi_struct
*napi
, int budget
)
2570 struct qlcnic_host_sds_ring
*sds_ring
=
2571 container_of(napi
, struct qlcnic_host_sds_ring
, napi
);
2573 struct qlcnic_adapter
*adapter
= sds_ring
->adapter
;
2576 work_done
= qlcnic_process_rcv_ring(sds_ring
, budget
);
2578 if (work_done
< budget
) {
2579 napi_complete(&sds_ring
->napi
);
2580 if (test_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
2581 qlcnic_enable_int(sds_ring
);
2587 #ifdef CONFIG_NET_POLL_CONTROLLER
2588 static void qlcnic_poll_controller(struct net_device
*netdev
)
2591 struct qlcnic_host_sds_ring
*sds_ring
;
2592 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
2593 struct qlcnic_recv_context
*recv_ctx
= adapter
->recv_ctx
;
2595 disable_irq(adapter
->irq
);
2596 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
2597 sds_ring
= &recv_ctx
->sds_rings
[ring
];
2598 qlcnic_intr(adapter
->irq
, sds_ring
);
2600 enable_irq(adapter
->irq
);
2605 qlcnic_idc_debug_info(struct qlcnic_adapter
*adapter
, u8 encoding
)
2609 val
= adapter
->portnum
& 0xf;
2610 val
|= encoding
<< 7;
2611 val
|= (jiffies
- adapter
->dev_rst_time
) << 8;
2613 QLCWR32(adapter
, QLCNIC_CRB_DRV_SCRATCH
, val
);
2614 adapter
->dev_rst_time
= jiffies
;
2618 qlcnic_set_drv_state(struct qlcnic_adapter
*adapter
, u8 state
)
2622 WARN_ON(state
!= QLCNIC_DEV_NEED_RESET
&&
2623 state
!= QLCNIC_DEV_NEED_QUISCENT
);
2625 if (qlcnic_api_lock(adapter
))
2628 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_STATE
);
2630 if (state
== QLCNIC_DEV_NEED_RESET
)
2631 QLC_DEV_SET_RST_RDY(val
, adapter
->portnum
);
2632 else if (state
== QLCNIC_DEV_NEED_QUISCENT
)
2633 QLC_DEV_SET_QSCNT_RDY(val
, adapter
->portnum
);
2635 QLCWR32(adapter
, QLCNIC_CRB_DRV_STATE
, val
);
2637 qlcnic_api_unlock(adapter
);
2643 qlcnic_clr_drv_state(struct qlcnic_adapter
*adapter
)
2647 if (qlcnic_api_lock(adapter
))
2650 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_STATE
);
2651 QLC_DEV_CLR_RST_QSCNT(val
, adapter
->portnum
);
2652 QLCWR32(adapter
, QLCNIC_CRB_DRV_STATE
, val
);
2654 qlcnic_api_unlock(adapter
);
2660 qlcnic_clr_all_drv_state(struct qlcnic_adapter
*adapter
, u8 failed
)
2664 if (qlcnic_api_lock(adapter
))
2667 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_ACTIVE
);
2668 QLC_DEV_CLR_REF_CNT(val
, adapter
->portnum
);
2669 QLCWR32(adapter
, QLCNIC_CRB_DRV_ACTIVE
, val
);
2672 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
, QLCNIC_DEV_FAILED
);
2673 dev_info(&adapter
->pdev
->dev
,
2674 "Device state set to Failed. Please Reboot\n");
2675 } else if (!(val
& 0x11111111))
2676 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
, QLCNIC_DEV_COLD
);
2678 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_STATE
);
2679 QLC_DEV_CLR_RST_QSCNT(val
, adapter
->portnum
);
2680 QLCWR32(adapter
, QLCNIC_CRB_DRV_STATE
, val
);
2682 qlcnic_api_unlock(adapter
);
2684 adapter
->fw_fail_cnt
= 0;
2685 adapter
->flags
&= ~QLCNIC_FW_HANG
;
2686 clear_bit(__QLCNIC_START_FW
, &adapter
->state
);
2687 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
2690 /* Grab api lock, before checking state */
2692 qlcnic_check_drv_state(struct qlcnic_adapter
*adapter
)
2694 int act
, state
, active_mask
;
2696 state
= QLCRD32(adapter
, QLCNIC_CRB_DRV_STATE
);
2697 act
= QLCRD32(adapter
, QLCNIC_CRB_DRV_ACTIVE
);
2699 if (adapter
->flags
& QLCNIC_FW_RESET_OWNER
) {
2700 active_mask
= (~(1 << (adapter
->ahw
->pci_func
* 4)));
2701 act
= act
& active_mask
;
2704 if (((state
& 0x11111111) == (act
& 0x11111111)) ||
2705 ((act
& 0x11111111) == ((state
>> 1) & 0x11111111)))
2711 static int qlcnic_check_idc_ver(struct qlcnic_adapter
*adapter
)
2713 u32 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_IDC_VER
);
2715 if (val
!= QLCNIC_DRV_IDC_VER
) {
2716 dev_warn(&adapter
->pdev
->dev
, "IDC Version mismatch, driver's"
2717 " idc ver = %x; reqd = %x\n", QLCNIC_DRV_IDC_VER
, val
);
2724 qlcnic_can_start_firmware(struct qlcnic_adapter
*adapter
)
2726 u32 val
, prev_state
;
2727 u8 dev_init_timeo
= adapter
->dev_init_timeo
;
2728 u8 portnum
= adapter
->portnum
;
2731 if (test_and_clear_bit(__QLCNIC_START_FW
, &adapter
->state
))
2734 if (qlcnic_api_lock(adapter
))
2737 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_ACTIVE
);
2738 if (!(val
& (1 << (portnum
* 4)))) {
2739 QLC_DEV_SET_REF_CNT(val
, portnum
);
2740 QLCWR32(adapter
, QLCNIC_CRB_DRV_ACTIVE
, val
);
2743 prev_state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
);
2744 QLCDB(adapter
, HW
, "Device state = %u\n", prev_state
);
2746 switch (prev_state
) {
2747 case QLCNIC_DEV_COLD
:
2748 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
, QLCNIC_DEV_INITIALIZING
);
2749 QLCWR32(adapter
, QLCNIC_CRB_DRV_IDC_VER
, QLCNIC_DRV_IDC_VER
);
2750 qlcnic_idc_debug_info(adapter
, 0);
2751 qlcnic_api_unlock(adapter
);
2754 case QLCNIC_DEV_READY
:
2755 ret
= qlcnic_check_idc_ver(adapter
);
2756 qlcnic_api_unlock(adapter
);
2759 case QLCNIC_DEV_NEED_RESET
:
2760 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_STATE
);
2761 QLC_DEV_SET_RST_RDY(val
, portnum
);
2762 QLCWR32(adapter
, QLCNIC_CRB_DRV_STATE
, val
);
2765 case QLCNIC_DEV_NEED_QUISCENT
:
2766 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_STATE
);
2767 QLC_DEV_SET_QSCNT_RDY(val
, portnum
);
2768 QLCWR32(adapter
, QLCNIC_CRB_DRV_STATE
, val
);
2771 case QLCNIC_DEV_FAILED
:
2772 dev_err(&adapter
->pdev
->dev
, "Device in failed state.\n");
2773 qlcnic_api_unlock(adapter
);
2776 case QLCNIC_DEV_INITIALIZING
:
2777 case QLCNIC_DEV_QUISCENT
:
2781 qlcnic_api_unlock(adapter
);
2785 prev_state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
);
2787 if (prev_state
== QLCNIC_DEV_QUISCENT
)
2789 } while ((prev_state
!= QLCNIC_DEV_READY
) && --dev_init_timeo
);
2791 if (!dev_init_timeo
) {
2792 dev_err(&adapter
->pdev
->dev
,
2793 "Waiting for device to initialize timeout\n");
2797 if (qlcnic_api_lock(adapter
))
2800 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_STATE
);
2801 QLC_DEV_CLR_RST_QSCNT(val
, portnum
);
2802 QLCWR32(adapter
, QLCNIC_CRB_DRV_STATE
, val
);
2804 ret
= qlcnic_check_idc_ver(adapter
);
2805 qlcnic_api_unlock(adapter
);
2811 qlcnic_fwinit_work(struct work_struct
*work
)
2813 struct qlcnic_adapter
*adapter
= container_of(work
,
2814 struct qlcnic_adapter
, fw_work
.work
);
2815 u32 dev_state
= 0xf;
2818 if (qlcnic_api_lock(adapter
))
2821 dev_state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
);
2822 if (dev_state
== QLCNIC_DEV_QUISCENT
||
2823 dev_state
== QLCNIC_DEV_NEED_QUISCENT
) {
2824 qlcnic_api_unlock(adapter
);
2825 qlcnic_schedule_work(adapter
, qlcnic_fwinit_work
,
2830 if (adapter
->op_mode
== QLCNIC_NON_PRIV_FUNC
) {
2831 qlcnic_api_unlock(adapter
);
2835 if (adapter
->fw_wait_cnt
++ > adapter
->reset_ack_timeo
) {
2836 dev_err(&adapter
->pdev
->dev
, "Reset:Failed to get ack %d sec\n",
2837 adapter
->reset_ack_timeo
);
2838 goto skip_ack_check
;
2841 if (!qlcnic_check_drv_state(adapter
)) {
2843 dev_state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
);
2845 if (dev_state
== QLCNIC_DEV_NEED_RESET
) {
2846 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
,
2847 QLCNIC_DEV_INITIALIZING
);
2848 set_bit(__QLCNIC_START_FW
, &adapter
->state
);
2849 QLCDB(adapter
, DRV
, "Restarting fw\n");
2850 qlcnic_idc_debug_info(adapter
, 0);
2851 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_STATE
);
2852 QLC_DEV_SET_RST_RDY(val
, adapter
->portnum
);
2853 QLCWR32(adapter
, QLCNIC_CRB_DRV_STATE
, val
);
2856 qlcnic_api_unlock(adapter
);
2859 if (adapter
->ahw
->fw_dump
.enable
&&
2860 (adapter
->flags
& QLCNIC_FW_RESET_OWNER
)) {
2861 QLCDB(adapter
, DRV
, "Take FW dump\n");
2862 qlcnic_dump_fw(adapter
);
2863 adapter
->flags
|= QLCNIC_FW_HANG
;
2867 adapter
->flags
&= ~QLCNIC_FW_RESET_OWNER
;
2868 if (!adapter
->nic_ops
->start_firmware(adapter
)) {
2869 qlcnic_schedule_work(adapter
, qlcnic_attach_work
, 0);
2870 adapter
->fw_wait_cnt
= 0;
2876 qlcnic_api_unlock(adapter
);
2879 dev_state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
);
2880 QLCDB(adapter
, HW
, "Func waiting: Device state=%u\n", dev_state
);
2882 switch (dev_state
) {
2883 case QLCNIC_DEV_READY
:
2884 if (!adapter
->nic_ops
->start_firmware(adapter
)) {
2885 qlcnic_schedule_work(adapter
, qlcnic_attach_work
, 0);
2886 adapter
->fw_wait_cnt
= 0;
2889 case QLCNIC_DEV_FAILED
:
2892 qlcnic_schedule_work(adapter
,
2893 qlcnic_fwinit_work
, FW_POLL_DELAY
);
2898 dev_err(&adapter
->pdev
->dev
, "Fwinit work failed state=%u "
2899 "fw_wait_cnt=%u\n", dev_state
, adapter
->fw_wait_cnt
);
2900 netif_device_attach(adapter
->netdev
);
2901 qlcnic_clr_all_drv_state(adapter
, 0);
2905 qlcnic_detach_work(struct work_struct
*work
)
2907 struct qlcnic_adapter
*adapter
= container_of(work
,
2908 struct qlcnic_adapter
, fw_work
.work
);
2909 struct net_device
*netdev
= adapter
->netdev
;
2912 netif_device_detach(netdev
);
2914 /* Dont grab rtnl lock during Quiscent mode */
2915 if (adapter
->dev_state
== QLCNIC_DEV_NEED_QUISCENT
) {
2916 if (netif_running(netdev
))
2917 __qlcnic_down(adapter
, netdev
);
2919 qlcnic_down(adapter
, netdev
);
2921 status
= QLCRD32(adapter
, QLCNIC_PEG_HALT_STATUS1
);
2923 if (status
& QLCNIC_RCODE_FATAL_ERROR
)
2926 if (adapter
->temp
== QLCNIC_TEMP_PANIC
)
2928 /* Dont ack if this instance is the reset owner */
2929 if (!(adapter
->flags
& QLCNIC_FW_RESET_OWNER
)) {
2930 if (qlcnic_set_drv_state(adapter
, adapter
->dev_state
))
2934 adapter
->fw_wait_cnt
= 0;
2936 qlcnic_schedule_work(adapter
, qlcnic_fwinit_work
, FW_POLL_DELAY
);
2941 dev_err(&adapter
->pdev
->dev
, "detach failed; status=%d temp=%d\n",
2942 status
, adapter
->temp
);
2943 netif_device_attach(netdev
);
2944 qlcnic_clr_all_drv_state(adapter
, 1);
2947 /*Transit NPAR state to NON Operational */
2949 qlcnic_set_npar_non_operational(struct qlcnic_adapter
*adapter
)
2953 state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_NPAR_STATE
);
2954 if (state
== QLCNIC_DEV_NPAR_NON_OPER
)
2957 if (qlcnic_api_lock(adapter
))
2959 QLCWR32(adapter
, QLCNIC_CRB_DEV_NPAR_STATE
, QLCNIC_DEV_NPAR_NON_OPER
);
2960 qlcnic_api_unlock(adapter
);
2963 /*Transit to RESET state from READY state only */
2965 qlcnic_dev_request_reset(struct qlcnic_adapter
*adapter
)
2969 adapter
->need_fw_reset
= 1;
2970 if (qlcnic_api_lock(adapter
))
2973 state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
);
2975 if (state
== QLCNIC_DEV_READY
) {
2976 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
, QLCNIC_DEV_NEED_RESET
);
2977 adapter
->flags
|= QLCNIC_FW_RESET_OWNER
;
2978 QLCDB(adapter
, DRV
, "NEED_RESET state set\n");
2979 qlcnic_idc_debug_info(adapter
, 0);
2982 QLCWR32(adapter
, QLCNIC_CRB_DEV_NPAR_STATE
, QLCNIC_DEV_NPAR_NON_OPER
);
2983 qlcnic_api_unlock(adapter
);
2986 /* Transit to NPAR READY state from NPAR NOT READY state */
2988 qlcnic_dev_set_npar_ready(struct qlcnic_adapter
*adapter
)
2990 if (qlcnic_api_lock(adapter
))
2993 QLCWR32(adapter
, QLCNIC_CRB_DEV_NPAR_STATE
, QLCNIC_DEV_NPAR_OPER
);
2994 QLCDB(adapter
, DRV
, "NPAR operational state set\n");
2996 qlcnic_api_unlock(adapter
);
3000 qlcnic_schedule_work(struct qlcnic_adapter
*adapter
,
3001 work_func_t func
, int delay
)
3003 if (test_bit(__QLCNIC_AER
, &adapter
->state
))
3006 INIT_DELAYED_WORK(&adapter
->fw_work
, func
);
3007 queue_delayed_work(qlcnic_wq
, &adapter
->fw_work
,
3008 round_jiffies_relative(delay
));
3012 qlcnic_cancel_fw_work(struct qlcnic_adapter
*adapter
)
3014 while (test_and_set_bit(__QLCNIC_RESETTING
, &adapter
->state
))
3017 cancel_delayed_work_sync(&adapter
->fw_work
);
3021 qlcnic_attach_work(struct work_struct
*work
)
3023 struct qlcnic_adapter
*adapter
= container_of(work
,
3024 struct qlcnic_adapter
, fw_work
.work
);
3025 struct net_device
*netdev
= adapter
->netdev
;
3028 if (adapter
->op_mode
!= QLCNIC_MGMT_FUNC
) {
3029 npar_state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_NPAR_STATE
);
3030 if (adapter
->fw_wait_cnt
++ > QLCNIC_DEV_NPAR_OPER_TIMEO
)
3031 qlcnic_clr_all_drv_state(adapter
, 0);
3032 else if (npar_state
!= QLCNIC_DEV_NPAR_OPER
)
3033 qlcnic_schedule_work(adapter
, qlcnic_attach_work
,
3037 QLCDB(adapter
, DRV
, "Waiting for NPAR state to operational\n");
3041 if (netif_running(netdev
)) {
3042 if (qlcnic_up(adapter
, netdev
))
3045 qlcnic_restore_indev_addr(netdev
, NETDEV_UP
);
3049 netif_device_attach(netdev
);
3050 adapter
->fw_fail_cnt
= 0;
3051 adapter
->flags
&= ~QLCNIC_FW_HANG
;
3052 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
3054 if (!qlcnic_clr_drv_state(adapter
))
3055 qlcnic_schedule_work(adapter
, qlcnic_fw_poll_work
,
3060 qlcnic_check_health(struct qlcnic_adapter
*adapter
)
3062 u32 state
= 0, heartbeat
;
3063 struct net_device
*netdev
= adapter
->netdev
;
3065 if (qlcnic_check_temp(adapter
))
3068 if (adapter
->need_fw_reset
)
3069 qlcnic_dev_request_reset(adapter
);
3071 state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
);
3072 if (state
== QLCNIC_DEV_NEED_RESET
) {
3073 qlcnic_set_npar_non_operational(adapter
);
3074 adapter
->need_fw_reset
= 1;
3075 } else if (state
== QLCNIC_DEV_NEED_QUISCENT
)
3078 heartbeat
= QLCRD32(adapter
, QLCNIC_PEG_ALIVE_COUNTER
);
3079 if (heartbeat
!= adapter
->heartbeat
) {
3080 adapter
->heartbeat
= heartbeat
;
3081 adapter
->fw_fail_cnt
= 0;
3082 if (adapter
->need_fw_reset
)
3085 if (adapter
->reset_context
&& auto_fw_reset
) {
3086 qlcnic_reset_hw_context(adapter
);
3087 adapter
->netdev
->trans_start
= jiffies
;
3093 if (++adapter
->fw_fail_cnt
< FW_FAIL_THRESH
)
3096 adapter
->flags
|= QLCNIC_FW_HANG
;
3098 qlcnic_dev_request_reset(adapter
);
3101 clear_bit(__QLCNIC_FW_ATTACHED
, &adapter
->state
);
3103 dev_info(&netdev
->dev
, "firmware hang detected\n");
3106 adapter
->dev_state
= (state
== QLCNIC_DEV_NEED_QUISCENT
) ? state
:
3107 QLCNIC_DEV_NEED_RESET
;
3109 if (auto_fw_reset
&&
3110 !test_and_set_bit(__QLCNIC_RESETTING
, &adapter
->state
)) {
3112 qlcnic_schedule_work(adapter
, qlcnic_detach_work
, 0);
3113 QLCDB(adapter
, DRV
, "fw recovery scheduled.\n");
3120 qlcnic_fw_poll_work(struct work_struct
*work
)
3122 struct qlcnic_adapter
*adapter
= container_of(work
,
3123 struct qlcnic_adapter
, fw_work
.work
);
3125 if (test_bit(__QLCNIC_RESETTING
, &adapter
->state
))
3129 if (qlcnic_check_health(adapter
))
3132 if (adapter
->fhash
.fnum
)
3133 qlcnic_prune_lb_filters(adapter
);
3136 qlcnic_schedule_work(adapter
, qlcnic_fw_poll_work
, FW_POLL_DELAY
);
3139 static int qlcnic_is_first_func(struct pci_dev
*pdev
)
3141 struct pci_dev
*oth_pdev
;
3142 int val
= pdev
->devfn
;
3145 oth_pdev
= pci_get_domain_bus_and_slot(pci_domain_nr
3146 (pdev
->bus
), pdev
->bus
->number
,
3147 PCI_DEVFN(PCI_SLOT(pdev
->devfn
), val
));
3151 if (oth_pdev
->current_state
!= PCI_D3cold
) {
3152 pci_dev_put(oth_pdev
);
3155 pci_dev_put(oth_pdev
);
3160 static int qlcnic_attach_func(struct pci_dev
*pdev
)
3162 int err
, first_func
;
3163 struct qlcnic_adapter
*adapter
= pci_get_drvdata(pdev
);
3164 struct net_device
*netdev
= adapter
->netdev
;
3166 pdev
->error_state
= pci_channel_io_normal
;
3168 err
= pci_enable_device(pdev
);
3172 pci_set_power_state(pdev
, PCI_D0
);
3173 pci_set_master(pdev
);
3174 pci_restore_state(pdev
);
3176 first_func
= qlcnic_is_first_func(pdev
);
3178 if (qlcnic_api_lock(adapter
))
3181 if (adapter
->op_mode
!= QLCNIC_NON_PRIV_FUNC
&& first_func
) {
3182 adapter
->need_fw_reset
= 1;
3183 set_bit(__QLCNIC_START_FW
, &adapter
->state
);
3184 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
, QLCNIC_DEV_INITIALIZING
);
3185 QLCDB(adapter
, DRV
, "Restarting fw\n");
3187 qlcnic_api_unlock(adapter
);
3189 err
= adapter
->nic_ops
->start_firmware(adapter
);
3193 qlcnic_clr_drv_state(adapter
);
3194 qlcnic_setup_intr(adapter
);
3196 if (netif_running(netdev
)) {
3197 err
= qlcnic_attach(adapter
);
3199 qlcnic_clr_all_drv_state(adapter
, 1);
3200 clear_bit(__QLCNIC_AER
, &adapter
->state
);
3201 netif_device_attach(netdev
);
3205 err
= qlcnic_up(adapter
, netdev
);
3209 qlcnic_restore_indev_addr(netdev
, NETDEV_UP
);
3212 netif_device_attach(netdev
);
3216 static pci_ers_result_t
qlcnic_io_error_detected(struct pci_dev
*pdev
,
3217 pci_channel_state_t state
)
3219 struct qlcnic_adapter
*adapter
= pci_get_drvdata(pdev
);
3220 struct net_device
*netdev
= adapter
->netdev
;
3222 if (state
== pci_channel_io_perm_failure
)
3223 return PCI_ERS_RESULT_DISCONNECT
;
3225 if (state
== pci_channel_io_normal
)
3226 return PCI_ERS_RESULT_RECOVERED
;
3228 set_bit(__QLCNIC_AER
, &adapter
->state
);
3229 netif_device_detach(netdev
);
3231 cancel_delayed_work_sync(&adapter
->fw_work
);
3233 if (netif_running(netdev
))
3234 qlcnic_down(adapter
, netdev
);
3236 qlcnic_detach(adapter
);
3237 qlcnic_teardown_intr(adapter
);
3239 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
3241 pci_save_state(pdev
);
3242 pci_disable_device(pdev
);
3244 return PCI_ERS_RESULT_NEED_RESET
;
3247 static pci_ers_result_t
qlcnic_io_slot_reset(struct pci_dev
*pdev
)
3249 return qlcnic_attach_func(pdev
) ? PCI_ERS_RESULT_DISCONNECT
:
3250 PCI_ERS_RESULT_RECOVERED
;
3253 static void qlcnic_io_resume(struct pci_dev
*pdev
)
3255 struct qlcnic_adapter
*adapter
= pci_get_drvdata(pdev
);
3257 pci_cleanup_aer_uncorrect_error_status(pdev
);
3259 if (QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
) == QLCNIC_DEV_READY
&&
3260 test_and_clear_bit(__QLCNIC_AER
, &adapter
->state
))
3261 qlcnic_schedule_work(adapter
, qlcnic_fw_poll_work
,
3266 qlcnicvf_start_firmware(struct qlcnic_adapter
*adapter
)
3270 err
= qlcnic_can_start_firmware(adapter
);
3274 err
= qlcnic_check_npar_opertional(adapter
);
3278 err
= qlcnic_initialize_nic(adapter
);
3282 qlcnic_check_options(adapter
);
3284 err
= qlcnic_set_eswitch_port_config(adapter
);
3288 adapter
->need_fw_reset
= 0;
3294 qlcnicvf_config_bridged_mode(struct qlcnic_adapter
*adapter
, u32 enable
)
3300 qlcnicvf_config_led(struct qlcnic_adapter
*adapter
, u32 state
, u32 rate
)
3306 qlcnic_store_bridged_mode(struct device
*dev
,
3307 struct device_attribute
*attr
, const char *buf
, size_t len
)
3309 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3313 if (!(adapter
->capabilities
& QLCNIC_FW_CAPABILITY_BDG
))
3316 if (!test_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
3319 if (strict_strtoul(buf
, 2, &new))
3322 if (!adapter
->nic_ops
->config_bridged_mode(adapter
, !!new))
3330 qlcnic_show_bridged_mode(struct device
*dev
,
3331 struct device_attribute
*attr
, char *buf
)
3333 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3334 int bridged_mode
= 0;
3336 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_BDG
)
3337 bridged_mode
= !!(adapter
->flags
& QLCNIC_BRIDGE_ENABLED
);
3339 return sprintf(buf
, "%d\n", bridged_mode
);
3342 static struct device_attribute dev_attr_bridged_mode
= {
3343 .attr
= {.name
= "bridged_mode", .mode
= (S_IRUGO
| S_IWUSR
)},
3344 .show
= qlcnic_show_bridged_mode
,
3345 .store
= qlcnic_store_bridged_mode
,
3349 qlcnic_store_diag_mode(struct device
*dev
,
3350 struct device_attribute
*attr
, const char *buf
, size_t len
)
3352 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3355 if (strict_strtoul(buf
, 2, &new))
3358 if (!!new != !!(adapter
->flags
& QLCNIC_DIAG_ENABLED
))
3359 adapter
->flags
^= QLCNIC_DIAG_ENABLED
;
3365 qlcnic_show_diag_mode(struct device
*dev
,
3366 struct device_attribute
*attr
, char *buf
)
3368 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3370 return sprintf(buf
, "%d\n",
3371 !!(adapter
->flags
& QLCNIC_DIAG_ENABLED
));
3374 static struct device_attribute dev_attr_diag_mode
= {
3375 .attr
= {.name
= "diag_mode", .mode
= (S_IRUGO
| S_IWUSR
)},
3376 .show
= qlcnic_show_diag_mode
,
3377 .store
= qlcnic_store_diag_mode
,
3380 int qlcnic_validate_max_rss(struct net_device
*netdev
, u8 max_hw
, u8 val
)
3382 if (!use_msi_x
&& !use_msi
) {
3383 netdev_info(netdev
, "no msix or msi support, hence no rss\n");
3387 if ((val
> max_hw
) || (val
< 2) || !is_power_of_2(val
)) {
3388 netdev_info(netdev
, "rss_ring valid range [2 - %x] in "
3389 " powers of 2\n", max_hw
);
3396 int qlcnic_set_max_rss(struct qlcnic_adapter
*adapter
, u8 data
)
3398 struct net_device
*netdev
= adapter
->netdev
;
3401 if (test_and_set_bit(__QLCNIC_RESETTING
, &adapter
->state
))
3404 netif_device_detach(netdev
);
3405 if (netif_running(netdev
))
3406 __qlcnic_down(adapter
, netdev
);
3407 qlcnic_detach(adapter
);
3408 qlcnic_teardown_intr(adapter
);
3410 if (qlcnic_enable_msix(adapter
, data
)) {
3411 netdev_info(netdev
, "failed setting max_rss; rss disabled\n");
3412 qlcnic_enable_msi_legacy(adapter
);
3415 if (netif_running(netdev
)) {
3416 err
= qlcnic_attach(adapter
);
3419 err
= __qlcnic_up(adapter
, netdev
);
3422 qlcnic_restore_indev_addr(netdev
, NETDEV_UP
);
3425 netif_device_attach(netdev
);
3426 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
3431 qlcnic_sysfs_validate_crb(struct qlcnic_adapter
*adapter
,
3432 loff_t offset
, size_t size
)
3434 size_t crb_size
= 4;
3436 if (!(adapter
->flags
& QLCNIC_DIAG_ENABLED
))
3439 if (offset
< QLCNIC_PCI_CRBSPACE
) {
3440 if (ADDR_IN_RANGE(offset
, QLCNIC_PCI_CAMQM
,
3441 QLCNIC_PCI_CAMQM_END
))
3447 if ((size
!= crb_size
) || (offset
& (crb_size
-1)))
3454 qlcnic_sysfs_read_crb(struct file
*filp
, struct kobject
*kobj
,
3455 struct bin_attribute
*attr
,
3456 char *buf
, loff_t offset
, size_t size
)
3458 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3459 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3464 ret
= qlcnic_sysfs_validate_crb(adapter
, offset
, size
);
3468 if (ADDR_IN_RANGE(offset
, QLCNIC_PCI_CAMQM
, QLCNIC_PCI_CAMQM_END
)) {
3469 qlcnic_pci_camqm_read_2M(adapter
, offset
, &qmdata
);
3470 memcpy(buf
, &qmdata
, size
);
3472 data
= QLCRD32(adapter
, offset
);
3473 memcpy(buf
, &data
, size
);
3479 qlcnic_sysfs_write_crb(struct file
*filp
, struct kobject
*kobj
,
3480 struct bin_attribute
*attr
,
3481 char *buf
, loff_t offset
, size_t size
)
3483 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3484 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3489 ret
= qlcnic_sysfs_validate_crb(adapter
, offset
, size
);
3493 if (ADDR_IN_RANGE(offset
, QLCNIC_PCI_CAMQM
, QLCNIC_PCI_CAMQM_END
)) {
3494 memcpy(&qmdata
, buf
, size
);
3495 qlcnic_pci_camqm_write_2M(adapter
, offset
, qmdata
);
3497 memcpy(&data
, buf
, size
);
3498 QLCWR32(adapter
, offset
, data
);
3504 qlcnic_sysfs_validate_mem(struct qlcnic_adapter
*adapter
,
3505 loff_t offset
, size_t size
)
3507 if (!(adapter
->flags
& QLCNIC_DIAG_ENABLED
))
3510 if ((size
!= 8) || (offset
& 0x7))
3517 qlcnic_sysfs_read_mem(struct file
*filp
, struct kobject
*kobj
,
3518 struct bin_attribute
*attr
,
3519 char *buf
, loff_t offset
, size_t size
)
3521 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3522 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3526 ret
= qlcnic_sysfs_validate_mem(adapter
, offset
, size
);
3530 if (qlcnic_pci_mem_read_2M(adapter
, offset
, &data
))
3533 memcpy(buf
, &data
, size
);
3539 qlcnic_sysfs_write_mem(struct file
*filp
, struct kobject
*kobj
,
3540 struct bin_attribute
*attr
,
3541 char *buf
, loff_t offset
, size_t size
)
3543 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3544 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3548 ret
= qlcnic_sysfs_validate_mem(adapter
, offset
, size
);
3552 memcpy(&data
, buf
, size
);
3554 if (qlcnic_pci_mem_write_2M(adapter
, offset
, data
))
3560 static struct bin_attribute bin_attr_crb
= {
3561 .attr
= {.name
= "crb", .mode
= (S_IRUGO
| S_IWUSR
)},
3563 .read
= qlcnic_sysfs_read_crb
,
3564 .write
= qlcnic_sysfs_write_crb
,
3567 static struct bin_attribute bin_attr_mem
= {
3568 .attr
= {.name
= "mem", .mode
= (S_IRUGO
| S_IWUSR
)},
3570 .read
= qlcnic_sysfs_read_mem
,
3571 .write
= qlcnic_sysfs_write_mem
,
3575 validate_pm_config(struct qlcnic_adapter
*adapter
,
3576 struct qlcnic_pm_func_cfg
*pm_cfg
, int count
)
3579 u8 src_pci_func
, s_esw_id
, d_esw_id
;
3583 for (i
= 0; i
< count
; i
++) {
3584 src_pci_func
= pm_cfg
[i
].pci_func
;
3585 dest_pci_func
= pm_cfg
[i
].dest_npar
;
3586 if (src_pci_func
>= QLCNIC_MAX_PCI_FUNC
3587 || dest_pci_func
>= QLCNIC_MAX_PCI_FUNC
)
3588 return QL_STATUS_INVALID_PARAM
;
3590 if (adapter
->npars
[src_pci_func
].type
!= QLCNIC_TYPE_NIC
)
3591 return QL_STATUS_INVALID_PARAM
;
3593 if (adapter
->npars
[dest_pci_func
].type
!= QLCNIC_TYPE_NIC
)
3594 return QL_STATUS_INVALID_PARAM
;
3596 s_esw_id
= adapter
->npars
[src_pci_func
].phy_port
;
3597 d_esw_id
= adapter
->npars
[dest_pci_func
].phy_port
;
3599 if (s_esw_id
!= d_esw_id
)
3600 return QL_STATUS_INVALID_PARAM
;
3608 qlcnic_sysfs_write_pm_config(struct file
*filp
, struct kobject
*kobj
,
3609 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3611 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3612 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3613 struct qlcnic_pm_func_cfg
*pm_cfg
;
3614 u32 id
, action
, pci_func
;
3615 int count
, rem
, i
, ret
;
3617 count
= size
/ sizeof(struct qlcnic_pm_func_cfg
);
3618 rem
= size
% sizeof(struct qlcnic_pm_func_cfg
);
3620 return QL_STATUS_INVALID_PARAM
;
3622 pm_cfg
= (struct qlcnic_pm_func_cfg
*) buf
;
3624 ret
= validate_pm_config(adapter
, pm_cfg
, count
);
3627 for (i
= 0; i
< count
; i
++) {
3628 pci_func
= pm_cfg
[i
].pci_func
;
3629 action
= !!pm_cfg
[i
].action
;
3630 id
= adapter
->npars
[pci_func
].phy_port
;
3631 ret
= qlcnic_config_port_mirroring(adapter
, id
,
3637 for (i
= 0; i
< count
; i
++) {
3638 pci_func
= pm_cfg
[i
].pci_func
;
3639 id
= adapter
->npars
[pci_func
].phy_port
;
3640 adapter
->npars
[pci_func
].enable_pm
= !!pm_cfg
[i
].action
;
3641 adapter
->npars
[pci_func
].dest_npar
= id
;
3647 qlcnic_sysfs_read_pm_config(struct file
*filp
, struct kobject
*kobj
,
3648 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3650 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3651 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3652 struct qlcnic_pm_func_cfg pm_cfg
[QLCNIC_MAX_PCI_FUNC
];
3655 if (size
!= sizeof(pm_cfg
))
3656 return QL_STATUS_INVALID_PARAM
;
3658 for (i
= 0; i
< QLCNIC_MAX_PCI_FUNC
; i
++) {
3659 if (adapter
->npars
[i
].type
!= QLCNIC_TYPE_NIC
)
3661 pm_cfg
[i
].action
= adapter
->npars
[i
].enable_pm
;
3662 pm_cfg
[i
].dest_npar
= 0;
3663 pm_cfg
[i
].pci_func
= i
;
3665 memcpy(buf
, &pm_cfg
, size
);
3671 validate_esw_config(struct qlcnic_adapter
*adapter
,
3672 struct qlcnic_esw_func_cfg
*esw_cfg
, int count
)
3678 op_mode
= readl(adapter
->ahw
->pci_base0
+ QLCNIC_DRV_OP_MODE
);
3680 for (i
= 0; i
< count
; i
++) {
3681 pci_func
= esw_cfg
[i
].pci_func
;
3682 if (pci_func
>= QLCNIC_MAX_PCI_FUNC
)
3683 return QL_STATUS_INVALID_PARAM
;
3685 if (adapter
->op_mode
== QLCNIC_MGMT_FUNC
)
3686 if (adapter
->npars
[pci_func
].type
!= QLCNIC_TYPE_NIC
)
3687 return QL_STATUS_INVALID_PARAM
;
3689 switch (esw_cfg
[i
].op_mode
) {
3690 case QLCNIC_PORT_DEFAULTS
:
3691 if (QLC_DEV_GET_DRV(op_mode
, pci_func
) !=
3692 QLCNIC_NON_PRIV_FUNC
) {
3693 if (esw_cfg
[i
].mac_anti_spoof
!= 0)
3694 return QL_STATUS_INVALID_PARAM
;
3695 if (esw_cfg
[i
].mac_override
!= 1)
3696 return QL_STATUS_INVALID_PARAM
;
3697 if (esw_cfg
[i
].promisc_mode
!= 1)
3698 return QL_STATUS_INVALID_PARAM
;
3701 case QLCNIC_ADD_VLAN
:
3702 if (!IS_VALID_VLAN(esw_cfg
[i
].vlan_id
))
3703 return QL_STATUS_INVALID_PARAM
;
3704 if (!esw_cfg
[i
].op_type
)
3705 return QL_STATUS_INVALID_PARAM
;
3707 case QLCNIC_DEL_VLAN
:
3708 if (!esw_cfg
[i
].op_type
)
3709 return QL_STATUS_INVALID_PARAM
;
3712 return QL_STATUS_INVALID_PARAM
;
3719 qlcnic_sysfs_write_esw_config(struct file
*file
, struct kobject
*kobj
,
3720 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3722 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3723 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3724 struct qlcnic_esw_func_cfg
*esw_cfg
;
3725 struct qlcnic_npar_info
*npar
;
3726 int count
, rem
, i
, ret
;
3727 u8 pci_func
, op_mode
= 0;
3729 count
= size
/ sizeof(struct qlcnic_esw_func_cfg
);
3730 rem
= size
% sizeof(struct qlcnic_esw_func_cfg
);
3732 return QL_STATUS_INVALID_PARAM
;
3734 esw_cfg
= (struct qlcnic_esw_func_cfg
*) buf
;
3735 ret
= validate_esw_config(adapter
, esw_cfg
, count
);
3739 for (i
= 0; i
< count
; i
++) {
3740 if (adapter
->op_mode
== QLCNIC_MGMT_FUNC
)
3741 if (qlcnic_config_switch_port(adapter
, &esw_cfg
[i
]))
3742 return QL_STATUS_INVALID_PARAM
;
3744 if (adapter
->ahw
->pci_func
!= esw_cfg
[i
].pci_func
)
3747 op_mode
= esw_cfg
[i
].op_mode
;
3748 qlcnic_get_eswitch_port_config(adapter
, &esw_cfg
[i
]);
3749 esw_cfg
[i
].op_mode
= op_mode
;
3750 esw_cfg
[i
].pci_func
= adapter
->ahw
->pci_func
;
3752 switch (esw_cfg
[i
].op_mode
) {
3753 case QLCNIC_PORT_DEFAULTS
:
3754 qlcnic_set_eswitch_port_features(adapter
, &esw_cfg
[i
]);
3756 case QLCNIC_ADD_VLAN
:
3757 qlcnic_set_vlan_config(adapter
, &esw_cfg
[i
]);
3759 case QLCNIC_DEL_VLAN
:
3760 esw_cfg
[i
].vlan_id
= 0;
3761 qlcnic_set_vlan_config(adapter
, &esw_cfg
[i
]);
3766 if (adapter
->op_mode
!= QLCNIC_MGMT_FUNC
)
3769 for (i
= 0; i
< count
; i
++) {
3770 pci_func
= esw_cfg
[i
].pci_func
;
3771 npar
= &adapter
->npars
[pci_func
];
3772 switch (esw_cfg
[i
].op_mode
) {
3773 case QLCNIC_PORT_DEFAULTS
:
3774 npar
->promisc_mode
= esw_cfg
[i
].promisc_mode
;
3775 npar
->mac_override
= esw_cfg
[i
].mac_override
;
3776 npar
->offload_flags
= esw_cfg
[i
].offload_flags
;
3777 npar
->mac_anti_spoof
= esw_cfg
[i
].mac_anti_spoof
;
3778 npar
->discard_tagged
= esw_cfg
[i
].discard_tagged
;
3780 case QLCNIC_ADD_VLAN
:
3781 npar
->pvid
= esw_cfg
[i
].vlan_id
;
3783 case QLCNIC_DEL_VLAN
:
3793 qlcnic_sysfs_read_esw_config(struct file
*file
, struct kobject
*kobj
,
3794 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3796 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3797 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3798 struct qlcnic_esw_func_cfg esw_cfg
[QLCNIC_MAX_PCI_FUNC
];
3801 if (size
!= sizeof(esw_cfg
))
3802 return QL_STATUS_INVALID_PARAM
;
3804 for (i
= 0; i
< QLCNIC_MAX_PCI_FUNC
; i
++) {
3805 if (adapter
->npars
[i
].type
!= QLCNIC_TYPE_NIC
)
3807 esw_cfg
[i
].pci_func
= i
;
3808 if (qlcnic_get_eswitch_port_config(adapter
, &esw_cfg
[i
]))
3809 return QL_STATUS_INVALID_PARAM
;
3811 memcpy(buf
, &esw_cfg
, size
);
3817 validate_npar_config(struct qlcnic_adapter
*adapter
,
3818 struct qlcnic_npar_func_cfg
*np_cfg
, int count
)
3822 for (i
= 0; i
< count
; i
++) {
3823 pci_func
= np_cfg
[i
].pci_func
;
3824 if (pci_func
>= QLCNIC_MAX_PCI_FUNC
)
3825 return QL_STATUS_INVALID_PARAM
;
3827 if (adapter
->npars
[pci_func
].type
!= QLCNIC_TYPE_NIC
)
3828 return QL_STATUS_INVALID_PARAM
;
3830 if (!IS_VALID_BW(np_cfg
[i
].min_bw
) ||
3831 !IS_VALID_BW(np_cfg
[i
].max_bw
))
3832 return QL_STATUS_INVALID_PARAM
;
3838 qlcnic_sysfs_write_npar_config(struct file
*file
, struct kobject
*kobj
,
3839 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3841 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3842 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3843 struct qlcnic_info nic_info
;
3844 struct qlcnic_npar_func_cfg
*np_cfg
;
3845 int i
, count
, rem
, ret
;
3848 count
= size
/ sizeof(struct qlcnic_npar_func_cfg
);
3849 rem
= size
% sizeof(struct qlcnic_npar_func_cfg
);
3851 return QL_STATUS_INVALID_PARAM
;
3853 np_cfg
= (struct qlcnic_npar_func_cfg
*) buf
;
3854 ret
= validate_npar_config(adapter
, np_cfg
, count
);
3858 for (i
= 0; i
< count
; i
++) {
3859 pci_func
= np_cfg
[i
].pci_func
;
3860 ret
= qlcnic_get_nic_info(adapter
, &nic_info
, pci_func
);
3863 nic_info
.pci_func
= pci_func
;
3864 nic_info
.min_tx_bw
= np_cfg
[i
].min_bw
;
3865 nic_info
.max_tx_bw
= np_cfg
[i
].max_bw
;
3866 ret
= qlcnic_set_nic_info(adapter
, &nic_info
);
3869 adapter
->npars
[i
].min_bw
= nic_info
.min_tx_bw
;
3870 adapter
->npars
[i
].max_bw
= nic_info
.max_tx_bw
;
3877 qlcnic_sysfs_read_npar_config(struct file
*file
, struct kobject
*kobj
,
3878 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3880 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3881 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3882 struct qlcnic_info nic_info
;
3883 struct qlcnic_npar_func_cfg np_cfg
[QLCNIC_MAX_PCI_FUNC
];
3886 if (size
!= sizeof(np_cfg
))
3887 return QL_STATUS_INVALID_PARAM
;
3889 for (i
= 0; i
< QLCNIC_MAX_PCI_FUNC
; i
++) {
3890 if (adapter
->npars
[i
].type
!= QLCNIC_TYPE_NIC
)
3892 ret
= qlcnic_get_nic_info(adapter
, &nic_info
, i
);
3896 np_cfg
[i
].pci_func
= i
;
3897 np_cfg
[i
].op_mode
= (u8
)nic_info
.op_mode
;
3898 np_cfg
[i
].port_num
= nic_info
.phys_port
;
3899 np_cfg
[i
].fw_capab
= nic_info
.capabilities
;
3900 np_cfg
[i
].min_bw
= nic_info
.min_tx_bw
;
3901 np_cfg
[i
].max_bw
= nic_info
.max_tx_bw
;
3902 np_cfg
[i
].max_tx_queues
= nic_info
.max_tx_ques
;
3903 np_cfg
[i
].max_rx_queues
= nic_info
.max_rx_ques
;
3905 memcpy(buf
, &np_cfg
, size
);
3910 qlcnic_sysfs_get_port_stats(struct file
*file
, struct kobject
*kobj
,
3911 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3913 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3914 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3915 struct qlcnic_esw_statistics port_stats
;
3918 if (size
!= sizeof(struct qlcnic_esw_statistics
))
3919 return QL_STATUS_INVALID_PARAM
;
3921 if (offset
>= QLCNIC_MAX_PCI_FUNC
)
3922 return QL_STATUS_INVALID_PARAM
;
3924 memset(&port_stats
, 0, size
);
3925 ret
= qlcnic_get_port_stats(adapter
, offset
, QLCNIC_QUERY_RX_COUNTER
,
3930 ret
= qlcnic_get_port_stats(adapter
, offset
, QLCNIC_QUERY_TX_COUNTER
,
3935 memcpy(buf
, &port_stats
, size
);
3940 qlcnic_sysfs_get_esw_stats(struct file
*file
, struct kobject
*kobj
,
3941 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3943 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3944 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3945 struct qlcnic_esw_statistics esw_stats
;
3948 if (size
!= sizeof(struct qlcnic_esw_statistics
))
3949 return QL_STATUS_INVALID_PARAM
;
3951 if (offset
>= QLCNIC_NIU_MAX_XG_PORTS
)
3952 return QL_STATUS_INVALID_PARAM
;
3954 memset(&esw_stats
, 0, size
);
3955 ret
= qlcnic_get_eswitch_stats(adapter
, offset
, QLCNIC_QUERY_RX_COUNTER
,
3960 ret
= qlcnic_get_eswitch_stats(adapter
, offset
, QLCNIC_QUERY_TX_COUNTER
,
3965 memcpy(buf
, &esw_stats
, size
);
3970 qlcnic_sysfs_clear_esw_stats(struct file
*file
, struct kobject
*kobj
,
3971 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3973 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3974 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3977 if (offset
>= QLCNIC_NIU_MAX_XG_PORTS
)
3978 return QL_STATUS_INVALID_PARAM
;
3980 ret
= qlcnic_clear_esw_stats(adapter
, QLCNIC_STATS_ESWITCH
, offset
,
3981 QLCNIC_QUERY_RX_COUNTER
);
3985 ret
= qlcnic_clear_esw_stats(adapter
, QLCNIC_STATS_ESWITCH
, offset
,
3986 QLCNIC_QUERY_TX_COUNTER
);
3994 qlcnic_sysfs_clear_port_stats(struct file
*file
, struct kobject
*kobj
,
3995 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3998 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3999 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
4002 if (offset
>= QLCNIC_MAX_PCI_FUNC
)
4003 return QL_STATUS_INVALID_PARAM
;
4005 ret
= qlcnic_clear_esw_stats(adapter
, QLCNIC_STATS_PORT
, offset
,
4006 QLCNIC_QUERY_RX_COUNTER
);
4010 ret
= qlcnic_clear_esw_stats(adapter
, QLCNIC_STATS_PORT
, offset
,
4011 QLCNIC_QUERY_TX_COUNTER
);
4019 qlcnic_sysfs_read_pci_config(struct file
*file
, struct kobject
*kobj
,
4020 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
4022 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
4023 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
4024 struct qlcnic_pci_func_cfg pci_cfg
[QLCNIC_MAX_PCI_FUNC
];
4025 struct qlcnic_pci_info
*pci_info
;
4028 if (size
!= sizeof(pci_cfg
))
4029 return QL_STATUS_INVALID_PARAM
;
4031 pci_info
= kcalloc(QLCNIC_MAX_PCI_FUNC
, sizeof(*pci_info
), GFP_KERNEL
);
4035 ret
= qlcnic_get_pci_info(adapter
, pci_info
);
4041 for (i
= 0; i
< QLCNIC_MAX_PCI_FUNC
; i
++) {
4042 pci_cfg
[i
].pci_func
= pci_info
[i
].id
;
4043 pci_cfg
[i
].func_type
= pci_info
[i
].type
;
4044 pci_cfg
[i
].port_num
= pci_info
[i
].default_port
;
4045 pci_cfg
[i
].min_bw
= pci_info
[i
].tx_min_bw
;
4046 pci_cfg
[i
].max_bw
= pci_info
[i
].tx_max_bw
;
4047 memcpy(&pci_cfg
[i
].def_mac_addr
, &pci_info
[i
].mac
, ETH_ALEN
);
4049 memcpy(buf
, &pci_cfg
, size
);
4053 static struct bin_attribute bin_attr_npar_config
= {
4054 .attr
= {.name
= "npar_config", .mode
= (S_IRUGO
| S_IWUSR
)},
4056 .read
= qlcnic_sysfs_read_npar_config
,
4057 .write
= qlcnic_sysfs_write_npar_config
,
4060 static struct bin_attribute bin_attr_pci_config
= {
4061 .attr
= {.name
= "pci_config", .mode
= (S_IRUGO
| S_IWUSR
)},
4063 .read
= qlcnic_sysfs_read_pci_config
,
4067 static struct bin_attribute bin_attr_port_stats
= {
4068 .attr
= {.name
= "port_stats", .mode
= (S_IRUGO
| S_IWUSR
)},
4070 .read
= qlcnic_sysfs_get_port_stats
,
4071 .write
= qlcnic_sysfs_clear_port_stats
,
4074 static struct bin_attribute bin_attr_esw_stats
= {
4075 .attr
= {.name
= "esw_stats", .mode
= (S_IRUGO
| S_IWUSR
)},
4077 .read
= qlcnic_sysfs_get_esw_stats
,
4078 .write
= qlcnic_sysfs_clear_esw_stats
,
4081 static struct bin_attribute bin_attr_esw_config
= {
4082 .attr
= {.name
= "esw_config", .mode
= (S_IRUGO
| S_IWUSR
)},
4084 .read
= qlcnic_sysfs_read_esw_config
,
4085 .write
= qlcnic_sysfs_write_esw_config
,
4088 static struct bin_attribute bin_attr_pm_config
= {
4089 .attr
= {.name
= "pm_config", .mode
= (S_IRUGO
| S_IWUSR
)},
4091 .read
= qlcnic_sysfs_read_pm_config
,
4092 .write
= qlcnic_sysfs_write_pm_config
,
4096 qlcnic_create_sysfs_entries(struct qlcnic_adapter
*adapter
)
4098 struct device
*dev
= &adapter
->pdev
->dev
;
4100 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_BDG
)
4101 if (device_create_file(dev
, &dev_attr_bridged_mode
))
4103 "failed to create bridged_mode sysfs entry\n");
4107 qlcnic_remove_sysfs_entries(struct qlcnic_adapter
*adapter
)
4109 struct device
*dev
= &adapter
->pdev
->dev
;
4111 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_BDG
)
4112 device_remove_file(dev
, &dev_attr_bridged_mode
);
4116 qlcnic_create_diag_entries(struct qlcnic_adapter
*adapter
)
4118 struct device
*dev
= &adapter
->pdev
->dev
;
4120 if (device_create_bin_file(dev
, &bin_attr_port_stats
))
4121 dev_info(dev
, "failed to create port stats sysfs entry");
4123 if (adapter
->op_mode
== QLCNIC_NON_PRIV_FUNC
)
4125 if (device_create_file(dev
, &dev_attr_diag_mode
))
4126 dev_info(dev
, "failed to create diag_mode sysfs entry\n");
4127 if (device_create_bin_file(dev
, &bin_attr_crb
))
4128 dev_info(dev
, "failed to create crb sysfs entry\n");
4129 if (device_create_bin_file(dev
, &bin_attr_mem
))
4130 dev_info(dev
, "failed to create mem sysfs entry\n");
4131 if (device_create_bin_file(dev
, &bin_attr_pci_config
))
4132 dev_info(dev
, "failed to create pci config sysfs entry");
4133 if (!(adapter
->flags
& QLCNIC_ESWITCH_ENABLED
))
4135 if (device_create_bin_file(dev
, &bin_attr_esw_config
))
4136 dev_info(dev
, "failed to create esw config sysfs entry");
4137 if (adapter
->op_mode
!= QLCNIC_MGMT_FUNC
)
4139 if (device_create_bin_file(dev
, &bin_attr_npar_config
))
4140 dev_info(dev
, "failed to create npar config sysfs entry");
4141 if (device_create_bin_file(dev
, &bin_attr_pm_config
))
4142 dev_info(dev
, "failed to create pm config sysfs entry");
4143 if (device_create_bin_file(dev
, &bin_attr_esw_stats
))
4144 dev_info(dev
, "failed to create eswitch stats sysfs entry");
4148 qlcnic_remove_diag_entries(struct qlcnic_adapter
*adapter
)
4150 struct device
*dev
= &adapter
->pdev
->dev
;
4152 device_remove_bin_file(dev
, &bin_attr_port_stats
);
4154 if (adapter
->op_mode
== QLCNIC_NON_PRIV_FUNC
)
4156 device_remove_file(dev
, &dev_attr_diag_mode
);
4157 device_remove_bin_file(dev
, &bin_attr_crb
);
4158 device_remove_bin_file(dev
, &bin_attr_mem
);
4159 device_remove_bin_file(dev
, &bin_attr_pci_config
);
4160 if (!(adapter
->flags
& QLCNIC_ESWITCH_ENABLED
))
4162 device_remove_bin_file(dev
, &bin_attr_esw_config
);
4163 if (adapter
->op_mode
!= QLCNIC_MGMT_FUNC
)
4165 device_remove_bin_file(dev
, &bin_attr_npar_config
);
4166 device_remove_bin_file(dev
, &bin_attr_pm_config
);
4167 device_remove_bin_file(dev
, &bin_attr_esw_stats
);
4172 #define is_qlcnic_netdev(dev) (dev->netdev_ops == &qlcnic_netdev_ops)
4175 qlcnic_config_indev_addr(struct qlcnic_adapter
*adapter
,
4176 struct net_device
*dev
, unsigned long event
)
4178 struct in_device
*indev
;
4180 indev
= in_dev_get(dev
);
4187 qlcnic_config_ipaddr(adapter
,
4188 ifa
->ifa_address
, QLCNIC_IP_UP
);
4191 qlcnic_config_ipaddr(adapter
,
4192 ifa
->ifa_address
, QLCNIC_IP_DOWN
);
4197 } endfor_ifa(indev
);
4203 qlcnic_restore_indev_addr(struct net_device
*netdev
, unsigned long event
)
4205 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
4206 struct net_device
*dev
;
4209 qlcnic_config_indev_addr(adapter
, netdev
, event
);
4211 for_each_set_bit(vid
, adapter
->vlans
, VLAN_N_VID
) {
4212 dev
= __vlan_find_dev_deep(netdev
, vid
);
4215 qlcnic_config_indev_addr(adapter
, dev
, event
);
4219 static int qlcnic_netdev_event(struct notifier_block
*this,
4220 unsigned long event
, void *ptr
)
4222 struct qlcnic_adapter
*adapter
;
4223 struct net_device
*dev
= (struct net_device
*)ptr
;
4229 if (dev
->priv_flags
& IFF_802_1Q_VLAN
) {
4230 dev
= vlan_dev_real_dev(dev
);
4234 if (!is_qlcnic_netdev(dev
))
4237 adapter
= netdev_priv(dev
);
4242 if (!test_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
4245 qlcnic_config_indev_addr(adapter
, dev
, event
);
4251 qlcnic_inetaddr_event(struct notifier_block
*this,
4252 unsigned long event
, void *ptr
)
4254 struct qlcnic_adapter
*adapter
;
4255 struct net_device
*dev
;
4257 struct in_ifaddr
*ifa
= (struct in_ifaddr
*)ptr
;
4259 dev
= ifa
->ifa_dev
? ifa
->ifa_dev
->dev
: NULL
;
4265 if (dev
->priv_flags
& IFF_802_1Q_VLAN
) {
4266 dev
= vlan_dev_real_dev(dev
);
4270 if (!is_qlcnic_netdev(dev
))
4273 adapter
= netdev_priv(dev
);
4278 if (!test_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
4283 qlcnic_config_ipaddr(adapter
, ifa
->ifa_address
, QLCNIC_IP_UP
);
4286 qlcnic_config_ipaddr(adapter
, ifa
->ifa_address
, QLCNIC_IP_DOWN
);
4296 static struct notifier_block qlcnic_netdev_cb
= {
4297 .notifier_call
= qlcnic_netdev_event
,
4300 static struct notifier_block qlcnic_inetaddr_cb
= {
4301 .notifier_call
= qlcnic_inetaddr_event
,
4305 qlcnic_restore_indev_addr(struct net_device
*dev
, unsigned long event
)
4308 static struct pci_error_handlers qlcnic_err_handler
= {
4309 .error_detected
= qlcnic_io_error_detected
,
4310 .slot_reset
= qlcnic_io_slot_reset
,
4311 .resume
= qlcnic_io_resume
,
4314 static struct pci_driver qlcnic_driver
= {
4315 .name
= qlcnic_driver_name
,
4316 .id_table
= qlcnic_pci_tbl
,
4317 .probe
= qlcnic_probe
,
4318 .remove
= __devexit_p(qlcnic_remove
),
4320 .suspend
= qlcnic_suspend
,
4321 .resume
= qlcnic_resume
,
4323 .shutdown
= qlcnic_shutdown
,
4324 .err_handler
= &qlcnic_err_handler
4328 static int __init
qlcnic_init_module(void)
4332 printk(KERN_INFO
"%s\n", qlcnic_driver_string
);
4334 qlcnic_wq
= create_singlethread_workqueue("qlcnic");
4335 if (qlcnic_wq
== NULL
) {
4336 printk(KERN_ERR
"qlcnic: cannot create workqueue\n");
4341 register_netdevice_notifier(&qlcnic_netdev_cb
);
4342 register_inetaddr_notifier(&qlcnic_inetaddr_cb
);
4345 ret
= pci_register_driver(&qlcnic_driver
);
4348 unregister_inetaddr_notifier(&qlcnic_inetaddr_cb
);
4349 unregister_netdevice_notifier(&qlcnic_netdev_cb
);
4351 destroy_workqueue(qlcnic_wq
);
4357 module_init(qlcnic_init_module
);
4359 static void __exit
qlcnic_exit_module(void)
4362 pci_unregister_driver(&qlcnic_driver
);
4365 unregister_inetaddr_notifier(&qlcnic_inetaddr_cb
);
4366 unregister_netdevice_notifier(&qlcnic_netdev_cb
);
4368 destroy_workqueue(qlcnic_wq
);
4371 module_exit(qlcnic_exit_module
);