netdev.c 20 KB

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