Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / ipxe / src / drivers / net / realtek.c
1 /*
2  * Copyright (C) 2012 Michael Brown <mbrown@fensystems.co.uk>.
3  *
4  * (EEPROM code originally implemented for rtl8139.c)
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; either version 2 of the
9  * License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301, USA.
20  */
21
22 FILE_LICENCE ( GPL2_OR_LATER );
23
24 #include <stdint.h>
25 #include <string.h>
26 #include <unistd.h>
27 #include <errno.h>
28 #include <byteswap.h>
29 #include <ipxe/netdevice.h>
30 #include <ipxe/ethernet.h>
31 #include <ipxe/if_ether.h>
32 #include <ipxe/iobuf.h>
33 #include <ipxe/malloc.h>
34 #include <ipxe/pci.h>
35 #include <ipxe/nvs.h>
36 #include <ipxe/threewire.h>
37 #include <ipxe/bitbash.h>
38 #include <ipxe/mii.h>
39 #include "realtek.h"
40
41 /** @file
42  *
43  * Realtek 10/100/1000 network card driver
44  *
45  * Based on the following datasheets:
46  *
47  *    http://www.datasheetarchive.com/dl/Datasheets-8/DSA-153536.pdf
48  *    http://www.datasheetarchive.com/indexdl/Datasheet-028/DSA00494723.pdf
49  */
50
51 /******************************************************************************
52  *
53  * Debugging
54  *
55  ******************************************************************************
56  */
57
58 /**
59  * Dump all registers (for debugging)
60  *
61  * @v rtl               Realtek device
62  */
63 static __attribute__ (( unused )) void realtek_dump ( struct realtek_nic *rtl ){
64         uint8_t regs[256];
65         unsigned int i;
66
67         /* Do nothing unless debug output is enabled */
68         if ( ! DBG_LOG )
69                 return;
70
71         /* Dump registers (via byte accesses; may not work for all registers) */
72         for ( i = 0 ; i < sizeof ( regs ) ; i++ )
73                 regs[i] = readb ( rtl->regs + i );
74         DBGC ( rtl, "REALTEK %p register dump:\n", rtl );
75         DBGC_HDA ( rtl, 0, regs, sizeof ( regs ) );
76 }
77
78 /******************************************************************************
79  *
80  * EEPROM interface
81  *
82  ******************************************************************************
83  */
84
85 /** Pin mapping for SPI bit-bashing interface */
86 static const uint8_t realtek_eeprom_bits[] = {
87         [SPI_BIT_SCLK]  = RTL_9346CR_EESK,
88         [SPI_BIT_MOSI]  = RTL_9346CR_EEDI,
89         [SPI_BIT_MISO]  = RTL_9346CR_EEDO,
90         [SPI_BIT_SS(0)] = RTL_9346CR_EECS,
91 };
92
93 /**
94  * Open bit-bashing interface
95  *
96  * @v basher            Bit-bashing interface
97  */
98 static void realtek_spi_open_bit ( struct bit_basher *basher ) {
99         struct realtek_nic *rtl = container_of ( basher, struct realtek_nic,
100                                                  spibit.basher );
101
102         /* Enable EEPROM access */
103         writeb ( RTL_9346CR_EEM_EEPROM, rtl->regs + RTL_9346CR );
104         readb ( rtl->regs + RTL_9346CR ); /* Ensure write reaches chip */
105 }
106
107 /**
108  * Close bit-bashing interface
109  *
110  * @v basher            Bit-bashing interface
111  */
112 static void realtek_spi_close_bit ( struct bit_basher *basher ) {
113         struct realtek_nic *rtl = container_of ( basher, struct realtek_nic,
114                                                  spibit.basher );
115
116         /* Disable EEPROM access */
117         writeb ( RTL_9346CR_EEM_NORMAL, rtl->regs + RTL_9346CR );
118         readb ( rtl->regs + RTL_9346CR ); /* Ensure write reaches chip */
119 }
120
121 /**
122  * Read input bit
123  *
124  * @v basher            Bit-bashing interface
125  * @v bit_id            Bit number
126  * @ret zero            Input is a logic 0
127  * @ret non-zero        Input is a logic 1
128  */
129 static int realtek_spi_read_bit ( struct bit_basher *basher,
130                                   unsigned int bit_id ) {
131         struct realtek_nic *rtl = container_of ( basher, struct realtek_nic,
132                                                  spibit.basher );
133         uint8_t mask = realtek_eeprom_bits[bit_id];
134         uint8_t reg;
135
136         DBG_DISABLE ( DBGLVL_IO );
137         reg = readb ( rtl->regs + RTL_9346CR );
138         DBG_ENABLE ( DBGLVL_IO );
139         return ( reg & mask );
140 }
141
142 /**
143  * Set/clear output bit
144  *
145  * @v basher            Bit-bashing interface
146  * @v bit_id            Bit number
147  * @v data              Value to write
148  */
149 static void realtek_spi_write_bit ( struct bit_basher *basher,
150                                     unsigned int bit_id, unsigned long data ) {
151         struct realtek_nic *rtl = container_of ( basher, struct realtek_nic,
152                                                  spibit.basher );
153         uint8_t mask = realtek_eeprom_bits[bit_id];
154         uint8_t reg;
155
156         DBG_DISABLE ( DBGLVL_IO );
157         reg = readb ( rtl->regs + RTL_9346CR );
158         reg &= ~mask;
159         reg |= ( data & mask );
160         writeb ( reg, rtl->regs + RTL_9346CR );
161         readb ( rtl->regs + RTL_9346CR ); /* Ensure write reaches chip */
162         DBG_ENABLE ( DBGLVL_IO );
163 }
164
165 /** SPI bit-bashing interface */
166 static struct bit_basher_operations realtek_basher_ops = {
167         .open = realtek_spi_open_bit,
168         .close = realtek_spi_close_bit,
169         .read = realtek_spi_read_bit,
170         .write = realtek_spi_write_bit,
171 };
172
173 /**
174  * Initialise EEPROM
175  *
176  * @v netdev            Network device
177  * @ret rc              Return status code
178  */
179 static int realtek_init_eeprom ( struct net_device *netdev ) {
180         struct realtek_nic *rtl = netdev->priv;
181         uint16_t id;
182         int rc;
183
184         /* Initialise SPI bit-bashing interface */
185         rtl->spibit.basher.op = &realtek_basher_ops;
186         rtl->spibit.bus.mode = SPI_MODE_THREEWIRE;
187         init_spi_bit_basher ( &rtl->spibit );
188
189         /* Detect EEPROM type and initialise three-wire device */
190         if ( readl ( rtl->regs + RTL_RCR ) & RTL_RCR_9356SEL ) {
191                 DBGC ( rtl, "REALTEK %p EEPROM is a 93C56\n", rtl );
192                 init_at93c56 ( &rtl->eeprom, 16 );
193         } else {
194                 DBGC ( rtl, "REALTEK %p EEPROM is a 93C46\n", rtl );
195                 init_at93c46 ( &rtl->eeprom, 16 );
196         }
197         rtl->eeprom.bus = &rtl->spibit.bus;
198
199         /* Check for EEPROM presence.  Some onboard NICs will have no
200          * EEPROM connected, with the BIOS being responsible for
201          * programming the initial register values.
202          */
203         if ( ( rc = nvs_read ( &rtl->eeprom.nvs, RTL_EEPROM_ID,
204                                &id, sizeof ( id ) ) ) != 0 ) {
205                 DBGC ( rtl, "REALTEK %p could not read EEPROM ID: %s\n",
206                        rtl, strerror ( rc ) );
207                 return rc;
208         }
209         if ( id != cpu_to_le16 ( RTL_EEPROM_ID_MAGIC ) ) {
210                 DBGC ( rtl, "REALTEK %p EEPROM ID incorrect (%#04x); assuming "
211                        "no EEPROM\n", rtl, le16_to_cpu ( id ) );
212                 return -ENODEV;
213         }
214
215         /* Initialise space for non-volatile options, if available
216          *
217          * We use offset 0x40 (i.e. address 0x20), length 0x40.  This
218          * block is marked as VPD in the Realtek datasheets, so we use
219          * it only if we detect that the card is not supporting VPD.
220          */
221         if ( readb ( rtl->regs + RTL_CONFIG1 ) & RTL_CONFIG1_VPD ) {
222                 DBGC ( rtl, "REALTEK %p EEPROM in use for VPD; cannot use "
223                        "for options\n", rtl );
224         } else {
225                 nvo_init ( &rtl->nvo, &rtl->eeprom.nvs, RTL_EEPROM_VPD,
226                            RTL_EEPROM_VPD_LEN, NULL, &netdev->refcnt );
227         }
228
229         return 0;
230 }
231
232 /******************************************************************************
233  *
234  * MII interface
235  *
236  ******************************************************************************
237  */
238
239 /**
240  * Read from MII register
241  *
242  * @v mii               MII interface
243  * @v reg               Register address
244  * @ret value           Data read, or negative error
245  */
246 static int realtek_mii_read ( struct mii_interface *mii, unsigned int reg ) {
247         struct realtek_nic *rtl = container_of ( mii, struct realtek_nic, mii );
248         unsigned int i;
249         uint32_t value;
250
251         /* Fail if PHYAR register is not present */
252         if ( ! rtl->have_phy_regs )
253                 return -ENOTSUP;
254
255         /* Initiate read */
256         writel ( RTL_PHYAR_VALUE ( 0, reg, 0 ), rtl->regs + RTL_PHYAR );
257
258         /* Wait for read to complete */
259         for ( i = 0 ; i < RTL_MII_MAX_WAIT_US ; i++ ) {
260
261                 /* If read is not complete, delay 1us and retry */
262                 value = readl ( rtl->regs + RTL_PHYAR );
263                 if ( ! ( value & RTL_PHYAR_FLAG ) ) {
264                         udelay ( 1 );
265                         continue;
266                 }
267
268                 /* Return register value */
269                 return ( RTL_PHYAR_DATA ( value ) );
270         }
271
272         DBGC ( rtl, "REALTEK %p timed out waiting for MII read\n", rtl );
273         return -ETIMEDOUT;
274 }
275
276 /**
277  * Write to MII register
278  *
279  * @v mii               MII interface
280  * @v reg               Register address
281  * @v data              Data to write
282  * @ret rc              Return status code
283  */
284 static int realtek_mii_write ( struct mii_interface *mii, unsigned int reg,
285                                unsigned int data) {
286         struct realtek_nic *rtl = container_of ( mii, struct realtek_nic, mii );
287         unsigned int i;
288
289         /* Fail if PHYAR register is not present */
290         if ( ! rtl->have_phy_regs )
291                 return -ENOTSUP;
292
293         /* Initiate write */
294         writel ( RTL_PHYAR_VALUE ( RTL_PHYAR_FLAG, reg, data ),
295                  rtl->regs + RTL_PHYAR );
296
297         /* Wait for write to complete */
298         for ( i = 0 ; i < RTL_MII_MAX_WAIT_US ; i++ ) {
299
300                 /* If write is not complete, delay 1us and retry */
301                 if ( readl ( rtl->regs + RTL_PHYAR ) & RTL_PHYAR_FLAG ) {
302                         udelay ( 1 );
303                         continue;
304                 }
305
306                 return 0;
307         }
308
309         DBGC ( rtl, "REALTEK %p timed out waiting for MII write\n", rtl );
310         return -ETIMEDOUT;
311 }
312
313 /** Realtek MII operations */
314 static struct mii_operations realtek_mii_operations = {
315         .read = realtek_mii_read,
316         .write = realtek_mii_write,
317 };
318
319 /******************************************************************************
320  *
321  * Device reset
322  *
323  ******************************************************************************
324  */
325
326 /**
327  * Reset hardware
328  *
329  * @v rtl               Realtek device
330  * @ret rc              Return status code
331  */
332 static int realtek_reset ( struct realtek_nic *rtl ) {
333         unsigned int i;
334
335         /* Issue reset */
336         writeb ( RTL_CR_RST, rtl->regs + RTL_CR );
337
338         /* Wait for reset to complete */
339         for ( i = 0 ; i < RTL_RESET_MAX_WAIT_MS ; i++ ) {
340
341                 /* If reset is not complete, delay 1ms and retry */
342                 if ( readb ( rtl->regs + RTL_CR ) & RTL_CR_RST ) {
343                         mdelay ( 1 );
344                         continue;
345                 }
346
347                 return 0;
348         }
349
350         DBGC ( rtl, "REALTEK %p timed out waiting for reset\n", rtl );
351         return -ETIMEDOUT;
352 }
353
354 /**
355  * Configure PHY for Gigabit operation
356  *
357  * @v rtl               Realtek device
358  * @ret rc              Return status code
359  */
360 static int realtek_phy_speed ( struct realtek_nic *rtl ) {
361         int ctrl1000;
362         int rc;
363
364         /* Read CTRL1000 register */
365         ctrl1000 = mii_read ( &rtl->mii, MII_CTRL1000 );
366         if ( ctrl1000 < 0 ) {
367                 rc = ctrl1000;
368                 DBGC ( rtl, "REALTEK %p could not read CTRL1000: %s\n",
369                        rtl, strerror ( rc ) );
370                 return rc;
371         }
372
373         /* Advertise 1000Mbps speeds */
374         ctrl1000 |= ( ADVERTISE_1000FULL | ADVERTISE_1000HALF );
375         if ( ( rc = mii_write ( &rtl->mii, MII_CTRL1000, ctrl1000 ) ) != 0 ) {
376                 DBGC ( rtl, "REALTEK %p could not write CTRL1000: %s\n",
377                        rtl, strerror ( rc ) );
378                 return rc;
379         }
380
381         return 0;
382 }
383
384 /**
385  * Reset PHY
386  *
387  * @v rtl               Realtek device
388  * @ret rc              Return status code
389  */
390 static int realtek_phy_reset ( struct realtek_nic *rtl ) {
391         int rc;
392
393         /* Do nothing if we have no separate PHY register access */
394         if ( ! rtl->have_phy_regs )
395                 return 0;
396
397         /* Perform MII reset */
398         if ( ( rc = mii_reset ( &rtl->mii ) ) != 0 ) {
399                 DBGC ( rtl, "REALTEK %p could not reset MII: %s\n",
400                        rtl, strerror ( rc ) );
401                 return rc;
402         }
403
404         /* Some cards (e.g. RTL8169SC) do not advertise Gigabit by
405          * default.  Try to enable advertisement of Gigabit speeds.
406          */
407         if ( ( rc = realtek_phy_speed ( rtl ) ) != 0 ) {
408                 /* Ignore failures, since the register may not be
409                  * present on non-Gigabit PHYs (e.g. RTL8101).
410                  */
411         }
412
413         /* Restart autonegotiation */
414         if ( ( rc = mii_restart ( &rtl->mii ) ) != 0 ) {
415                 DBGC ( rtl, "REALTEK %p could not restart MII: %s\n",
416                        rtl, strerror ( rc ) );
417                 return rc;
418         }
419
420         return 0;
421 }
422
423 /******************************************************************************
424  *
425  * Link state
426  *
427  ******************************************************************************
428  */
429
430 /**
431  * Check link state
432  *
433  * @v netdev            Network device
434  */
435 static void realtek_check_link ( struct net_device *netdev ) {
436         struct realtek_nic *rtl = netdev->priv;
437         uint8_t phystatus;
438         uint8_t msr;
439         int link_up;
440
441         /* Determine link state */
442         if ( rtl->have_phy_regs ) {
443                 mii_dump ( &rtl->mii );
444                 phystatus = readb ( rtl->regs + RTL_PHYSTATUS );
445                 link_up = ( phystatus & RTL_PHYSTATUS_LINKSTS );
446                 DBGC ( rtl, "REALTEK %p PHY status is %02x (%s%s%s%s%s%s, "
447                        "Link%s, %sDuplex)\n", rtl, phystatus,
448                        ( ( phystatus & RTL_PHYSTATUS_ENTBI ) ? "TBI" : "GMII" ),
449                        ( ( phystatus & RTL_PHYSTATUS_TXFLOW ) ?
450                          ", TxFlow" : "" ),
451                        ( ( phystatus & RTL_PHYSTATUS_RXFLOW ) ?
452                          ", RxFlow" : "" ),
453                        ( ( phystatus & RTL_PHYSTATUS_1000MF ) ?
454                          ", 1000Mbps" : "" ),
455                        ( ( phystatus & RTL_PHYSTATUS_100M ) ?
456                          ", 100Mbps" : "" ),
457                        ( ( phystatus & RTL_PHYSTATUS_10M ) ?
458                          ", 10Mbps" : "" ),
459                        ( ( phystatus & RTL_PHYSTATUS_LINKSTS ) ?
460                          "Up" : "Down" ),
461                        ( ( phystatus & RTL_PHYSTATUS_FULLDUP ) ?
462                          "Full" : "Half" ) );
463         } else {
464                 msr = readb ( rtl->regs + RTL_MSR );
465                 link_up = ( ! ( msr & RTL_MSR_LINKB ) );
466                 DBGC ( rtl, "REALTEK %p media status is %02x (Link%s, "
467                        "%dMbps%s%s%s%s%s)\n", rtl, msr,
468                        ( ( msr & RTL_MSR_LINKB ) ? "Down" : "Up" ),
469                        ( ( msr & RTL_MSR_SPEED_10 ) ? 10 : 100 ),
470                        ( ( msr & RTL_MSR_TXFCE ) ? ", TxFlow" : "" ),
471                        ( ( msr & RTL_MSR_RXFCE ) ? ", RxFlow" : "" ),
472                        ( ( msr & RTL_MSR_AUX_STATUS ) ? ", AuxPwr" : "" ),
473                        ( ( msr & RTL_MSR_TXPF ) ? ", TxPause" : "" ),
474                        ( ( msr & RTL_MSR_RXPF ) ? ", RxPause" : "" ) );
475         }
476
477         /* Report link state */
478         if ( link_up ) {
479                 netdev_link_up ( netdev );
480         } else {
481                 netdev_link_down ( netdev );
482         }
483 }
484
485 /******************************************************************************
486  *
487  * Network device interface
488  *
489  ******************************************************************************
490  */
491
492 /**
493  * Create receive buffer (legacy mode)
494  *
495  * @v rtl               Realtek device
496  * @ret rc              Return status code
497  */
498 static int realtek_create_buffer ( struct realtek_nic *rtl ) {
499         size_t len = ( RTL_RXBUF_LEN + RTL_RXBUF_PAD );
500         physaddr_t address;
501         int rc;
502
503         /* Do nothing unless in legacy mode */
504         if ( ! rtl->legacy )
505                 return 0;
506
507         /* Allocate buffer */
508         rtl->rx_buffer = malloc_dma ( len, RTL_RXBUF_ALIGN );
509         if ( ! rtl->rx_buffer ) {
510                 rc = -ENOMEM;
511                 goto err_alloc;
512         }
513         address = virt_to_bus ( rtl->rx_buffer );
514
515         /* Check that card can support address */
516         if ( address & ~0xffffffffULL ) {
517                 DBGC ( rtl, "REALTEK %p cannot support 64-bit RX buffer "
518                        "address\n", rtl );
519                 rc = -ENOTSUP;
520                 goto err_64bit;
521         }
522
523         /* Program buffer address */
524         writel ( address, rtl->regs + RTL_RBSTART );
525         DBGC ( rtl, "REALTEK %p receive buffer is at [%08llx,%08llx,%08llx)\n",
526                rtl, ( ( unsigned long long ) address ),
527                ( ( unsigned long long ) address + RTL_RXBUF_LEN ),
528                ( ( unsigned long long ) address + len ) );
529
530         return 0;
531
532  err_64bit:
533         free_dma ( rtl->rx_buffer, len );
534         rtl->rx_buffer = NULL;
535  err_alloc:
536         return rc;
537 }
538
539 /**
540  * Destroy receive buffer (legacy mode)
541  *
542  * @v rtl               Realtek device
543  */
544 static void realtek_destroy_buffer ( struct realtek_nic *rtl ) {
545         size_t len = ( RTL_RXBUF_LEN + RTL_RXBUF_PAD );
546
547         /* Do nothing unless in legacy mode */
548         if ( ! rtl->legacy )
549                 return;
550
551         /* Clear buffer address */
552         writel ( 0, rtl->regs + RTL_RBSTART );
553
554         /* Free buffer */
555         free_dma ( rtl->rx_buffer, len );
556         rtl->rx_buffer = NULL;
557         rtl->rx_offset = 0;
558 }
559
560 /**
561  * Create descriptor ring
562  *
563  * @v rtl               Realtek device
564  * @v ring              Descriptor ring
565  * @ret rc              Return status code
566  */
567 static int realtek_create_ring ( struct realtek_nic *rtl,
568                                  struct realtek_ring *ring ) {
569         physaddr_t address;
570
571         /* Do nothing in legacy mode */
572         if ( rtl->legacy )
573                 return 0;
574
575         /* Allocate descriptor ring */
576         ring->desc = malloc_dma ( ring->len, RTL_RING_ALIGN );
577         if ( ! ring->desc )
578                 return -ENOMEM;
579
580         /* Initialise descriptor ring */
581         memset ( ring->desc, 0, ring->len );
582
583         /* Program ring address */
584         address = virt_to_bus ( ring->desc );
585         writel ( ( ( ( uint64_t ) address ) >> 32 ),
586                  rtl->regs + ring->reg + 4 );
587         writel ( ( address & 0xffffffffUL ), rtl->regs + ring->reg );
588         DBGC ( rtl, "REALTEK %p ring %02x is at [%08llx,%08llx)\n",
589                rtl, ring->reg, ( ( unsigned long long ) address ),
590                ( ( unsigned long long ) address + ring->len ) );
591
592         return 0;
593 }
594
595 /**
596  * Destroy descriptor ring
597  *
598  * @v rtl               Realtek device
599  * @v ring              Descriptor ring
600  */
601 static void realtek_destroy_ring ( struct realtek_nic *rtl,
602                                    struct realtek_ring *ring ) {
603
604         /* Reset producer and consumer counters */
605         ring->prod = 0;
606         ring->cons = 0;
607
608         /* Do nothing more if in legacy mode */
609         if ( rtl->legacy )
610                 return;
611
612         /* Clear ring address */
613         writel ( 0, rtl->regs + ring->reg );
614         writel ( 0, rtl->regs + ring->reg + 4 );
615
616         /* Free descriptor ring */
617         free_dma ( ring->desc, ring->len );
618         ring->desc = NULL;
619 }
620
621 /**
622  * Refill receive descriptor ring
623  *
624  * @v rtl               Realtek device
625  */
626 static void realtek_refill_rx ( struct realtek_nic *rtl ) {
627         struct realtek_descriptor *rx;
628         struct io_buffer *iobuf;
629         unsigned int rx_idx;
630         physaddr_t address;
631         int is_last;
632
633         /* Do nothing in legacy mode */
634         if ( rtl->legacy )
635                 return;
636
637         while ( ( rtl->rx.prod - rtl->rx.cons ) < RTL_NUM_RX_DESC ) {
638
639                 /* Allocate I/O buffer */
640                 iobuf = alloc_iob ( RTL_RX_MAX_LEN );
641                 if ( ! iobuf ) {
642                         /* Wait for next refill */
643                         return;
644                 }
645
646                 /* Get next receive descriptor */
647                 rx_idx = ( rtl->rx.prod++ % RTL_NUM_RX_DESC );
648                 is_last = ( rx_idx == ( RTL_NUM_RX_DESC - 1 ) );
649                 rx = &rtl->rx.desc[rx_idx];
650
651                 /* Populate receive descriptor */
652                 address = virt_to_bus ( iobuf->data );
653                 rx->address = cpu_to_le64 ( address );
654                 rx->length = cpu_to_le16 ( RTL_RX_MAX_LEN );
655                 wmb();
656                 rx->flags = ( cpu_to_le16 ( RTL_DESC_OWN ) |
657                               ( is_last ? cpu_to_le16 ( RTL_DESC_EOR ) : 0 ) );
658                 wmb();
659
660                 /* Record I/O buffer */
661                 assert ( rtl->rx_iobuf[rx_idx] == NULL );
662                 rtl->rx_iobuf[rx_idx] = iobuf;
663
664                 DBGC2 ( rtl, "REALTEK %p RX %d is [%llx,%llx)\n", rtl, rx_idx,
665                         ( ( unsigned long long ) address ),
666                         ( ( unsigned long long ) address + RTL_RX_MAX_LEN ) );
667         }
668 }
669
670 /**
671  * Open network device
672  *
673  * @v netdev            Network device
674  * @ret rc              Return status code
675  */
676 static int realtek_open ( struct net_device *netdev ) {
677         struct realtek_nic *rtl = netdev->priv;
678         uint32_t tcr;
679         uint32_t rcr;
680         int rc;
681
682         /* Create transmit descriptor ring */
683         if ( ( rc = realtek_create_ring ( rtl, &rtl->tx ) ) != 0 )
684                 goto err_create_tx;
685
686         /* Create receive descriptor ring */
687         if ( ( rc = realtek_create_ring ( rtl, &rtl->rx ) ) != 0 )
688                 goto err_create_rx;
689
690         /* Create receive buffer */
691         if ( ( rc = realtek_create_buffer ( rtl ) ) != 0 )
692                 goto err_create_buffer;
693
694         /* Accept all packets */
695         writel ( 0xffffffffUL, rtl->regs + RTL_MAR0 );
696         writel ( 0xffffffffUL, rtl->regs + RTL_MAR4 );
697
698         /* Enable transmitter and receiver.  RTL8139 requires that
699          * this happens before writing to RCR.
700          */
701         writeb ( ( RTL_CR_TE | RTL_CR_RE ), rtl->regs + RTL_CR );
702
703         /* Configure transmitter */
704         tcr = readl ( rtl->regs + RTL_TCR );
705         tcr &= ~RTL_TCR_MXDMA_MASK;
706         tcr |= RTL_TCR_MXDMA_DEFAULT;
707         writel ( tcr, rtl->regs + RTL_TCR );
708
709         /* Configure receiver */
710         rcr = readl ( rtl->regs + RTL_RCR );
711         rcr &= ~( RTL_RCR_STOP_WORKING | RTL_RCR_RXFTH_MASK |
712                   RTL_RCR_RBLEN_MASK | RTL_RCR_MXDMA_MASK );
713         rcr |= ( RTL_RCR_RXFTH_DEFAULT | RTL_RCR_RBLEN_DEFAULT |
714                  RTL_RCR_MXDMA_DEFAULT | RTL_RCR_WRAP | RTL_RCR_AB |
715                  RTL_RCR_AM | RTL_RCR_APM | RTL_RCR_AAP );
716         writel ( rcr, rtl->regs + RTL_RCR );
717
718         /* Fill receive ring */
719         realtek_refill_rx ( rtl );
720
721         /* Update link state */
722         realtek_check_link ( netdev );
723
724         return 0;
725
726         realtek_destroy_buffer ( rtl );
727  err_create_buffer:
728         realtek_destroy_ring ( rtl, &rtl->rx );
729  err_create_rx:
730         realtek_destroy_ring ( rtl, &rtl->tx );
731  err_create_tx:
732         return rc;
733 }
734
735 /**
736  * Close network device
737  *
738  * @v netdev            Network device
739  */
740 static void realtek_close ( struct net_device *netdev ) {
741         struct realtek_nic *rtl = netdev->priv;
742         unsigned int i;
743
744         /* Disable receiver and transmitter */
745         writeb ( 0, rtl->regs + RTL_CR );
746
747         /* Destroy receive buffer */
748         realtek_destroy_buffer ( rtl );
749
750         /* Destroy receive descriptor ring */
751         realtek_destroy_ring ( rtl, &rtl->rx );
752
753         /* Discard any unused receive buffers */
754         for ( i = 0 ; i < RTL_NUM_RX_DESC ; i++ ) {
755                 if ( rtl->rx_iobuf[i] )
756                         free_iob ( rtl->rx_iobuf[i] );
757                 rtl->rx_iobuf[i] = NULL;
758         }
759
760         /* Destroy transmit descriptor ring */
761         realtek_destroy_ring ( rtl, &rtl->tx );
762 }
763
764 /**
765  * Transmit packet
766  *
767  * @v netdev            Network device
768  * @v iobuf             I/O buffer
769  * @ret rc              Return status code
770  */
771 static int realtek_transmit ( struct net_device *netdev,
772                               struct io_buffer *iobuf ) {
773         struct realtek_nic *rtl = netdev->priv;
774         struct realtek_descriptor *tx;
775         unsigned int tx_idx;
776         physaddr_t address;
777         int is_last;
778
779         /* Get next transmit descriptor */
780         if ( ( rtl->tx.prod - rtl->tx.cons ) >= RTL_NUM_TX_DESC ) {
781                 netdev_tx_defer ( netdev, iobuf );
782                 return 0;
783         }
784         tx_idx = ( rtl->tx.prod++ % RTL_NUM_TX_DESC );
785
786         /* Transmit packet */
787         if ( rtl->legacy ) {
788
789                 /* Pad and align packet */
790                 iob_pad ( iobuf, ETH_ZLEN );
791                 address = virt_to_bus ( iobuf->data );
792
793                 /* Check that card can support address */
794                 if ( address & ~0xffffffffULL ) {
795                         DBGC ( rtl, "REALTEK %p cannot support 64-bit TX "
796                                "buffer address\n", rtl );
797                         return -ENOTSUP;
798                 }
799
800                 /* Add to transmit ring */
801                 writel ( address, rtl->regs + RTL_TSAD ( tx_idx ) );
802                 writel ( ( RTL_TSD_ERTXTH_DEFAULT | iob_len ( iobuf ) ),
803                          rtl->regs + RTL_TSD ( tx_idx ) );
804
805         } else {
806
807                 /* Populate transmit descriptor */
808                 address = virt_to_bus ( iobuf->data );
809                 is_last = ( tx_idx == ( RTL_NUM_TX_DESC - 1 ) );
810                 tx = &rtl->tx.desc[tx_idx];
811                 tx->address = cpu_to_le64 ( address );
812                 tx->length = cpu_to_le16 ( iob_len ( iobuf ) );
813                 wmb();
814                 tx->flags = ( cpu_to_le16 ( RTL_DESC_OWN | RTL_DESC_FS |
815                                             RTL_DESC_LS ) |
816                               ( is_last ? cpu_to_le16 ( RTL_DESC_EOR ) : 0 ) );
817                 wmb();
818
819                 /* Notify card that there are packets ready to transmit */
820                 writeb ( RTL_TPPOLL_NPQ, rtl->regs + rtl->tppoll );
821         }
822
823         DBGC2 ( rtl, "REALTEK %p TX %d is [%llx,%llx)\n", rtl, tx_idx,
824                 ( ( unsigned long long ) virt_to_bus ( iobuf->data ) ),
825                 ( ( ( unsigned long long ) virt_to_bus ( iobuf->data ) ) +
826                   iob_len ( iobuf ) ) );
827
828         return 0;
829 }
830
831 /**
832  * Poll for completed packets
833  *
834  * @v netdev            Network device
835  */
836 static void realtek_poll_tx ( struct net_device *netdev ) {
837         struct realtek_nic *rtl = netdev->priv;
838         struct realtek_descriptor *tx;
839         unsigned int tx_idx;
840
841         /* Check for completed packets */
842         while ( rtl->tx.cons != rtl->tx.prod ) {
843
844                 /* Get next transmit descriptor */
845                 tx_idx = ( rtl->tx.cons % RTL_NUM_TX_DESC );
846
847                 /* Stop if descriptor is still in use */
848                 if ( rtl->legacy ) {
849
850                         /* Check ownership bit in transmit status register */
851                         if ( ! ( readl ( rtl->regs + RTL_TSD ( tx_idx ) ) &
852                                  RTL_TSD_OWN ) )
853                                 return;
854
855                 } else {
856
857                         /* Check ownership bit in descriptor */
858                         tx = &rtl->tx.desc[tx_idx];
859                         if ( tx->flags & cpu_to_le16 ( RTL_DESC_OWN ) )
860                                 return;
861                 }
862
863                 DBGC2 ( rtl, "REALTEK %p TX %d complete\n", rtl, tx_idx );
864
865                 /* Complete TX descriptor */
866                 rtl->tx.cons++;
867                 netdev_tx_complete_next ( netdev );
868         }
869 }
870
871 /**
872  * Poll for received packets (legacy mode)
873  *
874  * @v netdev            Network device
875  */
876 static void realtek_legacy_poll_rx ( struct net_device *netdev ) {
877         struct realtek_nic *rtl = netdev->priv;
878         struct realtek_legacy_header *rx;
879         struct io_buffer *iobuf;
880         size_t len;
881
882         /* Check for received packets */
883         while ( ! ( readb ( rtl->regs + RTL_CR ) & RTL_CR_BUFE ) ) {
884
885                 /* Extract packet from receive buffer */
886                 rx = ( rtl->rx_buffer + rtl->rx_offset );
887                 len = le16_to_cpu ( rx->length );
888                 if ( rx->status & cpu_to_le16 ( RTL_STAT_ROK ) ) {
889
890                         DBGC2 ( rtl, "REALTEK %p RX offset %x+%zx\n",
891                                 rtl, rtl->rx_offset, len );
892
893                         /* Allocate I/O buffer */
894                         iobuf = alloc_iob ( len );
895                         if ( ! iobuf ) {
896                                 netdev_rx_err ( netdev, NULL, -ENOMEM );
897                                 /* Leave packet for next poll */
898                                 break;
899                         }
900
901                         /* Copy data to I/O buffer */
902                         memcpy ( iob_put ( iobuf, len ), rx->data, len );
903                         iob_unput ( iobuf, 4 /* strip CRC */ );
904
905                         /* Hand off to network stack */
906                         netdev_rx ( netdev, iobuf );
907
908                 } else {
909
910                         DBGC ( rtl, "REALTEK %p RX offset %x+%zx error %04x\n",
911                                rtl, rtl->rx_offset, len,
912                                le16_to_cpu ( rx->status ) );
913                         netdev_rx_err ( netdev, NULL, -EIO );
914                 }
915
916                 /* Update buffer offset */
917                 rtl->rx_offset = ( rtl->rx_offset + sizeof ( *rx ) + len );
918                 rtl->rx_offset = ( ( rtl->rx_offset + 3 ) & ~3 );
919                 rtl->rx_offset = ( rtl->rx_offset % RTL_RXBUF_LEN );
920                 writew ( ( rtl->rx_offset - 16 ), rtl->regs + RTL_CAPR );
921
922                 /* Give chip time to react before rechecking RTL_CR */
923                 readw ( rtl->regs + RTL_CAPR );
924         }
925 }
926
927 /**
928  * Poll for received packets
929  *
930  * @v netdev            Network device
931  */
932 static void realtek_poll_rx ( struct net_device *netdev ) {
933         struct realtek_nic *rtl = netdev->priv;
934         struct realtek_descriptor *rx;
935         struct io_buffer *iobuf;
936         unsigned int rx_idx;
937         size_t len;
938
939         /* Poll receive buffer if in legacy mode */
940         if ( rtl->legacy ) {
941                 realtek_legacy_poll_rx ( netdev );
942                 return;
943         }
944
945         /* Check for received packets */
946         while ( rtl->rx.cons != rtl->rx.prod ) {
947
948                 /* Get next receive descriptor */
949                 rx_idx = ( rtl->rx.cons % RTL_NUM_RX_DESC );
950                 rx = &rtl->rx.desc[rx_idx];
951
952                 /* Stop if descriptor is still in use */
953                 if ( rx->flags & cpu_to_le16 ( RTL_DESC_OWN ) )
954                         return;
955
956                 /* Populate I/O buffer */
957                 iobuf = rtl->rx_iobuf[rx_idx];
958                 rtl->rx_iobuf[rx_idx] = NULL;
959                 len = ( le16_to_cpu ( rx->length ) & RTL_DESC_SIZE_MASK );
960                 iob_put ( iobuf, ( len - 4 /* strip CRC */ ) );
961
962                 /* Hand off to network stack */
963                 if ( rx->flags & cpu_to_le16 ( RTL_DESC_RES ) ) {
964                         DBGC ( rtl, "REALTEK %p RX %d error (length %zd, "
965                                "flags %04x)\n", rtl, rx_idx, len,
966                                le16_to_cpu ( rx->flags ) );
967                         netdev_rx_err ( netdev, iobuf, -EIO );
968                 } else {
969                         DBGC2 ( rtl, "REALTEK %p RX %d complete (length "
970                                 "%zd)\n", rtl, rx_idx, len );
971                         netdev_rx ( netdev, iobuf );
972                 }
973                 rtl->rx.cons++;
974         }
975 }
976
977 /**
978  * Poll for completed and received packets
979  *
980  * @v netdev            Network device
981  */
982 static void realtek_poll ( struct net_device *netdev ) {
983         struct realtek_nic *rtl = netdev->priv;
984         uint16_t isr;
985
986         /* Check for and acknowledge interrupts */
987         isr = readw ( rtl->regs + RTL_ISR );
988         if ( ! isr )
989                 return;
990         writew ( isr, rtl->regs + RTL_ISR );
991
992         /* Poll for TX completions, if applicable */
993         if ( isr & ( RTL_IRQ_TER | RTL_IRQ_TOK ) )
994                 realtek_poll_tx ( netdev );
995
996         /* Poll for RX completionsm, if applicable */
997         if ( isr & ( RTL_IRQ_RER | RTL_IRQ_ROK ) )
998                 realtek_poll_rx ( netdev );
999
1000         /* Check link state, if applicable */
1001         if ( isr & RTL_IRQ_PUN_LINKCHG )
1002                 realtek_check_link ( netdev );
1003
1004         /* Refill RX ring */
1005         realtek_refill_rx ( rtl );
1006 }
1007
1008 /**
1009  * Enable or disable interrupts
1010  *
1011  * @v netdev            Network device
1012  * @v enable            Interrupts should be enabled
1013  */
1014 static void realtek_irq ( struct net_device *netdev, int enable ) {
1015         struct realtek_nic *rtl = netdev->priv;
1016         uint16_t imr;
1017
1018         /* Set interrupt mask */
1019         imr = ( enable ? ( RTL_IRQ_PUN_LINKCHG | RTL_IRQ_TER | RTL_IRQ_TOK |
1020                            RTL_IRQ_RER | RTL_IRQ_ROK ) : 0 );
1021         writew ( imr, rtl->regs + RTL_IMR );
1022 }
1023
1024 /** Realtek network device operations */
1025 static struct net_device_operations realtek_operations = {
1026         .open           = realtek_open,
1027         .close          = realtek_close,
1028         .transmit       = realtek_transmit,
1029         .poll           = realtek_poll,
1030         .irq            = realtek_irq,
1031 };
1032
1033 /******************************************************************************
1034  *
1035  * PCI interface
1036  *
1037  ******************************************************************************
1038  */
1039
1040 /**
1041  * Detect device type
1042  *
1043  * @v rtl               Realtek device
1044  */
1045 static void realtek_detect ( struct realtek_nic *rtl ) {
1046         uint16_t rms;
1047         uint16_t check_rms;
1048         uint16_t cpcr;
1049         uint16_t check_cpcr;
1050
1051         /* The RX Packet Maximum Size register is present only on
1052          * 8169.  Try to set to our intended MTU.
1053          */
1054         rms = RTL_RX_MAX_LEN;
1055         writew ( rms, rtl->regs + RTL_RMS );
1056         check_rms = readw ( rtl->regs + RTL_RMS );
1057
1058         /* The C+ Command register is present only on 8169 and 8139C+.
1059          * Try to enable C+ mode and PCI Dual Address Cycle (for
1060          * 64-bit systems), if supported.
1061          *
1062          * Note that enabling DAC seems to cause bizarre behaviour
1063          * (lockups, garbage data on the wire) on some systems, even
1064          * if only 32-bit addresses are used.
1065          */
1066         cpcr = readw ( rtl->regs + RTL_CPCR );
1067         cpcr |= ( RTL_CPCR_MULRW | RTL_CPCR_CPRX | RTL_CPCR_CPTX );
1068         if ( sizeof ( physaddr_t ) > sizeof ( uint32_t ) )
1069                 cpcr |= RTL_CPCR_DAC;
1070         writew ( cpcr, rtl->regs + RTL_CPCR );
1071         check_cpcr = readw ( rtl->regs + RTL_CPCR );
1072
1073         /* Detect device type */
1074         if ( check_rms == rms ) {
1075                 DBGC ( rtl, "REALTEK %p appears to be an RTL8169\n", rtl );
1076                 rtl->have_phy_regs = 1;
1077                 rtl->tppoll = RTL_TPPOLL_8169;
1078         } else {
1079                 if ( ( check_cpcr == cpcr ) && ( cpcr != 0xffff ) ) {
1080                         DBGC ( rtl, "REALTEK %p appears to be an RTL8139C+\n",
1081                                rtl );
1082                         rtl->tppoll = RTL_TPPOLL_8139CP;
1083                 } else {
1084                         DBGC ( rtl, "REALTEK %p appears to be an RTL8139\n",
1085                                rtl );
1086                         rtl->legacy = 1;
1087                 }
1088         }
1089 }
1090
1091 /**
1092  * Probe PCI device
1093  *
1094  * @v pci               PCI device
1095  * @ret rc              Return status code
1096  */
1097 static int realtek_probe ( struct pci_device *pci ) {
1098         struct net_device *netdev;
1099         struct realtek_nic *rtl;
1100         unsigned int i;
1101         int rc;
1102
1103         /* Allocate and initialise net device */
1104         netdev = alloc_etherdev ( sizeof ( *rtl ) );
1105         if ( ! netdev ) {
1106                 rc = -ENOMEM;
1107                 goto err_alloc;
1108         }
1109         netdev_init ( netdev, &realtek_operations );
1110         rtl = netdev->priv;
1111         pci_set_drvdata ( pci, netdev );
1112         netdev->dev = &pci->dev;
1113         memset ( rtl, 0, sizeof ( *rtl ) );
1114         realtek_init_ring ( &rtl->tx, RTL_NUM_TX_DESC, RTL_TNPDS );
1115         realtek_init_ring ( &rtl->rx, RTL_NUM_RX_DESC, RTL_RDSAR );
1116
1117         /* Fix up PCI device */
1118         adjust_pci_device ( pci );
1119
1120         /* Map registers */
1121         rtl->regs = ioremap ( pci->membase, RTL_BAR_SIZE );
1122         if ( ! rtl->regs ) {
1123                 rc = -ENODEV;
1124                 goto err_ioremap;
1125         }
1126
1127         /* Reset the NIC */
1128         if ( ( rc = realtek_reset ( rtl ) ) != 0 )
1129                 goto err_reset;
1130
1131         /* Detect device type */
1132         realtek_detect ( rtl );
1133
1134         /* Initialise EEPROM */
1135         if ( ( rc = realtek_init_eeprom ( netdev ) ) == 0 ) {
1136
1137                 /* Read MAC address from EEPROM */
1138                 if ( ( rc = nvs_read ( &rtl->eeprom.nvs, RTL_EEPROM_MAC,
1139                                        netdev->hw_addr, ETH_ALEN ) ) != 0 ) {
1140                         DBGC ( rtl, "REALTEK %p could not read MAC address: "
1141                                "%s\n", rtl, strerror ( rc ) );
1142                         goto err_nvs_read;
1143                 }
1144
1145         } else {
1146
1147                 /* EEPROM not present.  Fall back to reading the
1148                  * current ID register value, which will hopefully
1149                  * have been programmed by the platform firmware.
1150                  */
1151                 for ( i = 0 ; i < ETH_ALEN ; i++ )
1152                         netdev->hw_addr[i] = readb ( rtl->regs + RTL_IDR0 + i );
1153         }
1154
1155         /* Initialise and reset MII interface */
1156         mii_init ( &rtl->mii, &realtek_mii_operations );
1157         if ( ( rc = realtek_phy_reset ( rtl ) ) != 0 )
1158                 goto err_phy_reset;
1159
1160         /* Register network device */
1161         if ( ( rc = register_netdev ( netdev ) ) != 0 )
1162                 goto err_register_netdev;
1163
1164         /* Set initial link state */
1165         realtek_check_link ( netdev );
1166
1167         /* Register non-volatile options, if applicable */
1168         if ( rtl->nvo.nvs ) {
1169                 if ( ( rc = register_nvo ( &rtl->nvo,
1170                                            netdev_settings ( netdev ) ) ) != 0)
1171                         goto err_register_nvo;
1172         }
1173
1174         return 0;
1175
1176  err_register_nvo:
1177         unregister_netdev ( netdev );
1178  err_register_netdev:
1179  err_phy_reset:
1180  err_nvs_read:
1181         realtek_reset ( rtl );
1182  err_reset:
1183         iounmap ( rtl->regs );
1184  err_ioremap:
1185         netdev_nullify ( netdev );
1186         netdev_put ( netdev );
1187  err_alloc:
1188         return rc;
1189 }
1190
1191 /**
1192  * Remove PCI device
1193  *
1194  * @v pci               PCI device
1195  */
1196 static void realtek_remove ( struct pci_device *pci ) {
1197         struct net_device *netdev = pci_get_drvdata ( pci );
1198         struct realtek_nic *rtl = netdev->priv;
1199
1200         /* Unregister non-volatile options, if applicable */
1201         if ( rtl->nvo.nvs )
1202                 unregister_nvo ( &rtl->nvo );
1203
1204         /* Unregister network device */
1205         unregister_netdev ( netdev );
1206
1207         /* Reset card */
1208         realtek_reset ( rtl );
1209
1210         /* Free network device */
1211         iounmap ( rtl->regs );
1212         netdev_nullify ( netdev );
1213         netdev_put ( netdev );
1214 }
1215
1216 /** Realtek PCI device IDs */
1217 static struct pci_device_id realtek_nics[] = {
1218         PCI_ROM ( 0x0001, 0x8168, "clone8169",  "Cloned 8169", 0 ),
1219         PCI_ROM ( 0x018a, 0x0106, "fpc0106tx",  "LevelOne FPC-0106TX", 0 ),
1220         PCI_ROM ( 0x021b, 0x8139, "hne300",     "Compaq HNE-300", 0 ),
1221         PCI_ROM ( 0x02ac, 0x1012, "s1012",      "SpeedStream 1012", 0 ),
1222         PCI_ROM ( 0x0357, 0x000a, "ttpmon",     "TTTech TTP-Monitoring", 0 ),
1223         PCI_ROM ( 0x10ec, 0x8129, "rtl8129",    "RTL-8129", 0 ),
1224         PCI_ROM ( 0x10ec, 0x8136, "rtl8136",    "RTL8101E/RTL8102E", 0 ),
1225         PCI_ROM ( 0x10ec, 0x8138, "rtl8138",    "RT8139 (B/C)", 0 ),
1226         PCI_ROM ( 0x10ec, 0x8139, "rtl8139",    "RTL-8139/8139C/8139C+", 0 ),
1227         PCI_ROM ( 0x10ec, 0x8167, "rtl8167",    "RTL-8110SC/8169SC", 0 ),
1228         PCI_ROM ( 0x10ec, 0x8168, "rtl8168",    "RTL8111/8168B", 0 ),
1229         PCI_ROM ( 0x10ec, 0x8169, "rtl8169",    "RTL-8169", 0 ),
1230         PCI_ROM ( 0x1113, 0x1211, "smc1211",    "SMC2-1211TX", 0 ),
1231         PCI_ROM ( 0x1186, 0x1300, "dfe538",     "DFE530TX+/DFE538TX", 0 ),
1232         PCI_ROM ( 0x1186, 0x1340, "dfe690",     "DFE-690TXD", 0 ),
1233         PCI_ROM ( 0x1186, 0x4300, "dge528t",    "DGE-528T", 0 ),
1234         PCI_ROM ( 0x11db, 0x1234, "sega8139",   "Sega Enterprises 8139", 0 ),
1235         PCI_ROM ( 0x1259, 0xa117, "allied8139", "Allied Telesyn 8139", 0 ),
1236         PCI_ROM ( 0x1259, 0xa11e, "allied81xx", "Allied Telesyn 81xx", 0 ),
1237         PCI_ROM ( 0x1259, 0xc107, "allied8169", "Allied Telesyn 8169", 0 ),
1238         PCI_ROM ( 0x126c, 0x1211, "northen8139","Northern Telecom 8139", 0 ),
1239         PCI_ROM ( 0x13d1, 0xab06, "fe2000vx",   "Abocom FE2000VX", 0 ),
1240         PCI_ROM ( 0x1432, 0x9130, "edi8139",    "Edimax 8139", 0 ),
1241         PCI_ROM ( 0x14ea, 0xab06, "fnw3603tx",  "Planex FNW-3603-TX", 0 ),
1242         PCI_ROM ( 0x14ea, 0xab07, "fnw3800tx",  "Planex FNW-3800-TX", 0 ),
1243         PCI_ROM ( 0x1500, 0x1360, "delta8139",  "Delta Electronics 8139", 0 ),
1244         PCI_ROM ( 0x16ec, 0x0116, "usr997902",  "USR997902", 0 ),
1245         PCI_ROM ( 0x1737, 0x1032, "linksys8169","Linksys 8169", 0 ),
1246         PCI_ROM ( 0x1743, 0x8139, "rolf100",    "Peppercorn ROL/F-100", 0 ),
1247         PCI_ROM ( 0x4033, 0x1360, "addron8139", "Addtron 8139", 0 ),
1248         PCI_ROM ( 0xffff, 0x8139, "clonse8139", "Cloned 8139", 0 ),
1249 };
1250
1251 /** Realtek PCI driver */
1252 struct pci_driver realtek_driver __pci_driver = {
1253         .ids = realtek_nics,
1254         .id_count = ( sizeof ( realtek_nics ) / sizeof ( realtek_nics[0] ) ),
1255         .probe = realtek_probe,
1256         .remove = realtek_remove,
1257 };