arcnet.c 33 KB

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