1 /*
2 * Copyright (C) 2003 - 2009 NetXen, Inc.
3 * Copyright (C) 2009 - QLogic Corporation.
4 * All rights reserved.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
19 * MA 02111-1307, USA.
20 *
21 * The full GNU General Public License is included in this distribution
22 * in the file called "COPYING".
23 *
24 */
25
26 #include <linux/slab.h>
27 #include <linux/vmalloc.h>
28 #include <linux/interrupt.h>
29 #include "netxen_nic_hw.h"
30
31 #include "netxen_nic.h"
32
33 #include <linux/dma-mapping.h>
34 #include <linux/if_vlan.h>
35 #include <net/ip.h>
36 #include <linux/ipv6.h>
37 #include <linux/inetdevice.h>
38 #include <linux/sysfs.h>
39 #include <linux/aer.h>
40
41 MODULE_DESCRIPTION("QLogic/NetXen (1/10) GbE Intelligent Ethernet Driver");
42 MODULE_LICENSE("GPL");
43 MODULE_VERSION(NETXEN_NIC_LINUX_VERSIONID);
44 MODULE_FIRMWARE(NX_UNIFIED_ROMIMAGE_NAME);
45
46 char netxen_nic_driver_name[] = "netxen_nic";
47 static char netxen_nic_driver_string[] = "QLogic/NetXen Network Driver v"
48 NETXEN_NIC_LINUX_VERSIONID;
49
50 static int port_mode = NETXEN_PORT_MODE_AUTO_NEG;
51
52 /* Default to restricted 1G auto-neg mode */
53 static int wol_port_mode = 5;
54
55 static int use_msi = 1;
56
57 static int use_msi_x = 1;
58
59 static int auto_fw_reset = AUTO_FW_RESET_ENABLED;
60 module_param(auto_fw_reset, int, 0644);
61 MODULE_PARM_DESC(auto_fw_reset,"Auto firmware reset (0=disabled, 1=enabled");
62
63 static int __devinit netxen_nic_probe(struct pci_dev *pdev,
64 const struct pci_device_id *ent);
65 static void __devexit netxen_nic_remove(struct pci_dev *pdev);
66 static int netxen_nic_open(struct net_device *netdev);
67 static int netxen_nic_close(struct net_device *netdev);
68 static netdev_tx_t netxen_nic_xmit_frame(struct sk_buff *,
69 struct net_device *);
70 static void netxen_tx_timeout(struct net_device *netdev);
71 static void netxen_tx_timeout_task(struct work_struct *work);
72 static void netxen_fw_poll_work(struct work_struct *work);
73 static void netxen_schedule_work(struct netxen_adapter *adapter,
74 work_func_t func, int delay);
75 static void netxen_cancel_fw_work(struct netxen_adapter *adapter);
76 static int netxen_nic_poll(struct napi_struct *napi, int budget);
77 #ifdef CONFIG_NET_POLL_CONTROLLER
78 static void netxen_nic_poll_controller(struct net_device *netdev);
79 #endif
80
81 static void netxen_create_sysfs_entries(struct netxen_adapter *adapter);
82 static void netxen_remove_sysfs_entries(struct netxen_adapter *adapter);
83 static void netxen_create_diag_entries(struct netxen_adapter *adapter);
84 static void netxen_remove_diag_entries(struct netxen_adapter *adapter);
85 static int nx_dev_request_aer(struct netxen_adapter *adapter);
86 static int nx_decr_dev_ref_cnt(struct netxen_adapter *adapter);
87 static int netxen_can_start_firmware(struct netxen_adapter *adapter);
88
89 static irqreturn_t netxen_intr(int irq, void *data);
90 static irqreturn_t netxen_msi_intr(int irq, void *data);
91 static irqreturn_t netxen_msix_intr(int irq, void *data);
92
93 static void netxen_free_vlan_ip_list(struct netxen_adapter *);
94 static void netxen_restore_indev_addr(struct net_device *dev, unsigned long);
95 static struct rtnl_link_stats64 *netxen_nic_get_stats(struct net_device *dev,
96 struct rtnl_link_stats64 *stats);
97 static int netxen_nic_set_mac(struct net_device *netdev, void *p);
98
99 /* PCI Device ID Table */
100 #define ENTRY(device) \
101 {PCI_DEVICE(PCI_VENDOR_ID_NETXEN, (device)), \
102 .class = PCI_CLASS_NETWORK_ETHERNET << 8, .class_mask = ~0}
103
104 static DEFINE_PCI_DEVICE_TABLE(netxen_pci_tbl) = {
105 ENTRY(PCI_DEVICE_ID_NX2031_10GXSR),
106 ENTRY(PCI_DEVICE_ID_NX2031_10GCX4),
107 ENTRY(PCI_DEVICE_ID_NX2031_4GCU),
108 ENTRY(PCI_DEVICE_ID_NX2031_IMEZ),
109 ENTRY(PCI_DEVICE_ID_NX2031_HMEZ),
110 ENTRY(PCI_DEVICE_ID_NX2031_XG_MGMT),
111 ENTRY(PCI_DEVICE_ID_NX2031_XG_MGMT2),
112 ENTRY(PCI_DEVICE_ID_NX3031),
113 {0,}
114 };
115
116 MODULE_DEVICE_TABLE(pci, netxen_pci_tbl);
117
118 static uint32_t crb_cmd_producer[4] = {
119 CRB_CMD_PRODUCER_OFFSET, CRB_CMD_PRODUCER_OFFSET_1,
120 CRB_CMD_PRODUCER_OFFSET_2, CRB_CMD_PRODUCER_OFFSET_3
121 };
122
123 void
netxen_nic_update_cmd_producer(struct netxen_adapter * adapter,struct nx_host_tx_ring * tx_ring)124 netxen_nic_update_cmd_producer(struct netxen_adapter *adapter,
125 struct nx_host_tx_ring *tx_ring)
126 {
127 NXWRIO(adapter, tx_ring->crb_cmd_producer, tx_ring->producer);
128 }
129
130 static uint32_t crb_cmd_consumer[4] = {
131 CRB_CMD_CONSUMER_OFFSET, CRB_CMD_CONSUMER_OFFSET_1,
132 CRB_CMD_CONSUMER_OFFSET_2, CRB_CMD_CONSUMER_OFFSET_3
133 };
134
135 static inline void
netxen_nic_update_cmd_consumer(struct netxen_adapter * adapter,struct nx_host_tx_ring * tx_ring)136 netxen_nic_update_cmd_consumer(struct netxen_adapter *adapter,
137 struct nx_host_tx_ring *tx_ring)
138 {
139 NXWRIO(adapter, tx_ring->crb_cmd_consumer, tx_ring->sw_consumer);
140 }
141
142 static uint32_t 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 struct netxen_legacy_intr_set legacy_intr[] = NX_LEGACY_INTR_CONFIG;
150
netxen_nic_disable_int(struct nx_host_sds_ring * sds_ring)151 static inline void netxen_nic_disable_int(struct nx_host_sds_ring *sds_ring)
152 {
153 struct netxen_adapter *adapter = sds_ring->adapter;
154
155 NXWRIO(adapter, sds_ring->crb_intr_mask, 0);
156 }
157
netxen_nic_enable_int(struct nx_host_sds_ring * sds_ring)158 static inline void netxen_nic_enable_int(struct nx_host_sds_ring *sds_ring)
159 {
160 struct netxen_adapter *adapter = sds_ring->adapter;
161
162 NXWRIO(adapter, sds_ring->crb_intr_mask, 0x1);
163
164 if (!NETXEN_IS_MSI_FAMILY(adapter))
165 NXWRIO(adapter, adapter->tgt_mask_reg, 0xfbff);
166 }
167
168 static int
netxen_alloc_sds_rings(struct netxen_recv_context * recv_ctx,int count)169 netxen_alloc_sds_rings(struct netxen_recv_context *recv_ctx, int count)
170 {
171 int size = sizeof(struct nx_host_sds_ring) * count;
172
173 recv_ctx->sds_rings = kzalloc(size, GFP_KERNEL);
174
175 return recv_ctx->sds_rings == NULL;
176 }
177
178 static void
netxen_free_sds_rings(struct netxen_recv_context * recv_ctx)179 netxen_free_sds_rings(struct netxen_recv_context *recv_ctx)
180 {
181 if (recv_ctx->sds_rings != NULL)
182 kfree(recv_ctx->sds_rings);
183
184 recv_ctx->sds_rings = NULL;
185 }
186
187 static int
netxen_napi_add(struct netxen_adapter * adapter,struct net_device * netdev)188 netxen_napi_add(struct netxen_adapter *adapter, struct net_device *netdev)
189 {
190 int ring;
191 struct nx_host_sds_ring *sds_ring;
192 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
193
194 if (netxen_alloc_sds_rings(recv_ctx, adapter->max_sds_rings))
195 return -ENOMEM;
196
197 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
198 sds_ring = &recv_ctx->sds_rings[ring];
199 netif_napi_add(netdev, &sds_ring->napi,
200 netxen_nic_poll, NETXEN_NETDEV_WEIGHT);
201 }
202
203 return 0;
204 }
205
206 static void
netxen_napi_del(struct netxen_adapter * adapter)207 netxen_napi_del(struct netxen_adapter *adapter)
208 {
209 int ring;
210 struct nx_host_sds_ring *sds_ring;
211 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
212
213 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
214 sds_ring = &recv_ctx->sds_rings[ring];
215 netif_napi_del(&sds_ring->napi);
216 }
217
218 netxen_free_sds_rings(&adapter->recv_ctx);
219 }
220
221 static void
netxen_napi_enable(struct netxen_adapter * adapter)222 netxen_napi_enable(struct netxen_adapter *adapter)
223 {
224 int ring;
225 struct nx_host_sds_ring *sds_ring;
226 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
227
228 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
229 sds_ring = &recv_ctx->sds_rings[ring];
230 napi_enable(&sds_ring->napi);
231 netxen_nic_enable_int(sds_ring);
232 }
233 }
234
235 static void
netxen_napi_disable(struct netxen_adapter * adapter)236 netxen_napi_disable(struct netxen_adapter *adapter)
237 {
238 int ring;
239 struct nx_host_sds_ring *sds_ring;
240 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
241
242 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
243 sds_ring = &recv_ctx->sds_rings[ring];
244 netxen_nic_disable_int(sds_ring);
245 napi_synchronize(&sds_ring->napi);
246 napi_disable(&sds_ring->napi);
247 }
248 }
249
nx_set_dma_mask(struct netxen_adapter * adapter)250 static int nx_set_dma_mask(struct netxen_adapter *adapter)
251 {
252 struct pci_dev *pdev = adapter->pdev;
253 uint64_t mask, cmask;
254
255 adapter->pci_using_dac = 0;
256
257 mask = DMA_BIT_MASK(32);
258 cmask = DMA_BIT_MASK(32);
259
260 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
261 #ifndef CONFIG_IA64
262 mask = DMA_BIT_MASK(35);
263 #endif
264 } else {
265 mask = DMA_BIT_MASK(39);
266 cmask = mask;
267 }
268
269 if (pci_set_dma_mask(pdev, mask) == 0 &&
270 pci_set_consistent_dma_mask(pdev, cmask) == 0) {
271 adapter->pci_using_dac = 1;
272 return 0;
273 }
274
275 return -EIO;
276 }
277
278 /* Update addressable range if firmware supports it */
279 static int
nx_update_dma_mask(struct netxen_adapter * adapter)280 nx_update_dma_mask(struct netxen_adapter *adapter)
281 {
282 int change, shift, err;
283 uint64_t mask, old_mask, old_cmask;
284 struct pci_dev *pdev = adapter->pdev;
285
286 change = 0;
287
288 shift = NXRD32(adapter, CRB_DMA_SHIFT);
289 if (shift > 32)
290 return 0;
291
292 if (NX_IS_REVISION_P3(adapter->ahw.revision_id) && (shift > 9))
293 change = 1;
294 else if ((adapter->ahw.revision_id == NX_P2_C1) && (shift <= 4))
295 change = 1;
296
297 if (change) {
298 old_mask = pdev->dma_mask;
299 old_cmask = pdev->dev.coherent_dma_mask;
300
301 mask = DMA_BIT_MASK(32+shift);
302
303 err = pci_set_dma_mask(pdev, mask);
304 if (err)
305 goto err_out;
306
307 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
308
309 err = pci_set_consistent_dma_mask(pdev, mask);
310 if (err)
311 goto err_out;
312 }
313 dev_info(&pdev->dev, "using %d-bit dma mask\n", 32+shift);
314 }
315
316 return 0;
317
318 err_out:
319 pci_set_dma_mask(pdev, old_mask);
320 pci_set_consistent_dma_mask(pdev, old_cmask);
321 return err;
322 }
323
324 static int
netxen_check_hw_init(struct netxen_adapter * adapter,int first_boot)325 netxen_check_hw_init(struct netxen_adapter *adapter, int first_boot)
326 {
327 u32 val, timeout;
328
329 if (first_boot == 0x55555555) {
330 /* This is the first boot after power up */
331 NXWR32(adapter, NETXEN_CAM_RAM(0x1fc), NETXEN_BDINFO_MAGIC);
332
333 if (!NX_IS_REVISION_P2(adapter->ahw.revision_id))
334 return 0;
335
336 /* PCI bus master workaround */
337 first_boot = NXRD32(adapter, NETXEN_PCIE_REG(0x4));
338 if (!(first_boot & 0x4)) {
339 first_boot |= 0x4;
340 NXWR32(adapter, NETXEN_PCIE_REG(0x4), first_boot);
341 NXRD32(adapter, NETXEN_PCIE_REG(0x4));
342 }
343
344 /* This is the first boot after power up */
345 first_boot = NXRD32(adapter, NETXEN_ROMUSB_GLB_SW_RESET);
346 if (first_boot != 0x80000f) {
347 /* clear the register for future unloads/loads */
348 NXWR32(adapter, NETXEN_CAM_RAM(0x1fc), 0);
349 return -EIO;
350 }
351
352 /* Start P2 boot loader */
353 val = NXRD32(adapter, NETXEN_ROMUSB_GLB_PEGTUNE_DONE);
354 NXWR32(adapter, NETXEN_ROMUSB_GLB_PEGTUNE_DONE, val | 0x1);
355 timeout = 0;
356 do {
357 msleep(1);
358 val = NXRD32(adapter, NETXEN_CAM_RAM(0x1fc));
359
360 if (++timeout > 5000)
361 return -EIO;
362
363 } while (val == NETXEN_BDINFO_MAGIC);
364 }
365 return 0;
366 }
367
netxen_set_port_mode(struct netxen_adapter * adapter)368 static void netxen_set_port_mode(struct netxen_adapter *adapter)
369 {
370 u32 val, data;
371
372 val = adapter->ahw.board_type;
373 if ((val == NETXEN_BRDTYPE_P3_HMEZ) ||
374 (val == NETXEN_BRDTYPE_P3_XG_LOM)) {
375 if (port_mode == NETXEN_PORT_MODE_802_3_AP) {
376 data = NETXEN_PORT_MODE_802_3_AP;
377 NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data);
378 } else if (port_mode == NETXEN_PORT_MODE_XG) {
379 data = NETXEN_PORT_MODE_XG;
380 NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data);
381 } else if (port_mode == NETXEN_PORT_MODE_AUTO_NEG_1G) {
382 data = NETXEN_PORT_MODE_AUTO_NEG_1G;
383 NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data);
384 } else if (port_mode == NETXEN_PORT_MODE_AUTO_NEG_XG) {
385 data = NETXEN_PORT_MODE_AUTO_NEG_XG;
386 NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data);
387 } else {
388 data = NETXEN_PORT_MODE_AUTO_NEG;
389 NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data);
390 }
391
392 if ((wol_port_mode != NETXEN_PORT_MODE_802_3_AP) &&
393 (wol_port_mode != NETXEN_PORT_MODE_XG) &&
394 (wol_port_mode != NETXEN_PORT_MODE_AUTO_NEG_1G) &&
395 (wol_port_mode != NETXEN_PORT_MODE_AUTO_NEG_XG)) {
396 wol_port_mode = NETXEN_PORT_MODE_AUTO_NEG;
397 }
398 NXWR32(adapter, NETXEN_WOL_PORT_MODE, wol_port_mode);
399 }
400 }
401
402 #define PCI_CAP_ID_GEN 0x10
403
netxen_pcie_strap_init(struct netxen_adapter * adapter)404 static void netxen_pcie_strap_init(struct netxen_adapter *adapter)
405 {
406 u32 pdevfuncsave;
407 u32 c8c9value = 0;
408 u32 chicken = 0;
409 u32 control = 0;
410 int i, pos;
411 struct pci_dev *pdev;
412
413 pdev = adapter->pdev;
414
415 chicken = NXRD32(adapter, NETXEN_PCIE_REG(PCIE_CHICKEN3));
416 /* clear chicken3.25:24 */
417 chicken &= 0xFCFFFFFF;
418 /*
419 * if gen1 and B0, set F1020 - if gen 2, do nothing
420 * if gen2 set to F1000
421 */
422 pos = pci_find_capability(pdev, PCI_CAP_ID_GEN);
423 if (pos == 0xC0) {
424 pci_read_config_dword(pdev, pos + 0x10, &control);
425 if ((control & 0x000F0000) != 0x00020000) {
426 /* set chicken3.24 if gen1 */
427 chicken |= 0x01000000;
428 }
429 dev_info(&adapter->pdev->dev, "Gen2 strapping detected\n");
430 c8c9value = 0xF1000;
431 } else {
432 /* set chicken3.24 if gen1 */
433 chicken |= 0x01000000;
434 dev_info(&adapter->pdev->dev, "Gen1 strapping detected\n");
435 if (adapter->ahw.revision_id == NX_P3_B0)
436 c8c9value = 0xF1020;
437 else
438 c8c9value = 0;
439 }
440
441 NXWR32(adapter, NETXEN_PCIE_REG(PCIE_CHICKEN3), chicken);
442
443 if (!c8c9value)
444 return;
445
446 pdevfuncsave = pdev->devfn;
447 if (pdevfuncsave & 0x07)
448 return;
449
450 for (i = 0; i < 8; i++) {
451 pci_read_config_dword(pdev, pos + 8, &control);
452 pci_read_config_dword(pdev, pos + 8, &control);
453 pci_write_config_dword(pdev, pos + 8, c8c9value);
454 pdev->devfn++;
455 }
456 pdev->devfn = pdevfuncsave;
457 }
458
netxen_set_msix_bit(struct pci_dev * pdev,int enable)459 static void netxen_set_msix_bit(struct pci_dev *pdev, int enable)
460 {
461 u32 control;
462 int pos;
463
464 pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
465 if (pos) {
466 pci_read_config_dword(pdev, pos, &control);
467 if (enable)
468 control |= PCI_MSIX_FLAGS_ENABLE;
469 else
470 control = 0;
471 pci_write_config_dword(pdev, pos, control);
472 }
473 }
474
netxen_init_msix_entries(struct netxen_adapter * adapter,int count)475 static void netxen_init_msix_entries(struct netxen_adapter *adapter, int count)
476 {
477 int i;
478
479 for (i = 0; i < count; i++)
480 adapter->msix_entries[i].entry = i;
481 }
482
483 static int
netxen_read_mac_addr(struct netxen_adapter * adapter)484 netxen_read_mac_addr(struct netxen_adapter *adapter)
485 {
486 int i;
487 unsigned char *p;
488 u64 mac_addr;
489 struct net_device *netdev = adapter->netdev;
490 struct pci_dev *pdev = adapter->pdev;
491
492 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
493 if (netxen_p3_get_mac_addr(adapter, &mac_addr) != 0)
494 return -EIO;
495 } else {
496 if (netxen_get_flash_mac_addr(adapter, &mac_addr) != 0)
497 return -EIO;
498 }
499
500 p = (unsigned char *)&mac_addr;
501 for (i = 0; i < 6; i++)
502 netdev->dev_addr[i] = *(p + 5 - i);
503
504 memcpy(netdev->perm_addr, netdev->dev_addr, netdev->addr_len);
505 memcpy(adapter->mac_addr, netdev->dev_addr, netdev->addr_len);
506
507 /* set station address */
508
509 if (!is_valid_ether_addr(netdev->perm_addr))
510 dev_warn(&pdev->dev, "Bad MAC address %pM.\n", netdev->dev_addr);
511
512 return 0;
513 }
514
netxen_nic_set_mac(struct net_device * netdev,void * p)515 static int netxen_nic_set_mac(struct net_device *netdev, void *p)
516 {
517 struct netxen_adapter *adapter = netdev_priv(netdev);
518 struct sockaddr *addr = p;
519
520 if (!is_valid_ether_addr(addr->sa_data))
521 return -EADDRNOTAVAIL;
522
523 if (netif_running(netdev)) {
524 netif_device_detach(netdev);
525 netxen_napi_disable(adapter);
526 }
527
528 memcpy(adapter->mac_addr, addr->sa_data, netdev->addr_len);
529 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
530 adapter->macaddr_set(adapter, addr->sa_data);
531
532 if (netif_running(netdev)) {
533 netif_device_attach(netdev);
534 netxen_napi_enable(adapter);
535 }
536 return 0;
537 }
538
netxen_set_multicast_list(struct net_device * dev)539 static void netxen_set_multicast_list(struct net_device *dev)
540 {
541 struct netxen_adapter *adapter = netdev_priv(dev);
542
543 adapter->set_multi(dev);
544 }
545
netxen_fix_features(struct net_device * dev,netdev_features_t features)546 static netdev_features_t netxen_fix_features(struct net_device *dev,
547 netdev_features_t features)
548 {
549 if (!(features & NETIF_F_RXCSUM)) {
550 netdev_info(dev, "disabling LRO as RXCSUM is off\n");
551
552 features &= ~NETIF_F_LRO;
553 }
554
555 return features;
556 }
557
netxen_set_features(struct net_device * dev,netdev_features_t features)558 static int netxen_set_features(struct net_device *dev,
559 netdev_features_t features)
560 {
561 struct netxen_adapter *adapter = netdev_priv(dev);
562 int hw_lro;
563
564 if (!((dev->features ^ features) & NETIF_F_LRO))
565 return 0;
566
567 hw_lro = (features & NETIF_F_LRO) ? NETXEN_NIC_LRO_ENABLED
568 : NETXEN_NIC_LRO_DISABLED;
569
570 if (netxen_config_hw_lro(adapter, hw_lro))
571 return -EIO;
572
573 if (!(features & NETIF_F_LRO) && netxen_send_lro_cleanup(adapter))
574 return -EIO;
575
576 return 0;
577 }
578
579 static const struct net_device_ops netxen_netdev_ops = {
580 .ndo_open = netxen_nic_open,
581 .ndo_stop = netxen_nic_close,
582 .ndo_start_xmit = netxen_nic_xmit_frame,
583 .ndo_get_stats64 = netxen_nic_get_stats,
584 .ndo_validate_addr = eth_validate_addr,
585 .ndo_set_rx_mode = netxen_set_multicast_list,
586 .ndo_set_mac_address = netxen_nic_set_mac,
587 .ndo_change_mtu = netxen_nic_change_mtu,
588 .ndo_tx_timeout = netxen_tx_timeout,
589 .ndo_fix_features = netxen_fix_features,
590 .ndo_set_features = netxen_set_features,
591 #ifdef CONFIG_NET_POLL_CONTROLLER
592 .ndo_poll_controller = netxen_nic_poll_controller,
593 #endif
594 };
595
596 static void
netxen_setup_intr(struct netxen_adapter * adapter)597 netxen_setup_intr(struct netxen_adapter *adapter)
598 {
599 struct netxen_legacy_intr_set *legacy_intrp;
600 struct pci_dev *pdev = adapter->pdev;
601 int err, num_msix;
602
603 if (adapter->rss_supported) {
604 num_msix = (num_online_cpus() >= MSIX_ENTRIES_PER_ADAPTER) ?
605 MSIX_ENTRIES_PER_ADAPTER : 2;
606 } else
607 num_msix = 1;
608
609 adapter->max_sds_rings = 1;
610
611 adapter->flags &= ~(NETXEN_NIC_MSI_ENABLED | NETXEN_NIC_MSIX_ENABLED);
612
613 if (adapter->ahw.revision_id >= NX_P3_B0)
614 legacy_intrp = &legacy_intr[adapter->ahw.pci_func];
615 else
616 legacy_intrp = &legacy_intr[0];
617
618 adapter->int_vec_bit = legacy_intrp->int_vec_bit;
619 adapter->tgt_status_reg = netxen_get_ioaddr(adapter,
620 legacy_intrp->tgt_status_reg);
621 adapter->tgt_mask_reg = netxen_get_ioaddr(adapter,
622 legacy_intrp->tgt_mask_reg);
623 adapter->pci_int_reg = netxen_get_ioaddr(adapter,
624 legacy_intrp->pci_int_reg);
625 adapter->isr_int_vec = netxen_get_ioaddr(adapter, ISR_INT_VECTOR);
626
627 if (adapter->ahw.revision_id >= NX_P3_B1)
628 adapter->crb_int_state_reg = netxen_get_ioaddr(adapter,
629 ISR_INT_STATE_REG);
630 else
631 adapter->crb_int_state_reg = netxen_get_ioaddr(adapter,
632 CRB_INT_VECTOR);
633
634 netxen_set_msix_bit(pdev, 0);
635
636 if (adapter->msix_supported) {
637
638 netxen_init_msix_entries(adapter, num_msix);
639 err = pci_enable_msix(pdev, adapter->msix_entries, num_msix);
640 if (err == 0) {
641 adapter->flags |= NETXEN_NIC_MSIX_ENABLED;
642 netxen_set_msix_bit(pdev, 1);
643
644 if (adapter->rss_supported)
645 adapter->max_sds_rings = num_msix;
646
647 dev_info(&pdev->dev, "using msi-x interrupts\n");
648 return;
649 }
650
651 if (err > 0)
652 pci_disable_msix(pdev);
653
654 /* fall through for msi */
655 }
656
657 if (use_msi && !pci_enable_msi(pdev)) {
658 adapter->flags |= NETXEN_NIC_MSI_ENABLED;
659 adapter->tgt_status_reg = netxen_get_ioaddr(adapter,
660 msi_tgt_status[adapter->ahw.pci_func]);
661 dev_info(&pdev->dev, "using msi interrupts\n");
662 adapter->msix_entries[0].vector = pdev->irq;
663 return;
664 }
665
666 dev_info(&pdev->dev, "using legacy interrupts\n");
667 adapter->msix_entries[0].vector = pdev->irq;
668 }
669
670 static void
netxen_teardown_intr(struct netxen_adapter * adapter)671 netxen_teardown_intr(struct netxen_adapter *adapter)
672 {
673 if (adapter->flags & NETXEN_NIC_MSIX_ENABLED)
674 pci_disable_msix(adapter->pdev);
675 if (adapter->flags & NETXEN_NIC_MSI_ENABLED)
676 pci_disable_msi(adapter->pdev);
677 }
678
679 static void
netxen_cleanup_pci_map(struct netxen_adapter * adapter)680 netxen_cleanup_pci_map(struct netxen_adapter *adapter)
681 {
682 if (adapter->ahw.db_base != NULL)
683 iounmap(adapter->ahw.db_base);
684 if (adapter->ahw.pci_base0 != NULL)
685 iounmap(adapter->ahw.pci_base0);
686 if (adapter->ahw.pci_base1 != NULL)
687 iounmap(adapter->ahw.pci_base1);
688 if (adapter->ahw.pci_base2 != NULL)
689 iounmap(adapter->ahw.pci_base2);
690 }
691
692 static int
netxen_setup_pci_map(struct netxen_adapter * adapter)693 netxen_setup_pci_map(struct netxen_adapter *adapter)
694 {
695 void __iomem *db_ptr = NULL;
696
697 resource_size_t mem_base, db_base;
698 unsigned long mem_len, db_len = 0;
699
700 struct pci_dev *pdev = adapter->pdev;
701 int pci_func = adapter->ahw.pci_func;
702 struct netxen_hardware_context *ahw = &adapter->ahw;
703
704 int err = 0;
705
706 /*
707 * Set the CRB window to invalid. If any register in window 0 is
708 * accessed it should set the window to 0 and then reset it to 1.
709 */
710 adapter->ahw.crb_win = -1;
711 adapter->ahw.ocm_win = -1;
712
713 /* remap phys address */
714 mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
715 mem_len = pci_resource_len(pdev, 0);
716
717 /* 128 Meg of memory */
718 if (mem_len == NETXEN_PCI_128MB_SIZE) {
719
720 ahw->pci_base0 = ioremap(mem_base, FIRST_PAGE_GROUP_SIZE);
721 ahw->pci_base1 = ioremap(mem_base + SECOND_PAGE_GROUP_START,
722 SECOND_PAGE_GROUP_SIZE);
723 ahw->pci_base2 = ioremap(mem_base + THIRD_PAGE_GROUP_START,
724 THIRD_PAGE_GROUP_SIZE);
725 if (ahw->pci_base0 == NULL || ahw->pci_base1 == NULL ||
726 ahw->pci_base2 == NULL) {
727 dev_err(&pdev->dev, "failed to map PCI bar 0\n");
728 err = -EIO;
729 goto err_out;
730 }
731
732 ahw->pci_len0 = FIRST_PAGE_GROUP_SIZE;
733
734 } else if (mem_len == NETXEN_PCI_32MB_SIZE) {
735
736 ahw->pci_base1 = ioremap(mem_base, SECOND_PAGE_GROUP_SIZE);
737 ahw->pci_base2 = ioremap(mem_base + THIRD_PAGE_GROUP_START -
738 SECOND_PAGE_GROUP_START, THIRD_PAGE_GROUP_SIZE);
739 if (ahw->pci_base1 == NULL || ahw->pci_base2 == NULL) {
740 dev_err(&pdev->dev, "failed to map PCI bar 0\n");
741 err = -EIO;
742 goto err_out;
743 }
744
745 } else if (mem_len == NETXEN_PCI_2MB_SIZE) {
746
747 ahw->pci_base0 = pci_ioremap_bar(pdev, 0);
748 if (ahw->pci_base0 == NULL) {
749 dev_err(&pdev->dev, "failed to map PCI bar 0\n");
750 return -EIO;
751 }
752 ahw->pci_len0 = mem_len;
753 } else {
754 return -EIO;
755 }
756
757 netxen_setup_hwops(adapter);
758
759 dev_info(&pdev->dev, "%dMB memory map\n", (int)(mem_len>>20));
760
761 if (NX_IS_REVISION_P3P(adapter->ahw.revision_id)) {
762 adapter->ahw.ocm_win_crb = netxen_get_ioaddr(adapter,
763 NETXEN_PCIX_PS_REG(PCIX_OCM_WINDOW_REG(pci_func)));
764
765 } else if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
766 adapter->ahw.ocm_win_crb = netxen_get_ioaddr(adapter,
767 NETXEN_PCIX_PS_REG(PCIE_MN_WINDOW_REG(pci_func)));
768 }
769
770 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
771 goto skip_doorbell;
772
773 db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */
774 db_len = pci_resource_len(pdev, 4);
775
776 if (db_len == 0) {
777 printk(KERN_ERR "%s: doorbell is disabled\n",
778 netxen_nic_driver_name);
779 err = -EIO;
780 goto err_out;
781 }
782
783 db_ptr = ioremap(db_base, NETXEN_DB_MAPSIZE_BYTES);
784 if (!db_ptr) {
785 printk(KERN_ERR "%s: Failed to allocate doorbell map.",
786 netxen_nic_driver_name);
787 err = -EIO;
788 goto err_out;
789 }
790
791 skip_doorbell:
792 adapter->ahw.db_base = db_ptr;
793 adapter->ahw.db_len = db_len;
794 return 0;
795
796 err_out:
797 netxen_cleanup_pci_map(adapter);
798 return err;
799 }
800
801 static void
netxen_check_options(struct netxen_adapter * adapter)802 netxen_check_options(struct netxen_adapter *adapter)
803 {
804 u32 fw_major, fw_minor, fw_build, prev_fw_version;
805 char brd_name[NETXEN_MAX_SHORT_NAME];
806 char serial_num[32];
807 int i, offset, val, err;
808 __le32 *ptr32;
809 struct pci_dev *pdev = adapter->pdev;
810
811 adapter->driver_mismatch = 0;
812
813 ptr32 = (__le32 *)&serial_num;
814 offset = NX_FW_SERIAL_NUM_OFFSET;
815 for (i = 0; i < 8; i++) {
816 if (netxen_rom_fast_read(adapter, offset, &val) == -1) {
817 dev_err(&pdev->dev, "error reading board info\n");
818 adapter->driver_mismatch = 1;
819 return;
820 }
821 ptr32[i] = cpu_to_le32(val);
822 offset += sizeof(u32);
823 }
824
825 fw_major = NXRD32(adapter, NETXEN_FW_VERSION_MAJOR);
826 fw_minor = NXRD32(adapter, NETXEN_FW_VERSION_MINOR);
827 fw_build = NXRD32(adapter, NETXEN_FW_VERSION_SUB);
828 prev_fw_version = adapter->fw_version;
829 adapter->fw_version = NETXEN_VERSION_CODE(fw_major, fw_minor, fw_build);
830
831 /* Get FW Mini Coredump template and store it */
832 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
833 if (adapter->mdump.md_template == NULL ||
834 adapter->fw_version > prev_fw_version) {
835 kfree(adapter->mdump.md_template);
836 adapter->mdump.md_template = NULL;
837 err = netxen_setup_minidump(adapter);
838 if (err)
839 dev_err(&adapter->pdev->dev,
840 "Failed to setup minidump rcode = %d\n", err);
841 }
842 }
843
844 if (adapter->portnum == 0) {
845 get_brd_name_by_type(adapter->ahw.board_type, brd_name);
846
847 pr_info("%s: %s Board S/N %s Chip rev 0x%x\n",
848 module_name(THIS_MODULE),
849 brd_name, serial_num, adapter->ahw.revision_id);
850 }
851
852 if (adapter->fw_version < NETXEN_VERSION_CODE(3, 4, 216)) {
853 adapter->driver_mismatch = 1;
854 dev_warn(&pdev->dev, "firmware version %d.%d.%d unsupported\n",
855 fw_major, fw_minor, fw_build);
856 return;
857 }
858
859 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
860 i = NXRD32(adapter, NETXEN_SRE_MISC);
861 adapter->ahw.cut_through = (i & 0x8000) ? 1 : 0;
862 }
863
864 dev_info(&pdev->dev, "firmware v%d.%d.%d [%s]\n",
865 fw_major, fw_minor, fw_build,
866 adapter->ahw.cut_through ? "cut-through" : "legacy");
867
868 if (adapter->fw_version >= NETXEN_VERSION_CODE(4, 0, 222))
869 adapter->capabilities = NXRD32(adapter, CRB_FW_CAPABILITIES_1);
870
871 if (adapter->ahw.port_type == NETXEN_NIC_XGBE) {
872 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_10G;
873 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G;
874 } else if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
875 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_1G;
876 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G;
877 }
878
879 adapter->msix_supported = 0;
880 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
881 adapter->msix_supported = !!use_msi_x;
882 adapter->rss_supported = !!use_msi_x;
883 } else {
884 u32 flashed_ver = 0;
885 netxen_rom_fast_read(adapter,
886 NX_FW_VERSION_OFFSET, (int *)&flashed_ver);
887 flashed_ver = NETXEN_DECODE_VERSION(flashed_ver);
888
889 if (flashed_ver >= NETXEN_VERSION_CODE(3, 4, 336)) {
890 switch (adapter->ahw.board_type) {
891 case NETXEN_BRDTYPE_P2_SB31_10G:
892 case NETXEN_BRDTYPE_P2_SB31_10G_CX4:
893 adapter->msix_supported = !!use_msi_x;
894 adapter->rss_supported = !!use_msi_x;
895 break;
896 default:
897 break;
898 }
899 }
900 }
901
902 adapter->num_txd = MAX_CMD_DESCRIPTORS;
903
904 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
905 adapter->num_lro_rxd = MAX_LRO_RCV_DESCRIPTORS;
906 adapter->max_rds_rings = 3;
907 } else {
908 adapter->num_lro_rxd = 0;
909 adapter->max_rds_rings = 2;
910 }
911 }
912
913 static int
netxen_start_firmware(struct netxen_adapter * adapter)914 netxen_start_firmware(struct netxen_adapter *adapter)
915 {
916 int val, err, first_boot;
917 struct pci_dev *pdev = adapter->pdev;
918
919 /* required for NX2031 dummy dma */
920 err = nx_set_dma_mask(adapter);
921 if (err)
922 return err;
923
924 err = netxen_can_start_firmware(adapter);
925
926 if (err < 0)
927 return err;
928
929 if (!err)
930 goto wait_init;
931
932 first_boot = NXRD32(adapter, NETXEN_CAM_RAM(0x1fc));
933
934 err = netxen_check_hw_init(adapter, first_boot);
935 if (err) {
936 dev_err(&pdev->dev, "error in init HW init sequence\n");
937 return err;
938 }
939
940 netxen_request_firmware(adapter);
941
942 err = netxen_need_fw_reset(adapter);
943 if (err < 0)
944 goto err_out;
945 if (err == 0)
946 goto pcie_strap_init;
947
948 if (first_boot != 0x55555555) {
949 NXWR32(adapter, CRB_CMDPEG_STATE, 0);
950 netxen_pinit_from_rom(adapter);
951 msleep(1);
952 }
953
954 NXWR32(adapter, CRB_DMA_SHIFT, 0x55555555);
955 NXWR32(adapter, NETXEN_PEG_HALT_STATUS1, 0);
956 NXWR32(adapter, NETXEN_PEG_HALT_STATUS2, 0);
957
958 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
959 netxen_set_port_mode(adapter);
960
961 err = netxen_load_firmware(adapter);
962 if (err)
963 goto err_out;
964
965 netxen_release_firmware(adapter);
966
967 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
968
969 /* Initialize multicast addr pool owners */
970 val = 0x7654;
971 if (adapter->ahw.port_type == NETXEN_NIC_XGBE)
972 val |= 0x0f000000;
973 NXWR32(adapter, NETXEN_MAC_ADDR_CNTL_REG, val);
974
975 }
976
977 err = netxen_init_dummy_dma(adapter);
978 if (err)
979 goto err_out;
980
981 /*
982 * Tell the hardware our version number.
983 */
984 val = (_NETXEN_NIC_LINUX_MAJOR << 16)
985 | ((_NETXEN_NIC_LINUX_MINOR << 8))
986 | (_NETXEN_NIC_LINUX_SUBVERSION);
987 NXWR32(adapter, CRB_DRIVER_VERSION, val);
988
989 pcie_strap_init:
990 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
991 netxen_pcie_strap_init(adapter);
992
993 wait_init:
994 /* Handshake with the card before we register the devices. */
995 err = netxen_phantom_init(adapter, NETXEN_NIC_PEG_TUNE);
996 if (err) {
997 netxen_free_dummy_dma(adapter);
998 goto err_out;
999 }
1000
1001 NXWR32(adapter, NX_CRB_DEV_STATE, NX_DEV_READY);
1002
1003 nx_update_dma_mask(adapter);
1004
1005 netxen_check_options(adapter);
1006
1007 adapter->need_fw_reset = 0;
1008
1009 /* fall through and release firmware */
1010
1011 err_out:
1012 netxen_release_firmware(adapter);
1013 return err;
1014 }
1015
1016 static int
netxen_nic_request_irq(struct netxen_adapter * adapter)1017 netxen_nic_request_irq(struct netxen_adapter *adapter)
1018 {
1019 irq_handler_t handler;
1020 struct nx_host_sds_ring *sds_ring;
1021 int err, ring;
1022
1023 unsigned long flags = 0;
1024 struct net_device *netdev = adapter->netdev;
1025 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
1026
1027 if (adapter->flags & NETXEN_NIC_MSIX_ENABLED)
1028 handler = netxen_msix_intr;
1029 else if (adapter->flags & NETXEN_NIC_MSI_ENABLED)
1030 handler = netxen_msi_intr;
1031 else {
1032 flags |= IRQF_SHARED;
1033 handler = netxen_intr;
1034 }
1035 adapter->irq = netdev->irq;
1036
1037 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
1038 sds_ring = &recv_ctx->sds_rings[ring];
1039 sprintf(sds_ring->name, "%s[%d]", netdev->name, ring);
1040 err = request_irq(sds_ring->irq, handler,
1041 flags, sds_ring->name, sds_ring);
1042 if (err)
1043 return err;
1044 }
1045
1046 return 0;
1047 }
1048
1049 static void
netxen_nic_free_irq(struct netxen_adapter * adapter)1050 netxen_nic_free_irq(struct netxen_adapter *adapter)
1051 {
1052 int ring;
1053 struct nx_host_sds_ring *sds_ring;
1054
1055 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
1056
1057 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
1058 sds_ring = &recv_ctx->sds_rings[ring];
1059 free_irq(sds_ring->irq, sds_ring);
1060 }
1061 }
1062
1063 static void
netxen_nic_init_coalesce_defaults(struct netxen_adapter * adapter)1064 netxen_nic_init_coalesce_defaults(struct netxen_adapter *adapter)
1065 {
1066 adapter->coal.flags = NETXEN_NIC_INTR_DEFAULT;
1067 adapter->coal.normal.data.rx_time_us =
1068 NETXEN_DEFAULT_INTR_COALESCE_RX_TIME_US;
1069 adapter->coal.normal.data.rx_packets =
1070 NETXEN_DEFAULT_INTR_COALESCE_RX_PACKETS;
1071 adapter->coal.normal.data.tx_time_us =
1072 NETXEN_DEFAULT_INTR_COALESCE_TX_TIME_US;
1073 adapter->coal.normal.data.tx_packets =
1074 NETXEN_DEFAULT_INTR_COALESCE_TX_PACKETS;
1075 }
1076
1077 /* with rtnl_lock */
1078 static int
__netxen_nic_up(struct netxen_adapter * adapter,struct net_device * netdev)1079 __netxen_nic_up(struct netxen_adapter *adapter, struct net_device *netdev)
1080 {
1081 int err;
1082
1083 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
1084 return -EIO;
1085
1086 err = adapter->init_port(adapter, adapter->physical_port);
1087 if (err) {
1088 printk(KERN_ERR "%s: Failed to initialize port %d\n",
1089 netxen_nic_driver_name, adapter->portnum);
1090 return err;
1091 }
1092 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
1093 adapter->macaddr_set(adapter, adapter->mac_addr);
1094
1095 adapter->set_multi(netdev);
1096 adapter->set_mtu(adapter, netdev->mtu);
1097
1098 adapter->ahw.linkup = 0;
1099
1100 if (adapter->max_sds_rings > 1)
1101 netxen_config_rss(adapter, 1);
1102
1103 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
1104 netxen_config_intr_coalesce(adapter);
1105
1106 if (netdev->features & NETIF_F_LRO)
1107 netxen_config_hw_lro(adapter, NETXEN_NIC_LRO_ENABLED);
1108
1109 netxen_napi_enable(adapter);
1110
1111 if (adapter->capabilities & NX_FW_CAPABILITY_LINK_NOTIFICATION)
1112 netxen_linkevent_request(adapter, 1);
1113 else
1114 netxen_nic_set_link_parameters(adapter);
1115
1116 set_bit(__NX_DEV_UP, &adapter->state);
1117 return 0;
1118 }
1119
1120 /* Usage: During resume and firmware recovery module.*/
1121
1122 static inline int
netxen_nic_up(struct netxen_adapter * adapter,struct net_device * netdev)1123 netxen_nic_up(struct netxen_adapter *adapter, struct net_device *netdev)
1124 {
1125 int err = 0;
1126
1127 rtnl_lock();
1128 if (netif_running(netdev))
1129 err = __netxen_nic_up(adapter, netdev);
1130 rtnl_unlock();
1131
1132 return err;
1133 }
1134
1135 /* with rtnl_lock */
1136 static void
__netxen_nic_down(struct netxen_adapter * adapter,struct net_device * netdev)1137 __netxen_nic_down(struct netxen_adapter *adapter, struct net_device *netdev)
1138 {
1139 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
1140 return;
1141
1142 if (!test_and_clear_bit(__NX_DEV_UP, &adapter->state))
1143 return;
1144
1145 smp_mb();
1146 spin_lock(&adapter->tx_clean_lock);
1147 netif_carrier_off(netdev);
1148 netif_tx_disable(netdev);
1149
1150 if (adapter->capabilities & NX_FW_CAPABILITY_LINK_NOTIFICATION)
1151 netxen_linkevent_request(adapter, 0);
1152
1153 if (adapter->stop_port)
1154 adapter->stop_port(adapter);
1155
1156 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
1157 netxen_p3_free_mac_list(adapter);
1158
1159 adapter->set_promisc(adapter, NETXEN_NIU_NON_PROMISC_MODE);
1160
1161 netxen_napi_disable(adapter);
1162
1163 netxen_release_tx_buffers(adapter);
1164 spin_unlock(&adapter->tx_clean_lock);
1165 }
1166
1167 /* Usage: During suspend and firmware recovery module */
1168
1169 static inline void
netxen_nic_down(struct netxen_adapter * adapter,struct net_device * netdev)1170 netxen_nic_down(struct netxen_adapter *adapter, struct net_device *netdev)
1171 {
1172 rtnl_lock();
1173 if (netif_running(netdev))
1174 __netxen_nic_down(adapter, netdev);
1175 rtnl_unlock();
1176
1177 }
1178
1179 static int
netxen_nic_attach(struct netxen_adapter * adapter)1180 netxen_nic_attach(struct netxen_adapter *adapter)
1181 {
1182 struct net_device *netdev = adapter->netdev;
1183 struct pci_dev *pdev = adapter->pdev;
1184 int err, ring;
1185 struct nx_host_rds_ring *rds_ring;
1186 struct nx_host_tx_ring *tx_ring;
1187
1188 if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC)
1189 return 0;
1190
1191 err = netxen_init_firmware(adapter);
1192 if (err)
1193 return err;
1194
1195 err = netxen_napi_add(adapter, netdev);
1196 if (err)
1197 return err;
1198
1199 err = netxen_alloc_sw_resources(adapter);
1200 if (err) {
1201 printk(KERN_ERR "%s: Error in setting sw resources\n",
1202 netdev->name);
1203 return err;
1204 }
1205
1206 err = netxen_alloc_hw_resources(adapter);
1207 if (err) {
1208 printk(KERN_ERR "%s: Error in setting hw resources\n",
1209 netdev->name);
1210 goto err_out_free_sw;
1211 }
1212
1213 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
1214 tx_ring = adapter->tx_ring;
1215 tx_ring->crb_cmd_producer = netxen_get_ioaddr(adapter,
1216 crb_cmd_producer[adapter->portnum]);
1217 tx_ring->crb_cmd_consumer = netxen_get_ioaddr(adapter,
1218 crb_cmd_consumer[adapter->portnum]);
1219
1220 tx_ring->producer = 0;
1221 tx_ring->sw_consumer = 0;
1222
1223 netxen_nic_update_cmd_producer(adapter, tx_ring);
1224 netxen_nic_update_cmd_consumer(adapter, tx_ring);
1225 }
1226
1227 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
1228 rds_ring = &adapter->recv_ctx.rds_rings[ring];
1229 netxen_post_rx_buffers(adapter, ring, rds_ring);
1230 }
1231
1232 err = netxen_nic_request_irq(adapter);
1233 if (err) {
1234 dev_err(&pdev->dev, "%s: failed to setup interrupt\n",
1235 netdev->name);
1236 goto err_out_free_rxbuf;
1237 }
1238
1239 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
1240 netxen_nic_init_coalesce_defaults(adapter);
1241
1242 netxen_create_sysfs_entries(adapter);
1243
1244 adapter->is_up = NETXEN_ADAPTER_UP_MAGIC;
1245 return 0;
1246
1247 err_out_free_rxbuf:
1248 netxen_release_rx_buffers(adapter);
1249 netxen_free_hw_resources(adapter);
1250 err_out_free_sw:
1251 netxen_free_sw_resources(adapter);
1252 return err;
1253 }
1254
1255 static void
netxen_nic_detach(struct netxen_adapter * adapter)1256 netxen_nic_detach(struct netxen_adapter *adapter)
1257 {
1258 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
1259 return;
1260
1261 netxen_remove_sysfs_entries(adapter);
1262
1263 netxen_free_hw_resources(adapter);
1264 netxen_release_rx_buffers(adapter);
1265 netxen_nic_free_irq(adapter);
1266 netxen_napi_del(adapter);
1267 netxen_free_sw_resources(adapter);
1268
1269 adapter->is_up = 0;
1270 }
1271
1272 int
netxen_nic_reset_context(struct netxen_adapter * adapter)1273 netxen_nic_reset_context(struct netxen_adapter *adapter)
1274 {
1275 int err = 0;
1276 struct net_device *netdev = adapter->netdev;
1277
1278 if (test_and_set_bit(__NX_RESETTING, &adapter->state))
1279 return -EBUSY;
1280
1281 if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC) {
1282
1283 netif_device_detach(netdev);
1284
1285 if (netif_running(netdev))
1286 __netxen_nic_down(adapter, netdev);
1287
1288 netxen_nic_detach(adapter);
1289
1290 if (netif_running(netdev)) {
1291 err = netxen_nic_attach(adapter);
1292 if (!err)
1293 err = __netxen_nic_up(adapter, netdev);
1294
1295 if (err)
1296 goto done;
1297 }
1298
1299 netif_device_attach(netdev);
1300 }
1301
1302 done:
1303 clear_bit(__NX_RESETTING, &adapter->state);
1304 return err;
1305 }
1306
1307 static int
netxen_setup_netdev(struct netxen_adapter * adapter,struct net_device * netdev)1308 netxen_setup_netdev(struct netxen_adapter *adapter,
1309 struct net_device *netdev)
1310 {
1311 int err = 0;
1312 struct pci_dev *pdev = adapter->pdev;
1313
1314 adapter->mc_enabled = 0;
1315 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
1316 adapter->max_mc_count = 38;
1317 else
1318 adapter->max_mc_count = 16;
1319
1320 netdev->netdev_ops = &netxen_netdev_ops;
1321 netdev->watchdog_timeo = 5*HZ;
1322
1323 netxen_nic_change_mtu(netdev, netdev->mtu);
1324
1325 SET_ETHTOOL_OPS(netdev, &netxen_nic_ethtool_ops);
1326
1327 netdev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO |
1328 NETIF_F_RXCSUM;
1329
1330 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
1331 netdev->hw_features |= NETIF_F_IPV6_CSUM | NETIF_F_TSO6;
1332
1333 netdev->vlan_features |= netdev->hw_features;
1334
1335 if (adapter->pci_using_dac) {
1336 netdev->features |= NETIF_F_HIGHDMA;
1337 netdev->vlan_features |= NETIF_F_HIGHDMA;
1338 }
1339
1340 if (adapter->capabilities & NX_FW_CAPABILITY_FVLANTX)
1341 netdev->hw_features |= NETIF_F_HW_VLAN_TX;
1342
1343 if (adapter->capabilities & NX_FW_CAPABILITY_HW_LRO)
1344 netdev->hw_features |= NETIF_F_LRO;
1345
1346 netdev->features |= netdev->hw_features;
1347
1348 netdev->irq = adapter->msix_entries[0].vector;
1349
1350 INIT_WORK(&adapter->tx_timeout_task, netxen_tx_timeout_task);
1351
1352 if (netxen_read_mac_addr(adapter))
1353 dev_warn(&pdev->dev, "failed to read mac addr\n");
1354
1355 netif_carrier_off(netdev);
1356
1357 err = register_netdev(netdev);
1358 if (err) {
1359 dev_err(&pdev->dev, "failed to register net device\n");
1360 return err;
1361 }
1362
1363 return 0;
1364 }
1365
1366 #ifdef CONFIG_PCIEAER
netxen_mask_aer_correctable(struct netxen_adapter * adapter)1367 static void netxen_mask_aer_correctable(struct netxen_adapter *adapter)
1368 {
1369 struct pci_dev *pdev = adapter->pdev;
1370 struct pci_dev *root = pdev->bus->self;
1371 u32 aer_pos;
1372
1373 /* root bus? */
1374 if (!root)
1375 return;
1376
1377 if (adapter->ahw.board_type != NETXEN_BRDTYPE_P3_4_GB_MM &&
1378 adapter->ahw.board_type != NETXEN_BRDTYPE_P3_10G_TP)
1379 return;
1380
1381 if (root->pcie_type != PCI_EXP_TYPE_ROOT_PORT)
1382 return;
1383
1384 aer_pos = pci_find_ext_capability(root, PCI_EXT_CAP_ID_ERR);
1385 if (!aer_pos)
1386 return;
1387
1388 pci_write_config_dword(root, aer_pos + PCI_ERR_COR_MASK, 0xffff);
1389 }
1390 #endif
1391
1392 static int __devinit
netxen_nic_probe(struct pci_dev * pdev,const struct pci_device_id * ent)1393 netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1394 {
1395 struct net_device *netdev = NULL;
1396 struct netxen_adapter *adapter = NULL;
1397 int i = 0, err;
1398 int pci_func_id = PCI_FUNC(pdev->devfn);
1399 uint8_t revision_id;
1400 u32 val;
1401
1402 if (pdev->revision >= NX_P3_A0 && pdev->revision <= NX_P3_B1) {
1403 pr_warning("%s: chip revisions between 0x%x-0x%x "
1404 "will not be enabled.\n",
1405 module_name(THIS_MODULE), NX_P3_A0, NX_P3_B1);
1406 return -ENODEV;
1407 }
1408
1409 if ((err = pci_enable_device(pdev)))
1410 return err;
1411
1412 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
1413 err = -ENODEV;
1414 goto err_out_disable_pdev;
1415 }
1416
1417 if ((err = pci_request_regions(pdev, netxen_nic_driver_name)))
1418 goto err_out_disable_pdev;
1419
1420 if (NX_IS_REVISION_P3(pdev->revision))
1421 pci_enable_pcie_error_reporting(pdev);
1422
1423 pci_set_master(pdev);
1424
1425 netdev = alloc_etherdev(sizeof(struct netxen_adapter));
1426 if(!netdev) {
1427 err = -ENOMEM;
1428 goto err_out_free_res;
1429 }
1430
1431 SET_NETDEV_DEV(netdev, &pdev->dev);
1432
1433 adapter = netdev_priv(netdev);
1434 adapter->netdev = netdev;
1435 adapter->pdev = pdev;
1436 adapter->ahw.pci_func = pci_func_id;
1437
1438 revision_id = pdev->revision;
1439 adapter->ahw.revision_id = revision_id;
1440
1441 rwlock_init(&adapter->ahw.crb_lock);
1442 spin_lock_init(&adapter->ahw.mem_lock);
1443
1444 spin_lock_init(&adapter->tx_clean_lock);
1445 INIT_LIST_HEAD(&adapter->mac_list);
1446 INIT_LIST_HEAD(&adapter->vlan_ip_list);
1447
1448 err = netxen_setup_pci_map(adapter);
1449 if (err)
1450 goto err_out_free_netdev;
1451
1452 /* This will be reset for mezz cards */
1453 adapter->portnum = pci_func_id;
1454
1455 err = netxen_nic_get_board_info(adapter);
1456 if (err) {
1457 dev_err(&pdev->dev, "Error getting board config info.\n");
1458 goto err_out_iounmap;
1459 }
1460
1461 #ifdef CONFIG_PCIEAER
1462 netxen_mask_aer_correctable(adapter);
1463 #endif
1464
1465 /* Mezz cards have PCI function 0,2,3 enabled */
1466 switch (adapter->ahw.board_type) {
1467 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ:
1468 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ:
1469 if (pci_func_id >= 2)
1470 adapter->portnum = pci_func_id - 2;
1471 break;
1472 default:
1473 break;
1474 }
1475
1476 err = netxen_check_flash_fw_compatibility(adapter);
1477 if (err)
1478 goto err_out_iounmap;
1479
1480 if (adapter->portnum == 0) {
1481 val = NXRD32(adapter, NX_CRB_DEV_REF_COUNT);
1482 if (val != 0xffffffff && val != 0) {
1483 NXWR32(adapter, NX_CRB_DEV_REF_COUNT, 0);
1484 adapter->need_fw_reset = 1;
1485 }
1486 }
1487
1488 err = netxen_start_firmware(adapter);
1489 if (err)
1490 goto err_out_decr_ref;
1491
1492 /*
1493 * See if the firmware gave us a virtual-physical port mapping.
1494 */
1495 adapter->physical_port = adapter->portnum;
1496 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
1497 i = NXRD32(adapter, CRB_V2P(adapter->portnum));
1498 if (i != 0x55555555)
1499 adapter->physical_port = i;
1500 }
1501
1502 netxen_nic_clear_stats(adapter);
1503
1504 netxen_setup_intr(adapter);
1505
1506 err = netxen_setup_netdev(adapter, netdev);
1507 if (err)
1508 goto err_out_disable_msi;
1509
1510 pci_set_drvdata(pdev, adapter);
1511
1512 netxen_schedule_work(adapter, netxen_fw_poll_work, FW_POLL_DELAY);
1513
1514 switch (adapter->ahw.port_type) {
1515 case NETXEN_NIC_GBE:
1516 dev_info(&adapter->pdev->dev, "%s: GbE port initialized\n",
1517 adapter->netdev->name);
1518 break;
1519 case NETXEN_NIC_XGBE:
1520 dev_info(&adapter->pdev->dev, "%s: XGbE port initialized\n",
1521 adapter->netdev->name);
1522 break;
1523 }
1524
1525 netxen_create_diag_entries(adapter);
1526
1527 return 0;
1528
1529 err_out_disable_msi:
1530 netxen_teardown_intr(adapter);
1531
1532 netxen_free_dummy_dma(adapter);
1533
1534 err_out_decr_ref:
1535 nx_decr_dev_ref_cnt(adapter);
1536
1537 err_out_iounmap:
1538 netxen_cleanup_pci_map(adapter);
1539
1540 err_out_free_netdev:
1541 free_netdev(netdev);
1542
1543 err_out_free_res:
1544 pci_release_regions(pdev);
1545
1546 err_out_disable_pdev:
1547 pci_set_drvdata(pdev, NULL);
1548 pci_disable_device(pdev);
1549 return err;
1550 }
1551
1552 static
netxen_cleanup_minidump(struct netxen_adapter * adapter)1553 void netxen_cleanup_minidump(struct netxen_adapter *adapter)
1554 {
1555 kfree(adapter->mdump.md_template);
1556 adapter->mdump.md_template = NULL;
1557
1558 if (adapter->mdump.md_capture_buff) {
1559 vfree(adapter->mdump.md_capture_buff);
1560 adapter->mdump.md_capture_buff = NULL;
1561 }
1562 }
1563
netxen_nic_remove(struct pci_dev * pdev)1564 static void __devexit netxen_nic_remove(struct pci_dev *pdev)
1565 {
1566 struct netxen_adapter *adapter;
1567 struct net_device *netdev;
1568
1569 adapter = pci_get_drvdata(pdev);
1570 if (adapter == NULL)
1571 return;
1572
1573 netdev = adapter->netdev;
1574
1575 netxen_cancel_fw_work(adapter);
1576
1577 unregister_netdev(netdev);
1578
1579 cancel_work_sync(&adapter->tx_timeout_task);
1580
1581 netxen_free_vlan_ip_list(adapter);
1582 netxen_nic_detach(adapter);
1583
1584 nx_decr_dev_ref_cnt(adapter);
1585
1586 if (adapter->portnum == 0)
1587 netxen_free_dummy_dma(adapter);
1588
1589 clear_bit(__NX_RESETTING, &adapter->state);
1590
1591 netxen_teardown_intr(adapter);
1592
1593 netxen_remove_diag_entries(adapter);
1594
1595 netxen_cleanup_pci_map(adapter);
1596
1597 netxen_release_firmware(adapter);
1598
1599 if (NX_IS_REVISION_P3(pdev->revision)) {
1600 netxen_cleanup_minidump(adapter);
1601 pci_disable_pcie_error_reporting(pdev);
1602 }
1603
1604 pci_release_regions(pdev);
1605 pci_disable_device(pdev);
1606 pci_set_drvdata(pdev, NULL);
1607
1608 free_netdev(netdev);
1609 }
1610
netxen_nic_detach_func(struct netxen_adapter * adapter)1611 static void netxen_nic_detach_func(struct netxen_adapter *adapter)
1612 {
1613 struct net_device *netdev = adapter->netdev;
1614
1615 netif_device_detach(netdev);
1616
1617 netxen_cancel_fw_work(adapter);
1618
1619 if (netif_running(netdev))
1620 netxen_nic_down(adapter, netdev);
1621
1622 cancel_work_sync(&adapter->tx_timeout_task);
1623
1624 netxen_nic_detach(adapter);
1625
1626 if (adapter->portnum == 0)
1627 netxen_free_dummy_dma(adapter);
1628
1629 nx_decr_dev_ref_cnt(adapter);
1630
1631 clear_bit(__NX_RESETTING, &adapter->state);
1632 }
1633
netxen_nic_attach_func(struct pci_dev * pdev)1634 static int netxen_nic_attach_func(struct pci_dev *pdev)
1635 {
1636 struct netxen_adapter *adapter = pci_get_drvdata(pdev);
1637 struct net_device *netdev = adapter->netdev;
1638 int err;
1639
1640 err = pci_enable_device(pdev);
1641 if (err)
1642 return err;
1643
1644 pci_set_power_state(pdev, PCI_D0);
1645 pci_set_master(pdev);
1646 pci_restore_state(pdev);
1647
1648 adapter->ahw.crb_win = -1;
1649 adapter->ahw.ocm_win = -1;
1650
1651 err = netxen_start_firmware(adapter);
1652 if (err) {
1653 dev_err(&pdev->dev, "failed to start firmware\n");
1654 return err;
1655 }
1656
1657 if (netif_running(netdev)) {
1658 err = netxen_nic_attach(adapter);
1659 if (err)
1660 goto err_out;
1661
1662 err = netxen_nic_up(adapter, netdev);
1663 if (err)
1664 goto err_out_detach;
1665
1666 netxen_restore_indev_addr(netdev, NETDEV_UP);
1667 }
1668
1669 netif_device_attach(netdev);
1670 netxen_schedule_work(adapter, netxen_fw_poll_work, FW_POLL_DELAY);
1671 return 0;
1672
1673 err_out_detach:
1674 netxen_nic_detach(adapter);
1675 err_out:
1676 nx_decr_dev_ref_cnt(adapter);
1677 return err;
1678 }
1679
netxen_io_error_detected(struct pci_dev * pdev,pci_channel_state_t state)1680 static pci_ers_result_t netxen_io_error_detected(struct pci_dev *pdev,
1681 pci_channel_state_t state)
1682 {
1683 struct netxen_adapter *adapter = pci_get_drvdata(pdev);
1684
1685 if (state == pci_channel_io_perm_failure)
1686 return PCI_ERS_RESULT_DISCONNECT;
1687
1688 if (nx_dev_request_aer(adapter))
1689 return PCI_ERS_RESULT_RECOVERED;
1690
1691 netxen_nic_detach_func(adapter);
1692
1693 pci_disable_device(pdev);
1694
1695 return PCI_ERS_RESULT_NEED_RESET;
1696 }
1697
netxen_io_slot_reset(struct pci_dev * pdev)1698 static pci_ers_result_t netxen_io_slot_reset(struct pci_dev *pdev)
1699 {
1700 int err = 0;
1701
1702 err = netxen_nic_attach_func(pdev);
1703
1704 return err ? PCI_ERS_RESULT_DISCONNECT : PCI_ERS_RESULT_RECOVERED;
1705 }
1706
netxen_io_resume(struct pci_dev * pdev)1707 static void netxen_io_resume(struct pci_dev *pdev)
1708 {
1709 pci_cleanup_aer_uncorrect_error_status(pdev);
1710 }
1711
netxen_nic_shutdown(struct pci_dev * pdev)1712 static void netxen_nic_shutdown(struct pci_dev *pdev)
1713 {
1714 struct netxen_adapter *adapter = pci_get_drvdata(pdev);
1715
1716 netxen_nic_detach_func(adapter);
1717
1718 if (pci_save_state(pdev))
1719 return;
1720
1721 if (netxen_nic_wol_supported(adapter)) {
1722 pci_enable_wake(pdev, PCI_D3cold, 1);
1723 pci_enable_wake(pdev, PCI_D3hot, 1);
1724 }
1725
1726 pci_disable_device(pdev);
1727 }
1728
1729 #ifdef CONFIG_PM
1730 static int
netxen_nic_suspend(struct pci_dev * pdev,pm_message_t state)1731 netxen_nic_suspend(struct pci_dev *pdev, pm_message_t state)
1732 {
1733 struct netxen_adapter *adapter = pci_get_drvdata(pdev);
1734 int retval;
1735
1736 netxen_nic_detach_func(adapter);
1737
1738 retval = pci_save_state(pdev);
1739 if (retval)
1740 return retval;
1741
1742 if (netxen_nic_wol_supported(adapter)) {
1743 pci_enable_wake(pdev, PCI_D3cold, 1);
1744 pci_enable_wake(pdev, PCI_D3hot, 1);
1745 }
1746
1747 pci_disable_device(pdev);
1748 pci_set_power_state(pdev, pci_choose_state(pdev, state));
1749
1750 return 0;
1751 }
1752
1753 static int
netxen_nic_resume(struct pci_dev * pdev)1754 netxen_nic_resume(struct pci_dev *pdev)
1755 {
1756 return netxen_nic_attach_func(pdev);
1757 }
1758 #endif
1759
netxen_nic_open(struct net_device * netdev)1760 static int netxen_nic_open(struct net_device *netdev)
1761 {
1762 struct netxen_adapter *adapter = netdev_priv(netdev);
1763 int err = 0;
1764
1765 if (adapter->driver_mismatch)
1766 return -EIO;
1767
1768 err = netxen_nic_attach(adapter);
1769 if (err)
1770 return err;
1771
1772 err = __netxen_nic_up(adapter, netdev);
1773 if (err)
1774 goto err_out;
1775
1776 netif_start_queue(netdev);
1777
1778 return 0;
1779
1780 err_out:
1781 netxen_nic_detach(adapter);
1782 return err;
1783 }
1784
1785 /*
1786 * netxen_nic_close - Disables a network interface entry point
1787 */
netxen_nic_close(struct net_device * netdev)1788 static int netxen_nic_close(struct net_device *netdev)
1789 {
1790 struct netxen_adapter *adapter = netdev_priv(netdev);
1791
1792 __netxen_nic_down(adapter, netdev);
1793 return 0;
1794 }
1795
1796 static void
netxen_tso_check(struct net_device * netdev,struct nx_host_tx_ring * tx_ring,struct cmd_desc_type0 * first_desc,struct sk_buff * skb)1797 netxen_tso_check(struct net_device *netdev,
1798 struct nx_host_tx_ring *tx_ring,
1799 struct cmd_desc_type0 *first_desc,
1800 struct sk_buff *skb)
1801 {
1802 u8 opcode = TX_ETHER_PKT;
1803 __be16 protocol = skb->protocol;
1804 u16 flags = 0, vid = 0;
1805 u32 producer;
1806 int copied, offset, copy_len, hdr_len = 0, tso = 0, vlan_oob = 0;
1807 struct cmd_desc_type0 *hwdesc;
1808 struct vlan_ethhdr *vh;
1809
1810 if (protocol == cpu_to_be16(ETH_P_8021Q)) {
1811
1812 vh = (struct vlan_ethhdr *)skb->data;
1813 protocol = vh->h_vlan_encapsulated_proto;
1814 flags = FLAGS_VLAN_TAGGED;
1815
1816 } else if (vlan_tx_tag_present(skb)) {
1817
1818 flags = FLAGS_VLAN_OOB;
1819 vid = vlan_tx_tag_get(skb);
1820 netxen_set_tx_vlan_tci(first_desc, vid);
1821 vlan_oob = 1;
1822 }
1823
1824 if ((netdev->features & (NETIF_F_TSO | NETIF_F_TSO6)) &&
1825 skb_shinfo(skb)->gso_size > 0) {
1826
1827 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
1828
1829 first_desc->mss = cpu_to_le16(skb_shinfo(skb)->gso_size);
1830 first_desc->total_hdr_length = hdr_len;
1831 if (vlan_oob) {
1832 first_desc->total_hdr_length += VLAN_HLEN;
1833 first_desc->tcp_hdr_offset = VLAN_HLEN;
1834 first_desc->ip_hdr_offset = VLAN_HLEN;
1835 /* Only in case of TSO on vlan device */
1836 flags |= FLAGS_VLAN_TAGGED;
1837 }
1838
1839 opcode = (protocol == cpu_to_be16(ETH_P_IPV6)) ?
1840 TX_TCP_LSO6 : TX_TCP_LSO;
1841 tso = 1;
1842
1843 } else if (skb->ip_summed == CHECKSUM_PARTIAL) {
1844 u8 l4proto;
1845
1846 if (protocol == cpu_to_be16(ETH_P_IP)) {
1847 l4proto = ip_hdr(skb)->protocol;
1848
1849 if (l4proto == IPPROTO_TCP)
1850 opcode = TX_TCP_PKT;
1851 else if(l4proto == IPPROTO_UDP)
1852 opcode = TX_UDP_PKT;
1853 } else if (protocol == cpu_to_be16(ETH_P_IPV6)) {
1854 l4proto = ipv6_hdr(skb)->nexthdr;
1855
1856 if (l4proto == IPPROTO_TCP)
1857 opcode = TX_TCPV6_PKT;
1858 else if(l4proto == IPPROTO_UDP)
1859 opcode = TX_UDPV6_PKT;
1860 }
1861 }
1862
1863 first_desc->tcp_hdr_offset += skb_transport_offset(skb);
1864 first_desc->ip_hdr_offset += skb_network_offset(skb);
1865 netxen_set_tx_flags_opcode(first_desc, flags, opcode);
1866
1867 if (!tso)
1868 return;
1869
1870 /* For LSO, we need to copy the MAC/IP/TCP headers into
1871 * the descriptor ring
1872 */
1873 producer = tx_ring->producer;
1874 copied = 0;
1875 offset = 2;
1876
1877 if (vlan_oob) {
1878 /* Create a TSO vlan header template for firmware */
1879
1880 hwdesc = &tx_ring->desc_head[producer];
1881 tx_ring->cmd_buf_arr[producer].skb = NULL;
1882
1883 copy_len = min((int)sizeof(struct cmd_desc_type0) - offset,
1884 hdr_len + VLAN_HLEN);
1885
1886 vh = (struct vlan_ethhdr *)((char *)hwdesc + 2);
1887 skb_copy_from_linear_data(skb, vh, 12);
1888 vh->h_vlan_proto = htons(ETH_P_8021Q);
1889 vh->h_vlan_TCI = htons(vid);
1890 skb_copy_from_linear_data_offset(skb, 12,
1891 (char *)vh + 16, copy_len - 16);
1892
1893 copied = copy_len - VLAN_HLEN;
1894 offset = 0;
1895
1896 producer = get_next_index(producer, tx_ring->num_desc);
1897 }
1898
1899 while (copied < hdr_len) {
1900
1901 copy_len = min((int)sizeof(struct cmd_desc_type0) - offset,
1902 (hdr_len - copied));
1903
1904 hwdesc = &tx_ring->desc_head[producer];
1905 tx_ring->cmd_buf_arr[producer].skb = NULL;
1906
1907 skb_copy_from_linear_data_offset(skb, copied,
1908 (char *)hwdesc + offset, copy_len);
1909
1910 copied += copy_len;
1911 offset = 0;
1912
1913 producer = get_next_index(producer, tx_ring->num_desc);
1914 }
1915
1916 tx_ring->producer = producer;
1917 barrier();
1918 }
1919
1920 static int
netxen_map_tx_skb(struct pci_dev * pdev,struct sk_buff * skb,struct netxen_cmd_buffer * pbuf)1921 netxen_map_tx_skb(struct pci_dev *pdev,
1922 struct sk_buff *skb, struct netxen_cmd_buffer *pbuf)
1923 {
1924 struct netxen_skb_frag *nf;
1925 struct skb_frag_struct *frag;
1926 int i, nr_frags;
1927 dma_addr_t map;
1928
1929 nr_frags = skb_shinfo(skb)->nr_frags;
1930 nf = &pbuf->frag_array[0];
1931
1932 map = pci_map_single(pdev, skb->data,
1933 skb_headlen(skb), PCI_DMA_TODEVICE);
1934 if (pci_dma_mapping_error(pdev, map))
1935 goto out_err;
1936
1937 nf->dma = map;
1938 nf->length = skb_headlen(skb);
1939
1940 for (i = 0; i < nr_frags; i++) {
1941 frag = &skb_shinfo(skb)->frags[i];
1942 nf = &pbuf->frag_array[i+1];
1943
1944 map = skb_frag_dma_map(&pdev->dev, frag, 0, skb_frag_size(frag),
1945 DMA_TO_DEVICE);
1946 if (dma_mapping_error(&pdev->dev, map))
1947 goto unwind;
1948
1949 nf->dma = map;
1950 nf->length = skb_frag_size(frag);
1951 }
1952
1953 return 0;
1954
1955 unwind:
1956 while (--i >= 0) {
1957 nf = &pbuf->frag_array[i+1];
1958 pci_unmap_page(pdev, nf->dma, nf->length, PCI_DMA_TODEVICE);
1959 nf->dma = 0ULL;
1960 }
1961
1962 nf = &pbuf->frag_array[0];
1963 pci_unmap_single(pdev, nf->dma, skb_headlen(skb), PCI_DMA_TODEVICE);
1964 nf->dma = 0ULL;
1965
1966 out_err:
1967 return -ENOMEM;
1968 }
1969
1970 static inline void
netxen_clear_cmddesc(u64 * desc)1971 netxen_clear_cmddesc(u64 *desc)
1972 {
1973 desc[0] = 0ULL;
1974 desc[2] = 0ULL;
1975 }
1976
1977 static netdev_tx_t
netxen_nic_xmit_frame(struct sk_buff * skb,struct net_device * netdev)1978 netxen_nic_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
1979 {
1980 struct netxen_adapter *adapter = netdev_priv(netdev);
1981 struct nx_host_tx_ring *tx_ring = adapter->tx_ring;
1982 struct netxen_cmd_buffer *pbuf;
1983 struct netxen_skb_frag *buffrag;
1984 struct cmd_desc_type0 *hwdesc, *first_desc;
1985 struct pci_dev *pdev;
1986 int i, k;
1987 int delta = 0;
1988 struct skb_frag_struct *frag;
1989
1990 u32 producer;
1991 int frag_count, no_of_desc;
1992 u32 num_txd = tx_ring->num_desc;
1993
1994 frag_count = skb_shinfo(skb)->nr_frags + 1;
1995
1996 /* 14 frags supported for normal packet and
1997 * 32 frags supported for TSO packet
1998 */
1999 if (!skb_is_gso(skb) && frag_count > NETXEN_MAX_FRAGS_PER_TX) {
2000
2001 for (i = 0; i < (frag_count - NETXEN_MAX_FRAGS_PER_TX); i++) {
2002 frag = &skb_shinfo(skb)->frags[i];
2003 delta += skb_frag_size(frag);
2004 }
2005
2006 if (!__pskb_pull_tail(skb, delta))
2007 goto drop_packet;
2008
2009 frag_count = 1 + skb_shinfo(skb)->nr_frags;
2010 }
2011 /* 4 fragments per cmd des */
2012 no_of_desc = (frag_count + 3) >> 2;
2013
2014 if (unlikely(netxen_tx_avail(tx_ring) <= TX_STOP_THRESH)) {
2015 netif_stop_queue(netdev);
2016 smp_mb();
2017 if (netxen_tx_avail(tx_ring) > TX_STOP_THRESH)
2018 netif_start_queue(netdev);
2019 else
2020 return NETDEV_TX_BUSY;
2021 }
2022
2023 producer = tx_ring->producer;
2024 pbuf = &tx_ring->cmd_buf_arr[producer];
2025
2026 pdev = adapter->pdev;
2027
2028 if (netxen_map_tx_skb(pdev, skb, pbuf))
2029 goto drop_packet;
2030
2031 pbuf->skb = skb;
2032 pbuf->frag_count = frag_count;
2033
2034 first_desc = hwdesc = &tx_ring->desc_head[producer];
2035 netxen_clear_cmddesc((u64 *)hwdesc);
2036
2037 netxen_set_tx_frags_len(first_desc, frag_count, skb->len);
2038 netxen_set_tx_port(first_desc, adapter->portnum);
2039
2040 for (i = 0; i < frag_count; i++) {
2041
2042 k = i % 4;
2043
2044 if ((k == 0) && (i > 0)) {
2045 /* move to next desc.*/
2046 producer = get_next_index(producer, num_txd);
2047 hwdesc = &tx_ring->desc_head[producer];
2048 netxen_clear_cmddesc((u64 *)hwdesc);
2049 tx_ring->cmd_buf_arr[producer].skb = NULL;
2050 }
2051
2052 buffrag = &pbuf->frag_array[i];
2053
2054 hwdesc->buffer_length[k] = cpu_to_le16(buffrag->length);
2055 switch (k) {
2056 case 0:
2057 hwdesc->addr_buffer1 = cpu_to_le64(buffrag->dma);
2058 break;
2059 case 1:
2060 hwdesc->addr_buffer2 = cpu_to_le64(buffrag->dma);
2061 break;
2062 case 2:
2063 hwdesc->addr_buffer3 = cpu_to_le64(buffrag->dma);
2064 break;
2065 case 3:
2066 hwdesc->addr_buffer4 = cpu_to_le64(buffrag->dma);
2067 break;
2068 }
2069 }
2070
2071 tx_ring->producer = get_next_index(producer, num_txd);
2072
2073 netxen_tso_check(netdev, tx_ring, first_desc, skb);
2074
2075 adapter->stats.txbytes += skb->len;
2076 adapter->stats.xmitcalled++;
2077
2078 netxen_nic_update_cmd_producer(adapter, tx_ring);
2079
2080 return NETDEV_TX_OK;
2081
2082 drop_packet:
2083 adapter->stats.txdropped++;
2084 dev_kfree_skb_any(skb);
2085 return NETDEV_TX_OK;
2086 }
2087
netxen_nic_check_temp(struct netxen_adapter * adapter)2088 static int netxen_nic_check_temp(struct netxen_adapter *adapter)
2089 {
2090 struct net_device *netdev = adapter->netdev;
2091 uint32_t temp, temp_state, temp_val;
2092 int rv = 0;
2093
2094 temp = NXRD32(adapter, CRB_TEMP_STATE);
2095
2096 temp_state = nx_get_temp_state(temp);
2097 temp_val = nx_get_temp_val(temp);
2098
2099 if (temp_state == NX_TEMP_PANIC) {
2100 printk(KERN_ALERT
2101 "%s: Device temperature %d degrees C exceeds"
2102 " maximum allowed. Hardware has been shut down.\n",
2103 netdev->name, temp_val);
2104 rv = 1;
2105 } else if (temp_state == NX_TEMP_WARN) {
2106 if (adapter->temp == NX_TEMP_NORMAL) {
2107 printk(KERN_ALERT
2108 "%s: Device temperature %d degrees C "
2109 "exceeds operating range."
2110 " Immediate action needed.\n",
2111 netdev->name, temp_val);
2112 }
2113 } else {
2114 if (adapter->temp == NX_TEMP_WARN) {
2115 printk(KERN_INFO
2116 "%s: Device temperature is now %d degrees C"
2117 " in normal range.\n", netdev->name,
2118 temp_val);
2119 }
2120 }
2121 adapter->temp = temp_state;
2122 return rv;
2123 }
2124
netxen_advert_link_change(struct netxen_adapter * adapter,int linkup)2125 void netxen_advert_link_change(struct netxen_adapter *adapter, int linkup)
2126 {
2127 struct net_device *netdev = adapter->netdev;
2128
2129 if (adapter->ahw.linkup && !linkup) {
2130 printk(KERN_INFO "%s: %s NIC Link is down\n",
2131 netxen_nic_driver_name, netdev->name);
2132 adapter->ahw.linkup = 0;
2133 if (netif_running(netdev)) {
2134 netif_carrier_off(netdev);
2135 netif_stop_queue(netdev);
2136 }
2137 adapter->link_changed = !adapter->has_link_events;
2138 } else if (!adapter->ahw.linkup && linkup) {
2139 printk(KERN_INFO "%s: %s NIC Link is up\n",
2140 netxen_nic_driver_name, netdev->name);
2141 adapter->ahw.linkup = 1;
2142 if (netif_running(netdev)) {
2143 netif_carrier_on(netdev);
2144 netif_wake_queue(netdev);
2145 }
2146 adapter->link_changed = !adapter->has_link_events;
2147 }
2148 }
2149
netxen_nic_handle_phy_intr(struct netxen_adapter * adapter)2150 static void netxen_nic_handle_phy_intr(struct netxen_adapter *adapter)
2151 {
2152 u32 val, port, linkup;
2153
2154 port = adapter->physical_port;
2155
2156 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
2157 val = NXRD32(adapter, CRB_XG_STATE_P3);
2158 val = XG_LINK_STATE_P3(adapter->ahw.pci_func, val);
2159 linkup = (val == XG_LINK_UP_P3);
2160 } else {
2161 val = NXRD32(adapter, CRB_XG_STATE);
2162 val = (val >> port*8) & 0xff;
2163 linkup = (val == XG_LINK_UP);
2164 }
2165
2166 netxen_advert_link_change(adapter, linkup);
2167 }
2168
netxen_tx_timeout(struct net_device * netdev)2169 static void netxen_tx_timeout(struct net_device *netdev)
2170 {
2171 struct netxen_adapter *adapter = netdev_priv(netdev);
2172
2173 if (test_bit(__NX_RESETTING, &adapter->state))
2174 return;
2175
2176 dev_err(&netdev->dev, "transmit timeout, resetting.\n");
2177 schedule_work(&adapter->tx_timeout_task);
2178 }
2179
netxen_tx_timeout_task(struct work_struct * work)2180 static void netxen_tx_timeout_task(struct work_struct *work)
2181 {
2182 struct netxen_adapter *adapter =
2183 container_of(work, struct netxen_adapter, tx_timeout_task);
2184
2185 if (!netif_running(adapter->netdev))
2186 return;
2187
2188 if (test_and_set_bit(__NX_RESETTING, &adapter->state))
2189 return;
2190
2191 if (++adapter->tx_timeo_cnt >= NX_MAX_TX_TIMEOUTS)
2192 goto request_reset;
2193
2194 rtnl_lock();
2195 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
2196 /* try to scrub interrupt */
2197 netxen_napi_disable(adapter);
2198
2199 netxen_napi_enable(adapter);
2200
2201 netif_wake_queue(adapter->netdev);
2202
2203 clear_bit(__NX_RESETTING, &adapter->state);
2204 } else {
2205 clear_bit(__NX_RESETTING, &adapter->state);
2206 if (netxen_nic_reset_context(adapter)) {
2207 rtnl_unlock();
2208 goto request_reset;
2209 }
2210 }
2211 adapter->netdev->trans_start = jiffies;
2212 rtnl_unlock();
2213 return;
2214
2215 request_reset:
2216 adapter->need_fw_reset = 1;
2217 clear_bit(__NX_RESETTING, &adapter->state);
2218 }
2219
netxen_nic_get_stats(struct net_device * netdev,struct rtnl_link_stats64 * stats)2220 static struct rtnl_link_stats64 *netxen_nic_get_stats(struct net_device *netdev,
2221 struct rtnl_link_stats64 *stats)
2222 {
2223 struct netxen_adapter *adapter = netdev_priv(netdev);
2224
2225 stats->rx_packets = adapter->stats.rx_pkts + adapter->stats.lro_pkts;
2226 stats->tx_packets = adapter->stats.xmitfinished;
2227 stats->rx_bytes = adapter->stats.rxbytes;
2228 stats->tx_bytes = adapter->stats.txbytes;
2229 stats->rx_dropped = adapter->stats.rxdropped;
2230 stats->tx_dropped = adapter->stats.txdropped;
2231
2232 return stats;
2233 }
2234
netxen_intr(int irq,void * data)2235 static irqreturn_t netxen_intr(int irq, void *data)
2236 {
2237 struct nx_host_sds_ring *sds_ring = data;
2238 struct netxen_adapter *adapter = sds_ring->adapter;
2239 u32 status = 0;
2240
2241 status = readl(adapter->isr_int_vec);
2242
2243 if (!(status & adapter->int_vec_bit))
2244 return IRQ_NONE;
2245
2246 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
2247 /* check interrupt state machine, to be sure */
2248 status = readl(adapter->crb_int_state_reg);
2249 if (!ISR_LEGACY_INT_TRIGGERED(status))
2250 return IRQ_NONE;
2251
2252 } else {
2253 unsigned long our_int = 0;
2254
2255 our_int = readl(adapter->crb_int_state_reg);
2256
2257 /* not our interrupt */
2258 if (!test_and_clear_bit((7 + adapter->portnum), &our_int))
2259 return IRQ_NONE;
2260
2261 /* claim interrupt */
2262 writel((our_int & 0xffffffff), adapter->crb_int_state_reg);
2263
2264 /* clear interrupt */
2265 netxen_nic_disable_int(sds_ring);
2266 }
2267
2268 writel(0xffffffff, adapter->tgt_status_reg);
2269 /* read twice to ensure write is flushed */
2270 readl(adapter->isr_int_vec);
2271 readl(adapter->isr_int_vec);
2272
2273 napi_schedule(&sds_ring->napi);
2274
2275 return IRQ_HANDLED;
2276 }
2277
netxen_msi_intr(int irq,void * data)2278 static irqreturn_t netxen_msi_intr(int irq, void *data)
2279 {
2280 struct nx_host_sds_ring *sds_ring = data;
2281 struct netxen_adapter *adapter = sds_ring->adapter;
2282
2283 /* clear interrupt */
2284 writel(0xffffffff, adapter->tgt_status_reg);
2285
2286 napi_schedule(&sds_ring->napi);
2287 return IRQ_HANDLED;
2288 }
2289
netxen_msix_intr(int irq,void * data)2290 static irqreturn_t netxen_msix_intr(int irq, void *data)
2291 {
2292 struct nx_host_sds_ring *sds_ring = data;
2293
2294 napi_schedule(&sds_ring->napi);
2295 return IRQ_HANDLED;
2296 }
2297
netxen_nic_poll(struct napi_struct * napi,int budget)2298 static int netxen_nic_poll(struct napi_struct *napi, int budget)
2299 {
2300 struct nx_host_sds_ring *sds_ring =
2301 container_of(napi, struct nx_host_sds_ring, napi);
2302
2303 struct netxen_adapter *adapter = sds_ring->adapter;
2304
2305 int tx_complete;
2306 int work_done;
2307
2308 tx_complete = netxen_process_cmd_ring(adapter);
2309
2310 work_done = netxen_process_rcv_ring(sds_ring, budget);
2311
2312 if ((work_done < budget) && tx_complete) {
2313 napi_complete(&sds_ring->napi);
2314 if (test_bit(__NX_DEV_UP, &adapter->state))
2315 netxen_nic_enable_int(sds_ring);
2316 }
2317
2318 return work_done;
2319 }
2320
2321 #ifdef CONFIG_NET_POLL_CONTROLLER
netxen_nic_poll_controller(struct net_device * netdev)2322 static void netxen_nic_poll_controller(struct net_device *netdev)
2323 {
2324 int ring;
2325 struct nx_host_sds_ring *sds_ring;
2326 struct netxen_adapter *adapter = netdev_priv(netdev);
2327 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
2328
2329 disable_irq(adapter->irq);
2330 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
2331 sds_ring = &recv_ctx->sds_rings[ring];
2332 netxen_intr(adapter->irq, sds_ring);
2333 }
2334 enable_irq(adapter->irq);
2335 }
2336 #endif
2337
2338 static int
nx_incr_dev_ref_cnt(struct netxen_adapter * adapter)2339 nx_incr_dev_ref_cnt(struct netxen_adapter *adapter)
2340 {
2341 int count;
2342 if (netxen_api_lock(adapter))
2343 return -EIO;
2344
2345 count = NXRD32(adapter, NX_CRB_DEV_REF_COUNT);
2346
2347 NXWR32(adapter, NX_CRB_DEV_REF_COUNT, ++count);
2348
2349 netxen_api_unlock(adapter);
2350 return count;
2351 }
2352
2353 static int
nx_decr_dev_ref_cnt(struct netxen_adapter * adapter)2354 nx_decr_dev_ref_cnt(struct netxen_adapter *adapter)
2355 {
2356 int count, state;
2357 if (netxen_api_lock(adapter))
2358 return -EIO;
2359
2360 count = NXRD32(adapter, NX_CRB_DEV_REF_COUNT);
2361 WARN_ON(count == 0);
2362
2363 NXWR32(adapter, NX_CRB_DEV_REF_COUNT, --count);
2364 state = NXRD32(adapter, NX_CRB_DEV_STATE);
2365
2366 if (count == 0 && state != NX_DEV_FAILED)
2367 NXWR32(adapter, NX_CRB_DEV_STATE, NX_DEV_COLD);
2368
2369 netxen_api_unlock(adapter);
2370 return count;
2371 }
2372
2373 static int
nx_dev_request_aer(struct netxen_adapter * adapter)2374 nx_dev_request_aer(struct netxen_adapter *adapter)
2375 {
2376 u32 state;
2377 int ret = -EINVAL;
2378
2379 if (netxen_api_lock(adapter))
2380 return ret;
2381
2382 state = NXRD32(adapter, NX_CRB_DEV_STATE);
2383
2384 if (state == NX_DEV_NEED_AER)
2385 ret = 0;
2386 else if (state == NX_DEV_READY) {
2387 NXWR32(adapter, NX_CRB_DEV_STATE, NX_DEV_NEED_AER);
2388 ret = 0;
2389 }
2390
2391 netxen_api_unlock(adapter);
2392 return ret;
2393 }
2394
2395 int
nx_dev_request_reset(struct netxen_adapter * adapter)2396 nx_dev_request_reset(struct netxen_adapter *adapter)
2397 {
2398 u32 state;
2399 int ret = -EINVAL;
2400
2401 if (netxen_api_lock(adapter))
2402 return ret;
2403
2404 state = NXRD32(adapter, NX_CRB_DEV_STATE);
2405
2406 if (state == NX_DEV_NEED_RESET || state == NX_DEV_FAILED)
2407 ret = 0;
2408 else if (state != NX_DEV_INITALIZING && state != NX_DEV_NEED_AER) {
2409 NXWR32(adapter, NX_CRB_DEV_STATE, NX_DEV_NEED_RESET);
2410 adapter->flags |= NETXEN_FW_RESET_OWNER;
2411 ret = 0;
2412 }
2413
2414 netxen_api_unlock(adapter);
2415
2416 return ret;
2417 }
2418
2419 static int
netxen_can_start_firmware(struct netxen_adapter * adapter)2420 netxen_can_start_firmware(struct netxen_adapter *adapter)
2421 {
2422 int count;
2423 int can_start = 0;
2424
2425 if (netxen_api_lock(adapter)) {
2426 nx_incr_dev_ref_cnt(adapter);
2427 return -1;
2428 }
2429
2430 count = NXRD32(adapter, NX_CRB_DEV_REF_COUNT);
2431
2432 if ((count < 0) || (count >= NX_MAX_PCI_FUNC))
2433 count = 0;
2434
2435 if (count == 0) {
2436 can_start = 1;
2437 NXWR32(adapter, NX_CRB_DEV_STATE, NX_DEV_INITALIZING);
2438 }
2439
2440 NXWR32(adapter, NX_CRB_DEV_REF_COUNT, ++count);
2441
2442 netxen_api_unlock(adapter);
2443
2444 return can_start;
2445 }
2446
2447 static void
netxen_schedule_work(struct netxen_adapter * adapter,work_func_t func,int delay)2448 netxen_schedule_work(struct netxen_adapter *adapter,
2449 work_func_t func, int delay)
2450 {
2451 INIT_DELAYED_WORK(&adapter->fw_work, func);
2452 schedule_delayed_work(&adapter->fw_work, delay);
2453 }
2454
2455 static void
netxen_cancel_fw_work(struct netxen_adapter * adapter)2456 netxen_cancel_fw_work(struct netxen_adapter *adapter)
2457 {
2458 while (test_and_set_bit(__NX_RESETTING, &adapter->state))
2459 msleep(10);
2460
2461 cancel_delayed_work_sync(&adapter->fw_work);
2462 }
2463
2464 static void
netxen_attach_work(struct work_struct * work)2465 netxen_attach_work(struct work_struct *work)
2466 {
2467 struct netxen_adapter *adapter = container_of(work,
2468 struct netxen_adapter, fw_work.work);
2469 struct net_device *netdev = adapter->netdev;
2470 int err = 0;
2471
2472 if (netif_running(netdev)) {
2473 err = netxen_nic_attach(adapter);
2474 if (err)
2475 goto done;
2476
2477 err = netxen_nic_up(adapter, netdev);
2478 if (err) {
2479 netxen_nic_detach(adapter);
2480 goto done;
2481 }
2482
2483 netxen_restore_indev_addr(netdev, NETDEV_UP);
2484 }
2485
2486 netif_device_attach(netdev);
2487
2488 done:
2489 adapter->fw_fail_cnt = 0;
2490 clear_bit(__NX_RESETTING, &adapter->state);
2491 netxen_schedule_work(adapter, netxen_fw_poll_work, FW_POLL_DELAY);
2492 }
2493
2494 static void
netxen_fwinit_work(struct work_struct * work)2495 netxen_fwinit_work(struct work_struct *work)
2496 {
2497 struct netxen_adapter *adapter = container_of(work,
2498 struct netxen_adapter, fw_work.work);
2499 int dev_state;
2500 int count;
2501 dev_state = NXRD32(adapter, NX_CRB_DEV_STATE);
2502 if (adapter->flags & NETXEN_FW_RESET_OWNER) {
2503 count = NXRD32(adapter, NX_CRB_DEV_REF_COUNT);
2504 WARN_ON(count == 0);
2505 if (count == 1) {
2506 if (adapter->mdump.md_enabled) {
2507 rtnl_lock();
2508 netxen_dump_fw(adapter);
2509 rtnl_unlock();
2510 }
2511 adapter->flags &= ~NETXEN_FW_RESET_OWNER;
2512 if (netxen_api_lock(adapter)) {
2513 clear_bit(__NX_RESETTING, &adapter->state);
2514 NXWR32(adapter, NX_CRB_DEV_STATE,
2515 NX_DEV_FAILED);
2516 return;
2517 }
2518 count = NXRD32(adapter, NX_CRB_DEV_REF_COUNT);
2519 NXWR32(adapter, NX_CRB_DEV_REF_COUNT, --count);
2520 NXWR32(adapter, NX_CRB_DEV_STATE, NX_DEV_COLD);
2521 dev_state = NX_DEV_COLD;
2522 netxen_api_unlock(adapter);
2523 }
2524 }
2525
2526 switch (dev_state) {
2527 case NX_DEV_COLD:
2528 case NX_DEV_READY:
2529 if (!netxen_start_firmware(adapter)) {
2530 netxen_schedule_work(adapter, netxen_attach_work, 0);
2531 return;
2532 }
2533 break;
2534
2535 case NX_DEV_NEED_RESET:
2536 case NX_DEV_INITALIZING:
2537 netxen_schedule_work(adapter,
2538 netxen_fwinit_work, 2 * FW_POLL_DELAY);
2539 return;
2540
2541 case NX_DEV_FAILED:
2542 default:
2543 nx_incr_dev_ref_cnt(adapter);
2544 break;
2545 }
2546
2547 if (netxen_api_lock(adapter)) {
2548 clear_bit(__NX_RESETTING, &adapter->state);
2549 return;
2550 }
2551 NXWR32(adapter, NX_CRB_DEV_STATE, NX_DEV_FAILED);
2552 netxen_api_unlock(adapter);
2553 dev_err(&adapter->pdev->dev, "%s: Device initialization Failed\n",
2554 adapter->netdev->name);
2555
2556 clear_bit(__NX_RESETTING, &adapter->state);
2557 }
2558
2559 static void
netxen_detach_work(struct work_struct * work)2560 netxen_detach_work(struct work_struct *work)
2561 {
2562 struct netxen_adapter *adapter = container_of(work,
2563 struct netxen_adapter, fw_work.work);
2564 struct net_device *netdev = adapter->netdev;
2565 int ref_cnt = 0, delay;
2566 u32 status;
2567
2568 netif_device_detach(netdev);
2569
2570 netxen_nic_down(adapter, netdev);
2571
2572 rtnl_lock();
2573 netxen_nic_detach(adapter);
2574 rtnl_unlock();
2575
2576 status = NXRD32(adapter, NETXEN_PEG_HALT_STATUS1);
2577
2578 if (status & NX_RCODE_FATAL_ERROR)
2579 goto err_ret;
2580
2581 if (adapter->temp == NX_TEMP_PANIC)
2582 goto err_ret;
2583
2584 if (!(adapter->flags & NETXEN_FW_RESET_OWNER))
2585 ref_cnt = nx_decr_dev_ref_cnt(adapter);
2586
2587 if (ref_cnt == -EIO)
2588 goto err_ret;
2589
2590 delay = (ref_cnt == 0) ? 0 : (2 * FW_POLL_DELAY);
2591
2592 adapter->fw_wait_cnt = 0;
2593 netxen_schedule_work(adapter, netxen_fwinit_work, delay);
2594
2595 return;
2596
2597 err_ret:
2598 clear_bit(__NX_RESETTING, &adapter->state);
2599 }
2600
2601 static int
netxen_check_health(struct netxen_adapter * adapter)2602 netxen_check_health(struct netxen_adapter *adapter)
2603 {
2604 u32 state, heartbit;
2605 u32 peg_status;
2606 struct net_device *netdev = adapter->netdev;
2607
2608 state = NXRD32(adapter, NX_CRB_DEV_STATE);
2609 if (state == NX_DEV_NEED_AER)
2610 return 0;
2611
2612 if (netxen_nic_check_temp(adapter))
2613 goto detach;
2614
2615 if (adapter->need_fw_reset) {
2616 if (nx_dev_request_reset(adapter))
2617 return 0;
2618 goto detach;
2619 }
2620
2621 /* NX_DEV_NEED_RESET, this state can be marked in two cases
2622 * 1. Tx timeout 2. Fw hang
2623 * Send request to destroy context in case of tx timeout only
2624 * and doesn't required in case of Fw hang
2625 */
2626 if (state == NX_DEV_NEED_RESET || state == NX_DEV_FAILED) {
2627 adapter->need_fw_reset = 1;
2628 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
2629 goto detach;
2630 }
2631
2632 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
2633 return 0;
2634
2635 heartbit = NXRD32(adapter, NETXEN_PEG_ALIVE_COUNTER);
2636 if (heartbit != adapter->heartbit) {
2637 adapter->heartbit = heartbit;
2638 adapter->fw_fail_cnt = 0;
2639 if (adapter->need_fw_reset)
2640 goto detach;
2641 return 0;
2642 }
2643
2644 if (++adapter->fw_fail_cnt < FW_FAIL_THRESH)
2645 return 0;
2646
2647 if (nx_dev_request_reset(adapter))
2648 return 0;
2649
2650 clear_bit(__NX_FW_ATTACHED, &adapter->state);
2651
2652 dev_err(&netdev->dev, "firmware hang detected\n");
2653 peg_status = NXRD32(adapter, NETXEN_PEG_HALT_STATUS1);
2654 dev_err(&adapter->pdev->dev, "Dumping hw/fw registers\n"
2655 "PEG_HALT_STATUS1: 0x%x, PEG_HALT_STATUS2: 0x%x,\n"
2656 "PEG_NET_0_PC: 0x%x, PEG_NET_1_PC: 0x%x,\n"
2657 "PEG_NET_2_PC: 0x%x, PEG_NET_3_PC: 0x%x,\n"
2658 "PEG_NET_4_PC: 0x%x\n",
2659 peg_status,
2660 NXRD32(adapter, NETXEN_PEG_HALT_STATUS2),
2661 NXRD32(adapter, NETXEN_CRB_PEG_NET_0 + 0x3c),
2662 NXRD32(adapter, NETXEN_CRB_PEG_NET_1 + 0x3c),
2663 NXRD32(adapter, NETXEN_CRB_PEG_NET_2 + 0x3c),
2664 NXRD32(adapter, NETXEN_CRB_PEG_NET_3 + 0x3c),
2665 NXRD32(adapter, NETXEN_CRB_PEG_NET_4 + 0x3c));
2666 if (NX_FWERROR_PEGSTAT1(peg_status) == 0x67)
2667 dev_err(&adapter->pdev->dev,
2668 "Firmware aborted with error code 0x00006700. "
2669 "Device is being reset.\n");
2670 detach:
2671 if ((auto_fw_reset == AUTO_FW_RESET_ENABLED) &&
2672 !test_and_set_bit(__NX_RESETTING, &adapter->state))
2673 netxen_schedule_work(adapter, netxen_detach_work, 0);
2674 return 1;
2675 }
2676
2677 static void
netxen_fw_poll_work(struct work_struct * work)2678 netxen_fw_poll_work(struct work_struct *work)
2679 {
2680 struct netxen_adapter *adapter = container_of(work,
2681 struct netxen_adapter, fw_work.work);
2682
2683 if (test_bit(__NX_RESETTING, &adapter->state))
2684 goto reschedule;
2685
2686 if (test_bit(__NX_DEV_UP, &adapter->state)) {
2687 if (!adapter->has_link_events) {
2688
2689 netxen_nic_handle_phy_intr(adapter);
2690
2691 if (adapter->link_changed)
2692 netxen_nic_set_link_parameters(adapter);
2693 }
2694 }
2695
2696 if (netxen_check_health(adapter))
2697 return;
2698
2699 reschedule:
2700 netxen_schedule_work(adapter, netxen_fw_poll_work, FW_POLL_DELAY);
2701 }
2702
2703 static ssize_t
netxen_store_bridged_mode(struct device * dev,struct device_attribute * attr,const char * buf,size_t len)2704 netxen_store_bridged_mode(struct device *dev,
2705 struct device_attribute *attr, const char *buf, size_t len)
2706 {
2707 struct net_device *net = to_net_dev(dev);
2708 struct netxen_adapter *adapter = netdev_priv(net);
2709 unsigned long new;
2710 int ret = -EINVAL;
2711
2712 if (!(adapter->capabilities & NX_FW_CAPABILITY_BDG))
2713 goto err_out;
2714
2715 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
2716 goto err_out;
2717
2718 if (strict_strtoul(buf, 2, &new))
2719 goto err_out;
2720
2721 if (!netxen_config_bridged_mode(adapter, !!new))
2722 ret = len;
2723
2724 err_out:
2725 return ret;
2726 }
2727
2728 static ssize_t
netxen_show_bridged_mode(struct device * dev,struct device_attribute * attr,char * buf)2729 netxen_show_bridged_mode(struct device *dev,
2730 struct device_attribute *attr, char *buf)
2731 {
2732 struct net_device *net = to_net_dev(dev);
2733 struct netxen_adapter *adapter;
2734 int bridged_mode = 0;
2735
2736 adapter = netdev_priv(net);
2737
2738 if (adapter->capabilities & NX_FW_CAPABILITY_BDG)
2739 bridged_mode = !!(adapter->flags & NETXEN_NIC_BRIDGE_ENABLED);
2740
2741 return sprintf(buf, "%d\n", bridged_mode);
2742 }
2743
2744 static struct device_attribute dev_attr_bridged_mode = {
2745 .attr = {.name = "bridged_mode", .mode = (S_IRUGO | S_IWUSR)},
2746 .show = netxen_show_bridged_mode,
2747 .store = netxen_store_bridged_mode,
2748 };
2749
2750 static ssize_t
netxen_store_diag_mode(struct device * dev,struct device_attribute * attr,const char * buf,size_t len)2751 netxen_store_diag_mode(struct device *dev,
2752 struct device_attribute *attr, const char *buf, size_t len)
2753 {
2754 struct netxen_adapter *adapter = dev_get_drvdata(dev);
2755 unsigned long new;
2756
2757 if (strict_strtoul(buf, 2, &new))
2758 return -EINVAL;
2759
2760 if (!!new != !!(adapter->flags & NETXEN_NIC_DIAG_ENABLED))
2761 adapter->flags ^= NETXEN_NIC_DIAG_ENABLED;
2762
2763 return len;
2764 }
2765
2766 static ssize_t
netxen_show_diag_mode(struct device * dev,struct device_attribute * attr,char * buf)2767 netxen_show_diag_mode(struct device *dev,
2768 struct device_attribute *attr, char *buf)
2769 {
2770 struct netxen_adapter *adapter = dev_get_drvdata(dev);
2771
2772 return sprintf(buf, "%d\n",
2773 !!(adapter->flags & NETXEN_NIC_DIAG_ENABLED));
2774 }
2775
2776 static struct device_attribute dev_attr_diag_mode = {
2777 .attr = {.name = "diag_mode", .mode = (S_IRUGO | S_IWUSR)},
2778 .show = netxen_show_diag_mode,
2779 .store = netxen_store_diag_mode,
2780 };
2781
2782 static int
netxen_sysfs_validate_crb(struct netxen_adapter * adapter,loff_t offset,size_t size)2783 netxen_sysfs_validate_crb(struct netxen_adapter *adapter,
2784 loff_t offset, size_t size)
2785 {
2786 size_t crb_size = 4;
2787
2788 if (!(adapter->flags & NETXEN_NIC_DIAG_ENABLED))
2789 return -EIO;
2790
2791 if (offset < NETXEN_PCI_CRBSPACE) {
2792 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
2793 return -EINVAL;
2794
2795 if (ADDR_IN_RANGE(offset, NETXEN_PCI_CAMQM,
2796 NETXEN_PCI_CAMQM_2M_END))
2797 crb_size = 8;
2798 else
2799 return -EINVAL;
2800 }
2801
2802 if ((size != crb_size) || (offset & (crb_size-1)))
2803 return -EINVAL;
2804
2805 return 0;
2806 }
2807
2808 static ssize_t
netxen_sysfs_read_crb(struct file * filp,struct kobject * kobj,struct bin_attribute * attr,char * buf,loff_t offset,size_t size)2809 netxen_sysfs_read_crb(struct file *filp, struct kobject *kobj,
2810 struct bin_attribute *attr,
2811 char *buf, loff_t offset, size_t size)
2812 {
2813 struct device *dev = container_of(kobj, struct device, kobj);
2814 struct netxen_adapter *adapter = dev_get_drvdata(dev);
2815 u32 data;
2816 u64 qmdata;
2817 int ret;
2818
2819 ret = netxen_sysfs_validate_crb(adapter, offset, size);
2820 if (ret != 0)
2821 return ret;
2822
2823 if (NX_IS_REVISION_P3(adapter->ahw.revision_id) &&
2824 ADDR_IN_RANGE(offset, NETXEN_PCI_CAMQM,
2825 NETXEN_PCI_CAMQM_2M_END)) {
2826 netxen_pci_camqm_read_2M(adapter, offset, &qmdata);
2827 memcpy(buf, &qmdata, size);
2828 } else {
2829 data = NXRD32(adapter, offset);
2830 memcpy(buf, &data, size);
2831 }
2832
2833 return size;
2834 }
2835
2836 static ssize_t
netxen_sysfs_write_crb(struct file * filp,struct kobject * kobj,struct bin_attribute * attr,char * buf,loff_t offset,size_t size)2837 netxen_sysfs_write_crb(struct file *filp, struct kobject *kobj,
2838 struct bin_attribute *attr,
2839 char *buf, loff_t offset, size_t size)
2840 {
2841 struct device *dev = container_of(kobj, struct device, kobj);
2842 struct netxen_adapter *adapter = dev_get_drvdata(dev);
2843 u32 data;
2844 u64 qmdata;
2845 int ret;
2846
2847 ret = netxen_sysfs_validate_crb(adapter, offset, size);
2848 if (ret != 0)
2849 return ret;
2850
2851 if (NX_IS_REVISION_P3(adapter->ahw.revision_id) &&
2852 ADDR_IN_RANGE(offset, NETXEN_PCI_CAMQM,
2853 NETXEN_PCI_CAMQM_2M_END)) {
2854 memcpy(&qmdata, buf, size);
2855 netxen_pci_camqm_write_2M(adapter, offset, qmdata);
2856 } else {
2857 memcpy(&data, buf, size);
2858 NXWR32(adapter, offset, data);
2859 }
2860
2861 return size;
2862 }
2863
2864 static int
netxen_sysfs_validate_mem(struct netxen_adapter * adapter,loff_t offset,size_t size)2865 netxen_sysfs_validate_mem(struct netxen_adapter *adapter,
2866 loff_t offset, size_t size)
2867 {
2868 if (!(adapter->flags & NETXEN_NIC_DIAG_ENABLED))
2869 return -EIO;
2870
2871 if ((size != 8) || (offset & 0x7))
2872 return -EIO;
2873
2874 return 0;
2875 }
2876
2877 static ssize_t
netxen_sysfs_read_mem(struct file * filp,struct kobject * kobj,struct bin_attribute * attr,char * buf,loff_t offset,size_t size)2878 netxen_sysfs_read_mem(struct file *filp, struct kobject *kobj,
2879 struct bin_attribute *attr,
2880 char *buf, loff_t offset, size_t size)
2881 {
2882 struct device *dev = container_of(kobj, struct device, kobj);
2883 struct netxen_adapter *adapter = dev_get_drvdata(dev);
2884 u64 data;
2885 int ret;
2886
2887 ret = netxen_sysfs_validate_mem(adapter, offset, size);
2888 if (ret != 0)
2889 return ret;
2890
2891 if (adapter->pci_mem_read(adapter, offset, &data))
2892 return -EIO;
2893
2894 memcpy(buf, &data, size);
2895
2896 return size;
2897 }
2898
netxen_sysfs_write_mem(struct file * filp,struct kobject * kobj,struct bin_attribute * attr,char * buf,loff_t offset,size_t size)2899 static ssize_t netxen_sysfs_write_mem(struct file *filp, struct kobject *kobj,
2900 struct bin_attribute *attr, char *buf,
2901 loff_t offset, size_t size)
2902 {
2903 struct device *dev = container_of(kobj, struct device, kobj);
2904 struct netxen_adapter *adapter = dev_get_drvdata(dev);
2905 u64 data;
2906 int ret;
2907
2908 ret = netxen_sysfs_validate_mem(adapter, offset, size);
2909 if (ret != 0)
2910 return ret;
2911
2912 memcpy(&data, buf, size);
2913
2914 if (adapter->pci_mem_write(adapter, offset, data))
2915 return -EIO;
2916
2917 return size;
2918 }
2919
2920
2921 static struct bin_attribute bin_attr_crb = {
2922 .attr = {.name = "crb", .mode = (S_IRUGO | S_IWUSR)},
2923 .size = 0,
2924 .read = netxen_sysfs_read_crb,
2925 .write = netxen_sysfs_write_crb,
2926 };
2927
2928 static struct bin_attribute bin_attr_mem = {
2929 .attr = {.name = "mem", .mode = (S_IRUGO | S_IWUSR)},
2930 .size = 0,
2931 .read = netxen_sysfs_read_mem,
2932 .write = netxen_sysfs_write_mem,
2933 };
2934
2935
2936 static void
netxen_create_sysfs_entries(struct netxen_adapter * adapter)2937 netxen_create_sysfs_entries(struct netxen_adapter *adapter)
2938 {
2939 struct device *dev = &adapter->pdev->dev;
2940
2941 if (adapter->capabilities & NX_FW_CAPABILITY_BDG) {
2942 /* bridged_mode control */
2943 if (device_create_file(dev, &dev_attr_bridged_mode)) {
2944 dev_warn(dev,
2945 "failed to create bridged_mode sysfs entry\n");
2946 }
2947 }
2948 }
2949
2950 static void
netxen_remove_sysfs_entries(struct netxen_adapter * adapter)2951 netxen_remove_sysfs_entries(struct netxen_adapter *adapter)
2952 {
2953 struct device *dev = &adapter->pdev->dev;
2954
2955 if (adapter->capabilities & NX_FW_CAPABILITY_BDG)
2956 device_remove_file(dev, &dev_attr_bridged_mode);
2957 }
2958
2959 static void
netxen_create_diag_entries(struct netxen_adapter * adapter)2960 netxen_create_diag_entries(struct netxen_adapter *adapter)
2961 {
2962 struct pci_dev *pdev = adapter->pdev;
2963 struct device *dev;
2964
2965 dev = &pdev->dev;
2966 if (device_create_file(dev, &dev_attr_diag_mode))
2967 dev_info(dev, "failed to create diag_mode sysfs entry\n");
2968 if (device_create_bin_file(dev, &bin_attr_crb))
2969 dev_info(dev, "failed to create crb sysfs entry\n");
2970 if (device_create_bin_file(dev, &bin_attr_mem))
2971 dev_info(dev, "failed to create mem sysfs entry\n");
2972 }
2973
2974
2975 static void
netxen_remove_diag_entries(struct netxen_adapter * adapter)2976 netxen_remove_diag_entries(struct netxen_adapter *adapter)
2977 {
2978 struct pci_dev *pdev = adapter->pdev;
2979 struct device *dev = &pdev->dev;
2980
2981 device_remove_file(dev, &dev_attr_diag_mode);
2982 device_remove_bin_file(dev, &bin_attr_crb);
2983 device_remove_bin_file(dev, &bin_attr_mem);
2984 }
2985
2986 #ifdef CONFIG_INET
2987
2988 #define is_netxen_netdev(dev) (dev->netdev_ops == &netxen_netdev_ops)
2989
2990 static int
netxen_destip_supported(struct netxen_adapter * adapter)2991 netxen_destip_supported(struct netxen_adapter *adapter)
2992 {
2993 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
2994 return 0;
2995
2996 if (adapter->ahw.cut_through)
2997 return 0;
2998
2999 return 1;
3000 }
3001
3002 static void
netxen_free_vlan_ip_list(struct netxen_adapter * adapter)3003 netxen_free_vlan_ip_list(struct netxen_adapter *adapter)
3004 {
3005 struct nx_vlan_ip_list *cur;
3006 struct list_head *head = &adapter->vlan_ip_list;
3007
3008 while (!list_empty(head)) {
3009 cur = list_entry(head->next, struct nx_vlan_ip_list, list);
3010 netxen_config_ipaddr(adapter, cur->ip_addr, NX_IP_DOWN);
3011 list_del(&cur->list);
3012 kfree(cur);
3013 }
3014
3015 }
3016 static void
netxen_list_config_vlan_ip(struct netxen_adapter * adapter,struct in_ifaddr * ifa,unsigned long event)3017 netxen_list_config_vlan_ip(struct netxen_adapter *adapter,
3018 struct in_ifaddr *ifa, unsigned long event)
3019 {
3020 struct net_device *dev;
3021 struct nx_vlan_ip_list *cur, *tmp_cur;
3022 struct list_head *head;
3023
3024 dev = ifa->ifa_dev ? ifa->ifa_dev->dev : NULL;
3025
3026 if (dev == NULL)
3027 return;
3028
3029 if (!is_vlan_dev(dev))
3030 return;
3031
3032 switch (event) {
3033 case NX_IP_UP:
3034 list_for_each(head, &adapter->vlan_ip_list) {
3035 cur = list_entry(head, struct nx_vlan_ip_list, list);
3036
3037 if (cur->ip_addr == ifa->ifa_address)
3038 return;
3039 }
3040
3041 cur = kzalloc(sizeof(struct nx_vlan_ip_list), GFP_ATOMIC);
3042 if (cur == NULL) {
3043 printk(KERN_ERR "%s: failed to add vlan ip to list\n",
3044 adapter->netdev->name);
3045 return;
3046 }
3047
3048 cur->ip_addr = ifa->ifa_address;
3049 list_add_tail(&cur->list, &adapter->vlan_ip_list);
3050 break;
3051 case NX_IP_DOWN:
3052 list_for_each_entry_safe(cur, tmp_cur,
3053 &adapter->vlan_ip_list, list) {
3054 if (cur->ip_addr == ifa->ifa_address) {
3055 list_del(&cur->list);
3056 kfree(cur);
3057 break;
3058 }
3059 }
3060 }
3061 }
3062 static void
netxen_config_indev_addr(struct netxen_adapter * adapter,struct net_device * dev,unsigned long event)3063 netxen_config_indev_addr(struct netxen_adapter *adapter,
3064 struct net_device *dev, unsigned long event)
3065 {
3066 struct in_device *indev;
3067
3068 if (!netxen_destip_supported(adapter))
3069 return;
3070
3071 indev = in_dev_get(dev);
3072 if (!indev)
3073 return;
3074
3075 for_ifa(indev) {
3076 switch (event) {
3077 case NETDEV_UP:
3078 netxen_config_ipaddr(adapter,
3079 ifa->ifa_address, NX_IP_UP);
3080 netxen_list_config_vlan_ip(adapter, ifa, NX_IP_UP);
3081 break;
3082 case NETDEV_DOWN:
3083 netxen_config_ipaddr(adapter,
3084 ifa->ifa_address, NX_IP_DOWN);
3085 netxen_list_config_vlan_ip(adapter, ifa, NX_IP_DOWN);
3086 break;
3087 default:
3088 break;
3089 }
3090 } endfor_ifa(indev);
3091
3092 in_dev_put(indev);
3093 }
3094
3095 static void
netxen_restore_indev_addr(struct net_device * netdev,unsigned long event)3096 netxen_restore_indev_addr(struct net_device *netdev, unsigned long event)
3097
3098 {
3099 struct netxen_adapter *adapter = netdev_priv(netdev);
3100 struct nx_vlan_ip_list *pos, *tmp_pos;
3101 unsigned long ip_event;
3102
3103 ip_event = (event == NETDEV_UP) ? NX_IP_UP : NX_IP_DOWN;
3104 netxen_config_indev_addr(adapter, netdev, event);
3105
3106 list_for_each_entry_safe(pos, tmp_pos, &adapter->vlan_ip_list, list) {
3107 netxen_config_ipaddr(adapter, pos->ip_addr, ip_event);
3108 }
3109 }
3110
netxen_netdev_event(struct notifier_block * this,unsigned long event,void * ptr)3111 static int netxen_netdev_event(struct notifier_block *this,
3112 unsigned long event, void *ptr)
3113 {
3114 struct netxen_adapter *adapter;
3115 struct net_device *dev = (struct net_device *)ptr;
3116 struct net_device *orig_dev = dev;
3117
3118 recheck:
3119 if (dev == NULL)
3120 goto done;
3121
3122 if (dev->priv_flags & IFF_802_1Q_VLAN) {
3123 dev = vlan_dev_real_dev(dev);
3124 goto recheck;
3125 }
3126
3127 if (!is_netxen_netdev(dev))
3128 goto done;
3129
3130 adapter = netdev_priv(dev);
3131
3132 if (!adapter)
3133 goto done;
3134
3135 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
3136 goto done;
3137
3138 netxen_config_indev_addr(adapter, orig_dev, event);
3139 done:
3140 return NOTIFY_DONE;
3141 }
3142
3143 static int
netxen_inetaddr_event(struct notifier_block * this,unsigned long event,void * ptr)3144 netxen_inetaddr_event(struct notifier_block *this,
3145 unsigned long event, void *ptr)
3146 {
3147 struct netxen_adapter *adapter;
3148 struct net_device *dev;
3149
3150 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
3151
3152 dev = ifa->ifa_dev ? ifa->ifa_dev->dev : NULL;
3153
3154 recheck:
3155 if (dev == NULL)
3156 goto done;
3157
3158 if (dev->priv_flags & IFF_802_1Q_VLAN) {
3159 dev = vlan_dev_real_dev(dev);
3160 goto recheck;
3161 }
3162
3163 if (!is_netxen_netdev(dev))
3164 goto done;
3165
3166 adapter = netdev_priv(dev);
3167
3168 if (!adapter || !netxen_destip_supported(adapter))
3169 goto done;
3170
3171 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
3172 goto done;
3173
3174 switch (event) {
3175 case NETDEV_UP:
3176 netxen_config_ipaddr(adapter, ifa->ifa_address, NX_IP_UP);
3177 netxen_list_config_vlan_ip(adapter, ifa, NX_IP_UP);
3178 break;
3179 case NETDEV_DOWN:
3180 netxen_config_ipaddr(adapter, ifa->ifa_address, NX_IP_DOWN);
3181 netxen_list_config_vlan_ip(adapter, ifa, NX_IP_DOWN);
3182 break;
3183 default:
3184 break;
3185 }
3186
3187 done:
3188 return NOTIFY_DONE;
3189 }
3190
3191 static struct notifier_block netxen_netdev_cb = {
3192 .notifier_call = netxen_netdev_event,
3193 };
3194
3195 static struct notifier_block netxen_inetaddr_cb = {
3196 .notifier_call = netxen_inetaddr_event,
3197 };
3198 #else
3199 static void
netxen_restore_indev_addr(struct net_device * dev,unsigned long event)3200 netxen_restore_indev_addr(struct net_device *dev, unsigned long event)
3201 { }
3202 static void
netxen_free_vlan_ip_list(struct netxen_adapter * adapter)3203 netxen_free_vlan_ip_list(struct netxen_adapter *adapter)
3204 { }
3205 #endif
3206
3207 static struct pci_error_handlers netxen_err_handler = {
3208 .error_detected = netxen_io_error_detected,
3209 .slot_reset = netxen_io_slot_reset,
3210 .resume = netxen_io_resume,
3211 };
3212
3213 static struct pci_driver netxen_driver = {
3214 .name = netxen_nic_driver_name,
3215 .id_table = netxen_pci_tbl,
3216 .probe = netxen_nic_probe,
3217 .remove = __devexit_p(netxen_nic_remove),
3218 #ifdef CONFIG_PM
3219 .suspend = netxen_nic_suspend,
3220 .resume = netxen_nic_resume,
3221 #endif
3222 .shutdown = netxen_nic_shutdown,
3223 .err_handler = &netxen_err_handler
3224 };
3225
netxen_init_module(void)3226 static int __init netxen_init_module(void)
3227 {
3228 printk(KERN_INFO "%s\n", netxen_nic_driver_string);
3229
3230 #ifdef CONFIG_INET
3231 register_netdevice_notifier(&netxen_netdev_cb);
3232 register_inetaddr_notifier(&netxen_inetaddr_cb);
3233 #endif
3234 return pci_register_driver(&netxen_driver);
3235 }
3236
3237 module_init(netxen_init_module);
3238
netxen_exit_module(void)3239 static void __exit netxen_exit_module(void)
3240 {
3241 pci_unregister_driver(&netxen_driver);
3242
3243 #ifdef CONFIG_INET
3244 unregister_inetaddr_notifier(&netxen_inetaddr_cb);
3245 unregister_netdevice_notifier(&netxen_netdev_cb);
3246 #endif
3247 }
3248
3249 module_exit(netxen_exit_module);
3250