00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef __RTL8139_H__
00011 #define __RTL8139_H__
00012
00013
00014
00015
00016
00017 #include <libc.h>
00018 #include <libpci.h>
00019
00020 #define RTL8139_MAX_DEV 2
00021
00022 #define PCI_VENDOR_REALTEK 0x10ec
00023 #define PCI_PRODUCT_REALTEK_RT8129 0x10ec
00024
00025 #define RTK_PCI_LOIO 0x10
00026 #define RTK_PCI_LOMEM 0x14
00027
00028 struct s_rtl8139_pci_dev {
00029 uint16_t vendor_id;
00030 uint16_t product_id;
00031 char *description;
00032 };
00033
00034
00035
00036
00037 #define RTL8139_TX_NB 4
00038
00039 struct s_dev_tx
00040 {
00041 int tx_id;
00042 int tx_used;
00043 };
00044
00045 typedef struct s_rtl8139_dev {
00046
00047 pci_tag_t pci_tag;
00048 int irq;
00049 u_int32_t id;
00050
00051 pid_t handler_pid;
00052
00053 #ifdef USE_IO
00054 u_int16_t iobase;
00055 u_int16_t iosize;
00056 #else
00057 vaddr_t membase;
00058 u_int32_t memsize;
00059 #endif
00060
00061 paddr_t rxpaddr;
00062 vaddr_t rxvaddr;
00063
00064 u_int32_t state;
00065
00066 struct s_dev_tx tx[RTL8139_TX_NB];
00067 int tx_current;
00068 } rtl8139_dev_t;
00069
00070
00071
00072
00073
00074 #define RXBUF_SIZE (64 * 1024)
00075 #define RXBUF_PGSIZE (ROUNDUP(RXBUF_SIZE + 16, PAGESIZE) / PAGESIZE)
00076
00077
00078
00079
00080
00081 #define RTK_IDR0 0x0000
00082 #define RTK_IDR1 0x0001
00083 #define RTK_IDR2 0x0002
00084 #define RTK_IDR3 0x0003
00085 #define RTK_IDR4 0x0004
00086 #define RTK_IDR5 0x0005
00087
00088 #define RTK_MAR0 0x0008
00089 #define RTK_MAR1 0x0009
00090 #define RTK_MAR2 0x000A
00091 #define RTK_MAR3 0x000B
00092 #define RTK_MAR4 0x000C
00093 #define RTK_MAR5 0x000D
00094 #define RTK_MAR6 0x000E
00095 #define RTK_MAR7 0x000F
00096
00097 #define RTK_TXSTAT0 0x0010
00098 #define RTK_TXSTAT1 0x0014
00099 #define RTK_TXSTAT2 0x0018
00100 #define RTK_TXSTAT3 0x001C
00101
00102 #define RTK_TXADDR0 0x0020
00103 #define RTK_TXADDR1 0x0024
00104 #define RTK_TXADDR2 0x0028
00105 #define RTK_TXADDR3 0x002C
00106
00107 #define RTK_RXADDR 0x0030
00108 #define RTK_RX_EARLY_BYTES 0x0034
00109 #define RTK_RX_EARLY_STAT 0x0036
00110 #define RTK_COMMAND 0x0037
00111 #define RTK_CURRXADDR 0x0038
00112 #define RTK_CURRXBUF 0x003A
00113 #define RTK_IMR 0x003C
00114 #define RTK_ISR 0x003E
00115 #define RTK_TXCFG 0x0040
00116 #define RTK_RXCFG 0x0044
00117 #define RTK_TIMERCNT 0x0048
00118 #define RTK_MISSEDPKT 0x004C
00119 #define RTK_EECMD 0x0050
00120 #define RTK_CFG0 0x0051
00121 #define RTK_CFG1 0x0052
00122
00123 #define RTK_MEDIASTAT 0x0058
00124
00125 #define RTK_MII 0x005A
00126 #define RTK_HALTCLK 0x005B
00127 #define RTK_MULTIINTR 0x005C
00128 #define RTK_PCIREV 0x005E
00129
00130 #define RTK_TXSTAT_ALL 0x0060
00131
00132 #define RTK_BMCR 0x0062
00133 #define RTK_BMSR 0x0064
00134 #define RTK_ANAR 0x0066
00135 #define RTK_LPAR 0x0068
00136 #define RTK_ANER 0x006A
00137
00138 #define RTK_DISCCNT 0x006C
00139 #define RTK_FALSECAR 0x006E
00140 #define RTK_NWAYTST 0x0070
00141 #define RTK_RX_ER 0x0072
00142 #define RTK_CSCFG 0x0074
00143
00144
00145
00146
00147 #define RTK_TXCFG_CLRABRT 0x00000001
00148 #define RTK_TXCFG_MAXDMA 0x00000700
00149 #define RTK_TXCFG_CRCAPPEND 0x00010000
00150 #define RTK_TXCFG_LOOPBKTST 0x00060000
00151 #define RTK_TXCFG_IFG2 0x00080000
00152 #define RTK_TXCFG_IFG 0x03000000
00153 #define RTK_TXCFG_HWREV 0x7CC00000
00154
00155 #define RTK_LOOPTEST_OFF 0x00000000
00156 #define RTK_LOOPTEST_ON 0x00020000
00157 #define RTK_LOOPTEST_ON_CPLUS 0x00060000
00158
00159 #define RTK_HWREV_8169 0x00000000
00160 #define RTK_HWREV_8169S 0x04000000
00161 #define RTK_HWREV_8110S 0x00800000
00162 #define RTK_HWREV_8139 0x60000000
00163 #define RTK_HWREV_8139A 0x70000000
00164 #define RTK_HWREV_8139AG 0x70800000
00165 #define RTK_HWREV_8139B 0x78000000
00166 #define RTK_HWREV_8130 0x7C000000
00167 #define RTK_HWREV_8139C 0x74000000
00168 #define RTK_HWREV_8139D 0x74400000
00169 #define RTK_HWREV_8139CPLUS 0x74800000
00170 #define RTK_HWREV_8101 0x74c00000
00171 #define RTK_HWREV_8100 0x78800000
00172
00173 #define RTK_TXDMA_16BYTES 0x00000000
00174 #define RTK_TXDMA_32BYTES 0x00000100
00175 #define RTK_TXDMA_64BYTES 0x00000200
00176 #define RTK_TXDMA_128BYTES 0x00000300
00177 #define RTK_TXDMA_256BYTES 0x00000400
00178 #define RTK_TXDMA_512BYTES 0x00000500
00179 #define RTK_TXDMA_1024BYTES 0x00000600
00180 #define RTK_TXDMA_2048BYTES 0x00000700
00181
00182
00183
00184
00185 #define RTK_TXSTAT_LENMASK 0x00001FFF
00186 #define RTK_TXSTAT_OWN 0x00002000
00187 #define RTK_TXSTAT_TX_UNDERRUN 0x00004000
00188 #define RTK_TXSTAT_TX_OK 0x00008000
00189 #define RTK_TXSTAT_EARLY_THRESH 0x003F0000
00190 #define RTK_TXSTAT_COLLCNT 0x0F000000
00191 #define RTK_TXSTAT_CARR_HBEAT 0x10000000
00192 #define RTK_TXSTAT_OUTOFWIN 0x20000000
00193 #define RTK_TXSTAT_TXABRT 0x40000000
00194 #define RTK_TXSTAT_CARRLOSS 0x80000000
00195
00196
00197
00198
00199 #define RTK_ISR_RX_OK 0x0001
00200 #define RTK_ISR_RX_ERR 0x0002
00201 #define RTK_ISR_TX_OK 0x0004
00202 #define RTK_ISR_TX_ERR 0x0008
00203 #define RTK_ISR_RX_OVERRUN 0x0010
00204 #define RTK_ISR_PKT_UNDERRUN 0x0020
00205 #define RTK_ISR_FIFO_OFLOW 0x0040
00206 #define RTK_ISR_CABLE_LEN_CHGD 0x2000
00207 #define RTK_ISR_TIMEOUT_EXPIRED 0x4000
00208 #define RTK_ISR_SYSTEM_ERR 0x8000
00209
00210 #define RTK_INTRS \
00211 (RTK_ISR_TX_OK|RTK_ISR_RX_OK|RTK_ISR_RX_ERR|RTK_ISR_TX_ERR| \
00212 RTK_ISR_RX_OVERRUN|RTK_ISR_PKT_UNDERRUN|RTK_ISR_FIFO_OFLOW| \
00213 RTK_ISR_SYSTEM_ERR)
00214
00215 #define RTK_INTRS_CPLUS \
00216 (RTK_ISR_RX_OK|RTK_ISR_RX_ERR|RTK_ISR_TX_ERR| \
00217 RTK_ISR_RX_OVERRUN|RTK_ISR_PKT_UNDERRUN|RTK_ISR_FIFO_OFLOW| \
00218 RTK_ISR_PCS_TIMEOUT|RTK_ISR_SYSTEM_ERR|RTK_ISR_TIMEOUT_EXPIRED)
00219
00220
00221
00222
00223 #define RTK_MEDIASTAT_RXPAUSE 0x01
00224 #define RTK_MEDIASTAT_TXPAUSE 0x02
00225 #define RTK_MEDIASTAT_LINK 0x04
00226 #define RTK_MEDIASTAT_SPEED10 0x08
00227 #define RTK_MEDIASTAT_RXFLOWCTL 0x40
00228 #define RTK_MEDIASTAT_TXFLOWCTL 0x80
00229
00230
00231
00232
00233 #define RTK_RXCFG_RX_ALLPHYS 0x00000001
00234 #define RTK_RXCFG_RX_INDIV 0x00000002
00235 #define RTK_RXCFG_RX_MULTI 0x00000004
00236 #define RTK_RXCFG_RX_BROAD 0x00000008
00237 #define RTK_RXCFG_RX_RUNT 0x00000010
00238 #define RTK_RXCFG_RX_ERRPKT 0x00000020
00239 #define RTK_RXCFG_WRAP 0x00000080
00240 #define RTK_RXCFG_MAXDMA 0x00000700
00241 #define RTK_RXCFG_BUFSZ 0x00001800
00242 #define RTK_RXCFG_FIFOTHRESH 0x0000E000
00243 #define RTK_RXCFG_EARLYTHRESH 0x07000000
00244
00245 #define RTK_RXDMA_16BYTES 0x00000000
00246 #define RTK_RXDMA_32BYTES 0x00000100
00247 #define RTK_RXDMA_64BYTES 0x00000200
00248 #define RTK_RXDMA_128BYTES 0x00000300
00249 #define RTK_RXDMA_256BYTES 0x00000400
00250 #define RTK_RXDMA_512BYTES 0x00000500
00251 #define RTK_RXDMA_1024BYTES 0x00000600
00252 #define RTK_RXDMA_UNLIMITED 0x00000700
00253
00254 #define RTK_RXBUF_8 0x00000000
00255 #define RTK_RXBUF_16 0x00000800
00256 #define RTK_RXBUF_32 0x00001000
00257 #define RTK_RXBUF_64 0x00001800
00258
00259 #define RTK_RXFIFO_16BYTES 0x00000000
00260 #define RTK_RXFIFO_32BYTES 0x00002000
00261 #define RTK_RXFIFO_64BYTES 0x00004000
00262 #define RTK_RXFIFO_128BYTES 0x00006000
00263 #define RTK_RXFIFO_256BYTES 0x00008000
00264 #define RTK_RXFIFO_512BYTES 0x0000A000
00265 #define RTK_RXFIFO_1024BYTES 0x0000C000
00266 #define RTK_RXFIFO_NOTHRESH 0x0000E000
00267
00268
00269
00270
00271
00272 #define RTK_RXSTAT_RXOK 0x00000001
00273 #define RTK_RXSTAT_ALIGNERR 0x00000002
00274 #define RTK_RXSTAT_CRCERR 0x00000004
00275 #define RTK_RXSTAT_GIANT 0x00000008
00276 #define RTK_RXSTAT_RUNT 0x00000010
00277 #define RTK_RXSTAT_BADSYM 0x00000020
00278 #define RTK_RXSTAT_BROAD 0x00002000
00279 #define RTK_RXSTAT_INDIV 0x00004000
00280 #define RTK_RXSTAT_MULTI 0x00008000
00281 #define RTK_RXSTAT_LENMASK 0xFFFF0000
00282
00283 #define RTK_RXSTAT_UNFINISHED 0xFFF0
00284 #define RTK_RXSTAT_LEN 4
00285
00286
00287
00288
00289 #define RTK_CMD_EMPTY_RXBUF 0x0001
00290 #define RTK_CMD_TX_ENB 0x0004
00291 #define RTK_CMD_RX_ENB 0x0008
00292 #define RTK_CMD_RESET 0x0010
00293
00294
00295
00296
00297 #define RTK_EE_DATAOUT 0x01
00298 #define RTK_EE_DATAIN 0x02
00299 #define RTK_EE_CLK 0x04
00300 #define RTK_EE_SEL 0x08
00301 #define RTK_EE_MODE (0x40|0x80)
00302
00303 #define RTK_EEMODE_OFF 0x00
00304 #define RTK_EEMODE_AUTOLOAD 0x40
00305 #define RTK_EEMODE_PROGRAM 0x80
00306 #define RTK_EEMODE_WRITECFG (0x80|0x40)
00307
00308
00309 #define RTK_EEADDR_LEN0 6
00310 #define RTK_EEADDR_LEN1 8
00311 #define RTK_EECMD_LEN 4
00312
00313 #define RTK_EECMD_WRITE 0x5
00314 #define RTK_EECMD_READ 0x6
00315 #define RTK_EECMD_ERASE 0x7
00316
00317 #define RTK_EE_ID 0x00
00318 #define RTK_EE_PCI_VID 0x01
00319 #define RTK_EE_PCI_DID 0x02
00320
00321 #define RTK_EE_EADDR0 0x07
00322 #define RTK_EE_EADDR1 0x08
00323 #define RTK_EE_EADDR2 0x09
00324
00325
00326
00327
00328 #define RTK_CFG0_ROM0 0x01
00329 #define RTK_CFG0_ROM1 0x02
00330 #define RTK_CFG0_ROM2 0x04
00331 #define RTK_CFG0_PL0 0x08
00332 #define RTK_CFG0_PL1 0x10
00333 #define RTK_CFG0_10MBPS 0x20
00334 #define RTK_CFG0_PCS 0x40
00335 #define RTK_CFG0_SCR 0x80
00336
00337
00338
00339
00340 #define RTK_CFG1_PWRDWN 0x01
00341 #define RTK_CFG1_SLEEP 0x02
00342 #define RTK_CFG1_IOMAP 0x04
00343 #define RTK_CFG1_MEMMAP 0x08
00344 #define RTK_CFG1_RSVD 0x10
00345 #define RTK_CFG1_DRVLOAD 0x20
00346 #define RTK_CFG1_LED0 0x40
00347 #define RTK_CFG1_LED1 0x80
00348
00349 #endif