blob: 599aa4eb9baa9bc8dd51cfd4ef3ac076583e99b4 [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,
Inaky Perez-Gonzalez5ab5a722009-10-15 18:16:08 +090092 /* 20 secs? yep, this is the maximum timeout that the device
93 * might take to get out of IDLE / negotiate it with the base
94 * station. We add 1sec for good measure. */
95 I2400M_TX_TIMEOUT = 21 * HZ,
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -080096 I2400M_TX_QLEN = 5,
97};
98
99
100static
101int i2400m_open(struct net_device *net_dev)
102{
103 int result;
104 struct i2400m *i2400m = net_dev_to_i2400m(net_dev);
105 struct device *dev = i2400m_dev(i2400m);
106
107 d_fnstart(3, dev, "(net_dev %p [i2400m %p])\n", net_dev, i2400m);
Inaky Perez-Gonzalez8f90f3e2009-09-16 17:53:57 -0700108 /* Make sure we wait until init is complete... */
109 mutex_lock(&i2400m->init_mutex);
110 if (i2400m->updown)
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800111 result = 0;
Inaky Perez-Gonzalez8f90f3e2009-09-16 17:53:57 -0700112 else
113 result = -EBUSY;
114 mutex_unlock(&i2400m->init_mutex);
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800115 d_fnend(3, dev, "(net_dev %p [i2400m %p]) = %d\n",
116 net_dev, i2400m, result);
117 return result;
118}
119
120
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800121static
122int i2400m_stop(struct net_device *net_dev)
123{
124 struct i2400m *i2400m = net_dev_to_i2400m(net_dev);
125 struct device *dev = i2400m_dev(i2400m);
126
127 d_fnstart(3, dev, "(net_dev %p [i2400m %p])\n", net_dev, i2400m);
Inaky Perez-Gonzalezac53aed2009-09-16 16:30:39 -0700128 i2400m_net_wake_stop(i2400m);
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800129 d_fnend(3, dev, "(net_dev %p [i2400m %p]) = 0\n", net_dev, i2400m);
130 return 0;
131}
132
133
134/*
135 * Wake up the device and transmit a held SKB, then restart the net queue
136 *
137 * When the device goes into basestation-idle mode, we need to tell it
138 * to exit that mode; it will negotiate with the base station, user
139 * space may have to intervene to rehandshake crypto and then tell us
140 * when it is ready to transmit the packet we have "queued". Still we
141 * need to give it sometime after it reports being ok.
142 *
143 * On error, there is not much we can do. If the error was on TX, we
144 * still wake the queue up to see if the next packet will be luckier.
145 *
146 * If _cmd_exit_idle() fails...well, it could be many things; most
147 * commonly it is that something else took the device out of IDLE mode
148 * (for example, the base station). In that case we get an -EILSEQ and
149 * we are just going to ignore that one. If the device is back to
150 * connected, then fine -- if it is someother state, the packet will
151 * be dropped anyway.
152 */
153void i2400m_wake_tx_work(struct work_struct *ws)
154{
155 int result;
156 struct i2400m *i2400m = container_of(ws, struct i2400m, wake_tx_ws);
Inaky Perez-Gonzalez5ab5a722009-10-15 18:16:08 +0900157 struct net_device *net_dev = i2400m->wimax_dev.net_dev;
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800158 struct device *dev = i2400m_dev(i2400m);
159 struct sk_buff *skb = i2400m->wake_tx_skb;
160 unsigned long flags;
161
162 spin_lock_irqsave(&i2400m->tx_lock, flags);
163 skb = i2400m->wake_tx_skb;
164 i2400m->wake_tx_skb = NULL;
165 spin_unlock_irqrestore(&i2400m->tx_lock, flags);
166
167 d_fnstart(3, dev, "(ws %p i2400m %p skb %p)\n", ws, i2400m, skb);
168 result = -EINVAL;
169 if (skb == NULL) {
170 dev_err(dev, "WAKE&TX: skb dissapeared!\n");
171 goto out_put;
172 }
Inaky Perez-Gonzalez5ab5a722009-10-15 18:16:08 +0900173 /* If we have, somehow, lost the connection after this was
174 * queued, don't do anything; this might be the device got
175 * reset or just disconnected. */
176 if (unlikely(!netif_carrier_ok(net_dev)))
177 goto out_kfree;
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800178 result = i2400m_cmd_exit_idle(i2400m);
179 if (result == -EILSEQ)
180 result = 0;
181 if (result < 0) {
182 dev_err(dev, "WAKE&TX: device didn't get out of idle: "
Inaky Perez-Gonzalezc931cee2009-10-19 16:24:56 +0900183 "%d - resetting\n", result);
184 i2400m_reset(i2400m, I2400M_RT_BUS);
185 goto error;
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800186 }
187 result = wait_event_timeout(i2400m->state_wq,
Inaky Perez-Gonzalez5ab5a722009-10-15 18:16:08 +0900188 i2400m->state != I2400M_SS_IDLE,
189 net_dev->watchdog_timeo - HZ/2);
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800190 if (result == 0)
191 result = -ETIMEDOUT;
192 if (result < 0) {
193 dev_err(dev, "WAKE&TX: error waiting for device to exit IDLE: "
Inaky Perez-Gonzalezc931cee2009-10-19 16:24:56 +0900194 "%d - resetting\n", result);
195 i2400m_reset(i2400m, I2400M_RT_BUS);
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800196 goto error;
197 }
198 msleep(20); /* device still needs some time or it drops it */
199 result = i2400m_tx(i2400m, skb->data, skb->len, I2400M_PT_DATA);
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800200error:
Inaky Perez-Gonzalez5ab5a722009-10-15 18:16:08 +0900201 netif_wake_queue(net_dev);
202out_kfree:
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800203 kfree_skb(skb); /* refcount transferred by _hard_start_xmit() */
204out_put:
205 i2400m_put(i2400m);
206 d_fnend(3, dev, "(ws %p i2400m %p skb %p) = void [%d]\n",
207 ws, i2400m, skb, result);
208}
209
210
211/*
212 * Prepare the data payload TX header
213 *
214 * The i2400m expects a 4 byte header in front of a data packet.
215 *
216 * Because we pretend to be an ethernet device, this packet comes with
217 * an ethernet header. Pull it and push our header.
218 */
219static
220void i2400m_tx_prep_header(struct sk_buff *skb)
221{
222 struct i2400m_pl_data_hdr *pl_hdr;
223 skb_pull(skb, ETH_HLEN);
224 pl_hdr = (struct i2400m_pl_data_hdr *) skb_push(skb, sizeof(*pl_hdr));
225 pl_hdr->reserved = 0;
226}
227
228
Inaky Perez-Gonzalezac53aed2009-09-16 16:30:39 -0700229
230/*
231 * Cleanup resources acquired during i2400m_net_wake_tx()
232 *
233 * This is called by __i2400m_dev_stop and means we have to make sure
234 * the workqueue is flushed from any pending work.
235 */
236void i2400m_net_wake_stop(struct i2400m *i2400m)
237{
238 struct device *dev = i2400m_dev(i2400m);
239
240 d_fnstart(3, dev, "(i2400m %p)\n", i2400m);
241 /* See i2400m_hard_start_xmit(), references are taken there
242 * and here we release them if the work was still
243 * pending. Note we can't differentiate work not pending vs
244 * never scheduled, so the NULL check does that. */
245 if (cancel_work_sync(&i2400m->wake_tx_ws) == 0
246 && i2400m->wake_tx_skb != NULL) {
247 unsigned long flags;
248 struct sk_buff *wake_tx_skb;
249 spin_lock_irqsave(&i2400m->tx_lock, flags);
250 wake_tx_skb = i2400m->wake_tx_skb; /* compat help */
251 i2400m->wake_tx_skb = NULL; /* compat help */
252 spin_unlock_irqrestore(&i2400m->tx_lock, flags);
253 i2400m_put(i2400m);
254 kfree_skb(wake_tx_skb);
255 }
256 d_fnend(3, dev, "(i2400m %p) = void\n", i2400m);
257 return;
258}
259
260
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800261/*
262 * TX an skb to an idle device
263 *
264 * When the device is in basestation-idle mode, we need to wake it up
265 * and then TX. So we queue a work_struct for doing so.
266 *
267 * We need to get an extra ref for the skb (so it is not dropped), as
268 * well as be careful not to queue more than one request (won't help
269 * at all). If more than one request comes or there are errors, we
270 * just drop the packets (see i2400m_hard_start_xmit()).
271 */
272static
273int i2400m_net_wake_tx(struct i2400m *i2400m, struct net_device *net_dev,
274 struct sk_buff *skb)
275{
276 int result;
277 struct device *dev = i2400m_dev(i2400m);
278 unsigned long flags;
279
280 d_fnstart(3, dev, "(skb %p net_dev %p)\n", skb, net_dev);
281 if (net_ratelimit()) {
282 d_printf(3, dev, "WAKE&NETTX: "
283 "skb %p sending %d bytes to radio\n",
284 skb, skb->len);
285 d_dump(4, dev, skb->data, skb->len);
286 }
287 /* We hold a ref count for i2400m and skb, so when
288 * stopping() the device, we need to cancel that work
289 * and if pending, release those resources. */
290 result = 0;
291 spin_lock_irqsave(&i2400m->tx_lock, flags);
292 if (!work_pending(&i2400m->wake_tx_ws)) {
293 netif_stop_queue(net_dev);
294 i2400m_get(i2400m);
295 i2400m->wake_tx_skb = skb_get(skb); /* transfer ref count */
296 i2400m_tx_prep_header(skb);
297 result = schedule_work(&i2400m->wake_tx_ws);
298 WARN_ON(result == 0);
299 }
300 spin_unlock_irqrestore(&i2400m->tx_lock, flags);
301 if (result == 0) {
302 /* Yes, this happens even if we stopped the
303 * queue -- blame the queue disciplines that
304 * queue without looking -- I guess there is a reason
305 * for that. */
306 if (net_ratelimit())
307 d_printf(1, dev, "NETTX: device exiting idle, "
308 "dropping skb %p, queue running %d\n",
309 skb, netif_queue_stopped(net_dev));
310 result = -EBUSY;
311 }
312 d_fnend(3, dev, "(skb %p net_dev %p) = %d\n", skb, net_dev, result);
313 return result;
314}
315
316
317/*
318 * Transmit a packet to the base station on behalf of the network stack.
319 *
320 * Returns: 0 if ok, < 0 errno code on error.
321 *
322 * We need to pull the ethernet header and add the hardware header,
323 * which is currently set to all zeroes and reserved.
324 */
325static
326int i2400m_net_tx(struct i2400m *i2400m, struct net_device *net_dev,
327 struct sk_buff *skb)
328{
329 int result;
330 struct device *dev = i2400m_dev(i2400m);
331
332 d_fnstart(3, dev, "(i2400m %p net_dev %p skb %p)\n",
333 i2400m, net_dev, skb);
334 /* FIXME: check eth hdr, only IPv4 is routed by the device as of now */
335 net_dev->trans_start = jiffies;
336 i2400m_tx_prep_header(skb);
337 d_printf(3, dev, "NETTX: skb %p sending %d bytes to radio\n",
338 skb, skb->len);
339 d_dump(4, dev, skb->data, skb->len);
340 result = i2400m_tx(i2400m, skb->data, skb->len, I2400M_PT_DATA);
341 d_fnend(3, dev, "(i2400m %p net_dev %p skb %p) = %d\n",
342 i2400m, net_dev, skb, result);
343 return result;
344}
345
346
347/*
348 * Transmit a packet to the base station on behalf of the network stack
349 *
350 *
351 * Returns: NETDEV_TX_OK (always, even in case of error)
352 *
353 * In case of error, we just drop it. Reasons:
354 *
355 * - we add a hw header to each skb, and if the network stack
356 * retries, we have no way to know if that skb has it or not.
357 *
358 * - network protocols have their own drop-recovery mechanisms
359 *
360 * - there is not much else we can do
361 *
362 * If the device is idle, we need to wake it up; that is an operation
363 * that will sleep. See i2400m_net_wake_tx() for details.
364 */
365static
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000366netdev_tx_t i2400m_hard_start_xmit(struct sk_buff *skb,
367 struct net_device *net_dev)
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800368{
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800369 struct i2400m *i2400m = net_dev_to_i2400m(net_dev);
370 struct device *dev = i2400m_dev(i2400m);
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000371 int result;
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800372
373 d_fnstart(3, dev, "(skb %p net_dev %p)\n", skb, net_dev);
Inaky Perez-Gonzalez9835fd82009-09-29 16:28:24 -0700374 if (skb_header_cloned(skb)) {
375 /*
376 * Make tcpdump/wireshark happy -- if they are
377 * running, the skb is cloned and we will overwrite
378 * the mac fields in i2400m_tx_prep_header. Expand
379 * seems to fix this...
380 */
381 result = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
382 if (result) {
383 result = NETDEV_TX_BUSY;
384 goto error_expand;
385 }
386 }
387
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800388 if (i2400m->state == I2400M_SS_IDLE)
389 result = i2400m_net_wake_tx(i2400m, net_dev, skb);
390 else
391 result = i2400m_net_tx(i2400m, net_dev, skb);
392 if (result < 0)
393 net_dev->stats.tx_dropped++;
394 else {
395 net_dev->stats.tx_packets++;
396 net_dev->stats.tx_bytes += skb->len;
397 }
Inaky Perez-Gonzalez9835fd82009-09-29 16:28:24 -0700398 result = NETDEV_TX_OK;
399error_expand:
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800400 kfree_skb(skb);
Inaky Perez-Gonzalez9835fd82009-09-29 16:28:24 -0700401 d_fnend(3, dev, "(skb %p net_dev %p) = %d\n", skb, net_dev, result);
402 return result;
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800403}
404
405
406static
407int i2400m_change_mtu(struct net_device *net_dev, int new_mtu)
408{
409 int result;
410 struct i2400m *i2400m = net_dev_to_i2400m(net_dev);
411 struct device *dev = i2400m_dev(i2400m);
412
413 if (new_mtu >= I2400M_MAX_MTU) {
414 dev_err(dev, "Cannot change MTU to %d (max is %d)\n",
415 new_mtu, I2400M_MAX_MTU);
416 result = -EINVAL;
417 } else {
418 net_dev->mtu = new_mtu;
419 result = 0;
420 }
421 return result;
422}
423
424
425static
426void i2400m_tx_timeout(struct net_device *net_dev)
427{
428 /*
429 * We might want to kick the device
430 *
431 * There is not much we can do though, as the device requires
432 * that we send the data aggregated. By the time we receive
433 * this, there might be data pending to be sent or not...
434 */
435 net_dev->stats.tx_errors++;
436 return;
437}
438
439
440/*
441 * Create a fake ethernet header
442 *
443 * For emulating an ethernet device, every received IP header has to
Inaky Perez-Gonzalezfd5c5652009-02-28 23:42:52 +0000444 * be prefixed with an ethernet header. Fake it with the given
445 * protocol.
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800446 */
447static
448void i2400m_rx_fake_eth_header(struct net_device *net_dev,
Harvey Harrison61b8d262009-02-28 23:42:53 +0000449 void *_eth_hdr, __be16 protocol)
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800450{
Inaky Perez-Gonzalezfe442682009-04-22 16:53:08 -0700451 struct i2400m *i2400m = net_dev_to_i2400m(net_dev);
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800452 struct ethhdr *eth_hdr = _eth_hdr;
453
454 memcpy(eth_hdr->h_dest, net_dev->dev_addr, sizeof(eth_hdr->h_dest));
Inaky Perez-Gonzalezfe442682009-04-22 16:53:08 -0700455 memcpy(eth_hdr->h_source, i2400m->src_mac_addr,
456 sizeof(eth_hdr->h_source));
Harvey Harrison61b8d262009-02-28 23:42:53 +0000457 eth_hdr->h_proto = protocol;
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800458}
459
460
461/*
462 * i2400m_net_rx - pass a network packet to the stack
463 *
464 * @i2400m: device instance
465 * @skb_rx: the skb where the buffer pointed to by @buf is
466 * @i: 1 if payload is the only one
467 * @buf: pointer to the buffer containing the data
468 * @len: buffer's length
469 *
Inaky Perez-Gonzalezfd5c5652009-02-28 23:42:52 +0000470 * This is only used now for the v1.3 firmware. It will be deprecated
471 * in >= 2.6.31.
472 *
473 * Note that due to firmware limitations, we don't have space to add
474 * an ethernet header, so we need to copy each packet. Firmware
475 * versions >= v1.4 fix this [see i2400m_net_erx()].
476 *
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800477 * We just clone the skb and set it up so that it's skb->data pointer
478 * points to "buf" and it's length.
479 *
480 * Note that if the payload is the last (or the only one) in a
481 * multi-payload message, we don't clone the SKB but just reuse it.
482 *
483 * This function is normally run from a thread context. However, we
484 * still use netif_rx() instead of netif_receive_skb() as was
485 * recommended in the mailing list. Reason is in some stress tests
486 * when sending/receiving a lot of data we seem to hit a softlock in
487 * the kernel's TCP implementation [aroudn tcp_delay_timer()]. Using
488 * netif_rx() took care of the issue.
489 *
490 * This is, of course, still open to do more research on why running
491 * with netif_receive_skb() hits this softlock. FIXME.
492 *
493 * FIXME: currently we don't do any efforts at distinguishing if what
494 * we got was an IPv4 or IPv6 header, to setup the protocol field
495 * correctly.
496 */
497void i2400m_net_rx(struct i2400m *i2400m, struct sk_buff *skb_rx,
498 unsigned i, const void *buf, int buf_len)
499{
500 struct net_device *net_dev = i2400m->wimax_dev.net_dev;
501 struct device *dev = i2400m_dev(i2400m);
502 struct sk_buff *skb;
503
504 d_fnstart(2, dev, "(i2400m %p buf %p buf_len %d)\n",
505 i2400m, buf, buf_len);
506 if (i) {
507 skb = skb_get(skb_rx);
508 d_printf(2, dev, "RX: reusing first payload skb %p\n", skb);
509 skb_pull(skb, buf - (void *) skb->data);
510 skb_trim(skb, (void *) skb_end_pointer(skb) - buf);
511 } else {
512 /* Yes, this is bad -- a lot of overhead -- see
513 * comments at the top of the file */
514 skb = __netdev_alloc_skb(net_dev, buf_len, GFP_KERNEL);
515 if (skb == NULL) {
516 dev_err(dev, "NETRX: no memory to realloc skb\n");
517 net_dev->stats.rx_dropped++;
518 goto error_skb_realloc;
519 }
520 memcpy(skb_put(skb, buf_len), buf, buf_len);
521 }
522 i2400m_rx_fake_eth_header(i2400m->wimax_dev.net_dev,
Harvey Harrison61b8d262009-02-28 23:42:53 +0000523 skb->data - ETH_HLEN,
524 cpu_to_be16(ETH_P_IP));
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800525 skb_set_mac_header(skb, -ETH_HLEN);
526 skb->dev = i2400m->wimax_dev.net_dev;
527 skb->protocol = htons(ETH_P_IP);
528 net_dev->stats.rx_packets++;
529 net_dev->stats.rx_bytes += buf_len;
530 d_printf(3, dev, "NETRX: receiving %d bytes to network stack\n",
531 buf_len);
532 d_dump(4, dev, buf, buf_len);
533 netif_rx_ni(skb); /* see notes in function header */
534error_skb_realloc:
535 d_fnend(2, dev, "(i2400m %p buf %p buf_len %d) = void\n",
536 i2400m, buf, buf_len);
537}
538
Inaky Perez-Gonzalezfd5c5652009-02-28 23:42:52 +0000539
540/*
541 * i2400m_net_erx - pass a network packet to the stack (extended version)
542 *
543 * @i2400m: device descriptor
544 * @skb: the skb where the packet is - the skb should be set to point
545 * at the IP packet; this function will add ethernet headers if
546 * needed.
547 * @cs: packet type
548 *
549 * This is only used now for firmware >= v1.4. Note it is quite
550 * similar to i2400m_net_rx() (used only for v1.3 firmware).
551 *
552 * This function is normally run from a thread context. However, we
553 * still use netif_rx() instead of netif_receive_skb() as was
554 * recommended in the mailing list. Reason is in some stress tests
555 * when sending/receiving a lot of data we seem to hit a softlock in
556 * the kernel's TCP implementation [aroudn tcp_delay_timer()]. Using
557 * netif_rx() took care of the issue.
558 *
559 * This is, of course, still open to do more research on why running
560 * with netif_receive_skb() hits this softlock. FIXME.
561 */
562void i2400m_net_erx(struct i2400m *i2400m, struct sk_buff *skb,
563 enum i2400m_cs cs)
564{
565 struct net_device *net_dev = i2400m->wimax_dev.net_dev;
566 struct device *dev = i2400m_dev(i2400m);
567 int protocol;
568
Randy Dunlapff5e2b42009-03-11 23:24:03 -0700569 d_fnstart(2, dev, "(i2400m %p skb %p [%u] cs %d)\n",
Inaky Perez-Gonzalezfd5c5652009-02-28 23:42:52 +0000570 i2400m, skb, skb->len, cs);
571 switch(cs) {
572 case I2400M_CS_IPV4_0:
573 case I2400M_CS_IPV4:
574 protocol = ETH_P_IP;
575 i2400m_rx_fake_eth_header(i2400m->wimax_dev.net_dev,
Harvey Harrison61b8d262009-02-28 23:42:53 +0000576 skb->data - ETH_HLEN,
577 cpu_to_be16(ETH_P_IP));
Inaky Perez-Gonzalezfd5c5652009-02-28 23:42:52 +0000578 skb_set_mac_header(skb, -ETH_HLEN);
579 skb->dev = i2400m->wimax_dev.net_dev;
580 skb->protocol = htons(ETH_P_IP);
581 net_dev->stats.rx_packets++;
582 net_dev->stats.rx_bytes += skb->len;
583 break;
584 default:
585 dev_err(dev, "ERX: BUG? CS type %u unsupported\n", cs);
586 goto error;
587
588 }
589 d_printf(3, dev, "ERX: receiving %d bytes to the network stack\n",
590 skb->len);
591 d_dump(4, dev, skb->data, skb->len);
592 netif_rx_ni(skb); /* see notes in function header */
593error:
Randy Dunlapff5e2b42009-03-11 23:24:03 -0700594 d_fnend(2, dev, "(i2400m %p skb %p [%u] cs %d) = void\n",
Inaky Perez-Gonzalezfd5c5652009-02-28 23:42:52 +0000595 i2400m, skb, skb->len, cs);
596}
597
Inaky Perez-Gonzaleza962dc22009-01-09 16:43:49 +0000598static const struct net_device_ops i2400m_netdev_ops = {
599 .ndo_open = i2400m_open,
600 .ndo_stop = i2400m_stop,
601 .ndo_start_xmit = i2400m_hard_start_xmit,
602 .ndo_tx_timeout = i2400m_tx_timeout,
603 .ndo_change_mtu = i2400m_change_mtu,
604};
605
Dan Williamsabb30732009-09-17 13:06:14 -0700606static void i2400m_get_drvinfo(struct net_device *net_dev,
607 struct ethtool_drvinfo *info)
608{
609 struct i2400m *i2400m = net_dev_to_i2400m(net_dev);
610
611 strncpy(info->driver, KBUILD_MODNAME, sizeof(info->driver) - 1);
612 strncpy(info->fw_version, i2400m->fw_name, sizeof(info->fw_version) - 1);
613 if (net_dev->dev.parent)
614 strncpy(info->bus_info, dev_name(net_dev->dev.parent),
615 sizeof(info->bus_info) - 1);
616}
617
618static const struct ethtool_ops i2400m_ethtool_ops = {
619 .get_drvinfo = i2400m_get_drvinfo,
620 .get_link = ethtool_op_get_link,
621};
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800622
623/**
624 * i2400m_netdev_setup - Setup setup @net_dev's i2400m private data
625 *
626 * Called by alloc_netdev()
627 */
628void i2400m_netdev_setup(struct net_device *net_dev)
629{
630 d_fnstart(3, NULL, "(net_dev %p)\n", net_dev);
631 ether_setup(net_dev);
632 net_dev->mtu = I2400M_MAX_MTU;
633 net_dev->tx_queue_len = I2400M_TX_QLEN;
634 net_dev->features =
635 NETIF_F_VLAN_CHALLENGED
636 | NETIF_F_HIGHDMA;
637 net_dev->flags =
638 IFF_NOARP /* i2400m is apure IP device */
639 & (~IFF_BROADCAST /* i2400m is P2P */
640 & ~IFF_MULTICAST);
641 net_dev->watchdog_timeo = I2400M_TX_TIMEOUT;
Inaky Perez-Gonzaleza962dc22009-01-09 16:43:49 +0000642 net_dev->netdev_ops = &i2400m_netdev_ops;
Dan Williamsabb30732009-09-17 13:06:14 -0700643 net_dev->ethtool_ops = &i2400m_ethtool_ops;
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800644 d_fnend(3, NULL, "(net_dev %p) = void\n", net_dev);
645}
646EXPORT_SYMBOL_GPL(i2400m_netdev_setup);
647