subr.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128
  1. /*****************************************************************************
  2. * *
  3. * File: subr.c *
  4. * $Revision: 1.27 $ *
  5. * $Date: 2005/06/22 01:08:36 $ *
  6. * Description: *
  7. * Various subroutines (intr,pio,etc.) used by Chelsio 10G Ethernet driver. *
  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 "elmer0.h"
  40. #include "regs.h"
  41. #include "gmac.h"
  42. #include "cphy.h"
  43. #include "sge.h"
  44. #include "tp.h"
  45. #include "espi.h"
  46. /**
  47. * t1_wait_op_done - wait until an operation is completed
  48. * @adapter: the adapter performing the operation
  49. * @reg: the register to check for completion
  50. * @mask: a single-bit field within @reg that indicates completion
  51. * @polarity: the value of the field when the operation is completed
  52. * @attempts: number of check iterations
  53. * @delay: delay in usecs between iterations
  54. *
  55. * Wait until an operation is completed by checking a bit in a register
  56. * up to @attempts times. Returns %0 if the operation completes and %1
  57. * otherwise.
  58. */
  59. static int t1_wait_op_done(adapter_t *adapter, int reg, u32 mask, int polarity,
  60. int attempts, int delay)
  61. {
  62. while (1) {
  63. u32 val = readl(adapter->regs + reg) & mask;
  64. if (!!val == polarity)
  65. return 0;
  66. if (--attempts == 0)
  67. return 1;
  68. if (delay)
  69. udelay(delay);
  70. }
  71. }
  72. #define TPI_ATTEMPTS 50
  73. /*
  74. * Write a register over the TPI interface (unlocked and locked versions).
  75. */
  76. int __t1_tpi_write(adapter_t *adapter, u32 addr, u32 value)
  77. {
  78. int tpi_busy;
  79. writel(addr, adapter->regs + A_TPI_ADDR);
  80. writel(value, adapter->regs + A_TPI_WR_DATA);
  81. writel(F_TPIWR, adapter->regs + A_TPI_CSR);
  82. tpi_busy = t1_wait_op_done(adapter, A_TPI_CSR, F_TPIRDY, 1,
  83. TPI_ATTEMPTS, 3);
  84. if (tpi_busy)
  85. pr_alert("%s: TPI write to 0x%x failed\n",
  86. adapter->name, addr);
  87. return tpi_busy;
  88. }
  89. int t1_tpi_write(adapter_t *adapter, u32 addr, u32 value)
  90. {
  91. int ret;
  92. spin_lock(&adapter->tpi_lock);
  93. ret = __t1_tpi_write(adapter, addr, value);
  94. spin_unlock(&adapter->tpi_lock);
  95. return ret;
  96. }
  97. /*
  98. * Read a register over the TPI interface (unlocked and locked versions).
  99. */
  100. int __t1_tpi_read(adapter_t *adapter, u32 addr, u32 *valp)
  101. {
  102. int tpi_busy;
  103. writel(addr, adapter->regs + A_TPI_ADDR);
  104. writel(0, adapter->regs + A_TPI_CSR);
  105. tpi_busy = t1_wait_op_done(adapter, A_TPI_CSR, F_TPIRDY, 1,
  106. TPI_ATTEMPTS, 3);
  107. if (tpi_busy)
  108. pr_alert("%s: TPI read from 0x%x failed\n",
  109. adapter->name, addr);
  110. else
  111. *valp = readl(adapter->regs + A_TPI_RD_DATA);
  112. return tpi_busy;
  113. }
  114. int t1_tpi_read(adapter_t *adapter, u32 addr, u32 *valp)
  115. {
  116. int ret;
  117. spin_lock(&adapter->tpi_lock);
  118. ret = __t1_tpi_read(adapter, addr, valp);
  119. spin_unlock(&adapter->tpi_lock);
  120. return ret;
  121. }
  122. /*
  123. * Set a TPI parameter.
  124. */
  125. static void t1_tpi_par(adapter_t *adapter, u32 value)
  126. {
  127. writel(V_TPIPAR(value), adapter->regs + A_TPI_PAR);
  128. }
  129. /*
  130. * Called when a port's link settings change to propagate the new values to the
  131. * associated PHY and MAC. After performing the common tasks it invokes an
  132. * OS-specific handler.
  133. */
  134. void t1_link_changed(adapter_t *adapter, int port_id)
  135. {
  136. int link_ok, speed, duplex, fc;
  137. struct cphy *phy = adapter->port[port_id].phy;
  138. struct link_config *lc = &adapter->port[port_id].link_config;
  139. phy->ops->get_link_status(phy, &link_ok, &speed, &duplex, &fc);
  140. lc->speed = speed < 0 ? SPEED_INVALID : speed;
  141. lc->duplex = duplex < 0 ? DUPLEX_INVALID : duplex;
  142. if (!(lc->requested_fc & PAUSE_AUTONEG))
  143. fc = lc->requested_fc & (PAUSE_RX | PAUSE_TX);
  144. if (link_ok && speed >= 0 && lc->autoneg == AUTONEG_ENABLE) {
  145. /* Set MAC speed, duplex, and flow control to match PHY. */
  146. struct cmac *mac = adapter->port[port_id].mac;
  147. mac->ops->set_speed_duplex_fc(mac, speed, duplex, fc);
  148. lc->fc = (unsigned char)fc;
  149. }
  150. t1_link_negotiated(adapter, port_id, link_ok, speed, duplex, fc);
  151. }
  152. static int t1_pci_intr_handler(adapter_t *adapter)
  153. {
  154. u32 pcix_cause;
  155. pci_read_config_dword(adapter->pdev, A_PCICFG_INTR_CAUSE, &pcix_cause);
  156. if (pcix_cause) {
  157. pci_write_config_dword(adapter->pdev, A_PCICFG_INTR_CAUSE,
  158. pcix_cause);
  159. t1_fatal_err(adapter); /* PCI errors are fatal */
  160. }
  161. return 0;
  162. }
  163. #ifdef CONFIG_CHELSIO_T1_1G
  164. #include "fpga_defs.h"
  165. /*
  166. * PHY interrupt handler for FPGA boards.
  167. */
  168. static int fpga_phy_intr_handler(adapter_t *adapter)
  169. {
  170. int p;
  171. u32 cause = readl(adapter->regs + FPGA_GMAC_ADDR_INTERRUPT_CAUSE);
  172. for_each_port(adapter, p)
  173. if (cause & (1 << p)) {
  174. struct cphy *phy = adapter->port[p].phy;
  175. int phy_cause = phy->ops->interrupt_handler(phy);
  176. if (phy_cause & cphy_cause_link_change)
  177. t1_link_changed(adapter, p);
  178. }
  179. writel(cause, adapter->regs + FPGA_GMAC_ADDR_INTERRUPT_CAUSE);
  180. return 0;
  181. }
  182. /*
  183. * Slow path interrupt handler for FPGAs.
  184. */
  185. static int fpga_slow_intr(adapter_t *adapter)
  186. {
  187. u32 cause = readl(adapter->regs + A_PL_CAUSE);
  188. cause &= ~F_PL_INTR_SGE_DATA;
  189. if (cause & F_PL_INTR_SGE_ERR)
  190. t1_sge_intr_error_handler(adapter->sge);
  191. if (cause & FPGA_PCIX_INTERRUPT_GMAC)
  192. fpga_phy_intr_handler(adapter);
  193. if (cause & FPGA_PCIX_INTERRUPT_TP) {
  194. /*
  195. * FPGA doesn't support MC4 interrupts and it requires
  196. * this odd layer of indirection for MC5.
  197. */
  198. u32 tp_cause = readl(adapter->regs + FPGA_TP_ADDR_INTERRUPT_CAUSE);
  199. /* Clear TP interrupt */
  200. writel(tp_cause, adapter->regs + FPGA_TP_ADDR_INTERRUPT_CAUSE);
  201. }
  202. if (cause & FPGA_PCIX_INTERRUPT_PCIX)
  203. t1_pci_intr_handler(adapter);
  204. /* Clear the interrupts just processed. */
  205. if (cause)
  206. writel(cause, adapter->regs + A_PL_CAUSE);
  207. return cause != 0;
  208. }
  209. #endif
  210. /*
  211. * Wait until Elmer's MI1 interface is ready for new operations.
  212. */
  213. static int mi1_wait_until_ready(adapter_t *adapter, int mi1_reg)
  214. {
  215. int attempts = 100, busy;
  216. do {
  217. u32 val;
  218. __t1_tpi_read(adapter, mi1_reg, &val);
  219. busy = val & F_MI1_OP_BUSY;
  220. if (busy)
  221. udelay(10);
  222. } while (busy && --attempts);
  223. if (busy)
  224. pr_alert("%s: MDIO operation timed out\n", adapter->name);
  225. return busy;
  226. }
  227. /*
  228. * MI1 MDIO initialization.
  229. */
  230. static void mi1_mdio_init(adapter_t *adapter, const struct board_info *bi)
  231. {
  232. u32 clkdiv = bi->clock_elmer0 / (2 * bi->mdio_mdc) - 1;
  233. u32 val = F_MI1_PREAMBLE_ENABLE | V_MI1_MDI_INVERT(bi->mdio_mdiinv) |
  234. V_MI1_MDI_ENABLE(bi->mdio_mdien) | V_MI1_CLK_DIV(clkdiv);
  235. if (!(bi->caps & SUPPORTED_10000baseT_Full))
  236. val |= V_MI1_SOF(1);
  237. t1_tpi_write(adapter, A_ELMER0_PORT0_MI1_CFG, val);
  238. }
  239. #if defined(CONFIG_CHELSIO_T1_1G)
  240. /*
  241. * Elmer MI1 MDIO read/write operations.
  242. */
  243. static int mi1_mdio_read(struct net_device *dev, int phy_addr, int mmd_addr,
  244. u16 reg_addr)
  245. {
  246. struct adapter *adapter = dev->ml_priv;
  247. u32 addr = V_MI1_REG_ADDR(reg_addr) | V_MI1_PHY_ADDR(phy_addr);
  248. unsigned int val;
  249. spin_lock(&adapter->tpi_lock);
  250. __t1_tpi_write(adapter, A_ELMER0_PORT0_MI1_ADDR, addr);
  251. __t1_tpi_write(adapter,
  252. A_ELMER0_PORT0_MI1_OP, MI1_OP_DIRECT_READ);
  253. mi1_wait_until_ready(adapter, A_ELMER0_PORT0_MI1_OP);
  254. __t1_tpi_read(adapter, A_ELMER0_PORT0_MI1_DATA, &val);
  255. spin_unlock(&adapter->tpi_lock);
  256. return val;
  257. }
  258. static int mi1_mdio_write(struct net_device *dev, int phy_addr, int mmd_addr,
  259. u16 reg_addr, u16 val)
  260. {
  261. struct adapter *adapter = dev->ml_priv;
  262. u32 addr = V_MI1_REG_ADDR(reg_addr) | V_MI1_PHY_ADDR(phy_addr);
  263. spin_lock(&adapter->tpi_lock);
  264. __t1_tpi_write(adapter, A_ELMER0_PORT0_MI1_ADDR, addr);
  265. __t1_tpi_write(adapter, A_ELMER0_PORT0_MI1_DATA, val);
  266. __t1_tpi_write(adapter,
  267. A_ELMER0_PORT0_MI1_OP, MI1_OP_DIRECT_WRITE);
  268. mi1_wait_until_ready(adapter, A_ELMER0_PORT0_MI1_OP);
  269. spin_unlock(&adapter->tpi_lock);
  270. return 0;
  271. }
  272. static const struct mdio_ops mi1_mdio_ops = {
  273. .init = mi1_mdio_init,
  274. .read = mi1_mdio_read,
  275. .write = mi1_mdio_write,
  276. .mode_support = MDIO_SUPPORTS_C22
  277. };
  278. #endif
  279. static int mi1_mdio_ext_read(struct net_device *dev, int phy_addr, int mmd_addr,
  280. u16 reg_addr)
  281. {
  282. struct adapter *adapter = dev->ml_priv;
  283. u32 addr = V_MI1_REG_ADDR(mmd_addr) | V_MI1_PHY_ADDR(phy_addr);
  284. unsigned int val;
  285. spin_lock(&adapter->tpi_lock);
  286. /* Write the address we want. */
  287. __t1_tpi_write(adapter, A_ELMER0_PORT0_MI1_ADDR, addr);
  288. __t1_tpi_write(adapter, A_ELMER0_PORT0_MI1_DATA, reg_addr);
  289. __t1_tpi_write(adapter, A_ELMER0_PORT0_MI1_OP,
  290. MI1_OP_INDIRECT_ADDRESS);
  291. mi1_wait_until_ready(adapter, A_ELMER0_PORT0_MI1_OP);
  292. /* Write the operation we want. */
  293. __t1_tpi_write(adapter,
  294. A_ELMER0_PORT0_MI1_OP, MI1_OP_INDIRECT_READ);
  295. mi1_wait_until_ready(adapter, A_ELMER0_PORT0_MI1_OP);
  296. /* Read the data. */
  297. __t1_tpi_read(adapter, A_ELMER0_PORT0_MI1_DATA, &val);
  298. spin_unlock(&adapter->tpi_lock);
  299. return val;
  300. }
  301. static int mi1_mdio_ext_write(struct net_device *dev, int phy_addr,
  302. int mmd_addr, u16 reg_addr, u16 val)
  303. {
  304. struct adapter *adapter = dev->ml_priv;
  305. u32 addr = V_MI1_REG_ADDR(mmd_addr) | V_MI1_PHY_ADDR(phy_addr);
  306. spin_lock(&adapter->tpi_lock);
  307. /* Write the address we want. */
  308. __t1_tpi_write(adapter, A_ELMER0_PORT0_MI1_ADDR, addr);
  309. __t1_tpi_write(adapter, A_ELMER0_PORT0_MI1_DATA, reg_addr);
  310. __t1_tpi_write(adapter, A_ELMER0_PORT0_MI1_OP,
  311. MI1_OP_INDIRECT_ADDRESS);
  312. mi1_wait_until_ready(adapter, A_ELMER0_PORT0_MI1_OP);
  313. /* Write the data. */
  314. __t1_tpi_write(adapter, A_ELMER0_PORT0_MI1_DATA, val);
  315. __t1_tpi_write(adapter, A_ELMER0_PORT0_MI1_OP, MI1_OP_INDIRECT_WRITE);
  316. mi1_wait_until_ready(adapter, A_ELMER0_PORT0_MI1_OP);
  317. spin_unlock(&adapter->tpi_lock);
  318. return 0;
  319. }
  320. static const struct mdio_ops mi1_mdio_ext_ops = {
  321. .init = mi1_mdio_init,
  322. .read = mi1_mdio_ext_read,
  323. .write = mi1_mdio_ext_write,
  324. .mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22
  325. };
  326. enum {
  327. CH_BRD_T110_1CU,
  328. CH_BRD_N110_1F,
  329. CH_BRD_N210_1F,
  330. CH_BRD_T210_1F,
  331. CH_BRD_T210_1CU,
  332. CH_BRD_N204_4CU,
  333. };
  334. static const struct board_info t1_board[] = {
  335. {
  336. .board = CHBT_BOARD_CHT110,
  337. .port_number = 1,
  338. .caps = SUPPORTED_10000baseT_Full,
  339. .chip_term = CHBT_TERM_T1,
  340. .chip_mac = CHBT_MAC_PM3393,
  341. .chip_phy = CHBT_PHY_MY3126,
  342. .clock_core = 125000000,
  343. .clock_mc3 = 150000000,
  344. .clock_mc4 = 125000000,
  345. .espi_nports = 1,
  346. .clock_elmer0 = 44,
  347. .mdio_mdien = 1,
  348. .mdio_mdiinv = 1,
  349. .mdio_mdc = 1,
  350. .mdio_phybaseaddr = 1,
  351. .gmac = &t1_pm3393_ops,
  352. .gphy = &t1_my3126_ops,
  353. .mdio_ops = &mi1_mdio_ext_ops,
  354. .desc = "Chelsio T110 1x10GBase-CX4 TOE",
  355. },
  356. {
  357. .board = CHBT_BOARD_N110,
  358. .port_number = 1,
  359. .caps = SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE,
  360. .chip_term = CHBT_TERM_T1,
  361. .chip_mac = CHBT_MAC_PM3393,
  362. .chip_phy = CHBT_PHY_88X2010,
  363. .clock_core = 125000000,
  364. .espi_nports = 1,
  365. .clock_elmer0 = 44,
  366. .mdio_mdien = 0,
  367. .mdio_mdiinv = 0,
  368. .mdio_mdc = 1,
  369. .mdio_phybaseaddr = 0,
  370. .gmac = &t1_pm3393_ops,
  371. .gphy = &t1_mv88x201x_ops,
  372. .mdio_ops = &mi1_mdio_ext_ops,
  373. .desc = "Chelsio N110 1x10GBaseX NIC",
  374. },
  375. {
  376. .board = CHBT_BOARD_N210,
  377. .port_number = 1,
  378. .caps = SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE,
  379. .chip_term = CHBT_TERM_T2,
  380. .chip_mac = CHBT_MAC_PM3393,
  381. .chip_phy = CHBT_PHY_88X2010,
  382. .clock_core = 125000000,
  383. .espi_nports = 1,
  384. .clock_elmer0 = 44,
  385. .mdio_mdien = 0,
  386. .mdio_mdiinv = 0,
  387. .mdio_mdc = 1,
  388. .mdio_phybaseaddr = 0,
  389. .gmac = &t1_pm3393_ops,
  390. .gphy = &t1_mv88x201x_ops,
  391. .mdio_ops = &mi1_mdio_ext_ops,
  392. .desc = "Chelsio N210 1x10GBaseX NIC",
  393. },
  394. {
  395. .board = CHBT_BOARD_CHT210,
  396. .port_number = 1,
  397. .caps = SUPPORTED_10000baseT_Full,
  398. .chip_term = CHBT_TERM_T2,
  399. .chip_mac = CHBT_MAC_PM3393,
  400. .chip_phy = CHBT_PHY_88X2010,
  401. .clock_core = 125000000,
  402. .clock_mc3 = 133000000,
  403. .clock_mc4 = 125000000,
  404. .espi_nports = 1,
  405. .clock_elmer0 = 44,
  406. .mdio_mdien = 0,
  407. .mdio_mdiinv = 0,
  408. .mdio_mdc = 1,
  409. .mdio_phybaseaddr = 0,
  410. .gmac = &t1_pm3393_ops,
  411. .gphy = &t1_mv88x201x_ops,
  412. .mdio_ops = &mi1_mdio_ext_ops,
  413. .desc = "Chelsio T210 1x10GBaseX TOE",
  414. },
  415. {
  416. .board = CHBT_BOARD_CHT210,
  417. .port_number = 1,
  418. .caps = SUPPORTED_10000baseT_Full,
  419. .chip_term = CHBT_TERM_T2,
  420. .chip_mac = CHBT_MAC_PM3393,
  421. .chip_phy = CHBT_PHY_MY3126,
  422. .clock_core = 125000000,
  423. .clock_mc3 = 133000000,
  424. .clock_mc4 = 125000000,
  425. .espi_nports = 1,
  426. .clock_elmer0 = 44,
  427. .mdio_mdien = 1,
  428. .mdio_mdiinv = 1,
  429. .mdio_mdc = 1,
  430. .mdio_phybaseaddr = 1,
  431. .gmac = &t1_pm3393_ops,
  432. .gphy = &t1_my3126_ops,
  433. .mdio_ops = &mi1_mdio_ext_ops,
  434. .desc = "Chelsio T210 1x10GBase-CX4 TOE",
  435. },
  436. #ifdef CONFIG_CHELSIO_T1_1G
  437. {
  438. .board = CHBT_BOARD_CHN204,
  439. .port_number = 4,
  440. .caps = SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full
  441. | SUPPORTED_100baseT_Half | SUPPORTED_100baseT_Full
  442. | SUPPORTED_1000baseT_Full | SUPPORTED_Autoneg |
  443. SUPPORTED_PAUSE | SUPPORTED_TP,
  444. .chip_term = CHBT_TERM_T2,
  445. .chip_mac = CHBT_MAC_VSC7321,
  446. .chip_phy = CHBT_PHY_88E1111,
  447. .clock_core = 100000000,
  448. .espi_nports = 4,
  449. .clock_elmer0 = 44,
  450. .mdio_mdien = 0,
  451. .mdio_mdiinv = 0,
  452. .mdio_mdc = 0,
  453. .mdio_phybaseaddr = 4,
  454. .gmac = &t1_vsc7326_ops,
  455. .gphy = &t1_mv88e1xxx_ops,
  456. .mdio_ops = &mi1_mdio_ops,
  457. .desc = "Chelsio N204 4x100/1000BaseT NIC",
  458. },
  459. #endif
  460. };
  461. const struct pci_device_id t1_pci_tbl[] = {
  462. CH_DEVICE(8, 0, CH_BRD_T110_1CU),
  463. CH_DEVICE(8, 1, CH_BRD_T110_1CU),
  464. CH_DEVICE(7, 0, CH_BRD_N110_1F),
  465. CH_DEVICE(10, 1, CH_BRD_N210_1F),
  466. CH_DEVICE(11, 1, CH_BRD_T210_1F),
  467. CH_DEVICE(14, 1, CH_BRD_T210_1CU),
  468. CH_DEVICE(16, 1, CH_BRD_N204_4CU),
  469. { 0 }
  470. };
  471. MODULE_DEVICE_TABLE(pci, t1_pci_tbl);
  472. /*
  473. * Return the board_info structure with a given index. Out-of-range indices
  474. * return NULL.
  475. */
  476. const struct board_info *t1_get_board_info(unsigned int board_id)
  477. {
  478. return board_id < ARRAY_SIZE(t1_board) ? &t1_board[board_id] : NULL;
  479. }
  480. struct chelsio_vpd_t {
  481. u32 format_version;
  482. u8 serial_number[16];
  483. u8 mac_base_address[6];
  484. u8 pad[2]; /* make multiple-of-4 size requirement explicit */
  485. };
  486. #define EEPROMSIZE (8 * 1024)
  487. #define EEPROM_MAX_POLL 4
  488. /*
  489. * Read SEEPROM. A zero is written to the flag register when the address is
  490. * written to the Control register. The hardware device will set the flag to a
  491. * one when 4B have been transferred to the Data register.
  492. */
  493. int t1_seeprom_read(adapter_t *adapter, u32 addr, __le32 *data)
  494. {
  495. int i = EEPROM_MAX_POLL;
  496. u16 val;
  497. u32 v;
  498. if (addr >= EEPROMSIZE || (addr & 3))
  499. return -EINVAL;
  500. pci_write_config_word(adapter->pdev, A_PCICFG_VPD_ADDR, (u16)addr);
  501. do {
  502. udelay(50);
  503. pci_read_config_word(adapter->pdev, A_PCICFG_VPD_ADDR, &val);
  504. } while (!(val & F_VPD_OP_FLAG) && --i);
  505. if (!(val & F_VPD_OP_FLAG)) {
  506. pr_err("%s: reading EEPROM address 0x%x failed\n",
  507. adapter->name, addr);
  508. return -EIO;
  509. }
  510. pci_read_config_dword(adapter->pdev, A_PCICFG_VPD_DATA, &v);
  511. *data = cpu_to_le32(v);
  512. return 0;
  513. }
  514. static int t1_eeprom_vpd_get(adapter_t *adapter, struct chelsio_vpd_t *vpd)
  515. {
  516. int addr, ret = 0;
  517. for (addr = 0; !ret && addr < sizeof(*vpd); addr += sizeof(u32))
  518. ret = t1_seeprom_read(adapter, addr,
  519. (__le32 *)((u8 *)vpd + addr));
  520. return ret;
  521. }
  522. /*
  523. * Read a port's MAC address from the VPD ROM.
  524. */
  525. static int vpd_macaddress_get(adapter_t *adapter, int index, u8 mac_addr[])
  526. {
  527. struct chelsio_vpd_t vpd;
  528. if (t1_eeprom_vpd_get(adapter, &vpd))
  529. return 1;
  530. memcpy(mac_addr, vpd.mac_base_address, 5);
  531. mac_addr[5] = vpd.mac_base_address[5] + index;
  532. return 0;
  533. }
  534. /*
  535. * Set up the MAC/PHY according to the requested link settings.
  536. *
  537. * If the PHY can auto-negotiate first decide what to advertise, then
  538. * enable/disable auto-negotiation as desired and reset.
  539. *
  540. * If the PHY does not auto-negotiate we just reset it.
  541. *
  542. * If auto-negotiation is off set the MAC to the proper speed/duplex/FC,
  543. * otherwise do it later based on the outcome of auto-negotiation.
  544. */
  545. int t1_link_start(struct cphy *phy, struct cmac *mac, struct link_config *lc)
  546. {
  547. unsigned int fc = lc->requested_fc & (PAUSE_RX | PAUSE_TX);
  548. if (lc->supported & SUPPORTED_Autoneg) {
  549. lc->advertising &= ~(ADVERTISED_ASYM_PAUSE | ADVERTISED_PAUSE);
  550. if (fc) {
  551. if (fc == ((PAUSE_RX | PAUSE_TX) &
  552. (mac->adapter->params.nports < 2)))
  553. lc->advertising |= ADVERTISED_PAUSE;
  554. else {
  555. lc->advertising |= ADVERTISED_ASYM_PAUSE;
  556. if (fc == PAUSE_RX)
  557. lc->advertising |= ADVERTISED_PAUSE;
  558. }
  559. }
  560. phy->ops->advertise(phy, lc->advertising);
  561. if (lc->autoneg == AUTONEG_DISABLE) {
  562. lc->speed = lc->requested_speed;
  563. lc->duplex = lc->requested_duplex;
  564. lc->fc = (unsigned char)fc;
  565. mac->ops->set_speed_duplex_fc(mac, lc->speed,
  566. lc->duplex, fc);
  567. /* Also disables autoneg */
  568. phy->state = PHY_AUTONEG_RDY;
  569. phy->ops->set_speed_duplex(phy, lc->speed, lc->duplex);
  570. phy->ops->reset(phy, 0);
  571. } else {
  572. phy->state = PHY_AUTONEG_EN;
  573. phy->ops->autoneg_enable(phy); /* also resets PHY */
  574. }
  575. } else {
  576. phy->state = PHY_AUTONEG_RDY;
  577. mac->ops->set_speed_duplex_fc(mac, -1, -1, fc);
  578. lc->fc = (unsigned char)fc;
  579. phy->ops->reset(phy, 0);
  580. }
  581. return 0;
  582. }
  583. /*
  584. * External interrupt handler for boards using elmer0.
  585. */
  586. int t1_elmer0_ext_intr_handler(adapter_t *adapter)
  587. {
  588. struct cphy *phy;
  589. int phy_cause;
  590. u32 cause;
  591. t1_tpi_read(adapter, A_ELMER0_INT_CAUSE, &cause);
  592. switch (board_info(adapter)->board) {
  593. #ifdef CONFIG_CHELSIO_T1_1G
  594. case CHBT_BOARD_CHT204:
  595. case CHBT_BOARD_CHT204E:
  596. case CHBT_BOARD_CHN204:
  597. case CHBT_BOARD_CHT204V: {
  598. int i, port_bit;
  599. for_each_port(adapter, i) {
  600. port_bit = i + 1;
  601. if (!(cause & (1 << port_bit)))
  602. continue;
  603. phy = adapter->port[i].phy;
  604. phy_cause = phy->ops->interrupt_handler(phy);
  605. if (phy_cause & cphy_cause_link_change)
  606. t1_link_changed(adapter, i);
  607. }
  608. break;
  609. }
  610. case CHBT_BOARD_CHT101:
  611. if (cause & ELMER0_GP_BIT1) { /* Marvell 88E1111 interrupt */
  612. phy = adapter->port[0].phy;
  613. phy_cause = phy->ops->interrupt_handler(phy);
  614. if (phy_cause & cphy_cause_link_change)
  615. t1_link_changed(adapter, 0);
  616. }
  617. break;
  618. case CHBT_BOARD_7500: {
  619. int p;
  620. /*
  621. * Elmer0's interrupt cause isn't useful here because there is
  622. * only one bit that can be set for all 4 ports. This means
  623. * we are forced to check every PHY's interrupt status
  624. * register to see who initiated the interrupt.
  625. */
  626. for_each_port(adapter, p) {
  627. phy = adapter->port[p].phy;
  628. phy_cause = phy->ops->interrupt_handler(phy);
  629. if (phy_cause & cphy_cause_link_change)
  630. t1_link_changed(adapter, p);
  631. }
  632. break;
  633. }
  634. #endif
  635. case CHBT_BOARD_CHT210:
  636. case CHBT_BOARD_N210:
  637. case CHBT_BOARD_N110:
  638. if (cause & ELMER0_GP_BIT6) { /* Marvell 88x2010 interrupt */
  639. phy = adapter->port[0].phy;
  640. phy_cause = phy->ops->interrupt_handler(phy);
  641. if (phy_cause & cphy_cause_link_change)
  642. t1_link_changed(adapter, 0);
  643. }
  644. break;
  645. case CHBT_BOARD_8000:
  646. case CHBT_BOARD_CHT110:
  647. if (netif_msg_intr(adapter))
  648. dev_dbg(&adapter->pdev->dev,
  649. "External interrupt cause 0x%x\n", cause);
  650. if (cause & ELMER0_GP_BIT1) { /* PMC3393 INTB */
  651. struct cmac *mac = adapter->port[0].mac;
  652. mac->ops->interrupt_handler(mac);
  653. }
  654. if (cause & ELMER0_GP_BIT5) { /* XPAK MOD_DETECT */
  655. u32 mod_detect;
  656. t1_tpi_read(adapter,
  657. A_ELMER0_GPI_STAT, &mod_detect);
  658. if (netif_msg_link(adapter))
  659. dev_info(&adapter->pdev->dev, "XPAK %s\n",
  660. mod_detect ? "removed" : "inserted");
  661. }
  662. break;
  663. }
  664. t1_tpi_write(adapter, A_ELMER0_INT_CAUSE, cause);
  665. return 0;
  666. }
  667. /* Enables all interrupts. */
  668. void t1_interrupts_enable(adapter_t *adapter)
  669. {
  670. unsigned int i;
  671. adapter->slow_intr_mask = F_PL_INTR_SGE_ERR | F_PL_INTR_TP;
  672. t1_sge_intr_enable(adapter->sge);
  673. t1_tp_intr_enable(adapter->tp);
  674. if (adapter->espi) {
  675. adapter->slow_intr_mask |= F_PL_INTR_ESPI;
  676. t1_espi_intr_enable(adapter->espi);
  677. }
  678. /* Enable MAC/PHY interrupts for each port. */
  679. for_each_port(adapter, i) {
  680. adapter->port[i].mac->ops->interrupt_enable(adapter->port[i].mac);
  681. adapter->port[i].phy->ops->interrupt_enable(adapter->port[i].phy);
  682. }
  683. /* Enable PCIX & external chip interrupts on ASIC boards. */
  684. if (t1_is_asic(adapter)) {
  685. u32 pl_intr = readl(adapter->regs + A_PL_ENABLE);
  686. /* PCI-X interrupts */
  687. pci_write_config_dword(adapter->pdev, A_PCICFG_INTR_ENABLE,
  688. 0xffffffff);
  689. adapter->slow_intr_mask |= F_PL_INTR_EXT | F_PL_INTR_PCIX;
  690. pl_intr |= F_PL_INTR_EXT | F_PL_INTR_PCIX;
  691. writel(pl_intr, adapter->regs + A_PL_ENABLE);
  692. }
  693. }
  694. /* Disables all interrupts. */
  695. void t1_interrupts_disable(adapter_t* adapter)
  696. {
  697. unsigned int i;
  698. t1_sge_intr_disable(adapter->sge);
  699. t1_tp_intr_disable(adapter->tp);
  700. if (adapter->espi)
  701. t1_espi_intr_disable(adapter->espi);
  702. /* Disable MAC/PHY interrupts for each port. */
  703. for_each_port(adapter, i) {
  704. adapter->port[i].mac->ops->interrupt_disable(adapter->port[i].mac);
  705. adapter->port[i].phy->ops->interrupt_disable(adapter->port[i].phy);
  706. }
  707. /* Disable PCIX & external chip interrupts. */
  708. if (t1_is_asic(adapter))
  709. writel(0, adapter->regs + A_PL_ENABLE);
  710. /* PCI-X interrupts */
  711. pci_write_config_dword(adapter->pdev, A_PCICFG_INTR_ENABLE, 0);
  712. adapter->slow_intr_mask = 0;
  713. }
  714. /* Clears all interrupts */
  715. void t1_interrupts_clear(adapter_t* adapter)
  716. {
  717. unsigned int i;
  718. t1_sge_intr_clear(adapter->sge);
  719. t1_tp_intr_clear(adapter->tp);
  720. if (adapter->espi)
  721. t1_espi_intr_clear(adapter->espi);
  722. /* Clear MAC/PHY interrupts for each port. */
  723. for_each_port(adapter, i) {
  724. adapter->port[i].mac->ops->interrupt_clear(adapter->port[i].mac);
  725. adapter->port[i].phy->ops->interrupt_clear(adapter->port[i].phy);
  726. }
  727. /* Enable interrupts for external devices. */
  728. if (t1_is_asic(adapter)) {
  729. u32 pl_intr = readl(adapter->regs + A_PL_CAUSE);
  730. writel(pl_intr | F_PL_INTR_EXT | F_PL_INTR_PCIX,
  731. adapter->regs + A_PL_CAUSE);
  732. }
  733. /* PCI-X interrupts */
  734. pci_write_config_dword(adapter->pdev, A_PCICFG_INTR_CAUSE, 0xffffffff);
  735. }
  736. /*
  737. * Slow path interrupt handler for ASICs.
  738. */
  739. static int asic_slow_intr(adapter_t *adapter)
  740. {
  741. u32 cause = readl(adapter->regs + A_PL_CAUSE);
  742. cause &= adapter->slow_intr_mask;
  743. if (!cause)
  744. return 0;
  745. if (cause & F_PL_INTR_SGE_ERR)
  746. t1_sge_intr_error_handler(adapter->sge);
  747. if (cause & F_PL_INTR_TP)
  748. t1_tp_intr_handler(adapter->tp);
  749. if (cause & F_PL_INTR_ESPI)
  750. t1_espi_intr_handler(adapter->espi);
  751. if (cause & F_PL_INTR_PCIX)
  752. t1_pci_intr_handler(adapter);
  753. if (cause & F_PL_INTR_EXT)
  754. t1_elmer0_ext_intr(adapter);
  755. /* Clear the interrupts just processed. */
  756. writel(cause, adapter->regs + A_PL_CAUSE);
  757. readl(adapter->regs + A_PL_CAUSE); /* flush writes */
  758. return 1;
  759. }
  760. int t1_slow_intr_handler(adapter_t *adapter)
  761. {
  762. #ifdef CONFIG_CHELSIO_T1_1G
  763. if (!t1_is_asic(adapter))
  764. return fpga_slow_intr(adapter);
  765. #endif
  766. return asic_slow_intr(adapter);
  767. }
  768. /* Power sequencing is a work-around for Intel's XPAKs. */
  769. static void power_sequence_xpak(adapter_t* adapter)
  770. {
  771. u32 mod_detect;
  772. u32 gpo;
  773. /* Check for XPAK */
  774. t1_tpi_read(adapter, A_ELMER0_GPI_STAT, &mod_detect);
  775. if (!(ELMER0_GP_BIT5 & mod_detect)) {
  776. /* XPAK is present */
  777. t1_tpi_read(adapter, A_ELMER0_GPO, &gpo);
  778. gpo |= ELMER0_GP_BIT18;
  779. t1_tpi_write(adapter, A_ELMER0_GPO, gpo);
  780. }
  781. }
  782. int t1_get_board_rev(adapter_t *adapter, const struct board_info *bi,
  783. struct adapter_params *p)
  784. {
  785. p->chip_version = bi->chip_term;
  786. p->is_asic = (p->chip_version != CHBT_TERM_FPGA);
  787. if (p->chip_version == CHBT_TERM_T1 ||
  788. p->chip_version == CHBT_TERM_T2 ||
  789. p->chip_version == CHBT_TERM_FPGA) {
  790. u32 val = readl(adapter->regs + A_TP_PC_CONFIG);
  791. val = G_TP_PC_REV(val);
  792. if (val == 2)
  793. p->chip_revision = TERM_T1B;
  794. else if (val == 3)
  795. p->chip_revision = TERM_T2;
  796. else
  797. return -1;
  798. } else
  799. return -1;
  800. return 0;
  801. }
  802. /*
  803. * Enable board components other than the Chelsio chip, such as external MAC
  804. * and PHY.
  805. */
  806. static int board_init(adapter_t *adapter, const struct board_info *bi)
  807. {
  808. switch (bi->board) {
  809. case CHBT_BOARD_8000:
  810. case CHBT_BOARD_N110:
  811. case CHBT_BOARD_N210:
  812. case CHBT_BOARD_CHT210:
  813. t1_tpi_par(adapter, 0xf);
  814. t1_tpi_write(adapter, A_ELMER0_GPO, 0x800);
  815. break;
  816. case CHBT_BOARD_CHT110:
  817. t1_tpi_par(adapter, 0xf);
  818. t1_tpi_write(adapter, A_ELMER0_GPO, 0x1800);
  819. /* TBD XXX Might not need. This fixes a problem
  820. * described in the Intel SR XPAK errata.
  821. */
  822. power_sequence_xpak(adapter);
  823. break;
  824. #ifdef CONFIG_CHELSIO_T1_1G
  825. case CHBT_BOARD_CHT204E:
  826. /* add config space write here */
  827. case CHBT_BOARD_CHT204:
  828. case CHBT_BOARD_CHT204V:
  829. case CHBT_BOARD_CHN204:
  830. t1_tpi_par(adapter, 0xf);
  831. t1_tpi_write(adapter, A_ELMER0_GPO, 0x804);
  832. break;
  833. case CHBT_BOARD_CHT101:
  834. case CHBT_BOARD_7500:
  835. t1_tpi_par(adapter, 0xf);
  836. t1_tpi_write(adapter, A_ELMER0_GPO, 0x1804);
  837. break;
  838. #endif
  839. }
  840. return 0;
  841. }
  842. /*
  843. * Initialize and configure the Terminator HW modules. Note that external
  844. * MAC and PHYs are initialized separately.
  845. */
  846. int t1_init_hw_modules(adapter_t *adapter)
  847. {
  848. int err = -EIO;
  849. const struct board_info *bi = board_info(adapter);
  850. if (!bi->clock_mc4) {
  851. u32 val = readl(adapter->regs + A_MC4_CFG);
  852. writel(val | F_READY | F_MC4_SLOW, adapter->regs + A_MC4_CFG);
  853. writel(F_M_BUS_ENABLE | F_TCAM_RESET,
  854. adapter->regs + A_MC5_CONFIG);
  855. }
  856. if (adapter->espi && t1_espi_init(adapter->espi, bi->chip_mac,
  857. bi->espi_nports))
  858. goto out_err;
  859. if (t1_tp_reset(adapter->tp, &adapter->params.tp, bi->clock_core))
  860. goto out_err;
  861. err = t1_sge_configure(adapter->sge, &adapter->params.sge);
  862. if (err)
  863. goto out_err;
  864. err = 0;
  865. out_err:
  866. return err;
  867. }
  868. /*
  869. * Determine a card's PCI mode.
  870. */
  871. static void get_pci_mode(adapter_t *adapter, struct chelsio_pci_params *p)
  872. {
  873. static const unsigned short speed_map[] = { 33, 66, 100, 133 };
  874. u32 pci_mode;
  875. pci_read_config_dword(adapter->pdev, A_PCICFG_MODE, &pci_mode);
  876. p->speed = speed_map[G_PCI_MODE_CLK(pci_mode)];
  877. p->width = (pci_mode & F_PCI_MODE_64BIT) ? 64 : 32;
  878. p->is_pcix = (pci_mode & F_PCI_MODE_PCIX) != 0;
  879. }
  880. /*
  881. * Release the structures holding the SW per-Terminator-HW-module state.
  882. */
  883. void t1_free_sw_modules(adapter_t *adapter)
  884. {
  885. unsigned int i;
  886. for_each_port(adapter, i) {
  887. struct cmac *mac = adapter->port[i].mac;
  888. struct cphy *phy = adapter->port[i].phy;
  889. if (mac)
  890. mac->ops->destroy(mac);
  891. if (phy)
  892. phy->ops->destroy(phy);
  893. }
  894. if (adapter->sge)
  895. t1_sge_destroy(adapter->sge);
  896. if (adapter->tp)
  897. t1_tp_destroy(adapter->tp);
  898. if (adapter->espi)
  899. t1_espi_destroy(adapter->espi);
  900. }
  901. static void init_link_config(struct link_config *lc,
  902. const struct board_info *bi)
  903. {
  904. lc->supported = bi->caps;
  905. lc->requested_speed = lc->speed = SPEED_INVALID;
  906. lc->requested_duplex = lc->duplex = DUPLEX_INVALID;
  907. lc->requested_fc = lc->fc = PAUSE_RX | PAUSE_TX;
  908. if (lc->supported & SUPPORTED_Autoneg) {
  909. lc->advertising = lc->supported;
  910. lc->autoneg = AUTONEG_ENABLE;
  911. lc->requested_fc |= PAUSE_AUTONEG;
  912. } else {
  913. lc->advertising = 0;
  914. lc->autoneg = AUTONEG_DISABLE;
  915. }
  916. }
  917. /*
  918. * Allocate and initialize the data structures that hold the SW state of
  919. * the Terminator HW modules.
  920. */
  921. int t1_init_sw_modules(adapter_t *adapter, const struct board_info *bi)
  922. {
  923. unsigned int i;
  924. adapter->params.brd_info = bi;
  925. adapter->params.nports = bi->port_number;
  926. adapter->params.stats_update_period = bi->gmac->stats_update_period;
  927. adapter->sge = t1_sge_create(adapter, &adapter->params.sge);
  928. if (!adapter->sge) {
  929. pr_err("%s: SGE initialization failed\n",
  930. adapter->name);
  931. goto error;
  932. }
  933. if (bi->espi_nports && !(adapter->espi = t1_espi_create(adapter))) {
  934. pr_err("%s: ESPI initialization failed\n",
  935. adapter->name);
  936. goto error;
  937. }
  938. adapter->tp = t1_tp_create(adapter, &adapter->params.tp);
  939. if (!adapter->tp) {
  940. pr_err("%s: TP initialization failed\n",
  941. adapter->name);
  942. goto error;
  943. }
  944. board_init(adapter, bi);
  945. bi->mdio_ops->init(adapter, bi);
  946. if (bi->gphy->reset)
  947. bi->gphy->reset(adapter);
  948. if (bi->gmac->reset)
  949. bi->gmac->reset(adapter);
  950. for_each_port(adapter, i) {
  951. u8 hw_addr[6];
  952. struct cmac *mac;
  953. int phy_addr = bi->mdio_phybaseaddr + i;
  954. adapter->port[i].phy = bi->gphy->create(adapter->port[i].dev,
  955. phy_addr, bi->mdio_ops);
  956. if (!adapter->port[i].phy) {
  957. pr_err("%s: PHY %d initialization failed\n",
  958. adapter->name, i);
  959. goto error;
  960. }
  961. adapter->port[i].mac = mac = bi->gmac->create(adapter, i);
  962. if (!mac) {
  963. pr_err("%s: MAC %d initialization failed\n",
  964. adapter->name, i);
  965. goto error;
  966. }
  967. /*
  968. * Get the port's MAC addresses either from the EEPROM if one
  969. * exists or the one hardcoded in the MAC.
  970. */
  971. if (!t1_is_asic(adapter) || bi->chip_mac == CHBT_MAC_DUMMY)
  972. mac->ops->macaddress_get(mac, hw_addr);
  973. else if (vpd_macaddress_get(adapter, i, hw_addr)) {
  974. pr_err("%s: could not read MAC address from VPD ROM\n",
  975. adapter->port[i].dev->name);
  976. goto error;
  977. }
  978. memcpy(adapter->port[i].dev->dev_addr, hw_addr, ETH_ALEN);
  979. init_link_config(&adapter->port[i].link_config, bi);
  980. }
  981. get_pci_mode(adapter, &adapter->params.pci);
  982. t1_interrupts_clear(adapter);
  983. return 0;
  984. error:
  985. t1_free_sw_modules(adapter);
  986. return -1;
  987. }