]>
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> | |
37 | ||
7f9a0c34 | 38 | MODULE_DESCRIPTION("QLogic 1/10 GbE Converged/Intelligent Ethernet Driver"); |
af19b491 AKS |
39 | MODULE_LICENSE("GPL"); |
40 | MODULE_VERSION(QLCNIC_LINUX_VERSIONID); | |
41 | MODULE_FIRMWARE(QLCNIC_UNIFIED_ROMIMAGE_NAME); | |
42 | ||
43 | char qlcnic_driver_name[] = "qlcnic"; | |
7f9a0c34 SV |
44 | static const char qlcnic_driver_string[] = "QLogic 1/10 GbE " |
45 | "Converged/Intelligent Ethernet Driver v" QLCNIC_LINUX_VERSIONID; | |
af19b491 AKS |
46 | |
47 | static int port_mode = QLCNIC_PORT_MODE_AUTO_NEG; | |
48 | ||
49 | /* Default to restricted 1G auto-neg mode */ | |
50 | static int wol_port_mode = 5; | |
51 | ||
52 | static int use_msi = 1; | |
53 | module_param(use_msi, int, 0644); | |
54 | MODULE_PARM_DESC(use_msi, "MSI interrupt (0=disabled, 1=enabled"); | |
55 | ||
56 | static int use_msi_x = 1; | |
57 | module_param(use_msi_x, int, 0644); | |
58 | MODULE_PARM_DESC(use_msi_x, "MSI-X interrupt (0=disabled, 1=enabled"); | |
59 | ||
60 | static int auto_fw_reset = AUTO_FW_RESET_ENABLED; | |
61 | module_param(auto_fw_reset, int, 0644); | |
62 | MODULE_PARM_DESC(auto_fw_reset, "Auto firmware reset (0=disabled, 1=enabled"); | |
63 | ||
4d5bdb38 AKS |
64 | static int load_fw_file; |
65 | module_param(load_fw_file, int, 0644); | |
66 | MODULE_PARM_DESC(load_fw_file, "Load firmware from (0=flash, 1=file"); | |
67 | ||
2e9d722d AC |
68 | static int qlcnic_config_npars; |
69 | module_param(qlcnic_config_npars, int, 0644); | |
70 | MODULE_PARM_DESC(qlcnic_config_npars, "Configure NPARs (0=disabled, 1=enabled"); | |
71 | ||
af19b491 AKS |
72 | static int __devinit qlcnic_probe(struct pci_dev *pdev, |
73 | const struct pci_device_id *ent); | |
74 | static void __devexit qlcnic_remove(struct pci_dev *pdev); | |
75 | static int qlcnic_open(struct net_device *netdev); | |
76 | static int qlcnic_close(struct net_device *netdev); | |
af19b491 AKS |
77 | static void qlcnic_tx_timeout(struct net_device *netdev); |
78 | static void qlcnic_tx_timeout_task(struct work_struct *work); | |
79 | static void qlcnic_attach_work(struct work_struct *work); | |
80 | static void qlcnic_fwinit_work(struct work_struct *work); | |
81 | static void qlcnic_fw_poll_work(struct work_struct *work); | |
82 | static void qlcnic_schedule_work(struct qlcnic_adapter *adapter, | |
83 | work_func_t func, int delay); | |
84 | static void qlcnic_cancel_fw_work(struct qlcnic_adapter *adapter); | |
85 | static int qlcnic_poll(struct napi_struct *napi, int budget); | |
86 | #ifdef CONFIG_NET_POLL_CONTROLLER | |
87 | static void qlcnic_poll_controller(struct net_device *netdev); | |
88 | #endif | |
89 | ||
90 | static void qlcnic_create_sysfs_entries(struct qlcnic_adapter *adapter); | |
91 | static void qlcnic_remove_sysfs_entries(struct qlcnic_adapter *adapter); | |
92 | static void qlcnic_create_diag_entries(struct qlcnic_adapter *adapter); | |
93 | static void qlcnic_remove_diag_entries(struct qlcnic_adapter *adapter); | |
94 | ||
6df900e9 | 95 | static void qlcnic_idc_debug_info(struct qlcnic_adapter *adapter, u8 encoding); |
af19b491 AKS |
96 | static void qlcnic_clr_all_drv_state(struct qlcnic_adapter *adapter); |
97 | static int qlcnic_can_start_firmware(struct qlcnic_adapter *adapter); | |
98 | ||
7eb9855d | 99 | static irqreturn_t qlcnic_tmp_intr(int irq, void *data); |
af19b491 AKS |
100 | static irqreturn_t qlcnic_intr(int irq, void *data); |
101 | static irqreturn_t qlcnic_msi_intr(int irq, void *data); | |
102 | static irqreturn_t qlcnic_msix_intr(int irq, void *data); | |
103 | ||
104 | static struct net_device_stats *qlcnic_get_stats(struct net_device *netdev); | |
105 | static void qlcnic_config_indev_addr(struct net_device *dev, unsigned long); | |
9f26f547 AC |
106 | static int qlcnic_start_firmware(struct qlcnic_adapter *); |
107 | ||
108 | static void qlcnic_dev_set_npar_ready(struct qlcnic_adapter *); | |
109 | static void qlcnicvf_clear_ilb_mode(struct qlcnic_adapter *); | |
110 | static int qlcnicvf_set_ilb_mode(struct qlcnic_adapter *); | |
111 | static int qlcnicvf_config_led(struct qlcnic_adapter *, u32, u32); | |
112 | static int qlcnicvf_config_bridged_mode(struct qlcnic_adapter *, u32); | |
113 | static int qlcnicvf_start_firmware(struct qlcnic_adapter *); | |
af19b491 AKS |
114 | /* PCI Device ID Table */ |
115 | #define ENTRY(device) \ | |
116 | {PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, (device)), \ | |
117 | .class = PCI_CLASS_NETWORK_ETHERNET << 8, .class_mask = ~0} | |
118 | ||
119 | #define PCI_DEVICE_ID_QLOGIC_QLE824X 0x8020 | |
120 | ||
6a902881 | 121 | static DEFINE_PCI_DEVICE_TABLE(qlcnic_pci_tbl) = { |
af19b491 AKS |
122 | ENTRY(PCI_DEVICE_ID_QLOGIC_QLE824X), |
123 | {0,} | |
124 | }; | |
125 | ||
126 | MODULE_DEVICE_TABLE(pci, qlcnic_pci_tbl); | |
127 | ||
128 | ||
129 | void | |
130 | qlcnic_update_cmd_producer(struct qlcnic_adapter *adapter, | |
131 | struct qlcnic_host_tx_ring *tx_ring) | |
132 | { | |
133 | writel(tx_ring->producer, tx_ring->crb_cmd_producer); | |
134 | ||
135 | if (qlcnic_tx_avail(tx_ring) <= TX_STOP_THRESH) { | |
136 | netif_stop_queue(adapter->netdev); | |
137 | smp_mb(); | |
8bfe8b91 | 138 | adapter->stats.xmit_off++; |
af19b491 AKS |
139 | } |
140 | } | |
141 | ||
142 | static const u32 msi_tgt_status[8] = { | |
143 | ISR_INT_TARGET_STATUS, ISR_INT_TARGET_STATUS_F1, | |
144 | ISR_INT_TARGET_STATUS_F2, ISR_INT_TARGET_STATUS_F3, | |
145 | ISR_INT_TARGET_STATUS_F4, ISR_INT_TARGET_STATUS_F5, | |
146 | ISR_INT_TARGET_STATUS_F6, ISR_INT_TARGET_STATUS_F7 | |
147 | }; | |
148 | ||
149 | static const | |
150 | struct qlcnic_legacy_intr_set legacy_intr[] = QLCNIC_LEGACY_INTR_CONFIG; | |
151 | ||
152 | static inline void qlcnic_disable_int(struct qlcnic_host_sds_ring *sds_ring) | |
153 | { | |
154 | writel(0, sds_ring->crb_intr_mask); | |
155 | } | |
156 | ||
157 | static inline void qlcnic_enable_int(struct qlcnic_host_sds_ring *sds_ring) | |
158 | { | |
159 | struct qlcnic_adapter *adapter = sds_ring->adapter; | |
160 | ||
161 | writel(0x1, sds_ring->crb_intr_mask); | |
162 | ||
163 | if (!QLCNIC_IS_MSI_FAMILY(adapter)) | |
164 | writel(0xfbff, adapter->tgt_mask_reg); | |
165 | } | |
166 | ||
167 | static int | |
168 | qlcnic_alloc_sds_rings(struct qlcnic_recv_context *recv_ctx, int count) | |
169 | { | |
170 | int size = sizeof(struct qlcnic_host_sds_ring) * count; | |
171 | ||
172 | recv_ctx->sds_rings = kzalloc(size, GFP_KERNEL); | |
173 | ||
174 | return (recv_ctx->sds_rings == NULL); | |
175 | } | |
176 | ||
177 | static void | |
178 | qlcnic_free_sds_rings(struct qlcnic_recv_context *recv_ctx) | |
179 | { | |
180 | if (recv_ctx->sds_rings != NULL) | |
181 | kfree(recv_ctx->sds_rings); | |
182 | ||
183 | recv_ctx->sds_rings = NULL; | |
184 | } | |
185 | ||
186 | static int | |
187 | qlcnic_napi_add(struct qlcnic_adapter *adapter, struct net_device *netdev) | |
188 | { | |
189 | int ring; | |
190 | struct qlcnic_host_sds_ring *sds_ring; | |
191 | struct qlcnic_recv_context *recv_ctx = &adapter->recv_ctx; | |
192 | ||
193 | if (qlcnic_alloc_sds_rings(recv_ctx, adapter->max_sds_rings)) | |
194 | return -ENOMEM; | |
195 | ||
196 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { | |
197 | sds_ring = &recv_ctx->sds_rings[ring]; | |
198 | netif_napi_add(netdev, &sds_ring->napi, | |
199 | qlcnic_poll, QLCNIC_NETDEV_WEIGHT); | |
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 | ||
2e9d722d | 325 | if (adapter->nic_ops->get_mac_addr(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 | ||
349 | if (netif_running(netdev)) { | |
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 | ||
358 | if (netif_running(netdev)) { | |
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 AC |
380 | static struct qlcnic_nic_template qlcnic_ops = { |
381 | .get_mac_addr = qlcnic_get_mac_addr, | |
382 | .config_bridged_mode = qlcnic_config_bridged_mode, | |
383 | .config_led = qlcnic_config_led, | |
384 | .set_ilb_mode = qlcnic_set_ilb_mode, | |
9f26f547 AC |
385 | .clear_ilb_mode = qlcnic_clear_ilb_mode, |
386 | .start_firmware = qlcnic_start_firmware | |
2e9d722d AC |
387 | }; |
388 | ||
389 | static struct qlcnic_nic_template qlcnic_pf_ops = { | |
390 | .get_mac_addr = qlcnic_get_mac_address, | |
391 | .config_bridged_mode = qlcnic_config_bridged_mode, | |
392 | .config_led = qlcnic_config_led, | |
393 | .set_ilb_mode = qlcnic_set_ilb_mode, | |
9f26f547 AC |
394 | .clear_ilb_mode = qlcnic_clear_ilb_mode, |
395 | .start_firmware = qlcnic_start_firmware | |
396 | }; | |
397 | ||
398 | static struct qlcnic_nic_template qlcnic_vf_ops = { | |
399 | .get_mac_addr = qlcnic_get_mac_address, | |
400 | .config_bridged_mode = qlcnicvf_config_bridged_mode, | |
401 | .config_led = qlcnicvf_config_led, | |
402 | .set_ilb_mode = qlcnicvf_set_ilb_mode, | |
403 | .clear_ilb_mode = qlcnicvf_clear_ilb_mode, | |
404 | .start_firmware = qlcnicvf_start_firmware | |
2e9d722d AC |
405 | }; |
406 | ||
af19b491 AKS |
407 | static void |
408 | qlcnic_setup_intr(struct qlcnic_adapter *adapter) | |
409 | { | |
410 | const struct qlcnic_legacy_intr_set *legacy_intrp; | |
411 | struct pci_dev *pdev = adapter->pdev; | |
412 | int err, num_msix; | |
413 | ||
414 | if (adapter->rss_supported) { | |
415 | num_msix = (num_online_cpus() >= MSIX_ENTRIES_PER_ADAPTER) ? | |
416 | MSIX_ENTRIES_PER_ADAPTER : 2; | |
417 | } else | |
418 | num_msix = 1; | |
419 | ||
420 | adapter->max_sds_rings = 1; | |
421 | ||
422 | adapter->flags &= ~(QLCNIC_MSI_ENABLED | QLCNIC_MSIX_ENABLED); | |
423 | ||
424 | legacy_intrp = &legacy_intr[adapter->ahw.pci_func]; | |
425 | ||
426 | adapter->int_vec_bit = legacy_intrp->int_vec_bit; | |
427 | adapter->tgt_status_reg = qlcnic_get_ioaddr(adapter, | |
428 | legacy_intrp->tgt_status_reg); | |
429 | adapter->tgt_mask_reg = qlcnic_get_ioaddr(adapter, | |
430 | legacy_intrp->tgt_mask_reg); | |
431 | adapter->isr_int_vec = qlcnic_get_ioaddr(adapter, ISR_INT_VECTOR); | |
432 | ||
433 | adapter->crb_int_state_reg = qlcnic_get_ioaddr(adapter, | |
434 | ISR_INT_STATE_REG); | |
435 | ||
436 | qlcnic_set_msix_bit(pdev, 0); | |
437 | ||
438 | if (adapter->msix_supported) { | |
439 | ||
440 | qlcnic_init_msix_entries(adapter, num_msix); | |
441 | err = pci_enable_msix(pdev, adapter->msix_entries, num_msix); | |
442 | if (err == 0) { | |
443 | adapter->flags |= QLCNIC_MSIX_ENABLED; | |
444 | qlcnic_set_msix_bit(pdev, 1); | |
445 | ||
446 | if (adapter->rss_supported) | |
447 | adapter->max_sds_rings = num_msix; | |
448 | ||
449 | dev_info(&pdev->dev, "using msi-x interrupts\n"); | |
450 | return; | |
451 | } | |
452 | ||
453 | if (err > 0) | |
454 | pci_disable_msix(pdev); | |
455 | ||
456 | /* fall through for msi */ | |
457 | } | |
458 | ||
459 | if (use_msi && !pci_enable_msi(pdev)) { | |
460 | adapter->flags |= QLCNIC_MSI_ENABLED; | |
461 | adapter->tgt_status_reg = qlcnic_get_ioaddr(adapter, | |
462 | msi_tgt_status[adapter->ahw.pci_func]); | |
463 | dev_info(&pdev->dev, "using msi interrupts\n"); | |
464 | adapter->msix_entries[0].vector = pdev->irq; | |
465 | return; | |
466 | } | |
467 | ||
468 | dev_info(&pdev->dev, "using legacy interrupts\n"); | |
469 | adapter->msix_entries[0].vector = pdev->irq; | |
470 | } | |
471 | ||
472 | static void | |
473 | qlcnic_teardown_intr(struct qlcnic_adapter *adapter) | |
474 | { | |
475 | if (adapter->flags & QLCNIC_MSIX_ENABLED) | |
476 | pci_disable_msix(adapter->pdev); | |
477 | if (adapter->flags & QLCNIC_MSI_ENABLED) | |
478 | pci_disable_msi(adapter->pdev); | |
479 | } | |
480 | ||
481 | static void | |
482 | qlcnic_cleanup_pci_map(struct qlcnic_adapter *adapter) | |
483 | { | |
484 | if (adapter->ahw.pci_base0 != NULL) | |
485 | iounmap(adapter->ahw.pci_base0); | |
486 | } | |
487 | ||
2e9d722d AC |
488 | static int |
489 | qlcnic_set_function_modes(struct qlcnic_adapter *adapter) | |
490 | { | |
491 | u8 id; | |
492 | u32 ref_count; | |
493 | int i, ret = 1; | |
494 | u32 data = QLCNIC_MGMT_FUNC; | |
495 | void __iomem *priv_op = adapter->ahw.pci_base0 + QLCNIC_DRV_OP_MODE; | |
496 | ||
497 | /* If other drivers are not in use set their privilege level */ | |
498 | ref_count = QLCRD32(adapter, QLCNIC_CRB_DEV_REF_COUNT); | |
499 | ret = qlcnic_api_lock(adapter); | |
500 | if (ret) | |
501 | goto err_lock; | |
502 | if (QLC_DEV_CLR_REF_CNT(ref_count, adapter->ahw.pci_func)) | |
503 | goto err_npar; | |
504 | ||
0e33c664 AC |
505 | if (qlcnic_config_npars) { |
506 | for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) { | |
507 | id = adapter->npars[i].id; | |
508 | if (adapter->npars[i].type != QLCNIC_TYPE_NIC || | |
509 | id == adapter->ahw.pci_func) | |
510 | continue; | |
511 | data |= (qlcnic_config_npars & | |
512 | QLC_DEV_SET_DRV(0xf, id)); | |
513 | } | |
514 | } else { | |
515 | data = readl(priv_op); | |
516 | data = (data & ~QLC_DEV_SET_DRV(0xf, adapter->ahw.pci_func)) | | |
517 | (QLC_DEV_SET_DRV(QLCNIC_MGMT_FUNC, | |
518 | adapter->ahw.pci_func)); | |
2e9d722d AC |
519 | } |
520 | writel(data, priv_op); | |
2e9d722d AC |
521 | err_npar: |
522 | qlcnic_api_unlock(adapter); | |
523 | err_lock: | |
524 | return ret; | |
525 | } | |
526 | ||
2e9d722d AC |
527 | static u32 |
528 | qlcnic_get_driver_mode(struct qlcnic_adapter *adapter) | |
529 | { | |
530 | void __iomem *msix_base_addr; | |
531 | void __iomem *priv_op; | |
532 | u32 func; | |
533 | u32 msix_base; | |
534 | u32 op_mode, priv_level; | |
535 | ||
536 | /* Determine FW API version */ | |
537 | adapter->fw_hal_version = readl(adapter->ahw.pci_base0 + QLCNIC_FW_API); | |
538 | if (adapter->fw_hal_version == ~0) { | |
539 | adapter->nic_ops = &qlcnic_ops; | |
540 | adapter->fw_hal_version = QLCNIC_FW_BASE; | |
541 | adapter->ahw.pci_func = PCI_FUNC(adapter->pdev->devfn); | |
0e33c664 | 542 | adapter->capabilities = QLCRD32(adapter, CRB_FW_CAPABILITIES_1); |
2e9d722d AC |
543 | dev_info(&adapter->pdev->dev, |
544 | "FW does not support nic partion\n"); | |
545 | return adapter->fw_hal_version; | |
546 | } | |
547 | ||
548 | /* Find PCI function number */ | |
549 | pci_read_config_dword(adapter->pdev, QLCNIC_MSIX_TABLE_OFFSET, &func); | |
550 | msix_base_addr = adapter->ahw.pci_base0 + QLCNIC_MSIX_BASE; | |
551 | msix_base = readl(msix_base_addr); | |
552 | func = (func - msix_base)/QLCNIC_MSIX_TBL_PGSIZE; | |
553 | adapter->ahw.pci_func = func; | |
554 | ||
0e33c664 AC |
555 | qlcnic_get_nic_info(adapter, adapter->ahw.pci_func); |
556 | ||
557 | if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED)) { | |
558 | adapter->nic_ops = &qlcnic_ops; | |
559 | return adapter->fw_hal_version; | |
560 | } | |
561 | ||
2e9d722d AC |
562 | /* Determine function privilege level */ |
563 | priv_op = adapter->ahw.pci_base0 + QLCNIC_DRV_OP_MODE; | |
564 | op_mode = readl(priv_op); | |
0e33c664 | 565 | if (op_mode == QLC_DEV_DRV_DEFAULT) |
2e9d722d | 566 | priv_level = QLCNIC_MGMT_FUNC; |
0e33c664 | 567 | else |
2e9d722d AC |
568 | priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw.pci_func); |
569 | ||
570 | switch (priv_level) { | |
571 | case QLCNIC_MGMT_FUNC: | |
572 | adapter->op_mode = QLCNIC_MGMT_FUNC; | |
573 | adapter->nic_ops = &qlcnic_pf_ops; | |
0e33c664 | 574 | qlcnic_get_pci_info(adapter); |
2e9d722d | 575 | /* Set privilege level for other functions */ |
0e33c664 | 576 | qlcnic_set_function_modes(adapter); |
2e9d722d AC |
577 | dev_info(&adapter->pdev->dev, |
578 | "HAL Version: %d, Management function\n", | |
579 | adapter->fw_hal_version); | |
580 | break; | |
581 | case QLCNIC_PRIV_FUNC: | |
582 | adapter->op_mode = QLCNIC_PRIV_FUNC; | |
583 | dev_info(&adapter->pdev->dev, | |
584 | "HAL Version: %d, Privileged function\n", | |
585 | adapter->fw_hal_version); | |
586 | adapter->nic_ops = &qlcnic_pf_ops; | |
587 | break; | |
9f26f547 AC |
588 | case QLCNIC_NON_PRIV_FUNC: |
589 | adapter->op_mode = QLCNIC_NON_PRIV_FUNC; | |
590 | dev_info(&adapter->pdev->dev, | |
591 | "HAL Version: %d Non Privileged function\n", | |
592 | adapter->fw_hal_version); | |
593 | adapter->nic_ops = &qlcnic_vf_ops; | |
594 | break; | |
2e9d722d AC |
595 | default: |
596 | dev_info(&adapter->pdev->dev, "Unknown function mode: %d\n", | |
597 | priv_level); | |
598 | return 0; | |
599 | } | |
600 | return adapter->fw_hal_version; | |
601 | } | |
602 | ||
af19b491 AKS |
603 | static int |
604 | qlcnic_setup_pci_map(struct qlcnic_adapter *adapter) | |
605 | { | |
606 | void __iomem *mem_ptr0 = NULL; | |
607 | resource_size_t mem_base; | |
608 | unsigned long mem_len, pci_len0 = 0; | |
609 | ||
610 | struct pci_dev *pdev = adapter->pdev; | |
af19b491 | 611 | |
af19b491 AKS |
612 | /* remap phys address */ |
613 | mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */ | |
614 | mem_len = pci_resource_len(pdev, 0); | |
615 | ||
616 | if (mem_len == QLCNIC_PCI_2MB_SIZE) { | |
617 | ||
618 | mem_ptr0 = pci_ioremap_bar(pdev, 0); | |
619 | if (mem_ptr0 == NULL) { | |
620 | dev_err(&pdev->dev, "failed to map PCI bar 0\n"); | |
621 | return -EIO; | |
622 | } | |
623 | pci_len0 = mem_len; | |
624 | } else { | |
625 | return -EIO; | |
626 | } | |
627 | ||
628 | dev_info(&pdev->dev, "%dMB memory map\n", (int)(mem_len>>20)); | |
629 | ||
630 | adapter->ahw.pci_base0 = mem_ptr0; | |
631 | adapter->ahw.pci_len0 = pci_len0; | |
632 | ||
2e9d722d AC |
633 | if (!qlcnic_get_driver_mode(adapter)) { |
634 | iounmap(adapter->ahw.pci_base0); | |
635 | return -EIO; | |
636 | } | |
637 | ||
af19b491 | 638 | adapter->ahw.ocm_win_crb = qlcnic_get_ioaddr(adapter, |
2e9d722d | 639 | QLCNIC_PCIX_PS_REG(PCIX_OCM_WINDOW_REG(adapter->ahw.pci_func))); |
af19b491 AKS |
640 | |
641 | return 0; | |
642 | } | |
643 | ||
644 | static void get_brd_name(struct qlcnic_adapter *adapter, char *name) | |
645 | { | |
646 | struct pci_dev *pdev = adapter->pdev; | |
647 | int i, found = 0; | |
648 | ||
649 | for (i = 0; i < NUM_SUPPORTED_BOARDS; ++i) { | |
650 | if (qlcnic_boards[i].vendor == pdev->vendor && | |
651 | qlcnic_boards[i].device == pdev->device && | |
652 | qlcnic_boards[i].sub_vendor == pdev->subsystem_vendor && | |
653 | qlcnic_boards[i].sub_device == pdev->subsystem_device) { | |
02f6e46f SC |
654 | sprintf(name, "%pM: %s" , |
655 | adapter->mac_addr, | |
656 | qlcnic_boards[i].short_name); | |
af19b491 AKS |
657 | found = 1; |
658 | break; | |
659 | } | |
660 | ||
661 | } | |
662 | ||
663 | if (!found) | |
7f9a0c34 | 664 | sprintf(name, "%pM Gigabit Ethernet", adapter->mac_addr); |
af19b491 AKS |
665 | } |
666 | ||
667 | static void | |
668 | qlcnic_check_options(struct qlcnic_adapter *adapter) | |
669 | { | |
670 | u32 fw_major, fw_minor, fw_build; | |
671 | char brd_name[QLCNIC_MAX_BOARD_NAME_LEN]; | |
672 | char serial_num[32]; | |
673 | int i, offset, val; | |
674 | int *ptr32; | |
675 | struct pci_dev *pdev = adapter->pdev; | |
676 | ||
677 | adapter->driver_mismatch = 0; | |
678 | ||
679 | ptr32 = (int *)&serial_num; | |
680 | offset = QLCNIC_FW_SERIAL_NUM_OFFSET; | |
681 | for (i = 0; i < 8; i++) { | |
682 | if (qlcnic_rom_fast_read(adapter, offset, &val) == -1) { | |
683 | dev_err(&pdev->dev, "error reading board info\n"); | |
684 | adapter->driver_mismatch = 1; | |
685 | return; | |
686 | } | |
687 | ptr32[i] = cpu_to_le32(val); | |
688 | offset += sizeof(u32); | |
689 | } | |
690 | ||
691 | fw_major = QLCRD32(adapter, QLCNIC_FW_VERSION_MAJOR); | |
692 | fw_minor = QLCRD32(adapter, QLCNIC_FW_VERSION_MINOR); | |
693 | fw_build = QLCRD32(adapter, QLCNIC_FW_VERSION_SUB); | |
694 | ||
695 | adapter->fw_version = QLCNIC_VERSION_CODE(fw_major, fw_minor, fw_build); | |
696 | ||
697 | if (adapter->portnum == 0) { | |
698 | get_brd_name(adapter, brd_name); | |
699 | ||
700 | pr_info("%s: %s Board Chip rev 0x%x\n", | |
701 | module_name(THIS_MODULE), | |
702 | brd_name, adapter->ahw.revision_id); | |
703 | } | |
704 | ||
251a84c9 AKS |
705 | dev_info(&pdev->dev, "firmware v%d.%d.%d\n", |
706 | fw_major, fw_minor, fw_build); | |
af19b491 | 707 | |
af19b491 AKS |
708 | adapter->flags &= ~QLCNIC_LRO_ENABLED; |
709 | ||
710 | if (adapter->ahw.port_type == QLCNIC_XGBE) { | |
711 | adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_10G; | |
712 | adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G; | |
713 | } else if (adapter->ahw.port_type == QLCNIC_GBE) { | |
714 | adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_1G; | |
715 | adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G; | |
716 | } | |
717 | ||
0e33c664 AC |
718 | qlcnic_get_nic_info(adapter, adapter->ahw.pci_func); |
719 | ||
af19b491 AKS |
720 | adapter->msix_supported = !!use_msi_x; |
721 | adapter->rss_supported = !!use_msi_x; | |
722 | ||
723 | adapter->num_txd = MAX_CMD_DESCRIPTORS; | |
724 | ||
af19b491 AKS |
725 | adapter->max_rds_rings = 2; |
726 | } | |
727 | ||
728 | static int | |
729 | qlcnic_start_firmware(struct qlcnic_adapter *adapter) | |
730 | { | |
731 | int val, err, first_boot; | |
732 | ||
aa5e18c0 SC |
733 | err = qlcnic_can_start_firmware(adapter); |
734 | if (err < 0) | |
735 | return err; | |
736 | else if (!err) | |
af19b491 AKS |
737 | goto wait_init; |
738 | ||
739 | first_boot = QLCRD32(adapter, QLCNIC_CAM_RAM(0x1fc)); | |
740 | if (first_boot == 0x55555555) | |
741 | /* This is the first boot after power up */ | |
742 | QLCWR32(adapter, QLCNIC_CAM_RAM(0x1fc), QLCNIC_BDINFO_MAGIC); | |
743 | ||
4d5bdb38 AKS |
744 | if (load_fw_file) |
745 | qlcnic_request_firmware(adapter); | |
746 | else | |
747 | adapter->fw_type = QLCNIC_FLASH_ROMIMAGE; | |
af19b491 AKS |
748 | |
749 | err = qlcnic_need_fw_reset(adapter); | |
750 | if (err < 0) | |
751 | goto err_out; | |
752 | if (err == 0) | |
753 | goto wait_init; | |
754 | ||
755 | if (first_boot != 0x55555555) { | |
756 | QLCWR32(adapter, CRB_CMDPEG_STATE, 0); | |
757 | qlcnic_pinit_from_rom(adapter); | |
758 | msleep(1); | |
759 | } | |
760 | ||
af19b491 AKS |
761 | QLCWR32(adapter, QLCNIC_PEG_HALT_STATUS1, 0); |
762 | QLCWR32(adapter, QLCNIC_PEG_HALT_STATUS2, 0); | |
763 | ||
764 | qlcnic_set_port_mode(adapter); | |
765 | ||
766 | err = qlcnic_load_firmware(adapter); | |
767 | if (err) | |
768 | goto err_out; | |
769 | ||
770 | qlcnic_release_firmware(adapter); | |
771 | ||
772 | val = (_QLCNIC_LINUX_MAJOR << 16) | |
773 | | ((_QLCNIC_LINUX_MINOR << 8)) | |
774 | | (_QLCNIC_LINUX_SUBVERSION); | |
775 | QLCWR32(adapter, CRB_DRIVER_VERSION, val); | |
776 | ||
777 | wait_init: | |
778 | /* Handshake with the card before we register the devices. */ | |
779 | err = qlcnic_phantom_init(adapter); | |
780 | if (err) | |
781 | goto err_out; | |
782 | ||
783 | QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_READY); | |
6df900e9 | 784 | qlcnic_idc_debug_info(adapter, 1); |
af19b491 | 785 | |
af19b491 AKS |
786 | qlcnic_check_options(adapter); |
787 | ||
0e33c664 AC |
788 | if (adapter->flags & QLCNIC_ESWITCH_ENABLED && |
789 | adapter->op_mode != QLCNIC_NON_PRIV_FUNC) | |
790 | qlcnic_dev_set_npar_ready(adapter); | |
2e9d722d | 791 | |
af19b491 AKS |
792 | adapter->need_fw_reset = 0; |
793 | ||
a7fc948f AKS |
794 | qlcnic_release_firmware(adapter); |
795 | return 0; | |
af19b491 AKS |
796 | |
797 | err_out: | |
a7fc948f AKS |
798 | QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_FAILED); |
799 | dev_err(&adapter->pdev->dev, "Device state set to failed\n"); | |
af19b491 AKS |
800 | qlcnic_release_firmware(adapter); |
801 | return err; | |
802 | } | |
803 | ||
804 | static int | |
805 | qlcnic_request_irq(struct qlcnic_adapter *adapter) | |
806 | { | |
807 | irq_handler_t handler; | |
808 | struct qlcnic_host_sds_ring *sds_ring; | |
809 | int err, ring; | |
810 | ||
811 | unsigned long flags = 0; | |
812 | struct net_device *netdev = adapter->netdev; | |
813 | struct qlcnic_recv_context *recv_ctx = &adapter->recv_ctx; | |
814 | ||
7eb9855d AKS |
815 | if (adapter->diag_test == QLCNIC_INTERRUPT_TEST) { |
816 | handler = qlcnic_tmp_intr; | |
817 | if (!QLCNIC_IS_MSI_FAMILY(adapter)) | |
818 | flags |= IRQF_SHARED; | |
819 | ||
820 | } else { | |
821 | if (adapter->flags & QLCNIC_MSIX_ENABLED) | |
822 | handler = qlcnic_msix_intr; | |
823 | else if (adapter->flags & QLCNIC_MSI_ENABLED) | |
824 | handler = qlcnic_msi_intr; | |
825 | else { | |
826 | flags |= IRQF_SHARED; | |
827 | handler = qlcnic_intr; | |
828 | } | |
af19b491 AKS |
829 | } |
830 | adapter->irq = netdev->irq; | |
831 | ||
832 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { | |
833 | sds_ring = &recv_ctx->sds_rings[ring]; | |
834 | sprintf(sds_ring->name, "%s[%d]", netdev->name, ring); | |
835 | err = request_irq(sds_ring->irq, handler, | |
836 | flags, sds_ring->name, sds_ring); | |
837 | if (err) | |
838 | return err; | |
839 | } | |
840 | ||
841 | return 0; | |
842 | } | |
843 | ||
844 | static void | |
845 | qlcnic_free_irq(struct qlcnic_adapter *adapter) | |
846 | { | |
847 | int ring; | |
848 | struct qlcnic_host_sds_ring *sds_ring; | |
849 | ||
850 | struct qlcnic_recv_context *recv_ctx = &adapter->recv_ctx; | |
851 | ||
852 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { | |
853 | sds_ring = &recv_ctx->sds_rings[ring]; | |
854 | free_irq(sds_ring->irq, sds_ring); | |
855 | } | |
856 | } | |
857 | ||
858 | static void | |
859 | qlcnic_init_coalesce_defaults(struct qlcnic_adapter *adapter) | |
860 | { | |
861 | adapter->coal.flags = QLCNIC_INTR_DEFAULT; | |
862 | adapter->coal.normal.data.rx_time_us = | |
863 | QLCNIC_DEFAULT_INTR_COALESCE_RX_TIME_US; | |
864 | adapter->coal.normal.data.rx_packets = | |
865 | QLCNIC_DEFAULT_INTR_COALESCE_RX_PACKETS; | |
866 | adapter->coal.normal.data.tx_time_us = | |
867 | QLCNIC_DEFAULT_INTR_COALESCE_TX_TIME_US; | |
868 | adapter->coal.normal.data.tx_packets = | |
869 | QLCNIC_DEFAULT_INTR_COALESCE_TX_PACKETS; | |
870 | } | |
871 | ||
872 | static int | |
873 | __qlcnic_up(struct qlcnic_adapter *adapter, struct net_device *netdev) | |
874 | { | |
875 | if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC) | |
876 | return -EIO; | |
877 | ||
878 | qlcnic_set_multi(netdev); | |
879 | qlcnic_fw_cmd_set_mtu(adapter, netdev->mtu); | |
880 | ||
881 | adapter->ahw.linkup = 0; | |
882 | ||
883 | if (adapter->max_sds_rings > 1) | |
884 | qlcnic_config_rss(adapter, 1); | |
885 | ||
886 | qlcnic_config_intr_coalesce(adapter); | |
887 | ||
888 | if (adapter->capabilities & QLCNIC_FW_CAPABILITY_HW_LRO) | |
889 | qlcnic_config_hw_lro(adapter, QLCNIC_LRO_ENABLED); | |
890 | ||
891 | qlcnic_napi_enable(adapter); | |
892 | ||
893 | qlcnic_linkevent_request(adapter, 1); | |
894 | ||
895 | set_bit(__QLCNIC_DEV_UP, &adapter->state); | |
896 | return 0; | |
897 | } | |
898 | ||
899 | /* Usage: During resume and firmware recovery module.*/ | |
900 | ||
901 | static int | |
902 | qlcnic_up(struct qlcnic_adapter *adapter, struct net_device *netdev) | |
903 | { | |
904 | int err = 0; | |
905 | ||
906 | rtnl_lock(); | |
907 | if (netif_running(netdev)) | |
908 | err = __qlcnic_up(adapter, netdev); | |
909 | rtnl_unlock(); | |
910 | ||
911 | return err; | |
912 | } | |
913 | ||
914 | static void | |
915 | __qlcnic_down(struct qlcnic_adapter *adapter, struct net_device *netdev) | |
916 | { | |
917 | if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC) | |
918 | return; | |
919 | ||
920 | if (!test_and_clear_bit(__QLCNIC_DEV_UP, &adapter->state)) | |
921 | return; | |
922 | ||
923 | smp_mb(); | |
924 | spin_lock(&adapter->tx_clean_lock); | |
925 | netif_carrier_off(netdev); | |
926 | netif_tx_disable(netdev); | |
927 | ||
928 | qlcnic_free_mac_list(adapter); | |
929 | ||
930 | qlcnic_nic_set_promisc(adapter, QLCNIC_NIU_NON_PROMISC_MODE); | |
931 | ||
932 | qlcnic_napi_disable(adapter); | |
933 | ||
934 | qlcnic_release_tx_buffers(adapter); | |
935 | spin_unlock(&adapter->tx_clean_lock); | |
936 | } | |
937 | ||
938 | /* Usage: During suspend and firmware recovery module */ | |
939 | ||
940 | static void | |
941 | qlcnic_down(struct qlcnic_adapter *adapter, struct net_device *netdev) | |
942 | { | |
943 | rtnl_lock(); | |
944 | if (netif_running(netdev)) | |
945 | __qlcnic_down(adapter, netdev); | |
946 | rtnl_unlock(); | |
947 | ||
948 | } | |
949 | ||
950 | static int | |
951 | qlcnic_attach(struct qlcnic_adapter *adapter) | |
952 | { | |
953 | struct net_device *netdev = adapter->netdev; | |
954 | struct pci_dev *pdev = adapter->pdev; | |
955 | int err, ring; | |
956 | struct qlcnic_host_rds_ring *rds_ring; | |
957 | ||
958 | if (adapter->is_up == QLCNIC_ADAPTER_UP_MAGIC) | |
959 | return 0; | |
960 | ||
961 | err = qlcnic_init_firmware(adapter); | |
962 | if (err) | |
963 | return err; | |
964 | ||
965 | err = qlcnic_napi_add(adapter, netdev); | |
966 | if (err) | |
967 | return err; | |
968 | ||
969 | err = qlcnic_alloc_sw_resources(adapter); | |
970 | if (err) { | |
971 | dev_err(&pdev->dev, "Error in setting sw resources\n"); | |
972 | return err; | |
973 | } | |
974 | ||
975 | err = qlcnic_alloc_hw_resources(adapter); | |
976 | if (err) { | |
977 | dev_err(&pdev->dev, "Error in setting hw resources\n"); | |
978 | goto err_out_free_sw; | |
979 | } | |
980 | ||
981 | ||
982 | for (ring = 0; ring < adapter->max_rds_rings; ring++) { | |
983 | rds_ring = &adapter->recv_ctx.rds_rings[ring]; | |
984 | qlcnic_post_rx_buffers(adapter, ring, rds_ring); | |
985 | } | |
986 | ||
987 | err = qlcnic_request_irq(adapter); | |
988 | if (err) { | |
989 | dev_err(&pdev->dev, "failed to setup interrupt\n"); | |
990 | goto err_out_free_rxbuf; | |
991 | } | |
992 | ||
993 | qlcnic_init_coalesce_defaults(adapter); | |
994 | ||
995 | qlcnic_create_sysfs_entries(adapter); | |
996 | ||
997 | adapter->is_up = QLCNIC_ADAPTER_UP_MAGIC; | |
998 | return 0; | |
999 | ||
1000 | err_out_free_rxbuf: | |
1001 | qlcnic_release_rx_buffers(adapter); | |
1002 | qlcnic_free_hw_resources(adapter); | |
1003 | err_out_free_sw: | |
1004 | qlcnic_free_sw_resources(adapter); | |
1005 | return err; | |
1006 | } | |
1007 | ||
1008 | static void | |
1009 | qlcnic_detach(struct qlcnic_adapter *adapter) | |
1010 | { | |
1011 | if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC) | |
1012 | return; | |
1013 | ||
1014 | qlcnic_remove_sysfs_entries(adapter); | |
1015 | ||
1016 | qlcnic_free_hw_resources(adapter); | |
1017 | qlcnic_release_rx_buffers(adapter); | |
1018 | qlcnic_free_irq(adapter); | |
1019 | qlcnic_napi_del(adapter); | |
1020 | qlcnic_free_sw_resources(adapter); | |
1021 | ||
1022 | adapter->is_up = 0; | |
1023 | } | |
1024 | ||
7eb9855d AKS |
1025 | void qlcnic_diag_free_res(struct net_device *netdev, int max_sds_rings) |
1026 | { | |
1027 | struct qlcnic_adapter *adapter = netdev_priv(netdev); | |
1028 | struct qlcnic_host_sds_ring *sds_ring; | |
1029 | int ring; | |
1030 | ||
78ad3892 | 1031 | clear_bit(__QLCNIC_DEV_UP, &adapter->state); |
cdaff185 AKS |
1032 | if (adapter->diag_test == QLCNIC_INTERRUPT_TEST) { |
1033 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { | |
1034 | sds_ring = &adapter->recv_ctx.sds_rings[ring]; | |
1035 | qlcnic_disable_int(sds_ring); | |
1036 | } | |
7eb9855d AKS |
1037 | } |
1038 | ||
1039 | qlcnic_detach(adapter); | |
1040 | ||
1041 | adapter->diag_test = 0; | |
1042 | adapter->max_sds_rings = max_sds_rings; | |
1043 | ||
1044 | if (qlcnic_attach(adapter)) | |
34ce3626 | 1045 | goto out; |
7eb9855d AKS |
1046 | |
1047 | if (netif_running(netdev)) | |
1048 | __qlcnic_up(adapter, netdev); | |
34ce3626 | 1049 | out: |
7eb9855d AKS |
1050 | netif_device_attach(netdev); |
1051 | } | |
1052 | ||
1053 | int qlcnic_diag_alloc_res(struct net_device *netdev, int test) | |
1054 | { | |
1055 | struct qlcnic_adapter *adapter = netdev_priv(netdev); | |
1056 | struct qlcnic_host_sds_ring *sds_ring; | |
1057 | int ring; | |
1058 | int ret; | |
1059 | ||
1060 | netif_device_detach(netdev); | |
1061 | ||
1062 | if (netif_running(netdev)) | |
1063 | __qlcnic_down(adapter, netdev); | |
1064 | ||
1065 | qlcnic_detach(adapter); | |
1066 | ||
1067 | adapter->max_sds_rings = 1; | |
1068 | adapter->diag_test = test; | |
1069 | ||
1070 | ret = qlcnic_attach(adapter); | |
34ce3626 AKS |
1071 | if (ret) { |
1072 | netif_device_attach(netdev); | |
7eb9855d | 1073 | return ret; |
34ce3626 | 1074 | } |
7eb9855d | 1075 | |
cdaff185 AKS |
1076 | if (adapter->diag_test == QLCNIC_INTERRUPT_TEST) { |
1077 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { | |
1078 | sds_ring = &adapter->recv_ctx.sds_rings[ring]; | |
1079 | qlcnic_enable_int(sds_ring); | |
1080 | } | |
7eb9855d | 1081 | } |
78ad3892 | 1082 | set_bit(__QLCNIC_DEV_UP, &adapter->state); |
7eb9855d AKS |
1083 | |
1084 | return 0; | |
1085 | } | |
1086 | ||
af19b491 AKS |
1087 | int |
1088 | qlcnic_reset_context(struct qlcnic_adapter *adapter) | |
1089 | { | |
1090 | int err = 0; | |
1091 | struct net_device *netdev = adapter->netdev; | |
1092 | ||
1093 | if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state)) | |
1094 | return -EBUSY; | |
1095 | ||
1096 | if (adapter->is_up == QLCNIC_ADAPTER_UP_MAGIC) { | |
1097 | ||
1098 | netif_device_detach(netdev); | |
1099 | ||
1100 | if (netif_running(netdev)) | |
1101 | __qlcnic_down(adapter, netdev); | |
1102 | ||
1103 | qlcnic_detach(adapter); | |
1104 | ||
1105 | if (netif_running(netdev)) { | |
1106 | err = qlcnic_attach(adapter); | |
1107 | if (!err) | |
34ce3626 | 1108 | __qlcnic_up(adapter, netdev); |
af19b491 AKS |
1109 | } |
1110 | ||
1111 | netif_device_attach(netdev); | |
1112 | } | |
1113 | ||
af19b491 AKS |
1114 | clear_bit(__QLCNIC_RESETTING, &adapter->state); |
1115 | return err; | |
1116 | } | |
1117 | ||
1118 | static int | |
1119 | qlcnic_setup_netdev(struct qlcnic_adapter *adapter, | |
1bb09fb9 | 1120 | struct net_device *netdev, u8 pci_using_dac) |
af19b491 AKS |
1121 | { |
1122 | int err; | |
1123 | struct pci_dev *pdev = adapter->pdev; | |
1124 | ||
1125 | adapter->rx_csum = 1; | |
1126 | adapter->mc_enabled = 0; | |
1127 | adapter->max_mc_count = 38; | |
1128 | ||
1129 | netdev->netdev_ops = &qlcnic_netdev_ops; | |
1130 | netdev->watchdog_timeo = 2*HZ; | |
1131 | ||
1132 | qlcnic_change_mtu(netdev, netdev->mtu); | |
1133 | ||
1134 | SET_ETHTOOL_OPS(netdev, &qlcnic_ethtool_ops); | |
1135 | ||
2e9d722d AC |
1136 | netdev->features |= (NETIF_F_SG | NETIF_F_IP_CSUM | |
1137 | NETIF_F_IPV6_CSUM | NETIF_F_GRO | NETIF_F_TSO | NETIF_F_TSO6); | |
af19b491 | 1138 | |
2e9d722d AC |
1139 | netdev->vlan_features |= (NETIF_F_SG | NETIF_F_IP_CSUM | |
1140 | NETIF_F_IPV6_CSUM | NETIF_F_TSO | NETIF_F_TSO6); | |
af19b491 | 1141 | |
1bb09fb9 | 1142 | if (pci_using_dac) { |
af19b491 AKS |
1143 | netdev->features |= NETIF_F_HIGHDMA; |
1144 | netdev->vlan_features |= NETIF_F_HIGHDMA; | |
1145 | } | |
1146 | ||
1147 | if (adapter->capabilities & QLCNIC_FW_CAPABILITY_FVLANTX) | |
1148 | netdev->features |= (NETIF_F_HW_VLAN_TX); | |
1149 | ||
1150 | if (adapter->capabilities & QLCNIC_FW_CAPABILITY_HW_LRO) | |
1151 | netdev->features |= NETIF_F_LRO; | |
1152 | ||
1153 | netdev->irq = adapter->msix_entries[0].vector; | |
1154 | ||
1155 | INIT_WORK(&adapter->tx_timeout_task, qlcnic_tx_timeout_task); | |
1156 | ||
1157 | if (qlcnic_read_mac_addr(adapter)) | |
1158 | dev_warn(&pdev->dev, "failed to read mac addr\n"); | |
1159 | ||
1160 | netif_carrier_off(netdev); | |
1161 | netif_stop_queue(netdev); | |
1162 | ||
1163 | err = register_netdev(netdev); | |
1164 | if (err) { | |
1165 | dev_err(&pdev->dev, "failed to register net device\n"); | |
1166 | return err; | |
1167 | } | |
1168 | ||
1169 | return 0; | |
1170 | } | |
1171 | ||
1bb09fb9 AKS |
1172 | static int qlcnic_set_dma_mask(struct pci_dev *pdev, u8 *pci_using_dac) |
1173 | { | |
1174 | if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) && | |
1175 | !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64))) | |
1176 | *pci_using_dac = 1; | |
1177 | else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) && | |
1178 | !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32))) | |
1179 | *pci_using_dac = 0; | |
1180 | else { | |
1181 | dev_err(&pdev->dev, "Unable to set DMA mask, aborting\n"); | |
1182 | return -EIO; | |
1183 | } | |
1184 | ||
1185 | return 0; | |
1186 | } | |
1187 | ||
af19b491 AKS |
1188 | static int __devinit |
1189 | qlcnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) | |
1190 | { | |
1191 | struct net_device *netdev = NULL; | |
1192 | struct qlcnic_adapter *adapter = NULL; | |
1193 | int err; | |
af19b491 | 1194 | uint8_t revision_id; |
1bb09fb9 | 1195 | uint8_t pci_using_dac; |
af19b491 AKS |
1196 | |
1197 | err = pci_enable_device(pdev); | |
1198 | if (err) | |
1199 | return err; | |
1200 | ||
1201 | if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) { | |
1202 | err = -ENODEV; | |
1203 | goto err_out_disable_pdev; | |
1204 | } | |
1205 | ||
1bb09fb9 AKS |
1206 | err = qlcnic_set_dma_mask(pdev, &pci_using_dac); |
1207 | if (err) | |
1208 | goto err_out_disable_pdev; | |
1209 | ||
af19b491 AKS |
1210 | err = pci_request_regions(pdev, qlcnic_driver_name); |
1211 | if (err) | |
1212 | goto err_out_disable_pdev; | |
1213 | ||
1214 | pci_set_master(pdev); | |
1215 | ||
1216 | netdev = alloc_etherdev(sizeof(struct qlcnic_adapter)); | |
1217 | if (!netdev) { | |
1218 | dev_err(&pdev->dev, "failed to allocate net_device\n"); | |
1219 | err = -ENOMEM; | |
1220 | goto err_out_free_res; | |
1221 | } | |
1222 | ||
1223 | SET_NETDEV_DEV(netdev, &pdev->dev); | |
1224 | ||
1225 | adapter = netdev_priv(netdev); | |
1226 | adapter->netdev = netdev; | |
1227 | adapter->pdev = pdev; | |
6df900e9 | 1228 | adapter->dev_rst_time = jiffies; |
af19b491 AKS |
1229 | |
1230 | revision_id = pdev->revision; | |
1231 | adapter->ahw.revision_id = revision_id; | |
1232 | ||
1233 | rwlock_init(&adapter->ahw.crb_lock); | |
1234 | mutex_init(&adapter->ahw.mem_lock); | |
1235 | ||
1236 | spin_lock_init(&adapter->tx_clean_lock); | |
1237 | INIT_LIST_HEAD(&adapter->mac_list); | |
1238 | ||
1239 | err = qlcnic_setup_pci_map(adapter); | |
1240 | if (err) | |
1241 | goto err_out_free_netdev; | |
1242 | ||
1243 | /* This will be reset for mezz cards */ | |
2e9d722d | 1244 | adapter->portnum = adapter->ahw.pci_func; |
af19b491 AKS |
1245 | |
1246 | err = qlcnic_get_board_info(adapter); | |
1247 | if (err) { | |
1248 | dev_err(&pdev->dev, "Error getting board config info.\n"); | |
1249 | goto err_out_iounmap; | |
1250 | } | |
1251 | ||
02f6e46f SC |
1252 | if (qlcnic_read_mac_addr(adapter)) |
1253 | dev_warn(&pdev->dev, "failed to read mac addr\n"); | |
1254 | ||
b3a24649 SC |
1255 | if (qlcnic_setup_idc_param(adapter)) |
1256 | goto err_out_iounmap; | |
af19b491 | 1257 | |
9f26f547 | 1258 | err = adapter->nic_ops->start_firmware(adapter); |
a7fc948f AKS |
1259 | if (err) { |
1260 | dev_err(&pdev->dev, "Loading fw failed.Please Reboot\n"); | |
af19b491 | 1261 | goto err_out_decr_ref; |
a7fc948f | 1262 | } |
af19b491 | 1263 | |
af19b491 AKS |
1264 | qlcnic_clear_stats(adapter); |
1265 | ||
1266 | qlcnic_setup_intr(adapter); | |
1267 | ||
1bb09fb9 | 1268 | err = qlcnic_setup_netdev(adapter, netdev, pci_using_dac); |
af19b491 AKS |
1269 | if (err) |
1270 | goto err_out_disable_msi; | |
1271 | ||
1272 | pci_set_drvdata(pdev, adapter); | |
1273 | ||
1274 | qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY); | |
1275 | ||
1276 | switch (adapter->ahw.port_type) { | |
1277 | case QLCNIC_GBE: | |
1278 | dev_info(&adapter->pdev->dev, "%s: GbE port initialized\n", | |
1279 | adapter->netdev->name); | |
1280 | break; | |
1281 | case QLCNIC_XGBE: | |
1282 | dev_info(&adapter->pdev->dev, "%s: XGbE port initialized\n", | |
1283 | adapter->netdev->name); | |
1284 | break; | |
1285 | } | |
1286 | ||
1287 | qlcnic_create_diag_entries(adapter); | |
1288 | ||
1289 | return 0; | |
1290 | ||
1291 | err_out_disable_msi: | |
1292 | qlcnic_teardown_intr(adapter); | |
1293 | ||
1294 | err_out_decr_ref: | |
1295 | qlcnic_clr_all_drv_state(adapter); | |
1296 | ||
1297 | err_out_iounmap: | |
1298 | qlcnic_cleanup_pci_map(adapter); | |
1299 | ||
1300 | err_out_free_netdev: | |
1301 | free_netdev(netdev); | |
1302 | ||
1303 | err_out_free_res: | |
1304 | pci_release_regions(pdev); | |
1305 | ||
1306 | err_out_disable_pdev: | |
1307 | pci_set_drvdata(pdev, NULL); | |
1308 | pci_disable_device(pdev); | |
1309 | return err; | |
1310 | } | |
1311 | ||
1312 | static void __devexit qlcnic_remove(struct pci_dev *pdev) | |
1313 | { | |
1314 | struct qlcnic_adapter *adapter; | |
1315 | struct net_device *netdev; | |
1316 | ||
1317 | adapter = pci_get_drvdata(pdev); | |
1318 | if (adapter == NULL) | |
1319 | return; | |
1320 | ||
1321 | netdev = adapter->netdev; | |
1322 | ||
1323 | qlcnic_cancel_fw_work(adapter); | |
1324 | ||
1325 | unregister_netdev(netdev); | |
1326 | ||
1327 | cancel_work_sync(&adapter->tx_timeout_task); | |
1328 | ||
1329 | qlcnic_detach(adapter); | |
1330 | ||
2e9d722d AC |
1331 | if (adapter->npars != NULL) |
1332 | kfree(adapter->npars); | |
1333 | if (adapter->eswitch != NULL) | |
1334 | kfree(adapter->eswitch); | |
1335 | ||
af19b491 AKS |
1336 | qlcnic_clr_all_drv_state(adapter); |
1337 | ||
1338 | clear_bit(__QLCNIC_RESETTING, &adapter->state); | |
1339 | ||
1340 | qlcnic_teardown_intr(adapter); | |
1341 | ||
1342 | qlcnic_remove_diag_entries(adapter); | |
1343 | ||
1344 | qlcnic_cleanup_pci_map(adapter); | |
1345 | ||
1346 | qlcnic_release_firmware(adapter); | |
1347 | ||
1348 | pci_release_regions(pdev); | |
1349 | pci_disable_device(pdev); | |
1350 | pci_set_drvdata(pdev, NULL); | |
1351 | ||
1352 | free_netdev(netdev); | |
1353 | } | |
1354 | static int __qlcnic_shutdown(struct pci_dev *pdev) | |
1355 | { | |
1356 | struct qlcnic_adapter *adapter = pci_get_drvdata(pdev); | |
1357 | struct net_device *netdev = adapter->netdev; | |
1358 | int retval; | |
1359 | ||
1360 | netif_device_detach(netdev); | |
1361 | ||
1362 | qlcnic_cancel_fw_work(adapter); | |
1363 | ||
1364 | if (netif_running(netdev)) | |
1365 | qlcnic_down(adapter, netdev); | |
1366 | ||
1367 | cancel_work_sync(&adapter->tx_timeout_task); | |
1368 | ||
1369 | qlcnic_detach(adapter); | |
1370 | ||
1371 | qlcnic_clr_all_drv_state(adapter); | |
1372 | ||
1373 | clear_bit(__QLCNIC_RESETTING, &adapter->state); | |
1374 | ||
1375 | retval = pci_save_state(pdev); | |
1376 | if (retval) | |
1377 | return retval; | |
1378 | ||
1379 | if (qlcnic_wol_supported(adapter)) { | |
1380 | pci_enable_wake(pdev, PCI_D3cold, 1); | |
1381 | pci_enable_wake(pdev, PCI_D3hot, 1); | |
1382 | } | |
1383 | ||
1384 | return 0; | |
1385 | } | |
1386 | ||
1387 | static void qlcnic_shutdown(struct pci_dev *pdev) | |
1388 | { | |
1389 | if (__qlcnic_shutdown(pdev)) | |
1390 | return; | |
1391 | ||
1392 | pci_disable_device(pdev); | |
1393 | } | |
1394 | ||
1395 | #ifdef CONFIG_PM | |
1396 | static int | |
1397 | qlcnic_suspend(struct pci_dev *pdev, pm_message_t state) | |
1398 | { | |
1399 | int retval; | |
1400 | ||
1401 | retval = __qlcnic_shutdown(pdev); | |
1402 | if (retval) | |
1403 | return retval; | |
1404 | ||
1405 | pci_set_power_state(pdev, pci_choose_state(pdev, state)); | |
1406 | return 0; | |
1407 | } | |
1408 | ||
1409 | static int | |
1410 | qlcnic_resume(struct pci_dev *pdev) | |
1411 | { | |
1412 | struct qlcnic_adapter *adapter = pci_get_drvdata(pdev); | |
1413 | struct net_device *netdev = adapter->netdev; | |
1414 | int err; | |
1415 | ||
1416 | err = pci_enable_device(pdev); | |
1417 | if (err) | |
1418 | return err; | |
1419 | ||
1420 | pci_set_power_state(pdev, PCI_D0); | |
1421 | pci_set_master(pdev); | |
1422 | pci_restore_state(pdev); | |
1423 | ||
9f26f547 | 1424 | err = adapter->nic_ops->start_firmware(adapter); |
af19b491 AKS |
1425 | if (err) { |
1426 | dev_err(&pdev->dev, "failed to start firmware\n"); | |
1427 | return err; | |
1428 | } | |
1429 | ||
1430 | if (netif_running(netdev)) { | |
1431 | err = qlcnic_attach(adapter); | |
1432 | if (err) | |
1433 | goto err_out; | |
1434 | ||
1435 | err = qlcnic_up(adapter, netdev); | |
1436 | if (err) | |
1437 | goto err_out_detach; | |
1438 | ||
1439 | ||
1440 | qlcnic_config_indev_addr(netdev, NETDEV_UP); | |
1441 | } | |
1442 | ||
1443 | netif_device_attach(netdev); | |
1444 | qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY); | |
1445 | return 0; | |
1446 | ||
1447 | err_out_detach: | |
1448 | qlcnic_detach(adapter); | |
1449 | err_out: | |
1450 | qlcnic_clr_all_drv_state(adapter); | |
34ce3626 | 1451 | netif_device_attach(netdev); |
af19b491 AKS |
1452 | return err; |
1453 | } | |
1454 | #endif | |
1455 | ||
1456 | static int qlcnic_open(struct net_device *netdev) | |
1457 | { | |
1458 | struct qlcnic_adapter *adapter = netdev_priv(netdev); | |
1459 | int err; | |
1460 | ||
1461 | if (adapter->driver_mismatch) | |
1462 | return -EIO; | |
1463 | ||
1464 | err = qlcnic_attach(adapter); | |
1465 | if (err) | |
1466 | return err; | |
1467 | ||
1468 | err = __qlcnic_up(adapter, netdev); | |
1469 | if (err) | |
1470 | goto err_out; | |
1471 | ||
1472 | netif_start_queue(netdev); | |
1473 | ||
1474 | return 0; | |
1475 | ||
1476 | err_out: | |
1477 | qlcnic_detach(adapter); | |
1478 | return err; | |
1479 | } | |
1480 | ||
1481 | /* | |
1482 | * qlcnic_close - Disables a network interface entry point | |
1483 | */ | |
1484 | static int qlcnic_close(struct net_device *netdev) | |
1485 | { | |
1486 | struct qlcnic_adapter *adapter = netdev_priv(netdev); | |
1487 | ||
1488 | __qlcnic_down(adapter, netdev); | |
1489 | return 0; | |
1490 | } | |
1491 | ||
1492 | static void | |
1493 | qlcnic_tso_check(struct net_device *netdev, | |
1494 | struct qlcnic_host_tx_ring *tx_ring, | |
1495 | struct cmd_desc_type0 *first_desc, | |
1496 | struct sk_buff *skb) | |
1497 | { | |
1498 | u8 opcode = TX_ETHER_PKT; | |
1499 | __be16 protocol = skb->protocol; | |
1500 | u16 flags = 0, vid = 0; | |
af19b491 AKS |
1501 | int copied, offset, copy_len, hdr_len = 0, tso = 0, vlan_oob = 0; |
1502 | struct cmd_desc_type0 *hwdesc; | |
1503 | struct vlan_ethhdr *vh; | |
8bfe8b91 | 1504 | struct qlcnic_adapter *adapter = netdev_priv(netdev); |
2e9d722d | 1505 | u32 producer = tx_ring->producer; |
af19b491 AKS |
1506 | |
1507 | if (protocol == cpu_to_be16(ETH_P_8021Q)) { | |
1508 | ||
1509 | vh = (struct vlan_ethhdr *)skb->data; | |
1510 | protocol = vh->h_vlan_encapsulated_proto; | |
1511 | flags = FLAGS_VLAN_TAGGED; | |
1512 | ||
1513 | } else if (vlan_tx_tag_present(skb)) { | |
1514 | ||
1515 | flags = FLAGS_VLAN_OOB; | |
1516 | vid = vlan_tx_tag_get(skb); | |
1517 | qlcnic_set_tx_vlan_tci(first_desc, vid); | |
1518 | vlan_oob = 1; | |
1519 | } | |
1520 | ||
2e9d722d AC |
1521 | if (*(skb->data) & BIT_0) { |
1522 | flags |= BIT_0; | |
1523 | memcpy(&first_desc->eth_addr, skb->data, ETH_ALEN); | |
1524 | } | |
1525 | ||
af19b491 AKS |
1526 | if ((netdev->features & (NETIF_F_TSO | NETIF_F_TSO6)) && |
1527 | skb_shinfo(skb)->gso_size > 0) { | |
1528 | ||
1529 | hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); | |
1530 | ||
1531 | first_desc->mss = cpu_to_le16(skb_shinfo(skb)->gso_size); | |
1532 | first_desc->total_hdr_length = hdr_len; | |
1533 | if (vlan_oob) { | |
1534 | first_desc->total_hdr_length += VLAN_HLEN; | |
1535 | first_desc->tcp_hdr_offset = VLAN_HLEN; | |
1536 | first_desc->ip_hdr_offset = VLAN_HLEN; | |
1537 | /* Only in case of TSO on vlan device */ | |
1538 | flags |= FLAGS_VLAN_TAGGED; | |
1539 | } | |
1540 | ||
1541 | opcode = (protocol == cpu_to_be16(ETH_P_IPV6)) ? | |
1542 | TX_TCP_LSO6 : TX_TCP_LSO; | |
1543 | tso = 1; | |
1544 | ||
1545 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { | |
1546 | u8 l4proto; | |
1547 | ||
1548 | if (protocol == cpu_to_be16(ETH_P_IP)) { | |
1549 | l4proto = ip_hdr(skb)->protocol; | |
1550 | ||
1551 | if (l4proto == IPPROTO_TCP) | |
1552 | opcode = TX_TCP_PKT; | |
1553 | else if (l4proto == IPPROTO_UDP) | |
1554 | opcode = TX_UDP_PKT; | |
1555 | } else if (protocol == cpu_to_be16(ETH_P_IPV6)) { | |
1556 | l4proto = ipv6_hdr(skb)->nexthdr; | |
1557 | ||
1558 | if (l4proto == IPPROTO_TCP) | |
1559 | opcode = TX_TCPV6_PKT; | |
1560 | else if (l4proto == IPPROTO_UDP) | |
1561 | opcode = TX_UDPV6_PKT; | |
1562 | } | |
1563 | } | |
1564 | ||
1565 | first_desc->tcp_hdr_offset += skb_transport_offset(skb); | |
1566 | first_desc->ip_hdr_offset += skb_network_offset(skb); | |
1567 | qlcnic_set_tx_flags_opcode(first_desc, flags, opcode); | |
1568 | ||
1569 | if (!tso) | |
1570 | return; | |
1571 | ||
1572 | /* For LSO, we need to copy the MAC/IP/TCP headers into | |
1573 | * the descriptor ring | |
1574 | */ | |
af19b491 AKS |
1575 | copied = 0; |
1576 | offset = 2; | |
1577 | ||
1578 | if (vlan_oob) { | |
1579 | /* Create a TSO vlan header template for firmware */ | |
1580 | ||
1581 | hwdesc = &tx_ring->desc_head[producer]; | |
1582 | tx_ring->cmd_buf_arr[producer].skb = NULL; | |
1583 | ||
1584 | copy_len = min((int)sizeof(struct cmd_desc_type0) - offset, | |
1585 | hdr_len + VLAN_HLEN); | |
1586 | ||
1587 | vh = (struct vlan_ethhdr *)((char *)hwdesc + 2); | |
1588 | skb_copy_from_linear_data(skb, vh, 12); | |
1589 | vh->h_vlan_proto = htons(ETH_P_8021Q); | |
1590 | vh->h_vlan_TCI = htons(vid); | |
1591 | skb_copy_from_linear_data_offset(skb, 12, | |
1592 | (char *)vh + 16, copy_len - 16); | |
1593 | ||
1594 | copied = copy_len - VLAN_HLEN; | |
1595 | offset = 0; | |
1596 | ||
1597 | producer = get_next_index(producer, tx_ring->num_desc); | |
1598 | } | |
1599 | ||
1600 | while (copied < hdr_len) { | |
1601 | ||
1602 | copy_len = min((int)sizeof(struct cmd_desc_type0) - offset, | |
1603 | (hdr_len - copied)); | |
1604 | ||
1605 | hwdesc = &tx_ring->desc_head[producer]; | |
1606 | tx_ring->cmd_buf_arr[producer].skb = NULL; | |
1607 | ||
1608 | skb_copy_from_linear_data_offset(skb, copied, | |
1609 | (char *)hwdesc + offset, copy_len); | |
1610 | ||
1611 | copied += copy_len; | |
1612 | offset = 0; | |
1613 | ||
1614 | producer = get_next_index(producer, tx_ring->num_desc); | |
1615 | } | |
1616 | ||
1617 | tx_ring->producer = producer; | |
1618 | barrier(); | |
8bfe8b91 | 1619 | adapter->stats.lso_frames++; |
af19b491 AKS |
1620 | } |
1621 | ||
1622 | static int | |
1623 | qlcnic_map_tx_skb(struct pci_dev *pdev, | |
1624 | struct sk_buff *skb, struct qlcnic_cmd_buffer *pbuf) | |
1625 | { | |
1626 | struct qlcnic_skb_frag *nf; | |
1627 | struct skb_frag_struct *frag; | |
1628 | int i, nr_frags; | |
1629 | dma_addr_t map; | |
1630 | ||
1631 | nr_frags = skb_shinfo(skb)->nr_frags; | |
1632 | nf = &pbuf->frag_array[0]; | |
1633 | ||
1634 | map = pci_map_single(pdev, skb->data, | |
1635 | skb_headlen(skb), PCI_DMA_TODEVICE); | |
1636 | if (pci_dma_mapping_error(pdev, map)) | |
1637 | goto out_err; | |
1638 | ||
1639 | nf->dma = map; | |
1640 | nf->length = skb_headlen(skb); | |
1641 | ||
1642 | for (i = 0; i < nr_frags; i++) { | |
1643 | frag = &skb_shinfo(skb)->frags[i]; | |
1644 | nf = &pbuf->frag_array[i+1]; | |
1645 | ||
1646 | map = pci_map_page(pdev, frag->page, frag->page_offset, | |
1647 | frag->size, PCI_DMA_TODEVICE); | |
1648 | if (pci_dma_mapping_error(pdev, map)) | |
1649 | goto unwind; | |
1650 | ||
1651 | nf->dma = map; | |
1652 | nf->length = frag->size; | |
1653 | } | |
1654 | ||
1655 | return 0; | |
1656 | ||
1657 | unwind: | |
1658 | while (--i >= 0) { | |
1659 | nf = &pbuf->frag_array[i+1]; | |
1660 | pci_unmap_page(pdev, nf->dma, nf->length, PCI_DMA_TODEVICE); | |
1661 | } | |
1662 | ||
1663 | nf = &pbuf->frag_array[0]; | |
1664 | pci_unmap_single(pdev, nf->dma, skb_headlen(skb), PCI_DMA_TODEVICE); | |
1665 | ||
1666 | out_err: | |
1667 | return -ENOMEM; | |
1668 | } | |
1669 | ||
1670 | static inline void | |
1671 | qlcnic_clear_cmddesc(u64 *desc) | |
1672 | { | |
1673 | desc[0] = 0ULL; | |
1674 | desc[2] = 0ULL; | |
1675 | } | |
1676 | ||
cdaff185 | 1677 | netdev_tx_t |
af19b491 AKS |
1678 | qlcnic_xmit_frame(struct sk_buff *skb, struct net_device *netdev) |
1679 | { | |
1680 | struct qlcnic_adapter *adapter = netdev_priv(netdev); | |
1681 | struct qlcnic_host_tx_ring *tx_ring = adapter->tx_ring; | |
1682 | struct qlcnic_cmd_buffer *pbuf; | |
1683 | struct qlcnic_skb_frag *buffrag; | |
1684 | struct cmd_desc_type0 *hwdesc, *first_desc; | |
1685 | struct pci_dev *pdev; | |
1686 | int i, k; | |
1687 | ||
1688 | u32 producer; | |
1689 | int frag_count, no_of_desc; | |
1690 | u32 num_txd = tx_ring->num_desc; | |
1691 | ||
780ab790 AKS |
1692 | if (!test_bit(__QLCNIC_DEV_UP, &adapter->state)) { |
1693 | netif_stop_queue(netdev); | |
1694 | return NETDEV_TX_BUSY; | |
1695 | } | |
1696 | ||
af19b491 AKS |
1697 | frag_count = skb_shinfo(skb)->nr_frags + 1; |
1698 | ||
1699 | /* 4 fragments per cmd des */ | |
1700 | no_of_desc = (frag_count + 3) >> 2; | |
1701 | ||
1702 | if (unlikely(no_of_desc + 2 > qlcnic_tx_avail(tx_ring))) { | |
1703 | netif_stop_queue(netdev); | |
8bfe8b91 | 1704 | adapter->stats.xmit_off++; |
af19b491 AKS |
1705 | return NETDEV_TX_BUSY; |
1706 | } | |
1707 | ||
1708 | producer = tx_ring->producer; | |
1709 | pbuf = &tx_ring->cmd_buf_arr[producer]; | |
1710 | ||
1711 | pdev = adapter->pdev; | |
1712 | ||
8ae6df97 AKS |
1713 | if (qlcnic_map_tx_skb(pdev, skb, pbuf)) { |
1714 | adapter->stats.tx_dma_map_error++; | |
af19b491 | 1715 | goto drop_packet; |
8ae6df97 | 1716 | } |
af19b491 AKS |
1717 | |
1718 | pbuf->skb = skb; | |
1719 | pbuf->frag_count = frag_count; | |
1720 | ||
1721 | first_desc = hwdesc = &tx_ring->desc_head[producer]; | |
1722 | qlcnic_clear_cmddesc((u64 *)hwdesc); | |
1723 | ||
1724 | qlcnic_set_tx_frags_len(first_desc, frag_count, skb->len); | |
1725 | qlcnic_set_tx_port(first_desc, adapter->portnum); | |
1726 | ||
1727 | for (i = 0; i < frag_count; i++) { | |
1728 | ||
1729 | k = i % 4; | |
1730 | ||
1731 | if ((k == 0) && (i > 0)) { | |
1732 | /* move to next desc.*/ | |
1733 | producer = get_next_index(producer, num_txd); | |
1734 | hwdesc = &tx_ring->desc_head[producer]; | |
1735 | qlcnic_clear_cmddesc((u64 *)hwdesc); | |
1736 | tx_ring->cmd_buf_arr[producer].skb = NULL; | |
1737 | } | |
1738 | ||
1739 | buffrag = &pbuf->frag_array[i]; | |
1740 | ||
1741 | hwdesc->buffer_length[k] = cpu_to_le16(buffrag->length); | |
1742 | switch (k) { | |
1743 | case 0: | |
1744 | hwdesc->addr_buffer1 = cpu_to_le64(buffrag->dma); | |
1745 | break; | |
1746 | case 1: | |
1747 | hwdesc->addr_buffer2 = cpu_to_le64(buffrag->dma); | |
1748 | break; | |
1749 | case 2: | |
1750 | hwdesc->addr_buffer3 = cpu_to_le64(buffrag->dma); | |
1751 | break; | |
1752 | case 3: | |
1753 | hwdesc->addr_buffer4 = cpu_to_le64(buffrag->dma); | |
1754 | break; | |
1755 | } | |
1756 | } | |
1757 | ||
1758 | tx_ring->producer = get_next_index(producer, num_txd); | |
1759 | ||
1760 | qlcnic_tso_check(netdev, tx_ring, first_desc, skb); | |
1761 | ||
1762 | qlcnic_update_cmd_producer(adapter, tx_ring); | |
1763 | ||
1764 | adapter->stats.txbytes += skb->len; | |
1765 | adapter->stats.xmitcalled++; | |
1766 | ||
1767 | return NETDEV_TX_OK; | |
1768 | ||
1769 | drop_packet: | |
1770 | adapter->stats.txdropped++; | |
1771 | dev_kfree_skb_any(skb); | |
1772 | return NETDEV_TX_OK; | |
1773 | } | |
1774 | ||
1775 | static int qlcnic_check_temp(struct qlcnic_adapter *adapter) | |
1776 | { | |
1777 | struct net_device *netdev = adapter->netdev; | |
1778 | u32 temp, temp_state, temp_val; | |
1779 | int rv = 0; | |
1780 | ||
1781 | temp = QLCRD32(adapter, CRB_TEMP_STATE); | |
1782 | ||
1783 | temp_state = qlcnic_get_temp_state(temp); | |
1784 | temp_val = qlcnic_get_temp_val(temp); | |
1785 | ||
1786 | if (temp_state == QLCNIC_TEMP_PANIC) { | |
1787 | dev_err(&netdev->dev, | |
1788 | "Device temperature %d degrees C exceeds" | |
1789 | " maximum allowed. Hardware has been shut down.\n", | |
1790 | temp_val); | |
1791 | rv = 1; | |
1792 | } else if (temp_state == QLCNIC_TEMP_WARN) { | |
1793 | if (adapter->temp == QLCNIC_TEMP_NORMAL) { | |
1794 | dev_err(&netdev->dev, | |
1795 | "Device temperature %d degrees C " | |
1796 | "exceeds operating range." | |
1797 | " Immediate action needed.\n", | |
1798 | temp_val); | |
1799 | } | |
1800 | } else { | |
1801 | if (adapter->temp == QLCNIC_TEMP_WARN) { | |
1802 | dev_info(&netdev->dev, | |
1803 | "Device temperature is now %d degrees C" | |
1804 | " in normal range.\n", temp_val); | |
1805 | } | |
1806 | } | |
1807 | adapter->temp = temp_state; | |
1808 | return rv; | |
1809 | } | |
1810 | ||
1811 | void qlcnic_advert_link_change(struct qlcnic_adapter *adapter, int linkup) | |
1812 | { | |
1813 | struct net_device *netdev = adapter->netdev; | |
1814 | ||
1815 | if (adapter->ahw.linkup && !linkup) { | |
1816 | dev_info(&netdev->dev, "NIC Link is down\n"); | |
1817 | adapter->ahw.linkup = 0; | |
1818 | if (netif_running(netdev)) { | |
1819 | netif_carrier_off(netdev); | |
1820 | netif_stop_queue(netdev); | |
1821 | } | |
1822 | } else if (!adapter->ahw.linkup && linkup) { | |
1823 | dev_info(&netdev->dev, "NIC Link is up\n"); | |
1824 | adapter->ahw.linkup = 1; | |
1825 | if (netif_running(netdev)) { | |
1826 | netif_carrier_on(netdev); | |
1827 | netif_wake_queue(netdev); | |
1828 | } | |
1829 | } | |
1830 | } | |
1831 | ||
1832 | static void qlcnic_tx_timeout(struct net_device *netdev) | |
1833 | { | |
1834 | struct qlcnic_adapter *adapter = netdev_priv(netdev); | |
1835 | ||
1836 | if (test_bit(__QLCNIC_RESETTING, &adapter->state)) | |
1837 | return; | |
1838 | ||
1839 | dev_err(&netdev->dev, "transmit timeout, resetting.\n"); | |
1840 | schedule_work(&adapter->tx_timeout_task); | |
1841 | } | |
1842 | ||
1843 | static void qlcnic_tx_timeout_task(struct work_struct *work) | |
1844 | { | |
1845 | struct qlcnic_adapter *adapter = | |
1846 | container_of(work, struct qlcnic_adapter, tx_timeout_task); | |
1847 | ||
1848 | if (!netif_running(adapter->netdev)) | |
1849 | return; | |
1850 | ||
1851 | if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state)) | |
1852 | return; | |
1853 | ||
1854 | if (++adapter->tx_timeo_cnt >= QLCNIC_MAX_TX_TIMEOUTS) | |
1855 | goto request_reset; | |
1856 | ||
1857 | clear_bit(__QLCNIC_RESETTING, &adapter->state); | |
1858 | if (!qlcnic_reset_context(adapter)) { | |
1859 | adapter->netdev->trans_start = jiffies; | |
1860 | return; | |
1861 | ||
1862 | /* context reset failed, fall through for fw reset */ | |
1863 | } | |
1864 | ||
1865 | request_reset: | |
1866 | adapter->need_fw_reset = 1; | |
1867 | clear_bit(__QLCNIC_RESETTING, &adapter->state); | |
65b5b420 | 1868 | QLCDB(adapter, DRV, "Resetting adapter\n"); |
af19b491 AKS |
1869 | } |
1870 | ||
1871 | static struct net_device_stats *qlcnic_get_stats(struct net_device *netdev) | |
1872 | { | |
1873 | struct qlcnic_adapter *adapter = netdev_priv(netdev); | |
1874 | struct net_device_stats *stats = &netdev->stats; | |
1875 | ||
1876 | memset(stats, 0, sizeof(*stats)); | |
1877 | ||
1878 | stats->rx_packets = adapter->stats.rx_pkts + adapter->stats.lro_pkts; | |
1879 | stats->tx_packets = adapter->stats.xmitfinished; | |
7e382594 | 1880 | stats->rx_bytes = adapter->stats.rxbytes + adapter->stats.lrobytes; |
af19b491 AKS |
1881 | stats->tx_bytes = adapter->stats.txbytes; |
1882 | stats->rx_dropped = adapter->stats.rxdropped; | |
1883 | stats->tx_dropped = adapter->stats.txdropped; | |
1884 | ||
1885 | return stats; | |
1886 | } | |
1887 | ||
7eb9855d | 1888 | static irqreturn_t qlcnic_clear_legacy_intr(struct qlcnic_adapter *adapter) |
af19b491 | 1889 | { |
af19b491 AKS |
1890 | u32 status; |
1891 | ||
1892 | status = readl(adapter->isr_int_vec); | |
1893 | ||
1894 | if (!(status & adapter->int_vec_bit)) | |
1895 | return IRQ_NONE; | |
1896 | ||
1897 | /* check interrupt state machine, to be sure */ | |
1898 | status = readl(adapter->crb_int_state_reg); | |
1899 | if (!ISR_LEGACY_INT_TRIGGERED(status)) | |
1900 | return IRQ_NONE; | |
1901 | ||
1902 | writel(0xffffffff, adapter->tgt_status_reg); | |
1903 | /* read twice to ensure write is flushed */ | |
1904 | readl(adapter->isr_int_vec); | |
1905 | readl(adapter->isr_int_vec); | |
1906 | ||
7eb9855d AKS |
1907 | return IRQ_HANDLED; |
1908 | } | |
1909 | ||
1910 | static irqreturn_t qlcnic_tmp_intr(int irq, void *data) | |
1911 | { | |
1912 | struct qlcnic_host_sds_ring *sds_ring = data; | |
1913 | struct qlcnic_adapter *adapter = sds_ring->adapter; | |
1914 | ||
1915 | if (adapter->flags & QLCNIC_MSIX_ENABLED) | |
1916 | goto done; | |
1917 | else if (adapter->flags & QLCNIC_MSI_ENABLED) { | |
1918 | writel(0xffffffff, adapter->tgt_status_reg); | |
1919 | goto done; | |
1920 | } | |
1921 | ||
1922 | if (qlcnic_clear_legacy_intr(adapter) == IRQ_NONE) | |
1923 | return IRQ_NONE; | |
1924 | ||
1925 | done: | |
1926 | adapter->diag_cnt++; | |
1927 | qlcnic_enable_int(sds_ring); | |
1928 | return IRQ_HANDLED; | |
1929 | } | |
1930 | ||
1931 | static irqreturn_t qlcnic_intr(int irq, void *data) | |
1932 | { | |
1933 | struct qlcnic_host_sds_ring *sds_ring = data; | |
1934 | struct qlcnic_adapter *adapter = sds_ring->adapter; | |
1935 | ||
1936 | if (qlcnic_clear_legacy_intr(adapter) == IRQ_NONE) | |
1937 | return IRQ_NONE; | |
1938 | ||
af19b491 AKS |
1939 | napi_schedule(&sds_ring->napi); |
1940 | ||
1941 | return IRQ_HANDLED; | |
1942 | } | |
1943 | ||
1944 | static irqreturn_t qlcnic_msi_intr(int irq, void *data) | |
1945 | { | |
1946 | struct qlcnic_host_sds_ring *sds_ring = data; | |
1947 | struct qlcnic_adapter *adapter = sds_ring->adapter; | |
1948 | ||
1949 | /* clear interrupt */ | |
1950 | writel(0xffffffff, adapter->tgt_status_reg); | |
1951 | ||
1952 | napi_schedule(&sds_ring->napi); | |
1953 | return IRQ_HANDLED; | |
1954 | } | |
1955 | ||
1956 | static irqreturn_t qlcnic_msix_intr(int irq, void *data) | |
1957 | { | |
1958 | struct qlcnic_host_sds_ring *sds_ring = data; | |
1959 | ||
1960 | napi_schedule(&sds_ring->napi); | |
1961 | return IRQ_HANDLED; | |
1962 | } | |
1963 | ||
1964 | static int qlcnic_process_cmd_ring(struct qlcnic_adapter *adapter) | |
1965 | { | |
1966 | u32 sw_consumer, hw_consumer; | |
1967 | int count = 0, i; | |
1968 | struct qlcnic_cmd_buffer *buffer; | |
1969 | struct pci_dev *pdev = adapter->pdev; | |
1970 | struct net_device *netdev = adapter->netdev; | |
1971 | struct qlcnic_skb_frag *frag; | |
1972 | int done; | |
1973 | struct qlcnic_host_tx_ring *tx_ring = adapter->tx_ring; | |
1974 | ||
1975 | if (!spin_trylock(&adapter->tx_clean_lock)) | |
1976 | return 1; | |
1977 | ||
1978 | sw_consumer = tx_ring->sw_consumer; | |
1979 | hw_consumer = le32_to_cpu(*(tx_ring->hw_consumer)); | |
1980 | ||
1981 | while (sw_consumer != hw_consumer) { | |
1982 | buffer = &tx_ring->cmd_buf_arr[sw_consumer]; | |
1983 | if (buffer->skb) { | |
1984 | frag = &buffer->frag_array[0]; | |
1985 | pci_unmap_single(pdev, frag->dma, frag->length, | |
1986 | PCI_DMA_TODEVICE); | |
1987 | frag->dma = 0ULL; | |
1988 | for (i = 1; i < buffer->frag_count; i++) { | |
1989 | frag++; | |
1990 | pci_unmap_page(pdev, frag->dma, frag->length, | |
1991 | PCI_DMA_TODEVICE); | |
1992 | frag->dma = 0ULL; | |
1993 | } | |
1994 | ||
1995 | adapter->stats.xmitfinished++; | |
1996 | dev_kfree_skb_any(buffer->skb); | |
1997 | buffer->skb = NULL; | |
1998 | } | |
1999 | ||
2000 | sw_consumer = get_next_index(sw_consumer, tx_ring->num_desc); | |
2001 | if (++count >= MAX_STATUS_HANDLE) | |
2002 | break; | |
2003 | } | |
2004 | ||
2005 | if (count && netif_running(netdev)) { | |
2006 | tx_ring->sw_consumer = sw_consumer; | |
2007 | ||
2008 | smp_mb(); | |
2009 | ||
2010 | if (netif_queue_stopped(netdev) && netif_carrier_ok(netdev)) { | |
2011 | __netif_tx_lock(tx_ring->txq, smp_processor_id()); | |
2012 | if (qlcnic_tx_avail(tx_ring) > TX_STOP_THRESH) { | |
2013 | netif_wake_queue(netdev); | |
2014 | adapter->tx_timeo_cnt = 0; | |
8bfe8b91 | 2015 | adapter->stats.xmit_on++; |
af19b491 AKS |
2016 | } |
2017 | __netif_tx_unlock(tx_ring->txq); | |
2018 | } | |
2019 | } | |
2020 | /* | |
2021 | * If everything is freed up to consumer then check if the ring is full | |
2022 | * If the ring is full then check if more needs to be freed and | |
2023 | * schedule the call back again. | |
2024 | * | |
2025 | * This happens when there are 2 CPUs. One could be freeing and the | |
2026 | * other filling it. If the ring is full when we get out of here and | |
2027 | * the card has already interrupted the host then the host can miss the | |
2028 | * interrupt. | |
2029 | * | |
2030 | * There is still a possible race condition and the host could miss an | |
2031 | * interrupt. The card has to take care of this. | |
2032 | */ | |
2033 | hw_consumer = le32_to_cpu(*(tx_ring->hw_consumer)); | |
2034 | done = (sw_consumer == hw_consumer); | |
2035 | spin_unlock(&adapter->tx_clean_lock); | |
2036 | ||
2037 | return done; | |
2038 | } | |
2039 | ||
2040 | static int qlcnic_poll(struct napi_struct *napi, int budget) | |
2041 | { | |
2042 | struct qlcnic_host_sds_ring *sds_ring = | |
2043 | container_of(napi, struct qlcnic_host_sds_ring, napi); | |
2044 | ||
2045 | struct qlcnic_adapter *adapter = sds_ring->adapter; | |
2046 | ||
2047 | int tx_complete; | |
2048 | int work_done; | |
2049 | ||
2050 | tx_complete = qlcnic_process_cmd_ring(adapter); | |
2051 | ||
2052 | work_done = qlcnic_process_rcv_ring(sds_ring, budget); | |
2053 | ||
2054 | if ((work_done < budget) && tx_complete) { | |
2055 | napi_complete(&sds_ring->napi); | |
2056 | if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) | |
2057 | qlcnic_enable_int(sds_ring); | |
2058 | } | |
2059 | ||
2060 | return work_done; | |
2061 | } | |
2062 | ||
2063 | #ifdef CONFIG_NET_POLL_CONTROLLER | |
2064 | static void qlcnic_poll_controller(struct net_device *netdev) | |
2065 | { | |
2066 | struct qlcnic_adapter *adapter = netdev_priv(netdev); | |
2067 | disable_irq(adapter->irq); | |
2068 | qlcnic_intr(adapter->irq, adapter); | |
2069 | enable_irq(adapter->irq); | |
2070 | } | |
2071 | #endif | |
2072 | ||
6df900e9 SC |
2073 | static void |
2074 | qlcnic_idc_debug_info(struct qlcnic_adapter *adapter, u8 encoding) | |
2075 | { | |
2076 | u32 val; | |
2077 | ||
2078 | val = adapter->portnum & 0xf; | |
2079 | val |= encoding << 7; | |
2080 | val |= (jiffies - adapter->dev_rst_time) << 8; | |
2081 | ||
2082 | QLCWR32(adapter, QLCNIC_CRB_DRV_SCRATCH, val); | |
2083 | adapter->dev_rst_time = jiffies; | |
2084 | } | |
2085 | ||
ade91f8e AKS |
2086 | static int |
2087 | qlcnic_set_drv_state(struct qlcnic_adapter *adapter, u8 state) | |
af19b491 AKS |
2088 | { |
2089 | u32 val; | |
2090 | ||
2091 | WARN_ON(state != QLCNIC_DEV_NEED_RESET && | |
2092 | state != QLCNIC_DEV_NEED_QUISCENT); | |
2093 | ||
2094 | if (qlcnic_api_lock(adapter)) | |
ade91f8e | 2095 | return -EIO; |
af19b491 AKS |
2096 | |
2097 | val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE); | |
2098 | ||
2099 | if (state == QLCNIC_DEV_NEED_RESET) | |
6d2a4724 | 2100 | QLC_DEV_SET_RST_RDY(val, adapter->portnum); |
af19b491 | 2101 | else if (state == QLCNIC_DEV_NEED_QUISCENT) |
6d2a4724 | 2102 | QLC_DEV_SET_QSCNT_RDY(val, adapter->portnum); |
af19b491 AKS |
2103 | |
2104 | QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val); | |
2105 | ||
2106 | qlcnic_api_unlock(adapter); | |
ade91f8e AKS |
2107 | |
2108 | return 0; | |
af19b491 AKS |
2109 | } |
2110 | ||
1b95a839 AKS |
2111 | static int |
2112 | qlcnic_clr_drv_state(struct qlcnic_adapter *adapter) | |
2113 | { | |
2114 | u32 val; | |
2115 | ||
2116 | if (qlcnic_api_lock(adapter)) | |
2117 | return -EBUSY; | |
2118 | ||
2119 | val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE); | |
6d2a4724 | 2120 | QLC_DEV_CLR_RST_QSCNT(val, adapter->portnum); |
1b95a839 AKS |
2121 | QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val); |
2122 | ||
2123 | qlcnic_api_unlock(adapter); | |
2124 | ||
2125 | return 0; | |
2126 | } | |
2127 | ||
af19b491 AKS |
2128 | static void |
2129 | qlcnic_clr_all_drv_state(struct qlcnic_adapter *adapter) | |
2130 | { | |
2131 | u32 val; | |
2132 | ||
2133 | if (qlcnic_api_lock(adapter)) | |
2134 | goto err; | |
2135 | ||
2136 | val = QLCRD32(adapter, QLCNIC_CRB_DEV_REF_COUNT); | |
6d2a4724 | 2137 | QLC_DEV_CLR_REF_CNT(val, adapter->portnum); |
af19b491 AKS |
2138 | QLCWR32(adapter, QLCNIC_CRB_DEV_REF_COUNT, val); |
2139 | ||
2140 | if (!(val & 0x11111111)) | |
2141 | QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_COLD); | |
2142 | ||
2143 | val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE); | |
6d2a4724 | 2144 | QLC_DEV_CLR_RST_QSCNT(val, adapter->portnum); |
af19b491 AKS |
2145 | QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val); |
2146 | ||
2147 | qlcnic_api_unlock(adapter); | |
2148 | err: | |
2149 | adapter->fw_fail_cnt = 0; | |
2150 | clear_bit(__QLCNIC_START_FW, &adapter->state); | |
2151 | clear_bit(__QLCNIC_RESETTING, &adapter->state); | |
2152 | } | |
2153 | ||
f73dfc50 | 2154 | /* Grab api lock, before checking state */ |
af19b491 AKS |
2155 | static int |
2156 | qlcnic_check_drv_state(struct qlcnic_adapter *adapter) | |
2157 | { | |
2158 | int act, state; | |
2159 | ||
2160 | state = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE); | |
2161 | act = QLCRD32(adapter, QLCNIC_CRB_DEV_REF_COUNT); | |
2162 | ||
2163 | if (((state & 0x11111111) == (act & 0x11111111)) || | |
2164 | ((act & 0x11111111) == ((state >> 1) & 0x11111111))) | |
2165 | return 0; | |
2166 | else | |
2167 | return 1; | |
2168 | } | |
2169 | ||
96f8118c SC |
2170 | static int qlcnic_check_idc_ver(struct qlcnic_adapter *adapter) |
2171 | { | |
2172 | u32 val = QLCRD32(adapter, QLCNIC_CRB_DRV_IDC_VER); | |
2173 | ||
2174 | if (val != QLCNIC_DRV_IDC_VER) { | |
2175 | dev_warn(&adapter->pdev->dev, "IDC Version mismatch, driver's" | |
2176 | " idc ver = %x; reqd = %x\n", QLCNIC_DRV_IDC_VER, val); | |
2177 | } | |
2178 | ||
2179 | return 0; | |
2180 | } | |
2181 | ||
af19b491 AKS |
2182 | static int |
2183 | qlcnic_can_start_firmware(struct qlcnic_adapter *adapter) | |
2184 | { | |
2185 | u32 val, prev_state; | |
aa5e18c0 | 2186 | u8 dev_init_timeo = adapter->dev_init_timeo; |
6d2a4724 | 2187 | u8 portnum = adapter->portnum; |
96f8118c | 2188 | u8 ret; |
af19b491 | 2189 | |
f73dfc50 AKS |
2190 | if (test_and_clear_bit(__QLCNIC_START_FW, &adapter->state)) |
2191 | return 1; | |
2192 | ||
af19b491 AKS |
2193 | if (qlcnic_api_lock(adapter)) |
2194 | return -1; | |
2195 | ||
2196 | val = QLCRD32(adapter, QLCNIC_CRB_DEV_REF_COUNT); | |
6d2a4724 AKS |
2197 | if (!(val & (1 << (portnum * 4)))) { |
2198 | QLC_DEV_SET_REF_CNT(val, portnum); | |
af19b491 | 2199 | QLCWR32(adapter, QLCNIC_CRB_DEV_REF_COUNT, val); |
af19b491 AKS |
2200 | } |
2201 | ||
2202 | prev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE); | |
65b5b420 | 2203 | QLCDB(adapter, HW, "Device state = %u\n", prev_state); |
af19b491 AKS |
2204 | |
2205 | switch (prev_state) { | |
2206 | case QLCNIC_DEV_COLD: | |
bbd8c6a4 | 2207 | QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_INITIALIZING); |
96f8118c | 2208 | QLCWR32(adapter, QLCNIC_CRB_DRV_IDC_VER, QLCNIC_DRV_IDC_VER); |
6df900e9 | 2209 | qlcnic_idc_debug_info(adapter, 0); |
af19b491 AKS |
2210 | qlcnic_api_unlock(adapter); |
2211 | return 1; | |
2212 | ||
2213 | case QLCNIC_DEV_READY: | |
96f8118c | 2214 | ret = qlcnic_check_idc_ver(adapter); |
af19b491 | 2215 | qlcnic_api_unlock(adapter); |
96f8118c | 2216 | return ret; |
af19b491 AKS |
2217 | |
2218 | case QLCNIC_DEV_NEED_RESET: | |
2219 | val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE); | |
6d2a4724 | 2220 | QLC_DEV_SET_RST_RDY(val, portnum); |
af19b491 AKS |
2221 | QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val); |
2222 | break; | |
2223 | ||
2224 | case QLCNIC_DEV_NEED_QUISCENT: | |
2225 | val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE); | |
6d2a4724 | 2226 | QLC_DEV_SET_QSCNT_RDY(val, portnum); |
af19b491 AKS |
2227 | QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val); |
2228 | break; | |
2229 | ||
2230 | case QLCNIC_DEV_FAILED: | |
a7fc948f | 2231 | dev_err(&adapter->pdev->dev, "Device in failed state.\n"); |
af19b491 AKS |
2232 | qlcnic_api_unlock(adapter); |
2233 | return -1; | |
bbd8c6a4 AKS |
2234 | |
2235 | case QLCNIC_DEV_INITIALIZING: | |
2236 | case QLCNIC_DEV_QUISCENT: | |
2237 | break; | |
af19b491 AKS |
2238 | } |
2239 | ||
2240 | qlcnic_api_unlock(adapter); | |
aa5e18c0 SC |
2241 | |
2242 | do { | |
af19b491 | 2243 | msleep(1000); |
a5e463d0 SC |
2244 | prev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE); |
2245 | ||
2246 | if (prev_state == QLCNIC_DEV_QUISCENT) | |
2247 | continue; | |
2248 | } while ((prev_state != QLCNIC_DEV_READY) && --dev_init_timeo); | |
af19b491 | 2249 | |
65b5b420 AKS |
2250 | if (!dev_init_timeo) { |
2251 | dev_err(&adapter->pdev->dev, | |
2252 | "Waiting for device to initialize timeout\n"); | |
af19b491 | 2253 | return -1; |
65b5b420 | 2254 | } |
af19b491 AKS |
2255 | |
2256 | if (qlcnic_api_lock(adapter)) | |
2257 | return -1; | |
2258 | ||
2259 | val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE); | |
6d2a4724 | 2260 | QLC_DEV_CLR_RST_QSCNT(val, portnum); |
af19b491 AKS |
2261 | QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val); |
2262 | ||
96f8118c | 2263 | ret = qlcnic_check_idc_ver(adapter); |
af19b491 AKS |
2264 | qlcnic_api_unlock(adapter); |
2265 | ||
96f8118c | 2266 | return ret; |
af19b491 AKS |
2267 | } |
2268 | ||
2269 | static void | |
2270 | qlcnic_fwinit_work(struct work_struct *work) | |
2271 | { | |
2272 | struct qlcnic_adapter *adapter = container_of(work, | |
2273 | struct qlcnic_adapter, fw_work.work); | |
9f26f547 | 2274 | u32 dev_state = 0xf, npar_state; |
af19b491 | 2275 | |
f73dfc50 AKS |
2276 | if (qlcnic_api_lock(adapter)) |
2277 | goto err_ret; | |
af19b491 | 2278 | |
a5e463d0 SC |
2279 | dev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE); |
2280 | if (dev_state == QLCNIC_DEV_QUISCENT) { | |
2281 | qlcnic_api_unlock(adapter); | |
2282 | qlcnic_schedule_work(adapter, qlcnic_fwinit_work, | |
2283 | FW_POLL_DELAY * 2); | |
2284 | return; | |
2285 | } | |
2286 | ||
9f26f547 AC |
2287 | if (adapter->op_mode == QLCNIC_NON_PRIV_FUNC) { |
2288 | npar_state = QLCRD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE); | |
2289 | if (npar_state == QLCNIC_DEV_NPAR_RDY) { | |
2290 | qlcnic_api_unlock(adapter); | |
2291 | goto wait_npar; | |
2292 | } else { | |
2293 | qlcnic_schedule_work(adapter, qlcnic_fwinit_work, | |
2294 | FW_POLL_DELAY); | |
2295 | qlcnic_api_unlock(adapter); | |
2296 | return; | |
2297 | } | |
2298 | } | |
2299 | ||
f73dfc50 AKS |
2300 | if (adapter->fw_wait_cnt++ > adapter->reset_ack_timeo) { |
2301 | dev_err(&adapter->pdev->dev, "Reset:Failed to get ack %d sec\n", | |
2302 | adapter->reset_ack_timeo); | |
2303 | goto skip_ack_check; | |
2304 | } | |
2305 | ||
2306 | if (!qlcnic_check_drv_state(adapter)) { | |
2307 | skip_ack_check: | |
2308 | dev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE); | |
a5e463d0 SC |
2309 | |
2310 | if (dev_state == QLCNIC_DEV_NEED_QUISCENT) { | |
2311 | QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, | |
2312 | QLCNIC_DEV_QUISCENT); | |
2313 | qlcnic_schedule_work(adapter, qlcnic_fwinit_work, | |
2314 | FW_POLL_DELAY * 2); | |
2315 | QLCDB(adapter, DRV, "Quiscing the driver\n"); | |
6df900e9 SC |
2316 | qlcnic_idc_debug_info(adapter, 0); |
2317 | ||
a5e463d0 SC |
2318 | qlcnic_api_unlock(adapter); |
2319 | return; | |
2320 | } | |
2321 | ||
f73dfc50 AKS |
2322 | if (dev_state == QLCNIC_DEV_NEED_RESET) { |
2323 | QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, | |
2324 | QLCNIC_DEV_INITIALIZING); | |
2325 | set_bit(__QLCNIC_START_FW, &adapter->state); | |
2326 | QLCDB(adapter, DRV, "Restarting fw\n"); | |
6df900e9 | 2327 | qlcnic_idc_debug_info(adapter, 0); |
af19b491 AKS |
2328 | } |
2329 | ||
f73dfc50 AKS |
2330 | qlcnic_api_unlock(adapter); |
2331 | ||
9f26f547 | 2332 | if (!adapter->nic_ops->start_firmware(adapter)) { |
af19b491 AKS |
2333 | qlcnic_schedule_work(adapter, qlcnic_attach_work, 0); |
2334 | return; | |
2335 | } | |
af19b491 AKS |
2336 | goto err_ret; |
2337 | } | |
2338 | ||
f73dfc50 | 2339 | qlcnic_api_unlock(adapter); |
aa5e18c0 | 2340 | |
9f26f547 | 2341 | wait_npar: |
af19b491 | 2342 | dev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE); |
f73dfc50 | 2343 | QLCDB(adapter, HW, "Func waiting: Device state=%u\n", dev_state); |
65b5b420 | 2344 | |
af19b491 | 2345 | switch (dev_state) { |
a5e463d0 SC |
2346 | case QLCNIC_DEV_QUISCENT: |
2347 | case QLCNIC_DEV_NEED_QUISCENT: | |
f73dfc50 AKS |
2348 | case QLCNIC_DEV_NEED_RESET: |
2349 | qlcnic_schedule_work(adapter, | |
2350 | qlcnic_fwinit_work, FW_POLL_DELAY); | |
2351 | return; | |
af19b491 AKS |
2352 | case QLCNIC_DEV_FAILED: |
2353 | break; | |
2354 | ||
2355 | default: | |
9f26f547 | 2356 | if (!adapter->nic_ops->start_firmware(adapter)) { |
f73dfc50 AKS |
2357 | qlcnic_schedule_work(adapter, qlcnic_attach_work, 0); |
2358 | return; | |
2359 | } | |
af19b491 AKS |
2360 | } |
2361 | ||
2362 | err_ret: | |
f73dfc50 AKS |
2363 | dev_err(&adapter->pdev->dev, "Fwinit work failed state=%u " |
2364 | "fw_wait_cnt=%u\n", dev_state, adapter->fw_wait_cnt); | |
34ce3626 | 2365 | netif_device_attach(adapter->netdev); |
af19b491 AKS |
2366 | qlcnic_clr_all_drv_state(adapter); |
2367 | } | |
2368 | ||
2369 | static void | |
2370 | qlcnic_detach_work(struct work_struct *work) | |
2371 | { | |
2372 | struct qlcnic_adapter *adapter = container_of(work, | |
2373 | struct qlcnic_adapter, fw_work.work); | |
2374 | struct net_device *netdev = adapter->netdev; | |
2375 | u32 status; | |
2376 | ||
2377 | netif_device_detach(netdev); | |
2378 | ||
2379 | qlcnic_down(adapter, netdev); | |
2380 | ||
ce668443 | 2381 | rtnl_lock(); |
af19b491 | 2382 | qlcnic_detach(adapter); |
ce668443 | 2383 | rtnl_unlock(); |
af19b491 AKS |
2384 | |
2385 | status = QLCRD32(adapter, QLCNIC_PEG_HALT_STATUS1); | |
2386 | ||
2387 | if (status & QLCNIC_RCODE_FATAL_ERROR) | |
2388 | goto err_ret; | |
2389 | ||
2390 | if (adapter->temp == QLCNIC_TEMP_PANIC) | |
2391 | goto err_ret; | |
2392 | ||
ade91f8e AKS |
2393 | if (qlcnic_set_drv_state(adapter, adapter->dev_state)) |
2394 | goto err_ret; | |
af19b491 AKS |
2395 | |
2396 | adapter->fw_wait_cnt = 0; | |
2397 | ||
2398 | qlcnic_schedule_work(adapter, qlcnic_fwinit_work, FW_POLL_DELAY); | |
2399 | ||
2400 | return; | |
2401 | ||
2402 | err_ret: | |
65b5b420 AKS |
2403 | dev_err(&adapter->pdev->dev, "detach failed; status=%d temp=%d\n", |
2404 | status, adapter->temp); | |
34ce3626 | 2405 | netif_device_attach(netdev); |
af19b491 AKS |
2406 | qlcnic_clr_all_drv_state(adapter); |
2407 | ||
2408 | } | |
2409 | ||
f73dfc50 | 2410 | /*Transit to RESET state from READY state only */ |
af19b491 AKS |
2411 | static void |
2412 | qlcnic_dev_request_reset(struct qlcnic_adapter *adapter) | |
2413 | { | |
2414 | u32 state; | |
2415 | ||
2416 | if (qlcnic_api_lock(adapter)) | |
2417 | return; | |
2418 | ||
2419 | state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE); | |
2420 | ||
f73dfc50 | 2421 | if (state == QLCNIC_DEV_READY) { |
af19b491 | 2422 | QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_NEED_RESET); |
65b5b420 | 2423 | QLCDB(adapter, DRV, "NEED_RESET state set\n"); |
6df900e9 | 2424 | qlcnic_idc_debug_info(adapter, 0); |
af19b491 AKS |
2425 | } |
2426 | ||
2427 | qlcnic_api_unlock(adapter); | |
2428 | } | |
2429 | ||
9f26f547 AC |
2430 | /* Transit to NPAR READY state from NPAR NOT READY state */ |
2431 | static void | |
2432 | qlcnic_dev_set_npar_ready(struct qlcnic_adapter *adapter) | |
2433 | { | |
2434 | u32 state; | |
2435 | ||
9f26f547 AC |
2436 | if (qlcnic_api_lock(adapter)) |
2437 | return; | |
2438 | ||
2439 | state = QLCRD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE); | |
2440 | ||
2441 | if (state != QLCNIC_DEV_NPAR_RDY) { | |
2442 | QLCWR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE, | |
2443 | QLCNIC_DEV_NPAR_RDY); | |
2444 | QLCDB(adapter, DRV, "NPAR READY state set\n"); | |
2445 | } | |
2446 | ||
2447 | qlcnic_api_unlock(adapter); | |
2448 | } | |
2449 | ||
af19b491 AKS |
2450 | static void |
2451 | qlcnic_schedule_work(struct qlcnic_adapter *adapter, | |
2452 | work_func_t func, int delay) | |
2453 | { | |
2454 | INIT_DELAYED_WORK(&adapter->fw_work, func); | |
2455 | schedule_delayed_work(&adapter->fw_work, round_jiffies_relative(delay)); | |
2456 | } | |
2457 | ||
2458 | static void | |
2459 | qlcnic_cancel_fw_work(struct qlcnic_adapter *adapter) | |
2460 | { | |
2461 | while (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state)) | |
2462 | msleep(10); | |
2463 | ||
2464 | cancel_delayed_work_sync(&adapter->fw_work); | |
2465 | } | |
2466 | ||
2467 | static void | |
2468 | qlcnic_attach_work(struct work_struct *work) | |
2469 | { | |
2470 | struct qlcnic_adapter *adapter = container_of(work, | |
2471 | struct qlcnic_adapter, fw_work.work); | |
2472 | struct net_device *netdev = adapter->netdev; | |
2473 | int err; | |
2474 | ||
2475 | if (netif_running(netdev)) { | |
2476 | err = qlcnic_attach(adapter); | |
2477 | if (err) | |
2478 | goto done; | |
2479 | ||
2480 | err = qlcnic_up(adapter, netdev); | |
2481 | if (err) { | |
2482 | qlcnic_detach(adapter); | |
2483 | goto done; | |
2484 | } | |
2485 | ||
2486 | qlcnic_config_indev_addr(netdev, NETDEV_UP); | |
2487 | } | |
2488 | ||
af19b491 | 2489 | done: |
34ce3626 | 2490 | netif_device_attach(netdev); |
af19b491 AKS |
2491 | adapter->fw_fail_cnt = 0; |
2492 | clear_bit(__QLCNIC_RESETTING, &adapter->state); | |
1b95a839 AKS |
2493 | |
2494 | if (!qlcnic_clr_drv_state(adapter)) | |
2495 | qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, | |
2496 | FW_POLL_DELAY); | |
af19b491 AKS |
2497 | } |
2498 | ||
2499 | static int | |
2500 | qlcnic_check_health(struct qlcnic_adapter *adapter) | |
2501 | { | |
2502 | u32 state = 0, heartbit; | |
2503 | struct net_device *netdev = adapter->netdev; | |
2504 | ||
2505 | if (qlcnic_check_temp(adapter)) | |
2506 | goto detach; | |
2507 | ||
2372a5f1 | 2508 | if (adapter->need_fw_reset) |
af19b491 | 2509 | qlcnic_dev_request_reset(adapter); |
af19b491 AKS |
2510 | |
2511 | state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE); | |
2512 | if (state == QLCNIC_DEV_NEED_RESET || state == QLCNIC_DEV_NEED_QUISCENT) | |
2513 | adapter->need_fw_reset = 1; | |
2514 | ||
2515 | heartbit = QLCRD32(adapter, QLCNIC_PEG_ALIVE_COUNTER); | |
2516 | if (heartbit != adapter->heartbit) { | |
2517 | adapter->heartbit = heartbit; | |
2518 | adapter->fw_fail_cnt = 0; | |
2519 | if (adapter->need_fw_reset) | |
2520 | goto detach; | |
2521 | return 0; | |
2522 | } | |
2523 | ||
2524 | if (++adapter->fw_fail_cnt < FW_FAIL_THRESH) | |
2525 | return 0; | |
2526 | ||
2527 | qlcnic_dev_request_reset(adapter); | |
2528 | ||
2529 | clear_bit(__QLCNIC_FW_ATTACHED, &adapter->state); | |
2530 | ||
2531 | dev_info(&netdev->dev, "firmware hang detected\n"); | |
2532 | ||
2533 | detach: | |
2534 | adapter->dev_state = (state == QLCNIC_DEV_NEED_QUISCENT) ? state : | |
2535 | QLCNIC_DEV_NEED_RESET; | |
2536 | ||
2537 | if ((auto_fw_reset == AUTO_FW_RESET_ENABLED) && | |
65b5b420 AKS |
2538 | !test_and_set_bit(__QLCNIC_RESETTING, &adapter->state)) { |
2539 | ||
af19b491 | 2540 | qlcnic_schedule_work(adapter, qlcnic_detach_work, 0); |
65b5b420 AKS |
2541 | QLCDB(adapter, DRV, "fw recovery scheduled.\n"); |
2542 | } | |
af19b491 AKS |
2543 | |
2544 | return 1; | |
2545 | } | |
2546 | ||
2547 | static void | |
2548 | qlcnic_fw_poll_work(struct work_struct *work) | |
2549 | { | |
2550 | struct qlcnic_adapter *adapter = container_of(work, | |
2551 | struct qlcnic_adapter, fw_work.work); | |
2552 | ||
2553 | if (test_bit(__QLCNIC_RESETTING, &adapter->state)) | |
2554 | goto reschedule; | |
2555 | ||
2556 | ||
2557 | if (qlcnic_check_health(adapter)) | |
2558 | return; | |
2559 | ||
2560 | reschedule: | |
2561 | qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY); | |
2562 | } | |
2563 | ||
87eb743b AC |
2564 | static int |
2565 | qlcnicvf_start_firmware(struct qlcnic_adapter *adapter) | |
2566 | { | |
2567 | int err; | |
2568 | ||
2569 | err = qlcnic_can_start_firmware(adapter); | |
2570 | if (err) | |
2571 | return err; | |
2572 | ||
2573 | qlcnic_check_options(adapter); | |
2574 | ||
2575 | adapter->need_fw_reset = 0; | |
2576 | ||
2577 | return err; | |
2578 | } | |
2579 | ||
2580 | static int | |
2581 | qlcnicvf_config_bridged_mode(struct qlcnic_adapter *adapter, u32 enable) | |
2582 | { | |
2583 | return -EOPNOTSUPP; | |
2584 | } | |
2585 | ||
2586 | static int | |
2587 | qlcnicvf_config_led(struct qlcnic_adapter *adapter, u32 state, u32 rate) | |
2588 | { | |
2589 | return -EOPNOTSUPP; | |
2590 | } | |
2591 | ||
2592 | static int | |
2593 | qlcnicvf_set_ilb_mode(struct qlcnic_adapter *adapter) | |
2594 | { | |
2595 | return -EOPNOTSUPP; | |
2596 | } | |
2597 | ||
2598 | static void | |
2599 | qlcnicvf_clear_ilb_mode(struct qlcnic_adapter *adapter) | |
2600 | { | |
2601 | return; | |
2602 | } | |
2603 | ||
af19b491 AKS |
2604 | static ssize_t |
2605 | qlcnic_store_bridged_mode(struct device *dev, | |
2606 | struct device_attribute *attr, const char *buf, size_t len) | |
2607 | { | |
2608 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); | |
2609 | unsigned long new; | |
2610 | int ret = -EINVAL; | |
2611 | ||
2612 | if (!(adapter->capabilities & QLCNIC_FW_CAPABILITY_BDG)) | |
2613 | goto err_out; | |
2614 | ||
2615 | if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC) | |
2616 | goto err_out; | |
2617 | ||
2618 | if (strict_strtoul(buf, 2, &new)) | |
2619 | goto err_out; | |
2620 | ||
2e9d722d | 2621 | if (!adapter->nic_ops->config_bridged_mode(adapter, !!new)) |
af19b491 AKS |
2622 | ret = len; |
2623 | ||
2624 | err_out: | |
2625 | return ret; | |
2626 | } | |
2627 | ||
2628 | static ssize_t | |
2629 | qlcnic_show_bridged_mode(struct device *dev, | |
2630 | struct device_attribute *attr, char *buf) | |
2631 | { | |
2632 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); | |
2633 | int bridged_mode = 0; | |
2634 | ||
2635 | if (adapter->capabilities & QLCNIC_FW_CAPABILITY_BDG) | |
2636 | bridged_mode = !!(adapter->flags & QLCNIC_BRIDGE_ENABLED); | |
2637 | ||
2638 | return sprintf(buf, "%d\n", bridged_mode); | |
2639 | } | |
2640 | ||
2641 | static struct device_attribute dev_attr_bridged_mode = { | |
2642 | .attr = {.name = "bridged_mode", .mode = (S_IRUGO | S_IWUSR)}, | |
2643 | .show = qlcnic_show_bridged_mode, | |
2644 | .store = qlcnic_store_bridged_mode, | |
2645 | }; | |
2646 | ||
2647 | static ssize_t | |
2648 | qlcnic_store_diag_mode(struct device *dev, | |
2649 | struct device_attribute *attr, const char *buf, size_t len) | |
2650 | { | |
2651 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); | |
2652 | unsigned long new; | |
2653 | ||
2654 | if (strict_strtoul(buf, 2, &new)) | |
2655 | return -EINVAL; | |
2656 | ||
2657 | if (!!new != !!(adapter->flags & QLCNIC_DIAG_ENABLED)) | |
2658 | adapter->flags ^= QLCNIC_DIAG_ENABLED; | |
2659 | ||
2660 | return len; | |
2661 | } | |
2662 | ||
2663 | static ssize_t | |
2664 | qlcnic_show_diag_mode(struct device *dev, | |
2665 | struct device_attribute *attr, char *buf) | |
2666 | { | |
2667 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); | |
2668 | ||
2669 | return sprintf(buf, "%d\n", | |
2670 | !!(adapter->flags & QLCNIC_DIAG_ENABLED)); | |
2671 | } | |
2672 | ||
2673 | static struct device_attribute dev_attr_diag_mode = { | |
2674 | .attr = {.name = "diag_mode", .mode = (S_IRUGO | S_IWUSR)}, | |
2675 | .show = qlcnic_show_diag_mode, | |
2676 | .store = qlcnic_store_diag_mode, | |
2677 | }; | |
2678 | ||
2679 | static int | |
2680 | qlcnic_sysfs_validate_crb(struct qlcnic_adapter *adapter, | |
2681 | loff_t offset, size_t size) | |
2682 | { | |
897e8c7c DP |
2683 | size_t crb_size = 4; |
2684 | ||
af19b491 AKS |
2685 | if (!(adapter->flags & QLCNIC_DIAG_ENABLED)) |
2686 | return -EIO; | |
2687 | ||
897e8c7c DP |
2688 | if (offset < QLCNIC_PCI_CRBSPACE) { |
2689 | if (ADDR_IN_RANGE(offset, QLCNIC_PCI_CAMQM, | |
2690 | QLCNIC_PCI_CAMQM_END)) | |
2691 | crb_size = 8; | |
2692 | else | |
2693 | return -EINVAL; | |
2694 | } | |
af19b491 | 2695 | |
897e8c7c DP |
2696 | if ((size != crb_size) || (offset & (crb_size-1))) |
2697 | return -EINVAL; | |
af19b491 AKS |
2698 | |
2699 | return 0; | |
2700 | } | |
2701 | ||
2702 | static ssize_t | |
2c3c8bea CW |
2703 | qlcnic_sysfs_read_crb(struct file *filp, struct kobject *kobj, |
2704 | struct bin_attribute *attr, | |
af19b491 AKS |
2705 | char *buf, loff_t offset, size_t size) |
2706 | { | |
2707 | struct device *dev = container_of(kobj, struct device, kobj); | |
2708 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); | |
2709 | u32 data; | |
897e8c7c | 2710 | u64 qmdata; |
af19b491 AKS |
2711 | int ret; |
2712 | ||
2713 | ret = qlcnic_sysfs_validate_crb(adapter, offset, size); | |
2714 | if (ret != 0) | |
2715 | return ret; | |
2716 | ||
897e8c7c DP |
2717 | if (ADDR_IN_RANGE(offset, QLCNIC_PCI_CAMQM, QLCNIC_PCI_CAMQM_END)) { |
2718 | qlcnic_pci_camqm_read_2M(adapter, offset, &qmdata); | |
2719 | memcpy(buf, &qmdata, size); | |
2720 | } else { | |
2721 | data = QLCRD32(adapter, offset); | |
2722 | memcpy(buf, &data, size); | |
2723 | } | |
af19b491 AKS |
2724 | return size; |
2725 | } | |
2726 | ||
2727 | static ssize_t | |
2c3c8bea CW |
2728 | qlcnic_sysfs_write_crb(struct file *filp, struct kobject *kobj, |
2729 | struct bin_attribute *attr, | |
af19b491 AKS |
2730 | char *buf, loff_t offset, size_t size) |
2731 | { | |
2732 | struct device *dev = container_of(kobj, struct device, kobj); | |
2733 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); | |
2734 | u32 data; | |
897e8c7c | 2735 | u64 qmdata; |
af19b491 AKS |
2736 | int ret; |
2737 | ||
2738 | ret = qlcnic_sysfs_validate_crb(adapter, offset, size); | |
2739 | if (ret != 0) | |
2740 | return ret; | |
2741 | ||
897e8c7c DP |
2742 | if (ADDR_IN_RANGE(offset, QLCNIC_PCI_CAMQM, QLCNIC_PCI_CAMQM_END)) { |
2743 | memcpy(&qmdata, buf, size); | |
2744 | qlcnic_pci_camqm_write_2M(adapter, offset, qmdata); | |
2745 | } else { | |
2746 | memcpy(&data, buf, size); | |
2747 | QLCWR32(adapter, offset, data); | |
2748 | } | |
af19b491 AKS |
2749 | return size; |
2750 | } | |
2751 | ||
2752 | static int | |
2753 | qlcnic_sysfs_validate_mem(struct qlcnic_adapter *adapter, | |
2754 | loff_t offset, size_t size) | |
2755 | { | |
2756 | if (!(adapter->flags & QLCNIC_DIAG_ENABLED)) | |
2757 | return -EIO; | |
2758 | ||
2759 | if ((size != 8) || (offset & 0x7)) | |
2760 | return -EIO; | |
2761 | ||
2762 | return 0; | |
2763 | } | |
2764 | ||
2765 | static ssize_t | |
2c3c8bea CW |
2766 | qlcnic_sysfs_read_mem(struct file *filp, struct kobject *kobj, |
2767 | struct bin_attribute *attr, | |
af19b491 AKS |
2768 | char *buf, loff_t offset, size_t size) |
2769 | { | |
2770 | struct device *dev = container_of(kobj, struct device, kobj); | |
2771 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); | |
2772 | u64 data; | |
2773 | int ret; | |
2774 | ||
2775 | ret = qlcnic_sysfs_validate_mem(adapter, offset, size); | |
2776 | if (ret != 0) | |
2777 | return ret; | |
2778 | ||
2779 | if (qlcnic_pci_mem_read_2M(adapter, offset, &data)) | |
2780 | return -EIO; | |
2781 | ||
2782 | memcpy(buf, &data, size); | |
2783 | ||
2784 | return size; | |
2785 | } | |
2786 | ||
2787 | static ssize_t | |
2c3c8bea CW |
2788 | qlcnic_sysfs_write_mem(struct file *filp, struct kobject *kobj, |
2789 | struct bin_attribute *attr, | |
af19b491 AKS |
2790 | char *buf, loff_t offset, size_t size) |
2791 | { | |
2792 | struct device *dev = container_of(kobj, struct device, kobj); | |
2793 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); | |
2794 | u64 data; | |
2795 | int ret; | |
2796 | ||
2797 | ret = qlcnic_sysfs_validate_mem(adapter, offset, size); | |
2798 | if (ret != 0) | |
2799 | return ret; | |
2800 | ||
2801 | memcpy(&data, buf, size); | |
2802 | ||
2803 | if (qlcnic_pci_mem_write_2M(adapter, offset, data)) | |
2804 | return -EIO; | |
2805 | ||
2806 | return size; | |
2807 | } | |
2808 | ||
2809 | ||
2810 | static struct bin_attribute bin_attr_crb = { | |
2811 | .attr = {.name = "crb", .mode = (S_IRUGO | S_IWUSR)}, | |
2812 | .size = 0, | |
2813 | .read = qlcnic_sysfs_read_crb, | |
2814 | .write = qlcnic_sysfs_write_crb, | |
2815 | }; | |
2816 | ||
2817 | static struct bin_attribute bin_attr_mem = { | |
2818 | .attr = {.name = "mem", .mode = (S_IRUGO | S_IWUSR)}, | |
2819 | .size = 0, | |
2820 | .read = qlcnic_sysfs_read_mem, | |
2821 | .write = qlcnic_sysfs_write_mem, | |
2822 | }; | |
2823 | ||
2824 | static void | |
2825 | qlcnic_create_sysfs_entries(struct qlcnic_adapter *adapter) | |
2826 | { | |
2827 | struct device *dev = &adapter->pdev->dev; | |
2828 | ||
2829 | if (adapter->capabilities & QLCNIC_FW_CAPABILITY_BDG) | |
2830 | if (device_create_file(dev, &dev_attr_bridged_mode)) | |
2831 | dev_warn(dev, | |
2832 | "failed to create bridged_mode sysfs entry\n"); | |
2833 | } | |
2834 | ||
2835 | static void | |
2836 | qlcnic_remove_sysfs_entries(struct qlcnic_adapter *adapter) | |
2837 | { | |
2838 | struct device *dev = &adapter->pdev->dev; | |
2839 | ||
2840 | if (adapter->capabilities & QLCNIC_FW_CAPABILITY_BDG) | |
2841 | device_remove_file(dev, &dev_attr_bridged_mode); | |
2842 | } | |
2843 | ||
2844 | static void | |
2845 | qlcnic_create_diag_entries(struct qlcnic_adapter *adapter) | |
2846 | { | |
2847 | struct device *dev = &adapter->pdev->dev; | |
2848 | ||
2849 | if (device_create_file(dev, &dev_attr_diag_mode)) | |
2850 | dev_info(dev, "failed to create diag_mode sysfs entry\n"); | |
2851 | if (device_create_bin_file(dev, &bin_attr_crb)) | |
2852 | dev_info(dev, "failed to create crb sysfs entry\n"); | |
2853 | if (device_create_bin_file(dev, &bin_attr_mem)) | |
2854 | dev_info(dev, "failed to create mem sysfs entry\n"); | |
2855 | } | |
2856 | ||
2857 | ||
2858 | static void | |
2859 | qlcnic_remove_diag_entries(struct qlcnic_adapter *adapter) | |
2860 | { | |
2861 | struct device *dev = &adapter->pdev->dev; | |
2862 | ||
2863 | device_remove_file(dev, &dev_attr_diag_mode); | |
2864 | device_remove_bin_file(dev, &bin_attr_crb); | |
2865 | device_remove_bin_file(dev, &bin_attr_mem); | |
2866 | } | |
2867 | ||
2868 | #ifdef CONFIG_INET | |
2869 | ||
2870 | #define is_qlcnic_netdev(dev) (dev->netdev_ops == &qlcnic_netdev_ops) | |
2871 | ||
af19b491 AKS |
2872 | static void |
2873 | qlcnic_config_indev_addr(struct net_device *dev, unsigned long event) | |
2874 | { | |
2875 | struct in_device *indev; | |
2876 | struct qlcnic_adapter *adapter = netdev_priv(dev); | |
2877 | ||
af19b491 AKS |
2878 | indev = in_dev_get(dev); |
2879 | if (!indev) | |
2880 | return; | |
2881 | ||
2882 | for_ifa(indev) { | |
2883 | switch (event) { | |
2884 | case NETDEV_UP: | |
2885 | qlcnic_config_ipaddr(adapter, | |
2886 | ifa->ifa_address, QLCNIC_IP_UP); | |
2887 | break; | |
2888 | case NETDEV_DOWN: | |
2889 | qlcnic_config_ipaddr(adapter, | |
2890 | ifa->ifa_address, QLCNIC_IP_DOWN); | |
2891 | break; | |
2892 | default: | |
2893 | break; | |
2894 | } | |
2895 | } endfor_ifa(indev); | |
2896 | ||
2897 | in_dev_put(indev); | |
af19b491 AKS |
2898 | } |
2899 | ||
2900 | static int qlcnic_netdev_event(struct notifier_block *this, | |
2901 | unsigned long event, void *ptr) | |
2902 | { | |
2903 | struct qlcnic_adapter *adapter; | |
2904 | struct net_device *dev = (struct net_device *)ptr; | |
2905 | ||
2906 | recheck: | |
2907 | if (dev == NULL) | |
2908 | goto done; | |
2909 | ||
2910 | if (dev->priv_flags & IFF_802_1Q_VLAN) { | |
2911 | dev = vlan_dev_real_dev(dev); | |
2912 | goto recheck; | |
2913 | } | |
2914 | ||
2915 | if (!is_qlcnic_netdev(dev)) | |
2916 | goto done; | |
2917 | ||
2918 | adapter = netdev_priv(dev); | |
2919 | ||
2920 | if (!adapter) | |
2921 | goto done; | |
2922 | ||
2923 | if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC) | |
2924 | goto done; | |
2925 | ||
2926 | qlcnic_config_indev_addr(dev, event); | |
2927 | done: | |
2928 | return NOTIFY_DONE; | |
2929 | } | |
2930 | ||
2931 | static int | |
2932 | qlcnic_inetaddr_event(struct notifier_block *this, | |
2933 | unsigned long event, void *ptr) | |
2934 | { | |
2935 | struct qlcnic_adapter *adapter; | |
2936 | struct net_device *dev; | |
2937 | ||
2938 | struct in_ifaddr *ifa = (struct in_ifaddr *)ptr; | |
2939 | ||
2940 | dev = ifa->ifa_dev ? ifa->ifa_dev->dev : NULL; | |
2941 | ||
2942 | recheck: | |
2943 | if (dev == NULL || !netif_running(dev)) | |
2944 | goto done; | |
2945 | ||
2946 | if (dev->priv_flags & IFF_802_1Q_VLAN) { | |
2947 | dev = vlan_dev_real_dev(dev); | |
2948 | goto recheck; | |
2949 | } | |
2950 | ||
2951 | if (!is_qlcnic_netdev(dev)) | |
2952 | goto done; | |
2953 | ||
2954 | adapter = netdev_priv(dev); | |
2955 | ||
251a84c9 | 2956 | if (!adapter) |
af19b491 AKS |
2957 | goto done; |
2958 | ||
2959 | if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC) | |
2960 | goto done; | |
2961 | ||
2962 | switch (event) { | |
2963 | case NETDEV_UP: | |
2964 | qlcnic_config_ipaddr(adapter, ifa->ifa_address, QLCNIC_IP_UP); | |
2965 | break; | |
2966 | case NETDEV_DOWN: | |
2967 | qlcnic_config_ipaddr(adapter, ifa->ifa_address, QLCNIC_IP_DOWN); | |
2968 | break; | |
2969 | default: | |
2970 | break; | |
2971 | } | |
2972 | ||
2973 | done: | |
2974 | return NOTIFY_DONE; | |
2975 | } | |
2976 | ||
2977 | static struct notifier_block qlcnic_netdev_cb = { | |
2978 | .notifier_call = qlcnic_netdev_event, | |
2979 | }; | |
2980 | ||
2981 | static struct notifier_block qlcnic_inetaddr_cb = { | |
2982 | .notifier_call = qlcnic_inetaddr_event, | |
2983 | }; | |
2984 | #else | |
2985 | static void | |
2986 | qlcnic_config_indev_addr(struct net_device *dev, unsigned long event) | |
2987 | { } | |
2988 | #endif | |
2989 | ||
2990 | static struct pci_driver qlcnic_driver = { | |
2991 | .name = qlcnic_driver_name, | |
2992 | .id_table = qlcnic_pci_tbl, | |
2993 | .probe = qlcnic_probe, | |
2994 | .remove = __devexit_p(qlcnic_remove), | |
2995 | #ifdef CONFIG_PM | |
2996 | .suspend = qlcnic_suspend, | |
2997 | .resume = qlcnic_resume, | |
2998 | #endif | |
2999 | .shutdown = qlcnic_shutdown | |
3000 | }; | |
3001 | ||
3002 | static int __init qlcnic_init_module(void) | |
3003 | { | |
3004 | ||
3005 | printk(KERN_INFO "%s\n", qlcnic_driver_string); | |
3006 | ||
3007 | #ifdef CONFIG_INET | |
3008 | register_netdevice_notifier(&qlcnic_netdev_cb); | |
3009 | register_inetaddr_notifier(&qlcnic_inetaddr_cb); | |
3010 | #endif | |
3011 | ||
3012 | ||
3013 | return pci_register_driver(&qlcnic_driver); | |
3014 | } | |
3015 | ||
3016 | module_init(qlcnic_init_module); | |
3017 | ||
3018 | static void __exit qlcnic_exit_module(void) | |
3019 | { | |
3020 | ||
3021 | pci_unregister_driver(&qlcnic_driver); | |
3022 | ||
3023 | #ifdef CONFIG_INET | |
3024 | unregister_inetaddr_notifier(&qlcnic_inetaddr_cb); | |
3025 | unregister_netdevice_notifier(&qlcnic_netdev_cb); | |
3026 | #endif | |
3027 | } | |
3028 | ||
3029 | module_exit(qlcnic_exit_module); |