pm3393.c 30 KB

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