Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2)  * Linux ARCnet driver - device-independent routines
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  * Written 1997 by David Woodhouse.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  * Written 1994-1999 by Avery Pennarun.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  * Written 1999-2000 by Martin Mares <mj@ucw.cz>.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)  * Derived from skeleton.c by Donald Becker.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9)  * Special thanks to Contemporary Controls, Inc. (www.ccontrols.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10)  *  for sponsoring the further development of this driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12)  * **********************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14)  * The original copyright was as follows:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16)  * skeleton.c Written 1993 by Donald Becker.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17)  * Copyright 1993 United States Government as represented by the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18)  * Director, National Security Agency.  This software may only be used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19)  * and distributed according to the terms of the GNU General Public License as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20)  * modified by SRC, incorporated herein by reference.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22)  * **********************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24)  * The change log is now in a file called ChangeLog in this directory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26)  * Sources:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27)  *  - Crynwr arcnet.com/arcether.com packet drivers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28)  *  - arcnet.c v0.00 dated 1/1/94 and apparently by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29)  *     Donald Becker - it didn't work :)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30)  *  - skeleton.c v0.05 dated 11/16/93 by Donald Becker
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31)  *     (from Linux Kernel 1.1.45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32)  *  - RFC's 1201 and 1051 - re: TCP/IP over ARCnet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33)  *  - The official ARCnet COM9026 data sheets (!) thanks to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34)  *     Ken Cornetet <kcornete@nyx10.cs.du.edu>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35)  *  - The official ARCnet COM20020 data sheets.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36)  *  - Information on some more obscure ARCnet controller chips, thanks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37)  *     to the nice people at SMSC.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38)  *  - net/inet/eth.c (from kernel 1.1.50) for header-building info.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39)  *  - Alternate Linux ARCnet source by V.Shergin <vsher@sao.stavropol.su>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40)  *  - Textual information and more alternate source from Joachim Koenig
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41)  *     <jojo@repas.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) #include <linux/if_arp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) #include <net/arp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) #include <linux/jiffies.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) #include <linux/errqueue.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) #include <linux/leds.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) #include "arcdevice.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) #include "com9026.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) /* "do nothing" functions for protocol drivers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) static void null_rx(struct net_device *dev, int bufnum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) 		    struct archdr *pkthdr, int length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) static int null_build_header(struct sk_buff *skb, struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) 			     unsigned short type, uint8_t daddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) static int null_prepare_tx(struct net_device *dev, struct archdr *pkt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) 			   int length, int bufnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) static void arcnet_rx(struct net_device *dev, int bufnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) /* one ArcProto per possible proto ID.  None of the elements of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72)  * arc_proto_map are allowed to be NULL; they will get set to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73)  * arc_proto_default instead.  It also must not be NULL; if you would like
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74)  * to set it to NULL, set it to &arc_proto_null instead.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) struct ArcProto *arc_proto_map[256];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) EXPORT_SYMBOL(arc_proto_map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) struct ArcProto *arc_proto_default;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) EXPORT_SYMBOL(arc_proto_default);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) struct ArcProto *arc_bcast_proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) EXPORT_SYMBOL(arc_bcast_proto);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) struct ArcProto *arc_raw_proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) EXPORT_SYMBOL(arc_raw_proto);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) static struct ArcProto arc_proto_null = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) 	.suffix		= '?',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) 	.mtu		= XMTU,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) 	.is_ip          = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) 	.rx		= null_rx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) 	.build_header	= null_build_header,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) 	.prepare_tx	= null_prepare_tx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) 	.continue_tx    = NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) 	.ack_tx         = NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) /* Exported function prototypes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) int arcnet_debug = ARCNET_DEBUG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) EXPORT_SYMBOL(arcnet_debug);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) /* Internal function prototypes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) static int arcnet_header(struct sk_buff *skb, struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) 			 unsigned short type, const void *daddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) 			 const void *saddr, unsigned len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) static int go_tx(struct net_device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) static int debug = ARCNET_DEBUG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) module_param(debug, int, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) static int __init arcnet_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) 	int count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) 	arcnet_debug = debug;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) 	pr_info("arcnet loaded\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) 	/* initialize the protocol map */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) 	arc_raw_proto = arc_proto_default = arc_bcast_proto = &arc_proto_null;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) 	for (count = 0; count < 256; count++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) 		arc_proto_map[count] = arc_proto_default;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) 	if (BUGLVL(D_DURING))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) 		pr_info("struct sizes: %zd %zd %zd %zd %zd\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) 			sizeof(struct arc_hardware),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) 			sizeof(struct arc_rfc1201),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) 			sizeof(struct arc_rfc1051),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) 			sizeof(struct arc_eth_encap),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) 			sizeof(struct archdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) static void __exit arcnet_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) module_init(arcnet_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) module_exit(arcnet_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) /* Dump the contents of an sk_buff */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) #if ARCNET_DEBUG_MAX & D_SKB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) void arcnet_dump_skb(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 		     struct sk_buff *skb, char *desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 	char hdr[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 	/* dump the packet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 	snprintf(hdr, sizeof(hdr), "%6s:%s skb->data:", dev->name, desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 	print_hex_dump(KERN_DEBUG, hdr, DUMP_PREFIX_OFFSET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 		       16, 1, skb->data, skb->len, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) EXPORT_SYMBOL(arcnet_dump_skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) /* Dump the contents of an ARCnet buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) #if (ARCNET_DEBUG_MAX & (D_RX | D_TX))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) static void arcnet_dump_packet(struct net_device *dev, int bufnum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) 			       char *desc, int take_arcnet_lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) 	struct arcnet_local *lp = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) 	int i, length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 	unsigned long flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) 	static uint8_t buf[512];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) 	char hdr[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) 	/* hw.copy_from_card expects IRQ context so take the IRQ lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) 	 * to keep it single threaded
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) 	if (take_arcnet_lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 		spin_lock_irqsave(&lp->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 	lp->hw.copy_from_card(dev, bufnum, 0, buf, 512);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 	if (take_arcnet_lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 		spin_unlock_irqrestore(&lp->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) 	/* if the offset[0] byte is nonzero, this is a 256-byte packet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 	length = (buf[2] ? 256 : 512);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 	/* dump the packet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 	snprintf(hdr, sizeof(hdr), "%6s:%s packet dump:", dev->name, desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) 	print_hex_dump(KERN_DEBUG, hdr, DUMP_PREFIX_OFFSET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 		       16, 1, buf, length, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) #define arcnet_dump_packet(dev, bufnum, desc, take_arcnet_lock) do { } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) /* Trigger a LED event in response to a ARCNET device event */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) void arcnet_led_event(struct net_device *dev, enum arcnet_led_event event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 	struct arcnet_local *lp = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) 	unsigned long led_delay = 350;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 	unsigned long tx_delay = 50;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 	switch (event) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 	case ARCNET_LED_EVENT_RECON:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 		led_trigger_blink_oneshot(lp->recon_led_trig,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 					  &led_delay, &led_delay, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) 	case ARCNET_LED_EVENT_OPEN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 		led_trigger_event(lp->tx_led_trig, LED_OFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 		led_trigger_event(lp->recon_led_trig, LED_OFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 	case ARCNET_LED_EVENT_STOP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 		led_trigger_event(lp->tx_led_trig, LED_OFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 		led_trigger_event(lp->recon_led_trig, LED_OFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 	case ARCNET_LED_EVENT_TX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 		led_trigger_blink_oneshot(lp->tx_led_trig,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 					  &tx_delay, &tx_delay, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) EXPORT_SYMBOL_GPL(arcnet_led_event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) static void arcnet_led_release(struct device *gendev, void *res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 	struct arcnet_local *lp = netdev_priv(to_net_dev(gendev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 	led_trigger_unregister_simple(lp->tx_led_trig);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 	led_trigger_unregister_simple(lp->recon_led_trig);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) /* Register ARCNET LED triggers for a arcnet device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233)  * This is normally called from a driver's probe function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) void devm_arcnet_led_init(struct net_device *netdev, int index, int subid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 	struct arcnet_local *lp = netdev_priv(netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 	void *res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 	res = devres_alloc(arcnet_led_release, 0, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 	if (!res) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 		netdev_err(netdev, "cannot register LED triggers\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 	snprintf(lp->tx_led_trig_name, sizeof(lp->tx_led_trig_name),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 		 "arc%d-%d-tx", index, subid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 	snprintf(lp->recon_led_trig_name, sizeof(lp->recon_led_trig_name),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 		 "arc%d-%d-recon", index, subid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 	led_trigger_register_simple(lp->tx_led_trig_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 				    &lp->tx_led_trig);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 	led_trigger_register_simple(lp->recon_led_trig_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 				    &lp->recon_led_trig);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 	devres_add(&netdev->dev, res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) EXPORT_SYMBOL_GPL(devm_arcnet_led_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) /* Unregister a protocol driver from the arc_proto_map.  Protocol drivers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261)  * are responsible for registering themselves, but the unregister routine
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262)  * is pretty generic so we'll do it here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) void arcnet_unregister_proto(struct ArcProto *proto)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 	int count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 	if (arc_proto_default == proto)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 		arc_proto_default = &arc_proto_null;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 	if (arc_bcast_proto == proto)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 		arc_bcast_proto = arc_proto_default;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 	if (arc_raw_proto == proto)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 		arc_raw_proto = arc_proto_default;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 	for (count = 0; count < 256; count++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 		if (arc_proto_map[count] == proto)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 			arc_proto_map[count] = arc_proto_default;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) EXPORT_SYMBOL(arcnet_unregister_proto);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) /* Add a buffer to the queue.  Only the interrupt handler is allowed to do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283)  * this, unless interrupts are disabled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285)  * Note: we don't check for a full queue, since there aren't enough buffers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286)  * to more than fill it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) static void release_arcbuf(struct net_device *dev, int bufnum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 	struct arcnet_local *lp = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 	lp->buf_queue[lp->first_free_buf++] = bufnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 	lp->first_free_buf %= 5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 	if (BUGLVL(D_DURING)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 		arc_printk(D_DURING, dev, "release_arcbuf: freed #%d; buffer queue is now: ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 			   bufnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 		for (i = lp->next_buf; i != lp->first_free_buf; i = (i + 1) % 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 			arc_cont(D_DURING, "#%d ", lp->buf_queue[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 		arc_cont(D_DURING, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) /* Get a buffer from the queue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306)  * If this returns -1, there are no buffers available.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) static int get_arcbuf(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 	struct arcnet_local *lp = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 	int buf = -1, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 	if (!atomic_dec_and_test(&lp->buf_lock)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 		/* already in this function */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 		arc_printk(D_NORMAL, dev, "get_arcbuf: overlap (%d)!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 			   lp->buf_lock.counter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 	} else {			/* we can continue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 		if (lp->next_buf >= 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 			lp->next_buf -= 5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 		if (lp->next_buf == lp->first_free_buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 			arc_printk(D_NORMAL, dev, "get_arcbuf: BUG: no buffers are available??\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 			buf = lp->buf_queue[lp->next_buf++];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 			lp->next_buf %= 5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 	if (BUGLVL(D_DURING)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 		arc_printk(D_DURING, dev, "get_arcbuf: got #%d; buffer queue is now: ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 			   buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 		for (i = lp->next_buf; i != lp->first_free_buf; i = (i + 1) % 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 			arc_cont(D_DURING, "#%d ", lp->buf_queue[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 		arc_cont(D_DURING, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 	atomic_inc(&lp->buf_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 	return buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) static int choose_mtu(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 	int count, mtu = 65535;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 	/* choose the smallest MTU of all available encaps */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 	for (count = 0; count < 256; count++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 		if (arc_proto_map[count] != &arc_proto_null &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 		    arc_proto_map[count]->mtu < mtu) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 			mtu = arc_proto_map[count]->mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 	return mtu == 65535 ? XMTU : mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) static const struct header_ops arcnet_header_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 	.create = arcnet_header,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) static const struct net_device_ops arcnet_netdev_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 	.ndo_open	= arcnet_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 	.ndo_stop	= arcnet_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 	.ndo_start_xmit = arcnet_send_packet,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 	.ndo_tx_timeout = arcnet_timeout,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) /* Setup a struct device for ARCnet. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) static void arcdev_setup(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 	dev->type = ARPHRD_ARCNET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 	dev->netdev_ops = &arcnet_netdev_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 	dev->header_ops = &arcnet_header_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 	dev->hard_header_len = sizeof(struct arc_hardware);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 	dev->mtu = choose_mtu();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 	dev->addr_len = ARCNET_ALEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 	dev->tx_queue_len = 100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 	dev->broadcast[0] = 0x00;	/* for us, broadcasts are address 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 	dev->watchdog_timeo = TX_TIMEOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 	/* New-style flags. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 	dev->flags = IFF_BROADCAST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) static void arcnet_timer(struct timer_list *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 	struct arcnet_local *lp = from_timer(lp, t, timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 	struct net_device *dev = lp->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 	if (!netif_carrier_ok(dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 		netif_carrier_on(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 		netdev_info(dev, "link up\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) static void arcnet_reply_tasklet(unsigned long data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 	struct arcnet_local *lp = (struct arcnet_local *)data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 	struct sk_buff *ackskb, *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 	struct sock_exterr_skb *serr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 	struct sock *sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 	local_irq_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 	skb = lp->outgoing.skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 	if (!skb || !skb->sk) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 		local_irq_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 	sock_hold(skb->sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 	sk = skb->sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 	ackskb = skb_clone_sk(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 	sock_put(skb->sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 	if (!ackskb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 		local_irq_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 	serr = SKB_EXT_ERR(ackskb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 	memset(serr, 0, sizeof(*serr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 	serr->ee.ee_errno = ENOMSG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 	serr->ee.ee_origin = SO_EE_ORIGIN_TXSTATUS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 	serr->ee.ee_data = skb_shinfo(skb)->tskey;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 	serr->ee.ee_info = lp->reply_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 	/* finally erasing outgoing skb */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 	dev_kfree_skb(lp->outgoing.skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 	lp->outgoing.skb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 	ackskb->dev = lp->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 	ret = sock_queue_err_skb(sk, ackskb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 		kfree_skb(ackskb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 	local_irq_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) struct net_device *alloc_arcdev(const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 	struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 	dev = alloc_netdev(sizeof(struct arcnet_local),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 			   name && *name ? name : "arc%d", NET_NAME_UNKNOWN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 			   arcdev_setup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 	if (dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 		struct arcnet_local *lp = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 		lp->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 		spin_lock_init(&lp->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 		timer_setup(&lp->timer, arcnet_timer, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 	return dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) EXPORT_SYMBOL(alloc_arcdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) /* Open/initialize the board.  This is called sometime after booting when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462)  * the 'ifconfig' program is run.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464)  * This routine should set everything up anew at each open, even registers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465)  * that "should" only need to be set once at boot, so that there is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466)  * non-reboot way to recover if something goes wrong.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) int arcnet_open(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 	struct arcnet_local *lp = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 	int count, newmtu, error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 	arc_printk(D_INIT, dev, "opened.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 	if (!try_module_get(lp->hw.owner))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 	if (BUGLVL(D_PROTO)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 		arc_printk(D_PROTO, dev, "protocol map (default is '%c'): ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 			   arc_proto_default->suffix);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 		for (count = 0; count < 256; count++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 			arc_cont(D_PROTO, "%c", arc_proto_map[count]->suffix);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 		arc_cont(D_PROTO, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 	tasklet_init(&lp->reply_tasklet, arcnet_reply_tasklet,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 		     (unsigned long)lp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 	arc_printk(D_INIT, dev, "arcnet_open: resetting card.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 	/* try to put the card in a defined state - if it fails the first
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 	 * time, actually reset it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 	error = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 	if (lp->hw.reset(dev, 0) && lp->hw.reset(dev, 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 		goto out_module_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 	newmtu = choose_mtu();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 	if (newmtu < dev->mtu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 		dev->mtu = newmtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 	arc_printk(D_INIT, dev, "arcnet_open: mtu: %d.\n", dev->mtu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 	/* autodetect the encapsulation for each host. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 	memset(lp->default_proto, 0, sizeof(lp->default_proto));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 	/* the broadcast address is special - use the 'bcast' protocol */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 	for (count = 0; count < 256; count++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 		if (arc_proto_map[count] == arc_bcast_proto) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 			lp->default_proto[0] = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 	/* initialize buffers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 	atomic_set(&lp->buf_lock, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 	lp->next_buf = lp->first_free_buf = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 	release_arcbuf(dev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 	release_arcbuf(dev, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 	release_arcbuf(dev, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 	release_arcbuf(dev, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 	lp->cur_tx = lp->next_tx = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 	lp->cur_rx = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 	lp->rfc1201.sequence = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 	/* bring up the hardware driver */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 	if (lp->hw.open)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 		lp->hw.open(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 	if (dev->dev_addr[0] == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) 		arc_printk(D_NORMAL, dev, "WARNING!  Station address 00 is reserved for broadcasts!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 	else if (dev->dev_addr[0] == 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 		arc_printk(D_NORMAL, dev, "WARNING!  Station address FF may confuse DOS networking programs!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 	arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 	if (lp->hw.status(dev) & RESETflag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 		arc_printk(D_DEBUG, dev, "%s: %d: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 			   __FILE__, __LINE__, __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 		lp->hw.command(dev, CFLAGScmd | RESETclear);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 	arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 	/* make sure we're ready to receive IRQ's. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 	lp->hw.intmask(dev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 	udelay(1);		/* give it time to set the mask before
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 				 * we reset it again. (may not even be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 				 * necessary)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 	arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 	lp->intmask = NORXflag | RECONflag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 	lp->hw.intmask(dev, lp->intmask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 	arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 	netif_carrier_off(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 	netif_start_queue(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 	mod_timer(&lp->timer, jiffies + msecs_to_jiffies(1000));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 	arcnet_led_event(dev, ARCNET_LED_EVENT_OPEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563)  out_module_put:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 	module_put(lp->hw.owner);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) EXPORT_SYMBOL(arcnet_open);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) /* The inverse routine to arcnet_open - shuts down the card. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) int arcnet_close(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 	struct arcnet_local *lp = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 	arcnet_led_event(dev, ARCNET_LED_EVENT_STOP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 	del_timer_sync(&lp->timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 	netif_stop_queue(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 	netif_carrier_off(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 	tasklet_kill(&lp->reply_tasklet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 	/* flush TX and disable RX */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 	lp->hw.intmask(dev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 	lp->hw.command(dev, NOTXcmd);	/* stop transmit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 	lp->hw.command(dev, NORXcmd);	/* disable receive */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 	mdelay(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 	/* shut down the card */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 	lp->hw.close(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 	module_put(lp->hw.owner);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) EXPORT_SYMBOL(arcnet_close);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) static int arcnet_header(struct sk_buff *skb, struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 			 unsigned short type, const void *daddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 			 const void *saddr, unsigned len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 	const struct arcnet_local *lp = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 	uint8_t _daddr, proto_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 	struct ArcProto *proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 	arc_printk(D_DURING, dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 		   "create header from %d to %d; protocol %d (%Xh); size %u.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 		   saddr ? *(uint8_t *)saddr : -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 		   daddr ? *(uint8_t *)daddr : -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 		   type, type, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 	if (skb->len != 0 && len != skb->len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 		arc_printk(D_NORMAL, dev, "arcnet_header: Yikes!  skb->len(%d) != len(%d)!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 			   skb->len, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 	/* Type is host order - ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 	if (type == ETH_P_ARCNET) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 		proto = arc_raw_proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 		arc_printk(D_DEBUG, dev, "arc_raw_proto used. proto='%c'\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 			   proto->suffix);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 		_daddr = daddr ? *(uint8_t *)daddr : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 	} else if (!daddr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 		/* if the dest addr isn't provided, we can't choose an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 		 * encapsulation!  Store the packet type (eg. ETH_P_IP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 		 * for now, and we'll push on a real header when we do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 		 * rebuild_header.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 		*(uint16_t *)skb_push(skb, 2) = type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 		/* XXX: Why not use skb->mac_len? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 		if (skb->network_header - skb->mac_header != 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 			arc_printk(D_NORMAL, dev, "arcnet_header: Yikes!  diff (%u) is not 2!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 				   skb->network_header - skb->mac_header);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 		return -2;	/* return error -- can't transmit yet! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 		/* otherwise, we can just add the header as usual. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 		_daddr = *(uint8_t *)daddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 		proto_num = lp->default_proto[_daddr];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 		proto = arc_proto_map[proto_num];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 		arc_printk(D_DURING, dev, "building header for %02Xh using protocol '%c'\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 			   proto_num, proto->suffix);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 		if (proto == &arc_proto_null && arc_bcast_proto != proto) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 			arc_printk(D_DURING, dev, "actually, let's use '%c' instead.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 				   arc_bcast_proto->suffix);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 			proto = arc_bcast_proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 	return proto->build_header(skb, dev, type, _daddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) /* Called by the kernel in order to transmit a packet. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) netdev_tx_t arcnet_send_packet(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 			       struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 	struct arcnet_local *lp = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 	struct archdr *pkt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 	struct arc_rfc1201 *soft;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 	struct ArcProto *proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 	int txbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 	int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 	arc_printk(D_DURING, dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 		   "transmit requested (status=%Xh, txbufs=%d/%d, len=%d, protocol %x)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 		   lp->hw.status(dev), lp->cur_tx, lp->next_tx, skb->len, skb->protocol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 	pkt = (struct archdr *)skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 	soft = &pkt->soft.rfc1201;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 	proto = arc_proto_map[soft->proto];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 	arc_printk(D_SKB_SIZE, dev, "skb: transmitting %d bytes to %02X\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 		   skb->len, pkt->hard.dest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 	if (BUGLVL(D_SKB))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 		arcnet_dump_skb(dev, skb, "tx");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 	/* fits in one packet? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 	if (skb->len - ARC_HDR_SIZE > XMTU && !proto->continue_tx) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 		arc_printk(D_NORMAL, dev, "fixme: packet too large: compensating badly!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 		dev_kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 		return NETDEV_TX_OK;	/* don't try again */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 	/* We're busy transmitting a packet... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 	netif_stop_queue(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 	spin_lock_irqsave(&lp->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 	lp->hw.intmask(dev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 	if (lp->next_tx == -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 		txbuf = get_arcbuf(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 		txbuf = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 	if (txbuf != -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 		lp->outgoing.skb = skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 		if (proto->prepare_tx(dev, pkt, skb->len, txbuf) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 		    !proto->ack_tx) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 			/* done right away and we don't want to acknowledge
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 			 *  the package later - forget about it now
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 			dev->stats.tx_bytes += skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 			/* do it the 'split' way */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 			lp->outgoing.proto = proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 			lp->outgoing.skb = skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 			lp->outgoing.pkt = pkt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 			if (proto->continue_tx &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 			    proto->continue_tx(dev, txbuf)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 				arc_printk(D_NORMAL, dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 					   "bug! continue_tx finished the first time! (proto='%c')\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 					   proto->suffix);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 		retval = NETDEV_TX_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 		lp->next_tx = txbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 		retval = NETDEV_TX_BUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 	arc_printk(D_DEBUG, dev, "%s: %d: %s, status: %x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 		   __FILE__, __LINE__, __func__, lp->hw.status(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 	/* make sure we didn't ignore a TX IRQ while we were in here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 	lp->hw.intmask(dev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 	arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 	lp->intmask |= TXFREEflag | EXCNAKflag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 	lp->hw.intmask(dev, lp->intmask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 	arc_printk(D_DEBUG, dev, "%s: %d: %s, status: %x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 		   __FILE__, __LINE__, __func__, lp->hw.status(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 	arcnet_led_event(dev, ARCNET_LED_EVENT_TX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 	spin_unlock_irqrestore(&lp->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 	return retval;		/* no need to try again */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) EXPORT_SYMBOL(arcnet_send_packet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) /* Actually start transmitting a packet that was loaded into a buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735)  * by prepare_tx.  This should _only_ be called by the interrupt handler.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) static int go_tx(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 	struct arcnet_local *lp = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 	arc_printk(D_DURING, dev, "go_tx: status=%Xh, intmask=%Xh, next_tx=%d, cur_tx=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 		   lp->hw.status(dev), lp->intmask, lp->next_tx, lp->cur_tx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 	if (lp->cur_tx != -1 || lp->next_tx == -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 	if (BUGLVL(D_TX))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 		arcnet_dump_packet(dev, lp->next_tx, "go_tx", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 	lp->cur_tx = lp->next_tx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 	lp->next_tx = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 	/* start sending */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 	lp->hw.command(dev, TXcmd | (lp->cur_tx << 3));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 	dev->stats.tx_packets++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 	lp->lasttrans_dest = lp->lastload_dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 	lp->lastload_dest = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 	lp->excnak_pending = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 	lp->intmask |= TXFREEflag | EXCNAKflag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) /* Called by the kernel when transmit times out */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) void arcnet_timeout(struct net_device *dev, unsigned int txqueue)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 	struct arcnet_local *lp = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 	int status = lp->hw.status(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 	char *msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 	spin_lock_irqsave(&lp->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 	if (status & TXFREEflag) {	/* transmit _DID_ finish */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 		msg = " - missed IRQ?";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 		msg = "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 		dev->stats.tx_aborted_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 		lp->timed_out = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 		lp->hw.command(dev, NOTXcmd | (lp->cur_tx << 3));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 	dev->stats.tx_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 	/* make sure we didn't miss a TX or a EXC NAK IRQ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 	lp->hw.intmask(dev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 	lp->intmask |= TXFREEflag | EXCNAKflag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 	lp->hw.intmask(dev, lp->intmask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 	spin_unlock_irqrestore(&lp->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 	if (time_after(jiffies, lp->last_timeout + 10 * HZ)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 		arc_printk(D_EXTRA, dev, "tx timed out%s (status=%Xh, intmask=%Xh, dest=%02Xh)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 			   msg, status, lp->intmask, lp->lasttrans_dest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 		lp->last_timeout = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 	if (lp->cur_tx == -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 		netif_wake_queue(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) EXPORT_SYMBOL(arcnet_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) /* The typical workload of the driver: Handle the network interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803)  * interrupts. Establish which device needs attention, and call the correct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804)  * chipset interrupt handler.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) irqreturn_t arcnet_interrupt(int irq, void *dev_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 	struct net_device *dev = dev_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 	struct arcnet_local *lp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 	int recbuf, status, diagstatus, didsomething, boguscount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 	int retval = IRQ_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 	arc_printk(D_DURING, dev, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 	arc_printk(D_DURING, dev, "in arcnet_interrupt\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 	lp = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 	BUG_ON(!lp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 	spin_lock_irqsave(&lp->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 	/* RESET flag was enabled - if device is not running, we must
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 	 * clear it right away (but nothing else).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 	if (!netif_running(dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 		if (lp->hw.status(dev) & RESETflag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 			lp->hw.command(dev, CFLAGScmd | RESETclear);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 		lp->hw.intmask(dev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 		spin_unlock_irqrestore(&lp->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 		return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 	arc_printk(D_DURING, dev, "in arcnet_inthandler (status=%Xh, intmask=%Xh)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 		   lp->hw.status(dev), lp->intmask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 	boguscount = 5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 		status = lp->hw.status(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 		diagstatus = (status >> 8) & 0xFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 		arc_printk(D_DEBUG, dev, "%s: %d: %s: status=%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 			   __FILE__, __LINE__, __func__, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 		didsomething = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 		/* RESET flag was enabled - card is resetting and if RX is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 		 * disabled, it's NOT because we just got a packet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 		 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 		 * The card is in an undefined state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 		 * Clear it out and start over.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 		if (status & RESETflag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 			arc_printk(D_NORMAL, dev, "spurious reset (status=%Xh)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 				   status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 			arcnet_close(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 			arcnet_open(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 			/* get out of the interrupt handler! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 		/* RX is inhibited - we must have received something.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 		 * Prepare to receive into the next buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 		 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 		 * We don't actually copy the received packet from the card
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 		 * until after the transmit handler runs (and possibly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 		 * launches the next tx); this should improve latency slightly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 		 * if we get both types of interrupts at once.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 		recbuf = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 		if (status & lp->intmask & NORXflag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 			recbuf = lp->cur_rx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 			arc_printk(D_DURING, dev, "Buffer #%d: receive irq (status=%Xh)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 				   recbuf, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 			lp->cur_rx = get_arcbuf(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 			if (lp->cur_rx != -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 				arc_printk(D_DURING, dev, "enabling receive to buffer #%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 					   lp->cur_rx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 				lp->hw.command(dev, RXcmd | (lp->cur_rx << 3) | RXbcasts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 			didsomething++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 		if ((diagstatus & EXCNAKflag)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 			arc_printk(D_DURING, dev, "EXCNAK IRQ (diagstat=%Xh)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 				   diagstatus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 			lp->hw.command(dev, NOTXcmd);      /* disable transmit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 			lp->excnak_pending = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 			lp->hw.command(dev, EXCNAKclear);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 			lp->intmask &= ~(EXCNAKflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 			didsomething++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 		/* a transmit finished, and we're interested in it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 		if ((status & lp->intmask & TXFREEflag) || lp->timed_out) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 			int ackstatus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 			lp->intmask &= ~(TXFREEflag | EXCNAKflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 			if (status & TXACKflag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 				ackstatus = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 			else if (lp->excnak_pending)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 				ackstatus = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 				ackstatus = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 			arc_printk(D_DURING, dev, "TX IRQ (stat=%Xh)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 				   status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 			if (lp->cur_tx != -1 && !lp->timed_out) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 				if (!(status & TXACKflag)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 					if (lp->lasttrans_dest != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 						arc_printk(D_EXTRA, dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 							   "transmit was not acknowledged! (status=%Xh, dest=%02Xh)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 							   status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 							   lp->lasttrans_dest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 						dev->stats.tx_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 						dev->stats.tx_carrier_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 					} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 						arc_printk(D_DURING, dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 							   "broadcast was not acknowledged; that's normal (status=%Xh, dest=%02Xh)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 							   status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 							   lp->lasttrans_dest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 				if (lp->outgoing.proto &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 				    lp->outgoing.proto->ack_tx) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 					lp->outgoing.proto
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 						->ack_tx(dev, ackstatus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 				lp->reply_status = ackstatus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 				tasklet_hi_schedule(&lp->reply_tasklet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 			if (lp->cur_tx != -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 				release_arcbuf(dev, lp->cur_tx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 			lp->cur_tx = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 			lp->timed_out = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 			didsomething++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 			/* send another packet if there is one */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 			go_tx(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 			/* continue a split packet, if any */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 			if (lp->outgoing.proto &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 			    lp->outgoing.proto->continue_tx) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 				int txbuf = get_arcbuf(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 				if (txbuf != -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 					if (lp->outgoing.proto->continue_tx(dev, txbuf)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 						/* that was the last segment */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 						dev->stats.tx_bytes += lp->outgoing.skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 						if (!lp->outgoing.proto->ack_tx) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 							dev_kfree_skb_irq(lp->outgoing.skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 							lp->outgoing.proto = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 						}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 					lp->next_tx = txbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 			/* inform upper layers of idleness, if necessary */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 			if (lp->cur_tx == -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 				netif_wake_queue(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 		/* now process the received packet, if any */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 		if (recbuf != -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 			if (BUGLVL(D_RX))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 				arcnet_dump_packet(dev, recbuf, "rx irq", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 			arcnet_rx(dev, recbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 			release_arcbuf(dev, recbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 			didsomething++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 		if (status & lp->intmask & RECONflag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 			lp->hw.command(dev, CFLAGScmd | CONFIGclear);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 			dev->stats.tx_carrier_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 			arc_printk(D_RECON, dev, "Network reconfiguration detected (status=%Xh)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 				   status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 			if (netif_carrier_ok(dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 				netif_carrier_off(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 				netdev_info(dev, "link down\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 			mod_timer(&lp->timer, jiffies + msecs_to_jiffies(1000));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 			arcnet_led_event(dev, ARCNET_LED_EVENT_RECON);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 			/* MYRECON bit is at bit 7 of diagstatus */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 			if (diagstatus & 0x80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 				arc_printk(D_RECON, dev, "Put out that recon myself\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 			/* is the RECON info empty or old? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 			if (!lp->first_recon || !lp->last_recon ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 			    time_after(jiffies, lp->last_recon + HZ * 10)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 				if (lp->network_down)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 					arc_printk(D_NORMAL, dev, "reconfiguration detected: cabling restored?\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 				lp->first_recon = lp->last_recon = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 				lp->num_recons = lp->network_down = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 				arc_printk(D_DURING, dev, "recon: clearing counters.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 			} else {	/* add to current RECON counter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 				lp->last_recon = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 				lp->num_recons++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 				arc_printk(D_DURING, dev, "recon: counter=%d, time=%lds, net=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 					   lp->num_recons,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 					   (lp->last_recon - lp->first_recon) / HZ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 					   lp->network_down);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 				/* if network is marked up;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 				 * and first_recon and last_recon are 60+ apart;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 				 * and the average no. of recons counted is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 				 *    > RECON_THRESHOLD/min;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 				 * then print a warning message.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 				if (!lp->network_down &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 				    (lp->last_recon - lp->first_recon) <= HZ * 60 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 				    lp->num_recons >= RECON_THRESHOLD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 					lp->network_down = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 					arc_printk(D_NORMAL, dev, "many reconfigurations detected: cabling problem?\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 				} else if (!lp->network_down &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 					   lp->last_recon - lp->first_recon > HZ * 60) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 					/* reset counters if we've gone for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 					 *  over a minute.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 					 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 					lp->first_recon = lp->last_recon;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 					lp->num_recons = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 		} else if (lp->network_down &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 			   time_after(jiffies, lp->last_recon + HZ * 10)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 			if (lp->network_down)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 				arc_printk(D_NORMAL, dev, "cabling restored?\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 			lp->first_recon = lp->last_recon = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 			lp->num_recons = lp->network_down = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 			arc_printk(D_DURING, dev, "not recon: clearing counters anyway.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 			netif_carrier_on(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 		if (didsomething)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 			retval |= IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 	} while (--boguscount && didsomething);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 	arc_printk(D_DURING, dev, "arcnet_interrupt complete (status=%Xh, count=%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 		   lp->hw.status(dev), boguscount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 	arc_printk(D_DURING, dev, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 	lp->hw.intmask(dev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 	udelay(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 	lp->hw.intmask(dev, lp->intmask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 	spin_unlock_irqrestore(&lp->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) EXPORT_SYMBOL(arcnet_interrupt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) /* This is a generic packet receiver that calls arcnet??_rx depending on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061)  * protocol ID found.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) static void arcnet_rx(struct net_device *dev, int bufnum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 	struct arcnet_local *lp = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 	union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 		struct archdr pkt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 		char buf[512];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 	} rxdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 	struct arc_rfc1201 *soft;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 	int length, ofs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 	soft = &rxdata.pkt.soft.rfc1201;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 	lp->hw.copy_from_card(dev, bufnum, 0, &rxdata.pkt, ARC_HDR_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 	if (rxdata.pkt.hard.offset[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 		ofs = rxdata.pkt.hard.offset[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 		length = 256 - ofs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 		ofs = rxdata.pkt.hard.offset[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 		length = 512 - ofs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 	/* get the full header, if possible */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 	if (sizeof(rxdata.pkt.soft) <= length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 		lp->hw.copy_from_card(dev, bufnum, ofs, soft, sizeof(rxdata.pkt.soft));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 		memset(&rxdata.pkt.soft, 0, sizeof(rxdata.pkt.soft));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 		lp->hw.copy_from_card(dev, bufnum, ofs, soft, length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 	arc_printk(D_DURING, dev, "Buffer #%d: received packet from %02Xh to %02Xh (%d+4 bytes)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) 		   bufnum, rxdata.pkt.hard.source, rxdata.pkt.hard.dest, length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 	dev->stats.rx_packets++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 	dev->stats.rx_bytes += length + ARC_HDR_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 	/* call the right receiver for the protocol */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) 	if (arc_proto_map[soft->proto]->is_ip) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 		if (BUGLVL(D_PROTO)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 			struct ArcProto
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 			*oldp = arc_proto_map[lp->default_proto[rxdata.pkt.hard.source]],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 			*newp = arc_proto_map[soft->proto];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 			if (oldp != newp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 				arc_printk(D_PROTO, dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 					   "got protocol %02Xh; encap for host %02Xh is now '%c' (was '%c')\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 					   soft->proto, rxdata.pkt.hard.source,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 					   newp->suffix, oldp->suffix);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 		/* broadcasts will always be done with the last-used encap. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 		lp->default_proto[0] = soft->proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 		/* in striking contrast, the following isn't a hack. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 		lp->default_proto[rxdata.pkt.hard.source] = soft->proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 	/* call the protocol-specific receiver. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) 	arc_proto_map[soft->proto]->rx(dev, bufnum, &rxdata.pkt, length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) static void null_rx(struct net_device *dev, int bufnum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) 		    struct archdr *pkthdr, int length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) 	arc_printk(D_PROTO, dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) 		   "rx: don't know how to deal with proto %02Xh from host %02Xh.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) 		   pkthdr->soft.rfc1201.proto, pkthdr->hard.source);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) static int null_build_header(struct sk_buff *skb, struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 			     unsigned short type, uint8_t daddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 	struct arcnet_local *lp = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 	arc_printk(D_PROTO, dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 		   "tx: can't build header for encap %02Xh; load a protocol driver.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 		   lp->default_proto[daddr]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 	/* always fails */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) /* the "do nothing" prepare_tx function warns that there's nothing to do. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) static int null_prepare_tx(struct net_device *dev, struct archdr *pkt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) 			   int length, int bufnum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) 	struct arcnet_local *lp = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) 	struct arc_hardware newpkt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) 	arc_printk(D_PROTO, dev, "tx: no encap for this host; load a protocol driver.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) 	/* send a packet to myself -- will never get received, of course */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) 	newpkt.source = newpkt.dest = dev->dev_addr[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) 	/* only one byte of actual data (and it's random) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) 	newpkt.offset[0] = 0xFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) 	lp->hw.copy_to_card(dev, bufnum, 0, &newpkt, ARC_HDR_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) 	return 1;		/* done */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) }