blob: f67af4291f8c403b25d0cf20c3720f9d0102827d [file] [log] [blame]
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -08001/*
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 *
Inaky Perez-Gonzalezfd5c5652009-02-28 23:42:52 +000031 * 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.
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -080037 *
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
Inaky Perez-Gonzalezfd5c5652009-02-28 23:42:52 +000069 * available (firmware <= 1.3)
70 * i2400m_net_erx Called by the RX code when a data frame is
71 * available (firmware >= 1.4).
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -080072 * 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>
Dan Williamsabb30732009-09-17 13:06:14 -070077#include <linux/ethtool.h>
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -080078#include "i2400m.h"
79
80
81#define D_SUBMODULE netdev
82#include "debug-levels.h"
83
84enum {
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
97static
98int 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);
Inaky Perez-Gonzalez8f90f3e2009-09-16 17:53:57 -0700105 /* Make sure we wait until init is complete... */
106 mutex_lock(&i2400m->init_mutex);
107 if (i2400m->updown)
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800108 result = 0;
Inaky Perez-Gonzalez8f90f3e2009-09-16 17:53:57 -0700109 else
110 result = -EBUSY;
111 mutex_unlock(&i2400m->init_mutex);
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800112 d_fnend(3, dev, "(net_dev %p [i2400m %p]) = %d\n",
113 net_dev, i2400m, result);
114 return result;
115}
116
117
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800118static
119int i2400m_stop(struct net_device *net_dev)
120{
121 struct i2400m *i2400m = net_dev_to_i2400m(net_dev);
122 struct device *dev = i2400m_dev(i2400m);
123
124 d_fnstart(3, dev, "(net_dev %p [i2400m %p])\n", net_dev, i2400m);
Inaky Perez-Gonzalezac53aed2009-09-16 16:30:39 -0700125 i2400m_net_wake_stop(i2400m);
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800126 d_fnend(3, dev, "(net_dev %p [i2400m %p]) = 0\n", net_dev, i2400m);
127 return 0;
128}
129
130
131/*
132 * Wake up the device and transmit a held SKB, then restart the net queue
133 *
134 * When the device goes into basestation-idle mode, we need to tell it
135 * to exit that mode; it will negotiate with the base station, user
136 * space may have to intervene to rehandshake crypto and then tell us
137 * when it is ready to transmit the packet we have "queued". Still we
138 * need to give it sometime after it reports being ok.
139 *
140 * On error, there is not much we can do. If the error was on TX, we
141 * still wake the queue up to see if the next packet will be luckier.
142 *
143 * If _cmd_exit_idle() fails...well, it could be many things; most
144 * commonly it is that something else took the device out of IDLE mode
145 * (for example, the base station). In that case we get an -EILSEQ and
146 * we are just going to ignore that one. If the device is back to
147 * connected, then fine -- if it is someother state, the packet will
148 * be dropped anyway.
149 */
150void i2400m_wake_tx_work(struct work_struct *ws)
151{
152 int result;
153 struct i2400m *i2400m = container_of(ws, struct i2400m, wake_tx_ws);
154 struct device *dev = i2400m_dev(i2400m);
155 struct sk_buff *skb = i2400m->wake_tx_skb;
156 unsigned long flags;
157
158 spin_lock_irqsave(&i2400m->tx_lock, flags);
159 skb = i2400m->wake_tx_skb;
160 i2400m->wake_tx_skb = NULL;
161 spin_unlock_irqrestore(&i2400m->tx_lock, flags);
162
163 d_fnstart(3, dev, "(ws %p i2400m %p skb %p)\n", ws, i2400m, skb);
164 result = -EINVAL;
165 if (skb == NULL) {
166 dev_err(dev, "WAKE&TX: skb dissapeared!\n");
167 goto out_put;
168 }
169 result = i2400m_cmd_exit_idle(i2400m);
170 if (result == -EILSEQ)
171 result = 0;
172 if (result < 0) {
173 dev_err(dev, "WAKE&TX: device didn't get out of idle: "
Inaky Perez-Gonzalezc931cee2009-10-19 16:24:56 +0900174 "%d - resetting\n", result);
175 i2400m_reset(i2400m, I2400M_RT_BUS);
176 goto error;
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800177 }
178 result = wait_event_timeout(i2400m->state_wq,
179 i2400m->state != I2400M_SS_IDLE, 5 * HZ);
180 if (result == 0)
181 result = -ETIMEDOUT;
182 if (result < 0) {
183 dev_err(dev, "WAKE&TX: error waiting for device to exit IDLE: "
Inaky Perez-Gonzalezc931cee2009-10-19 16:24:56 +0900184 "%d - resetting\n", result);
185 i2400m_reset(i2400m, I2400M_RT_BUS);
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800186 goto error;
187 }
188 msleep(20); /* device still needs some time or it drops it */
189 result = i2400m_tx(i2400m, skb->data, skb->len, I2400M_PT_DATA);
190 netif_wake_queue(i2400m->wimax_dev.net_dev);
191error:
192 kfree_skb(skb); /* refcount transferred by _hard_start_xmit() */
193out_put:
194 i2400m_put(i2400m);
195 d_fnend(3, dev, "(ws %p i2400m %p skb %p) = void [%d]\n",
196 ws, i2400m, skb, result);
197}
198
199
200/*
201 * Prepare the data payload TX header
202 *
203 * The i2400m expects a 4 byte header in front of a data packet.
204 *
205 * Because we pretend to be an ethernet device, this packet comes with
206 * an ethernet header. Pull it and push our header.
207 */
208static
209void i2400m_tx_prep_header(struct sk_buff *skb)
210{
211 struct i2400m_pl_data_hdr *pl_hdr;
212 skb_pull(skb, ETH_HLEN);
213 pl_hdr = (struct i2400m_pl_data_hdr *) skb_push(skb, sizeof(*pl_hdr));
214 pl_hdr->reserved = 0;
215}
216
217
Inaky Perez-Gonzalezac53aed2009-09-16 16:30:39 -0700218
219/*
220 * Cleanup resources acquired during i2400m_net_wake_tx()
221 *
222 * This is called by __i2400m_dev_stop and means we have to make sure
223 * the workqueue is flushed from any pending work.
224 */
225void i2400m_net_wake_stop(struct i2400m *i2400m)
226{
227 struct device *dev = i2400m_dev(i2400m);
228
229 d_fnstart(3, dev, "(i2400m %p)\n", i2400m);
230 /* See i2400m_hard_start_xmit(), references are taken there
231 * and here we release them if the work was still
232 * pending. Note we can't differentiate work not pending vs
233 * never scheduled, so the NULL check does that. */
234 if (cancel_work_sync(&i2400m->wake_tx_ws) == 0
235 && i2400m->wake_tx_skb != NULL) {
236 unsigned long flags;
237 struct sk_buff *wake_tx_skb;
238 spin_lock_irqsave(&i2400m->tx_lock, flags);
239 wake_tx_skb = i2400m->wake_tx_skb; /* compat help */
240 i2400m->wake_tx_skb = NULL; /* compat help */
241 spin_unlock_irqrestore(&i2400m->tx_lock, flags);
242 i2400m_put(i2400m);
243 kfree_skb(wake_tx_skb);
244 }
245 d_fnend(3, dev, "(i2400m %p) = void\n", i2400m);
246 return;
247}
248
249
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800250/*
251 * TX an skb to an idle device
252 *
253 * When the device is in basestation-idle mode, we need to wake it up
254 * and then TX. So we queue a work_struct for doing so.
255 *
256 * We need to get an extra ref for the skb (so it is not dropped), as
257 * well as be careful not to queue more than one request (won't help
258 * at all). If more than one request comes or there are errors, we
259 * just drop the packets (see i2400m_hard_start_xmit()).
260 */
261static
262int i2400m_net_wake_tx(struct i2400m *i2400m, struct net_device *net_dev,
263 struct sk_buff *skb)
264{
265 int result;
266 struct device *dev = i2400m_dev(i2400m);
267 unsigned long flags;
268
269 d_fnstart(3, dev, "(skb %p net_dev %p)\n", skb, net_dev);
270 if (net_ratelimit()) {
271 d_printf(3, dev, "WAKE&NETTX: "
272 "skb %p sending %d bytes to radio\n",
273 skb, skb->len);
274 d_dump(4, dev, skb->data, skb->len);
275 }
276 /* We hold a ref count for i2400m and skb, so when
277 * stopping() the device, we need to cancel that work
278 * and if pending, release those resources. */
279 result = 0;
280 spin_lock_irqsave(&i2400m->tx_lock, flags);
281 if (!work_pending(&i2400m->wake_tx_ws)) {
282 netif_stop_queue(net_dev);
283 i2400m_get(i2400m);
284 i2400m->wake_tx_skb = skb_get(skb); /* transfer ref count */
285 i2400m_tx_prep_header(skb);
286 result = schedule_work(&i2400m->wake_tx_ws);
287 WARN_ON(result == 0);
288 }
289 spin_unlock_irqrestore(&i2400m->tx_lock, flags);
290 if (result == 0) {
291 /* Yes, this happens even if we stopped the
292 * queue -- blame the queue disciplines that
293 * queue without looking -- I guess there is a reason
294 * for that. */
295 if (net_ratelimit())
296 d_printf(1, dev, "NETTX: device exiting idle, "
297 "dropping skb %p, queue running %d\n",
298 skb, netif_queue_stopped(net_dev));
299 result = -EBUSY;
300 }
301 d_fnend(3, dev, "(skb %p net_dev %p) = %d\n", skb, net_dev, result);
302 return result;
303}
304
305
306/*
307 * Transmit a packet to the base station on behalf of the network stack.
308 *
309 * Returns: 0 if ok, < 0 errno code on error.
310 *
311 * We need to pull the ethernet header and add the hardware header,
312 * which is currently set to all zeroes and reserved.
313 */
314static
315int i2400m_net_tx(struct i2400m *i2400m, struct net_device *net_dev,
316 struct sk_buff *skb)
317{
318 int result;
319 struct device *dev = i2400m_dev(i2400m);
320
321 d_fnstart(3, dev, "(i2400m %p net_dev %p skb %p)\n",
322 i2400m, net_dev, skb);
323 /* FIXME: check eth hdr, only IPv4 is routed by the device as of now */
324 net_dev->trans_start = jiffies;
325 i2400m_tx_prep_header(skb);
326 d_printf(3, dev, "NETTX: skb %p sending %d bytes to radio\n",
327 skb, skb->len);
328 d_dump(4, dev, skb->data, skb->len);
329 result = i2400m_tx(i2400m, skb->data, skb->len, I2400M_PT_DATA);
330 d_fnend(3, dev, "(i2400m %p net_dev %p skb %p) = %d\n",
331 i2400m, net_dev, skb, result);
332 return result;
333}
334
335
336/*
337 * Transmit a packet to the base station on behalf of the network stack
338 *
339 *
340 * Returns: NETDEV_TX_OK (always, even in case of error)
341 *
342 * In case of error, we just drop it. Reasons:
343 *
344 * - we add a hw header to each skb, and if the network stack
345 * retries, we have no way to know if that skb has it or not.
346 *
347 * - network protocols have their own drop-recovery mechanisms
348 *
349 * - there is not much else we can do
350 *
351 * If the device is idle, we need to wake it up; that is an operation
352 * that will sleep. See i2400m_net_wake_tx() for details.
353 */
354static
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000355netdev_tx_t i2400m_hard_start_xmit(struct sk_buff *skb,
356 struct net_device *net_dev)
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800357{
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800358 struct i2400m *i2400m = net_dev_to_i2400m(net_dev);
359 struct device *dev = i2400m_dev(i2400m);
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000360 int result;
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800361
362 d_fnstart(3, dev, "(skb %p net_dev %p)\n", skb, net_dev);
Inaky Perez-Gonzalez9835fd82009-09-29 16:28:24 -0700363 if (skb_header_cloned(skb)) {
364 /*
365 * Make tcpdump/wireshark happy -- if they are
366 * running, the skb is cloned and we will overwrite
367 * the mac fields in i2400m_tx_prep_header. Expand
368 * seems to fix this...
369 */
370 result = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
371 if (result) {
372 result = NETDEV_TX_BUSY;
373 goto error_expand;
374 }
375 }
376
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800377 if (i2400m->state == I2400M_SS_IDLE)
378 result = i2400m_net_wake_tx(i2400m, net_dev, skb);
379 else
380 result = i2400m_net_tx(i2400m, net_dev, skb);
381 if (result < 0)
382 net_dev->stats.tx_dropped++;
383 else {
384 net_dev->stats.tx_packets++;
385 net_dev->stats.tx_bytes += skb->len;
386 }
Inaky Perez-Gonzalez9835fd82009-09-29 16:28:24 -0700387 result = NETDEV_TX_OK;
388error_expand:
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800389 kfree_skb(skb);
Inaky Perez-Gonzalez9835fd82009-09-29 16:28:24 -0700390 d_fnend(3, dev, "(skb %p net_dev %p) = %d\n", skb, net_dev, result);
391 return result;
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800392}
393
394
395static
396int i2400m_change_mtu(struct net_device *net_dev, int new_mtu)
397{
398 int result;
399 struct i2400m *i2400m = net_dev_to_i2400m(net_dev);
400 struct device *dev = i2400m_dev(i2400m);
401
402 if (new_mtu >= I2400M_MAX_MTU) {
403 dev_err(dev, "Cannot change MTU to %d (max is %d)\n",
404 new_mtu, I2400M_MAX_MTU);
405 result = -EINVAL;
406 } else {
407 net_dev->mtu = new_mtu;
408 result = 0;
409 }
410 return result;
411}
412
413
414static
415void i2400m_tx_timeout(struct net_device *net_dev)
416{
417 /*
418 * We might want to kick the device
419 *
420 * There is not much we can do though, as the device requires
421 * that we send the data aggregated. By the time we receive
422 * this, there might be data pending to be sent or not...
423 */
424 net_dev->stats.tx_errors++;
425 return;
426}
427
428
429/*
430 * Create a fake ethernet header
431 *
432 * For emulating an ethernet device, every received IP header has to
Inaky Perez-Gonzalezfd5c5652009-02-28 23:42:52 +0000433 * be prefixed with an ethernet header. Fake it with the given
434 * protocol.
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800435 */
436static
437void i2400m_rx_fake_eth_header(struct net_device *net_dev,
Harvey Harrison61b8d262009-02-28 23:42:53 +0000438 void *_eth_hdr, __be16 protocol)
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800439{
Inaky Perez-Gonzalezfe442682009-04-22 16:53:08 -0700440 struct i2400m *i2400m = net_dev_to_i2400m(net_dev);
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800441 struct ethhdr *eth_hdr = _eth_hdr;
442
443 memcpy(eth_hdr->h_dest, net_dev->dev_addr, sizeof(eth_hdr->h_dest));
Inaky Perez-Gonzalezfe442682009-04-22 16:53:08 -0700444 memcpy(eth_hdr->h_source, i2400m->src_mac_addr,
445 sizeof(eth_hdr->h_source));
Harvey Harrison61b8d262009-02-28 23:42:53 +0000446 eth_hdr->h_proto = protocol;
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800447}
448
449
450/*
451 * i2400m_net_rx - pass a network packet to the stack
452 *
453 * @i2400m: device instance
454 * @skb_rx: the skb where the buffer pointed to by @buf is
455 * @i: 1 if payload is the only one
456 * @buf: pointer to the buffer containing the data
457 * @len: buffer's length
458 *
Inaky Perez-Gonzalezfd5c5652009-02-28 23:42:52 +0000459 * This is only used now for the v1.3 firmware. It will be deprecated
460 * in >= 2.6.31.
461 *
462 * Note that due to firmware limitations, we don't have space to add
463 * an ethernet header, so we need to copy each packet. Firmware
464 * versions >= v1.4 fix this [see i2400m_net_erx()].
465 *
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800466 * We just clone the skb and set it up so that it's skb->data pointer
467 * points to "buf" and it's length.
468 *
469 * Note that if the payload is the last (or the only one) in a
470 * multi-payload message, we don't clone the SKB but just reuse it.
471 *
472 * This function is normally run from a thread context. However, we
473 * still use netif_rx() instead of netif_receive_skb() as was
474 * recommended in the mailing list. Reason is in some stress tests
475 * when sending/receiving a lot of data we seem to hit a softlock in
476 * the kernel's TCP implementation [aroudn tcp_delay_timer()]. Using
477 * netif_rx() took care of the issue.
478 *
479 * This is, of course, still open to do more research on why running
480 * with netif_receive_skb() hits this softlock. FIXME.
481 *
482 * FIXME: currently we don't do any efforts at distinguishing if what
483 * we got was an IPv4 or IPv6 header, to setup the protocol field
484 * correctly.
485 */
486void i2400m_net_rx(struct i2400m *i2400m, struct sk_buff *skb_rx,
487 unsigned i, const void *buf, int buf_len)
488{
489 struct net_device *net_dev = i2400m->wimax_dev.net_dev;
490 struct device *dev = i2400m_dev(i2400m);
491 struct sk_buff *skb;
492
493 d_fnstart(2, dev, "(i2400m %p buf %p buf_len %d)\n",
494 i2400m, buf, buf_len);
495 if (i) {
496 skb = skb_get(skb_rx);
497 d_printf(2, dev, "RX: reusing first payload skb %p\n", skb);
498 skb_pull(skb, buf - (void *) skb->data);
499 skb_trim(skb, (void *) skb_end_pointer(skb) - buf);
500 } else {
501 /* Yes, this is bad -- a lot of overhead -- see
502 * comments at the top of the file */
503 skb = __netdev_alloc_skb(net_dev, buf_len, GFP_KERNEL);
504 if (skb == NULL) {
505 dev_err(dev, "NETRX: no memory to realloc skb\n");
506 net_dev->stats.rx_dropped++;
507 goto error_skb_realloc;
508 }
509 memcpy(skb_put(skb, buf_len), buf, buf_len);
510 }
511 i2400m_rx_fake_eth_header(i2400m->wimax_dev.net_dev,
Harvey Harrison61b8d262009-02-28 23:42:53 +0000512 skb->data - ETH_HLEN,
513 cpu_to_be16(ETH_P_IP));
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800514 skb_set_mac_header(skb, -ETH_HLEN);
515 skb->dev = i2400m->wimax_dev.net_dev;
516 skb->protocol = htons(ETH_P_IP);
517 net_dev->stats.rx_packets++;
518 net_dev->stats.rx_bytes += buf_len;
519 d_printf(3, dev, "NETRX: receiving %d bytes to network stack\n",
520 buf_len);
521 d_dump(4, dev, buf, buf_len);
522 netif_rx_ni(skb); /* see notes in function header */
523error_skb_realloc:
524 d_fnend(2, dev, "(i2400m %p buf %p buf_len %d) = void\n",
525 i2400m, buf, buf_len);
526}
527
Inaky Perez-Gonzalezfd5c5652009-02-28 23:42:52 +0000528
529/*
530 * i2400m_net_erx - pass a network packet to the stack (extended version)
531 *
532 * @i2400m: device descriptor
533 * @skb: the skb where the packet is - the skb should be set to point
534 * at the IP packet; this function will add ethernet headers if
535 * needed.
536 * @cs: packet type
537 *
538 * This is only used now for firmware >= v1.4. Note it is quite
539 * similar to i2400m_net_rx() (used only for v1.3 firmware).
540 *
541 * This function is normally run from a thread context. However, we
542 * still use netif_rx() instead of netif_receive_skb() as was
543 * recommended in the mailing list. Reason is in some stress tests
544 * when sending/receiving a lot of data we seem to hit a softlock in
545 * the kernel's TCP implementation [aroudn tcp_delay_timer()]. Using
546 * netif_rx() took care of the issue.
547 *
548 * This is, of course, still open to do more research on why running
549 * with netif_receive_skb() hits this softlock. FIXME.
550 */
551void i2400m_net_erx(struct i2400m *i2400m, struct sk_buff *skb,
552 enum i2400m_cs cs)
553{
554 struct net_device *net_dev = i2400m->wimax_dev.net_dev;
555 struct device *dev = i2400m_dev(i2400m);
556 int protocol;
557
Randy Dunlapff5e2b42009-03-11 23:24:03 -0700558 d_fnstart(2, dev, "(i2400m %p skb %p [%u] cs %d)\n",
Inaky Perez-Gonzalezfd5c5652009-02-28 23:42:52 +0000559 i2400m, skb, skb->len, cs);
560 switch(cs) {
561 case I2400M_CS_IPV4_0:
562 case I2400M_CS_IPV4:
563 protocol = ETH_P_IP;
564 i2400m_rx_fake_eth_header(i2400m->wimax_dev.net_dev,
Harvey Harrison61b8d262009-02-28 23:42:53 +0000565 skb->data - ETH_HLEN,
566 cpu_to_be16(ETH_P_IP));
Inaky Perez-Gonzalezfd5c5652009-02-28 23:42:52 +0000567 skb_set_mac_header(skb, -ETH_HLEN);
568 skb->dev = i2400m->wimax_dev.net_dev;
569 skb->protocol = htons(ETH_P_IP);
570 net_dev->stats.rx_packets++;
571 net_dev->stats.rx_bytes += skb->len;
572 break;
573 default:
574 dev_err(dev, "ERX: BUG? CS type %u unsupported\n", cs);
575 goto error;
576
577 }
578 d_printf(3, dev, "ERX: receiving %d bytes to the network stack\n",
579 skb->len);
580 d_dump(4, dev, skb->data, skb->len);
581 netif_rx_ni(skb); /* see notes in function header */
582error:
Randy Dunlapff5e2b42009-03-11 23:24:03 -0700583 d_fnend(2, dev, "(i2400m %p skb %p [%u] cs %d) = void\n",
Inaky Perez-Gonzalezfd5c5652009-02-28 23:42:52 +0000584 i2400m, skb, skb->len, cs);
585}
586
Inaky Perez-Gonzaleza962dc22009-01-09 16:43:49 +0000587static const struct net_device_ops i2400m_netdev_ops = {
588 .ndo_open = i2400m_open,
589 .ndo_stop = i2400m_stop,
590 .ndo_start_xmit = i2400m_hard_start_xmit,
591 .ndo_tx_timeout = i2400m_tx_timeout,
592 .ndo_change_mtu = i2400m_change_mtu,
593};
594
Dan Williamsabb30732009-09-17 13:06:14 -0700595static void i2400m_get_drvinfo(struct net_device *net_dev,
596 struct ethtool_drvinfo *info)
597{
598 struct i2400m *i2400m = net_dev_to_i2400m(net_dev);
599
600 strncpy(info->driver, KBUILD_MODNAME, sizeof(info->driver) - 1);
601 strncpy(info->fw_version, i2400m->fw_name, sizeof(info->fw_version) - 1);
602 if (net_dev->dev.parent)
603 strncpy(info->bus_info, dev_name(net_dev->dev.parent),
604 sizeof(info->bus_info) - 1);
605}
606
607static const struct ethtool_ops i2400m_ethtool_ops = {
608 .get_drvinfo = i2400m_get_drvinfo,
609 .get_link = ethtool_op_get_link,
610};
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800611
612/**
613 * i2400m_netdev_setup - Setup setup @net_dev's i2400m private data
614 *
615 * Called by alloc_netdev()
616 */
617void i2400m_netdev_setup(struct net_device *net_dev)
618{
619 d_fnstart(3, NULL, "(net_dev %p)\n", net_dev);
620 ether_setup(net_dev);
621 net_dev->mtu = I2400M_MAX_MTU;
622 net_dev->tx_queue_len = I2400M_TX_QLEN;
623 net_dev->features =
624 NETIF_F_VLAN_CHALLENGED
625 | NETIF_F_HIGHDMA;
626 net_dev->flags =
627 IFF_NOARP /* i2400m is apure IP device */
628 & (~IFF_BROADCAST /* i2400m is P2P */
629 & ~IFF_MULTICAST);
630 net_dev->watchdog_timeo = I2400M_TX_TIMEOUT;
Inaky Perez-Gonzaleza962dc22009-01-09 16:43:49 +0000631 net_dev->netdev_ops = &i2400m_netdev_ops;
Dan Williamsabb30732009-09-17 13:06:14 -0700632 net_dev->ethtool_ops = &i2400m_ethtool_ops;
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800633 d_fnend(3, NULL, "(net_dev %p) = void\n", net_dev);
634}
635EXPORT_SYMBOL_GPL(i2400m_netdev_setup);
636