smc91x.h 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300
  1. /*------------------------------------------------------------------------
  2. . smc91x.h - macros for SMSC's 91C9x/91C1xx single-chip Ethernet device.
  3. .
  4. . Copyright (C) 1996 by Erik Stahlman
  5. . Copyright (C) 2001 Standard Microsystems Corporation
  6. . Developed by Simple Network Magic Corporation
  7. . Copyright (C) 2003 Monta Vista Software, Inc.
  8. . Unified SMC91x driver by Nicolas Pitre
  9. .
  10. . This program is free software; you can redistribute it and/or modify
  11. . it under the terms of the GNU General Public License as published by
  12. . the Free Software Foundation; either version 2 of the License, or
  13. . (at your option) any later version.
  14. .
  15. . This program is distributed in the hope that it will be useful,
  16. . but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. . MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. . GNU General Public License for more details.
  19. .
  20. . You should have received a copy of the GNU General Public License
  21. . along with this program; if not, write to the Free Software
  22. . Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  23. .
  24. . Information contained in this file was obtained from the LAN91C111
  25. . manual from SMC. To get a copy, if you really want one, you can find
  26. . information under www.smsc.com.
  27. .
  28. . Authors
  29. . Erik Stahlman <erik@vt.edu>
  30. . Daris A Nevil <dnevil@snmc.com>
  31. . Nicolas Pitre <nico@cam.org>
  32. .
  33. ---------------------------------------------------------------------------*/
  34. #ifndef _SMC91X_H_
  35. #define _SMC91X_H_
  36. #include <linux/smc91x.h>
  37. /*
  38. * Define your architecture specific bus configuration parameters here.
  39. */
  40. #if defined(CONFIG_ARCH_LUBBOCK) ||\
  41. defined(CONFIG_MACH_MAINSTONE) ||\
  42. defined(CONFIG_MACH_ZYLONITE) ||\
  43. defined(CONFIG_MACH_LITTLETON) ||\
  44. defined(CONFIG_MACH_ZYLONITE2) ||\
  45. defined(CONFIG_ARCH_VIPER)
  46. #include <asm/mach-types.h>
  47. /* Now the bus width is specified in the platform data
  48. * pretend here to support all I/O access types
  49. */
  50. #define SMC_CAN_USE_8BIT 1
  51. #define SMC_CAN_USE_16BIT 1
  52. #define SMC_CAN_USE_32BIT 1
  53. #define SMC_NOWAIT 1
  54. #define SMC_IO_SHIFT (lp->io_shift)
  55. #define SMC_inb(a, r) readb((a) + (r))
  56. #define SMC_inw(a, r) readw((a) + (r))
  57. #define SMC_inl(a, r) readl((a) + (r))
  58. #define SMC_outb(v, a, r) writeb(v, (a) + (r))
  59. #define SMC_outl(v, a, r) writel(v, (a) + (r))
  60. #define SMC_insw(a, r, p, l) readsw((a) + (r), p, l)
  61. #define SMC_outsw(a, r, p, l) writesw((a) + (r), p, l)
  62. #define SMC_insl(a, r, p, l) readsl((a) + (r), p, l)
  63. #define SMC_outsl(a, r, p, l) writesl((a) + (r), p, l)
  64. #define SMC_IRQ_FLAGS (-1) /* from resource */
  65. /* We actually can't write halfwords properly if not word aligned */
  66. static inline void SMC_outw(u16 val, void __iomem *ioaddr, int reg)
  67. {
  68. if (machine_is_mainstone() && reg & 2) {
  69. unsigned int v = val << 16;
  70. v |= readl(ioaddr + (reg & ~2)) & 0xffff;
  71. writel(v, ioaddr + (reg & ~2));
  72. } else {
  73. writew(val, ioaddr + reg);
  74. }
  75. }
  76. #elif defined(CONFIG_BLACKFIN)
  77. #define SMC_IRQ_FLAGS IRQF_TRIGGER_HIGH
  78. #define RPC_LSA_DEFAULT RPC_LED_100_10
  79. #define RPC_LSB_DEFAULT RPC_LED_TX_RX
  80. #define SMC_CAN_USE_8BIT 0
  81. #define SMC_CAN_USE_16BIT 1
  82. # if defined(CONFIG_BF561)
  83. #define SMC_CAN_USE_32BIT 1
  84. # else
  85. #define SMC_CAN_USE_32BIT 0
  86. # endif
  87. #define SMC_IO_SHIFT 0
  88. #define SMC_NOWAIT 1
  89. #define SMC_USE_BFIN_DMA 0
  90. #define SMC_inw(a, r) readw((a) + (r))
  91. #define SMC_outw(v, a, r) writew(v, (a) + (r))
  92. #define SMC_insw(a, r, p, l) readsw((a) + (r), p, l)
  93. #define SMC_outsw(a, r, p, l) writesw((a) + (r), p, l)
  94. # if SMC_CAN_USE_32BIT
  95. #define SMC_inl(a, r) readl((a) + (r))
  96. #define SMC_outl(v, a, r) writel(v, (a) + (r))
  97. #define SMC_insl(a, r, p, l) readsl((a) + (r), p, l)
  98. #define SMC_outsl(a, r, p, l) writesl((a) + (r), p, l)
  99. # endif
  100. #elif defined(CONFIG_REDWOOD_5) || defined(CONFIG_REDWOOD_6)
  101. /* We can only do 16-bit reads and writes in the static memory space. */
  102. #define SMC_CAN_USE_8BIT 0
  103. #define SMC_CAN_USE_16BIT 1
  104. #define SMC_CAN_USE_32BIT 0
  105. #define SMC_NOWAIT 1
  106. #define SMC_IO_SHIFT 0
  107. #define SMC_inw(a, r) in_be16((volatile u16 *)((a) + (r)))
  108. #define SMC_outw(v, a, r) out_be16((volatile u16 *)((a) + (r)), v)
  109. #define SMC_insw(a, r, p, l) \
  110. do { \
  111. unsigned long __port = (a) + (r); \
  112. u16 *__p = (u16 *)(p); \
  113. int __l = (l); \
  114. insw(__port, __p, __l); \
  115. while (__l > 0) { \
  116. *__p = swab16(*__p); \
  117. __p++; \
  118. __l--; \
  119. } \
  120. } while (0)
  121. #define SMC_outsw(a, r, p, l) \
  122. do { \
  123. unsigned long __port = (a) + (r); \
  124. u16 *__p = (u16 *)(p); \
  125. int __l = (l); \
  126. while (__l > 0) { \
  127. /* Believe it or not, the swab isn't needed. */ \
  128. outw( /* swab16 */ (*__p++), __port); \
  129. __l--; \
  130. } \
  131. } while (0)
  132. #define SMC_IRQ_FLAGS (0)
  133. #elif defined(CONFIG_SA1100_PLEB)
  134. /* We can only do 16-bit reads and writes in the static memory space. */
  135. #define SMC_CAN_USE_8BIT 1
  136. #define SMC_CAN_USE_16BIT 1
  137. #define SMC_CAN_USE_32BIT 0
  138. #define SMC_IO_SHIFT 0
  139. #define SMC_NOWAIT 1
  140. #define SMC_inb(a, r) readb((a) + (r))
  141. #define SMC_insb(a, r, p, l) readsb((a) + (r), p, (l))
  142. #define SMC_inw(a, r) readw((a) + (r))
  143. #define SMC_insw(a, r, p, l) readsw((a) + (r), p, l)
  144. #define SMC_outb(v, a, r) writeb(v, (a) + (r))
  145. #define SMC_outsb(a, r, p, l) writesb((a) + (r), p, (l))
  146. #define SMC_outw(v, a, r) writew(v, (a) + (r))
  147. #define SMC_outsw(a, r, p, l) writesw((a) + (r), p, l)
  148. #define SMC_IRQ_FLAGS (-1)
  149. #elif defined(CONFIG_SA1100_ASSABET)
  150. #include <mach/neponset.h>
  151. /* We can only do 8-bit reads and writes in the static memory space. */
  152. #define SMC_CAN_USE_8BIT 1
  153. #define SMC_CAN_USE_16BIT 0
  154. #define SMC_CAN_USE_32BIT 0
  155. #define SMC_NOWAIT 1
  156. /* The first two address lines aren't connected... */
  157. #define SMC_IO_SHIFT 2
  158. #define SMC_inb(a, r) readb((a) + (r))
  159. #define SMC_outb(v, a, r) writeb(v, (a) + (r))
  160. #define SMC_insb(a, r, p, l) readsb((a) + (r), p, (l))
  161. #define SMC_outsb(a, r, p, l) writesb((a) + (r), p, (l))
  162. #define SMC_IRQ_FLAGS (-1) /* from resource */
  163. #elif defined(CONFIG_MACH_LOGICPD_PXA270)
  164. #define SMC_CAN_USE_8BIT 0
  165. #define SMC_CAN_USE_16BIT 1
  166. #define SMC_CAN_USE_32BIT 0
  167. #define SMC_IO_SHIFT 0
  168. #define SMC_NOWAIT 1
  169. #define SMC_inw(a, r) readw((a) + (r))
  170. #define SMC_outw(v, a, r) writew(v, (a) + (r))
  171. #define SMC_insw(a, r, p, l) readsw((a) + (r), p, l)
  172. #define SMC_outsw(a, r, p, l) writesw((a) + (r), p, l)
  173. #elif defined(CONFIG_ARCH_INNOKOM) || \
  174. defined(CONFIG_ARCH_PXA_IDP) || \
  175. defined(CONFIG_ARCH_RAMSES) || \
  176. defined(CONFIG_ARCH_PCM027)
  177. #define SMC_CAN_USE_8BIT 1
  178. #define SMC_CAN_USE_16BIT 1
  179. #define SMC_CAN_USE_32BIT 1
  180. #define SMC_IO_SHIFT 0
  181. #define SMC_NOWAIT 1
  182. #define SMC_USE_PXA_DMA 1
  183. #define SMC_inb(a, r) readb((a) + (r))
  184. #define SMC_inw(a, r) readw((a) + (r))
  185. #define SMC_inl(a, r) readl((a) + (r))
  186. #define SMC_outb(v, a, r) writeb(v, (a) + (r))
  187. #define SMC_outl(v, a, r) writel(v, (a) + (r))
  188. #define SMC_insl(a, r, p, l) readsl((a) + (r), p, l)
  189. #define SMC_outsl(a, r, p, l) writesl((a) + (r), p, l)
  190. #define SMC_IRQ_FLAGS (-1) /* from resource */
  191. /* We actually can't write halfwords properly if not word aligned */
  192. static inline void
  193. SMC_outw(u16 val, void __iomem *ioaddr, int reg)
  194. {
  195. if (reg & 2) {
  196. unsigned int v = val << 16;
  197. v |= readl(ioaddr + (reg & ~2)) & 0xffff;
  198. writel(v, ioaddr + (reg & ~2));
  199. } else {
  200. writew(val, ioaddr + reg);
  201. }
  202. }
  203. #elif defined(CONFIG_ARCH_OMAP)
  204. /* We can only do 16-bit reads and writes in the static memory space. */
  205. #define SMC_CAN_USE_8BIT 0
  206. #define SMC_CAN_USE_16BIT 1
  207. #define SMC_CAN_USE_32BIT 0
  208. #define SMC_IO_SHIFT 0
  209. #define SMC_NOWAIT 1
  210. #define SMC_inw(a, r) readw((a) + (r))
  211. #define SMC_outw(v, a, r) writew(v, (a) + (r))
  212. #define SMC_insw(a, r, p, l) readsw((a) + (r), p, l)
  213. #define SMC_outsw(a, r, p, l) writesw((a) + (r), p, l)
  214. #define SMC_IRQ_FLAGS (-1) /* from resource */
  215. #elif defined(CONFIG_SH_SH4202_MICRODEV)
  216. #define SMC_CAN_USE_8BIT 0
  217. #define SMC_CAN_USE_16BIT 1
  218. #define SMC_CAN_USE_32BIT 0
  219. #define SMC_inb(a, r) inb((a) + (r) - 0xa0000000)
  220. #define SMC_inw(a, r) inw((a) + (r) - 0xa0000000)
  221. #define SMC_inl(a, r) inl((a) + (r) - 0xa0000000)
  222. #define SMC_outb(v, a, r) outb(v, (a) + (r) - 0xa0000000)
  223. #define SMC_outw(v, a, r) outw(v, (a) + (r) - 0xa0000000)
  224. #define SMC_outl(v, a, r) outl(v, (a) + (r) - 0xa0000000)
  225. #define SMC_insl(a, r, p, l) insl((a) + (r) - 0xa0000000, p, l)
  226. #define SMC_outsl(a, r, p, l) outsl((a) + (r) - 0xa0000000, p, l)
  227. #define SMC_insw(a, r, p, l) insw((a) + (r) - 0xa0000000, p, l)
  228. #define SMC_outsw(a, r, p, l) outsw((a) + (r) - 0xa0000000, p, l)
  229. #define SMC_IRQ_FLAGS (0)
  230. #elif defined(CONFIG_M32R)
  231. #define SMC_CAN_USE_8BIT 0
  232. #define SMC_CAN_USE_16BIT 1
  233. #define SMC_CAN_USE_32BIT 0
  234. #define SMC_inb(a, r) inb(((u32)a) + (r))
  235. #define SMC_inw(a, r) inw(((u32)a) + (r))
  236. #define SMC_outb(v, a, r) outb(v, ((u32)a) + (r))
  237. #define SMC_outw(v, a, r) outw(v, ((u32)a) + (r))
  238. #define SMC_insw(a, r, p, l) insw(((u32)a) + (r), p, l)
  239. #define SMC_outsw(a, r, p, l) outsw(((u32)a) + (r), p, l)
  240. #define SMC_IRQ_FLAGS (0)
  241. #define RPC_LSA_DEFAULT RPC_LED_TX_RX
  242. #define RPC_LSB_DEFAULT RPC_LED_100_10
  243. #elif defined(CONFIG_MACH_LPD79520) \
  244. || defined(CONFIG_MACH_LPD7A400) \
  245. || defined(CONFIG_MACH_LPD7A404)
  246. /* The LPD7X_IOBARRIER is necessary to overcome a mismatch between the
  247. * way that the CPU handles chip selects and the way that the SMC chip
  248. * expects the chip select to operate. Refer to
  249. * Documentation/arm/Sharp-LH/IOBarrier for details. The read from
  250. * IOBARRIER is a byte, in order that we read the least-common
  251. * denominator. It would be wasteful to read 32 bits from an 8-bit
  252. * accessible region.
  253. *
  254. * There is no explicit protection against interrupts intervening
  255. * between the writew and the IOBARRIER. In SMC ISR there is a
  256. * preamble that performs an IOBARRIER in the extremely unlikely event
  257. * that the driver interrupts itself between a writew to the chip an
  258. * the IOBARRIER that follows *and* the cache is large enough that the
  259. * first off-chip access while handing the interrupt is to the SMC
  260. * chip. Other devices in the same address space as the SMC chip must
  261. * be aware of the potential for trouble and perform a similar
  262. * IOBARRIER on entry to their ISR.
  263. */
  264. #include <mach/constants.h> /* IOBARRIER_VIRT */
  265. #define SMC_CAN_USE_8BIT 0
  266. #define SMC_CAN_USE_16BIT 1
  267. #define SMC_CAN_USE_32BIT 0
  268. #define SMC_NOWAIT 0
  269. #define LPD7X_IOBARRIER readb (IOBARRIER_VIRT)
  270. #define SMC_inw(a,r)\
  271. ({ unsigned short v = readw ((void*) ((a) + (r))); LPD7X_IOBARRIER; v; })
  272. #define SMC_outw(v,a,r) ({ writew ((v), (a) + (r)); LPD7X_IOBARRIER; })
  273. #define SMC_insw LPD7_SMC_insw
  274. static inline void LPD7_SMC_insw (unsigned char* a, int r,
  275. unsigned char* p, int l)
  276. {
  277. unsigned short* ps = (unsigned short*) p;
  278. while (l-- > 0) {
  279. *ps++ = readw (a + r);
  280. LPD7X_IOBARRIER;
  281. }
  282. }
  283. #define SMC_outsw LPD7_SMC_outsw
  284. static inline void LPD7_SMC_outsw (unsigned char* a, int r,
  285. unsigned char* p, int l)
  286. {
  287. unsigned short* ps = (unsigned short*) p;
  288. while (l-- > 0) {
  289. writew (*ps++, a + r);
  290. LPD7X_IOBARRIER;
  291. }
  292. }
  293. #define SMC_INTERRUPT_PREAMBLE LPD7X_IOBARRIER
  294. #define RPC_LSA_DEFAULT RPC_LED_TX_RX
  295. #define RPC_LSB_DEFAULT RPC_LED_100_10
  296. #elif defined(CONFIG_SOC_AU1X00)
  297. #include <au1xxx.h>
  298. /* We can only do 16-bit reads and writes in the static memory space. */
  299. #define SMC_CAN_USE_8BIT 0
  300. #define SMC_CAN_USE_16BIT 1
  301. #define SMC_CAN_USE_32BIT 0
  302. #define SMC_IO_SHIFT 0
  303. #define SMC_NOWAIT 1
  304. #define SMC_inw(a, r) au_readw((unsigned long)((a) + (r)))
  305. #define SMC_insw(a, r, p, l) \
  306. do { \
  307. unsigned long _a = (unsigned long)((a) + (r)); \
  308. int _l = (l); \
  309. u16 *_p = (u16 *)(p); \
  310. while (_l-- > 0) \
  311. *_p++ = au_readw(_a); \
  312. } while(0)
  313. #define SMC_outw(v, a, r) au_writew(v, (unsigned long)((a) + (r)))
  314. #define SMC_outsw(a, r, p, l) \
  315. do { \
  316. unsigned long _a = (unsigned long)((a) + (r)); \
  317. int _l = (l); \
  318. const u16 *_p = (const u16 *)(p); \
  319. while (_l-- > 0) \
  320. au_writew(*_p++ , _a); \
  321. } while(0)
  322. #define SMC_IRQ_FLAGS (0)
  323. #elif defined(CONFIG_ARCH_VERSATILE)
  324. #define SMC_CAN_USE_8BIT 1
  325. #define SMC_CAN_USE_16BIT 1
  326. #define SMC_CAN_USE_32BIT 1
  327. #define SMC_NOWAIT 1
  328. #define SMC_inb(a, r) readb((a) + (r))
  329. #define SMC_inw(a, r) readw((a) + (r))
  330. #define SMC_inl(a, r) readl((a) + (r))
  331. #define SMC_outb(v, a, r) writeb(v, (a) + (r))
  332. #define SMC_outw(v, a, r) writew(v, (a) + (r))
  333. #define SMC_outl(v, a, r) writel(v, (a) + (r))
  334. #define SMC_insl(a, r, p, l) readsl((a) + (r), p, l)
  335. #define SMC_outsl(a, r, p, l) writesl((a) + (r), p, l)
  336. #define SMC_IRQ_FLAGS (-1) /* from resource */
  337. #elif defined(CONFIG_MN10300)
  338. /*
  339. * MN10300/AM33 configuration
  340. */
  341. #include <asm/unit/smc91111.h>
  342. #else
  343. /*
  344. * Default configuration
  345. */
  346. #define SMC_CAN_USE_8BIT 1
  347. #define SMC_CAN_USE_16BIT 1
  348. #define SMC_CAN_USE_32BIT 1
  349. #define SMC_NOWAIT 1
  350. #define SMC_IO_SHIFT (lp->io_shift)
  351. #define SMC_inb(a, r) readb((a) + (r))
  352. #define SMC_inw(a, r) readw((a) + (r))
  353. #define SMC_inl(a, r) readl((a) + (r))
  354. #define SMC_outb(v, a, r) writeb(v, (a) + (r))
  355. #define SMC_outw(v, a, r) writew(v, (a) + (r))
  356. #define SMC_outl(v, a, r) writel(v, (a) + (r))
  357. #define SMC_insw(a, r, p, l) readsw((a) + (r), p, l)
  358. #define SMC_outsw(a, r, p, l) writesw((a) + (r), p, l)
  359. #define SMC_insl(a, r, p, l) readsl((a) + (r), p, l)
  360. #define SMC_outsl(a, r, p, l) writesl((a) + (r), p, l)
  361. #define RPC_LSA_DEFAULT RPC_LED_100_10
  362. #define RPC_LSB_DEFAULT RPC_LED_TX_RX
  363. #endif
  364. /* store this information for the driver.. */
  365. struct smc_local {
  366. /*
  367. * If I have to wait until memory is available to send a
  368. * packet, I will store the skbuff here, until I get the
  369. * desired memory. Then, I'll send it out and free it.
  370. */
  371. struct sk_buff *pending_tx_skb;
  372. struct tasklet_struct tx_task;
  373. /* version/revision of the SMC91x chip */
  374. int version;
  375. /* Contains the current active transmission mode */
  376. int tcr_cur_mode;
  377. /* Contains the current active receive mode */
  378. int rcr_cur_mode;
  379. /* Contains the current active receive/phy mode */
  380. int rpc_cur_mode;
  381. int ctl_rfduplx;
  382. int ctl_rspeed;
  383. u32 msg_enable;
  384. u32 phy_type;
  385. struct mii_if_info mii;
  386. /* work queue */
  387. struct work_struct phy_configure;
  388. struct net_device *dev;
  389. int work_pending;
  390. spinlock_t lock;
  391. #ifdef CONFIG_ARCH_PXA
  392. /* DMA needs the physical address of the chip */
  393. u_long physaddr;
  394. struct device *device;
  395. #endif
  396. void __iomem *base;
  397. void __iomem *datacs;
  398. /* the low address lines on some platforms aren't connected... */
  399. int io_shift;
  400. struct smc91x_platdata cfg;
  401. };
  402. #define SMC_8BIT(p) ((p)->cfg.flags & SMC91X_USE_8BIT)
  403. #define SMC_16BIT(p) ((p)->cfg.flags & SMC91X_USE_16BIT)
  404. #define SMC_32BIT(p) ((p)->cfg.flags & SMC91X_USE_32BIT)
  405. #ifdef CONFIG_ARCH_PXA
  406. /*
  407. * Let's use the DMA engine on the XScale PXA2xx for RX packets. This is
  408. * always happening in irq context so no need to worry about races. TX is
  409. * different and probably not worth it for that reason, and not as critical
  410. * as RX which can overrun memory and lose packets.
  411. */
  412. #include <linux/dma-mapping.h>
  413. #include <mach/dma.h>
  414. #ifdef SMC_insl
  415. #undef SMC_insl
  416. #define SMC_insl(a, r, p, l) \
  417. smc_pxa_dma_insl(a, lp, r, dev->dma, p, l)
  418. static inline void
  419. smc_pxa_dma_insl(void __iomem *ioaddr, struct smc_local *lp, int reg, int dma,
  420. u_char *buf, int len)
  421. {
  422. u_long physaddr = lp->physaddr;
  423. dma_addr_t dmabuf;
  424. /* fallback if no DMA available */
  425. if (dma == (unsigned char)-1) {
  426. readsl(ioaddr + reg, buf, len);
  427. return;
  428. }
  429. /* 64 bit alignment is required for memory to memory DMA */
  430. if ((long)buf & 4) {
  431. *((u32 *)buf) = SMC_inl(ioaddr, reg);
  432. buf += 4;
  433. len--;
  434. }
  435. len *= 4;
  436. dmabuf = dma_map_single(lp->device, buf, len, DMA_FROM_DEVICE);
  437. DCSR(dma) = DCSR_NODESC;
  438. DTADR(dma) = dmabuf;
  439. DSADR(dma) = physaddr + reg;
  440. DCMD(dma) = (DCMD_INCTRGADDR | DCMD_BURST32 |
  441. DCMD_WIDTH4 | (DCMD_LENGTH & len));
  442. DCSR(dma) = DCSR_NODESC | DCSR_RUN;
  443. while (!(DCSR(dma) & DCSR_STOPSTATE))
  444. cpu_relax();
  445. DCSR(dma) = 0;
  446. dma_unmap_single(lp->device, dmabuf, len, DMA_FROM_DEVICE);
  447. }
  448. #endif
  449. #ifdef SMC_insw
  450. #undef SMC_insw
  451. #define SMC_insw(a, r, p, l) \
  452. smc_pxa_dma_insw(a, lp, r, dev->dma, p, l)
  453. static inline void
  454. smc_pxa_dma_insw(void __iomem *ioaddr, struct smc_local *lp, int reg, int dma,
  455. u_char *buf, int len)
  456. {
  457. u_long physaddr = lp->physaddr;
  458. dma_addr_t dmabuf;
  459. /* fallback if no DMA available */
  460. if (dma == (unsigned char)-1) {
  461. readsw(ioaddr + reg, buf, len);
  462. return;
  463. }
  464. /* 64 bit alignment is required for memory to memory DMA */
  465. while ((long)buf & 6) {
  466. *((u16 *)buf) = SMC_inw(ioaddr, reg);
  467. buf += 2;
  468. len--;
  469. }
  470. len *= 2;
  471. dmabuf = dma_map_single(lp->device, buf, len, DMA_FROM_DEVICE);
  472. DCSR(dma) = DCSR_NODESC;
  473. DTADR(dma) = dmabuf;
  474. DSADR(dma) = physaddr + reg;
  475. DCMD(dma) = (DCMD_INCTRGADDR | DCMD_BURST32 |
  476. DCMD_WIDTH2 | (DCMD_LENGTH & len));
  477. DCSR(dma) = DCSR_NODESC | DCSR_RUN;
  478. while (!(DCSR(dma) & DCSR_STOPSTATE))
  479. cpu_relax();
  480. DCSR(dma) = 0;
  481. dma_unmap_single(lp->device, dmabuf, len, DMA_FROM_DEVICE);
  482. }
  483. #endif
  484. static void
  485. smc_pxa_dma_irq(int dma, void *dummy)
  486. {
  487. DCSR(dma) = 0;
  488. }
  489. #endif /* CONFIG_ARCH_PXA */
  490. /*
  491. * Everything a particular hardware setup needs should have been defined
  492. * at this point. Add stubs for the undefined cases, mainly to avoid
  493. * compilation warnings since they'll be optimized away, or to prevent buggy
  494. * use of them.
  495. */
  496. #if ! SMC_CAN_USE_32BIT
  497. #define SMC_inl(ioaddr, reg) ({ BUG(); 0; })
  498. #define SMC_outl(x, ioaddr, reg) BUG()
  499. #define SMC_insl(a, r, p, l) BUG()
  500. #define SMC_outsl(a, r, p, l) BUG()
  501. #endif
  502. #if !defined(SMC_insl) || !defined(SMC_outsl)
  503. #define SMC_insl(a, r, p, l) BUG()
  504. #define SMC_outsl(a, r, p, l) BUG()
  505. #endif
  506. #if ! SMC_CAN_USE_16BIT
  507. /*
  508. * Any 16-bit access is performed with two 8-bit accesses if the hardware
  509. * can't do it directly. Most registers are 16-bit so those are mandatory.
  510. */
  511. #define SMC_outw(x, ioaddr, reg) \
  512. do { \
  513. unsigned int __val16 = (x); \
  514. SMC_outb( __val16, ioaddr, reg ); \
  515. SMC_outb( __val16 >> 8, ioaddr, reg + (1 << SMC_IO_SHIFT));\
  516. } while (0)
  517. #define SMC_inw(ioaddr, reg) \
  518. ({ \
  519. unsigned int __val16; \
  520. __val16 = SMC_inb( ioaddr, reg ); \
  521. __val16 |= SMC_inb( ioaddr, reg + (1 << SMC_IO_SHIFT)) << 8; \
  522. __val16; \
  523. })
  524. #define SMC_insw(a, r, p, l) BUG()
  525. #define SMC_outsw(a, r, p, l) BUG()
  526. #endif
  527. #if !defined(SMC_insw) || !defined(SMC_outsw)
  528. #define SMC_insw(a, r, p, l) BUG()
  529. #define SMC_outsw(a, r, p, l) BUG()
  530. #endif
  531. #if ! SMC_CAN_USE_8BIT
  532. #define SMC_inb(ioaddr, reg) ({ BUG(); 0; })
  533. #define SMC_outb(x, ioaddr, reg) BUG()
  534. #define SMC_insb(a, r, p, l) BUG()
  535. #define SMC_outsb(a, r, p, l) BUG()
  536. #endif
  537. #if !defined(SMC_insb) || !defined(SMC_outsb)
  538. #define SMC_insb(a, r, p, l) BUG()
  539. #define SMC_outsb(a, r, p, l) BUG()
  540. #endif
  541. #ifndef SMC_CAN_USE_DATACS
  542. #define SMC_CAN_USE_DATACS 0
  543. #endif
  544. #ifndef SMC_IO_SHIFT
  545. #define SMC_IO_SHIFT 0
  546. #endif
  547. #ifndef SMC_IRQ_FLAGS
  548. #define SMC_IRQ_FLAGS IRQF_TRIGGER_RISING
  549. #endif
  550. #ifndef SMC_INTERRUPT_PREAMBLE
  551. #define SMC_INTERRUPT_PREAMBLE
  552. #endif
  553. /* Because of bank switching, the LAN91x uses only 16 I/O ports */
  554. #define SMC_IO_EXTENT (16 << SMC_IO_SHIFT)
  555. #define SMC_DATA_EXTENT (4)
  556. /*
  557. . Bank Select Register:
  558. .
  559. . yyyy yyyy 0000 00xx
  560. . xx = bank number
  561. . yyyy yyyy = 0x33, for identification purposes.
  562. */
  563. #define BANK_SELECT (14 << SMC_IO_SHIFT)
  564. // Transmit Control Register
  565. /* BANK 0 */
  566. #define TCR_REG(lp) SMC_REG(lp, 0x0000, 0)
  567. #define TCR_ENABLE 0x0001 // When 1 we can transmit
  568. #define TCR_LOOP 0x0002 // Controls output pin LBK
  569. #define TCR_FORCOL 0x0004 // When 1 will force a collision
  570. #define TCR_PAD_EN 0x0080 // When 1 will pad tx frames < 64 bytes w/0
  571. #define TCR_NOCRC 0x0100 // When 1 will not append CRC to tx frames
  572. #define TCR_MON_CSN 0x0400 // When 1 tx monitors carrier
  573. #define TCR_FDUPLX 0x0800 // When 1 enables full duplex operation
  574. #define TCR_STP_SQET 0x1000 // When 1 stops tx if Signal Quality Error
  575. #define TCR_EPH_LOOP 0x2000 // When 1 enables EPH block loopback
  576. #define TCR_SWFDUP 0x8000 // When 1 enables Switched Full Duplex mode
  577. #define TCR_CLEAR 0 /* do NOTHING */
  578. /* the default settings for the TCR register : */
  579. #define TCR_DEFAULT (TCR_ENABLE | TCR_PAD_EN)
  580. // EPH Status Register
  581. /* BANK 0 */
  582. #define EPH_STATUS_REG(lp) SMC_REG(lp, 0x0002, 0)
  583. #define ES_TX_SUC 0x0001 // Last TX was successful
  584. #define ES_SNGL_COL 0x0002 // Single collision detected for last tx
  585. #define ES_MUL_COL 0x0004 // Multiple collisions detected for last tx
  586. #define ES_LTX_MULT 0x0008 // Last tx was a multicast
  587. #define ES_16COL 0x0010 // 16 Collisions Reached
  588. #define ES_SQET 0x0020 // Signal Quality Error Test
  589. #define ES_LTXBRD 0x0040 // Last tx was a broadcast
  590. #define ES_TXDEFR 0x0080 // Transmit Deferred
  591. #define ES_LATCOL 0x0200 // Late collision detected on last tx
  592. #define ES_LOSTCARR 0x0400 // Lost Carrier Sense
  593. #define ES_EXC_DEF 0x0800 // Excessive Deferral
  594. #define ES_CTR_ROL 0x1000 // Counter Roll Over indication
  595. #define ES_LINK_OK 0x4000 // Driven by inverted value of nLNK pin
  596. #define ES_TXUNRN 0x8000 // Tx Underrun
  597. // Receive Control Register
  598. /* BANK 0 */
  599. #define RCR_REG(lp) SMC_REG(lp, 0x0004, 0)
  600. #define RCR_RX_ABORT 0x0001 // Set if a rx frame was aborted
  601. #define RCR_PRMS 0x0002 // Enable promiscuous mode
  602. #define RCR_ALMUL 0x0004 // When set accepts all multicast frames
  603. #define RCR_RXEN 0x0100 // IFF this is set, we can receive packets
  604. #define RCR_STRIP_CRC 0x0200 // When set strips CRC from rx packets
  605. #define RCR_ABORT_ENB 0x0200 // When set will abort rx on collision
  606. #define RCR_FILT_CAR 0x0400 // When set filters leading 12 bit s of carrier
  607. #define RCR_SOFTRST 0x8000 // resets the chip
  608. /* the normal settings for the RCR register : */
  609. #define RCR_DEFAULT (RCR_STRIP_CRC | RCR_RXEN)
  610. #define RCR_CLEAR 0x0 // set it to a base state
  611. // Counter Register
  612. /* BANK 0 */
  613. #define COUNTER_REG(lp) SMC_REG(lp, 0x0006, 0)
  614. // Memory Information Register
  615. /* BANK 0 */
  616. #define MIR_REG(lp) SMC_REG(lp, 0x0008, 0)
  617. // Receive/Phy Control Register
  618. /* BANK 0 */
  619. #define RPC_REG(lp) SMC_REG(lp, 0x000A, 0)
  620. #define RPC_SPEED 0x2000 // When 1 PHY is in 100Mbps mode.
  621. #define RPC_DPLX 0x1000 // When 1 PHY is in Full-Duplex Mode
  622. #define RPC_ANEG 0x0800 // When 1 PHY is in Auto-Negotiate Mode
  623. #define RPC_LSXA_SHFT 5 // Bits to shift LS2A,LS1A,LS0A to lsb
  624. #define RPC_LSXB_SHFT 2 // Bits to get LS2B,LS1B,LS0B to lsb
  625. #ifndef RPC_LSA_DEFAULT
  626. #define RPC_LSA_DEFAULT RPC_LED_100
  627. #endif
  628. #ifndef RPC_LSB_DEFAULT
  629. #define RPC_LSB_DEFAULT RPC_LED_FD
  630. #endif
  631. #define RPC_DEFAULT (RPC_ANEG | RPC_SPEED | RPC_DPLX)
  632. /* Bank 0 0x0C is reserved */
  633. // Bank Select Register
  634. /* All Banks */
  635. #define BSR_REG 0x000E
  636. // Configuration Reg
  637. /* BANK 1 */
  638. #define CONFIG_REG(lp) SMC_REG(lp, 0x0000, 1)
  639. #define CONFIG_EXT_PHY 0x0200 // 1=external MII, 0=internal Phy
  640. #define CONFIG_GPCNTRL 0x0400 // Inverse value drives pin nCNTRL
  641. #define CONFIG_NO_WAIT 0x1000 // When 1 no extra wait states on ISA bus
  642. #define CONFIG_EPH_POWER_EN 0x8000 // When 0 EPH is placed into low power mode.
  643. // Default is powered-up, Internal Phy, Wait States, and pin nCNTRL=low
  644. #define CONFIG_DEFAULT (CONFIG_EPH_POWER_EN)
  645. // Base Address Register
  646. /* BANK 1 */
  647. #define BASE_REG(lp) SMC_REG(lp, 0x0002, 1)
  648. // Individual Address Registers
  649. /* BANK 1 */
  650. #define ADDR0_REG(lp) SMC_REG(lp, 0x0004, 1)
  651. #define ADDR1_REG(lp) SMC_REG(lp, 0x0006, 1)
  652. #define ADDR2_REG(lp) SMC_REG(lp, 0x0008, 1)
  653. // General Purpose Register
  654. /* BANK 1 */
  655. #define GP_REG(lp) SMC_REG(lp, 0x000A, 1)
  656. // Control Register
  657. /* BANK 1 */
  658. #define CTL_REG(lp) SMC_REG(lp, 0x000C, 1)
  659. #define CTL_RCV_BAD 0x4000 // When 1 bad CRC packets are received
  660. #define CTL_AUTO_RELEASE 0x0800 // When 1 tx pages are released automatically
  661. #define CTL_LE_ENABLE 0x0080 // When 1 enables Link Error interrupt
  662. #define CTL_CR_ENABLE 0x0040 // When 1 enables Counter Rollover interrupt
  663. #define CTL_TE_ENABLE 0x0020 // When 1 enables Transmit Error interrupt
  664. #define CTL_EEPROM_SELECT 0x0004 // Controls EEPROM reload & store
  665. #define CTL_RELOAD 0x0002 // When set reads EEPROM into registers
  666. #define CTL_STORE 0x0001 // When set stores registers into EEPROM
  667. // MMU Command Register
  668. /* BANK 2 */
  669. #define MMU_CMD_REG(lp) SMC_REG(lp, 0x0000, 2)
  670. #define MC_BUSY 1 // When 1 the last release has not completed
  671. #define MC_NOP (0<<5) // No Op
  672. #define MC_ALLOC (1<<5) // OR with number of 256 byte packets
  673. #define MC_RESET (2<<5) // Reset MMU to initial state
  674. #define MC_REMOVE (3<<5) // Remove the current rx packet
  675. #define MC_RELEASE (4<<5) // Remove and release the current rx packet
  676. #define MC_FREEPKT (5<<5) // Release packet in PNR register
  677. #define MC_ENQUEUE (6<<5) // Enqueue the packet for transmit
  678. #define MC_RSTTXFIFO (7<<5) // Reset the TX FIFOs
  679. // Packet Number Register
  680. /* BANK 2 */
  681. #define PN_REG(lp) SMC_REG(lp, 0x0002, 2)
  682. // Allocation Result Register
  683. /* BANK 2 */
  684. #define AR_REG(lp) SMC_REG(lp, 0x0003, 2)
  685. #define AR_FAILED 0x80 // Alocation Failed
  686. // TX FIFO Ports Register
  687. /* BANK 2 */
  688. #define TXFIFO_REG(lp) SMC_REG(lp, 0x0004, 2)
  689. #define TXFIFO_TEMPTY 0x80 // TX FIFO Empty
  690. // RX FIFO Ports Register
  691. /* BANK 2 */
  692. #define RXFIFO_REG(lp) SMC_REG(lp, 0x0005, 2)
  693. #define RXFIFO_REMPTY 0x80 // RX FIFO Empty
  694. #define FIFO_REG(lp) SMC_REG(lp, 0x0004, 2)
  695. // Pointer Register
  696. /* BANK 2 */
  697. #define PTR_REG(lp) SMC_REG(lp, 0x0006, 2)
  698. #define PTR_RCV 0x8000 // 1=Receive area, 0=Transmit area
  699. #define PTR_AUTOINC 0x4000 // Auto increment the pointer on each access
  700. #define PTR_READ 0x2000 // When 1 the operation is a read
  701. // Data Register
  702. /* BANK 2 */
  703. #define DATA_REG(lp) SMC_REG(lp, 0x0008, 2)
  704. // Interrupt Status/Acknowledge Register
  705. /* BANK 2 */
  706. #define INT_REG(lp) SMC_REG(lp, 0x000C, 2)
  707. // Interrupt Mask Register
  708. /* BANK 2 */
  709. #define IM_REG(lp) SMC_REG(lp, 0x000D, 2)
  710. #define IM_MDINT 0x80 // PHY MI Register 18 Interrupt
  711. #define IM_ERCV_INT 0x40 // Early Receive Interrupt
  712. #define IM_EPH_INT 0x20 // Set by Ethernet Protocol Handler section
  713. #define IM_RX_OVRN_INT 0x10 // Set by Receiver Overruns
  714. #define IM_ALLOC_INT 0x08 // Set when allocation request is completed
  715. #define IM_TX_EMPTY_INT 0x04 // Set if the TX FIFO goes empty
  716. #define IM_TX_INT 0x02 // Transmit Interrupt
  717. #define IM_RCV_INT 0x01 // Receive Interrupt
  718. // Multicast Table Registers
  719. /* BANK 3 */
  720. #define MCAST_REG1(lp) SMC_REG(lp, 0x0000, 3)
  721. #define MCAST_REG2(lp) SMC_REG(lp, 0x0002, 3)
  722. #define MCAST_REG3(lp) SMC_REG(lp, 0x0004, 3)
  723. #define MCAST_REG4(lp) SMC_REG(lp, 0x0006, 3)
  724. // Management Interface Register (MII)
  725. /* BANK 3 */
  726. #define MII_REG(lp) SMC_REG(lp, 0x0008, 3)
  727. #define MII_MSK_CRS100 0x4000 // Disables CRS100 detection during tx half dup
  728. #define MII_MDOE 0x0008 // MII Output Enable
  729. #define MII_MCLK 0x0004 // MII Clock, pin MDCLK
  730. #define MII_MDI 0x0002 // MII Input, pin MDI
  731. #define MII_MDO 0x0001 // MII Output, pin MDO
  732. // Revision Register
  733. /* BANK 3 */
  734. /* ( hi: chip id low: rev # ) */
  735. #define REV_REG(lp) SMC_REG(lp, 0x000A, 3)
  736. // Early RCV Register
  737. /* BANK 3 */
  738. /* this is NOT on SMC9192 */
  739. #define ERCV_REG(lp) SMC_REG(lp, 0x000C, 3)
  740. #define ERCV_RCV_DISCRD 0x0080 // When 1 discards a packet being received
  741. #define ERCV_THRESHOLD 0x001F // ERCV Threshold Mask
  742. // External Register
  743. /* BANK 7 */
  744. #define EXT_REG(lp) SMC_REG(lp, 0x0000, 7)
  745. #define CHIP_9192 3
  746. #define CHIP_9194 4
  747. #define CHIP_9195 5
  748. #define CHIP_9196 6
  749. #define CHIP_91100 7
  750. #define CHIP_91100FD 8
  751. #define CHIP_91111FD 9
  752. static const char * chip_ids[ 16 ] = {
  753. NULL, NULL, NULL,
  754. /* 3 */ "SMC91C90/91C92",
  755. /* 4 */ "SMC91C94",
  756. /* 5 */ "SMC91C95",
  757. /* 6 */ "SMC91C96",
  758. /* 7 */ "SMC91C100",
  759. /* 8 */ "SMC91C100FD",
  760. /* 9 */ "SMC91C11xFD",
  761. NULL, NULL, NULL,
  762. NULL, NULL, NULL};
  763. /*
  764. . Receive status bits
  765. */
  766. #define RS_ALGNERR 0x8000
  767. #define RS_BRODCAST 0x4000
  768. #define RS_BADCRC 0x2000
  769. #define RS_ODDFRAME 0x1000
  770. #define RS_TOOLONG 0x0800
  771. #define RS_TOOSHORT 0x0400
  772. #define RS_MULTICAST 0x0001
  773. #define RS_ERRORS (RS_ALGNERR | RS_BADCRC | RS_TOOLONG | RS_TOOSHORT)
  774. /*
  775. * PHY IDs
  776. * LAN83C183 == LAN91C111 Internal PHY
  777. */
  778. #define PHY_LAN83C183 0x0016f840
  779. #define PHY_LAN83C180 0x02821c50
  780. /*
  781. * PHY Register Addresses (LAN91C111 Internal PHY)
  782. *
  783. * Generic PHY registers can be found in <linux/mii.h>
  784. *
  785. * These phy registers are specific to our on-board phy.
  786. */
  787. // PHY Configuration Register 1
  788. #define PHY_CFG1_REG 0x10
  789. #define PHY_CFG1_LNKDIS 0x8000 // 1=Rx Link Detect Function disabled
  790. #define PHY_CFG1_XMTDIS 0x4000 // 1=TP Transmitter Disabled
  791. #define PHY_CFG1_XMTPDN 0x2000 // 1=TP Transmitter Powered Down
  792. #define PHY_CFG1_BYPSCR 0x0400 // 1=Bypass scrambler/descrambler
  793. #define PHY_CFG1_UNSCDS 0x0200 // 1=Unscramble Idle Reception Disable
  794. #define PHY_CFG1_EQLZR 0x0100 // 1=Rx Equalizer Disabled
  795. #define PHY_CFG1_CABLE 0x0080 // 1=STP(150ohm), 0=UTP(100ohm)
  796. #define PHY_CFG1_RLVL0 0x0040 // 1=Rx Squelch level reduced by 4.5db
  797. #define PHY_CFG1_TLVL_SHIFT 2 // Transmit Output Level Adjust
  798. #define PHY_CFG1_TLVL_MASK 0x003C
  799. #define PHY_CFG1_TRF_MASK 0x0003 // Transmitter Rise/Fall time
  800. // PHY Configuration Register 2
  801. #define PHY_CFG2_REG 0x11
  802. #define PHY_CFG2_APOLDIS 0x0020 // 1=Auto Polarity Correction disabled
  803. #define PHY_CFG2_JABDIS 0x0010 // 1=Jabber disabled
  804. #define PHY_CFG2_MREG 0x0008 // 1=Multiple register access (MII mgt)
  805. #define PHY_CFG2_INTMDIO 0x0004 // 1=Interrupt signaled with MDIO pulseo
  806. // PHY Status Output (and Interrupt status) Register
  807. #define PHY_INT_REG 0x12 // Status Output (Interrupt Status)
  808. #define PHY_INT_INT 0x8000 // 1=bits have changed since last read
  809. #define PHY_INT_LNKFAIL 0x4000 // 1=Link Not detected
  810. #define PHY_INT_LOSSSYNC 0x2000 // 1=Descrambler has lost sync
  811. #define PHY_INT_CWRD 0x1000 // 1=Invalid 4B5B code detected on rx
  812. #define PHY_INT_SSD 0x0800 // 1=No Start Of Stream detected on rx
  813. #define PHY_INT_ESD 0x0400 // 1=No End Of Stream detected on rx
  814. #define PHY_INT_RPOL 0x0200 // 1=Reverse Polarity detected
  815. #define PHY_INT_JAB 0x0100 // 1=Jabber detected
  816. #define PHY_INT_SPDDET 0x0080 // 1=100Base-TX mode, 0=10Base-T mode
  817. #define PHY_INT_DPLXDET 0x0040 // 1=Device in Full Duplex
  818. // PHY Interrupt/Status Mask Register
  819. #define PHY_MASK_REG 0x13 // Interrupt Mask
  820. // Uses the same bit definitions as PHY_INT_REG
  821. /*
  822. * SMC91C96 ethernet config and status registers.
  823. * These are in the "attribute" space.
  824. */
  825. #define ECOR 0x8000
  826. #define ECOR_RESET 0x80
  827. #define ECOR_LEVEL_IRQ 0x40
  828. #define ECOR_WR_ATTRIB 0x04
  829. #define ECOR_ENABLE 0x01
  830. #define ECSR 0x8002
  831. #define ECSR_IOIS8 0x20
  832. #define ECSR_PWRDWN 0x04
  833. #define ECSR_INT 0x02
  834. #define ATTRIB_SIZE ((64*1024) << SMC_IO_SHIFT)
  835. /*
  836. * Macros to abstract register access according to the data bus
  837. * capabilities. Please use those and not the in/out primitives.
  838. * Note: the following macros do *not* select the bank -- this must
  839. * be done separately as needed in the main code. The SMC_REG() macro
  840. * only uses the bank argument for debugging purposes (when enabled).
  841. *
  842. * Note: despite inline functions being safer, everything leading to this
  843. * should preferably be macros to let BUG() display the line number in
  844. * the core source code since we're interested in the top call site
  845. * not in any inline function location.
  846. */
  847. #if SMC_DEBUG > 0
  848. #define SMC_REG(lp, reg, bank) \
  849. ({ \
  850. int __b = SMC_CURRENT_BANK(lp); \
  851. if (unlikely((__b & ~0xf0) != (0x3300 | bank))) { \
  852. printk( "%s: bank reg screwed (0x%04x)\n", \
  853. CARDNAME, __b ); \
  854. BUG(); \
  855. } \
  856. reg<<SMC_IO_SHIFT; \
  857. })
  858. #else
  859. #define SMC_REG(lp, reg, bank) (reg<<SMC_IO_SHIFT)
  860. #endif
  861. /*
  862. * Hack Alert: Some setups just can't write 8 or 16 bits reliably when not
  863. * aligned to a 32 bit boundary. I tell you that does exist!
  864. * Fortunately the affected register accesses can be easily worked around
  865. * since we can write zeroes to the preceeding 16 bits without adverse
  866. * effects and use a 32-bit access.
  867. *
  868. * Enforce it on any 32-bit capable setup for now.
  869. */
  870. #define SMC_MUST_ALIGN_WRITE(lp) SMC_32BIT(lp)
  871. #define SMC_GET_PN(lp) \
  872. (SMC_8BIT(lp) ? (SMC_inb(ioaddr, PN_REG(lp))) \
  873. : (SMC_inw(ioaddr, PN_REG(lp)) & 0xFF))
  874. #define SMC_SET_PN(lp, x) \
  875. do { \
  876. if (SMC_MUST_ALIGN_WRITE(lp)) \
  877. SMC_outl((x)<<16, ioaddr, SMC_REG(lp, 0, 2)); \
  878. else if (SMC_8BIT(lp)) \
  879. SMC_outb(x, ioaddr, PN_REG(lp)); \
  880. else \
  881. SMC_outw(x, ioaddr, PN_REG(lp)); \
  882. } while (0)
  883. #define SMC_GET_AR(lp) \
  884. (SMC_8BIT(lp) ? (SMC_inb(ioaddr, AR_REG(lp))) \
  885. : (SMC_inw(ioaddr, PN_REG(lp)) >> 8))
  886. #define SMC_GET_TXFIFO(lp) \
  887. (SMC_8BIT(lp) ? (SMC_inb(ioaddr, TXFIFO_REG(lp))) \
  888. : (SMC_inw(ioaddr, TXFIFO_REG(lp)) & 0xFF))
  889. #define SMC_GET_RXFIFO(lp) \
  890. (SMC_8BIT(lp) ? (SMC_inb(ioaddr, RXFIFO_REG(lp))) \
  891. : (SMC_inw(ioaddr, TXFIFO_REG(lp)) >> 8))
  892. #define SMC_GET_INT(lp) \
  893. (SMC_8BIT(lp) ? (SMC_inb(ioaddr, INT_REG(lp))) \
  894. : (SMC_inw(ioaddr, INT_REG(lp)) & 0xFF))
  895. #define SMC_ACK_INT(lp, x) \
  896. do { \
  897. if (SMC_8BIT(lp)) \
  898. SMC_outb(x, ioaddr, INT_REG(lp)); \
  899. else { \
  900. unsigned long __flags; \
  901. int __mask; \
  902. local_irq_save(__flags); \
  903. __mask = SMC_inw(ioaddr, INT_REG(lp)) & ~0xff; \
  904. SMC_outw(__mask | (x), ioaddr, INT_REG(lp)); \
  905. local_irq_restore(__flags); \
  906. } \
  907. } while (0)
  908. #define SMC_GET_INT_MASK(lp) \
  909. (SMC_8BIT(lp) ? (SMC_inb(ioaddr, IM_REG(lp))) \
  910. : (SMC_inw(ioaddr, INT_REG(lp)) >> 8))
  911. #define SMC_SET_INT_MASK(lp, x) \
  912. do { \
  913. if (SMC_8BIT(lp)) \
  914. SMC_outb(x, ioaddr, IM_REG(lp)); \
  915. else \
  916. SMC_outw((x) << 8, ioaddr, INT_REG(lp)); \
  917. } while (0)
  918. #define SMC_CURRENT_BANK(lp) SMC_inw(ioaddr, BANK_SELECT)
  919. #define SMC_SELECT_BANK(lp, x) \
  920. do { \
  921. if (SMC_MUST_ALIGN_WRITE(lp)) \
  922. SMC_outl((x)<<16, ioaddr, 12<<SMC_IO_SHIFT); \
  923. else \
  924. SMC_outw(x, ioaddr, BANK_SELECT); \
  925. } while (0)
  926. #define SMC_GET_BASE(lp) SMC_inw(ioaddr, BASE_REG(lp))
  927. #define SMC_SET_BASE(lp, x) SMC_outw(x, ioaddr, BASE_REG(lp))
  928. #define SMC_GET_CONFIG(lp) SMC_inw(ioaddr, CONFIG_REG(lp))
  929. #define SMC_SET_CONFIG(lp, x) SMC_outw(x, ioaddr, CONFIG_REG(lp))
  930. #define SMC_GET_COUNTER(lp) SMC_inw(ioaddr, COUNTER_REG(lp))
  931. #define SMC_GET_CTL(lp) SMC_inw(ioaddr, CTL_REG(lp))
  932. #define SMC_SET_CTL(lp, x) SMC_outw(x, ioaddr, CTL_REG(lp))
  933. #define SMC_GET_MII(lp) SMC_inw(ioaddr, MII_REG(lp))
  934. #define SMC_SET_MII(lp, x) SMC_outw(x, ioaddr, MII_REG(lp))
  935. #define SMC_GET_MIR(lp) SMC_inw(ioaddr, MIR_REG(lp))
  936. #define SMC_SET_MIR(lp, x) SMC_outw(x, ioaddr, MIR_REG(lp))
  937. #define SMC_GET_MMU_CMD(lp) SMC_inw(ioaddr, MMU_CMD_REG(lp))
  938. #define SMC_SET_MMU_CMD(lp, x) SMC_outw(x, ioaddr, MMU_CMD_REG(lp))
  939. #define SMC_GET_FIFO(lp) SMC_inw(ioaddr, FIFO_REG(lp))
  940. #define SMC_GET_PTR(lp) SMC_inw(ioaddr, PTR_REG(lp))
  941. #define SMC_SET_PTR(lp, x) \
  942. do { \
  943. if (SMC_MUST_ALIGN_WRITE(lp)) \
  944. SMC_outl((x)<<16, ioaddr, SMC_REG(lp, 4, 2)); \
  945. else \
  946. SMC_outw(x, ioaddr, PTR_REG(lp)); \
  947. } while (0)
  948. #define SMC_GET_EPH_STATUS(lp) SMC_inw(ioaddr, EPH_STATUS_REG(lp))
  949. #define SMC_GET_RCR(lp) SMC_inw(ioaddr, RCR_REG(lp))
  950. #define SMC_SET_RCR(lp, x) SMC_outw(x, ioaddr, RCR_REG(lp))
  951. #define SMC_GET_REV(lp) SMC_inw(ioaddr, REV_REG(lp))
  952. #define SMC_GET_RPC(lp) SMC_inw(ioaddr, RPC_REG(lp))
  953. #define SMC_SET_RPC(lp, x) \
  954. do { \
  955. if (SMC_MUST_ALIGN_WRITE(lp)) \
  956. SMC_outl((x)<<16, ioaddr, SMC_REG(lp, 8, 0)); \
  957. else \
  958. SMC_outw(x, ioaddr, RPC_REG(lp)); \
  959. } while (0)
  960. #define SMC_GET_TCR(lp) SMC_inw(ioaddr, TCR_REG(lp))
  961. #define SMC_SET_TCR(lp, x) SMC_outw(x, ioaddr, TCR_REG(lp))
  962. #ifndef SMC_GET_MAC_ADDR
  963. #define SMC_GET_MAC_ADDR(lp, addr) \
  964. do { \
  965. unsigned int __v; \
  966. __v = SMC_inw(ioaddr, ADDR0_REG(lp)); \
  967. addr[0] = __v; addr[1] = __v >> 8; \
  968. __v = SMC_inw(ioaddr, ADDR1_REG(lp)); \
  969. addr[2] = __v; addr[3] = __v >> 8; \
  970. __v = SMC_inw(ioaddr, ADDR2_REG(lp)); \
  971. addr[4] = __v; addr[5] = __v >> 8; \
  972. } while (0)
  973. #endif
  974. #define SMC_SET_MAC_ADDR(lp, addr) \
  975. do { \
  976. SMC_outw(addr[0]|(addr[1] << 8), ioaddr, ADDR0_REG(lp)); \
  977. SMC_outw(addr[2]|(addr[3] << 8), ioaddr, ADDR1_REG(lp)); \
  978. SMC_outw(addr[4]|(addr[5] << 8), ioaddr, ADDR2_REG(lp)); \
  979. } while (0)
  980. #define SMC_SET_MCAST(lp, x) \
  981. do { \
  982. const unsigned char *mt = (x); \
  983. SMC_outw(mt[0] | (mt[1] << 8), ioaddr, MCAST_REG1(lp)); \
  984. SMC_outw(mt[2] | (mt[3] << 8), ioaddr, MCAST_REG2(lp)); \
  985. SMC_outw(mt[4] | (mt[5] << 8), ioaddr, MCAST_REG3(lp)); \
  986. SMC_outw(mt[6] | (mt[7] << 8), ioaddr, MCAST_REG4(lp)); \
  987. } while (0)
  988. #define SMC_PUT_PKT_HDR(lp, status, length) \
  989. do { \
  990. if (SMC_32BIT(lp)) \
  991. SMC_outl((status) | (length)<<16, ioaddr, \
  992. DATA_REG(lp)); \
  993. else { \
  994. SMC_outw(status, ioaddr, DATA_REG(lp)); \
  995. SMC_outw(length, ioaddr, DATA_REG(lp)); \
  996. } \
  997. } while (0)
  998. #define SMC_GET_PKT_HDR(lp, status, length) \
  999. do { \
  1000. if (SMC_32BIT(lp)) { \
  1001. unsigned int __val = SMC_inl(ioaddr, DATA_REG(lp)); \
  1002. (status) = __val & 0xffff; \
  1003. (length) = __val >> 16; \
  1004. } else { \
  1005. (status) = SMC_inw(ioaddr, DATA_REG(lp)); \
  1006. (length) = SMC_inw(ioaddr, DATA_REG(lp)); \
  1007. } \
  1008. } while (0)
  1009. #define SMC_PUSH_DATA(lp, p, l) \
  1010. do { \
  1011. if (SMC_32BIT(lp)) { \
  1012. void *__ptr = (p); \
  1013. int __len = (l); \
  1014. void __iomem *__ioaddr = ioaddr; \
  1015. if (__len >= 2 && (unsigned long)__ptr & 2) { \
  1016. __len -= 2; \
  1017. SMC_outw(*(u16 *)__ptr, ioaddr, \
  1018. DATA_REG(lp)); \
  1019. __ptr += 2; \
  1020. } \
  1021. if (SMC_CAN_USE_DATACS && lp->datacs) \
  1022. __ioaddr = lp->datacs; \
  1023. SMC_outsl(__ioaddr, DATA_REG(lp), __ptr, __len>>2); \
  1024. if (__len & 2) { \
  1025. __ptr += (__len & ~3); \
  1026. SMC_outw(*((u16 *)__ptr), ioaddr, \
  1027. DATA_REG(lp)); \
  1028. } \
  1029. } else if (SMC_16BIT(lp)) \
  1030. SMC_outsw(ioaddr, DATA_REG(lp), p, (l) >> 1); \
  1031. else if (SMC_8BIT(lp)) \
  1032. SMC_outsb(ioaddr, DATA_REG(lp), p, l); \
  1033. } while (0)
  1034. #define SMC_PULL_DATA(lp, p, l) \
  1035. do { \
  1036. if (SMC_32BIT(lp)) { \
  1037. void *__ptr = (p); \
  1038. int __len = (l); \
  1039. void __iomem *__ioaddr = ioaddr; \
  1040. if ((unsigned long)__ptr & 2) { \
  1041. /* \
  1042. * We want 32bit alignment here. \
  1043. * Since some buses perform a full \
  1044. * 32bit fetch even for 16bit data \
  1045. * we can't use SMC_inw() here. \
  1046. * Back both source (on-chip) and \
  1047. * destination pointers of 2 bytes. \
  1048. * This is possible since the call to \
  1049. * SMC_GET_PKT_HDR() already advanced \
  1050. * the source pointer of 4 bytes, and \
  1051. * the skb_reserve(skb, 2) advanced \
  1052. * the destination pointer of 2 bytes. \
  1053. */ \
  1054. __ptr -= 2; \
  1055. __len += 2; \
  1056. SMC_SET_PTR(lp, \
  1057. 2|PTR_READ|PTR_RCV|PTR_AUTOINC); \
  1058. } \
  1059. if (SMC_CAN_USE_DATACS && lp->datacs) \
  1060. __ioaddr = lp->datacs; \
  1061. __len += 2; \
  1062. SMC_insl(__ioaddr, DATA_REG(lp), __ptr, __len>>2); \
  1063. } else if (SMC_16BIT(lp)) \
  1064. SMC_insw(ioaddr, DATA_REG(lp), p, (l) >> 1); \
  1065. else if (SMC_8BIT(lp)) \
  1066. SMC_insb(ioaddr, DATA_REG(lp), p, l); \
  1067. } while (0)
  1068. #endif /* _SMC91X_H_ */