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_rx_mode
= 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
, prev_fw_version
;
647 struct pci_dev
*pdev
= adapter
->pdev
;
648 struct qlcnic_fw_dump
*fw_dump
= &adapter
->ahw
->fw_dump
;
650 prev_fw_version
= adapter
->fw_version
;
652 fw_major
= QLCRD32(adapter
, QLCNIC_FW_VERSION_MAJOR
);
653 fw_minor
= QLCRD32(adapter
, QLCNIC_FW_VERSION_MINOR
);
654 fw_build
= QLCRD32(adapter
, QLCNIC_FW_VERSION_SUB
);
656 adapter
->fw_version
= QLCNIC_VERSION_CODE(fw_major
, fw_minor
, fw_build
);
658 if (adapter
->op_mode
!= QLCNIC_NON_PRIV_FUNC
) {
659 if (fw_dump
->tmpl_hdr
== NULL
||
660 adapter
->fw_version
> prev_fw_version
) {
661 if (fw_dump
->tmpl_hdr
)
662 vfree(fw_dump
->tmpl_hdr
);
663 if (!qlcnic_fw_cmd_get_minidump_temp(adapter
))
665 "Supports FW dump capability\n");
669 dev_info(&pdev
->dev
, "firmware v%d.%d.%d\n",
670 fw_major
, fw_minor
, fw_build
);
671 if (adapter
->ahw
->port_type
== QLCNIC_XGBE
) {
672 if (adapter
->flags
& QLCNIC_ESWITCH_ENABLED
) {
673 adapter
->num_rxd
= DEFAULT_RCV_DESCRIPTORS_VF
;
674 adapter
->max_rxd
= MAX_RCV_DESCRIPTORS_VF
;
676 adapter
->num_rxd
= DEFAULT_RCV_DESCRIPTORS_10G
;
677 adapter
->max_rxd
= MAX_RCV_DESCRIPTORS_10G
;
680 adapter
->num_jumbo_rxd
= MAX_JUMBO_RCV_DESCRIPTORS_10G
;
681 adapter
->max_jumbo_rxd
= MAX_JUMBO_RCV_DESCRIPTORS_10G
;
683 } else if (adapter
->ahw
->port_type
== QLCNIC_GBE
) {
684 adapter
->num_rxd
= DEFAULT_RCV_DESCRIPTORS_1G
;
685 adapter
->num_jumbo_rxd
= MAX_JUMBO_RCV_DESCRIPTORS_1G
;
686 adapter
->max_jumbo_rxd
= MAX_JUMBO_RCV_DESCRIPTORS_1G
;
687 adapter
->max_rxd
= MAX_RCV_DESCRIPTORS_1G
;
690 adapter
->msix_supported
= !!use_msi_x
;
692 adapter
->num_txd
= MAX_CMD_DESCRIPTORS
;
694 adapter
->max_rds_rings
= MAX_RDS_RINGS
;
698 qlcnic_initialize_nic(struct qlcnic_adapter
*adapter
)
701 struct qlcnic_info nic_info
;
703 err
= qlcnic_get_nic_info(adapter
, &nic_info
, adapter
->ahw
->pci_func
);
707 adapter
->physical_port
= (u8
)nic_info
.phys_port
;
708 adapter
->switch_mode
= nic_info
.switch_mode
;
709 adapter
->max_tx_ques
= nic_info
.max_tx_ques
;
710 adapter
->max_rx_ques
= nic_info
.max_rx_ques
;
711 adapter
->capabilities
= nic_info
.capabilities
;
712 adapter
->max_mac_filters
= nic_info
.max_mac_filters
;
713 adapter
->max_mtu
= nic_info
.max_mtu
;
715 if (adapter
->capabilities
& BIT_6
)
716 adapter
->flags
|= QLCNIC_ESWITCH_ENABLED
;
718 adapter
->flags
&= ~QLCNIC_ESWITCH_ENABLED
;
724 qlcnic_set_vlan_config(struct qlcnic_adapter
*adapter
,
725 struct qlcnic_esw_func_cfg
*esw_cfg
)
727 if (esw_cfg
->discard_tagged
)
728 adapter
->flags
&= ~QLCNIC_TAGGING_ENABLED
;
730 adapter
->flags
|= QLCNIC_TAGGING_ENABLED
;
732 if (esw_cfg
->vlan_id
)
733 adapter
->pvid
= esw_cfg
->vlan_id
;
739 qlcnic_vlan_rx_add(struct net_device
*netdev
, u16 vid
)
741 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
742 set_bit(vid
, adapter
->vlans
);
746 qlcnic_vlan_rx_del(struct net_device
*netdev
, u16 vid
)
748 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
750 qlcnic_restore_indev_addr(netdev
, NETDEV_DOWN
);
751 clear_bit(vid
, adapter
->vlans
);
755 qlcnic_set_eswitch_port_features(struct qlcnic_adapter
*adapter
,
756 struct qlcnic_esw_func_cfg
*esw_cfg
)
758 adapter
->flags
&= ~(QLCNIC_MACSPOOF
| QLCNIC_MAC_OVERRIDE_DISABLED
|
759 QLCNIC_PROMISC_DISABLED
);
761 if (esw_cfg
->mac_anti_spoof
)
762 adapter
->flags
|= QLCNIC_MACSPOOF
;
764 if (!esw_cfg
->mac_override
)
765 adapter
->flags
|= QLCNIC_MAC_OVERRIDE_DISABLED
;
767 if (!esw_cfg
->promisc_mode
)
768 adapter
->flags
|= QLCNIC_PROMISC_DISABLED
;
770 qlcnic_set_netdev_features(adapter
, esw_cfg
);
774 qlcnic_set_eswitch_port_config(struct qlcnic_adapter
*adapter
)
776 struct qlcnic_esw_func_cfg esw_cfg
;
778 if (!(adapter
->flags
& QLCNIC_ESWITCH_ENABLED
))
781 esw_cfg
.pci_func
= adapter
->ahw
->pci_func
;
782 if (qlcnic_get_eswitch_port_config(adapter
, &esw_cfg
))
784 qlcnic_set_vlan_config(adapter
, &esw_cfg
);
785 qlcnic_set_eswitch_port_features(adapter
, &esw_cfg
);
791 qlcnic_set_netdev_features(struct qlcnic_adapter
*adapter
,
792 struct qlcnic_esw_func_cfg
*esw_cfg
)
794 struct net_device
*netdev
= adapter
->netdev
;
795 unsigned long features
, vlan_features
;
797 features
= (NETIF_F_SG
| NETIF_F_IP_CSUM
| NETIF_F_RXCSUM
|
798 NETIF_F_IPV6_CSUM
| NETIF_F_GRO
);
799 vlan_features
= (NETIF_F_SG
| NETIF_F_IP_CSUM
|
800 NETIF_F_IPV6_CSUM
| NETIF_F_HW_VLAN_FILTER
);
802 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_TSO
) {
803 features
|= (NETIF_F_TSO
| NETIF_F_TSO6
);
804 vlan_features
|= (NETIF_F_TSO
| NETIF_F_TSO6
);
807 if (netdev
->features
& NETIF_F_LRO
)
808 features
|= NETIF_F_LRO
;
810 if (esw_cfg
->offload_flags
& BIT_0
) {
811 netdev
->features
|= features
;
812 if (!(esw_cfg
->offload_flags
& BIT_1
))
813 netdev
->features
&= ~NETIF_F_TSO
;
814 if (!(esw_cfg
->offload_flags
& BIT_2
))
815 netdev
->features
&= ~NETIF_F_TSO6
;
817 netdev
->features
&= ~features
;
820 netdev
->vlan_features
= (features
& vlan_features
);
824 qlcnic_check_eswitch_mode(struct qlcnic_adapter
*adapter
)
826 void __iomem
*priv_op
;
827 u32 op_mode
, priv_level
;
830 err
= qlcnic_initialize_nic(adapter
);
834 if (adapter
->flags
& QLCNIC_ADAPTER_INITIALIZED
)
837 priv_op
= adapter
->ahw
->pci_base0
+ QLCNIC_DRV_OP_MODE
;
838 op_mode
= readl(priv_op
);
839 priv_level
= QLC_DEV_GET_DRV(op_mode
, adapter
->ahw
->pci_func
);
841 if (op_mode
== QLC_DEV_DRV_DEFAULT
)
842 priv_level
= QLCNIC_MGMT_FUNC
;
844 priv_level
= QLC_DEV_GET_DRV(op_mode
, adapter
->ahw
->pci_func
);
846 if (adapter
->flags
& QLCNIC_ESWITCH_ENABLED
) {
847 if (priv_level
== QLCNIC_MGMT_FUNC
) {
848 adapter
->op_mode
= QLCNIC_MGMT_FUNC
;
849 err
= qlcnic_init_pci_info(adapter
);
852 /* Set privilege level for other functions */
853 qlcnic_set_function_modes(adapter
);
854 dev_info(&adapter
->pdev
->dev
,
855 "HAL Version: %d, Management function\n",
856 adapter
->fw_hal_version
);
857 } else if (priv_level
== QLCNIC_PRIV_FUNC
) {
858 adapter
->op_mode
= QLCNIC_PRIV_FUNC
;
859 dev_info(&adapter
->pdev
->dev
,
860 "HAL Version: %d, Privileged function\n",
861 adapter
->fw_hal_version
);
865 adapter
->flags
|= QLCNIC_ADAPTER_INITIALIZED
;
871 qlcnic_set_default_offload_settings(struct qlcnic_adapter
*adapter
)
873 struct qlcnic_esw_func_cfg esw_cfg
;
874 struct qlcnic_npar_info
*npar
;
877 if (adapter
->need_fw_reset
)
880 for (i
= 0; i
< QLCNIC_MAX_PCI_FUNC
; i
++) {
881 if (adapter
->npars
[i
].type
!= QLCNIC_TYPE_NIC
)
883 memset(&esw_cfg
, 0, sizeof(struct qlcnic_esw_func_cfg
));
884 esw_cfg
.pci_func
= i
;
885 esw_cfg
.offload_flags
= BIT_0
;
886 esw_cfg
.mac_override
= BIT_0
;
887 esw_cfg
.promisc_mode
= BIT_0
;
888 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_TSO
)
889 esw_cfg
.offload_flags
|= (BIT_1
| BIT_2
);
890 if (qlcnic_config_switch_port(adapter
, &esw_cfg
))
892 npar
= &adapter
->npars
[i
];
893 npar
->pvid
= esw_cfg
.vlan_id
;
894 npar
->mac_override
= esw_cfg
.mac_override
;
895 npar
->mac_anti_spoof
= esw_cfg
.mac_anti_spoof
;
896 npar
->discard_tagged
= esw_cfg
.discard_tagged
;
897 npar
->promisc_mode
= esw_cfg
.promisc_mode
;
898 npar
->offload_flags
= esw_cfg
.offload_flags
;
905 qlcnic_reset_eswitch_config(struct qlcnic_adapter
*adapter
,
906 struct qlcnic_npar_info
*npar
, int pci_func
)
908 struct qlcnic_esw_func_cfg esw_cfg
;
909 esw_cfg
.op_mode
= QLCNIC_PORT_DEFAULTS
;
910 esw_cfg
.pci_func
= pci_func
;
911 esw_cfg
.vlan_id
= npar
->pvid
;
912 esw_cfg
.mac_override
= npar
->mac_override
;
913 esw_cfg
.discard_tagged
= npar
->discard_tagged
;
914 esw_cfg
.mac_anti_spoof
= npar
->mac_anti_spoof
;
915 esw_cfg
.offload_flags
= npar
->offload_flags
;
916 esw_cfg
.promisc_mode
= npar
->promisc_mode
;
917 if (qlcnic_config_switch_port(adapter
, &esw_cfg
))
920 esw_cfg
.op_mode
= QLCNIC_ADD_VLAN
;
921 if (qlcnic_config_switch_port(adapter
, &esw_cfg
))
928 qlcnic_reset_npar_config(struct qlcnic_adapter
*adapter
)
931 struct qlcnic_npar_info
*npar
;
932 struct qlcnic_info nic_info
;
934 if (!adapter
->need_fw_reset
)
937 /* Set the NPAR config data after FW reset */
938 for (i
= 0; i
< QLCNIC_MAX_PCI_FUNC
; i
++) {
939 npar
= &adapter
->npars
[i
];
940 if (npar
->type
!= QLCNIC_TYPE_NIC
)
942 err
= qlcnic_get_nic_info(adapter
, &nic_info
, i
);
945 nic_info
.min_tx_bw
= npar
->min_bw
;
946 nic_info
.max_tx_bw
= npar
->max_bw
;
947 err
= qlcnic_set_nic_info(adapter
, &nic_info
);
951 if (npar
->enable_pm
) {
952 err
= qlcnic_config_port_mirroring(adapter
,
953 npar
->dest_npar
, 1, i
);
957 err
= qlcnic_reset_eswitch_config(adapter
, npar
, i
);
964 static int qlcnic_check_npar_opertional(struct qlcnic_adapter
*adapter
)
966 u8 npar_opt_timeo
= QLCNIC_DEV_NPAR_OPER_TIMEO
;
969 if (adapter
->op_mode
== QLCNIC_MGMT_FUNC
)
972 npar_state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_NPAR_STATE
);
973 while (npar_state
!= QLCNIC_DEV_NPAR_OPER
&& --npar_opt_timeo
) {
975 npar_state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_NPAR_STATE
);
977 if (!npar_opt_timeo
) {
978 dev_err(&adapter
->pdev
->dev
,
979 "Waiting for NPAR state to opertional timeout\n");
986 qlcnic_set_mgmt_operations(struct qlcnic_adapter
*adapter
)
990 if (!(adapter
->flags
& QLCNIC_ESWITCH_ENABLED
) ||
991 adapter
->op_mode
!= QLCNIC_MGMT_FUNC
)
994 err
= qlcnic_set_default_offload_settings(adapter
);
998 err
= qlcnic_reset_npar_config(adapter
);
1002 qlcnic_dev_set_npar_ready(adapter
);
1008 qlcnic_start_firmware(struct qlcnic_adapter
*adapter
)
1012 err
= qlcnic_can_start_firmware(adapter
);
1016 goto check_fw_status
;
1019 qlcnic_request_firmware(adapter
);
1021 err
= qlcnic_check_flash_fw_ver(adapter
);
1025 adapter
->fw_type
= QLCNIC_FLASH_ROMIMAGE
;
1028 err
= qlcnic_need_fw_reset(adapter
);
1030 goto check_fw_status
;
1032 err
= qlcnic_pinit_from_rom(adapter
);
1036 err
= qlcnic_load_firmware(adapter
);
1040 qlcnic_release_firmware(adapter
);
1041 QLCWR32(adapter
, CRB_DRIVER_VERSION
, QLCNIC_DRIVER_VERSION
);
1044 err
= qlcnic_check_fw_status(adapter
);
1048 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
, QLCNIC_DEV_READY
);
1049 qlcnic_idc_debug_info(adapter
, 1);
1051 err
= qlcnic_check_eswitch_mode(adapter
);
1053 dev_err(&adapter
->pdev
->dev
,
1054 "Memory allocation failed for eswitch\n");
1057 err
= qlcnic_set_mgmt_operations(adapter
);
1061 qlcnic_check_options(adapter
);
1062 adapter
->need_fw_reset
= 0;
1064 qlcnic_release_firmware(adapter
);
1068 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
, QLCNIC_DEV_FAILED
);
1069 dev_err(&adapter
->pdev
->dev
, "Device state set to failed\n");
1071 qlcnic_release_firmware(adapter
);
1076 qlcnic_request_irq(struct qlcnic_adapter
*adapter
)
1078 irq_handler_t handler
;
1079 struct qlcnic_host_sds_ring
*sds_ring
;
1082 unsigned long flags
= 0;
1083 struct net_device
*netdev
= adapter
->netdev
;
1084 struct qlcnic_recv_context
*recv_ctx
= adapter
->recv_ctx
;
1086 if (adapter
->diag_test
== QLCNIC_INTERRUPT_TEST
) {
1087 handler
= qlcnic_tmp_intr
;
1088 if (!QLCNIC_IS_MSI_FAMILY(adapter
))
1089 flags
|= IRQF_SHARED
;
1092 if (adapter
->flags
& QLCNIC_MSIX_ENABLED
)
1093 handler
= qlcnic_msix_intr
;
1094 else if (adapter
->flags
& QLCNIC_MSI_ENABLED
)
1095 handler
= qlcnic_msi_intr
;
1097 flags
|= IRQF_SHARED
;
1098 handler
= qlcnic_intr
;
1101 adapter
->irq
= netdev
->irq
;
1103 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
1104 sds_ring
= &recv_ctx
->sds_rings
[ring
];
1105 sprintf(sds_ring
->name
, "%s[%d]", netdev
->name
, ring
);
1106 err
= request_irq(sds_ring
->irq
, handler
,
1107 flags
, sds_ring
->name
, sds_ring
);
1116 qlcnic_free_irq(struct qlcnic_adapter
*adapter
)
1119 struct qlcnic_host_sds_ring
*sds_ring
;
1121 struct qlcnic_recv_context
*recv_ctx
= adapter
->recv_ctx
;
1123 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
1124 sds_ring
= &recv_ctx
->sds_rings
[ring
];
1125 free_irq(sds_ring
->irq
, sds_ring
);
1130 __qlcnic_up(struct qlcnic_adapter
*adapter
, struct net_device
*netdev
)
1133 struct qlcnic_host_rds_ring
*rds_ring
;
1135 if (adapter
->is_up
!= QLCNIC_ADAPTER_UP_MAGIC
)
1138 if (test_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
1140 if (qlcnic_set_eswitch_port_config(adapter
))
1143 if (qlcnic_fw_create_ctx(adapter
))
1146 for (ring
= 0; ring
< adapter
->max_rds_rings
; ring
++) {
1147 rds_ring
= &adapter
->recv_ctx
->rds_rings
[ring
];
1148 qlcnic_post_rx_buffers(adapter
, rds_ring
);
1151 qlcnic_set_multi(netdev
);
1152 qlcnic_fw_cmd_set_mtu(adapter
, netdev
->mtu
);
1154 adapter
->ahw
->linkup
= 0;
1156 if (adapter
->max_sds_rings
> 1)
1157 qlcnic_config_rss(adapter
, 1);
1159 qlcnic_config_intr_coalesce(adapter
);
1161 if (netdev
->features
& NETIF_F_LRO
)
1162 qlcnic_config_hw_lro(adapter
, QLCNIC_LRO_ENABLED
);
1164 qlcnic_napi_enable(adapter
);
1166 qlcnic_linkevent_request(adapter
, 1);
1168 adapter
->reset_context
= 0;
1169 set_bit(__QLCNIC_DEV_UP
, &adapter
->state
);
1173 /* Usage: During resume and firmware recovery module.*/
1176 qlcnic_up(struct qlcnic_adapter
*adapter
, struct net_device
*netdev
)
1181 if (netif_running(netdev
))
1182 err
= __qlcnic_up(adapter
, netdev
);
1189 __qlcnic_down(struct qlcnic_adapter
*adapter
, struct net_device
*netdev
)
1191 if (adapter
->is_up
!= QLCNIC_ADAPTER_UP_MAGIC
)
1194 if (!test_and_clear_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
1198 spin_lock(&adapter
->tx_clean_lock
);
1199 netif_carrier_off(netdev
);
1200 netif_tx_disable(netdev
);
1202 qlcnic_free_mac_list(adapter
);
1204 if (adapter
->fhash
.fnum
)
1205 qlcnic_delete_lb_filters(adapter
);
1207 qlcnic_nic_set_promisc(adapter
, QLCNIC_NIU_NON_PROMISC_MODE
);
1209 qlcnic_napi_disable(adapter
);
1211 qlcnic_fw_destroy_ctx(adapter
);
1213 qlcnic_reset_rx_buffers_list(adapter
);
1214 qlcnic_release_tx_buffers(adapter
);
1215 spin_unlock(&adapter
->tx_clean_lock
);
1218 /* Usage: During suspend and firmware recovery module */
1221 qlcnic_down(struct qlcnic_adapter
*adapter
, struct net_device
*netdev
)
1224 if (netif_running(netdev
))
1225 __qlcnic_down(adapter
, netdev
);
1231 qlcnic_attach(struct qlcnic_adapter
*adapter
)
1233 struct net_device
*netdev
= adapter
->netdev
;
1234 struct pci_dev
*pdev
= adapter
->pdev
;
1237 if (adapter
->is_up
== QLCNIC_ADAPTER_UP_MAGIC
)
1240 err
= qlcnic_napi_add(adapter
, netdev
);
1244 err
= qlcnic_alloc_sw_resources(adapter
);
1246 dev_err(&pdev
->dev
, "Error in setting sw resources\n");
1247 goto err_out_napi_del
;
1250 err
= qlcnic_alloc_hw_resources(adapter
);
1252 dev_err(&pdev
->dev
, "Error in setting hw resources\n");
1253 goto err_out_free_sw
;
1256 err
= qlcnic_request_irq(adapter
);
1258 dev_err(&pdev
->dev
, "failed to setup interrupt\n");
1259 goto err_out_free_hw
;
1262 qlcnic_create_sysfs_entries(adapter
);
1264 adapter
->is_up
= QLCNIC_ADAPTER_UP_MAGIC
;
1268 qlcnic_free_hw_resources(adapter
);
1270 qlcnic_free_sw_resources(adapter
);
1272 qlcnic_napi_del(adapter
);
1277 qlcnic_detach(struct qlcnic_adapter
*adapter
)
1279 if (adapter
->is_up
!= QLCNIC_ADAPTER_UP_MAGIC
)
1282 qlcnic_remove_sysfs_entries(adapter
);
1284 qlcnic_free_hw_resources(adapter
);
1285 qlcnic_release_rx_buffers(adapter
);
1286 qlcnic_free_irq(adapter
);
1287 qlcnic_napi_del(adapter
);
1288 qlcnic_free_sw_resources(adapter
);
1293 void qlcnic_diag_free_res(struct net_device
*netdev
, int max_sds_rings
)
1295 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
1296 struct qlcnic_host_sds_ring
*sds_ring
;
1299 clear_bit(__QLCNIC_DEV_UP
, &adapter
->state
);
1300 if (adapter
->diag_test
== QLCNIC_INTERRUPT_TEST
) {
1301 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
1302 sds_ring
= &adapter
->recv_ctx
->sds_rings
[ring
];
1303 qlcnic_disable_int(sds_ring
);
1307 qlcnic_fw_destroy_ctx(adapter
);
1309 qlcnic_detach(adapter
);
1311 adapter
->diag_test
= 0;
1312 adapter
->max_sds_rings
= max_sds_rings
;
1314 if (qlcnic_attach(adapter
))
1317 if (netif_running(netdev
))
1318 __qlcnic_up(adapter
, netdev
);
1320 netif_device_attach(netdev
);
1323 static int qlcnic_alloc_adapter_resources(struct qlcnic_adapter
*adapter
)
1326 adapter
->ahw
= kzalloc(sizeof(struct qlcnic_hardware_context
),
1328 if (!adapter
->ahw
) {
1329 dev_err(&adapter
->pdev
->dev
,
1330 "Failed to allocate recv ctx resources for adapter\n");
1334 adapter
->recv_ctx
= kzalloc(sizeof(struct qlcnic_recv_context
),
1336 if (!adapter
->recv_ctx
) {
1337 dev_err(&adapter
->pdev
->dev
,
1338 "Failed to allocate recv ctx resources for adapter\n");
1339 kfree(adapter
->ahw
);
1340 adapter
->ahw
= NULL
;
1344 /* Initialize interrupt coalesce parameters */
1345 adapter
->ahw
->coal
.flag
= QLCNIC_INTR_DEFAULT
;
1346 adapter
->ahw
->coal
.rx_time_us
= QLCNIC_DEFAULT_INTR_COALESCE_RX_TIME_US
;
1347 adapter
->ahw
->coal
.rx_packets
= QLCNIC_DEFAULT_INTR_COALESCE_RX_PACKETS
;
1352 static void qlcnic_free_adapter_resources(struct qlcnic_adapter
*adapter
)
1354 kfree(adapter
->recv_ctx
);
1355 adapter
->recv_ctx
= NULL
;
1357 if (adapter
->ahw
->fw_dump
.tmpl_hdr
) {
1358 vfree(adapter
->ahw
->fw_dump
.tmpl_hdr
);
1359 adapter
->ahw
->fw_dump
.tmpl_hdr
= NULL
;
1361 kfree(adapter
->ahw
);
1362 adapter
->ahw
= NULL
;
1365 int qlcnic_diag_alloc_res(struct net_device
*netdev
, int test
)
1367 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
1368 struct qlcnic_host_sds_ring
*sds_ring
;
1369 struct qlcnic_host_rds_ring
*rds_ring
;
1373 netif_device_detach(netdev
);
1375 if (netif_running(netdev
))
1376 __qlcnic_down(adapter
, netdev
);
1378 qlcnic_detach(adapter
);
1380 adapter
->max_sds_rings
= 1;
1381 adapter
->diag_test
= test
;
1383 ret
= qlcnic_attach(adapter
);
1385 netif_device_attach(netdev
);
1389 ret
= qlcnic_fw_create_ctx(adapter
);
1391 qlcnic_detach(adapter
);
1392 netif_device_attach(netdev
);
1396 for (ring
= 0; ring
< adapter
->max_rds_rings
; ring
++) {
1397 rds_ring
= &adapter
->recv_ctx
->rds_rings
[ring
];
1398 qlcnic_post_rx_buffers(adapter
, rds_ring
);
1401 if (adapter
->diag_test
== QLCNIC_INTERRUPT_TEST
) {
1402 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
1403 sds_ring
= &adapter
->recv_ctx
->sds_rings
[ring
];
1404 qlcnic_enable_int(sds_ring
);
1408 if (adapter
->diag_test
== QLCNIC_LOOPBACK_TEST
) {
1409 adapter
->ahw
->loopback_state
= 0;
1410 qlcnic_linkevent_request(adapter
, 1);
1413 set_bit(__QLCNIC_DEV_UP
, &adapter
->state
);
1418 /* Reset context in hardware only */
1420 qlcnic_reset_hw_context(struct qlcnic_adapter
*adapter
)
1422 struct net_device
*netdev
= adapter
->netdev
;
1424 if (test_and_set_bit(__QLCNIC_RESETTING
, &adapter
->state
))
1427 netif_device_detach(netdev
);
1429 qlcnic_down(adapter
, netdev
);
1431 qlcnic_up(adapter
, netdev
);
1433 netif_device_attach(netdev
);
1435 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
1440 qlcnic_reset_context(struct qlcnic_adapter
*adapter
)
1443 struct net_device
*netdev
= adapter
->netdev
;
1445 if (test_and_set_bit(__QLCNIC_RESETTING
, &adapter
->state
))
1448 if (adapter
->is_up
== QLCNIC_ADAPTER_UP_MAGIC
) {
1450 netif_device_detach(netdev
);
1452 if (netif_running(netdev
))
1453 __qlcnic_down(adapter
, netdev
);
1455 qlcnic_detach(adapter
);
1457 if (netif_running(netdev
)) {
1458 err
= qlcnic_attach(adapter
);
1460 __qlcnic_up(adapter
, netdev
);
1463 netif_device_attach(netdev
);
1466 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
1471 qlcnic_setup_netdev(struct qlcnic_adapter
*adapter
,
1472 struct net_device
*netdev
, u8 pci_using_dac
)
1475 struct pci_dev
*pdev
= adapter
->pdev
;
1477 adapter
->mc_enabled
= 0;
1478 adapter
->max_mc_count
= 38;
1480 netdev
->netdev_ops
= &qlcnic_netdev_ops
;
1481 netdev
->watchdog_timeo
= 5*HZ
;
1483 qlcnic_change_mtu(netdev
, netdev
->mtu
);
1485 SET_ETHTOOL_OPS(netdev
, &qlcnic_ethtool_ops
);
1487 netdev
->hw_features
= NETIF_F_SG
| NETIF_F_IP_CSUM
|
1488 NETIF_F_IPV6_CSUM
| NETIF_F_RXCSUM
;
1490 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_TSO
)
1491 netdev
->hw_features
|= NETIF_F_TSO
| NETIF_F_TSO6
;
1493 netdev
->hw_features
|= NETIF_F_HIGHDMA
;
1495 netdev
->vlan_features
= netdev
->hw_features
;
1497 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_FVLANTX
)
1498 netdev
->hw_features
|= NETIF_F_HW_VLAN_TX
;
1499 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_HW_LRO
)
1500 netdev
->hw_features
|= NETIF_F_LRO
;
1502 netdev
->features
|= netdev
->hw_features
|
1503 NETIF_F_HW_VLAN_RX
| NETIF_F_HW_VLAN_FILTER
;
1505 netdev
->irq
= adapter
->msix_entries
[0].vector
;
1507 err
= register_netdev(netdev
);
1509 dev_err(&pdev
->dev
, "failed to register net device\n");
1516 static int qlcnic_set_dma_mask(struct pci_dev
*pdev
, u8
*pci_using_dac
)
1518 if (!pci_set_dma_mask(pdev
, DMA_BIT_MASK(64)) &&
1519 !pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(64)))
1521 else if (!pci_set_dma_mask(pdev
, DMA_BIT_MASK(32)) &&
1522 !pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(32)))
1525 dev_err(&pdev
->dev
, "Unable to set DMA mask, aborting\n");
1533 qlcnic_alloc_msix_entries(struct qlcnic_adapter
*adapter
, u16 count
)
1535 adapter
->msix_entries
= kcalloc(count
, sizeof(struct msix_entry
),
1538 if (adapter
->msix_entries
)
1541 dev_err(&adapter
->pdev
->dev
, "failed allocating msix_entries\n");
1545 static int __devinit
1546 qlcnic_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
1548 struct net_device
*netdev
= NULL
;
1549 struct qlcnic_adapter
*adapter
= NULL
;
1551 uint8_t revision_id
;
1552 uint8_t pci_using_dac
;
1553 char brd_name
[QLCNIC_MAX_BOARD_NAME_LEN
];
1555 err
= pci_enable_device(pdev
);
1559 if (!(pci_resource_flags(pdev
, 0) & IORESOURCE_MEM
)) {
1561 goto err_out_disable_pdev
;
1564 err
= qlcnic_set_dma_mask(pdev
, &pci_using_dac
);
1566 goto err_out_disable_pdev
;
1568 err
= pci_request_regions(pdev
, qlcnic_driver_name
);
1570 goto err_out_disable_pdev
;
1572 pci_set_master(pdev
);
1573 pci_enable_pcie_error_reporting(pdev
);
1575 netdev
= alloc_etherdev(sizeof(struct qlcnic_adapter
));
1577 dev_err(&pdev
->dev
, "failed to allocate net_device\n");
1579 goto err_out_free_res
;
1582 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
1584 adapter
= netdev_priv(netdev
);
1585 adapter
->netdev
= netdev
;
1586 adapter
->pdev
= pdev
;
1588 if (qlcnic_alloc_adapter_resources(adapter
))
1589 goto err_out_free_netdev
;
1591 adapter
->dev_rst_time
= jiffies
;
1592 revision_id
= pdev
->revision
;
1593 adapter
->ahw
->revision_id
= revision_id
;
1594 adapter
->mac_learn
= qlcnic_mac_learn
;
1596 rwlock_init(&adapter
->ahw
->crb_lock
);
1597 mutex_init(&adapter
->ahw
->mem_lock
);
1599 spin_lock_init(&adapter
->tx_clean_lock
);
1600 INIT_LIST_HEAD(&adapter
->mac_list
);
1602 err
= qlcnic_setup_pci_map(adapter
);
1604 goto err_out_free_hw
;
1606 /* This will be reset for mezz cards */
1607 adapter
->portnum
= adapter
->ahw
->pci_func
;
1609 err
= qlcnic_get_board_info(adapter
);
1611 dev_err(&pdev
->dev
, "Error getting board config info.\n");
1612 goto err_out_iounmap
;
1615 err
= qlcnic_setup_idc_param(adapter
);
1617 goto err_out_iounmap
;
1619 adapter
->flags
|= QLCNIC_NEED_FLR
;
1621 err
= adapter
->nic_ops
->start_firmware(adapter
);
1623 dev_err(&pdev
->dev
, "Loading fw failed.Please Reboot\n");
1624 goto err_out_decr_ref
;
1627 if (qlcnic_read_mac_addr(adapter
))
1628 dev_warn(&pdev
->dev
, "failed to read mac addr\n");
1630 if (adapter
->portnum
== 0) {
1631 get_brd_name(adapter
, brd_name
);
1633 pr_info("%s: %s Board Chip rev 0x%x\n",
1634 module_name(THIS_MODULE
),
1635 brd_name
, adapter
->ahw
->revision_id
);
1638 qlcnic_clear_stats(adapter
);
1640 err
= qlcnic_alloc_msix_entries(adapter
, adapter
->max_rx_ques
);
1642 goto err_out_decr_ref
;
1644 qlcnic_setup_intr(adapter
);
1646 err
= qlcnic_setup_netdev(adapter
, netdev
, pci_using_dac
);
1648 goto err_out_disable_msi
;
1650 pci_set_drvdata(pdev
, adapter
);
1652 qlcnic_schedule_work(adapter
, qlcnic_fw_poll_work
, FW_POLL_DELAY
);
1654 switch (adapter
->ahw
->port_type
) {
1656 dev_info(&adapter
->pdev
->dev
, "%s: GbE port initialized\n",
1657 adapter
->netdev
->name
);
1660 dev_info(&adapter
->pdev
->dev
, "%s: XGbE port initialized\n",
1661 adapter
->netdev
->name
);
1665 if (adapter
->mac_learn
)
1666 qlcnic_alloc_lb_filters_mem(adapter
);
1668 qlcnic_create_diag_entries(adapter
);
1672 err_out_disable_msi
:
1673 qlcnic_teardown_intr(adapter
);
1674 kfree(adapter
->msix_entries
);
1677 qlcnic_clr_all_drv_state(adapter
, 0);
1680 qlcnic_cleanup_pci_map(adapter
);
1683 qlcnic_free_adapter_resources(adapter
);
1685 err_out_free_netdev
:
1686 free_netdev(netdev
);
1689 pci_release_regions(pdev
);
1691 err_out_disable_pdev
:
1692 pci_set_drvdata(pdev
, NULL
);
1693 pci_disable_device(pdev
);
1697 static void __devexit
qlcnic_remove(struct pci_dev
*pdev
)
1699 struct qlcnic_adapter
*adapter
;
1700 struct net_device
*netdev
;
1702 adapter
= pci_get_drvdata(pdev
);
1703 if (adapter
== NULL
)
1706 netdev
= adapter
->netdev
;
1708 qlcnic_cancel_fw_work(adapter
);
1710 unregister_netdev(netdev
);
1712 qlcnic_detach(adapter
);
1714 if (adapter
->npars
!= NULL
)
1715 kfree(adapter
->npars
);
1716 if (adapter
->eswitch
!= NULL
)
1717 kfree(adapter
->eswitch
);
1719 qlcnic_clr_all_drv_state(adapter
, 0);
1721 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
1723 qlcnic_free_lb_filters_mem(adapter
);
1725 qlcnic_teardown_intr(adapter
);
1726 kfree(adapter
->msix_entries
);
1728 qlcnic_remove_diag_entries(adapter
);
1730 qlcnic_cleanup_pci_map(adapter
);
1732 qlcnic_release_firmware(adapter
);
1734 pci_disable_pcie_error_reporting(pdev
);
1735 pci_release_regions(pdev
);
1736 pci_disable_device(pdev
);
1737 pci_set_drvdata(pdev
, NULL
);
1739 qlcnic_free_adapter_resources(adapter
);
1740 free_netdev(netdev
);
1742 static int __qlcnic_shutdown(struct pci_dev
*pdev
)
1744 struct qlcnic_adapter
*adapter
= pci_get_drvdata(pdev
);
1745 struct net_device
*netdev
= adapter
->netdev
;
1748 netif_device_detach(netdev
);
1750 qlcnic_cancel_fw_work(adapter
);
1752 if (netif_running(netdev
))
1753 qlcnic_down(adapter
, netdev
);
1755 qlcnic_clr_all_drv_state(adapter
, 0);
1757 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
1759 retval
= pci_save_state(pdev
);
1763 if (qlcnic_wol_supported(adapter
)) {
1764 pci_enable_wake(pdev
, PCI_D3cold
, 1);
1765 pci_enable_wake(pdev
, PCI_D3hot
, 1);
1771 static void qlcnic_shutdown(struct pci_dev
*pdev
)
1773 if (__qlcnic_shutdown(pdev
))
1776 pci_disable_device(pdev
);
1781 qlcnic_suspend(struct pci_dev
*pdev
, pm_message_t state
)
1785 retval
= __qlcnic_shutdown(pdev
);
1789 pci_set_power_state(pdev
, pci_choose_state(pdev
, state
));
1794 qlcnic_resume(struct pci_dev
*pdev
)
1796 struct qlcnic_adapter
*adapter
= pci_get_drvdata(pdev
);
1797 struct net_device
*netdev
= adapter
->netdev
;
1800 err
= pci_enable_device(pdev
);
1804 pci_set_power_state(pdev
, PCI_D0
);
1805 pci_set_master(pdev
);
1806 pci_restore_state(pdev
);
1808 err
= adapter
->nic_ops
->start_firmware(adapter
);
1810 dev_err(&pdev
->dev
, "failed to start firmware\n");
1814 if (netif_running(netdev
)) {
1815 err
= qlcnic_up(adapter
, netdev
);
1819 qlcnic_restore_indev_addr(netdev
, NETDEV_UP
);
1822 netif_device_attach(netdev
);
1823 qlcnic_schedule_work(adapter
, qlcnic_fw_poll_work
, FW_POLL_DELAY
);
1828 static int qlcnic_open(struct net_device
*netdev
)
1830 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
1833 netif_carrier_off(netdev
);
1835 err
= qlcnic_attach(adapter
);
1839 err
= __qlcnic_up(adapter
, netdev
);
1843 netif_start_queue(netdev
);
1848 qlcnic_detach(adapter
);
1853 * qlcnic_close - Disables a network interface entry point
1855 static int qlcnic_close(struct net_device
*netdev
)
1857 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
1859 __qlcnic_down(adapter
, netdev
);
1863 void qlcnic_alloc_lb_filters_mem(struct qlcnic_adapter
*adapter
)
1868 if (adapter
->fhash
.fmax
&& adapter
->fhash
.fhead
)
1871 spin_lock_init(&adapter
->mac_learn_lock
);
1873 head
= kcalloc(QLCNIC_LB_MAX_FILTERS
, sizeof(struct hlist_head
),
1878 adapter
->fhash
.fmax
= QLCNIC_LB_MAX_FILTERS
;
1879 adapter
->fhash
.fhead
= head
;
1881 for (i
= 0; i
< adapter
->fhash
.fmax
; i
++)
1882 INIT_HLIST_HEAD(&adapter
->fhash
.fhead
[i
]);
1885 static void qlcnic_free_lb_filters_mem(struct qlcnic_adapter
*adapter
)
1887 if (adapter
->fhash
.fmax
&& adapter
->fhash
.fhead
)
1888 kfree(adapter
->fhash
.fhead
);
1890 adapter
->fhash
.fhead
= NULL
;
1891 adapter
->fhash
.fmax
= 0;
1894 static void qlcnic_change_filter(struct qlcnic_adapter
*adapter
,
1895 u64 uaddr
, __le16 vlan_id
, struct qlcnic_host_tx_ring
*tx_ring
)
1897 struct cmd_desc_type0
*hwdesc
;
1898 struct qlcnic_nic_req
*req
;
1899 struct qlcnic_mac_req
*mac_req
;
1900 struct qlcnic_vlan_req
*vlan_req
;
1904 producer
= tx_ring
->producer
;
1905 hwdesc
= &tx_ring
->desc_head
[tx_ring
->producer
];
1907 req
= (struct qlcnic_nic_req
*)hwdesc
;
1908 memset(req
, 0, sizeof(struct qlcnic_nic_req
));
1909 req
->qhdr
= cpu_to_le64(QLCNIC_REQUEST
<< 23);
1911 word
= QLCNIC_MAC_EVENT
| ((u64
)(adapter
->portnum
) << 16);
1912 req
->req_hdr
= cpu_to_le64(word
);
1914 mac_req
= (struct qlcnic_mac_req
*)&(req
->words
[0]);
1915 mac_req
->op
= vlan_id
? QLCNIC_MAC_VLAN_ADD
: QLCNIC_MAC_ADD
;
1916 memcpy(mac_req
->mac_addr
, &uaddr
, ETH_ALEN
);
1918 vlan_req
= (struct qlcnic_vlan_req
*)&req
->words
[1];
1919 vlan_req
->vlan_id
= vlan_id
;
1921 tx_ring
->producer
= get_next_index(producer
, tx_ring
->num_desc
);
1925 #define QLCNIC_MAC_HASH(MAC)\
1926 ((((MAC) & 0x70000) >> 0x10) | (((MAC) & 0x70000000000ULL) >> 0x25))
1929 qlcnic_send_filter(struct qlcnic_adapter
*adapter
,
1930 struct qlcnic_host_tx_ring
*tx_ring
,
1931 struct cmd_desc_type0
*first_desc
,
1932 struct sk_buff
*skb
)
1934 struct ethhdr
*phdr
= (struct ethhdr
*)(skb
->data
);
1935 struct qlcnic_filter
*fil
, *tmp_fil
;
1936 struct hlist_node
*tmp_hnode
, *n
;
1937 struct hlist_head
*head
;
1942 if (!compare_ether_addr(phdr
->h_source
, adapter
->mac_addr
))
1945 if (adapter
->fhash
.fnum
>= adapter
->fhash
.fmax
)
1948 /* Only NPAR capable devices support vlan based learning*/
1949 if (adapter
->flags
& QLCNIC_ESWITCH_ENABLED
)
1950 vlan_id
= first_desc
->vlan_TCI
;
1951 memcpy(&src_addr
, phdr
->h_source
, ETH_ALEN
);
1952 hindex
= QLCNIC_MAC_HASH(src_addr
) & (QLCNIC_LB_MAX_FILTERS
- 1);
1953 head
= &(adapter
->fhash
.fhead
[hindex
]);
1955 hlist_for_each_entry_safe(tmp_fil
, tmp_hnode
, n
, head
, fnode
) {
1956 if (!memcmp(tmp_fil
->faddr
, &src_addr
, ETH_ALEN
) &&
1957 tmp_fil
->vlan_id
== vlan_id
) {
1960 (QLCNIC_READD_AGE
* HZ
+ tmp_fil
->ftime
))
1961 qlcnic_change_filter(adapter
, src_addr
, vlan_id
,
1963 tmp_fil
->ftime
= jiffies
;
1968 fil
= kzalloc(sizeof(struct qlcnic_filter
), GFP_ATOMIC
);
1972 qlcnic_change_filter(adapter
, src_addr
, vlan_id
, tx_ring
);
1974 fil
->ftime
= jiffies
;
1975 fil
->vlan_id
= vlan_id
;
1976 memcpy(fil
->faddr
, &src_addr
, ETH_ALEN
);
1977 spin_lock(&adapter
->mac_learn_lock
);
1978 hlist_add_head(&(fil
->fnode
), head
);
1979 adapter
->fhash
.fnum
++;
1980 spin_unlock(&adapter
->mac_learn_lock
);
1984 qlcnic_tx_pkt(struct qlcnic_adapter
*adapter
,
1985 struct cmd_desc_type0
*first_desc
,
1986 struct sk_buff
*skb
)
1988 u8 opcode
= 0, hdr_len
= 0;
1989 u16 flags
= 0, vlan_tci
= 0;
1990 int copied
, offset
, copy_len
;
1991 struct cmd_desc_type0
*hwdesc
;
1992 struct vlan_ethhdr
*vh
;
1993 struct qlcnic_host_tx_ring
*tx_ring
= adapter
->tx_ring
;
1994 u16 protocol
= ntohs(skb
->protocol
);
1995 u32 producer
= tx_ring
->producer
;
1997 if (protocol
== ETH_P_8021Q
) {
1998 vh
= (struct vlan_ethhdr
*)skb
->data
;
1999 flags
= FLAGS_VLAN_TAGGED
;
2000 vlan_tci
= vh
->h_vlan_TCI
;
2001 } else if (vlan_tx_tag_present(skb
)) {
2002 flags
= FLAGS_VLAN_OOB
;
2003 vlan_tci
= vlan_tx_tag_get(skb
);
2005 if (unlikely(adapter
->pvid
)) {
2006 if (vlan_tci
&& !(adapter
->flags
& QLCNIC_TAGGING_ENABLED
))
2008 if (vlan_tci
&& (adapter
->flags
& QLCNIC_TAGGING_ENABLED
))
2011 flags
= FLAGS_VLAN_OOB
;
2012 vlan_tci
= adapter
->pvid
;
2015 qlcnic_set_tx_vlan_tci(first_desc
, vlan_tci
);
2016 qlcnic_set_tx_flags_opcode(first_desc
, flags
, opcode
);
2018 if (*(skb
->data
) & BIT_0
) {
2020 memcpy(&first_desc
->eth_addr
, skb
->data
, ETH_ALEN
);
2022 opcode
= TX_ETHER_PKT
;
2023 if ((adapter
->netdev
->features
& (NETIF_F_TSO
| NETIF_F_TSO6
)) &&
2024 skb_shinfo(skb
)->gso_size
> 0) {
2026 hdr_len
= skb_transport_offset(skb
) + tcp_hdrlen(skb
);
2028 first_desc
->mss
= cpu_to_le16(skb_shinfo(skb
)->gso_size
);
2029 first_desc
->total_hdr_length
= hdr_len
;
2031 opcode
= (protocol
== ETH_P_IPV6
) ? TX_TCP_LSO6
: TX_TCP_LSO
;
2033 /* For LSO, we need to copy the MAC/IP/TCP headers into
2034 * the descriptor ring */
2038 if (flags
& FLAGS_VLAN_OOB
) {
2039 first_desc
->total_hdr_length
+= VLAN_HLEN
;
2040 first_desc
->tcp_hdr_offset
= VLAN_HLEN
;
2041 first_desc
->ip_hdr_offset
= VLAN_HLEN
;
2042 /* Only in case of TSO on vlan device */
2043 flags
|= FLAGS_VLAN_TAGGED
;
2045 /* Create a TSO vlan header template for firmware */
2047 hwdesc
= &tx_ring
->desc_head
[producer
];
2048 tx_ring
->cmd_buf_arr
[producer
].skb
= NULL
;
2050 copy_len
= min((int)sizeof(struct cmd_desc_type0
) -
2051 offset
, hdr_len
+ VLAN_HLEN
);
2053 vh
= (struct vlan_ethhdr
*)((char *) hwdesc
+ 2);
2054 skb_copy_from_linear_data(skb
, vh
, 12);
2055 vh
->h_vlan_proto
= htons(ETH_P_8021Q
);
2056 vh
->h_vlan_TCI
= htons(vlan_tci
);
2058 skb_copy_from_linear_data_offset(skb
, 12,
2059 (char *)vh
+ 16, copy_len
- 16);
2061 copied
= copy_len
- VLAN_HLEN
;
2064 producer
= get_next_index(producer
, tx_ring
->num_desc
);
2067 while (copied
< hdr_len
) {
2069 copy_len
= min((int)sizeof(struct cmd_desc_type0
) -
2070 offset
, (hdr_len
- copied
));
2072 hwdesc
= &tx_ring
->desc_head
[producer
];
2073 tx_ring
->cmd_buf_arr
[producer
].skb
= NULL
;
2075 skb_copy_from_linear_data_offset(skb
, copied
,
2076 (char *) hwdesc
+ offset
, copy_len
);
2081 producer
= get_next_index(producer
, tx_ring
->num_desc
);
2084 tx_ring
->producer
= producer
;
2086 adapter
->stats
.lso_frames
++;
2088 } else if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
2091 if (protocol
== ETH_P_IP
) {
2092 l4proto
= ip_hdr(skb
)->protocol
;
2094 if (l4proto
== IPPROTO_TCP
)
2095 opcode
= TX_TCP_PKT
;
2096 else if (l4proto
== IPPROTO_UDP
)
2097 opcode
= TX_UDP_PKT
;
2098 } else if (protocol
== ETH_P_IPV6
) {
2099 l4proto
= ipv6_hdr(skb
)->nexthdr
;
2101 if (l4proto
== IPPROTO_TCP
)
2102 opcode
= TX_TCPV6_PKT
;
2103 else if (l4proto
== IPPROTO_UDP
)
2104 opcode
= TX_UDPV6_PKT
;
2107 first_desc
->tcp_hdr_offset
+= skb_transport_offset(skb
);
2108 first_desc
->ip_hdr_offset
+= skb_network_offset(skb
);
2109 qlcnic_set_tx_flags_opcode(first_desc
, flags
, opcode
);
2115 qlcnic_map_tx_skb(struct pci_dev
*pdev
,
2116 struct sk_buff
*skb
, struct qlcnic_cmd_buffer
*pbuf
)
2118 struct qlcnic_skb_frag
*nf
;
2119 struct skb_frag_struct
*frag
;
2123 nr_frags
= skb_shinfo(skb
)->nr_frags
;
2124 nf
= &pbuf
->frag_array
[0];
2126 map
= pci_map_single(pdev
, skb
->data
,
2127 skb_headlen(skb
), PCI_DMA_TODEVICE
);
2128 if (pci_dma_mapping_error(pdev
, map
))
2132 nf
->length
= skb_headlen(skb
);
2134 for (i
= 0; i
< nr_frags
; i
++) {
2135 frag
= &skb_shinfo(skb
)->frags
[i
];
2136 nf
= &pbuf
->frag_array
[i
+1];
2138 map
= pci_map_page(pdev
, frag
->page
, frag
->page_offset
,
2139 frag
->size
, PCI_DMA_TODEVICE
);
2140 if (pci_dma_mapping_error(pdev
, map
))
2144 nf
->length
= frag
->size
;
2151 nf
= &pbuf
->frag_array
[i
+1];
2152 pci_unmap_page(pdev
, nf
->dma
, nf
->length
, PCI_DMA_TODEVICE
);
2155 nf
= &pbuf
->frag_array
[0];
2156 pci_unmap_single(pdev
, nf
->dma
, skb_headlen(skb
), PCI_DMA_TODEVICE
);
2163 qlcnic_unmap_buffers(struct pci_dev
*pdev
, struct sk_buff
*skb
,
2164 struct qlcnic_cmd_buffer
*pbuf
)
2166 struct qlcnic_skb_frag
*nf
= &pbuf
->frag_array
[0];
2167 int nr_frags
= skb_shinfo(skb
)->nr_frags
;
2170 for (i
= 0; i
< nr_frags
; i
++) {
2171 nf
= &pbuf
->frag_array
[i
+1];
2172 pci_unmap_page(pdev
, nf
->dma
, nf
->length
, PCI_DMA_TODEVICE
);
2175 nf
= &pbuf
->frag_array
[0];
2176 pci_unmap_single(pdev
, nf
->dma
, skb_headlen(skb
), PCI_DMA_TODEVICE
);
2181 qlcnic_clear_cmddesc(u64
*desc
)
2189 qlcnic_xmit_frame(struct sk_buff
*skb
, struct net_device
*netdev
)
2191 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
2192 struct qlcnic_host_tx_ring
*tx_ring
= adapter
->tx_ring
;
2193 struct qlcnic_cmd_buffer
*pbuf
;
2194 struct qlcnic_skb_frag
*buffrag
;
2195 struct cmd_desc_type0
*hwdesc
, *first_desc
;
2196 struct pci_dev
*pdev
;
2197 struct ethhdr
*phdr
;
2203 u32 num_txd
= tx_ring
->num_desc
;
2205 if (!test_bit(__QLCNIC_DEV_UP
, &adapter
->state
)) {
2206 netif_stop_queue(netdev
);
2207 return NETDEV_TX_BUSY
;
2210 if (adapter
->flags
& QLCNIC_MACSPOOF
) {
2211 phdr
= (struct ethhdr
*)skb
->data
;
2212 if (compare_ether_addr(phdr
->h_source
,
2217 frag_count
= skb_shinfo(skb
)->nr_frags
+ 1;
2218 /* 14 frags supported for normal packet and
2219 * 32 frags supported for TSO packet
2221 if (!skb_is_gso(skb
) && frag_count
> QLCNIC_MAX_FRAGS_PER_TX
) {
2223 for (i
= 0; i
< (frag_count
- QLCNIC_MAX_FRAGS_PER_TX
); i
++)
2224 delta
+= skb_shinfo(skb
)->frags
[i
].size
;
2226 if (!__pskb_pull_tail(skb
, delta
))
2229 frag_count
= 1 + skb_shinfo(skb
)->nr_frags
;
2232 if (unlikely(qlcnic_tx_avail(tx_ring
) <= TX_STOP_THRESH
)) {
2233 netif_stop_queue(netdev
);
2234 if (qlcnic_tx_avail(tx_ring
) > TX_STOP_THRESH
)
2235 netif_start_queue(netdev
);
2237 adapter
->stats
.xmit_off
++;
2238 return NETDEV_TX_BUSY
;
2242 producer
= tx_ring
->producer
;
2243 pbuf
= &tx_ring
->cmd_buf_arr
[producer
];
2245 pdev
= adapter
->pdev
;
2247 first_desc
= hwdesc
= &tx_ring
->desc_head
[producer
];
2248 qlcnic_clear_cmddesc((u64
*)hwdesc
);
2250 if (qlcnic_map_tx_skb(pdev
, skb
, pbuf
)) {
2251 adapter
->stats
.tx_dma_map_error
++;
2256 pbuf
->frag_count
= frag_count
;
2258 qlcnic_set_tx_frags_len(first_desc
, frag_count
, skb
->len
);
2259 qlcnic_set_tx_port(first_desc
, adapter
->portnum
);
2261 for (i
= 0; i
< frag_count
; i
++) {
2265 if ((k
== 0) && (i
> 0)) {
2266 /* move to next desc.*/
2267 producer
= get_next_index(producer
, num_txd
);
2268 hwdesc
= &tx_ring
->desc_head
[producer
];
2269 qlcnic_clear_cmddesc((u64
*)hwdesc
);
2270 tx_ring
->cmd_buf_arr
[producer
].skb
= NULL
;
2273 buffrag
= &pbuf
->frag_array
[i
];
2275 hwdesc
->buffer_length
[k
] = cpu_to_le16(buffrag
->length
);
2278 hwdesc
->addr_buffer1
= cpu_to_le64(buffrag
->dma
);
2281 hwdesc
->addr_buffer2
= cpu_to_le64(buffrag
->dma
);
2284 hwdesc
->addr_buffer3
= cpu_to_le64(buffrag
->dma
);
2287 hwdesc
->addr_buffer4
= cpu_to_le64(buffrag
->dma
);
2292 tx_ring
->producer
= get_next_index(producer
, num_txd
);
2295 if (unlikely(qlcnic_tx_pkt(adapter
, first_desc
, skb
)))
2298 if (adapter
->mac_learn
)
2299 qlcnic_send_filter(adapter
, tx_ring
, first_desc
, skb
);
2301 adapter
->stats
.txbytes
+= skb
->len
;
2302 adapter
->stats
.xmitcalled
++;
2304 qlcnic_update_cmd_producer(adapter
, tx_ring
);
2306 return NETDEV_TX_OK
;
2309 qlcnic_unmap_buffers(pdev
, skb
, pbuf
);
2311 adapter
->stats
.txdropped
++;
2312 dev_kfree_skb_any(skb
);
2313 return NETDEV_TX_OK
;
2316 static int qlcnic_check_temp(struct qlcnic_adapter
*adapter
)
2318 struct net_device
*netdev
= adapter
->netdev
;
2319 u32 temp
, temp_state
, temp_val
;
2322 temp
= QLCRD32(adapter
, CRB_TEMP_STATE
);
2324 temp_state
= qlcnic_get_temp_state(temp
);
2325 temp_val
= qlcnic_get_temp_val(temp
);
2327 if (temp_state
== QLCNIC_TEMP_PANIC
) {
2328 dev_err(&netdev
->dev
,
2329 "Device temperature %d degrees C exceeds"
2330 " maximum allowed. Hardware has been shut down.\n",
2333 } else if (temp_state
== QLCNIC_TEMP_WARN
) {
2334 if (adapter
->temp
== QLCNIC_TEMP_NORMAL
) {
2335 dev_err(&netdev
->dev
,
2336 "Device temperature %d degrees C "
2337 "exceeds operating range."
2338 " Immediate action needed.\n",
2342 if (adapter
->temp
== QLCNIC_TEMP_WARN
) {
2343 dev_info(&netdev
->dev
,
2344 "Device temperature is now %d degrees C"
2345 " in normal range.\n", temp_val
);
2348 adapter
->temp
= temp_state
;
2352 void qlcnic_advert_link_change(struct qlcnic_adapter
*adapter
, int linkup
)
2354 struct net_device
*netdev
= adapter
->netdev
;
2356 if (adapter
->ahw
->linkup
&& !linkup
) {
2357 netdev_info(netdev
, "NIC Link is down\n");
2358 adapter
->ahw
->linkup
= 0;
2359 if (netif_running(netdev
)) {
2360 netif_carrier_off(netdev
);
2361 netif_stop_queue(netdev
);
2363 } else if (!adapter
->ahw
->linkup
&& linkup
) {
2364 netdev_info(netdev
, "NIC Link is up\n");
2365 adapter
->ahw
->linkup
= 1;
2366 if (netif_running(netdev
)) {
2367 netif_carrier_on(netdev
);
2368 netif_wake_queue(netdev
);
2373 static void qlcnic_tx_timeout(struct net_device
*netdev
)
2375 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
2377 if (test_bit(__QLCNIC_RESETTING
, &adapter
->state
))
2380 dev_err(&netdev
->dev
, "transmit timeout, resetting.\n");
2382 if (++adapter
->tx_timeo_cnt
>= QLCNIC_MAX_TX_TIMEOUTS
)
2383 adapter
->need_fw_reset
= 1;
2385 adapter
->reset_context
= 1;
2388 static struct net_device_stats
*qlcnic_get_stats(struct net_device
*netdev
)
2390 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
2391 struct net_device_stats
*stats
= &netdev
->stats
;
2393 stats
->rx_packets
= adapter
->stats
.rx_pkts
+ adapter
->stats
.lro_pkts
;
2394 stats
->tx_packets
= adapter
->stats
.xmitfinished
;
2395 stats
->rx_bytes
= adapter
->stats
.rxbytes
+ adapter
->stats
.lrobytes
;
2396 stats
->tx_bytes
= adapter
->stats
.txbytes
;
2397 stats
->rx_dropped
= adapter
->stats
.rxdropped
;
2398 stats
->tx_dropped
= adapter
->stats
.txdropped
;
2403 static irqreturn_t
qlcnic_clear_legacy_intr(struct qlcnic_adapter
*adapter
)
2407 status
= readl(adapter
->isr_int_vec
);
2409 if (!(status
& adapter
->int_vec_bit
))
2412 /* check interrupt state machine, to be sure */
2413 status
= readl(adapter
->crb_int_state_reg
);
2414 if (!ISR_LEGACY_INT_TRIGGERED(status
))
2417 writel(0xffffffff, adapter
->tgt_status_reg
);
2418 /* read twice to ensure write is flushed */
2419 readl(adapter
->isr_int_vec
);
2420 readl(adapter
->isr_int_vec
);
2425 static irqreturn_t
qlcnic_tmp_intr(int irq
, void *data
)
2427 struct qlcnic_host_sds_ring
*sds_ring
= data
;
2428 struct qlcnic_adapter
*adapter
= sds_ring
->adapter
;
2430 if (adapter
->flags
& QLCNIC_MSIX_ENABLED
)
2432 else if (adapter
->flags
& QLCNIC_MSI_ENABLED
) {
2433 writel(0xffffffff, adapter
->tgt_status_reg
);
2437 if (qlcnic_clear_legacy_intr(adapter
) == IRQ_NONE
)
2441 adapter
->diag_cnt
++;
2442 qlcnic_enable_int(sds_ring
);
2446 static irqreturn_t
qlcnic_intr(int irq
, void *data
)
2448 struct qlcnic_host_sds_ring
*sds_ring
= data
;
2449 struct qlcnic_adapter
*adapter
= sds_ring
->adapter
;
2451 if (qlcnic_clear_legacy_intr(adapter
) == IRQ_NONE
)
2454 napi_schedule(&sds_ring
->napi
);
2459 static irqreturn_t
qlcnic_msi_intr(int irq
, void *data
)
2461 struct qlcnic_host_sds_ring
*sds_ring
= data
;
2462 struct qlcnic_adapter
*adapter
= sds_ring
->adapter
;
2464 /* clear interrupt */
2465 writel(0xffffffff, adapter
->tgt_status_reg
);
2467 napi_schedule(&sds_ring
->napi
);
2471 static irqreturn_t
qlcnic_msix_intr(int irq
, void *data
)
2473 struct qlcnic_host_sds_ring
*sds_ring
= data
;
2475 napi_schedule(&sds_ring
->napi
);
2479 static int qlcnic_process_cmd_ring(struct qlcnic_adapter
*adapter
)
2481 u32 sw_consumer
, hw_consumer
;
2483 struct qlcnic_cmd_buffer
*buffer
;
2484 struct pci_dev
*pdev
= adapter
->pdev
;
2485 struct net_device
*netdev
= adapter
->netdev
;
2486 struct qlcnic_skb_frag
*frag
;
2488 struct qlcnic_host_tx_ring
*tx_ring
= adapter
->tx_ring
;
2490 if (!spin_trylock(&adapter
->tx_clean_lock
))
2493 sw_consumer
= tx_ring
->sw_consumer
;
2494 hw_consumer
= le32_to_cpu(*(tx_ring
->hw_consumer
));
2496 while (sw_consumer
!= hw_consumer
) {
2497 buffer
= &tx_ring
->cmd_buf_arr
[sw_consumer
];
2499 frag
= &buffer
->frag_array
[0];
2500 pci_unmap_single(pdev
, frag
->dma
, frag
->length
,
2503 for (i
= 1; i
< buffer
->frag_count
; i
++) {
2505 pci_unmap_page(pdev
, frag
->dma
, frag
->length
,
2510 adapter
->stats
.xmitfinished
++;
2511 dev_kfree_skb_any(buffer
->skb
);
2515 sw_consumer
= get_next_index(sw_consumer
, tx_ring
->num_desc
);
2516 if (++count
>= MAX_STATUS_HANDLE
)
2520 if (count
&& netif_running(netdev
)) {
2521 tx_ring
->sw_consumer
= sw_consumer
;
2525 if (netif_queue_stopped(netdev
) && netif_carrier_ok(netdev
)) {
2526 if (qlcnic_tx_avail(tx_ring
) > TX_STOP_THRESH
) {
2527 netif_wake_queue(netdev
);
2528 adapter
->stats
.xmit_on
++;
2531 adapter
->tx_timeo_cnt
= 0;
2534 * If everything is freed up to consumer then check if the ring is full
2535 * If the ring is full then check if more needs to be freed and
2536 * schedule the call back again.
2538 * This happens when there are 2 CPUs. One could be freeing and the
2539 * other filling it. If the ring is full when we get out of here and
2540 * the card has already interrupted the host then the host can miss the
2543 * There is still a possible race condition and the host could miss an
2544 * interrupt. The card has to take care of this.
2546 hw_consumer
= le32_to_cpu(*(tx_ring
->hw_consumer
));
2547 done
= (sw_consumer
== hw_consumer
);
2548 spin_unlock(&adapter
->tx_clean_lock
);
2553 static int qlcnic_poll(struct napi_struct
*napi
, int budget
)
2555 struct qlcnic_host_sds_ring
*sds_ring
=
2556 container_of(napi
, struct qlcnic_host_sds_ring
, napi
);
2558 struct qlcnic_adapter
*adapter
= sds_ring
->adapter
;
2563 tx_complete
= qlcnic_process_cmd_ring(adapter
);
2565 work_done
= qlcnic_process_rcv_ring(sds_ring
, budget
);
2567 if ((work_done
< budget
) && tx_complete
) {
2568 napi_complete(&sds_ring
->napi
);
2569 if (test_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
2570 qlcnic_enable_int(sds_ring
);
2576 static int qlcnic_rx_poll(struct napi_struct
*napi
, int budget
)
2578 struct qlcnic_host_sds_ring
*sds_ring
=
2579 container_of(napi
, struct qlcnic_host_sds_ring
, napi
);
2581 struct qlcnic_adapter
*adapter
= sds_ring
->adapter
;
2584 work_done
= qlcnic_process_rcv_ring(sds_ring
, budget
);
2586 if (work_done
< budget
) {
2587 napi_complete(&sds_ring
->napi
);
2588 if (test_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
2589 qlcnic_enable_int(sds_ring
);
2595 #ifdef CONFIG_NET_POLL_CONTROLLER
2596 static void qlcnic_poll_controller(struct net_device
*netdev
)
2599 struct qlcnic_host_sds_ring
*sds_ring
;
2600 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
2601 struct qlcnic_recv_context
*recv_ctx
= adapter
->recv_ctx
;
2603 disable_irq(adapter
->irq
);
2604 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
2605 sds_ring
= &recv_ctx
->sds_rings
[ring
];
2606 qlcnic_intr(adapter
->irq
, sds_ring
);
2608 enable_irq(adapter
->irq
);
2613 qlcnic_idc_debug_info(struct qlcnic_adapter
*adapter
, u8 encoding
)
2617 val
= adapter
->portnum
& 0xf;
2618 val
|= encoding
<< 7;
2619 val
|= (jiffies
- adapter
->dev_rst_time
) << 8;
2621 QLCWR32(adapter
, QLCNIC_CRB_DRV_SCRATCH
, val
);
2622 adapter
->dev_rst_time
= jiffies
;
2626 qlcnic_set_drv_state(struct qlcnic_adapter
*adapter
, u8 state
)
2630 WARN_ON(state
!= QLCNIC_DEV_NEED_RESET
&&
2631 state
!= QLCNIC_DEV_NEED_QUISCENT
);
2633 if (qlcnic_api_lock(adapter
))
2636 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_STATE
);
2638 if (state
== QLCNIC_DEV_NEED_RESET
)
2639 QLC_DEV_SET_RST_RDY(val
, adapter
->portnum
);
2640 else if (state
== QLCNIC_DEV_NEED_QUISCENT
)
2641 QLC_DEV_SET_QSCNT_RDY(val
, adapter
->portnum
);
2643 QLCWR32(adapter
, QLCNIC_CRB_DRV_STATE
, val
);
2645 qlcnic_api_unlock(adapter
);
2651 qlcnic_clr_drv_state(struct qlcnic_adapter
*adapter
)
2655 if (qlcnic_api_lock(adapter
))
2658 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_STATE
);
2659 QLC_DEV_CLR_RST_QSCNT(val
, adapter
->portnum
);
2660 QLCWR32(adapter
, QLCNIC_CRB_DRV_STATE
, val
);
2662 qlcnic_api_unlock(adapter
);
2668 qlcnic_clr_all_drv_state(struct qlcnic_adapter
*adapter
, u8 failed
)
2672 if (qlcnic_api_lock(adapter
))
2675 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_ACTIVE
);
2676 QLC_DEV_CLR_REF_CNT(val
, adapter
->portnum
);
2677 QLCWR32(adapter
, QLCNIC_CRB_DRV_ACTIVE
, val
);
2680 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
, QLCNIC_DEV_FAILED
);
2681 dev_info(&adapter
->pdev
->dev
,
2682 "Device state set to Failed. Please Reboot\n");
2683 } else if (!(val
& 0x11111111))
2684 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
, QLCNIC_DEV_COLD
);
2686 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_STATE
);
2687 QLC_DEV_CLR_RST_QSCNT(val
, adapter
->portnum
);
2688 QLCWR32(adapter
, QLCNIC_CRB_DRV_STATE
, val
);
2690 qlcnic_api_unlock(adapter
);
2692 adapter
->fw_fail_cnt
= 0;
2693 adapter
->flags
&= ~QLCNIC_FW_HANG
;
2694 clear_bit(__QLCNIC_START_FW
, &adapter
->state
);
2695 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
2698 /* Grab api lock, before checking state */
2700 qlcnic_check_drv_state(struct qlcnic_adapter
*adapter
)
2702 int act
, state
, active_mask
;
2704 state
= QLCRD32(adapter
, QLCNIC_CRB_DRV_STATE
);
2705 act
= QLCRD32(adapter
, QLCNIC_CRB_DRV_ACTIVE
);
2707 if (adapter
->flags
& QLCNIC_FW_RESET_OWNER
) {
2708 active_mask
= (~(1 << (adapter
->ahw
->pci_func
* 4)));
2709 act
= act
& active_mask
;
2712 if (((state
& 0x11111111) == (act
& 0x11111111)) ||
2713 ((act
& 0x11111111) == ((state
>> 1) & 0x11111111)))
2719 static int qlcnic_check_idc_ver(struct qlcnic_adapter
*adapter
)
2721 u32 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_IDC_VER
);
2723 if (val
!= QLCNIC_DRV_IDC_VER
) {
2724 dev_warn(&adapter
->pdev
->dev
, "IDC Version mismatch, driver's"
2725 " idc ver = %x; reqd = %x\n", QLCNIC_DRV_IDC_VER
, val
);
2732 qlcnic_can_start_firmware(struct qlcnic_adapter
*adapter
)
2734 u32 val
, prev_state
;
2735 u8 dev_init_timeo
= adapter
->dev_init_timeo
;
2736 u8 portnum
= adapter
->portnum
;
2739 if (test_and_clear_bit(__QLCNIC_START_FW
, &adapter
->state
))
2742 if (qlcnic_api_lock(adapter
))
2745 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_ACTIVE
);
2746 if (!(val
& (1 << (portnum
* 4)))) {
2747 QLC_DEV_SET_REF_CNT(val
, portnum
);
2748 QLCWR32(adapter
, QLCNIC_CRB_DRV_ACTIVE
, val
);
2751 prev_state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
);
2752 QLCDB(adapter
, HW
, "Device state = %u\n", prev_state
);
2754 switch (prev_state
) {
2755 case QLCNIC_DEV_COLD
:
2756 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
, QLCNIC_DEV_INITIALIZING
);
2757 QLCWR32(adapter
, QLCNIC_CRB_DRV_IDC_VER
, QLCNIC_DRV_IDC_VER
);
2758 qlcnic_idc_debug_info(adapter
, 0);
2759 qlcnic_api_unlock(adapter
);
2762 case QLCNIC_DEV_READY
:
2763 ret
= qlcnic_check_idc_ver(adapter
);
2764 qlcnic_api_unlock(adapter
);
2767 case QLCNIC_DEV_NEED_RESET
:
2768 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_STATE
);
2769 QLC_DEV_SET_RST_RDY(val
, portnum
);
2770 QLCWR32(adapter
, QLCNIC_CRB_DRV_STATE
, val
);
2773 case QLCNIC_DEV_NEED_QUISCENT
:
2774 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_STATE
);
2775 QLC_DEV_SET_QSCNT_RDY(val
, portnum
);
2776 QLCWR32(adapter
, QLCNIC_CRB_DRV_STATE
, val
);
2779 case QLCNIC_DEV_FAILED
:
2780 dev_err(&adapter
->pdev
->dev
, "Device in failed state.\n");
2781 qlcnic_api_unlock(adapter
);
2784 case QLCNIC_DEV_INITIALIZING
:
2785 case QLCNIC_DEV_QUISCENT
:
2789 qlcnic_api_unlock(adapter
);
2793 prev_state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
);
2795 if (prev_state
== QLCNIC_DEV_QUISCENT
)
2797 } while ((prev_state
!= QLCNIC_DEV_READY
) && --dev_init_timeo
);
2799 if (!dev_init_timeo
) {
2800 dev_err(&adapter
->pdev
->dev
,
2801 "Waiting for device to initialize timeout\n");
2805 if (qlcnic_api_lock(adapter
))
2808 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_STATE
);
2809 QLC_DEV_CLR_RST_QSCNT(val
, portnum
);
2810 QLCWR32(adapter
, QLCNIC_CRB_DRV_STATE
, val
);
2812 ret
= qlcnic_check_idc_ver(adapter
);
2813 qlcnic_api_unlock(adapter
);
2819 qlcnic_fwinit_work(struct work_struct
*work
)
2821 struct qlcnic_adapter
*adapter
= container_of(work
,
2822 struct qlcnic_adapter
, fw_work
.work
);
2823 u32 dev_state
= 0xf;
2826 if (qlcnic_api_lock(adapter
))
2829 dev_state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
);
2830 if (dev_state
== QLCNIC_DEV_QUISCENT
||
2831 dev_state
== QLCNIC_DEV_NEED_QUISCENT
) {
2832 qlcnic_api_unlock(adapter
);
2833 qlcnic_schedule_work(adapter
, qlcnic_fwinit_work
,
2838 if (adapter
->op_mode
== QLCNIC_NON_PRIV_FUNC
) {
2839 qlcnic_api_unlock(adapter
);
2843 if (adapter
->fw_wait_cnt
++ > adapter
->reset_ack_timeo
) {
2844 dev_err(&adapter
->pdev
->dev
, "Reset:Failed to get ack %d sec\n",
2845 adapter
->reset_ack_timeo
);
2846 goto skip_ack_check
;
2849 if (!qlcnic_check_drv_state(adapter
)) {
2851 dev_state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
);
2853 if (dev_state
== QLCNIC_DEV_NEED_RESET
) {
2854 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
,
2855 QLCNIC_DEV_INITIALIZING
);
2856 set_bit(__QLCNIC_START_FW
, &adapter
->state
);
2857 QLCDB(adapter
, DRV
, "Restarting fw\n");
2858 qlcnic_idc_debug_info(adapter
, 0);
2859 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_STATE
);
2860 QLC_DEV_SET_RST_RDY(val
, adapter
->portnum
);
2861 QLCWR32(adapter
, QLCNIC_CRB_DRV_STATE
, val
);
2864 qlcnic_api_unlock(adapter
);
2867 if (adapter
->ahw
->fw_dump
.enable
&&
2868 (adapter
->flags
& QLCNIC_FW_RESET_OWNER
)) {
2869 QLCDB(adapter
, DRV
, "Take FW dump\n");
2870 qlcnic_dump_fw(adapter
);
2871 adapter
->flags
|= QLCNIC_FW_HANG
;
2875 adapter
->flags
&= ~QLCNIC_FW_RESET_OWNER
;
2876 if (!adapter
->nic_ops
->start_firmware(adapter
)) {
2877 qlcnic_schedule_work(adapter
, qlcnic_attach_work
, 0);
2878 adapter
->fw_wait_cnt
= 0;
2884 qlcnic_api_unlock(adapter
);
2887 dev_state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
);
2888 QLCDB(adapter
, HW
, "Func waiting: Device state=%u\n", dev_state
);
2890 switch (dev_state
) {
2891 case QLCNIC_DEV_READY
:
2892 if (!adapter
->nic_ops
->start_firmware(adapter
)) {
2893 qlcnic_schedule_work(adapter
, qlcnic_attach_work
, 0);
2894 adapter
->fw_wait_cnt
= 0;
2897 case QLCNIC_DEV_FAILED
:
2900 qlcnic_schedule_work(adapter
,
2901 qlcnic_fwinit_work
, FW_POLL_DELAY
);
2906 dev_err(&adapter
->pdev
->dev
, "Fwinit work failed state=%u "
2907 "fw_wait_cnt=%u\n", dev_state
, adapter
->fw_wait_cnt
);
2908 netif_device_attach(adapter
->netdev
);
2909 qlcnic_clr_all_drv_state(adapter
, 0);
2913 qlcnic_detach_work(struct work_struct
*work
)
2915 struct qlcnic_adapter
*adapter
= container_of(work
,
2916 struct qlcnic_adapter
, fw_work
.work
);
2917 struct net_device
*netdev
= adapter
->netdev
;
2920 netif_device_detach(netdev
);
2922 /* Dont grab rtnl lock during Quiscent mode */
2923 if (adapter
->dev_state
== QLCNIC_DEV_NEED_QUISCENT
) {
2924 if (netif_running(netdev
))
2925 __qlcnic_down(adapter
, netdev
);
2927 qlcnic_down(adapter
, netdev
);
2929 status
= QLCRD32(adapter
, QLCNIC_PEG_HALT_STATUS1
);
2931 if (status
& QLCNIC_RCODE_FATAL_ERROR
) {
2932 dev_err(&adapter
->pdev
->dev
,
2933 "Detaching the device: peg halt status1=0x%x\n",
2936 if (QLCNIC_FWERROR_CODE(status
) == QLCNIC_FWERROR_FAN_FAILURE
) {
2937 dev_err(&adapter
->pdev
->dev
,
2938 "On board active cooling fan failed. "
2939 "Device has been halted.\n");
2940 dev_err(&adapter
->pdev
->dev
,
2941 "Replace the adapter.\n");
2947 if (adapter
->temp
== QLCNIC_TEMP_PANIC
) {
2948 dev_err(&adapter
->pdev
->dev
, "Detaching the device: temp=%d\n",
2953 /* Dont ack if this instance is the reset owner */
2954 if (!(adapter
->flags
& QLCNIC_FW_RESET_OWNER
)) {
2955 if (qlcnic_set_drv_state(adapter
, adapter
->dev_state
)) {
2956 dev_err(&adapter
->pdev
->dev
,
2957 "Failed to set driver state,"
2958 "detaching the device.\n");
2963 adapter
->fw_wait_cnt
= 0;
2965 qlcnic_schedule_work(adapter
, qlcnic_fwinit_work
, FW_POLL_DELAY
);
2970 netif_device_attach(netdev
);
2971 qlcnic_clr_all_drv_state(adapter
, 1);
2974 /*Transit NPAR state to NON Operational */
2976 qlcnic_set_npar_non_operational(struct qlcnic_adapter
*adapter
)
2980 state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_NPAR_STATE
);
2981 if (state
== QLCNIC_DEV_NPAR_NON_OPER
)
2984 if (qlcnic_api_lock(adapter
))
2986 QLCWR32(adapter
, QLCNIC_CRB_DEV_NPAR_STATE
, QLCNIC_DEV_NPAR_NON_OPER
);
2987 qlcnic_api_unlock(adapter
);
2990 /*Transit to RESET state from READY state only */
2992 qlcnic_dev_request_reset(struct qlcnic_adapter
*adapter
)
2996 adapter
->need_fw_reset
= 1;
2997 if (qlcnic_api_lock(adapter
))
3000 state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
);
3002 if (state
== QLCNIC_DEV_READY
) {
3003 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
, QLCNIC_DEV_NEED_RESET
);
3004 adapter
->flags
|= QLCNIC_FW_RESET_OWNER
;
3005 QLCDB(adapter
, DRV
, "NEED_RESET state set\n");
3006 qlcnic_idc_debug_info(adapter
, 0);
3009 QLCWR32(adapter
, QLCNIC_CRB_DEV_NPAR_STATE
, QLCNIC_DEV_NPAR_NON_OPER
);
3010 qlcnic_api_unlock(adapter
);
3013 /* Transit to NPAR READY state from NPAR NOT READY state */
3015 qlcnic_dev_set_npar_ready(struct qlcnic_adapter
*adapter
)
3017 if (qlcnic_api_lock(adapter
))
3020 QLCWR32(adapter
, QLCNIC_CRB_DEV_NPAR_STATE
, QLCNIC_DEV_NPAR_OPER
);
3021 QLCDB(adapter
, DRV
, "NPAR operational state set\n");
3023 qlcnic_api_unlock(adapter
);
3027 qlcnic_schedule_work(struct qlcnic_adapter
*adapter
,
3028 work_func_t func
, int delay
)
3030 if (test_bit(__QLCNIC_AER
, &adapter
->state
))
3033 INIT_DELAYED_WORK(&adapter
->fw_work
, func
);
3034 queue_delayed_work(qlcnic_wq
, &adapter
->fw_work
,
3035 round_jiffies_relative(delay
));
3039 qlcnic_cancel_fw_work(struct qlcnic_adapter
*adapter
)
3041 while (test_and_set_bit(__QLCNIC_RESETTING
, &adapter
->state
))
3044 cancel_delayed_work_sync(&adapter
->fw_work
);
3048 qlcnic_attach_work(struct work_struct
*work
)
3050 struct qlcnic_adapter
*adapter
= container_of(work
,
3051 struct qlcnic_adapter
, fw_work
.work
);
3052 struct net_device
*netdev
= adapter
->netdev
;
3055 if (adapter
->op_mode
!= QLCNIC_MGMT_FUNC
) {
3056 npar_state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_NPAR_STATE
);
3057 if (adapter
->fw_wait_cnt
++ > QLCNIC_DEV_NPAR_OPER_TIMEO
)
3058 qlcnic_clr_all_drv_state(adapter
, 0);
3059 else if (npar_state
!= QLCNIC_DEV_NPAR_OPER
)
3060 qlcnic_schedule_work(adapter
, qlcnic_attach_work
,
3064 QLCDB(adapter
, DRV
, "Waiting for NPAR state to operational\n");
3068 if (netif_running(netdev
)) {
3069 if (qlcnic_up(adapter
, netdev
))
3072 qlcnic_restore_indev_addr(netdev
, NETDEV_UP
);
3076 netif_device_attach(netdev
);
3077 adapter
->fw_fail_cnt
= 0;
3078 adapter
->flags
&= ~QLCNIC_FW_HANG
;
3079 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
3081 if (!qlcnic_clr_drv_state(adapter
))
3082 qlcnic_schedule_work(adapter
, qlcnic_fw_poll_work
,
3087 qlcnic_check_health(struct qlcnic_adapter
*adapter
)
3089 u32 state
= 0, heartbeat
;
3090 struct net_device
*netdev
= adapter
->netdev
;
3092 if (qlcnic_check_temp(adapter
))
3095 if (adapter
->need_fw_reset
)
3096 qlcnic_dev_request_reset(adapter
);
3098 state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
);
3099 if (state
== QLCNIC_DEV_NEED_RESET
) {
3100 qlcnic_set_npar_non_operational(adapter
);
3101 adapter
->need_fw_reset
= 1;
3102 } else if (state
== QLCNIC_DEV_NEED_QUISCENT
)
3105 heartbeat
= QLCRD32(adapter
, QLCNIC_PEG_ALIVE_COUNTER
);
3106 if (heartbeat
!= adapter
->heartbeat
) {
3107 adapter
->heartbeat
= heartbeat
;
3108 adapter
->fw_fail_cnt
= 0;
3109 if (adapter
->need_fw_reset
)
3112 if (adapter
->reset_context
&& auto_fw_reset
) {
3113 qlcnic_reset_hw_context(adapter
);
3114 adapter
->netdev
->trans_start
= jiffies
;
3120 if (++adapter
->fw_fail_cnt
< FW_FAIL_THRESH
)
3123 adapter
->flags
|= QLCNIC_FW_HANG
;
3125 qlcnic_dev_request_reset(adapter
);
3128 clear_bit(__QLCNIC_FW_ATTACHED
, &adapter
->state
);
3130 dev_info(&netdev
->dev
, "firmware hang detected\n");
3131 dev_info(&adapter
->pdev
->dev
, "Dumping hw/fw registers\n"
3132 "PEG_HALT_STATUS1: 0x%x, PEG_HALT_STATUS2: 0x%x,\n"
3133 "PEG_NET_0_PC: 0x%x, PEG_NET_1_PC: 0x%x,\n"
3134 "PEG_NET_2_PC: 0x%x, PEG_NET_3_PC: 0x%x,\n"
3135 "PEG_NET_4_PC: 0x%x\n",
3136 QLCRD32(adapter
, QLCNIC_PEG_HALT_STATUS1
),
3137 QLCRD32(adapter
, QLCNIC_PEG_HALT_STATUS2
),
3138 QLCRD32(adapter
, QLCNIC_CRB_PEG_NET_0
+ 0x3c),
3139 QLCRD32(adapter
, QLCNIC_CRB_PEG_NET_1
+ 0x3c),
3140 QLCRD32(adapter
, QLCNIC_CRB_PEG_NET_2
+ 0x3c),
3141 QLCRD32(adapter
, QLCNIC_CRB_PEG_NET_3
+ 0x3c),
3142 QLCRD32(adapter
, QLCNIC_CRB_PEG_NET_4
+ 0x3c));
3144 adapter
->dev_state
= (state
== QLCNIC_DEV_NEED_QUISCENT
) ? state
:
3145 QLCNIC_DEV_NEED_RESET
;
3147 if (auto_fw_reset
&&
3148 !test_and_set_bit(__QLCNIC_RESETTING
, &adapter
->state
)) {
3150 qlcnic_schedule_work(adapter
, qlcnic_detach_work
, 0);
3151 QLCDB(adapter
, DRV
, "fw recovery scheduled.\n");
3158 qlcnic_fw_poll_work(struct work_struct
*work
)
3160 struct qlcnic_adapter
*adapter
= container_of(work
,
3161 struct qlcnic_adapter
, fw_work
.work
);
3163 if (test_bit(__QLCNIC_RESETTING
, &adapter
->state
))
3167 if (qlcnic_check_health(adapter
))
3170 if (adapter
->fhash
.fnum
)
3171 qlcnic_prune_lb_filters(adapter
);
3174 qlcnic_schedule_work(adapter
, qlcnic_fw_poll_work
, FW_POLL_DELAY
);
3177 static int qlcnic_is_first_func(struct pci_dev
*pdev
)
3179 struct pci_dev
*oth_pdev
;
3180 int val
= pdev
->devfn
;
3183 oth_pdev
= pci_get_domain_bus_and_slot(pci_domain_nr
3184 (pdev
->bus
), pdev
->bus
->number
,
3185 PCI_DEVFN(PCI_SLOT(pdev
->devfn
), val
));
3189 if (oth_pdev
->current_state
!= PCI_D3cold
) {
3190 pci_dev_put(oth_pdev
);
3193 pci_dev_put(oth_pdev
);
3198 static int qlcnic_attach_func(struct pci_dev
*pdev
)
3200 int err
, first_func
;
3201 struct qlcnic_adapter
*adapter
= pci_get_drvdata(pdev
);
3202 struct net_device
*netdev
= adapter
->netdev
;
3204 pdev
->error_state
= pci_channel_io_normal
;
3206 err
= pci_enable_device(pdev
);
3210 pci_set_power_state(pdev
, PCI_D0
);
3211 pci_set_master(pdev
);
3212 pci_restore_state(pdev
);
3214 first_func
= qlcnic_is_first_func(pdev
);
3216 if (qlcnic_api_lock(adapter
))
3219 if (adapter
->op_mode
!= QLCNIC_NON_PRIV_FUNC
&& first_func
) {
3220 adapter
->need_fw_reset
= 1;
3221 set_bit(__QLCNIC_START_FW
, &adapter
->state
);
3222 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
, QLCNIC_DEV_INITIALIZING
);
3223 QLCDB(adapter
, DRV
, "Restarting fw\n");
3225 qlcnic_api_unlock(adapter
);
3227 err
= adapter
->nic_ops
->start_firmware(adapter
);
3231 qlcnic_clr_drv_state(adapter
);
3232 qlcnic_setup_intr(adapter
);
3234 if (netif_running(netdev
)) {
3235 err
= qlcnic_attach(adapter
);
3237 qlcnic_clr_all_drv_state(adapter
, 1);
3238 clear_bit(__QLCNIC_AER
, &adapter
->state
);
3239 netif_device_attach(netdev
);
3243 err
= qlcnic_up(adapter
, netdev
);
3247 qlcnic_restore_indev_addr(netdev
, NETDEV_UP
);
3250 netif_device_attach(netdev
);
3254 static pci_ers_result_t
qlcnic_io_error_detected(struct pci_dev
*pdev
,
3255 pci_channel_state_t state
)
3257 struct qlcnic_adapter
*adapter
= pci_get_drvdata(pdev
);
3258 struct net_device
*netdev
= adapter
->netdev
;
3260 if (state
== pci_channel_io_perm_failure
)
3261 return PCI_ERS_RESULT_DISCONNECT
;
3263 if (state
== pci_channel_io_normal
)
3264 return PCI_ERS_RESULT_RECOVERED
;
3266 set_bit(__QLCNIC_AER
, &adapter
->state
);
3267 netif_device_detach(netdev
);
3269 cancel_delayed_work_sync(&adapter
->fw_work
);
3271 if (netif_running(netdev
))
3272 qlcnic_down(adapter
, netdev
);
3274 qlcnic_detach(adapter
);
3275 qlcnic_teardown_intr(adapter
);
3277 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
3279 pci_save_state(pdev
);
3280 pci_disable_device(pdev
);
3282 return PCI_ERS_RESULT_NEED_RESET
;
3285 static pci_ers_result_t
qlcnic_io_slot_reset(struct pci_dev
*pdev
)
3287 return qlcnic_attach_func(pdev
) ? PCI_ERS_RESULT_DISCONNECT
:
3288 PCI_ERS_RESULT_RECOVERED
;
3291 static void qlcnic_io_resume(struct pci_dev
*pdev
)
3293 struct qlcnic_adapter
*adapter
= pci_get_drvdata(pdev
);
3295 pci_cleanup_aer_uncorrect_error_status(pdev
);
3297 if (QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
) == QLCNIC_DEV_READY
&&
3298 test_and_clear_bit(__QLCNIC_AER
, &adapter
->state
))
3299 qlcnic_schedule_work(adapter
, qlcnic_fw_poll_work
,
3304 qlcnicvf_start_firmware(struct qlcnic_adapter
*adapter
)
3308 err
= qlcnic_can_start_firmware(adapter
);
3312 err
= qlcnic_check_npar_opertional(adapter
);
3316 err
= qlcnic_initialize_nic(adapter
);
3320 qlcnic_check_options(adapter
);
3322 err
= qlcnic_set_eswitch_port_config(adapter
);
3326 adapter
->need_fw_reset
= 0;
3332 qlcnicvf_config_bridged_mode(struct qlcnic_adapter
*adapter
, u32 enable
)
3338 qlcnicvf_config_led(struct qlcnic_adapter
*adapter
, u32 state
, u32 rate
)
3344 qlcnic_store_bridged_mode(struct device
*dev
,
3345 struct device_attribute
*attr
, const char *buf
, size_t len
)
3347 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3351 if (!(adapter
->capabilities
& QLCNIC_FW_CAPABILITY_BDG
))
3354 if (!test_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
3357 if (strict_strtoul(buf
, 2, &new))
3360 if (!adapter
->nic_ops
->config_bridged_mode(adapter
, !!new))
3368 qlcnic_show_bridged_mode(struct device
*dev
,
3369 struct device_attribute
*attr
, char *buf
)
3371 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3372 int bridged_mode
= 0;
3374 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_BDG
)
3375 bridged_mode
= !!(adapter
->flags
& QLCNIC_BRIDGE_ENABLED
);
3377 return sprintf(buf
, "%d\n", bridged_mode
);
3380 static struct device_attribute dev_attr_bridged_mode
= {
3381 .attr
= {.name
= "bridged_mode", .mode
= (S_IRUGO
| S_IWUSR
)},
3382 .show
= qlcnic_show_bridged_mode
,
3383 .store
= qlcnic_store_bridged_mode
,
3387 qlcnic_store_diag_mode(struct device
*dev
,
3388 struct device_attribute
*attr
, const char *buf
, size_t len
)
3390 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3393 if (strict_strtoul(buf
, 2, &new))
3396 if (!!new != !!(adapter
->flags
& QLCNIC_DIAG_ENABLED
))
3397 adapter
->flags
^= QLCNIC_DIAG_ENABLED
;
3403 qlcnic_show_diag_mode(struct device
*dev
,
3404 struct device_attribute
*attr
, char *buf
)
3406 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3408 return sprintf(buf
, "%d\n",
3409 !!(adapter
->flags
& QLCNIC_DIAG_ENABLED
));
3412 static struct device_attribute dev_attr_diag_mode
= {
3413 .attr
= {.name
= "diag_mode", .mode
= (S_IRUGO
| S_IWUSR
)},
3414 .show
= qlcnic_show_diag_mode
,
3415 .store
= qlcnic_store_diag_mode
,
3418 int qlcnic_validate_max_rss(struct net_device
*netdev
, u8 max_hw
, u8 val
)
3420 if (!use_msi_x
&& !use_msi
) {
3421 netdev_info(netdev
, "no msix or msi support, hence no rss\n");
3425 if ((val
> max_hw
) || (val
< 2) || !is_power_of_2(val
)) {
3426 netdev_info(netdev
, "rss_ring valid range [2 - %x] in "
3427 " powers of 2\n", max_hw
);
3434 int qlcnic_set_max_rss(struct qlcnic_adapter
*adapter
, u8 data
)
3436 struct net_device
*netdev
= adapter
->netdev
;
3439 if (test_and_set_bit(__QLCNIC_RESETTING
, &adapter
->state
))
3442 netif_device_detach(netdev
);
3443 if (netif_running(netdev
))
3444 __qlcnic_down(adapter
, netdev
);
3445 qlcnic_detach(adapter
);
3446 qlcnic_teardown_intr(adapter
);
3448 if (qlcnic_enable_msix(adapter
, data
)) {
3449 netdev_info(netdev
, "failed setting max_rss; rss disabled\n");
3450 qlcnic_enable_msi_legacy(adapter
);
3453 if (netif_running(netdev
)) {
3454 err
= qlcnic_attach(adapter
);
3457 err
= __qlcnic_up(adapter
, netdev
);
3460 qlcnic_restore_indev_addr(netdev
, NETDEV_UP
);
3463 netif_device_attach(netdev
);
3464 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
3469 qlcnic_validate_beacon(struct qlcnic_adapter
*adapter
, u16 beacon
, u8
*state
,
3472 *rate
= LSB(beacon
);
3473 *state
= MSB(beacon
);
3475 QLCDB(adapter
, DRV
, "rate %x state %x\n", *rate
, *state
);
3478 *rate
= __QLCNIC_MAX_LED_RATE
;
3480 } else if (*state
> __QLCNIC_MAX_LED_STATE
)
3483 if ((!*rate
) || (*rate
> __QLCNIC_MAX_LED_RATE
))
3490 qlcnic_store_beacon(struct device
*dev
,
3491 struct device_attribute
*attr
, const char *buf
, size_t len
)
3493 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3494 int max_sds_rings
= adapter
->max_sds_rings
;
3500 if (len
!= sizeof(u16
))
3501 return QL_STATUS_INVALID_PARAM
;
3503 memcpy(&beacon
, buf
, sizeof(u16
));
3504 err
= qlcnic_validate_beacon(adapter
, beacon
, &b_state
, &b_rate
);
3508 if (adapter
->ahw
->beacon_state
== b_state
)
3511 if (!adapter
->ahw
->beacon_state
)
3512 if (test_and_set_bit(__QLCNIC_LED_ENABLE
, &adapter
->state
))
3515 if (!test_bit(__QLCNIC_DEV_UP
, &adapter
->state
)) {
3516 if (test_and_set_bit(__QLCNIC_RESETTING
, &adapter
->state
))
3518 err
= qlcnic_diag_alloc_res(adapter
->netdev
, QLCNIC_LED_TEST
);
3520 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
3521 clear_bit(__QLCNIC_LED_ENABLE
, &adapter
->state
);
3527 err
= qlcnic_config_led(adapter
, b_state
, b_rate
);
3530 adapter
->ahw
->beacon_state
= b_state
;
3535 qlcnic_diag_free_res(adapter
->netdev
, max_sds_rings
);
3536 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
3540 clear_bit(__QLCNIC_LED_ENABLE
, &adapter
->state
);
3546 qlcnic_show_beacon(struct device
*dev
,
3547 struct device_attribute
*attr
, char *buf
)
3549 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3551 return sprintf(buf
, "%d\n", adapter
->ahw
->beacon_state
);
3554 static struct device_attribute dev_attr_beacon
= {
3555 .attr
= {.name
= "beacon", .mode
= (S_IRUGO
| S_IWUSR
)},
3556 .show
= qlcnic_show_beacon
,
3557 .store
= qlcnic_store_beacon
,
3561 qlcnic_sysfs_validate_crb(struct qlcnic_adapter
*adapter
,
3562 loff_t offset
, size_t size
)
3564 size_t crb_size
= 4;
3566 if (!(adapter
->flags
& QLCNIC_DIAG_ENABLED
))
3569 if (offset
< QLCNIC_PCI_CRBSPACE
) {
3570 if (ADDR_IN_RANGE(offset
, QLCNIC_PCI_CAMQM
,
3571 QLCNIC_PCI_CAMQM_END
))
3577 if ((size
!= crb_size
) || (offset
& (crb_size
-1)))
3584 qlcnic_sysfs_read_crb(struct file
*filp
, struct kobject
*kobj
,
3585 struct bin_attribute
*attr
,
3586 char *buf
, loff_t offset
, size_t size
)
3588 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3589 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3594 ret
= qlcnic_sysfs_validate_crb(adapter
, offset
, size
);
3598 if (ADDR_IN_RANGE(offset
, QLCNIC_PCI_CAMQM
, QLCNIC_PCI_CAMQM_END
)) {
3599 qlcnic_pci_camqm_read_2M(adapter
, offset
, &qmdata
);
3600 memcpy(buf
, &qmdata
, size
);
3602 data
= QLCRD32(adapter
, offset
);
3603 memcpy(buf
, &data
, size
);
3609 qlcnic_sysfs_write_crb(struct file
*filp
, struct kobject
*kobj
,
3610 struct bin_attribute
*attr
,
3611 char *buf
, loff_t offset
, size_t size
)
3613 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3614 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3619 ret
= qlcnic_sysfs_validate_crb(adapter
, offset
, size
);
3623 if (ADDR_IN_RANGE(offset
, QLCNIC_PCI_CAMQM
, QLCNIC_PCI_CAMQM_END
)) {
3624 memcpy(&qmdata
, buf
, size
);
3625 qlcnic_pci_camqm_write_2M(adapter
, offset
, qmdata
);
3627 memcpy(&data
, buf
, size
);
3628 QLCWR32(adapter
, offset
, data
);
3634 qlcnic_sysfs_validate_mem(struct qlcnic_adapter
*adapter
,
3635 loff_t offset
, size_t size
)
3637 if (!(adapter
->flags
& QLCNIC_DIAG_ENABLED
))
3640 if ((size
!= 8) || (offset
& 0x7))
3647 qlcnic_sysfs_read_mem(struct file
*filp
, struct kobject
*kobj
,
3648 struct bin_attribute
*attr
,
3649 char *buf
, loff_t offset
, size_t size
)
3651 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3652 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3656 ret
= qlcnic_sysfs_validate_mem(adapter
, offset
, size
);
3660 if (qlcnic_pci_mem_read_2M(adapter
, offset
, &data
))
3663 memcpy(buf
, &data
, size
);
3669 qlcnic_sysfs_write_mem(struct file
*filp
, struct kobject
*kobj
,
3670 struct bin_attribute
*attr
,
3671 char *buf
, loff_t offset
, size_t size
)
3673 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3674 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3678 ret
= qlcnic_sysfs_validate_mem(adapter
, offset
, size
);
3682 memcpy(&data
, buf
, size
);
3684 if (qlcnic_pci_mem_write_2M(adapter
, offset
, data
))
3690 static struct bin_attribute bin_attr_crb
= {
3691 .attr
= {.name
= "crb", .mode
= (S_IRUGO
| S_IWUSR
)},
3693 .read
= qlcnic_sysfs_read_crb
,
3694 .write
= qlcnic_sysfs_write_crb
,
3697 static struct bin_attribute bin_attr_mem
= {
3698 .attr
= {.name
= "mem", .mode
= (S_IRUGO
| S_IWUSR
)},
3700 .read
= qlcnic_sysfs_read_mem
,
3701 .write
= qlcnic_sysfs_write_mem
,
3705 validate_pm_config(struct qlcnic_adapter
*adapter
,
3706 struct qlcnic_pm_func_cfg
*pm_cfg
, int count
)
3709 u8 src_pci_func
, s_esw_id
, d_esw_id
;
3713 for (i
= 0; i
< count
; i
++) {
3714 src_pci_func
= pm_cfg
[i
].pci_func
;
3715 dest_pci_func
= pm_cfg
[i
].dest_npar
;
3716 if (src_pci_func
>= QLCNIC_MAX_PCI_FUNC
3717 || dest_pci_func
>= QLCNIC_MAX_PCI_FUNC
)
3718 return QL_STATUS_INVALID_PARAM
;
3720 if (adapter
->npars
[src_pci_func
].type
!= QLCNIC_TYPE_NIC
)
3721 return QL_STATUS_INVALID_PARAM
;
3723 if (adapter
->npars
[dest_pci_func
].type
!= QLCNIC_TYPE_NIC
)
3724 return QL_STATUS_INVALID_PARAM
;
3726 s_esw_id
= adapter
->npars
[src_pci_func
].phy_port
;
3727 d_esw_id
= adapter
->npars
[dest_pci_func
].phy_port
;
3729 if (s_esw_id
!= d_esw_id
)
3730 return QL_STATUS_INVALID_PARAM
;
3738 qlcnic_sysfs_write_pm_config(struct file
*filp
, struct kobject
*kobj
,
3739 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3741 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3742 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3743 struct qlcnic_pm_func_cfg
*pm_cfg
;
3744 u32 id
, action
, pci_func
;
3745 int count
, rem
, i
, ret
;
3747 count
= size
/ sizeof(struct qlcnic_pm_func_cfg
);
3748 rem
= size
% sizeof(struct qlcnic_pm_func_cfg
);
3750 return QL_STATUS_INVALID_PARAM
;
3752 pm_cfg
= (struct qlcnic_pm_func_cfg
*) buf
;
3754 ret
= validate_pm_config(adapter
, pm_cfg
, count
);
3757 for (i
= 0; i
< count
; i
++) {
3758 pci_func
= pm_cfg
[i
].pci_func
;
3759 action
= !!pm_cfg
[i
].action
;
3760 id
= adapter
->npars
[pci_func
].phy_port
;
3761 ret
= qlcnic_config_port_mirroring(adapter
, id
,
3767 for (i
= 0; i
< count
; i
++) {
3768 pci_func
= pm_cfg
[i
].pci_func
;
3769 id
= adapter
->npars
[pci_func
].phy_port
;
3770 adapter
->npars
[pci_func
].enable_pm
= !!pm_cfg
[i
].action
;
3771 adapter
->npars
[pci_func
].dest_npar
= id
;
3777 qlcnic_sysfs_read_pm_config(struct file
*filp
, struct kobject
*kobj
,
3778 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3780 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3781 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3782 struct qlcnic_pm_func_cfg pm_cfg
[QLCNIC_MAX_PCI_FUNC
];
3785 if (size
!= sizeof(pm_cfg
))
3786 return QL_STATUS_INVALID_PARAM
;
3788 for (i
= 0; i
< QLCNIC_MAX_PCI_FUNC
; i
++) {
3789 if (adapter
->npars
[i
].type
!= QLCNIC_TYPE_NIC
)
3791 pm_cfg
[i
].action
= adapter
->npars
[i
].enable_pm
;
3792 pm_cfg
[i
].dest_npar
= 0;
3793 pm_cfg
[i
].pci_func
= i
;
3795 memcpy(buf
, &pm_cfg
, size
);
3801 validate_esw_config(struct qlcnic_adapter
*adapter
,
3802 struct qlcnic_esw_func_cfg
*esw_cfg
, int count
)
3808 op_mode
= readl(adapter
->ahw
->pci_base0
+ QLCNIC_DRV_OP_MODE
);
3810 for (i
= 0; i
< count
; i
++) {
3811 pci_func
= esw_cfg
[i
].pci_func
;
3812 if (pci_func
>= QLCNIC_MAX_PCI_FUNC
)
3813 return QL_STATUS_INVALID_PARAM
;
3815 if (adapter
->op_mode
== QLCNIC_MGMT_FUNC
)
3816 if (adapter
->npars
[pci_func
].type
!= QLCNIC_TYPE_NIC
)
3817 return QL_STATUS_INVALID_PARAM
;
3819 switch (esw_cfg
[i
].op_mode
) {
3820 case QLCNIC_PORT_DEFAULTS
:
3821 if (QLC_DEV_GET_DRV(op_mode
, pci_func
) !=
3822 QLCNIC_NON_PRIV_FUNC
) {
3823 if (esw_cfg
[i
].mac_anti_spoof
!= 0)
3824 return QL_STATUS_INVALID_PARAM
;
3825 if (esw_cfg
[i
].mac_override
!= 1)
3826 return QL_STATUS_INVALID_PARAM
;
3827 if (esw_cfg
[i
].promisc_mode
!= 1)
3828 return QL_STATUS_INVALID_PARAM
;
3831 case QLCNIC_ADD_VLAN
:
3832 if (!IS_VALID_VLAN(esw_cfg
[i
].vlan_id
))
3833 return QL_STATUS_INVALID_PARAM
;
3834 if (!esw_cfg
[i
].op_type
)
3835 return QL_STATUS_INVALID_PARAM
;
3837 case QLCNIC_DEL_VLAN
:
3838 if (!esw_cfg
[i
].op_type
)
3839 return QL_STATUS_INVALID_PARAM
;
3842 return QL_STATUS_INVALID_PARAM
;
3849 qlcnic_sysfs_write_esw_config(struct file
*file
, struct kobject
*kobj
,
3850 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3852 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3853 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3854 struct qlcnic_esw_func_cfg
*esw_cfg
;
3855 struct qlcnic_npar_info
*npar
;
3856 int count
, rem
, i
, ret
;
3857 u8 pci_func
, op_mode
= 0;
3859 count
= size
/ sizeof(struct qlcnic_esw_func_cfg
);
3860 rem
= size
% sizeof(struct qlcnic_esw_func_cfg
);
3862 return QL_STATUS_INVALID_PARAM
;
3864 esw_cfg
= (struct qlcnic_esw_func_cfg
*) buf
;
3865 ret
= validate_esw_config(adapter
, esw_cfg
, count
);
3869 for (i
= 0; i
< count
; i
++) {
3870 if (adapter
->op_mode
== QLCNIC_MGMT_FUNC
)
3871 if (qlcnic_config_switch_port(adapter
, &esw_cfg
[i
]))
3872 return QL_STATUS_INVALID_PARAM
;
3874 if (adapter
->ahw
->pci_func
!= esw_cfg
[i
].pci_func
)
3877 op_mode
= esw_cfg
[i
].op_mode
;
3878 qlcnic_get_eswitch_port_config(adapter
, &esw_cfg
[i
]);
3879 esw_cfg
[i
].op_mode
= op_mode
;
3880 esw_cfg
[i
].pci_func
= adapter
->ahw
->pci_func
;
3882 switch (esw_cfg
[i
].op_mode
) {
3883 case QLCNIC_PORT_DEFAULTS
:
3884 qlcnic_set_eswitch_port_features(adapter
, &esw_cfg
[i
]);
3886 case QLCNIC_ADD_VLAN
:
3887 qlcnic_set_vlan_config(adapter
, &esw_cfg
[i
]);
3889 case QLCNIC_DEL_VLAN
:
3890 esw_cfg
[i
].vlan_id
= 0;
3891 qlcnic_set_vlan_config(adapter
, &esw_cfg
[i
]);
3896 if (adapter
->op_mode
!= QLCNIC_MGMT_FUNC
)
3899 for (i
= 0; i
< count
; i
++) {
3900 pci_func
= esw_cfg
[i
].pci_func
;
3901 npar
= &adapter
->npars
[pci_func
];
3902 switch (esw_cfg
[i
].op_mode
) {
3903 case QLCNIC_PORT_DEFAULTS
:
3904 npar
->promisc_mode
= esw_cfg
[i
].promisc_mode
;
3905 npar
->mac_override
= esw_cfg
[i
].mac_override
;
3906 npar
->offload_flags
= esw_cfg
[i
].offload_flags
;
3907 npar
->mac_anti_spoof
= esw_cfg
[i
].mac_anti_spoof
;
3908 npar
->discard_tagged
= esw_cfg
[i
].discard_tagged
;
3910 case QLCNIC_ADD_VLAN
:
3911 npar
->pvid
= esw_cfg
[i
].vlan_id
;
3913 case QLCNIC_DEL_VLAN
:
3923 qlcnic_sysfs_read_esw_config(struct file
*file
, struct kobject
*kobj
,
3924 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3926 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3927 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3928 struct qlcnic_esw_func_cfg esw_cfg
[QLCNIC_MAX_PCI_FUNC
];
3931 if (size
!= sizeof(esw_cfg
))
3932 return QL_STATUS_INVALID_PARAM
;
3934 for (i
= 0; i
< QLCNIC_MAX_PCI_FUNC
; i
++) {
3935 if (adapter
->npars
[i
].type
!= QLCNIC_TYPE_NIC
)
3937 esw_cfg
[i
].pci_func
= i
;
3938 if (qlcnic_get_eswitch_port_config(adapter
, &esw_cfg
[i
]))
3939 return QL_STATUS_INVALID_PARAM
;
3941 memcpy(buf
, &esw_cfg
, size
);
3947 validate_npar_config(struct qlcnic_adapter
*adapter
,
3948 struct qlcnic_npar_func_cfg
*np_cfg
, int count
)
3952 for (i
= 0; i
< count
; i
++) {
3953 pci_func
= np_cfg
[i
].pci_func
;
3954 if (pci_func
>= QLCNIC_MAX_PCI_FUNC
)
3955 return QL_STATUS_INVALID_PARAM
;
3957 if (adapter
->npars
[pci_func
].type
!= QLCNIC_TYPE_NIC
)
3958 return QL_STATUS_INVALID_PARAM
;
3960 if (!IS_VALID_BW(np_cfg
[i
].min_bw
) ||
3961 !IS_VALID_BW(np_cfg
[i
].max_bw
))
3962 return QL_STATUS_INVALID_PARAM
;
3968 qlcnic_sysfs_write_npar_config(struct file
*file
, struct kobject
*kobj
,
3969 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3971 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3972 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3973 struct qlcnic_info nic_info
;
3974 struct qlcnic_npar_func_cfg
*np_cfg
;
3975 int i
, count
, rem
, ret
;
3978 count
= size
/ sizeof(struct qlcnic_npar_func_cfg
);
3979 rem
= size
% sizeof(struct qlcnic_npar_func_cfg
);
3981 return QL_STATUS_INVALID_PARAM
;
3983 np_cfg
= (struct qlcnic_npar_func_cfg
*) buf
;
3984 ret
= validate_npar_config(adapter
, np_cfg
, count
);
3988 for (i
= 0; i
< count
; i
++) {
3989 pci_func
= np_cfg
[i
].pci_func
;
3990 ret
= qlcnic_get_nic_info(adapter
, &nic_info
, pci_func
);
3993 nic_info
.pci_func
= pci_func
;
3994 nic_info
.min_tx_bw
= np_cfg
[i
].min_bw
;
3995 nic_info
.max_tx_bw
= np_cfg
[i
].max_bw
;
3996 ret
= qlcnic_set_nic_info(adapter
, &nic_info
);
3999 adapter
->npars
[i
].min_bw
= nic_info
.min_tx_bw
;
4000 adapter
->npars
[i
].max_bw
= nic_info
.max_tx_bw
;
4007 qlcnic_sysfs_read_npar_config(struct file
*file
, struct kobject
*kobj
,
4008 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
4010 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
4011 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
4012 struct qlcnic_info nic_info
;
4013 struct qlcnic_npar_func_cfg np_cfg
[QLCNIC_MAX_PCI_FUNC
];
4016 if (size
!= sizeof(np_cfg
))
4017 return QL_STATUS_INVALID_PARAM
;
4019 for (i
= 0; i
< QLCNIC_MAX_PCI_FUNC
; i
++) {
4020 if (adapter
->npars
[i
].type
!= QLCNIC_TYPE_NIC
)
4022 ret
= qlcnic_get_nic_info(adapter
, &nic_info
, i
);
4026 np_cfg
[i
].pci_func
= i
;
4027 np_cfg
[i
].op_mode
= (u8
)nic_info
.op_mode
;
4028 np_cfg
[i
].port_num
= nic_info
.phys_port
;
4029 np_cfg
[i
].fw_capab
= nic_info
.capabilities
;
4030 np_cfg
[i
].min_bw
= nic_info
.min_tx_bw
;
4031 np_cfg
[i
].max_bw
= nic_info
.max_tx_bw
;
4032 np_cfg
[i
].max_tx_queues
= nic_info
.max_tx_ques
;
4033 np_cfg
[i
].max_rx_queues
= nic_info
.max_rx_ques
;
4035 memcpy(buf
, &np_cfg
, size
);
4040 qlcnic_sysfs_get_port_stats(struct file
*file
, struct kobject
*kobj
,
4041 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
4043 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
4044 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
4045 struct qlcnic_esw_statistics port_stats
;
4048 if (size
!= sizeof(struct qlcnic_esw_statistics
))
4049 return QL_STATUS_INVALID_PARAM
;
4051 if (offset
>= QLCNIC_MAX_PCI_FUNC
)
4052 return QL_STATUS_INVALID_PARAM
;
4054 memset(&port_stats
, 0, size
);
4055 ret
= qlcnic_get_port_stats(adapter
, offset
, QLCNIC_QUERY_RX_COUNTER
,
4060 ret
= qlcnic_get_port_stats(adapter
, offset
, QLCNIC_QUERY_TX_COUNTER
,
4065 memcpy(buf
, &port_stats
, size
);
4070 qlcnic_sysfs_get_esw_stats(struct file
*file
, struct kobject
*kobj
,
4071 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
4073 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
4074 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
4075 struct qlcnic_esw_statistics esw_stats
;
4078 if (size
!= sizeof(struct qlcnic_esw_statistics
))
4079 return QL_STATUS_INVALID_PARAM
;
4081 if (offset
>= QLCNIC_NIU_MAX_XG_PORTS
)
4082 return QL_STATUS_INVALID_PARAM
;
4084 memset(&esw_stats
, 0, size
);
4085 ret
= qlcnic_get_eswitch_stats(adapter
, offset
, QLCNIC_QUERY_RX_COUNTER
,
4090 ret
= qlcnic_get_eswitch_stats(adapter
, offset
, QLCNIC_QUERY_TX_COUNTER
,
4095 memcpy(buf
, &esw_stats
, size
);
4100 qlcnic_sysfs_clear_esw_stats(struct file
*file
, struct kobject
*kobj
,
4101 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
4103 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
4104 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
4107 if (offset
>= QLCNIC_NIU_MAX_XG_PORTS
)
4108 return QL_STATUS_INVALID_PARAM
;
4110 ret
= qlcnic_clear_esw_stats(adapter
, QLCNIC_STATS_ESWITCH
, offset
,
4111 QLCNIC_QUERY_RX_COUNTER
);
4115 ret
= qlcnic_clear_esw_stats(adapter
, QLCNIC_STATS_ESWITCH
, offset
,
4116 QLCNIC_QUERY_TX_COUNTER
);
4124 qlcnic_sysfs_clear_port_stats(struct file
*file
, struct kobject
*kobj
,
4125 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
4128 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
4129 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
4132 if (offset
>= QLCNIC_MAX_PCI_FUNC
)
4133 return QL_STATUS_INVALID_PARAM
;
4135 ret
= qlcnic_clear_esw_stats(adapter
, QLCNIC_STATS_PORT
, offset
,
4136 QLCNIC_QUERY_RX_COUNTER
);
4140 ret
= qlcnic_clear_esw_stats(adapter
, QLCNIC_STATS_PORT
, offset
,
4141 QLCNIC_QUERY_TX_COUNTER
);
4149 qlcnic_sysfs_read_pci_config(struct file
*file
, struct kobject
*kobj
,
4150 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
4152 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
4153 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
4154 struct qlcnic_pci_func_cfg pci_cfg
[QLCNIC_MAX_PCI_FUNC
];
4155 struct qlcnic_pci_info
*pci_info
;
4158 if (size
!= sizeof(pci_cfg
))
4159 return QL_STATUS_INVALID_PARAM
;
4161 pci_info
= kcalloc(QLCNIC_MAX_PCI_FUNC
, sizeof(*pci_info
), GFP_KERNEL
);
4165 ret
= qlcnic_get_pci_info(adapter
, pci_info
);
4171 for (i
= 0; i
< QLCNIC_MAX_PCI_FUNC
; i
++) {
4172 pci_cfg
[i
].pci_func
= pci_info
[i
].id
;
4173 pci_cfg
[i
].func_type
= pci_info
[i
].type
;
4174 pci_cfg
[i
].port_num
= pci_info
[i
].default_port
;
4175 pci_cfg
[i
].min_bw
= pci_info
[i
].tx_min_bw
;
4176 pci_cfg
[i
].max_bw
= pci_info
[i
].tx_max_bw
;
4177 memcpy(&pci_cfg
[i
].def_mac_addr
, &pci_info
[i
].mac
, ETH_ALEN
);
4179 memcpy(buf
, &pci_cfg
, size
);
4183 static struct bin_attribute bin_attr_npar_config
= {
4184 .attr
= {.name
= "npar_config", .mode
= (S_IRUGO
| S_IWUSR
)},
4186 .read
= qlcnic_sysfs_read_npar_config
,
4187 .write
= qlcnic_sysfs_write_npar_config
,
4190 static struct bin_attribute bin_attr_pci_config
= {
4191 .attr
= {.name
= "pci_config", .mode
= (S_IRUGO
| S_IWUSR
)},
4193 .read
= qlcnic_sysfs_read_pci_config
,
4197 static struct bin_attribute bin_attr_port_stats
= {
4198 .attr
= {.name
= "port_stats", .mode
= (S_IRUGO
| S_IWUSR
)},
4200 .read
= qlcnic_sysfs_get_port_stats
,
4201 .write
= qlcnic_sysfs_clear_port_stats
,
4204 static struct bin_attribute bin_attr_esw_stats
= {
4205 .attr
= {.name
= "esw_stats", .mode
= (S_IRUGO
| S_IWUSR
)},
4207 .read
= qlcnic_sysfs_get_esw_stats
,
4208 .write
= qlcnic_sysfs_clear_esw_stats
,
4211 static struct bin_attribute bin_attr_esw_config
= {
4212 .attr
= {.name
= "esw_config", .mode
= (S_IRUGO
| S_IWUSR
)},
4214 .read
= qlcnic_sysfs_read_esw_config
,
4215 .write
= qlcnic_sysfs_write_esw_config
,
4218 static struct bin_attribute bin_attr_pm_config
= {
4219 .attr
= {.name
= "pm_config", .mode
= (S_IRUGO
| S_IWUSR
)},
4221 .read
= qlcnic_sysfs_read_pm_config
,
4222 .write
= qlcnic_sysfs_write_pm_config
,
4226 qlcnic_create_sysfs_entries(struct qlcnic_adapter
*adapter
)
4228 struct device
*dev
= &adapter
->pdev
->dev
;
4230 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_BDG
)
4231 if (device_create_file(dev
, &dev_attr_bridged_mode
))
4233 "failed to create bridged_mode sysfs entry\n");
4237 qlcnic_remove_sysfs_entries(struct qlcnic_adapter
*adapter
)
4239 struct device
*dev
= &adapter
->pdev
->dev
;
4241 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_BDG
)
4242 device_remove_file(dev
, &dev_attr_bridged_mode
);
4246 qlcnic_create_diag_entries(struct qlcnic_adapter
*adapter
)
4248 struct device
*dev
= &adapter
->pdev
->dev
;
4250 if (device_create_bin_file(dev
, &bin_attr_port_stats
))
4251 dev_info(dev
, "failed to create port stats sysfs entry");
4253 if (adapter
->op_mode
== QLCNIC_NON_PRIV_FUNC
)
4255 if (device_create_file(dev
, &dev_attr_diag_mode
))
4256 dev_info(dev
, "failed to create diag_mode sysfs entry\n");
4257 if (device_create_file(dev
, &dev_attr_beacon
))
4258 dev_info(dev
, "failed to create beacon sysfs entry");
4259 if (device_create_bin_file(dev
, &bin_attr_crb
))
4260 dev_info(dev
, "failed to create crb sysfs entry\n");
4261 if (device_create_bin_file(dev
, &bin_attr_mem
))
4262 dev_info(dev
, "failed to create mem sysfs entry\n");
4263 if (device_create_bin_file(dev
, &bin_attr_pci_config
))
4264 dev_info(dev
, "failed to create pci config sysfs entry");
4265 if (!(adapter
->flags
& QLCNIC_ESWITCH_ENABLED
))
4267 if (device_create_bin_file(dev
, &bin_attr_esw_config
))
4268 dev_info(dev
, "failed to create esw config sysfs entry");
4269 if (adapter
->op_mode
!= QLCNIC_MGMT_FUNC
)
4271 if (device_create_bin_file(dev
, &bin_attr_npar_config
))
4272 dev_info(dev
, "failed to create npar config sysfs entry");
4273 if (device_create_bin_file(dev
, &bin_attr_pm_config
))
4274 dev_info(dev
, "failed to create pm config sysfs entry");
4275 if (device_create_bin_file(dev
, &bin_attr_esw_stats
))
4276 dev_info(dev
, "failed to create eswitch stats sysfs entry");
4280 qlcnic_remove_diag_entries(struct qlcnic_adapter
*adapter
)
4282 struct device
*dev
= &adapter
->pdev
->dev
;
4284 device_remove_bin_file(dev
, &bin_attr_port_stats
);
4286 if (adapter
->op_mode
== QLCNIC_NON_PRIV_FUNC
)
4288 device_remove_file(dev
, &dev_attr_diag_mode
);
4289 device_remove_file(dev
, &dev_attr_beacon
);
4290 device_remove_bin_file(dev
, &bin_attr_crb
);
4291 device_remove_bin_file(dev
, &bin_attr_mem
);
4292 device_remove_bin_file(dev
, &bin_attr_pci_config
);
4293 if (!(adapter
->flags
& QLCNIC_ESWITCH_ENABLED
))
4295 device_remove_bin_file(dev
, &bin_attr_esw_config
);
4296 if (adapter
->op_mode
!= QLCNIC_MGMT_FUNC
)
4298 device_remove_bin_file(dev
, &bin_attr_npar_config
);
4299 device_remove_bin_file(dev
, &bin_attr_pm_config
);
4300 device_remove_bin_file(dev
, &bin_attr_esw_stats
);
4305 #define is_qlcnic_netdev(dev) (dev->netdev_ops == &qlcnic_netdev_ops)
4308 qlcnic_config_indev_addr(struct qlcnic_adapter
*adapter
,
4309 struct net_device
*dev
, unsigned long event
)
4311 struct in_device
*indev
;
4313 indev
= in_dev_get(dev
);
4320 qlcnic_config_ipaddr(adapter
,
4321 ifa
->ifa_address
, QLCNIC_IP_UP
);
4324 qlcnic_config_ipaddr(adapter
,
4325 ifa
->ifa_address
, QLCNIC_IP_DOWN
);
4330 } endfor_ifa(indev
);
4336 qlcnic_restore_indev_addr(struct net_device
*netdev
, unsigned long event
)
4338 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
4339 struct net_device
*dev
;
4342 qlcnic_config_indev_addr(adapter
, netdev
, event
);
4344 for_each_set_bit(vid
, adapter
->vlans
, VLAN_N_VID
) {
4345 dev
= __vlan_find_dev_deep(netdev
, vid
);
4348 qlcnic_config_indev_addr(adapter
, dev
, event
);
4352 static int qlcnic_netdev_event(struct notifier_block
*this,
4353 unsigned long event
, void *ptr
)
4355 struct qlcnic_adapter
*adapter
;
4356 struct net_device
*dev
= (struct net_device
*)ptr
;
4362 if (dev
->priv_flags
& IFF_802_1Q_VLAN
) {
4363 dev
= vlan_dev_real_dev(dev
);
4367 if (!is_qlcnic_netdev(dev
))
4370 adapter
= netdev_priv(dev
);
4375 if (!test_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
4378 qlcnic_config_indev_addr(adapter
, dev
, event
);
4384 qlcnic_inetaddr_event(struct notifier_block
*this,
4385 unsigned long event
, void *ptr
)
4387 struct qlcnic_adapter
*adapter
;
4388 struct net_device
*dev
;
4390 struct in_ifaddr
*ifa
= (struct in_ifaddr
*)ptr
;
4392 dev
= ifa
->ifa_dev
? ifa
->ifa_dev
->dev
: NULL
;
4398 if (dev
->priv_flags
& IFF_802_1Q_VLAN
) {
4399 dev
= vlan_dev_real_dev(dev
);
4403 if (!is_qlcnic_netdev(dev
))
4406 adapter
= netdev_priv(dev
);
4411 if (!test_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
4416 qlcnic_config_ipaddr(adapter
, ifa
->ifa_address
, QLCNIC_IP_UP
);
4419 qlcnic_config_ipaddr(adapter
, ifa
->ifa_address
, QLCNIC_IP_DOWN
);
4429 static struct notifier_block qlcnic_netdev_cb
= {
4430 .notifier_call
= qlcnic_netdev_event
,
4433 static struct notifier_block qlcnic_inetaddr_cb
= {
4434 .notifier_call
= qlcnic_inetaddr_event
,
4438 qlcnic_restore_indev_addr(struct net_device
*dev
, unsigned long event
)
4441 static struct pci_error_handlers qlcnic_err_handler
= {
4442 .error_detected
= qlcnic_io_error_detected
,
4443 .slot_reset
= qlcnic_io_slot_reset
,
4444 .resume
= qlcnic_io_resume
,
4447 static struct pci_driver qlcnic_driver
= {
4448 .name
= qlcnic_driver_name
,
4449 .id_table
= qlcnic_pci_tbl
,
4450 .probe
= qlcnic_probe
,
4451 .remove
= __devexit_p(qlcnic_remove
),
4453 .suspend
= qlcnic_suspend
,
4454 .resume
= qlcnic_resume
,
4456 .shutdown
= qlcnic_shutdown
,
4457 .err_handler
= &qlcnic_err_handler
4461 static int __init
qlcnic_init_module(void)
4465 printk(KERN_INFO
"%s\n", qlcnic_driver_string
);
4467 qlcnic_wq
= create_singlethread_workqueue("qlcnic");
4468 if (qlcnic_wq
== NULL
) {
4469 printk(KERN_ERR
"qlcnic: cannot create workqueue\n");
4474 register_netdevice_notifier(&qlcnic_netdev_cb
);
4475 register_inetaddr_notifier(&qlcnic_inetaddr_cb
);
4478 ret
= pci_register_driver(&qlcnic_driver
);
4481 unregister_inetaddr_notifier(&qlcnic_inetaddr_cb
);
4482 unregister_netdevice_notifier(&qlcnic_netdev_cb
);
4484 destroy_workqueue(qlcnic_wq
);
4490 module_init(qlcnic_init_module
);
4492 static void __exit
qlcnic_exit_module(void)
4495 pci_unregister_driver(&qlcnic_driver
);
4498 unregister_inetaddr_notifier(&qlcnic_inetaddr_cb
);
4499 unregister_netdevice_notifier(&qlcnic_netdev_cb
);
4501 destroy_workqueue(qlcnic_wq
);
4504 module_exit(qlcnic_exit_module
);