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 int qlcnic_vlan_rx_add(struct net_device
*, u16
);
101 static int 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
);
747 qlcnic_vlan_rx_del(struct net_device
*netdev
, u16 vid
)
749 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
751 qlcnic_restore_indev_addr(netdev
, NETDEV_DOWN
);
752 clear_bit(vid
, adapter
->vlans
);
757 qlcnic_set_eswitch_port_features(struct qlcnic_adapter
*adapter
,
758 struct qlcnic_esw_func_cfg
*esw_cfg
)
760 adapter
->flags
&= ~(QLCNIC_MACSPOOF
| QLCNIC_MAC_OVERRIDE_DISABLED
|
761 QLCNIC_PROMISC_DISABLED
);
763 if (esw_cfg
->mac_anti_spoof
)
764 adapter
->flags
|= QLCNIC_MACSPOOF
;
766 if (!esw_cfg
->mac_override
)
767 adapter
->flags
|= QLCNIC_MAC_OVERRIDE_DISABLED
;
769 if (!esw_cfg
->promisc_mode
)
770 adapter
->flags
|= QLCNIC_PROMISC_DISABLED
;
772 qlcnic_set_netdev_features(adapter
, esw_cfg
);
776 qlcnic_set_eswitch_port_config(struct qlcnic_adapter
*adapter
)
778 struct qlcnic_esw_func_cfg esw_cfg
;
780 if (!(adapter
->flags
& QLCNIC_ESWITCH_ENABLED
))
783 esw_cfg
.pci_func
= adapter
->ahw
->pci_func
;
784 if (qlcnic_get_eswitch_port_config(adapter
, &esw_cfg
))
786 qlcnic_set_vlan_config(adapter
, &esw_cfg
);
787 qlcnic_set_eswitch_port_features(adapter
, &esw_cfg
);
793 qlcnic_set_netdev_features(struct qlcnic_adapter
*adapter
,
794 struct qlcnic_esw_func_cfg
*esw_cfg
)
796 struct net_device
*netdev
= adapter
->netdev
;
797 netdev_features_t features
, vlan_features
;
799 features
= (NETIF_F_SG
| NETIF_F_IP_CSUM
| NETIF_F_RXCSUM
|
800 NETIF_F_IPV6_CSUM
| NETIF_F_GRO
);
801 vlan_features
= (NETIF_F_SG
| NETIF_F_IP_CSUM
|
802 NETIF_F_IPV6_CSUM
| NETIF_F_HW_VLAN_FILTER
);
804 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_TSO
) {
805 features
|= (NETIF_F_TSO
| NETIF_F_TSO6
);
806 vlan_features
|= (NETIF_F_TSO
| NETIF_F_TSO6
);
809 if (netdev
->features
& NETIF_F_LRO
)
810 features
|= NETIF_F_LRO
;
812 if (esw_cfg
->offload_flags
& BIT_0
) {
813 netdev
->features
|= features
;
814 if (!(esw_cfg
->offload_flags
& BIT_1
))
815 netdev
->features
&= ~NETIF_F_TSO
;
816 if (!(esw_cfg
->offload_flags
& BIT_2
))
817 netdev
->features
&= ~NETIF_F_TSO6
;
819 netdev
->features
&= ~features
;
822 netdev
->vlan_features
= (features
& vlan_features
);
826 qlcnic_check_eswitch_mode(struct qlcnic_adapter
*adapter
)
828 void __iomem
*priv_op
;
829 u32 op_mode
, priv_level
;
832 err
= qlcnic_initialize_nic(adapter
);
836 if (adapter
->flags
& QLCNIC_ADAPTER_INITIALIZED
)
839 priv_op
= adapter
->ahw
->pci_base0
+ QLCNIC_DRV_OP_MODE
;
840 op_mode
= readl(priv_op
);
841 priv_level
= QLC_DEV_GET_DRV(op_mode
, adapter
->ahw
->pci_func
);
843 if (op_mode
== QLC_DEV_DRV_DEFAULT
)
844 priv_level
= QLCNIC_MGMT_FUNC
;
846 priv_level
= QLC_DEV_GET_DRV(op_mode
, adapter
->ahw
->pci_func
);
848 if (adapter
->flags
& QLCNIC_ESWITCH_ENABLED
) {
849 if (priv_level
== QLCNIC_MGMT_FUNC
) {
850 adapter
->op_mode
= QLCNIC_MGMT_FUNC
;
851 err
= qlcnic_init_pci_info(adapter
);
854 /* Set privilege level for other functions */
855 qlcnic_set_function_modes(adapter
);
856 dev_info(&adapter
->pdev
->dev
,
857 "HAL Version: %d, Management function\n",
858 adapter
->fw_hal_version
);
859 } else if (priv_level
== QLCNIC_PRIV_FUNC
) {
860 adapter
->op_mode
= QLCNIC_PRIV_FUNC
;
861 dev_info(&adapter
->pdev
->dev
,
862 "HAL Version: %d, Privileged function\n",
863 adapter
->fw_hal_version
);
867 adapter
->flags
|= QLCNIC_ADAPTER_INITIALIZED
;
873 qlcnic_set_default_offload_settings(struct qlcnic_adapter
*adapter
)
875 struct qlcnic_esw_func_cfg esw_cfg
;
876 struct qlcnic_npar_info
*npar
;
879 if (adapter
->need_fw_reset
)
882 for (i
= 0; i
< QLCNIC_MAX_PCI_FUNC
; i
++) {
883 if (adapter
->npars
[i
].type
!= QLCNIC_TYPE_NIC
)
885 memset(&esw_cfg
, 0, sizeof(struct qlcnic_esw_func_cfg
));
886 esw_cfg
.pci_func
= i
;
887 esw_cfg
.offload_flags
= BIT_0
;
888 esw_cfg
.mac_override
= BIT_0
;
889 esw_cfg
.promisc_mode
= BIT_0
;
890 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_TSO
)
891 esw_cfg
.offload_flags
|= (BIT_1
| BIT_2
);
892 if (qlcnic_config_switch_port(adapter
, &esw_cfg
))
894 npar
= &adapter
->npars
[i
];
895 npar
->pvid
= esw_cfg
.vlan_id
;
896 npar
->mac_override
= esw_cfg
.mac_override
;
897 npar
->mac_anti_spoof
= esw_cfg
.mac_anti_spoof
;
898 npar
->discard_tagged
= esw_cfg
.discard_tagged
;
899 npar
->promisc_mode
= esw_cfg
.promisc_mode
;
900 npar
->offload_flags
= esw_cfg
.offload_flags
;
907 qlcnic_reset_eswitch_config(struct qlcnic_adapter
*adapter
,
908 struct qlcnic_npar_info
*npar
, int pci_func
)
910 struct qlcnic_esw_func_cfg esw_cfg
;
911 esw_cfg
.op_mode
= QLCNIC_PORT_DEFAULTS
;
912 esw_cfg
.pci_func
= pci_func
;
913 esw_cfg
.vlan_id
= npar
->pvid
;
914 esw_cfg
.mac_override
= npar
->mac_override
;
915 esw_cfg
.discard_tagged
= npar
->discard_tagged
;
916 esw_cfg
.mac_anti_spoof
= npar
->mac_anti_spoof
;
917 esw_cfg
.offload_flags
= npar
->offload_flags
;
918 esw_cfg
.promisc_mode
= npar
->promisc_mode
;
919 if (qlcnic_config_switch_port(adapter
, &esw_cfg
))
922 esw_cfg
.op_mode
= QLCNIC_ADD_VLAN
;
923 if (qlcnic_config_switch_port(adapter
, &esw_cfg
))
930 qlcnic_reset_npar_config(struct qlcnic_adapter
*adapter
)
933 struct qlcnic_npar_info
*npar
;
934 struct qlcnic_info nic_info
;
936 if (!adapter
->need_fw_reset
)
939 /* Set the NPAR config data after FW reset */
940 for (i
= 0; i
< QLCNIC_MAX_PCI_FUNC
; i
++) {
941 npar
= &adapter
->npars
[i
];
942 if (npar
->type
!= QLCNIC_TYPE_NIC
)
944 err
= qlcnic_get_nic_info(adapter
, &nic_info
, i
);
947 nic_info
.min_tx_bw
= npar
->min_bw
;
948 nic_info
.max_tx_bw
= npar
->max_bw
;
949 err
= qlcnic_set_nic_info(adapter
, &nic_info
);
953 if (npar
->enable_pm
) {
954 err
= qlcnic_config_port_mirroring(adapter
,
955 npar
->dest_npar
, 1, i
);
959 err
= qlcnic_reset_eswitch_config(adapter
, npar
, i
);
966 static int qlcnic_check_npar_opertional(struct qlcnic_adapter
*adapter
)
968 u8 npar_opt_timeo
= QLCNIC_DEV_NPAR_OPER_TIMEO
;
971 if (adapter
->op_mode
== QLCNIC_MGMT_FUNC
)
974 npar_state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_NPAR_STATE
);
975 while (npar_state
!= QLCNIC_DEV_NPAR_OPER
&& --npar_opt_timeo
) {
977 npar_state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_NPAR_STATE
);
979 if (!npar_opt_timeo
) {
980 dev_err(&adapter
->pdev
->dev
,
981 "Waiting for NPAR state to opertional timeout\n");
988 qlcnic_set_mgmt_operations(struct qlcnic_adapter
*adapter
)
992 if (!(adapter
->flags
& QLCNIC_ESWITCH_ENABLED
) ||
993 adapter
->op_mode
!= QLCNIC_MGMT_FUNC
)
996 err
= qlcnic_set_default_offload_settings(adapter
);
1000 err
= qlcnic_reset_npar_config(adapter
);
1004 qlcnic_dev_set_npar_ready(adapter
);
1010 qlcnic_start_firmware(struct qlcnic_adapter
*adapter
)
1014 err
= qlcnic_can_start_firmware(adapter
);
1018 goto check_fw_status
;
1021 qlcnic_request_firmware(adapter
);
1023 err
= qlcnic_check_flash_fw_ver(adapter
);
1027 adapter
->fw_type
= QLCNIC_FLASH_ROMIMAGE
;
1030 err
= qlcnic_need_fw_reset(adapter
);
1032 goto check_fw_status
;
1034 err
= qlcnic_pinit_from_rom(adapter
);
1038 err
= qlcnic_load_firmware(adapter
);
1042 qlcnic_release_firmware(adapter
);
1043 QLCWR32(adapter
, CRB_DRIVER_VERSION
, QLCNIC_DRIVER_VERSION
);
1046 err
= qlcnic_check_fw_status(adapter
);
1050 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
, QLCNIC_DEV_READY
);
1051 qlcnic_idc_debug_info(adapter
, 1);
1053 err
= qlcnic_check_eswitch_mode(adapter
);
1055 dev_err(&adapter
->pdev
->dev
,
1056 "Memory allocation failed for eswitch\n");
1059 err
= qlcnic_set_mgmt_operations(adapter
);
1063 qlcnic_check_options(adapter
);
1064 adapter
->need_fw_reset
= 0;
1066 qlcnic_release_firmware(adapter
);
1070 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
, QLCNIC_DEV_FAILED
);
1071 dev_err(&adapter
->pdev
->dev
, "Device state set to failed\n");
1073 qlcnic_release_firmware(adapter
);
1078 qlcnic_request_irq(struct qlcnic_adapter
*adapter
)
1080 irq_handler_t handler
;
1081 struct qlcnic_host_sds_ring
*sds_ring
;
1084 unsigned long flags
= 0;
1085 struct net_device
*netdev
= adapter
->netdev
;
1086 struct qlcnic_recv_context
*recv_ctx
= adapter
->recv_ctx
;
1088 if (adapter
->diag_test
== QLCNIC_INTERRUPT_TEST
) {
1089 handler
= qlcnic_tmp_intr
;
1090 if (!QLCNIC_IS_MSI_FAMILY(adapter
))
1091 flags
|= IRQF_SHARED
;
1094 if (adapter
->flags
& QLCNIC_MSIX_ENABLED
)
1095 handler
= qlcnic_msix_intr
;
1096 else if (adapter
->flags
& QLCNIC_MSI_ENABLED
)
1097 handler
= qlcnic_msi_intr
;
1099 flags
|= IRQF_SHARED
;
1100 handler
= qlcnic_intr
;
1103 adapter
->irq
= netdev
->irq
;
1105 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
1106 sds_ring
= &recv_ctx
->sds_rings
[ring
];
1107 sprintf(sds_ring
->name
, "%s[%d]", netdev
->name
, ring
);
1108 err
= request_irq(sds_ring
->irq
, handler
,
1109 flags
, sds_ring
->name
, sds_ring
);
1118 qlcnic_free_irq(struct qlcnic_adapter
*adapter
)
1121 struct qlcnic_host_sds_ring
*sds_ring
;
1123 struct qlcnic_recv_context
*recv_ctx
= adapter
->recv_ctx
;
1125 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
1126 sds_ring
= &recv_ctx
->sds_rings
[ring
];
1127 free_irq(sds_ring
->irq
, sds_ring
);
1132 __qlcnic_up(struct qlcnic_adapter
*adapter
, struct net_device
*netdev
)
1135 struct qlcnic_host_rds_ring
*rds_ring
;
1137 if (adapter
->is_up
!= QLCNIC_ADAPTER_UP_MAGIC
)
1140 if (test_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
1142 if (qlcnic_set_eswitch_port_config(adapter
))
1145 if (qlcnic_fw_create_ctx(adapter
))
1148 for (ring
= 0; ring
< adapter
->max_rds_rings
; ring
++) {
1149 rds_ring
= &adapter
->recv_ctx
->rds_rings
[ring
];
1150 qlcnic_post_rx_buffers(adapter
, rds_ring
);
1153 qlcnic_set_multi(netdev
);
1154 qlcnic_fw_cmd_set_mtu(adapter
, netdev
->mtu
);
1156 adapter
->ahw
->linkup
= 0;
1158 if (adapter
->max_sds_rings
> 1)
1159 qlcnic_config_rss(adapter
, 1);
1161 qlcnic_config_intr_coalesce(adapter
);
1163 if (netdev
->features
& NETIF_F_LRO
)
1164 qlcnic_config_hw_lro(adapter
, QLCNIC_LRO_ENABLED
);
1166 qlcnic_napi_enable(adapter
);
1168 qlcnic_linkevent_request(adapter
, 1);
1170 adapter
->reset_context
= 0;
1171 set_bit(__QLCNIC_DEV_UP
, &adapter
->state
);
1175 /* Usage: During resume and firmware recovery module.*/
1178 qlcnic_up(struct qlcnic_adapter
*adapter
, struct net_device
*netdev
)
1183 if (netif_running(netdev
))
1184 err
= __qlcnic_up(adapter
, netdev
);
1191 __qlcnic_down(struct qlcnic_adapter
*adapter
, struct net_device
*netdev
)
1193 if (adapter
->is_up
!= QLCNIC_ADAPTER_UP_MAGIC
)
1196 if (!test_and_clear_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
1200 spin_lock(&adapter
->tx_clean_lock
);
1201 netif_carrier_off(netdev
);
1202 netif_tx_disable(netdev
);
1204 qlcnic_free_mac_list(adapter
);
1206 if (adapter
->fhash
.fnum
)
1207 qlcnic_delete_lb_filters(adapter
);
1209 qlcnic_nic_set_promisc(adapter
, QLCNIC_NIU_NON_PROMISC_MODE
);
1211 qlcnic_napi_disable(adapter
);
1213 qlcnic_fw_destroy_ctx(adapter
);
1215 qlcnic_reset_rx_buffers_list(adapter
);
1216 qlcnic_release_tx_buffers(adapter
);
1217 spin_unlock(&adapter
->tx_clean_lock
);
1220 /* Usage: During suspend and firmware recovery module */
1223 qlcnic_down(struct qlcnic_adapter
*adapter
, struct net_device
*netdev
)
1226 if (netif_running(netdev
))
1227 __qlcnic_down(adapter
, netdev
);
1233 qlcnic_attach(struct qlcnic_adapter
*adapter
)
1235 struct net_device
*netdev
= adapter
->netdev
;
1236 struct pci_dev
*pdev
= adapter
->pdev
;
1239 if (adapter
->is_up
== QLCNIC_ADAPTER_UP_MAGIC
)
1242 err
= qlcnic_napi_add(adapter
, netdev
);
1246 err
= qlcnic_alloc_sw_resources(adapter
);
1248 dev_err(&pdev
->dev
, "Error in setting sw resources\n");
1249 goto err_out_napi_del
;
1252 err
= qlcnic_alloc_hw_resources(adapter
);
1254 dev_err(&pdev
->dev
, "Error in setting hw resources\n");
1255 goto err_out_free_sw
;
1258 err
= qlcnic_request_irq(adapter
);
1260 dev_err(&pdev
->dev
, "failed to setup interrupt\n");
1261 goto err_out_free_hw
;
1264 qlcnic_create_sysfs_entries(adapter
);
1266 adapter
->is_up
= QLCNIC_ADAPTER_UP_MAGIC
;
1270 qlcnic_free_hw_resources(adapter
);
1272 qlcnic_free_sw_resources(adapter
);
1274 qlcnic_napi_del(adapter
);
1279 qlcnic_detach(struct qlcnic_adapter
*adapter
)
1281 if (adapter
->is_up
!= QLCNIC_ADAPTER_UP_MAGIC
)
1284 qlcnic_remove_sysfs_entries(adapter
);
1286 qlcnic_free_hw_resources(adapter
);
1287 qlcnic_release_rx_buffers(adapter
);
1288 qlcnic_free_irq(adapter
);
1289 qlcnic_napi_del(adapter
);
1290 qlcnic_free_sw_resources(adapter
);
1295 void qlcnic_diag_free_res(struct net_device
*netdev
, int max_sds_rings
)
1297 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
1298 struct qlcnic_host_sds_ring
*sds_ring
;
1301 clear_bit(__QLCNIC_DEV_UP
, &adapter
->state
);
1302 if (adapter
->diag_test
== QLCNIC_INTERRUPT_TEST
) {
1303 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
1304 sds_ring
= &adapter
->recv_ctx
->sds_rings
[ring
];
1305 qlcnic_disable_int(sds_ring
);
1309 qlcnic_fw_destroy_ctx(adapter
);
1311 qlcnic_detach(adapter
);
1313 adapter
->diag_test
= 0;
1314 adapter
->max_sds_rings
= max_sds_rings
;
1316 if (qlcnic_attach(adapter
))
1319 if (netif_running(netdev
))
1320 __qlcnic_up(adapter
, netdev
);
1322 netif_device_attach(netdev
);
1325 static int qlcnic_alloc_adapter_resources(struct qlcnic_adapter
*adapter
)
1328 adapter
->ahw
= kzalloc(sizeof(struct qlcnic_hardware_context
),
1330 if (!adapter
->ahw
) {
1331 dev_err(&adapter
->pdev
->dev
,
1332 "Failed to allocate recv ctx resources for adapter\n");
1336 adapter
->recv_ctx
= kzalloc(sizeof(struct qlcnic_recv_context
),
1338 if (!adapter
->recv_ctx
) {
1339 dev_err(&adapter
->pdev
->dev
,
1340 "Failed to allocate recv ctx resources for adapter\n");
1341 kfree(adapter
->ahw
);
1342 adapter
->ahw
= NULL
;
1346 /* Initialize interrupt coalesce parameters */
1347 adapter
->ahw
->coal
.flag
= QLCNIC_INTR_DEFAULT
;
1348 adapter
->ahw
->coal
.rx_time_us
= QLCNIC_DEFAULT_INTR_COALESCE_RX_TIME_US
;
1349 adapter
->ahw
->coal
.rx_packets
= QLCNIC_DEFAULT_INTR_COALESCE_RX_PACKETS
;
1354 static void qlcnic_free_adapter_resources(struct qlcnic_adapter
*adapter
)
1356 kfree(adapter
->recv_ctx
);
1357 adapter
->recv_ctx
= NULL
;
1359 if (adapter
->ahw
->fw_dump
.tmpl_hdr
) {
1360 vfree(adapter
->ahw
->fw_dump
.tmpl_hdr
);
1361 adapter
->ahw
->fw_dump
.tmpl_hdr
= NULL
;
1363 kfree(adapter
->ahw
);
1364 adapter
->ahw
= NULL
;
1367 int qlcnic_diag_alloc_res(struct net_device
*netdev
, int test
)
1369 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
1370 struct qlcnic_host_sds_ring
*sds_ring
;
1371 struct qlcnic_host_rds_ring
*rds_ring
;
1375 netif_device_detach(netdev
);
1377 if (netif_running(netdev
))
1378 __qlcnic_down(adapter
, netdev
);
1380 qlcnic_detach(adapter
);
1382 adapter
->max_sds_rings
= 1;
1383 adapter
->diag_test
= test
;
1385 ret
= qlcnic_attach(adapter
);
1387 netif_device_attach(netdev
);
1391 ret
= qlcnic_fw_create_ctx(adapter
);
1393 qlcnic_detach(adapter
);
1394 netif_device_attach(netdev
);
1398 for (ring
= 0; ring
< adapter
->max_rds_rings
; ring
++) {
1399 rds_ring
= &adapter
->recv_ctx
->rds_rings
[ring
];
1400 qlcnic_post_rx_buffers(adapter
, rds_ring
);
1403 if (adapter
->diag_test
== QLCNIC_INTERRUPT_TEST
) {
1404 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
1405 sds_ring
= &adapter
->recv_ctx
->sds_rings
[ring
];
1406 qlcnic_enable_int(sds_ring
);
1410 if (adapter
->diag_test
== QLCNIC_LOOPBACK_TEST
) {
1411 adapter
->ahw
->loopback_state
= 0;
1412 qlcnic_linkevent_request(adapter
, 1);
1415 set_bit(__QLCNIC_DEV_UP
, &adapter
->state
);
1420 /* Reset context in hardware only */
1422 qlcnic_reset_hw_context(struct qlcnic_adapter
*adapter
)
1424 struct net_device
*netdev
= adapter
->netdev
;
1426 if (test_and_set_bit(__QLCNIC_RESETTING
, &adapter
->state
))
1429 netif_device_detach(netdev
);
1431 qlcnic_down(adapter
, netdev
);
1433 qlcnic_up(adapter
, netdev
);
1435 netif_device_attach(netdev
);
1437 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
1442 qlcnic_reset_context(struct qlcnic_adapter
*adapter
)
1445 struct net_device
*netdev
= adapter
->netdev
;
1447 if (test_and_set_bit(__QLCNIC_RESETTING
, &adapter
->state
))
1450 if (adapter
->is_up
== QLCNIC_ADAPTER_UP_MAGIC
) {
1452 netif_device_detach(netdev
);
1454 if (netif_running(netdev
))
1455 __qlcnic_down(adapter
, netdev
);
1457 qlcnic_detach(adapter
);
1459 if (netif_running(netdev
)) {
1460 err
= qlcnic_attach(adapter
);
1462 __qlcnic_up(adapter
, netdev
);
1465 netif_device_attach(netdev
);
1468 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
1473 qlcnic_setup_netdev(struct qlcnic_adapter
*adapter
,
1474 struct net_device
*netdev
, u8 pci_using_dac
)
1477 struct pci_dev
*pdev
= adapter
->pdev
;
1479 adapter
->mc_enabled
= 0;
1480 adapter
->max_mc_count
= 38;
1482 netdev
->netdev_ops
= &qlcnic_netdev_ops
;
1483 netdev
->watchdog_timeo
= 5*HZ
;
1485 qlcnic_change_mtu(netdev
, netdev
->mtu
);
1487 SET_ETHTOOL_OPS(netdev
, &qlcnic_ethtool_ops
);
1489 netdev
->hw_features
= NETIF_F_SG
| NETIF_F_IP_CSUM
|
1490 NETIF_F_IPV6_CSUM
| NETIF_F_RXCSUM
;
1492 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_TSO
)
1493 netdev
->hw_features
|= NETIF_F_TSO
| NETIF_F_TSO6
;
1495 netdev
->hw_features
|= NETIF_F_HIGHDMA
;
1497 netdev
->vlan_features
= netdev
->hw_features
;
1499 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_FVLANTX
)
1500 netdev
->hw_features
|= NETIF_F_HW_VLAN_TX
;
1501 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_HW_LRO
)
1502 netdev
->hw_features
|= NETIF_F_LRO
;
1504 netdev
->features
|= netdev
->hw_features
|
1505 NETIF_F_HW_VLAN_RX
| NETIF_F_HW_VLAN_FILTER
;
1507 netdev
->irq
= adapter
->msix_entries
[0].vector
;
1509 err
= register_netdev(netdev
);
1511 dev_err(&pdev
->dev
, "failed to register net device\n");
1518 static int qlcnic_set_dma_mask(struct pci_dev
*pdev
, u8
*pci_using_dac
)
1520 if (!pci_set_dma_mask(pdev
, DMA_BIT_MASK(64)) &&
1521 !pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(64)))
1523 else if (!pci_set_dma_mask(pdev
, DMA_BIT_MASK(32)) &&
1524 !pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(32)))
1527 dev_err(&pdev
->dev
, "Unable to set DMA mask, aborting\n");
1535 qlcnic_alloc_msix_entries(struct qlcnic_adapter
*adapter
, u16 count
)
1537 adapter
->msix_entries
= kcalloc(count
, sizeof(struct msix_entry
),
1540 if (adapter
->msix_entries
)
1543 dev_err(&adapter
->pdev
->dev
, "failed allocating msix_entries\n");
1547 static int __devinit
1548 qlcnic_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
1550 struct net_device
*netdev
= NULL
;
1551 struct qlcnic_adapter
*adapter
= NULL
;
1553 uint8_t revision_id
;
1554 uint8_t pci_using_dac
;
1555 char brd_name
[QLCNIC_MAX_BOARD_NAME_LEN
];
1557 err
= pci_enable_device(pdev
);
1561 if (!(pci_resource_flags(pdev
, 0) & IORESOURCE_MEM
)) {
1563 goto err_out_disable_pdev
;
1566 err
= qlcnic_set_dma_mask(pdev
, &pci_using_dac
);
1568 goto err_out_disable_pdev
;
1570 err
= pci_request_regions(pdev
, qlcnic_driver_name
);
1572 goto err_out_disable_pdev
;
1574 pci_set_master(pdev
);
1575 pci_enable_pcie_error_reporting(pdev
);
1577 netdev
= alloc_etherdev(sizeof(struct qlcnic_adapter
));
1579 dev_err(&pdev
->dev
, "failed to allocate net_device\n");
1581 goto err_out_free_res
;
1584 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
1586 adapter
= netdev_priv(netdev
);
1587 adapter
->netdev
= netdev
;
1588 adapter
->pdev
= pdev
;
1590 if (qlcnic_alloc_adapter_resources(adapter
))
1591 goto err_out_free_netdev
;
1593 adapter
->dev_rst_time
= jiffies
;
1594 revision_id
= pdev
->revision
;
1595 adapter
->ahw
->revision_id
= revision_id
;
1596 adapter
->mac_learn
= qlcnic_mac_learn
;
1598 rwlock_init(&adapter
->ahw
->crb_lock
);
1599 mutex_init(&adapter
->ahw
->mem_lock
);
1601 spin_lock_init(&adapter
->tx_clean_lock
);
1602 INIT_LIST_HEAD(&adapter
->mac_list
);
1604 err
= qlcnic_setup_pci_map(adapter
);
1606 goto err_out_free_hw
;
1608 /* This will be reset for mezz cards */
1609 adapter
->portnum
= adapter
->ahw
->pci_func
;
1611 err
= qlcnic_get_board_info(adapter
);
1613 dev_err(&pdev
->dev
, "Error getting board config info.\n");
1614 goto err_out_iounmap
;
1617 err
= qlcnic_setup_idc_param(adapter
);
1619 goto err_out_iounmap
;
1621 adapter
->flags
|= QLCNIC_NEED_FLR
;
1623 err
= adapter
->nic_ops
->start_firmware(adapter
);
1625 dev_err(&pdev
->dev
, "Loading fw failed.Please Reboot\n");
1626 goto err_out_decr_ref
;
1629 if (qlcnic_read_mac_addr(adapter
))
1630 dev_warn(&pdev
->dev
, "failed to read mac addr\n");
1632 if (adapter
->portnum
== 0) {
1633 get_brd_name(adapter
, brd_name
);
1635 pr_info("%s: %s Board Chip rev 0x%x\n",
1636 module_name(THIS_MODULE
),
1637 brd_name
, adapter
->ahw
->revision_id
);
1640 qlcnic_clear_stats(adapter
);
1642 err
= qlcnic_alloc_msix_entries(adapter
, adapter
->max_rx_ques
);
1644 goto err_out_decr_ref
;
1646 qlcnic_setup_intr(adapter
);
1648 err
= qlcnic_setup_netdev(adapter
, netdev
, pci_using_dac
);
1650 goto err_out_disable_msi
;
1652 pci_set_drvdata(pdev
, adapter
);
1654 qlcnic_schedule_work(adapter
, qlcnic_fw_poll_work
, FW_POLL_DELAY
);
1656 switch (adapter
->ahw
->port_type
) {
1658 dev_info(&adapter
->pdev
->dev
, "%s: GbE port initialized\n",
1659 adapter
->netdev
->name
);
1662 dev_info(&adapter
->pdev
->dev
, "%s: XGbE port initialized\n",
1663 adapter
->netdev
->name
);
1667 if (adapter
->mac_learn
)
1668 qlcnic_alloc_lb_filters_mem(adapter
);
1670 qlcnic_create_diag_entries(adapter
);
1674 err_out_disable_msi
:
1675 qlcnic_teardown_intr(adapter
);
1676 kfree(adapter
->msix_entries
);
1679 qlcnic_clr_all_drv_state(adapter
, 0);
1682 qlcnic_cleanup_pci_map(adapter
);
1685 qlcnic_free_adapter_resources(adapter
);
1687 err_out_free_netdev
:
1688 free_netdev(netdev
);
1691 pci_release_regions(pdev
);
1693 err_out_disable_pdev
:
1694 pci_set_drvdata(pdev
, NULL
);
1695 pci_disable_device(pdev
);
1699 static void __devexit
qlcnic_remove(struct pci_dev
*pdev
)
1701 struct qlcnic_adapter
*adapter
;
1702 struct net_device
*netdev
;
1704 adapter
= pci_get_drvdata(pdev
);
1705 if (adapter
== NULL
)
1708 netdev
= adapter
->netdev
;
1710 qlcnic_cancel_fw_work(adapter
);
1712 unregister_netdev(netdev
);
1714 qlcnic_detach(adapter
);
1716 if (adapter
->npars
!= NULL
)
1717 kfree(adapter
->npars
);
1718 if (adapter
->eswitch
!= NULL
)
1719 kfree(adapter
->eswitch
);
1721 qlcnic_clr_all_drv_state(adapter
, 0);
1723 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
1725 qlcnic_free_lb_filters_mem(adapter
);
1727 qlcnic_teardown_intr(adapter
);
1728 kfree(adapter
->msix_entries
);
1730 qlcnic_remove_diag_entries(adapter
);
1732 qlcnic_cleanup_pci_map(adapter
);
1734 qlcnic_release_firmware(adapter
);
1736 pci_disable_pcie_error_reporting(pdev
);
1737 pci_release_regions(pdev
);
1738 pci_disable_device(pdev
);
1739 pci_set_drvdata(pdev
, NULL
);
1741 qlcnic_free_adapter_resources(adapter
);
1742 free_netdev(netdev
);
1744 static int __qlcnic_shutdown(struct pci_dev
*pdev
)
1746 struct qlcnic_adapter
*adapter
= pci_get_drvdata(pdev
);
1747 struct net_device
*netdev
= adapter
->netdev
;
1750 netif_device_detach(netdev
);
1752 qlcnic_cancel_fw_work(adapter
);
1754 if (netif_running(netdev
))
1755 qlcnic_down(adapter
, netdev
);
1757 qlcnic_clr_all_drv_state(adapter
, 0);
1759 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
1761 retval
= pci_save_state(pdev
);
1765 if (qlcnic_wol_supported(adapter
)) {
1766 pci_enable_wake(pdev
, PCI_D3cold
, 1);
1767 pci_enable_wake(pdev
, PCI_D3hot
, 1);
1773 static void qlcnic_shutdown(struct pci_dev
*pdev
)
1775 if (__qlcnic_shutdown(pdev
))
1778 pci_disable_device(pdev
);
1783 qlcnic_suspend(struct pci_dev
*pdev
, pm_message_t state
)
1787 retval
= __qlcnic_shutdown(pdev
);
1791 pci_set_power_state(pdev
, pci_choose_state(pdev
, state
));
1796 qlcnic_resume(struct pci_dev
*pdev
)
1798 struct qlcnic_adapter
*adapter
= pci_get_drvdata(pdev
);
1799 struct net_device
*netdev
= adapter
->netdev
;
1802 err
= pci_enable_device(pdev
);
1806 pci_set_power_state(pdev
, PCI_D0
);
1807 pci_set_master(pdev
);
1808 pci_restore_state(pdev
);
1810 err
= adapter
->nic_ops
->start_firmware(adapter
);
1812 dev_err(&pdev
->dev
, "failed to start firmware\n");
1816 if (netif_running(netdev
)) {
1817 err
= qlcnic_up(adapter
, netdev
);
1821 qlcnic_restore_indev_addr(netdev
, NETDEV_UP
);
1824 netif_device_attach(netdev
);
1825 qlcnic_schedule_work(adapter
, qlcnic_fw_poll_work
, FW_POLL_DELAY
);
1830 static int qlcnic_open(struct net_device
*netdev
)
1832 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
1835 netif_carrier_off(netdev
);
1837 err
= qlcnic_attach(adapter
);
1841 err
= __qlcnic_up(adapter
, netdev
);
1845 netif_start_queue(netdev
);
1850 qlcnic_detach(adapter
);
1855 * qlcnic_close - Disables a network interface entry point
1857 static int qlcnic_close(struct net_device
*netdev
)
1859 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
1861 __qlcnic_down(adapter
, netdev
);
1865 void qlcnic_alloc_lb_filters_mem(struct qlcnic_adapter
*adapter
)
1870 if (adapter
->fhash
.fmax
&& adapter
->fhash
.fhead
)
1873 spin_lock_init(&adapter
->mac_learn_lock
);
1875 head
= kcalloc(QLCNIC_LB_MAX_FILTERS
, sizeof(struct hlist_head
),
1880 adapter
->fhash
.fmax
= QLCNIC_LB_MAX_FILTERS
;
1881 adapter
->fhash
.fhead
= head
;
1883 for (i
= 0; i
< adapter
->fhash
.fmax
; i
++)
1884 INIT_HLIST_HEAD(&adapter
->fhash
.fhead
[i
]);
1887 static void qlcnic_free_lb_filters_mem(struct qlcnic_adapter
*adapter
)
1889 if (adapter
->fhash
.fmax
&& adapter
->fhash
.fhead
)
1890 kfree(adapter
->fhash
.fhead
);
1892 adapter
->fhash
.fhead
= NULL
;
1893 adapter
->fhash
.fmax
= 0;
1896 static void qlcnic_change_filter(struct qlcnic_adapter
*adapter
,
1897 u64 uaddr
, __le16 vlan_id
, struct qlcnic_host_tx_ring
*tx_ring
)
1899 struct cmd_desc_type0
*hwdesc
;
1900 struct qlcnic_nic_req
*req
;
1901 struct qlcnic_mac_req
*mac_req
;
1902 struct qlcnic_vlan_req
*vlan_req
;
1906 producer
= tx_ring
->producer
;
1907 hwdesc
= &tx_ring
->desc_head
[tx_ring
->producer
];
1909 req
= (struct qlcnic_nic_req
*)hwdesc
;
1910 memset(req
, 0, sizeof(struct qlcnic_nic_req
));
1911 req
->qhdr
= cpu_to_le64(QLCNIC_REQUEST
<< 23);
1913 word
= QLCNIC_MAC_EVENT
| ((u64
)(adapter
->portnum
) << 16);
1914 req
->req_hdr
= cpu_to_le64(word
);
1916 mac_req
= (struct qlcnic_mac_req
*)&(req
->words
[0]);
1917 mac_req
->op
= vlan_id
? QLCNIC_MAC_VLAN_ADD
: QLCNIC_MAC_ADD
;
1918 memcpy(mac_req
->mac_addr
, &uaddr
, ETH_ALEN
);
1920 vlan_req
= (struct qlcnic_vlan_req
*)&req
->words
[1];
1921 vlan_req
->vlan_id
= vlan_id
;
1923 tx_ring
->producer
= get_next_index(producer
, tx_ring
->num_desc
);
1927 #define QLCNIC_MAC_HASH(MAC)\
1928 ((((MAC) & 0x70000) >> 0x10) | (((MAC) & 0x70000000000ULL) >> 0x25))
1931 qlcnic_send_filter(struct qlcnic_adapter
*adapter
,
1932 struct qlcnic_host_tx_ring
*tx_ring
,
1933 struct cmd_desc_type0
*first_desc
,
1934 struct sk_buff
*skb
)
1936 struct ethhdr
*phdr
= (struct ethhdr
*)(skb
->data
);
1937 struct qlcnic_filter
*fil
, *tmp_fil
;
1938 struct hlist_node
*tmp_hnode
, *n
;
1939 struct hlist_head
*head
;
1944 if (!compare_ether_addr(phdr
->h_source
, adapter
->mac_addr
))
1947 if (adapter
->fhash
.fnum
>= adapter
->fhash
.fmax
)
1950 /* Only NPAR capable devices support vlan based learning*/
1951 if (adapter
->flags
& QLCNIC_ESWITCH_ENABLED
)
1952 vlan_id
= first_desc
->vlan_TCI
;
1953 memcpy(&src_addr
, phdr
->h_source
, ETH_ALEN
);
1954 hindex
= QLCNIC_MAC_HASH(src_addr
) & (QLCNIC_LB_MAX_FILTERS
- 1);
1955 head
= &(adapter
->fhash
.fhead
[hindex
]);
1957 hlist_for_each_entry_safe(tmp_fil
, tmp_hnode
, n
, head
, fnode
) {
1958 if (!memcmp(tmp_fil
->faddr
, &src_addr
, ETH_ALEN
) &&
1959 tmp_fil
->vlan_id
== vlan_id
) {
1962 (QLCNIC_READD_AGE
* HZ
+ tmp_fil
->ftime
))
1963 qlcnic_change_filter(adapter
, src_addr
, vlan_id
,
1965 tmp_fil
->ftime
= jiffies
;
1970 fil
= kzalloc(sizeof(struct qlcnic_filter
), GFP_ATOMIC
);
1974 qlcnic_change_filter(adapter
, src_addr
, vlan_id
, tx_ring
);
1976 fil
->ftime
= jiffies
;
1977 fil
->vlan_id
= vlan_id
;
1978 memcpy(fil
->faddr
, &src_addr
, ETH_ALEN
);
1979 spin_lock(&adapter
->mac_learn_lock
);
1980 hlist_add_head(&(fil
->fnode
), head
);
1981 adapter
->fhash
.fnum
++;
1982 spin_unlock(&adapter
->mac_learn_lock
);
1986 qlcnic_tx_pkt(struct qlcnic_adapter
*adapter
,
1987 struct cmd_desc_type0
*first_desc
,
1988 struct sk_buff
*skb
)
1990 u8 opcode
= 0, hdr_len
= 0;
1991 u16 flags
= 0, vlan_tci
= 0;
1992 int copied
, offset
, copy_len
;
1993 struct cmd_desc_type0
*hwdesc
;
1994 struct vlan_ethhdr
*vh
;
1995 struct qlcnic_host_tx_ring
*tx_ring
= adapter
->tx_ring
;
1996 u16 protocol
= ntohs(skb
->protocol
);
1997 u32 producer
= tx_ring
->producer
;
1999 if (protocol
== ETH_P_8021Q
) {
2000 vh
= (struct vlan_ethhdr
*)skb
->data
;
2001 flags
= FLAGS_VLAN_TAGGED
;
2002 vlan_tci
= vh
->h_vlan_TCI
;
2003 } else if (vlan_tx_tag_present(skb
)) {
2004 flags
= FLAGS_VLAN_OOB
;
2005 vlan_tci
= vlan_tx_tag_get(skb
);
2007 if (unlikely(adapter
->pvid
)) {
2008 if (vlan_tci
&& !(adapter
->flags
& QLCNIC_TAGGING_ENABLED
))
2010 if (vlan_tci
&& (adapter
->flags
& QLCNIC_TAGGING_ENABLED
))
2013 flags
= FLAGS_VLAN_OOB
;
2014 vlan_tci
= adapter
->pvid
;
2017 qlcnic_set_tx_vlan_tci(first_desc
, vlan_tci
);
2018 qlcnic_set_tx_flags_opcode(first_desc
, flags
, opcode
);
2020 if (*(skb
->data
) & BIT_0
) {
2022 memcpy(&first_desc
->eth_addr
, skb
->data
, ETH_ALEN
);
2024 opcode
= TX_ETHER_PKT
;
2025 if ((adapter
->netdev
->features
& (NETIF_F_TSO
| NETIF_F_TSO6
)) &&
2026 skb_shinfo(skb
)->gso_size
> 0) {
2028 hdr_len
= skb_transport_offset(skb
) + tcp_hdrlen(skb
);
2030 first_desc
->mss
= cpu_to_le16(skb_shinfo(skb
)->gso_size
);
2031 first_desc
->total_hdr_length
= hdr_len
;
2033 opcode
= (protocol
== ETH_P_IPV6
) ? TX_TCP_LSO6
: TX_TCP_LSO
;
2035 /* For LSO, we need to copy the MAC/IP/TCP headers into
2036 * the descriptor ring */
2040 if (flags
& FLAGS_VLAN_OOB
) {
2041 first_desc
->total_hdr_length
+= VLAN_HLEN
;
2042 first_desc
->tcp_hdr_offset
= VLAN_HLEN
;
2043 first_desc
->ip_hdr_offset
= VLAN_HLEN
;
2044 /* Only in case of TSO on vlan device */
2045 flags
|= FLAGS_VLAN_TAGGED
;
2047 /* Create a TSO vlan header template for firmware */
2049 hwdesc
= &tx_ring
->desc_head
[producer
];
2050 tx_ring
->cmd_buf_arr
[producer
].skb
= NULL
;
2052 copy_len
= min((int)sizeof(struct cmd_desc_type0
) -
2053 offset
, hdr_len
+ VLAN_HLEN
);
2055 vh
= (struct vlan_ethhdr
*)((char *) hwdesc
+ 2);
2056 skb_copy_from_linear_data(skb
, vh
, 12);
2057 vh
->h_vlan_proto
= htons(ETH_P_8021Q
);
2058 vh
->h_vlan_TCI
= htons(vlan_tci
);
2060 skb_copy_from_linear_data_offset(skb
, 12,
2061 (char *)vh
+ 16, copy_len
- 16);
2063 copied
= copy_len
- VLAN_HLEN
;
2066 producer
= get_next_index(producer
, tx_ring
->num_desc
);
2069 while (copied
< hdr_len
) {
2071 copy_len
= min((int)sizeof(struct cmd_desc_type0
) -
2072 offset
, (hdr_len
- copied
));
2074 hwdesc
= &tx_ring
->desc_head
[producer
];
2075 tx_ring
->cmd_buf_arr
[producer
].skb
= NULL
;
2077 skb_copy_from_linear_data_offset(skb
, copied
,
2078 (char *) hwdesc
+ offset
, copy_len
);
2083 producer
= get_next_index(producer
, tx_ring
->num_desc
);
2086 tx_ring
->producer
= producer
;
2088 adapter
->stats
.lso_frames
++;
2090 } else if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
2093 if (protocol
== ETH_P_IP
) {
2094 l4proto
= ip_hdr(skb
)->protocol
;
2096 if (l4proto
== IPPROTO_TCP
)
2097 opcode
= TX_TCP_PKT
;
2098 else if (l4proto
== IPPROTO_UDP
)
2099 opcode
= TX_UDP_PKT
;
2100 } else if (protocol
== ETH_P_IPV6
) {
2101 l4proto
= ipv6_hdr(skb
)->nexthdr
;
2103 if (l4proto
== IPPROTO_TCP
)
2104 opcode
= TX_TCPV6_PKT
;
2105 else if (l4proto
== IPPROTO_UDP
)
2106 opcode
= TX_UDPV6_PKT
;
2109 first_desc
->tcp_hdr_offset
+= skb_transport_offset(skb
);
2110 first_desc
->ip_hdr_offset
+= skb_network_offset(skb
);
2111 qlcnic_set_tx_flags_opcode(first_desc
, flags
, opcode
);
2117 qlcnic_map_tx_skb(struct pci_dev
*pdev
,
2118 struct sk_buff
*skb
, struct qlcnic_cmd_buffer
*pbuf
)
2120 struct qlcnic_skb_frag
*nf
;
2121 struct skb_frag_struct
*frag
;
2125 nr_frags
= skb_shinfo(skb
)->nr_frags
;
2126 nf
= &pbuf
->frag_array
[0];
2128 map
= pci_map_single(pdev
, skb
->data
,
2129 skb_headlen(skb
), PCI_DMA_TODEVICE
);
2130 if (pci_dma_mapping_error(pdev
, map
))
2134 nf
->length
= skb_headlen(skb
);
2136 for (i
= 0; i
< nr_frags
; i
++) {
2137 frag
= &skb_shinfo(skb
)->frags
[i
];
2138 nf
= &pbuf
->frag_array
[i
+1];
2140 map
= skb_frag_dma_map(&pdev
->dev
, frag
, 0, skb_frag_size(frag
),
2142 if (dma_mapping_error(&pdev
->dev
, map
))
2146 nf
->length
= skb_frag_size(frag
);
2153 nf
= &pbuf
->frag_array
[i
+1];
2154 pci_unmap_page(pdev
, nf
->dma
, nf
->length
, PCI_DMA_TODEVICE
);
2157 nf
= &pbuf
->frag_array
[0];
2158 pci_unmap_single(pdev
, nf
->dma
, skb_headlen(skb
), PCI_DMA_TODEVICE
);
2165 qlcnic_unmap_buffers(struct pci_dev
*pdev
, struct sk_buff
*skb
,
2166 struct qlcnic_cmd_buffer
*pbuf
)
2168 struct qlcnic_skb_frag
*nf
= &pbuf
->frag_array
[0];
2169 int nr_frags
= skb_shinfo(skb
)->nr_frags
;
2172 for (i
= 0; i
< nr_frags
; i
++) {
2173 nf
= &pbuf
->frag_array
[i
+1];
2174 pci_unmap_page(pdev
, nf
->dma
, nf
->length
, PCI_DMA_TODEVICE
);
2177 nf
= &pbuf
->frag_array
[0];
2178 pci_unmap_single(pdev
, nf
->dma
, skb_headlen(skb
), PCI_DMA_TODEVICE
);
2183 qlcnic_clear_cmddesc(u64
*desc
)
2191 qlcnic_xmit_frame(struct sk_buff
*skb
, struct net_device
*netdev
)
2193 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
2194 struct qlcnic_host_tx_ring
*tx_ring
= adapter
->tx_ring
;
2195 struct qlcnic_cmd_buffer
*pbuf
;
2196 struct qlcnic_skb_frag
*buffrag
;
2197 struct cmd_desc_type0
*hwdesc
, *first_desc
;
2198 struct pci_dev
*pdev
;
2199 struct ethhdr
*phdr
;
2205 u32 num_txd
= tx_ring
->num_desc
;
2207 if (!test_bit(__QLCNIC_DEV_UP
, &adapter
->state
)) {
2208 netif_stop_queue(netdev
);
2209 return NETDEV_TX_BUSY
;
2212 if (adapter
->flags
& QLCNIC_MACSPOOF
) {
2213 phdr
= (struct ethhdr
*)skb
->data
;
2214 if (compare_ether_addr(phdr
->h_source
,
2219 frag_count
= skb_shinfo(skb
)->nr_frags
+ 1;
2220 /* 14 frags supported for normal packet and
2221 * 32 frags supported for TSO packet
2223 if (!skb_is_gso(skb
) && frag_count
> QLCNIC_MAX_FRAGS_PER_TX
) {
2225 for (i
= 0; i
< (frag_count
- QLCNIC_MAX_FRAGS_PER_TX
); i
++)
2226 delta
+= skb_frag_size(&skb_shinfo(skb
)->frags
[i
]);
2228 if (!__pskb_pull_tail(skb
, delta
))
2231 frag_count
= 1 + skb_shinfo(skb
)->nr_frags
;
2234 if (unlikely(qlcnic_tx_avail(tx_ring
) <= TX_STOP_THRESH
)) {
2235 netif_stop_queue(netdev
);
2236 if (qlcnic_tx_avail(tx_ring
) > TX_STOP_THRESH
)
2237 netif_start_queue(netdev
);
2239 adapter
->stats
.xmit_off
++;
2240 return NETDEV_TX_BUSY
;
2244 producer
= tx_ring
->producer
;
2245 pbuf
= &tx_ring
->cmd_buf_arr
[producer
];
2247 pdev
= adapter
->pdev
;
2249 first_desc
= hwdesc
= &tx_ring
->desc_head
[producer
];
2250 qlcnic_clear_cmddesc((u64
*)hwdesc
);
2252 if (qlcnic_map_tx_skb(pdev
, skb
, pbuf
)) {
2253 adapter
->stats
.tx_dma_map_error
++;
2258 pbuf
->frag_count
= frag_count
;
2260 qlcnic_set_tx_frags_len(first_desc
, frag_count
, skb
->len
);
2261 qlcnic_set_tx_port(first_desc
, adapter
->portnum
);
2263 for (i
= 0; i
< frag_count
; i
++) {
2267 if ((k
== 0) && (i
> 0)) {
2268 /* move to next desc.*/
2269 producer
= get_next_index(producer
, num_txd
);
2270 hwdesc
= &tx_ring
->desc_head
[producer
];
2271 qlcnic_clear_cmddesc((u64
*)hwdesc
);
2272 tx_ring
->cmd_buf_arr
[producer
].skb
= NULL
;
2275 buffrag
= &pbuf
->frag_array
[i
];
2277 hwdesc
->buffer_length
[k
] = cpu_to_le16(buffrag
->length
);
2280 hwdesc
->addr_buffer1
= cpu_to_le64(buffrag
->dma
);
2283 hwdesc
->addr_buffer2
= cpu_to_le64(buffrag
->dma
);
2286 hwdesc
->addr_buffer3
= cpu_to_le64(buffrag
->dma
);
2289 hwdesc
->addr_buffer4
= cpu_to_le64(buffrag
->dma
);
2294 tx_ring
->producer
= get_next_index(producer
, num_txd
);
2297 if (unlikely(qlcnic_tx_pkt(adapter
, first_desc
, skb
)))
2300 if (adapter
->mac_learn
)
2301 qlcnic_send_filter(adapter
, tx_ring
, first_desc
, skb
);
2303 adapter
->stats
.txbytes
+= skb
->len
;
2304 adapter
->stats
.xmitcalled
++;
2306 qlcnic_update_cmd_producer(adapter
, tx_ring
);
2308 return NETDEV_TX_OK
;
2311 qlcnic_unmap_buffers(pdev
, skb
, pbuf
);
2313 adapter
->stats
.txdropped
++;
2314 dev_kfree_skb_any(skb
);
2315 return NETDEV_TX_OK
;
2318 static int qlcnic_check_temp(struct qlcnic_adapter
*adapter
)
2320 struct net_device
*netdev
= adapter
->netdev
;
2321 u32 temp
, temp_state
, temp_val
;
2324 temp
= QLCRD32(adapter
, CRB_TEMP_STATE
);
2326 temp_state
= qlcnic_get_temp_state(temp
);
2327 temp_val
= qlcnic_get_temp_val(temp
);
2329 if (temp_state
== QLCNIC_TEMP_PANIC
) {
2330 dev_err(&netdev
->dev
,
2331 "Device temperature %d degrees C exceeds"
2332 " maximum allowed. Hardware has been shut down.\n",
2335 } else if (temp_state
== QLCNIC_TEMP_WARN
) {
2336 if (adapter
->temp
== QLCNIC_TEMP_NORMAL
) {
2337 dev_err(&netdev
->dev
,
2338 "Device temperature %d degrees C "
2339 "exceeds operating range."
2340 " Immediate action needed.\n",
2344 if (adapter
->temp
== QLCNIC_TEMP_WARN
) {
2345 dev_info(&netdev
->dev
,
2346 "Device temperature is now %d degrees C"
2347 " in normal range.\n", temp_val
);
2350 adapter
->temp
= temp_state
;
2354 void qlcnic_advert_link_change(struct qlcnic_adapter
*adapter
, int linkup
)
2356 struct net_device
*netdev
= adapter
->netdev
;
2358 if (adapter
->ahw
->linkup
&& !linkup
) {
2359 netdev_info(netdev
, "NIC Link is down\n");
2360 adapter
->ahw
->linkup
= 0;
2361 if (netif_running(netdev
)) {
2362 netif_carrier_off(netdev
);
2363 netif_stop_queue(netdev
);
2365 } else if (!adapter
->ahw
->linkup
&& linkup
) {
2366 netdev_info(netdev
, "NIC Link is up\n");
2367 adapter
->ahw
->linkup
= 1;
2368 if (netif_running(netdev
)) {
2369 netif_carrier_on(netdev
);
2370 netif_wake_queue(netdev
);
2375 static void qlcnic_tx_timeout(struct net_device
*netdev
)
2377 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
2379 if (test_bit(__QLCNIC_RESETTING
, &adapter
->state
))
2382 dev_err(&netdev
->dev
, "transmit timeout, resetting.\n");
2384 if (++adapter
->tx_timeo_cnt
>= QLCNIC_MAX_TX_TIMEOUTS
)
2385 adapter
->need_fw_reset
= 1;
2387 adapter
->reset_context
= 1;
2390 static struct net_device_stats
*qlcnic_get_stats(struct net_device
*netdev
)
2392 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
2393 struct net_device_stats
*stats
= &netdev
->stats
;
2395 stats
->rx_packets
= adapter
->stats
.rx_pkts
+ adapter
->stats
.lro_pkts
;
2396 stats
->tx_packets
= adapter
->stats
.xmitfinished
;
2397 stats
->rx_bytes
= adapter
->stats
.rxbytes
+ adapter
->stats
.lrobytes
;
2398 stats
->tx_bytes
= adapter
->stats
.txbytes
;
2399 stats
->rx_dropped
= adapter
->stats
.rxdropped
;
2400 stats
->tx_dropped
= adapter
->stats
.txdropped
;
2405 static irqreturn_t
qlcnic_clear_legacy_intr(struct qlcnic_adapter
*adapter
)
2409 status
= readl(adapter
->isr_int_vec
);
2411 if (!(status
& adapter
->int_vec_bit
))
2414 /* check interrupt state machine, to be sure */
2415 status
= readl(adapter
->crb_int_state_reg
);
2416 if (!ISR_LEGACY_INT_TRIGGERED(status
))
2419 writel(0xffffffff, adapter
->tgt_status_reg
);
2420 /* read twice to ensure write is flushed */
2421 readl(adapter
->isr_int_vec
);
2422 readl(adapter
->isr_int_vec
);
2427 static irqreturn_t
qlcnic_tmp_intr(int irq
, void *data
)
2429 struct qlcnic_host_sds_ring
*sds_ring
= data
;
2430 struct qlcnic_adapter
*adapter
= sds_ring
->adapter
;
2432 if (adapter
->flags
& QLCNIC_MSIX_ENABLED
)
2434 else if (adapter
->flags
& QLCNIC_MSI_ENABLED
) {
2435 writel(0xffffffff, adapter
->tgt_status_reg
);
2439 if (qlcnic_clear_legacy_intr(adapter
) == IRQ_NONE
)
2443 adapter
->diag_cnt
++;
2444 qlcnic_enable_int(sds_ring
);
2448 static irqreturn_t
qlcnic_intr(int irq
, void *data
)
2450 struct qlcnic_host_sds_ring
*sds_ring
= data
;
2451 struct qlcnic_adapter
*adapter
= sds_ring
->adapter
;
2453 if (qlcnic_clear_legacy_intr(adapter
) == IRQ_NONE
)
2456 napi_schedule(&sds_ring
->napi
);
2461 static irqreturn_t
qlcnic_msi_intr(int irq
, void *data
)
2463 struct qlcnic_host_sds_ring
*sds_ring
= data
;
2464 struct qlcnic_adapter
*adapter
= sds_ring
->adapter
;
2466 /* clear interrupt */
2467 writel(0xffffffff, adapter
->tgt_status_reg
);
2469 napi_schedule(&sds_ring
->napi
);
2473 static irqreturn_t
qlcnic_msix_intr(int irq
, void *data
)
2475 struct qlcnic_host_sds_ring
*sds_ring
= data
;
2477 napi_schedule(&sds_ring
->napi
);
2481 static int qlcnic_process_cmd_ring(struct qlcnic_adapter
*adapter
)
2483 u32 sw_consumer
, hw_consumer
;
2485 struct qlcnic_cmd_buffer
*buffer
;
2486 struct pci_dev
*pdev
= adapter
->pdev
;
2487 struct net_device
*netdev
= adapter
->netdev
;
2488 struct qlcnic_skb_frag
*frag
;
2490 struct qlcnic_host_tx_ring
*tx_ring
= adapter
->tx_ring
;
2492 if (!spin_trylock(&adapter
->tx_clean_lock
))
2495 sw_consumer
= tx_ring
->sw_consumer
;
2496 hw_consumer
= le32_to_cpu(*(tx_ring
->hw_consumer
));
2498 while (sw_consumer
!= hw_consumer
) {
2499 buffer
= &tx_ring
->cmd_buf_arr
[sw_consumer
];
2501 frag
= &buffer
->frag_array
[0];
2502 pci_unmap_single(pdev
, frag
->dma
, frag
->length
,
2505 for (i
= 1; i
< buffer
->frag_count
; i
++) {
2507 pci_unmap_page(pdev
, frag
->dma
, frag
->length
,
2512 adapter
->stats
.xmitfinished
++;
2513 dev_kfree_skb_any(buffer
->skb
);
2517 sw_consumer
= get_next_index(sw_consumer
, tx_ring
->num_desc
);
2518 if (++count
>= MAX_STATUS_HANDLE
)
2522 if (count
&& netif_running(netdev
)) {
2523 tx_ring
->sw_consumer
= sw_consumer
;
2527 if (netif_queue_stopped(netdev
) && netif_carrier_ok(netdev
)) {
2528 if (qlcnic_tx_avail(tx_ring
) > TX_STOP_THRESH
) {
2529 netif_wake_queue(netdev
);
2530 adapter
->stats
.xmit_on
++;
2533 adapter
->tx_timeo_cnt
= 0;
2536 * If everything is freed up to consumer then check if the ring is full
2537 * If the ring is full then check if more needs to be freed and
2538 * schedule the call back again.
2540 * This happens when there are 2 CPUs. One could be freeing and the
2541 * other filling it. If the ring is full when we get out of here and
2542 * the card has already interrupted the host then the host can miss the
2545 * There is still a possible race condition and the host could miss an
2546 * interrupt. The card has to take care of this.
2548 hw_consumer
= le32_to_cpu(*(tx_ring
->hw_consumer
));
2549 done
= (sw_consumer
== hw_consumer
);
2550 spin_unlock(&adapter
->tx_clean_lock
);
2555 static int qlcnic_poll(struct napi_struct
*napi
, int budget
)
2557 struct qlcnic_host_sds_ring
*sds_ring
=
2558 container_of(napi
, struct qlcnic_host_sds_ring
, napi
);
2560 struct qlcnic_adapter
*adapter
= sds_ring
->adapter
;
2565 tx_complete
= qlcnic_process_cmd_ring(adapter
);
2567 work_done
= qlcnic_process_rcv_ring(sds_ring
, budget
);
2569 if ((work_done
< budget
) && tx_complete
) {
2570 napi_complete(&sds_ring
->napi
);
2571 if (test_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
2572 qlcnic_enable_int(sds_ring
);
2578 static int qlcnic_rx_poll(struct napi_struct
*napi
, int budget
)
2580 struct qlcnic_host_sds_ring
*sds_ring
=
2581 container_of(napi
, struct qlcnic_host_sds_ring
, napi
);
2583 struct qlcnic_adapter
*adapter
= sds_ring
->adapter
;
2586 work_done
= qlcnic_process_rcv_ring(sds_ring
, budget
);
2588 if (work_done
< budget
) {
2589 napi_complete(&sds_ring
->napi
);
2590 if (test_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
2591 qlcnic_enable_int(sds_ring
);
2597 #ifdef CONFIG_NET_POLL_CONTROLLER
2598 static void qlcnic_poll_controller(struct net_device
*netdev
)
2601 struct qlcnic_host_sds_ring
*sds_ring
;
2602 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
2603 struct qlcnic_recv_context
*recv_ctx
= adapter
->recv_ctx
;
2605 disable_irq(adapter
->irq
);
2606 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
2607 sds_ring
= &recv_ctx
->sds_rings
[ring
];
2608 qlcnic_intr(adapter
->irq
, sds_ring
);
2610 enable_irq(adapter
->irq
);
2615 qlcnic_idc_debug_info(struct qlcnic_adapter
*adapter
, u8 encoding
)
2619 val
= adapter
->portnum
& 0xf;
2620 val
|= encoding
<< 7;
2621 val
|= (jiffies
- adapter
->dev_rst_time
) << 8;
2623 QLCWR32(adapter
, QLCNIC_CRB_DRV_SCRATCH
, val
);
2624 adapter
->dev_rst_time
= jiffies
;
2628 qlcnic_set_drv_state(struct qlcnic_adapter
*adapter
, u8 state
)
2632 WARN_ON(state
!= QLCNIC_DEV_NEED_RESET
&&
2633 state
!= QLCNIC_DEV_NEED_QUISCENT
);
2635 if (qlcnic_api_lock(adapter
))
2638 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_STATE
);
2640 if (state
== QLCNIC_DEV_NEED_RESET
)
2641 QLC_DEV_SET_RST_RDY(val
, adapter
->portnum
);
2642 else if (state
== QLCNIC_DEV_NEED_QUISCENT
)
2643 QLC_DEV_SET_QSCNT_RDY(val
, adapter
->portnum
);
2645 QLCWR32(adapter
, QLCNIC_CRB_DRV_STATE
, val
);
2647 qlcnic_api_unlock(adapter
);
2653 qlcnic_clr_drv_state(struct qlcnic_adapter
*adapter
)
2657 if (qlcnic_api_lock(adapter
))
2660 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_STATE
);
2661 QLC_DEV_CLR_RST_QSCNT(val
, adapter
->portnum
);
2662 QLCWR32(adapter
, QLCNIC_CRB_DRV_STATE
, val
);
2664 qlcnic_api_unlock(adapter
);
2670 qlcnic_clr_all_drv_state(struct qlcnic_adapter
*adapter
, u8 failed
)
2674 if (qlcnic_api_lock(adapter
))
2677 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_ACTIVE
);
2678 QLC_DEV_CLR_REF_CNT(val
, adapter
->portnum
);
2679 QLCWR32(adapter
, QLCNIC_CRB_DRV_ACTIVE
, val
);
2682 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
, QLCNIC_DEV_FAILED
);
2683 dev_info(&adapter
->pdev
->dev
,
2684 "Device state set to Failed. Please Reboot\n");
2685 } else if (!(val
& 0x11111111))
2686 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
, QLCNIC_DEV_COLD
);
2688 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_STATE
);
2689 QLC_DEV_CLR_RST_QSCNT(val
, adapter
->portnum
);
2690 QLCWR32(adapter
, QLCNIC_CRB_DRV_STATE
, val
);
2692 qlcnic_api_unlock(adapter
);
2694 adapter
->fw_fail_cnt
= 0;
2695 adapter
->flags
&= ~QLCNIC_FW_HANG
;
2696 clear_bit(__QLCNIC_START_FW
, &adapter
->state
);
2697 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
2700 /* Grab api lock, before checking state */
2702 qlcnic_check_drv_state(struct qlcnic_adapter
*adapter
)
2704 int act
, state
, active_mask
;
2706 state
= QLCRD32(adapter
, QLCNIC_CRB_DRV_STATE
);
2707 act
= QLCRD32(adapter
, QLCNIC_CRB_DRV_ACTIVE
);
2709 if (adapter
->flags
& QLCNIC_FW_RESET_OWNER
) {
2710 active_mask
= (~(1 << (adapter
->ahw
->pci_func
* 4)));
2711 act
= act
& active_mask
;
2714 if (((state
& 0x11111111) == (act
& 0x11111111)) ||
2715 ((act
& 0x11111111) == ((state
>> 1) & 0x11111111)))
2721 static int qlcnic_check_idc_ver(struct qlcnic_adapter
*adapter
)
2723 u32 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_IDC_VER
);
2725 if (val
!= QLCNIC_DRV_IDC_VER
) {
2726 dev_warn(&adapter
->pdev
->dev
, "IDC Version mismatch, driver's"
2727 " idc ver = %x; reqd = %x\n", QLCNIC_DRV_IDC_VER
, val
);
2734 qlcnic_can_start_firmware(struct qlcnic_adapter
*adapter
)
2736 u32 val
, prev_state
;
2737 u8 dev_init_timeo
= adapter
->dev_init_timeo
;
2738 u8 portnum
= adapter
->portnum
;
2741 if (test_and_clear_bit(__QLCNIC_START_FW
, &adapter
->state
))
2744 if (qlcnic_api_lock(adapter
))
2747 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_ACTIVE
);
2748 if (!(val
& (1 << (portnum
* 4)))) {
2749 QLC_DEV_SET_REF_CNT(val
, portnum
);
2750 QLCWR32(adapter
, QLCNIC_CRB_DRV_ACTIVE
, val
);
2753 prev_state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
);
2754 QLCDB(adapter
, HW
, "Device state = %u\n", prev_state
);
2756 switch (prev_state
) {
2757 case QLCNIC_DEV_COLD
:
2758 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
, QLCNIC_DEV_INITIALIZING
);
2759 QLCWR32(adapter
, QLCNIC_CRB_DRV_IDC_VER
, QLCNIC_DRV_IDC_VER
);
2760 qlcnic_idc_debug_info(adapter
, 0);
2761 qlcnic_api_unlock(adapter
);
2764 case QLCNIC_DEV_READY
:
2765 ret
= qlcnic_check_idc_ver(adapter
);
2766 qlcnic_api_unlock(adapter
);
2769 case QLCNIC_DEV_NEED_RESET
:
2770 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_STATE
);
2771 QLC_DEV_SET_RST_RDY(val
, portnum
);
2772 QLCWR32(adapter
, QLCNIC_CRB_DRV_STATE
, val
);
2775 case QLCNIC_DEV_NEED_QUISCENT
:
2776 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_STATE
);
2777 QLC_DEV_SET_QSCNT_RDY(val
, portnum
);
2778 QLCWR32(adapter
, QLCNIC_CRB_DRV_STATE
, val
);
2781 case QLCNIC_DEV_FAILED
:
2782 dev_err(&adapter
->pdev
->dev
, "Device in failed state.\n");
2783 qlcnic_api_unlock(adapter
);
2786 case QLCNIC_DEV_INITIALIZING
:
2787 case QLCNIC_DEV_QUISCENT
:
2791 qlcnic_api_unlock(adapter
);
2795 prev_state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
);
2797 if (prev_state
== QLCNIC_DEV_QUISCENT
)
2799 } while ((prev_state
!= QLCNIC_DEV_READY
) && --dev_init_timeo
);
2801 if (!dev_init_timeo
) {
2802 dev_err(&adapter
->pdev
->dev
,
2803 "Waiting for device to initialize timeout\n");
2807 if (qlcnic_api_lock(adapter
))
2810 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_STATE
);
2811 QLC_DEV_CLR_RST_QSCNT(val
, portnum
);
2812 QLCWR32(adapter
, QLCNIC_CRB_DRV_STATE
, val
);
2814 ret
= qlcnic_check_idc_ver(adapter
);
2815 qlcnic_api_unlock(adapter
);
2821 qlcnic_fwinit_work(struct work_struct
*work
)
2823 struct qlcnic_adapter
*adapter
= container_of(work
,
2824 struct qlcnic_adapter
, fw_work
.work
);
2825 u32 dev_state
= 0xf;
2828 if (qlcnic_api_lock(adapter
))
2831 dev_state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
);
2832 if (dev_state
== QLCNIC_DEV_QUISCENT
||
2833 dev_state
== QLCNIC_DEV_NEED_QUISCENT
) {
2834 qlcnic_api_unlock(adapter
);
2835 qlcnic_schedule_work(adapter
, qlcnic_fwinit_work
,
2840 if (adapter
->op_mode
== QLCNIC_NON_PRIV_FUNC
) {
2841 qlcnic_api_unlock(adapter
);
2845 if (dev_state
== QLCNIC_DEV_INITIALIZING
||
2846 dev_state
== QLCNIC_DEV_READY
) {
2847 dev_info(&adapter
->pdev
->dev
, "Detected state change from "
2848 "DEV_NEED_RESET, skipping ack check\n");
2849 goto skip_ack_check
;
2852 if (adapter
->fw_wait_cnt
++ > adapter
->reset_ack_timeo
) {
2853 dev_info(&adapter
->pdev
->dev
, "Reset:Failed to get ack %d sec\n",
2854 adapter
->reset_ack_timeo
);
2855 goto skip_ack_check
;
2858 if (!qlcnic_check_drv_state(adapter
)) {
2860 dev_state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
);
2862 if (dev_state
== QLCNIC_DEV_NEED_RESET
) {
2863 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
,
2864 QLCNIC_DEV_INITIALIZING
);
2865 set_bit(__QLCNIC_START_FW
, &adapter
->state
);
2866 QLCDB(adapter
, DRV
, "Restarting fw\n");
2867 qlcnic_idc_debug_info(adapter
, 0);
2868 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_STATE
);
2869 QLC_DEV_SET_RST_RDY(val
, adapter
->portnum
);
2870 QLCWR32(adapter
, QLCNIC_CRB_DRV_STATE
, val
);
2873 qlcnic_api_unlock(adapter
);
2876 if (adapter
->ahw
->fw_dump
.enable
&&
2877 (adapter
->flags
& QLCNIC_FW_RESET_OWNER
)) {
2878 QLCDB(adapter
, DRV
, "Take FW dump\n");
2879 qlcnic_dump_fw(adapter
);
2880 adapter
->flags
|= QLCNIC_FW_HANG
;
2884 adapter
->flags
&= ~QLCNIC_FW_RESET_OWNER
;
2885 if (!adapter
->nic_ops
->start_firmware(adapter
)) {
2886 qlcnic_schedule_work(adapter
, qlcnic_attach_work
, 0);
2887 adapter
->fw_wait_cnt
= 0;
2893 qlcnic_api_unlock(adapter
);
2896 dev_state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
);
2897 QLCDB(adapter
, HW
, "Func waiting: Device state=%u\n", dev_state
);
2899 switch (dev_state
) {
2900 case QLCNIC_DEV_READY
:
2901 if (!adapter
->nic_ops
->start_firmware(adapter
)) {
2902 qlcnic_schedule_work(adapter
, qlcnic_attach_work
, 0);
2903 adapter
->fw_wait_cnt
= 0;
2906 case QLCNIC_DEV_FAILED
:
2909 qlcnic_schedule_work(adapter
,
2910 qlcnic_fwinit_work
, FW_POLL_DELAY
);
2915 dev_err(&adapter
->pdev
->dev
, "Fwinit work failed state=%u "
2916 "fw_wait_cnt=%u\n", dev_state
, adapter
->fw_wait_cnt
);
2917 netif_device_attach(adapter
->netdev
);
2918 qlcnic_clr_all_drv_state(adapter
, 0);
2922 qlcnic_detach_work(struct work_struct
*work
)
2924 struct qlcnic_adapter
*adapter
= container_of(work
,
2925 struct qlcnic_adapter
, fw_work
.work
);
2926 struct net_device
*netdev
= adapter
->netdev
;
2929 netif_device_detach(netdev
);
2931 /* Dont grab rtnl lock during Quiscent mode */
2932 if (adapter
->dev_state
== QLCNIC_DEV_NEED_QUISCENT
) {
2933 if (netif_running(netdev
))
2934 __qlcnic_down(adapter
, netdev
);
2936 qlcnic_down(adapter
, netdev
);
2938 status
= QLCRD32(adapter
, QLCNIC_PEG_HALT_STATUS1
);
2940 if (status
& QLCNIC_RCODE_FATAL_ERROR
) {
2941 dev_err(&adapter
->pdev
->dev
,
2942 "Detaching the device: peg halt status1=0x%x\n",
2945 if (QLCNIC_FWERROR_CODE(status
) == QLCNIC_FWERROR_FAN_FAILURE
) {
2946 dev_err(&adapter
->pdev
->dev
,
2947 "On board active cooling fan failed. "
2948 "Device has been halted.\n");
2949 dev_err(&adapter
->pdev
->dev
,
2950 "Replace the adapter.\n");
2956 if (adapter
->temp
== QLCNIC_TEMP_PANIC
) {
2957 dev_err(&adapter
->pdev
->dev
, "Detaching the device: temp=%d\n",
2962 /* Dont ack if this instance is the reset owner */
2963 if (!(adapter
->flags
& QLCNIC_FW_RESET_OWNER
)) {
2964 if (qlcnic_set_drv_state(adapter
, adapter
->dev_state
)) {
2965 dev_err(&adapter
->pdev
->dev
,
2966 "Failed to set driver state,"
2967 "detaching the device.\n");
2972 adapter
->fw_wait_cnt
= 0;
2974 qlcnic_schedule_work(adapter
, qlcnic_fwinit_work
, FW_POLL_DELAY
);
2979 netif_device_attach(netdev
);
2980 qlcnic_clr_all_drv_state(adapter
, 1);
2983 /*Transit NPAR state to NON Operational */
2985 qlcnic_set_npar_non_operational(struct qlcnic_adapter
*adapter
)
2989 state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_NPAR_STATE
);
2990 if (state
== QLCNIC_DEV_NPAR_NON_OPER
)
2993 if (qlcnic_api_lock(adapter
))
2995 QLCWR32(adapter
, QLCNIC_CRB_DEV_NPAR_STATE
, QLCNIC_DEV_NPAR_NON_OPER
);
2996 qlcnic_api_unlock(adapter
);
2999 /*Transit to RESET state from READY state only */
3001 qlcnic_dev_request_reset(struct qlcnic_adapter
*adapter
)
3005 adapter
->need_fw_reset
= 1;
3006 if (qlcnic_api_lock(adapter
))
3009 state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
);
3011 if (state
== QLCNIC_DEV_READY
) {
3012 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
, QLCNIC_DEV_NEED_RESET
);
3013 adapter
->flags
|= QLCNIC_FW_RESET_OWNER
;
3014 QLCDB(adapter
, DRV
, "NEED_RESET state set\n");
3015 qlcnic_idc_debug_info(adapter
, 0);
3018 QLCWR32(adapter
, QLCNIC_CRB_DEV_NPAR_STATE
, QLCNIC_DEV_NPAR_NON_OPER
);
3019 qlcnic_api_unlock(adapter
);
3022 /* Transit to NPAR READY state from NPAR NOT READY state */
3024 qlcnic_dev_set_npar_ready(struct qlcnic_adapter
*adapter
)
3026 if (qlcnic_api_lock(adapter
))
3029 QLCWR32(adapter
, QLCNIC_CRB_DEV_NPAR_STATE
, QLCNIC_DEV_NPAR_OPER
);
3030 QLCDB(adapter
, DRV
, "NPAR operational state set\n");
3032 qlcnic_api_unlock(adapter
);
3036 qlcnic_schedule_work(struct qlcnic_adapter
*adapter
,
3037 work_func_t func
, int delay
)
3039 if (test_bit(__QLCNIC_AER
, &adapter
->state
))
3042 INIT_DELAYED_WORK(&adapter
->fw_work
, func
);
3043 queue_delayed_work(qlcnic_wq
, &adapter
->fw_work
,
3044 round_jiffies_relative(delay
));
3048 qlcnic_cancel_fw_work(struct qlcnic_adapter
*adapter
)
3050 while (test_and_set_bit(__QLCNIC_RESETTING
, &adapter
->state
))
3053 cancel_delayed_work_sync(&adapter
->fw_work
);
3057 qlcnic_attach_work(struct work_struct
*work
)
3059 struct qlcnic_adapter
*adapter
= container_of(work
,
3060 struct qlcnic_adapter
, fw_work
.work
);
3061 struct net_device
*netdev
= adapter
->netdev
;
3064 if (adapter
->op_mode
!= QLCNIC_MGMT_FUNC
) {
3065 npar_state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_NPAR_STATE
);
3066 if (adapter
->fw_wait_cnt
++ > QLCNIC_DEV_NPAR_OPER_TIMEO
)
3067 qlcnic_clr_all_drv_state(adapter
, 0);
3068 else if (npar_state
!= QLCNIC_DEV_NPAR_OPER
)
3069 qlcnic_schedule_work(adapter
, qlcnic_attach_work
,
3073 QLCDB(adapter
, DRV
, "Waiting for NPAR state to operational\n");
3077 if (netif_running(netdev
)) {
3078 if (qlcnic_up(adapter
, netdev
))
3081 qlcnic_restore_indev_addr(netdev
, NETDEV_UP
);
3085 netif_device_attach(netdev
);
3086 adapter
->fw_fail_cnt
= 0;
3087 adapter
->flags
&= ~QLCNIC_FW_HANG
;
3088 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
3090 if (!qlcnic_clr_drv_state(adapter
))
3091 qlcnic_schedule_work(adapter
, qlcnic_fw_poll_work
,
3096 qlcnic_check_health(struct qlcnic_adapter
*adapter
)
3098 u32 state
= 0, heartbeat
;
3101 if (qlcnic_check_temp(adapter
))
3104 if (adapter
->need_fw_reset
)
3105 qlcnic_dev_request_reset(adapter
);
3107 state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
);
3108 if (state
== QLCNIC_DEV_NEED_RESET
) {
3109 qlcnic_set_npar_non_operational(adapter
);
3110 adapter
->need_fw_reset
= 1;
3111 } else if (state
== QLCNIC_DEV_NEED_QUISCENT
)
3114 heartbeat
= QLCRD32(adapter
, QLCNIC_PEG_ALIVE_COUNTER
);
3115 if (heartbeat
!= adapter
->heartbeat
) {
3116 adapter
->heartbeat
= heartbeat
;
3117 adapter
->fw_fail_cnt
= 0;
3118 if (adapter
->need_fw_reset
)
3121 if (adapter
->reset_context
&& auto_fw_reset
) {
3122 qlcnic_reset_hw_context(adapter
);
3123 adapter
->netdev
->trans_start
= jiffies
;
3129 if (++adapter
->fw_fail_cnt
< FW_FAIL_THRESH
)
3132 adapter
->flags
|= QLCNIC_FW_HANG
;
3134 qlcnic_dev_request_reset(adapter
);
3137 clear_bit(__QLCNIC_FW_ATTACHED
, &adapter
->state
);
3139 dev_err(&adapter
->pdev
->dev
, "firmware hang detected\n");
3140 dev_err(&adapter
->pdev
->dev
, "Dumping hw/fw registers\n"
3141 "PEG_HALT_STATUS1: 0x%x, PEG_HALT_STATUS2: 0x%x,\n"
3142 "PEG_NET_0_PC: 0x%x, PEG_NET_1_PC: 0x%x,\n"
3143 "PEG_NET_2_PC: 0x%x, PEG_NET_3_PC: 0x%x,\n"
3144 "PEG_NET_4_PC: 0x%x\n",
3145 QLCRD32(adapter
, QLCNIC_PEG_HALT_STATUS1
),
3146 QLCRD32(adapter
, QLCNIC_PEG_HALT_STATUS2
),
3147 QLCRD32(adapter
, QLCNIC_CRB_PEG_NET_0
+ 0x3c),
3148 QLCRD32(adapter
, QLCNIC_CRB_PEG_NET_1
+ 0x3c),
3149 QLCRD32(adapter
, QLCNIC_CRB_PEG_NET_2
+ 0x3c),
3150 QLCRD32(adapter
, QLCNIC_CRB_PEG_NET_3
+ 0x3c),
3151 QLCRD32(adapter
, QLCNIC_CRB_PEG_NET_4
+ 0x3c));
3152 peg_status
= QLCRD32(adapter
, QLCNIC_PEG_HALT_STATUS1
);
3153 if (LSW(MSB(peg_status
)) == 0x67)
3154 dev_err(&adapter
->pdev
->dev
,
3155 "Firmware aborted with error code 0x00006700. "
3156 "Device is being reset.\n");
3158 adapter
->dev_state
= (state
== QLCNIC_DEV_NEED_QUISCENT
) ? state
:
3159 QLCNIC_DEV_NEED_RESET
;
3161 if (auto_fw_reset
&&
3162 !test_and_set_bit(__QLCNIC_RESETTING
, &adapter
->state
)) {
3164 qlcnic_schedule_work(adapter
, qlcnic_detach_work
, 0);
3165 QLCDB(adapter
, DRV
, "fw recovery scheduled.\n");
3172 qlcnic_fw_poll_work(struct work_struct
*work
)
3174 struct qlcnic_adapter
*adapter
= container_of(work
,
3175 struct qlcnic_adapter
, fw_work
.work
);
3177 if (test_bit(__QLCNIC_RESETTING
, &adapter
->state
))
3181 if (qlcnic_check_health(adapter
))
3184 if (adapter
->fhash
.fnum
)
3185 qlcnic_prune_lb_filters(adapter
);
3188 qlcnic_schedule_work(adapter
, qlcnic_fw_poll_work
, FW_POLL_DELAY
);
3191 static int qlcnic_is_first_func(struct pci_dev
*pdev
)
3193 struct pci_dev
*oth_pdev
;
3194 int val
= pdev
->devfn
;
3197 oth_pdev
= pci_get_domain_bus_and_slot(pci_domain_nr
3198 (pdev
->bus
), pdev
->bus
->number
,
3199 PCI_DEVFN(PCI_SLOT(pdev
->devfn
), val
));
3203 if (oth_pdev
->current_state
!= PCI_D3cold
) {
3204 pci_dev_put(oth_pdev
);
3207 pci_dev_put(oth_pdev
);
3212 static int qlcnic_attach_func(struct pci_dev
*pdev
)
3214 int err
, first_func
;
3215 struct qlcnic_adapter
*adapter
= pci_get_drvdata(pdev
);
3216 struct net_device
*netdev
= adapter
->netdev
;
3218 pdev
->error_state
= pci_channel_io_normal
;
3220 err
= pci_enable_device(pdev
);
3224 pci_set_power_state(pdev
, PCI_D0
);
3225 pci_set_master(pdev
);
3226 pci_restore_state(pdev
);
3228 first_func
= qlcnic_is_first_func(pdev
);
3230 if (qlcnic_api_lock(adapter
))
3233 if (adapter
->op_mode
!= QLCNIC_NON_PRIV_FUNC
&& first_func
) {
3234 adapter
->need_fw_reset
= 1;
3235 set_bit(__QLCNIC_START_FW
, &adapter
->state
);
3236 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
, QLCNIC_DEV_INITIALIZING
);
3237 QLCDB(adapter
, DRV
, "Restarting fw\n");
3239 qlcnic_api_unlock(adapter
);
3241 err
= adapter
->nic_ops
->start_firmware(adapter
);
3245 qlcnic_clr_drv_state(adapter
);
3246 qlcnic_setup_intr(adapter
);
3248 if (netif_running(netdev
)) {
3249 err
= qlcnic_attach(adapter
);
3251 qlcnic_clr_all_drv_state(adapter
, 1);
3252 clear_bit(__QLCNIC_AER
, &adapter
->state
);
3253 netif_device_attach(netdev
);
3257 err
= qlcnic_up(adapter
, netdev
);
3261 qlcnic_restore_indev_addr(netdev
, NETDEV_UP
);
3264 netif_device_attach(netdev
);
3268 static pci_ers_result_t
qlcnic_io_error_detected(struct pci_dev
*pdev
,
3269 pci_channel_state_t state
)
3271 struct qlcnic_adapter
*adapter
= pci_get_drvdata(pdev
);
3272 struct net_device
*netdev
= adapter
->netdev
;
3274 if (state
== pci_channel_io_perm_failure
)
3275 return PCI_ERS_RESULT_DISCONNECT
;
3277 if (state
== pci_channel_io_normal
)
3278 return PCI_ERS_RESULT_RECOVERED
;
3280 set_bit(__QLCNIC_AER
, &adapter
->state
);
3281 netif_device_detach(netdev
);
3283 cancel_delayed_work_sync(&adapter
->fw_work
);
3285 if (netif_running(netdev
))
3286 qlcnic_down(adapter
, netdev
);
3288 qlcnic_detach(adapter
);
3289 qlcnic_teardown_intr(adapter
);
3291 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
3293 pci_save_state(pdev
);
3294 pci_disable_device(pdev
);
3296 return PCI_ERS_RESULT_NEED_RESET
;
3299 static pci_ers_result_t
qlcnic_io_slot_reset(struct pci_dev
*pdev
)
3301 return qlcnic_attach_func(pdev
) ? PCI_ERS_RESULT_DISCONNECT
:
3302 PCI_ERS_RESULT_RECOVERED
;
3305 static void qlcnic_io_resume(struct pci_dev
*pdev
)
3307 struct qlcnic_adapter
*adapter
= pci_get_drvdata(pdev
);
3309 pci_cleanup_aer_uncorrect_error_status(pdev
);
3311 if (QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
) == QLCNIC_DEV_READY
&&
3312 test_and_clear_bit(__QLCNIC_AER
, &adapter
->state
))
3313 qlcnic_schedule_work(adapter
, qlcnic_fw_poll_work
,
3318 qlcnicvf_start_firmware(struct qlcnic_adapter
*adapter
)
3322 err
= qlcnic_can_start_firmware(adapter
);
3326 err
= qlcnic_check_npar_opertional(adapter
);
3330 err
= qlcnic_initialize_nic(adapter
);
3334 qlcnic_check_options(adapter
);
3336 err
= qlcnic_set_eswitch_port_config(adapter
);
3340 adapter
->need_fw_reset
= 0;
3346 qlcnicvf_config_bridged_mode(struct qlcnic_adapter
*adapter
, u32 enable
)
3352 qlcnicvf_config_led(struct qlcnic_adapter
*adapter
, u32 state
, u32 rate
)
3358 qlcnic_store_bridged_mode(struct device
*dev
,
3359 struct device_attribute
*attr
, const char *buf
, size_t len
)
3361 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3365 if (!(adapter
->capabilities
& QLCNIC_FW_CAPABILITY_BDG
))
3368 if (!test_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
3371 if (strict_strtoul(buf
, 2, &new))
3374 if (!adapter
->nic_ops
->config_bridged_mode(adapter
, !!new))
3382 qlcnic_show_bridged_mode(struct device
*dev
,
3383 struct device_attribute
*attr
, char *buf
)
3385 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3386 int bridged_mode
= 0;
3388 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_BDG
)
3389 bridged_mode
= !!(adapter
->flags
& QLCNIC_BRIDGE_ENABLED
);
3391 return sprintf(buf
, "%d\n", bridged_mode
);
3394 static struct device_attribute dev_attr_bridged_mode
= {
3395 .attr
= {.name
= "bridged_mode", .mode
= (S_IRUGO
| S_IWUSR
)},
3396 .show
= qlcnic_show_bridged_mode
,
3397 .store
= qlcnic_store_bridged_mode
,
3401 qlcnic_store_diag_mode(struct device
*dev
,
3402 struct device_attribute
*attr
, const char *buf
, size_t len
)
3404 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3407 if (strict_strtoul(buf
, 2, &new))
3410 if (!!new != !!(adapter
->flags
& QLCNIC_DIAG_ENABLED
))
3411 adapter
->flags
^= QLCNIC_DIAG_ENABLED
;
3417 qlcnic_show_diag_mode(struct device
*dev
,
3418 struct device_attribute
*attr
, char *buf
)
3420 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3422 return sprintf(buf
, "%d\n",
3423 !!(adapter
->flags
& QLCNIC_DIAG_ENABLED
));
3426 static struct device_attribute dev_attr_diag_mode
= {
3427 .attr
= {.name
= "diag_mode", .mode
= (S_IRUGO
| S_IWUSR
)},
3428 .show
= qlcnic_show_diag_mode
,
3429 .store
= qlcnic_store_diag_mode
,
3432 int qlcnic_validate_max_rss(struct net_device
*netdev
, u8 max_hw
, u8 val
)
3434 if (!use_msi_x
&& !use_msi
) {
3435 netdev_info(netdev
, "no msix or msi support, hence no rss\n");
3439 if ((val
> max_hw
) || (val
< 2) || !is_power_of_2(val
)) {
3440 netdev_info(netdev
, "rss_ring valid range [2 - %x] in "
3441 " powers of 2\n", max_hw
);
3448 int qlcnic_set_max_rss(struct qlcnic_adapter
*adapter
, u8 data
)
3450 struct net_device
*netdev
= adapter
->netdev
;
3453 if (test_and_set_bit(__QLCNIC_RESETTING
, &adapter
->state
))
3456 netif_device_detach(netdev
);
3457 if (netif_running(netdev
))
3458 __qlcnic_down(adapter
, netdev
);
3459 qlcnic_detach(adapter
);
3460 qlcnic_teardown_intr(adapter
);
3462 if (qlcnic_enable_msix(adapter
, data
)) {
3463 netdev_info(netdev
, "failed setting max_rss; rss disabled\n");
3464 qlcnic_enable_msi_legacy(adapter
);
3467 if (netif_running(netdev
)) {
3468 err
= qlcnic_attach(adapter
);
3471 err
= __qlcnic_up(adapter
, netdev
);
3474 qlcnic_restore_indev_addr(netdev
, NETDEV_UP
);
3477 netif_device_attach(netdev
);
3478 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
3483 qlcnic_validate_beacon(struct qlcnic_adapter
*adapter
, u16 beacon
, u8
*state
,
3486 *rate
= LSB(beacon
);
3487 *state
= MSB(beacon
);
3489 QLCDB(adapter
, DRV
, "rate %x state %x\n", *rate
, *state
);
3492 *rate
= __QLCNIC_MAX_LED_RATE
;
3494 } else if (*state
> __QLCNIC_MAX_LED_STATE
)
3497 if ((!*rate
) || (*rate
> __QLCNIC_MAX_LED_RATE
))
3504 qlcnic_store_beacon(struct device
*dev
,
3505 struct device_attribute
*attr
, const char *buf
, size_t len
)
3507 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3508 int max_sds_rings
= adapter
->max_sds_rings
;
3513 if (adapter
->op_mode
== QLCNIC_NON_PRIV_FUNC
) {
3514 dev_warn(dev
, "LED test not supported for non "
3515 "privilege function\n");
3519 if (len
!= sizeof(u16
))
3520 return QL_STATUS_INVALID_PARAM
;
3522 memcpy(&beacon
, buf
, sizeof(u16
));
3523 err
= qlcnic_validate_beacon(adapter
, beacon
, &b_state
, &b_rate
);
3527 if (adapter
->ahw
->beacon_state
== b_state
)
3532 if (!adapter
->ahw
->beacon_state
)
3533 if (test_and_set_bit(__QLCNIC_LED_ENABLE
, &adapter
->state
)) {
3538 if (test_bit(__QLCNIC_RESETTING
, &adapter
->state
)) {
3543 if (!test_bit(__QLCNIC_DEV_UP
, &adapter
->state
)) {
3544 err
= qlcnic_diag_alloc_res(adapter
->netdev
, QLCNIC_LED_TEST
);
3547 set_bit(__QLCNIC_DIAG_RES_ALLOC
, &adapter
->state
);
3550 err
= qlcnic_config_led(adapter
, b_state
, b_rate
);
3554 adapter
->ahw
->beacon_state
= b_state
;
3557 if (test_and_clear_bit(__QLCNIC_DIAG_RES_ALLOC
, &adapter
->state
))
3558 qlcnic_diag_free_res(adapter
->netdev
, max_sds_rings
);
3561 if (!adapter
->ahw
->beacon_state
)
3562 clear_bit(__QLCNIC_LED_ENABLE
, &adapter
->state
);
3569 qlcnic_show_beacon(struct device
*dev
,
3570 struct device_attribute
*attr
, char *buf
)
3572 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3574 return sprintf(buf
, "%d\n", adapter
->ahw
->beacon_state
);
3577 static struct device_attribute dev_attr_beacon
= {
3578 .attr
= {.name
= "beacon", .mode
= (S_IRUGO
| S_IWUSR
)},
3579 .show
= qlcnic_show_beacon
,
3580 .store
= qlcnic_store_beacon
,
3584 qlcnic_sysfs_validate_crb(struct qlcnic_adapter
*adapter
,
3585 loff_t offset
, size_t size
)
3587 size_t crb_size
= 4;
3589 if (!(adapter
->flags
& QLCNIC_DIAG_ENABLED
))
3592 if (offset
< QLCNIC_PCI_CRBSPACE
) {
3593 if (ADDR_IN_RANGE(offset
, QLCNIC_PCI_CAMQM
,
3594 QLCNIC_PCI_CAMQM_END
))
3600 if ((size
!= crb_size
) || (offset
& (crb_size
-1)))
3607 qlcnic_sysfs_read_crb(struct file
*filp
, struct kobject
*kobj
,
3608 struct bin_attribute
*attr
,
3609 char *buf
, loff_t offset
, size_t size
)
3611 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3612 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3617 ret
= qlcnic_sysfs_validate_crb(adapter
, offset
, size
);
3621 if (ADDR_IN_RANGE(offset
, QLCNIC_PCI_CAMQM
, QLCNIC_PCI_CAMQM_END
)) {
3622 qlcnic_pci_camqm_read_2M(adapter
, offset
, &qmdata
);
3623 memcpy(buf
, &qmdata
, size
);
3625 data
= QLCRD32(adapter
, offset
);
3626 memcpy(buf
, &data
, size
);
3632 qlcnic_sysfs_write_crb(struct file
*filp
, struct kobject
*kobj
,
3633 struct bin_attribute
*attr
,
3634 char *buf
, loff_t offset
, size_t size
)
3636 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3637 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3642 ret
= qlcnic_sysfs_validate_crb(adapter
, offset
, size
);
3646 if (ADDR_IN_RANGE(offset
, QLCNIC_PCI_CAMQM
, QLCNIC_PCI_CAMQM_END
)) {
3647 memcpy(&qmdata
, buf
, size
);
3648 qlcnic_pci_camqm_write_2M(adapter
, offset
, qmdata
);
3650 memcpy(&data
, buf
, size
);
3651 QLCWR32(adapter
, offset
, data
);
3657 qlcnic_sysfs_validate_mem(struct qlcnic_adapter
*adapter
,
3658 loff_t offset
, size_t size
)
3660 if (!(adapter
->flags
& QLCNIC_DIAG_ENABLED
))
3663 if ((size
!= 8) || (offset
& 0x7))
3670 qlcnic_sysfs_read_mem(struct file
*filp
, struct kobject
*kobj
,
3671 struct bin_attribute
*attr
,
3672 char *buf
, loff_t offset
, size_t size
)
3674 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3675 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3679 ret
= qlcnic_sysfs_validate_mem(adapter
, offset
, size
);
3683 if (qlcnic_pci_mem_read_2M(adapter
, offset
, &data
))
3686 memcpy(buf
, &data
, size
);
3692 qlcnic_sysfs_write_mem(struct file
*filp
, struct kobject
*kobj
,
3693 struct bin_attribute
*attr
,
3694 char *buf
, loff_t offset
, size_t size
)
3696 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3697 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3701 ret
= qlcnic_sysfs_validate_mem(adapter
, offset
, size
);
3705 memcpy(&data
, buf
, size
);
3707 if (qlcnic_pci_mem_write_2M(adapter
, offset
, data
))
3713 static struct bin_attribute bin_attr_crb
= {
3714 .attr
= {.name
= "crb", .mode
= (S_IRUGO
| S_IWUSR
)},
3716 .read
= qlcnic_sysfs_read_crb
,
3717 .write
= qlcnic_sysfs_write_crb
,
3720 static struct bin_attribute bin_attr_mem
= {
3721 .attr
= {.name
= "mem", .mode
= (S_IRUGO
| S_IWUSR
)},
3723 .read
= qlcnic_sysfs_read_mem
,
3724 .write
= qlcnic_sysfs_write_mem
,
3728 validate_pm_config(struct qlcnic_adapter
*adapter
,
3729 struct qlcnic_pm_func_cfg
*pm_cfg
, int count
)
3732 u8 src_pci_func
, s_esw_id
, d_esw_id
;
3736 for (i
= 0; i
< count
; i
++) {
3737 src_pci_func
= pm_cfg
[i
].pci_func
;
3738 dest_pci_func
= pm_cfg
[i
].dest_npar
;
3739 if (src_pci_func
>= QLCNIC_MAX_PCI_FUNC
3740 || dest_pci_func
>= QLCNIC_MAX_PCI_FUNC
)
3741 return QL_STATUS_INVALID_PARAM
;
3743 if (adapter
->npars
[src_pci_func
].type
!= QLCNIC_TYPE_NIC
)
3744 return QL_STATUS_INVALID_PARAM
;
3746 if (adapter
->npars
[dest_pci_func
].type
!= QLCNIC_TYPE_NIC
)
3747 return QL_STATUS_INVALID_PARAM
;
3749 s_esw_id
= adapter
->npars
[src_pci_func
].phy_port
;
3750 d_esw_id
= adapter
->npars
[dest_pci_func
].phy_port
;
3752 if (s_esw_id
!= d_esw_id
)
3753 return QL_STATUS_INVALID_PARAM
;
3761 qlcnic_sysfs_write_pm_config(struct file
*filp
, struct kobject
*kobj
,
3762 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3764 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3765 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3766 struct qlcnic_pm_func_cfg
*pm_cfg
;
3767 u32 id
, action
, pci_func
;
3768 int count
, rem
, i
, ret
;
3770 count
= size
/ sizeof(struct qlcnic_pm_func_cfg
);
3771 rem
= size
% sizeof(struct qlcnic_pm_func_cfg
);
3773 return QL_STATUS_INVALID_PARAM
;
3775 pm_cfg
= (struct qlcnic_pm_func_cfg
*) buf
;
3777 ret
= validate_pm_config(adapter
, pm_cfg
, count
);
3780 for (i
= 0; i
< count
; i
++) {
3781 pci_func
= pm_cfg
[i
].pci_func
;
3782 action
= !!pm_cfg
[i
].action
;
3783 id
= adapter
->npars
[pci_func
].phy_port
;
3784 ret
= qlcnic_config_port_mirroring(adapter
, id
,
3790 for (i
= 0; i
< count
; i
++) {
3791 pci_func
= pm_cfg
[i
].pci_func
;
3792 id
= adapter
->npars
[pci_func
].phy_port
;
3793 adapter
->npars
[pci_func
].enable_pm
= !!pm_cfg
[i
].action
;
3794 adapter
->npars
[pci_func
].dest_npar
= id
;
3800 qlcnic_sysfs_read_pm_config(struct file
*filp
, struct kobject
*kobj
,
3801 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3803 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3804 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3805 struct qlcnic_pm_func_cfg pm_cfg
[QLCNIC_MAX_PCI_FUNC
];
3808 if (size
!= sizeof(pm_cfg
))
3809 return QL_STATUS_INVALID_PARAM
;
3811 for (i
= 0; i
< QLCNIC_MAX_PCI_FUNC
; i
++) {
3812 if (adapter
->npars
[i
].type
!= QLCNIC_TYPE_NIC
)
3814 pm_cfg
[i
].action
= adapter
->npars
[i
].enable_pm
;
3815 pm_cfg
[i
].dest_npar
= 0;
3816 pm_cfg
[i
].pci_func
= i
;
3818 memcpy(buf
, &pm_cfg
, size
);
3824 validate_esw_config(struct qlcnic_adapter
*adapter
,
3825 struct qlcnic_esw_func_cfg
*esw_cfg
, int count
)
3831 op_mode
= readl(adapter
->ahw
->pci_base0
+ QLCNIC_DRV_OP_MODE
);
3833 for (i
= 0; i
< count
; i
++) {
3834 pci_func
= esw_cfg
[i
].pci_func
;
3835 if (pci_func
>= QLCNIC_MAX_PCI_FUNC
)
3836 return QL_STATUS_INVALID_PARAM
;
3838 if (adapter
->op_mode
== QLCNIC_MGMT_FUNC
)
3839 if (adapter
->npars
[pci_func
].type
!= QLCNIC_TYPE_NIC
)
3840 return QL_STATUS_INVALID_PARAM
;
3842 switch (esw_cfg
[i
].op_mode
) {
3843 case QLCNIC_PORT_DEFAULTS
:
3844 if (QLC_DEV_GET_DRV(op_mode
, pci_func
) !=
3845 QLCNIC_NON_PRIV_FUNC
) {
3846 if (esw_cfg
[i
].mac_anti_spoof
!= 0)
3847 return QL_STATUS_INVALID_PARAM
;
3848 if (esw_cfg
[i
].mac_override
!= 1)
3849 return QL_STATUS_INVALID_PARAM
;
3850 if (esw_cfg
[i
].promisc_mode
!= 1)
3851 return QL_STATUS_INVALID_PARAM
;
3854 case QLCNIC_ADD_VLAN
:
3855 if (!IS_VALID_VLAN(esw_cfg
[i
].vlan_id
))
3856 return QL_STATUS_INVALID_PARAM
;
3857 if (!esw_cfg
[i
].op_type
)
3858 return QL_STATUS_INVALID_PARAM
;
3860 case QLCNIC_DEL_VLAN
:
3861 if (!esw_cfg
[i
].op_type
)
3862 return QL_STATUS_INVALID_PARAM
;
3865 return QL_STATUS_INVALID_PARAM
;
3872 qlcnic_sysfs_write_esw_config(struct file
*file
, struct kobject
*kobj
,
3873 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3875 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3876 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3877 struct qlcnic_esw_func_cfg
*esw_cfg
;
3878 struct qlcnic_npar_info
*npar
;
3879 int count
, rem
, i
, ret
;
3880 u8 pci_func
, op_mode
= 0;
3882 count
= size
/ sizeof(struct qlcnic_esw_func_cfg
);
3883 rem
= size
% sizeof(struct qlcnic_esw_func_cfg
);
3885 return QL_STATUS_INVALID_PARAM
;
3887 esw_cfg
= (struct qlcnic_esw_func_cfg
*) buf
;
3888 ret
= validate_esw_config(adapter
, esw_cfg
, count
);
3892 for (i
= 0; i
< count
; i
++) {
3893 if (adapter
->op_mode
== QLCNIC_MGMT_FUNC
)
3894 if (qlcnic_config_switch_port(adapter
, &esw_cfg
[i
]))
3895 return QL_STATUS_INVALID_PARAM
;
3897 if (adapter
->ahw
->pci_func
!= esw_cfg
[i
].pci_func
)
3900 op_mode
= esw_cfg
[i
].op_mode
;
3901 qlcnic_get_eswitch_port_config(adapter
, &esw_cfg
[i
]);
3902 esw_cfg
[i
].op_mode
= op_mode
;
3903 esw_cfg
[i
].pci_func
= adapter
->ahw
->pci_func
;
3905 switch (esw_cfg
[i
].op_mode
) {
3906 case QLCNIC_PORT_DEFAULTS
:
3907 qlcnic_set_eswitch_port_features(adapter
, &esw_cfg
[i
]);
3909 case QLCNIC_ADD_VLAN
:
3910 qlcnic_set_vlan_config(adapter
, &esw_cfg
[i
]);
3912 case QLCNIC_DEL_VLAN
:
3913 esw_cfg
[i
].vlan_id
= 0;
3914 qlcnic_set_vlan_config(adapter
, &esw_cfg
[i
]);
3919 if (adapter
->op_mode
!= QLCNIC_MGMT_FUNC
)
3922 for (i
= 0; i
< count
; i
++) {
3923 pci_func
= esw_cfg
[i
].pci_func
;
3924 npar
= &adapter
->npars
[pci_func
];
3925 switch (esw_cfg
[i
].op_mode
) {
3926 case QLCNIC_PORT_DEFAULTS
:
3927 npar
->promisc_mode
= esw_cfg
[i
].promisc_mode
;
3928 npar
->mac_override
= esw_cfg
[i
].mac_override
;
3929 npar
->offload_flags
= esw_cfg
[i
].offload_flags
;
3930 npar
->mac_anti_spoof
= esw_cfg
[i
].mac_anti_spoof
;
3931 npar
->discard_tagged
= esw_cfg
[i
].discard_tagged
;
3933 case QLCNIC_ADD_VLAN
:
3934 npar
->pvid
= esw_cfg
[i
].vlan_id
;
3936 case QLCNIC_DEL_VLAN
:
3946 qlcnic_sysfs_read_esw_config(struct file
*file
, struct kobject
*kobj
,
3947 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3949 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3950 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3951 struct qlcnic_esw_func_cfg esw_cfg
[QLCNIC_MAX_PCI_FUNC
];
3954 if (size
!= sizeof(esw_cfg
))
3955 return QL_STATUS_INVALID_PARAM
;
3957 for (i
= 0; i
< QLCNIC_MAX_PCI_FUNC
; i
++) {
3958 if (adapter
->npars
[i
].type
!= QLCNIC_TYPE_NIC
)
3960 esw_cfg
[i
].pci_func
= i
;
3961 if (qlcnic_get_eswitch_port_config(adapter
, &esw_cfg
[i
]))
3962 return QL_STATUS_INVALID_PARAM
;
3964 memcpy(buf
, &esw_cfg
, size
);
3970 validate_npar_config(struct qlcnic_adapter
*adapter
,
3971 struct qlcnic_npar_func_cfg
*np_cfg
, int count
)
3975 for (i
= 0; i
< count
; i
++) {
3976 pci_func
= np_cfg
[i
].pci_func
;
3977 if (pci_func
>= QLCNIC_MAX_PCI_FUNC
)
3978 return QL_STATUS_INVALID_PARAM
;
3980 if (adapter
->npars
[pci_func
].type
!= QLCNIC_TYPE_NIC
)
3981 return QL_STATUS_INVALID_PARAM
;
3983 if (!IS_VALID_BW(np_cfg
[i
].min_bw
) ||
3984 !IS_VALID_BW(np_cfg
[i
].max_bw
))
3985 return QL_STATUS_INVALID_PARAM
;
3991 qlcnic_sysfs_write_npar_config(struct file
*file
, struct kobject
*kobj
,
3992 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3994 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3995 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3996 struct qlcnic_info nic_info
;
3997 struct qlcnic_npar_func_cfg
*np_cfg
;
3998 int i
, count
, rem
, ret
;
4001 count
= size
/ sizeof(struct qlcnic_npar_func_cfg
);
4002 rem
= size
% sizeof(struct qlcnic_npar_func_cfg
);
4004 return QL_STATUS_INVALID_PARAM
;
4006 np_cfg
= (struct qlcnic_npar_func_cfg
*) buf
;
4007 ret
= validate_npar_config(adapter
, np_cfg
, count
);
4011 for (i
= 0; i
< count
; i
++) {
4012 pci_func
= np_cfg
[i
].pci_func
;
4013 ret
= qlcnic_get_nic_info(adapter
, &nic_info
, pci_func
);
4016 nic_info
.pci_func
= pci_func
;
4017 nic_info
.min_tx_bw
= np_cfg
[i
].min_bw
;
4018 nic_info
.max_tx_bw
= np_cfg
[i
].max_bw
;
4019 ret
= qlcnic_set_nic_info(adapter
, &nic_info
);
4022 adapter
->npars
[i
].min_bw
= nic_info
.min_tx_bw
;
4023 adapter
->npars
[i
].max_bw
= nic_info
.max_tx_bw
;
4030 qlcnic_sysfs_read_npar_config(struct file
*file
, struct kobject
*kobj
,
4031 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
4033 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
4034 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
4035 struct qlcnic_info nic_info
;
4036 struct qlcnic_npar_func_cfg np_cfg
[QLCNIC_MAX_PCI_FUNC
];
4039 if (size
!= sizeof(np_cfg
))
4040 return QL_STATUS_INVALID_PARAM
;
4042 for (i
= 0; i
< QLCNIC_MAX_PCI_FUNC
; i
++) {
4043 if (adapter
->npars
[i
].type
!= QLCNIC_TYPE_NIC
)
4045 ret
= qlcnic_get_nic_info(adapter
, &nic_info
, i
);
4049 np_cfg
[i
].pci_func
= i
;
4050 np_cfg
[i
].op_mode
= (u8
)nic_info
.op_mode
;
4051 np_cfg
[i
].port_num
= nic_info
.phys_port
;
4052 np_cfg
[i
].fw_capab
= nic_info
.capabilities
;
4053 np_cfg
[i
].min_bw
= nic_info
.min_tx_bw
;
4054 np_cfg
[i
].max_bw
= nic_info
.max_tx_bw
;
4055 np_cfg
[i
].max_tx_queues
= nic_info
.max_tx_ques
;
4056 np_cfg
[i
].max_rx_queues
= nic_info
.max_rx_ques
;
4058 memcpy(buf
, &np_cfg
, size
);
4063 qlcnic_sysfs_get_port_stats(struct file
*file
, struct kobject
*kobj
,
4064 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
4066 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
4067 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
4068 struct qlcnic_esw_statistics port_stats
;
4071 if (size
!= sizeof(struct qlcnic_esw_statistics
))
4072 return QL_STATUS_INVALID_PARAM
;
4074 if (offset
>= QLCNIC_MAX_PCI_FUNC
)
4075 return QL_STATUS_INVALID_PARAM
;
4077 memset(&port_stats
, 0, size
);
4078 ret
= qlcnic_get_port_stats(adapter
, offset
, QLCNIC_QUERY_RX_COUNTER
,
4083 ret
= qlcnic_get_port_stats(adapter
, offset
, QLCNIC_QUERY_TX_COUNTER
,
4088 memcpy(buf
, &port_stats
, size
);
4093 qlcnic_sysfs_get_esw_stats(struct file
*file
, struct kobject
*kobj
,
4094 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
4096 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
4097 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
4098 struct qlcnic_esw_statistics esw_stats
;
4101 if (size
!= sizeof(struct qlcnic_esw_statistics
))
4102 return QL_STATUS_INVALID_PARAM
;
4104 if (offset
>= QLCNIC_NIU_MAX_XG_PORTS
)
4105 return QL_STATUS_INVALID_PARAM
;
4107 memset(&esw_stats
, 0, size
);
4108 ret
= qlcnic_get_eswitch_stats(adapter
, offset
, QLCNIC_QUERY_RX_COUNTER
,
4113 ret
= qlcnic_get_eswitch_stats(adapter
, offset
, QLCNIC_QUERY_TX_COUNTER
,
4118 memcpy(buf
, &esw_stats
, size
);
4123 qlcnic_sysfs_clear_esw_stats(struct file
*file
, struct kobject
*kobj
,
4124 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
4126 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
4127 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
4130 if (offset
>= QLCNIC_NIU_MAX_XG_PORTS
)
4131 return QL_STATUS_INVALID_PARAM
;
4133 ret
= qlcnic_clear_esw_stats(adapter
, QLCNIC_STATS_ESWITCH
, offset
,
4134 QLCNIC_QUERY_RX_COUNTER
);
4138 ret
= qlcnic_clear_esw_stats(adapter
, QLCNIC_STATS_ESWITCH
, offset
,
4139 QLCNIC_QUERY_TX_COUNTER
);
4147 qlcnic_sysfs_clear_port_stats(struct file
*file
, struct kobject
*kobj
,
4148 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
4151 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
4152 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
4155 if (offset
>= QLCNIC_MAX_PCI_FUNC
)
4156 return QL_STATUS_INVALID_PARAM
;
4158 ret
= qlcnic_clear_esw_stats(adapter
, QLCNIC_STATS_PORT
, offset
,
4159 QLCNIC_QUERY_RX_COUNTER
);
4163 ret
= qlcnic_clear_esw_stats(adapter
, QLCNIC_STATS_PORT
, offset
,
4164 QLCNIC_QUERY_TX_COUNTER
);
4172 qlcnic_sysfs_read_pci_config(struct file
*file
, struct kobject
*kobj
,
4173 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
4175 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
4176 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
4177 struct qlcnic_pci_func_cfg pci_cfg
[QLCNIC_MAX_PCI_FUNC
];
4178 struct qlcnic_pci_info
*pci_info
;
4181 if (size
!= sizeof(pci_cfg
))
4182 return QL_STATUS_INVALID_PARAM
;
4184 pci_info
= kcalloc(QLCNIC_MAX_PCI_FUNC
, sizeof(*pci_info
), GFP_KERNEL
);
4188 ret
= qlcnic_get_pci_info(adapter
, pci_info
);
4194 for (i
= 0; i
< QLCNIC_MAX_PCI_FUNC
; i
++) {
4195 pci_cfg
[i
].pci_func
= pci_info
[i
].id
;
4196 pci_cfg
[i
].func_type
= pci_info
[i
].type
;
4197 pci_cfg
[i
].port_num
= pci_info
[i
].default_port
;
4198 pci_cfg
[i
].min_bw
= pci_info
[i
].tx_min_bw
;
4199 pci_cfg
[i
].max_bw
= pci_info
[i
].tx_max_bw
;
4200 memcpy(&pci_cfg
[i
].def_mac_addr
, &pci_info
[i
].mac
, ETH_ALEN
);
4202 memcpy(buf
, &pci_cfg
, size
);
4206 static struct bin_attribute bin_attr_npar_config
= {
4207 .attr
= {.name
= "npar_config", .mode
= (S_IRUGO
| S_IWUSR
)},
4209 .read
= qlcnic_sysfs_read_npar_config
,
4210 .write
= qlcnic_sysfs_write_npar_config
,
4213 static struct bin_attribute bin_attr_pci_config
= {
4214 .attr
= {.name
= "pci_config", .mode
= (S_IRUGO
| S_IWUSR
)},
4216 .read
= qlcnic_sysfs_read_pci_config
,
4220 static struct bin_attribute bin_attr_port_stats
= {
4221 .attr
= {.name
= "port_stats", .mode
= (S_IRUGO
| S_IWUSR
)},
4223 .read
= qlcnic_sysfs_get_port_stats
,
4224 .write
= qlcnic_sysfs_clear_port_stats
,
4227 static struct bin_attribute bin_attr_esw_stats
= {
4228 .attr
= {.name
= "esw_stats", .mode
= (S_IRUGO
| S_IWUSR
)},
4230 .read
= qlcnic_sysfs_get_esw_stats
,
4231 .write
= qlcnic_sysfs_clear_esw_stats
,
4234 static struct bin_attribute bin_attr_esw_config
= {
4235 .attr
= {.name
= "esw_config", .mode
= (S_IRUGO
| S_IWUSR
)},
4237 .read
= qlcnic_sysfs_read_esw_config
,
4238 .write
= qlcnic_sysfs_write_esw_config
,
4241 static struct bin_attribute bin_attr_pm_config
= {
4242 .attr
= {.name
= "pm_config", .mode
= (S_IRUGO
| S_IWUSR
)},
4244 .read
= qlcnic_sysfs_read_pm_config
,
4245 .write
= qlcnic_sysfs_write_pm_config
,
4249 qlcnic_create_sysfs_entries(struct qlcnic_adapter
*adapter
)
4251 struct device
*dev
= &adapter
->pdev
->dev
;
4253 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_BDG
)
4254 if (device_create_file(dev
, &dev_attr_bridged_mode
))
4256 "failed to create bridged_mode sysfs entry\n");
4260 qlcnic_remove_sysfs_entries(struct qlcnic_adapter
*adapter
)
4262 struct device
*dev
= &adapter
->pdev
->dev
;
4264 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_BDG
)
4265 device_remove_file(dev
, &dev_attr_bridged_mode
);
4269 qlcnic_create_diag_entries(struct qlcnic_adapter
*adapter
)
4271 struct device
*dev
= &adapter
->pdev
->dev
;
4273 if (device_create_bin_file(dev
, &bin_attr_port_stats
))
4274 dev_info(dev
, "failed to create port stats sysfs entry");
4276 if (adapter
->op_mode
== QLCNIC_NON_PRIV_FUNC
)
4278 if (device_create_file(dev
, &dev_attr_diag_mode
))
4279 dev_info(dev
, "failed to create diag_mode sysfs entry\n");
4280 if (device_create_file(dev
, &dev_attr_beacon
))
4281 dev_info(dev
, "failed to create beacon sysfs entry");
4282 if (device_create_bin_file(dev
, &bin_attr_crb
))
4283 dev_info(dev
, "failed to create crb sysfs entry\n");
4284 if (device_create_bin_file(dev
, &bin_attr_mem
))
4285 dev_info(dev
, "failed to create mem sysfs entry\n");
4286 if (device_create_bin_file(dev
, &bin_attr_pci_config
))
4287 dev_info(dev
, "failed to create pci config sysfs entry");
4288 if (!(adapter
->flags
& QLCNIC_ESWITCH_ENABLED
))
4290 if (device_create_bin_file(dev
, &bin_attr_esw_config
))
4291 dev_info(dev
, "failed to create esw config sysfs entry");
4292 if (adapter
->op_mode
!= QLCNIC_MGMT_FUNC
)
4294 if (device_create_bin_file(dev
, &bin_attr_npar_config
))
4295 dev_info(dev
, "failed to create npar config sysfs entry");
4296 if (device_create_bin_file(dev
, &bin_attr_pm_config
))
4297 dev_info(dev
, "failed to create pm config sysfs entry");
4298 if (device_create_bin_file(dev
, &bin_attr_esw_stats
))
4299 dev_info(dev
, "failed to create eswitch stats sysfs entry");
4303 qlcnic_remove_diag_entries(struct qlcnic_adapter
*adapter
)
4305 struct device
*dev
= &adapter
->pdev
->dev
;
4307 device_remove_bin_file(dev
, &bin_attr_port_stats
);
4309 if (adapter
->op_mode
== QLCNIC_NON_PRIV_FUNC
)
4311 device_remove_file(dev
, &dev_attr_diag_mode
);
4312 device_remove_file(dev
, &dev_attr_beacon
);
4313 device_remove_bin_file(dev
, &bin_attr_crb
);
4314 device_remove_bin_file(dev
, &bin_attr_mem
);
4315 device_remove_bin_file(dev
, &bin_attr_pci_config
);
4316 if (!(adapter
->flags
& QLCNIC_ESWITCH_ENABLED
))
4318 device_remove_bin_file(dev
, &bin_attr_esw_config
);
4319 if (adapter
->op_mode
!= QLCNIC_MGMT_FUNC
)
4321 device_remove_bin_file(dev
, &bin_attr_npar_config
);
4322 device_remove_bin_file(dev
, &bin_attr_pm_config
);
4323 device_remove_bin_file(dev
, &bin_attr_esw_stats
);
4328 #define is_qlcnic_netdev(dev) (dev->netdev_ops == &qlcnic_netdev_ops)
4331 qlcnic_config_indev_addr(struct qlcnic_adapter
*adapter
,
4332 struct net_device
*dev
, unsigned long event
)
4334 struct in_device
*indev
;
4336 indev
= in_dev_get(dev
);
4343 qlcnic_config_ipaddr(adapter
,
4344 ifa
->ifa_address
, QLCNIC_IP_UP
);
4347 qlcnic_config_ipaddr(adapter
,
4348 ifa
->ifa_address
, QLCNIC_IP_DOWN
);
4353 } endfor_ifa(indev
);
4359 qlcnic_restore_indev_addr(struct net_device
*netdev
, unsigned long event
)
4361 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
4362 struct net_device
*dev
;
4365 qlcnic_config_indev_addr(adapter
, netdev
, event
);
4367 for_each_set_bit(vid
, adapter
->vlans
, VLAN_N_VID
) {
4368 dev
= __vlan_find_dev_deep(netdev
, vid
);
4371 qlcnic_config_indev_addr(adapter
, dev
, event
);
4375 static int qlcnic_netdev_event(struct notifier_block
*this,
4376 unsigned long event
, void *ptr
)
4378 struct qlcnic_adapter
*adapter
;
4379 struct net_device
*dev
= (struct net_device
*)ptr
;
4385 if (dev
->priv_flags
& IFF_802_1Q_VLAN
) {
4386 dev
= vlan_dev_real_dev(dev
);
4390 if (!is_qlcnic_netdev(dev
))
4393 adapter
= netdev_priv(dev
);
4398 if (!test_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
4401 qlcnic_config_indev_addr(adapter
, dev
, event
);
4407 qlcnic_inetaddr_event(struct notifier_block
*this,
4408 unsigned long event
, void *ptr
)
4410 struct qlcnic_adapter
*adapter
;
4411 struct net_device
*dev
;
4413 struct in_ifaddr
*ifa
= (struct in_ifaddr
*)ptr
;
4415 dev
= ifa
->ifa_dev
? ifa
->ifa_dev
->dev
: NULL
;
4421 if (dev
->priv_flags
& IFF_802_1Q_VLAN
) {
4422 dev
= vlan_dev_real_dev(dev
);
4426 if (!is_qlcnic_netdev(dev
))
4429 adapter
= netdev_priv(dev
);
4434 if (!test_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
4439 qlcnic_config_ipaddr(adapter
, ifa
->ifa_address
, QLCNIC_IP_UP
);
4442 qlcnic_config_ipaddr(adapter
, ifa
->ifa_address
, QLCNIC_IP_DOWN
);
4452 static struct notifier_block qlcnic_netdev_cb
= {
4453 .notifier_call
= qlcnic_netdev_event
,
4456 static struct notifier_block qlcnic_inetaddr_cb
= {
4457 .notifier_call
= qlcnic_inetaddr_event
,
4461 qlcnic_restore_indev_addr(struct net_device
*dev
, unsigned long event
)
4464 static struct pci_error_handlers qlcnic_err_handler
= {
4465 .error_detected
= qlcnic_io_error_detected
,
4466 .slot_reset
= qlcnic_io_slot_reset
,
4467 .resume
= qlcnic_io_resume
,
4470 static struct pci_driver qlcnic_driver
= {
4471 .name
= qlcnic_driver_name
,
4472 .id_table
= qlcnic_pci_tbl
,
4473 .probe
= qlcnic_probe
,
4474 .remove
= __devexit_p(qlcnic_remove
),
4476 .suspend
= qlcnic_suspend
,
4477 .resume
= qlcnic_resume
,
4479 .shutdown
= qlcnic_shutdown
,
4480 .err_handler
= &qlcnic_err_handler
4484 static int __init
qlcnic_init_module(void)
4488 printk(KERN_INFO
"%s\n", qlcnic_driver_string
);
4490 qlcnic_wq
= create_singlethread_workqueue("qlcnic");
4491 if (qlcnic_wq
== NULL
) {
4492 printk(KERN_ERR
"qlcnic: cannot create workqueue\n");
4497 register_netdevice_notifier(&qlcnic_netdev_cb
);
4498 register_inetaddr_notifier(&qlcnic_inetaddr_cb
);
4501 ret
= pci_register_driver(&qlcnic_driver
);
4504 unregister_inetaddr_notifier(&qlcnic_inetaddr_cb
);
4505 unregister_netdevice_notifier(&qlcnic_netdev_cb
);
4507 destroy_workqueue(qlcnic_wq
);
4513 module_init(qlcnic_init_module
);
4515 static void __exit
qlcnic_exit_module(void)
4518 pci_unregister_driver(&qlcnic_driver
);
4521 unregister_inetaddr_notifier(&qlcnic_inetaddr_cb
);
4522 unregister_netdevice_notifier(&qlcnic_netdev_cb
);
4524 destroy_workqueue(qlcnic_wq
);
4527 module_exit(qlcnic_exit_module
);