Remove *_fill_nic() calls, and directly set nic->ioaddr and nic->irqno .
[gpxe.git] / src / drivers / net / via-rhine.c
blob0c955fab38ab5271faa31e7f44820da64b160a94
1 /* rhine.c:Fast Ethernet driver for Linux. */
2 /*
3 Adapted 09-jan-2000 by Paolo Marini (paolom@prisma-eng.it)
5 originally written by Donald Becker.
7 This software may be used and distributed according to the terms
8 of the GNU Public License (GPL), incorporated herein by reference.
9 Drivers derived from this code also fall under the GPL and must retain
10 this authorship and copyright notice.
12 Under no circumstances are the authors responsible for
13 the proper functioning of this software, nor do the authors assume any
14 responsibility for damages incurred with its use.
16 This driver is designed for the VIA VT86C100A Rhine-II PCI Fast Ethernet
17 controller.
21 static const char *version = "rhine.c v1.0.2 2004-10-29\n";
23 /* A few user-configurable values. */
25 // max time out delay time
26 #define W_MAX_TIMEOUT 0x0FFFU
28 /* Size of the in-memory receive ring. */
29 #define RX_BUF_LEN_IDX 3 /* 0==8K, 1==16K, 2==32K, 3==64K */
30 #define RX_BUF_LEN (8192 << RX_BUF_LEN_IDX)
32 /* Size of the Tx bounce buffers -- must be at least (dev->mtu+14+4). */
33 #define TX_BUF_SIZE 1536
34 #define RX_BUF_SIZE 1536
36 /* PCI Tuning Parameters
37 Threshold is bytes transferred to chip before transmission starts. */
38 #define TX_FIFO_THRESH 256 /* In bytes, rounded down to 32 byte units. */
40 /* The following settings are log_2(bytes)-4: 0 == 16 bytes .. 6==1024. */
41 #define RX_FIFO_THRESH 4 /* Rx buffer level before first PCI xfer. */
42 #define RX_DMA_BURST 4 /* Maximum PCI burst, '4' is 256 bytes */
43 #define TX_DMA_BURST 4
45 /* Operational parameters that usually are not changed. */
46 /* Time in jiffies before concluding the transmitter is hung. */
47 #define TX_TIMEOUT ((2000*HZ)/1000)
49 #include "etherboot.h"
50 #include "nic.h"
51 #include <gpxe/pci.h>
52 #include <gpxe/ethernet.h>
53 #include "timer.h"
55 /* define all ioaddr */
57 #define byPAR0 ioaddr
58 #define byRCR ioaddr + 6
59 #define byTCR ioaddr + 7
60 #define byCR0 ioaddr + 8
61 #define byCR1 ioaddr + 9
62 #define byISR0 ioaddr + 0x0c
63 #define byISR1 ioaddr + 0x0d
64 #define byIMR0 ioaddr + 0x0e
65 #define byIMR1 ioaddr + 0x0f
66 #define byMAR0 ioaddr + 0x10
67 #define byMAR1 ioaddr + 0x11
68 #define byMAR2 ioaddr + 0x12
69 #define byMAR3 ioaddr + 0x13
70 #define byMAR4 ioaddr + 0x14
71 #define byMAR5 ioaddr + 0x15
72 #define byMAR6 ioaddr + 0x16
73 #define byMAR7 ioaddr + 0x17
74 #define dwCurrentRxDescAddr ioaddr + 0x18
75 #define dwCurrentTxDescAddr ioaddr + 0x1c
76 #define dwCurrentRDSE0 ioaddr + 0x20
77 #define dwCurrentRDSE1 ioaddr + 0x24
78 #define dwCurrentRDSE2 ioaddr + 0x28
79 #define dwCurrentRDSE3 ioaddr + 0x2c
80 #define dwNextRDSE0 ioaddr + 0x30
81 #define dwNextRDSE1 ioaddr + 0x34
82 #define dwNextRDSE2 ioaddr + 0x38
83 #define dwNextRDSE3 ioaddr + 0x3c
84 #define dwCurrentTDSE0 ioaddr + 0x40
85 #define dwCurrentTDSE1 ioaddr + 0x44
86 #define dwCurrentTDSE2 ioaddr + 0x48
87 #define dwCurrentTDSE3 ioaddr + 0x4c
88 #define dwNextTDSE0 ioaddr + 0x50
89 #define dwNextTDSE1 ioaddr + 0x54
90 #define dwNextTDSE2 ioaddr + 0x58
91 #define dwNextTDSE3 ioaddr + 0x5c
92 #define dwCurrRxDMAPtr ioaddr + 0x60
93 #define dwCurrTxDMAPtr ioaddr + 0x64
94 #define byMPHY ioaddr + 0x6c
95 #define byMIISR ioaddr + 0x6d
96 #define byBCR0 ioaddr + 0x6e
97 #define byBCR1 ioaddr + 0x6f
98 #define byMIICR ioaddr + 0x70
99 #define byMIIAD ioaddr + 0x71
100 #define wMIIDATA ioaddr + 0x72
101 #define byEECSR ioaddr + 0x74
102 #define byTEST ioaddr + 0x75
103 #define byGPIO ioaddr + 0x76
104 #define byCFGA ioaddr + 0x78
105 #define byCFGB ioaddr + 0x79
106 #define byCFGC ioaddr + 0x7a
107 #define byCFGD ioaddr + 0x7b
108 #define wTallyCntMPA ioaddr + 0x7c
109 #define wTallyCntCRC ioaddr + 0x7d
110 #define bySTICKHW ioaddr + 0x83
111 #define byWOLcrClr ioaddr + 0xA4
112 #define byWOLcgClr ioaddr + 0xA7
113 #define byPwrcsrClr ioaddr + 0xAC
115 /*--------------------- Exioaddr Definitions -------------------------*/
118 * Bits in the RCR register
121 #define RCR_RRFT2 0x80
122 #define RCR_RRFT1 0x40
123 #define RCR_RRFT0 0x20
124 #define RCR_PROM 0x10
125 #define RCR_AB 0x08
126 #define RCR_AM 0x04
127 #define RCR_AR 0x02
128 #define RCR_SEP 0x01
131 * Bits in the TCR register
134 #define TCR_RTSF 0x80
135 #define TCR_RTFT1 0x40
136 #define TCR_RTFT0 0x20
137 #define TCR_OFSET 0x08
138 #define TCR_LB1 0x04 /* loopback[1] */
139 #define TCR_LB0 0x02 /* loopback[0] */
142 * Bits in the CR0 register
145 #define CR0_RDMD 0x40 /* rx descriptor polling demand */
146 #define CR0_TDMD 0x20 /* tx descriptor polling demand */
147 #define CR0_TXON 0x10
148 #define CR0_RXON 0x08
149 #define CR0_STOP 0x04 /* stop NIC, default = 1 */
150 #define CR0_STRT 0x02 /* start NIC */
151 #define CR0_INIT 0x01 /* start init process */
155 * Bits in the CR1 register
158 #define CR1_SFRST 0x80 /* software reset */
159 #define CR1_RDMD1 0x40 /* RDMD1 */
160 #define CR1_TDMD1 0x20 /* TDMD1 */
161 #define CR1_KEYPAG 0x10 /* turn on par/key */
162 #define CR1_DPOLL 0x08 /* disable rx/tx auto polling */
163 #define CR1_FDX 0x04 /* full duplex mode */
164 #define CR1_ETEN 0x02 /* early tx mode */
165 #define CR1_EREN 0x01 /* early rx mode */
168 * Bits in the CR register
171 #define CR_RDMD 0x0040 /* rx descriptor polling demand */
172 #define CR_TDMD 0x0020 /* tx descriptor polling demand */
173 #define CR_TXON 0x0010
174 #define CR_RXON 0x0008
175 #define CR_STOP 0x0004 /* stop NIC, default = 1 */
176 #define CR_STRT 0x0002 /* start NIC */
177 #define CR_INIT 0x0001 /* start init process */
178 #define CR_SFRST 0x8000 /* software reset */
179 #define CR_RDMD1 0x4000 /* RDMD1 */
180 #define CR_TDMD1 0x2000 /* TDMD1 */
181 #define CR_KEYPAG 0x1000 /* turn on par/key */
182 #define CR_DPOLL 0x0800 /* disable rx/tx auto polling */
183 #define CR_FDX 0x0400 /* full duplex mode */
184 #define CR_ETEN 0x0200 /* early tx mode */
185 #define CR_EREN 0x0100 /* early rx mode */
188 * Bits in the IMR0 register
191 #define IMR0_CNTM 0x80
192 #define IMR0_BEM 0x40
193 #define IMR0_RUM 0x20
194 #define IMR0_TUM 0x10
195 #define IMR0_TXEM 0x08
196 #define IMR0_RXEM 0x04
197 #define IMR0_PTXM 0x02
198 #define IMR0_PRXM 0x01
200 /* define imrshadow */
202 #define IMRShadow 0x5AFF
205 * Bits in the IMR1 register
208 #define IMR1_INITM 0x80
209 #define IMR1_SRCM 0x40
210 #define IMR1_NBFM 0x10
211 #define IMR1_PRAIM 0x08
212 #define IMR1_RES0M 0x04
213 #define IMR1_ETM 0x02
214 #define IMR1_ERM 0x01
217 * Bits in the ISR register
220 #define ISR_INITI 0x8000
221 #define ISR_SRCI 0x4000
222 #define ISR_ABTI 0x2000
223 #define ISR_NORBF 0x1000
224 #define ISR_PKTRA 0x0800
225 #define ISR_RES0 0x0400
226 #define ISR_ETI 0x0200
227 #define ISR_ERI 0x0100
228 #define ISR_CNT 0x0080
229 #define ISR_BE 0x0040
230 #define ISR_RU 0x0020
231 #define ISR_TU 0x0010
232 #define ISR_TXE 0x0008
233 #define ISR_RXE 0x0004
234 #define ISR_PTX 0x0002
235 #define ISR_PRX 0x0001
238 * Bits in the ISR0 register
241 #define ISR0_CNT 0x80
242 #define ISR0_BE 0x40
243 #define ISR0_RU 0x20
244 #define ISR0_TU 0x10
245 #define ISR0_TXE 0x08
246 #define ISR0_RXE 0x04
247 #define ISR0_PTX 0x02
248 #define ISR0_PRX 0x01
251 * Bits in the ISR1 register
254 #define ISR1_INITI 0x80
255 #define ISR1_SRCI 0x40
256 #define ISR1_NORBF 0x10
257 #define ISR1_PKTRA 0x08
258 #define ISR1_ETI 0x02
259 #define ISR1_ERI 0x01
261 /* ISR ABNORMAL CONDITION */
263 #define ISR_ABNORMAL ISR_BE+ISR_RU+ISR_TU+ISR_CNT+ISR_NORBF+ISR_PKTRA
266 * Bits in the MIISR register
269 #define MIISR_MIIERR 0x08
270 #define MIISR_MRERR 0x04
271 #define MIISR_LNKFL 0x02
272 #define MIISR_SPEED 0x01
275 * Bits in the MIICR register
278 #define MIICR_MAUTO 0x80
279 #define MIICR_RCMD 0x40
280 #define MIICR_WCMD 0x20
281 #define MIICR_MDPM 0x10
282 #define MIICR_MOUT 0x08
283 #define MIICR_MDO 0x04
284 #define MIICR_MDI 0x02
285 #define MIICR_MDC 0x01
288 * Bits in the EECSR register
291 #define EECSR_EEPR 0x80 /* eeprom programed status, 73h means programed */
292 #define EECSR_EMBP 0x40 /* eeprom embeded programming */
293 #define EECSR_AUTOLD 0x20 /* eeprom content reload */
294 #define EECSR_DPM 0x10 /* eeprom direct programming */
295 #define EECSR_CS 0x08 /* eeprom CS pin */
296 #define EECSR_SK 0x04 /* eeprom SK pin */
297 #define EECSR_DI 0x02 /* eeprom DI pin */
298 #define EECSR_DO 0x01 /* eeprom DO pin */
301 * Bits in the BCR0 register
304 #define BCR0_CRFT2 0x20
305 #define BCR0_CRFT1 0x10
306 #define BCR0_CRFT0 0x08
307 #define BCR0_DMAL2 0x04
308 #define BCR0_DMAL1 0x02
309 #define BCR0_DMAL0 0x01
312 * Bits in the BCR1 register
315 #define BCR1_CTSF 0x20
316 #define BCR1_CTFT1 0x10
317 #define BCR1_CTFT0 0x08
318 #define BCR1_POT2 0x04
319 #define BCR1_POT1 0x02
320 #define BCR1_POT0 0x01
323 * Bits in the CFGA register
326 #define CFGA_EELOAD 0x80 /* enable eeprom embeded and direct programming */
327 #define CFGA_JUMPER 0x40
328 #define CFGA_MTGPIO 0x08
329 #define CFGA_T10EN 0x02
330 #define CFGA_AUTO 0x01
333 * Bits in the CFGB register
336 #define CFGB_PD 0x80
337 #define CFGB_POLEN 0x02
338 #define CFGB_LNKEN 0x01
341 * Bits in the CFGC register
344 #define CFGC_M10TIO 0x80
345 #define CFGC_M10POL 0x40
346 #define CFGC_PHY1 0x20
347 #define CFGC_PHY0 0x10
348 #define CFGC_BTSEL 0x08
349 #define CFGC_BPS2 0x04 /* bootrom select[2] */
350 #define CFGC_BPS1 0x02 /* bootrom select[1] */
351 #define CFGC_BPS0 0x01 /* bootrom select[0] */
354 * Bits in the CFGD register
357 #define CFGD_GPIOEN 0x80
358 #define CFGD_DIAG 0x40
359 #define CFGD_MAGIC 0x10
360 #define CFGD_RANDOM 0x08
361 #define CFGD_CFDX 0x04
362 #define CFGD_CEREN 0x02
363 #define CFGD_CETEN 0x01
365 /* Bits in RSR */
366 #define RSR_RERR 0x00000001
367 #define RSR_CRC 0x00000002
368 #define RSR_FAE 0x00000004
369 #define RSR_FOV 0x00000008
370 #define RSR_LONG 0x00000010
371 #define RSR_RUNT 0x00000020
372 #define RSR_SERR 0x00000040
373 #define RSR_BUFF 0x00000080
374 #define RSR_EDP 0x00000100
375 #define RSR_STP 0x00000200
376 #define RSR_CHN 0x00000400
377 #define RSR_PHY 0x00000800
378 #define RSR_BAR 0x00001000
379 #define RSR_MAR 0x00002000
380 #define RSR_RXOK 0x00008000
381 #define RSR_ABNORMAL RSR_RERR+RSR_LONG+RSR_RUNT
383 /* Bits in TSR */
384 #define TSR_NCR0 0x00000001
385 #define TSR_NCR1 0x00000002
386 #define TSR_NCR2 0x00000004
387 #define TSR_NCR3 0x00000008
388 #define TSR_COLS 0x00000010
389 #define TSR_CDH 0x00000080
390 #define TSR_ABT 0x00000100
391 #define TSR_OWC 0x00000200
392 #define TSR_CRS 0x00000400
393 #define TSR_UDF 0x00000800
394 #define TSR_TBUFF 0x00001000
395 #define TSR_SERR 0x00002000
396 #define TSR_JAB 0x00004000
397 #define TSR_TERR 0x00008000
398 #define TSR_ABNORMAL TSR_TERR+TSR_OWC+TSR_ABT+TSR_JAB+TSR_CRS
399 #define TSR_OWN_BIT 0x80000000
401 #define CB_DELAY_LOOP_WAIT 10 /* 10ms */
402 /* enabled mask value of irq */
404 #define W_IMR_MASK_VALUE 0x1BFF /* initial value of IMR */
406 /* Ethernet address filter type */
407 #define PKT_TYPE_DIRECTED 0x0001 /* obsolete, directed address is always accepted */
408 #define PKT_TYPE_MULTICAST 0x0002
409 #define PKT_TYPE_ALL_MULTICAST 0x0004
410 #define PKT_TYPE_BROADCAST 0x0008
411 #define PKT_TYPE_PROMISCUOUS 0x0020
412 #define PKT_TYPE_LONG 0x2000
413 #define PKT_TYPE_RUNT 0x4000
414 #define PKT_TYPE_ERROR 0x8000 /* accept error packets, e.g. CRC error */
416 /* Loopback mode */
418 #define NIC_LB_NONE 0x00
419 #define NIC_LB_INTERNAL 0x01
420 #define NIC_LB_PHY 0x02 /* MII or Internal-10BaseT loopback */
422 #define TX_RING_SIZE 2
423 #define RX_RING_SIZE 2
424 #define PKT_BUF_SZ 1536 /* Size of each temporary Rx buffer. */
426 #define PCI_REG_MODE3 0x53
427 #define MODE3_MIION 0x04 /* in PCI_REG_MOD3 OF PCI space */
429 enum rhine_revs {
430 VT86C100A = 0x00,
431 VTunknown0 = 0x20,
432 VT6102 = 0x40,
433 VT8231 = 0x50, /* Integrated MAC */
434 VT8233 = 0x60, /* Integrated MAC */
435 VT8235 = 0x74, /* Integrated MAC */
436 VT8237 = 0x78, /* Integrated MAC */
437 VTunknown1 = 0x7C,
438 VT6105 = 0x80,
439 VT6105_B0 = 0x83,
440 VT6105L = 0x8A,
441 VT6107 = 0x8C,
442 VTunknown2 = 0x8E,
443 VT6105M = 0x90,
446 /* Transmit and receive descriptors definition */
448 struct rhine_tx_desc
450 union VTC_tx_status_tag
452 struct
454 unsigned long ncro:1;
455 unsigned long ncr1:1;
456 unsigned long ncr2:1;
457 unsigned long ncr3:1;
458 unsigned long cols:1;
459 unsigned long reserve_1:2;
460 unsigned long cdh:1;
461 unsigned long abt:1;
462 unsigned long owc:1;
463 unsigned long crs:1;
464 unsigned long udf:1;
465 unsigned long tbuff:1;
466 unsigned long serr:1;
467 unsigned long jab:1;
468 unsigned long terr:1;
469 unsigned long reserve_2:15;
470 unsigned long own_bit:1;
472 bits;
473 unsigned long lw;
475 tx_status;
477 union VTC_tx_ctrl_tag
479 struct
481 unsigned long tx_buf_size:11;
482 unsigned long extend_tx_buf_size:4;
483 unsigned long chn:1;
484 unsigned long crc:1;
485 unsigned long reserve_1:4;
486 unsigned long stp:1;
487 unsigned long edp:1;
488 unsigned long ic:1;
489 unsigned long reserve_2:8;
491 bits;
492 unsigned long lw;
494 tx_ctrl;
496 unsigned long buf_addr_1:32;
497 unsigned long buf_addr_2:32;
501 struct rhine_rx_desc
503 union VTC_rx_status_tag
505 struct
507 unsigned long rerr:1;
508 unsigned long crc_error:1;
509 unsigned long fae:1;
510 unsigned long fov:1;
511 unsigned long toolong:1;
512 unsigned long runt:1;
513 unsigned long serr:1;
514 unsigned long buff:1;
515 unsigned long edp:1;
516 unsigned long stp:1;
517 unsigned long chn:1;
518 unsigned long phy:1;
519 unsigned long bar:1;
520 unsigned long mar:1;
521 unsigned long reserve_1:1;
522 unsigned long rxok:1;
523 unsigned long frame_length:11;
524 unsigned long reverve_2:4;
525 unsigned long own_bit:1;
527 bits;
528 unsigned long lw;
530 rx_status;
532 union VTC_rx_ctrl_tag
534 struct
536 unsigned long rx_buf_size:11;
537 unsigned long extend_rx_buf_size:4;
538 unsigned long reserved_1:17;
540 bits;
541 unsigned long lw;
543 rx_ctrl;
545 unsigned long buf_addr_1:32;
546 unsigned long buf_addr_2:32;
550 struct {
551 char txbuf[TX_RING_SIZE * PKT_BUF_SZ + 32];
552 char rxbuf[RX_RING_SIZE * PKT_BUF_SZ + 32];
553 char txdesc[TX_RING_SIZE * sizeof (struct rhine_tx_desc) + 32];
554 char rxdesc[RX_RING_SIZE * sizeof (struct rhine_rx_desc) + 32];
555 } rhine_buffers __shared;
557 /* The I/O extent. */
558 #define rhine_TOTAL_SIZE 0x80
560 #ifdef HAVE_DEVLIST
561 struct netdev_entry rhine_drv =
562 { "rhine", rhine_probe, rhine_TOTAL_SIZE, NULL };
563 #endif
565 static int rhine_debug = 1;
568 Theory of Operation
570 I. Board Compatibility
572 This driver is designed for the VIA 86c100A Rhine-II PCI Fast Ethernet
573 controller.
575 II. Board-specific settings
577 Boards with this chip are functional only in a bus-master PCI slot.
579 Many operational settings are loaded from the EEPROM to the Config word at
580 offset 0x78. This driver assumes that they are correct.
581 If this driver is compiled to use PCI memory space operations the EEPROM
582 must be configured to enable memory ops.
584 III. Driver operation
586 IIIa. Ring buffers
588 This driver uses two statically allocated fixed-size descriptor lists
589 formed into rings by a branch from the final descriptor to the beginning of
590 the list. The ring sizes are set at compile time by RX/TX_RING_SIZE.
592 IIIb/c. Transmit/Receive Structure
594 This driver attempts to use a zero-copy receive and transmit scheme.
596 Alas, all data buffers are required to start on a 32 bit boundary, so
597 the driver must often copy transmit packets into bounce buffers.
599 The driver allocates full frame size skbuffs for the Rx ring buffers at
600 open() time and passes the skb->data field to the chip as receive data
601 buffers. When an incoming frame is less than RX_COPYBREAK bytes long,
602 a fresh skbuff is allocated and the frame is copied to the new skbuff.
603 When the incoming frame is larger, the skbuff is passed directly up the
604 protocol stack. Buffers consumed this way are replaced by newly allocated
605 skbuffs in the last phase of netdev_rx().
607 The RX_COPYBREAK value is chosen to trade-off the memory wasted by
608 using a full-sized skbuff for small frames vs. the copying costs of larger
609 frames. New boards are typically used in generously configured machines
610 and the underfilled buffers have negligible impact compared to the benefit of
611 a single allocation size, so the default value of zero results in never
612 copying packets. When copying is done, the cost is usually mitigated by using
613 a combined copy/checksum routine. Copying also preloads the cache, which is
614 most useful with small frames.
616 Since the VIA chips are only able to transfer data to buffers on 32 bit
617 boundaries, the the IP header at offset 14 in an ethernet frame isn't
618 longword aligned for further processing. Copying these unaligned buffers
619 has the beneficial effect of 16-byte aligning the IP header.
621 IIId. Synchronization
623 The driver runs as two independent, single-threaded flows of control. One
624 is the send-packet routine, which enforces single-threaded use by the
625 dev->tbusy flag. The other thread is the interrupt handler, which is single
626 threaded by the hardware and interrupt handling software.
628 The send packet thread has partial control over the Tx ring and 'dev->tbusy'
629 flag. It sets the tbusy flag whenever it's queuing a Tx packet. If the next
630 queue slot is empty, it clears the tbusy flag when finished otherwise it sets
631 the 'lp->tx_full' flag.
633 The interrupt handler has exclusive control over the Rx ring and records stats
634 from the Tx ring. After reaping the stats, it marks the Tx queue entry as
635 empty by incrementing the dirty_tx mark. Iff the 'lp->tx_full' flag is set, it
636 clears both the tx_full and tbusy flags.
638 IV. Notes
640 IVb. References
642 Preliminary VT86C100A manual from http://www.via.com.tw/
643 http://cesdis.gsfc.nasa.gov/linux/misc/100mbps.html
644 http://cesdis.gsfc.nasa.gov/linux/misc/NWay.html
646 IVc. Errata
648 The VT86C100A manual is not reliable information.
649 The chip does not handle unaligned transmit or receive buffers, resulting
650 in significant performance degradation for bounce buffer copies on transmit
651 and unaligned IP headers on receive.
652 The chip does not pad to minimum transmit length.
656 /* The rest of these values should never change. */
657 #define NUM_TX_DESC 2 /* Number of Tx descriptor registers. */
659 static struct rhine_private
661 char devname[8]; /* Used only for kernel debugging. */
662 const char *product_name;
663 struct rhine_rx_desc *rx_ring;
664 struct rhine_tx_desc *tx_ring;
665 char *rx_buffs[RX_RING_SIZE];
666 char *tx_buffs[TX_RING_SIZE];
668 /* temporary Rx buffers. */
670 int chip_id;
671 int chip_revision;
672 unsigned short ioaddr;
673 unsigned int cur_rx, cur_tx; /* The next free and used entries */
674 unsigned int dirty_rx, dirty_tx;
675 /* The saved address of a sent-in-place packet/buffer, for skfree(). */
676 struct sk_buff *tx_skbuff[TX_RING_SIZE];
677 unsigned char mc_filter[8]; /* Current multicast filter. */
678 char phys[4]; /* MII device addresses. */
679 unsigned int tx_full:1; /* The Tx queue is full. */
680 unsigned int full_duplex:1; /* Full-duplex operation requested. */
681 unsigned int default_port:4; /* Last dev->if_port value. */
682 unsigned int media2:4; /* Secondary monitored media port. */
683 unsigned int medialock:1; /* Don't sense media type. */
684 unsigned int mediasense:1; /* Media sensing in progress. */
686 rhine;
688 static void rhine_probe1 (struct nic *nic, struct pci_device *pci, int ioaddr,
689 int chip_id, int options);
690 static int QueryAuto (int);
691 static int ReadMII (int byMIIIndex, int);
692 static void WriteMII (char, char, char, int);
693 static void MIIDelay (void);
694 static void rhine_init_ring (struct nic *dev);
695 static void rhine_disable (struct nic *nic);
696 static void rhine_reset (struct nic *nic);
697 static int rhine_poll (struct nic *nic, int retreive);
698 static void rhine_transmit (struct nic *nic, const char *d, unsigned int t,
699 unsigned int s, const char *p);
700 static void reload_eeprom(int ioaddr);
703 static void reload_eeprom(int ioaddr)
705 int i;
706 outb(0x20, byEECSR);
707 /* Typically 2 cycles to reload. */
708 for (i = 0; i < 150; i++)
709 if (! (inb(byEECSR) & 0x20))
710 break;
712 /* Initialize the Rx and Tx rings, along with various 'dev' bits. */
713 static void
714 rhine_init_ring (struct nic *nic)
716 struct rhine_private *tp = (struct rhine_private *) nic->priv_data;
717 int i;
719 tp->tx_full = 0;
720 tp->cur_rx = tp->cur_tx = 0;
721 tp->dirty_rx = tp->dirty_tx = 0;
723 for (i = 0; i < RX_RING_SIZE; i++)
726 tp->rx_ring[i].rx_status.bits.own_bit = 1;
727 tp->rx_ring[i].rx_ctrl.bits.rx_buf_size = 1536;
729 tp->rx_ring[i].buf_addr_1 = virt_to_bus (tp->rx_buffs[i]);
730 tp->rx_ring[i].buf_addr_2 = virt_to_bus (&tp->rx_ring[i + 1]);
731 /* printf("[%d]buf1=%hX,buf2=%hX",i,tp->rx_ring[i].buf_addr_1,tp->rx_ring[i].buf_addr_2); */
733 /* Mark the last entry as wrapping the ring. */
734 /* tp->rx_ring[i-1].rx_ctrl.bits.rx_buf_size =1518; */
735 tp->rx_ring[i - 1].buf_addr_2 = virt_to_bus (&tp->rx_ring[0]);
736 /*printf("[%d]buf1=%hX,buf2=%hX",i-1,tp->rx_ring[i-1].buf_addr_1,tp->rx_ring[i-1].buf_addr_2); */
738 /* The Tx buffer descriptor is filled in as needed, but we
739 do need to clear the ownership bit. */
741 for (i = 0; i < TX_RING_SIZE; i++)
744 tp->tx_ring[i].tx_status.lw = 0;
745 tp->tx_ring[i].tx_ctrl.lw = 0x00e08000;
746 tp->tx_ring[i].buf_addr_1 = virt_to_bus (tp->tx_buffs[i]);
747 tp->tx_ring[i].buf_addr_2 = virt_to_bus (&tp->tx_ring[i + 1]);
748 /* printf("[%d]buf1=%hX,buf2=%hX",i,tp->tx_ring[i].buf_addr_1,tp->tx_ring[i].buf_addr_2); */
751 tp->tx_ring[i - 1].buf_addr_2 = virt_to_bus (&tp->tx_ring[0]);
752 /* printf("[%d]buf1=%hX,buf2=%hX",i,tp->tx_ring[i-1].buf_addr_1,tp->tx_ring[i-1].buf_addr_2); */
756 QueryAuto (int ioaddr)
758 int byMIIIndex;
759 int MIIReturn;
761 int advertising,mii_reg5;
762 int negociated;
764 byMIIIndex = 0x04;
765 MIIReturn = ReadMII (byMIIIndex, ioaddr);
766 advertising=MIIReturn;
768 byMIIIndex = 0x05;
769 MIIReturn = ReadMII (byMIIIndex, ioaddr);
770 mii_reg5=MIIReturn;
772 negociated=mii_reg5 & advertising;
774 if ( (negociated & 0x100) || (negociated & 0x1C0) == 0x40 )
775 return 1;
776 else
777 return 0;
782 ReadMII (int byMIIIndex, int ioaddr)
784 int ReturnMII;
785 char byMIIAdrbak;
786 char byMIICRbak;
787 char byMIItemp;
789 byMIIAdrbak = inb (byMIIAD);
790 byMIICRbak = inb (byMIICR);
791 outb (byMIICRbak & 0x7f, byMIICR);
792 MIIDelay ();
794 outb (byMIIIndex, byMIIAD);
795 MIIDelay ();
797 outb (inb (byMIICR) | 0x40, byMIICR);
799 byMIItemp = inb (byMIICR);
800 byMIItemp = byMIItemp & 0x40;
802 load_timer2(2*TICKS_PER_MS);
803 while (byMIItemp != 0 && timer2_running())
805 byMIItemp = inb (byMIICR);
806 byMIItemp = byMIItemp & 0x40;
808 MIIDelay ();
810 ReturnMII = inw (wMIIDATA);
812 outb (byMIIAdrbak, byMIIAD);
813 outb (byMIICRbak, byMIICR);
814 MIIDelay ();
816 return (ReturnMII);
820 void
821 WriteMII (char byMIISetByte, char byMIISetBit, char byMIIOP, int ioaddr)
823 int ReadMIItmp;
824 int MIIMask;
825 char byMIIAdrbak;
826 char byMIICRbak;
827 char byMIItemp;
830 byMIIAdrbak = inb (byMIIAD);
832 byMIICRbak = inb (byMIICR);
833 outb (byMIICRbak & 0x7f, byMIICR);
834 MIIDelay ();
835 outb (byMIISetByte, byMIIAD);
836 MIIDelay ();
838 outb (inb (byMIICR) | 0x40, byMIICR);
840 byMIItemp = inb (byMIICR);
841 byMIItemp = byMIItemp & 0x40;
843 load_timer2(2*TICKS_PER_MS);
844 while (byMIItemp != 0 && timer2_running())
846 byMIItemp = inb (byMIICR);
847 byMIItemp = byMIItemp & 0x40;
849 MIIDelay ();
851 ReadMIItmp = inw (wMIIDATA);
852 MIIMask = 0x0001;
853 MIIMask = MIIMask << byMIISetBit;
856 if (byMIIOP == 0)
858 MIIMask = ~MIIMask;
859 ReadMIItmp = ReadMIItmp & MIIMask;
861 else
863 ReadMIItmp = ReadMIItmp | MIIMask;
866 outw (ReadMIItmp, wMIIDATA);
867 MIIDelay ();
869 outb (inb (byMIICR) | 0x20, byMIICR);
870 byMIItemp = inb (byMIICR);
871 byMIItemp = byMIItemp & 0x20;
873 load_timer2(2*TICKS_PER_MS);
874 while (byMIItemp != 0 && timer2_running())
876 byMIItemp = inb (byMIICR);
877 byMIItemp = byMIItemp & 0x20;
879 MIIDelay ();
881 outb (byMIIAdrbak & 0x7f, byMIIAD);
882 outb (byMIICRbak, byMIICR);
883 MIIDelay ();
887 void
888 MIIDelay (void)
890 int i;
891 for (i = 0; i < 0x7fff; i++)
893 ( void ) inb (0x61);
894 ( void ) inb (0x61);
895 ( void ) inb (0x61);
896 ( void ) inb (0x61);
900 /* Offsets to the device registers. */
901 enum register_offsets {
902 StationAddr=0x00, RxConfig=0x06, TxConfig=0x07, ChipCmd=0x08,
903 IntrStatus=0x0C, IntrEnable=0x0E,
904 MulticastFilter0=0x10, MulticastFilter1=0x14,
905 RxRingPtr=0x18, TxRingPtr=0x1C, GFIFOTest=0x54,
906 MIIPhyAddr=0x6C, MIIStatus=0x6D, PCIBusConfig=0x6E,
907 MIICmd=0x70, MIIRegAddr=0x71, MIIData=0x72, MACRegEEcsr=0x74,
908 ConfigA=0x78, ConfigB=0x79, ConfigC=0x7A, ConfigD=0x7B,
909 RxMissed=0x7C, RxCRCErrs=0x7E, MiscCmd=0x81,
910 StickyHW=0x83, IntrStatus2=0x84, WOLcrClr=0xA4, WOLcgClr=0xA7,
911 PwrcsrClr=0xAC,
914 /* Bits in the interrupt status/mask registers. */
915 enum intr_status_bits {
916 IntrRxDone=0x0001, IntrRxErr=0x0004, IntrRxEmpty=0x0020,
917 IntrTxDone=0x0002, IntrTxError=0x0008, IntrTxUnderrun=0x0210,
918 IntrPCIErr=0x0040,
919 IntrStatsMax=0x0080, IntrRxEarly=0x0100,
920 IntrRxOverflow=0x0400, IntrRxDropped=0x0800, IntrRxNoBuf=0x1000,
921 IntrTxAborted=0x2000, IntrLinkChange=0x4000,
922 IntrRxWakeUp=0x8000,
923 IntrNormalSummary=0x0003, IntrAbnormalSummary=0xC260,
924 IntrTxDescRace=0x080000, /* mapped from IntrStatus2 */
925 IntrTxErrSummary=0x082218,
927 #define DEFAULT_INTR (IntrRxDone | IntrRxErr | IntrRxEmpty| IntrRxOverflow | \
928 IntrRxDropped | IntrRxNoBuf)
930 /***************************************************************************
931 IRQ - PXE IRQ Handler
932 ***************************************************************************/
933 void rhine_irq ( struct nic *nic, irq_action_t action ) {
934 struct rhine_private *tp = (struct rhine_private *) nic->priv_data;
935 /* Enable interrupts by setting the interrupt mask. */
936 unsigned int intr_status;
938 switch ( action ) {
939 case DISABLE :
940 case ENABLE :
941 intr_status = inw(nic->ioaddr + IntrStatus);
942 /* On Rhine-II, Bit 3 indicates Tx descriptor write-back race. */
944 /* added comment by guard */
945 /* For supporting VT6107, please use revision id to recognize different chips in driver */
946 // if (tp->chip_id == 0x3065)
947 if( tp->chip_revision < 0x80 && tp->chip_revision >=0x40 )
948 intr_status |= inb(nic->ioaddr + IntrStatus2) << 16;
949 intr_status = (intr_status & ~DEFAULT_INTR);
950 if ( action == ENABLE )
951 intr_status = intr_status | DEFAULT_INTR;
952 outw(intr_status, nic->ioaddr + IntrEnable);
953 break;
954 case FORCE :
955 outw(0x0010, nic->ioaddr + 0x84);
956 break;
960 static struct nic_operations rhine_operations;
962 static int
963 rhine_probe ( struct nic *nic, struct pci_device *pci ) {
965 struct rhine_private *tp = (struct rhine_private *) nic->priv_data;
967 if (!pci->ioaddr)
968 return 0;
970 rhine_probe1 (nic, pci, pci->ioaddr, pci->device, -1);
972 adjust_pci_device ( pci );
974 rhine_reset (nic);
976 nic->nic_op = &rhine_operations;
978 nic->irqno = pci->irq;
979 nic->ioaddr = tp->ioaddr;
981 return 1;
984 static void set_rx_mode(struct nic *nic __unused) {
985 struct rhine_private *tp = (struct rhine_private *) nic->priv_data;
986 unsigned char rx_mode;
987 int ioaddr = tp->ioaddr;
989 /* ! IFF_PROMISC */
990 outl(0xffffffff, byMAR0);
991 outl(0xffffffff, byMAR4);
992 rx_mode = 0x0C;
994 outb(0x60 /* thresh */ | rx_mode, byRCR );
997 static void
998 rhine_probe1 (struct nic *nic, struct pci_device *pci, int ioaddr, int chip_id, int options)
1000 struct rhine_private *tp;
1001 static int did_version = 0; /* Already printed version info. */
1002 unsigned int i, ww;
1003 unsigned int timeout;
1004 int FDXFlag;
1005 int byMIIvalue, LineSpeed, MIICRbak;
1006 uint8_t revision_id;
1007 unsigned char mode3_reg;
1009 if (rhine_debug > 0 && did_version++ == 0)
1010 printf (version);
1012 // get revision id.
1013 pci_read_config_byte(pci, PCI_REVISION, &revision_id);
1015 /* D-Link provided reset code (with comment additions) */
1016 if (revision_id >= 0x40) {
1017 unsigned char byOrgValue;
1019 if(rhine_debug > 0)
1020 printf("Enabling Sticky Bit Workaround for Chip_id: 0x%hX\n"
1021 , chip_id);
1022 /* clear sticky bit before reset & read ethernet address */
1023 byOrgValue = inb(bySTICKHW);
1024 byOrgValue = byOrgValue & 0xFC;
1025 outb(byOrgValue, bySTICKHW);
1027 /* (bits written are cleared?) */
1028 /* disable force PME-enable */
1029 outb(0x80, byWOLcgClr);
1030 /* disable power-event config bit */
1031 outb(0xFF, byWOLcrClr);
1032 /* clear power status (undocumented in vt6102 docs?) */
1033 outb(0xFF, byPwrcsrClr);
1037 /* Reset the chip to erase previous misconfiguration. */
1038 outw(CR_SFRST, byCR0);
1039 // if vt3043 delay after reset
1040 if (revision_id <0x40) {
1041 udelay(10000);
1043 // polling till software reset complete
1044 // W_MAX_TIMEOUT is the timeout period
1045 for(ww = 0; ww < W_MAX_TIMEOUT; ww++) {
1046 if ((inw(byCR0) & CR_SFRST) == 0)
1047 break;
1050 // issue AUTOLoad in EECSR to reload eeprom
1051 outb(0x20, byEECSR );
1053 // if vt3065 delay after reset
1054 if (revision_id >=0x40) {
1055 // delay 8ms to let MAC stable
1056 mdelay(8);
1058 * for 3065D, EEPROM reloaded will cause bit 0 in MAC_REG_CFGA
1059 * turned on. it makes MAC receive magic packet
1060 * automatically. So, we turn it off. (D-Link)
1062 outb(inb(byCFGA) & 0xFE, byCFGA);
1065 /* turn on bit2 in PCI configuration register 0x53 , only for 3065*/
1066 if (revision_id >= 0x40) {
1067 pci_read_config_byte(pci, PCI_REG_MODE3, &mode3_reg);
1068 pci_write_config_byte(pci, PCI_REG_MODE3, mode3_reg|MODE3_MIION);
1072 /* back off algorithm ,disable the right-most 4-bit off CFGD*/
1073 outb(inb(byCFGD) & (~(CFGD_RANDOM | CFGD_CFDX | CFGD_CEREN | CFGD_CETEN)), byCFGD);
1075 /* reload eeprom */
1076 reload_eeprom(ioaddr);
1078 /* Perhaps this should be read from the EEPROM? */
1079 for (i = 0; i < ETH_ALEN; i++)
1080 nic->node_addr[i] = inb (byPAR0 + i);
1082 DBG ( "IO address %#hX Ethernet Address: %s\n", ioaddr, eth_ntoa ( nic->node_addr ) );
1084 /* restart MII auto-negotiation */
1085 WriteMII (0, 9, 1, ioaddr);
1086 printf ("Analyzing Media type,this may take several seconds... ");
1087 for (i = 0; i < 5; i++)
1089 /* need to wait 1 millisecond - we will round it up to 50-100ms */
1090 timeout = currticks() + 2;
1091 for (timeout = currticks() + 2; currticks() < timeout;)
1092 /* nothing */;
1093 if (ReadMII (1, ioaddr) & 0x0020)
1094 break;
1096 printf ("OK.\n");
1098 #if 0
1099 /* JJM : for Debug */
1100 printf("MII : Address %hhX ",inb(ioaddr+0x6c));
1102 unsigned char st1,st2,adv1,adv2,l1,l2;
1104 st1=ReadMII(1,ioaddr)>>8;
1105 st2=ReadMII(1,ioaddr)&0xFF;
1106 adv1=ReadMII(4,ioaddr)>>8;
1107 adv2=ReadMII(4,ioaddr)&0xFF;
1108 l1=ReadMII(5,ioaddr)>>8;
1109 l2=ReadMII(5,ioaddr)&0xFF;
1110 printf(" status 0x%hhX%hhX, advertising 0x%hhX%hhX, link 0x%hhX%hhX\n", st1,st2,adv1,adv2,l1,l2);
1112 #endif
1115 /* query MII to know LineSpeed,duplex mode */
1116 byMIIvalue = inb (ioaddr + 0x6d);
1117 LineSpeed = byMIIvalue & MIISR_SPEED;
1118 if (LineSpeed != 0) //JJM
1120 printf ("Linespeed=10Mbs");
1122 else
1124 printf ("Linespeed=100Mbs");
1127 FDXFlag = QueryAuto (ioaddr);
1128 if (FDXFlag == 1)
1130 printf (" Fullduplex\n");
1131 outw (CR_FDX, byCR0);
1133 else
1135 printf (" Halfduplex\n");
1139 /* set MII 10 FULL ON, only apply in vt3043 */
1140 if(chip_id == 0x3043)
1141 WriteMII (0x17, 1, 1, ioaddr);
1143 /* turn on MII link change */
1144 MIICRbak = inb (byMIICR);
1145 outb (MIICRbak & 0x7F, byMIICR);
1146 MIIDelay ();
1147 outb (0x41, byMIIAD);
1148 MIIDelay ();
1150 /* while((inb(byMIIAD)&0x20)==0) ; */
1151 outb (MIICRbak | 0x80, byMIICR);
1153 nic->priv_data = &rhine;
1154 tp = &rhine;
1155 tp->chip_id = chip_id;
1156 tp->ioaddr = ioaddr;
1157 tp->phys[0] = -1;
1158 tp->chip_revision = revision_id;
1160 /* The lower four bits are the media type. */
1161 if (options > 0)
1163 tp->full_duplex = (options & 16) ? 1 : 0;
1164 tp->default_port = options & 15;
1165 if (tp->default_port)
1166 tp->medialock = 1;
1168 return;
1171 static void
1172 rhine_disable ( struct nic *nic ) {
1174 struct rhine_private *tp = (struct rhine_private *) nic->priv_data;
1175 int ioaddr = tp->ioaddr;
1177 rhine_reset(nic);
1179 printf ("rhine disable\n");
1180 /* Switch to loopback mode to avoid hardware races. */
1181 writeb(0x60 | 0x01, byTCR);
1182 /* Stop the chip's Tx and Rx processes. */
1183 writew(CR_STOP, byCR0);
1186 /**************************************************************************
1187 ETH_RESET - Reset adapter
1188 ***************************************************************************/
1189 static void
1190 rhine_reset (struct nic *nic)
1192 struct rhine_private *tp = (struct rhine_private *) nic->priv_data;
1193 int ioaddr = tp->ioaddr;
1194 int i, j;
1195 int FDXFlag, CRbak;
1196 int rx_ring_tmp, rx_ring_tmp1;
1197 int tx_ring_tmp, tx_ring_tmp1;
1198 int rx_bufs_tmp, rx_bufs_tmp1;
1199 int tx_bufs_tmp, tx_bufs_tmp1;
1201 /* printf ("rhine_reset\n"); */
1202 /* Soft reset the chip. */
1203 /*outb(CmdReset, ioaddr + ChipCmd); */
1205 tx_bufs_tmp = (int) rhine_buffers.txbuf;
1206 tx_ring_tmp = (int) rhine_buffers.txdesc;
1207 rx_bufs_tmp = (int) rhine_buffers.rxbuf;
1208 rx_ring_tmp = (int) rhine_buffers.rxdesc;
1210 /* tune RD TD 32 byte alignment */
1211 rx_ring_tmp1 = (int) virt_to_bus ((char *) rx_ring_tmp);
1212 j = (rx_ring_tmp1 + 32) & (~0x1f);
1213 /* printf ("txring[%d]", j); */
1214 tp->rx_ring = (struct rhine_rx_desc *) bus_to_virt (j);
1216 tx_ring_tmp1 = (int) virt_to_bus ((char *) tx_ring_tmp);
1217 j = (tx_ring_tmp1 + 32) & (~0x1f);
1218 tp->tx_ring = (struct rhine_tx_desc *) bus_to_virt (j);
1219 /* printf ("rxring[%X]", j); */
1222 tx_bufs_tmp1 = (int) virt_to_bus ((char *) tx_bufs_tmp);
1223 j = (int) (tx_bufs_tmp1 + 32) & (~0x1f);
1224 tx_bufs_tmp = (int) bus_to_virt (j);
1225 /* printf ("txb[%X]", j); */
1227 rx_bufs_tmp1 = (int) virt_to_bus ((char *) rx_bufs_tmp);
1228 j = (int) (rx_bufs_tmp1 + 32) & (~0x1f);
1229 rx_bufs_tmp = (int) bus_to_virt (j);
1230 /* printf ("rxb[%X][%X]", rx_bufs_tmp1, j); */
1232 for (i = 0; i < RX_RING_SIZE; i++)
1234 tp->rx_buffs[i] = (char *) rx_bufs_tmp;
1235 /* printf("r[%X]",tp->rx_buffs[i]); */
1236 rx_bufs_tmp += 1536;
1239 for (i = 0; i < TX_RING_SIZE; i++)
1241 tp->tx_buffs[i] = (char *) tx_bufs_tmp;
1242 /* printf("t[%X]",tp->tx_buffs[i]); */
1243 tx_bufs_tmp += 1536;
1246 /* software reset */
1247 outb (CR1_SFRST, byCR1);
1248 MIIDelay ();
1250 /* printf ("init ring"); */
1251 rhine_init_ring (nic);
1252 /*write TD RD Descriptor to MAC */
1253 outl (virt_to_bus (tp->rx_ring), dwCurrentRxDescAddr);
1254 outl (virt_to_bus (tp->tx_ring), dwCurrentTxDescAddr);
1256 /* Setup Multicast */
1257 set_rx_mode(nic);
1259 /* set TCR RCR threshold to store and forward*/
1260 outb (0x3e, byBCR0);
1261 outb (0x38, byBCR1);
1262 outb (0x2c, byRCR);
1263 outb (0x60, byTCR);
1264 /* Set Fulldupex */
1265 FDXFlag = QueryAuto (ioaddr);
1266 if (FDXFlag == 1)
1268 outb (CFGD_CFDX, byCFGD);
1269 outw (CR_FDX, byCR0);
1272 /* KICK NIC to WORK */
1273 CRbak = inw (byCR0);
1274 CRbak = CRbak & 0xFFFB; /* not CR_STOP */
1275 outw ((CRbak | CR_STRT | CR_TXON | CR_RXON | CR_DPOLL), byCR0);
1277 /* disable all known interrupt */
1278 outw (0, byIMR0);
1280 /* Beware of PCI posted writes */
1281 #define IOSYNC do { readb(nic->ioaddr + StationAddr); } while (0)
1283 static int
1284 rhine_poll (struct nic *nic, int retreive)
1286 struct rhine_private *tp = (struct rhine_private *) nic->priv_data;
1287 int rxstatus, good = 0;;
1289 if (tp->rx_ring[tp->cur_rx].rx_status.bits.own_bit == 0)
1291 unsigned int intr_status;
1292 /* There is a packet ready */
1293 if(!retreive)
1294 return 1;
1296 intr_status = inw(nic->ioaddr + IntrStatus);
1297 /* On Rhine-II, Bit 3 indicates Tx descriptor write-back race. */
1298 #if 0
1299 if (tp->chip_id == 0x3065)
1300 intr_status |= inb(nic->ioaddr + IntrStatus2) << 16;
1301 #endif
1302 /* Acknowledge all of the current interrupt sources ASAP. */
1303 if (intr_status & IntrTxDescRace)
1304 outb(0x08, nic->ioaddr + IntrStatus2);
1305 outw(intr_status & 0xffff, nic->ioaddr + IntrStatus);
1306 IOSYNC;
1308 rxstatus = tp->rx_ring[tp->cur_rx].rx_status.lw;
1309 if ((rxstatus & 0x0300) != 0x0300)
1311 printf("rhine_poll: bad status\n");
1313 else if (rxstatus & (RSR_ABNORMAL))
1315 printf ("rxerr[%X]\n", rxstatus);
1317 else
1318 good = 1;
1320 if (good)
1322 nic->packetlen = tp->rx_ring[tp->cur_rx].rx_status.bits.frame_length;
1323 memcpy (nic->packet, tp->rx_buffs[tp->cur_rx], nic->packetlen);
1324 /* printf ("Packet RXed\n"); */
1326 tp->rx_ring[tp->cur_rx].rx_status.bits.own_bit = 1;
1327 tp->cur_rx++;
1328 tp->cur_rx = tp->cur_rx % RX_RING_SIZE;
1330 /* Acknowledge all of the current interrupt sources ASAP. */
1331 outw(DEFAULT_INTR & ~IntrRxDone, nic->ioaddr + IntrStatus);
1333 IOSYNC;
1335 return good;
1338 static void
1339 rhine_transmit (struct nic *nic,
1340 const char *d, unsigned int t, unsigned int s, const char *p)
1342 struct rhine_private *tp = (struct rhine_private *) nic->priv_data;
1343 int ioaddr = tp->ioaddr;
1344 int entry;
1345 unsigned char CR1bak;
1346 unsigned char CR0bak;
1347 unsigned int nstype;
1350 /*printf ("rhine_transmit\n"); */
1351 /* setup ethernet header */
1354 /* Calculate the next Tx descriptor entry. */
1355 entry = tp->cur_tx % TX_RING_SIZE;
1357 memcpy (tp->tx_buffs[entry], d, ETH_ALEN); /* dst */
1358 memcpy (tp->tx_buffs[entry] + ETH_ALEN, nic->node_addr, ETH_ALEN); /* src */
1360 nstype=htons(t);
1361 memcpy(tp->tx_buffs[entry] + 2 * ETH_ALEN, (char*)&nstype, 2);
1363 memcpy (tp->tx_buffs[entry] + ETH_HLEN, p, s);
1364 s += ETH_HLEN;
1365 while (s < ETH_ZLEN)
1366 *((char *) tp->tx_buffs[entry] + (s++)) = 0;
1368 tp->tx_ring[entry].tx_ctrl.bits.tx_buf_size = s;
1370 tp->tx_ring[entry].tx_status.bits.own_bit = 1;
1373 CR1bak = inb (byCR1);
1375 CR1bak = CR1bak | CR1_TDMD1;
1376 /*printf("tdsw=[%X]",tp->tx_ring[entry].tx_status.lw); */
1377 /*printf("tdcw=[%X]",tp->tx_ring[entry].tx_ctrl.lw); */
1378 /*printf("tdbuf1=[%X]",tp->tx_ring[entry].buf_addr_1); */
1379 /*printf("tdbuf2=[%X]",tp->tx_ring[entry].buf_addr_2); */
1380 /*printf("td1=[%X]",inl(dwCurrentTDSE0)); */
1381 /*printf("td2=[%X]",inl(dwCurrentTDSE1)); */
1382 /*printf("td3=[%X]",inl(dwCurrentTDSE2)); */
1383 /*printf("td4=[%X]",inl(dwCurrentTDSE3)); */
1385 outb (CR1bak, byCR1);
1388 load_timer2(10*TICKS_PER_MS);
1389 /* Wait until transmit is finished or timeout*/
1390 while((tp->tx_ring[entry].tx_status.bits.own_bit !=0) && timer2_running())
1393 if(tp->tx_ring[entry].tx_status.bits.terr == 0)
1394 break;
1396 if(tp->tx_ring[entry].tx_status.bits.abt == 1)
1398 // turn on TX
1399 CR0bak = inb(byCR0);
1400 CR0bak = CR0bak|CR_TXON;
1401 outb(CR0bak,byCR0);
1403 }while(0);
1404 tp->cur_tx++;
1406 /*outw(IMRShadow,byIMR0); */
1407 /*dev_kfree_skb(tp->tx_skbuff[entry], FREE_WRITE); */
1408 /*tp->tx_skbuff[entry] = 0; */
1411 static struct nic_operations rhine_operations = {
1412 .connect = dummy_connect,
1413 .poll = rhine_poll,
1414 .transmit = rhine_transmit,
1415 .irq = rhine_irq,
1419 static struct pci_device_id rhine_nics[] = {
1420 PCI_ROM(0x1106, 0x3065, "dlink-530tx", "VIA 6102"),
1421 PCI_ROM(0x1106, 0x3106, "via-rhine-6105", "VIA 6105"),
1422 PCI_ROM(0x1106, 0x3043, "dlink-530tx-old", "VIA 3043"), /* Rhine-I 86c100a */
1423 PCI_ROM(0x1106, 0x3053, "via6105m", "VIA 6105M"),
1424 PCI_ROM(0x1106, 0x6100, "via-rhine-old", "VIA 86C100A"), /* Rhine-II */
1427 PCI_DRIVER ( rhine_driver, rhine_nics, PCI_NO_CLASS );
1429 DRIVER ( "VIA 86C100", nic_driver, pci_driver, rhine_driver,
1430 rhine_probe, rhine_disable );
1432 /* EOF via-rhine.c */
1435 * Local variables:
1436 * c-basic-offset: 8
1437 * c-indent-level: 8
1438 * tab-width: 8
1439 * End: