smc911x.h 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913
  1. /*------------------------------------------------------------------------
  2. . smc911x.h - macros for SMSC's LAN911{5,6,7,8} single-chip Ethernet device.
  3. .
  4. . Copyright (C) 2005 Sensoria Corp.
  5. . Derived from the unified SMC91x driver by Nicolas Pitre
  6. .
  7. . This program is free software; you can redistribute it and/or modify
  8. . it under the terms of the GNU General Public License as published by
  9. . the Free Software Foundation; either version 2 of the License, or
  10. . (at your option) any later version.
  11. .
  12. . This program is distributed in the hope that it will be useful,
  13. . but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. . MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. . GNU General Public License for more details.
  16. .
  17. . You should have received a copy of the GNU General Public License
  18. . along with this program; if not, see <http://www.gnu.org/licenses/>.
  19. .
  20. . Information contained in this file was obtained from the LAN9118
  21. . manual from SMC. To get a copy, if you really want one, you can find
  22. . information under www.smsc.com.
  23. .
  24. . Authors
  25. . Dustin McIntire <dustin@sensoria.com>
  26. .
  27. ---------------------------------------------------------------------------*/
  28. #ifndef _SMC911X_H_
  29. #define _SMC911X_H_
  30. #include <linux/smc911x.h>
  31. /*
  32. * Use the DMA feature on PXA chips
  33. */
  34. #ifdef CONFIG_ARCH_PXA
  35. #define SMC_USE_PXA_DMA 1
  36. #define SMC_USE_16BIT 0
  37. #define SMC_USE_32BIT 1
  38. #define SMC_IRQ_SENSE IRQF_TRIGGER_FALLING
  39. #elif defined(CONFIG_SH_MAGIC_PANEL_R2)
  40. #define SMC_USE_16BIT 0
  41. #define SMC_USE_32BIT 1
  42. #define SMC_IRQ_SENSE IRQF_TRIGGER_LOW
  43. #elif defined(CONFIG_ARCH_OMAP3)
  44. #define SMC_USE_16BIT 0
  45. #define SMC_USE_32BIT 1
  46. #define SMC_IRQ_SENSE IRQF_TRIGGER_LOW
  47. #define SMC_MEM_RESERVED 1
  48. #elif defined(CONFIG_ARCH_OMAP2)
  49. #define SMC_USE_16BIT 0
  50. #define SMC_USE_32BIT 1
  51. #define SMC_IRQ_SENSE IRQF_TRIGGER_LOW
  52. #define SMC_MEM_RESERVED 1
  53. #else
  54. /*
  55. * Default configuration
  56. */
  57. #define SMC_DYNAMIC_BUS_CONFIG
  58. #endif
  59. #ifdef SMC_USE_PXA_DMA
  60. #define SMC_USE_DMA
  61. #endif
  62. /* store this information for the driver.. */
  63. struct smc911x_local {
  64. /*
  65. * If I have to wait until the DMA is finished and ready to reload a
  66. * packet, I will store the skbuff here. Then, the DMA will send it
  67. * out and free it.
  68. */
  69. struct sk_buff *pending_tx_skb;
  70. /* version/revision of the SMC911x chip */
  71. u16 version;
  72. u16 revision;
  73. /* FIFO sizes */
  74. int tx_fifo_kb;
  75. int tx_fifo_size;
  76. int rx_fifo_size;
  77. int afc_cfg;
  78. /* Contains the current active receive/phy mode */
  79. int ctl_rfduplx;
  80. int ctl_rspeed;
  81. u32 msg_enable;
  82. u32 phy_type;
  83. struct mii_if_info mii;
  84. /* work queue */
  85. struct work_struct phy_configure;
  86. int tx_throttle;
  87. spinlock_t lock;
  88. struct net_device *netdev;
  89. #ifdef SMC_USE_DMA
  90. /* DMA needs the physical address of the chip */
  91. u_long physaddr;
  92. struct dma_chan *rxdma;
  93. struct dma_chan *txdma;
  94. int rxdma_active;
  95. int txdma_active;
  96. struct sk_buff *current_rx_skb;
  97. struct sk_buff *current_tx_skb;
  98. struct device *dev;
  99. #endif
  100. void __iomem *base;
  101. #ifdef SMC_DYNAMIC_BUS_CONFIG
  102. struct smc911x_platdata cfg;
  103. #endif
  104. };
  105. /*
  106. * Define the bus width specific IO macros
  107. */
  108. #ifdef SMC_DYNAMIC_BUS_CONFIG
  109. static inline unsigned int SMC_inl(struct smc911x_local *lp, int reg)
  110. {
  111. void __iomem *ioaddr = lp->base + reg;
  112. if (lp->cfg.flags & SMC911X_USE_32BIT)
  113. return readl(ioaddr);
  114. if (lp->cfg.flags & SMC911X_USE_16BIT)
  115. return readw(ioaddr) | (readw(ioaddr + 2) << 16);
  116. BUG();
  117. }
  118. static inline void SMC_outl(unsigned int value, struct smc911x_local *lp,
  119. int reg)
  120. {
  121. void __iomem *ioaddr = lp->base + reg;
  122. if (lp->cfg.flags & SMC911X_USE_32BIT) {
  123. writel(value, ioaddr);
  124. return;
  125. }
  126. if (lp->cfg.flags & SMC911X_USE_16BIT) {
  127. writew(value & 0xffff, ioaddr);
  128. writew(value >> 16, ioaddr + 2);
  129. return;
  130. }
  131. BUG();
  132. }
  133. static inline void SMC_insl(struct smc911x_local *lp, int reg,
  134. void *addr, unsigned int count)
  135. {
  136. void __iomem *ioaddr = lp->base + reg;
  137. if (lp->cfg.flags & SMC911X_USE_32BIT) {
  138. ioread32_rep(ioaddr, addr, count);
  139. return;
  140. }
  141. if (lp->cfg.flags & SMC911X_USE_16BIT) {
  142. ioread16_rep(ioaddr, addr, count * 2);
  143. return;
  144. }
  145. BUG();
  146. }
  147. static inline void SMC_outsl(struct smc911x_local *lp, int reg,
  148. void *addr, unsigned int count)
  149. {
  150. void __iomem *ioaddr = lp->base + reg;
  151. if (lp->cfg.flags & SMC911X_USE_32BIT) {
  152. iowrite32_rep(ioaddr, addr, count);
  153. return;
  154. }
  155. if (lp->cfg.flags & SMC911X_USE_16BIT) {
  156. iowrite16_rep(ioaddr, addr, count * 2);
  157. return;
  158. }
  159. BUG();
  160. }
  161. #else
  162. #if SMC_USE_16BIT
  163. #define SMC_inl(lp, r) ((readw((lp)->base + (r)) & 0xFFFF) + (readw((lp)->base + (r) + 2) << 16))
  164. #define SMC_outl(v, lp, r) \
  165. do{ \
  166. writew(v & 0xFFFF, (lp)->base + (r)); \
  167. writew(v >> 16, (lp)->base + (r) + 2); \
  168. } while (0)
  169. #define SMC_insl(lp, r, p, l) ioread16_rep((short*)((lp)->base + (r)), p, l*2)
  170. #define SMC_outsl(lp, r, p, l) iowrite16_rep((short*)((lp)->base + (r)), p, l*2)
  171. #elif SMC_USE_32BIT
  172. #define SMC_inl(lp, r) readl((lp)->base + (r))
  173. #define SMC_outl(v, lp, r) writel(v, (lp)->base + (r))
  174. #define SMC_insl(lp, r, p, l) ioread32_rep((int*)((lp)->base + (r)), p, l)
  175. #define SMC_outsl(lp, r, p, l) iowrite32_rep((int*)((lp)->base + (r)), p, l)
  176. #endif /* SMC_USE_16BIT */
  177. #endif /* SMC_DYNAMIC_BUS_CONFIG */
  178. #ifdef SMC_USE_PXA_DMA
  179. /*
  180. * Use a DMA for RX and TX packets.
  181. */
  182. #include <linux/dma-mapping.h>
  183. static dma_addr_t rx_dmabuf, tx_dmabuf;
  184. static int rx_dmalen, tx_dmalen;
  185. static void smc911x_rx_dma_irq(void *data);
  186. static void smc911x_tx_dma_irq(void *data);
  187. #ifdef SMC_insl
  188. #undef SMC_insl
  189. #define SMC_insl(lp, r, p, l) \
  190. smc_pxa_dma_insl(lp, lp->physaddr, r, lp->rxdma, p, l)
  191. static inline void
  192. smc_pxa_dma_insl(struct smc911x_local *lp, u_long physaddr,
  193. int reg, struct dma_chan *dma, u_char *buf, int len)
  194. {
  195. struct dma_async_tx_descriptor *tx;
  196. /* 64 bit alignment is required for memory to memory DMA */
  197. if ((long)buf & 4) {
  198. *((u32 *)buf) = SMC_inl(lp, reg);
  199. buf += 4;
  200. len--;
  201. }
  202. len *= 4;
  203. rx_dmabuf = dma_map_single(lp->dev, buf, len, DMA_FROM_DEVICE);
  204. rx_dmalen = len;
  205. tx = dmaengine_prep_slave_single(dma, rx_dmabuf, rx_dmalen,
  206. DMA_DEV_TO_MEM, 0);
  207. if (tx) {
  208. tx->callback = smc911x_rx_dma_irq;
  209. tx->callback_param = lp;
  210. dmaengine_submit(tx);
  211. dma_async_issue_pending(dma);
  212. }
  213. }
  214. #endif
  215. #ifdef SMC_outsl
  216. #undef SMC_outsl
  217. #define SMC_outsl(lp, r, p, l) \
  218. smc_pxa_dma_outsl(lp, lp->physaddr, r, lp->txdma, p, l)
  219. static inline void
  220. smc_pxa_dma_outsl(struct smc911x_local *lp, u_long physaddr,
  221. int reg, struct dma_chan *dma, u_char *buf, int len)
  222. {
  223. struct dma_async_tx_descriptor *tx;
  224. /* 64 bit alignment is required for memory to memory DMA */
  225. if ((long)buf & 4) {
  226. SMC_outl(*((u32 *)buf), lp, reg);
  227. buf += 4;
  228. len--;
  229. }
  230. len *= 4;
  231. tx_dmabuf = dma_map_single(lp->dev, buf, len, DMA_TO_DEVICE);
  232. tx_dmalen = len;
  233. tx = dmaengine_prep_slave_single(dma, tx_dmabuf, tx_dmalen,
  234. DMA_DEV_TO_MEM, 0);
  235. if (tx) {
  236. tx->callback = smc911x_tx_dma_irq;
  237. tx->callback_param = lp;
  238. dmaengine_submit(tx);
  239. dma_async_issue_pending(dma);
  240. }
  241. }
  242. #endif
  243. #endif /* SMC_USE_PXA_DMA */
  244. /* Chip Parameters and Register Definitions */
  245. #define SMC911X_TX_FIFO_LOW_THRESHOLD (1536*2)
  246. #define SMC911X_IO_EXTENT 0x100
  247. #define SMC911X_EEPROM_LEN 7
  248. /* Below are the register offsets and bit definitions
  249. * of the Lan911x memory space
  250. */
  251. #define RX_DATA_FIFO (0x00)
  252. #define TX_DATA_FIFO (0x20)
  253. #define TX_CMD_A_INT_ON_COMP_ (0x80000000)
  254. #define TX_CMD_A_INT_BUF_END_ALGN_ (0x03000000)
  255. #define TX_CMD_A_INT_4_BYTE_ALGN_ (0x00000000)
  256. #define TX_CMD_A_INT_16_BYTE_ALGN_ (0x01000000)
  257. #define TX_CMD_A_INT_32_BYTE_ALGN_ (0x02000000)
  258. #define TX_CMD_A_INT_DATA_OFFSET_ (0x001F0000)
  259. #define TX_CMD_A_INT_FIRST_SEG_ (0x00002000)
  260. #define TX_CMD_A_INT_LAST_SEG_ (0x00001000)
  261. #define TX_CMD_A_BUF_SIZE_ (0x000007FF)
  262. #define TX_CMD_B_PKT_TAG_ (0xFFFF0000)
  263. #define TX_CMD_B_ADD_CRC_DISABLE_ (0x00002000)
  264. #define TX_CMD_B_DISABLE_PADDING_ (0x00001000)
  265. #define TX_CMD_B_PKT_BYTE_LENGTH_ (0x000007FF)
  266. #define RX_STATUS_FIFO (0x40)
  267. #define RX_STS_PKT_LEN_ (0x3FFF0000)
  268. #define RX_STS_ES_ (0x00008000)
  269. #define RX_STS_BCST_ (0x00002000)
  270. #define RX_STS_LEN_ERR_ (0x00001000)
  271. #define RX_STS_RUNT_ERR_ (0x00000800)
  272. #define RX_STS_MCAST_ (0x00000400)
  273. #define RX_STS_TOO_LONG_ (0x00000080)
  274. #define RX_STS_COLL_ (0x00000040)
  275. #define RX_STS_ETH_TYPE_ (0x00000020)
  276. #define RX_STS_WDOG_TMT_ (0x00000010)
  277. #define RX_STS_MII_ERR_ (0x00000008)
  278. #define RX_STS_DRIBBLING_ (0x00000004)
  279. #define RX_STS_CRC_ERR_ (0x00000002)
  280. #define RX_STATUS_FIFO_PEEK (0x44)
  281. #define TX_STATUS_FIFO (0x48)
  282. #define TX_STS_TAG_ (0xFFFF0000)
  283. #define TX_STS_ES_ (0x00008000)
  284. #define TX_STS_LOC_ (0x00000800)
  285. #define TX_STS_NO_CARR_ (0x00000400)
  286. #define TX_STS_LATE_COLL_ (0x00000200)
  287. #define TX_STS_MANY_COLL_ (0x00000100)
  288. #define TX_STS_COLL_CNT_ (0x00000078)
  289. #define TX_STS_MANY_DEFER_ (0x00000004)
  290. #define TX_STS_UNDERRUN_ (0x00000002)
  291. #define TX_STS_DEFERRED_ (0x00000001)
  292. #define TX_STATUS_FIFO_PEEK (0x4C)
  293. #define ID_REV (0x50)
  294. #define ID_REV_CHIP_ID_ (0xFFFF0000) /* RO */
  295. #define ID_REV_REV_ID_ (0x0000FFFF) /* RO */
  296. #define INT_CFG (0x54)
  297. #define INT_CFG_INT_DEAS_ (0xFF000000) /* R/W */
  298. #define INT_CFG_INT_DEAS_CLR_ (0x00004000)
  299. #define INT_CFG_INT_DEAS_STS_ (0x00002000)
  300. #define INT_CFG_IRQ_INT_ (0x00001000) /* RO */
  301. #define INT_CFG_IRQ_EN_ (0x00000100) /* R/W */
  302. #define INT_CFG_IRQ_POL_ (0x00000010) /* R/W Not Affected by SW Reset */
  303. #define INT_CFG_IRQ_TYPE_ (0x00000001) /* R/W Not Affected by SW Reset */
  304. #define INT_STS (0x58)
  305. #define INT_STS_SW_INT_ (0x80000000) /* R/WC */
  306. #define INT_STS_TXSTOP_INT_ (0x02000000) /* R/WC */
  307. #define INT_STS_RXSTOP_INT_ (0x01000000) /* R/WC */
  308. #define INT_STS_RXDFH_INT_ (0x00800000) /* R/WC */
  309. #define INT_STS_RXDF_INT_ (0x00400000) /* R/WC */
  310. #define INT_STS_TX_IOC_ (0x00200000) /* R/WC */
  311. #define INT_STS_RXD_INT_ (0x00100000) /* R/WC */
  312. #define INT_STS_GPT_INT_ (0x00080000) /* R/WC */
  313. #define INT_STS_PHY_INT_ (0x00040000) /* RO */
  314. #define INT_STS_PME_INT_ (0x00020000) /* R/WC */
  315. #define INT_STS_TXSO_ (0x00010000) /* R/WC */
  316. #define INT_STS_RWT_ (0x00008000) /* R/WC */
  317. #define INT_STS_RXE_ (0x00004000) /* R/WC */
  318. #define INT_STS_TXE_ (0x00002000) /* R/WC */
  319. //#define INT_STS_ERX_ (0x00001000) /* R/WC */
  320. #define INT_STS_TDFU_ (0x00000800) /* R/WC */
  321. #define INT_STS_TDFO_ (0x00000400) /* R/WC */
  322. #define INT_STS_TDFA_ (0x00000200) /* R/WC */
  323. #define INT_STS_TSFF_ (0x00000100) /* R/WC */
  324. #define INT_STS_TSFL_ (0x00000080) /* R/WC */
  325. //#define INT_STS_RXDF_ (0x00000040) /* R/WC */
  326. #define INT_STS_RDFO_ (0x00000040) /* R/WC */
  327. #define INT_STS_RDFL_ (0x00000020) /* R/WC */
  328. #define INT_STS_RSFF_ (0x00000010) /* R/WC */
  329. #define INT_STS_RSFL_ (0x00000008) /* R/WC */
  330. #define INT_STS_GPIO2_INT_ (0x00000004) /* R/WC */
  331. #define INT_STS_GPIO1_INT_ (0x00000002) /* R/WC */
  332. #define INT_STS_GPIO0_INT_ (0x00000001) /* R/WC */
  333. #define INT_EN (0x5C)
  334. #define INT_EN_SW_INT_EN_ (0x80000000) /* R/W */
  335. #define INT_EN_TXSTOP_INT_EN_ (0x02000000) /* R/W */
  336. #define INT_EN_RXSTOP_INT_EN_ (0x01000000) /* R/W */
  337. #define INT_EN_RXDFH_INT_EN_ (0x00800000) /* R/W */
  338. //#define INT_EN_RXDF_INT_EN_ (0x00400000) /* R/W */
  339. #define INT_EN_TIOC_INT_EN_ (0x00200000) /* R/W */
  340. #define INT_EN_RXD_INT_EN_ (0x00100000) /* R/W */
  341. #define INT_EN_GPT_INT_EN_ (0x00080000) /* R/W */
  342. #define INT_EN_PHY_INT_EN_ (0x00040000) /* R/W */
  343. #define INT_EN_PME_INT_EN_ (0x00020000) /* R/W */
  344. #define INT_EN_TXSO_EN_ (0x00010000) /* R/W */
  345. #define INT_EN_RWT_EN_ (0x00008000) /* R/W */
  346. #define INT_EN_RXE_EN_ (0x00004000) /* R/W */
  347. #define INT_EN_TXE_EN_ (0x00002000) /* R/W */
  348. //#define INT_EN_ERX_EN_ (0x00001000) /* R/W */
  349. #define INT_EN_TDFU_EN_ (0x00000800) /* R/W */
  350. #define INT_EN_TDFO_EN_ (0x00000400) /* R/W */
  351. #define INT_EN_TDFA_EN_ (0x00000200) /* R/W */
  352. #define INT_EN_TSFF_EN_ (0x00000100) /* R/W */
  353. #define INT_EN_TSFL_EN_ (0x00000080) /* R/W */
  354. //#define INT_EN_RXDF_EN_ (0x00000040) /* R/W */
  355. #define INT_EN_RDFO_EN_ (0x00000040) /* R/W */
  356. #define INT_EN_RDFL_EN_ (0x00000020) /* R/W */
  357. #define INT_EN_RSFF_EN_ (0x00000010) /* R/W */
  358. #define INT_EN_RSFL_EN_ (0x00000008) /* R/W */
  359. #define INT_EN_GPIO2_INT_ (0x00000004) /* R/W */
  360. #define INT_EN_GPIO1_INT_ (0x00000002) /* R/W */
  361. #define INT_EN_GPIO0_INT_ (0x00000001) /* R/W */
  362. #define BYTE_TEST (0x64)
  363. #define FIFO_INT (0x68)
  364. #define FIFO_INT_TX_AVAIL_LEVEL_ (0xFF000000) /* R/W */
  365. #define FIFO_INT_TX_STS_LEVEL_ (0x00FF0000) /* R/W */
  366. #define FIFO_INT_RX_AVAIL_LEVEL_ (0x0000FF00) /* R/W */
  367. #define FIFO_INT_RX_STS_LEVEL_ (0x000000FF) /* R/W */
  368. #define RX_CFG (0x6C)
  369. #define RX_CFG_RX_END_ALGN_ (0xC0000000) /* R/W */
  370. #define RX_CFG_RX_END_ALGN4_ (0x00000000) /* R/W */
  371. #define RX_CFG_RX_END_ALGN16_ (0x40000000) /* R/W */
  372. #define RX_CFG_RX_END_ALGN32_ (0x80000000) /* R/W */
  373. #define RX_CFG_RX_DMA_CNT_ (0x0FFF0000) /* R/W */
  374. #define RX_CFG_RX_DUMP_ (0x00008000) /* R/W */
  375. #define RX_CFG_RXDOFF_ (0x00001F00) /* R/W */
  376. //#define RX_CFG_RXBAD_ (0x00000001) /* R/W */
  377. #define TX_CFG (0x70)
  378. //#define TX_CFG_TX_DMA_LVL_ (0xE0000000) /* R/W */
  379. //#define TX_CFG_TX_DMA_CNT_ (0x0FFF0000) /* R/W Self Clearing */
  380. #define TX_CFG_TXS_DUMP_ (0x00008000) /* Self Clearing */
  381. #define TX_CFG_TXD_DUMP_ (0x00004000) /* Self Clearing */
  382. #define TX_CFG_TXSAO_ (0x00000004) /* R/W */
  383. #define TX_CFG_TX_ON_ (0x00000002) /* R/W */
  384. #define TX_CFG_STOP_TX_ (0x00000001) /* Self Clearing */
  385. #define HW_CFG (0x74)
  386. #define HW_CFG_TTM_ (0x00200000) /* R/W */
  387. #define HW_CFG_SF_ (0x00100000) /* R/W */
  388. #define HW_CFG_TX_FIF_SZ_ (0x000F0000) /* R/W */
  389. #define HW_CFG_TR_ (0x00003000) /* R/W */
  390. #define HW_CFG_PHY_CLK_SEL_ (0x00000060) /* R/W */
  391. #define HW_CFG_PHY_CLK_SEL_INT_PHY_ (0x00000000) /* R/W */
  392. #define HW_CFG_PHY_CLK_SEL_EXT_PHY_ (0x00000020) /* R/W */
  393. #define HW_CFG_PHY_CLK_SEL_CLK_DIS_ (0x00000040) /* R/W */
  394. #define HW_CFG_SMI_SEL_ (0x00000010) /* R/W */
  395. #define HW_CFG_EXT_PHY_DET_ (0x00000008) /* RO */
  396. #define HW_CFG_EXT_PHY_EN_ (0x00000004) /* R/W */
  397. #define HW_CFG_32_16_BIT_MODE_ (0x00000004) /* RO */
  398. #define HW_CFG_SRST_TO_ (0x00000002) /* RO */
  399. #define HW_CFG_SRST_ (0x00000001) /* Self Clearing */
  400. #define RX_DP_CTRL (0x78)
  401. #define RX_DP_CTRL_RX_FFWD_ (0x80000000) /* R/W */
  402. #define RX_DP_CTRL_FFWD_BUSY_ (0x80000000) /* RO */
  403. #define RX_FIFO_INF (0x7C)
  404. #define RX_FIFO_INF_RXSUSED_ (0x00FF0000) /* RO */
  405. #define RX_FIFO_INF_RXDUSED_ (0x0000FFFF) /* RO */
  406. #define TX_FIFO_INF (0x80)
  407. #define TX_FIFO_INF_TSUSED_ (0x00FF0000) /* RO */
  408. #define TX_FIFO_INF_TDFREE_ (0x0000FFFF) /* RO */
  409. #define PMT_CTRL (0x84)
  410. #define PMT_CTRL_PM_MODE_ (0x00003000) /* Self Clearing */
  411. #define PMT_CTRL_PHY_RST_ (0x00000400) /* Self Clearing */
  412. #define PMT_CTRL_WOL_EN_ (0x00000200) /* R/W */
  413. #define PMT_CTRL_ED_EN_ (0x00000100) /* R/W */
  414. #define PMT_CTRL_PME_TYPE_ (0x00000040) /* R/W Not Affected by SW Reset */
  415. #define PMT_CTRL_WUPS_ (0x00000030) /* R/WC */
  416. #define PMT_CTRL_WUPS_NOWAKE_ (0x00000000) /* R/WC */
  417. #define PMT_CTRL_WUPS_ED_ (0x00000010) /* R/WC */
  418. #define PMT_CTRL_WUPS_WOL_ (0x00000020) /* R/WC */
  419. #define PMT_CTRL_WUPS_MULTI_ (0x00000030) /* R/WC */
  420. #define PMT_CTRL_PME_IND_ (0x00000008) /* R/W */
  421. #define PMT_CTRL_PME_POL_ (0x00000004) /* R/W */
  422. #define PMT_CTRL_PME_EN_ (0x00000002) /* R/W Not Affected by SW Reset */
  423. #define PMT_CTRL_READY_ (0x00000001) /* RO */
  424. #define GPIO_CFG (0x88)
  425. #define GPIO_CFG_LED3_EN_ (0x40000000) /* R/W */
  426. #define GPIO_CFG_LED2_EN_ (0x20000000) /* R/W */
  427. #define GPIO_CFG_LED1_EN_ (0x10000000) /* R/W */
  428. #define GPIO_CFG_GPIO2_INT_POL_ (0x04000000) /* R/W */
  429. #define GPIO_CFG_GPIO1_INT_POL_ (0x02000000) /* R/W */
  430. #define GPIO_CFG_GPIO0_INT_POL_ (0x01000000) /* R/W */
  431. #define GPIO_CFG_EEPR_EN_ (0x00700000) /* R/W */
  432. #define GPIO_CFG_GPIOBUF2_ (0x00040000) /* R/W */
  433. #define GPIO_CFG_GPIOBUF1_ (0x00020000) /* R/W */
  434. #define GPIO_CFG_GPIOBUF0_ (0x00010000) /* R/W */
  435. #define GPIO_CFG_GPIODIR2_ (0x00000400) /* R/W */
  436. #define GPIO_CFG_GPIODIR1_ (0x00000200) /* R/W */
  437. #define GPIO_CFG_GPIODIR0_ (0x00000100) /* R/W */
  438. #define GPIO_CFG_GPIOD4_ (0x00000010) /* R/W */
  439. #define GPIO_CFG_GPIOD3_ (0x00000008) /* R/W */
  440. #define GPIO_CFG_GPIOD2_ (0x00000004) /* R/W */
  441. #define GPIO_CFG_GPIOD1_ (0x00000002) /* R/W */
  442. #define GPIO_CFG_GPIOD0_ (0x00000001) /* R/W */
  443. #define GPT_CFG (0x8C)
  444. #define GPT_CFG_TIMER_EN_ (0x20000000) /* R/W */
  445. #define GPT_CFG_GPT_LOAD_ (0x0000FFFF) /* R/W */
  446. #define GPT_CNT (0x90)
  447. #define GPT_CNT_GPT_CNT_ (0x0000FFFF) /* RO */
  448. #define ENDIAN (0x98)
  449. #define FREE_RUN (0x9C)
  450. #define RX_DROP (0xA0)
  451. #define MAC_CSR_CMD (0xA4)
  452. #define MAC_CSR_CMD_CSR_BUSY_ (0x80000000) /* Self Clearing */
  453. #define MAC_CSR_CMD_R_NOT_W_ (0x40000000) /* R/W */
  454. #define MAC_CSR_CMD_CSR_ADDR_ (0x000000FF) /* R/W */
  455. #define MAC_CSR_DATA (0xA8)
  456. #define AFC_CFG (0xAC)
  457. #define AFC_CFG_AFC_HI_ (0x00FF0000) /* R/W */
  458. #define AFC_CFG_AFC_LO_ (0x0000FF00) /* R/W */
  459. #define AFC_CFG_BACK_DUR_ (0x000000F0) /* R/W */
  460. #define AFC_CFG_FCMULT_ (0x00000008) /* R/W */
  461. #define AFC_CFG_FCBRD_ (0x00000004) /* R/W */
  462. #define AFC_CFG_FCADD_ (0x00000002) /* R/W */
  463. #define AFC_CFG_FCANY_ (0x00000001) /* R/W */
  464. #define E2P_CMD (0xB0)
  465. #define E2P_CMD_EPC_BUSY_ (0x80000000) /* Self Clearing */
  466. #define E2P_CMD_EPC_CMD_ (0x70000000) /* R/W */
  467. #define E2P_CMD_EPC_CMD_READ_ (0x00000000) /* R/W */
  468. #define E2P_CMD_EPC_CMD_EWDS_ (0x10000000) /* R/W */
  469. #define E2P_CMD_EPC_CMD_EWEN_ (0x20000000) /* R/W */
  470. #define E2P_CMD_EPC_CMD_WRITE_ (0x30000000) /* R/W */
  471. #define E2P_CMD_EPC_CMD_WRAL_ (0x40000000) /* R/W */
  472. #define E2P_CMD_EPC_CMD_ERASE_ (0x50000000) /* R/W */
  473. #define E2P_CMD_EPC_CMD_ERAL_ (0x60000000) /* R/W */
  474. #define E2P_CMD_EPC_CMD_RELOAD_ (0x70000000) /* R/W */
  475. #define E2P_CMD_EPC_TIMEOUT_ (0x00000200) /* RO */
  476. #define E2P_CMD_MAC_ADDR_LOADED_ (0x00000100) /* RO */
  477. #define E2P_CMD_EPC_ADDR_ (0x000000FF) /* R/W */
  478. #define E2P_DATA (0xB4)
  479. #define E2P_DATA_EEPROM_DATA_ (0x000000FF) /* R/W */
  480. /* end of LAN register offsets and bit definitions */
  481. /*
  482. ****************************************************************************
  483. ****************************************************************************
  484. * MAC Control and Status Register (Indirect Address)
  485. * Offset (through the MAC_CSR CMD and DATA port)
  486. ****************************************************************************
  487. ****************************************************************************
  488. *
  489. */
  490. #define MAC_CR (0x01) /* R/W */
  491. /* MAC_CR - MAC Control Register */
  492. #define MAC_CR_RXALL_ (0x80000000)
  493. // TODO: delete this bit? It is not described in the data sheet.
  494. #define MAC_CR_HBDIS_ (0x10000000)
  495. #define MAC_CR_RCVOWN_ (0x00800000)
  496. #define MAC_CR_LOOPBK_ (0x00200000)
  497. #define MAC_CR_FDPX_ (0x00100000)
  498. #define MAC_CR_MCPAS_ (0x00080000)
  499. #define MAC_CR_PRMS_ (0x00040000)
  500. #define MAC_CR_INVFILT_ (0x00020000)
  501. #define MAC_CR_PASSBAD_ (0x00010000)
  502. #define MAC_CR_HFILT_ (0x00008000)
  503. #define MAC_CR_HPFILT_ (0x00002000)
  504. #define MAC_CR_LCOLL_ (0x00001000)
  505. #define MAC_CR_BCAST_ (0x00000800)
  506. #define MAC_CR_DISRTY_ (0x00000400)
  507. #define MAC_CR_PADSTR_ (0x00000100)
  508. #define MAC_CR_BOLMT_MASK_ (0x000000C0)
  509. #define MAC_CR_DFCHK_ (0x00000020)
  510. #define MAC_CR_TXEN_ (0x00000008)
  511. #define MAC_CR_RXEN_ (0x00000004)
  512. #define ADDRH (0x02) /* R/W mask 0x0000FFFFUL */
  513. #define ADDRL (0x03) /* R/W mask 0xFFFFFFFFUL */
  514. #define HASHH (0x04) /* R/W */
  515. #define HASHL (0x05) /* R/W */
  516. #define MII_ACC (0x06) /* R/W */
  517. #define MII_ACC_PHY_ADDR_ (0x0000F800)
  518. #define MII_ACC_MIIRINDA_ (0x000007C0)
  519. #define MII_ACC_MII_WRITE_ (0x00000002)
  520. #define MII_ACC_MII_BUSY_ (0x00000001)
  521. #define MII_DATA (0x07) /* R/W mask 0x0000FFFFUL */
  522. #define FLOW (0x08) /* R/W */
  523. #define FLOW_FCPT_ (0xFFFF0000)
  524. #define FLOW_FCPASS_ (0x00000004)
  525. #define FLOW_FCEN_ (0x00000002)
  526. #define FLOW_FCBSY_ (0x00000001)
  527. #define VLAN1 (0x09) /* R/W mask 0x0000FFFFUL */
  528. #define VLAN1_VTI1_ (0x0000ffff)
  529. #define VLAN2 (0x0A) /* R/W mask 0x0000FFFFUL */
  530. #define VLAN2_VTI2_ (0x0000ffff)
  531. #define WUFF (0x0B) /* WO */
  532. #define WUCSR (0x0C) /* R/W */
  533. #define WUCSR_GUE_ (0x00000200)
  534. #define WUCSR_WUFR_ (0x00000040)
  535. #define WUCSR_MPR_ (0x00000020)
  536. #define WUCSR_WAKE_EN_ (0x00000004)
  537. #define WUCSR_MPEN_ (0x00000002)
  538. /*
  539. ****************************************************************************
  540. * Chip Specific MII Defines
  541. ****************************************************************************
  542. *
  543. * Phy register offsets and bit definitions
  544. *
  545. */
  546. #define PHY_MODE_CTRL_STS ((u32)17) /* Mode Control/Status Register */
  547. //#define MODE_CTRL_STS_FASTRIP_ ((u16)0x4000)
  548. #define MODE_CTRL_STS_EDPWRDOWN_ ((u16)0x2000)
  549. //#define MODE_CTRL_STS_LOWSQEN_ ((u16)0x0800)
  550. //#define MODE_CTRL_STS_MDPREBP_ ((u16)0x0400)
  551. //#define MODE_CTRL_STS_FARLOOPBACK_ ((u16)0x0200)
  552. //#define MODE_CTRL_STS_FASTEST_ ((u16)0x0100)
  553. //#define MODE_CTRL_STS_REFCLKEN_ ((u16)0x0010)
  554. //#define MODE_CTRL_STS_PHYADBP_ ((u16)0x0008)
  555. //#define MODE_CTRL_STS_FORCE_G_LINK_ ((u16)0x0004)
  556. #define MODE_CTRL_STS_ENERGYON_ ((u16)0x0002)
  557. #define PHY_INT_SRC ((u32)29)
  558. #define PHY_INT_SRC_ENERGY_ON_ ((u16)0x0080)
  559. #define PHY_INT_SRC_ANEG_COMP_ ((u16)0x0040)
  560. #define PHY_INT_SRC_REMOTE_FAULT_ ((u16)0x0020)
  561. #define PHY_INT_SRC_LINK_DOWN_ ((u16)0x0010)
  562. #define PHY_INT_SRC_ANEG_LP_ACK_ ((u16)0x0008)
  563. #define PHY_INT_SRC_PAR_DET_FAULT_ ((u16)0x0004)
  564. #define PHY_INT_SRC_ANEG_PGRX_ ((u16)0x0002)
  565. #define PHY_INT_MASK ((u32)30)
  566. #define PHY_INT_MASK_ENERGY_ON_ ((u16)0x0080)
  567. #define PHY_INT_MASK_ANEG_COMP_ ((u16)0x0040)
  568. #define PHY_INT_MASK_REMOTE_FAULT_ ((u16)0x0020)
  569. #define PHY_INT_MASK_LINK_DOWN_ ((u16)0x0010)
  570. #define PHY_INT_MASK_ANEG_LP_ACK_ ((u16)0x0008)
  571. #define PHY_INT_MASK_PAR_DET_FAULT_ ((u16)0x0004)
  572. #define PHY_INT_MASK_ANEG_PGRX_ ((u16)0x0002)
  573. #define PHY_SPECIAL ((u32)31)
  574. #define PHY_SPECIAL_ANEG_DONE_ ((u16)0x1000)
  575. #define PHY_SPECIAL_RES_ ((u16)0x0040)
  576. #define PHY_SPECIAL_RES_MASK_ ((u16)0x0FE1)
  577. #define PHY_SPECIAL_SPD_ ((u16)0x001C)
  578. #define PHY_SPECIAL_SPD_10HALF_ ((u16)0x0004)
  579. #define PHY_SPECIAL_SPD_10FULL_ ((u16)0x0014)
  580. #define PHY_SPECIAL_SPD_100HALF_ ((u16)0x0008)
  581. #define PHY_SPECIAL_SPD_100FULL_ ((u16)0x0018)
  582. #define LAN911X_INTERNAL_PHY_ID (0x0007C000)
  583. /* Chip ID values */
  584. #define CHIP_9115 0x0115
  585. #define CHIP_9116 0x0116
  586. #define CHIP_9117 0x0117
  587. #define CHIP_9118 0x0118
  588. #define CHIP_9211 0x9211
  589. #define CHIP_9215 0x115A
  590. #define CHIP_9217 0x117A
  591. #define CHIP_9218 0x118A
  592. struct chip_id {
  593. u16 id;
  594. char *name;
  595. };
  596. static const struct chip_id chip_ids[] = {
  597. { CHIP_9115, "LAN9115" },
  598. { CHIP_9116, "LAN9116" },
  599. { CHIP_9117, "LAN9117" },
  600. { CHIP_9118, "LAN9118" },
  601. { CHIP_9211, "LAN9211" },
  602. { CHIP_9215, "LAN9215" },
  603. { CHIP_9217, "LAN9217" },
  604. { CHIP_9218, "LAN9218" },
  605. { 0, NULL },
  606. };
  607. #define IS_REV_A(x) ((x & 0xFFFF)==0)
  608. /*
  609. * Macros to abstract register access according to the data bus
  610. * capabilities. Please use those and not the in/out primitives.
  611. */
  612. /* FIFO read/write macros */
  613. #define SMC_PUSH_DATA(lp, p, l) SMC_outsl( lp, TX_DATA_FIFO, p, (l) >> 2 )
  614. #define SMC_PULL_DATA(lp, p, l) SMC_insl ( lp, RX_DATA_FIFO, p, (l) >> 2 )
  615. #define SMC_SET_TX_FIFO(lp, x) SMC_outl( x, lp, TX_DATA_FIFO )
  616. #define SMC_GET_RX_FIFO(lp) SMC_inl( lp, RX_DATA_FIFO )
  617. /* I/O mapped register read/write macros */
  618. #define SMC_GET_TX_STS_FIFO(lp) SMC_inl( lp, TX_STATUS_FIFO )
  619. #define SMC_GET_RX_STS_FIFO(lp) SMC_inl( lp, RX_STATUS_FIFO )
  620. #define SMC_GET_RX_STS_FIFO_PEEK(lp) SMC_inl( lp, RX_STATUS_FIFO_PEEK )
  621. #define SMC_GET_PN(lp) (SMC_inl( lp, ID_REV ) >> 16)
  622. #define SMC_GET_REV(lp) (SMC_inl( lp, ID_REV ) & 0xFFFF)
  623. #define SMC_GET_IRQ_CFG(lp) SMC_inl( lp, INT_CFG )
  624. #define SMC_SET_IRQ_CFG(lp, x) SMC_outl( x, lp, INT_CFG )
  625. #define SMC_GET_INT(lp) SMC_inl( lp, INT_STS )
  626. #define SMC_ACK_INT(lp, x) SMC_outl( x, lp, INT_STS )
  627. #define SMC_GET_INT_EN(lp) SMC_inl( lp, INT_EN )
  628. #define SMC_SET_INT_EN(lp, x) SMC_outl( x, lp, INT_EN )
  629. #define SMC_GET_BYTE_TEST(lp) SMC_inl( lp, BYTE_TEST )
  630. #define SMC_SET_BYTE_TEST(lp, x) SMC_outl( x, lp, BYTE_TEST )
  631. #define SMC_GET_FIFO_INT(lp) SMC_inl( lp, FIFO_INT )
  632. #define SMC_SET_FIFO_INT(lp, x) SMC_outl( x, lp, FIFO_INT )
  633. #define SMC_SET_FIFO_TDA(lp, x) \
  634. do { \
  635. unsigned long __flags; \
  636. int __mask; \
  637. local_irq_save(__flags); \
  638. __mask = SMC_GET_FIFO_INT((lp)) & ~(0xFF<<24); \
  639. SMC_SET_FIFO_INT( (lp), __mask | (x)<<24 ); \
  640. local_irq_restore(__flags); \
  641. } while (0)
  642. #define SMC_SET_FIFO_TSL(lp, x) \
  643. do { \
  644. unsigned long __flags; \
  645. int __mask; \
  646. local_irq_save(__flags); \
  647. __mask = SMC_GET_FIFO_INT((lp)) & ~(0xFF<<16); \
  648. SMC_SET_FIFO_INT( (lp), __mask | (((x) & 0xFF)<<16)); \
  649. local_irq_restore(__flags); \
  650. } while (0)
  651. #define SMC_SET_FIFO_RSA(lp, x) \
  652. do { \
  653. unsigned long __flags; \
  654. int __mask; \
  655. local_irq_save(__flags); \
  656. __mask = SMC_GET_FIFO_INT((lp)) & ~(0xFF<<8); \
  657. SMC_SET_FIFO_INT( (lp), __mask | (((x) & 0xFF)<<8)); \
  658. local_irq_restore(__flags); \
  659. } while (0)
  660. #define SMC_SET_FIFO_RSL(lp, x) \
  661. do { \
  662. unsigned long __flags; \
  663. int __mask; \
  664. local_irq_save(__flags); \
  665. __mask = SMC_GET_FIFO_INT((lp)) & ~0xFF; \
  666. SMC_SET_FIFO_INT( (lp),__mask | ((x) & 0xFF)); \
  667. local_irq_restore(__flags); \
  668. } while (0)
  669. #define SMC_GET_RX_CFG(lp) SMC_inl( lp, RX_CFG )
  670. #define SMC_SET_RX_CFG(lp, x) SMC_outl( x, lp, RX_CFG )
  671. #define SMC_GET_TX_CFG(lp) SMC_inl( lp, TX_CFG )
  672. #define SMC_SET_TX_CFG(lp, x) SMC_outl( x, lp, TX_CFG )
  673. #define SMC_GET_HW_CFG(lp) SMC_inl( lp, HW_CFG )
  674. #define SMC_SET_HW_CFG(lp, x) SMC_outl( x, lp, HW_CFG )
  675. #define SMC_GET_RX_DP_CTRL(lp) SMC_inl( lp, RX_DP_CTRL )
  676. #define SMC_SET_RX_DP_CTRL(lp, x) SMC_outl( x, lp, RX_DP_CTRL )
  677. #define SMC_GET_PMT_CTRL(lp) SMC_inl( lp, PMT_CTRL )
  678. #define SMC_SET_PMT_CTRL(lp, x) SMC_outl( x, lp, PMT_CTRL )
  679. #define SMC_GET_GPIO_CFG(lp) SMC_inl( lp, GPIO_CFG )
  680. #define SMC_SET_GPIO_CFG(lp, x) SMC_outl( x, lp, GPIO_CFG )
  681. #define SMC_GET_RX_FIFO_INF(lp) SMC_inl( lp, RX_FIFO_INF )
  682. #define SMC_SET_RX_FIFO_INF(lp, x) SMC_outl( x, lp, RX_FIFO_INF )
  683. #define SMC_GET_TX_FIFO_INF(lp) SMC_inl( lp, TX_FIFO_INF )
  684. #define SMC_SET_TX_FIFO_INF(lp, x) SMC_outl( x, lp, TX_FIFO_INF )
  685. #define SMC_GET_GPT_CFG(lp) SMC_inl( lp, GPT_CFG )
  686. #define SMC_SET_GPT_CFG(lp, x) SMC_outl( x, lp, GPT_CFG )
  687. #define SMC_GET_RX_DROP(lp) SMC_inl( lp, RX_DROP )
  688. #define SMC_SET_RX_DROP(lp, x) SMC_outl( x, lp, RX_DROP )
  689. #define SMC_GET_MAC_CMD(lp) SMC_inl( lp, MAC_CSR_CMD )
  690. #define SMC_SET_MAC_CMD(lp, x) SMC_outl( x, lp, MAC_CSR_CMD )
  691. #define SMC_GET_MAC_DATA(lp) SMC_inl( lp, MAC_CSR_DATA )
  692. #define SMC_SET_MAC_DATA(lp, x) SMC_outl( x, lp, MAC_CSR_DATA )
  693. #define SMC_GET_AFC_CFG(lp) SMC_inl( lp, AFC_CFG )
  694. #define SMC_SET_AFC_CFG(lp, x) SMC_outl( x, lp, AFC_CFG )
  695. #define SMC_GET_E2P_CMD(lp) SMC_inl( lp, E2P_CMD )
  696. #define SMC_SET_E2P_CMD(lp, x) SMC_outl( x, lp, E2P_CMD )
  697. #define SMC_GET_E2P_DATA(lp) SMC_inl( lp, E2P_DATA )
  698. #define SMC_SET_E2P_DATA(lp, x) SMC_outl( x, lp, E2P_DATA )
  699. /* MAC register read/write macros */
  700. #define SMC_GET_MAC_CSR(lp,a,v) \
  701. do { \
  702. while (SMC_GET_MAC_CMD((lp)) & MAC_CSR_CMD_CSR_BUSY_); \
  703. SMC_SET_MAC_CMD((lp),MAC_CSR_CMD_CSR_BUSY_ | \
  704. MAC_CSR_CMD_R_NOT_W_ | (a) ); \
  705. while (SMC_GET_MAC_CMD((lp)) & MAC_CSR_CMD_CSR_BUSY_); \
  706. v = SMC_GET_MAC_DATA((lp)); \
  707. } while (0)
  708. #define SMC_SET_MAC_CSR(lp,a,v) \
  709. do { \
  710. while (SMC_GET_MAC_CMD((lp)) & MAC_CSR_CMD_CSR_BUSY_); \
  711. SMC_SET_MAC_DATA((lp), v); \
  712. SMC_SET_MAC_CMD((lp), MAC_CSR_CMD_CSR_BUSY_ | (a) ); \
  713. while (SMC_GET_MAC_CMD((lp)) & MAC_CSR_CMD_CSR_BUSY_); \
  714. } while (0)
  715. #define SMC_GET_MAC_CR(lp, x) SMC_GET_MAC_CSR( (lp), MAC_CR, x )
  716. #define SMC_SET_MAC_CR(lp, x) SMC_SET_MAC_CSR( (lp), MAC_CR, x )
  717. #define SMC_GET_ADDRH(lp, x) SMC_GET_MAC_CSR( (lp), ADDRH, x )
  718. #define SMC_SET_ADDRH(lp, x) SMC_SET_MAC_CSR( (lp), ADDRH, x )
  719. #define SMC_GET_ADDRL(lp, x) SMC_GET_MAC_CSR( (lp), ADDRL, x )
  720. #define SMC_SET_ADDRL(lp, x) SMC_SET_MAC_CSR( (lp), ADDRL, x )
  721. #define SMC_GET_HASHH(lp, x) SMC_GET_MAC_CSR( (lp), HASHH, x )
  722. #define SMC_SET_HASHH(lp, x) SMC_SET_MAC_CSR( (lp), HASHH, x )
  723. #define SMC_GET_HASHL(lp, x) SMC_GET_MAC_CSR( (lp), HASHL, x )
  724. #define SMC_SET_HASHL(lp, x) SMC_SET_MAC_CSR( (lp), HASHL, x )
  725. #define SMC_GET_MII_ACC(lp, x) SMC_GET_MAC_CSR( (lp), MII_ACC, x )
  726. #define SMC_SET_MII_ACC(lp, x) SMC_SET_MAC_CSR( (lp), MII_ACC, x )
  727. #define SMC_GET_MII_DATA(lp, x) SMC_GET_MAC_CSR( (lp), MII_DATA, x )
  728. #define SMC_SET_MII_DATA(lp, x) SMC_SET_MAC_CSR( (lp), MII_DATA, x )
  729. #define SMC_GET_FLOW(lp, x) SMC_GET_MAC_CSR( (lp), FLOW, x )
  730. #define SMC_SET_FLOW(lp, x) SMC_SET_MAC_CSR( (lp), FLOW, x )
  731. #define SMC_GET_VLAN1(lp, x) SMC_GET_MAC_CSR( (lp), VLAN1, x )
  732. #define SMC_SET_VLAN1(lp, x) SMC_SET_MAC_CSR( (lp), VLAN1, x )
  733. #define SMC_GET_VLAN2(lp, x) SMC_GET_MAC_CSR( (lp), VLAN2, x )
  734. #define SMC_SET_VLAN2(lp, x) SMC_SET_MAC_CSR( (lp), VLAN2, x )
  735. #define SMC_SET_WUFF(lp, x) SMC_SET_MAC_CSR( (lp), WUFF, x )
  736. #define SMC_GET_WUCSR(lp, x) SMC_GET_MAC_CSR( (lp), WUCSR, x )
  737. #define SMC_SET_WUCSR(lp, x) SMC_SET_MAC_CSR( (lp), WUCSR, x )
  738. /* PHY register read/write macros */
  739. #define SMC_GET_MII(lp,a,phy,v) \
  740. do { \
  741. u32 __v; \
  742. do { \
  743. SMC_GET_MII_ACC((lp), __v); \
  744. } while ( __v & MII_ACC_MII_BUSY_ ); \
  745. SMC_SET_MII_ACC( (lp), ((phy)<<11) | ((a)<<6) | \
  746. MII_ACC_MII_BUSY_); \
  747. do { \
  748. SMC_GET_MII_ACC( (lp), __v); \
  749. } while ( __v & MII_ACC_MII_BUSY_ ); \
  750. SMC_GET_MII_DATA((lp), v); \
  751. } while (0)
  752. #define SMC_SET_MII(lp,a,phy,v) \
  753. do { \
  754. u32 __v; \
  755. do { \
  756. SMC_GET_MII_ACC((lp), __v); \
  757. } while ( __v & MII_ACC_MII_BUSY_ ); \
  758. SMC_SET_MII_DATA((lp), v); \
  759. SMC_SET_MII_ACC( (lp), ((phy)<<11) | ((a)<<6) | \
  760. MII_ACC_MII_BUSY_ | \
  761. MII_ACC_MII_WRITE_ ); \
  762. do { \
  763. SMC_GET_MII_ACC((lp), __v); \
  764. } while ( __v & MII_ACC_MII_BUSY_ ); \
  765. } while (0)
  766. #define SMC_GET_PHY_BMCR(lp,phy,x) SMC_GET_MII( (lp), MII_BMCR, phy, x )
  767. #define SMC_SET_PHY_BMCR(lp,phy,x) SMC_SET_MII( (lp), MII_BMCR, phy, x )
  768. #define SMC_GET_PHY_BMSR(lp,phy,x) SMC_GET_MII( (lp), MII_BMSR, phy, x )
  769. #define SMC_GET_PHY_ID1(lp,phy,x) SMC_GET_MII( (lp), MII_PHYSID1, phy, x )
  770. #define SMC_GET_PHY_ID2(lp,phy,x) SMC_GET_MII( (lp), MII_PHYSID2, phy, x )
  771. #define SMC_GET_PHY_MII_ADV(lp,phy,x) SMC_GET_MII( (lp), MII_ADVERTISE, phy, x )
  772. #define SMC_SET_PHY_MII_ADV(lp,phy,x) SMC_SET_MII( (lp), MII_ADVERTISE, phy, x )
  773. #define SMC_GET_PHY_MII_LPA(lp,phy,x) SMC_GET_MII( (lp), MII_LPA, phy, x )
  774. #define SMC_SET_PHY_MII_LPA(lp,phy,x) SMC_SET_MII( (lp), MII_LPA, phy, x )
  775. #define SMC_GET_PHY_CTRL_STS(lp,phy,x) SMC_GET_MII( (lp), PHY_MODE_CTRL_STS, phy, x )
  776. #define SMC_SET_PHY_CTRL_STS(lp,phy,x) SMC_SET_MII( (lp), PHY_MODE_CTRL_STS, phy, x )
  777. #define SMC_GET_PHY_INT_SRC(lp,phy,x) SMC_GET_MII( (lp), PHY_INT_SRC, phy, x )
  778. #define SMC_SET_PHY_INT_SRC(lp,phy,x) SMC_SET_MII( (lp), PHY_INT_SRC, phy, x )
  779. #define SMC_GET_PHY_INT_MASK(lp,phy,x) SMC_GET_MII( (lp), PHY_INT_MASK, phy, x )
  780. #define SMC_SET_PHY_INT_MASK(lp,phy,x) SMC_SET_MII( (lp), PHY_INT_MASK, phy, x )
  781. #define SMC_GET_PHY_SPECIAL(lp,phy,x) SMC_GET_MII( (lp), PHY_SPECIAL, phy, x )
  782. /* Misc read/write macros */
  783. #ifndef SMC_GET_MAC_ADDR
  784. #define SMC_GET_MAC_ADDR(lp, addr) \
  785. do { \
  786. unsigned int __v; \
  787. \
  788. SMC_GET_MAC_CSR((lp), ADDRL, __v); \
  789. addr[0] = __v; addr[1] = __v >> 8; \
  790. addr[2] = __v >> 16; addr[3] = __v >> 24; \
  791. SMC_GET_MAC_CSR((lp), ADDRH, __v); \
  792. addr[4] = __v; addr[5] = __v >> 8; \
  793. } while (0)
  794. #endif
  795. #define SMC_SET_MAC_ADDR(lp, addr) \
  796. do { \
  797. SMC_SET_MAC_CSR((lp), ADDRL, \
  798. addr[0] | \
  799. (addr[1] << 8) | \
  800. (addr[2] << 16) | \
  801. (addr[3] << 24)); \
  802. SMC_SET_MAC_CSR((lp), ADDRH, addr[4]|(addr[5] << 8));\
  803. } while (0)
  804. #define SMC_WRITE_EEPROM_CMD(lp, cmd, addr) \
  805. do { \
  806. while (SMC_GET_E2P_CMD((lp)) & MAC_CSR_CMD_CSR_BUSY_); \
  807. SMC_SET_MAC_CMD((lp), MAC_CSR_CMD_R_NOT_W_ | a ); \
  808. while (SMC_GET_MAC_CMD((lp)) & MAC_CSR_CMD_CSR_BUSY_); \
  809. } while (0)
  810. #endif /* _SMC911X_H_ */