1 /* arcnet.c
2 Written 1994-95 by Avery Pennarun, derived from skeleton.c by
3 Donald Becker.
4
5 Contact Avery at: apenwarr@foxnet.net or
6 RR #5 Pole Line Road, Thunder Bay, ON, Canada P7C 5M9
7
8 **********************
9
10 The original copyright was as follows:
11
12 skeleton.c Written 1993 by Donald Becker.
13 Copyright 1993 United States Government as represented by the
14 Director, National Security Agency. This software may only be used
15 and distributed according to the terms of the GNU Public License as
16 modified by SRC, incorporated herein by reference.
17
18 **********************
19
20 v1.92 ALPHA (95/07/11)
21 - Fixes to make things work with kernel 1.3.x. Completely broke
22 1.2.x support. Oops? 1.2.x users keep using 1.91 ALPHA until I
23 get out a version that supports both.
24
25 v1.91 ALPHA (95/07/02)
26 - Oops. Exception packets hit us again! I remembered to test
27 them in Windows-protocol mode, but due to the many various
28 changes they broke in RFC1201 instead. All fixed.
29 - A long-standing bug with "exception" packets not setting
30 protocol_id properly has been corrected. This would have caused
31 random problems talking to non-Linux servers. I've also sent in
32 a patch to fix this in the latest stable ARCnet (now 1.02).
33 - ARC_P_IPX is an RFC1201 protocol too. Thanks, Tomasz.
34 - We're now "properly" (I think) handling the multiple 'tbusy' and
35 'start' flags (one for each protocol device) better.
36 - The driver should now start without a NULL-pointer dereference
37 if you aren't connected to the network.
38
39 v1.90 ALPHA (95/06/18)
40 - Removal of some outdated and messy config options (no one has
41 ever complained about the defaults since they were introduced):
42 DANGER_PROBE, EXTRA_DELAYS, IRQ_XMIT, CAREFUL_XMIT,
43 STRICT_MEM_DETECT, LIMIT_MTU, USE_TIMER_HANDLER. Also took out
44 a few "#if 0" sections which are no longer useful.
45 - Cleaned up debug levels - now instead of levels, there are
46 individual flags. Watch out when changing with ifconfig.
47 - More cleanups and beautification. Removed more dead code and
48 made sure every function was commented.
49 - Fixed the DETECT_RECONFIGS option so that it actually _won't_
50 detect reconfigs. Previously, the RECON irq would be disabled
51 but the recon messages would still be logged on the next normal
52 IRQ.
53 - Initial support for "multiprotocol" ARCnet (this involved a LOT
54 of reorganizing!). Added an arc0w device, which allows us to
55 talk to "Windows" ARCnet TCP/IP protocol. To use it, ifconfig
56 arc0 and arc0w (in that order). For now, Windows-protocol
57 hosts should have routes through arc0w - eventually I hope to
58 make things more automatic.
59 v1.11 ALPHA (95/06/07)
60 - Tomasz saves the day again with patches to fix operation if the
61 new VERIFY_ACK option is disabled.
62 - LOTS of little code cleanups/improvements by Tomasz.
63 - Changed autoprobe, since the "never-changing command port"
64 probe was causing problems for some people. I also reset the
65 card fewer times during the probe if DANGER_PROBE is defined,
66 since DANGER_PROBE seems to be a more reliable method anyway.
67 - It looks like the null-pointer problem was finally REALLY fixed
68 by some change from Linux 1.2.8 to 1.2.9. How handy!
69 v1.10 ALPHA (95/04/15)
70 - Fixed (?) some null-pointer dereference bugs
71 - Added better network error detection (from Tomasz) - in
72 particular, we now notice when our network isn't connected,
73 also known as a "network reconfiguration."
74 - We now increment lp->stats.tx_dropped in several more places,
75 on a suggestion from Tomasz.
76 - Minor cleanups/spelling fixes.
77 - We now monitor the TXACK bit in the status register: we don't do
78 anything with it yet, just notice when a transmitted packet isn't
79 acknowledged.
80 - Minor fix with sequence numbers (sometimes they were being sent in
81 the wrong order due to Linux's packet queuing).
82 v1.01 (95/03/24)
83 - Fixed some IPX-related bugs. (Thanks to Tomasz Motylewski
84 <motyl@tichy.ch.uj.edu.pl> for the patches to make arcnet work
85 with dosemu!)
86 v1.00 (95/02/15)
87 - Initial non-alpha release.
88
89
90 TO DO:
91
92 - Test in systems with NON-ARCnet network cards, just to see if
93 autoprobe kills anything. Currently, we do cause some NE2000's to
94 die.
95 - What about cards with shared memory that can be "turned off?"
96 - NFS mount freezes after several megabytes to SOSS for DOS.
97 unmount/remount fixes it. Is this arcnet-specific? I don't know.
98 - Add support for "old" (RFC1051) protocol arcnet, such as AmiTCP
99 and NetBSD. Work in Tomasz' initial support for this.
100 - How about TCP/IP over netbios?
101 - Some newer ARCnets support promiscuous mode, supposedly.
102 If someone sends me information, I'll try to implement it.
103 - Remove excess lock variables that are probably not necessary
104 anymore due to the changes in Linux 1.2.9.
105
106
107 Sources:
108 - Crynwr arcnet.com/arcether.com packet drivers.
109 - arcnet.c v0.00 dated 1/1/94 and apparently by
110 Donald Becker - it didn't work :)
111 - skeleton.c v0.05 dated 11/16/93 by Donald Becker
112 (from Linux Kernel 1.1.45)
113 - The official ARCnet data sheets (!) thanks to Ken Cornetet
114 <kcornete@nyx10.cs.du.edu>
115 - RFC's 1201 and 1051 (mostly 1201) - re: ARCnet IP packets
116 - net/inet/eth.c (from kernel 1.1.50) for header-building info...
117 - Alternate Linux ARCnet source by V.Shergin <vsher@sao.stavropol.su>
118 - Textual information and more alternate source from Joachim Koenig
119 <jojo@repas.de>
120 */
121
122 static char *version =
123 "arcnet.c:v1.92 ALPHA 95/07/11 Avery Pennarun <apenwarr@foxnet.net>\n";
124
125 /**************************************************************************/
126
127 /* Define this if you want to detect network reconfigurations.
128 * They may be a real nuisance on a larger ARCnet network: but if you are
129 * a network administrator you probably would like to count them.
130 * Reconfigurations will be recorded in stats.tx_carrier_errors
131 * (the last field of the /proc/net/dev file).
132 *
133 * The card sends the reconfiguration signal when it loses the connection
134 * to the rest of its network. It is a 'Hello, is anybody there?' cry. This
135 * usually happens when a new computer on the network is powered on or when
136 * the cable is broken.
137 */
138 #define DETECT_RECONFIGS
139
140 /* Define this if you want to make sure transmitted packets are "acknowledged"
141 * by the destination host, as long as they're not to the broadcast address.
142 *
143 * That way, if one segment of a split packet doesn't get through, it can
144 * be resent immediately rather than confusing the other end.
145 *
146 * Disable this to return to 1.01-style behaviour, if you have problems.
147 */
148 #define VERIFY_ACK
149
150 /* Define this if you want to make it easier to use the "call trace" when
151 * a kernel NULL pointer assignment occurs.
152 */
153 #undef static
154
155 /**************************************************************************/
156
157
158 #include <linux/config.h>
159 #ifdef MODULE
160 #include <linux/module.h>
161 #include <linux/version.h>
162 #endif /* MODULE */
163
164 #include <linux/kernel.h>
165 #include <linux/sched.h>
166 #include <linux/types.h>
167 #include <linux/fcntl.h>
168 #include <linux/interrupt.h>
169 #include <linux/ptrace.h>
170 #include <linux/ioport.h>
171 #include <linux/in.h>
172 #include <linux/malloc.h>
173 #include <linux/string.h>
174 #include <linux/timer.h>
175 #include <linux/errno.h>
176 #include <linux/delay.h>
177
178 #include <asm/system.h>
179 #include <asm/bitops.h>
180 #include <asm/io.h>
181 #include <asm/dma.h>
182
183 #include <linux/netdevice.h>
184 #include <linux/etherdevice.h>
185 #include <linux/skbuff.h>
186
187 #include <net/arp.h>
188
189
190 /* new debugging bitflags: each option can be enabled individually.
191 *
192 * these can be set while the driver is running by typing:
193 * ifconfig arc0 down metric 1xxx HOSTNAME
194 * where 1xx is 1000 + the debug level you want
195 * and HOSTNAME is your hostname/ip address
196 * and then resetting your routes.
197 */
198 #define D_NORMAL 1 /* D_NORMAL startup announcement */
199 #define D_INIT 2 /* D_INIT show init/probe messages */
200 #define D_EXTRA 4 /* D_EXTRA extra information */
201 /* debug levels past this point give LOTS of output! */
202 #define D_DURING 8 /* D_DURING during normal use (irq's) */
203 #define D_TX 16 /* D_TX show tx packets */
204 #define D_RX 32 /* D_RX show rx packets */
205 #define D_SKB 64 /* D_SKB dump skb's */
206
207 #ifndef NET_DEBUG
208 #define NET_DEBUG D_NORMAL|D_INIT|D_EXTRA
209 #endif
210 int arcnet_debug = NET_DEBUG;
211
212 #ifndef HAVE_AUTOIRQ
213 /* From auto_irq.c, in ioport.h for later versions. */
214 extern void autoirq_setup(int waittime);
215 extern int autoirq_report(int waittime);
216 /* The map from IRQ number (as passed to the interrupt handler) to
217 'struct device'. */
218 extern struct device *irq2dev_map[16];
219 #endif
220
221 #ifndef HAVE_PORTRESERVE
222 #define check_region(ioaddr, size) 0
223 #define request_region(ioaddr, size) do ; while (0)
224 #endif
225
226 /* macro to simplify debug checking */
227 #define BUGLVL(x) if (arcnet_debug&(x))
228
229
230 /* Some useful multiprotocol macros */
231 #define TBUSY lp->adev->tbusy \
232 =lp->wdev->tbusy
233 #define IF_TBUSY (lp->adev->tbusy \
234 || lp->wdev->tbusy)
235 #define START lp->adev->start \
236 =lp->wdev->start
237
238
239 /* The number of low I/O ports used by the ethercard. */
240 #define ARCNET_TOTAL_SIZE 16
241
242
243 /* Handy defines for ARCnet specific stuff */
244 /* COM 9026 (?) --> ARCnet register addresses */
245 #define INTMASK (ioaddr+0) /* writable */
246 #define STATUS (ioaddr+0) /* readable */
247 #define COMMAND (ioaddr+1) /* writable, returns random vals on read (?) */
248 #define RESET (ioaddr+8) /* software reset writable */
249
250 /* Time needed for various things (in clock ticks, 1/100 sec) */
251 /* We mostly don't bother with these - watch out. */
252 #define RESETtime 40 /* reset */
253 #define XMITtime 10 /* send (?) */
254 #define ACKtime 10 /* acknowledge (?) */
255
256 /* these are the max/min lengths of packet data. (including
257 * ClientData header)
258 * note: packet sizes 250, 251, 252 are impossible (God knows why)
259 * so exception packets become necessary.
260 *
261 * These numbers are compared with the length of the full packet,
262 * including ClientData header.
263 */
264 #define MTU 253 /* normal packet max size */
265 #define MinTU 257 /* extended packet min size */
266 #define XMTU 508 /* extended packet max size */
267
268 /* status/interrupt mask bit fields */
269 #define TXFREEflag 0x01 /* transmitter available */
270 #define TXACKflag 0x02 /* transmitted msg. ackd */
271 #define RECONflag 0x04 /* system reconfigured */
272 #define TESTflag 0x08 /* test flag */
273 #define RESETflag 0x10 /* power-on-reset */
274 #define RES1flag 0x20 /* unused */
275 #define RES2flag 0x40 /* unused */
276 #define NORXflag 0x80 /* receiver inhibited */
277
278 #ifdef DETECT_RECONFIGS
279 #define RECON_flag RECONflag
280 #else
281 #define RECON_flag 0
282 #endif
283
284 /* in the command register, the following bits have these meanings:
285 * 0-2 command
286 * 3-4 page number (for enable rcv/xmt command)
287 * 7 receive broadcasts
288 */
289 #define NOTXcmd 0x01 /* disable transmitter */
290 #define NORXcmd 0x02 /* disable receiver */
291 #define TXcmd 0x03 /* enable transmitter */
292 #define RXcmd 0x04 /* enable receiver */
293 #define CONFIGcmd 0x05 /* define configuration */
294 #define CFLAGScmd 0x06 /* clear flags */
295 #define TESTcmd 0x07 /* load test flags */
296
297 /* flags for "clear flags" command */
298 #define RESETclear 0x08 /* power-on-reset */
299 #define CONFIGclear 0x10 /* system reconfigured */
300
301 /* flags for "load test flags" command */
302 #define TESTload 0x08 /* test flag (diagnostic) */
303
304 /* byte deposited into first address of buffers on reset */
305 #define TESTvalue 0321 /* that's octal for 0xD1 :) */
306
307 /* for "enable receiver" command */
308 #define RXbcasts 0x80 /* receive broadcasts */
309
310 /* flags for "define configuration" command */
311 #define NORMALconf 0x00 /* 1-249 byte packets */
312 #define EXTconf 0x08 /* 250-504 byte packets */
313
314 /* buffers (4 total) used for receive and xmit.
315 */
316 #define EnableReceiver() outb(RXcmd|(recbuf<<3)|RXbcasts,COMMAND)
317
318 /* RFC1201 Protocol ID's */
319 #define ARC_P_IP 212 /* 0xD4 */
320 #define ARC_P_ARP 213 /* 0xD5 */
321 #define ARC_P_RARP 214 /* 0xD6 */
322 #define ARC_P_IPX 250 /* 0xFA */
323
324 /* MS LanMan/WfWg protocol */
325 #define ARC_P_MS_TCPIP 0xE8
326
327 /* Unsupported/indirectly supported protocols */
328 #define ARC_P_LANSOFT 251 /* 0xFB */
329 #define ARC_P_ATALK 0xDD
330
331 /* these structures define the format of an arcnet packet. */
332 #define NORMAL 0
333 #define EXTENDED 1
334 #define EXCEPTION 2
335
336 /* the header required by the card itself */
337 struct HardHeader
338 {
339 u_char source, /* source ARCnet - filled in automagically */
340 destination, /* destination ARCnet - 0 for broadcast */
341 offset1, /* offset of ClientData (256-byte packets) */
342 offset2; /* offset of ClientData (512-byte packets) */
343 };
344
345 /* a complete ARCnet packet */
346 union ArcPacket
347 {
348 struct HardHeader hardheader; /* the hardware header */
349 u_char raw[512]; /* raw packet info, incl ClientData */
350 };
351
352 /* the "client data" header - RFC-1201 information
353 * notice that this screws up if it's not an even number of bytes
354 * <sigh>
355 */
356 struct ClientData
357 {
358 /* data that's NOT part of real packet - we MUST get rid of it before
359 * actually sending!!
360 */
361 u_char saddr, /* Source address - needed for IPX */
362 daddr; /* Destination address */
363
364 /* data that IS part of real packet */
365 u_char protocol_id, /* ARC_P_IP, ARC_P_ARP, etc */
366 split_flag; /* for use with split packets */
367 u_short sequence; /* sequence number */
368 };
369 #define EXTRA_CLIENTDATA (sizeof(struct ClientData)-4)
370
371
372 /* "Incoming" is information needed for each address that could be sending
373 * to us. Mostly for partially-received split packets.
374 */
375 struct Incoming
376 {
377 struct sk_buff *skb; /* packet data buffer */
378 unsigned char lastpacket, /* number of last packet (from 1) */
379 numpackets; /* number of packets in split */
380 u_short sequence; /* sequence number of assembly */
381 };
382
383 struct Outgoing
384 {
385 struct sk_buff *skb; /* buffer from upper levels */
386 struct ClientData *hdr; /* clientdata of last packet */
387 u_char *data; /* pointer to data in packet */
388 short length, /* bytes total */
389 dataleft, /* bytes left */
390 segnum, /* segment being sent */
391 numsegs, /* number of segments */
392 seglen; /* length of segment */
393 #ifdef VERIFY_ACK
394 short lastload_dest, /* can last loaded packet be acked? */
395 lasttrans_dest; /* can last TX'd packet be acked? */
396 #endif
397
398 };
399
400
401 /* Information that needs to be kept for each board. */
402 struct arcnet_local {
403 struct enet_statistics stats;
404 u_char arcnum; /* arcnet number - our 8-bit address */
405 u_short sequence; /* sequence number (incs with each packet) */
406 u_char recbuf, /* receive buffer # (0 or 1) */
407 txbuf, /* transmit buffer # (2 or 3) */
408 txready; /* buffer where a packet is ready to send */
409 short intx, /* in TX routine? */
410 in_txhandler, /* in TX_IRQ handler? */
411 sending; /* transmit in progress? */
412 short tx_left; /* segments of split packet left to TX */
413
414 struct timer_list timer; /* the timer interrupt struct */
415 struct Incoming incoming[256]; /* one from each address */
416 struct Outgoing outgoing; /* packet currently being sent */
417
418 struct device *adev; /* RFC1201 protocol device */
419 struct device *wdev; /* Windows protocol device */
420 };
421
422
423 /* Index to functions, as function prototypes. */
424 extern int arcnet_probe(struct device *dev);
425 #ifndef MODULE
426 static int arcnet_memprobe(struct device *dev,u_char *addr);
427 static int arcnet_ioprobe(struct device *dev, short ioaddr);
428 #endif
429 static int arcnetW_init(struct device *dev);
430
431 static int arcnet_open(struct device *dev);
432 static int arcnet_close(struct device *dev);
433 static int arcnet_reset(struct device *dev);
434
435 static int arcnetA_send_packet(struct sk_buff *skb, struct device *dev);
436 static void arcnetA_continue_tx(struct device *dev);
437 static void arcnetA_prepare_tx(struct device *dev,struct ClientData *hdr,
438 short length,char *data);
439 static void arcnetA_go_tx(struct device *dev);
440
441 static int arcnetW_send_packet(struct sk_buff *skb, struct device *dev);
442
443 static void arcnet_interrupt(int irq,struct pt_regs *regs);
444 static void arcnet_inthandler(struct device *dev);
445
446 static void arcnet_rx(struct device *dev,int recbuf);
447 static void arcnetA_rx(struct device *dev,struct ClientData *arcsoft,
448 int length,u_char saddr, u_char daddr);
449 static void arcnetW_rx(struct device *dev,u_char *arcsoft,
450 int length,u_char saddr, u_char daddr);
451
452 static struct enet_statistics *arcnet_get_stats(struct device *dev);
453 static void set_multicast_list(struct device *dev, int num_addrs, void *addrs);
454
455 /* annoying functions for header/arp/etc building */
456 int arcnetA_header(struct sk_buff *skb,struct device *dev,unsigned short type,
457 void *daddr,void *saddr,unsigned len);
458 int arcnetA_rebuild_header(void *eth,struct device *dev,unsigned long raddr,
459 struct sk_buff *skb);
460 unsigned short arcnetA_type_trans(struct sk_buff *skb,struct device *dev);
461
462 #ifdef MODULE
463 int init_module(void);
464 void cleanup_module(void);
465 #endif
466
467 #define tx_done(dev) 1
468
469 #define JIFFER(time) for (delayval=0; delayval<(time*10); delayval++) \
470 udelay(1000);
471
472
473 /****************************************************************************
474 * *
475 * Probe and initialization *
476 * *
477 ****************************************************************************/
478
479
480 /* Check for a network adaptor of this type, and return '0' if one exists.
481 * If dev->base_addr == 0, probe all likely locations.
482 * If dev->base_addr == 1, always return failure.
483 * If dev->base_addr == 2, allocate space for the device and return success
484 * (detachable devices only).
485 */
486 int
487 arcnet_probe(struct device *dev)
/* ![[previous]](../icons/n_left.png)
![[next]](../icons/right.png)
![[first]](../icons/n_first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
488 {
489 #ifndef MODULE
490 /* I refuse to probe anything less than 0x200, because anyone using
491 * an address like that should probably be shot.
492 */
493 int *port, ports[] = {/* first the suggested values! */
494 0x300,0x2E0,0x2F0,0x2D0,
495 /* ...now everything else possible. */
496 0x200,0x210,0x220,0x230,0x240,0x250,0x260,0x270,
497 0x280,0x290,0x2a0,0x2b0,0x2c0,
498 0x310,0x320,0x330,0x340,0x350,0x360,0x370,
499 0x380,0x390,0x3a0,/* video ports, */0x3e0,0x3f0,
500 /* a null ends the list */
501 0};
502 /* I'm not going to probe below 0xA0000 either, for similar reasons.
503 */
504 unsigned long *addr, addrs[] = {0xD0000,0xE0000,0xA0000,0xB0000,
505 0xC0000,0xF0000,
506 /* from <mdrejhon@magi.com> */
507 0xE1000,
508 0xDD000,0xDC000,
509 0xD9000,0xD8000,0xD5000,0xD4000,0xD1000,
510 0xCD000,0xCC000,
511 0xC9000,0xC8000,0xC5000,0xC4000,
512 /* terminator */
513 0};
514 int base_addr=dev->base_addr, status=0;
515 #endif /* MODULE */
516 int delayval;
517 struct arcnet_local *lp;
518
519 BUGLVL(D_NORMAL)
520 {
521 printk(version);
522 printk("arcnet: ***\n");
523 printk("arcnet: * Read linux/drivers/net/README.arcnet for important release notes!\n");
524 printk("arcnet: *\n");
525 printk("arcnet: * This is an ALPHA version! (Last stable release: v1.02) E-mail me if\n");
526 printk("arcnet: * you have any questions, comments, or bug reports.\n");
527 printk("arcnet: ***\n");
528 }
529
530 BUGLVL(D_INIT)
531 printk("arcnet: given: base %lXh, IRQ %Xh, shmem %lXh\n",
532 dev->base_addr,dev->irq,dev->mem_start);
533
534 #ifndef MODULE
535 if (base_addr > 0x1ff) /* Check a single specified location. */
536 status=arcnet_ioprobe(dev, base_addr);
537 else if (base_addr > 0) /* Don't probe at all. */
538 return ENXIO;
539 else for (port = &ports[0]; *port; port++)
540 {
541 int ioaddr = *port;
542 if (check_region(ioaddr, ARCNET_TOTAL_SIZE))
543 {
544 BUGLVL(D_INIT)
545 printk("arcnet: Skipping %Xh because of check_region...\n",
546 ioaddr);
547 continue;
548 }
549
550 status=arcnet_ioprobe(dev, ioaddr);
551 if (!status) break;
552 }
553
554 if (status) return status;
555
556 /* ioprobe turned out okay. Now give it a couple seconds to finish
557 * initializing...
558 */
559 BUGLVL(D_INIT)
560 printk("arcnet: ioprobe okay! Waiting for reset...\n");
561 JIFFER(100);
562
563 /* okay, now we have to find the shared memory area. */
564 BUGLVL(D_INIT)
565 printk("arcnet: starting memory probe, given %lXh\n",
566 dev->mem_start);
567 if (dev->mem_start) /* value given - probe just that one */
568 {
569 status=arcnet_memprobe(dev,(u_char *)dev->mem_start);
570 if (status) return status;
571 }
572 else /* no value given - probe everything */
573 {
574 for (addr = &addrs[0]; *addr; addr++) {
575 status=arcnet_memprobe(dev,(u_char *)(*addr));
576 if (!status) break;
577 }
578
579 if (status) return status;
580 }
581 #else /* MODULE */
582 if (!dev->base_addr || !dev->irq || !dev->mem_start
583 || !dev->rmem_start)
584 {
585 printk("arcnet: loadable modules can't autoprobe!\n");
586 printk("arcnet: try using io=, irqnum=, and shmem= on the insmod line.\n");
587 printk("arcnet: you may also need num= to change the device name. (ie. num=1 for arc1)\n");
588 return ENODEV;
589 }
590 #endif
591 /* now reserve the irq... */
592 {
593 int irqval = request_irq(dev->irq, &arcnet_interrupt, 0,
594 "arcnet");
595 if (irqval) {
596 printk("%s: unable to get IRQ %d (irqval=%d).\n",
597 dev->name,dev->irq, irqval);
598 return EAGAIN;
599 }
600 }
601
602 /* Grab the region so we can find another board if autoIRQ fails. */
603 request_region(dev->base_addr, ARCNET_TOTAL_SIZE,"arcnet");
604
605 printk("%s: ARCnet card found at %03lXh, IRQ %d, ShMem at %lXh.\n",
606 dev->name, dev->base_addr, dev->irq, dev->mem_start);
607
608 /* Initialize the device structure. */
609 dev->priv = kmalloc(sizeof(struct arcnet_local), GFP_KERNEL);
610 memset(dev->priv, 0, sizeof(struct arcnet_local));
611 lp=(struct arcnet_local *)(dev->priv);
612
613 dev->open=arcnet_open;
614 dev->stop=arcnet_close;
615 dev->hard_start_xmit=arcnetA_send_packet;
616 dev->get_stats=arcnet_get_stats;
617 #ifdef HAVE_MULTICAST
618 dev->set_multicast_list = &set_multicast_list;
619 #endif
620
621 /* Fill in the fields of the device structure with ethernet-generic
622 * values.
623 */
624 ether_setup(dev);
625
626 /* And now fill particular fields with arcnet values */
627 dev->type=ARPHRD_ARCNET;
628 dev->hard_header_len=sizeof(struct ClientData);
629 BUGLVL(D_DURING)
630 printk("arcnet: ClientData header size is %d.\narcnet: HardHeader size is %d.\n",
631 sizeof(struct ClientData),sizeof(struct HardHeader));
632
633 /* since we strip EXTRA_CLIENTDATA bytes off before sending,
634 * we let Linux add that many bytes to the packet data...
635 */
636 dev->addr_len=1;
637 dev->broadcast[0]=0x00;
638
639 BUGLVL(D_INIT) printk("arcnet: arcnet_probe: resetting card.\n");
640 arcnet_reset(dev);
641 JIFFER(50);
642 BUGLVL(D_NORMAL)
643 printk("arcnet: We appear to be station %d (%02Xh)\n",
644 lp->arcnum,lp->arcnum);
645 if (lp->arcnum==0)
646 printk("arcnet: WARNING! Station address 0 is reserved for broadcasts!\n");
647 if (lp->arcnum==255)
648 printk("arcnet: WARNING! Station address 255 may confuse DOS networking programs!\n");
649 dev->dev_addr[0]=lp->arcnum;
650 lp->sequence=1;
651 lp->recbuf=0;
652
653 dev->hard_header=arcnetA_header;
654 dev->rebuild_header=arcnetA_rebuild_header;
655
656 return 0;
657 }
658
659 #ifndef MODULE
660
661 int arcnet_ioprobe(struct device *dev, short ioaddr)
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
662 {
663 int delayval,airq;
664
665 BUGLVL(D_INIT)
666 {
667 printk("arcnet: probing address %Xh\n",ioaddr);
668 printk("arcnet: status1=%Xh\n",inb(STATUS));
669 }
670
671
672 /* very simple - all we have to do is reset the card, and if there's
673 * no irq, it's not an ARCnet. We can also kill two birds with
674 * one stone because we detect the IRQ at the same time :)
675 */
676
677 /* reset the card by reading the reset port */
678 inb(RESET);
679 JIFFER(RESETtime);
680
681 /* if status port is FF, there's certainly no arcnet... give up. */
682 if (inb(STATUS)==0xFF)
683 {
684 BUGLVL(D_INIT)
685 printk("arcnet: probe failed. Status port empty.\n");
686 return ENODEV;
687 }
688
689 #if 0
690 /* we'll try to be reasonably sure it's an arcnet by making sure
691 * the value of the COMMAND port changes automatically once in a
692 * while. I have no idea what those values ARE, but at least
693 * they work.
694 */
695 {
696 int initval,curval;
697
698 curval=initval=inb(COMMAND);
699 delayval=jiffies+5;
700 while (delayval>=jiffies && curval==initval)
701 curval=inb(COMMAND);
702
703 if (curval==initval)
704 {
705 printk("arcnet: probe failed. never-changing command port (%02Xh).\n",
706 initval);
707 return ENODEV;
708 }
709 }
710 #endif
711
712 BUGLVL(D_INIT)
713 printk("arcnet: status2=%Xh\n",inb(STATUS));
714
715 /* now we turn the reset bit off so we can IRQ next reset... */
716 outb(CFLAGScmd|RESETclear|CONFIGclear,COMMAND);
717 if (inb(STATUS) & RESETflag) /* reset flag STILL on */
718 {
719 BUGLVL(D_INIT)
720 printk("arcnet: probe failed. eternal reset flag1...(status=%Xh)\n",
721 inb(STATUS));
722 return ENODEV;
723 }
724
725 /* set up automatic IRQ detection */
726 autoirq_setup(0);
727
728
729 /* if we do this, we're sure to get an IRQ since the card has
730 * just reset and the NORXflag is on until we tell it to start
731 * receiving.
732 *
733 * However, this could, theoretically, cause a lockup. Maybe I'm just
734 * not very good at theory! :)
735 */
736 outb(NORXflag,INTMASK);
737 JIFFER(RESETtime);
738 outb(0,INTMASK);
739
740 /* and turn the reset flag back off */
741 outb(CFLAGScmd|RESETclear|CONFIGclear,COMMAND);
742
743 airq = autoirq_report(0);
744 BUGLVL(D_INIT) if (airq)
745 printk("arcnet: autoirq is %d\n", airq);
746
747 /* if there was no autoirq AND the user hasn't set any defaults,
748 * give up.
749 */
750 if (!airq && !(dev->base_addr && dev->irq))
751 {
752 BUGLVL(D_INIT)
753 printk("arcnet: probe failed. no autoirq...\n");
754 return ENODEV;
755 }
756
757 /* otherwise we probably have a card. Let's make sure. */
758
759 if (inb(STATUS) & RESETflag) /* reset flag on */
760 {
761 /* now we turn the reset bit off */
762 outb(CFLAGScmd|RESETclear|CONFIGclear,COMMAND);
763 }
764
765 if (inb(STATUS) & RESETflag) /* reset flag STILL on */
766 {
767 BUGLVL(D_INIT)
768 printk("arcnet: probe failed. eternal reset flag...(status=%Xh)\n",
769 inb(STATUS));
770 return ENODEV;
771 }
772
773 /* okay, we've got a real, live ARCnet on our hands. */
774 if (!dev->base_addr) dev->base_addr=ioaddr;
775
776 if (dev->irq < 2) /* "Auto-IRQ" */
777 {
778 /* we already did the autoirq above, so store the values */
779 dev->irq=airq;
780 }
781 else if (dev->irq == 2)
782 {
783 BUGLVL(D_NORMAL)
784 printk("arcnet: IRQ2 == IRQ9, don't worry.\n");
785 dev->irq = 9;
786 }
787
788 BUGLVL(D_INIT)
789 printk("arcnet: irq and base address seem okay. (%lXh, IRQ %d)\n",
790 dev->base_addr,dev->irq);
791 return 0;
792 }
793
794
795 /* A memory probe that is called after the card is reset.
796 * It checks for the official TESTvalue in byte 0 and makes sure the buffer
797 * has certain characteristics of an ARCnet.
798 */
799 int arcnet_memprobe(struct device *dev,u_char *addr)
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
800 {
801 BUGLVL(D_INIT)
802 printk("arcnet: probing memory at %lXh\n",(u_long)addr);
803
804 dev->mem_start=0;
805
806 /* ARCnet memory byte 0 is TESTvalue */
807 if (addr[0]!=TESTvalue)
808 {
809 BUGLVL(D_INIT)
810 printk("arcnet: probe failed. addr=%lXh, addr[0]=%Xh (not %Xh)\n",
811 (unsigned long)addr,addr[0],TESTvalue);
812 return ENODEV;
813 }
814
815 /* now verify the shared memory writability */
816 addr[0]=0x42;
817 if (addr[0]!=0x42)
818 {
819 BUGLVL(D_INIT)
820 printk("arcnet: probe failed. addr=%lXh, addr[0]=%Xh (not 42h)\n",
821 (unsigned long)addr,addr[0]);
822 return ENODEV;
823 }
824
825 /* got it! fill in dev */
826 dev->mem_start=(unsigned long)addr;
827 dev->mem_end=dev->mem_start+512*4-1;
828 dev->rmem_start=dev->mem_start+512*0;
829 dev->rmem_end=dev->mem_start+512*2-1;
830
831 return 0;
832 }
833
834 #endif /* MODULE */
835
836
837 int arcnet_reset(struct device *dev)
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
838 {
839 struct arcnet_local *lp=(struct arcnet_local *)dev->priv;
840 short ioaddr=dev->base_addr;
841 int delayval,recbuf=lp->recbuf;
842 u_char *cardmem;
843
844 outb(0,INTMASK); /* no IRQ's, please! */
845
846 BUGLVL(D_INIT)
847 printk("arcnet: Resetting %s (status=%Xh)\n",
848 dev->name,inb(STATUS));
849
850 inb(RESET); /* Reset by reading this port */
851 JIFFER(RESETtime);
852
853 outb(CFLAGScmd|RESETclear, COMMAND); /* clear flags & end reset */
854 outb(CFLAGScmd|CONFIGclear,COMMAND);
855
856 /* after a reset, the first byte of shared mem is TESTvalue and the
857 * second byte is our 8-bit ARCnet address.
858 */
859 cardmem = (u_char *) dev->mem_start;
860 if (cardmem[0] != TESTvalue)
861 {
862 BUGLVL(D_INIT)
863 printk("arcnet: reset failed: TESTvalue not present.\n");
864 return 1;
865 }
866 lp->arcnum=cardmem[1]; /* save address for later use */
867
868 /* clear out status variables */
869 recbuf=lp->recbuf=0;
870 lp->txbuf=2;
871
872 /* enable extended (512-byte) packets */
873 outb(CONFIGcmd|EXTconf,COMMAND);
874
875 /* clean out all the memory to make debugging make more sense :) */
876 BUGLVL(D_DURING)
877 memset((void *)dev->mem_start,0x42,2048);
878
879 /* and enable receive of our first packet to the first buffer */
880 EnableReceiver();
881
882 /* re-enable interrupts */
883 outb(NORXflag|RECON_flag,INTMASK);
884
885 /* done! return success. */
886 return 0;
887 }
888
889 static int arcnetW_init(struct device *dev)
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
890 {
891 struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
892
893 ether_setup(lp->wdev);
894 dev->dev_addr[0]=0;
895 dev->dev_addr[5]=lp->arcnum;
896 dev->mtu=493; /* MTU is small because of missing packet splitting */
897 lp->wdev->open=NULL;
898 lp->wdev->stop=NULL;
899 lp->wdev->hard_start_xmit=arcnetW_send_packet;
900
901 BUGLVL(D_EXTRA)
902 printk("%s: ARCnet \"Windows\" protocol initialized.\n",
903 lp->wdev->name);
904
905 return 0;
906 }
907
908
909 /****************************************************************************
910 * *
911 * Open and close the driver *
912 * *
913 ****************************************************************************/
914
915
916 /* Open/initialize the board. This is called sometime after booting when
917 * the 'ifconfig' program is run.
918 *
919 * This routine should set everything up anew at each open, even
920 * registers that "should" only need to be set once at boot, so that
921 * there is non-reboot way to recover if something goes wrong.
922 */
923 static int
924 arcnet_open(struct device *dev)
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
925 {
926 struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
927
928 if (dev->metric>=1000)
929 {
930 arcnet_debug=dev->metric-1000;
931 printk("arcnet: debug level set to %d\n",arcnet_debug);
932 dev->metric=1;
933 }
934
935 BUGLVL(D_NORMAL) printk(version);
936
937 irq2dev_map[dev->irq] = dev;
938
939 BUGLVL(D_EXTRA) printk("arcnet: arcnet_open: resetting card.\n");
940
941 /* try to reset - twice if it fails the first time */
942 if (arcnet_reset(dev) && arcnet_reset(dev))
943 return -ENODEV;
944
945 dev->tbusy=0;
946 dev->interrupt=0;
947 lp->intx=0;
948 lp->in_txhandler=0;
949
950 /* The RFC1201 driver is the default - just store */
951 lp->adev=dev;
952 BUGLVL(D_EXTRA)
953 printk("%s: ARCnet RFC1201 protocol initialized.\n",
954 lp->adev->name);
955
956 /* Initialize the Windows protocol driver */
957 lp->wdev=(struct device *)kmalloc(sizeof(struct device),GFP_KERNEL);
958 memcpy(lp->wdev,dev,sizeof(struct device));
959 lp->wdev->name=(char *)kmalloc(10,GFP_KERNEL);
960 sprintf(lp->wdev->name,"%sw",dev->name);
961 lp->wdev->init=arcnetW_init;
962 register_netdev(lp->wdev);
963
964 /* we're started */
965 START=1;
966
967 #ifdef MODULE
968 MOD_INC_USE_COUNT;
969 #endif
970
971 return 0;
972 }
973
974
975 /* The inverse routine to arcnet_open - shuts down the card.
976 */
977 static int
978 arcnet_close(struct device *dev)
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
979 {
980 int ioaddr = dev->base_addr;
981 struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
982
983 TBUSY=1;
984 START=0;
985
986 /* Flush the Tx and disable Rx here. */
987
988 outb(0,INTMASK); /* no IRQ's */
989 outb(NOTXcmd,COMMAND); /* disable transmit */
990 outb(NORXcmd,COMMAND); /* disable receive */
991
992 /* do NOT free lp->adev!! It's static! */
993 lp->adev=NULL;
994
995 /* free the Windows protocol device */
996 lp->wdev->start=0;
997 lp->wdev->priv=NULL;
998 unregister_netdev(lp->wdev);
999 kfree(lp->wdev->name);
1000 kfree(lp->wdev);
1001 lp->wdev=NULL;
1002
1003 /* Update the statistics here. */
1004
1005 #ifdef MODULE
1006 MOD_DEC_USE_COUNT;
1007 #endif
1008
1009 return 0;
1010 }
1011
1012
1013
1014 /****************************************************************************
1015 * *
1016 * Transmitter routines *
1017 * *
1018 ****************************************************************************/
1019
1020
1021 /* Called by the kernel in order to transmit a packet.
1022 */
1023 static int
1024 arcnetA_send_packet(struct sk_buff *skb, struct device *dev)
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
1025 {
1026 struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
1027 int ioaddr=dev->base_addr;
1028
1029 lp->intx++;
1030
1031 BUGLVL(D_DURING)
1032 printk("arcnet: transmit requested (status=%Xh, inTX=%d)\n",
1033 inb(STATUS),lp->intx);
1034
1035 if (lp->in_txhandler)
1036 {
1037 printk("arcnet: send_packet called while in txhandler!\n");
1038 lp->intx--;
1039 return 1;
1040 }
1041
1042 if (IF_TBUSY)
1043 {
1044 /* If we get here, some higher level has decided we are broken.
1045 There should really be a "kick me" function call instead. */
1046 int tickssofar = jiffies - dev->trans_start;
1047 int recbuf=lp->recbuf;
1048 int status=inb(STATUS);
1049
1050 if (tickssofar < 5)
1051 {
1052 BUGLVL(D_DURING)
1053 printk("arcnet: premature kickme! (status=%Xh ticks=%d o.skb=%ph numsegs=%d segnum=%d\n",
1054 status,tickssofar,lp->outgoing.skb,
1055 lp->outgoing.numsegs,
1056 lp->outgoing.segnum);
1057 lp->intx--;
1058 return 1;
1059 }
1060
1061 BUGLVL(D_EXTRA)
1062 printk("arcnet: transmit timed out (status=%Xh, inTX=%d, inTXh=%d, tickssofar=%d)\n",
1063 status,lp->intx,lp->in_txhandler,tickssofar);
1064
1065 lp->stats.tx_errors++;
1066
1067 /* Try to restart the adaptor. */
1068 /*arcnet_reset(dev);*/
1069
1070 outb(0,INTMASK);
1071 if (status&NORXflag) EnableReceiver();
1072 if (!(status&TXFREEflag)) outb(NOTXcmd,COMMAND);
1073 dev->trans_start = jiffies;
1074
1075 if (lp->outgoing.skb)
1076 {
1077 dev_kfree_skb(lp->outgoing.skb,FREE_WRITE);
1078 lp->stats.tx_dropped++;
1079 }
1080 lp->outgoing.skb=NULL;
1081
1082 TBUSY=0;
1083 lp->intx--;
1084 /*lp->intx=0;*/
1085 /*lp->in_txhandler=0;*/
1086 lp->txready=0;
1087 lp->sending=0;
1088 mark_bh(NET_BH);
1089
1090 outb(NORXflag|RECON_flag,INTMASK);
1091
1092 return 1;
1093 }
1094
1095 /* If some higher layer thinks we've missed a tx-done interrupt
1096 we are passed NULL. Caution: dev_tint() handles the cli()/sti()
1097 itself. */
1098 if (skb == NULL) {
1099 BUGLVL(D_NORMAL)
1100 printk("arcnet: tx passed null skb (status=%Xh, inTX=%d, tickssofar=%ld)\n",
1101 inb(STATUS),lp->intx,jiffies-dev->trans_start);
1102 dev_tint(dev);
1103 lp->intx--;
1104 return 0;
1105 }
1106
1107 if (lp->txready) /* transmit already in progress! */
1108 {
1109 printk("arcnet: trying to start new packet while busy! (status=%Xh)\n",
1110 inb(STATUS));
1111 /*printk("arcnet: marking as not ready.\n");*/
1112 outb(0,INTMASK);
1113 outb(NOTXcmd,COMMAND); /* abort current send */
1114 arcnet_inthandler(dev); /* fake an interrupt */
1115 lp->stats.tx_errors++;
1116 lp->intx--;
1117 lp->txready=0; /* we definitely need this line! */
1118
1119 return 1;
1120 }
1121
1122 /* Block a timer-based transmit from overlapping. This could better be
1123 done with atomic_swap(1, dev->tbusy), but set_bit() works as well. */
1124 if (set_bit(0, (void*)&dev->tbusy) != 0)
1125 {
1126 printk("arcnet: transmitter called with busy bit set! (status=%Xh, inTX=%d, tickssofar=%ld)\n",
1127 inb(STATUS),lp->intx,jiffies-dev->trans_start);
1128 lp->intx--;
1129 return -EBUSY;
1130 }
1131 else {
1132 struct Outgoing *out=&(lp->outgoing);
1133
1134 TBUSY=1;
1135
1136 out->length = 1 < skb->len ? skb->len : 1;
1137 out->hdr=(struct ClientData*)skb->data;
1138 out->skb=skb;
1139
1140 BUGLVL(D_SKB)
1141 {
1142 short i;
1143 for( i=0; i< skb->len; i++)
1144 {
1145 if( i%16 == 0 ) printk("\n[%04hX] ",i);
1146 printk("%02hX ",((unsigned char*)skb->data)[i]);
1147 }
1148 printk("\n");
1149 }
1150
1151 out->hdr->sequence=(lp->sequence++);
1152
1153 if (lp->txready && inb(STATUS)&TXFREEflag)
1154 arcnetA_go_tx(dev);
1155
1156 /* fits in one packet? */
1157 if (out->length-EXTRA_CLIENTDATA<=XMTU)
1158 {
1159 BUGLVL(D_DURING)
1160 printk("arcnet: not splitting %d-byte packet. (split_flag=%d)\n",
1161 out->length,out->hdr->split_flag);
1162 BUGLVL(D_EXTRA) if (out->hdr->split_flag)
1163 printk("arcnet: short packet has split_flag set?! (split_flag=%d)\n",
1164 out->hdr->split_flag);
1165 out->numsegs=1;
1166 out->segnum=1;
1167 arcnetA_prepare_tx(dev,out->hdr,
1168 out->length-sizeof(struct ClientData),
1169 ((char *)skb->data)+sizeof(struct ClientData));
1170
1171 /* done right away */
1172 dev_kfree_skb(out->skb,FREE_WRITE);
1173 out->skb=NULL;
1174
1175 if (!lp->sending)
1176 {
1177 arcnetA_go_tx(dev);
1178
1179 /* inform upper layers */
1180 TBUSY=0;
1181 mark_bh(NET_BH);
1182 }
1183 }
1184 else /* too big for one - split it */
1185 {
1186 int maxsegsize=XMTU-4;
1187
1188 out->data=(u_char *)skb->data
1189 + sizeof(struct ClientData);
1190 out->dataleft=out->length-sizeof(struct ClientData);
1191 out->numsegs=(out->dataleft+maxsegsize-1)/maxsegsize;
1192
1193 out->segnum=0;
1194
1195 BUGLVL(D_TX) printk("arcnet: packet (%d bytes) split into %d fragments:\n",
1196 out->length,out->numsegs);
1197
1198 /* if a packet waiting, launch it */
1199 if (lp->txready && inb(STATUS)&TXFREEflag)
1200 arcnetA_go_tx(dev);
1201
1202 if (!lp->txready)
1203 {
1204 /* prepare a packet, launch it and prepare
1205 * another.
1206 */
1207 arcnetA_continue_tx(dev);
1208 if (!lp->sending)
1209 {
1210 arcnetA_go_tx(dev);
1211 arcnetA_continue_tx(dev);
1212 if (!lp->sending)
1213 arcnetA_go_tx(dev);
1214 }
1215 }
1216
1217 /* if segnum==numsegs, the transmission is finished;
1218 * free the skb right away.
1219 */
1220 if (out->segnum==out->numsegs)
1221 {
1222 /* transmit completed */
1223 out->segnum++;
1224 if (out->skb)
1225 dev_kfree_skb(out->skb,FREE_WRITE);
1226 out->skb=NULL;
1227 }
1228 }
1229 }
1230
1231 lp->intx--;
1232 lp->stats.tx_packets++;
1233 dev->trans_start=jiffies;
1234 return 0;
1235 }
1236
1237 /* After an RFC1201 split packet has been set up, this function calls
1238 * arcnetA_prepare_tx to load the next segment into the card. This function
1239 * does NOT automatically call arcnetA_go_tx to allow for easier double-
1240 * buffering.
1241 */
1242 static void arcnetA_continue_tx(struct device *dev)
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
1243 {
1244 struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
1245 int maxsegsize=XMTU-4;
1246 struct Outgoing *out=&(lp->outgoing);
1247
1248 if (lp->txready)
1249 {
1250 printk("arcnet: continue_tx: called with packet in buffer!\n");
1251 return;
1252 }
1253
1254 if (out->segnum>=out->numsegs)
1255 {
1256 printk("arcnet: continue_tx: building segment %d of %d!\n",
1257 out->segnum+1,out->numsegs);
1258 }
1259
1260 if (!out->segnum) /* first packet */
1261 out->hdr->split_flag=((out->numsegs-2)<<1)+1;
1262 else
1263 out->hdr->split_flag=out->segnum<<1;
1264
1265 out->seglen=maxsegsize;
1266 if (out->seglen>out->dataleft) out->seglen=out->dataleft;
1267
1268 BUGLVL(D_TX) printk("arcnet: building packet #%d (%d bytes) of %d (%d total), splitflag=%d\n",
1269 out->segnum+1,out->seglen,out->numsegs,
1270 out->length,out->hdr->split_flag);
1271
1272 arcnetA_prepare_tx(dev,out->hdr,out->seglen,out->data);
1273
1274 out->dataleft-=out->seglen;
1275 out->data+=out->seglen;
1276 out->segnum++;
1277 }
1278
1279
1280 /* Given an skb, copy a packet into the ARCnet buffers for later transmission
1281 * by arcnetA_go_tx.
1282 */
1283 static void
1284 arcnetA_prepare_tx(struct device *dev,struct ClientData *hdr,short length,
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
1285 char *data)
1286 {
1287 struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
1288 struct ClientData *arcsoft;
1289 union ArcPacket *arcpacket =
1290 (union ArcPacket *)(dev->mem_start+512*(lp->txbuf^1));
1291 u_char pkttype;
1292 int offset;
1293 short daddr;
1294
1295 lp->txbuf=lp->txbuf^1; /* XOR with 1 to alternate between 2 and 3 */
1296
1297 length+=4;
1298
1299 BUGLVL(D_TX)
1300 printk("arcnet: arcnetA_prep_tx: hdr:%ph, length:%d, data:%ph\n",
1301 hdr,length,data);
1302
1303 /* clean out the page to make debugging make more sense :) */
1304 BUGLVL(D_DURING)
1305 memset((void *)dev->mem_start+lp->txbuf*512,0x42,512);
1306
1307 daddr=arcpacket->hardheader.destination=hdr->daddr;
1308
1309 /* load packet into shared memory */
1310 if (length<=MTU) /* Normal (256-byte) Packet */
1311 {
1312 pkttype=NORMAL;
1313
1314 arcpacket->hardheader.offset1=offset=256-length;
1315 arcsoft=(struct ClientData *)
1316 (&arcpacket->raw[offset-EXTRA_CLIENTDATA]);
1317 }
1318 else if (length>=MinTU) /* Extended (512-byte) Packet */
1319 {
1320 pkttype=EXTENDED;
1321
1322 arcpacket->hardheader.offset1=0;
1323 arcpacket->hardheader.offset2=offset=512-length;
1324 arcsoft=(struct ClientData *)
1325 (&arcpacket->raw[offset-EXTRA_CLIENTDATA]);
1326 }
1327 else /* Exception Packet */
1328 {
1329 pkttype=EXCEPTION;
1330
1331 arcpacket->hardheader.offset1=0;
1332 arcpacket->hardheader.offset2=offset=512-length-4;
1333 arcsoft=(struct ClientData *)
1334 (&arcpacket->raw[offset+4-EXTRA_CLIENTDATA]);
1335
1336 /* exception-specific stuff - these four bytes
1337 * make the packet long enough to fit in a 512-byte
1338 * frame.
1339 */
1340 arcpacket->raw[offset+0]=hdr->protocol_id;
1341 arcpacket->raw[offset+1]=0xFF; /* FF flag */
1342 arcpacket->raw[offset+2]=0xFF; /* FF padding */
1343 arcpacket->raw[offset+3]=0xFF; /* FF padding */
1344 }
1345
1346
1347 /* copy the packet into ARCnet shmem
1348 * - the first bytes of ClientData header are skipped
1349 */
1350 memcpy((u_char*)arcsoft+EXTRA_CLIENTDATA,
1351 (u_char*)hdr+EXTRA_CLIENTDATA,4);
1352 memcpy((u_char*)arcsoft+sizeof(struct ClientData),
1353 data,length-4);
1354
1355 BUGLVL(D_DURING) printk("arcnet: transmitting packet to station %02Xh (%d bytes, type=%d)\n",
1356 daddr,length,pkttype);
1357
1358 BUGLVL(D_TX)
1359 {
1360 int countx,county;
1361
1362 printk("arcnet: packet dump [tx] follows:");
1363
1364 for (county=0; county<16+(pkttype!=NORMAL)*16; county++)
1365 {
1366 printk("\n[%04X] ",county*16);
1367 for (countx=0; countx<16; countx++)
1368 printk("%02X ",
1369 arcpacket->raw[county*16+countx]);
1370 }
1371
1372 printk("\n");
1373 }
1374
1375 #ifdef VERIFY_ACK
1376 lp->outgoing.lastload_dest=hdr->daddr;
1377 #endif
1378 lp->txready=lp->txbuf; /* packet is ready for sending */
1379 }
1380
1381 /* Actually start transmitting a packet that was placed in the card's
1382 * buffer by arcnetA_prepare_tx.
1383 */
1384 static void
1385 arcnetA_go_tx(struct device *dev)
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
1386 {
1387 struct arcnet_local *lp=(struct arcnet_local *)dev->priv;
1388 int ioaddr=dev->base_addr;
1389
1390 BUGLVL(D_DURING)
1391 printk("arcnet: go_tx: status=%Xh\n",
1392 inb(STATUS));
1393
1394 if (!(inb(STATUS)&TXFREEflag) || !lp->txready) return;
1395
1396 /* start sending */
1397 outb(TXcmd|(lp->txready<<3),COMMAND);
1398
1399 outb(TXFREEflag|NORXflag|RECON_flag,INTMASK);
1400
1401 dev->trans_start = jiffies;
1402 lp->txready=0;
1403 lp->sending++;
1404 #ifdef VERIFY_ACK
1405 lp->outgoing.lasttrans_dest=lp->outgoing.lastload_dest;
1406 lp->outgoing.lastload_dest=0;
1407 #endif
1408 }
1409
1410
1411 /* Called by the kernel in order to transmit a "Windows" packet.
1412 */
1413 static int
1414 arcnetW_send_packet(struct sk_buff *skb, struct device *dev)
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
1415 {
1416 struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
1417
1418 BUGLVL(D_DURING)
1419 printk("%s: in arcnetW_send_packet (skb=%p)\n",dev->name,skb);
1420
1421 if (IF_TBUSY)
1422 {
1423 /* If we get here, some higher level has decided we are broken.
1424 There should really be a "kick me" function call instead. */
1425 int tickssofar = jiffies - dev->trans_start;
1426 if (tickssofar < 10)
1427 return 1;
1428 printk("%s: transmit timed out\n",dev->name);
1429
1430 /* Try to restart the adaptor. */
1431 TBUSY=0;
1432 dev->trans_start = jiffies;
1433 return 0;
1434 }
1435
1436 /* If some higher layer thinks we've missed an tx-done interrupt
1437 we are passed NULL. Caution: dev_tint() handles the cli()/sti()
1438 itself. */
1439 if (skb == NULL)
1440 {
1441 dev_tint(dev);
1442 return 0;
1443 }
1444
1445 /* Block a timer-based transmit from overlapping. This could better be
1446 done with atomic_swap(1, dev->tbusy), but set_bit() works as well. */
1447 if (set_bit(0, (void*)&dev->tbusy) != 0)
1448 printk("%s: Transmitter access conflict.\n", dev->name);
1449 else
1450 {
1451 union ArcPacket *arcpacket =
1452 (union ArcPacket *)(dev->mem_start+512*(lp->txbuf^1));
1453 u_char *arcsoft,daddr;
1454 short offset,length=skb->len+1;
1455
1456 TBUSY=1;
1457
1458 if (length>XMTU)
1459 {
1460 printk("arcnet: MTU for %s and %s must be <= 493 for Windows protocol.\n",
1461 lp->adev->name,lp->wdev->name);
1462 printk("arcnet: transmit aborted.\n");
1463
1464 dev_kfree_skb(skb,FREE_WRITE);
1465 return 0;
1466 }
1467
1468 BUGLVL(D_DURING)
1469 printk("arcnet: starting tx sequence...\n");
1470
1471 lp->txbuf=lp->txbuf^1; /* XOR with 1 to alternate btw 2 & 3 */
1472
1473 /* clean out the page to make debugging make more sense :) */
1474 BUGLVL(D_DURING)
1475 memset((void *)dev->mem_start+lp->txbuf*512,0x42,512);
1476
1477 /* broadcasts have address FF:FF:FF:FF:FF:FF in etherspeak */
1478 if (((struct ethhdr*)(skb->data))->h_dest[0] == 0xFF)
1479 daddr=arcpacket->hardheader.destination=0;
1480 else
1481 daddr=arcpacket->hardheader.destination=
1482 ((struct ethhdr*)(skb->data))->h_dest[5];
1483
1484 /* load packet into shared memory */
1485 offset=512-length;
1486 if (length>MTU) /* long/exception packet */
1487 {
1488 if (length<MinTU) offset-=3;
1489 arcpacket->hardheader.offset1=0;
1490 arcpacket->hardheader.offset2=offset;
1491 }
1492 else /* short packet */
1493 {
1494 arcpacket->hardheader.offset1=(offset-=256);
1495 }
1496
1497 BUGLVL(D_DURING)
1498 printk("arcnet: length=%Xh, offset=%Xh, offset1=%Xh, offset2=%Xh\n",
1499 length,offset,arcpacket->hardheader.offset1,
1500 arcpacket->hardheader.offset2);
1501
1502 arcsoft=&arcpacket->raw[offset];
1503 arcsoft[0]=ARC_P_MS_TCPIP;
1504 arcsoft++;
1505
1506 /* copy the packet into ARCnet shmem
1507 * - the first bytes of ClientData header are skipped
1508 */
1509 BUGLVL(D_DURING) printk("arcnet: ready to memcpy\n");
1510
1511 memcpy(arcsoft,skb->data,skb->len);
1512
1513 BUGLVL(D_DURING)
1514 printk("arcnet: transmitting packet to station %02Xh (%d bytes)\n",
1515 daddr,length);
1516
1517 BUGLVL(D_TX)
1518 {
1519 int countx,county;
1520
1521 printk("arcnet: packet dump [tx] follows:");
1522
1523 for (county=0; county<16+(length>=240)*16; county++)
1524 {
1525 printk("\n[%04X] ",county*16);
1526 for (countx=0; countx<16; countx++)
1527 printk("%02X ",
1528 arcpacket->raw[county*16+countx]);
1529 }
1530
1531 printk("\n");
1532 }
1533
1534 #ifdef VERIFY_ACK
1535 lp->outgoing.lastload_dest=daddr;
1536 #endif
1537 lp->txready=lp->txbuf; /* packet is ready for sending */
1538
1539 arcnetA_go_tx(dev);
1540 dev->trans_start = jiffies;
1541 }
1542
1543 dev_kfree_skb(skb,FREE_WRITE);
1544
1545 return 0;
1546 }
1547
1548
1549 /****************************************************************************
1550 * *
1551 * Interrupt handler *
1552 * *
1553 ****************************************************************************/
1554
1555
1556 /* The typical workload of the driver: Handle the network interface
1557 * interrupts. This doesn't do much right now except call arcnet_inthandler,
1558 * which takes different parameters but is sometimes called from other places
1559 * as well.
1560 */
1561 static void
1562 arcnet_interrupt(int irq,struct pt_regs *regs)
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
1563 {
1564 struct device *dev = (struct device *)(irq2dev_map[irq]);
1565
1566 if (dev==NULL || !dev->start)
1567 {
1568 BUGLVL(D_EXTRA)
1569 printk("arcnet: irq %d for unknown device.\n", irq);
1570 return;
1571 }
1572
1573 arcnet_inthandler(dev);
1574 }
1575
1576
1577 /* The actual interrupt handler routine - handle various IRQ's generated
1578 * by the card.
1579 */
1580 static void
1581 arcnet_inthandler(struct device *dev)
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
1582 {
1583 struct arcnet_local *lp;
1584 int ioaddr, status, boguscount = 3, didsomething;
1585
1586 if (dev->interrupt)
1587 printk("arcnet: DRIVER PROBLEM! Nested arcnet interrupts!\n");
1588
1589 dev->interrupt = 1;
1590
1591 ioaddr = dev->base_addr;
1592 lp = (struct arcnet_local *)dev->priv;
1593
1594 outb(0,INTMASK);
1595 sti();
1596
1597 BUGLVL(D_DURING)
1598 printk("arcnet: in net_interrupt (status=%Xh)\n",inb(STATUS));
1599
1600 do
1601 {
1602 status = inb(STATUS);
1603 didsomething=0;
1604
1605 if (!dev->start)
1606 {
1607 BUGLVL(D_DURING)
1608 printk("arcnet: ARCnet not yet initialized. irq ignored. (status=%Xh)\n",
1609 status);
1610 if (!(status&NORXflag))
1611 outb(NORXflag|RECON_flag,INTMASK);
1612
1613 dev->interrupt=0;
1614 return;
1615 }
1616
1617 /* RESET flag was enabled - card is resetting and if RX
1618 * is disabled, it's NOT because we just got a packet.
1619 */
1620 if (status & RESETflag)
1621 {
1622 outb(CFLAGScmd|RESETclear,COMMAND);
1623 BUGLVL(D_INIT)
1624 printk("arcnet: reset irq (status=%Xh)\n",
1625 status);
1626 }
1627 #ifdef DETECT_RECONFIGS
1628 if (status & RECONflag)
1629 {
1630 outb(CFLAGScmd|CONFIGclear,COMMAND);
1631 BUGLVL(D_EXTRA)
1632 printk("arcnet: Network reconfiguration detected (status=%Xh)\n",
1633 status);
1634 lp->stats.tx_carrier_errors++;
1635 }
1636 #endif
1637
1638 /* RX is inhibited - we must have received something. */
1639 if (status & NORXflag)
1640 {
1641 int recbuf=lp->recbuf=!lp->recbuf;
1642
1643 BUGLVL(D_DURING)
1644 printk("arcnet: receive irq (status=%Xh)\n",
1645 status);
1646
1647 /* enable receive of our next packet */
1648 EnableReceiver();
1649
1650 /* Got a packet. */
1651 arcnet_rx(dev,!recbuf);
1652
1653 didsomething++;
1654 }
1655
1656 /* it can only be an xmit-done irq if we're xmitting :) */
1657 if (status&TXFREEflag && !lp->in_txhandler && lp->sending)
1658 {
1659 struct Outgoing *out=&(lp->outgoing);
1660
1661 lp->in_txhandler++;
1662 lp->sending--;
1663
1664 BUGLVL(D_DURING)
1665 printk("arcnet: TX IRQ (stat=%Xh, numsegs=%d, segnum=%d, skb=%ph)\n",
1666 status,out->numsegs,out->segnum,out->skb);
1667
1668 #ifdef VERIFY_ACK
1669 if (!(status&TXACKflag))
1670 {
1671 if (lp->outgoing.lasttrans_dest != 0)
1672 {
1673 BUGLVL(D_NORMAL)
1674 printk("arcnet: transmit was not acknowledged! (status=%Xh, dest=%d)\n",
1675 status,
1676 lp->outgoing.lasttrans_dest);
1677 lp->stats.tx_errors++;
1678 }
1679 else
1680 {
1681 BUGLVL(D_DURING)
1682 printk("arcnet: broadcast was not acknowledged; that's normal (status=%Xh, dest=%d)\n",
1683 status,
1684 lp->outgoing.lasttrans_dest);
1685 }
1686 }
1687 #endif
1688
1689 /* send packet if there is one */
1690 if (lp->txready)
1691 {
1692 arcnetA_go_tx(dev);
1693 didsomething++;
1694 }
1695
1696 if (lp->intx)
1697 {
1698 lp->in_txhandler--;
1699 continue;
1700 }
1701
1702 if (!lp->outgoing.skb)
1703 {
1704 BUGLVL(D_DURING)
1705 printk("arcnet: TX IRQ done: no split to continue.\n");
1706
1707 /* inform upper layers */
1708 if (!lp->txready && IF_TBUSY)
1709 {
1710 TBUSY=0;
1711 mark_bh(NET_BH);
1712 }
1713
1714 lp->in_txhandler--;
1715 continue;
1716 }
1717
1718 /*lp->stats.tx_packets++;*/
1719
1720 /* if more than one segment, and not all segments
1721 * are done, then continue xmit.
1722 */
1723 if (out->segnum<out->numsegs)
1724 arcnetA_continue_tx(dev);
1725 if (lp->txready && !lp->sending)
1726 arcnetA_go_tx(dev);
1727
1728 /* if segnum==numsegs, the transmission is finished;
1729 * free the skb.
1730 */
1731 if (out->segnum>=out->numsegs)
1732 {
1733 /* transmit completed */
1734 out->segnum++;
1735 if (out->skb)
1736 dev_kfree_skb(out->skb,FREE_WRITE);
1737 out->skb=NULL;
1738
1739 /* inform upper layers */
1740 if (!lp->txready && IF_TBUSY)
1741 {
1742 TBUSY=0;
1743 mark_bh(NET_BH);
1744 }
1745 }
1746 didsomething++;
1747
1748 lp->in_txhandler--;
1749 }
1750
1751 } while (--boguscount && didsomething);
1752
1753 BUGLVL(D_DURING)
1754 printk("arcnet: net_interrupt complete (status=%Xh)\n\n",
1755 inb(STATUS));
1756
1757 if (dev->start && lp->sending )
1758 outb(NORXflag|TXFREEflag|RECON_flag,INTMASK);
1759 else
1760 outb(NORXflag|RECON_flag,INTMASK);
1761
1762 dev->interrupt=0;
1763 }
1764
1765
1766 /****************************************************************************
1767 * *
1768 * Receiver routines *
1769 * *
1770 ****************************************************************************/
1771
1772
1773 /* A packet has arrived; grab it from the buffers and possibly unsplit it.
1774 * This is a generic packet receiver that calls arcnet??_rx depending on the
1775 * protocol ID found.
1776 */
1777 static void
1778 arcnet_rx(struct device *dev,int recbuf)
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
1779 {
1780 struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
1781 int ioaddr = dev->base_addr;
1782 union ArcPacket *arcpacket=
1783 (union ArcPacket *)(dev->mem_start+recbuf*512);
1784 u_char *arcsoft;
1785 short length,offset;
1786 u_char daddr,saddr;
1787
1788 saddr=arcpacket->hardheader.source;
1789 daddr=arcpacket->hardheader.destination;
1790
1791 /* if source is 0, it's a "used" packet! */
1792 if (saddr==0)
1793 {
1794 printk("arcnet: discarding old packet. (status=%Xh)\n",
1795 inb(STATUS));
1796 lp->stats.rx_errors++;
1797 return;
1798 }
1799 arcpacket->hardheader.source=0;
1800
1801 if (arcpacket->hardheader.offset1) /* Normal Packet */
1802 {
1803 offset=arcpacket->hardheader.offset1;
1804 arcsoft=&arcpacket->raw[offset];
1805 length=256-offset;
1806 }
1807 else /* ExtendedPacket or ExceptionPacket */
1808 {
1809 offset=arcpacket->hardheader.offset2;
1810 arcsoft=&arcpacket->raw[offset];
1811
1812 length=512-offset;
1813 }
1814
1815 BUGLVL(D_DURING)
1816 printk("arcnet: received packet from %02Xh to %02Xh (%d bytes)\n",
1817 saddr,daddr,length);
1818
1819 /* call the right receiver for the protocol */
1820 switch (arcsoft[0])
1821 {
1822 case ARC_P_IP:
1823 case ARC_P_ARP:
1824 case ARC_P_RARP:
1825 case ARC_P_IPX:
1826 arcnetA_rx(dev,(struct ClientData*)arcsoft,
1827 length,saddr,daddr);
1828 break;
1829 case ARC_P_MS_TCPIP:
1830 arcnetW_rx(dev,arcsoft,length,saddr,daddr);
1831 break;
1832 default:
1833 printk("arcnet: received unknown protocol %d (%Xh)\n",
1834 arcsoft[0],arcsoft[0]);
1835 break;
1836 }
1837
1838 BUGLVL(D_RX)
1839 {
1840 int countx,county;
1841
1842 printk("arcnet: rx packet dump follows:");
1843
1844 for (county=0; county<16+(length>240)*16; county++)
1845 {
1846 printk("\n[%04X] ",county*16);
1847 for (countx=0; countx<16; countx++)
1848 printk("%02X ",
1849 arcpacket->raw[county*16+countx]);
1850 }
1851
1852 printk("\n");
1853 }
1854
1855
1856 /* If any worth-while packets have been received, a mark_bh(NET_BH)
1857 * has been done by netif_rx and Linux will handle them after we
1858 * return.
1859 */
1860 }
1861
1862
1863 /* Packet receiver for "standard" RFC1201-style packets
1864 */
1865 static void
1866 arcnetA_rx(struct device *dev,struct ClientData *arcsoft,
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
1867 int length,u_char saddr, u_char daddr)
1868 {
1869 struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
1870 struct sk_buff *skb;
1871 struct ClientData *soft;
1872
1873 BUGLVL(D_DURING)
1874 printk("arcnet: it's an RFC1201 packet (length=%d)\n",
1875 length);
1876
1877 arcsoft=(struct ClientData *)((u_char *)arcsoft-EXTRA_CLIENTDATA);
1878 length+=EXTRA_CLIENTDATA;
1879
1880 if (arcsoft->split_flag==0xFF) /* Exception Packet */
1881 {
1882 BUGLVL(D_DURING)
1883 printk("arcnet: compensating for exception packet\n");
1884
1885 /* skip over 4-byte junkola */
1886 arcsoft=(struct ClientData *)
1887 ((u_char *)arcsoft + 4);
1888 length-=4;
1889 }
1890
1891 if (!arcsoft->split_flag) /* not split */
1892 {
1893 struct Incoming *in=&lp->incoming[saddr];
1894
1895 BUGLVL(D_RX) printk("arcnet: incoming is not split (splitflag=%d)\n",
1896 arcsoft->split_flag);
1897
1898 if (in->skb) /* already assembling one! */
1899 {
1900 BUGLVL(D_EXTRA) printk("arcnet: aborting assembly (seq=%d) for unsplit packet (splitflag=%d, seq=%d)\n",
1901 in->sequence,arcsoft->split_flag,
1902 arcsoft->sequence);
1903 kfree_skb(in->skb,FREE_WRITE);
1904 lp->stats.tx_dropped++;
1905 lp->stats.rx_errors++;
1906 in->skb=NULL;
1907 }
1908
1909 in->sequence=arcsoft->sequence;
1910
1911 skb = alloc_skb(length, GFP_ATOMIC);
1912 if (skb == NULL) {
1913 printk("arcnet: Memory squeeze, dropping packet.\n");
1914 lp->stats.rx_dropped++;
1915 return;
1916 }
1917 soft=(struct ClientData *)skb->data;
1918
1919 skb->len = length;
1920 skb->dev = dev;
1921
1922 memcpy((u_char *)soft+EXTRA_CLIENTDATA,
1923 (u_char *)arcsoft+EXTRA_CLIENTDATA,
1924 length-EXTRA_CLIENTDATA);
1925 soft->daddr=daddr;
1926 soft->saddr=saddr;
1927
1928 /* ARP packets have problems when sent from DOS.
1929 * source address is always 0 on some systems! So we take
1930 * the hardware source addr (which is impossible to fumble)
1931 * and insert it ourselves.
1932 */
1933 if (soft->protocol_id == ARC_P_ARP)
1934 {
1935 struct arphdr *arp=(struct arphdr *)
1936 ((char *)soft+sizeof(struct ClientData));
1937
1938 /* make sure addresses are the right length */
1939 if (arp->ar_hln==1 && arp->ar_pln==4)
1940 {
1941 char *cptr=(char *)(arp)+sizeof(struct arphdr);
1942
1943 if (!*cptr) /* is saddr = 00? */
1944 {
1945 BUGLVL(D_EXTRA)
1946 printk("arcnet: ARP source address was 00h, set to %02Xh.\n",
1947 saddr);
1948 *cptr=saddr;
1949 }
1950 else BUGLVL(D_DURING)
1951 {
1952 printk("arcnet: ARP source address (%Xh) is fine.\n",
1953 *cptr);
1954 }
1955 }
1956 else
1957 {
1958 printk("arcnet: funny-shaped ARP packet. (%Xh, %Xh)\n",
1959 arp->ar_hln,arp->ar_pln);
1960 lp->stats.rx_frame_errors++;
1961 }
1962 }
1963
1964 BUGLVL(D_SKB)
1965 {
1966 short i;
1967 for( i=0; i< skb->len; i++)
1968 {
1969 if( i%16 == 0 ) printk("\n[%04hX] ",i);
1970 printk("%02hX ",((unsigned char*)skb->data)[i]);
1971 }
1972 printk("\n");
1973 }
1974
1975 skb->protocol=arcnetA_type_trans(skb,dev);
1976
1977 netif_rx(skb);
1978 lp->stats.rx_packets++;
1979 }
1980 else /* split packet */
1981 {
1982 /* NOTE: MSDOS ARP packet correction should only need to
1983 * apply to unsplit packets, since ARP packets are so short.
1984 *
1985 * My interpretation of the RFC1201 (ARCnet) document is that
1986 * if a packet is received out of order, the entire assembly
1987 * process should be aborted.
1988 *
1989 * The RFC also mentions "it is possible for successfully
1990 * received packets to be retransmitted." As of 0.40 all
1991 * previously received packets are allowed, not just the
1992 * most recent one.
1993 *
1994 * We allow multiple assembly processes, one for each
1995 * ARCnet card possible on the network. Seems rather like
1996 * a waste of memory. Necessary?
1997 */
1998
1999 struct Incoming *in=&lp->incoming[saddr];
2000
2001 BUGLVL(D_RX) printk("arcnet: packet is split (splitflag=%d, seq=%d)\n",
2002 arcsoft->split_flag,in->sequence);
2003
2004 if (in->skb && in->sequence!=arcsoft->sequence)
2005 {
2006 BUGLVL(D_EXTRA) printk("arcnet: wrong seq number, aborting assembly (expected=%d, seq=%d, splitflag=%d)\n",
2007 in->sequence,arcsoft->sequence,
2008 arcsoft->split_flag);
2009 kfree_skb(in->skb,FREE_WRITE);
2010 in->skb=NULL;
2011 lp->stats.tx_dropped++;
2012 lp->stats.rx_fifo_errors++;
2013 in->lastpacket=in->numpackets=0;
2014 }
2015
2016 if (arcsoft->split_flag & 1) /* first packet in split */
2017 {
2018 BUGLVL(D_RX) printk("arcnet: brand new splitpacket (splitflag=%d)\n",
2019 arcsoft->split_flag);
2020 if (in->skb) /* already assembling one! */
2021 {
2022 BUGLVL(D_EXTRA) printk("arcnet: aborting previous (seq=%d) assembly (splitflag=%d, seq=%d)\n",
2023 in->sequence,arcsoft->split_flag,
2024 arcsoft->sequence);
2025 lp->stats.tx_dropped++;
2026 lp->stats.rx_over_errors++;
2027 kfree_skb(in->skb,FREE_WRITE);
2028 }
2029
2030 in->sequence=arcsoft->sequence;
2031 in->numpackets=((unsigned)arcsoft->split_flag>>1)+2;
2032 in->lastpacket=1;
2033
2034 if (in->numpackets>16)
2035 {
2036 BUGLVL(D_EXTRA) printk("arcnet: incoming packet more than 16 segments; dropping. (splitflag=%d)\n",
2037 arcsoft->split_flag);
2038 lp->stats.rx_dropped++;
2039 return;
2040 }
2041
2042 in->skb=skb=alloc_skb(508*in->numpackets
2043 + sizeof(struct ClientData),
2044 GFP_ATOMIC);
2045 if (skb == NULL) {
2046 printk("%s: (split) memory squeeze, dropping packet.\n",
2047 dev->name);
2048 lp->stats.rx_dropped++;
2049 return;
2050 }
2051
2052 /* I don't know what this is for, but it DOES avoid
2053 * warnings...
2054 */
2055 skb->free=1;
2056
2057 soft=(struct ClientData *)skb->data;
2058
2059 skb->len=sizeof(struct ClientData);
2060 skb->dev=dev;
2061
2062 memcpy((u_char *)soft+EXTRA_CLIENTDATA,
2063 (u_char *)arcsoft+EXTRA_CLIENTDATA,
2064 sizeof(struct ClientData)-EXTRA_CLIENTDATA);
2065 soft->split_flag=0; /* final packet won't be split */
2066 }
2067 else /* not first packet */
2068 {
2069 int packetnum=((unsigned)arcsoft->split_flag>>1) + 1;
2070
2071 /* if we're not assembling, there's no point
2072 * trying to continue.
2073 */
2074 if (!in->skb)
2075 {
2076 BUGLVL(D_EXTRA) printk("arcnet: can't continue split without starting first! (splitflag=%d, seq=%d)\n",
2077 arcsoft->split_flag,arcsoft->sequence);
2078 lp->stats.rx_errors++;
2079 return;
2080 }
2081
2082 in->lastpacket++;
2083 if (packetnum!=in->lastpacket) /* not the right flag! */
2084 {
2085 /* harmless duplicate? ignore. */
2086 if (packetnum<=in->lastpacket-1)
2087 {
2088 BUGLVL(D_EXTRA) printk("arcnet: duplicate splitpacket ignored! (splitflag=%d)\n",
2089 arcsoft->split_flag);
2090 return;
2091 }
2092
2093 /* "bad" duplicate, kill reassembly */
2094 BUGLVL(D_EXTRA) printk("arcnet: out-of-order splitpacket, reassembly (seq=%d) aborted (splitflag=%d, seq=%d)\n",
2095 in->sequence,arcsoft->split_flag,
2096 arcsoft->sequence);
2097 kfree_skb(in->skb,FREE_WRITE);
2098 in->skb=NULL;
2099 lp->stats.tx_dropped++;
2100 lp->stats.rx_fifo_errors++;
2101 in->lastpacket=in->numpackets=0;
2102 return;
2103 }
2104
2105 soft=(struct ClientData *)in->skb->data;
2106 }
2107
2108 skb=in->skb;
2109
2110 memcpy(skb->data+skb->len,
2111 (u_char *)arcsoft+sizeof(struct ClientData),
2112 length-sizeof(struct ClientData));
2113
2114 skb->len+=length-sizeof(struct ClientData);
2115
2116 soft->daddr=daddr;
2117 soft->saddr=saddr;
2118
2119 /* are we done? */
2120 if (in->lastpacket == in->numpackets)
2121 {
2122 if (!skb || !in->skb)
2123 printk("arcnet: ?!? done reassembling packet, no skb? (skb=%ph, in->skb=%ph)\n",
2124 skb,in->skb);
2125 in->skb=NULL;
2126 in->lastpacket=in->numpackets=0;
2127
2128 BUGLVL(D_SKB)
2129 {
2130 short i;
2131 for( i=0; i< skb->len; i++)
2132 {
2133 if( i%16 == 0 ) printk("\n[%04hX] ",i);
2134 printk("%02hX ",((unsigned char*)skb->data)[i]);
2135 }
2136 printk("\n");
2137 }
2138
2139 skb->protocol=arcnetA_type_trans(skb,dev);
2140
2141 netif_rx(skb);
2142 lp->stats.rx_packets++;
2143 }
2144 }
2145 }
2146
2147
2148 /* Packet receiver for non-standard Windows-style packets
2149 */
2150 static void
2151 arcnetW_rx(struct device *dev,u_char *arcsoft,
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
2152 int length,u_char saddr, u_char daddr)
2153 {
2154 struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
2155 struct sk_buff *skb;
2156
2157 BUGLVL(D_DURING)
2158 printk("arcnet: it's a Windows packet (length=%d)\n",
2159 length);
2160
2161 skb = alloc_skb(length, GFP_ATOMIC);
2162 if (skb == NULL) {
2163 printk("arcnet: Memory squeeze, dropping packet.\n");
2164 lp->stats.rx_dropped++;
2165 return;
2166 }
2167
2168 skb->len = length;
2169 skb->dev = lp->wdev;
2170
2171 memcpy(skb->data,(u_char *)arcsoft+1,length-1);
2172
2173 BUGLVL(D_SKB)
2174 {
2175 short i;
2176 printk("arcnet: rx skb dump follows:\n");
2177 for(i=0; i<skb->len; i++)
2178 {
2179 if (i%16==0)
2180 printk("\n[%04hX] ",i);
2181 else
2182 printk("%02hX ",((u_char *)skb->data)[i]);
2183 }
2184 printk("\n");
2185 }
2186
2187 skb->protocol=eth_type_trans(skb,dev);
2188
2189 netif_rx(skb);
2190 lp->stats.rx_packets++;
2191 }
2192
2193
2194 /****************************************************************************
2195 * *
2196 * Miscellaneous routines *
2197 * *
2198 ****************************************************************************/
2199
2200
2201 /* Get the current statistics. This may be called with the card open or
2202 * closed.
2203 */
2204
2205 static struct enet_statistics *
2206 arcnet_get_stats(struct device *dev)
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
2207 {
2208 struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
2209
2210 return &lp->stats;
2211 }
2212
2213 /* Set or clear the multicast filter for this adaptor.
2214 * num_addrs == -1 Promiscuous mode, receive all packets
2215 * num_addrs == 0 Normal mode, clear multicast list
2216 * num_addrs > 0 Multicast mode, receive normal and MC packets, and do
2217 * best-effort filtering.
2218 */
2219 static void
2220 set_multicast_list(struct device *dev, int num_addrs, void *addrs)
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
2221 {
2222 #if 0 /* no promiscuous mode at all on most ARCnet models */
2223 struct arcnet_local *lp=(struct arcnet_local *)(dev->priv);
2224
2225 short ioaddr = dev->base_addr;
2226 if (num_addrs) {
2227 outw(69, ioaddr); /* Enable promiscuous mode */
2228 } else
2229 outw(99, ioaddr); /* Disable promiscuous mode, use normal mode */
2230 #endif
2231 }
2232
2233 /* Create the ARCnet ClientData header for an arbitrary protocol layer
2234 *
2235 * saddr=NULL means use device source address (always will anyway)
2236 * daddr=NULL means leave destination address (eg unresolved arp)
2237 */
2238 int arcnetA_header(struct sk_buff *skb,struct device *dev,unsigned short type,
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
2239 void *daddr,void *saddr,unsigned len)
2240 {
2241 struct ClientData *head = (struct ClientData *)
2242 skb_push(skb,dev->hard_header_len);
2243 /* struct arcnet_local *lp=(struct arcnet_local *)(dev->priv);*/
2244
2245 /* set the protocol ID according to RFC-1201 */
2246 switch(type)
2247 {
2248 case ETH_P_IP:
2249 head->protocol_id=ARC_P_IP;
2250 break;
2251 case ETH_P_ARP:
2252 head->protocol_id=ARC_P_ARP;
2253 break;
2254 case ETH_P_RARP:
2255 head->protocol_id=ARC_P_RARP;
2256 break;
2257 case ETH_P_IPX:
2258 head->protocol_id=ARC_P_IPX;
2259 break;
2260 case ETH_P_ATALK:
2261 head->protocol_id=ARC_P_ATALK;
2262 break;
2263 default:
2264 printk("arcnet: I don't understand protocol %d (%Xh)\n",
2265 type,type);
2266 return 0;
2267 }
2268
2269 /*
2270 * Set the source hardware address.
2271 *
2272 * This is pretty pointless for most purposes, but it can help
2273 * in debugging. saddr is stored in the ClientData header and
2274 * removed before sending the packet (since ARCnet does not allow
2275 * us to change the source address in the actual packet sent)
2276 */
2277 if(saddr)
2278 head->saddr=((u_char*)saddr)[0];
2279 else
2280 head->saddr=((u_char*)(dev->dev_addr))[0];
2281
2282 #if 0
2283 /*
2284 * Anyway, the loopback-device should never use this function...
2285 *
2286 * And the chances of it using the ARCnet version of it are so
2287 * tiny that I don't think we have to worry :)
2288 */
2289 if (dev->flags & IFF_LOOPBACK)
2290 {
2291 head->daddr=0;
2292 return(dev->hard_header_len);
2293 }
2294 #endif
2295
2296 head->split_flag=0; /* split packets are done elsewhere */
2297 head->sequence=0; /* so are sequence numbers */
2298
2299 /* supposedly if daddr is NULL, we should ignore it... */
2300 if(daddr)
2301 {
2302 head->daddr=((u_char*)daddr)[0];
2303 return dev->hard_header_len;
2304 }
2305 else
2306 head->daddr=0; /* better fill one in anyway */
2307
2308 return -dev->hard_header_len;
2309 }
2310
2311
2312 /* Rebuild the ARCnet ClientData header. This is called after an ARP
2313 * (or in future other address resolution) has completed on this
2314 * sk_buff. We now let ARP fill in the other fields.
2315 */
2316 int arcnetA_rebuild_header(void *buff,struct device *dev,unsigned long dst,
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
2317 struct sk_buff *skb)
2318 {
2319 struct ClientData *head = (struct ClientData *)buff;
2320
2321 /*
2322 * Only ARP and IP are currently supported
2323 */
2324
2325 if(head->protocol_id != ARC_P_IP)
2326 {
2327 printk("arcnet: I don't understand resolve type %d (%Xh) addresses!\n",
2328 head->protocol_id,head->protocol_id);
2329 head->daddr=0;
2330 /*memcpy(eth->h_source, dev->dev_addr, dev->addr_len);*/
2331 return 0;
2332 }
2333
2334 /*
2335 * Try and get ARP to resolve the header.
2336 */
2337 #ifdef CONFIG_INET
2338 return arp_find(&(head->daddr), dst, dev, dev->pa_addr, skb)? 1 : 0;
2339 #else
2340 return 0;
2341 #endif
2342 }
2343
2344 /* Determine a packet's protocol ID.
2345 *
2346 * With ARCnet we have to convert everything to Ethernet-style stuff.
2347 */
2348 unsigned short arcnetA_type_trans(struct sk_buff *skb,struct device *dev)
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
2349 {
2350 struct ClientData *head = (struct ClientData *) skb->data;
2351 struct arcnet_local *lp=(struct arcnet_local *) (dev->priv);
2352
2353 /* Pull off the arcnet header. */
2354 skb->mac.raw=skb->data;
2355 skb_pull(skb,dev->hard_header_len);
2356
2357 if (head->daddr==0)
2358 skb->pkt_type=PACKET_BROADCAST;
2359 else if (dev->flags&IFF_PROMISC)
2360 {
2361 /* if we're not sending to ourselves :) */
2362 if (head->daddr != dev->dev_addr[0])
2363 skb->pkt_type=PACKET_OTHERHOST;
2364 }
2365
2366 /* now return the protocol number */
2367 switch (head->protocol_id)
2368 {
2369 case ARC_P_IP: return htons(ETH_P_IP);
2370 case ARC_P_ARP: return htons(ETH_P_ARP);
2371 case ARC_P_RARP: return htons(ETH_P_RARP);
2372 case ARC_P_IPX: return htons(ETH_P_IPX);
2373 case ARC_P_ATALK: return htons(ETH_P_ATALK); /* untested appletalk */
2374 case ARC_P_LANSOFT: /* don't understand. fall through. */
2375 default:
2376 BUGLVL(D_EXTRA)
2377 printk("arcnet: received packet of unknown protocol id %d (%Xh)\n",
2378 head->protocol_id,head->protocol_id);
2379 lp->stats.rx_frame_errors++;
2380 return 0;
2381 }
2382
2383 return htons(ETH_P_IP);
2384 }
2385
2386
2387
2388 /****************************************************************************
2389 * *
2390 * Kernel Loadable Module Support *
2391 * *
2392 ****************************************************************************/
2393
2394
2395 #ifdef MODULE
2396 char kernel_version[] = UTS_RELEASE;
2397 static struct device thiscard = {
2398 " ",/* if blank, device name inserted by /linux/drivers/net/net_init.c */
2399 0, 0, 0, 0,
2400 0, 0, /* I/O address, IRQ */
2401 0, 0, 0, NULL, arcnet_probe };
2402
2403
2404 int io=0x0; /* <--- EDIT THESE LINES FOR YOUR CONFIGURATION */
2405 int irqnum=0; /* or use the insmod io= irqnum= shmem= options */
2406 int shmem=0;
2407 int num=0; /* number of device (ie for 0 for arc0, 1 for arc1...) */
2408
2409 int
2410 init_module(void)
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
2411 {
2412 sprintf(thiscard.name,"arc%d",num);
2413
2414 thiscard.base_addr=io;
2415
2416 thiscard.irq=irqnum;
2417 if (thiscard.irq==2) thiscard.irq=9;
2418
2419 if (shmem)
2420 {
2421 thiscard.mem_start=shmem;
2422 thiscard.mem_end=thiscard.mem_start+512*4-1;
2423 thiscard.rmem_start=thiscard.mem_start+512*0;
2424 thiscard.rmem_end=thiscard.mem_start+512*2-1;
2425 }
2426
2427 if (register_netdev(&thiscard) != 0)
2428 return -EIO;
2429 return 0;
2430 }
2431
2432 void
2433 cleanup_module(void)
/* ![[previous]](../icons/left.png)
![[next]](../icons/n_right.png)
![[first]](../icons/first.png)
![[last]](../icons/n_last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
2434 {
2435 if (MOD_IN_USE)
2436 {
2437 printk("%s: device busy, remove delayed\n",thiscard.name);
2438 }
2439 else
2440 {
2441 if (thiscard.start) arcnet_close(&thiscard);
2442 if (thiscard.irq) free_irq(thiscard.irq);
2443 if (thiscard.base_addr) release_region(thiscard.base_addr,
2444 ARCNET_TOTAL_SIZE);
2445 unregister_netdev(&thiscard);
2446 }
2447 }
2448
2449 #endif /* MODULE */
2450
2451
2452
2453 /*
2454 * Local variables:
2455 * compile-command: "gcc -D__KERNEL__ -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O6 -m486 -c arcnet.c"
2456 * version-control: t
2457 * kept-new-versions: 5
2458 * tab-width: 8
2459 * End:
2460 */
2461