blob: e7d1a51ee3fe4766f454255153d6a9dcdf47b130 [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: "
174 "%d\n", result);
175 goto error;
176 }
177 result = wait_event_timeout(i2400m->state_wq,
178 i2400m->state != I2400M_SS_IDLE, 5 * HZ);
179 if (result == 0)
180 result = -ETIMEDOUT;
181 if (result < 0) {
182 dev_err(dev, "WAKE&TX: error waiting for device to exit IDLE: "
183 "%d\n", result);
184 goto error;
185 }
186 msleep(20); /* device still needs some time or it drops it */
187 result = i2400m_tx(i2400m, skb->data, skb->len, I2400M_PT_DATA);
188 netif_wake_queue(i2400m->wimax_dev.net_dev);
189error:
190 kfree_skb(skb); /* refcount transferred by _hard_start_xmit() */
191out_put:
192 i2400m_put(i2400m);
193 d_fnend(3, dev, "(ws %p i2400m %p skb %p) = void [%d]\n",
194 ws, i2400m, skb, result);
195}
196
197
198/*
199 * Prepare the data payload TX header
200 *
201 * The i2400m expects a 4 byte header in front of a data packet.
202 *
203 * Because we pretend to be an ethernet device, this packet comes with
204 * an ethernet header. Pull it and push our header.
205 */
206static
207void i2400m_tx_prep_header(struct sk_buff *skb)
208{
209 struct i2400m_pl_data_hdr *pl_hdr;
210 skb_pull(skb, ETH_HLEN);
211 pl_hdr = (struct i2400m_pl_data_hdr *) skb_push(skb, sizeof(*pl_hdr));
212 pl_hdr->reserved = 0;
213}
214
215
Inaky Perez-Gonzalezac53aed2009-09-16 16:30:39 -0700216
217/*
218 * Cleanup resources acquired during i2400m_net_wake_tx()
219 *
220 * This is called by __i2400m_dev_stop and means we have to make sure
221 * the workqueue is flushed from any pending work.
222 */
223void i2400m_net_wake_stop(struct i2400m *i2400m)
224{
225 struct device *dev = i2400m_dev(i2400m);
226
227 d_fnstart(3, dev, "(i2400m %p)\n", i2400m);
228 /* See i2400m_hard_start_xmit(), references are taken there
229 * and here we release them if the work was still
230 * pending. Note we can't differentiate work not pending vs
231 * never scheduled, so the NULL check does that. */
232 if (cancel_work_sync(&i2400m->wake_tx_ws) == 0
233 && i2400m->wake_tx_skb != NULL) {
234 unsigned long flags;
235 struct sk_buff *wake_tx_skb;
236 spin_lock_irqsave(&i2400m->tx_lock, flags);
237 wake_tx_skb = i2400m->wake_tx_skb; /* compat help */
238 i2400m->wake_tx_skb = NULL; /* compat help */
239 spin_unlock_irqrestore(&i2400m->tx_lock, flags);
240 i2400m_put(i2400m);
241 kfree_skb(wake_tx_skb);
242 }
243 d_fnend(3, dev, "(i2400m %p) = void\n", i2400m);
244 return;
245}
246
247
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800248/*
249 * TX an skb to an idle device
250 *
251 * When the device is in basestation-idle mode, we need to wake it up
252 * and then TX. So we queue a work_struct for doing so.
253 *
254 * We need to get an extra ref for the skb (so it is not dropped), as
255 * well as be careful not to queue more than one request (won't help
256 * at all). If more than one request comes or there are errors, we
257 * just drop the packets (see i2400m_hard_start_xmit()).
258 */
259static
260int i2400m_net_wake_tx(struct i2400m *i2400m, struct net_device *net_dev,
261 struct sk_buff *skb)
262{
263 int result;
264 struct device *dev = i2400m_dev(i2400m);
265 unsigned long flags;
266
267 d_fnstart(3, dev, "(skb %p net_dev %p)\n", skb, net_dev);
268 if (net_ratelimit()) {
269 d_printf(3, dev, "WAKE&NETTX: "
270 "skb %p sending %d bytes to radio\n",
271 skb, skb->len);
272 d_dump(4, dev, skb->data, skb->len);
273 }
274 /* We hold a ref count for i2400m and skb, so when
275 * stopping() the device, we need to cancel that work
276 * and if pending, release those resources. */
277 result = 0;
278 spin_lock_irqsave(&i2400m->tx_lock, flags);
279 if (!work_pending(&i2400m->wake_tx_ws)) {
280 netif_stop_queue(net_dev);
281 i2400m_get(i2400m);
282 i2400m->wake_tx_skb = skb_get(skb); /* transfer ref count */
283 i2400m_tx_prep_header(skb);
284 result = schedule_work(&i2400m->wake_tx_ws);
285 WARN_ON(result == 0);
286 }
287 spin_unlock_irqrestore(&i2400m->tx_lock, flags);
288 if (result == 0) {
289 /* Yes, this happens even if we stopped the
290 * queue -- blame the queue disciplines that
291 * queue without looking -- I guess there is a reason
292 * for that. */
293 if (net_ratelimit())
294 d_printf(1, dev, "NETTX: device exiting idle, "
295 "dropping skb %p, queue running %d\n",
296 skb, netif_queue_stopped(net_dev));
297 result = -EBUSY;
298 }
299 d_fnend(3, dev, "(skb %p net_dev %p) = %d\n", skb, net_dev, result);
300 return result;
301}
302
303
304/*
305 * Transmit a packet to the base station on behalf of the network stack.
306 *
307 * Returns: 0 if ok, < 0 errno code on error.
308 *
309 * We need to pull the ethernet header and add the hardware header,
310 * which is currently set to all zeroes and reserved.
311 */
312static
313int i2400m_net_tx(struct i2400m *i2400m, struct net_device *net_dev,
314 struct sk_buff *skb)
315{
316 int result;
317 struct device *dev = i2400m_dev(i2400m);
318
319 d_fnstart(3, dev, "(i2400m %p net_dev %p skb %p)\n",
320 i2400m, net_dev, skb);
321 /* FIXME: check eth hdr, only IPv4 is routed by the device as of now */
322 net_dev->trans_start = jiffies;
323 i2400m_tx_prep_header(skb);
324 d_printf(3, dev, "NETTX: skb %p sending %d bytes to radio\n",
325 skb, skb->len);
326 d_dump(4, dev, skb->data, skb->len);
327 result = i2400m_tx(i2400m, skb->data, skb->len, I2400M_PT_DATA);
328 d_fnend(3, dev, "(i2400m %p net_dev %p skb %p) = %d\n",
329 i2400m, net_dev, skb, result);
330 return result;
331}
332
333
334/*
335 * Transmit a packet to the base station on behalf of the network stack
336 *
337 *
338 * Returns: NETDEV_TX_OK (always, even in case of error)
339 *
340 * In case of error, we just drop it. Reasons:
341 *
342 * - we add a hw header to each skb, and if the network stack
343 * retries, we have no way to know if that skb has it or not.
344 *
345 * - network protocols have their own drop-recovery mechanisms
346 *
347 * - there is not much else we can do
348 *
349 * If the device is idle, we need to wake it up; that is an operation
350 * that will sleep. See i2400m_net_wake_tx() for details.
351 */
352static
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000353netdev_tx_t i2400m_hard_start_xmit(struct sk_buff *skb,
354 struct net_device *net_dev)
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800355{
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800356 struct i2400m *i2400m = net_dev_to_i2400m(net_dev);
357 struct device *dev = i2400m_dev(i2400m);
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000358 int result;
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800359
360 d_fnstart(3, dev, "(skb %p net_dev %p)\n", skb, net_dev);
Inaky Perez-Gonzalez9835fd82009-09-29 16:28:24 -0700361 if (skb_header_cloned(skb)) {
362 /*
363 * Make tcpdump/wireshark happy -- if they are
364 * running, the skb is cloned and we will overwrite
365 * the mac fields in i2400m_tx_prep_header. Expand
366 * seems to fix this...
367 */
368 result = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
369 if (result) {
370 result = NETDEV_TX_BUSY;
371 goto error_expand;
372 }
373 }
374
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800375 if (i2400m->state == I2400M_SS_IDLE)
376 result = i2400m_net_wake_tx(i2400m, net_dev, skb);
377 else
378 result = i2400m_net_tx(i2400m, net_dev, skb);
379 if (result < 0)
380 net_dev->stats.tx_dropped++;
381 else {
382 net_dev->stats.tx_packets++;
383 net_dev->stats.tx_bytes += skb->len;
384 }
Inaky Perez-Gonzalez9835fd82009-09-29 16:28:24 -0700385 result = NETDEV_TX_OK;
386error_expand:
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800387 kfree_skb(skb);
Inaky Perez-Gonzalez9835fd82009-09-29 16:28:24 -0700388 d_fnend(3, dev, "(skb %p net_dev %p) = %d\n", skb, net_dev, result);
389 return result;
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800390}
391
392
393static
394int i2400m_change_mtu(struct net_device *net_dev, int new_mtu)
395{
396 int result;
397 struct i2400m *i2400m = net_dev_to_i2400m(net_dev);
398 struct device *dev = i2400m_dev(i2400m);
399
400 if (new_mtu >= I2400M_MAX_MTU) {
401 dev_err(dev, "Cannot change MTU to %d (max is %d)\n",
402 new_mtu, I2400M_MAX_MTU);
403 result = -EINVAL;
404 } else {
405 net_dev->mtu = new_mtu;
406 result = 0;
407 }
408 return result;
409}
410
411
412static
413void i2400m_tx_timeout(struct net_device *net_dev)
414{
415 /*
416 * We might want to kick the device
417 *
418 * There is not much we can do though, as the device requires
419 * that we send the data aggregated. By the time we receive
420 * this, there might be data pending to be sent or not...
421 */
422 net_dev->stats.tx_errors++;
423 return;
424}
425
426
427/*
428 * Create a fake ethernet header
429 *
430 * For emulating an ethernet device, every received IP header has to
Inaky Perez-Gonzalezfd5c5652009-02-28 23:42:52 +0000431 * be prefixed with an ethernet header. Fake it with the given
432 * protocol.
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800433 */
434static
435void i2400m_rx_fake_eth_header(struct net_device *net_dev,
Harvey Harrison61b8d262009-02-28 23:42:53 +0000436 void *_eth_hdr, __be16 protocol)
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800437{
Inaky Perez-Gonzalezfe442682009-04-22 16:53:08 -0700438 struct i2400m *i2400m = net_dev_to_i2400m(net_dev);
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800439 struct ethhdr *eth_hdr = _eth_hdr;
440
441 memcpy(eth_hdr->h_dest, net_dev->dev_addr, sizeof(eth_hdr->h_dest));
Inaky Perez-Gonzalezfe442682009-04-22 16:53:08 -0700442 memcpy(eth_hdr->h_source, i2400m->src_mac_addr,
443 sizeof(eth_hdr->h_source));
Harvey Harrison61b8d262009-02-28 23:42:53 +0000444 eth_hdr->h_proto = protocol;
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800445}
446
447
448/*
449 * i2400m_net_rx - pass a network packet to the stack
450 *
451 * @i2400m: device instance
452 * @skb_rx: the skb where the buffer pointed to by @buf is
453 * @i: 1 if payload is the only one
454 * @buf: pointer to the buffer containing the data
455 * @len: buffer's length
456 *
Inaky Perez-Gonzalezfd5c5652009-02-28 23:42:52 +0000457 * This is only used now for the v1.3 firmware. It will be deprecated
458 * in >= 2.6.31.
459 *
460 * Note that due to firmware limitations, we don't have space to add
461 * an ethernet header, so we need to copy each packet. Firmware
462 * versions >= v1.4 fix this [see i2400m_net_erx()].
463 *
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800464 * We just clone the skb and set it up so that it's skb->data pointer
465 * points to "buf" and it's length.
466 *
467 * Note that if the payload is the last (or the only one) in a
468 * multi-payload message, we don't clone the SKB but just reuse it.
469 *
470 * This function is normally run from a thread context. However, we
471 * still use netif_rx() instead of netif_receive_skb() as was
472 * recommended in the mailing list. Reason is in some stress tests
473 * when sending/receiving a lot of data we seem to hit a softlock in
474 * the kernel's TCP implementation [aroudn tcp_delay_timer()]. Using
475 * netif_rx() took care of the issue.
476 *
477 * This is, of course, still open to do more research on why running
478 * with netif_receive_skb() hits this softlock. FIXME.
479 *
480 * FIXME: currently we don't do any efforts at distinguishing if what
481 * we got was an IPv4 or IPv6 header, to setup the protocol field
482 * correctly.
483 */
484void i2400m_net_rx(struct i2400m *i2400m, struct sk_buff *skb_rx,
485 unsigned i, const void *buf, int buf_len)
486{
487 struct net_device *net_dev = i2400m->wimax_dev.net_dev;
488 struct device *dev = i2400m_dev(i2400m);
489 struct sk_buff *skb;
490
491 d_fnstart(2, dev, "(i2400m %p buf %p buf_len %d)\n",
492 i2400m, buf, buf_len);
493 if (i) {
494 skb = skb_get(skb_rx);
495 d_printf(2, dev, "RX: reusing first payload skb %p\n", skb);
496 skb_pull(skb, buf - (void *) skb->data);
497 skb_trim(skb, (void *) skb_end_pointer(skb) - buf);
498 } else {
499 /* Yes, this is bad -- a lot of overhead -- see
500 * comments at the top of the file */
501 skb = __netdev_alloc_skb(net_dev, buf_len, GFP_KERNEL);
502 if (skb == NULL) {
503 dev_err(dev, "NETRX: no memory to realloc skb\n");
504 net_dev->stats.rx_dropped++;
505 goto error_skb_realloc;
506 }
507 memcpy(skb_put(skb, buf_len), buf, buf_len);
508 }
509 i2400m_rx_fake_eth_header(i2400m->wimax_dev.net_dev,
Harvey Harrison61b8d262009-02-28 23:42:53 +0000510 skb->data - ETH_HLEN,
511 cpu_to_be16(ETH_P_IP));
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800512 skb_set_mac_header(skb, -ETH_HLEN);
513 skb->dev = i2400m->wimax_dev.net_dev;
514 skb->protocol = htons(ETH_P_IP);
515 net_dev->stats.rx_packets++;
516 net_dev->stats.rx_bytes += buf_len;
517 d_printf(3, dev, "NETRX: receiving %d bytes to network stack\n",
518 buf_len);
519 d_dump(4, dev, buf, buf_len);
520 netif_rx_ni(skb); /* see notes in function header */
521error_skb_realloc:
522 d_fnend(2, dev, "(i2400m %p buf %p buf_len %d) = void\n",
523 i2400m, buf, buf_len);
524}
525
Inaky Perez-Gonzalezfd5c5652009-02-28 23:42:52 +0000526
527/*
528 * i2400m_net_erx - pass a network packet to the stack (extended version)
529 *
530 * @i2400m: device descriptor
531 * @skb: the skb where the packet is - the skb should be set to point
532 * at the IP packet; this function will add ethernet headers if
533 * needed.
534 * @cs: packet type
535 *
536 * This is only used now for firmware >= v1.4. Note it is quite
537 * similar to i2400m_net_rx() (used only for v1.3 firmware).
538 *
539 * This function is normally run from a thread context. However, we
540 * still use netif_rx() instead of netif_receive_skb() as was
541 * recommended in the mailing list. Reason is in some stress tests
542 * when sending/receiving a lot of data we seem to hit a softlock in
543 * the kernel's TCP implementation [aroudn tcp_delay_timer()]. Using
544 * netif_rx() took care of the issue.
545 *
546 * This is, of course, still open to do more research on why running
547 * with netif_receive_skb() hits this softlock. FIXME.
548 */
549void i2400m_net_erx(struct i2400m *i2400m, struct sk_buff *skb,
550 enum i2400m_cs cs)
551{
552 struct net_device *net_dev = i2400m->wimax_dev.net_dev;
553 struct device *dev = i2400m_dev(i2400m);
554 int protocol;
555
Randy Dunlapff5e2b42009-03-11 23:24:03 -0700556 d_fnstart(2, dev, "(i2400m %p skb %p [%u] cs %d)\n",
Inaky Perez-Gonzalezfd5c5652009-02-28 23:42:52 +0000557 i2400m, skb, skb->len, cs);
558 switch(cs) {
559 case I2400M_CS_IPV4_0:
560 case I2400M_CS_IPV4:
561 protocol = ETH_P_IP;
562 i2400m_rx_fake_eth_header(i2400m->wimax_dev.net_dev,
Harvey Harrison61b8d262009-02-28 23:42:53 +0000563 skb->data - ETH_HLEN,
564 cpu_to_be16(ETH_P_IP));
Inaky Perez-Gonzalezfd5c5652009-02-28 23:42:52 +0000565 skb_set_mac_header(skb, -ETH_HLEN);
566 skb->dev = i2400m->wimax_dev.net_dev;
567 skb->protocol = htons(ETH_P_IP);
568 net_dev->stats.rx_packets++;
569 net_dev->stats.rx_bytes += skb->len;
570 break;
571 default:
572 dev_err(dev, "ERX: BUG? CS type %u unsupported\n", cs);
573 goto error;
574
575 }
576 d_printf(3, dev, "ERX: receiving %d bytes to the network stack\n",
577 skb->len);
578 d_dump(4, dev, skb->data, skb->len);
579 netif_rx_ni(skb); /* see notes in function header */
580error:
Randy Dunlapff5e2b42009-03-11 23:24:03 -0700581 d_fnend(2, dev, "(i2400m %p skb %p [%u] cs %d) = void\n",
Inaky Perez-Gonzalezfd5c5652009-02-28 23:42:52 +0000582 i2400m, skb, skb->len, cs);
583}
584
Inaky Perez-Gonzaleza962dc22009-01-09 16:43:49 +0000585static const struct net_device_ops i2400m_netdev_ops = {
586 .ndo_open = i2400m_open,
587 .ndo_stop = i2400m_stop,
588 .ndo_start_xmit = i2400m_hard_start_xmit,
589 .ndo_tx_timeout = i2400m_tx_timeout,
590 .ndo_change_mtu = i2400m_change_mtu,
591};
592
Dan Williamsabb30732009-09-17 13:06:14 -0700593static void i2400m_get_drvinfo(struct net_device *net_dev,
594 struct ethtool_drvinfo *info)
595{
596 struct i2400m *i2400m = net_dev_to_i2400m(net_dev);
597
598 strncpy(info->driver, KBUILD_MODNAME, sizeof(info->driver) - 1);
599 strncpy(info->fw_version, i2400m->fw_name, sizeof(info->fw_version) - 1);
600 if (net_dev->dev.parent)
601 strncpy(info->bus_info, dev_name(net_dev->dev.parent),
602 sizeof(info->bus_info) - 1);
603}
604
605static const struct ethtool_ops i2400m_ethtool_ops = {
606 .get_drvinfo = i2400m_get_drvinfo,
607 .get_link = ethtool_op_get_link,
608};
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800609
610/**
611 * i2400m_netdev_setup - Setup setup @net_dev's i2400m private data
612 *
613 * Called by alloc_netdev()
614 */
615void i2400m_netdev_setup(struct net_device *net_dev)
616{
617 d_fnstart(3, NULL, "(net_dev %p)\n", net_dev);
618 ether_setup(net_dev);
619 net_dev->mtu = I2400M_MAX_MTU;
620 net_dev->tx_queue_len = I2400M_TX_QLEN;
621 net_dev->features =
622 NETIF_F_VLAN_CHALLENGED
623 | NETIF_F_HIGHDMA;
624 net_dev->flags =
625 IFF_NOARP /* i2400m is apure IP device */
626 & (~IFF_BROADCAST /* i2400m is P2P */
627 & ~IFF_MULTICAST);
628 net_dev->watchdog_timeo = I2400M_TX_TIMEOUT;
Inaky Perez-Gonzaleza962dc22009-01-09 16:43:49 +0000629 net_dev->netdev_ops = &i2400m_netdev_ops;
Dan Williamsabb30732009-09-17 13:06:14 -0700630 net_dev->ethtool_ops = &i2400m_ethtool_ops;
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800631 d_fnend(3, NULL, "(net_dev %p) = void\n", net_dev);
632}
633EXPORT_SYMBOL_GPL(i2400m_netdev_setup);
634