Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003  * INET         An implementation of the TCP/IP protocol suite for the LINUX
0004  *              operating system.  NET  is implemented using the  BSD Socket
0005  *              interface as the means of communication with the user level.
0006  *
0007  *              Definitions used by the ARCnet driver.
0008  *
0009  * Authors:     Avery Pennarun and David Woodhouse
0010  */
0011 #ifndef _LINUX_ARCDEVICE_H
0012 #define _LINUX_ARCDEVICE_H
0013 
0014 #include <asm/timex.h>
0015 #include <linux/if_arcnet.h>
0016 
0017 #ifdef __KERNEL__
0018 #include <linux/interrupt.h>
0019 
0020 /*
0021  * RECON_THRESHOLD is the maximum number of RECON messages to receive
0022  * within one minute before printing a "cabling problem" warning. The
0023  * default value should be fine.
0024  *
0025  * After that, a "cabling restored" message will be printed on the next IRQ
0026  * if no RECON messages have been received for 10 seconds.
0027  *
0028  * Do not define RECON_THRESHOLD at all if you want to disable this feature.
0029  */
0030 #define RECON_THRESHOLD 30
0031 
0032 /*
0033  * Define this to the minimum "timeout" value.  If a transmit takes longer
0034  * than TX_TIMEOUT jiffies, Linux will abort the TX and retry.  On a large
0035  * network, or one with heavy network traffic, this timeout may need to be
0036  * increased.  The larger it is, though, the longer it will be between
0037  * necessary transmits - don't set this too high.
0038  */
0039 #define TX_TIMEOUT (HZ * 200 / 1000)
0040 
0041 /* Display warnings about the driver being an ALPHA version. */
0042 #undef ALPHA_WARNING
0043 
0044 /*
0045  * Debugging bitflags: each option can be enabled individually.
0046  *
0047  * Note: only debug flags included in the ARCNET_DEBUG_MAX define will
0048  *   actually be available.  GCC will (at least, GCC 2.7.0 will) notice
0049  *   lines using a BUGLVL not in ARCNET_DEBUG_MAX and automatically optimize
0050  *   them out.
0051  */
0052 #define D_NORMAL    1   /* important operational info             */
0053 #define D_EXTRA     2   /* useful, but non-vital information      */
0054 #define D_INIT      4   /* show init/probe messages               */
0055 #define D_INIT_REASONS  8   /* show reasons for discarding probes     */
0056 #define D_RECON     32  /* print a message whenever token is lost */
0057 #define D_PROTO     64  /* debug auto-protocol support            */
0058 /* debug levels below give LOTS of output during normal operation! */
0059 #define D_DURING    128 /* trace operations (including irq's)     */
0060 #define D_TX            256 /* show tx packets                        */
0061 #define D_RX        512 /* show rx packets                        */
0062 #define D_SKB       1024    /* show skb's                             */
0063 #define D_SKB_SIZE  2048    /* show skb sizes             */
0064 #define D_TIMING    4096    /* show time needed to copy buffers to card */
0065 #define D_DEBUG         8192    /* Very detailed debug line for line */
0066 
0067 #ifndef ARCNET_DEBUG_MAX
0068 #define ARCNET_DEBUG_MAX (127)  /* change to ~0 if you want detailed debugging */
0069 #endif
0070 
0071 #ifndef ARCNET_DEBUG
0072 #define ARCNET_DEBUG (D_NORMAL | D_EXTRA)
0073 #endif
0074 extern int arcnet_debug;
0075 
0076 #define BUGLVL(x)   ((x) & ARCNET_DEBUG_MAX & arcnet_debug)
0077 
0078 /* macros to simplify debug checking */
0079 #define arc_printk(x, dev, fmt, ...)                    \
0080 do {                                    \
0081     if (BUGLVL(x)) {                        \
0082         if ((x) == D_NORMAL)                    \
0083             netdev_warn(dev, fmt, ##__VA_ARGS__);       \
0084         else if ((x) < D_DURING)                \
0085             netdev_info(dev, fmt, ##__VA_ARGS__);       \
0086         else                            \
0087             netdev_dbg(dev, fmt, ##__VA_ARGS__);        \
0088     }                               \
0089 } while (0)
0090 
0091 #define arc_cont(x, fmt, ...)                       \
0092 do {                                    \
0093     if (BUGLVL(x))                          \
0094         pr_cont(fmt, ##__VA_ARGS__);                \
0095 } while (0)
0096 
0097 /* see how long a function call takes to run, expressed in CPU cycles */
0098 #define TIME(dev, name, bytes, call)                    \
0099 do {                                    \
0100     if (BUGLVL(D_TIMING)) {                     \
0101         unsigned long _x, _y;                   \
0102         _x = get_cycles();                  \
0103         call;                           \
0104         _y = get_cycles();                  \
0105         arc_printk(D_TIMING, dev,               \
0106                "%s: %d bytes in %lu cycles == %lu Kbytes/100Mcycle\n", \
0107                name, bytes, _y - _x,            \
0108                100000000 / 1024 * bytes / (_y - _x + 1));   \
0109     } else {                            \
0110         call;                           \
0111     }                               \
0112 } while (0)
0113 
0114 /*
0115  * Time needed to reset the card - in ms (milliseconds).  This works on my
0116  * SMC PC100.  I can't find a reference that tells me just how long I
0117  * should wait.
0118  */
0119 #define RESETtime (300)
0120 
0121 /*
0122  * These are the max/min lengths of packet payload, not including the
0123  * arc_hardware header, but definitely including the soft header.
0124  *
0125  * Note: packet sizes 254, 255, 256 are impossible because of the way
0126  * ARCnet registers work  That's why RFC1201 defines "exception" packets.
0127  * In non-RFC1201 protocols, we have to just tack some extra bytes on the
0128  * end.
0129  */
0130 #define MTU 253     /* normal packet max size */
0131 #define MinTU   257     /* extended packet min size */
0132 #define XMTU    508     /* extended packet max size */
0133 
0134 /* status/interrupt mask bit fields */
0135 #define TXFREEflag  0x01    /* transmitter available */
0136 #define TXACKflag       0x02    /* transmitted msg. ackd */
0137 #define RECONflag       0x04    /* network reconfigured */
0138 #define TESTflag        0x08    /* test flag */
0139 #define EXCNAKflag      0x08    /* excesive nak flag */
0140 #define RESETflag       0x10    /* power-on-reset */
0141 #define RES1flag        0x20    /* reserved - usually set by jumper */
0142 #define RES2flag        0x40    /* reserved - usually set by jumper */
0143 #define NORXflag        0x80    /* receiver inhibited */
0144 
0145 /* Flags used for IO-mapped memory operations */
0146 #define AUTOINCflag     0x40    /* Increase location with each access */
0147 #define IOMAPflag       0x02    /* (for 90xx) Use IO mapped memory, not mmap */
0148 #define ENABLE16flag    0x80    /* (for 90xx) Enable 16-bit mode */
0149 
0150 /* in the command register, the following bits have these meanings:
0151  *                0-2     command
0152  *                3-4     page number (for enable rcv/xmt command)
0153  *                 7      receive broadcasts
0154  */
0155 #define NOTXcmd         0x01    /* disable transmitter */
0156 #define NORXcmd         0x02    /* disable receiver */
0157 #define TXcmd           0x03    /* enable transmitter */
0158 #define RXcmd           0x04    /* enable receiver */
0159 #define CONFIGcmd       0x05    /* define configuration */
0160 #define CFLAGScmd       0x06    /* clear flags */
0161 #define TESTcmd         0x07    /* load test flags */
0162 #define STARTIOcmd      0x18    /* start internal operation */
0163 
0164 /* flags for "clear flags" command */
0165 #define RESETclear      0x08    /* power-on-reset */
0166 #define CONFIGclear     0x10    /* system reconfigured */
0167 
0168 #define EXCNAKclear     0x0E    /* Clear and acknowledge the excive nak bit */
0169 
0170 /* flags for "load test flags" command */
0171 #define TESTload        0x08    /* test flag (diagnostic) */
0172 
0173 /* byte deposited into first address of buffers on reset */
0174 #define TESTvalue       0321    /* that's octal for 0xD1 :) */
0175 
0176 /* for "enable receiver" command */
0177 #define RXbcasts        0x80    /* receive broadcasts */
0178 
0179 /* flags for "define configuration" command */
0180 #define NORMALconf      0x00    /* 1-249 byte packets */
0181 #define EXTconf         0x08    /* 250-504 byte packets */
0182 
0183 /* card feature flags, set during auto-detection.
0184  * (currently only used by com20020pci)
0185  */
0186 #define ARC_IS_5MBIT    1   /* card default speed is 5MBit */
0187 #define ARC_CAN_10MBIT  2   /* card uses COM20022, supporting 10MBit,
0188                  but default is 2.5MBit. */
0189 
0190 /* information needed to define an encapsulation driver */
0191 struct ArcProto {
0192     char suffix;        /* a for RFC1201, e for ether-encap, etc. */
0193     int mtu;        /* largest possible packet */
0194     int is_ip;              /* This is a ip plugin - not a raw thing */
0195 
0196     void (*rx)(struct net_device *dev, int bufnum,
0197            struct archdr *pkthdr, int length);
0198     int (*build_header)(struct sk_buff *skb, struct net_device *dev,
0199                 unsigned short ethproto, uint8_t daddr);
0200 
0201     /* these functions return '1' if the skb can now be freed */
0202     int (*prepare_tx)(struct net_device *dev, struct archdr *pkt,
0203               int length, int bufnum);
0204     int (*continue_tx)(struct net_device *dev, int bufnum);
0205     int (*ack_tx)(struct net_device *dev, int acked);
0206 };
0207 
0208 extern struct ArcProto *arc_proto_map[256], *arc_proto_default,
0209     *arc_bcast_proto, *arc_raw_proto;
0210 
0211 /*
0212  * "Incoming" is information needed for each address that could be sending
0213  * to us.  Mostly for partially-received split packets.
0214  */
0215 struct Incoming {
0216     struct sk_buff *skb;    /* packet data buffer             */
0217     __be16 sequence;    /* sequence number of assembly    */
0218     uint8_t lastpacket, /* number of last packet (from 1) */
0219         numpackets; /* number of packets in split     */
0220 };
0221 
0222 /* only needed for RFC1201 */
0223 struct Outgoing {
0224     struct ArcProto *proto; /* protocol driver that owns this:
0225                  *   if NULL, no packet is pending.
0226                  */
0227     struct sk_buff *skb;    /* buffer from upper levels */
0228     struct archdr *pkt; /* a pointer into the skb */
0229     uint16_t length,    /* bytes total */
0230         dataleft,   /* bytes left */
0231         segnum,     /* segment being sent */
0232         numsegs;    /* number of segments */
0233 };
0234 
0235 #define ARCNET_LED_NAME_SZ (IFNAMSIZ + 6)
0236 
0237 struct arcnet_local {
0238     uint8_t config,     /* current value of CONFIG register */
0239         timeout,    /* Extended timeout for COM20020 */
0240         backplane,  /* Backplane flag for COM20020 */
0241         clockp,     /* COM20020 clock divider */
0242         clockm,     /* COM20020 clock multiplier flag */
0243         setup,      /* Contents of setup1 register */
0244         setup2,     /* Contents of setup2 register */
0245         intmask;    /* current value of INTMASK register */
0246     uint8_t default_proto[256]; /* default encap to use for each host */
0247     int cur_tx,     /* buffer used by current transmit, or -1 */
0248         next_tx,    /* buffer where a packet is ready to send */
0249         cur_rx;     /* current receive buffer */
0250     int lastload_dest,  /* can last loaded packet be acked? */
0251         lasttrans_dest; /* can last TX'd packet be acked? */
0252     int timed_out;  /* need to process TX timeout and drop packet */
0253     unsigned long last_timeout; /* time of last reported timeout */
0254     char *card_name;    /* card ident string */
0255     int card_flags;     /* special card features */
0256 
0257     /* On preemtive and SMB a lock is needed */
0258     spinlock_t lock;
0259 
0260     struct led_trigger *tx_led_trig;
0261     char tx_led_trig_name[ARCNET_LED_NAME_SZ];
0262     struct led_trigger *recon_led_trig;
0263     char recon_led_trig_name[ARCNET_LED_NAME_SZ];
0264 
0265     struct timer_list   timer;
0266 
0267     struct net_device *dev;
0268     int reply_status;
0269     struct tasklet_struct reply_tasklet;
0270 
0271     /*
0272      * Buffer management: an ARCnet card has 4 x 512-byte buffers, each of
0273      * which can be used for either sending or receiving.  The new dynamic
0274      * buffer management routines use a simple circular queue of available
0275      * buffers, and take them as they're needed.  This way, we simplify
0276      * situations in which we (for example) want to pre-load a transmit
0277      * buffer, or start receiving while we copy a received packet to
0278      * memory.
0279      *
0280      * The rules: only the interrupt handler is allowed to _add_ buffers to
0281      * the queue; thus, this doesn't require a lock.  Both the interrupt
0282      * handler and the transmit function will want to _remove_ buffers, so
0283      * we need to handle the situation where they try to do it at the same
0284      * time.
0285      *
0286      * If next_buf == first_free_buf, the queue is empty.  Since there are
0287      * only four possible buffers, the queue should never be full.
0288      */
0289     atomic_t buf_lock;
0290     int buf_queue[5];
0291     int next_buf, first_free_buf;
0292 
0293     /* network "reconfiguration" handling */
0294     unsigned long first_recon; /* time of "first" RECON message to count */
0295     unsigned long last_recon;  /* time of most recent RECON */
0296     int num_recons;     /* number of RECONs between first and last. */
0297     int network_down;   /* do we think the network is down? */
0298 
0299     int excnak_pending;    /* We just got an excesive nak interrupt */
0300 
0301     /* RESET flag handling */
0302     int reset_in_progress;
0303     struct work_struct reset_work;
0304 
0305     struct {
0306         uint16_t sequence;  /* sequence number (incs with each packet) */
0307         __be16 aborted_seq;
0308 
0309         struct Incoming incoming[256];  /* one from each address */
0310     } rfc1201;
0311 
0312     /* really only used by rfc1201, but we'll pretend it's not */
0313     struct Outgoing outgoing;   /* packet currently being sent */
0314 
0315     /* hardware-specific functions */
0316     struct {
0317         struct module *owner;
0318         void (*command)(struct net_device *dev, int cmd);
0319         int (*status)(struct net_device *dev);
0320         void (*intmask)(struct net_device *dev, int mask);
0321         int (*reset)(struct net_device *dev, int really_reset);
0322         void (*open)(struct net_device *dev);
0323         void (*close)(struct net_device *dev);
0324         void (*datatrigger) (struct net_device * dev, int enable);
0325         void (*recontrigger) (struct net_device * dev, int enable);
0326 
0327         void (*copy_to_card)(struct net_device *dev, int bufnum,
0328                      int offset, void *buf, int count);
0329         void (*copy_from_card)(struct net_device *dev, int bufnum,
0330                        int offset, void *buf, int count);
0331     } hw;
0332 
0333     void __iomem *mem_start;    /* pointer to ioremap'ed MMIO */
0334 };
0335 
0336 enum arcnet_led_event {
0337     ARCNET_LED_EVENT_RECON,
0338     ARCNET_LED_EVENT_OPEN,
0339     ARCNET_LED_EVENT_STOP,
0340     ARCNET_LED_EVENT_TX,
0341 };
0342 
0343 void arcnet_led_event(struct net_device *netdev, enum arcnet_led_event event);
0344 void devm_arcnet_led_init(struct net_device *netdev, int index, int subid);
0345 
0346 #if ARCNET_DEBUG_MAX & D_SKB
0347 void arcnet_dump_skb(struct net_device *dev, struct sk_buff *skb, char *desc);
0348 #else
0349 static inline
0350 void arcnet_dump_skb(struct net_device *dev, struct sk_buff *skb, char *desc)
0351 {
0352 }
0353 #endif
0354 
0355 void arcnet_unregister_proto(struct ArcProto *proto);
0356 irqreturn_t arcnet_interrupt(int irq, void *dev_id);
0357 
0358 struct net_device *alloc_arcdev(const char *name);
0359 void free_arcdev(struct net_device *dev);
0360 
0361 int arcnet_open(struct net_device *dev);
0362 int arcnet_close(struct net_device *dev);
0363 netdev_tx_t arcnet_send_packet(struct sk_buff *skb,
0364                    struct net_device *dev);
0365 void arcnet_timeout(struct net_device *dev, unsigned int txqueue);
0366 
0367 static inline void arcnet_set_addr(struct net_device *dev, u8 addr)
0368 {
0369     dev_addr_set(dev, &addr);
0370 }
0371 
0372 /* I/O equivalents */
0373 
0374 #ifdef CONFIG_SA1100_CT6001
0375 #define BUS_ALIGN  2  /* 8 bit device on a 16 bit bus - needs padding */
0376 #else
0377 #define BUS_ALIGN  1
0378 #endif
0379 
0380 /* addr and offset allow register like names to define the actual IO  address.
0381  * A configuration option multiplies the offset for alignment.
0382  */
0383 #define arcnet_inb(addr, offset)                    \
0384     inb((addr) + BUS_ALIGN * (offset))
0385 #define arcnet_outb(value, addr, offset)                \
0386     outb(value, (addr) + BUS_ALIGN * (offset))
0387 
0388 #define arcnet_insb(addr, offset, buffer, count)            \
0389     insb((addr) + BUS_ALIGN * (offset), buffer, count)
0390 #define arcnet_outsb(addr, offset, buffer, count)           \
0391     outsb((addr) + BUS_ALIGN * (offset), buffer, count)
0392 
0393 #define arcnet_readb(addr, offset)                  \
0394     readb((addr) + (offset))
0395 #define arcnet_writeb(value, addr, offset)              \
0396     writeb(value, (addr) + (offset))
0397 
0398 #endif              /* __KERNEL__ */
0399 #endif              /* _LINUX_ARCDEVICE_H */