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