pm3393.c 30 KB

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