subr.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172
  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, u32 *data)
  496. {
  497. int i = EEPROM_MAX_POLL;
  498. u16 val;
  499. if (addr >= EEPROMSIZE || (addr & 3))
  500. return -EINVAL;
  501. pci_write_config_word(adapter->pdev, A_PCICFG_VPD_ADDR, (u16)addr);
  502. do {
  503. udelay(50);
  504. pci_read_config_word(adapter->pdev, A_PCICFG_VPD_ADDR, &val);
  505. } while (!(val & F_VPD_OP_FLAG) && --i);
  506. if (!(val & F_VPD_OP_FLAG)) {
  507. CH_ERR("%s: reading EEPROM address 0x%x failed\n",
  508. adapter->name, addr);
  509. return -EIO;
  510. }
  511. pci_read_config_dword(adapter->pdev, A_PCICFG_VPD_DATA, data);
  512. *data = le32_to_cpu(*data);
  513. return 0;
  514. }
  515. static int t1_eeprom_vpd_get(adapter_t *adapter, struct chelsio_vpd_t *vpd)
  516. {
  517. int addr, ret = 0;
  518. for (addr = 0; !ret && addr < sizeof(*vpd); addr += sizeof(u32))
  519. ret = t1_seeprom_read(adapter, addr,
  520. (u32 *)((u8 *)vpd + addr));
  521. return ret;
  522. }
  523. /*
  524. * Read a port's MAC address from the VPD ROM.
  525. */
  526. static int vpd_macaddress_get(adapter_t *adapter, int index, u8 mac_addr[])
  527. {
  528. struct chelsio_vpd_t vpd;
  529. if (t1_eeprom_vpd_get(adapter, &vpd))
  530. return 1;
  531. memcpy(mac_addr, vpd.mac_base_address, 5);
  532. mac_addr[5] = vpd.mac_base_address[5] + index;
  533. return 0;
  534. }
  535. /*
  536. * Set up the MAC/PHY according to the requested link settings.
  537. *
  538. * If the PHY can auto-negotiate first decide what to advertise, then
  539. * enable/disable auto-negotiation as desired and reset.
  540. *
  541. * If the PHY does not auto-negotiate we just reset it.
  542. *
  543. * If auto-negotiation is off set the MAC to the proper speed/duplex/FC,
  544. * otherwise do it later based on the outcome of auto-negotiation.
  545. */
  546. int t1_link_start(struct cphy *phy, struct cmac *mac, struct link_config *lc)
  547. {
  548. unsigned int fc = lc->requested_fc & (PAUSE_RX | PAUSE_TX);
  549. if (lc->supported & SUPPORTED_Autoneg) {
  550. lc->advertising &= ~(ADVERTISED_ASYM_PAUSE | ADVERTISED_PAUSE);
  551. if (fc) {
  552. if (fc == ((PAUSE_RX | PAUSE_TX) &
  553. (mac->adapter->params.nports < 2)))
  554. lc->advertising |= ADVERTISED_PAUSE;
  555. else {
  556. lc->advertising |= ADVERTISED_ASYM_PAUSE;
  557. if (fc == PAUSE_RX)
  558. lc->advertising |= ADVERTISED_PAUSE;
  559. }
  560. }
  561. phy->ops->advertise(phy, lc->advertising);
  562. if (lc->autoneg == AUTONEG_DISABLE) {
  563. lc->speed = lc->requested_speed;
  564. lc->duplex = lc->requested_duplex;
  565. lc->fc = (unsigned char)fc;
  566. mac->ops->set_speed_duplex_fc(mac, lc->speed,
  567. lc->duplex, fc);
  568. /* Also disables autoneg */
  569. phy->state = PHY_AUTONEG_RDY;
  570. phy->ops->set_speed_duplex(phy, lc->speed, lc->duplex);
  571. phy->ops->reset(phy, 0);
  572. } else {
  573. phy->state = PHY_AUTONEG_EN;
  574. phy->ops->autoneg_enable(phy); /* also resets PHY */
  575. }
  576. } else {
  577. phy->state = PHY_AUTONEG_RDY;
  578. mac->ops->set_speed_duplex_fc(mac, -1, -1, fc);
  579. lc->fc = (unsigned char)fc;
  580. phy->ops->reset(phy, 0);
  581. }
  582. return 0;
  583. }
  584. /*
  585. * External interrupt handler for boards using elmer0.
  586. */
  587. int t1_elmer0_ext_intr_handler(adapter_t *adapter)
  588. {
  589. struct cphy *phy;
  590. int phy_cause;
  591. u32 cause;
  592. t1_tpi_read(adapter, A_ELMER0_INT_CAUSE, &cause);
  593. switch (board_info(adapter)->board) {
  594. #ifdef CONFIG_CHELSIO_T1_1G
  595. case CHBT_BOARD_CHT204:
  596. case CHBT_BOARD_CHT204E:
  597. case CHBT_BOARD_CHN204:
  598. case CHBT_BOARD_CHT204V: {
  599. int i, port_bit;
  600. for_each_port(adapter, i) {
  601. port_bit = i + 1;
  602. if (!(cause & (1 << port_bit)))
  603. continue;
  604. phy = adapter->port[i].phy;
  605. phy_cause = phy->ops->interrupt_handler(phy);
  606. if (phy_cause & cphy_cause_link_change)
  607. t1_link_changed(adapter, i);
  608. }
  609. break;
  610. }
  611. case CHBT_BOARD_CHT101:
  612. if (cause & ELMER0_GP_BIT1) { /* Marvell 88E1111 interrupt */
  613. phy = adapter->port[0].phy;
  614. phy_cause = phy->ops->interrupt_handler(phy);
  615. if (phy_cause & cphy_cause_link_change)
  616. t1_link_changed(adapter, 0);
  617. }
  618. break;
  619. case CHBT_BOARD_7500: {
  620. int p;
  621. /*
  622. * Elmer0's interrupt cause isn't useful here because there is
  623. * only one bit that can be set for all 4 ports. This means
  624. * we are forced to check every PHY's interrupt status
  625. * register to see who initiated the interrupt.
  626. */
  627. for_each_port(adapter, p) {
  628. phy = adapter->port[p].phy;
  629. phy_cause = phy->ops->interrupt_handler(phy);
  630. if (phy_cause & cphy_cause_link_change)
  631. t1_link_changed(adapter, p);
  632. }
  633. break;
  634. }
  635. #endif
  636. case CHBT_BOARD_CHT210:
  637. case CHBT_BOARD_N210:
  638. case CHBT_BOARD_N110:
  639. if (cause & ELMER0_GP_BIT6) { /* Marvell 88x2010 interrupt */
  640. phy = adapter->port[0].phy;
  641. phy_cause = phy->ops->interrupt_handler(phy);
  642. if (phy_cause & cphy_cause_link_change)
  643. t1_link_changed(adapter, 0);
  644. }
  645. break;
  646. case CHBT_BOARD_8000:
  647. case CHBT_BOARD_CHT110:
  648. CH_DBG(adapter, INTR, "External interrupt cause 0x%x\n",
  649. 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. CH_MSG(adapter, INFO, LINK, "XPAK %s\n",
  659. mod_detect ? "removed" : "inserted");
  660. }
  661. break;
  662. #ifdef CONFIG_CHELSIO_T1_COUGAR
  663. case CHBT_BOARD_COUGAR:
  664. if (adapter->params.nports == 1) {
  665. if (cause & ELMER0_GP_BIT1) { /* Vitesse MAC */
  666. struct cmac *mac = adapter->port[0].mac;
  667. mac->ops->interrupt_handler(mac);
  668. }
  669. if (cause & ELMER0_GP_BIT5) { /* XPAK MOD_DETECT */
  670. }
  671. } else {
  672. int i, port_bit;
  673. for_each_port(adapter, i) {
  674. port_bit = i ? i + 1 : 0;
  675. if (!(cause & (1 << port_bit)))
  676. continue;
  677. phy = adapter->port[i].phy;
  678. phy_cause = phy->ops->interrupt_handler(phy);
  679. if (phy_cause & cphy_cause_link_change)
  680. t1_link_changed(adapter, i);
  681. }
  682. }
  683. break;
  684. #endif
  685. }
  686. t1_tpi_write(adapter, A_ELMER0_INT_CAUSE, cause);
  687. return 0;
  688. }
  689. /* Enables all interrupts. */
  690. void t1_interrupts_enable(adapter_t *adapter)
  691. {
  692. unsigned int i;
  693. adapter->slow_intr_mask = F_PL_INTR_SGE_ERR | F_PL_INTR_TP;
  694. t1_sge_intr_enable(adapter->sge);
  695. t1_tp_intr_enable(adapter->tp);
  696. if (adapter->espi) {
  697. adapter->slow_intr_mask |= F_PL_INTR_ESPI;
  698. t1_espi_intr_enable(adapter->espi);
  699. }
  700. /* Enable MAC/PHY interrupts for each port. */
  701. for_each_port(adapter, i) {
  702. adapter->port[i].mac->ops->interrupt_enable(adapter->port[i].mac);
  703. adapter->port[i].phy->ops->interrupt_enable(adapter->port[i].phy);
  704. }
  705. /* Enable PCIX & external chip interrupts on ASIC boards. */
  706. if (t1_is_asic(adapter)) {
  707. u32 pl_intr = readl(adapter->regs + A_PL_ENABLE);
  708. /* PCI-X interrupts */
  709. pci_write_config_dword(adapter->pdev, A_PCICFG_INTR_ENABLE,
  710. 0xffffffff);
  711. adapter->slow_intr_mask |= F_PL_INTR_EXT | F_PL_INTR_PCIX;
  712. pl_intr |= F_PL_INTR_EXT | F_PL_INTR_PCIX;
  713. writel(pl_intr, adapter->regs + A_PL_ENABLE);
  714. }
  715. }
  716. /* Disables all interrupts. */
  717. void t1_interrupts_disable(adapter_t* adapter)
  718. {
  719. unsigned int i;
  720. t1_sge_intr_disable(adapter->sge);
  721. t1_tp_intr_disable(adapter->tp);
  722. if (adapter->espi)
  723. t1_espi_intr_disable(adapter->espi);
  724. /* Disable MAC/PHY interrupts for each port. */
  725. for_each_port(adapter, i) {
  726. adapter->port[i].mac->ops->interrupt_disable(adapter->port[i].mac);
  727. adapter->port[i].phy->ops->interrupt_disable(adapter->port[i].phy);
  728. }
  729. /* Disable PCIX & external chip interrupts. */
  730. if (t1_is_asic(adapter))
  731. writel(0, adapter->regs + A_PL_ENABLE);
  732. /* PCI-X interrupts */
  733. pci_write_config_dword(adapter->pdev, A_PCICFG_INTR_ENABLE, 0);
  734. adapter->slow_intr_mask = 0;
  735. }
  736. /* Clears all interrupts */
  737. void t1_interrupts_clear(adapter_t* adapter)
  738. {
  739. unsigned int i;
  740. t1_sge_intr_clear(adapter->sge);
  741. t1_tp_intr_clear(adapter->tp);
  742. if (adapter->espi)
  743. t1_espi_intr_clear(adapter->espi);
  744. /* Clear MAC/PHY interrupts for each port. */
  745. for_each_port(adapter, i) {
  746. adapter->port[i].mac->ops->interrupt_clear(adapter->port[i].mac);
  747. adapter->port[i].phy->ops->interrupt_clear(adapter->port[i].phy);
  748. }
  749. /* Enable interrupts for external devices. */
  750. if (t1_is_asic(adapter)) {
  751. u32 pl_intr = readl(adapter->regs + A_PL_CAUSE);
  752. writel(pl_intr | F_PL_INTR_EXT | F_PL_INTR_PCIX,
  753. adapter->regs + A_PL_CAUSE);
  754. }
  755. /* PCI-X interrupts */
  756. pci_write_config_dword(adapter->pdev, A_PCICFG_INTR_CAUSE, 0xffffffff);
  757. }
  758. /*
  759. * Slow path interrupt handler for ASICs.
  760. */
  761. static int asic_slow_intr(adapter_t *adapter)
  762. {
  763. u32 cause = readl(adapter->regs + A_PL_CAUSE);
  764. cause &= adapter->slow_intr_mask;
  765. if (!cause)
  766. return 0;
  767. if (cause & F_PL_INTR_SGE_ERR)
  768. t1_sge_intr_error_handler(adapter->sge);
  769. if (cause & F_PL_INTR_TP)
  770. t1_tp_intr_handler(adapter->tp);
  771. if (cause & F_PL_INTR_ESPI)
  772. t1_espi_intr_handler(adapter->espi);
  773. if (cause & F_PL_INTR_PCIX)
  774. t1_pci_intr_handler(adapter);
  775. if (cause & F_PL_INTR_EXT)
  776. t1_elmer0_ext_intr_handler(adapter);
  777. /* Clear the interrupts just processed. */
  778. writel(cause, adapter->regs + A_PL_CAUSE);
  779. readl(adapter->regs + A_PL_CAUSE); /* flush writes */
  780. return 1;
  781. }
  782. int t1_slow_intr_handler(adapter_t *adapter)
  783. {
  784. #ifdef CONFIG_CHELSIO_T1_1G
  785. if (!t1_is_asic(adapter))
  786. return fpga_slow_intr(adapter);
  787. #endif
  788. return asic_slow_intr(adapter);
  789. }
  790. /* Power sequencing is a work-around for Intel's XPAKs. */
  791. static void power_sequence_xpak(adapter_t* adapter)
  792. {
  793. u32 mod_detect;
  794. u32 gpo;
  795. /* Check for XPAK */
  796. t1_tpi_read(adapter, A_ELMER0_GPI_STAT, &mod_detect);
  797. if (!(ELMER0_GP_BIT5 & mod_detect)) {
  798. /* XPAK is present */
  799. t1_tpi_read(adapter, A_ELMER0_GPO, &gpo);
  800. gpo |= ELMER0_GP_BIT18;
  801. t1_tpi_write(adapter, A_ELMER0_GPO, gpo);
  802. }
  803. }
  804. int __devinit t1_get_board_rev(adapter_t *adapter, const struct board_info *bi,
  805. struct adapter_params *p)
  806. {
  807. p->chip_version = bi->chip_term;
  808. p->is_asic = (p->chip_version != CHBT_TERM_FPGA);
  809. if (p->chip_version == CHBT_TERM_T1 ||
  810. p->chip_version == CHBT_TERM_T2 ||
  811. p->chip_version == CHBT_TERM_FPGA) {
  812. u32 val = readl(adapter->regs + A_TP_PC_CONFIG);
  813. val = G_TP_PC_REV(val);
  814. if (val == 2)
  815. p->chip_revision = TERM_T1B;
  816. else if (val == 3)
  817. p->chip_revision = TERM_T2;
  818. else
  819. return -1;
  820. } else
  821. return -1;
  822. return 0;
  823. }
  824. /*
  825. * Enable board components other than the Chelsio chip, such as external MAC
  826. * and PHY.
  827. */
  828. static int board_init(adapter_t *adapter, const struct board_info *bi)
  829. {
  830. switch (bi->board) {
  831. case CHBT_BOARD_8000:
  832. case CHBT_BOARD_N110:
  833. case CHBT_BOARD_N210:
  834. case CHBT_BOARD_CHT210:
  835. case CHBT_BOARD_COUGAR:
  836. t1_tpi_par(adapter, 0xf);
  837. t1_tpi_write(adapter, A_ELMER0_GPO, 0x800);
  838. break;
  839. case CHBT_BOARD_CHT110:
  840. t1_tpi_par(adapter, 0xf);
  841. t1_tpi_write(adapter, A_ELMER0_GPO, 0x1800);
  842. /* TBD XXX Might not need. This fixes a problem
  843. * described in the Intel SR XPAK errata.
  844. */
  845. power_sequence_xpak(adapter);
  846. break;
  847. #ifdef CONFIG_CHELSIO_T1_1G
  848. case CHBT_BOARD_CHT204E:
  849. /* add config space write here */
  850. case CHBT_BOARD_CHT204:
  851. case CHBT_BOARD_CHT204V:
  852. case CHBT_BOARD_CHN204:
  853. t1_tpi_par(adapter, 0xf);
  854. t1_tpi_write(adapter, A_ELMER0_GPO, 0x804);
  855. break;
  856. case CHBT_BOARD_CHT101:
  857. case CHBT_BOARD_7500:
  858. t1_tpi_par(adapter, 0xf);
  859. t1_tpi_write(adapter, A_ELMER0_GPO, 0x1804);
  860. break;
  861. #endif
  862. }
  863. return 0;
  864. }
  865. /*
  866. * Initialize and configure the Terminator HW modules. Note that external
  867. * MAC and PHYs are initialized separately.
  868. */
  869. int t1_init_hw_modules(adapter_t *adapter)
  870. {
  871. int err = -EIO;
  872. const struct board_info *bi = board_info(adapter);
  873. if (!bi->clock_mc4) {
  874. u32 val = readl(adapter->regs + A_MC4_CFG);
  875. writel(val | F_READY | F_MC4_SLOW, adapter->regs + A_MC4_CFG);
  876. writel(F_M_BUS_ENABLE | F_TCAM_RESET,
  877. adapter->regs + A_MC5_CONFIG);
  878. }
  879. #ifdef CONFIG_CHELSIO_T1_COUGAR
  880. if (adapter->cspi && t1_cspi_init(adapter->cspi))
  881. goto out_err;
  882. #endif
  883. if (adapter->espi && t1_espi_init(adapter->espi, bi->chip_mac,
  884. bi->espi_nports))
  885. goto out_err;
  886. if (t1_tp_reset(adapter->tp, &adapter->params.tp, bi->clock_core))
  887. goto out_err;
  888. err = t1_sge_configure(adapter->sge, &adapter->params.sge);
  889. if (err)
  890. goto out_err;
  891. err = 0;
  892. out_err:
  893. return err;
  894. }
  895. /*
  896. * Determine a card's PCI mode.
  897. */
  898. static void __devinit get_pci_mode(adapter_t *adapter, struct chelsio_pci_params *p)
  899. {
  900. static const unsigned short speed_map[] = { 33, 66, 100, 133 };
  901. u32 pci_mode;
  902. pci_read_config_dword(adapter->pdev, A_PCICFG_MODE, &pci_mode);
  903. p->speed = speed_map[G_PCI_MODE_CLK(pci_mode)];
  904. p->width = (pci_mode & F_PCI_MODE_64BIT) ? 64 : 32;
  905. p->is_pcix = (pci_mode & F_PCI_MODE_PCIX) != 0;
  906. }
  907. /*
  908. * Release the structures holding the SW per-Terminator-HW-module state.
  909. */
  910. void t1_free_sw_modules(adapter_t *adapter)
  911. {
  912. unsigned int i;
  913. for_each_port(adapter, i) {
  914. struct cmac *mac = adapter->port[i].mac;
  915. struct cphy *phy = adapter->port[i].phy;
  916. if (mac)
  917. mac->ops->destroy(mac);
  918. if (phy)
  919. phy->ops->destroy(phy);
  920. }
  921. if (adapter->sge)
  922. t1_sge_destroy(adapter->sge);
  923. if (adapter->tp)
  924. t1_tp_destroy(adapter->tp);
  925. if (adapter->espi)
  926. t1_espi_destroy(adapter->espi);
  927. #ifdef CONFIG_CHELSIO_T1_COUGAR
  928. if (adapter->cspi)
  929. t1_cspi_destroy(adapter->cspi);
  930. #endif
  931. }
  932. static void __devinit init_link_config(struct link_config *lc,
  933. const struct board_info *bi)
  934. {
  935. lc->supported = bi->caps;
  936. lc->requested_speed = lc->speed = SPEED_INVALID;
  937. lc->requested_duplex = lc->duplex = DUPLEX_INVALID;
  938. lc->requested_fc = lc->fc = PAUSE_RX | PAUSE_TX;
  939. if (lc->supported & SUPPORTED_Autoneg) {
  940. lc->advertising = lc->supported;
  941. lc->autoneg = AUTONEG_ENABLE;
  942. lc->requested_fc |= PAUSE_AUTONEG;
  943. } else {
  944. lc->advertising = 0;
  945. lc->autoneg = AUTONEG_DISABLE;
  946. }
  947. }
  948. #ifdef CONFIG_CHELSIO_T1_COUGAR
  949. if (bi->clock_cspi && !(adapter->cspi = t1_cspi_create(adapter))) {
  950. CH_ERR("%s: CSPI initialization failed\n",
  951. adapter->name);
  952. goto error;
  953. }
  954. #endif
  955. /*
  956. * Allocate and initialize the data structures that hold the SW state of
  957. * the Terminator HW modules.
  958. */
  959. int __devinit t1_init_sw_modules(adapter_t *adapter,
  960. const struct board_info *bi)
  961. {
  962. unsigned int i;
  963. adapter->params.brd_info = bi;
  964. adapter->params.nports = bi->port_number;
  965. adapter->params.stats_update_period = bi->gmac->stats_update_period;
  966. adapter->sge = t1_sge_create(adapter, &adapter->params.sge);
  967. if (!adapter->sge) {
  968. CH_ERR("%s: SGE initialization failed\n",
  969. adapter->name);
  970. goto error;
  971. }
  972. if (bi->espi_nports && !(adapter->espi = t1_espi_create(adapter))) {
  973. CH_ERR("%s: ESPI initialization failed\n",
  974. adapter->name);
  975. goto error;
  976. }
  977. adapter->tp = t1_tp_create(adapter, &adapter->params.tp);
  978. if (!adapter->tp) {
  979. CH_ERR("%s: TP initialization failed\n",
  980. adapter->name);
  981. goto error;
  982. }
  983. board_init(adapter, bi);
  984. bi->mdio_ops->init(adapter, bi);
  985. if (bi->gphy->reset)
  986. bi->gphy->reset(adapter);
  987. if (bi->gmac->reset)
  988. bi->gmac->reset(adapter);
  989. for_each_port(adapter, i) {
  990. u8 hw_addr[6];
  991. struct cmac *mac;
  992. int phy_addr = bi->mdio_phybaseaddr + i;
  993. adapter->port[i].phy = bi->gphy->create(adapter, phy_addr,
  994. bi->mdio_ops);
  995. if (!adapter->port[i].phy) {
  996. CH_ERR("%s: PHY %d initialization failed\n",
  997. adapter->name, i);
  998. goto error;
  999. }
  1000. adapter->port[i].mac = mac = bi->gmac->create(adapter, i);
  1001. if (!mac) {
  1002. CH_ERR("%s: MAC %d initialization failed\n",
  1003. adapter->name, i);
  1004. goto error;
  1005. }
  1006. /*
  1007. * Get the port's MAC addresses either from the EEPROM if one
  1008. * exists or the one hardcoded in the MAC.
  1009. */
  1010. if (!t1_is_asic(adapter) || bi->chip_mac == CHBT_MAC_DUMMY)
  1011. mac->ops->macaddress_get(mac, hw_addr);
  1012. else if (vpd_macaddress_get(adapter, i, hw_addr)) {
  1013. CH_ERR("%s: could not read MAC address from VPD ROM\n",
  1014. adapter->port[i].dev->name);
  1015. goto error;
  1016. }
  1017. memcpy(adapter->port[i].dev->dev_addr, hw_addr, ETH_ALEN);
  1018. init_link_config(&adapter->port[i].link_config, bi);
  1019. }
  1020. get_pci_mode(adapter, &adapter->params.pci);
  1021. t1_interrupts_clear(adapter);
  1022. return 0;
  1023. error:
  1024. t1_free_sw_modules(adapter);
  1025. return -1;
  1026. }