2 * QLogic qlcnic NIC Driver
3 * Copyright (c) 2009-2013 QLogic Corporation
5 * See LICENSE.qlcnic for copyright and licensing details.
8 #include <linux/vmalloc.h>
9 #include <linux/interrupt.h>
10 #include <linux/swab.h>
11 #include <linux/dma-mapping.h>
12 #include <linux/if_vlan.h>
14 #include <linux/ipv6.h>
15 #include <linux/inetdevice.h>
16 #include <linux/aer.h>
17 #include <linux/log2.h>
18 #include <linux/pci.h>
19 #include <net/vxlan.h>
22 #include "qlcnic_sriov.h"
23 #include "qlcnic_hw.h"
25 MODULE_DESCRIPTION("QLogic 1/10 GbE Converged/Intelligent Ethernet Driver");
26 MODULE_LICENSE("GPL");
27 MODULE_VERSION(QLCNIC_LINUX_VERSIONID
);
28 MODULE_FIRMWARE(QLCNIC_UNIFIED_ROMIMAGE_NAME
);
30 char qlcnic_driver_name
[] = "qlcnic";
31 static const char qlcnic_driver_string
[] = "QLogic 1/10 GbE "
32 "Converged/Intelligent Ethernet Driver v" QLCNIC_LINUX_VERSIONID
;
34 static int qlcnic_mac_learn
;
35 module_param(qlcnic_mac_learn
, int, 0444);
36 MODULE_PARM_DESC(qlcnic_mac_learn
,
37 "Mac Filter (0=learning is disabled, 1=Driver learning is enabled, 2=FDB learning is enabled)");
39 int qlcnic_use_msi
= 1;
40 MODULE_PARM_DESC(use_msi
, "MSI interrupt (0=disabled, 1=enabled)");
41 module_param_named(use_msi
, qlcnic_use_msi
, int, 0444);
43 int qlcnic_use_msi_x
= 1;
44 MODULE_PARM_DESC(use_msi_x
, "MSI-X interrupt (0=disabled, 1=enabled)");
45 module_param_named(use_msi_x
, qlcnic_use_msi_x
, int, 0444);
47 int qlcnic_auto_fw_reset
= 1;
48 MODULE_PARM_DESC(auto_fw_reset
, "Auto firmware reset (0=disabled, 1=enabled)");
49 module_param_named(auto_fw_reset
, qlcnic_auto_fw_reset
, int, 0644);
51 int qlcnic_load_fw_file
;
52 MODULE_PARM_DESC(load_fw_file
, "Load firmware from (0=flash, 1=file, 2=POST in fast mode, 3= POST in medium mode, 4=POST in slow mode)");
53 module_param_named(load_fw_file
, qlcnic_load_fw_file
, int, 0444);
55 static int qlcnic_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
);
56 static void qlcnic_remove(struct pci_dev
*pdev
);
57 static int qlcnic_open(struct net_device
*netdev
);
58 static int qlcnic_close(struct net_device
*netdev
);
59 static void qlcnic_tx_timeout(struct net_device
*netdev
);
60 static void qlcnic_attach_work(struct work_struct
*work
);
61 static void qlcnic_fwinit_work(struct work_struct
*work
);
63 static void qlcnic_idc_debug_info(struct qlcnic_adapter
*adapter
, u8 encoding
);
64 static int qlcnic_can_start_firmware(struct qlcnic_adapter
*adapter
);
66 static irqreturn_t
qlcnic_tmp_intr(int irq
, void *data
);
67 static irqreturn_t
qlcnic_intr(int irq
, void *data
);
68 static irqreturn_t
qlcnic_msi_intr(int irq
, void *data
);
69 static irqreturn_t
qlcnic_msix_intr(int irq
, void *data
);
70 static irqreturn_t
qlcnic_msix_tx_intr(int irq
, void *data
);
72 static struct net_device_stats
*qlcnic_get_stats(struct net_device
*netdev
);
73 static int qlcnic_start_firmware(struct qlcnic_adapter
*);
75 static void qlcnic_free_lb_filters_mem(struct qlcnic_adapter
*adapter
);
76 static void qlcnic_dev_set_npar_ready(struct qlcnic_adapter
*);
77 static int qlcnicvf_start_firmware(struct qlcnic_adapter
*);
78 static int qlcnic_vlan_rx_add(struct net_device
*, __be16
, u16
);
79 static int qlcnic_vlan_rx_del(struct net_device
*, __be16
, u16
);
81 static int qlcnic_82xx_setup_intr(struct qlcnic_adapter
*);
82 static void qlcnic_82xx_dev_request_reset(struct qlcnic_adapter
*, u32
);
83 static irqreturn_t
qlcnic_82xx_clear_legacy_intr(struct qlcnic_adapter
*);
84 static pci_ers_result_t
qlcnic_82xx_io_slot_reset(struct pci_dev
*);
85 static int qlcnic_82xx_start_firmware(struct qlcnic_adapter
*);
86 static void qlcnic_82xx_io_resume(struct pci_dev
*);
87 static void qlcnic_82xx_set_mac_filter_count(struct qlcnic_adapter
*);
88 static pci_ers_result_t
qlcnic_82xx_io_error_detected(struct pci_dev
*,
90 static u32
qlcnic_vlan_tx_check(struct qlcnic_adapter
*adapter
)
92 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
94 if (adapter
->pdev
->device
== PCI_DEVICE_ID_QLOGIC_QLE824X
)
95 return ahw
->capabilities
& QLCNIC_FW_CAPABILITY_FVLANTX
;
100 /* PCI Device ID Table */
101 #define ENTRY(device) \
102 {PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, (device)), \
103 .class = PCI_CLASS_NETWORK_ETHERNET << 8, .class_mask = ~0}
105 static const struct pci_device_id qlcnic_pci_tbl
[] = {
106 ENTRY(PCI_DEVICE_ID_QLOGIC_QLE824X
),
107 ENTRY(PCI_DEVICE_ID_QLOGIC_QLE834X
),
108 ENTRY(PCI_DEVICE_ID_QLOGIC_VF_QLE834X
),
109 ENTRY(PCI_DEVICE_ID_QLOGIC_QLE8830
),
110 ENTRY(PCI_DEVICE_ID_QLOGIC_VF_QLE8C30
),
111 ENTRY(PCI_DEVICE_ID_QLOGIC_QLE844X
),
112 ENTRY(PCI_DEVICE_ID_QLOGIC_VF_QLE844X
),
116 MODULE_DEVICE_TABLE(pci
, qlcnic_pci_tbl
);
119 inline void qlcnic_update_cmd_producer(struct qlcnic_host_tx_ring
*tx_ring
)
121 writel(tx_ring
->producer
, tx_ring
->crb_cmd_producer
);
124 static const u32 msi_tgt_status
[8] = {
125 ISR_INT_TARGET_STATUS
, ISR_INT_TARGET_STATUS_F1
,
126 ISR_INT_TARGET_STATUS_F2
, ISR_INT_TARGET_STATUS_F3
,
127 ISR_INT_TARGET_STATUS_F4
, ISR_INT_TARGET_STATUS_F5
,
128 ISR_INT_TARGET_STATUS_F6
, ISR_INT_TARGET_STATUS_F7
131 static const u32 qlcnic_reg_tbl
[] = {
132 0x1B20A8, /* PEG_HALT_STAT1 */
133 0x1B20AC, /* PEG_HALT_STAT2 */
134 0x1B20B0, /* FW_HEARTBEAT */
135 0x1B2100, /* LOCK ID */
136 0x1B2128, /* FW_CAPABILITIES */
137 0x1B2138, /* drv active */
138 0x1B2140, /* dev state */
139 0x1B2144, /* drv state */
140 0x1B2148, /* drv scratch */
141 0x1B214C, /* dev partition info */
142 0x1B2174, /* drv idc ver */
143 0x1B2150, /* fw version major */
144 0x1B2154, /* fw version minor */
145 0x1B2158, /* fw version sub */
146 0x1B219C, /* npar state */
147 0x1B21FC, /* FW_IMG_VALID */
148 0x1B2250, /* CMD_PEG_STATE */
149 0x1B233C, /* RCV_PEG_STATE */
150 0x1B23B4, /* ASIC TEMP */
151 0x1B216C, /* FW api */
152 0x1B2170, /* drv op mode */
153 0x13C010, /* flash lock */
154 0x13C014, /* flash unlock */
157 static const struct qlcnic_board_info qlcnic_boards
[] = {
158 { PCI_VENDOR_ID_QLOGIC
,
159 PCI_DEVICE_ID_QLOGIC_QLE844X
,
162 "8400 series 10GbE Converged Network Adapter (TCP/IP Networking)" },
163 { PCI_VENDOR_ID_QLOGIC
,
164 PCI_DEVICE_ID_QLOGIC_QLE834X
,
165 PCI_VENDOR_ID_QLOGIC
,
167 "8300 Series Dual Port 10GbE Converged Network Adapter "
168 "(TCP/IP Networking)" },
169 { PCI_VENDOR_ID_QLOGIC
,
170 PCI_DEVICE_ID_QLOGIC_QLE834X
,
171 PCI_VENDOR_ID_QLOGIC
,
173 "8300 Series Single Port 10GbE Converged Network Adapter "
174 "(TCP/IP Networking)" },
175 { PCI_VENDOR_ID_QLOGIC
,
176 PCI_DEVICE_ID_QLOGIC_QLE834X
,
177 PCI_VENDOR_ID_QLOGIC
,
179 "8300 Series Dual Port 10GbE Converged Network Adapter "
180 "(TCP/IP Networking)" },
181 { PCI_VENDOR_ID_QLOGIC
,
182 PCI_DEVICE_ID_QLOGIC_QLE834X
,
183 PCI_VENDOR_ID_QLOGIC
,
185 "8300 Series Dual Port 10GbE Converged Network Adapter "
186 "(TCP/IP Networking)" },
187 { PCI_VENDOR_ID_QLOGIC
,
188 PCI_DEVICE_ID_QLOGIC_QLE834X
,
189 PCI_VENDOR_ID_QLOGIC
,
191 "8300 Series Dual Port 10GbE Converged Network Adapter "
192 "(TCP/IP Networking)" },
193 { PCI_VENDOR_ID_QLOGIC
,
194 PCI_DEVICE_ID_QLOGIC_QLE834X
,
195 PCI_VENDOR_ID_QLOGIC
,
197 "8300 Series Dual Port 10GbE Converged Network Adapter "
198 "(TCP/IP Networking)" },
199 { PCI_VENDOR_ID_QLOGIC
,
200 PCI_DEVICE_ID_QLOGIC_QLE834X
,
201 PCI_VENDOR_ID_QLOGIC
,
203 "8300 Series Dual Port 10GbE Converged Network Adapter "
204 "(TCP/IP Networking)" },
205 { PCI_VENDOR_ID_QLOGIC
,
206 PCI_DEVICE_ID_QLOGIC_QLE834X
,
207 PCI_VENDOR_ID_QLOGIC
,
209 "8300 Series Single Port 10GbE Converged Network Adapter "
210 "(TCP/IP Networking)" },
211 { PCI_VENDOR_ID_QLOGIC
,
212 PCI_DEVICE_ID_QLOGIC_QLE834X
,
213 PCI_VENDOR_ID_QLOGIC
,
215 "8300 Series Dual Port 10GbE Converged Network Adapter "
216 "(TCP/IP Networking)" },
217 { PCI_VENDOR_ID_QLOGIC
,
218 PCI_DEVICE_ID_QLOGIC_QLE834X
,
219 PCI_VENDOR_ID_QLOGIC
,
221 "8300 Series Dual Port 10GbE Converged Network Adapter "
222 "(TCP/IP Networking)" },
223 { PCI_VENDOR_ID_QLOGIC
,
224 PCI_DEVICE_ID_QLOGIC_QLE834X
,
225 0x0, 0x0, "8300 Series 1/10GbE Controller" },
226 { PCI_VENDOR_ID_QLOGIC
,
227 PCI_DEVICE_ID_QLOGIC_QLE8830
,
230 "8830 Series 1/10GbE Controller" },
231 { PCI_VENDOR_ID_QLOGIC
,
232 PCI_DEVICE_ID_QLOGIC_QLE824X
,
233 PCI_VENDOR_ID_QLOGIC
,
235 "8200 Series Single Port 10GbE Converged Network Adapter"
236 "(TCP/IP Networking)" },
237 { PCI_VENDOR_ID_QLOGIC
,
238 PCI_DEVICE_ID_QLOGIC_QLE824X
,
239 PCI_VENDOR_ID_QLOGIC
,
241 "8200 Series Dual Port 10GbE Converged Network Adapter"
242 "(TCP/IP Networking)" },
243 { PCI_VENDOR_ID_QLOGIC
,
244 PCI_DEVICE_ID_QLOGIC_QLE824X
,
245 PCI_VENDOR_ID_QLOGIC
,
247 "3200 Series Dual Port 10Gb Intelligent Ethernet Adapter" },
248 { PCI_VENDOR_ID_QLOGIC
,
249 PCI_DEVICE_ID_QLOGIC_QLE824X
,
250 PCI_VENDOR_ID_QLOGIC
,
252 "3200 Series Quad Port 1Gb Intelligent Ethernet Adapter" },
253 { PCI_VENDOR_ID_QLOGIC
,
254 PCI_DEVICE_ID_QLOGIC_QLE824X
,
255 PCI_VENDOR_ID_QLOGIC
,
257 "3200 Series Single Port 10Gb Intelligent Ethernet Adapter" },
258 { PCI_VENDOR_ID_QLOGIC
,
259 PCI_DEVICE_ID_QLOGIC_QLE824X
,
261 "NC523SFP 10Gb 2-port Server Adapter" },
262 { PCI_VENDOR_ID_QLOGIC
,
263 PCI_DEVICE_ID_QLOGIC_QLE824X
,
265 "CN1000Q Dual Port Converged Network Adapter" },
266 { PCI_VENDOR_ID_QLOGIC
,
267 PCI_DEVICE_ID_QLOGIC_QLE824X
,
268 PCI_VENDOR_ID_QLOGIC
,
270 "QME8242-k 10GbE Dual Port Mezzanine Card" },
271 { PCI_VENDOR_ID_QLOGIC
,
272 PCI_DEVICE_ID_QLOGIC_QLE824X
,
273 0x0, 0x0, "cLOM8214 1/10GbE Controller" },
276 #define NUM_SUPPORTED_BOARDS ARRAY_SIZE(qlcnic_boards)
279 struct qlcnic_legacy_intr_set legacy_intr
[] = QLCNIC_LEGACY_INTR_CONFIG
;
281 int qlcnic_alloc_sds_rings(struct qlcnic_recv_context
*recv_ctx
, int count
)
283 int size
= sizeof(struct qlcnic_host_sds_ring
) * count
;
285 recv_ctx
->sds_rings
= kzalloc(size
, GFP_KERNEL
);
287 return recv_ctx
->sds_rings
== NULL
;
290 void qlcnic_free_sds_rings(struct qlcnic_recv_context
*recv_ctx
)
292 kfree(recv_ctx
->sds_rings
);
293 recv_ctx
->sds_rings
= NULL
;
296 int qlcnic_read_mac_addr(struct qlcnic_adapter
*adapter
)
298 struct net_device
*netdev
= adapter
->netdev
;
299 struct pci_dev
*pdev
= adapter
->pdev
;
300 u8 mac_addr
[ETH_ALEN
];
303 ret
= qlcnic_get_mac_address(adapter
, mac_addr
,
304 adapter
->ahw
->pci_func
);
308 memcpy(netdev
->dev_addr
, mac_addr
, ETH_ALEN
);
309 memcpy(adapter
->mac_addr
, netdev
->dev_addr
, netdev
->addr_len
);
311 /* set station address */
313 if (!is_valid_ether_addr(netdev
->dev_addr
))
314 dev_warn(&pdev
->dev
, "Bad MAC address %pM.\n",
320 static void qlcnic_delete_adapter_mac(struct qlcnic_adapter
*adapter
)
322 struct qlcnic_mac_vlan_list
*cur
;
323 struct list_head
*head
;
325 list_for_each(head
, &adapter
->mac_list
) {
326 cur
= list_entry(head
, struct qlcnic_mac_vlan_list
, list
);
327 if (ether_addr_equal_unaligned(adapter
->mac_addr
, cur
->mac_addr
)) {
328 qlcnic_sre_macaddr_change(adapter
, cur
->mac_addr
,
330 list_del(&cur
->list
);
337 static int qlcnic_set_mac(struct net_device
*netdev
, void *p
)
339 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
340 struct sockaddr
*addr
= p
;
342 if (qlcnic_sriov_vf_check(adapter
))
345 if ((adapter
->flags
& QLCNIC_MAC_OVERRIDE_DISABLED
))
348 if (!is_valid_ether_addr(addr
->sa_data
))
351 if (ether_addr_equal_unaligned(adapter
->mac_addr
, addr
->sa_data
) &&
352 ether_addr_equal_unaligned(netdev
->dev_addr
, addr
->sa_data
))
355 if (test_bit(__QLCNIC_DEV_UP
, &adapter
->state
)) {
356 netif_device_detach(netdev
);
357 qlcnic_napi_disable(adapter
);
360 qlcnic_delete_adapter_mac(adapter
);
361 memcpy(adapter
->mac_addr
, addr
->sa_data
, netdev
->addr_len
);
362 memcpy(netdev
->dev_addr
, addr
->sa_data
, netdev
->addr_len
);
363 qlcnic_set_multi(adapter
->netdev
);
365 if (test_bit(__QLCNIC_DEV_UP
, &adapter
->state
)) {
366 netif_device_attach(netdev
);
367 qlcnic_napi_enable(adapter
);
372 static int qlcnic_fdb_del(struct ndmsg
*ndm
, struct nlattr
*tb
[],
373 struct net_device
*netdev
,
374 const unsigned char *addr
, u16 vid
)
376 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
377 int err
= -EOPNOTSUPP
;
379 if (!adapter
->fdb_mac_learn
)
380 return ndo_dflt_fdb_del(ndm
, tb
, netdev
, addr
, vid
);
382 if ((adapter
->flags
& QLCNIC_ESWITCH_ENABLED
) ||
383 qlcnic_sriov_check(adapter
)) {
384 if (is_unicast_ether_addr(addr
)) {
385 err
= dev_uc_del(netdev
, addr
);
387 err
= qlcnic_nic_del_mac(adapter
, addr
);
388 } else if (is_multicast_ether_addr(addr
)) {
389 err
= dev_mc_del(netdev
, addr
);
397 static int qlcnic_fdb_add(struct ndmsg
*ndm
, struct nlattr
*tb
[],
398 struct net_device
*netdev
,
399 const unsigned char *addr
, u16 vid
, u16 flags
,
400 struct netlink_ext_ack
*extack
)
402 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
405 if (!adapter
->fdb_mac_learn
)
406 return ndo_dflt_fdb_add(ndm
, tb
, netdev
, addr
, vid
, flags
);
408 if (!(adapter
->flags
& QLCNIC_ESWITCH_ENABLED
) &&
409 !qlcnic_sriov_check(adapter
)) {
410 pr_info("%s: FDB e-switch is not enabled\n", __func__
);
414 if (ether_addr_equal(addr
, adapter
->mac_addr
))
417 if (is_unicast_ether_addr(addr
)) {
418 if (netdev_uc_count(netdev
) < adapter
->ahw
->max_uc_count
)
419 err
= dev_uc_add_excl(netdev
, addr
);
422 } else if (is_multicast_ether_addr(addr
)) {
423 err
= dev_mc_add_excl(netdev
, addr
);
431 static int qlcnic_fdb_dump(struct sk_buff
*skb
, struct netlink_callback
*ncb
,
432 struct net_device
*netdev
,
433 struct net_device
*filter_dev
, int *idx
)
435 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
438 if (!adapter
->fdb_mac_learn
)
439 return ndo_dflt_fdb_dump(skb
, ncb
, netdev
, filter_dev
, idx
);
441 if ((adapter
->flags
& QLCNIC_ESWITCH_ENABLED
) ||
442 qlcnic_sriov_check(adapter
))
443 err
= ndo_dflt_fdb_dump(skb
, ncb
, netdev
, filter_dev
, idx
);
448 static void qlcnic_82xx_cancel_idc_work(struct qlcnic_adapter
*adapter
)
450 while (test_and_set_bit(__QLCNIC_RESETTING
, &adapter
->state
))
451 usleep_range(10000, 11000);
453 if (!adapter
->fw_work
.work
.func
)
456 cancel_delayed_work_sync(&adapter
->fw_work
);
459 static int qlcnic_get_phys_port_id(struct net_device
*netdev
,
460 struct netdev_phys_item_id
*ppid
)
462 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
463 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
465 if (!(adapter
->flags
& QLCNIC_HAS_PHYS_PORT_ID
))
468 ppid
->id_len
= sizeof(ahw
->phys_port_id
);
469 memcpy(ppid
->id
, ahw
->phys_port_id
, ppid
->id_len
);
474 static void qlcnic_add_vxlan_port(struct net_device
*netdev
,
475 struct udp_tunnel_info
*ti
)
477 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
478 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
480 if (ti
->type
!= UDP_TUNNEL_TYPE_VXLAN
)
483 /* Adapter supports only one VXLAN port. Use very first port
484 * for enabling offload
486 if (!qlcnic_encap_rx_offload(adapter
))
488 if (!ahw
->vxlan_port_count
) {
489 ahw
->vxlan_port_count
= 1;
490 ahw
->vxlan_port
= ntohs(ti
->port
);
491 adapter
->flags
|= QLCNIC_ADD_VXLAN_PORT
;
494 if (ahw
->vxlan_port
== ntohs(ti
->port
))
495 ahw
->vxlan_port_count
++;
499 static void qlcnic_del_vxlan_port(struct net_device
*netdev
,
500 struct udp_tunnel_info
*ti
)
502 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
503 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
505 if (ti
->type
!= UDP_TUNNEL_TYPE_VXLAN
)
508 if (!qlcnic_encap_rx_offload(adapter
) || !ahw
->vxlan_port_count
||
509 (ahw
->vxlan_port
!= ntohs(ti
->port
)))
512 ahw
->vxlan_port_count
--;
513 if (!ahw
->vxlan_port_count
)
514 adapter
->flags
|= QLCNIC_DEL_VXLAN_PORT
;
517 static netdev_features_t
qlcnic_features_check(struct sk_buff
*skb
,
518 struct net_device
*dev
,
519 netdev_features_t features
)
521 features
= vlan_features_check(skb
, features
);
522 return vxlan_features_check(skb
, features
);
525 static const struct net_device_ops qlcnic_netdev_ops
= {
526 .ndo_open
= qlcnic_open
,
527 .ndo_stop
= qlcnic_close
,
528 .ndo_start_xmit
= qlcnic_xmit_frame
,
529 .ndo_get_stats
= qlcnic_get_stats
,
530 .ndo_validate_addr
= eth_validate_addr
,
531 .ndo_set_rx_mode
= qlcnic_set_multi
,
532 .ndo_set_mac_address
= qlcnic_set_mac
,
533 .ndo_change_mtu
= qlcnic_change_mtu
,
534 .ndo_fix_features
= qlcnic_fix_features
,
535 .ndo_set_features
= qlcnic_set_features
,
536 .ndo_tx_timeout
= qlcnic_tx_timeout
,
537 .ndo_vlan_rx_add_vid
= qlcnic_vlan_rx_add
,
538 .ndo_vlan_rx_kill_vid
= qlcnic_vlan_rx_del
,
539 .ndo_fdb_add
= qlcnic_fdb_add
,
540 .ndo_fdb_del
= qlcnic_fdb_del
,
541 .ndo_fdb_dump
= qlcnic_fdb_dump
,
542 .ndo_get_phys_port_id
= qlcnic_get_phys_port_id
,
543 .ndo_udp_tunnel_add
= qlcnic_add_vxlan_port
,
544 .ndo_udp_tunnel_del
= qlcnic_del_vxlan_port
,
545 .ndo_features_check
= qlcnic_features_check
,
546 #ifdef CONFIG_QLCNIC_SRIOV
547 .ndo_set_vf_mac
= qlcnic_sriov_set_vf_mac
,
548 .ndo_set_vf_rate
= qlcnic_sriov_set_vf_tx_rate
,
549 .ndo_get_vf_config
= qlcnic_sriov_get_vf_config
,
550 .ndo_set_vf_vlan
= qlcnic_sriov_set_vf_vlan
,
551 .ndo_set_vf_spoofchk
= qlcnic_sriov_set_vf_spoofchk
,
555 static const struct net_device_ops qlcnic_netdev_failed_ops
= {
556 .ndo_open
= qlcnic_open
,
559 static struct qlcnic_nic_template qlcnic_ops
= {
560 .config_bridged_mode
= qlcnic_config_bridged_mode
,
561 .config_led
= qlcnic_82xx_config_led
,
562 .start_firmware
= qlcnic_82xx_start_firmware
,
563 .request_reset
= qlcnic_82xx_dev_request_reset
,
564 .cancel_idc_work
= qlcnic_82xx_cancel_idc_work
,
565 .napi_add
= qlcnic_82xx_napi_add
,
566 .napi_del
= qlcnic_82xx_napi_del
,
567 .config_ipaddr
= qlcnic_82xx_config_ipaddr
,
568 .shutdown
= qlcnic_82xx_shutdown
,
569 .resume
= qlcnic_82xx_resume
,
570 .clear_legacy_intr
= qlcnic_82xx_clear_legacy_intr
,
573 struct qlcnic_nic_template qlcnic_vf_ops
= {
574 .config_bridged_mode
= qlcnicvf_config_bridged_mode
,
575 .config_led
= qlcnicvf_config_led
,
576 .start_firmware
= qlcnicvf_start_firmware
579 static struct qlcnic_hardware_ops qlcnic_hw_ops
= {
580 .read_crb
= qlcnic_82xx_read_crb
,
581 .write_crb
= qlcnic_82xx_write_crb
,
582 .read_reg
= qlcnic_82xx_hw_read_wx_2M
,
583 .write_reg
= qlcnic_82xx_hw_write_wx_2M
,
584 .get_mac_address
= qlcnic_82xx_get_mac_address
,
585 .setup_intr
= qlcnic_82xx_setup_intr
,
586 .alloc_mbx_args
= qlcnic_82xx_alloc_mbx_args
,
587 .mbx_cmd
= qlcnic_82xx_issue_cmd
,
588 .get_func_no
= qlcnic_82xx_get_func_no
,
589 .api_lock
= qlcnic_82xx_api_lock
,
590 .api_unlock
= qlcnic_82xx_api_unlock
,
591 .add_sysfs
= qlcnic_82xx_add_sysfs
,
592 .remove_sysfs
= qlcnic_82xx_remove_sysfs
,
593 .process_lb_rcv_ring_diag
= qlcnic_82xx_process_rcv_ring_diag
,
594 .create_rx_ctx
= qlcnic_82xx_fw_cmd_create_rx_ctx
,
595 .create_tx_ctx
= qlcnic_82xx_fw_cmd_create_tx_ctx
,
596 .del_rx_ctx
= qlcnic_82xx_fw_cmd_del_rx_ctx
,
597 .del_tx_ctx
= qlcnic_82xx_fw_cmd_del_tx_ctx
,
598 .setup_link_event
= qlcnic_82xx_linkevent_request
,
599 .get_nic_info
= qlcnic_82xx_get_nic_info
,
600 .get_pci_info
= qlcnic_82xx_get_pci_info
,
601 .set_nic_info
= qlcnic_82xx_set_nic_info
,
602 .change_macvlan
= qlcnic_82xx_sre_macaddr_change
,
603 .napi_enable
= qlcnic_82xx_napi_enable
,
604 .napi_disable
= qlcnic_82xx_napi_disable
,
605 .config_intr_coal
= qlcnic_82xx_config_intr_coalesce
,
606 .config_rss
= qlcnic_82xx_config_rss
,
607 .config_hw_lro
= qlcnic_82xx_config_hw_lro
,
608 .config_loopback
= qlcnic_82xx_set_lb_mode
,
609 .clear_loopback
= qlcnic_82xx_clear_lb_mode
,
610 .config_promisc_mode
= qlcnic_82xx_nic_set_promisc
,
611 .change_l2_filter
= qlcnic_82xx_change_filter
,
612 .get_board_info
= qlcnic_82xx_get_board_info
,
613 .set_mac_filter_count
= qlcnic_82xx_set_mac_filter_count
,
614 .free_mac_list
= qlcnic_82xx_free_mac_list
,
615 .read_phys_port_id
= qlcnic_82xx_read_phys_port_id
,
616 .io_error_detected
= qlcnic_82xx_io_error_detected
,
617 .io_slot_reset
= qlcnic_82xx_io_slot_reset
,
618 .io_resume
= qlcnic_82xx_io_resume
,
619 .get_beacon_state
= qlcnic_82xx_get_beacon_state
,
620 .enable_sds_intr
= qlcnic_82xx_enable_sds_intr
,
621 .disable_sds_intr
= qlcnic_82xx_disable_sds_intr
,
622 .enable_tx_intr
= qlcnic_82xx_enable_tx_intr
,
623 .disable_tx_intr
= qlcnic_82xx_disable_tx_intr
,
624 .get_saved_state
= qlcnic_82xx_get_saved_state
,
625 .set_saved_state
= qlcnic_82xx_set_saved_state
,
626 .cache_tmpl_hdr_values
= qlcnic_82xx_cache_tmpl_hdr_values
,
627 .get_cap_size
= qlcnic_82xx_get_cap_size
,
628 .set_sys_info
= qlcnic_82xx_set_sys_info
,
629 .store_cap_mask
= qlcnic_82xx_store_cap_mask
,
630 .encap_rx_offload
= qlcnic_82xx_encap_rx_offload
,
631 .encap_tx_offload
= qlcnic_82xx_encap_tx_offload
,
634 static int qlcnic_check_multi_tx_capability(struct qlcnic_adapter
*adapter
)
636 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
638 if (qlcnic_82xx_check(adapter
) &&
639 (ahw
->extra_capability
[0] & QLCNIC_FW_CAPABILITY_2_MULTI_TX
)) {
640 test_and_set_bit(__QLCNIC_MULTI_TX_UNIQUE
, &adapter
->state
);
647 static int qlcnic_max_rings(struct qlcnic_adapter
*adapter
, u8 ring_cnt
,
650 int num_rings
, max_rings
= QLCNIC_MAX_SDS_RINGS
;
652 if (queue_type
== QLCNIC_RX_QUEUE
)
653 max_rings
= adapter
->max_sds_rings
;
654 else if (queue_type
== QLCNIC_TX_QUEUE
)
655 max_rings
= adapter
->max_tx_rings
;
657 num_rings
= rounddown_pow_of_two(min_t(int, num_online_cpus(),
660 if (ring_cnt
> num_rings
)
666 void qlcnic_set_tx_ring_count(struct qlcnic_adapter
*adapter
, u8 tx_cnt
)
668 /* 83xx adapter does not have max_tx_rings intialized in probe */
669 if (adapter
->max_tx_rings
)
670 adapter
->drv_tx_rings
= qlcnic_max_rings(adapter
, tx_cnt
,
673 adapter
->drv_tx_rings
= tx_cnt
;
676 void qlcnic_set_sds_ring_count(struct qlcnic_adapter
*adapter
, u8 rx_cnt
)
678 /* 83xx adapter does not have max_sds_rings intialized in probe */
679 if (adapter
->max_sds_rings
)
680 adapter
->drv_sds_rings
= qlcnic_max_rings(adapter
, rx_cnt
,
683 adapter
->drv_sds_rings
= rx_cnt
;
686 int qlcnic_setup_tss_rss_intr(struct qlcnic_adapter
*adapter
)
688 struct pci_dev
*pdev
= adapter
->pdev
;
689 int num_msix
= 0, err
= 0, vector
;
691 adapter
->flags
&= ~QLCNIC_TSS_RSS
;
693 if (adapter
->drv_tss_rings
> 0)
694 num_msix
+= adapter
->drv_tss_rings
;
696 num_msix
+= adapter
->drv_tx_rings
;
698 if (adapter
->drv_rss_rings
> 0)
699 num_msix
+= adapter
->drv_rss_rings
;
701 num_msix
+= adapter
->drv_sds_rings
;
703 if (qlcnic_83xx_check(adapter
))
706 if (!adapter
->msix_entries
) {
707 adapter
->msix_entries
= kcalloc(num_msix
,
708 sizeof(struct msix_entry
),
710 if (!adapter
->msix_entries
)
714 for (vector
= 0; vector
< num_msix
; vector
++)
715 adapter
->msix_entries
[vector
].entry
= vector
;
718 err
= pci_enable_msix_exact(pdev
, adapter
->msix_entries
, num_msix
);
719 if (err
== -ENOSPC
) {
720 if (!adapter
->drv_tss_rings
&& !adapter
->drv_rss_rings
)
723 netdev_info(adapter
->netdev
,
724 "Unable to allocate %d MSI-X vectors, Available vectors %d\n",
727 num_msix
= adapter
->drv_tx_rings
+ adapter
->drv_sds_rings
;
729 /* Set rings to 0 so we can restore original TSS/RSS count */
730 adapter
->drv_tss_rings
= 0;
731 adapter
->drv_rss_rings
= 0;
733 if (qlcnic_83xx_check(adapter
))
736 netdev_info(adapter
->netdev
,
737 "Restoring %d Tx, %d SDS rings for total %d vectors.\n",
738 adapter
->drv_tx_rings
, adapter
->drv_sds_rings
,
742 } else if (err
< 0) {
746 adapter
->ahw
->num_msix
= num_msix
;
747 if (adapter
->drv_tss_rings
> 0)
748 adapter
->drv_tx_rings
= adapter
->drv_tss_rings
;
750 if (adapter
->drv_rss_rings
> 0)
751 adapter
->drv_sds_rings
= adapter
->drv_rss_rings
;
756 int qlcnic_enable_msix(struct qlcnic_adapter
*adapter
, u32 num_msix
)
758 struct pci_dev
*pdev
= adapter
->pdev
;
761 if (!adapter
->msix_entries
) {
762 adapter
->msix_entries
= kcalloc(num_msix
,
763 sizeof(struct msix_entry
),
765 if (!adapter
->msix_entries
)
769 adapter
->flags
&= ~(QLCNIC_MSI_ENABLED
| QLCNIC_MSIX_ENABLED
);
771 if (adapter
->ahw
->msix_supported
) {
773 for (vector
= 0; vector
< num_msix
; vector
++)
774 adapter
->msix_entries
[vector
].entry
= vector
;
776 err
= pci_enable_msix_range(pdev
,
777 adapter
->msix_entries
, 1, num_msix
);
779 if (err
== num_msix
) {
780 adapter
->flags
|= QLCNIC_MSIX_ENABLED
;
781 adapter
->ahw
->num_msix
= num_msix
;
782 dev_info(&pdev
->dev
, "using msi-x interrupts\n");
784 } else if (err
> 0) {
785 pci_disable_msix(pdev
);
788 "Unable to allocate %d MSI-X vectors, Available vectors %d\n",
791 if (qlcnic_82xx_check(adapter
)) {
792 num_msix
= rounddown_pow_of_two(err
);
793 if (err
< QLCNIC_82XX_MINIMUM_VECTOR
)
796 num_msix
= rounddown_pow_of_two(err
- 1);
798 if (err
< QLCNIC_83XX_MINIMUM_VECTOR
)
802 if (qlcnic_82xx_check(adapter
) &&
803 !qlcnic_check_multi_tx(adapter
)) {
804 adapter
->drv_sds_rings
= num_msix
;
805 adapter
->drv_tx_rings
= QLCNIC_SINGLE_RING
;
807 /* Distribute vectors equally */
808 adapter
->drv_tx_rings
= num_msix
/ 2;
809 adapter
->drv_sds_rings
= adapter
->drv_tx_rings
;
814 "Trying to allocate %d MSI-X interrupt vectors\n",
820 "Unable to allocate %d MSI-X vectors, err=%d\n",
829 static int qlcnic_82xx_calculate_msix_vector(struct qlcnic_adapter
*adapter
)
833 num_msix
= adapter
->drv_sds_rings
;
835 if (qlcnic_check_multi_tx(adapter
))
836 num_msix
+= adapter
->drv_tx_rings
;
838 num_msix
+= QLCNIC_SINGLE_RING
;
843 static int qlcnic_enable_msi_legacy(struct qlcnic_adapter
*adapter
)
846 u32 offset
, mask_reg
;
847 const struct qlcnic_legacy_intr_set
*legacy_intrp
;
848 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
849 struct pci_dev
*pdev
= adapter
->pdev
;
851 if (qlcnic_use_msi
&& !pci_enable_msi(pdev
)) {
852 adapter
->flags
|= QLCNIC_MSI_ENABLED
;
853 offset
= msi_tgt_status
[adapter
->ahw
->pci_func
];
854 adapter
->tgt_status_reg
= qlcnic_get_ioaddr(adapter
->ahw
,
856 dev_info(&pdev
->dev
, "using msi interrupts\n");
857 adapter
->msix_entries
[0].vector
= pdev
->irq
;
861 if (qlcnic_use_msi
|| qlcnic_use_msi_x
)
864 legacy_intrp
= &legacy_intr
[adapter
->ahw
->pci_func
];
865 adapter
->ahw
->int_vec_bit
= legacy_intrp
->int_vec_bit
;
866 offset
= legacy_intrp
->tgt_status_reg
;
867 adapter
->tgt_status_reg
= qlcnic_get_ioaddr(ahw
, offset
);
868 mask_reg
= legacy_intrp
->tgt_mask_reg
;
869 adapter
->tgt_mask_reg
= qlcnic_get_ioaddr(ahw
, mask_reg
);
870 adapter
->isr_int_vec
= qlcnic_get_ioaddr(ahw
, ISR_INT_VECTOR
);
871 adapter
->crb_int_state_reg
= qlcnic_get_ioaddr(ahw
, ISR_INT_STATE_REG
);
872 dev_info(&pdev
->dev
, "using legacy interrupts\n");
873 adapter
->msix_entries
[0].vector
= pdev
->irq
;
877 static int qlcnic_82xx_setup_intr(struct qlcnic_adapter
*adapter
)
879 int num_msix
, err
= 0;
881 if (adapter
->flags
& QLCNIC_TSS_RSS
) {
882 err
= qlcnic_setup_tss_rss_intr(adapter
);
885 num_msix
= adapter
->ahw
->num_msix
;
887 num_msix
= qlcnic_82xx_calculate_msix_vector(adapter
);
889 err
= qlcnic_enable_msix(adapter
, num_msix
);
893 if (!(adapter
->flags
& QLCNIC_MSIX_ENABLED
)) {
894 qlcnic_disable_multi_tx(adapter
);
895 adapter
->drv_sds_rings
= QLCNIC_SINGLE_RING
;
897 err
= qlcnic_enable_msi_legacy(adapter
);
906 int qlcnic_82xx_mq_intrpt(struct qlcnic_adapter
*adapter
, int op_type
)
908 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
911 if (qlcnic_check_multi_tx(adapter
) &&
913 (adapter
->flags
& QLCNIC_MSIX_ENABLED
)) {
915 vzalloc(array_size(sizeof(struct qlcnic_intrpt_config
),
920 for (i
= 0; i
< ahw
->num_msix
; i
++) {
921 ahw
->intr_tbl
[i
].type
= QLCNIC_INTRPT_MSIX
;
922 ahw
->intr_tbl
[i
].id
= i
;
923 ahw
->intr_tbl
[i
].src
= 0;
926 err
= qlcnic_82xx_config_intrpt(adapter
, 1);
928 dev_err(&adapter
->pdev
->dev
,
929 "Failed to configure Interrupt for %d vector\n",
937 void qlcnic_teardown_intr(struct qlcnic_adapter
*adapter
)
939 if (adapter
->flags
& QLCNIC_MSIX_ENABLED
)
940 pci_disable_msix(adapter
->pdev
);
941 if (adapter
->flags
& QLCNIC_MSI_ENABLED
)
942 pci_disable_msi(adapter
->pdev
);
944 kfree(adapter
->msix_entries
);
945 adapter
->msix_entries
= NULL
;
947 if (adapter
->ahw
->intr_tbl
) {
948 vfree(adapter
->ahw
->intr_tbl
);
949 adapter
->ahw
->intr_tbl
= NULL
;
953 static void qlcnic_cleanup_pci_map(struct qlcnic_hardware_context
*ahw
)
955 if (ahw
->pci_base0
!= NULL
)
956 iounmap(ahw
->pci_base0
);
959 static int qlcnic_get_act_pci_func(struct qlcnic_adapter
*adapter
)
961 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
962 struct qlcnic_pci_info
*pci_info
;
965 if (!(adapter
->flags
& QLCNIC_ESWITCH_ENABLED
)) {
966 switch (ahw
->port_type
) {
968 ahw
->total_nic_func
= QLCNIC_NIU_MAX_GBE_PORTS
;
971 ahw
->total_nic_func
= QLCNIC_NIU_MAX_XG_PORTS
;
977 if (ahw
->op_mode
== QLCNIC_MGMT_FUNC
)
980 pci_info
= kcalloc(ahw
->max_vnic_func
, sizeof(*pci_info
), GFP_KERNEL
);
984 ret
= qlcnic_get_pci_info(adapter
, pci_info
);
989 static bool qlcnic_port_eswitch_cfg_capability(struct qlcnic_adapter
*adapter
)
993 if (qlcnic_84xx_check(adapter
)) {
995 } else if (qlcnic_83xx_check(adapter
)) {
996 if (adapter
->ahw
->extra_capability
[0] &
997 QLCNIC_FW_CAPABILITY_2_PER_PORT_ESWITCH_CFG
)
1006 int qlcnic_init_pci_info(struct qlcnic_adapter
*adapter
)
1008 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
1009 struct qlcnic_pci_info
*pci_info
;
1010 int i
, id
= 0, ret
= 0, j
= 0;
1014 pci_info
= kcalloc(ahw
->max_vnic_func
, sizeof(*pci_info
), GFP_KERNEL
);
1018 ret
= qlcnic_get_pci_info(adapter
, pci_info
);
1022 act_pci_func
= ahw
->total_nic_func
;
1024 adapter
->npars
= kcalloc(act_pci_func
,
1025 sizeof(struct qlcnic_npar_info
),
1027 if (!adapter
->npars
) {
1032 adapter
->eswitch
= kcalloc(QLCNIC_NIU_MAX_XG_PORTS
,
1033 sizeof(struct qlcnic_eswitch
),
1035 if (!adapter
->eswitch
) {
1040 for (i
= 0; i
< ahw
->max_vnic_func
; i
++) {
1041 pfn
= pci_info
[i
].id
;
1043 if (pfn
>= ahw
->max_vnic_func
) {
1045 dev_err(&adapter
->pdev
->dev
, "%s: Invalid function 0x%x, max 0x%x\n",
1046 __func__
, pfn
, ahw
->max_vnic_func
);
1050 if (!pci_info
[i
].active
||
1051 (pci_info
[i
].type
!= QLCNIC_TYPE_NIC
))
1054 if (qlcnic_port_eswitch_cfg_capability(adapter
)) {
1055 if (!qlcnic_83xx_set_port_eswitch_status(adapter
, pfn
,
1057 adapter
->npars
[j
].eswitch_status
= true;
1061 adapter
->npars
[j
].eswitch_status
= true;
1064 adapter
->npars
[j
].pci_func
= pfn
;
1065 adapter
->npars
[j
].active
= (u8
)pci_info
[i
].active
;
1066 adapter
->npars
[j
].type
= (u8
)pci_info
[i
].type
;
1067 adapter
->npars
[j
].phy_port
= (u8
)pci_info
[i
].default_port
;
1068 adapter
->npars
[j
].min_bw
= pci_info
[i
].tx_min_bw
;
1069 adapter
->npars
[j
].max_bw
= pci_info
[i
].tx_max_bw
;
1071 memcpy(&adapter
->npars
[j
].mac
, &pci_info
[i
].mac
, ETH_ALEN
);
1075 /* Update eSwitch status for adapters without per port eSwitch
1076 * configuration capability
1078 if (!qlcnic_port_eswitch_cfg_capability(adapter
)) {
1079 for (i
= 0; i
< QLCNIC_NIU_MAX_XG_PORTS
; i
++)
1080 adapter
->eswitch
[i
].flags
|= QLCNIC_SWITCH_ENABLE
;
1087 kfree(adapter
->eswitch
);
1088 adapter
->eswitch
= NULL
;
1090 kfree(adapter
->npars
);
1091 adapter
->npars
= NULL
;
1099 qlcnic_set_function_modes(struct qlcnic_adapter
*adapter
)
1103 u32 data
= QLCNIC_MGMT_FUNC
;
1104 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
1106 ret
= qlcnic_api_lock(adapter
);
1111 data
= QLC_SHARED_REG_RD32(adapter
, QLCNIC_DRV_OP_MODE
);
1112 data
= (data
& ~QLC_DEV_SET_DRV(0xf, id
)) |
1113 QLC_DEV_SET_DRV(QLCNIC_MGMT_FUNC
, id
);
1114 QLC_SHARED_REG_WR32(adapter
, QLCNIC_DRV_OP_MODE
, data
);
1115 qlcnic_api_unlock(adapter
);
1120 static void qlcnic_check_vf(struct qlcnic_adapter
*adapter
,
1121 const struct pci_device_id
*ent
)
1123 u32 op_mode
, priv_level
;
1125 /* Determine FW API version */
1126 adapter
->ahw
->fw_hal_version
= QLC_SHARED_REG_RD32(adapter
,
1129 /* Find PCI function number */
1130 qlcnic_get_func_no(adapter
);
1132 /* Determine function privilege level */
1133 op_mode
= QLC_SHARED_REG_RD32(adapter
, QLCNIC_DRV_OP_MODE
);
1134 if (op_mode
== QLC_DEV_DRV_DEFAULT
)
1135 priv_level
= QLCNIC_MGMT_FUNC
;
1137 priv_level
= QLC_DEV_GET_DRV(op_mode
, adapter
->ahw
->pci_func
);
1139 if (priv_level
== QLCNIC_NON_PRIV_FUNC
) {
1140 adapter
->ahw
->op_mode
= QLCNIC_NON_PRIV_FUNC
;
1141 dev_info(&adapter
->pdev
->dev
,
1142 "HAL Version: %d Non Privileged function\n",
1143 adapter
->ahw
->fw_hal_version
);
1144 adapter
->nic_ops
= &qlcnic_vf_ops
;
1146 adapter
->nic_ops
= &qlcnic_ops
;
1149 #define QLCNIC_82XX_BAR0_LENGTH 0x00200000UL
1150 #define QLCNIC_83XX_BAR0_LENGTH 0x4000
1151 static void qlcnic_get_bar_length(u32 dev_id
, ulong
*bar
)
1154 case PCI_DEVICE_ID_QLOGIC_QLE824X
:
1155 *bar
= QLCNIC_82XX_BAR0_LENGTH
;
1157 case PCI_DEVICE_ID_QLOGIC_QLE834X
:
1158 case PCI_DEVICE_ID_QLOGIC_QLE8830
:
1159 case PCI_DEVICE_ID_QLOGIC_QLE844X
:
1160 case PCI_DEVICE_ID_QLOGIC_VF_QLE834X
:
1161 case PCI_DEVICE_ID_QLOGIC_VF_QLE844X
:
1162 case PCI_DEVICE_ID_QLOGIC_VF_QLE8C30
:
1163 *bar
= QLCNIC_83XX_BAR0_LENGTH
;
1170 static int qlcnic_setup_pci_map(struct pci_dev
*pdev
,
1171 struct qlcnic_hardware_context
*ahw
)
1174 void __iomem
*mem_ptr0
= NULL
;
1175 unsigned long mem_len
, pci_len0
= 0, bar0_len
;
1177 /* remap phys address */
1178 mem_len
= pci_resource_len(pdev
, 0);
1180 qlcnic_get_bar_length(pdev
->device
, &bar0_len
);
1181 if (mem_len
>= bar0_len
) {
1183 mem_ptr0
= pci_ioremap_bar(pdev
, 0);
1184 if (mem_ptr0
== NULL
) {
1185 dev_err(&pdev
->dev
, "failed to map PCI bar 0\n");
1193 dev_info(&pdev
->dev
, "%dKB memory map\n", (int)(mem_len
>> 10));
1195 ahw
->pci_base0
= mem_ptr0
;
1196 ahw
->pci_len0
= pci_len0
;
1197 offset
= QLCNIC_PCIX_PS_REG(PCIX_OCM_WINDOW_REG(ahw
->pci_func
));
1198 qlcnic_get_ioaddr(ahw
, offset
);
1203 static bool qlcnic_validate_subsystem_id(struct qlcnic_adapter
*adapter
,
1206 struct pci_dev
*pdev
= adapter
->pdev
;
1207 unsigned short subsystem_vendor
;
1210 subsystem_vendor
= pdev
->subsystem_vendor
;
1212 if (pdev
->device
== PCI_DEVICE_ID_QLOGIC_QLE824X
||
1213 pdev
->device
== PCI_DEVICE_ID_QLOGIC_QLE834X
) {
1214 if (qlcnic_boards
[index
].sub_vendor
== subsystem_vendor
&&
1215 qlcnic_boards
[index
].sub_device
== pdev
->subsystem_device
)
1224 static void qlcnic_get_board_name(struct qlcnic_adapter
*adapter
, char *name
)
1226 struct pci_dev
*pdev
= adapter
->pdev
;
1229 for (i
= 0; i
< NUM_SUPPORTED_BOARDS
; ++i
) {
1230 if (qlcnic_boards
[i
].vendor
== pdev
->vendor
&&
1231 qlcnic_boards
[i
].device
== pdev
->device
&&
1232 qlcnic_validate_subsystem_id(adapter
, i
)) {
1239 sprintf(name
, "%pM Gigabit Ethernet", adapter
->mac_addr
);
1241 sprintf(name
, "%pM: %s" , adapter
->mac_addr
,
1242 qlcnic_boards
[i
].short_name
);
1246 qlcnic_check_options(struct qlcnic_adapter
*adapter
)
1249 u32 fw_major
, fw_minor
, fw_build
, prev_fw_version
;
1250 struct pci_dev
*pdev
= adapter
->pdev
;
1251 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
1252 struct qlcnic_fw_dump
*fw_dump
= &ahw
->fw_dump
;
1254 prev_fw_version
= adapter
->fw_version
;
1256 fw_major
= QLC_SHARED_REG_RD32(adapter
, QLCNIC_FW_VERSION_MAJOR
);
1257 fw_minor
= QLC_SHARED_REG_RD32(adapter
, QLCNIC_FW_VERSION_MINOR
);
1258 fw_build
= QLC_SHARED_REG_RD32(adapter
, QLCNIC_FW_VERSION_SUB
);
1260 adapter
->fw_version
= QLCNIC_VERSION_CODE(fw_major
, fw_minor
, fw_build
);
1262 err
= qlcnic_get_board_info(adapter
);
1264 dev_err(&pdev
->dev
, "Error getting board config info.\n");
1267 if (ahw
->op_mode
!= QLCNIC_NON_PRIV_FUNC
) {
1268 if (fw_dump
->tmpl_hdr
== NULL
||
1269 adapter
->fw_version
> prev_fw_version
) {
1270 vfree(fw_dump
->tmpl_hdr
);
1271 if (!qlcnic_fw_cmd_get_minidump_temp(adapter
))
1272 dev_info(&pdev
->dev
,
1273 "Supports FW dump capability\n");
1277 dev_info(&pdev
->dev
, "Driver v%s, firmware v%d.%d.%d\n",
1278 QLCNIC_LINUX_VERSIONID
, fw_major
, fw_minor
, fw_build
);
1280 if (adapter
->ahw
->port_type
== QLCNIC_XGBE
) {
1281 if (adapter
->flags
& QLCNIC_ESWITCH_ENABLED
) {
1282 adapter
->num_rxd
= DEFAULT_RCV_DESCRIPTORS_VF
;
1283 adapter
->max_rxd
= MAX_RCV_DESCRIPTORS_VF
;
1285 adapter
->num_rxd
= DEFAULT_RCV_DESCRIPTORS_10G
;
1286 adapter
->max_rxd
= MAX_RCV_DESCRIPTORS_10G
;
1289 adapter
->num_jumbo_rxd
= MAX_JUMBO_RCV_DESCRIPTORS_10G
;
1290 adapter
->max_jumbo_rxd
= MAX_JUMBO_RCV_DESCRIPTORS_10G
;
1292 } else if (adapter
->ahw
->port_type
== QLCNIC_GBE
) {
1293 adapter
->num_rxd
= DEFAULT_RCV_DESCRIPTORS_1G
;
1294 adapter
->num_jumbo_rxd
= MAX_JUMBO_RCV_DESCRIPTORS_1G
;
1295 adapter
->max_jumbo_rxd
= MAX_JUMBO_RCV_DESCRIPTORS_1G
;
1296 adapter
->max_rxd
= MAX_RCV_DESCRIPTORS_1G
;
1299 adapter
->ahw
->msix_supported
= !!qlcnic_use_msi_x
;
1301 adapter
->num_txd
= MAX_CMD_DESCRIPTORS
;
1303 adapter
->max_rds_rings
= MAX_RDS_RINGS
;
1307 qlcnic_initialize_nic(struct qlcnic_adapter
*adapter
)
1309 struct qlcnic_info nic_info
;
1312 memset(&nic_info
, 0, sizeof(struct qlcnic_info
));
1313 err
= qlcnic_get_nic_info(adapter
, &nic_info
, adapter
->ahw
->pci_func
);
1317 adapter
->ahw
->physical_port
= (u8
)nic_info
.phys_port
;
1318 adapter
->ahw
->switch_mode
= nic_info
.switch_mode
;
1319 adapter
->ahw
->max_tx_ques
= nic_info
.max_tx_ques
;
1320 adapter
->ahw
->max_rx_ques
= nic_info
.max_rx_ques
;
1321 adapter
->ahw
->capabilities
= nic_info
.capabilities
;
1323 if (adapter
->ahw
->capabilities
& QLCNIC_FW_CAPABILITY_MORE_CAPS
) {
1325 temp
= QLCRD32(adapter
, CRB_FW_CAPABILITIES_2
, &err
);
1328 adapter
->ahw
->extra_capability
[0] = temp
;
1330 adapter
->ahw
->extra_capability
[0] = 0;
1333 adapter
->ahw
->max_mac_filters
= nic_info
.max_mac_filters
;
1334 adapter
->ahw
->max_mtu
= nic_info
.max_mtu
;
1336 if (adapter
->ahw
->capabilities
& BIT_6
) {
1337 adapter
->flags
|= QLCNIC_ESWITCH_ENABLED
;
1338 adapter
->ahw
->nic_mode
= QLCNIC_VNIC_MODE
;
1339 adapter
->max_tx_rings
= QLCNIC_MAX_HW_VNIC_TX_RINGS
;
1340 adapter
->max_sds_rings
= QLCNIC_MAX_VNIC_SDS_RINGS
;
1342 dev_info(&adapter
->pdev
->dev
, "vNIC mode enabled.\n");
1344 adapter
->ahw
->nic_mode
= QLCNIC_DEFAULT_MODE
;
1345 adapter
->max_tx_rings
= QLCNIC_MAX_HW_TX_RINGS
;
1346 adapter
->max_sds_rings
= QLCNIC_MAX_SDS_RINGS
;
1347 adapter
->flags
&= ~QLCNIC_ESWITCH_ENABLED
;
1353 void qlcnic_set_vlan_config(struct qlcnic_adapter
*adapter
,
1354 struct qlcnic_esw_func_cfg
*esw_cfg
)
1356 if (esw_cfg
->discard_tagged
)
1357 adapter
->flags
&= ~QLCNIC_TAGGING_ENABLED
;
1359 adapter
->flags
|= QLCNIC_TAGGING_ENABLED
;
1361 if (esw_cfg
->vlan_id
) {
1362 adapter
->rx_pvid
= esw_cfg
->vlan_id
;
1363 adapter
->tx_pvid
= esw_cfg
->vlan_id
;
1365 adapter
->rx_pvid
= 0;
1366 adapter
->tx_pvid
= 0;
1371 qlcnic_vlan_rx_add(struct net_device
*netdev
, __be16 proto
, u16 vid
)
1373 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
1376 if (qlcnic_sriov_vf_check(adapter
)) {
1377 err
= qlcnic_sriov_cfg_vf_guest_vlan(adapter
, vid
, 1);
1380 "Cannot add VLAN filter for VLAN id %d, err=%d",
1386 set_bit(vid
, adapter
->vlans
);
1391 qlcnic_vlan_rx_del(struct net_device
*netdev
, __be16 proto
, u16 vid
)
1393 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
1396 if (qlcnic_sriov_vf_check(adapter
)) {
1397 err
= qlcnic_sriov_cfg_vf_guest_vlan(adapter
, vid
, 0);
1400 "Cannot delete VLAN filter for VLAN id %d, err=%d",
1406 qlcnic_restore_indev_addr(netdev
, NETDEV_DOWN
);
1407 clear_bit(vid
, adapter
->vlans
);
1411 void qlcnic_set_eswitch_port_features(struct qlcnic_adapter
*adapter
,
1412 struct qlcnic_esw_func_cfg
*esw_cfg
)
1414 adapter
->flags
&= ~(QLCNIC_MACSPOOF
| QLCNIC_MAC_OVERRIDE_DISABLED
|
1415 QLCNIC_PROMISC_DISABLED
);
1417 if (esw_cfg
->mac_anti_spoof
)
1418 adapter
->flags
|= QLCNIC_MACSPOOF
;
1420 if (!esw_cfg
->mac_override
)
1421 adapter
->flags
|= QLCNIC_MAC_OVERRIDE_DISABLED
;
1423 if (!esw_cfg
->promisc_mode
)
1424 adapter
->flags
|= QLCNIC_PROMISC_DISABLED
;
1427 int qlcnic_set_eswitch_port_config(struct qlcnic_adapter
*adapter
)
1429 struct qlcnic_esw_func_cfg esw_cfg
;
1431 if (!(adapter
->flags
& QLCNIC_ESWITCH_ENABLED
))
1434 esw_cfg
.pci_func
= adapter
->ahw
->pci_func
;
1435 if (qlcnic_get_eswitch_port_config(adapter
, &esw_cfg
))
1437 qlcnic_set_vlan_config(adapter
, &esw_cfg
);
1438 qlcnic_set_eswitch_port_features(adapter
, &esw_cfg
);
1439 qlcnic_set_netdev_features(adapter
, &esw_cfg
);
1444 void qlcnic_set_netdev_features(struct qlcnic_adapter
*adapter
,
1445 struct qlcnic_esw_func_cfg
*esw_cfg
)
1447 struct net_device
*netdev
= adapter
->netdev
;
1449 if (qlcnic_83xx_check(adapter
))
1452 adapter
->offload_flags
= esw_cfg
->offload_flags
;
1453 adapter
->flags
|= QLCNIC_APP_CHANGED_FLAGS
;
1454 netdev_update_features(netdev
);
1455 adapter
->flags
&= ~QLCNIC_APP_CHANGED_FLAGS
;
1459 qlcnic_check_eswitch_mode(struct qlcnic_adapter
*adapter
)
1461 u32 op_mode
, priv_level
;
1464 err
= qlcnic_initialize_nic(adapter
);
1468 if (adapter
->flags
& QLCNIC_ADAPTER_INITIALIZED
)
1471 op_mode
= QLC_SHARED_REG_RD32(adapter
, QLCNIC_DRV_OP_MODE
);
1472 priv_level
= QLC_DEV_GET_DRV(op_mode
, adapter
->ahw
->pci_func
);
1474 if (op_mode
== QLC_DEV_DRV_DEFAULT
)
1475 priv_level
= QLCNIC_MGMT_FUNC
;
1477 priv_level
= QLC_DEV_GET_DRV(op_mode
, adapter
->ahw
->pci_func
);
1479 if (adapter
->flags
& QLCNIC_ESWITCH_ENABLED
) {
1480 if (priv_level
== QLCNIC_MGMT_FUNC
) {
1481 adapter
->ahw
->op_mode
= QLCNIC_MGMT_FUNC
;
1482 err
= qlcnic_init_pci_info(adapter
);
1485 /* Set privilege level for other functions */
1486 qlcnic_set_function_modes(adapter
);
1487 dev_info(&adapter
->pdev
->dev
,
1488 "HAL Version: %d, Management function\n",
1489 adapter
->ahw
->fw_hal_version
);
1490 } else if (priv_level
== QLCNIC_PRIV_FUNC
) {
1491 adapter
->ahw
->op_mode
= QLCNIC_PRIV_FUNC
;
1492 dev_info(&adapter
->pdev
->dev
,
1493 "HAL Version: %d, Privileged function\n",
1494 adapter
->ahw
->fw_hal_version
);
1497 adapter
->ahw
->nic_mode
= QLCNIC_DEFAULT_MODE
;
1500 adapter
->flags
|= QLCNIC_ADAPTER_INITIALIZED
;
1505 int qlcnic_set_default_offload_settings(struct qlcnic_adapter
*adapter
)
1507 struct qlcnic_esw_func_cfg esw_cfg
;
1508 struct qlcnic_npar_info
*npar
;
1511 if (adapter
->need_fw_reset
)
1514 for (i
= 0; i
< adapter
->ahw
->total_nic_func
; i
++) {
1515 if (!adapter
->npars
[i
].eswitch_status
)
1518 memset(&esw_cfg
, 0, sizeof(struct qlcnic_esw_func_cfg
));
1519 esw_cfg
.pci_func
= adapter
->npars
[i
].pci_func
;
1520 esw_cfg
.mac_override
= BIT_0
;
1521 esw_cfg
.promisc_mode
= BIT_0
;
1522 if (qlcnic_82xx_check(adapter
)) {
1523 esw_cfg
.offload_flags
= BIT_0
;
1524 if (QLCNIC_IS_TSO_CAPABLE(adapter
))
1525 esw_cfg
.offload_flags
|= (BIT_1
| BIT_2
);
1527 if (qlcnic_config_switch_port(adapter
, &esw_cfg
))
1529 npar
= &adapter
->npars
[i
];
1530 npar
->pvid
= esw_cfg
.vlan_id
;
1531 npar
->mac_override
= esw_cfg
.mac_override
;
1532 npar
->mac_anti_spoof
= esw_cfg
.mac_anti_spoof
;
1533 npar
->discard_tagged
= esw_cfg
.discard_tagged
;
1534 npar
->promisc_mode
= esw_cfg
.promisc_mode
;
1535 npar
->offload_flags
= esw_cfg
.offload_flags
;
1543 qlcnic_reset_eswitch_config(struct qlcnic_adapter
*adapter
,
1544 struct qlcnic_npar_info
*npar
, int pci_func
)
1546 struct qlcnic_esw_func_cfg esw_cfg
;
1547 esw_cfg
.op_mode
= QLCNIC_PORT_DEFAULTS
;
1548 esw_cfg
.pci_func
= pci_func
;
1549 esw_cfg
.vlan_id
= npar
->pvid
;
1550 esw_cfg
.mac_override
= npar
->mac_override
;
1551 esw_cfg
.discard_tagged
= npar
->discard_tagged
;
1552 esw_cfg
.mac_anti_spoof
= npar
->mac_anti_spoof
;
1553 esw_cfg
.offload_flags
= npar
->offload_flags
;
1554 esw_cfg
.promisc_mode
= npar
->promisc_mode
;
1555 if (qlcnic_config_switch_port(adapter
, &esw_cfg
))
1558 esw_cfg
.op_mode
= QLCNIC_ADD_VLAN
;
1559 if (qlcnic_config_switch_port(adapter
, &esw_cfg
))
1565 int qlcnic_reset_npar_config(struct qlcnic_adapter
*adapter
)
1568 struct qlcnic_npar_info
*npar
;
1569 struct qlcnic_info nic_info
;
1572 if (qlcnic_82xx_check(adapter
))
1573 if (!adapter
->need_fw_reset
)
1576 /* Set the NPAR config data after FW reset */
1577 for (i
= 0; i
< adapter
->ahw
->total_nic_func
; i
++) {
1578 npar
= &adapter
->npars
[i
];
1579 pci_func
= npar
->pci_func
;
1580 if (!adapter
->npars
[i
].eswitch_status
)
1583 memset(&nic_info
, 0, sizeof(struct qlcnic_info
));
1584 err
= qlcnic_get_nic_info(adapter
, &nic_info
, pci_func
);
1587 nic_info
.min_tx_bw
= npar
->min_bw
;
1588 nic_info
.max_tx_bw
= npar
->max_bw
;
1589 err
= qlcnic_set_nic_info(adapter
, &nic_info
);
1593 if (npar
->enable_pm
) {
1594 err
= qlcnic_config_port_mirroring(adapter
,
1600 err
= qlcnic_reset_eswitch_config(adapter
, npar
, pci_func
);
1607 static int qlcnic_check_npar_opertional(struct qlcnic_adapter
*adapter
)
1609 u8 npar_opt_timeo
= QLCNIC_DEV_NPAR_OPER_TIMEO
;
1612 if (adapter
->ahw
->op_mode
== QLCNIC_MGMT_FUNC
)
1615 npar_state
= QLC_SHARED_REG_RD32(adapter
,
1616 QLCNIC_CRB_DEV_NPAR_STATE
);
1617 while (npar_state
!= QLCNIC_DEV_NPAR_OPER
&& --npar_opt_timeo
) {
1619 npar_state
= QLC_SHARED_REG_RD32(adapter
,
1620 QLCNIC_CRB_DEV_NPAR_STATE
);
1622 if (!npar_opt_timeo
) {
1623 dev_err(&adapter
->pdev
->dev
,
1624 "Waiting for NPAR state to operational timeout\n");
1631 qlcnic_set_mgmt_operations(struct qlcnic_adapter
*adapter
)
1635 if (!(adapter
->flags
& QLCNIC_ESWITCH_ENABLED
) ||
1636 adapter
->ahw
->op_mode
!= QLCNIC_MGMT_FUNC
)
1639 err
= qlcnic_set_default_offload_settings(adapter
);
1643 err
= qlcnic_reset_npar_config(adapter
);
1647 qlcnic_dev_set_npar_ready(adapter
);
1652 static int qlcnic_82xx_start_firmware(struct qlcnic_adapter
*adapter
)
1656 err
= qlcnic_can_start_firmware(adapter
);
1660 goto check_fw_status
;
1662 if (qlcnic_load_fw_file
)
1663 qlcnic_request_firmware(adapter
);
1665 err
= qlcnic_check_flash_fw_ver(adapter
);
1669 adapter
->ahw
->fw_type
= QLCNIC_FLASH_ROMIMAGE
;
1672 err
= qlcnic_need_fw_reset(adapter
);
1674 goto check_fw_status
;
1676 err
= qlcnic_pinit_from_rom(adapter
);
1680 err
= qlcnic_load_firmware(adapter
);
1684 qlcnic_release_firmware(adapter
);
1685 QLCWR32(adapter
, CRB_DRIVER_VERSION
, QLCNIC_DRIVER_VERSION
);
1688 err
= qlcnic_check_fw_status(adapter
);
1692 QLC_SHARED_REG_WR32(adapter
, QLCNIC_CRB_DEV_STATE
, QLCNIC_DEV_READY
);
1693 qlcnic_idc_debug_info(adapter
, 1);
1694 err
= qlcnic_check_eswitch_mode(adapter
);
1696 dev_err(&adapter
->pdev
->dev
,
1697 "Memory allocation failed for eswitch\n");
1700 err
= qlcnic_set_mgmt_operations(adapter
);
1704 qlcnic_check_options(adapter
);
1705 adapter
->need_fw_reset
= 0;
1707 qlcnic_release_firmware(adapter
);
1711 QLC_SHARED_REG_WR32(adapter
, QLCNIC_CRB_DEV_STATE
, QLCNIC_DEV_FAILED
);
1712 dev_err(&adapter
->pdev
->dev
, "Device state set to failed\n");
1714 qlcnic_release_firmware(adapter
);
1719 qlcnic_request_irq(struct qlcnic_adapter
*adapter
)
1721 irq_handler_t handler
;
1722 struct qlcnic_host_sds_ring
*sds_ring
;
1723 struct qlcnic_host_tx_ring
*tx_ring
;
1724 int err
, ring
, num_sds_rings
;
1726 unsigned long flags
= 0;
1727 struct net_device
*netdev
= adapter
->netdev
;
1728 struct qlcnic_recv_context
*recv_ctx
= adapter
->recv_ctx
;
1730 if (adapter
->ahw
->diag_test
== QLCNIC_INTERRUPT_TEST
) {
1731 if (qlcnic_82xx_check(adapter
))
1732 handler
= qlcnic_tmp_intr
;
1734 handler
= qlcnic_83xx_tmp_intr
;
1735 if (!QLCNIC_IS_MSI_FAMILY(adapter
))
1736 flags
|= IRQF_SHARED
;
1739 if (adapter
->flags
& QLCNIC_MSIX_ENABLED
)
1740 handler
= qlcnic_msix_intr
;
1741 else if (adapter
->flags
& QLCNIC_MSI_ENABLED
)
1742 handler
= qlcnic_msi_intr
;
1744 flags
|= IRQF_SHARED
;
1745 if (qlcnic_82xx_check(adapter
))
1746 handler
= qlcnic_intr
;
1748 handler
= qlcnic_83xx_intr
;
1751 adapter
->irq
= netdev
->irq
;
1753 if (adapter
->ahw
->diag_test
!= QLCNIC_LOOPBACK_TEST
) {
1754 if (qlcnic_82xx_check(adapter
) ||
1755 (qlcnic_83xx_check(adapter
) &&
1756 (adapter
->flags
& QLCNIC_MSIX_ENABLED
))) {
1757 num_sds_rings
= adapter
->drv_sds_rings
;
1758 for (ring
= 0; ring
< num_sds_rings
; ring
++) {
1759 sds_ring
= &recv_ctx
->sds_rings
[ring
];
1760 if (qlcnic_82xx_check(adapter
) &&
1761 !qlcnic_check_multi_tx(adapter
) &&
1762 (ring
== (num_sds_rings
- 1))) {
1763 if (!(adapter
->flags
&
1764 QLCNIC_MSIX_ENABLED
))
1765 snprintf(sds_ring
->name
,
1766 sizeof(sds_ring
->name
),
1769 snprintf(sds_ring
->name
,
1770 sizeof(sds_ring
->name
),
1772 netdev
->name
, ring
);
1774 snprintf(sds_ring
->name
,
1775 sizeof(sds_ring
->name
),
1777 netdev
->name
, ring
);
1779 err
= request_irq(sds_ring
->irq
, handler
, flags
,
1780 sds_ring
->name
, sds_ring
);
1785 if ((qlcnic_82xx_check(adapter
) &&
1786 qlcnic_check_multi_tx(adapter
)) ||
1787 (qlcnic_83xx_check(adapter
) &&
1788 (adapter
->flags
& QLCNIC_MSIX_ENABLED
) &&
1789 !(adapter
->flags
& QLCNIC_TX_INTR_SHARED
))) {
1790 handler
= qlcnic_msix_tx_intr
;
1791 for (ring
= 0; ring
< adapter
->drv_tx_rings
;
1793 tx_ring
= &adapter
->tx_ring
[ring
];
1794 snprintf(tx_ring
->name
, sizeof(tx_ring
->name
),
1795 "%s-tx-%d", netdev
->name
, ring
);
1796 err
= request_irq(tx_ring
->irq
, handler
, flags
,
1797 tx_ring
->name
, tx_ring
);
1807 qlcnic_free_irq(struct qlcnic_adapter
*adapter
)
1810 struct qlcnic_host_sds_ring
*sds_ring
;
1811 struct qlcnic_host_tx_ring
*tx_ring
;
1813 struct qlcnic_recv_context
*recv_ctx
= adapter
->recv_ctx
;
1815 if (adapter
->ahw
->diag_test
!= QLCNIC_LOOPBACK_TEST
) {
1816 if (qlcnic_82xx_check(adapter
) ||
1817 (qlcnic_83xx_check(adapter
) &&
1818 (adapter
->flags
& QLCNIC_MSIX_ENABLED
))) {
1819 for (ring
= 0; ring
< adapter
->drv_sds_rings
; ring
++) {
1820 sds_ring
= &recv_ctx
->sds_rings
[ring
];
1821 free_irq(sds_ring
->irq
, sds_ring
);
1824 if ((qlcnic_83xx_check(adapter
) &&
1825 !(adapter
->flags
& QLCNIC_TX_INTR_SHARED
)) ||
1826 (qlcnic_82xx_check(adapter
) &&
1827 qlcnic_check_multi_tx(adapter
))) {
1828 for (ring
= 0; ring
< adapter
->drv_tx_rings
;
1830 tx_ring
= &adapter
->tx_ring
[ring
];
1832 free_irq(tx_ring
->irq
, tx_ring
);
1838 static void qlcnic_get_lro_mss_capability(struct qlcnic_adapter
*adapter
)
1842 if (qlcnic_82xx_check(adapter
)) {
1843 if (adapter
->ahw
->extra_capability
[0] &
1844 QLCNIC_FW_CAPABILITY_2_LRO_MAX_TCP_SEG
)
1845 adapter
->flags
|= QLCNIC_FW_LRO_MSS_CAP
;
1847 capab
= adapter
->ahw
->capabilities
;
1848 if (QLC_83XX_GET_FW_LRO_MSS_CAPABILITY(capab
))
1849 adapter
->flags
|= QLCNIC_FW_LRO_MSS_CAP
;
1853 static int qlcnic_config_def_intr_coalesce(struct qlcnic_adapter
*adapter
)
1855 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
1858 /* Initialize interrupt coalesce parameters */
1859 ahw
->coal
.flag
= QLCNIC_INTR_DEFAULT
;
1861 if (qlcnic_83xx_check(adapter
)) {
1862 ahw
->coal
.type
= QLCNIC_INTR_COAL_TYPE_RX_TX
;
1863 ahw
->coal
.tx_time_us
= QLCNIC_DEF_INTR_COALESCE_TX_TIME_US
;
1864 ahw
->coal
.tx_packets
= QLCNIC_DEF_INTR_COALESCE_TX_PACKETS
;
1865 ahw
->coal
.rx_time_us
= QLCNIC_DEF_INTR_COALESCE_RX_TIME_US
;
1866 ahw
->coal
.rx_packets
= QLCNIC_DEF_INTR_COALESCE_RX_PACKETS
;
1868 err
= qlcnic_83xx_set_rx_tx_intr_coal(adapter
);
1870 ahw
->coal
.type
= QLCNIC_INTR_COAL_TYPE_RX
;
1871 ahw
->coal
.rx_time_us
= QLCNIC_DEF_INTR_COALESCE_RX_TIME_US
;
1872 ahw
->coal
.rx_packets
= QLCNIC_DEF_INTR_COALESCE_RX_PACKETS
;
1874 err
= qlcnic_82xx_set_rx_coalesce(adapter
);
1880 int __qlcnic_up(struct qlcnic_adapter
*adapter
, struct net_device
*netdev
)
1883 struct qlcnic_host_rds_ring
*rds_ring
;
1885 if (adapter
->is_up
!= QLCNIC_ADAPTER_UP_MAGIC
)
1888 if (test_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
1891 if (qlcnic_set_eswitch_port_config(adapter
))
1894 qlcnic_get_lro_mss_capability(adapter
);
1896 if (qlcnic_fw_create_ctx(adapter
))
1899 for (ring
= 0; ring
< adapter
->max_rds_rings
; ring
++) {
1900 rds_ring
= &adapter
->recv_ctx
->rds_rings
[ring
];
1901 qlcnic_post_rx_buffers(adapter
, rds_ring
, ring
);
1904 qlcnic_set_multi(netdev
);
1905 qlcnic_fw_cmd_set_mtu(adapter
, netdev
->mtu
);
1907 adapter
->ahw
->linkup
= 0;
1909 if (adapter
->drv_sds_rings
> 1)
1910 qlcnic_config_rss(adapter
, 1);
1912 qlcnic_config_def_intr_coalesce(adapter
);
1914 if (netdev
->features
& NETIF_F_LRO
)
1915 qlcnic_config_hw_lro(adapter
, QLCNIC_LRO_ENABLED
);
1917 set_bit(__QLCNIC_DEV_UP
, &adapter
->state
);
1918 qlcnic_napi_enable(adapter
);
1920 qlcnic_linkevent_request(adapter
, 1);
1922 adapter
->ahw
->reset_context
= 0;
1923 netif_tx_start_all_queues(netdev
);
1927 int qlcnic_up(struct qlcnic_adapter
*adapter
, struct net_device
*netdev
)
1932 if (netif_running(netdev
))
1933 err
= __qlcnic_up(adapter
, netdev
);
1939 void __qlcnic_down(struct qlcnic_adapter
*adapter
, struct net_device
*netdev
)
1943 if (adapter
->is_up
!= QLCNIC_ADAPTER_UP_MAGIC
)
1946 if (!test_and_clear_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
1950 netif_carrier_off(netdev
);
1951 adapter
->ahw
->linkup
= 0;
1952 netif_tx_disable(netdev
);
1954 qlcnic_free_mac_list(adapter
);
1956 if (adapter
->fhash
.fnum
)
1957 qlcnic_delete_lb_filters(adapter
);
1959 qlcnic_nic_set_promisc(adapter
, QLCNIC_NIU_NON_PROMISC_MODE
);
1960 if (qlcnic_sriov_vf_check(adapter
))
1961 qlcnic_sriov_cleanup_async_list(&adapter
->ahw
->sriov
->bc
);
1963 qlcnic_napi_disable(adapter
);
1965 qlcnic_fw_destroy_ctx(adapter
);
1966 adapter
->flags
&= ~QLCNIC_FW_LRO_MSS_CAP
;
1968 qlcnic_reset_rx_buffers_list(adapter
);
1970 for (ring
= 0; ring
< adapter
->drv_tx_rings
; ring
++)
1971 qlcnic_release_tx_buffers(adapter
, &adapter
->tx_ring
[ring
]);
1974 /* Usage: During suspend and firmware recovery module */
1976 void qlcnic_down(struct qlcnic_adapter
*adapter
, struct net_device
*netdev
)
1979 if (netif_running(netdev
))
1980 __qlcnic_down(adapter
, netdev
);
1986 qlcnic_attach(struct qlcnic_adapter
*adapter
)
1988 struct net_device
*netdev
= adapter
->netdev
;
1989 struct pci_dev
*pdev
= adapter
->pdev
;
1992 if (adapter
->is_up
== QLCNIC_ADAPTER_UP_MAGIC
)
1995 err
= qlcnic_napi_add(adapter
, netdev
);
1999 err
= qlcnic_alloc_sw_resources(adapter
);
2001 dev_err(&pdev
->dev
, "Error in setting sw resources\n");
2002 goto err_out_napi_del
;
2005 err
= qlcnic_alloc_hw_resources(adapter
);
2007 dev_err(&pdev
->dev
, "Error in setting hw resources\n");
2008 goto err_out_free_sw
;
2011 err
= qlcnic_request_irq(adapter
);
2013 dev_err(&pdev
->dev
, "failed to setup interrupt\n");
2014 goto err_out_free_hw
;
2017 qlcnic_create_sysfs_entries(adapter
);
2019 if (qlcnic_encap_rx_offload(adapter
))
2020 udp_tunnel_get_rx_info(netdev
);
2022 adapter
->is_up
= QLCNIC_ADAPTER_UP_MAGIC
;
2026 qlcnic_free_hw_resources(adapter
);
2028 qlcnic_free_sw_resources(adapter
);
2030 qlcnic_napi_del(adapter
);
2034 void qlcnic_detach(struct qlcnic_adapter
*adapter
)
2036 if (adapter
->is_up
!= QLCNIC_ADAPTER_UP_MAGIC
)
2039 qlcnic_remove_sysfs_entries(adapter
);
2041 qlcnic_free_hw_resources(adapter
);
2042 qlcnic_release_rx_buffers(adapter
);
2043 qlcnic_free_irq(adapter
);
2044 qlcnic_napi_del(adapter
);
2045 qlcnic_free_sw_resources(adapter
);
2050 void qlcnic_diag_free_res(struct net_device
*netdev
, int drv_sds_rings
)
2052 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
2053 struct qlcnic_host_sds_ring
*sds_ring
;
2054 int drv_tx_rings
= adapter
->drv_tx_rings
;
2057 clear_bit(__QLCNIC_DEV_UP
, &adapter
->state
);
2058 if (adapter
->ahw
->diag_test
== QLCNIC_INTERRUPT_TEST
) {
2059 for (ring
= 0; ring
< adapter
->drv_sds_rings
; ring
++) {
2060 sds_ring
= &adapter
->recv_ctx
->sds_rings
[ring
];
2061 qlcnic_disable_sds_intr(adapter
, sds_ring
);
2065 qlcnic_fw_destroy_ctx(adapter
);
2067 qlcnic_detach(adapter
);
2069 adapter
->ahw
->diag_test
= 0;
2070 adapter
->drv_sds_rings
= drv_sds_rings
;
2071 adapter
->drv_tx_rings
= drv_tx_rings
;
2073 if (qlcnic_attach(adapter
))
2076 if (netif_running(netdev
))
2077 __qlcnic_up(adapter
, netdev
);
2079 netif_device_attach(netdev
);
2082 static int qlcnic_alloc_adapter_resources(struct qlcnic_adapter
*adapter
)
2084 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
2087 adapter
->recv_ctx
= kzalloc(sizeof(struct qlcnic_recv_context
),
2089 if (!adapter
->recv_ctx
) {
2094 if (qlcnic_83xx_check(adapter
)) {
2095 ahw
->coal
.type
= QLCNIC_INTR_COAL_TYPE_RX_TX
;
2096 ahw
->coal
.tx_time_us
= QLCNIC_DEF_INTR_COALESCE_TX_TIME_US
;
2097 ahw
->coal
.tx_packets
= QLCNIC_DEF_INTR_COALESCE_TX_PACKETS
;
2098 ahw
->coal
.rx_time_us
= QLCNIC_DEF_INTR_COALESCE_RX_TIME_US
;
2099 ahw
->coal
.rx_packets
= QLCNIC_DEF_INTR_COALESCE_RX_PACKETS
;
2101 ahw
->coal
.type
= QLCNIC_INTR_COAL_TYPE_RX
;
2102 ahw
->coal
.rx_time_us
= QLCNIC_DEF_INTR_COALESCE_RX_TIME_US
;
2103 ahw
->coal
.rx_packets
= QLCNIC_DEF_INTR_COALESCE_RX_PACKETS
;
2107 memset(&adapter
->stats
, 0, sizeof(adapter
->stats
));
2112 static void qlcnic_free_adapter_resources(struct qlcnic_adapter
*adapter
)
2114 struct qlcnic_fw_dump
*fw_dump
= &adapter
->ahw
->fw_dump
;
2116 kfree(adapter
->recv_ctx
);
2117 adapter
->recv_ctx
= NULL
;
2119 if (fw_dump
->tmpl_hdr
) {
2120 vfree(fw_dump
->tmpl_hdr
);
2121 fw_dump
->tmpl_hdr
= NULL
;
2124 if (fw_dump
->dma_buffer
) {
2125 dma_free_coherent(&adapter
->pdev
->dev
, QLC_PEX_DMA_READ_SIZE
,
2126 fw_dump
->dma_buffer
, fw_dump
->phys_addr
);
2127 fw_dump
->dma_buffer
= NULL
;
2130 kfree(adapter
->ahw
->reset
.buff
);
2131 adapter
->ahw
->fw_dump
.tmpl_hdr
= NULL
;
2134 int qlcnic_diag_alloc_res(struct net_device
*netdev
, int test
)
2136 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
2137 struct qlcnic_host_sds_ring
*sds_ring
;
2138 struct qlcnic_host_rds_ring
*rds_ring
;
2142 netif_device_detach(netdev
);
2144 if (netif_running(netdev
))
2145 __qlcnic_down(adapter
, netdev
);
2147 qlcnic_detach(adapter
);
2149 adapter
->drv_sds_rings
= QLCNIC_SINGLE_RING
;
2150 adapter
->ahw
->diag_test
= test
;
2151 adapter
->ahw
->linkup
= 0;
2153 ret
= qlcnic_attach(adapter
);
2155 netif_device_attach(netdev
);
2159 ret
= qlcnic_fw_create_ctx(adapter
);
2161 qlcnic_detach(adapter
);
2162 netif_device_attach(netdev
);
2166 for (ring
= 0; ring
< adapter
->max_rds_rings
; ring
++) {
2167 rds_ring
= &adapter
->recv_ctx
->rds_rings
[ring
];
2168 qlcnic_post_rx_buffers(adapter
, rds_ring
, ring
);
2171 if (adapter
->ahw
->diag_test
== QLCNIC_INTERRUPT_TEST
) {
2172 for (ring
= 0; ring
< adapter
->drv_sds_rings
; ring
++) {
2173 sds_ring
= &adapter
->recv_ctx
->sds_rings
[ring
];
2174 qlcnic_enable_sds_intr(adapter
, sds_ring
);
2178 if (adapter
->ahw
->diag_test
== QLCNIC_LOOPBACK_TEST
) {
2179 adapter
->ahw
->loopback_state
= 0;
2180 qlcnic_linkevent_request(adapter
, 1);
2183 set_bit(__QLCNIC_DEV_UP
, &adapter
->state
);
2188 /* Reset context in hardware only */
2190 qlcnic_reset_hw_context(struct qlcnic_adapter
*adapter
)
2192 struct net_device
*netdev
= adapter
->netdev
;
2194 if (test_and_set_bit(__QLCNIC_RESETTING
, &adapter
->state
))
2197 netif_device_detach(netdev
);
2199 qlcnic_down(adapter
, netdev
);
2201 qlcnic_up(adapter
, netdev
);
2203 netif_device_attach(netdev
);
2205 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
2206 netdev_info(adapter
->netdev
, "%s: soft reset complete\n", __func__
);
2211 qlcnic_reset_context(struct qlcnic_adapter
*adapter
)
2214 struct net_device
*netdev
= adapter
->netdev
;
2216 if (test_and_set_bit(__QLCNIC_RESETTING
, &adapter
->state
))
2219 if (adapter
->is_up
== QLCNIC_ADAPTER_UP_MAGIC
) {
2221 netif_device_detach(netdev
);
2223 if (netif_running(netdev
))
2224 __qlcnic_down(adapter
, netdev
);
2226 qlcnic_detach(adapter
);
2228 if (netif_running(netdev
)) {
2229 err
= qlcnic_attach(adapter
);
2231 __qlcnic_up(adapter
, netdev
);
2232 qlcnic_restore_indev_addr(netdev
, NETDEV_UP
);
2236 netif_device_attach(netdev
);
2239 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
2243 static void qlcnic_82xx_set_mac_filter_count(struct qlcnic_adapter
*adapter
)
2245 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
2246 u16 act_pci_fn
= ahw
->total_nic_func
;
2249 ahw
->max_mc_count
= QLCNIC_MAX_MC_COUNT
;
2250 if (act_pci_fn
<= 2)
2251 count
= (QLCNIC_MAX_UC_COUNT
- QLCNIC_MAX_MC_COUNT
) /
2254 count
= (QLCNIC_LB_MAX_FILTERS
- QLCNIC_MAX_MC_COUNT
) /
2256 ahw
->max_uc_count
= count
;
2259 static int qlcnic_set_real_num_queues(struct qlcnic_adapter
*adapter
,
2260 u8 tx_queues
, u8 rx_queues
)
2262 struct net_device
*netdev
= adapter
->netdev
;
2266 err
= netif_set_real_num_tx_queues(netdev
, tx_queues
);
2268 netdev_err(netdev
, "failed to set %d Tx queues\n",
2275 err
= netif_set_real_num_rx_queues(netdev
, rx_queues
);
2277 netdev_err(netdev
, "failed to set %d Rx queues\n",
2285 qlcnic_setup_netdev(struct qlcnic_adapter
*adapter
, struct net_device
*netdev
,
2289 struct pci_dev
*pdev
= adapter
->pdev
;
2291 adapter
->rx_csum
= 1;
2292 adapter
->ahw
->mc_enabled
= 0;
2293 qlcnic_set_mac_filter_count(adapter
);
2295 netdev
->netdev_ops
= &qlcnic_netdev_ops
;
2296 netdev
->watchdog_timeo
= QLCNIC_WATCHDOG_TIMEOUTVALUE
* HZ
;
2298 qlcnic_change_mtu(netdev
, netdev
->mtu
);
2300 netdev
->ethtool_ops
= (qlcnic_sriov_vf_check(adapter
)) ?
2301 &qlcnic_sriov_vf_ethtool_ops
: &qlcnic_ethtool_ops
;
2303 netdev
->features
|= (NETIF_F_SG
| NETIF_F_IP_CSUM
| NETIF_F_RXCSUM
|
2304 NETIF_F_IPV6_CSUM
| NETIF_F_GRO
|
2305 NETIF_F_HW_VLAN_CTAG_RX
);
2306 netdev
->vlan_features
|= (NETIF_F_SG
| NETIF_F_IP_CSUM
|
2309 if (QLCNIC_IS_TSO_CAPABLE(adapter
)) {
2310 netdev
->features
|= (NETIF_F_TSO
| NETIF_F_TSO6
);
2311 netdev
->vlan_features
|= (NETIF_F_TSO
| NETIF_F_TSO6
);
2314 if (pci_using_dac
) {
2315 netdev
->features
|= NETIF_F_HIGHDMA
;
2316 netdev
->vlan_features
|= NETIF_F_HIGHDMA
;
2319 if (qlcnic_vlan_tx_check(adapter
))
2320 netdev
->features
|= (NETIF_F_HW_VLAN_CTAG_TX
);
2322 if (qlcnic_sriov_vf_check(adapter
))
2323 netdev
->features
|= NETIF_F_HW_VLAN_CTAG_FILTER
;
2325 if (adapter
->ahw
->capabilities
& QLCNIC_FW_CAPABILITY_HW_LRO
)
2326 netdev
->features
|= NETIF_F_LRO
;
2328 if (qlcnic_encap_tx_offload(adapter
)) {
2329 netdev
->features
|= NETIF_F_GSO_UDP_TUNNEL
;
2331 /* encapsulation Tx offload supported by Adapter */
2332 netdev
->hw_enc_features
= NETIF_F_IP_CSUM
|
2333 NETIF_F_GSO_UDP_TUNNEL
|
2338 if (qlcnic_encap_rx_offload(adapter
))
2339 netdev
->hw_enc_features
|= NETIF_F_RXCSUM
;
2341 netdev
->hw_features
= netdev
->features
;
2342 netdev
->priv_flags
|= IFF_UNICAST_FLT
;
2343 netdev
->irq
= adapter
->msix_entries
[0].vector
;
2345 /* MTU range: 68 - 9600 */
2346 netdev
->min_mtu
= P3P_MIN_MTU
;
2347 netdev
->max_mtu
= P3P_MAX_MTU
;
2349 err
= qlcnic_set_real_num_queues(adapter
, adapter
->drv_tx_rings
,
2350 adapter
->drv_sds_rings
);
2354 qlcnic_dcb_init_dcbnl_ops(adapter
->dcb
);
2356 err
= register_netdev(netdev
);
2358 dev_err(&pdev
->dev
, "failed to register net device\n");
2365 static int qlcnic_set_dma_mask(struct pci_dev
*pdev
, int *pci_using_dac
)
2367 if (!pci_set_dma_mask(pdev
, DMA_BIT_MASK(64)) &&
2368 !pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(64)))
2370 else if (!pci_set_dma_mask(pdev
, DMA_BIT_MASK(32)) &&
2371 !pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(32)))
2374 dev_err(&pdev
->dev
, "Unable to set DMA mask, aborting\n");
2381 void qlcnic_free_tx_rings(struct qlcnic_adapter
*adapter
)
2384 struct qlcnic_host_tx_ring
*tx_ring
;
2386 for (ring
= 0; ring
< adapter
->drv_tx_rings
; ring
++) {
2387 tx_ring
= &adapter
->tx_ring
[ring
];
2389 vfree(tx_ring
->cmd_buf_arr
);
2390 tx_ring
->cmd_buf_arr
= NULL
;
2393 kfree(adapter
->tx_ring
);
2396 int qlcnic_alloc_tx_rings(struct qlcnic_adapter
*adapter
,
2397 struct net_device
*netdev
)
2399 int ring
, vector
, index
;
2400 struct qlcnic_host_tx_ring
*tx_ring
;
2401 struct qlcnic_cmd_buffer
*cmd_buf_arr
;
2403 tx_ring
= kcalloc(adapter
->drv_tx_rings
,
2404 sizeof(struct qlcnic_host_tx_ring
), GFP_KERNEL
);
2405 if (tx_ring
== NULL
)
2408 adapter
->tx_ring
= tx_ring
;
2410 for (ring
= 0; ring
< adapter
->drv_tx_rings
; ring
++) {
2411 tx_ring
= &adapter
->tx_ring
[ring
];
2412 tx_ring
->num_desc
= adapter
->num_txd
;
2413 tx_ring
->txq
= netdev_get_tx_queue(netdev
, ring
);
2414 cmd_buf_arr
= vzalloc(TX_BUFF_RINGSIZE(tx_ring
));
2415 if (cmd_buf_arr
== NULL
) {
2416 qlcnic_free_tx_rings(adapter
);
2419 tx_ring
->cmd_buf_arr
= cmd_buf_arr
;
2420 spin_lock_init(&tx_ring
->tx_clean_lock
);
2423 if (qlcnic_83xx_check(adapter
) ||
2424 (qlcnic_82xx_check(adapter
) && qlcnic_check_multi_tx(adapter
))) {
2425 for (ring
= 0; ring
< adapter
->drv_tx_rings
; ring
++) {
2426 tx_ring
= &adapter
->tx_ring
[ring
];
2427 tx_ring
->adapter
= adapter
;
2428 if (adapter
->flags
& QLCNIC_MSIX_ENABLED
) {
2429 index
= adapter
->drv_sds_rings
+ ring
;
2430 vector
= adapter
->msix_entries
[index
].vector
;
2431 tx_ring
->irq
= vector
;
2439 void qlcnic_set_drv_version(struct qlcnic_adapter
*adapter
)
2441 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
2444 if (qlcnic_82xx_check(adapter
))
2445 fw_cmd
= QLCNIC_CMD_82XX_SET_DRV_VER
;
2446 else if (qlcnic_83xx_check(adapter
))
2447 fw_cmd
= QLCNIC_CMD_83XX_SET_DRV_VER
;
2449 if (ahw
->extra_capability
[0] & QLCNIC_FW_CAPABILITY_SET_DRV_VER
)
2450 qlcnic_fw_cmd_set_drv_version(adapter
, fw_cmd
);
2453 /* Reset firmware API lock */
2454 static void qlcnic_reset_api_lock(struct qlcnic_adapter
*adapter
)
2456 qlcnic_api_lock(adapter
);
2457 qlcnic_api_unlock(adapter
);
2462 qlcnic_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
2464 struct net_device
*netdev
= NULL
;
2465 struct qlcnic_adapter
*adapter
= NULL
;
2466 struct qlcnic_hardware_context
*ahw
;
2467 int err
, pci_using_dac
= -1;
2468 char board_name
[QLCNIC_MAX_BOARD_NAME_LEN
+ 19]; /* MAC + ": " + name */
2470 err
= pci_enable_device(pdev
);
2474 if (!(pci_resource_flags(pdev
, 0) & IORESOURCE_MEM
)) {
2476 goto err_out_disable_pdev
;
2479 err
= qlcnic_set_dma_mask(pdev
, &pci_using_dac
);
2481 goto err_out_disable_pdev
;
2483 err
= pci_request_regions(pdev
, qlcnic_driver_name
);
2485 goto err_out_disable_pdev
;
2487 pci_set_master(pdev
);
2488 pci_enable_pcie_error_reporting(pdev
);
2490 ahw
= kzalloc(sizeof(struct qlcnic_hardware_context
), GFP_KERNEL
);
2493 goto err_out_free_res
;
2496 switch (ent
->device
) {
2497 case PCI_DEVICE_ID_QLOGIC_QLE824X
:
2498 ahw
->hw_ops
= &qlcnic_hw_ops
;
2499 ahw
->reg_tbl
= (u32
*) qlcnic_reg_tbl
;
2501 case PCI_DEVICE_ID_QLOGIC_QLE834X
:
2502 case PCI_DEVICE_ID_QLOGIC_QLE8830
:
2503 case PCI_DEVICE_ID_QLOGIC_QLE844X
:
2504 qlcnic_83xx_register_map(ahw
);
2506 case PCI_DEVICE_ID_QLOGIC_VF_QLE834X
:
2507 case PCI_DEVICE_ID_QLOGIC_VF_QLE8C30
:
2508 case PCI_DEVICE_ID_QLOGIC_VF_QLE844X
:
2509 qlcnic_sriov_vf_register_map(ahw
);
2512 goto err_out_free_hw_res
;
2515 err
= qlcnic_setup_pci_map(pdev
, ahw
);
2517 goto err_out_free_hw_res
;
2519 netdev
= alloc_etherdev_mq(sizeof(struct qlcnic_adapter
),
2520 QLCNIC_MAX_TX_RINGS
);
2523 goto err_out_iounmap
;
2526 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
2528 adapter
= netdev_priv(netdev
);
2529 adapter
->netdev
= netdev
;
2530 adapter
->pdev
= pdev
;
2533 adapter
->qlcnic_wq
= create_singlethread_workqueue("qlcnic");
2534 if (adapter
->qlcnic_wq
== NULL
) {
2536 dev_err(&pdev
->dev
, "Failed to create workqueue\n");
2537 goto err_out_free_netdev
;
2540 err
= qlcnic_alloc_adapter_resources(adapter
);
2542 goto err_out_free_wq
;
2544 adapter
->dev_rst_time
= jiffies
;
2545 ahw
->revision_id
= pdev
->revision
;
2546 ahw
->max_vnic_func
= qlcnic_get_vnic_func_count(adapter
);
2547 if (qlcnic_mac_learn
== FDB_MAC_LEARN
)
2548 adapter
->fdb_mac_learn
= true;
2549 else if (qlcnic_mac_learn
== DRV_MAC_LEARN
)
2550 adapter
->drv_mac_learn
= true;
2552 rwlock_init(&adapter
->ahw
->crb_lock
);
2553 mutex_init(&adapter
->ahw
->mem_lock
);
2555 INIT_LIST_HEAD(&adapter
->mac_list
);
2557 qlcnic_register_dcb(adapter
);
2559 if (qlcnic_82xx_check(adapter
)) {
2560 qlcnic_check_vf(adapter
, ent
);
2561 adapter
->portnum
= adapter
->ahw
->pci_func
;
2562 qlcnic_reset_api_lock(adapter
);
2563 err
= qlcnic_start_firmware(adapter
);
2565 dev_err(&pdev
->dev
, "Loading fw failed.Please Reboot\n"
2566 "\t\tIf reboot doesn't help, try flashing the card\n");
2567 goto err_out_maintenance_mode
;
2570 /* compute and set default and max tx/sds rings */
2571 if (adapter
->ahw
->msix_supported
) {
2572 if (qlcnic_check_multi_tx_capability(adapter
) == 1)
2573 qlcnic_set_tx_ring_count(adapter
,
2574 QLCNIC_SINGLE_RING
);
2576 qlcnic_set_tx_ring_count(adapter
,
2577 QLCNIC_DEF_TX_RINGS
);
2578 qlcnic_set_sds_ring_count(adapter
,
2579 QLCNIC_DEF_SDS_RINGS
);
2581 qlcnic_set_tx_ring_count(adapter
, QLCNIC_SINGLE_RING
);
2582 qlcnic_set_sds_ring_count(adapter
, QLCNIC_SINGLE_RING
);
2585 err
= qlcnic_setup_idc_param(adapter
);
2587 goto err_out_free_hw
;
2589 adapter
->flags
|= QLCNIC_NEED_FLR
;
2591 } else if (qlcnic_83xx_check(adapter
)) {
2592 qlcnic_83xx_check_vf(adapter
, ent
);
2593 adapter
->portnum
= adapter
->ahw
->pci_func
;
2594 err
= qlcnic_83xx_init(adapter
, pci_using_dac
);
2597 case -ENOTRECOVERABLE
:
2598 dev_err(&pdev
->dev
, "Adapter initialization failed due to a faulty hardware\n");
2599 dev_err(&pdev
->dev
, "Please replace the adapter with new one and return the faulty adapter for repair\n");
2600 goto err_out_free_hw
;
2602 dev_err(&pdev
->dev
, "Adapter initialization failed. Please reboot\n");
2603 goto err_out_free_hw
;
2605 dev_err(&pdev
->dev
, "Adapter initialization failed\n");
2606 goto err_out_free_hw
;
2608 dev_err(&pdev
->dev
, "Adapter initialization failed. Driver will load in maintenance mode to recover the adapter using the application\n");
2609 goto err_out_maintenance_mode
;
2613 if (qlcnic_sriov_vf_check(adapter
))
2617 "%s: failed. Please Reboot\n", __func__
);
2619 goto err_out_free_hw
;
2622 if (qlcnic_read_mac_addr(adapter
))
2623 dev_warn(&pdev
->dev
, "failed to read mac addr\n");
2625 qlcnic_read_phys_port_id(adapter
);
2627 if (adapter
->portnum
== 0) {
2628 qlcnic_get_board_name(adapter
, board_name
);
2630 pr_info("%s: %s Board Chip rev 0x%x\n",
2631 module_name(THIS_MODULE
),
2632 board_name
, adapter
->ahw
->revision_id
);
2635 if (qlcnic_83xx_check(adapter
) && !qlcnic_use_msi_x
&&
2637 dev_warn(&pdev
->dev
,
2638 "Device does not support MSI interrupts\n");
2640 if (qlcnic_82xx_check(adapter
)) {
2641 qlcnic_dcb_enable(adapter
->dcb
);
2642 qlcnic_dcb_get_info(adapter
->dcb
);
2643 err
= qlcnic_setup_intr(adapter
);
2646 dev_err(&pdev
->dev
, "Failed to setup interrupt\n");
2647 goto err_out_disable_msi
;
2651 err
= qlcnic_get_act_pci_func(adapter
);
2653 goto err_out_disable_mbx_intr
;
2655 if (adapter
->portnum
== 0)
2656 qlcnic_set_drv_version(adapter
);
2658 err
= qlcnic_setup_netdev(adapter
, netdev
, pci_using_dac
);
2660 goto err_out_disable_mbx_intr
;
2662 pci_set_drvdata(pdev
, adapter
);
2664 if (qlcnic_82xx_check(adapter
))
2665 qlcnic_schedule_work(adapter
, qlcnic_fw_poll_work
,
2668 switch (adapter
->ahw
->port_type
) {
2670 dev_info(&adapter
->pdev
->dev
, "%s: GbE port initialized\n",
2671 adapter
->netdev
->name
);
2674 dev_info(&adapter
->pdev
->dev
, "%s: XGbE port initialized\n",
2675 adapter
->netdev
->name
);
2679 if (adapter
->drv_mac_learn
)
2680 qlcnic_alloc_lb_filters_mem(adapter
);
2682 qlcnic_add_sysfs(adapter
);
2683 qlcnic_register_hwmon_dev(adapter
);
2686 err_out_disable_mbx_intr
:
2687 if (qlcnic_83xx_check(adapter
))
2688 qlcnic_83xx_free_mbx_intr(adapter
);
2690 err_out_disable_msi
:
2691 qlcnic_teardown_intr(adapter
);
2692 qlcnic_cancel_idc_work(adapter
);
2693 qlcnic_clr_all_drv_state(adapter
, 0);
2696 qlcnic_free_adapter_resources(adapter
);
2699 destroy_workqueue(adapter
->qlcnic_wq
);
2701 err_out_free_netdev
:
2702 free_netdev(netdev
);
2705 qlcnic_cleanup_pci_map(ahw
);
2707 err_out_free_hw_res
:
2711 pci_release_regions(pdev
);
2713 err_out_disable_pdev
:
2714 pci_disable_device(pdev
);
2717 err_out_maintenance_mode
:
2718 set_bit(__QLCNIC_MAINTENANCE_MODE
, &adapter
->state
);
2719 netdev
->netdev_ops
= &qlcnic_netdev_failed_ops
;
2720 netdev
->ethtool_ops
= &qlcnic_ethtool_failed_ops
;
2721 ahw
->port_type
= QLCNIC_XGBE
;
2723 if (qlcnic_83xx_check(adapter
))
2724 adapter
->tgt_status_reg
= NULL
;
2726 ahw
->board_type
= QLCNIC_BRDTYPE_P3P_10G_SFP_PLUS
;
2728 err
= register_netdev(netdev
);
2731 dev_err(&pdev
->dev
, "Failed to register net device\n");
2732 qlcnic_clr_all_drv_state(adapter
, 0);
2733 goto err_out_free_hw
;
2736 pci_set_drvdata(pdev
, adapter
);
2737 qlcnic_add_sysfs(adapter
);
2742 static void qlcnic_remove(struct pci_dev
*pdev
)
2744 struct qlcnic_adapter
*adapter
;
2745 struct net_device
*netdev
;
2746 struct qlcnic_hardware_context
*ahw
;
2748 adapter
= pci_get_drvdata(pdev
);
2749 if (adapter
== NULL
)
2752 netdev
= adapter
->netdev
;
2754 qlcnic_cancel_idc_work(adapter
);
2755 qlcnic_sriov_pf_disable(adapter
);
2758 unregister_netdev(netdev
);
2759 qlcnic_sriov_cleanup(adapter
);
2761 if (qlcnic_83xx_check(adapter
)) {
2762 qlcnic_83xx_initialize_nic(adapter
, 0);
2763 cancel_delayed_work_sync(&adapter
->idc_aen_work
);
2764 qlcnic_83xx_free_mbx_intr(adapter
);
2765 qlcnic_83xx_detach_mailbox_work(adapter
);
2766 qlcnic_83xx_free_mailbox(ahw
->mailbox
);
2767 kfree(ahw
->fw_info
);
2770 qlcnic_dcb_free(adapter
->dcb
);
2771 qlcnic_detach(adapter
);
2772 kfree(adapter
->npars
);
2773 kfree(adapter
->eswitch
);
2775 if (qlcnic_82xx_check(adapter
))
2776 qlcnic_clr_all_drv_state(adapter
, 0);
2778 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
2780 qlcnic_free_lb_filters_mem(adapter
);
2782 qlcnic_teardown_intr(adapter
);
2784 qlcnic_remove_sysfs(adapter
);
2786 qlcnic_unregister_hwmon_dev(adapter
);
2788 qlcnic_cleanup_pci_map(adapter
->ahw
);
2790 qlcnic_release_firmware(adapter
);
2792 pci_disable_pcie_error_reporting(pdev
);
2793 pci_release_regions(pdev
);
2794 pci_disable_device(pdev
);
2796 if (adapter
->qlcnic_wq
) {
2797 destroy_workqueue(adapter
->qlcnic_wq
);
2798 adapter
->qlcnic_wq
= NULL
;
2801 qlcnic_free_adapter_resources(adapter
);
2803 free_netdev(netdev
);
2806 static void qlcnic_shutdown(struct pci_dev
*pdev
)
2808 if (__qlcnic_shutdown(pdev
))
2811 pci_disable_device(pdev
);
2815 static int qlcnic_suspend(struct pci_dev
*pdev
, pm_message_t state
)
2819 retval
= __qlcnic_shutdown(pdev
);
2823 pci_set_power_state(pdev
, pci_choose_state(pdev
, state
));
2827 static int qlcnic_resume(struct pci_dev
*pdev
)
2829 struct qlcnic_adapter
*adapter
= pci_get_drvdata(pdev
);
2832 err
= pci_enable_device(pdev
);
2836 pci_set_power_state(pdev
, PCI_D0
);
2837 pci_set_master(pdev
);
2838 pci_restore_state(pdev
);
2840 return __qlcnic_resume(adapter
);
2844 static int qlcnic_open(struct net_device
*netdev
)
2846 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
2849 if (test_bit(__QLCNIC_MAINTENANCE_MODE
, &adapter
->state
)) {
2850 netdev_err(netdev
, "%s: Device is in non-operational state\n",
2856 netif_carrier_off(netdev
);
2858 err
= qlcnic_attach(adapter
);
2862 err
= __qlcnic_up(adapter
, netdev
);
2864 qlcnic_detach(adapter
);
2870 * qlcnic_close - Disables a network interface entry point
2872 static int qlcnic_close(struct net_device
*netdev
)
2874 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
2876 __qlcnic_down(adapter
, netdev
);
2881 #define QLCNIC_VF_LB_BUCKET_SIZE 1
2883 void qlcnic_alloc_lb_filters_mem(struct qlcnic_adapter
*adapter
)
2887 struct net_device
*netdev
= adapter
->netdev
;
2888 u32 filter_size
= 0;
2889 u16 act_pci_func
= 0;
2891 if (adapter
->fhash
.fmax
&& adapter
->fhash
.fhead
)
2894 act_pci_func
= adapter
->ahw
->total_nic_func
;
2895 spin_lock_init(&adapter
->mac_learn_lock
);
2896 spin_lock_init(&adapter
->rx_mac_learn_lock
);
2898 if (qlcnic_sriov_vf_check(adapter
)) {
2899 filter_size
= QLCNIC_83XX_SRIOV_VF_MAX_MAC
- 1;
2900 adapter
->fhash
.fbucket_size
= QLCNIC_VF_LB_BUCKET_SIZE
;
2901 } else if (qlcnic_82xx_check(adapter
)) {
2902 filter_size
= QLCNIC_LB_MAX_FILTERS
;
2903 adapter
->fhash
.fbucket_size
= QLCNIC_LB_BUCKET_SIZE
;
2905 filter_size
= QLC_83XX_LB_MAX_FILTERS
;
2906 adapter
->fhash
.fbucket_size
= QLC_83XX_LB_BUCKET_SIZE
;
2909 head
= kcalloc(adapter
->fhash
.fbucket_size
,
2910 sizeof(struct hlist_head
), GFP_ATOMIC
);
2915 adapter
->fhash
.fmax
= (filter_size
/ act_pci_func
);
2916 adapter
->fhash
.fhead
= head
;
2918 netdev_info(netdev
, "active nic func = %d, mac filter size=%d\n",
2919 act_pci_func
, adapter
->fhash
.fmax
);
2921 for (i
= 0; i
< adapter
->fhash
.fbucket_size
; i
++)
2922 INIT_HLIST_HEAD(&adapter
->fhash
.fhead
[i
]);
2924 adapter
->rx_fhash
.fbucket_size
= adapter
->fhash
.fbucket_size
;
2926 head
= kcalloc(adapter
->rx_fhash
.fbucket_size
,
2927 sizeof(struct hlist_head
), GFP_ATOMIC
);
2932 adapter
->rx_fhash
.fmax
= (filter_size
/ act_pci_func
);
2933 adapter
->rx_fhash
.fhead
= head
;
2935 for (i
= 0; i
< adapter
->rx_fhash
.fbucket_size
; i
++)
2936 INIT_HLIST_HEAD(&adapter
->rx_fhash
.fhead
[i
]);
2939 static void qlcnic_free_lb_filters_mem(struct qlcnic_adapter
*adapter
)
2941 if (adapter
->fhash
.fmax
)
2942 kfree(adapter
->fhash
.fhead
);
2944 adapter
->fhash
.fhead
= NULL
;
2945 adapter
->fhash
.fmax
= 0;
2947 if (adapter
->rx_fhash
.fmax
)
2948 kfree(adapter
->rx_fhash
.fhead
);
2950 adapter
->rx_fhash
.fmax
= 0;
2951 adapter
->rx_fhash
.fhead
= NULL
;
2954 int qlcnic_check_temp(struct qlcnic_adapter
*adapter
)
2956 struct net_device
*netdev
= adapter
->netdev
;
2957 u32 temp_state
, temp_val
, temp
= 0;
2960 if (qlcnic_83xx_check(adapter
))
2961 temp
= QLCRDX(adapter
->ahw
, QLC_83XX_ASIC_TEMP
);
2963 if (qlcnic_82xx_check(adapter
))
2964 temp
= QLC_SHARED_REG_RD32(adapter
, QLCNIC_ASIC_TEMP
);
2966 temp_state
= qlcnic_get_temp_state(temp
);
2967 temp_val
= qlcnic_get_temp_val(temp
);
2969 if (temp_state
== QLCNIC_TEMP_PANIC
) {
2970 dev_err(&netdev
->dev
,
2971 "Device temperature %d degrees C exceeds"
2972 " maximum allowed. Hardware has been shut down.\n",
2975 } else if (temp_state
== QLCNIC_TEMP_WARN
) {
2976 if (adapter
->ahw
->temp
== QLCNIC_TEMP_NORMAL
) {
2977 dev_err(&netdev
->dev
,
2978 "Device temperature %d degrees C "
2979 "exceeds operating range."
2980 " Immediate action needed.\n",
2984 if (adapter
->ahw
->temp
== QLCNIC_TEMP_WARN
) {
2985 dev_info(&netdev
->dev
,
2986 "Device temperature is now %d degrees C"
2987 " in normal range.\n", temp_val
);
2990 adapter
->ahw
->temp
= temp_state
;
2994 static inline void dump_tx_ring_desc(struct qlcnic_host_tx_ring
*tx_ring
)
2998 for (i
= 0; i
< tx_ring
->num_desc
; i
++) {
2999 pr_info("TX Desc: %d\n", i
);
3000 print_hex_dump(KERN_INFO
, "TX: ", DUMP_PREFIX_OFFSET
, 16, 1,
3001 &tx_ring
->desc_head
[i
],
3002 sizeof(struct cmd_desc_type0
), true);
3006 static void qlcnic_dump_rings(struct qlcnic_adapter
*adapter
)
3008 struct qlcnic_recv_context
*recv_ctx
= adapter
->recv_ctx
;
3009 struct net_device
*netdev
= adapter
->netdev
;
3010 struct qlcnic_host_rds_ring
*rds_ring
;
3011 struct qlcnic_host_sds_ring
*sds_ring
;
3012 struct qlcnic_host_tx_ring
*tx_ring
;
3015 if (!netdev
|| !netif_running(netdev
))
3018 for (ring
= 0; ring
< adapter
->max_rds_rings
; ring
++) {
3019 rds_ring
= &recv_ctx
->rds_rings
[ring
];
3023 "rds_ring=%d crb_rcv_producer=%d producer=%u num_desc=%u\n",
3024 ring
, readl(rds_ring
->crb_rcv_producer
),
3025 rds_ring
->producer
, rds_ring
->num_desc
);
3028 for (ring
= 0; ring
< adapter
->drv_sds_rings
; ring
++) {
3029 sds_ring
= &(recv_ctx
->sds_rings
[ring
]);
3033 "sds_ring=%d crb_sts_consumer=%d consumer=%u crb_intr_mask=%d num_desc=%u\n",
3034 ring
, readl(sds_ring
->crb_sts_consumer
),
3035 sds_ring
->consumer
, readl(sds_ring
->crb_intr_mask
),
3036 sds_ring
->num_desc
);
3039 for (ring
= 0; ring
< adapter
->drv_tx_rings
; ring
++) {
3040 tx_ring
= &adapter
->tx_ring
[ring
];
3043 netdev_info(netdev
, "Tx ring=%d Context Id=0x%x\n",
3044 ring
, tx_ring
->ctx_id
);
3046 "xmit_finished=%llu, xmit_called=%llu, xmit_on=%llu, xmit_off=%llu\n",
3047 tx_ring
->tx_stats
.xmit_finished
,
3048 tx_ring
->tx_stats
.xmit_called
,
3049 tx_ring
->tx_stats
.xmit_on
,
3050 tx_ring
->tx_stats
.xmit_off
);
3052 if (tx_ring
->crb_intr_mask
)
3053 netdev_info(netdev
, "crb_intr_mask=%d\n",
3054 readl(tx_ring
->crb_intr_mask
));
3057 "hw_producer=%d, sw_producer=%d sw_consumer=%d, hw_consumer=%d\n",
3058 readl(tx_ring
->crb_cmd_producer
),
3059 tx_ring
->producer
, tx_ring
->sw_consumer
,
3060 le32_to_cpu(*(tx_ring
->hw_consumer
)));
3062 netdev_info(netdev
, "Total desc=%d, Available desc=%d\n",
3063 tx_ring
->num_desc
, qlcnic_tx_avail(tx_ring
));
3065 if (netif_msg_tx_err(adapter
->ahw
))
3066 dump_tx_ring_desc(tx_ring
);
3071 static void qlcnic_tx_timeout(struct net_device
*netdev
)
3073 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
3075 if (test_bit(__QLCNIC_RESETTING
, &adapter
->state
))
3078 qlcnic_dump_rings(adapter
);
3080 if (++adapter
->tx_timeo_cnt
>= QLCNIC_MAX_TX_TIMEOUTS
||
3081 netif_msg_tx_err(adapter
->ahw
)) {
3082 netdev_err(netdev
, "Tx timeout, reset the adapter.\n");
3083 if (qlcnic_82xx_check(adapter
))
3084 adapter
->need_fw_reset
= 1;
3085 else if (qlcnic_83xx_check(adapter
))
3086 qlcnic_83xx_idc_request_reset(adapter
,
3087 QLCNIC_FORCE_FW_DUMP_KEY
);
3089 netdev_err(netdev
, "Tx timeout, reset adapter context.\n");
3090 adapter
->ahw
->reset_context
= 1;
3094 static struct net_device_stats
*qlcnic_get_stats(struct net_device
*netdev
)
3096 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
3097 struct net_device_stats
*stats
= &netdev
->stats
;
3099 if (test_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
3100 qlcnic_update_stats(adapter
);
3102 stats
->rx_packets
= adapter
->stats
.rx_pkts
+ adapter
->stats
.lro_pkts
;
3103 stats
->tx_packets
= adapter
->stats
.xmitfinished
;
3104 stats
->rx_bytes
= adapter
->stats
.rxbytes
+ adapter
->stats
.lrobytes
;
3105 stats
->tx_bytes
= adapter
->stats
.txbytes
;
3106 stats
->rx_dropped
= adapter
->stats
.rxdropped
;
3107 stats
->tx_dropped
= adapter
->stats
.txdropped
;
3112 static irqreturn_t
qlcnic_82xx_clear_legacy_intr(struct qlcnic_adapter
*adapter
)
3116 status
= readl(adapter
->isr_int_vec
);
3118 if (!(status
& adapter
->ahw
->int_vec_bit
))
3121 /* check interrupt state machine, to be sure */
3122 status
= readl(adapter
->crb_int_state_reg
);
3123 if (!ISR_LEGACY_INT_TRIGGERED(status
))
3126 writel(0xffffffff, adapter
->tgt_status_reg
);
3127 /* read twice to ensure write is flushed */
3128 readl(adapter
->isr_int_vec
);
3129 readl(adapter
->isr_int_vec
);
3134 static irqreturn_t
qlcnic_tmp_intr(int irq
, void *data
)
3136 struct qlcnic_host_sds_ring
*sds_ring
= data
;
3137 struct qlcnic_adapter
*adapter
= sds_ring
->adapter
;
3139 if (adapter
->flags
& QLCNIC_MSIX_ENABLED
)
3141 else if (adapter
->flags
& QLCNIC_MSI_ENABLED
) {
3142 writel(0xffffffff, adapter
->tgt_status_reg
);
3146 if (qlcnic_clear_legacy_intr(adapter
) == IRQ_NONE
)
3150 adapter
->ahw
->diag_cnt
++;
3151 qlcnic_enable_sds_intr(adapter
, sds_ring
);
3155 static irqreturn_t
qlcnic_intr(int irq
, void *data
)
3157 struct qlcnic_host_sds_ring
*sds_ring
= data
;
3158 struct qlcnic_adapter
*adapter
= sds_ring
->adapter
;
3160 if (qlcnic_clear_legacy_intr(adapter
) == IRQ_NONE
)
3163 napi_schedule(&sds_ring
->napi
);
3168 static irqreturn_t
qlcnic_msi_intr(int irq
, void *data
)
3170 struct qlcnic_host_sds_ring
*sds_ring
= data
;
3171 struct qlcnic_adapter
*adapter
= sds_ring
->adapter
;
3173 /* clear interrupt */
3174 writel(0xffffffff, adapter
->tgt_status_reg
);
3176 napi_schedule(&sds_ring
->napi
);
3180 static irqreturn_t
qlcnic_msix_intr(int irq
, void *data
)
3182 struct qlcnic_host_sds_ring
*sds_ring
= data
;
3184 napi_schedule(&sds_ring
->napi
);
3188 static irqreturn_t
qlcnic_msix_tx_intr(int irq
, void *data
)
3190 struct qlcnic_host_tx_ring
*tx_ring
= data
;
3192 napi_schedule(&tx_ring
->napi
);
3197 qlcnic_idc_debug_info(struct qlcnic_adapter
*adapter
, u8 encoding
)
3201 val
= adapter
->portnum
& 0xf;
3202 val
|= encoding
<< 7;
3203 val
|= (jiffies
- adapter
->dev_rst_time
) << 8;
3205 QLC_SHARED_REG_WR32(adapter
, QLCNIC_CRB_DRV_SCRATCH
, val
);
3206 adapter
->dev_rst_time
= jiffies
;
3210 qlcnic_set_drv_state(struct qlcnic_adapter
*adapter
, u8 state
)
3214 WARN_ON(state
!= QLCNIC_DEV_NEED_RESET
&&
3215 state
!= QLCNIC_DEV_NEED_QUISCENT
);
3217 if (qlcnic_api_lock(adapter
))
3220 val
= QLC_SHARED_REG_RD32(adapter
, QLCNIC_CRB_DRV_STATE
);
3222 if (state
== QLCNIC_DEV_NEED_RESET
)
3223 QLC_DEV_SET_RST_RDY(val
, adapter
->portnum
);
3224 else if (state
== QLCNIC_DEV_NEED_QUISCENT
)
3225 QLC_DEV_SET_QSCNT_RDY(val
, adapter
->portnum
);
3227 QLC_SHARED_REG_WR32(adapter
, QLCNIC_CRB_DRV_STATE
, val
);
3229 qlcnic_api_unlock(adapter
);
3235 qlcnic_clr_drv_state(struct qlcnic_adapter
*adapter
)
3239 if (qlcnic_api_lock(adapter
))
3242 val
= QLC_SHARED_REG_RD32(adapter
, QLCNIC_CRB_DRV_STATE
);
3243 QLC_DEV_CLR_RST_QSCNT(val
, adapter
->portnum
);
3244 QLC_SHARED_REG_WR32(adapter
, QLCNIC_CRB_DRV_STATE
, val
);
3246 qlcnic_api_unlock(adapter
);
3251 void qlcnic_clr_all_drv_state(struct qlcnic_adapter
*adapter
, u8 failed
)
3255 if (qlcnic_api_lock(adapter
))
3258 val
= QLC_SHARED_REG_RD32(adapter
, QLCNIC_CRB_DRV_ACTIVE
);
3259 QLC_DEV_CLR_REF_CNT(val
, adapter
->portnum
);
3260 QLC_SHARED_REG_WR32(adapter
, QLCNIC_CRB_DRV_ACTIVE
, val
);
3263 QLC_SHARED_REG_WR32(adapter
, QLCNIC_CRB_DEV_STATE
,
3265 dev_info(&adapter
->pdev
->dev
,
3266 "Device state set to Failed. Please Reboot\n");
3267 } else if (!(val
& 0x11111111))
3268 QLC_SHARED_REG_WR32(adapter
, QLCNIC_CRB_DEV_STATE
,
3271 val
= QLC_SHARED_REG_RD32(adapter
, QLCNIC_CRB_DRV_STATE
);
3272 QLC_DEV_CLR_RST_QSCNT(val
, adapter
->portnum
);
3273 QLC_SHARED_REG_WR32(adapter
, QLCNIC_CRB_DRV_STATE
, val
);
3275 qlcnic_api_unlock(adapter
);
3277 adapter
->fw_fail_cnt
= 0;
3278 adapter
->flags
&= ~QLCNIC_FW_HANG
;
3279 clear_bit(__QLCNIC_START_FW
, &adapter
->state
);
3280 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
3283 /* Grab api lock, before checking state */
3285 qlcnic_check_drv_state(struct qlcnic_adapter
*adapter
)
3287 int act
, state
, active_mask
;
3288 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
3290 state
= QLC_SHARED_REG_RD32(adapter
, QLCNIC_CRB_DRV_STATE
);
3291 act
= QLC_SHARED_REG_RD32(adapter
, QLCNIC_CRB_DRV_ACTIVE
);
3293 if (adapter
->flags
& QLCNIC_FW_RESET_OWNER
) {
3294 active_mask
= (~(1 << (ahw
->pci_func
* 4)));
3295 act
= act
& active_mask
;
3298 if (((state
& 0x11111111) == (act
& 0x11111111)) ||
3299 ((act
& 0x11111111) == ((state
>> 1) & 0x11111111)))
3305 static int qlcnic_check_idc_ver(struct qlcnic_adapter
*adapter
)
3307 u32 val
= QLC_SHARED_REG_RD32(adapter
, QLCNIC_CRB_DRV_IDC_VER
);
3309 if (val
!= QLCNIC_DRV_IDC_VER
) {
3310 dev_warn(&adapter
->pdev
->dev
, "IDC Version mismatch, driver's"
3311 " idc ver = %x; reqd = %x\n", QLCNIC_DRV_IDC_VER
, val
);
3318 qlcnic_can_start_firmware(struct qlcnic_adapter
*adapter
)
3320 u32 val
, prev_state
;
3321 u8 dev_init_timeo
= adapter
->dev_init_timeo
;
3322 u8 portnum
= adapter
->portnum
;
3325 if (test_and_clear_bit(__QLCNIC_START_FW
, &adapter
->state
))
3328 if (qlcnic_api_lock(adapter
))
3331 val
= QLC_SHARED_REG_RD32(adapter
, QLCNIC_CRB_DRV_ACTIVE
);
3332 if (!(val
& (1 << (portnum
* 4)))) {
3333 QLC_DEV_SET_REF_CNT(val
, portnum
);
3334 QLC_SHARED_REG_WR32(adapter
, QLCNIC_CRB_DRV_ACTIVE
, val
);
3337 prev_state
= QLC_SHARED_REG_RD32(adapter
, QLCNIC_CRB_DEV_STATE
);
3338 QLCDB(adapter
, HW
, "Device state = %u\n", prev_state
);
3340 switch (prev_state
) {
3341 case QLCNIC_DEV_COLD
:
3342 QLC_SHARED_REG_WR32(adapter
, QLCNIC_CRB_DEV_STATE
,
3343 QLCNIC_DEV_INITIALIZING
);
3344 QLC_SHARED_REG_WR32(adapter
, QLCNIC_CRB_DRV_IDC_VER
,
3345 QLCNIC_DRV_IDC_VER
);
3346 qlcnic_idc_debug_info(adapter
, 0);
3347 qlcnic_api_unlock(adapter
);
3350 case QLCNIC_DEV_READY
:
3351 ret
= qlcnic_check_idc_ver(adapter
);
3352 qlcnic_api_unlock(adapter
);
3355 case QLCNIC_DEV_NEED_RESET
:
3356 val
= QLC_SHARED_REG_RD32(adapter
, QLCNIC_CRB_DRV_STATE
);
3357 QLC_DEV_SET_RST_RDY(val
, portnum
);
3358 QLC_SHARED_REG_WR32(adapter
, QLCNIC_CRB_DRV_STATE
, val
);
3361 case QLCNIC_DEV_NEED_QUISCENT
:
3362 val
= QLC_SHARED_REG_RD32(adapter
, QLCNIC_CRB_DRV_STATE
);
3363 QLC_DEV_SET_QSCNT_RDY(val
, portnum
);
3364 QLC_SHARED_REG_WR32(adapter
, QLCNIC_CRB_DRV_STATE
, val
);
3367 case QLCNIC_DEV_FAILED
:
3368 dev_err(&adapter
->pdev
->dev
, "Device in failed state.\n");
3369 qlcnic_api_unlock(adapter
);
3372 case QLCNIC_DEV_INITIALIZING
:
3373 case QLCNIC_DEV_QUISCENT
:
3377 qlcnic_api_unlock(adapter
);
3381 prev_state
= QLC_SHARED_REG_RD32(adapter
, QLCNIC_CRB_DEV_STATE
);
3383 if (prev_state
== QLCNIC_DEV_QUISCENT
)
3385 } while ((prev_state
!= QLCNIC_DEV_READY
) && --dev_init_timeo
);
3387 if (!dev_init_timeo
) {
3388 dev_err(&adapter
->pdev
->dev
,
3389 "Waiting for device to initialize timeout\n");
3393 if (qlcnic_api_lock(adapter
))
3396 val
= QLC_SHARED_REG_RD32(adapter
, QLCNIC_CRB_DRV_STATE
);
3397 QLC_DEV_CLR_RST_QSCNT(val
, portnum
);
3398 QLC_SHARED_REG_WR32(adapter
, QLCNIC_CRB_DRV_STATE
, val
);
3400 ret
= qlcnic_check_idc_ver(adapter
);
3401 qlcnic_api_unlock(adapter
);
3407 qlcnic_fwinit_work(struct work_struct
*work
)
3409 struct qlcnic_adapter
*adapter
= container_of(work
,
3410 struct qlcnic_adapter
, fw_work
.work
);
3411 u32 dev_state
= 0xf;
3414 if (qlcnic_api_lock(adapter
))
3417 dev_state
= QLC_SHARED_REG_RD32(adapter
, QLCNIC_CRB_DEV_STATE
);
3418 if (dev_state
== QLCNIC_DEV_QUISCENT
||
3419 dev_state
== QLCNIC_DEV_NEED_QUISCENT
) {
3420 qlcnic_api_unlock(adapter
);
3421 qlcnic_schedule_work(adapter
, qlcnic_fwinit_work
,
3426 if (adapter
->ahw
->op_mode
== QLCNIC_NON_PRIV_FUNC
) {
3427 qlcnic_api_unlock(adapter
);
3431 if (dev_state
== QLCNIC_DEV_INITIALIZING
||
3432 dev_state
== QLCNIC_DEV_READY
) {
3433 dev_info(&adapter
->pdev
->dev
, "Detected state change from "
3434 "DEV_NEED_RESET, skipping ack check\n");
3435 goto skip_ack_check
;
3438 if (adapter
->fw_wait_cnt
++ > adapter
->reset_ack_timeo
) {
3439 dev_info(&adapter
->pdev
->dev
, "Reset:Failed to get ack %d sec\n",
3440 adapter
->reset_ack_timeo
);
3441 goto skip_ack_check
;
3444 if (!qlcnic_check_drv_state(adapter
)) {
3446 dev_state
= QLC_SHARED_REG_RD32(adapter
, QLCNIC_CRB_DEV_STATE
);
3448 if (dev_state
== QLCNIC_DEV_NEED_RESET
) {
3449 QLC_SHARED_REG_WR32(adapter
, QLCNIC_CRB_DEV_STATE
,
3450 QLCNIC_DEV_INITIALIZING
);
3451 set_bit(__QLCNIC_START_FW
, &adapter
->state
);
3452 QLCDB(adapter
, DRV
, "Restarting fw\n");
3453 qlcnic_idc_debug_info(adapter
, 0);
3454 val
= QLC_SHARED_REG_RD32(adapter
,
3455 QLCNIC_CRB_DRV_STATE
);
3456 QLC_DEV_SET_RST_RDY(val
, adapter
->portnum
);
3457 QLC_SHARED_REG_WR32(adapter
,
3458 QLCNIC_CRB_DRV_STATE
, val
);
3461 qlcnic_api_unlock(adapter
);
3464 if (qlcnic_check_fw_dump_state(adapter
) &&
3465 (adapter
->flags
& QLCNIC_FW_RESET_OWNER
)) {
3466 QLCDB(adapter
, DRV
, "Take FW dump\n");
3467 qlcnic_dump_fw(adapter
);
3468 adapter
->flags
|= QLCNIC_FW_HANG
;
3472 adapter
->flags
&= ~QLCNIC_FW_RESET_OWNER
;
3473 if (!adapter
->nic_ops
->start_firmware(adapter
)) {
3474 qlcnic_schedule_work(adapter
, qlcnic_attach_work
, 0);
3475 adapter
->fw_wait_cnt
= 0;
3481 qlcnic_api_unlock(adapter
);
3484 dev_state
= QLC_SHARED_REG_RD32(adapter
, QLCNIC_CRB_DEV_STATE
);
3485 QLCDB(adapter
, HW
, "Func waiting: Device state=%u\n", dev_state
);
3487 switch (dev_state
) {
3488 case QLCNIC_DEV_READY
:
3489 if (!qlcnic_start_firmware(adapter
)) {
3490 qlcnic_schedule_work(adapter
, qlcnic_attach_work
, 0);
3491 adapter
->fw_wait_cnt
= 0;
3494 case QLCNIC_DEV_FAILED
:
3497 qlcnic_schedule_work(adapter
,
3498 qlcnic_fwinit_work
, FW_POLL_DELAY
);
3503 dev_err(&adapter
->pdev
->dev
, "Fwinit work failed state=%u "
3504 "fw_wait_cnt=%u\n", dev_state
, adapter
->fw_wait_cnt
);
3505 netif_device_attach(adapter
->netdev
);
3506 qlcnic_clr_all_drv_state(adapter
, 0);
3510 qlcnic_detach_work(struct work_struct
*work
)
3512 struct qlcnic_adapter
*adapter
= container_of(work
,
3513 struct qlcnic_adapter
, fw_work
.work
);
3514 struct net_device
*netdev
= adapter
->netdev
;
3517 netif_device_detach(netdev
);
3519 /* Dont grab rtnl lock during Quiscent mode */
3520 if (adapter
->dev_state
== QLCNIC_DEV_NEED_QUISCENT
) {
3521 if (netif_running(netdev
))
3522 __qlcnic_down(adapter
, netdev
);
3524 qlcnic_down(adapter
, netdev
);
3526 status
= QLC_SHARED_REG_RD32(adapter
, QLCNIC_PEG_HALT_STATUS1
);
3528 if (status
& QLCNIC_RCODE_FATAL_ERROR
) {
3529 dev_err(&adapter
->pdev
->dev
,
3530 "Detaching the device: peg halt status1=0x%x\n",
3533 if (QLCNIC_FWERROR_CODE(status
) == QLCNIC_FWERROR_FAN_FAILURE
) {
3534 dev_err(&adapter
->pdev
->dev
,
3535 "On board active cooling fan failed. "
3536 "Device has been halted.\n");
3537 dev_err(&adapter
->pdev
->dev
,
3538 "Replace the adapter.\n");
3544 if (adapter
->ahw
->temp
== QLCNIC_TEMP_PANIC
) {
3545 dev_err(&adapter
->pdev
->dev
, "Detaching the device: temp=%d\n",
3546 adapter
->ahw
->temp
);
3550 /* Dont ack if this instance is the reset owner */
3551 if (!(adapter
->flags
& QLCNIC_FW_RESET_OWNER
)) {
3552 if (qlcnic_set_drv_state(adapter
, adapter
->dev_state
)) {
3553 dev_err(&adapter
->pdev
->dev
,
3554 "Failed to set driver state,"
3555 "detaching the device.\n");
3560 adapter
->fw_wait_cnt
= 0;
3562 qlcnic_schedule_work(adapter
, qlcnic_fwinit_work
, FW_POLL_DELAY
);
3567 netif_device_attach(netdev
);
3568 qlcnic_clr_all_drv_state(adapter
, 1);
3571 /*Transit NPAR state to NON Operational */
3573 qlcnic_set_npar_non_operational(struct qlcnic_adapter
*adapter
)
3577 state
= QLC_SHARED_REG_RD32(adapter
, QLCNIC_CRB_DEV_NPAR_STATE
);
3578 if (state
== QLCNIC_DEV_NPAR_NON_OPER
)
3581 if (qlcnic_api_lock(adapter
))
3583 QLC_SHARED_REG_WR32(adapter
, QLCNIC_CRB_DEV_NPAR_STATE
,
3584 QLCNIC_DEV_NPAR_NON_OPER
);
3585 qlcnic_api_unlock(adapter
);
3588 static void qlcnic_82xx_dev_request_reset(struct qlcnic_adapter
*adapter
,
3591 u32 state
, xg_val
= 0, gb_val
= 0;
3593 qlcnic_xg_set_xg0_mask(xg_val
);
3594 qlcnic_xg_set_xg1_mask(xg_val
);
3595 QLCWR32(adapter
, QLCNIC_NIU_XG_PAUSE_CTL
, xg_val
);
3596 qlcnic_gb_set_gb0_mask(gb_val
);
3597 qlcnic_gb_set_gb1_mask(gb_val
);
3598 qlcnic_gb_set_gb2_mask(gb_val
);
3599 qlcnic_gb_set_gb3_mask(gb_val
);
3600 QLCWR32(adapter
, QLCNIC_NIU_GB_PAUSE_CTL
, gb_val
);
3601 dev_info(&adapter
->pdev
->dev
, "Pause control frames disabled"
3603 adapter
->need_fw_reset
= 1;
3605 if (qlcnic_api_lock(adapter
))
3608 state
= QLC_SHARED_REG_RD32(adapter
, QLCNIC_CRB_DEV_STATE
);
3610 if (test_bit(__QLCNIC_MAINTENANCE_MODE
, &adapter
->state
)) {
3611 netdev_err(adapter
->netdev
, "%s: Device is in non-operational state\n",
3613 qlcnic_api_unlock(adapter
);
3618 if (state
== QLCNIC_DEV_READY
) {
3619 QLC_SHARED_REG_WR32(adapter
, QLCNIC_CRB_DEV_STATE
,
3620 QLCNIC_DEV_NEED_RESET
);
3621 adapter
->flags
|= QLCNIC_FW_RESET_OWNER
;
3622 QLCDB(adapter
, DRV
, "NEED_RESET state set\n");
3623 qlcnic_idc_debug_info(adapter
, 0);
3626 QLC_SHARED_REG_WR32(adapter
, QLCNIC_CRB_DEV_NPAR_STATE
,
3627 QLCNIC_DEV_NPAR_NON_OPER
);
3628 qlcnic_api_unlock(adapter
);
3631 /* Transit to NPAR READY state from NPAR NOT READY state */
3633 qlcnic_dev_set_npar_ready(struct qlcnic_adapter
*adapter
)
3635 if (qlcnic_api_lock(adapter
))
3638 QLC_SHARED_REG_WR32(adapter
, QLCNIC_CRB_DEV_NPAR_STATE
,
3639 QLCNIC_DEV_NPAR_OPER
);
3640 QLCDB(adapter
, DRV
, "NPAR operational state set\n");
3642 qlcnic_api_unlock(adapter
);
3645 void qlcnic_schedule_work(struct qlcnic_adapter
*adapter
,
3646 work_func_t func
, int delay
)
3648 if (test_bit(__QLCNIC_AER
, &adapter
->state
))
3651 INIT_DELAYED_WORK(&adapter
->fw_work
, func
);
3652 queue_delayed_work(adapter
->qlcnic_wq
, &adapter
->fw_work
,
3653 round_jiffies_relative(delay
));
3657 qlcnic_attach_work(struct work_struct
*work
)
3659 struct qlcnic_adapter
*adapter
= container_of(work
,
3660 struct qlcnic_adapter
, fw_work
.work
);
3661 struct net_device
*netdev
= adapter
->netdev
;
3664 if (adapter
->ahw
->op_mode
!= QLCNIC_MGMT_FUNC
) {
3665 npar_state
= QLC_SHARED_REG_RD32(adapter
,
3666 QLCNIC_CRB_DEV_NPAR_STATE
);
3667 if (adapter
->fw_wait_cnt
++ > QLCNIC_DEV_NPAR_OPER_TIMEO
)
3668 qlcnic_clr_all_drv_state(adapter
, 0);
3669 else if (npar_state
!= QLCNIC_DEV_NPAR_OPER
)
3670 qlcnic_schedule_work(adapter
, qlcnic_attach_work
,
3674 QLCDB(adapter
, DRV
, "Waiting for NPAR state to operational\n");
3678 qlcnic_dcb_get_info(adapter
->dcb
);
3680 if (netif_running(netdev
)) {
3681 if (qlcnic_up(adapter
, netdev
))
3684 qlcnic_restore_indev_addr(netdev
, NETDEV_UP
);
3688 netif_device_attach(netdev
);
3689 adapter
->fw_fail_cnt
= 0;
3690 adapter
->flags
&= ~QLCNIC_FW_HANG
;
3691 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
3692 if (adapter
->portnum
== 0)
3693 qlcnic_set_drv_version(adapter
);
3695 if (!qlcnic_clr_drv_state(adapter
))
3696 qlcnic_schedule_work(adapter
, qlcnic_fw_poll_work
,
3701 qlcnic_check_health(struct qlcnic_adapter
*adapter
)
3703 struct qlcnic_hardware_context
*ahw
= adapter
->ahw
;
3704 struct qlcnic_fw_dump
*fw_dump
= &ahw
->fw_dump
;
3705 u32 state
= 0, heartbeat
;
3709 if (qlcnic_check_temp(adapter
))
3712 if (adapter
->need_fw_reset
)
3713 qlcnic_dev_request_reset(adapter
, 0);
3715 state
= QLC_SHARED_REG_RD32(adapter
, QLCNIC_CRB_DEV_STATE
);
3716 if (state
== QLCNIC_DEV_NEED_RESET
) {
3717 qlcnic_set_npar_non_operational(adapter
);
3718 adapter
->need_fw_reset
= 1;
3719 } else if (state
== QLCNIC_DEV_NEED_QUISCENT
)
3722 heartbeat
= QLC_SHARED_REG_RD32(adapter
, QLCNIC_PEG_ALIVE_COUNTER
);
3723 if (heartbeat
!= adapter
->heartbeat
) {
3724 adapter
->heartbeat
= heartbeat
;
3725 adapter
->fw_fail_cnt
= 0;
3726 if (adapter
->need_fw_reset
)
3729 if (ahw
->reset_context
&& qlcnic_auto_fw_reset
)
3730 qlcnic_reset_hw_context(adapter
);
3735 if (++adapter
->fw_fail_cnt
< FW_FAIL_THRESH
)
3738 adapter
->flags
|= QLCNIC_FW_HANG
;
3740 qlcnic_dev_request_reset(adapter
, 0);
3742 if (qlcnic_auto_fw_reset
)
3743 clear_bit(__QLCNIC_FW_ATTACHED
, &adapter
->state
);
3745 dev_err(&adapter
->pdev
->dev
, "firmware hang detected\n");
3746 peg_status
= QLC_SHARED_REG_RD32(adapter
, QLCNIC_PEG_HALT_STATUS1
);
3747 dev_err(&adapter
->pdev
->dev
, "Dumping hw/fw registers\n"
3748 "PEG_HALT_STATUS1: 0x%x, PEG_HALT_STATUS2: 0x%x,\n"
3749 "PEG_NET_0_PC: 0x%x, PEG_NET_1_PC: 0x%x,\n"
3750 "PEG_NET_2_PC: 0x%x, PEG_NET_3_PC: 0x%x,\n"
3751 "PEG_NET_4_PC: 0x%x\n",
3753 QLC_SHARED_REG_RD32(adapter
, QLCNIC_PEG_HALT_STATUS2
),
3754 QLCRD32(adapter
, QLCNIC_CRB_PEG_NET_0
+ 0x3c, &err
),
3755 QLCRD32(adapter
, QLCNIC_CRB_PEG_NET_1
+ 0x3c, &err
),
3756 QLCRD32(adapter
, QLCNIC_CRB_PEG_NET_2
+ 0x3c, &err
),
3757 QLCRD32(adapter
, QLCNIC_CRB_PEG_NET_3
+ 0x3c, &err
),
3758 QLCRD32(adapter
, QLCNIC_CRB_PEG_NET_4
+ 0x3c, &err
));
3759 if (QLCNIC_FWERROR_CODE(peg_status
) == 0x67)
3760 dev_err(&adapter
->pdev
->dev
,
3761 "Firmware aborted with error code 0x00006700. "
3762 "Device is being reset.\n");
3764 adapter
->dev_state
= (state
== QLCNIC_DEV_NEED_QUISCENT
) ? state
:
3765 QLCNIC_DEV_NEED_RESET
;
3767 if (qlcnic_auto_fw_reset
&& !test_and_set_bit(__QLCNIC_RESETTING
,
3770 qlcnic_schedule_work(adapter
, qlcnic_detach_work
, 0);
3771 QLCDB(adapter
, DRV
, "fw recovery scheduled.\n");
3772 } else if (!qlcnic_auto_fw_reset
&& fw_dump
->enable
&&
3773 adapter
->flags
& QLCNIC_FW_RESET_OWNER
) {
3774 qlcnic_dump_fw(adapter
);
3780 void qlcnic_fw_poll_work(struct work_struct
*work
)
3782 struct qlcnic_adapter
*adapter
= container_of(work
,
3783 struct qlcnic_adapter
, fw_work
.work
);
3785 if (test_bit(__QLCNIC_RESETTING
, &adapter
->state
))
3789 if (qlcnic_check_health(adapter
))
3792 if (adapter
->fhash
.fnum
)
3793 qlcnic_prune_lb_filters(adapter
);
3796 qlcnic_schedule_work(adapter
, qlcnic_fw_poll_work
, FW_POLL_DELAY
);
3799 static int qlcnic_is_first_func(struct pci_dev
*pdev
)
3801 struct pci_dev
*oth_pdev
;
3802 int val
= pdev
->devfn
;
3805 oth_pdev
= pci_get_domain_bus_and_slot(pci_domain_nr
3806 (pdev
->bus
), pdev
->bus
->number
,
3807 PCI_DEVFN(PCI_SLOT(pdev
->devfn
), val
));
3811 if (oth_pdev
->current_state
!= PCI_D3cold
) {
3812 pci_dev_put(oth_pdev
);
3815 pci_dev_put(oth_pdev
);
3820 static int qlcnic_attach_func(struct pci_dev
*pdev
)
3822 int err
, first_func
;
3823 struct qlcnic_adapter
*adapter
= pci_get_drvdata(pdev
);
3824 struct net_device
*netdev
= adapter
->netdev
;
3826 pdev
->error_state
= pci_channel_io_normal
;
3828 err
= pci_enable_device(pdev
);
3832 pci_set_master(pdev
);
3833 pci_restore_state(pdev
);
3835 first_func
= qlcnic_is_first_func(pdev
);
3837 if (qlcnic_api_lock(adapter
))
3840 if (adapter
->ahw
->op_mode
!= QLCNIC_NON_PRIV_FUNC
&& first_func
) {
3841 adapter
->need_fw_reset
= 1;
3842 set_bit(__QLCNIC_START_FW
, &adapter
->state
);
3843 QLC_SHARED_REG_WR32(adapter
, QLCNIC_CRB_DEV_STATE
,
3844 QLCNIC_DEV_INITIALIZING
);
3845 QLCDB(adapter
, DRV
, "Restarting fw\n");
3847 qlcnic_api_unlock(adapter
);
3849 err
= qlcnic_start_firmware(adapter
);
3853 qlcnic_clr_drv_state(adapter
);
3854 kfree(adapter
->msix_entries
);
3855 adapter
->msix_entries
= NULL
;
3856 err
= qlcnic_setup_intr(adapter
);
3859 kfree(adapter
->msix_entries
);
3860 netdev_err(netdev
, "failed to setup interrupt\n");
3864 if (netif_running(netdev
)) {
3865 err
= qlcnic_attach(adapter
);
3867 qlcnic_clr_all_drv_state(adapter
, 1);
3868 clear_bit(__QLCNIC_AER
, &adapter
->state
);
3869 netif_device_attach(netdev
);
3873 err
= qlcnic_up(adapter
, netdev
);
3877 qlcnic_restore_indev_addr(netdev
, NETDEV_UP
);
3880 netif_device_attach(netdev
);
3884 static pci_ers_result_t
qlcnic_82xx_io_error_detected(struct pci_dev
*pdev
,
3885 pci_channel_state_t state
)
3887 struct qlcnic_adapter
*adapter
= pci_get_drvdata(pdev
);
3888 struct net_device
*netdev
= adapter
->netdev
;
3890 if (state
== pci_channel_io_perm_failure
)
3891 return PCI_ERS_RESULT_DISCONNECT
;
3893 if (state
== pci_channel_io_normal
)
3894 return PCI_ERS_RESULT_RECOVERED
;
3896 set_bit(__QLCNIC_AER
, &adapter
->state
);
3897 netif_device_detach(netdev
);
3899 cancel_delayed_work_sync(&adapter
->fw_work
);
3901 if (netif_running(netdev
))
3902 qlcnic_down(adapter
, netdev
);
3904 qlcnic_detach(adapter
);
3905 qlcnic_teardown_intr(adapter
);
3907 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
3909 pci_save_state(pdev
);
3910 pci_disable_device(pdev
);
3912 return PCI_ERS_RESULT_NEED_RESET
;
3915 static pci_ers_result_t
qlcnic_82xx_io_slot_reset(struct pci_dev
*pdev
)
3917 pci_ers_result_t res
;
3920 res
= qlcnic_attach_func(pdev
) ? PCI_ERS_RESULT_DISCONNECT
:
3921 PCI_ERS_RESULT_RECOVERED
;
3927 static void qlcnic_82xx_io_resume(struct pci_dev
*pdev
)
3930 struct qlcnic_adapter
*adapter
= pci_get_drvdata(pdev
);
3932 state
= QLC_SHARED_REG_RD32(adapter
, QLCNIC_CRB_DEV_STATE
);
3933 if (state
== QLCNIC_DEV_READY
&& test_and_clear_bit(__QLCNIC_AER
,
3935 qlcnic_schedule_work(adapter
, qlcnic_fw_poll_work
,
3939 static pci_ers_result_t
qlcnic_io_error_detected(struct pci_dev
*pdev
,
3940 pci_channel_state_t state
)
3942 struct qlcnic_adapter
*adapter
= pci_get_drvdata(pdev
);
3943 struct qlcnic_hardware_ops
*hw_ops
= adapter
->ahw
->hw_ops
;
3945 if (hw_ops
->io_error_detected
) {
3946 return hw_ops
->io_error_detected(pdev
, state
);
3948 dev_err(&pdev
->dev
, "AER error_detected handler not registered.\n");
3949 return PCI_ERS_RESULT_DISCONNECT
;
3953 static pci_ers_result_t
qlcnic_io_slot_reset(struct pci_dev
*pdev
)
3955 struct qlcnic_adapter
*adapter
= pci_get_drvdata(pdev
);
3956 struct qlcnic_hardware_ops
*hw_ops
= adapter
->ahw
->hw_ops
;
3958 if (hw_ops
->io_slot_reset
) {
3959 return hw_ops
->io_slot_reset(pdev
);
3961 dev_err(&pdev
->dev
, "AER slot_reset handler not registered.\n");
3962 return PCI_ERS_RESULT_DISCONNECT
;
3966 static void qlcnic_io_resume(struct pci_dev
*pdev
)
3968 struct qlcnic_adapter
*adapter
= pci_get_drvdata(pdev
);
3969 struct qlcnic_hardware_ops
*hw_ops
= adapter
->ahw
->hw_ops
;
3971 if (hw_ops
->io_resume
)
3972 hw_ops
->io_resume(pdev
);
3974 dev_err(&pdev
->dev
, "AER resume handler not registered.\n");
3979 qlcnicvf_start_firmware(struct qlcnic_adapter
*adapter
)
3983 err
= qlcnic_can_start_firmware(adapter
);
3987 err
= qlcnic_check_npar_opertional(adapter
);
3991 err
= qlcnic_initialize_nic(adapter
);
3995 qlcnic_check_options(adapter
);
3997 err
= qlcnic_set_eswitch_port_config(adapter
);
4001 adapter
->need_fw_reset
= 0;
4006 int qlcnic_validate_rings(struct qlcnic_adapter
*adapter
, __u32 ring_cnt
,
4009 struct net_device
*netdev
= adapter
->netdev
;
4012 if (queue_type
== QLCNIC_RX_QUEUE
)
4017 if (!is_power_of_2(ring_cnt
)) {
4018 netdev_err(netdev
, "%s rings value should be a power of 2\n",
4023 if (qlcnic_82xx_check(adapter
) && (queue_type
== QLCNIC_TX_QUEUE
) &&
4024 !qlcnic_check_multi_tx(adapter
)) {
4025 netdev_err(netdev
, "No Multi Tx queue support\n");
4029 if (ring_cnt
> num_online_cpus()) {
4031 "%s value[%u] should not be higher than, number of online CPUs\n",
4032 buf
, num_online_cpus());
4039 int qlcnic_setup_rings(struct qlcnic_adapter
*adapter
)
4041 struct net_device
*netdev
= adapter
->netdev
;
4042 u8 tx_rings
, rx_rings
;
4045 if (test_bit(__QLCNIC_RESETTING
, &adapter
->state
))
4048 tx_rings
= adapter
->drv_tss_rings
;
4049 rx_rings
= adapter
->drv_rss_rings
;
4051 netif_device_detach(netdev
);
4053 err
= qlcnic_set_real_num_queues(adapter
, tx_rings
, rx_rings
);
4057 if (netif_running(netdev
))
4058 __qlcnic_down(adapter
, netdev
);
4060 qlcnic_detach(adapter
);
4062 if (qlcnic_83xx_check(adapter
)) {
4063 qlcnic_83xx_free_mbx_intr(adapter
);
4064 qlcnic_83xx_enable_mbx_poll(adapter
);
4067 qlcnic_teardown_intr(adapter
);
4069 err
= qlcnic_setup_intr(adapter
);
4071 kfree(adapter
->msix_entries
);
4072 netdev_err(netdev
, "failed to setup interrupt\n");
4076 /* Check if we need to update real_num_{tx|rx}_queues because
4077 * qlcnic_setup_intr() may change Tx/Rx rings size
4079 if ((tx_rings
!= adapter
->drv_tx_rings
) ||
4080 (rx_rings
!= adapter
->drv_sds_rings
)) {
4081 err
= qlcnic_set_real_num_queues(adapter
,
4082 adapter
->drv_tx_rings
,
4083 adapter
->drv_sds_rings
);
4088 if (qlcnic_83xx_check(adapter
)) {
4089 qlcnic_83xx_initialize_nic(adapter
, 1);
4090 err
= qlcnic_83xx_setup_mbx_intr(adapter
);
4091 qlcnic_83xx_disable_mbx_poll(adapter
);
4093 dev_err(&adapter
->pdev
->dev
,
4094 "failed to setup mbx interrupt\n");
4099 if (netif_running(netdev
)) {
4100 err
= qlcnic_attach(adapter
);
4103 err
= __qlcnic_up(adapter
, netdev
);
4106 qlcnic_restore_indev_addr(netdev
, NETDEV_UP
);
4109 netif_device_attach(netdev
);
4110 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
4116 #define is_qlcnic_netdev(dev) (dev->netdev_ops == &qlcnic_netdev_ops)
4119 qlcnic_config_indev_addr(struct qlcnic_adapter
*adapter
,
4120 struct net_device
*dev
, unsigned long event
)
4122 struct in_device
*indev
;
4124 indev
= in_dev_get(dev
);
4131 qlcnic_config_ipaddr(adapter
,
4132 ifa
->ifa_address
, QLCNIC_IP_UP
);
4135 qlcnic_config_ipaddr(adapter
,
4136 ifa
->ifa_address
, QLCNIC_IP_DOWN
);
4141 } endfor_ifa(indev
);
4146 void qlcnic_restore_indev_addr(struct net_device
*netdev
, unsigned long event
)
4148 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
4149 struct net_device
*dev
;
4152 qlcnic_config_indev_addr(adapter
, netdev
, event
);
4155 for_each_set_bit(vid
, adapter
->vlans
, VLAN_N_VID
) {
4156 dev
= __vlan_find_dev_deep_rcu(netdev
, htons(ETH_P_8021Q
), vid
);
4159 qlcnic_config_indev_addr(adapter
, dev
, event
);
4164 static int qlcnic_netdev_event(struct notifier_block
*this,
4165 unsigned long event
, void *ptr
)
4167 struct qlcnic_adapter
*adapter
;
4168 struct net_device
*dev
= netdev_notifier_info_to_dev(ptr
);
4174 if (is_vlan_dev(dev
)) {
4175 dev
= vlan_dev_real_dev(dev
);
4179 if (!is_qlcnic_netdev(dev
))
4182 adapter
= netdev_priv(dev
);
4187 if (!test_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
4190 qlcnic_config_indev_addr(adapter
, dev
, event
);
4196 qlcnic_inetaddr_event(struct notifier_block
*this,
4197 unsigned long event
, void *ptr
)
4199 struct qlcnic_adapter
*adapter
;
4200 struct net_device
*dev
;
4202 struct in_ifaddr
*ifa
= (struct in_ifaddr
*)ptr
;
4204 dev
= ifa
->ifa_dev
? ifa
->ifa_dev
->dev
: NULL
;
4210 if (is_vlan_dev(dev
)) {
4211 dev
= vlan_dev_real_dev(dev
);
4215 if (!is_qlcnic_netdev(dev
))
4218 adapter
= netdev_priv(dev
);
4223 if (!test_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
4228 qlcnic_config_ipaddr(adapter
, ifa
->ifa_address
, QLCNIC_IP_UP
);
4232 qlcnic_config_ipaddr(adapter
, ifa
->ifa_address
, QLCNIC_IP_DOWN
);
4243 static struct notifier_block qlcnic_netdev_cb
= {
4244 .notifier_call
= qlcnic_netdev_event
,
4247 static struct notifier_block qlcnic_inetaddr_cb
= {
4248 .notifier_call
= qlcnic_inetaddr_event
,
4251 void qlcnic_restore_indev_addr(struct net_device
*dev
, unsigned long event
)
4254 static const struct pci_error_handlers qlcnic_err_handler
= {
4255 .error_detected
= qlcnic_io_error_detected
,
4256 .slot_reset
= qlcnic_io_slot_reset
,
4257 .resume
= qlcnic_io_resume
,
4260 static struct pci_driver qlcnic_driver
= {
4261 .name
= qlcnic_driver_name
,
4262 .id_table
= qlcnic_pci_tbl
,
4263 .probe
= qlcnic_probe
,
4264 .remove
= qlcnic_remove
,
4266 .suspend
= qlcnic_suspend
,
4267 .resume
= qlcnic_resume
,
4269 .shutdown
= qlcnic_shutdown
,
4270 .err_handler
= &qlcnic_err_handler
,
4271 #ifdef CONFIG_QLCNIC_SRIOV
4272 .sriov_configure
= qlcnic_pci_sriov_configure
,
4277 static int __init
qlcnic_init_module(void)
4281 printk(KERN_INFO
"%s\n", qlcnic_driver_string
);
4284 register_netdevice_notifier(&qlcnic_netdev_cb
);
4285 register_inetaddr_notifier(&qlcnic_inetaddr_cb
);
4288 ret
= pci_register_driver(&qlcnic_driver
);
4291 unregister_inetaddr_notifier(&qlcnic_inetaddr_cb
);
4292 unregister_netdevice_notifier(&qlcnic_netdev_cb
);
4299 module_init(qlcnic_init_module
);
4301 static void __exit
qlcnic_exit_module(void)
4303 pci_unregister_driver(&qlcnic_driver
);
4306 unregister_inetaddr_notifier(&qlcnic_inetaddr_cb
);
4307 unregister_netdevice_notifier(&qlcnic_netdev_cb
);
4311 module_exit(qlcnic_exit_module
);