]>
Commit | Line | Data |
---|---|---|
af19b491 | 1 | /* |
40839129 SV |
2 | * QLogic qlcnic NIC Driver |
3 | * Copyright (c) 2009-2010 QLogic Corporation | |
af19b491 | 4 | * |
40839129 | 5 | * See LICENSE.qlcnic for copyright and licensing details. |
af19b491 AKS |
6 | */ |
7 | ||
5a0e3ad6 | 8 | #include <linux/slab.h> |
af19b491 AKS |
9 | #include <linux/vmalloc.h> |
10 | #include <linux/interrupt.h> | |
11 | ||
12 | #include "qlcnic.h" | |
13 | ||
7e56cac4 | 14 | #include <linux/swab.h> |
af19b491 | 15 | #include <linux/dma-mapping.h> |
af19b491 AKS |
16 | #include <net/ip.h> |
17 | #include <linux/ipv6.h> | |
18 | #include <linux/inetdevice.h> | |
19 | #include <linux/sysfs.h> | |
451724c8 | 20 | #include <linux/aer.h> |
f94bc1e7 | 21 | #include <linux/log2.h> |
af19b491 | 22 | |
7f9a0c34 | 23 | MODULE_DESCRIPTION("QLogic 1/10 GbE Converged/Intelligent Ethernet Driver"); |
af19b491 AKS |
24 | MODULE_LICENSE("GPL"); |
25 | MODULE_VERSION(QLCNIC_LINUX_VERSIONID); | |
26 | MODULE_FIRMWARE(QLCNIC_UNIFIED_ROMIMAGE_NAME); | |
27 | ||
28 | char qlcnic_driver_name[] = "qlcnic"; | |
7f9a0c34 SV |
29 | static const char qlcnic_driver_string[] = "QLogic 1/10 GbE " |
30 | "Converged/Intelligent Ethernet Driver v" QLCNIC_LINUX_VERSIONID; | |
af19b491 | 31 | |
f7ec804a | 32 | static struct workqueue_struct *qlcnic_wq; |
b5e5492c | 33 | static int qlcnic_mac_learn; |
b11a25aa | 34 | module_param(qlcnic_mac_learn, int, 0444); |
b5e5492c AKS |
35 | MODULE_PARM_DESC(qlcnic_mac_learn, "Mac Filter (0=disabled, 1=enabled)"); |
36 | ||
af19b491 | 37 | static int use_msi = 1; |
b11a25aa | 38 | module_param(use_msi, int, 0444); |
af19b491 AKS |
39 | MODULE_PARM_DESC(use_msi, "MSI interrupt (0=disabled, 1=enabled"); |
40 | ||
41 | static int use_msi_x = 1; | |
b11a25aa | 42 | module_param(use_msi_x, int, 0444); |
af19b491 AKS |
43 | MODULE_PARM_DESC(use_msi_x, "MSI-X interrupt (0=disabled, 1=enabled"); |
44 | ||
9ce13ca8 | 45 | static int auto_fw_reset = 1; |
af19b491 AKS |
46 | module_param(auto_fw_reset, int, 0644); |
47 | MODULE_PARM_DESC(auto_fw_reset, "Auto firmware reset (0=disabled, 1=enabled"); | |
48 | ||
4d5bdb38 | 49 | static int load_fw_file; |
b11a25aa | 50 | module_param(load_fw_file, int, 0444); |
4d5bdb38 AKS |
51 | MODULE_PARM_DESC(load_fw_file, "Load firmware from (0=flash, 1=file"); |
52 | ||
2e9d722d | 53 | static int qlcnic_config_npars; |
b11a25aa | 54 | module_param(qlcnic_config_npars, int, 0444); |
2e9d722d AC |
55 | MODULE_PARM_DESC(qlcnic_config_npars, "Configure NPARs (0=disabled, 1=enabled"); |
56 | ||
af19b491 AKS |
57 | static int __devinit qlcnic_probe(struct pci_dev *pdev, |
58 | const struct pci_device_id *ent); | |
59 | static void __devexit qlcnic_remove(struct pci_dev *pdev); | |
60 | static int qlcnic_open(struct net_device *netdev); | |
61 | static int qlcnic_close(struct net_device *netdev); | |
af19b491 | 62 | static void qlcnic_tx_timeout(struct net_device *netdev); |
af19b491 AKS |
63 | static void qlcnic_attach_work(struct work_struct *work); |
64 | static void qlcnic_fwinit_work(struct work_struct *work); | |
65 | static void qlcnic_fw_poll_work(struct work_struct *work); | |
66 | static void qlcnic_schedule_work(struct qlcnic_adapter *adapter, | |
67 | work_func_t func, int delay); | |
68 | static void qlcnic_cancel_fw_work(struct qlcnic_adapter *adapter); | |
69 | static int qlcnic_poll(struct napi_struct *napi, int budget); | |
8f891387 | 70 | static int qlcnic_rx_poll(struct napi_struct *napi, int budget); |
af19b491 AKS |
71 | #ifdef CONFIG_NET_POLL_CONTROLLER |
72 | static void qlcnic_poll_controller(struct net_device *netdev); | |
73 | #endif | |
74 | ||
75 | static void qlcnic_create_sysfs_entries(struct qlcnic_adapter *adapter); | |
76 | static void qlcnic_remove_sysfs_entries(struct qlcnic_adapter *adapter); | |
77 | static void qlcnic_create_diag_entries(struct qlcnic_adapter *adapter); | |
78 | static void qlcnic_remove_diag_entries(struct qlcnic_adapter *adapter); | |
79 | ||
6df900e9 | 80 | static void qlcnic_idc_debug_info(struct qlcnic_adapter *adapter, u8 encoding); |
21854f02 | 81 | static void qlcnic_clr_all_drv_state(struct qlcnic_adapter *adapter, u8); |
af19b491 AKS |
82 | static int qlcnic_can_start_firmware(struct qlcnic_adapter *adapter); |
83 | ||
7eb9855d | 84 | static irqreturn_t qlcnic_tmp_intr(int irq, void *data); |
af19b491 AKS |
85 | static irqreturn_t qlcnic_intr(int irq, void *data); |
86 | static irqreturn_t qlcnic_msi_intr(int irq, void *data); | |
87 | static irqreturn_t qlcnic_msix_intr(int irq, void *data); | |
88 | ||
89 | static struct net_device_stats *qlcnic_get_stats(struct net_device *netdev); | |
aec1e845 | 90 | static void qlcnic_restore_indev_addr(struct net_device *dev, unsigned long); |
9f26f547 AC |
91 | static int qlcnic_start_firmware(struct qlcnic_adapter *); |
92 | ||
b5e5492c AKS |
93 | static void qlcnic_alloc_lb_filters_mem(struct qlcnic_adapter *adapter); |
94 | static void qlcnic_free_lb_filters_mem(struct qlcnic_adapter *adapter); | |
9f26f547 | 95 | static void qlcnic_dev_set_npar_ready(struct qlcnic_adapter *); |
9f26f547 AC |
96 | static int qlcnicvf_config_led(struct qlcnic_adapter *, u32, u32); |
97 | static int qlcnicvf_config_bridged_mode(struct qlcnic_adapter *, u32); | |
98 | static int qlcnicvf_start_firmware(struct qlcnic_adapter *); | |
0325d69b RB |
99 | static void qlcnic_set_netdev_features(struct qlcnic_adapter *, |
100 | struct qlcnic_esw_func_cfg *); | |
b9796a14 AC |
101 | static void qlcnic_vlan_rx_add(struct net_device *, u16); |
102 | static void qlcnic_vlan_rx_del(struct net_device *, u16); | |
103 | ||
af19b491 AKS |
104 | /* PCI Device ID Table */ |
105 | #define ENTRY(device) \ | |
106 | {PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, (device)), \ | |
107 | .class = PCI_CLASS_NETWORK_ETHERNET << 8, .class_mask = ~0} | |
108 | ||
109 | #define PCI_DEVICE_ID_QLOGIC_QLE824X 0x8020 | |
110 | ||
6a902881 | 111 | static DEFINE_PCI_DEVICE_TABLE(qlcnic_pci_tbl) = { |
af19b491 AKS |
112 | ENTRY(PCI_DEVICE_ID_QLOGIC_QLE824X), |
113 | {0,} | |
114 | }; | |
115 | ||
116 | MODULE_DEVICE_TABLE(pci, qlcnic_pci_tbl); | |
117 | ||
118 | ||
b1fc6d3c | 119 | inline void |
af19b491 AKS |
120 | qlcnic_update_cmd_producer(struct qlcnic_adapter *adapter, |
121 | struct qlcnic_host_tx_ring *tx_ring) | |
122 | { | |
123 | writel(tx_ring->producer, tx_ring->crb_cmd_producer); | |
af19b491 AKS |
124 | } |
125 | ||
126 | static const u32 msi_tgt_status[8] = { | |
127 | ISR_INT_TARGET_STATUS, ISR_INT_TARGET_STATUS_F1, | |
128 | ISR_INT_TARGET_STATUS_F2, ISR_INT_TARGET_STATUS_F3, | |
129 | ISR_INT_TARGET_STATUS_F4, ISR_INT_TARGET_STATUS_F5, | |
130 | ISR_INT_TARGET_STATUS_F6, ISR_INT_TARGET_STATUS_F7 | |
131 | }; | |
132 | ||
133 | static const | |
134 | struct qlcnic_legacy_intr_set legacy_intr[] = QLCNIC_LEGACY_INTR_CONFIG; | |
135 | ||
136 | static inline void qlcnic_disable_int(struct qlcnic_host_sds_ring *sds_ring) | |
137 | { | |
138 | writel(0, sds_ring->crb_intr_mask); | |
139 | } | |
140 | ||
141 | static inline void qlcnic_enable_int(struct qlcnic_host_sds_ring *sds_ring) | |
142 | { | |
143 | struct qlcnic_adapter *adapter = sds_ring->adapter; | |
144 | ||
145 | writel(0x1, sds_ring->crb_intr_mask); | |
146 | ||
147 | if (!QLCNIC_IS_MSI_FAMILY(adapter)) | |
148 | writel(0xfbff, adapter->tgt_mask_reg); | |
149 | } | |
150 | ||
151 | static int | |
152 | qlcnic_alloc_sds_rings(struct qlcnic_recv_context *recv_ctx, int count) | |
153 | { | |
154 | int size = sizeof(struct qlcnic_host_sds_ring) * count; | |
155 | ||
156 | recv_ctx->sds_rings = kzalloc(size, GFP_KERNEL); | |
157 | ||
807540ba | 158 | return recv_ctx->sds_rings == NULL; |
af19b491 AKS |
159 | } |
160 | ||
161 | static void | |
162 | qlcnic_free_sds_rings(struct qlcnic_recv_context *recv_ctx) | |
163 | { | |
164 | if (recv_ctx->sds_rings != NULL) | |
165 | kfree(recv_ctx->sds_rings); | |
166 | ||
167 | recv_ctx->sds_rings = NULL; | |
168 | } | |
169 | ||
170 | static int | |
171 | qlcnic_napi_add(struct qlcnic_adapter *adapter, struct net_device *netdev) | |
172 | { | |
173 | int ring; | |
174 | struct qlcnic_host_sds_ring *sds_ring; | |
b1fc6d3c | 175 | struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx; |
af19b491 AKS |
176 | |
177 | if (qlcnic_alloc_sds_rings(recv_ctx, adapter->max_sds_rings)) | |
178 | return -ENOMEM; | |
179 | ||
180 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { | |
181 | sds_ring = &recv_ctx->sds_rings[ring]; | |
8f891387 | 182 | |
183 | if (ring == adapter->max_sds_rings - 1) | |
184 | netif_napi_add(netdev, &sds_ring->napi, qlcnic_poll, | |
185 | QLCNIC_NETDEV_WEIGHT/adapter->max_sds_rings); | |
186 | else | |
187 | netif_napi_add(netdev, &sds_ring->napi, | |
188 | qlcnic_rx_poll, QLCNIC_NETDEV_WEIGHT*2); | |
af19b491 AKS |
189 | } |
190 | ||
191 | return 0; | |
192 | } | |
193 | ||
194 | static void | |
195 | qlcnic_napi_del(struct qlcnic_adapter *adapter) | |
196 | { | |
197 | int ring; | |
198 | struct qlcnic_host_sds_ring *sds_ring; | |
b1fc6d3c | 199 | struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx; |
af19b491 AKS |
200 | |
201 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { | |
202 | sds_ring = &recv_ctx->sds_rings[ring]; | |
203 | netif_napi_del(&sds_ring->napi); | |
204 | } | |
205 | ||
b1fc6d3c | 206 | qlcnic_free_sds_rings(adapter->recv_ctx); |
af19b491 AKS |
207 | } |
208 | ||
209 | static void | |
210 | qlcnic_napi_enable(struct qlcnic_adapter *adapter) | |
211 | { | |
212 | int ring; | |
213 | struct qlcnic_host_sds_ring *sds_ring; | |
b1fc6d3c | 214 | struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx; |
af19b491 | 215 | |
780ab790 AKS |
216 | if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC) |
217 | return; | |
218 | ||
af19b491 AKS |
219 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { |
220 | sds_ring = &recv_ctx->sds_rings[ring]; | |
221 | napi_enable(&sds_ring->napi); | |
222 | qlcnic_enable_int(sds_ring); | |
223 | } | |
224 | } | |
225 | ||
226 | static void | |
227 | qlcnic_napi_disable(struct qlcnic_adapter *adapter) | |
228 | { | |
229 | int ring; | |
230 | struct qlcnic_host_sds_ring *sds_ring; | |
b1fc6d3c | 231 | struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx; |
af19b491 | 232 | |
780ab790 AKS |
233 | if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC) |
234 | return; | |
235 | ||
af19b491 AKS |
236 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { |
237 | sds_ring = &recv_ctx->sds_rings[ring]; | |
238 | qlcnic_disable_int(sds_ring); | |
239 | napi_synchronize(&sds_ring->napi); | |
240 | napi_disable(&sds_ring->napi); | |
241 | } | |
242 | } | |
243 | ||
244 | static void qlcnic_clear_stats(struct qlcnic_adapter *adapter) | |
245 | { | |
246 | memset(&adapter->stats, 0, sizeof(adapter->stats)); | |
af19b491 AKS |
247 | } |
248 | ||
af19b491 AKS |
249 | static void qlcnic_set_msix_bit(struct pci_dev *pdev, int enable) |
250 | { | |
251 | u32 control; | |
252 | int pos; | |
253 | ||
254 | pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX); | |
255 | if (pos) { | |
256 | pci_read_config_dword(pdev, pos, &control); | |
257 | if (enable) | |
258 | control |= PCI_MSIX_FLAGS_ENABLE; | |
259 | else | |
260 | control = 0; | |
261 | pci_write_config_dword(pdev, pos, control); | |
262 | } | |
263 | } | |
264 | ||
265 | static void qlcnic_init_msix_entries(struct qlcnic_adapter *adapter, int count) | |
266 | { | |
267 | int i; | |
268 | ||
269 | for (i = 0; i < count; i++) | |
270 | adapter->msix_entries[i].entry = i; | |
271 | } | |
272 | ||
273 | static int | |
274 | qlcnic_read_mac_addr(struct qlcnic_adapter *adapter) | |
275 | { | |
2e9d722d | 276 | u8 mac_addr[ETH_ALEN]; |
af19b491 AKS |
277 | struct net_device *netdev = adapter->netdev; |
278 | struct pci_dev *pdev = adapter->pdev; | |
279 | ||
da48e6c3 | 280 | if (qlcnic_get_mac_address(adapter, mac_addr) != 0) |
af19b491 AKS |
281 | return -EIO; |
282 | ||
2e9d722d | 283 | memcpy(netdev->dev_addr, mac_addr, ETH_ALEN); |
af19b491 AKS |
284 | memcpy(netdev->perm_addr, netdev->dev_addr, netdev->addr_len); |
285 | memcpy(adapter->mac_addr, netdev->dev_addr, netdev->addr_len); | |
286 | ||
287 | /* set station address */ | |
288 | ||
289 | if (!is_valid_ether_addr(netdev->perm_addr)) | |
290 | dev_warn(&pdev->dev, "Bad MAC address %pM.\n", | |
291 | netdev->dev_addr); | |
292 | ||
293 | return 0; | |
294 | } | |
295 | ||
296 | static int qlcnic_set_mac(struct net_device *netdev, void *p) | |
297 | { | |
298 | struct qlcnic_adapter *adapter = netdev_priv(netdev); | |
299 | struct sockaddr *addr = p; | |
300 | ||
7373373d RB |
301 | if ((adapter->flags & QLCNIC_MAC_OVERRIDE_DISABLED)) |
302 | return -EOPNOTSUPP; | |
303 | ||
af19b491 AKS |
304 | if (!is_valid_ether_addr(addr->sa_data)) |
305 | return -EINVAL; | |
306 | ||
8a15ad1f | 307 | if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) { |
af19b491 AKS |
308 | netif_device_detach(netdev); |
309 | qlcnic_napi_disable(adapter); | |
310 | } | |
311 | ||
312 | memcpy(adapter->mac_addr, addr->sa_data, netdev->addr_len); | |
313 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); | |
314 | qlcnic_set_multi(adapter->netdev); | |
315 | ||
8a15ad1f | 316 | if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) { |
af19b491 AKS |
317 | netif_device_attach(netdev); |
318 | qlcnic_napi_enable(adapter); | |
319 | } | |
320 | return 0; | |
321 | } | |
322 | ||
323 | static const struct net_device_ops qlcnic_netdev_ops = { | |
324 | .ndo_open = qlcnic_open, | |
325 | .ndo_stop = qlcnic_close, | |
326 | .ndo_start_xmit = qlcnic_xmit_frame, | |
327 | .ndo_get_stats = qlcnic_get_stats, | |
328 | .ndo_validate_addr = eth_validate_addr, | |
329 | .ndo_set_multicast_list = qlcnic_set_multi, | |
330 | .ndo_set_mac_address = qlcnic_set_mac, | |
331 | .ndo_change_mtu = qlcnic_change_mtu, | |
135d84a9 MM |
332 | .ndo_fix_features = qlcnic_fix_features, |
333 | .ndo_set_features = qlcnic_set_features, | |
af19b491 | 334 | .ndo_tx_timeout = qlcnic_tx_timeout, |
b9796a14 AC |
335 | .ndo_vlan_rx_add_vid = qlcnic_vlan_rx_add, |
336 | .ndo_vlan_rx_kill_vid = qlcnic_vlan_rx_del, | |
af19b491 AKS |
337 | #ifdef CONFIG_NET_POLL_CONTROLLER |
338 | .ndo_poll_controller = qlcnic_poll_controller, | |
339 | #endif | |
340 | }; | |
341 | ||
2e9d722d | 342 | static struct qlcnic_nic_template qlcnic_ops = { |
2e9d722d AC |
343 | .config_bridged_mode = qlcnic_config_bridged_mode, |
344 | .config_led = qlcnic_config_led, | |
9f26f547 AC |
345 | .start_firmware = qlcnic_start_firmware |
346 | }; | |
347 | ||
348 | static struct qlcnic_nic_template qlcnic_vf_ops = { | |
9f26f547 AC |
349 | .config_bridged_mode = qlcnicvf_config_bridged_mode, |
350 | .config_led = qlcnicvf_config_led, | |
9f26f547 | 351 | .start_firmware = qlcnicvf_start_firmware |
2e9d722d AC |
352 | }; |
353 | ||
f94bc1e7 | 354 | static int qlcnic_enable_msix(struct qlcnic_adapter *adapter, u32 num_msix) |
af19b491 | 355 | { |
af19b491 | 356 | struct pci_dev *pdev = adapter->pdev; |
f94bc1e7 | 357 | int err = -1; |
af19b491 AKS |
358 | |
359 | adapter->max_sds_rings = 1; | |
af19b491 | 360 | adapter->flags &= ~(QLCNIC_MSI_ENABLED | QLCNIC_MSIX_ENABLED); |
af19b491 AKS |
361 | qlcnic_set_msix_bit(pdev, 0); |
362 | ||
363 | if (adapter->msix_supported) { | |
f94bc1e7 | 364 | enable_msix: |
af19b491 AKS |
365 | qlcnic_init_msix_entries(adapter, num_msix); |
366 | err = pci_enable_msix(pdev, adapter->msix_entries, num_msix); | |
367 | if (err == 0) { | |
368 | adapter->flags |= QLCNIC_MSIX_ENABLED; | |
369 | qlcnic_set_msix_bit(pdev, 1); | |
370 | ||
b1fc6d3c | 371 | adapter->max_sds_rings = num_msix; |
af19b491 AKS |
372 | |
373 | dev_info(&pdev->dev, "using msi-x interrupts\n"); | |
f94bc1e7 | 374 | return err; |
af19b491 | 375 | } |
f94bc1e7 SC |
376 | if (err > 0) { |
377 | num_msix = rounddown_pow_of_two(err); | |
378 | if (num_msix) | |
379 | goto enable_msix; | |
380 | } | |
381 | } | |
382 | return err; | |
383 | } | |
af19b491 | 384 | |
af19b491 | 385 | |
f94bc1e7 SC |
386 | static void qlcnic_enable_msi_legacy(struct qlcnic_adapter *adapter) |
387 | { | |
388 | const struct qlcnic_legacy_intr_set *legacy_intrp; | |
389 | struct pci_dev *pdev = adapter->pdev; | |
af19b491 AKS |
390 | |
391 | if (use_msi && !pci_enable_msi(pdev)) { | |
392 | adapter->flags |= QLCNIC_MSI_ENABLED; | |
393 | adapter->tgt_status_reg = qlcnic_get_ioaddr(adapter, | |
b1fc6d3c | 394 | msi_tgt_status[adapter->ahw->pci_func]); |
af19b491 AKS |
395 | dev_info(&pdev->dev, "using msi interrupts\n"); |
396 | adapter->msix_entries[0].vector = pdev->irq; | |
397 | return; | |
398 | } | |
399 | ||
f94bc1e7 SC |
400 | legacy_intrp = &legacy_intr[adapter->ahw->pci_func]; |
401 | ||
402 | adapter->int_vec_bit = legacy_intrp->int_vec_bit; | |
403 | adapter->tgt_status_reg = qlcnic_get_ioaddr(adapter, | |
404 | legacy_intrp->tgt_status_reg); | |
405 | adapter->tgt_mask_reg = qlcnic_get_ioaddr(adapter, | |
406 | legacy_intrp->tgt_mask_reg); | |
407 | adapter->isr_int_vec = qlcnic_get_ioaddr(adapter, ISR_INT_VECTOR); | |
408 | ||
409 | adapter->crb_int_state_reg = qlcnic_get_ioaddr(adapter, | |
410 | ISR_INT_STATE_REG); | |
af19b491 AKS |
411 | dev_info(&pdev->dev, "using legacy interrupts\n"); |
412 | adapter->msix_entries[0].vector = pdev->irq; | |
413 | } | |
414 | ||
f94bc1e7 SC |
415 | static void |
416 | qlcnic_setup_intr(struct qlcnic_adapter *adapter) | |
417 | { | |
418 | int num_msix; | |
419 | ||
420 | if (adapter->msix_supported) { | |
5f6ec29a SC |
421 | num_msix = rounddown_pow_of_two(min_t(int, num_online_cpus(), |
422 | QLCNIC_DEF_NUM_STS_DESC_RINGS)); | |
f94bc1e7 SC |
423 | } else |
424 | num_msix = 1; | |
425 | ||
426 | if (!qlcnic_enable_msix(adapter, num_msix)) | |
427 | return; | |
428 | ||
429 | qlcnic_enable_msi_legacy(adapter); | |
430 | } | |
431 | ||
af19b491 AKS |
432 | static void |
433 | qlcnic_teardown_intr(struct qlcnic_adapter *adapter) | |
434 | { | |
435 | if (adapter->flags & QLCNIC_MSIX_ENABLED) | |
436 | pci_disable_msix(adapter->pdev); | |
437 | if (adapter->flags & QLCNIC_MSI_ENABLED) | |
438 | pci_disable_msi(adapter->pdev); | |
439 | } | |
440 | ||
441 | static void | |
442 | qlcnic_cleanup_pci_map(struct qlcnic_adapter *adapter) | |
443 | { | |
b1fc6d3c AC |
444 | if (adapter->ahw->pci_base0 != NULL) |
445 | iounmap(adapter->ahw->pci_base0); | |
af19b491 AKS |
446 | } |
447 | ||
346fe763 RB |
448 | static int |
449 | qlcnic_init_pci_info(struct qlcnic_adapter *adapter) | |
450 | { | |
e88db3bd | 451 | struct qlcnic_pci_info *pci_info; |
900853a4 | 452 | int i, ret = 0; |
346fe763 RB |
453 | u8 pfn; |
454 | ||
e88db3bd DC |
455 | pci_info = kcalloc(QLCNIC_MAX_PCI_FUNC, sizeof(*pci_info), GFP_KERNEL); |
456 | if (!pci_info) | |
457 | return -ENOMEM; | |
458 | ||
ca315ac2 | 459 | adapter->npars = kzalloc(sizeof(struct qlcnic_npar_info) * |
346fe763 | 460 | QLCNIC_MAX_PCI_FUNC, GFP_KERNEL); |
e88db3bd | 461 | if (!adapter->npars) { |
900853a4 | 462 | ret = -ENOMEM; |
e88db3bd DC |
463 | goto err_pci_info; |
464 | } | |
346fe763 | 465 | |
ca315ac2 | 466 | adapter->eswitch = kzalloc(sizeof(struct qlcnic_eswitch) * |
346fe763 RB |
467 | QLCNIC_NIU_MAX_XG_PORTS, GFP_KERNEL); |
468 | if (!adapter->eswitch) { | |
900853a4 | 469 | ret = -ENOMEM; |
ca315ac2 | 470 | goto err_npars; |
346fe763 RB |
471 | } |
472 | ||
473 | ret = qlcnic_get_pci_info(adapter, pci_info); | |
ca315ac2 DC |
474 | if (ret) |
475 | goto err_eswitch; | |
346fe763 | 476 | |
ca315ac2 DC |
477 | for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) { |
478 | pfn = pci_info[i].id; | |
f848d6dd SC |
479 | if (pfn > QLCNIC_MAX_PCI_FUNC) { |
480 | ret = QL_STATUS_INVALID_PARAM; | |
481 | goto err_eswitch; | |
482 | } | |
a1c0c459 SC |
483 | adapter->npars[pfn].active = (u8)pci_info[i].active; |
484 | adapter->npars[pfn].type = (u8)pci_info[i].type; | |
485 | adapter->npars[pfn].phy_port = (u8)pci_info[i].default_port; | |
ca315ac2 DC |
486 | adapter->npars[pfn].min_bw = pci_info[i].tx_min_bw; |
487 | adapter->npars[pfn].max_bw = pci_info[i].tx_max_bw; | |
346fe763 RB |
488 | } |
489 | ||
ca315ac2 DC |
490 | for (i = 0; i < QLCNIC_NIU_MAX_XG_PORTS; i++) |
491 | adapter->eswitch[i].flags |= QLCNIC_SWITCH_ENABLE; | |
492 | ||
e88db3bd | 493 | kfree(pci_info); |
ca315ac2 DC |
494 | return 0; |
495 | ||
496 | err_eswitch: | |
346fe763 RB |
497 | kfree(adapter->eswitch); |
498 | adapter->eswitch = NULL; | |
ca315ac2 | 499 | err_npars: |
346fe763 | 500 | kfree(adapter->npars); |
ca315ac2 | 501 | adapter->npars = NULL; |
e88db3bd DC |
502 | err_pci_info: |
503 | kfree(pci_info); | |
346fe763 RB |
504 | |
505 | return ret; | |
506 | } | |
507 | ||
2e9d722d AC |
508 | static int |
509 | qlcnic_set_function_modes(struct qlcnic_adapter *adapter) | |
510 | { | |
511 | u8 id; | |
512 | u32 ref_count; | |
513 | int i, ret = 1; | |
514 | u32 data = QLCNIC_MGMT_FUNC; | |
b1fc6d3c | 515 | void __iomem *priv_op = adapter->ahw->pci_base0 + QLCNIC_DRV_OP_MODE; |
2e9d722d AC |
516 | |
517 | /* If other drivers are not in use set their privilege level */ | |
31018e06 | 518 | ref_count = QLCRD32(adapter, QLCNIC_CRB_DRV_ACTIVE); |
2e9d722d AC |
519 | ret = qlcnic_api_lock(adapter); |
520 | if (ret) | |
521 | goto err_lock; | |
2e9d722d | 522 | |
0e33c664 AC |
523 | if (qlcnic_config_npars) { |
524 | for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) { | |
346fe763 | 525 | id = i; |
0e33c664 | 526 | if (adapter->npars[i].type != QLCNIC_TYPE_NIC || |
b1fc6d3c | 527 | id == adapter->ahw->pci_func) |
0e33c664 AC |
528 | continue; |
529 | data |= (qlcnic_config_npars & | |
530 | QLC_DEV_SET_DRV(0xf, id)); | |
531 | } | |
532 | } else { | |
533 | data = readl(priv_op); | |
b1fc6d3c | 534 | data = (data & ~QLC_DEV_SET_DRV(0xf, adapter->ahw->pci_func)) | |
0e33c664 | 535 | (QLC_DEV_SET_DRV(QLCNIC_MGMT_FUNC, |
b1fc6d3c | 536 | adapter->ahw->pci_func)); |
2e9d722d AC |
537 | } |
538 | writel(data, priv_op); | |
2e9d722d AC |
539 | qlcnic_api_unlock(adapter); |
540 | err_lock: | |
541 | return ret; | |
542 | } | |
543 | ||
0866d96d AC |
544 | static void |
545 | qlcnic_check_vf(struct qlcnic_adapter *adapter) | |
2e9d722d AC |
546 | { |
547 | void __iomem *msix_base_addr; | |
548 | void __iomem *priv_op; | |
549 | u32 func; | |
550 | u32 msix_base; | |
551 | u32 op_mode, priv_level; | |
552 | ||
553 | /* Determine FW API version */ | |
b1fc6d3c AC |
554 | adapter->fw_hal_version = readl(adapter->ahw->pci_base0 + |
555 | QLCNIC_FW_API); | |
2e9d722d AC |
556 | |
557 | /* Find PCI function number */ | |
558 | pci_read_config_dword(adapter->pdev, QLCNIC_MSIX_TABLE_OFFSET, &func); | |
b1fc6d3c | 559 | msix_base_addr = adapter->ahw->pci_base0 + QLCNIC_MSIX_BASE; |
2e9d722d AC |
560 | msix_base = readl(msix_base_addr); |
561 | func = (func - msix_base)/QLCNIC_MSIX_TBL_PGSIZE; | |
b1fc6d3c | 562 | adapter->ahw->pci_func = func; |
2e9d722d AC |
563 | |
564 | /* Determine function privilege level */ | |
b1fc6d3c | 565 | priv_op = adapter->ahw->pci_base0 + QLCNIC_DRV_OP_MODE; |
2e9d722d | 566 | op_mode = readl(priv_op); |
0e33c664 | 567 | if (op_mode == QLC_DEV_DRV_DEFAULT) |
2e9d722d | 568 | priv_level = QLCNIC_MGMT_FUNC; |
0e33c664 | 569 | else |
b1fc6d3c | 570 | priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw->pci_func); |
2e9d722d | 571 | |
0866d96d | 572 | if (priv_level == QLCNIC_NON_PRIV_FUNC) { |
9f26f547 AC |
573 | adapter->op_mode = QLCNIC_NON_PRIV_FUNC; |
574 | dev_info(&adapter->pdev->dev, | |
575 | "HAL Version: %d Non Privileged function\n", | |
576 | adapter->fw_hal_version); | |
577 | adapter->nic_ops = &qlcnic_vf_ops; | |
0866d96d AC |
578 | } else |
579 | adapter->nic_ops = &qlcnic_ops; | |
2e9d722d AC |
580 | } |
581 | ||
af19b491 AKS |
582 | static int |
583 | qlcnic_setup_pci_map(struct qlcnic_adapter *adapter) | |
584 | { | |
585 | void __iomem *mem_ptr0 = NULL; | |
586 | resource_size_t mem_base; | |
587 | unsigned long mem_len, pci_len0 = 0; | |
588 | ||
589 | struct pci_dev *pdev = adapter->pdev; | |
af19b491 | 590 | |
af19b491 AKS |
591 | /* remap phys address */ |
592 | mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */ | |
593 | mem_len = pci_resource_len(pdev, 0); | |
594 | ||
595 | if (mem_len == QLCNIC_PCI_2MB_SIZE) { | |
596 | ||
597 | mem_ptr0 = pci_ioremap_bar(pdev, 0); | |
598 | if (mem_ptr0 == NULL) { | |
599 | dev_err(&pdev->dev, "failed to map PCI bar 0\n"); | |
600 | return -EIO; | |
601 | } | |
602 | pci_len0 = mem_len; | |
603 | } else { | |
604 | return -EIO; | |
605 | } | |
606 | ||
607 | dev_info(&pdev->dev, "%dMB memory map\n", (int)(mem_len>>20)); | |
608 | ||
b1fc6d3c AC |
609 | adapter->ahw->pci_base0 = mem_ptr0; |
610 | adapter->ahw->pci_len0 = pci_len0; | |
af19b491 | 611 | |
0866d96d | 612 | qlcnic_check_vf(adapter); |
2e9d722d | 613 | |
b1fc6d3c AC |
614 | adapter->ahw->ocm_win_crb = qlcnic_get_ioaddr(adapter, |
615 | QLCNIC_PCIX_PS_REG(PCIX_OCM_WINDOW_REG( | |
616 | adapter->ahw->pci_func))); | |
af19b491 AKS |
617 | |
618 | return 0; | |
619 | } | |
620 | ||
621 | static void get_brd_name(struct qlcnic_adapter *adapter, char *name) | |
622 | { | |
623 | struct pci_dev *pdev = adapter->pdev; | |
624 | int i, found = 0; | |
625 | ||
626 | for (i = 0; i < NUM_SUPPORTED_BOARDS; ++i) { | |
627 | if (qlcnic_boards[i].vendor == pdev->vendor && | |
628 | qlcnic_boards[i].device == pdev->device && | |
629 | qlcnic_boards[i].sub_vendor == pdev->subsystem_vendor && | |
630 | qlcnic_boards[i].sub_device == pdev->subsystem_device) { | |
02f6e46f SC |
631 | sprintf(name, "%pM: %s" , |
632 | adapter->mac_addr, | |
633 | qlcnic_boards[i].short_name); | |
af19b491 AKS |
634 | found = 1; |
635 | break; | |
636 | } | |
637 | ||
638 | } | |
639 | ||
640 | if (!found) | |
7f9a0c34 | 641 | sprintf(name, "%pM Gigabit Ethernet", adapter->mac_addr); |
af19b491 AKS |
642 | } |
643 | ||
644 | static void | |
645 | qlcnic_check_options(struct qlcnic_adapter *adapter) | |
646 | { | |
647 | u32 fw_major, fw_minor, fw_build; | |
af19b491 | 648 | struct pci_dev *pdev = adapter->pdev; |
af19b491 AKS |
649 | |
650 | fw_major = QLCRD32(adapter, QLCNIC_FW_VERSION_MAJOR); | |
651 | fw_minor = QLCRD32(adapter, QLCNIC_FW_VERSION_MINOR); | |
652 | fw_build = QLCRD32(adapter, QLCNIC_FW_VERSION_SUB); | |
653 | ||
654 | adapter->fw_version = QLCNIC_VERSION_CODE(fw_major, fw_minor, fw_build); | |
655 | ||
251a84c9 AKS |
656 | dev_info(&pdev->dev, "firmware v%d.%d.%d\n", |
657 | fw_major, fw_minor, fw_build); | |
b1fc6d3c | 658 | if (adapter->ahw->port_type == QLCNIC_XGBE) { |
90d19005 SC |
659 | if (adapter->flags & QLCNIC_ESWITCH_ENABLED) { |
660 | adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_VF; | |
661 | adapter->max_rxd = MAX_RCV_DESCRIPTORS_VF; | |
662 | } else { | |
663 | adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_10G; | |
664 | adapter->max_rxd = MAX_RCV_DESCRIPTORS_10G; | |
665 | } | |
666 | ||
af19b491 | 667 | adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G; |
90d19005 SC |
668 | adapter->max_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G; |
669 | ||
b1fc6d3c | 670 | } else if (adapter->ahw->port_type == QLCNIC_GBE) { |
af19b491 AKS |
671 | adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_1G; |
672 | adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G; | |
90d19005 SC |
673 | adapter->max_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G; |
674 | adapter->max_rxd = MAX_RCV_DESCRIPTORS_1G; | |
af19b491 AKS |
675 | } |
676 | ||
677 | adapter->msix_supported = !!use_msi_x; | |
af19b491 AKS |
678 | |
679 | adapter->num_txd = MAX_CMD_DESCRIPTORS; | |
680 | ||
251b036a | 681 | adapter->max_rds_rings = MAX_RDS_RINGS; |
af19b491 AKS |
682 | } |
683 | ||
174240a8 RB |
684 | static int |
685 | qlcnic_initialize_nic(struct qlcnic_adapter *adapter) | |
686 | { | |
687 | int err; | |
688 | struct qlcnic_info nic_info; | |
689 | ||
b1fc6d3c | 690 | err = qlcnic_get_nic_info(adapter, &nic_info, adapter->ahw->pci_func); |
174240a8 RB |
691 | if (err) |
692 | return err; | |
693 | ||
a1c0c459 | 694 | adapter->physical_port = (u8)nic_info.phys_port; |
174240a8 RB |
695 | adapter->switch_mode = nic_info.switch_mode; |
696 | adapter->max_tx_ques = nic_info.max_tx_ques; | |
697 | adapter->max_rx_ques = nic_info.max_rx_ques; | |
698 | adapter->capabilities = nic_info.capabilities; | |
699 | adapter->max_mac_filters = nic_info.max_mac_filters; | |
700 | adapter->max_mtu = nic_info.max_mtu; | |
701 | ||
702 | if (adapter->capabilities & BIT_6) | |
703 | adapter->flags |= QLCNIC_ESWITCH_ENABLED; | |
704 | else | |
705 | adapter->flags &= ~QLCNIC_ESWITCH_ENABLED; | |
706 | ||
707 | return err; | |
708 | } | |
709 | ||
8cf61f89 AKS |
710 | static void |
711 | qlcnic_set_vlan_config(struct qlcnic_adapter *adapter, | |
712 | struct qlcnic_esw_func_cfg *esw_cfg) | |
713 | { | |
714 | if (esw_cfg->discard_tagged) | |
715 | adapter->flags &= ~QLCNIC_TAGGING_ENABLED; | |
716 | else | |
717 | adapter->flags |= QLCNIC_TAGGING_ENABLED; | |
718 | ||
719 | if (esw_cfg->vlan_id) | |
720 | adapter->pvid = esw_cfg->vlan_id; | |
721 | else | |
722 | adapter->pvid = 0; | |
723 | } | |
724 | ||
b9796a14 AC |
725 | static void |
726 | qlcnic_vlan_rx_add(struct net_device *netdev, u16 vid) | |
727 | { | |
728 | struct qlcnic_adapter *adapter = netdev_priv(netdev); | |
729 | set_bit(vid, adapter->vlans); | |
730 | } | |
731 | ||
732 | static void | |
733 | qlcnic_vlan_rx_del(struct net_device *netdev, u16 vid) | |
734 | { | |
735 | struct qlcnic_adapter *adapter = netdev_priv(netdev); | |
736 | ||
737 | qlcnic_restore_indev_addr(netdev, NETDEV_DOWN); | |
738 | clear_bit(vid, adapter->vlans); | |
739 | } | |
740 | ||
0325d69b RB |
741 | static void |
742 | qlcnic_set_eswitch_port_features(struct qlcnic_adapter *adapter, | |
743 | struct qlcnic_esw_func_cfg *esw_cfg) | |
744 | { | |
ee07c1a7 RB |
745 | adapter->flags &= ~(QLCNIC_MACSPOOF | QLCNIC_MAC_OVERRIDE_DISABLED | |
746 | QLCNIC_PROMISC_DISABLED); | |
7613c87b RB |
747 | |
748 | if (esw_cfg->mac_anti_spoof) | |
749 | adapter->flags |= QLCNIC_MACSPOOF; | |
fe4d434d | 750 | |
7373373d RB |
751 | if (!esw_cfg->mac_override) |
752 | adapter->flags |= QLCNIC_MAC_OVERRIDE_DISABLED; | |
753 | ||
ee07c1a7 RB |
754 | if (!esw_cfg->promisc_mode) |
755 | adapter->flags |= QLCNIC_PROMISC_DISABLED; | |
756 | ||
0325d69b RB |
757 | qlcnic_set_netdev_features(adapter, esw_cfg); |
758 | } | |
759 | ||
760 | static int | |
761 | qlcnic_set_eswitch_port_config(struct qlcnic_adapter *adapter) | |
762 | { | |
763 | struct qlcnic_esw_func_cfg esw_cfg; | |
764 | ||
765 | if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED)) | |
766 | return 0; | |
767 | ||
b1fc6d3c | 768 | esw_cfg.pci_func = adapter->ahw->pci_func; |
0325d69b RB |
769 | if (qlcnic_get_eswitch_port_config(adapter, &esw_cfg)) |
770 | return -EIO; | |
8cf61f89 | 771 | qlcnic_set_vlan_config(adapter, &esw_cfg); |
0325d69b RB |
772 | qlcnic_set_eswitch_port_features(adapter, &esw_cfg); |
773 | ||
774 | return 0; | |
775 | } | |
776 | ||
777 | static void | |
778 | qlcnic_set_netdev_features(struct qlcnic_adapter *adapter, | |
779 | struct qlcnic_esw_func_cfg *esw_cfg) | |
780 | { | |
781 | struct net_device *netdev = adapter->netdev; | |
782 | unsigned long features, vlan_features; | |
783 | ||
135d84a9 | 784 | features = (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_RXCSUM | |
0325d69b RB |
785 | NETIF_F_IPV6_CSUM | NETIF_F_GRO); |
786 | vlan_features = (NETIF_F_SG | NETIF_F_IP_CSUM | | |
b9796a14 | 787 | NETIF_F_IPV6_CSUM | NETIF_F_HW_VLAN_FILTER); |
0325d69b RB |
788 | |
789 | if (adapter->capabilities & QLCNIC_FW_CAPABILITY_TSO) { | |
790 | features |= (NETIF_F_TSO | NETIF_F_TSO6); | |
791 | vlan_features |= (NETIF_F_TSO | NETIF_F_TSO6); | |
792 | } | |
b56421d0 RB |
793 | |
794 | if (netdev->features & NETIF_F_LRO) | |
0325d69b RB |
795 | features |= NETIF_F_LRO; |
796 | ||
797 | if (esw_cfg->offload_flags & BIT_0) { | |
798 | netdev->features |= features; | |
0325d69b RB |
799 | if (!(esw_cfg->offload_flags & BIT_1)) |
800 | netdev->features &= ~NETIF_F_TSO; | |
801 | if (!(esw_cfg->offload_flags & BIT_2)) | |
802 | netdev->features &= ~NETIF_F_TSO6; | |
803 | } else { | |
804 | netdev->features &= ~features; | |
0325d69b RB |
805 | } |
806 | ||
807 | netdev->vlan_features = (features & vlan_features); | |
808 | } | |
809 | ||
0866d96d AC |
810 | static int |
811 | qlcnic_check_eswitch_mode(struct qlcnic_adapter *adapter) | |
812 | { | |
813 | void __iomem *priv_op; | |
814 | u32 op_mode, priv_level; | |
815 | int err = 0; | |
816 | ||
174240a8 RB |
817 | err = qlcnic_initialize_nic(adapter); |
818 | if (err) | |
819 | return err; | |
820 | ||
0866d96d AC |
821 | if (adapter->flags & QLCNIC_ADAPTER_INITIALIZED) |
822 | return 0; | |
823 | ||
b1fc6d3c | 824 | priv_op = adapter->ahw->pci_base0 + QLCNIC_DRV_OP_MODE; |
0866d96d | 825 | op_mode = readl(priv_op); |
b1fc6d3c | 826 | priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw->pci_func); |
0866d96d AC |
827 | |
828 | if (op_mode == QLC_DEV_DRV_DEFAULT) | |
829 | priv_level = QLCNIC_MGMT_FUNC; | |
830 | else | |
b1fc6d3c | 831 | priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw->pci_func); |
0866d96d | 832 | |
174240a8 | 833 | if (adapter->flags & QLCNIC_ESWITCH_ENABLED) { |
0866d96d AC |
834 | if (priv_level == QLCNIC_MGMT_FUNC) { |
835 | adapter->op_mode = QLCNIC_MGMT_FUNC; | |
836 | err = qlcnic_init_pci_info(adapter); | |
837 | if (err) | |
838 | return err; | |
839 | /* Set privilege level for other functions */ | |
840 | qlcnic_set_function_modes(adapter); | |
841 | dev_info(&adapter->pdev->dev, | |
842 | "HAL Version: %d, Management function\n", | |
843 | adapter->fw_hal_version); | |
844 | } else if (priv_level == QLCNIC_PRIV_FUNC) { | |
845 | adapter->op_mode = QLCNIC_PRIV_FUNC; | |
846 | dev_info(&adapter->pdev->dev, | |
847 | "HAL Version: %d, Privileged function\n", | |
848 | adapter->fw_hal_version); | |
849 | } | |
174240a8 | 850 | } |
0866d96d AC |
851 | |
852 | adapter->flags |= QLCNIC_ADAPTER_INITIALIZED; | |
853 | ||
854 | return err; | |
855 | } | |
856 | ||
0325d69b RB |
857 | static int |
858 | qlcnic_set_default_offload_settings(struct qlcnic_adapter *adapter) | |
859 | { | |
860 | struct qlcnic_esw_func_cfg esw_cfg; | |
861 | struct qlcnic_npar_info *npar; | |
862 | u8 i; | |
863 | ||
174240a8 | 864 | if (adapter->need_fw_reset) |
0325d69b RB |
865 | return 0; |
866 | ||
867 | for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) { | |
868 | if (adapter->npars[i].type != QLCNIC_TYPE_NIC) | |
869 | continue; | |
870 | memset(&esw_cfg, 0, sizeof(struct qlcnic_esw_func_cfg)); | |
871 | esw_cfg.pci_func = i; | |
872 | esw_cfg.offload_flags = BIT_0; | |
7373373d | 873 | esw_cfg.mac_override = BIT_0; |
ee07c1a7 | 874 | esw_cfg.promisc_mode = BIT_0; |
0325d69b RB |
875 | if (adapter->capabilities & QLCNIC_FW_CAPABILITY_TSO) |
876 | esw_cfg.offload_flags |= (BIT_1 | BIT_2); | |
877 | if (qlcnic_config_switch_port(adapter, &esw_cfg)) | |
878 | return -EIO; | |
879 | npar = &adapter->npars[i]; | |
880 | npar->pvid = esw_cfg.vlan_id; | |
7373373d | 881 | npar->mac_override = esw_cfg.mac_override; |
0325d69b RB |
882 | npar->mac_anti_spoof = esw_cfg.mac_anti_spoof; |
883 | npar->discard_tagged = esw_cfg.discard_tagged; | |
884 | npar->promisc_mode = esw_cfg.promisc_mode; | |
885 | npar->offload_flags = esw_cfg.offload_flags; | |
886 | } | |
887 | ||
888 | return 0; | |
889 | } | |
890 | ||
4e8acb01 RB |
891 | static int |
892 | qlcnic_reset_eswitch_config(struct qlcnic_adapter *adapter, | |
893 | struct qlcnic_npar_info *npar, int pci_func) | |
894 | { | |
895 | struct qlcnic_esw_func_cfg esw_cfg; | |
896 | esw_cfg.op_mode = QLCNIC_PORT_DEFAULTS; | |
897 | esw_cfg.pci_func = pci_func; | |
898 | esw_cfg.vlan_id = npar->pvid; | |
7373373d | 899 | esw_cfg.mac_override = npar->mac_override; |
4e8acb01 RB |
900 | esw_cfg.discard_tagged = npar->discard_tagged; |
901 | esw_cfg.mac_anti_spoof = npar->mac_anti_spoof; | |
902 | esw_cfg.offload_flags = npar->offload_flags; | |
903 | esw_cfg.promisc_mode = npar->promisc_mode; | |
904 | if (qlcnic_config_switch_port(adapter, &esw_cfg)) | |
905 | return -EIO; | |
906 | ||
907 | esw_cfg.op_mode = QLCNIC_ADD_VLAN; | |
908 | if (qlcnic_config_switch_port(adapter, &esw_cfg)) | |
909 | return -EIO; | |
910 | ||
911 | return 0; | |
912 | } | |
913 | ||
cea8975e AC |
914 | static int |
915 | qlcnic_reset_npar_config(struct qlcnic_adapter *adapter) | |
916 | { | |
4e8acb01 | 917 | int i, err; |
cea8975e AC |
918 | struct qlcnic_npar_info *npar; |
919 | struct qlcnic_info nic_info; | |
920 | ||
174240a8 | 921 | if (!adapter->need_fw_reset) |
cea8975e AC |
922 | return 0; |
923 | ||
4e8acb01 RB |
924 | /* Set the NPAR config data after FW reset */ |
925 | for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) { | |
926 | npar = &adapter->npars[i]; | |
927 | if (npar->type != QLCNIC_TYPE_NIC) | |
928 | continue; | |
929 | err = qlcnic_get_nic_info(adapter, &nic_info, i); | |
930 | if (err) | |
931 | return err; | |
932 | nic_info.min_tx_bw = npar->min_bw; | |
933 | nic_info.max_tx_bw = npar->max_bw; | |
934 | err = qlcnic_set_nic_info(adapter, &nic_info); | |
935 | if (err) | |
936 | return err; | |
cea8975e | 937 | |
4e8acb01 RB |
938 | if (npar->enable_pm) { |
939 | err = qlcnic_config_port_mirroring(adapter, | |
940 | npar->dest_npar, 1, i); | |
941 | if (err) | |
942 | return err; | |
cea8975e | 943 | } |
4e8acb01 RB |
944 | err = qlcnic_reset_eswitch_config(adapter, npar, i); |
945 | if (err) | |
946 | return err; | |
cea8975e | 947 | } |
4e8acb01 | 948 | return 0; |
cea8975e AC |
949 | } |
950 | ||
78f84e1a AKS |
951 | static int qlcnic_check_npar_opertional(struct qlcnic_adapter *adapter) |
952 | { | |
953 | u8 npar_opt_timeo = QLCNIC_DEV_NPAR_OPER_TIMEO; | |
954 | u32 npar_state; | |
955 | ||
956 | if (adapter->op_mode == QLCNIC_MGMT_FUNC) | |
957 | return 0; | |
958 | ||
959 | npar_state = QLCRD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE); | |
960 | while (npar_state != QLCNIC_DEV_NPAR_OPER && --npar_opt_timeo) { | |
961 | msleep(1000); | |
962 | npar_state = QLCRD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE); | |
963 | } | |
964 | if (!npar_opt_timeo) { | |
965 | dev_err(&adapter->pdev->dev, | |
966 | "Waiting for NPAR state to opertional timeout\n"); | |
967 | return -EIO; | |
968 | } | |
969 | return 0; | |
970 | } | |
971 | ||
174240a8 RB |
972 | static int |
973 | qlcnic_set_mgmt_operations(struct qlcnic_adapter *adapter) | |
974 | { | |
975 | int err; | |
976 | ||
977 | if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED) || | |
978 | adapter->op_mode != QLCNIC_MGMT_FUNC) | |
979 | return 0; | |
980 | ||
981 | err = qlcnic_set_default_offload_settings(adapter); | |
982 | if (err) | |
983 | return err; | |
984 | ||
985 | err = qlcnic_reset_npar_config(adapter); | |
986 | if (err) | |
987 | return err; | |
988 | ||
989 | qlcnic_dev_set_npar_ready(adapter); | |
990 | ||
991 | return err; | |
992 | } | |
993 | ||
af19b491 AKS |
994 | static int |
995 | qlcnic_start_firmware(struct qlcnic_adapter *adapter) | |
996 | { | |
d4066833 | 997 | int err; |
af19b491 | 998 | |
aa5e18c0 SC |
999 | err = qlcnic_can_start_firmware(adapter); |
1000 | if (err < 0) | |
1001 | return err; | |
1002 | else if (!err) | |
d4066833 | 1003 | goto check_fw_status; |
af19b491 | 1004 | |
4d5bdb38 AKS |
1005 | if (load_fw_file) |
1006 | qlcnic_request_firmware(adapter); | |
8f891387 | 1007 | else { |
8cfdce08 SC |
1008 | err = qlcnic_check_flash_fw_ver(adapter); |
1009 | if (err) | |
8f891387 | 1010 | goto err_out; |
1011 | ||
4d5bdb38 | 1012 | adapter->fw_type = QLCNIC_FLASH_ROMIMAGE; |
8f891387 | 1013 | } |
af19b491 AKS |
1014 | |
1015 | err = qlcnic_need_fw_reset(adapter); | |
af19b491 | 1016 | if (err == 0) |
4e70812b | 1017 | goto check_fw_status; |
af19b491 | 1018 | |
d4066833 SC |
1019 | err = qlcnic_pinit_from_rom(adapter); |
1020 | if (err) | |
1021 | goto err_out; | |
af19b491 AKS |
1022 | |
1023 | err = qlcnic_load_firmware(adapter); | |
1024 | if (err) | |
1025 | goto err_out; | |
1026 | ||
1027 | qlcnic_release_firmware(adapter); | |
d4066833 | 1028 | QLCWR32(adapter, CRB_DRIVER_VERSION, QLCNIC_DRIVER_VERSION); |
af19b491 | 1029 | |
d4066833 SC |
1030 | check_fw_status: |
1031 | err = qlcnic_check_fw_status(adapter); | |
af19b491 AKS |
1032 | if (err) |
1033 | goto err_out; | |
1034 | ||
1035 | QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_READY); | |
6df900e9 | 1036 | qlcnic_idc_debug_info(adapter, 1); |
b18971d1 | 1037 | |
0866d96d AC |
1038 | err = qlcnic_check_eswitch_mode(adapter); |
1039 | if (err) { | |
1040 | dev_err(&adapter->pdev->dev, | |
1041 | "Memory allocation failed for eswitch\n"); | |
1042 | goto err_out; | |
1043 | } | |
174240a8 RB |
1044 | err = qlcnic_set_mgmt_operations(adapter); |
1045 | if (err) | |
1046 | goto err_out; | |
1047 | ||
1048 | qlcnic_check_options(adapter); | |
af19b491 AKS |
1049 | adapter->need_fw_reset = 0; |
1050 | ||
a7fc948f AKS |
1051 | qlcnic_release_firmware(adapter); |
1052 | return 0; | |
af19b491 AKS |
1053 | |
1054 | err_out: | |
a7fc948f AKS |
1055 | QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_FAILED); |
1056 | dev_err(&adapter->pdev->dev, "Device state set to failed\n"); | |
0866d96d | 1057 | |
af19b491 AKS |
1058 | qlcnic_release_firmware(adapter); |
1059 | return err; | |
1060 | } | |
1061 | ||
1062 | static int | |
1063 | qlcnic_request_irq(struct qlcnic_adapter *adapter) | |
1064 | { | |
1065 | irq_handler_t handler; | |
1066 | struct qlcnic_host_sds_ring *sds_ring; | |
1067 | int err, ring; | |
1068 | ||
1069 | unsigned long flags = 0; | |
1070 | struct net_device *netdev = adapter->netdev; | |
b1fc6d3c | 1071 | struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx; |
af19b491 | 1072 | |
7eb9855d AKS |
1073 | if (adapter->diag_test == QLCNIC_INTERRUPT_TEST) { |
1074 | handler = qlcnic_tmp_intr; | |
1075 | if (!QLCNIC_IS_MSI_FAMILY(adapter)) | |
1076 | flags |= IRQF_SHARED; | |
1077 | ||
1078 | } else { | |
1079 | if (adapter->flags & QLCNIC_MSIX_ENABLED) | |
1080 | handler = qlcnic_msix_intr; | |
1081 | else if (adapter->flags & QLCNIC_MSI_ENABLED) | |
1082 | handler = qlcnic_msi_intr; | |
1083 | else { | |
1084 | flags |= IRQF_SHARED; | |
1085 | handler = qlcnic_intr; | |
1086 | } | |
af19b491 AKS |
1087 | } |
1088 | adapter->irq = netdev->irq; | |
1089 | ||
1090 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { | |
1091 | sds_ring = &recv_ctx->sds_rings[ring]; | |
1092 | sprintf(sds_ring->name, "%s[%d]", netdev->name, ring); | |
1093 | err = request_irq(sds_ring->irq, handler, | |
1094 | flags, sds_ring->name, sds_ring); | |
1095 | if (err) | |
1096 | return err; | |
1097 | } | |
1098 | ||
1099 | return 0; | |
1100 | } | |
1101 | ||
1102 | static void | |
1103 | qlcnic_free_irq(struct qlcnic_adapter *adapter) | |
1104 | { | |
1105 | int ring; | |
1106 | struct qlcnic_host_sds_ring *sds_ring; | |
1107 | ||
b1fc6d3c | 1108 | struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx; |
af19b491 AKS |
1109 | |
1110 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { | |
1111 | sds_ring = &recv_ctx->sds_rings[ring]; | |
1112 | free_irq(sds_ring->irq, sds_ring); | |
1113 | } | |
1114 | } | |
1115 | ||
af19b491 AKS |
1116 | static int |
1117 | __qlcnic_up(struct qlcnic_adapter *adapter, struct net_device *netdev) | |
1118 | { | |
8a15ad1f AKS |
1119 | int ring; |
1120 | struct qlcnic_host_rds_ring *rds_ring; | |
1121 | ||
af19b491 AKS |
1122 | if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC) |
1123 | return -EIO; | |
1124 | ||
8a15ad1f AKS |
1125 | if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) |
1126 | return 0; | |
0325d69b RB |
1127 | if (qlcnic_set_eswitch_port_config(adapter)) |
1128 | return -EIO; | |
8a15ad1f AKS |
1129 | |
1130 | if (qlcnic_fw_create_ctx(adapter)) | |
1131 | return -EIO; | |
1132 | ||
1133 | for (ring = 0; ring < adapter->max_rds_rings; ring++) { | |
b1fc6d3c AC |
1134 | rds_ring = &adapter->recv_ctx->rds_rings[ring]; |
1135 | qlcnic_post_rx_buffers(adapter, rds_ring); | |
8a15ad1f AKS |
1136 | } |
1137 | ||
af19b491 AKS |
1138 | qlcnic_set_multi(netdev); |
1139 | qlcnic_fw_cmd_set_mtu(adapter, netdev->mtu); | |
1140 | ||
b1fc6d3c | 1141 | adapter->ahw->linkup = 0; |
af19b491 AKS |
1142 | |
1143 | if (adapter->max_sds_rings > 1) | |
1144 | qlcnic_config_rss(adapter, 1); | |
1145 | ||
1146 | qlcnic_config_intr_coalesce(adapter); | |
1147 | ||
24763d80 | 1148 | if (netdev->features & NETIF_F_LRO) |
af19b491 AKS |
1149 | qlcnic_config_hw_lro(adapter, QLCNIC_LRO_ENABLED); |
1150 | ||
1151 | qlcnic_napi_enable(adapter); | |
1152 | ||
1153 | qlcnic_linkevent_request(adapter, 1); | |
1154 | ||
68bf1c68 | 1155 | adapter->reset_context = 0; |
af19b491 AKS |
1156 | set_bit(__QLCNIC_DEV_UP, &adapter->state); |
1157 | return 0; | |
1158 | } | |
1159 | ||
1160 | /* Usage: During resume and firmware recovery module.*/ | |
1161 | ||
1162 | static int | |
1163 | qlcnic_up(struct qlcnic_adapter *adapter, struct net_device *netdev) | |
1164 | { | |
1165 | int err = 0; | |
1166 | ||
1167 | rtnl_lock(); | |
1168 | if (netif_running(netdev)) | |
1169 | err = __qlcnic_up(adapter, netdev); | |
1170 | rtnl_unlock(); | |
1171 | ||
1172 | return err; | |
1173 | } | |
1174 | ||
1175 | static void | |
1176 | __qlcnic_down(struct qlcnic_adapter *adapter, struct net_device *netdev) | |
1177 | { | |
1178 | if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC) | |
1179 | return; | |
1180 | ||
1181 | if (!test_and_clear_bit(__QLCNIC_DEV_UP, &adapter->state)) | |
1182 | return; | |
1183 | ||
1184 | smp_mb(); | |
1185 | spin_lock(&adapter->tx_clean_lock); | |
1186 | netif_carrier_off(netdev); | |
1187 | netif_tx_disable(netdev); | |
1188 | ||
1189 | qlcnic_free_mac_list(adapter); | |
1190 | ||
b5e5492c AKS |
1191 | if (adapter->fhash.fnum) |
1192 | qlcnic_delete_lb_filters(adapter); | |
1193 | ||
af19b491 AKS |
1194 | qlcnic_nic_set_promisc(adapter, QLCNIC_NIU_NON_PROMISC_MODE); |
1195 | ||
1196 | qlcnic_napi_disable(adapter); | |
1197 | ||
8a15ad1f AKS |
1198 | qlcnic_fw_destroy_ctx(adapter); |
1199 | ||
1200 | qlcnic_reset_rx_buffers_list(adapter); | |
af19b491 AKS |
1201 | qlcnic_release_tx_buffers(adapter); |
1202 | spin_unlock(&adapter->tx_clean_lock); | |
1203 | } | |
1204 | ||
1205 | /* Usage: During suspend and firmware recovery module */ | |
1206 | ||
1207 | static void | |
1208 | qlcnic_down(struct qlcnic_adapter *adapter, struct net_device *netdev) | |
1209 | { | |
1210 | rtnl_lock(); | |
1211 | if (netif_running(netdev)) | |
1212 | __qlcnic_down(adapter, netdev); | |
1213 | rtnl_unlock(); | |
1214 | ||
1215 | } | |
1216 | ||
1217 | static int | |
1218 | qlcnic_attach(struct qlcnic_adapter *adapter) | |
1219 | { | |
1220 | struct net_device *netdev = adapter->netdev; | |
1221 | struct pci_dev *pdev = adapter->pdev; | |
8a15ad1f | 1222 | int err; |
af19b491 AKS |
1223 | |
1224 | if (adapter->is_up == QLCNIC_ADAPTER_UP_MAGIC) | |
1225 | return 0; | |
1226 | ||
af19b491 AKS |
1227 | err = qlcnic_napi_add(adapter, netdev); |
1228 | if (err) | |
1229 | return err; | |
1230 | ||
1231 | err = qlcnic_alloc_sw_resources(adapter); | |
1232 | if (err) { | |
1233 | dev_err(&pdev->dev, "Error in setting sw resources\n"); | |
8a15ad1f | 1234 | goto err_out_napi_del; |
af19b491 AKS |
1235 | } |
1236 | ||
1237 | err = qlcnic_alloc_hw_resources(adapter); | |
1238 | if (err) { | |
1239 | dev_err(&pdev->dev, "Error in setting hw resources\n"); | |
1240 | goto err_out_free_sw; | |
1241 | } | |
1242 | ||
af19b491 AKS |
1243 | err = qlcnic_request_irq(adapter); |
1244 | if (err) { | |
1245 | dev_err(&pdev->dev, "failed to setup interrupt\n"); | |
8a15ad1f | 1246 | goto err_out_free_hw; |
af19b491 AKS |
1247 | } |
1248 | ||
af19b491 AKS |
1249 | qlcnic_create_sysfs_entries(adapter); |
1250 | ||
1251 | adapter->is_up = QLCNIC_ADAPTER_UP_MAGIC; | |
1252 | return 0; | |
1253 | ||
8a15ad1f | 1254 | err_out_free_hw: |
af19b491 AKS |
1255 | qlcnic_free_hw_resources(adapter); |
1256 | err_out_free_sw: | |
1257 | qlcnic_free_sw_resources(adapter); | |
8a15ad1f AKS |
1258 | err_out_napi_del: |
1259 | qlcnic_napi_del(adapter); | |
af19b491 AKS |
1260 | return err; |
1261 | } | |
1262 | ||
1263 | static void | |
1264 | qlcnic_detach(struct qlcnic_adapter *adapter) | |
1265 | { | |
1266 | if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC) | |
1267 | return; | |
1268 | ||
1269 | qlcnic_remove_sysfs_entries(adapter); | |
1270 | ||
1271 | qlcnic_free_hw_resources(adapter); | |
1272 | qlcnic_release_rx_buffers(adapter); | |
1273 | qlcnic_free_irq(adapter); | |
1274 | qlcnic_napi_del(adapter); | |
1275 | qlcnic_free_sw_resources(adapter); | |
1276 | ||
1277 | adapter->is_up = 0; | |
1278 | } | |
1279 | ||
7eb9855d AKS |
1280 | void qlcnic_diag_free_res(struct net_device *netdev, int max_sds_rings) |
1281 | { | |
1282 | struct qlcnic_adapter *adapter = netdev_priv(netdev); | |
1283 | struct qlcnic_host_sds_ring *sds_ring; | |
1284 | int ring; | |
1285 | ||
78ad3892 | 1286 | clear_bit(__QLCNIC_DEV_UP, &adapter->state); |
cdaff185 AKS |
1287 | if (adapter->diag_test == QLCNIC_INTERRUPT_TEST) { |
1288 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { | |
b1fc6d3c | 1289 | sds_ring = &adapter->recv_ctx->sds_rings[ring]; |
cdaff185 AKS |
1290 | qlcnic_disable_int(sds_ring); |
1291 | } | |
7eb9855d AKS |
1292 | } |
1293 | ||
8a15ad1f AKS |
1294 | qlcnic_fw_destroy_ctx(adapter); |
1295 | ||
7eb9855d AKS |
1296 | qlcnic_detach(adapter); |
1297 | ||
1298 | adapter->diag_test = 0; | |
1299 | adapter->max_sds_rings = max_sds_rings; | |
1300 | ||
1301 | if (qlcnic_attach(adapter)) | |
34ce3626 | 1302 | goto out; |
7eb9855d AKS |
1303 | |
1304 | if (netif_running(netdev)) | |
1305 | __qlcnic_up(adapter, netdev); | |
34ce3626 | 1306 | out: |
7eb9855d AKS |
1307 | netif_device_attach(netdev); |
1308 | } | |
1309 | ||
b1fc6d3c AC |
1310 | static int qlcnic_alloc_adapter_resources(struct qlcnic_adapter *adapter) |
1311 | { | |
1312 | int err = 0; | |
1313 | adapter->ahw = kzalloc(sizeof(struct qlcnic_hardware_context), | |
1314 | GFP_KERNEL); | |
1315 | if (!adapter->ahw) { | |
1316 | dev_err(&adapter->pdev->dev, | |
1317 | "Failed to allocate recv ctx resources for adapter\n"); | |
1318 | err = -ENOMEM; | |
1319 | goto err_out; | |
1320 | } | |
1321 | adapter->recv_ctx = kzalloc(sizeof(struct qlcnic_recv_context), | |
1322 | GFP_KERNEL); | |
1323 | if (!adapter->recv_ctx) { | |
1324 | dev_err(&adapter->pdev->dev, | |
1325 | "Failed to allocate recv ctx resources for adapter\n"); | |
1326 | kfree(adapter->ahw); | |
1327 | adapter->ahw = NULL; | |
1328 | err = -ENOMEM; | |
8816d009 | 1329 | goto err_out; |
b1fc6d3c | 1330 | } |
8816d009 AC |
1331 | /* Initialize interrupt coalesce parameters */ |
1332 | adapter->ahw->coal.flag = QLCNIC_INTR_DEFAULT; | |
1333 | adapter->ahw->coal.rx_time_us = QLCNIC_DEFAULT_INTR_COALESCE_RX_TIME_US; | |
1334 | adapter->ahw->coal.rx_packets = QLCNIC_DEFAULT_INTR_COALESCE_RX_PACKETS; | |
b1fc6d3c AC |
1335 | err_out: |
1336 | return err; | |
1337 | } | |
1338 | ||
1339 | static void qlcnic_free_adapter_resources(struct qlcnic_adapter *adapter) | |
1340 | { | |
1341 | kfree(adapter->recv_ctx); | |
1342 | adapter->recv_ctx = NULL; | |
1343 | ||
18f2f616 AC |
1344 | if (adapter->ahw->fw_dump.tmpl_hdr) { |
1345 | vfree(adapter->ahw->fw_dump.tmpl_hdr); | |
1346 | adapter->ahw->fw_dump.tmpl_hdr = NULL; | |
1347 | } | |
b1fc6d3c AC |
1348 | kfree(adapter->ahw); |
1349 | adapter->ahw = NULL; | |
1350 | } | |
1351 | ||
7eb9855d AKS |
1352 | int qlcnic_diag_alloc_res(struct net_device *netdev, int test) |
1353 | { | |
1354 | struct qlcnic_adapter *adapter = netdev_priv(netdev); | |
1355 | struct qlcnic_host_sds_ring *sds_ring; | |
8a15ad1f | 1356 | struct qlcnic_host_rds_ring *rds_ring; |
7eb9855d AKS |
1357 | int ring; |
1358 | int ret; | |
1359 | ||
1360 | netif_device_detach(netdev); | |
1361 | ||
1362 | if (netif_running(netdev)) | |
1363 | __qlcnic_down(adapter, netdev); | |
1364 | ||
1365 | qlcnic_detach(adapter); | |
1366 | ||
1367 | adapter->max_sds_rings = 1; | |
1368 | adapter->diag_test = test; | |
1369 | ||
1370 | ret = qlcnic_attach(adapter); | |
34ce3626 AKS |
1371 | if (ret) { |
1372 | netif_device_attach(netdev); | |
7eb9855d | 1373 | return ret; |
34ce3626 | 1374 | } |
7eb9855d | 1375 | |
8a15ad1f AKS |
1376 | ret = qlcnic_fw_create_ctx(adapter); |
1377 | if (ret) { | |
1378 | qlcnic_detach(adapter); | |
57e46248 | 1379 | netif_device_attach(netdev); |
8a15ad1f AKS |
1380 | return ret; |
1381 | } | |
1382 | ||
1383 | for (ring = 0; ring < adapter->max_rds_rings; ring++) { | |
b1fc6d3c AC |
1384 | rds_ring = &adapter->recv_ctx->rds_rings[ring]; |
1385 | qlcnic_post_rx_buffers(adapter, rds_ring); | |
8a15ad1f AKS |
1386 | } |
1387 | ||
cdaff185 AKS |
1388 | if (adapter->diag_test == QLCNIC_INTERRUPT_TEST) { |
1389 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { | |
b1fc6d3c | 1390 | sds_ring = &adapter->recv_ctx->sds_rings[ring]; |
cdaff185 AKS |
1391 | qlcnic_enable_int(sds_ring); |
1392 | } | |
7eb9855d | 1393 | } |
78ad3892 | 1394 | set_bit(__QLCNIC_DEV_UP, &adapter->state); |
7eb9855d AKS |
1395 | |
1396 | return 0; | |
1397 | } | |
1398 | ||
68bf1c68 AKS |
1399 | /* Reset context in hardware only */ |
1400 | static int | |
1401 | qlcnic_reset_hw_context(struct qlcnic_adapter *adapter) | |
1402 | { | |
1403 | struct net_device *netdev = adapter->netdev; | |
1404 | ||
1405 | if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state)) | |
1406 | return -EBUSY; | |
1407 | ||
1408 | netif_device_detach(netdev); | |
1409 | ||
1410 | qlcnic_down(adapter, netdev); | |
1411 | ||
1412 | qlcnic_up(adapter, netdev); | |
1413 | ||
1414 | netif_device_attach(netdev); | |
1415 | ||
1416 | clear_bit(__QLCNIC_RESETTING, &adapter->state); | |
1417 | return 0; | |
1418 | } | |
1419 | ||
af19b491 AKS |
1420 | int |
1421 | qlcnic_reset_context(struct qlcnic_adapter *adapter) | |
1422 | { | |
1423 | int err = 0; | |
1424 | struct net_device *netdev = adapter->netdev; | |
1425 | ||
1426 | if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state)) | |
1427 | return -EBUSY; | |
1428 | ||
1429 | if (adapter->is_up == QLCNIC_ADAPTER_UP_MAGIC) { | |
1430 | ||
1431 | netif_device_detach(netdev); | |
1432 | ||
1433 | if (netif_running(netdev)) | |
1434 | __qlcnic_down(adapter, netdev); | |
1435 | ||
1436 | qlcnic_detach(adapter); | |
1437 | ||
1438 | if (netif_running(netdev)) { | |
1439 | err = qlcnic_attach(adapter); | |
1440 | if (!err) | |
34ce3626 | 1441 | __qlcnic_up(adapter, netdev); |
af19b491 AKS |
1442 | } |
1443 | ||
1444 | netif_device_attach(netdev); | |
1445 | } | |
1446 | ||
af19b491 AKS |
1447 | clear_bit(__QLCNIC_RESETTING, &adapter->state); |
1448 | return err; | |
1449 | } | |
1450 | ||
1451 | static int | |
1452 | qlcnic_setup_netdev(struct qlcnic_adapter *adapter, | |
1bb09fb9 | 1453 | struct net_device *netdev, u8 pci_using_dac) |
af19b491 AKS |
1454 | { |
1455 | int err; | |
1456 | struct pci_dev *pdev = adapter->pdev; | |
1457 | ||
af19b491 AKS |
1458 | adapter->mc_enabled = 0; |
1459 | adapter->max_mc_count = 38; | |
1460 | ||
1461 | netdev->netdev_ops = &qlcnic_netdev_ops; | |
ef71ff83 | 1462 | netdev->watchdog_timeo = 5*HZ; |
af19b491 AKS |
1463 | |
1464 | qlcnic_change_mtu(netdev, netdev->mtu); | |
1465 | ||
1466 | SET_ETHTOOL_OPS(netdev, &qlcnic_ethtool_ops); | |
1467 | ||
135d84a9 MM |
1468 | netdev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | |
1469 | NETIF_F_IPV6_CSUM | NETIF_F_RXCSUM; | |
ac8d0c4f | 1470 | |
135d84a9 MM |
1471 | if (adapter->capabilities & QLCNIC_FW_CAPABILITY_TSO) |
1472 | netdev->hw_features |= NETIF_F_TSO | NETIF_F_TSO6; | |
1473 | if (pci_using_dac) | |
1474 | netdev->hw_features |= NETIF_F_HIGHDMA; | |
af19b491 | 1475 | |
135d84a9 | 1476 | netdev->vlan_features = netdev->hw_features; |
af19b491 AKS |
1477 | |
1478 | if (adapter->capabilities & QLCNIC_FW_CAPABILITY_FVLANTX) | |
135d84a9 | 1479 | netdev->hw_features |= NETIF_F_HW_VLAN_TX; |
af19b491 | 1480 | if (adapter->capabilities & QLCNIC_FW_CAPABILITY_HW_LRO) |
135d84a9 MM |
1481 | netdev->hw_features |= NETIF_F_LRO; |
1482 | ||
1483 | netdev->features |= netdev->hw_features | | |
1484 | NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER; | |
1485 | ||
af19b491 AKS |
1486 | netdev->irq = adapter->msix_entries[0].vector; |
1487 | ||
af19b491 AKS |
1488 | err = register_netdev(netdev); |
1489 | if (err) { | |
1490 | dev_err(&pdev->dev, "failed to register net device\n"); | |
1491 | return err; | |
1492 | } | |
1493 | ||
1494 | return 0; | |
1495 | } | |
1496 | ||
1bb09fb9 AKS |
1497 | static int qlcnic_set_dma_mask(struct pci_dev *pdev, u8 *pci_using_dac) |
1498 | { | |
1499 | if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) && | |
1500 | !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64))) | |
1501 | *pci_using_dac = 1; | |
1502 | else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) && | |
1503 | !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32))) | |
1504 | *pci_using_dac = 0; | |
1505 | else { | |
1506 | dev_err(&pdev->dev, "Unable to set DMA mask, aborting\n"); | |
1507 | return -EIO; | |
1508 | } | |
1509 | ||
1510 | return 0; | |
1511 | } | |
1512 | ||
f94bc1e7 SC |
1513 | static int |
1514 | qlcnic_alloc_msix_entries(struct qlcnic_adapter *adapter, u16 count) | |
1515 | { | |
1516 | adapter->msix_entries = kcalloc(count, sizeof(struct msix_entry), | |
1517 | GFP_KERNEL); | |
1518 | ||
1519 | if (adapter->msix_entries) | |
1520 | return 0; | |
1521 | ||
1522 | dev_err(&adapter->pdev->dev, "failed allocating msix_entries\n"); | |
1523 | return -ENOMEM; | |
1524 | } | |
1525 | ||
af19b491 AKS |
1526 | static int __devinit |
1527 | qlcnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) | |
1528 | { | |
1529 | struct net_device *netdev = NULL; | |
1530 | struct qlcnic_adapter *adapter = NULL; | |
1531 | int err; | |
af19b491 | 1532 | uint8_t revision_id; |
1bb09fb9 | 1533 | uint8_t pci_using_dac; |
da48e6c3 | 1534 | char brd_name[QLCNIC_MAX_BOARD_NAME_LEN]; |
af19b491 AKS |
1535 | |
1536 | err = pci_enable_device(pdev); | |
1537 | if (err) | |
1538 | return err; | |
1539 | ||
1540 | if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) { | |
1541 | err = -ENODEV; | |
1542 | goto err_out_disable_pdev; | |
1543 | } | |
1544 | ||
1bb09fb9 AKS |
1545 | err = qlcnic_set_dma_mask(pdev, &pci_using_dac); |
1546 | if (err) | |
1547 | goto err_out_disable_pdev; | |
1548 | ||
af19b491 AKS |
1549 | err = pci_request_regions(pdev, qlcnic_driver_name); |
1550 | if (err) | |
1551 | goto err_out_disable_pdev; | |
1552 | ||
1553 | pci_set_master(pdev); | |
451724c8 | 1554 | pci_enable_pcie_error_reporting(pdev); |
af19b491 AKS |
1555 | |
1556 | netdev = alloc_etherdev(sizeof(struct qlcnic_adapter)); | |
1557 | if (!netdev) { | |
1558 | dev_err(&pdev->dev, "failed to allocate net_device\n"); | |
1559 | err = -ENOMEM; | |
1560 | goto err_out_free_res; | |
1561 | } | |
1562 | ||
1563 | SET_NETDEV_DEV(netdev, &pdev->dev); | |
1564 | ||
1565 | adapter = netdev_priv(netdev); | |
1566 | adapter->netdev = netdev; | |
1567 | adapter->pdev = pdev; | |
af19b491 | 1568 | |
b1fc6d3c AC |
1569 | if (qlcnic_alloc_adapter_resources(adapter)) |
1570 | goto err_out_free_netdev; | |
1571 | ||
1572 | adapter->dev_rst_time = jiffies; | |
af19b491 | 1573 | revision_id = pdev->revision; |
b1fc6d3c | 1574 | adapter->ahw->revision_id = revision_id; |
af19b491 | 1575 | |
b1fc6d3c AC |
1576 | rwlock_init(&adapter->ahw->crb_lock); |
1577 | mutex_init(&adapter->ahw->mem_lock); | |
af19b491 AKS |
1578 | |
1579 | spin_lock_init(&adapter->tx_clean_lock); | |
1580 | INIT_LIST_HEAD(&adapter->mac_list); | |
1581 | ||
1582 | err = qlcnic_setup_pci_map(adapter); | |
1583 | if (err) | |
b1fc6d3c | 1584 | goto err_out_free_hw; |
af19b491 AKS |
1585 | |
1586 | /* This will be reset for mezz cards */ | |
b1fc6d3c | 1587 | adapter->portnum = adapter->ahw->pci_func; |
af19b491 AKS |
1588 | |
1589 | err = qlcnic_get_board_info(adapter); | |
1590 | if (err) { | |
1591 | dev_err(&pdev->dev, "Error getting board config info.\n"); | |
1592 | goto err_out_iounmap; | |
1593 | } | |
1594 | ||
8cfdce08 SC |
1595 | err = qlcnic_setup_idc_param(adapter); |
1596 | if (err) | |
b3a24649 | 1597 | goto err_out_iounmap; |
af19b491 | 1598 | |
1dc0f3c5 | 1599 | adapter->flags |= QLCNIC_NEED_FLR; |
b0044bcf | 1600 | |
9f26f547 | 1601 | err = adapter->nic_ops->start_firmware(adapter); |
a7fc948f AKS |
1602 | if (err) { |
1603 | dev_err(&pdev->dev, "Loading fw failed.Please Reboot\n"); | |
af19b491 | 1604 | goto err_out_decr_ref; |
a7fc948f | 1605 | } |
af19b491 | 1606 | |
602ca6f0 SV |
1607 | /* Get FW dump template and store it */ |
1608 | if (adapter->op_mode != QLCNIC_NON_PRIV_FUNC) | |
1609 | if (!qlcnic_fw_cmd_get_minidump_temp(adapter)) | |
1610 | dev_info(&pdev->dev, | |
1611 | "Supports FW dump capability\n"); | |
1612 | ||
da48e6c3 RB |
1613 | if (qlcnic_read_mac_addr(adapter)) |
1614 | dev_warn(&pdev->dev, "failed to read mac addr\n"); | |
1615 | ||
1616 | if (adapter->portnum == 0) { | |
1617 | get_brd_name(adapter, brd_name); | |
1618 | ||
1619 | pr_info("%s: %s Board Chip rev 0x%x\n", | |
1620 | module_name(THIS_MODULE), | |
b1fc6d3c | 1621 | brd_name, adapter->ahw->revision_id); |
da48e6c3 RB |
1622 | } |
1623 | ||
af19b491 AKS |
1624 | qlcnic_clear_stats(adapter); |
1625 | ||
f94bc1e7 SC |
1626 | err = qlcnic_alloc_msix_entries(adapter, adapter->max_rx_ques); |
1627 | if (err) | |
1628 | goto err_out_decr_ref; | |
1629 | ||
af19b491 AKS |
1630 | qlcnic_setup_intr(adapter); |
1631 | ||
1bb09fb9 | 1632 | err = qlcnic_setup_netdev(adapter, netdev, pci_using_dac); |
af19b491 AKS |
1633 | if (err) |
1634 | goto err_out_disable_msi; | |
1635 | ||
1636 | pci_set_drvdata(pdev, adapter); | |
1637 | ||
1638 | qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY); | |
1639 | ||
b1fc6d3c | 1640 | switch (adapter->ahw->port_type) { |
af19b491 AKS |
1641 | case QLCNIC_GBE: |
1642 | dev_info(&adapter->pdev->dev, "%s: GbE port initialized\n", | |
1643 | adapter->netdev->name); | |
1644 | break; | |
1645 | case QLCNIC_XGBE: | |
1646 | dev_info(&adapter->pdev->dev, "%s: XGbE port initialized\n", | |
1647 | adapter->netdev->name); | |
1648 | break; | |
1649 | } | |
1650 | ||
b5e5492c | 1651 | qlcnic_alloc_lb_filters_mem(adapter); |
af19b491 AKS |
1652 | qlcnic_create_diag_entries(adapter); |
1653 | ||
1654 | return 0; | |
1655 | ||
1656 | err_out_disable_msi: | |
1657 | qlcnic_teardown_intr(adapter); | |
f94bc1e7 | 1658 | kfree(adapter->msix_entries); |
af19b491 AKS |
1659 | |
1660 | err_out_decr_ref: | |
21854f02 | 1661 | qlcnic_clr_all_drv_state(adapter, 0); |
af19b491 AKS |
1662 | |
1663 | err_out_iounmap: | |
1664 | qlcnic_cleanup_pci_map(adapter); | |
1665 | ||
b1fc6d3c AC |
1666 | err_out_free_hw: |
1667 | qlcnic_free_adapter_resources(adapter); | |
1668 | ||
af19b491 AKS |
1669 | err_out_free_netdev: |
1670 | free_netdev(netdev); | |
1671 | ||
1672 | err_out_free_res: | |
1673 | pci_release_regions(pdev); | |
1674 | ||
1675 | err_out_disable_pdev: | |
1676 | pci_set_drvdata(pdev, NULL); | |
1677 | pci_disable_device(pdev); | |
1678 | return err; | |
1679 | } | |
1680 | ||
1681 | static void __devexit qlcnic_remove(struct pci_dev *pdev) | |
1682 | { | |
1683 | struct qlcnic_adapter *adapter; | |
1684 | struct net_device *netdev; | |
1685 | ||
1686 | adapter = pci_get_drvdata(pdev); | |
1687 | if (adapter == NULL) | |
1688 | return; | |
1689 | ||
1690 | netdev = adapter->netdev; | |
1691 | ||
1692 | qlcnic_cancel_fw_work(adapter); | |
1693 | ||
1694 | unregister_netdev(netdev); | |
1695 | ||
af19b491 AKS |
1696 | qlcnic_detach(adapter); |
1697 | ||
2e9d722d AC |
1698 | if (adapter->npars != NULL) |
1699 | kfree(adapter->npars); | |
1700 | if (adapter->eswitch != NULL) | |
1701 | kfree(adapter->eswitch); | |
1702 | ||
21854f02 | 1703 | qlcnic_clr_all_drv_state(adapter, 0); |
af19b491 AKS |
1704 | |
1705 | clear_bit(__QLCNIC_RESETTING, &adapter->state); | |
1706 | ||
b5e5492c AKS |
1707 | qlcnic_free_lb_filters_mem(adapter); |
1708 | ||
af19b491 | 1709 | qlcnic_teardown_intr(adapter); |
f94bc1e7 | 1710 | kfree(adapter->msix_entries); |
af19b491 AKS |
1711 | |
1712 | qlcnic_remove_diag_entries(adapter); | |
1713 | ||
1714 | qlcnic_cleanup_pci_map(adapter); | |
1715 | ||
1716 | qlcnic_release_firmware(adapter); | |
1717 | ||
451724c8 | 1718 | pci_disable_pcie_error_reporting(pdev); |
af19b491 AKS |
1719 | pci_release_regions(pdev); |
1720 | pci_disable_device(pdev); | |
1721 | pci_set_drvdata(pdev, NULL); | |
1722 | ||
b1fc6d3c | 1723 | qlcnic_free_adapter_resources(adapter); |
af19b491 AKS |
1724 | free_netdev(netdev); |
1725 | } | |
1726 | static int __qlcnic_shutdown(struct pci_dev *pdev) | |
1727 | { | |
1728 | struct qlcnic_adapter *adapter = pci_get_drvdata(pdev); | |
1729 | struct net_device *netdev = adapter->netdev; | |
1730 | int retval; | |
1731 | ||
1732 | netif_device_detach(netdev); | |
1733 | ||
1734 | qlcnic_cancel_fw_work(adapter); | |
1735 | ||
1736 | if (netif_running(netdev)) | |
1737 | qlcnic_down(adapter, netdev); | |
1738 | ||
21854f02 | 1739 | qlcnic_clr_all_drv_state(adapter, 0); |
af19b491 AKS |
1740 | |
1741 | clear_bit(__QLCNIC_RESETTING, &adapter->state); | |
1742 | ||
1743 | retval = pci_save_state(pdev); | |
1744 | if (retval) | |
1745 | return retval; | |
1746 | ||
1747 | if (qlcnic_wol_supported(adapter)) { | |
1748 | pci_enable_wake(pdev, PCI_D3cold, 1); | |
1749 | pci_enable_wake(pdev, PCI_D3hot, 1); | |
1750 | } | |
1751 | ||
1752 | return 0; | |
1753 | } | |
1754 | ||
1755 | static void qlcnic_shutdown(struct pci_dev *pdev) | |
1756 | { | |
1757 | if (__qlcnic_shutdown(pdev)) | |
1758 | return; | |
1759 | ||
1760 | pci_disable_device(pdev); | |
1761 | } | |
1762 | ||
1763 | #ifdef CONFIG_PM | |
1764 | static int | |
1765 | qlcnic_suspend(struct pci_dev *pdev, pm_message_t state) | |
1766 | { | |
1767 | int retval; | |
1768 | ||
1769 | retval = __qlcnic_shutdown(pdev); | |
1770 | if (retval) | |
1771 | return retval; | |
1772 | ||
1773 | pci_set_power_state(pdev, pci_choose_state(pdev, state)); | |
1774 | return 0; | |
1775 | } | |
1776 | ||
1777 | static int | |
1778 | qlcnic_resume(struct pci_dev *pdev) | |
1779 | { | |
1780 | struct qlcnic_adapter *adapter = pci_get_drvdata(pdev); | |
1781 | struct net_device *netdev = adapter->netdev; | |
1782 | int err; | |
1783 | ||
1784 | err = pci_enable_device(pdev); | |
1785 | if (err) | |
1786 | return err; | |
1787 | ||
1788 | pci_set_power_state(pdev, PCI_D0); | |
1789 | pci_set_master(pdev); | |
1790 | pci_restore_state(pdev); | |
1791 | ||
9f26f547 | 1792 | err = adapter->nic_ops->start_firmware(adapter); |
af19b491 AKS |
1793 | if (err) { |
1794 | dev_err(&pdev->dev, "failed to start firmware\n"); | |
1795 | return err; | |
1796 | } | |
1797 | ||
1798 | if (netif_running(netdev)) { | |
af19b491 AKS |
1799 | err = qlcnic_up(adapter, netdev); |
1800 | if (err) | |
52486a3a | 1801 | goto done; |
af19b491 | 1802 | |
aec1e845 | 1803 | qlcnic_restore_indev_addr(netdev, NETDEV_UP); |
af19b491 | 1804 | } |
52486a3a | 1805 | done: |
af19b491 AKS |
1806 | netif_device_attach(netdev); |
1807 | qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY); | |
1808 | return 0; | |
af19b491 AKS |
1809 | } |
1810 | #endif | |
1811 | ||
1812 | static int qlcnic_open(struct net_device *netdev) | |
1813 | { | |
1814 | struct qlcnic_adapter *adapter = netdev_priv(netdev); | |
1815 | int err; | |
1816 | ||
c55ad8e5 AKS |
1817 | netif_carrier_off(netdev); |
1818 | ||
af19b491 AKS |
1819 | err = qlcnic_attach(adapter); |
1820 | if (err) | |
1821 | return err; | |
1822 | ||
1823 | err = __qlcnic_up(adapter, netdev); | |
1824 | if (err) | |
1825 | goto err_out; | |
1826 | ||
1827 | netif_start_queue(netdev); | |
1828 | ||
1829 | return 0; | |
1830 | ||
1831 | err_out: | |
1832 | qlcnic_detach(adapter); | |
1833 | return err; | |
1834 | } | |
1835 | ||
1836 | /* | |
1837 | * qlcnic_close - Disables a network interface entry point | |
1838 | */ | |
1839 | static int qlcnic_close(struct net_device *netdev) | |
1840 | { | |
1841 | struct qlcnic_adapter *adapter = netdev_priv(netdev); | |
1842 | ||
1843 | __qlcnic_down(adapter, netdev); | |
1844 | return 0; | |
1845 | } | |
1846 | ||
b5e5492c AKS |
1847 | static void |
1848 | qlcnic_alloc_lb_filters_mem(struct qlcnic_adapter *adapter) | |
1849 | { | |
1850 | void *head; | |
1851 | int i; | |
1852 | ||
1853 | if (!qlcnic_mac_learn) | |
1854 | return; | |
1855 | ||
1856 | spin_lock_init(&adapter->mac_learn_lock); | |
1857 | ||
1858 | head = kcalloc(QLCNIC_LB_MAX_FILTERS, sizeof(struct hlist_head), | |
1859 | GFP_KERNEL); | |
1860 | if (!head) | |
1861 | return; | |
1862 | ||
1863 | adapter->fhash.fmax = QLCNIC_LB_MAX_FILTERS; | |
43d620c8 | 1864 | adapter->fhash.fhead = head; |
b5e5492c AKS |
1865 | |
1866 | for (i = 0; i < adapter->fhash.fmax; i++) | |
1867 | INIT_HLIST_HEAD(&adapter->fhash.fhead[i]); | |
1868 | } | |
1869 | ||
1870 | static void qlcnic_free_lb_filters_mem(struct qlcnic_adapter *adapter) | |
1871 | { | |
1872 | if (adapter->fhash.fmax && adapter->fhash.fhead) | |
1873 | kfree(adapter->fhash.fhead); | |
1874 | ||
1875 | adapter->fhash.fhead = NULL; | |
1876 | adapter->fhash.fmax = 0; | |
1877 | } | |
1878 | ||
1879 | static void qlcnic_change_filter(struct qlcnic_adapter *adapter, | |
7e56cac4 | 1880 | u64 uaddr, __le16 vlan_id, struct qlcnic_host_tx_ring *tx_ring) |
b5e5492c AKS |
1881 | { |
1882 | struct cmd_desc_type0 *hwdesc; | |
1883 | struct qlcnic_nic_req *req; | |
1884 | struct qlcnic_mac_req *mac_req; | |
7e56cac4 | 1885 | struct qlcnic_vlan_req *vlan_req; |
b5e5492c AKS |
1886 | u32 producer; |
1887 | u64 word; | |
1888 | ||
1889 | producer = tx_ring->producer; | |
1890 | hwdesc = &tx_ring->desc_head[tx_ring->producer]; | |
1891 | ||
1892 | req = (struct qlcnic_nic_req *)hwdesc; | |
1893 | memset(req, 0, sizeof(struct qlcnic_nic_req)); | |
1894 | req->qhdr = cpu_to_le64(QLCNIC_REQUEST << 23); | |
1895 | ||
1896 | word = QLCNIC_MAC_EVENT | ((u64)(adapter->portnum) << 16); | |
1897 | req->req_hdr = cpu_to_le64(word); | |
1898 | ||
1899 | mac_req = (struct qlcnic_mac_req *)&(req->words[0]); | |
03c5d770 | 1900 | mac_req->op = vlan_id ? QLCNIC_MAC_VLAN_ADD : QLCNIC_MAC_ADD; |
b5e5492c AKS |
1901 | memcpy(mac_req->mac_addr, &uaddr, ETH_ALEN); |
1902 | ||
7e56cac4 SC |
1903 | vlan_req = (struct qlcnic_vlan_req *)&req->words[1]; |
1904 | vlan_req->vlan_id = vlan_id; | |
03c5d770 | 1905 | |
b5e5492c | 1906 | tx_ring->producer = get_next_index(producer, tx_ring->num_desc); |
036d61f0 | 1907 | smp_mb(); |
b5e5492c AKS |
1908 | } |
1909 | ||
1910 | #define QLCNIC_MAC_HASH(MAC)\ | |
1911 | ((((MAC) & 0x70000) >> 0x10) | (((MAC) & 0x70000000000ULL) >> 0x25)) | |
1912 | ||
1913 | static void | |
1914 | qlcnic_send_filter(struct qlcnic_adapter *adapter, | |
1915 | struct qlcnic_host_tx_ring *tx_ring, | |
1916 | struct cmd_desc_type0 *first_desc, | |
1917 | struct sk_buff *skb) | |
1918 | { | |
1919 | struct ethhdr *phdr = (struct ethhdr *)(skb->data); | |
1920 | struct qlcnic_filter *fil, *tmp_fil; | |
1921 | struct hlist_node *tmp_hnode, *n; | |
1922 | struct hlist_head *head; | |
1923 | u64 src_addr = 0; | |
7e56cac4 | 1924 | __le16 vlan_id = 0; |
b5e5492c AKS |
1925 | u8 hindex; |
1926 | ||
1927 | if (!compare_ether_addr(phdr->h_source, adapter->mac_addr)) | |
1928 | return; | |
1929 | ||
1930 | if (adapter->fhash.fnum >= adapter->fhash.fmax) | |
1931 | return; | |
1932 | ||
03c5d770 AKS |
1933 | /* Only NPAR capable devices support vlan based learning*/ |
1934 | if (adapter->flags & QLCNIC_ESWITCH_ENABLED) | |
1935 | vlan_id = first_desc->vlan_TCI; | |
b5e5492c AKS |
1936 | memcpy(&src_addr, phdr->h_source, ETH_ALEN); |
1937 | hindex = QLCNIC_MAC_HASH(src_addr) & (QLCNIC_LB_MAX_FILTERS - 1); | |
1938 | head = &(adapter->fhash.fhead[hindex]); | |
1939 | ||
1940 | hlist_for_each_entry_safe(tmp_fil, tmp_hnode, n, head, fnode) { | |
03c5d770 AKS |
1941 | if (!memcmp(tmp_fil->faddr, &src_addr, ETH_ALEN) && |
1942 | tmp_fil->vlan_id == vlan_id) { | |
e5edb7b1 | 1943 | |
1944 | if (jiffies > | |
1945 | (QLCNIC_READD_AGE * HZ + tmp_fil->ftime)) | |
1946 | qlcnic_change_filter(adapter, src_addr, vlan_id, | |
1947 | tx_ring); | |
b5e5492c AKS |
1948 | tmp_fil->ftime = jiffies; |
1949 | return; | |
1950 | } | |
1951 | } | |
1952 | ||
1953 | fil = kzalloc(sizeof(struct qlcnic_filter), GFP_ATOMIC); | |
1954 | if (!fil) | |
1955 | return; | |
1956 | ||
03c5d770 | 1957 | qlcnic_change_filter(adapter, src_addr, vlan_id, tx_ring); |
b5e5492c AKS |
1958 | |
1959 | fil->ftime = jiffies; | |
03c5d770 | 1960 | fil->vlan_id = vlan_id; |
b5e5492c AKS |
1961 | memcpy(fil->faddr, &src_addr, ETH_ALEN); |
1962 | spin_lock(&adapter->mac_learn_lock); | |
1963 | hlist_add_head(&(fil->fnode), head); | |
1964 | adapter->fhash.fnum++; | |
1965 | spin_unlock(&adapter->mac_learn_lock); | |
1966 | } | |
1967 | ||
036d61f0 AC |
1968 | static int |
1969 | qlcnic_tx_pkt(struct qlcnic_adapter *adapter, | |
af19b491 AKS |
1970 | struct cmd_desc_type0 *first_desc, |
1971 | struct sk_buff *skb) | |
1972 | { | |
036d61f0 AC |
1973 | u8 opcode = 0, hdr_len = 0; |
1974 | u16 flags = 0, vlan_tci = 0; | |
1975 | int copied, offset, copy_len; | |
af19b491 AKS |
1976 | struct cmd_desc_type0 *hwdesc; |
1977 | struct vlan_ethhdr *vh; | |
036d61f0 AC |
1978 | struct qlcnic_host_tx_ring *tx_ring = adapter->tx_ring; |
1979 | u16 protocol = ntohs(skb->protocol); | |
2e9d722d | 1980 | u32 producer = tx_ring->producer; |
036d61f0 AC |
1981 | |
1982 | if (protocol == ETH_P_8021Q) { | |
1983 | vh = (struct vlan_ethhdr *)skb->data; | |
1984 | flags = FLAGS_VLAN_TAGGED; | |
1985 | vlan_tci = vh->h_vlan_TCI; | |
1986 | } else if (vlan_tx_tag_present(skb)) { | |
1987 | flags = FLAGS_VLAN_OOB; | |
1988 | vlan_tci = vlan_tx_tag_get(skb); | |
1989 | } | |
1990 | if (unlikely(adapter->pvid)) { | |
1991 | if (vlan_tci && !(adapter->flags & QLCNIC_TAGGING_ENABLED)) | |
1992 | return -EIO; | |
1993 | if (vlan_tci && (adapter->flags & QLCNIC_TAGGING_ENABLED)) | |
1994 | goto set_flags; | |
1995 | ||
1996 | flags = FLAGS_VLAN_OOB; | |
1997 | vlan_tci = adapter->pvid; | |
1998 | } | |
1999 | set_flags: | |
2000 | qlcnic_set_tx_vlan_tci(first_desc, vlan_tci); | |
2001 | qlcnic_set_tx_flags_opcode(first_desc, flags, opcode); | |
af19b491 | 2002 | |
2e9d722d AC |
2003 | if (*(skb->data) & BIT_0) { |
2004 | flags |= BIT_0; | |
2005 | memcpy(&first_desc->eth_addr, skb->data, ETH_ALEN); | |
2006 | } | |
036d61f0 AC |
2007 | opcode = TX_ETHER_PKT; |
2008 | if ((adapter->netdev->features & (NETIF_F_TSO | NETIF_F_TSO6)) && | |
af19b491 AKS |
2009 | skb_shinfo(skb)->gso_size > 0) { |
2010 | ||
2011 | hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); | |
2012 | ||
2013 | first_desc->mss = cpu_to_le16(skb_shinfo(skb)->gso_size); | |
2014 | first_desc->total_hdr_length = hdr_len; | |
036d61f0 AC |
2015 | |
2016 | opcode = (protocol == ETH_P_IPV6) ? TX_TCP_LSO6 : TX_TCP_LSO; | |
2017 | ||
2018 | /* For LSO, we need to copy the MAC/IP/TCP headers into | |
2019 | * the descriptor ring */ | |
2020 | copied = 0; | |
2021 | offset = 2; | |
2022 | ||
2023 | if (flags & FLAGS_VLAN_OOB) { | |
af19b491 AKS |
2024 | first_desc->total_hdr_length += VLAN_HLEN; |
2025 | first_desc->tcp_hdr_offset = VLAN_HLEN; | |
2026 | first_desc->ip_hdr_offset = VLAN_HLEN; | |
2027 | /* Only in case of TSO on vlan device */ | |
2028 | flags |= FLAGS_VLAN_TAGGED; | |
036d61f0 AC |
2029 | |
2030 | /* Create a TSO vlan header template for firmware */ | |
2031 | ||
2032 | hwdesc = &tx_ring->desc_head[producer]; | |
2033 | tx_ring->cmd_buf_arr[producer].skb = NULL; | |
2034 | ||
2035 | copy_len = min((int)sizeof(struct cmd_desc_type0) - | |
2036 | offset, hdr_len + VLAN_HLEN); | |
2037 | ||
2038 | vh = (struct vlan_ethhdr *)((char *) hwdesc + 2); | |
2039 | skb_copy_from_linear_data(skb, vh, 12); | |
2040 | vh->h_vlan_proto = htons(ETH_P_8021Q); | |
2041 | vh->h_vlan_TCI = htons(vlan_tci); | |
2042 | ||
2043 | skb_copy_from_linear_data_offset(skb, 12, | |
2044 | (char *)vh + 16, copy_len - 16); | |
2045 | ||
2046 | copied = copy_len - VLAN_HLEN; | |
2047 | offset = 0; | |
2048 | ||
2049 | producer = get_next_index(producer, tx_ring->num_desc); | |
af19b491 AKS |
2050 | } |
2051 | ||
036d61f0 AC |
2052 | while (copied < hdr_len) { |
2053 | ||
2054 | copy_len = min((int)sizeof(struct cmd_desc_type0) - | |
2055 | offset, (hdr_len - copied)); | |
2056 | ||
2057 | hwdesc = &tx_ring->desc_head[producer]; | |
2058 | tx_ring->cmd_buf_arr[producer].skb = NULL; | |
2059 | ||
2060 | skb_copy_from_linear_data_offset(skb, copied, | |
2061 | (char *) hwdesc + offset, copy_len); | |
2062 | ||
2063 | copied += copy_len; | |
2064 | offset = 0; | |
2065 | ||
2066 | producer = get_next_index(producer, tx_ring->num_desc); | |
2067 | } | |
2068 | ||
2069 | tx_ring->producer = producer; | |
2070 | smp_mb(); | |
2071 | adapter->stats.lso_frames++; | |
af19b491 AKS |
2072 | |
2073 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { | |
2074 | u8 l4proto; | |
2075 | ||
036d61f0 | 2076 | if (protocol == ETH_P_IP) { |
af19b491 AKS |
2077 | l4proto = ip_hdr(skb)->protocol; |
2078 | ||
2079 | if (l4proto == IPPROTO_TCP) | |
2080 | opcode = TX_TCP_PKT; | |
2081 | else if (l4proto == IPPROTO_UDP) | |
2082 | opcode = TX_UDP_PKT; | |
036d61f0 | 2083 | } else if (protocol == ETH_P_IPV6) { |
af19b491 AKS |
2084 | l4proto = ipv6_hdr(skb)->nexthdr; |
2085 | ||
2086 | if (l4proto == IPPROTO_TCP) | |
2087 | opcode = TX_TCPV6_PKT; | |
2088 | else if (l4proto == IPPROTO_UDP) | |
2089 | opcode = TX_UDPV6_PKT; | |
2090 | } | |
2091 | } | |
af19b491 AKS |
2092 | first_desc->tcp_hdr_offset += skb_transport_offset(skb); |
2093 | first_desc->ip_hdr_offset += skb_network_offset(skb); | |
2094 | qlcnic_set_tx_flags_opcode(first_desc, flags, opcode); | |
2095 | ||
036d61f0 | 2096 | return 0; |
af19b491 AKS |
2097 | } |
2098 | ||
2099 | static int | |
2100 | qlcnic_map_tx_skb(struct pci_dev *pdev, | |
2101 | struct sk_buff *skb, struct qlcnic_cmd_buffer *pbuf) | |
2102 | { | |
2103 | struct qlcnic_skb_frag *nf; | |
2104 | struct skb_frag_struct *frag; | |
2105 | int i, nr_frags; | |
2106 | dma_addr_t map; | |
2107 | ||
2108 | nr_frags = skb_shinfo(skb)->nr_frags; | |
2109 | nf = &pbuf->frag_array[0]; | |
2110 | ||
2111 | map = pci_map_single(pdev, skb->data, | |
2112 | skb_headlen(skb), PCI_DMA_TODEVICE); | |
2113 | if (pci_dma_mapping_error(pdev, map)) | |
2114 | goto out_err; | |
2115 | ||
2116 | nf->dma = map; | |
2117 | nf->length = skb_headlen(skb); | |
2118 | ||
2119 | for (i = 0; i < nr_frags; i++) { | |
2120 | frag = &skb_shinfo(skb)->frags[i]; | |
2121 | nf = &pbuf->frag_array[i+1]; | |
2122 | ||
2123 | map = pci_map_page(pdev, frag->page, frag->page_offset, | |
2124 | frag->size, PCI_DMA_TODEVICE); | |
2125 | if (pci_dma_mapping_error(pdev, map)) | |
2126 | goto unwind; | |
2127 | ||
2128 | nf->dma = map; | |
2129 | nf->length = frag->size; | |
2130 | } | |
2131 | ||
2132 | return 0; | |
2133 | ||
2134 | unwind: | |
2135 | while (--i >= 0) { | |
2136 | nf = &pbuf->frag_array[i+1]; | |
2137 | pci_unmap_page(pdev, nf->dma, nf->length, PCI_DMA_TODEVICE); | |
2138 | } | |
2139 | ||
2140 | nf = &pbuf->frag_array[0]; | |
2141 | pci_unmap_single(pdev, nf->dma, skb_headlen(skb), PCI_DMA_TODEVICE); | |
2142 | ||
2143 | out_err: | |
2144 | return -ENOMEM; | |
2145 | } | |
2146 | ||
036d61f0 AC |
2147 | static void |
2148 | qlcnic_unmap_buffers(struct pci_dev *pdev, struct sk_buff *skb, | |
2149 | struct qlcnic_cmd_buffer *pbuf) | |
8cf61f89 | 2150 | { |
036d61f0 AC |
2151 | struct qlcnic_skb_frag *nf = &pbuf->frag_array[0]; |
2152 | int nr_frags = skb_shinfo(skb)->nr_frags; | |
2153 | int i; | |
8cf61f89 | 2154 | |
036d61f0 AC |
2155 | for (i = 0; i < nr_frags; i++) { |
2156 | nf = &pbuf->frag_array[i+1]; | |
2157 | pci_unmap_page(pdev, nf->dma, nf->length, PCI_DMA_TODEVICE); | |
8cf61f89 | 2158 | } |
8cf61f89 | 2159 | |
036d61f0 AC |
2160 | nf = &pbuf->frag_array[0]; |
2161 | pci_unmap_single(pdev, nf->dma, skb_headlen(skb), PCI_DMA_TODEVICE); | |
5b446c6a | 2162 | pbuf->skb = NULL; |
8cf61f89 AKS |
2163 | } |
2164 | ||
af19b491 AKS |
2165 | static inline void |
2166 | qlcnic_clear_cmddesc(u64 *desc) | |
2167 | { | |
2168 | desc[0] = 0ULL; | |
2169 | desc[2] = 0ULL; | |
8cf61f89 | 2170 | desc[7] = 0ULL; |
af19b491 AKS |
2171 | } |
2172 | ||
cdaff185 | 2173 | netdev_tx_t |
af19b491 AKS |
2174 | qlcnic_xmit_frame(struct sk_buff *skb, struct net_device *netdev) |
2175 | { | |
2176 | struct qlcnic_adapter *adapter = netdev_priv(netdev); | |
2177 | struct qlcnic_host_tx_ring *tx_ring = adapter->tx_ring; | |
2178 | struct qlcnic_cmd_buffer *pbuf; | |
2179 | struct qlcnic_skb_frag *buffrag; | |
2180 | struct cmd_desc_type0 *hwdesc, *first_desc; | |
2181 | struct pci_dev *pdev; | |
dcb50aff | 2182 | struct ethhdr *phdr; |
91a403ca | 2183 | int delta = 0; |
af19b491 AKS |
2184 | int i, k; |
2185 | ||
2186 | u32 producer; | |
036d61f0 | 2187 | int frag_count; |
af19b491 AKS |
2188 | u32 num_txd = tx_ring->num_desc; |
2189 | ||
780ab790 AKS |
2190 | if (!test_bit(__QLCNIC_DEV_UP, &adapter->state)) { |
2191 | netif_stop_queue(netdev); | |
2192 | return NETDEV_TX_BUSY; | |
2193 | } | |
2194 | ||
fe4d434d | 2195 | if (adapter->flags & QLCNIC_MACSPOOF) { |
dcb50aff RB |
2196 | phdr = (struct ethhdr *)skb->data; |
2197 | if (compare_ether_addr(phdr->h_source, | |
fe4d434d SC |
2198 | adapter->mac_addr)) |
2199 | goto drop_packet; | |
2200 | } | |
2201 | ||
af19b491 | 2202 | frag_count = skb_shinfo(skb)->nr_frags + 1; |
91a403ca AKS |
2203 | /* 14 frags supported for normal packet and |
2204 | * 32 frags supported for TSO packet | |
2205 | */ | |
2206 | if (!skb_is_gso(skb) && frag_count > QLCNIC_MAX_FRAGS_PER_TX) { | |
2207 | ||
2208 | for (i = 0; i < (frag_count - QLCNIC_MAX_FRAGS_PER_TX); i++) | |
2209 | delta += skb_shinfo(skb)->frags[i].size; | |
2210 | ||
2211 | if (!__pskb_pull_tail(skb, delta)) | |
2212 | goto drop_packet; | |
2213 | ||
2214 | frag_count = 1 + skb_shinfo(skb)->nr_frags; | |
2215 | } | |
af19b491 | 2216 | |
ef71ff83 | 2217 | if (unlikely(qlcnic_tx_avail(tx_ring) <= TX_STOP_THRESH)) { |
af19b491 | 2218 | netif_stop_queue(netdev); |
ef71ff83 RB |
2219 | if (qlcnic_tx_avail(tx_ring) > TX_STOP_THRESH) |
2220 | netif_start_queue(netdev); | |
2221 | else { | |
2222 | adapter->stats.xmit_off++; | |
2223 | return NETDEV_TX_BUSY; | |
2224 | } | |
af19b491 AKS |
2225 | } |
2226 | ||
2227 | producer = tx_ring->producer; | |
2228 | pbuf = &tx_ring->cmd_buf_arr[producer]; | |
2229 | ||
2230 | pdev = adapter->pdev; | |
2231 | ||
8cf61f89 AKS |
2232 | first_desc = hwdesc = &tx_ring->desc_head[producer]; |
2233 | qlcnic_clear_cmddesc((u64 *)hwdesc); | |
2234 | ||
8ae6df97 AKS |
2235 | if (qlcnic_map_tx_skb(pdev, skb, pbuf)) { |
2236 | adapter->stats.tx_dma_map_error++; | |
af19b491 | 2237 | goto drop_packet; |
8ae6df97 | 2238 | } |
af19b491 AKS |
2239 | |
2240 | pbuf->skb = skb; | |
2241 | pbuf->frag_count = frag_count; | |
2242 | ||
af19b491 AKS |
2243 | qlcnic_set_tx_frags_len(first_desc, frag_count, skb->len); |
2244 | qlcnic_set_tx_port(first_desc, adapter->portnum); | |
2245 | ||
2246 | for (i = 0; i < frag_count; i++) { | |
2247 | ||
2248 | k = i % 4; | |
2249 | ||
2250 | if ((k == 0) && (i > 0)) { | |
2251 | /* move to next desc.*/ | |
2252 | producer = get_next_index(producer, num_txd); | |
2253 | hwdesc = &tx_ring->desc_head[producer]; | |
2254 | qlcnic_clear_cmddesc((u64 *)hwdesc); | |
2255 | tx_ring->cmd_buf_arr[producer].skb = NULL; | |
2256 | } | |
2257 | ||
2258 | buffrag = &pbuf->frag_array[i]; | |
2259 | ||
2260 | hwdesc->buffer_length[k] = cpu_to_le16(buffrag->length); | |
2261 | switch (k) { | |
2262 | case 0: | |
2263 | hwdesc->addr_buffer1 = cpu_to_le64(buffrag->dma); | |
2264 | break; | |
2265 | case 1: | |
2266 | hwdesc->addr_buffer2 = cpu_to_le64(buffrag->dma); | |
2267 | break; | |
2268 | case 2: | |
2269 | hwdesc->addr_buffer3 = cpu_to_le64(buffrag->dma); | |
2270 | break; | |
2271 | case 3: | |
2272 | hwdesc->addr_buffer4 = cpu_to_le64(buffrag->dma); | |
2273 | break; | |
2274 | } | |
2275 | } | |
2276 | ||
2277 | tx_ring->producer = get_next_index(producer, num_txd); | |
036d61f0 | 2278 | smp_mb(); |
af19b491 | 2279 | |
036d61f0 AC |
2280 | if (unlikely(qlcnic_tx_pkt(adapter, first_desc, skb))) |
2281 | goto unwind_buff; | |
af19b491 | 2282 | |
b5e5492c AKS |
2283 | if (qlcnic_mac_learn) |
2284 | qlcnic_send_filter(adapter, tx_ring, first_desc, skb); | |
2285 | ||
af19b491 AKS |
2286 | qlcnic_update_cmd_producer(adapter, tx_ring); |
2287 | ||
2288 | adapter->stats.txbytes += skb->len; | |
2289 | adapter->stats.xmitcalled++; | |
2290 | ||
2291 | return NETDEV_TX_OK; | |
2292 | ||
036d61f0 AC |
2293 | unwind_buff: |
2294 | qlcnic_unmap_buffers(pdev, skb, pbuf); | |
af19b491 AKS |
2295 | drop_packet: |
2296 | adapter->stats.txdropped++; | |
2297 | dev_kfree_skb_any(skb); | |
2298 | return NETDEV_TX_OK; | |
2299 | } | |
2300 | ||
2301 | static int qlcnic_check_temp(struct qlcnic_adapter *adapter) | |
2302 | { | |
2303 | struct net_device *netdev = adapter->netdev; | |
2304 | u32 temp, temp_state, temp_val; | |
2305 | int rv = 0; | |
2306 | ||
2307 | temp = QLCRD32(adapter, CRB_TEMP_STATE); | |
2308 | ||
2309 | temp_state = qlcnic_get_temp_state(temp); | |
2310 | temp_val = qlcnic_get_temp_val(temp); | |
2311 | ||
2312 | if (temp_state == QLCNIC_TEMP_PANIC) { | |
2313 | dev_err(&netdev->dev, | |
2314 | "Device temperature %d degrees C exceeds" | |
2315 | " maximum allowed. Hardware has been shut down.\n", | |
2316 | temp_val); | |
2317 | rv = 1; | |
2318 | } else if (temp_state == QLCNIC_TEMP_WARN) { | |
2319 | if (adapter->temp == QLCNIC_TEMP_NORMAL) { | |
2320 | dev_err(&netdev->dev, | |
2321 | "Device temperature %d degrees C " | |
2322 | "exceeds operating range." | |
2323 | " Immediate action needed.\n", | |
2324 | temp_val); | |
2325 | } | |
2326 | } else { | |
2327 | if (adapter->temp == QLCNIC_TEMP_WARN) { | |
2328 | dev_info(&netdev->dev, | |
2329 | "Device temperature is now %d degrees C" | |
2330 | " in normal range.\n", temp_val); | |
2331 | } | |
2332 | } | |
2333 | adapter->temp = temp_state; | |
2334 | return rv; | |
2335 | } | |
2336 | ||
2337 | void qlcnic_advert_link_change(struct qlcnic_adapter *adapter, int linkup) | |
2338 | { | |
2339 | struct net_device *netdev = adapter->netdev; | |
2340 | ||
b1fc6d3c | 2341 | if (adapter->ahw->linkup && !linkup) { |
69324275 | 2342 | netdev_info(netdev, "NIC Link is down\n"); |
b1fc6d3c | 2343 | adapter->ahw->linkup = 0; |
af19b491 AKS |
2344 | if (netif_running(netdev)) { |
2345 | netif_carrier_off(netdev); | |
2346 | netif_stop_queue(netdev); | |
2347 | } | |
b1fc6d3c | 2348 | } else if (!adapter->ahw->linkup && linkup) { |
69324275 | 2349 | netdev_info(netdev, "NIC Link is up\n"); |
b1fc6d3c | 2350 | adapter->ahw->linkup = 1; |
af19b491 AKS |
2351 | if (netif_running(netdev)) { |
2352 | netif_carrier_on(netdev); | |
2353 | netif_wake_queue(netdev); | |
2354 | } | |
2355 | } | |
2356 | } | |
2357 | ||
2358 | static void qlcnic_tx_timeout(struct net_device *netdev) | |
2359 | { | |
2360 | struct qlcnic_adapter *adapter = netdev_priv(netdev); | |
2361 | ||
2362 | if (test_bit(__QLCNIC_RESETTING, &adapter->state)) | |
2363 | return; | |
2364 | ||
2365 | dev_err(&netdev->dev, "transmit timeout, resetting.\n"); | |
af19b491 AKS |
2366 | |
2367 | if (++adapter->tx_timeo_cnt >= QLCNIC_MAX_TX_TIMEOUTS) | |
68bf1c68 AKS |
2368 | adapter->need_fw_reset = 1; |
2369 | else | |
2370 | adapter->reset_context = 1; | |
af19b491 AKS |
2371 | } |
2372 | ||
2373 | static struct net_device_stats *qlcnic_get_stats(struct net_device *netdev) | |
2374 | { | |
2375 | struct qlcnic_adapter *adapter = netdev_priv(netdev); | |
2376 | struct net_device_stats *stats = &netdev->stats; | |
2377 | ||
af19b491 AKS |
2378 | stats->rx_packets = adapter->stats.rx_pkts + adapter->stats.lro_pkts; |
2379 | stats->tx_packets = adapter->stats.xmitfinished; | |
7e382594 | 2380 | stats->rx_bytes = adapter->stats.rxbytes + adapter->stats.lrobytes; |
af19b491 AKS |
2381 | stats->tx_bytes = adapter->stats.txbytes; |
2382 | stats->rx_dropped = adapter->stats.rxdropped; | |
2383 | stats->tx_dropped = adapter->stats.txdropped; | |
2384 | ||
2385 | return stats; | |
2386 | } | |
2387 | ||
7eb9855d | 2388 | static irqreturn_t qlcnic_clear_legacy_intr(struct qlcnic_adapter *adapter) |
af19b491 | 2389 | { |
af19b491 AKS |
2390 | u32 status; |
2391 | ||
2392 | status = readl(adapter->isr_int_vec); | |
2393 | ||
2394 | if (!(status & adapter->int_vec_bit)) | |
2395 | return IRQ_NONE; | |
2396 | ||
2397 | /* check interrupt state machine, to be sure */ | |
2398 | status = readl(adapter->crb_int_state_reg); | |
2399 | if (!ISR_LEGACY_INT_TRIGGERED(status)) | |
2400 | return IRQ_NONE; | |
2401 | ||
2402 | writel(0xffffffff, adapter->tgt_status_reg); | |
2403 | /* read twice to ensure write is flushed */ | |
2404 | readl(adapter->isr_int_vec); | |
2405 | readl(adapter->isr_int_vec); | |
2406 | ||
7eb9855d AKS |
2407 | return IRQ_HANDLED; |
2408 | } | |
2409 | ||
2410 | static irqreturn_t qlcnic_tmp_intr(int irq, void *data) | |
2411 | { | |
2412 | struct qlcnic_host_sds_ring *sds_ring = data; | |
2413 | struct qlcnic_adapter *adapter = sds_ring->adapter; | |
2414 | ||
2415 | if (adapter->flags & QLCNIC_MSIX_ENABLED) | |
2416 | goto done; | |
2417 | else if (adapter->flags & QLCNIC_MSI_ENABLED) { | |
2418 | writel(0xffffffff, adapter->tgt_status_reg); | |
2419 | goto done; | |
2420 | } | |
2421 | ||
2422 | if (qlcnic_clear_legacy_intr(adapter) == IRQ_NONE) | |
2423 | return IRQ_NONE; | |
2424 | ||
2425 | done: | |
2426 | adapter->diag_cnt++; | |
2427 | qlcnic_enable_int(sds_ring); | |
2428 | return IRQ_HANDLED; | |
2429 | } | |
2430 | ||
2431 | static irqreturn_t qlcnic_intr(int irq, void *data) | |
2432 | { | |
2433 | struct qlcnic_host_sds_ring *sds_ring = data; | |
2434 | struct qlcnic_adapter *adapter = sds_ring->adapter; | |
2435 | ||
2436 | if (qlcnic_clear_legacy_intr(adapter) == IRQ_NONE) | |
2437 | return IRQ_NONE; | |
2438 | ||
af19b491 AKS |
2439 | napi_schedule(&sds_ring->napi); |
2440 | ||
2441 | return IRQ_HANDLED; | |
2442 | } | |
2443 | ||
2444 | static irqreturn_t qlcnic_msi_intr(int irq, void *data) | |
2445 | { | |
2446 | struct qlcnic_host_sds_ring *sds_ring = data; | |
2447 | struct qlcnic_adapter *adapter = sds_ring->adapter; | |
2448 | ||
2449 | /* clear interrupt */ | |
2450 | writel(0xffffffff, adapter->tgt_status_reg); | |
2451 | ||
2452 | napi_schedule(&sds_ring->napi); | |
2453 | return IRQ_HANDLED; | |
2454 | } | |
2455 | ||
2456 | static irqreturn_t qlcnic_msix_intr(int irq, void *data) | |
2457 | { | |
2458 | struct qlcnic_host_sds_ring *sds_ring = data; | |
2459 | ||
2460 | napi_schedule(&sds_ring->napi); | |
2461 | return IRQ_HANDLED; | |
2462 | } | |
2463 | ||
2464 | static int qlcnic_process_cmd_ring(struct qlcnic_adapter *adapter) | |
2465 | { | |
2466 | u32 sw_consumer, hw_consumer; | |
2467 | int count = 0, i; | |
2468 | struct qlcnic_cmd_buffer *buffer; | |
2469 | struct pci_dev *pdev = adapter->pdev; | |
2470 | struct net_device *netdev = adapter->netdev; | |
2471 | struct qlcnic_skb_frag *frag; | |
2472 | int done; | |
2473 | struct qlcnic_host_tx_ring *tx_ring = adapter->tx_ring; | |
2474 | ||
2475 | if (!spin_trylock(&adapter->tx_clean_lock)) | |
2476 | return 1; | |
2477 | ||
2478 | sw_consumer = tx_ring->sw_consumer; | |
2479 | hw_consumer = le32_to_cpu(*(tx_ring->hw_consumer)); | |
2480 | ||
2481 | while (sw_consumer != hw_consumer) { | |
2482 | buffer = &tx_ring->cmd_buf_arr[sw_consumer]; | |
2483 | if (buffer->skb) { | |
2484 | frag = &buffer->frag_array[0]; | |
2485 | pci_unmap_single(pdev, frag->dma, frag->length, | |
2486 | PCI_DMA_TODEVICE); | |
2487 | frag->dma = 0ULL; | |
2488 | for (i = 1; i < buffer->frag_count; i++) { | |
2489 | frag++; | |
2490 | pci_unmap_page(pdev, frag->dma, frag->length, | |
2491 | PCI_DMA_TODEVICE); | |
2492 | frag->dma = 0ULL; | |
2493 | } | |
2494 | ||
2495 | adapter->stats.xmitfinished++; | |
2496 | dev_kfree_skb_any(buffer->skb); | |
2497 | buffer->skb = NULL; | |
2498 | } | |
2499 | ||
2500 | sw_consumer = get_next_index(sw_consumer, tx_ring->num_desc); | |
2501 | if (++count >= MAX_STATUS_HANDLE) | |
2502 | break; | |
2503 | } | |
2504 | ||
2505 | if (count && netif_running(netdev)) { | |
2506 | tx_ring->sw_consumer = sw_consumer; | |
2507 | ||
2508 | smp_mb(); | |
2509 | ||
2510 | if (netif_queue_stopped(netdev) && netif_carrier_ok(netdev)) { | |
af19b491 AKS |
2511 | if (qlcnic_tx_avail(tx_ring) > TX_STOP_THRESH) { |
2512 | netif_wake_queue(netdev); | |
8bfe8b91 | 2513 | adapter->stats.xmit_on++; |
af19b491 | 2514 | } |
af19b491 | 2515 | } |
ef71ff83 | 2516 | adapter->tx_timeo_cnt = 0; |
af19b491 AKS |
2517 | } |
2518 | /* | |
2519 | * If everything is freed up to consumer then check if the ring is full | |
2520 | * If the ring is full then check if more needs to be freed and | |
2521 | * schedule the call back again. | |
2522 | * | |
2523 | * This happens when there are 2 CPUs. One could be freeing and the | |
2524 | * other filling it. If the ring is full when we get out of here and | |
2525 | * the card has already interrupted the host then the host can miss the | |
2526 | * interrupt. | |
2527 | * | |
2528 | * There is still a possible race condition and the host could miss an | |
2529 | * interrupt. The card has to take care of this. | |
2530 | */ | |
2531 | hw_consumer = le32_to_cpu(*(tx_ring->hw_consumer)); | |
2532 | done = (sw_consumer == hw_consumer); | |
2533 | spin_unlock(&adapter->tx_clean_lock); | |
2534 | ||
2535 | return done; | |
2536 | } | |
2537 | ||
2538 | static int qlcnic_poll(struct napi_struct *napi, int budget) | |
2539 | { | |
2540 | struct qlcnic_host_sds_ring *sds_ring = | |
2541 | container_of(napi, struct qlcnic_host_sds_ring, napi); | |
2542 | ||
2543 | struct qlcnic_adapter *adapter = sds_ring->adapter; | |
2544 | ||
2545 | int tx_complete; | |
2546 | int work_done; | |
2547 | ||
2548 | tx_complete = qlcnic_process_cmd_ring(adapter); | |
2549 | ||
2550 | work_done = qlcnic_process_rcv_ring(sds_ring, budget); | |
2551 | ||
2552 | if ((work_done < budget) && tx_complete) { | |
2553 | napi_complete(&sds_ring->napi); | |
2554 | if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) | |
2555 | qlcnic_enable_int(sds_ring); | |
2556 | } | |
2557 | ||
2558 | return work_done; | |
2559 | } | |
2560 | ||
8f891387 | 2561 | static int qlcnic_rx_poll(struct napi_struct *napi, int budget) |
2562 | { | |
2563 | struct qlcnic_host_sds_ring *sds_ring = | |
2564 | container_of(napi, struct qlcnic_host_sds_ring, napi); | |
2565 | ||
2566 | struct qlcnic_adapter *adapter = sds_ring->adapter; | |
2567 | int work_done; | |
2568 | ||
2569 | work_done = qlcnic_process_rcv_ring(sds_ring, budget); | |
2570 | ||
2571 | if (work_done < budget) { | |
2572 | napi_complete(&sds_ring->napi); | |
2573 | if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) | |
2574 | qlcnic_enable_int(sds_ring); | |
2575 | } | |
2576 | ||
2577 | return work_done; | |
2578 | } | |
2579 | ||
af19b491 AKS |
2580 | #ifdef CONFIG_NET_POLL_CONTROLLER |
2581 | static void qlcnic_poll_controller(struct net_device *netdev) | |
2582 | { | |
bf82791e YL |
2583 | int ring; |
2584 | struct qlcnic_host_sds_ring *sds_ring; | |
af19b491 | 2585 | struct qlcnic_adapter *adapter = netdev_priv(netdev); |
b1fc6d3c | 2586 | struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx; |
bf82791e | 2587 | |
af19b491 | 2588 | disable_irq(adapter->irq); |
bf82791e YL |
2589 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { |
2590 | sds_ring = &recv_ctx->sds_rings[ring]; | |
2591 | qlcnic_intr(adapter->irq, sds_ring); | |
2592 | } | |
af19b491 AKS |
2593 | enable_irq(adapter->irq); |
2594 | } | |
2595 | #endif | |
2596 | ||
6df900e9 SC |
2597 | static void |
2598 | qlcnic_idc_debug_info(struct qlcnic_adapter *adapter, u8 encoding) | |
2599 | { | |
2600 | u32 val; | |
2601 | ||
2602 | val = adapter->portnum & 0xf; | |
2603 | val |= encoding << 7; | |
2604 | val |= (jiffies - adapter->dev_rst_time) << 8; | |
2605 | ||
2606 | QLCWR32(adapter, QLCNIC_CRB_DRV_SCRATCH, val); | |
2607 | adapter->dev_rst_time = jiffies; | |
2608 | } | |
2609 | ||
ade91f8e AKS |
2610 | static int |
2611 | qlcnic_set_drv_state(struct qlcnic_adapter *adapter, u8 state) | |
af19b491 AKS |
2612 | { |
2613 | u32 val; | |
2614 | ||
2615 | WARN_ON(state != QLCNIC_DEV_NEED_RESET && | |
2616 | state != QLCNIC_DEV_NEED_QUISCENT); | |
2617 | ||
2618 | if (qlcnic_api_lock(adapter)) | |
ade91f8e | 2619 | return -EIO; |
af19b491 AKS |
2620 | |
2621 | val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE); | |
2622 | ||
2623 | if (state == QLCNIC_DEV_NEED_RESET) | |
6d2a4724 | 2624 | QLC_DEV_SET_RST_RDY(val, adapter->portnum); |
af19b491 | 2625 | else if (state == QLCNIC_DEV_NEED_QUISCENT) |
6d2a4724 | 2626 | QLC_DEV_SET_QSCNT_RDY(val, adapter->portnum); |
af19b491 AKS |
2627 | |
2628 | QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val); | |
2629 | ||
2630 | qlcnic_api_unlock(adapter); | |
ade91f8e AKS |
2631 | |
2632 | return 0; | |
af19b491 AKS |
2633 | } |
2634 | ||
1b95a839 AKS |
2635 | static int |
2636 | qlcnic_clr_drv_state(struct qlcnic_adapter *adapter) | |
2637 | { | |
2638 | u32 val; | |
2639 | ||
2640 | if (qlcnic_api_lock(adapter)) | |
2641 | return -EBUSY; | |
2642 | ||
2643 | val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE); | |
6d2a4724 | 2644 | QLC_DEV_CLR_RST_QSCNT(val, adapter->portnum); |
1b95a839 AKS |
2645 | QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val); |
2646 | ||
2647 | qlcnic_api_unlock(adapter); | |
2648 | ||
2649 | return 0; | |
2650 | } | |
2651 | ||
af19b491 | 2652 | static void |
21854f02 | 2653 | qlcnic_clr_all_drv_state(struct qlcnic_adapter *adapter, u8 failed) |
af19b491 AKS |
2654 | { |
2655 | u32 val; | |
2656 | ||
2657 | if (qlcnic_api_lock(adapter)) | |
2658 | goto err; | |
2659 | ||
31018e06 | 2660 | val = QLCRD32(adapter, QLCNIC_CRB_DRV_ACTIVE); |
6d2a4724 | 2661 | QLC_DEV_CLR_REF_CNT(val, adapter->portnum); |
31018e06 | 2662 | QLCWR32(adapter, QLCNIC_CRB_DRV_ACTIVE, val); |
af19b491 | 2663 | |
21854f02 AKS |
2664 | if (failed) { |
2665 | QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_FAILED); | |
2666 | dev_info(&adapter->pdev->dev, | |
2667 | "Device state set to Failed. Please Reboot\n"); | |
2668 | } else if (!(val & 0x11111111)) | |
af19b491 AKS |
2669 | QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_COLD); |
2670 | ||
2671 | val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE); | |
6d2a4724 | 2672 | QLC_DEV_CLR_RST_QSCNT(val, adapter->portnum); |
af19b491 AKS |
2673 | QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val); |
2674 | ||
2675 | qlcnic_api_unlock(adapter); | |
2676 | err: | |
2677 | adapter->fw_fail_cnt = 0; | |
2678 | clear_bit(__QLCNIC_START_FW, &adapter->state); | |
2679 | clear_bit(__QLCNIC_RESETTING, &adapter->state); | |
2680 | } | |
2681 | ||
f73dfc50 | 2682 | /* Grab api lock, before checking state */ |
af19b491 AKS |
2683 | static int |
2684 | qlcnic_check_drv_state(struct qlcnic_adapter *adapter) | |
2685 | { | |
602ca6f0 | 2686 | int act, state, active_mask; |
af19b491 AKS |
2687 | |
2688 | state = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE); | |
31018e06 | 2689 | act = QLCRD32(adapter, QLCNIC_CRB_DRV_ACTIVE); |
af19b491 | 2690 | |
602ca6f0 SV |
2691 | if (adapter->flags & QLCNIC_FW_RESET_OWNER) { |
2692 | active_mask = (~(1 << (adapter->ahw->pci_func * 4))); | |
2693 | act = act & active_mask; | |
2694 | } | |
2695 | ||
af19b491 AKS |
2696 | if (((state & 0x11111111) == (act & 0x11111111)) || |
2697 | ((act & 0x11111111) == ((state >> 1) & 0x11111111))) | |
2698 | return 0; | |
2699 | else | |
2700 | return 1; | |
2701 | } | |
2702 | ||
96f8118c SC |
2703 | static int qlcnic_check_idc_ver(struct qlcnic_adapter *adapter) |
2704 | { | |
2705 | u32 val = QLCRD32(adapter, QLCNIC_CRB_DRV_IDC_VER); | |
2706 | ||
2707 | if (val != QLCNIC_DRV_IDC_VER) { | |
2708 | dev_warn(&adapter->pdev->dev, "IDC Version mismatch, driver's" | |
2709 | " idc ver = %x; reqd = %x\n", QLCNIC_DRV_IDC_VER, val); | |
2710 | } | |
2711 | ||
2712 | return 0; | |
2713 | } | |
2714 | ||
af19b491 AKS |
2715 | static int |
2716 | qlcnic_can_start_firmware(struct qlcnic_adapter *adapter) | |
2717 | { | |
2718 | u32 val, prev_state; | |
aa5e18c0 | 2719 | u8 dev_init_timeo = adapter->dev_init_timeo; |
6d2a4724 | 2720 | u8 portnum = adapter->portnum; |
96f8118c | 2721 | u8 ret; |
af19b491 | 2722 | |
f73dfc50 AKS |
2723 | if (test_and_clear_bit(__QLCNIC_START_FW, &adapter->state)) |
2724 | return 1; | |
2725 | ||
af19b491 AKS |
2726 | if (qlcnic_api_lock(adapter)) |
2727 | return -1; | |
2728 | ||
31018e06 | 2729 | val = QLCRD32(adapter, QLCNIC_CRB_DRV_ACTIVE); |
6d2a4724 AKS |
2730 | if (!(val & (1 << (portnum * 4)))) { |
2731 | QLC_DEV_SET_REF_CNT(val, portnum); | |
31018e06 | 2732 | QLCWR32(adapter, QLCNIC_CRB_DRV_ACTIVE, val); |
af19b491 AKS |
2733 | } |
2734 | ||
2735 | prev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE); | |
65b5b420 | 2736 | QLCDB(adapter, HW, "Device state = %u\n", prev_state); |
af19b491 AKS |
2737 | |
2738 | switch (prev_state) { | |
2739 | case QLCNIC_DEV_COLD: | |
bbd8c6a4 | 2740 | QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_INITIALIZING); |
96f8118c | 2741 | QLCWR32(adapter, QLCNIC_CRB_DRV_IDC_VER, QLCNIC_DRV_IDC_VER); |
6df900e9 | 2742 | qlcnic_idc_debug_info(adapter, 0); |
af19b491 AKS |
2743 | qlcnic_api_unlock(adapter); |
2744 | return 1; | |
2745 | ||
2746 | case QLCNIC_DEV_READY: | |
96f8118c | 2747 | ret = qlcnic_check_idc_ver(adapter); |
af19b491 | 2748 | qlcnic_api_unlock(adapter); |
96f8118c | 2749 | return ret; |
af19b491 AKS |
2750 | |
2751 | case QLCNIC_DEV_NEED_RESET: | |
2752 | val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE); | |
6d2a4724 | 2753 | QLC_DEV_SET_RST_RDY(val, portnum); |
af19b491 AKS |
2754 | QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val); |
2755 | break; | |
2756 | ||
2757 | case QLCNIC_DEV_NEED_QUISCENT: | |
2758 | val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE); | |
6d2a4724 | 2759 | QLC_DEV_SET_QSCNT_RDY(val, portnum); |
af19b491 AKS |
2760 | QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val); |
2761 | break; | |
2762 | ||
2763 | case QLCNIC_DEV_FAILED: | |
a7fc948f | 2764 | dev_err(&adapter->pdev->dev, "Device in failed state.\n"); |
af19b491 AKS |
2765 | qlcnic_api_unlock(adapter); |
2766 | return -1; | |
bbd8c6a4 AKS |
2767 | |
2768 | case QLCNIC_DEV_INITIALIZING: | |
2769 | case QLCNIC_DEV_QUISCENT: | |
2770 | break; | |
af19b491 AKS |
2771 | } |
2772 | ||
2773 | qlcnic_api_unlock(adapter); | |
aa5e18c0 SC |
2774 | |
2775 | do { | |
af19b491 | 2776 | msleep(1000); |
a5e463d0 SC |
2777 | prev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE); |
2778 | ||
2779 | if (prev_state == QLCNIC_DEV_QUISCENT) | |
2780 | continue; | |
2781 | } while ((prev_state != QLCNIC_DEV_READY) && --dev_init_timeo); | |
af19b491 | 2782 | |
65b5b420 AKS |
2783 | if (!dev_init_timeo) { |
2784 | dev_err(&adapter->pdev->dev, | |
2785 | "Waiting for device to initialize timeout\n"); | |
af19b491 | 2786 | return -1; |
65b5b420 | 2787 | } |
af19b491 AKS |
2788 | |
2789 | if (qlcnic_api_lock(adapter)) | |
2790 | return -1; | |
2791 | ||
2792 | val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE); | |
6d2a4724 | 2793 | QLC_DEV_CLR_RST_QSCNT(val, portnum); |
af19b491 AKS |
2794 | QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val); |
2795 | ||
96f8118c | 2796 | ret = qlcnic_check_idc_ver(adapter); |
af19b491 AKS |
2797 | qlcnic_api_unlock(adapter); |
2798 | ||
96f8118c | 2799 | return ret; |
af19b491 AKS |
2800 | } |
2801 | ||
2802 | static void | |
2803 | qlcnic_fwinit_work(struct work_struct *work) | |
2804 | { | |
2805 | struct qlcnic_adapter *adapter = container_of(work, | |
2806 | struct qlcnic_adapter, fw_work.work); | |
3c4b23b1 | 2807 | u32 dev_state = 0xf; |
af19b491 | 2808 | |
f73dfc50 AKS |
2809 | if (qlcnic_api_lock(adapter)) |
2810 | goto err_ret; | |
af19b491 | 2811 | |
a5e463d0 | 2812 | dev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE); |
b8c17620 AKS |
2813 | if (dev_state == QLCNIC_DEV_QUISCENT || |
2814 | dev_state == QLCNIC_DEV_NEED_QUISCENT) { | |
a5e463d0 SC |
2815 | qlcnic_api_unlock(adapter); |
2816 | qlcnic_schedule_work(adapter, qlcnic_fwinit_work, | |
2817 | FW_POLL_DELAY * 2); | |
2818 | return; | |
2819 | } | |
2820 | ||
9f26f547 | 2821 | if (adapter->op_mode == QLCNIC_NON_PRIV_FUNC) { |
3c4b23b1 AKS |
2822 | qlcnic_api_unlock(adapter); |
2823 | goto wait_npar; | |
9f26f547 AC |
2824 | } |
2825 | ||
f73dfc50 AKS |
2826 | if (adapter->fw_wait_cnt++ > adapter->reset_ack_timeo) { |
2827 | dev_err(&adapter->pdev->dev, "Reset:Failed to get ack %d sec\n", | |
2828 | adapter->reset_ack_timeo); | |
2829 | goto skip_ack_check; | |
2830 | } | |
2831 | ||
2832 | if (!qlcnic_check_drv_state(adapter)) { | |
2833 | skip_ack_check: | |
602ca6f0 SV |
2834 | if (!(adapter->flags & QLCNIC_FW_RESET_OWNER)) { |
2835 | qlcnic_api_unlock(adapter); | |
2836 | goto wait_npar; | |
2837 | } | |
2838 | ||
f73dfc50 | 2839 | dev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE); |
a5e463d0 | 2840 | |
f73dfc50 AKS |
2841 | if (dev_state == QLCNIC_DEV_NEED_RESET) { |
2842 | QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, | |
2843 | QLCNIC_DEV_INITIALIZING); | |
2844 | set_bit(__QLCNIC_START_FW, &adapter->state); | |
2845 | QLCDB(adapter, DRV, "Restarting fw\n"); | |
6df900e9 | 2846 | qlcnic_idc_debug_info(adapter, 0); |
af19b491 AKS |
2847 | } |
2848 | ||
f73dfc50 AKS |
2849 | qlcnic_api_unlock(adapter); |
2850 | ||
287e38aa | 2851 | rtnl_lock(); |
9d6a6440 AC |
2852 | if (adapter->ahw->fw_dump.enable) { |
2853 | QLCDB(adapter, DRV, "Take FW dump\n"); | |
2854 | qlcnic_dump_fw(adapter); | |
2855 | adapter->flags &= ~QLCNIC_FW_RESET_OWNER; | |
2856 | } | |
287e38aa | 2857 | rtnl_unlock(); |
9f26f547 | 2858 | if (!adapter->nic_ops->start_firmware(adapter)) { |
af19b491 | 2859 | qlcnic_schedule_work(adapter, qlcnic_attach_work, 0); |
b18971d1 | 2860 | adapter->fw_wait_cnt = 0; |
af19b491 AKS |
2861 | return; |
2862 | } | |
af19b491 AKS |
2863 | goto err_ret; |
2864 | } | |
2865 | ||
f73dfc50 | 2866 | qlcnic_api_unlock(adapter); |
aa5e18c0 | 2867 | |
9f26f547 | 2868 | wait_npar: |
af19b491 | 2869 | dev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE); |
f73dfc50 | 2870 | QLCDB(adapter, HW, "Func waiting: Device state=%u\n", dev_state); |
65b5b420 | 2871 | |
af19b491 | 2872 | switch (dev_state) { |
3c4b23b1 | 2873 | case QLCNIC_DEV_READY: |
9f26f547 | 2874 | if (!adapter->nic_ops->start_firmware(adapter)) { |
f73dfc50 | 2875 | qlcnic_schedule_work(adapter, qlcnic_attach_work, 0); |
b18971d1 | 2876 | adapter->fw_wait_cnt = 0; |
f73dfc50 AKS |
2877 | return; |
2878 | } | |
3c4b23b1 AKS |
2879 | case QLCNIC_DEV_FAILED: |
2880 | break; | |
2881 | default: | |
2882 | qlcnic_schedule_work(adapter, | |
2883 | qlcnic_fwinit_work, FW_POLL_DELAY); | |
2884 | return; | |
af19b491 AKS |
2885 | } |
2886 | ||
2887 | err_ret: | |
f73dfc50 AKS |
2888 | dev_err(&adapter->pdev->dev, "Fwinit work failed state=%u " |
2889 | "fw_wait_cnt=%u\n", dev_state, adapter->fw_wait_cnt); | |
34ce3626 | 2890 | netif_device_attach(adapter->netdev); |
21854f02 | 2891 | qlcnic_clr_all_drv_state(adapter, 0); |
af19b491 AKS |
2892 | } |
2893 | ||
2894 | static void | |
2895 | qlcnic_detach_work(struct work_struct *work) | |
2896 | { | |
2897 | struct qlcnic_adapter *adapter = container_of(work, | |
2898 | struct qlcnic_adapter, fw_work.work); | |
2899 | struct net_device *netdev = adapter->netdev; | |
2900 | u32 status; | |
2901 | ||
2902 | netif_device_detach(netdev); | |
2903 | ||
b8c17620 AKS |
2904 | /* Dont grab rtnl lock during Quiscent mode */ |
2905 | if (adapter->dev_state == QLCNIC_DEV_NEED_QUISCENT) { | |
2906 | if (netif_running(netdev)) | |
2907 | __qlcnic_down(adapter, netdev); | |
2908 | } else | |
2909 | qlcnic_down(adapter, netdev); | |
af19b491 | 2910 | |
af19b491 AKS |
2911 | status = QLCRD32(adapter, QLCNIC_PEG_HALT_STATUS1); |
2912 | ||
2913 | if (status & QLCNIC_RCODE_FATAL_ERROR) | |
2914 | goto err_ret; | |
2915 | ||
2916 | if (adapter->temp == QLCNIC_TEMP_PANIC) | |
2917 | goto err_ret; | |
602ca6f0 SV |
2918 | /* Dont ack if this instance is the reset owner */ |
2919 | if (!(adapter->flags & QLCNIC_FW_RESET_OWNER)) { | |
2920 | if (qlcnic_set_drv_state(adapter, adapter->dev_state)) | |
2921 | goto err_ret; | |
2922 | } | |
af19b491 AKS |
2923 | |
2924 | adapter->fw_wait_cnt = 0; | |
2925 | ||
2926 | qlcnic_schedule_work(adapter, qlcnic_fwinit_work, FW_POLL_DELAY); | |
2927 | ||
2928 | return; | |
2929 | ||
2930 | err_ret: | |
65b5b420 AKS |
2931 | dev_err(&adapter->pdev->dev, "detach failed; status=%d temp=%d\n", |
2932 | status, adapter->temp); | |
34ce3626 | 2933 | netif_device_attach(netdev); |
21854f02 | 2934 | qlcnic_clr_all_drv_state(adapter, 1); |
af19b491 AKS |
2935 | } |
2936 | ||
3c4b23b1 AKS |
2937 | /*Transit NPAR state to NON Operational */ |
2938 | static void | |
2939 | qlcnic_set_npar_non_operational(struct qlcnic_adapter *adapter) | |
2940 | { | |
2941 | u32 state; | |
2942 | ||
2943 | state = QLCRD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE); | |
2944 | if (state == QLCNIC_DEV_NPAR_NON_OPER) | |
2945 | return; | |
2946 | ||
2947 | if (qlcnic_api_lock(adapter)) | |
2948 | return; | |
2949 | QLCWR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE, QLCNIC_DEV_NPAR_NON_OPER); | |
2950 | qlcnic_api_unlock(adapter); | |
2951 | } | |
2952 | ||
f73dfc50 | 2953 | /*Transit to RESET state from READY state only */ |
18f2f616 | 2954 | void |
af19b491 AKS |
2955 | qlcnic_dev_request_reset(struct qlcnic_adapter *adapter) |
2956 | { | |
2957 | u32 state; | |
2958 | ||
cea8975e | 2959 | adapter->need_fw_reset = 1; |
af19b491 AKS |
2960 | if (qlcnic_api_lock(adapter)) |
2961 | return; | |
2962 | ||
2963 | state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE); | |
2964 | ||
f73dfc50 | 2965 | if (state == QLCNIC_DEV_READY) { |
af19b491 | 2966 | QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_NEED_RESET); |
602ca6f0 | 2967 | adapter->flags |= QLCNIC_FW_RESET_OWNER; |
65b5b420 | 2968 | QLCDB(adapter, DRV, "NEED_RESET state set\n"); |
6df900e9 | 2969 | qlcnic_idc_debug_info(adapter, 0); |
af19b491 AKS |
2970 | } |
2971 | ||
3c4b23b1 | 2972 | QLCWR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE, QLCNIC_DEV_NPAR_NON_OPER); |
af19b491 AKS |
2973 | qlcnic_api_unlock(adapter); |
2974 | } | |
2975 | ||
9f26f547 AC |
2976 | /* Transit to NPAR READY state from NPAR NOT READY state */ |
2977 | static void | |
2978 | qlcnic_dev_set_npar_ready(struct qlcnic_adapter *adapter) | |
2979 | { | |
9f26f547 AC |
2980 | if (qlcnic_api_lock(adapter)) |
2981 | return; | |
2982 | ||
3c4b23b1 AKS |
2983 | QLCWR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE, QLCNIC_DEV_NPAR_OPER); |
2984 | QLCDB(adapter, DRV, "NPAR operational state set\n"); | |
9f26f547 AC |
2985 | |
2986 | qlcnic_api_unlock(adapter); | |
2987 | } | |
2988 | ||
af19b491 AKS |
2989 | static void |
2990 | qlcnic_schedule_work(struct qlcnic_adapter *adapter, | |
2991 | work_func_t func, int delay) | |
2992 | { | |
451724c8 SC |
2993 | if (test_bit(__QLCNIC_AER, &adapter->state)) |
2994 | return; | |
2995 | ||
af19b491 | 2996 | INIT_DELAYED_WORK(&adapter->fw_work, func); |
f7ec804a AKS |
2997 | queue_delayed_work(qlcnic_wq, &adapter->fw_work, |
2998 | round_jiffies_relative(delay)); | |
af19b491 AKS |
2999 | } |
3000 | ||
3001 | static void | |
3002 | qlcnic_cancel_fw_work(struct qlcnic_adapter *adapter) | |
3003 | { | |
3004 | while (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state)) | |
3005 | msleep(10); | |
3006 | ||
3007 | cancel_delayed_work_sync(&adapter->fw_work); | |
3008 | } | |
3009 | ||
3010 | static void | |
3011 | qlcnic_attach_work(struct work_struct *work) | |
3012 | { | |
3013 | struct qlcnic_adapter *adapter = container_of(work, | |
3014 | struct qlcnic_adapter, fw_work.work); | |
3015 | struct net_device *netdev = adapter->netdev; | |
b18971d1 | 3016 | u32 npar_state; |
af19b491 | 3017 | |
b18971d1 AKS |
3018 | if (adapter->op_mode != QLCNIC_MGMT_FUNC) { |
3019 | npar_state = QLCRD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE); | |
3020 | if (adapter->fw_wait_cnt++ > QLCNIC_DEV_NPAR_OPER_TIMEO) | |
3021 | qlcnic_clr_all_drv_state(adapter, 0); | |
3022 | else if (npar_state != QLCNIC_DEV_NPAR_OPER) | |
3023 | qlcnic_schedule_work(adapter, qlcnic_attach_work, | |
3024 | FW_POLL_DELAY); | |
3025 | else | |
3026 | goto attach; | |
3027 | QLCDB(adapter, DRV, "Waiting for NPAR state to operational\n"); | |
3028 | return; | |
3029 | } | |
3030 | attach: | |
af19b491 | 3031 | if (netif_running(netdev)) { |
52486a3a | 3032 | if (qlcnic_up(adapter, netdev)) |
af19b491 | 3033 | goto done; |
af19b491 | 3034 | |
aec1e845 | 3035 | qlcnic_restore_indev_addr(netdev, NETDEV_UP); |
af19b491 AKS |
3036 | } |
3037 | ||
af19b491 | 3038 | done: |
34ce3626 | 3039 | netif_device_attach(netdev); |
af19b491 AKS |
3040 | adapter->fw_fail_cnt = 0; |
3041 | clear_bit(__QLCNIC_RESETTING, &adapter->state); | |
1b95a839 AKS |
3042 | |
3043 | if (!qlcnic_clr_drv_state(adapter)) | |
3044 | qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, | |
3045 | FW_POLL_DELAY); | |
af19b491 AKS |
3046 | } |
3047 | ||
3048 | static int | |
3049 | qlcnic_check_health(struct qlcnic_adapter *adapter) | |
3050 | { | |
4e70812b | 3051 | u32 state = 0, heartbeat; |
af19b491 AKS |
3052 | struct net_device *netdev = adapter->netdev; |
3053 | ||
3054 | if (qlcnic_check_temp(adapter)) | |
3055 | goto detach; | |
3056 | ||
2372a5f1 | 3057 | if (adapter->need_fw_reset) |
af19b491 | 3058 | qlcnic_dev_request_reset(adapter); |
af19b491 AKS |
3059 | |
3060 | state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE); | |
b8c17620 | 3061 | if (state == QLCNIC_DEV_NEED_RESET) { |
3c4b23b1 | 3062 | qlcnic_set_npar_non_operational(adapter); |
af19b491 | 3063 | adapter->need_fw_reset = 1; |
b8c17620 AKS |
3064 | } else if (state == QLCNIC_DEV_NEED_QUISCENT) |
3065 | goto detach; | |
af19b491 | 3066 | |
4e70812b SC |
3067 | heartbeat = QLCRD32(adapter, QLCNIC_PEG_ALIVE_COUNTER); |
3068 | if (heartbeat != adapter->heartbeat) { | |
3069 | adapter->heartbeat = heartbeat; | |
af19b491 AKS |
3070 | adapter->fw_fail_cnt = 0; |
3071 | if (adapter->need_fw_reset) | |
3072 | goto detach; | |
68bf1c68 | 3073 | |
9ce13ca8 | 3074 | if (adapter->reset_context && auto_fw_reset) { |
68bf1c68 AKS |
3075 | qlcnic_reset_hw_context(adapter); |
3076 | adapter->netdev->trans_start = jiffies; | |
3077 | } | |
3078 | ||
af19b491 AKS |
3079 | return 0; |
3080 | } | |
3081 | ||
3082 | if (++adapter->fw_fail_cnt < FW_FAIL_THRESH) | |
3083 | return 0; | |
3084 | ||
3085 | qlcnic_dev_request_reset(adapter); | |
3086 | ||
9ce13ca8 | 3087 | if (auto_fw_reset) |
0df170b6 | 3088 | clear_bit(__QLCNIC_FW_ATTACHED, &adapter->state); |
af19b491 AKS |
3089 | |
3090 | dev_info(&netdev->dev, "firmware hang detected\n"); | |
3091 | ||
3092 | detach: | |
3093 | adapter->dev_state = (state == QLCNIC_DEV_NEED_QUISCENT) ? state : | |
3094 | QLCNIC_DEV_NEED_RESET; | |
3095 | ||
9ce13ca8 | 3096 | if (auto_fw_reset && |
65b5b420 AKS |
3097 | !test_and_set_bit(__QLCNIC_RESETTING, &adapter->state)) { |
3098 | ||
af19b491 | 3099 | qlcnic_schedule_work(adapter, qlcnic_detach_work, 0); |
65b5b420 AKS |
3100 | QLCDB(adapter, DRV, "fw recovery scheduled.\n"); |
3101 | } | |
af19b491 AKS |
3102 | |
3103 | return 1; | |
3104 | } | |
3105 | ||
3106 | static void | |
3107 | qlcnic_fw_poll_work(struct work_struct *work) | |
3108 | { | |
3109 | struct qlcnic_adapter *adapter = container_of(work, | |
3110 | struct qlcnic_adapter, fw_work.work); | |
3111 | ||
3112 | if (test_bit(__QLCNIC_RESETTING, &adapter->state)) | |
3113 | goto reschedule; | |
3114 | ||
3115 | ||
3116 | if (qlcnic_check_health(adapter)) | |
3117 | return; | |
3118 | ||
b5e5492c AKS |
3119 | if (adapter->fhash.fnum) |
3120 | qlcnic_prune_lb_filters(adapter); | |
3121 | ||
af19b491 AKS |
3122 | reschedule: |
3123 | qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY); | |
3124 | } | |
3125 | ||
451724c8 SC |
3126 | static int qlcnic_is_first_func(struct pci_dev *pdev) |
3127 | { | |
3128 | struct pci_dev *oth_pdev; | |
3129 | int val = pdev->devfn; | |
3130 | ||
3131 | while (val-- > 0) { | |
3132 | oth_pdev = pci_get_domain_bus_and_slot(pci_domain_nr | |
3133 | (pdev->bus), pdev->bus->number, | |
3134 | PCI_DEVFN(PCI_SLOT(pdev->devfn), val)); | |
bfc978fa AKS |
3135 | if (!oth_pdev) |
3136 | continue; | |
451724c8 | 3137 | |
bfc978fa AKS |
3138 | if (oth_pdev->current_state != PCI_D3cold) { |
3139 | pci_dev_put(oth_pdev); | |
451724c8 | 3140 | return 0; |
bfc978fa AKS |
3141 | } |
3142 | pci_dev_put(oth_pdev); | |
451724c8 SC |
3143 | } |
3144 | return 1; | |
3145 | } | |
3146 | ||
3147 | static int qlcnic_attach_func(struct pci_dev *pdev) | |
3148 | { | |
3149 | int err, first_func; | |
3150 | struct qlcnic_adapter *adapter = pci_get_drvdata(pdev); | |
3151 | struct net_device *netdev = adapter->netdev; | |
3152 | ||
3153 | pdev->error_state = pci_channel_io_normal; | |
3154 | ||
3155 | err = pci_enable_device(pdev); | |
3156 | if (err) | |
3157 | return err; | |
3158 | ||
3159 | pci_set_power_state(pdev, PCI_D0); | |
3160 | pci_set_master(pdev); | |
3161 | pci_restore_state(pdev); | |
3162 | ||
3163 | first_func = qlcnic_is_first_func(pdev); | |
3164 | ||
3165 | if (qlcnic_api_lock(adapter)) | |
3166 | return -EINVAL; | |
3167 | ||
933fce12 | 3168 | if (adapter->op_mode != QLCNIC_NON_PRIV_FUNC && first_func) { |
451724c8 SC |
3169 | adapter->need_fw_reset = 1; |
3170 | set_bit(__QLCNIC_START_FW, &adapter->state); | |
3171 | QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_INITIALIZING); | |
3172 | QLCDB(adapter, DRV, "Restarting fw\n"); | |
3173 | } | |
3174 | qlcnic_api_unlock(adapter); | |
3175 | ||
3176 | err = adapter->nic_ops->start_firmware(adapter); | |
3177 | if (err) | |
3178 | return err; | |
3179 | ||
3180 | qlcnic_clr_drv_state(adapter); | |
3181 | qlcnic_setup_intr(adapter); | |
3182 | ||
3183 | if (netif_running(netdev)) { | |
3184 | err = qlcnic_attach(adapter); | |
3185 | if (err) { | |
21854f02 | 3186 | qlcnic_clr_all_drv_state(adapter, 1); |
451724c8 SC |
3187 | clear_bit(__QLCNIC_AER, &adapter->state); |
3188 | netif_device_attach(netdev); | |
3189 | return err; | |
3190 | } | |
3191 | ||
3192 | err = qlcnic_up(adapter, netdev); | |
3193 | if (err) | |
3194 | goto done; | |
3195 | ||
aec1e845 | 3196 | qlcnic_restore_indev_addr(netdev, NETDEV_UP); |
451724c8 SC |
3197 | } |
3198 | done: | |
3199 | netif_device_attach(netdev); | |
3200 | return err; | |
3201 | } | |
3202 | ||
3203 | static pci_ers_result_t qlcnic_io_error_detected(struct pci_dev *pdev, | |
3204 | pci_channel_state_t state) | |
3205 | { | |
3206 | struct qlcnic_adapter *adapter = pci_get_drvdata(pdev); | |
3207 | struct net_device *netdev = adapter->netdev; | |
3208 | ||
3209 | if (state == pci_channel_io_perm_failure) | |
3210 | return PCI_ERS_RESULT_DISCONNECT; | |
3211 | ||
3212 | if (state == pci_channel_io_normal) | |
3213 | return PCI_ERS_RESULT_RECOVERED; | |
3214 | ||
3215 | set_bit(__QLCNIC_AER, &adapter->state); | |
3216 | netif_device_detach(netdev); | |
3217 | ||
3218 | cancel_delayed_work_sync(&adapter->fw_work); | |
3219 | ||
3220 | if (netif_running(netdev)) | |
3221 | qlcnic_down(adapter, netdev); | |
3222 | ||
3223 | qlcnic_detach(adapter); | |
3224 | qlcnic_teardown_intr(adapter); | |
3225 | ||
3226 | clear_bit(__QLCNIC_RESETTING, &adapter->state); | |
3227 | ||
3228 | pci_save_state(pdev); | |
3229 | pci_disable_device(pdev); | |
3230 | ||
3231 | return PCI_ERS_RESULT_NEED_RESET; | |
3232 | } | |
3233 | ||
3234 | static pci_ers_result_t qlcnic_io_slot_reset(struct pci_dev *pdev) | |
3235 | { | |
3236 | return qlcnic_attach_func(pdev) ? PCI_ERS_RESULT_DISCONNECT : | |
3237 | PCI_ERS_RESULT_RECOVERED; | |
3238 | } | |
3239 | ||
3240 | static void qlcnic_io_resume(struct pci_dev *pdev) | |
3241 | { | |
3242 | struct qlcnic_adapter *adapter = pci_get_drvdata(pdev); | |
3243 | ||
3244 | pci_cleanup_aer_uncorrect_error_status(pdev); | |
3245 | ||
3246 | if (QLCRD32(adapter, QLCNIC_CRB_DEV_STATE) == QLCNIC_DEV_READY && | |
3247 | test_and_clear_bit(__QLCNIC_AER, &adapter->state)) | |
3248 | qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, | |
3249 | FW_POLL_DELAY); | |
3250 | } | |
3251 | ||
87eb743b AC |
3252 | static int |
3253 | qlcnicvf_start_firmware(struct qlcnic_adapter *adapter) | |
3254 | { | |
3255 | int err; | |
3256 | ||
3257 | err = qlcnic_can_start_firmware(adapter); | |
3258 | if (err) | |
3259 | return err; | |
3260 | ||
78f84e1a AKS |
3261 | err = qlcnic_check_npar_opertional(adapter); |
3262 | if (err) | |
3263 | return err; | |
3c4b23b1 | 3264 | |
174240a8 RB |
3265 | err = qlcnic_initialize_nic(adapter); |
3266 | if (err) | |
3267 | return err; | |
3268 | ||
87eb743b AC |
3269 | qlcnic_check_options(adapter); |
3270 | ||
7373373d RB |
3271 | err = qlcnic_set_eswitch_port_config(adapter); |
3272 | if (err) | |
3273 | return err; | |
3274 | ||
87eb743b AC |
3275 | adapter->need_fw_reset = 0; |
3276 | ||
3277 | return err; | |
3278 | } | |
3279 | ||
3280 | static int | |
3281 | qlcnicvf_config_bridged_mode(struct qlcnic_adapter *adapter, u32 enable) | |
3282 | { | |
3283 | return -EOPNOTSUPP; | |
3284 | } | |
3285 | ||
3286 | static int | |
3287 | qlcnicvf_config_led(struct qlcnic_adapter *adapter, u32 state, u32 rate) | |
3288 | { | |
3289 | return -EOPNOTSUPP; | |
3290 | } | |
3291 | ||
af19b491 AKS |
3292 | static ssize_t |
3293 | qlcnic_store_bridged_mode(struct device *dev, | |
3294 | struct device_attribute *attr, const char *buf, size_t len) | |
3295 | { | |
3296 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); | |
3297 | unsigned long new; | |
3298 | int ret = -EINVAL; | |
3299 | ||
3300 | if (!(adapter->capabilities & QLCNIC_FW_CAPABILITY_BDG)) | |
3301 | goto err_out; | |
3302 | ||
8a15ad1f | 3303 | if (!test_bit(__QLCNIC_DEV_UP, &adapter->state)) |
af19b491 AKS |
3304 | goto err_out; |
3305 | ||
3306 | if (strict_strtoul(buf, 2, &new)) | |
3307 | goto err_out; | |
3308 | ||
2e9d722d | 3309 | if (!adapter->nic_ops->config_bridged_mode(adapter, !!new)) |
af19b491 AKS |
3310 | ret = len; |
3311 | ||
3312 | err_out: | |
3313 | return ret; | |
3314 | } | |
3315 | ||
3316 | static ssize_t | |
3317 | qlcnic_show_bridged_mode(struct device *dev, | |
3318 | struct device_attribute *attr, char *buf) | |
3319 | { | |
3320 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); | |
3321 | int bridged_mode = 0; | |
3322 | ||
3323 | if (adapter->capabilities & QLCNIC_FW_CAPABILITY_BDG) | |
3324 | bridged_mode = !!(adapter->flags & QLCNIC_BRIDGE_ENABLED); | |
3325 | ||
3326 | return sprintf(buf, "%d\n", bridged_mode); | |
3327 | } | |
3328 | ||
3329 | static struct device_attribute dev_attr_bridged_mode = { | |
3330 | .attr = {.name = "bridged_mode", .mode = (S_IRUGO | S_IWUSR)}, | |
3331 | .show = qlcnic_show_bridged_mode, | |
3332 | .store = qlcnic_store_bridged_mode, | |
3333 | }; | |
3334 | ||
3335 | static ssize_t | |
3336 | qlcnic_store_diag_mode(struct device *dev, | |
3337 | struct device_attribute *attr, const char *buf, size_t len) | |
3338 | { | |
3339 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); | |
3340 | unsigned long new; | |
3341 | ||
3342 | if (strict_strtoul(buf, 2, &new)) | |
3343 | return -EINVAL; | |
3344 | ||
3345 | if (!!new != !!(adapter->flags & QLCNIC_DIAG_ENABLED)) | |
3346 | adapter->flags ^= QLCNIC_DIAG_ENABLED; | |
3347 | ||
3348 | return len; | |
3349 | } | |
3350 | ||
3351 | static ssize_t | |
3352 | qlcnic_show_diag_mode(struct device *dev, | |
3353 | struct device_attribute *attr, char *buf) | |
3354 | { | |
3355 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); | |
3356 | ||
3357 | return sprintf(buf, "%d\n", | |
3358 | !!(adapter->flags & QLCNIC_DIAG_ENABLED)); | |
3359 | } | |
3360 | ||
3361 | static struct device_attribute dev_attr_diag_mode = { | |
3362 | .attr = {.name = "diag_mode", .mode = (S_IRUGO | S_IWUSR)}, | |
3363 | .show = qlcnic_show_diag_mode, | |
3364 | .store = qlcnic_store_diag_mode, | |
3365 | }; | |
3366 | ||
f94bc1e7 SC |
3367 | int qlcnic_validate_max_rss(struct net_device *netdev, u8 max_hw, u8 val) |
3368 | { | |
3369 | if (!use_msi_x && !use_msi) { | |
3370 | netdev_info(netdev, "no msix or msi support, hence no rss\n"); | |
3371 | return -EINVAL; | |
3372 | } | |
3373 | ||
3374 | if ((val > max_hw) || (val < 2) || !is_power_of_2(val)) { | |
3375 | netdev_info(netdev, "rss_ring valid range [2 - %x] in " | |
3376 | " powers of 2\n", max_hw); | |
3377 | return -EINVAL; | |
3378 | } | |
3379 | return 0; | |
3380 | ||
3381 | } | |
3382 | ||
3383 | int qlcnic_set_max_rss(struct qlcnic_adapter *adapter, u8 data) | |
3384 | { | |
3385 | struct net_device *netdev = adapter->netdev; | |
3386 | int err = 0; | |
3387 | ||
3388 | if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state)) | |
3389 | return -EBUSY; | |
3390 | ||
3391 | netif_device_detach(netdev); | |
3392 | if (netif_running(netdev)) | |
3393 | __qlcnic_down(adapter, netdev); | |
3394 | qlcnic_detach(adapter); | |
3395 | qlcnic_teardown_intr(adapter); | |
3396 | ||
3397 | if (qlcnic_enable_msix(adapter, data)) { | |
3398 | netdev_info(netdev, "failed setting max_rss; rss disabled\n"); | |
3399 | qlcnic_enable_msi_legacy(adapter); | |
3400 | } | |
3401 | ||
3402 | if (netif_running(netdev)) { | |
3403 | err = qlcnic_attach(adapter); | |
3404 | if (err) | |
3405 | goto done; | |
3406 | err = __qlcnic_up(adapter, netdev); | |
3407 | if (err) | |
3408 | goto done; | |
3409 | qlcnic_restore_indev_addr(netdev, NETDEV_UP); | |
3410 | } | |
3411 | done: | |
3412 | netif_device_attach(netdev); | |
3413 | clear_bit(__QLCNIC_RESETTING, &adapter->state); | |
3414 | return err; | |
3415 | } | |
3416 | ||
af19b491 AKS |
3417 | static int |
3418 | qlcnic_sysfs_validate_crb(struct qlcnic_adapter *adapter, | |
3419 | loff_t offset, size_t size) | |
3420 | { | |
897e8c7c DP |
3421 | size_t crb_size = 4; |
3422 | ||
af19b491 AKS |
3423 | if (!(adapter->flags & QLCNIC_DIAG_ENABLED)) |
3424 | return -EIO; | |
3425 | ||
897e8c7c DP |
3426 | if (offset < QLCNIC_PCI_CRBSPACE) { |
3427 | if (ADDR_IN_RANGE(offset, QLCNIC_PCI_CAMQM, | |
3428 | QLCNIC_PCI_CAMQM_END)) | |
3429 | crb_size = 8; | |
3430 | else | |
3431 | return -EINVAL; | |
3432 | } | |
af19b491 | 3433 | |
897e8c7c DP |
3434 | if ((size != crb_size) || (offset & (crb_size-1))) |
3435 | return -EINVAL; | |
af19b491 AKS |
3436 | |
3437 | return 0; | |
3438 | } | |
3439 | ||
3440 | static ssize_t | |
2c3c8bea CW |
3441 | qlcnic_sysfs_read_crb(struct file *filp, struct kobject *kobj, |
3442 | struct bin_attribute *attr, | |
af19b491 AKS |
3443 | char *buf, loff_t offset, size_t size) |
3444 | { | |
3445 | struct device *dev = container_of(kobj, struct device, kobj); | |
3446 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); | |
3447 | u32 data; | |
897e8c7c | 3448 | u64 qmdata; |
af19b491 AKS |
3449 | int ret; |
3450 | ||
3451 | ret = qlcnic_sysfs_validate_crb(adapter, offset, size); | |
3452 | if (ret != 0) | |
3453 | return ret; | |
3454 | ||
897e8c7c DP |
3455 | if (ADDR_IN_RANGE(offset, QLCNIC_PCI_CAMQM, QLCNIC_PCI_CAMQM_END)) { |
3456 | qlcnic_pci_camqm_read_2M(adapter, offset, &qmdata); | |
3457 | memcpy(buf, &qmdata, size); | |
3458 | } else { | |
3459 | data = QLCRD32(adapter, offset); | |
3460 | memcpy(buf, &data, size); | |
3461 | } | |
af19b491 AKS |
3462 | return size; |
3463 | } | |
3464 | ||
3465 | static ssize_t | |
2c3c8bea CW |
3466 | qlcnic_sysfs_write_crb(struct file *filp, struct kobject *kobj, |
3467 | struct bin_attribute *attr, | |
af19b491 AKS |
3468 | char *buf, loff_t offset, size_t size) |
3469 | { | |
3470 | struct device *dev = container_of(kobj, struct device, kobj); | |
3471 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); | |
3472 | u32 data; | |
897e8c7c | 3473 | u64 qmdata; |
af19b491 AKS |
3474 | int ret; |
3475 | ||
3476 | ret = qlcnic_sysfs_validate_crb(adapter, offset, size); | |
3477 | if (ret != 0) | |
3478 | return ret; | |
3479 | ||
897e8c7c DP |
3480 | if (ADDR_IN_RANGE(offset, QLCNIC_PCI_CAMQM, QLCNIC_PCI_CAMQM_END)) { |
3481 | memcpy(&qmdata, buf, size); | |
3482 | qlcnic_pci_camqm_write_2M(adapter, offset, qmdata); | |
3483 | } else { | |
3484 | memcpy(&data, buf, size); | |
3485 | QLCWR32(adapter, offset, data); | |
3486 | } | |
af19b491 AKS |
3487 | return size; |
3488 | } | |
3489 | ||
3490 | static int | |
3491 | qlcnic_sysfs_validate_mem(struct qlcnic_adapter *adapter, | |
3492 | loff_t offset, size_t size) | |
3493 | { | |
3494 | if (!(adapter->flags & QLCNIC_DIAG_ENABLED)) | |
3495 | return -EIO; | |
3496 | ||
3497 | if ((size != 8) || (offset & 0x7)) | |
3498 | return -EIO; | |
3499 | ||
3500 | return 0; | |
3501 | } | |
3502 | ||
3503 | static ssize_t | |
2c3c8bea CW |
3504 | qlcnic_sysfs_read_mem(struct file *filp, struct kobject *kobj, |
3505 | struct bin_attribute *attr, | |
af19b491 AKS |
3506 | char *buf, loff_t offset, size_t size) |
3507 | { | |
3508 | struct device *dev = container_of(kobj, struct device, kobj); | |
3509 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); | |
3510 | u64 data; | |
3511 | int ret; | |
3512 | ||
3513 | ret = qlcnic_sysfs_validate_mem(adapter, offset, size); | |
3514 | if (ret != 0) | |
3515 | return ret; | |
3516 | ||
3517 | if (qlcnic_pci_mem_read_2M(adapter, offset, &data)) | |
3518 | return -EIO; | |
3519 | ||
3520 | memcpy(buf, &data, size); | |
3521 | ||
3522 | return size; | |
3523 | } | |
3524 | ||
3525 | static ssize_t | |
2c3c8bea CW |
3526 | qlcnic_sysfs_write_mem(struct file *filp, struct kobject *kobj, |
3527 | struct bin_attribute *attr, | |
af19b491 AKS |
3528 | char *buf, loff_t offset, size_t size) |
3529 | { | |
3530 | struct device *dev = container_of(kobj, struct device, kobj); | |
3531 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); | |
3532 | u64 data; | |
3533 | int ret; | |
3534 | ||
3535 | ret = qlcnic_sysfs_validate_mem(adapter, offset, size); | |
3536 | if (ret != 0) | |
3537 | return ret; | |
3538 | ||
3539 | memcpy(&data, buf, size); | |
3540 | ||
3541 | if (qlcnic_pci_mem_write_2M(adapter, offset, data)) | |
3542 | return -EIO; | |
3543 | ||
3544 | return size; | |
3545 | } | |
3546 | ||
af19b491 AKS |
3547 | static struct bin_attribute bin_attr_crb = { |
3548 | .attr = {.name = "crb", .mode = (S_IRUGO | S_IWUSR)}, | |
3549 | .size = 0, | |
3550 | .read = qlcnic_sysfs_read_crb, | |
3551 | .write = qlcnic_sysfs_write_crb, | |
3552 | }; | |
3553 | ||
3554 | static struct bin_attribute bin_attr_mem = { | |
3555 | .attr = {.name = "mem", .mode = (S_IRUGO | S_IWUSR)}, | |
3556 | .size = 0, | |
3557 | .read = qlcnic_sysfs_read_mem, | |
3558 | .write = qlcnic_sysfs_write_mem, | |
3559 | }; | |
3560 | ||
cea8975e | 3561 | static int |
346fe763 RB |
3562 | validate_pm_config(struct qlcnic_adapter *adapter, |
3563 | struct qlcnic_pm_func_cfg *pm_cfg, int count) | |
3564 | { | |
3565 | ||
3566 | u8 src_pci_func, s_esw_id, d_esw_id; | |
3567 | u8 dest_pci_func; | |
3568 | int i; | |
3569 | ||
3570 | for (i = 0; i < count; i++) { | |
3571 | src_pci_func = pm_cfg[i].pci_func; | |
3572 | dest_pci_func = pm_cfg[i].dest_npar; | |
3573 | if (src_pci_func >= QLCNIC_MAX_PCI_FUNC | |
3574 | || dest_pci_func >= QLCNIC_MAX_PCI_FUNC) | |
3575 | return QL_STATUS_INVALID_PARAM; | |
3576 | ||
3577 | if (adapter->npars[src_pci_func].type != QLCNIC_TYPE_NIC) | |
3578 | return QL_STATUS_INVALID_PARAM; | |
3579 | ||
3580 | if (adapter->npars[dest_pci_func].type != QLCNIC_TYPE_NIC) | |
3581 | return QL_STATUS_INVALID_PARAM; | |
3582 | ||
346fe763 RB |
3583 | s_esw_id = adapter->npars[src_pci_func].phy_port; |
3584 | d_esw_id = adapter->npars[dest_pci_func].phy_port; | |
3585 | ||
3586 | if (s_esw_id != d_esw_id) | |
3587 | return QL_STATUS_INVALID_PARAM; | |
3588 | ||
3589 | } | |
3590 | return 0; | |
3591 | ||
3592 | } | |
3593 | ||
3594 | static ssize_t | |
3595 | qlcnic_sysfs_write_pm_config(struct file *filp, struct kobject *kobj, | |
3596 | struct bin_attribute *attr, char *buf, loff_t offset, size_t size) | |
3597 | { | |
3598 | struct device *dev = container_of(kobj, struct device, kobj); | |
3599 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); | |
3600 | struct qlcnic_pm_func_cfg *pm_cfg; | |
3601 | u32 id, action, pci_func; | |
3602 | int count, rem, i, ret; | |
3603 | ||
3604 | count = size / sizeof(struct qlcnic_pm_func_cfg); | |
3605 | rem = size % sizeof(struct qlcnic_pm_func_cfg); | |
3606 | if (rem) | |
3607 | return QL_STATUS_INVALID_PARAM; | |
3608 | ||
3609 | pm_cfg = (struct qlcnic_pm_func_cfg *) buf; | |
3610 | ||
3611 | ret = validate_pm_config(adapter, pm_cfg, count); | |
3612 | if (ret) | |
3613 | return ret; | |
3614 | for (i = 0; i < count; i++) { | |
3615 | pci_func = pm_cfg[i].pci_func; | |
4e8acb01 | 3616 | action = !!pm_cfg[i].action; |
346fe763 RB |
3617 | id = adapter->npars[pci_func].phy_port; |
3618 | ret = qlcnic_config_port_mirroring(adapter, id, | |
3619 | action, pci_func); | |
3620 | if (ret) | |
3621 | return ret; | |
3622 | } | |
3623 | ||
3624 | for (i = 0; i < count; i++) { | |
3625 | pci_func = pm_cfg[i].pci_func; | |
3626 | id = adapter->npars[pci_func].phy_port; | |
4e8acb01 | 3627 | adapter->npars[pci_func].enable_pm = !!pm_cfg[i].action; |
346fe763 RB |
3628 | adapter->npars[pci_func].dest_npar = id; |
3629 | } | |
3630 | return size; | |
3631 | } | |
3632 | ||
3633 | static ssize_t | |
3634 | qlcnic_sysfs_read_pm_config(struct file *filp, struct kobject *kobj, | |
3635 | struct bin_attribute *attr, char *buf, loff_t offset, size_t size) | |
3636 | { | |
3637 | struct device *dev = container_of(kobj, struct device, kobj); | |
3638 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); | |
3639 | struct qlcnic_pm_func_cfg pm_cfg[QLCNIC_MAX_PCI_FUNC]; | |
3640 | int i; | |
3641 | ||
3642 | if (size != sizeof(pm_cfg)) | |
3643 | return QL_STATUS_INVALID_PARAM; | |
3644 | ||
3645 | for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) { | |
3646 | if (adapter->npars[i].type != QLCNIC_TYPE_NIC) | |
3647 | continue; | |
3648 | pm_cfg[i].action = adapter->npars[i].enable_pm; | |
3649 | pm_cfg[i].dest_npar = 0; | |
3650 | pm_cfg[i].pci_func = i; | |
3651 | } | |
3652 | memcpy(buf, &pm_cfg, size); | |
3653 | ||
3654 | return size; | |
3655 | } | |
3656 | ||
cea8975e | 3657 | static int |
346fe763 | 3658 | validate_esw_config(struct qlcnic_adapter *adapter, |
4e8acb01 | 3659 | struct qlcnic_esw_func_cfg *esw_cfg, int count) |
346fe763 | 3660 | { |
7613c87b | 3661 | u32 op_mode; |
346fe763 RB |
3662 | u8 pci_func; |
3663 | int i; | |
7613c87b | 3664 | |
b1fc6d3c | 3665 | op_mode = readl(adapter->ahw->pci_base0 + QLCNIC_DRV_OP_MODE); |
7613c87b | 3666 | |
346fe763 RB |
3667 | for (i = 0; i < count; i++) { |
3668 | pci_func = esw_cfg[i].pci_func; | |
3669 | if (pci_func >= QLCNIC_MAX_PCI_FUNC) | |
3670 | return QL_STATUS_INVALID_PARAM; | |
3671 | ||
4e8acb01 RB |
3672 | if (adapter->op_mode == QLCNIC_MGMT_FUNC) |
3673 | if (adapter->npars[pci_func].type != QLCNIC_TYPE_NIC) | |
3674 | return QL_STATUS_INVALID_PARAM; | |
346fe763 | 3675 | |
4e8acb01 RB |
3676 | switch (esw_cfg[i].op_mode) { |
3677 | case QLCNIC_PORT_DEFAULTS: | |
7613c87b | 3678 | if (QLC_DEV_GET_DRV(op_mode, pci_func) != |
7373373d | 3679 | QLCNIC_NON_PRIV_FUNC) { |
091056b2 AKS |
3680 | if (esw_cfg[i].mac_anti_spoof != 0) |
3681 | return QL_STATUS_INVALID_PARAM; | |
3682 | if (esw_cfg[i].mac_override != 1) | |
3683 | return QL_STATUS_INVALID_PARAM; | |
3684 | if (esw_cfg[i].promisc_mode != 1) | |
3685 | return QL_STATUS_INVALID_PARAM; | |
7373373d | 3686 | } |
4e8acb01 RB |
3687 | break; |
3688 | case QLCNIC_ADD_VLAN: | |
346fe763 RB |
3689 | if (!IS_VALID_VLAN(esw_cfg[i].vlan_id)) |
3690 | return QL_STATUS_INVALID_PARAM; | |
4e8acb01 RB |
3691 | if (!esw_cfg[i].op_type) |
3692 | return QL_STATUS_INVALID_PARAM; | |
3693 | break; | |
3694 | case QLCNIC_DEL_VLAN: | |
4e8acb01 RB |
3695 | if (!esw_cfg[i].op_type) |
3696 | return QL_STATUS_INVALID_PARAM; | |
3697 | break; | |
3698 | default: | |
346fe763 | 3699 | return QL_STATUS_INVALID_PARAM; |
4e8acb01 | 3700 | } |
346fe763 | 3701 | } |
346fe763 RB |
3702 | return 0; |
3703 | } | |
3704 | ||
3705 | static ssize_t | |
3706 | qlcnic_sysfs_write_esw_config(struct file *file, struct kobject *kobj, | |
3707 | struct bin_attribute *attr, char *buf, loff_t offset, size_t size) | |
3708 | { | |
3709 | struct device *dev = container_of(kobj, struct device, kobj); | |
3710 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); | |
3711 | struct qlcnic_esw_func_cfg *esw_cfg; | |
4e8acb01 | 3712 | struct qlcnic_npar_info *npar; |
346fe763 | 3713 | int count, rem, i, ret; |
0325d69b | 3714 | u8 pci_func, op_mode = 0; |
346fe763 RB |
3715 | |
3716 | count = size / sizeof(struct qlcnic_esw_func_cfg); | |
3717 | rem = size % sizeof(struct qlcnic_esw_func_cfg); | |
3718 | if (rem) | |
3719 | return QL_STATUS_INVALID_PARAM; | |
3720 | ||
3721 | esw_cfg = (struct qlcnic_esw_func_cfg *) buf; | |
3722 | ret = validate_esw_config(adapter, esw_cfg, count); | |
3723 | if (ret) | |
3724 | return ret; | |
3725 | ||
3726 | for (i = 0; i < count; i++) { | |
0325d69b RB |
3727 | if (adapter->op_mode == QLCNIC_MGMT_FUNC) |
3728 | if (qlcnic_config_switch_port(adapter, &esw_cfg[i])) | |
3729 | return QL_STATUS_INVALID_PARAM; | |
e9a47700 | 3730 | |
b1fc6d3c | 3731 | if (adapter->ahw->pci_func != esw_cfg[i].pci_func) |
e9a47700 RB |
3732 | continue; |
3733 | ||
3734 | op_mode = esw_cfg[i].op_mode; | |
3735 | qlcnic_get_eswitch_port_config(adapter, &esw_cfg[i]); | |
3736 | esw_cfg[i].op_mode = op_mode; | |
b1fc6d3c | 3737 | esw_cfg[i].pci_func = adapter->ahw->pci_func; |
e9a47700 RB |
3738 | |
3739 | switch (esw_cfg[i].op_mode) { | |
3740 | case QLCNIC_PORT_DEFAULTS: | |
3741 | qlcnic_set_eswitch_port_features(adapter, &esw_cfg[i]); | |
3742 | break; | |
8cf61f89 AKS |
3743 | case QLCNIC_ADD_VLAN: |
3744 | qlcnic_set_vlan_config(adapter, &esw_cfg[i]); | |
3745 | break; | |
3746 | case QLCNIC_DEL_VLAN: | |
3747 | esw_cfg[i].vlan_id = 0; | |
3748 | qlcnic_set_vlan_config(adapter, &esw_cfg[i]); | |
3749 | break; | |
0325d69b | 3750 | } |
346fe763 RB |
3751 | } |
3752 | ||
0325d69b RB |
3753 | if (adapter->op_mode != QLCNIC_MGMT_FUNC) |
3754 | goto out; | |
e9a47700 | 3755 | |
346fe763 RB |
3756 | for (i = 0; i < count; i++) { |
3757 | pci_func = esw_cfg[i].pci_func; | |
4e8acb01 RB |
3758 | npar = &adapter->npars[pci_func]; |
3759 | switch (esw_cfg[i].op_mode) { | |
3760 | case QLCNIC_PORT_DEFAULTS: | |
3761 | npar->promisc_mode = esw_cfg[i].promisc_mode; | |
7373373d | 3762 | npar->mac_override = esw_cfg[i].mac_override; |
4e8acb01 RB |
3763 | npar->offload_flags = esw_cfg[i].offload_flags; |
3764 | npar->mac_anti_spoof = esw_cfg[i].mac_anti_spoof; | |
3765 | npar->discard_tagged = esw_cfg[i].discard_tagged; | |
3766 | break; | |
3767 | case QLCNIC_ADD_VLAN: | |
3768 | npar->pvid = esw_cfg[i].vlan_id; | |
3769 | break; | |
3770 | case QLCNIC_DEL_VLAN: | |
3771 | npar->pvid = 0; | |
3772 | break; | |
3773 | } | |
346fe763 | 3774 | } |
0325d69b | 3775 | out: |
346fe763 RB |
3776 | return size; |
3777 | } | |
3778 | ||
3779 | static ssize_t | |
3780 | qlcnic_sysfs_read_esw_config(struct file *file, struct kobject *kobj, | |
3781 | struct bin_attribute *attr, char *buf, loff_t offset, size_t size) | |
3782 | { | |
3783 | struct device *dev = container_of(kobj, struct device, kobj); | |
3784 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); | |
3785 | struct qlcnic_esw_func_cfg esw_cfg[QLCNIC_MAX_PCI_FUNC]; | |
4e8acb01 | 3786 | u8 i; |
346fe763 RB |
3787 | |
3788 | if (size != sizeof(esw_cfg)) | |
3789 | return QL_STATUS_INVALID_PARAM; | |
3790 | ||
3791 | for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) { | |
3792 | if (adapter->npars[i].type != QLCNIC_TYPE_NIC) | |
3793 | continue; | |
4e8acb01 RB |
3794 | esw_cfg[i].pci_func = i; |
3795 | if (qlcnic_get_eswitch_port_config(adapter, &esw_cfg[i])) | |
3796 | return QL_STATUS_INVALID_PARAM; | |
346fe763 RB |
3797 | } |
3798 | memcpy(buf, &esw_cfg, size); | |
3799 | ||
3800 | return size; | |
3801 | } | |
3802 | ||
cea8975e | 3803 | static int |
346fe763 RB |
3804 | validate_npar_config(struct qlcnic_adapter *adapter, |
3805 | struct qlcnic_npar_func_cfg *np_cfg, int count) | |
3806 | { | |
3807 | u8 pci_func, i; | |
3808 | ||
3809 | for (i = 0; i < count; i++) { | |
3810 | pci_func = np_cfg[i].pci_func; | |
3811 | if (pci_func >= QLCNIC_MAX_PCI_FUNC) | |
3812 | return QL_STATUS_INVALID_PARAM; | |
3813 | ||
3814 | if (adapter->npars[pci_func].type != QLCNIC_TYPE_NIC) | |
3815 | return QL_STATUS_INVALID_PARAM; | |
3816 | ||
d12b0d9a RB |
3817 | if (!IS_VALID_BW(np_cfg[i].min_bw) || |
3818 | !IS_VALID_BW(np_cfg[i].max_bw)) | |
346fe763 RB |
3819 | return QL_STATUS_INVALID_PARAM; |
3820 | } | |
3821 | return 0; | |
3822 | } | |
3823 | ||
3824 | static ssize_t | |
3825 | qlcnic_sysfs_write_npar_config(struct file *file, struct kobject *kobj, | |
3826 | struct bin_attribute *attr, char *buf, loff_t offset, size_t size) | |
3827 | { | |
3828 | struct device *dev = container_of(kobj, struct device, kobj); | |
3829 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); | |
3830 | struct qlcnic_info nic_info; | |
3831 | struct qlcnic_npar_func_cfg *np_cfg; | |
3832 | int i, count, rem, ret; | |
3833 | u8 pci_func; | |
3834 | ||
3835 | count = size / sizeof(struct qlcnic_npar_func_cfg); | |
3836 | rem = size % sizeof(struct qlcnic_npar_func_cfg); | |
3837 | if (rem) | |
3838 | return QL_STATUS_INVALID_PARAM; | |
3839 | ||
3840 | np_cfg = (struct qlcnic_npar_func_cfg *) buf; | |
3841 | ret = validate_npar_config(adapter, np_cfg, count); | |
3842 | if (ret) | |
3843 | return ret; | |
3844 | ||
3845 | for (i = 0; i < count ; i++) { | |
3846 | pci_func = np_cfg[i].pci_func; | |
3847 | ret = qlcnic_get_nic_info(adapter, &nic_info, pci_func); | |
3848 | if (ret) | |
3849 | return ret; | |
3850 | nic_info.pci_func = pci_func; | |
3851 | nic_info.min_tx_bw = np_cfg[i].min_bw; | |
3852 | nic_info.max_tx_bw = np_cfg[i].max_bw; | |
3853 | ret = qlcnic_set_nic_info(adapter, &nic_info); | |
3854 | if (ret) | |
3855 | return ret; | |
cea8975e AC |
3856 | adapter->npars[i].min_bw = nic_info.min_tx_bw; |
3857 | adapter->npars[i].max_bw = nic_info.max_tx_bw; | |
346fe763 RB |
3858 | } |
3859 | ||
3860 | return size; | |
3861 | ||
3862 | } | |
3863 | static ssize_t | |
3864 | qlcnic_sysfs_read_npar_config(struct file *file, struct kobject *kobj, | |
3865 | struct bin_attribute *attr, char *buf, loff_t offset, size_t size) | |
3866 | { | |
3867 | struct device *dev = container_of(kobj, struct device, kobj); | |
3868 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); | |
3869 | struct qlcnic_info nic_info; | |
3870 | struct qlcnic_npar_func_cfg np_cfg[QLCNIC_MAX_PCI_FUNC]; | |
3871 | int i, ret; | |
3872 | ||
3873 | if (size != sizeof(np_cfg)) | |
3874 | return QL_STATUS_INVALID_PARAM; | |
3875 | ||
3876 | for (i = 0; i < QLCNIC_MAX_PCI_FUNC ; i++) { | |
3877 | if (adapter->npars[i].type != QLCNIC_TYPE_NIC) | |
3878 | continue; | |
3879 | ret = qlcnic_get_nic_info(adapter, &nic_info, i); | |
3880 | if (ret) | |
3881 | return ret; | |
3882 | ||
3883 | np_cfg[i].pci_func = i; | |
a1c0c459 | 3884 | np_cfg[i].op_mode = (u8)nic_info.op_mode; |
346fe763 RB |
3885 | np_cfg[i].port_num = nic_info.phys_port; |
3886 | np_cfg[i].fw_capab = nic_info.capabilities; | |
3887 | np_cfg[i].min_bw = nic_info.min_tx_bw ; | |
3888 | np_cfg[i].max_bw = nic_info.max_tx_bw; | |
3889 | np_cfg[i].max_tx_queues = nic_info.max_tx_ques; | |
3890 | np_cfg[i].max_rx_queues = nic_info.max_rx_ques; | |
3891 | } | |
3892 | memcpy(buf, &np_cfg, size); | |
3893 | return size; | |
3894 | } | |
3895 | ||
b6021212 AKS |
3896 | static ssize_t |
3897 | qlcnic_sysfs_get_port_stats(struct file *file, struct kobject *kobj, | |
3898 | struct bin_attribute *attr, char *buf, loff_t offset, size_t size) | |
3899 | { | |
3900 | struct device *dev = container_of(kobj, struct device, kobj); | |
3901 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); | |
3902 | struct qlcnic_esw_statistics port_stats; | |
3903 | int ret; | |
3904 | ||
3905 | if (size != sizeof(struct qlcnic_esw_statistics)) | |
3906 | return QL_STATUS_INVALID_PARAM; | |
3907 | ||
3908 | if (offset >= QLCNIC_MAX_PCI_FUNC) | |
3909 | return QL_STATUS_INVALID_PARAM; | |
3910 | ||
3911 | memset(&port_stats, 0, size); | |
3912 | ret = qlcnic_get_port_stats(adapter, offset, QLCNIC_QUERY_RX_COUNTER, | |
3913 | &port_stats.rx); | |
3914 | if (ret) | |
3915 | return ret; | |
3916 | ||
3917 | ret = qlcnic_get_port_stats(adapter, offset, QLCNIC_QUERY_TX_COUNTER, | |
3918 | &port_stats.tx); | |
3919 | if (ret) | |
3920 | return ret; | |
3921 | ||
3922 | memcpy(buf, &port_stats, size); | |
3923 | return size; | |
3924 | } | |
3925 | ||
3926 | static ssize_t | |
3927 | qlcnic_sysfs_get_esw_stats(struct file *file, struct kobject *kobj, | |
3928 | struct bin_attribute *attr, char *buf, loff_t offset, size_t size) | |
3929 | { | |
3930 | struct device *dev = container_of(kobj, struct device, kobj); | |
3931 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); | |
3932 | struct qlcnic_esw_statistics esw_stats; | |
3933 | int ret; | |
3934 | ||
3935 | if (size != sizeof(struct qlcnic_esw_statistics)) | |
3936 | return QL_STATUS_INVALID_PARAM; | |
3937 | ||
3938 | if (offset >= QLCNIC_NIU_MAX_XG_PORTS) | |
3939 | return QL_STATUS_INVALID_PARAM; | |
3940 | ||
3941 | memset(&esw_stats, 0, size); | |
3942 | ret = qlcnic_get_eswitch_stats(adapter, offset, QLCNIC_QUERY_RX_COUNTER, | |
3943 | &esw_stats.rx); | |
3944 | if (ret) | |
3945 | return ret; | |
3946 | ||
3947 | ret = qlcnic_get_eswitch_stats(adapter, offset, QLCNIC_QUERY_TX_COUNTER, | |
3948 | &esw_stats.tx); | |
3949 | if (ret) | |
3950 | return ret; | |
3951 | ||
3952 | memcpy(buf, &esw_stats, size); | |
3953 | return size; | |
3954 | } | |
3955 | ||
3956 | static ssize_t | |
3957 | qlcnic_sysfs_clear_esw_stats(struct file *file, struct kobject *kobj, | |
3958 | struct bin_attribute *attr, char *buf, loff_t offset, size_t size) | |
3959 | { | |
3960 | struct device *dev = container_of(kobj, struct device, kobj); | |
3961 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); | |
3962 | int ret; | |
3963 | ||
3964 | if (offset >= QLCNIC_NIU_MAX_XG_PORTS) | |
3965 | return QL_STATUS_INVALID_PARAM; | |
3966 | ||
3967 | ret = qlcnic_clear_esw_stats(adapter, QLCNIC_STATS_ESWITCH, offset, | |
3968 | QLCNIC_QUERY_RX_COUNTER); | |
3969 | if (ret) | |
3970 | return ret; | |
3971 | ||
3972 | ret = qlcnic_clear_esw_stats(adapter, QLCNIC_STATS_ESWITCH, offset, | |
3973 | QLCNIC_QUERY_TX_COUNTER); | |
3974 | if (ret) | |
3975 | return ret; | |
3976 | ||
3977 | return size; | |
3978 | } | |
3979 | ||
3980 | static ssize_t | |
3981 | qlcnic_sysfs_clear_port_stats(struct file *file, struct kobject *kobj, | |
3982 | struct bin_attribute *attr, char *buf, loff_t offset, size_t size) | |
3983 | { | |
3984 | ||
3985 | struct device *dev = container_of(kobj, struct device, kobj); | |
3986 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); | |
3987 | int ret; | |
3988 | ||
3989 | if (offset >= QLCNIC_MAX_PCI_FUNC) | |
3990 | return QL_STATUS_INVALID_PARAM; | |
3991 | ||
3992 | ret = qlcnic_clear_esw_stats(adapter, QLCNIC_STATS_PORT, offset, | |
3993 | QLCNIC_QUERY_RX_COUNTER); | |
3994 | if (ret) | |
3995 | return ret; | |
3996 | ||
3997 | ret = qlcnic_clear_esw_stats(adapter, QLCNIC_STATS_PORT, offset, | |
3998 | QLCNIC_QUERY_TX_COUNTER); | |
3999 | if (ret) | |
4000 | return ret; | |
4001 | ||
4002 | return size; | |
4003 | } | |
4004 | ||
346fe763 RB |
4005 | static ssize_t |
4006 | qlcnic_sysfs_read_pci_config(struct file *file, struct kobject *kobj, | |
4007 | struct bin_attribute *attr, char *buf, loff_t offset, size_t size) | |
4008 | { | |
4009 | struct device *dev = container_of(kobj, struct device, kobj); | |
4010 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); | |
4011 | struct qlcnic_pci_func_cfg pci_cfg[QLCNIC_MAX_PCI_FUNC]; | |
e88db3bd | 4012 | struct qlcnic_pci_info *pci_info; |
346fe763 RB |
4013 | int i, ret; |
4014 | ||
4015 | if (size != sizeof(pci_cfg)) | |
4016 | return QL_STATUS_INVALID_PARAM; | |
4017 | ||
e88db3bd DC |
4018 | pci_info = kcalloc(QLCNIC_MAX_PCI_FUNC, sizeof(*pci_info), GFP_KERNEL); |
4019 | if (!pci_info) | |
4020 | return -ENOMEM; | |
4021 | ||
346fe763 | 4022 | ret = qlcnic_get_pci_info(adapter, pci_info); |
e88db3bd DC |
4023 | if (ret) { |
4024 | kfree(pci_info); | |
346fe763 | 4025 | return ret; |
e88db3bd | 4026 | } |
346fe763 RB |
4027 | |
4028 | for (i = 0; i < QLCNIC_MAX_PCI_FUNC ; i++) { | |
4029 | pci_cfg[i].pci_func = pci_info[i].id; | |
4030 | pci_cfg[i].func_type = pci_info[i].type; | |
4031 | pci_cfg[i].port_num = pci_info[i].default_port; | |
4032 | pci_cfg[i].min_bw = pci_info[i].tx_min_bw; | |
4033 | pci_cfg[i].max_bw = pci_info[i].tx_max_bw; | |
4034 | memcpy(&pci_cfg[i].def_mac_addr, &pci_info[i].mac, ETH_ALEN); | |
4035 | } | |
4036 | memcpy(buf, &pci_cfg, size); | |
e88db3bd | 4037 | kfree(pci_info); |
346fe763 | 4038 | return size; |
346fe763 RB |
4039 | } |
4040 | static struct bin_attribute bin_attr_npar_config = { | |
4041 | .attr = {.name = "npar_config", .mode = (S_IRUGO | S_IWUSR)}, | |
4042 | .size = 0, | |
4043 | .read = qlcnic_sysfs_read_npar_config, | |
4044 | .write = qlcnic_sysfs_write_npar_config, | |
4045 | }; | |
4046 | ||
4047 | static struct bin_attribute bin_attr_pci_config = { | |
4048 | .attr = {.name = "pci_config", .mode = (S_IRUGO | S_IWUSR)}, | |
4049 | .size = 0, | |
4050 | .read = qlcnic_sysfs_read_pci_config, | |
4051 | .write = NULL, | |
4052 | }; | |
4053 | ||
b6021212 AKS |
4054 | static struct bin_attribute bin_attr_port_stats = { |
4055 | .attr = {.name = "port_stats", .mode = (S_IRUGO | S_IWUSR)}, | |
4056 | .size = 0, | |
4057 | .read = qlcnic_sysfs_get_port_stats, | |
4058 | .write = qlcnic_sysfs_clear_port_stats, | |
4059 | }; | |
4060 | ||
4061 | static struct bin_attribute bin_attr_esw_stats = { | |
4062 | .attr = {.name = "esw_stats", .mode = (S_IRUGO | S_IWUSR)}, | |
4063 | .size = 0, | |
4064 | .read = qlcnic_sysfs_get_esw_stats, | |
4065 | .write = qlcnic_sysfs_clear_esw_stats, | |
4066 | }; | |
4067 | ||
346fe763 RB |
4068 | static struct bin_attribute bin_attr_esw_config = { |
4069 | .attr = {.name = "esw_config", .mode = (S_IRUGO | S_IWUSR)}, | |
4070 | .size = 0, | |
4071 | .read = qlcnic_sysfs_read_esw_config, | |
4072 | .write = qlcnic_sysfs_write_esw_config, | |
4073 | }; | |
4074 | ||
4075 | static struct bin_attribute bin_attr_pm_config = { | |
4076 | .attr = {.name = "pm_config", .mode = (S_IRUGO | S_IWUSR)}, | |
4077 | .size = 0, | |
4078 | .read = qlcnic_sysfs_read_pm_config, | |
4079 | .write = qlcnic_sysfs_write_pm_config, | |
4080 | }; | |
4081 | ||
af19b491 AKS |
4082 | static void |
4083 | qlcnic_create_sysfs_entries(struct qlcnic_adapter *adapter) | |
4084 | { | |
4085 | struct device *dev = &adapter->pdev->dev; | |
4086 | ||
4087 | if (adapter->capabilities & QLCNIC_FW_CAPABILITY_BDG) | |
4088 | if (device_create_file(dev, &dev_attr_bridged_mode)) | |
4089 | dev_warn(dev, | |
4090 | "failed to create bridged_mode sysfs entry\n"); | |
4091 | } | |
4092 | ||
4093 | static void | |
4094 | qlcnic_remove_sysfs_entries(struct qlcnic_adapter *adapter) | |
4095 | { | |
4096 | struct device *dev = &adapter->pdev->dev; | |
4097 | ||
4098 | if (adapter->capabilities & QLCNIC_FW_CAPABILITY_BDG) | |
4099 | device_remove_file(dev, &dev_attr_bridged_mode); | |
4100 | } | |
4101 | ||
4102 | static void | |
4103 | qlcnic_create_diag_entries(struct qlcnic_adapter *adapter) | |
4104 | { | |
4105 | struct device *dev = &adapter->pdev->dev; | |
4106 | ||
b6021212 AKS |
4107 | if (device_create_bin_file(dev, &bin_attr_port_stats)) |
4108 | dev_info(dev, "failed to create port stats sysfs entry"); | |
4109 | ||
132ff00a AC |
4110 | if (adapter->op_mode == QLCNIC_NON_PRIV_FUNC) |
4111 | return; | |
af19b491 AKS |
4112 | if (device_create_file(dev, &dev_attr_diag_mode)) |
4113 | dev_info(dev, "failed to create diag_mode sysfs entry\n"); | |
4114 | if (device_create_bin_file(dev, &bin_attr_crb)) | |
4115 | dev_info(dev, "failed to create crb sysfs entry\n"); | |
4116 | if (device_create_bin_file(dev, &bin_attr_mem)) | |
4117 | dev_info(dev, "failed to create mem sysfs entry\n"); | |
53478fef SC |
4118 | if (device_create_bin_file(dev, &bin_attr_pci_config)) |
4119 | dev_info(dev, "failed to create pci config sysfs entry"); | |
4e8acb01 RB |
4120 | if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED)) |
4121 | return; | |
4122 | if (device_create_bin_file(dev, &bin_attr_esw_config)) | |
4123 | dev_info(dev, "failed to create esw config sysfs entry"); | |
4124 | if (adapter->op_mode != QLCNIC_MGMT_FUNC) | |
346fe763 | 4125 | return; |
346fe763 RB |
4126 | if (device_create_bin_file(dev, &bin_attr_npar_config)) |
4127 | dev_info(dev, "failed to create npar config sysfs entry"); | |
346fe763 RB |
4128 | if (device_create_bin_file(dev, &bin_attr_pm_config)) |
4129 | dev_info(dev, "failed to create pm config sysfs entry"); | |
b6021212 AKS |
4130 | if (device_create_bin_file(dev, &bin_attr_esw_stats)) |
4131 | dev_info(dev, "failed to create eswitch stats sysfs entry"); | |
af19b491 AKS |
4132 | } |
4133 | ||
af19b491 AKS |
4134 | static void |
4135 | qlcnic_remove_diag_entries(struct qlcnic_adapter *adapter) | |
4136 | { | |
4137 | struct device *dev = &adapter->pdev->dev; | |
4138 | ||
b6021212 AKS |
4139 | device_remove_bin_file(dev, &bin_attr_port_stats); |
4140 | ||
132ff00a AC |
4141 | if (adapter->op_mode == QLCNIC_NON_PRIV_FUNC) |
4142 | return; | |
af19b491 AKS |
4143 | device_remove_file(dev, &dev_attr_diag_mode); |
4144 | device_remove_bin_file(dev, &bin_attr_crb); | |
4145 | device_remove_bin_file(dev, &bin_attr_mem); | |
53478fef | 4146 | device_remove_bin_file(dev, &bin_attr_pci_config); |
4e8acb01 RB |
4147 | if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED)) |
4148 | return; | |
4149 | device_remove_bin_file(dev, &bin_attr_esw_config); | |
4150 | if (adapter->op_mode != QLCNIC_MGMT_FUNC) | |
346fe763 | 4151 | return; |
346fe763 | 4152 | device_remove_bin_file(dev, &bin_attr_npar_config); |
346fe763 | 4153 | device_remove_bin_file(dev, &bin_attr_pm_config); |
b6021212 | 4154 | device_remove_bin_file(dev, &bin_attr_esw_stats); |
af19b491 AKS |
4155 | } |
4156 | ||
4157 | #ifdef CONFIG_INET | |
4158 | ||
4159 | #define is_qlcnic_netdev(dev) (dev->netdev_ops == &qlcnic_netdev_ops) | |
4160 | ||
af19b491 | 4161 | static void |
aec1e845 AKS |
4162 | qlcnic_config_indev_addr(struct qlcnic_adapter *adapter, |
4163 | struct net_device *dev, unsigned long event) | |
af19b491 AKS |
4164 | { |
4165 | struct in_device *indev; | |
af19b491 | 4166 | |
af19b491 AKS |
4167 | indev = in_dev_get(dev); |
4168 | if (!indev) | |
4169 | return; | |
4170 | ||
4171 | for_ifa(indev) { | |
4172 | switch (event) { | |
4173 | case NETDEV_UP: | |
4174 | qlcnic_config_ipaddr(adapter, | |
4175 | ifa->ifa_address, QLCNIC_IP_UP); | |
4176 | break; | |
4177 | case NETDEV_DOWN: | |
4178 | qlcnic_config_ipaddr(adapter, | |
4179 | ifa->ifa_address, QLCNIC_IP_DOWN); | |
4180 | break; | |
4181 | default: | |
4182 | break; | |
4183 | } | |
4184 | } endfor_ifa(indev); | |
4185 | ||
4186 | in_dev_put(indev); | |
af19b491 AKS |
4187 | } |
4188 | ||
aec1e845 AKS |
4189 | static void |
4190 | qlcnic_restore_indev_addr(struct net_device *netdev, unsigned long event) | |
4191 | { | |
4192 | struct qlcnic_adapter *adapter = netdev_priv(netdev); | |
4193 | struct net_device *dev; | |
4194 | u16 vid; | |
4195 | ||
4196 | qlcnic_config_indev_addr(adapter, netdev, event); | |
4197 | ||
b9796a14 AC |
4198 | for_each_set_bit(vid, adapter->vlans, VLAN_N_VID) { |
4199 | dev = vlan_find_dev(netdev, vid); | |
aec1e845 AKS |
4200 | if (!dev) |
4201 | continue; | |
aec1e845 AKS |
4202 | qlcnic_config_indev_addr(adapter, dev, event); |
4203 | } | |
4204 | } | |
4205 | ||
af19b491 AKS |
4206 | static int qlcnic_netdev_event(struct notifier_block *this, |
4207 | unsigned long event, void *ptr) | |
4208 | { | |
4209 | struct qlcnic_adapter *adapter; | |
4210 | struct net_device *dev = (struct net_device *)ptr; | |
4211 | ||
4212 | recheck: | |
4213 | if (dev == NULL) | |
4214 | goto done; | |
4215 | ||
4216 | if (dev->priv_flags & IFF_802_1Q_VLAN) { | |
4217 | dev = vlan_dev_real_dev(dev); | |
4218 | goto recheck; | |
4219 | } | |
4220 | ||
4221 | if (!is_qlcnic_netdev(dev)) | |
4222 | goto done; | |
4223 | ||
4224 | adapter = netdev_priv(dev); | |
4225 | ||
4226 | if (!adapter) | |
4227 | goto done; | |
4228 | ||
8a15ad1f | 4229 | if (!test_bit(__QLCNIC_DEV_UP, &adapter->state)) |
af19b491 AKS |
4230 | goto done; |
4231 | ||
aec1e845 | 4232 | qlcnic_config_indev_addr(adapter, dev, event); |
af19b491 AKS |
4233 | done: |
4234 | return NOTIFY_DONE; | |
4235 | } | |
4236 | ||
4237 | static int | |
4238 | qlcnic_inetaddr_event(struct notifier_block *this, | |
4239 | unsigned long event, void *ptr) | |
4240 | { | |
4241 | struct qlcnic_adapter *adapter; | |
4242 | struct net_device *dev; | |
4243 | ||
4244 | struct in_ifaddr *ifa = (struct in_ifaddr *)ptr; | |
4245 | ||
4246 | dev = ifa->ifa_dev ? ifa->ifa_dev->dev : NULL; | |
4247 | ||
4248 | recheck: | |
aec1e845 | 4249 | if (dev == NULL) |
af19b491 AKS |
4250 | goto done; |
4251 | ||
4252 | if (dev->priv_flags & IFF_802_1Q_VLAN) { | |
4253 | dev = vlan_dev_real_dev(dev); | |
4254 | goto recheck; | |
4255 | } | |
4256 | ||
4257 | if (!is_qlcnic_netdev(dev)) | |
4258 | goto done; | |
4259 | ||
4260 | adapter = netdev_priv(dev); | |
4261 | ||
251a84c9 | 4262 | if (!adapter) |
af19b491 AKS |
4263 | goto done; |
4264 | ||
8a15ad1f | 4265 | if (!test_bit(__QLCNIC_DEV_UP, &adapter->state)) |
af19b491 AKS |
4266 | goto done; |
4267 | ||
4268 | switch (event) { | |
4269 | case NETDEV_UP: | |
4270 | qlcnic_config_ipaddr(adapter, ifa->ifa_address, QLCNIC_IP_UP); | |
4271 | break; | |
4272 | case NETDEV_DOWN: | |
4273 | qlcnic_config_ipaddr(adapter, ifa->ifa_address, QLCNIC_IP_DOWN); | |
4274 | break; | |
4275 | default: | |
4276 | break; | |
4277 | } | |
4278 | ||
4279 | done: | |
4280 | return NOTIFY_DONE; | |
4281 | } | |
4282 | ||
4283 | static struct notifier_block qlcnic_netdev_cb = { | |
4284 | .notifier_call = qlcnic_netdev_event, | |
4285 | }; | |
4286 | ||
4287 | static struct notifier_block qlcnic_inetaddr_cb = { | |
4288 | .notifier_call = qlcnic_inetaddr_event, | |
4289 | }; | |
4290 | #else | |
4291 | static void | |
aec1e845 | 4292 | qlcnic_restore_indev_addr(struct net_device *dev, unsigned long event) |
af19b491 AKS |
4293 | { } |
4294 | #endif | |
451724c8 SC |
4295 | static struct pci_error_handlers qlcnic_err_handler = { |
4296 | .error_detected = qlcnic_io_error_detected, | |
4297 | .slot_reset = qlcnic_io_slot_reset, | |
4298 | .resume = qlcnic_io_resume, | |
4299 | }; | |
af19b491 AKS |
4300 | |
4301 | static struct pci_driver qlcnic_driver = { | |
4302 | .name = qlcnic_driver_name, | |
4303 | .id_table = qlcnic_pci_tbl, | |
4304 | .probe = qlcnic_probe, | |
4305 | .remove = __devexit_p(qlcnic_remove), | |
4306 | #ifdef CONFIG_PM | |
4307 | .suspend = qlcnic_suspend, | |
4308 | .resume = qlcnic_resume, | |
4309 | #endif | |
451724c8 SC |
4310 | .shutdown = qlcnic_shutdown, |
4311 | .err_handler = &qlcnic_err_handler | |
4312 | ||
af19b491 AKS |
4313 | }; |
4314 | ||
4315 | static int __init qlcnic_init_module(void) | |
4316 | { | |
0cf3a14c | 4317 | int ret; |
af19b491 AKS |
4318 | |
4319 | printk(KERN_INFO "%s\n", qlcnic_driver_string); | |
4320 | ||
f7ec804a AKS |
4321 | qlcnic_wq = create_singlethread_workqueue("qlcnic"); |
4322 | if (qlcnic_wq == NULL) { | |
4323 | printk(KERN_ERR "qlcnic: cannot create workqueue\n"); | |
4324 | return -ENOMEM; | |
4325 | } | |
4326 | ||
af19b491 AKS |
4327 | #ifdef CONFIG_INET |
4328 | register_netdevice_notifier(&qlcnic_netdev_cb); | |
4329 | register_inetaddr_notifier(&qlcnic_inetaddr_cb); | |
4330 | #endif | |
4331 | ||
0cf3a14c AKS |
4332 | ret = pci_register_driver(&qlcnic_driver); |
4333 | if (ret) { | |
4334 | #ifdef CONFIG_INET | |
4335 | unregister_inetaddr_notifier(&qlcnic_inetaddr_cb); | |
4336 | unregister_netdevice_notifier(&qlcnic_netdev_cb); | |
4337 | #endif | |
f7ec804a | 4338 | destroy_workqueue(qlcnic_wq); |
0cf3a14c | 4339 | } |
af19b491 | 4340 | |
0cf3a14c | 4341 | return ret; |
af19b491 AKS |
4342 | } |
4343 | ||
4344 | module_init(qlcnic_init_module); | |
4345 | ||
4346 | static void __exit qlcnic_exit_module(void) | |
4347 | { | |
4348 | ||
4349 | pci_unregister_driver(&qlcnic_driver); | |
4350 | ||
4351 | #ifdef CONFIG_INET | |
4352 | unregister_inetaddr_notifier(&qlcnic_inetaddr_cb); | |
4353 | unregister_netdevice_notifier(&qlcnic_netdev_cb); | |
4354 | #endif | |
f7ec804a | 4355 | destroy_workqueue(qlcnic_wq); |
af19b491 AKS |
4356 | } |
4357 | ||
4358 | module_exit(qlcnic_exit_module); |