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