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
))
304 return -EADDRNOTAVAIL
;
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
);
1463 qlcnic_restore_indev_addr(netdev
, NETDEV_UP
);
1467 netif_device_attach(netdev
);
1470 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
1475 qlcnic_setup_netdev(struct qlcnic_adapter
*adapter
,
1476 struct net_device
*netdev
, u8 pci_using_dac
)
1479 struct pci_dev
*pdev
= adapter
->pdev
;
1481 adapter
->mc_enabled
= 0;
1482 adapter
->max_mc_count
= 38;
1484 netdev
->netdev_ops
= &qlcnic_netdev_ops
;
1485 netdev
->watchdog_timeo
= 5*HZ
;
1487 qlcnic_change_mtu(netdev
, netdev
->mtu
);
1489 SET_ETHTOOL_OPS(netdev
, &qlcnic_ethtool_ops
);
1491 netdev
->hw_features
= NETIF_F_SG
| NETIF_F_IP_CSUM
|
1492 NETIF_F_IPV6_CSUM
| NETIF_F_RXCSUM
;
1494 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_TSO
)
1495 netdev
->hw_features
|= NETIF_F_TSO
| NETIF_F_TSO6
;
1497 netdev
->hw_features
|= NETIF_F_HIGHDMA
;
1499 netdev
->vlan_features
= netdev
->hw_features
;
1501 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_FVLANTX
)
1502 netdev
->hw_features
|= NETIF_F_HW_VLAN_TX
;
1503 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_HW_LRO
)
1504 netdev
->hw_features
|= NETIF_F_LRO
;
1506 netdev
->features
|= netdev
->hw_features
|
1507 NETIF_F_HW_VLAN_RX
| NETIF_F_HW_VLAN_FILTER
;
1509 netdev
->irq
= adapter
->msix_entries
[0].vector
;
1511 err
= register_netdev(netdev
);
1513 dev_err(&pdev
->dev
, "failed to register net device\n");
1520 static int qlcnic_set_dma_mask(struct pci_dev
*pdev
, u8
*pci_using_dac
)
1522 if (!pci_set_dma_mask(pdev
, DMA_BIT_MASK(64)) &&
1523 !pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(64)))
1525 else if (!pci_set_dma_mask(pdev
, DMA_BIT_MASK(32)) &&
1526 !pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(32)))
1529 dev_err(&pdev
->dev
, "Unable to set DMA mask, aborting\n");
1537 qlcnic_alloc_msix_entries(struct qlcnic_adapter
*adapter
, u16 count
)
1539 adapter
->msix_entries
= kcalloc(count
, sizeof(struct msix_entry
),
1542 if (adapter
->msix_entries
)
1545 dev_err(&adapter
->pdev
->dev
, "failed allocating msix_entries\n");
1549 static int __devinit
1550 qlcnic_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
1552 struct net_device
*netdev
= NULL
;
1553 struct qlcnic_adapter
*adapter
= NULL
;
1555 uint8_t revision_id
;
1556 uint8_t pci_using_dac
;
1557 char brd_name
[QLCNIC_MAX_BOARD_NAME_LEN
];
1559 err
= pci_enable_device(pdev
);
1563 if (!(pci_resource_flags(pdev
, 0) & IORESOURCE_MEM
)) {
1565 goto err_out_disable_pdev
;
1568 err
= qlcnic_set_dma_mask(pdev
, &pci_using_dac
);
1570 goto err_out_disable_pdev
;
1572 err
= pci_request_regions(pdev
, qlcnic_driver_name
);
1574 goto err_out_disable_pdev
;
1576 pci_set_master(pdev
);
1577 pci_enable_pcie_error_reporting(pdev
);
1579 netdev
= alloc_etherdev(sizeof(struct qlcnic_adapter
));
1582 goto err_out_free_res
;
1585 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
1587 adapter
= netdev_priv(netdev
);
1588 adapter
->netdev
= netdev
;
1589 adapter
->pdev
= pdev
;
1591 if (qlcnic_alloc_adapter_resources(adapter
))
1592 goto err_out_free_netdev
;
1594 adapter
->dev_rst_time
= jiffies
;
1595 revision_id
= pdev
->revision
;
1596 adapter
->ahw
->revision_id
= revision_id
;
1597 adapter
->mac_learn
= qlcnic_mac_learn
;
1599 rwlock_init(&adapter
->ahw
->crb_lock
);
1600 mutex_init(&adapter
->ahw
->mem_lock
);
1602 spin_lock_init(&adapter
->tx_clean_lock
);
1603 INIT_LIST_HEAD(&adapter
->mac_list
);
1605 err
= qlcnic_setup_pci_map(adapter
);
1607 goto err_out_free_hw
;
1609 /* This will be reset for mezz cards */
1610 adapter
->portnum
= adapter
->ahw
->pci_func
;
1612 err
= qlcnic_get_board_info(adapter
);
1614 dev_err(&pdev
->dev
, "Error getting board config info.\n");
1615 goto err_out_iounmap
;
1618 err
= qlcnic_setup_idc_param(adapter
);
1620 goto err_out_iounmap
;
1622 adapter
->flags
|= QLCNIC_NEED_FLR
;
1624 err
= adapter
->nic_ops
->start_firmware(adapter
);
1626 dev_err(&pdev
->dev
, "Loading fw failed.Please Reboot\n");
1627 goto err_out_decr_ref
;
1630 if (qlcnic_read_mac_addr(adapter
))
1631 dev_warn(&pdev
->dev
, "failed to read mac addr\n");
1633 if (adapter
->portnum
== 0) {
1634 get_brd_name(adapter
, brd_name
);
1636 pr_info("%s: %s Board Chip rev 0x%x\n",
1637 module_name(THIS_MODULE
),
1638 brd_name
, adapter
->ahw
->revision_id
);
1641 qlcnic_clear_stats(adapter
);
1643 err
= qlcnic_alloc_msix_entries(adapter
, adapter
->max_rx_ques
);
1645 goto err_out_decr_ref
;
1647 qlcnic_setup_intr(adapter
);
1649 err
= qlcnic_setup_netdev(adapter
, netdev
, pci_using_dac
);
1651 goto err_out_disable_msi
;
1653 pci_set_drvdata(pdev
, adapter
);
1655 qlcnic_schedule_work(adapter
, qlcnic_fw_poll_work
, FW_POLL_DELAY
);
1657 switch (adapter
->ahw
->port_type
) {
1659 dev_info(&adapter
->pdev
->dev
, "%s: GbE port initialized\n",
1660 adapter
->netdev
->name
);
1663 dev_info(&adapter
->pdev
->dev
, "%s: XGbE port initialized\n",
1664 adapter
->netdev
->name
);
1668 if (adapter
->mac_learn
)
1669 qlcnic_alloc_lb_filters_mem(adapter
);
1671 qlcnic_create_diag_entries(adapter
);
1675 err_out_disable_msi
:
1676 qlcnic_teardown_intr(adapter
);
1677 kfree(adapter
->msix_entries
);
1680 qlcnic_clr_all_drv_state(adapter
, 0);
1683 qlcnic_cleanup_pci_map(adapter
);
1686 qlcnic_free_adapter_resources(adapter
);
1688 err_out_free_netdev
:
1689 free_netdev(netdev
);
1692 pci_release_regions(pdev
);
1694 err_out_disable_pdev
:
1695 pci_set_drvdata(pdev
, NULL
);
1696 pci_disable_device(pdev
);
1700 static void __devexit
qlcnic_remove(struct pci_dev
*pdev
)
1702 struct qlcnic_adapter
*adapter
;
1703 struct net_device
*netdev
;
1705 adapter
= pci_get_drvdata(pdev
);
1706 if (adapter
== NULL
)
1709 netdev
= adapter
->netdev
;
1711 qlcnic_cancel_fw_work(adapter
);
1713 unregister_netdev(netdev
);
1715 qlcnic_detach(adapter
);
1717 if (adapter
->npars
!= NULL
)
1718 kfree(adapter
->npars
);
1719 if (adapter
->eswitch
!= NULL
)
1720 kfree(adapter
->eswitch
);
1722 qlcnic_clr_all_drv_state(adapter
, 0);
1724 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
1726 qlcnic_free_lb_filters_mem(adapter
);
1728 qlcnic_teardown_intr(adapter
);
1729 kfree(adapter
->msix_entries
);
1731 qlcnic_remove_diag_entries(adapter
);
1733 qlcnic_cleanup_pci_map(adapter
);
1735 qlcnic_release_firmware(adapter
);
1737 pci_disable_pcie_error_reporting(pdev
);
1738 pci_release_regions(pdev
);
1739 pci_disable_device(pdev
);
1740 pci_set_drvdata(pdev
, NULL
);
1742 qlcnic_free_adapter_resources(adapter
);
1743 free_netdev(netdev
);
1745 static int __qlcnic_shutdown(struct pci_dev
*pdev
)
1747 struct qlcnic_adapter
*adapter
= pci_get_drvdata(pdev
);
1748 struct net_device
*netdev
= adapter
->netdev
;
1751 netif_device_detach(netdev
);
1753 qlcnic_cancel_fw_work(adapter
);
1755 if (netif_running(netdev
))
1756 qlcnic_down(adapter
, netdev
);
1758 qlcnic_clr_all_drv_state(adapter
, 0);
1760 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
1762 retval
= pci_save_state(pdev
);
1766 if (qlcnic_wol_supported(adapter
)) {
1767 pci_enable_wake(pdev
, PCI_D3cold
, 1);
1768 pci_enable_wake(pdev
, PCI_D3hot
, 1);
1774 static void qlcnic_shutdown(struct pci_dev
*pdev
)
1776 if (__qlcnic_shutdown(pdev
))
1779 pci_disable_device(pdev
);
1784 qlcnic_suspend(struct pci_dev
*pdev
, pm_message_t state
)
1788 retval
= __qlcnic_shutdown(pdev
);
1792 pci_set_power_state(pdev
, pci_choose_state(pdev
, state
));
1797 qlcnic_resume(struct pci_dev
*pdev
)
1799 struct qlcnic_adapter
*adapter
= pci_get_drvdata(pdev
);
1800 struct net_device
*netdev
= adapter
->netdev
;
1803 err
= pci_enable_device(pdev
);
1807 pci_set_power_state(pdev
, PCI_D0
);
1808 pci_set_master(pdev
);
1809 pci_restore_state(pdev
);
1811 err
= adapter
->nic_ops
->start_firmware(adapter
);
1813 dev_err(&pdev
->dev
, "failed to start firmware\n");
1817 if (netif_running(netdev
)) {
1818 err
= qlcnic_up(adapter
, netdev
);
1822 qlcnic_restore_indev_addr(netdev
, NETDEV_UP
);
1825 netif_device_attach(netdev
);
1826 qlcnic_schedule_work(adapter
, qlcnic_fw_poll_work
, FW_POLL_DELAY
);
1831 static int qlcnic_open(struct net_device
*netdev
)
1833 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
1836 netif_carrier_off(netdev
);
1838 err
= qlcnic_attach(adapter
);
1842 err
= __qlcnic_up(adapter
, netdev
);
1846 netif_start_queue(netdev
);
1851 qlcnic_detach(adapter
);
1856 * qlcnic_close - Disables a network interface entry point
1858 static int qlcnic_close(struct net_device
*netdev
)
1860 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
1862 __qlcnic_down(adapter
, netdev
);
1866 void qlcnic_alloc_lb_filters_mem(struct qlcnic_adapter
*adapter
)
1871 if (adapter
->fhash
.fmax
&& adapter
->fhash
.fhead
)
1874 spin_lock_init(&adapter
->mac_learn_lock
);
1876 head
= kcalloc(QLCNIC_LB_MAX_FILTERS
, sizeof(struct hlist_head
),
1881 adapter
->fhash
.fmax
= QLCNIC_LB_MAX_FILTERS
;
1882 adapter
->fhash
.fhead
= head
;
1884 for (i
= 0; i
< adapter
->fhash
.fmax
; i
++)
1885 INIT_HLIST_HEAD(&adapter
->fhash
.fhead
[i
]);
1888 static void qlcnic_free_lb_filters_mem(struct qlcnic_adapter
*adapter
)
1890 if (adapter
->fhash
.fmax
&& adapter
->fhash
.fhead
)
1891 kfree(adapter
->fhash
.fhead
);
1893 adapter
->fhash
.fhead
= NULL
;
1894 adapter
->fhash
.fmax
= 0;
1897 static void qlcnic_change_filter(struct qlcnic_adapter
*adapter
,
1898 u64 uaddr
, __le16 vlan_id
, struct qlcnic_host_tx_ring
*tx_ring
)
1900 struct cmd_desc_type0
*hwdesc
;
1901 struct qlcnic_nic_req
*req
;
1902 struct qlcnic_mac_req
*mac_req
;
1903 struct qlcnic_vlan_req
*vlan_req
;
1907 producer
= tx_ring
->producer
;
1908 hwdesc
= &tx_ring
->desc_head
[tx_ring
->producer
];
1910 req
= (struct qlcnic_nic_req
*)hwdesc
;
1911 memset(req
, 0, sizeof(struct qlcnic_nic_req
));
1912 req
->qhdr
= cpu_to_le64(QLCNIC_REQUEST
<< 23);
1914 word
= QLCNIC_MAC_EVENT
| ((u64
)(adapter
->portnum
) << 16);
1915 req
->req_hdr
= cpu_to_le64(word
);
1917 mac_req
= (struct qlcnic_mac_req
*)&(req
->words
[0]);
1918 mac_req
->op
= vlan_id
? QLCNIC_MAC_VLAN_ADD
: QLCNIC_MAC_ADD
;
1919 memcpy(mac_req
->mac_addr
, &uaddr
, ETH_ALEN
);
1921 vlan_req
= (struct qlcnic_vlan_req
*)&req
->words
[1];
1922 vlan_req
->vlan_id
= vlan_id
;
1924 tx_ring
->producer
= get_next_index(producer
, tx_ring
->num_desc
);
1928 #define QLCNIC_MAC_HASH(MAC)\
1929 ((((MAC) & 0x70000) >> 0x10) | (((MAC) & 0x70000000000ULL) >> 0x25))
1932 qlcnic_send_filter(struct qlcnic_adapter
*adapter
,
1933 struct qlcnic_host_tx_ring
*tx_ring
,
1934 struct cmd_desc_type0
*first_desc
,
1935 struct sk_buff
*skb
)
1937 struct ethhdr
*phdr
= (struct ethhdr
*)(skb
->data
);
1938 struct qlcnic_filter
*fil
, *tmp_fil
;
1939 struct hlist_node
*tmp_hnode
, *n
;
1940 struct hlist_head
*head
;
1945 if (!compare_ether_addr(phdr
->h_source
, adapter
->mac_addr
))
1948 if (adapter
->fhash
.fnum
>= adapter
->fhash
.fmax
)
1951 /* Only NPAR capable devices support vlan based learning*/
1952 if (adapter
->flags
& QLCNIC_ESWITCH_ENABLED
)
1953 vlan_id
= first_desc
->vlan_TCI
;
1954 memcpy(&src_addr
, phdr
->h_source
, ETH_ALEN
);
1955 hindex
= QLCNIC_MAC_HASH(src_addr
) & (QLCNIC_LB_MAX_FILTERS
- 1);
1956 head
= &(adapter
->fhash
.fhead
[hindex
]);
1958 hlist_for_each_entry_safe(tmp_fil
, tmp_hnode
, n
, head
, fnode
) {
1959 if (!memcmp(tmp_fil
->faddr
, &src_addr
, ETH_ALEN
) &&
1960 tmp_fil
->vlan_id
== vlan_id
) {
1963 (QLCNIC_READD_AGE
* HZ
+ tmp_fil
->ftime
))
1964 qlcnic_change_filter(adapter
, src_addr
, vlan_id
,
1966 tmp_fil
->ftime
= jiffies
;
1971 fil
= kzalloc(sizeof(struct qlcnic_filter
), GFP_ATOMIC
);
1975 qlcnic_change_filter(adapter
, src_addr
, vlan_id
, tx_ring
);
1977 fil
->ftime
= jiffies
;
1978 fil
->vlan_id
= vlan_id
;
1979 memcpy(fil
->faddr
, &src_addr
, ETH_ALEN
);
1980 spin_lock(&adapter
->mac_learn_lock
);
1981 hlist_add_head(&(fil
->fnode
), head
);
1982 adapter
->fhash
.fnum
++;
1983 spin_unlock(&adapter
->mac_learn_lock
);
1987 qlcnic_tx_pkt(struct qlcnic_adapter
*adapter
,
1988 struct cmd_desc_type0
*first_desc
,
1989 struct sk_buff
*skb
)
1991 u8 opcode
= 0, hdr_len
= 0;
1992 u16 flags
= 0, vlan_tci
= 0;
1993 int copied
, offset
, copy_len
;
1994 struct cmd_desc_type0
*hwdesc
;
1995 struct vlan_ethhdr
*vh
;
1996 struct qlcnic_host_tx_ring
*tx_ring
= adapter
->tx_ring
;
1997 u16 protocol
= ntohs(skb
->protocol
);
1998 u32 producer
= tx_ring
->producer
;
2000 if (protocol
== ETH_P_8021Q
) {
2001 vh
= (struct vlan_ethhdr
*)skb
->data
;
2002 flags
= FLAGS_VLAN_TAGGED
;
2003 vlan_tci
= vh
->h_vlan_TCI
;
2004 } else if (vlan_tx_tag_present(skb
)) {
2005 flags
= FLAGS_VLAN_OOB
;
2006 vlan_tci
= vlan_tx_tag_get(skb
);
2008 if (unlikely(adapter
->pvid
)) {
2009 if (vlan_tci
&& !(adapter
->flags
& QLCNIC_TAGGING_ENABLED
))
2011 if (vlan_tci
&& (adapter
->flags
& QLCNIC_TAGGING_ENABLED
))
2014 flags
= FLAGS_VLAN_OOB
;
2015 vlan_tci
= adapter
->pvid
;
2018 qlcnic_set_tx_vlan_tci(first_desc
, vlan_tci
);
2019 qlcnic_set_tx_flags_opcode(first_desc
, flags
, opcode
);
2021 if (*(skb
->data
) & BIT_0
) {
2023 memcpy(&first_desc
->eth_addr
, skb
->data
, ETH_ALEN
);
2025 opcode
= TX_ETHER_PKT
;
2026 if ((adapter
->netdev
->features
& (NETIF_F_TSO
| NETIF_F_TSO6
)) &&
2027 skb_shinfo(skb
)->gso_size
> 0) {
2029 hdr_len
= skb_transport_offset(skb
) + tcp_hdrlen(skb
);
2031 first_desc
->mss
= cpu_to_le16(skb_shinfo(skb
)->gso_size
);
2032 first_desc
->total_hdr_length
= hdr_len
;
2034 opcode
= (protocol
== ETH_P_IPV6
) ? TX_TCP_LSO6
: TX_TCP_LSO
;
2036 /* For LSO, we need to copy the MAC/IP/TCP headers into
2037 * the descriptor ring */
2041 if (flags
& FLAGS_VLAN_OOB
) {
2042 first_desc
->total_hdr_length
+= VLAN_HLEN
;
2043 first_desc
->tcp_hdr_offset
= VLAN_HLEN
;
2044 first_desc
->ip_hdr_offset
= VLAN_HLEN
;
2045 /* Only in case of TSO on vlan device */
2046 flags
|= FLAGS_VLAN_TAGGED
;
2048 /* Create a TSO vlan header template for firmware */
2050 hwdesc
= &tx_ring
->desc_head
[producer
];
2051 tx_ring
->cmd_buf_arr
[producer
].skb
= NULL
;
2053 copy_len
= min((int)sizeof(struct cmd_desc_type0
) -
2054 offset
, hdr_len
+ VLAN_HLEN
);
2056 vh
= (struct vlan_ethhdr
*)((char *) hwdesc
+ 2);
2057 skb_copy_from_linear_data(skb
, vh
, 12);
2058 vh
->h_vlan_proto
= htons(ETH_P_8021Q
);
2059 vh
->h_vlan_TCI
= htons(vlan_tci
);
2061 skb_copy_from_linear_data_offset(skb
, 12,
2062 (char *)vh
+ 16, copy_len
- 16);
2064 copied
= copy_len
- VLAN_HLEN
;
2067 producer
= get_next_index(producer
, tx_ring
->num_desc
);
2070 while (copied
< hdr_len
) {
2072 copy_len
= min((int)sizeof(struct cmd_desc_type0
) -
2073 offset
, (hdr_len
- copied
));
2075 hwdesc
= &tx_ring
->desc_head
[producer
];
2076 tx_ring
->cmd_buf_arr
[producer
].skb
= NULL
;
2078 skb_copy_from_linear_data_offset(skb
, copied
,
2079 (char *) hwdesc
+ offset
, copy_len
);
2084 producer
= get_next_index(producer
, tx_ring
->num_desc
);
2087 tx_ring
->producer
= producer
;
2089 adapter
->stats
.lso_frames
++;
2091 } else if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
2094 if (protocol
== ETH_P_IP
) {
2095 l4proto
= ip_hdr(skb
)->protocol
;
2097 if (l4proto
== IPPROTO_TCP
)
2098 opcode
= TX_TCP_PKT
;
2099 else if (l4proto
== IPPROTO_UDP
)
2100 opcode
= TX_UDP_PKT
;
2101 } else if (protocol
== ETH_P_IPV6
) {
2102 l4proto
= ipv6_hdr(skb
)->nexthdr
;
2104 if (l4proto
== IPPROTO_TCP
)
2105 opcode
= TX_TCPV6_PKT
;
2106 else if (l4proto
== IPPROTO_UDP
)
2107 opcode
= TX_UDPV6_PKT
;
2110 first_desc
->tcp_hdr_offset
+= skb_transport_offset(skb
);
2111 first_desc
->ip_hdr_offset
+= skb_network_offset(skb
);
2112 qlcnic_set_tx_flags_opcode(first_desc
, flags
, opcode
);
2118 qlcnic_map_tx_skb(struct pci_dev
*pdev
,
2119 struct sk_buff
*skb
, struct qlcnic_cmd_buffer
*pbuf
)
2121 struct qlcnic_skb_frag
*nf
;
2122 struct skb_frag_struct
*frag
;
2126 nr_frags
= skb_shinfo(skb
)->nr_frags
;
2127 nf
= &pbuf
->frag_array
[0];
2129 map
= pci_map_single(pdev
, skb
->data
,
2130 skb_headlen(skb
), PCI_DMA_TODEVICE
);
2131 if (pci_dma_mapping_error(pdev
, map
))
2135 nf
->length
= skb_headlen(skb
);
2137 for (i
= 0; i
< nr_frags
; i
++) {
2138 frag
= &skb_shinfo(skb
)->frags
[i
];
2139 nf
= &pbuf
->frag_array
[i
+1];
2141 map
= skb_frag_dma_map(&pdev
->dev
, frag
, 0, skb_frag_size(frag
),
2143 if (dma_mapping_error(&pdev
->dev
, map
))
2147 nf
->length
= skb_frag_size(frag
);
2154 nf
= &pbuf
->frag_array
[i
+1];
2155 pci_unmap_page(pdev
, nf
->dma
, nf
->length
, PCI_DMA_TODEVICE
);
2158 nf
= &pbuf
->frag_array
[0];
2159 pci_unmap_single(pdev
, nf
->dma
, skb_headlen(skb
), PCI_DMA_TODEVICE
);
2166 qlcnic_unmap_buffers(struct pci_dev
*pdev
, struct sk_buff
*skb
,
2167 struct qlcnic_cmd_buffer
*pbuf
)
2169 struct qlcnic_skb_frag
*nf
= &pbuf
->frag_array
[0];
2170 int nr_frags
= skb_shinfo(skb
)->nr_frags
;
2173 for (i
= 0; i
< nr_frags
; i
++) {
2174 nf
= &pbuf
->frag_array
[i
+1];
2175 pci_unmap_page(pdev
, nf
->dma
, nf
->length
, PCI_DMA_TODEVICE
);
2178 nf
= &pbuf
->frag_array
[0];
2179 pci_unmap_single(pdev
, nf
->dma
, skb_headlen(skb
), PCI_DMA_TODEVICE
);
2184 qlcnic_clear_cmddesc(u64
*desc
)
2192 qlcnic_xmit_frame(struct sk_buff
*skb
, struct net_device
*netdev
)
2194 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
2195 struct qlcnic_host_tx_ring
*tx_ring
= adapter
->tx_ring
;
2196 struct qlcnic_cmd_buffer
*pbuf
;
2197 struct qlcnic_skb_frag
*buffrag
;
2198 struct cmd_desc_type0
*hwdesc
, *first_desc
;
2199 struct pci_dev
*pdev
;
2200 struct ethhdr
*phdr
;
2206 u32 num_txd
= tx_ring
->num_desc
;
2208 if (!test_bit(__QLCNIC_DEV_UP
, &adapter
->state
)) {
2209 netif_stop_queue(netdev
);
2210 return NETDEV_TX_BUSY
;
2213 if (adapter
->flags
& QLCNIC_MACSPOOF
) {
2214 phdr
= (struct ethhdr
*)skb
->data
;
2215 if (compare_ether_addr(phdr
->h_source
,
2220 frag_count
= skb_shinfo(skb
)->nr_frags
+ 1;
2221 /* 14 frags supported for normal packet and
2222 * 32 frags supported for TSO packet
2224 if (!skb_is_gso(skb
) && frag_count
> QLCNIC_MAX_FRAGS_PER_TX
) {
2226 for (i
= 0; i
< (frag_count
- QLCNIC_MAX_FRAGS_PER_TX
); i
++)
2227 delta
+= skb_frag_size(&skb_shinfo(skb
)->frags
[i
]);
2229 if (!__pskb_pull_tail(skb
, delta
))
2232 frag_count
= 1 + skb_shinfo(skb
)->nr_frags
;
2235 if (unlikely(qlcnic_tx_avail(tx_ring
) <= TX_STOP_THRESH
)) {
2236 netif_stop_queue(netdev
);
2237 if (qlcnic_tx_avail(tx_ring
) > TX_STOP_THRESH
)
2238 netif_start_queue(netdev
);
2240 adapter
->stats
.xmit_off
++;
2241 return NETDEV_TX_BUSY
;
2245 producer
= tx_ring
->producer
;
2246 pbuf
= &tx_ring
->cmd_buf_arr
[producer
];
2248 pdev
= adapter
->pdev
;
2250 first_desc
= hwdesc
= &tx_ring
->desc_head
[producer
];
2251 qlcnic_clear_cmddesc((u64
*)hwdesc
);
2253 if (qlcnic_map_tx_skb(pdev
, skb
, pbuf
)) {
2254 adapter
->stats
.tx_dma_map_error
++;
2259 pbuf
->frag_count
= frag_count
;
2261 qlcnic_set_tx_frags_len(first_desc
, frag_count
, skb
->len
);
2262 qlcnic_set_tx_port(first_desc
, adapter
->portnum
);
2264 for (i
= 0; i
< frag_count
; i
++) {
2268 if ((k
== 0) && (i
> 0)) {
2269 /* move to next desc.*/
2270 producer
= get_next_index(producer
, num_txd
);
2271 hwdesc
= &tx_ring
->desc_head
[producer
];
2272 qlcnic_clear_cmddesc((u64
*)hwdesc
);
2273 tx_ring
->cmd_buf_arr
[producer
].skb
= NULL
;
2276 buffrag
= &pbuf
->frag_array
[i
];
2278 hwdesc
->buffer_length
[k
] = cpu_to_le16(buffrag
->length
);
2281 hwdesc
->addr_buffer1
= cpu_to_le64(buffrag
->dma
);
2284 hwdesc
->addr_buffer2
= cpu_to_le64(buffrag
->dma
);
2287 hwdesc
->addr_buffer3
= cpu_to_le64(buffrag
->dma
);
2290 hwdesc
->addr_buffer4
= cpu_to_le64(buffrag
->dma
);
2295 tx_ring
->producer
= get_next_index(producer
, num_txd
);
2298 if (unlikely(qlcnic_tx_pkt(adapter
, first_desc
, skb
)))
2301 if (adapter
->mac_learn
)
2302 qlcnic_send_filter(adapter
, tx_ring
, first_desc
, skb
);
2304 adapter
->stats
.txbytes
+= skb
->len
;
2305 adapter
->stats
.xmitcalled
++;
2307 qlcnic_update_cmd_producer(adapter
, tx_ring
);
2309 return NETDEV_TX_OK
;
2312 qlcnic_unmap_buffers(pdev
, skb
, pbuf
);
2314 adapter
->stats
.txdropped
++;
2315 dev_kfree_skb_any(skb
);
2316 return NETDEV_TX_OK
;
2319 static int qlcnic_check_temp(struct qlcnic_adapter
*adapter
)
2321 struct net_device
*netdev
= adapter
->netdev
;
2322 u32 temp
, temp_state
, temp_val
;
2325 temp
= QLCRD32(adapter
, CRB_TEMP_STATE
);
2327 temp_state
= qlcnic_get_temp_state(temp
);
2328 temp_val
= qlcnic_get_temp_val(temp
);
2330 if (temp_state
== QLCNIC_TEMP_PANIC
) {
2331 dev_err(&netdev
->dev
,
2332 "Device temperature %d degrees C exceeds"
2333 " maximum allowed. Hardware has been shut down.\n",
2336 } else if (temp_state
== QLCNIC_TEMP_WARN
) {
2337 if (adapter
->temp
== QLCNIC_TEMP_NORMAL
) {
2338 dev_err(&netdev
->dev
,
2339 "Device temperature %d degrees C "
2340 "exceeds operating range."
2341 " Immediate action needed.\n",
2345 if (adapter
->temp
== QLCNIC_TEMP_WARN
) {
2346 dev_info(&netdev
->dev
,
2347 "Device temperature is now %d degrees C"
2348 " in normal range.\n", temp_val
);
2351 adapter
->temp
= temp_state
;
2355 void qlcnic_advert_link_change(struct qlcnic_adapter
*adapter
, int linkup
)
2357 struct net_device
*netdev
= adapter
->netdev
;
2359 if (adapter
->ahw
->linkup
&& !linkup
) {
2360 netdev_info(netdev
, "NIC Link is down\n");
2361 adapter
->ahw
->linkup
= 0;
2362 if (netif_running(netdev
)) {
2363 netif_carrier_off(netdev
);
2364 netif_stop_queue(netdev
);
2366 } else if (!adapter
->ahw
->linkup
&& linkup
) {
2367 netdev_info(netdev
, "NIC Link is up\n");
2368 adapter
->ahw
->linkup
= 1;
2369 if (netif_running(netdev
)) {
2370 netif_carrier_on(netdev
);
2371 netif_wake_queue(netdev
);
2376 static void qlcnic_tx_timeout(struct net_device
*netdev
)
2378 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
2380 if (test_bit(__QLCNIC_RESETTING
, &adapter
->state
))
2383 dev_err(&netdev
->dev
, "transmit timeout, resetting.\n");
2385 if (++adapter
->tx_timeo_cnt
>= QLCNIC_MAX_TX_TIMEOUTS
)
2386 adapter
->need_fw_reset
= 1;
2388 adapter
->reset_context
= 1;
2391 static struct net_device_stats
*qlcnic_get_stats(struct net_device
*netdev
)
2393 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
2394 struct net_device_stats
*stats
= &netdev
->stats
;
2396 stats
->rx_packets
= adapter
->stats
.rx_pkts
+ adapter
->stats
.lro_pkts
;
2397 stats
->tx_packets
= adapter
->stats
.xmitfinished
;
2398 stats
->rx_bytes
= adapter
->stats
.rxbytes
+ adapter
->stats
.lrobytes
;
2399 stats
->tx_bytes
= adapter
->stats
.txbytes
;
2400 stats
->rx_dropped
= adapter
->stats
.rxdropped
;
2401 stats
->tx_dropped
= adapter
->stats
.txdropped
;
2406 static irqreturn_t
qlcnic_clear_legacy_intr(struct qlcnic_adapter
*adapter
)
2410 status
= readl(adapter
->isr_int_vec
);
2412 if (!(status
& adapter
->int_vec_bit
))
2415 /* check interrupt state machine, to be sure */
2416 status
= readl(adapter
->crb_int_state_reg
);
2417 if (!ISR_LEGACY_INT_TRIGGERED(status
))
2420 writel(0xffffffff, adapter
->tgt_status_reg
);
2421 /* read twice to ensure write is flushed */
2422 readl(adapter
->isr_int_vec
);
2423 readl(adapter
->isr_int_vec
);
2428 static irqreturn_t
qlcnic_tmp_intr(int irq
, void *data
)
2430 struct qlcnic_host_sds_ring
*sds_ring
= data
;
2431 struct qlcnic_adapter
*adapter
= sds_ring
->adapter
;
2433 if (adapter
->flags
& QLCNIC_MSIX_ENABLED
)
2435 else if (adapter
->flags
& QLCNIC_MSI_ENABLED
) {
2436 writel(0xffffffff, adapter
->tgt_status_reg
);
2440 if (qlcnic_clear_legacy_intr(adapter
) == IRQ_NONE
)
2444 adapter
->diag_cnt
++;
2445 qlcnic_enable_int(sds_ring
);
2449 static irqreturn_t
qlcnic_intr(int irq
, void *data
)
2451 struct qlcnic_host_sds_ring
*sds_ring
= data
;
2452 struct qlcnic_adapter
*adapter
= sds_ring
->adapter
;
2454 if (qlcnic_clear_legacy_intr(adapter
) == IRQ_NONE
)
2457 napi_schedule(&sds_ring
->napi
);
2462 static irqreturn_t
qlcnic_msi_intr(int irq
, void *data
)
2464 struct qlcnic_host_sds_ring
*sds_ring
= data
;
2465 struct qlcnic_adapter
*adapter
= sds_ring
->adapter
;
2467 /* clear interrupt */
2468 writel(0xffffffff, adapter
->tgt_status_reg
);
2470 napi_schedule(&sds_ring
->napi
);
2474 static irqreturn_t
qlcnic_msix_intr(int irq
, void *data
)
2476 struct qlcnic_host_sds_ring
*sds_ring
= data
;
2478 napi_schedule(&sds_ring
->napi
);
2482 static int qlcnic_process_cmd_ring(struct qlcnic_adapter
*adapter
)
2484 u32 sw_consumer
, hw_consumer
;
2486 struct qlcnic_cmd_buffer
*buffer
;
2487 struct pci_dev
*pdev
= adapter
->pdev
;
2488 struct net_device
*netdev
= adapter
->netdev
;
2489 struct qlcnic_skb_frag
*frag
;
2491 struct qlcnic_host_tx_ring
*tx_ring
= adapter
->tx_ring
;
2493 if (!spin_trylock(&adapter
->tx_clean_lock
))
2496 sw_consumer
= tx_ring
->sw_consumer
;
2497 hw_consumer
= le32_to_cpu(*(tx_ring
->hw_consumer
));
2499 while (sw_consumer
!= hw_consumer
) {
2500 buffer
= &tx_ring
->cmd_buf_arr
[sw_consumer
];
2502 frag
= &buffer
->frag_array
[0];
2503 pci_unmap_single(pdev
, frag
->dma
, frag
->length
,
2506 for (i
= 1; i
< buffer
->frag_count
; i
++) {
2508 pci_unmap_page(pdev
, frag
->dma
, frag
->length
,
2513 adapter
->stats
.xmitfinished
++;
2514 dev_kfree_skb_any(buffer
->skb
);
2518 sw_consumer
= get_next_index(sw_consumer
, tx_ring
->num_desc
);
2519 if (++count
>= MAX_STATUS_HANDLE
)
2523 if (count
&& netif_running(netdev
)) {
2524 tx_ring
->sw_consumer
= sw_consumer
;
2528 if (netif_queue_stopped(netdev
) && netif_carrier_ok(netdev
)) {
2529 if (qlcnic_tx_avail(tx_ring
) > TX_STOP_THRESH
) {
2530 netif_wake_queue(netdev
);
2531 adapter
->stats
.xmit_on
++;
2534 adapter
->tx_timeo_cnt
= 0;
2537 * If everything is freed up to consumer then check if the ring is full
2538 * If the ring is full then check if more needs to be freed and
2539 * schedule the call back again.
2541 * This happens when there are 2 CPUs. One could be freeing and the
2542 * other filling it. If the ring is full when we get out of here and
2543 * the card has already interrupted the host then the host can miss the
2546 * There is still a possible race condition and the host could miss an
2547 * interrupt. The card has to take care of this.
2549 hw_consumer
= le32_to_cpu(*(tx_ring
->hw_consumer
));
2550 done
= (sw_consumer
== hw_consumer
);
2551 spin_unlock(&adapter
->tx_clean_lock
);
2556 static int qlcnic_poll(struct napi_struct
*napi
, int budget
)
2558 struct qlcnic_host_sds_ring
*sds_ring
=
2559 container_of(napi
, struct qlcnic_host_sds_ring
, napi
);
2561 struct qlcnic_adapter
*adapter
= sds_ring
->adapter
;
2566 tx_complete
= qlcnic_process_cmd_ring(adapter
);
2568 work_done
= qlcnic_process_rcv_ring(sds_ring
, budget
);
2570 if ((work_done
< budget
) && tx_complete
) {
2571 napi_complete(&sds_ring
->napi
);
2572 if (test_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
2573 qlcnic_enable_int(sds_ring
);
2579 static int qlcnic_rx_poll(struct napi_struct
*napi
, int budget
)
2581 struct qlcnic_host_sds_ring
*sds_ring
=
2582 container_of(napi
, struct qlcnic_host_sds_ring
, napi
);
2584 struct qlcnic_adapter
*adapter
= sds_ring
->adapter
;
2587 work_done
= qlcnic_process_rcv_ring(sds_ring
, budget
);
2589 if (work_done
< budget
) {
2590 napi_complete(&sds_ring
->napi
);
2591 if (test_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
2592 qlcnic_enable_int(sds_ring
);
2598 #ifdef CONFIG_NET_POLL_CONTROLLER
2599 static void qlcnic_poll_controller(struct net_device
*netdev
)
2602 struct qlcnic_host_sds_ring
*sds_ring
;
2603 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
2604 struct qlcnic_recv_context
*recv_ctx
= adapter
->recv_ctx
;
2606 disable_irq(adapter
->irq
);
2607 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
2608 sds_ring
= &recv_ctx
->sds_rings
[ring
];
2609 qlcnic_intr(adapter
->irq
, sds_ring
);
2611 enable_irq(adapter
->irq
);
2616 qlcnic_idc_debug_info(struct qlcnic_adapter
*adapter
, u8 encoding
)
2620 val
= adapter
->portnum
& 0xf;
2621 val
|= encoding
<< 7;
2622 val
|= (jiffies
- adapter
->dev_rst_time
) << 8;
2624 QLCWR32(adapter
, QLCNIC_CRB_DRV_SCRATCH
, val
);
2625 adapter
->dev_rst_time
= jiffies
;
2629 qlcnic_set_drv_state(struct qlcnic_adapter
*adapter
, u8 state
)
2633 WARN_ON(state
!= QLCNIC_DEV_NEED_RESET
&&
2634 state
!= QLCNIC_DEV_NEED_QUISCENT
);
2636 if (qlcnic_api_lock(adapter
))
2639 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_STATE
);
2641 if (state
== QLCNIC_DEV_NEED_RESET
)
2642 QLC_DEV_SET_RST_RDY(val
, adapter
->portnum
);
2643 else if (state
== QLCNIC_DEV_NEED_QUISCENT
)
2644 QLC_DEV_SET_QSCNT_RDY(val
, adapter
->portnum
);
2646 QLCWR32(adapter
, QLCNIC_CRB_DRV_STATE
, val
);
2648 qlcnic_api_unlock(adapter
);
2654 qlcnic_clr_drv_state(struct qlcnic_adapter
*adapter
)
2658 if (qlcnic_api_lock(adapter
))
2661 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_STATE
);
2662 QLC_DEV_CLR_RST_QSCNT(val
, adapter
->portnum
);
2663 QLCWR32(adapter
, QLCNIC_CRB_DRV_STATE
, val
);
2665 qlcnic_api_unlock(adapter
);
2671 qlcnic_clr_all_drv_state(struct qlcnic_adapter
*adapter
, u8 failed
)
2675 if (qlcnic_api_lock(adapter
))
2678 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_ACTIVE
);
2679 QLC_DEV_CLR_REF_CNT(val
, adapter
->portnum
);
2680 QLCWR32(adapter
, QLCNIC_CRB_DRV_ACTIVE
, val
);
2683 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
, QLCNIC_DEV_FAILED
);
2684 dev_info(&adapter
->pdev
->dev
,
2685 "Device state set to Failed. Please Reboot\n");
2686 } else if (!(val
& 0x11111111))
2687 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
, QLCNIC_DEV_COLD
);
2689 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_STATE
);
2690 QLC_DEV_CLR_RST_QSCNT(val
, adapter
->portnum
);
2691 QLCWR32(adapter
, QLCNIC_CRB_DRV_STATE
, val
);
2693 qlcnic_api_unlock(adapter
);
2695 adapter
->fw_fail_cnt
= 0;
2696 adapter
->flags
&= ~QLCNIC_FW_HANG
;
2697 clear_bit(__QLCNIC_START_FW
, &adapter
->state
);
2698 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
2701 /* Grab api lock, before checking state */
2703 qlcnic_check_drv_state(struct qlcnic_adapter
*adapter
)
2705 int act
, state
, active_mask
;
2707 state
= QLCRD32(adapter
, QLCNIC_CRB_DRV_STATE
);
2708 act
= QLCRD32(adapter
, QLCNIC_CRB_DRV_ACTIVE
);
2710 if (adapter
->flags
& QLCNIC_FW_RESET_OWNER
) {
2711 active_mask
= (~(1 << (adapter
->ahw
->pci_func
* 4)));
2712 act
= act
& active_mask
;
2715 if (((state
& 0x11111111) == (act
& 0x11111111)) ||
2716 ((act
& 0x11111111) == ((state
>> 1) & 0x11111111)))
2722 static int qlcnic_check_idc_ver(struct qlcnic_adapter
*adapter
)
2724 u32 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_IDC_VER
);
2726 if (val
!= QLCNIC_DRV_IDC_VER
) {
2727 dev_warn(&adapter
->pdev
->dev
, "IDC Version mismatch, driver's"
2728 " idc ver = %x; reqd = %x\n", QLCNIC_DRV_IDC_VER
, val
);
2735 qlcnic_can_start_firmware(struct qlcnic_adapter
*adapter
)
2737 u32 val
, prev_state
;
2738 u8 dev_init_timeo
= adapter
->dev_init_timeo
;
2739 u8 portnum
= adapter
->portnum
;
2742 if (test_and_clear_bit(__QLCNIC_START_FW
, &adapter
->state
))
2745 if (qlcnic_api_lock(adapter
))
2748 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_ACTIVE
);
2749 if (!(val
& (1 << (portnum
* 4)))) {
2750 QLC_DEV_SET_REF_CNT(val
, portnum
);
2751 QLCWR32(adapter
, QLCNIC_CRB_DRV_ACTIVE
, val
);
2754 prev_state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
);
2755 QLCDB(adapter
, HW
, "Device state = %u\n", prev_state
);
2757 switch (prev_state
) {
2758 case QLCNIC_DEV_COLD
:
2759 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
, QLCNIC_DEV_INITIALIZING
);
2760 QLCWR32(adapter
, QLCNIC_CRB_DRV_IDC_VER
, QLCNIC_DRV_IDC_VER
);
2761 qlcnic_idc_debug_info(adapter
, 0);
2762 qlcnic_api_unlock(adapter
);
2765 case QLCNIC_DEV_READY
:
2766 ret
= qlcnic_check_idc_ver(adapter
);
2767 qlcnic_api_unlock(adapter
);
2770 case QLCNIC_DEV_NEED_RESET
:
2771 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_STATE
);
2772 QLC_DEV_SET_RST_RDY(val
, portnum
);
2773 QLCWR32(adapter
, QLCNIC_CRB_DRV_STATE
, val
);
2776 case QLCNIC_DEV_NEED_QUISCENT
:
2777 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_STATE
);
2778 QLC_DEV_SET_QSCNT_RDY(val
, portnum
);
2779 QLCWR32(adapter
, QLCNIC_CRB_DRV_STATE
, val
);
2782 case QLCNIC_DEV_FAILED
:
2783 dev_err(&adapter
->pdev
->dev
, "Device in failed state.\n");
2784 qlcnic_api_unlock(adapter
);
2787 case QLCNIC_DEV_INITIALIZING
:
2788 case QLCNIC_DEV_QUISCENT
:
2792 qlcnic_api_unlock(adapter
);
2796 prev_state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
);
2798 if (prev_state
== QLCNIC_DEV_QUISCENT
)
2800 } while ((prev_state
!= QLCNIC_DEV_READY
) && --dev_init_timeo
);
2802 if (!dev_init_timeo
) {
2803 dev_err(&adapter
->pdev
->dev
,
2804 "Waiting for device to initialize timeout\n");
2808 if (qlcnic_api_lock(adapter
))
2811 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_STATE
);
2812 QLC_DEV_CLR_RST_QSCNT(val
, portnum
);
2813 QLCWR32(adapter
, QLCNIC_CRB_DRV_STATE
, val
);
2815 ret
= qlcnic_check_idc_ver(adapter
);
2816 qlcnic_api_unlock(adapter
);
2822 qlcnic_fwinit_work(struct work_struct
*work
)
2824 struct qlcnic_adapter
*adapter
= container_of(work
,
2825 struct qlcnic_adapter
, fw_work
.work
);
2826 u32 dev_state
= 0xf;
2829 if (qlcnic_api_lock(adapter
))
2832 dev_state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
);
2833 if (dev_state
== QLCNIC_DEV_QUISCENT
||
2834 dev_state
== QLCNIC_DEV_NEED_QUISCENT
) {
2835 qlcnic_api_unlock(adapter
);
2836 qlcnic_schedule_work(adapter
, qlcnic_fwinit_work
,
2841 if (adapter
->op_mode
== QLCNIC_NON_PRIV_FUNC
) {
2842 qlcnic_api_unlock(adapter
);
2846 if (dev_state
== QLCNIC_DEV_INITIALIZING
||
2847 dev_state
== QLCNIC_DEV_READY
) {
2848 dev_info(&adapter
->pdev
->dev
, "Detected state change from "
2849 "DEV_NEED_RESET, skipping ack check\n");
2850 goto skip_ack_check
;
2853 if (adapter
->fw_wait_cnt
++ > adapter
->reset_ack_timeo
) {
2854 dev_info(&adapter
->pdev
->dev
, "Reset:Failed to get ack %d sec\n",
2855 adapter
->reset_ack_timeo
);
2856 goto skip_ack_check
;
2859 if (!qlcnic_check_drv_state(adapter
)) {
2861 dev_state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
);
2863 if (dev_state
== QLCNIC_DEV_NEED_RESET
) {
2864 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
,
2865 QLCNIC_DEV_INITIALIZING
);
2866 set_bit(__QLCNIC_START_FW
, &adapter
->state
);
2867 QLCDB(adapter
, DRV
, "Restarting fw\n");
2868 qlcnic_idc_debug_info(adapter
, 0);
2869 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_STATE
);
2870 QLC_DEV_SET_RST_RDY(val
, adapter
->portnum
);
2871 QLCWR32(adapter
, QLCNIC_CRB_DRV_STATE
, val
);
2874 qlcnic_api_unlock(adapter
);
2877 if (adapter
->ahw
->fw_dump
.enable
&&
2878 (adapter
->flags
& QLCNIC_FW_RESET_OWNER
)) {
2879 QLCDB(adapter
, DRV
, "Take FW dump\n");
2880 qlcnic_dump_fw(adapter
);
2881 adapter
->flags
|= QLCNIC_FW_HANG
;
2885 adapter
->flags
&= ~QLCNIC_FW_RESET_OWNER
;
2886 if (!adapter
->nic_ops
->start_firmware(adapter
)) {
2887 qlcnic_schedule_work(adapter
, qlcnic_attach_work
, 0);
2888 adapter
->fw_wait_cnt
= 0;
2894 qlcnic_api_unlock(adapter
);
2897 dev_state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
);
2898 QLCDB(adapter
, HW
, "Func waiting: Device state=%u\n", dev_state
);
2900 switch (dev_state
) {
2901 case QLCNIC_DEV_READY
:
2902 if (!adapter
->nic_ops
->start_firmware(adapter
)) {
2903 qlcnic_schedule_work(adapter
, qlcnic_attach_work
, 0);
2904 adapter
->fw_wait_cnt
= 0;
2907 case QLCNIC_DEV_FAILED
:
2910 qlcnic_schedule_work(adapter
,
2911 qlcnic_fwinit_work
, FW_POLL_DELAY
);
2916 dev_err(&adapter
->pdev
->dev
, "Fwinit work failed state=%u "
2917 "fw_wait_cnt=%u\n", dev_state
, adapter
->fw_wait_cnt
);
2918 netif_device_attach(adapter
->netdev
);
2919 qlcnic_clr_all_drv_state(adapter
, 0);
2923 qlcnic_detach_work(struct work_struct
*work
)
2925 struct qlcnic_adapter
*adapter
= container_of(work
,
2926 struct qlcnic_adapter
, fw_work
.work
);
2927 struct net_device
*netdev
= adapter
->netdev
;
2930 netif_device_detach(netdev
);
2932 /* Dont grab rtnl lock during Quiscent mode */
2933 if (adapter
->dev_state
== QLCNIC_DEV_NEED_QUISCENT
) {
2934 if (netif_running(netdev
))
2935 __qlcnic_down(adapter
, netdev
);
2937 qlcnic_down(adapter
, netdev
);
2939 status
= QLCRD32(adapter
, QLCNIC_PEG_HALT_STATUS1
);
2941 if (status
& QLCNIC_RCODE_FATAL_ERROR
) {
2942 dev_err(&adapter
->pdev
->dev
,
2943 "Detaching the device: peg halt status1=0x%x\n",
2946 if (QLCNIC_FWERROR_CODE(status
) == QLCNIC_FWERROR_FAN_FAILURE
) {
2947 dev_err(&adapter
->pdev
->dev
,
2948 "On board active cooling fan failed. "
2949 "Device has been halted.\n");
2950 dev_err(&adapter
->pdev
->dev
,
2951 "Replace the adapter.\n");
2957 if (adapter
->temp
== QLCNIC_TEMP_PANIC
) {
2958 dev_err(&adapter
->pdev
->dev
, "Detaching the device: temp=%d\n",
2963 /* Dont ack if this instance is the reset owner */
2964 if (!(adapter
->flags
& QLCNIC_FW_RESET_OWNER
)) {
2965 if (qlcnic_set_drv_state(adapter
, adapter
->dev_state
)) {
2966 dev_err(&adapter
->pdev
->dev
,
2967 "Failed to set driver state,"
2968 "detaching the device.\n");
2973 adapter
->fw_wait_cnt
= 0;
2975 qlcnic_schedule_work(adapter
, qlcnic_fwinit_work
, FW_POLL_DELAY
);
2980 netif_device_attach(netdev
);
2981 qlcnic_clr_all_drv_state(adapter
, 1);
2984 /*Transit NPAR state to NON Operational */
2986 qlcnic_set_npar_non_operational(struct qlcnic_adapter
*adapter
)
2990 state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_NPAR_STATE
);
2991 if (state
== QLCNIC_DEV_NPAR_NON_OPER
)
2994 if (qlcnic_api_lock(adapter
))
2996 QLCWR32(adapter
, QLCNIC_CRB_DEV_NPAR_STATE
, QLCNIC_DEV_NPAR_NON_OPER
);
2997 qlcnic_api_unlock(adapter
);
3000 /*Transit to RESET state from READY state only */
3002 qlcnic_dev_request_reset(struct qlcnic_adapter
*adapter
)
3004 u32 state
, xg_val
= 0, gb_val
= 0;
3006 qlcnic_xg_set_xg0_mask(xg_val
);
3007 qlcnic_xg_set_xg1_mask(xg_val
);
3008 QLCWR32(adapter
, QLCNIC_NIU_XG_PAUSE_CTL
, xg_val
);
3009 qlcnic_gb_set_gb0_mask(gb_val
);
3010 qlcnic_gb_set_gb1_mask(gb_val
);
3011 qlcnic_gb_set_gb2_mask(gb_val
);
3012 qlcnic_gb_set_gb3_mask(gb_val
);
3013 QLCWR32(adapter
, QLCNIC_NIU_GB_PAUSE_CTL
, gb_val
);
3014 dev_info(&adapter
->pdev
->dev
, "Pause control frames disabled"
3016 adapter
->need_fw_reset
= 1;
3017 if (qlcnic_api_lock(adapter
))
3020 state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
);
3022 if (state
== QLCNIC_DEV_READY
) {
3023 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
, QLCNIC_DEV_NEED_RESET
);
3024 adapter
->flags
|= QLCNIC_FW_RESET_OWNER
;
3025 QLCDB(adapter
, DRV
, "NEED_RESET state set\n");
3026 qlcnic_idc_debug_info(adapter
, 0);
3029 QLCWR32(adapter
, QLCNIC_CRB_DEV_NPAR_STATE
, QLCNIC_DEV_NPAR_NON_OPER
);
3030 qlcnic_api_unlock(adapter
);
3033 /* Transit to NPAR READY state from NPAR NOT READY state */
3035 qlcnic_dev_set_npar_ready(struct qlcnic_adapter
*adapter
)
3037 if (qlcnic_api_lock(adapter
))
3040 QLCWR32(adapter
, QLCNIC_CRB_DEV_NPAR_STATE
, QLCNIC_DEV_NPAR_OPER
);
3041 QLCDB(adapter
, DRV
, "NPAR operational state set\n");
3043 qlcnic_api_unlock(adapter
);
3047 qlcnic_schedule_work(struct qlcnic_adapter
*adapter
,
3048 work_func_t func
, int delay
)
3050 if (test_bit(__QLCNIC_AER
, &adapter
->state
))
3053 INIT_DELAYED_WORK(&adapter
->fw_work
, func
);
3054 queue_delayed_work(qlcnic_wq
, &adapter
->fw_work
,
3055 round_jiffies_relative(delay
));
3059 qlcnic_cancel_fw_work(struct qlcnic_adapter
*adapter
)
3061 while (test_and_set_bit(__QLCNIC_RESETTING
, &adapter
->state
))
3064 cancel_delayed_work_sync(&adapter
->fw_work
);
3068 qlcnic_attach_work(struct work_struct
*work
)
3070 struct qlcnic_adapter
*adapter
= container_of(work
,
3071 struct qlcnic_adapter
, fw_work
.work
);
3072 struct net_device
*netdev
= adapter
->netdev
;
3075 if (adapter
->op_mode
!= QLCNIC_MGMT_FUNC
) {
3076 npar_state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_NPAR_STATE
);
3077 if (adapter
->fw_wait_cnt
++ > QLCNIC_DEV_NPAR_OPER_TIMEO
)
3078 qlcnic_clr_all_drv_state(adapter
, 0);
3079 else if (npar_state
!= QLCNIC_DEV_NPAR_OPER
)
3080 qlcnic_schedule_work(adapter
, qlcnic_attach_work
,
3084 QLCDB(adapter
, DRV
, "Waiting for NPAR state to operational\n");
3088 if (netif_running(netdev
)) {
3089 if (qlcnic_up(adapter
, netdev
))
3092 qlcnic_restore_indev_addr(netdev
, NETDEV_UP
);
3096 netif_device_attach(netdev
);
3097 adapter
->fw_fail_cnt
= 0;
3098 adapter
->flags
&= ~QLCNIC_FW_HANG
;
3099 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
3101 if (!qlcnic_clr_drv_state(adapter
))
3102 qlcnic_schedule_work(adapter
, qlcnic_fw_poll_work
,
3107 qlcnic_check_health(struct qlcnic_adapter
*adapter
)
3109 u32 state
= 0, heartbeat
;
3112 if (qlcnic_check_temp(adapter
))
3115 if (adapter
->need_fw_reset
)
3116 qlcnic_dev_request_reset(adapter
);
3118 state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
);
3119 if (state
== QLCNIC_DEV_NEED_RESET
) {
3120 qlcnic_set_npar_non_operational(adapter
);
3121 adapter
->need_fw_reset
= 1;
3122 } else if (state
== QLCNIC_DEV_NEED_QUISCENT
)
3125 heartbeat
= QLCRD32(adapter
, QLCNIC_PEG_ALIVE_COUNTER
);
3126 if (heartbeat
!= adapter
->heartbeat
) {
3127 adapter
->heartbeat
= heartbeat
;
3128 adapter
->fw_fail_cnt
= 0;
3129 if (adapter
->need_fw_reset
)
3132 if (adapter
->reset_context
&& auto_fw_reset
) {
3133 qlcnic_reset_hw_context(adapter
);
3134 adapter
->netdev
->trans_start
= jiffies
;
3140 if (++adapter
->fw_fail_cnt
< FW_FAIL_THRESH
)
3143 adapter
->flags
|= QLCNIC_FW_HANG
;
3145 qlcnic_dev_request_reset(adapter
);
3148 clear_bit(__QLCNIC_FW_ATTACHED
, &adapter
->state
);
3150 dev_err(&adapter
->pdev
->dev
, "firmware hang detected\n");
3151 dev_err(&adapter
->pdev
->dev
, "Dumping hw/fw registers\n"
3152 "PEG_HALT_STATUS1: 0x%x, PEG_HALT_STATUS2: 0x%x,\n"
3153 "PEG_NET_0_PC: 0x%x, PEG_NET_1_PC: 0x%x,\n"
3154 "PEG_NET_2_PC: 0x%x, PEG_NET_3_PC: 0x%x,\n"
3155 "PEG_NET_4_PC: 0x%x\n",
3156 QLCRD32(adapter
, QLCNIC_PEG_HALT_STATUS1
),
3157 QLCRD32(adapter
, QLCNIC_PEG_HALT_STATUS2
),
3158 QLCRD32(adapter
, QLCNIC_CRB_PEG_NET_0
+ 0x3c),
3159 QLCRD32(adapter
, QLCNIC_CRB_PEG_NET_1
+ 0x3c),
3160 QLCRD32(adapter
, QLCNIC_CRB_PEG_NET_2
+ 0x3c),
3161 QLCRD32(adapter
, QLCNIC_CRB_PEG_NET_3
+ 0x3c),
3162 QLCRD32(adapter
, QLCNIC_CRB_PEG_NET_4
+ 0x3c));
3163 peg_status
= QLCRD32(adapter
, QLCNIC_PEG_HALT_STATUS1
);
3164 if (QLCNIC_FWERROR_CODE(peg_status
) == 0x67)
3165 dev_err(&adapter
->pdev
->dev
,
3166 "Firmware aborted with error code 0x00006700. "
3167 "Device is being reset.\n");
3169 adapter
->dev_state
= (state
== QLCNIC_DEV_NEED_QUISCENT
) ? state
:
3170 QLCNIC_DEV_NEED_RESET
;
3172 if (auto_fw_reset
&&
3173 !test_and_set_bit(__QLCNIC_RESETTING
, &adapter
->state
)) {
3175 qlcnic_schedule_work(adapter
, qlcnic_detach_work
, 0);
3176 QLCDB(adapter
, DRV
, "fw recovery scheduled.\n");
3183 qlcnic_fw_poll_work(struct work_struct
*work
)
3185 struct qlcnic_adapter
*adapter
= container_of(work
,
3186 struct qlcnic_adapter
, fw_work
.work
);
3188 if (test_bit(__QLCNIC_RESETTING
, &adapter
->state
))
3192 if (qlcnic_check_health(adapter
))
3195 if (adapter
->fhash
.fnum
)
3196 qlcnic_prune_lb_filters(adapter
);
3199 qlcnic_schedule_work(adapter
, qlcnic_fw_poll_work
, FW_POLL_DELAY
);
3202 static int qlcnic_is_first_func(struct pci_dev
*pdev
)
3204 struct pci_dev
*oth_pdev
;
3205 int val
= pdev
->devfn
;
3208 oth_pdev
= pci_get_domain_bus_and_slot(pci_domain_nr
3209 (pdev
->bus
), pdev
->bus
->number
,
3210 PCI_DEVFN(PCI_SLOT(pdev
->devfn
), val
));
3214 if (oth_pdev
->current_state
!= PCI_D3cold
) {
3215 pci_dev_put(oth_pdev
);
3218 pci_dev_put(oth_pdev
);
3223 static int qlcnic_attach_func(struct pci_dev
*pdev
)
3225 int err
, first_func
;
3226 struct qlcnic_adapter
*adapter
= pci_get_drvdata(pdev
);
3227 struct net_device
*netdev
= adapter
->netdev
;
3229 pdev
->error_state
= pci_channel_io_normal
;
3231 err
= pci_enable_device(pdev
);
3235 pci_set_power_state(pdev
, PCI_D0
);
3236 pci_set_master(pdev
);
3237 pci_restore_state(pdev
);
3239 first_func
= qlcnic_is_first_func(pdev
);
3241 if (qlcnic_api_lock(adapter
))
3244 if (adapter
->op_mode
!= QLCNIC_NON_PRIV_FUNC
&& first_func
) {
3245 adapter
->need_fw_reset
= 1;
3246 set_bit(__QLCNIC_START_FW
, &adapter
->state
);
3247 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
, QLCNIC_DEV_INITIALIZING
);
3248 QLCDB(adapter
, DRV
, "Restarting fw\n");
3250 qlcnic_api_unlock(adapter
);
3252 err
= adapter
->nic_ops
->start_firmware(adapter
);
3256 qlcnic_clr_drv_state(adapter
);
3257 qlcnic_setup_intr(adapter
);
3259 if (netif_running(netdev
)) {
3260 err
= qlcnic_attach(adapter
);
3262 qlcnic_clr_all_drv_state(adapter
, 1);
3263 clear_bit(__QLCNIC_AER
, &adapter
->state
);
3264 netif_device_attach(netdev
);
3268 err
= qlcnic_up(adapter
, netdev
);
3272 qlcnic_restore_indev_addr(netdev
, NETDEV_UP
);
3275 netif_device_attach(netdev
);
3279 static pci_ers_result_t
qlcnic_io_error_detected(struct pci_dev
*pdev
,
3280 pci_channel_state_t state
)
3282 struct qlcnic_adapter
*adapter
= pci_get_drvdata(pdev
);
3283 struct net_device
*netdev
= adapter
->netdev
;
3285 if (state
== pci_channel_io_perm_failure
)
3286 return PCI_ERS_RESULT_DISCONNECT
;
3288 if (state
== pci_channel_io_normal
)
3289 return PCI_ERS_RESULT_RECOVERED
;
3291 set_bit(__QLCNIC_AER
, &adapter
->state
);
3292 netif_device_detach(netdev
);
3294 cancel_delayed_work_sync(&adapter
->fw_work
);
3296 if (netif_running(netdev
))
3297 qlcnic_down(adapter
, netdev
);
3299 qlcnic_detach(adapter
);
3300 qlcnic_teardown_intr(adapter
);
3302 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
3304 pci_save_state(pdev
);
3305 pci_disable_device(pdev
);
3307 return PCI_ERS_RESULT_NEED_RESET
;
3310 static pci_ers_result_t
qlcnic_io_slot_reset(struct pci_dev
*pdev
)
3312 return qlcnic_attach_func(pdev
) ? PCI_ERS_RESULT_DISCONNECT
:
3313 PCI_ERS_RESULT_RECOVERED
;
3316 static void qlcnic_io_resume(struct pci_dev
*pdev
)
3318 struct qlcnic_adapter
*adapter
= pci_get_drvdata(pdev
);
3320 pci_cleanup_aer_uncorrect_error_status(pdev
);
3322 if (QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
) == QLCNIC_DEV_READY
&&
3323 test_and_clear_bit(__QLCNIC_AER
, &adapter
->state
))
3324 qlcnic_schedule_work(adapter
, qlcnic_fw_poll_work
,
3329 qlcnicvf_start_firmware(struct qlcnic_adapter
*adapter
)
3333 err
= qlcnic_can_start_firmware(adapter
);
3337 err
= qlcnic_check_npar_opertional(adapter
);
3341 err
= qlcnic_initialize_nic(adapter
);
3345 qlcnic_check_options(adapter
);
3347 err
= qlcnic_set_eswitch_port_config(adapter
);
3351 adapter
->need_fw_reset
= 0;
3357 qlcnicvf_config_bridged_mode(struct qlcnic_adapter
*adapter
, u32 enable
)
3363 qlcnicvf_config_led(struct qlcnic_adapter
*adapter
, u32 state
, u32 rate
)
3369 qlcnic_store_bridged_mode(struct device
*dev
,
3370 struct device_attribute
*attr
, const char *buf
, size_t len
)
3372 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3376 if (!(adapter
->capabilities
& QLCNIC_FW_CAPABILITY_BDG
))
3379 if (!test_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
3382 if (strict_strtoul(buf
, 2, &new))
3385 if (!adapter
->nic_ops
->config_bridged_mode(adapter
, !!new))
3393 qlcnic_show_bridged_mode(struct device
*dev
,
3394 struct device_attribute
*attr
, char *buf
)
3396 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3397 int bridged_mode
= 0;
3399 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_BDG
)
3400 bridged_mode
= !!(adapter
->flags
& QLCNIC_BRIDGE_ENABLED
);
3402 return sprintf(buf
, "%d\n", bridged_mode
);
3405 static struct device_attribute dev_attr_bridged_mode
= {
3406 .attr
= {.name
= "bridged_mode", .mode
= (S_IRUGO
| S_IWUSR
)},
3407 .show
= qlcnic_show_bridged_mode
,
3408 .store
= qlcnic_store_bridged_mode
,
3412 qlcnic_store_diag_mode(struct device
*dev
,
3413 struct device_attribute
*attr
, const char *buf
, size_t len
)
3415 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3418 if (strict_strtoul(buf
, 2, &new))
3421 if (!!new != !!(adapter
->flags
& QLCNIC_DIAG_ENABLED
))
3422 adapter
->flags
^= QLCNIC_DIAG_ENABLED
;
3428 qlcnic_show_diag_mode(struct device
*dev
,
3429 struct device_attribute
*attr
, char *buf
)
3431 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3433 return sprintf(buf
, "%d\n",
3434 !!(adapter
->flags
& QLCNIC_DIAG_ENABLED
));
3437 static struct device_attribute dev_attr_diag_mode
= {
3438 .attr
= {.name
= "diag_mode", .mode
= (S_IRUGO
| S_IWUSR
)},
3439 .show
= qlcnic_show_diag_mode
,
3440 .store
= qlcnic_store_diag_mode
,
3443 int qlcnic_validate_max_rss(struct net_device
*netdev
, u8 max_hw
, u8 val
)
3445 if (!use_msi_x
&& !use_msi
) {
3446 netdev_info(netdev
, "no msix or msi support, hence no rss\n");
3450 if ((val
> max_hw
) || (val
< 2) || !is_power_of_2(val
)) {
3451 netdev_info(netdev
, "rss_ring valid range [2 - %x] in "
3452 " powers of 2\n", max_hw
);
3459 int qlcnic_set_max_rss(struct qlcnic_adapter
*adapter
, u8 data
)
3461 struct net_device
*netdev
= adapter
->netdev
;
3464 if (test_and_set_bit(__QLCNIC_RESETTING
, &adapter
->state
))
3467 netif_device_detach(netdev
);
3468 if (netif_running(netdev
))
3469 __qlcnic_down(adapter
, netdev
);
3470 qlcnic_detach(adapter
);
3471 qlcnic_teardown_intr(adapter
);
3473 if (qlcnic_enable_msix(adapter
, data
)) {
3474 netdev_info(netdev
, "failed setting max_rss; rss disabled\n");
3475 qlcnic_enable_msi_legacy(adapter
);
3478 if (netif_running(netdev
)) {
3479 err
= qlcnic_attach(adapter
);
3482 err
= __qlcnic_up(adapter
, netdev
);
3485 qlcnic_restore_indev_addr(netdev
, NETDEV_UP
);
3488 netif_device_attach(netdev
);
3489 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
3494 qlcnic_validate_beacon(struct qlcnic_adapter
*adapter
, u16 beacon
, u8
*state
,
3497 *rate
= LSB(beacon
);
3498 *state
= MSB(beacon
);
3500 QLCDB(adapter
, DRV
, "rate %x state %x\n", *rate
, *state
);
3503 *rate
= __QLCNIC_MAX_LED_RATE
;
3505 } else if (*state
> __QLCNIC_MAX_LED_STATE
)
3508 if ((!*rate
) || (*rate
> __QLCNIC_MAX_LED_RATE
))
3515 qlcnic_store_beacon(struct device
*dev
,
3516 struct device_attribute
*attr
, const char *buf
, size_t len
)
3518 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3519 int max_sds_rings
= adapter
->max_sds_rings
;
3524 if (adapter
->op_mode
== QLCNIC_NON_PRIV_FUNC
) {
3525 dev_warn(dev
, "LED test not supported for non "
3526 "privilege function\n");
3530 if (len
!= sizeof(u16
))
3531 return QL_STATUS_INVALID_PARAM
;
3533 memcpy(&beacon
, buf
, sizeof(u16
));
3534 err
= qlcnic_validate_beacon(adapter
, beacon
, &b_state
, &b_rate
);
3538 if (adapter
->ahw
->beacon_state
== b_state
)
3543 if (!adapter
->ahw
->beacon_state
)
3544 if (test_and_set_bit(__QLCNIC_LED_ENABLE
, &adapter
->state
)) {
3549 if (test_bit(__QLCNIC_RESETTING
, &adapter
->state
)) {
3554 if (!test_bit(__QLCNIC_DEV_UP
, &adapter
->state
)) {
3555 err
= qlcnic_diag_alloc_res(adapter
->netdev
, QLCNIC_LED_TEST
);
3558 set_bit(__QLCNIC_DIAG_RES_ALLOC
, &adapter
->state
);
3561 err
= qlcnic_config_led(adapter
, b_state
, b_rate
);
3565 adapter
->ahw
->beacon_state
= b_state
;
3568 if (test_and_clear_bit(__QLCNIC_DIAG_RES_ALLOC
, &adapter
->state
))
3569 qlcnic_diag_free_res(adapter
->netdev
, max_sds_rings
);
3572 if (!adapter
->ahw
->beacon_state
)
3573 clear_bit(__QLCNIC_LED_ENABLE
, &adapter
->state
);
3580 qlcnic_show_beacon(struct device
*dev
,
3581 struct device_attribute
*attr
, char *buf
)
3583 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3585 return sprintf(buf
, "%d\n", adapter
->ahw
->beacon_state
);
3588 static struct device_attribute dev_attr_beacon
= {
3589 .attr
= {.name
= "beacon", .mode
= (S_IRUGO
| S_IWUSR
)},
3590 .show
= qlcnic_show_beacon
,
3591 .store
= qlcnic_store_beacon
,
3595 qlcnic_sysfs_validate_crb(struct qlcnic_adapter
*adapter
,
3596 loff_t offset
, size_t size
)
3598 size_t crb_size
= 4;
3600 if (!(adapter
->flags
& QLCNIC_DIAG_ENABLED
))
3603 if (offset
< QLCNIC_PCI_CRBSPACE
) {
3604 if (ADDR_IN_RANGE(offset
, QLCNIC_PCI_CAMQM
,
3605 QLCNIC_PCI_CAMQM_END
))
3611 if ((size
!= crb_size
) || (offset
& (crb_size
-1)))
3618 qlcnic_sysfs_read_crb(struct file
*filp
, struct kobject
*kobj
,
3619 struct bin_attribute
*attr
,
3620 char *buf
, loff_t offset
, size_t size
)
3622 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3623 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3628 ret
= qlcnic_sysfs_validate_crb(adapter
, offset
, size
);
3632 if (ADDR_IN_RANGE(offset
, QLCNIC_PCI_CAMQM
, QLCNIC_PCI_CAMQM_END
)) {
3633 qlcnic_pci_camqm_read_2M(adapter
, offset
, &qmdata
);
3634 memcpy(buf
, &qmdata
, size
);
3636 data
= QLCRD32(adapter
, offset
);
3637 memcpy(buf
, &data
, size
);
3643 qlcnic_sysfs_write_crb(struct file
*filp
, struct kobject
*kobj
,
3644 struct bin_attribute
*attr
,
3645 char *buf
, loff_t offset
, size_t size
)
3647 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3648 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3653 ret
= qlcnic_sysfs_validate_crb(adapter
, offset
, size
);
3657 if (ADDR_IN_RANGE(offset
, QLCNIC_PCI_CAMQM
, QLCNIC_PCI_CAMQM_END
)) {
3658 memcpy(&qmdata
, buf
, size
);
3659 qlcnic_pci_camqm_write_2M(adapter
, offset
, qmdata
);
3661 memcpy(&data
, buf
, size
);
3662 QLCWR32(adapter
, offset
, data
);
3668 qlcnic_sysfs_validate_mem(struct qlcnic_adapter
*adapter
,
3669 loff_t offset
, size_t size
)
3671 if (!(adapter
->flags
& QLCNIC_DIAG_ENABLED
))
3674 if ((size
!= 8) || (offset
& 0x7))
3681 qlcnic_sysfs_read_mem(struct file
*filp
, struct kobject
*kobj
,
3682 struct bin_attribute
*attr
,
3683 char *buf
, loff_t offset
, size_t size
)
3685 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3686 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3690 ret
= qlcnic_sysfs_validate_mem(adapter
, offset
, size
);
3694 if (qlcnic_pci_mem_read_2M(adapter
, offset
, &data
))
3697 memcpy(buf
, &data
, size
);
3703 qlcnic_sysfs_write_mem(struct file
*filp
, struct kobject
*kobj
,
3704 struct bin_attribute
*attr
,
3705 char *buf
, loff_t offset
, size_t size
)
3707 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3708 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3712 ret
= qlcnic_sysfs_validate_mem(adapter
, offset
, size
);
3716 memcpy(&data
, buf
, size
);
3718 if (qlcnic_pci_mem_write_2M(adapter
, offset
, data
))
3724 static struct bin_attribute bin_attr_crb
= {
3725 .attr
= {.name
= "crb", .mode
= (S_IRUGO
| S_IWUSR
)},
3727 .read
= qlcnic_sysfs_read_crb
,
3728 .write
= qlcnic_sysfs_write_crb
,
3731 static struct bin_attribute bin_attr_mem
= {
3732 .attr
= {.name
= "mem", .mode
= (S_IRUGO
| S_IWUSR
)},
3734 .read
= qlcnic_sysfs_read_mem
,
3735 .write
= qlcnic_sysfs_write_mem
,
3739 validate_pm_config(struct qlcnic_adapter
*adapter
,
3740 struct qlcnic_pm_func_cfg
*pm_cfg
, int count
)
3743 u8 src_pci_func
, s_esw_id
, d_esw_id
;
3747 for (i
= 0; i
< count
; i
++) {
3748 src_pci_func
= pm_cfg
[i
].pci_func
;
3749 dest_pci_func
= pm_cfg
[i
].dest_npar
;
3750 if (src_pci_func
>= QLCNIC_MAX_PCI_FUNC
3751 || dest_pci_func
>= QLCNIC_MAX_PCI_FUNC
)
3752 return QL_STATUS_INVALID_PARAM
;
3754 if (adapter
->npars
[src_pci_func
].type
!= QLCNIC_TYPE_NIC
)
3755 return QL_STATUS_INVALID_PARAM
;
3757 if (adapter
->npars
[dest_pci_func
].type
!= QLCNIC_TYPE_NIC
)
3758 return QL_STATUS_INVALID_PARAM
;
3760 s_esw_id
= adapter
->npars
[src_pci_func
].phy_port
;
3761 d_esw_id
= adapter
->npars
[dest_pci_func
].phy_port
;
3763 if (s_esw_id
!= d_esw_id
)
3764 return QL_STATUS_INVALID_PARAM
;
3772 qlcnic_sysfs_write_pm_config(struct file
*filp
, struct kobject
*kobj
,
3773 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3775 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3776 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3777 struct qlcnic_pm_func_cfg
*pm_cfg
;
3778 u32 id
, action
, pci_func
;
3779 int count
, rem
, i
, ret
;
3781 count
= size
/ sizeof(struct qlcnic_pm_func_cfg
);
3782 rem
= size
% sizeof(struct qlcnic_pm_func_cfg
);
3784 return QL_STATUS_INVALID_PARAM
;
3786 pm_cfg
= (struct qlcnic_pm_func_cfg
*) buf
;
3788 ret
= validate_pm_config(adapter
, pm_cfg
, count
);
3791 for (i
= 0; i
< count
; i
++) {
3792 pci_func
= pm_cfg
[i
].pci_func
;
3793 action
= !!pm_cfg
[i
].action
;
3794 id
= adapter
->npars
[pci_func
].phy_port
;
3795 ret
= qlcnic_config_port_mirroring(adapter
, id
,
3801 for (i
= 0; i
< count
; i
++) {
3802 pci_func
= pm_cfg
[i
].pci_func
;
3803 id
= adapter
->npars
[pci_func
].phy_port
;
3804 adapter
->npars
[pci_func
].enable_pm
= !!pm_cfg
[i
].action
;
3805 adapter
->npars
[pci_func
].dest_npar
= id
;
3811 qlcnic_sysfs_read_pm_config(struct file
*filp
, struct kobject
*kobj
,
3812 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3814 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3815 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3816 struct qlcnic_pm_func_cfg pm_cfg
[QLCNIC_MAX_PCI_FUNC
];
3819 if (size
!= sizeof(pm_cfg
))
3820 return QL_STATUS_INVALID_PARAM
;
3822 for (i
= 0; i
< QLCNIC_MAX_PCI_FUNC
; i
++) {
3823 if (adapter
->npars
[i
].type
!= QLCNIC_TYPE_NIC
)
3825 pm_cfg
[i
].action
= adapter
->npars
[i
].enable_pm
;
3826 pm_cfg
[i
].dest_npar
= 0;
3827 pm_cfg
[i
].pci_func
= i
;
3829 memcpy(buf
, &pm_cfg
, size
);
3835 validate_esw_config(struct qlcnic_adapter
*adapter
,
3836 struct qlcnic_esw_func_cfg
*esw_cfg
, int count
)
3842 op_mode
= readl(adapter
->ahw
->pci_base0
+ QLCNIC_DRV_OP_MODE
);
3844 for (i
= 0; i
< count
; i
++) {
3845 pci_func
= esw_cfg
[i
].pci_func
;
3846 if (pci_func
>= QLCNIC_MAX_PCI_FUNC
)
3847 return QL_STATUS_INVALID_PARAM
;
3849 if (adapter
->op_mode
== QLCNIC_MGMT_FUNC
)
3850 if (adapter
->npars
[pci_func
].type
!= QLCNIC_TYPE_NIC
)
3851 return QL_STATUS_INVALID_PARAM
;
3853 switch (esw_cfg
[i
].op_mode
) {
3854 case QLCNIC_PORT_DEFAULTS
:
3855 if (QLC_DEV_GET_DRV(op_mode
, pci_func
) !=
3856 QLCNIC_NON_PRIV_FUNC
) {
3857 if (esw_cfg
[i
].mac_anti_spoof
!= 0)
3858 return QL_STATUS_INVALID_PARAM
;
3859 if (esw_cfg
[i
].mac_override
!= 1)
3860 return QL_STATUS_INVALID_PARAM
;
3861 if (esw_cfg
[i
].promisc_mode
!= 1)
3862 return QL_STATUS_INVALID_PARAM
;
3865 case QLCNIC_ADD_VLAN
:
3866 if (!IS_VALID_VLAN(esw_cfg
[i
].vlan_id
))
3867 return QL_STATUS_INVALID_PARAM
;
3868 if (!esw_cfg
[i
].op_type
)
3869 return QL_STATUS_INVALID_PARAM
;
3871 case QLCNIC_DEL_VLAN
:
3872 if (!esw_cfg
[i
].op_type
)
3873 return QL_STATUS_INVALID_PARAM
;
3876 return QL_STATUS_INVALID_PARAM
;
3883 qlcnic_sysfs_write_esw_config(struct file
*file
, struct kobject
*kobj
,
3884 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3886 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3887 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3888 struct qlcnic_esw_func_cfg
*esw_cfg
;
3889 struct qlcnic_npar_info
*npar
;
3890 int count
, rem
, i
, ret
;
3891 u8 pci_func
, op_mode
= 0;
3893 count
= size
/ sizeof(struct qlcnic_esw_func_cfg
);
3894 rem
= size
% sizeof(struct qlcnic_esw_func_cfg
);
3896 return QL_STATUS_INVALID_PARAM
;
3898 esw_cfg
= (struct qlcnic_esw_func_cfg
*) buf
;
3899 ret
= validate_esw_config(adapter
, esw_cfg
, count
);
3903 for (i
= 0; i
< count
; i
++) {
3904 if (adapter
->op_mode
== QLCNIC_MGMT_FUNC
)
3905 if (qlcnic_config_switch_port(adapter
, &esw_cfg
[i
]))
3906 return QL_STATUS_INVALID_PARAM
;
3908 if (adapter
->ahw
->pci_func
!= esw_cfg
[i
].pci_func
)
3911 op_mode
= esw_cfg
[i
].op_mode
;
3912 qlcnic_get_eswitch_port_config(adapter
, &esw_cfg
[i
]);
3913 esw_cfg
[i
].op_mode
= op_mode
;
3914 esw_cfg
[i
].pci_func
= adapter
->ahw
->pci_func
;
3916 switch (esw_cfg
[i
].op_mode
) {
3917 case QLCNIC_PORT_DEFAULTS
:
3918 qlcnic_set_eswitch_port_features(adapter
, &esw_cfg
[i
]);
3920 case QLCNIC_ADD_VLAN
:
3921 qlcnic_set_vlan_config(adapter
, &esw_cfg
[i
]);
3923 case QLCNIC_DEL_VLAN
:
3924 esw_cfg
[i
].vlan_id
= 0;
3925 qlcnic_set_vlan_config(adapter
, &esw_cfg
[i
]);
3930 if (adapter
->op_mode
!= QLCNIC_MGMT_FUNC
)
3933 for (i
= 0; i
< count
; i
++) {
3934 pci_func
= esw_cfg
[i
].pci_func
;
3935 npar
= &adapter
->npars
[pci_func
];
3936 switch (esw_cfg
[i
].op_mode
) {
3937 case QLCNIC_PORT_DEFAULTS
:
3938 npar
->promisc_mode
= esw_cfg
[i
].promisc_mode
;
3939 npar
->mac_override
= esw_cfg
[i
].mac_override
;
3940 npar
->offload_flags
= esw_cfg
[i
].offload_flags
;
3941 npar
->mac_anti_spoof
= esw_cfg
[i
].mac_anti_spoof
;
3942 npar
->discard_tagged
= esw_cfg
[i
].discard_tagged
;
3944 case QLCNIC_ADD_VLAN
:
3945 npar
->pvid
= esw_cfg
[i
].vlan_id
;
3947 case QLCNIC_DEL_VLAN
:
3957 qlcnic_sysfs_read_esw_config(struct file
*file
, struct kobject
*kobj
,
3958 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3960 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3961 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3962 struct qlcnic_esw_func_cfg esw_cfg
[QLCNIC_MAX_PCI_FUNC
];
3965 if (size
!= sizeof(esw_cfg
))
3966 return QL_STATUS_INVALID_PARAM
;
3968 for (i
= 0; i
< QLCNIC_MAX_PCI_FUNC
; i
++) {
3969 if (adapter
->npars
[i
].type
!= QLCNIC_TYPE_NIC
)
3971 esw_cfg
[i
].pci_func
= i
;
3972 if (qlcnic_get_eswitch_port_config(adapter
, &esw_cfg
[i
]))
3973 return QL_STATUS_INVALID_PARAM
;
3975 memcpy(buf
, &esw_cfg
, size
);
3981 validate_npar_config(struct qlcnic_adapter
*adapter
,
3982 struct qlcnic_npar_func_cfg
*np_cfg
, int count
)
3986 for (i
= 0; i
< count
; i
++) {
3987 pci_func
= np_cfg
[i
].pci_func
;
3988 if (pci_func
>= QLCNIC_MAX_PCI_FUNC
)
3989 return QL_STATUS_INVALID_PARAM
;
3991 if (adapter
->npars
[pci_func
].type
!= QLCNIC_TYPE_NIC
)
3992 return QL_STATUS_INVALID_PARAM
;
3994 if (!IS_VALID_BW(np_cfg
[i
].min_bw
) ||
3995 !IS_VALID_BW(np_cfg
[i
].max_bw
))
3996 return QL_STATUS_INVALID_PARAM
;
4002 qlcnic_sysfs_write_npar_config(struct file
*file
, struct kobject
*kobj
,
4003 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
4005 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
4006 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
4007 struct qlcnic_info nic_info
;
4008 struct qlcnic_npar_func_cfg
*np_cfg
;
4009 int i
, count
, rem
, ret
;
4012 count
= size
/ sizeof(struct qlcnic_npar_func_cfg
);
4013 rem
= size
% sizeof(struct qlcnic_npar_func_cfg
);
4015 return QL_STATUS_INVALID_PARAM
;
4017 np_cfg
= (struct qlcnic_npar_func_cfg
*) buf
;
4018 ret
= validate_npar_config(adapter
, np_cfg
, count
);
4022 for (i
= 0; i
< count
; i
++) {
4023 pci_func
= np_cfg
[i
].pci_func
;
4024 ret
= qlcnic_get_nic_info(adapter
, &nic_info
, pci_func
);
4027 nic_info
.pci_func
= pci_func
;
4028 nic_info
.min_tx_bw
= np_cfg
[i
].min_bw
;
4029 nic_info
.max_tx_bw
= np_cfg
[i
].max_bw
;
4030 ret
= qlcnic_set_nic_info(adapter
, &nic_info
);
4033 adapter
->npars
[i
].min_bw
= nic_info
.min_tx_bw
;
4034 adapter
->npars
[i
].max_bw
= nic_info
.max_tx_bw
;
4041 qlcnic_sysfs_read_npar_config(struct file
*file
, struct kobject
*kobj
,
4042 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
4044 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
4045 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
4046 struct qlcnic_info nic_info
;
4047 struct qlcnic_npar_func_cfg np_cfg
[QLCNIC_MAX_PCI_FUNC
];
4050 if (size
!= sizeof(np_cfg
))
4051 return QL_STATUS_INVALID_PARAM
;
4053 for (i
= 0; i
< QLCNIC_MAX_PCI_FUNC
; i
++) {
4054 if (adapter
->npars
[i
].type
!= QLCNIC_TYPE_NIC
)
4056 ret
= qlcnic_get_nic_info(adapter
, &nic_info
, i
);
4060 np_cfg
[i
].pci_func
= i
;
4061 np_cfg
[i
].op_mode
= (u8
)nic_info
.op_mode
;
4062 np_cfg
[i
].port_num
= nic_info
.phys_port
;
4063 np_cfg
[i
].fw_capab
= nic_info
.capabilities
;
4064 np_cfg
[i
].min_bw
= nic_info
.min_tx_bw
;
4065 np_cfg
[i
].max_bw
= nic_info
.max_tx_bw
;
4066 np_cfg
[i
].max_tx_queues
= nic_info
.max_tx_ques
;
4067 np_cfg
[i
].max_rx_queues
= nic_info
.max_rx_ques
;
4069 memcpy(buf
, &np_cfg
, size
);
4074 qlcnic_sysfs_get_port_stats(struct file
*file
, struct kobject
*kobj
,
4075 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
4077 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
4078 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
4079 struct qlcnic_esw_statistics port_stats
;
4082 if (size
!= sizeof(struct qlcnic_esw_statistics
))
4083 return QL_STATUS_INVALID_PARAM
;
4085 if (offset
>= QLCNIC_MAX_PCI_FUNC
)
4086 return QL_STATUS_INVALID_PARAM
;
4088 memset(&port_stats
, 0, size
);
4089 ret
= qlcnic_get_port_stats(adapter
, offset
, QLCNIC_QUERY_RX_COUNTER
,
4094 ret
= qlcnic_get_port_stats(adapter
, offset
, QLCNIC_QUERY_TX_COUNTER
,
4099 memcpy(buf
, &port_stats
, size
);
4104 qlcnic_sysfs_get_esw_stats(struct file
*file
, struct kobject
*kobj
,
4105 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
4107 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
4108 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
4109 struct qlcnic_esw_statistics esw_stats
;
4112 if (size
!= sizeof(struct qlcnic_esw_statistics
))
4113 return QL_STATUS_INVALID_PARAM
;
4115 if (offset
>= QLCNIC_NIU_MAX_XG_PORTS
)
4116 return QL_STATUS_INVALID_PARAM
;
4118 memset(&esw_stats
, 0, size
);
4119 ret
= qlcnic_get_eswitch_stats(adapter
, offset
, QLCNIC_QUERY_RX_COUNTER
,
4124 ret
= qlcnic_get_eswitch_stats(adapter
, offset
, QLCNIC_QUERY_TX_COUNTER
,
4129 memcpy(buf
, &esw_stats
, size
);
4134 qlcnic_sysfs_clear_esw_stats(struct file
*file
, struct kobject
*kobj
,
4135 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
4137 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
4138 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
4141 if (offset
>= QLCNIC_NIU_MAX_XG_PORTS
)
4142 return QL_STATUS_INVALID_PARAM
;
4144 ret
= qlcnic_clear_esw_stats(adapter
, QLCNIC_STATS_ESWITCH
, offset
,
4145 QLCNIC_QUERY_RX_COUNTER
);
4149 ret
= qlcnic_clear_esw_stats(adapter
, QLCNIC_STATS_ESWITCH
, offset
,
4150 QLCNIC_QUERY_TX_COUNTER
);
4158 qlcnic_sysfs_clear_port_stats(struct file
*file
, struct kobject
*kobj
,
4159 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
4162 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
4163 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
4166 if (offset
>= QLCNIC_MAX_PCI_FUNC
)
4167 return QL_STATUS_INVALID_PARAM
;
4169 ret
= qlcnic_clear_esw_stats(adapter
, QLCNIC_STATS_PORT
, offset
,
4170 QLCNIC_QUERY_RX_COUNTER
);
4174 ret
= qlcnic_clear_esw_stats(adapter
, QLCNIC_STATS_PORT
, offset
,
4175 QLCNIC_QUERY_TX_COUNTER
);
4183 qlcnic_sysfs_read_pci_config(struct file
*file
, struct kobject
*kobj
,
4184 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
4186 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
4187 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
4188 struct qlcnic_pci_func_cfg pci_cfg
[QLCNIC_MAX_PCI_FUNC
];
4189 struct qlcnic_pci_info
*pci_info
;
4192 if (size
!= sizeof(pci_cfg
))
4193 return QL_STATUS_INVALID_PARAM
;
4195 pci_info
= kcalloc(QLCNIC_MAX_PCI_FUNC
, sizeof(*pci_info
), GFP_KERNEL
);
4199 ret
= qlcnic_get_pci_info(adapter
, pci_info
);
4205 for (i
= 0; i
< QLCNIC_MAX_PCI_FUNC
; i
++) {
4206 pci_cfg
[i
].pci_func
= pci_info
[i
].id
;
4207 pci_cfg
[i
].func_type
= pci_info
[i
].type
;
4208 pci_cfg
[i
].port_num
= pci_info
[i
].default_port
;
4209 pci_cfg
[i
].min_bw
= pci_info
[i
].tx_min_bw
;
4210 pci_cfg
[i
].max_bw
= pci_info
[i
].tx_max_bw
;
4211 memcpy(&pci_cfg
[i
].def_mac_addr
, &pci_info
[i
].mac
, ETH_ALEN
);
4213 memcpy(buf
, &pci_cfg
, size
);
4217 static struct bin_attribute bin_attr_npar_config
= {
4218 .attr
= {.name
= "npar_config", .mode
= (S_IRUGO
| S_IWUSR
)},
4220 .read
= qlcnic_sysfs_read_npar_config
,
4221 .write
= qlcnic_sysfs_write_npar_config
,
4224 static struct bin_attribute bin_attr_pci_config
= {
4225 .attr
= {.name
= "pci_config", .mode
= (S_IRUGO
| S_IWUSR
)},
4227 .read
= qlcnic_sysfs_read_pci_config
,
4231 static struct bin_attribute bin_attr_port_stats
= {
4232 .attr
= {.name
= "port_stats", .mode
= (S_IRUGO
| S_IWUSR
)},
4234 .read
= qlcnic_sysfs_get_port_stats
,
4235 .write
= qlcnic_sysfs_clear_port_stats
,
4238 static struct bin_attribute bin_attr_esw_stats
= {
4239 .attr
= {.name
= "esw_stats", .mode
= (S_IRUGO
| S_IWUSR
)},
4241 .read
= qlcnic_sysfs_get_esw_stats
,
4242 .write
= qlcnic_sysfs_clear_esw_stats
,
4245 static struct bin_attribute bin_attr_esw_config
= {
4246 .attr
= {.name
= "esw_config", .mode
= (S_IRUGO
| S_IWUSR
)},
4248 .read
= qlcnic_sysfs_read_esw_config
,
4249 .write
= qlcnic_sysfs_write_esw_config
,
4252 static struct bin_attribute bin_attr_pm_config
= {
4253 .attr
= {.name
= "pm_config", .mode
= (S_IRUGO
| S_IWUSR
)},
4255 .read
= qlcnic_sysfs_read_pm_config
,
4256 .write
= qlcnic_sysfs_write_pm_config
,
4260 qlcnic_create_sysfs_entries(struct qlcnic_adapter
*adapter
)
4262 struct device
*dev
= &adapter
->pdev
->dev
;
4264 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_BDG
)
4265 if (device_create_file(dev
, &dev_attr_bridged_mode
))
4267 "failed to create bridged_mode sysfs entry\n");
4271 qlcnic_remove_sysfs_entries(struct qlcnic_adapter
*adapter
)
4273 struct device
*dev
= &adapter
->pdev
->dev
;
4275 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_BDG
)
4276 device_remove_file(dev
, &dev_attr_bridged_mode
);
4280 qlcnic_create_diag_entries(struct qlcnic_adapter
*adapter
)
4282 struct device
*dev
= &adapter
->pdev
->dev
;
4284 if (device_create_bin_file(dev
, &bin_attr_port_stats
))
4285 dev_info(dev
, "failed to create port stats sysfs entry");
4287 if (adapter
->op_mode
== QLCNIC_NON_PRIV_FUNC
)
4289 if (device_create_file(dev
, &dev_attr_diag_mode
))
4290 dev_info(dev
, "failed to create diag_mode sysfs entry\n");
4291 if (device_create_file(dev
, &dev_attr_beacon
))
4292 dev_info(dev
, "failed to create beacon sysfs entry");
4293 if (device_create_bin_file(dev
, &bin_attr_crb
))
4294 dev_info(dev
, "failed to create crb sysfs entry\n");
4295 if (device_create_bin_file(dev
, &bin_attr_mem
))
4296 dev_info(dev
, "failed to create mem sysfs entry\n");
4297 if (device_create_bin_file(dev
, &bin_attr_pci_config
))
4298 dev_info(dev
, "failed to create pci config sysfs entry");
4299 if (!(adapter
->flags
& QLCNIC_ESWITCH_ENABLED
))
4301 if (device_create_bin_file(dev
, &bin_attr_esw_config
))
4302 dev_info(dev
, "failed to create esw config sysfs entry");
4303 if (adapter
->op_mode
!= QLCNIC_MGMT_FUNC
)
4305 if (device_create_bin_file(dev
, &bin_attr_npar_config
))
4306 dev_info(dev
, "failed to create npar config sysfs entry");
4307 if (device_create_bin_file(dev
, &bin_attr_pm_config
))
4308 dev_info(dev
, "failed to create pm config sysfs entry");
4309 if (device_create_bin_file(dev
, &bin_attr_esw_stats
))
4310 dev_info(dev
, "failed to create eswitch stats sysfs entry");
4314 qlcnic_remove_diag_entries(struct qlcnic_adapter
*adapter
)
4316 struct device
*dev
= &adapter
->pdev
->dev
;
4318 device_remove_bin_file(dev
, &bin_attr_port_stats
);
4320 if (adapter
->op_mode
== QLCNIC_NON_PRIV_FUNC
)
4322 device_remove_file(dev
, &dev_attr_diag_mode
);
4323 device_remove_file(dev
, &dev_attr_beacon
);
4324 device_remove_bin_file(dev
, &bin_attr_crb
);
4325 device_remove_bin_file(dev
, &bin_attr_mem
);
4326 device_remove_bin_file(dev
, &bin_attr_pci_config
);
4327 if (!(adapter
->flags
& QLCNIC_ESWITCH_ENABLED
))
4329 device_remove_bin_file(dev
, &bin_attr_esw_config
);
4330 if (adapter
->op_mode
!= QLCNIC_MGMT_FUNC
)
4332 device_remove_bin_file(dev
, &bin_attr_npar_config
);
4333 device_remove_bin_file(dev
, &bin_attr_pm_config
);
4334 device_remove_bin_file(dev
, &bin_attr_esw_stats
);
4339 #define is_qlcnic_netdev(dev) (dev->netdev_ops == &qlcnic_netdev_ops)
4342 qlcnic_config_indev_addr(struct qlcnic_adapter
*adapter
,
4343 struct net_device
*dev
, unsigned long event
)
4345 struct in_device
*indev
;
4347 indev
= in_dev_get(dev
);
4354 qlcnic_config_ipaddr(adapter
,
4355 ifa
->ifa_address
, QLCNIC_IP_UP
);
4358 qlcnic_config_ipaddr(adapter
,
4359 ifa
->ifa_address
, QLCNIC_IP_DOWN
);
4364 } endfor_ifa(indev
);
4370 qlcnic_restore_indev_addr(struct net_device
*netdev
, unsigned long event
)
4372 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
4373 struct net_device
*dev
;
4376 qlcnic_config_indev_addr(adapter
, netdev
, event
);
4378 for_each_set_bit(vid
, adapter
->vlans
, VLAN_N_VID
) {
4379 dev
= __vlan_find_dev_deep(netdev
, vid
);
4382 qlcnic_config_indev_addr(adapter
, dev
, event
);
4386 static int qlcnic_netdev_event(struct notifier_block
*this,
4387 unsigned long event
, void *ptr
)
4389 struct qlcnic_adapter
*adapter
;
4390 struct net_device
*dev
= (struct net_device
*)ptr
;
4396 if (dev
->priv_flags
& IFF_802_1Q_VLAN
) {
4397 dev
= vlan_dev_real_dev(dev
);
4401 if (!is_qlcnic_netdev(dev
))
4404 adapter
= netdev_priv(dev
);
4409 if (!test_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
4412 qlcnic_config_indev_addr(adapter
, dev
, event
);
4418 qlcnic_inetaddr_event(struct notifier_block
*this,
4419 unsigned long event
, void *ptr
)
4421 struct qlcnic_adapter
*adapter
;
4422 struct net_device
*dev
;
4424 struct in_ifaddr
*ifa
= (struct in_ifaddr
*)ptr
;
4426 dev
= ifa
->ifa_dev
? ifa
->ifa_dev
->dev
: NULL
;
4432 if (dev
->priv_flags
& IFF_802_1Q_VLAN
) {
4433 dev
= vlan_dev_real_dev(dev
);
4437 if (!is_qlcnic_netdev(dev
))
4440 adapter
= netdev_priv(dev
);
4445 if (!test_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
4450 qlcnic_config_ipaddr(adapter
, ifa
->ifa_address
, QLCNIC_IP_UP
);
4453 qlcnic_config_ipaddr(adapter
, ifa
->ifa_address
, QLCNIC_IP_DOWN
);
4463 static struct notifier_block qlcnic_netdev_cb
= {
4464 .notifier_call
= qlcnic_netdev_event
,
4467 static struct notifier_block qlcnic_inetaddr_cb
= {
4468 .notifier_call
= qlcnic_inetaddr_event
,
4472 qlcnic_restore_indev_addr(struct net_device
*dev
, unsigned long event
)
4475 static struct pci_error_handlers qlcnic_err_handler
= {
4476 .error_detected
= qlcnic_io_error_detected
,
4477 .slot_reset
= qlcnic_io_slot_reset
,
4478 .resume
= qlcnic_io_resume
,
4481 static struct pci_driver qlcnic_driver
= {
4482 .name
= qlcnic_driver_name
,
4483 .id_table
= qlcnic_pci_tbl
,
4484 .probe
= qlcnic_probe
,
4485 .remove
= __devexit_p(qlcnic_remove
),
4487 .suspend
= qlcnic_suspend
,
4488 .resume
= qlcnic_resume
,
4490 .shutdown
= qlcnic_shutdown
,
4491 .err_handler
= &qlcnic_err_handler
4495 static int __init
qlcnic_init_module(void)
4499 printk(KERN_INFO
"%s\n", qlcnic_driver_string
);
4501 qlcnic_wq
= create_singlethread_workqueue("qlcnic");
4502 if (qlcnic_wq
== NULL
) {
4503 printk(KERN_ERR
"qlcnic: cannot create workqueue\n");
4508 register_netdevice_notifier(&qlcnic_netdev_cb
);
4509 register_inetaddr_notifier(&qlcnic_inetaddr_cb
);
4512 ret
= pci_register_driver(&qlcnic_driver
);
4515 unregister_inetaddr_notifier(&qlcnic_inetaddr_cb
);
4516 unregister_netdevice_notifier(&qlcnic_netdev_cb
);
4518 destroy_workqueue(qlcnic_wq
);
4524 module_init(qlcnic_init_module
);
4526 static void __exit
qlcnic_exit_module(void)
4529 pci_unregister_driver(&qlcnic_driver
);
4532 unregister_inetaddr_notifier(&qlcnic_inetaddr_cb
);
4533 unregister_netdevice_notifier(&qlcnic_netdev_cb
);
4535 destroy_workqueue(qlcnic_wq
);
4538 module_exit(qlcnic_exit_module
);