Rev 7299 | Rev 9148 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 7299 | Rev 8997 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
2 | ;; ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2018. All rights reserved. ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2021. All rights reserved. ;; |
4 | ;; Distributed under terms of the GNU General Public License ;; |
4 | ;; Distributed under terms of the GNU General Public License ;; |
5 | ;; ;; |
5 | ;; ;; |
6 | ;; RTL8169 driver for KolibriOS ;; |
6 | ;; RTL8169 driver for KolibriOS ;; |
7 | ;; ;; |
7 | ;; ;; |
8 | ;; Copyright 2007 mike.dld, ;; |
8 | ;; Copyright 2007 mike.dld, ;; |
Line 23... | Line 23... | ||
23 | 23 | ||
24 | CURRENT_API = 0x0200 |
24 | CURRENT_API = 0x0200 |
25 | COMPATIBLE_API = 0x0100 |
25 | COMPATIBLE_API = 0x0100 |
Line 26... | Line 26... | ||
26 | API_VERSION = (COMPATIBLE_API shl 16) + CURRENT_API |
26 | API_VERSION = (COMPATIBLE_API shl 16) + CURRENT_API |
Line -... | Line 27... | ||
- | 27 | ||
- | 28 | ; configureable area |
|
27 | 29 | ||
28 | MAX_DEVICES = 16 |
30 | MAX_DEVICES = 16 ; Maximum number of devices this driver may handle |
Line 29... | Line 31... | ||
29 | 31 | ||
30 | __DEBUG__ = 1 |
32 | __DEBUG__ = 1 ; 1 = on, 0 = off |
- | 33 | __DEBUG_LEVEL__ = 2 ; 1 = verbose, 2 = errors only |
|
- | 34 | ||
Line 31... | Line 35... | ||
31 | __DEBUG_LEVEL__ = 2 ; 1 = verbose, 2 = errors only |
35 | NUM_TX_DESC = 32 ; Number of packets in send ring buffer |
Line 32... | Line 36... | ||
32 | 36 | NUM_RX_DESC = 32 ; Number of packets in receive ring buffer |
|
33 | NUM_TX_DESC = 4 |
37 | |
34 | NUM_RX_DESC = 4 |
38 | ; end configureable area |
35 | 39 | ||
36 | section '.flat' readable writable executable |
40 | section '.flat' readable writable executable |
Line -... | Line 41... | ||
- | 41 | ||
- | 42 | include '../proc32.inc' |
|
- | 43 | include '../struct.inc' |
|
- | 44 | include '../macros.inc' |
|
- | 45 | include '../fdo.inc' |
|
- | 46 | include '../netdrv.inc' |
|
- | 47 | ||
- | 48 | if (bsr NUM_TX_DESC)>(bsf NUM_TX_DESC) |
|
- | 49 | display 'NUM_TX_DESC must be a power of two' |
|
- | 50 | err |
|
37 | 51 | end if |
|
38 | include '../proc32.inc' |
52 | |
39 | include '../struct.inc' |
53 | if (bsr NUM_RX_DESC)>(bsf NUM_RX_DESC) |
40 | include '../macros.inc' |
54 | display 'NUM_RX_DESC must be a power of two' |
41 | include '../fdo.inc' |
55 | err |
Line 88... | Line 102... | ||
88 | ISB_TxOK = 0x04 |
102 | ISB_TxOK = 0x04 |
89 | ISB_RxErr = 0x02 |
103 | ISB_RxErr = 0x02 |
90 | ISB_RxOK = 0x01 |
104 | ISB_RxOK = 0x01 |
Line 91... | Line 105... | ||
91 | 105 | ||
- | 106 | ; RxStatusDesc |
|
- | 107 | SD_RxBOVF = (1 shl 24) |
|
92 | ; RxStatusDesc |
108 | SD_RxFOVF = (1 shl 23) |
93 | SD_RxRES = 0x00200000 |
109 | SD_RxRWT = (1 shl 22) |
94 | SD_RxCRC = 0x00080000 |
110 | SD_RxRES = (1 shl 21) |
95 | SD_RxRUNT = 0x00100000 |
111 | SD_RxRUNT = (1 shl 20) |
Line 96... | Line 112... | ||
96 | SD_RxRWT = 0x00400000 |
112 | SD_RxCRC = (1 shl 19) |
97 | 113 | ||
98 | ; ChipCmdBits |
114 | ; ChipCmdBits |
99 | CMD_Reset = 0x10 |
115 | CMD_Reset = 0x10 |
Line 1028... | Line 1044... | ||
1028 | [eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\ |
1044 | [eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\ |
1029 | [eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\ |
1045 | [eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\ |
1030 | [eax+13]:2,[eax+12]:2 |
1046 | [eax+13]:2,[eax+12]:2 |
Line 1031... | Line 1047... | ||
1031 | 1047 | ||
1032 | cmp [esi + NET_BUFF.length], 1514 |
1048 | cmp [esi + NET_BUFF.length], 1514 |
1033 | ja .fail |
1049 | ja .error |
1034 | cmp [esi + NET_BUFF.length], 60 |
1050 | cmp [esi + NET_BUFF.length], 60 |
Line 1035... | Line 1051... | ||
1035 | jb .fail |
1051 | jb .error |
1036 | 1052 | ||
Line 1037... | Line 1053... | ||
1037 | ;---------------------------------- |
1053 | ;---------------------------------- |
Line 1045... | Line 1061... | ||
1045 | 1061 | ||
1046 | ;---------------------------------- |
1062 | ;---------------------------------- |
Line 1047... | Line 1063... | ||
1047 | ; Check if the descriptor is in use |
1063 | ; Check if the descriptor is in use |
1048 | 1064 | ||
Line 1049... | Line 1065... | ||
1049 | test [esi + tx_desc.status], DSB_OWNbit |
1065 | test [esi + tx_desc.status], DSB_OWNbit |
1050 | jnz .desc |
1066 | jnz .overrun |
Line 1051... | Line 1067... | ||
1051 | 1067 | ||
Line 1093... | Line 1109... | ||
1093 | 1109 | ||
1094 | popf |
1110 | popf |
1095 | xor eax, eax |
1111 | xor eax, eax |
Line 1096... | Line 1112... | ||
1096 | ret |
1112 | ret |
1097 | 1113 | ||
- | 1114 | .error: |
|
- | 1115 | DEBUGF 2, "TX packet error\n" |
|
- | 1116 | inc [ebx + device.packets_tx_err] |
|
- | 1117 | invoke NetFree, [bufferptr] |
|
- | 1118 | ||
- | 1119 | popf |
|
- | 1120 | or eax, -1 |
|
1098 | .desc: |
1121 | ret |
1099 | DEBUGF 2,"Descriptor is still in use!\n" |
1122 | |
- | 1123 | .overrun: |
|
1100 | .fail: |
1124 | DEBUGF 2, "TX overrun\n" |
- | 1125 | inc [ebx + device.packets_tx_ovr] |
|
1101 | DEBUGF 2,"Transmit failed\n" |
1126 | invoke NetFree, [bufferptr] |
1102 | invoke NetFree, [bufferptr] |
1127 | |
1103 | popf |
1128 | popf |
Line 1104... | Line 1129... | ||
1104 | or eax, -1 |
1129 | or eax, -1 |
Line 1166... | Line 1191... | ||
1166 | lea esi, [ebx + device.rx_ring + eax] |
1191 | lea esi, [ebx + device.rx_ring + eax] |
Line 1167... | Line 1192... | ||
1167 | 1192 | ||
1168 | DEBUGF 1,"RxDesc.status = 0x%x\n", [esi + rx_desc.status] |
1193 | DEBUGF 1,"RxDesc.status = 0x%x\n", [esi + rx_desc.status] |
1169 | mov ecx, [esi + rx_desc.status] |
1194 | mov ecx, [esi + rx_desc.status] |
1170 | test ecx, DSB_OWNbit |
1195 | test ecx, DSB_OWNbit |
Line 1171... | Line 1196... | ||
1171 | jnz .rx_return |
1196 | jnz .rx_done |
- | 1197 | ||
1172 | 1198 | DEBUGF 1,"cur_rx = %u\n", [ebx + device.cur_rx] |
|
1173 | DEBUGF 1,"cur_rx = %u\n", [ebx + device.cur_rx] |
1199 | |
Line 1174... | Line 1200... | ||
1174 | test ecx, SD_RxRES |
1200 | test ecx, SD_RxRES |
1175 | jnz .rx_reuse |
1201 | jnz .rx_error |
1176 | 1202 | ||
1177 | push ebx |
1203 | push ebx |
Line 1196... | Line 1222... | ||
1196 | ; Allocate a new buffer |
1222 | ; Allocate a new buffer |
Line 1197... | Line 1223... | ||
1197 | 1223 | ||
1198 | mov [esi + rx_desc.status], 0 |
1224 | mov [esi + rx_desc.status], 0 |
1199 | invoke NetAlloc, RX_BUF_SIZE+NET_BUFF.data |
1225 | invoke NetAlloc, RX_BUF_SIZE+NET_BUFF.data |
1200 | test eax, eax |
1226 | test eax, eax |
1201 | jz .no_more_buffers |
1227 | jz .rx_overrun |
1202 | mov [esi + rx_desc.buf_soft_addr], eax |
1228 | mov [esi + rx_desc.buf_soft_addr], eax |
1203 | invoke GetPhysAddr |
1229 | invoke GetPhysAddr |
1204 | add eax, NET_BUFF.data |
1230 | add eax, NET_BUFF.data |
Line 1212... | Line 1238... | ||
1212 | jne @f |
1238 | jne @f |
1213 | or eax, DSB_EORbit |
1239 | or eax, DSB_EORbit |
1214 | @@: |
1240 | @@: |
1215 | mov [esi + rx_desc.status], eax |
1241 | mov [esi + rx_desc.status], eax |
Line 1216... | Line -... | ||
1216 | - | ||
1217 | .no_more_buffers: |
1242 | |
1218 | ;-------------- |
1243 | ;-------------- |
Line 1219... | Line 1244... | ||
1219 | ; Update rx ptr |
1244 | ; Update rx ptr |
1220 | 1245 | ||
Line 1221... | Line 1246... | ||
1221 | inc [ebx + device.cur_rx] |
1246 | inc [ebx + device.cur_rx] |
Line -... | Line 1247... | ||
- | 1247 | and [ebx + device.cur_rx], NUM_RX_DESC - 1 |
|
- | 1248 | ||
- | 1249 | jmp [EthInput] |
|
- | 1250 | ||
- | 1251 | .rx_overrun: |
|
- | 1252 | DEBUGF 2,"RX FIFO overrun\n" |
|
- | 1253 | inc [ebx + device.packets_rx_ovr] |
|
- | 1254 | jmp .rx_next |
|
- | 1255 | ||
- | 1256 | .rx_error: |
|
- | 1257 | inc [ebx + device.packets_rx_err] |
|
- | 1258 | test ecx, SD_RxRWT or SD_RxRUNT |
|
- | 1259 | jz @f |
|
- | 1260 | DEBUGF 2,"RX length error" |
|
- | 1261 | @@: |
|
- | 1262 | test ecx, SD_RxCRC |
|
- | 1263 | jz @f |
|
- | 1264 | DEBUGF 2,"RX CRC error" |
|
- | 1265 | @@: |
|
- | 1266 | test ecx, SD_RxFOVF |
|
1222 | and [ebx + device.cur_rx], NUM_RX_DESC - 1 |
1267 | jz @f |
1223 | 1268 | DEBUGF 2,"RX FIFO error" |
|
1224 | jmp [EthInput] |
1269 | @@: |
1225 | 1270 | ||
1226 | .rx_reuse: |
1271 | .rx_next: |
1227 | mov eax, DSB_OWNbit or RX_BUF_SIZE |
1272 | mov eax, DSB_OWNbit or RX_BUF_SIZE |
1228 | cmp [ebx + device.cur_rx], NUM_RX_DESC - 1 |
1273 | cmp [ebx + device.cur_rx], NUM_RX_DESC - 1 |
1229 | jne @f |
1274 | jne @f |
1230 | or eax, DSB_EORbit |
1275 | or eax, DSB_EORbit |
Line 1231... | Line 1276... | ||
1231 | @@: |
1276 | @@: |
1232 | mov [esi + rx_desc.status], eax |
1277 | mov [esi + rx_desc.status], eax |
1233 | push ebx |
1278 | push ebx |
Line 1234... | Line 1279... | ||
1234 | jmp .rx_loop |
1279 | jmp .rx_loop |
1235 | 1280 |