pm3393.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790
  1. /*****************************************************************************
  2. * *
  3. * File: pm3393.c *
  4. * $Revision: 1.16 $ *
  5. * $Date: 2005/05/14 00:59:32 $ *
  6. * Description: *
  7. * PMC/SIERRA (pm3393) MAC-PHY functionality. *
  8. * part of the Chelsio 10Gb Ethernet Driver. *
  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, version 2, as *
  12. * published by the Free Software Foundation. *
  13. * *
  14. * You should have received a copy of the GNU General Public License along *
  15. * with this program; if not, see <http://www.gnu.org/licenses/>. *
  16. * *
  17. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED *
  18. * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF *
  19. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. *
  20. * *
  21. * http://www.chelsio.com *
  22. * *
  23. * Copyright (c) 2003 - 2005 Chelsio Communications, Inc. *
  24. * All rights reserved. *
  25. * *
  26. * Maintainers: maintainers@chelsio.com *
  27. * *
  28. * Authors: Dimitrios Michailidis <dm@chelsio.com> *
  29. * Tina Yang <tainay@chelsio.com> *
  30. * Felix Marti <felix@chelsio.com> *
  31. * Scott Bardone <sbardone@chelsio.com> *
  32. * Kurt Ottaway <kottaway@chelsio.com> *
  33. * Frank DiMambro <frank@chelsio.com> *
  34. * *
  35. * History: *
  36. * *
  37. ****************************************************************************/
  38. #include "common.h"
  39. #include "regs.h"
  40. #include "gmac.h"
  41. #include "elmer0.h"
  42. #include "suni1x10gexp_regs.h"
  43. #include <linux/crc32.h>
  44. #include <linux/slab.h>
  45. #define OFFSET(REG_ADDR) ((REG_ADDR) << 2)
  46. #define IPG 12
  47. #define TXXG_CONF1_VAL ((IPG << SUNI1x10GEXP_BITOFF_TXXG_IPGT) | \
  48. SUNI1x10GEXP_BITMSK_TXXG_32BIT_ALIGN | SUNI1x10GEXP_BITMSK_TXXG_CRCEN | \
  49. SUNI1x10GEXP_BITMSK_TXXG_PADEN)
  50. #define RXXG_CONF1_VAL (SUNI1x10GEXP_BITMSK_RXXG_PUREP | 0x14 | \
  51. SUNI1x10GEXP_BITMSK_RXXG_FLCHK | SUNI1x10GEXP_BITMSK_RXXG_CRC_STRIP)
  52. /* Update statistics every 15 minutes */
  53. #define STATS_TICK_SECS (15 * 60)
  54. enum { /* RMON registers */
  55. RxOctetsReceivedOK = SUNI1x10GEXP_REG_MSTAT_COUNTER_1_LOW,
  56. RxUnicastFramesReceivedOK = SUNI1x10GEXP_REG_MSTAT_COUNTER_4_LOW,
  57. RxMulticastFramesReceivedOK = SUNI1x10GEXP_REG_MSTAT_COUNTER_5_LOW,
  58. RxBroadcastFramesReceivedOK = SUNI1x10GEXP_REG_MSTAT_COUNTER_6_LOW,
  59. RxPAUSEMACCtrlFramesReceived = SUNI1x10GEXP_REG_MSTAT_COUNTER_8_LOW,
  60. RxFrameCheckSequenceErrors = SUNI1x10GEXP_REG_MSTAT_COUNTER_10_LOW,
  61. RxFramesLostDueToInternalMACErrors = SUNI1x10GEXP_REG_MSTAT_COUNTER_11_LOW,
  62. RxSymbolErrors = SUNI1x10GEXP_REG_MSTAT_COUNTER_12_LOW,
  63. RxInRangeLengthErrors = SUNI1x10GEXP_REG_MSTAT_COUNTER_13_LOW,
  64. RxFramesTooLongErrors = SUNI1x10GEXP_REG_MSTAT_COUNTER_15_LOW,
  65. RxJabbers = SUNI1x10GEXP_REG_MSTAT_COUNTER_16_LOW,
  66. RxFragments = SUNI1x10GEXP_REG_MSTAT_COUNTER_17_LOW,
  67. RxUndersizedFrames = SUNI1x10GEXP_REG_MSTAT_COUNTER_18_LOW,
  68. RxJumboFramesReceivedOK = SUNI1x10GEXP_REG_MSTAT_COUNTER_25_LOW,
  69. RxJumboOctetsReceivedOK = SUNI1x10GEXP_REG_MSTAT_COUNTER_26_LOW,
  70. TxOctetsTransmittedOK = SUNI1x10GEXP_REG_MSTAT_COUNTER_33_LOW,
  71. TxFramesLostDueToInternalMACTransmissionError = SUNI1x10GEXP_REG_MSTAT_COUNTER_35_LOW,
  72. TxTransmitSystemError = SUNI1x10GEXP_REG_MSTAT_COUNTER_36_LOW,
  73. TxUnicastFramesTransmittedOK = SUNI1x10GEXP_REG_MSTAT_COUNTER_38_LOW,
  74. TxMulticastFramesTransmittedOK = SUNI1x10GEXP_REG_MSTAT_COUNTER_40_LOW,
  75. TxBroadcastFramesTransmittedOK = SUNI1x10GEXP_REG_MSTAT_COUNTER_42_LOW,
  76. TxPAUSEMACCtrlFramesTransmitted = SUNI1x10GEXP_REG_MSTAT_COUNTER_43_LOW,
  77. TxJumboFramesReceivedOK = SUNI1x10GEXP_REG_MSTAT_COUNTER_51_LOW,
  78. TxJumboOctetsReceivedOK = SUNI1x10GEXP_REG_MSTAT_COUNTER_52_LOW
  79. };
  80. struct _cmac_instance {
  81. u8 enabled;
  82. u8 fc;
  83. u8 mac_addr[6];
  84. };
  85. static int pmread(struct cmac *cmac, u32 reg, u32 * data32)
  86. {
  87. t1_tpi_read(cmac->adapter, OFFSET(reg), data32);
  88. return 0;
  89. }
  90. static int pmwrite(struct cmac *cmac, u32 reg, u32 data32)
  91. {
  92. t1_tpi_write(cmac->adapter, OFFSET(reg), data32);
  93. return 0;
  94. }
  95. /* Port reset. */
  96. static int pm3393_reset(struct cmac *cmac)
  97. {
  98. return 0;
  99. }
  100. /*
  101. * Enable interrupts for the PM3393
  102. *
  103. * 1. Enable PM3393 BLOCK interrupts.
  104. * 2. Enable PM3393 Master Interrupt bit(INTE)
  105. * 3. Enable ELMER's PM3393 bit.
  106. * 4. Enable Terminator external interrupt.
  107. */
  108. static int pm3393_interrupt_enable(struct cmac *cmac)
  109. {
  110. u32 pl_intr;
  111. /* PM3393 - Enabling all hardware block interrupts.
  112. */
  113. pmwrite(cmac, SUNI1x10GEXP_REG_SERDES_3125_INTERRUPT_ENABLE, 0xffff);
  114. pmwrite(cmac, SUNI1x10GEXP_REG_XRF_INTERRUPT_ENABLE, 0xffff);
  115. pmwrite(cmac, SUNI1x10GEXP_REG_XRF_DIAG_INTERRUPT_ENABLE, 0xffff);
  116. pmwrite(cmac, SUNI1x10GEXP_REG_RXOAM_INTERRUPT_ENABLE, 0xffff);
  117. /* Don't interrupt on statistics overflow, we are polling */
  118. pmwrite(cmac, SUNI1x10GEXP_REG_MSTAT_INTERRUPT_MASK_0, 0);
  119. pmwrite(cmac, SUNI1x10GEXP_REG_MSTAT_INTERRUPT_MASK_1, 0);
  120. pmwrite(cmac, SUNI1x10GEXP_REG_MSTAT_INTERRUPT_MASK_2, 0);
  121. pmwrite(cmac, SUNI1x10GEXP_REG_MSTAT_INTERRUPT_MASK_3, 0);
  122. pmwrite(cmac, SUNI1x10GEXP_REG_IFLX_FIFO_OVERFLOW_ENABLE, 0xffff);
  123. pmwrite(cmac, SUNI1x10GEXP_REG_PL4ODP_INTERRUPT_MASK, 0xffff);
  124. pmwrite(cmac, SUNI1x10GEXP_REG_XTEF_INTERRUPT_ENABLE, 0xffff);
  125. pmwrite(cmac, SUNI1x10GEXP_REG_TXOAM_INTERRUPT_ENABLE, 0xffff);
  126. pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_CONFIG_3, 0xffff);
  127. pmwrite(cmac, SUNI1x10GEXP_REG_PL4IO_LOCK_DETECT_MASK, 0xffff);
  128. pmwrite(cmac, SUNI1x10GEXP_REG_TXXG_CONFIG_3, 0xffff);
  129. pmwrite(cmac, SUNI1x10GEXP_REG_PL4IDU_INTERRUPT_MASK, 0xffff);
  130. pmwrite(cmac, SUNI1x10GEXP_REG_EFLX_FIFO_OVERFLOW_ERROR_ENABLE, 0xffff);
  131. /* PM3393 - Global interrupt enable
  132. */
  133. /* TBD XXX Disable for now until we figure out why error interrupts keep asserting. */
  134. pmwrite(cmac, SUNI1x10GEXP_REG_GLOBAL_INTERRUPT_ENABLE,
  135. 0 /*SUNI1x10GEXP_BITMSK_TOP_INTE */ );
  136. /* TERMINATOR - PL_INTERUPTS_EXT */
  137. pl_intr = readl(cmac->adapter->regs + A_PL_ENABLE);
  138. pl_intr |= F_PL_INTR_EXT;
  139. writel(pl_intr, cmac->adapter->regs + A_PL_ENABLE);
  140. return 0;
  141. }
  142. static int pm3393_interrupt_disable(struct cmac *cmac)
  143. {
  144. u32 elmer;
  145. /* PM3393 - Enabling HW interrupt blocks. */
  146. pmwrite(cmac, SUNI1x10GEXP_REG_SERDES_3125_INTERRUPT_ENABLE, 0);
  147. pmwrite(cmac, SUNI1x10GEXP_REG_XRF_INTERRUPT_ENABLE, 0);
  148. pmwrite(cmac, SUNI1x10GEXP_REG_XRF_DIAG_INTERRUPT_ENABLE, 0);
  149. pmwrite(cmac, SUNI1x10GEXP_REG_RXOAM_INTERRUPT_ENABLE, 0);
  150. pmwrite(cmac, SUNI1x10GEXP_REG_MSTAT_INTERRUPT_MASK_0, 0);
  151. pmwrite(cmac, SUNI1x10GEXP_REG_MSTAT_INTERRUPT_MASK_1, 0);
  152. pmwrite(cmac, SUNI1x10GEXP_REG_MSTAT_INTERRUPT_MASK_2, 0);
  153. pmwrite(cmac, SUNI1x10GEXP_REG_MSTAT_INTERRUPT_MASK_3, 0);
  154. pmwrite(cmac, SUNI1x10GEXP_REG_IFLX_FIFO_OVERFLOW_ENABLE, 0);
  155. pmwrite(cmac, SUNI1x10GEXP_REG_PL4ODP_INTERRUPT_MASK, 0);
  156. pmwrite(cmac, SUNI1x10GEXP_REG_XTEF_INTERRUPT_ENABLE, 0);
  157. pmwrite(cmac, SUNI1x10GEXP_REG_TXOAM_INTERRUPT_ENABLE, 0);
  158. pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_CONFIG_3, 0);
  159. pmwrite(cmac, SUNI1x10GEXP_REG_PL4IO_LOCK_DETECT_MASK, 0);
  160. pmwrite(cmac, SUNI1x10GEXP_REG_TXXG_CONFIG_3, 0);
  161. pmwrite(cmac, SUNI1x10GEXP_REG_PL4IDU_INTERRUPT_MASK, 0);
  162. pmwrite(cmac, SUNI1x10GEXP_REG_EFLX_FIFO_OVERFLOW_ERROR_ENABLE, 0);
  163. /* PM3393 - Global interrupt enable */
  164. pmwrite(cmac, SUNI1x10GEXP_REG_GLOBAL_INTERRUPT_ENABLE, 0);
  165. /* ELMER - External chip interrupts. */
  166. t1_tpi_read(cmac->adapter, A_ELMER0_INT_ENABLE, &elmer);
  167. elmer &= ~ELMER0_GP_BIT1;
  168. t1_tpi_write(cmac->adapter, A_ELMER0_INT_ENABLE, elmer);
  169. /* TERMINATOR - PL_INTERUPTS_EXT */
  170. /* DO NOT DISABLE TERMINATOR's EXTERNAL INTERRUPTS. ANOTHER CHIP
  171. * COULD WANT THEM ENABLED. We disable PM3393 at the ELMER level.
  172. */
  173. return 0;
  174. }
  175. static int pm3393_interrupt_clear(struct cmac *cmac)
  176. {
  177. u32 elmer;
  178. u32 pl_intr;
  179. u32 val32;
  180. /* PM3393 - Clearing HW interrupt blocks. Note, this assumes
  181. * bit WCIMODE=0 for a clear-on-read.
  182. */
  183. pmread(cmac, SUNI1x10GEXP_REG_SERDES_3125_INTERRUPT_STATUS, &val32);
  184. pmread(cmac, SUNI1x10GEXP_REG_XRF_INTERRUPT_STATUS, &val32);
  185. pmread(cmac, SUNI1x10GEXP_REG_XRF_DIAG_INTERRUPT_STATUS, &val32);
  186. pmread(cmac, SUNI1x10GEXP_REG_RXOAM_INTERRUPT_STATUS, &val32);
  187. pmread(cmac, SUNI1x10GEXP_REG_PL4ODP_INTERRUPT, &val32);
  188. pmread(cmac, SUNI1x10GEXP_REG_XTEF_INTERRUPT_STATUS, &val32);
  189. pmread(cmac, SUNI1x10GEXP_REG_IFLX_FIFO_OVERFLOW_INTERRUPT, &val32);
  190. pmread(cmac, SUNI1x10GEXP_REG_TXOAM_INTERRUPT_STATUS, &val32);
  191. pmread(cmac, SUNI1x10GEXP_REG_RXXG_INTERRUPT, &val32);
  192. pmread(cmac, SUNI1x10GEXP_REG_TXXG_INTERRUPT, &val32);
  193. pmread(cmac, SUNI1x10GEXP_REG_PL4IDU_INTERRUPT, &val32);
  194. pmread(cmac, SUNI1x10GEXP_REG_EFLX_FIFO_OVERFLOW_ERROR_INDICATION,
  195. &val32);
  196. pmread(cmac, SUNI1x10GEXP_REG_PL4IO_LOCK_DETECT_STATUS, &val32);
  197. pmread(cmac, SUNI1x10GEXP_REG_PL4IO_LOCK_DETECT_CHANGE, &val32);
  198. /* PM3393 - Global interrupt status
  199. */
  200. pmread(cmac, SUNI1x10GEXP_REG_MASTER_INTERRUPT_STATUS, &val32);
  201. /* ELMER - External chip interrupts.
  202. */
  203. t1_tpi_read(cmac->adapter, A_ELMER0_INT_CAUSE, &elmer);
  204. elmer |= ELMER0_GP_BIT1;
  205. t1_tpi_write(cmac->adapter, A_ELMER0_INT_CAUSE, elmer);
  206. /* TERMINATOR - PL_INTERUPTS_EXT
  207. */
  208. pl_intr = readl(cmac->adapter->regs + A_PL_CAUSE);
  209. pl_intr |= F_PL_INTR_EXT;
  210. writel(pl_intr, cmac->adapter->regs + A_PL_CAUSE);
  211. return 0;
  212. }
  213. /* Interrupt handler */
  214. static int pm3393_interrupt_handler(struct cmac *cmac)
  215. {
  216. u32 master_intr_status;
  217. /* Read the master interrupt status register. */
  218. pmread(cmac, SUNI1x10GEXP_REG_MASTER_INTERRUPT_STATUS,
  219. &master_intr_status);
  220. if (netif_msg_intr(cmac->adapter))
  221. dev_dbg(&cmac->adapter->pdev->dev, "PM3393 intr cause 0x%x\n",
  222. master_intr_status);
  223. /* TBD XXX Lets just clear everything for now */
  224. pm3393_interrupt_clear(cmac);
  225. return 0;
  226. }
  227. static int pm3393_enable(struct cmac *cmac, int which)
  228. {
  229. if (which & MAC_DIRECTION_RX)
  230. pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_CONFIG_1,
  231. (RXXG_CONF1_VAL | SUNI1x10GEXP_BITMSK_RXXG_RXEN));
  232. if (which & MAC_DIRECTION_TX) {
  233. u32 val = TXXG_CONF1_VAL | SUNI1x10GEXP_BITMSK_TXXG_TXEN0;
  234. if (cmac->instance->fc & PAUSE_RX)
  235. val |= SUNI1x10GEXP_BITMSK_TXXG_FCRX;
  236. if (cmac->instance->fc & PAUSE_TX)
  237. val |= SUNI1x10GEXP_BITMSK_TXXG_FCTX;
  238. pmwrite(cmac, SUNI1x10GEXP_REG_TXXG_CONFIG_1, val);
  239. }
  240. cmac->instance->enabled |= which;
  241. return 0;
  242. }
  243. static int pm3393_enable_port(struct cmac *cmac, int which)
  244. {
  245. /* Clear port statistics */
  246. pmwrite(cmac, SUNI1x10GEXP_REG_MSTAT_CONTROL,
  247. SUNI1x10GEXP_BITMSK_MSTAT_CLEAR);
  248. udelay(2);
  249. memset(&cmac->stats, 0, sizeof(struct cmac_statistics));
  250. pm3393_enable(cmac, which);
  251. /*
  252. * XXX This should be done by the PHY and preferably not at all.
  253. * The PHY doesn't give us link status indication on its own so have
  254. * the link management code query it instead.
  255. */
  256. t1_link_changed(cmac->adapter, 0);
  257. return 0;
  258. }
  259. static int pm3393_disable(struct cmac *cmac, int which)
  260. {
  261. if (which & MAC_DIRECTION_RX)
  262. pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_CONFIG_1, RXXG_CONF1_VAL);
  263. if (which & MAC_DIRECTION_TX)
  264. pmwrite(cmac, SUNI1x10GEXP_REG_TXXG_CONFIG_1, TXXG_CONF1_VAL);
  265. /*
  266. * The disable is graceful. Give the PM3393 time. Can't wait very
  267. * long here, we may be holding locks.
  268. */
  269. udelay(20);
  270. cmac->instance->enabled &= ~which;
  271. return 0;
  272. }
  273. static int pm3393_loopback_enable(struct cmac *cmac)
  274. {
  275. return 0;
  276. }
  277. static int pm3393_loopback_disable(struct cmac *cmac)
  278. {
  279. return 0;
  280. }
  281. static int pm3393_set_mtu(struct cmac *cmac, int mtu)
  282. {
  283. int enabled = cmac->instance->enabled;
  284. mtu += ETH_HLEN + ETH_FCS_LEN;
  285. /* Disable Rx/Tx MAC before configuring it. */
  286. if (enabled)
  287. pm3393_disable(cmac, MAC_DIRECTION_RX | MAC_DIRECTION_TX);
  288. pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_MAX_FRAME_LENGTH, mtu);
  289. pmwrite(cmac, SUNI1x10GEXP_REG_TXXG_MAX_FRAME_SIZE, mtu);
  290. if (enabled)
  291. pm3393_enable(cmac, enabled);
  292. return 0;
  293. }
  294. static int pm3393_set_rx_mode(struct cmac *cmac, struct t1_rx_mode *rm)
  295. {
  296. int enabled = cmac->instance->enabled & MAC_DIRECTION_RX;
  297. u32 rx_mode;
  298. /* Disable MAC RX before reconfiguring it */
  299. if (enabled)
  300. pm3393_disable(cmac, MAC_DIRECTION_RX);
  301. pmread(cmac, SUNI1x10GEXP_REG_RXXG_ADDRESS_FILTER_CONTROL_2, &rx_mode);
  302. rx_mode &= ~(SUNI1x10GEXP_BITMSK_RXXG_PMODE |
  303. SUNI1x10GEXP_BITMSK_RXXG_MHASH_EN);
  304. pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_ADDRESS_FILTER_CONTROL_2,
  305. (u16)rx_mode);
  306. if (t1_rx_mode_promisc(rm)) {
  307. /* Promiscuous mode. */
  308. rx_mode |= SUNI1x10GEXP_BITMSK_RXXG_PMODE;
  309. }
  310. if (t1_rx_mode_allmulti(rm)) {
  311. /* Accept all multicast. */
  312. pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_MULTICAST_HASH_LOW, 0xffff);
  313. pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_MULTICAST_HASH_MIDLOW, 0xffff);
  314. pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_MULTICAST_HASH_MIDHIGH, 0xffff);
  315. pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_MULTICAST_HASH_HIGH, 0xffff);
  316. rx_mode |= SUNI1x10GEXP_BITMSK_RXXG_MHASH_EN;
  317. } else if (t1_rx_mode_mc_cnt(rm)) {
  318. /* Accept one or more multicast(s). */
  319. struct netdev_hw_addr *ha;
  320. int bit;
  321. u16 mc_filter[4] = { 0, };
  322. netdev_for_each_mc_addr(ha, t1_get_netdev(rm)) {
  323. /* bit[23:28] */
  324. bit = (ether_crc(ETH_ALEN, ha->addr) >> 23) & 0x3f;
  325. mc_filter[bit >> 4] |= 1 << (bit & 0xf);
  326. }
  327. pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_MULTICAST_HASH_LOW, mc_filter[0]);
  328. pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_MULTICAST_HASH_MIDLOW, mc_filter[1]);
  329. pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_MULTICAST_HASH_MIDHIGH, mc_filter[2]);
  330. pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_MULTICAST_HASH_HIGH, mc_filter[3]);
  331. rx_mode |= SUNI1x10GEXP_BITMSK_RXXG_MHASH_EN;
  332. }
  333. pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_ADDRESS_FILTER_CONTROL_2, (u16)rx_mode);
  334. if (enabled)
  335. pm3393_enable(cmac, MAC_DIRECTION_RX);
  336. return 0;
  337. }
  338. static int pm3393_get_speed_duplex_fc(struct cmac *cmac, int *speed,
  339. int *duplex, int *fc)
  340. {
  341. if (speed)
  342. *speed = SPEED_10000;
  343. if (duplex)
  344. *duplex = DUPLEX_FULL;
  345. if (fc)
  346. *fc = cmac->instance->fc;
  347. return 0;
  348. }
  349. static int pm3393_set_speed_duplex_fc(struct cmac *cmac, int speed, int duplex,
  350. int fc)
  351. {
  352. if (speed >= 0 && speed != SPEED_10000)
  353. return -1;
  354. if (duplex >= 0 && duplex != DUPLEX_FULL)
  355. return -1;
  356. if (fc & ~(PAUSE_TX | PAUSE_RX))
  357. return -1;
  358. if (fc != cmac->instance->fc) {
  359. cmac->instance->fc = (u8) fc;
  360. if (cmac->instance->enabled & MAC_DIRECTION_TX)
  361. pm3393_enable(cmac, MAC_DIRECTION_TX);
  362. }
  363. return 0;
  364. }
  365. #define RMON_UPDATE(mac, name, stat_name) \
  366. { \
  367. t1_tpi_read((mac)->adapter, OFFSET(name), &val0); \
  368. t1_tpi_read((mac)->adapter, OFFSET((name)+1), &val1); \
  369. t1_tpi_read((mac)->adapter, OFFSET((name)+2), &val2); \
  370. (mac)->stats.stat_name = (u64)(val0 & 0xffff) | \
  371. ((u64)(val1 & 0xffff) << 16) | \
  372. ((u64)(val2 & 0xff) << 32) | \
  373. ((mac)->stats.stat_name & \
  374. 0xffffff0000000000ULL); \
  375. if (ro & \
  376. (1ULL << ((name - SUNI1x10GEXP_REG_MSTAT_COUNTER_0_LOW) >> 2))) \
  377. (mac)->stats.stat_name += 1ULL << 40; \
  378. }
  379. static const struct cmac_statistics *pm3393_update_statistics(struct cmac *mac,
  380. int flag)
  381. {
  382. u64 ro;
  383. u32 val0, val1, val2, val3;
  384. /* Snap the counters */
  385. pmwrite(mac, SUNI1x10GEXP_REG_MSTAT_CONTROL,
  386. SUNI1x10GEXP_BITMSK_MSTAT_SNAP);
  387. /* Counter rollover, clear on read */
  388. pmread(mac, SUNI1x10GEXP_REG_MSTAT_COUNTER_ROLLOVER_0, &val0);
  389. pmread(mac, SUNI1x10GEXP_REG_MSTAT_COUNTER_ROLLOVER_1, &val1);
  390. pmread(mac, SUNI1x10GEXP_REG_MSTAT_COUNTER_ROLLOVER_2, &val2);
  391. pmread(mac, SUNI1x10GEXP_REG_MSTAT_COUNTER_ROLLOVER_3, &val3);
  392. ro = ((u64)val0 & 0xffff) | (((u64)val1 & 0xffff) << 16) |
  393. (((u64)val2 & 0xffff) << 32) | (((u64)val3 & 0xffff) << 48);
  394. /* Rx stats */
  395. RMON_UPDATE(mac, RxOctetsReceivedOK, RxOctetsOK);
  396. RMON_UPDATE(mac, RxUnicastFramesReceivedOK, RxUnicastFramesOK);
  397. RMON_UPDATE(mac, RxMulticastFramesReceivedOK, RxMulticastFramesOK);
  398. RMON_UPDATE(mac, RxBroadcastFramesReceivedOK, RxBroadcastFramesOK);
  399. RMON_UPDATE(mac, RxPAUSEMACCtrlFramesReceived, RxPauseFrames);
  400. RMON_UPDATE(mac, RxFrameCheckSequenceErrors, RxFCSErrors);
  401. RMON_UPDATE(mac, RxFramesLostDueToInternalMACErrors,
  402. RxInternalMACRcvError);
  403. RMON_UPDATE(mac, RxSymbolErrors, RxSymbolErrors);
  404. RMON_UPDATE(mac, RxInRangeLengthErrors, RxInRangeLengthErrors);
  405. RMON_UPDATE(mac, RxFramesTooLongErrors , RxFrameTooLongErrors);
  406. RMON_UPDATE(mac, RxJabbers, RxJabberErrors);
  407. RMON_UPDATE(mac, RxFragments, RxRuntErrors);
  408. RMON_UPDATE(mac, RxUndersizedFrames, RxRuntErrors);
  409. RMON_UPDATE(mac, RxJumboFramesReceivedOK, RxJumboFramesOK);
  410. RMON_UPDATE(mac, RxJumboOctetsReceivedOK, RxJumboOctetsOK);
  411. /* Tx stats */
  412. RMON_UPDATE(mac, TxOctetsTransmittedOK, TxOctetsOK);
  413. RMON_UPDATE(mac, TxFramesLostDueToInternalMACTransmissionError,
  414. TxInternalMACXmitError);
  415. RMON_UPDATE(mac, TxTransmitSystemError, TxFCSErrors);
  416. RMON_UPDATE(mac, TxUnicastFramesTransmittedOK, TxUnicastFramesOK);
  417. RMON_UPDATE(mac, TxMulticastFramesTransmittedOK, TxMulticastFramesOK);
  418. RMON_UPDATE(mac, TxBroadcastFramesTransmittedOK, TxBroadcastFramesOK);
  419. RMON_UPDATE(mac, TxPAUSEMACCtrlFramesTransmitted, TxPauseFrames);
  420. RMON_UPDATE(mac, TxJumboFramesReceivedOK, TxJumboFramesOK);
  421. RMON_UPDATE(mac, TxJumboOctetsReceivedOK, TxJumboOctetsOK);
  422. return &mac->stats;
  423. }
  424. static int pm3393_macaddress_get(struct cmac *cmac, u8 mac_addr[6])
  425. {
  426. memcpy(mac_addr, cmac->instance->mac_addr, ETH_ALEN);
  427. return 0;
  428. }
  429. static int pm3393_macaddress_set(struct cmac *cmac, u8 ma[6])
  430. {
  431. u32 val, lo, mid, hi, enabled = cmac->instance->enabled;
  432. /*
  433. * MAC addr: 00:07:43:00:13:09
  434. *
  435. * ma[5] = 0x09
  436. * ma[4] = 0x13
  437. * ma[3] = 0x00
  438. * ma[2] = 0x43
  439. * ma[1] = 0x07
  440. * ma[0] = 0x00
  441. *
  442. * The PM3393 requires byte swapping and reverse order entry
  443. * when programming MAC addresses:
  444. *
  445. * low_bits[15:0] = ma[1]:ma[0]
  446. * mid_bits[31:16] = ma[3]:ma[2]
  447. * high_bits[47:32] = ma[5]:ma[4]
  448. */
  449. /* Store local copy */
  450. memcpy(cmac->instance->mac_addr, ma, ETH_ALEN);
  451. lo = ((u32) ma[1] << 8) | (u32) ma[0];
  452. mid = ((u32) ma[3] << 8) | (u32) ma[2];
  453. hi = ((u32) ma[5] << 8) | (u32) ma[4];
  454. /* Disable Rx/Tx MAC before configuring it. */
  455. if (enabled)
  456. pm3393_disable(cmac, MAC_DIRECTION_RX | MAC_DIRECTION_TX);
  457. /* Set RXXG Station Address */
  458. pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_SA_15_0, lo);
  459. pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_SA_31_16, mid);
  460. pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_SA_47_32, hi);
  461. /* Set TXXG Station Address */
  462. pmwrite(cmac, SUNI1x10GEXP_REG_TXXG_SA_15_0, lo);
  463. pmwrite(cmac, SUNI1x10GEXP_REG_TXXG_SA_31_16, mid);
  464. pmwrite(cmac, SUNI1x10GEXP_REG_TXXG_SA_47_32, hi);
  465. /* Setup Exact Match Filter 1 with our MAC address
  466. *
  467. * Must disable exact match filter before configuring it.
  468. */
  469. pmread(cmac, SUNI1x10GEXP_REG_RXXG_ADDRESS_FILTER_CONTROL_0, &val);
  470. val &= 0xff0f;
  471. pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_ADDRESS_FILTER_CONTROL_0, val);
  472. pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_EXACT_MATCH_ADDR_1_LOW, lo);
  473. pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_EXACT_MATCH_ADDR_1_MID, mid);
  474. pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_EXACT_MATCH_ADDR_1_HIGH, hi);
  475. val |= 0x0090;
  476. pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_ADDRESS_FILTER_CONTROL_0, val);
  477. if (enabled)
  478. pm3393_enable(cmac, enabled);
  479. return 0;
  480. }
  481. static void pm3393_destroy(struct cmac *cmac)
  482. {
  483. kfree(cmac);
  484. }
  485. static const struct cmac_ops pm3393_ops = {
  486. .destroy = pm3393_destroy,
  487. .reset = pm3393_reset,
  488. .interrupt_enable = pm3393_interrupt_enable,
  489. .interrupt_disable = pm3393_interrupt_disable,
  490. .interrupt_clear = pm3393_interrupt_clear,
  491. .interrupt_handler = pm3393_interrupt_handler,
  492. .enable = pm3393_enable_port,
  493. .disable = pm3393_disable,
  494. .loopback_enable = pm3393_loopback_enable,
  495. .loopback_disable = pm3393_loopback_disable,
  496. .set_mtu = pm3393_set_mtu,
  497. .set_rx_mode = pm3393_set_rx_mode,
  498. .get_speed_duplex_fc = pm3393_get_speed_duplex_fc,
  499. .set_speed_duplex_fc = pm3393_set_speed_duplex_fc,
  500. .statistics_update = pm3393_update_statistics,
  501. .macaddress_get = pm3393_macaddress_get,
  502. .macaddress_set = pm3393_macaddress_set
  503. };
  504. static struct cmac *pm3393_mac_create(adapter_t *adapter, int index)
  505. {
  506. struct cmac *cmac;
  507. cmac = kzalloc(sizeof(*cmac) + sizeof(cmac_instance), GFP_KERNEL);
  508. if (!cmac)
  509. return NULL;
  510. cmac->ops = &pm3393_ops;
  511. cmac->instance = (cmac_instance *) (cmac + 1);
  512. cmac->adapter = adapter;
  513. cmac->instance->fc = PAUSE_TX | PAUSE_RX;
  514. t1_tpi_write(adapter, OFFSET(0x0001), 0x00008000);
  515. t1_tpi_write(adapter, OFFSET(0x0001), 0x00000000);
  516. t1_tpi_write(adapter, OFFSET(0x2308), 0x00009800);
  517. t1_tpi_write(adapter, OFFSET(0x2305), 0x00001001); /* PL4IO Enable */
  518. t1_tpi_write(adapter, OFFSET(0x2320), 0x00008800);
  519. t1_tpi_write(adapter, OFFSET(0x2321), 0x00008800);
  520. t1_tpi_write(adapter, OFFSET(0x2322), 0x00008800);
  521. t1_tpi_write(adapter, OFFSET(0x2323), 0x00008800);
  522. t1_tpi_write(adapter, OFFSET(0x2324), 0x00008800);
  523. t1_tpi_write(adapter, OFFSET(0x2325), 0x00008800);
  524. t1_tpi_write(adapter, OFFSET(0x2326), 0x00008800);
  525. t1_tpi_write(adapter, OFFSET(0x2327), 0x00008800);
  526. t1_tpi_write(adapter, OFFSET(0x2328), 0x00008800);
  527. t1_tpi_write(adapter, OFFSET(0x2329), 0x00008800);
  528. t1_tpi_write(adapter, OFFSET(0x232a), 0x00008800);
  529. t1_tpi_write(adapter, OFFSET(0x232b), 0x00008800);
  530. t1_tpi_write(adapter, OFFSET(0x232c), 0x00008800);
  531. t1_tpi_write(adapter, OFFSET(0x232d), 0x00008800);
  532. t1_tpi_write(adapter, OFFSET(0x232e), 0x00008800);
  533. t1_tpi_write(adapter, OFFSET(0x232f), 0x00008800);
  534. t1_tpi_write(adapter, OFFSET(0x230d), 0x00009c00);
  535. t1_tpi_write(adapter, OFFSET(0x2304), 0x00000202); /* PL4IO Calendar Repetitions */
  536. t1_tpi_write(adapter, OFFSET(0x3200), 0x00008080); /* EFLX Enable */
  537. t1_tpi_write(adapter, OFFSET(0x3210), 0x00000000); /* EFLX Channel Deprovision */
  538. t1_tpi_write(adapter, OFFSET(0x3203), 0x00000000); /* EFLX Low Limit */
  539. t1_tpi_write(adapter, OFFSET(0x3204), 0x00000040); /* EFLX High Limit */
  540. t1_tpi_write(adapter, OFFSET(0x3205), 0x000002cc); /* EFLX Almost Full */
  541. t1_tpi_write(adapter, OFFSET(0x3206), 0x00000199); /* EFLX Almost Empty */
  542. t1_tpi_write(adapter, OFFSET(0x3207), 0x00000240); /* EFLX Cut Through Threshold */
  543. t1_tpi_write(adapter, OFFSET(0x3202), 0x00000000); /* EFLX Indirect Register Update */
  544. t1_tpi_write(adapter, OFFSET(0x3210), 0x00000001); /* EFLX Channel Provision */
  545. t1_tpi_write(adapter, OFFSET(0x3208), 0x0000ffff); /* EFLX Undocumented */
  546. t1_tpi_write(adapter, OFFSET(0x320a), 0x0000ffff); /* EFLX Undocumented */
  547. t1_tpi_write(adapter, OFFSET(0x320c), 0x0000ffff); /* EFLX enable overflow interrupt The other bit are undocumented */
  548. t1_tpi_write(adapter, OFFSET(0x320e), 0x0000ffff); /* EFLX Undocumented */
  549. t1_tpi_write(adapter, OFFSET(0x2200), 0x0000c000); /* IFLX Configuration - enable */
  550. t1_tpi_write(adapter, OFFSET(0x2201), 0x00000000); /* IFLX Channel Deprovision */
  551. t1_tpi_write(adapter, OFFSET(0x220e), 0x00000000); /* IFLX Low Limit */
  552. t1_tpi_write(adapter, OFFSET(0x220f), 0x00000100); /* IFLX High Limit */
  553. t1_tpi_write(adapter, OFFSET(0x2210), 0x00000c00); /* IFLX Almost Full Limit */
  554. t1_tpi_write(adapter, OFFSET(0x2211), 0x00000599); /* IFLX Almost Empty Limit */
  555. t1_tpi_write(adapter, OFFSET(0x220d), 0x00000000); /* IFLX Indirect Register Update */
  556. t1_tpi_write(adapter, OFFSET(0x2201), 0x00000001); /* IFLX Channel Provision */
  557. t1_tpi_write(adapter, OFFSET(0x2203), 0x0000ffff); /* IFLX Undocumented */
  558. t1_tpi_write(adapter, OFFSET(0x2205), 0x0000ffff); /* IFLX Undocumented */
  559. t1_tpi_write(adapter, OFFSET(0x2209), 0x0000ffff); /* IFLX Enable overflow interrupt. The other bit are undocumented */
  560. t1_tpi_write(adapter, OFFSET(0x2241), 0xfffffffe); /* PL4MOS Undocumented */
  561. t1_tpi_write(adapter, OFFSET(0x2242), 0x0000ffff); /* PL4MOS Undocumented */
  562. t1_tpi_write(adapter, OFFSET(0x2243), 0x00000008); /* PL4MOS Starving Burst Size */
  563. t1_tpi_write(adapter, OFFSET(0x2244), 0x00000008); /* PL4MOS Hungry Burst Size */
  564. t1_tpi_write(adapter, OFFSET(0x2245), 0x00000008); /* PL4MOS Transfer Size */
  565. t1_tpi_write(adapter, OFFSET(0x2240), 0x00000005); /* PL4MOS Disable */
  566. t1_tpi_write(adapter, OFFSET(0x2280), 0x00002103); /* PL4ODP Training Repeat and SOP rule */
  567. t1_tpi_write(adapter, OFFSET(0x2284), 0x00000000); /* PL4ODP MAX_T setting */
  568. t1_tpi_write(adapter, OFFSET(0x3280), 0x00000087); /* PL4IDU Enable data forward, port state machine. Set ALLOW_NON_ZERO_OLB */
  569. t1_tpi_write(adapter, OFFSET(0x3282), 0x0000001f); /* PL4IDU Enable Dip4 check error interrupts */
  570. t1_tpi_write(adapter, OFFSET(0x3040), 0x0c32); /* # TXXG Config */
  571. /* For T1 use timer based Mac flow control. */
  572. t1_tpi_write(adapter, OFFSET(0x304d), 0x8000);
  573. t1_tpi_write(adapter, OFFSET(0x2040), 0x059c); /* # RXXG Config */
  574. t1_tpi_write(adapter, OFFSET(0x2049), 0x0001); /* # RXXG Cut Through */
  575. t1_tpi_write(adapter, OFFSET(0x2070), 0x0000); /* # Disable promiscuous mode */
  576. /* Setup Exact Match Filter 0 to allow broadcast packets.
  577. */
  578. t1_tpi_write(adapter, OFFSET(0x206e), 0x0000); /* # Disable Match Enable bit */
  579. t1_tpi_write(adapter, OFFSET(0x204a), 0xffff); /* # low addr */
  580. t1_tpi_write(adapter, OFFSET(0x204b), 0xffff); /* # mid addr */
  581. t1_tpi_write(adapter, OFFSET(0x204c), 0xffff); /* # high addr */
  582. t1_tpi_write(adapter, OFFSET(0x206e), 0x0009); /* # Enable Match Enable bit */
  583. t1_tpi_write(adapter, OFFSET(0x0003), 0x0000); /* # NO SOP/ PAD_EN setup */
  584. t1_tpi_write(adapter, OFFSET(0x0100), 0x0ff0); /* # RXEQB disabled */
  585. t1_tpi_write(adapter, OFFSET(0x0101), 0x0f0f); /* # No Preemphasis */
  586. return cmac;
  587. }
  588. static int pm3393_mac_reset(adapter_t * adapter)
  589. {
  590. u32 val;
  591. u32 x;
  592. u32 is_pl4_reset_finished;
  593. u32 is_pl4_outof_lock;
  594. u32 is_xaui_mabc_pll_locked;
  595. u32 successful_reset;
  596. int i;
  597. /* The following steps are required to properly reset
  598. * the PM3393. This information is provided in the
  599. * PM3393 datasheet (Issue 2: November 2002)
  600. * section 13.1 -- Device Reset.
  601. *
  602. * The PM3393 has three types of components that are
  603. * individually reset:
  604. *
  605. * DRESETB - Digital circuitry
  606. * PL4_ARESETB - PL4 analog circuitry
  607. * XAUI_ARESETB - XAUI bus analog circuitry
  608. *
  609. * Steps to reset PM3393 using RSTB pin:
  610. *
  611. * 1. Assert RSTB pin low ( write 0 )
  612. * 2. Wait at least 1ms to initiate a complete initialization of device.
  613. * 3. Wait until all external clocks and REFSEL are stable.
  614. * 4. Wait minimum of 1ms. (after external clocks and REFEL are stable)
  615. * 5. De-assert RSTB ( write 1 )
  616. * 6. Wait until internal timers to expires after ~14ms.
  617. * - Allows analog clock synthesizer(PL4CSU) to stabilize to
  618. * selected reference frequency before allowing the digital
  619. * portion of the device to operate.
  620. * 7. Wait at least 200us for XAUI interface to stabilize.
  621. * 8. Verify the PM3393 came out of reset successfully.
  622. * Set successful reset flag if everything worked else try again
  623. * a few more times.
  624. */
  625. successful_reset = 0;
  626. for (i = 0; i < 3 && !successful_reset; i++) {
  627. /* 1 */
  628. t1_tpi_read(adapter, A_ELMER0_GPO, &val);
  629. val &= ~1;
  630. t1_tpi_write(adapter, A_ELMER0_GPO, val);
  631. /* 2 */
  632. msleep(1);
  633. /* 3 */
  634. msleep(1);
  635. /* 4 */
  636. msleep(2 /*1 extra ms for safety */ );
  637. /* 5 */
  638. val |= 1;
  639. t1_tpi_write(adapter, A_ELMER0_GPO, val);
  640. /* 6 */
  641. msleep(15 /*1 extra ms for safety */ );
  642. /* 7 */
  643. msleep(1);
  644. /* 8 */
  645. /* Has PL4 analog block come out of reset correctly? */
  646. t1_tpi_read(adapter, OFFSET(SUNI1x10GEXP_REG_DEVICE_STATUS), &val);
  647. is_pl4_reset_finished = (val & SUNI1x10GEXP_BITMSK_TOP_EXPIRED);
  648. /* TBD XXX SUNI1x10GEXP_BITMSK_TOP_PL4_IS_DOOL gets locked later in the init sequence
  649. * figure out why? */
  650. /* Have all PL4 block clocks locked? */
  651. x = (SUNI1x10GEXP_BITMSK_TOP_PL4_ID_DOOL
  652. /*| SUNI1x10GEXP_BITMSK_TOP_PL4_IS_DOOL */ |
  653. SUNI1x10GEXP_BITMSK_TOP_PL4_ID_ROOL |
  654. SUNI1x10GEXP_BITMSK_TOP_PL4_IS_ROOL |
  655. SUNI1x10GEXP_BITMSK_TOP_PL4_OUT_ROOL);
  656. is_pl4_outof_lock = (val & x);
  657. /* ??? If this fails, might be able to software reset the XAUI part
  658. * and try to recover... thus saving us from doing another HW reset */
  659. /* Has the XAUI MABC PLL circuitry stablized? */
  660. is_xaui_mabc_pll_locked =
  661. (val & SUNI1x10GEXP_BITMSK_TOP_SXRA_EXPIRED);
  662. successful_reset = (is_pl4_reset_finished && !is_pl4_outof_lock
  663. && is_xaui_mabc_pll_locked);
  664. if (netif_msg_hw(adapter))
  665. dev_dbg(&adapter->pdev->dev,
  666. "PM3393 HW reset %d: pl4_reset 0x%x, val 0x%x, "
  667. "is_pl4_outof_lock 0x%x, xaui_locked 0x%x\n",
  668. i, is_pl4_reset_finished, val,
  669. is_pl4_outof_lock, is_xaui_mabc_pll_locked);
  670. }
  671. return successful_reset ? 0 : 1;
  672. }
  673. const struct gmac t1_pm3393_ops = {
  674. .stats_update_period = STATS_TICK_SECS,
  675. .create = pm3393_mac_create,
  676. .reset = pm3393_mac_reset,
  677. };