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