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_alloc_lb_filters_mem(struct qlcnic_adapter
*adapter
);
94 static void qlcnic_free_lb_filters_mem(struct qlcnic_adapter
*adapter
);
95 static void qlcnic_dev_set_npar_ready(struct qlcnic_adapter
*);
96 static int qlcnicvf_config_led(struct qlcnic_adapter
*, u32
, u32
);
97 static int qlcnicvf_config_bridged_mode(struct qlcnic_adapter
*, u32
);
98 static int qlcnicvf_start_firmware(struct qlcnic_adapter
*);
99 static void qlcnic_set_netdev_features(struct qlcnic_adapter
*,
100 struct qlcnic_esw_func_cfg
*);
101 static void qlcnic_vlan_rx_add(struct net_device
*, u16
);
102 static void qlcnic_vlan_rx_del(struct net_device
*, u16
);
104 /* PCI Device ID Table */
105 #define ENTRY(device) \
106 {PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, (device)), \
107 .class = PCI_CLASS_NETWORK_ETHERNET << 8, .class_mask = ~0}
109 #define PCI_DEVICE_ID_QLOGIC_QLE824X 0x8020
111 static DEFINE_PCI_DEVICE_TABLE(qlcnic_pci_tbl
) = {
112 ENTRY(PCI_DEVICE_ID_QLOGIC_QLE824X
),
116 MODULE_DEVICE_TABLE(pci
, qlcnic_pci_tbl
);
120 qlcnic_update_cmd_producer(struct qlcnic_adapter
*adapter
,
121 struct qlcnic_host_tx_ring
*tx_ring
)
123 writel(tx_ring
->producer
, tx_ring
->crb_cmd_producer
);
126 static const u32 msi_tgt_status
[8] = {
127 ISR_INT_TARGET_STATUS
, ISR_INT_TARGET_STATUS_F1
,
128 ISR_INT_TARGET_STATUS_F2
, ISR_INT_TARGET_STATUS_F3
,
129 ISR_INT_TARGET_STATUS_F4
, ISR_INT_TARGET_STATUS_F5
,
130 ISR_INT_TARGET_STATUS_F6
, ISR_INT_TARGET_STATUS_F7
134 struct qlcnic_legacy_intr_set legacy_intr
[] = QLCNIC_LEGACY_INTR_CONFIG
;
136 static inline void qlcnic_disable_int(struct qlcnic_host_sds_ring
*sds_ring
)
138 writel(0, sds_ring
->crb_intr_mask
);
141 static inline void qlcnic_enable_int(struct qlcnic_host_sds_ring
*sds_ring
)
143 struct qlcnic_adapter
*adapter
= sds_ring
->adapter
;
145 writel(0x1, sds_ring
->crb_intr_mask
);
147 if (!QLCNIC_IS_MSI_FAMILY(adapter
))
148 writel(0xfbff, adapter
->tgt_mask_reg
);
152 qlcnic_alloc_sds_rings(struct qlcnic_recv_context
*recv_ctx
, int count
)
154 int size
= sizeof(struct qlcnic_host_sds_ring
) * count
;
156 recv_ctx
->sds_rings
= kzalloc(size
, GFP_KERNEL
);
158 return recv_ctx
->sds_rings
== NULL
;
162 qlcnic_free_sds_rings(struct qlcnic_recv_context
*recv_ctx
)
164 if (recv_ctx
->sds_rings
!= NULL
)
165 kfree(recv_ctx
->sds_rings
);
167 recv_ctx
->sds_rings
= NULL
;
171 qlcnic_napi_add(struct qlcnic_adapter
*adapter
, struct net_device
*netdev
)
174 struct qlcnic_host_sds_ring
*sds_ring
;
175 struct qlcnic_recv_context
*recv_ctx
= adapter
->recv_ctx
;
177 if (qlcnic_alloc_sds_rings(recv_ctx
, adapter
->max_sds_rings
))
180 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
181 sds_ring
= &recv_ctx
->sds_rings
[ring
];
183 if (ring
== adapter
->max_sds_rings
- 1)
184 netif_napi_add(netdev
, &sds_ring
->napi
, qlcnic_poll
,
185 QLCNIC_NETDEV_WEIGHT
/adapter
->max_sds_rings
);
187 netif_napi_add(netdev
, &sds_ring
->napi
,
188 qlcnic_rx_poll
, QLCNIC_NETDEV_WEIGHT
*2);
195 qlcnic_napi_del(struct qlcnic_adapter
*adapter
)
198 struct qlcnic_host_sds_ring
*sds_ring
;
199 struct qlcnic_recv_context
*recv_ctx
= adapter
->recv_ctx
;
201 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
202 sds_ring
= &recv_ctx
->sds_rings
[ring
];
203 netif_napi_del(&sds_ring
->napi
);
206 qlcnic_free_sds_rings(adapter
->recv_ctx
);
210 qlcnic_napi_enable(struct qlcnic_adapter
*adapter
)
213 struct qlcnic_host_sds_ring
*sds_ring
;
214 struct qlcnic_recv_context
*recv_ctx
= adapter
->recv_ctx
;
216 if (adapter
->is_up
!= QLCNIC_ADAPTER_UP_MAGIC
)
219 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
220 sds_ring
= &recv_ctx
->sds_rings
[ring
];
221 napi_enable(&sds_ring
->napi
);
222 qlcnic_enable_int(sds_ring
);
227 qlcnic_napi_disable(struct qlcnic_adapter
*adapter
)
230 struct qlcnic_host_sds_ring
*sds_ring
;
231 struct qlcnic_recv_context
*recv_ctx
= adapter
->recv_ctx
;
233 if (adapter
->is_up
!= QLCNIC_ADAPTER_UP_MAGIC
)
236 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
237 sds_ring
= &recv_ctx
->sds_rings
[ring
];
238 qlcnic_disable_int(sds_ring
);
239 napi_synchronize(&sds_ring
->napi
);
240 napi_disable(&sds_ring
->napi
);
244 static void qlcnic_clear_stats(struct qlcnic_adapter
*adapter
)
246 memset(&adapter
->stats
, 0, sizeof(adapter
->stats
));
249 static void qlcnic_set_msix_bit(struct pci_dev
*pdev
, int enable
)
254 pos
= pci_find_capability(pdev
, PCI_CAP_ID_MSIX
);
256 pci_read_config_dword(pdev
, pos
, &control
);
258 control
|= PCI_MSIX_FLAGS_ENABLE
;
261 pci_write_config_dword(pdev
, pos
, control
);
265 static void qlcnic_init_msix_entries(struct qlcnic_adapter
*adapter
, int count
)
269 for (i
= 0; i
< count
; i
++)
270 adapter
->msix_entries
[i
].entry
= i
;
274 qlcnic_read_mac_addr(struct qlcnic_adapter
*adapter
)
276 u8 mac_addr
[ETH_ALEN
];
277 struct net_device
*netdev
= adapter
->netdev
;
278 struct pci_dev
*pdev
= adapter
->pdev
;
280 if (qlcnic_get_mac_address(adapter
, mac_addr
) != 0)
283 memcpy(netdev
->dev_addr
, mac_addr
, ETH_ALEN
);
284 memcpy(netdev
->perm_addr
, netdev
->dev_addr
, netdev
->addr_len
);
285 memcpy(adapter
->mac_addr
, netdev
->dev_addr
, netdev
->addr_len
);
287 /* set station address */
289 if (!is_valid_ether_addr(netdev
->perm_addr
))
290 dev_warn(&pdev
->dev
, "Bad MAC address %pM.\n",
296 static int qlcnic_set_mac(struct net_device
*netdev
, void *p
)
298 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
299 struct sockaddr
*addr
= p
;
301 if ((adapter
->flags
& QLCNIC_MAC_OVERRIDE_DISABLED
))
304 if (!is_valid_ether_addr(addr
->sa_data
))
307 if (test_bit(__QLCNIC_DEV_UP
, &adapter
->state
)) {
308 netif_device_detach(netdev
);
309 qlcnic_napi_disable(adapter
);
312 memcpy(adapter
->mac_addr
, addr
->sa_data
, netdev
->addr_len
);
313 memcpy(netdev
->dev_addr
, addr
->sa_data
, netdev
->addr_len
);
314 qlcnic_set_multi(adapter
->netdev
);
316 if (test_bit(__QLCNIC_DEV_UP
, &adapter
->state
)) {
317 netif_device_attach(netdev
);
318 qlcnic_napi_enable(adapter
);
323 static const struct net_device_ops qlcnic_netdev_ops
= {
324 .ndo_open
= qlcnic_open
,
325 .ndo_stop
= qlcnic_close
,
326 .ndo_start_xmit
= qlcnic_xmit_frame
,
327 .ndo_get_stats
= qlcnic_get_stats
,
328 .ndo_validate_addr
= eth_validate_addr
,
329 .ndo_set_multicast_list
= qlcnic_set_multi
,
330 .ndo_set_mac_address
= qlcnic_set_mac
,
331 .ndo_change_mtu
= qlcnic_change_mtu
,
332 .ndo_fix_features
= qlcnic_fix_features
,
333 .ndo_set_features
= qlcnic_set_features
,
334 .ndo_tx_timeout
= qlcnic_tx_timeout
,
335 .ndo_vlan_rx_add_vid
= qlcnic_vlan_rx_add
,
336 .ndo_vlan_rx_kill_vid
= qlcnic_vlan_rx_del
,
337 #ifdef CONFIG_NET_POLL_CONTROLLER
338 .ndo_poll_controller
= qlcnic_poll_controller
,
342 static struct qlcnic_nic_template qlcnic_ops
= {
343 .config_bridged_mode
= qlcnic_config_bridged_mode
,
344 .config_led
= qlcnic_config_led
,
345 .start_firmware
= qlcnic_start_firmware
348 static struct qlcnic_nic_template qlcnic_vf_ops
= {
349 .config_bridged_mode
= qlcnicvf_config_bridged_mode
,
350 .config_led
= qlcnicvf_config_led
,
351 .start_firmware
= qlcnicvf_start_firmware
354 static int qlcnic_enable_msix(struct qlcnic_adapter
*adapter
, u32 num_msix
)
356 struct pci_dev
*pdev
= adapter
->pdev
;
359 adapter
->max_sds_rings
= 1;
360 adapter
->flags
&= ~(QLCNIC_MSI_ENABLED
| QLCNIC_MSIX_ENABLED
);
361 qlcnic_set_msix_bit(pdev
, 0);
363 if (adapter
->msix_supported
) {
365 qlcnic_init_msix_entries(adapter
, num_msix
);
366 err
= pci_enable_msix(pdev
, adapter
->msix_entries
, num_msix
);
368 adapter
->flags
|= QLCNIC_MSIX_ENABLED
;
369 qlcnic_set_msix_bit(pdev
, 1);
371 adapter
->max_sds_rings
= num_msix
;
373 dev_info(&pdev
->dev
, "using msi-x interrupts\n");
377 num_msix
= rounddown_pow_of_two(err
);
386 static void qlcnic_enable_msi_legacy(struct qlcnic_adapter
*adapter
)
388 const struct qlcnic_legacy_intr_set
*legacy_intrp
;
389 struct pci_dev
*pdev
= adapter
->pdev
;
391 if (use_msi
&& !pci_enable_msi(pdev
)) {
392 adapter
->flags
|= QLCNIC_MSI_ENABLED
;
393 adapter
->tgt_status_reg
= qlcnic_get_ioaddr(adapter
,
394 msi_tgt_status
[adapter
->ahw
->pci_func
]);
395 dev_info(&pdev
->dev
, "using msi interrupts\n");
396 adapter
->msix_entries
[0].vector
= pdev
->irq
;
400 legacy_intrp
= &legacy_intr
[adapter
->ahw
->pci_func
];
402 adapter
->int_vec_bit
= legacy_intrp
->int_vec_bit
;
403 adapter
->tgt_status_reg
= qlcnic_get_ioaddr(adapter
,
404 legacy_intrp
->tgt_status_reg
);
405 adapter
->tgt_mask_reg
= qlcnic_get_ioaddr(adapter
,
406 legacy_intrp
->tgt_mask_reg
);
407 adapter
->isr_int_vec
= qlcnic_get_ioaddr(adapter
, ISR_INT_VECTOR
);
409 adapter
->crb_int_state_reg
= qlcnic_get_ioaddr(adapter
,
411 dev_info(&pdev
->dev
, "using legacy interrupts\n");
412 adapter
->msix_entries
[0].vector
= pdev
->irq
;
416 qlcnic_setup_intr(struct qlcnic_adapter
*adapter
)
420 if (adapter
->msix_supported
) {
421 num_msix
= (num_online_cpus() >=
422 QLCNIC_DEF_NUM_STS_DESC_RINGS
) ?
423 QLCNIC_DEF_NUM_STS_DESC_RINGS
:
424 QLCNIC_MIN_NUM_RSS_RINGS
;
428 if (!qlcnic_enable_msix(adapter
, num_msix
))
431 qlcnic_enable_msi_legacy(adapter
);
435 qlcnic_teardown_intr(struct qlcnic_adapter
*adapter
)
437 if (adapter
->flags
& QLCNIC_MSIX_ENABLED
)
438 pci_disable_msix(adapter
->pdev
);
439 if (adapter
->flags
& QLCNIC_MSI_ENABLED
)
440 pci_disable_msi(adapter
->pdev
);
444 qlcnic_cleanup_pci_map(struct qlcnic_adapter
*adapter
)
446 if (adapter
->ahw
->pci_base0
!= NULL
)
447 iounmap(adapter
->ahw
->pci_base0
);
451 qlcnic_init_pci_info(struct qlcnic_adapter
*adapter
)
453 struct qlcnic_pci_info
*pci_info
;
457 pci_info
= kcalloc(QLCNIC_MAX_PCI_FUNC
, sizeof(*pci_info
), GFP_KERNEL
);
461 adapter
->npars
= kzalloc(sizeof(struct qlcnic_npar_info
) *
462 QLCNIC_MAX_PCI_FUNC
, GFP_KERNEL
);
463 if (!adapter
->npars
) {
468 adapter
->eswitch
= kzalloc(sizeof(struct qlcnic_eswitch
) *
469 QLCNIC_NIU_MAX_XG_PORTS
, GFP_KERNEL
);
470 if (!adapter
->eswitch
) {
475 ret
= qlcnic_get_pci_info(adapter
, pci_info
);
479 for (i
= 0; i
< QLCNIC_MAX_PCI_FUNC
; i
++) {
480 pfn
= pci_info
[i
].id
;
481 if (pfn
> QLCNIC_MAX_PCI_FUNC
) {
482 ret
= QL_STATUS_INVALID_PARAM
;
485 adapter
->npars
[pfn
].active
= (u8
)pci_info
[i
].active
;
486 adapter
->npars
[pfn
].type
= (u8
)pci_info
[i
].type
;
487 adapter
->npars
[pfn
].phy_port
= (u8
)pci_info
[i
].default_port
;
488 adapter
->npars
[pfn
].min_bw
= pci_info
[i
].tx_min_bw
;
489 adapter
->npars
[pfn
].max_bw
= pci_info
[i
].tx_max_bw
;
492 for (i
= 0; i
< QLCNIC_NIU_MAX_XG_PORTS
; i
++)
493 adapter
->eswitch
[i
].flags
|= QLCNIC_SWITCH_ENABLE
;
499 kfree(adapter
->eswitch
);
500 adapter
->eswitch
= NULL
;
502 kfree(adapter
->npars
);
503 adapter
->npars
= NULL
;
511 qlcnic_set_function_modes(struct qlcnic_adapter
*adapter
)
516 u32 data
= QLCNIC_MGMT_FUNC
;
517 void __iomem
*priv_op
= adapter
->ahw
->pci_base0
+ QLCNIC_DRV_OP_MODE
;
519 /* If other drivers are not in use set their privilege level */
520 ref_count
= QLCRD32(adapter
, QLCNIC_CRB_DRV_ACTIVE
);
521 ret
= qlcnic_api_lock(adapter
);
525 if (qlcnic_config_npars
) {
526 for (i
= 0; i
< QLCNIC_MAX_PCI_FUNC
; i
++) {
528 if (adapter
->npars
[i
].type
!= QLCNIC_TYPE_NIC
||
529 id
== adapter
->ahw
->pci_func
)
531 data
|= (qlcnic_config_npars
&
532 QLC_DEV_SET_DRV(0xf, id
));
535 data
= readl(priv_op
);
536 data
= (data
& ~QLC_DEV_SET_DRV(0xf, adapter
->ahw
->pci_func
)) |
537 (QLC_DEV_SET_DRV(QLCNIC_MGMT_FUNC
,
538 adapter
->ahw
->pci_func
));
540 writel(data
, priv_op
);
541 qlcnic_api_unlock(adapter
);
547 qlcnic_check_vf(struct qlcnic_adapter
*adapter
)
549 void __iomem
*msix_base_addr
;
550 void __iomem
*priv_op
;
553 u32 op_mode
, priv_level
;
555 /* Determine FW API version */
556 adapter
->fw_hal_version
= readl(adapter
->ahw
->pci_base0
+
559 /* Find PCI function number */
560 pci_read_config_dword(adapter
->pdev
, QLCNIC_MSIX_TABLE_OFFSET
, &func
);
561 msix_base_addr
= adapter
->ahw
->pci_base0
+ QLCNIC_MSIX_BASE
;
562 msix_base
= readl(msix_base_addr
);
563 func
= (func
- msix_base
)/QLCNIC_MSIX_TBL_PGSIZE
;
564 adapter
->ahw
->pci_func
= func
;
566 /* Determine function privilege level */
567 priv_op
= adapter
->ahw
->pci_base0
+ QLCNIC_DRV_OP_MODE
;
568 op_mode
= readl(priv_op
);
569 if (op_mode
== QLC_DEV_DRV_DEFAULT
)
570 priv_level
= QLCNIC_MGMT_FUNC
;
572 priv_level
= QLC_DEV_GET_DRV(op_mode
, adapter
->ahw
->pci_func
);
574 if (priv_level
== QLCNIC_NON_PRIV_FUNC
) {
575 adapter
->op_mode
= QLCNIC_NON_PRIV_FUNC
;
576 dev_info(&adapter
->pdev
->dev
,
577 "HAL Version: %d Non Privileged function\n",
578 adapter
->fw_hal_version
);
579 adapter
->nic_ops
= &qlcnic_vf_ops
;
581 adapter
->nic_ops
= &qlcnic_ops
;
585 qlcnic_setup_pci_map(struct qlcnic_adapter
*adapter
)
587 void __iomem
*mem_ptr0
= NULL
;
588 resource_size_t mem_base
;
589 unsigned long mem_len
, pci_len0
= 0;
591 struct pci_dev
*pdev
= adapter
->pdev
;
593 /* remap phys address */
594 mem_base
= pci_resource_start(pdev
, 0); /* 0 is for BAR 0 */
595 mem_len
= pci_resource_len(pdev
, 0);
597 if (mem_len
== QLCNIC_PCI_2MB_SIZE
) {
599 mem_ptr0
= pci_ioremap_bar(pdev
, 0);
600 if (mem_ptr0
== NULL
) {
601 dev_err(&pdev
->dev
, "failed to map PCI bar 0\n");
609 dev_info(&pdev
->dev
, "%dMB memory map\n", (int)(mem_len
>>20));
611 adapter
->ahw
->pci_base0
= mem_ptr0
;
612 adapter
->ahw
->pci_len0
= pci_len0
;
614 qlcnic_check_vf(adapter
);
616 adapter
->ahw
->ocm_win_crb
= qlcnic_get_ioaddr(adapter
,
617 QLCNIC_PCIX_PS_REG(PCIX_OCM_WINDOW_REG(
618 adapter
->ahw
->pci_func
)));
623 static void get_brd_name(struct qlcnic_adapter
*adapter
, char *name
)
625 struct pci_dev
*pdev
= adapter
->pdev
;
628 for (i
= 0; i
< NUM_SUPPORTED_BOARDS
; ++i
) {
629 if (qlcnic_boards
[i
].vendor
== pdev
->vendor
&&
630 qlcnic_boards
[i
].device
== pdev
->device
&&
631 qlcnic_boards
[i
].sub_vendor
== pdev
->subsystem_vendor
&&
632 qlcnic_boards
[i
].sub_device
== pdev
->subsystem_device
) {
633 sprintf(name
, "%pM: %s" ,
635 qlcnic_boards
[i
].short_name
);
643 sprintf(name
, "%pM Gigabit Ethernet", adapter
->mac_addr
);
647 qlcnic_check_options(struct qlcnic_adapter
*adapter
)
649 u32 fw_major
, fw_minor
, fw_build
;
650 struct pci_dev
*pdev
= adapter
->pdev
;
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 dev_info(&pdev
->dev
, "firmware v%d.%d.%d\n",
659 fw_major
, fw_minor
, fw_build
);
660 if (adapter
->ahw
->port_type
== QLCNIC_XGBE
) {
661 if (adapter
->flags
& QLCNIC_ESWITCH_ENABLED
) {
662 adapter
->num_rxd
= DEFAULT_RCV_DESCRIPTORS_VF
;
663 adapter
->max_rxd
= MAX_RCV_DESCRIPTORS_VF
;
665 adapter
->num_rxd
= DEFAULT_RCV_DESCRIPTORS_10G
;
666 adapter
->max_rxd
= MAX_RCV_DESCRIPTORS_10G
;
669 adapter
->num_jumbo_rxd
= MAX_JUMBO_RCV_DESCRIPTORS_10G
;
670 adapter
->max_jumbo_rxd
= MAX_JUMBO_RCV_DESCRIPTORS_10G
;
672 } else if (adapter
->ahw
->port_type
== QLCNIC_GBE
) {
673 adapter
->num_rxd
= DEFAULT_RCV_DESCRIPTORS_1G
;
674 adapter
->num_jumbo_rxd
= MAX_JUMBO_RCV_DESCRIPTORS_1G
;
675 adapter
->max_jumbo_rxd
= MAX_JUMBO_RCV_DESCRIPTORS_1G
;
676 adapter
->max_rxd
= MAX_RCV_DESCRIPTORS_1G
;
679 adapter
->msix_supported
= !!use_msi_x
;
681 adapter
->num_txd
= MAX_CMD_DESCRIPTORS
;
683 adapter
->max_rds_rings
= MAX_RDS_RINGS
;
687 qlcnic_initialize_nic(struct qlcnic_adapter
*adapter
)
690 struct qlcnic_info nic_info
;
692 err
= qlcnic_get_nic_info(adapter
, &nic_info
, adapter
->ahw
->pci_func
);
696 adapter
->physical_port
= (u8
)nic_info
.phys_port
;
697 adapter
->switch_mode
= nic_info
.switch_mode
;
698 adapter
->max_tx_ques
= nic_info
.max_tx_ques
;
699 adapter
->max_rx_ques
= nic_info
.max_rx_ques
;
700 adapter
->capabilities
= nic_info
.capabilities
;
701 adapter
->max_mac_filters
= nic_info
.max_mac_filters
;
702 adapter
->max_mtu
= nic_info
.max_mtu
;
704 if (adapter
->capabilities
& BIT_6
)
705 adapter
->flags
|= QLCNIC_ESWITCH_ENABLED
;
707 adapter
->flags
&= ~QLCNIC_ESWITCH_ENABLED
;
713 qlcnic_set_vlan_config(struct qlcnic_adapter
*adapter
,
714 struct qlcnic_esw_func_cfg
*esw_cfg
)
716 if (esw_cfg
->discard_tagged
)
717 adapter
->flags
&= ~QLCNIC_TAGGING_ENABLED
;
719 adapter
->flags
|= QLCNIC_TAGGING_ENABLED
;
721 if (esw_cfg
->vlan_id
)
722 adapter
->pvid
= esw_cfg
->vlan_id
;
728 qlcnic_vlan_rx_add(struct net_device
*netdev
, u16 vid
)
730 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
731 set_bit(vid
, adapter
->vlans
);
735 qlcnic_vlan_rx_del(struct net_device
*netdev
, u16 vid
)
737 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
739 qlcnic_restore_indev_addr(netdev
, NETDEV_DOWN
);
740 clear_bit(vid
, adapter
->vlans
);
744 qlcnic_set_eswitch_port_features(struct qlcnic_adapter
*adapter
,
745 struct qlcnic_esw_func_cfg
*esw_cfg
)
747 adapter
->flags
&= ~(QLCNIC_MACSPOOF
| QLCNIC_MAC_OVERRIDE_DISABLED
|
748 QLCNIC_PROMISC_DISABLED
);
750 if (esw_cfg
->mac_anti_spoof
)
751 adapter
->flags
|= QLCNIC_MACSPOOF
;
753 if (!esw_cfg
->mac_override
)
754 adapter
->flags
|= QLCNIC_MAC_OVERRIDE_DISABLED
;
756 if (!esw_cfg
->promisc_mode
)
757 adapter
->flags
|= QLCNIC_PROMISC_DISABLED
;
759 qlcnic_set_netdev_features(adapter
, esw_cfg
);
763 qlcnic_set_eswitch_port_config(struct qlcnic_adapter
*adapter
)
765 struct qlcnic_esw_func_cfg esw_cfg
;
767 if (!(adapter
->flags
& QLCNIC_ESWITCH_ENABLED
))
770 esw_cfg
.pci_func
= adapter
->ahw
->pci_func
;
771 if (qlcnic_get_eswitch_port_config(adapter
, &esw_cfg
))
773 qlcnic_set_vlan_config(adapter
, &esw_cfg
);
774 qlcnic_set_eswitch_port_features(adapter
, &esw_cfg
);
780 qlcnic_set_netdev_features(struct qlcnic_adapter
*adapter
,
781 struct qlcnic_esw_func_cfg
*esw_cfg
)
783 struct net_device
*netdev
= adapter
->netdev
;
784 unsigned long features
, vlan_features
;
786 features
= (NETIF_F_SG
| NETIF_F_IP_CSUM
| NETIF_F_RXCSUM
|
787 NETIF_F_IPV6_CSUM
| NETIF_F_GRO
);
788 vlan_features
= (NETIF_F_SG
| NETIF_F_IP_CSUM
|
789 NETIF_F_IPV6_CSUM
| NETIF_F_HW_VLAN_FILTER
);
791 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_TSO
) {
792 features
|= (NETIF_F_TSO
| NETIF_F_TSO6
);
793 vlan_features
|= (NETIF_F_TSO
| NETIF_F_TSO6
);
796 if (netdev
->features
& NETIF_F_LRO
)
797 features
|= NETIF_F_LRO
;
799 if (esw_cfg
->offload_flags
& BIT_0
) {
800 netdev
->features
|= features
;
801 if (!(esw_cfg
->offload_flags
& BIT_1
))
802 netdev
->features
&= ~NETIF_F_TSO
;
803 if (!(esw_cfg
->offload_flags
& BIT_2
))
804 netdev
->features
&= ~NETIF_F_TSO6
;
806 netdev
->features
&= ~features
;
809 netdev
->vlan_features
= (features
& vlan_features
);
813 qlcnic_check_eswitch_mode(struct qlcnic_adapter
*adapter
)
815 void __iomem
*priv_op
;
816 u32 op_mode
, priv_level
;
819 err
= qlcnic_initialize_nic(adapter
);
823 if (adapter
->flags
& QLCNIC_ADAPTER_INITIALIZED
)
826 priv_op
= adapter
->ahw
->pci_base0
+ QLCNIC_DRV_OP_MODE
;
827 op_mode
= readl(priv_op
);
828 priv_level
= QLC_DEV_GET_DRV(op_mode
, adapter
->ahw
->pci_func
);
830 if (op_mode
== QLC_DEV_DRV_DEFAULT
)
831 priv_level
= QLCNIC_MGMT_FUNC
;
833 priv_level
= QLC_DEV_GET_DRV(op_mode
, adapter
->ahw
->pci_func
);
835 if (adapter
->flags
& QLCNIC_ESWITCH_ENABLED
) {
836 if (priv_level
== QLCNIC_MGMT_FUNC
) {
837 adapter
->op_mode
= QLCNIC_MGMT_FUNC
;
838 err
= qlcnic_init_pci_info(adapter
);
841 /* Set privilege level for other functions */
842 qlcnic_set_function_modes(adapter
);
843 dev_info(&adapter
->pdev
->dev
,
844 "HAL Version: %d, Management function\n",
845 adapter
->fw_hal_version
);
846 } else if (priv_level
== QLCNIC_PRIV_FUNC
) {
847 adapter
->op_mode
= QLCNIC_PRIV_FUNC
;
848 dev_info(&adapter
->pdev
->dev
,
849 "HAL Version: %d, Privileged function\n",
850 adapter
->fw_hal_version
);
854 adapter
->flags
|= QLCNIC_ADAPTER_INITIALIZED
;
860 qlcnic_set_default_offload_settings(struct qlcnic_adapter
*adapter
)
862 struct qlcnic_esw_func_cfg esw_cfg
;
863 struct qlcnic_npar_info
*npar
;
866 if (adapter
->need_fw_reset
)
869 for (i
= 0; i
< QLCNIC_MAX_PCI_FUNC
; i
++) {
870 if (adapter
->npars
[i
].type
!= QLCNIC_TYPE_NIC
)
872 memset(&esw_cfg
, 0, sizeof(struct qlcnic_esw_func_cfg
));
873 esw_cfg
.pci_func
= i
;
874 esw_cfg
.offload_flags
= BIT_0
;
875 esw_cfg
.mac_override
= BIT_0
;
876 esw_cfg
.promisc_mode
= BIT_0
;
877 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_TSO
)
878 esw_cfg
.offload_flags
|= (BIT_1
| BIT_2
);
879 if (qlcnic_config_switch_port(adapter
, &esw_cfg
))
881 npar
= &adapter
->npars
[i
];
882 npar
->pvid
= esw_cfg
.vlan_id
;
883 npar
->mac_override
= esw_cfg
.mac_override
;
884 npar
->mac_anti_spoof
= esw_cfg
.mac_anti_spoof
;
885 npar
->discard_tagged
= esw_cfg
.discard_tagged
;
886 npar
->promisc_mode
= esw_cfg
.promisc_mode
;
887 npar
->offload_flags
= esw_cfg
.offload_flags
;
894 qlcnic_reset_eswitch_config(struct qlcnic_adapter
*adapter
,
895 struct qlcnic_npar_info
*npar
, int pci_func
)
897 struct qlcnic_esw_func_cfg esw_cfg
;
898 esw_cfg
.op_mode
= QLCNIC_PORT_DEFAULTS
;
899 esw_cfg
.pci_func
= pci_func
;
900 esw_cfg
.vlan_id
= npar
->pvid
;
901 esw_cfg
.mac_override
= npar
->mac_override
;
902 esw_cfg
.discard_tagged
= npar
->discard_tagged
;
903 esw_cfg
.mac_anti_spoof
= npar
->mac_anti_spoof
;
904 esw_cfg
.offload_flags
= npar
->offload_flags
;
905 esw_cfg
.promisc_mode
= npar
->promisc_mode
;
906 if (qlcnic_config_switch_port(adapter
, &esw_cfg
))
909 esw_cfg
.op_mode
= QLCNIC_ADD_VLAN
;
910 if (qlcnic_config_switch_port(adapter
, &esw_cfg
))
917 qlcnic_reset_npar_config(struct qlcnic_adapter
*adapter
)
920 struct qlcnic_npar_info
*npar
;
921 struct qlcnic_info nic_info
;
923 if (!adapter
->need_fw_reset
)
926 /* Set the NPAR config data after FW reset */
927 for (i
= 0; i
< QLCNIC_MAX_PCI_FUNC
; i
++) {
928 npar
= &adapter
->npars
[i
];
929 if (npar
->type
!= QLCNIC_TYPE_NIC
)
931 err
= qlcnic_get_nic_info(adapter
, &nic_info
, i
);
934 nic_info
.min_tx_bw
= npar
->min_bw
;
935 nic_info
.max_tx_bw
= npar
->max_bw
;
936 err
= qlcnic_set_nic_info(adapter
, &nic_info
);
940 if (npar
->enable_pm
) {
941 err
= qlcnic_config_port_mirroring(adapter
,
942 npar
->dest_npar
, 1, i
);
946 err
= qlcnic_reset_eswitch_config(adapter
, npar
, i
);
953 static int qlcnic_check_npar_opertional(struct qlcnic_adapter
*adapter
)
955 u8 npar_opt_timeo
= QLCNIC_DEV_NPAR_OPER_TIMEO
;
958 if (adapter
->op_mode
== QLCNIC_MGMT_FUNC
)
961 npar_state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_NPAR_STATE
);
962 while (npar_state
!= QLCNIC_DEV_NPAR_OPER
&& --npar_opt_timeo
) {
964 npar_state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_NPAR_STATE
);
966 if (!npar_opt_timeo
) {
967 dev_err(&adapter
->pdev
->dev
,
968 "Waiting for NPAR state to opertional timeout\n");
975 qlcnic_set_mgmt_operations(struct qlcnic_adapter
*adapter
)
979 if (!(adapter
->flags
& QLCNIC_ESWITCH_ENABLED
) ||
980 adapter
->op_mode
!= QLCNIC_MGMT_FUNC
)
983 err
= qlcnic_set_default_offload_settings(adapter
);
987 err
= qlcnic_reset_npar_config(adapter
);
991 qlcnic_dev_set_npar_ready(adapter
);
997 qlcnic_start_firmware(struct qlcnic_adapter
*adapter
)
1001 err
= qlcnic_can_start_firmware(adapter
);
1005 goto check_fw_status
;
1008 qlcnic_request_firmware(adapter
);
1010 err
= qlcnic_check_flash_fw_ver(adapter
);
1014 adapter
->fw_type
= QLCNIC_FLASH_ROMIMAGE
;
1017 err
= qlcnic_need_fw_reset(adapter
);
1019 goto check_fw_status
;
1021 err
= qlcnic_pinit_from_rom(adapter
);
1025 err
= qlcnic_load_firmware(adapter
);
1029 qlcnic_release_firmware(adapter
);
1030 QLCWR32(adapter
, CRB_DRIVER_VERSION
, QLCNIC_DRIVER_VERSION
);
1033 err
= qlcnic_check_fw_status(adapter
);
1037 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
, QLCNIC_DEV_READY
);
1038 qlcnic_idc_debug_info(adapter
, 1);
1040 err
= qlcnic_check_eswitch_mode(adapter
);
1042 dev_err(&adapter
->pdev
->dev
,
1043 "Memory allocation failed for eswitch\n");
1046 err
= qlcnic_set_mgmt_operations(adapter
);
1050 qlcnic_check_options(adapter
);
1051 adapter
->need_fw_reset
= 0;
1053 qlcnic_release_firmware(adapter
);
1057 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
, QLCNIC_DEV_FAILED
);
1058 dev_err(&adapter
->pdev
->dev
, "Device state set to failed\n");
1060 qlcnic_release_firmware(adapter
);
1065 qlcnic_request_irq(struct qlcnic_adapter
*adapter
)
1067 irq_handler_t handler
;
1068 struct qlcnic_host_sds_ring
*sds_ring
;
1071 unsigned long flags
= 0;
1072 struct net_device
*netdev
= adapter
->netdev
;
1073 struct qlcnic_recv_context
*recv_ctx
= adapter
->recv_ctx
;
1075 if (adapter
->diag_test
== QLCNIC_INTERRUPT_TEST
) {
1076 handler
= qlcnic_tmp_intr
;
1077 if (!QLCNIC_IS_MSI_FAMILY(adapter
))
1078 flags
|= IRQF_SHARED
;
1081 if (adapter
->flags
& QLCNIC_MSIX_ENABLED
)
1082 handler
= qlcnic_msix_intr
;
1083 else if (adapter
->flags
& QLCNIC_MSI_ENABLED
)
1084 handler
= qlcnic_msi_intr
;
1086 flags
|= IRQF_SHARED
;
1087 handler
= qlcnic_intr
;
1090 adapter
->irq
= netdev
->irq
;
1092 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
1093 sds_ring
= &recv_ctx
->sds_rings
[ring
];
1094 sprintf(sds_ring
->name
, "%s[%d]", netdev
->name
, ring
);
1095 err
= request_irq(sds_ring
->irq
, handler
,
1096 flags
, sds_ring
->name
, sds_ring
);
1105 qlcnic_free_irq(struct qlcnic_adapter
*adapter
)
1108 struct qlcnic_host_sds_ring
*sds_ring
;
1110 struct qlcnic_recv_context
*recv_ctx
= adapter
->recv_ctx
;
1112 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
1113 sds_ring
= &recv_ctx
->sds_rings
[ring
];
1114 free_irq(sds_ring
->irq
, sds_ring
);
1119 __qlcnic_up(struct qlcnic_adapter
*adapter
, struct net_device
*netdev
)
1122 struct qlcnic_host_rds_ring
*rds_ring
;
1124 if (adapter
->is_up
!= QLCNIC_ADAPTER_UP_MAGIC
)
1127 if (test_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
1129 if (qlcnic_set_eswitch_port_config(adapter
))
1132 if (qlcnic_fw_create_ctx(adapter
))
1135 for (ring
= 0; ring
< adapter
->max_rds_rings
; ring
++) {
1136 rds_ring
= &adapter
->recv_ctx
->rds_rings
[ring
];
1137 qlcnic_post_rx_buffers(adapter
, rds_ring
);
1140 qlcnic_set_multi(netdev
);
1141 qlcnic_fw_cmd_set_mtu(adapter
, netdev
->mtu
);
1143 adapter
->ahw
->linkup
= 0;
1145 if (adapter
->max_sds_rings
> 1)
1146 qlcnic_config_rss(adapter
, 1);
1148 qlcnic_config_intr_coalesce(adapter
);
1150 if (netdev
->features
& NETIF_F_LRO
)
1151 qlcnic_config_hw_lro(adapter
, QLCNIC_LRO_ENABLED
);
1153 qlcnic_napi_enable(adapter
);
1155 qlcnic_linkevent_request(adapter
, 1);
1157 adapter
->reset_context
= 0;
1158 set_bit(__QLCNIC_DEV_UP
, &adapter
->state
);
1162 /* Usage: During resume and firmware recovery module.*/
1165 qlcnic_up(struct qlcnic_adapter
*adapter
, struct net_device
*netdev
)
1170 if (netif_running(netdev
))
1171 err
= __qlcnic_up(adapter
, netdev
);
1178 __qlcnic_down(struct qlcnic_adapter
*adapter
, struct net_device
*netdev
)
1180 if (adapter
->is_up
!= QLCNIC_ADAPTER_UP_MAGIC
)
1183 if (!test_and_clear_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
1187 spin_lock(&adapter
->tx_clean_lock
);
1188 netif_carrier_off(netdev
);
1189 netif_tx_disable(netdev
);
1191 qlcnic_free_mac_list(adapter
);
1193 if (adapter
->fhash
.fnum
)
1194 qlcnic_delete_lb_filters(adapter
);
1196 qlcnic_nic_set_promisc(adapter
, QLCNIC_NIU_NON_PROMISC_MODE
);
1198 qlcnic_napi_disable(adapter
);
1200 qlcnic_fw_destroy_ctx(adapter
);
1202 qlcnic_reset_rx_buffers_list(adapter
);
1203 qlcnic_release_tx_buffers(adapter
);
1204 spin_unlock(&adapter
->tx_clean_lock
);
1207 /* Usage: During suspend and firmware recovery module */
1210 qlcnic_down(struct qlcnic_adapter
*adapter
, struct net_device
*netdev
)
1213 if (netif_running(netdev
))
1214 __qlcnic_down(adapter
, netdev
);
1220 qlcnic_attach(struct qlcnic_adapter
*adapter
)
1222 struct net_device
*netdev
= adapter
->netdev
;
1223 struct pci_dev
*pdev
= adapter
->pdev
;
1226 if (adapter
->is_up
== QLCNIC_ADAPTER_UP_MAGIC
)
1229 err
= qlcnic_napi_add(adapter
, netdev
);
1233 err
= qlcnic_alloc_sw_resources(adapter
);
1235 dev_err(&pdev
->dev
, "Error in setting sw resources\n");
1236 goto err_out_napi_del
;
1239 err
= qlcnic_alloc_hw_resources(adapter
);
1241 dev_err(&pdev
->dev
, "Error in setting hw resources\n");
1242 goto err_out_free_sw
;
1245 err
= qlcnic_request_irq(adapter
);
1247 dev_err(&pdev
->dev
, "failed to setup interrupt\n");
1248 goto err_out_free_hw
;
1251 qlcnic_create_sysfs_entries(adapter
);
1253 adapter
->is_up
= QLCNIC_ADAPTER_UP_MAGIC
;
1257 qlcnic_free_hw_resources(adapter
);
1259 qlcnic_free_sw_resources(adapter
);
1261 qlcnic_napi_del(adapter
);
1266 qlcnic_detach(struct qlcnic_adapter
*adapter
)
1268 if (adapter
->is_up
!= QLCNIC_ADAPTER_UP_MAGIC
)
1271 qlcnic_remove_sysfs_entries(adapter
);
1273 qlcnic_free_hw_resources(adapter
);
1274 qlcnic_release_rx_buffers(adapter
);
1275 qlcnic_free_irq(adapter
);
1276 qlcnic_napi_del(adapter
);
1277 qlcnic_free_sw_resources(adapter
);
1282 void qlcnic_diag_free_res(struct net_device
*netdev
, int max_sds_rings
)
1284 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
1285 struct qlcnic_host_sds_ring
*sds_ring
;
1288 clear_bit(__QLCNIC_DEV_UP
, &adapter
->state
);
1289 if (adapter
->diag_test
== QLCNIC_INTERRUPT_TEST
) {
1290 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
1291 sds_ring
= &adapter
->recv_ctx
->sds_rings
[ring
];
1292 qlcnic_disable_int(sds_ring
);
1296 qlcnic_fw_destroy_ctx(adapter
);
1298 qlcnic_detach(adapter
);
1300 adapter
->diag_test
= 0;
1301 adapter
->max_sds_rings
= max_sds_rings
;
1303 if (qlcnic_attach(adapter
))
1306 if (netif_running(netdev
))
1307 __qlcnic_up(adapter
, netdev
);
1309 netif_device_attach(netdev
);
1312 static int qlcnic_alloc_adapter_resources(struct qlcnic_adapter
*adapter
)
1315 adapter
->ahw
= kzalloc(sizeof(struct qlcnic_hardware_context
),
1317 if (!adapter
->ahw
) {
1318 dev_err(&adapter
->pdev
->dev
,
1319 "Failed to allocate recv ctx resources for adapter\n");
1323 adapter
->recv_ctx
= kzalloc(sizeof(struct qlcnic_recv_context
),
1325 if (!adapter
->recv_ctx
) {
1326 dev_err(&adapter
->pdev
->dev
,
1327 "Failed to allocate recv ctx resources for adapter\n");
1328 kfree(adapter
->ahw
);
1329 adapter
->ahw
= NULL
;
1333 /* Initialize interrupt coalesce parameters */
1334 adapter
->ahw
->coal
.flag
= QLCNIC_INTR_DEFAULT
;
1335 adapter
->ahw
->coal
.rx_time_us
= QLCNIC_DEFAULT_INTR_COALESCE_RX_TIME_US
;
1336 adapter
->ahw
->coal
.rx_packets
= QLCNIC_DEFAULT_INTR_COALESCE_RX_PACKETS
;
1341 static void qlcnic_free_adapter_resources(struct qlcnic_adapter
*adapter
)
1343 kfree(adapter
->recv_ctx
);
1344 adapter
->recv_ctx
= NULL
;
1346 if (adapter
->ahw
->fw_dump
.tmpl_hdr
) {
1347 vfree(adapter
->ahw
->fw_dump
.tmpl_hdr
);
1348 adapter
->ahw
->fw_dump
.tmpl_hdr
= NULL
;
1350 kfree(adapter
->ahw
);
1351 adapter
->ahw
= NULL
;
1354 int qlcnic_diag_alloc_res(struct net_device
*netdev
, int test
)
1356 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
1357 struct qlcnic_host_sds_ring
*sds_ring
;
1358 struct qlcnic_host_rds_ring
*rds_ring
;
1362 netif_device_detach(netdev
);
1364 if (netif_running(netdev
))
1365 __qlcnic_down(adapter
, netdev
);
1367 qlcnic_detach(adapter
);
1369 adapter
->max_sds_rings
= 1;
1370 adapter
->diag_test
= test
;
1372 ret
= qlcnic_attach(adapter
);
1374 netif_device_attach(netdev
);
1378 ret
= qlcnic_fw_create_ctx(adapter
);
1380 qlcnic_detach(adapter
);
1381 netif_device_attach(netdev
);
1385 for (ring
= 0; ring
< adapter
->max_rds_rings
; ring
++) {
1386 rds_ring
= &adapter
->recv_ctx
->rds_rings
[ring
];
1387 qlcnic_post_rx_buffers(adapter
, rds_ring
);
1390 if (adapter
->diag_test
== QLCNIC_INTERRUPT_TEST
) {
1391 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
1392 sds_ring
= &adapter
->recv_ctx
->sds_rings
[ring
];
1393 qlcnic_enable_int(sds_ring
);
1396 set_bit(__QLCNIC_DEV_UP
, &adapter
->state
);
1401 /* Reset context in hardware only */
1403 qlcnic_reset_hw_context(struct qlcnic_adapter
*adapter
)
1405 struct net_device
*netdev
= adapter
->netdev
;
1407 if (test_and_set_bit(__QLCNIC_RESETTING
, &adapter
->state
))
1410 netif_device_detach(netdev
);
1412 qlcnic_down(adapter
, netdev
);
1414 qlcnic_up(adapter
, netdev
);
1416 netif_device_attach(netdev
);
1418 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
1423 qlcnic_reset_context(struct qlcnic_adapter
*adapter
)
1426 struct net_device
*netdev
= adapter
->netdev
;
1428 if (test_and_set_bit(__QLCNIC_RESETTING
, &adapter
->state
))
1431 if (adapter
->is_up
== QLCNIC_ADAPTER_UP_MAGIC
) {
1433 netif_device_detach(netdev
);
1435 if (netif_running(netdev
))
1436 __qlcnic_down(adapter
, netdev
);
1438 qlcnic_detach(adapter
);
1440 if (netif_running(netdev
)) {
1441 err
= qlcnic_attach(adapter
);
1443 __qlcnic_up(adapter
, netdev
);
1446 netif_device_attach(netdev
);
1449 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
1454 qlcnic_setup_netdev(struct qlcnic_adapter
*adapter
,
1455 struct net_device
*netdev
, u8 pci_using_dac
)
1458 struct pci_dev
*pdev
= adapter
->pdev
;
1460 adapter
->mc_enabled
= 0;
1461 adapter
->max_mc_count
= 38;
1463 netdev
->netdev_ops
= &qlcnic_netdev_ops
;
1464 netdev
->watchdog_timeo
= 5*HZ
;
1466 qlcnic_change_mtu(netdev
, netdev
->mtu
);
1468 SET_ETHTOOL_OPS(netdev
, &qlcnic_ethtool_ops
);
1470 netdev
->hw_features
= NETIF_F_SG
| NETIF_F_IP_CSUM
|
1471 NETIF_F_IPV6_CSUM
| NETIF_F_RXCSUM
;
1473 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_TSO
)
1474 netdev
->hw_features
|= NETIF_F_TSO
| NETIF_F_TSO6
;
1476 netdev
->hw_features
|= NETIF_F_HIGHDMA
;
1478 netdev
->vlan_features
= netdev
->hw_features
;
1480 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_FVLANTX
)
1481 netdev
->hw_features
|= NETIF_F_HW_VLAN_TX
;
1482 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_HW_LRO
)
1483 netdev
->hw_features
|= NETIF_F_LRO
;
1485 netdev
->features
|= netdev
->hw_features
|
1486 NETIF_F_HW_VLAN_RX
| NETIF_F_HW_VLAN_FILTER
;
1488 netdev
->irq
= adapter
->msix_entries
[0].vector
;
1490 netif_carrier_off(netdev
);
1492 err
= register_netdev(netdev
);
1494 dev_err(&pdev
->dev
, "failed to register net device\n");
1501 static int qlcnic_set_dma_mask(struct pci_dev
*pdev
, u8
*pci_using_dac
)
1503 if (!pci_set_dma_mask(pdev
, DMA_BIT_MASK(64)) &&
1504 !pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(64)))
1506 else if (!pci_set_dma_mask(pdev
, DMA_BIT_MASK(32)) &&
1507 !pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(32)))
1510 dev_err(&pdev
->dev
, "Unable to set DMA mask, aborting\n");
1518 qlcnic_alloc_msix_entries(struct qlcnic_adapter
*adapter
, u16 count
)
1520 adapter
->msix_entries
= kcalloc(count
, sizeof(struct msix_entry
),
1523 if (adapter
->msix_entries
)
1526 dev_err(&adapter
->pdev
->dev
, "failed allocating msix_entries\n");
1530 static int __devinit
1531 qlcnic_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
1533 struct net_device
*netdev
= NULL
;
1534 struct qlcnic_adapter
*adapter
= NULL
;
1536 uint8_t revision_id
;
1537 uint8_t pci_using_dac
;
1538 char brd_name
[QLCNIC_MAX_BOARD_NAME_LEN
];
1540 err
= pci_enable_device(pdev
);
1544 if (!(pci_resource_flags(pdev
, 0) & IORESOURCE_MEM
)) {
1546 goto err_out_disable_pdev
;
1549 err
= qlcnic_set_dma_mask(pdev
, &pci_using_dac
);
1551 goto err_out_disable_pdev
;
1553 err
= pci_request_regions(pdev
, qlcnic_driver_name
);
1555 goto err_out_disable_pdev
;
1557 pci_set_master(pdev
);
1558 pci_enable_pcie_error_reporting(pdev
);
1560 netdev
= alloc_etherdev(sizeof(struct qlcnic_adapter
));
1562 dev_err(&pdev
->dev
, "failed to allocate net_device\n");
1564 goto err_out_free_res
;
1567 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
1569 adapter
= netdev_priv(netdev
);
1570 adapter
->netdev
= netdev
;
1571 adapter
->pdev
= pdev
;
1573 if (qlcnic_alloc_adapter_resources(adapter
))
1574 goto err_out_free_netdev
;
1576 adapter
->dev_rst_time
= jiffies
;
1577 revision_id
= pdev
->revision
;
1578 adapter
->ahw
->revision_id
= revision_id
;
1580 rwlock_init(&adapter
->ahw
->crb_lock
);
1581 mutex_init(&adapter
->ahw
->mem_lock
);
1583 spin_lock_init(&adapter
->tx_clean_lock
);
1584 INIT_LIST_HEAD(&adapter
->mac_list
);
1586 err
= qlcnic_setup_pci_map(adapter
);
1588 goto err_out_free_hw
;
1590 /* This will be reset for mezz cards */
1591 adapter
->portnum
= adapter
->ahw
->pci_func
;
1593 /* Get FW dump template and store it */
1594 if (adapter
->op_mode
!= QLCNIC_NON_PRIV_FUNC
)
1595 qlcnic_fw_cmd_get_minidump_temp(adapter
);
1597 err
= qlcnic_get_board_info(adapter
);
1599 dev_err(&pdev
->dev
, "Error getting board config info.\n");
1600 goto err_out_iounmap
;
1603 err
= qlcnic_setup_idc_param(adapter
);
1605 goto err_out_iounmap
;
1607 adapter
->flags
|= QLCNIC_NEED_FLR
;
1609 err
= adapter
->nic_ops
->start_firmware(adapter
);
1611 dev_err(&pdev
->dev
, "Loading fw failed.Please Reboot\n");
1612 goto err_out_decr_ref
;
1615 if (qlcnic_read_mac_addr(adapter
))
1616 dev_warn(&pdev
->dev
, "failed to read mac addr\n");
1618 if (adapter
->portnum
== 0) {
1619 get_brd_name(adapter
, brd_name
);
1621 pr_info("%s: %s Board Chip rev 0x%x\n",
1622 module_name(THIS_MODULE
),
1623 brd_name
, adapter
->ahw
->revision_id
);
1626 qlcnic_clear_stats(adapter
);
1628 err
= qlcnic_alloc_msix_entries(adapter
, adapter
->max_rx_ques
);
1630 goto err_out_decr_ref
;
1632 qlcnic_setup_intr(adapter
);
1634 err
= qlcnic_setup_netdev(adapter
, netdev
, pci_using_dac
);
1636 goto err_out_disable_msi
;
1638 pci_set_drvdata(pdev
, adapter
);
1640 qlcnic_schedule_work(adapter
, qlcnic_fw_poll_work
, FW_POLL_DELAY
);
1642 switch (adapter
->ahw
->port_type
) {
1644 dev_info(&adapter
->pdev
->dev
, "%s: GbE port initialized\n",
1645 adapter
->netdev
->name
);
1648 dev_info(&adapter
->pdev
->dev
, "%s: XGbE port initialized\n",
1649 adapter
->netdev
->name
);
1653 qlcnic_alloc_lb_filters_mem(adapter
);
1654 qlcnic_create_diag_entries(adapter
);
1658 err_out_disable_msi
:
1659 qlcnic_teardown_intr(adapter
);
1660 kfree(adapter
->msix_entries
);
1663 qlcnic_clr_all_drv_state(adapter
, 0);
1666 qlcnic_cleanup_pci_map(adapter
);
1669 qlcnic_free_adapter_resources(adapter
);
1671 err_out_free_netdev
:
1672 free_netdev(netdev
);
1675 pci_release_regions(pdev
);
1677 err_out_disable_pdev
:
1678 pci_set_drvdata(pdev
, NULL
);
1679 pci_disable_device(pdev
);
1683 static void __devexit
qlcnic_remove(struct pci_dev
*pdev
)
1685 struct qlcnic_adapter
*adapter
;
1686 struct net_device
*netdev
;
1688 adapter
= pci_get_drvdata(pdev
);
1689 if (adapter
== NULL
)
1692 netdev
= adapter
->netdev
;
1694 qlcnic_cancel_fw_work(adapter
);
1696 unregister_netdev(netdev
);
1698 qlcnic_detach(adapter
);
1700 if (adapter
->npars
!= NULL
)
1701 kfree(adapter
->npars
);
1702 if (adapter
->eswitch
!= NULL
)
1703 kfree(adapter
->eswitch
);
1705 qlcnic_clr_all_drv_state(adapter
, 0);
1707 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
1709 qlcnic_free_lb_filters_mem(adapter
);
1711 qlcnic_teardown_intr(adapter
);
1712 kfree(adapter
->msix_entries
);
1714 qlcnic_remove_diag_entries(adapter
);
1716 qlcnic_cleanup_pci_map(adapter
);
1718 qlcnic_release_firmware(adapter
);
1720 pci_disable_pcie_error_reporting(pdev
);
1721 pci_release_regions(pdev
);
1722 pci_disable_device(pdev
);
1723 pci_set_drvdata(pdev
, NULL
);
1725 qlcnic_free_adapter_resources(adapter
);
1726 free_netdev(netdev
);
1728 static int __qlcnic_shutdown(struct pci_dev
*pdev
)
1730 struct qlcnic_adapter
*adapter
= pci_get_drvdata(pdev
);
1731 struct net_device
*netdev
= adapter
->netdev
;
1734 netif_device_detach(netdev
);
1736 qlcnic_cancel_fw_work(adapter
);
1738 if (netif_running(netdev
))
1739 qlcnic_down(adapter
, netdev
);
1741 qlcnic_clr_all_drv_state(adapter
, 0);
1743 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
1745 retval
= pci_save_state(pdev
);
1749 if (qlcnic_wol_supported(adapter
)) {
1750 pci_enable_wake(pdev
, PCI_D3cold
, 1);
1751 pci_enable_wake(pdev
, PCI_D3hot
, 1);
1757 static void qlcnic_shutdown(struct pci_dev
*pdev
)
1759 if (__qlcnic_shutdown(pdev
))
1762 pci_disable_device(pdev
);
1767 qlcnic_suspend(struct pci_dev
*pdev
, pm_message_t state
)
1771 retval
= __qlcnic_shutdown(pdev
);
1775 pci_set_power_state(pdev
, pci_choose_state(pdev
, state
));
1780 qlcnic_resume(struct pci_dev
*pdev
)
1782 struct qlcnic_adapter
*adapter
= pci_get_drvdata(pdev
);
1783 struct net_device
*netdev
= adapter
->netdev
;
1786 err
= pci_enable_device(pdev
);
1790 pci_set_power_state(pdev
, PCI_D0
);
1791 pci_set_master(pdev
);
1792 pci_restore_state(pdev
);
1794 err
= adapter
->nic_ops
->start_firmware(adapter
);
1796 dev_err(&pdev
->dev
, "failed to start firmware\n");
1800 if (netif_running(netdev
)) {
1801 err
= qlcnic_up(adapter
, netdev
);
1805 qlcnic_restore_indev_addr(netdev
, NETDEV_UP
);
1808 netif_device_attach(netdev
);
1809 qlcnic_schedule_work(adapter
, qlcnic_fw_poll_work
, FW_POLL_DELAY
);
1814 static int qlcnic_open(struct net_device
*netdev
)
1816 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
1819 err
= qlcnic_attach(adapter
);
1823 err
= __qlcnic_up(adapter
, netdev
);
1827 netif_start_queue(netdev
);
1832 qlcnic_detach(adapter
);
1837 * qlcnic_close - Disables a network interface entry point
1839 static int qlcnic_close(struct net_device
*netdev
)
1841 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
1843 __qlcnic_down(adapter
, netdev
);
1848 qlcnic_alloc_lb_filters_mem(struct qlcnic_adapter
*adapter
)
1853 if (!qlcnic_mac_learn
)
1856 spin_lock_init(&adapter
->mac_learn_lock
);
1858 head
= kcalloc(QLCNIC_LB_MAX_FILTERS
, sizeof(struct hlist_head
),
1863 adapter
->fhash
.fmax
= QLCNIC_LB_MAX_FILTERS
;
1864 adapter
->fhash
.fhead
= (struct hlist_head
*)head
;
1866 for (i
= 0; i
< adapter
->fhash
.fmax
; i
++)
1867 INIT_HLIST_HEAD(&adapter
->fhash
.fhead
[i
]);
1870 static void qlcnic_free_lb_filters_mem(struct qlcnic_adapter
*adapter
)
1872 if (adapter
->fhash
.fmax
&& adapter
->fhash
.fhead
)
1873 kfree(adapter
->fhash
.fhead
);
1875 adapter
->fhash
.fhead
= NULL
;
1876 adapter
->fhash
.fmax
= 0;
1879 static void qlcnic_change_filter(struct qlcnic_adapter
*adapter
,
1880 u64 uaddr
, __le16 vlan_id
, struct qlcnic_host_tx_ring
*tx_ring
)
1882 struct cmd_desc_type0
*hwdesc
;
1883 struct qlcnic_nic_req
*req
;
1884 struct qlcnic_mac_req
*mac_req
;
1885 struct qlcnic_vlan_req
*vlan_req
;
1889 producer
= tx_ring
->producer
;
1890 hwdesc
= &tx_ring
->desc_head
[tx_ring
->producer
];
1892 req
= (struct qlcnic_nic_req
*)hwdesc
;
1893 memset(req
, 0, sizeof(struct qlcnic_nic_req
));
1894 req
->qhdr
= cpu_to_le64(QLCNIC_REQUEST
<< 23);
1896 word
= QLCNIC_MAC_EVENT
| ((u64
)(adapter
->portnum
) << 16);
1897 req
->req_hdr
= cpu_to_le64(word
);
1899 mac_req
= (struct qlcnic_mac_req
*)&(req
->words
[0]);
1900 mac_req
->op
= vlan_id
? QLCNIC_MAC_VLAN_ADD
: QLCNIC_MAC_ADD
;
1901 memcpy(mac_req
->mac_addr
, &uaddr
, ETH_ALEN
);
1903 vlan_req
= (struct qlcnic_vlan_req
*)&req
->words
[1];
1904 vlan_req
->vlan_id
= vlan_id
;
1906 tx_ring
->producer
= get_next_index(producer
, tx_ring
->num_desc
);
1910 #define QLCNIC_MAC_HASH(MAC)\
1911 ((((MAC) & 0x70000) >> 0x10) | (((MAC) & 0x70000000000ULL) >> 0x25))
1914 qlcnic_send_filter(struct qlcnic_adapter
*adapter
,
1915 struct qlcnic_host_tx_ring
*tx_ring
,
1916 struct cmd_desc_type0
*first_desc
,
1917 struct sk_buff
*skb
)
1919 struct ethhdr
*phdr
= (struct ethhdr
*)(skb
->data
);
1920 struct qlcnic_filter
*fil
, *tmp_fil
;
1921 struct hlist_node
*tmp_hnode
, *n
;
1922 struct hlist_head
*head
;
1927 if (!compare_ether_addr(phdr
->h_source
, adapter
->mac_addr
))
1930 if (adapter
->fhash
.fnum
>= adapter
->fhash
.fmax
)
1933 /* Only NPAR capable devices support vlan based learning*/
1934 if (adapter
->flags
& QLCNIC_ESWITCH_ENABLED
)
1935 vlan_id
= first_desc
->vlan_TCI
;
1936 memcpy(&src_addr
, phdr
->h_source
, ETH_ALEN
);
1937 hindex
= QLCNIC_MAC_HASH(src_addr
) & (QLCNIC_LB_MAX_FILTERS
- 1);
1938 head
= &(adapter
->fhash
.fhead
[hindex
]);
1940 hlist_for_each_entry_safe(tmp_fil
, tmp_hnode
, n
, head
, fnode
) {
1941 if (!memcmp(tmp_fil
->faddr
, &src_addr
, ETH_ALEN
) &&
1942 tmp_fil
->vlan_id
== vlan_id
) {
1945 (QLCNIC_READD_AGE
* HZ
+ tmp_fil
->ftime
))
1946 qlcnic_change_filter(adapter
, src_addr
, vlan_id
,
1948 tmp_fil
->ftime
= jiffies
;
1953 fil
= kzalloc(sizeof(struct qlcnic_filter
), GFP_ATOMIC
);
1957 qlcnic_change_filter(adapter
, src_addr
, vlan_id
, tx_ring
);
1959 fil
->ftime
= jiffies
;
1960 fil
->vlan_id
= vlan_id
;
1961 memcpy(fil
->faddr
, &src_addr
, ETH_ALEN
);
1962 spin_lock(&adapter
->mac_learn_lock
);
1963 hlist_add_head(&(fil
->fnode
), head
);
1964 adapter
->fhash
.fnum
++;
1965 spin_unlock(&adapter
->mac_learn_lock
);
1969 qlcnic_tx_pkt(struct qlcnic_adapter
*adapter
,
1970 struct cmd_desc_type0
*first_desc
,
1971 struct sk_buff
*skb
)
1973 u8 opcode
= 0, hdr_len
= 0;
1974 u16 flags
= 0, vlan_tci
= 0;
1975 int copied
, offset
, copy_len
;
1976 struct cmd_desc_type0
*hwdesc
;
1977 struct vlan_ethhdr
*vh
;
1978 struct qlcnic_host_tx_ring
*tx_ring
= adapter
->tx_ring
;
1979 u16 protocol
= ntohs(skb
->protocol
);
1980 u32 producer
= tx_ring
->producer
;
1982 if (protocol
== ETH_P_8021Q
) {
1983 vh
= (struct vlan_ethhdr
*)skb
->data
;
1984 flags
= FLAGS_VLAN_TAGGED
;
1985 vlan_tci
= vh
->h_vlan_TCI
;
1986 } else if (vlan_tx_tag_present(skb
)) {
1987 flags
= FLAGS_VLAN_OOB
;
1988 vlan_tci
= vlan_tx_tag_get(skb
);
1990 if (unlikely(adapter
->pvid
)) {
1991 if (vlan_tci
&& !(adapter
->flags
& QLCNIC_TAGGING_ENABLED
))
1993 if (vlan_tci
&& (adapter
->flags
& QLCNIC_TAGGING_ENABLED
))
1996 flags
= FLAGS_VLAN_OOB
;
1997 vlan_tci
= adapter
->pvid
;
2000 qlcnic_set_tx_vlan_tci(first_desc
, vlan_tci
);
2001 qlcnic_set_tx_flags_opcode(first_desc
, flags
, opcode
);
2003 if (*(skb
->data
) & BIT_0
) {
2005 memcpy(&first_desc
->eth_addr
, skb
->data
, ETH_ALEN
);
2007 opcode
= TX_ETHER_PKT
;
2008 if ((adapter
->netdev
->features
& (NETIF_F_TSO
| NETIF_F_TSO6
)) &&
2009 skb_shinfo(skb
)->gso_size
> 0) {
2011 hdr_len
= skb_transport_offset(skb
) + tcp_hdrlen(skb
);
2013 first_desc
->mss
= cpu_to_le16(skb_shinfo(skb
)->gso_size
);
2014 first_desc
->total_hdr_length
= hdr_len
;
2016 opcode
= (protocol
== ETH_P_IPV6
) ? TX_TCP_LSO6
: TX_TCP_LSO
;
2018 /* For LSO, we need to copy the MAC/IP/TCP headers into
2019 * the descriptor ring */
2023 if (flags
& FLAGS_VLAN_OOB
) {
2024 first_desc
->total_hdr_length
+= VLAN_HLEN
;
2025 first_desc
->tcp_hdr_offset
= VLAN_HLEN
;
2026 first_desc
->ip_hdr_offset
= VLAN_HLEN
;
2027 /* Only in case of TSO on vlan device */
2028 flags
|= FLAGS_VLAN_TAGGED
;
2030 /* Create a TSO vlan header template for firmware */
2032 hwdesc
= &tx_ring
->desc_head
[producer
];
2033 tx_ring
->cmd_buf_arr
[producer
].skb
= NULL
;
2035 copy_len
= min((int)sizeof(struct cmd_desc_type0
) -
2036 offset
, hdr_len
+ VLAN_HLEN
);
2038 vh
= (struct vlan_ethhdr
*)((char *) hwdesc
+ 2);
2039 skb_copy_from_linear_data(skb
, vh
, 12);
2040 vh
->h_vlan_proto
= htons(ETH_P_8021Q
);
2041 vh
->h_vlan_TCI
= htons(vlan_tci
);
2043 skb_copy_from_linear_data_offset(skb
, 12,
2044 (char *)vh
+ 16, copy_len
- 16);
2046 copied
= copy_len
- VLAN_HLEN
;
2049 producer
= get_next_index(producer
, tx_ring
->num_desc
);
2052 while (copied
< hdr_len
) {
2054 copy_len
= min((int)sizeof(struct cmd_desc_type0
) -
2055 offset
, (hdr_len
- copied
));
2057 hwdesc
= &tx_ring
->desc_head
[producer
];
2058 tx_ring
->cmd_buf_arr
[producer
].skb
= NULL
;
2060 skb_copy_from_linear_data_offset(skb
, copied
,
2061 (char *) hwdesc
+ offset
, copy_len
);
2066 producer
= get_next_index(producer
, tx_ring
->num_desc
);
2069 tx_ring
->producer
= producer
;
2071 adapter
->stats
.lso_frames
++;
2073 } else if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
2076 if (protocol
== ETH_P_IP
) {
2077 l4proto
= ip_hdr(skb
)->protocol
;
2079 if (l4proto
== IPPROTO_TCP
)
2080 opcode
= TX_TCP_PKT
;
2081 else if (l4proto
== IPPROTO_UDP
)
2082 opcode
= TX_UDP_PKT
;
2083 } else if (protocol
== ETH_P_IPV6
) {
2084 l4proto
= ipv6_hdr(skb
)->nexthdr
;
2086 if (l4proto
== IPPROTO_TCP
)
2087 opcode
= TX_TCPV6_PKT
;
2088 else if (l4proto
== IPPROTO_UDP
)
2089 opcode
= TX_UDPV6_PKT
;
2092 first_desc
->tcp_hdr_offset
+= skb_transport_offset(skb
);
2093 first_desc
->ip_hdr_offset
+= skb_network_offset(skb
);
2094 qlcnic_set_tx_flags_opcode(first_desc
, flags
, opcode
);
2100 qlcnic_map_tx_skb(struct pci_dev
*pdev
,
2101 struct sk_buff
*skb
, struct qlcnic_cmd_buffer
*pbuf
)
2103 struct qlcnic_skb_frag
*nf
;
2104 struct skb_frag_struct
*frag
;
2108 nr_frags
= skb_shinfo(skb
)->nr_frags
;
2109 nf
= &pbuf
->frag_array
[0];
2111 map
= pci_map_single(pdev
, skb
->data
,
2112 skb_headlen(skb
), PCI_DMA_TODEVICE
);
2113 if (pci_dma_mapping_error(pdev
, map
))
2117 nf
->length
= skb_headlen(skb
);
2119 for (i
= 0; i
< nr_frags
; i
++) {
2120 frag
= &skb_shinfo(skb
)->frags
[i
];
2121 nf
= &pbuf
->frag_array
[i
+1];
2123 map
= pci_map_page(pdev
, frag
->page
, frag
->page_offset
,
2124 frag
->size
, PCI_DMA_TODEVICE
);
2125 if (pci_dma_mapping_error(pdev
, map
))
2129 nf
->length
= frag
->size
;
2136 nf
= &pbuf
->frag_array
[i
+1];
2137 pci_unmap_page(pdev
, nf
->dma
, nf
->length
, PCI_DMA_TODEVICE
);
2140 nf
= &pbuf
->frag_array
[0];
2141 pci_unmap_single(pdev
, nf
->dma
, skb_headlen(skb
), PCI_DMA_TODEVICE
);
2148 qlcnic_unmap_buffers(struct pci_dev
*pdev
, struct sk_buff
*skb
,
2149 struct qlcnic_cmd_buffer
*pbuf
)
2151 struct qlcnic_skb_frag
*nf
= &pbuf
->frag_array
[0];
2152 int nr_frags
= skb_shinfo(skb
)->nr_frags
;
2155 for (i
= 0; i
< nr_frags
; i
++) {
2156 nf
= &pbuf
->frag_array
[i
+1];
2157 pci_unmap_page(pdev
, nf
->dma
, nf
->length
, PCI_DMA_TODEVICE
);
2160 nf
= &pbuf
->frag_array
[0];
2161 pci_unmap_single(pdev
, nf
->dma
, skb_headlen(skb
), PCI_DMA_TODEVICE
);
2165 qlcnic_clear_cmddesc(u64
*desc
)
2173 qlcnic_xmit_frame(struct sk_buff
*skb
, struct net_device
*netdev
)
2175 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
2176 struct qlcnic_host_tx_ring
*tx_ring
= adapter
->tx_ring
;
2177 struct qlcnic_cmd_buffer
*pbuf
;
2178 struct qlcnic_skb_frag
*buffrag
;
2179 struct cmd_desc_type0
*hwdesc
, *first_desc
;
2180 struct pci_dev
*pdev
;
2181 struct ethhdr
*phdr
;
2187 u32 num_txd
= tx_ring
->num_desc
;
2189 if (!test_bit(__QLCNIC_DEV_UP
, &adapter
->state
)) {
2190 netif_stop_queue(netdev
);
2191 return NETDEV_TX_BUSY
;
2194 if (adapter
->flags
& QLCNIC_MACSPOOF
) {
2195 phdr
= (struct ethhdr
*)skb
->data
;
2196 if (compare_ether_addr(phdr
->h_source
,
2201 frag_count
= skb_shinfo(skb
)->nr_frags
+ 1;
2202 /* 14 frags supported for normal packet and
2203 * 32 frags supported for TSO packet
2205 if (!skb_is_gso(skb
) && frag_count
> QLCNIC_MAX_FRAGS_PER_TX
) {
2207 for (i
= 0; i
< (frag_count
- QLCNIC_MAX_FRAGS_PER_TX
); i
++)
2208 delta
+= skb_shinfo(skb
)->frags
[i
].size
;
2210 if (!__pskb_pull_tail(skb
, delta
))
2213 frag_count
= 1 + skb_shinfo(skb
)->nr_frags
;
2216 if (unlikely(qlcnic_tx_avail(tx_ring
) <= TX_STOP_THRESH
)) {
2217 netif_stop_queue(netdev
);
2218 if (qlcnic_tx_avail(tx_ring
) > TX_STOP_THRESH
)
2219 netif_start_queue(netdev
);
2221 adapter
->stats
.xmit_off
++;
2222 return NETDEV_TX_BUSY
;
2226 producer
= tx_ring
->producer
;
2227 pbuf
= &tx_ring
->cmd_buf_arr
[producer
];
2229 pdev
= adapter
->pdev
;
2231 first_desc
= hwdesc
= &tx_ring
->desc_head
[producer
];
2232 qlcnic_clear_cmddesc((u64
*)hwdesc
);
2234 if (qlcnic_map_tx_skb(pdev
, skb
, pbuf
)) {
2235 adapter
->stats
.tx_dma_map_error
++;
2240 pbuf
->frag_count
= frag_count
;
2242 qlcnic_set_tx_frags_len(first_desc
, frag_count
, skb
->len
);
2243 qlcnic_set_tx_port(first_desc
, adapter
->portnum
);
2245 for (i
= 0; i
< frag_count
; i
++) {
2249 if ((k
== 0) && (i
> 0)) {
2250 /* move to next desc.*/
2251 producer
= get_next_index(producer
, num_txd
);
2252 hwdesc
= &tx_ring
->desc_head
[producer
];
2253 qlcnic_clear_cmddesc((u64
*)hwdesc
);
2254 tx_ring
->cmd_buf_arr
[producer
].skb
= NULL
;
2257 buffrag
= &pbuf
->frag_array
[i
];
2259 hwdesc
->buffer_length
[k
] = cpu_to_le16(buffrag
->length
);
2262 hwdesc
->addr_buffer1
= cpu_to_le64(buffrag
->dma
);
2265 hwdesc
->addr_buffer2
= cpu_to_le64(buffrag
->dma
);
2268 hwdesc
->addr_buffer3
= cpu_to_le64(buffrag
->dma
);
2271 hwdesc
->addr_buffer4
= cpu_to_le64(buffrag
->dma
);
2276 tx_ring
->producer
= get_next_index(producer
, num_txd
);
2279 if (unlikely(qlcnic_tx_pkt(adapter
, first_desc
, skb
)))
2282 if (qlcnic_mac_learn
)
2283 qlcnic_send_filter(adapter
, tx_ring
, first_desc
, skb
);
2285 qlcnic_update_cmd_producer(adapter
, tx_ring
);
2287 adapter
->stats
.txbytes
+= skb
->len
;
2288 adapter
->stats
.xmitcalled
++;
2290 return NETDEV_TX_OK
;
2293 qlcnic_unmap_buffers(pdev
, skb
, pbuf
);
2295 adapter
->stats
.txdropped
++;
2296 dev_kfree_skb_any(skb
);
2297 return NETDEV_TX_OK
;
2300 static int qlcnic_check_temp(struct qlcnic_adapter
*adapter
)
2302 struct net_device
*netdev
= adapter
->netdev
;
2303 u32 temp
, temp_state
, temp_val
;
2306 temp
= QLCRD32(adapter
, CRB_TEMP_STATE
);
2308 temp_state
= qlcnic_get_temp_state(temp
);
2309 temp_val
= qlcnic_get_temp_val(temp
);
2311 if (temp_state
== QLCNIC_TEMP_PANIC
) {
2312 dev_err(&netdev
->dev
,
2313 "Device temperature %d degrees C exceeds"
2314 " maximum allowed. Hardware has been shut down.\n",
2317 } else if (temp_state
== QLCNIC_TEMP_WARN
) {
2318 if (adapter
->temp
== QLCNIC_TEMP_NORMAL
) {
2319 dev_err(&netdev
->dev
,
2320 "Device temperature %d degrees C "
2321 "exceeds operating range."
2322 " Immediate action needed.\n",
2326 if (adapter
->temp
== QLCNIC_TEMP_WARN
) {
2327 dev_info(&netdev
->dev
,
2328 "Device temperature is now %d degrees C"
2329 " in normal range.\n", temp_val
);
2332 adapter
->temp
= temp_state
;
2336 void qlcnic_advert_link_change(struct qlcnic_adapter
*adapter
, int linkup
)
2338 struct net_device
*netdev
= adapter
->netdev
;
2340 if (adapter
->ahw
->linkup
&& !linkup
) {
2341 netdev_info(netdev
, "NIC Link is down\n");
2342 adapter
->ahw
->linkup
= 0;
2343 if (netif_running(netdev
)) {
2344 netif_carrier_off(netdev
);
2345 netif_stop_queue(netdev
);
2347 } else if (!adapter
->ahw
->linkup
&& linkup
) {
2348 netdev_info(netdev
, "NIC Link is up\n");
2349 adapter
->ahw
->linkup
= 1;
2350 if (netif_running(netdev
)) {
2351 netif_carrier_on(netdev
);
2352 netif_wake_queue(netdev
);
2357 static void qlcnic_tx_timeout(struct net_device
*netdev
)
2359 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
2361 if (test_bit(__QLCNIC_RESETTING
, &adapter
->state
))
2364 dev_err(&netdev
->dev
, "transmit timeout, resetting.\n");
2366 if (++adapter
->tx_timeo_cnt
>= QLCNIC_MAX_TX_TIMEOUTS
)
2367 adapter
->need_fw_reset
= 1;
2369 adapter
->reset_context
= 1;
2372 static struct net_device_stats
*qlcnic_get_stats(struct net_device
*netdev
)
2374 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
2375 struct net_device_stats
*stats
= &netdev
->stats
;
2377 stats
->rx_packets
= adapter
->stats
.rx_pkts
+ adapter
->stats
.lro_pkts
;
2378 stats
->tx_packets
= adapter
->stats
.xmitfinished
;
2379 stats
->rx_bytes
= adapter
->stats
.rxbytes
+ adapter
->stats
.lrobytes
;
2380 stats
->tx_bytes
= adapter
->stats
.txbytes
;
2381 stats
->rx_dropped
= adapter
->stats
.rxdropped
;
2382 stats
->tx_dropped
= adapter
->stats
.txdropped
;
2387 static irqreturn_t
qlcnic_clear_legacy_intr(struct qlcnic_adapter
*adapter
)
2391 status
= readl(adapter
->isr_int_vec
);
2393 if (!(status
& adapter
->int_vec_bit
))
2396 /* check interrupt state machine, to be sure */
2397 status
= readl(adapter
->crb_int_state_reg
);
2398 if (!ISR_LEGACY_INT_TRIGGERED(status
))
2401 writel(0xffffffff, adapter
->tgt_status_reg
);
2402 /* read twice to ensure write is flushed */
2403 readl(adapter
->isr_int_vec
);
2404 readl(adapter
->isr_int_vec
);
2409 static irqreturn_t
qlcnic_tmp_intr(int irq
, void *data
)
2411 struct qlcnic_host_sds_ring
*sds_ring
= data
;
2412 struct qlcnic_adapter
*adapter
= sds_ring
->adapter
;
2414 if (adapter
->flags
& QLCNIC_MSIX_ENABLED
)
2416 else if (adapter
->flags
& QLCNIC_MSI_ENABLED
) {
2417 writel(0xffffffff, adapter
->tgt_status_reg
);
2421 if (qlcnic_clear_legacy_intr(adapter
) == IRQ_NONE
)
2425 adapter
->diag_cnt
++;
2426 qlcnic_enable_int(sds_ring
);
2430 static irqreturn_t
qlcnic_intr(int irq
, void *data
)
2432 struct qlcnic_host_sds_ring
*sds_ring
= data
;
2433 struct qlcnic_adapter
*adapter
= sds_ring
->adapter
;
2435 if (qlcnic_clear_legacy_intr(adapter
) == IRQ_NONE
)
2438 napi_schedule(&sds_ring
->napi
);
2443 static irqreturn_t
qlcnic_msi_intr(int irq
, void *data
)
2445 struct qlcnic_host_sds_ring
*sds_ring
= data
;
2446 struct qlcnic_adapter
*adapter
= sds_ring
->adapter
;
2448 /* clear interrupt */
2449 writel(0xffffffff, adapter
->tgt_status_reg
);
2451 napi_schedule(&sds_ring
->napi
);
2455 static irqreturn_t
qlcnic_msix_intr(int irq
, void *data
)
2457 struct qlcnic_host_sds_ring
*sds_ring
= data
;
2459 napi_schedule(&sds_ring
->napi
);
2463 static int qlcnic_process_cmd_ring(struct qlcnic_adapter
*adapter
)
2465 u32 sw_consumer
, hw_consumer
;
2467 struct qlcnic_cmd_buffer
*buffer
;
2468 struct pci_dev
*pdev
= adapter
->pdev
;
2469 struct net_device
*netdev
= adapter
->netdev
;
2470 struct qlcnic_skb_frag
*frag
;
2472 struct qlcnic_host_tx_ring
*tx_ring
= adapter
->tx_ring
;
2474 if (!spin_trylock(&adapter
->tx_clean_lock
))
2477 sw_consumer
= tx_ring
->sw_consumer
;
2478 hw_consumer
= le32_to_cpu(*(tx_ring
->hw_consumer
));
2480 while (sw_consumer
!= hw_consumer
) {
2481 buffer
= &tx_ring
->cmd_buf_arr
[sw_consumer
];
2483 frag
= &buffer
->frag_array
[0];
2484 pci_unmap_single(pdev
, frag
->dma
, frag
->length
,
2487 for (i
= 1; i
< buffer
->frag_count
; i
++) {
2489 pci_unmap_page(pdev
, frag
->dma
, frag
->length
,
2494 adapter
->stats
.xmitfinished
++;
2495 dev_kfree_skb_any(buffer
->skb
);
2499 sw_consumer
= get_next_index(sw_consumer
, tx_ring
->num_desc
);
2500 if (++count
>= MAX_STATUS_HANDLE
)
2504 if (count
&& netif_running(netdev
)) {
2505 tx_ring
->sw_consumer
= sw_consumer
;
2509 if (netif_queue_stopped(netdev
) && netif_carrier_ok(netdev
)) {
2510 if (qlcnic_tx_avail(tx_ring
) > TX_STOP_THRESH
) {
2511 netif_wake_queue(netdev
);
2512 adapter
->stats
.xmit_on
++;
2515 adapter
->tx_timeo_cnt
= 0;
2518 * If everything is freed up to consumer then check if the ring is full
2519 * If the ring is full then check if more needs to be freed and
2520 * schedule the call back again.
2522 * This happens when there are 2 CPUs. One could be freeing and the
2523 * other filling it. If the ring is full when we get out of here and
2524 * the card has already interrupted the host then the host can miss the
2527 * There is still a possible race condition and the host could miss an
2528 * interrupt. The card has to take care of this.
2530 hw_consumer
= le32_to_cpu(*(tx_ring
->hw_consumer
));
2531 done
= (sw_consumer
== hw_consumer
);
2532 spin_unlock(&adapter
->tx_clean_lock
);
2537 static int qlcnic_poll(struct napi_struct
*napi
, int budget
)
2539 struct qlcnic_host_sds_ring
*sds_ring
=
2540 container_of(napi
, struct qlcnic_host_sds_ring
, napi
);
2542 struct qlcnic_adapter
*adapter
= sds_ring
->adapter
;
2547 tx_complete
= qlcnic_process_cmd_ring(adapter
);
2549 work_done
= qlcnic_process_rcv_ring(sds_ring
, budget
);
2551 if ((work_done
< budget
) && tx_complete
) {
2552 napi_complete(&sds_ring
->napi
);
2553 if (test_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
2554 qlcnic_enable_int(sds_ring
);
2560 static int qlcnic_rx_poll(struct napi_struct
*napi
, int budget
)
2562 struct qlcnic_host_sds_ring
*sds_ring
=
2563 container_of(napi
, struct qlcnic_host_sds_ring
, napi
);
2565 struct qlcnic_adapter
*adapter
= sds_ring
->adapter
;
2568 work_done
= qlcnic_process_rcv_ring(sds_ring
, budget
);
2570 if (work_done
< budget
) {
2571 napi_complete(&sds_ring
->napi
);
2572 if (test_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
2573 qlcnic_enable_int(sds_ring
);
2579 #ifdef CONFIG_NET_POLL_CONTROLLER
2580 static void qlcnic_poll_controller(struct net_device
*netdev
)
2583 struct qlcnic_host_sds_ring
*sds_ring
;
2584 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
2585 struct qlcnic_recv_context
*recv_ctx
= adapter
->recv_ctx
;
2587 disable_irq(adapter
->irq
);
2588 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
2589 sds_ring
= &recv_ctx
->sds_rings
[ring
];
2590 qlcnic_intr(adapter
->irq
, sds_ring
);
2592 enable_irq(adapter
->irq
);
2597 qlcnic_idc_debug_info(struct qlcnic_adapter
*adapter
, u8 encoding
)
2601 val
= adapter
->portnum
& 0xf;
2602 val
|= encoding
<< 7;
2603 val
|= (jiffies
- adapter
->dev_rst_time
) << 8;
2605 QLCWR32(adapter
, QLCNIC_CRB_DRV_SCRATCH
, val
);
2606 adapter
->dev_rst_time
= jiffies
;
2610 qlcnic_set_drv_state(struct qlcnic_adapter
*adapter
, u8 state
)
2614 WARN_ON(state
!= QLCNIC_DEV_NEED_RESET
&&
2615 state
!= QLCNIC_DEV_NEED_QUISCENT
);
2617 if (qlcnic_api_lock(adapter
))
2620 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_STATE
);
2622 if (state
== QLCNIC_DEV_NEED_RESET
)
2623 QLC_DEV_SET_RST_RDY(val
, adapter
->portnum
);
2624 else if (state
== QLCNIC_DEV_NEED_QUISCENT
)
2625 QLC_DEV_SET_QSCNT_RDY(val
, adapter
->portnum
);
2627 QLCWR32(adapter
, QLCNIC_CRB_DRV_STATE
, val
);
2629 qlcnic_api_unlock(adapter
);
2635 qlcnic_clr_drv_state(struct qlcnic_adapter
*adapter
)
2639 if (qlcnic_api_lock(adapter
))
2642 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_STATE
);
2643 QLC_DEV_CLR_RST_QSCNT(val
, adapter
->portnum
);
2644 QLCWR32(adapter
, QLCNIC_CRB_DRV_STATE
, val
);
2646 qlcnic_api_unlock(adapter
);
2652 qlcnic_clr_all_drv_state(struct qlcnic_adapter
*adapter
, u8 failed
)
2656 if (qlcnic_api_lock(adapter
))
2659 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_ACTIVE
);
2660 QLC_DEV_CLR_REF_CNT(val
, adapter
->portnum
);
2661 QLCWR32(adapter
, QLCNIC_CRB_DRV_ACTIVE
, val
);
2664 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
, QLCNIC_DEV_FAILED
);
2665 dev_info(&adapter
->pdev
->dev
,
2666 "Device state set to Failed. Please Reboot\n");
2667 } else if (!(val
& 0x11111111))
2668 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
, QLCNIC_DEV_COLD
);
2670 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_STATE
);
2671 QLC_DEV_CLR_RST_QSCNT(val
, adapter
->portnum
);
2672 QLCWR32(adapter
, QLCNIC_CRB_DRV_STATE
, val
);
2674 qlcnic_api_unlock(adapter
);
2676 adapter
->fw_fail_cnt
= 0;
2677 clear_bit(__QLCNIC_START_FW
, &adapter
->state
);
2678 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
2681 /* Grab api lock, before checking state */
2683 qlcnic_check_drv_state(struct qlcnic_adapter
*adapter
)
2687 state
= QLCRD32(adapter
, QLCNIC_CRB_DRV_STATE
);
2688 act
= QLCRD32(adapter
, QLCNIC_CRB_DRV_ACTIVE
);
2690 if (((state
& 0x11111111) == (act
& 0x11111111)) ||
2691 ((act
& 0x11111111) == ((state
>> 1) & 0x11111111)))
2697 static int qlcnic_check_idc_ver(struct qlcnic_adapter
*adapter
)
2699 u32 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_IDC_VER
);
2701 if (val
!= QLCNIC_DRV_IDC_VER
) {
2702 dev_warn(&adapter
->pdev
->dev
, "IDC Version mismatch, driver's"
2703 " idc ver = %x; reqd = %x\n", QLCNIC_DRV_IDC_VER
, val
);
2710 qlcnic_can_start_firmware(struct qlcnic_adapter
*adapter
)
2712 u32 val
, prev_state
;
2713 u8 dev_init_timeo
= adapter
->dev_init_timeo
;
2714 u8 portnum
= adapter
->portnum
;
2717 if (test_and_clear_bit(__QLCNIC_START_FW
, &adapter
->state
))
2720 if (qlcnic_api_lock(adapter
))
2723 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_ACTIVE
);
2724 if (!(val
& (1 << (portnum
* 4)))) {
2725 QLC_DEV_SET_REF_CNT(val
, portnum
);
2726 QLCWR32(adapter
, QLCNIC_CRB_DRV_ACTIVE
, val
);
2729 prev_state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
);
2730 QLCDB(adapter
, HW
, "Device state = %u\n", prev_state
);
2732 switch (prev_state
) {
2733 case QLCNIC_DEV_COLD
:
2734 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
, QLCNIC_DEV_INITIALIZING
);
2735 QLCWR32(adapter
, QLCNIC_CRB_DRV_IDC_VER
, QLCNIC_DRV_IDC_VER
);
2736 qlcnic_idc_debug_info(adapter
, 0);
2737 qlcnic_api_unlock(adapter
);
2740 case QLCNIC_DEV_READY
:
2741 ret
= qlcnic_check_idc_ver(adapter
);
2742 qlcnic_api_unlock(adapter
);
2745 case QLCNIC_DEV_NEED_RESET
:
2746 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_STATE
);
2747 QLC_DEV_SET_RST_RDY(val
, portnum
);
2748 QLCWR32(adapter
, QLCNIC_CRB_DRV_STATE
, val
);
2751 case QLCNIC_DEV_NEED_QUISCENT
:
2752 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_STATE
);
2753 QLC_DEV_SET_QSCNT_RDY(val
, portnum
);
2754 QLCWR32(adapter
, QLCNIC_CRB_DRV_STATE
, val
);
2757 case QLCNIC_DEV_FAILED
:
2758 dev_err(&adapter
->pdev
->dev
, "Device in failed state.\n");
2759 qlcnic_api_unlock(adapter
);
2762 case QLCNIC_DEV_INITIALIZING
:
2763 case QLCNIC_DEV_QUISCENT
:
2767 qlcnic_api_unlock(adapter
);
2771 prev_state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
);
2773 if (prev_state
== QLCNIC_DEV_QUISCENT
)
2775 } while ((prev_state
!= QLCNIC_DEV_READY
) && --dev_init_timeo
);
2777 if (!dev_init_timeo
) {
2778 dev_err(&adapter
->pdev
->dev
,
2779 "Waiting for device to initialize timeout\n");
2783 if (qlcnic_api_lock(adapter
))
2786 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_STATE
);
2787 QLC_DEV_CLR_RST_QSCNT(val
, portnum
);
2788 QLCWR32(adapter
, QLCNIC_CRB_DRV_STATE
, val
);
2790 ret
= qlcnic_check_idc_ver(adapter
);
2791 qlcnic_api_unlock(adapter
);
2797 qlcnic_fwinit_work(struct work_struct
*work
)
2799 struct qlcnic_adapter
*adapter
= container_of(work
,
2800 struct qlcnic_adapter
, fw_work
.work
);
2801 u32 dev_state
= 0xf;
2803 if (qlcnic_api_lock(adapter
))
2806 dev_state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
);
2807 if (dev_state
== QLCNIC_DEV_QUISCENT
||
2808 dev_state
== QLCNIC_DEV_NEED_QUISCENT
) {
2809 qlcnic_api_unlock(adapter
);
2810 qlcnic_schedule_work(adapter
, qlcnic_fwinit_work
,
2815 if (adapter
->op_mode
== QLCNIC_NON_PRIV_FUNC
) {
2816 qlcnic_api_unlock(adapter
);
2820 if (adapter
->fw_wait_cnt
++ > adapter
->reset_ack_timeo
) {
2821 dev_err(&adapter
->pdev
->dev
, "Reset:Failed to get ack %d sec\n",
2822 adapter
->reset_ack_timeo
);
2823 goto skip_ack_check
;
2826 if (!qlcnic_check_drv_state(adapter
)) {
2828 dev_state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
);
2830 if (dev_state
== QLCNIC_DEV_NEED_RESET
) {
2831 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
,
2832 QLCNIC_DEV_INITIALIZING
);
2833 set_bit(__QLCNIC_START_FW
, &adapter
->state
);
2834 QLCDB(adapter
, DRV
, "Restarting fw\n");
2835 qlcnic_idc_debug_info(adapter
, 0);
2836 QLCDB(adapter
, DRV
, "Take FW dump\n");
2837 qlcnic_dump_fw(adapter
);
2840 qlcnic_api_unlock(adapter
);
2842 if (!adapter
->nic_ops
->start_firmware(adapter
)) {
2843 qlcnic_schedule_work(adapter
, qlcnic_attach_work
, 0);
2844 adapter
->fw_wait_cnt
= 0;
2850 qlcnic_api_unlock(adapter
);
2853 dev_state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
);
2854 QLCDB(adapter
, HW
, "Func waiting: Device state=%u\n", dev_state
);
2856 switch (dev_state
) {
2857 case QLCNIC_DEV_READY
:
2858 if (!adapter
->nic_ops
->start_firmware(adapter
)) {
2859 qlcnic_schedule_work(adapter
, qlcnic_attach_work
, 0);
2860 adapter
->fw_wait_cnt
= 0;
2863 case QLCNIC_DEV_FAILED
:
2866 qlcnic_schedule_work(adapter
,
2867 qlcnic_fwinit_work
, FW_POLL_DELAY
);
2872 dev_err(&adapter
->pdev
->dev
, "Fwinit work failed state=%u "
2873 "fw_wait_cnt=%u\n", dev_state
, adapter
->fw_wait_cnt
);
2874 netif_device_attach(adapter
->netdev
);
2875 qlcnic_clr_all_drv_state(adapter
, 0);
2879 qlcnic_detach_work(struct work_struct
*work
)
2881 struct qlcnic_adapter
*adapter
= container_of(work
,
2882 struct qlcnic_adapter
, fw_work
.work
);
2883 struct net_device
*netdev
= adapter
->netdev
;
2886 netif_device_detach(netdev
);
2888 /* Dont grab rtnl lock during Quiscent mode */
2889 if (adapter
->dev_state
== QLCNIC_DEV_NEED_QUISCENT
) {
2890 if (netif_running(netdev
))
2891 __qlcnic_down(adapter
, netdev
);
2893 qlcnic_down(adapter
, netdev
);
2895 status
= QLCRD32(adapter
, QLCNIC_PEG_HALT_STATUS1
);
2897 if (status
& QLCNIC_RCODE_FATAL_ERROR
)
2900 if (adapter
->temp
== QLCNIC_TEMP_PANIC
)
2903 if (qlcnic_set_drv_state(adapter
, adapter
->dev_state
))
2906 adapter
->fw_wait_cnt
= 0;
2908 qlcnic_schedule_work(adapter
, qlcnic_fwinit_work
, FW_POLL_DELAY
);
2913 dev_err(&adapter
->pdev
->dev
, "detach failed; status=%d temp=%d\n",
2914 status
, adapter
->temp
);
2915 netif_device_attach(netdev
);
2916 qlcnic_clr_all_drv_state(adapter
, 1);
2919 /*Transit NPAR state to NON Operational */
2921 qlcnic_set_npar_non_operational(struct qlcnic_adapter
*adapter
)
2925 state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_NPAR_STATE
);
2926 if (state
== QLCNIC_DEV_NPAR_NON_OPER
)
2929 if (qlcnic_api_lock(adapter
))
2931 QLCWR32(adapter
, QLCNIC_CRB_DEV_NPAR_STATE
, QLCNIC_DEV_NPAR_NON_OPER
);
2932 qlcnic_api_unlock(adapter
);
2935 /*Transit to RESET state from READY state only */
2937 qlcnic_dev_request_reset(struct qlcnic_adapter
*adapter
)
2941 adapter
->need_fw_reset
= 1;
2942 if (qlcnic_api_lock(adapter
))
2945 state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
);
2947 if (state
== QLCNIC_DEV_READY
) {
2948 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
, QLCNIC_DEV_NEED_RESET
);
2949 QLCDB(adapter
, DRV
, "NEED_RESET state set\n");
2950 qlcnic_idc_debug_info(adapter
, 0);
2953 QLCWR32(adapter
, QLCNIC_CRB_DEV_NPAR_STATE
, QLCNIC_DEV_NPAR_NON_OPER
);
2954 qlcnic_api_unlock(adapter
);
2957 /* Transit to NPAR READY state from NPAR NOT READY state */
2959 qlcnic_dev_set_npar_ready(struct qlcnic_adapter
*adapter
)
2961 if (qlcnic_api_lock(adapter
))
2964 QLCWR32(adapter
, QLCNIC_CRB_DEV_NPAR_STATE
, QLCNIC_DEV_NPAR_OPER
);
2965 QLCDB(adapter
, DRV
, "NPAR operational state set\n");
2967 qlcnic_api_unlock(adapter
);
2971 qlcnic_schedule_work(struct qlcnic_adapter
*adapter
,
2972 work_func_t func
, int delay
)
2974 if (test_bit(__QLCNIC_AER
, &adapter
->state
))
2977 INIT_DELAYED_WORK(&adapter
->fw_work
, func
);
2978 queue_delayed_work(qlcnic_wq
, &adapter
->fw_work
,
2979 round_jiffies_relative(delay
));
2983 qlcnic_cancel_fw_work(struct qlcnic_adapter
*adapter
)
2985 while (test_and_set_bit(__QLCNIC_RESETTING
, &adapter
->state
))
2988 cancel_delayed_work_sync(&adapter
->fw_work
);
2992 qlcnic_attach_work(struct work_struct
*work
)
2994 struct qlcnic_adapter
*adapter
= container_of(work
,
2995 struct qlcnic_adapter
, fw_work
.work
);
2996 struct net_device
*netdev
= adapter
->netdev
;
2999 if (adapter
->op_mode
!= QLCNIC_MGMT_FUNC
) {
3000 npar_state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_NPAR_STATE
);
3001 if (adapter
->fw_wait_cnt
++ > QLCNIC_DEV_NPAR_OPER_TIMEO
)
3002 qlcnic_clr_all_drv_state(adapter
, 0);
3003 else if (npar_state
!= QLCNIC_DEV_NPAR_OPER
)
3004 qlcnic_schedule_work(adapter
, qlcnic_attach_work
,
3008 QLCDB(adapter
, DRV
, "Waiting for NPAR state to operational\n");
3012 if (netif_running(netdev
)) {
3013 if (qlcnic_up(adapter
, netdev
))
3016 qlcnic_restore_indev_addr(netdev
, NETDEV_UP
);
3020 netif_device_attach(netdev
);
3021 adapter
->fw_fail_cnt
= 0;
3022 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
3024 if (!qlcnic_clr_drv_state(adapter
))
3025 qlcnic_schedule_work(adapter
, qlcnic_fw_poll_work
,
3030 qlcnic_check_health(struct qlcnic_adapter
*adapter
)
3032 u32 state
= 0, heartbeat
;
3033 struct net_device
*netdev
= adapter
->netdev
;
3035 if (qlcnic_check_temp(adapter
))
3038 if (adapter
->need_fw_reset
)
3039 qlcnic_dev_request_reset(adapter
);
3041 state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
);
3042 if (state
== QLCNIC_DEV_NEED_RESET
) {
3043 qlcnic_set_npar_non_operational(adapter
);
3044 adapter
->need_fw_reset
= 1;
3045 } else if (state
== QLCNIC_DEV_NEED_QUISCENT
)
3048 heartbeat
= QLCRD32(adapter
, QLCNIC_PEG_ALIVE_COUNTER
);
3049 if (heartbeat
!= adapter
->heartbeat
) {
3050 adapter
->heartbeat
= heartbeat
;
3051 adapter
->fw_fail_cnt
= 0;
3052 if (adapter
->need_fw_reset
)
3055 if (adapter
->reset_context
&& auto_fw_reset
) {
3056 qlcnic_reset_hw_context(adapter
);
3057 adapter
->netdev
->trans_start
= jiffies
;
3063 if (++adapter
->fw_fail_cnt
< FW_FAIL_THRESH
)
3066 qlcnic_dev_request_reset(adapter
);
3069 clear_bit(__QLCNIC_FW_ATTACHED
, &adapter
->state
);
3071 dev_info(&netdev
->dev
, "firmware hang detected\n");
3074 adapter
->dev_state
= (state
== QLCNIC_DEV_NEED_QUISCENT
) ? state
:
3075 QLCNIC_DEV_NEED_RESET
;
3077 if (auto_fw_reset
&&
3078 !test_and_set_bit(__QLCNIC_RESETTING
, &adapter
->state
)) {
3080 qlcnic_schedule_work(adapter
, qlcnic_detach_work
, 0);
3081 QLCDB(adapter
, DRV
, "fw recovery scheduled.\n");
3088 qlcnic_fw_poll_work(struct work_struct
*work
)
3090 struct qlcnic_adapter
*adapter
= container_of(work
,
3091 struct qlcnic_adapter
, fw_work
.work
);
3093 if (test_bit(__QLCNIC_RESETTING
, &adapter
->state
))
3097 if (qlcnic_check_health(adapter
))
3100 if (adapter
->fhash
.fnum
)
3101 qlcnic_prune_lb_filters(adapter
);
3104 qlcnic_schedule_work(adapter
, qlcnic_fw_poll_work
, FW_POLL_DELAY
);
3107 static int qlcnic_is_first_func(struct pci_dev
*pdev
)
3109 struct pci_dev
*oth_pdev
;
3110 int val
= pdev
->devfn
;
3113 oth_pdev
= pci_get_domain_bus_and_slot(pci_domain_nr
3114 (pdev
->bus
), pdev
->bus
->number
,
3115 PCI_DEVFN(PCI_SLOT(pdev
->devfn
), val
));
3119 if (oth_pdev
->current_state
!= PCI_D3cold
) {
3120 pci_dev_put(oth_pdev
);
3123 pci_dev_put(oth_pdev
);
3128 static int qlcnic_attach_func(struct pci_dev
*pdev
)
3130 int err
, first_func
;
3131 struct qlcnic_adapter
*adapter
= pci_get_drvdata(pdev
);
3132 struct net_device
*netdev
= adapter
->netdev
;
3134 pdev
->error_state
= pci_channel_io_normal
;
3136 err
= pci_enable_device(pdev
);
3140 pci_set_power_state(pdev
, PCI_D0
);
3141 pci_set_master(pdev
);
3142 pci_restore_state(pdev
);
3144 first_func
= qlcnic_is_first_func(pdev
);
3146 if (qlcnic_api_lock(adapter
))
3149 if (adapter
->op_mode
!= QLCNIC_NON_PRIV_FUNC
&& first_func
) {
3150 adapter
->need_fw_reset
= 1;
3151 set_bit(__QLCNIC_START_FW
, &adapter
->state
);
3152 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
, QLCNIC_DEV_INITIALIZING
);
3153 QLCDB(adapter
, DRV
, "Restarting fw\n");
3155 qlcnic_api_unlock(adapter
);
3157 err
= adapter
->nic_ops
->start_firmware(adapter
);
3161 qlcnic_clr_drv_state(adapter
);
3162 qlcnic_setup_intr(adapter
);
3164 if (netif_running(netdev
)) {
3165 err
= qlcnic_attach(adapter
);
3167 qlcnic_clr_all_drv_state(adapter
, 1);
3168 clear_bit(__QLCNIC_AER
, &adapter
->state
);
3169 netif_device_attach(netdev
);
3173 err
= qlcnic_up(adapter
, netdev
);
3177 qlcnic_restore_indev_addr(netdev
, NETDEV_UP
);
3180 netif_device_attach(netdev
);
3184 static pci_ers_result_t
qlcnic_io_error_detected(struct pci_dev
*pdev
,
3185 pci_channel_state_t state
)
3187 struct qlcnic_adapter
*adapter
= pci_get_drvdata(pdev
);
3188 struct net_device
*netdev
= adapter
->netdev
;
3190 if (state
== pci_channel_io_perm_failure
)
3191 return PCI_ERS_RESULT_DISCONNECT
;
3193 if (state
== pci_channel_io_normal
)
3194 return PCI_ERS_RESULT_RECOVERED
;
3196 set_bit(__QLCNIC_AER
, &adapter
->state
);
3197 netif_device_detach(netdev
);
3199 cancel_delayed_work_sync(&adapter
->fw_work
);
3201 if (netif_running(netdev
))
3202 qlcnic_down(adapter
, netdev
);
3204 qlcnic_detach(adapter
);
3205 qlcnic_teardown_intr(adapter
);
3207 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
3209 pci_save_state(pdev
);
3210 pci_disable_device(pdev
);
3212 return PCI_ERS_RESULT_NEED_RESET
;
3215 static pci_ers_result_t
qlcnic_io_slot_reset(struct pci_dev
*pdev
)
3217 return qlcnic_attach_func(pdev
) ? PCI_ERS_RESULT_DISCONNECT
:
3218 PCI_ERS_RESULT_RECOVERED
;
3221 static void qlcnic_io_resume(struct pci_dev
*pdev
)
3223 struct qlcnic_adapter
*adapter
= pci_get_drvdata(pdev
);
3225 pci_cleanup_aer_uncorrect_error_status(pdev
);
3227 if (QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
) == QLCNIC_DEV_READY
&&
3228 test_and_clear_bit(__QLCNIC_AER
, &adapter
->state
))
3229 qlcnic_schedule_work(adapter
, qlcnic_fw_poll_work
,
3234 qlcnicvf_start_firmware(struct qlcnic_adapter
*adapter
)
3238 err
= qlcnic_can_start_firmware(adapter
);
3242 err
= qlcnic_check_npar_opertional(adapter
);
3246 err
= qlcnic_initialize_nic(adapter
);
3250 qlcnic_check_options(adapter
);
3252 err
= qlcnic_set_eswitch_port_config(adapter
);
3256 adapter
->need_fw_reset
= 0;
3262 qlcnicvf_config_bridged_mode(struct qlcnic_adapter
*adapter
, u32 enable
)
3268 qlcnicvf_config_led(struct qlcnic_adapter
*adapter
, u32 state
, u32 rate
)
3274 qlcnic_store_bridged_mode(struct device
*dev
,
3275 struct device_attribute
*attr
, const char *buf
, size_t len
)
3277 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3281 if (!(adapter
->capabilities
& QLCNIC_FW_CAPABILITY_BDG
))
3284 if (!test_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
3287 if (strict_strtoul(buf
, 2, &new))
3290 if (!adapter
->nic_ops
->config_bridged_mode(adapter
, !!new))
3298 qlcnic_show_bridged_mode(struct device
*dev
,
3299 struct device_attribute
*attr
, char *buf
)
3301 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3302 int bridged_mode
= 0;
3304 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_BDG
)
3305 bridged_mode
= !!(adapter
->flags
& QLCNIC_BRIDGE_ENABLED
);
3307 return sprintf(buf
, "%d\n", bridged_mode
);
3310 static struct device_attribute dev_attr_bridged_mode
= {
3311 .attr
= {.name
= "bridged_mode", .mode
= (S_IRUGO
| S_IWUSR
)},
3312 .show
= qlcnic_show_bridged_mode
,
3313 .store
= qlcnic_store_bridged_mode
,
3317 qlcnic_store_diag_mode(struct device
*dev
,
3318 struct device_attribute
*attr
, const char *buf
, size_t len
)
3320 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3323 if (strict_strtoul(buf
, 2, &new))
3326 if (!!new != !!(adapter
->flags
& QLCNIC_DIAG_ENABLED
))
3327 adapter
->flags
^= QLCNIC_DIAG_ENABLED
;
3333 qlcnic_show_diag_mode(struct device
*dev
,
3334 struct device_attribute
*attr
, char *buf
)
3336 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3338 return sprintf(buf
, "%d\n",
3339 !!(adapter
->flags
& QLCNIC_DIAG_ENABLED
));
3342 static struct device_attribute dev_attr_diag_mode
= {
3343 .attr
= {.name
= "diag_mode", .mode
= (S_IRUGO
| S_IWUSR
)},
3344 .show
= qlcnic_show_diag_mode
,
3345 .store
= qlcnic_store_diag_mode
,
3348 int qlcnic_validate_max_rss(struct net_device
*netdev
, u8 max_hw
, u8 val
)
3350 if (!use_msi_x
&& !use_msi
) {
3351 netdev_info(netdev
, "no msix or msi support, hence no rss\n");
3355 if ((val
> max_hw
) || (val
< 2) || !is_power_of_2(val
)) {
3356 netdev_info(netdev
, "rss_ring valid range [2 - %x] in "
3357 " powers of 2\n", max_hw
);
3364 int qlcnic_set_max_rss(struct qlcnic_adapter
*adapter
, u8 data
)
3366 struct net_device
*netdev
= adapter
->netdev
;
3369 if (test_and_set_bit(__QLCNIC_RESETTING
, &adapter
->state
))
3372 netif_device_detach(netdev
);
3373 if (netif_running(netdev
))
3374 __qlcnic_down(adapter
, netdev
);
3375 qlcnic_detach(adapter
);
3376 qlcnic_teardown_intr(adapter
);
3378 if (qlcnic_enable_msix(adapter
, data
)) {
3379 netdev_info(netdev
, "failed setting max_rss; rss disabled\n");
3380 qlcnic_enable_msi_legacy(adapter
);
3383 if (netif_running(netdev
)) {
3384 err
= qlcnic_attach(adapter
);
3387 err
= __qlcnic_up(adapter
, netdev
);
3390 qlcnic_restore_indev_addr(netdev
, NETDEV_UP
);
3393 netif_device_attach(netdev
);
3394 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
3399 qlcnic_sysfs_validate_crb(struct qlcnic_adapter
*adapter
,
3400 loff_t offset
, size_t size
)
3402 size_t crb_size
= 4;
3404 if (!(adapter
->flags
& QLCNIC_DIAG_ENABLED
))
3407 if (offset
< QLCNIC_PCI_CRBSPACE
) {
3408 if (ADDR_IN_RANGE(offset
, QLCNIC_PCI_CAMQM
,
3409 QLCNIC_PCI_CAMQM_END
))
3415 if ((size
!= crb_size
) || (offset
& (crb_size
-1)))
3422 qlcnic_sysfs_read_crb(struct file
*filp
, struct kobject
*kobj
,
3423 struct bin_attribute
*attr
,
3424 char *buf
, loff_t offset
, size_t size
)
3426 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3427 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3432 ret
= qlcnic_sysfs_validate_crb(adapter
, offset
, size
);
3436 if (ADDR_IN_RANGE(offset
, QLCNIC_PCI_CAMQM
, QLCNIC_PCI_CAMQM_END
)) {
3437 qlcnic_pci_camqm_read_2M(adapter
, offset
, &qmdata
);
3438 memcpy(buf
, &qmdata
, size
);
3440 data
= QLCRD32(adapter
, offset
);
3441 memcpy(buf
, &data
, size
);
3447 qlcnic_sysfs_write_crb(struct file
*filp
, struct kobject
*kobj
,
3448 struct bin_attribute
*attr
,
3449 char *buf
, loff_t offset
, size_t size
)
3451 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3452 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3457 ret
= qlcnic_sysfs_validate_crb(adapter
, offset
, size
);
3461 if (ADDR_IN_RANGE(offset
, QLCNIC_PCI_CAMQM
, QLCNIC_PCI_CAMQM_END
)) {
3462 memcpy(&qmdata
, buf
, size
);
3463 qlcnic_pci_camqm_write_2M(adapter
, offset
, qmdata
);
3465 memcpy(&data
, buf
, size
);
3466 QLCWR32(adapter
, offset
, data
);
3472 qlcnic_sysfs_validate_mem(struct qlcnic_adapter
*adapter
,
3473 loff_t offset
, size_t size
)
3475 if (!(adapter
->flags
& QLCNIC_DIAG_ENABLED
))
3478 if ((size
!= 8) || (offset
& 0x7))
3485 qlcnic_sysfs_read_mem(struct file
*filp
, struct kobject
*kobj
,
3486 struct bin_attribute
*attr
,
3487 char *buf
, loff_t offset
, size_t size
)
3489 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3490 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3494 ret
= qlcnic_sysfs_validate_mem(adapter
, offset
, size
);
3498 if (qlcnic_pci_mem_read_2M(adapter
, offset
, &data
))
3501 memcpy(buf
, &data
, size
);
3507 qlcnic_sysfs_write_mem(struct file
*filp
, struct kobject
*kobj
,
3508 struct bin_attribute
*attr
,
3509 char *buf
, loff_t offset
, size_t size
)
3511 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3512 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3516 ret
= qlcnic_sysfs_validate_mem(adapter
, offset
, size
);
3520 memcpy(&data
, buf
, size
);
3522 if (qlcnic_pci_mem_write_2M(adapter
, offset
, data
))
3528 static struct bin_attribute bin_attr_crb
= {
3529 .attr
= {.name
= "crb", .mode
= (S_IRUGO
| S_IWUSR
)},
3531 .read
= qlcnic_sysfs_read_crb
,
3532 .write
= qlcnic_sysfs_write_crb
,
3535 static struct bin_attribute bin_attr_mem
= {
3536 .attr
= {.name
= "mem", .mode
= (S_IRUGO
| S_IWUSR
)},
3538 .read
= qlcnic_sysfs_read_mem
,
3539 .write
= qlcnic_sysfs_write_mem
,
3543 validate_pm_config(struct qlcnic_adapter
*adapter
,
3544 struct qlcnic_pm_func_cfg
*pm_cfg
, int count
)
3547 u8 src_pci_func
, s_esw_id
, d_esw_id
;
3551 for (i
= 0; i
< count
; i
++) {
3552 src_pci_func
= pm_cfg
[i
].pci_func
;
3553 dest_pci_func
= pm_cfg
[i
].dest_npar
;
3554 if (src_pci_func
>= QLCNIC_MAX_PCI_FUNC
3555 || dest_pci_func
>= QLCNIC_MAX_PCI_FUNC
)
3556 return QL_STATUS_INVALID_PARAM
;
3558 if (adapter
->npars
[src_pci_func
].type
!= QLCNIC_TYPE_NIC
)
3559 return QL_STATUS_INVALID_PARAM
;
3561 if (adapter
->npars
[dest_pci_func
].type
!= QLCNIC_TYPE_NIC
)
3562 return QL_STATUS_INVALID_PARAM
;
3564 s_esw_id
= adapter
->npars
[src_pci_func
].phy_port
;
3565 d_esw_id
= adapter
->npars
[dest_pci_func
].phy_port
;
3567 if (s_esw_id
!= d_esw_id
)
3568 return QL_STATUS_INVALID_PARAM
;
3576 qlcnic_sysfs_write_pm_config(struct file
*filp
, struct kobject
*kobj
,
3577 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3579 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3580 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3581 struct qlcnic_pm_func_cfg
*pm_cfg
;
3582 u32 id
, action
, pci_func
;
3583 int count
, rem
, i
, ret
;
3585 count
= size
/ sizeof(struct qlcnic_pm_func_cfg
);
3586 rem
= size
% sizeof(struct qlcnic_pm_func_cfg
);
3588 return QL_STATUS_INVALID_PARAM
;
3590 pm_cfg
= (struct qlcnic_pm_func_cfg
*) buf
;
3592 ret
= validate_pm_config(adapter
, pm_cfg
, count
);
3595 for (i
= 0; i
< count
; i
++) {
3596 pci_func
= pm_cfg
[i
].pci_func
;
3597 action
= !!pm_cfg
[i
].action
;
3598 id
= adapter
->npars
[pci_func
].phy_port
;
3599 ret
= qlcnic_config_port_mirroring(adapter
, id
,
3605 for (i
= 0; i
< count
; i
++) {
3606 pci_func
= pm_cfg
[i
].pci_func
;
3607 id
= adapter
->npars
[pci_func
].phy_port
;
3608 adapter
->npars
[pci_func
].enable_pm
= !!pm_cfg
[i
].action
;
3609 adapter
->npars
[pci_func
].dest_npar
= id
;
3615 qlcnic_sysfs_read_pm_config(struct file
*filp
, struct kobject
*kobj
,
3616 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3618 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3619 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3620 struct qlcnic_pm_func_cfg pm_cfg
[QLCNIC_MAX_PCI_FUNC
];
3623 if (size
!= sizeof(pm_cfg
))
3624 return QL_STATUS_INVALID_PARAM
;
3626 for (i
= 0; i
< QLCNIC_MAX_PCI_FUNC
; i
++) {
3627 if (adapter
->npars
[i
].type
!= QLCNIC_TYPE_NIC
)
3629 pm_cfg
[i
].action
= adapter
->npars
[i
].enable_pm
;
3630 pm_cfg
[i
].dest_npar
= 0;
3631 pm_cfg
[i
].pci_func
= i
;
3633 memcpy(buf
, &pm_cfg
, size
);
3639 validate_esw_config(struct qlcnic_adapter
*adapter
,
3640 struct qlcnic_esw_func_cfg
*esw_cfg
, int count
)
3646 op_mode
= readl(adapter
->ahw
->pci_base0
+ QLCNIC_DRV_OP_MODE
);
3648 for (i
= 0; i
< count
; i
++) {
3649 pci_func
= esw_cfg
[i
].pci_func
;
3650 if (pci_func
>= QLCNIC_MAX_PCI_FUNC
)
3651 return QL_STATUS_INVALID_PARAM
;
3653 if (adapter
->op_mode
== QLCNIC_MGMT_FUNC
)
3654 if (adapter
->npars
[pci_func
].type
!= QLCNIC_TYPE_NIC
)
3655 return QL_STATUS_INVALID_PARAM
;
3657 switch (esw_cfg
[i
].op_mode
) {
3658 case QLCNIC_PORT_DEFAULTS
:
3659 if (QLC_DEV_GET_DRV(op_mode
, pci_func
) !=
3660 QLCNIC_NON_PRIV_FUNC
) {
3661 if (esw_cfg
[i
].mac_anti_spoof
!= 0)
3662 return QL_STATUS_INVALID_PARAM
;
3663 if (esw_cfg
[i
].mac_override
!= 1)
3664 return QL_STATUS_INVALID_PARAM
;
3665 if (esw_cfg
[i
].promisc_mode
!= 1)
3666 return QL_STATUS_INVALID_PARAM
;
3669 case QLCNIC_ADD_VLAN
:
3670 if (!IS_VALID_VLAN(esw_cfg
[i
].vlan_id
))
3671 return QL_STATUS_INVALID_PARAM
;
3672 if (!esw_cfg
[i
].op_type
)
3673 return QL_STATUS_INVALID_PARAM
;
3675 case QLCNIC_DEL_VLAN
:
3676 if (!esw_cfg
[i
].op_type
)
3677 return QL_STATUS_INVALID_PARAM
;
3680 return QL_STATUS_INVALID_PARAM
;
3687 qlcnic_sysfs_write_esw_config(struct file
*file
, struct kobject
*kobj
,
3688 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3690 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3691 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3692 struct qlcnic_esw_func_cfg
*esw_cfg
;
3693 struct qlcnic_npar_info
*npar
;
3694 int count
, rem
, i
, ret
;
3695 u8 pci_func
, op_mode
= 0;
3697 count
= size
/ sizeof(struct qlcnic_esw_func_cfg
);
3698 rem
= size
% sizeof(struct qlcnic_esw_func_cfg
);
3700 return QL_STATUS_INVALID_PARAM
;
3702 esw_cfg
= (struct qlcnic_esw_func_cfg
*) buf
;
3703 ret
= validate_esw_config(adapter
, esw_cfg
, count
);
3707 for (i
= 0; i
< count
; i
++) {
3708 if (adapter
->op_mode
== QLCNIC_MGMT_FUNC
)
3709 if (qlcnic_config_switch_port(adapter
, &esw_cfg
[i
]))
3710 return QL_STATUS_INVALID_PARAM
;
3712 if (adapter
->ahw
->pci_func
!= esw_cfg
[i
].pci_func
)
3715 op_mode
= esw_cfg
[i
].op_mode
;
3716 qlcnic_get_eswitch_port_config(adapter
, &esw_cfg
[i
]);
3717 esw_cfg
[i
].op_mode
= op_mode
;
3718 esw_cfg
[i
].pci_func
= adapter
->ahw
->pci_func
;
3720 switch (esw_cfg
[i
].op_mode
) {
3721 case QLCNIC_PORT_DEFAULTS
:
3722 qlcnic_set_eswitch_port_features(adapter
, &esw_cfg
[i
]);
3724 case QLCNIC_ADD_VLAN
:
3725 qlcnic_set_vlan_config(adapter
, &esw_cfg
[i
]);
3727 case QLCNIC_DEL_VLAN
:
3728 esw_cfg
[i
].vlan_id
= 0;
3729 qlcnic_set_vlan_config(adapter
, &esw_cfg
[i
]);
3734 if (adapter
->op_mode
!= QLCNIC_MGMT_FUNC
)
3737 for (i
= 0; i
< count
; i
++) {
3738 pci_func
= esw_cfg
[i
].pci_func
;
3739 npar
= &adapter
->npars
[pci_func
];
3740 switch (esw_cfg
[i
].op_mode
) {
3741 case QLCNIC_PORT_DEFAULTS
:
3742 npar
->promisc_mode
= esw_cfg
[i
].promisc_mode
;
3743 npar
->mac_override
= esw_cfg
[i
].mac_override
;
3744 npar
->offload_flags
= esw_cfg
[i
].offload_flags
;
3745 npar
->mac_anti_spoof
= esw_cfg
[i
].mac_anti_spoof
;
3746 npar
->discard_tagged
= esw_cfg
[i
].discard_tagged
;
3748 case QLCNIC_ADD_VLAN
:
3749 npar
->pvid
= esw_cfg
[i
].vlan_id
;
3751 case QLCNIC_DEL_VLAN
:
3761 qlcnic_sysfs_read_esw_config(struct file
*file
, struct kobject
*kobj
,
3762 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3764 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3765 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3766 struct qlcnic_esw_func_cfg esw_cfg
[QLCNIC_MAX_PCI_FUNC
];
3769 if (size
!= sizeof(esw_cfg
))
3770 return QL_STATUS_INVALID_PARAM
;
3772 for (i
= 0; i
< QLCNIC_MAX_PCI_FUNC
; i
++) {
3773 if (adapter
->npars
[i
].type
!= QLCNIC_TYPE_NIC
)
3775 esw_cfg
[i
].pci_func
= i
;
3776 if (qlcnic_get_eswitch_port_config(adapter
, &esw_cfg
[i
]))
3777 return QL_STATUS_INVALID_PARAM
;
3779 memcpy(buf
, &esw_cfg
, size
);
3785 validate_npar_config(struct qlcnic_adapter
*adapter
,
3786 struct qlcnic_npar_func_cfg
*np_cfg
, int count
)
3790 for (i
= 0; i
< count
; i
++) {
3791 pci_func
= np_cfg
[i
].pci_func
;
3792 if (pci_func
>= QLCNIC_MAX_PCI_FUNC
)
3793 return QL_STATUS_INVALID_PARAM
;
3795 if (adapter
->npars
[pci_func
].type
!= QLCNIC_TYPE_NIC
)
3796 return QL_STATUS_INVALID_PARAM
;
3798 if (!IS_VALID_BW(np_cfg
[i
].min_bw
) ||
3799 !IS_VALID_BW(np_cfg
[i
].max_bw
))
3800 return QL_STATUS_INVALID_PARAM
;
3806 qlcnic_sysfs_write_npar_config(struct file
*file
, struct kobject
*kobj
,
3807 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3809 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3810 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3811 struct qlcnic_info nic_info
;
3812 struct qlcnic_npar_func_cfg
*np_cfg
;
3813 int i
, count
, rem
, ret
;
3816 count
= size
/ sizeof(struct qlcnic_npar_func_cfg
);
3817 rem
= size
% sizeof(struct qlcnic_npar_func_cfg
);
3819 return QL_STATUS_INVALID_PARAM
;
3821 np_cfg
= (struct qlcnic_npar_func_cfg
*) buf
;
3822 ret
= validate_npar_config(adapter
, np_cfg
, count
);
3826 for (i
= 0; i
< count
; i
++) {
3827 pci_func
= np_cfg
[i
].pci_func
;
3828 ret
= qlcnic_get_nic_info(adapter
, &nic_info
, pci_func
);
3831 nic_info
.pci_func
= pci_func
;
3832 nic_info
.min_tx_bw
= np_cfg
[i
].min_bw
;
3833 nic_info
.max_tx_bw
= np_cfg
[i
].max_bw
;
3834 ret
= qlcnic_set_nic_info(adapter
, &nic_info
);
3837 adapter
->npars
[i
].min_bw
= nic_info
.min_tx_bw
;
3838 adapter
->npars
[i
].max_bw
= nic_info
.max_tx_bw
;
3845 qlcnic_sysfs_read_npar_config(struct file
*file
, struct kobject
*kobj
,
3846 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3848 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3849 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3850 struct qlcnic_info nic_info
;
3851 struct qlcnic_npar_func_cfg np_cfg
[QLCNIC_MAX_PCI_FUNC
];
3854 if (size
!= sizeof(np_cfg
))
3855 return QL_STATUS_INVALID_PARAM
;
3857 for (i
= 0; i
< QLCNIC_MAX_PCI_FUNC
; i
++) {
3858 if (adapter
->npars
[i
].type
!= QLCNIC_TYPE_NIC
)
3860 ret
= qlcnic_get_nic_info(adapter
, &nic_info
, i
);
3864 np_cfg
[i
].pci_func
= i
;
3865 np_cfg
[i
].op_mode
= (u8
)nic_info
.op_mode
;
3866 np_cfg
[i
].port_num
= nic_info
.phys_port
;
3867 np_cfg
[i
].fw_capab
= nic_info
.capabilities
;
3868 np_cfg
[i
].min_bw
= nic_info
.min_tx_bw
;
3869 np_cfg
[i
].max_bw
= nic_info
.max_tx_bw
;
3870 np_cfg
[i
].max_tx_queues
= nic_info
.max_tx_ques
;
3871 np_cfg
[i
].max_rx_queues
= nic_info
.max_rx_ques
;
3873 memcpy(buf
, &np_cfg
, size
);
3878 qlcnic_sysfs_get_port_stats(struct file
*file
, struct kobject
*kobj
,
3879 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3881 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3882 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3883 struct qlcnic_esw_statistics port_stats
;
3886 if (size
!= sizeof(struct qlcnic_esw_statistics
))
3887 return QL_STATUS_INVALID_PARAM
;
3889 if (offset
>= QLCNIC_MAX_PCI_FUNC
)
3890 return QL_STATUS_INVALID_PARAM
;
3892 memset(&port_stats
, 0, size
);
3893 ret
= qlcnic_get_port_stats(adapter
, offset
, QLCNIC_QUERY_RX_COUNTER
,
3898 ret
= qlcnic_get_port_stats(adapter
, offset
, QLCNIC_QUERY_TX_COUNTER
,
3903 memcpy(buf
, &port_stats
, size
);
3908 qlcnic_sysfs_get_esw_stats(struct file
*file
, struct kobject
*kobj
,
3909 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3911 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3912 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3913 struct qlcnic_esw_statistics esw_stats
;
3916 if (size
!= sizeof(struct qlcnic_esw_statistics
))
3917 return QL_STATUS_INVALID_PARAM
;
3919 if (offset
>= QLCNIC_NIU_MAX_XG_PORTS
)
3920 return QL_STATUS_INVALID_PARAM
;
3922 memset(&esw_stats
, 0, size
);
3923 ret
= qlcnic_get_eswitch_stats(adapter
, offset
, QLCNIC_QUERY_RX_COUNTER
,
3928 ret
= qlcnic_get_eswitch_stats(adapter
, offset
, QLCNIC_QUERY_TX_COUNTER
,
3933 memcpy(buf
, &esw_stats
, size
);
3938 qlcnic_sysfs_clear_esw_stats(struct file
*file
, struct kobject
*kobj
,
3939 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3941 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3942 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3945 if (offset
>= QLCNIC_NIU_MAX_XG_PORTS
)
3946 return QL_STATUS_INVALID_PARAM
;
3948 ret
= qlcnic_clear_esw_stats(adapter
, QLCNIC_STATS_ESWITCH
, offset
,
3949 QLCNIC_QUERY_RX_COUNTER
);
3953 ret
= qlcnic_clear_esw_stats(adapter
, QLCNIC_STATS_ESWITCH
, offset
,
3954 QLCNIC_QUERY_TX_COUNTER
);
3962 qlcnic_sysfs_clear_port_stats(struct file
*file
, struct kobject
*kobj
,
3963 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3966 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3967 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3970 if (offset
>= QLCNIC_MAX_PCI_FUNC
)
3971 return QL_STATUS_INVALID_PARAM
;
3973 ret
= qlcnic_clear_esw_stats(adapter
, QLCNIC_STATS_PORT
, offset
,
3974 QLCNIC_QUERY_RX_COUNTER
);
3978 ret
= qlcnic_clear_esw_stats(adapter
, QLCNIC_STATS_PORT
, offset
,
3979 QLCNIC_QUERY_TX_COUNTER
);
3987 qlcnic_sysfs_read_pci_config(struct file
*file
, struct kobject
*kobj
,
3988 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3990 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3991 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3992 struct qlcnic_pci_func_cfg pci_cfg
[QLCNIC_MAX_PCI_FUNC
];
3993 struct qlcnic_pci_info
*pci_info
;
3996 if (size
!= sizeof(pci_cfg
))
3997 return QL_STATUS_INVALID_PARAM
;
3999 pci_info
= kcalloc(QLCNIC_MAX_PCI_FUNC
, sizeof(*pci_info
), GFP_KERNEL
);
4003 ret
= qlcnic_get_pci_info(adapter
, pci_info
);
4009 for (i
= 0; i
< QLCNIC_MAX_PCI_FUNC
; i
++) {
4010 pci_cfg
[i
].pci_func
= pci_info
[i
].id
;
4011 pci_cfg
[i
].func_type
= pci_info
[i
].type
;
4012 pci_cfg
[i
].port_num
= pci_info
[i
].default_port
;
4013 pci_cfg
[i
].min_bw
= pci_info
[i
].tx_min_bw
;
4014 pci_cfg
[i
].max_bw
= pci_info
[i
].tx_max_bw
;
4015 memcpy(&pci_cfg
[i
].def_mac_addr
, &pci_info
[i
].mac
, ETH_ALEN
);
4017 memcpy(buf
, &pci_cfg
, size
);
4021 static struct bin_attribute bin_attr_npar_config
= {
4022 .attr
= {.name
= "npar_config", .mode
= (S_IRUGO
| S_IWUSR
)},
4024 .read
= qlcnic_sysfs_read_npar_config
,
4025 .write
= qlcnic_sysfs_write_npar_config
,
4028 static struct bin_attribute bin_attr_pci_config
= {
4029 .attr
= {.name
= "pci_config", .mode
= (S_IRUGO
| S_IWUSR
)},
4031 .read
= qlcnic_sysfs_read_pci_config
,
4035 static struct bin_attribute bin_attr_port_stats
= {
4036 .attr
= {.name
= "port_stats", .mode
= (S_IRUGO
| S_IWUSR
)},
4038 .read
= qlcnic_sysfs_get_port_stats
,
4039 .write
= qlcnic_sysfs_clear_port_stats
,
4042 static struct bin_attribute bin_attr_esw_stats
= {
4043 .attr
= {.name
= "esw_stats", .mode
= (S_IRUGO
| S_IWUSR
)},
4045 .read
= qlcnic_sysfs_get_esw_stats
,
4046 .write
= qlcnic_sysfs_clear_esw_stats
,
4049 static struct bin_attribute bin_attr_esw_config
= {
4050 .attr
= {.name
= "esw_config", .mode
= (S_IRUGO
| S_IWUSR
)},
4052 .read
= qlcnic_sysfs_read_esw_config
,
4053 .write
= qlcnic_sysfs_write_esw_config
,
4056 static struct bin_attribute bin_attr_pm_config
= {
4057 .attr
= {.name
= "pm_config", .mode
= (S_IRUGO
| S_IWUSR
)},
4059 .read
= qlcnic_sysfs_read_pm_config
,
4060 .write
= qlcnic_sysfs_write_pm_config
,
4064 qlcnic_create_sysfs_entries(struct qlcnic_adapter
*adapter
)
4066 struct device
*dev
= &adapter
->pdev
->dev
;
4068 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_BDG
)
4069 if (device_create_file(dev
, &dev_attr_bridged_mode
))
4071 "failed to create bridged_mode sysfs entry\n");
4075 qlcnic_remove_sysfs_entries(struct qlcnic_adapter
*adapter
)
4077 struct device
*dev
= &adapter
->pdev
->dev
;
4079 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_BDG
)
4080 device_remove_file(dev
, &dev_attr_bridged_mode
);
4084 qlcnic_create_diag_entries(struct qlcnic_adapter
*adapter
)
4086 struct device
*dev
= &adapter
->pdev
->dev
;
4088 if (device_create_bin_file(dev
, &bin_attr_port_stats
))
4089 dev_info(dev
, "failed to create port stats sysfs entry");
4091 if (adapter
->op_mode
== QLCNIC_NON_PRIV_FUNC
)
4093 if (device_create_file(dev
, &dev_attr_diag_mode
))
4094 dev_info(dev
, "failed to create diag_mode sysfs entry\n");
4095 if (device_create_bin_file(dev
, &bin_attr_crb
))
4096 dev_info(dev
, "failed to create crb sysfs entry\n");
4097 if (device_create_bin_file(dev
, &bin_attr_mem
))
4098 dev_info(dev
, "failed to create mem sysfs entry\n");
4099 if (device_create_bin_file(dev
, &bin_attr_pci_config
))
4100 dev_info(dev
, "failed to create pci config sysfs entry");
4101 if (!(adapter
->flags
& QLCNIC_ESWITCH_ENABLED
))
4103 if (device_create_bin_file(dev
, &bin_attr_esw_config
))
4104 dev_info(dev
, "failed to create esw config sysfs entry");
4105 if (adapter
->op_mode
!= QLCNIC_MGMT_FUNC
)
4107 if (device_create_bin_file(dev
, &bin_attr_npar_config
))
4108 dev_info(dev
, "failed to create npar config sysfs entry");
4109 if (device_create_bin_file(dev
, &bin_attr_pm_config
))
4110 dev_info(dev
, "failed to create pm config sysfs entry");
4111 if (device_create_bin_file(dev
, &bin_attr_esw_stats
))
4112 dev_info(dev
, "failed to create eswitch stats sysfs entry");
4116 qlcnic_remove_diag_entries(struct qlcnic_adapter
*adapter
)
4118 struct device
*dev
= &adapter
->pdev
->dev
;
4120 device_remove_bin_file(dev
, &bin_attr_port_stats
);
4122 if (adapter
->op_mode
== QLCNIC_NON_PRIV_FUNC
)
4124 device_remove_file(dev
, &dev_attr_diag_mode
);
4125 device_remove_bin_file(dev
, &bin_attr_crb
);
4126 device_remove_bin_file(dev
, &bin_attr_mem
);
4127 device_remove_bin_file(dev
, &bin_attr_pci_config
);
4128 if (!(adapter
->flags
& QLCNIC_ESWITCH_ENABLED
))
4130 device_remove_bin_file(dev
, &bin_attr_esw_config
);
4131 if (adapter
->op_mode
!= QLCNIC_MGMT_FUNC
)
4133 device_remove_bin_file(dev
, &bin_attr_npar_config
);
4134 device_remove_bin_file(dev
, &bin_attr_pm_config
);
4135 device_remove_bin_file(dev
, &bin_attr_esw_stats
);
4140 #define is_qlcnic_netdev(dev) (dev->netdev_ops == &qlcnic_netdev_ops)
4143 qlcnic_config_indev_addr(struct qlcnic_adapter
*adapter
,
4144 struct net_device
*dev
, unsigned long event
)
4146 struct in_device
*indev
;
4148 indev
= in_dev_get(dev
);
4155 qlcnic_config_ipaddr(adapter
,
4156 ifa
->ifa_address
, QLCNIC_IP_UP
);
4159 qlcnic_config_ipaddr(adapter
,
4160 ifa
->ifa_address
, QLCNIC_IP_DOWN
);
4165 } endfor_ifa(indev
);
4171 qlcnic_restore_indev_addr(struct net_device
*netdev
, unsigned long event
)
4173 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
4174 struct net_device
*dev
;
4177 qlcnic_config_indev_addr(adapter
, netdev
, event
);
4179 for_each_set_bit(vid
, adapter
->vlans
, VLAN_N_VID
) {
4180 dev
= vlan_find_dev(netdev
, vid
);
4183 qlcnic_config_indev_addr(adapter
, dev
, event
);
4187 static int qlcnic_netdev_event(struct notifier_block
*this,
4188 unsigned long event
, void *ptr
)
4190 struct qlcnic_adapter
*adapter
;
4191 struct net_device
*dev
= (struct net_device
*)ptr
;
4197 if (dev
->priv_flags
& IFF_802_1Q_VLAN
) {
4198 dev
= vlan_dev_real_dev(dev
);
4202 if (!is_qlcnic_netdev(dev
))
4205 adapter
= netdev_priv(dev
);
4210 if (!test_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
4213 qlcnic_config_indev_addr(adapter
, dev
, event
);
4219 qlcnic_inetaddr_event(struct notifier_block
*this,
4220 unsigned long event
, void *ptr
)
4222 struct qlcnic_adapter
*adapter
;
4223 struct net_device
*dev
;
4225 struct in_ifaddr
*ifa
= (struct in_ifaddr
*)ptr
;
4227 dev
= ifa
->ifa_dev
? ifa
->ifa_dev
->dev
: NULL
;
4233 if (dev
->priv_flags
& IFF_802_1Q_VLAN
) {
4234 dev
= vlan_dev_real_dev(dev
);
4238 if (!is_qlcnic_netdev(dev
))
4241 adapter
= netdev_priv(dev
);
4246 if (!test_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
4251 qlcnic_config_ipaddr(adapter
, ifa
->ifa_address
, QLCNIC_IP_UP
);
4254 qlcnic_config_ipaddr(adapter
, ifa
->ifa_address
, QLCNIC_IP_DOWN
);
4264 static struct notifier_block qlcnic_netdev_cb
= {
4265 .notifier_call
= qlcnic_netdev_event
,
4268 static struct notifier_block qlcnic_inetaddr_cb
= {
4269 .notifier_call
= qlcnic_inetaddr_event
,
4273 qlcnic_restore_indev_addr(struct net_device
*dev
, unsigned long event
)
4276 static struct pci_error_handlers qlcnic_err_handler
= {
4277 .error_detected
= qlcnic_io_error_detected
,
4278 .slot_reset
= qlcnic_io_slot_reset
,
4279 .resume
= qlcnic_io_resume
,
4282 static struct pci_driver qlcnic_driver
= {
4283 .name
= qlcnic_driver_name
,
4284 .id_table
= qlcnic_pci_tbl
,
4285 .probe
= qlcnic_probe
,
4286 .remove
= __devexit_p(qlcnic_remove
),
4288 .suspend
= qlcnic_suspend
,
4289 .resume
= qlcnic_resume
,
4291 .shutdown
= qlcnic_shutdown
,
4292 .err_handler
= &qlcnic_err_handler
4296 static int __init
qlcnic_init_module(void)
4300 printk(KERN_INFO
"%s\n", qlcnic_driver_string
);
4302 qlcnic_wq
= create_singlethread_workqueue("qlcnic");
4303 if (qlcnic_wq
== NULL
) {
4304 printk(KERN_ERR
"qlcnic: cannot create workqueue\n");
4309 register_netdevice_notifier(&qlcnic_netdev_cb
);
4310 register_inetaddr_notifier(&qlcnic_inetaddr_cb
);
4313 ret
= pci_register_driver(&qlcnic_driver
);
4316 unregister_inetaddr_notifier(&qlcnic_inetaddr_cb
);
4317 unregister_netdevice_notifier(&qlcnic_netdev_cb
);
4319 destroy_workqueue(qlcnic_wq
);
4325 module_init(qlcnic_init_module
);
4327 static void __exit
qlcnic_exit_module(void)
4330 pci_unregister_driver(&qlcnic_driver
);
4333 unregister_inetaddr_notifier(&qlcnic_inetaddr_cb
);
4334 unregister_netdevice_notifier(&qlcnic_netdev_cb
);
4336 destroy_workqueue(qlcnic_wq
);
4339 module_exit(qlcnic_exit_module
);