2 * Copyright (C) 2009 - QLogic Corporation.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20 * The full GNU General Public License is included in this distribution
21 * in the file called "COPYING".
25 #include <linux/slab.h>
26 #include <linux/vmalloc.h>
27 #include <linux/interrupt.h>
31 #include <linux/dma-mapping.h>
32 #include <linux/if_vlan.h>
34 #include <linux/ipv6.h>
35 #include <linux/inetdevice.h>
36 #include <linux/sysfs.h>
37 #include <linux/aer.h>
39 MODULE_DESCRIPTION("QLogic 1/10 GbE Converged/Intelligent Ethernet Driver");
40 MODULE_LICENSE("GPL");
41 MODULE_VERSION(QLCNIC_LINUX_VERSIONID
);
42 MODULE_FIRMWARE(QLCNIC_UNIFIED_ROMIMAGE_NAME
);
44 char qlcnic_driver_name
[] = "qlcnic";
45 static const char qlcnic_driver_string
[] = "QLogic 1/10 GbE "
46 "Converged/Intelligent Ethernet Driver v" QLCNIC_LINUX_VERSIONID
;
48 static int port_mode
= QLCNIC_PORT_MODE_AUTO_NEG
;
50 /* Default to restricted 1G auto-neg mode */
51 static int wol_port_mode
= 5;
53 static int use_msi
= 1;
54 module_param(use_msi
, int, 0644);
55 MODULE_PARM_DESC(use_msi
, "MSI interrupt (0=disabled, 1=enabled");
57 static int use_msi_x
= 1;
58 module_param(use_msi_x
, int, 0644);
59 MODULE_PARM_DESC(use_msi_x
, "MSI-X interrupt (0=disabled, 1=enabled");
61 static int auto_fw_reset
= AUTO_FW_RESET_ENABLED
;
62 module_param(auto_fw_reset
, int, 0644);
63 MODULE_PARM_DESC(auto_fw_reset
, "Auto firmware reset (0=disabled, 1=enabled");
65 static int load_fw_file
;
66 module_param(load_fw_file
, int, 0644);
67 MODULE_PARM_DESC(load_fw_file
, "Load firmware from (0=flash, 1=file");
69 static int qlcnic_config_npars
;
70 module_param(qlcnic_config_npars
, int, 0644);
71 MODULE_PARM_DESC(qlcnic_config_npars
, "Configure NPARs (0=disabled, 1=enabled");
73 static int __devinit
qlcnic_probe(struct pci_dev
*pdev
,
74 const struct pci_device_id
*ent
);
75 static void __devexit
qlcnic_remove(struct pci_dev
*pdev
);
76 static int qlcnic_open(struct net_device
*netdev
);
77 static int qlcnic_close(struct net_device
*netdev
);
78 static void qlcnic_tx_timeout(struct net_device
*netdev
);
79 static void qlcnic_attach_work(struct work_struct
*work
);
80 static void qlcnic_fwinit_work(struct work_struct
*work
);
81 static void qlcnic_fw_poll_work(struct work_struct
*work
);
82 static void qlcnic_schedule_work(struct qlcnic_adapter
*adapter
,
83 work_func_t func
, int delay
);
84 static void qlcnic_cancel_fw_work(struct qlcnic_adapter
*adapter
);
85 static int qlcnic_poll(struct napi_struct
*napi
, int budget
);
86 static int qlcnic_rx_poll(struct napi_struct
*napi
, int budget
);
87 #ifdef CONFIG_NET_POLL_CONTROLLER
88 static void qlcnic_poll_controller(struct net_device
*netdev
);
91 static void qlcnic_create_sysfs_entries(struct qlcnic_adapter
*adapter
);
92 static void qlcnic_remove_sysfs_entries(struct qlcnic_adapter
*adapter
);
93 static void qlcnic_create_diag_entries(struct qlcnic_adapter
*adapter
);
94 static void qlcnic_remove_diag_entries(struct qlcnic_adapter
*adapter
);
96 static void qlcnic_idc_debug_info(struct qlcnic_adapter
*adapter
, u8 encoding
);
97 static void qlcnic_clr_all_drv_state(struct qlcnic_adapter
*adapter
);
98 static int qlcnic_can_start_firmware(struct qlcnic_adapter
*adapter
);
100 static irqreturn_t
qlcnic_tmp_intr(int irq
, void *data
);
101 static irqreturn_t
qlcnic_intr(int irq
, void *data
);
102 static irqreturn_t
qlcnic_msi_intr(int irq
, void *data
);
103 static irqreturn_t
qlcnic_msix_intr(int irq
, void *data
);
105 static struct net_device_stats
*qlcnic_get_stats(struct net_device
*netdev
);
106 static void qlcnic_config_indev_addr(struct net_device
*dev
, unsigned long);
107 static int qlcnic_start_firmware(struct qlcnic_adapter
*);
109 static void qlcnic_dev_set_npar_ready(struct qlcnic_adapter
*);
110 static int qlcnicvf_config_led(struct qlcnic_adapter
*, u32
, u32
);
111 static int qlcnicvf_config_bridged_mode(struct qlcnic_adapter
*, u32
);
112 static int qlcnicvf_start_firmware(struct qlcnic_adapter
*);
113 /* PCI Device ID Table */
114 #define ENTRY(device) \
115 {PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, (device)), \
116 .class = PCI_CLASS_NETWORK_ETHERNET << 8, .class_mask = ~0}
118 #define PCI_DEVICE_ID_QLOGIC_QLE824X 0x8020
120 static DEFINE_PCI_DEVICE_TABLE(qlcnic_pci_tbl
) = {
121 ENTRY(PCI_DEVICE_ID_QLOGIC_QLE824X
),
125 MODULE_DEVICE_TABLE(pci
, qlcnic_pci_tbl
);
129 qlcnic_update_cmd_producer(struct qlcnic_adapter
*adapter
,
130 struct qlcnic_host_tx_ring
*tx_ring
)
132 writel(tx_ring
->producer
, tx_ring
->crb_cmd_producer
);
135 static const u32 msi_tgt_status
[8] = {
136 ISR_INT_TARGET_STATUS
, ISR_INT_TARGET_STATUS_F1
,
137 ISR_INT_TARGET_STATUS_F2
, ISR_INT_TARGET_STATUS_F3
,
138 ISR_INT_TARGET_STATUS_F4
, ISR_INT_TARGET_STATUS_F5
,
139 ISR_INT_TARGET_STATUS_F6
, ISR_INT_TARGET_STATUS_F7
143 struct qlcnic_legacy_intr_set legacy_intr
[] = QLCNIC_LEGACY_INTR_CONFIG
;
145 static inline void qlcnic_disable_int(struct qlcnic_host_sds_ring
*sds_ring
)
147 writel(0, sds_ring
->crb_intr_mask
);
150 static inline void qlcnic_enable_int(struct qlcnic_host_sds_ring
*sds_ring
)
152 struct qlcnic_adapter
*adapter
= sds_ring
->adapter
;
154 writel(0x1, sds_ring
->crb_intr_mask
);
156 if (!QLCNIC_IS_MSI_FAMILY(adapter
))
157 writel(0xfbff, adapter
->tgt_mask_reg
);
161 qlcnic_alloc_sds_rings(struct qlcnic_recv_context
*recv_ctx
, int count
)
163 int size
= sizeof(struct qlcnic_host_sds_ring
) * count
;
165 recv_ctx
->sds_rings
= kzalloc(size
, GFP_KERNEL
);
167 return (recv_ctx
->sds_rings
== NULL
);
171 qlcnic_free_sds_rings(struct qlcnic_recv_context
*recv_ctx
)
173 if (recv_ctx
->sds_rings
!= NULL
)
174 kfree(recv_ctx
->sds_rings
);
176 recv_ctx
->sds_rings
= NULL
;
180 qlcnic_napi_add(struct qlcnic_adapter
*adapter
, struct net_device
*netdev
)
183 struct qlcnic_host_sds_ring
*sds_ring
;
184 struct qlcnic_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
186 if (qlcnic_alloc_sds_rings(recv_ctx
, adapter
->max_sds_rings
))
189 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
190 sds_ring
= &recv_ctx
->sds_rings
[ring
];
192 if (ring
== adapter
->max_sds_rings
- 1)
193 netif_napi_add(netdev
, &sds_ring
->napi
, qlcnic_poll
,
194 QLCNIC_NETDEV_WEIGHT
/adapter
->max_sds_rings
);
196 netif_napi_add(netdev
, &sds_ring
->napi
,
197 qlcnic_rx_poll
, QLCNIC_NETDEV_WEIGHT
*2);
204 qlcnic_napi_del(struct qlcnic_adapter
*adapter
)
207 struct qlcnic_host_sds_ring
*sds_ring
;
208 struct qlcnic_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
210 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
211 sds_ring
= &recv_ctx
->sds_rings
[ring
];
212 netif_napi_del(&sds_ring
->napi
);
215 qlcnic_free_sds_rings(&adapter
->recv_ctx
);
219 qlcnic_napi_enable(struct qlcnic_adapter
*adapter
)
222 struct qlcnic_host_sds_ring
*sds_ring
;
223 struct qlcnic_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
225 if (adapter
->is_up
!= QLCNIC_ADAPTER_UP_MAGIC
)
228 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
229 sds_ring
= &recv_ctx
->sds_rings
[ring
];
230 napi_enable(&sds_ring
->napi
);
231 qlcnic_enable_int(sds_ring
);
236 qlcnic_napi_disable(struct qlcnic_adapter
*adapter
)
239 struct qlcnic_host_sds_ring
*sds_ring
;
240 struct qlcnic_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
242 if (adapter
->is_up
!= QLCNIC_ADAPTER_UP_MAGIC
)
245 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
246 sds_ring
= &recv_ctx
->sds_rings
[ring
];
247 qlcnic_disable_int(sds_ring
);
248 napi_synchronize(&sds_ring
->napi
);
249 napi_disable(&sds_ring
->napi
);
253 static void qlcnic_clear_stats(struct qlcnic_adapter
*adapter
)
255 memset(&adapter
->stats
, 0, sizeof(adapter
->stats
));
258 static void qlcnic_set_port_mode(struct qlcnic_adapter
*adapter
)
262 val
= adapter
->ahw
.board_type
;
263 if ((val
== QLCNIC_BRDTYPE_P3_HMEZ
) ||
264 (val
== QLCNIC_BRDTYPE_P3_XG_LOM
)) {
265 if (port_mode
== QLCNIC_PORT_MODE_802_3_AP
) {
266 data
= QLCNIC_PORT_MODE_802_3_AP
;
267 QLCWR32(adapter
, QLCNIC_PORT_MODE_ADDR
, data
);
268 } else if (port_mode
== QLCNIC_PORT_MODE_XG
) {
269 data
= QLCNIC_PORT_MODE_XG
;
270 QLCWR32(adapter
, QLCNIC_PORT_MODE_ADDR
, data
);
271 } else if (port_mode
== QLCNIC_PORT_MODE_AUTO_NEG_1G
) {
272 data
= QLCNIC_PORT_MODE_AUTO_NEG_1G
;
273 QLCWR32(adapter
, QLCNIC_PORT_MODE_ADDR
, data
);
274 } else if (port_mode
== QLCNIC_PORT_MODE_AUTO_NEG_XG
) {
275 data
= QLCNIC_PORT_MODE_AUTO_NEG_XG
;
276 QLCWR32(adapter
, QLCNIC_PORT_MODE_ADDR
, data
);
278 data
= QLCNIC_PORT_MODE_AUTO_NEG
;
279 QLCWR32(adapter
, QLCNIC_PORT_MODE_ADDR
, data
);
282 if ((wol_port_mode
!= QLCNIC_PORT_MODE_802_3_AP
) &&
283 (wol_port_mode
!= QLCNIC_PORT_MODE_XG
) &&
284 (wol_port_mode
!= QLCNIC_PORT_MODE_AUTO_NEG_1G
) &&
285 (wol_port_mode
!= QLCNIC_PORT_MODE_AUTO_NEG_XG
)) {
286 wol_port_mode
= QLCNIC_PORT_MODE_AUTO_NEG
;
288 QLCWR32(adapter
, QLCNIC_WOL_PORT_MODE
, wol_port_mode
);
292 static void qlcnic_set_msix_bit(struct pci_dev
*pdev
, int enable
)
297 pos
= pci_find_capability(pdev
, PCI_CAP_ID_MSIX
);
299 pci_read_config_dword(pdev
, pos
, &control
);
301 control
|= PCI_MSIX_FLAGS_ENABLE
;
304 pci_write_config_dword(pdev
, pos
, control
);
308 static void qlcnic_init_msix_entries(struct qlcnic_adapter
*adapter
, int count
)
312 for (i
= 0; i
< count
; i
++)
313 adapter
->msix_entries
[i
].entry
= i
;
317 qlcnic_read_mac_addr(struct qlcnic_adapter
*adapter
)
319 u8 mac_addr
[ETH_ALEN
];
320 struct net_device
*netdev
= adapter
->netdev
;
321 struct pci_dev
*pdev
= adapter
->pdev
;
323 if (adapter
->nic_ops
->get_mac_addr(adapter
, mac_addr
) != 0)
326 memcpy(netdev
->dev_addr
, mac_addr
, ETH_ALEN
);
327 memcpy(netdev
->perm_addr
, netdev
->dev_addr
, netdev
->addr_len
);
328 memcpy(adapter
->mac_addr
, netdev
->dev_addr
, netdev
->addr_len
);
330 /* set station address */
332 if (!is_valid_ether_addr(netdev
->perm_addr
))
333 dev_warn(&pdev
->dev
, "Bad MAC address %pM.\n",
339 static int qlcnic_set_mac(struct net_device
*netdev
, void *p
)
341 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
342 struct sockaddr
*addr
= p
;
344 if (!is_valid_ether_addr(addr
->sa_data
))
347 if (test_bit(__QLCNIC_DEV_UP
, &adapter
->state
)) {
348 netif_device_detach(netdev
);
349 qlcnic_napi_disable(adapter
);
352 memcpy(adapter
->mac_addr
, addr
->sa_data
, netdev
->addr_len
);
353 memcpy(netdev
->dev_addr
, addr
->sa_data
, netdev
->addr_len
);
354 qlcnic_set_multi(adapter
->netdev
);
356 if (test_bit(__QLCNIC_DEV_UP
, &adapter
->state
)) {
357 netif_device_attach(netdev
);
358 qlcnic_napi_enable(adapter
);
363 static const struct net_device_ops qlcnic_netdev_ops
= {
364 .ndo_open
= qlcnic_open
,
365 .ndo_stop
= qlcnic_close
,
366 .ndo_start_xmit
= qlcnic_xmit_frame
,
367 .ndo_get_stats
= qlcnic_get_stats
,
368 .ndo_validate_addr
= eth_validate_addr
,
369 .ndo_set_multicast_list
= qlcnic_set_multi
,
370 .ndo_set_mac_address
= qlcnic_set_mac
,
371 .ndo_change_mtu
= qlcnic_change_mtu
,
372 .ndo_tx_timeout
= qlcnic_tx_timeout
,
373 #ifdef CONFIG_NET_POLL_CONTROLLER
374 .ndo_poll_controller
= qlcnic_poll_controller
,
378 static struct qlcnic_nic_template qlcnic_ops
= {
379 .get_mac_addr
= qlcnic_get_mac_address
,
380 .config_bridged_mode
= qlcnic_config_bridged_mode
,
381 .config_led
= qlcnic_config_led
,
382 .start_firmware
= qlcnic_start_firmware
385 static struct qlcnic_nic_template qlcnic_vf_ops
= {
386 .get_mac_addr
= qlcnic_get_mac_address
,
387 .config_bridged_mode
= qlcnicvf_config_bridged_mode
,
388 .config_led
= qlcnicvf_config_led
,
389 .start_firmware
= qlcnicvf_start_firmware
393 qlcnic_setup_intr(struct qlcnic_adapter
*adapter
)
395 const struct qlcnic_legacy_intr_set
*legacy_intrp
;
396 struct pci_dev
*pdev
= adapter
->pdev
;
399 if (adapter
->rss_supported
) {
400 num_msix
= (num_online_cpus() >= MSIX_ENTRIES_PER_ADAPTER
) ?
401 MSIX_ENTRIES_PER_ADAPTER
: 2;
405 adapter
->max_sds_rings
= 1;
407 adapter
->flags
&= ~(QLCNIC_MSI_ENABLED
| QLCNIC_MSIX_ENABLED
);
409 legacy_intrp
= &legacy_intr
[adapter
->ahw
.pci_func
];
411 adapter
->int_vec_bit
= legacy_intrp
->int_vec_bit
;
412 adapter
->tgt_status_reg
= qlcnic_get_ioaddr(adapter
,
413 legacy_intrp
->tgt_status_reg
);
414 adapter
->tgt_mask_reg
= qlcnic_get_ioaddr(adapter
,
415 legacy_intrp
->tgt_mask_reg
);
416 adapter
->isr_int_vec
= qlcnic_get_ioaddr(adapter
, ISR_INT_VECTOR
);
418 adapter
->crb_int_state_reg
= qlcnic_get_ioaddr(adapter
,
421 qlcnic_set_msix_bit(pdev
, 0);
423 if (adapter
->msix_supported
) {
425 qlcnic_init_msix_entries(adapter
, num_msix
);
426 err
= pci_enable_msix(pdev
, adapter
->msix_entries
, num_msix
);
428 adapter
->flags
|= QLCNIC_MSIX_ENABLED
;
429 qlcnic_set_msix_bit(pdev
, 1);
431 if (adapter
->rss_supported
)
432 adapter
->max_sds_rings
= num_msix
;
434 dev_info(&pdev
->dev
, "using msi-x interrupts\n");
439 pci_disable_msix(pdev
);
441 /* fall through for msi */
444 if (use_msi
&& !pci_enable_msi(pdev
)) {
445 adapter
->flags
|= QLCNIC_MSI_ENABLED
;
446 adapter
->tgt_status_reg
= qlcnic_get_ioaddr(adapter
,
447 msi_tgt_status
[adapter
->ahw
.pci_func
]);
448 dev_info(&pdev
->dev
, "using msi interrupts\n");
449 adapter
->msix_entries
[0].vector
= pdev
->irq
;
453 dev_info(&pdev
->dev
, "using legacy interrupts\n");
454 adapter
->msix_entries
[0].vector
= pdev
->irq
;
458 qlcnic_teardown_intr(struct qlcnic_adapter
*adapter
)
460 if (adapter
->flags
& QLCNIC_MSIX_ENABLED
)
461 pci_disable_msix(adapter
->pdev
);
462 if (adapter
->flags
& QLCNIC_MSI_ENABLED
)
463 pci_disable_msi(adapter
->pdev
);
467 qlcnic_cleanup_pci_map(struct qlcnic_adapter
*adapter
)
469 if (adapter
->ahw
.pci_base0
!= NULL
)
470 iounmap(adapter
->ahw
.pci_base0
);
474 qlcnic_init_pci_info(struct qlcnic_adapter
*adapter
)
476 struct qlcnic_pci_info
*pci_info
;
480 pci_info
= kcalloc(QLCNIC_MAX_PCI_FUNC
, sizeof(*pci_info
), GFP_KERNEL
);
484 adapter
->npars
= kzalloc(sizeof(struct qlcnic_npar_info
) *
485 QLCNIC_MAX_PCI_FUNC
, GFP_KERNEL
);
486 if (!adapter
->npars
) {
491 adapter
->eswitch
= kzalloc(sizeof(struct qlcnic_eswitch
) *
492 QLCNIC_NIU_MAX_XG_PORTS
, GFP_KERNEL
);
493 if (!adapter
->eswitch
) {
498 ret
= qlcnic_get_pci_info(adapter
, pci_info
);
502 for (i
= 0; i
< QLCNIC_MAX_PCI_FUNC
; i
++) {
503 pfn
= pci_info
[i
].id
;
504 if (pfn
> QLCNIC_MAX_PCI_FUNC
)
505 return QL_STATUS_INVALID_PARAM
;
506 adapter
->npars
[pfn
].active
= pci_info
[i
].active
;
507 adapter
->npars
[pfn
].type
= pci_info
[i
].type
;
508 adapter
->npars
[pfn
].phy_port
= pci_info
[i
].default_port
;
509 adapter
->npars
[pfn
].mac_learning
= DEFAULT_MAC_LEARN
;
510 adapter
->npars
[pfn
].min_bw
= pci_info
[i
].tx_min_bw
;
511 adapter
->npars
[pfn
].max_bw
= pci_info
[i
].tx_max_bw
;
514 for (i
= 0; i
< QLCNIC_NIU_MAX_XG_PORTS
; i
++)
515 adapter
->eswitch
[i
].flags
|= QLCNIC_SWITCH_ENABLE
;
521 kfree(adapter
->eswitch
);
522 adapter
->eswitch
= NULL
;
524 kfree(adapter
->npars
);
525 adapter
->npars
= NULL
;
533 qlcnic_set_function_modes(struct qlcnic_adapter
*adapter
)
538 u32 data
= QLCNIC_MGMT_FUNC
;
539 void __iomem
*priv_op
= adapter
->ahw
.pci_base0
+ QLCNIC_DRV_OP_MODE
;
541 /* If other drivers are not in use set their privilege level */
542 ref_count
= QLCRD32(adapter
, QLCNIC_CRB_DEV_REF_COUNT
);
543 ret
= qlcnic_api_lock(adapter
);
546 if (QLC_DEV_CLR_REF_CNT(ref_count
, adapter
->ahw
.pci_func
))
549 if (qlcnic_config_npars
) {
550 for (i
= 0; i
< QLCNIC_MAX_PCI_FUNC
; i
++) {
552 if (adapter
->npars
[i
].type
!= QLCNIC_TYPE_NIC
||
553 id
== adapter
->ahw
.pci_func
)
555 data
|= (qlcnic_config_npars
&
556 QLC_DEV_SET_DRV(0xf, id
));
559 data
= readl(priv_op
);
560 data
= (data
& ~QLC_DEV_SET_DRV(0xf, adapter
->ahw
.pci_func
)) |
561 (QLC_DEV_SET_DRV(QLCNIC_MGMT_FUNC
,
562 adapter
->ahw
.pci_func
));
564 writel(data
, priv_op
);
566 qlcnic_api_unlock(adapter
);
572 qlcnic_get_driver_mode(struct qlcnic_adapter
*adapter
)
574 void __iomem
*msix_base_addr
;
575 void __iomem
*priv_op
;
576 struct qlcnic_info nic_info
;
579 u32 op_mode
, priv_level
;
581 /* Determine FW API version */
582 adapter
->fw_hal_version
= readl(adapter
->ahw
.pci_base0
+ QLCNIC_FW_API
);
584 /* Find PCI function number */
585 pci_read_config_dword(adapter
->pdev
, QLCNIC_MSIX_TABLE_OFFSET
, &func
);
586 msix_base_addr
= adapter
->ahw
.pci_base0
+ QLCNIC_MSIX_BASE
;
587 msix_base
= readl(msix_base_addr
);
588 func
= (func
- msix_base
)/QLCNIC_MSIX_TBL_PGSIZE
;
589 adapter
->ahw
.pci_func
= func
;
591 if (!qlcnic_get_nic_info(adapter
, &nic_info
, adapter
->ahw
.pci_func
)) {
592 adapter
->capabilities
= nic_info
.capabilities
;
594 if (adapter
->capabilities
& BIT_6
)
595 adapter
->flags
|= QLCNIC_ESWITCH_ENABLED
;
597 adapter
->flags
&= ~QLCNIC_ESWITCH_ENABLED
;
600 if (!(adapter
->flags
& QLCNIC_ESWITCH_ENABLED
)) {
601 adapter
->nic_ops
= &qlcnic_ops
;
602 return adapter
->fw_hal_version
;
605 /* Determine function privilege level */
606 priv_op
= adapter
->ahw
.pci_base0
+ QLCNIC_DRV_OP_MODE
;
607 op_mode
= readl(priv_op
);
608 if (op_mode
== QLC_DEV_DRV_DEFAULT
)
609 priv_level
= QLCNIC_MGMT_FUNC
;
611 priv_level
= QLC_DEV_GET_DRV(op_mode
, adapter
->ahw
.pci_func
);
613 switch (priv_level
) {
614 case QLCNIC_MGMT_FUNC
:
615 adapter
->op_mode
= QLCNIC_MGMT_FUNC
;
616 adapter
->nic_ops
= &qlcnic_ops
;
617 qlcnic_init_pci_info(adapter
);
618 /* Set privilege level for other functions */
619 qlcnic_set_function_modes(adapter
);
620 dev_info(&adapter
->pdev
->dev
,
621 "HAL Version: %d, Management function\n",
622 adapter
->fw_hal_version
);
624 case QLCNIC_PRIV_FUNC
:
625 adapter
->op_mode
= QLCNIC_PRIV_FUNC
;
626 dev_info(&adapter
->pdev
->dev
,
627 "HAL Version: %d, Privileged function\n",
628 adapter
->fw_hal_version
);
629 adapter
->nic_ops
= &qlcnic_ops
;
631 case QLCNIC_NON_PRIV_FUNC
:
632 adapter
->op_mode
= QLCNIC_NON_PRIV_FUNC
;
633 dev_info(&adapter
->pdev
->dev
,
634 "HAL Version: %d Non Privileged function\n",
635 adapter
->fw_hal_version
);
636 adapter
->nic_ops
= &qlcnic_vf_ops
;
639 dev_info(&adapter
->pdev
->dev
, "Unknown function mode: %d\n",
643 return adapter
->fw_hal_version
;
647 qlcnic_setup_pci_map(struct qlcnic_adapter
*adapter
)
649 void __iomem
*mem_ptr0
= NULL
;
650 resource_size_t mem_base
;
651 unsigned long mem_len
, pci_len0
= 0;
653 struct pci_dev
*pdev
= adapter
->pdev
;
655 /* remap phys address */
656 mem_base
= pci_resource_start(pdev
, 0); /* 0 is for BAR 0 */
657 mem_len
= pci_resource_len(pdev
, 0);
659 if (mem_len
== QLCNIC_PCI_2MB_SIZE
) {
661 mem_ptr0
= pci_ioremap_bar(pdev
, 0);
662 if (mem_ptr0
== NULL
) {
663 dev_err(&pdev
->dev
, "failed to map PCI bar 0\n");
671 dev_info(&pdev
->dev
, "%dMB memory map\n", (int)(mem_len
>>20));
673 adapter
->ahw
.pci_base0
= mem_ptr0
;
674 adapter
->ahw
.pci_len0
= pci_len0
;
676 if (!qlcnic_get_driver_mode(adapter
)) {
677 iounmap(adapter
->ahw
.pci_base0
);
681 adapter
->ahw
.ocm_win_crb
= qlcnic_get_ioaddr(adapter
,
682 QLCNIC_PCIX_PS_REG(PCIX_OCM_WINDOW_REG(adapter
->ahw
.pci_func
)));
687 static void get_brd_name(struct qlcnic_adapter
*adapter
, char *name
)
689 struct pci_dev
*pdev
= adapter
->pdev
;
692 for (i
= 0; i
< NUM_SUPPORTED_BOARDS
; ++i
) {
693 if (qlcnic_boards
[i
].vendor
== pdev
->vendor
&&
694 qlcnic_boards
[i
].device
== pdev
->device
&&
695 qlcnic_boards
[i
].sub_vendor
== pdev
->subsystem_vendor
&&
696 qlcnic_boards
[i
].sub_device
== pdev
->subsystem_device
) {
697 sprintf(name
, "%pM: %s" ,
699 qlcnic_boards
[i
].short_name
);
707 sprintf(name
, "%pM Gigabit Ethernet", adapter
->mac_addr
);
711 qlcnic_check_options(struct qlcnic_adapter
*adapter
)
713 u32 fw_major
, fw_minor
, fw_build
;
714 char brd_name
[QLCNIC_MAX_BOARD_NAME_LEN
];
718 struct pci_dev
*pdev
= adapter
->pdev
;
719 struct qlcnic_info nic_info
;
720 adapter
->driver_mismatch
= 0;
722 ptr32
= (int *)&serial_num
;
723 offset
= QLCNIC_FW_SERIAL_NUM_OFFSET
;
724 for (i
= 0; i
< 8; i
++) {
725 if (qlcnic_rom_fast_read(adapter
, offset
, &val
) == -1) {
726 dev_err(&pdev
->dev
, "error reading board info\n");
727 adapter
->driver_mismatch
= 1;
730 ptr32
[i
] = cpu_to_le32(val
);
731 offset
+= sizeof(u32
);
734 fw_major
= QLCRD32(adapter
, QLCNIC_FW_VERSION_MAJOR
);
735 fw_minor
= QLCRD32(adapter
, QLCNIC_FW_VERSION_MINOR
);
736 fw_build
= QLCRD32(adapter
, QLCNIC_FW_VERSION_SUB
);
738 adapter
->fw_version
= QLCNIC_VERSION_CODE(fw_major
, fw_minor
, fw_build
);
740 if (adapter
->portnum
== 0) {
741 get_brd_name(adapter
, brd_name
);
743 pr_info("%s: %s Board Chip rev 0x%x\n",
744 module_name(THIS_MODULE
),
745 brd_name
, adapter
->ahw
.revision_id
);
748 dev_info(&pdev
->dev
, "firmware v%d.%d.%d\n",
749 fw_major
, fw_minor
, fw_build
);
751 adapter
->flags
&= ~QLCNIC_LRO_ENABLED
;
753 if (adapter
->ahw
.port_type
== QLCNIC_XGBE
) {
754 adapter
->num_rxd
= DEFAULT_RCV_DESCRIPTORS_10G
;
755 adapter
->num_jumbo_rxd
= MAX_JUMBO_RCV_DESCRIPTORS_10G
;
756 } else if (adapter
->ahw
.port_type
== QLCNIC_GBE
) {
757 adapter
->num_rxd
= DEFAULT_RCV_DESCRIPTORS_1G
;
758 adapter
->num_jumbo_rxd
= MAX_JUMBO_RCV_DESCRIPTORS_1G
;
761 if (!qlcnic_get_nic_info(adapter
, &nic_info
, adapter
->ahw
.pci_func
)) {
762 adapter
->physical_port
= nic_info
.phys_port
;
763 adapter
->switch_mode
= nic_info
.switch_mode
;
764 adapter
->max_tx_ques
= nic_info
.max_tx_ques
;
765 adapter
->max_rx_ques
= nic_info
.max_rx_ques
;
766 adapter
->capabilities
= nic_info
.capabilities
;
767 adapter
->max_mac_filters
= nic_info
.max_mac_filters
;
768 adapter
->max_mtu
= nic_info
.max_mtu
;
771 adapter
->msix_supported
= !!use_msi_x
;
772 adapter
->rss_supported
= !!use_msi_x
;
774 adapter
->num_txd
= MAX_CMD_DESCRIPTORS
;
776 adapter
->max_rds_rings
= 2;
780 qlcnic_reset_npar_config(struct qlcnic_adapter
*adapter
)
783 struct qlcnic_npar_info
*npar
;
784 struct qlcnic_info nic_info
;
786 if (!(adapter
->flags
& QLCNIC_ESWITCH_ENABLED
) ||
787 !adapter
->need_fw_reset
)
790 if (adapter
->op_mode
== QLCNIC_MGMT_FUNC
) {
791 /* Set the NPAR config data after FW reset */
792 for (i
= 0; i
< QLCNIC_MAX_PCI_FUNC
; i
++) {
793 npar
= &adapter
->npars
[i
];
794 if (npar
->type
!= QLCNIC_TYPE_NIC
)
796 err
= qlcnic_get_nic_info(adapter
, &nic_info
, i
);
799 nic_info
.min_tx_bw
= npar
->min_bw
;
800 nic_info
.max_tx_bw
= npar
->max_bw
;
801 err
= qlcnic_set_nic_info(adapter
, &nic_info
);
805 if (npar
->enable_pm
) {
806 err
= qlcnic_config_port_mirroring(adapter
,
807 npar
->dest_npar
, 1, i
);
812 npar
->mac_learning
= DEFAULT_MAC_LEARN
;
813 npar
->host_vlan_tag
= 0;
814 npar
->promisc_mode
= 0;
815 npar
->discard_tagged
= 0;
824 qlcnic_start_firmware(struct qlcnic_adapter
*adapter
)
826 int val
, err
, first_boot
;
828 err
= qlcnic_can_start_firmware(adapter
);
834 first_boot
= QLCRD32(adapter
, QLCNIC_CAM_RAM(0x1fc));
835 if (first_boot
== 0x55555555)
836 /* This is the first boot after power up */
837 QLCWR32(adapter
, QLCNIC_CAM_RAM(0x1fc), QLCNIC_BDINFO_MAGIC
);
840 qlcnic_request_firmware(adapter
);
842 if (qlcnic_check_flash_fw_ver(adapter
))
845 adapter
->fw_type
= QLCNIC_FLASH_ROMIMAGE
;
848 err
= qlcnic_need_fw_reset(adapter
);
854 if (first_boot
!= 0x55555555) {
855 QLCWR32(adapter
, CRB_CMDPEG_STATE
, 0);
856 QLCWR32(adapter
, CRB_RCVPEG_STATE
, 0);
857 qlcnic_pinit_from_rom(adapter
);
861 QLCWR32(adapter
, QLCNIC_PEG_HALT_STATUS1
, 0);
862 QLCWR32(adapter
, QLCNIC_PEG_HALT_STATUS2
, 0);
864 qlcnic_set_port_mode(adapter
);
866 err
= qlcnic_load_firmware(adapter
);
870 qlcnic_release_firmware(adapter
);
872 val
= (_QLCNIC_LINUX_MAJOR
<< 16)
873 | ((_QLCNIC_LINUX_MINOR
<< 8))
874 | (_QLCNIC_LINUX_SUBVERSION
);
875 QLCWR32(adapter
, CRB_DRIVER_VERSION
, val
);
878 /* Handshake with the card before we register the devices. */
879 err
= qlcnic_init_firmware(adapter
);
883 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
, QLCNIC_DEV_READY
);
884 qlcnic_idc_debug_info(adapter
, 1);
886 qlcnic_check_options(adapter
);
887 if (qlcnic_reset_npar_config(adapter
))
889 qlcnic_dev_set_npar_ready(adapter
);
891 adapter
->need_fw_reset
= 0;
893 qlcnic_release_firmware(adapter
);
897 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
, QLCNIC_DEV_FAILED
);
898 dev_err(&adapter
->pdev
->dev
, "Device state set to failed\n");
899 qlcnic_release_firmware(adapter
);
904 qlcnic_request_irq(struct qlcnic_adapter
*adapter
)
906 irq_handler_t handler
;
907 struct qlcnic_host_sds_ring
*sds_ring
;
910 unsigned long flags
= 0;
911 struct net_device
*netdev
= adapter
->netdev
;
912 struct qlcnic_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
914 if (adapter
->diag_test
== QLCNIC_INTERRUPT_TEST
) {
915 handler
= qlcnic_tmp_intr
;
916 if (!QLCNIC_IS_MSI_FAMILY(adapter
))
917 flags
|= IRQF_SHARED
;
920 if (adapter
->flags
& QLCNIC_MSIX_ENABLED
)
921 handler
= qlcnic_msix_intr
;
922 else if (adapter
->flags
& QLCNIC_MSI_ENABLED
)
923 handler
= qlcnic_msi_intr
;
925 flags
|= IRQF_SHARED
;
926 handler
= qlcnic_intr
;
929 adapter
->irq
= netdev
->irq
;
931 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
932 sds_ring
= &recv_ctx
->sds_rings
[ring
];
933 sprintf(sds_ring
->name
, "%s[%d]", netdev
->name
, ring
);
934 err
= request_irq(sds_ring
->irq
, handler
,
935 flags
, sds_ring
->name
, sds_ring
);
944 qlcnic_free_irq(struct qlcnic_adapter
*adapter
)
947 struct qlcnic_host_sds_ring
*sds_ring
;
949 struct qlcnic_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
951 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
952 sds_ring
= &recv_ctx
->sds_rings
[ring
];
953 free_irq(sds_ring
->irq
, sds_ring
);
958 qlcnic_init_coalesce_defaults(struct qlcnic_adapter
*adapter
)
960 adapter
->coal
.flags
= QLCNIC_INTR_DEFAULT
;
961 adapter
->coal
.normal
.data
.rx_time_us
=
962 QLCNIC_DEFAULT_INTR_COALESCE_RX_TIME_US
;
963 adapter
->coal
.normal
.data
.rx_packets
=
964 QLCNIC_DEFAULT_INTR_COALESCE_RX_PACKETS
;
965 adapter
->coal
.normal
.data
.tx_time_us
=
966 QLCNIC_DEFAULT_INTR_COALESCE_TX_TIME_US
;
967 adapter
->coal
.normal
.data
.tx_packets
=
968 QLCNIC_DEFAULT_INTR_COALESCE_TX_PACKETS
;
972 __qlcnic_up(struct qlcnic_adapter
*adapter
, struct net_device
*netdev
)
975 struct qlcnic_host_rds_ring
*rds_ring
;
977 if (adapter
->is_up
!= QLCNIC_ADAPTER_UP_MAGIC
)
980 if (test_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
983 if (qlcnic_fw_create_ctx(adapter
))
986 for (ring
= 0; ring
< adapter
->max_rds_rings
; ring
++) {
987 rds_ring
= &adapter
->recv_ctx
.rds_rings
[ring
];
988 qlcnic_post_rx_buffers(adapter
, ring
, rds_ring
);
991 qlcnic_set_multi(netdev
);
992 qlcnic_fw_cmd_set_mtu(adapter
, netdev
->mtu
);
994 adapter
->ahw
.linkup
= 0;
996 if (adapter
->max_sds_rings
> 1)
997 qlcnic_config_rss(adapter
, 1);
999 qlcnic_config_intr_coalesce(adapter
);
1001 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_HW_LRO
)
1002 qlcnic_config_hw_lro(adapter
, QLCNIC_LRO_ENABLED
);
1004 qlcnic_napi_enable(adapter
);
1006 qlcnic_linkevent_request(adapter
, 1);
1008 adapter
->reset_context
= 0;
1009 set_bit(__QLCNIC_DEV_UP
, &adapter
->state
);
1013 /* Usage: During resume and firmware recovery module.*/
1016 qlcnic_up(struct qlcnic_adapter
*adapter
, struct net_device
*netdev
)
1021 if (netif_running(netdev
))
1022 err
= __qlcnic_up(adapter
, netdev
);
1029 __qlcnic_down(struct qlcnic_adapter
*adapter
, struct net_device
*netdev
)
1031 if (adapter
->is_up
!= QLCNIC_ADAPTER_UP_MAGIC
)
1034 if (!test_and_clear_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
1038 spin_lock(&adapter
->tx_clean_lock
);
1039 netif_carrier_off(netdev
);
1040 netif_tx_disable(netdev
);
1042 qlcnic_free_mac_list(adapter
);
1044 qlcnic_nic_set_promisc(adapter
, QLCNIC_NIU_NON_PROMISC_MODE
);
1046 qlcnic_napi_disable(adapter
);
1048 qlcnic_fw_destroy_ctx(adapter
);
1050 qlcnic_reset_rx_buffers_list(adapter
);
1051 qlcnic_release_tx_buffers(adapter
);
1052 spin_unlock(&adapter
->tx_clean_lock
);
1055 /* Usage: During suspend and firmware recovery module */
1058 qlcnic_down(struct qlcnic_adapter
*adapter
, struct net_device
*netdev
)
1061 if (netif_running(netdev
))
1062 __qlcnic_down(adapter
, netdev
);
1068 qlcnic_attach(struct qlcnic_adapter
*adapter
)
1070 struct net_device
*netdev
= adapter
->netdev
;
1071 struct pci_dev
*pdev
= adapter
->pdev
;
1074 if (adapter
->is_up
== QLCNIC_ADAPTER_UP_MAGIC
)
1077 err
= qlcnic_napi_add(adapter
, netdev
);
1081 err
= qlcnic_alloc_sw_resources(adapter
);
1083 dev_err(&pdev
->dev
, "Error in setting sw resources\n");
1084 goto err_out_napi_del
;
1087 err
= qlcnic_alloc_hw_resources(adapter
);
1089 dev_err(&pdev
->dev
, "Error in setting hw resources\n");
1090 goto err_out_free_sw
;
1093 err
= qlcnic_request_irq(adapter
);
1095 dev_err(&pdev
->dev
, "failed to setup interrupt\n");
1096 goto err_out_free_hw
;
1099 qlcnic_init_coalesce_defaults(adapter
);
1101 qlcnic_create_sysfs_entries(adapter
);
1103 adapter
->is_up
= QLCNIC_ADAPTER_UP_MAGIC
;
1107 qlcnic_free_hw_resources(adapter
);
1109 qlcnic_free_sw_resources(adapter
);
1111 qlcnic_napi_del(adapter
);
1116 qlcnic_detach(struct qlcnic_adapter
*adapter
)
1118 if (adapter
->is_up
!= QLCNIC_ADAPTER_UP_MAGIC
)
1121 qlcnic_remove_sysfs_entries(adapter
);
1123 qlcnic_free_hw_resources(adapter
);
1124 qlcnic_release_rx_buffers(adapter
);
1125 qlcnic_free_irq(adapter
);
1126 qlcnic_napi_del(adapter
);
1127 qlcnic_free_sw_resources(adapter
);
1132 void qlcnic_diag_free_res(struct net_device
*netdev
, int max_sds_rings
)
1134 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
1135 struct qlcnic_host_sds_ring
*sds_ring
;
1138 clear_bit(__QLCNIC_DEV_UP
, &adapter
->state
);
1139 if (adapter
->diag_test
== QLCNIC_INTERRUPT_TEST
) {
1140 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
1141 sds_ring
= &adapter
->recv_ctx
.sds_rings
[ring
];
1142 qlcnic_disable_int(sds_ring
);
1146 qlcnic_fw_destroy_ctx(adapter
);
1148 qlcnic_detach(adapter
);
1150 adapter
->diag_test
= 0;
1151 adapter
->max_sds_rings
= max_sds_rings
;
1153 if (qlcnic_attach(adapter
))
1156 if (netif_running(netdev
))
1157 __qlcnic_up(adapter
, netdev
);
1159 netif_device_attach(netdev
);
1162 int qlcnic_diag_alloc_res(struct net_device
*netdev
, int test
)
1164 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
1165 struct qlcnic_host_sds_ring
*sds_ring
;
1166 struct qlcnic_host_rds_ring
*rds_ring
;
1170 netif_device_detach(netdev
);
1172 if (netif_running(netdev
))
1173 __qlcnic_down(adapter
, netdev
);
1175 qlcnic_detach(adapter
);
1177 adapter
->max_sds_rings
= 1;
1178 adapter
->diag_test
= test
;
1180 ret
= qlcnic_attach(adapter
);
1182 netif_device_attach(netdev
);
1186 ret
= qlcnic_fw_create_ctx(adapter
);
1188 qlcnic_detach(adapter
);
1189 netif_device_attach(netdev
);
1193 for (ring
= 0; ring
< adapter
->max_rds_rings
; ring
++) {
1194 rds_ring
= &adapter
->recv_ctx
.rds_rings
[ring
];
1195 qlcnic_post_rx_buffers(adapter
, ring
, rds_ring
);
1198 if (adapter
->diag_test
== QLCNIC_INTERRUPT_TEST
) {
1199 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
1200 sds_ring
= &adapter
->recv_ctx
.sds_rings
[ring
];
1201 qlcnic_enable_int(sds_ring
);
1204 set_bit(__QLCNIC_DEV_UP
, &adapter
->state
);
1209 /* Reset context in hardware only */
1211 qlcnic_reset_hw_context(struct qlcnic_adapter
*adapter
)
1213 struct net_device
*netdev
= adapter
->netdev
;
1215 if (test_and_set_bit(__QLCNIC_RESETTING
, &adapter
->state
))
1218 netif_device_detach(netdev
);
1220 qlcnic_down(adapter
, netdev
);
1222 qlcnic_up(adapter
, netdev
);
1224 netif_device_attach(netdev
);
1226 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
1231 qlcnic_reset_context(struct qlcnic_adapter
*adapter
)
1234 struct net_device
*netdev
= adapter
->netdev
;
1236 if (test_and_set_bit(__QLCNIC_RESETTING
, &adapter
->state
))
1239 if (adapter
->is_up
== QLCNIC_ADAPTER_UP_MAGIC
) {
1241 netif_device_detach(netdev
);
1243 if (netif_running(netdev
))
1244 __qlcnic_down(adapter
, netdev
);
1246 qlcnic_detach(adapter
);
1248 if (netif_running(netdev
)) {
1249 err
= qlcnic_attach(adapter
);
1251 __qlcnic_up(adapter
, netdev
);
1254 netif_device_attach(netdev
);
1257 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
1262 qlcnic_setup_netdev(struct qlcnic_adapter
*adapter
,
1263 struct net_device
*netdev
, u8 pci_using_dac
)
1266 struct pci_dev
*pdev
= adapter
->pdev
;
1268 adapter
->rx_csum
= 1;
1269 adapter
->mc_enabled
= 0;
1270 adapter
->max_mc_count
= 38;
1272 netdev
->netdev_ops
= &qlcnic_netdev_ops
;
1273 netdev
->watchdog_timeo
= 5*HZ
;
1275 qlcnic_change_mtu(netdev
, netdev
->mtu
);
1277 SET_ETHTOOL_OPS(netdev
, &qlcnic_ethtool_ops
);
1279 netdev
->features
|= (NETIF_F_SG
| NETIF_F_IP_CSUM
|
1280 NETIF_F_IPV6_CSUM
| NETIF_F_GRO
);
1281 netdev
->vlan_features
|= (NETIF_F_SG
| NETIF_F_IP_CSUM
|
1284 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_TSO
) {
1285 netdev
->features
|= (NETIF_F_TSO
| NETIF_F_TSO6
);
1286 netdev
->vlan_features
|= (NETIF_F_TSO
| NETIF_F_TSO6
);
1289 if (pci_using_dac
) {
1290 netdev
->features
|= NETIF_F_HIGHDMA
;
1291 netdev
->vlan_features
|= NETIF_F_HIGHDMA
;
1294 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_FVLANTX
)
1295 netdev
->features
|= (NETIF_F_HW_VLAN_TX
);
1297 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_HW_LRO
)
1298 netdev
->features
|= NETIF_F_LRO
;
1300 netdev
->irq
= adapter
->msix_entries
[0].vector
;
1302 if (qlcnic_read_mac_addr(adapter
))
1303 dev_warn(&pdev
->dev
, "failed to read mac addr\n");
1305 netif_carrier_off(netdev
);
1306 netif_stop_queue(netdev
);
1308 err
= register_netdev(netdev
);
1310 dev_err(&pdev
->dev
, "failed to register net device\n");
1317 static int qlcnic_set_dma_mask(struct pci_dev
*pdev
, u8
*pci_using_dac
)
1319 if (!pci_set_dma_mask(pdev
, DMA_BIT_MASK(64)) &&
1320 !pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(64)))
1322 else if (!pci_set_dma_mask(pdev
, DMA_BIT_MASK(32)) &&
1323 !pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(32)))
1326 dev_err(&pdev
->dev
, "Unable to set DMA mask, aborting\n");
1333 static int __devinit
1334 qlcnic_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
1336 struct net_device
*netdev
= NULL
;
1337 struct qlcnic_adapter
*adapter
= NULL
;
1339 uint8_t revision_id
;
1340 uint8_t pci_using_dac
;
1342 err
= pci_enable_device(pdev
);
1346 if (!(pci_resource_flags(pdev
, 0) & IORESOURCE_MEM
)) {
1348 goto err_out_disable_pdev
;
1351 err
= qlcnic_set_dma_mask(pdev
, &pci_using_dac
);
1353 goto err_out_disable_pdev
;
1355 err
= pci_request_regions(pdev
, qlcnic_driver_name
);
1357 goto err_out_disable_pdev
;
1359 pci_set_master(pdev
);
1360 pci_enable_pcie_error_reporting(pdev
);
1362 netdev
= alloc_etherdev(sizeof(struct qlcnic_adapter
));
1364 dev_err(&pdev
->dev
, "failed to allocate net_device\n");
1366 goto err_out_free_res
;
1369 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
1371 adapter
= netdev_priv(netdev
);
1372 adapter
->netdev
= netdev
;
1373 adapter
->pdev
= pdev
;
1374 adapter
->dev_rst_time
= jiffies
;
1376 revision_id
= pdev
->revision
;
1377 adapter
->ahw
.revision_id
= revision_id
;
1379 rwlock_init(&adapter
->ahw
.crb_lock
);
1380 mutex_init(&adapter
->ahw
.mem_lock
);
1382 spin_lock_init(&adapter
->tx_clean_lock
);
1383 INIT_LIST_HEAD(&adapter
->mac_list
);
1385 err
= qlcnic_setup_pci_map(adapter
);
1387 goto err_out_free_netdev
;
1389 /* This will be reset for mezz cards */
1390 adapter
->portnum
= adapter
->ahw
.pci_func
;
1392 err
= qlcnic_get_board_info(adapter
);
1394 dev_err(&pdev
->dev
, "Error getting board config info.\n");
1395 goto err_out_iounmap
;
1398 if (qlcnic_read_mac_addr(adapter
))
1399 dev_warn(&pdev
->dev
, "failed to read mac addr\n");
1401 if (qlcnic_setup_idc_param(adapter
))
1402 goto err_out_iounmap
;
1404 err
= adapter
->nic_ops
->start_firmware(adapter
);
1406 dev_err(&pdev
->dev
, "Loading fw failed.Please Reboot\n");
1407 goto err_out_decr_ref
;
1410 qlcnic_clear_stats(adapter
);
1412 qlcnic_setup_intr(adapter
);
1414 err
= qlcnic_setup_netdev(adapter
, netdev
, pci_using_dac
);
1416 goto err_out_disable_msi
;
1418 pci_set_drvdata(pdev
, adapter
);
1420 qlcnic_schedule_work(adapter
, qlcnic_fw_poll_work
, FW_POLL_DELAY
);
1422 switch (adapter
->ahw
.port_type
) {
1424 dev_info(&adapter
->pdev
->dev
, "%s: GbE port initialized\n",
1425 adapter
->netdev
->name
);
1428 dev_info(&adapter
->pdev
->dev
, "%s: XGbE port initialized\n",
1429 adapter
->netdev
->name
);
1433 qlcnic_create_diag_entries(adapter
);
1437 err_out_disable_msi
:
1438 qlcnic_teardown_intr(adapter
);
1441 qlcnic_clr_all_drv_state(adapter
);
1444 qlcnic_cleanup_pci_map(adapter
);
1446 err_out_free_netdev
:
1447 free_netdev(netdev
);
1450 pci_release_regions(pdev
);
1452 err_out_disable_pdev
:
1453 pci_set_drvdata(pdev
, NULL
);
1454 pci_disable_device(pdev
);
1458 static void __devexit
qlcnic_remove(struct pci_dev
*pdev
)
1460 struct qlcnic_adapter
*adapter
;
1461 struct net_device
*netdev
;
1463 adapter
= pci_get_drvdata(pdev
);
1464 if (adapter
== NULL
)
1467 netdev
= adapter
->netdev
;
1469 qlcnic_cancel_fw_work(adapter
);
1471 unregister_netdev(netdev
);
1473 qlcnic_detach(adapter
);
1475 if (adapter
->npars
!= NULL
)
1476 kfree(adapter
->npars
);
1477 if (adapter
->eswitch
!= NULL
)
1478 kfree(adapter
->eswitch
);
1480 qlcnic_clr_all_drv_state(adapter
);
1482 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
1484 qlcnic_teardown_intr(adapter
);
1486 qlcnic_remove_diag_entries(adapter
);
1488 qlcnic_cleanup_pci_map(adapter
);
1490 qlcnic_release_firmware(adapter
);
1492 pci_disable_pcie_error_reporting(pdev
);
1493 pci_release_regions(pdev
);
1494 pci_disable_device(pdev
);
1495 pci_set_drvdata(pdev
, NULL
);
1497 free_netdev(netdev
);
1499 static int __qlcnic_shutdown(struct pci_dev
*pdev
)
1501 struct qlcnic_adapter
*adapter
= pci_get_drvdata(pdev
);
1502 struct net_device
*netdev
= adapter
->netdev
;
1505 netif_device_detach(netdev
);
1507 qlcnic_cancel_fw_work(adapter
);
1509 if (netif_running(netdev
))
1510 qlcnic_down(adapter
, netdev
);
1512 qlcnic_clr_all_drv_state(adapter
);
1514 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
1516 retval
= pci_save_state(pdev
);
1520 if (qlcnic_wol_supported(adapter
)) {
1521 pci_enable_wake(pdev
, PCI_D3cold
, 1);
1522 pci_enable_wake(pdev
, PCI_D3hot
, 1);
1528 static void qlcnic_shutdown(struct pci_dev
*pdev
)
1530 if (__qlcnic_shutdown(pdev
))
1533 pci_disable_device(pdev
);
1538 qlcnic_suspend(struct pci_dev
*pdev
, pm_message_t state
)
1542 retval
= __qlcnic_shutdown(pdev
);
1546 pci_set_power_state(pdev
, pci_choose_state(pdev
, state
));
1551 qlcnic_resume(struct pci_dev
*pdev
)
1553 struct qlcnic_adapter
*adapter
= pci_get_drvdata(pdev
);
1554 struct net_device
*netdev
= adapter
->netdev
;
1557 err
= pci_enable_device(pdev
);
1561 pci_set_power_state(pdev
, PCI_D0
);
1562 pci_set_master(pdev
);
1563 pci_restore_state(pdev
);
1565 err
= adapter
->nic_ops
->start_firmware(adapter
);
1567 dev_err(&pdev
->dev
, "failed to start firmware\n");
1571 if (netif_running(netdev
)) {
1572 err
= qlcnic_up(adapter
, netdev
);
1576 qlcnic_config_indev_addr(netdev
, NETDEV_UP
);
1579 netif_device_attach(netdev
);
1580 qlcnic_schedule_work(adapter
, qlcnic_fw_poll_work
, FW_POLL_DELAY
);
1585 static int qlcnic_open(struct net_device
*netdev
)
1587 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
1590 if (adapter
->driver_mismatch
)
1593 err
= qlcnic_attach(adapter
);
1597 err
= __qlcnic_up(adapter
, netdev
);
1601 netif_start_queue(netdev
);
1606 qlcnic_detach(adapter
);
1611 * qlcnic_close - Disables a network interface entry point
1613 static int qlcnic_close(struct net_device
*netdev
)
1615 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
1617 __qlcnic_down(adapter
, netdev
);
1622 qlcnic_tso_check(struct net_device
*netdev
,
1623 struct qlcnic_host_tx_ring
*tx_ring
,
1624 struct cmd_desc_type0
*first_desc
,
1625 struct sk_buff
*skb
)
1627 u8 opcode
= TX_ETHER_PKT
;
1628 __be16 protocol
= skb
->protocol
;
1629 u16 flags
= 0, vid
= 0;
1630 int copied
, offset
, copy_len
, hdr_len
= 0, tso
= 0, vlan_oob
= 0;
1631 struct cmd_desc_type0
*hwdesc
;
1632 struct vlan_ethhdr
*vh
;
1633 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
1634 u32 producer
= tx_ring
->producer
;
1636 if (protocol
== cpu_to_be16(ETH_P_8021Q
)) {
1638 vh
= (struct vlan_ethhdr
*)skb
->data
;
1639 protocol
= vh
->h_vlan_encapsulated_proto
;
1640 flags
= FLAGS_VLAN_TAGGED
;
1642 } else if (vlan_tx_tag_present(skb
)) {
1644 flags
= FLAGS_VLAN_OOB
;
1645 vid
= vlan_tx_tag_get(skb
);
1646 qlcnic_set_tx_vlan_tci(first_desc
, vid
);
1650 if (*(skb
->data
) & BIT_0
) {
1652 memcpy(&first_desc
->eth_addr
, skb
->data
, ETH_ALEN
);
1655 if ((netdev
->features
& (NETIF_F_TSO
| NETIF_F_TSO6
)) &&
1656 skb_shinfo(skb
)->gso_size
> 0) {
1658 hdr_len
= skb_transport_offset(skb
) + tcp_hdrlen(skb
);
1660 first_desc
->mss
= cpu_to_le16(skb_shinfo(skb
)->gso_size
);
1661 first_desc
->total_hdr_length
= hdr_len
;
1663 first_desc
->total_hdr_length
+= VLAN_HLEN
;
1664 first_desc
->tcp_hdr_offset
= VLAN_HLEN
;
1665 first_desc
->ip_hdr_offset
= VLAN_HLEN
;
1666 /* Only in case of TSO on vlan device */
1667 flags
|= FLAGS_VLAN_TAGGED
;
1670 opcode
= (protocol
== cpu_to_be16(ETH_P_IPV6
)) ?
1671 TX_TCP_LSO6
: TX_TCP_LSO
;
1674 } else if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
1677 if (protocol
== cpu_to_be16(ETH_P_IP
)) {
1678 l4proto
= ip_hdr(skb
)->protocol
;
1680 if (l4proto
== IPPROTO_TCP
)
1681 opcode
= TX_TCP_PKT
;
1682 else if (l4proto
== IPPROTO_UDP
)
1683 opcode
= TX_UDP_PKT
;
1684 } else if (protocol
== cpu_to_be16(ETH_P_IPV6
)) {
1685 l4proto
= ipv6_hdr(skb
)->nexthdr
;
1687 if (l4proto
== IPPROTO_TCP
)
1688 opcode
= TX_TCPV6_PKT
;
1689 else if (l4proto
== IPPROTO_UDP
)
1690 opcode
= TX_UDPV6_PKT
;
1694 first_desc
->tcp_hdr_offset
+= skb_transport_offset(skb
);
1695 first_desc
->ip_hdr_offset
+= skb_network_offset(skb
);
1696 qlcnic_set_tx_flags_opcode(first_desc
, flags
, opcode
);
1701 /* For LSO, we need to copy the MAC/IP/TCP headers into
1702 * the descriptor ring
1708 /* Create a TSO vlan header template for firmware */
1710 hwdesc
= &tx_ring
->desc_head
[producer
];
1711 tx_ring
->cmd_buf_arr
[producer
].skb
= NULL
;
1713 copy_len
= min((int)sizeof(struct cmd_desc_type0
) - offset
,
1714 hdr_len
+ VLAN_HLEN
);
1716 vh
= (struct vlan_ethhdr
*)((char *)hwdesc
+ 2);
1717 skb_copy_from_linear_data(skb
, vh
, 12);
1718 vh
->h_vlan_proto
= htons(ETH_P_8021Q
);
1719 vh
->h_vlan_TCI
= htons(vid
);
1720 skb_copy_from_linear_data_offset(skb
, 12,
1721 (char *)vh
+ 16, copy_len
- 16);
1723 copied
= copy_len
- VLAN_HLEN
;
1726 producer
= get_next_index(producer
, tx_ring
->num_desc
);
1729 while (copied
< hdr_len
) {
1731 copy_len
= min((int)sizeof(struct cmd_desc_type0
) - offset
,
1732 (hdr_len
- copied
));
1734 hwdesc
= &tx_ring
->desc_head
[producer
];
1735 tx_ring
->cmd_buf_arr
[producer
].skb
= NULL
;
1737 skb_copy_from_linear_data_offset(skb
, copied
,
1738 (char *)hwdesc
+ offset
, copy_len
);
1743 producer
= get_next_index(producer
, tx_ring
->num_desc
);
1746 tx_ring
->producer
= producer
;
1748 adapter
->stats
.lso_frames
++;
1752 qlcnic_map_tx_skb(struct pci_dev
*pdev
,
1753 struct sk_buff
*skb
, struct qlcnic_cmd_buffer
*pbuf
)
1755 struct qlcnic_skb_frag
*nf
;
1756 struct skb_frag_struct
*frag
;
1760 nr_frags
= skb_shinfo(skb
)->nr_frags
;
1761 nf
= &pbuf
->frag_array
[0];
1763 map
= pci_map_single(pdev
, skb
->data
,
1764 skb_headlen(skb
), PCI_DMA_TODEVICE
);
1765 if (pci_dma_mapping_error(pdev
, map
))
1769 nf
->length
= skb_headlen(skb
);
1771 for (i
= 0; i
< nr_frags
; i
++) {
1772 frag
= &skb_shinfo(skb
)->frags
[i
];
1773 nf
= &pbuf
->frag_array
[i
+1];
1775 map
= pci_map_page(pdev
, frag
->page
, frag
->page_offset
,
1776 frag
->size
, PCI_DMA_TODEVICE
);
1777 if (pci_dma_mapping_error(pdev
, map
))
1781 nf
->length
= frag
->size
;
1788 nf
= &pbuf
->frag_array
[i
+1];
1789 pci_unmap_page(pdev
, nf
->dma
, nf
->length
, PCI_DMA_TODEVICE
);
1792 nf
= &pbuf
->frag_array
[0];
1793 pci_unmap_single(pdev
, nf
->dma
, skb_headlen(skb
), PCI_DMA_TODEVICE
);
1800 qlcnic_clear_cmddesc(u64
*desc
)
1807 qlcnic_xmit_frame(struct sk_buff
*skb
, struct net_device
*netdev
)
1809 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
1810 struct qlcnic_host_tx_ring
*tx_ring
= adapter
->tx_ring
;
1811 struct qlcnic_cmd_buffer
*pbuf
;
1812 struct qlcnic_skb_frag
*buffrag
;
1813 struct cmd_desc_type0
*hwdesc
, *first_desc
;
1814 struct pci_dev
*pdev
;
1818 int frag_count
, no_of_desc
;
1819 u32 num_txd
= tx_ring
->num_desc
;
1821 if (!test_bit(__QLCNIC_DEV_UP
, &adapter
->state
)) {
1822 netif_stop_queue(netdev
);
1823 return NETDEV_TX_BUSY
;
1826 frag_count
= skb_shinfo(skb
)->nr_frags
+ 1;
1828 /* 4 fragments per cmd des */
1829 no_of_desc
= (frag_count
+ 3) >> 2;
1831 if (unlikely(qlcnic_tx_avail(tx_ring
) <= TX_STOP_THRESH
)) {
1832 netif_stop_queue(netdev
);
1834 if (qlcnic_tx_avail(tx_ring
) > TX_STOP_THRESH
)
1835 netif_start_queue(netdev
);
1837 adapter
->stats
.xmit_off
++;
1838 return NETDEV_TX_BUSY
;
1842 producer
= tx_ring
->producer
;
1843 pbuf
= &tx_ring
->cmd_buf_arr
[producer
];
1845 pdev
= adapter
->pdev
;
1847 if (qlcnic_map_tx_skb(pdev
, skb
, pbuf
)) {
1848 adapter
->stats
.tx_dma_map_error
++;
1853 pbuf
->frag_count
= frag_count
;
1855 first_desc
= hwdesc
= &tx_ring
->desc_head
[producer
];
1856 qlcnic_clear_cmddesc((u64
*)hwdesc
);
1858 qlcnic_set_tx_frags_len(first_desc
, frag_count
, skb
->len
);
1859 qlcnic_set_tx_port(first_desc
, adapter
->portnum
);
1861 for (i
= 0; i
< frag_count
; i
++) {
1865 if ((k
== 0) && (i
> 0)) {
1866 /* move to next desc.*/
1867 producer
= get_next_index(producer
, num_txd
);
1868 hwdesc
= &tx_ring
->desc_head
[producer
];
1869 qlcnic_clear_cmddesc((u64
*)hwdesc
);
1870 tx_ring
->cmd_buf_arr
[producer
].skb
= NULL
;
1873 buffrag
= &pbuf
->frag_array
[i
];
1875 hwdesc
->buffer_length
[k
] = cpu_to_le16(buffrag
->length
);
1878 hwdesc
->addr_buffer1
= cpu_to_le64(buffrag
->dma
);
1881 hwdesc
->addr_buffer2
= cpu_to_le64(buffrag
->dma
);
1884 hwdesc
->addr_buffer3
= cpu_to_le64(buffrag
->dma
);
1887 hwdesc
->addr_buffer4
= cpu_to_le64(buffrag
->dma
);
1892 tx_ring
->producer
= get_next_index(producer
, num_txd
);
1894 qlcnic_tso_check(netdev
, tx_ring
, first_desc
, skb
);
1896 qlcnic_update_cmd_producer(adapter
, tx_ring
);
1898 adapter
->stats
.txbytes
+= skb
->len
;
1899 adapter
->stats
.xmitcalled
++;
1901 return NETDEV_TX_OK
;
1904 adapter
->stats
.txdropped
++;
1905 dev_kfree_skb_any(skb
);
1906 return NETDEV_TX_OK
;
1909 static int qlcnic_check_temp(struct qlcnic_adapter
*adapter
)
1911 struct net_device
*netdev
= adapter
->netdev
;
1912 u32 temp
, temp_state
, temp_val
;
1915 temp
= QLCRD32(adapter
, CRB_TEMP_STATE
);
1917 temp_state
= qlcnic_get_temp_state(temp
);
1918 temp_val
= qlcnic_get_temp_val(temp
);
1920 if (temp_state
== QLCNIC_TEMP_PANIC
) {
1921 dev_err(&netdev
->dev
,
1922 "Device temperature %d degrees C exceeds"
1923 " maximum allowed. Hardware has been shut down.\n",
1926 } else if (temp_state
== QLCNIC_TEMP_WARN
) {
1927 if (adapter
->temp
== QLCNIC_TEMP_NORMAL
) {
1928 dev_err(&netdev
->dev
,
1929 "Device temperature %d degrees C "
1930 "exceeds operating range."
1931 " Immediate action needed.\n",
1935 if (adapter
->temp
== QLCNIC_TEMP_WARN
) {
1936 dev_info(&netdev
->dev
,
1937 "Device temperature is now %d degrees C"
1938 " in normal range.\n", temp_val
);
1941 adapter
->temp
= temp_state
;
1945 void qlcnic_advert_link_change(struct qlcnic_adapter
*adapter
, int linkup
)
1947 struct net_device
*netdev
= adapter
->netdev
;
1949 if (adapter
->ahw
.linkup
&& !linkup
) {
1950 dev_info(&netdev
->dev
, "NIC Link is down\n");
1951 adapter
->ahw
.linkup
= 0;
1952 if (netif_running(netdev
)) {
1953 netif_carrier_off(netdev
);
1954 netif_stop_queue(netdev
);
1956 } else if (!adapter
->ahw
.linkup
&& linkup
) {
1957 dev_info(&netdev
->dev
, "NIC Link is up\n");
1958 adapter
->ahw
.linkup
= 1;
1959 if (netif_running(netdev
)) {
1960 netif_carrier_on(netdev
);
1961 netif_wake_queue(netdev
);
1966 static void qlcnic_tx_timeout(struct net_device
*netdev
)
1968 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
1970 if (test_bit(__QLCNIC_RESETTING
, &adapter
->state
))
1973 dev_err(&netdev
->dev
, "transmit timeout, resetting.\n");
1975 if (++adapter
->tx_timeo_cnt
>= QLCNIC_MAX_TX_TIMEOUTS
)
1976 adapter
->need_fw_reset
= 1;
1978 adapter
->reset_context
= 1;
1981 static struct net_device_stats
*qlcnic_get_stats(struct net_device
*netdev
)
1983 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
1984 struct net_device_stats
*stats
= &netdev
->stats
;
1986 stats
->rx_packets
= adapter
->stats
.rx_pkts
+ adapter
->stats
.lro_pkts
;
1987 stats
->tx_packets
= adapter
->stats
.xmitfinished
;
1988 stats
->rx_bytes
= adapter
->stats
.rxbytes
+ adapter
->stats
.lrobytes
;
1989 stats
->tx_bytes
= adapter
->stats
.txbytes
;
1990 stats
->rx_dropped
= adapter
->stats
.rxdropped
;
1991 stats
->tx_dropped
= adapter
->stats
.txdropped
;
1996 static irqreturn_t
qlcnic_clear_legacy_intr(struct qlcnic_adapter
*adapter
)
2000 status
= readl(adapter
->isr_int_vec
);
2002 if (!(status
& adapter
->int_vec_bit
))
2005 /* check interrupt state machine, to be sure */
2006 status
= readl(adapter
->crb_int_state_reg
);
2007 if (!ISR_LEGACY_INT_TRIGGERED(status
))
2010 writel(0xffffffff, adapter
->tgt_status_reg
);
2011 /* read twice to ensure write is flushed */
2012 readl(adapter
->isr_int_vec
);
2013 readl(adapter
->isr_int_vec
);
2018 static irqreturn_t
qlcnic_tmp_intr(int irq
, void *data
)
2020 struct qlcnic_host_sds_ring
*sds_ring
= data
;
2021 struct qlcnic_adapter
*adapter
= sds_ring
->adapter
;
2023 if (adapter
->flags
& QLCNIC_MSIX_ENABLED
)
2025 else if (adapter
->flags
& QLCNIC_MSI_ENABLED
) {
2026 writel(0xffffffff, adapter
->tgt_status_reg
);
2030 if (qlcnic_clear_legacy_intr(adapter
) == IRQ_NONE
)
2034 adapter
->diag_cnt
++;
2035 qlcnic_enable_int(sds_ring
);
2039 static irqreturn_t
qlcnic_intr(int irq
, void *data
)
2041 struct qlcnic_host_sds_ring
*sds_ring
= data
;
2042 struct qlcnic_adapter
*adapter
= sds_ring
->adapter
;
2044 if (qlcnic_clear_legacy_intr(adapter
) == IRQ_NONE
)
2047 napi_schedule(&sds_ring
->napi
);
2052 static irqreturn_t
qlcnic_msi_intr(int irq
, void *data
)
2054 struct qlcnic_host_sds_ring
*sds_ring
= data
;
2055 struct qlcnic_adapter
*adapter
= sds_ring
->adapter
;
2057 /* clear interrupt */
2058 writel(0xffffffff, adapter
->tgt_status_reg
);
2060 napi_schedule(&sds_ring
->napi
);
2064 static irqreturn_t
qlcnic_msix_intr(int irq
, void *data
)
2066 struct qlcnic_host_sds_ring
*sds_ring
= data
;
2068 napi_schedule(&sds_ring
->napi
);
2072 static int qlcnic_process_cmd_ring(struct qlcnic_adapter
*adapter
)
2074 u32 sw_consumer
, hw_consumer
;
2076 struct qlcnic_cmd_buffer
*buffer
;
2077 struct pci_dev
*pdev
= adapter
->pdev
;
2078 struct net_device
*netdev
= adapter
->netdev
;
2079 struct qlcnic_skb_frag
*frag
;
2081 struct qlcnic_host_tx_ring
*tx_ring
= adapter
->tx_ring
;
2083 if (!spin_trylock(&adapter
->tx_clean_lock
))
2086 sw_consumer
= tx_ring
->sw_consumer
;
2087 hw_consumer
= le32_to_cpu(*(tx_ring
->hw_consumer
));
2089 while (sw_consumer
!= hw_consumer
) {
2090 buffer
= &tx_ring
->cmd_buf_arr
[sw_consumer
];
2092 frag
= &buffer
->frag_array
[0];
2093 pci_unmap_single(pdev
, frag
->dma
, frag
->length
,
2096 for (i
= 1; i
< buffer
->frag_count
; i
++) {
2098 pci_unmap_page(pdev
, frag
->dma
, frag
->length
,
2103 adapter
->stats
.xmitfinished
++;
2104 dev_kfree_skb_any(buffer
->skb
);
2108 sw_consumer
= get_next_index(sw_consumer
, tx_ring
->num_desc
);
2109 if (++count
>= MAX_STATUS_HANDLE
)
2113 if (count
&& netif_running(netdev
)) {
2114 tx_ring
->sw_consumer
= sw_consumer
;
2118 if (netif_queue_stopped(netdev
) && netif_carrier_ok(netdev
)) {
2119 if (qlcnic_tx_avail(tx_ring
) > TX_STOP_THRESH
) {
2120 netif_wake_queue(netdev
);
2121 adapter
->stats
.xmit_on
++;
2124 adapter
->tx_timeo_cnt
= 0;
2127 * If everything is freed up to consumer then check if the ring is full
2128 * If the ring is full then check if more needs to be freed and
2129 * schedule the call back again.
2131 * This happens when there are 2 CPUs. One could be freeing and the
2132 * other filling it. If the ring is full when we get out of here and
2133 * the card has already interrupted the host then the host can miss the
2136 * There is still a possible race condition and the host could miss an
2137 * interrupt. The card has to take care of this.
2139 hw_consumer
= le32_to_cpu(*(tx_ring
->hw_consumer
));
2140 done
= (sw_consumer
== hw_consumer
);
2141 spin_unlock(&adapter
->tx_clean_lock
);
2146 static int qlcnic_poll(struct napi_struct
*napi
, int budget
)
2148 struct qlcnic_host_sds_ring
*sds_ring
=
2149 container_of(napi
, struct qlcnic_host_sds_ring
, napi
);
2151 struct qlcnic_adapter
*adapter
= sds_ring
->adapter
;
2156 tx_complete
= qlcnic_process_cmd_ring(adapter
);
2158 work_done
= qlcnic_process_rcv_ring(sds_ring
, budget
);
2160 if ((work_done
< budget
) && tx_complete
) {
2161 napi_complete(&sds_ring
->napi
);
2162 if (test_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
2163 qlcnic_enable_int(sds_ring
);
2169 static int qlcnic_rx_poll(struct napi_struct
*napi
, int budget
)
2171 struct qlcnic_host_sds_ring
*sds_ring
=
2172 container_of(napi
, struct qlcnic_host_sds_ring
, napi
);
2174 struct qlcnic_adapter
*adapter
= sds_ring
->adapter
;
2177 work_done
= qlcnic_process_rcv_ring(sds_ring
, budget
);
2179 if (work_done
< budget
) {
2180 napi_complete(&sds_ring
->napi
);
2181 if (test_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
2182 qlcnic_enable_int(sds_ring
);
2188 #ifdef CONFIG_NET_POLL_CONTROLLER
2189 static void qlcnic_poll_controller(struct net_device
*netdev
)
2192 struct qlcnic_host_sds_ring
*sds_ring
;
2193 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
2194 struct qlcnic_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
2196 disable_irq(adapter
->irq
);
2197 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
2198 sds_ring
= &recv_ctx
->sds_rings
[ring
];
2199 qlcnic_intr(adapter
->irq
, sds_ring
);
2201 enable_irq(adapter
->irq
);
2206 qlcnic_idc_debug_info(struct qlcnic_adapter
*adapter
, u8 encoding
)
2210 val
= adapter
->portnum
& 0xf;
2211 val
|= encoding
<< 7;
2212 val
|= (jiffies
- adapter
->dev_rst_time
) << 8;
2214 QLCWR32(adapter
, QLCNIC_CRB_DRV_SCRATCH
, val
);
2215 adapter
->dev_rst_time
= jiffies
;
2219 qlcnic_set_drv_state(struct qlcnic_adapter
*adapter
, u8 state
)
2223 WARN_ON(state
!= QLCNIC_DEV_NEED_RESET
&&
2224 state
!= QLCNIC_DEV_NEED_QUISCENT
);
2226 if (qlcnic_api_lock(adapter
))
2229 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_STATE
);
2231 if (state
== QLCNIC_DEV_NEED_RESET
)
2232 QLC_DEV_SET_RST_RDY(val
, adapter
->portnum
);
2233 else if (state
== QLCNIC_DEV_NEED_QUISCENT
)
2234 QLC_DEV_SET_QSCNT_RDY(val
, adapter
->portnum
);
2236 QLCWR32(adapter
, QLCNIC_CRB_DRV_STATE
, val
);
2238 qlcnic_api_unlock(adapter
);
2244 qlcnic_clr_drv_state(struct qlcnic_adapter
*adapter
)
2248 if (qlcnic_api_lock(adapter
))
2251 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_STATE
);
2252 QLC_DEV_CLR_RST_QSCNT(val
, adapter
->portnum
);
2253 QLCWR32(adapter
, QLCNIC_CRB_DRV_STATE
, val
);
2255 qlcnic_api_unlock(adapter
);
2261 qlcnic_clr_all_drv_state(struct qlcnic_adapter
*adapter
)
2265 if (qlcnic_api_lock(adapter
))
2268 val
= QLCRD32(adapter
, QLCNIC_CRB_DEV_REF_COUNT
);
2269 QLC_DEV_CLR_REF_CNT(val
, adapter
->portnum
);
2270 QLCWR32(adapter
, QLCNIC_CRB_DEV_REF_COUNT
, val
);
2272 if (!(val
& 0x11111111))
2273 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
, QLCNIC_DEV_COLD
);
2275 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_STATE
);
2276 QLC_DEV_CLR_RST_QSCNT(val
, adapter
->portnum
);
2277 QLCWR32(adapter
, QLCNIC_CRB_DRV_STATE
, val
);
2279 qlcnic_api_unlock(adapter
);
2281 adapter
->fw_fail_cnt
= 0;
2282 clear_bit(__QLCNIC_START_FW
, &adapter
->state
);
2283 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
2286 /* Grab api lock, before checking state */
2288 qlcnic_check_drv_state(struct qlcnic_adapter
*adapter
)
2292 state
= QLCRD32(adapter
, QLCNIC_CRB_DRV_STATE
);
2293 act
= QLCRD32(adapter
, QLCNIC_CRB_DEV_REF_COUNT
);
2295 if (((state
& 0x11111111) == (act
& 0x11111111)) ||
2296 ((act
& 0x11111111) == ((state
>> 1) & 0x11111111)))
2302 static int qlcnic_check_idc_ver(struct qlcnic_adapter
*adapter
)
2304 u32 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_IDC_VER
);
2306 if (val
!= QLCNIC_DRV_IDC_VER
) {
2307 dev_warn(&adapter
->pdev
->dev
, "IDC Version mismatch, driver's"
2308 " idc ver = %x; reqd = %x\n", QLCNIC_DRV_IDC_VER
, val
);
2315 qlcnic_can_start_firmware(struct qlcnic_adapter
*adapter
)
2317 u32 val
, prev_state
;
2318 u8 dev_init_timeo
= adapter
->dev_init_timeo
;
2319 u8 portnum
= adapter
->portnum
;
2322 if (test_and_clear_bit(__QLCNIC_START_FW
, &adapter
->state
))
2325 if (qlcnic_api_lock(adapter
))
2328 val
= QLCRD32(adapter
, QLCNIC_CRB_DEV_REF_COUNT
);
2329 if (!(val
& (1 << (portnum
* 4)))) {
2330 QLC_DEV_SET_REF_CNT(val
, portnum
);
2331 QLCWR32(adapter
, QLCNIC_CRB_DEV_REF_COUNT
, val
);
2334 prev_state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
);
2335 QLCDB(adapter
, HW
, "Device state = %u\n", prev_state
);
2337 switch (prev_state
) {
2338 case QLCNIC_DEV_COLD
:
2339 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
, QLCNIC_DEV_INITIALIZING
);
2340 QLCWR32(adapter
, QLCNIC_CRB_DRV_IDC_VER
, QLCNIC_DRV_IDC_VER
);
2341 qlcnic_idc_debug_info(adapter
, 0);
2342 qlcnic_api_unlock(adapter
);
2345 case QLCNIC_DEV_READY
:
2346 ret
= qlcnic_check_idc_ver(adapter
);
2347 qlcnic_api_unlock(adapter
);
2350 case QLCNIC_DEV_NEED_RESET
:
2351 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_STATE
);
2352 QLC_DEV_SET_RST_RDY(val
, portnum
);
2353 QLCWR32(adapter
, QLCNIC_CRB_DRV_STATE
, val
);
2356 case QLCNIC_DEV_NEED_QUISCENT
:
2357 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_STATE
);
2358 QLC_DEV_SET_QSCNT_RDY(val
, portnum
);
2359 QLCWR32(adapter
, QLCNIC_CRB_DRV_STATE
, val
);
2362 case QLCNIC_DEV_FAILED
:
2363 dev_err(&adapter
->pdev
->dev
, "Device in failed state.\n");
2364 qlcnic_api_unlock(adapter
);
2367 case QLCNIC_DEV_INITIALIZING
:
2368 case QLCNIC_DEV_QUISCENT
:
2372 qlcnic_api_unlock(adapter
);
2376 prev_state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
);
2378 if (prev_state
== QLCNIC_DEV_QUISCENT
)
2380 } while ((prev_state
!= QLCNIC_DEV_READY
) && --dev_init_timeo
);
2382 if (!dev_init_timeo
) {
2383 dev_err(&adapter
->pdev
->dev
,
2384 "Waiting for device to initialize timeout\n");
2388 if (qlcnic_api_lock(adapter
))
2391 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_STATE
);
2392 QLC_DEV_CLR_RST_QSCNT(val
, portnum
);
2393 QLCWR32(adapter
, QLCNIC_CRB_DRV_STATE
, val
);
2395 ret
= qlcnic_check_idc_ver(adapter
);
2396 qlcnic_api_unlock(adapter
);
2402 qlcnic_fwinit_work(struct work_struct
*work
)
2404 struct qlcnic_adapter
*adapter
= container_of(work
,
2405 struct qlcnic_adapter
, fw_work
.work
);
2406 u32 dev_state
= 0xf, npar_state
;
2408 if (qlcnic_api_lock(adapter
))
2411 dev_state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
);
2412 if (dev_state
== QLCNIC_DEV_QUISCENT
) {
2413 qlcnic_api_unlock(adapter
);
2414 qlcnic_schedule_work(adapter
, qlcnic_fwinit_work
,
2419 if (adapter
->op_mode
== QLCNIC_NON_PRIV_FUNC
) {
2420 npar_state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_NPAR_STATE
);
2421 if (npar_state
== QLCNIC_DEV_NPAR_RDY
) {
2422 qlcnic_api_unlock(adapter
);
2425 qlcnic_schedule_work(adapter
, qlcnic_fwinit_work
,
2427 qlcnic_api_unlock(adapter
);
2432 if (adapter
->fw_wait_cnt
++ > adapter
->reset_ack_timeo
) {
2433 dev_err(&adapter
->pdev
->dev
, "Reset:Failed to get ack %d sec\n",
2434 adapter
->reset_ack_timeo
);
2435 goto skip_ack_check
;
2438 if (!qlcnic_check_drv_state(adapter
)) {
2440 dev_state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
);
2442 if (dev_state
== QLCNIC_DEV_NEED_QUISCENT
) {
2443 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
,
2444 QLCNIC_DEV_QUISCENT
);
2445 qlcnic_schedule_work(adapter
, qlcnic_fwinit_work
,
2447 QLCDB(adapter
, DRV
, "Quiscing the driver\n");
2448 qlcnic_idc_debug_info(adapter
, 0);
2450 qlcnic_api_unlock(adapter
);
2454 if (dev_state
== QLCNIC_DEV_NEED_RESET
) {
2455 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
,
2456 QLCNIC_DEV_INITIALIZING
);
2457 set_bit(__QLCNIC_START_FW
, &adapter
->state
);
2458 QLCDB(adapter
, DRV
, "Restarting fw\n");
2459 qlcnic_idc_debug_info(adapter
, 0);
2462 qlcnic_api_unlock(adapter
);
2464 if (!adapter
->nic_ops
->start_firmware(adapter
)) {
2465 qlcnic_schedule_work(adapter
, qlcnic_attach_work
, 0);
2471 qlcnic_api_unlock(adapter
);
2474 dev_state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
);
2475 QLCDB(adapter
, HW
, "Func waiting: Device state=%u\n", dev_state
);
2477 switch (dev_state
) {
2478 case QLCNIC_DEV_QUISCENT
:
2479 case QLCNIC_DEV_NEED_QUISCENT
:
2480 case QLCNIC_DEV_NEED_RESET
:
2481 qlcnic_schedule_work(adapter
,
2482 qlcnic_fwinit_work
, FW_POLL_DELAY
);
2484 case QLCNIC_DEV_FAILED
:
2488 if (!adapter
->nic_ops
->start_firmware(adapter
)) {
2489 qlcnic_schedule_work(adapter
, qlcnic_attach_work
, 0);
2495 dev_err(&adapter
->pdev
->dev
, "Fwinit work failed state=%u "
2496 "fw_wait_cnt=%u\n", dev_state
, adapter
->fw_wait_cnt
);
2497 netif_device_attach(adapter
->netdev
);
2498 qlcnic_clr_all_drv_state(adapter
);
2502 qlcnic_detach_work(struct work_struct
*work
)
2504 struct qlcnic_adapter
*adapter
= container_of(work
,
2505 struct qlcnic_adapter
, fw_work
.work
);
2506 struct net_device
*netdev
= adapter
->netdev
;
2509 netif_device_detach(netdev
);
2511 qlcnic_down(adapter
, netdev
);
2513 status
= QLCRD32(adapter
, QLCNIC_PEG_HALT_STATUS1
);
2515 if (status
& QLCNIC_RCODE_FATAL_ERROR
)
2518 if (adapter
->temp
== QLCNIC_TEMP_PANIC
)
2521 if (qlcnic_set_drv_state(adapter
, adapter
->dev_state
))
2524 adapter
->fw_wait_cnt
= 0;
2526 qlcnic_schedule_work(adapter
, qlcnic_fwinit_work
, FW_POLL_DELAY
);
2531 dev_err(&adapter
->pdev
->dev
, "detach failed; status=%d temp=%d\n",
2532 status
, adapter
->temp
);
2533 netif_device_attach(netdev
);
2534 qlcnic_clr_all_drv_state(adapter
);
2538 /*Transit to RESET state from READY state only */
2540 qlcnic_dev_request_reset(struct qlcnic_adapter
*adapter
)
2544 adapter
->need_fw_reset
= 1;
2545 if (qlcnic_api_lock(adapter
))
2548 state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
);
2550 if (state
== QLCNIC_DEV_READY
) {
2551 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
, QLCNIC_DEV_NEED_RESET
);
2552 QLCDB(adapter
, DRV
, "NEED_RESET state set\n");
2553 qlcnic_idc_debug_info(adapter
, 0);
2556 qlcnic_api_unlock(adapter
);
2559 /* Transit to NPAR READY state from NPAR NOT READY state */
2561 qlcnic_dev_set_npar_ready(struct qlcnic_adapter
*adapter
)
2565 if (!(adapter
->flags
& QLCNIC_ESWITCH_ENABLED
) ||
2566 adapter
->op_mode
== QLCNIC_NON_PRIV_FUNC
)
2568 if (qlcnic_api_lock(adapter
))
2571 state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_NPAR_STATE
);
2573 if (state
!= QLCNIC_DEV_NPAR_RDY
) {
2574 QLCWR32(adapter
, QLCNIC_CRB_DEV_NPAR_STATE
,
2575 QLCNIC_DEV_NPAR_RDY
);
2576 QLCDB(adapter
, DRV
, "NPAR READY state set\n");
2579 qlcnic_api_unlock(adapter
);
2583 qlcnic_schedule_work(struct qlcnic_adapter
*adapter
,
2584 work_func_t func
, int delay
)
2586 if (test_bit(__QLCNIC_AER
, &adapter
->state
))
2589 INIT_DELAYED_WORK(&adapter
->fw_work
, func
);
2590 schedule_delayed_work(&adapter
->fw_work
, round_jiffies_relative(delay
));
2594 qlcnic_cancel_fw_work(struct qlcnic_adapter
*adapter
)
2596 while (test_and_set_bit(__QLCNIC_RESETTING
, &adapter
->state
))
2599 cancel_delayed_work_sync(&adapter
->fw_work
);
2603 qlcnic_attach_work(struct work_struct
*work
)
2605 struct qlcnic_adapter
*adapter
= container_of(work
,
2606 struct qlcnic_adapter
, fw_work
.work
);
2607 struct net_device
*netdev
= adapter
->netdev
;
2609 if (netif_running(netdev
)) {
2610 if (qlcnic_up(adapter
, netdev
))
2613 qlcnic_config_indev_addr(netdev
, NETDEV_UP
);
2617 netif_device_attach(netdev
);
2618 adapter
->fw_fail_cnt
= 0;
2619 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
2621 if (!qlcnic_clr_drv_state(adapter
))
2622 qlcnic_schedule_work(adapter
, qlcnic_fw_poll_work
,
2627 qlcnic_check_health(struct qlcnic_adapter
*adapter
)
2629 u32 state
= 0, heartbit
;
2630 struct net_device
*netdev
= adapter
->netdev
;
2632 if (qlcnic_check_temp(adapter
))
2635 if (adapter
->need_fw_reset
)
2636 qlcnic_dev_request_reset(adapter
);
2638 state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
);
2639 if (state
== QLCNIC_DEV_NEED_RESET
|| state
== QLCNIC_DEV_NEED_QUISCENT
)
2640 adapter
->need_fw_reset
= 1;
2642 heartbit
= QLCRD32(adapter
, QLCNIC_PEG_ALIVE_COUNTER
);
2643 if (heartbit
!= adapter
->heartbit
) {
2644 adapter
->heartbit
= heartbit
;
2645 adapter
->fw_fail_cnt
= 0;
2646 if (adapter
->need_fw_reset
)
2649 if (adapter
->reset_context
&&
2650 auto_fw_reset
== AUTO_FW_RESET_ENABLED
) {
2651 qlcnic_reset_hw_context(adapter
);
2652 adapter
->netdev
->trans_start
= jiffies
;
2658 if (++adapter
->fw_fail_cnt
< FW_FAIL_THRESH
)
2661 qlcnic_dev_request_reset(adapter
);
2663 if ((auto_fw_reset
== AUTO_FW_RESET_ENABLED
))
2664 clear_bit(__QLCNIC_FW_ATTACHED
, &adapter
->state
);
2666 dev_info(&netdev
->dev
, "firmware hang detected\n");
2669 adapter
->dev_state
= (state
== QLCNIC_DEV_NEED_QUISCENT
) ? state
:
2670 QLCNIC_DEV_NEED_RESET
;
2672 if ((auto_fw_reset
== AUTO_FW_RESET_ENABLED
) &&
2673 !test_and_set_bit(__QLCNIC_RESETTING
, &adapter
->state
)) {
2675 qlcnic_schedule_work(adapter
, qlcnic_detach_work
, 0);
2676 QLCDB(adapter
, DRV
, "fw recovery scheduled.\n");
2683 qlcnic_fw_poll_work(struct work_struct
*work
)
2685 struct qlcnic_adapter
*adapter
= container_of(work
,
2686 struct qlcnic_adapter
, fw_work
.work
);
2688 if (test_bit(__QLCNIC_RESETTING
, &adapter
->state
))
2692 if (qlcnic_check_health(adapter
))
2696 qlcnic_schedule_work(adapter
, qlcnic_fw_poll_work
, FW_POLL_DELAY
);
2699 static int qlcnic_is_first_func(struct pci_dev
*pdev
)
2701 struct pci_dev
*oth_pdev
;
2702 int val
= pdev
->devfn
;
2705 oth_pdev
= pci_get_domain_bus_and_slot(pci_domain_nr
2706 (pdev
->bus
), pdev
->bus
->number
,
2707 PCI_DEVFN(PCI_SLOT(pdev
->devfn
), val
));
2711 if (oth_pdev
->current_state
!= PCI_D3cold
) {
2712 pci_dev_put(oth_pdev
);
2715 pci_dev_put(oth_pdev
);
2720 static int qlcnic_attach_func(struct pci_dev
*pdev
)
2722 int err
, first_func
;
2723 struct qlcnic_adapter
*adapter
= pci_get_drvdata(pdev
);
2724 struct net_device
*netdev
= adapter
->netdev
;
2726 pdev
->error_state
= pci_channel_io_normal
;
2728 err
= pci_enable_device(pdev
);
2732 pci_set_power_state(pdev
, PCI_D0
);
2733 pci_set_master(pdev
);
2734 pci_restore_state(pdev
);
2736 first_func
= qlcnic_is_first_func(pdev
);
2738 if (qlcnic_api_lock(adapter
))
2742 adapter
->need_fw_reset
= 1;
2743 set_bit(__QLCNIC_START_FW
, &adapter
->state
);
2744 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
, QLCNIC_DEV_INITIALIZING
);
2745 QLCDB(adapter
, DRV
, "Restarting fw\n");
2747 qlcnic_api_unlock(adapter
);
2749 err
= adapter
->nic_ops
->start_firmware(adapter
);
2753 qlcnic_clr_drv_state(adapter
);
2754 qlcnic_setup_intr(adapter
);
2756 if (netif_running(netdev
)) {
2757 err
= qlcnic_attach(adapter
);
2759 qlcnic_clr_all_drv_state(adapter
);
2760 clear_bit(__QLCNIC_AER
, &adapter
->state
);
2761 netif_device_attach(netdev
);
2765 err
= qlcnic_up(adapter
, netdev
);
2769 qlcnic_config_indev_addr(netdev
, NETDEV_UP
);
2772 netif_device_attach(netdev
);
2776 static pci_ers_result_t
qlcnic_io_error_detected(struct pci_dev
*pdev
,
2777 pci_channel_state_t state
)
2779 struct qlcnic_adapter
*adapter
= pci_get_drvdata(pdev
);
2780 struct net_device
*netdev
= adapter
->netdev
;
2782 if (state
== pci_channel_io_perm_failure
)
2783 return PCI_ERS_RESULT_DISCONNECT
;
2785 if (state
== pci_channel_io_normal
)
2786 return PCI_ERS_RESULT_RECOVERED
;
2788 set_bit(__QLCNIC_AER
, &adapter
->state
);
2789 netif_device_detach(netdev
);
2791 cancel_delayed_work_sync(&adapter
->fw_work
);
2793 if (netif_running(netdev
))
2794 qlcnic_down(adapter
, netdev
);
2796 qlcnic_detach(adapter
);
2797 qlcnic_teardown_intr(adapter
);
2799 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
2801 pci_save_state(pdev
);
2802 pci_disable_device(pdev
);
2804 return PCI_ERS_RESULT_NEED_RESET
;
2807 static pci_ers_result_t
qlcnic_io_slot_reset(struct pci_dev
*pdev
)
2809 return qlcnic_attach_func(pdev
) ? PCI_ERS_RESULT_DISCONNECT
:
2810 PCI_ERS_RESULT_RECOVERED
;
2813 static void qlcnic_io_resume(struct pci_dev
*pdev
)
2815 struct qlcnic_adapter
*adapter
= pci_get_drvdata(pdev
);
2817 pci_cleanup_aer_uncorrect_error_status(pdev
);
2819 if (QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
) == QLCNIC_DEV_READY
&&
2820 test_and_clear_bit(__QLCNIC_AER
, &adapter
->state
))
2821 qlcnic_schedule_work(adapter
, qlcnic_fw_poll_work
,
2827 qlcnicvf_start_firmware(struct qlcnic_adapter
*adapter
)
2831 err
= qlcnic_can_start_firmware(adapter
);
2835 qlcnic_check_options(adapter
);
2837 adapter
->need_fw_reset
= 0;
2843 qlcnicvf_config_bridged_mode(struct qlcnic_adapter
*adapter
, u32 enable
)
2849 qlcnicvf_config_led(struct qlcnic_adapter
*adapter
, u32 state
, u32 rate
)
2855 qlcnic_store_bridged_mode(struct device
*dev
,
2856 struct device_attribute
*attr
, const char *buf
, size_t len
)
2858 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
2862 if (!(adapter
->capabilities
& QLCNIC_FW_CAPABILITY_BDG
))
2865 if (!test_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
2868 if (strict_strtoul(buf
, 2, &new))
2871 if (!adapter
->nic_ops
->config_bridged_mode(adapter
, !!new))
2879 qlcnic_show_bridged_mode(struct device
*dev
,
2880 struct device_attribute
*attr
, char *buf
)
2882 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
2883 int bridged_mode
= 0;
2885 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_BDG
)
2886 bridged_mode
= !!(adapter
->flags
& QLCNIC_BRIDGE_ENABLED
);
2888 return sprintf(buf
, "%d\n", bridged_mode
);
2891 static struct device_attribute dev_attr_bridged_mode
= {
2892 .attr
= {.name
= "bridged_mode", .mode
= (S_IRUGO
| S_IWUSR
)},
2893 .show
= qlcnic_show_bridged_mode
,
2894 .store
= qlcnic_store_bridged_mode
,
2898 qlcnic_store_diag_mode(struct device
*dev
,
2899 struct device_attribute
*attr
, const char *buf
, size_t len
)
2901 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
2904 if (strict_strtoul(buf
, 2, &new))
2907 if (!!new != !!(adapter
->flags
& QLCNIC_DIAG_ENABLED
))
2908 adapter
->flags
^= QLCNIC_DIAG_ENABLED
;
2914 qlcnic_show_diag_mode(struct device
*dev
,
2915 struct device_attribute
*attr
, char *buf
)
2917 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
2919 return sprintf(buf
, "%d\n",
2920 !!(adapter
->flags
& QLCNIC_DIAG_ENABLED
));
2923 static struct device_attribute dev_attr_diag_mode
= {
2924 .attr
= {.name
= "diag_mode", .mode
= (S_IRUGO
| S_IWUSR
)},
2925 .show
= qlcnic_show_diag_mode
,
2926 .store
= qlcnic_store_diag_mode
,
2930 qlcnic_sysfs_validate_crb(struct qlcnic_adapter
*adapter
,
2931 loff_t offset
, size_t size
)
2933 size_t crb_size
= 4;
2935 if (!(adapter
->flags
& QLCNIC_DIAG_ENABLED
))
2938 if (offset
< QLCNIC_PCI_CRBSPACE
) {
2939 if (ADDR_IN_RANGE(offset
, QLCNIC_PCI_CAMQM
,
2940 QLCNIC_PCI_CAMQM_END
))
2946 if ((size
!= crb_size
) || (offset
& (crb_size
-1)))
2953 qlcnic_sysfs_read_crb(struct file
*filp
, struct kobject
*kobj
,
2954 struct bin_attribute
*attr
,
2955 char *buf
, loff_t offset
, size_t size
)
2957 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
2958 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
2963 ret
= qlcnic_sysfs_validate_crb(adapter
, offset
, size
);
2967 if (ADDR_IN_RANGE(offset
, QLCNIC_PCI_CAMQM
, QLCNIC_PCI_CAMQM_END
)) {
2968 qlcnic_pci_camqm_read_2M(adapter
, offset
, &qmdata
);
2969 memcpy(buf
, &qmdata
, size
);
2971 data
= QLCRD32(adapter
, offset
);
2972 memcpy(buf
, &data
, size
);
2978 qlcnic_sysfs_write_crb(struct file
*filp
, struct kobject
*kobj
,
2979 struct bin_attribute
*attr
,
2980 char *buf
, loff_t offset
, size_t size
)
2982 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
2983 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
2988 ret
= qlcnic_sysfs_validate_crb(adapter
, offset
, size
);
2992 if (ADDR_IN_RANGE(offset
, QLCNIC_PCI_CAMQM
, QLCNIC_PCI_CAMQM_END
)) {
2993 memcpy(&qmdata
, buf
, size
);
2994 qlcnic_pci_camqm_write_2M(adapter
, offset
, qmdata
);
2996 memcpy(&data
, buf
, size
);
2997 QLCWR32(adapter
, offset
, data
);
3003 qlcnic_sysfs_validate_mem(struct qlcnic_adapter
*adapter
,
3004 loff_t offset
, size_t size
)
3006 if (!(adapter
->flags
& QLCNIC_DIAG_ENABLED
))
3009 if ((size
!= 8) || (offset
& 0x7))
3016 qlcnic_sysfs_read_mem(struct file
*filp
, struct kobject
*kobj
,
3017 struct bin_attribute
*attr
,
3018 char *buf
, loff_t offset
, size_t size
)
3020 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3021 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3025 ret
= qlcnic_sysfs_validate_mem(adapter
, offset
, size
);
3029 if (qlcnic_pci_mem_read_2M(adapter
, offset
, &data
))
3032 memcpy(buf
, &data
, size
);
3038 qlcnic_sysfs_write_mem(struct file
*filp
, struct kobject
*kobj
,
3039 struct bin_attribute
*attr
,
3040 char *buf
, loff_t offset
, size_t size
)
3042 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3043 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3047 ret
= qlcnic_sysfs_validate_mem(adapter
, offset
, size
);
3051 memcpy(&data
, buf
, size
);
3053 if (qlcnic_pci_mem_write_2M(adapter
, offset
, data
))
3060 static struct bin_attribute bin_attr_crb
= {
3061 .attr
= {.name
= "crb", .mode
= (S_IRUGO
| S_IWUSR
)},
3063 .read
= qlcnic_sysfs_read_crb
,
3064 .write
= qlcnic_sysfs_write_crb
,
3067 static struct bin_attribute bin_attr_mem
= {
3068 .attr
= {.name
= "mem", .mode
= (S_IRUGO
| S_IWUSR
)},
3070 .read
= qlcnic_sysfs_read_mem
,
3071 .write
= qlcnic_sysfs_write_mem
,
3075 validate_pm_config(struct qlcnic_adapter
*adapter
,
3076 struct qlcnic_pm_func_cfg
*pm_cfg
, int count
)
3079 u8 src_pci_func
, s_esw_id
, d_esw_id
;
3083 for (i
= 0; i
< count
; i
++) {
3084 src_pci_func
= pm_cfg
[i
].pci_func
;
3085 dest_pci_func
= pm_cfg
[i
].dest_npar
;
3086 if (src_pci_func
>= QLCNIC_MAX_PCI_FUNC
3087 || dest_pci_func
>= QLCNIC_MAX_PCI_FUNC
)
3088 return QL_STATUS_INVALID_PARAM
;
3090 if (adapter
->npars
[src_pci_func
].type
!= QLCNIC_TYPE_NIC
)
3091 return QL_STATUS_INVALID_PARAM
;
3093 if (adapter
->npars
[dest_pci_func
].type
!= QLCNIC_TYPE_NIC
)
3094 return QL_STATUS_INVALID_PARAM
;
3096 if (!IS_VALID_MODE(pm_cfg
[i
].action
))
3097 return QL_STATUS_INVALID_PARAM
;
3099 s_esw_id
= adapter
->npars
[src_pci_func
].phy_port
;
3100 d_esw_id
= adapter
->npars
[dest_pci_func
].phy_port
;
3102 if (s_esw_id
!= d_esw_id
)
3103 return QL_STATUS_INVALID_PARAM
;
3111 qlcnic_sysfs_write_pm_config(struct file
*filp
, struct kobject
*kobj
,
3112 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3114 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3115 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3116 struct qlcnic_pm_func_cfg
*pm_cfg
;
3117 u32 id
, action
, pci_func
;
3118 int count
, rem
, i
, ret
;
3120 count
= size
/ sizeof(struct qlcnic_pm_func_cfg
);
3121 rem
= size
% sizeof(struct qlcnic_pm_func_cfg
);
3123 return QL_STATUS_INVALID_PARAM
;
3125 pm_cfg
= (struct qlcnic_pm_func_cfg
*) buf
;
3127 ret
= validate_pm_config(adapter
, pm_cfg
, count
);
3130 for (i
= 0; i
< count
; i
++) {
3131 pci_func
= pm_cfg
[i
].pci_func
;
3132 action
= pm_cfg
[i
].action
;
3133 id
= adapter
->npars
[pci_func
].phy_port
;
3134 ret
= qlcnic_config_port_mirroring(adapter
, id
,
3140 for (i
= 0; i
< count
; i
++) {
3141 pci_func
= pm_cfg
[i
].pci_func
;
3142 id
= adapter
->npars
[pci_func
].phy_port
;
3143 adapter
->npars
[pci_func
].enable_pm
= pm_cfg
[i
].action
;
3144 adapter
->npars
[pci_func
].dest_npar
= id
;
3150 qlcnic_sysfs_read_pm_config(struct file
*filp
, struct kobject
*kobj
,
3151 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3153 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3154 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3155 struct qlcnic_pm_func_cfg pm_cfg
[QLCNIC_MAX_PCI_FUNC
];
3158 if (size
!= sizeof(pm_cfg
))
3159 return QL_STATUS_INVALID_PARAM
;
3161 for (i
= 0; i
< QLCNIC_MAX_PCI_FUNC
; i
++) {
3162 if (adapter
->npars
[i
].type
!= QLCNIC_TYPE_NIC
)
3164 pm_cfg
[i
].action
= adapter
->npars
[i
].enable_pm
;
3165 pm_cfg
[i
].dest_npar
= 0;
3166 pm_cfg
[i
].pci_func
= i
;
3168 memcpy(buf
, &pm_cfg
, size
);
3174 validate_esw_config(struct qlcnic_adapter
*adapter
,
3175 struct qlcnic_esw_func_cfg
*esw_cfg
, int count
)
3180 for (i
= 0; i
< count
; i
++) {
3181 pci_func
= esw_cfg
[i
].pci_func
;
3182 if (pci_func
>= QLCNIC_MAX_PCI_FUNC
)
3183 return QL_STATUS_INVALID_PARAM
;
3185 if (adapter
->npars
[i
].type
!= QLCNIC_TYPE_NIC
)
3186 return QL_STATUS_INVALID_PARAM
;
3188 if (esw_cfg
->host_vlan_tag
== 1)
3189 if (!IS_VALID_VLAN(esw_cfg
[i
].vlan_id
))
3190 return QL_STATUS_INVALID_PARAM
;
3192 if (!IS_VALID_MODE(esw_cfg
[i
].promisc_mode
)
3193 || !IS_VALID_MODE(esw_cfg
[i
].host_vlan_tag
)
3194 || !IS_VALID_MODE(esw_cfg
[i
].mac_learning
)
3195 || !IS_VALID_MODE(esw_cfg
[i
].discard_tagged
))
3196 return QL_STATUS_INVALID_PARAM
;
3203 qlcnic_sysfs_write_esw_config(struct file
*file
, struct kobject
*kobj
,
3204 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3206 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3207 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3208 struct qlcnic_esw_func_cfg
*esw_cfg
;
3209 int count
, rem
, i
, ret
;
3212 count
= size
/ sizeof(struct qlcnic_esw_func_cfg
);
3213 rem
= size
% sizeof(struct qlcnic_esw_func_cfg
);
3215 return QL_STATUS_INVALID_PARAM
;
3217 esw_cfg
= (struct qlcnic_esw_func_cfg
*) buf
;
3218 ret
= validate_esw_config(adapter
, esw_cfg
, count
);
3222 for (i
= 0; i
< count
; i
++) {
3223 pci_func
= esw_cfg
[i
].pci_func
;
3224 id
= adapter
->npars
[pci_func
].phy_port
;
3225 ret
= qlcnic_config_switch_port(adapter
, id
,
3226 esw_cfg
[i
].host_vlan_tag
,
3227 esw_cfg
[i
].discard_tagged
,
3228 esw_cfg
[i
].promisc_mode
,
3229 esw_cfg
[i
].mac_learning
,
3230 esw_cfg
[i
].pci_func
,
3231 esw_cfg
[i
].vlan_id
);
3236 for (i
= 0; i
< count
; i
++) {
3237 pci_func
= esw_cfg
[i
].pci_func
;
3238 adapter
->npars
[pci_func
].promisc_mode
= esw_cfg
[i
].promisc_mode
;
3239 adapter
->npars
[pci_func
].mac_learning
= esw_cfg
[i
].mac_learning
;
3240 adapter
->npars
[pci_func
].vlan_id
= esw_cfg
[i
].vlan_id
;
3241 adapter
->npars
[pci_func
].discard_tagged
=
3242 esw_cfg
[i
].discard_tagged
;
3243 adapter
->npars
[pci_func
].host_vlan_tag
=
3244 esw_cfg
[i
].host_vlan_tag
;
3251 qlcnic_sysfs_read_esw_config(struct file
*file
, struct kobject
*kobj
,
3252 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3254 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3255 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3256 struct qlcnic_esw_func_cfg esw_cfg
[QLCNIC_MAX_PCI_FUNC
];
3259 if (size
!= sizeof(esw_cfg
))
3260 return QL_STATUS_INVALID_PARAM
;
3262 for (i
= 0; i
< QLCNIC_MAX_PCI_FUNC
; i
++) {
3263 if (adapter
->npars
[i
].type
!= QLCNIC_TYPE_NIC
)
3266 esw_cfg
[i
].host_vlan_tag
= adapter
->npars
[i
].host_vlan_tag
;
3267 esw_cfg
[i
].promisc_mode
= adapter
->npars
[i
].promisc_mode
;
3268 esw_cfg
[i
].discard_tagged
= adapter
->npars
[i
].discard_tagged
;
3269 esw_cfg
[i
].vlan_id
= adapter
->npars
[i
].vlan_id
;
3270 esw_cfg
[i
].mac_learning
= adapter
->npars
[i
].mac_learning
;
3272 memcpy(buf
, &esw_cfg
, size
);
3278 validate_npar_config(struct qlcnic_adapter
*adapter
,
3279 struct qlcnic_npar_func_cfg
*np_cfg
, int count
)
3283 for (i
= 0; i
< count
; i
++) {
3284 pci_func
= np_cfg
[i
].pci_func
;
3285 if (pci_func
>= QLCNIC_MAX_PCI_FUNC
)
3286 return QL_STATUS_INVALID_PARAM
;
3288 if (adapter
->npars
[pci_func
].type
!= QLCNIC_TYPE_NIC
)
3289 return QL_STATUS_INVALID_PARAM
;
3291 if (!IS_VALID_BW(np_cfg
[i
].min_bw
)
3292 || !IS_VALID_BW(np_cfg
[i
].max_bw
)
3293 || !IS_VALID_RX_QUEUES(np_cfg
[i
].max_rx_queues
)
3294 || !IS_VALID_TX_QUEUES(np_cfg
[i
].max_tx_queues
))
3295 return QL_STATUS_INVALID_PARAM
;
3301 qlcnic_sysfs_write_npar_config(struct file
*file
, struct kobject
*kobj
,
3302 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3304 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3305 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3306 struct qlcnic_info nic_info
;
3307 struct qlcnic_npar_func_cfg
*np_cfg
;
3308 int i
, count
, rem
, ret
;
3311 count
= size
/ sizeof(struct qlcnic_npar_func_cfg
);
3312 rem
= size
% sizeof(struct qlcnic_npar_func_cfg
);
3314 return QL_STATUS_INVALID_PARAM
;
3316 np_cfg
= (struct qlcnic_npar_func_cfg
*) buf
;
3317 ret
= validate_npar_config(adapter
, np_cfg
, count
);
3321 for (i
= 0; i
< count
; i
++) {
3322 pci_func
= np_cfg
[i
].pci_func
;
3323 ret
= qlcnic_get_nic_info(adapter
, &nic_info
, pci_func
);
3326 nic_info
.pci_func
= pci_func
;
3327 nic_info
.min_tx_bw
= np_cfg
[i
].min_bw
;
3328 nic_info
.max_tx_bw
= np_cfg
[i
].max_bw
;
3329 ret
= qlcnic_set_nic_info(adapter
, &nic_info
);
3332 adapter
->npars
[i
].min_bw
= nic_info
.min_tx_bw
;
3333 adapter
->npars
[i
].max_bw
= nic_info
.max_tx_bw
;
3340 qlcnic_sysfs_read_npar_config(struct file
*file
, struct kobject
*kobj
,
3341 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3343 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3344 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3345 struct qlcnic_info nic_info
;
3346 struct qlcnic_npar_func_cfg np_cfg
[QLCNIC_MAX_PCI_FUNC
];
3349 if (size
!= sizeof(np_cfg
))
3350 return QL_STATUS_INVALID_PARAM
;
3352 for (i
= 0; i
< QLCNIC_MAX_PCI_FUNC
; i
++) {
3353 if (adapter
->npars
[i
].type
!= QLCNIC_TYPE_NIC
)
3355 ret
= qlcnic_get_nic_info(adapter
, &nic_info
, i
);
3359 np_cfg
[i
].pci_func
= i
;
3360 np_cfg
[i
].op_mode
= nic_info
.op_mode
;
3361 np_cfg
[i
].port_num
= nic_info
.phys_port
;
3362 np_cfg
[i
].fw_capab
= nic_info
.capabilities
;
3363 np_cfg
[i
].min_bw
= nic_info
.min_tx_bw
;
3364 np_cfg
[i
].max_bw
= nic_info
.max_tx_bw
;
3365 np_cfg
[i
].max_tx_queues
= nic_info
.max_tx_ques
;
3366 np_cfg
[i
].max_rx_queues
= nic_info
.max_rx_ques
;
3368 memcpy(buf
, &np_cfg
, size
);
3373 qlcnic_sysfs_read_pci_config(struct file
*file
, struct kobject
*kobj
,
3374 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3376 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3377 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3378 struct qlcnic_pci_func_cfg pci_cfg
[QLCNIC_MAX_PCI_FUNC
];
3379 struct qlcnic_pci_info
*pci_info
;
3382 if (size
!= sizeof(pci_cfg
))
3383 return QL_STATUS_INVALID_PARAM
;
3385 pci_info
= kcalloc(QLCNIC_MAX_PCI_FUNC
, sizeof(*pci_info
), GFP_KERNEL
);
3389 ret
= qlcnic_get_pci_info(adapter
, pci_info
);
3395 for (i
= 0; i
< QLCNIC_MAX_PCI_FUNC
; i
++) {
3396 pci_cfg
[i
].pci_func
= pci_info
[i
].id
;
3397 pci_cfg
[i
].func_type
= pci_info
[i
].type
;
3398 pci_cfg
[i
].port_num
= pci_info
[i
].default_port
;
3399 pci_cfg
[i
].min_bw
= pci_info
[i
].tx_min_bw
;
3400 pci_cfg
[i
].max_bw
= pci_info
[i
].tx_max_bw
;
3401 memcpy(&pci_cfg
[i
].def_mac_addr
, &pci_info
[i
].mac
, ETH_ALEN
);
3403 memcpy(buf
, &pci_cfg
, size
);
3407 static struct bin_attribute bin_attr_npar_config
= {
3408 .attr
= {.name
= "npar_config", .mode
= (S_IRUGO
| S_IWUSR
)},
3410 .read
= qlcnic_sysfs_read_npar_config
,
3411 .write
= qlcnic_sysfs_write_npar_config
,
3414 static struct bin_attribute bin_attr_pci_config
= {
3415 .attr
= {.name
= "pci_config", .mode
= (S_IRUGO
| S_IWUSR
)},
3417 .read
= qlcnic_sysfs_read_pci_config
,
3421 static struct bin_attribute bin_attr_esw_config
= {
3422 .attr
= {.name
= "esw_config", .mode
= (S_IRUGO
| S_IWUSR
)},
3424 .read
= qlcnic_sysfs_read_esw_config
,
3425 .write
= qlcnic_sysfs_write_esw_config
,
3428 static struct bin_attribute bin_attr_pm_config
= {
3429 .attr
= {.name
= "pm_config", .mode
= (S_IRUGO
| S_IWUSR
)},
3431 .read
= qlcnic_sysfs_read_pm_config
,
3432 .write
= qlcnic_sysfs_write_pm_config
,
3436 qlcnic_create_sysfs_entries(struct qlcnic_adapter
*adapter
)
3438 struct device
*dev
= &adapter
->pdev
->dev
;
3440 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_BDG
)
3441 if (device_create_file(dev
, &dev_attr_bridged_mode
))
3443 "failed to create bridged_mode sysfs entry\n");
3447 qlcnic_remove_sysfs_entries(struct qlcnic_adapter
*adapter
)
3449 struct device
*dev
= &adapter
->pdev
->dev
;
3451 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_BDG
)
3452 device_remove_file(dev
, &dev_attr_bridged_mode
);
3456 qlcnic_create_diag_entries(struct qlcnic_adapter
*adapter
)
3458 struct device
*dev
= &adapter
->pdev
->dev
;
3460 if (adapter
->op_mode
== QLCNIC_NON_PRIV_FUNC
)
3462 if (device_create_file(dev
, &dev_attr_diag_mode
))
3463 dev_info(dev
, "failed to create diag_mode sysfs entry\n");
3464 if (device_create_bin_file(dev
, &bin_attr_crb
))
3465 dev_info(dev
, "failed to create crb sysfs entry\n");
3466 if (device_create_bin_file(dev
, &bin_attr_mem
))
3467 dev_info(dev
, "failed to create mem sysfs entry\n");
3468 if (!(adapter
->flags
& QLCNIC_ESWITCH_ENABLED
) ||
3469 adapter
->op_mode
!= QLCNIC_MGMT_FUNC
)
3471 if (device_create_bin_file(dev
, &bin_attr_pci_config
))
3472 dev_info(dev
, "failed to create pci config sysfs entry");
3473 if (device_create_bin_file(dev
, &bin_attr_npar_config
))
3474 dev_info(dev
, "failed to create npar config sysfs entry");
3475 if (device_create_bin_file(dev
, &bin_attr_esw_config
))
3476 dev_info(dev
, "failed to create esw config sysfs entry");
3477 if (device_create_bin_file(dev
, &bin_attr_pm_config
))
3478 dev_info(dev
, "failed to create pm config sysfs entry");
3483 qlcnic_remove_diag_entries(struct qlcnic_adapter
*adapter
)
3485 struct device
*dev
= &adapter
->pdev
->dev
;
3487 if (adapter
->op_mode
== QLCNIC_NON_PRIV_FUNC
)
3489 device_remove_file(dev
, &dev_attr_diag_mode
);
3490 device_remove_bin_file(dev
, &bin_attr_crb
);
3491 device_remove_bin_file(dev
, &bin_attr_mem
);
3492 if (!(adapter
->flags
& QLCNIC_ESWITCH_ENABLED
) ||
3493 adapter
->op_mode
!= QLCNIC_MGMT_FUNC
)
3495 device_remove_bin_file(dev
, &bin_attr_pci_config
);
3496 device_remove_bin_file(dev
, &bin_attr_npar_config
);
3497 device_remove_bin_file(dev
, &bin_attr_esw_config
);
3498 device_remove_bin_file(dev
, &bin_attr_pm_config
);
3503 #define is_qlcnic_netdev(dev) (dev->netdev_ops == &qlcnic_netdev_ops)
3506 qlcnic_config_indev_addr(struct net_device
*dev
, unsigned long event
)
3508 struct in_device
*indev
;
3509 struct qlcnic_adapter
*adapter
= netdev_priv(dev
);
3511 indev
= in_dev_get(dev
);
3518 qlcnic_config_ipaddr(adapter
,
3519 ifa
->ifa_address
, QLCNIC_IP_UP
);
3522 qlcnic_config_ipaddr(adapter
,
3523 ifa
->ifa_address
, QLCNIC_IP_DOWN
);
3528 } endfor_ifa(indev
);
3533 static int qlcnic_netdev_event(struct notifier_block
*this,
3534 unsigned long event
, void *ptr
)
3536 struct qlcnic_adapter
*adapter
;
3537 struct net_device
*dev
= (struct net_device
*)ptr
;
3543 if (dev
->priv_flags
& IFF_802_1Q_VLAN
) {
3544 dev
= vlan_dev_real_dev(dev
);
3548 if (!is_qlcnic_netdev(dev
))
3551 adapter
= netdev_priv(dev
);
3556 if (!test_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
3559 qlcnic_config_indev_addr(dev
, event
);
3565 qlcnic_inetaddr_event(struct notifier_block
*this,
3566 unsigned long event
, void *ptr
)
3568 struct qlcnic_adapter
*adapter
;
3569 struct net_device
*dev
;
3571 struct in_ifaddr
*ifa
= (struct in_ifaddr
*)ptr
;
3573 dev
= ifa
->ifa_dev
? ifa
->ifa_dev
->dev
: NULL
;
3576 if (dev
== NULL
|| !netif_running(dev
))
3579 if (dev
->priv_flags
& IFF_802_1Q_VLAN
) {
3580 dev
= vlan_dev_real_dev(dev
);
3584 if (!is_qlcnic_netdev(dev
))
3587 adapter
= netdev_priv(dev
);
3592 if (!test_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
3597 qlcnic_config_ipaddr(adapter
, ifa
->ifa_address
, QLCNIC_IP_UP
);
3600 qlcnic_config_ipaddr(adapter
, ifa
->ifa_address
, QLCNIC_IP_DOWN
);
3610 static struct notifier_block qlcnic_netdev_cb
= {
3611 .notifier_call
= qlcnic_netdev_event
,
3614 static struct notifier_block qlcnic_inetaddr_cb
= {
3615 .notifier_call
= qlcnic_inetaddr_event
,
3619 qlcnic_config_indev_addr(struct net_device
*dev
, unsigned long event
)
3622 static struct pci_error_handlers qlcnic_err_handler
= {
3623 .error_detected
= qlcnic_io_error_detected
,
3624 .slot_reset
= qlcnic_io_slot_reset
,
3625 .resume
= qlcnic_io_resume
,
3628 static struct pci_driver qlcnic_driver
= {
3629 .name
= qlcnic_driver_name
,
3630 .id_table
= qlcnic_pci_tbl
,
3631 .probe
= qlcnic_probe
,
3632 .remove
= __devexit_p(qlcnic_remove
),
3634 .suspend
= qlcnic_suspend
,
3635 .resume
= qlcnic_resume
,
3637 .shutdown
= qlcnic_shutdown
,
3638 .err_handler
= &qlcnic_err_handler
3642 static int __init
qlcnic_init_module(void)
3646 printk(KERN_INFO
"%s\n", qlcnic_driver_string
);
3649 register_netdevice_notifier(&qlcnic_netdev_cb
);
3650 register_inetaddr_notifier(&qlcnic_inetaddr_cb
);
3653 ret
= pci_register_driver(&qlcnic_driver
);
3656 unregister_inetaddr_notifier(&qlcnic_inetaddr_cb
);
3657 unregister_netdevice_notifier(&qlcnic_netdev_cb
);
3664 module_init(qlcnic_init_module
);
3666 static void __exit
qlcnic_exit_module(void)
3669 pci_unregister_driver(&qlcnic_driver
);
3672 unregister_inetaddr_notifier(&qlcnic_inetaddr_cb
);
3673 unregister_netdevice_notifier(&qlcnic_netdev_cb
);
3677 module_exit(qlcnic_exit_module
);