xref: /OK3568_Linux_fs/kernel/drivers/net/ethernet/amd/7990.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * 7990.h -- LANCE ethernet IC generic routines.
4*4882a593Smuzhiyun  * This is an attempt to separate out the bits of various ethernet
5*4882a593Smuzhiyun  * drivers that are common because they all use the AMD 7990 LANCE
6*4882a593Smuzhiyun  * (Local Area Network Controller for Ethernet) chip.
7*4882a593Smuzhiyun  *
8*4882a593Smuzhiyun  * Copyright (C) 05/1998 Peter Maydell <pmaydell@chiark.greenend.org.uk>
9*4882a593Smuzhiyun  *
10*4882a593Smuzhiyun  * Most of this stuff was obtained by looking at other LANCE drivers,
11*4882a593Smuzhiyun  * in particular a2065.[ch]. The AMD C-LANCE datasheet was also helpful.
12*4882a593Smuzhiyun  */
13*4882a593Smuzhiyun 
14*4882a593Smuzhiyun #ifndef _7990_H
15*4882a593Smuzhiyun #define _7990_H
16*4882a593Smuzhiyun 
17*4882a593Smuzhiyun /* The lance only has two register locations. We communicate mostly via memory. */
18*4882a593Smuzhiyun #define LANCE_RDP	0	/* Register Data Port */
19*4882a593Smuzhiyun #define LANCE_RAP	2	/* Register Address Port */
20*4882a593Smuzhiyun 
21*4882a593Smuzhiyun /* Transmit/receive ring definitions.
22*4882a593Smuzhiyun  * We allow the specific drivers to override these defaults if they want to.
23*4882a593Smuzhiyun  * NB: according to lance.c, increasing the number of buffers is a waste
24*4882a593Smuzhiyun  * of space and reduces the chance that an upper layer will be able to
25*4882a593Smuzhiyun  * reorder queued Tx packets based on priority. [Clearly there is a minimum
26*4882a593Smuzhiyun  * limit too: too small and we drop rx packets and can't tx at full speed.]
27*4882a593Smuzhiyun  * 4+4 seems to be the usual setting; the atarilance driver uses 3 and 5.
28*4882a593Smuzhiyun  */
29*4882a593Smuzhiyun 
30*4882a593Smuzhiyun /* Blast! This won't work. The problem is that we can't specify a default
31*4882a593Smuzhiyun  * setting because that would cause the lance_init_block struct to be
32*4882a593Smuzhiyun  * too long (and overflow the RAM on shared-memory cards like the HP LANCE.
33*4882a593Smuzhiyun  */
34*4882a593Smuzhiyun #ifndef LANCE_LOG_TX_BUFFERS
35*4882a593Smuzhiyun #define LANCE_LOG_TX_BUFFERS 1
36*4882a593Smuzhiyun #define LANCE_LOG_RX_BUFFERS 3
37*4882a593Smuzhiyun #endif
38*4882a593Smuzhiyun 
39*4882a593Smuzhiyun #define TX_RING_SIZE		(1 << LANCE_LOG_TX_BUFFERS)
40*4882a593Smuzhiyun #define RX_RING_SIZE		(1 << LANCE_LOG_RX_BUFFERS)
41*4882a593Smuzhiyun #define TX_RING_MOD_MASK	(TX_RING_SIZE - 1)
42*4882a593Smuzhiyun #define RX_RING_MOD_MASK	(RX_RING_SIZE - 1)
43*4882a593Smuzhiyun #define TX_RING_LEN_BITS	((LANCE_LOG_TX_BUFFERS) << 29)
44*4882a593Smuzhiyun #define RX_RING_LEN_BITS	((LANCE_LOG_RX_BUFFERS) << 29)
45*4882a593Smuzhiyun #define PKT_BUFF_SIZE		(1544)
46*4882a593Smuzhiyun #define RX_BUFF_SIZE		PKT_BUFF_SIZE
47*4882a593Smuzhiyun #define TX_BUFF_SIZE		PKT_BUFF_SIZE
48*4882a593Smuzhiyun 
49*4882a593Smuzhiyun /* Each receive buffer is described by a receive message descriptor (RMD) */
50*4882a593Smuzhiyun struct lance_rx_desc {
51*4882a593Smuzhiyun 	volatile unsigned short rmd0;	    /* low address of packet */
52*4882a593Smuzhiyun 	volatile unsigned char  rmd1_bits;  /* descriptor bits */
53*4882a593Smuzhiyun 	volatile unsigned char  rmd1_hadr;  /* high address of packet */
54*4882a593Smuzhiyun 	volatile short    length;	    /* This length is 2s complement (negative)!
55*4882a593Smuzhiyun 					     * Buffer length */
56*4882a593Smuzhiyun 	volatile unsigned short mblength;   /* Actual number of bytes received */
57*4882a593Smuzhiyun };
58*4882a593Smuzhiyun 
59*4882a593Smuzhiyun /* Ditto for TMD: */
60*4882a593Smuzhiyun struct lance_tx_desc {
61*4882a593Smuzhiyun 	volatile unsigned short tmd0;	    /* low address of packet */
62*4882a593Smuzhiyun 	volatile unsigned char  tmd1_bits;  /* descriptor bits */
63*4882a593Smuzhiyun 	volatile unsigned char  tmd1_hadr;  /* high address of packet */
64*4882a593Smuzhiyun 	volatile short    length;	    /* Length is 2s complement (negative)! */
65*4882a593Smuzhiyun 	volatile unsigned short misc;
66*4882a593Smuzhiyun };
67*4882a593Smuzhiyun 
68*4882a593Smuzhiyun /* There are three memory structures accessed by the LANCE:
69*4882a593Smuzhiyun  * the initialization block, the receive and transmit descriptor rings,
70*4882a593Smuzhiyun  * and the data buffers themselves. In fact we might as well put the
71*4882a593Smuzhiyun  * init block,the Tx and Rx rings and the buffers together in memory:
72*4882a593Smuzhiyun  */
73*4882a593Smuzhiyun struct lance_init_block {
74*4882a593Smuzhiyun 	volatile unsigned short mode;		/* Pre-set mode (reg. 15) */
75*4882a593Smuzhiyun 	volatile unsigned char phys_addr[6];	/* Physical ethernet address */
76*4882a593Smuzhiyun 	volatile unsigned filter[2];		/* Multicast filter (64 bits) */
77*4882a593Smuzhiyun 
78*4882a593Smuzhiyun 	/* Receive and transmit ring base, along with extra bits. */
79*4882a593Smuzhiyun 	volatile unsigned short rx_ptr;		/* receive descriptor addr */
80*4882a593Smuzhiyun 	volatile unsigned short rx_len;		/* receive len and high addr */
81*4882a593Smuzhiyun 	volatile unsigned short tx_ptr;		/* transmit descriptor addr */
82*4882a593Smuzhiyun 	volatile unsigned short tx_len;		/* transmit len and high addr */
83*4882a593Smuzhiyun 
84*4882a593Smuzhiyun 	/* The Tx and Rx ring entries must be aligned on 8-byte boundaries.
85*4882a593Smuzhiyun 	 * This will be true if this whole struct is 8-byte aligned.
86*4882a593Smuzhiyun 	 */
87*4882a593Smuzhiyun 	volatile struct lance_tx_desc btx_ring[TX_RING_SIZE];
88*4882a593Smuzhiyun 	volatile struct lance_rx_desc brx_ring[RX_RING_SIZE];
89*4882a593Smuzhiyun 
90*4882a593Smuzhiyun 	volatile char tx_buf[TX_RING_SIZE][TX_BUFF_SIZE];
91*4882a593Smuzhiyun 	volatile char rx_buf[RX_RING_SIZE][RX_BUFF_SIZE];
92*4882a593Smuzhiyun 	/* we use this just to make the struct big enough that we can move its startaddr
93*4882a593Smuzhiyun 	 * in order to force alignment to an eight byte boundary.
94*4882a593Smuzhiyun 	 */
95*4882a593Smuzhiyun };
96*4882a593Smuzhiyun 
97*4882a593Smuzhiyun /* This is where we keep all the stuff the driver needs to know about.
98*4882a593Smuzhiyun  * I'm definitely unhappy about the mechanism for allowing specific
99*4882a593Smuzhiyun  * drivers to add things...
100*4882a593Smuzhiyun  */
101*4882a593Smuzhiyun struct lance_private {
102*4882a593Smuzhiyun 	const char *name;
103*4882a593Smuzhiyun 	unsigned long base;
104*4882a593Smuzhiyun 	volatile struct lance_init_block *init_block; /* CPU address of RAM */
105*4882a593Smuzhiyun 	volatile struct lance_init_block *lance_init_block; /* LANCE address of RAM */
106*4882a593Smuzhiyun 
107*4882a593Smuzhiyun 	int rx_new, tx_new;
108*4882a593Smuzhiyun 	int rx_old, tx_old;
109*4882a593Smuzhiyun 
110*4882a593Smuzhiyun 	int lance_log_rx_bufs, lance_log_tx_bufs;
111*4882a593Smuzhiyun 	int rx_ring_mod_mask, tx_ring_mod_mask;
112*4882a593Smuzhiyun 
113*4882a593Smuzhiyun 	int tpe;			/* TPE is selected */
114*4882a593Smuzhiyun 	int auto_select;		/* cable-selection is by carrier */
115*4882a593Smuzhiyun 	unsigned short busmaster_regval;
116*4882a593Smuzhiyun 
117*4882a593Smuzhiyun 	unsigned int irq;		/* IRQ to register */
118*4882a593Smuzhiyun 
119*4882a593Smuzhiyun 	/* This is because the HP LANCE is disgusting and you have to check
120*4882a593Smuzhiyun 	 * a DIO-specific register every time you read/write the LANCE regs :-<
121*4882a593Smuzhiyun 	 * [could we get away with making these some sort of macro?]
122*4882a593Smuzhiyun 	 */
123*4882a593Smuzhiyun 	void (*writerap)(void *, unsigned short);
124*4882a593Smuzhiyun 	void (*writerdp)(void *, unsigned short);
125*4882a593Smuzhiyun 	unsigned short (*readrdp)(void *);
126*4882a593Smuzhiyun 	spinlock_t devlock;
127*4882a593Smuzhiyun 	char tx_full;
128*4882a593Smuzhiyun };
129*4882a593Smuzhiyun 
130*4882a593Smuzhiyun /*
131*4882a593Smuzhiyun  *		Am7990 Control and Status Registers
132*4882a593Smuzhiyun  */
133*4882a593Smuzhiyun #define LE_CSR0		0x0000	/* LANCE Controller Status */
134*4882a593Smuzhiyun #define LE_CSR1		0x0001	/* IADR[15:0] (bit0==0 ie word aligned) */
135*4882a593Smuzhiyun #define LE_CSR2		0x0002	/* IADR[23:16] (high bits reserved) */
136*4882a593Smuzhiyun #define LE_CSR3		0x0003	/* Misc */
137*4882a593Smuzhiyun 
138*4882a593Smuzhiyun /*
139*4882a593Smuzhiyun  *		Bit definitions for CSR0 (LANCE Controller Status)
140*4882a593Smuzhiyun  */
141*4882a593Smuzhiyun #define LE_C0_ERR	0x8000	/* Error = BABL | CERR | MISS | MERR */
142*4882a593Smuzhiyun #define LE_C0_BABL	0x4000	/* Babble: Transmitted too many bits */
143*4882a593Smuzhiyun #define LE_C0_CERR	0x2000	/* No Heartbeat (10BASE-T) */
144*4882a593Smuzhiyun #define LE_C0_MISS	0x1000	/* Missed Frame (no rx buffer to put it in) */
145*4882a593Smuzhiyun #define LE_C0_MERR	0x0800	/* Memory Error */
146*4882a593Smuzhiyun #define LE_C0_RINT	0x0400	/* Receive Interrupt */
147*4882a593Smuzhiyun #define LE_C0_TINT	0x0200	/* Transmit Interrupt */
148*4882a593Smuzhiyun #define LE_C0_IDON	0x0100	/* Initialization Done */
149*4882a593Smuzhiyun #define LE_C0_INTR	0x0080	/* Interrupt Flag
150*4882a593Smuzhiyun 				   = BABL | MISS | MERR | RINT | TINT | IDON */
151*4882a593Smuzhiyun #define LE_C0_INEA	0x0040	/* Interrupt Enable */
152*4882a593Smuzhiyun #define LE_C0_RXON	0x0020	/* Receive On */
153*4882a593Smuzhiyun #define LE_C0_TXON	0x0010	/* Transmit On */
154*4882a593Smuzhiyun #define LE_C0_TDMD	0x0008	/* Transmit Demand */
155*4882a593Smuzhiyun #define LE_C0_STOP	0x0004	/* Stop */
156*4882a593Smuzhiyun #define LE_C0_STRT	0x0002	/* Start */
157*4882a593Smuzhiyun #define LE_C0_INIT	0x0001	/* Initialize */
158*4882a593Smuzhiyun 
159*4882a593Smuzhiyun 
160*4882a593Smuzhiyun /*
161*4882a593Smuzhiyun  *		Bit definitions for CSR3
162*4882a593Smuzhiyun  */
163*4882a593Smuzhiyun #define LE_C3_BSWP	0x0004	/* Byte Swap (on for big endian byte order) */
164*4882a593Smuzhiyun #define LE_C3_ACON	0x0002	/* ALE Control (on for active low ALE) */
165*4882a593Smuzhiyun #define LE_C3_BCON	0x0001	/* Byte Control */
166*4882a593Smuzhiyun 
167*4882a593Smuzhiyun 
168*4882a593Smuzhiyun /*
169*4882a593Smuzhiyun  *		Mode Flags
170*4882a593Smuzhiyun  */
171*4882a593Smuzhiyun #define LE_MO_PROM	0x8000	/* Promiscuous Mode */
172*4882a593Smuzhiyun /* these next ones 0x4000 -- 0x0080 are not available on the LANCE 7990,
173*4882a593Smuzhiyun  * but they are in NetBSD's am7990.h, presumably for backwards-compatible chips
174*4882a593Smuzhiyun  */
175*4882a593Smuzhiyun #define LE_MO_DRCVBC	0x4000	/* disable receive broadcast */
176*4882a593Smuzhiyun #define LE_MO_DRCVPA	0x2000	/* disable physical address detection */
177*4882a593Smuzhiyun #define LE_MO_DLNKTST	0x1000	/* disable link status */
178*4882a593Smuzhiyun #define LE_MO_DAPC	0x0800	/* disable automatic polarity correction */
179*4882a593Smuzhiyun #define LE_MO_MENDECL	0x0400	/* MENDEC loopback mode */
180*4882a593Smuzhiyun #define LE_MO_LRTTSEL	0x0200	/* lower RX threshold / TX mode selection */
181*4882a593Smuzhiyun #define LE_MO_PSEL1	0x0100	/* port selection bit1 */
182*4882a593Smuzhiyun #define LE_MO_PSEL0	0x0080	/* port selection bit0 */
183*4882a593Smuzhiyun /* and this one is from the C-LANCE data sheet... */
184*4882a593Smuzhiyun #define LE_MO_EMBA	0x0080	/* Enable Modified Backoff Algorithm
185*4882a593Smuzhiyun 				   (C-LANCE, not original LANCE) */
186*4882a593Smuzhiyun #define LE_MO_INTL	0x0040	/* Internal Loopback */
187*4882a593Smuzhiyun #define LE_MO_DRTY	0x0020	/* Disable Retry */
188*4882a593Smuzhiyun #define LE_MO_FCOLL	0x0010	/* Force Collision */
189*4882a593Smuzhiyun #define LE_MO_DXMTFCS	0x0008	/* Disable Transmit CRC */
190*4882a593Smuzhiyun #define LE_MO_LOOP	0x0004	/* Loopback Enable */
191*4882a593Smuzhiyun #define LE_MO_DTX	0x0002	/* Disable Transmitter */
192*4882a593Smuzhiyun #define LE_MO_DRX	0x0001	/* Disable Receiver */
193*4882a593Smuzhiyun 
194*4882a593Smuzhiyun 
195*4882a593Smuzhiyun /*
196*4882a593Smuzhiyun  *		Receive Flags
197*4882a593Smuzhiyun  */
198*4882a593Smuzhiyun #define LE_R1_OWN	0x80	/* LANCE owns the descriptor */
199*4882a593Smuzhiyun #define LE_R1_ERR	0x40	/* Error */
200*4882a593Smuzhiyun #define LE_R1_FRA	0x20	/* Framing Error */
201*4882a593Smuzhiyun #define LE_R1_OFL	0x10	/* Overflow Error */
202*4882a593Smuzhiyun #define LE_R1_CRC	0x08	/* CRC Error */
203*4882a593Smuzhiyun #define LE_R1_BUF	0x04	/* Buffer Error */
204*4882a593Smuzhiyun #define LE_R1_SOP	0x02	/* Start of Packet */
205*4882a593Smuzhiyun #define LE_R1_EOP	0x01	/* End of Packet */
206*4882a593Smuzhiyun #define LE_R1_POK	0x03	/* Packet is complete: SOP + EOP */
207*4882a593Smuzhiyun 
208*4882a593Smuzhiyun 
209*4882a593Smuzhiyun /*
210*4882a593Smuzhiyun  *		Transmit Flags
211*4882a593Smuzhiyun  */
212*4882a593Smuzhiyun #define LE_T1_OWN	0x80	/* LANCE owns the descriptor */
213*4882a593Smuzhiyun #define LE_T1_ERR	0x40	/* Error */
214*4882a593Smuzhiyun #define LE_T1_RES	0x20	/* Reserved, LANCE writes this with a zero */
215*4882a593Smuzhiyun #define LE_T1_EMORE	0x10	/* More than one retry needed */
216*4882a593Smuzhiyun #define LE_T1_EONE	0x08	/* One retry needed */
217*4882a593Smuzhiyun #define LE_T1_EDEF	0x04	/* Deferred */
218*4882a593Smuzhiyun #define LE_T1_SOP	0x02	/* Start of Packet */
219*4882a593Smuzhiyun #define LE_T1_EOP	0x01	/* End of Packet */
220*4882a593Smuzhiyun #define LE_T1_POK	0x03	/* Packet is complete: SOP + EOP */
221*4882a593Smuzhiyun 
222*4882a593Smuzhiyun /*
223*4882a593Smuzhiyun  *		Error Flags
224*4882a593Smuzhiyun  */
225*4882a593Smuzhiyun #define LE_T3_BUF	0x8000	/* Buffer Error */
226*4882a593Smuzhiyun #define LE_T3_UFL	0x4000	/* Underflow Error */
227*4882a593Smuzhiyun #define LE_T3_LCOL	0x1000	/* Late Collision */
228*4882a593Smuzhiyun #define LE_T3_CLOS	0x0800	/* Loss of Carrier */
229*4882a593Smuzhiyun #define LE_T3_RTY	0x0400	/* Retry Error */
230*4882a593Smuzhiyun #define LE_T3_TDR	0x03ff	/* Time Domain Reflectometry */
231*4882a593Smuzhiyun 
232*4882a593Smuzhiyun /* Miscellaneous useful macros */
233*4882a593Smuzhiyun 
234*4882a593Smuzhiyun #define TX_BUFFS_AVAIL ((lp->tx_old <= lp->tx_new) ? \
235*4882a593Smuzhiyun 			lp->tx_old + lp->tx_ring_mod_mask - lp->tx_new : \
236*4882a593Smuzhiyun 			lp->tx_old - lp->tx_new - 1)
237*4882a593Smuzhiyun 
238*4882a593Smuzhiyun /* The LANCE only uses 24 bit addresses. This does the obvious thing. */
239*4882a593Smuzhiyun #define LANCE_ADDR(x) ((int)(x) & ~0xff000000)
240*4882a593Smuzhiyun 
241*4882a593Smuzhiyun /* Now the prototypes we export */
242*4882a593Smuzhiyun int lance_open(struct net_device *dev);
243*4882a593Smuzhiyun int lance_close(struct net_device *dev);
244*4882a593Smuzhiyun netdev_tx_t lance_start_xmit(struct sk_buff *skb, struct net_device *dev);
245*4882a593Smuzhiyun void lance_set_multicast(struct net_device *dev);
246*4882a593Smuzhiyun void lance_tx_timeout(struct net_device *dev, unsigned int txqueue);
247*4882a593Smuzhiyun #ifdef CONFIG_NET_POLL_CONTROLLER
248*4882a593Smuzhiyun void lance_poll(struct net_device *dev);
249*4882a593Smuzhiyun #endif
250*4882a593Smuzhiyun 
251*4882a593Smuzhiyun #endif /* ndef _7990_H */
252