pm3393.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814
  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, write to the Free Software Foundation, Inc., *
  16. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
  17. * *
  18. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED *
  19. * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF *
  20. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. *
  21. * *
  22. * http://www.chelsio.com *
  23. * *
  24. * Copyright (c) 2003 - 2005 Chelsio Communications, Inc. *
  25. * All rights reserved. *
  26. * *
  27. * Maintainers: maintainers@chelsio.com *
  28. * *
  29. * Authors: Dimitrios Michailidis <dm@chelsio.com> *
  30. * Tina Yang <tainay@chelsio.com> *
  31. * Felix Marti <felix@chelsio.com> *
  32. * Scott Bardone <sbardone@chelsio.com> *
  33. * Kurt Ottaway <kottaway@chelsio.com> *
  34. * Frank DiMambro <frank@chelsio.com> *
  35. * *
  36. * History: *
  37. * *
  38. ****************************************************************************/
  39. #include "common.h"
  40. #include "regs.h"
  41. #include "gmac.h"
  42. #include "elmer0.h"
  43. #include "suni1x10gexp_regs.h"
  44. #include <linux/crc32.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. CH_DBG(cmac->adapter, INTR, "PM3393 intr cause 0x%x\n",
  223. master_intr_status);
  224. /* TBD XXX Lets just clear everything for now */
  225. pm3393_interrupt_clear(cmac);
  226. return 0;
  227. }
  228. static int pm3393_enable(struct cmac *cmac, int which)
  229. {
  230. if (which & MAC_DIRECTION_RX)
  231. pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_CONFIG_1,
  232. (RXXG_CONF1_VAL | SUNI1x10GEXP_BITMSK_RXXG_RXEN));
  233. if (which & MAC_DIRECTION_TX) {
  234. u32 val = TXXG_CONF1_VAL | SUNI1x10GEXP_BITMSK_TXXG_TXEN0;
  235. if (cmac->instance->fc & PAUSE_RX)
  236. val |= SUNI1x10GEXP_BITMSK_TXXG_FCRX;
  237. if (cmac->instance->fc & PAUSE_TX)
  238. val |= SUNI1x10GEXP_BITMSK_TXXG_FCTX;
  239. pmwrite(cmac, SUNI1x10GEXP_REG_TXXG_CONFIG_1, val);
  240. }
  241. cmac->instance->enabled |= which;
  242. return 0;
  243. }
  244. static int pm3393_enable_port(struct cmac *cmac, int which)
  245. {
  246. /* Clear port statistics */
  247. pmwrite(cmac, SUNI1x10GEXP_REG_MSTAT_CONTROL,
  248. SUNI1x10GEXP_BITMSK_MSTAT_CLEAR);
  249. udelay(2);
  250. memset(&cmac->stats, 0, sizeof(struct cmac_statistics));
  251. pm3393_enable(cmac, which);
  252. /*
  253. * XXX This should be done by the PHY and preferrably not at all.
  254. * The PHY doesn't give us link status indication on its own so have
  255. * the link management code query it instead.
  256. */
  257. t1_link_changed(cmac->adapter, 0);
  258. return 0;
  259. }
  260. static int pm3393_disable(struct cmac *cmac, int which)
  261. {
  262. if (which & MAC_DIRECTION_RX)
  263. pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_CONFIG_1, RXXG_CONF1_VAL);
  264. if (which & MAC_DIRECTION_TX)
  265. pmwrite(cmac, SUNI1x10GEXP_REG_TXXG_CONFIG_1, TXXG_CONF1_VAL);
  266. /*
  267. * The disable is graceful. Give the PM3393 time. Can't wait very
  268. * long here, we may be holding locks.
  269. */
  270. udelay(20);
  271. cmac->instance->enabled &= ~which;
  272. return 0;
  273. }
  274. static int pm3393_loopback_enable(struct cmac *cmac)
  275. {
  276. return 0;
  277. }
  278. static int pm3393_loopback_disable(struct cmac *cmac)
  279. {
  280. return 0;
  281. }
  282. static int pm3393_set_mtu(struct cmac *cmac, int mtu)
  283. {
  284. int enabled = cmac->instance->enabled;
  285. /* MAX_FRAME_SIZE includes header + FCS, mtu doesn't */
  286. mtu += 14 + 4;
  287. if (mtu > MAX_FRAME_SIZE)
  288. return -EINVAL;
  289. /* Disable Rx/Tx MAC before configuring it. */
  290. if (enabled)
  291. pm3393_disable(cmac, MAC_DIRECTION_RX | MAC_DIRECTION_TX);
  292. pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_MAX_FRAME_LENGTH, mtu);
  293. pmwrite(cmac, SUNI1x10GEXP_REG_TXXG_MAX_FRAME_SIZE, mtu);
  294. if (enabled)
  295. pm3393_enable(cmac, enabled);
  296. return 0;
  297. }
  298. static int pm3393_set_rx_mode(struct cmac *cmac, struct t1_rx_mode *rm)
  299. {
  300. int enabled = cmac->instance->enabled & MAC_DIRECTION_RX;
  301. u32 rx_mode;
  302. /* Disable MAC RX before reconfiguring it */
  303. if (enabled)
  304. pm3393_disable(cmac, MAC_DIRECTION_RX);
  305. pmread(cmac, SUNI1x10GEXP_REG_RXXG_ADDRESS_FILTER_CONTROL_2, &rx_mode);
  306. rx_mode &= ~(SUNI1x10GEXP_BITMSK_RXXG_PMODE |
  307. SUNI1x10GEXP_BITMSK_RXXG_MHASH_EN);
  308. pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_ADDRESS_FILTER_CONTROL_2,
  309. (u16)rx_mode);
  310. if (t1_rx_mode_promisc(rm)) {
  311. /* Promiscuous mode. */
  312. rx_mode |= SUNI1x10GEXP_BITMSK_RXXG_PMODE;
  313. }
  314. if (t1_rx_mode_allmulti(rm)) {
  315. /* Accept all multicast. */
  316. pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_MULTICAST_HASH_LOW, 0xffff);
  317. pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_MULTICAST_HASH_MIDLOW, 0xffff);
  318. pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_MULTICAST_HASH_MIDHIGH, 0xffff);
  319. pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_MULTICAST_HASH_HIGH, 0xffff);
  320. rx_mode |= SUNI1x10GEXP_BITMSK_RXXG_MHASH_EN;
  321. } else if (t1_rx_mode_mc_cnt(rm)) {
  322. /* Accept one or more multicast(s). */
  323. u8 *addr;
  324. int bit;
  325. u16 mc_filter[4] = { 0, };
  326. while ((addr = t1_get_next_mcaddr(rm))) {
  327. bit = (ether_crc(ETH_ALEN, addr) >> 23) & 0x3f; /* bit[23:28] */
  328. mc_filter[bit >> 4] |= 1 << (bit & 0xf);
  329. }
  330. pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_MULTICAST_HASH_LOW, mc_filter[0]);
  331. pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_MULTICAST_HASH_MIDLOW, mc_filter[1]);
  332. pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_MULTICAST_HASH_MIDHIGH, mc_filter[2]);
  333. pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_MULTICAST_HASH_HIGH, mc_filter[3]);
  334. rx_mode |= SUNI1x10GEXP_BITMSK_RXXG_MHASH_EN;
  335. }
  336. pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_ADDRESS_FILTER_CONTROL_2, (u16)rx_mode);
  337. if (enabled)
  338. pm3393_enable(cmac, MAC_DIRECTION_RX);
  339. return 0;
  340. }
  341. static int pm3393_get_speed_duplex_fc(struct cmac *cmac, int *speed,
  342. int *duplex, int *fc)
  343. {
  344. if (speed)
  345. *speed = SPEED_10000;
  346. if (duplex)
  347. *duplex = DUPLEX_FULL;
  348. if (fc)
  349. *fc = cmac->instance->fc;
  350. return 0;
  351. }
  352. static int pm3393_set_speed_duplex_fc(struct cmac *cmac, int speed, int duplex,
  353. int fc)
  354. {
  355. if (speed >= 0 && speed != SPEED_10000)
  356. return -1;
  357. if (duplex >= 0 && duplex != DUPLEX_FULL)
  358. return -1;
  359. if (fc & ~(PAUSE_TX | PAUSE_RX))
  360. return -1;
  361. if (fc != cmac->instance->fc) {
  362. cmac->instance->fc = (u8) fc;
  363. if (cmac->instance->enabled & MAC_DIRECTION_TX)
  364. pm3393_enable(cmac, MAC_DIRECTION_TX);
  365. }
  366. return 0;
  367. }
  368. static void pm3393_rmon_update(struct adapter *adapter, u32 offs, u64 *val,
  369. int over)
  370. {
  371. u32 val0, val1, val2;
  372. t1_tpi_read(adapter, offs, &val0);
  373. t1_tpi_read(adapter, offs + 4, &val1);
  374. t1_tpi_read(adapter, offs + 8, &val2);
  375. *val &= ~0ull << 40;
  376. *val |= val0 & 0xffff;
  377. *val |= (val1 & 0xffff) << 16;
  378. *val |= (u64)(val2 & 0xff) << 32;
  379. if (over)
  380. *val += 1ull << 40;
  381. }
  382. static const struct cmac_statistics *pm3393_update_statistics(struct cmac *mac,
  383. int flag)
  384. {
  385. static struct {
  386. unsigned int reg;
  387. unsigned int offset;
  388. } hw_stats [] = {
  389. #define HW_STAT(name, stat_name) \
  390. { name, (&((struct cmac_statistics *)NULL)->stat_name) - (u64 *)NULL }
  391. /* Rx stats */
  392. HW_STAT(RxOctetsReceivedOK, RxOctetsOK),
  393. HW_STAT(RxUnicastFramesReceivedOK, RxUnicastFramesOK),
  394. HW_STAT(RxMulticastFramesReceivedOK, RxMulticastFramesOK),
  395. HW_STAT(RxBroadcastFramesReceivedOK, RxBroadcastFramesOK),
  396. HW_STAT(RxPAUSEMACCtrlFramesReceived, RxPauseFrames),
  397. HW_STAT(RxFrameCheckSequenceErrors, RxFCSErrors),
  398. HW_STAT(RxFramesLostDueToInternalMACErrors,
  399. RxInternalMACRcvError),
  400. HW_STAT(RxSymbolErrors, RxSymbolErrors),
  401. HW_STAT(RxInRangeLengthErrors, RxInRangeLengthErrors),
  402. HW_STAT(RxFramesTooLongErrors , RxFrameTooLongErrors),
  403. HW_STAT(RxJabbers, RxJabberErrors),
  404. HW_STAT(RxFragments, RxRuntErrors),
  405. HW_STAT(RxUndersizedFrames, RxRuntErrors),
  406. HW_STAT(RxJumboFramesReceivedOK, RxJumboFramesOK),
  407. HW_STAT(RxJumboOctetsReceivedOK, RxJumboOctetsOK),
  408. /* Tx stats */
  409. HW_STAT(TxOctetsTransmittedOK, TxOctetsOK),
  410. HW_STAT(TxFramesLostDueToInternalMACTransmissionError,
  411. TxInternalMACXmitError),
  412. HW_STAT(TxTransmitSystemError, TxFCSErrors),
  413. HW_STAT(TxUnicastFramesTransmittedOK, TxUnicastFramesOK),
  414. HW_STAT(TxMulticastFramesTransmittedOK, TxMulticastFramesOK),
  415. HW_STAT(TxBroadcastFramesTransmittedOK, TxBroadcastFramesOK),
  416. HW_STAT(TxPAUSEMACCtrlFramesTransmitted, TxPauseFrames),
  417. HW_STAT(TxJumboFramesReceivedOK, TxJumboFramesOK),
  418. HW_STAT(TxJumboOctetsReceivedOK, TxJumboOctetsOK)
  419. }, *p = hw_stats;
  420. u64 ro;
  421. u32 val0, val1, val2, val3;
  422. u64 *stats = (u64 *) &mac->stats;
  423. unsigned int i;
  424. /* Snap the counters */
  425. pmwrite(mac, SUNI1x10GEXP_REG_MSTAT_CONTROL,
  426. SUNI1x10GEXP_BITMSK_MSTAT_SNAP);
  427. /* Counter rollover, clear on read */
  428. pmread(mac, SUNI1x10GEXP_REG_MSTAT_COUNTER_ROLLOVER_0, &val0);
  429. pmread(mac, SUNI1x10GEXP_REG_MSTAT_COUNTER_ROLLOVER_1, &val1);
  430. pmread(mac, SUNI1x10GEXP_REG_MSTAT_COUNTER_ROLLOVER_2, &val2);
  431. pmread(mac, SUNI1x10GEXP_REG_MSTAT_COUNTER_ROLLOVER_3, &val3);
  432. ro = ((u64)val0 & 0xffff) | (((u64)val1 & 0xffff) << 16) |
  433. (((u64)val2 & 0xffff) << 32) | (((u64)val3 & 0xffff) << 48);
  434. for (i = 0; i < ARRAY_SIZE(hw_stats); i++) {
  435. unsigned reg = p->reg - SUNI1x10GEXP_REG_MSTAT_COUNTER_0_LOW;
  436. pm3393_rmon_update((mac)->adapter, OFFSET(p->reg),
  437. stats + p->offset, ro & (reg >> 2));
  438. }
  439. return &mac->stats;
  440. }
  441. static int pm3393_macaddress_get(struct cmac *cmac, u8 mac_addr[6])
  442. {
  443. memcpy(mac_addr, cmac->instance->mac_addr, 6);
  444. return 0;
  445. }
  446. static int pm3393_macaddress_set(struct cmac *cmac, u8 ma[6])
  447. {
  448. u32 val, lo, mid, hi, enabled = cmac->instance->enabled;
  449. /*
  450. * MAC addr: 00:07:43:00:13:09
  451. *
  452. * ma[5] = 0x09
  453. * ma[4] = 0x13
  454. * ma[3] = 0x00
  455. * ma[2] = 0x43
  456. * ma[1] = 0x07
  457. * ma[0] = 0x00
  458. *
  459. * The PM3393 requires byte swapping and reverse order entry
  460. * when programming MAC addresses:
  461. *
  462. * low_bits[15:0] = ma[1]:ma[0]
  463. * mid_bits[31:16] = ma[3]:ma[2]
  464. * high_bits[47:32] = ma[5]:ma[4]
  465. */
  466. /* Store local copy */
  467. memcpy(cmac->instance->mac_addr, ma, 6);
  468. lo = ((u32) ma[1] << 8) | (u32) ma[0];
  469. mid = ((u32) ma[3] << 8) | (u32) ma[2];
  470. hi = ((u32) ma[5] << 8) | (u32) ma[4];
  471. /* Disable Rx/Tx MAC before configuring it. */
  472. if (enabled)
  473. pm3393_disable(cmac, MAC_DIRECTION_RX | MAC_DIRECTION_TX);
  474. /* Set RXXG Station Address */
  475. pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_SA_15_0, lo);
  476. pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_SA_31_16, mid);
  477. pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_SA_47_32, hi);
  478. /* Set TXXG Station Address */
  479. pmwrite(cmac, SUNI1x10GEXP_REG_TXXG_SA_15_0, lo);
  480. pmwrite(cmac, SUNI1x10GEXP_REG_TXXG_SA_31_16, mid);
  481. pmwrite(cmac, SUNI1x10GEXP_REG_TXXG_SA_47_32, hi);
  482. /* Setup Exact Match Filter 1 with our MAC address
  483. *
  484. * Must disable exact match filter before configuring it.
  485. */
  486. pmread(cmac, SUNI1x10GEXP_REG_RXXG_ADDRESS_FILTER_CONTROL_0, &val);
  487. val &= 0xff0f;
  488. pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_ADDRESS_FILTER_CONTROL_0, val);
  489. pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_EXACT_MATCH_ADDR_1_LOW, lo);
  490. pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_EXACT_MATCH_ADDR_1_MID, mid);
  491. pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_EXACT_MATCH_ADDR_1_HIGH, hi);
  492. val |= 0x0090;
  493. pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_ADDRESS_FILTER_CONTROL_0, val);
  494. if (enabled)
  495. pm3393_enable(cmac, enabled);
  496. return 0;
  497. }
  498. static void pm3393_destroy(struct cmac *cmac)
  499. {
  500. kfree(cmac);
  501. }
  502. static struct cmac_ops pm3393_ops = {
  503. .destroy = pm3393_destroy,
  504. .reset = pm3393_reset,
  505. .interrupt_enable = pm3393_interrupt_enable,
  506. .interrupt_disable = pm3393_interrupt_disable,
  507. .interrupt_clear = pm3393_interrupt_clear,
  508. .interrupt_handler = pm3393_interrupt_handler,
  509. .enable = pm3393_enable_port,
  510. .disable = pm3393_disable,
  511. .loopback_enable = pm3393_loopback_enable,
  512. .loopback_disable = pm3393_loopback_disable,
  513. .set_mtu = pm3393_set_mtu,
  514. .set_rx_mode = pm3393_set_rx_mode,
  515. .get_speed_duplex_fc = pm3393_get_speed_duplex_fc,
  516. .set_speed_duplex_fc = pm3393_set_speed_duplex_fc,
  517. .statistics_update = pm3393_update_statistics,
  518. .macaddress_get = pm3393_macaddress_get,
  519. .macaddress_set = pm3393_macaddress_set
  520. };
  521. static struct cmac *pm3393_mac_create(adapter_t *adapter, int index)
  522. {
  523. struct cmac *cmac;
  524. cmac = kzalloc(sizeof(*cmac) + sizeof(cmac_instance), GFP_KERNEL);
  525. if (!cmac)
  526. return NULL;
  527. cmac->ops = &pm3393_ops;
  528. cmac->instance = (cmac_instance *) (cmac + 1);
  529. cmac->adapter = adapter;
  530. cmac->instance->fc = PAUSE_TX | PAUSE_RX;
  531. t1_tpi_write(adapter, OFFSET(0x0001), 0x00008000);
  532. t1_tpi_write(adapter, OFFSET(0x0001), 0x00000000);
  533. t1_tpi_write(adapter, OFFSET(0x2308), 0x00009800);
  534. t1_tpi_write(adapter, OFFSET(0x2305), 0x00001001); /* PL4IO Enable */
  535. t1_tpi_write(adapter, OFFSET(0x2320), 0x00008800);
  536. t1_tpi_write(adapter, OFFSET(0x2321), 0x00008800);
  537. t1_tpi_write(adapter, OFFSET(0x2322), 0x00008800);
  538. t1_tpi_write(adapter, OFFSET(0x2323), 0x00008800);
  539. t1_tpi_write(adapter, OFFSET(0x2324), 0x00008800);
  540. t1_tpi_write(adapter, OFFSET(0x2325), 0x00008800);
  541. t1_tpi_write(adapter, OFFSET(0x2326), 0x00008800);
  542. t1_tpi_write(adapter, OFFSET(0x2327), 0x00008800);
  543. t1_tpi_write(adapter, OFFSET(0x2328), 0x00008800);
  544. t1_tpi_write(adapter, OFFSET(0x2329), 0x00008800);
  545. t1_tpi_write(adapter, OFFSET(0x232a), 0x00008800);
  546. t1_tpi_write(adapter, OFFSET(0x232b), 0x00008800);
  547. t1_tpi_write(adapter, OFFSET(0x232c), 0x00008800);
  548. t1_tpi_write(adapter, OFFSET(0x232d), 0x00008800);
  549. t1_tpi_write(adapter, OFFSET(0x232e), 0x00008800);
  550. t1_tpi_write(adapter, OFFSET(0x232f), 0x00008800);
  551. t1_tpi_write(adapter, OFFSET(0x230d), 0x00009c00);
  552. t1_tpi_write(adapter, OFFSET(0x2304), 0x00000202); /* PL4IO Calendar Repetitions */
  553. t1_tpi_write(adapter, OFFSET(0x3200), 0x00008080); /* EFLX Enable */
  554. t1_tpi_write(adapter, OFFSET(0x3210), 0x00000000); /* EFLX Channel Deprovision */
  555. t1_tpi_write(adapter, OFFSET(0x3203), 0x00000000); /* EFLX Low Limit */
  556. t1_tpi_write(adapter, OFFSET(0x3204), 0x00000040); /* EFLX High Limit */
  557. t1_tpi_write(adapter, OFFSET(0x3205), 0x000002cc); /* EFLX Almost Full */
  558. t1_tpi_write(adapter, OFFSET(0x3206), 0x00000199); /* EFLX Almost Empty */
  559. t1_tpi_write(adapter, OFFSET(0x3207), 0x00000240); /* EFLX Cut Through Threshold */
  560. t1_tpi_write(adapter, OFFSET(0x3202), 0x00000000); /* EFLX Indirect Register Update */
  561. t1_tpi_write(adapter, OFFSET(0x3210), 0x00000001); /* EFLX Channel Provision */
  562. t1_tpi_write(adapter, OFFSET(0x3208), 0x0000ffff); /* EFLX Undocumented */
  563. t1_tpi_write(adapter, OFFSET(0x320a), 0x0000ffff); /* EFLX Undocumented */
  564. t1_tpi_write(adapter, OFFSET(0x320c), 0x0000ffff); /* EFLX enable overflow interrupt The other bit are undocumented */
  565. t1_tpi_write(adapter, OFFSET(0x320e), 0x0000ffff); /* EFLX Undocumented */
  566. t1_tpi_write(adapter, OFFSET(0x2200), 0x0000c000); /* IFLX Configuration - enable */
  567. t1_tpi_write(adapter, OFFSET(0x2201), 0x00000000); /* IFLX Channel Deprovision */
  568. t1_tpi_write(adapter, OFFSET(0x220e), 0x00000000); /* IFLX Low Limit */
  569. t1_tpi_write(adapter, OFFSET(0x220f), 0x00000100); /* IFLX High Limit */
  570. t1_tpi_write(adapter, OFFSET(0x2210), 0x00000c00); /* IFLX Almost Full Limit */
  571. t1_tpi_write(adapter, OFFSET(0x2211), 0x00000599); /* IFLX Almost Empty Limit */
  572. t1_tpi_write(adapter, OFFSET(0x220d), 0x00000000); /* IFLX Indirect Register Update */
  573. t1_tpi_write(adapter, OFFSET(0x2201), 0x00000001); /* IFLX Channel Provision */
  574. t1_tpi_write(adapter, OFFSET(0x2203), 0x0000ffff); /* IFLX Undocumented */
  575. t1_tpi_write(adapter, OFFSET(0x2205), 0x0000ffff); /* IFLX Undocumented */
  576. t1_tpi_write(adapter, OFFSET(0x2209), 0x0000ffff); /* IFLX Enable overflow interrupt. The other bit are undocumented */
  577. t1_tpi_write(adapter, OFFSET(0x2241), 0xfffffffe); /* PL4MOS Undocumented */
  578. t1_tpi_write(adapter, OFFSET(0x2242), 0x0000ffff); /* PL4MOS Undocumented */
  579. t1_tpi_write(adapter, OFFSET(0x2243), 0x00000008); /* PL4MOS Starving Burst Size */
  580. t1_tpi_write(adapter, OFFSET(0x2244), 0x00000008); /* PL4MOS Hungry Burst Size */
  581. t1_tpi_write(adapter, OFFSET(0x2245), 0x00000008); /* PL4MOS Transfer Size */
  582. t1_tpi_write(adapter, OFFSET(0x2240), 0x00000005); /* PL4MOS Disable */
  583. t1_tpi_write(adapter, OFFSET(0x2280), 0x00002103); /* PL4ODP Training Repeat and SOP rule */
  584. t1_tpi_write(adapter, OFFSET(0x2284), 0x00000000); /* PL4ODP MAX_T setting */
  585. t1_tpi_write(adapter, OFFSET(0x3280), 0x00000087); /* PL4IDU Enable data forward, port state machine. Set ALLOW_NON_ZERO_OLB */
  586. t1_tpi_write(adapter, OFFSET(0x3282), 0x0000001f); /* PL4IDU Enable Dip4 check error interrupts */
  587. t1_tpi_write(adapter, OFFSET(0x3040), 0x0c32); /* # TXXG Config */
  588. /* For T1 use timer based Mac flow control. */
  589. t1_tpi_write(adapter, OFFSET(0x304d), 0x8000);
  590. t1_tpi_write(adapter, OFFSET(0x2040), 0x059c); /* # RXXG Config */
  591. t1_tpi_write(adapter, OFFSET(0x2049), 0x0001); /* # RXXG Cut Through */
  592. t1_tpi_write(adapter, OFFSET(0x2070), 0x0000); /* # Disable promiscuous mode */
  593. /* Setup Exact Match Filter 0 to allow broadcast packets.
  594. */
  595. t1_tpi_write(adapter, OFFSET(0x206e), 0x0000); /* # Disable Match Enable bit */
  596. t1_tpi_write(adapter, OFFSET(0x204a), 0xffff); /* # low addr */
  597. t1_tpi_write(adapter, OFFSET(0x204b), 0xffff); /* # mid addr */
  598. t1_tpi_write(adapter, OFFSET(0x204c), 0xffff); /* # high addr */
  599. t1_tpi_write(adapter, OFFSET(0x206e), 0x0009); /* # Enable Match Enable bit */
  600. t1_tpi_write(adapter, OFFSET(0x0003), 0x0000); /* # NO SOP/ PAD_EN setup */
  601. t1_tpi_write(adapter, OFFSET(0x0100), 0x0ff0); /* # RXEQB disabled */
  602. t1_tpi_write(adapter, OFFSET(0x0101), 0x0f0f); /* # No Preemphasis */
  603. return cmac;
  604. }
  605. static int pm3393_mac_reset(adapter_t * adapter)
  606. {
  607. u32 val;
  608. u32 x;
  609. u32 is_pl4_reset_finished;
  610. u32 is_pl4_outof_lock;
  611. u32 is_xaui_mabc_pll_locked;
  612. u32 successful_reset;
  613. int i;
  614. /* The following steps are required to properly reset
  615. * the PM3393. This information is provided in the
  616. * PM3393 datasheet (Issue 2: November 2002)
  617. * section 13.1 -- Device Reset.
  618. *
  619. * The PM3393 has three types of components that are
  620. * individually reset:
  621. *
  622. * DRESETB - Digital circuitry
  623. * PL4_ARESETB - PL4 analog circuitry
  624. * XAUI_ARESETB - XAUI bus analog circuitry
  625. *
  626. * Steps to reset PM3393 using RSTB pin:
  627. *
  628. * 1. Assert RSTB pin low ( write 0 )
  629. * 2. Wait at least 1ms to initiate a complete initialization of device.
  630. * 3. Wait until all external clocks and REFSEL are stable.
  631. * 4. Wait minimum of 1ms. (after external clocks and REFEL are stable)
  632. * 5. De-assert RSTB ( write 1 )
  633. * 6. Wait until internal timers to expires after ~14ms.
  634. * - Allows analog clock synthesizer(PL4CSU) to stabilize to
  635. * selected reference frequency before allowing the digital
  636. * portion of the device to operate.
  637. * 7. Wait at least 200us for XAUI interface to stabilize.
  638. * 8. Verify the PM3393 came out of reset successfully.
  639. * Set successful reset flag if everything worked else try again
  640. * a few more times.
  641. */
  642. successful_reset = 0;
  643. for (i = 0; i < 3 && !successful_reset; i++) {
  644. /* 1 */
  645. t1_tpi_read(adapter, A_ELMER0_GPO, &val);
  646. val &= ~1;
  647. t1_tpi_write(adapter, A_ELMER0_GPO, val);
  648. /* 2 */
  649. msleep(1);
  650. /* 3 */
  651. msleep(1);
  652. /* 4 */
  653. msleep(2 /*1 extra ms for safety */ );
  654. /* 5 */
  655. val |= 1;
  656. t1_tpi_write(adapter, A_ELMER0_GPO, val);
  657. /* 6 */
  658. msleep(15 /*1 extra ms for safety */ );
  659. /* 7 */
  660. msleep(1);
  661. /* 8 */
  662. /* Has PL4 analog block come out of reset correctly? */
  663. t1_tpi_read(adapter, OFFSET(SUNI1x10GEXP_REG_DEVICE_STATUS), &val);
  664. is_pl4_reset_finished = (val & SUNI1x10GEXP_BITMSK_TOP_EXPIRED);
  665. /* TBD XXX SUNI1x10GEXP_BITMSK_TOP_PL4_IS_DOOL gets locked later in the init sequence
  666. * figure out why? */
  667. /* Have all PL4 block clocks locked? */
  668. x = (SUNI1x10GEXP_BITMSK_TOP_PL4_ID_DOOL
  669. /*| SUNI1x10GEXP_BITMSK_TOP_PL4_IS_DOOL */ |
  670. SUNI1x10GEXP_BITMSK_TOP_PL4_ID_ROOL |
  671. SUNI1x10GEXP_BITMSK_TOP_PL4_IS_ROOL |
  672. SUNI1x10GEXP_BITMSK_TOP_PL4_OUT_ROOL);
  673. is_pl4_outof_lock = (val & x);
  674. /* ??? If this fails, might be able to software reset the XAUI part
  675. * and try to recover... thus saving us from doing another HW reset */
  676. /* Has the XAUI MABC PLL circuitry stablized? */
  677. is_xaui_mabc_pll_locked =
  678. (val & SUNI1x10GEXP_BITMSK_TOP_SXRA_EXPIRED);
  679. successful_reset = (is_pl4_reset_finished && !is_pl4_outof_lock
  680. && is_xaui_mabc_pll_locked);
  681. CH_DBG(adapter, HW,
  682. "PM3393 HW reset %d: pl4_reset 0x%x, val 0x%x, "
  683. "is_pl4_outof_lock 0x%x, xaui_locked 0x%x\n",
  684. i, is_pl4_reset_finished, val, is_pl4_outof_lock,
  685. is_xaui_mabc_pll_locked);
  686. }
  687. return successful_reset ? 0 : 1;
  688. }
  689. const struct gmac t1_pm3393_ops = {
  690. .stats_update_period = STATS_TICK_SECS,
  691. .create = pm3393_mac_create,
  692. .reset = pm3393_mac_reset,
  693. };