]>
Commit | Line | Data |
---|---|---|
3d396eb1 | 1 | /* |
5d242f1c | 2 | * Copyright (C) 2003 - 2009 NetXen, Inc. |
3d396eb1 | 3 | * All rights reserved. |
80922fbc | 4 | * |
3d396eb1 AK |
5 | * This program is free software; you can redistribute it and/or |
6 | * modify it under the terms of the GNU General Public License | |
7 | * as published by the Free Software Foundation; either version 2 | |
8 | * of the License, or (at your option) any later version. | |
80922fbc | 9 | * |
3d396eb1 AK |
10 | * This program is distributed in the hope that it will be useful, but |
11 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | * GNU General Public License for more details. | |
80922fbc | 14 | * |
3d396eb1 AK |
15 | * You should have received a copy of the GNU General Public License |
16 | * along with this program; if not, write to the Free Software | |
17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, | |
18 | * MA 02111-1307, USA. | |
80922fbc | 19 | * |
3d396eb1 AK |
20 | * The full GNU General Public License is included in this distribution |
21 | * in the file called LICENSE. | |
80922fbc | 22 | * |
3d396eb1 AK |
23 | * Contact Information: |
24 | * info@netxen.com | |
5d242f1c DP |
25 | * NetXen Inc, |
26 | * 18922 Forge Drive | |
27 | * Cupertino, CA 95014-0701 | |
3d396eb1 AK |
28 | * |
29 | */ | |
30 | ||
cb8011ad | 31 | #include <linux/vmalloc.h> |
e98e3350 | 32 | #include <linux/interrupt.h> |
3d396eb1 AK |
33 | #include "netxen_nic_hw.h" |
34 | ||
35 | #include "netxen_nic.h" | |
3d396eb1 | 36 | |
1494a814 | 37 | #include <linux/dma-mapping.h> |
391587c3 | 38 | #include <linux/if_vlan.h> |
c9bdd4b5 | 39 | #include <net/ip.h> |
00977784 | 40 | #include <linux/ipv6.h> |
6598b169 | 41 | #include <linux/inetdevice.h> |
1494a814 | 42 | |
3d396eb1 AK |
43 | MODULE_DESCRIPTION("NetXen Multi port (1/10) Gigabit Network Driver"); |
44 | MODULE_LICENSE("GPL"); | |
45 | MODULE_VERSION(NETXEN_NIC_LINUX_VERSIONID); | |
46 | ||
ceded32f | 47 | char netxen_nic_driver_name[] = "netxen_nic"; |
3d396eb1 | 48 | static char netxen_nic_driver_string[] = "NetXen Network Driver version " |
cb8011ad | 49 | NETXEN_NIC_LINUX_VERSIONID; |
3d396eb1 | 50 | |
2956640d DP |
51 | static int port_mode = NETXEN_PORT_MODE_AUTO_NEG; |
52 | ||
53 | /* Default to restricted 1G auto-neg mode */ | |
54 | static int wol_port_mode = 5; | |
55 | ||
56 | static int use_msi = 1; | |
57 | ||
58 | static int use_msi_x = 1; | |
59 | ||
3d396eb1 AK |
60 | /* Local functions to NetXen NIC driver */ |
61 | static int __devinit netxen_nic_probe(struct pci_dev *pdev, | |
2956640d | 62 | const struct pci_device_id *ent); |
3d396eb1 AK |
63 | static void __devexit netxen_nic_remove(struct pci_dev *pdev); |
64 | static int netxen_nic_open(struct net_device *netdev); | |
65 | static int netxen_nic_close(struct net_device *netdev); | |
61357325 SH |
66 | static netdev_tx_t netxen_nic_xmit_frame(struct sk_buff *, |
67 | struct net_device *); | |
3d396eb1 | 68 | static void netxen_tx_timeout(struct net_device *netdev); |
f17443f4 | 69 | static void netxen_reset_task(struct work_struct *work); |
3d396eb1 | 70 | static void netxen_watchdog(unsigned long); |
bea3348e | 71 | static int netxen_nic_poll(struct napi_struct *napi, int budget); |
3d396eb1 AK |
72 | #ifdef CONFIG_NET_POLL_CONTROLLER |
73 | static void netxen_nic_poll_controller(struct net_device *netdev); | |
74 | #endif | |
fa3ce355 NK |
75 | |
76 | static void netxen_create_sysfs_entries(struct netxen_adapter *adapter); | |
77 | static void netxen_remove_sysfs_entries(struct netxen_adapter *adapter); | |
78 | ||
1494a814 | 79 | static irqreturn_t netxen_intr(int irq, void *data); |
05aaa02d | 80 | static irqreturn_t netxen_msi_intr(int irq, void *data); |
b3df68f8 | 81 | static irqreturn_t netxen_msix_intr(int irq, void *data); |
3d396eb1 AK |
82 | |
83 | /* PCI Device ID Table */ | |
70081ac5 | 84 | #define ENTRY(device) \ |
040dec3b | 85 | {PCI_DEVICE(PCI_VENDOR_ID_NETXEN, (device)), \ |
70081ac5 AV |
86 | .class = PCI_CLASS_NETWORK_ETHERNET << 8, .class_mask = ~0} |
87 | ||
3d396eb1 | 88 | static struct pci_device_id netxen_pci_tbl[] __devinitdata = { |
040dec3b DP |
89 | ENTRY(PCI_DEVICE_ID_NX2031_10GXSR), |
90 | ENTRY(PCI_DEVICE_ID_NX2031_10GCX4), | |
91 | ENTRY(PCI_DEVICE_ID_NX2031_4GCU), | |
92 | ENTRY(PCI_DEVICE_ID_NX2031_IMEZ), | |
93 | ENTRY(PCI_DEVICE_ID_NX2031_HMEZ), | |
94 | ENTRY(PCI_DEVICE_ID_NX2031_XG_MGMT), | |
95 | ENTRY(PCI_DEVICE_ID_NX2031_XG_MGMT2), | |
96 | ENTRY(PCI_DEVICE_ID_NX3031), | |
3d396eb1 AK |
97 | {0,} |
98 | }; | |
99 | ||
100 | MODULE_DEVICE_TABLE(pci, netxen_pci_tbl); | |
101 | ||
7830b22c DP |
102 | static uint32_t crb_cmd_producer[4] = { |
103 | CRB_CMD_PRODUCER_OFFSET, CRB_CMD_PRODUCER_OFFSET_1, | |
104 | CRB_CMD_PRODUCER_OFFSET_2, CRB_CMD_PRODUCER_OFFSET_3 | |
105 | }; | |
106 | ||
c9fc891f | 107 | void |
3ce06a32 | 108 | netxen_nic_update_cmd_producer(struct netxen_adapter *adapter, |
cb2107be | 109 | struct nx_host_tx_ring *tx_ring) |
3176ff3e | 110 | { |
cb2107be DP |
111 | NXWR32(adapter, tx_ring->crb_cmd_producer, tx_ring->producer); |
112 | ||
113 | if (netxen_tx_avail(tx_ring) <= TX_STOP_THRESH) { | |
114 | netif_stop_queue(adapter->netdev); | |
115 | smp_mb(); | |
116 | } | |
3176ff3e MT |
117 | } |
118 | ||
7830b22c DP |
119 | static uint32_t crb_cmd_consumer[4] = { |
120 | CRB_CMD_CONSUMER_OFFSET, CRB_CMD_CONSUMER_OFFSET_1, | |
121 | CRB_CMD_CONSUMER_OFFSET_2, CRB_CMD_CONSUMER_OFFSET_3 | |
122 | }; | |
123 | ||
3ce06a32 DP |
124 | static inline void |
125 | netxen_nic_update_cmd_consumer(struct netxen_adapter *adapter, | |
cb2107be | 126 | struct nx_host_tx_ring *tx_ring) |
3176ff3e | 127 | { |
cb2107be | 128 | NXWR32(adapter, tx_ring->crb_cmd_consumer, tx_ring->sw_consumer); |
3176ff3e MT |
129 | } |
130 | ||
2956640d | 131 | static uint32_t msi_tgt_status[8] = { |
443be796 | 132 | ISR_INT_TARGET_STATUS, ISR_INT_TARGET_STATUS_F1, |
2956640d DP |
133 | ISR_INT_TARGET_STATUS_F2, ISR_INT_TARGET_STATUS_F3, |
134 | ISR_INT_TARGET_STATUS_F4, ISR_INT_TARGET_STATUS_F5, | |
135 | ISR_INT_TARGET_STATUS_F6, ISR_INT_TARGET_STATUS_F7 | |
443be796 DP |
136 | }; |
137 | ||
2956640d DP |
138 | static struct netxen_legacy_intr_set legacy_intr[] = NX_LEGACY_INTR_CONFIG; |
139 | ||
d8b100c5 | 140 | static inline void netxen_nic_disable_int(struct nx_host_sds_ring *sds_ring) |
4638aef1 | 141 | { |
d8b100c5 DP |
142 | struct netxen_adapter *adapter = sds_ring->adapter; |
143 | ||
f98a9f69 | 144 | NXWR32(adapter, sds_ring->crb_intr_mask, 0); |
4638aef1 SH |
145 | } |
146 | ||
d8b100c5 | 147 | static inline void netxen_nic_enable_int(struct nx_host_sds_ring *sds_ring) |
4638aef1 | 148 | { |
d8b100c5 DP |
149 | struct netxen_adapter *adapter = sds_ring->adapter; |
150 | ||
f98a9f69 | 151 | NXWR32(adapter, sds_ring->crb_intr_mask, 0x1); |
4638aef1 | 152 | |
092bc571 DP |
153 | if (!NETXEN_IS_MSI_FAMILY(adapter)) |
154 | adapter->pci_write_immediate(adapter, | |
155 | adapter->legacy_intr.tgt_mask_reg, 0xfbff); | |
4638aef1 SH |
156 | } |
157 | ||
71dcddbd DP |
158 | static int |
159 | netxen_alloc_sds_rings(struct netxen_recv_context *recv_ctx, int count) | |
160 | { | |
161 | int size = sizeof(struct nx_host_sds_ring) * count; | |
162 | ||
163 | recv_ctx->sds_rings = kzalloc(size, GFP_KERNEL); | |
164 | ||
165 | return (recv_ctx->sds_rings == NULL); | |
166 | } | |
167 | ||
d8b100c5 | 168 | static void |
71dcddbd DP |
169 | netxen_free_sds_rings(struct netxen_recv_context *recv_ctx) |
170 | { | |
171 | if (recv_ctx->sds_rings != NULL) | |
172 | kfree(recv_ctx->sds_rings); | |
232e7d68 DP |
173 | |
174 | recv_ctx->sds_rings = NULL; | |
71dcddbd DP |
175 | } |
176 | ||
177 | static int | |
d8b100c5 DP |
178 | netxen_napi_add(struct netxen_adapter *adapter, struct net_device *netdev) |
179 | { | |
180 | int ring; | |
181 | struct nx_host_sds_ring *sds_ring; | |
182 | struct netxen_recv_context *recv_ctx = &adapter->recv_ctx; | |
183 | ||
71dcddbd | 184 | if (netxen_alloc_sds_rings(recv_ctx, adapter->max_sds_rings)) |
f17443f4 | 185 | return -ENOMEM; |
71dcddbd | 186 | |
d8b100c5 DP |
187 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { |
188 | sds_ring = &recv_ctx->sds_rings[ring]; | |
189 | netif_napi_add(netdev, &sds_ring->napi, | |
190 | netxen_nic_poll, NETXEN_NETDEV_WEIGHT); | |
191 | } | |
71dcddbd DP |
192 | |
193 | return 0; | |
d8b100c5 DP |
194 | } |
195 | ||
232e7d68 DP |
196 | static void |
197 | netxen_napi_del(struct netxen_adapter *adapter) | |
198 | { | |
199 | int ring; | |
200 | struct nx_host_sds_ring *sds_ring; | |
201 | struct netxen_recv_context *recv_ctx = &adapter->recv_ctx; | |
202 | ||
203 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { | |
204 | sds_ring = &recv_ctx->sds_rings[ring]; | |
205 | netif_napi_del(&sds_ring->napi); | |
206 | } | |
207 | ||
208 | netxen_free_sds_rings(&adapter->recv_ctx); | |
209 | } | |
210 | ||
d8b100c5 DP |
211 | static void |
212 | netxen_napi_enable(struct netxen_adapter *adapter) | |
213 | { | |
214 | int ring; | |
215 | struct nx_host_sds_ring *sds_ring; | |
216 | struct netxen_recv_context *recv_ctx = &adapter->recv_ctx; | |
217 | ||
218 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { | |
219 | sds_ring = &recv_ctx->sds_rings[ring]; | |
220 | napi_enable(&sds_ring->napi); | |
221 | netxen_nic_enable_int(sds_ring); | |
222 | } | |
223 | } | |
224 | ||
225 | static void | |
226 | netxen_napi_disable(struct netxen_adapter *adapter) | |
227 | { | |
228 | int ring; | |
229 | struct nx_host_sds_ring *sds_ring; | |
230 | struct netxen_recv_context *recv_ctx = &adapter->recv_ctx; | |
231 | ||
232 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { | |
233 | sds_ring = &recv_ctx->sds_rings[ring]; | |
be339aee | 234 | netxen_nic_disable_int(sds_ring); |
b2af9cb0 DP |
235 | napi_synchronize(&sds_ring->napi); |
236 | napi_disable(&sds_ring->napi); | |
d8b100c5 DP |
237 | } |
238 | } | |
239 | ||
50c643e7 | 240 | static int nx_set_dma_mask(struct netxen_adapter *adapter) |
2956640d DP |
241 | { |
242 | struct pci_dev *pdev = adapter->pdev; | |
1f434f63 DP |
243 | uint64_t mask, cmask; |
244 | ||
245 | adapter->pci_using_dac = 0; | |
2956640d | 246 | |
6afd142f | 247 | mask = DMA_BIT_MASK(32); |
6afd142f | 248 | cmask = DMA_BIT_MASK(32); |
1f434f63 | 249 | |
50c643e7 | 250 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) { |
1f434f63 | 251 | #ifndef CONFIG_IA64 |
6afd142f | 252 | mask = DMA_BIT_MASK(35); |
1f434f63 | 253 | #endif |
50c643e7 DP |
254 | } else { |
255 | mask = DMA_BIT_MASK(39); | |
256 | cmask = mask; | |
257 | } | |
258 | ||
2956640d | 259 | if (pci_set_dma_mask(pdev, mask) == 0 && |
1f434f63 | 260 | pci_set_consistent_dma_mask(pdev, cmask) == 0) { |
2956640d DP |
261 | adapter->pci_using_dac = 1; |
262 | return 0; | |
263 | } | |
2956640d | 264 | |
1f434f63 DP |
265 | return -EIO; |
266 | } | |
267 | ||
268 | /* Update addressable range if firmware supports it */ | |
269 | static int | |
270 | nx_update_dma_mask(struct netxen_adapter *adapter) | |
271 | { | |
272 | int change, shift, err; | |
50c643e7 | 273 | uint64_t mask, old_mask, old_cmask; |
1f434f63 DP |
274 | struct pci_dev *pdev = adapter->pdev; |
275 | ||
276 | change = 0; | |
277 | ||
f98a9f69 | 278 | shift = NXRD32(adapter, CRB_DMA_SHIFT); |
f60f7856 | 279 | if (shift > 32) |
1f434f63 DP |
280 | return 0; |
281 | ||
282 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id) && (shift > 9)) | |
283 | change = 1; | |
284 | else if ((adapter->ahw.revision_id == NX_P2_C1) && (shift <= 4)) | |
285 | change = 1; | |
286 | ||
287 | if (change) { | |
288 | old_mask = pdev->dma_mask; | |
50c643e7 DP |
289 | old_cmask = pdev->dev.coherent_dma_mask; |
290 | ||
f60f7856 | 291 | mask = DMA_BIT_MASK(32+shift); |
1f434f63 DP |
292 | |
293 | err = pci_set_dma_mask(pdev, mask); | |
294 | if (err) | |
50c643e7 DP |
295 | goto err_out; |
296 | ||
297 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) { | |
298 | ||
299 | err = pci_set_consistent_dma_mask(pdev, mask); | |
300 | if (err) | |
301 | goto err_out; | |
302 | } | |
303 | dev_info(&pdev->dev, "using %d-bit dma mask\n", 32+shift); | |
2956640d DP |
304 | } |
305 | ||
2956640d | 306 | return 0; |
50c643e7 DP |
307 | |
308 | err_out: | |
309 | pci_set_dma_mask(pdev, old_mask); | |
310 | pci_set_consistent_dma_mask(pdev, old_cmask); | |
311 | return err; | |
2956640d DP |
312 | } |
313 | ||
24767ab1 DP |
314 | static void |
315 | netxen_check_options(struct netxen_adapter *adapter) | |
2956640d | 316 | { |
24767ab1 DP |
317 | if (adapter->ahw.port_type == NETXEN_NIC_XGBE) { |
318 | adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_10G; | |
319 | adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G; | |
320 | } else if (adapter->ahw.port_type == NETXEN_NIC_GBE) { | |
321 | adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_1G; | |
322 | adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G; | |
323 | } | |
2956640d | 324 | |
f6d21f44 DP |
325 | adapter->msix_supported = 0; |
326 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) { | |
c7860a2a | 327 | adapter->msix_supported = !!use_msi_x; |
f6d21f44 DP |
328 | adapter->rss_supported = !!use_msi_x; |
329 | } else if (adapter->fw_version >= NETXEN_VERSION_CODE(3, 4, 336)) { | |
330 | switch (adapter->ahw.board_type) { | |
331 | case NETXEN_BRDTYPE_P2_SB31_10G: | |
332 | case NETXEN_BRDTYPE_P2_SB31_10G_CX4: | |
f6d21f44 DP |
333 | adapter->msix_supported = !!use_msi_x; |
334 | adapter->rss_supported = !!use_msi_x; | |
335 | break; | |
336 | default: | |
337 | break; | |
338 | } | |
339 | } | |
2956640d | 340 | |
24767ab1 | 341 | adapter->num_txd = MAX_CMD_DESCRIPTORS; |
2956640d | 342 | |
24767ab1 DP |
343 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) { |
344 | adapter->num_lro_rxd = MAX_LRO_RCV_DESCRIPTORS; | |
345 | adapter->max_rds_rings = 3; | |
346 | } else { | |
347 | adapter->num_lro_rxd = 0; | |
348 | adapter->max_rds_rings = 2; | |
349 | } | |
2956640d DP |
350 | } |
351 | ||
352 | static int | |
353 | netxen_check_hw_init(struct netxen_adapter *adapter, int first_boot) | |
354 | { | |
27c915a4 | 355 | u32 val, timeout; |
2956640d DP |
356 | |
357 | if (first_boot == 0x55555555) { | |
358 | /* This is the first boot after power up */ | |
f98a9f69 | 359 | NXWR32(adapter, NETXEN_CAM_RAM(0x1fc), NETXEN_BDINFO_MAGIC); |
27c915a4 DP |
360 | |
361 | if (!NX_IS_REVISION_P2(adapter->ahw.revision_id)) | |
362 | return 0; | |
2956640d DP |
363 | |
364 | /* PCI bus master workaround */ | |
f98a9f69 | 365 | first_boot = NXRD32(adapter, NETXEN_PCIE_REG(0x4)); |
2956640d DP |
366 | if (!(first_boot & 0x4)) { |
367 | first_boot |= 0x4; | |
f98a9f69 DP |
368 | NXWR32(adapter, NETXEN_PCIE_REG(0x4), first_boot); |
369 | first_boot = NXRD32(adapter, NETXEN_PCIE_REG(0x4)); | |
2956640d DP |
370 | } |
371 | ||
372 | /* This is the first boot after power up */ | |
f98a9f69 | 373 | first_boot = NXRD32(adapter, NETXEN_ROMUSB_GLB_SW_RESET); |
2956640d DP |
374 | if (first_boot != 0x80000f) { |
375 | /* clear the register for future unloads/loads */ | |
f98a9f69 | 376 | NXWR32(adapter, NETXEN_CAM_RAM(0x1fc), 0); |
27c915a4 | 377 | return -EIO; |
2956640d DP |
378 | } |
379 | ||
27c915a4 | 380 | /* Start P2 boot loader */ |
f98a9f69 DP |
381 | val = NXRD32(adapter, NETXEN_ROMUSB_GLB_PEGTUNE_DONE); |
382 | NXWR32(adapter, NETXEN_ROMUSB_GLB_PEGTUNE_DONE, val | 0x1); | |
27c915a4 DP |
383 | timeout = 0; |
384 | do { | |
385 | msleep(1); | |
f98a9f69 | 386 | val = NXRD32(adapter, NETXEN_CAM_RAM(0x1fc)); |
27c915a4 DP |
387 | |
388 | if (++timeout > 5000) | |
389 | return -EIO; | |
390 | ||
391 | } while (val == NETXEN_BDINFO_MAGIC); | |
2956640d | 392 | } |
27c915a4 | 393 | return 0; |
2956640d DP |
394 | } |
395 | ||
396 | static void netxen_set_port_mode(struct netxen_adapter *adapter) | |
397 | { | |
398 | u32 val, data; | |
399 | ||
1e2d0059 | 400 | val = adapter->ahw.board_type; |
2956640d DP |
401 | if ((val == NETXEN_BRDTYPE_P3_HMEZ) || |
402 | (val == NETXEN_BRDTYPE_P3_XG_LOM)) { | |
403 | if (port_mode == NETXEN_PORT_MODE_802_3_AP) { | |
404 | data = NETXEN_PORT_MODE_802_3_AP; | |
f98a9f69 | 405 | NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data); |
2956640d DP |
406 | } else if (port_mode == NETXEN_PORT_MODE_XG) { |
407 | data = NETXEN_PORT_MODE_XG; | |
f98a9f69 | 408 | NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data); |
2956640d DP |
409 | } else if (port_mode == NETXEN_PORT_MODE_AUTO_NEG_1G) { |
410 | data = NETXEN_PORT_MODE_AUTO_NEG_1G; | |
f98a9f69 | 411 | NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data); |
2956640d DP |
412 | } else if (port_mode == NETXEN_PORT_MODE_AUTO_NEG_XG) { |
413 | data = NETXEN_PORT_MODE_AUTO_NEG_XG; | |
f98a9f69 | 414 | NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data); |
2956640d DP |
415 | } else { |
416 | data = NETXEN_PORT_MODE_AUTO_NEG; | |
f98a9f69 | 417 | NXWR32(adapter, NETXEN_PORT_MODE_ADDR, data); |
2956640d DP |
418 | } |
419 | ||
420 | if ((wol_port_mode != NETXEN_PORT_MODE_802_3_AP) && | |
421 | (wol_port_mode != NETXEN_PORT_MODE_XG) && | |
422 | (wol_port_mode != NETXEN_PORT_MODE_AUTO_NEG_1G) && | |
423 | (wol_port_mode != NETXEN_PORT_MODE_AUTO_NEG_XG)) { | |
424 | wol_port_mode = NETXEN_PORT_MODE_AUTO_NEG; | |
425 | } | |
f98a9f69 | 426 | NXWR32(adapter, NETXEN_WOL_PORT_MODE, wol_port_mode); |
2956640d DP |
427 | } |
428 | } | |
429 | ||
2956640d DP |
430 | static void netxen_set_msix_bit(struct pci_dev *pdev, int enable) |
431 | { | |
432 | u32 control; | |
433 | int pos; | |
434 | ||
435 | pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX); | |
436 | if (pos) { | |
437 | pci_read_config_dword(pdev, pos, &control); | |
438 | if (enable) | |
439 | control |= PCI_MSIX_FLAGS_ENABLE; | |
440 | else | |
441 | control = 0; | |
442 | pci_write_config_dword(pdev, pos, control); | |
443 | } | |
444 | } | |
445 | ||
be339aee | 446 | static void netxen_init_msix_entries(struct netxen_adapter *adapter, int count) |
2956640d DP |
447 | { |
448 | int i; | |
449 | ||
be339aee | 450 | for (i = 0; i < count; i++) |
2956640d DP |
451 | adapter->msix_entries[i].entry = i; |
452 | } | |
453 | ||
9dc28efe DP |
454 | static int |
455 | netxen_read_mac_addr(struct netxen_adapter *adapter) | |
456 | { | |
457 | int i; | |
458 | unsigned char *p; | |
459 | __le64 mac_addr; | |
9dc28efe DP |
460 | struct net_device *netdev = adapter->netdev; |
461 | struct pci_dev *pdev = adapter->pdev; | |
462 | ||
9dc28efe DP |
463 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) { |
464 | if (netxen_p3_get_mac_addr(adapter, &mac_addr) != 0) | |
465 | return -EIO; | |
466 | } else { | |
467 | if (netxen_get_flash_mac_addr(adapter, &mac_addr) != 0) | |
468 | return -EIO; | |
469 | } | |
470 | ||
471 | p = (unsigned char *)&mac_addr; | |
472 | for (i = 0; i < 6; i++) | |
473 | netdev->dev_addr[i] = *(p + 5 - i); | |
474 | ||
475 | memcpy(netdev->perm_addr, netdev->dev_addr, netdev->addr_len); | |
476 | ||
477 | /* set station address */ | |
478 | ||
e174961c JB |
479 | if (!is_valid_ether_addr(netdev->perm_addr)) |
480 | dev_warn(&pdev->dev, "Bad MAC address %pM.\n", netdev->dev_addr); | |
9dc28efe DP |
481 | |
482 | return 0; | |
483 | } | |
484 | ||
3d0a3cc9 DP |
485 | int netxen_nic_set_mac(struct net_device *netdev, void *p) |
486 | { | |
487 | struct netxen_adapter *adapter = netdev_priv(netdev); | |
488 | struct sockaddr *addr = p; | |
489 | ||
490 | if (!is_valid_ether_addr(addr->sa_data)) | |
491 | return -EINVAL; | |
492 | ||
493 | if (netif_running(netdev)) { | |
494 | netif_device_detach(netdev); | |
495 | netxen_napi_disable(adapter); | |
496 | } | |
497 | ||
498 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); | |
499 | adapter->macaddr_set(adapter, addr->sa_data); | |
500 | ||
501 | if (netif_running(netdev)) { | |
502 | netif_device_attach(netdev); | |
503 | netxen_napi_enable(adapter); | |
504 | } | |
505 | return 0; | |
506 | } | |
507 | ||
1abd266f SH |
508 | static void netxen_set_multicast_list(struct net_device *dev) |
509 | { | |
510 | struct netxen_adapter *adapter = netdev_priv(dev); | |
511 | ||
3d0a3cc9 | 512 | adapter->set_multi(dev); |
1abd266f SH |
513 | } |
514 | ||
515 | static const struct net_device_ops netxen_netdev_ops = { | |
516 | .ndo_open = netxen_nic_open, | |
517 | .ndo_stop = netxen_nic_close, | |
518 | .ndo_start_xmit = netxen_nic_xmit_frame, | |
519 | .ndo_get_stats = netxen_nic_get_stats, | |
520 | .ndo_validate_addr = eth_validate_addr, | |
521 | .ndo_set_multicast_list = netxen_set_multicast_list, | |
522 | .ndo_set_mac_address = netxen_nic_set_mac, | |
523 | .ndo_change_mtu = netxen_nic_change_mtu, | |
524 | .ndo_tx_timeout = netxen_tx_timeout, | |
525 | #ifdef CONFIG_NET_POLL_CONTROLLER | |
526 | .ndo_poll_controller = netxen_nic_poll_controller, | |
527 | #endif | |
528 | }; | |
529 | ||
97daee83 DP |
530 | static void |
531 | netxen_setup_intr(struct netxen_adapter *adapter) | |
532 | { | |
533 | struct netxen_legacy_intr_set *legacy_intrp; | |
534 | struct pci_dev *pdev = adapter->pdev; | |
be339aee DP |
535 | int err, num_msix; |
536 | ||
537 | if (adapter->rss_supported) { | |
538 | num_msix = (num_online_cpus() >= MSIX_ENTRIES_PER_ADAPTER) ? | |
539 | MSIX_ENTRIES_PER_ADAPTER : 2; | |
540 | } else | |
541 | num_msix = 1; | |
542 | ||
543 | adapter->max_sds_rings = 1; | |
97daee83 DP |
544 | |
545 | adapter->flags &= ~(NETXEN_NIC_MSI_ENABLED | NETXEN_NIC_MSIX_ENABLED); | |
97daee83 DP |
546 | |
547 | if (adapter->ahw.revision_id >= NX_P3_B0) | |
548 | legacy_intrp = &legacy_intr[adapter->ahw.pci_func]; | |
549 | else | |
550 | legacy_intrp = &legacy_intr[0]; | |
551 | adapter->legacy_intr.int_vec_bit = legacy_intrp->int_vec_bit; | |
552 | adapter->legacy_intr.tgt_status_reg = legacy_intrp->tgt_status_reg; | |
553 | adapter->legacy_intr.tgt_mask_reg = legacy_intrp->tgt_mask_reg; | |
554 | adapter->legacy_intr.pci_int_reg = legacy_intrp->pci_int_reg; | |
555 | ||
556 | netxen_set_msix_bit(pdev, 0); | |
557 | ||
558 | if (adapter->msix_supported) { | |
559 | ||
be339aee DP |
560 | netxen_init_msix_entries(adapter, num_msix); |
561 | err = pci_enable_msix(pdev, adapter->msix_entries, num_msix); | |
562 | if (err == 0) { | |
563 | adapter->flags |= NETXEN_NIC_MSIX_ENABLED; | |
564 | netxen_set_msix_bit(pdev, 1); | |
97daee83 | 565 | |
be339aee DP |
566 | if (adapter->rss_supported) |
567 | adapter->max_sds_rings = num_msix; | |
97daee83 | 568 | |
be339aee DP |
569 | dev_info(&pdev->dev, "using msi-x interrupts\n"); |
570 | return; | |
571 | } | |
572 | ||
573 | if (err > 0) | |
574 | pci_disable_msix(pdev); | |
575 | ||
576 | /* fall through for msi */ | |
97daee83 | 577 | } |
be339aee DP |
578 | |
579 | if (use_msi && !pci_enable_msi(pdev)) { | |
580 | adapter->flags |= NETXEN_NIC_MSI_ENABLED; | |
581 | adapter->msi_tgt_status = | |
582 | msi_tgt_status[adapter->ahw.pci_func]; | |
583 | dev_info(&pdev->dev, "using msi interrupts\n"); | |
f67f3408 | 584 | adapter->msix_entries[0].vector = pdev->irq; |
be339aee DP |
585 | return; |
586 | } | |
587 | ||
588 | dev_info(&pdev->dev, "using legacy interrupts\n"); | |
589 | adapter->msix_entries[0].vector = pdev->irq; | |
97daee83 DP |
590 | } |
591 | ||
592 | static void | |
593 | netxen_teardown_intr(struct netxen_adapter *adapter) | |
594 | { | |
595 | if (adapter->flags & NETXEN_NIC_MSIX_ENABLED) | |
596 | pci_disable_msix(adapter->pdev); | |
597 | if (adapter->flags & NETXEN_NIC_MSI_ENABLED) | |
598 | pci_disable_msi(adapter->pdev); | |
599 | } | |
600 | ||
601 | static void | |
602 | netxen_cleanup_pci_map(struct netxen_adapter *adapter) | |
603 | { | |
604 | if (adapter->ahw.db_base != NULL) | |
605 | iounmap(adapter->ahw.db_base); | |
606 | if (adapter->ahw.pci_base0 != NULL) | |
607 | iounmap(adapter->ahw.pci_base0); | |
608 | if (adapter->ahw.pci_base1 != NULL) | |
609 | iounmap(adapter->ahw.pci_base1); | |
610 | if (adapter->ahw.pci_base2 != NULL) | |
611 | iounmap(adapter->ahw.pci_base2); | |
612 | } | |
613 | ||
614 | static int | |
615 | netxen_setup_pci_map(struct netxen_adapter *adapter) | |
616 | { | |
617 | void __iomem *mem_ptr0 = NULL; | |
618 | void __iomem *mem_ptr1 = NULL; | |
619 | void __iomem *mem_ptr2 = NULL; | |
620 | void __iomem *db_ptr = NULL; | |
621 | ||
97daee83 DP |
622 | unsigned long mem_base, mem_len, db_base, db_len = 0, pci_len0 = 0; |
623 | ||
624 | struct pci_dev *pdev = adapter->pdev; | |
625 | int pci_func = adapter->ahw.pci_func; | |
626 | ||
627 | int err = 0; | |
628 | ||
629 | /* | |
630 | * Set the CRB window to invalid. If any register in window 0 is | |
631 | * accessed it should set the window to 0 and then reset it to 1. | |
632 | */ | |
633 | adapter->curr_window = 255; | |
634 | adapter->ahw.qdr_sn_window = -1; | |
635 | adapter->ahw.ddr_mn_window = -1; | |
636 | ||
637 | /* remap phys address */ | |
638 | mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */ | |
639 | mem_len = pci_resource_len(pdev, 0); | |
640 | pci_len0 = 0; | |
641 | ||
642 | adapter->hw_write_wx = netxen_nic_hw_write_wx_128M; | |
643 | adapter->hw_read_wx = netxen_nic_hw_read_wx_128M; | |
644 | adapter->pci_read_immediate = netxen_nic_pci_read_immediate_128M; | |
645 | adapter->pci_write_immediate = netxen_nic_pci_write_immediate_128M; | |
97daee83 DP |
646 | adapter->pci_set_window = netxen_nic_pci_set_window_128M; |
647 | adapter->pci_mem_read = netxen_nic_pci_mem_read_128M; | |
648 | adapter->pci_mem_write = netxen_nic_pci_mem_write_128M; | |
649 | ||
650 | /* 128 Meg of memory */ | |
651 | if (mem_len == NETXEN_PCI_128MB_SIZE) { | |
652 | mem_ptr0 = ioremap(mem_base, FIRST_PAGE_GROUP_SIZE); | |
653 | mem_ptr1 = ioremap(mem_base + SECOND_PAGE_GROUP_START, | |
654 | SECOND_PAGE_GROUP_SIZE); | |
655 | mem_ptr2 = ioremap(mem_base + THIRD_PAGE_GROUP_START, | |
656 | THIRD_PAGE_GROUP_SIZE); | |
97daee83 DP |
657 | } else if (mem_len == NETXEN_PCI_32MB_SIZE) { |
658 | mem_ptr1 = ioremap(mem_base, SECOND_PAGE_GROUP_SIZE); | |
659 | mem_ptr2 = ioremap(mem_base + THIRD_PAGE_GROUP_START - | |
660 | SECOND_PAGE_GROUP_START, THIRD_PAGE_GROUP_SIZE); | |
97daee83 DP |
661 | } else if (mem_len == NETXEN_PCI_2MB_SIZE) { |
662 | adapter->hw_write_wx = netxen_nic_hw_write_wx_2M; | |
663 | adapter->hw_read_wx = netxen_nic_hw_read_wx_2M; | |
664 | adapter->pci_read_immediate = netxen_nic_pci_read_immediate_2M; | |
665 | adapter->pci_write_immediate = | |
666 | netxen_nic_pci_write_immediate_2M; | |
97daee83 DP |
667 | adapter->pci_set_window = netxen_nic_pci_set_window_2M; |
668 | adapter->pci_mem_read = netxen_nic_pci_mem_read_2M; | |
669 | adapter->pci_mem_write = netxen_nic_pci_mem_write_2M; | |
670 | ||
671 | mem_ptr0 = pci_ioremap_bar(pdev, 0); | |
672 | if (mem_ptr0 == NULL) { | |
673 | dev_err(&pdev->dev, "failed to map PCI bar 0\n"); | |
674 | return -EIO; | |
675 | } | |
676 | pci_len0 = mem_len; | |
97daee83 DP |
677 | |
678 | adapter->ahw.ddr_mn_window = 0; | |
679 | adapter->ahw.qdr_sn_window = 0; | |
680 | ||
681 | adapter->ahw.mn_win_crb = 0x100000 + PCIX_MN_WINDOW + | |
682 | (pci_func * 0x20); | |
683 | adapter->ahw.ms_win_crb = 0x100000 + PCIX_SN_WINDOW; | |
684 | if (pci_func < 4) | |
685 | adapter->ahw.ms_win_crb += (pci_func * 0x20); | |
686 | else | |
687 | adapter->ahw.ms_win_crb += | |
688 | 0xA0 + ((pci_func - 4) * 0x10); | |
689 | } else { | |
690 | return -EIO; | |
691 | } | |
692 | ||
693 | dev_info(&pdev->dev, "%dMB memory map\n", (int)(mem_len>>20)); | |
694 | ||
695 | adapter->ahw.pci_base0 = mem_ptr0; | |
696 | adapter->ahw.pci_len0 = pci_len0; | |
97daee83 DP |
697 | adapter->ahw.pci_base1 = mem_ptr1; |
698 | adapter->ahw.pci_base2 = mem_ptr2; | |
699 | ||
700 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) | |
701 | goto skip_doorbell; | |
702 | ||
703 | db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */ | |
704 | db_len = pci_resource_len(pdev, 4); | |
705 | ||
706 | if (db_len == 0) { | |
707 | printk(KERN_ERR "%s: doorbell is disabled\n", | |
708 | netxen_nic_driver_name); | |
709 | err = -EIO; | |
710 | goto err_out; | |
711 | } | |
712 | ||
713 | db_ptr = ioremap(db_base, NETXEN_DB_MAPSIZE_BYTES); | |
714 | if (!db_ptr) { | |
715 | printk(KERN_ERR "%s: Failed to allocate doorbell map.", | |
716 | netxen_nic_driver_name); | |
717 | err = -EIO; | |
718 | goto err_out; | |
719 | } | |
720 | ||
721 | skip_doorbell: | |
722 | adapter->ahw.db_base = db_ptr; | |
723 | adapter->ahw.db_len = db_len; | |
724 | return 0; | |
725 | ||
726 | err_out: | |
727 | netxen_cleanup_pci_map(adapter); | |
728 | return err; | |
729 | } | |
730 | ||
ba599d4f | 731 | static int |
f7185c71 | 732 | netxen_start_firmware(struct netxen_adapter *adapter, int request_fw) |
ba599d4f DP |
733 | { |
734 | int val, err, first_boot; | |
735 | struct pci_dev *pdev = adapter->pdev; | |
736 | ||
0b72e659 | 737 | int first_driver = 0; |
f7185c71 DP |
738 | |
739 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) | |
740 | first_driver = (adapter->portnum == 0); | |
741 | else | |
742 | first_driver = (adapter->ahw.pci_func == 0); | |
0b72e659 DP |
743 | |
744 | if (!first_driver) | |
96f2ebd2 | 745 | goto wait_init; |
0b72e659 | 746 | |
f98a9f69 | 747 | first_boot = NXRD32(adapter, NETXEN_CAM_RAM(0x1fc)); |
ba599d4f DP |
748 | |
749 | err = netxen_check_hw_init(adapter, first_boot); | |
750 | if (err) { | |
751 | dev_err(&pdev->dev, "error in init HW init sequence\n"); | |
752 | return err; | |
753 | } | |
754 | ||
f7185c71 DP |
755 | if (request_fw) |
756 | netxen_request_firmware(adapter); | |
757 | ||
67c38fc6 | 758 | err = netxen_need_fw_reset(adapter); |
1dbc84a7 | 759 | if (err < 0) |
67c38fc6 | 760 | return err; |
1dbc84a7 DP |
761 | if (err == 0) |
762 | goto wait_init; | |
67c38fc6 | 763 | |
ba599d4f | 764 | if (first_boot != 0x55555555) { |
f98a9f69 | 765 | NXWR32(adapter, CRB_CMDPEG_STATE, 0); |
ba599d4f DP |
766 | netxen_pinit_from_rom(adapter, 0); |
767 | msleep(1); | |
768 | } | |
567c6c4e | 769 | |
f98a9f69 | 770 | NXWR32(adapter, CRB_DMA_SHIFT, 0x55555555); |
567c6c4e DP |
771 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) |
772 | netxen_set_port_mode(adapter); | |
773 | ||
ba599d4f DP |
774 | netxen_load_firmware(adapter); |
775 | ||
776 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) { | |
777 | ||
778 | /* Initialize multicast addr pool owners */ | |
779 | val = 0x7654; | |
1e2d0059 | 780 | if (adapter->ahw.port_type == NETXEN_NIC_XGBE) |
ba599d4f | 781 | val |= 0x0f000000; |
f98a9f69 | 782 | NXWR32(adapter, NETXEN_MAC_ADDR_CNTL_REG, val); |
ba599d4f DP |
783 | |
784 | } | |
785 | ||
83ac51fa | 786 | err = netxen_init_dummy_dma(adapter); |
ba599d4f DP |
787 | if (err) |
788 | return err; | |
789 | ||
790 | /* | |
791 | * Tell the hardware our version number. | |
792 | */ | |
793 | val = (_NETXEN_NIC_LINUX_MAJOR << 16) | |
794 | | ((_NETXEN_NIC_LINUX_MINOR << 8)) | |
795 | | (_NETXEN_NIC_LINUX_SUBVERSION); | |
f98a9f69 | 796 | NXWR32(adapter, CRB_DRIVER_VERSION, val); |
ba599d4f | 797 | |
96f2ebd2 | 798 | wait_init: |
ba599d4f DP |
799 | /* Handshake with the card before we register the devices. */ |
800 | err = netxen_phantom_init(adapter, NETXEN_NIC_PEG_TUNE); | |
801 | if (err) { | |
83ac51fa | 802 | netxen_free_dummy_dma(adapter); |
ba599d4f DP |
803 | return err; |
804 | } | |
805 | ||
68b3cae0 DP |
806 | nx_update_dma_mask(adapter); |
807 | ||
808 | netxen_nic_get_firmware_info(adapter); | |
809 | ||
ba599d4f DP |
810 | return 0; |
811 | } | |
812 | ||
9f5bc7f1 DP |
813 | static int |
814 | netxen_nic_request_irq(struct netxen_adapter *adapter) | |
815 | { | |
816 | irq_handler_t handler; | |
d8b100c5 DP |
817 | struct nx_host_sds_ring *sds_ring; |
818 | int err, ring; | |
819 | ||
9f5bc7f1 DP |
820 | unsigned long flags = IRQF_SAMPLE_RANDOM; |
821 | struct net_device *netdev = adapter->netdev; | |
d8b100c5 | 822 | struct netxen_recv_context *recv_ctx = &adapter->recv_ctx; |
9f5bc7f1 | 823 | |
9f5bc7f1 DP |
824 | if (adapter->flags & NETXEN_NIC_MSIX_ENABLED) |
825 | handler = netxen_msix_intr; | |
826 | else if (adapter->flags & NETXEN_NIC_MSI_ENABLED) | |
827 | handler = netxen_msi_intr; | |
828 | else { | |
829 | flags |= IRQF_SHARED; | |
830 | handler = netxen_intr; | |
831 | } | |
832 | adapter->irq = netdev->irq; | |
833 | ||
d8b100c5 DP |
834 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { |
835 | sds_ring = &recv_ctx->sds_rings[ring]; | |
be339aee | 836 | sprintf(sds_ring->name, "%s[%d]", netdev->name, ring); |
d8b100c5 DP |
837 | err = request_irq(sds_ring->irq, handler, |
838 | flags, sds_ring->name, sds_ring); | |
839 | if (err) | |
840 | return err; | |
841 | } | |
842 | ||
843 | return 0; | |
844 | } | |
845 | ||
846 | static void | |
847 | netxen_nic_free_irq(struct netxen_adapter *adapter) | |
848 | { | |
849 | int ring; | |
850 | struct nx_host_sds_ring *sds_ring; | |
851 | ||
852 | struct netxen_recv_context *recv_ctx = &adapter->recv_ctx; | |
853 | ||
854 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { | |
855 | sds_ring = &recv_ctx->sds_rings[ring]; | |
856 | free_irq(sds_ring->irq, sds_ring); | |
857 | } | |
9f5bc7f1 DP |
858 | } |
859 | ||
ca2ef330 DP |
860 | static void |
861 | netxen_nic_init_coalesce_defaults(struct netxen_adapter *adapter) | |
862 | { | |
863 | adapter->coal.flags = NETXEN_NIC_INTR_DEFAULT; | |
864 | adapter->coal.normal.data.rx_time_us = | |
865 | NETXEN_DEFAULT_INTR_COALESCE_RX_TIME_US; | |
866 | adapter->coal.normal.data.rx_packets = | |
867 | NETXEN_DEFAULT_INTR_COALESCE_RX_PACKETS; | |
868 | adapter->coal.normal.data.tx_time_us = | |
869 | NETXEN_DEFAULT_INTR_COALESCE_TX_TIME_US; | |
870 | adapter->coal.normal.data.tx_packets = | |
871 | NETXEN_DEFAULT_INTR_COALESCE_TX_PACKETS; | |
872 | } | |
873 | ||
9f5bc7f1 DP |
874 | static int |
875 | netxen_nic_up(struct netxen_adapter *adapter, struct net_device *netdev) | |
876 | { | |
877 | int err; | |
878 | ||
879 | err = adapter->init_port(adapter, adapter->physical_port); | |
880 | if (err) { | |
881 | printk(KERN_ERR "%s: Failed to initialize port %d\n", | |
882 | netxen_nic_driver_name, adapter->portnum); | |
883 | return err; | |
884 | } | |
3d0a3cc9 DP |
885 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) |
886 | adapter->macaddr_set(adapter, netdev->dev_addr); | |
9f5bc7f1 | 887 | |
3d0a3cc9 DP |
888 | adapter->set_multi(netdev); |
889 | adapter->set_mtu(adapter, netdev->mtu); | |
9f5bc7f1 DP |
890 | |
891 | adapter->ahw.linkup = 0; | |
9f5bc7f1 | 892 | |
d8b100c5 DP |
893 | if (adapter->max_sds_rings > 1) |
894 | netxen_config_rss(adapter, 1); | |
9f5bc7f1 | 895 | |
ca2ef330 DP |
896 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) |
897 | netxen_config_intr_coalesce(adapter); | |
898 | ||
1bb482f8 NK |
899 | if (adapter->capabilities & NX_FW_CAPABILITY_HW_LRO) |
900 | netxen_config_hw_lro(adapter, NETXEN_NIC_LRO_ENABLED); | |
901 | ||
b2af9cb0 DP |
902 | netxen_napi_enable(adapter); |
903 | ||
5103c9f7 | 904 | if (adapter->capabilities & NX_FW_CAPABILITY_LINK_NOTIFICATION) |
3bf26ce3 | 905 | netxen_linkevent_request(adapter, 1); |
3d0a3cc9 DP |
906 | else |
907 | netxen_nic_set_link_parameters(adapter); | |
908 | ||
909 | mod_timer(&adapter->watchdog_timer, jiffies); | |
3bf26ce3 | 910 | |
9f5bc7f1 DP |
911 | return 0; |
912 | } | |
913 | ||
914 | static void | |
915 | netxen_nic_down(struct netxen_adapter *adapter, struct net_device *netdev) | |
916 | { | |
b2af9cb0 | 917 | spin_lock(&adapter->tx_clean_lock); |
9f5bc7f1 | 918 | netif_carrier_off(netdev); |
b2af9cb0 | 919 | netif_tx_disable(netdev); |
9f5bc7f1 DP |
920 | |
921 | if (adapter->stop_port) | |
922 | adapter->stop_port(adapter); | |
923 | ||
5cf4d323 DP |
924 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) |
925 | netxen_p3_free_mac_list(adapter); | |
926 | ||
22b5794b AKS |
927 | adapter->set_promisc(adapter, NETXEN_NIU_NON_PROMISC_MODE); |
928 | ||
be339aee DP |
929 | netxen_napi_disable(adapter); |
930 | ||
9f5bc7f1 | 931 | netxen_release_tx_buffers(adapter); |
b2af9cb0 | 932 | spin_unlock(&adapter->tx_clean_lock); |
9f5bc7f1 | 933 | |
9f5bc7f1 DP |
934 | del_timer_sync(&adapter->watchdog_timer); |
935 | } | |
936 | ||
937 | ||
938 | static int | |
939 | netxen_nic_attach(struct netxen_adapter *adapter) | |
940 | { | |
941 | struct net_device *netdev = adapter->netdev; | |
942 | struct pci_dev *pdev = adapter->pdev; | |
becf46a0 | 943 | int err, ring; |
d8b100c5 | 944 | struct nx_host_rds_ring *rds_ring; |
d877f1e3 | 945 | struct nx_host_tx_ring *tx_ring; |
9f5bc7f1 | 946 | |
7042cd8f AKS |
947 | if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC) |
948 | return 0; | |
949 | ||
9f5bc7f1 | 950 | err = netxen_init_firmware(adapter); |
232e7d68 DP |
951 | if (err) |
952 | return err; | |
953 | ||
954 | err = netxen_napi_add(adapter, netdev); | |
955 | if (err) | |
956 | return err; | |
9f5bc7f1 | 957 | |
9f5bc7f1 DP |
958 | err = netxen_alloc_sw_resources(adapter); |
959 | if (err) { | |
960 | printk(KERN_ERR "%s: Error in setting sw resources\n", | |
961 | netdev->name); | |
962 | return err; | |
963 | } | |
964 | ||
965 | netxen_nic_clear_stats(adapter); | |
966 | ||
967 | err = netxen_alloc_hw_resources(adapter); | |
968 | if (err) { | |
969 | printk(KERN_ERR "%s: Error in setting hw resources\n", | |
970 | netdev->name); | |
971 | goto err_out_free_sw; | |
972 | } | |
973 | ||
4f96b988 | 974 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) { |
4ea528a1 | 975 | tx_ring = adapter->tx_ring; |
d877f1e3 DP |
976 | tx_ring->crb_cmd_producer = crb_cmd_producer[adapter->portnum]; |
977 | tx_ring->crb_cmd_consumer = crb_cmd_consumer[adapter->portnum]; | |
9f5bc7f1 | 978 | |
cb2107be DP |
979 | tx_ring->producer = 0; |
980 | tx_ring->sw_consumer = 0; | |
981 | ||
982 | netxen_nic_update_cmd_producer(adapter, tx_ring); | |
983 | netxen_nic_update_cmd_consumer(adapter, tx_ring); | |
9f5bc7f1 DP |
984 | } |
985 | ||
d8b100c5 DP |
986 | for (ring = 0; ring < adapter->max_rds_rings; ring++) { |
987 | rds_ring = &adapter->recv_ctx.rds_rings[ring]; | |
988 | netxen_post_rx_buffers(adapter, ring, rds_ring); | |
989 | } | |
9f5bc7f1 DP |
990 | |
991 | err = netxen_nic_request_irq(adapter); | |
992 | if (err) { | |
993 | dev_err(&pdev->dev, "%s: failed to setup interrupt\n", | |
994 | netdev->name); | |
995 | goto err_out_free_rxbuf; | |
996 | } | |
997 | ||
ca2ef330 DP |
998 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) |
999 | netxen_nic_init_coalesce_defaults(adapter); | |
1000 | ||
fa3ce355 NK |
1001 | netxen_create_sysfs_entries(adapter); |
1002 | ||
9f5bc7f1 DP |
1003 | adapter->is_up = NETXEN_ADAPTER_UP_MAGIC; |
1004 | return 0; | |
1005 | ||
1006 | err_out_free_rxbuf: | |
1007 | netxen_release_rx_buffers(adapter); | |
1008 | netxen_free_hw_resources(adapter); | |
1009 | err_out_free_sw: | |
1010 | netxen_free_sw_resources(adapter); | |
1011 | return err; | |
1012 | } | |
1013 | ||
1014 | static void | |
1015 | netxen_nic_detach(struct netxen_adapter *adapter) | |
1016 | { | |
7042cd8f AKS |
1017 | if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC) |
1018 | return; | |
1019 | ||
fa3ce355 NK |
1020 | netxen_remove_sysfs_entries(adapter); |
1021 | ||
9f5bc7f1 | 1022 | netxen_free_hw_resources(adapter); |
cf981ffb | 1023 | netxen_release_rx_buffers(adapter); |
be339aee | 1024 | netxen_nic_free_irq(adapter); |
232e7d68 | 1025 | netxen_napi_del(adapter); |
9f5bc7f1 DP |
1026 | netxen_free_sw_resources(adapter); |
1027 | ||
1028 | adapter->is_up = 0; | |
1029 | } | |
1030 | ||
7042cd8f AKS |
1031 | int |
1032 | netxen_nic_reset_context(struct netxen_adapter *adapter) | |
1033 | { | |
1034 | int err = 0; | |
1035 | struct net_device *netdev = adapter->netdev; | |
1036 | ||
1037 | if (adapter->is_up == NETXEN_ADAPTER_UP_MAGIC) { | |
1038 | ||
1039 | if (netif_running(netdev)) | |
1040 | netxen_nic_down(adapter, netdev); | |
1041 | ||
1042 | netxen_nic_detach(adapter); | |
1043 | ||
1044 | err = netxen_nic_attach(adapter); | |
1045 | if (err) | |
1046 | goto done; | |
1047 | ||
1048 | if (netif_running(netdev)) | |
1049 | err = netxen_nic_up(adapter, netdev); | |
1050 | } | |
1051 | done: | |
1052 | return err; | |
1053 | } | |
1054 | ||
f17443f4 DP |
1055 | static int |
1056 | netxen_setup_netdev(struct netxen_adapter *adapter, | |
1057 | struct net_device *netdev) | |
1058 | { | |
1059 | int err = 0; | |
1060 | struct pci_dev *pdev = adapter->pdev; | |
1061 | ||
1062 | adapter->rx_csum = 1; | |
1063 | adapter->mc_enabled = 0; | |
1064 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) | |
1065 | adapter->max_mc_count = 38; | |
1066 | else | |
1067 | adapter->max_mc_count = 16; | |
1068 | ||
1069 | netdev->netdev_ops = &netxen_netdev_ops; | |
1070 | netdev->watchdog_timeo = 2*HZ; | |
1071 | ||
1072 | netxen_nic_change_mtu(netdev, netdev->mtu); | |
1073 | ||
1074 | SET_ETHTOOL_OPS(netdev, &netxen_nic_ethtool_ops); | |
1075 | ||
1076 | netdev->features |= (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO); | |
1077 | netdev->features |= (NETIF_F_GRO); | |
1078 | netdev->vlan_features |= (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO); | |
1079 | ||
1080 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) { | |
1081 | netdev->features |= (NETIF_F_IPV6_CSUM | NETIF_F_TSO6); | |
1082 | netdev->vlan_features |= (NETIF_F_IPV6_CSUM | NETIF_F_TSO6); | |
1083 | } | |
1084 | ||
1085 | if (adapter->pci_using_dac) { | |
1086 | netdev->features |= NETIF_F_HIGHDMA; | |
1087 | netdev->vlan_features |= NETIF_F_HIGHDMA; | |
1088 | } | |
1089 | ||
028afe71 DP |
1090 | if (adapter->capabilities & NX_FW_CAPABILITY_FVLANTX) |
1091 | netdev->features |= (NETIF_F_HW_VLAN_TX); | |
1092 | ||
1bb482f8 NK |
1093 | if (adapter->capabilities & NX_FW_CAPABILITY_HW_LRO) |
1094 | netdev->features |= NETIF_F_LRO; | |
1095 | ||
f17443f4 DP |
1096 | netdev->irq = adapter->msix_entries[0].vector; |
1097 | ||
1098 | err = netxen_napi_add(adapter, netdev); | |
1099 | if (err) | |
1100 | return err; | |
1101 | ||
1102 | init_timer(&adapter->watchdog_timer); | |
1103 | adapter->watchdog_timer.function = &netxen_watchdog; | |
1104 | adapter->watchdog_timer.data = (unsigned long)adapter; | |
1105 | INIT_WORK(&adapter->watchdog_task, netxen_watchdog_task); | |
1106 | INIT_WORK(&adapter->tx_timeout_task, netxen_reset_task); | |
1107 | ||
1108 | if (netxen_read_mac_addr(adapter)) | |
1109 | dev_warn(&pdev->dev, "failed to read mac addr\n"); | |
1110 | ||
1111 | netif_carrier_off(netdev); | |
1112 | netif_stop_queue(netdev); | |
1113 | ||
1114 | err = register_netdev(netdev); | |
1115 | if (err) { | |
1116 | dev_err(&pdev->dev, "failed to register net device\n"); | |
1117 | return err; | |
1118 | } | |
1119 | ||
1120 | return 0; | |
1121 | } | |
1122 | ||
3d396eb1 AK |
1123 | static int __devinit |
1124 | netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) | |
1125 | { | |
1126 | struct net_device *netdev = NULL; | |
1127 | struct netxen_adapter *adapter = NULL; | |
2956640d | 1128 | int i = 0, err; |
3176ff3e | 1129 | int pci_func_id = PCI_FUNC(pdev->devfn); |
2956640d | 1130 | uint8_t revision_id; |
3d396eb1 | 1131 | |
3176ff3e | 1132 | if (pdev->class != 0x020000) { |
dcd56fdb | 1133 | printk(KERN_DEBUG "NetXen function %d, class %x will not " |
3176ff3e | 1134 | "be enabled.\n",pci_func_id, pdev->class); |
ed25ffa1 AK |
1135 | return -ENODEV; |
1136 | } | |
2956640d | 1137 | |
11d89d63 DP |
1138 | if (pdev->revision >= NX_P3_A0 && pdev->revision < NX_P3_B1) { |
1139 | printk(KERN_WARNING "NetXen chip revisions between 0x%x-0x%x" | |
1140 | "will not be enabled.\n", | |
1141 | NX_P3_A0, NX_P3_B1); | |
1142 | return -ENODEV; | |
1143 | } | |
1144 | ||
3d396eb1 AK |
1145 | if ((err = pci_enable_device(pdev))) |
1146 | return err; | |
2956640d | 1147 | |
3d396eb1 AK |
1148 | if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) { |
1149 | err = -ENODEV; | |
1150 | goto err_out_disable_pdev; | |
1151 | } | |
1152 | ||
1153 | if ((err = pci_request_regions(pdev, netxen_nic_driver_name))) | |
1154 | goto err_out_disable_pdev; | |
1155 | ||
1156 | pci_set_master(pdev); | |
3176ff3e MT |
1157 | |
1158 | netdev = alloc_etherdev(sizeof(struct netxen_adapter)); | |
1159 | if(!netdev) { | |
f17443f4 DP |
1160 | dev_err(&pdev->dev, "failed to allocate net_device\n"); |
1161 | err = -ENOMEM; | |
3176ff3e MT |
1162 | goto err_out_free_res; |
1163 | } | |
1164 | ||
3176ff3e MT |
1165 | SET_NETDEV_DEV(netdev, &pdev->dev); |
1166 | ||
4cf1653a | 1167 | adapter = netdev_priv(netdev); |
2956640d DP |
1168 | adapter->netdev = netdev; |
1169 | adapter->pdev = pdev; | |
13ba9c77 | 1170 | adapter->ahw.pci_func = pci_func_id; |
2956640d DP |
1171 | |
1172 | revision_id = pdev->revision; | |
1173 | adapter->ahw.revision_id = revision_id; | |
1174 | ||
50c643e7 | 1175 | err = nx_set_dma_mask(adapter); |
2956640d DP |
1176 | if (err) |
1177 | goto err_out_free_netdev; | |
1178 | ||
3ce06a32 | 1179 | rwlock_init(&adapter->adapter_lock); |
d8b100c5 | 1180 | spin_lock_init(&adapter->tx_clean_lock); |
5cf4d323 | 1181 | INIT_LIST_HEAD(&adapter->mac_list); |
3ce06a32 | 1182 | |
97daee83 DP |
1183 | err = netxen_setup_pci_map(adapter); |
1184 | if (err) | |
6c80b18d | 1185 | goto err_out_free_netdev; |
3d396eb1 | 1186 | |
2d1a3bbd | 1187 | /* This will be reset for mezz cards */ |
3176ff3e | 1188 | adapter->portnum = pci_func_id; |
3176ff3e | 1189 | |
f17443f4 DP |
1190 | err = netxen_nic_get_board_info(adapter); |
1191 | if (err) { | |
1192 | dev_err(&pdev->dev, "Error getting board config info.\n"); | |
dcd56fdb DP |
1193 | goto err_out_iounmap; |
1194 | } | |
6c80b18d | 1195 | |
6c80b18d MT |
1196 | netxen_initialize_adapter_ops(adapter); |
1197 | ||
13ba9c77 | 1198 | /* Mezz cards have PCI function 0,2,3 enabled */ |
1e2d0059 | 1199 | switch (adapter->ahw.board_type) { |
dc515f2e DP |
1200 | case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ: |
1201 | case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ: | |
1202 | if (pci_func_id >= 2) | |
13ba9c77 | 1203 | adapter->portnum = pci_func_id - 2; |
dc515f2e DP |
1204 | break; |
1205 | default: | |
1206 | break; | |
1207 | } | |
13ba9c77 | 1208 | |
f7185c71 | 1209 | err = netxen_start_firmware(adapter, 1); |
0b72e659 DP |
1210 | if (err) |
1211 | goto err_out_iounmap; | |
f17443f4 | 1212 | |
3d396eb1 | 1213 | /* |
6c80b18d | 1214 | * See if the firmware gave us a virtual-physical port mapping. |
3d396eb1 | 1215 | */ |
dcd56fdb | 1216 | adapter->physical_port = adapter->portnum; |
4f96b988 | 1217 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) { |
f98a9f69 | 1218 | i = NXRD32(adapter, CRB_V2P(adapter->portnum)); |
044fad0d DP |
1219 | if (i != 0x55555555) |
1220 | adapter->physical_port = i; | |
1221 | } | |
6c80b18d | 1222 | |
438627c7 | 1223 | netxen_check_options(adapter); |
2956640d | 1224 | |
97daee83 | 1225 | netxen_setup_intr(adapter); |
2956640d | 1226 | |
f17443f4 | 1227 | err = netxen_setup_netdev(adapter, netdev); |
9dc28efe | 1228 | if (err) |
2956640d | 1229 | goto err_out_disable_msi; |
6c80b18d MT |
1230 | |
1231 | pci_set_drvdata(pdev, adapter); | |
3d396eb1 | 1232 | |
1e2d0059 | 1233 | switch (adapter->ahw.port_type) { |
2956640d DP |
1234 | case NETXEN_NIC_GBE: |
1235 | dev_info(&adapter->pdev->dev, "%s: GbE port initialized\n", | |
1236 | adapter->netdev->name); | |
1237 | break; | |
1238 | case NETXEN_NIC_XGBE: | |
1239 | dev_info(&adapter->pdev->dev, "%s: XGbE port initialized\n", | |
1240 | adapter->netdev->name); | |
1241 | break; | |
3d396eb1 | 1242 | } |
3d396eb1 | 1243 | |
2956640d DP |
1244 | return 0; |
1245 | ||
1246 | err_out_disable_msi: | |
97daee83 | 1247 | netxen_teardown_intr(adapter); |
6c80b18d | 1248 | |
83ac51fa | 1249 | netxen_free_dummy_dma(adapter); |
3d396eb1 | 1250 | |
2956640d | 1251 | err_out_iounmap: |
97daee83 | 1252 | netxen_cleanup_pci_map(adapter); |
cb8011ad | 1253 | |
6c80b18d MT |
1254 | err_out_free_netdev: |
1255 | free_netdev(netdev); | |
1256 | ||
1257 | err_out_free_res: | |
3d396eb1 | 1258 | pci_release_regions(pdev); |
6c80b18d MT |
1259 | |
1260 | err_out_disable_pdev: | |
2956640d | 1261 | pci_set_drvdata(pdev, NULL); |
3d396eb1 AK |
1262 | pci_disable_device(pdev); |
1263 | return err; | |
1264 | } | |
1265 | ||
1266 | static void __devexit netxen_nic_remove(struct pci_dev *pdev) | |
1267 | { | |
1268 | struct netxen_adapter *adapter; | |
3176ff3e | 1269 | struct net_device *netdev; |
3d396eb1 | 1270 | |
6c80b18d | 1271 | adapter = pci_get_drvdata(pdev); |
3d396eb1 AK |
1272 | if (adapter == NULL) |
1273 | return; | |
1274 | ||
6c80b18d MT |
1275 | netdev = adapter->netdev; |
1276 | ||
96acb6eb DP |
1277 | unregister_netdev(netdev); |
1278 | ||
e424fa9d AKS |
1279 | cancel_work_sync(&adapter->watchdog_task); |
1280 | cancel_work_sync(&adapter->tx_timeout_task); | |
1281 | ||
7042cd8f | 1282 | netxen_nic_detach(adapter); |
3d396eb1 | 1283 | |
439b454e | 1284 | if (adapter->portnum == 0) |
83ac51fa | 1285 | netxen_free_dummy_dma(adapter); |
96acb6eb | 1286 | |
97daee83 | 1287 | netxen_teardown_intr(adapter); |
3052246c | 1288 | |
97daee83 | 1289 | netxen_cleanup_pci_map(adapter); |
595e3fb8 | 1290 | |
f7185c71 DP |
1291 | netxen_release_firmware(adapter); |
1292 | ||
595e3fb8 | 1293 | pci_release_regions(pdev); |
3052246c | 1294 | pci_disable_device(pdev); |
595e3fb8 MT |
1295 | pci_set_drvdata(pdev, NULL); |
1296 | ||
6c80b18d | 1297 | free_netdev(netdev); |
3d396eb1 | 1298 | } |
22b5794b | 1299 | static int __netxen_nic_shutdown(struct pci_dev *pdev) |
0b72e659 | 1300 | { |
0b72e659 DP |
1301 | struct netxen_adapter *adapter = pci_get_drvdata(pdev); |
1302 | struct net_device *netdev = adapter->netdev; | |
22b5794b | 1303 | int retval; |
0b72e659 DP |
1304 | |
1305 | netif_device_detach(netdev); | |
1306 | ||
1307 | if (netif_running(netdev)) | |
1308 | netxen_nic_down(adapter, netdev); | |
1309 | ||
e424fa9d AKS |
1310 | cancel_work_sync(&adapter->watchdog_task); |
1311 | cancel_work_sync(&adapter->tx_timeout_task); | |
1312 | ||
7042cd8f | 1313 | netxen_nic_detach(adapter); |
0b72e659 | 1314 | |
22b5794b AKS |
1315 | if (adapter->portnum == 0) |
1316 | netxen_free_dummy_dma(adapter); | |
1317 | ||
1318 | retval = pci_save_state(pdev); | |
1319 | if (retval) | |
1320 | return retval; | |
0b72e659 DP |
1321 | |
1322 | if (netxen_nic_wol_supported(adapter)) { | |
1323 | pci_enable_wake(pdev, PCI_D3cold, 1); | |
1324 | pci_enable_wake(pdev, PCI_D3hot, 1); | |
1325 | } | |
1326 | ||
1327 | pci_disable_device(pdev); | |
0b72e659 DP |
1328 | |
1329 | return 0; | |
1330 | } | |
22b5794b AKS |
1331 | static void netxen_nic_shutdown(struct pci_dev *pdev) |
1332 | { | |
1333 | if (__netxen_nic_shutdown(pdev)) | |
1334 | return; | |
1335 | } | |
1336 | #ifdef CONFIG_PM | |
1337 | static int | |
1338 | netxen_nic_suspend(struct pci_dev *pdev, pm_message_t state) | |
1339 | { | |
1340 | int retval; | |
1341 | ||
1342 | retval = __netxen_nic_shutdown(pdev); | |
1343 | if (retval) | |
1344 | return retval; | |
1345 | ||
1346 | pci_set_power_state(pdev, pci_choose_state(pdev, state)); | |
1347 | return 0; | |
1348 | } | |
0b72e659 DP |
1349 | |
1350 | static int | |
1351 | netxen_nic_resume(struct pci_dev *pdev) | |
1352 | { | |
1353 | struct netxen_adapter *adapter = pci_get_drvdata(pdev); | |
1354 | struct net_device *netdev = adapter->netdev; | |
1355 | int err; | |
1356 | ||
1357 | pci_set_power_state(pdev, PCI_D0); | |
1358 | pci_restore_state(pdev); | |
1359 | ||
1360 | err = pci_enable_device(pdev); | |
1361 | if (err) | |
1362 | return err; | |
1363 | ||
1364 | adapter->curr_window = 255; | |
1365 | ||
f7185c71 | 1366 | err = netxen_start_firmware(adapter, 0); |
0b72e659 DP |
1367 | if (err) { |
1368 | dev_err(&pdev->dev, "failed to start firmware\n"); | |
1369 | return err; | |
1370 | } | |
1371 | ||
1372 | if (netif_running(netdev)) { | |
1373 | err = netxen_nic_attach(adapter); | |
1374 | if (err) | |
1375 | return err; | |
1376 | ||
1377 | err = netxen_nic_up(adapter, netdev); | |
1378 | if (err) | |
1379 | return err; | |
1380 | ||
1381 | netif_device_attach(netdev); | |
1382 | } | |
1383 | ||
1384 | return 0; | |
1385 | } | |
01542cd1 | 1386 | #endif |
0b72e659 | 1387 | |
3d396eb1 AK |
1388 | static int netxen_nic_open(struct net_device *netdev) |
1389 | { | |
4cf1653a | 1390 | struct netxen_adapter *adapter = netdev_priv(netdev); |
3d396eb1 | 1391 | int err = 0; |
3d396eb1 | 1392 | |
dcd56fdb DP |
1393 | if (adapter->driver_mismatch) |
1394 | return -EIO; | |
1395 | ||
7042cd8f AKS |
1396 | err = netxen_nic_attach(adapter); |
1397 | if (err) | |
1398 | return err; | |
2956640d | 1399 | |
9f5bc7f1 DP |
1400 | err = netxen_nic_up(adapter, netdev); |
1401 | if (err) | |
1402 | goto err_out; | |
05aaa02d | 1403 | |
dcd56fdb | 1404 | netif_start_queue(netdev); |
3d396eb1 AK |
1405 | |
1406 | return 0; | |
2956640d | 1407 | |
9f5bc7f1 DP |
1408 | err_out: |
1409 | netxen_nic_detach(adapter); | |
2956640d | 1410 | return err; |
3d396eb1 AK |
1411 | } |
1412 | ||
1413 | /* | |
1414 | * netxen_nic_close - Disables a network interface entry point | |
1415 | */ | |
1416 | static int netxen_nic_close(struct net_device *netdev) | |
1417 | { | |
3176ff3e | 1418 | struct netxen_adapter *adapter = netdev_priv(netdev); |
3d396eb1 | 1419 | |
9f5bc7f1 | 1420 | netxen_nic_down(adapter, netdev); |
3d396eb1 AK |
1421 | return 0; |
1422 | } | |
1423 | ||
1bcfd790 DP |
1424 | static void |
1425 | netxen_tso_check(struct net_device *netdev, | |
1426 | struct nx_host_tx_ring *tx_ring, | |
1427 | struct cmd_desc_type0 *first_desc, | |
1428 | struct sk_buff *skb) | |
cd1f8160 | 1429 | { |
391587c3 | 1430 | u8 opcode = TX_ETHER_PKT; |
cdff1036 | 1431 | __be16 protocol = skb->protocol; |
028afe71 | 1432 | u16 flags = 0, vid = 0; |
1bcfd790 | 1433 | u32 producer; |
028afe71 | 1434 | int copied, offset, copy_len, hdr_len = 0, tso = 0, vlan_oob = 0; |
1bcfd790 | 1435 | struct cmd_desc_type0 *hwdesc; |
028afe71 | 1436 | struct vlan_ethhdr *vh; |
cdff1036 | 1437 | |
09640e63 | 1438 | if (protocol == cpu_to_be16(ETH_P_8021Q)) { |
028afe71 DP |
1439 | |
1440 | vh = (struct vlan_ethhdr *)skb->data; | |
cdff1036 DP |
1441 | protocol = vh->h_vlan_encapsulated_proto; |
1442 | flags = FLAGS_VLAN_TAGGED; | |
028afe71 DP |
1443 | |
1444 | } else if (vlan_tx_tag_present(skb)) { | |
1445 | ||
1446 | flags = FLAGS_VLAN_OOB; | |
1447 | vid = vlan_tx_tag_get(skb); | |
1448 | netxen_set_tx_vlan_tci(first_desc, vid); | |
1449 | vlan_oob = 1; | |
cdff1036 | 1450 | } |
cd1f8160 | 1451 | |
391587c3 DP |
1452 | if ((netdev->features & (NETIF_F_TSO | NETIF_F_TSO6)) && |
1453 | skb_shinfo(skb)->gso_size > 0) { | |
1454 | ||
1bcfd790 DP |
1455 | hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); |
1456 | ||
1457 | first_desc->mss = cpu_to_le16(skb_shinfo(skb)->gso_size); | |
1458 | first_desc->total_hdr_length = hdr_len; | |
028afe71 DP |
1459 | if (vlan_oob) { |
1460 | first_desc->total_hdr_length += VLAN_HLEN; | |
1461 | first_desc->tcp_hdr_offset = VLAN_HLEN; | |
1462 | first_desc->ip_hdr_offset = VLAN_HLEN; | |
1463 | /* Only in case of TSO on vlan device */ | |
1464 | flags |= FLAGS_VLAN_TAGGED; | |
1465 | } | |
391587c3 | 1466 | |
09640e63 | 1467 | opcode = (protocol == cpu_to_be16(ETH_P_IPV6)) ? |
391587c3 | 1468 | TX_TCP_LSO6 : TX_TCP_LSO; |
1bcfd790 | 1469 | tso = 1; |
cd1f8160 DP |
1470 | |
1471 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { | |
391587c3 DP |
1472 | u8 l4proto; |
1473 | ||
09640e63 | 1474 | if (protocol == cpu_to_be16(ETH_P_IP)) { |
391587c3 DP |
1475 | l4proto = ip_hdr(skb)->protocol; |
1476 | ||
1477 | if (l4proto == IPPROTO_TCP) | |
1478 | opcode = TX_TCP_PKT; | |
1479 | else if(l4proto == IPPROTO_UDP) | |
1480 | opcode = TX_UDP_PKT; | |
09640e63 | 1481 | } else if (protocol == cpu_to_be16(ETH_P_IPV6)) { |
391587c3 DP |
1482 | l4proto = ipv6_hdr(skb)->nexthdr; |
1483 | ||
1484 | if (l4proto == IPPROTO_TCP) | |
1485 | opcode = TX_TCPV6_PKT; | |
1486 | else if(l4proto == IPPROTO_UDP) | |
1487 | opcode = TX_UDPV6_PKT; | |
1488 | } | |
cd1f8160 | 1489 | } |
028afe71 DP |
1490 | |
1491 | first_desc->tcp_hdr_offset += skb_transport_offset(skb); | |
1492 | first_desc->ip_hdr_offset += skb_network_offset(skb); | |
1bcfd790 DP |
1493 | netxen_set_tx_flags_opcode(first_desc, flags, opcode); |
1494 | ||
1495 | if (!tso) | |
1496 | return; | |
1497 | ||
1498 | /* For LSO, we need to copy the MAC/IP/TCP headers into | |
1499 | * the descriptor ring | |
1500 | */ | |
1501 | producer = tx_ring->producer; | |
1502 | copied = 0; | |
1503 | offset = 2; | |
1504 | ||
028afe71 DP |
1505 | if (vlan_oob) { |
1506 | /* Create a TSO vlan header template for firmware */ | |
1507 | ||
1508 | hwdesc = &tx_ring->desc_head[producer]; | |
1509 | tx_ring->cmd_buf_arr[producer].skb = NULL; | |
1510 | ||
1511 | copy_len = min((int)sizeof(struct cmd_desc_type0) - offset, | |
1512 | hdr_len + VLAN_HLEN); | |
1513 | ||
1514 | vh = (struct vlan_ethhdr *)((char *)hwdesc + 2); | |
1515 | skb_copy_from_linear_data(skb, vh, 12); | |
1516 | vh->h_vlan_proto = htons(ETH_P_8021Q); | |
1517 | vh->h_vlan_TCI = htons(vid); | |
1518 | skb_copy_from_linear_data_offset(skb, 12, | |
1519 | (char *)vh + 16, copy_len - 16); | |
1520 | ||
545eb370 | 1521 | copied = copy_len - VLAN_HLEN; |
028afe71 DP |
1522 | offset = 0; |
1523 | ||
1524 | producer = get_next_index(producer, tx_ring->num_desc); | |
1525 | } | |
1526 | ||
1bcfd790 DP |
1527 | while (copied < hdr_len) { |
1528 | ||
1529 | copy_len = min((int)sizeof(struct cmd_desc_type0) - offset, | |
1530 | (hdr_len - copied)); | |
1531 | ||
1532 | hwdesc = &tx_ring->desc_head[producer]; | |
1533 | tx_ring->cmd_buf_arr[producer].skb = NULL; | |
1534 | ||
1535 | skb_copy_from_linear_data_offset(skb, copied, | |
1536 | (char *)hwdesc + offset, copy_len); | |
1537 | ||
1538 | copied += copy_len; | |
1539 | offset = 0; | |
1540 | ||
1541 | producer = get_next_index(producer, tx_ring->num_desc); | |
1542 | } | |
1543 | ||
1544 | tx_ring->producer = producer; | |
1545 | barrier(); | |
cd1f8160 DP |
1546 | } |
1547 | ||
ce644ed4 DP |
1548 | static int |
1549 | netxen_map_tx_skb(struct pci_dev *pdev, | |
1550 | struct sk_buff *skb, struct netxen_cmd_buffer *pbuf) | |
6f703406 | 1551 | { |
ce644ed4 DP |
1552 | struct netxen_skb_frag *nf; |
1553 | struct skb_frag_struct *frag; | |
1554 | int i, nr_frags; | |
1555 | dma_addr_t map; | |
1556 | ||
1557 | nr_frags = skb_shinfo(skb)->nr_frags; | |
1558 | nf = &pbuf->frag_array[0]; | |
1559 | ||
1560 | map = pci_map_single(pdev, skb->data, | |
1561 | skb_headlen(skb), PCI_DMA_TODEVICE); | |
1562 | if (pci_dma_mapping_error(pdev, map)) | |
1563 | goto out_err; | |
6f703406 | 1564 | |
ce644ed4 DP |
1565 | nf->dma = map; |
1566 | nf->length = skb_headlen(skb); | |
1567 | ||
1568 | for (i = 0; i < nr_frags; i++) { | |
1569 | frag = &skb_shinfo(skb)->frags[i]; | |
1570 | nf = &pbuf->frag_array[i+1]; | |
1571 | ||
1572 | map = pci_map_page(pdev, frag->page, frag->page_offset, | |
1573 | frag->size, PCI_DMA_TODEVICE); | |
1574 | if (pci_dma_mapping_error(pdev, map)) | |
1575 | goto unwind; | |
1576 | ||
1577 | nf->dma = map; | |
1578 | nf->length = frag->size; | |
1579 | } | |
1580 | ||
1581 | return 0; | |
6f703406 | 1582 | |
ce644ed4 DP |
1583 | unwind: |
1584 | while (i > 0) { | |
1585 | nf = &pbuf->frag_array[i]; | |
1586 | pci_unmap_page(pdev, nf->dma, nf->length, PCI_DMA_TODEVICE); | |
6f703406 | 1587 | } |
ce644ed4 DP |
1588 | |
1589 | nf = &pbuf->frag_array[0]; | |
1590 | pci_unmap_single(pdev, nf->dma, skb_headlen(skb), PCI_DMA_TODEVICE); | |
1591 | ||
1592 | out_err: | |
1593 | return -ENOMEM; | |
6f703406 DP |
1594 | } |
1595 | ||
d32cc3d2 DP |
1596 | static inline void |
1597 | netxen_clear_cmddesc(u64 *desc) | |
1598 | { | |
1bcfd790 DP |
1599 | desc[0] = 0ULL; |
1600 | desc[2] = 0ULL; | |
d32cc3d2 DP |
1601 | } |
1602 | ||
61357325 | 1603 | static netdev_tx_t |
d32cc3d2 | 1604 | netxen_nic_xmit_frame(struct sk_buff *skb, struct net_device *netdev) |
3d396eb1 | 1605 | { |
3176ff3e | 1606 | struct netxen_adapter *adapter = netdev_priv(netdev); |
4ea528a1 | 1607 | struct nx_host_tx_ring *tx_ring = adapter->tx_ring; |
391587c3 | 1608 | struct netxen_cmd_buffer *pbuf; |
3d396eb1 | 1609 | struct netxen_skb_frag *buffrag; |
1bcfd790 DP |
1610 | struct cmd_desc_type0 *hwdesc, *first_desc; |
1611 | struct pci_dev *pdev; | |
391587c3 | 1612 | int i, k; |
3d396eb1 | 1613 | |
cb2107be | 1614 | u32 producer; |
ce644ed4 | 1615 | int frag_count, no_of_desc; |
d877f1e3 | 1616 | u32 num_txd = tx_ring->num_desc; |
3d396eb1 | 1617 | |
3d396eb1 AK |
1618 | frag_count = skb_shinfo(skb)->nr_frags + 1; |
1619 | ||
d877f1e3 | 1620 | /* 4 fragments per cmd des */ |
3d396eb1 | 1621 | no_of_desc = (frag_count + 3) >> 2; |
53a01e00 | 1622 | |
cb2107be | 1623 | if (unlikely(no_of_desc + 2) > netxen_tx_avail(tx_ring)) { |
ba53e6b4 | 1624 | netif_stop_queue(netdev); |
ba53e6b4 | 1625 | return NETDEV_TX_BUSY; |
53a01e00 | 1626 | } |
3d396eb1 | 1627 | |
cb2107be | 1628 | producer = tx_ring->producer; |
ce644ed4 | 1629 | pbuf = &tx_ring->cmd_buf_arr[producer]; |
cb2107be | 1630 | |
1bcfd790 | 1631 | pdev = adapter->pdev; |
391587c3 | 1632 | |
ce644ed4 | 1633 | if (netxen_map_tx_skb(pdev, skb, pbuf)) |
1bcfd790 | 1634 | goto drop_packet; |
391587c3 | 1635 | |
3d396eb1 | 1636 | pbuf->skb = skb; |
3d396eb1 | 1637 | pbuf->frag_count = frag_count; |
6f703406 | 1638 | |
1bcfd790 DP |
1639 | first_desc = hwdesc = &tx_ring->desc_head[producer]; |
1640 | netxen_clear_cmddesc((u64 *)hwdesc); | |
3d396eb1 | 1641 | |
ce644ed4 DP |
1642 | netxen_set_tx_frags_len(first_desc, frag_count, skb->len); |
1643 | netxen_set_tx_port(first_desc, adapter->portnum); | |
3d396eb1 | 1644 | |
ce644ed4 | 1645 | for (i = 0; i < frag_count; i++) { |
3d396eb1 | 1646 | |
ce644ed4 DP |
1647 | k = i % 4; |
1648 | ||
1649 | if ((k == 0) && (i > 0)) { | |
1650 | /* move to next desc.*/ | |
ba53e6b4 | 1651 | producer = get_next_index(producer, num_txd); |
d877f1e3 | 1652 | hwdesc = &tx_ring->desc_head[producer]; |
d32cc3d2 | 1653 | netxen_clear_cmddesc((u64 *)hwdesc); |
ce644ed4 | 1654 | tx_ring->cmd_buf_arr[producer].skb = NULL; |
6f703406 | 1655 | } |
3d396eb1 | 1656 | |
ce644ed4 | 1657 | buffrag = &pbuf->frag_array[i]; |
3d396eb1 | 1658 | |
ce644ed4 | 1659 | hwdesc->buffer_length[k] = cpu_to_le16(buffrag->length); |
3d396eb1 AK |
1660 | switch (k) { |
1661 | case 0: | |
ce644ed4 | 1662 | hwdesc->addr_buffer1 = cpu_to_le64(buffrag->dma); |
3d396eb1 AK |
1663 | break; |
1664 | case 1: | |
ce644ed4 | 1665 | hwdesc->addr_buffer2 = cpu_to_le64(buffrag->dma); |
3d396eb1 AK |
1666 | break; |
1667 | case 2: | |
ce644ed4 | 1668 | hwdesc->addr_buffer3 = cpu_to_le64(buffrag->dma); |
3d396eb1 AK |
1669 | break; |
1670 | case 3: | |
ce644ed4 | 1671 | hwdesc->addr_buffer4 = cpu_to_le64(buffrag->dma); |
3d396eb1 AK |
1672 | break; |
1673 | } | |
3d396eb1 | 1674 | } |
ce644ed4 | 1675 | |
1bcfd790 | 1676 | tx_ring->producer = get_next_index(producer, num_txd); |
3d396eb1 | 1677 | |
1bcfd790 | 1678 | netxen_tso_check(netdev, tx_ring, first_desc, skb); |
6c80b18d | 1679 | |
cb2107be | 1680 | netxen_nic_update_cmd_producer(adapter, tx_ring); |
3d396eb1 | 1681 | |
1bcfd790 | 1682 | adapter->stats.txbytes += skb->len; |
ba53e6b4 | 1683 | adapter->stats.xmitcalled++; |
3d396eb1 | 1684 | |
3d396eb1 | 1685 | return NETDEV_TX_OK; |
6f703406 DP |
1686 | |
1687 | drop_packet: | |
1688 | adapter->stats.txdropped++; | |
1689 | dev_kfree_skb_any(skb); | |
1690 | return NETDEV_TX_OK; | |
3d396eb1 AK |
1691 | } |
1692 | ||
a97342f9 DP |
1693 | static int netxen_nic_check_temp(struct netxen_adapter *adapter) |
1694 | { | |
1695 | struct net_device *netdev = adapter->netdev; | |
1696 | uint32_t temp, temp_state, temp_val; | |
1697 | int rv = 0; | |
1698 | ||
f98a9f69 | 1699 | temp = NXRD32(adapter, CRB_TEMP_STATE); |
a97342f9 DP |
1700 | |
1701 | temp_state = nx_get_temp_state(temp); | |
1702 | temp_val = nx_get_temp_val(temp); | |
1703 | ||
1704 | if (temp_state == NX_TEMP_PANIC) { | |
1705 | printk(KERN_ALERT | |
1706 | "%s: Device temperature %d degrees C exceeds" | |
1707 | " maximum allowed. Hardware has been shut down.\n", | |
e4135c2d | 1708 | netdev->name, temp_val); |
a97342f9 DP |
1709 | rv = 1; |
1710 | } else if (temp_state == NX_TEMP_WARN) { | |
1711 | if (adapter->temp == NX_TEMP_NORMAL) { | |
1712 | printk(KERN_ALERT | |
1713 | "%s: Device temperature %d degrees C " | |
1714 | "exceeds operating range." | |
1715 | " Immediate action needed.\n", | |
e4135c2d | 1716 | netdev->name, temp_val); |
a97342f9 DP |
1717 | } |
1718 | } else { | |
1719 | if (adapter->temp == NX_TEMP_WARN) { | |
1720 | printk(KERN_INFO | |
1721 | "%s: Device temperature is now %d degrees C" | |
e4135c2d | 1722 | " in normal range.\n", netdev->name, |
a97342f9 DP |
1723 | temp_val); |
1724 | } | |
1725 | } | |
1726 | adapter->temp = temp_state; | |
1727 | return rv; | |
1728 | } | |
1729 | ||
3bf26ce3 | 1730 | void netxen_advert_link_change(struct netxen_adapter *adapter, int linkup) |
a97342f9 DP |
1731 | { |
1732 | struct net_device *netdev = adapter->netdev; | |
a97342f9 DP |
1733 | |
1734 | if (adapter->ahw.linkup && !linkup) { | |
1735 | printk(KERN_INFO "%s: %s NIC Link is down\n", | |
1736 | netxen_nic_driver_name, netdev->name); | |
1737 | adapter->ahw.linkup = 0; | |
1738 | if (netif_running(netdev)) { | |
1739 | netif_carrier_off(netdev); | |
1740 | netif_stop_queue(netdev); | |
1741 | } | |
e424fa9d | 1742 | adapter->link_changed = !adapter->has_link_events; |
a97342f9 DP |
1743 | } else if (!adapter->ahw.linkup && linkup) { |
1744 | printk(KERN_INFO "%s: %s NIC Link is up\n", | |
1745 | netxen_nic_driver_name, netdev->name); | |
1746 | adapter->ahw.linkup = 1; | |
1747 | if (netif_running(netdev)) { | |
1748 | netif_carrier_on(netdev); | |
1749 | netif_wake_queue(netdev); | |
1750 | } | |
e424fa9d | 1751 | adapter->link_changed = !adapter->has_link_events; |
a97342f9 DP |
1752 | } |
1753 | } | |
1754 | ||
3bf26ce3 DP |
1755 | static void netxen_nic_handle_phy_intr(struct netxen_adapter *adapter) |
1756 | { | |
1757 | u32 val, port, linkup; | |
1758 | ||
1759 | port = adapter->physical_port; | |
1760 | ||
1761 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) { | |
f98a9f69 | 1762 | val = NXRD32(adapter, CRB_XG_STATE_P3); |
3bf26ce3 DP |
1763 | val = XG_LINK_STATE_P3(adapter->ahw.pci_func, val); |
1764 | linkup = (val == XG_LINK_UP_P3); | |
1765 | } else { | |
f98a9f69 | 1766 | val = NXRD32(adapter, CRB_XG_STATE); |
3bf26ce3 DP |
1767 | if (adapter->ahw.port_type == NETXEN_NIC_GBE) |
1768 | linkup = (val >> port) & 1; | |
1769 | else { | |
1770 | val = (val >> port*8) & 0xff; | |
1771 | linkup = (val == XG_LINK_UP); | |
1772 | } | |
1773 | } | |
1774 | ||
1775 | netxen_advert_link_change(adapter, linkup); | |
1776 | } | |
1777 | ||
e424fa9d AKS |
1778 | static void netxen_nic_thermal_shutdown(struct netxen_adapter *adapter) |
1779 | { | |
1780 | struct net_device *netdev = adapter->netdev; | |
1781 | ||
1782 | netif_device_detach(netdev); | |
1783 | netxen_nic_down(adapter, netdev); | |
1784 | netxen_nic_detach(adapter); | |
1785 | } | |
1786 | ||
3d396eb1 AK |
1787 | static void netxen_watchdog(unsigned long v) |
1788 | { | |
1789 | struct netxen_adapter *adapter = (struct netxen_adapter *)v; | |
ed25ffa1 | 1790 | |
e424fa9d AKS |
1791 | if (netxen_nic_check_temp(adapter)) |
1792 | goto do_sched; | |
1793 | ||
1794 | if (!adapter->has_link_events) { | |
1795 | netxen_nic_handle_phy_intr(adapter); | |
1796 | ||
1797 | if (adapter->link_changed) | |
1798 | goto do_sched; | |
1799 | } | |
1800 | ||
1801 | if (netif_running(adapter->netdev)) | |
1802 | mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ); | |
1803 | ||
1804 | return; | |
1805 | ||
1806 | do_sched: | |
1807 | schedule_work(&adapter->watchdog_task); | |
3d396eb1 AK |
1808 | } |
1809 | ||
a97342f9 DP |
1810 | void netxen_watchdog_task(struct work_struct *work) |
1811 | { | |
1812 | struct netxen_adapter *adapter = | |
1813 | container_of(work, struct netxen_adapter, watchdog_task); | |
1814 | ||
e424fa9d AKS |
1815 | if (adapter->temp == NX_TEMP_PANIC) { |
1816 | netxen_nic_thermal_shutdown(adapter); | |
a97342f9 | 1817 | return; |
e424fa9d | 1818 | } |
a97342f9 | 1819 | |
e424fa9d AKS |
1820 | if (adapter->link_changed) |
1821 | netxen_nic_set_link_parameters(adapter); | |
a97342f9 | 1822 | |
922c4f2c DP |
1823 | if (netif_running(adapter->netdev)) |
1824 | mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ); | |
a97342f9 DP |
1825 | } |
1826 | ||
3d396eb1 AK |
1827 | static void netxen_tx_timeout(struct net_device *netdev) |
1828 | { | |
e424fa9d | 1829 | struct netxen_adapter *adapter = netdev_priv(netdev); |
f17443f4 DP |
1830 | |
1831 | dev_err(&netdev->dev, "transmit timeout, resetting.\n"); | |
e424fa9d | 1832 | schedule_work(&adapter->tx_timeout_task); |
3d396eb1 AK |
1833 | } |
1834 | ||
f17443f4 | 1835 | static void netxen_reset_task(struct work_struct *work) |
3d396eb1 | 1836 | { |
4790654c | 1837 | struct netxen_adapter *adapter = |
3176ff3e | 1838 | container_of(work, struct netxen_adapter, tx_timeout_task); |
3d396eb1 | 1839 | |
b2af9cb0 DP |
1840 | if (!netif_running(adapter->netdev)) |
1841 | return; | |
1842 | ||
d8b100c5 | 1843 | netxen_napi_disable(adapter); |
ba53e6b4 | 1844 | |
6c80b18d | 1845 | adapter->netdev->trans_start = jiffies; |
ba53e6b4 | 1846 | |
d8b100c5 | 1847 | netxen_napi_enable(adapter); |
6c80b18d | 1848 | netif_wake_queue(adapter->netdev); |
3d396eb1 AK |
1849 | } |
1850 | ||
a97342f9 DP |
1851 | struct net_device_stats *netxen_nic_get_stats(struct net_device *netdev) |
1852 | { | |
1853 | struct netxen_adapter *adapter = netdev_priv(netdev); | |
1854 | struct net_device_stats *stats = &adapter->net_stats; | |
1855 | ||
1856 | memset(stats, 0, sizeof(*stats)); | |
1857 | ||
1bb482f8 | 1858 | stats->rx_packets = adapter->stats.rx_pkts + adapter->stats.lro_pkts; |
e98e3350 | 1859 | stats->tx_packets = adapter->stats.xmitfinished; |
a97342f9 | 1860 | stats->rx_bytes = adapter->stats.rxbytes; |
a97342f9 | 1861 | stats->tx_bytes = adapter->stats.txbytes; |
a97342f9 | 1862 | stats->rx_dropped = adapter->stats.rxdropped; |
a97342f9 DP |
1863 | stats->tx_dropped = adapter->stats.txdropped; |
1864 | ||
1865 | return stats; | |
1866 | } | |
1867 | ||
e4c93c81 | 1868 | static irqreturn_t netxen_intr(int irq, void *data) |
3d396eb1 | 1869 | { |
d8b100c5 DP |
1870 | struct nx_host_sds_ring *sds_ring = data; |
1871 | struct netxen_adapter *adapter = sds_ring->adapter; | |
d71e1be8 DP |
1872 | u32 status = 0; |
1873 | ||
1874 | status = adapter->pci_read_immediate(adapter, ISR_INT_VECTOR); | |
1875 | ||
1876 | if (!(status & adapter->legacy_intr.int_vec_bit)) | |
05aaa02d | 1877 | return IRQ_NONE; |
e01872af | 1878 | |
d71e1be8 DP |
1879 | if (adapter->ahw.revision_id >= NX_P3_B1) { |
1880 | /* check interrupt state machine, to be sure */ | |
1881 | status = adapter->pci_read_immediate(adapter, | |
1882 | ISR_INT_STATE_REG); | |
1883 | if (!ISR_LEGACY_INT_TRIGGERED(status)) | |
1884 | return IRQ_NONE; | |
1885 | ||
092bc571 DP |
1886 | } else { |
1887 | unsigned long our_int = 0; | |
d71e1be8 | 1888 | |
f98a9f69 | 1889 | our_int = NXRD32(adapter, CRB_INT_VECTOR); |
092bc571 | 1890 | |
d71e1be8 | 1891 | /* not our interrupt */ |
092bc571 | 1892 | if (!test_and_clear_bit((7 + adapter->portnum), &our_int)) |
d71e1be8 DP |
1893 | return IRQ_NONE; |
1894 | ||
092bc571 | 1895 | /* claim interrupt */ |
f98a9f69 | 1896 | NXWR32(adapter, CRB_INT_VECTOR, (our_int & 0xffffffff)); |
e01872af | 1897 | } |
1898 | ||
092bc571 | 1899 | /* clear interrupt */ |
4f96b988 | 1900 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) |
d8b100c5 | 1901 | netxen_nic_disable_int(sds_ring); |
092bc571 DP |
1902 | |
1903 | adapter->pci_write_immediate(adapter, | |
1904 | adapter->legacy_intr.tgt_status_reg, | |
1905 | 0xffffffff); | |
1906 | /* read twice to ensure write is flushed */ | |
1907 | adapter->pci_read_immediate(adapter, ISR_INT_VECTOR); | |
1908 | adapter->pci_read_immediate(adapter, ISR_INT_VECTOR); | |
1909 | ||
d8b100c5 | 1910 | napi_schedule(&sds_ring->napi); |
3d396eb1 AK |
1911 | |
1912 | return IRQ_HANDLED; | |
1913 | } | |
1914 | ||
e4c93c81 | 1915 | static irqreturn_t netxen_msi_intr(int irq, void *data) |
05aaa02d | 1916 | { |
d8b100c5 DP |
1917 | struct nx_host_sds_ring *sds_ring = data; |
1918 | struct netxen_adapter *adapter = sds_ring->adapter; | |
05aaa02d | 1919 | |
092bc571 DP |
1920 | /* clear interrupt */ |
1921 | adapter->pci_write_immediate(adapter, | |
7a2469ce | 1922 | adapter->msi_tgt_status, 0xffffffff); |
092bc571 | 1923 | |
d8b100c5 | 1924 | napi_schedule(&sds_ring->napi); |
05aaa02d DP |
1925 | return IRQ_HANDLED; |
1926 | } | |
1927 | ||
b3df68f8 DP |
1928 | static irqreturn_t netxen_msix_intr(int irq, void *data) |
1929 | { | |
d8b100c5 | 1930 | struct nx_host_sds_ring *sds_ring = data; |
b3df68f8 | 1931 | |
d8b100c5 | 1932 | napi_schedule(&sds_ring->napi); |
b3df68f8 DP |
1933 | return IRQ_HANDLED; |
1934 | } | |
1935 | ||
bea3348e | 1936 | static int netxen_nic_poll(struct napi_struct *napi, int budget) |
3d396eb1 | 1937 | { |
d8b100c5 DP |
1938 | struct nx_host_sds_ring *sds_ring = |
1939 | container_of(napi, struct nx_host_sds_ring, napi); | |
1940 | ||
1941 | struct netxen_adapter *adapter = sds_ring->adapter; | |
1942 | ||
05aaa02d | 1943 | int tx_complete; |
bea3348e | 1944 | int work_done; |
3d396eb1 | 1945 | |
05aaa02d | 1946 | tx_complete = netxen_process_cmd_ring(adapter); |
3d396eb1 | 1947 | |
d8b100c5 | 1948 | work_done = netxen_process_rcv_ring(sds_ring, budget); |
3d396eb1 | 1949 | |
05aaa02d | 1950 | if ((work_done < budget) && tx_complete) { |
d8b100c5 | 1951 | napi_complete(&sds_ring->napi); |
b2af9cb0 DP |
1952 | if (netif_running(adapter->netdev)) |
1953 | netxen_nic_enable_int(sds_ring); | |
3d396eb1 AK |
1954 | } |
1955 | ||
bea3348e | 1956 | return work_done; |
3d396eb1 AK |
1957 | } |
1958 | ||
1959 | #ifdef CONFIG_NET_POLL_CONTROLLER | |
1960 | static void netxen_nic_poll_controller(struct net_device *netdev) | |
1961 | { | |
3176ff3e | 1962 | struct netxen_adapter *adapter = netdev_priv(netdev); |
3d396eb1 | 1963 | disable_irq(adapter->irq); |
1494a814 | 1964 | netxen_intr(adapter->irq, adapter); |
3d396eb1 AK |
1965 | enable_irq(adapter->irq); |
1966 | } | |
1967 | #endif | |
3d396eb1 | 1968 | |
fa3ce355 NK |
1969 | static ssize_t |
1970 | netxen_store_bridged_mode(struct device *dev, | |
1971 | struct device_attribute *attr, const char *buf, size_t len) | |
1972 | { | |
1973 | struct net_device *net = to_net_dev(dev); | |
1974 | struct netxen_adapter *adapter = netdev_priv(net); | |
1975 | unsigned long new; | |
1976 | int ret = -EINVAL; | |
1977 | ||
1978 | if (!(adapter->capabilities & NX_FW_CAPABILITY_BDG)) | |
1979 | goto err_out; | |
1980 | ||
1981 | if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC) | |
1982 | goto err_out; | |
1983 | ||
1984 | if (strict_strtoul(buf, 2, &new)) | |
1985 | goto err_out; | |
1986 | ||
1987 | if (!netxen_config_bridged_mode(adapter, !!new)) | |
1988 | ret = len; | |
1989 | ||
1990 | err_out: | |
1991 | return ret; | |
1992 | } | |
1993 | ||
1994 | static ssize_t | |
1995 | netxen_show_bridged_mode(struct device *dev, | |
1996 | struct device_attribute *attr, char *buf) | |
1997 | { | |
1998 | struct net_device *net = to_net_dev(dev); | |
1999 | struct netxen_adapter *adapter; | |
2000 | int bridged_mode = 0; | |
2001 | ||
2002 | adapter = netdev_priv(net); | |
2003 | ||
2004 | if (adapter->capabilities & NX_FW_CAPABILITY_BDG) | |
2005 | bridged_mode = !!(adapter->flags & NETXEN_NIC_BRIDGE_ENABLED); | |
2006 | ||
2007 | return sprintf(buf, "%d\n", bridged_mode); | |
2008 | } | |
2009 | ||
2010 | static struct device_attribute dev_attr_bridged_mode = { | |
2011 | .attr = {.name = "bridged_mode", .mode = (S_IRUGO | S_IWUSR)}, | |
2012 | .show = netxen_show_bridged_mode, | |
2013 | .store = netxen_store_bridged_mode, | |
2014 | }; | |
2015 | ||
2016 | static void | |
2017 | netxen_create_sysfs_entries(struct netxen_adapter *adapter) | |
2018 | { | |
2019 | struct net_device *netdev = adapter->netdev; | |
2020 | struct device *dev = &netdev->dev; | |
2021 | ||
2022 | if (adapter->capabilities & NX_FW_CAPABILITY_BDG) { | |
2023 | /* bridged_mode control */ | |
2024 | if (device_create_file(dev, &dev_attr_bridged_mode)) { | |
2025 | dev_warn(&netdev->dev, | |
2026 | "failed to create bridged_mode sysfs entry\n"); | |
2027 | } | |
2028 | } | |
2029 | } | |
2030 | ||
2031 | static void | |
2032 | netxen_remove_sysfs_entries(struct netxen_adapter *adapter) | |
2033 | { | |
2034 | struct net_device *netdev = adapter->netdev; | |
2035 | struct device *dev = &netdev->dev; | |
2036 | ||
2037 | if (adapter->capabilities & NX_FW_CAPABILITY_BDG) | |
2038 | device_remove_file(dev, &dev_attr_bridged_mode); | |
2039 | } | |
2040 | ||
2041 | static void netxen_watchdog(unsigned long); | |
2042 | ||
044824d9 DP |
2043 | #ifdef CONFIG_INET |
2044 | ||
6598b169 DP |
2045 | #define is_netxen_netdev(dev) (dev->netdev_ops == &netxen_netdev_ops) |
2046 | ||
2047 | static int | |
2048 | netxen_destip_supported(struct netxen_adapter *adapter) | |
2049 | { | |
2050 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) | |
2051 | return 0; | |
2052 | ||
2053 | if (adapter->ahw.cut_through) | |
2054 | return 0; | |
2055 | ||
2056 | return 1; | |
2057 | } | |
2058 | ||
2059 | static int netxen_netdev_event(struct notifier_block *this, | |
2060 | unsigned long event, void *ptr) | |
2061 | { | |
2062 | struct netxen_adapter *adapter; | |
2063 | struct net_device *dev = (struct net_device *)ptr; | |
2064 | struct in_device *indev; | |
2065 | ||
2066 | recheck: | |
2067 | if (dev == NULL) | |
2068 | goto done; | |
2069 | ||
2070 | if (dev->priv_flags & IFF_802_1Q_VLAN) { | |
2071 | dev = vlan_dev_real_dev(dev); | |
2072 | goto recheck; | |
2073 | } | |
2074 | ||
2075 | if (!is_netxen_netdev(dev)) | |
2076 | goto done; | |
2077 | ||
2078 | adapter = netdev_priv(dev); | |
2079 | ||
2080 | if (!adapter || !netxen_destip_supported(adapter)) | |
2081 | goto done; | |
2082 | ||
2083 | if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC) | |
2084 | goto done; | |
2085 | ||
2086 | indev = in_dev_get(dev); | |
2087 | if (!indev) | |
2088 | goto done; | |
2089 | ||
2090 | for_ifa(indev) { | |
2091 | switch (event) { | |
2092 | case NETDEV_UP: | |
2093 | netxen_config_ipaddr(adapter, | |
2094 | ifa->ifa_address, NX_IP_UP); | |
2095 | break; | |
2096 | case NETDEV_DOWN: | |
2097 | netxen_config_ipaddr(adapter, | |
2098 | ifa->ifa_address, NX_IP_DOWN); | |
2099 | break; | |
2100 | default: | |
2101 | break; | |
2102 | } | |
2103 | } endfor_ifa(indev); | |
2104 | ||
2105 | in_dev_put(indev); | |
2106 | done: | |
2107 | return NOTIFY_DONE; | |
2108 | } | |
2109 | ||
2110 | static int | |
2111 | netxen_inetaddr_event(struct notifier_block *this, | |
2112 | unsigned long event, void *ptr) | |
2113 | { | |
2114 | struct netxen_adapter *adapter; | |
2115 | struct net_device *dev; | |
2116 | ||
2117 | struct in_ifaddr *ifa = (struct in_ifaddr *)ptr; | |
2118 | ||
2119 | dev = ifa->ifa_dev ? ifa->ifa_dev->dev : NULL; | |
2120 | ||
2121 | recheck: | |
2122 | if (dev == NULL || !netif_running(dev)) | |
2123 | goto done; | |
2124 | ||
2125 | if (dev->priv_flags & IFF_802_1Q_VLAN) { | |
2126 | dev = vlan_dev_real_dev(dev); | |
2127 | goto recheck; | |
2128 | } | |
2129 | ||
2130 | if (!is_netxen_netdev(dev)) | |
2131 | goto done; | |
2132 | ||
2133 | adapter = netdev_priv(dev); | |
2134 | ||
2135 | if (!adapter || !netxen_destip_supported(adapter)) | |
2136 | goto done; | |
2137 | ||
2138 | if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC) | |
2139 | goto done; | |
2140 | ||
2141 | switch (event) { | |
2142 | case NETDEV_UP: | |
2143 | netxen_config_ipaddr(adapter, ifa->ifa_address, NX_IP_UP); | |
2144 | break; | |
2145 | case NETDEV_DOWN: | |
2146 | netxen_config_ipaddr(adapter, ifa->ifa_address, NX_IP_DOWN); | |
2147 | break; | |
2148 | default: | |
2149 | break; | |
2150 | } | |
2151 | ||
2152 | done: | |
2153 | return NOTIFY_DONE; | |
2154 | } | |
2155 | ||
2156 | static struct notifier_block netxen_netdev_cb = { | |
2157 | .notifier_call = netxen_netdev_event, | |
2158 | }; | |
2159 | ||
2160 | static struct notifier_block netxen_inetaddr_cb = { | |
2161 | .notifier_call = netxen_inetaddr_event, | |
2162 | }; | |
044824d9 | 2163 | #endif |
6598b169 | 2164 | |
3d396eb1 AK |
2165 | static struct pci_driver netxen_driver = { |
2166 | .name = netxen_nic_driver_name, | |
2167 | .id_table = netxen_pci_tbl, | |
2168 | .probe = netxen_nic_probe, | |
0b72e659 | 2169 | .remove = __devexit_p(netxen_nic_remove), |
01542cd1 | 2170 | #ifdef CONFIG_PM |
0b72e659 | 2171 | .suspend = netxen_nic_suspend, |
22b5794b | 2172 | .resume = netxen_nic_resume, |
01542cd1 | 2173 | #endif |
22b5794b | 2174 | .shutdown = netxen_nic_shutdown |
3d396eb1 AK |
2175 | }; |
2176 | ||
3d396eb1 AK |
2177 | static int __init netxen_init_module(void) |
2178 | { | |
ff4fbd43 DP |
2179 | printk(KERN_INFO "%s\n", netxen_nic_driver_string); |
2180 | ||
044824d9 | 2181 | #ifdef CONFIG_INET |
6598b169 DP |
2182 | register_netdevice_notifier(&netxen_netdev_cb); |
2183 | register_inetaddr_notifier(&netxen_inetaddr_cb); | |
044824d9 | 2184 | #endif |
6598b169 | 2185 | |
184231bd | 2186 | return pci_register_driver(&netxen_driver); |
3d396eb1 AK |
2187 | } |
2188 | ||
2189 | module_init(netxen_init_module); | |
2190 | ||
2191 | static void __exit netxen_exit_module(void) | |
2192 | { | |
3d396eb1 | 2193 | pci_unregister_driver(&netxen_driver); |
6598b169 | 2194 | |
044824d9 | 2195 | #ifdef CONFIG_INET |
6598b169 DP |
2196 | unregister_inetaddr_notifier(&netxen_inetaddr_cb); |
2197 | unregister_netdevice_notifier(&netxen_netdev_cb); | |
044824d9 | 2198 | #endif |
3d396eb1 AK |
2199 | } |
2200 | ||
2201 | module_exit(netxen_exit_module); |