netdev.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  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 <linux/export.h>
  80. #include "i2400m.h"
  81. #define D_SUBMODULE netdev
  82. #include "debug-levels.h"
  83. enum {
  84. /* netdev interface */
  85. /* 20 secs? yep, this is the maximum timeout that the device
  86. * might take to get out of IDLE / negotiate it with the base
  87. * station. We add 1sec for good measure. */
  88. I2400M_TX_TIMEOUT = 21 * HZ,
  89. /*
  90. * Experimentation has determined that, 20 to be a good value
  91. * for minimizing the jitter in the throughput.
  92. */
  93. I2400M_TX_QLEN = 20,
  94. };
  95. static
  96. int i2400m_open(struct net_device *net_dev)
  97. {
  98. int result;
  99. struct i2400m *i2400m = net_dev_to_i2400m(net_dev);
  100. struct device *dev = i2400m_dev(i2400m);
  101. d_fnstart(3, dev, "(net_dev %p [i2400m %p])\n", net_dev, i2400m);
  102. /* Make sure we wait until init is complete... */
  103. mutex_lock(&i2400m->init_mutex);
  104. if (i2400m->updown)
  105. result = 0;
  106. else
  107. result = -EBUSY;
  108. mutex_unlock(&i2400m->init_mutex);
  109. d_fnend(3, dev, "(net_dev %p [i2400m %p]) = %d\n",
  110. net_dev, i2400m, result);
  111. return result;
  112. }
  113. static
  114. int i2400m_stop(struct net_device *net_dev)
  115. {
  116. struct i2400m *i2400m = net_dev_to_i2400m(net_dev);
  117. struct device *dev = i2400m_dev(i2400m);
  118. d_fnstart(3, dev, "(net_dev %p [i2400m %p])\n", net_dev, i2400m);
  119. i2400m_net_wake_stop(i2400m);
  120. d_fnend(3, dev, "(net_dev %p [i2400m %p]) = 0\n", net_dev, i2400m);
  121. return 0;
  122. }
  123. /*
  124. * Wake up the device and transmit a held SKB, then restart the net queue
  125. *
  126. * When the device goes into basestation-idle mode, we need to tell it
  127. * to exit that mode; it will negotiate with the base station, user
  128. * space may have to intervene to rehandshake crypto and then tell us
  129. * when it is ready to transmit the packet we have "queued". Still we
  130. * need to give it sometime after it reports being ok.
  131. *
  132. * On error, there is not much we can do. If the error was on TX, we
  133. * still wake the queue up to see if the next packet will be luckier.
  134. *
  135. * If _cmd_exit_idle() fails...well, it could be many things; most
  136. * commonly it is that something else took the device out of IDLE mode
  137. * (for example, the base station). In that case we get an -EILSEQ and
  138. * we are just going to ignore that one. If the device is back to
  139. * connected, then fine -- if it is someother state, the packet will
  140. * be dropped anyway.
  141. */
  142. void i2400m_wake_tx_work(struct work_struct *ws)
  143. {
  144. int result;
  145. struct i2400m *i2400m = container_of(ws, struct i2400m, wake_tx_ws);
  146. struct net_device *net_dev = i2400m->wimax_dev.net_dev;
  147. struct device *dev = i2400m_dev(i2400m);
  148. struct sk_buff *skb;
  149. unsigned long flags;
  150. spin_lock_irqsave(&i2400m->tx_lock, flags);
  151. skb = i2400m->wake_tx_skb;
  152. i2400m->wake_tx_skb = NULL;
  153. spin_unlock_irqrestore(&i2400m->tx_lock, flags);
  154. d_fnstart(3, dev, "(ws %p i2400m %p skb %p)\n", ws, i2400m, skb);
  155. result = -EINVAL;
  156. if (skb == NULL) {
  157. dev_err(dev, "WAKE&TX: skb disappeared!\n");
  158. goto out_put;
  159. }
  160. /* If we have, somehow, lost the connection after this was
  161. * queued, don't do anything; this might be the device got
  162. * reset or just disconnected. */
  163. if (unlikely(!netif_carrier_ok(net_dev)))
  164. goto out_kfree;
  165. result = i2400m_cmd_exit_idle(i2400m);
  166. if (result == -EILSEQ)
  167. result = 0;
  168. if (result < 0) {
  169. dev_err(dev, "WAKE&TX: device didn't get out of idle: "
  170. "%d - resetting\n", result);
  171. i2400m_reset(i2400m, I2400M_RT_BUS);
  172. goto error;
  173. }
  174. result = wait_event_timeout(i2400m->state_wq,
  175. i2400m->state != I2400M_SS_IDLE,
  176. net_dev->watchdog_timeo - HZ/2);
  177. if (result == 0)
  178. result = -ETIMEDOUT;
  179. if (result < 0) {
  180. dev_err(dev, "WAKE&TX: error waiting for device to exit IDLE: "
  181. "%d - resetting\n", result);
  182. i2400m_reset(i2400m, I2400M_RT_BUS);
  183. goto error;
  184. }
  185. msleep(20); /* device still needs some time or it drops it */
  186. result = i2400m_tx(i2400m, skb->data, skb->len, I2400M_PT_DATA);
  187. error:
  188. netif_wake_queue(net_dev);
  189. out_kfree:
  190. kfree_skb(skb); /* refcount transferred by _hard_start_xmit() */
  191. out_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. * Prepare the data payload TX header
  198. *
  199. * The i2400m expects a 4 byte header in front of a data packet.
  200. *
  201. * Because we pretend to be an ethernet device, this packet comes with
  202. * an ethernet header. Pull it and push our header.
  203. */
  204. static
  205. void i2400m_tx_prep_header(struct sk_buff *skb)
  206. {
  207. struct i2400m_pl_data_hdr *pl_hdr;
  208. skb_pull(skb, ETH_HLEN);
  209. pl_hdr = skb_push(skb, sizeof(*pl_hdr));
  210. pl_hdr->reserved = 0;
  211. }
  212. /*
  213. * Cleanup resources acquired during i2400m_net_wake_tx()
  214. *
  215. * This is called by __i2400m_dev_stop and means we have to make sure
  216. * the workqueue is flushed from any pending work.
  217. */
  218. void i2400m_net_wake_stop(struct i2400m *i2400m)
  219. {
  220. struct device *dev = i2400m_dev(i2400m);
  221. struct sk_buff *wake_tx_skb;
  222. unsigned long flags;
  223. d_fnstart(3, dev, "(i2400m %p)\n", i2400m);
  224. /*
  225. * See i2400m_hard_start_xmit(), references are taken there and
  226. * here we release them if the packet was still pending.
  227. */
  228. cancel_work_sync(&i2400m->wake_tx_ws);
  229. spin_lock_irqsave(&i2400m->tx_lock, flags);
  230. wake_tx_skb = i2400m->wake_tx_skb;
  231. i2400m->wake_tx_skb = NULL;
  232. spin_unlock_irqrestore(&i2400m->tx_lock, flags);
  233. if (wake_tx_skb) {
  234. i2400m_put(i2400m);
  235. kfree_skb(wake_tx_skb);
  236. }
  237. d_fnend(3, dev, "(i2400m %p) = void\n", i2400m);
  238. }
  239. /*
  240. * TX an skb to an idle device
  241. *
  242. * When the device is in basestation-idle mode, we need to wake it up
  243. * and then TX. So we queue a work_struct for doing so.
  244. *
  245. * We need to get an extra ref for the skb (so it is not dropped), as
  246. * well as be careful not to queue more than one request (won't help
  247. * at all). If more than one request comes or there are errors, we
  248. * just drop the packets (see i2400m_hard_start_xmit()).
  249. */
  250. static
  251. int i2400m_net_wake_tx(struct i2400m *i2400m, struct net_device *net_dev,
  252. struct sk_buff *skb)
  253. {
  254. int result;
  255. struct device *dev = i2400m_dev(i2400m);
  256. unsigned long flags;
  257. d_fnstart(3, dev, "(skb %p net_dev %p)\n", skb, net_dev);
  258. if (net_ratelimit()) {
  259. d_printf(3, dev, "WAKE&NETTX: "
  260. "skb %p sending %d bytes to radio\n",
  261. skb, skb->len);
  262. d_dump(4, dev, skb->data, skb->len);
  263. }
  264. /* We hold a ref count for i2400m and skb, so when
  265. * stopping() the device, we need to cancel that work
  266. * and if pending, release those resources. */
  267. result = 0;
  268. spin_lock_irqsave(&i2400m->tx_lock, flags);
  269. if (!i2400m->wake_tx_skb) {
  270. netif_stop_queue(net_dev);
  271. i2400m_get(i2400m);
  272. i2400m->wake_tx_skb = skb_get(skb); /* transfer ref count */
  273. i2400m_tx_prep_header(skb);
  274. result = schedule_work(&i2400m->wake_tx_ws);
  275. WARN_ON(result == 0);
  276. }
  277. spin_unlock_irqrestore(&i2400m->tx_lock, flags);
  278. if (result == 0) {
  279. /* Yes, this happens even if we stopped the
  280. * queue -- blame the queue disciplines that
  281. * queue without looking -- I guess there is a reason
  282. * for that. */
  283. if (net_ratelimit())
  284. d_printf(1, dev, "NETTX: device exiting idle, "
  285. "dropping skb %p, queue running %d\n",
  286. skb, netif_queue_stopped(net_dev));
  287. result = -EBUSY;
  288. }
  289. d_fnend(3, dev, "(skb %p net_dev %p) = %d\n", skb, net_dev, result);
  290. return result;
  291. }
  292. /*
  293. * Transmit a packet to the base station on behalf of the network stack.
  294. *
  295. * Returns: 0 if ok, < 0 errno code on error.
  296. *
  297. * We need to pull the ethernet header and add the hardware header,
  298. * which is currently set to all zeroes and reserved.
  299. */
  300. static
  301. int i2400m_net_tx(struct i2400m *i2400m, struct net_device *net_dev,
  302. struct sk_buff *skb)
  303. {
  304. int result;
  305. struct device *dev = i2400m_dev(i2400m);
  306. d_fnstart(3, dev, "(i2400m %p net_dev %p skb %p)\n",
  307. i2400m, net_dev, skb);
  308. /* FIXME: check eth hdr, only IPv4 is routed by the device as of now */
  309. netif_trans_update(net_dev);
  310. i2400m_tx_prep_header(skb);
  311. d_printf(3, dev, "NETTX: skb %p sending %d bytes to radio\n",
  312. skb, skb->len);
  313. d_dump(4, dev, skb->data, skb->len);
  314. result = i2400m_tx(i2400m, skb->data, skb->len, I2400M_PT_DATA);
  315. d_fnend(3, dev, "(i2400m %p net_dev %p skb %p) = %d\n",
  316. i2400m, net_dev, skb, result);
  317. return result;
  318. }
  319. /*
  320. * Transmit a packet to the base station on behalf of the network stack
  321. *
  322. *
  323. * Returns: NETDEV_TX_OK (always, even in case of error)
  324. *
  325. * In case of error, we just drop it. Reasons:
  326. *
  327. * - we add a hw header to each skb, and if the network stack
  328. * retries, we have no way to know if that skb has it or not.
  329. *
  330. * - network protocols have their own drop-recovery mechanisms
  331. *
  332. * - there is not much else we can do
  333. *
  334. * If the device is idle, we need to wake it up; that is an operation
  335. * that will sleep. See i2400m_net_wake_tx() for details.
  336. */
  337. static
  338. netdev_tx_t i2400m_hard_start_xmit(struct sk_buff *skb,
  339. struct net_device *net_dev)
  340. {
  341. struct i2400m *i2400m = net_dev_to_i2400m(net_dev);
  342. struct device *dev = i2400m_dev(i2400m);
  343. int result = -1;
  344. d_fnstart(3, dev, "(skb %p net_dev %p)\n", skb, net_dev);
  345. if (skb_cow_head(skb, 0))
  346. goto drop;
  347. if (i2400m->state == I2400M_SS_IDLE)
  348. result = i2400m_net_wake_tx(i2400m, net_dev, skb);
  349. else
  350. result = i2400m_net_tx(i2400m, net_dev, skb);
  351. if (result < 0) {
  352. drop:
  353. net_dev->stats.tx_dropped++;
  354. } else {
  355. net_dev->stats.tx_packets++;
  356. net_dev->stats.tx_bytes += skb->len;
  357. }
  358. dev_kfree_skb(skb);
  359. d_fnend(3, dev, "(skb %p net_dev %p) = %d\n", skb, net_dev, result);
  360. return NETDEV_TX_OK;
  361. }
  362. static
  363. void i2400m_tx_timeout(struct net_device *net_dev)
  364. {
  365. /*
  366. * We might want to kick the device
  367. *
  368. * There is not much we can do though, as the device requires
  369. * that we send the data aggregated. By the time we receive
  370. * this, there might be data pending to be sent or not...
  371. */
  372. net_dev->stats.tx_errors++;
  373. }
  374. /*
  375. * Create a fake ethernet header
  376. *
  377. * For emulating an ethernet device, every received IP header has to
  378. * be prefixed with an ethernet header. Fake it with the given
  379. * protocol.
  380. */
  381. static
  382. void i2400m_rx_fake_eth_header(struct net_device *net_dev,
  383. void *_eth_hdr, __be16 protocol)
  384. {
  385. struct i2400m *i2400m = net_dev_to_i2400m(net_dev);
  386. struct ethhdr *eth_hdr = _eth_hdr;
  387. memcpy(eth_hdr->h_dest, net_dev->dev_addr, sizeof(eth_hdr->h_dest));
  388. memcpy(eth_hdr->h_source, i2400m->src_mac_addr,
  389. sizeof(eth_hdr->h_source));
  390. eth_hdr->h_proto = protocol;
  391. }
  392. /*
  393. * i2400m_net_rx - pass a network packet to the stack
  394. *
  395. * @i2400m: device instance
  396. * @skb_rx: the skb where the buffer pointed to by @buf is
  397. * @i: 1 if payload is the only one
  398. * @buf: pointer to the buffer containing the data
  399. * @len: buffer's length
  400. *
  401. * This is only used now for the v1.3 firmware. It will be deprecated
  402. * in >= 2.6.31.
  403. *
  404. * Note that due to firmware limitations, we don't have space to add
  405. * an ethernet header, so we need to copy each packet. Firmware
  406. * versions >= v1.4 fix this [see i2400m_net_erx()].
  407. *
  408. * We just clone the skb and set it up so that it's skb->data pointer
  409. * points to "buf" and it's length.
  410. *
  411. * Note that if the payload is the last (or the only one) in a
  412. * multi-payload message, we don't clone the SKB but just reuse it.
  413. *
  414. * This function is normally run from a thread context. However, we
  415. * still use netif_rx() instead of netif_receive_skb() as was
  416. * recommended in the mailing list. Reason is in some stress tests
  417. * when sending/receiving a lot of data we seem to hit a softlock in
  418. * the kernel's TCP implementation [aroudn tcp_delay_timer()]. Using
  419. * netif_rx() took care of the issue.
  420. *
  421. * This is, of course, still open to do more research on why running
  422. * with netif_receive_skb() hits this softlock. FIXME.
  423. *
  424. * FIXME: currently we don't do any efforts at distinguishing if what
  425. * we got was an IPv4 or IPv6 header, to setup the protocol field
  426. * correctly.
  427. */
  428. void i2400m_net_rx(struct i2400m *i2400m, struct sk_buff *skb_rx,
  429. unsigned i, const void *buf, int buf_len)
  430. {
  431. struct net_device *net_dev = i2400m->wimax_dev.net_dev;
  432. struct device *dev = i2400m_dev(i2400m);
  433. struct sk_buff *skb;
  434. d_fnstart(2, dev, "(i2400m %p buf %p buf_len %d)\n",
  435. i2400m, buf, buf_len);
  436. if (i) {
  437. skb = skb_get(skb_rx);
  438. d_printf(2, dev, "RX: reusing first payload skb %p\n", skb);
  439. skb_pull(skb, buf - (void *) skb->data);
  440. skb_trim(skb, (void *) skb_end_pointer(skb) - buf);
  441. } else {
  442. /* Yes, this is bad -- a lot of overhead -- see
  443. * comments at the top of the file */
  444. skb = __netdev_alloc_skb(net_dev, buf_len, GFP_KERNEL);
  445. if (skb == NULL) {
  446. dev_err(dev, "NETRX: no memory to realloc skb\n");
  447. net_dev->stats.rx_dropped++;
  448. goto error_skb_realloc;
  449. }
  450. skb_put_data(skb, buf, buf_len);
  451. }
  452. i2400m_rx_fake_eth_header(i2400m->wimax_dev.net_dev,
  453. skb->data - ETH_HLEN,
  454. cpu_to_be16(ETH_P_IP));
  455. skb_set_mac_header(skb, -ETH_HLEN);
  456. skb->dev = i2400m->wimax_dev.net_dev;
  457. skb->protocol = htons(ETH_P_IP);
  458. net_dev->stats.rx_packets++;
  459. net_dev->stats.rx_bytes += buf_len;
  460. d_printf(3, dev, "NETRX: receiving %d bytes to network stack\n",
  461. buf_len);
  462. d_dump(4, dev, buf, buf_len);
  463. netif_rx_ni(skb); /* see notes in function header */
  464. error_skb_realloc:
  465. d_fnend(2, dev, "(i2400m %p buf %p buf_len %d) = void\n",
  466. i2400m, buf, buf_len);
  467. }
  468. /*
  469. * i2400m_net_erx - pass a network packet to the stack (extended version)
  470. *
  471. * @i2400m: device descriptor
  472. * @skb: the skb where the packet is - the skb should be set to point
  473. * at the IP packet; this function will add ethernet headers if
  474. * needed.
  475. * @cs: packet type
  476. *
  477. * This is only used now for firmware >= v1.4. Note it is quite
  478. * similar to i2400m_net_rx() (used only for v1.3 firmware).
  479. *
  480. * This function is normally run from a thread context. However, we
  481. * still use netif_rx() instead of netif_receive_skb() as was
  482. * recommended in the mailing list. Reason is in some stress tests
  483. * when sending/receiving a lot of data we seem to hit a softlock in
  484. * the kernel's TCP implementation [aroudn tcp_delay_timer()]. Using
  485. * netif_rx() took care of the issue.
  486. *
  487. * This is, of course, still open to do more research on why running
  488. * with netif_receive_skb() hits this softlock. FIXME.
  489. */
  490. void i2400m_net_erx(struct i2400m *i2400m, struct sk_buff *skb,
  491. enum i2400m_cs cs)
  492. {
  493. struct net_device *net_dev = i2400m->wimax_dev.net_dev;
  494. struct device *dev = i2400m_dev(i2400m);
  495. int protocol;
  496. d_fnstart(2, dev, "(i2400m %p skb %p [%u] cs %d)\n",
  497. i2400m, skb, skb->len, cs);
  498. switch(cs) {
  499. case I2400M_CS_IPV4_0:
  500. case I2400M_CS_IPV4:
  501. protocol = ETH_P_IP;
  502. i2400m_rx_fake_eth_header(i2400m->wimax_dev.net_dev,
  503. skb->data - ETH_HLEN,
  504. cpu_to_be16(ETH_P_IP));
  505. skb_set_mac_header(skb, -ETH_HLEN);
  506. skb->dev = i2400m->wimax_dev.net_dev;
  507. skb->protocol = htons(ETH_P_IP);
  508. net_dev->stats.rx_packets++;
  509. net_dev->stats.rx_bytes += skb->len;
  510. break;
  511. default:
  512. dev_err(dev, "ERX: BUG? CS type %u unsupported\n", cs);
  513. goto error;
  514. }
  515. d_printf(3, dev, "ERX: receiving %d bytes to the network stack\n",
  516. skb->len);
  517. d_dump(4, dev, skb->data, skb->len);
  518. netif_rx_ni(skb); /* see notes in function header */
  519. error:
  520. d_fnend(2, dev, "(i2400m %p skb %p [%u] cs %d) = void\n",
  521. i2400m, skb, skb->len, cs);
  522. }
  523. static const struct net_device_ops i2400m_netdev_ops = {
  524. .ndo_open = i2400m_open,
  525. .ndo_stop = i2400m_stop,
  526. .ndo_start_xmit = i2400m_hard_start_xmit,
  527. .ndo_tx_timeout = i2400m_tx_timeout,
  528. };
  529. static void i2400m_get_drvinfo(struct net_device *net_dev,
  530. struct ethtool_drvinfo *info)
  531. {
  532. struct i2400m *i2400m = net_dev_to_i2400m(net_dev);
  533. strlcpy(info->driver, KBUILD_MODNAME, sizeof(info->driver));
  534. strlcpy(info->fw_version, i2400m->fw_name ? : "",
  535. sizeof(info->fw_version));
  536. if (net_dev->dev.parent)
  537. strlcpy(info->bus_info, dev_name(net_dev->dev.parent),
  538. sizeof(info->bus_info));
  539. }
  540. static const struct ethtool_ops i2400m_ethtool_ops = {
  541. .get_drvinfo = i2400m_get_drvinfo,
  542. .get_link = ethtool_op_get_link,
  543. };
  544. /**
  545. * i2400m_netdev_setup - Setup setup @net_dev's i2400m private data
  546. *
  547. * Called by alloc_netdev()
  548. */
  549. void i2400m_netdev_setup(struct net_device *net_dev)
  550. {
  551. d_fnstart(3, NULL, "(net_dev %p)\n", net_dev);
  552. ether_setup(net_dev);
  553. net_dev->mtu = I2400M_MAX_MTU;
  554. net_dev->min_mtu = 0;
  555. net_dev->max_mtu = I2400M_MAX_MTU;
  556. net_dev->tx_queue_len = I2400M_TX_QLEN;
  557. net_dev->features =
  558. NETIF_F_VLAN_CHALLENGED
  559. | NETIF_F_HIGHDMA;
  560. net_dev->flags =
  561. IFF_NOARP /* i2400m is apure IP device */
  562. & (~IFF_BROADCAST /* i2400m is P2P */
  563. & ~IFF_MULTICAST);
  564. net_dev->watchdog_timeo = I2400M_TX_TIMEOUT;
  565. net_dev->netdev_ops = &i2400m_netdev_ops;
  566. net_dev->ethtool_ops = &i2400m_ethtool_ops;
  567. d_fnend(3, NULL, "(net_dev %p) = void\n", net_dev);
  568. }
  569. EXPORT_SYMBOL_GPL(i2400m_netdev_setup);