blob: fefd794087adaac433c5a36d6db748fa9afae35a [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);
361 if (i2400m->state == I2400M_SS_IDLE)
362 result = i2400m_net_wake_tx(i2400m, net_dev, skb);
363 else
364 result = i2400m_net_tx(i2400m, net_dev, skb);
365 if (result < 0)
366 net_dev->stats.tx_dropped++;
367 else {
368 net_dev->stats.tx_packets++;
369 net_dev->stats.tx_bytes += skb->len;
370 }
371 kfree_skb(skb);
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000372
373 d_fnend(3, dev, "(skb %p net_dev %p)\n", skb, net_dev);
374 return NETDEV_TX_OK;
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800375}
376
377
378static
379int i2400m_change_mtu(struct net_device *net_dev, int new_mtu)
380{
381 int result;
382 struct i2400m *i2400m = net_dev_to_i2400m(net_dev);
383 struct device *dev = i2400m_dev(i2400m);
384
385 if (new_mtu >= I2400M_MAX_MTU) {
386 dev_err(dev, "Cannot change MTU to %d (max is %d)\n",
387 new_mtu, I2400M_MAX_MTU);
388 result = -EINVAL;
389 } else {
390 net_dev->mtu = new_mtu;
391 result = 0;
392 }
393 return result;
394}
395
396
397static
398void i2400m_tx_timeout(struct net_device *net_dev)
399{
400 /*
401 * We might want to kick the device
402 *
403 * There is not much we can do though, as the device requires
404 * that we send the data aggregated. By the time we receive
405 * this, there might be data pending to be sent or not...
406 */
407 net_dev->stats.tx_errors++;
408 return;
409}
410
411
412/*
413 * Create a fake ethernet header
414 *
415 * For emulating an ethernet device, every received IP header has to
Inaky Perez-Gonzalezfd5c5652009-02-28 23:42:52 +0000416 * be prefixed with an ethernet header. Fake it with the given
417 * protocol.
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800418 */
419static
420void i2400m_rx_fake_eth_header(struct net_device *net_dev,
Harvey Harrison61b8d262009-02-28 23:42:53 +0000421 void *_eth_hdr, __be16 protocol)
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800422{
Inaky Perez-Gonzalezfe442682009-04-22 16:53:08 -0700423 struct i2400m *i2400m = net_dev_to_i2400m(net_dev);
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800424 struct ethhdr *eth_hdr = _eth_hdr;
425
426 memcpy(eth_hdr->h_dest, net_dev->dev_addr, sizeof(eth_hdr->h_dest));
Inaky Perez-Gonzalezfe442682009-04-22 16:53:08 -0700427 memcpy(eth_hdr->h_source, i2400m->src_mac_addr,
428 sizeof(eth_hdr->h_source));
Harvey Harrison61b8d262009-02-28 23:42:53 +0000429 eth_hdr->h_proto = protocol;
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800430}
431
432
433/*
434 * i2400m_net_rx - pass a network packet to the stack
435 *
436 * @i2400m: device instance
437 * @skb_rx: the skb where the buffer pointed to by @buf is
438 * @i: 1 if payload is the only one
439 * @buf: pointer to the buffer containing the data
440 * @len: buffer's length
441 *
Inaky Perez-Gonzalezfd5c5652009-02-28 23:42:52 +0000442 * This is only used now for the v1.3 firmware. It will be deprecated
443 * in >= 2.6.31.
444 *
445 * Note that due to firmware limitations, we don't have space to add
446 * an ethernet header, so we need to copy each packet. Firmware
447 * versions >= v1.4 fix this [see i2400m_net_erx()].
448 *
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800449 * We just clone the skb and set it up so that it's skb->data pointer
450 * points to "buf" and it's length.
451 *
452 * Note that if the payload is the last (or the only one) in a
453 * multi-payload message, we don't clone the SKB but just reuse it.
454 *
455 * This function is normally run from a thread context. However, we
456 * still use netif_rx() instead of netif_receive_skb() as was
457 * recommended in the mailing list. Reason is in some stress tests
458 * when sending/receiving a lot of data we seem to hit a softlock in
459 * the kernel's TCP implementation [aroudn tcp_delay_timer()]. Using
460 * netif_rx() took care of the issue.
461 *
462 * This is, of course, still open to do more research on why running
463 * with netif_receive_skb() hits this softlock. FIXME.
464 *
465 * FIXME: currently we don't do any efforts at distinguishing if what
466 * we got was an IPv4 or IPv6 header, to setup the protocol field
467 * correctly.
468 */
469void i2400m_net_rx(struct i2400m *i2400m, struct sk_buff *skb_rx,
470 unsigned i, const void *buf, int buf_len)
471{
472 struct net_device *net_dev = i2400m->wimax_dev.net_dev;
473 struct device *dev = i2400m_dev(i2400m);
474 struct sk_buff *skb;
475
476 d_fnstart(2, dev, "(i2400m %p buf %p buf_len %d)\n",
477 i2400m, buf, buf_len);
478 if (i) {
479 skb = skb_get(skb_rx);
480 d_printf(2, dev, "RX: reusing first payload skb %p\n", skb);
481 skb_pull(skb, buf - (void *) skb->data);
482 skb_trim(skb, (void *) skb_end_pointer(skb) - buf);
483 } else {
484 /* Yes, this is bad -- a lot of overhead -- see
485 * comments at the top of the file */
486 skb = __netdev_alloc_skb(net_dev, buf_len, GFP_KERNEL);
487 if (skb == NULL) {
488 dev_err(dev, "NETRX: no memory to realloc skb\n");
489 net_dev->stats.rx_dropped++;
490 goto error_skb_realloc;
491 }
492 memcpy(skb_put(skb, buf_len), buf, buf_len);
493 }
494 i2400m_rx_fake_eth_header(i2400m->wimax_dev.net_dev,
Harvey Harrison61b8d262009-02-28 23:42:53 +0000495 skb->data - ETH_HLEN,
496 cpu_to_be16(ETH_P_IP));
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800497 skb_set_mac_header(skb, -ETH_HLEN);
498 skb->dev = i2400m->wimax_dev.net_dev;
499 skb->protocol = htons(ETH_P_IP);
500 net_dev->stats.rx_packets++;
501 net_dev->stats.rx_bytes += buf_len;
502 d_printf(3, dev, "NETRX: receiving %d bytes to network stack\n",
503 buf_len);
504 d_dump(4, dev, buf, buf_len);
505 netif_rx_ni(skb); /* see notes in function header */
506error_skb_realloc:
507 d_fnend(2, dev, "(i2400m %p buf %p buf_len %d) = void\n",
508 i2400m, buf, buf_len);
509}
510
Inaky Perez-Gonzalezfd5c5652009-02-28 23:42:52 +0000511
512/*
513 * i2400m_net_erx - pass a network packet to the stack (extended version)
514 *
515 * @i2400m: device descriptor
516 * @skb: the skb where the packet is - the skb should be set to point
517 * at the IP packet; this function will add ethernet headers if
518 * needed.
519 * @cs: packet type
520 *
521 * This is only used now for firmware >= v1.4. Note it is quite
522 * similar to i2400m_net_rx() (used only for v1.3 firmware).
523 *
524 * This function is normally run from a thread context. However, we
525 * still use netif_rx() instead of netif_receive_skb() as was
526 * recommended in the mailing list. Reason is in some stress tests
527 * when sending/receiving a lot of data we seem to hit a softlock in
528 * the kernel's TCP implementation [aroudn tcp_delay_timer()]. Using
529 * netif_rx() took care of the issue.
530 *
531 * This is, of course, still open to do more research on why running
532 * with netif_receive_skb() hits this softlock. FIXME.
533 */
534void i2400m_net_erx(struct i2400m *i2400m, struct sk_buff *skb,
535 enum i2400m_cs cs)
536{
537 struct net_device *net_dev = i2400m->wimax_dev.net_dev;
538 struct device *dev = i2400m_dev(i2400m);
539 int protocol;
540
Randy Dunlapff5e2b42009-03-11 23:24:03 -0700541 d_fnstart(2, dev, "(i2400m %p skb %p [%u] cs %d)\n",
Inaky Perez-Gonzalezfd5c5652009-02-28 23:42:52 +0000542 i2400m, skb, skb->len, cs);
543 switch(cs) {
544 case I2400M_CS_IPV4_0:
545 case I2400M_CS_IPV4:
546 protocol = ETH_P_IP;
547 i2400m_rx_fake_eth_header(i2400m->wimax_dev.net_dev,
Harvey Harrison61b8d262009-02-28 23:42:53 +0000548 skb->data - ETH_HLEN,
549 cpu_to_be16(ETH_P_IP));
Inaky Perez-Gonzalezfd5c5652009-02-28 23:42:52 +0000550 skb_set_mac_header(skb, -ETH_HLEN);
551 skb->dev = i2400m->wimax_dev.net_dev;
552 skb->protocol = htons(ETH_P_IP);
553 net_dev->stats.rx_packets++;
554 net_dev->stats.rx_bytes += skb->len;
555 break;
556 default:
557 dev_err(dev, "ERX: BUG? CS type %u unsupported\n", cs);
558 goto error;
559
560 }
561 d_printf(3, dev, "ERX: receiving %d bytes to the network stack\n",
562 skb->len);
563 d_dump(4, dev, skb->data, skb->len);
564 netif_rx_ni(skb); /* see notes in function header */
565error:
Randy Dunlapff5e2b42009-03-11 23:24:03 -0700566 d_fnend(2, dev, "(i2400m %p skb %p [%u] cs %d) = void\n",
Inaky Perez-Gonzalezfd5c5652009-02-28 23:42:52 +0000567 i2400m, skb, skb->len, cs);
568}
569
Inaky Perez-Gonzaleza962dc22009-01-09 16:43:49 +0000570static const struct net_device_ops i2400m_netdev_ops = {
571 .ndo_open = i2400m_open,
572 .ndo_stop = i2400m_stop,
573 .ndo_start_xmit = i2400m_hard_start_xmit,
574 .ndo_tx_timeout = i2400m_tx_timeout,
575 .ndo_change_mtu = i2400m_change_mtu,
576};
577
Dan Williamsabb30732009-09-17 13:06:14 -0700578static void i2400m_get_drvinfo(struct net_device *net_dev,
579 struct ethtool_drvinfo *info)
580{
581 struct i2400m *i2400m = net_dev_to_i2400m(net_dev);
582
583 strncpy(info->driver, KBUILD_MODNAME, sizeof(info->driver) - 1);
584 strncpy(info->fw_version, i2400m->fw_name, sizeof(info->fw_version) - 1);
585 if (net_dev->dev.parent)
586 strncpy(info->bus_info, dev_name(net_dev->dev.parent),
587 sizeof(info->bus_info) - 1);
588}
589
590static const struct ethtool_ops i2400m_ethtool_ops = {
591 .get_drvinfo = i2400m_get_drvinfo,
592 .get_link = ethtool_op_get_link,
593};
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800594
595/**
596 * i2400m_netdev_setup - Setup setup @net_dev's i2400m private data
597 *
598 * Called by alloc_netdev()
599 */
600void i2400m_netdev_setup(struct net_device *net_dev)
601{
602 d_fnstart(3, NULL, "(net_dev %p)\n", net_dev);
603 ether_setup(net_dev);
604 net_dev->mtu = I2400M_MAX_MTU;
605 net_dev->tx_queue_len = I2400M_TX_QLEN;
606 net_dev->features =
607 NETIF_F_VLAN_CHALLENGED
608 | NETIF_F_HIGHDMA;
609 net_dev->flags =
610 IFF_NOARP /* i2400m is apure IP device */
611 & (~IFF_BROADCAST /* i2400m is P2P */
612 & ~IFF_MULTICAST);
613 net_dev->watchdog_timeo = I2400M_TX_TIMEOUT;
Inaky Perez-Gonzaleza962dc22009-01-09 16:43:49 +0000614 net_dev->netdev_ops = &i2400m_netdev_ops;
Dan Williamsabb30732009-09-17 13:06:14 -0700615 net_dev->ethtool_ops = &i2400m_ethtool_ops;
Inaky Perez-Gonzalezce6cde92008-12-20 16:57:45 -0800616 d_fnend(3, NULL, "(net_dev %p) = void\n", net_dev);
617}
618EXPORT_SYMBOL_GPL(i2400m_netdev_setup);
619