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