Browse Source

[3c90x] 3c90x driver rewrite using gPXE API

This is a major rewrite of the legacy etherboot 3c90x driver using the
gPXE API for much improved performance over the legacy driver it
replaces.

This driver has been tested on 3c905, 3c905B, and 3c905C cards.

Reviewed-by: Stefan Hajnoczi <stefanha@gmail.com>
Reviewed-by: Marty Connor <mdc@etherboot.org>
Tested-by: Marty Connor <mdc@etherboot.org>
Tested-by: Daniel Verkamp <daniel@drv.nu>

Signed-off-by: Marty Connor <mdc@etherboot.org>
tags/v0.9.8
Thomas Miletich 15 years ago
parent
commit
90c01ef1e4
2 changed files with 1200 additions and 935 deletions
  1. 900
    935
      src/drivers/net/3c90x.c
  2. 300
    0
      src/drivers/net/3c90x.h

+ 900
- 935
src/drivers/net/3c90x.c
File diff suppressed because it is too large
View File


+ 300
- 0
src/drivers/net/3c90x.h View File

@@ -0,0 +1,300 @@
1
+/*
2
+ * 3c90x.c -- This file implements the 3c90x driver for etherboot.  Written
3
+ * by Greg Beeley, Greg.Beeley@LightSys.org.  Modified by Steve Smith,
4
+ * Steve.Smith@Juno.Com. Alignment bug fix Neil Newell (nn@icenoir.net).
5
+ *
6
+ * Port from etherboot to gPXE API, implementation of tx/rx ring support
7
+ * by Thomas Miletich, thomas.miletich@gmail.com
8
+ * Thanks to Marty Connor and Stefan Hajnoczi for their help and feedback.
9
+ *
10
+ * This program Copyright (C) 1999 LightSys Technology Services, Inc.
11
+ * Portions Copyright (C) 1999 Steve Smith
12
+ *
13
+ * This program may be re-distributed in source or binary form, modified,
14
+ * sold, or copied for any purpose, provided that the above copyright message
15
+ * and this text are included with all source copies or derivative works, and
16
+ * provided that the above copyright message and this text are included in the
17
+ * documentation of any binary-only distributions.  This program is distributed
18
+ * WITHOUT ANY WARRANTY, without even the warranty of FITNESS FOR A PARTICULAR
19
+ * PURPOSE or MERCHANTABILITY.  Please read the associated documentation
20
+ * "3c90x.txt" before compiling and using this driver.
21
+ *
22
+ * --------
23
+ *
24
+ * Program written with the assistance of the 3com documentation for
25
+ * the 3c905B-TX card, as well as with some assistance from the 3c59x
26
+ * driver Donald Becker wrote for the Linux kernel, and with some assistance
27
+ * from the remainder of the Etherboot distribution.
28
+ *
29
+ * REVISION HISTORY:
30
+ *
31
+ * v0.10	1-26-1998	GRB	Initial implementation.
32
+ * v0.90	1-27-1998	GRB	System works.
33
+ * v1.00pre1	2-11-1998	GRB	Got prom boot issue fixed.
34
+ * v2.0		9-24-1999	SCS	Modified for 3c905 (from 3c905b code)
35
+ *					Re-wrote poll and transmit for
36
+ *					better error recovery and heavy
37
+ *					network traffic operation
38
+ * v2.01    5-26-2003 NN Fixed driver alignment issue which
39
+ *                  caused system lockups if driver structures
40
+ *                  not 8-byte aligned.
41
+ * v2.02   11-28-2007 GSt Got polling working again by replacing
42
+ * 			"for(i=0;i<40000;i++);" with "mdelay(1);"
43
+ *
44
+ *
45
+ * indent options: indent -kr -i8 3c90x.c
46
+ */
47
+
48
+#ifndef __3C90X_H_
49
+#define __3C90X_H_
50
+
51
+static struct net_device_operations a3c90x_operations;
52
+
53
+#define	XCVR_MAGIC	(0x5A00)
54
+
55
+/* Register definitions for the 3c905 */
56
+enum Registers {
57
+	regPowerMgmtCtrl_w = 0x7c,	/* 905B Revision Only                 */
58
+	regUpMaxBurst_w = 0x7a,	/* 905B Revision Only                 */
59
+	regDnMaxBurst_w = 0x78,	/* 905B Revision Only                 */
60
+	regDebugControl_w = 0x74,	/* 905B Revision Only                 */
61
+	regDebugData_l = 0x70,	/* 905B Revision Only                 */
62
+	regRealTimeCnt_l = 0x40,	/* Universal                          */
63
+	regUpBurstThresh_b = 0x3e,	/* 905B Revision Only                 */
64
+	regUpPoll_b = 0x3d,	/* 905B Revision Only                 */
65
+	regUpPriorityThresh_b = 0x3c,	/* 905B Revision Only                 */
66
+	regUpListPtr_l = 0x38,	/* Universal                          */
67
+	regCountdown_w = 0x36,	/* Universal                          */
68
+	regFreeTimer_w = 0x34,	/* Universal                          */
69
+	regUpPktStatus_l = 0x30,	/* Universal with Exception, pg 130   */
70
+	regTxFreeThresh_b = 0x2f,	/* 90X Revision Only                  */
71
+	regDnPoll_b = 0x2d,	/* 905B Revision Only                 */
72
+	regDnPriorityThresh_b = 0x2c,	/* 905B Revision Only                 */
73
+	regDnBurstThresh_b = 0x2a,	/* 905B Revision Only                 */
74
+	regDnListPtr_l = 0x24,	/* Universal with Exception, pg 107   */
75
+	regDmaCtrl_l = 0x20,	/* Universal with Exception, pg 106   */
76
+	/*                                    */
77
+	regIntStatusAuto_w = 0x1e,	/* 905B Revision Only                 */
78
+	regTxStatus_b = 0x1b,	/* Universal with Exception, pg 113   */
79
+	regTimer_b = 0x1a,	/* Universal                          */
80
+	regTxPktId_b = 0x18,	/* 905B Revision Only                 */
81
+	regCommandIntStatus_w = 0x0e,	/* Universal (Command Variations)     */
82
+};
83
+
84
+/* following are windowed registers */
85
+enum Registers7 {
86
+	regPowerMgmtEvent_7_w = 0x0c,	/* 905B Revision Only                 */
87
+	regVlanEtherType_7_w = 0x04,	/* 905B Revision Only                 */
88
+	regVlanMask_7_w = 0x00,	/* 905B Revision Only                 */
89
+};
90
+
91
+enum Registers6 {
92
+	regBytesXmittedOk_6_w = 0x0c,	/* Universal                          */
93
+	regBytesRcvdOk_6_w = 0x0a,	/* Universal                          */
94
+	regUpperFramesOk_6_b = 0x09,	/* Universal                          */
95
+	regFramesDeferred_6_b = 0x08,	/* Universal                          */
96
+	regFramesRecdOk_6_b = 0x07,	/* Universal with Exceptions, pg 142  */
97
+	regFramesXmittedOk_6_b = 0x06,	/* Universal                          */
98
+	regRxOverruns_6_b = 0x05,	/* Universal                          */
99
+	regLateCollisions_6_b = 0x04,	/* Universal                          */
100
+	regSingleCollisions_6_b = 0x03,	/* Universal                          */
101
+	regMultipleCollisions_6_b = 0x02,	/* Universal                          */
102
+	regSqeErrors_6_b = 0x01,	/* Universal                          */
103
+	regCarrierLost_6_b = 0x00,	/* Universal                          */
104
+};
105
+
106
+enum Registers5 {
107
+	regIndicationEnable_5_w = 0x0c,	/* Universal                          */
108
+	regInterruptEnable_5_w = 0x0a,	/* Universal                          */
109
+	regTxReclaimThresh_5_b = 0x09,	/* 905B Revision Only                 */
110
+	regRxFilter_5_b = 0x08,	/* Universal                          */
111
+	regRxEarlyThresh_5_w = 0x06,	/* Universal                          */
112
+	regTxStartThresh_5_w = 0x00,	/* Universal                          */
113
+};
114
+
115
+enum Registers4 {
116
+	regUpperBytesOk_4_b = 0x0d,	/* Universal                          */
117
+	regBadSSD_4_b = 0x0c,	/* Universal                          */
118
+	regMediaStatus_4_w = 0x0a,	/* Universal with Exceptions, pg 201  */
119
+	regPhysicalMgmt_4_w = 0x08,	/* Universal                          */
120
+	regNetworkDiagnostic_4_w = 0x06,	/* Universal with Exceptions, pg 203  */
121
+	regFifoDiagnostic_4_w = 0x04,	/* Universal with Exceptions, pg 196  */
122
+	regVcoDiagnostic_4_w = 0x02,	/* Undocumented?                      */
123
+};
124
+
125
+enum Registers3 {
126
+	regTxFree_3_w = 0x0c,	/* Universal                          */
127
+	regRxFree_3_w = 0x0a,	/* Universal with Exceptions, pg 125  */
128
+	regResetMediaOptions_3_w = 0x08,	/* Media Options on B Revision,       */
129
+	/* Reset Options on Non-B Revision    */
130
+	regMacControl_3_w = 0x06,	/* Universal with Exceptions, pg 199  */
131
+	regMaxPktSize_3_w = 0x04,	/* 905B Revision Only                 */
132
+	regInternalConfig_3_l = 0x00,	/* Universal, different bit           */
133
+	/* definitions, pg 59                 */
134
+};
135
+
136
+enum Registers2 {
137
+	regResetOptions_2_w = 0x0c,	/* 905B Revision Only                 */
138
+	regStationMask_2_3w = 0x06,	/* Universal with Exceptions, pg 127  */
139
+	regStationAddress_2_3w = 0x00,	/* Universal with Exceptions, pg 127  */
140
+};
141
+
142
+enum Registers1 {
143
+	regRxStatus_1_w = 0x0a,	/* 90X Revision Only, Pg 126          */
144
+};
145
+
146
+enum Registers0 {
147
+	regEepromData_0_w = 0x0c,	/* Universal                          */
148
+	regEepromCommand_0_w = 0x0a,	/* Universal                          */
149
+	regBiosRomData_0_b = 0x08,	/* 905B Revision Only                 */
150
+	regBiosRomAddr_0_l = 0x04,	/* 905B Revision Only                 */
151
+};
152
+
153
+
154
+/* The names for the eight register windows */
155
+enum Windows {
156
+	winNone = 0xff,
157
+	winPowerVlan7 = 0x07,
158
+	winStatistics6 = 0x06,
159
+	winTxRxControl5 = 0x05,
160
+	winDiagnostics4 = 0x04,
161
+	winTxRxOptions3 = 0x03,
162
+	winAddressing2 = 0x02,
163
+	winUnused1 = 0x01,
164
+	winEepromBios0 = 0x00,
165
+};
166
+
167
+
168
+/* Command definitions for the 3c90X */
169
+enum Commands {
170
+	cmdGlobalReset = 0x00,	/* Universal with Exceptions, pg 151 */
171
+	cmdSelectRegisterWindow = 0x01,	/* Universal                         */
172
+	cmdEnableDcConverter = 0x02,	/*                                   */
173
+	cmdRxDisable = 0x03,	/*                                   */
174
+	cmdRxEnable = 0x04,	/* Universal                         */
175
+	cmdRxReset = 0x05,	/* Universal                         */
176
+	cmdStallCtl = 0x06,	/* Universal                         */
177
+	cmdTxEnable = 0x09,	/* Universal                         */
178
+	cmdTxDisable = 0x0A,	/*                                   */
179
+	cmdTxReset = 0x0B,	/* Universal                         */
180
+	cmdRequestInterrupt = 0x0C,	/*                                   */
181
+	cmdAcknowledgeInterrupt = 0x0D,	/* Universal                         */
182
+	cmdSetInterruptEnable = 0x0E,	/* Universal                         */
183
+	cmdSetIndicationEnable = 0x0F,	/* Universal                         */
184
+	cmdSetRxFilter = 0x10,	/* Universal                         */
185
+	cmdSetRxEarlyThresh = 0x11,	/*                                   */
186
+	cmdSetTxStartThresh = 0x13,	/*                                   */
187
+	cmdStatisticsEnable = 0x15,	/*                                   */
188
+	cmdStatisticsDisable = 0x16,	/*                                   */
189
+	cmdDisableDcConverter = 0x17,	/*                                   */
190
+	cmdSetTxReclaimThresh = 0x18,	/*                                   */
191
+	cmdSetHashFilterBit = 0x19,	/*                                   */
192
+};
193
+
194
+enum FrameStartHeader {
195
+	fshTxIndicate = 0x8000,
196
+	fshDnComplete = 0x10000,
197
+};
198
+
199
+enum UpDownDesc {
200
+	upLastFrag = (1 << 31),
201
+	downLastFrag = (1 << 31),
202
+};
203
+
204
+enum UpPktStatus {
205
+	upComplete = (1 << 15),
206
+	upError = (1 << 14),
207
+};
208
+
209
+enum Stalls {
210
+	upStall = 0x00,
211
+	upUnStall = 0x01,
212
+
213
+	dnStall = 0x02,
214
+	dnUnStall = 0x03,
215
+};
216
+
217
+enum Resources {
218
+	resRxRing = 0x00,
219
+	resTxRing = 0x02,
220
+	resRxIOBuf = 0x04
221
+};
222
+
223
+enum eeprom {
224
+	eepromBusy = (1 << 15),
225
+	eepromRead = ((0x02) << 6),
226
+	eepromRead_556 = 0x230,
227
+	eepromHwAddrOffset = 0x0a,
228
+};
229
+
230
+/* Bit 4 is only used in revison B and upwards */
231
+enum linktype {
232
+	link10BaseT = 0x00,
233
+	linkAUI = 0x01,
234
+	link10Base2 = 0x03,
235
+	link100BaseFX = 0x05,
236
+	linkMII = 0x06,
237
+	linkAutoneg = 0x08,
238
+	linkExternalMII = 0x09,
239
+};
240
+
241
+/* Values for int status register bitmask */
242
+#define	INT_INTERRUPTLATCH	(1<<0)
243
+#define INT_HOSTERROR		(1<<1)
244
+#define INT_TXCOMPLETE		(1<<2)
245
+#define INT_RXCOMPLETE		(1<<4)
246
+#define INT_RXEARLY		(1<<5)
247
+#define INT_INTREQUESTED	(1<<6)
248
+#define INT_UPDATESTATS		(1<<7)
249
+#define INT_LINKEVENT		(1<<8)
250
+#define INT_DNCOMPLETE		(1<<9)
251
+#define INT_UPCOMPLETE		(1<<10)
252
+#define INT_CMDINPROGRESS	(1<<12)
253
+#define INT_WINDOWNUMBER	(7<<13)
254
+
255
+/* Buffer sizes */
256
+#define TX_RING_SIZE 8
257
+#define RX_RING_SIZE 8
258
+#define TX_RING_ALIGN 16
259
+#define RX_RING_ALIGN 16
260
+#define RX_BUF_SIZE 1536
261
+
262
+/* Timeouts for eeprom and command completion */
263
+/* Timeout 1 second, to be save */
264
+#define EEPROM_TIMEOUT		1 * 1000 * 1000
265
+
266
+/* TX descriptor */
267
+struct TXD {
268
+	volatile unsigned int DnNextPtr;
269
+	volatile unsigned int FrameStartHeader;
270
+	volatile unsigned int DataAddr;
271
+	volatile unsigned int DataLength;
272
+} __attribute__ ((aligned(8)));	/* 64-bit aligned for bus mastering */
273
+
274
+/* RX descriptor */
275
+struct RXD {
276
+	volatile unsigned int UpNextPtr;
277
+	volatile unsigned int UpPktStatus;
278
+	volatile unsigned int DataAddr;
279
+	volatile unsigned int DataLength;
280
+} __attribute__ ((aligned(8)));	/* 64-bit aligned for bus mastering */
281
+
282
+/* Private NIC dats */
283
+struct INF_3C90X {
284
+	unsigned int is3c556;
285
+	unsigned char isBrev;
286
+	unsigned char CurrentWindow;
287
+	unsigned int IOAddr;
288
+	unsigned short eeprom[0x21];
289
+	unsigned int tx_cur;	/* current entry in tx_ring */
290
+	unsigned int tx_cnt;	/* current number of used tx descriptors */
291
+	unsigned int tx_tail;	/* entry of last finished packet */
292
+	unsigned int rx_cur;
293
+	struct TXD *tx_ring;
294
+	struct RXD *rx_ring;
295
+	struct io_buffer *tx_iobuf[TX_RING_SIZE];
296
+	struct io_buffer *rx_iobuf[RX_RING_SIZE];
297
+	struct nvs_device nvs;
298
+};
299
+
300
+#endif

Loading…
Cancel
Save