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