]>
Commit | Line | Data |
---|---|---|
ce6cde92 IPG |
1 | /* |
2 | * Intel Wireless WiMAX Connection 2400m | |
3 | * Glue with the networking stack | |
4 | * | |
5 | * | |
6 | * Copyright (C) 2007 Intel Corporation <linux-wimax@intel.com> | |
7 | * Yanir Lubetkin <yanirx.lubetkin@intel.com> | |
8 | * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> | |
9 | * | |
10 | * This program is free software; you can redistribute it and/or | |
11 | * modify it under the terms of the GNU General Public License version | |
12 | * 2 as published by the Free Software Foundation. | |
13 | * | |
14 | * This program is distributed in the hope that it will be useful, | |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | * GNU General Public License for more details. | |
18 | * | |
19 | * You should have received a copy of the GNU General Public License | |
20 | * along with this program; if not, write to the Free Software | |
21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | |
22 | * 02110-1301, USA. | |
23 | * | |
24 | * | |
25 | * This implements an ethernet device for the i2400m. | |
26 | * | |
27 | * We fake being an ethernet device to simplify the support from user | |
28 | * space and from the other side. The world is (sadly) configured to | |
29 | * take in only Ethernet devices... | |
30 | * | |
fd5c565c IPG |
31 | * Because of this, when using firmwares <= v1.3, there is an |
32 | * copy-each-rxed-packet overhead on the RX path. Each IP packet has | |
33 | * to be reallocated to add an ethernet header (as there is no space | |
34 | * in what we get from the device). This is a known drawback and | |
35 | * firmwares >= 1.4 add header space that can be used to insert the | |
36 | * ethernet header without having to reallocate and copy. | |
ce6cde92 IPG |
37 | * |
38 | * TX error handling is tricky; because we have to FIFO/queue the | |
39 | * buffers for transmission (as the hardware likes it aggregated), we | |
40 | * just give the skb to the TX subsystem and by the time it is | |
41 | * transmitted, we have long forgotten about it. So we just don't care | |
42 | * too much about it. | |
43 | * | |
44 | * Note that when the device is in idle mode with the basestation, we | |
45 | * need to negotiate coming back up online. That involves negotiation | |
46 | * and possible user space interaction. Thus, we defer to a workqueue | |
47 | * to do all that. By default, we only queue a single packet and drop | |
48 | * the rest, as potentially the time to go back from idle to normal is | |
49 | * long. | |
50 | * | |
51 | * ROADMAP | |
52 | * | |
53 | * i2400m_open Called on ifconfig up | |
54 | * i2400m_stop Called on ifconfig down | |
55 | * | |
56 | * i2400m_hard_start_xmit Called by the network stack to send a packet | |
57 | * i2400m_net_wake_tx Wake up device from basestation-IDLE & TX | |
58 | * i2400m_wake_tx_work | |
59 | * i2400m_cmd_exit_idle | |
60 | * i2400m_tx | |
61 | * i2400m_net_tx TX a data frame | |
62 | * i2400m_tx | |
63 | * | |
64 | * i2400m_change_mtu Called on ifconfig mtu XXX | |
65 | * | |
66 | * i2400m_tx_timeout Called when the device times out | |
67 | * | |
68 | * i2400m_net_rx Called by the RX code when a data frame is | |
fd5c565c IPG |
69 | * available (firmware <= 1.3) |
70 | * i2400m_net_erx Called by the RX code when a data frame is | |
71 | * available (firmware >= 1.4). | |
ce6cde92 IPG |
72 | * i2400m_netdev_setup Called to setup all the netdev stuff from |
73 | * alloc_netdev. | |
74 | */ | |
75 | #include <linux/if_arp.h> | |
76 | #include <linux/netdevice.h> | |
abb30733 | 77 | #include <linux/ethtool.h> |
ce6cde92 IPG |
78 | #include "i2400m.h" |
79 | ||
80 | ||
81 | #define D_SUBMODULE netdev | |
82 | #include "debug-levels.h" | |
83 | ||
84 | enum { | |
85 | /* netdev interface */ | |
86 | /* | |
87 | * Out of NWG spec (R1_v1.2.2), 3.3.3 ASN Bearer Plane MTU Size | |
88 | * | |
89 | * The MTU is 1400 or less | |
90 | */ | |
91 | I2400M_MAX_MTU = 1400, | |
92 | I2400M_TX_TIMEOUT = HZ, | |
93 | I2400M_TX_QLEN = 5, | |
94 | }; | |
95 | ||
96 | ||
97 | static | |
98 | int i2400m_open(struct net_device *net_dev) | |
99 | { | |
100 | int result; | |
101 | struct i2400m *i2400m = net_dev_to_i2400m(net_dev); | |
102 | struct device *dev = i2400m_dev(i2400m); | |
103 | ||
104 | d_fnstart(3, dev, "(net_dev %p [i2400m %p])\n", net_dev, i2400m); | |
105 | if (i2400m->ready == 0) { | |
106 | dev_err(dev, "Device is still initializing\n"); | |
107 | result = -EBUSY; | |
108 | } else | |
109 | result = 0; | |
110 | d_fnend(3, dev, "(net_dev %p [i2400m %p]) = %d\n", | |
111 | net_dev, i2400m, result); | |
112 | return result; | |
113 | } | |
114 | ||
115 | ||
ce6cde92 IPG |
116 | static |
117 | int i2400m_stop(struct net_device *net_dev) | |
118 | { | |
119 | struct i2400m *i2400m = net_dev_to_i2400m(net_dev); | |
120 | struct device *dev = i2400m_dev(i2400m); | |
121 | ||
122 | d_fnstart(3, dev, "(net_dev %p [i2400m %p])\n", net_dev, i2400m); | |
ac53aed9 | 123 | i2400m_net_wake_stop(i2400m); |
ce6cde92 IPG |
124 | d_fnend(3, dev, "(net_dev %p [i2400m %p]) = 0\n", net_dev, i2400m); |
125 | return 0; | |
126 | } | |
127 | ||
128 | ||
129 | /* | |
130 | * Wake up the device and transmit a held SKB, then restart the net queue | |
131 | * | |
132 | * When the device goes into basestation-idle mode, we need to tell it | |
133 | * to exit that mode; it will negotiate with the base station, user | |
134 | * space may have to intervene to rehandshake crypto and then tell us | |
135 | * when it is ready to transmit the packet we have "queued". Still we | |
136 | * need to give it sometime after it reports being ok. | |
137 | * | |
138 | * On error, there is not much we can do. If the error was on TX, we | |
139 | * still wake the queue up to see if the next packet will be luckier. | |
140 | * | |
141 | * If _cmd_exit_idle() fails...well, it could be many things; most | |
142 | * commonly it is that something else took the device out of IDLE mode | |
143 | * (for example, the base station). In that case we get an -EILSEQ and | |
144 | * we are just going to ignore that one. If the device is back to | |
145 | * connected, then fine -- if it is someother state, the packet will | |
146 | * be dropped anyway. | |
147 | */ | |
148 | void i2400m_wake_tx_work(struct work_struct *ws) | |
149 | { | |
150 | int result; | |
151 | struct i2400m *i2400m = container_of(ws, struct i2400m, wake_tx_ws); | |
152 | struct device *dev = i2400m_dev(i2400m); | |
153 | struct sk_buff *skb = i2400m->wake_tx_skb; | |
154 | unsigned long flags; | |
155 | ||
156 | spin_lock_irqsave(&i2400m->tx_lock, flags); | |
157 | skb = i2400m->wake_tx_skb; | |
158 | i2400m->wake_tx_skb = NULL; | |
159 | spin_unlock_irqrestore(&i2400m->tx_lock, flags); | |
160 | ||
161 | d_fnstart(3, dev, "(ws %p i2400m %p skb %p)\n", ws, i2400m, skb); | |
162 | result = -EINVAL; | |
163 | if (skb == NULL) { | |
164 | dev_err(dev, "WAKE&TX: skb dissapeared!\n"); | |
165 | goto out_put; | |
166 | } | |
167 | result = i2400m_cmd_exit_idle(i2400m); | |
168 | if (result == -EILSEQ) | |
169 | result = 0; | |
170 | if (result < 0) { | |
171 | dev_err(dev, "WAKE&TX: device didn't get out of idle: " | |
172 | "%d\n", result); | |
173 | goto error; | |
174 | } | |
175 | result = wait_event_timeout(i2400m->state_wq, | |
176 | i2400m->state != I2400M_SS_IDLE, 5 * HZ); | |
177 | if (result == 0) | |
178 | result = -ETIMEDOUT; | |
179 | if (result < 0) { | |
180 | dev_err(dev, "WAKE&TX: error waiting for device to exit IDLE: " | |
181 | "%d\n", result); | |
182 | goto error; | |
183 | } | |
184 | msleep(20); /* device still needs some time or it drops it */ | |
185 | result = i2400m_tx(i2400m, skb->data, skb->len, I2400M_PT_DATA); | |
186 | netif_wake_queue(i2400m->wimax_dev.net_dev); | |
187 | error: | |
188 | kfree_skb(skb); /* refcount transferred by _hard_start_xmit() */ | |
189 | out_put: | |
190 | i2400m_put(i2400m); | |
191 | d_fnend(3, dev, "(ws %p i2400m %p skb %p) = void [%d]\n", | |
192 | ws, i2400m, skb, result); | |
193 | } | |
194 | ||
195 | ||
196 | /* | |
197 | * Prepare the data payload TX header | |
198 | * | |
199 | * The i2400m expects a 4 byte header in front of a data packet. | |
200 | * | |
201 | * Because we pretend to be an ethernet device, this packet comes with | |
202 | * an ethernet header. Pull it and push our header. | |
203 | */ | |
204 | static | |
205 | void i2400m_tx_prep_header(struct sk_buff *skb) | |
206 | { | |
207 | struct i2400m_pl_data_hdr *pl_hdr; | |
208 | skb_pull(skb, ETH_HLEN); | |
209 | pl_hdr = (struct i2400m_pl_data_hdr *) skb_push(skb, sizeof(*pl_hdr)); | |
210 | pl_hdr->reserved = 0; | |
211 | } | |
212 | ||
213 | ||
ac53aed9 IPG |
214 | |
215 | /* | |
216 | * Cleanup resources acquired during i2400m_net_wake_tx() | |
217 | * | |
218 | * This is called by __i2400m_dev_stop and means we have to make sure | |
219 | * the workqueue is flushed from any pending work. | |
220 | */ | |
221 | void i2400m_net_wake_stop(struct i2400m *i2400m) | |
222 | { | |
223 | struct device *dev = i2400m_dev(i2400m); | |
224 | ||
225 | d_fnstart(3, dev, "(i2400m %p)\n", i2400m); | |
226 | /* See i2400m_hard_start_xmit(), references are taken there | |
227 | * and here we release them if the work was still | |
228 | * pending. Note we can't differentiate work not pending vs | |
229 | * never scheduled, so the NULL check does that. */ | |
230 | if (cancel_work_sync(&i2400m->wake_tx_ws) == 0 | |
231 | && i2400m->wake_tx_skb != NULL) { | |
232 | unsigned long flags; | |
233 | struct sk_buff *wake_tx_skb; | |
234 | spin_lock_irqsave(&i2400m->tx_lock, flags); | |
235 | wake_tx_skb = i2400m->wake_tx_skb; /* compat help */ | |
236 | i2400m->wake_tx_skb = NULL; /* compat help */ | |
237 | spin_unlock_irqrestore(&i2400m->tx_lock, flags); | |
238 | i2400m_put(i2400m); | |
239 | kfree_skb(wake_tx_skb); | |
240 | } | |
241 | d_fnend(3, dev, "(i2400m %p) = void\n", i2400m); | |
242 | return; | |
243 | } | |
244 | ||
245 | ||
ce6cde92 IPG |
246 | /* |
247 | * TX an skb to an idle device | |
248 | * | |
249 | * When the device is in basestation-idle mode, we need to wake it up | |
250 | * and then TX. So we queue a work_struct for doing so. | |
251 | * | |
252 | * We need to get an extra ref for the skb (so it is not dropped), as | |
253 | * well as be careful not to queue more than one request (won't help | |
254 | * at all). If more than one request comes or there are errors, we | |
255 | * just drop the packets (see i2400m_hard_start_xmit()). | |
256 | */ | |
257 | static | |
258 | int i2400m_net_wake_tx(struct i2400m *i2400m, struct net_device *net_dev, | |
259 | struct sk_buff *skb) | |
260 | { | |
261 | int result; | |
262 | struct device *dev = i2400m_dev(i2400m); | |
263 | unsigned long flags; | |
264 | ||
265 | d_fnstart(3, dev, "(skb %p net_dev %p)\n", skb, net_dev); | |
266 | if (net_ratelimit()) { | |
267 | d_printf(3, dev, "WAKE&NETTX: " | |
268 | "skb %p sending %d bytes to radio\n", | |
269 | skb, skb->len); | |
270 | d_dump(4, dev, skb->data, skb->len); | |
271 | } | |
272 | /* We hold a ref count for i2400m and skb, so when | |
273 | * stopping() the device, we need to cancel that work | |
274 | * and if pending, release those resources. */ | |
275 | result = 0; | |
276 | spin_lock_irqsave(&i2400m->tx_lock, flags); | |
277 | if (!work_pending(&i2400m->wake_tx_ws)) { | |
278 | netif_stop_queue(net_dev); | |
279 | i2400m_get(i2400m); | |
280 | i2400m->wake_tx_skb = skb_get(skb); /* transfer ref count */ | |
281 | i2400m_tx_prep_header(skb); | |
282 | result = schedule_work(&i2400m->wake_tx_ws); | |
283 | WARN_ON(result == 0); | |
284 | } | |
285 | spin_unlock_irqrestore(&i2400m->tx_lock, flags); | |
286 | if (result == 0) { | |
287 | /* Yes, this happens even if we stopped the | |
288 | * queue -- blame the queue disciplines that | |
289 | * queue without looking -- I guess there is a reason | |
290 | * for that. */ | |
291 | if (net_ratelimit()) | |
292 | d_printf(1, dev, "NETTX: device exiting idle, " | |
293 | "dropping skb %p, queue running %d\n", | |
294 | skb, netif_queue_stopped(net_dev)); | |
295 | result = -EBUSY; | |
296 | } | |
297 | d_fnend(3, dev, "(skb %p net_dev %p) = %d\n", skb, net_dev, result); | |
298 | return result; | |
299 | } | |
300 | ||
301 | ||
302 | /* | |
303 | * Transmit a packet to the base station on behalf of the network stack. | |
304 | * | |
305 | * Returns: 0 if ok, < 0 errno code on error. | |
306 | * | |
307 | * We need to pull the ethernet header and add the hardware header, | |
308 | * which is currently set to all zeroes and reserved. | |
309 | */ | |
310 | static | |
311 | int i2400m_net_tx(struct i2400m *i2400m, struct net_device *net_dev, | |
312 | struct sk_buff *skb) | |
313 | { | |
314 | int result; | |
315 | struct device *dev = i2400m_dev(i2400m); | |
316 | ||
317 | d_fnstart(3, dev, "(i2400m %p net_dev %p skb %p)\n", | |
318 | i2400m, net_dev, skb); | |
319 | /* FIXME: check eth hdr, only IPv4 is routed by the device as of now */ | |
320 | net_dev->trans_start = jiffies; | |
321 | i2400m_tx_prep_header(skb); | |
322 | d_printf(3, dev, "NETTX: skb %p sending %d bytes to radio\n", | |
323 | skb, skb->len); | |
324 | d_dump(4, dev, skb->data, skb->len); | |
325 | result = i2400m_tx(i2400m, skb->data, skb->len, I2400M_PT_DATA); | |
326 | d_fnend(3, dev, "(i2400m %p net_dev %p skb %p) = %d\n", | |
327 | i2400m, net_dev, skb, result); | |
328 | return result; | |
329 | } | |
330 | ||
331 | ||
332 | /* | |
333 | * Transmit a packet to the base station on behalf of the network stack | |
334 | * | |
335 | * | |
336 | * Returns: NETDEV_TX_OK (always, even in case of error) | |
337 | * | |
338 | * In case of error, we just drop it. Reasons: | |
339 | * | |
340 | * - we add a hw header to each skb, and if the network stack | |
341 | * retries, we have no way to know if that skb has it or not. | |
342 | * | |
343 | * - network protocols have their own drop-recovery mechanisms | |
344 | * | |
345 | * - there is not much else we can do | |
346 | * | |
347 | * If the device is idle, we need to wake it up; that is an operation | |
348 | * that will sleep. See i2400m_net_wake_tx() for details. | |
349 | */ | |
350 | static | |
d0cf9c0d SH |
351 | netdev_tx_t i2400m_hard_start_xmit(struct sk_buff *skb, |
352 | struct net_device *net_dev) | |
ce6cde92 | 353 | { |
ce6cde92 IPG |
354 | struct i2400m *i2400m = net_dev_to_i2400m(net_dev); |
355 | struct device *dev = i2400m_dev(i2400m); | |
d0cf9c0d | 356 | int result; |
ce6cde92 IPG |
357 | |
358 | d_fnstart(3, dev, "(skb %p net_dev %p)\n", skb, net_dev); | |
359 | if (i2400m->state == I2400M_SS_IDLE) | |
360 | result = i2400m_net_wake_tx(i2400m, net_dev, skb); | |
361 | else | |
362 | result = i2400m_net_tx(i2400m, net_dev, skb); | |
363 | if (result < 0) | |
364 | net_dev->stats.tx_dropped++; | |
365 | else { | |
366 | net_dev->stats.tx_packets++; | |
367 | net_dev->stats.tx_bytes += skb->len; | |
368 | } | |
369 | kfree_skb(skb); | |
d0cf9c0d SH |
370 | |
371 | d_fnend(3, dev, "(skb %p net_dev %p)\n", skb, net_dev); | |
372 | return NETDEV_TX_OK; | |
ce6cde92 IPG |
373 | } |
374 | ||
375 | ||
376 | static | |
377 | int i2400m_change_mtu(struct net_device *net_dev, int new_mtu) | |
378 | { | |
379 | int result; | |
380 | struct i2400m *i2400m = net_dev_to_i2400m(net_dev); | |
381 | struct device *dev = i2400m_dev(i2400m); | |
382 | ||
383 | if (new_mtu >= I2400M_MAX_MTU) { | |
384 | dev_err(dev, "Cannot change MTU to %d (max is %d)\n", | |
385 | new_mtu, I2400M_MAX_MTU); | |
386 | result = -EINVAL; | |
387 | } else { | |
388 | net_dev->mtu = new_mtu; | |
389 | result = 0; | |
390 | } | |
391 | return result; | |
392 | } | |
393 | ||
394 | ||
395 | static | |
396 | void i2400m_tx_timeout(struct net_device *net_dev) | |
397 | { | |
398 | /* | |
399 | * We might want to kick the device | |
400 | * | |
401 | * There is not much we can do though, as the device requires | |
402 | * that we send the data aggregated. By the time we receive | |
403 | * this, there might be data pending to be sent or not... | |
404 | */ | |
405 | net_dev->stats.tx_errors++; | |
406 | return; | |
407 | } | |
408 | ||
409 | ||
410 | /* | |
411 | * Create a fake ethernet header | |
412 | * | |
413 | * For emulating an ethernet device, every received IP header has to | |
fd5c565c IPG |
414 | * be prefixed with an ethernet header. Fake it with the given |
415 | * protocol. | |
ce6cde92 IPG |
416 | */ |
417 | static | |
418 | void i2400m_rx_fake_eth_header(struct net_device *net_dev, | |
61b8d268 | 419 | void *_eth_hdr, __be16 protocol) |
ce6cde92 | 420 | { |
fe442683 | 421 | struct i2400m *i2400m = net_dev_to_i2400m(net_dev); |
ce6cde92 IPG |
422 | struct ethhdr *eth_hdr = _eth_hdr; |
423 | ||
424 | memcpy(eth_hdr->h_dest, net_dev->dev_addr, sizeof(eth_hdr->h_dest)); | |
fe442683 IPG |
425 | memcpy(eth_hdr->h_source, i2400m->src_mac_addr, |
426 | sizeof(eth_hdr->h_source)); | |
61b8d268 | 427 | eth_hdr->h_proto = protocol; |
ce6cde92 IPG |
428 | } |
429 | ||
430 | ||
431 | /* | |
432 | * i2400m_net_rx - pass a network packet to the stack | |
433 | * | |
434 | * @i2400m: device instance | |
435 | * @skb_rx: the skb where the buffer pointed to by @buf is | |
436 | * @i: 1 if payload is the only one | |
437 | * @buf: pointer to the buffer containing the data | |
438 | * @len: buffer's length | |
439 | * | |
fd5c565c IPG |
440 | * This is only used now for the v1.3 firmware. It will be deprecated |
441 | * in >= 2.6.31. | |
442 | * | |
443 | * Note that due to firmware limitations, we don't have space to add | |
444 | * an ethernet header, so we need to copy each packet. Firmware | |
445 | * versions >= v1.4 fix this [see i2400m_net_erx()]. | |
446 | * | |
ce6cde92 IPG |
447 | * We just clone the skb and set it up so that it's skb->data pointer |
448 | * points to "buf" and it's length. | |
449 | * | |
450 | * Note that if the payload is the last (or the only one) in a | |
451 | * multi-payload message, we don't clone the SKB but just reuse it. | |
452 | * | |
453 | * This function is normally run from a thread context. However, we | |
454 | * still use netif_rx() instead of netif_receive_skb() as was | |
455 | * recommended in the mailing list. Reason is in some stress tests | |
456 | * when sending/receiving a lot of data we seem to hit a softlock in | |
457 | * the kernel's TCP implementation [aroudn tcp_delay_timer()]. Using | |
458 | * netif_rx() took care of the issue. | |
459 | * | |
460 | * This is, of course, still open to do more research on why running | |
461 | * with netif_receive_skb() hits this softlock. FIXME. | |
462 | * | |
463 | * FIXME: currently we don't do any efforts at distinguishing if what | |
464 | * we got was an IPv4 or IPv6 header, to setup the protocol field | |
465 | * correctly. | |
466 | */ | |
467 | void i2400m_net_rx(struct i2400m *i2400m, struct sk_buff *skb_rx, | |
468 | unsigned i, const void *buf, int buf_len) | |
469 | { | |
470 | struct net_device *net_dev = i2400m->wimax_dev.net_dev; | |
471 | struct device *dev = i2400m_dev(i2400m); | |
472 | struct sk_buff *skb; | |
473 | ||
474 | d_fnstart(2, dev, "(i2400m %p buf %p buf_len %d)\n", | |
475 | i2400m, buf, buf_len); | |
476 | if (i) { | |
477 | skb = skb_get(skb_rx); | |
478 | d_printf(2, dev, "RX: reusing first payload skb %p\n", skb); | |
479 | skb_pull(skb, buf - (void *) skb->data); | |
480 | skb_trim(skb, (void *) skb_end_pointer(skb) - buf); | |
481 | } else { | |
482 | /* Yes, this is bad -- a lot of overhead -- see | |
483 | * comments at the top of the file */ | |
484 | skb = __netdev_alloc_skb(net_dev, buf_len, GFP_KERNEL); | |
485 | if (skb == NULL) { | |
486 | dev_err(dev, "NETRX: no memory to realloc skb\n"); | |
487 | net_dev->stats.rx_dropped++; | |
488 | goto error_skb_realloc; | |
489 | } | |
490 | memcpy(skb_put(skb, buf_len), buf, buf_len); | |
491 | } | |
492 | i2400m_rx_fake_eth_header(i2400m->wimax_dev.net_dev, | |
61b8d268 HH |
493 | skb->data - ETH_HLEN, |
494 | cpu_to_be16(ETH_P_IP)); | |
ce6cde92 IPG |
495 | skb_set_mac_header(skb, -ETH_HLEN); |
496 | skb->dev = i2400m->wimax_dev.net_dev; | |
497 | skb->protocol = htons(ETH_P_IP); | |
498 | net_dev->stats.rx_packets++; | |
499 | net_dev->stats.rx_bytes += buf_len; | |
500 | d_printf(3, dev, "NETRX: receiving %d bytes to network stack\n", | |
501 | buf_len); | |
502 | d_dump(4, dev, buf, buf_len); | |
503 | netif_rx_ni(skb); /* see notes in function header */ | |
504 | error_skb_realloc: | |
505 | d_fnend(2, dev, "(i2400m %p buf %p buf_len %d) = void\n", | |
506 | i2400m, buf, buf_len); | |
507 | } | |
508 | ||
fd5c565c IPG |
509 | |
510 | /* | |
511 | * i2400m_net_erx - pass a network packet to the stack (extended version) | |
512 | * | |
513 | * @i2400m: device descriptor | |
514 | * @skb: the skb where the packet is - the skb should be set to point | |
515 | * at the IP packet; this function will add ethernet headers if | |
516 | * needed. | |
517 | * @cs: packet type | |
518 | * | |
519 | * This is only used now for firmware >= v1.4. Note it is quite | |
520 | * similar to i2400m_net_rx() (used only for v1.3 firmware). | |
521 | * | |
522 | * This function is normally run from a thread context. However, we | |
523 | * still use netif_rx() instead of netif_receive_skb() as was | |
524 | * recommended in the mailing list. Reason is in some stress tests | |
525 | * when sending/receiving a lot of data we seem to hit a softlock in | |
526 | * the kernel's TCP implementation [aroudn tcp_delay_timer()]. Using | |
527 | * netif_rx() took care of the issue. | |
528 | * | |
529 | * This is, of course, still open to do more research on why running | |
530 | * with netif_receive_skb() hits this softlock. FIXME. | |
531 | */ | |
532 | void i2400m_net_erx(struct i2400m *i2400m, struct sk_buff *skb, | |
533 | enum i2400m_cs cs) | |
534 | { | |
535 | struct net_device *net_dev = i2400m->wimax_dev.net_dev; | |
536 | struct device *dev = i2400m_dev(i2400m); | |
537 | int protocol; | |
538 | ||
ff5e2b47 | 539 | d_fnstart(2, dev, "(i2400m %p skb %p [%u] cs %d)\n", |
fd5c565c IPG |
540 | i2400m, skb, skb->len, cs); |
541 | switch(cs) { | |
542 | case I2400M_CS_IPV4_0: | |
543 | case I2400M_CS_IPV4: | |
544 | protocol = ETH_P_IP; | |
545 | i2400m_rx_fake_eth_header(i2400m->wimax_dev.net_dev, | |
61b8d268 HH |
546 | skb->data - ETH_HLEN, |
547 | cpu_to_be16(ETH_P_IP)); | |
fd5c565c IPG |
548 | skb_set_mac_header(skb, -ETH_HLEN); |
549 | skb->dev = i2400m->wimax_dev.net_dev; | |
550 | skb->protocol = htons(ETH_P_IP); | |
551 | net_dev->stats.rx_packets++; | |
552 | net_dev->stats.rx_bytes += skb->len; | |
553 | break; | |
554 | default: | |
555 | dev_err(dev, "ERX: BUG? CS type %u unsupported\n", cs); | |
556 | goto error; | |
557 | ||
558 | } | |
559 | d_printf(3, dev, "ERX: receiving %d bytes to the network stack\n", | |
560 | skb->len); | |
561 | d_dump(4, dev, skb->data, skb->len); | |
562 | netif_rx_ni(skb); /* see notes in function header */ | |
563 | error: | |
ff5e2b47 | 564 | d_fnend(2, dev, "(i2400m %p skb %p [%u] cs %d) = void\n", |
fd5c565c IPG |
565 | i2400m, skb, skb->len, cs); |
566 | } | |
567 | ||
a962dc25 IPG |
568 | static const struct net_device_ops i2400m_netdev_ops = { |
569 | .ndo_open = i2400m_open, | |
570 | .ndo_stop = i2400m_stop, | |
571 | .ndo_start_xmit = i2400m_hard_start_xmit, | |
572 | .ndo_tx_timeout = i2400m_tx_timeout, | |
573 | .ndo_change_mtu = i2400m_change_mtu, | |
574 | }; | |
575 | ||
abb30733 DW |
576 | static void i2400m_get_drvinfo(struct net_device *net_dev, |
577 | struct ethtool_drvinfo *info) | |
578 | { | |
579 | struct i2400m *i2400m = net_dev_to_i2400m(net_dev); | |
580 | ||
581 | strncpy(info->driver, KBUILD_MODNAME, sizeof(info->driver) - 1); | |
582 | strncpy(info->fw_version, i2400m->fw_name, sizeof(info->fw_version) - 1); | |
583 | if (net_dev->dev.parent) | |
584 | strncpy(info->bus_info, dev_name(net_dev->dev.parent), | |
585 | sizeof(info->bus_info) - 1); | |
586 | } | |
587 | ||
588 | static const struct ethtool_ops i2400m_ethtool_ops = { | |
589 | .get_drvinfo = i2400m_get_drvinfo, | |
590 | .get_link = ethtool_op_get_link, | |
591 | }; | |
ce6cde92 IPG |
592 | |
593 | /** | |
594 | * i2400m_netdev_setup - Setup setup @net_dev's i2400m private data | |
595 | * | |
596 | * Called by alloc_netdev() | |
597 | */ | |
598 | void i2400m_netdev_setup(struct net_device *net_dev) | |
599 | { | |
600 | d_fnstart(3, NULL, "(net_dev %p)\n", net_dev); | |
601 | ether_setup(net_dev); | |
602 | net_dev->mtu = I2400M_MAX_MTU; | |
603 | net_dev->tx_queue_len = I2400M_TX_QLEN; | |
604 | net_dev->features = | |
605 | NETIF_F_VLAN_CHALLENGED | |
606 | | NETIF_F_HIGHDMA; | |
607 | net_dev->flags = | |
608 | IFF_NOARP /* i2400m is apure IP device */ | |
609 | & (~IFF_BROADCAST /* i2400m is P2P */ | |
610 | & ~IFF_MULTICAST); | |
611 | net_dev->watchdog_timeo = I2400M_TX_TIMEOUT; | |
a962dc25 | 612 | net_dev->netdev_ops = &i2400m_netdev_ops; |
abb30733 | 613 | net_dev->ethtool_ops = &i2400m_ethtool_ops; |
ce6cde92 IPG |
614 | d_fnend(3, NULL, "(net_dev %p) = void\n", net_dev); |
615 | } | |
616 | EXPORT_SYMBOL_GPL(i2400m_netdev_setup); | |
617 |