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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since be971233 was be971233, checked in by Agnieszka Tabaka <nufcia@…>, 11 years ago

Initial receive support. Also added TX interrupt handling (still buggy as it
losts some of interrupts, though).

  • Property mode set to 100644
File size: 12.4 KB
RevLine 
[fef725d]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/** Size of RTL8169 registers address space */
43#define RTL8169_IO_SIZE 256
44
[59b3095]45#define RTL8169_FRAME_MAX_LENGTH 1518
46
[fef725d]47/** Registers of RTL8169 family card offsets from the memory address base */
48enum rtl8169_registers {
49 IDR0 = 0x00, /**< First MAC address bit, 6 1b registres sequence */
50 MAC0 = IDR0, /**< Alias for IDR0 */
51 /* 0x06 - 0x07 reserved */
52 MAR0 = 0x08, /**< Multicast mask registers 8 1b registers sequence */
53 DTCCR = 0x10, /**< Dump Tally Counter Command Register */
54 TNPDS = 0x20, /**< Transmit Normal Priority Descriptors */
55 THPDS = 0x28, /**< Transmit High Priority Descriptors */
56 FLASH = 0x30, /**< Flash memory read/write register */
57 ERBCR = 0x34, /**< Early Receive Byte Count Register */
58 ERSR = 0x36, /**< Early Rx Status Register */
59 CR = 0x37, /**< Command register, 1b */
60 TPPOLL = 0x38, /**< Transmit Priority Polling Register */
61 CBA = 0x3a, /**< Current buffer address, 2b */
62 IMR = 0x3c, /**< Interrupt mask register, 2b */
63 ISR = 0x3e, /**< Interrupt status register, 2b */
64 TCR = 0x40, /**< Transmit (Tx) configuration register, 4b */
65 RCR = 0x44, /**< Receive (Rx) configuration register, 4b */
66 TCTR = 0x48, /**< Timer count register */
67 MPC = 0x4c, /**< Missed packet count */
68 CR9346 = 0x50, /**< 93C46 command register (locking of registers) */
69 CONFIG0 = 0x51, /**< Configuration register 0, 1b */
70 CONFIG1 = 0x52, /**< Configuration register 1, 1b */
71 CONFIG2 = 0x53, /**< Configuration register 2, 1b */
72 CONFIG3 = 0x54, /**< Configuration register 3, 1b */
73 CONFIG4 = 0x55, /**< Configuration register 4, 1b */
74 CONFIG5 = 0x56, /**< Configuration register 5, 1b */
75 /* 0x57 reserved */
76 TIMINT = 0x58, /**< Timer interrupt register, 4b */
77 MULINT = 0x58, /**< Multiple interrupt select, 4b */
78 /* 0x5e-0x5f reserved */
79 PHYAR = 0x60, /**< PHY Access Register, 4b */
80 TBICSR0 = 0x64, /**< TBI Control and Status Register, 4b */
81 TBI_ANAR = 0x58, /**< TBI Auto-Negotiation Advertisement Register, 2b */
82 TBI_LPAR = 0x6a, /**< TBI Auto-Negotiation Link Partner Ability Register, 2b */
83 PHYSTATUS = 0x6c, /**< PHY Status Register */
84 /* 0x6d-0x83 reserved */
85 WAKEUP0 = 0x84, /**< Power Management Wakeup frame0, 8b */
86 WAKEUP1 = 0x8c, /**< Power Management Wakeup frame1, 8b */
87 WAKEUP2LD = 0x94, /**< Power Management Wakeup frame2 low dword, 8b */
88 WAKEUP2HD = 0x9c, /**< Power Management Wakeup frame2 high dword, 8b */
89 WAKEUP3LD = 0xa4, /**< Power Management Wakeup frame3 low dword, 8b */
90 WAKEUP3HD = 0xac, /**< Power Management Wakeup frame3 high dword, 8b */
[90782c36]91 WAKEUP4LD = 0xb4, /**< Power Management Wakeup frame4 low dword, 8b */
92 WAKEUP4HD = 0xbc, /**< Power Management Wakeup frame4 high dword, 8b */
[fef725d]93 CRC0 = 0xc4, /**< 16-bit CRC of wakeup frame 0, 2b */
94 CRC1 = 0xc6, /**< 16-bit CRC of wakeup frame 1, 2b */
95 CRC2 = 0xc8, /**< 16-bit CRC of wakeup frame 2, 2b */
96 CRC3 = 0xca, /**< 16-bit CRC of wakeup frame 3, 2b */
97 CRC4 = 0xcc, /**< 16-bit CRC of wakeup frame 4, 2b */
98 /* 0xce - 0xd9 reserved */
99 RMS = 0xda, /**< Rx packet Maximum Size, 2b */
100 /* 0xdc - 0xdf reserved */
101 CCR = 0xe0, /**< C+ Command Register */
102 /* 0xe2 - 0xe3 reserved */
103 RDSAR = 0xe4, /**< Receive Descriptor Start Address Register, 8b */
104 ETTHR = 0xec, /**< Early Transmit Threshold Register, 1b */
105 /* 0xed - 0xef reserved */
106 FER = 0xf0, /**< Function Event Register, 4b */
107 FEMR = 0xf4, /**< Function Event Mask Register, 4b */
108 FPSR = 0xf8, /**< Function Preset State Register, 4b */
109 FFER = 0xfc, /**< Function Force Event Register, 4b */
110};
111
112/** Command register bits */
113enum rtl8169_cr {
114 CR_TE = (1 << 2), /**< Transmitter enable bit */
115 CR_RE = (1 << 3), /**< Receiver enable bit */
116 CR_RST = (1 << 4), /**< Reset - set to 1 to force software reset */
117};
118
119/** Config1 register bits */
120enum rtl8169_config1 {
121 CONFIG1_LEDS_SHIFT = 6, /**< Shift of CONFIG1_LEDS bits */
122 CONFIG1_LEDS_SIZE = 2, /**< Size of CONFIG1_LEDS bits */
123 CONFIG1_DVRLOAD = (1 << 5), /**< Driver load */
124 CONFIG1_LWACT = (1 << 4), /**< LWAKE active mode */
125 CONFIG1_MEMMAP = (1 << 3), /**< Memory mapping */
126 CONFIG1_IOMAP = (1 << 2), /**< I/O space mapping */
127 CONFIG1_VPD = (1 << 1), /**< Set to enable Vital Product Data */
128 CONFIG1_PMEn = (1 << 0) /**< Power management enabled */
129};
130
131enum rtl8169_config2 {
132 CONFIG2_AUXSTATUS = (1 << 4), /**< Auxiliary Power Present Status */
133 CONFIG2_PCIBUSWIDTH = (1 << 3), /**< PCI Bus Width */
134 CONFIG2_PCICLKF_SHIFT = 0,
135 CONFIG2_PCICLKF_SIZE = 2
[90782c36]136};
[fef725d]137
138enum rtl8169_config3 {
139 CONFIG3_GNT_SELECT = (1 << 7), /**< Gnt select */
140 CONFIG3_PARM_EN = (1 << 6), /**< Parameter enabled (100MBit mode) */
141 CONFIG3_MAGIC = (1 << 5), /**< WoL Magic frame enable */
142 CONFIG3_LINK_UP = (1 << 4), /**< Wakeup if link is reestablished */
143 CONFIG3_CLKRUN_EN = (1 << 2), /**< CLKRUN enabled */ /* TODO: check what does it mean */
144 CONFIG3_FBTBEN = (1 << 0), /**< Fast back to back enabled */
145};
146
147enum rtl8169_config4 {
148 CONFIG4_RxFIFOAutoClr = (1 << 7), /**< Automatic RxFIFO owerflow clear */
149 CONFIG4_AnaOff = (1 << 6), /**< Analog poweroff */
150 CONFIG4_LongWF = (1 << 5), /**< Long wakeup frame */
151 CONFIG4_LWPME = (1 << 4), /**< LWAKE and PMEB assertion */
152 CONFIG4_LWPTN = (1 << 2), /**< LWake pattern */
153 CONFIG4_PBWakeup = (1 << 0), /**< Preboot wakeup */
154};
155
156enum rtl8169_config5 {
157 CONFIG5_BROADCAST_WAKEUP = (1 << 6), /**< Broadcast wakeup frame enable */
158 CONFIG5_MULTICAST_WAKEUP = (1 << 5), /**< Multicast wakeup frame enable */
159 CONFIG5_UNICAST_WAKEUP = (1 << 4), /**< Unicast wakeup frame enable */
160 /* Bits 3-2 reserved */
161 CONFIG5_LAN_WAKE = (1 << 1), /**< LANWake signal enabled */
162 CONFIG5_PME_STATUS = (1 << 0), /**< PMEn change: 0 = SW, 1 = SW+PCI */
163};
164
165/** Interrupt_masks
166 *
167 * The masks are the same for both IMR and ISR
168 */
169enum rtl8169_interrupts {
170 INT_SERR = (1 << 15), /**< System error interrupt */
171 INT_TIME_OUT = (1 << 14), /**< Time out interrupt */
172 /* Bits 9 - 13 reserved */
173 INT_SW = (1 << 8), /**< Software Interrupt */
174 INT_TDU = (1 << 7), /**< Tx Descriptor Unvailable */
175 INT_FIFOOVW = (1 << 6), /**< Receiver FIFO overflow interrupt */
176 INT_PUN = (1 << 5), /**< Packet Underrun/Link Change Interrupt */
177 INT_RXOVW = (1 << 4), /**< Receiver buffer overflow */
178 INT_TER = (1 << 3), /**< Transmit error interrupt */
179 INT_TOK = (1 << 2), /**< Transmit OK interrupt */
180 INT_RER = (1 << 1), /**< Receive error interrupt */
181 INT_ROK = (1 << 0), /**< Receive OK interrupt */
182};
183
184/** Transmit status descriptor registers bits */
185enum rtl8169_tsd {
186 TSD_CRS = (1 << 31), /**< Carrier Sense Lost */
187 TSD_TABT = (1 << 30), /**< Transmit Abort */
188 TSD_OWC = (1 << 29), /**< Out of Window Collision */
189 TSD_CDH = (1 << 28), /**< CD Heart Beat */
190 TSD_NCC_SHIFT = 24, /**< Collision Count - bit shift */
191 TSD_NCC_SIZE = 4, /**< Collision Count - bit size */
192 TSD_NCC_MASK = (1 << 4)-1, /**< Collision Count - bit size */
193 TSD_ERTXTH_SHIFT = 16, /**< Early Tx Threshold - bit shift */
194 TSD_ERTXTH_SIZE = 6, /**< Early Tx Treshold - bit size */
195 TSD_TOK = (1 << 15), /**< Transmit OK */
196 TSD_TUN = (1 << 14), /**< Transmit FIFO Underrun */
197 TSD_OWN = (1 << 13), /**< OWN */
198 TSD_SIZE_SHIFT = 0, /**< Size - bit shift */
199 TSD_SIZE_SIZE = 13, /**< Size - bit size */
200 TSD_SIZE_MASK = 0x1fff, /**< Size - bit mask */
201};
202
203/** Receiver control register values */
204enum rtl8169_rcr {
205 RCR_MulERINT = 1 << 24, /**< Multiple early interrupt select */
206 /* Bits 23-17 reserved */
207 RCR_RER8 = 1 << 16,
208 RCR_RXFTH_SHIFT = 13, /**< Rx FIFO treshold part shitf */
209 RCR_RXFTH_SIZE = 3, /**< Rx FIFO treshold part size */
210 /* Bits 12-11 reserved */
211 RCR_MXDMA_SHIFT = 8, /**< Max DMA Burst Size part shift */
212 RCR_MXDMA_SIZE = 3, /**< Max DMA Burst Size part size */
213 /* Bit 7 reserved */
214 RCR_ACCEPT_ERROR = 1 << 5, /**< Accept error frame */
215 RCR_ACCEPT_RUNT = 1 << 4, /**< Accept Runt (8-64 bytes) frames */
216 RCR_ACCEPT_BROADCAST = 1 << 3, /**< Accept broadcast */
217 RCR_ACCEPT_MULTICAST = 1 << 2, /**< Accept multicast */
218 RCR_ACCEPT_PHYS_MATCH = 1 << 1, /**< Accept device MAC address match */
219 RCR_ACCEPT_ALL_PHYS = 1 << 0, /**< Accept all frames with phys. desticnation */
220 RCR_ACCEPT_MASK = (1 << 6) - 1 /**< Mask of accept part */
221};
222
223enum rtl8169_cr9346 {
224 CR9346EEM1_SHIFT = 6, /**< RTL8169 operating mode shift */
225 CR9346EEM1_SIZE = 2, /**< RTL8169 operating mode mask */
226 /* Bits 5-4 reserved */
227 EECS = (1 << 3), /**< EECS pin of 93C46 */
228 EESK = (1 << 2), /**< EESK pin of 93C46 */
229 EEDI = (1 << 1), /**< EEDI pin of 93C46 */
230 EEDO = (1 << 0), /**< EEDO pin of 93C46 */
231};
232
233/** Auto-negotiation advertisement register */
234enum rtl8169_anar {
235 ANAR_NEXT_PAGE = (1 << 15), /**< Next page bit, 0 - primary capability */
236 ANAR_ACK = (1 << 14), /**< Capability reception acknowledge */
237 ANAR_REMOTE_FAULT = (1 << 13), /**< Remote fault detection capability */
238 ANAR_PAUSE = (1 << 10), /**< Symetric pause frame capability */
239 ANAR_100T4 = (1 << 9), /**< T4, not supported by the device */
240 ANAR_100TX_FD = (1 << 8), /**< 100BASE_TX full duplex */
241 ANAR_100TX_HD = (1 << 7), /**< 100BASE_TX half duplex */
242 ANAR_10_FD = (1 << 6), /**< 10BASE_T full duplex */
243 ANAR_10_HD = (1 << 5), /**< 10BASE_T half duplex */
[90782c36]244 ANAR_SELECTOR = 0x1, /**< Selector */
245};
246
247enum rtl8169_phystatus {
248 PHYSTATUS_TBIEN = (1 << 7), /**< TBI enabled */
249 PHYSTATUS_TXFLOW = (1 << 6), /**< TX flow control enabled */
250 PHYSTATUS_RXFLOW = (1 << 5), /**< RX flow control enabled */
251 PHYSTATUS_1000M = (1 << 4), /**< Link speed is 1000Mbit/s */
252 PHYSTATUS_100M = (1 << 3), /**< Link speed is 100Mbit/s */
253 PHYSTATUS_10M = (1 << 2), /**< Link speed is 10Mbit/s */
254 PHYSTATUS_LINK = (1 << 1), /**< Link up */
255 PHYSTATUS_FDX = (1 << 0), /**< Link is full duplex */
[fef725d]256};
257
[59b3095]258enum rtl8169_tppoll {
259 TPPOLL_HPQ = (1 << 7), /**< Start transmit on high priority queue */
260 TPPOLL_NPQ = (1 << 6), /**< Start transmit on normal queue */
261 /* Bits 5-1 reserved */
262 TPPOLL_FSWINT = (1 << 0), /** < Generate software interrupt */
263};
264
265enum rtl8169_descr_control {
266 CONTROL_OWN = (1 << 31), /**< Descriptor ownership */
267 CONTROL_EOR = (1 << 30), /**< End Of Ring marker */
268 CONTROL_FS = (1 << 29), /**< First Segment marker */
269 CONTROL_LS = (1 << 28), /**< Last Segment marker */
270 CONTROL_LGSEN = (1 << 27), /**< Large send enable */
271 CONTROL_MSS_SHIFT = 16,
272 CONTROL_MSS_MASK = 10,
273 CONTROL_FRAMELEN_MASK = 0xffff
274};
275
276enum rtl8169_descr_txstatus {
277 TXSTATUS_UNDERRUN = (1 << 25),
278 TXSTATUS_TXERRSUM = (1 << 23),
279 TXSTATUS_OWINCOL = (1 << 22),
280 TXSTATUS_LINKFAIL = (1 << 21),
281 TXSTATUS_EXCESSCOL = (1 << 20)
282};
283
[be971233]284enum rtl8169_descr_rxstatus {
285 RXSTATUS_MAR = (1 << 27),
286 RXSTATUS_PAM = (1 << 26),
287 RXSTATUS_BAR = (1 << 25),
288 RXSTATUS_BOVF = (1 << 24),
289 RXSTATUS_FOVF = (1 << 23),
290 RXSTATUS_RWT = (1 << 22),
291 RXSTATUS_RES = (1 << 21),
292 RXSTATUS_RUNT = (1 << 20),
293 RXSTATUS_CRC = (1 << 19),
294 RXSTATUS_PID1 = (1 << 18),
295 RXSTATUS_PID0 = (1 << 17),
296 RXSTATUS_IPF = (1 << 16),
297 RXSTATUS_UDPF = (1 << 15),
298 RXSTATUS_TCPF = (1 << 14)
299};
300
[59b3095]301typedef struct rtl8169_descr {
[fef725d]302 uint32_t control;
303 uint32_t vlan;
304 uint32_t buf_low;
305 uint32_t buf_high;
[59b3095]306} rtl8169_descr_t;
[fef725d]307
308#endif
Note: See TracBrowser for help on using the repository browser.