arcnet.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219
  1. /*
  2. * Linux ARCnet driver - device-independent routines
  3. *
  4. * Written 1997 by David Woodhouse.
  5. * Written 1994-1999 by Avery Pennarun.
  6. * Written 1999-2000 by Martin Mares <[email protected]>.
  7. * Derived from skeleton.c by Donald Becker.
  8. *
  9. * Special thanks to Contemporary Controls, Inc. (www.ccontrols.com)
  10. * for sponsoring the further development of this driver.
  11. *
  12. * **********************
  13. *
  14. * The original copyright was as follows:
  15. *
  16. * skeleton.c Written 1993 by Donald Becker.
  17. * Copyright 1993 United States Government as represented by the
  18. * Director, National Security Agency. This software may only be used
  19. * and distributed according to the terms of the GNU General Public License as
  20. * modified by SRC, incorporated herein by reference.
  21. *
  22. * **********************
  23. *
  24. * The change log is now in a file called ChangeLog in this directory.
  25. *
  26. * Sources:
  27. * - Crynwr arcnet.com/arcether.com packet drivers.
  28. * - arcnet.c v0.00 dated 1/1/94 and apparently by
  29. * Donald Becker - it didn't work :)
  30. * - skeleton.c v0.05 dated 11/16/93 by Donald Becker
  31. * (from Linux Kernel 1.1.45)
  32. * - RFC's 1201 and 1051 - re: TCP/IP over ARCnet
  33. * - The official ARCnet COM9026 data sheets (!) thanks to
  34. * Ken Cornetet <[email protected]>
  35. * - The official ARCnet COM20020 data sheets.
  36. * - Information on some more obscure ARCnet controller chips, thanks
  37. * to the nice people at SMSC.
  38. * - net/inet/eth.c (from kernel 1.1.50) for header-building info.
  39. * - Alternate Linux ARCnet source by V.Shergin <[email protected]>
  40. * - Textual information and more alternate source from Joachim Koenig
  41. * <[email protected]>
  42. */
  43. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  44. #include <linux/module.h>
  45. #include <linux/types.h>
  46. #include <linux/delay.h>
  47. #include <linux/netdevice.h>
  48. #include <linux/if_arp.h>
  49. #include <net/arp.h>
  50. #include <linux/init.h>
  51. #include <linux/jiffies.h>
  52. #include <linux/errqueue.h>
  53. #include <linux/leds.h>
  54. #include "arcdevice.h"
  55. #include "com9026.h"
  56. /* "do nothing" functions for protocol drivers */
  57. static void null_rx(struct net_device *dev, int bufnum,
  58. struct archdr *pkthdr, int length);
  59. static int null_build_header(struct sk_buff *skb, struct net_device *dev,
  60. unsigned short type, uint8_t daddr);
  61. static int null_prepare_tx(struct net_device *dev, struct archdr *pkt,
  62. int length, int bufnum);
  63. static void arcnet_rx(struct net_device *dev, int bufnum);
  64. /* one ArcProto per possible proto ID. None of the elements of
  65. * arc_proto_map are allowed to be NULL; they will get set to
  66. * arc_proto_default instead. It also must not be NULL; if you would like
  67. * to set it to NULL, set it to &arc_proto_null instead.
  68. */
  69. struct ArcProto *arc_proto_map[256];
  70. EXPORT_SYMBOL(arc_proto_map);
  71. struct ArcProto *arc_proto_default;
  72. EXPORT_SYMBOL(arc_proto_default);
  73. struct ArcProto *arc_bcast_proto;
  74. EXPORT_SYMBOL(arc_bcast_proto);
  75. struct ArcProto *arc_raw_proto;
  76. EXPORT_SYMBOL(arc_raw_proto);
  77. static struct ArcProto arc_proto_null = {
  78. .suffix = '?',
  79. .mtu = XMTU,
  80. .is_ip = 0,
  81. .rx = null_rx,
  82. .build_header = null_build_header,
  83. .prepare_tx = null_prepare_tx,
  84. .continue_tx = NULL,
  85. .ack_tx = NULL
  86. };
  87. /* Exported function prototypes */
  88. int arcnet_debug = ARCNET_DEBUG;
  89. EXPORT_SYMBOL(arcnet_debug);
  90. /* Internal function prototypes */
  91. static int arcnet_header(struct sk_buff *skb, struct net_device *dev,
  92. unsigned short type, const void *daddr,
  93. const void *saddr, unsigned len);
  94. static int go_tx(struct net_device *dev);
  95. static int debug = ARCNET_DEBUG;
  96. module_param(debug, int, 0);
  97. MODULE_LICENSE("GPL");
  98. static int __init arcnet_init(void)
  99. {
  100. int count;
  101. arcnet_debug = debug;
  102. pr_info("arcnet loaded\n");
  103. /* initialize the protocol map */
  104. arc_raw_proto = arc_proto_default = arc_bcast_proto = &arc_proto_null;
  105. for (count = 0; count < 256; count++)
  106. arc_proto_map[count] = arc_proto_default;
  107. if (BUGLVL(D_DURING))
  108. pr_info("struct sizes: %zd %zd %zd %zd %zd\n",
  109. sizeof(struct arc_hardware),
  110. sizeof(struct arc_rfc1201),
  111. sizeof(struct arc_rfc1051),
  112. sizeof(struct arc_eth_encap),
  113. sizeof(struct archdr));
  114. return 0;
  115. }
  116. static void __exit arcnet_exit(void)
  117. {
  118. }
  119. module_init(arcnet_init);
  120. module_exit(arcnet_exit);
  121. /* Dump the contents of an sk_buff */
  122. #if ARCNET_DEBUG_MAX & D_SKB
  123. void arcnet_dump_skb(struct net_device *dev,
  124. struct sk_buff *skb, char *desc)
  125. {
  126. char hdr[32];
  127. /* dump the packet */
  128. snprintf(hdr, sizeof(hdr), "%6s:%s skb->data:", dev->name, desc);
  129. print_hex_dump(KERN_DEBUG, hdr, DUMP_PREFIX_OFFSET,
  130. 16, 1, skb->data, skb->len, true);
  131. }
  132. EXPORT_SYMBOL(arcnet_dump_skb);
  133. #endif
  134. /* Dump the contents of an ARCnet buffer */
  135. #if (ARCNET_DEBUG_MAX & (D_RX | D_TX))
  136. static void arcnet_dump_packet(struct net_device *dev, int bufnum,
  137. char *desc, int take_arcnet_lock)
  138. {
  139. struct arcnet_local *lp = netdev_priv(dev);
  140. int i, length;
  141. unsigned long flags = 0;
  142. static uint8_t buf[512];
  143. char hdr[32];
  144. /* hw.copy_from_card expects IRQ context so take the IRQ lock
  145. * to keep it single threaded
  146. */
  147. if (take_arcnet_lock)
  148. spin_lock_irqsave(&lp->lock, flags);
  149. lp->hw.copy_from_card(dev, bufnum, 0, buf, 512);
  150. if (take_arcnet_lock)
  151. spin_unlock_irqrestore(&lp->lock, flags);
  152. /* if the offset[0] byte is nonzero, this is a 256-byte packet */
  153. length = (buf[2] ? 256 : 512);
  154. /* dump the packet */
  155. snprintf(hdr, sizeof(hdr), "%6s:%s packet dump:", dev->name, desc);
  156. print_hex_dump(KERN_DEBUG, hdr, DUMP_PREFIX_OFFSET,
  157. 16, 1, buf, length, true);
  158. }
  159. #else
  160. #define arcnet_dump_packet(dev, bufnum, desc, take_arcnet_lock) do { } while (0)
  161. #endif
  162. /* Trigger a LED event in response to a ARCNET device event */
  163. void arcnet_led_event(struct net_device *dev, enum arcnet_led_event event)
  164. {
  165. struct arcnet_local *lp = netdev_priv(dev);
  166. unsigned long led_delay = 350;
  167. unsigned long tx_delay = 50;
  168. switch (event) {
  169. case ARCNET_LED_EVENT_RECON:
  170. led_trigger_blink_oneshot(lp->recon_led_trig,
  171. &led_delay, &led_delay, 0);
  172. break;
  173. case ARCNET_LED_EVENT_OPEN:
  174. led_trigger_event(lp->tx_led_trig, LED_OFF);
  175. led_trigger_event(lp->recon_led_trig, LED_OFF);
  176. break;
  177. case ARCNET_LED_EVENT_STOP:
  178. led_trigger_event(lp->tx_led_trig, LED_OFF);
  179. led_trigger_event(lp->recon_led_trig, LED_OFF);
  180. break;
  181. case ARCNET_LED_EVENT_TX:
  182. led_trigger_blink_oneshot(lp->tx_led_trig,
  183. &tx_delay, &tx_delay, 0);
  184. break;
  185. }
  186. }
  187. EXPORT_SYMBOL_GPL(arcnet_led_event);
  188. static void arcnet_led_release(struct device *gendev, void *res)
  189. {
  190. struct arcnet_local *lp = netdev_priv(to_net_dev(gendev));
  191. led_trigger_unregister_simple(lp->tx_led_trig);
  192. led_trigger_unregister_simple(lp->recon_led_trig);
  193. }
  194. /* Register ARCNET LED triggers for a arcnet device
  195. *
  196. * This is normally called from a driver's probe function
  197. */
  198. void devm_arcnet_led_init(struct net_device *netdev, int index, int subid)
  199. {
  200. struct arcnet_local *lp = netdev_priv(netdev);
  201. void *res;
  202. res = devres_alloc(arcnet_led_release, 0, GFP_KERNEL);
  203. if (!res) {
  204. netdev_err(netdev, "cannot register LED triggers\n");
  205. return;
  206. }
  207. snprintf(lp->tx_led_trig_name, sizeof(lp->tx_led_trig_name),
  208. "arc%d-%d-tx", index, subid);
  209. snprintf(lp->recon_led_trig_name, sizeof(lp->recon_led_trig_name),
  210. "arc%d-%d-recon", index, subid);
  211. led_trigger_register_simple(lp->tx_led_trig_name,
  212. &lp->tx_led_trig);
  213. led_trigger_register_simple(lp->recon_led_trig_name,
  214. &lp->recon_led_trig);
  215. devres_add(&netdev->dev, res);
  216. }
  217. EXPORT_SYMBOL_GPL(devm_arcnet_led_init);
  218. /* Unregister a protocol driver from the arc_proto_map. Protocol drivers
  219. * are responsible for registering themselves, but the unregister routine
  220. * is pretty generic so we'll do it here.
  221. */
  222. void arcnet_unregister_proto(struct ArcProto *proto)
  223. {
  224. int count;
  225. if (arc_proto_default == proto)
  226. arc_proto_default = &arc_proto_null;
  227. if (arc_bcast_proto == proto)
  228. arc_bcast_proto = arc_proto_default;
  229. if (arc_raw_proto == proto)
  230. arc_raw_proto = arc_proto_default;
  231. for (count = 0; count < 256; count++) {
  232. if (arc_proto_map[count] == proto)
  233. arc_proto_map[count] = arc_proto_default;
  234. }
  235. }
  236. EXPORT_SYMBOL(arcnet_unregister_proto);
  237. /* Add a buffer to the queue. Only the interrupt handler is allowed to do
  238. * this, unless interrupts are disabled.
  239. *
  240. * Note: we don't check for a full queue, since there aren't enough buffers
  241. * to more than fill it.
  242. */
  243. static void release_arcbuf(struct net_device *dev, int bufnum)
  244. {
  245. struct arcnet_local *lp = netdev_priv(dev);
  246. int i;
  247. lp->buf_queue[lp->first_free_buf++] = bufnum;
  248. lp->first_free_buf %= 5;
  249. if (BUGLVL(D_DURING)) {
  250. arc_printk(D_DURING, dev, "release_arcbuf: freed #%d; buffer queue is now: ",
  251. bufnum);
  252. for (i = lp->next_buf; i != lp->first_free_buf; i = (i + 1) % 5)
  253. arc_cont(D_DURING, "#%d ", lp->buf_queue[i]);
  254. arc_cont(D_DURING, "\n");
  255. }
  256. }
  257. /* Get a buffer from the queue.
  258. * If this returns -1, there are no buffers available.
  259. */
  260. static int get_arcbuf(struct net_device *dev)
  261. {
  262. struct arcnet_local *lp = netdev_priv(dev);
  263. int buf = -1, i;
  264. if (!atomic_dec_and_test(&lp->buf_lock)) {
  265. /* already in this function */
  266. arc_printk(D_NORMAL, dev, "get_arcbuf: overlap (%d)!\n",
  267. lp->buf_lock.counter);
  268. } else { /* we can continue */
  269. if (lp->next_buf >= 5)
  270. lp->next_buf -= 5;
  271. if (lp->next_buf == lp->first_free_buf) {
  272. arc_printk(D_NORMAL, dev, "get_arcbuf: BUG: no buffers are available??\n");
  273. } else {
  274. buf = lp->buf_queue[lp->next_buf++];
  275. lp->next_buf %= 5;
  276. }
  277. }
  278. if (BUGLVL(D_DURING)) {
  279. arc_printk(D_DURING, dev, "get_arcbuf: got #%d; buffer queue is now: ",
  280. buf);
  281. for (i = lp->next_buf; i != lp->first_free_buf; i = (i + 1) % 5)
  282. arc_cont(D_DURING, "#%d ", lp->buf_queue[i]);
  283. arc_cont(D_DURING, "\n");
  284. }
  285. atomic_inc(&lp->buf_lock);
  286. return buf;
  287. }
  288. static int choose_mtu(void)
  289. {
  290. int count, mtu = 65535;
  291. /* choose the smallest MTU of all available encaps */
  292. for (count = 0; count < 256; count++) {
  293. if (arc_proto_map[count] != &arc_proto_null &&
  294. arc_proto_map[count]->mtu < mtu) {
  295. mtu = arc_proto_map[count]->mtu;
  296. }
  297. }
  298. return mtu == 65535 ? XMTU : mtu;
  299. }
  300. static const struct header_ops arcnet_header_ops = {
  301. .create = arcnet_header,
  302. };
  303. static const struct net_device_ops arcnet_netdev_ops = {
  304. .ndo_open = arcnet_open,
  305. .ndo_stop = arcnet_close,
  306. .ndo_start_xmit = arcnet_send_packet,
  307. .ndo_tx_timeout = arcnet_timeout,
  308. };
  309. /* Setup a struct device for ARCnet. */
  310. static void arcdev_setup(struct net_device *dev)
  311. {
  312. dev->type = ARPHRD_ARCNET;
  313. dev->netdev_ops = &arcnet_netdev_ops;
  314. dev->header_ops = &arcnet_header_ops;
  315. dev->hard_header_len = sizeof(struct arc_hardware);
  316. dev->mtu = choose_mtu();
  317. dev->addr_len = ARCNET_ALEN;
  318. dev->tx_queue_len = 100;
  319. dev->broadcast[0] = 0x00; /* for us, broadcasts are address 0 */
  320. dev->watchdog_timeo = TX_TIMEOUT;
  321. /* New-style flags. */
  322. dev->flags = IFF_BROADCAST;
  323. }
  324. static void arcnet_timer(struct timer_list *t)
  325. {
  326. struct arcnet_local *lp = from_timer(lp, t, timer);
  327. struct net_device *dev = lp->dev;
  328. spin_lock_irq(&lp->lock);
  329. if (!lp->reset_in_progress && !netif_carrier_ok(dev)) {
  330. netif_carrier_on(dev);
  331. netdev_info(dev, "link up\n");
  332. }
  333. spin_unlock_irq(&lp->lock);
  334. }
  335. static void reset_device_work(struct work_struct *work)
  336. {
  337. struct arcnet_local *lp;
  338. struct net_device *dev;
  339. lp = container_of(work, struct arcnet_local, reset_work);
  340. dev = lp->dev;
  341. /* Do not bring the network interface back up if an ifdown
  342. * was already done.
  343. */
  344. if (!netif_running(dev) || !lp->reset_in_progress)
  345. return;
  346. rtnl_lock();
  347. /* Do another check, in case of an ifdown that was triggered in
  348. * the small race window between the exit condition above and
  349. * acquiring RTNL.
  350. */
  351. if (!netif_running(dev) || !lp->reset_in_progress)
  352. goto out;
  353. dev_close(dev);
  354. dev_open(dev, NULL);
  355. out:
  356. rtnl_unlock();
  357. }
  358. static void arcnet_reply_tasklet(struct tasklet_struct *t)
  359. {
  360. struct arcnet_local *lp = from_tasklet(lp, t, reply_tasklet);
  361. struct sk_buff *ackskb, *skb;
  362. struct sock_exterr_skb *serr;
  363. struct sock *sk;
  364. int ret;
  365. local_irq_disable();
  366. skb = lp->outgoing.skb;
  367. if (!skb || !skb->sk) {
  368. local_irq_enable();
  369. return;
  370. }
  371. sock_hold(skb->sk);
  372. sk = skb->sk;
  373. ackskb = skb_clone_sk(skb);
  374. sock_put(skb->sk);
  375. if (!ackskb) {
  376. local_irq_enable();
  377. return;
  378. }
  379. serr = SKB_EXT_ERR(ackskb);
  380. memset(serr, 0, sizeof(*serr));
  381. serr->ee.ee_errno = ENOMSG;
  382. serr->ee.ee_origin = SO_EE_ORIGIN_TXSTATUS;
  383. serr->ee.ee_data = skb_shinfo(skb)->tskey;
  384. serr->ee.ee_info = lp->reply_status;
  385. /* finally erasing outgoing skb */
  386. dev_kfree_skb(lp->outgoing.skb);
  387. lp->outgoing.skb = NULL;
  388. ackskb->dev = lp->dev;
  389. ret = sock_queue_err_skb(sk, ackskb);
  390. if (ret)
  391. dev_kfree_skb_irq(ackskb);
  392. local_irq_enable();
  393. };
  394. struct net_device *alloc_arcdev(const char *name)
  395. {
  396. struct net_device *dev;
  397. dev = alloc_netdev(sizeof(struct arcnet_local),
  398. name && *name ? name : "arc%d", NET_NAME_UNKNOWN,
  399. arcdev_setup);
  400. if (dev) {
  401. struct arcnet_local *lp = netdev_priv(dev);
  402. lp->dev = dev;
  403. spin_lock_init(&lp->lock);
  404. timer_setup(&lp->timer, arcnet_timer, 0);
  405. INIT_WORK(&lp->reset_work, reset_device_work);
  406. }
  407. return dev;
  408. }
  409. EXPORT_SYMBOL(alloc_arcdev);
  410. void free_arcdev(struct net_device *dev)
  411. {
  412. struct arcnet_local *lp = netdev_priv(dev);
  413. /* Do not cancel this at ->ndo_close(), as the workqueue itself
  414. * indirectly calls the ifdown path through dev_close().
  415. */
  416. cancel_work_sync(&lp->reset_work);
  417. free_netdev(dev);
  418. }
  419. EXPORT_SYMBOL(free_arcdev);
  420. /* Open/initialize the board. This is called sometime after booting when
  421. * the 'ifconfig' program is run.
  422. *
  423. * This routine should set everything up anew at each open, even registers
  424. * that "should" only need to be set once at boot, so that there is
  425. * non-reboot way to recover if something goes wrong.
  426. */
  427. int arcnet_open(struct net_device *dev)
  428. {
  429. struct arcnet_local *lp = netdev_priv(dev);
  430. int count, newmtu, error;
  431. arc_printk(D_INIT, dev, "opened.");
  432. if (!try_module_get(lp->hw.owner))
  433. return -ENODEV;
  434. if (BUGLVL(D_PROTO)) {
  435. arc_printk(D_PROTO, dev, "protocol map (default is '%c'): ",
  436. arc_proto_default->suffix);
  437. for (count = 0; count < 256; count++)
  438. arc_cont(D_PROTO, "%c", arc_proto_map[count]->suffix);
  439. arc_cont(D_PROTO, "\n");
  440. }
  441. tasklet_setup(&lp->reply_tasklet, arcnet_reply_tasklet);
  442. arc_printk(D_INIT, dev, "arcnet_open: resetting card.\n");
  443. /* try to put the card in a defined state - if it fails the first
  444. * time, actually reset it.
  445. */
  446. error = -ENODEV;
  447. if (lp->hw.reset(dev, 0) && lp->hw.reset(dev, 1))
  448. goto out_module_put;
  449. newmtu = choose_mtu();
  450. if (newmtu < dev->mtu)
  451. dev->mtu = newmtu;
  452. arc_printk(D_INIT, dev, "arcnet_open: mtu: %d.\n", dev->mtu);
  453. /* autodetect the encapsulation for each host. */
  454. memset(lp->default_proto, 0, sizeof(lp->default_proto));
  455. /* the broadcast address is special - use the 'bcast' protocol */
  456. for (count = 0; count < 256; count++) {
  457. if (arc_proto_map[count] == arc_bcast_proto) {
  458. lp->default_proto[0] = count;
  459. break;
  460. }
  461. }
  462. /* initialize buffers */
  463. atomic_set(&lp->buf_lock, 1);
  464. lp->next_buf = lp->first_free_buf = 0;
  465. release_arcbuf(dev, 0);
  466. release_arcbuf(dev, 1);
  467. release_arcbuf(dev, 2);
  468. release_arcbuf(dev, 3);
  469. lp->cur_tx = lp->next_tx = -1;
  470. lp->cur_rx = -1;
  471. lp->rfc1201.sequence = 1;
  472. /* bring up the hardware driver */
  473. if (lp->hw.open)
  474. lp->hw.open(dev);
  475. if (dev->dev_addr[0] == 0)
  476. arc_printk(D_NORMAL, dev, "WARNING! Station address 00 is reserved for broadcasts!\n");
  477. else if (dev->dev_addr[0] == 255)
  478. arc_printk(D_NORMAL, dev, "WARNING! Station address FF may confuse DOS networking programs!\n");
  479. arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__);
  480. if (lp->hw.status(dev) & RESETflag) {
  481. arc_printk(D_DEBUG, dev, "%s: %d: %s\n",
  482. __FILE__, __LINE__, __func__);
  483. lp->hw.command(dev, CFLAGScmd | RESETclear);
  484. }
  485. arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__);
  486. /* make sure we're ready to receive IRQ's. */
  487. lp->hw.intmask(dev, 0);
  488. udelay(1); /* give it time to set the mask before
  489. * we reset it again. (may not even be
  490. * necessary)
  491. */
  492. arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__);
  493. lp->intmask = NORXflag | RECONflag;
  494. lp->hw.intmask(dev, lp->intmask);
  495. arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__);
  496. netif_carrier_off(dev);
  497. netif_start_queue(dev);
  498. mod_timer(&lp->timer, jiffies + msecs_to_jiffies(1000));
  499. arcnet_led_event(dev, ARCNET_LED_EVENT_OPEN);
  500. return 0;
  501. out_module_put:
  502. module_put(lp->hw.owner);
  503. return error;
  504. }
  505. EXPORT_SYMBOL(arcnet_open);
  506. /* The inverse routine to arcnet_open - shuts down the card. */
  507. int arcnet_close(struct net_device *dev)
  508. {
  509. struct arcnet_local *lp = netdev_priv(dev);
  510. arcnet_led_event(dev, ARCNET_LED_EVENT_STOP);
  511. del_timer_sync(&lp->timer);
  512. netif_stop_queue(dev);
  513. netif_carrier_off(dev);
  514. tasklet_kill(&lp->reply_tasklet);
  515. /* flush TX and disable RX */
  516. lp->hw.intmask(dev, 0);
  517. lp->hw.command(dev, NOTXcmd); /* stop transmit */
  518. lp->hw.command(dev, NORXcmd); /* disable receive */
  519. mdelay(1);
  520. /* shut down the card */
  521. lp->hw.close(dev);
  522. /* reset counters */
  523. lp->reset_in_progress = 0;
  524. module_put(lp->hw.owner);
  525. return 0;
  526. }
  527. EXPORT_SYMBOL(arcnet_close);
  528. static int arcnet_header(struct sk_buff *skb, struct net_device *dev,
  529. unsigned short type, const void *daddr,
  530. const void *saddr, unsigned len)
  531. {
  532. const struct arcnet_local *lp = netdev_priv(dev);
  533. uint8_t _daddr, proto_num;
  534. struct ArcProto *proto;
  535. arc_printk(D_DURING, dev,
  536. "create header from %d to %d; protocol %d (%Xh); size %u.\n",
  537. saddr ? *(uint8_t *)saddr : -1,
  538. daddr ? *(uint8_t *)daddr : -1,
  539. type, type, len);
  540. if (skb->len != 0 && len != skb->len)
  541. arc_printk(D_NORMAL, dev, "arcnet_header: Yikes! skb->len(%d) != len(%d)!\n",
  542. skb->len, len);
  543. /* Type is host order - ? */
  544. if (type == ETH_P_ARCNET) {
  545. proto = arc_raw_proto;
  546. arc_printk(D_DEBUG, dev, "arc_raw_proto used. proto='%c'\n",
  547. proto->suffix);
  548. _daddr = daddr ? *(uint8_t *)daddr : 0;
  549. } else if (!daddr) {
  550. /* if the dest addr isn't provided, we can't choose an
  551. * encapsulation! Store the packet type (eg. ETH_P_IP)
  552. * for now, and we'll push on a real header when we do
  553. * rebuild_header.
  554. */
  555. *(uint16_t *)skb_push(skb, 2) = type;
  556. /* XXX: Why not use skb->mac_len? */
  557. if (skb->network_header - skb->mac_header != 2)
  558. arc_printk(D_NORMAL, dev, "arcnet_header: Yikes! diff (%u) is not 2!\n",
  559. skb->network_header - skb->mac_header);
  560. return -2; /* return error -- can't transmit yet! */
  561. } else {
  562. /* otherwise, we can just add the header as usual. */
  563. _daddr = *(uint8_t *)daddr;
  564. proto_num = lp->default_proto[_daddr];
  565. proto = arc_proto_map[proto_num];
  566. arc_printk(D_DURING, dev, "building header for %02Xh using protocol '%c'\n",
  567. proto_num, proto->suffix);
  568. if (proto == &arc_proto_null && arc_bcast_proto != proto) {
  569. arc_printk(D_DURING, dev, "actually, let's use '%c' instead.\n",
  570. arc_bcast_proto->suffix);
  571. proto = arc_bcast_proto;
  572. }
  573. }
  574. return proto->build_header(skb, dev, type, _daddr);
  575. }
  576. /* Called by the kernel in order to transmit a packet. */
  577. netdev_tx_t arcnet_send_packet(struct sk_buff *skb,
  578. struct net_device *dev)
  579. {
  580. struct arcnet_local *lp = netdev_priv(dev);
  581. struct archdr *pkt;
  582. struct arc_rfc1201 *soft;
  583. struct ArcProto *proto;
  584. int txbuf;
  585. unsigned long flags;
  586. int retval;
  587. arc_printk(D_DURING, dev,
  588. "transmit requested (status=%Xh, txbufs=%d/%d, len=%d, protocol %x)\n",
  589. lp->hw.status(dev), lp->cur_tx, lp->next_tx, skb->len, skb->protocol);
  590. pkt = (struct archdr *)skb->data;
  591. soft = &pkt->soft.rfc1201;
  592. proto = arc_proto_map[soft->proto];
  593. arc_printk(D_SKB_SIZE, dev, "skb: transmitting %d bytes to %02X\n",
  594. skb->len, pkt->hard.dest);
  595. if (BUGLVL(D_SKB))
  596. arcnet_dump_skb(dev, skb, "tx");
  597. /* fits in one packet? */
  598. if (skb->len - ARC_HDR_SIZE > XMTU && !proto->continue_tx) {
  599. arc_printk(D_NORMAL, dev, "fixme: packet too large: compensating badly!\n");
  600. dev_kfree_skb(skb);
  601. return NETDEV_TX_OK; /* don't try again */
  602. }
  603. /* We're busy transmitting a packet... */
  604. netif_stop_queue(dev);
  605. spin_lock_irqsave(&lp->lock, flags);
  606. lp->hw.intmask(dev, 0);
  607. if (lp->next_tx == -1)
  608. txbuf = get_arcbuf(dev);
  609. else
  610. txbuf = -1;
  611. if (txbuf != -1) {
  612. lp->outgoing.skb = skb;
  613. if (proto->prepare_tx(dev, pkt, skb->len, txbuf) &&
  614. !proto->ack_tx) {
  615. /* done right away and we don't want to acknowledge
  616. * the package later - forget about it now
  617. */
  618. dev->stats.tx_bytes += skb->len;
  619. } else {
  620. /* do it the 'split' way */
  621. lp->outgoing.proto = proto;
  622. lp->outgoing.skb = skb;
  623. lp->outgoing.pkt = pkt;
  624. if (proto->continue_tx &&
  625. proto->continue_tx(dev, txbuf)) {
  626. arc_printk(D_NORMAL, dev,
  627. "bug! continue_tx finished the first time! (proto='%c')\n",
  628. proto->suffix);
  629. }
  630. }
  631. retval = NETDEV_TX_OK;
  632. lp->next_tx = txbuf;
  633. } else {
  634. retval = NETDEV_TX_BUSY;
  635. }
  636. arc_printk(D_DEBUG, dev, "%s: %d: %s, status: %x\n",
  637. __FILE__, __LINE__, __func__, lp->hw.status(dev));
  638. /* make sure we didn't ignore a TX IRQ while we were in here */
  639. lp->hw.intmask(dev, 0);
  640. arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__);
  641. lp->intmask |= TXFREEflag | EXCNAKflag;
  642. lp->hw.intmask(dev, lp->intmask);
  643. arc_printk(D_DEBUG, dev, "%s: %d: %s, status: %x\n",
  644. __FILE__, __LINE__, __func__, lp->hw.status(dev));
  645. arcnet_led_event(dev, ARCNET_LED_EVENT_TX);
  646. spin_unlock_irqrestore(&lp->lock, flags);
  647. return retval; /* no need to try again */
  648. }
  649. EXPORT_SYMBOL(arcnet_send_packet);
  650. /* Actually start transmitting a packet that was loaded into a buffer
  651. * by prepare_tx. This should _only_ be called by the interrupt handler.
  652. */
  653. static int go_tx(struct net_device *dev)
  654. {
  655. struct arcnet_local *lp = netdev_priv(dev);
  656. arc_printk(D_DURING, dev, "go_tx: status=%Xh, intmask=%Xh, next_tx=%d, cur_tx=%d\n",
  657. lp->hw.status(dev), lp->intmask, lp->next_tx, lp->cur_tx);
  658. if (lp->cur_tx != -1 || lp->next_tx == -1)
  659. return 0;
  660. if (BUGLVL(D_TX))
  661. arcnet_dump_packet(dev, lp->next_tx, "go_tx", 0);
  662. lp->cur_tx = lp->next_tx;
  663. lp->next_tx = -1;
  664. /* start sending */
  665. lp->hw.command(dev, TXcmd | (lp->cur_tx << 3));
  666. dev->stats.tx_packets++;
  667. lp->lasttrans_dest = lp->lastload_dest;
  668. lp->lastload_dest = 0;
  669. lp->excnak_pending = 0;
  670. lp->intmask |= TXFREEflag | EXCNAKflag;
  671. return 1;
  672. }
  673. /* Called by the kernel when transmit times out */
  674. void arcnet_timeout(struct net_device *dev, unsigned int txqueue)
  675. {
  676. unsigned long flags;
  677. struct arcnet_local *lp = netdev_priv(dev);
  678. int status = lp->hw.status(dev);
  679. char *msg;
  680. spin_lock_irqsave(&lp->lock, flags);
  681. if (status & TXFREEflag) { /* transmit _DID_ finish */
  682. msg = " - missed IRQ?";
  683. } else {
  684. msg = "";
  685. dev->stats.tx_aborted_errors++;
  686. lp->timed_out = 1;
  687. lp->hw.command(dev, NOTXcmd | (lp->cur_tx << 3));
  688. }
  689. dev->stats.tx_errors++;
  690. /* make sure we didn't miss a TX or a EXC NAK IRQ */
  691. lp->hw.intmask(dev, 0);
  692. lp->intmask |= TXFREEflag | EXCNAKflag;
  693. lp->hw.intmask(dev, lp->intmask);
  694. spin_unlock_irqrestore(&lp->lock, flags);
  695. if (time_after(jiffies, lp->last_timeout + 10 * HZ)) {
  696. arc_printk(D_EXTRA, dev, "tx timed out%s (status=%Xh, intmask=%Xh, dest=%02Xh)\n",
  697. msg, status, lp->intmask, lp->lasttrans_dest);
  698. lp->last_timeout = jiffies;
  699. }
  700. if (lp->cur_tx == -1)
  701. netif_wake_queue(dev);
  702. }
  703. EXPORT_SYMBOL(arcnet_timeout);
  704. /* The typical workload of the driver: Handle the network interface
  705. * interrupts. Establish which device needs attention, and call the correct
  706. * chipset interrupt handler.
  707. */
  708. irqreturn_t arcnet_interrupt(int irq, void *dev_id)
  709. {
  710. struct net_device *dev = dev_id;
  711. struct arcnet_local *lp;
  712. int recbuf, status, diagstatus, didsomething, boguscount;
  713. unsigned long flags;
  714. int retval = IRQ_NONE;
  715. arc_printk(D_DURING, dev, "\n");
  716. arc_printk(D_DURING, dev, "in arcnet_interrupt\n");
  717. lp = netdev_priv(dev);
  718. BUG_ON(!lp);
  719. spin_lock_irqsave(&lp->lock, flags);
  720. if (lp->reset_in_progress)
  721. goto out;
  722. /* RESET flag was enabled - if device is not running, we must
  723. * clear it right away (but nothing else).
  724. */
  725. if (!netif_running(dev)) {
  726. if (lp->hw.status(dev) & RESETflag)
  727. lp->hw.command(dev, CFLAGScmd | RESETclear);
  728. lp->hw.intmask(dev, 0);
  729. spin_unlock_irqrestore(&lp->lock, flags);
  730. return retval;
  731. }
  732. arc_printk(D_DURING, dev, "in arcnet_inthandler (status=%Xh, intmask=%Xh)\n",
  733. lp->hw.status(dev), lp->intmask);
  734. boguscount = 5;
  735. do {
  736. status = lp->hw.status(dev);
  737. diagstatus = (status >> 8) & 0xFF;
  738. arc_printk(D_DEBUG, dev, "%s: %d: %s: status=%x\n",
  739. __FILE__, __LINE__, __func__, status);
  740. didsomething = 0;
  741. /* RESET flag was enabled - card is resetting and if RX is
  742. * disabled, it's NOT because we just got a packet.
  743. *
  744. * The card is in an undefined state.
  745. * Clear it out and start over.
  746. */
  747. if (status & RESETflag) {
  748. arc_printk(D_NORMAL, dev, "spurious reset (status=%Xh)\n",
  749. status);
  750. lp->reset_in_progress = 1;
  751. netif_stop_queue(dev);
  752. netif_carrier_off(dev);
  753. schedule_work(&lp->reset_work);
  754. /* get out of the interrupt handler! */
  755. goto out;
  756. }
  757. /* RX is inhibited - we must have received something.
  758. * Prepare to receive into the next buffer.
  759. *
  760. * We don't actually copy the received packet from the card
  761. * until after the transmit handler runs (and possibly
  762. * launches the next tx); this should improve latency slightly
  763. * if we get both types of interrupts at once.
  764. */
  765. recbuf = -1;
  766. if (status & lp->intmask & NORXflag) {
  767. recbuf = lp->cur_rx;
  768. arc_printk(D_DURING, dev, "Buffer #%d: receive irq (status=%Xh)\n",
  769. recbuf, status);
  770. lp->cur_rx = get_arcbuf(dev);
  771. if (lp->cur_rx != -1) {
  772. arc_printk(D_DURING, dev, "enabling receive to buffer #%d\n",
  773. lp->cur_rx);
  774. lp->hw.command(dev, RXcmd | (lp->cur_rx << 3) | RXbcasts);
  775. }
  776. didsomething++;
  777. }
  778. if ((diagstatus & EXCNAKflag)) {
  779. arc_printk(D_DURING, dev, "EXCNAK IRQ (diagstat=%Xh)\n",
  780. diagstatus);
  781. lp->hw.command(dev, NOTXcmd); /* disable transmit */
  782. lp->excnak_pending = 1;
  783. lp->hw.command(dev, EXCNAKclear);
  784. lp->intmask &= ~(EXCNAKflag);
  785. didsomething++;
  786. }
  787. /* a transmit finished, and we're interested in it. */
  788. if ((status & lp->intmask & TXFREEflag) || lp->timed_out) {
  789. int ackstatus;
  790. lp->intmask &= ~(TXFREEflag | EXCNAKflag);
  791. if (status & TXACKflag)
  792. ackstatus = 2;
  793. else if (lp->excnak_pending)
  794. ackstatus = 1;
  795. else
  796. ackstatus = 0;
  797. arc_printk(D_DURING, dev, "TX IRQ (stat=%Xh)\n",
  798. status);
  799. if (lp->cur_tx != -1 && !lp->timed_out) {
  800. if (!(status & TXACKflag)) {
  801. if (lp->lasttrans_dest != 0) {
  802. arc_printk(D_EXTRA, dev,
  803. "transmit was not acknowledged! (status=%Xh, dest=%02Xh)\n",
  804. status,
  805. lp->lasttrans_dest);
  806. dev->stats.tx_errors++;
  807. dev->stats.tx_carrier_errors++;
  808. } else {
  809. arc_printk(D_DURING, dev,
  810. "broadcast was not acknowledged; that's normal (status=%Xh, dest=%02Xh)\n",
  811. status,
  812. lp->lasttrans_dest);
  813. }
  814. }
  815. if (lp->outgoing.proto &&
  816. lp->outgoing.proto->ack_tx) {
  817. lp->outgoing.proto
  818. ->ack_tx(dev, ackstatus);
  819. }
  820. lp->reply_status = ackstatus;
  821. tasklet_hi_schedule(&lp->reply_tasklet);
  822. }
  823. if (lp->cur_tx != -1)
  824. release_arcbuf(dev, lp->cur_tx);
  825. lp->cur_tx = -1;
  826. lp->timed_out = 0;
  827. didsomething++;
  828. /* send another packet if there is one */
  829. go_tx(dev);
  830. /* continue a split packet, if any */
  831. if (lp->outgoing.proto &&
  832. lp->outgoing.proto->continue_tx) {
  833. int txbuf = get_arcbuf(dev);
  834. if (txbuf != -1) {
  835. if (lp->outgoing.proto->continue_tx(dev, txbuf)) {
  836. /* that was the last segment */
  837. dev->stats.tx_bytes += lp->outgoing.skb->len;
  838. if (!lp->outgoing.proto->ack_tx) {
  839. dev_kfree_skb_irq(lp->outgoing.skb);
  840. lp->outgoing.proto = NULL;
  841. }
  842. }
  843. lp->next_tx = txbuf;
  844. }
  845. }
  846. /* inform upper layers of idleness, if necessary */
  847. if (lp->cur_tx == -1)
  848. netif_wake_queue(dev);
  849. }
  850. /* now process the received packet, if any */
  851. if (recbuf != -1) {
  852. if (BUGLVL(D_RX))
  853. arcnet_dump_packet(dev, recbuf, "rx irq", 0);
  854. arcnet_rx(dev, recbuf);
  855. release_arcbuf(dev, recbuf);
  856. didsomething++;
  857. }
  858. if (status & lp->intmask & RECONflag) {
  859. lp->hw.command(dev, CFLAGScmd | CONFIGclear);
  860. dev->stats.tx_carrier_errors++;
  861. arc_printk(D_RECON, dev, "Network reconfiguration detected (status=%Xh)\n",
  862. status);
  863. if (netif_carrier_ok(dev)) {
  864. netif_carrier_off(dev);
  865. netdev_info(dev, "link down\n");
  866. }
  867. mod_timer(&lp->timer, jiffies + msecs_to_jiffies(1000));
  868. arcnet_led_event(dev, ARCNET_LED_EVENT_RECON);
  869. /* MYRECON bit is at bit 7 of diagstatus */
  870. if (diagstatus & 0x80)
  871. arc_printk(D_RECON, dev, "Put out that recon myself\n");
  872. /* is the RECON info empty or old? */
  873. if (!lp->first_recon || !lp->last_recon ||
  874. time_after(jiffies, lp->last_recon + HZ * 10)) {
  875. if (lp->network_down)
  876. arc_printk(D_NORMAL, dev, "reconfiguration detected: cabling restored?\n");
  877. lp->first_recon = lp->last_recon = jiffies;
  878. lp->num_recons = lp->network_down = 0;
  879. arc_printk(D_DURING, dev, "recon: clearing counters.\n");
  880. } else { /* add to current RECON counter */
  881. lp->last_recon = jiffies;
  882. lp->num_recons++;
  883. arc_printk(D_DURING, dev, "recon: counter=%d, time=%lds, net=%d\n",
  884. lp->num_recons,
  885. (lp->last_recon - lp->first_recon) / HZ,
  886. lp->network_down);
  887. /* if network is marked up;
  888. * and first_recon and last_recon are 60+ apart;
  889. * and the average no. of recons counted is
  890. * > RECON_THRESHOLD/min;
  891. * then print a warning message.
  892. */
  893. if (!lp->network_down &&
  894. (lp->last_recon - lp->first_recon) <= HZ * 60 &&
  895. lp->num_recons >= RECON_THRESHOLD) {
  896. lp->network_down = 1;
  897. arc_printk(D_NORMAL, dev, "many reconfigurations detected: cabling problem?\n");
  898. } else if (!lp->network_down &&
  899. lp->last_recon - lp->first_recon > HZ * 60) {
  900. /* reset counters if we've gone for
  901. * over a minute.
  902. */
  903. lp->first_recon = lp->last_recon;
  904. lp->num_recons = 1;
  905. }
  906. }
  907. } else if (lp->network_down &&
  908. time_after(jiffies, lp->last_recon + HZ * 10)) {
  909. if (lp->network_down)
  910. arc_printk(D_NORMAL, dev, "cabling restored?\n");
  911. lp->first_recon = lp->last_recon = 0;
  912. lp->num_recons = lp->network_down = 0;
  913. arc_printk(D_DURING, dev, "not recon: clearing counters anyway.\n");
  914. netif_carrier_on(dev);
  915. }
  916. if (didsomething)
  917. retval |= IRQ_HANDLED;
  918. } while (--boguscount && didsomething);
  919. arc_printk(D_DURING, dev, "arcnet_interrupt complete (status=%Xh, count=%d)\n",
  920. lp->hw.status(dev), boguscount);
  921. arc_printk(D_DURING, dev, "\n");
  922. lp->hw.intmask(dev, 0);
  923. udelay(1);
  924. lp->hw.intmask(dev, lp->intmask);
  925. out:
  926. spin_unlock_irqrestore(&lp->lock, flags);
  927. return retval;
  928. }
  929. EXPORT_SYMBOL(arcnet_interrupt);
  930. /* This is a generic packet receiver that calls arcnet??_rx depending on the
  931. * protocol ID found.
  932. */
  933. static void arcnet_rx(struct net_device *dev, int bufnum)
  934. {
  935. struct arcnet_local *lp = netdev_priv(dev);
  936. union {
  937. struct archdr pkt;
  938. char buf[512];
  939. } rxdata;
  940. struct arc_rfc1201 *soft;
  941. int length, ofs;
  942. soft = &rxdata.pkt.soft.rfc1201;
  943. lp->hw.copy_from_card(dev, bufnum, 0, &rxdata.pkt, ARC_HDR_SIZE);
  944. if (rxdata.pkt.hard.offset[0]) {
  945. ofs = rxdata.pkt.hard.offset[0];
  946. length = 256 - ofs;
  947. } else {
  948. ofs = rxdata.pkt.hard.offset[1];
  949. length = 512 - ofs;
  950. }
  951. /* get the full header, if possible */
  952. if (sizeof(rxdata.pkt.soft) <= length) {
  953. lp->hw.copy_from_card(dev, bufnum, ofs, soft, sizeof(rxdata.pkt.soft));
  954. } else {
  955. memset(&rxdata.pkt.soft, 0, sizeof(rxdata.pkt.soft));
  956. lp->hw.copy_from_card(dev, bufnum, ofs, soft, length);
  957. }
  958. arc_printk(D_DURING, dev, "Buffer #%d: received packet from %02Xh to %02Xh (%d+4 bytes)\n",
  959. bufnum, rxdata.pkt.hard.source, rxdata.pkt.hard.dest, length);
  960. dev->stats.rx_packets++;
  961. dev->stats.rx_bytes += length + ARC_HDR_SIZE;
  962. /* call the right receiver for the protocol */
  963. if (arc_proto_map[soft->proto]->is_ip) {
  964. if (BUGLVL(D_PROTO)) {
  965. struct ArcProto
  966. *oldp = arc_proto_map[lp->default_proto[rxdata.pkt.hard.source]],
  967. *newp = arc_proto_map[soft->proto];
  968. if (oldp != newp) {
  969. arc_printk(D_PROTO, dev,
  970. "got protocol %02Xh; encap for host %02Xh is now '%c' (was '%c')\n",
  971. soft->proto, rxdata.pkt.hard.source,
  972. newp->suffix, oldp->suffix);
  973. }
  974. }
  975. /* broadcasts will always be done with the last-used encap. */
  976. lp->default_proto[0] = soft->proto;
  977. /* in striking contrast, the following isn't a hack. */
  978. lp->default_proto[rxdata.pkt.hard.source] = soft->proto;
  979. }
  980. /* call the protocol-specific receiver. */
  981. arc_proto_map[soft->proto]->rx(dev, bufnum, &rxdata.pkt, length);
  982. }
  983. static void null_rx(struct net_device *dev, int bufnum,
  984. struct archdr *pkthdr, int length)
  985. {
  986. arc_printk(D_PROTO, dev,
  987. "rx: don't know how to deal with proto %02Xh from host %02Xh.\n",
  988. pkthdr->soft.rfc1201.proto, pkthdr->hard.source);
  989. }
  990. static int null_build_header(struct sk_buff *skb, struct net_device *dev,
  991. unsigned short type, uint8_t daddr)
  992. {
  993. struct arcnet_local *lp = netdev_priv(dev);
  994. arc_printk(D_PROTO, dev,
  995. "tx: can't build header for encap %02Xh; load a protocol driver.\n",
  996. lp->default_proto[daddr]);
  997. /* always fails */
  998. return 0;
  999. }
  1000. /* the "do nothing" prepare_tx function warns that there's nothing to do. */
  1001. static int null_prepare_tx(struct net_device *dev, struct archdr *pkt,
  1002. int length, int bufnum)
  1003. {
  1004. struct arcnet_local *lp = netdev_priv(dev);
  1005. struct arc_hardware newpkt;
  1006. arc_printk(D_PROTO, dev, "tx: no encap for this host; load a protocol driver.\n");
  1007. /* send a packet to myself -- will never get received, of course */
  1008. newpkt.source = newpkt.dest = dev->dev_addr[0];
  1009. /* only one byte of actual data (and it's random) */
  1010. newpkt.offset[0] = 0xFF;
  1011. lp->hw.copy_to_card(dev, bufnum, 0, &newpkt, ARC_HDR_SIZE);
  1012. return 1; /* done */
  1013. }