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-velocity.h 50KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938
  1. #define EB54 1
  2. /*
  3. * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
  4. * All rights reserved.
  5. *
  6. * This software may be redistributed and/or modified under
  7. * the terms of the GNU General Public License as published by the Free
  8. * Software Foundation; either version 2 of the License, or
  9. * any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  13. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  14. * for more details.
  15. *
  16. * File: via-velocity.h
  17. *
  18. * Purpose: Header file to define driver's private structures.
  19. *
  20. * Author: Chuang Liang-Shing, AJ Jiang
  21. *
  22. * Date: Jan 24, 2003
  23. *
  24. * Changes for Etherboot Port:
  25. * Copyright (c) 2006 by Timothy Legge <tlegge@rogers.com>
  26. */
  27. #include "timer.h"
  28. #ifndef EB54
  29. typedef unsigned char u8;
  30. typedef signed char s8;
  31. typedef unsigned short u16;
  32. typedef signed short s16;
  33. typedef unsigned int u32;
  34. typedef signed int s32;
  35. #endif
  36. #ifndef VELOCITY_H
  37. #define VELOCITY_H
  38. #define VELOCITY_TX_CSUM_SUPPORT
  39. #define VELOCITY_NAME "via-velocity"
  40. #define VELOCITY_FULL_DRV_NAM "VIA Networking Velocity Family Gigabit Ethernet Adapter Driver"
  41. #define VELOCITY_VERSION "1.13"
  42. #define PKT_BUF_SZ 1564
  43. #define MAX_UNITS 8
  44. #define OPTION_DEFAULT { [0 ... MAX_UNITS-1] = -1}
  45. #define REV_ID_VT6110 (0)
  46. #define BYTE_REG_BITS_ON(x,p) do { writeb(readb((p))|(x),(p));} while (0)
  47. #define WORD_REG_BITS_ON(x,p) do { writew(readw((p))|(x),(p));} while (0)
  48. #define DWORD_REG_BITS_ON(x,p) do { writel(readl((p))|(x),(p));} while (0)
  49. #define BYTE_REG_BITS_IS_ON(x,p) (readb((p)) & (x))
  50. #define WORD_REG_BITS_IS_ON(x,p) (readw((p)) & (x))
  51. #define DWORD_REG_BITS_IS_ON(x,p) (readl((p)) & (x))
  52. #define BYTE_REG_BITS_OFF(x,p) do { writeb(readb((p)) & (~(x)),(p));} while (0)
  53. #define WORD_REG_BITS_OFF(x,p) do { writew(readw((p)) & (~(x)),(p));} while (0)
  54. #define DWORD_REG_BITS_OFF(x,p) do { writel(readl((p)) & (~(x)),(p));} while (0)
  55. #define BYTE_REG_BITS_SET(x,m,p) do { writeb( (readb((p)) & (~(m))) |(x),(p));} while (0)
  56. #define WORD_REG_BITS_SET(x,m,p) do { writew( (readw((p)) & (~(m))) |(x),(p));} while (0)
  57. #define DWORD_REG_BITS_SET(x,m,p) do { writel( (readl((p)) & (~(m)))|(x),(p));} while (0)
  58. #define VAR_USED(p) do {(p)=(p);} while (0)
  59. /*
  60. * Purpose: Structures for MAX RX/TX descriptors.
  61. */
  62. #define B_OWNED_BY_CHIP 1
  63. #define B_OWNED_BY_HOST 0
  64. /*
  65. * Bits in the RSR0 register
  66. */
  67. #define RSR_DETAG 0x0080
  68. #define RSR_SNTAG 0x0040
  69. #define RSR_RXER 0x0020
  70. #define RSR_RL 0x0010
  71. #define RSR_CE 0x0008
  72. #define RSR_FAE 0x0004
  73. #define RSR_CRC 0x0002
  74. #define RSR_VIDM 0x0001
  75. /*
  76. * Bits in the RSR1 register
  77. */
  78. #define RSR_RXOK 0x8000 // rx OK
  79. #define RSR_PFT 0x4000 // Perfect filtering address match
  80. #define RSR_MAR 0x2000 // MAC accept multicast address packet
  81. #define RSR_BAR 0x1000 // MAC accept broadcast address packet
  82. #define RSR_PHY 0x0800 // MAC accept physical address packet
  83. #define RSR_VTAG 0x0400 // 802.1p/1q tagging packet indicator
  84. #define RSR_STP 0x0200 // start of packet
  85. #define RSR_EDP 0x0100 // end of packet
  86. /*
  87. * Bits in the RSR1 register
  88. */
  89. #define RSR1_RXOK 0x80 // rx OK
  90. #define RSR1_PFT 0x40 // Perfect filtering address match
  91. #define RSR1_MAR 0x20 // MAC accept multicast address packet
  92. #define RSR1_BAR 0x10 // MAC accept broadcast address packet
  93. #define RSR1_PHY 0x08 // MAC accept physical address packet
  94. #define RSR1_VTAG 0x04 // 802.1p/1q tagging packet indicator
  95. #define RSR1_STP 0x02 // start of packet
  96. #define RSR1_EDP 0x01 // end of packet
  97. /*
  98. * Bits in the CSM register
  99. */
  100. #define CSM_IPOK 0x40 //IP Checkusm validatiaon ok
  101. #define CSM_TUPOK 0x20 //TCP/UDP Checkusm validatiaon ok
  102. #define CSM_FRAG 0x10 //Fragment IP datagram
  103. #define CSM_IPKT 0x04 //Received an IP packet
  104. #define CSM_TCPKT 0x02 //Received a TCP packet
  105. #define CSM_UDPKT 0x01 //Received a UDP packet
  106. /*
  107. * Bits in the TSR0 register
  108. */
  109. #define TSR0_ABT 0x0080 // Tx abort because of excessive collision
  110. #define TSR0_OWT 0x0040 // Jumbo frame Tx abort
  111. #define TSR0_OWC 0x0020 // Out of window collision
  112. #define TSR0_COLS 0x0010 // experience collision in this transmit event
  113. #define TSR0_NCR3 0x0008 // collision retry counter[3]
  114. #define TSR0_NCR2 0x0004 // collision retry counter[2]
  115. #define TSR0_NCR1 0x0002 // collision retry counter[1]
  116. #define TSR0_NCR0 0x0001 // collision retry counter[0]
  117. #define TSR0_TERR 0x8000 //
  118. #define TSR0_FDX 0x4000 // current transaction is serviced by full duplex mode
  119. #define TSR0_GMII 0x2000 // current transaction is serviced by GMII mode
  120. #define TSR0_LNKFL 0x1000 // packet serviced during link down
  121. #define TSR0_SHDN 0x0400 // shutdown case
  122. #define TSR0_CRS 0x0200 // carrier sense lost
  123. #define TSR0_CDH 0x0100 // AQE test fail (CD heartbeat)
  124. /*
  125. * Bits in the TSR1 register
  126. */
  127. #define TSR1_TERR 0x80 //
  128. #define TSR1_FDX 0x40 // current transaction is serviced by full duplex mode
  129. #define TSR1_GMII 0x20 // current transaction is serviced by GMII mode
  130. #define TSR1_LNKFL 0x10 // packet serviced during link down
  131. #define TSR1_SHDN 0x04 // shutdown case
  132. #define TSR1_CRS 0x02 // carrier sense lost
  133. #define TSR1_CDH 0x01 // AQE test fail (CD heartbeat)
  134. //
  135. // Bits in the TCR0 register
  136. //
  137. #define TCR0_TIC 0x80 // assert interrupt immediately while descriptor has been send complete
  138. #define TCR0_PIC 0x40 // priority interrupt request, INA# is issued over adaptive interrupt scheme
  139. #define TCR0_VETAG 0x20 // enable VLAN tag
  140. #define TCR0_IPCK 0x10 // request IP checksum calculation.
  141. #define TCR0_UDPCK 0x08 // request UDP checksum calculation.
  142. #define TCR0_TCPCK 0x04 // request TCP checksum calculation.
  143. #define TCR0_JMBO 0x02 // indicate a jumbo packet in GMAC side
  144. #define TCR0_CRC 0x01 // disable CRC generation
  145. #define TCPLS_NORMAL 3
  146. #define TCPLS_START 2
  147. #define TCPLS_END 1
  148. #define TCPLS_MED 0
  149. // max transmit or receive buffer size
  150. #define CB_RX_BUF_SIZE 2048UL // max buffer size
  151. // NOTE: must be multiple of 4
  152. #define CB_MAX_RD_NUM 512 // MAX # of RD
  153. #define CB_MAX_TD_NUM 256 // MAX # of TD
  154. #define CB_INIT_RD_NUM_3119 128 // init # of RD, for setup VT3119
  155. #define CB_INIT_TD_NUM_3119 64 // init # of TD, for setup VT3119
  156. #define CB_INIT_RD_NUM 128 // init # of RD, for setup default
  157. #define CB_INIT_TD_NUM 64 // init # of TD, for setup default
  158. // for 3119
  159. #define CB_TD_RING_NUM 4 // # of TD rings.
  160. #define CB_MAX_SEG_PER_PKT 7 // max data seg per packet (Tx)
  161. /*
  162. * If collisions excess 15 times , tx will abort, and
  163. * if tx fifo underflow, tx will fail
  164. * we should try to resend it
  165. */
  166. #define CB_MAX_TX_ABORT_RETRY 3
  167. /*
  168. * Receive descriptor
  169. */
  170. struct rdesc0 {
  171. u16 RSR; /* Receive status */
  172. u16 len:14; /* Received packet length */
  173. u16 reserved:1;
  174. u16 owner:1; /* Who owns this buffer ? */
  175. };
  176. struct rdesc1 {
  177. u16 PQTAG;
  178. u8 CSM;
  179. u8 IPKT;
  180. };
  181. struct rx_desc {
  182. struct rdesc0 rdesc0;
  183. struct rdesc1 rdesc1;
  184. u32 pa_low; /* Low 32 bit PCI address */
  185. u16 pa_high; /* Next 16 bit PCI address (48 total) */
  186. u16 len:15; /* Frame size */
  187. u16 inten:1; /* Enable interrupt */
  188. } __attribute__ ((__packed__));
  189. /*
  190. * Transmit descriptor
  191. */
  192. struct tdesc0 {
  193. u16 TSR; /* Transmit status register */
  194. u16 pktsize:14; /* Size of frame */
  195. u16 reserved:1;
  196. u16 owner:1; /* Who owns the buffer */
  197. };
  198. struct pqinf { /* Priority queue info */
  199. u16 VID:12;
  200. u16 CFI:1;
  201. u16 priority:3;
  202. } __attribute__ ((__packed__));
  203. struct tdesc1 {
  204. struct pqinf pqinf;
  205. u8 TCR;
  206. u8 TCPLS:2;
  207. u8 reserved:2;
  208. u8 CMDZ:4;
  209. } __attribute__ ((__packed__));
  210. struct td_buf {
  211. u32 pa_low;
  212. u16 pa_high;
  213. u16 bufsize:14;
  214. u16 reserved:1;
  215. u16 queue:1;
  216. } __attribute__ ((__packed__));
  217. struct tx_desc {
  218. struct tdesc0 tdesc0;
  219. struct tdesc1 tdesc1;
  220. struct td_buf td_buf[7];
  221. };
  222. #ifdef LINUX
  223. struct velocity_rd_info {
  224. struct sk_buff *skb;
  225. dma_addr_t skb_dma;
  226. };
  227. /**
  228. * alloc_rd_info - allocate an rd info block
  229. *
  230. * Alocate and initialize a receive info structure used for keeping
  231. * track of kernel side information related to each receive
  232. * descriptor we are using
  233. */
  234. static inline struct velocity_rd_info *alloc_rd_info(void)
  235. {
  236. struct velocity_rd_info *ptr;
  237. if ((ptr =
  238. kmalloc(sizeof(struct velocity_rd_info), GFP_ATOMIC)) == NULL)
  239. return NULL;
  240. else {
  241. memset(ptr, 0, sizeof(struct velocity_rd_info));
  242. return ptr;
  243. }
  244. }
  245. /*
  246. * Used to track transmit side buffers.
  247. */
  248. struct velocity_td_info {
  249. struct sk_buff *skb;
  250. u8 *buf;
  251. int nskb_dma;
  252. dma_addr_t skb_dma[7];
  253. dma_addr_t buf_dma;
  254. };
  255. #endif
  256. enum {
  257. OWNED_BY_HOST = 0,
  258. OWNED_BY_NIC = 1
  259. } velocity_owner;
  260. /*
  261. * MAC registers and macros.
  262. */
  263. #define MCAM_SIZE 64
  264. #define VCAM_SIZE 64
  265. #define TX_QUEUE_NO 4
  266. #define MAX_HW_MIB_COUNTER 32
  267. #define VELOCITY_MIN_MTU (1514-14)
  268. #define VELOCITY_MAX_MTU (9000)
  269. /*
  270. * Registers in the MAC
  271. */
  272. #define MAC_REG_PAR 0x00 // physical address
  273. #define MAC_REG_RCR 0x06
  274. #define MAC_REG_TCR 0x07
  275. #define MAC_REG_CR0_SET 0x08
  276. #define MAC_REG_CR1_SET 0x09
  277. #define MAC_REG_CR2_SET 0x0A
  278. #define MAC_REG_CR3_SET 0x0B
  279. #define MAC_REG_CR0_CLR 0x0C
  280. #define MAC_REG_CR1_CLR 0x0D
  281. #define MAC_REG_CR2_CLR 0x0E
  282. #define MAC_REG_CR3_CLR 0x0F
  283. #define MAC_REG_MAR 0x10
  284. #define MAC_REG_CAM 0x10
  285. #define MAC_REG_DEC_BASE_HI 0x18
  286. #define MAC_REG_DBF_BASE_HI 0x1C
  287. #define MAC_REG_ISR_CTL 0x20
  288. #define MAC_REG_ISR_HOTMR 0x20
  289. #define MAC_REG_ISR_TSUPTHR 0x20
  290. #define MAC_REG_ISR_RSUPTHR 0x20
  291. #define MAC_REG_ISR_CTL1 0x21
  292. #define MAC_REG_TXE_SR 0x22
  293. #define MAC_REG_RXE_SR 0x23
  294. #define MAC_REG_ISR 0x24
  295. #define MAC_REG_ISR0 0x24
  296. #define MAC_REG_ISR1 0x25
  297. #define MAC_REG_ISR2 0x26
  298. #define MAC_REG_ISR3 0x27
  299. #define MAC_REG_IMR 0x28
  300. #define MAC_REG_IMR0 0x28
  301. #define MAC_REG_IMR1 0x29
  302. #define MAC_REG_IMR2 0x2A
  303. #define MAC_REG_IMR3 0x2B
  304. #define MAC_REG_TDCSR_SET 0x30
  305. #define MAC_REG_RDCSR_SET 0x32
  306. #define MAC_REG_TDCSR_CLR 0x34
  307. #define MAC_REG_RDCSR_CLR 0x36
  308. #define MAC_REG_RDBASE_LO 0x38
  309. #define MAC_REG_RDINDX 0x3C
  310. #define MAC_REG_TDBASE_LO 0x40
  311. #define MAC_REG_RDCSIZE 0x50
  312. #define MAC_REG_TDCSIZE 0x52
  313. #define MAC_REG_TDINDX 0x54
  314. #define MAC_REG_TDIDX0 0x54
  315. #define MAC_REG_TDIDX1 0x56
  316. #define MAC_REG_TDIDX2 0x58
  317. #define MAC_REG_TDIDX3 0x5A
  318. #define MAC_REG_PAUSE_TIMER 0x5C
  319. #define MAC_REG_RBRDU 0x5E
  320. #define MAC_REG_FIFO_TEST0 0x60
  321. #define MAC_REG_FIFO_TEST1 0x64
  322. #define MAC_REG_CAMADDR 0x68
  323. #define MAC_REG_CAMCR 0x69
  324. #define MAC_REG_GFTEST 0x6A
  325. #define MAC_REG_FTSTCMD 0x6B
  326. #define MAC_REG_MIICFG 0x6C
  327. #define MAC_REG_MIISR 0x6D
  328. #define MAC_REG_PHYSR0 0x6E
  329. #define MAC_REG_PHYSR1 0x6F
  330. #define MAC_REG_MIICR 0x70
  331. #define MAC_REG_MIIADR 0x71
  332. #define MAC_REG_MIIDATA 0x72
  333. #define MAC_REG_SOFT_TIMER0 0x74
  334. #define MAC_REG_SOFT_TIMER1 0x76
  335. #define MAC_REG_CFGA 0x78
  336. #define MAC_REG_CFGB 0x79
  337. #define MAC_REG_CFGC 0x7A
  338. #define MAC_REG_CFGD 0x7B
  339. #define MAC_REG_DCFG0 0x7C
  340. #define MAC_REG_DCFG1 0x7D
  341. #define MAC_REG_MCFG0 0x7E
  342. #define MAC_REG_MCFG1 0x7F
  343. #define MAC_REG_TBIST 0x80
  344. #define MAC_REG_RBIST 0x81
  345. #define MAC_REG_PMCC 0x82
  346. #define MAC_REG_STICKHW 0x83
  347. #define MAC_REG_MIBCR 0x84
  348. #define MAC_REG_EERSV 0x85
  349. #define MAC_REG_REVID 0x86
  350. #define MAC_REG_MIBREAD 0x88
  351. #define MAC_REG_BPMA 0x8C
  352. #define MAC_REG_EEWR_DATA 0x8C
  353. #define MAC_REG_BPMD_WR 0x8F
  354. #define MAC_REG_BPCMD 0x90
  355. #define MAC_REG_BPMD_RD 0x91
  356. #define MAC_REG_EECHKSUM 0x92
  357. #define MAC_REG_EECSR 0x93
  358. #define MAC_REG_EERD_DATA 0x94
  359. #define MAC_REG_EADDR 0x96
  360. #define MAC_REG_EMBCMD 0x97
  361. #define MAC_REG_JMPSR0 0x98
  362. #define MAC_REG_JMPSR1 0x99
  363. #define MAC_REG_JMPSR2 0x9A
  364. #define MAC_REG_JMPSR3 0x9B
  365. #define MAC_REG_CHIPGSR 0x9C
  366. #define MAC_REG_TESTCFG 0x9D
  367. #define MAC_REG_DEBUG 0x9E
  368. #define MAC_REG_CHIPGCR 0x9F
  369. #define MAC_REG_WOLCR0_SET 0xA0
  370. #define MAC_REG_WOLCR1_SET 0xA1
  371. #define MAC_REG_PWCFG_SET 0xA2
  372. #define MAC_REG_WOLCFG_SET 0xA3
  373. #define MAC_REG_WOLCR0_CLR 0xA4
  374. #define MAC_REG_WOLCR1_CLR 0xA5
  375. #define MAC_REG_PWCFG_CLR 0xA6
  376. #define MAC_REG_WOLCFG_CLR 0xA7
  377. #define MAC_REG_WOLSR0_SET 0xA8
  378. #define MAC_REG_WOLSR1_SET 0xA9
  379. #define MAC_REG_WOLSR0_CLR 0xAC
  380. #define MAC_REG_WOLSR1_CLR 0xAD
  381. #define MAC_REG_PATRN_CRC0 0xB0
  382. #define MAC_REG_PATRN_CRC1 0xB2
  383. #define MAC_REG_PATRN_CRC2 0xB4
  384. #define MAC_REG_PATRN_CRC3 0xB6
  385. #define MAC_REG_PATRN_CRC4 0xB8
  386. #define MAC_REG_PATRN_CRC5 0xBA
  387. #define MAC_REG_PATRN_CRC6 0xBC
  388. #define MAC_REG_PATRN_CRC7 0xBE
  389. #define MAC_REG_BYTEMSK0_0 0xC0
  390. #define MAC_REG_BYTEMSK0_1 0xC4
  391. #define MAC_REG_BYTEMSK0_2 0xC8
  392. #define MAC_REG_BYTEMSK0_3 0xCC
  393. #define MAC_REG_BYTEMSK1_0 0xD0
  394. #define MAC_REG_BYTEMSK1_1 0xD4
  395. #define MAC_REG_BYTEMSK1_2 0xD8
  396. #define MAC_REG_BYTEMSK1_3 0xDC
  397. #define MAC_REG_BYTEMSK2_0 0xE0
  398. #define MAC_REG_BYTEMSK2_1 0xE4
  399. #define MAC_REG_BYTEMSK2_2 0xE8
  400. #define MAC_REG_BYTEMSK2_3 0xEC
  401. #define MAC_REG_BYTEMSK3_0 0xF0
  402. #define MAC_REG_BYTEMSK3_1 0xF4
  403. #define MAC_REG_BYTEMSK3_2 0xF8
  404. #define MAC_REG_BYTEMSK3_3 0xFC
  405. /*
  406. * Bits in the RCR register
  407. */
  408. #define RCR_AS 0x80
  409. #define RCR_AP 0x40
  410. #define RCR_AL 0x20
  411. #define RCR_PROM 0x10
  412. #define RCR_AB 0x08
  413. #define RCR_AM 0x04
  414. #define RCR_AR 0x02
  415. #define RCR_SEP 0x01
  416. /*
  417. * Bits in the TCR register
  418. */
  419. #define TCR_TB2BDIS 0x80
  420. #define TCR_COLTMC1 0x08
  421. #define TCR_COLTMC0 0x04
  422. #define TCR_LB1 0x02 /* loopback[1] */
  423. #define TCR_LB0 0x01 /* loopback[0] */
  424. /*
  425. * Bits in the CR0 register
  426. */
  427. #define CR0_TXON 0x00000008UL
  428. #define CR0_RXON 0x00000004UL
  429. #define CR0_STOP 0x00000002UL /* stop MAC, default = 1 */
  430. #define CR0_STRT 0x00000001UL /* start MAC */
  431. #define CR0_SFRST 0x00008000UL /* software reset */
  432. #define CR0_TM1EN 0x00004000UL
  433. #define CR0_TM0EN 0x00002000UL
  434. #define CR0_DPOLL 0x00000800UL /* disable rx/tx auto polling */
  435. #define CR0_DISAU 0x00000100UL
  436. #define CR0_XONEN 0x00800000UL
  437. #define CR0_FDXTFCEN 0x00400000UL /* full-duplex TX flow control enable */
  438. #define CR0_FDXRFCEN 0x00200000UL /* full-duplex RX flow control enable */
  439. #define CR0_HDXFCEN 0x00100000UL /* half-duplex flow control enable */
  440. #define CR0_XHITH1 0x00080000UL /* TX XON high threshold 1 */
  441. #define CR0_XHITH0 0x00040000UL /* TX XON high threshold 0 */
  442. #define CR0_XLTH1 0x00020000UL /* TX pause frame low threshold 1 */
  443. #define CR0_XLTH0 0x00010000UL /* TX pause frame low threshold 0 */
  444. #define CR0_GSPRST 0x80000000UL
  445. #define CR0_FORSRST 0x40000000UL
  446. #define CR0_FPHYRST 0x20000000UL
  447. #define CR0_DIAG 0x10000000UL
  448. #define CR0_INTPCTL 0x04000000UL
  449. #define CR0_GINTMSK1 0x02000000UL
  450. #define CR0_GINTMSK0 0x01000000UL
  451. /*
  452. * Bits in the CR1 register
  453. */
  454. #define CR1_SFRST 0x80 /* software reset */
  455. #define CR1_TM1EN 0x40
  456. #define CR1_TM0EN 0x20
  457. #define CR1_DPOLL 0x08 /* disable rx/tx auto polling */
  458. #define CR1_DISAU 0x01
  459. /*
  460. * Bits in the CR2 register
  461. */
  462. #define CR2_XONEN 0x80
  463. #define CR2_FDXTFCEN 0x40 /* full-duplex TX flow control enable */
  464. #define CR2_FDXRFCEN 0x20 /* full-duplex RX flow control enable */
  465. #define CR2_HDXFCEN 0x10 /* half-duplex flow control enable */
  466. #define CR2_XHITH1 0x08 /* TX XON high threshold 1 */
  467. #define CR2_XHITH0 0x04 /* TX XON high threshold 0 */
  468. #define CR2_XLTH1 0x02 /* TX pause frame low threshold 1 */
  469. #define CR2_XLTH0 0x01 /* TX pause frame low threshold 0 */
  470. /*
  471. * Bits in the CR3 register
  472. */
  473. #define CR3_GSPRST 0x80
  474. #define CR3_FORSRST 0x40
  475. #define CR3_FPHYRST 0x20
  476. #define CR3_DIAG 0x10
  477. #define CR3_INTPCTL 0x04
  478. #define CR3_GINTMSK1 0x02
  479. #define CR3_GINTMSK0 0x01
  480. #define ISRCTL_UDPINT 0x8000
  481. #define ISRCTL_TSUPDIS 0x4000
  482. #define ISRCTL_RSUPDIS 0x2000
  483. #define ISRCTL_PMSK1 0x1000
  484. #define ISRCTL_PMSK0 0x0800
  485. #define ISRCTL_INTPD 0x0400
  486. #define ISRCTL_HCRLD 0x0200
  487. #define ISRCTL_SCRLD 0x0100
  488. /*
  489. * Bits in the ISR_CTL1 register
  490. */
  491. #define ISRCTL1_UDPINT 0x80
  492. #define ISRCTL1_TSUPDIS 0x40
  493. #define ISRCTL1_RSUPDIS 0x20
  494. #define ISRCTL1_PMSK1 0x10
  495. #define ISRCTL1_PMSK0 0x08
  496. #define ISRCTL1_INTPD 0x04
  497. #define ISRCTL1_HCRLD 0x02
  498. #define ISRCTL1_SCRLD 0x01
  499. /*
  500. * Bits in the TXE_SR register
  501. */
  502. #define TXESR_TFDBS 0x08
  503. #define TXESR_TDWBS 0x04
  504. #define TXESR_TDRBS 0x02
  505. #define TXESR_TDSTR 0x01
  506. /*
  507. * Bits in the RXE_SR register
  508. */
  509. #define RXESR_RFDBS 0x08
  510. #define RXESR_RDWBS 0x04
  511. #define RXESR_RDRBS 0x02
  512. #define RXESR_RDSTR 0x01
  513. /*
  514. * Bits in the ISR register
  515. */
  516. #define ISR_ISR3 0x80000000UL
  517. #define ISR_ISR2 0x40000000UL
  518. #define ISR_ISR1 0x20000000UL
  519. #define ISR_ISR0 0x10000000UL
  520. #define ISR_TXSTLI 0x02000000UL
  521. #define ISR_RXSTLI 0x01000000UL
  522. #define ISR_HFLD 0x00800000UL
  523. #define ISR_UDPI 0x00400000UL
  524. #define ISR_MIBFI 0x00200000UL
  525. #define ISR_SHDNI 0x00100000UL
  526. #define ISR_PHYI 0x00080000UL
  527. #define ISR_PWEI 0x00040000UL
  528. #define ISR_TMR1I 0x00020000UL
  529. #define ISR_TMR0I 0x00010000UL
  530. #define ISR_SRCI 0x00008000UL
  531. #define ISR_LSTPEI 0x00004000UL
  532. #define ISR_LSTEI 0x00002000UL
  533. #define ISR_OVFI 0x00001000UL
  534. #define ISR_FLONI 0x00000800UL
  535. #define ISR_RACEI 0x00000400UL
  536. #define ISR_TXWB1I 0x00000200UL
  537. #define ISR_TXWB0I 0x00000100UL
  538. #define ISR_PTX3I 0x00000080UL
  539. #define ISR_PTX2I 0x00000040UL
  540. #define ISR_PTX1I 0x00000020UL
  541. #define ISR_PTX0I 0x00000010UL
  542. #define ISR_PTXI 0x00000008UL
  543. #define ISR_PRXI 0x00000004UL
  544. #define ISR_PPTXI 0x00000002UL
  545. #define ISR_PPRXI 0x00000001UL
  546. /*
  547. * Bits in the IMR register
  548. */
  549. #define IMR_TXSTLM 0x02000000UL
  550. #define IMR_UDPIM 0x00400000UL
  551. #define IMR_MIBFIM 0x00200000UL
  552. #define IMR_SHDNIM 0x00100000UL
  553. #define IMR_PHYIM 0x00080000UL
  554. #define IMR_PWEIM 0x00040000UL
  555. #define IMR_TMR1IM 0x00020000UL
  556. #define IMR_TMR0IM 0x00010000UL
  557. #define IMR_SRCIM 0x00008000UL
  558. #define IMR_LSTPEIM 0x00004000UL
  559. #define IMR_LSTEIM 0x00002000UL
  560. #define IMR_OVFIM 0x00001000UL
  561. #define IMR_FLONIM 0x00000800UL
  562. #define IMR_RACEIM 0x00000400UL
  563. #define IMR_TXWB1IM 0x00000200UL
  564. #define IMR_TXWB0IM 0x00000100UL
  565. #define IMR_PTX3IM 0x00000080UL
  566. #define IMR_PTX2IM 0x00000040UL
  567. #define IMR_PTX1IM 0x00000020UL
  568. #define IMR_PTX0IM 0x00000010UL
  569. #define IMR_PTXIM 0x00000008UL
  570. #define IMR_PRXIM 0x00000004UL
  571. #define IMR_PPTXIM 0x00000002UL
  572. #define IMR_PPRXIM 0x00000001UL
  573. /* 0x0013FB0FUL = initial value of IMR */
  574. #define INT_MASK_DEF ( IMR_PPTXIM|IMR_PPRXIM| IMR_PTXIM|IMR_PRXIM | \
  575. IMR_PWEIM|IMR_TXWB0IM|IMR_TXWB1IM|IMR_FLONIM| \
  576. IMR_OVFIM|IMR_LSTEIM|IMR_LSTPEIM|IMR_SRCIM|IMR_MIBFIM|\
  577. IMR_SHDNIM |IMR_TMR1IM|IMR_TMR0IM|IMR_TXSTLM )
  578. /*
  579. * Bits in the TDCSR0/1, RDCSR0 register
  580. */
  581. #define TRDCSR_DEAD 0x0008
  582. #define TRDCSR_WAK 0x0004
  583. #define TRDCSR_ACT 0x0002
  584. #define TRDCSR_RUN 0x0001
  585. /*
  586. * Bits in the CAMADDR register
  587. */
  588. #define CAMADDR_CAMEN 0x80
  589. #define CAMADDR_VCAMSL 0x40
  590. /*
  591. * Bits in the CAMCR register
  592. */
  593. #define CAMCR_PS1 0x80
  594. #define CAMCR_PS0 0x40
  595. #define CAMCR_AITRPKT 0x20
  596. #define CAMCR_AITR16 0x10
  597. #define CAMCR_CAMRD 0x08
  598. #define CAMCR_CAMWR 0x04
  599. #define CAMCR_PS_CAM_MASK 0x40
  600. #define CAMCR_PS_CAM_DATA 0x80
  601. #define CAMCR_PS_MAR 0x00
  602. /*
  603. * Bits in the MIICFG register
  604. */
  605. #define MIICFG_MPO1 0x80
  606. #define MIICFG_MPO0 0x40
  607. #define MIICFG_MFDC 0x20
  608. /*
  609. * Bits in the MIISR register
  610. */
  611. #define MIISR_MIDLE 0x80
  612. /*
  613. * Bits in the PHYSR0 register
  614. */
  615. #define PHYSR0_PHYRST 0x80
  616. #define PHYSR0_LINKGD 0x40
  617. #define PHYSR0_FDPX 0x10
  618. #define PHYSR0_SPDG 0x08
  619. #define PHYSR0_SPD10 0x04
  620. #define PHYSR0_RXFLC 0x02
  621. #define PHYSR0_TXFLC 0x01
  622. /*
  623. * Bits in the PHYSR1 register
  624. */
  625. #define PHYSR1_PHYTBI 0x01
  626. /*
  627. * Bits in the MIICR register
  628. */
  629. #define MIICR_MAUTO 0x80
  630. #define MIICR_RCMD 0x40
  631. #define MIICR_WCMD 0x20
  632. #define MIICR_MDPM 0x10
  633. #define MIICR_MOUT 0x08
  634. #define MIICR_MDO 0x04
  635. #define MIICR_MDI 0x02
  636. #define MIICR_MDC 0x01
  637. /*
  638. * Bits in the MIIADR register
  639. */
  640. #define MIIADR_SWMPL 0x80
  641. /*
  642. * Bits in the CFGA register
  643. */
  644. #define CFGA_PMHCTG 0x08
  645. #define CFGA_GPIO1PD 0x04
  646. #define CFGA_ABSHDN 0x02
  647. #define CFGA_PACPI 0x01
  648. /*
  649. * Bits in the CFGB register
  650. */
  651. #define CFGB_GTCKOPT 0x80
  652. #define CFGB_MIIOPT 0x40
  653. #define CFGB_CRSEOPT 0x20
  654. #define CFGB_OFSET 0x10
  655. #define CFGB_CRANDOM 0x08
  656. #define CFGB_CAP 0x04
  657. #define CFGB_MBA 0x02
  658. #define CFGB_BAKOPT 0x01
  659. /*
  660. * Bits in the CFGC register
  661. */
  662. #define CFGC_EELOAD 0x80
  663. #define CFGC_BROPT 0x40
  664. #define CFGC_DLYEN 0x20
  665. #define CFGC_DTSEL 0x10
  666. #define CFGC_BTSEL 0x08
  667. #define CFGC_BPS2 0x04 /* bootrom select[2] */
  668. #define CFGC_BPS1 0x02 /* bootrom select[1] */
  669. #define CFGC_BPS0 0x01 /* bootrom select[0] */
  670. /*
  671. * Bits in the CFGD register
  672. */
  673. #define CFGD_IODIS 0x80
  674. #define CFGD_MSLVDACEN 0x40
  675. #define CFGD_CFGDACEN 0x20
  676. #define CFGD_PCI64EN 0x10
  677. #define CFGD_HTMRL4 0x08
  678. /*
  679. * Bits in the DCFG1 register
  680. */
  681. #define DCFG_XMWI 0x8000
  682. #define DCFG_XMRM 0x4000
  683. #define DCFG_XMRL 0x2000
  684. #define DCFG_PERDIS 0x1000
  685. #define DCFG_MRWAIT 0x0400
  686. #define DCFG_MWWAIT 0x0200
  687. #define DCFG_LATMEN 0x0100
  688. /*
  689. * Bits in the MCFG0 register
  690. */
  691. #define MCFG_RXARB 0x0080
  692. #define MCFG_RFT1 0x0020
  693. #define MCFG_RFT0 0x0010
  694. #define MCFG_LOWTHOPT 0x0008
  695. #define MCFG_PQEN 0x0004
  696. #define MCFG_RTGOPT 0x0002
  697. #define MCFG_VIDFR 0x0001
  698. /*
  699. * Bits in the MCFG1 register
  700. */
  701. #define MCFG_TXARB 0x8000
  702. #define MCFG_TXQBK1 0x0800
  703. #define MCFG_TXQBK0 0x0400
  704. #define MCFG_TXQNOBK 0x0200
  705. #define MCFG_SNAPOPT 0x0100
  706. /*
  707. * Bits in the PMCC register
  708. */
  709. #define PMCC_DSI 0x80
  710. #define PMCC_D2_DIS 0x40
  711. #define PMCC_D1_DIS 0x20
  712. #define PMCC_D3C_EN 0x10
  713. #define PMCC_D3H_EN 0x08
  714. #define PMCC_D2_EN 0x04
  715. #define PMCC_D1_EN 0x02
  716. #define PMCC_D0_EN 0x01
  717. /*
  718. * Bits in STICKHW
  719. */
  720. #define STICKHW_SWPTAG 0x10
  721. #define STICKHW_WOLSR 0x08
  722. #define STICKHW_WOLEN 0x04
  723. #define STICKHW_DS1 0x02 /* R/W by software/cfg cycle */
  724. #define STICKHW_DS0 0x01 /* suspend well DS write port */
  725. /*
  726. * Bits in the MIBCR register
  727. */
  728. #define MIBCR_MIBISTOK 0x80
  729. #define MIBCR_MIBISTGO 0x40
  730. #define MIBCR_MIBINC 0x20
  731. #define MIBCR_MIBHI 0x10
  732. #define MIBCR_MIBFRZ 0x08
  733. #define MIBCR_MIBFLSH 0x04
  734. #define MIBCR_MPTRINI 0x02
  735. #define MIBCR_MIBCLR 0x01
  736. /*
  737. * Bits in the EERSV register
  738. */
  739. #define EERSV_BOOT_RPL ((u8) 0x01) /* Boot method selection for VT6110 */
  740. #define EERSV_BOOT_MASK ((u8) 0x06)
  741. #define EERSV_BOOT_INT19 ((u8) 0x00)
  742. #define EERSV_BOOT_INT18 ((u8) 0x02)
  743. #define EERSV_BOOT_LOCAL ((u8) 0x04)
  744. #define EERSV_BOOT_BEV ((u8) 0x06)
  745. /*
  746. * Bits in BPCMD
  747. */
  748. #define BPCMD_BPDNE 0x80
  749. #define BPCMD_EBPWR 0x02
  750. #define BPCMD_EBPRD 0x01
  751. /*
  752. * Bits in the EECSR register
  753. */
  754. #define EECSR_EMBP 0x40 /* eeprom embeded programming */
  755. #define EECSR_RELOAD 0x20 /* eeprom content reload */
  756. #define EECSR_DPM 0x10 /* eeprom direct programming */
  757. #define EECSR_ECS 0x08 /* eeprom CS pin */
  758. #define EECSR_ECK 0x04 /* eeprom CK pin */
  759. #define EECSR_EDI 0x02 /* eeprom DI pin */
  760. #define EECSR_EDO 0x01 /* eeprom DO pin */
  761. /*
  762. * Bits in the EMBCMD register
  763. */
  764. #define EMBCMD_EDONE 0x80
  765. #define EMBCMD_EWDIS 0x08
  766. #define EMBCMD_EWEN 0x04
  767. #define EMBCMD_EWR 0x02
  768. #define EMBCMD_ERD 0x01
  769. /*
  770. * Bits in TESTCFG register
  771. */
  772. #define TESTCFG_HBDIS 0x80
  773. /*
  774. * Bits in CHIPGCR register
  775. */
  776. #define CHIPGCR_FCGMII 0x80
  777. #define CHIPGCR_FCFDX 0x40
  778. #define CHIPGCR_FCRESV 0x20
  779. #define CHIPGCR_FCMODE 0x10
  780. #define CHIPGCR_LPSOPT 0x08
  781. #define CHIPGCR_TM1US 0x04
  782. #define CHIPGCR_TM0US 0x02
  783. #define CHIPGCR_PHYINTEN 0x01
  784. /*
  785. * Bits in WOLCR0
  786. */
  787. #define WOLCR_MSWOLEN7 0x0080 /* enable pattern match filtering */
  788. #define WOLCR_MSWOLEN6 0x0040
  789. #define WOLCR_MSWOLEN5 0x0020
  790. #define WOLCR_MSWOLEN4 0x0010
  791. #define WOLCR_MSWOLEN3 0x0008
  792. #define WOLCR_MSWOLEN2 0x0004
  793. #define WOLCR_MSWOLEN1 0x0002
  794. #define WOLCR_MSWOLEN0 0x0001
  795. #define WOLCR_ARP_EN 0x0001
  796. /*
  797. * Bits in WOLCR1
  798. */
  799. #define WOLCR_LINKOFF_EN 0x0800 /* link off detected enable */
  800. #define WOLCR_LINKON_EN 0x0400 /* link on detected enable */
  801. #define WOLCR_MAGIC_EN 0x0200 /* magic packet filter enable */
  802. #define WOLCR_UNICAST_EN 0x0100 /* unicast filter enable */
  803. /*
  804. * Bits in PWCFG
  805. */
  806. #define PWCFG_PHYPWOPT 0x80 /* internal MII I/F timing */
  807. #define PWCFG_PCISTICK 0x40 /* PCI sticky R/W enable */
  808. #define PWCFG_WOLTYPE 0x20 /* pulse(1) or button (0) */
  809. #define PWCFG_LEGCY_WOL 0x10
  810. #define PWCFG_PMCSR_PME_SR 0x08
  811. #define PWCFG_PMCSR_PME_EN 0x04 /* control by PCISTICK */
  812. #define PWCFG_LEGACY_WOLSR 0x02 /* Legacy WOL_SR shadow */
  813. #define PWCFG_LEGACY_WOLEN 0x01 /* Legacy WOL_EN shadow */
  814. /*
  815. * Bits in WOLCFG
  816. */
  817. #define WOLCFG_PMEOVR 0x80 /* for legacy use, force PMEEN always */
  818. #define WOLCFG_SAM 0x20 /* accept multicast case reset, default=0 */
  819. #define WOLCFG_SAB 0x10 /* accept broadcast case reset, default=0 */
  820. #define WOLCFG_SMIIACC 0x08 /* ?? */
  821. #define WOLCFG_SGENWH 0x02
  822. #define WOLCFG_PHYINTEN 0x01 /* 0:PHYINT trigger enable, 1:use internal MII
  823. to report status change */
  824. /*
  825. * Bits in WOLSR1
  826. */
  827. #define WOLSR_LINKOFF_INT 0x0800
  828. #define WOLSR_LINKON_INT 0x0400
  829. #define WOLSR_MAGIC_INT 0x0200
  830. #define WOLSR_UNICAST_INT 0x0100
  831. /*
  832. * Ethernet address filter type
  833. */
  834. #define PKT_TYPE_NONE 0x0000 /* Turn off receiver */
  835. #define PKT_TYPE_DIRECTED 0x0001 /* obselete, directed address is always accepted */
  836. #define PKT_TYPE_MULTICAST 0x0002
  837. #define PKT_TYPE_ALL_MULTICAST 0x0004
  838. #define PKT_TYPE_BROADCAST 0x0008
  839. #define PKT_TYPE_PROMISCUOUS 0x0020
  840. #define PKT_TYPE_LONG 0x2000 /* NOTE.... the definition of LONG is >2048 bytes in our chip */
  841. #define PKT_TYPE_RUNT 0x4000
  842. #define PKT_TYPE_ERROR 0x8000 /* Accept error packets, e.g. CRC error */
  843. /*
  844. * Loopback mode
  845. */
  846. #define MAC_LB_NONE 0x00
  847. #define MAC_LB_INTERNAL 0x01
  848. #define MAC_LB_EXTERNAL 0x02
  849. /*
  850. * Enabled mask value of irq
  851. */
  852. #if defined(_SIM)
  853. #define IMR_MASK_VALUE 0x0033FF0FUL /* initial value of IMR
  854. set IMR0 to 0x0F according to spec */
  855. #else
  856. #define IMR_MASK_VALUE 0x0013FB0FUL /* initial value of IMR
  857. ignore MIBFI,RACEI to
  858. reduce intr. frequency
  859. NOTE.... do not enable NoBuf int mask at driver driver
  860. when (1) NoBuf -> RxThreshold = SF
  861. (2) OK -> RxThreshold = original value
  862. */
  863. #endif
  864. /*
  865. * Revision id
  866. */
  867. #define REV_ID_VT3119_A0 0x00
  868. #define REV_ID_VT3119_A1 0x01
  869. #define REV_ID_VT3216_A0 0x10
  870. /*
  871. * Max time out delay time
  872. */
  873. #define W_MAX_TIMEOUT 0x0FFFU
  874. /*
  875. * MAC registers as a structure. Cannot be directly accessed this
  876. * way but generates offsets for readl/writel() calls
  877. */
  878. struct mac_regs {
  879. volatile u8 PAR[6]; /* 0x00 */
  880. volatile u8 RCR;
  881. volatile u8 TCR;
  882. volatile u32 CR0Set; /* 0x08 */
  883. volatile u32 CR0Clr; /* 0x0C */
  884. volatile u8 MARCAM[8]; /* 0x10 */
  885. volatile u32 DecBaseHi; /* 0x18 */
  886. volatile u16 DbfBaseHi; /* 0x1C */
  887. volatile u16 reserved_1E;
  888. volatile u16 ISRCTL; /* 0x20 */
  889. volatile u8 TXESR;
  890. volatile u8 RXESR;
  891. volatile u32 ISR; /* 0x24 */
  892. volatile u32 IMR;
  893. volatile u32 TDStatusPort; /* 0x2C */
  894. volatile u16 TDCSRSet; /* 0x30 */
  895. volatile u8 RDCSRSet;
  896. volatile u8 reserved_33;
  897. volatile u16 TDCSRClr;
  898. volatile u8 RDCSRClr;
  899. volatile u8 reserved_37;
  900. volatile u32 RDBaseLo; /* 0x38 */
  901. volatile u16 RDIdx; /* 0x3C */
  902. volatile u16 reserved_3E;
  903. volatile u32 TDBaseLo[4]; /* 0x40 */
  904. volatile u16 RDCSize; /* 0x50 */
  905. volatile u16 TDCSize; /* 0x52 */
  906. volatile u16 TDIdx[4]; /* 0x54 */
  907. volatile u16 tx_pause_timer; /* 0x5C */
  908. volatile u16 RBRDU; /* 0x5E */
  909. volatile u32 FIFOTest0; /* 0x60 */
  910. volatile u32 FIFOTest1; /* 0x64 */
  911. volatile u8 CAMADDR; /* 0x68 */
  912. volatile u8 CAMCR; /* 0x69 */
  913. volatile u8 GFTEST; /* 0x6A */
  914. volatile u8 FTSTCMD; /* 0x6B */
  915. volatile u8 MIICFG; /* 0x6C */
  916. volatile u8 MIISR;
  917. volatile u8 PHYSR0;
  918. volatile u8 PHYSR1;
  919. volatile u8 MIICR;
  920. volatile u8 MIIADR;
  921. volatile u16 MIIDATA;
  922. volatile u16 SoftTimer0; /* 0x74 */
  923. volatile u16 SoftTimer1;
  924. volatile u8 CFGA; /* 0x78 */
  925. volatile u8 CFGB;
  926. volatile u8 CFGC;
  927. volatile u8 CFGD;
  928. volatile u16 DCFG; /* 0x7C */
  929. volatile u16 MCFG;
  930. volatile u8 TBIST; /* 0x80 */
  931. volatile u8 RBIST;
  932. volatile u8 PMCPORT;
  933. volatile u8 STICKHW;
  934. volatile u8 MIBCR; /* 0x84 */
  935. volatile u8 reserved_85;
  936. volatile u8 rev_id;
  937. volatile u8 PORSTS;
  938. volatile u32 MIBData; /* 0x88 */
  939. volatile u16 EEWrData;
  940. volatile u8 reserved_8E;
  941. volatile u8 BPMDWr;
  942. volatile u8 BPCMD;
  943. volatile u8 BPMDRd;
  944. volatile u8 EECHKSUM; /* 0x92 */
  945. volatile u8 EECSR;
  946. volatile u16 EERdData; /* 0x94 */
  947. volatile u8 EADDR;
  948. volatile u8 EMBCMD;
  949. volatile u8 JMPSR0; /* 0x98 */
  950. volatile u8 JMPSR1;
  951. volatile u8 JMPSR2;
  952. volatile u8 JMPSR3;
  953. volatile u8 CHIPGSR; /* 0x9C */
  954. volatile u8 TESTCFG;
  955. volatile u8 DEBUG;
  956. volatile u8 CHIPGCR;
  957. volatile u16 WOLCRSet; /* 0xA0 */
  958. volatile u8 PWCFGSet;
  959. volatile u8 WOLCFGSet;
  960. volatile u16 WOLCRClr; /* 0xA4 */
  961. volatile u8 PWCFGCLR;
  962. volatile u8 WOLCFGClr;
  963. volatile u16 WOLSRSet; /* 0xA8 */
  964. volatile u16 reserved_AA;
  965. volatile u16 WOLSRClr; /* 0xAC */
  966. volatile u16 reserved_AE;
  967. volatile u16 PatternCRC[8]; /* 0xB0 */
  968. volatile u32 ByteMask[4][4]; /* 0xC0 */
  969. } __attribute__ ((__packed__));
  970. enum hw_mib {
  971. HW_MIB_ifRxAllPkts = 0,
  972. HW_MIB_ifRxOkPkts,
  973. HW_MIB_ifTxOkPkts,
  974. HW_MIB_ifRxErrorPkts,
  975. HW_MIB_ifRxRuntOkPkt,
  976. HW_MIB_ifRxRuntErrPkt,
  977. HW_MIB_ifRx64Pkts,
  978. HW_MIB_ifTx64Pkts,
  979. HW_MIB_ifRx65To127Pkts,
  980. HW_MIB_ifTx65To127Pkts,
  981. HW_MIB_ifRx128To255Pkts,
  982. HW_MIB_ifTx128To255Pkts,
  983. HW_MIB_ifRx256To511Pkts,
  984. HW_MIB_ifTx256To511Pkts,
  985. HW_MIB_ifRx512To1023Pkts,
  986. HW_MIB_ifTx512To1023Pkts,
  987. HW_MIB_ifRx1024To1518Pkts,
  988. HW_MIB_ifTx1024To1518Pkts,
  989. HW_MIB_ifTxEtherCollisions,
  990. HW_MIB_ifRxPktCRCE,
  991. HW_MIB_ifRxJumboPkts,
  992. HW_MIB_ifTxJumboPkts,
  993. HW_MIB_ifRxMacControlFrames,
  994. HW_MIB_ifTxMacControlFrames,
  995. HW_MIB_ifRxPktFAE,
  996. HW_MIB_ifRxLongOkPkt,
  997. HW_MIB_ifRxLongPktErrPkt,
  998. HW_MIB_ifTXSQEErrors,
  999. HW_MIB_ifRxNobuf,
  1000. HW_MIB_ifRxSymbolErrors,
  1001. HW_MIB_ifInRangeLengthErrors,
  1002. HW_MIB_ifLateCollisions,
  1003. HW_MIB_SIZE
  1004. };
  1005. enum chip_type {
  1006. CHIP_TYPE_VT6110 = 1,
  1007. };
  1008. struct velocity_info_tbl {
  1009. enum chip_type chip_id;
  1010. char *name;
  1011. int io_size;
  1012. int txqueue;
  1013. u32 flags;
  1014. };
  1015. struct velocity_info_tbl *info;
  1016. #define mac_hw_mibs_init(regs) {\
  1017. BYTE_REG_BITS_ON(MIBCR_MIBFRZ,&((regs)->MIBCR));\
  1018. BYTE_REG_BITS_ON(MIBCR_MIBCLR,&((regs)->MIBCR));\
  1019. do {}\
  1020. while (BYTE_REG_BITS_IS_ON(MIBCR_MIBCLR,&((regs)->MIBCR)));\
  1021. BYTE_REG_BITS_OFF(MIBCR_MIBFRZ,&((regs)->MIBCR));\
  1022. }
  1023. #define mac_read_isr(regs) readl(&((regs)->ISR))
  1024. #define mac_write_isr(regs, x) writel((x),&((regs)->ISR))
  1025. #define mac_clear_isr(regs) writel(0xffffffffL,&((regs)->ISR))
  1026. #define mac_write_int_mask(mask, regs) writel((mask),&((regs)->IMR));
  1027. #define mac_disable_int(regs) writel(CR0_GINTMSK1,&((regs)->CR0Clr))
  1028. #define mac_enable_int(regs) writel(CR0_GINTMSK1,&((regs)->CR0Set))
  1029. #define mac_hw_mibs_read(regs, MIBs) {\
  1030. int i;\
  1031. BYTE_REG_BITS_ON(MIBCR_MPTRINI,&((regs)->MIBCR));\
  1032. for (i=0;i<HW_MIB_SIZE;i++) {\
  1033. (MIBs)[i]=readl(&((regs)->MIBData));\
  1034. }\
  1035. }
  1036. #define mac_set_dma_length(regs, n) {\
  1037. BYTE_REG_BITS_SET((n),0x07,&((regs)->DCFG));\
  1038. }
  1039. #define mac_set_rx_thresh(regs, n) {\
  1040. BYTE_REG_BITS_SET((n),(MCFG_RFT0|MCFG_RFT1),&((regs)->MCFG));\
  1041. }
  1042. #define mac_rx_queue_run(regs) {\
  1043. writeb(TRDCSR_RUN, &((regs)->RDCSRSet));\
  1044. }
  1045. #define mac_rx_queue_wake(regs) {\
  1046. writeb(TRDCSR_WAK, &((regs)->RDCSRSet));\
  1047. }
  1048. #define mac_tx_queue_run(regs, n) {\
  1049. writew(TRDCSR_RUN<<((n)*4),&((regs)->TDCSRSet));\
  1050. }
  1051. #define mac_tx_queue_wake(regs, n) {\
  1052. writew(TRDCSR_WAK<<(n*4),&((regs)->TDCSRSet));\
  1053. }
  1054. #define mac_eeprom_reload(regs) {\
  1055. int i=0;\
  1056. BYTE_REG_BITS_ON(EECSR_RELOAD,&((regs)->EECSR));\
  1057. do {\
  1058. udelay(10);\
  1059. if (i++>0x1000) {\
  1060. break;\
  1061. }\
  1062. }while (BYTE_REG_BITS_IS_ON(EECSR_RELOAD,&((regs)->EECSR)));\
  1063. }
  1064. enum velocity_cam_type {
  1065. VELOCITY_VLAN_ID_CAM = 0,
  1066. VELOCITY_MULTICAST_CAM
  1067. };
  1068. /**
  1069. * mac_get_cam_mask - Read a CAM mask
  1070. * @regs: register block for this velocity
  1071. * @mask: buffer to store mask
  1072. * @cam_type: CAM to fetch
  1073. *
  1074. * Fetch the mask bits of the selected CAM and store them into the
  1075. * provided mask buffer.
  1076. */
  1077. static inline void mac_get_cam_mask(struct mac_regs *regs, u8 * mask,
  1078. enum velocity_cam_type cam_type)
  1079. {
  1080. int i;
  1081. /* Select CAM mask */
  1082. BYTE_REG_BITS_SET(CAMCR_PS_CAM_MASK, CAMCR_PS1 | CAMCR_PS0,
  1083. &regs->CAMCR);
  1084. if (cam_type == VELOCITY_VLAN_ID_CAM)
  1085. writeb(CAMADDR_VCAMSL, &regs->CAMADDR);
  1086. else
  1087. writeb(0, &regs->CAMADDR);
  1088. /* read mask */
  1089. for (i = 0; i < 8; i++)
  1090. *mask++ = readb(&(regs->MARCAM[i]));
  1091. /* disable CAMEN */
  1092. writeb(0, &regs->CAMADDR);
  1093. /* Select mar */
  1094. BYTE_REG_BITS_SET(CAMCR_PS_MAR, CAMCR_PS1 | CAMCR_PS0,
  1095. &regs->CAMCR);
  1096. }
  1097. /**
  1098. * mac_set_cam_mask - Set a CAM mask
  1099. * @regs: register block for this velocity
  1100. * @mask: CAM mask to load
  1101. * @cam_type: CAM to store
  1102. *
  1103. * Store a new mask into a CAM
  1104. */
  1105. static inline void mac_set_cam_mask(struct mac_regs *regs, u8 * mask,
  1106. enum velocity_cam_type cam_type)
  1107. {
  1108. int i;
  1109. /* Select CAM mask */
  1110. BYTE_REG_BITS_SET(CAMCR_PS_CAM_MASK, CAMCR_PS1 | CAMCR_PS0,
  1111. &regs->CAMCR);
  1112. if (cam_type == VELOCITY_VLAN_ID_CAM)
  1113. writeb(CAMADDR_CAMEN | CAMADDR_VCAMSL, &regs->CAMADDR);
  1114. else
  1115. writeb(CAMADDR_CAMEN, &regs->CAMADDR);
  1116. for (i = 0; i < 8; i++) {
  1117. writeb(*mask++, &(regs->MARCAM[i]));
  1118. }
  1119. /* disable CAMEN */
  1120. writeb(0, &regs->CAMADDR);
  1121. /* Select mar */
  1122. BYTE_REG_BITS_SET(CAMCR_PS_MAR, CAMCR_PS1 | CAMCR_PS0,
  1123. &regs->CAMCR);
  1124. }
  1125. /**
  1126. * mac_set_cam - set CAM data
  1127. * @regs: register block of this velocity
  1128. * @idx: Cam index
  1129. * @addr: 2 or 6 bytes of CAM data
  1130. * @cam_type: CAM to load
  1131. *
  1132. * Load an address or vlan tag into a CAM
  1133. */
  1134. static inline void mac_set_cam(struct mac_regs *regs, int idx, u8 * addr,
  1135. enum velocity_cam_type cam_type)
  1136. {
  1137. int i;
  1138. /* Select CAM mask */
  1139. BYTE_REG_BITS_SET(CAMCR_PS_CAM_DATA, CAMCR_PS1 | CAMCR_PS0,
  1140. &regs->CAMCR);
  1141. idx &= (64 - 1);
  1142. if (cam_type == VELOCITY_VLAN_ID_CAM)
  1143. writeb(CAMADDR_CAMEN | CAMADDR_VCAMSL | idx,
  1144. &regs->CAMADDR);
  1145. else
  1146. writeb(CAMADDR_CAMEN | idx, &regs->CAMADDR);
  1147. if (cam_type == VELOCITY_VLAN_ID_CAM)
  1148. writew(*((u16 *) addr), &regs->MARCAM[0]);
  1149. else {
  1150. for (i = 0; i < 6; i++) {
  1151. writeb(*addr++, &(regs->MARCAM[i]));
  1152. }
  1153. }
  1154. BYTE_REG_BITS_ON(CAMCR_CAMWR, &regs->CAMCR);
  1155. udelay(10);
  1156. writeb(0, &regs->CAMADDR);
  1157. /* Select mar */
  1158. BYTE_REG_BITS_SET(CAMCR_PS_MAR, CAMCR_PS1 | CAMCR_PS0,
  1159. &regs->CAMCR);
  1160. }
  1161. /**
  1162. * mac_get_cam - fetch CAM data
  1163. * @regs: register block of this velocity
  1164. * @idx: Cam index
  1165. * @addr: buffer to hold up to 6 bytes of CAM data
  1166. * @cam_type: CAM to load
  1167. *
  1168. * Load an address or vlan tag from a CAM into the buffer provided by
  1169. * the caller. VLAN tags are 2 bytes the address cam entries are 6.
  1170. */
  1171. static inline void mac_get_cam(struct mac_regs *regs, int idx, u8 * addr,
  1172. enum velocity_cam_type cam_type)
  1173. {
  1174. int i;
  1175. /* Select CAM mask */
  1176. BYTE_REG_BITS_SET(CAMCR_PS_CAM_DATA, CAMCR_PS1 | CAMCR_PS0,
  1177. &regs->CAMCR);
  1178. idx &= (64 - 1);
  1179. if (cam_type == VELOCITY_VLAN_ID_CAM)
  1180. writeb(CAMADDR_CAMEN | CAMADDR_VCAMSL | idx,
  1181. &regs->CAMADDR);
  1182. else
  1183. writeb(CAMADDR_CAMEN | idx, &regs->CAMADDR);
  1184. BYTE_REG_BITS_ON(CAMCR_CAMRD, &regs->CAMCR);
  1185. udelay(10);
  1186. if (cam_type == VELOCITY_VLAN_ID_CAM)
  1187. *((u16 *) addr) = readw(&(regs->MARCAM[0]));
  1188. else
  1189. for (i = 0; i < 6; i++, addr++)
  1190. *((u8 *) addr) = readb(&(regs->MARCAM[i]));
  1191. writeb(0, &regs->CAMADDR);
  1192. /* Select mar */
  1193. BYTE_REG_BITS_SET(CAMCR_PS_MAR, CAMCR_PS1 | CAMCR_PS0,
  1194. &regs->CAMCR);
  1195. }
  1196. /**
  1197. * mac_wol_reset - reset WOL after exiting low power
  1198. * @regs: register block of this velocity
  1199. *
  1200. * Called after we drop out of wake on lan mode in order to
  1201. * reset the Wake on lan features. This function doesn't restore
  1202. * the rest of the logic from the result of sleep/wakeup
  1203. */
  1204. inline static void mac_wol_reset(struct mac_regs *regs)
  1205. {
  1206. /* Turn off SWPTAG right after leaving power mode */
  1207. BYTE_REG_BITS_OFF(STICKHW_SWPTAG, &regs->STICKHW);
  1208. /* clear sticky bits */
  1209. BYTE_REG_BITS_OFF((STICKHW_DS1 | STICKHW_DS0), &regs->STICKHW);
  1210. BYTE_REG_BITS_OFF(CHIPGCR_FCGMII, &regs->CHIPGCR);
  1211. BYTE_REG_BITS_OFF(CHIPGCR_FCMODE, &regs->CHIPGCR);
  1212. /* disable force PME-enable */
  1213. writeb(WOLCFG_PMEOVR, &regs->WOLCFGClr);
  1214. /* disable power-event config bit */
  1215. writew(0xFFFF, &regs->WOLCRClr);
  1216. /* clear power status */
  1217. writew(0xFFFF, &regs->WOLSRClr);
  1218. }
  1219. /*
  1220. * Header for WOL definitions. Used to compute hashes
  1221. */
  1222. typedef u8 MCAM_ADDR[ETH_ALEN];
  1223. struct arp_packet {
  1224. u8 dest_mac[ETH_ALEN];
  1225. u8 src_mac[ETH_ALEN];
  1226. u16 type;
  1227. u16 ar_hrd;
  1228. u16 ar_pro;
  1229. u8 ar_hln;
  1230. u8 ar_pln;
  1231. u16 ar_op;
  1232. u8 ar_sha[ETH_ALEN];
  1233. u8 ar_sip[4];
  1234. u8 ar_tha[ETH_ALEN];
  1235. u8 ar_tip[4];
  1236. } __attribute__ ((__packed__));
  1237. struct _magic_packet {
  1238. u8 dest_mac[6];
  1239. u8 src_mac[6];
  1240. u16 type;
  1241. u8 MAC[16][6];
  1242. u8 password[6];
  1243. } __attribute__ ((__packed__));
  1244. /*
  1245. * Store for chip context when saving and restoring status. Not
  1246. * all fields are saved/restored currently.
  1247. */
  1248. struct velocity_context {
  1249. u8 mac_reg[256];
  1250. MCAM_ADDR cam_addr[MCAM_SIZE];
  1251. u16 vcam[VCAM_SIZE];
  1252. u32 cammask[2];
  1253. u32 patcrc[2];
  1254. u32 pattern[8];
  1255. };
  1256. /*
  1257. * MII registers.
  1258. */
  1259. /*
  1260. * Registers in the MII (offset unit is WORD)
  1261. */
  1262. #define MII_REG_BMCR 0x00 // physical address
  1263. #define MII_REG_BMSR 0x01 //
  1264. #define MII_REG_PHYID1 0x02 // OUI
  1265. #define MII_REG_PHYID2 0x03 // OUI + Module ID + REV ID
  1266. #define MII_REG_ANAR 0x04 //
  1267. #define MII_REG_ANLPAR 0x05 //
  1268. #define MII_REG_G1000CR 0x09 //
  1269. #define MII_REG_G1000SR 0x0A //
  1270. #define MII_REG_MODCFG 0x10 //
  1271. #define MII_REG_TCSR 0x16 //
  1272. #define MII_REG_PLED 0x1B //
  1273. // NS, MYSON only
  1274. #define MII_REG_PCR 0x17 //
  1275. // ESI only
  1276. #define MII_REG_PCSR 0x17 //
  1277. #define MII_REG_AUXCR 0x1C //
  1278. // Marvell 88E1000/88E1000S
  1279. #define MII_REG_PSCR 0x10 // PHY specific control register
  1280. //
  1281. // Bits in the BMCR register
  1282. //
  1283. #define BMCR_RESET 0x8000 //
  1284. #define BMCR_LBK 0x4000 //
  1285. #define BMCR_SPEED100 0x2000 //
  1286. #define BMCR_AUTO 0x1000 //
  1287. #define BMCR_PD 0x0800 //
  1288. #define BMCR_ISO 0x0400 //
  1289. #define BMCR_REAUTO 0x0200 //
  1290. #define BMCR_FDX 0x0100 //
  1291. #define BMCR_SPEED1G 0x0040 //
  1292. //
  1293. // Bits in the BMSR register
  1294. //
  1295. #define BMSR_AUTOCM 0x0020 //
  1296. #define BMSR_LNK 0x0004 //
  1297. //
  1298. // Bits in the ANAR register
  1299. //
  1300. #define ANAR_ASMDIR 0x0800 // Asymmetric PAUSE support
  1301. #define ANAR_PAUSE 0x0400 // Symmetric PAUSE Support
  1302. #define ANAR_T4 0x0200 //
  1303. #define ANAR_TXFD 0x0100 //
  1304. #define ANAR_TX 0x0080 //
  1305. #define ANAR_10FD 0x0040 //
  1306. #define ANAR_10 0x0020 //
  1307. //
  1308. // Bits in the ANLPAR register
  1309. //
  1310. #define ANLPAR_ASMDIR 0x0800 // Asymmetric PAUSE support
  1311. #define ANLPAR_PAUSE 0x0400 // Symmetric PAUSE Support
  1312. #define ANLPAR_T4 0x0200 //
  1313. #define ANLPAR_TXFD 0x0100 //
  1314. #define ANLPAR_TX 0x0080 //
  1315. #define ANLPAR_10FD 0x0040 //
  1316. #define ANLPAR_10 0x0020 //
  1317. //
  1318. // Bits in the G1000CR register
  1319. //
  1320. #define G1000CR_1000FD 0x0200 // PHY is 1000-T Full-duplex capable
  1321. #define G1000CR_1000 0x0100 // PHY is 1000-T Half-duplex capable
  1322. //
  1323. // Bits in the G1000SR register
  1324. //
  1325. #define G1000SR_1000FD 0x0800 // LP PHY is 1000-T Full-duplex capable
  1326. #define G1000SR_1000 0x0400 // LP PHY is 1000-T Half-duplex capable
  1327. #define TCSR_ECHODIS 0x2000 //
  1328. #define AUXCR_MDPPS 0x0004 //
  1329. // Bits in the PLED register
  1330. #define PLED_LALBE 0x0004 //
  1331. // Marvell 88E1000/88E1000S Bits in the PHY specific control register (10h)
  1332. #define PSCR_ACRSTX 0x0800 // Assert CRS on Transmit
  1333. #define PHYID_CICADA_CS8201 0x000FC410UL
  1334. #define PHYID_VT3216_32BIT 0x000FC610UL
  1335. #define PHYID_VT3216_64BIT 0x000FC600UL
  1336. #define PHYID_MARVELL_1000 0x01410C50UL
  1337. #define PHYID_MARVELL_1000S 0x01410C40UL
  1338. #define PHYID_REV_ID_MASK 0x0000000FUL
  1339. #define PHYID_GET_PHY_REV_ID(i) ((i) & PHYID_REV_ID_MASK)
  1340. #define PHYID_GET_PHY_ID(i) ((i) & ~PHYID_REV_ID_MASK)
  1341. #define MII_REG_BITS_ON(x,i,p) do {\
  1342. u16 w;\
  1343. velocity_mii_read((p),(i),&(w));\
  1344. (w)|=(x);\
  1345. velocity_mii_write((p),(i),(w));\
  1346. } while (0)
  1347. #define MII_REG_BITS_OFF(x,i,p) do {\
  1348. u16 w;\
  1349. velocity_mii_read((p),(i),&(w));\
  1350. (w)&=(~(x));\
  1351. velocity_mii_write((p),(i),(w));\
  1352. } while (0)
  1353. #define MII_REG_BITS_IS_ON(x,i,p) ({\
  1354. u16 w;\
  1355. velocity_mii_read((p),(i),&(w));\
  1356. ((int) ((w) & (x)));})
  1357. #define MII_GET_PHY_ID(p) ({\
  1358. u32 id;\
  1359. velocity_mii_read((p),MII_REG_PHYID2,(u16 *) &id);\
  1360. velocity_mii_read((p),MII_REG_PHYID1,((u16 *) &id)+1);\
  1361. (id);})
  1362. #ifdef LINUX
  1363. /*
  1364. * Inline debug routine
  1365. */
  1366. enum velocity_msg_level {
  1367. MSG_LEVEL_ERR = 0, //Errors that will cause abnormal operation.
  1368. MSG_LEVEL_NOTICE = 1, //Some errors need users to be notified.
  1369. MSG_LEVEL_INFO = 2, //Normal message.
  1370. MSG_LEVEL_VERBOSE = 3, //Will report all trival errors.
  1371. MSG_LEVEL_DEBUG = 4 //Only for debug purpose.
  1372. };
  1373. #ifdef VELOCITY_DEBUG
  1374. #define ASSERT(x) { \
  1375. if (!(x)) { \
  1376. printk(KERN_ERR "assertion %s failed: file %s line %d\n", #x,\
  1377. __FUNCTION__, __LINE__);\
  1378. BUG(); \
  1379. }\
  1380. }
  1381. #define VELOCITY_DBG(p,args...) printk(p, ##args)
  1382. #else
  1383. #define ASSERT(x)
  1384. #define VELOCITY_DBG(x)
  1385. #endif
  1386. #define VELOCITY_PRT(l, p, args...) do {if (l<=msglevel) printf( p ,##args);} while (0)
  1387. #define VELOCITY_PRT_CAMMASK(p,t) {\
  1388. int i;\
  1389. if ((t)==VELOCITY_MULTICAST_CAM) {\
  1390. for (i=0;i<(MCAM_SIZE/8);i++)\
  1391. printk("%02X",(p)->mCAMmask[i]);\
  1392. }\
  1393. else {\
  1394. for (i=0;i<(VCAM_SIZE/8);i++)\
  1395. printk("%02X",(p)->vCAMmask[i]);\
  1396. }\
  1397. printk("\n");\
  1398. }
  1399. #endif
  1400. #define VELOCITY_WOL_MAGIC 0x00000000UL
  1401. #define VELOCITY_WOL_PHY 0x00000001UL
  1402. #define VELOCITY_WOL_ARP 0x00000002UL
  1403. #define VELOCITY_WOL_UCAST 0x00000004UL
  1404. #define VELOCITY_WOL_BCAST 0x00000010UL
  1405. #define VELOCITY_WOL_MCAST 0x00000020UL
  1406. #define VELOCITY_WOL_MAGIC_SEC 0x00000040UL
  1407. /*
  1408. * Flags for options
  1409. */
  1410. #define VELOCITY_FLAGS_TAGGING 0x00000001UL
  1411. #define VELOCITY_FLAGS_TX_CSUM 0x00000002UL
  1412. #define VELOCITY_FLAGS_RX_CSUM 0x00000004UL
  1413. #define VELOCITY_FLAGS_IP_ALIGN 0x00000008UL
  1414. #define VELOCITY_FLAGS_VAL_PKT_LEN 0x00000010UL
  1415. #define VELOCITY_FLAGS_FLOW_CTRL 0x01000000UL
  1416. /*
  1417. * Flags for driver status
  1418. */
  1419. #define VELOCITY_FLAGS_OPENED 0x00010000UL
  1420. #define VELOCITY_FLAGS_VMNS_CONNECTED 0x00020000UL
  1421. #define VELOCITY_FLAGS_VMNS_COMMITTED 0x00040000UL
  1422. #define VELOCITY_FLAGS_WOL_ENABLED 0x00080000UL
  1423. /*
  1424. * Flags for MII status
  1425. */
  1426. #define VELOCITY_LINK_FAIL 0x00000001UL
  1427. #define VELOCITY_SPEED_10 0x00000002UL
  1428. #define VELOCITY_SPEED_100 0x00000004UL
  1429. #define VELOCITY_SPEED_1000 0x00000008UL
  1430. #define VELOCITY_DUPLEX_FULL 0x00000010UL
  1431. #define VELOCITY_AUTONEG_ENABLE 0x00000020UL
  1432. #define VELOCITY_FORCED_BY_EEPROM 0x00000040UL
  1433. /*
  1434. * For velocity_set_media_duplex
  1435. */
  1436. #define VELOCITY_LINK_CHANGE 0x00000001UL
  1437. enum speed_opt {
  1438. SPD_DPX_AUTO = 0,
  1439. SPD_DPX_100_HALF = 1,
  1440. SPD_DPX_100_FULL = 2,
  1441. SPD_DPX_10_HALF = 3,
  1442. SPD_DPX_10_FULL = 4
  1443. };
  1444. enum velocity_init_type {
  1445. VELOCITY_INIT_COLD = 0,
  1446. VELOCITY_INIT_RESET,
  1447. VELOCITY_INIT_WOL
  1448. };
  1449. enum velocity_flow_cntl_type {
  1450. FLOW_CNTL_DEFAULT = 1,
  1451. FLOW_CNTL_TX,
  1452. FLOW_CNTL_RX,
  1453. FLOW_CNTL_TX_RX,
  1454. FLOW_CNTL_DISABLE,
  1455. };
  1456. struct velocity_opt {
  1457. int numrx; /* Number of RX descriptors */
  1458. int numtx; /* Number of TX descriptors */
  1459. enum speed_opt spd_dpx; /* Media link mode */
  1460. int vid; /* vlan id */
  1461. int DMA_length; /* DMA length */
  1462. int rx_thresh; /* RX_THRESH */
  1463. int flow_cntl;
  1464. int wol_opts; /* Wake on lan options */
  1465. int td_int_count;
  1466. int int_works;
  1467. int rx_bandwidth_hi;
  1468. int rx_bandwidth_lo;
  1469. int rx_bandwidth_en;
  1470. u32 flags;
  1471. };
  1472. #define RX_DESC_MIN 4
  1473. #define RX_DESC_MAX 255
  1474. #define RX_DESC_DEF 64
  1475. #define TX_DESC_MIN 1
  1476. #define TX_DESC_MAX 256
  1477. #define TX_DESC_DEF 4
  1478. struct velocity_info {
  1479. // struct list_head list;
  1480. struct pci_device *pdev;
  1481. // struct net_device *dev;
  1482. // struct net_device_stats stats;
  1483. #ifdef CONFIG_PM
  1484. u32 pci_state[16];
  1485. #endif
  1486. // dma_addr_t rd_pool_dma;
  1487. // dma_addr_t td_pool_dma[TX_QUEUE_NO];
  1488. // dma_addr_t tx_bufs_dma;
  1489. u8 *tx_bufs;
  1490. u8 ip_addr[4];
  1491. enum chip_type chip_id;
  1492. struct mac_regs *mac_regs;
  1493. unsigned long memaddr;
  1494. unsigned long ioaddr;
  1495. u32 io_size;
  1496. u8 rev_id;
  1497. #define AVAIL_TD(p,q) ((p)->options.numtx-((p)->td_used[(q)]))
  1498. int num_txq;
  1499. volatile int td_used[TX_QUEUE_NO];
  1500. int td_curr;
  1501. int td_tail[TX_QUEUE_NO];
  1502. unsigned char *TxDescArrays; /* Index of Tx Descriptor buffer */
  1503. unsigned char *RxDescArrays; /* Index of Rx Descriptor buffer */
  1504. unsigned char *tx_buffs;
  1505. unsigned char *rx_buffs;
  1506. unsigned char *txb;
  1507. unsigned char *rxb;
  1508. struct tx_desc *td_rings;
  1509. struct velocity_td_info *td_infos[TX_QUEUE_NO];
  1510. int rd_curr;
  1511. int rd_dirty;
  1512. u32 rd_filled;
  1513. struct rx_desc *rd_ring;
  1514. struct velocity_rd_info *rd_info; /* It's an array */
  1515. #define GET_RD_BY_IDX(vptr, idx) (vptr->rd_ring[idx])
  1516. u32 mib_counter[MAX_HW_MIB_COUNTER];
  1517. struct velocity_opt options;
  1518. u32 int_mask;
  1519. u32 flags;
  1520. int rx_buf_sz;
  1521. u32 mii_status;
  1522. u32 phy_id;
  1523. int multicast_limit;
  1524. u8 vCAMmask[(VCAM_SIZE / 8)];
  1525. u8 mCAMmask[(MCAM_SIZE / 8)];
  1526. // spinlock_t lock;
  1527. int wol_opts;
  1528. u8 wol_passwd[6];
  1529. struct velocity_context context;
  1530. u32 ticks;
  1531. u32 rx_bytes;
  1532. } vptx;
  1533. static struct velocity_info *vptr;
  1534. #ifdef LINUX
  1535. /**
  1536. * velocity_get_ip - find an IP address for the device
  1537. * @vptr: Velocity to query
  1538. *
  1539. * Dig out an IP address for this interface so that we can
  1540. * configure wakeup with WOL for ARP. If there are multiple IP
  1541. * addresses on this chain then we use the first - multi-IP WOL is not
  1542. * supported.
  1543. *
  1544. * CHECK ME: locking
  1545. */
  1546. inline static int velocity_get_ip(struct velocity_info *vptr)
  1547. {
  1548. struct in_device *in_dev = (struct in_device *) vptr->dev->ip_ptr;
  1549. struct in_ifaddr *ifa;
  1550. if (in_dev != NULL) {
  1551. ifa = (struct in_ifaddr *) in_dev->ifa_list;
  1552. if (ifa != NULL) {
  1553. memcpy(vptr->ip_addr, &ifa->ifa_address, 4);
  1554. return 0;
  1555. }
  1556. }
  1557. return -ENOENT;
  1558. }
  1559. /**
  1560. * velocity_update_hw_mibs - fetch MIB counters from chip
  1561. * @vptr: velocity to update
  1562. *
  1563. * The velocity hardware keeps certain counters in the hardware
  1564. * side. We need to read these when the user asks for statistics
  1565. * or when they overflow (causing an interrupt). The read of the
  1566. * statistic clears it, so we keep running master counters in user
  1567. * space.
  1568. */
  1569. static inline void velocity_update_hw_mibs(struct velocity_info *vptr)
  1570. {
  1571. u32 tmp;
  1572. int i;
  1573. BYTE_REG_BITS_ON(MIBCR_MIBFLSH, &(vptr->mac_regs->MIBCR));
  1574. while (BYTE_REG_BITS_IS_ON
  1575. (MIBCR_MIBFLSH, &(vptr->mac_regs->MIBCR)));
  1576. BYTE_REG_BITS_ON(MIBCR_MPTRINI, &(vptr->mac_regs->MIBCR));
  1577. for (i = 0; i < HW_MIB_SIZE; i++) {
  1578. tmp = readl(&(vptr->mac_regs->MIBData)) & 0x00FFFFFFUL;
  1579. vptr->mib_counter[i] += tmp;
  1580. }
  1581. }
  1582. #endif
  1583. /**
  1584. * init_flow_control_register - set up flow control
  1585. * @vptr: velocity to configure
  1586. *
  1587. * Configure the flow control registers for this velocity device.
  1588. */
  1589. static inline void init_flow_control_register(struct velocity_info *vptr)
  1590. {
  1591. struct mac_regs *regs = vptr->mac_regs;
  1592. /* Set {XHITH1, XHITH0, XLTH1, XLTH0} in FlowCR1 to {1, 0, 1, 1}
  1593. depend on RD=64, and Turn on XNOEN in FlowCR1 */
  1594. writel((CR0_XONEN | CR0_XHITH1 | CR0_XLTH1 | CR0_XLTH0),
  1595. &regs->CR0Set);
  1596. writel((CR0_FDXTFCEN | CR0_FDXRFCEN | CR0_HDXFCEN | CR0_XHITH0),
  1597. &regs->CR0Clr);
  1598. /* Set TxPauseTimer to 0xFFFF */
  1599. writew(0xFFFF, &regs->tx_pause_timer);
  1600. /* Initialize RBRDU to Rx buffer count. */
  1601. writew(vptr->options.numrx, &regs->RBRDU);
  1602. }
  1603. #endif