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