]> Joshua Wise's Git repositories - netwatch.git/blame - net/3c90x.c
rearrangements
[netwatch.git] / net / 3c90x.c
CommitLineData
748534f4
JP
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 <timer.h>
42#include <io.h>
43#include <pci.h>
44#include <minilib.h>
45#include <output.h>
46
47#define XCVR_MAGIC (0x5A00)
48/** any single transmission fails after 16 collisions or other errors
49 ** this is the number of times to retry the transmission -- this should
50 ** be plenty
51 **/
52#define XMIT_RETRIES 250
53
54/*** Register definitions for the 3c905 ***/
55enum Registers
56 {
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 **/
85enum Registers7
86 {
87 regPowerMgmtEvent_7_w = 0x0c, /** 905B Revision Only **/
88 regVlanEtherType_7_w = 0x04, /** 905B Revision Only **/
89 regVlanMask_7_w = 0x00, /** 905B Revision Only **/
90 };
91
92enum Registers6
93 {
94 regBytesXmittedOk_6_w = 0x0c, /** Universal **/
95 regBytesRcvdOk_6_w = 0x0a, /** Universal **/
96 regUpperFramesOk_6_b = 0x09, /** Universal **/
97 regFramesDeferred_6_b = 0x08, /** Universal **/
98 regFramesRecdOk_6_b = 0x07, /** Universal with Exceptions, pg 142 **/
99 regFramesXmittedOk_6_b = 0x06, /** Universal **/
100 regRxOverruns_6_b = 0x05, /** Universal **/
101 regLateCollisions_6_b = 0x04, /** Universal **/
102 regSingleCollisions_6_b = 0x03, /** Universal **/
103 regMultipleCollisions_6_b = 0x02, /** Universal **/
104 regSqeErrors_6_b = 0x01, /** Universal **/
105 regCarrierLost_6_b = 0x00, /** Universal **/
106 };
107
108enum Registers5
109 {
110 regIndicationEnable_5_w = 0x0c, /** Universal **/
111 regInterruptEnable_5_w = 0x0a, /** Universal **/
112 regTxReclaimThresh_5_b = 0x09, /** 905B Revision Only **/
113 regRxFilter_5_b = 0x08, /** Universal **/
114 regRxEarlyThresh_5_w = 0x06, /** Universal **/
115 regTxStartThresh_5_w = 0x00, /** Universal **/
116 };
117
118enum Registers4
119 {
120 regUpperBytesOk_4_b = 0x0d, /** Universal **/
121 regBadSSD_4_b = 0x0c, /** Universal **/
122 regMediaStatus_4_w = 0x0a, /** Universal with Exceptions, pg 201 **/
123 regPhysicalMgmt_4_w = 0x08, /** Universal **/
124 regNetworkDiagnostic_4_w = 0x06, /** Universal with Exceptions, pg 203 **/
125 regFifoDiagnostic_4_w = 0x04, /** Universal with Exceptions, pg 196 **/
126 regVcoDiagnostic_4_w = 0x02, /** Undocumented? **/
127 };
128
129enum Registers3
130 {
131 regTxFree_3_w = 0x0c, /** Universal **/
132 regRxFree_3_w = 0x0a, /** Universal with Exceptions, pg 125 **/
133 regResetMediaOptions_3_w = 0x08, /** Media Options on B Revision, **/
134 /** Reset Options on Non-B Revision **/
135 regMacControl_3_w = 0x06, /** Universal with Exceptions, pg 199 **/
136 regMaxPktSize_3_w = 0x04, /** 905B Revision Only **/
137 regInternalConfig_3_l = 0x00, /** Universal, different bit **/
138 /** definitions, pg 59 **/
139 };
140
141enum Registers2
142 {
143 regResetOptions_2_w = 0x0c, /** 905B Revision Only **/
144 regStationMask_2_3w = 0x06, /** Universal with Exceptions, pg 127 **/
145 regStationAddress_2_3w = 0x00, /** Universal with Exceptions, pg 127 **/
146 };
147
148enum Registers1
149 {
150 regRxStatus_1_w = 0x0a, /** 90X Revision Only, Pg 126 **/
151 };
152
153enum Registers0
154 {
155 regEepromData_0_w = 0x0c, /** Universal **/
156 regEepromCommand_0_w = 0x0a, /** Universal **/
157 regBiosRomData_0_b = 0x08, /** 905B Revision Only **/
158 regBiosRomAddr_0_l = 0x04, /** 905B Revision Only **/
159 };
160
161
162/*** The names for the eight register windows ***/
163enum Windows
164 {
165 winPowerVlan7 = 0x07,
166 winStatistics6 = 0x06,
167 winTxRxControl5 = 0x05,
168 winDiagnostics4 = 0x04,
169 winTxRxOptions3 = 0x03,
170 winAddressing2 = 0x02,
171 winUnused1 = 0x01,
172 winEepromBios0 = 0x00,
173 };
174
175
176/*** Command definitions for the 3c90X ***/
177enum Commands
178 {
179 cmdGlobalReset = 0x00, /** Universal with Exceptions, pg 151 **/
180 cmdSelectRegisterWindow = 0x01, /** Universal **/
181 cmdEnableDcConverter = 0x02, /** **/
182 cmdRxDisable = 0x03, /** **/
183 cmdRxEnable = 0x04, /** Universal **/
184 cmdRxReset = 0x05, /** Universal **/
185 cmdStallCtl = 0x06, /** Universal **/
186 cmdTxEnable = 0x09, /** Universal **/
187 cmdTxDisable = 0x0A, /** **/
188 cmdTxReset = 0x0B, /** Universal **/
189 cmdRequestInterrupt = 0x0C, /** **/
190 cmdAcknowledgeInterrupt = 0x0D, /** Universal **/
191 cmdSetInterruptEnable = 0x0E, /** Universal **/
192 cmdSetIndicationEnable = 0x0F, /** Universal **/
193 cmdSetRxFilter = 0x10, /** Universal **/
194 cmdSetRxEarlyThresh = 0x11, /** **/
195 cmdSetTxStartThresh = 0x13, /** **/
196 cmdStatisticsEnable = 0x15, /** **/
197 cmdStatisticsDisable = 0x16, /** **/
198 cmdDisableDcConverter = 0x17, /** **/
199 cmdSetTxReclaimThresh = 0x18, /** **/
200 cmdSetHashFilterBit = 0x19, /** **/
201 };
202
203
204/*** Values for int status register bitmask **/
205#define INT_INTERRUPTLATCH (1<<0)
206#define INT_HOSTERROR (1<<1)
207#define INT_TXCOMPLETE (1<<2)
208#define INT_RXCOMPLETE (1<<4)
209#define INT_RXEARLY (1<<5)
210#define INT_INTREQUESTED (1<<6)
211#define INT_UPDATESTATS (1<<7)
212#define INT_LINKEVENT (1<<8)
213#define INT_DNCOMPLETE (1<<9)
214#define INT_UPCOMPLETE (1<<10)
215#define INT_CMDINPROGRESS (1<<12)
216#define INT_WINDOWNUMBER (7<<13)
217
218
219/*** TX descriptor ***/
220typedef struct
221 {
222 unsigned int DnNextPtr;
223 unsigned int FrameStartHeader;
224 unsigned int HdrAddr;
225 unsigned int HdrLength;
226 unsigned int DataAddr;
227 unsigned int DataLength;
228 }
229 TXD __attribute__ ((aligned(8))); /* 64-bit aligned for bus mastering */
230
231/*** RX descriptor ***/
232typedef struct
233 {
234 unsigned int UpNextPtr;
235 unsigned int UpPktStatus;
236 unsigned int DataAddr;
237 unsigned int DataLength;
238 }
239 RXD __attribute__ ((aligned(8))); /* 64-bit aligned for bus mastering */
240
241/*** Global variables ***/
242static struct
243 {
244 unsigned int is3c556;
245 unsigned char isBrev;
246 unsigned char CurrentWindow;
247 unsigned int IOAddr;
248 unsigned char HWAddr[ETH_ALEN];
249 TXD TransmitDPD;
250 RXD ReceiveUPD;
251 }
252 INF_3C90X;
253
254
255/*** a3c90x_internal_IssueCommand: sends a command to the 3c90x card
256 ***/
257static int
258a3c90x_internal_IssueCommand(int ioaddr, int cmd, int param)
259 {
260 unsigned int val;
261
262 /** Build the cmd. **/
263 val = cmd;
264 val <<= 11;
265 val |= param;
266
267 /** Send the cmd to the cmd register **/
268 outw(val, ioaddr + regCommandIntStatus_w);
269
270 /** Wait for the cmd to complete, if necessary **/
271 while (inw(ioaddr + regCommandIntStatus_w) & INT_CMDINPROGRESS);
272
273 return 0;
274 }
275
276
277/*** a3c90x_internal_SetWindow: selects a register window set.
278 ***/
279static int
280a3c90x_internal_SetWindow(int ioaddr, int window)
281 {
282
283 /** Window already as set? **/
284 if (INF_3C90X.CurrentWindow == window) return 0;
285
286 /** Issue the window command. **/
287 a3c90x_internal_IssueCommand(ioaddr, cmdSelectRegisterWindow, window);
288 INF_3C90X.CurrentWindow = window;
289
290 return 0;
291 }
292
293
294/*** a3c90x_internal_ReadEeprom - read data from the serial eeprom.
295 ***/
296static unsigned short
297a3c90x_internal_ReadEeprom(int ioaddr, int address)
298 {
299 unsigned short val;
300
301 /** Select correct window **/
302 a3c90x_internal_SetWindow(INF_3C90X.IOAddr, winEepromBios0);
303
304 /** Make sure the eeprom isn't busy **/
305 while((1<<15) & inw(ioaddr + regEepromCommand_0_w));
306
307 /** Read the value. **/
308 if (INF_3C90X.is3c556)
309 {
310 outw(address + (0x230), ioaddr + regEepromCommand_0_w);
311 }
312 else
313 {
314 outw(address + ((0x02)<<6), ioaddr + regEepromCommand_0_w);
315 }
316
317 while((1<<15) & inw(ioaddr + regEepromCommand_0_w));
318 val = inw(ioaddr + regEepromData_0_w);
319
320 return val;
321 }
322
323
324#ifdef CFG_3C90X_BOOTROM_FIX
325/*** a3c90x_internal_WriteEepromWord - write a physical word of
326 *** data to the onboard serial eeprom (not the BIOS prom, but the
327 *** nvram in the card that stores, among other things, the MAC
328 *** address).
329 ***/
330static int
331a3c90x_internal_WriteEepromWord(int ioaddr, int address, unsigned short value)
332 {
333 /** Select register window **/
334 a3c90x_internal_SetWindow(ioaddr, winEepromBios0);
335
336 /** Verify Eeprom not busy **/
337 while((1<<15) & inw(ioaddr + regEepromCommand_0_w));
338
339 /** Issue WriteEnable, and wait for completion. **/
340 outw(0x30, ioaddr + regEepromCommand_0_w);
341 while((1<<15) & inw(ioaddr + regEepromCommand_0_w));
342
343 /** Issue EraseRegister, and wait for completion. **/
344 outw(address + ((0x03)<<6), ioaddr + regEepromCommand_0_w);
345 while((1<<15) & inw(ioaddr + regEepromCommand_0_w));
346
347 /** Send the new data to the eeprom, and wait for completion. **/
348 outw(value, ioaddr + regEepromData_0_w);
349 outw(0x30, ioaddr + regEepromCommand_0_w);
350 while((1<<15) & inw(ioaddr + regEepromCommand_0_w));
351
352 /** Burn the new data into the eeprom, and wait for completion. **/
353 outw(address + ((0x01)<<6), ioaddr + regEepromCommand_0_w);
354 while((1<<15) & inw(ioaddr + regEepromCommand_0_w));
355
356 return 0;
357 }
358#endif
359
360#ifdef CFG_3C90X_BOOTROM_FIX
361/*** a3c90x_internal_WriteEeprom - write data to the serial eeprom,
362 *** and re-compute the eeprom checksum.
363 ***/
364static int
365a3c90x_internal_WriteEeprom(int ioaddr, int address, unsigned short value)
366 {
367 int cksum = 0,v;
368 int i;
369 int maxAddress, cksumAddress;
370
371 if (INF_3C90X.isBrev)
372 {
373 maxAddress=0x1f;
374 cksumAddress=0x20;
375 }
376 else
377 {
378 maxAddress=0x16;
379 cksumAddress=0x17;
380 }
381
382 /** Write the value. **/
383 if (a3c90x_internal_WriteEepromWord(ioaddr, address, value) == -1)
384 return -1;
385
386 /** Recompute the checksum. **/
387 for(i=0;i<=maxAddress;i++)
388 {
389 v = a3c90x_internal_ReadEeprom(ioaddr, i);
390 cksum ^= (v & 0xFF);
391 cksum ^= ((v>>8) & 0xFF);
392 }
393 /** Write the checksum to the location in the eeprom **/
394 if (a3c90x_internal_WriteEepromWord(ioaddr, cksumAddress, cksum) == -1)
395 return -1;
396
397 return 0;
398 }
399#endif
400
401/*** a3c90x_reset: exported function that resets the card to its default
402 *** state. This is so the Linux driver can re-set the card up the way
403 *** it wants to. If CFG_3C90X_PRESERVE_XCVR is defined, then the reset will
404 *** not alter the selected transceiver that we used to download the boot
405 *** image.
406 ***/
407static void a3c90x_reset(void)
408 {
409#ifdef CFG_3C90X_PRESERVE_XCVR
410 int cfg;
411 /** Read the current InternalConfig value. **/
412 a3c90x_internal_SetWindow(INF_3C90X.IOAddr, winTxRxOptions3);
413 cfg = inl(INF_3C90X.IOAddr + regInternalConfig_3_l);
414#endif
415
416 /** Send the reset command to the card **/
417 outputf("Issuing RESET:");
418 a3c90x_internal_IssueCommand(INF_3C90X.IOAddr, cmdGlobalReset, 0);
419
420 /** wait for reset command to complete **/
421 while (inw(INF_3C90X.IOAddr + regCommandIntStatus_w) & INT_CMDINPROGRESS);
422
423 /** global reset command resets station mask, non-B revision cards
424 ** require explicit reset of values
425 **/
426 a3c90x_internal_SetWindow(INF_3C90X.IOAddr, winAddressing2);
427 outw(0, INF_3C90X.IOAddr + regStationMask_2_3w+0);
428 outw(0, INF_3C90X.IOAddr + regStationMask_2_3w+2);
429 outw(0, INF_3C90X.IOAddr + regStationMask_2_3w+4);
430
431#ifdef CFG_3C90X_PRESERVE_XCVR
432 /** Re-set the original InternalConfig value from before reset **/
433 a3c90x_internal_SetWindow(INF_3C90X.IOAddr, winTxRxOptions3);
434 outl(cfg, INF_3C90X.IOAddr + regInternalConfig_3_l);
435
436 /** enable DC converter for 10-Base-T **/
437 if ((cfg&0x0300) == 0x0300)
438 {
439 a3c90x_internal_IssueCommand(INF_3C90X.IOAddr, cmdEnableDcConverter, 0);
440 }
441#endif
442
443 /** Issue transmit reset, wait for command completion **/
444 a3c90x_internal_IssueCommand(INF_3C90X.IOAddr, cmdTxReset, 0);
445 while (inw(INF_3C90X.IOAddr + regCommandIntStatus_w) & INT_CMDINPROGRESS)
446 ;
447 if (! INF_3C90X.isBrev)
448 outb(0x01, INF_3C90X.IOAddr + regTxFreeThresh_b);
449 a3c90x_internal_IssueCommand(INF_3C90X.IOAddr, cmdTxEnable, 0);
450
451 /**
452 ** reset of the receiver on B-revision cards re-negotiates the link
453 ** takes several seconds (a computer eternity)
454 **/
455 if (INF_3C90X.isBrev)
456 a3c90x_internal_IssueCommand(INF_3C90X.IOAddr, cmdRxReset, 0x04);
457 else
458 a3c90x_internal_IssueCommand(INF_3C90X.IOAddr, cmdRxReset, 0x00);
459 while (inw(INF_3C90X.IOAddr + regCommandIntStatus_w) & INT_CMDINPROGRESS);
460 ;
461 a3c90x_internal_IssueCommand(INF_3C90X.IOAddr, cmdRxEnable, 0);
462
463 a3c90x_internal_IssueCommand(INF_3C90X.IOAddr,
464 cmdSetInterruptEnable, 0);
465 /** enable rxComplete and txComplete **/
466 a3c90x_internal_IssueCommand(INF_3C90X.IOAddr,
467 cmdSetIndicationEnable, 0x0014);
468 /** acknowledge any pending status flags **/
469 a3c90x_internal_IssueCommand(INF_3C90X.IOAddr,
470 cmdAcknowledgeInterrupt, 0x661);
471
472 return;
473 }
474
475
476
477/*** a3c90x_transmit: exported function that transmits a packet. Does not
478 *** return any particular status. Parameters are:
479 *** dest_addr[6] - destination address, ethernet;
480 *** proto - protocol type (ARP, IP, etc);
481 *** size - size of the non-header part of the packet that needs transmitted;
482 *** pkt - the pointer to the packet data itself.
483 ***/
484static void
485a3c90x_transmit(const char *dest_addr, unsigned int proto,
486 unsigned int size, const char *pkt)
487 {
488
489 struct eth_hdr
490 {
491 unsigned char dst_addr[ETH_ALEN];
492 unsigned char src_addr[ETH_ALEN];
493 unsigned short type;
494 } hdr;
495
496 unsigned char status;
497 unsigned i, retries;
498
499 for (retries=0; retries < XMIT_RETRIES ; retries++)
500 {
501 /** Stall the download engine **/
502 a3c90x_internal_IssueCommand(INF_3C90X.IOAddr, cmdStallCtl, 2);
503
504 /** Make sure the card is not waiting on us **/
505 inw(INF_3C90X.IOAddr + regCommandIntStatus_w);
506 inw(INF_3C90X.IOAddr + regCommandIntStatus_w);
507
508 while (inw(INF_3C90X.IOAddr+regCommandIntStatus_w) &
509 INT_CMDINPROGRESS)
510 ;
511
512 /** Set the ethernet packet type **/
513 hdr.type = htons(proto);
514
515 /** Copy the destination address **/
516 memcpy(hdr.dst_addr, dest_addr, ETH_ALEN);
517
518 /** Copy our MAC address **/
519 memcpy(hdr.src_addr, INF_3C90X.HWAddr, ETH_ALEN);
520
521 /** Setup the DPD (download descriptor) **/
522 INF_3C90X.TransmitDPD.DnNextPtr = 0;
523 /** set notification for transmission completion (bit 15) **/
524 INF_3C90X.TransmitDPD.FrameStartHeader = (size + sizeof(hdr)) | 0x8000;
525 INF_3C90X.TransmitDPD.HdrAddr = virt_to_bus(&hdr);
526 INF_3C90X.TransmitDPD.HdrLength = sizeof(hdr);
527 INF_3C90X.TransmitDPD.DataAddr = virt_to_bus(pkt);
528 INF_3C90X.TransmitDPD.DataLength = size + (1<<31);
529
530 /** Send the packet **/
531 outl(virt_to_bus(&(INF_3C90X.TransmitDPD)),
532 INF_3C90X.IOAddr + regDnListPtr_l);
533
534 /** End Stall and Wait for upload to complete. **/
535 a3c90x_internal_IssueCommand(INF_3C90X.IOAddr, cmdStallCtl, 3);
536 while(inl(INF_3C90X.IOAddr + regDnListPtr_l) != 0)
537 ;
538
539 /** Wait for NIC Transmit to Complete **/
540 oneshot_start_ms(10); /* Give it 10 ms */
541 while (!(inw(INF_3C90X.IOAddr + regCommandIntStatus_w)&0x0004) &&
542 oneshot_running())
543 ;
544
545 if (!(inw(INF_3C90X.IOAddr + regCommandIntStatus_w)&0x0004))
546 {
547 outputf("3C90X: Tx Timeout");
548 continue;
549 }
550
551 status = inb(INF_3C90X.IOAddr + regTxStatus_b);
552
553 /** acknowledge transmit interrupt by writing status **/
554 outb(0x00, INF_3C90X.IOAddr + regTxStatus_b);
555
556 /** successful completion (sans "interrupt Requested" bit) **/
557 if ((status & 0xbf) == 0x80)
558 return;
559
560 outputf("3C90X: Status (%hhX)", status);
561 /** check error codes **/
562 if (status & 0x02)
563 {
564 outputf("3C90X: Tx Reclaim Error (%hhX)", status);
565 a3c90x_reset();
566 }
567 else if (status & 0x04)
568 {
569 outputf("3C90X: Tx Status Overflow (%hhX)", status);
570 for (i=0; i<32; i++)
571 outb(0x00, INF_3C90X.IOAddr + regTxStatus_b);
572 /** must re-enable after max collisions before re-issuing tx **/
573 a3c90x_internal_IssueCommand(INF_3C90X.IOAddr, cmdTxEnable, 0);
574 }
575 else if (status & 0x08)
576 {
577 outputf("3C90X: Tx Max Collisions (%hhX)", status);
578 /** must re-enable after max collisions before re-issuing tx **/
579 a3c90x_internal_IssueCommand(INF_3C90X.IOAddr, cmdTxEnable, 0);
580 }
581 else if (status & 0x10)
582 {
583 outputf("3C90X: Tx Underrun (%hhX)", status);
584 a3c90x_reset();
585 }
586 else if (status & 0x20)
587 {
588 outputf("3C90X: Tx Jabber (%hhX)", status);
589 a3c90x_reset();
590 }
591 else if ((status & 0x80) != 0x80)
592 {
593 outputf("3C90X: Internal Error - Incomplete Transmission (%hhX)",
594 status);
595 a3c90x_reset();
596 }
597 }
598
599 /** failed after RETRY attempts **/
600 outputf("Failed to send after %d retries", retries);
601 return;
602
603 }
604
605
606
607/*** a3c90x_poll: exported routine that waits for a certain length of time
608 *** for a packet, and if it sees none, returns 0. This routine should
609 *** copy the packet to nic->packet if it gets a packet and set the size
610 *** in nic->packetlen. Return 1 if a packet was found.
611 ***/
612static int
613a3c90x_poll(struct nic *nic, int retrieve)
614 {
615 int i, errcode;
616
617 if (!(inw(INF_3C90X.IOAddr + regCommandIntStatus_w)&0x0010))
618 {
619 return 0;
620 }
621
622 if ( ! retrieve ) return 1;
623
624 /** we don't need to acknowledge rxComplete -- the upload engine
625 ** does it for us.
626 **/
627
628 /** Build the up-load descriptor **/
629 INF_3C90X.ReceiveUPD.UpNextPtr = 0;
630 INF_3C90X.ReceiveUPD.UpPktStatus = 0;
631 INF_3C90X.ReceiveUPD.DataAddr = virt_to_bus(nic->packet);
632 INF_3C90X.ReceiveUPD.DataLength = 1536 + (1<<31);
633
634 /** Submit the upload descriptor to the NIC **/
635 outl(virt_to_bus(&(INF_3C90X.ReceiveUPD)),
636 INF_3C90X.IOAddr + regUpListPtr_l);
637
638 /** Wait for upload completion (upComplete(15) or upError (14)) **/
639 for(i=0;i<40000;i++);
640 while((INF_3C90X.ReceiveUPD.UpPktStatus & ((1<<14) | (1<<15))) == 0)
641 for(i=0;i<40000;i++);
642
643 /** Check for Error (else we have good packet) **/
644 if (INF_3C90X.ReceiveUPD.UpPktStatus & (1<<14))
645 {
646 errcode = INF_3C90X.ReceiveUPD.UpPktStatus;
647 if (errcode & (1<<16))
648 outputf("3C90X: Rx Overrun (%hX)",errcode>>16);
649 else if (errcode & (1<<17))
650 outputf("3C90X: Runt Frame (%hX)",errcode>>16);
651 else if (errcode & (1<<18))
652 outputf("3C90X: Alignment Error (%hX)",errcode>>16);
653 else if (errcode & (1<<19))
654 outputf("3C90X: CRC Error (%hX)",errcode>>16);
655 else if (errcode & (1<<20))
656 outputf("3C90X: Oversized Frame (%hX)",errcode>>16);
657 else
658 outputf("3C90X: Packet error (%hX)",errcode>>16);
659 return 0;
660 }
661
662 /** Ok, got packet. Set length in nic->packetlen. **/
663 nic->packetlen = (INF_3C90X.ReceiveUPD.UpPktStatus & 0x1FFF);
664
665 return 1;
666 }
667
668
669
670/*** a3c90x_disable: exported routine to disable the card. What's this for?
671 *** the eepro100.c driver didn't have one, so I just left this one empty too.
672 *** Ideas anyone?
673 *** Must turn off receiver at least so stray packets will not corrupt memory
674 *** [Ken]
675 ***/
676void a3c90x_disable(struct dev *dev)
677{
678 /* reset and disable merge */
679 a3c90x_reset();
680 /* Disable the receiver and transmitter. */
681 outw(cmdRxDisable, INF_3C90X.IOAddr + regCommandIntStatus_w);
682 outw(cmdTxDisable, INF_3C90X.IOAddr + regCommandIntStatus_w);
683}
684
685
686/*** a3c90x_probe: exported routine to probe for the 3c905 card and perform
687 *** initialization. If this routine is called, the pci functions did find the
688 *** card. We just have to init it here.
689 ***/
690static int a3c90x_probe(struct pci_dev * pci, void * data)
691{
748534f4
JP
692 INF_3C90X.is3c556 = (pci->did == 0x6055);
693
694 int i, c;
695 unsigned short eeprom[0x21];
696 unsigned int cfg;
697 unsigned int mopt;
698 unsigned int mstat;
699 unsigned short linktype;
700#define HWADDR_OFFSET 10
701
702 unsigned long ioaddr = 0;
703 for (i = 0; i < 6; i++) {
704 if (pci->bars[i].type == PCI_BAR_IO) {
705 ioaddr = pci->bars[i].addr;
706 break;
707 }
708 }
709
710 if (ioaddr == 0)
711 return 0;
712/*
713 adjust_pci_dev(pci);
714*/
715 nic->ioaddr = ioaddr & ~3;
716 nic->irqno = 0;
717
718 INF_3C90X.IOAddr = ioaddr & ~3;
719 INF_3C90X.CurrentWindow = 255;
720 switch (a3c90x_internal_ReadEeprom(INF_3C90X.IOAddr, 0x03))
721 {
722 case 0x9000: /** 10 Base TPO **/
723 case 0x9001: /** 10/100 T4 **/
724 case 0x9050: /** 10/100 TPO **/
725 case 0x9051: /** 10 Base Combo **/
726 INF_3C90X.isBrev = 0;
727 break;
728
729 case 0x9004: /** 10 Base TPO **/
730 case 0x9005: /** 10 Base Combo **/
731 case 0x9006: /** 10 Base TPO and Base2 **/
732 case 0x900A: /** 10 Base FL **/
733 case 0x9055: /** 10/100 TPO **/
734 case 0x9056: /** 10/100 T4 **/
735 case 0x905A: /** 10 Base FX **/
736 default:
737 INF_3C90X.isBrev = 1;
738 break;
739 }
740
741 /** Load the EEPROM contents **/
742 if (INF_3C90X.isBrev)
743 {
744 for(i=0;i<=0x20;i++)
745 {
746 eeprom[i] = a3c90x_internal_ReadEeprom(INF_3C90X.IOAddr, i);
747 }
748
749#ifdef CFG_3C90X_BOOTROM_FIX
750 /** Set xcvrSelect in InternalConfig in eeprom. **/
751 /* only necessary for 3c905b revision cards with boot PROM bug!!! */
752 a3c90x_internal_WriteEeprom(INF_3C90X.IOAddr, 0x13, 0x0160);
753#endif
754
755#ifdef CFG_3C90X_XCVR
756 if (CFG_3C90X_XCVR == 255)
757 {
758 /** Clear the LanWorks register **/
759 a3c90x_internal_WriteEeprom(INF_3C90X.IOAddr, 0x16, 0);
760 }
761 else
762 {
763 /** Set the selected permanent-xcvrSelect in the
764 ** LanWorks register
765 **/
766 a3c90x_internal_WriteEeprom(INF_3C90X.IOAddr, 0x16,
767 XCVR_MAGIC + ((CFG_3C90X_XCVR) & 0x000F));
768 }
769#endif
770 }
771 else
772 {
773 for(i=0;i<=0x17;i++)
774 {
775 eeprom[i] = a3c90x_internal_ReadEeprom(INF_3C90X.IOAddr, i);
776 }
777 }
778
779 /** Print identification message **/
780#ifdef CFG_3C90X_BOOTROM_FIX
781 if (INF_3C90X.isBrev)
782 {
783 outputf("NOTE: 3c905b bootrom fix enabled; has side "
784 "effects. See 3c90x.txt for info.");
785 }
786#endif
787
788 /** Retrieve the Hardware address and print it on the screen. **/
789 INF_3C90X.HWAddr[0] = eeprom[HWADDR_OFFSET + 0]>>8;
790 INF_3C90X.HWAddr[1] = eeprom[HWADDR_OFFSET + 0]&0xFF;
791 INF_3C90X.HWAddr[2] = eeprom[HWADDR_OFFSET + 1]>>8;
792 INF_3C90X.HWAddr[3] = eeprom[HWADDR_OFFSET + 1]&0xFF;
793 INF_3C90X.HWAddr[4] = eeprom[HWADDR_OFFSET + 2]>>8;
794 INF_3C90X.HWAddr[5] = eeprom[HWADDR_OFFSET + 2]&0xFF;
795 outputf("MAC Address = %!", INF_3C90X.HWAddr);
796
797 /** 3C556: Invert MII power **/
798 if (INF_3C90X.is3c556) {
799 unsigned int tmp;
800 a3c90x_internal_SetWindow(INF_3C90X.IOAddr, winAddressing2);
801 tmp = inw(INF_3C90X.IOAddr + regResetOptions_2_w);
802 tmp |= 0x4000;
803 outw(tmp, INF_3C90X.IOAddr + regResetOptions_2_w);
804 }
805
806 /* Test if the link is good, if not continue */
807 a3c90x_internal_SetWindow(INF_3C90X.IOAddr, winDiagnostics4);
808 mstat = inw(INF_3C90X.IOAddr + regMediaStatus_4_w);
809 if((mstat & (1<<11)) == 0) {
810 outputf("Valid link not established");
811 return 0;
812 }
813
814 /** Program the MAC address into the station address registers **/
815 a3c90x_internal_SetWindow(INF_3C90X.IOAddr, winAddressing2);
816 outw(htons(eeprom[HWADDR_OFFSET + 0]), INF_3C90X.IOAddr + regStationAddress_2_3w);
817 outw(htons(eeprom[HWADDR_OFFSET + 1]), INF_3C90X.IOAddr + regStationAddress_2_3w+2);
818 outw(htons(eeprom[HWADDR_OFFSET + 2]), INF_3C90X.IOAddr + regStationAddress_2_3w+4);
819 outw(0, INF_3C90X.IOAddr + regStationMask_2_3w+0);
820 outw(0, INF_3C90X.IOAddr + regStationMask_2_3w+2);
821 outw(0, INF_3C90X.IOAddr + regStationMask_2_3w+4);
822
823 /** Fill in our entry in the etherboot arp table **/
824/* XXX ? for lwip?
825 for(i=0;i<ETH_ALEN;i++)
826 nic->node_addr[i] = (eeprom[HWADDR_OFFSET + i/2] >> (8*((i&1)^1))) & 0xff;
827*/
828
829 /** Read the media options register, print a message and set default
830 ** xcvr.
831 **
832 ** Uses Media Option command on B revision, Reset Option on non-B
833 ** revision cards -- same register address
834 **/
835 a3c90x_internal_SetWindow(INF_3C90X.IOAddr, winTxRxOptions3);
836 mopt = inw(INF_3C90X.IOAddr + regResetMediaOptions_3_w);
837
838 /** mask out VCO bit that is defined as 10baseFL bit on B-rev cards **/
839 if (! INF_3C90X.isBrev)
840 {
841 mopt &= 0x7F;
842 }
843
844 outputf("Connectors present: ");
845 c = 0;
846 linktype = 0x0008;
847 if (mopt & 0x01)
848 {
849 outputf("%s100Base-T4",(c++)?", ":"");
850 linktype = 0x0006;
851 }
852 if (mopt & 0x04)
853 {
854 outputf("%s100Base-FX",(c++)?", ":"");
855 linktype = 0x0005;
856 }
857 if (mopt & 0x10)
858 {
859 outputf("%s10Base-2",(c++)?", ":"");
860 linktype = 0x0003;
861 }
862 if (mopt & 0x20)
863 {
864 outputf("%sAUI",(c++)?", ":"");
865 linktype = 0x0001;
866 }
867 if (mopt & 0x40)
868 {
869 outputf("%sMII",(c++)?", ":"");
870 linktype = 0x0006;
871 }
872 if ((mopt & 0xA) == 0xA)
873 {
874 outputf("%s10Base-T / 100Base-TX",(c++)?", ":"");
875 linktype = 0x0008;
876 }
877 else if ((mopt & 0xA) == 0x2)
878 {
879 outputf("%s100Base-TX",(c++)?", ":"");
880 linktype = 0x0008;
881 }
882 else if ((mopt & 0xA) == 0x8)
883 {
884 outputf("%s10Base-T",(c++)?", ":"");
885 linktype = 0x0008;
886 }
887 outputf(".");
888
889 /** Determine transceiver type to use, depending on value stored in
890 ** eeprom 0x16
891 **/
892 if (INF_3C90X.isBrev)
893 {
894 if ((eeprom[0x16] & 0xFF00) == XCVR_MAGIC)
895 {
896 /** User-defined **/
897 linktype = eeprom[0x16] & 0x000F;
898 }
899 }
900 else
901 {
902#ifdef CFG_3C90X_XCVR
903 if (CFG_3C90X_XCVR != 255)
904 linktype = CFG_3C90X_XCVR;
905#endif /* CFG_3C90X_XCVR */
906
907 /** I don't know what MII MAC only mode is!!! **/
908 if (linktype == 0x0009)
909 {
910 if (INF_3C90X.isBrev)
911 outputf("WARNING: MII External MAC Mode only supported on B-revision "
912 "cards!!!!\nFalling Back to MII Mode\n");
913 linktype = 0x0006;
914 }
915 }
916
917 /** enable DC converter for 10-Base-T **/
918 if (linktype == 0x0003)
919 {
920 a3c90x_internal_IssueCommand(INF_3C90X.IOAddr, cmdEnableDcConverter, 0);
921 }
922
923 /** Set the link to the type we just determined. **/
924 a3c90x_internal_SetWindow(INF_3C90X.IOAddr, winTxRxOptions3);
925 cfg = inl(INF_3C90X.IOAddr + regInternalConfig_3_l);
926 cfg &= ~(0xF<<20);
927 cfg |= (linktype<<20);
928 outl(cfg, INF_3C90X.IOAddr + regInternalConfig_3_l);
929
930 /** Now that we set the xcvr type, reset the Tx and Rx, re-enable. **/
931 a3c90x_internal_IssueCommand(INF_3C90X.IOAddr, cmdTxReset, 0x00);
932 while (inw(INF_3C90X.IOAddr + regCommandIntStatus_w) & INT_CMDINPROGRESS)
933 ;
934
935 if (!INF_3C90X.isBrev)
936 outb(0x01, INF_3C90X.IOAddr + regTxFreeThresh_b);
937
938 a3c90x_internal_IssueCommand(INF_3C90X.IOAddr, cmdTxEnable, 0);
939
940 /**
941 ** reset of the receiver on B-revision cards re-negotiates the link
942 ** takes several seconds (a computer eternity)
943 **/
944 if (INF_3C90X.isBrev)
945 a3c90x_internal_IssueCommand(INF_3C90X.IOAddr, cmdRxReset, 0x04);
946 else
947 a3c90x_internal_IssueCommand(INF_3C90X.IOAddr, cmdRxReset, 0x00);
948 while (inw(INF_3C90X.IOAddr + regCommandIntStatus_w) & INT_CMDINPROGRESS)
949 ;
950
951 /** Set the RX filter = receive only individual pkts & multicast & bcast. **/
952 a3c90x_internal_IssueCommand(INF_3C90X.IOAddr, cmdSetRxFilter, 0x01 + 0x02 + 0x04);
953 a3c90x_internal_IssueCommand(INF_3C90X.IOAddr, cmdRxEnable, 0);
954
955
956 /**
957 ** set Indication and Interrupt flags , acknowledge any IRQ's
958 **/
959 a3c90x_internal_IssueCommand(INF_3C90X.IOAddr, cmdSetInterruptEnable, 0);
960 a3c90x_internal_IssueCommand(INF_3C90X.IOAddr,
961 cmdSetIndicationEnable, 0x0014);
962 a3c90x_internal_IssueCommand(INF_3C90X.IOAddr,
963 cmdAcknowledgeInterrupt, 0x661);
964
965 /* * Set our exported functions **/
966 nic->poll = a3c90x_poll;
967 nic->transmit = a3c90x_transmit;
968
969 return 1;
970}
971
972static struct pci_id a3c90x_nics[] = {
973/* Original 90x revisions: */
974PCI_ROM(0x10b7, 0x6055, "3c556", "3C556"), /* Huricane */
975PCI_ROM(0x10b7, 0x9000, "3c905-tpo", "3Com900-TPO"), /* 10 Base TPO */
976PCI_ROM(0x10b7, 0x9001, "3c905-t4", "3Com900-Combo"), /* 10/100 T4 */
977PCI_ROM(0x10b7, 0x9050, "3c905-tpo100", "3Com905-TX"), /* 100 Base TX / 10/100 TPO */
978PCI_ROM(0x10b7, 0x9051, "3c905-combo", "3Com905-T4"), /* 100 Base T4 / 10 Base Combo */
979/* Newer 90xB revisions: */
980PCI_ROM(0x10b7, 0x9004, "3c905b-tpo", "3Com900B-TPO"), /* 10 Base TPO */
981PCI_ROM(0x10b7, 0x9005, "3c905b-combo", "3Com900B-Combo"), /* 10 Base Combo */
982PCI_ROM(0x10b7, 0x9006, "3c905b-tpb2", "3Com900B-2/T"), /* 10 Base TP and Base2 */
983PCI_ROM(0x10b7, 0x900a, "3c905b-fl", "3Com900B-FL"), /* 10 Base FL */
984PCI_ROM(0x10b7, 0x9055, "3c905b-tpo100", "3Com905B-TX"), /* 10/100 TPO */
985PCI_ROM(0x10b7, 0x9056, "3c905b-t4", "3Com905B-T4"), /* 10/100 T4 */
986PCI_ROM(0x10b7, 0x9058, "3c905b-9058", "3Com905B-9058"), /* Cyclone 10/100/BNC */
987PCI_ROM(0x10b7, 0x905a, "3c905b-fx", "3Com905B-FL"), /* 100 Base FX / 10 Base FX */
988/* Newer 90xC revision: */
989PCI_ROM(0x10b7, 0x9200, "3c905c-tpo", "3Com905C-TXM"), /* 10/100 TPO (3C905C-TXM) */
990PCI_ROM(0x10b7, 0x9202, "3c920b-emb-ati", "3c920B-EMB-WNM (ATI Radeon 9100 IGP)"), /* 3c920B-EMB-WNM (ATI Radeon 9100 IGP) */
991PCI_ROM(0x10b7, 0x9210, "3c920b-emb-wnm","3Com20B-EMB WNM"),
992PCI_ROM(0x10b7, 0x9800, "3c980", "3Com980-Cyclone"), /* Cyclone */
993PCI_ROM(0x10b7, 0x9805, "3c9805", "3Com9805"), /* Dual Port Server Cyclone */
994PCI_ROM(0x10b7, 0x7646, "3csoho100-tx", "3CSOHO100-TX"), /* Hurricane */
995PCI_ROM(0x10b7, 0x4500, "3c450", "3Com450 HomePNA Tornado"),
996PCI_ROM(0x10b7, 0x1201, "3c982a", "3Com982A"),
997PCI_ROM(0x10b7, 0x1202, "3c982b", "3Com982B"),
998};
999
1000struct pci_driver a3c90x_driver = {
1001 .name = "3C90X",
1002 .probe = a3c90x_probe,
1003 .ids = a3c90x_nics,
1004 .id_count = sizeof(a3c90x_nics)/sizeof(a3c90x_nics[0]),
1005};
This page took 0.103848 seconds and 4 git commands to generate.