]>
Commit | Line | Data |
---|---|---|
0da34b6d BG |
1 | /************************************************************************* |
2 | * myri10ge.c: Myricom Myri-10G Ethernet driver. | |
3 | * | |
4a2e612a | 4 | * Copyright (C) 2005 - 2007 Myricom, Inc. |
0da34b6d BG |
5 | * All rights reserved. |
6 | * | |
7 | * Redistribution and use in source and binary forms, with or without | |
8 | * modification, are permitted provided that the following conditions | |
9 | * are met: | |
10 | * 1. Redistributions of source code must retain the above copyright | |
11 | * notice, this list of conditions and the following disclaimer. | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | |
15 | * 3. Neither the name of Myricom, Inc. nor the names of its contributors | |
16 | * may be used to endorse or promote products derived from this software | |
17 | * without specific prior written permission. | |
18 | * | |
4a2e612a BG |
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
0da34b6d | 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
4a2e612a BG |
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
29 | * POSSIBILITY OF SUCH DAMAGE. | |
0da34b6d BG |
30 | * |
31 | * | |
32 | * If the eeprom on your board is not recent enough, you will need to get a | |
33 | * newer firmware image at: | |
34 | * http://www.myri.com/scs/download-Myri10GE.html | |
35 | * | |
36 | * Contact Information: | |
37 | * <help@myri.com> | |
38 | * Myricom, Inc., 325N Santa Anita Avenue, Arcadia, CA 91006 | |
39 | *************************************************************************/ | |
40 | ||
41 | #include <linux/tcp.h> | |
42 | #include <linux/netdevice.h> | |
43 | #include <linux/skbuff.h> | |
44 | #include <linux/string.h> | |
45 | #include <linux/module.h> | |
46 | #include <linux/pci.h> | |
b10c0668 | 47 | #include <linux/dma-mapping.h> |
0da34b6d BG |
48 | #include <linux/etherdevice.h> |
49 | #include <linux/if_ether.h> | |
50 | #include <linux/if_vlan.h> | |
1e6e9342 | 51 | #include <linux/inet_lro.h> |
0da34b6d BG |
52 | #include <linux/ip.h> |
53 | #include <linux/inet.h> | |
54 | #include <linux/in.h> | |
55 | #include <linux/ethtool.h> | |
56 | #include <linux/firmware.h> | |
57 | #include <linux/delay.h> | |
58 | #include <linux/version.h> | |
59 | #include <linux/timer.h> | |
60 | #include <linux/vmalloc.h> | |
61 | #include <linux/crc32.h> | |
62 | #include <linux/moduleparam.h> | |
63 | #include <linux/io.h> | |
199126a2 | 64 | #include <linux/log2.h> |
0da34b6d | 65 | #include <net/checksum.h> |
1e6e9342 AG |
66 | #include <net/ip.h> |
67 | #include <net/tcp.h> | |
0da34b6d BG |
68 | #include <asm/byteorder.h> |
69 | #include <asm/io.h> | |
0da34b6d BG |
70 | #include <asm/processor.h> |
71 | #ifdef CONFIG_MTRR | |
72 | #include <asm/mtrr.h> | |
73 | #endif | |
74 | ||
75 | #include "myri10ge_mcp.h" | |
76 | #include "myri10ge_mcp_gen_header.h" | |
77 | ||
e0d7c526 | 78 | #define MYRI10GE_VERSION_STR "1.3.2-1.287" |
0da34b6d BG |
79 | |
80 | MODULE_DESCRIPTION("Myricom 10G driver (10GbE)"); | |
81 | MODULE_AUTHOR("Maintainer: help@myri.com"); | |
82 | MODULE_VERSION(MYRI10GE_VERSION_STR); | |
83 | MODULE_LICENSE("Dual BSD/GPL"); | |
84 | ||
85 | #define MYRI10GE_MAX_ETHER_MTU 9014 | |
86 | ||
87 | #define MYRI10GE_ETH_STOPPED 0 | |
88 | #define MYRI10GE_ETH_STOPPING 1 | |
89 | #define MYRI10GE_ETH_STARTING 2 | |
90 | #define MYRI10GE_ETH_RUNNING 3 | |
91 | #define MYRI10GE_ETH_OPEN_FAILED 4 | |
92 | ||
93 | #define MYRI10GE_EEPROM_STRINGS_SIZE 256 | |
94 | #define MYRI10GE_MAX_SEND_DESC_TSO ((65536 / 2048) * 2) | |
1e6e9342 AG |
95 | #define MYRI10GE_MAX_LRO_DESCRIPTORS 8 |
96 | #define MYRI10GE_LRO_MAX_PKTS 64 | |
0da34b6d | 97 | |
40f6cff5 | 98 | #define MYRI10GE_NO_CONFIRM_DATA htonl(0xffffffff) |
0da34b6d BG |
99 | #define MYRI10GE_NO_RESPONSE_RESULT 0xffffffff |
100 | ||
dd50f336 BG |
101 | #define MYRI10GE_ALLOC_ORDER 0 |
102 | #define MYRI10GE_ALLOC_SIZE ((1 << MYRI10GE_ALLOC_ORDER) * PAGE_SIZE) | |
103 | #define MYRI10GE_MAX_FRAGS_PER_FRAME (MYRI10GE_MAX_ETHER_MTU/MYRI10GE_ALLOC_SIZE + 1) | |
104 | ||
0da34b6d | 105 | struct myri10ge_rx_buffer_state { |
dd50f336 BG |
106 | struct page *page; |
107 | int page_offset; | |
0da34b6d BG |
108 | DECLARE_PCI_UNMAP_ADDR(bus) |
109 | DECLARE_PCI_UNMAP_LEN(len) | |
110 | }; | |
111 | ||
112 | struct myri10ge_tx_buffer_state { | |
113 | struct sk_buff *skb; | |
114 | int last; | |
115 | DECLARE_PCI_UNMAP_ADDR(bus) | |
116 | DECLARE_PCI_UNMAP_LEN(len) | |
117 | }; | |
118 | ||
119 | struct myri10ge_cmd { | |
120 | u32 data0; | |
121 | u32 data1; | |
122 | u32 data2; | |
123 | }; | |
124 | ||
125 | struct myri10ge_rx_buf { | |
126 | struct mcp_kreq_ether_recv __iomem *lanai; /* lanai ptr for recv ring */ | |
127 | u8 __iomem *wc_fifo; /* w/c rx dma addr fifo address */ | |
128 | struct mcp_kreq_ether_recv *shadow; /* host shadow of recv ring */ | |
129 | struct myri10ge_rx_buffer_state *info; | |
dd50f336 BG |
130 | struct page *page; |
131 | dma_addr_t bus; | |
132 | int page_offset; | |
0da34b6d | 133 | int cnt; |
dd50f336 | 134 | int fill_cnt; |
0da34b6d BG |
135 | int alloc_fail; |
136 | int mask; /* number of rx slots -1 */ | |
dd50f336 | 137 | int watchdog_needed; |
0da34b6d BG |
138 | }; |
139 | ||
140 | struct myri10ge_tx_buf { | |
141 | struct mcp_kreq_ether_send __iomem *lanai; /* lanai ptr for sendq */ | |
142 | u8 __iomem *wc_fifo; /* w/c send fifo address */ | |
143 | struct mcp_kreq_ether_send *req_list; /* host shadow of sendq */ | |
144 | char *req_bytes; | |
145 | struct myri10ge_tx_buffer_state *info; | |
146 | int mask; /* number of transmit slots -1 */ | |
147 | int boundary; /* boundary transmits cannot cross */ | |
148 | int req ____cacheline_aligned; /* transmit slots submitted */ | |
149 | int pkt_start; /* packets started */ | |
150 | int done ____cacheline_aligned; /* transmit slots completed */ | |
151 | int pkt_done; /* packets completed */ | |
152 | }; | |
153 | ||
154 | struct myri10ge_rx_done { | |
155 | struct mcp_slot *entry; | |
156 | dma_addr_t bus; | |
157 | int cnt; | |
158 | int idx; | |
1e6e9342 AG |
159 | struct net_lro_mgr lro_mgr; |
160 | struct net_lro_desc lro_desc[MYRI10GE_MAX_LRO_DESCRIPTORS]; | |
0da34b6d BG |
161 | }; |
162 | ||
163 | struct myri10ge_priv { | |
164 | int running; /* running? */ | |
165 | int csum_flag; /* rx_csums? */ | |
166 | struct myri10ge_tx_buf tx; /* transmit ring */ | |
167 | struct myri10ge_rx_buf rx_small; | |
168 | struct myri10ge_rx_buf rx_big; | |
169 | struct myri10ge_rx_done rx_done; | |
170 | int small_bytes; | |
dd50f336 | 171 | int big_bytes; |
0da34b6d | 172 | struct net_device *dev; |
bea3348e | 173 | struct napi_struct napi; |
0da34b6d BG |
174 | struct net_device_stats stats; |
175 | u8 __iomem *sram; | |
176 | int sram_size; | |
177 | unsigned long board_span; | |
178 | unsigned long iomem_base; | |
40f6cff5 AV |
179 | __be32 __iomem *irq_claim; |
180 | __be32 __iomem *irq_deassert; | |
0da34b6d BG |
181 | char *mac_addr_string; |
182 | struct mcp_cmd_response *cmd; | |
183 | dma_addr_t cmd_bus; | |
184 | struct mcp_irq_data *fw_stats; | |
185 | dma_addr_t fw_stats_bus; | |
186 | struct pci_dev *pdev; | |
187 | int msi_enabled; | |
66341fff | 188 | u32 link_state; |
0da34b6d BG |
189 | unsigned int rdma_tags_available; |
190 | int intr_coal_delay; | |
40f6cff5 | 191 | __be32 __iomem *intr_coal_delay_ptr; |
0da34b6d | 192 | int mtrr; |
276e26c3 | 193 | int wc_enabled; |
0da34b6d BG |
194 | int wake_queue; |
195 | int stop_queue; | |
196 | int down_cnt; | |
197 | wait_queue_head_t down_wq; | |
198 | struct work_struct watchdog_work; | |
199 | struct timer_list watchdog_timer; | |
200 | int watchdog_tx_done; | |
c54772e7 | 201 | int watchdog_tx_req; |
626fda94 | 202 | int watchdog_pause; |
0da34b6d BG |
203 | int watchdog_resets; |
204 | int tx_linearized; | |
205 | int pause; | |
206 | char *fw_name; | |
207 | char eeprom_strings[MYRI10GE_EEPROM_STRINGS_SIZE]; | |
c0bf8801 | 208 | char *product_code_string; |
0da34b6d | 209 | char fw_version[128]; |
9dc6f0e7 BG |
210 | int fw_ver_major; |
211 | int fw_ver_minor; | |
212 | int fw_ver_tiny; | |
213 | int adopted_rx_filter_bug; | |
0da34b6d BG |
214 | u8 mac_addr[6]; /* eeprom mac address */ |
215 | unsigned long serial_number; | |
216 | int vendor_specific_offset; | |
85a7ea1b | 217 | int fw_multicast_support; |
4f93fde0 BG |
218 | unsigned long features; |
219 | u32 max_tso6; | |
0da34b6d BG |
220 | u32 read_dma; |
221 | u32 write_dma; | |
222 | u32 read_write_dma; | |
c58ac5ca BG |
223 | u32 link_changes; |
224 | u32 msg_enable; | |
0da34b6d BG |
225 | }; |
226 | ||
227 | static char *myri10ge_fw_unaligned = "myri10ge_ethp_z8e.dat"; | |
228 | static char *myri10ge_fw_aligned = "myri10ge_eth_z8e.dat"; | |
229 | ||
230 | static char *myri10ge_fw_name = NULL; | |
231 | module_param(myri10ge_fw_name, charp, S_IRUGO | S_IWUSR); | |
d1ce3a0f | 232 | MODULE_PARM_DESC(myri10ge_fw_name, "Firmware image name"); |
0da34b6d BG |
233 | |
234 | static int myri10ge_ecrc_enable = 1; | |
235 | module_param(myri10ge_ecrc_enable, int, S_IRUGO); | |
d1ce3a0f | 236 | MODULE_PARM_DESC(myri10ge_ecrc_enable, "Enable Extended CRC on PCI-E"); |
0da34b6d BG |
237 | |
238 | static int myri10ge_max_intr_slots = 1024; | |
239 | module_param(myri10ge_max_intr_slots, int, S_IRUGO); | |
d1ce3a0f | 240 | MODULE_PARM_DESC(myri10ge_max_intr_slots, "Interrupt queue slots"); |
0da34b6d BG |
241 | |
242 | static int myri10ge_small_bytes = -1; /* -1 == auto */ | |
243 | module_param(myri10ge_small_bytes, int, S_IRUGO | S_IWUSR); | |
d1ce3a0f | 244 | MODULE_PARM_DESC(myri10ge_small_bytes, "Threshold of small packets"); |
0da34b6d BG |
245 | |
246 | static int myri10ge_msi = 1; /* enable msi by default */ | |
3621cec5 | 247 | module_param(myri10ge_msi, int, S_IRUGO | S_IWUSR); |
d1ce3a0f | 248 | MODULE_PARM_DESC(myri10ge_msi, "Enable Message Signalled Interrupts"); |
0da34b6d | 249 | |
f761fae1 | 250 | static int myri10ge_intr_coal_delay = 75; |
0da34b6d | 251 | module_param(myri10ge_intr_coal_delay, int, S_IRUGO); |
d1ce3a0f | 252 | MODULE_PARM_DESC(myri10ge_intr_coal_delay, "Interrupt coalescing delay"); |
0da34b6d BG |
253 | |
254 | static int myri10ge_flow_control = 1; | |
255 | module_param(myri10ge_flow_control, int, S_IRUGO); | |
d1ce3a0f | 256 | MODULE_PARM_DESC(myri10ge_flow_control, "Pause parameter"); |
0da34b6d BG |
257 | |
258 | static int myri10ge_deassert_wait = 1; | |
259 | module_param(myri10ge_deassert_wait, int, S_IRUGO | S_IWUSR); | |
260 | MODULE_PARM_DESC(myri10ge_deassert_wait, | |
d1ce3a0f | 261 | "Wait when deasserting legacy interrupts"); |
0da34b6d BG |
262 | |
263 | static int myri10ge_force_firmware = 0; | |
264 | module_param(myri10ge_force_firmware, int, S_IRUGO); | |
265 | MODULE_PARM_DESC(myri10ge_force_firmware, | |
d1ce3a0f | 266 | "Force firmware to assume aligned completions"); |
0da34b6d | 267 | |
0da34b6d BG |
268 | static int myri10ge_initial_mtu = MYRI10GE_MAX_ETHER_MTU - ETH_HLEN; |
269 | module_param(myri10ge_initial_mtu, int, S_IRUGO); | |
d1ce3a0f | 270 | MODULE_PARM_DESC(myri10ge_initial_mtu, "Initial MTU"); |
0da34b6d BG |
271 | |
272 | static int myri10ge_napi_weight = 64; | |
273 | module_param(myri10ge_napi_weight, int, S_IRUGO); | |
d1ce3a0f | 274 | MODULE_PARM_DESC(myri10ge_napi_weight, "Set NAPI weight"); |
0da34b6d BG |
275 | |
276 | static int myri10ge_watchdog_timeout = 1; | |
277 | module_param(myri10ge_watchdog_timeout, int, S_IRUGO); | |
d1ce3a0f | 278 | MODULE_PARM_DESC(myri10ge_watchdog_timeout, "Set watchdog timeout"); |
0da34b6d BG |
279 | |
280 | static int myri10ge_max_irq_loops = 1048576; | |
281 | module_param(myri10ge_max_irq_loops, int, S_IRUGO); | |
282 | MODULE_PARM_DESC(myri10ge_max_irq_loops, | |
d1ce3a0f | 283 | "Set stuck legacy IRQ detection threshold"); |
0da34b6d | 284 | |
c58ac5ca BG |
285 | #define MYRI10GE_MSG_DEFAULT NETIF_MSG_LINK |
286 | ||
287 | static int myri10ge_debug = -1; /* defaults above */ | |
288 | module_param(myri10ge_debug, int, 0); | |
289 | MODULE_PARM_DESC(myri10ge_debug, "Debug level (0=none,...,16=all)"); | |
290 | ||
1e6e9342 AG |
291 | static int myri10ge_lro = 1; |
292 | module_param(myri10ge_lro, int, S_IRUGO); | |
d1ce3a0f | 293 | MODULE_PARM_DESC(myri10ge_lro, "Enable large receive offload"); |
1e6e9342 AG |
294 | |
295 | static int myri10ge_lro_max_pkts = MYRI10GE_LRO_MAX_PKTS; | |
296 | module_param(myri10ge_lro_max_pkts, int, S_IRUGO); | |
d1ce3a0f BG |
297 | MODULE_PARM_DESC(myri10ge_lro_max_pkts, |
298 | "Number of LRO packets to be aggregated"); | |
1e6e9342 | 299 | |
dd50f336 BG |
300 | static int myri10ge_fill_thresh = 256; |
301 | module_param(myri10ge_fill_thresh, int, S_IRUGO | S_IWUSR); | |
d1ce3a0f | 302 | MODULE_PARM_DESC(myri10ge_fill_thresh, "Number of empty rx slots allowed"); |
dd50f336 | 303 | |
f181137f BG |
304 | static int myri10ge_reset_recover = 1; |
305 | ||
f761fae1 | 306 | static int myri10ge_wcfifo = 0; |
6ebc087a | 307 | module_param(myri10ge_wcfifo, int, S_IRUGO); |
d1ce3a0f | 308 | MODULE_PARM_DESC(myri10ge_wcfifo, "Enable WC Fifo when WC is enabled"); |
6ebc087a | 309 | |
0da34b6d BG |
310 | #define MYRI10GE_FW_OFFSET 1024*1024 |
311 | #define MYRI10GE_HIGHPART_TO_U32(X) \ | |
312 | (sizeof (X) == 8) ? ((u32)((u64)(X) >> 32)) : (0) | |
313 | #define MYRI10GE_LOWPART_TO_U32(X) ((u32)(X)) | |
314 | ||
315 | #define myri10ge_pio_copy(to,from,size) __iowrite64_copy(to,from,size/8) | |
316 | ||
2f76216f | 317 | static void myri10ge_set_multicast_list(struct net_device *dev); |
4f93fde0 | 318 | static int myri10ge_sw_tso(struct sk_buff *skb, struct net_device *dev); |
2f76216f | 319 | |
6250223e | 320 | static inline void put_be32(__be32 val, __be32 __iomem * p) |
40f6cff5 | 321 | { |
6250223e | 322 | __raw_writel((__force __u32) val, (__force void __iomem *)p); |
40f6cff5 AV |
323 | } |
324 | ||
0da34b6d BG |
325 | static int |
326 | myri10ge_send_cmd(struct myri10ge_priv *mgp, u32 cmd, | |
327 | struct myri10ge_cmd *data, int atomic) | |
328 | { | |
329 | struct mcp_cmd *buf; | |
330 | char buf_bytes[sizeof(*buf) + 8]; | |
331 | struct mcp_cmd_response *response = mgp->cmd; | |
e700f9f4 | 332 | char __iomem *cmd_addr = mgp->sram + MXGEFW_ETH_CMD; |
0da34b6d BG |
333 | u32 dma_low, dma_high, result, value; |
334 | int sleep_total = 0; | |
335 | ||
336 | /* ensure buf is aligned to 8 bytes */ | |
337 | buf = (struct mcp_cmd *)ALIGN((unsigned long)buf_bytes, 8); | |
338 | ||
339 | buf->data0 = htonl(data->data0); | |
340 | buf->data1 = htonl(data->data1); | |
341 | buf->data2 = htonl(data->data2); | |
342 | buf->cmd = htonl(cmd); | |
343 | dma_low = MYRI10GE_LOWPART_TO_U32(mgp->cmd_bus); | |
344 | dma_high = MYRI10GE_HIGHPART_TO_U32(mgp->cmd_bus); | |
345 | ||
346 | buf->response_addr.low = htonl(dma_low); | |
347 | buf->response_addr.high = htonl(dma_high); | |
40f6cff5 | 348 | response->result = htonl(MYRI10GE_NO_RESPONSE_RESULT); |
0da34b6d BG |
349 | mb(); |
350 | myri10ge_pio_copy(cmd_addr, buf, sizeof(*buf)); | |
351 | ||
352 | /* wait up to 15ms. Longest command is the DMA benchmark, | |
353 | * which is capped at 5ms, but runs from a timeout handler | |
354 | * that runs every 7.8ms. So a 15ms timeout leaves us with | |
355 | * a 2.2ms margin | |
356 | */ | |
357 | if (atomic) { | |
358 | /* if atomic is set, do not sleep, | |
359 | * and try to get the completion quickly | |
360 | * (1ms will be enough for those commands) */ | |
361 | for (sleep_total = 0; | |
362 | sleep_total < 1000 | |
40f6cff5 | 363 | && response->result == htonl(MYRI10GE_NO_RESPONSE_RESULT); |
bd2db0cf | 364 | sleep_total += 10) { |
0da34b6d | 365 | udelay(10); |
bd2db0cf BG |
366 | mb(); |
367 | } | |
0da34b6d BG |
368 | } else { |
369 | /* use msleep for most command */ | |
370 | for (sleep_total = 0; | |
371 | sleep_total < 15 | |
40f6cff5 | 372 | && response->result == htonl(MYRI10GE_NO_RESPONSE_RESULT); |
0da34b6d BG |
373 | sleep_total++) |
374 | msleep(1); | |
375 | } | |
376 | ||
377 | result = ntohl(response->result); | |
378 | value = ntohl(response->data); | |
379 | if (result != MYRI10GE_NO_RESPONSE_RESULT) { | |
380 | if (result == 0) { | |
381 | data->data0 = value; | |
382 | return 0; | |
85a7ea1b BG |
383 | } else if (result == MXGEFW_CMD_UNKNOWN) { |
384 | return -ENOSYS; | |
5443e9ea BG |
385 | } else if (result == MXGEFW_CMD_ERROR_UNALIGNED) { |
386 | return -E2BIG; | |
0da34b6d BG |
387 | } else { |
388 | dev_err(&mgp->pdev->dev, | |
389 | "command %d failed, result = %d\n", | |
390 | cmd, result); | |
391 | return -ENXIO; | |
392 | } | |
393 | } | |
394 | ||
395 | dev_err(&mgp->pdev->dev, "command %d timed out, result = %d\n", | |
396 | cmd, result); | |
397 | return -EAGAIN; | |
398 | } | |
399 | ||
400 | /* | |
401 | * The eeprom strings on the lanaiX have the format | |
402 | * SN=x\0 | |
403 | * MAC=x:x:x:x:x:x\0 | |
404 | * PT:ddd mmm xx xx:xx:xx xx\0 | |
405 | * PV:ddd mmm xx xx:xx:xx xx\0 | |
406 | */ | |
407 | static int myri10ge_read_mac_addr(struct myri10ge_priv *mgp) | |
408 | { | |
409 | char *ptr, *limit; | |
410 | int i; | |
411 | ||
412 | ptr = mgp->eeprom_strings; | |
413 | limit = mgp->eeprom_strings + MYRI10GE_EEPROM_STRINGS_SIZE; | |
414 | ||
415 | while (*ptr != '\0' && ptr < limit) { | |
416 | if (memcmp(ptr, "MAC=", 4) == 0) { | |
417 | ptr += 4; | |
418 | mgp->mac_addr_string = ptr; | |
419 | for (i = 0; i < 6; i++) { | |
420 | if ((ptr + 2) > limit) | |
421 | goto abort; | |
422 | mgp->mac_addr[i] = | |
423 | simple_strtoul(ptr, &ptr, 16); | |
424 | ptr += 1; | |
425 | } | |
426 | } | |
c0bf8801 BG |
427 | if (memcmp(ptr, "PC=", 3) == 0) { |
428 | ptr += 3; | |
429 | mgp->product_code_string = ptr; | |
430 | } | |
0da34b6d BG |
431 | if (memcmp((const void *)ptr, "SN=", 3) == 0) { |
432 | ptr += 3; | |
433 | mgp->serial_number = simple_strtoul(ptr, &ptr, 10); | |
434 | } | |
435 | while (ptr < limit && *ptr++) ; | |
436 | } | |
437 | ||
438 | return 0; | |
439 | ||
440 | abort: | |
441 | dev_err(&mgp->pdev->dev, "failed to parse eeprom_strings\n"); | |
442 | return -ENXIO; | |
443 | } | |
444 | ||
445 | /* | |
446 | * Enable or disable periodic RDMAs from the host to make certain | |
447 | * chipsets resend dropped PCIe messages | |
448 | */ | |
449 | ||
450 | static void myri10ge_dummy_rdma(struct myri10ge_priv *mgp, int enable) | |
451 | { | |
452 | char __iomem *submit; | |
f8fd57c1 | 453 | __be32 buf[16] __attribute__ ((__aligned__(8))); |
0da34b6d BG |
454 | u32 dma_low, dma_high; |
455 | int i; | |
456 | ||
457 | /* clear confirmation addr */ | |
458 | mgp->cmd->data = 0; | |
459 | mb(); | |
460 | ||
461 | /* send a rdma command to the PCIe engine, and wait for the | |
462 | * response in the confirmation address. The firmware should | |
463 | * write a -1 there to indicate it is alive and well | |
464 | */ | |
465 | dma_low = MYRI10GE_LOWPART_TO_U32(mgp->cmd_bus); | |
466 | dma_high = MYRI10GE_HIGHPART_TO_U32(mgp->cmd_bus); | |
467 | ||
468 | buf[0] = htonl(dma_high); /* confirm addr MSW */ | |
469 | buf[1] = htonl(dma_low); /* confirm addr LSW */ | |
40f6cff5 | 470 | buf[2] = MYRI10GE_NO_CONFIRM_DATA; /* confirm data */ |
0da34b6d BG |
471 | buf[3] = htonl(dma_high); /* dummy addr MSW */ |
472 | buf[4] = htonl(dma_low); /* dummy addr LSW */ | |
473 | buf[5] = htonl(enable); /* enable? */ | |
474 | ||
e700f9f4 | 475 | submit = mgp->sram + MXGEFW_BOOT_DUMMY_RDMA; |
0da34b6d BG |
476 | |
477 | myri10ge_pio_copy(submit, &buf, sizeof(buf)); | |
478 | for (i = 0; mgp->cmd->data != MYRI10GE_NO_CONFIRM_DATA && i < 20; i++) | |
479 | msleep(1); | |
480 | if (mgp->cmd->data != MYRI10GE_NO_CONFIRM_DATA) | |
481 | dev_err(&mgp->pdev->dev, "dummy rdma %s failed\n", | |
482 | (enable ? "enable" : "disable")); | |
483 | } | |
484 | ||
485 | static int | |
486 | myri10ge_validate_firmware(struct myri10ge_priv *mgp, | |
487 | struct mcp_gen_header *hdr) | |
488 | { | |
489 | struct device *dev = &mgp->pdev->dev; | |
0da34b6d BG |
490 | |
491 | /* check firmware type */ | |
492 | if (ntohl(hdr->mcp_type) != MCP_TYPE_ETH) { | |
493 | dev_err(dev, "Bad firmware type: 0x%x\n", ntohl(hdr->mcp_type)); | |
494 | return -EINVAL; | |
495 | } | |
496 | ||
497 | /* save firmware version for ethtool */ | |
498 | strncpy(mgp->fw_version, hdr->version, sizeof(mgp->fw_version)); | |
499 | ||
9dc6f0e7 BG |
500 | sscanf(mgp->fw_version, "%d.%d.%d", &mgp->fw_ver_major, |
501 | &mgp->fw_ver_minor, &mgp->fw_ver_tiny); | |
0da34b6d | 502 | |
9dc6f0e7 BG |
503 | if (!(mgp->fw_ver_major == MXGEFW_VERSION_MAJOR |
504 | && mgp->fw_ver_minor == MXGEFW_VERSION_MINOR)) { | |
0da34b6d BG |
505 | dev_err(dev, "Found firmware version %s\n", mgp->fw_version); |
506 | dev_err(dev, "Driver needs %d.%d\n", MXGEFW_VERSION_MAJOR, | |
507 | MXGEFW_VERSION_MINOR); | |
508 | return -EINVAL; | |
509 | } | |
510 | return 0; | |
511 | } | |
512 | ||
513 | static int myri10ge_load_hotplug_firmware(struct myri10ge_priv *mgp, u32 * size) | |
514 | { | |
515 | unsigned crc, reread_crc; | |
516 | const struct firmware *fw; | |
517 | struct device *dev = &mgp->pdev->dev; | |
518 | struct mcp_gen_header *hdr; | |
519 | size_t hdr_offset; | |
520 | int status; | |
e454358a | 521 | unsigned i; |
0da34b6d BG |
522 | |
523 | if ((status = request_firmware(&fw, mgp->fw_name, dev)) < 0) { | |
524 | dev_err(dev, "Unable to load %s firmware image via hotplug\n", | |
525 | mgp->fw_name); | |
526 | status = -EINVAL; | |
527 | goto abort_with_nothing; | |
528 | } | |
529 | ||
530 | /* check size */ | |
531 | ||
532 | if (fw->size >= mgp->sram_size - MYRI10GE_FW_OFFSET || | |
533 | fw->size < MCP_HEADER_PTR_OFFSET + 4) { | |
534 | dev_err(dev, "Firmware size invalid:%d\n", (int)fw->size); | |
535 | status = -EINVAL; | |
536 | goto abort_with_fw; | |
537 | } | |
538 | ||
539 | /* check id */ | |
40f6cff5 | 540 | hdr_offset = ntohl(*(__be32 *) (fw->data + MCP_HEADER_PTR_OFFSET)); |
0da34b6d BG |
541 | if ((hdr_offset & 3) || hdr_offset + sizeof(*hdr) > fw->size) { |
542 | dev_err(dev, "Bad firmware file\n"); | |
543 | status = -EINVAL; | |
544 | goto abort_with_fw; | |
545 | } | |
546 | hdr = (void *)(fw->data + hdr_offset); | |
547 | ||
548 | status = myri10ge_validate_firmware(mgp, hdr); | |
549 | if (status != 0) | |
550 | goto abort_with_fw; | |
551 | ||
552 | crc = crc32(~0, fw->data, fw->size); | |
e454358a BG |
553 | for (i = 0; i < fw->size; i += 256) { |
554 | myri10ge_pio_copy(mgp->sram + MYRI10GE_FW_OFFSET + i, | |
555 | fw->data + i, | |
556 | min(256U, (unsigned)(fw->size - i))); | |
557 | mb(); | |
558 | readb(mgp->sram); | |
b10c0668 | 559 | } |
0da34b6d BG |
560 | /* corruption checking is good for parity recovery and buggy chipset */ |
561 | memcpy_fromio(fw->data, mgp->sram + MYRI10GE_FW_OFFSET, fw->size); | |
562 | reread_crc = crc32(~0, fw->data, fw->size); | |
563 | if (crc != reread_crc) { | |
564 | dev_err(dev, "CRC failed(fw-len=%u), got 0x%x (expect 0x%x)\n", | |
565 | (unsigned)fw->size, reread_crc, crc); | |
566 | status = -EIO; | |
567 | goto abort_with_fw; | |
568 | } | |
569 | *size = (u32) fw->size; | |
570 | ||
571 | abort_with_fw: | |
572 | release_firmware(fw); | |
573 | ||
574 | abort_with_nothing: | |
575 | return status; | |
576 | } | |
577 | ||
578 | static int myri10ge_adopt_running_firmware(struct myri10ge_priv *mgp) | |
579 | { | |
580 | struct mcp_gen_header *hdr; | |
581 | struct device *dev = &mgp->pdev->dev; | |
582 | const size_t bytes = sizeof(struct mcp_gen_header); | |
583 | size_t hdr_offset; | |
584 | int status; | |
585 | ||
586 | /* find running firmware header */ | |
66341fff | 587 | hdr_offset = swab32(readl(mgp->sram + MCP_HEADER_PTR_OFFSET)); |
0da34b6d BG |
588 | |
589 | if ((hdr_offset & 3) || hdr_offset + sizeof(*hdr) > mgp->sram_size) { | |
590 | dev_err(dev, "Running firmware has bad header offset (%d)\n", | |
591 | (int)hdr_offset); | |
592 | return -EIO; | |
593 | } | |
594 | ||
595 | /* copy header of running firmware from SRAM to host memory to | |
596 | * validate firmware */ | |
597 | hdr = kmalloc(bytes, GFP_KERNEL); | |
598 | if (hdr == NULL) { | |
599 | dev_err(dev, "could not malloc firmware hdr\n"); | |
600 | return -ENOMEM; | |
601 | } | |
602 | memcpy_fromio(hdr, mgp->sram + hdr_offset, bytes); | |
603 | status = myri10ge_validate_firmware(mgp, hdr); | |
604 | kfree(hdr); | |
9dc6f0e7 BG |
605 | |
606 | /* check to see if adopted firmware has bug where adopting | |
607 | * it will cause broadcasts to be filtered unless the NIC | |
608 | * is kept in ALLMULTI mode */ | |
609 | if (mgp->fw_ver_major == 1 && mgp->fw_ver_minor == 4 && | |
610 | mgp->fw_ver_tiny >= 4 && mgp->fw_ver_tiny <= 11) { | |
611 | mgp->adopted_rx_filter_bug = 1; | |
612 | dev_warn(dev, "Adopting fw %d.%d.%d: " | |
613 | "working around rx filter bug\n", | |
614 | mgp->fw_ver_major, mgp->fw_ver_minor, | |
615 | mgp->fw_ver_tiny); | |
616 | } | |
0da34b6d BG |
617 | return status; |
618 | } | |
619 | ||
620 | static int myri10ge_load_firmware(struct myri10ge_priv *mgp) | |
621 | { | |
622 | char __iomem *submit; | |
f8fd57c1 | 623 | __be32 buf[16] __attribute__ ((__aligned__(8))); |
0da34b6d BG |
624 | u32 dma_low, dma_high, size; |
625 | int status, i; | |
4f93fde0 | 626 | struct myri10ge_cmd cmd; |
0da34b6d | 627 | |
b10c0668 | 628 | size = 0; |
0da34b6d BG |
629 | status = myri10ge_load_hotplug_firmware(mgp, &size); |
630 | if (status) { | |
631 | dev_warn(&mgp->pdev->dev, "hotplug firmware loading failed\n"); | |
632 | ||
633 | /* Do not attempt to adopt firmware if there | |
634 | * was a bad crc */ | |
635 | if (status == -EIO) | |
636 | return status; | |
637 | ||
638 | status = myri10ge_adopt_running_firmware(mgp); | |
639 | if (status != 0) { | |
640 | dev_err(&mgp->pdev->dev, | |
641 | "failed to adopt running firmware\n"); | |
642 | return status; | |
643 | } | |
644 | dev_info(&mgp->pdev->dev, | |
645 | "Successfully adopted running firmware\n"); | |
646 | if (mgp->tx.boundary == 4096) { | |
647 | dev_warn(&mgp->pdev->dev, | |
648 | "Using firmware currently running on NIC" | |
649 | ". For optimal\n"); | |
650 | dev_warn(&mgp->pdev->dev, | |
651 | "performance consider loading optimized " | |
652 | "firmware\n"); | |
653 | dev_warn(&mgp->pdev->dev, "via hotplug\n"); | |
654 | } | |
655 | ||
656 | mgp->fw_name = "adopted"; | |
657 | mgp->tx.boundary = 2048; | |
658 | return status; | |
659 | } | |
660 | ||
661 | /* clear confirmation addr */ | |
662 | mgp->cmd->data = 0; | |
663 | mb(); | |
664 | ||
665 | /* send a reload command to the bootstrap MCP, and wait for the | |
666 | * response in the confirmation address. The firmware should | |
667 | * write a -1 there to indicate it is alive and well | |
668 | */ | |
669 | dma_low = MYRI10GE_LOWPART_TO_U32(mgp->cmd_bus); | |
670 | dma_high = MYRI10GE_HIGHPART_TO_U32(mgp->cmd_bus); | |
671 | ||
672 | buf[0] = htonl(dma_high); /* confirm addr MSW */ | |
673 | buf[1] = htonl(dma_low); /* confirm addr LSW */ | |
40f6cff5 | 674 | buf[2] = MYRI10GE_NO_CONFIRM_DATA; /* confirm data */ |
0da34b6d BG |
675 | |
676 | /* FIX: All newest firmware should un-protect the bottom of | |
677 | * the sram before handoff. However, the very first interfaces | |
678 | * do not. Therefore the handoff copy must skip the first 8 bytes | |
679 | */ | |
680 | buf[3] = htonl(MYRI10GE_FW_OFFSET + 8); /* where the code starts */ | |
681 | buf[4] = htonl(size - 8); /* length of code */ | |
682 | buf[5] = htonl(8); /* where to copy to */ | |
683 | buf[6] = htonl(0); /* where to jump to */ | |
684 | ||
e700f9f4 | 685 | submit = mgp->sram + MXGEFW_BOOT_HANDOFF; |
0da34b6d BG |
686 | |
687 | myri10ge_pio_copy(submit, &buf, sizeof(buf)); | |
688 | mb(); | |
689 | msleep(1); | |
690 | mb(); | |
691 | i = 0; | |
d93ca2a4 BG |
692 | while (mgp->cmd->data != MYRI10GE_NO_CONFIRM_DATA && i < 9) { |
693 | msleep(1 << i); | |
0da34b6d BG |
694 | i++; |
695 | } | |
696 | if (mgp->cmd->data != MYRI10GE_NO_CONFIRM_DATA) { | |
697 | dev_err(&mgp->pdev->dev, "handoff failed\n"); | |
698 | return -ENXIO; | |
699 | } | |
700 | dev_info(&mgp->pdev->dev, "handoff confirmed\n"); | |
9a71db72 | 701 | myri10ge_dummy_rdma(mgp, 1); |
0da34b6d | 702 | |
4f93fde0 BG |
703 | /* probe for IPv6 TSO support */ |
704 | mgp->features = NETIF_F_SG | NETIF_F_HW_CSUM | NETIF_F_TSO; | |
705 | status = myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_MAX_TSO6_HDR_SIZE, | |
706 | &cmd, 0); | |
707 | if (status == 0) { | |
708 | mgp->max_tso6 = cmd.data0; | |
709 | mgp->features |= NETIF_F_TSO6; | |
710 | } | |
0da34b6d BG |
711 | return 0; |
712 | } | |
713 | ||
714 | static int myri10ge_update_mac_address(struct myri10ge_priv *mgp, u8 * addr) | |
715 | { | |
716 | struct myri10ge_cmd cmd; | |
717 | int status; | |
718 | ||
719 | cmd.data0 = ((addr[0] << 24) | (addr[1] << 16) | |
720 | | (addr[2] << 8) | addr[3]); | |
721 | ||
722 | cmd.data1 = ((addr[4] << 8) | (addr[5])); | |
723 | ||
724 | status = myri10ge_send_cmd(mgp, MXGEFW_SET_MAC_ADDRESS, &cmd, 0); | |
725 | return status; | |
726 | } | |
727 | ||
728 | static int myri10ge_change_pause(struct myri10ge_priv *mgp, int pause) | |
729 | { | |
730 | struct myri10ge_cmd cmd; | |
731 | int status, ctl; | |
732 | ||
733 | ctl = pause ? MXGEFW_ENABLE_FLOW_CONTROL : MXGEFW_DISABLE_FLOW_CONTROL; | |
734 | status = myri10ge_send_cmd(mgp, ctl, &cmd, 0); | |
735 | ||
736 | if (status) { | |
737 | printk(KERN_ERR | |
738 | "myri10ge: %s: Failed to set flow control mode\n", | |
739 | mgp->dev->name); | |
740 | return status; | |
741 | } | |
742 | mgp->pause = pause; | |
743 | return 0; | |
744 | } | |
745 | ||
746 | static void | |
747 | myri10ge_change_promisc(struct myri10ge_priv *mgp, int promisc, int atomic) | |
748 | { | |
749 | struct myri10ge_cmd cmd; | |
750 | int status, ctl; | |
751 | ||
752 | ctl = promisc ? MXGEFW_ENABLE_PROMISC : MXGEFW_DISABLE_PROMISC; | |
753 | status = myri10ge_send_cmd(mgp, ctl, &cmd, atomic); | |
754 | if (status) | |
755 | printk(KERN_ERR "myri10ge: %s: Failed to set promisc mode\n", | |
756 | mgp->dev->name); | |
757 | } | |
758 | ||
0d6ac257 | 759 | static int myri10ge_dma_test(struct myri10ge_priv *mgp, int test_type) |
0da34b6d BG |
760 | { |
761 | struct myri10ge_cmd cmd; | |
762 | int status; | |
0da34b6d | 763 | u32 len; |
34fdccea BG |
764 | struct page *dmatest_page; |
765 | dma_addr_t dmatest_bus; | |
0d6ac257 BG |
766 | char *test = " "; |
767 | ||
768 | dmatest_page = alloc_page(GFP_KERNEL); | |
769 | if (!dmatest_page) | |
770 | return -ENOMEM; | |
771 | dmatest_bus = pci_map_page(mgp->pdev, dmatest_page, 0, PAGE_SIZE, | |
772 | DMA_BIDIRECTIONAL); | |
773 | ||
774 | /* Run a small DMA test. | |
775 | * The magic multipliers to the length tell the firmware | |
776 | * to do DMA read, write, or read+write tests. The | |
777 | * results are returned in cmd.data0. The upper 16 | |
778 | * bits or the return is the number of transfers completed. | |
779 | * The lower 16 bits is the time in 0.5us ticks that the | |
780 | * transfers took to complete. | |
781 | */ | |
782 | ||
783 | len = mgp->tx.boundary; | |
784 | ||
785 | cmd.data0 = MYRI10GE_LOWPART_TO_U32(dmatest_bus); | |
786 | cmd.data1 = MYRI10GE_HIGHPART_TO_U32(dmatest_bus); | |
787 | cmd.data2 = len * 0x10000; | |
788 | status = myri10ge_send_cmd(mgp, test_type, &cmd, 0); | |
789 | if (status != 0) { | |
790 | test = "read"; | |
791 | goto abort; | |
792 | } | |
793 | mgp->read_dma = ((cmd.data0 >> 16) * len * 2) / (cmd.data0 & 0xffff); | |
794 | cmd.data0 = MYRI10GE_LOWPART_TO_U32(dmatest_bus); | |
795 | cmd.data1 = MYRI10GE_HIGHPART_TO_U32(dmatest_bus); | |
796 | cmd.data2 = len * 0x1; | |
797 | status = myri10ge_send_cmd(mgp, test_type, &cmd, 0); | |
798 | if (status != 0) { | |
799 | test = "write"; | |
800 | goto abort; | |
801 | } | |
802 | mgp->write_dma = ((cmd.data0 >> 16) * len * 2) / (cmd.data0 & 0xffff); | |
803 | ||
804 | cmd.data0 = MYRI10GE_LOWPART_TO_U32(dmatest_bus); | |
805 | cmd.data1 = MYRI10GE_HIGHPART_TO_U32(dmatest_bus); | |
806 | cmd.data2 = len * 0x10001; | |
807 | status = myri10ge_send_cmd(mgp, test_type, &cmd, 0); | |
808 | if (status != 0) { | |
809 | test = "read/write"; | |
810 | goto abort; | |
811 | } | |
812 | mgp->read_write_dma = ((cmd.data0 >> 16) * len * 2 * 2) / | |
813 | (cmd.data0 & 0xffff); | |
814 | ||
815 | abort: | |
816 | pci_unmap_page(mgp->pdev, dmatest_bus, PAGE_SIZE, DMA_BIDIRECTIONAL); | |
817 | put_page(dmatest_page); | |
818 | ||
819 | if (status != 0 && test_type != MXGEFW_CMD_UNALIGNED_TEST) | |
820 | dev_warn(&mgp->pdev->dev, "DMA %s benchmark failed: %d\n", | |
821 | test, status); | |
822 | ||
823 | return status; | |
824 | } | |
825 | ||
826 | static int myri10ge_reset(struct myri10ge_priv *mgp) | |
827 | { | |
828 | struct myri10ge_cmd cmd; | |
829 | int status; | |
830 | size_t bytes; | |
0da34b6d BG |
831 | |
832 | /* try to send a reset command to the card to see if it | |
833 | * is alive */ | |
834 | memset(&cmd, 0, sizeof(cmd)); | |
835 | status = myri10ge_send_cmd(mgp, MXGEFW_CMD_RESET, &cmd, 0); | |
836 | if (status != 0) { | |
837 | dev_err(&mgp->pdev->dev, "failed reset\n"); | |
838 | return -ENXIO; | |
839 | } | |
0d6ac257 BG |
840 | |
841 | (void)myri10ge_dma_test(mgp, MXGEFW_DMA_TEST); | |
0da34b6d BG |
842 | |
843 | /* Now exchange information about interrupts */ | |
844 | ||
845 | bytes = myri10ge_max_intr_slots * sizeof(*mgp->rx_done.entry); | |
846 | memset(mgp->rx_done.entry, 0, bytes); | |
847 | cmd.data0 = (u32) bytes; | |
848 | status = myri10ge_send_cmd(mgp, MXGEFW_CMD_SET_INTRQ_SIZE, &cmd, 0); | |
849 | cmd.data0 = MYRI10GE_LOWPART_TO_U32(mgp->rx_done.bus); | |
850 | cmd.data1 = MYRI10GE_HIGHPART_TO_U32(mgp->rx_done.bus); | |
851 | status |= myri10ge_send_cmd(mgp, MXGEFW_CMD_SET_INTRQ_DMA, &cmd, 0); | |
852 | ||
853 | status |= | |
854 | myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_IRQ_ACK_OFFSET, &cmd, 0); | |
40f6cff5 | 855 | mgp->irq_claim = (__iomem __be32 *) (mgp->sram + cmd.data0); |
df30a740 BG |
856 | status |= myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_IRQ_DEASSERT_OFFSET, |
857 | &cmd, 0); | |
858 | mgp->irq_deassert = (__iomem __be32 *) (mgp->sram + cmd.data0); | |
0da34b6d | 859 | |
0da34b6d BG |
860 | status |= myri10ge_send_cmd |
861 | (mgp, MXGEFW_CMD_GET_INTR_COAL_DELAY_OFFSET, &cmd, 0); | |
40f6cff5 | 862 | mgp->intr_coal_delay_ptr = (__iomem __be32 *) (mgp->sram + cmd.data0); |
0da34b6d BG |
863 | if (status != 0) { |
864 | dev_err(&mgp->pdev->dev, "failed set interrupt parameters\n"); | |
865 | return status; | |
866 | } | |
40f6cff5 | 867 | put_be32(htonl(mgp->intr_coal_delay), mgp->intr_coal_delay_ptr); |
0da34b6d | 868 | |
0da34b6d BG |
869 | memset(mgp->rx_done.entry, 0, bytes); |
870 | ||
871 | /* reset mcp/driver shared state back to 0 */ | |
872 | mgp->tx.req = 0; | |
873 | mgp->tx.done = 0; | |
874 | mgp->tx.pkt_start = 0; | |
875 | mgp->tx.pkt_done = 0; | |
876 | mgp->rx_big.cnt = 0; | |
877 | mgp->rx_small.cnt = 0; | |
878 | mgp->rx_done.idx = 0; | |
879 | mgp->rx_done.cnt = 0; | |
c58ac5ca | 880 | mgp->link_changes = 0; |
0da34b6d | 881 | status = myri10ge_update_mac_address(mgp, mgp->dev->dev_addr); |
0da34b6d | 882 | myri10ge_change_pause(mgp, mgp->pause); |
2f76216f | 883 | myri10ge_set_multicast_list(mgp->dev); |
0da34b6d BG |
884 | return status; |
885 | } | |
886 | ||
887 | static inline void | |
888 | myri10ge_submit_8rx(struct mcp_kreq_ether_recv __iomem * dst, | |
889 | struct mcp_kreq_ether_recv *src) | |
890 | { | |
40f6cff5 | 891 | __be32 low; |
0da34b6d BG |
892 | |
893 | low = src->addr_low; | |
40f6cff5 | 894 | src->addr_low = htonl(DMA_32BIT_MASK); |
e67bda55 BG |
895 | myri10ge_pio_copy(dst, src, 4 * sizeof(*src)); |
896 | mb(); | |
897 | myri10ge_pio_copy(dst + 4, src + 4, 4 * sizeof(*src)); | |
0da34b6d BG |
898 | mb(); |
899 | src->addr_low = low; | |
40f6cff5 | 900 | put_be32(low, &dst->addr_low); |
0da34b6d BG |
901 | mb(); |
902 | } | |
903 | ||
40f6cff5 | 904 | static inline void myri10ge_vlan_ip_csum(struct sk_buff *skb, __wsum hw_csum) |
0da34b6d BG |
905 | { |
906 | struct vlan_hdr *vh = (struct vlan_hdr *)(skb->data); | |
907 | ||
40f6cff5 | 908 | if ((skb->protocol == htons(ETH_P_8021Q)) && |
0da34b6d BG |
909 | (vh->h_vlan_encapsulated_proto == htons(ETH_P_IP) || |
910 | vh->h_vlan_encapsulated_proto == htons(ETH_P_IPV6))) { | |
911 | skb->csum = hw_csum; | |
84fa7933 | 912 | skb->ip_summed = CHECKSUM_COMPLETE; |
0da34b6d BG |
913 | } |
914 | } | |
915 | ||
dd50f336 BG |
916 | static inline void |
917 | myri10ge_rx_skb_build(struct sk_buff *skb, u8 * va, | |
918 | struct skb_frag_struct *rx_frags, int len, int hlen) | |
919 | { | |
920 | struct skb_frag_struct *skb_frags; | |
921 | ||
922 | skb->len = skb->data_len = len; | |
923 | skb->truesize = len + sizeof(struct sk_buff); | |
924 | /* attach the page(s) */ | |
925 | ||
926 | skb_frags = skb_shinfo(skb)->frags; | |
927 | while (len > 0) { | |
928 | memcpy(skb_frags, rx_frags, sizeof(*skb_frags)); | |
929 | len -= rx_frags->size; | |
930 | skb_frags++; | |
931 | rx_frags++; | |
932 | skb_shinfo(skb)->nr_frags++; | |
933 | } | |
934 | ||
935 | /* pskb_may_pull is not available in irq context, but | |
936 | * skb_pull() (for ether_pad and eth_type_trans()) requires | |
937 | * the beginning of the packet in skb_headlen(), move it | |
938 | * manually */ | |
27d7ff46 | 939 | skb_copy_to_linear_data(skb, va, hlen); |
dd50f336 BG |
940 | skb_shinfo(skb)->frags[0].page_offset += hlen; |
941 | skb_shinfo(skb)->frags[0].size -= hlen; | |
942 | skb->data_len -= hlen; | |
943 | skb->tail += hlen; | |
944 | skb_pull(skb, MXGEFW_PAD); | |
945 | } | |
946 | ||
947 | static void | |
948 | myri10ge_alloc_rx_pages(struct myri10ge_priv *mgp, struct myri10ge_rx_buf *rx, | |
949 | int bytes, int watchdog) | |
950 | { | |
951 | struct page *page; | |
952 | int idx; | |
953 | ||
954 | if (unlikely(rx->watchdog_needed && !watchdog)) | |
955 | return; | |
956 | ||
957 | /* try to refill entire ring */ | |
958 | while (rx->fill_cnt != (rx->cnt + rx->mask + 1)) { | |
959 | idx = rx->fill_cnt & rx->mask; | |
ae8509b1 | 960 | if (rx->page_offset + bytes <= MYRI10GE_ALLOC_SIZE) { |
dd50f336 BG |
961 | /* we can use part of previous page */ |
962 | get_page(rx->page); | |
963 | } else { | |
964 | /* we need a new page */ | |
965 | page = | |
966 | alloc_pages(GFP_ATOMIC | __GFP_COMP, | |
967 | MYRI10GE_ALLOC_ORDER); | |
968 | if (unlikely(page == NULL)) { | |
969 | if (rx->fill_cnt - rx->cnt < 16) | |
970 | rx->watchdog_needed = 1; | |
971 | return; | |
972 | } | |
973 | rx->page = page; | |
974 | rx->page_offset = 0; | |
975 | rx->bus = pci_map_page(mgp->pdev, page, 0, | |
976 | MYRI10GE_ALLOC_SIZE, | |
977 | PCI_DMA_FROMDEVICE); | |
978 | } | |
979 | rx->info[idx].page = rx->page; | |
980 | rx->info[idx].page_offset = rx->page_offset; | |
981 | /* note that this is the address of the start of the | |
982 | * page */ | |
983 | pci_unmap_addr_set(&rx->info[idx], bus, rx->bus); | |
984 | rx->shadow[idx].addr_low = | |
985 | htonl(MYRI10GE_LOWPART_TO_U32(rx->bus) + rx->page_offset); | |
986 | rx->shadow[idx].addr_high = | |
987 | htonl(MYRI10GE_HIGHPART_TO_U32(rx->bus)); | |
988 | ||
989 | /* start next packet on a cacheline boundary */ | |
990 | rx->page_offset += SKB_DATA_ALIGN(bytes); | |
ae8509b1 BG |
991 | |
992 | #if MYRI10GE_ALLOC_SIZE > 4096 | |
993 | /* don't cross a 4KB boundary */ | |
994 | if ((rx->page_offset >> 12) != | |
995 | ((rx->page_offset + bytes - 1) >> 12)) | |
996 | rx->page_offset = (rx->page_offset + 4096) & ~4095; | |
997 | #endif | |
dd50f336 BG |
998 | rx->fill_cnt++; |
999 | ||
1000 | /* copy 8 descriptors to the firmware at a time */ | |
1001 | if ((idx & 7) == 7) { | |
1002 | if (rx->wc_fifo == NULL) | |
1003 | myri10ge_submit_8rx(&rx->lanai[idx - 7], | |
1004 | &rx->shadow[idx - 7]); | |
1005 | else { | |
1006 | mb(); | |
1007 | myri10ge_pio_copy(rx->wc_fifo, | |
1008 | &rx->shadow[idx - 7], 64); | |
1009 | } | |
1010 | } | |
1011 | } | |
1012 | } | |
1013 | ||
1014 | static inline void | |
1015 | myri10ge_unmap_rx_page(struct pci_dev *pdev, | |
1016 | struct myri10ge_rx_buffer_state *info, int bytes) | |
1017 | { | |
1018 | /* unmap the recvd page if we're the only or last user of it */ | |
1019 | if (bytes >= MYRI10GE_ALLOC_SIZE / 2 || | |
1020 | (info->page_offset + 2 * bytes) > MYRI10GE_ALLOC_SIZE) { | |
1021 | pci_unmap_page(pdev, (pci_unmap_addr(info, bus) | |
1022 | & ~(MYRI10GE_ALLOC_SIZE - 1)), | |
1023 | MYRI10GE_ALLOC_SIZE, PCI_DMA_FROMDEVICE); | |
1024 | } | |
1025 | } | |
1026 | ||
1027 | #define MYRI10GE_HLEN 64 /* The number of bytes to copy from a | |
1028 | * page into an skb */ | |
1029 | ||
1030 | static inline int | |
52ea6fb3 BG |
1031 | myri10ge_rx_done(struct myri10ge_priv *mgp, struct myri10ge_rx_buf *rx, |
1032 | int bytes, int len, __wsum csum) | |
dd50f336 BG |
1033 | { |
1034 | struct sk_buff *skb; | |
1035 | struct skb_frag_struct rx_frags[MYRI10GE_MAX_FRAGS_PER_FRAME]; | |
1036 | int i, idx, hlen, remainder; | |
1037 | struct pci_dev *pdev = mgp->pdev; | |
1038 | struct net_device *dev = mgp->dev; | |
1039 | u8 *va; | |
1040 | ||
1041 | len += MXGEFW_PAD; | |
1042 | idx = rx->cnt & rx->mask; | |
1043 | va = page_address(rx->info[idx].page) + rx->info[idx].page_offset; | |
1044 | prefetch(va); | |
1045 | /* Fill skb_frag_struct(s) with data from our receive */ | |
1046 | for (i = 0, remainder = len; remainder > 0; i++) { | |
1047 | myri10ge_unmap_rx_page(pdev, &rx->info[idx], bytes); | |
1048 | rx_frags[i].page = rx->info[idx].page; | |
1049 | rx_frags[i].page_offset = rx->info[idx].page_offset; | |
1050 | if (remainder < MYRI10GE_ALLOC_SIZE) | |
1051 | rx_frags[i].size = remainder; | |
1052 | else | |
1053 | rx_frags[i].size = MYRI10GE_ALLOC_SIZE; | |
1054 | rx->cnt++; | |
1055 | idx = rx->cnt & rx->mask; | |
1056 | remainder -= MYRI10GE_ALLOC_SIZE; | |
1057 | } | |
1058 | ||
1e6e9342 AG |
1059 | if (mgp->csum_flag && myri10ge_lro) { |
1060 | rx_frags[0].page_offset += MXGEFW_PAD; | |
1061 | rx_frags[0].size -= MXGEFW_PAD; | |
1062 | len -= MXGEFW_PAD; | |
1063 | lro_receive_frags(&mgp->rx_done.lro_mgr, rx_frags, | |
66341fff AV |
1064 | len, len, |
1065 | /* opaque, will come back in get_frag_header */ | |
1066 | (void *)(__force unsigned long)csum, | |
1067 | csum); | |
1e6e9342 AG |
1068 | return 1; |
1069 | } | |
1070 | ||
dd50f336 BG |
1071 | hlen = MYRI10GE_HLEN > len ? len : MYRI10GE_HLEN; |
1072 | ||
e636b2ea BG |
1073 | /* allocate an skb to attach the page(s) to. This is done |
1074 | * after trying LRO, so as to avoid skb allocation overheads */ | |
dd50f336 BG |
1075 | |
1076 | skb = netdev_alloc_skb(dev, MYRI10GE_HLEN + 16); | |
1077 | if (unlikely(skb == NULL)) { | |
1078 | mgp->stats.rx_dropped++; | |
1079 | do { | |
1080 | i--; | |
1081 | put_page(rx_frags[i].page); | |
1082 | } while (i != 0); | |
1083 | return 0; | |
1084 | } | |
1085 | ||
1086 | /* Attach the pages to the skb, and trim off any padding */ | |
1087 | myri10ge_rx_skb_build(skb, va, rx_frags, len, hlen); | |
1088 | if (skb_shinfo(skb)->frags[0].size <= 0) { | |
1089 | put_page(skb_shinfo(skb)->frags[0].page); | |
1090 | skb_shinfo(skb)->nr_frags = 0; | |
1091 | } | |
1092 | skb->protocol = eth_type_trans(skb, dev); | |
dd50f336 BG |
1093 | |
1094 | if (mgp->csum_flag) { | |
1095 | if ((skb->protocol == htons(ETH_P_IP)) || | |
1096 | (skb->protocol == htons(ETH_P_IPV6))) { | |
1097 | skb->csum = csum; | |
1098 | skb->ip_summed = CHECKSUM_COMPLETE; | |
1099 | } else | |
1100 | myri10ge_vlan_ip_csum(skb, csum); | |
1101 | } | |
1102 | netif_receive_skb(skb); | |
1103 | dev->last_rx = jiffies; | |
1104 | return 1; | |
1105 | } | |
1106 | ||
0da34b6d BG |
1107 | static inline void myri10ge_tx_done(struct myri10ge_priv *mgp, int mcp_index) |
1108 | { | |
1109 | struct pci_dev *pdev = mgp->pdev; | |
1110 | struct myri10ge_tx_buf *tx = &mgp->tx; | |
1111 | struct sk_buff *skb; | |
1112 | int idx, len; | |
0da34b6d BG |
1113 | |
1114 | while (tx->pkt_done != mcp_index) { | |
1115 | idx = tx->done & tx->mask; | |
1116 | skb = tx->info[idx].skb; | |
1117 | ||
1118 | /* Mark as free */ | |
1119 | tx->info[idx].skb = NULL; | |
1120 | if (tx->info[idx].last) { | |
1121 | tx->pkt_done++; | |
1122 | tx->info[idx].last = 0; | |
1123 | } | |
1124 | tx->done++; | |
1125 | len = pci_unmap_len(&tx->info[idx], len); | |
1126 | pci_unmap_len_set(&tx->info[idx], len, 0); | |
1127 | if (skb) { | |
1128 | mgp->stats.tx_bytes += skb->len; | |
1129 | mgp->stats.tx_packets++; | |
1130 | dev_kfree_skb_irq(skb); | |
1131 | if (len) | |
1132 | pci_unmap_single(pdev, | |
1133 | pci_unmap_addr(&tx->info[idx], | |
1134 | bus), len, | |
1135 | PCI_DMA_TODEVICE); | |
1136 | } else { | |
1137 | if (len) | |
1138 | pci_unmap_page(pdev, | |
1139 | pci_unmap_addr(&tx->info[idx], | |
1140 | bus), len, | |
1141 | PCI_DMA_TODEVICE); | |
1142 | } | |
0da34b6d BG |
1143 | } |
1144 | /* start the queue if we've stopped it */ | |
1145 | if (netif_queue_stopped(mgp->dev) | |
1146 | && tx->req - tx->done < (tx->mask >> 1)) { | |
1147 | mgp->wake_queue++; | |
1148 | netif_wake_queue(mgp->dev); | |
1149 | } | |
1150 | } | |
1151 | ||
bea3348e | 1152 | static inline int myri10ge_clean_rx_done(struct myri10ge_priv *mgp, int budget) |
0da34b6d BG |
1153 | { |
1154 | struct myri10ge_rx_done *rx_done = &mgp->rx_done; | |
1155 | unsigned long rx_bytes = 0; | |
1156 | unsigned long rx_packets = 0; | |
1157 | unsigned long rx_ok; | |
1158 | ||
1159 | int idx = rx_done->idx; | |
1160 | int cnt = rx_done->cnt; | |
bea3348e | 1161 | int work_done = 0; |
0da34b6d | 1162 | u16 length; |
40f6cff5 | 1163 | __wsum checksum; |
0da34b6d | 1164 | |
c956a240 | 1165 | while (rx_done->entry[idx].length != 0 && work_done < budget) { |
0da34b6d BG |
1166 | length = ntohs(rx_done->entry[idx].length); |
1167 | rx_done->entry[idx].length = 0; | |
40f6cff5 | 1168 | checksum = csum_unfold(rx_done->entry[idx].checksum); |
0da34b6d | 1169 | if (length <= mgp->small_bytes) |
52ea6fb3 BG |
1170 | rx_ok = myri10ge_rx_done(mgp, &mgp->rx_small, |
1171 | mgp->small_bytes, | |
1172 | length, checksum); | |
0da34b6d | 1173 | else |
52ea6fb3 BG |
1174 | rx_ok = myri10ge_rx_done(mgp, &mgp->rx_big, |
1175 | mgp->big_bytes, | |
1176 | length, checksum); | |
0da34b6d BG |
1177 | rx_packets += rx_ok; |
1178 | rx_bytes += rx_ok * (unsigned long)length; | |
1179 | cnt++; | |
1180 | idx = cnt & (myri10ge_max_intr_slots - 1); | |
c956a240 | 1181 | work_done++; |
0da34b6d BG |
1182 | } |
1183 | rx_done->idx = idx; | |
1184 | rx_done->cnt = cnt; | |
1185 | mgp->stats.rx_packets += rx_packets; | |
1186 | mgp->stats.rx_bytes += rx_bytes; | |
c7dab99b | 1187 | |
1e6e9342 AG |
1188 | if (myri10ge_lro) |
1189 | lro_flush_all(&rx_done->lro_mgr); | |
1190 | ||
c7dab99b BG |
1191 | /* restock receive rings if needed */ |
1192 | if (mgp->rx_small.fill_cnt - mgp->rx_small.cnt < myri10ge_fill_thresh) | |
1193 | myri10ge_alloc_rx_pages(mgp, &mgp->rx_small, | |
1194 | mgp->small_bytes + MXGEFW_PAD, 0); | |
1195 | if (mgp->rx_big.fill_cnt - mgp->rx_big.cnt < myri10ge_fill_thresh) | |
1196 | myri10ge_alloc_rx_pages(mgp, &mgp->rx_big, mgp->big_bytes, 0); | |
1197 | ||
bea3348e | 1198 | return work_done; |
0da34b6d BG |
1199 | } |
1200 | ||
1201 | static inline void myri10ge_check_statblock(struct myri10ge_priv *mgp) | |
1202 | { | |
1203 | struct mcp_irq_data *stats = mgp->fw_stats; | |
1204 | ||
1205 | if (unlikely(stats->stats_updated)) { | |
798a95db BG |
1206 | unsigned link_up = ntohl(stats->link_up); |
1207 | if (mgp->link_state != link_up) { | |
1208 | mgp->link_state = link_up; | |
1209 | ||
1210 | if (mgp->link_state == MXGEFW_LINK_UP) { | |
c58ac5ca BG |
1211 | if (netif_msg_link(mgp)) |
1212 | printk(KERN_INFO | |
1213 | "myri10ge: %s: link up\n", | |
1214 | mgp->dev->name); | |
0da34b6d | 1215 | netif_carrier_on(mgp->dev); |
c58ac5ca | 1216 | mgp->link_changes++; |
0da34b6d | 1217 | } else { |
c58ac5ca BG |
1218 | if (netif_msg_link(mgp)) |
1219 | printk(KERN_INFO | |
798a95db BG |
1220 | "myri10ge: %s: link %s\n", |
1221 | mgp->dev->name, | |
1222 | (link_up == MXGEFW_LINK_MYRINET ? | |
1223 | "mismatch (Myrinet detected)" : | |
1224 | "down")); | |
0da34b6d | 1225 | netif_carrier_off(mgp->dev); |
c58ac5ca | 1226 | mgp->link_changes++; |
0da34b6d BG |
1227 | } |
1228 | } | |
1229 | if (mgp->rdma_tags_available != | |
1230 | ntohl(mgp->fw_stats->rdma_tags_available)) { | |
1231 | mgp->rdma_tags_available = | |
1232 | ntohl(mgp->fw_stats->rdma_tags_available); | |
1233 | printk(KERN_WARNING "myri10ge: %s: RDMA timed out! " | |
1234 | "%d tags left\n", mgp->dev->name, | |
1235 | mgp->rdma_tags_available); | |
1236 | } | |
1237 | mgp->down_cnt += stats->link_down; | |
1238 | if (stats->link_down) | |
1239 | wake_up(&mgp->down_wq); | |
1240 | } | |
1241 | } | |
1242 | ||
bea3348e | 1243 | static int myri10ge_poll(struct napi_struct *napi, int budget) |
0da34b6d | 1244 | { |
e636b2ea BG |
1245 | struct myri10ge_priv *mgp = |
1246 | container_of(napi, struct myri10ge_priv, napi); | |
bea3348e | 1247 | struct net_device *netdev = mgp->dev; |
bea3348e | 1248 | int work_done; |
0da34b6d BG |
1249 | |
1250 | /* process as many rx events as NAPI will allow */ | |
bea3348e | 1251 | work_done = myri10ge_clean_rx_done(mgp, budget); |
0da34b6d | 1252 | |
4ec24119 | 1253 | if (work_done < budget) { |
bea3348e | 1254 | netif_rx_complete(netdev, napi); |
40f6cff5 | 1255 | put_be32(htonl(3), mgp->irq_claim); |
0da34b6d | 1256 | } |
bea3348e | 1257 | return work_done; |
0da34b6d BG |
1258 | } |
1259 | ||
7d12e780 | 1260 | static irqreturn_t myri10ge_intr(int irq, void *arg) |
0da34b6d BG |
1261 | { |
1262 | struct myri10ge_priv *mgp = arg; | |
1263 | struct mcp_irq_data *stats = mgp->fw_stats; | |
1264 | struct myri10ge_tx_buf *tx = &mgp->tx; | |
1265 | u32 send_done_count; | |
1266 | int i; | |
1267 | ||
1268 | /* make sure it is our IRQ, and that the DMA has finished */ | |
1269 | if (unlikely(!stats->valid)) | |
1270 | return (IRQ_NONE); | |
1271 | ||
1272 | /* low bit indicates receives are present, so schedule | |
1273 | * napi poll handler */ | |
1274 | if (stats->valid & 1) | |
bea3348e | 1275 | netif_rx_schedule(mgp->dev, &mgp->napi); |
0da34b6d BG |
1276 | |
1277 | if (!mgp->msi_enabled) { | |
40f6cff5 | 1278 | put_be32(0, mgp->irq_deassert); |
0da34b6d BG |
1279 | if (!myri10ge_deassert_wait) |
1280 | stats->valid = 0; | |
1281 | mb(); | |
1282 | } else | |
1283 | stats->valid = 0; | |
1284 | ||
1285 | /* Wait for IRQ line to go low, if using INTx */ | |
1286 | i = 0; | |
1287 | while (1) { | |
1288 | i++; | |
1289 | /* check for transmit completes and receives */ | |
1290 | send_done_count = ntohl(stats->send_done_count); | |
1291 | if (send_done_count != tx->pkt_done) | |
1292 | myri10ge_tx_done(mgp, (int)send_done_count); | |
1293 | if (unlikely(i > myri10ge_max_irq_loops)) { | |
1294 | printk(KERN_WARNING "myri10ge: %s: irq stuck?\n", | |
1295 | mgp->dev->name); | |
1296 | stats->valid = 0; | |
1297 | schedule_work(&mgp->watchdog_work); | |
1298 | } | |
1299 | if (likely(stats->valid == 0)) | |
1300 | break; | |
1301 | cpu_relax(); | |
1302 | barrier(); | |
1303 | } | |
1304 | ||
1305 | myri10ge_check_statblock(mgp); | |
1306 | ||
40f6cff5 | 1307 | put_be32(htonl(3), mgp->irq_claim + 1); |
0da34b6d BG |
1308 | return (IRQ_HANDLED); |
1309 | } | |
1310 | ||
1311 | static int | |
1312 | myri10ge_get_settings(struct net_device *netdev, struct ethtool_cmd *cmd) | |
1313 | { | |
c0bf8801 BG |
1314 | struct myri10ge_priv *mgp = netdev_priv(netdev); |
1315 | char *ptr; | |
1316 | int i; | |
1317 | ||
0da34b6d BG |
1318 | cmd->autoneg = AUTONEG_DISABLE; |
1319 | cmd->speed = SPEED_10000; | |
1320 | cmd->duplex = DUPLEX_FULL; | |
c0bf8801 BG |
1321 | |
1322 | /* | |
1323 | * parse the product code to deterimine the interface type | |
1324 | * (CX4, XFP, Quad Ribbon Fiber) by looking at the character | |
1325 | * after the 3rd dash in the driver's cached copy of the | |
1326 | * EEPROM's product code string. | |
1327 | */ | |
1328 | ptr = mgp->product_code_string; | |
1329 | if (ptr == NULL) { | |
1330 | printk(KERN_ERR "myri10ge: %s: Missing product code\n", | |
99f5f87e | 1331 | netdev->name); |
c0bf8801 BG |
1332 | return 0; |
1333 | } | |
1334 | for (i = 0; i < 3; i++, ptr++) { | |
1335 | ptr = strchr(ptr, '-'); | |
1336 | if (ptr == NULL) { | |
1337 | printk(KERN_ERR "myri10ge: %s: Invalid product " | |
1338 | "code %s\n", netdev->name, | |
1339 | mgp->product_code_string); | |
1340 | return 0; | |
1341 | } | |
1342 | } | |
1343 | if (*ptr == 'R' || *ptr == 'Q') { | |
1344 | /* We've found either an XFP or quad ribbon fiber */ | |
1345 | cmd->port = PORT_FIBRE; | |
1346 | } | |
0da34b6d BG |
1347 | return 0; |
1348 | } | |
1349 | ||
1350 | static void | |
1351 | myri10ge_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *info) | |
1352 | { | |
1353 | struct myri10ge_priv *mgp = netdev_priv(netdev); | |
1354 | ||
1355 | strlcpy(info->driver, "myri10ge", sizeof(info->driver)); | |
1356 | strlcpy(info->version, MYRI10GE_VERSION_STR, sizeof(info->version)); | |
1357 | strlcpy(info->fw_version, mgp->fw_version, sizeof(info->fw_version)); | |
1358 | strlcpy(info->bus_info, pci_name(mgp->pdev), sizeof(info->bus_info)); | |
1359 | } | |
1360 | ||
1361 | static int | |
1362 | myri10ge_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *coal) | |
1363 | { | |
1364 | struct myri10ge_priv *mgp = netdev_priv(netdev); | |
99f5f87e | 1365 | |
0da34b6d BG |
1366 | coal->rx_coalesce_usecs = mgp->intr_coal_delay; |
1367 | return 0; | |
1368 | } | |
1369 | ||
1370 | static int | |
1371 | myri10ge_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *coal) | |
1372 | { | |
1373 | struct myri10ge_priv *mgp = netdev_priv(netdev); | |
1374 | ||
1375 | mgp->intr_coal_delay = coal->rx_coalesce_usecs; | |
40f6cff5 | 1376 | put_be32(htonl(mgp->intr_coal_delay), mgp->intr_coal_delay_ptr); |
0da34b6d BG |
1377 | return 0; |
1378 | } | |
1379 | ||
1380 | static void | |
1381 | myri10ge_get_pauseparam(struct net_device *netdev, | |
1382 | struct ethtool_pauseparam *pause) | |
1383 | { | |
1384 | struct myri10ge_priv *mgp = netdev_priv(netdev); | |
1385 | ||
1386 | pause->autoneg = 0; | |
1387 | pause->rx_pause = mgp->pause; | |
1388 | pause->tx_pause = mgp->pause; | |
1389 | } | |
1390 | ||
1391 | static int | |
1392 | myri10ge_set_pauseparam(struct net_device *netdev, | |
1393 | struct ethtool_pauseparam *pause) | |
1394 | { | |
1395 | struct myri10ge_priv *mgp = netdev_priv(netdev); | |
1396 | ||
1397 | if (pause->tx_pause != mgp->pause) | |
1398 | return myri10ge_change_pause(mgp, pause->tx_pause); | |
1399 | if (pause->rx_pause != mgp->pause) | |
1400 | return myri10ge_change_pause(mgp, pause->tx_pause); | |
1401 | if (pause->autoneg != 0) | |
1402 | return -EINVAL; | |
1403 | return 0; | |
1404 | } | |
1405 | ||
1406 | static void | |
1407 | myri10ge_get_ringparam(struct net_device *netdev, | |
1408 | struct ethtool_ringparam *ring) | |
1409 | { | |
1410 | struct myri10ge_priv *mgp = netdev_priv(netdev); | |
1411 | ||
1412 | ring->rx_mini_max_pending = mgp->rx_small.mask + 1; | |
1413 | ring->rx_max_pending = mgp->rx_big.mask + 1; | |
1414 | ring->rx_jumbo_max_pending = 0; | |
1415 | ring->tx_max_pending = mgp->rx_small.mask + 1; | |
1416 | ring->rx_mini_pending = ring->rx_mini_max_pending; | |
1417 | ring->rx_pending = ring->rx_max_pending; | |
1418 | ring->rx_jumbo_pending = ring->rx_jumbo_max_pending; | |
1419 | ring->tx_pending = ring->tx_max_pending; | |
1420 | } | |
1421 | ||
1422 | static u32 myri10ge_get_rx_csum(struct net_device *netdev) | |
1423 | { | |
1424 | struct myri10ge_priv *mgp = netdev_priv(netdev); | |
99f5f87e | 1425 | |
0da34b6d BG |
1426 | if (mgp->csum_flag) |
1427 | return 1; | |
1428 | else | |
1429 | return 0; | |
1430 | } | |
1431 | ||
1432 | static int myri10ge_set_rx_csum(struct net_device *netdev, u32 csum_enabled) | |
1433 | { | |
1434 | struct myri10ge_priv *mgp = netdev_priv(netdev); | |
99f5f87e | 1435 | |
0da34b6d BG |
1436 | if (csum_enabled) |
1437 | mgp->csum_flag = MXGEFW_FLAGS_CKSUM; | |
1438 | else | |
1439 | mgp->csum_flag = 0; | |
1440 | return 0; | |
1441 | } | |
1442 | ||
4f93fde0 BG |
1443 | static int myri10ge_set_tso(struct net_device *netdev, u32 tso_enabled) |
1444 | { | |
1445 | struct myri10ge_priv *mgp = netdev_priv(netdev); | |
1446 | unsigned long flags = mgp->features & (NETIF_F_TSO6 | NETIF_F_TSO); | |
1447 | ||
1448 | if (tso_enabled) | |
1449 | netdev->features |= flags; | |
1450 | else | |
1451 | netdev->features &= ~flags; | |
1452 | return 0; | |
1453 | } | |
1454 | ||
0da34b6d BG |
1455 | static const char myri10ge_gstrings_stats[][ETH_GSTRING_LEN] = { |
1456 | "rx_packets", "tx_packets", "rx_bytes", "tx_bytes", "rx_errors", | |
1457 | "tx_errors", "rx_dropped", "tx_dropped", "multicast", "collisions", | |
1458 | "rx_length_errors", "rx_over_errors", "rx_crc_errors", | |
1459 | "rx_frame_errors", "rx_fifo_errors", "rx_missed_errors", | |
1460 | "tx_aborted_errors", "tx_carrier_errors", "tx_fifo_errors", | |
1461 | "tx_heartbeat_errors", "tx_window_errors", | |
1462 | /* device-specific stats */ | |
2c1a1088 | 1463 | "tx_boundary", "WC", "irq", "MSI", |
0da34b6d BG |
1464 | "read_dma_bw_MBs", "write_dma_bw_MBs", "read_write_dma_bw_MBs", |
1465 | "serial_number", "tx_pkt_start", "tx_pkt_done", | |
1466 | "tx_req", "tx_done", "rx_small_cnt", "rx_big_cnt", | |
1467 | "wake_queue", "stop_queue", "watchdog_resets", "tx_linearized", | |
c58ac5ca | 1468 | "link_changes", "link_up", "dropped_link_overflow", |
cee505db BG |
1469 | "dropped_link_error_or_filtered", |
1470 | "dropped_pause", "dropped_bad_phy", "dropped_bad_crc32", | |
1471 | "dropped_unicast_filtered", "dropped_multicast_filtered", | |
0da34b6d | 1472 | "dropped_runt", "dropped_overrun", "dropped_no_small_buffer", |
1e6e9342 AG |
1473 | "dropped_no_big_buffer", "LRO aggregated", "LRO flushed", |
1474 | "LRO avg aggr", "LRO no_desc" | |
0da34b6d BG |
1475 | }; |
1476 | ||
1477 | #define MYRI10GE_NET_STATS_LEN 21 | |
4c3616cd | 1478 | #define MYRI10GE_STATS_LEN ARRAY_SIZE(myri10ge_gstrings_stats) |
0da34b6d BG |
1479 | |
1480 | static void | |
1481 | myri10ge_get_strings(struct net_device *netdev, u32 stringset, u8 * data) | |
1482 | { | |
1483 | switch (stringset) { | |
1484 | case ETH_SS_STATS: | |
1485 | memcpy(data, *myri10ge_gstrings_stats, | |
1486 | sizeof(myri10ge_gstrings_stats)); | |
1487 | break; | |
1488 | } | |
1489 | } | |
1490 | ||
b9f2c044 | 1491 | static int myri10ge_get_sset_count(struct net_device *netdev, int sset) |
0da34b6d | 1492 | { |
b9f2c044 JG |
1493 | switch (sset) { |
1494 | case ETH_SS_STATS: | |
1495 | return MYRI10GE_STATS_LEN; | |
1496 | default: | |
1497 | return -EOPNOTSUPP; | |
1498 | } | |
0da34b6d BG |
1499 | } |
1500 | ||
1501 | static void | |
1502 | myri10ge_get_ethtool_stats(struct net_device *netdev, | |
1503 | struct ethtool_stats *stats, u64 * data) | |
1504 | { | |
1505 | struct myri10ge_priv *mgp = netdev_priv(netdev); | |
1506 | int i; | |
1507 | ||
1508 | for (i = 0; i < MYRI10GE_NET_STATS_LEN; i++) | |
1509 | data[i] = ((unsigned long *)&mgp->stats)[i]; | |
1510 | ||
2c1a1088 | 1511 | data[i++] = (unsigned int)mgp->tx.boundary; |
276e26c3 | 1512 | data[i++] = (unsigned int)mgp->wc_enabled; |
2c1a1088 BG |
1513 | data[i++] = (unsigned int)mgp->pdev->irq; |
1514 | data[i++] = (unsigned int)mgp->msi_enabled; | |
0da34b6d BG |
1515 | data[i++] = (unsigned int)mgp->read_dma; |
1516 | data[i++] = (unsigned int)mgp->write_dma; | |
1517 | data[i++] = (unsigned int)mgp->read_write_dma; | |
1518 | data[i++] = (unsigned int)mgp->serial_number; | |
1519 | data[i++] = (unsigned int)mgp->tx.pkt_start; | |
1520 | data[i++] = (unsigned int)mgp->tx.pkt_done; | |
1521 | data[i++] = (unsigned int)mgp->tx.req; | |
1522 | data[i++] = (unsigned int)mgp->tx.done; | |
1523 | data[i++] = (unsigned int)mgp->rx_small.cnt; | |
1524 | data[i++] = (unsigned int)mgp->rx_big.cnt; | |
1525 | data[i++] = (unsigned int)mgp->wake_queue; | |
1526 | data[i++] = (unsigned int)mgp->stop_queue; | |
1527 | data[i++] = (unsigned int)mgp->watchdog_resets; | |
1528 | data[i++] = (unsigned int)mgp->tx_linearized; | |
c58ac5ca | 1529 | data[i++] = (unsigned int)mgp->link_changes; |
0da34b6d BG |
1530 | data[i++] = (unsigned int)ntohl(mgp->fw_stats->link_up); |
1531 | data[i++] = (unsigned int)ntohl(mgp->fw_stats->dropped_link_overflow); | |
1532 | data[i++] = | |
1533 | (unsigned int)ntohl(mgp->fw_stats->dropped_link_error_or_filtered); | |
cee505db BG |
1534 | data[i++] = (unsigned int)ntohl(mgp->fw_stats->dropped_pause); |
1535 | data[i++] = (unsigned int)ntohl(mgp->fw_stats->dropped_bad_phy); | |
1536 | data[i++] = (unsigned int)ntohl(mgp->fw_stats->dropped_bad_crc32); | |
1537 | data[i++] = | |
1538 | (unsigned int)ntohl(mgp->fw_stats->dropped_unicast_filtered); | |
85a7ea1b BG |
1539 | data[i++] = |
1540 | (unsigned int)ntohl(mgp->fw_stats->dropped_multicast_filtered); | |
0da34b6d BG |
1541 | data[i++] = (unsigned int)ntohl(mgp->fw_stats->dropped_runt); |
1542 | data[i++] = (unsigned int)ntohl(mgp->fw_stats->dropped_overrun); | |
1543 | data[i++] = (unsigned int)ntohl(mgp->fw_stats->dropped_no_small_buffer); | |
1544 | data[i++] = (unsigned int)ntohl(mgp->fw_stats->dropped_no_big_buffer); | |
1e6e9342 AG |
1545 | data[i++] = mgp->rx_done.lro_mgr.stats.aggregated; |
1546 | data[i++] = mgp->rx_done.lro_mgr.stats.flushed; | |
1547 | if (mgp->rx_done.lro_mgr.stats.flushed) | |
1548 | data[i++] = mgp->rx_done.lro_mgr.stats.aggregated / | |
1549 | mgp->rx_done.lro_mgr.stats.flushed; | |
1550 | else | |
1551 | data[i++] = 0; | |
1552 | data[i++] = mgp->rx_done.lro_mgr.stats.no_desc; | |
0da34b6d BG |
1553 | } |
1554 | ||
c58ac5ca BG |
1555 | static void myri10ge_set_msglevel(struct net_device *netdev, u32 value) |
1556 | { | |
1557 | struct myri10ge_priv *mgp = netdev_priv(netdev); | |
1558 | mgp->msg_enable = value; | |
1559 | } | |
1560 | ||
1561 | static u32 myri10ge_get_msglevel(struct net_device *netdev) | |
1562 | { | |
1563 | struct myri10ge_priv *mgp = netdev_priv(netdev); | |
1564 | return mgp->msg_enable; | |
1565 | } | |
1566 | ||
7282d491 | 1567 | static const struct ethtool_ops myri10ge_ethtool_ops = { |
0da34b6d BG |
1568 | .get_settings = myri10ge_get_settings, |
1569 | .get_drvinfo = myri10ge_get_drvinfo, | |
1570 | .get_coalesce = myri10ge_get_coalesce, | |
1571 | .set_coalesce = myri10ge_set_coalesce, | |
1572 | .get_pauseparam = myri10ge_get_pauseparam, | |
1573 | .set_pauseparam = myri10ge_set_pauseparam, | |
1574 | .get_ringparam = myri10ge_get_ringparam, | |
1575 | .get_rx_csum = myri10ge_get_rx_csum, | |
1576 | .set_rx_csum = myri10ge_set_rx_csum, | |
b10c0668 | 1577 | .set_tx_csum = ethtool_op_set_tx_hw_csum, |
0da34b6d | 1578 | .set_sg = ethtool_op_set_sg, |
4f93fde0 | 1579 | .set_tso = myri10ge_set_tso, |
6ffdd071 | 1580 | .get_link = ethtool_op_get_link, |
0da34b6d | 1581 | .get_strings = myri10ge_get_strings, |
b9f2c044 | 1582 | .get_sset_count = myri10ge_get_sset_count, |
c58ac5ca BG |
1583 | .get_ethtool_stats = myri10ge_get_ethtool_stats, |
1584 | .set_msglevel = myri10ge_set_msglevel, | |
1585 | .get_msglevel = myri10ge_get_msglevel | |
0da34b6d BG |
1586 | }; |
1587 | ||
1588 | static int myri10ge_allocate_rings(struct net_device *dev) | |
1589 | { | |
1590 | struct myri10ge_priv *mgp; | |
1591 | struct myri10ge_cmd cmd; | |
1592 | int tx_ring_size, rx_ring_size; | |
1593 | int tx_ring_entries, rx_ring_entries; | |
1594 | int i, status; | |
1595 | size_t bytes; | |
1596 | ||
1597 | mgp = netdev_priv(dev); | |
1598 | ||
1599 | /* get ring sizes */ | |
1600 | ||
1601 | status = myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_SEND_RING_SIZE, &cmd, 0); | |
1602 | tx_ring_size = cmd.data0; | |
1603 | status |= myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_RX_RING_SIZE, &cmd, 0); | |
355c7265 BG |
1604 | if (status != 0) |
1605 | return status; | |
0da34b6d BG |
1606 | rx_ring_size = cmd.data0; |
1607 | ||
1608 | tx_ring_entries = tx_ring_size / sizeof(struct mcp_kreq_ether_send); | |
1609 | rx_ring_entries = rx_ring_size / sizeof(struct mcp_dma_addr); | |
1610 | mgp->tx.mask = tx_ring_entries - 1; | |
1611 | mgp->rx_small.mask = mgp->rx_big.mask = rx_ring_entries - 1; | |
1612 | ||
355c7265 BG |
1613 | status = -ENOMEM; |
1614 | ||
0da34b6d BG |
1615 | /* allocate the host shadow rings */ |
1616 | ||
1617 | bytes = 8 + (MYRI10GE_MAX_SEND_DESC_TSO + 4) | |
1618 | * sizeof(*mgp->tx.req_list); | |
1619 | mgp->tx.req_bytes = kzalloc(bytes, GFP_KERNEL); | |
1620 | if (mgp->tx.req_bytes == NULL) | |
1621 | goto abort_with_nothing; | |
1622 | ||
1623 | /* ensure req_list entries are aligned to 8 bytes */ | |
1624 | mgp->tx.req_list = (struct mcp_kreq_ether_send *) | |
1625 | ALIGN((unsigned long)mgp->tx.req_bytes, 8); | |
1626 | ||
1627 | bytes = rx_ring_entries * sizeof(*mgp->rx_small.shadow); | |
1628 | mgp->rx_small.shadow = kzalloc(bytes, GFP_KERNEL); | |
1629 | if (mgp->rx_small.shadow == NULL) | |
1630 | goto abort_with_tx_req_bytes; | |
1631 | ||
1632 | bytes = rx_ring_entries * sizeof(*mgp->rx_big.shadow); | |
1633 | mgp->rx_big.shadow = kzalloc(bytes, GFP_KERNEL); | |
1634 | if (mgp->rx_big.shadow == NULL) | |
1635 | goto abort_with_rx_small_shadow; | |
1636 | ||
1637 | /* allocate the host info rings */ | |
1638 | ||
1639 | bytes = tx_ring_entries * sizeof(*mgp->tx.info); | |
1640 | mgp->tx.info = kzalloc(bytes, GFP_KERNEL); | |
1641 | if (mgp->tx.info == NULL) | |
1642 | goto abort_with_rx_big_shadow; | |
1643 | ||
1644 | bytes = rx_ring_entries * sizeof(*mgp->rx_small.info); | |
1645 | mgp->rx_small.info = kzalloc(bytes, GFP_KERNEL); | |
1646 | if (mgp->rx_small.info == NULL) | |
1647 | goto abort_with_tx_info; | |
1648 | ||
1649 | bytes = rx_ring_entries * sizeof(*mgp->rx_big.info); | |
1650 | mgp->rx_big.info = kzalloc(bytes, GFP_KERNEL); | |
1651 | if (mgp->rx_big.info == NULL) | |
1652 | goto abort_with_rx_small_info; | |
1653 | ||
1654 | /* Fill the receive rings */ | |
c7dab99b BG |
1655 | mgp->rx_big.cnt = 0; |
1656 | mgp->rx_small.cnt = 0; | |
1657 | mgp->rx_big.fill_cnt = 0; | |
1658 | mgp->rx_small.fill_cnt = 0; | |
1659 | mgp->rx_small.page_offset = MYRI10GE_ALLOC_SIZE; | |
1660 | mgp->rx_big.page_offset = MYRI10GE_ALLOC_SIZE; | |
1661 | mgp->rx_small.watchdog_needed = 0; | |
1662 | mgp->rx_big.watchdog_needed = 0; | |
1663 | myri10ge_alloc_rx_pages(mgp, &mgp->rx_small, | |
1664 | mgp->small_bytes + MXGEFW_PAD, 0); | |
0da34b6d | 1665 | |
c7dab99b BG |
1666 | if (mgp->rx_small.fill_cnt < mgp->rx_small.mask + 1) { |
1667 | printk(KERN_ERR "myri10ge: %s: alloced only %d small bufs\n", | |
1668 | dev->name, mgp->rx_small.fill_cnt); | |
1669 | goto abort_with_rx_small_ring; | |
0da34b6d BG |
1670 | } |
1671 | ||
c7dab99b BG |
1672 | myri10ge_alloc_rx_pages(mgp, &mgp->rx_big, mgp->big_bytes, 0); |
1673 | if (mgp->rx_big.fill_cnt < mgp->rx_big.mask + 1) { | |
1674 | printk(KERN_ERR "myri10ge: %s: alloced only %d big bufs\n", | |
1675 | dev->name, mgp->rx_big.fill_cnt); | |
1676 | goto abort_with_rx_big_ring; | |
0da34b6d BG |
1677 | } |
1678 | ||
1679 | return 0; | |
1680 | ||
1681 | abort_with_rx_big_ring: | |
c7dab99b BG |
1682 | for (i = mgp->rx_big.cnt; i < mgp->rx_big.fill_cnt; i++) { |
1683 | int idx = i & mgp->rx_big.mask; | |
1684 | myri10ge_unmap_rx_page(mgp->pdev, &mgp->rx_big.info[idx], | |
1685 | mgp->big_bytes); | |
1686 | put_page(mgp->rx_big.info[idx].page); | |
0da34b6d BG |
1687 | } |
1688 | ||
1689 | abort_with_rx_small_ring: | |
c7dab99b BG |
1690 | for (i = mgp->rx_small.cnt; i < mgp->rx_small.fill_cnt; i++) { |
1691 | int idx = i & mgp->rx_small.mask; | |
1692 | myri10ge_unmap_rx_page(mgp->pdev, &mgp->rx_small.info[idx], | |
1693 | mgp->small_bytes + MXGEFW_PAD); | |
1694 | put_page(mgp->rx_small.info[idx].page); | |
0da34b6d | 1695 | } |
c7dab99b | 1696 | |
0da34b6d BG |
1697 | kfree(mgp->rx_big.info); |
1698 | ||
1699 | abort_with_rx_small_info: | |
1700 | kfree(mgp->rx_small.info); | |
1701 | ||
1702 | abort_with_tx_info: | |
1703 | kfree(mgp->tx.info); | |
1704 | ||
1705 | abort_with_rx_big_shadow: | |
1706 | kfree(mgp->rx_big.shadow); | |
1707 | ||
1708 | abort_with_rx_small_shadow: | |
1709 | kfree(mgp->rx_small.shadow); | |
1710 | ||
1711 | abort_with_tx_req_bytes: | |
1712 | kfree(mgp->tx.req_bytes); | |
1713 | mgp->tx.req_bytes = NULL; | |
1714 | mgp->tx.req_list = NULL; | |
1715 | ||
1716 | abort_with_nothing: | |
1717 | return status; | |
1718 | } | |
1719 | ||
1720 | static void myri10ge_free_rings(struct net_device *dev) | |
1721 | { | |
1722 | struct myri10ge_priv *mgp; | |
1723 | struct sk_buff *skb; | |
1724 | struct myri10ge_tx_buf *tx; | |
1725 | int i, len, idx; | |
1726 | ||
1727 | mgp = netdev_priv(dev); | |
1728 | ||
c7dab99b BG |
1729 | for (i = mgp->rx_big.cnt; i < mgp->rx_big.fill_cnt; i++) { |
1730 | idx = i & mgp->rx_big.mask; | |
1731 | if (i == mgp->rx_big.fill_cnt - 1) | |
1732 | mgp->rx_big.info[idx].page_offset = MYRI10GE_ALLOC_SIZE; | |
1733 | myri10ge_unmap_rx_page(mgp->pdev, &mgp->rx_big.info[idx], | |
1734 | mgp->big_bytes); | |
1735 | put_page(mgp->rx_big.info[idx].page); | |
0da34b6d BG |
1736 | } |
1737 | ||
c7dab99b BG |
1738 | for (i = mgp->rx_small.cnt; i < mgp->rx_small.fill_cnt; i++) { |
1739 | idx = i & mgp->rx_small.mask; | |
1740 | if (i == mgp->rx_small.fill_cnt - 1) | |
1741 | mgp->rx_small.info[idx].page_offset = | |
1742 | MYRI10GE_ALLOC_SIZE; | |
1743 | myri10ge_unmap_rx_page(mgp->pdev, &mgp->rx_small.info[idx], | |
1744 | mgp->small_bytes + MXGEFW_PAD); | |
1745 | put_page(mgp->rx_small.info[idx].page); | |
1746 | } | |
0da34b6d BG |
1747 | tx = &mgp->tx; |
1748 | while (tx->done != tx->req) { | |
1749 | idx = tx->done & tx->mask; | |
1750 | skb = tx->info[idx].skb; | |
1751 | ||
1752 | /* Mark as free */ | |
1753 | tx->info[idx].skb = NULL; | |
1754 | tx->done++; | |
1755 | len = pci_unmap_len(&tx->info[idx], len); | |
1756 | pci_unmap_len_set(&tx->info[idx], len, 0); | |
1757 | if (skb) { | |
1758 | mgp->stats.tx_dropped++; | |
1759 | dev_kfree_skb_any(skb); | |
1760 | if (len) | |
1761 | pci_unmap_single(mgp->pdev, | |
1762 | pci_unmap_addr(&tx->info[idx], | |
1763 | bus), len, | |
1764 | PCI_DMA_TODEVICE); | |
1765 | } else { | |
1766 | if (len) | |
1767 | pci_unmap_page(mgp->pdev, | |
1768 | pci_unmap_addr(&tx->info[idx], | |
1769 | bus), len, | |
1770 | PCI_DMA_TODEVICE); | |
1771 | } | |
1772 | } | |
1773 | kfree(mgp->rx_big.info); | |
1774 | ||
1775 | kfree(mgp->rx_small.info); | |
1776 | ||
1777 | kfree(mgp->tx.info); | |
1778 | ||
1779 | kfree(mgp->rx_big.shadow); | |
1780 | ||
1781 | kfree(mgp->rx_small.shadow); | |
1782 | ||
1783 | kfree(mgp->tx.req_bytes); | |
1784 | mgp->tx.req_bytes = NULL; | |
1785 | mgp->tx.req_list = NULL; | |
1786 | } | |
1787 | ||
df30a740 BG |
1788 | static int myri10ge_request_irq(struct myri10ge_priv *mgp) |
1789 | { | |
1790 | struct pci_dev *pdev = mgp->pdev; | |
1791 | int status; | |
1792 | ||
1793 | if (myri10ge_msi) { | |
1794 | status = pci_enable_msi(pdev); | |
1795 | if (status != 0) | |
1796 | dev_err(&pdev->dev, | |
1797 | "Error %d setting up MSI; falling back to xPIC\n", | |
1798 | status); | |
1799 | else | |
1800 | mgp->msi_enabled = 1; | |
1801 | } else { | |
1802 | mgp->msi_enabled = 0; | |
1803 | } | |
1804 | status = request_irq(pdev->irq, myri10ge_intr, IRQF_SHARED, | |
1805 | mgp->dev->name, mgp); | |
1806 | if (status != 0) { | |
1807 | dev_err(&pdev->dev, "failed to allocate IRQ\n"); | |
1808 | if (mgp->msi_enabled) | |
1809 | pci_disable_msi(pdev); | |
1810 | } | |
1811 | return status; | |
1812 | } | |
1813 | ||
1814 | static void myri10ge_free_irq(struct myri10ge_priv *mgp) | |
1815 | { | |
1816 | struct pci_dev *pdev = mgp->pdev; | |
1817 | ||
1818 | free_irq(pdev->irq, mgp); | |
1819 | if (mgp->msi_enabled) | |
1820 | pci_disable_msi(pdev); | |
1821 | } | |
1822 | ||
1e6e9342 AG |
1823 | static int |
1824 | myri10ge_get_frag_header(struct skb_frag_struct *frag, void **mac_hdr, | |
1825 | void **ip_hdr, void **tcpudp_hdr, | |
1826 | u64 * hdr_flags, void *priv) | |
1827 | { | |
1828 | struct ethhdr *eh; | |
1829 | struct vlan_ethhdr *veh; | |
1830 | struct iphdr *iph; | |
1831 | u8 *va = page_address(frag->page) + frag->page_offset; | |
1832 | unsigned long ll_hlen; | |
66341fff AV |
1833 | /* passed opaque through lro_receive_frags() */ |
1834 | __wsum csum = (__force __wsum) (unsigned long)priv; | |
1e6e9342 AG |
1835 | |
1836 | /* find the mac header, aborting if not IPv4 */ | |
1837 | ||
1838 | eh = (struct ethhdr *)va; | |
1839 | *mac_hdr = eh; | |
1840 | ll_hlen = ETH_HLEN; | |
1841 | if (eh->h_proto != htons(ETH_P_IP)) { | |
1842 | if (eh->h_proto == htons(ETH_P_8021Q)) { | |
1843 | veh = (struct vlan_ethhdr *)va; | |
1844 | if (veh->h_vlan_encapsulated_proto != htons(ETH_P_IP)) | |
1845 | return -1; | |
1846 | ||
1847 | ll_hlen += VLAN_HLEN; | |
1848 | ||
1849 | /* | |
1850 | * HW checksum starts ETH_HLEN bytes into | |
1851 | * frame, so we must subtract off the VLAN | |
1852 | * header's checksum before csum can be used | |
1853 | */ | |
1854 | csum = csum_sub(csum, csum_partial(va + ETH_HLEN, | |
1855 | VLAN_HLEN, 0)); | |
1856 | } else { | |
1857 | return -1; | |
1858 | } | |
1859 | } | |
1860 | *hdr_flags = LRO_IPV4; | |
1861 | ||
1862 | iph = (struct iphdr *)(va + ll_hlen); | |
1863 | *ip_hdr = iph; | |
1864 | if (iph->protocol != IPPROTO_TCP) | |
1865 | return -1; | |
1866 | *hdr_flags |= LRO_TCP; | |
1867 | *tcpudp_hdr = (u8 *) (*ip_hdr) + (iph->ihl << 2); | |
1868 | ||
1869 | /* verify the IP checksum */ | |
1870 | if (unlikely(ip_fast_csum((u8 *) iph, iph->ihl))) | |
1871 | return -1; | |
1872 | ||
1873 | /* verify the checksum */ | |
1874 | if (unlikely(csum_tcpudp_magic(iph->saddr, iph->daddr, | |
1875 | ntohs(iph->tot_len) - (iph->ihl << 2), | |
1876 | IPPROTO_TCP, csum))) | |
1877 | return -1; | |
1878 | ||
1879 | return 0; | |
1880 | } | |
1881 | ||
0da34b6d BG |
1882 | static int myri10ge_open(struct net_device *dev) |
1883 | { | |
1884 | struct myri10ge_priv *mgp; | |
1885 | struct myri10ge_cmd cmd; | |
1e6e9342 | 1886 | struct net_lro_mgr *lro_mgr; |
0da34b6d BG |
1887 | int status, big_pow2; |
1888 | ||
1889 | mgp = netdev_priv(dev); | |
1890 | ||
1891 | if (mgp->running != MYRI10GE_ETH_STOPPED) | |
1892 | return -EBUSY; | |
1893 | ||
1894 | mgp->running = MYRI10GE_ETH_STARTING; | |
1895 | status = myri10ge_reset(mgp); | |
1896 | if (status != 0) { | |
1897 | printk(KERN_ERR "myri10ge: %s: failed reset\n", dev->name); | |
df30a740 | 1898 | goto abort_with_nothing; |
0da34b6d BG |
1899 | } |
1900 | ||
df30a740 BG |
1901 | status = myri10ge_request_irq(mgp); |
1902 | if (status != 0) | |
1903 | goto abort_with_nothing; | |
1904 | ||
0da34b6d BG |
1905 | /* decide what small buffer size to use. For good TCP rx |
1906 | * performance, it is important to not receive 1514 byte | |
1907 | * frames into jumbo buffers, as it confuses the socket buffer | |
1908 | * accounting code, leading to drops and erratic performance. | |
1909 | */ | |
1910 | ||
1911 | if (dev->mtu <= ETH_DATA_LEN) | |
c7dab99b BG |
1912 | /* enough for a TCP header */ |
1913 | mgp->small_bytes = (128 > SMP_CACHE_BYTES) | |
1914 | ? (128 - MXGEFW_PAD) | |
1915 | : (SMP_CACHE_BYTES - MXGEFW_PAD); | |
0da34b6d | 1916 | else |
de3c4507 BG |
1917 | /* enough for a vlan encapsulated ETH_DATA_LEN frame */ |
1918 | mgp->small_bytes = VLAN_ETH_FRAME_LEN; | |
0da34b6d BG |
1919 | |
1920 | /* Override the small buffer size? */ | |
1921 | if (myri10ge_small_bytes > 0) | |
1922 | mgp->small_bytes = myri10ge_small_bytes; | |
1923 | ||
0da34b6d BG |
1924 | /* get the lanai pointers to the send and receive rings */ |
1925 | ||
1926 | status |= myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_SEND_OFFSET, &cmd, 0); | |
1927 | mgp->tx.lanai = | |
1928 | (struct mcp_kreq_ether_send __iomem *)(mgp->sram + cmd.data0); | |
1929 | ||
1930 | status |= | |
1931 | myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_SMALL_RX_OFFSET, &cmd, 0); | |
1932 | mgp->rx_small.lanai = | |
1933 | (struct mcp_kreq_ether_recv __iomem *)(mgp->sram + cmd.data0); | |
1934 | ||
1935 | status |= myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_BIG_RX_OFFSET, &cmd, 0); | |
1936 | mgp->rx_big.lanai = | |
1937 | (struct mcp_kreq_ether_recv __iomem *)(mgp->sram + cmd.data0); | |
1938 | ||
1939 | if (status != 0) { | |
1940 | printk(KERN_ERR | |
1941 | "myri10ge: %s: failed to get ring sizes or locations\n", | |
1942 | dev->name); | |
1943 | mgp->running = MYRI10GE_ETH_STOPPED; | |
df30a740 | 1944 | goto abort_with_irq; |
0da34b6d BG |
1945 | } |
1946 | ||
276e26c3 | 1947 | if (myri10ge_wcfifo && mgp->wc_enabled) { |
e700f9f4 BG |
1948 | mgp->tx.wc_fifo = (u8 __iomem *) mgp->sram + MXGEFW_ETH_SEND_4; |
1949 | mgp->rx_small.wc_fifo = | |
1950 | (u8 __iomem *) mgp->sram + MXGEFW_ETH_RECV_SMALL; | |
1951 | mgp->rx_big.wc_fifo = | |
1952 | (u8 __iomem *) mgp->sram + MXGEFW_ETH_RECV_BIG; | |
0da34b6d BG |
1953 | } else { |
1954 | mgp->tx.wc_fifo = NULL; | |
1955 | mgp->rx_small.wc_fifo = NULL; | |
1956 | mgp->rx_big.wc_fifo = NULL; | |
1957 | } | |
1958 | ||
0da34b6d BG |
1959 | /* Firmware needs the big buff size as a power of 2. Lie and |
1960 | * tell him the buffer is larger, because we only use 1 | |
1961 | * buffer/pkt, and the mtu will prevent overruns. | |
1962 | */ | |
13348bee | 1963 | big_pow2 = dev->mtu + ETH_HLEN + VLAN_HLEN + MXGEFW_PAD; |
c7dab99b | 1964 | if (big_pow2 < MYRI10GE_ALLOC_SIZE / 2) { |
199126a2 | 1965 | while (!is_power_of_2(big_pow2)) |
c7dab99b | 1966 | big_pow2++; |
13348bee | 1967 | mgp->big_bytes = dev->mtu + ETH_HLEN + VLAN_HLEN + MXGEFW_PAD; |
c7dab99b BG |
1968 | } else { |
1969 | big_pow2 = MYRI10GE_ALLOC_SIZE; | |
1970 | mgp->big_bytes = big_pow2; | |
1971 | } | |
1972 | ||
1973 | status = myri10ge_allocate_rings(dev); | |
1974 | if (status != 0) | |
df30a740 | 1975 | goto abort_with_irq; |
0da34b6d BG |
1976 | |
1977 | /* now give firmware buffers sizes, and MTU */ | |
1978 | cmd.data0 = dev->mtu + ETH_HLEN + VLAN_HLEN; | |
1979 | status = myri10ge_send_cmd(mgp, MXGEFW_CMD_SET_MTU, &cmd, 0); | |
1980 | cmd.data0 = mgp->small_bytes; | |
1981 | status |= | |
1982 | myri10ge_send_cmd(mgp, MXGEFW_CMD_SET_SMALL_BUFFER_SIZE, &cmd, 0); | |
1983 | cmd.data0 = big_pow2; | |
1984 | status |= | |
1985 | myri10ge_send_cmd(mgp, MXGEFW_CMD_SET_BIG_BUFFER_SIZE, &cmd, 0); | |
1986 | if (status) { | |
1987 | printk(KERN_ERR "myri10ge: %s: Couldn't set buffer sizes\n", | |
1988 | dev->name); | |
1989 | goto abort_with_rings; | |
1990 | } | |
1991 | ||
1992 | cmd.data0 = MYRI10GE_LOWPART_TO_U32(mgp->fw_stats_bus); | |
1993 | cmd.data1 = MYRI10GE_HIGHPART_TO_U32(mgp->fw_stats_bus); | |
85a7ea1b BG |
1994 | cmd.data2 = sizeof(struct mcp_irq_data); |
1995 | status = myri10ge_send_cmd(mgp, MXGEFW_CMD_SET_STATS_DMA_V2, &cmd, 0); | |
1996 | if (status == -ENOSYS) { | |
1997 | dma_addr_t bus = mgp->fw_stats_bus; | |
1998 | bus += offsetof(struct mcp_irq_data, send_done_count); | |
1999 | cmd.data0 = MYRI10GE_LOWPART_TO_U32(bus); | |
2000 | cmd.data1 = MYRI10GE_HIGHPART_TO_U32(bus); | |
2001 | status = myri10ge_send_cmd(mgp, | |
2002 | MXGEFW_CMD_SET_STATS_DMA_OBSOLETE, | |
2003 | &cmd, 0); | |
2004 | /* Firmware cannot support multicast without STATS_DMA_V2 */ | |
2005 | mgp->fw_multicast_support = 0; | |
2006 | } else { | |
2007 | mgp->fw_multicast_support = 1; | |
2008 | } | |
0da34b6d BG |
2009 | if (status) { |
2010 | printk(KERN_ERR "myri10ge: %s: Couldn't set stats DMA\n", | |
2011 | dev->name); | |
2012 | goto abort_with_rings; | |
2013 | } | |
2014 | ||
66341fff | 2015 | mgp->link_state = ~0U; |
0da34b6d BG |
2016 | mgp->rdma_tags_available = 15; |
2017 | ||
1e6e9342 AG |
2018 | lro_mgr = &mgp->rx_done.lro_mgr; |
2019 | lro_mgr->dev = dev; | |
2020 | lro_mgr->features = LRO_F_NAPI; | |
2021 | lro_mgr->ip_summed = CHECKSUM_COMPLETE; | |
2022 | lro_mgr->ip_summed_aggr = CHECKSUM_UNNECESSARY; | |
2023 | lro_mgr->max_desc = MYRI10GE_MAX_LRO_DESCRIPTORS; | |
2024 | lro_mgr->lro_arr = mgp->rx_done.lro_desc; | |
2025 | lro_mgr->get_frag_header = myri10ge_get_frag_header; | |
2026 | lro_mgr->max_aggr = myri10ge_lro_max_pkts; | |
621544eb | 2027 | lro_mgr->frag_align_pad = 2; |
1e6e9342 AG |
2028 | if (lro_mgr->max_aggr > MAX_SKB_FRAGS) |
2029 | lro_mgr->max_aggr = MAX_SKB_FRAGS; | |
2030 | ||
bea3348e | 2031 | napi_enable(&mgp->napi); /* must happen prior to any irq */ |
0da34b6d BG |
2032 | |
2033 | status = myri10ge_send_cmd(mgp, MXGEFW_CMD_ETHERNET_UP, &cmd, 0); | |
2034 | if (status) { | |
2035 | printk(KERN_ERR "myri10ge: %s: Couldn't bring up link\n", | |
2036 | dev->name); | |
2037 | goto abort_with_rings; | |
2038 | } | |
2039 | ||
2040 | mgp->wake_queue = 0; | |
2041 | mgp->stop_queue = 0; | |
2042 | mgp->running = MYRI10GE_ETH_RUNNING; | |
2043 | mgp->watchdog_timer.expires = jiffies + myri10ge_watchdog_timeout * HZ; | |
2044 | add_timer(&mgp->watchdog_timer); | |
2045 | netif_wake_queue(dev); | |
2046 | return 0; | |
2047 | ||
2048 | abort_with_rings: | |
2049 | myri10ge_free_rings(dev); | |
2050 | ||
df30a740 BG |
2051 | abort_with_irq: |
2052 | myri10ge_free_irq(mgp); | |
2053 | ||
0da34b6d BG |
2054 | abort_with_nothing: |
2055 | mgp->running = MYRI10GE_ETH_STOPPED; | |
2056 | return -ENOMEM; | |
2057 | } | |
2058 | ||
2059 | static int myri10ge_close(struct net_device *dev) | |
2060 | { | |
2061 | struct myri10ge_priv *mgp; | |
2062 | struct myri10ge_cmd cmd; | |
2063 | int status, old_down_cnt; | |
2064 | ||
2065 | mgp = netdev_priv(dev); | |
2066 | ||
2067 | if (mgp->running != MYRI10GE_ETH_RUNNING) | |
2068 | return 0; | |
2069 | ||
2070 | if (mgp->tx.req_bytes == NULL) | |
2071 | return 0; | |
2072 | ||
2073 | del_timer_sync(&mgp->watchdog_timer); | |
2074 | mgp->running = MYRI10GE_ETH_STOPPING; | |
bea3348e | 2075 | napi_disable(&mgp->napi); |
0da34b6d BG |
2076 | netif_carrier_off(dev); |
2077 | netif_stop_queue(dev); | |
2078 | old_down_cnt = mgp->down_cnt; | |
2079 | mb(); | |
2080 | status = myri10ge_send_cmd(mgp, MXGEFW_CMD_ETHERNET_DOWN, &cmd, 0); | |
2081 | if (status) | |
2082 | printk(KERN_ERR "myri10ge: %s: Couldn't bring down link\n", | |
2083 | dev->name); | |
2084 | ||
2085 | wait_event_timeout(mgp->down_wq, old_down_cnt != mgp->down_cnt, HZ); | |
2086 | if (old_down_cnt == mgp->down_cnt) | |
2087 | printk(KERN_ERR "myri10ge: %s never got down irq\n", dev->name); | |
2088 | ||
2089 | netif_tx_disable(dev); | |
df30a740 | 2090 | myri10ge_free_irq(mgp); |
0da34b6d BG |
2091 | myri10ge_free_rings(dev); |
2092 | ||
2093 | mgp->running = MYRI10GE_ETH_STOPPED; | |
2094 | return 0; | |
2095 | } | |
2096 | ||
2097 | /* copy an array of struct mcp_kreq_ether_send's to the mcp. Copy | |
2098 | * backwards one at a time and handle ring wraps */ | |
2099 | ||
2100 | static inline void | |
2101 | myri10ge_submit_req_backwards(struct myri10ge_tx_buf *tx, | |
2102 | struct mcp_kreq_ether_send *src, int cnt) | |
2103 | { | |
2104 | int idx, starting_slot; | |
2105 | starting_slot = tx->req; | |
2106 | while (cnt > 1) { | |
2107 | cnt--; | |
2108 | idx = (starting_slot + cnt) & tx->mask; | |
2109 | myri10ge_pio_copy(&tx->lanai[idx], &src[cnt], sizeof(*src)); | |
2110 | mb(); | |
2111 | } | |
2112 | } | |
2113 | ||
2114 | /* | |
2115 | * copy an array of struct mcp_kreq_ether_send's to the mcp. Copy | |
2116 | * at most 32 bytes at a time, so as to avoid involving the software | |
2117 | * pio handler in the nic. We re-write the first segment's flags | |
2118 | * to mark them valid only after writing the entire chain. | |
2119 | */ | |
2120 | ||
2121 | static inline void | |
2122 | myri10ge_submit_req(struct myri10ge_tx_buf *tx, struct mcp_kreq_ether_send *src, | |
2123 | int cnt) | |
2124 | { | |
2125 | int idx, i; | |
2126 | struct mcp_kreq_ether_send __iomem *dstp, *dst; | |
2127 | struct mcp_kreq_ether_send *srcp; | |
2128 | u8 last_flags; | |
2129 | ||
2130 | idx = tx->req & tx->mask; | |
2131 | ||
2132 | last_flags = src->flags; | |
2133 | src->flags = 0; | |
2134 | mb(); | |
2135 | dst = dstp = &tx->lanai[idx]; | |
2136 | srcp = src; | |
2137 | ||
2138 | if ((idx + cnt) < tx->mask) { | |
2139 | for (i = 0; i < (cnt - 1); i += 2) { | |
2140 | myri10ge_pio_copy(dstp, srcp, 2 * sizeof(*src)); | |
2141 | mb(); /* force write every 32 bytes */ | |
2142 | srcp += 2; | |
2143 | dstp += 2; | |
2144 | } | |
2145 | } else { | |
2146 | /* submit all but the first request, and ensure | |
2147 | * that it is submitted below */ | |
2148 | myri10ge_submit_req_backwards(tx, src, cnt); | |
2149 | i = 0; | |
2150 | } | |
2151 | if (i < cnt) { | |
2152 | /* submit the first request */ | |
2153 | myri10ge_pio_copy(dstp, srcp, sizeof(*src)); | |
2154 | mb(); /* barrier before setting valid flag */ | |
2155 | } | |
2156 | ||
2157 | /* re-write the last 32-bits with the valid flags */ | |
2158 | src->flags = last_flags; | |
40f6cff5 | 2159 | put_be32(*((__be32 *) src + 3), (__be32 __iomem *) dst + 3); |
0da34b6d BG |
2160 | tx->req += cnt; |
2161 | mb(); | |
2162 | } | |
2163 | ||
2164 | static inline void | |
2165 | myri10ge_submit_req_wc(struct myri10ge_tx_buf *tx, | |
2166 | struct mcp_kreq_ether_send *src, int cnt) | |
2167 | { | |
2168 | tx->req += cnt; | |
2169 | mb(); | |
2170 | while (cnt >= 4) { | |
2171 | myri10ge_pio_copy(tx->wc_fifo, src, 64); | |
2172 | mb(); | |
2173 | src += 4; | |
2174 | cnt -= 4; | |
2175 | } | |
2176 | if (cnt > 0) { | |
2177 | /* pad it to 64 bytes. The src is 64 bytes bigger than it | |
2178 | * needs to be so that we don't overrun it */ | |
e700f9f4 BG |
2179 | myri10ge_pio_copy(tx->wc_fifo + MXGEFW_ETH_SEND_OFFSET(cnt), |
2180 | src, 64); | |
0da34b6d BG |
2181 | mb(); |
2182 | } | |
2183 | } | |
2184 | ||
2185 | /* | |
2186 | * Transmit a packet. We need to split the packet so that a single | |
2187 | * segment does not cross myri10ge->tx.boundary, so this makes segment | |
2188 | * counting tricky. So rather than try to count segments up front, we | |
2189 | * just give up if there are too few segments to hold a reasonably | |
2190 | * fragmented packet currently available. If we run | |
2191 | * out of segments while preparing a packet for DMA, we just linearize | |
2192 | * it and try again. | |
2193 | */ | |
2194 | ||
2195 | static int myri10ge_xmit(struct sk_buff *skb, struct net_device *dev) | |
2196 | { | |
2197 | struct myri10ge_priv *mgp = netdev_priv(dev); | |
2198 | struct mcp_kreq_ether_send *req; | |
2199 | struct myri10ge_tx_buf *tx = &mgp->tx; | |
2200 | struct skb_frag_struct *frag; | |
2201 | dma_addr_t bus; | |
40f6cff5 AV |
2202 | u32 low; |
2203 | __be32 high_swapped; | |
0da34b6d BG |
2204 | unsigned int len; |
2205 | int idx, last_idx, avail, frag_cnt, frag_idx, count, mss, max_segments; | |
2206 | u16 pseudo_hdr_offset, cksum_offset; | |
2207 | int cum_len, seglen, boundary, rdma_count; | |
2208 | u8 flags, odd_flag; | |
2209 | ||
2210 | again: | |
2211 | req = tx->req_list; | |
2212 | avail = tx->mask - 1 - (tx->req - tx->done); | |
2213 | ||
2214 | mss = 0; | |
2215 | max_segments = MXGEFW_MAX_SEND_DESC; | |
2216 | ||
917690cd | 2217 | if (skb_is_gso(skb)) { |
7967168c | 2218 | mss = skb_shinfo(skb)->gso_size; |
917690cd | 2219 | max_segments = MYRI10GE_MAX_SEND_DESC_TSO; |
0da34b6d | 2220 | } |
0da34b6d BG |
2221 | |
2222 | if ((unlikely(avail < max_segments))) { | |
2223 | /* we are out of transmit resources */ | |
2224 | mgp->stop_queue++; | |
2225 | netif_stop_queue(dev); | |
2226 | return 1; | |
2227 | } | |
2228 | ||
2229 | /* Setup checksum offloading, if needed */ | |
2230 | cksum_offset = 0; | |
2231 | pseudo_hdr_offset = 0; | |
2232 | odd_flag = 0; | |
2233 | flags = (MXGEFW_FLAGS_NO_TSO | MXGEFW_FLAGS_FIRST); | |
84fa7933 | 2234 | if (likely(skb->ip_summed == CHECKSUM_PARTIAL)) { |
ea2ae17d | 2235 | cksum_offset = skb_transport_offset(skb); |
ff1dcadb | 2236 | pseudo_hdr_offset = cksum_offset + skb->csum_offset; |
0da34b6d BG |
2237 | /* If the headers are excessively large, then we must |
2238 | * fall back to a software checksum */ | |
4f93fde0 BG |
2239 | if (unlikely(!mss && (cksum_offset > 255 || |
2240 | pseudo_hdr_offset > 127))) { | |
84fa7933 | 2241 | if (skb_checksum_help(skb)) |
0da34b6d BG |
2242 | goto drop; |
2243 | cksum_offset = 0; | |
2244 | pseudo_hdr_offset = 0; | |
2245 | } else { | |
0da34b6d BG |
2246 | odd_flag = MXGEFW_FLAGS_ALIGN_ODD; |
2247 | flags |= MXGEFW_FLAGS_CKSUM; | |
2248 | } | |
2249 | } | |
2250 | ||
2251 | cum_len = 0; | |
2252 | ||
0da34b6d BG |
2253 | if (mss) { /* TSO */ |
2254 | /* this removes any CKSUM flag from before */ | |
2255 | flags = (MXGEFW_FLAGS_TSO_HDR | MXGEFW_FLAGS_FIRST); | |
2256 | ||
2257 | /* negative cum_len signifies to the | |
2258 | * send loop that we are still in the | |
2259 | * header portion of the TSO packet. | |
4f93fde0 | 2260 | * TSO header can be at most 1KB long */ |
ab6a5bb6 | 2261 | cum_len = -(skb_transport_offset(skb) + tcp_hdrlen(skb)); |
0da34b6d | 2262 | |
4f93fde0 BG |
2263 | /* for IPv6 TSO, the checksum offset stores the |
2264 | * TCP header length, to save the firmware from | |
2265 | * the need to parse the headers */ | |
2266 | if (skb_is_gso_v6(skb)) { | |
2267 | cksum_offset = tcp_hdrlen(skb); | |
2268 | /* Can only handle headers <= max_tso6 long */ | |
2269 | if (unlikely(-cum_len > mgp->max_tso6)) | |
2270 | return myri10ge_sw_tso(skb, dev); | |
2271 | } | |
0da34b6d BG |
2272 | /* for TSO, pseudo_hdr_offset holds mss. |
2273 | * The firmware figures out where to put | |
2274 | * the checksum by parsing the header. */ | |
40f6cff5 | 2275 | pseudo_hdr_offset = mss; |
0da34b6d | 2276 | } else |
0da34b6d BG |
2277 | /* Mark small packets, and pad out tiny packets */ |
2278 | if (skb->len <= MXGEFW_SEND_SMALL_SIZE) { | |
2279 | flags |= MXGEFW_FLAGS_SMALL; | |
2280 | ||
2281 | /* pad frames to at least ETH_ZLEN bytes */ | |
2282 | if (unlikely(skb->len < ETH_ZLEN)) { | |
5b057c6b | 2283 | if (skb_padto(skb, ETH_ZLEN)) { |
0da34b6d BG |
2284 | /* The packet is gone, so we must |
2285 | * return 0 */ | |
2286 | mgp->stats.tx_dropped += 1; | |
2287 | return 0; | |
2288 | } | |
2289 | /* adjust the len to account for the zero pad | |
2290 | * so that the nic can know how long it is */ | |
2291 | skb->len = ETH_ZLEN; | |
2292 | } | |
2293 | } | |
2294 | ||
2295 | /* map the skb for DMA */ | |
2296 | len = skb->len - skb->data_len; | |
2297 | idx = tx->req & tx->mask; | |
2298 | tx->info[idx].skb = skb; | |
2299 | bus = pci_map_single(mgp->pdev, skb->data, len, PCI_DMA_TODEVICE); | |
2300 | pci_unmap_addr_set(&tx->info[idx], bus, bus); | |
2301 | pci_unmap_len_set(&tx->info[idx], len, len); | |
2302 | ||
2303 | frag_cnt = skb_shinfo(skb)->nr_frags; | |
2304 | frag_idx = 0; | |
2305 | count = 0; | |
2306 | rdma_count = 0; | |
2307 | ||
2308 | /* "rdma_count" is the number of RDMAs belonging to the | |
2309 | * current packet BEFORE the current send request. For | |
2310 | * non-TSO packets, this is equal to "count". | |
2311 | * For TSO packets, rdma_count needs to be reset | |
2312 | * to 0 after a segment cut. | |
2313 | * | |
2314 | * The rdma_count field of the send request is | |
2315 | * the number of RDMAs of the packet starting at | |
2316 | * that request. For TSO send requests with one ore more cuts | |
2317 | * in the middle, this is the number of RDMAs starting | |
2318 | * after the last cut in the request. All previous | |
2319 | * segments before the last cut implicitly have 1 RDMA. | |
2320 | * | |
2321 | * Since the number of RDMAs is not known beforehand, | |
2322 | * it must be filled-in retroactively - after each | |
2323 | * segmentation cut or at the end of the entire packet. | |
2324 | */ | |
2325 | ||
2326 | while (1) { | |
2327 | /* Break the SKB or Fragment up into pieces which | |
2328 | * do not cross mgp->tx.boundary */ | |
2329 | low = MYRI10GE_LOWPART_TO_U32(bus); | |
2330 | high_swapped = htonl(MYRI10GE_HIGHPART_TO_U32(bus)); | |
2331 | while (len) { | |
2332 | u8 flags_next; | |
2333 | int cum_len_next; | |
2334 | ||
2335 | if (unlikely(count == max_segments)) | |
2336 | goto abort_linearize; | |
2337 | ||
2338 | boundary = (low + tx->boundary) & ~(tx->boundary - 1); | |
2339 | seglen = boundary - low; | |
2340 | if (seglen > len) | |
2341 | seglen = len; | |
2342 | flags_next = flags & ~MXGEFW_FLAGS_FIRST; | |
2343 | cum_len_next = cum_len + seglen; | |
0da34b6d BG |
2344 | if (mss) { /* TSO */ |
2345 | (req - rdma_count)->rdma_count = rdma_count + 1; | |
2346 | ||
2347 | if (likely(cum_len >= 0)) { /* payload */ | |
2348 | int next_is_first, chop; | |
2349 | ||
2350 | chop = (cum_len_next > mss); | |
2351 | cum_len_next = cum_len_next % mss; | |
2352 | next_is_first = (cum_len_next == 0); | |
2353 | flags |= chop * MXGEFW_FLAGS_TSO_CHOP; | |
2354 | flags_next |= next_is_first * | |
2355 | MXGEFW_FLAGS_FIRST; | |
2356 | rdma_count |= -(chop | next_is_first); | |
2357 | rdma_count += chop & !next_is_first; | |
2358 | } else if (likely(cum_len_next >= 0)) { /* header ends */ | |
2359 | int small; | |
2360 | ||
2361 | rdma_count = -1; | |
2362 | cum_len_next = 0; | |
2363 | seglen = -cum_len; | |
2364 | small = (mss <= MXGEFW_SEND_SMALL_SIZE); | |
2365 | flags_next = MXGEFW_FLAGS_TSO_PLD | | |
2366 | MXGEFW_FLAGS_FIRST | | |
2367 | (small * MXGEFW_FLAGS_SMALL); | |
2368 | } | |
2369 | } | |
0da34b6d BG |
2370 | req->addr_high = high_swapped; |
2371 | req->addr_low = htonl(low); | |
40f6cff5 | 2372 | req->pseudo_hdr_offset = htons(pseudo_hdr_offset); |
0da34b6d BG |
2373 | req->pad = 0; /* complete solid 16-byte block; does this matter? */ |
2374 | req->rdma_count = 1; | |
2375 | req->length = htons(seglen); | |
2376 | req->cksum_offset = cksum_offset; | |
2377 | req->flags = flags | ((cum_len & 1) * odd_flag); | |
2378 | ||
2379 | low += seglen; | |
2380 | len -= seglen; | |
2381 | cum_len = cum_len_next; | |
2382 | flags = flags_next; | |
2383 | req++; | |
2384 | count++; | |
2385 | rdma_count++; | |
4f93fde0 BG |
2386 | if (cksum_offset != 0 && !(mss && skb_is_gso_v6(skb))) { |
2387 | if (unlikely(cksum_offset > seglen)) | |
2388 | cksum_offset -= seglen; | |
2389 | else | |
2390 | cksum_offset = 0; | |
2391 | } | |
0da34b6d BG |
2392 | } |
2393 | if (frag_idx == frag_cnt) | |
2394 | break; | |
2395 | ||
2396 | /* map next fragment for DMA */ | |
2397 | idx = (count + tx->req) & tx->mask; | |
2398 | frag = &skb_shinfo(skb)->frags[frag_idx]; | |
2399 | frag_idx++; | |
2400 | len = frag->size; | |
2401 | bus = pci_map_page(mgp->pdev, frag->page, frag->page_offset, | |
2402 | len, PCI_DMA_TODEVICE); | |
2403 | pci_unmap_addr_set(&tx->info[idx], bus, bus); | |
2404 | pci_unmap_len_set(&tx->info[idx], len, len); | |
2405 | } | |
2406 | ||
2407 | (req - rdma_count)->rdma_count = rdma_count; | |
0da34b6d BG |
2408 | if (mss) |
2409 | do { | |
2410 | req--; | |
2411 | req->flags |= MXGEFW_FLAGS_TSO_LAST; | |
2412 | } while (!(req->flags & (MXGEFW_FLAGS_TSO_CHOP | | |
2413 | MXGEFW_FLAGS_FIRST))); | |
0da34b6d BG |
2414 | idx = ((count - 1) + tx->req) & tx->mask; |
2415 | tx->info[idx].last = 1; | |
2416 | if (tx->wc_fifo == NULL) | |
2417 | myri10ge_submit_req(tx, tx->req_list, count); | |
2418 | else | |
2419 | myri10ge_submit_req_wc(tx, tx->req_list, count); | |
2420 | tx->pkt_start++; | |
2421 | if ((avail - count) < MXGEFW_MAX_SEND_DESC) { | |
2422 | mgp->stop_queue++; | |
2423 | netif_stop_queue(dev); | |
2424 | } | |
2425 | dev->trans_start = jiffies; | |
2426 | return 0; | |
2427 | ||
2428 | abort_linearize: | |
2429 | /* Free any DMA resources we've alloced and clear out the skb | |
2430 | * slot so as to not trip up assertions, and to avoid a | |
2431 | * double-free if linearizing fails */ | |
2432 | ||
2433 | last_idx = (idx + 1) & tx->mask; | |
2434 | idx = tx->req & tx->mask; | |
2435 | tx->info[idx].skb = NULL; | |
2436 | do { | |
2437 | len = pci_unmap_len(&tx->info[idx], len); | |
2438 | if (len) { | |
2439 | if (tx->info[idx].skb != NULL) | |
2440 | pci_unmap_single(mgp->pdev, | |
2441 | pci_unmap_addr(&tx->info[idx], | |
2442 | bus), len, | |
2443 | PCI_DMA_TODEVICE); | |
2444 | else | |
2445 | pci_unmap_page(mgp->pdev, | |
2446 | pci_unmap_addr(&tx->info[idx], | |
2447 | bus), len, | |
2448 | PCI_DMA_TODEVICE); | |
2449 | pci_unmap_len_set(&tx->info[idx], len, 0); | |
2450 | tx->info[idx].skb = NULL; | |
2451 | } | |
2452 | idx = (idx + 1) & tx->mask; | |
2453 | } while (idx != last_idx); | |
89114afd | 2454 | if (skb_is_gso(skb)) { |
0da34b6d BG |
2455 | printk(KERN_ERR |
2456 | "myri10ge: %s: TSO but wanted to linearize?!?!?\n", | |
2457 | mgp->dev->name); | |
2458 | goto drop; | |
2459 | } | |
2460 | ||
bec0e859 | 2461 | if (skb_linearize(skb)) |
0da34b6d BG |
2462 | goto drop; |
2463 | ||
2464 | mgp->tx_linearized++; | |
2465 | goto again; | |
2466 | ||
2467 | drop: | |
2468 | dev_kfree_skb_any(skb); | |
2469 | mgp->stats.tx_dropped += 1; | |
2470 | return 0; | |
2471 | ||
2472 | } | |
2473 | ||
4f93fde0 BG |
2474 | static int myri10ge_sw_tso(struct sk_buff *skb, struct net_device *dev) |
2475 | { | |
2476 | struct sk_buff *segs, *curr; | |
2477 | struct myri10ge_priv *mgp = dev->priv; | |
2478 | int status; | |
2479 | ||
2480 | segs = skb_gso_segment(skb, dev->features & ~NETIF_F_TSO6); | |
801678c5 | 2481 | if (IS_ERR(segs)) |
4f93fde0 BG |
2482 | goto drop; |
2483 | ||
2484 | while (segs) { | |
2485 | curr = segs; | |
2486 | segs = segs->next; | |
2487 | curr->next = NULL; | |
2488 | status = myri10ge_xmit(curr, dev); | |
2489 | if (status != 0) { | |
2490 | dev_kfree_skb_any(curr); | |
2491 | if (segs != NULL) { | |
2492 | curr = segs; | |
2493 | segs = segs->next; | |
2494 | curr->next = NULL; | |
2495 | dev_kfree_skb_any(segs); | |
2496 | } | |
2497 | goto drop; | |
2498 | } | |
2499 | } | |
2500 | dev_kfree_skb_any(skb); | |
2501 | return 0; | |
2502 | ||
2503 | drop: | |
2504 | dev_kfree_skb_any(skb); | |
2505 | mgp->stats.tx_dropped += 1; | |
2506 | return 0; | |
2507 | } | |
2508 | ||
0da34b6d BG |
2509 | static struct net_device_stats *myri10ge_get_stats(struct net_device *dev) |
2510 | { | |
2511 | struct myri10ge_priv *mgp = netdev_priv(dev); | |
2512 | return &mgp->stats; | |
2513 | } | |
2514 | ||
2515 | static void myri10ge_set_multicast_list(struct net_device *dev) | |
2516 | { | |
85a7ea1b BG |
2517 | struct myri10ge_cmd cmd; |
2518 | struct myri10ge_priv *mgp; | |
2519 | struct dev_mc_list *mc_list; | |
6250223e | 2520 | __be32 data[2] = { 0, 0 }; |
85a7ea1b | 2521 | int err; |
0795af57 | 2522 | DECLARE_MAC_BUF(mac); |
85a7ea1b BG |
2523 | |
2524 | mgp = netdev_priv(dev); | |
0da34b6d BG |
2525 | /* can be called from atomic contexts, |
2526 | * pass 1 to force atomicity in myri10ge_send_cmd() */ | |
85a7ea1b BG |
2527 | myri10ge_change_promisc(mgp, dev->flags & IFF_PROMISC, 1); |
2528 | ||
2529 | /* This firmware is known to not support multicast */ | |
2f76216f | 2530 | if (!mgp->fw_multicast_support) |
85a7ea1b BG |
2531 | return; |
2532 | ||
2533 | /* Disable multicast filtering */ | |
2534 | ||
2535 | err = myri10ge_send_cmd(mgp, MXGEFW_ENABLE_ALLMULTI, &cmd, 1); | |
2536 | if (err != 0) { | |
2537 | printk(KERN_ERR "myri10ge: %s: Failed MXGEFW_ENABLE_ALLMULTI," | |
2538 | " error status: %d\n", dev->name, err); | |
2539 | goto abort; | |
2540 | } | |
2541 | ||
2f76216f | 2542 | if ((dev->flags & IFF_ALLMULTI) || mgp->adopted_rx_filter_bug) { |
85a7ea1b BG |
2543 | /* request to disable multicast filtering, so quit here */ |
2544 | return; | |
2545 | } | |
2546 | ||
2547 | /* Flush the filters */ | |
2548 | ||
2549 | err = myri10ge_send_cmd(mgp, MXGEFW_LEAVE_ALL_MULTICAST_GROUPS, | |
2550 | &cmd, 1); | |
2551 | if (err != 0) { | |
2552 | printk(KERN_ERR | |
2553 | "myri10ge: %s: Failed MXGEFW_LEAVE_ALL_MULTICAST_GROUPS" | |
2554 | ", error status: %d\n", dev->name, err); | |
2555 | goto abort; | |
2556 | } | |
2557 | ||
2558 | /* Walk the multicast list, and add each address */ | |
2559 | for (mc_list = dev->mc_list; mc_list != NULL; mc_list = mc_list->next) { | |
40f6cff5 AV |
2560 | memcpy(data, &mc_list->dmi_addr, 6); |
2561 | cmd.data0 = ntohl(data[0]); | |
2562 | cmd.data1 = ntohl(data[1]); | |
85a7ea1b BG |
2563 | err = myri10ge_send_cmd(mgp, MXGEFW_JOIN_MULTICAST_GROUP, |
2564 | &cmd, 1); | |
2565 | ||
2566 | if (err != 0) { | |
2567 | printk(KERN_ERR "myri10ge: %s: Failed " | |
2568 | "MXGEFW_JOIN_MULTICAST_GROUP, error status:" | |
2569 | "%d\t", dev->name, err); | |
0795af57 JP |
2570 | printk(KERN_ERR "MAC %s\n", |
2571 | print_mac(mac, mc_list->dmi_addr)); | |
85a7ea1b BG |
2572 | goto abort; |
2573 | } | |
2574 | } | |
2575 | /* Enable multicast filtering */ | |
2576 | err = myri10ge_send_cmd(mgp, MXGEFW_DISABLE_ALLMULTI, &cmd, 1); | |
2577 | if (err != 0) { | |
2578 | printk(KERN_ERR "myri10ge: %s: Failed MXGEFW_DISABLE_ALLMULTI," | |
2579 | "error status: %d\n", dev->name, err); | |
2580 | goto abort; | |
2581 | } | |
2582 | ||
2583 | return; | |
2584 | ||
2585 | abort: | |
2586 | return; | |
0da34b6d BG |
2587 | } |
2588 | ||
2589 | static int myri10ge_set_mac_address(struct net_device *dev, void *addr) | |
2590 | { | |
2591 | struct sockaddr *sa = addr; | |
2592 | struct myri10ge_priv *mgp = netdev_priv(dev); | |
2593 | int status; | |
2594 | ||
2595 | if (!is_valid_ether_addr(sa->sa_data)) | |
2596 | return -EADDRNOTAVAIL; | |
2597 | ||
2598 | status = myri10ge_update_mac_address(mgp, sa->sa_data); | |
2599 | if (status != 0) { | |
2600 | printk(KERN_ERR | |
2601 | "myri10ge: %s: changing mac address failed with %d\n", | |
2602 | dev->name, status); | |
2603 | return status; | |
2604 | } | |
2605 | ||
2606 | /* change the dev structure */ | |
2607 | memcpy(dev->dev_addr, sa->sa_data, 6); | |
2608 | return 0; | |
2609 | } | |
2610 | ||
2611 | static int myri10ge_change_mtu(struct net_device *dev, int new_mtu) | |
2612 | { | |
2613 | struct myri10ge_priv *mgp = netdev_priv(dev); | |
2614 | int error = 0; | |
2615 | ||
2616 | if ((new_mtu < 68) || (ETH_HLEN + new_mtu > MYRI10GE_MAX_ETHER_MTU)) { | |
2617 | printk(KERN_ERR "myri10ge: %s: new mtu (%d) is not valid\n", | |
2618 | dev->name, new_mtu); | |
2619 | return -EINVAL; | |
2620 | } | |
2621 | printk(KERN_INFO "%s: changing mtu from %d to %d\n", | |
2622 | dev->name, dev->mtu, new_mtu); | |
2623 | if (mgp->running) { | |
2624 | /* if we change the mtu on an active device, we must | |
2625 | * reset the device so the firmware sees the change */ | |
2626 | myri10ge_close(dev); | |
2627 | dev->mtu = new_mtu; | |
2628 | myri10ge_open(dev); | |
2629 | } else | |
2630 | dev->mtu = new_mtu; | |
2631 | ||
2632 | return error; | |
2633 | } | |
2634 | ||
2635 | /* | |
2636 | * Enable ECRC to align PCI-E Completion packets on an 8-byte boundary. | |
2637 | * Only do it if the bridge is a root port since we don't want to disturb | |
2638 | * any other device, except if forced with myri10ge_ecrc_enable > 1. | |
2639 | */ | |
2640 | ||
0da34b6d BG |
2641 | static void myri10ge_enable_ecrc(struct myri10ge_priv *mgp) |
2642 | { | |
2643 | struct pci_dev *bridge = mgp->pdev->bus->self; | |
2644 | struct device *dev = &mgp->pdev->dev; | |
2645 | unsigned cap; | |
2646 | unsigned err_cap; | |
2647 | u16 val; | |
2648 | u8 ext_type; | |
2649 | int ret; | |
2650 | ||
2651 | if (!myri10ge_ecrc_enable || !bridge) | |
2652 | return; | |
2653 | ||
2654 | /* check that the bridge is a root port */ | |
2655 | cap = pci_find_capability(bridge, PCI_CAP_ID_EXP); | |
2656 | pci_read_config_word(bridge, cap + PCI_CAP_FLAGS, &val); | |
2657 | ext_type = (val & PCI_EXP_FLAGS_TYPE) >> 4; | |
2658 | if (ext_type != PCI_EXP_TYPE_ROOT_PORT) { | |
2659 | if (myri10ge_ecrc_enable > 1) { | |
2660 | struct pci_dev *old_bridge = bridge; | |
2661 | ||
2662 | /* Walk the hierarchy up to the root port | |
2663 | * where ECRC has to be enabled */ | |
2664 | do { | |
2665 | bridge = bridge->bus->self; | |
2666 | if (!bridge) { | |
2667 | dev_err(dev, | |
2668 | "Failed to find root port" | |
2669 | " to force ECRC\n"); | |
2670 | return; | |
2671 | } | |
2672 | cap = | |
2673 | pci_find_capability(bridge, PCI_CAP_ID_EXP); | |
2674 | pci_read_config_word(bridge, | |
2675 | cap + PCI_CAP_FLAGS, &val); | |
2676 | ext_type = (val & PCI_EXP_FLAGS_TYPE) >> 4; | |
2677 | } while (ext_type != PCI_EXP_TYPE_ROOT_PORT); | |
2678 | ||
2679 | dev_info(dev, | |
2680 | "Forcing ECRC on non-root port %s" | |
2681 | " (enabling on root port %s)\n", | |
2682 | pci_name(old_bridge), pci_name(bridge)); | |
2683 | } else { | |
2684 | dev_err(dev, | |
2685 | "Not enabling ECRC on non-root port %s\n", | |
2686 | pci_name(bridge)); | |
2687 | return; | |
2688 | } | |
2689 | } | |
2690 | ||
2691 | cap = pci_find_ext_capability(bridge, PCI_EXT_CAP_ID_ERR); | |
0da34b6d BG |
2692 | if (!cap) |
2693 | return; | |
2694 | ||
2695 | ret = pci_read_config_dword(bridge, cap + PCI_ERR_CAP, &err_cap); | |
2696 | if (ret) { | |
2697 | dev_err(dev, "failed reading ext-conf-space of %s\n", | |
2698 | pci_name(bridge)); | |
2699 | dev_err(dev, "\t pci=nommconf in use? " | |
2700 | "or buggy/incomplete/absent ACPI MCFG attr?\n"); | |
2701 | return; | |
2702 | } | |
2703 | if (!(err_cap & PCI_ERR_CAP_ECRC_GENC)) | |
2704 | return; | |
2705 | ||
2706 | err_cap |= PCI_ERR_CAP_ECRC_GENE; | |
2707 | pci_write_config_dword(bridge, cap + PCI_ERR_CAP, err_cap); | |
2708 | dev_info(dev, "Enabled ECRC on upstream bridge %s\n", pci_name(bridge)); | |
0da34b6d BG |
2709 | } |
2710 | ||
2711 | /* | |
2712 | * The Lanai Z8E PCI-E interface achieves higher Read-DMA throughput | |
2713 | * when the PCI-E Completion packets are aligned on an 8-byte | |
2714 | * boundary. Some PCI-E chip sets always align Completion packets; on | |
2715 | * the ones that do not, the alignment can be enforced by enabling | |
2716 | * ECRC generation (if supported). | |
2717 | * | |
2718 | * When PCI-E Completion packets are not aligned, it is actually more | |
2719 | * efficient to limit Read-DMA transactions to 2KB, rather than 4KB. | |
2720 | * | |
2721 | * If the driver can neither enable ECRC nor verify that it has | |
2722 | * already been enabled, then it must use a firmware image which works | |
2723 | * around unaligned completion packets (myri10ge_ethp_z8e.dat), and it | |
2724 | * should also ensure that it never gives the device a Read-DMA which is | |
2725 | * larger than 2KB by setting the tx.boundary to 2KB. If ECRC is | |
2726 | * enabled, then the driver should use the aligned (myri10ge_eth_z8e.dat) | |
2727 | * firmware image, and set tx.boundary to 4KB. | |
2728 | */ | |
2729 | ||
5443e9ea | 2730 | static void myri10ge_firmware_probe(struct myri10ge_priv *mgp) |
0da34b6d | 2731 | { |
5443e9ea BG |
2732 | struct pci_dev *pdev = mgp->pdev; |
2733 | struct device *dev = &pdev->dev; | |
302d242c | 2734 | int status; |
0da34b6d | 2735 | |
5443e9ea BG |
2736 | mgp->tx.boundary = 4096; |
2737 | /* | |
2738 | * Verify the max read request size was set to 4KB | |
2739 | * before trying the test with 4KB. | |
2740 | */ | |
302d242c BG |
2741 | status = pcie_get_readrq(pdev); |
2742 | if (status < 0) { | |
5443e9ea BG |
2743 | dev_err(dev, "Couldn't read max read req size: %d\n", status); |
2744 | goto abort; | |
2745 | } | |
302d242c BG |
2746 | if (status != 4096) { |
2747 | dev_warn(dev, "Max Read Request size != 4096 (%d)\n", status); | |
5443e9ea BG |
2748 | mgp->tx.boundary = 2048; |
2749 | } | |
2750 | /* | |
2751 | * load the optimized firmware (which assumes aligned PCIe | |
2752 | * completions) in order to see if it works on this host. | |
2753 | */ | |
2754 | mgp->fw_name = myri10ge_fw_aligned; | |
2755 | status = myri10ge_load_firmware(mgp); | |
2756 | if (status != 0) { | |
2757 | goto abort; | |
2758 | } | |
2759 | ||
2760 | /* | |
2761 | * Enable ECRC if possible | |
2762 | */ | |
2763 | myri10ge_enable_ecrc(mgp); | |
2764 | ||
2765 | /* | |
2766 | * Run a DMA test which watches for unaligned completions and | |
2767 | * aborts on the first one seen. | |
2768 | */ | |
2769 | ||
2770 | status = myri10ge_dma_test(mgp, MXGEFW_CMD_UNALIGNED_TEST); | |
2771 | if (status == 0) | |
2772 | return; /* keep the aligned firmware */ | |
2773 | ||
2774 | if (status != -E2BIG) | |
2775 | dev_warn(dev, "DMA test failed: %d\n", status); | |
2776 | if (status == -ENOSYS) | |
2777 | dev_warn(dev, "Falling back to ethp! " | |
2778 | "Please install up to date fw\n"); | |
2779 | abort: | |
2780 | /* fall back to using the unaligned firmware */ | |
0da34b6d BG |
2781 | mgp->tx.boundary = 2048; |
2782 | mgp->fw_name = myri10ge_fw_unaligned; | |
2783 | ||
5443e9ea BG |
2784 | } |
2785 | ||
2786 | static void myri10ge_select_firmware(struct myri10ge_priv *mgp) | |
2787 | { | |
0da34b6d | 2788 | if (myri10ge_force_firmware == 0) { |
ce7f9368 BG |
2789 | int link_width, exp_cap; |
2790 | u16 lnk; | |
2791 | ||
2792 | exp_cap = pci_find_capability(mgp->pdev, PCI_CAP_ID_EXP); | |
2793 | pci_read_config_word(mgp->pdev, exp_cap + PCI_EXP_LNKSTA, &lnk); | |
2794 | link_width = (lnk >> 4) & 0x3f; | |
2795 | ||
ce7f9368 BG |
2796 | /* Check to see if Link is less than 8 or if the |
2797 | * upstream bridge is known to provide aligned | |
2798 | * completions */ | |
2799 | if (link_width < 8) { | |
2800 | dev_info(&mgp->pdev->dev, "PCIE x%d Link\n", | |
2801 | link_width); | |
2802 | mgp->tx.boundary = 4096; | |
2803 | mgp->fw_name = myri10ge_fw_aligned; | |
5443e9ea BG |
2804 | } else { |
2805 | myri10ge_firmware_probe(mgp); | |
0da34b6d BG |
2806 | } |
2807 | } else { | |
2808 | if (myri10ge_force_firmware == 1) { | |
2809 | dev_info(&mgp->pdev->dev, | |
2810 | "Assuming aligned completions (forced)\n"); | |
2811 | mgp->tx.boundary = 4096; | |
2812 | mgp->fw_name = myri10ge_fw_aligned; | |
2813 | } else { | |
2814 | dev_info(&mgp->pdev->dev, | |
2815 | "Assuming unaligned completions (forced)\n"); | |
2816 | mgp->tx.boundary = 2048; | |
2817 | mgp->fw_name = myri10ge_fw_unaligned; | |
2818 | } | |
2819 | } | |
2820 | if (myri10ge_fw_name != NULL) { | |
2821 | dev_info(&mgp->pdev->dev, "overriding firmware to %s\n", | |
2822 | myri10ge_fw_name); | |
2823 | mgp->fw_name = myri10ge_fw_name; | |
2824 | } | |
2825 | } | |
2826 | ||
0da34b6d | 2827 | #ifdef CONFIG_PM |
0da34b6d BG |
2828 | static int myri10ge_suspend(struct pci_dev *pdev, pm_message_t state) |
2829 | { | |
2830 | struct myri10ge_priv *mgp; | |
2831 | struct net_device *netdev; | |
2832 | ||
2833 | mgp = pci_get_drvdata(pdev); | |
2834 | if (mgp == NULL) | |
2835 | return -EINVAL; | |
2836 | netdev = mgp->dev; | |
2837 | ||
2838 | netif_device_detach(netdev); | |
2839 | if (netif_running(netdev)) { | |
2840 | printk(KERN_INFO "myri10ge: closing %s\n", netdev->name); | |
2841 | rtnl_lock(); | |
2842 | myri10ge_close(netdev); | |
2843 | rtnl_unlock(); | |
2844 | } | |
2845 | myri10ge_dummy_rdma(mgp, 0); | |
83f6e152 | 2846 | pci_save_state(pdev); |
0da34b6d | 2847 | pci_disable_device(pdev); |
1a63e846 BG |
2848 | |
2849 | return pci_set_power_state(pdev, pci_choose_state(pdev, state)); | |
0da34b6d BG |
2850 | } |
2851 | ||
2852 | static int myri10ge_resume(struct pci_dev *pdev) | |
2853 | { | |
2854 | struct myri10ge_priv *mgp; | |
2855 | struct net_device *netdev; | |
2856 | int status; | |
2857 | u16 vendor; | |
2858 | ||
2859 | mgp = pci_get_drvdata(pdev); | |
2860 | if (mgp == NULL) | |
2861 | return -EINVAL; | |
2862 | netdev = mgp->dev; | |
2863 | pci_set_power_state(pdev, 0); /* zeros conf space as a side effect */ | |
2864 | msleep(5); /* give card time to respond */ | |
2865 | pci_read_config_word(mgp->pdev, PCI_VENDOR_ID, &vendor); | |
2866 | if (vendor == 0xffff) { | |
2867 | printk(KERN_ERR "myri10ge: %s: device disappeared!\n", | |
2868 | mgp->dev->name); | |
2869 | return -EIO; | |
2870 | } | |
83f6e152 | 2871 | |
1a63e846 BG |
2872 | status = pci_restore_state(pdev); |
2873 | if (status) | |
2874 | return status; | |
4c2248cc BG |
2875 | |
2876 | status = pci_enable_device(pdev); | |
1a63e846 | 2877 | if (status) { |
4c2248cc | 2878 | dev_err(&pdev->dev, "failed to enable device\n"); |
1a63e846 | 2879 | return status; |
4c2248cc BG |
2880 | } |
2881 | ||
0da34b6d BG |
2882 | pci_set_master(pdev); |
2883 | ||
0da34b6d | 2884 | myri10ge_reset(mgp); |
013b68bf | 2885 | myri10ge_dummy_rdma(mgp, 1); |
0da34b6d BG |
2886 | |
2887 | /* Save configuration space to be restored if the | |
2888 | * nic resets due to a parity error */ | |
83f6e152 | 2889 | pci_save_state(pdev); |
0da34b6d BG |
2890 | |
2891 | if (netif_running(netdev)) { | |
2892 | rtnl_lock(); | |
df30a740 | 2893 | status = myri10ge_open(netdev); |
0da34b6d | 2894 | rtnl_unlock(); |
df30a740 BG |
2895 | if (status != 0) |
2896 | goto abort_with_enabled; | |
2897 | ||
0da34b6d BG |
2898 | } |
2899 | netif_device_attach(netdev); | |
2900 | ||
2901 | return 0; | |
2902 | ||
4c2248cc BG |
2903 | abort_with_enabled: |
2904 | pci_disable_device(pdev); | |
0da34b6d BG |
2905 | return -EIO; |
2906 | ||
2907 | } | |
0da34b6d BG |
2908 | #endif /* CONFIG_PM */ |
2909 | ||
2910 | static u32 myri10ge_read_reboot(struct myri10ge_priv *mgp) | |
2911 | { | |
2912 | struct pci_dev *pdev = mgp->pdev; | |
2913 | int vs = mgp->vendor_specific_offset; | |
2914 | u32 reboot; | |
2915 | ||
2916 | /*enter read32 mode */ | |
2917 | pci_write_config_byte(pdev, vs + 0x10, 0x3); | |
2918 | ||
2919 | /*read REBOOT_STATUS (0xfffffff0) */ | |
2920 | pci_write_config_dword(pdev, vs + 0x18, 0xfffffff0); | |
2921 | pci_read_config_dword(pdev, vs + 0x14, &reboot); | |
2922 | return reboot; | |
2923 | } | |
2924 | ||
2925 | /* | |
2926 | * This watchdog is used to check whether the board has suffered | |
2927 | * from a parity error and needs to be recovered. | |
2928 | */ | |
c4028958 | 2929 | static void myri10ge_watchdog(struct work_struct *work) |
0da34b6d | 2930 | { |
c4028958 | 2931 | struct myri10ge_priv *mgp = |
6250223e | 2932 | container_of(work, struct myri10ge_priv, watchdog_work); |
0da34b6d BG |
2933 | u32 reboot; |
2934 | int status; | |
2935 | u16 cmd, vendor; | |
2936 | ||
2937 | mgp->watchdog_resets++; | |
2938 | pci_read_config_word(mgp->pdev, PCI_COMMAND, &cmd); | |
2939 | if ((cmd & PCI_COMMAND_MASTER) == 0) { | |
2940 | /* Bus master DMA disabled? Check to see | |
2941 | * if the card rebooted due to a parity error | |
2942 | * For now, just report it */ | |
2943 | reboot = myri10ge_read_reboot(mgp); | |
2944 | printk(KERN_ERR | |
f181137f BG |
2945 | "myri10ge: %s: NIC rebooted (0x%x),%s resetting\n", |
2946 | mgp->dev->name, reboot, | |
2947 | myri10ge_reset_recover ? " " : " not"); | |
2948 | if (myri10ge_reset_recover == 0) | |
2949 | return; | |
2950 | ||
2951 | myri10ge_reset_recover--; | |
2952 | ||
0da34b6d BG |
2953 | /* |
2954 | * A rebooted nic will come back with config space as | |
2955 | * it was after power was applied to PCIe bus. | |
2956 | * Attempt to restore config space which was saved | |
2957 | * when the driver was loaded, or the last time the | |
2958 | * nic was resumed from power saving mode. | |
2959 | */ | |
83f6e152 | 2960 | pci_restore_state(mgp->pdev); |
7adda30c BG |
2961 | |
2962 | /* save state again for accounting reasons */ | |
83f6e152 | 2963 | pci_save_state(mgp->pdev); |
7adda30c | 2964 | |
0da34b6d BG |
2965 | } else { |
2966 | /* if we get back -1's from our slot, perhaps somebody | |
2967 | * powered off our card. Don't try to reset it in | |
2968 | * this case */ | |
2969 | if (cmd == 0xffff) { | |
2970 | pci_read_config_word(mgp->pdev, PCI_VENDOR_ID, &vendor); | |
2971 | if (vendor == 0xffff) { | |
2972 | printk(KERN_ERR | |
2973 | "myri10ge: %s: device disappeared!\n", | |
2974 | mgp->dev->name); | |
2975 | return; | |
2976 | } | |
2977 | } | |
2978 | /* Perhaps it is a software error. Try to reset */ | |
2979 | ||
2980 | printk(KERN_ERR "myri10ge: %s: device timeout, resetting\n", | |
2981 | mgp->dev->name); | |
2982 | printk(KERN_INFO "myri10ge: %s: %d %d %d %d %d\n", | |
2983 | mgp->dev->name, mgp->tx.req, mgp->tx.done, | |
2984 | mgp->tx.pkt_start, mgp->tx.pkt_done, | |
2985 | (int)ntohl(mgp->fw_stats->send_done_count)); | |
2986 | msleep(2000); | |
2987 | printk(KERN_INFO "myri10ge: %s: %d %d %d %d %d\n", | |
2988 | mgp->dev->name, mgp->tx.req, mgp->tx.done, | |
2989 | mgp->tx.pkt_start, mgp->tx.pkt_done, | |
2990 | (int)ntohl(mgp->fw_stats->send_done_count)); | |
2991 | } | |
2992 | rtnl_lock(); | |
2993 | myri10ge_close(mgp->dev); | |
2994 | status = myri10ge_load_firmware(mgp); | |
2995 | if (status != 0) | |
2996 | printk(KERN_ERR "myri10ge: %s: failed to load firmware\n", | |
2997 | mgp->dev->name); | |
2998 | else | |
2999 | myri10ge_open(mgp->dev); | |
3000 | rtnl_unlock(); | |
3001 | } | |
3002 | ||
3003 | /* | |
3004 | * We use our own timer routine rather than relying upon | |
3005 | * netdev->tx_timeout because we have a very large hardware transmit | |
3006 | * queue. Due to the large queue, the netdev->tx_timeout function | |
3007 | * cannot detect a NIC with a parity error in a timely fashion if the | |
3008 | * NIC is lightly loaded. | |
3009 | */ | |
3010 | static void myri10ge_watchdog_timer(unsigned long arg) | |
3011 | { | |
3012 | struct myri10ge_priv *mgp; | |
626fda94 | 3013 | u32 rx_pause_cnt; |
0da34b6d BG |
3014 | |
3015 | mgp = (struct myri10ge_priv *)arg; | |
c7dab99b BG |
3016 | |
3017 | if (mgp->rx_small.watchdog_needed) { | |
3018 | myri10ge_alloc_rx_pages(mgp, &mgp->rx_small, | |
3019 | mgp->small_bytes + MXGEFW_PAD, 1); | |
3020 | if (mgp->rx_small.fill_cnt - mgp->rx_small.cnt >= | |
3021 | myri10ge_fill_thresh) | |
3022 | mgp->rx_small.watchdog_needed = 0; | |
3023 | } | |
3024 | if (mgp->rx_big.watchdog_needed) { | |
3025 | myri10ge_alloc_rx_pages(mgp, &mgp->rx_big, mgp->big_bytes, 1); | |
3026 | if (mgp->rx_big.fill_cnt - mgp->rx_big.cnt >= | |
3027 | myri10ge_fill_thresh) | |
3028 | mgp->rx_big.watchdog_needed = 0; | |
3029 | } | |
626fda94 | 3030 | rx_pause_cnt = ntohl(mgp->fw_stats->dropped_pause); |
c7dab99b | 3031 | |
0da34b6d | 3032 | if (mgp->tx.req != mgp->tx.done && |
c54772e7 | 3033 | mgp->tx.done == mgp->watchdog_tx_done && |
626fda94 | 3034 | mgp->watchdog_tx_req != mgp->watchdog_tx_done) { |
0da34b6d | 3035 | /* nic seems like it might be stuck.. */ |
626fda94 BG |
3036 | if (rx_pause_cnt != mgp->watchdog_pause) { |
3037 | if (net_ratelimit()) | |
3038 | printk(KERN_WARNING "myri10ge %s:" | |
3039 | "TX paused, check link partner\n", | |
3040 | mgp->dev->name); | |
3041 | } else { | |
3042 | schedule_work(&mgp->watchdog_work); | |
3043 | return; | |
3044 | } | |
3045 | } | |
3046 | /* rearm timer */ | |
3047 | mod_timer(&mgp->watchdog_timer, | |
3048 | jiffies + myri10ge_watchdog_timeout * HZ); | |
0da34b6d | 3049 | mgp->watchdog_tx_done = mgp->tx.done; |
c54772e7 | 3050 | mgp->watchdog_tx_req = mgp->tx.req; |
626fda94 | 3051 | mgp->watchdog_pause = rx_pause_cnt; |
0da34b6d BG |
3052 | } |
3053 | ||
3054 | static int myri10ge_probe(struct pci_dev *pdev, const struct pci_device_id *ent) | |
3055 | { | |
3056 | struct net_device *netdev; | |
3057 | struct myri10ge_priv *mgp; | |
3058 | struct device *dev = &pdev->dev; | |
3059 | size_t bytes; | |
3060 | int i; | |
3061 | int status = -ENXIO; | |
0da34b6d | 3062 | int dac_enabled; |
0da34b6d BG |
3063 | |
3064 | netdev = alloc_etherdev(sizeof(*mgp)); | |
3065 | if (netdev == NULL) { | |
3066 | dev_err(dev, "Could not allocate ethernet device\n"); | |
3067 | return -ENOMEM; | |
3068 | } | |
3069 | ||
b245fb67 MH |
3070 | SET_NETDEV_DEV(netdev, &pdev->dev); |
3071 | ||
0da34b6d | 3072 | mgp = netdev_priv(netdev); |
0da34b6d | 3073 | mgp->dev = netdev; |
e636b2ea | 3074 | netif_napi_add(netdev, &mgp->napi, myri10ge_poll, myri10ge_napi_weight); |
0da34b6d BG |
3075 | mgp->pdev = pdev; |
3076 | mgp->csum_flag = MXGEFW_FLAGS_CKSUM; | |
3077 | mgp->pause = myri10ge_flow_control; | |
3078 | mgp->intr_coal_delay = myri10ge_intr_coal_delay; | |
c58ac5ca | 3079 | mgp->msg_enable = netif_msg_init(myri10ge_debug, MYRI10GE_MSG_DEFAULT); |
0da34b6d BG |
3080 | init_waitqueue_head(&mgp->down_wq); |
3081 | ||
3082 | if (pci_enable_device(pdev)) { | |
3083 | dev_err(&pdev->dev, "pci_enable_device call failed\n"); | |
3084 | status = -ENODEV; | |
3085 | goto abort_with_netdev; | |
3086 | } | |
0da34b6d BG |
3087 | |
3088 | /* Find the vendor-specific cap so we can check | |
3089 | * the reboot register later on */ | |
3090 | mgp->vendor_specific_offset | |
3091 | = pci_find_capability(pdev, PCI_CAP_ID_VNDR); | |
3092 | ||
3093 | /* Set our max read request to 4KB */ | |
302d242c | 3094 | status = pcie_set_readrq(pdev, 4096); |
0da34b6d BG |
3095 | if (status != 0) { |
3096 | dev_err(&pdev->dev, "Error %d writing PCI_EXP_DEVCTL\n", | |
3097 | status); | |
3098 | goto abort_with_netdev; | |
3099 | } | |
3100 | ||
3101 | pci_set_master(pdev); | |
3102 | dac_enabled = 1; | |
3103 | status = pci_set_dma_mask(pdev, DMA_64BIT_MASK); | |
3104 | if (status != 0) { | |
3105 | dac_enabled = 0; | |
3106 | dev_err(&pdev->dev, | |
898eb71c JP |
3107 | "64-bit pci address mask was refused, " |
3108 | "trying 32-bit\n"); | |
0da34b6d BG |
3109 | status = pci_set_dma_mask(pdev, DMA_32BIT_MASK); |
3110 | } | |
3111 | if (status != 0) { | |
3112 | dev_err(&pdev->dev, "Error %d setting DMA mask\n", status); | |
3113 | goto abort_with_netdev; | |
3114 | } | |
b10c0668 BG |
3115 | mgp->cmd = dma_alloc_coherent(&pdev->dev, sizeof(*mgp->cmd), |
3116 | &mgp->cmd_bus, GFP_KERNEL); | |
0da34b6d BG |
3117 | if (mgp->cmd == NULL) |
3118 | goto abort_with_netdev; | |
3119 | ||
b10c0668 BG |
3120 | mgp->fw_stats = dma_alloc_coherent(&pdev->dev, sizeof(*mgp->fw_stats), |
3121 | &mgp->fw_stats_bus, GFP_KERNEL); | |
0da34b6d BG |
3122 | if (mgp->fw_stats == NULL) |
3123 | goto abort_with_cmd; | |
3124 | ||
3125 | mgp->board_span = pci_resource_len(pdev, 0); | |
3126 | mgp->iomem_base = pci_resource_start(pdev, 0); | |
3127 | mgp->mtrr = -1; | |
276e26c3 | 3128 | mgp->wc_enabled = 0; |
0da34b6d BG |
3129 | #ifdef CONFIG_MTRR |
3130 | mgp->mtrr = mtrr_add(mgp->iomem_base, mgp->board_span, | |
3131 | MTRR_TYPE_WRCOMB, 1); | |
276e26c3 BG |
3132 | if (mgp->mtrr >= 0) |
3133 | mgp->wc_enabled = 1; | |
0da34b6d BG |
3134 | #endif |
3135 | /* Hack. need to get rid of these magic numbers */ | |
3136 | mgp->sram_size = | |
3137 | 2 * 1024 * 1024 - (2 * (48 * 1024) + (32 * 1024)) - 0x100; | |
3138 | if (mgp->sram_size > mgp->board_span) { | |
3139 | dev_err(&pdev->dev, "board span %ld bytes too small\n", | |
3140 | mgp->board_span); | |
3141 | goto abort_with_wc; | |
3142 | } | |
3143 | mgp->sram = ioremap(mgp->iomem_base, mgp->board_span); | |
3144 | if (mgp->sram == NULL) { | |
3145 | dev_err(&pdev->dev, "ioremap failed for %ld bytes at 0x%lx\n", | |
3146 | mgp->board_span, mgp->iomem_base); | |
3147 | status = -ENXIO; | |
3148 | goto abort_with_wc; | |
3149 | } | |
3150 | memcpy_fromio(mgp->eeprom_strings, | |
3151 | mgp->sram + mgp->sram_size - MYRI10GE_EEPROM_STRINGS_SIZE, | |
3152 | MYRI10GE_EEPROM_STRINGS_SIZE); | |
3153 | memset(mgp->eeprom_strings + MYRI10GE_EEPROM_STRINGS_SIZE - 2, 0, 2); | |
3154 | status = myri10ge_read_mac_addr(mgp); | |
3155 | if (status) | |
3156 | goto abort_with_ioremap; | |
3157 | ||
3158 | for (i = 0; i < ETH_ALEN; i++) | |
3159 | netdev->dev_addr[i] = mgp->mac_addr[i]; | |
3160 | ||
3161 | /* allocate rx done ring */ | |
3162 | bytes = myri10ge_max_intr_slots * sizeof(*mgp->rx_done.entry); | |
b10c0668 BG |
3163 | mgp->rx_done.entry = dma_alloc_coherent(&pdev->dev, bytes, |
3164 | &mgp->rx_done.bus, GFP_KERNEL); | |
0da34b6d BG |
3165 | if (mgp->rx_done.entry == NULL) |
3166 | goto abort_with_ioremap; | |
3167 | memset(mgp->rx_done.entry, 0, bytes); | |
3168 | ||
5443e9ea BG |
3169 | myri10ge_select_firmware(mgp); |
3170 | ||
0da34b6d BG |
3171 | status = myri10ge_load_firmware(mgp); |
3172 | if (status != 0) { | |
3173 | dev_err(&pdev->dev, "failed to load firmware\n"); | |
3174 | goto abort_with_rx_done; | |
3175 | } | |
3176 | ||
3177 | status = myri10ge_reset(mgp); | |
3178 | if (status != 0) { | |
3179 | dev_err(&pdev->dev, "failed reset\n"); | |
3180 | goto abort_with_firmware; | |
3181 | } | |
3182 | ||
0da34b6d BG |
3183 | pci_set_drvdata(pdev, mgp); |
3184 | if ((myri10ge_initial_mtu + ETH_HLEN) > MYRI10GE_MAX_ETHER_MTU) | |
3185 | myri10ge_initial_mtu = MYRI10GE_MAX_ETHER_MTU - ETH_HLEN; | |
3186 | if ((myri10ge_initial_mtu + ETH_HLEN) < 68) | |
3187 | myri10ge_initial_mtu = 68; | |
3188 | netdev->mtu = myri10ge_initial_mtu; | |
3189 | netdev->open = myri10ge_open; | |
3190 | netdev->stop = myri10ge_close; | |
3191 | netdev->hard_start_xmit = myri10ge_xmit; | |
3192 | netdev->get_stats = myri10ge_get_stats; | |
3193 | netdev->base_addr = mgp->iomem_base; | |
0da34b6d BG |
3194 | netdev->change_mtu = myri10ge_change_mtu; |
3195 | netdev->set_multicast_list = myri10ge_set_multicast_list; | |
3196 | netdev->set_mac_address = myri10ge_set_mac_address; | |
4f93fde0 | 3197 | netdev->features = mgp->features; |
0da34b6d BG |
3198 | if (dac_enabled) |
3199 | netdev->features |= NETIF_F_HIGHDMA; | |
0da34b6d | 3200 | |
21d05db1 BG |
3201 | /* make sure we can get an irq, and that MSI can be |
3202 | * setup (if available). Also ensure netdev->irq | |
3203 | * is set to correct value if MSI is enabled */ | |
3204 | status = myri10ge_request_irq(mgp); | |
3205 | if (status != 0) | |
3206 | goto abort_with_firmware; | |
3207 | netdev->irq = pdev->irq; | |
3208 | myri10ge_free_irq(mgp); | |
3209 | ||
0da34b6d BG |
3210 | /* Save configuration space to be restored if the |
3211 | * nic resets due to a parity error */ | |
83f6e152 | 3212 | pci_save_state(pdev); |
0da34b6d BG |
3213 | |
3214 | /* Setup the watchdog timer */ | |
3215 | setup_timer(&mgp->watchdog_timer, myri10ge_watchdog_timer, | |
3216 | (unsigned long)mgp); | |
3217 | ||
3218 | SET_ETHTOOL_OPS(netdev, &myri10ge_ethtool_ops); | |
c4028958 | 3219 | INIT_WORK(&mgp->watchdog_work, myri10ge_watchdog); |
0da34b6d BG |
3220 | status = register_netdev(netdev); |
3221 | if (status != 0) { | |
3222 | dev_err(&pdev->dev, "register_netdev failed: %d\n", status); | |
7adda30c | 3223 | goto abort_with_state; |
0da34b6d | 3224 | } |
21d05db1 BG |
3225 | dev_info(dev, "%s IRQ %d, tx bndry %d, fw %s, WC %s\n", |
3226 | (mgp->msi_enabled ? "MSI" : "xPIC"), | |
3227 | netdev->irq, mgp->tx.boundary, mgp->fw_name, | |
276e26c3 | 3228 | (mgp->wc_enabled ? "Enabled" : "Disabled")); |
0da34b6d BG |
3229 | |
3230 | return 0; | |
3231 | ||
7adda30c | 3232 | abort_with_state: |
83f6e152 | 3233 | pci_restore_state(pdev); |
0da34b6d BG |
3234 | |
3235 | abort_with_firmware: | |
3236 | myri10ge_dummy_rdma(mgp, 0); | |
3237 | ||
3238 | abort_with_rx_done: | |
3239 | bytes = myri10ge_max_intr_slots * sizeof(*mgp->rx_done.entry); | |
b10c0668 BG |
3240 | dma_free_coherent(&pdev->dev, bytes, |
3241 | mgp->rx_done.entry, mgp->rx_done.bus); | |
0da34b6d BG |
3242 | |
3243 | abort_with_ioremap: | |
3244 | iounmap(mgp->sram); | |
3245 | ||
3246 | abort_with_wc: | |
3247 | #ifdef CONFIG_MTRR | |
3248 | if (mgp->mtrr >= 0) | |
3249 | mtrr_del(mgp->mtrr, mgp->iomem_base, mgp->board_span); | |
3250 | #endif | |
b10c0668 BG |
3251 | dma_free_coherent(&pdev->dev, sizeof(*mgp->fw_stats), |
3252 | mgp->fw_stats, mgp->fw_stats_bus); | |
0da34b6d BG |
3253 | |
3254 | abort_with_cmd: | |
b10c0668 BG |
3255 | dma_free_coherent(&pdev->dev, sizeof(*mgp->cmd), |
3256 | mgp->cmd, mgp->cmd_bus); | |
0da34b6d BG |
3257 | |
3258 | abort_with_netdev: | |
3259 | ||
3260 | free_netdev(netdev); | |
3261 | return status; | |
3262 | } | |
3263 | ||
3264 | /* | |
3265 | * myri10ge_remove | |
3266 | * | |
3267 | * Does what is necessary to shutdown one Myrinet device. Called | |
3268 | * once for each Myrinet card by the kernel when a module is | |
3269 | * unloaded. | |
3270 | */ | |
3271 | static void myri10ge_remove(struct pci_dev *pdev) | |
3272 | { | |
3273 | struct myri10ge_priv *mgp; | |
3274 | struct net_device *netdev; | |
3275 | size_t bytes; | |
3276 | ||
3277 | mgp = pci_get_drvdata(pdev); | |
3278 | if (mgp == NULL) | |
3279 | return; | |
3280 | ||
3281 | flush_scheduled_work(); | |
3282 | netdev = mgp->dev; | |
3283 | unregister_netdev(netdev); | |
0da34b6d BG |
3284 | |
3285 | myri10ge_dummy_rdma(mgp, 0); | |
3286 | ||
7adda30c | 3287 | /* avoid a memory leak */ |
83f6e152 | 3288 | pci_restore_state(pdev); |
7adda30c | 3289 | |
0da34b6d | 3290 | bytes = myri10ge_max_intr_slots * sizeof(*mgp->rx_done.entry); |
b10c0668 BG |
3291 | dma_free_coherent(&pdev->dev, bytes, |
3292 | mgp->rx_done.entry, mgp->rx_done.bus); | |
0da34b6d BG |
3293 | |
3294 | iounmap(mgp->sram); | |
3295 | ||
3296 | #ifdef CONFIG_MTRR | |
3297 | if (mgp->mtrr >= 0) | |
3298 | mtrr_del(mgp->mtrr, mgp->iomem_base, mgp->board_span); | |
3299 | #endif | |
b10c0668 BG |
3300 | dma_free_coherent(&pdev->dev, sizeof(*mgp->fw_stats), |
3301 | mgp->fw_stats, mgp->fw_stats_bus); | |
0da34b6d | 3302 | |
b10c0668 BG |
3303 | dma_free_coherent(&pdev->dev, sizeof(*mgp->cmd), |
3304 | mgp->cmd, mgp->cmd_bus); | |
0da34b6d BG |
3305 | |
3306 | free_netdev(netdev); | |
3307 | pci_set_drvdata(pdev, NULL); | |
3308 | } | |
3309 | ||
b10c0668 | 3310 | #define PCI_DEVICE_ID_MYRICOM_MYRI10GE_Z8E 0x0008 |
a07bc1ff | 3311 | #define PCI_DEVICE_ID_MYRICOM_MYRI10GE_Z8E_9 0x0009 |
0da34b6d BG |
3312 | |
3313 | static struct pci_device_id myri10ge_pci_tbl[] = { | |
b10c0668 | 3314 | {PCI_DEVICE(PCI_VENDOR_ID_MYRICOM, PCI_DEVICE_ID_MYRICOM_MYRI10GE_Z8E)}, |
a07bc1ff BG |
3315 | {PCI_DEVICE |
3316 | (PCI_VENDOR_ID_MYRICOM, PCI_DEVICE_ID_MYRICOM_MYRI10GE_Z8E_9)}, | |
0da34b6d BG |
3317 | {0}, |
3318 | }; | |
3319 | ||
3320 | static struct pci_driver myri10ge_driver = { | |
3321 | .name = "myri10ge", | |
3322 | .probe = myri10ge_probe, | |
3323 | .remove = myri10ge_remove, | |
3324 | .id_table = myri10ge_pci_tbl, | |
3325 | #ifdef CONFIG_PM | |
3326 | .suspend = myri10ge_suspend, | |
3327 | .resume = myri10ge_resume, | |
3328 | #endif | |
3329 | }; | |
3330 | ||
3331 | static __init int myri10ge_init_module(void) | |
3332 | { | |
3333 | printk(KERN_INFO "%s: Version %s\n", myri10ge_driver.name, | |
3334 | MYRI10GE_VERSION_STR); | |
3335 | return pci_register_driver(&myri10ge_driver); | |
3336 | } | |
3337 | ||
3338 | module_init(myri10ge_init_module); | |
3339 | ||
3340 | static __exit void myri10ge_cleanup_module(void) | |
3341 | { | |
3342 | pci_unregister_driver(&myri10ge_driver); | |
3343 | } | |
3344 | ||
3345 | module_exit(myri10ge_cleanup_module); |