subr.c 32 KB

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