source: mainline/uspace/drv/nic/rtl8169/defs.h@ cbfece7

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since cbfece7 was cbfece7, checked in by Agnieszka Tabaka <nufcia@…>, 11 years ago
  • Merged mainline changes
  • Refactored rtl8169 driver to work with recent driver framework changes
  • Fixed speed selection in rtl8169 (disables autonegotiation first)
  • Added support for restarting autonegotiation
  • Added new switch to 'nic' utility which restarts autonegotiation
  • Property mode set to 100644
File size: 13.3 KB
Line 
1/*
2 * Copyright (c) 2014 Agnieszka Tabaka
3 * Copyright (c) 2011 Jiri Michalec
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * - The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30/** @file rtl8169_defs.h
31 *
32 * Registers, bit positions and masks definition
33 * of the RTL8169 network family cards
34 */
35
36#ifndef RTL8169_DEFS_H_
37#define RTL8169_DEFS_H_
38
39#include <sys/types.h>
40#include <ddi.h>
41
42#define PCI_VID_REALTEK 0x10ec
43#define PCI_VID_DLINK 0x1186
44
45/** Size of RTL8169 registers address space */
46#define RTL8169_IO_SIZE 256
47
48#define RTL8169_FRAME_MAX_LENGTH 1518
49
50/** Registers of RTL8169 family card offsets from the memory address base */
51enum rtl8169_registers {
52 IDR0 = 0x00, /**< First MAC address bit, 6 1b registres sequence */
53 MAC0 = IDR0, /**< Alias for IDR0 */
54 /* 0x06 - 0x07 reserved */
55 MAR0 = 0x08, /**< Multicast mask registers 8 1b registers sequence */
56 DTCCR = 0x10, /**< Dump Tally Counter Command Register */
57 TNPDS = 0x20, /**< Transmit Normal Priority Descriptors */
58 THPDS = 0x28, /**< Transmit High Priority Descriptors */
59 FLASH = 0x30, /**< Flash memory read/write register */
60 ERBCR = 0x34, /**< Early Receive Byte Count Register */
61 ERSR = 0x36, /**< Early Rx Status Register */
62 CR = 0x37, /**< Command register, 1b */
63 TPPOLL = 0x38, /**< Transmit Priority Polling Register */
64 CBA = 0x3a, /**< Current buffer address, 2b */
65 IMR = 0x3c, /**< Interrupt mask register, 2b */
66 ISR = 0x3e, /**< Interrupt status register, 2b */
67 TCR = 0x40, /**< Transmit (Tx) configuration register, 4b */
68 RCR = 0x44, /**< Receive (Rx) configuration register, 4b */
69 TCTR = 0x48, /**< Timer count register */
70 MPC = 0x4c, /**< Missed packet count */
71 CR9346 = 0x50, /**< 93C46 command register (locking of registers) */
72 CONFIG0 = 0x51, /**< Configuration register 0, 1b */
73 CONFIG1 = 0x52, /**< Configuration register 1, 1b */
74 CONFIG2 = 0x53, /**< Configuration register 2, 1b */
75 CONFIG3 = 0x54, /**< Configuration register 3, 1b */
76 CONFIG4 = 0x55, /**< Configuration register 4, 1b */
77 CONFIG5 = 0x56, /**< Configuration register 5, 1b */
78 /* 0x57 reserved */
79 TIMINT = 0x58, /**< Timer interrupt register, 4b */
80 MULINT = 0x58, /**< Multiple interrupt select, 4b */
81 /* 0x5e-0x5f reserved */
82 PHYAR = 0x60, /**< PHY Access Register, 4b */
83 TBICSR0 = 0x64, /**< TBI Control and Status Register, 4b */
84 TBI_ANAR = 0x58, /**< TBI Auto-Negotiation Advertisement Register, 2b */
85 TBI_LPAR = 0x6a, /**< TBI Auto-Negotiation Link Partner Ability Register, 2b */
86 PHYSTATUS = 0x6c, /**< PHY Status Register */
87 /* 0x6d-0x83 reserved */
88 WAKEUP0 = 0x84, /**< Power Management Wakeup frame0, 8b */
89 WAKEUP1 = 0x8c, /**< Power Management Wakeup frame1, 8b */
90 WAKEUP2LD = 0x94, /**< Power Management Wakeup frame2 low dword, 8b */
91 WAKEUP2HD = 0x9c, /**< Power Management Wakeup frame2 high dword, 8b */
92 WAKEUP3LD = 0xa4, /**< Power Management Wakeup frame3 low dword, 8b */
93 WAKEUP3HD = 0xac, /**< Power Management Wakeup frame3 high dword, 8b */
94 WAKEUP4LD = 0xb4, /**< Power Management Wakeup frame4 low dword, 8b */
95 WAKEUP4HD = 0xbc, /**< Power Management Wakeup frame4 high dword, 8b */
96 CRC0 = 0xc4, /**< 16-bit CRC of wakeup frame 0, 2b */
97 CRC1 = 0xc6, /**< 16-bit CRC of wakeup frame 1, 2b */
98 CRC2 = 0xc8, /**< 16-bit CRC of wakeup frame 2, 2b */
99 CRC3 = 0xca, /**< 16-bit CRC of wakeup frame 3, 2b */
100 CRC4 = 0xcc, /**< 16-bit CRC of wakeup frame 4, 2b */
101 /* 0xce - 0xd9 reserved */
102 RMS = 0xda, /**< Rx packet Maximum Size, 2b */
103 /* 0xdc - 0xdf reserved */
104 CCR = 0xe0, /**< C+ Command Register */
105 /* 0xe2 - 0xe3 reserved */
106 RDSAR = 0xe4, /**< Receive Descriptor Start Address Register, 8b */
107 ETTHR = 0xec, /**< Early Transmit Threshold Register, 1b */
108 /* 0xed - 0xef reserved */
109 FER = 0xf0, /**< Function Event Register, 4b */
110 FEMR = 0xf4, /**< Function Event Mask Register, 4b */
111 FPSR = 0xf8, /**< Function Preset State Register, 4b */
112 FFER = 0xfc, /**< Function Force Event Register, 4b */
113};
114
115enum rtl8169_mii_registers {
116 MII_BMCR = 0x00,
117 MII_BMSR = 0x01,
118 MII_ANAR = 0x04,
119};
120
121/** Command register bits */
122enum rtl8169_cr {
123 CR_TE = (1 << 2), /**< Transmitter enable bit */
124 CR_RE = (1 << 3), /**< Receiver enable bit */
125 CR_RST = (1 << 4), /**< Reset - set to 1 to force software reset */
126};
127
128/** Config1 register bits */
129enum rtl8169_config1 {
130 CONFIG1_LEDS_SHIFT = 6, /**< Shift of CONFIG1_LEDS bits */
131 CONFIG1_LEDS_SIZE = 2, /**< Size of CONFIG1_LEDS bits */
132 CONFIG1_DVRLOAD = (1 << 5), /**< Driver load */
133 CONFIG1_LWACT = (1 << 4), /**< LWAKE active mode */
134 CONFIG1_MEMMAP = (1 << 3), /**< Memory mapping */
135 CONFIG1_IOMAP = (1 << 2), /**< I/O space mapping */
136 CONFIG1_VPD = (1 << 1), /**< Set to enable Vital Product Data */
137 CONFIG1_PMEn = (1 << 0) /**< Power management enabled */
138};
139
140enum rtl8169_config2 {
141 CONFIG2_AUXSTATUS = (1 << 4), /**< Auxiliary Power Present Status */
142 CONFIG2_PCIBUSWIDTH = (1 << 3), /**< PCI Bus Width */
143 CONFIG2_PCICLKF_SHIFT = 0,
144 CONFIG2_PCICLKF_SIZE = 2
145};
146
147enum rtl8169_config3 {
148 CONFIG3_GNT_SELECT = (1 << 7), /**< Gnt select */
149 CONFIG3_PARM_EN = (1 << 6), /**< Parameter enabled (100MBit mode) */
150 CONFIG3_MAGIC = (1 << 5), /**< WoL Magic frame enable */
151 CONFIG3_LINK_UP = (1 << 4), /**< Wakeup if link is reestablished */
152 CONFIG3_CLKRUN_EN = (1 << 2), /**< CLKRUN enabled */ /* TODO: check what does it mean */
153 CONFIG3_FBTBEN = (1 << 0), /**< Fast back to back enabled */
154};
155
156enum rtl8169_config4 {
157 CONFIG4_RxFIFOAutoClr = (1 << 7), /**< Automatic RxFIFO owerflow clear */
158 CONFIG4_AnaOff = (1 << 6), /**< Analog poweroff */
159 CONFIG4_LongWF = (1 << 5), /**< Long wakeup frame */
160 CONFIG4_LWPME = (1 << 4), /**< LWAKE and PMEB assertion */
161 CONFIG4_LWPTN = (1 << 2), /**< LWake pattern */
162 CONFIG4_PBWakeup = (1 << 0), /**< Preboot wakeup */
163};
164
165enum rtl8169_config5 {
166 CONFIG5_BROADCAST_WAKEUP = (1 << 6), /**< Broadcast wakeup frame enable */
167 CONFIG5_MULTICAST_WAKEUP = (1 << 5), /**< Multicast wakeup frame enable */
168 CONFIG5_UNICAST_WAKEUP = (1 << 4), /**< Unicast wakeup frame enable */
169 /* Bits 3-2 reserved */
170 CONFIG5_LAN_WAKE = (1 << 1), /**< LANWake signal enabled */
171 CONFIG5_PME_STATUS = (1 << 0), /**< PMEn change: 0 = SW, 1 = SW+PCI */
172};
173
174/** Interrupt_masks
175 *
176 * The masks are the same for both IMR and ISR
177 */
178enum rtl8169_interrupts {
179 INT_SERR = (1 << 15), /**< System error interrupt */
180 INT_TIME_OUT = (1 << 14), /**< Time out interrupt */
181 /* Bits 9 - 13 reserved */
182 INT_SW = (1 << 8), /**< Software Interrupt */
183 INT_TDU = (1 << 7), /**< Tx Descriptor Unvailable */
184 INT_FIFOOVW = (1 << 6), /**< Receiver FIFO overflow interrupt */
185 INT_PUN = (1 << 5), /**< Packet Underrun/Link Change Interrupt */
186 INT_RXOVW = (1 << 4), /**< Receiver buffer overflow */
187 INT_TER = (1 << 3), /**< Transmit error interrupt */
188 INT_TOK = (1 << 2), /**< Transmit OK interrupt */
189 INT_RER = (1 << 1), /**< Receive error interrupt */
190 INT_ROK = (1 << 0), /**< Receive OK interrupt */
191 INT_KNOWN = (INT_SERR | INT_TIME_OUT | INT_SW | INT_TDU \
192 | INT_FIFOOVW | INT_PUN | INT_RXOVW | INT_TER \
193 | INT_TOK| INT_RER | INT_ROK),
194};
195
196/** Transmit status descriptor registers bits */
197enum rtl8169_tsd {
198 TSD_CRS = (1 << 31), /**< Carrier Sense Lost */
199 TSD_TABT = (1 << 30), /**< Transmit Abort */
200 TSD_OWC = (1 << 29), /**< Out of Window Collision */
201 TSD_CDH = (1 << 28), /**< CD Heart Beat */
202 TSD_NCC_SHIFT = 24, /**< Collision Count - bit shift */
203 TSD_NCC_SIZE = 4, /**< Collision Count - bit size */
204 TSD_NCC_MASK = (1 << 4)-1, /**< Collision Count - bit size */
205 TSD_ERTXTH_SHIFT = 16, /**< Early Tx Threshold - bit shift */
206 TSD_ERTXTH_SIZE = 6, /**< Early Tx Treshold - bit size */
207 TSD_TOK = (1 << 15), /**< Transmit OK */
208 TSD_TUN = (1 << 14), /**< Transmit FIFO Underrun */
209 TSD_OWN = (1 << 13), /**< OWN */
210 TSD_SIZE_SHIFT = 0, /**< Size - bit shift */
211 TSD_SIZE_SIZE = 13, /**< Size - bit size */
212 TSD_SIZE_MASK = 0x1fff, /**< Size - bit mask */
213};
214
215/** Receiver control register values */
216enum rtl8169_rcr {
217 RCR_MulERINT = 1 << 24, /**< Multiple early interrupt select */
218 /* Bits 23-17 reserved */
219 RCR_RER8 = 1 << 16,
220 RCR_RXFTH_SHIFT = 13, /**< Rx FIFO treshold part shitf */
221 RCR_RXFTH_SIZE = 3, /**< Rx FIFO treshold part size */
222 /* Bits 12-11 reserved */
223 RCR_MXDMA_SHIFT = 8, /**< Max DMA Burst Size part shift */
224 RCR_MXDMA_SIZE = 3, /**< Max DMA Burst Size part size */
225 /* Bit 7 reserved */
226 RCR_ACCEPT_ERROR = 1 << 5, /**< Accept error frame */
227 RCR_ACCEPT_RUNT = 1 << 4, /**< Accept Runt (8-64 bytes) frames */
228 RCR_ACCEPT_BROADCAST = 1 << 3, /**< Accept broadcast */
229 RCR_ACCEPT_MULTICAST = 1 << 2, /**< Accept multicast */
230 RCR_ACCEPT_PHYS_MATCH = 1 << 1, /**< Accept device MAC address match */
231 RCR_ACCEPT_ALL_PHYS = 1 << 0, /**< Accept all frames with phys. desticnation */
232 RCR_ACCEPT_MASK = (1 << 6) - 1 /**< Mask of accept part */
233};
234
235enum rtl8169_cr9346 {
236 CR9346EEM1_SHIFT = 6, /**< RTL8169 operating mode shift */
237 CR9346EEM1_SIZE = 2, /**< RTL8169 operating mode mask */
238 /* Bits 5-4 reserved */
239 EECS = (1 << 3), /**< EECS pin of 93C46 */
240 EESK = (1 << 2), /**< EESK pin of 93C46 */
241 EEDI = (1 << 1), /**< EEDI pin of 93C46 */
242 EEDO = (1 << 0), /**< EEDO pin of 93C46 */
243};
244
245/** Auto-negotiation advertisement register */
246enum rtl8169_anar {
247 ANAR_NEXT_PAGE = (1 << 15), /**< Next page bit, 0 - primary capability */
248 ANAR_ACK = (1 << 14), /**< Capability reception acknowledge */
249 ANAR_REMOTE_FAULT = (1 << 13), /**< Remote fault detection capability */
250 ANAR_PAUSE = (1 << 10), /**< Symetric pause frame capability */
251 ANAR_100T4 = (1 << 9), /**< T4, not supported by the device */
252 ANAR_100TX_FD = (1 << 8), /**< 100BASE_TX full duplex */
253 ANAR_100TX_HD = (1 << 7), /**< 100BASE_TX half duplex */
254 ANAR_10_FD = (1 << 6), /**< 10BASE_T full duplex */
255 ANAR_10_HD = (1 << 5), /**< 10BASE_T half duplex */
256 ANAR_SELECTOR = 0x1, /**< Selector */
257};
258
259enum rtl8169_phystatus {
260 PHYSTATUS_TBIEN = (1 << 7), /**< TBI enabled */
261 PHYSTATUS_TXFLOW = (1 << 6), /**< TX flow control enabled */
262 PHYSTATUS_RXFLOW = (1 << 5), /**< RX flow control enabled */
263 PHYSTATUS_1000M = (1 << 4), /**< Link speed is 1000Mbit/s */
264 PHYSTATUS_100M = (1 << 3), /**< Link speed is 100Mbit/s */
265 PHYSTATUS_10M = (1 << 2), /**< Link speed is 10Mbit/s */
266 PHYSTATUS_LINK = (1 << 1), /**< Link up */
267 PHYSTATUS_FDX = (1 << 0), /**< Link is full duplex */
268};
269
270enum rtl8169_tppoll {
271 TPPOLL_HPQ = (1 << 7), /**< Start transmit on high priority queue */
272 TPPOLL_NPQ = (1 << 6), /**< Start transmit on normal queue */
273 /* Bits 5-1 reserved */
274 TPPOLL_FSWINT = (1 << 0), /** < Generate software interrupt */
275};
276
277enum rtl8169_phyar {
278 PHYAR_RW_SHIFT = 31, /**< Read (0) or write (1) command */
279 PHYAR_RW_READ = (0 << PHYAR_RW_SHIFT),
280 PHYAR_RW_WRITE = (1 << PHYAR_RW_SHIFT),
281 PHYAR_ADDR_SHIFT = 15,
282 PHYAR_ADDR_MASK = 0x1f,
283 PHYAR_DATA_MASK = 0xffff
284};
285
286enum rtl8169_bmcr {
287 BMCR_RESET = (1 << 15), /**< Software reset */
288 BMCR_SPD_100 = (1 << 13), /**< 100 MBit mode set */
289 BMCR_AN_ENABLE = (1 << 12), /**< Autonegotion enable */
290 BMCR_AN_RESTART = (1 << 9), /**< Restart autonegotion */
291 BMCR_DUPLEX = (1 << 8), /**< Duplex mode: 1=full duplex */
292 BMCR_SPD_1000 = (1 << 6), /**< 1000 Mbit mode set */
293};
294
295enum rtl8169_descr_control {
296 CONTROL_OWN = (1 << 31), /**< Descriptor ownership */
297 CONTROL_EOR = (1 << 30), /**< End Of Ring marker */
298 CONTROL_FS = (1 << 29), /**< First Segment marker */
299 CONTROL_LS = (1 << 28), /**< Last Segment marker */
300 CONTROL_LGSEN = (1 << 27), /**< Large send enable */
301 CONTROL_MSS_SHIFT = 16,
302 CONTROL_MSS_MASK = 10,
303 CONTROL_FRAMELEN_MASK = 0xffff
304};
305
306enum rtl8169_descr_txstatus {
307 TXSTATUS_UNDERRUN = (1 << 25),
308 TXSTATUS_TXERRSUM = (1 << 23),
309 TXSTATUS_OWINCOL = (1 << 22),
310 TXSTATUS_LINKFAIL = (1 << 21),
311 TXSTATUS_EXCESSCOL = (1 << 20)
312};
313
314enum rtl8169_descr_rxstatus {
315 RXSTATUS_MAR = (1 << 27),
316 RXSTATUS_PAM = (1 << 26),
317 RXSTATUS_BAR = (1 << 25),
318 RXSTATUS_BOVF = (1 << 24),
319 RXSTATUS_FOVF = (1 << 23),
320 RXSTATUS_RWT = (1 << 22),
321 RXSTATUS_RES = (1 << 21),
322 RXSTATUS_RUNT = (1 << 20),
323 RXSTATUS_CRC = (1 << 19),
324 RXSTATUS_PID1 = (1 << 18),
325 RXSTATUS_PID0 = (1 << 17),
326 RXSTATUS_IPF = (1 << 16),
327 RXSTATUS_UDPF = (1 << 15),
328 RXSTATUS_TCPF = (1 << 14)
329};
330
331typedef struct rtl8169_descr {
332 uint32_t control;
333 uint32_t vlan;
334 uint32_t buf_low;
335 uint32_t buf_high;
336} rtl8169_descr_t;
337
338#endif
Note: See TracBrowser for help on using the repository browser.