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

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