You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

via-rhine.c 39KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447
  1. /* rhine.c:Fast Ethernet driver for Linux. */
  2. /*
  3. Adapted 09-jan-2000 by Paolo Marini (paolom@prisma-eng.it)
  4. originally written by Donald Becker.
  5. This software may be used and distributed according to the terms
  6. of the GNU Public License (GPL), incorporated herein by reference.
  7. Drivers derived from this code also fall under the GPL and must retain
  8. this authorship and copyright notice.
  9. Under no circumstances are the authors responsible for
  10. the proper functioning of this software, nor do the authors assume any
  11. responsibility for damages incurred with its use.
  12. This driver is designed for the VIA VT86C100A Rhine-II PCI Fast Ethernet
  13. controller.
  14. */
  15. static const char *version = "rhine.c v1.0.2 2004-10-29\n";
  16. /* A few user-configurable values. */
  17. // max time out delay time
  18. #define W_MAX_TIMEOUT 0x0FFFU
  19. /* Size of the in-memory receive ring. */
  20. #define RX_BUF_LEN_IDX 3 /* 0==8K, 1==16K, 2==32K, 3==64K */
  21. #define RX_BUF_LEN (8192 << RX_BUF_LEN_IDX)
  22. /* Size of the Tx bounce buffers -- must be at least (dev->mtu+14+4). */
  23. #define TX_BUF_SIZE 1536
  24. #define RX_BUF_SIZE 1536
  25. /* PCI Tuning Parameters
  26. Threshold is bytes transferred to chip before transmission starts. */
  27. #define TX_FIFO_THRESH 256 /* In bytes, rounded down to 32 byte units. */
  28. /* The following settings are log_2(bytes)-4: 0 == 16 bytes .. 6==1024. */
  29. #define RX_FIFO_THRESH 4 /* Rx buffer level before first PCI xfer. */
  30. #define RX_DMA_BURST 4 /* Maximum PCI burst, '4' is 256 bytes */
  31. #define TX_DMA_BURST 4
  32. /* Operational parameters that usually are not changed. */
  33. /* Time in jiffies before concluding the transmitter is hung. */
  34. #define TX_TIMEOUT ((2000*HZ)/1000)
  35. #include "etherboot.h"
  36. #include "nic.h"
  37. #include <gpxe/pci.h>
  38. #include <gpxe/ethernet.h>
  39. /* define all ioaddr */
  40. #define byPAR0 ioaddr
  41. #define byRCR ioaddr + 6
  42. #define byTCR ioaddr + 7
  43. #define byCR0 ioaddr + 8
  44. #define byCR1 ioaddr + 9
  45. #define byISR0 ioaddr + 0x0c
  46. #define byISR1 ioaddr + 0x0d
  47. #define byIMR0 ioaddr + 0x0e
  48. #define byIMR1 ioaddr + 0x0f
  49. #define byMAR0 ioaddr + 0x10
  50. #define byMAR1 ioaddr + 0x11
  51. #define byMAR2 ioaddr + 0x12
  52. #define byMAR3 ioaddr + 0x13
  53. #define byMAR4 ioaddr + 0x14
  54. #define byMAR5 ioaddr + 0x15
  55. #define byMAR6 ioaddr + 0x16
  56. #define byMAR7 ioaddr + 0x17
  57. #define dwCurrentRxDescAddr ioaddr + 0x18
  58. #define dwCurrentTxDescAddr ioaddr + 0x1c
  59. #define dwCurrentRDSE0 ioaddr + 0x20
  60. #define dwCurrentRDSE1 ioaddr + 0x24
  61. #define dwCurrentRDSE2 ioaddr + 0x28
  62. #define dwCurrentRDSE3 ioaddr + 0x2c
  63. #define dwNextRDSE0 ioaddr + 0x30
  64. #define dwNextRDSE1 ioaddr + 0x34
  65. #define dwNextRDSE2 ioaddr + 0x38
  66. #define dwNextRDSE3 ioaddr + 0x3c
  67. #define dwCurrentTDSE0 ioaddr + 0x40
  68. #define dwCurrentTDSE1 ioaddr + 0x44
  69. #define dwCurrentTDSE2 ioaddr + 0x48
  70. #define dwCurrentTDSE3 ioaddr + 0x4c
  71. #define dwNextTDSE0 ioaddr + 0x50
  72. #define dwNextTDSE1 ioaddr + 0x54
  73. #define dwNextTDSE2 ioaddr + 0x58
  74. #define dwNextTDSE3 ioaddr + 0x5c
  75. #define dwCurrRxDMAPtr ioaddr + 0x60
  76. #define dwCurrTxDMAPtr ioaddr + 0x64
  77. #define byMPHY ioaddr + 0x6c
  78. #define byMIISR ioaddr + 0x6d
  79. #define byBCR0 ioaddr + 0x6e
  80. #define byBCR1 ioaddr + 0x6f
  81. #define byMIICR ioaddr + 0x70
  82. #define byMIIAD ioaddr + 0x71
  83. #define wMIIDATA ioaddr + 0x72
  84. #define byEECSR ioaddr + 0x74
  85. #define byTEST ioaddr + 0x75
  86. #define byGPIO ioaddr + 0x76
  87. #define byCFGA ioaddr + 0x78
  88. #define byCFGB ioaddr + 0x79
  89. #define byCFGC ioaddr + 0x7a
  90. #define byCFGD ioaddr + 0x7b
  91. #define wTallyCntMPA ioaddr + 0x7c
  92. #define wTallyCntCRC ioaddr + 0x7d
  93. #define bySTICKHW ioaddr + 0x83
  94. #define byWOLcrClr ioaddr + 0xA4
  95. #define byWOLcgClr ioaddr + 0xA7
  96. #define byPwrcsrClr ioaddr + 0xAC
  97. /*--------------------- Exioaddr Definitions -------------------------*/
  98. /*
  99. * Bits in the RCR register
  100. */
  101. #define RCR_RRFT2 0x80
  102. #define RCR_RRFT1 0x40
  103. #define RCR_RRFT0 0x20
  104. #define RCR_PROM 0x10
  105. #define RCR_AB 0x08
  106. #define RCR_AM 0x04
  107. #define RCR_AR 0x02
  108. #define RCR_SEP 0x01
  109. /*
  110. * Bits in the TCR register
  111. */
  112. #define TCR_RTSF 0x80
  113. #define TCR_RTFT1 0x40
  114. #define TCR_RTFT0 0x20
  115. #define TCR_OFSET 0x08
  116. #define TCR_LB1 0x04 /* loopback[1] */
  117. #define TCR_LB0 0x02 /* loopback[0] */
  118. /*
  119. * Bits in the CR0 register
  120. */
  121. #define CR0_RDMD 0x40 /* rx descriptor polling demand */
  122. #define CR0_TDMD 0x20 /* tx descriptor polling demand */
  123. #define CR0_TXON 0x10
  124. #define CR0_RXON 0x08
  125. #define CR0_STOP 0x04 /* stop NIC, default = 1 */
  126. #define CR0_STRT 0x02 /* start NIC */
  127. #define CR0_INIT 0x01 /* start init process */
  128. /*
  129. * Bits in the CR1 register
  130. */
  131. #define CR1_SFRST 0x80 /* software reset */
  132. #define CR1_RDMD1 0x40 /* RDMD1 */
  133. #define CR1_TDMD1 0x20 /* TDMD1 */
  134. #define CR1_KEYPAG 0x10 /* turn on par/key */
  135. #define CR1_DPOLL 0x08 /* disable rx/tx auto polling */
  136. #define CR1_FDX 0x04 /* full duplex mode */
  137. #define CR1_ETEN 0x02 /* early tx mode */
  138. #define CR1_EREN 0x01 /* early rx mode */
  139. /*
  140. * Bits in the CR register
  141. */
  142. #define CR_RDMD 0x0040 /* rx descriptor polling demand */
  143. #define CR_TDMD 0x0020 /* tx descriptor polling demand */
  144. #define CR_TXON 0x0010
  145. #define CR_RXON 0x0008
  146. #define CR_STOP 0x0004 /* stop NIC, default = 1 */
  147. #define CR_STRT 0x0002 /* start NIC */
  148. #define CR_INIT 0x0001 /* start init process */
  149. #define CR_SFRST 0x8000 /* software reset */
  150. #define CR_RDMD1 0x4000 /* RDMD1 */
  151. #define CR_TDMD1 0x2000 /* TDMD1 */
  152. #define CR_KEYPAG 0x1000 /* turn on par/key */
  153. #define CR_DPOLL 0x0800 /* disable rx/tx auto polling */
  154. #define CR_FDX 0x0400 /* full duplex mode */
  155. #define CR_ETEN 0x0200 /* early tx mode */
  156. #define CR_EREN 0x0100 /* early rx mode */
  157. /*
  158. * Bits in the IMR0 register
  159. */
  160. #define IMR0_CNTM 0x80
  161. #define IMR0_BEM 0x40
  162. #define IMR0_RUM 0x20
  163. #define IMR0_TUM 0x10
  164. #define IMR0_TXEM 0x08
  165. #define IMR0_RXEM 0x04
  166. #define IMR0_PTXM 0x02
  167. #define IMR0_PRXM 0x01
  168. /* define imrshadow */
  169. #define IMRShadow 0x5AFF
  170. /*
  171. * Bits in the IMR1 register
  172. */
  173. #define IMR1_INITM 0x80
  174. #define IMR1_SRCM 0x40
  175. #define IMR1_NBFM 0x10
  176. #define IMR1_PRAIM 0x08
  177. #define IMR1_RES0M 0x04
  178. #define IMR1_ETM 0x02
  179. #define IMR1_ERM 0x01
  180. /*
  181. * Bits in the ISR register
  182. */
  183. #define ISR_INITI 0x8000
  184. #define ISR_SRCI 0x4000
  185. #define ISR_ABTI 0x2000
  186. #define ISR_NORBF 0x1000
  187. #define ISR_PKTRA 0x0800
  188. #define ISR_RES0 0x0400
  189. #define ISR_ETI 0x0200
  190. #define ISR_ERI 0x0100
  191. #define ISR_CNT 0x0080
  192. #define ISR_BE 0x0040
  193. #define ISR_RU 0x0020
  194. #define ISR_TU 0x0010
  195. #define ISR_TXE 0x0008
  196. #define ISR_RXE 0x0004
  197. #define ISR_PTX 0x0002
  198. #define ISR_PRX 0x0001
  199. /*
  200. * Bits in the ISR0 register
  201. */
  202. #define ISR0_CNT 0x80
  203. #define ISR0_BE 0x40
  204. #define ISR0_RU 0x20
  205. #define ISR0_TU 0x10
  206. #define ISR0_TXE 0x08
  207. #define ISR0_RXE 0x04
  208. #define ISR0_PTX 0x02
  209. #define ISR0_PRX 0x01
  210. /*
  211. * Bits in the ISR1 register
  212. */
  213. #define ISR1_INITI 0x80
  214. #define ISR1_SRCI 0x40
  215. #define ISR1_NORBF 0x10
  216. #define ISR1_PKTRA 0x08
  217. #define ISR1_ETI 0x02
  218. #define ISR1_ERI 0x01
  219. /* ISR ABNORMAL CONDITION */
  220. #define ISR_ABNORMAL ISR_BE+ISR_RU+ISR_TU+ISR_CNT+ISR_NORBF+ISR_PKTRA
  221. /*
  222. * Bits in the MIISR register
  223. */
  224. #define MIISR_MIIERR 0x08
  225. #define MIISR_MRERR 0x04
  226. #define MIISR_LNKFL 0x02
  227. #define MIISR_SPEED 0x01
  228. /*
  229. * Bits in the MIICR register
  230. */
  231. #define MIICR_MAUTO 0x80
  232. #define MIICR_RCMD 0x40
  233. #define MIICR_WCMD 0x20
  234. #define MIICR_MDPM 0x10
  235. #define MIICR_MOUT 0x08
  236. #define MIICR_MDO 0x04
  237. #define MIICR_MDI 0x02
  238. #define MIICR_MDC 0x01
  239. /*
  240. * Bits in the EECSR register
  241. */
  242. #define EECSR_EEPR 0x80 /* eeprom programed status, 73h means programed */
  243. #define EECSR_EMBP 0x40 /* eeprom embeded programming */
  244. #define EECSR_AUTOLD 0x20 /* eeprom content reload */
  245. #define EECSR_DPM 0x10 /* eeprom direct programming */
  246. #define EECSR_CS 0x08 /* eeprom CS pin */
  247. #define EECSR_SK 0x04 /* eeprom SK pin */
  248. #define EECSR_DI 0x02 /* eeprom DI pin */
  249. #define EECSR_DO 0x01 /* eeprom DO pin */
  250. /*
  251. * Bits in the BCR0 register
  252. */
  253. #define BCR0_CRFT2 0x20
  254. #define BCR0_CRFT1 0x10
  255. #define BCR0_CRFT0 0x08
  256. #define BCR0_DMAL2 0x04
  257. #define BCR0_DMAL1 0x02
  258. #define BCR0_DMAL0 0x01
  259. /*
  260. * Bits in the BCR1 register
  261. */
  262. #define BCR1_CTSF 0x20
  263. #define BCR1_CTFT1 0x10
  264. #define BCR1_CTFT0 0x08
  265. #define BCR1_POT2 0x04
  266. #define BCR1_POT1 0x02
  267. #define BCR1_POT0 0x01
  268. /*
  269. * Bits in the CFGA register
  270. */
  271. #define CFGA_EELOAD 0x80 /* enable eeprom embeded and direct programming */
  272. #define CFGA_JUMPER 0x40
  273. #define CFGA_MTGPIO 0x08
  274. #define CFGA_T10EN 0x02
  275. #define CFGA_AUTO 0x01
  276. /*
  277. * Bits in the CFGB register
  278. */
  279. #define CFGB_PD 0x80
  280. #define CFGB_POLEN 0x02
  281. #define CFGB_LNKEN 0x01
  282. /*
  283. * Bits in the CFGC register
  284. */
  285. #define CFGC_M10TIO 0x80
  286. #define CFGC_M10POL 0x40
  287. #define CFGC_PHY1 0x20
  288. #define CFGC_PHY0 0x10
  289. #define CFGC_BTSEL 0x08
  290. #define CFGC_BPS2 0x04 /* bootrom select[2] */
  291. #define CFGC_BPS1 0x02 /* bootrom select[1] */
  292. #define CFGC_BPS0 0x01 /* bootrom select[0] */
  293. /*
  294. * Bits in the CFGD register
  295. */
  296. #define CFGD_GPIOEN 0x80
  297. #define CFGD_DIAG 0x40
  298. #define CFGD_MAGIC 0x10
  299. #define CFGD_RANDOM 0x08
  300. #define CFGD_CFDX 0x04
  301. #define CFGD_CEREN 0x02
  302. #define CFGD_CETEN 0x01
  303. /* Bits in RSR */
  304. #define RSR_RERR 0x00000001
  305. #define RSR_CRC 0x00000002
  306. #define RSR_FAE 0x00000004
  307. #define RSR_FOV 0x00000008
  308. #define RSR_LONG 0x00000010
  309. #define RSR_RUNT 0x00000020
  310. #define RSR_SERR 0x00000040
  311. #define RSR_BUFF 0x00000080
  312. #define RSR_EDP 0x00000100
  313. #define RSR_STP 0x00000200
  314. #define RSR_CHN 0x00000400
  315. #define RSR_PHY 0x00000800
  316. #define RSR_BAR 0x00001000
  317. #define RSR_MAR 0x00002000
  318. #define RSR_RXOK 0x00008000
  319. #define RSR_ABNORMAL RSR_RERR+RSR_LONG+RSR_RUNT
  320. /* Bits in TSR */
  321. #define TSR_NCR0 0x00000001
  322. #define TSR_NCR1 0x00000002
  323. #define TSR_NCR2 0x00000004
  324. #define TSR_NCR3 0x00000008
  325. #define TSR_COLS 0x00000010
  326. #define TSR_CDH 0x00000080
  327. #define TSR_ABT 0x00000100
  328. #define TSR_OWC 0x00000200
  329. #define TSR_CRS 0x00000400
  330. #define TSR_UDF 0x00000800
  331. #define TSR_TBUFF 0x00001000
  332. #define TSR_SERR 0x00002000
  333. #define TSR_JAB 0x00004000
  334. #define TSR_TERR 0x00008000
  335. #define TSR_ABNORMAL TSR_TERR+TSR_OWC+TSR_ABT+TSR_JAB+TSR_CRS
  336. #define TSR_OWN_BIT 0x80000000
  337. #define CB_DELAY_LOOP_WAIT 10 /* 10ms */
  338. /* enabled mask value of irq */
  339. #define W_IMR_MASK_VALUE 0x1BFF /* initial value of IMR */
  340. /* Ethernet address filter type */
  341. #define PKT_TYPE_DIRECTED 0x0001 /* obsolete, directed address is always accepted */
  342. #define PKT_TYPE_MULTICAST 0x0002
  343. #define PKT_TYPE_ALL_MULTICAST 0x0004
  344. #define PKT_TYPE_BROADCAST 0x0008
  345. #define PKT_TYPE_PROMISCUOUS 0x0020
  346. #define PKT_TYPE_LONG 0x2000
  347. #define PKT_TYPE_RUNT 0x4000
  348. #define PKT_TYPE_ERROR 0x8000 /* accept error packets, e.g. CRC error */
  349. /* Loopback mode */
  350. #define NIC_LB_NONE 0x00
  351. #define NIC_LB_INTERNAL 0x01
  352. #define NIC_LB_PHY 0x02 /* MII or Internal-10BaseT loopback */
  353. #define TX_RING_SIZE 2
  354. #define RX_RING_SIZE 2
  355. #define PKT_BUF_SZ 1536 /* Size of each temporary Rx buffer. */
  356. #define PCI_REG_MODE3 0x53
  357. #define MODE3_MIION 0x04 /* in PCI_REG_MOD3 OF PCI space */
  358. enum rhine_revs {
  359. VT86C100A = 0x00,
  360. VTunknown0 = 0x20,
  361. VT6102 = 0x40,
  362. VT8231 = 0x50, /* Integrated MAC */
  363. VT8233 = 0x60, /* Integrated MAC */
  364. VT8235 = 0x74, /* Integrated MAC */
  365. VT8237 = 0x78, /* Integrated MAC */
  366. VTunknown1 = 0x7C,
  367. VT6105 = 0x80,
  368. VT6105_B0 = 0x83,
  369. VT6105L = 0x8A,
  370. VT6107 = 0x8C,
  371. VTunknown2 = 0x8E,
  372. VT6105M = 0x90,
  373. };
  374. /* Transmit and receive descriptors definition */
  375. struct rhine_tx_desc
  376. {
  377. union VTC_tx_status_tag
  378. {
  379. struct
  380. {
  381. unsigned long ncro:1;
  382. unsigned long ncr1:1;
  383. unsigned long ncr2:1;
  384. unsigned long ncr3:1;
  385. unsigned long cols:1;
  386. unsigned long reserve_1:2;
  387. unsigned long cdh:1;
  388. unsigned long abt:1;
  389. unsigned long owc:1;
  390. unsigned long crs:1;
  391. unsigned long udf:1;
  392. unsigned long tbuff:1;
  393. unsigned long serr:1;
  394. unsigned long jab:1;
  395. unsigned long terr:1;
  396. unsigned long reserve_2:15;
  397. unsigned long own_bit:1;
  398. }
  399. bits;
  400. unsigned long lw;
  401. }
  402. tx_status;
  403. union VTC_tx_ctrl_tag
  404. {
  405. struct
  406. {
  407. unsigned long tx_buf_size:11;
  408. unsigned long extend_tx_buf_size:4;
  409. unsigned long chn:1;
  410. unsigned long crc:1;
  411. unsigned long reserve_1:4;
  412. unsigned long stp:1;
  413. unsigned long edp:1;
  414. unsigned long ic:1;
  415. unsigned long reserve_2:8;
  416. }
  417. bits;
  418. unsigned long lw;
  419. }
  420. tx_ctrl;
  421. unsigned long buf_addr_1:32;
  422. unsigned long buf_addr_2:32;
  423. };
  424. struct rhine_rx_desc
  425. {
  426. union VTC_rx_status_tag
  427. {
  428. struct
  429. {
  430. unsigned long rerr:1;
  431. unsigned long crc_error:1;
  432. unsigned long fae:1;
  433. unsigned long fov:1;
  434. unsigned long toolong:1;
  435. unsigned long runt:1;
  436. unsigned long serr:1;
  437. unsigned long buff:1;
  438. unsigned long edp:1;
  439. unsigned long stp:1;
  440. unsigned long chn:1;
  441. unsigned long phy:1;
  442. unsigned long bar:1;
  443. unsigned long mar:1;
  444. unsigned long reserve_1:1;
  445. unsigned long rxok:1;
  446. unsigned long frame_length:11;
  447. unsigned long reverve_2:4;
  448. unsigned long own_bit:1;
  449. }
  450. bits;
  451. unsigned long lw;
  452. }
  453. rx_status;
  454. union VTC_rx_ctrl_tag
  455. {
  456. struct
  457. {
  458. unsigned long rx_buf_size:11;
  459. unsigned long extend_rx_buf_size:4;
  460. unsigned long reserved_1:17;
  461. }
  462. bits;
  463. unsigned long lw;
  464. }
  465. rx_ctrl;
  466. unsigned long buf_addr_1:32;
  467. unsigned long buf_addr_2:32;
  468. };
  469. struct {
  470. char txbuf[TX_RING_SIZE * PKT_BUF_SZ + 32];
  471. char rxbuf[RX_RING_SIZE * PKT_BUF_SZ + 32];
  472. char txdesc[TX_RING_SIZE * sizeof (struct rhine_tx_desc) + 32];
  473. char rxdesc[RX_RING_SIZE * sizeof (struct rhine_rx_desc) + 32];
  474. } rhine_buffers __shared;
  475. /* The I/O extent. */
  476. #define rhine_TOTAL_SIZE 0x80
  477. #ifdef HAVE_DEVLIST
  478. struct netdev_entry rhine_drv =
  479. { "rhine", rhine_probe, rhine_TOTAL_SIZE, NULL };
  480. #endif
  481. static int rhine_debug = 1;
  482. /*
  483. Theory of Operation
  484. I. Board Compatibility
  485. This driver is designed for the VIA 86c100A Rhine-II PCI Fast Ethernet
  486. controller.
  487. II. Board-specific settings
  488. Boards with this chip are functional only in a bus-master PCI slot.
  489. Many operational settings are loaded from the EEPROM to the Config word at
  490. offset 0x78. This driver assumes that they are correct.
  491. If this driver is compiled to use PCI memory space operations the EEPROM
  492. must be configured to enable memory ops.
  493. III. Driver operation
  494. IIIa. Ring buffers
  495. This driver uses two statically allocated fixed-size descriptor lists
  496. formed into rings by a branch from the final descriptor to the beginning of
  497. the list. The ring sizes are set at compile time by RX/TX_RING_SIZE.
  498. IIIb/c. Transmit/Receive Structure
  499. This driver attempts to use a zero-copy receive and transmit scheme.
  500. Alas, all data buffers are required to start on a 32 bit boundary, so
  501. the driver must often copy transmit packets into bounce buffers.
  502. The driver allocates full frame size skbuffs for the Rx ring buffers at
  503. open() time and passes the skb->data field to the chip as receive data
  504. buffers. When an incoming frame is less than RX_COPYBREAK bytes long,
  505. a fresh skbuff is allocated and the frame is copied to the new skbuff.
  506. When the incoming frame is larger, the skbuff is passed directly up the
  507. protocol stack. Buffers consumed this way are replaced by newly allocated
  508. skbuffs in the last phase of netdev_rx().
  509. The RX_COPYBREAK value is chosen to trade-off the memory wasted by
  510. using a full-sized skbuff for small frames vs. the copying costs of larger
  511. frames. New boards are typically used in generously configured machines
  512. and the underfilled buffers have negligible impact compared to the benefit of
  513. a single allocation size, so the default value of zero results in never
  514. copying packets. When copying is done, the cost is usually mitigated by using
  515. a combined copy/checksum routine. Copying also preloads the cache, which is
  516. most useful with small frames.
  517. Since the VIA chips are only able to transfer data to buffers on 32 bit
  518. boundaries, the the IP header at offset 14 in an ethernet frame isn't
  519. longword aligned for further processing. Copying these unaligned buffers
  520. has the beneficial effect of 16-byte aligning the IP header.
  521. IIId. Synchronization
  522. The driver runs as two independent, single-threaded flows of control. One
  523. is the send-packet routine, which enforces single-threaded use by the
  524. dev->tbusy flag. The other thread is the interrupt handler, which is single
  525. threaded by the hardware and interrupt handling software.
  526. The send packet thread has partial control over the Tx ring and 'dev->tbusy'
  527. flag. It sets the tbusy flag whenever it's queuing a Tx packet. If the next
  528. queue slot is empty, it clears the tbusy flag when finished otherwise it sets
  529. the 'lp->tx_full' flag.
  530. The interrupt handler has exclusive control over the Rx ring and records stats
  531. from the Tx ring. After reaping the stats, it marks the Tx queue entry as
  532. empty by incrementing the dirty_tx mark. Iff the 'lp->tx_full' flag is set, it
  533. clears both the tx_full and tbusy flags.
  534. IV. Notes
  535. IVb. References
  536. Preliminary VT86C100A manual from http://www.via.com.tw/
  537. http://cesdis.gsfc.nasa.gov/linux/misc/100mbps.html
  538. http://cesdis.gsfc.nasa.gov/linux/misc/NWay.html
  539. IVc. Errata
  540. The VT86C100A manual is not reliable information.
  541. The chip does not handle unaligned transmit or receive buffers, resulting
  542. in significant performance degradation for bounce buffer copies on transmit
  543. and unaligned IP headers on receive.
  544. The chip does not pad to minimum transmit length.
  545. */
  546. /* The rest of these values should never change. */
  547. #define NUM_TX_DESC 2 /* Number of Tx descriptor registers. */
  548. static struct rhine_private
  549. {
  550. char devname[8]; /* Used only for kernel debugging. */
  551. const char *product_name;
  552. struct rhine_rx_desc *rx_ring;
  553. struct rhine_tx_desc *tx_ring;
  554. char *rx_buffs[RX_RING_SIZE];
  555. char *tx_buffs[TX_RING_SIZE];
  556. /* temporary Rx buffers. */
  557. int chip_id;
  558. int chip_revision;
  559. unsigned short ioaddr;
  560. unsigned int cur_rx, cur_tx; /* The next free and used entries */
  561. unsigned int dirty_rx, dirty_tx;
  562. /* The saved address of a sent-in-place packet/buffer, for skfree(). */
  563. struct sk_buff *tx_skbuff[TX_RING_SIZE];
  564. unsigned char mc_filter[8]; /* Current multicast filter. */
  565. char phys[4]; /* MII device addresses. */
  566. unsigned int tx_full:1; /* The Tx queue is full. */
  567. unsigned int full_duplex:1; /* Full-duplex operation requested. */
  568. unsigned int default_port:4; /* Last dev->if_port value. */
  569. unsigned int media2:4; /* Secondary monitored media port. */
  570. unsigned int medialock:1; /* Don't sense media type. */
  571. unsigned int mediasense:1; /* Media sensing in progress. */
  572. }
  573. rhine;
  574. static void rhine_probe1 (struct nic *nic, struct pci_device *pci, int ioaddr,
  575. int chip_id, int options);
  576. static int QueryAuto (int);
  577. static int ReadMII (int byMIIIndex, int);
  578. static void WriteMII (char, char, char, int);
  579. static void MIIDelay (void);
  580. static void rhine_init_ring (struct nic *dev);
  581. static void rhine_disable (struct nic *nic);
  582. static void rhine_reset (struct nic *nic);
  583. static int rhine_poll (struct nic *nic, int retreive);
  584. static void rhine_transmit (struct nic *nic, const char *d, unsigned int t,
  585. unsigned int s, const char *p);
  586. static void reload_eeprom(int ioaddr);
  587. static void reload_eeprom(int ioaddr)
  588. {
  589. int i;
  590. outb(0x20, byEECSR);
  591. /* Typically 2 cycles to reload. */
  592. for (i = 0; i < 150; i++)
  593. if (! (inb(byEECSR) & 0x20))
  594. break;
  595. }
  596. /* Initialize the Rx and Tx rings, along with various 'dev' bits. */
  597. static void
  598. rhine_init_ring (struct nic *nic)
  599. {
  600. struct rhine_private *tp = (struct rhine_private *) nic->priv_data;
  601. int i;
  602. tp->tx_full = 0;
  603. tp->cur_rx = tp->cur_tx = 0;
  604. tp->dirty_rx = tp->dirty_tx = 0;
  605. for (i = 0; i < RX_RING_SIZE; i++)
  606. {
  607. tp->rx_ring[i].rx_status.bits.own_bit = 1;
  608. tp->rx_ring[i].rx_ctrl.bits.rx_buf_size = 1536;
  609. tp->rx_ring[i].buf_addr_1 = virt_to_bus (tp->rx_buffs[i]);
  610. tp->rx_ring[i].buf_addr_2 = virt_to_bus (&tp->rx_ring[i + 1]);
  611. /* printf("[%d]buf1=%hX,buf2=%hX",i,tp->rx_ring[i].buf_addr_1,tp->rx_ring[i].buf_addr_2); */
  612. }
  613. /* Mark the last entry as wrapping the ring. */
  614. /* tp->rx_ring[i-1].rx_ctrl.bits.rx_buf_size =1518; */
  615. tp->rx_ring[i - 1].buf_addr_2 = virt_to_bus (&tp->rx_ring[0]);
  616. /*printf("[%d]buf1=%hX,buf2=%hX",i-1,tp->rx_ring[i-1].buf_addr_1,tp->rx_ring[i-1].buf_addr_2); */
  617. /* The Tx buffer descriptor is filled in as needed, but we
  618. do need to clear the ownership bit. */
  619. for (i = 0; i < TX_RING_SIZE; i++)
  620. {
  621. tp->tx_ring[i].tx_status.lw = 0;
  622. tp->tx_ring[i].tx_ctrl.lw = 0x00e08000;
  623. tp->tx_ring[i].buf_addr_1 = virt_to_bus (tp->tx_buffs[i]);
  624. tp->tx_ring[i].buf_addr_2 = virt_to_bus (&tp->tx_ring[i + 1]);
  625. /* printf("[%d]buf1=%hX,buf2=%hX",i,tp->tx_ring[i].buf_addr_1,tp->tx_ring[i].buf_addr_2); */
  626. }
  627. tp->tx_ring[i - 1].buf_addr_2 = virt_to_bus (&tp->tx_ring[0]);
  628. /* printf("[%d]buf1=%hX,buf2=%hX",i,tp->tx_ring[i-1].buf_addr_1,tp->tx_ring[i-1].buf_addr_2); */
  629. }
  630. int
  631. QueryAuto (int ioaddr)
  632. {
  633. int byMIIIndex;
  634. int MIIReturn;
  635. int advertising,mii_reg5;
  636. int negociated;
  637. byMIIIndex = 0x04;
  638. MIIReturn = ReadMII (byMIIIndex, ioaddr);
  639. advertising=MIIReturn;
  640. byMIIIndex = 0x05;
  641. MIIReturn = ReadMII (byMIIIndex, ioaddr);
  642. mii_reg5=MIIReturn;
  643. negociated=mii_reg5 & advertising;
  644. if ( (negociated & 0x100) || (negociated & 0x1C0) == 0x40 )
  645. return 1;
  646. else
  647. return 0;
  648. }
  649. int
  650. ReadMII (int byMIIIndex, int ioaddr)
  651. {
  652. int ReturnMII;
  653. char byMIIAdrbak;
  654. char byMIICRbak;
  655. char byMIItemp;
  656. unsigned long ct;
  657. byMIIAdrbak = inb (byMIIAD);
  658. byMIICRbak = inb (byMIICR);
  659. outb (byMIICRbak & 0x7f, byMIICR);
  660. MIIDelay ();
  661. outb (byMIIIndex, byMIIAD);
  662. MIIDelay ();
  663. outb (inb (byMIICR) | 0x40, byMIICR);
  664. byMIItemp = inb (byMIICR);
  665. byMIItemp = byMIItemp & 0x40;
  666. ct = currticks();
  667. while (byMIItemp != 0 && ct + 2*1000 < currticks())
  668. {
  669. byMIItemp = inb (byMIICR);
  670. byMIItemp = byMIItemp & 0x40;
  671. }
  672. MIIDelay ();
  673. ReturnMII = inw (wMIIDATA);
  674. outb (byMIIAdrbak, byMIIAD);
  675. outb (byMIICRbak, byMIICR);
  676. MIIDelay ();
  677. return (ReturnMII);
  678. }
  679. void
  680. WriteMII (char byMIISetByte, char byMIISetBit, char byMIIOP, int ioaddr)
  681. {
  682. int ReadMIItmp;
  683. int MIIMask;
  684. char byMIIAdrbak;
  685. char byMIICRbak;
  686. char byMIItemp;
  687. unsigned long ct;
  688. byMIIAdrbak = inb (byMIIAD);
  689. byMIICRbak = inb (byMIICR);
  690. outb (byMIICRbak & 0x7f, byMIICR);
  691. MIIDelay ();
  692. outb (byMIISetByte, byMIIAD);
  693. MIIDelay ();
  694. outb (inb (byMIICR) | 0x40, byMIICR);
  695. byMIItemp = inb (byMIICR);
  696. byMIItemp = byMIItemp & 0x40;
  697. ct = currticks();
  698. while (byMIItemp != 0 && ct + 2*1000 < currticks())
  699. {
  700. byMIItemp = inb (byMIICR);
  701. byMIItemp = byMIItemp & 0x40;
  702. }
  703. MIIDelay ();
  704. ReadMIItmp = inw (wMIIDATA);
  705. MIIMask = 0x0001;
  706. MIIMask = MIIMask << byMIISetBit;
  707. if (byMIIOP == 0)
  708. {
  709. MIIMask = ~MIIMask;
  710. ReadMIItmp = ReadMIItmp & MIIMask;
  711. }
  712. else
  713. {
  714. ReadMIItmp = ReadMIItmp | MIIMask;
  715. }
  716. outw (ReadMIItmp, wMIIDATA);
  717. MIIDelay ();
  718. outb (inb (byMIICR) | 0x20, byMIICR);
  719. byMIItemp = inb (byMIICR);
  720. byMIItemp = byMIItemp & 0x20;
  721. ct = currticks();
  722. while (byMIItemp != 0 && ct + 2*1000 < currticks())
  723. {
  724. byMIItemp = inb (byMIICR);
  725. byMIItemp = byMIItemp & 0x20;
  726. }
  727. MIIDelay ();
  728. outb (byMIIAdrbak & 0x7f, byMIIAD);
  729. outb (byMIICRbak, byMIICR);
  730. MIIDelay ();
  731. }
  732. void
  733. MIIDelay (void)
  734. {
  735. int i;
  736. for (i = 0; i < 0x7fff; i++)
  737. {
  738. ( void ) inb (0x61);
  739. ( void ) inb (0x61);
  740. ( void ) inb (0x61);
  741. ( void ) inb (0x61);
  742. }
  743. }
  744. /* Offsets to the device registers. */
  745. enum register_offsets {
  746. StationAddr=0x00, RxConfig=0x06, TxConfig=0x07, ChipCmd=0x08,
  747. IntrStatus=0x0C, IntrEnable=0x0E,
  748. MulticastFilter0=0x10, MulticastFilter1=0x14,
  749. RxRingPtr=0x18, TxRingPtr=0x1C, GFIFOTest=0x54,
  750. MIIPhyAddr=0x6C, MIIStatus=0x6D, PCIBusConfig=0x6E,
  751. MIICmd=0x70, MIIRegAddr=0x71, MIIData=0x72, MACRegEEcsr=0x74,
  752. ConfigA=0x78, ConfigB=0x79, ConfigC=0x7A, ConfigD=0x7B,
  753. RxMissed=0x7C, RxCRCErrs=0x7E, MiscCmd=0x81,
  754. StickyHW=0x83, IntrStatus2=0x84, WOLcrClr=0xA4, WOLcgClr=0xA7,
  755. PwrcsrClr=0xAC,
  756. };
  757. /* Bits in the interrupt status/mask registers. */
  758. enum intr_status_bits {
  759. IntrRxDone=0x0001, IntrRxErr=0x0004, IntrRxEmpty=0x0020,
  760. IntrTxDone=0x0002, IntrTxError=0x0008, IntrTxUnderrun=0x0210,
  761. IntrPCIErr=0x0040,
  762. IntrStatsMax=0x0080, IntrRxEarly=0x0100,
  763. IntrRxOverflow=0x0400, IntrRxDropped=0x0800, IntrRxNoBuf=0x1000,
  764. IntrTxAborted=0x2000, IntrLinkChange=0x4000,
  765. IntrRxWakeUp=0x8000,
  766. IntrNormalSummary=0x0003, IntrAbnormalSummary=0xC260,
  767. IntrTxDescRace=0x080000, /* mapped from IntrStatus2 */
  768. IntrTxErrSummary=0x082218,
  769. };
  770. #define DEFAULT_INTR (IntrRxDone | IntrRxErr | IntrRxEmpty| IntrRxOverflow | \
  771. IntrRxDropped | IntrRxNoBuf)
  772. /***************************************************************************
  773. IRQ - PXE IRQ Handler
  774. ***************************************************************************/
  775. void rhine_irq ( struct nic *nic, irq_action_t action ) {
  776. struct rhine_private *tp = (struct rhine_private *) nic->priv_data;
  777. /* Enable interrupts by setting the interrupt mask. */
  778. unsigned int intr_status;
  779. switch ( action ) {
  780. case DISABLE :
  781. case ENABLE :
  782. intr_status = inw(nic->ioaddr + IntrStatus);
  783. /* On Rhine-II, Bit 3 indicates Tx descriptor write-back race. */
  784. /* added comment by guard */
  785. /* For supporting VT6107, please use revision id to recognize different chips in driver */
  786. // if (tp->chip_id == 0x3065)
  787. if( tp->chip_revision < 0x80 && tp->chip_revision >=0x40 )
  788. intr_status |= inb(nic->ioaddr + IntrStatus2) << 16;
  789. intr_status = (intr_status & ~DEFAULT_INTR);
  790. if ( action == ENABLE )
  791. intr_status = intr_status | DEFAULT_INTR;
  792. outw(intr_status, nic->ioaddr + IntrEnable);
  793. break;
  794. case FORCE :
  795. outw(0x0010, nic->ioaddr + 0x84);
  796. break;
  797. }
  798. }
  799. static struct nic_operations rhine_operations;
  800. static int
  801. rhine_probe ( struct nic *nic, struct pci_device *pci ) {
  802. struct rhine_private *tp = (struct rhine_private *) nic->priv_data;
  803. if (!pci->ioaddr)
  804. return 0;
  805. rhine_probe1 (nic, pci, pci->ioaddr, pci->device, -1);
  806. adjust_pci_device ( pci );
  807. rhine_reset (nic);
  808. nic->nic_op = &rhine_operations;
  809. nic->irqno = pci->irq;
  810. nic->ioaddr = tp->ioaddr;
  811. return 1;
  812. }
  813. static void set_rx_mode(struct nic *nic __unused) {
  814. struct rhine_private *tp = (struct rhine_private *) nic->priv_data;
  815. unsigned char rx_mode;
  816. int ioaddr = tp->ioaddr;
  817. /* ! IFF_PROMISC */
  818. outl(0xffffffff, byMAR0);
  819. outl(0xffffffff, byMAR4);
  820. rx_mode = 0x0C;
  821. outb(0x60 /* thresh */ | rx_mode, byRCR );
  822. }
  823. static void
  824. rhine_probe1 (struct nic *nic, struct pci_device *pci, int ioaddr, int chip_id, int options)
  825. {
  826. struct rhine_private *tp;
  827. static int did_version = 0; /* Already printed version info. */
  828. unsigned int i, ww;
  829. unsigned int timeout;
  830. int FDXFlag;
  831. int byMIIvalue, LineSpeed, MIICRbak;
  832. uint8_t revision_id;
  833. unsigned char mode3_reg;
  834. if (rhine_debug > 0 && did_version++ == 0)
  835. printf ("%s",version);
  836. // get revision id.
  837. pci_read_config_byte(pci, PCI_REVISION, &revision_id);
  838. /* D-Link provided reset code (with comment additions) */
  839. if (revision_id >= 0x40) {
  840. unsigned char byOrgValue;
  841. if(rhine_debug > 0)
  842. printf("Enabling Sticky Bit Workaround for Chip_id: 0x%hX\n"
  843. , chip_id);
  844. /* clear sticky bit before reset & read ethernet address */
  845. byOrgValue = inb(bySTICKHW);
  846. byOrgValue = byOrgValue & 0xFC;
  847. outb(byOrgValue, bySTICKHW);
  848. /* (bits written are cleared?) */
  849. /* disable force PME-enable */
  850. outb(0x80, byWOLcgClr);
  851. /* disable power-event config bit */
  852. outb(0xFF, byWOLcrClr);
  853. /* clear power status (undocumented in vt6102 docs?) */
  854. outb(0xFF, byPwrcsrClr);
  855. }
  856. /* Reset the chip to erase previous misconfiguration. */
  857. outw(CR_SFRST, byCR0);
  858. // if vt3043 delay after reset
  859. if (revision_id <0x40) {
  860. udelay(10000);
  861. }
  862. // polling till software reset complete
  863. // W_MAX_TIMEOUT is the timeout period
  864. for(ww = 0; ww < W_MAX_TIMEOUT; ww++) {
  865. if ((inw(byCR0) & CR_SFRST) == 0)
  866. break;
  867. }
  868. // issue AUTOLoad in EECSR to reload eeprom
  869. outb(0x20, byEECSR );
  870. // if vt3065 delay after reset
  871. if (revision_id >=0x40) {
  872. // delay 8ms to let MAC stable
  873. mdelay(8);
  874. /*
  875. * for 3065D, EEPROM reloaded will cause bit 0 in MAC_REG_CFGA
  876. * turned on. it makes MAC receive magic packet
  877. * automatically. So, we turn it off. (D-Link)
  878. */
  879. outb(inb(byCFGA) & 0xFE, byCFGA);
  880. }
  881. /* turn on bit2 in PCI configuration register 0x53 , only for 3065*/
  882. if (revision_id >= 0x40) {
  883. pci_read_config_byte(pci, PCI_REG_MODE3, &mode3_reg);
  884. pci_write_config_byte(pci, PCI_REG_MODE3, mode3_reg|MODE3_MIION);
  885. }
  886. /* back off algorithm ,disable the right-most 4-bit off CFGD*/
  887. outb(inb(byCFGD) & (~(CFGD_RANDOM | CFGD_CFDX | CFGD_CEREN | CFGD_CETEN)), byCFGD);
  888. /* reload eeprom */
  889. reload_eeprom(ioaddr);
  890. /* Perhaps this should be read from the EEPROM? */
  891. for (i = 0; i < ETH_ALEN; i++)
  892. nic->node_addr[i] = inb (byPAR0 + i);
  893. DBG ( "IO address %#hX Ethernet Address: %s\n", ioaddr, eth_ntoa ( nic->node_addr ) );
  894. /* restart MII auto-negotiation */
  895. WriteMII (0, 9, 1, ioaddr);
  896. printf ("Analyzing Media type,this may take several seconds... ");
  897. for (i = 0; i < 5; i++)
  898. {
  899. /* need to wait 1 millisecond - we will round it up to 50-100ms */
  900. timeout = currticks() + 2;
  901. for (timeout = currticks() + 2; currticks() < timeout;)
  902. /* nothing */;
  903. if (ReadMII (1, ioaddr) & 0x0020)
  904. break;
  905. }
  906. printf ("OK.\n");
  907. #if 0
  908. /* JJM : for Debug */
  909. printf("MII : Address %hhX ",inb(ioaddr+0x6c));
  910. {
  911. unsigned char st1,st2,adv1,adv2,l1,l2;
  912. st1=ReadMII(1,ioaddr)>>8;
  913. st2=ReadMII(1,ioaddr)&0xFF;
  914. adv1=ReadMII(4,ioaddr)>>8;
  915. adv2=ReadMII(4,ioaddr)&0xFF;
  916. l1=ReadMII(5,ioaddr)>>8;
  917. l2=ReadMII(5,ioaddr)&0xFF;
  918. printf(" status 0x%hhX%hhX, advertising 0x%hhX%hhX, link 0x%hhX%hhX\n", st1,st2,adv1,adv2,l1,l2);
  919. }
  920. #endif
  921. /* query MII to know LineSpeed,duplex mode */
  922. byMIIvalue = inb (ioaddr + 0x6d);
  923. LineSpeed = byMIIvalue & MIISR_SPEED;
  924. if (LineSpeed != 0) //JJM
  925. {
  926. printf ("Linespeed=10Mbs");
  927. }
  928. else
  929. {
  930. printf ("Linespeed=100Mbs");
  931. }
  932. FDXFlag = QueryAuto (ioaddr);
  933. if (FDXFlag == 1)
  934. {
  935. printf (" Fullduplex\n");
  936. outw (CR_FDX, byCR0);
  937. }
  938. else
  939. {
  940. printf (" Halfduplex\n");
  941. }
  942. /* set MII 10 FULL ON, only apply in vt3043 */
  943. if(chip_id == 0x3043)
  944. WriteMII (0x17, 1, 1, ioaddr);
  945. /* turn on MII link change */
  946. MIICRbak = inb (byMIICR);
  947. outb (MIICRbak & 0x7F, byMIICR);
  948. MIIDelay ();
  949. outb (0x41, byMIIAD);
  950. MIIDelay ();
  951. /* while((inb(byMIIAD)&0x20)==0) ; */
  952. outb (MIICRbak | 0x80, byMIICR);
  953. nic->priv_data = &rhine;
  954. tp = &rhine;
  955. tp->chip_id = chip_id;
  956. tp->ioaddr = ioaddr;
  957. tp->phys[0] = -1;
  958. tp->chip_revision = revision_id;
  959. /* The lower four bits are the media type. */
  960. if (options > 0)
  961. {
  962. tp->full_duplex = (options & 16) ? 1 : 0;
  963. tp->default_port = options & 15;
  964. if (tp->default_port)
  965. tp->medialock = 1;
  966. }
  967. return;
  968. }
  969. static void
  970. rhine_disable ( struct nic *nic ) {
  971. struct rhine_private *tp = (struct rhine_private *) nic->priv_data;
  972. int ioaddr = tp->ioaddr;
  973. rhine_reset(nic);
  974. printf ("rhine disable\n");
  975. /* Switch to loopback mode to avoid hardware races. */
  976. outb(0x60 | 0x01, byTCR);
  977. /* Stop the chip's Tx and Rx processes. */
  978. outw(CR_STOP, byCR0);
  979. }
  980. /**************************************************************************
  981. ETH_RESET - Reset adapter
  982. ***************************************************************************/
  983. static void
  984. rhine_reset (struct nic *nic)
  985. {
  986. struct rhine_private *tp = (struct rhine_private *) nic->priv_data;
  987. int ioaddr = tp->ioaddr;
  988. int i, j;
  989. int FDXFlag, CRbak;
  990. void *rx_ring_tmp;
  991. void *tx_ring_tmp;
  992. void *rx_bufs_tmp;
  993. void *tx_bufs_tmp;
  994. unsigned long rx_ring_tmp1;
  995. unsigned long tx_ring_tmp1;
  996. unsigned long rx_bufs_tmp1;
  997. unsigned long tx_bufs_tmp1;
  998. /* printf ("rhine_reset\n"); */
  999. /* Soft reset the chip. */
  1000. /*outb(CmdReset, ioaddr + ChipCmd); */
  1001. tx_bufs_tmp = rhine_buffers.txbuf;
  1002. tx_ring_tmp = rhine_buffers.txdesc;
  1003. rx_bufs_tmp = rhine_buffers.rxbuf;
  1004. rx_ring_tmp = rhine_buffers.rxdesc;
  1005. /* tune RD TD 32 byte alignment */
  1006. rx_ring_tmp1 = virt_to_bus ( rx_ring_tmp );
  1007. j = (rx_ring_tmp1 + 32) & (~0x1f);
  1008. /* printf ("txring[%d]", j); */
  1009. tp->rx_ring = (struct rhine_rx_desc *) bus_to_virt (j);
  1010. tx_ring_tmp1 = virt_to_bus ( tx_ring_tmp );
  1011. j = (tx_ring_tmp1 + 32) & (~0x1f);
  1012. tp->tx_ring = (struct rhine_tx_desc *) bus_to_virt (j);
  1013. /* printf ("rxring[%X]", j); */
  1014. tx_bufs_tmp1 = virt_to_bus ( tx_bufs_tmp );
  1015. j = (int) (tx_bufs_tmp1 + 32) & (~0x1f);
  1016. tx_bufs_tmp = bus_to_virt (j);
  1017. /* printf ("txb[%X]", j); */
  1018. rx_bufs_tmp1 = virt_to_bus ( rx_bufs_tmp );
  1019. j = (int) (rx_bufs_tmp1 + 32) & (~0x1f);
  1020. rx_bufs_tmp = bus_to_virt (j);
  1021. /* printf ("rxb[%X][%X]", rx_bufs_tmp1, j); */
  1022. for (i = 0; i < RX_RING_SIZE; i++)
  1023. {
  1024. tp->rx_buffs[i] = (char *) rx_bufs_tmp;
  1025. /* printf("r[%X]",tp->rx_buffs[i]); */
  1026. rx_bufs_tmp += 1536;
  1027. }
  1028. for (i = 0; i < TX_RING_SIZE; i++)
  1029. {
  1030. tp->tx_buffs[i] = (char *) tx_bufs_tmp;
  1031. /* printf("t[%X]",tp->tx_buffs[i]); */
  1032. tx_bufs_tmp += 1536;
  1033. }
  1034. /* software reset */
  1035. outb (CR1_SFRST, byCR1);
  1036. MIIDelay ();
  1037. /* printf ("init ring"); */
  1038. rhine_init_ring (nic);
  1039. /*write TD RD Descriptor to MAC */
  1040. outl (virt_to_bus (tp->rx_ring), dwCurrentRxDescAddr);
  1041. outl (virt_to_bus (tp->tx_ring), dwCurrentTxDescAddr);
  1042. /* Setup Multicast */
  1043. set_rx_mode(nic);
  1044. /* set TCR RCR threshold to store and forward*/
  1045. outb (0x3e, byBCR0);
  1046. outb (0x38, byBCR1);
  1047. outb (0x2c, byRCR);
  1048. outb (0x60, byTCR);
  1049. /* Set Fulldupex */
  1050. FDXFlag = QueryAuto (ioaddr);
  1051. if (FDXFlag == 1)
  1052. {
  1053. outb (CFGD_CFDX, byCFGD);
  1054. outw (CR_FDX, byCR0);
  1055. }
  1056. /* KICK NIC to WORK */
  1057. CRbak = inw (byCR0);
  1058. CRbak = CRbak & 0xFFFB; /* not CR_STOP */
  1059. outw ((CRbak | CR_STRT | CR_TXON | CR_RXON | CR_DPOLL), byCR0);
  1060. /* disable all known interrupt */
  1061. outw (0, byIMR0);
  1062. }
  1063. /* Beware of PCI posted writes */
  1064. #define IOSYNC do { inb(nic->ioaddr + StationAddr); } while (0)
  1065. static int
  1066. rhine_poll (struct nic *nic, int retreive)
  1067. {
  1068. struct rhine_private *tp = (struct rhine_private *) nic->priv_data;
  1069. int rxstatus, good = 0;;
  1070. if (tp->rx_ring[tp->cur_rx].rx_status.bits.own_bit == 0)
  1071. {
  1072. unsigned int intr_status;
  1073. /* There is a packet ready */
  1074. if(!retreive)
  1075. return 1;
  1076. intr_status = inw(nic->ioaddr + IntrStatus);
  1077. /* On Rhine-II, Bit 3 indicates Tx descriptor write-back race. */
  1078. #if 0
  1079. if (tp->chip_id == 0x3065)
  1080. intr_status |= inb(nic->ioaddr + IntrStatus2) << 16;
  1081. #endif
  1082. /* Acknowledge all of the current interrupt sources ASAP. */
  1083. if (intr_status & IntrTxDescRace)
  1084. outb(0x08, nic->ioaddr + IntrStatus2);
  1085. outw(intr_status & 0xffff, nic->ioaddr + IntrStatus);
  1086. IOSYNC;
  1087. rxstatus = tp->rx_ring[tp->cur_rx].rx_status.lw;
  1088. if ((rxstatus & 0x0300) != 0x0300)
  1089. {
  1090. printf("rhine_poll: bad status\n");
  1091. }
  1092. else if (rxstatus & (RSR_ABNORMAL))
  1093. {
  1094. printf ("rxerr[%X]\n", rxstatus);
  1095. }
  1096. else
  1097. good = 1;
  1098. if (good)
  1099. {
  1100. nic->packetlen = tp->rx_ring[tp->cur_rx].rx_status.bits.frame_length;
  1101. memcpy (nic->packet, tp->rx_buffs[tp->cur_rx], nic->packetlen);
  1102. /* printf ("Packet RXed\n"); */
  1103. }
  1104. tp->rx_ring[tp->cur_rx].rx_status.bits.own_bit = 1;
  1105. tp->cur_rx++;
  1106. tp->cur_rx = tp->cur_rx % RX_RING_SIZE;
  1107. }
  1108. /* Acknowledge all of the current interrupt sources ASAP. */
  1109. outw(DEFAULT_INTR & ~IntrRxDone, nic->ioaddr + IntrStatus);
  1110. IOSYNC;
  1111. return good;
  1112. }
  1113. static void
  1114. rhine_transmit (struct nic *nic,
  1115. const char *d, unsigned int t, unsigned int s, const char *p)
  1116. {
  1117. struct rhine_private *tp = (struct rhine_private *) nic->priv_data;
  1118. int ioaddr = tp->ioaddr;
  1119. int entry;
  1120. unsigned char CR1bak;
  1121. unsigned char CR0bak;
  1122. unsigned int nstype;
  1123. unsigned long ct;
  1124. /*printf ("rhine_transmit\n"); */
  1125. /* setup ethernet header */
  1126. /* Calculate the next Tx descriptor entry. */
  1127. entry = tp->cur_tx % TX_RING_SIZE;
  1128. memcpy (tp->tx_buffs[entry], d, ETH_ALEN); /* dst */
  1129. memcpy (tp->tx_buffs[entry] + ETH_ALEN, nic->node_addr, ETH_ALEN); /* src */
  1130. nstype=htons(t);
  1131. memcpy(tp->tx_buffs[entry] + 2 * ETH_ALEN, (char*)&nstype, 2);
  1132. memcpy (tp->tx_buffs[entry] + ETH_HLEN, p, s);
  1133. s += ETH_HLEN;
  1134. while (s < ETH_ZLEN)
  1135. *((char *) tp->tx_buffs[entry] + (s++)) = 0;
  1136. tp->tx_ring[entry].tx_ctrl.bits.tx_buf_size = s;
  1137. tp->tx_ring[entry].tx_status.bits.own_bit = 1;
  1138. CR1bak = inb (byCR1);
  1139. CR1bak = CR1bak | CR1_TDMD1;
  1140. /*printf("tdsw=[%X]",tp->tx_ring[entry].tx_status.lw); */
  1141. /*printf("tdcw=[%X]",tp->tx_ring[entry].tx_ctrl.lw); */
  1142. /*printf("tdbuf1=[%X]",tp->tx_ring[entry].buf_addr_1); */
  1143. /*printf("tdbuf2=[%X]",tp->tx_ring[entry].buf_addr_2); */
  1144. /*printf("td1=[%X]",inl(dwCurrentTDSE0)); */
  1145. /*printf("td2=[%X]",inl(dwCurrentTDSE1)); */
  1146. /*printf("td3=[%X]",inl(dwCurrentTDSE2)); */
  1147. /*printf("td4=[%X]",inl(dwCurrentTDSE3)); */
  1148. outb (CR1bak, byCR1);
  1149. do
  1150. {
  1151. ct = currticks();
  1152. /* Wait until transmit is finished or timeout*/
  1153. while((tp->tx_ring[entry].tx_status.bits.own_bit !=0) &&
  1154. ct + 10*1000 < currticks())
  1155. ;
  1156. if(tp->tx_ring[entry].tx_status.bits.terr == 0)
  1157. break;
  1158. if(tp->tx_ring[entry].tx_status.bits.abt == 1)
  1159. {
  1160. // turn on TX
  1161. CR0bak = inb(byCR0);
  1162. CR0bak = CR0bak|CR_TXON;
  1163. outb(CR0bak,byCR0);
  1164. }
  1165. }while(0);
  1166. tp->cur_tx++;
  1167. /*outw(IMRShadow,byIMR0); */
  1168. /*dev_kfree_skb(tp->tx_skbuff[entry], FREE_WRITE); */
  1169. /*tp->tx_skbuff[entry] = 0; */
  1170. }
  1171. static struct nic_operations rhine_operations = {
  1172. .connect = dummy_connect,
  1173. .poll = rhine_poll,
  1174. .transmit = rhine_transmit,
  1175. .irq = rhine_irq,
  1176. };
  1177. static struct pci_device_id rhine_nics[] = {
  1178. PCI_ROM(0x1106, 0x3065, "dlink-530tx", "VIA 6102"),
  1179. PCI_ROM(0x1106, 0x3106, "via-rhine-6105", "VIA 6105"),
  1180. PCI_ROM(0x1106, 0x3043, "dlink-530tx-old", "VIA 3043"), /* Rhine-I 86c100a */
  1181. PCI_ROM(0x1106, 0x3053, "via6105m", "VIA 6105M"),
  1182. PCI_ROM(0x1106, 0x6100, "via-rhine-old", "VIA 86C100A"), /* Rhine-II */
  1183. };
  1184. PCI_DRIVER ( rhine_driver, rhine_nics, PCI_NO_CLASS );
  1185. DRIVER ( "VIA 86C100", nic_driver, pci_driver, rhine_driver,
  1186. rhine_probe, rhine_disable );
  1187. /* EOF via-rhine.c */
  1188. /*
  1189. * Local variables:
  1190. * c-basic-offset: 8
  1191. * c-indent-level: 8
  1192. * tab-width: 8
  1193. * End:
  1194. */