subr.c 32 KB

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