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
, u8
);
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 static void qlcnic_set_netdev_features(struct qlcnic_adapter
*,
114 struct qlcnic_esw_func_cfg
*);
115 /* PCI Device ID Table */
116 #define ENTRY(device) \
117 {PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, (device)), \
118 .class = PCI_CLASS_NETWORK_ETHERNET << 8, .class_mask = ~0}
120 #define PCI_DEVICE_ID_QLOGIC_QLE824X 0x8020
122 static DEFINE_PCI_DEVICE_TABLE(qlcnic_pci_tbl
) = {
123 ENTRY(PCI_DEVICE_ID_QLOGIC_QLE824X
),
127 MODULE_DEVICE_TABLE(pci
, qlcnic_pci_tbl
);
131 qlcnic_update_cmd_producer(struct qlcnic_adapter
*adapter
,
132 struct qlcnic_host_tx_ring
*tx_ring
)
134 writel(tx_ring
->producer
, tx_ring
->crb_cmd_producer
);
137 static const u32 msi_tgt_status
[8] = {
138 ISR_INT_TARGET_STATUS
, ISR_INT_TARGET_STATUS_F1
,
139 ISR_INT_TARGET_STATUS_F2
, ISR_INT_TARGET_STATUS_F3
,
140 ISR_INT_TARGET_STATUS_F4
, ISR_INT_TARGET_STATUS_F5
,
141 ISR_INT_TARGET_STATUS_F6
, ISR_INT_TARGET_STATUS_F7
145 struct qlcnic_legacy_intr_set legacy_intr
[] = QLCNIC_LEGACY_INTR_CONFIG
;
147 static inline void qlcnic_disable_int(struct qlcnic_host_sds_ring
*sds_ring
)
149 writel(0, sds_ring
->crb_intr_mask
);
152 static inline void qlcnic_enable_int(struct qlcnic_host_sds_ring
*sds_ring
)
154 struct qlcnic_adapter
*adapter
= sds_ring
->adapter
;
156 writel(0x1, sds_ring
->crb_intr_mask
);
158 if (!QLCNIC_IS_MSI_FAMILY(adapter
))
159 writel(0xfbff, adapter
->tgt_mask_reg
);
163 qlcnic_alloc_sds_rings(struct qlcnic_recv_context
*recv_ctx
, int count
)
165 int size
= sizeof(struct qlcnic_host_sds_ring
) * count
;
167 recv_ctx
->sds_rings
= kzalloc(size
, GFP_KERNEL
);
169 return (recv_ctx
->sds_rings
== NULL
);
173 qlcnic_free_sds_rings(struct qlcnic_recv_context
*recv_ctx
)
175 if (recv_ctx
->sds_rings
!= NULL
)
176 kfree(recv_ctx
->sds_rings
);
178 recv_ctx
->sds_rings
= NULL
;
182 qlcnic_napi_add(struct qlcnic_adapter
*adapter
, struct net_device
*netdev
)
185 struct qlcnic_host_sds_ring
*sds_ring
;
186 struct qlcnic_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
188 if (qlcnic_alloc_sds_rings(recv_ctx
, adapter
->max_sds_rings
))
191 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
192 sds_ring
= &recv_ctx
->sds_rings
[ring
];
194 if (ring
== adapter
->max_sds_rings
- 1)
195 netif_napi_add(netdev
, &sds_ring
->napi
, qlcnic_poll
,
196 QLCNIC_NETDEV_WEIGHT
/adapter
->max_sds_rings
);
198 netif_napi_add(netdev
, &sds_ring
->napi
,
199 qlcnic_rx_poll
, QLCNIC_NETDEV_WEIGHT
*2);
206 qlcnic_napi_del(struct qlcnic_adapter
*adapter
)
209 struct qlcnic_host_sds_ring
*sds_ring
;
210 struct qlcnic_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
212 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
213 sds_ring
= &recv_ctx
->sds_rings
[ring
];
214 netif_napi_del(&sds_ring
->napi
);
217 qlcnic_free_sds_rings(&adapter
->recv_ctx
);
221 qlcnic_napi_enable(struct qlcnic_adapter
*adapter
)
224 struct qlcnic_host_sds_ring
*sds_ring
;
225 struct qlcnic_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
227 if (adapter
->is_up
!= QLCNIC_ADAPTER_UP_MAGIC
)
230 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
231 sds_ring
= &recv_ctx
->sds_rings
[ring
];
232 napi_enable(&sds_ring
->napi
);
233 qlcnic_enable_int(sds_ring
);
238 qlcnic_napi_disable(struct qlcnic_adapter
*adapter
)
241 struct qlcnic_host_sds_ring
*sds_ring
;
242 struct qlcnic_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
244 if (adapter
->is_up
!= QLCNIC_ADAPTER_UP_MAGIC
)
247 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
248 sds_ring
= &recv_ctx
->sds_rings
[ring
];
249 qlcnic_disable_int(sds_ring
);
250 napi_synchronize(&sds_ring
->napi
);
251 napi_disable(&sds_ring
->napi
);
255 static void qlcnic_clear_stats(struct qlcnic_adapter
*adapter
)
257 memset(&adapter
->stats
, 0, sizeof(adapter
->stats
));
260 static void qlcnic_set_port_mode(struct qlcnic_adapter
*adapter
)
264 val
= adapter
->ahw
.board_type
;
265 if ((val
== QLCNIC_BRDTYPE_P3_HMEZ
) ||
266 (val
== QLCNIC_BRDTYPE_P3_XG_LOM
)) {
267 if (port_mode
== QLCNIC_PORT_MODE_802_3_AP
) {
268 data
= QLCNIC_PORT_MODE_802_3_AP
;
269 QLCWR32(adapter
, QLCNIC_PORT_MODE_ADDR
, data
);
270 } else if (port_mode
== QLCNIC_PORT_MODE_XG
) {
271 data
= QLCNIC_PORT_MODE_XG
;
272 QLCWR32(adapter
, QLCNIC_PORT_MODE_ADDR
, data
);
273 } else if (port_mode
== QLCNIC_PORT_MODE_AUTO_NEG_1G
) {
274 data
= QLCNIC_PORT_MODE_AUTO_NEG_1G
;
275 QLCWR32(adapter
, QLCNIC_PORT_MODE_ADDR
, data
);
276 } else if (port_mode
== QLCNIC_PORT_MODE_AUTO_NEG_XG
) {
277 data
= QLCNIC_PORT_MODE_AUTO_NEG_XG
;
278 QLCWR32(adapter
, QLCNIC_PORT_MODE_ADDR
, data
);
280 data
= QLCNIC_PORT_MODE_AUTO_NEG
;
281 QLCWR32(adapter
, QLCNIC_PORT_MODE_ADDR
, data
);
284 if ((wol_port_mode
!= QLCNIC_PORT_MODE_802_3_AP
) &&
285 (wol_port_mode
!= QLCNIC_PORT_MODE_XG
) &&
286 (wol_port_mode
!= QLCNIC_PORT_MODE_AUTO_NEG_1G
) &&
287 (wol_port_mode
!= QLCNIC_PORT_MODE_AUTO_NEG_XG
)) {
288 wol_port_mode
= QLCNIC_PORT_MODE_AUTO_NEG
;
290 QLCWR32(adapter
, QLCNIC_WOL_PORT_MODE
, wol_port_mode
);
294 static void qlcnic_set_msix_bit(struct pci_dev
*pdev
, int enable
)
299 pos
= pci_find_capability(pdev
, PCI_CAP_ID_MSIX
);
301 pci_read_config_dword(pdev
, pos
, &control
);
303 control
|= PCI_MSIX_FLAGS_ENABLE
;
306 pci_write_config_dword(pdev
, pos
, control
);
310 static void qlcnic_init_msix_entries(struct qlcnic_adapter
*adapter
, int count
)
314 for (i
= 0; i
< count
; i
++)
315 adapter
->msix_entries
[i
].entry
= i
;
319 qlcnic_read_mac_addr(struct qlcnic_adapter
*adapter
)
321 u8 mac_addr
[ETH_ALEN
];
322 struct net_device
*netdev
= adapter
->netdev
;
323 struct pci_dev
*pdev
= adapter
->pdev
;
325 if (qlcnic_get_mac_address(adapter
, mac_addr
) != 0)
328 memcpy(netdev
->dev_addr
, mac_addr
, ETH_ALEN
);
329 memcpy(netdev
->perm_addr
, netdev
->dev_addr
, netdev
->addr_len
);
330 memcpy(adapter
->mac_addr
, netdev
->dev_addr
, netdev
->addr_len
);
332 /* set station address */
334 if (!is_valid_ether_addr(netdev
->perm_addr
))
335 dev_warn(&pdev
->dev
, "Bad MAC address %pM.\n",
341 static int qlcnic_set_mac(struct net_device
*netdev
, void *p
)
343 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
344 struct sockaddr
*addr
= p
;
346 if (!is_valid_ether_addr(addr
->sa_data
))
349 if (test_bit(__QLCNIC_DEV_UP
, &adapter
->state
)) {
350 netif_device_detach(netdev
);
351 qlcnic_napi_disable(adapter
);
354 memcpy(adapter
->mac_addr
, addr
->sa_data
, netdev
->addr_len
);
355 memcpy(netdev
->dev_addr
, addr
->sa_data
, netdev
->addr_len
);
356 qlcnic_set_multi(adapter
->netdev
);
358 if (test_bit(__QLCNIC_DEV_UP
, &adapter
->state
)) {
359 netif_device_attach(netdev
);
360 qlcnic_napi_enable(adapter
);
365 static const struct net_device_ops qlcnic_netdev_ops
= {
366 .ndo_open
= qlcnic_open
,
367 .ndo_stop
= qlcnic_close
,
368 .ndo_start_xmit
= qlcnic_xmit_frame
,
369 .ndo_get_stats
= qlcnic_get_stats
,
370 .ndo_validate_addr
= eth_validate_addr
,
371 .ndo_set_multicast_list
= qlcnic_set_multi
,
372 .ndo_set_mac_address
= qlcnic_set_mac
,
373 .ndo_change_mtu
= qlcnic_change_mtu
,
374 .ndo_tx_timeout
= qlcnic_tx_timeout
,
375 #ifdef CONFIG_NET_POLL_CONTROLLER
376 .ndo_poll_controller
= qlcnic_poll_controller
,
380 static struct qlcnic_nic_template qlcnic_ops
= {
381 .config_bridged_mode
= qlcnic_config_bridged_mode
,
382 .config_led
= qlcnic_config_led
,
383 .start_firmware
= qlcnic_start_firmware
386 static struct qlcnic_nic_template qlcnic_vf_ops
= {
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
].min_bw
= pci_info
[i
].tx_min_bw
;
510 adapter
->npars
[pfn
].max_bw
= pci_info
[i
].tx_max_bw
;
513 for (i
= 0; i
< QLCNIC_NIU_MAX_XG_PORTS
; i
++)
514 adapter
->eswitch
[i
].flags
|= QLCNIC_SWITCH_ENABLE
;
520 kfree(adapter
->eswitch
);
521 adapter
->eswitch
= NULL
;
523 kfree(adapter
->npars
);
524 adapter
->npars
= NULL
;
532 qlcnic_set_function_modes(struct qlcnic_adapter
*adapter
)
537 u32 data
= QLCNIC_MGMT_FUNC
;
538 void __iomem
*priv_op
= adapter
->ahw
.pci_base0
+ QLCNIC_DRV_OP_MODE
;
540 /* If other drivers are not in use set their privilege level */
541 ref_count
= QLCRD32(adapter
, QLCNIC_CRB_DRV_ACTIVE
);
542 ret
= qlcnic_api_lock(adapter
);
546 if (qlcnic_config_npars
) {
547 for (i
= 0; i
< QLCNIC_MAX_PCI_FUNC
; i
++) {
549 if (adapter
->npars
[i
].type
!= QLCNIC_TYPE_NIC
||
550 id
== adapter
->ahw
.pci_func
)
552 data
|= (qlcnic_config_npars
&
553 QLC_DEV_SET_DRV(0xf, id
));
556 data
= readl(priv_op
);
557 data
= (data
& ~QLC_DEV_SET_DRV(0xf, adapter
->ahw
.pci_func
)) |
558 (QLC_DEV_SET_DRV(QLCNIC_MGMT_FUNC
,
559 adapter
->ahw
.pci_func
));
561 writel(data
, priv_op
);
562 qlcnic_api_unlock(adapter
);
568 qlcnic_check_vf(struct qlcnic_adapter
*adapter
)
570 void __iomem
*msix_base_addr
;
571 void __iomem
*priv_op
;
574 u32 op_mode
, priv_level
;
576 /* Determine FW API version */
577 adapter
->fw_hal_version
= readl(adapter
->ahw
.pci_base0
+ QLCNIC_FW_API
);
579 /* Find PCI function number */
580 pci_read_config_dword(adapter
->pdev
, QLCNIC_MSIX_TABLE_OFFSET
, &func
);
581 msix_base_addr
= adapter
->ahw
.pci_base0
+ QLCNIC_MSIX_BASE
;
582 msix_base
= readl(msix_base_addr
);
583 func
= (func
- msix_base
)/QLCNIC_MSIX_TBL_PGSIZE
;
584 adapter
->ahw
.pci_func
= func
;
586 /* Determine function privilege level */
587 priv_op
= adapter
->ahw
.pci_base0
+ QLCNIC_DRV_OP_MODE
;
588 op_mode
= readl(priv_op
);
589 if (op_mode
== QLC_DEV_DRV_DEFAULT
)
590 priv_level
= QLCNIC_MGMT_FUNC
;
592 priv_level
= QLC_DEV_GET_DRV(op_mode
, adapter
->ahw
.pci_func
);
594 if (priv_level
== QLCNIC_NON_PRIV_FUNC
) {
595 adapter
->op_mode
= QLCNIC_NON_PRIV_FUNC
;
596 dev_info(&adapter
->pdev
->dev
,
597 "HAL Version: %d Non Privileged function\n",
598 adapter
->fw_hal_version
);
599 adapter
->nic_ops
= &qlcnic_vf_ops
;
601 adapter
->nic_ops
= &qlcnic_ops
;
605 qlcnic_setup_pci_map(struct qlcnic_adapter
*adapter
)
607 void __iomem
*mem_ptr0
= NULL
;
608 resource_size_t mem_base
;
609 unsigned long mem_len
, pci_len0
= 0;
611 struct pci_dev
*pdev
= adapter
->pdev
;
613 /* remap phys address */
614 mem_base
= pci_resource_start(pdev
, 0); /* 0 is for BAR 0 */
615 mem_len
= pci_resource_len(pdev
, 0);
617 if (mem_len
== QLCNIC_PCI_2MB_SIZE
) {
619 mem_ptr0
= pci_ioremap_bar(pdev
, 0);
620 if (mem_ptr0
== NULL
) {
621 dev_err(&pdev
->dev
, "failed to map PCI bar 0\n");
629 dev_info(&pdev
->dev
, "%dMB memory map\n", (int)(mem_len
>>20));
631 adapter
->ahw
.pci_base0
= mem_ptr0
;
632 adapter
->ahw
.pci_len0
= pci_len0
;
634 qlcnic_check_vf(adapter
);
636 adapter
->ahw
.ocm_win_crb
= qlcnic_get_ioaddr(adapter
,
637 QLCNIC_PCIX_PS_REG(PCIX_OCM_WINDOW_REG(adapter
->ahw
.pci_func
)));
642 static void get_brd_name(struct qlcnic_adapter
*adapter
, char *name
)
644 struct pci_dev
*pdev
= adapter
->pdev
;
647 for (i
= 0; i
< NUM_SUPPORTED_BOARDS
; ++i
) {
648 if (qlcnic_boards
[i
].vendor
== pdev
->vendor
&&
649 qlcnic_boards
[i
].device
== pdev
->device
&&
650 qlcnic_boards
[i
].sub_vendor
== pdev
->subsystem_vendor
&&
651 qlcnic_boards
[i
].sub_device
== pdev
->subsystem_device
) {
652 sprintf(name
, "%pM: %s" ,
654 qlcnic_boards
[i
].short_name
);
662 sprintf(name
, "%pM Gigabit Ethernet", adapter
->mac_addr
);
666 qlcnic_check_options(struct qlcnic_adapter
*adapter
)
668 u32 fw_major
, fw_minor
, fw_build
;
669 struct pci_dev
*pdev
= adapter
->pdev
;
671 fw_major
= QLCRD32(adapter
, QLCNIC_FW_VERSION_MAJOR
);
672 fw_minor
= QLCRD32(adapter
, QLCNIC_FW_VERSION_MINOR
);
673 fw_build
= QLCRD32(adapter
, QLCNIC_FW_VERSION_SUB
);
675 adapter
->fw_version
= QLCNIC_VERSION_CODE(fw_major
, fw_minor
, fw_build
);
677 dev_info(&pdev
->dev
, "firmware v%d.%d.%d\n",
678 fw_major
, fw_minor
, fw_build
);
680 adapter
->flags
&= ~QLCNIC_LRO_ENABLED
;
682 if (adapter
->ahw
.port_type
== QLCNIC_XGBE
) {
683 adapter
->num_rxd
= DEFAULT_RCV_DESCRIPTORS_10G
;
684 adapter
->num_jumbo_rxd
= MAX_JUMBO_RCV_DESCRIPTORS_10G
;
685 } else if (adapter
->ahw
.port_type
== QLCNIC_GBE
) {
686 adapter
->num_rxd
= DEFAULT_RCV_DESCRIPTORS_1G
;
687 adapter
->num_jumbo_rxd
= MAX_JUMBO_RCV_DESCRIPTORS_1G
;
690 adapter
->msix_supported
= !!use_msi_x
;
691 adapter
->rss_supported
= !!use_msi_x
;
693 adapter
->num_txd
= MAX_CMD_DESCRIPTORS
;
695 adapter
->max_rds_rings
= MAX_RDS_RINGS
;
699 qlcnic_initialize_nic(struct qlcnic_adapter
*adapter
)
702 struct qlcnic_info nic_info
;
704 err
= qlcnic_get_nic_info(adapter
, &nic_info
, adapter
->ahw
.pci_func
);
708 adapter
->physical_port
= nic_info
.phys_port
;
709 adapter
->switch_mode
= nic_info
.switch_mode
;
710 adapter
->max_tx_ques
= nic_info
.max_tx_ques
;
711 adapter
->max_rx_ques
= nic_info
.max_rx_ques
;
712 adapter
->capabilities
= nic_info
.capabilities
;
713 adapter
->max_mac_filters
= nic_info
.max_mac_filters
;
714 adapter
->max_mtu
= nic_info
.max_mtu
;
716 if (adapter
->capabilities
& BIT_6
)
717 adapter
->flags
|= QLCNIC_ESWITCH_ENABLED
;
719 adapter
->flags
&= ~QLCNIC_ESWITCH_ENABLED
;
725 qlcnic_set_vlan_config(struct qlcnic_adapter
*adapter
,
726 struct qlcnic_esw_func_cfg
*esw_cfg
)
728 if (esw_cfg
->discard_tagged
)
729 adapter
->flags
&= ~QLCNIC_TAGGING_ENABLED
;
731 adapter
->flags
|= QLCNIC_TAGGING_ENABLED
;
733 if (esw_cfg
->vlan_id
)
734 adapter
->pvid
= esw_cfg
->vlan_id
;
740 qlcnic_set_eswitch_port_features(struct qlcnic_adapter
*adapter
,
741 struct qlcnic_esw_func_cfg
*esw_cfg
)
743 adapter
->flags
&= ~QLCNIC_MACSPOOF
;
745 if (esw_cfg
->mac_anti_spoof
)
746 adapter
->flags
|= QLCNIC_MACSPOOF
;
748 qlcnic_set_netdev_features(adapter
, esw_cfg
);
752 qlcnic_set_eswitch_port_config(struct qlcnic_adapter
*adapter
)
754 struct qlcnic_esw_func_cfg esw_cfg
;
756 if (!(adapter
->flags
& QLCNIC_ESWITCH_ENABLED
))
759 esw_cfg
.pci_func
= adapter
->ahw
.pci_func
;
760 if (qlcnic_get_eswitch_port_config(adapter
, &esw_cfg
))
762 qlcnic_set_vlan_config(adapter
, &esw_cfg
);
763 qlcnic_set_eswitch_port_features(adapter
, &esw_cfg
);
769 qlcnic_set_netdev_features(struct qlcnic_adapter
*adapter
,
770 struct qlcnic_esw_func_cfg
*esw_cfg
)
772 struct net_device
*netdev
= adapter
->netdev
;
773 unsigned long features
, vlan_features
;
775 features
= (NETIF_F_SG
| NETIF_F_IP_CSUM
|
776 NETIF_F_IPV6_CSUM
| NETIF_F_GRO
);
777 vlan_features
= (NETIF_F_SG
| NETIF_F_IP_CSUM
|
780 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_TSO
) {
781 features
|= (NETIF_F_TSO
| NETIF_F_TSO6
);
782 vlan_features
|= (NETIF_F_TSO
| NETIF_F_TSO6
);
784 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_HW_LRO
)
785 features
|= NETIF_F_LRO
;
787 if (esw_cfg
->offload_flags
& BIT_0
) {
788 netdev
->features
|= features
;
789 adapter
->rx_csum
= 1;
790 if (!(esw_cfg
->offload_flags
& BIT_1
))
791 netdev
->features
&= ~NETIF_F_TSO
;
792 if (!(esw_cfg
->offload_flags
& BIT_2
))
793 netdev
->features
&= ~NETIF_F_TSO6
;
795 netdev
->features
&= ~features
;
796 adapter
->rx_csum
= 0;
799 netdev
->vlan_features
= (features
& vlan_features
);
803 qlcnic_check_eswitch_mode(struct qlcnic_adapter
*adapter
)
805 void __iomem
*priv_op
;
806 u32 op_mode
, priv_level
;
809 err
= qlcnic_initialize_nic(adapter
);
813 if (adapter
->flags
& QLCNIC_ADAPTER_INITIALIZED
)
816 priv_op
= adapter
->ahw
.pci_base0
+ QLCNIC_DRV_OP_MODE
;
817 op_mode
= readl(priv_op
);
818 priv_level
= QLC_DEV_GET_DRV(op_mode
, adapter
->ahw
.pci_func
);
820 if (op_mode
== QLC_DEV_DRV_DEFAULT
)
821 priv_level
= QLCNIC_MGMT_FUNC
;
823 priv_level
= QLC_DEV_GET_DRV(op_mode
, adapter
->ahw
.pci_func
);
825 if (adapter
->flags
& QLCNIC_ESWITCH_ENABLED
) {
826 if (priv_level
== QLCNIC_MGMT_FUNC
) {
827 adapter
->op_mode
= QLCNIC_MGMT_FUNC
;
828 err
= qlcnic_init_pci_info(adapter
);
831 /* Set privilege level for other functions */
832 qlcnic_set_function_modes(adapter
);
833 dev_info(&adapter
->pdev
->dev
,
834 "HAL Version: %d, Management function\n",
835 adapter
->fw_hal_version
);
836 } else if (priv_level
== QLCNIC_PRIV_FUNC
) {
837 adapter
->op_mode
= QLCNIC_PRIV_FUNC
;
838 dev_info(&adapter
->pdev
->dev
,
839 "HAL Version: %d, Privileged function\n",
840 adapter
->fw_hal_version
);
844 adapter
->flags
|= QLCNIC_ADAPTER_INITIALIZED
;
850 qlcnic_set_default_offload_settings(struct qlcnic_adapter
*adapter
)
852 struct qlcnic_esw_func_cfg esw_cfg
;
853 struct qlcnic_npar_info
*npar
;
856 if (adapter
->need_fw_reset
)
859 for (i
= 0; i
< QLCNIC_MAX_PCI_FUNC
; i
++) {
860 if (adapter
->npars
[i
].type
!= QLCNIC_TYPE_NIC
)
862 memset(&esw_cfg
, 0, sizeof(struct qlcnic_esw_func_cfg
));
863 esw_cfg
.pci_func
= i
;
864 esw_cfg
.offload_flags
= BIT_0
;
865 esw_cfg
.mac_learning
= BIT_0
;
866 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_TSO
)
867 esw_cfg
.offload_flags
|= (BIT_1
| BIT_2
);
868 if (qlcnic_config_switch_port(adapter
, &esw_cfg
))
870 npar
= &adapter
->npars
[i
];
871 npar
->pvid
= esw_cfg
.vlan_id
;
872 npar
->mac_learning
= esw_cfg
.offload_flags
;
873 npar
->mac_anti_spoof
= esw_cfg
.mac_anti_spoof
;
874 npar
->discard_tagged
= esw_cfg
.discard_tagged
;
875 npar
->promisc_mode
= esw_cfg
.promisc_mode
;
876 npar
->offload_flags
= esw_cfg
.offload_flags
;
883 qlcnic_reset_eswitch_config(struct qlcnic_adapter
*adapter
,
884 struct qlcnic_npar_info
*npar
, int pci_func
)
886 struct qlcnic_esw_func_cfg esw_cfg
;
887 esw_cfg
.op_mode
= QLCNIC_PORT_DEFAULTS
;
888 esw_cfg
.pci_func
= pci_func
;
889 esw_cfg
.vlan_id
= npar
->pvid
;
890 esw_cfg
.mac_learning
= npar
->mac_learning
;
891 esw_cfg
.discard_tagged
= npar
->discard_tagged
;
892 esw_cfg
.mac_anti_spoof
= npar
->mac_anti_spoof
;
893 esw_cfg
.offload_flags
= npar
->offload_flags
;
894 esw_cfg
.promisc_mode
= npar
->promisc_mode
;
895 if (qlcnic_config_switch_port(adapter
, &esw_cfg
))
898 esw_cfg
.op_mode
= QLCNIC_ADD_VLAN
;
899 if (qlcnic_config_switch_port(adapter
, &esw_cfg
))
906 qlcnic_reset_npar_config(struct qlcnic_adapter
*adapter
)
909 struct qlcnic_npar_info
*npar
;
910 struct qlcnic_info nic_info
;
912 if (!adapter
->need_fw_reset
)
915 /* Set the NPAR config data after FW reset */
916 for (i
= 0; i
< QLCNIC_MAX_PCI_FUNC
; i
++) {
917 npar
= &adapter
->npars
[i
];
918 if (npar
->type
!= QLCNIC_TYPE_NIC
)
920 err
= qlcnic_get_nic_info(adapter
, &nic_info
, i
);
923 nic_info
.min_tx_bw
= npar
->min_bw
;
924 nic_info
.max_tx_bw
= npar
->max_bw
;
925 err
= qlcnic_set_nic_info(adapter
, &nic_info
);
929 if (npar
->enable_pm
) {
930 err
= qlcnic_config_port_mirroring(adapter
,
931 npar
->dest_npar
, 1, i
);
935 err
= qlcnic_reset_eswitch_config(adapter
, npar
, i
);
942 static int qlcnic_check_npar_opertional(struct qlcnic_adapter
*adapter
)
944 u8 npar_opt_timeo
= QLCNIC_DEV_NPAR_OPER_TIMEO
;
947 if (adapter
->op_mode
== QLCNIC_MGMT_FUNC
)
950 npar_state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_NPAR_STATE
);
951 while (npar_state
!= QLCNIC_DEV_NPAR_OPER
&& --npar_opt_timeo
) {
953 npar_state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_NPAR_STATE
);
955 if (!npar_opt_timeo
) {
956 dev_err(&adapter
->pdev
->dev
,
957 "Waiting for NPAR state to opertional timeout\n");
964 qlcnic_set_mgmt_operations(struct qlcnic_adapter
*adapter
)
968 if (!(adapter
->flags
& QLCNIC_ESWITCH_ENABLED
) ||
969 adapter
->op_mode
!= QLCNIC_MGMT_FUNC
)
972 err
= qlcnic_set_default_offload_settings(adapter
);
976 err
= qlcnic_reset_npar_config(adapter
);
980 qlcnic_dev_set_npar_ready(adapter
);
986 qlcnic_start_firmware(struct qlcnic_adapter
*adapter
)
990 err
= qlcnic_can_start_firmware(adapter
);
994 goto check_fw_status
;
997 qlcnic_request_firmware(adapter
);
999 err
= qlcnic_check_flash_fw_ver(adapter
);
1003 adapter
->fw_type
= QLCNIC_FLASH_ROMIMAGE
;
1006 err
= qlcnic_need_fw_reset(adapter
);
1008 goto check_fw_status
;
1010 err
= qlcnic_pinit_from_rom(adapter
);
1013 qlcnic_set_port_mode(adapter
);
1015 err
= qlcnic_load_firmware(adapter
);
1019 qlcnic_release_firmware(adapter
);
1020 QLCWR32(adapter
, CRB_DRIVER_VERSION
, QLCNIC_DRIVER_VERSION
);
1023 err
= qlcnic_check_fw_status(adapter
);
1027 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
, QLCNIC_DEV_READY
);
1028 qlcnic_idc_debug_info(adapter
, 1);
1030 err
= qlcnic_check_eswitch_mode(adapter
);
1032 dev_err(&adapter
->pdev
->dev
,
1033 "Memory allocation failed for eswitch\n");
1036 err
= qlcnic_set_mgmt_operations(adapter
);
1040 qlcnic_check_options(adapter
);
1041 adapter
->need_fw_reset
= 0;
1043 qlcnic_release_firmware(adapter
);
1047 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
, QLCNIC_DEV_FAILED
);
1048 dev_err(&adapter
->pdev
->dev
, "Device state set to failed\n");
1050 qlcnic_release_firmware(adapter
);
1055 qlcnic_request_irq(struct qlcnic_adapter
*adapter
)
1057 irq_handler_t handler
;
1058 struct qlcnic_host_sds_ring
*sds_ring
;
1061 unsigned long flags
= 0;
1062 struct net_device
*netdev
= adapter
->netdev
;
1063 struct qlcnic_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
1065 if (adapter
->diag_test
== QLCNIC_INTERRUPT_TEST
) {
1066 handler
= qlcnic_tmp_intr
;
1067 if (!QLCNIC_IS_MSI_FAMILY(adapter
))
1068 flags
|= IRQF_SHARED
;
1071 if (adapter
->flags
& QLCNIC_MSIX_ENABLED
)
1072 handler
= qlcnic_msix_intr
;
1073 else if (adapter
->flags
& QLCNIC_MSI_ENABLED
)
1074 handler
= qlcnic_msi_intr
;
1076 flags
|= IRQF_SHARED
;
1077 handler
= qlcnic_intr
;
1080 adapter
->irq
= netdev
->irq
;
1082 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
1083 sds_ring
= &recv_ctx
->sds_rings
[ring
];
1084 sprintf(sds_ring
->name
, "%s[%d]", netdev
->name
, ring
);
1085 err
= request_irq(sds_ring
->irq
, handler
,
1086 flags
, sds_ring
->name
, sds_ring
);
1095 qlcnic_free_irq(struct qlcnic_adapter
*adapter
)
1098 struct qlcnic_host_sds_ring
*sds_ring
;
1100 struct qlcnic_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
1102 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
1103 sds_ring
= &recv_ctx
->sds_rings
[ring
];
1104 free_irq(sds_ring
->irq
, sds_ring
);
1109 qlcnic_init_coalesce_defaults(struct qlcnic_adapter
*adapter
)
1111 adapter
->coal
.flags
= QLCNIC_INTR_DEFAULT
;
1112 adapter
->coal
.normal
.data
.rx_time_us
=
1113 QLCNIC_DEFAULT_INTR_COALESCE_RX_TIME_US
;
1114 adapter
->coal
.normal
.data
.rx_packets
=
1115 QLCNIC_DEFAULT_INTR_COALESCE_RX_PACKETS
;
1116 adapter
->coal
.normal
.data
.tx_time_us
=
1117 QLCNIC_DEFAULT_INTR_COALESCE_TX_TIME_US
;
1118 adapter
->coal
.normal
.data
.tx_packets
=
1119 QLCNIC_DEFAULT_INTR_COALESCE_TX_PACKETS
;
1123 __qlcnic_up(struct qlcnic_adapter
*adapter
, struct net_device
*netdev
)
1126 struct qlcnic_host_rds_ring
*rds_ring
;
1128 if (adapter
->is_up
!= QLCNIC_ADAPTER_UP_MAGIC
)
1131 if (test_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
1133 if (qlcnic_set_eswitch_port_config(adapter
))
1136 if (qlcnic_fw_create_ctx(adapter
))
1139 for (ring
= 0; ring
< adapter
->max_rds_rings
; ring
++) {
1140 rds_ring
= &adapter
->recv_ctx
.rds_rings
[ring
];
1141 qlcnic_post_rx_buffers(adapter
, ring
, rds_ring
);
1144 qlcnic_set_multi(netdev
);
1145 qlcnic_fw_cmd_set_mtu(adapter
, netdev
->mtu
);
1147 adapter
->ahw
.linkup
= 0;
1149 if (adapter
->max_sds_rings
> 1)
1150 qlcnic_config_rss(adapter
, 1);
1152 qlcnic_config_intr_coalesce(adapter
);
1154 if (netdev
->features
& NETIF_F_LRO
)
1155 qlcnic_config_hw_lro(adapter
, QLCNIC_LRO_ENABLED
);
1157 qlcnic_napi_enable(adapter
);
1159 qlcnic_linkevent_request(adapter
, 1);
1161 adapter
->reset_context
= 0;
1162 set_bit(__QLCNIC_DEV_UP
, &adapter
->state
);
1166 /* Usage: During resume and firmware recovery module.*/
1169 qlcnic_up(struct qlcnic_adapter
*adapter
, struct net_device
*netdev
)
1174 if (netif_running(netdev
))
1175 err
= __qlcnic_up(adapter
, netdev
);
1182 __qlcnic_down(struct qlcnic_adapter
*adapter
, struct net_device
*netdev
)
1184 if (adapter
->is_up
!= QLCNIC_ADAPTER_UP_MAGIC
)
1187 if (!test_and_clear_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
1191 spin_lock(&adapter
->tx_clean_lock
);
1192 netif_carrier_off(netdev
);
1193 netif_tx_disable(netdev
);
1195 qlcnic_free_mac_list(adapter
);
1197 qlcnic_nic_set_promisc(adapter
, QLCNIC_NIU_NON_PROMISC_MODE
);
1199 qlcnic_napi_disable(adapter
);
1201 qlcnic_fw_destroy_ctx(adapter
);
1203 qlcnic_reset_rx_buffers_list(adapter
);
1204 qlcnic_release_tx_buffers(adapter
);
1205 spin_unlock(&adapter
->tx_clean_lock
);
1208 /* Usage: During suspend and firmware recovery module */
1211 qlcnic_down(struct qlcnic_adapter
*adapter
, struct net_device
*netdev
)
1214 if (netif_running(netdev
))
1215 __qlcnic_down(adapter
, netdev
);
1221 qlcnic_attach(struct qlcnic_adapter
*adapter
)
1223 struct net_device
*netdev
= adapter
->netdev
;
1224 struct pci_dev
*pdev
= adapter
->pdev
;
1227 if (adapter
->is_up
== QLCNIC_ADAPTER_UP_MAGIC
)
1230 err
= qlcnic_napi_add(adapter
, netdev
);
1234 err
= qlcnic_alloc_sw_resources(adapter
);
1236 dev_err(&pdev
->dev
, "Error in setting sw resources\n");
1237 goto err_out_napi_del
;
1240 err
= qlcnic_alloc_hw_resources(adapter
);
1242 dev_err(&pdev
->dev
, "Error in setting hw resources\n");
1243 goto err_out_free_sw
;
1246 err
= qlcnic_request_irq(adapter
);
1248 dev_err(&pdev
->dev
, "failed to setup interrupt\n");
1249 goto err_out_free_hw
;
1252 qlcnic_init_coalesce_defaults(adapter
);
1254 qlcnic_create_sysfs_entries(adapter
);
1256 adapter
->is_up
= QLCNIC_ADAPTER_UP_MAGIC
;
1260 qlcnic_free_hw_resources(adapter
);
1262 qlcnic_free_sw_resources(adapter
);
1264 qlcnic_napi_del(adapter
);
1269 qlcnic_detach(struct qlcnic_adapter
*adapter
)
1271 if (adapter
->is_up
!= QLCNIC_ADAPTER_UP_MAGIC
)
1274 qlcnic_remove_sysfs_entries(adapter
);
1276 qlcnic_free_hw_resources(adapter
);
1277 qlcnic_release_rx_buffers(adapter
);
1278 qlcnic_free_irq(adapter
);
1279 qlcnic_napi_del(adapter
);
1280 qlcnic_free_sw_resources(adapter
);
1285 void qlcnic_diag_free_res(struct net_device
*netdev
, int max_sds_rings
)
1287 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
1288 struct qlcnic_host_sds_ring
*sds_ring
;
1291 clear_bit(__QLCNIC_DEV_UP
, &adapter
->state
);
1292 if (adapter
->diag_test
== QLCNIC_INTERRUPT_TEST
) {
1293 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
1294 sds_ring
= &adapter
->recv_ctx
.sds_rings
[ring
];
1295 qlcnic_disable_int(sds_ring
);
1299 qlcnic_fw_destroy_ctx(adapter
);
1301 qlcnic_detach(adapter
);
1303 adapter
->diag_test
= 0;
1304 adapter
->max_sds_rings
= max_sds_rings
;
1306 if (qlcnic_attach(adapter
))
1309 if (netif_running(netdev
))
1310 __qlcnic_up(adapter
, netdev
);
1312 netif_device_attach(netdev
);
1315 int qlcnic_diag_alloc_res(struct net_device
*netdev
, int test
)
1317 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
1318 struct qlcnic_host_sds_ring
*sds_ring
;
1319 struct qlcnic_host_rds_ring
*rds_ring
;
1323 netif_device_detach(netdev
);
1325 if (netif_running(netdev
))
1326 __qlcnic_down(adapter
, netdev
);
1328 qlcnic_detach(adapter
);
1330 adapter
->max_sds_rings
= 1;
1331 adapter
->diag_test
= test
;
1333 ret
= qlcnic_attach(adapter
);
1335 netif_device_attach(netdev
);
1339 ret
= qlcnic_fw_create_ctx(adapter
);
1341 qlcnic_detach(adapter
);
1342 netif_device_attach(netdev
);
1346 for (ring
= 0; ring
< adapter
->max_rds_rings
; ring
++) {
1347 rds_ring
= &adapter
->recv_ctx
.rds_rings
[ring
];
1348 qlcnic_post_rx_buffers(adapter
, ring
, rds_ring
);
1351 if (adapter
->diag_test
== QLCNIC_INTERRUPT_TEST
) {
1352 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
1353 sds_ring
= &adapter
->recv_ctx
.sds_rings
[ring
];
1354 qlcnic_enable_int(sds_ring
);
1357 set_bit(__QLCNIC_DEV_UP
, &adapter
->state
);
1362 /* Reset context in hardware only */
1364 qlcnic_reset_hw_context(struct qlcnic_adapter
*adapter
)
1366 struct net_device
*netdev
= adapter
->netdev
;
1368 if (test_and_set_bit(__QLCNIC_RESETTING
, &adapter
->state
))
1371 netif_device_detach(netdev
);
1373 qlcnic_down(adapter
, netdev
);
1375 qlcnic_up(adapter
, netdev
);
1377 netif_device_attach(netdev
);
1379 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
1384 qlcnic_reset_context(struct qlcnic_adapter
*adapter
)
1387 struct net_device
*netdev
= adapter
->netdev
;
1389 if (test_and_set_bit(__QLCNIC_RESETTING
, &adapter
->state
))
1392 if (adapter
->is_up
== QLCNIC_ADAPTER_UP_MAGIC
) {
1394 netif_device_detach(netdev
);
1396 if (netif_running(netdev
))
1397 __qlcnic_down(adapter
, netdev
);
1399 qlcnic_detach(adapter
);
1401 if (netif_running(netdev
)) {
1402 err
= qlcnic_attach(adapter
);
1404 __qlcnic_up(adapter
, netdev
);
1407 netif_device_attach(netdev
);
1410 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
1415 qlcnic_setup_netdev(struct qlcnic_adapter
*adapter
,
1416 struct net_device
*netdev
, u8 pci_using_dac
)
1419 struct pci_dev
*pdev
= adapter
->pdev
;
1421 adapter
->rx_csum
= 1;
1422 adapter
->mc_enabled
= 0;
1423 adapter
->max_mc_count
= 38;
1425 netdev
->netdev_ops
= &qlcnic_netdev_ops
;
1426 netdev
->watchdog_timeo
= 5*HZ
;
1428 qlcnic_change_mtu(netdev
, netdev
->mtu
);
1430 SET_ETHTOOL_OPS(netdev
, &qlcnic_ethtool_ops
);
1432 netdev
->features
|= (NETIF_F_SG
| NETIF_F_IP_CSUM
|
1433 NETIF_F_IPV6_CSUM
| NETIF_F_GRO
);
1434 netdev
->vlan_features
|= (NETIF_F_SG
| NETIF_F_IP_CSUM
|
1437 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_TSO
) {
1438 netdev
->features
|= (NETIF_F_TSO
| NETIF_F_TSO6
);
1439 netdev
->vlan_features
|= (NETIF_F_TSO
| NETIF_F_TSO6
);
1442 if (pci_using_dac
) {
1443 netdev
->features
|= NETIF_F_HIGHDMA
;
1444 netdev
->vlan_features
|= NETIF_F_HIGHDMA
;
1447 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_FVLANTX
)
1448 netdev
->features
|= (NETIF_F_HW_VLAN_TX
);
1450 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_HW_LRO
)
1451 netdev
->features
|= NETIF_F_LRO
;
1452 netdev
->irq
= adapter
->msix_entries
[0].vector
;
1454 netif_carrier_off(netdev
);
1455 netif_stop_queue(netdev
);
1457 err
= register_netdev(netdev
);
1459 dev_err(&pdev
->dev
, "failed to register net device\n");
1466 static int qlcnic_set_dma_mask(struct pci_dev
*pdev
, u8
*pci_using_dac
)
1468 if (!pci_set_dma_mask(pdev
, DMA_BIT_MASK(64)) &&
1469 !pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(64)))
1471 else if (!pci_set_dma_mask(pdev
, DMA_BIT_MASK(32)) &&
1472 !pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(32)))
1475 dev_err(&pdev
->dev
, "Unable to set DMA mask, aborting\n");
1482 static int __devinit
1483 qlcnic_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
1485 struct net_device
*netdev
= NULL
;
1486 struct qlcnic_adapter
*adapter
= NULL
;
1488 uint8_t revision_id
;
1489 uint8_t pci_using_dac
;
1490 char brd_name
[QLCNIC_MAX_BOARD_NAME_LEN
];
1492 err
= pci_enable_device(pdev
);
1496 if (!(pci_resource_flags(pdev
, 0) & IORESOURCE_MEM
)) {
1498 goto err_out_disable_pdev
;
1501 err
= qlcnic_set_dma_mask(pdev
, &pci_using_dac
);
1503 goto err_out_disable_pdev
;
1505 err
= pci_request_regions(pdev
, qlcnic_driver_name
);
1507 goto err_out_disable_pdev
;
1509 pci_set_master(pdev
);
1510 pci_enable_pcie_error_reporting(pdev
);
1512 netdev
= alloc_etherdev(sizeof(struct qlcnic_adapter
));
1514 dev_err(&pdev
->dev
, "failed to allocate net_device\n");
1516 goto err_out_free_res
;
1519 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
1521 adapter
= netdev_priv(netdev
);
1522 adapter
->netdev
= netdev
;
1523 adapter
->pdev
= pdev
;
1524 adapter
->dev_rst_time
= jiffies
;
1526 revision_id
= pdev
->revision
;
1527 adapter
->ahw
.revision_id
= revision_id
;
1529 rwlock_init(&adapter
->ahw
.crb_lock
);
1530 mutex_init(&adapter
->ahw
.mem_lock
);
1532 spin_lock_init(&adapter
->tx_clean_lock
);
1533 INIT_LIST_HEAD(&adapter
->mac_list
);
1535 err
= qlcnic_setup_pci_map(adapter
);
1537 goto err_out_free_netdev
;
1539 /* This will be reset for mezz cards */
1540 adapter
->portnum
= adapter
->ahw
.pci_func
;
1542 err
= qlcnic_get_board_info(adapter
);
1544 dev_err(&pdev
->dev
, "Error getting board config info.\n");
1545 goto err_out_iounmap
;
1548 err
= qlcnic_setup_idc_param(adapter
);
1550 goto err_out_iounmap
;
1552 err
= adapter
->nic_ops
->start_firmware(adapter
);
1554 dev_err(&pdev
->dev
, "Loading fw failed.Please Reboot\n");
1555 goto err_out_decr_ref
;
1558 if (qlcnic_read_mac_addr(adapter
))
1559 dev_warn(&pdev
->dev
, "failed to read mac addr\n");
1561 if (adapter
->portnum
== 0) {
1562 get_brd_name(adapter
, brd_name
);
1564 pr_info("%s: %s Board Chip rev 0x%x\n",
1565 module_name(THIS_MODULE
),
1566 brd_name
, adapter
->ahw
.revision_id
);
1569 qlcnic_clear_stats(adapter
);
1571 qlcnic_setup_intr(adapter
);
1573 err
= qlcnic_setup_netdev(adapter
, netdev
, pci_using_dac
);
1575 goto err_out_disable_msi
;
1577 pci_set_drvdata(pdev
, adapter
);
1579 qlcnic_schedule_work(adapter
, qlcnic_fw_poll_work
, FW_POLL_DELAY
);
1581 switch (adapter
->ahw
.port_type
) {
1583 dev_info(&adapter
->pdev
->dev
, "%s: GbE port initialized\n",
1584 adapter
->netdev
->name
);
1587 dev_info(&adapter
->pdev
->dev
, "%s: XGbE port initialized\n",
1588 adapter
->netdev
->name
);
1592 qlcnic_create_diag_entries(adapter
);
1596 err_out_disable_msi
:
1597 qlcnic_teardown_intr(adapter
);
1600 qlcnic_clr_all_drv_state(adapter
, 0);
1603 qlcnic_cleanup_pci_map(adapter
);
1605 err_out_free_netdev
:
1606 free_netdev(netdev
);
1609 pci_release_regions(pdev
);
1611 err_out_disable_pdev
:
1612 pci_set_drvdata(pdev
, NULL
);
1613 pci_disable_device(pdev
);
1617 static void __devexit
qlcnic_remove(struct pci_dev
*pdev
)
1619 struct qlcnic_adapter
*adapter
;
1620 struct net_device
*netdev
;
1622 adapter
= pci_get_drvdata(pdev
);
1623 if (adapter
== NULL
)
1626 netdev
= adapter
->netdev
;
1628 qlcnic_cancel_fw_work(adapter
);
1630 unregister_netdev(netdev
);
1632 qlcnic_detach(adapter
);
1634 if (adapter
->npars
!= NULL
)
1635 kfree(adapter
->npars
);
1636 if (adapter
->eswitch
!= NULL
)
1637 kfree(adapter
->eswitch
);
1639 qlcnic_clr_all_drv_state(adapter
, 0);
1641 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
1643 qlcnic_teardown_intr(adapter
);
1645 qlcnic_remove_diag_entries(adapter
);
1647 qlcnic_cleanup_pci_map(adapter
);
1649 qlcnic_release_firmware(adapter
);
1651 pci_disable_pcie_error_reporting(pdev
);
1652 pci_release_regions(pdev
);
1653 pci_disable_device(pdev
);
1654 pci_set_drvdata(pdev
, NULL
);
1656 free_netdev(netdev
);
1658 static int __qlcnic_shutdown(struct pci_dev
*pdev
)
1660 struct qlcnic_adapter
*adapter
= pci_get_drvdata(pdev
);
1661 struct net_device
*netdev
= adapter
->netdev
;
1664 netif_device_detach(netdev
);
1666 qlcnic_cancel_fw_work(adapter
);
1668 if (netif_running(netdev
))
1669 qlcnic_down(adapter
, netdev
);
1671 qlcnic_clr_all_drv_state(adapter
, 0);
1673 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
1675 retval
= pci_save_state(pdev
);
1679 if (qlcnic_wol_supported(adapter
)) {
1680 pci_enable_wake(pdev
, PCI_D3cold
, 1);
1681 pci_enable_wake(pdev
, PCI_D3hot
, 1);
1687 static void qlcnic_shutdown(struct pci_dev
*pdev
)
1689 if (__qlcnic_shutdown(pdev
))
1692 pci_disable_device(pdev
);
1697 qlcnic_suspend(struct pci_dev
*pdev
, pm_message_t state
)
1701 retval
= __qlcnic_shutdown(pdev
);
1705 pci_set_power_state(pdev
, pci_choose_state(pdev
, state
));
1710 qlcnic_resume(struct pci_dev
*pdev
)
1712 struct qlcnic_adapter
*adapter
= pci_get_drvdata(pdev
);
1713 struct net_device
*netdev
= adapter
->netdev
;
1716 err
= pci_enable_device(pdev
);
1720 pci_set_power_state(pdev
, PCI_D0
);
1721 pci_set_master(pdev
);
1722 pci_restore_state(pdev
);
1724 err
= adapter
->nic_ops
->start_firmware(adapter
);
1726 dev_err(&pdev
->dev
, "failed to start firmware\n");
1730 if (netif_running(netdev
)) {
1731 err
= qlcnic_up(adapter
, netdev
);
1735 qlcnic_config_indev_addr(netdev
, NETDEV_UP
);
1738 netif_device_attach(netdev
);
1739 qlcnic_schedule_work(adapter
, qlcnic_fw_poll_work
, FW_POLL_DELAY
);
1744 static int qlcnic_open(struct net_device
*netdev
)
1746 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
1749 err
= qlcnic_attach(adapter
);
1753 err
= __qlcnic_up(adapter
, netdev
);
1757 netif_start_queue(netdev
);
1762 qlcnic_detach(adapter
);
1767 * qlcnic_close - Disables a network interface entry point
1769 static int qlcnic_close(struct net_device
*netdev
)
1771 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
1773 __qlcnic_down(adapter
, netdev
);
1778 qlcnic_tso_check(struct net_device
*netdev
,
1779 struct qlcnic_host_tx_ring
*tx_ring
,
1780 struct cmd_desc_type0
*first_desc
,
1781 struct sk_buff
*skb
)
1783 u8 opcode
= TX_ETHER_PKT
;
1784 __be16 protocol
= skb
->protocol
;
1786 int copied
, offset
, copy_len
, hdr_len
= 0, tso
= 0;
1787 struct cmd_desc_type0
*hwdesc
;
1788 struct vlan_ethhdr
*vh
;
1789 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
1790 u32 producer
= tx_ring
->producer
;
1791 int vlan_oob
= first_desc
->flags_opcode
& cpu_to_le16(FLAGS_VLAN_OOB
);
1793 if (*(skb
->data
) & BIT_0
) {
1795 memcpy(&first_desc
->eth_addr
, skb
->data
, ETH_ALEN
);
1798 if ((netdev
->features
& (NETIF_F_TSO
| NETIF_F_TSO6
)) &&
1799 skb_shinfo(skb
)->gso_size
> 0) {
1801 hdr_len
= skb_transport_offset(skb
) + tcp_hdrlen(skb
);
1803 first_desc
->mss
= cpu_to_le16(skb_shinfo(skb
)->gso_size
);
1804 first_desc
->total_hdr_length
= hdr_len
;
1806 first_desc
->total_hdr_length
+= VLAN_HLEN
;
1807 first_desc
->tcp_hdr_offset
= VLAN_HLEN
;
1808 first_desc
->ip_hdr_offset
= VLAN_HLEN
;
1809 /* Only in case of TSO on vlan device */
1810 flags
|= FLAGS_VLAN_TAGGED
;
1813 opcode
= (protocol
== cpu_to_be16(ETH_P_IPV6
)) ?
1814 TX_TCP_LSO6
: TX_TCP_LSO
;
1817 } else if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
1820 if (protocol
== cpu_to_be16(ETH_P_IP
)) {
1821 l4proto
= ip_hdr(skb
)->protocol
;
1823 if (l4proto
== IPPROTO_TCP
)
1824 opcode
= TX_TCP_PKT
;
1825 else if (l4proto
== IPPROTO_UDP
)
1826 opcode
= TX_UDP_PKT
;
1827 } else if (protocol
== cpu_to_be16(ETH_P_IPV6
)) {
1828 l4proto
= ipv6_hdr(skb
)->nexthdr
;
1830 if (l4proto
== IPPROTO_TCP
)
1831 opcode
= TX_TCPV6_PKT
;
1832 else if (l4proto
== IPPROTO_UDP
)
1833 opcode
= TX_UDPV6_PKT
;
1837 first_desc
->tcp_hdr_offset
+= skb_transport_offset(skb
);
1838 first_desc
->ip_hdr_offset
+= skb_network_offset(skb
);
1839 qlcnic_set_tx_flags_opcode(first_desc
, flags
, opcode
);
1844 /* For LSO, we need to copy the MAC/IP/TCP headers into
1845 * the descriptor ring
1851 /* Create a TSO vlan header template for firmware */
1853 hwdesc
= &tx_ring
->desc_head
[producer
];
1854 tx_ring
->cmd_buf_arr
[producer
].skb
= NULL
;
1856 copy_len
= min((int)sizeof(struct cmd_desc_type0
) - offset
,
1857 hdr_len
+ VLAN_HLEN
);
1859 vh
= (struct vlan_ethhdr
*)((char *)hwdesc
+ 2);
1860 skb_copy_from_linear_data(skb
, vh
, 12);
1861 vh
->h_vlan_proto
= htons(ETH_P_8021Q
);
1862 vh
->h_vlan_TCI
= htons(first_desc
->vlan_TCI
);
1863 skb_copy_from_linear_data_offset(skb
, 12,
1864 (char *)vh
+ 16, copy_len
- 16);
1866 copied
= copy_len
- VLAN_HLEN
;
1869 producer
= get_next_index(producer
, tx_ring
->num_desc
);
1872 while (copied
< hdr_len
) {
1874 copy_len
= min((int)sizeof(struct cmd_desc_type0
) - offset
,
1875 (hdr_len
- copied
));
1877 hwdesc
= &tx_ring
->desc_head
[producer
];
1878 tx_ring
->cmd_buf_arr
[producer
].skb
= NULL
;
1880 skb_copy_from_linear_data_offset(skb
, copied
,
1881 (char *)hwdesc
+ offset
, copy_len
);
1886 producer
= get_next_index(producer
, tx_ring
->num_desc
);
1889 tx_ring
->producer
= producer
;
1891 adapter
->stats
.lso_frames
++;
1895 qlcnic_map_tx_skb(struct pci_dev
*pdev
,
1896 struct sk_buff
*skb
, struct qlcnic_cmd_buffer
*pbuf
)
1898 struct qlcnic_skb_frag
*nf
;
1899 struct skb_frag_struct
*frag
;
1903 nr_frags
= skb_shinfo(skb
)->nr_frags
;
1904 nf
= &pbuf
->frag_array
[0];
1906 map
= pci_map_single(pdev
, skb
->data
,
1907 skb_headlen(skb
), PCI_DMA_TODEVICE
);
1908 if (pci_dma_mapping_error(pdev
, map
))
1912 nf
->length
= skb_headlen(skb
);
1914 for (i
= 0; i
< nr_frags
; i
++) {
1915 frag
= &skb_shinfo(skb
)->frags
[i
];
1916 nf
= &pbuf
->frag_array
[i
+1];
1918 map
= pci_map_page(pdev
, frag
->page
, frag
->page_offset
,
1919 frag
->size
, PCI_DMA_TODEVICE
);
1920 if (pci_dma_mapping_error(pdev
, map
))
1924 nf
->length
= frag
->size
;
1931 nf
= &pbuf
->frag_array
[i
+1];
1932 pci_unmap_page(pdev
, nf
->dma
, nf
->length
, PCI_DMA_TODEVICE
);
1935 nf
= &pbuf
->frag_array
[0];
1936 pci_unmap_single(pdev
, nf
->dma
, skb_headlen(skb
), PCI_DMA_TODEVICE
);
1943 qlcnic_check_tx_tagging(struct qlcnic_adapter
*adapter
,
1944 struct sk_buff
*skb
,
1945 struct cmd_desc_type0
*first_desc
)
1949 __be16 protocol
= skb
->protocol
;
1950 struct vlan_ethhdr
*vh
;
1952 if (protocol
== cpu_to_be16(ETH_P_8021Q
)) {
1953 vh
= (struct vlan_ethhdr
*)skb
->data
;
1954 protocol
= vh
->h_vlan_encapsulated_proto
;
1955 flags
= FLAGS_VLAN_TAGGED
;
1956 qlcnic_set_tx_vlan_tci(first_desc
, ntohs(vh
->h_vlan_TCI
));
1957 } else if (vlan_tx_tag_present(skb
)) {
1958 flags
= FLAGS_VLAN_OOB
;
1959 qlcnic_set_tx_vlan_tci(first_desc
, vlan_tx_tag_get(skb
));
1961 if (unlikely(adapter
->pvid
)) {
1962 if (first_desc
->vlan_TCI
&&
1963 !(adapter
->flags
& QLCNIC_TAGGING_ENABLED
))
1965 if (first_desc
->vlan_TCI
&&
1966 (adapter
->flags
& QLCNIC_TAGGING_ENABLED
))
1969 flags
= FLAGS_VLAN_OOB
;
1970 qlcnic_set_tx_vlan_tci(first_desc
, adapter
->pvid
);
1973 qlcnic_set_tx_flags_opcode(first_desc
, flags
, opcode
);
1978 qlcnic_clear_cmddesc(u64
*desc
)
1986 qlcnic_xmit_frame(struct sk_buff
*skb
, struct net_device
*netdev
)
1988 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
1989 struct qlcnic_host_tx_ring
*tx_ring
= adapter
->tx_ring
;
1990 struct qlcnic_cmd_buffer
*pbuf
;
1991 struct qlcnic_skb_frag
*buffrag
;
1992 struct cmd_desc_type0
*hwdesc
, *first_desc
;
1993 struct pci_dev
*pdev
;
1997 int frag_count
, no_of_desc
;
1998 u32 num_txd
= tx_ring
->num_desc
;
2000 if (!test_bit(__QLCNIC_DEV_UP
, &adapter
->state
)) {
2001 netif_stop_queue(netdev
);
2002 return NETDEV_TX_BUSY
;
2005 if (adapter
->flags
& QLCNIC_MACSPOOF
) {
2006 if (compare_ether_addr(eth_hdr(skb
)->h_source
,
2011 frag_count
= skb_shinfo(skb
)->nr_frags
+ 1;
2013 /* 4 fragments per cmd des */
2014 no_of_desc
= (frag_count
+ 3) >> 2;
2016 if (unlikely(qlcnic_tx_avail(tx_ring
) <= TX_STOP_THRESH
)) {
2017 netif_stop_queue(netdev
);
2019 if (qlcnic_tx_avail(tx_ring
) > TX_STOP_THRESH
)
2020 netif_start_queue(netdev
);
2022 adapter
->stats
.xmit_off
++;
2023 return NETDEV_TX_BUSY
;
2027 producer
= tx_ring
->producer
;
2028 pbuf
= &tx_ring
->cmd_buf_arr
[producer
];
2030 pdev
= adapter
->pdev
;
2032 first_desc
= hwdesc
= &tx_ring
->desc_head
[producer
];
2033 qlcnic_clear_cmddesc((u64
*)hwdesc
);
2035 if (qlcnic_check_tx_tagging(adapter
, skb
, first_desc
))
2038 if (qlcnic_map_tx_skb(pdev
, skb
, pbuf
)) {
2039 adapter
->stats
.tx_dma_map_error
++;
2044 pbuf
->frag_count
= frag_count
;
2046 qlcnic_set_tx_frags_len(first_desc
, frag_count
, skb
->len
);
2047 qlcnic_set_tx_port(first_desc
, adapter
->portnum
);
2049 for (i
= 0; i
< frag_count
; i
++) {
2053 if ((k
== 0) && (i
> 0)) {
2054 /* move to next desc.*/
2055 producer
= get_next_index(producer
, num_txd
);
2056 hwdesc
= &tx_ring
->desc_head
[producer
];
2057 qlcnic_clear_cmddesc((u64
*)hwdesc
);
2058 tx_ring
->cmd_buf_arr
[producer
].skb
= NULL
;
2061 buffrag
= &pbuf
->frag_array
[i
];
2063 hwdesc
->buffer_length
[k
] = cpu_to_le16(buffrag
->length
);
2066 hwdesc
->addr_buffer1
= cpu_to_le64(buffrag
->dma
);
2069 hwdesc
->addr_buffer2
= cpu_to_le64(buffrag
->dma
);
2072 hwdesc
->addr_buffer3
= cpu_to_le64(buffrag
->dma
);
2075 hwdesc
->addr_buffer4
= cpu_to_le64(buffrag
->dma
);
2080 tx_ring
->producer
= get_next_index(producer
, num_txd
);
2082 qlcnic_tso_check(netdev
, tx_ring
, first_desc
, skb
);
2084 qlcnic_update_cmd_producer(adapter
, tx_ring
);
2086 adapter
->stats
.txbytes
+= skb
->len
;
2087 adapter
->stats
.xmitcalled
++;
2089 return NETDEV_TX_OK
;
2092 adapter
->stats
.txdropped
++;
2093 dev_kfree_skb_any(skb
);
2094 return NETDEV_TX_OK
;
2097 static int qlcnic_check_temp(struct qlcnic_adapter
*adapter
)
2099 struct net_device
*netdev
= adapter
->netdev
;
2100 u32 temp
, temp_state
, temp_val
;
2103 temp
= QLCRD32(adapter
, CRB_TEMP_STATE
);
2105 temp_state
= qlcnic_get_temp_state(temp
);
2106 temp_val
= qlcnic_get_temp_val(temp
);
2108 if (temp_state
== QLCNIC_TEMP_PANIC
) {
2109 dev_err(&netdev
->dev
,
2110 "Device temperature %d degrees C exceeds"
2111 " maximum allowed. Hardware has been shut down.\n",
2114 } else if (temp_state
== QLCNIC_TEMP_WARN
) {
2115 if (adapter
->temp
== QLCNIC_TEMP_NORMAL
) {
2116 dev_err(&netdev
->dev
,
2117 "Device temperature %d degrees C "
2118 "exceeds operating range."
2119 " Immediate action needed.\n",
2123 if (adapter
->temp
== QLCNIC_TEMP_WARN
) {
2124 dev_info(&netdev
->dev
,
2125 "Device temperature is now %d degrees C"
2126 " in normal range.\n", temp_val
);
2129 adapter
->temp
= temp_state
;
2133 void qlcnic_advert_link_change(struct qlcnic_adapter
*adapter
, int linkup
)
2135 struct net_device
*netdev
= adapter
->netdev
;
2137 if (adapter
->ahw
.linkup
&& !linkup
) {
2138 netdev_info(netdev
, "NIC Link is down\n");
2139 adapter
->ahw
.linkup
= 0;
2140 if (netif_running(netdev
)) {
2141 netif_carrier_off(netdev
);
2142 netif_stop_queue(netdev
);
2144 } else if (!adapter
->ahw
.linkup
&& linkup
) {
2145 netdev_info(netdev
, "NIC Link is up\n");
2146 adapter
->ahw
.linkup
= 1;
2147 if (netif_running(netdev
)) {
2148 netif_carrier_on(netdev
);
2149 netif_wake_queue(netdev
);
2154 static void qlcnic_tx_timeout(struct net_device
*netdev
)
2156 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
2158 if (test_bit(__QLCNIC_RESETTING
, &adapter
->state
))
2161 dev_err(&netdev
->dev
, "transmit timeout, resetting.\n");
2163 if (++adapter
->tx_timeo_cnt
>= QLCNIC_MAX_TX_TIMEOUTS
)
2164 adapter
->need_fw_reset
= 1;
2166 adapter
->reset_context
= 1;
2169 static struct net_device_stats
*qlcnic_get_stats(struct net_device
*netdev
)
2171 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
2172 struct net_device_stats
*stats
= &netdev
->stats
;
2174 stats
->rx_packets
= adapter
->stats
.rx_pkts
+ adapter
->stats
.lro_pkts
;
2175 stats
->tx_packets
= adapter
->stats
.xmitfinished
;
2176 stats
->rx_bytes
= adapter
->stats
.rxbytes
+ adapter
->stats
.lrobytes
;
2177 stats
->tx_bytes
= adapter
->stats
.txbytes
;
2178 stats
->rx_dropped
= adapter
->stats
.rxdropped
;
2179 stats
->tx_dropped
= adapter
->stats
.txdropped
;
2184 static irqreturn_t
qlcnic_clear_legacy_intr(struct qlcnic_adapter
*adapter
)
2188 status
= readl(adapter
->isr_int_vec
);
2190 if (!(status
& adapter
->int_vec_bit
))
2193 /* check interrupt state machine, to be sure */
2194 status
= readl(adapter
->crb_int_state_reg
);
2195 if (!ISR_LEGACY_INT_TRIGGERED(status
))
2198 writel(0xffffffff, adapter
->tgt_status_reg
);
2199 /* read twice to ensure write is flushed */
2200 readl(adapter
->isr_int_vec
);
2201 readl(adapter
->isr_int_vec
);
2206 static irqreturn_t
qlcnic_tmp_intr(int irq
, void *data
)
2208 struct qlcnic_host_sds_ring
*sds_ring
= data
;
2209 struct qlcnic_adapter
*adapter
= sds_ring
->adapter
;
2211 if (adapter
->flags
& QLCNIC_MSIX_ENABLED
)
2213 else if (adapter
->flags
& QLCNIC_MSI_ENABLED
) {
2214 writel(0xffffffff, adapter
->tgt_status_reg
);
2218 if (qlcnic_clear_legacy_intr(adapter
) == IRQ_NONE
)
2222 adapter
->diag_cnt
++;
2223 qlcnic_enable_int(sds_ring
);
2227 static irqreturn_t
qlcnic_intr(int irq
, void *data
)
2229 struct qlcnic_host_sds_ring
*sds_ring
= data
;
2230 struct qlcnic_adapter
*adapter
= sds_ring
->adapter
;
2232 if (qlcnic_clear_legacy_intr(adapter
) == IRQ_NONE
)
2235 napi_schedule(&sds_ring
->napi
);
2240 static irqreturn_t
qlcnic_msi_intr(int irq
, void *data
)
2242 struct qlcnic_host_sds_ring
*sds_ring
= data
;
2243 struct qlcnic_adapter
*adapter
= sds_ring
->adapter
;
2245 /* clear interrupt */
2246 writel(0xffffffff, adapter
->tgt_status_reg
);
2248 napi_schedule(&sds_ring
->napi
);
2252 static irqreturn_t
qlcnic_msix_intr(int irq
, void *data
)
2254 struct qlcnic_host_sds_ring
*sds_ring
= data
;
2256 napi_schedule(&sds_ring
->napi
);
2260 static int qlcnic_process_cmd_ring(struct qlcnic_adapter
*adapter
)
2262 u32 sw_consumer
, hw_consumer
;
2264 struct qlcnic_cmd_buffer
*buffer
;
2265 struct pci_dev
*pdev
= adapter
->pdev
;
2266 struct net_device
*netdev
= adapter
->netdev
;
2267 struct qlcnic_skb_frag
*frag
;
2269 struct qlcnic_host_tx_ring
*tx_ring
= adapter
->tx_ring
;
2271 if (!spin_trylock(&adapter
->tx_clean_lock
))
2274 sw_consumer
= tx_ring
->sw_consumer
;
2275 hw_consumer
= le32_to_cpu(*(tx_ring
->hw_consumer
));
2277 while (sw_consumer
!= hw_consumer
) {
2278 buffer
= &tx_ring
->cmd_buf_arr
[sw_consumer
];
2280 frag
= &buffer
->frag_array
[0];
2281 pci_unmap_single(pdev
, frag
->dma
, frag
->length
,
2284 for (i
= 1; i
< buffer
->frag_count
; i
++) {
2286 pci_unmap_page(pdev
, frag
->dma
, frag
->length
,
2291 adapter
->stats
.xmitfinished
++;
2292 dev_kfree_skb_any(buffer
->skb
);
2296 sw_consumer
= get_next_index(sw_consumer
, tx_ring
->num_desc
);
2297 if (++count
>= MAX_STATUS_HANDLE
)
2301 if (count
&& netif_running(netdev
)) {
2302 tx_ring
->sw_consumer
= sw_consumer
;
2306 if (netif_queue_stopped(netdev
) && netif_carrier_ok(netdev
)) {
2307 if (qlcnic_tx_avail(tx_ring
) > TX_STOP_THRESH
) {
2308 netif_wake_queue(netdev
);
2309 adapter
->stats
.xmit_on
++;
2312 adapter
->tx_timeo_cnt
= 0;
2315 * If everything is freed up to consumer then check if the ring is full
2316 * If the ring is full then check if more needs to be freed and
2317 * schedule the call back again.
2319 * This happens when there are 2 CPUs. One could be freeing and the
2320 * other filling it. If the ring is full when we get out of here and
2321 * the card has already interrupted the host then the host can miss the
2324 * There is still a possible race condition and the host could miss an
2325 * interrupt. The card has to take care of this.
2327 hw_consumer
= le32_to_cpu(*(tx_ring
->hw_consumer
));
2328 done
= (sw_consumer
== hw_consumer
);
2329 spin_unlock(&adapter
->tx_clean_lock
);
2334 static int qlcnic_poll(struct napi_struct
*napi
, int budget
)
2336 struct qlcnic_host_sds_ring
*sds_ring
=
2337 container_of(napi
, struct qlcnic_host_sds_ring
, napi
);
2339 struct qlcnic_adapter
*adapter
= sds_ring
->adapter
;
2344 tx_complete
= qlcnic_process_cmd_ring(adapter
);
2346 work_done
= qlcnic_process_rcv_ring(sds_ring
, budget
);
2348 if ((work_done
< budget
) && tx_complete
) {
2349 napi_complete(&sds_ring
->napi
);
2350 if (test_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
2351 qlcnic_enable_int(sds_ring
);
2357 static int qlcnic_rx_poll(struct napi_struct
*napi
, int budget
)
2359 struct qlcnic_host_sds_ring
*sds_ring
=
2360 container_of(napi
, struct qlcnic_host_sds_ring
, napi
);
2362 struct qlcnic_adapter
*adapter
= sds_ring
->adapter
;
2365 work_done
= qlcnic_process_rcv_ring(sds_ring
, budget
);
2367 if (work_done
< budget
) {
2368 napi_complete(&sds_ring
->napi
);
2369 if (test_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
2370 qlcnic_enable_int(sds_ring
);
2376 #ifdef CONFIG_NET_POLL_CONTROLLER
2377 static void qlcnic_poll_controller(struct net_device
*netdev
)
2379 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
2380 disable_irq(adapter
->irq
);
2381 qlcnic_intr(adapter
->irq
, adapter
);
2382 enable_irq(adapter
->irq
);
2387 qlcnic_idc_debug_info(struct qlcnic_adapter
*adapter
, u8 encoding
)
2391 val
= adapter
->portnum
& 0xf;
2392 val
|= encoding
<< 7;
2393 val
|= (jiffies
- adapter
->dev_rst_time
) << 8;
2395 QLCWR32(adapter
, QLCNIC_CRB_DRV_SCRATCH
, val
);
2396 adapter
->dev_rst_time
= jiffies
;
2400 qlcnic_set_drv_state(struct qlcnic_adapter
*adapter
, u8 state
)
2404 WARN_ON(state
!= QLCNIC_DEV_NEED_RESET
&&
2405 state
!= QLCNIC_DEV_NEED_QUISCENT
);
2407 if (qlcnic_api_lock(adapter
))
2410 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_STATE
);
2412 if (state
== QLCNIC_DEV_NEED_RESET
)
2413 QLC_DEV_SET_RST_RDY(val
, adapter
->portnum
);
2414 else if (state
== QLCNIC_DEV_NEED_QUISCENT
)
2415 QLC_DEV_SET_QSCNT_RDY(val
, adapter
->portnum
);
2417 QLCWR32(adapter
, QLCNIC_CRB_DRV_STATE
, val
);
2419 qlcnic_api_unlock(adapter
);
2425 qlcnic_clr_drv_state(struct qlcnic_adapter
*adapter
)
2429 if (qlcnic_api_lock(adapter
))
2432 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_STATE
);
2433 QLC_DEV_CLR_RST_QSCNT(val
, adapter
->portnum
);
2434 QLCWR32(adapter
, QLCNIC_CRB_DRV_STATE
, val
);
2436 qlcnic_api_unlock(adapter
);
2442 qlcnic_clr_all_drv_state(struct qlcnic_adapter
*adapter
, u8 failed
)
2446 if (qlcnic_api_lock(adapter
))
2449 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_ACTIVE
);
2450 QLC_DEV_CLR_REF_CNT(val
, adapter
->portnum
);
2451 QLCWR32(adapter
, QLCNIC_CRB_DRV_ACTIVE
, val
);
2454 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
, QLCNIC_DEV_FAILED
);
2455 dev_info(&adapter
->pdev
->dev
,
2456 "Device state set to Failed. Please Reboot\n");
2457 } else if (!(val
& 0x11111111))
2458 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
, QLCNIC_DEV_COLD
);
2460 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_STATE
);
2461 QLC_DEV_CLR_RST_QSCNT(val
, adapter
->portnum
);
2462 QLCWR32(adapter
, QLCNIC_CRB_DRV_STATE
, val
);
2464 qlcnic_api_unlock(adapter
);
2466 adapter
->fw_fail_cnt
= 0;
2467 clear_bit(__QLCNIC_START_FW
, &adapter
->state
);
2468 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
2471 /* Grab api lock, before checking state */
2473 qlcnic_check_drv_state(struct qlcnic_adapter
*adapter
)
2477 state
= QLCRD32(adapter
, QLCNIC_CRB_DRV_STATE
);
2478 act
= QLCRD32(adapter
, QLCNIC_CRB_DRV_ACTIVE
);
2480 if (((state
& 0x11111111) == (act
& 0x11111111)) ||
2481 ((act
& 0x11111111) == ((state
>> 1) & 0x11111111)))
2487 static int qlcnic_check_idc_ver(struct qlcnic_adapter
*adapter
)
2489 u32 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_IDC_VER
);
2491 if (val
!= QLCNIC_DRV_IDC_VER
) {
2492 dev_warn(&adapter
->pdev
->dev
, "IDC Version mismatch, driver's"
2493 " idc ver = %x; reqd = %x\n", QLCNIC_DRV_IDC_VER
, val
);
2500 qlcnic_can_start_firmware(struct qlcnic_adapter
*adapter
)
2502 u32 val
, prev_state
;
2503 u8 dev_init_timeo
= adapter
->dev_init_timeo
;
2504 u8 portnum
= adapter
->portnum
;
2507 if (test_and_clear_bit(__QLCNIC_START_FW
, &adapter
->state
))
2510 if (qlcnic_api_lock(adapter
))
2513 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_ACTIVE
);
2514 if (!(val
& (1 << (portnum
* 4)))) {
2515 QLC_DEV_SET_REF_CNT(val
, portnum
);
2516 QLCWR32(adapter
, QLCNIC_CRB_DRV_ACTIVE
, val
);
2519 prev_state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
);
2520 QLCDB(adapter
, HW
, "Device state = %u\n", prev_state
);
2522 switch (prev_state
) {
2523 case QLCNIC_DEV_COLD
:
2524 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
, QLCNIC_DEV_INITIALIZING
);
2525 QLCWR32(adapter
, QLCNIC_CRB_DRV_IDC_VER
, QLCNIC_DRV_IDC_VER
);
2526 qlcnic_idc_debug_info(adapter
, 0);
2527 qlcnic_api_unlock(adapter
);
2530 case QLCNIC_DEV_READY
:
2531 ret
= qlcnic_check_idc_ver(adapter
);
2532 qlcnic_api_unlock(adapter
);
2535 case QLCNIC_DEV_NEED_RESET
:
2536 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_STATE
);
2537 QLC_DEV_SET_RST_RDY(val
, portnum
);
2538 QLCWR32(adapter
, QLCNIC_CRB_DRV_STATE
, val
);
2541 case QLCNIC_DEV_NEED_QUISCENT
:
2542 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_STATE
);
2543 QLC_DEV_SET_QSCNT_RDY(val
, portnum
);
2544 QLCWR32(adapter
, QLCNIC_CRB_DRV_STATE
, val
);
2547 case QLCNIC_DEV_FAILED
:
2548 dev_err(&adapter
->pdev
->dev
, "Device in failed state.\n");
2549 qlcnic_api_unlock(adapter
);
2552 case QLCNIC_DEV_INITIALIZING
:
2553 case QLCNIC_DEV_QUISCENT
:
2557 qlcnic_api_unlock(adapter
);
2561 prev_state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
);
2563 if (prev_state
== QLCNIC_DEV_QUISCENT
)
2565 } while ((prev_state
!= QLCNIC_DEV_READY
) && --dev_init_timeo
);
2567 if (!dev_init_timeo
) {
2568 dev_err(&adapter
->pdev
->dev
,
2569 "Waiting for device to initialize timeout\n");
2573 if (qlcnic_api_lock(adapter
))
2576 val
= QLCRD32(adapter
, QLCNIC_CRB_DRV_STATE
);
2577 QLC_DEV_CLR_RST_QSCNT(val
, portnum
);
2578 QLCWR32(adapter
, QLCNIC_CRB_DRV_STATE
, val
);
2580 ret
= qlcnic_check_idc_ver(adapter
);
2581 qlcnic_api_unlock(adapter
);
2587 qlcnic_fwinit_work(struct work_struct
*work
)
2589 struct qlcnic_adapter
*adapter
= container_of(work
,
2590 struct qlcnic_adapter
, fw_work
.work
);
2591 u32 dev_state
= 0xf;
2593 if (qlcnic_api_lock(adapter
))
2596 dev_state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
);
2597 if (dev_state
== QLCNIC_DEV_QUISCENT
) {
2598 qlcnic_api_unlock(adapter
);
2599 qlcnic_schedule_work(adapter
, qlcnic_fwinit_work
,
2604 if (adapter
->op_mode
== QLCNIC_NON_PRIV_FUNC
) {
2605 qlcnic_api_unlock(adapter
);
2609 if (adapter
->fw_wait_cnt
++ > adapter
->reset_ack_timeo
) {
2610 dev_err(&adapter
->pdev
->dev
, "Reset:Failed to get ack %d sec\n",
2611 adapter
->reset_ack_timeo
);
2612 goto skip_ack_check
;
2615 if (!qlcnic_check_drv_state(adapter
)) {
2617 dev_state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
);
2619 if (dev_state
== QLCNIC_DEV_NEED_QUISCENT
) {
2620 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
,
2621 QLCNIC_DEV_QUISCENT
);
2622 qlcnic_schedule_work(adapter
, qlcnic_fwinit_work
,
2624 QLCDB(adapter
, DRV
, "Quiscing the driver\n");
2625 qlcnic_idc_debug_info(adapter
, 0);
2627 qlcnic_api_unlock(adapter
);
2631 if (dev_state
== QLCNIC_DEV_NEED_RESET
) {
2632 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
,
2633 QLCNIC_DEV_INITIALIZING
);
2634 set_bit(__QLCNIC_START_FW
, &adapter
->state
);
2635 QLCDB(adapter
, DRV
, "Restarting fw\n");
2636 qlcnic_idc_debug_info(adapter
, 0);
2639 qlcnic_api_unlock(adapter
);
2641 if (!adapter
->nic_ops
->start_firmware(adapter
)) {
2642 qlcnic_schedule_work(adapter
, qlcnic_attach_work
, 0);
2643 adapter
->fw_wait_cnt
= 0;
2649 qlcnic_api_unlock(adapter
);
2652 dev_state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
);
2653 QLCDB(adapter
, HW
, "Func waiting: Device state=%u\n", dev_state
);
2655 switch (dev_state
) {
2656 case QLCNIC_DEV_READY
:
2657 if (!adapter
->nic_ops
->start_firmware(adapter
)) {
2658 qlcnic_schedule_work(adapter
, qlcnic_attach_work
, 0);
2659 adapter
->fw_wait_cnt
= 0;
2662 case QLCNIC_DEV_FAILED
:
2665 qlcnic_schedule_work(adapter
,
2666 qlcnic_fwinit_work
, FW_POLL_DELAY
);
2671 dev_err(&adapter
->pdev
->dev
, "Fwinit work failed state=%u "
2672 "fw_wait_cnt=%u\n", dev_state
, adapter
->fw_wait_cnt
);
2673 netif_device_attach(adapter
->netdev
);
2674 qlcnic_clr_all_drv_state(adapter
, 0);
2678 qlcnic_detach_work(struct work_struct
*work
)
2680 struct qlcnic_adapter
*adapter
= container_of(work
,
2681 struct qlcnic_adapter
, fw_work
.work
);
2682 struct net_device
*netdev
= adapter
->netdev
;
2685 netif_device_detach(netdev
);
2687 qlcnic_down(adapter
, netdev
);
2689 status
= QLCRD32(adapter
, QLCNIC_PEG_HALT_STATUS1
);
2691 if (status
& QLCNIC_RCODE_FATAL_ERROR
)
2694 if (adapter
->temp
== QLCNIC_TEMP_PANIC
)
2697 if (qlcnic_set_drv_state(adapter
, adapter
->dev_state
))
2700 adapter
->fw_wait_cnt
= 0;
2702 qlcnic_schedule_work(adapter
, qlcnic_fwinit_work
, FW_POLL_DELAY
);
2707 dev_err(&adapter
->pdev
->dev
, "detach failed; status=%d temp=%d\n",
2708 status
, adapter
->temp
);
2709 netif_device_attach(netdev
);
2710 qlcnic_clr_all_drv_state(adapter
, 1);
2713 /*Transit NPAR state to NON Operational */
2715 qlcnic_set_npar_non_operational(struct qlcnic_adapter
*adapter
)
2719 state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_NPAR_STATE
);
2720 if (state
== QLCNIC_DEV_NPAR_NON_OPER
)
2723 if (qlcnic_api_lock(adapter
))
2725 QLCWR32(adapter
, QLCNIC_CRB_DEV_NPAR_STATE
, QLCNIC_DEV_NPAR_NON_OPER
);
2726 qlcnic_api_unlock(adapter
);
2729 /*Transit to RESET state from READY state only */
2731 qlcnic_dev_request_reset(struct qlcnic_adapter
*adapter
)
2735 adapter
->need_fw_reset
= 1;
2736 if (qlcnic_api_lock(adapter
))
2739 state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
);
2741 if (state
== QLCNIC_DEV_READY
) {
2742 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
, QLCNIC_DEV_NEED_RESET
);
2743 QLCDB(adapter
, DRV
, "NEED_RESET state set\n");
2744 qlcnic_idc_debug_info(adapter
, 0);
2747 QLCWR32(adapter
, QLCNIC_CRB_DEV_NPAR_STATE
, QLCNIC_DEV_NPAR_NON_OPER
);
2748 qlcnic_api_unlock(adapter
);
2751 /* Transit to NPAR READY state from NPAR NOT READY state */
2753 qlcnic_dev_set_npar_ready(struct qlcnic_adapter
*adapter
)
2755 if (qlcnic_api_lock(adapter
))
2758 QLCWR32(adapter
, QLCNIC_CRB_DEV_NPAR_STATE
, QLCNIC_DEV_NPAR_OPER
);
2759 QLCDB(adapter
, DRV
, "NPAR operational state set\n");
2761 qlcnic_api_unlock(adapter
);
2765 qlcnic_schedule_work(struct qlcnic_adapter
*adapter
,
2766 work_func_t func
, int delay
)
2768 if (test_bit(__QLCNIC_AER
, &adapter
->state
))
2771 INIT_DELAYED_WORK(&adapter
->fw_work
, func
);
2772 schedule_delayed_work(&adapter
->fw_work
, round_jiffies_relative(delay
));
2776 qlcnic_cancel_fw_work(struct qlcnic_adapter
*adapter
)
2778 while (test_and_set_bit(__QLCNIC_RESETTING
, &adapter
->state
))
2781 cancel_delayed_work_sync(&adapter
->fw_work
);
2785 qlcnic_attach_work(struct work_struct
*work
)
2787 struct qlcnic_adapter
*adapter
= container_of(work
,
2788 struct qlcnic_adapter
, fw_work
.work
);
2789 struct net_device
*netdev
= adapter
->netdev
;
2792 if (adapter
->op_mode
!= QLCNIC_MGMT_FUNC
) {
2793 npar_state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_NPAR_STATE
);
2794 if (adapter
->fw_wait_cnt
++ > QLCNIC_DEV_NPAR_OPER_TIMEO
)
2795 qlcnic_clr_all_drv_state(adapter
, 0);
2796 else if (npar_state
!= QLCNIC_DEV_NPAR_OPER
)
2797 qlcnic_schedule_work(adapter
, qlcnic_attach_work
,
2801 QLCDB(adapter
, DRV
, "Waiting for NPAR state to operational\n");
2805 if (netif_running(netdev
)) {
2806 if (qlcnic_up(adapter
, netdev
))
2809 qlcnic_config_indev_addr(netdev
, NETDEV_UP
);
2813 netif_device_attach(netdev
);
2814 adapter
->fw_fail_cnt
= 0;
2815 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
2817 if (!qlcnic_clr_drv_state(adapter
))
2818 qlcnic_schedule_work(adapter
, qlcnic_fw_poll_work
,
2823 qlcnic_check_health(struct qlcnic_adapter
*adapter
)
2825 u32 state
= 0, heartbeat
;
2826 struct net_device
*netdev
= adapter
->netdev
;
2828 if (qlcnic_check_temp(adapter
))
2831 if (adapter
->need_fw_reset
)
2832 qlcnic_dev_request_reset(adapter
);
2834 state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
);
2835 if (state
== QLCNIC_DEV_NEED_RESET
||
2836 state
== QLCNIC_DEV_NEED_QUISCENT
) {
2837 qlcnic_set_npar_non_operational(adapter
);
2838 adapter
->need_fw_reset
= 1;
2841 heartbeat
= QLCRD32(adapter
, QLCNIC_PEG_ALIVE_COUNTER
);
2842 if (heartbeat
!= adapter
->heartbeat
) {
2843 adapter
->heartbeat
= heartbeat
;
2844 adapter
->fw_fail_cnt
= 0;
2845 if (adapter
->need_fw_reset
)
2848 if (adapter
->reset_context
&&
2849 auto_fw_reset
== AUTO_FW_RESET_ENABLED
) {
2850 qlcnic_reset_hw_context(adapter
);
2851 adapter
->netdev
->trans_start
= jiffies
;
2857 if (++adapter
->fw_fail_cnt
< FW_FAIL_THRESH
)
2860 qlcnic_dev_request_reset(adapter
);
2862 if ((auto_fw_reset
== AUTO_FW_RESET_ENABLED
))
2863 clear_bit(__QLCNIC_FW_ATTACHED
, &adapter
->state
);
2865 dev_info(&netdev
->dev
, "firmware hang detected\n");
2868 adapter
->dev_state
= (state
== QLCNIC_DEV_NEED_QUISCENT
) ? state
:
2869 QLCNIC_DEV_NEED_RESET
;
2871 if ((auto_fw_reset
== AUTO_FW_RESET_ENABLED
) &&
2872 !test_and_set_bit(__QLCNIC_RESETTING
, &adapter
->state
)) {
2874 qlcnic_schedule_work(adapter
, qlcnic_detach_work
, 0);
2875 QLCDB(adapter
, DRV
, "fw recovery scheduled.\n");
2882 qlcnic_fw_poll_work(struct work_struct
*work
)
2884 struct qlcnic_adapter
*adapter
= container_of(work
,
2885 struct qlcnic_adapter
, fw_work
.work
);
2887 if (test_bit(__QLCNIC_RESETTING
, &adapter
->state
))
2891 if (qlcnic_check_health(adapter
))
2895 qlcnic_schedule_work(adapter
, qlcnic_fw_poll_work
, FW_POLL_DELAY
);
2898 static int qlcnic_is_first_func(struct pci_dev
*pdev
)
2900 struct pci_dev
*oth_pdev
;
2901 int val
= pdev
->devfn
;
2904 oth_pdev
= pci_get_domain_bus_and_slot(pci_domain_nr
2905 (pdev
->bus
), pdev
->bus
->number
,
2906 PCI_DEVFN(PCI_SLOT(pdev
->devfn
), val
));
2910 if (oth_pdev
->current_state
!= PCI_D3cold
) {
2911 pci_dev_put(oth_pdev
);
2914 pci_dev_put(oth_pdev
);
2919 static int qlcnic_attach_func(struct pci_dev
*pdev
)
2921 int err
, first_func
;
2922 struct qlcnic_adapter
*adapter
= pci_get_drvdata(pdev
);
2923 struct net_device
*netdev
= adapter
->netdev
;
2925 pdev
->error_state
= pci_channel_io_normal
;
2927 err
= pci_enable_device(pdev
);
2931 pci_set_power_state(pdev
, PCI_D0
);
2932 pci_set_master(pdev
);
2933 pci_restore_state(pdev
);
2935 first_func
= qlcnic_is_first_func(pdev
);
2937 if (qlcnic_api_lock(adapter
))
2940 if (adapter
->op_mode
!= QLCNIC_NON_PRIV_FUNC
&& first_func
) {
2941 adapter
->need_fw_reset
= 1;
2942 set_bit(__QLCNIC_START_FW
, &adapter
->state
);
2943 QLCWR32(adapter
, QLCNIC_CRB_DEV_STATE
, QLCNIC_DEV_INITIALIZING
);
2944 QLCDB(adapter
, DRV
, "Restarting fw\n");
2946 qlcnic_api_unlock(adapter
);
2948 err
= adapter
->nic_ops
->start_firmware(adapter
);
2952 qlcnic_clr_drv_state(adapter
);
2953 qlcnic_setup_intr(adapter
);
2955 if (netif_running(netdev
)) {
2956 err
= qlcnic_attach(adapter
);
2958 qlcnic_clr_all_drv_state(adapter
, 1);
2959 clear_bit(__QLCNIC_AER
, &adapter
->state
);
2960 netif_device_attach(netdev
);
2964 err
= qlcnic_up(adapter
, netdev
);
2968 qlcnic_config_indev_addr(netdev
, NETDEV_UP
);
2971 netif_device_attach(netdev
);
2975 static pci_ers_result_t
qlcnic_io_error_detected(struct pci_dev
*pdev
,
2976 pci_channel_state_t state
)
2978 struct qlcnic_adapter
*adapter
= pci_get_drvdata(pdev
);
2979 struct net_device
*netdev
= adapter
->netdev
;
2981 if (state
== pci_channel_io_perm_failure
)
2982 return PCI_ERS_RESULT_DISCONNECT
;
2984 if (state
== pci_channel_io_normal
)
2985 return PCI_ERS_RESULT_RECOVERED
;
2987 set_bit(__QLCNIC_AER
, &adapter
->state
);
2988 netif_device_detach(netdev
);
2990 cancel_delayed_work_sync(&adapter
->fw_work
);
2992 if (netif_running(netdev
))
2993 qlcnic_down(adapter
, netdev
);
2995 qlcnic_detach(adapter
);
2996 qlcnic_teardown_intr(adapter
);
2998 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
3000 pci_save_state(pdev
);
3001 pci_disable_device(pdev
);
3003 return PCI_ERS_RESULT_NEED_RESET
;
3006 static pci_ers_result_t
qlcnic_io_slot_reset(struct pci_dev
*pdev
)
3008 return qlcnic_attach_func(pdev
) ? PCI_ERS_RESULT_DISCONNECT
:
3009 PCI_ERS_RESULT_RECOVERED
;
3012 static void qlcnic_io_resume(struct pci_dev
*pdev
)
3014 struct qlcnic_adapter
*adapter
= pci_get_drvdata(pdev
);
3016 pci_cleanup_aer_uncorrect_error_status(pdev
);
3018 if (QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
) == QLCNIC_DEV_READY
&&
3019 test_and_clear_bit(__QLCNIC_AER
, &adapter
->state
))
3020 qlcnic_schedule_work(adapter
, qlcnic_fw_poll_work
,
3025 qlcnicvf_start_firmware(struct qlcnic_adapter
*adapter
)
3029 err
= qlcnic_can_start_firmware(adapter
);
3033 err
= qlcnic_check_npar_opertional(adapter
);
3037 err
= qlcnic_initialize_nic(adapter
);
3041 qlcnic_check_options(adapter
);
3043 adapter
->need_fw_reset
= 0;
3049 qlcnicvf_config_bridged_mode(struct qlcnic_adapter
*adapter
, u32 enable
)
3055 qlcnicvf_config_led(struct qlcnic_adapter
*adapter
, u32 state
, u32 rate
)
3061 qlcnic_store_bridged_mode(struct device
*dev
,
3062 struct device_attribute
*attr
, const char *buf
, size_t len
)
3064 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3068 if (!(adapter
->capabilities
& QLCNIC_FW_CAPABILITY_BDG
))
3071 if (!test_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
3074 if (strict_strtoul(buf
, 2, &new))
3077 if (!adapter
->nic_ops
->config_bridged_mode(adapter
, !!new))
3085 qlcnic_show_bridged_mode(struct device
*dev
,
3086 struct device_attribute
*attr
, char *buf
)
3088 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3089 int bridged_mode
= 0;
3091 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_BDG
)
3092 bridged_mode
= !!(adapter
->flags
& QLCNIC_BRIDGE_ENABLED
);
3094 return sprintf(buf
, "%d\n", bridged_mode
);
3097 static struct device_attribute dev_attr_bridged_mode
= {
3098 .attr
= {.name
= "bridged_mode", .mode
= (S_IRUGO
| S_IWUSR
)},
3099 .show
= qlcnic_show_bridged_mode
,
3100 .store
= qlcnic_store_bridged_mode
,
3104 qlcnic_store_diag_mode(struct device
*dev
,
3105 struct device_attribute
*attr
, const char *buf
, size_t len
)
3107 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3110 if (strict_strtoul(buf
, 2, &new))
3113 if (!!new != !!(adapter
->flags
& QLCNIC_DIAG_ENABLED
))
3114 adapter
->flags
^= QLCNIC_DIAG_ENABLED
;
3120 qlcnic_show_diag_mode(struct device
*dev
,
3121 struct device_attribute
*attr
, char *buf
)
3123 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3125 return sprintf(buf
, "%d\n",
3126 !!(adapter
->flags
& QLCNIC_DIAG_ENABLED
));
3129 static struct device_attribute dev_attr_diag_mode
= {
3130 .attr
= {.name
= "diag_mode", .mode
= (S_IRUGO
| S_IWUSR
)},
3131 .show
= qlcnic_show_diag_mode
,
3132 .store
= qlcnic_store_diag_mode
,
3136 qlcnic_sysfs_validate_crb(struct qlcnic_adapter
*adapter
,
3137 loff_t offset
, size_t size
)
3139 size_t crb_size
= 4;
3141 if (!(adapter
->flags
& QLCNIC_DIAG_ENABLED
))
3144 if (offset
< QLCNIC_PCI_CRBSPACE
) {
3145 if (ADDR_IN_RANGE(offset
, QLCNIC_PCI_CAMQM
,
3146 QLCNIC_PCI_CAMQM_END
))
3152 if ((size
!= crb_size
) || (offset
& (crb_size
-1)))
3159 qlcnic_sysfs_read_crb(struct file
*filp
, struct kobject
*kobj
,
3160 struct bin_attribute
*attr
,
3161 char *buf
, loff_t offset
, size_t size
)
3163 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3164 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3169 ret
= qlcnic_sysfs_validate_crb(adapter
, offset
, size
);
3173 if (ADDR_IN_RANGE(offset
, QLCNIC_PCI_CAMQM
, QLCNIC_PCI_CAMQM_END
)) {
3174 qlcnic_pci_camqm_read_2M(adapter
, offset
, &qmdata
);
3175 memcpy(buf
, &qmdata
, size
);
3177 data
= QLCRD32(adapter
, offset
);
3178 memcpy(buf
, &data
, size
);
3184 qlcnic_sysfs_write_crb(struct file
*filp
, struct kobject
*kobj
,
3185 struct bin_attribute
*attr
,
3186 char *buf
, loff_t offset
, size_t size
)
3188 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3189 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3194 ret
= qlcnic_sysfs_validate_crb(adapter
, offset
, size
);
3198 if (ADDR_IN_RANGE(offset
, QLCNIC_PCI_CAMQM
, QLCNIC_PCI_CAMQM_END
)) {
3199 memcpy(&qmdata
, buf
, size
);
3200 qlcnic_pci_camqm_write_2M(adapter
, offset
, qmdata
);
3202 memcpy(&data
, buf
, size
);
3203 QLCWR32(adapter
, offset
, data
);
3209 qlcnic_sysfs_validate_mem(struct qlcnic_adapter
*adapter
,
3210 loff_t offset
, size_t size
)
3212 if (!(adapter
->flags
& QLCNIC_DIAG_ENABLED
))
3215 if ((size
!= 8) || (offset
& 0x7))
3222 qlcnic_sysfs_read_mem(struct file
*filp
, struct kobject
*kobj
,
3223 struct bin_attribute
*attr
,
3224 char *buf
, loff_t offset
, size_t size
)
3226 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3227 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3231 ret
= qlcnic_sysfs_validate_mem(adapter
, offset
, size
);
3235 if (qlcnic_pci_mem_read_2M(adapter
, offset
, &data
))
3238 memcpy(buf
, &data
, size
);
3244 qlcnic_sysfs_write_mem(struct file
*filp
, struct kobject
*kobj
,
3245 struct bin_attribute
*attr
,
3246 char *buf
, loff_t offset
, size_t size
)
3248 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3249 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3253 ret
= qlcnic_sysfs_validate_mem(adapter
, offset
, size
);
3257 memcpy(&data
, buf
, size
);
3259 if (qlcnic_pci_mem_write_2M(adapter
, offset
, data
))
3266 static struct bin_attribute bin_attr_crb
= {
3267 .attr
= {.name
= "crb", .mode
= (S_IRUGO
| S_IWUSR
)},
3269 .read
= qlcnic_sysfs_read_crb
,
3270 .write
= qlcnic_sysfs_write_crb
,
3273 static struct bin_attribute bin_attr_mem
= {
3274 .attr
= {.name
= "mem", .mode
= (S_IRUGO
| S_IWUSR
)},
3276 .read
= qlcnic_sysfs_read_mem
,
3277 .write
= qlcnic_sysfs_write_mem
,
3281 validate_pm_config(struct qlcnic_adapter
*adapter
,
3282 struct qlcnic_pm_func_cfg
*pm_cfg
, int count
)
3285 u8 src_pci_func
, s_esw_id
, d_esw_id
;
3289 for (i
= 0; i
< count
; i
++) {
3290 src_pci_func
= pm_cfg
[i
].pci_func
;
3291 dest_pci_func
= pm_cfg
[i
].dest_npar
;
3292 if (src_pci_func
>= QLCNIC_MAX_PCI_FUNC
3293 || dest_pci_func
>= QLCNIC_MAX_PCI_FUNC
)
3294 return QL_STATUS_INVALID_PARAM
;
3296 if (adapter
->npars
[src_pci_func
].type
!= QLCNIC_TYPE_NIC
)
3297 return QL_STATUS_INVALID_PARAM
;
3299 if (adapter
->npars
[dest_pci_func
].type
!= QLCNIC_TYPE_NIC
)
3300 return QL_STATUS_INVALID_PARAM
;
3302 s_esw_id
= adapter
->npars
[src_pci_func
].phy_port
;
3303 d_esw_id
= adapter
->npars
[dest_pci_func
].phy_port
;
3305 if (s_esw_id
!= d_esw_id
)
3306 return QL_STATUS_INVALID_PARAM
;
3314 qlcnic_sysfs_write_pm_config(struct file
*filp
, struct kobject
*kobj
,
3315 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3317 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3318 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3319 struct qlcnic_pm_func_cfg
*pm_cfg
;
3320 u32 id
, action
, pci_func
;
3321 int count
, rem
, i
, ret
;
3323 count
= size
/ sizeof(struct qlcnic_pm_func_cfg
);
3324 rem
= size
% sizeof(struct qlcnic_pm_func_cfg
);
3326 return QL_STATUS_INVALID_PARAM
;
3328 pm_cfg
= (struct qlcnic_pm_func_cfg
*) buf
;
3330 ret
= validate_pm_config(adapter
, pm_cfg
, count
);
3333 for (i
= 0; i
< count
; i
++) {
3334 pci_func
= pm_cfg
[i
].pci_func
;
3335 action
= !!pm_cfg
[i
].action
;
3336 id
= adapter
->npars
[pci_func
].phy_port
;
3337 ret
= qlcnic_config_port_mirroring(adapter
, id
,
3343 for (i
= 0; i
< count
; i
++) {
3344 pci_func
= pm_cfg
[i
].pci_func
;
3345 id
= adapter
->npars
[pci_func
].phy_port
;
3346 adapter
->npars
[pci_func
].enable_pm
= !!pm_cfg
[i
].action
;
3347 adapter
->npars
[pci_func
].dest_npar
= id
;
3353 qlcnic_sysfs_read_pm_config(struct file
*filp
, struct kobject
*kobj
,
3354 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3356 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3357 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3358 struct qlcnic_pm_func_cfg pm_cfg
[QLCNIC_MAX_PCI_FUNC
];
3361 if (size
!= sizeof(pm_cfg
))
3362 return QL_STATUS_INVALID_PARAM
;
3364 for (i
= 0; i
< QLCNIC_MAX_PCI_FUNC
; i
++) {
3365 if (adapter
->npars
[i
].type
!= QLCNIC_TYPE_NIC
)
3367 pm_cfg
[i
].action
= adapter
->npars
[i
].enable_pm
;
3368 pm_cfg
[i
].dest_npar
= 0;
3369 pm_cfg
[i
].pci_func
= i
;
3371 memcpy(buf
, &pm_cfg
, size
);
3377 validate_esw_config(struct qlcnic_adapter
*adapter
,
3378 struct qlcnic_esw_func_cfg
*esw_cfg
, int count
)
3384 op_mode
= readl(adapter
->ahw
.pci_base0
+ QLCNIC_DRV_OP_MODE
);
3386 for (i
= 0; i
< count
; i
++) {
3387 pci_func
= esw_cfg
[i
].pci_func
;
3388 if (pci_func
>= QLCNIC_MAX_PCI_FUNC
)
3389 return QL_STATUS_INVALID_PARAM
;
3391 if (adapter
->op_mode
== QLCNIC_MGMT_FUNC
)
3392 if (adapter
->npars
[pci_func
].type
!= QLCNIC_TYPE_NIC
)
3393 return QL_STATUS_INVALID_PARAM
;
3395 switch (esw_cfg
[i
].op_mode
) {
3396 case QLCNIC_PORT_DEFAULTS
:
3397 if (QLC_DEV_GET_DRV(op_mode
, pci_func
) !=
3398 QLCNIC_NON_PRIV_FUNC
)
3399 esw_cfg
[i
].mac_anti_spoof
= 0;
3401 case QLCNIC_ADD_VLAN
:
3402 if (!IS_VALID_VLAN(esw_cfg
[i
].vlan_id
))
3403 return QL_STATUS_INVALID_PARAM
;
3404 if (!esw_cfg
[i
].op_type
)
3405 return QL_STATUS_INVALID_PARAM
;
3407 case QLCNIC_DEL_VLAN
:
3408 if (!esw_cfg
[i
].op_type
)
3409 return QL_STATUS_INVALID_PARAM
;
3412 return QL_STATUS_INVALID_PARAM
;
3419 qlcnic_sysfs_write_esw_config(struct file
*file
, struct kobject
*kobj
,
3420 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3422 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3423 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3424 struct qlcnic_esw_func_cfg
*esw_cfg
;
3425 struct qlcnic_npar_info
*npar
;
3426 int count
, rem
, i
, ret
;
3427 u8 pci_func
, op_mode
= 0;
3429 count
= size
/ sizeof(struct qlcnic_esw_func_cfg
);
3430 rem
= size
% sizeof(struct qlcnic_esw_func_cfg
);
3432 return QL_STATUS_INVALID_PARAM
;
3434 esw_cfg
= (struct qlcnic_esw_func_cfg
*) buf
;
3435 ret
= validate_esw_config(adapter
, esw_cfg
, count
);
3439 for (i
= 0; i
< count
; i
++) {
3440 if (adapter
->op_mode
== QLCNIC_MGMT_FUNC
)
3441 if (qlcnic_config_switch_port(adapter
, &esw_cfg
[i
]))
3442 return QL_STATUS_INVALID_PARAM
;
3444 if (adapter
->ahw
.pci_func
!= esw_cfg
[i
].pci_func
)
3447 op_mode
= esw_cfg
[i
].op_mode
;
3448 qlcnic_get_eswitch_port_config(adapter
, &esw_cfg
[i
]);
3449 esw_cfg
[i
].op_mode
= op_mode
;
3450 esw_cfg
[i
].pci_func
= adapter
->ahw
.pci_func
;
3452 switch (esw_cfg
[i
].op_mode
) {
3453 case QLCNIC_PORT_DEFAULTS
:
3454 qlcnic_set_eswitch_port_features(adapter
, &esw_cfg
[i
]);
3456 case QLCNIC_ADD_VLAN
:
3457 qlcnic_set_vlan_config(adapter
, &esw_cfg
[i
]);
3459 case QLCNIC_DEL_VLAN
:
3460 esw_cfg
[i
].vlan_id
= 0;
3461 qlcnic_set_vlan_config(adapter
, &esw_cfg
[i
]);
3466 if (adapter
->op_mode
!= QLCNIC_MGMT_FUNC
)
3469 for (i
= 0; i
< count
; i
++) {
3470 pci_func
= esw_cfg
[i
].pci_func
;
3471 npar
= &adapter
->npars
[pci_func
];
3472 switch (esw_cfg
[i
].op_mode
) {
3473 case QLCNIC_PORT_DEFAULTS
:
3474 npar
->promisc_mode
= esw_cfg
[i
].promisc_mode
;
3475 npar
->mac_learning
= esw_cfg
[i
].mac_learning
;
3476 npar
->offload_flags
= esw_cfg
[i
].offload_flags
;
3477 npar
->mac_anti_spoof
= esw_cfg
[i
].mac_anti_spoof
;
3478 npar
->discard_tagged
= esw_cfg
[i
].discard_tagged
;
3480 case QLCNIC_ADD_VLAN
:
3481 npar
->pvid
= esw_cfg
[i
].vlan_id
;
3483 case QLCNIC_DEL_VLAN
:
3493 qlcnic_sysfs_read_esw_config(struct file
*file
, struct kobject
*kobj
,
3494 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3496 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3497 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3498 struct qlcnic_esw_func_cfg esw_cfg
[QLCNIC_MAX_PCI_FUNC
];
3501 if (size
!= sizeof(esw_cfg
))
3502 return QL_STATUS_INVALID_PARAM
;
3504 for (i
= 0; i
< QLCNIC_MAX_PCI_FUNC
; i
++) {
3505 if (adapter
->npars
[i
].type
!= QLCNIC_TYPE_NIC
)
3507 esw_cfg
[i
].pci_func
= i
;
3508 if (qlcnic_get_eswitch_port_config(adapter
, &esw_cfg
[i
]))
3509 return QL_STATUS_INVALID_PARAM
;
3511 memcpy(buf
, &esw_cfg
, size
);
3517 validate_npar_config(struct qlcnic_adapter
*adapter
,
3518 struct qlcnic_npar_func_cfg
*np_cfg
, int count
)
3522 for (i
= 0; i
< count
; i
++) {
3523 pci_func
= np_cfg
[i
].pci_func
;
3524 if (pci_func
>= QLCNIC_MAX_PCI_FUNC
)
3525 return QL_STATUS_INVALID_PARAM
;
3527 if (adapter
->npars
[pci_func
].type
!= QLCNIC_TYPE_NIC
)
3528 return QL_STATUS_INVALID_PARAM
;
3530 if (!IS_VALID_BW(np_cfg
[i
].min_bw
)
3531 || !IS_VALID_BW(np_cfg
[i
].max_bw
)
3532 || !IS_VALID_RX_QUEUES(np_cfg
[i
].max_rx_queues
)
3533 || !IS_VALID_TX_QUEUES(np_cfg
[i
].max_tx_queues
))
3534 return QL_STATUS_INVALID_PARAM
;
3540 qlcnic_sysfs_write_npar_config(struct file
*file
, struct kobject
*kobj
,
3541 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3543 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3544 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3545 struct qlcnic_info nic_info
;
3546 struct qlcnic_npar_func_cfg
*np_cfg
;
3547 int i
, count
, rem
, ret
;
3550 count
= size
/ sizeof(struct qlcnic_npar_func_cfg
);
3551 rem
= size
% sizeof(struct qlcnic_npar_func_cfg
);
3553 return QL_STATUS_INVALID_PARAM
;
3555 np_cfg
= (struct qlcnic_npar_func_cfg
*) buf
;
3556 ret
= validate_npar_config(adapter
, np_cfg
, count
);
3560 for (i
= 0; i
< count
; i
++) {
3561 pci_func
= np_cfg
[i
].pci_func
;
3562 ret
= qlcnic_get_nic_info(adapter
, &nic_info
, pci_func
);
3565 nic_info
.pci_func
= pci_func
;
3566 nic_info
.min_tx_bw
= np_cfg
[i
].min_bw
;
3567 nic_info
.max_tx_bw
= np_cfg
[i
].max_bw
;
3568 ret
= qlcnic_set_nic_info(adapter
, &nic_info
);
3571 adapter
->npars
[i
].min_bw
= nic_info
.min_tx_bw
;
3572 adapter
->npars
[i
].max_bw
= nic_info
.max_tx_bw
;
3579 qlcnic_sysfs_read_npar_config(struct file
*file
, struct kobject
*kobj
,
3580 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3582 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3583 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3584 struct qlcnic_info nic_info
;
3585 struct qlcnic_npar_func_cfg np_cfg
[QLCNIC_MAX_PCI_FUNC
];
3588 if (size
!= sizeof(np_cfg
))
3589 return QL_STATUS_INVALID_PARAM
;
3591 for (i
= 0; i
< QLCNIC_MAX_PCI_FUNC
; i
++) {
3592 if (adapter
->npars
[i
].type
!= QLCNIC_TYPE_NIC
)
3594 ret
= qlcnic_get_nic_info(adapter
, &nic_info
, i
);
3598 np_cfg
[i
].pci_func
= i
;
3599 np_cfg
[i
].op_mode
= nic_info
.op_mode
;
3600 np_cfg
[i
].port_num
= nic_info
.phys_port
;
3601 np_cfg
[i
].fw_capab
= nic_info
.capabilities
;
3602 np_cfg
[i
].min_bw
= nic_info
.min_tx_bw
;
3603 np_cfg
[i
].max_bw
= nic_info
.max_tx_bw
;
3604 np_cfg
[i
].max_tx_queues
= nic_info
.max_tx_ques
;
3605 np_cfg
[i
].max_rx_queues
= nic_info
.max_rx_ques
;
3607 memcpy(buf
, &np_cfg
, size
);
3612 qlcnic_sysfs_get_port_stats(struct file
*file
, struct kobject
*kobj
,
3613 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3615 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3616 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3617 struct qlcnic_esw_statistics port_stats
;
3620 if (size
!= sizeof(struct qlcnic_esw_statistics
))
3621 return QL_STATUS_INVALID_PARAM
;
3623 if (offset
>= QLCNIC_MAX_PCI_FUNC
)
3624 return QL_STATUS_INVALID_PARAM
;
3626 memset(&port_stats
, 0, size
);
3627 ret
= qlcnic_get_port_stats(adapter
, offset
, QLCNIC_QUERY_RX_COUNTER
,
3632 ret
= qlcnic_get_port_stats(adapter
, offset
, QLCNIC_QUERY_TX_COUNTER
,
3637 memcpy(buf
, &port_stats
, size
);
3642 qlcnic_sysfs_get_esw_stats(struct file
*file
, struct kobject
*kobj
,
3643 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3645 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3646 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3647 struct qlcnic_esw_statistics esw_stats
;
3650 if (size
!= sizeof(struct qlcnic_esw_statistics
))
3651 return QL_STATUS_INVALID_PARAM
;
3653 if (offset
>= QLCNIC_NIU_MAX_XG_PORTS
)
3654 return QL_STATUS_INVALID_PARAM
;
3656 memset(&esw_stats
, 0, size
);
3657 ret
= qlcnic_get_eswitch_stats(adapter
, offset
, QLCNIC_QUERY_RX_COUNTER
,
3662 ret
= qlcnic_get_eswitch_stats(adapter
, offset
, QLCNIC_QUERY_TX_COUNTER
,
3667 memcpy(buf
, &esw_stats
, size
);
3672 qlcnic_sysfs_clear_esw_stats(struct file
*file
, struct kobject
*kobj
,
3673 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3675 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3676 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3679 if (offset
>= QLCNIC_NIU_MAX_XG_PORTS
)
3680 return QL_STATUS_INVALID_PARAM
;
3682 ret
= qlcnic_clear_esw_stats(adapter
, QLCNIC_STATS_ESWITCH
, offset
,
3683 QLCNIC_QUERY_RX_COUNTER
);
3687 ret
= qlcnic_clear_esw_stats(adapter
, QLCNIC_STATS_ESWITCH
, offset
,
3688 QLCNIC_QUERY_TX_COUNTER
);
3696 qlcnic_sysfs_clear_port_stats(struct file
*file
, struct kobject
*kobj
,
3697 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3700 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3701 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3704 if (offset
>= QLCNIC_MAX_PCI_FUNC
)
3705 return QL_STATUS_INVALID_PARAM
;
3707 ret
= qlcnic_clear_esw_stats(adapter
, QLCNIC_STATS_PORT
, offset
,
3708 QLCNIC_QUERY_RX_COUNTER
);
3712 ret
= qlcnic_clear_esw_stats(adapter
, QLCNIC_STATS_PORT
, offset
,
3713 QLCNIC_QUERY_TX_COUNTER
);
3721 qlcnic_sysfs_read_pci_config(struct file
*file
, struct kobject
*kobj
,
3722 struct bin_attribute
*attr
, char *buf
, loff_t offset
, size_t size
)
3724 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3725 struct qlcnic_adapter
*adapter
= dev_get_drvdata(dev
);
3726 struct qlcnic_pci_func_cfg pci_cfg
[QLCNIC_MAX_PCI_FUNC
];
3727 struct qlcnic_pci_info
*pci_info
;
3730 if (size
!= sizeof(pci_cfg
))
3731 return QL_STATUS_INVALID_PARAM
;
3733 pci_info
= kcalloc(QLCNIC_MAX_PCI_FUNC
, sizeof(*pci_info
), GFP_KERNEL
);
3737 ret
= qlcnic_get_pci_info(adapter
, pci_info
);
3743 for (i
= 0; i
< QLCNIC_MAX_PCI_FUNC
; i
++) {
3744 pci_cfg
[i
].pci_func
= pci_info
[i
].id
;
3745 pci_cfg
[i
].func_type
= pci_info
[i
].type
;
3746 pci_cfg
[i
].port_num
= pci_info
[i
].default_port
;
3747 pci_cfg
[i
].min_bw
= pci_info
[i
].tx_min_bw
;
3748 pci_cfg
[i
].max_bw
= pci_info
[i
].tx_max_bw
;
3749 memcpy(&pci_cfg
[i
].def_mac_addr
, &pci_info
[i
].mac
, ETH_ALEN
);
3751 memcpy(buf
, &pci_cfg
, size
);
3755 static struct bin_attribute bin_attr_npar_config
= {
3756 .attr
= {.name
= "npar_config", .mode
= (S_IRUGO
| S_IWUSR
)},
3758 .read
= qlcnic_sysfs_read_npar_config
,
3759 .write
= qlcnic_sysfs_write_npar_config
,
3762 static struct bin_attribute bin_attr_pci_config
= {
3763 .attr
= {.name
= "pci_config", .mode
= (S_IRUGO
| S_IWUSR
)},
3765 .read
= qlcnic_sysfs_read_pci_config
,
3769 static struct bin_attribute bin_attr_port_stats
= {
3770 .attr
= {.name
= "port_stats", .mode
= (S_IRUGO
| S_IWUSR
)},
3772 .read
= qlcnic_sysfs_get_port_stats
,
3773 .write
= qlcnic_sysfs_clear_port_stats
,
3776 static struct bin_attribute bin_attr_esw_stats
= {
3777 .attr
= {.name
= "esw_stats", .mode
= (S_IRUGO
| S_IWUSR
)},
3779 .read
= qlcnic_sysfs_get_esw_stats
,
3780 .write
= qlcnic_sysfs_clear_esw_stats
,
3783 static struct bin_attribute bin_attr_esw_config
= {
3784 .attr
= {.name
= "esw_config", .mode
= (S_IRUGO
| S_IWUSR
)},
3786 .read
= qlcnic_sysfs_read_esw_config
,
3787 .write
= qlcnic_sysfs_write_esw_config
,
3790 static struct bin_attribute bin_attr_pm_config
= {
3791 .attr
= {.name
= "pm_config", .mode
= (S_IRUGO
| S_IWUSR
)},
3793 .read
= qlcnic_sysfs_read_pm_config
,
3794 .write
= qlcnic_sysfs_write_pm_config
,
3798 qlcnic_create_sysfs_entries(struct qlcnic_adapter
*adapter
)
3800 struct device
*dev
= &adapter
->pdev
->dev
;
3802 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_BDG
)
3803 if (device_create_file(dev
, &dev_attr_bridged_mode
))
3805 "failed to create bridged_mode sysfs entry\n");
3809 qlcnic_remove_sysfs_entries(struct qlcnic_adapter
*adapter
)
3811 struct device
*dev
= &adapter
->pdev
->dev
;
3813 if (adapter
->capabilities
& QLCNIC_FW_CAPABILITY_BDG
)
3814 device_remove_file(dev
, &dev_attr_bridged_mode
);
3818 qlcnic_create_diag_entries(struct qlcnic_adapter
*adapter
)
3820 struct device
*dev
= &adapter
->pdev
->dev
;
3822 if (device_create_bin_file(dev
, &bin_attr_port_stats
))
3823 dev_info(dev
, "failed to create port stats sysfs entry");
3825 if (adapter
->op_mode
== QLCNIC_NON_PRIV_FUNC
)
3827 if (device_create_file(dev
, &dev_attr_diag_mode
))
3828 dev_info(dev
, "failed to create diag_mode sysfs entry\n");
3829 if (device_create_bin_file(dev
, &bin_attr_crb
))
3830 dev_info(dev
, "failed to create crb sysfs entry\n");
3831 if (device_create_bin_file(dev
, &bin_attr_mem
))
3832 dev_info(dev
, "failed to create mem sysfs entry\n");
3833 if (!(adapter
->flags
& QLCNIC_ESWITCH_ENABLED
))
3835 if (device_create_bin_file(dev
, &bin_attr_esw_config
))
3836 dev_info(dev
, "failed to create esw config sysfs entry");
3837 if (adapter
->op_mode
!= QLCNIC_MGMT_FUNC
)
3839 if (device_create_bin_file(dev
, &bin_attr_pci_config
))
3840 dev_info(dev
, "failed to create pci config sysfs entry");
3841 if (device_create_bin_file(dev
, &bin_attr_npar_config
))
3842 dev_info(dev
, "failed to create npar config sysfs entry");
3843 if (device_create_bin_file(dev
, &bin_attr_pm_config
))
3844 dev_info(dev
, "failed to create pm config sysfs entry");
3845 if (device_create_bin_file(dev
, &bin_attr_esw_stats
))
3846 dev_info(dev
, "failed to create eswitch stats sysfs entry");
3850 qlcnic_remove_diag_entries(struct qlcnic_adapter
*adapter
)
3852 struct device
*dev
= &adapter
->pdev
->dev
;
3854 device_remove_bin_file(dev
, &bin_attr_port_stats
);
3856 if (adapter
->op_mode
== QLCNIC_NON_PRIV_FUNC
)
3858 device_remove_file(dev
, &dev_attr_diag_mode
);
3859 device_remove_bin_file(dev
, &bin_attr_crb
);
3860 device_remove_bin_file(dev
, &bin_attr_mem
);
3861 if (!(adapter
->flags
& QLCNIC_ESWITCH_ENABLED
))
3863 device_remove_bin_file(dev
, &bin_attr_esw_config
);
3864 if (adapter
->op_mode
!= QLCNIC_MGMT_FUNC
)
3866 device_remove_bin_file(dev
, &bin_attr_pci_config
);
3867 device_remove_bin_file(dev
, &bin_attr_npar_config
);
3868 device_remove_bin_file(dev
, &bin_attr_pm_config
);
3869 device_remove_bin_file(dev
, &bin_attr_esw_stats
);
3874 #define is_qlcnic_netdev(dev) (dev->netdev_ops == &qlcnic_netdev_ops)
3877 qlcnic_config_indev_addr(struct net_device
*dev
, unsigned long event
)
3879 struct in_device
*indev
;
3880 struct qlcnic_adapter
*adapter
= netdev_priv(dev
);
3882 indev
= in_dev_get(dev
);
3889 qlcnic_config_ipaddr(adapter
,
3890 ifa
->ifa_address
, QLCNIC_IP_UP
);
3893 qlcnic_config_ipaddr(adapter
,
3894 ifa
->ifa_address
, QLCNIC_IP_DOWN
);
3899 } endfor_ifa(indev
);
3904 static int qlcnic_netdev_event(struct notifier_block
*this,
3905 unsigned long event
, void *ptr
)
3907 struct qlcnic_adapter
*adapter
;
3908 struct net_device
*dev
= (struct net_device
*)ptr
;
3914 if (dev
->priv_flags
& IFF_802_1Q_VLAN
) {
3915 dev
= vlan_dev_real_dev(dev
);
3919 if (!is_qlcnic_netdev(dev
))
3922 adapter
= netdev_priv(dev
);
3927 if (!test_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
3930 qlcnic_config_indev_addr(dev
, event
);
3936 qlcnic_inetaddr_event(struct notifier_block
*this,
3937 unsigned long event
, void *ptr
)
3939 struct qlcnic_adapter
*adapter
;
3940 struct net_device
*dev
;
3942 struct in_ifaddr
*ifa
= (struct in_ifaddr
*)ptr
;
3944 dev
= ifa
->ifa_dev
? ifa
->ifa_dev
->dev
: NULL
;
3947 if (dev
== NULL
|| !netif_running(dev
))
3950 if (dev
->priv_flags
& IFF_802_1Q_VLAN
) {
3951 dev
= vlan_dev_real_dev(dev
);
3955 if (!is_qlcnic_netdev(dev
))
3958 adapter
= netdev_priv(dev
);
3963 if (!test_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
3968 qlcnic_config_ipaddr(adapter
, ifa
->ifa_address
, QLCNIC_IP_UP
);
3971 qlcnic_config_ipaddr(adapter
, ifa
->ifa_address
, QLCNIC_IP_DOWN
);
3981 static struct notifier_block qlcnic_netdev_cb
= {
3982 .notifier_call
= qlcnic_netdev_event
,
3985 static struct notifier_block qlcnic_inetaddr_cb
= {
3986 .notifier_call
= qlcnic_inetaddr_event
,
3990 qlcnic_config_indev_addr(struct net_device
*dev
, unsigned long event
)
3993 static struct pci_error_handlers qlcnic_err_handler
= {
3994 .error_detected
= qlcnic_io_error_detected
,
3995 .slot_reset
= qlcnic_io_slot_reset
,
3996 .resume
= qlcnic_io_resume
,
3999 static struct pci_driver qlcnic_driver
= {
4000 .name
= qlcnic_driver_name
,
4001 .id_table
= qlcnic_pci_tbl
,
4002 .probe
= qlcnic_probe
,
4003 .remove
= __devexit_p(qlcnic_remove
),
4005 .suspend
= qlcnic_suspend
,
4006 .resume
= qlcnic_resume
,
4008 .shutdown
= qlcnic_shutdown
,
4009 .err_handler
= &qlcnic_err_handler
4013 static int __init
qlcnic_init_module(void)
4017 printk(KERN_INFO
"%s\n", qlcnic_driver_string
);
4020 register_netdevice_notifier(&qlcnic_netdev_cb
);
4021 register_inetaddr_notifier(&qlcnic_inetaddr_cb
);
4024 ret
= pci_register_driver(&qlcnic_driver
);
4027 unregister_inetaddr_notifier(&qlcnic_inetaddr_cb
);
4028 unregister_netdevice_notifier(&qlcnic_netdev_cb
);
4035 module_init(qlcnic_init_module
);
4037 static void __exit
qlcnic_exit_module(void)
4040 pci_unregister_driver(&qlcnic_driver
);
4043 unregister_inetaddr_notifier(&qlcnic_inetaddr_cb
);
4044 unregister_netdevice_notifier(&qlcnic_netdev_cb
);
4048 module_exit(qlcnic_exit_module
);