Skip to content

Commit 2a0154d

Browse files
committedApr 18, 2012
[realtek] Replace driver for Realtek Gigabit NICs
Tested-by: Thomas Miletich <thomas.miletich@gmail.com> Debugged-by: Thomas Miletich <thomas.miletich@gmail.com> Tested-by: Robin Smidsrød <robin@smidsrod.no> Signed-off-by: Michael Brown <mcb30@ipxe.org>
1 parent 9b2aabe commit 2a0154d

File tree

5 files changed

+985
-2718
lines changed

5 files changed

+985
-2718
lines changed
 

‎src/drivers/net/r8169.c

Lines changed: 0 additions & 2232 deletions
This file was deleted.

‎src/drivers/net/r8169.h

Lines changed: 0 additions & 486 deletions
This file was deleted.

‎src/drivers/net/realtek.c

Lines changed: 779 additions & 0 deletions
Large diffs are not rendered by default.

‎src/drivers/net/realtek.h

Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
#ifndef _REALTEK_H
2+
#define _REALTEK_H
3+
4+
/** @file
5+
*
6+
* Realtek 10/100/1000 network card driver
7+
*
8+
*/
9+
10+
FILE_LICENCE ( GPL2_OR_LATER );
11+
12+
#include <ipxe/spi.h>
13+
#include <ipxe/spi_bit.h>
14+
#include <ipxe/nvo.h>
15+
#include <ipxe/if_ether.h>
16+
17+
/** PCI memory BAR size */
18+
#define RTL_BAR_SIZE 0x100
19+
20+
/** A packet descriptor */
21+
struct realtek_descriptor {
22+
/** Buffer size */
23+
uint16_t length;
24+
/** Flags */
25+
uint16_t flags;
26+
/** Reserved */
27+
uint32_t reserved;
28+
/** Buffer address */
29+
uint64_t address;
30+
} __attribute__ (( packed ));
31+
32+
/** Descriptor buffer size mask */
33+
#define RTL_DESC_SIZE_MASK 0x3fff
34+
35+
/** Packet descriptor flags */
36+
enum realtek_descriptor_flags {
37+
/** Descriptor is owned by NIC */
38+
RTL_DESC_OWN = 0x8000,
39+
/** End of descriptor ring */
40+
RTL_DESC_EOR = 0x4000,
41+
/** First segment descriptor */
42+
RTL_DESC_FS = 0x2000,
43+
/** Last segment descriptor */
44+
RTL_DESC_LS = 0x1000,
45+
/** Receive error summary */
46+
RTL_DESC_RES = 0x0020,
47+
};
48+
49+
/** Descriptor ring alignment */
50+
#define RTL_RING_ALIGN 256
51+
52+
/** ID Register 0 (6 bytes) */
53+
#define RTL_IDR0 0x00
54+
55+
/** Multicast Register 0 (dword) */
56+
#define RTL_MAR0 0x08
57+
58+
/** Multicast Register 4 (dword) */
59+
#define RTL_MAR4 0x0c
60+
61+
/** Transmit Normal Priority Descriptors (qword) */
62+
#define RTL_TNPDS 0x20
63+
64+
/** Number of transmit descriptors */
65+
#define RTL_NUM_TX_DESC 4
66+
67+
/** Command Register (byte) */
68+
#define RTL_CR 0x37
69+
#define RTL_CR_RST 0x10 /**< Reset */
70+
#define RTL_CR_RE 0x08 /**< Receiver Enable */
71+
#define RTL_CR_TE 0x04 /**< Transmit Enable */
72+
73+
/** Maximum time to wait for a reset, in milliseconds */
74+
#define RTL_RESET_MAX_WAIT_MS 100
75+
76+
/** Transmit Priority Polling Register (byte) */
77+
#define RTL_TPPOLL 0x38
78+
#define RTL_TPPOLL_NPQ 0x40 /**< Normal Priority Queue Polling */
79+
80+
/** Interrupt Mask Register (word) */
81+
#define RTL_IMR 0x3c
82+
#define RTL_IRQ_PUN_LINKCHG 0x20 /**< Packet underrun / link change */
83+
#define RTL_IRQ_TER 0x08 /**< Transmit error */
84+
#define RTL_IRQ_TOK 0x04 /**< Transmit OK */
85+
#define RTL_IRQ_RER 0x02 /**< Receive error */
86+
#define RTL_IRQ_ROK 0x01 /**< Receive OK */
87+
88+
/** Interrupt Status Register (word) */
89+
#define RTL_ISR 0x3e
90+
91+
/** Receive (Rx) Configuration Register (dword) */
92+
#define RTL_RCR 0x44
93+
#define RTL_RCR_9356SEL 0x40 /**< EEPROM is a 93C56 */
94+
#define RTL_RCR_AB 0x08 /**< Accept broadcast packets */
95+
#define RTL_RCR_AM 0x04 /**< Accept multicast packets */
96+
#define RTL_RCR_APM 0x02 /**< Accept physical match packets */
97+
#define RTL_RCR_AAP 0x01 /**< Accept all packets */
98+
99+
/** 93C46 (93C56) Command Register (byte) */
100+
#define RTL_9346CR 0x50
101+
#define RTL_9346CR_EEM1 0x80 /**< Mode select bit 1 */
102+
#define RTL_9346CR_EEM0 0x40 /**< Mode select bit 0 */
103+
#define RTL_9346CR_EECS 0x08 /**< Chip select */
104+
#define RTL_9346CR_EESK 0x04 /**< Clock */
105+
#define RTL_9346CR_EEDI 0x02 /**< Data in */
106+
#define RTL_9346CR_EEDO 0x01 /**< Data out */
107+
108+
/** Word offset of MAC address within EEPROM */
109+
#define RTL_EEPROM_MAC ( 0x0e / 2 )
110+
111+
/** Word offset of VPD / non-volatile options within EEPROM */
112+
#define RTL_EEPROM_VPD ( 0x40 / 2 )
113+
114+
/** Length of VPD / non-volatile options within EEPROM */
115+
#define RTL_EEPROM_VPD_LEN 0x40
116+
117+
/** Configuration Register 1 (byte) */
118+
#define RTL_CONFIG1 0x52
119+
#define RTL_CONFIG1_VPD 0x02 /**< Vital Product Data enabled */
120+
121+
/** PHY Access Register (dword) */
122+
#define RTL_PHYAR 0x60
123+
#define RTL_PHYAR_FLAG 0x80000000UL /**< Read/write flag */
124+
125+
/** Construct PHY Access Register value */
126+
#define RTL_PHYAR_VALUE( flag, reg, data ) ( (flag) | ( (reg) << 16 ) | (data) )
127+
128+
/** Extract PHY Access Register data */
129+
#define RTL_PHYAR_DATA( value ) ( (value) & 0xffff )
130+
131+
/** Maximum time to wait for PHY access, in microseconds */
132+
#define RTL_MII_MAX_WAIT_US 500
133+
134+
/** PHY (GMII, MII, or TBI) Status Register (byte) */
135+
#define RTL_PHYSTATUS 0x6c
136+
#define RTL_PHYSTATUS_LINKSTS 0x02 /**< Link ok */
137+
138+
/** RX Packet Maximum Size Register (word) */
139+
#define RTL_RMS 0xda
140+
141+
/** C+ Command Register (word) */
142+
#define RTL_CPCR 0xe0
143+
#define RTL_CPCR_DAC 0x10 /**< PCI Dual Address Cycle Enable */
144+
#define RTL_CPCR_MULRW 0x08 /**< PCI Multiple Read/Write Enable */
145+
146+
/** Receive Descriptor Start Address Register (qword) */
147+
#define RTL_RDSAR 0xe4
148+
149+
/** Number of receive descriptors */
150+
#define RTL_NUM_RX_DESC 4
151+
152+
/** Receive buffer length */
153+
#define RTL_RX_MAX_LEN ( ETH_FRAME_LEN + 4 /* VLAN */ + 4 /* CRC */ )
154+
155+
/** A Realtek descriptor ring */
156+
struct realtek_ring {
157+
/** Descriptors */
158+
struct realtek_descriptor *desc;
159+
/** Producer index */
160+
unsigned int prod;
161+
/** Consumer index */
162+
unsigned int cons;
163+
164+
/** Descriptor start address register */
165+
unsigned int reg;
166+
/** Length (in bytes) */
167+
size_t len;
168+
};
169+
170+
/**
171+
* Initialise descriptor ring
172+
*
173+
* @v ring Descriptor ring
174+
* @v count Number of descriptors
175+
* @v reg Descriptor start address register
176+
*/
177+
static inline __attribute__ (( always_inline)) void
178+
realtek_init_ring ( struct realtek_ring *ring, unsigned int count,
179+
unsigned int reg ) {
180+
ring->len = ( count * sizeof ( ring->desc[0] ) );
181+
ring->reg = reg;
182+
}
183+
184+
/** A Realtek network card */
185+
struct realtek_nic {
186+
/** Registers */
187+
void *regs;
188+
/** SPI bit-bashing interface */
189+
struct spi_bit_basher spibit;
190+
/** EEPROM */
191+
struct spi_device eeprom;
192+
/** Non-volatile options */
193+
struct nvo_block nvo;
194+
/** MII interface */
195+
struct mii_interface mii;
196+
197+
/** Transmit descriptor ring */
198+
struct realtek_ring tx;
199+
/** Receive descriptor ring */
200+
struct realtek_ring rx;
201+
/** Receive I/O buffers */
202+
struct io_buffer *rx_iobuf[RTL_NUM_RX_DESC];
203+
};
204+
205+
#endif /* _REALTEK_H */

‎src/include/ipxe/errfile.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
142142
#define ERRFILE_ath ( ERRFILE_DRIVER | 0x00600000 )
143143
#define ERRFILE_vmxnet3 ( ERRFILE_DRIVER | 0x00610000 )
144144
#define ERRFILE_mii ( ERRFILE_DRIVER | 0x00620000 )
145+
#define ERRFILE_realtek ( ERRFILE_DRIVER | 0x00630000 )
145146

146147
#define ERRFILE_scsi ( ERRFILE_DRIVER | 0x00700000 )
147148
#define ERRFILE_arbel ( ERRFILE_DRIVER | 0x00710000 )

0 commit comments

Comments
 (0)
Please sign in to comment.