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