Subversion Repositories shark

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 pj 1
/* Generic NS8390 register definitions. */
2
/* This file is part of Donald Becker's 8390 drivers, and is distributed
3
   under the same license. Auto-loading of 8390.o added by Paul Gortmaker.
4
   Some of these names and comments originated from the Crynwr
5
   packet drivers, which are distributed under the GPL. */
6
 
7
#ifndef _8390_h
8
#define _8390_h
9
 
10
#include <linux/config.h>
11
#include <linux/if_ether.h>
12
#include <linux/ioport.h>
13
#include <linux/skbuff.h>
14
 
15
/* With kmod, drivers can now load the 8390 module themselves! */
16
#if 0 /* def CONFIG_KMOD */
17
#define LOAD_8390_BY_KMOD
18
#endif
19
 
20
#define TX_2X_PAGES 12
21
#define TX_1X_PAGES 6
22
 
23
/* Should always use two Tx slots to get back-to-back transmits. */
24
#define EI_PINGPONG
25
 
26
#ifdef EI_PINGPONG
27
#define TX_PAGES TX_2X_PAGES
28
#else
29
#define TX_PAGES TX_1X_PAGES
30
#endif
31
 
32
#define ETHER_ADDR_LEN 6
33
 
34
/* The 8390 specific per-packet-header format. */
35
struct e8390_pkt_hdr {
36
  unsigned char status; /* status */
37
  unsigned char next;   /* pointer to next packet. */
38
  unsigned short count; /* header + packet length in bytes */
39
};
40
 
41
#ifdef notdef
42
extern int ei_debug;
43
#else
44
#define ei_debug 1
45
#endif
46
 
47
#ifndef HAVE_AUTOIRQ
48
/* From auto_irq.c */
49
extern void autoirq_setup(int waittime);
50
extern unsigned long autoirq_report(int waittime);
51
#endif
52
 
53
#if defined(LOAD_8390_BY_KMOD) && defined(MODULE) && !defined(NS8390_CORE)
54
 
55
/* Function pointers to be mapped onto the 8390 core support */
56
static int (*S_ethdev_init)(struct device *dev);
57
static void (*S_NS8390_init)(struct device *dev, int startp);
58
static int (*S_ei_open)(struct device *dev);
59
static int (*S_ei_close)(struct device *dev);
60
static void (*S_ei_interrupt)(int irq, void *dev_id, struct pt_regs *regs);
61
 
62
 
63
#define NS8390_KSYSMS_PRESENT   (                       \
64
        get_module_symbol(NULL, "ethdev_init") != 0 &&  \
65
        get_module_symbol(NULL, "NS8390_init") != 0 &&  \
66
        get_module_symbol(NULL, "ei_open") != 0 &&      \
67
        get_module_symbol(NULL, "ei_close") != 0 &&     \
68
        get_module_symbol(NULL, "ei_interrupt") != 0)
69
 
70
extern __inline__ int load_8390_module(const char *driver)
71
{
72
 
73
        if (! NS8390_KSYSMS_PRESENT) {
74
                int (*request_mod)(const char *module_name);
75
 
76
                if (get_module_symbol("", "request_module") == 0) {
77
                        printk("%s: module auto-load (kmod) support not present.\n", driver);
78
                        printk("%s: unable to auto-load required 8390 module.\n", driver);
79
                        printk("%s: try \"modprobe 8390\" as root 1st.\n", driver);
80
                        return -ENOSYS;
81
                }
82
 
83
                request_mod = (void*)get_module_symbol("", "request_module");
84
                if (request_mod("8390")) {
85
                        printk("%s: request to load the 8390 module failed.\n", driver);
86
                        return -ENOSYS;
87
                }
88
 
89
                /* Check if module really loaded and is valid */
90
                if (! NS8390_KSYSMS_PRESENT) {
91
                        printk("%s: 8390.o not found/invalid or failed to load.\n", driver);
92
                        return -ENOSYS;
93
                }
94
 
95
                printk(KERN_INFO "%s: auto-loaded 8390 module.\n", driver);
96
        }
97
 
98
        /* Map the functions into place */
99
        S_ethdev_init = (void*)get_module_symbol(0, "ethdev_init");
100
        S_NS8390_init = (void*)get_module_symbol(0, "NS8390_init");
101
        S_ei_open = (void*)get_module_symbol(0, "ei_open");
102
        S_ei_close = (void*)get_module_symbol(0, "ei_close");
103
        S_ei_interrupt = (void*)get_module_symbol(0, "ei_interrupt");
104
 
105
        return 0;
106
}
107
 
108
/*
109
 * Since a kmod aware driver won't explicitly show a dependence on the
110
 * exported 8390 functions (due to the mapping above), the 8390 module
111
 * (if present, and not in-kernel) needs to be protected from garbage
112
 * collection.  NS8390_module is only defined for a modular 8390 core.
113
 */
114
 
115
extern __inline__  void lock_8390_module(void)
116
{
117
        struct module **mod = (struct module**)get_module_symbol(0, "NS8390_module");
118
 
119
        if (mod != NULL && *mod != NULL)
120
                __MOD_INC_USE_COUNT(*mod);
121
}
122
 
123
extern __inline__  void unlock_8390_module(void)
124
{
125
        struct module **mod = (struct module**)get_module_symbol(0, "NS8390_module");
126
 
127
        if (mod != NULL && *mod != NULL)
128
                __MOD_DEC_USE_COUNT(*mod);
129
}
130
 
131
/*
132
 * These are last so they only have scope over the driver
133
 * code (wd, ne, 3c503, etc.)  and not over the above code.
134
 */
135
#define ethdev_init S_ethdev_init
136
#define NS8390_init S_NS8390_init
137
#define ei_open S_ei_open
138
#define ei_close S_ei_close
139
#define ei_interrupt S_ei_interrupt
140
 
141
#else   /* not a module or kmod support not wanted */
142
 
143
#define load_8390_module(driver)        0
144
#define lock_8390_module()              do { } while (0)
145
#define unlock_8390_module()            do { } while (0)
146
extern int ethdev_init(struct device *dev);
147
extern void NS8390_init(struct device *dev, int startp);
148
extern int ei_open(struct device *dev);
149
extern int ei_close(struct device *dev);
150
extern void ei_interrupt(int irq, void *dev_id, struct pt_regs *regs);
151
 
152
#endif
153
 
154
/* Most of these entries should be in 'struct device' (or most of the
155
   things in there should be here!) */
156
/* You have one of these per-board */
157
struct ei_device {
158
        const char *name;
159
        void (*reset_8390)(struct device *);
160
        void (*get_8390_hdr)(struct device *, struct e8390_pkt_hdr *, int);
161
        void (*block_output)(struct device *, int, const unsigned char *, int);
162
        void (*block_input)(struct device *, int, struct sk_buff *, int);
163
        unsigned char mcfilter[8];
164
        unsigned open:1;
165
        unsigned word16:1;              /* We have the 16-bit (vs 8-bit) version of the card. */
166
        unsigned txing:1;               /* Transmit Active */
167
        unsigned irqlock:1;             /* 8390's intrs disabled when '1'. */
168
        unsigned dmaing:1;              /* Remote DMA Active */
169
        unsigned char tx_start_page, rx_start_page, stop_page;
170
        unsigned char current_page;     /* Read pointer in buffer  */
171
        unsigned char interface_num;    /* Net port (AUI, 10bT.) to use. */
172
        unsigned char txqueue;          /* Tx Packet buffer queue length. */
173
        short tx1, tx2;                 /* Packet lengths for ping-pong tx. */
174
        short lasttx;                   /* Alpha version consistency check. */
175
        unsigned char reg0;             /* Register '0' in a WD8013 */
176
        unsigned char reg5;             /* Register '5' in a WD8013 */
177
        unsigned char saved_irq;        /* Original dev->irq value. */
178
        struct net_device_stats stat;   /* The new statistics table. */
179
        u32 *reg_offset;                /* Register mapping table */
180
        spinlock_t page_lock;           /* Page register locks */
181
        unsigned long priv;             /* Private field to store bus IDs etc. */
182
};
183
 
184
/* The maximum number of 8390 interrupt service routines called per IRQ. */
185
#define MAX_SERVICE 12
186
 
187
/* The maximum time waited (in jiffies) before assuming a Tx failed. (20ms) */
188
#define TX_TIMEOUT (20*HZ/100)
189
 
190
#define ei_status (*(struct ei_device *)(dev->priv))
191
 
192
/* Some generic ethernet register configurations. */
193
#define E8390_TX_IRQ_MASK       0xa     /* For register EN0_ISR */
194
#define E8390_RX_IRQ_MASK       0x5
195
#define E8390_RXCONFIG          0x4     /* EN0_RXCR: broadcasts, no multicast,errors */
196
#define E8390_RXOFF             0x20    /* EN0_RXCR: Accept no packets */
197
#define E8390_TXCONFIG          0x00    /* EN0_TXCR: Normal transmit mode */
198
#define E8390_TXOFF             0x02    /* EN0_TXCR: Transmitter off */
199
 
200
/*  Register accessed at EN_CMD, the 8390 base addr.  */
201
#define E8390_STOP      0x01    /* Stop and reset the chip */
202
#define E8390_START     0x02    /* Start the chip, clear reset */
203
#define E8390_TRANS     0x04    /* Transmit a frame */
204
#define E8390_RREAD     0x08    /* Remote read */
205
#define E8390_RWRITE    0x10    /* Remote write  */
206
#define E8390_NODMA     0x20    /* Remote DMA */
207
#define E8390_PAGE0     0x00    /* Select page chip registers */
208
#define E8390_PAGE1     0x40    /* using the two high-order bits */
209
#define E8390_PAGE2     0x80    /* Page 3 is invalid. */
210
 
211
/*
212
 *      Only generate indirect loads given a machine that needs them.
213
 */
214
 
215
#if defined(CONFIG_MAC) || defined(CONFIG_AMIGA_PCMCIA) || \
216
    defined(CONFIG_ARIADNE2) || defined(CONFIG_ARIADNE2_MODULE)
217
#define EI_SHIFT(x)     (ei_local->reg_offset[x])
218
#else
219
#define EI_SHIFT(x)     (x)
220
#endif
221
 
222
#define E8390_CMD       EI_SHIFT(0x00)  /* The command register (for all pages) */
223
/* Page 0 register offsets. */
224
#define EN0_CLDALO      EI_SHIFT(0x01)  /* Low byte of current local dma addr  RD */
225
#define EN0_STARTPG     EI_SHIFT(0x01)  /* Starting page of ring bfr WR */
226
#define EN0_CLDAHI      EI_SHIFT(0x02)  /* High byte of current local dma addr  RD */
227
#define EN0_STOPPG      EI_SHIFT(0x02)  /* Ending page +1 of ring bfr WR */
228
#define EN0_BOUNDARY    EI_SHIFT(0x03)  /* Boundary page of ring bfr RD WR */
229
#define EN0_TSR         EI_SHIFT(0x04)  /* Transmit status reg RD */
230
#define EN0_TPSR        EI_SHIFT(0x04)  /* Transmit starting page WR */
231
#define EN0_NCR         EI_SHIFT(0x05)  /* Number of collision reg RD */
232
#define EN0_TCNTLO      EI_SHIFT(0x05)  /* Low  byte of tx byte count WR */
233
#define EN0_FIFO        EI_SHIFT(0x06)  /* FIFO RD */
234
#define EN0_TCNTHI      EI_SHIFT(0x06)  /* High byte of tx byte count WR */
235
#define EN0_ISR         EI_SHIFT(0x07)  /* Interrupt status reg RD WR */
236
#define EN0_CRDALO      EI_SHIFT(0x08)  /* low byte of current remote dma address RD */
237
#define EN0_RSARLO      EI_SHIFT(0x08)  /* Remote start address reg 0 */
238
#define EN0_CRDAHI      EI_SHIFT(0x09)  /* high byte, current remote dma address RD */
239
#define EN0_RSARHI      EI_SHIFT(0x09)  /* Remote start address reg 1 */
240
#define EN0_RCNTLO      EI_SHIFT(0x0a)  /* Remote byte count reg WR */
241
#define EN0_RCNTHI      EI_SHIFT(0x0b)  /* Remote byte count reg WR */
242
#define EN0_RSR         EI_SHIFT(0x0c)  /* rx status reg RD */
243
#define EN0_RXCR        EI_SHIFT(0x0c)  /* RX configuration reg WR */
244
#define EN0_TXCR        EI_SHIFT(0x0d)  /* TX configuration reg WR */
245
#define EN0_COUNTER0    EI_SHIFT(0x0d)  /* Rcv alignment error counter RD */
246
#define EN0_DCFG        EI_SHIFT(0x0e)  /* Data configuration reg WR */
247
#define EN0_COUNTER1    EI_SHIFT(0x0e)  /* Rcv CRC error counter RD */
248
#define EN0_IMR         EI_SHIFT(0x0f)  /* Interrupt mask reg WR */
249
#define EN0_COUNTER2    EI_SHIFT(0x0f)  /* Rcv missed frame error counter RD */
250
 
251
/* Bits in EN0_ISR - Interrupt status register */
252
#define ENISR_RX        0x01    /* Receiver, no error */
253
#define ENISR_TX        0x02    /* Transmitter, no error */
254
#define ENISR_RX_ERR    0x04    /* Receiver, with error */
255
#define ENISR_TX_ERR    0x08    /* Transmitter, with error */
256
#define ENISR_OVER      0x10    /* Receiver overwrote the ring */
257
#define ENISR_COUNTERS  0x20    /* Counters need emptying */
258
#define ENISR_RDC       0x40    /* remote dma complete */
259
#define ENISR_RESET     0x80    /* Reset completed */
260
#define ENISR_ALL       0x3f    /* Interrupts we will enable */
261
 
262
/* Bits in EN0_DCFG - Data config register */
263
#define ENDCFG_WTS      0x01    /* word transfer mode selection */
264
 
265
/* Page 1 register offsets. */
266
#define EN1_PHYS   EI_SHIFT(0x01)       /* This board's physical enet addr RD WR */
267
#define EN1_PHYS_SHIFT(i)  EI_SHIFT(i+1) /* Get and set mac address */
268
#define EN1_CURPAG EI_SHIFT(0x07)       /* Current memory page RD WR */
269
#define EN1_MULT   EI_SHIFT(0x08)       /* Multicast filter mask array (8 bytes) RD WR */
270
#define EN1_MULT_SHIFT(i)  EI_SHIFT(8+i) /* Get and set multicast filter */
271
 
272
/* Bits in received packet status byte and EN0_RSR*/
273
#define ENRSR_RXOK      0x01    /* Received a good packet */
274
#define ENRSR_CRC       0x02    /* CRC error */
275
#define ENRSR_FAE       0x04    /* frame alignment error */
276
#define ENRSR_FO        0x08    /* FIFO overrun */
277
#define ENRSR_MPA       0x10    /* missed pkt */
278
#define ENRSR_PHY       0x20    /* physical/multicast address */
279
#define ENRSR_DIS       0x40    /* receiver disable. set in monitor mode */
280
#define ENRSR_DEF       0x80    /* deferring */
281
 
282
/* Transmitted packet status, EN0_TSR. */
283
#define ENTSR_PTX 0x01  /* Packet transmitted without error */
284
#define ENTSR_ND  0x02  /* The transmit wasn't deferred. */
285
#define ENTSR_COL 0x04  /* The transmit collided at least once. */
286
#define ENTSR_ABT 0x08  /* The transmit collided 16 times, and was deferred. */
287
#define ENTSR_CRS 0x10  /* The carrier sense was lost. */
288
#define ENTSR_FU  0x20  /* A "FIFO underrun" occurred during transmit. */
289
#define ENTSR_CDH 0x40  /* The collision detect "heartbeat" signal was lost. */
290
#define ENTSR_OWC 0x80  /* There was an out-of-window collision. */
291
 
292
#endif /* _8390_h */