]> Joshua Wise's Git repositories - netwatch.git/blame_incremental - net/3c90x.c
Convert the transmitter to be a ring buffer, too.
[netwatch.git] / net / 3c90x.c
... / ...
CommitLineData
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 * This program Copyright (C) 1999 LightSys Technology Services, Inc.
7 * Portions Copyright (C) 1999 Steve Smith
8 *
9 * This program may be re-distributed in source or binary form, modified,
10 * sold, or copied for any purpose, provided that the above copyright message
11 * and this text are included with all source copies or derivative works, and
12 * provided that the above copyright message and this text are included in the
13 * documentation of any binary-only distributions. This program is distributed
14 * WITHOUT ANY WARRANTY, without even the warranty of FITNESS FOR A PARTICULAR
15 * PURPOSE or MERCHANTABILITY. Please read the associated documentation
16 * "3c90x.txt" before compiling and using this driver.
17 *
18 * --------
19 *
20 * Program written with the assistance of the 3com documentation for
21 * the 3c905B-TX card, as well as with some assistance from the 3c59x
22 * driver Donald Becker wrote for the Linux kernel, and with some assistance
23 * from the remainder of the Etherboot distribution.
24 *
25 * REVISION HISTORY:
26 *
27 * v0.10 1-26-1998 GRB Initial implementation.
28 * v0.90 1-27-1998 GRB System works.
29 * v1.00pre1 2-11-1998 GRB Got prom boot issue fixed.
30 * v2.0 9-24-1999 SCS Modified for 3c905 (from 3c905b code)
31 * Re-wrote poll and transmit for
32 * better error recovery and heavy
33 * network traffic operation
34 * v2.01 5-26-2003 NN Fixed driver alignment issue which
35 * caused system lockups if driver structures
36 * not 8-byte aligned.
37 *
38 */
39
40#include "etherboot-compat.h"
41#include "net.h"
42#include <timer.h>
43#include <io.h>
44#include <pci.h>
45#include <pci-bother.h>
46#include <minilib.h>
47#include <output.h>
48#include <paging.h>
49
50#define XCVR_MAGIC (0x5A00)
51/** any single transmission fails after 16 collisions or other errors
52 ** this is the number of times to retry the transmission -- this should
53 ** be plenty
54 **/
55#define XMIT_RETRIES 5
56
57/*** Register definitions for the 3c905 ***/
58enum Registers
59 {
60 regPowerMgmtCtrl_w = 0x7c, /** 905B Revision Only **/
61 regUpMaxBurst_w = 0x7a, /** 905B Revision Only **/
62 regDnMaxBurst_w = 0x78, /** 905B Revision Only **/
63 regDebugControl_w = 0x74, /** 905B Revision Only **/
64 regDebugData_l = 0x70, /** 905B Revision Only **/
65 regRealTimeCnt_l = 0x40, /** Universal **/
66 regUpBurstThresh_b = 0x3e, /** 905B Revision Only **/
67 regUpPoll_b = 0x3d, /** 905B Revision Only **/
68 regUpPriorityThresh_b = 0x3c, /** 905B Revision Only **/
69 regUpListPtr_l = 0x38, /** Universal **/
70 regCountdown_w = 0x36, /** Universal **/
71 regFreeTimer_w = 0x34, /** Universal **/
72 regUpPktStatus_l = 0x30, /** Universal with Exception, pg 130 **/
73 regTxFreeThresh_b = 0x2f, /** 90X Revision Only **/
74 regDnPoll_b = 0x2d, /** 905B Revision Only **/
75 regDnPriorityThresh_b = 0x2c, /** 905B Revision Only **/
76 regDnBurstThresh_b = 0x2a, /** 905B Revision Only **/
77 regDnListPtr_l = 0x24, /** Universal with Exception, pg 107 **/
78 regDmaCtrl_l = 0x20, /** Universal with Exception, pg 106 **/
79 /** **/
80 regIntStatusAuto_w = 0x1e, /** 905B Revision Only **/
81 regTxStatus_b = 0x1b, /** Universal with Exception, pg 113 **/
82 regTimer_b = 0x1a, /** Universal **/
83 regTxPktId_b = 0x18, /** 905B Revision Only **/
84 regCommandIntStatus_w = 0x0e, /** Universal (Command Variations) **/
85 };
86
87/** following are windowed registers **/
88enum Registers7
89 {
90 regPowerMgmtEvent_7_w = 0x0c, /** 905B Revision Only **/
91 regVlanEtherType_7_w = 0x04, /** 905B Revision Only **/
92 regVlanMask_7_w = 0x00, /** 905B Revision Only **/
93 };
94
95enum Registers6
96 {
97 regBytesXmittedOk_6_w = 0x0c, /** Universal **/
98 regBytesRcvdOk_6_w = 0x0a, /** Universal **/
99 regUpperFramesOk_6_b = 0x09, /** Universal **/
100 regFramesDeferred_6_b = 0x08, /** Universal **/
101 regFramesRecdOk_6_b = 0x07, /** Universal with Exceptions, pg 142 **/
102 regFramesXmittedOk_6_b = 0x06, /** Universal **/
103 regRxOverruns_6_b = 0x05, /** Universal **/
104 regLateCollisions_6_b = 0x04, /** Universal **/
105 regSingleCollisions_6_b = 0x03, /** Universal **/
106 regMultipleCollisions_6_b = 0x02, /** Universal **/
107 regSqeErrors_6_b = 0x01, /** Universal **/
108 regCarrierLost_6_b = 0x00, /** Universal **/
109 };
110
111enum Registers5
112 {
113 regIndicationEnable_5_w = 0x0c, /** Universal **/
114 regInterruptEnable_5_w = 0x0a, /** Universal **/
115 regTxReclaimThresh_5_b = 0x09, /** 905B Revision Only **/
116 regRxFilter_5_b = 0x08, /** Universal **/
117 regRxEarlyThresh_5_w = 0x06, /** Universal **/
118 regTxStartThresh_5_w = 0x00, /** Universal **/
119 };
120
121enum Registers4
122 {
123 regUpperBytesOk_4_b = 0x0d, /** Universal **/
124 regBadSSD_4_b = 0x0c, /** Universal **/
125 regMediaStatus_4_w = 0x0a, /** Universal with Exceptions, pg 201 **/
126 regPhysicalMgmt_4_w = 0x08, /** Universal **/
127 regNetworkDiagnostic_4_w = 0x06, /** Universal with Exceptions, pg 203 **/
128 regFifoDiagnostic_4_w = 0x04, /** Universal with Exceptions, pg 196 **/
129 regVcoDiagnostic_4_w = 0x02, /** Undocumented? **/
130 };
131
132enum Registers3
133 {
134 regTxFree_3_w = 0x0c, /** Universal **/
135 regRxFree_3_w = 0x0a, /** Universal with Exceptions, pg 125 **/
136 regResetMediaOptions_3_w = 0x08, /** Media Options on B Revision, **/
137 /** Reset Options on Non-B Revision **/
138 regMacControl_3_w = 0x06, /** Universal with Exceptions, pg 199 **/
139 regMaxPktSize_3_w = 0x04, /** 905B Revision Only **/
140 regInternalConfig_3_l = 0x00, /** Universal, different bit **/
141 /** definitions, pg 59 **/
142 };
143
144enum Registers2
145 {
146 regResetOptions_2_w = 0x0c, /** 905B Revision Only **/
147 regStationMask_2_3w = 0x06, /** Universal with Exceptions, pg 127 **/
148 regStationAddress_2_3w = 0x00, /** Universal with Exceptions, pg 127 **/
149 };
150
151enum Registers1
152 {
153 regRxStatus_1_w = 0x0a, /** 90X Revision Only, Pg 126 **/
154 };
155
156enum Registers0
157 {
158 regEepromData_0_w = 0x0c, /** Universal **/
159 regEepromCommand_0_w = 0x0a, /** Universal **/
160 regBiosRomData_0_b = 0x08, /** 905B Revision Only **/
161 regBiosRomAddr_0_l = 0x04, /** 905B Revision Only **/
162 };
163
164
165/*** The names for the eight register windows ***/
166enum Windows
167 {
168 winPowerVlan7 = 0x07,
169 winStatistics6 = 0x06,
170 winTxRxControl5 = 0x05,
171 winDiagnostics4 = 0x04,
172 winTxRxOptions3 = 0x03,
173 winAddressing2 = 0x02,
174 winUnused1 = 0x01,
175 winEepromBios0 = 0x00,
176 };
177
178
179/*** Command definitions for the 3c90X ***/
180enum Commands
181 {
182 cmdGlobalReset = 0x00, /** Universal with Exceptions, pg 151 **/
183 cmdSelectRegisterWindow = 0x01, /** Universal **/
184 cmdEnableDcConverter = 0x02, /** **/
185 cmdRxDisable = 0x03, /** **/
186 cmdRxEnable = 0x04, /** Universal **/
187 cmdRxReset = 0x05, /** Universal **/
188 cmdStallCtl = 0x06, /** Universal **/
189 cmdTxEnable = 0x09, /** Universal **/
190 cmdTxDisable = 0x0A, /** **/
191 cmdTxReset = 0x0B, /** Universal **/
192 cmdRequestInterrupt = 0x0C, /** **/
193 cmdAcknowledgeInterrupt = 0x0D, /** Universal **/
194 cmdSetInterruptEnable = 0x0E, /** Universal **/
195 cmdSetIndicationEnable = 0x0F, /** Universal **/
196 cmdSetRxFilter = 0x10, /** Universal **/
197 cmdSetRxEarlyThresh = 0x11, /** **/
198 cmdSetTxStartThresh = 0x13, /** **/
199 cmdStatisticsEnable = 0x15, /** **/
200 cmdStatisticsDisable = 0x16, /** **/
201 cmdDisableDcConverter = 0x17, /** **/
202 cmdSetTxReclaimThresh = 0x18, /** **/
203 cmdSetHashFilterBit = 0x19, /** **/
204 };
205
206
207/*** Values for int status register bitmask **/
208#define INT_INTERRUPTLATCH (1<<0)
209#define INT_HOSTERROR (1<<1)
210#define INT_TXCOMPLETE (1<<2)
211#define INT_RXCOMPLETE (1<<4)
212#define INT_RXEARLY (1<<5)
213#define INT_INTREQUESTED (1<<6)
214#define INT_UPDATESTATS (1<<7)
215#define INT_LINKEVENT (1<<8)
216#define INT_DNCOMPLETE (1<<9)
217#define INT_UPCOMPLETE (1<<10)
218#define INT_CMDINPROGRESS (1<<12)
219#define INT_WINDOWNUMBER (7<<13)
220
221/* These structures are all 64-bit aligned, as needed for bus-mastering I/O. */
222typedef struct {
223 unsigned int addr;
224 unsigned int len;
225} segment_t __attribute__ ((aligned(8)));
226
227typedef struct {
228 unsigned int next;
229 unsigned int hdr;
230 segment_t segments[64 /* XXX magic */];
231} txdesc_t __attribute__ ((aligned(8)));
232
233/*** RX descriptor ***/
234typedef struct {
235 unsigned int next;
236 unsigned int status;
237 segment_t segments[64];
238} rxdesc_t __attribute__ ((aligned(8)));
239
240/*** Global variables ***/
241static struct
242 {
243 unsigned int is3c556;
244 unsigned char isBrev;
245 unsigned char CurrentWindow;
246 unsigned int IOAddr;
247 unsigned char HWAddr[ETH_ALEN];
248 }
249 INF_3C90X;
250
251static struct nic nic;
252
253#define _outl(v,a) outl((a),(v))
254#define _outw(v,a) outw((a),(v))
255#define _outb(v,a) outb((a),(v))
256
257static int _issue_command(int ioaddr, int cmd, int param)
258{
259 outw(ioaddr + regCommandIntStatus_w, (cmd << 11) | param);
260
261 while (inw(ioaddr + regCommandIntStatus_w) & INT_CMDINPROGRESS)
262 ;
263
264 return 0;
265}
266
267
268/*** a3c90x_internal_SetWindow: selects a register window set.
269 ***/
270static int _set_window(int ioaddr, int window)
271{
272 if (INF_3C90X.CurrentWindow == window)
273 return 0;
274
275 _issue_command(ioaddr, cmdSelectRegisterWindow, window);
276 INF_3C90X.CurrentWindow = window;
277
278 return 0;
279}
280
281
282/*** a3c90x_internal_ReadEeprom - read data from the serial eeprom.
283 ***/
284static unsigned short
285a3c90x_internal_ReadEeprom(int ioaddr, int address)
286{
287 unsigned short val;
288
289 /** Select correct window **/
290 _set_window(INF_3C90X.IOAddr, winEepromBios0);
291
292 /** Make sure the eeprom isn't busy **/
293 do
294 {
295 int i;
296 for (i = 0; i < 165; i++)
297 inb(0x80); /* wait 165 usec */
298 }
299 while(0x8000 & inw(ioaddr + regEepromCommand_0_w));
300
301 /** Read the value. **/
302 if (INF_3C90X.is3c556)
303 _outw(address + (0x230), ioaddr + regEepromCommand_0_w);
304 else
305 _outw(address + 0x80, ioaddr + regEepromCommand_0_w);
306
307 do
308 {
309 int i;
310 for (i = 0; i < 165; i++)
311 inb(0x80); /* wait 165 usec */
312 }
313 while(0x8000 & inw(ioaddr + regEepromCommand_0_w));
314 val = inw(ioaddr + regEepromData_0_w);
315
316 return val;
317}
318
319
320#ifdef CFG_3C90X_BOOTROM_FIX
321/*** a3c90x_internal_WriteEepromWord - write a physical word of
322 *** data to the onboard serial eeprom (not the BIOS prom, but the
323 *** nvram in the card that stores, among other things, the MAC
324 *** address).
325 ***/
326static int
327a3c90x_internal_WriteEepromWord(int ioaddr, int address, unsigned short value)
328 {
329 /** Select register window **/
330 _set_window(ioaddr, winEepromBios0);
331
332 /** Verify Eeprom not busy **/
333 while((1<<15) & inw(ioaddr + regEepromCommand_0_w));
334
335 /** Issue WriteEnable, and wait for completion. **/
336 _outw(0x30, ioaddr + regEepromCommand_0_w);
337 while((1<<15) & inw(ioaddr + regEepromCommand_0_w));
338
339 /** Issue EraseRegister, and wait for completion. **/
340 _outw(address + ((0x03)<<6), ioaddr + regEepromCommand_0_w);
341 while((1<<15) & inw(ioaddr + regEepromCommand_0_w));
342
343 /** Send the new data to the eeprom, and wait for completion. **/
344 _outw(value, ioaddr + regEepromData_0_w);
345 _outw(0x30, ioaddr + regEepromCommand_0_w);
346 while((1<<15) & inw(ioaddr + regEepromCommand_0_w));
347
348 /** Burn the new data into the eeprom, and wait for completion. **/
349 _outw(address + ((0x01)<<6), ioaddr + regEepromCommand_0_w);
350 while((1<<15) & inw(ioaddr + regEepromCommand_0_w));
351
352 return 0;
353 }
354#endif
355
356#ifdef CFG_3C90X_BOOTROM_FIX
357/*** a3c90x_internal_WriteEeprom - write data to the serial eeprom,
358 *** and re-compute the eeprom checksum.
359 ***/
360static int
361a3c90x_internal_WriteEeprom(int ioaddr, int address, unsigned short value)
362 {
363 int cksum = 0,v;
364 int i;
365 int maxAddress, cksumAddress;
366
367 if (INF_3C90X.isBrev)
368 {
369 maxAddress=0x1f;
370 cksumAddress=0x20;
371 }
372 else
373 {
374 maxAddress=0x16;
375 cksumAddress=0x17;
376 }
377
378 /** Write the value. **/
379 if (a3c90x_internal_WriteEepromWord(ioaddr, address, value) == -1)
380 return -1;
381
382 /** Recompute the checksum. **/
383 for(i=0;i<=maxAddress;i++)
384 {
385 v = a3c90x_internal_ReadEeprom(ioaddr, i);
386 cksum ^= (v & 0xFF);
387 cksum ^= ((v>>8) & 0xFF);
388 }
389 /** Write the checksum to the location in the eeprom **/
390 if (a3c90x_internal_WriteEepromWord(ioaddr, cksumAddress, cksum) == -1)
391 return -1;
392
393 return 0;
394 }
395#endif
396
397/*** a3c90x_reset: exported function that resets the card to its default
398 *** state. This is so the Linux driver can re-set the card up the way
399 *** it wants to. If CFG_3C90X_PRESERVE_XCVR is defined, then the reset will
400 *** not alter the selected transceiver that we used to download the boot
401 *** image.
402 ***/
403static void a3c90x_reset(void)
404 {
405 /** Send the reset command to the card **/
406 outputf("3c90x: issuing RESET");
407 _issue_command(INF_3C90X.IOAddr, cmdGlobalReset, 0);
408
409 /** global reset command resets station mask, non-B revision cards
410 ** require explicit reset of values
411 **/
412 _set_window(INF_3C90X.IOAddr, winAddressing2);
413 _outw(0, INF_3C90X.IOAddr + regStationMask_2_3w+0);
414 _outw(0, INF_3C90X.IOAddr + regStationMask_2_3w+2);
415 _outw(0, INF_3C90X.IOAddr + regStationMask_2_3w+4);
416
417 /** Issue transmit reset, wait for command completion **/
418 _issue_command(INF_3C90X.IOAddr, cmdTxReset, 0);
419 if (! INF_3C90X.isBrev)
420 _outb(0x01, INF_3C90X.IOAddr + regTxFreeThresh_b);
421 _issue_command(INF_3C90X.IOAddr, cmdTxEnable, 0);
422
423 /**
424 ** reset of the receiver on B-revision cards re-negotiates the link
425 ** takes several seconds (a computer eternity)
426 **/
427 if (INF_3C90X.isBrev)
428 _issue_command(INF_3C90X.IOAddr, cmdRxReset, 0x04);
429 else
430 _issue_command(INF_3C90X.IOAddr, cmdRxReset, 0x00);
431 while (inw(INF_3C90X.IOAddr + regCommandIntStatus_w) & INT_CMDINPROGRESS)
432 ;
433 _issue_command(INF_3C90X.IOAddr, cmdRxEnable, 0);
434
435 _issue_command(INF_3C90X.IOAddr, cmdSetInterruptEnable, 0);
436 /** enable rxComplete and txComplete **/
437 _issue_command(INF_3C90X.IOAddr, cmdSetIndicationEnable, 0x0014);
438 /** acknowledge any pending status flags **/
439 _issue_command(INF_3C90X.IOAddr, cmdAcknowledgeInterrupt, 0x661);
440
441 return;
442 }
443
444/***************************** Transmit routines *****************************/
445
446#define XMIT_BUFS 8
447
448static txdesc_t txdescs[XMIT_BUFS];
449static struct pbuf *txpbufs[XMIT_BUFS] = {0,};
450
451/* txcons is the index into the ring buffer of the last packet that the
452 * 3c90x was seen processing, or -1 if the 3c90x was idle.
453 */
454static int txcons = -1;
455
456/* txprod is the index of the _next_ buffer that the driver will write into. */
457static int txprod = 0;
458
459/* _transmit adds a packet to the transmit ring buffer. If no space is
460 * available in the buffer, then _transmit blocks until a packet has been
461 * transmitted.
462 */
463static void _transmit(struct pbuf *p)
464{
465 unsigned char status;
466 int len, n;
467
468 /* Wait for there to be space. */
469 if (txcons == txprod)
470 {
471 int i = 0;
472
473 outputf("3c90x: txbuf full, waiting for space...");
474 while (inl(INF_3C90X.IOAddr + regDnListPtr_l) != 0)
475 i++;
476 outputf("3c90x: took %d iters", i);
477 }
478
479 /* Stall the download engine so it doesn't bother us. */
480 _issue_command(INF_3C90X.IOAddr, cmdStallCtl, 2 /* Stall download */);
481
482 /* Clean up old txcons. */
483 if (txcons != -1)
484 {
485 unsigned long curp = inl(INF_3C90X.IOAddr + regDnListPtr_l);
486 int end;
487
488 if (curp == 0)
489 end = txprod;
490 else
491 end = (curp - v2p(txdescs)) / sizeof(txdescs[0]);
492
493 while (txcons != end)
494 {
495 pbuf_free(txpbufs[txcons]);
496 txpbufs[txcons] = NULL;
497 txdescs[txcons].hdr = 0;
498 txdescs[txcons].next = 0;
499 txcons = (txcons + 1) % XMIT_BUFS;
500 }
501 if (txcons == txprod)
502 txcons = -1;
503 }
504
505 /* Look at the TX status */
506 status = inb(INF_3C90X.IOAddr + regTxStatus_b);
507 if (status)
508 {
509 outputf("3c90x: error: the nus.");
510 outb(INF_3C90X.IOAddr + regTxStatus_b, 0x00);
511 }
512
513 /* Set up the new txdesc. */
514 txdescs[txprod].next = 0;
515 len = 0;
516 n = 0;
517 txpbufs[txprod] = p;
518 for (; p; p = p->next)
519 {
520 txdescs[txprod].segments[n].addr = v2p(p->payload);
521 txdescs[txprod].segments[n].len = p->len | (p->next ? 0 : (1 << 31));
522 len += p->len;
523 pbuf_ref(p);
524 n++;
525 }
526 txdescs[txprod].hdr = len; /* If we wanted completion notification, bit 15 */
527
528 /* Now link the new one in, after it's been set up. */
529 txdescs[(txprod + XMIT_BUFS - 1) % XMIT_BUFS].next = v2p(&(txdescs[txprod]));
530
531 /* If the card is stopped, start it up again. */
532 if (inl(INF_3C90X.IOAddr + regDnListPtr_l) == 0)
533 {
534 outl(INF_3C90X.IOAddr + regDnListPtr_l, v2p(&(txdescs[txprod])));
535 txcons = txprod;
536 }
537
538 txprod = (txprod + 1) % XMIT_BUFS;
539
540 /* And let it proceed on its way. */
541 _issue_command(INF_3C90X.IOAddr, cmdStallCtl, 3 /* Unstall download */);
542
543#if 0
544 /** successful completion (sans "interrupt Requested" bit) **/
545 if ((status & 0xbf) == 0x80)
546 return;
547
548 outputf("3c90x: Status (%hhX)", status);
549 /** check error codes **/
550 if (status & 0x02)
551 {
552 outputf("3c90x: Tx Reclaim Error (%hhX)", status);
553 a3c90x_reset();
554 } else if (status & 0x04) {
555 outputf("3c90x: Tx Status Overflow (%hhX)", status);
556 for (i=0; i<32; i++)
557 _outb(0x00, INF_3C90X.IOAddr + regTxStatus_b);
558 /** must re-enable after max collisions before re-issuing tx **/
559 _issue_command(INF_3C90X.IOAddr, cmdTxEnable, 0);
560 } else if (status & 0x08) {
561 outputf("3c90x: Tx Max Collisions (%hhX)", status);
562 /** must re-enable after max collisions before re-issuing tx **/
563 _issue_command(INF_3C90X.IOAddr, cmdTxEnable, 0);
564 } else if (status & 0x10) {
565 outputf("3c90x: Tx Underrun (%hhX)", status);
566 a3c90x_reset();
567 } else if (status & 0x20) {
568 outputf("3c90x: Tx Jabber (%hhX)", status);
569 a3c90x_reset();
570 } else if ((status & 0x80) != 0x80) {
571 outputf("3c90x: Internal Error - Incomplete Transmission (%hhX)", status);
572 a3c90x_reset();
573 }
574#endif
575}
576
577/***************************** Receive routines *****************************/
578#define MAX_RECV_SIZE 1536
579#define RECV_BUFS 16
580
581static rxdesc_t rxdescs[RECV_BUFS];
582static struct pbuf *rxpbufs[RECV_BUFS] = {0,};
583
584/* rxcons is the pointer to the receive descriptor that the ethernet card will
585 * write into next.
586 */
587static int rxcons = 0;
588
589/* rxprod is the pointer to the receive descriptor that the driver will
590 * allocate next.
591 */
592static int rxprod = 0;
593
594/* _recv_prepare fills the 3c90x's ring buffer with fresh pbufs from lwIP.
595 * The upload engine need not be stalled.
596 */
597static void _recv_prepare(struct nic *nic)
598{
599 int oldprod;
600
601 oldprod = rxprod;
602 while ((rxprod != rxcons) || !rxpbufs[rxprod])
603 {
604 int i;
605 struct pbuf *p;
606
607 if (!rxpbufs[rxprod])
608 rxpbufs[rxprod] = p = pbuf_alloc(PBUF_RAW, MAX_RECV_SIZE, PBUF_POOL);
609 else {
610 outputf("WARNING: 3c90x has pbuf in slot %d", rxprod);
611 p = rxpbufs[rxprod];
612 }
613
614 if (!p)
615 {
616 outputf("3c90x: out of memory for rx pbuf?");
617 break;
618 }
619
620 rxdescs[rxprod].status = 0;
621 rxdescs[rxprod].next = 0;
622 for (i = 0; p; p = p->next, i++)
623 {
624 rxdescs[rxprod].segments[i].addr = v2p(p->payload);
625 rxdescs[rxprod].segments[i].len = p->len | (p->next ? 0 : (1 << 31));
626 }
627
628 /* Hook in the new one after and only after it's been fully set up. */
629 rxdescs[(rxprod + RECV_BUFS - 1) % RECV_BUFS].next = v2p(&(rxdescs[rxprod]));
630 rxprod = (rxprod + 1) % RECV_BUFS;
631 }
632
633 if (inl(INF_3C90X.IOAddr + regUpListPtr_l) == 0 && rxpbufs[oldprod]) /* Ran out of shit, and got new shit? */
634 {
635 outl(INF_3C90X.IOAddr + regUpListPtr_l, v2p(&rxdescs[oldprod]));
636 outputf("3c90x: WARNING: Ran out of rx slots");
637 }
638
639}
640
641/* _recv polls the ring buffer to see if any packets are available. If any
642 * are, then eth_recv is called for each available. _recv returns how many
643 * packets it received successfully. Whether _recv got any packets or not,
644 * _recv does not block, and reinitializes the ring buffer with fresh pbufs.
645 */
646static int _recv(struct nic *nic)
647{
648 int errcode, n = 0;
649 struct pbuf *p;
650
651 /* Nothing to do? */
652 while ((rxdescs[rxcons].status & ((1<<14) | (1<<15))) != 0)
653 {
654 /** Check for Error (else we have good packet) **/
655 if (rxdescs[rxcons].status & (1<<14))
656 {
657 errcode = rxdescs[rxcons].status;
658 if (errcode & (1<<16))
659 outputf("3C90X: Rx Overrun (%hX)",errcode>>16);
660 else if (errcode & (1<<17))
661 outputf("3C90X: Runt Frame (%hX)",errcode>>16);
662 else if (errcode & (1<<18))
663 outputf("3C90X: Alignment Error (%hX)",errcode>>16);
664 else if (errcode & (1<<19))
665 outputf("3C90X: CRC Error (%hX)",errcode>>16);
666 else if (errcode & (1<<20))
667 outputf("3C90X: Oversized Frame (%hX)",errcode>>16);
668 else
669 outputf("3C90X: Packet error (%hX)",errcode>>16);
670
671 p = NULL;
672 pbuf_free(rxpbufs[rxcons]); /* Bounce the old one before setting it up again. */
673 } else {
674 p = rxpbufs[rxcons];
675 pbuf_realloc(p, rxdescs[rxcons].status & 0x1FFF); /* Resize the packet to how large it actually is. */
676 }
677
678 rxpbufs[rxcons] = NULL;
679 rxdescs[rxcons].status = 0;
680 rxcons = (rxcons + 1) % RECV_BUFS;
681
682 if (p)
683 {
684 eth_recv(nic, p);
685 n++;
686 }
687 }
688
689 _recv_prepare(nic); /* Light the NIC up again. */
690 return n;
691}
692
693/*** a3c90x_disable: exported routine to disable the card. What's this for?
694 *** the eepro100.c driver didn't have one, so I just left this one empty too.
695 *** Ideas anyone?
696 *** Must turn off receiver at least so stray packets will not corrupt memory
697 *** [Ken]
698 ***/
699void a3c90x_disable(struct dev *dev)
700{
701 /* reset and disable merge */
702 a3c90x_reset();
703 /* Disable the receiver and transmitter. */
704 _outw(cmdRxDisable, INF_3C90X.IOAddr + regCommandIntStatus_w);
705 _outw(cmdTxDisable, INF_3C90X.IOAddr + regCommandIntStatus_w);
706}
707
708
709/*** a3c90x_probe: exported routine to probe for the 3c905 card and perform
710 *** initialization. If this routine is called, the pci functions did find the
711 *** card. We just have to init it here.
712 ***/
713static int a3c90x_probe(struct pci_dev * pci, void * data)
714{
715 INF_3C90X.is3c556 = (pci->did == 0x6055);
716
717 int i, c;
718 unsigned short eeprom[0x100];
719 unsigned int cfg;
720 unsigned int mopt;
721 unsigned int mstat;
722 unsigned short linktype;
723#define HWADDR_OFFSET 10
724
725 unsigned long ioaddr = 0;
726 for (i = 0; i < 6; i++) {
727 if (pci->bars[i].type == PCI_BAR_IO) {
728 ioaddr = pci->bars[i].addr;
729 break;
730 }
731 }
732
733 if (ioaddr == 0)
734 {
735 outputf("3c90x: Unable to find I/O address");
736 return 0;
737 }
738
739 /* Power it on */
740 pci_write16(pci->bus, pci->dev, pci->fn, 0xE0,
741 pci_read16(pci->bus, pci->dev, pci->fn, 0xE0) & ~0x3);
742
743 outputf("3c90x: Picked I/O address %04x", ioaddr);
744 pci_bother_add(pci);
745 nic.ioaddr = ioaddr & ~3;
746 nic.irqno = 0;
747
748 INF_3C90X.IOAddr = ioaddr;
749 INF_3C90X.CurrentWindow = 255;
750 switch (a3c90x_internal_ReadEeprom(INF_3C90X.IOAddr, 0x03))
751 {
752 case 0x9000: /** 10 Base TPO **/
753 case 0x9001: /** 10/100 T4 **/
754 case 0x9050: /** 10/100 TPO **/
755 case 0x9051: /** 10 Base Combo **/
756 INF_3C90X.isBrev = 0;
757 break;
758
759 case 0x9004: /** 10 Base TPO **/
760 case 0x9005: /** 10 Base Combo **/
761 case 0x9006: /** 10 Base TPO and Base2 **/
762 case 0x900A: /** 10 Base FL **/
763 case 0x9055: /** 10/100 TPO **/
764 case 0x9056: /** 10/100 T4 **/
765 case 0x905A: /** 10 Base FX **/
766 default:
767 INF_3C90X.isBrev = 1;
768 break;
769 }
770
771 /** Load the EEPROM contents **/
772 if (INF_3C90X.isBrev)
773 {
774 for(i=0;i<=/*0x20*/0x7F;i++)
775 {
776 eeprom[i] = a3c90x_internal_ReadEeprom(INF_3C90X.IOAddr, i);
777 }
778
779#ifdef CFG_3C90X_BOOTROM_FIX
780 /** Set xcvrSelect in InternalConfig in eeprom. **/
781 /* only necessary for 3c905b revision cards with boot PROM bug!!! */
782 a3c90x_internal_WriteEeprom(INF_3C90X.IOAddr, 0x13, 0x0160);
783#endif
784
785#ifdef CFG_3C90X_XCVR
786 if (CFG_3C90X_XCVR == 255)
787 {
788 /** Clear the LanWorks register **/
789 a3c90x_internal_WriteEeprom(INF_3C90X.IOAddr, 0x16, 0);
790 }
791 else
792 {
793 /** Set the selected permanent-xcvrSelect in the
794 ** LanWorks register
795 **/
796 a3c90x_internal_WriteEeprom(INF_3C90X.IOAddr, 0x16,
797 XCVR_MAGIC + ((CFG_3C90X_XCVR) & 0x000F));
798 }
799#endif
800 }
801 else
802 {
803 for(i=0;i<=/*0x17*/0x7F;i++)
804 {
805 eeprom[i] = a3c90x_internal_ReadEeprom(INF_3C90X.IOAddr, i);
806 }
807 }
808
809 /** Print identification message **/
810#ifdef CFG_3C90X_BOOTROM_FIX
811 if (INF_3C90X.isBrev)
812 {
813 outputf("NOTE: 3c905b bootrom fix enabled; has side "
814 "effects. See 3c90x.txt for info.");
815 }
816#endif
817
818 /** Retrieve the Hardware address and print it on the screen. **/
819 INF_3C90X.HWAddr[0] = eeprom[HWADDR_OFFSET + 0]>>8;
820 INF_3C90X.HWAddr[1] = eeprom[HWADDR_OFFSET + 0]&0xFF;
821 INF_3C90X.HWAddr[2] = eeprom[HWADDR_OFFSET + 1]>>8;
822 INF_3C90X.HWAddr[3] = eeprom[HWADDR_OFFSET + 1]&0xFF;
823 INF_3C90X.HWAddr[4] = eeprom[HWADDR_OFFSET + 2]>>8;
824 INF_3C90X.HWAddr[5] = eeprom[HWADDR_OFFSET + 2]&0xFF;
825 outputf("MAC Address = %02x:%02x:%02x:%02x:%02x:%02x",
826 INF_3C90X.HWAddr[0],
827 INF_3C90X.HWAddr[1],
828 INF_3C90X.HWAddr[2],
829 INF_3C90X.HWAddr[3],
830 INF_3C90X.HWAddr[4],
831 INF_3C90X.HWAddr[5]);
832
833 /** 3C556: Invert MII power **/
834 if (INF_3C90X.is3c556) {
835 unsigned int tmp;
836 _set_window(INF_3C90X.IOAddr, winAddressing2);
837 tmp = inw(INF_3C90X.IOAddr + regResetOptions_2_w);
838 tmp |= 0x4000;
839 _outw(tmp, INF_3C90X.IOAddr + regResetOptions_2_w);
840 }
841
842 /* Test if the link is good, if not continue */
843 _set_window(INF_3C90X.IOAddr, winDiagnostics4);
844 mstat = inw(INF_3C90X.IOAddr + regMediaStatus_4_w);
845 if((mstat & (1<<11)) == 0) {
846 outputf("Valid link not established");
847 return 0;
848 }
849
850 /** Program the MAC address into the station address registers **/
851 _set_window(INF_3C90X.IOAddr, winAddressing2);
852 _outw(htons(eeprom[HWADDR_OFFSET + 0]), INF_3C90X.IOAddr + regStationAddress_2_3w);
853 _outw(htons(eeprom[HWADDR_OFFSET + 1]), INF_3C90X.IOAddr + regStationAddress_2_3w+2);
854 _outw(htons(eeprom[HWADDR_OFFSET + 2]), INF_3C90X.IOAddr + regStationAddress_2_3w+4);
855 _outw(0, INF_3C90X.IOAddr + regStationMask_2_3w+0);
856 _outw(0, INF_3C90X.IOAddr + regStationMask_2_3w+2);
857 _outw(0, INF_3C90X.IOAddr + regStationMask_2_3w+4);
858
859 /** Read the media options register, print a message and set default
860 ** xcvr.
861 **
862 ** Uses Media Option command on B revision, Reset Option on non-B
863 ** revision cards -- same register address
864 **/
865 _set_window(INF_3C90X.IOAddr, winTxRxOptions3);
866 mopt = inw(INF_3C90X.IOAddr + regResetMediaOptions_3_w);
867
868 /** mask out VCO bit that is defined as 10baseFL bit on B-rev cards **/
869 if (! INF_3C90X.isBrev)
870 {
871 mopt &= 0x7F;
872 }
873
874 outputf("Connectors present: ");
875 c = 0;
876 linktype = 0x0008;
877 if (mopt & 0x01)
878 {
879 outputf(" 100Base-T4");
880 linktype = 0x0006;
881 }
882 if (mopt & 0x04)
883 {
884 outputf(" 100Base-FX");
885 linktype = 0x0005;
886 }
887 if (mopt & 0x10)
888 {
889 outputf(" 10Base-2");
890 linktype = 0x0003;
891 }
892 if (mopt & 0x20)
893 {
894 outputf(" AUI");
895 linktype = 0x0001;
896 }
897 if (mopt & 0x40)
898 {
899 outputf(" MII");
900 linktype = 0x0006;
901 }
902 if ((mopt & 0xA) == 0xA)
903 {
904 outputf(" 10Base-T / 100Base-TX");
905 linktype = 0x0008;
906 }
907 else if ((mopt & 0xA) == 0x2)
908 {
909 outputf(" 100Base-TX");
910 linktype = 0x0008;
911 }
912 else if ((mopt & 0xA) == 0x8)
913 {
914 outputf(" 10Base-T");
915 linktype = 0x0008;
916 }
917
918 /** Determine transceiver type to use, depending on value stored in
919 ** eeprom 0x16
920 **/
921 if (INF_3C90X.isBrev)
922 {
923 if ((eeprom[0x16] & 0xFF00) == XCVR_MAGIC)
924 {
925 /** User-defined **/
926 linktype = eeprom[0x16] & 0x000F;
927 }
928 }
929 else
930 {
931#ifdef CFG_3C90X_XCVR
932 if (CFG_3C90X_XCVR != 255)
933 linktype = CFG_3C90X_XCVR;
934#endif /* CFG_3C90X_XCVR */
935
936 /** I don't know what MII MAC only mode is!!! **/
937 if (linktype == 0x0009)
938 {
939 if (INF_3C90X.isBrev)
940 outputf("WARNING: MII External MAC Mode only supported on B-revision "
941 "cards!!!!\nFalling Back to MII Mode\n");
942 linktype = 0x0006;
943 }
944 }
945
946 /** enable DC converter for 10-Base-T **/
947 if (linktype == 0x0003)
948 {
949 _issue_command(INF_3C90X.IOAddr, cmdEnableDcConverter, 0);
950 }
951
952 /** Set the link to the type we just determined. **/
953 _set_window(INF_3C90X.IOAddr, winTxRxOptions3);
954 cfg = inl(INF_3C90X.IOAddr + regInternalConfig_3_l);
955 cfg &= ~(0xF<<20);
956 cfg |= (linktype<<20);
957 _outl(cfg, INF_3C90X.IOAddr + regInternalConfig_3_l);
958
959 /** Now that we set the xcvr type, reset the Tx and Rx, re-enable. **/
960 _issue_command(INF_3C90X.IOAddr, cmdTxReset, 0);
961 if (!INF_3C90X.isBrev)
962 _outb(0x01, INF_3C90X.IOAddr + regTxFreeThresh_b);
963
964 _issue_command(INF_3C90X.IOAddr, cmdTxEnable, 0);
965
966 /**
967 ** reset of the receiver on B-revision cards re-negotiates the link
968 ** takes several seconds (a computer eternity)
969 **/
970 if (INF_3C90X.isBrev)
971 _issue_command(INF_3C90X.IOAddr, cmdRxReset, 0x04);
972 else
973 _issue_command(INF_3C90X.IOAddr, cmdRxReset, 0x00);
974
975 /** Set the RX filter = receive only individual pkts & multicast & bcast. **/
976 _issue_command(INF_3C90X.IOAddr, cmdSetRxFilter, 0x01 + 0x02 + 0x04);
977
978 /* Stick some packets in the queue. */
979 _recv_prepare(&nic);
980
981 /* And light up the RX engine. */
982 _issue_command(INF_3C90X.IOAddr, cmdRxEnable, 0);
983
984 /**
985 ** set Indication and Interrupt flags , acknowledge any IRQ's
986 **/
987 _issue_command(INF_3C90X.IOAddr, cmdSetInterruptEnable, 0);
988 _issue_command(INF_3C90X.IOAddr, cmdSetIndicationEnable, 0x0014);
989 _issue_command(INF_3C90X.IOAddr, cmdAcknowledgeInterrupt, 0x661);
990
991 /* * Set our exported functions **/
992 nic.recv = _recv;
993 nic.transmit = _transmit;
994 memcpy(nic.hwaddr, INF_3C90X.HWAddr, 6);
995 eth_register(&nic);
996
997 return 1;
998}
999
1000static struct pci_id a3c90x_nics[] = {
1001/* Original 90x revisions: */
1002PCI_ROM(0x10b7, 0x6055, "3c556", "3C556"), /* Huricane */
1003PCI_ROM(0x10b7, 0x9000, "3c905-tpo", "3Com900-TPO"), /* 10 Base TPO */
1004PCI_ROM(0x10b7, 0x9001, "3c905-t4", "3Com900-Combo"), /* 10/100 T4 */
1005PCI_ROM(0x10b7, 0x9050, "3c905-tpo100", "3Com905-TX"), /* 100 Base TX / 10/100 TPO */
1006PCI_ROM(0x10b7, 0x9051, "3c905-combo", "3Com905-T4"), /* 100 Base T4 / 10 Base Combo */
1007/* Newer 90xB revisions: */
1008PCI_ROM(0x10b7, 0x9004, "3c905b-tpo", "3Com900B-TPO"), /* 10 Base TPO */
1009PCI_ROM(0x10b7, 0x9005, "3c905b-combo", "3Com900B-Combo"), /* 10 Base Combo */
1010PCI_ROM(0x10b7, 0x9006, "3c905b-tpb2", "3Com900B-2/T"), /* 10 Base TP and Base2 */
1011PCI_ROM(0x10b7, 0x900a, "3c905b-fl", "3Com900B-FL"), /* 10 Base FL */
1012PCI_ROM(0x10b7, 0x9055, "3c905b-tpo100", "3Com905B-TX"), /* 10/100 TPO */
1013PCI_ROM(0x10b7, 0x9056, "3c905b-t4", "3Com905B-T4"), /* 10/100 T4 */
1014PCI_ROM(0x10b7, 0x9058, "3c905b-9058", "3Com905B-9058"), /* Cyclone 10/100/BNC */
1015PCI_ROM(0x10b7, 0x905a, "3c905b-fx", "3Com905B-FL"), /* 100 Base FX / 10 Base FX */
1016/* Newer 90xC revision: */
1017PCI_ROM(0x10b7, 0x9200, "3c905c-tpo", "3Com905C-TXM"), /* 10/100 TPO (3C905C-TXM) */
1018PCI_ROM(0x10b7, 0x9202, "3c920b-emb-ati", "3c920B-EMB-WNM (ATI Radeon 9100 IGP)"), /* 3c920B-EMB-WNM (ATI Radeon 9100 IGP) */
1019PCI_ROM(0x10b7, 0x9210, "3c920b-emb-wnm","3Com20B-EMB WNM"),
1020PCI_ROM(0x10b7, 0x9800, "3c980", "3Com980-Cyclone"), /* Cyclone */
1021PCI_ROM(0x10b7, 0x9805, "3c9805", "3Com9805"), /* Dual Port Server Cyclone */
1022PCI_ROM(0x10b7, 0x7646, "3csoho100-tx", "3CSOHO100-TX"), /* Hurricane */
1023PCI_ROM(0x10b7, 0x4500, "3c450", "3Com450 HomePNA Tornado"),
1024PCI_ROM(0x10b7, 0x1201, "3c982a", "3Com982A"),
1025PCI_ROM(0x10b7, 0x1202, "3c982b", "3Com982B"),
1026};
1027
1028struct pci_driver a3c90x_driver = {
1029 .name = "3C90X",
1030 .probe = a3c90x_probe,
1031 .ids = a3c90x_nics,
1032 .id_count = sizeof(a3c90x_nics)/sizeof(a3c90x_nics[0]),
1033};
This page took 0.03774 seconds and 4 git commands to generate.