subr.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175
  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(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. struct pci_device_id 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. CH_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. CH_DBG(adapter, INTR, "External interrupt cause 0x%x\n",
  654. cause);
  655. if (cause & ELMER0_GP_BIT1) { /* PMC3393 INTB */
  656. struct cmac *mac = adapter->port[0].mac;
  657. mac->ops->interrupt_handler(mac);
  658. }
  659. if (cause & ELMER0_GP_BIT5) { /* XPAK MOD_DETECT */
  660. u32 mod_detect;
  661. t1_tpi_read(adapter,
  662. A_ELMER0_GPI_STAT, &mod_detect);
  663. CH_MSG(adapter, INFO, LINK, "XPAK %s\n",
  664. mod_detect ? "removed" : "inserted");
  665. }
  666. break;
  667. #ifdef CONFIG_CHELSIO_T1_COUGAR
  668. case CHBT_BOARD_COUGAR:
  669. if (adapter->params.nports == 1) {
  670. if (cause & ELMER0_GP_BIT1) { /* Vitesse MAC */
  671. struct cmac *mac = adapter->port[0].mac;
  672. mac->ops->interrupt_handler(mac);
  673. }
  674. if (cause & ELMER0_GP_BIT5) { /* XPAK MOD_DETECT */
  675. }
  676. } else {
  677. int i, port_bit;
  678. for_each_port(adapter, i) {
  679. port_bit = i ? i + 1 : 0;
  680. if (!(cause & (1 << port_bit)))
  681. continue;
  682. phy = adapter->port[i].phy;
  683. phy_cause = phy->ops->interrupt_handler(phy);
  684. if (phy_cause & cphy_cause_link_change)
  685. t1_link_changed(adapter, i);
  686. }
  687. }
  688. break;
  689. #endif
  690. }
  691. t1_tpi_write(adapter, A_ELMER0_INT_CAUSE, cause);
  692. return 0;
  693. }
  694. /* Enables all interrupts. */
  695. void t1_interrupts_enable(adapter_t *adapter)
  696. {
  697. unsigned int i;
  698. adapter->slow_intr_mask = F_PL_INTR_SGE_ERR | F_PL_INTR_TP;
  699. t1_sge_intr_enable(adapter->sge);
  700. t1_tp_intr_enable(adapter->tp);
  701. if (adapter->espi) {
  702. adapter->slow_intr_mask |= F_PL_INTR_ESPI;
  703. t1_espi_intr_enable(adapter->espi);
  704. }
  705. /* Enable MAC/PHY interrupts for each port. */
  706. for_each_port(adapter, i) {
  707. adapter->port[i].mac->ops->interrupt_enable(adapter->port[i].mac);
  708. adapter->port[i].phy->ops->interrupt_enable(adapter->port[i].phy);
  709. }
  710. /* Enable PCIX & external chip interrupts on ASIC boards. */
  711. if (t1_is_asic(adapter)) {
  712. u32 pl_intr = readl(adapter->regs + A_PL_ENABLE);
  713. /* PCI-X interrupts */
  714. pci_write_config_dword(adapter->pdev, A_PCICFG_INTR_ENABLE,
  715. 0xffffffff);
  716. adapter->slow_intr_mask |= F_PL_INTR_EXT | F_PL_INTR_PCIX;
  717. pl_intr |= F_PL_INTR_EXT | F_PL_INTR_PCIX;
  718. writel(pl_intr, adapter->regs + A_PL_ENABLE);
  719. }
  720. }
  721. /* Disables all interrupts. */
  722. void t1_interrupts_disable(adapter_t* adapter)
  723. {
  724. unsigned int i;
  725. t1_sge_intr_disable(adapter->sge);
  726. t1_tp_intr_disable(adapter->tp);
  727. if (adapter->espi)
  728. t1_espi_intr_disable(adapter->espi);
  729. /* Disable MAC/PHY interrupts for each port. */
  730. for_each_port(adapter, i) {
  731. adapter->port[i].mac->ops->interrupt_disable(adapter->port[i].mac);
  732. adapter->port[i].phy->ops->interrupt_disable(adapter->port[i].phy);
  733. }
  734. /* Disable PCIX & external chip interrupts. */
  735. if (t1_is_asic(adapter))
  736. writel(0, adapter->regs + A_PL_ENABLE);
  737. /* PCI-X interrupts */
  738. pci_write_config_dword(adapter->pdev, A_PCICFG_INTR_ENABLE, 0);
  739. adapter->slow_intr_mask = 0;
  740. }
  741. /* Clears all interrupts */
  742. void t1_interrupts_clear(adapter_t* adapter)
  743. {
  744. unsigned int i;
  745. t1_sge_intr_clear(adapter->sge);
  746. t1_tp_intr_clear(adapter->tp);
  747. if (adapter->espi)
  748. t1_espi_intr_clear(adapter->espi);
  749. /* Clear MAC/PHY interrupts for each port. */
  750. for_each_port(adapter, i) {
  751. adapter->port[i].mac->ops->interrupt_clear(adapter->port[i].mac);
  752. adapter->port[i].phy->ops->interrupt_clear(adapter->port[i].phy);
  753. }
  754. /* Enable interrupts for external devices. */
  755. if (t1_is_asic(adapter)) {
  756. u32 pl_intr = readl(adapter->regs + A_PL_CAUSE);
  757. writel(pl_intr | F_PL_INTR_EXT | F_PL_INTR_PCIX,
  758. adapter->regs + A_PL_CAUSE);
  759. }
  760. /* PCI-X interrupts */
  761. pci_write_config_dword(adapter->pdev, A_PCICFG_INTR_CAUSE, 0xffffffff);
  762. }
  763. /*
  764. * Slow path interrupt handler for ASICs.
  765. */
  766. static int asic_slow_intr(adapter_t *adapter)
  767. {
  768. u32 cause = readl(adapter->regs + A_PL_CAUSE);
  769. cause &= adapter->slow_intr_mask;
  770. if (!cause)
  771. return 0;
  772. if (cause & F_PL_INTR_SGE_ERR)
  773. t1_sge_intr_error_handler(adapter->sge);
  774. if (cause & F_PL_INTR_TP)
  775. t1_tp_intr_handler(adapter->tp);
  776. if (cause & F_PL_INTR_ESPI)
  777. t1_espi_intr_handler(adapter->espi);
  778. if (cause & F_PL_INTR_PCIX)
  779. t1_pci_intr_handler(adapter);
  780. if (cause & F_PL_INTR_EXT)
  781. t1_elmer0_ext_intr(adapter);
  782. /* Clear the interrupts just processed. */
  783. writel(cause, adapter->regs + A_PL_CAUSE);
  784. readl(adapter->regs + A_PL_CAUSE); /* flush writes */
  785. return 1;
  786. }
  787. int t1_slow_intr_handler(adapter_t *adapter)
  788. {
  789. #ifdef CONFIG_CHELSIO_T1_1G
  790. if (!t1_is_asic(adapter))
  791. return fpga_slow_intr(adapter);
  792. #endif
  793. return asic_slow_intr(adapter);
  794. }
  795. /* Power sequencing is a work-around for Intel's XPAKs. */
  796. static void power_sequence_xpak(adapter_t* adapter)
  797. {
  798. u32 mod_detect;
  799. u32 gpo;
  800. /* Check for XPAK */
  801. t1_tpi_read(adapter, A_ELMER0_GPI_STAT, &mod_detect);
  802. if (!(ELMER0_GP_BIT5 & mod_detect)) {
  803. /* XPAK is present */
  804. t1_tpi_read(adapter, A_ELMER0_GPO, &gpo);
  805. gpo |= ELMER0_GP_BIT18;
  806. t1_tpi_write(adapter, A_ELMER0_GPO, gpo);
  807. }
  808. }
  809. int __devinit t1_get_board_rev(adapter_t *adapter, const struct board_info *bi,
  810. struct adapter_params *p)
  811. {
  812. p->chip_version = bi->chip_term;
  813. p->is_asic = (p->chip_version != CHBT_TERM_FPGA);
  814. if (p->chip_version == CHBT_TERM_T1 ||
  815. p->chip_version == CHBT_TERM_T2 ||
  816. p->chip_version == CHBT_TERM_FPGA) {
  817. u32 val = readl(adapter->regs + A_TP_PC_CONFIG);
  818. val = G_TP_PC_REV(val);
  819. if (val == 2)
  820. p->chip_revision = TERM_T1B;
  821. else if (val == 3)
  822. p->chip_revision = TERM_T2;
  823. else
  824. return -1;
  825. } else
  826. return -1;
  827. return 0;
  828. }
  829. /*
  830. * Enable board components other than the Chelsio chip, such as external MAC
  831. * and PHY.
  832. */
  833. static int board_init(adapter_t *adapter, const struct board_info *bi)
  834. {
  835. switch (bi->board) {
  836. case CHBT_BOARD_8000:
  837. case CHBT_BOARD_N110:
  838. case CHBT_BOARD_N210:
  839. case CHBT_BOARD_CHT210:
  840. case CHBT_BOARD_COUGAR:
  841. t1_tpi_par(adapter, 0xf);
  842. t1_tpi_write(adapter, A_ELMER0_GPO, 0x800);
  843. break;
  844. case CHBT_BOARD_CHT110:
  845. t1_tpi_par(adapter, 0xf);
  846. t1_tpi_write(adapter, A_ELMER0_GPO, 0x1800);
  847. /* TBD XXX Might not need. This fixes a problem
  848. * described in the Intel SR XPAK errata.
  849. */
  850. power_sequence_xpak(adapter);
  851. break;
  852. #ifdef CONFIG_CHELSIO_T1_1G
  853. case CHBT_BOARD_CHT204E:
  854. /* add config space write here */
  855. case CHBT_BOARD_CHT204:
  856. case CHBT_BOARD_CHT204V:
  857. case CHBT_BOARD_CHN204:
  858. t1_tpi_par(adapter, 0xf);
  859. t1_tpi_write(adapter, A_ELMER0_GPO, 0x804);
  860. break;
  861. case CHBT_BOARD_CHT101:
  862. case CHBT_BOARD_7500:
  863. t1_tpi_par(adapter, 0xf);
  864. t1_tpi_write(adapter, A_ELMER0_GPO, 0x1804);
  865. break;
  866. #endif
  867. }
  868. return 0;
  869. }
  870. /*
  871. * Initialize and configure the Terminator HW modules. Note that external
  872. * MAC and PHYs are initialized separately.
  873. */
  874. int t1_init_hw_modules(adapter_t *adapter)
  875. {
  876. int err = -EIO;
  877. const struct board_info *bi = board_info(adapter);
  878. if (!bi->clock_mc4) {
  879. u32 val = readl(adapter->regs + A_MC4_CFG);
  880. writel(val | F_READY | F_MC4_SLOW, adapter->regs + A_MC4_CFG);
  881. writel(F_M_BUS_ENABLE | F_TCAM_RESET,
  882. adapter->regs + A_MC5_CONFIG);
  883. }
  884. #ifdef CONFIG_CHELSIO_T1_COUGAR
  885. if (adapter->cspi && t1_cspi_init(adapter->cspi))
  886. goto out_err;
  887. #endif
  888. if (adapter->espi && t1_espi_init(adapter->espi, bi->chip_mac,
  889. bi->espi_nports))
  890. goto out_err;
  891. if (t1_tp_reset(adapter->tp, &adapter->params.tp, bi->clock_core))
  892. goto out_err;
  893. err = t1_sge_configure(adapter->sge, &adapter->params.sge);
  894. if (err)
  895. goto out_err;
  896. err = 0;
  897. out_err:
  898. return err;
  899. }
  900. /*
  901. * Determine a card's PCI mode.
  902. */
  903. static void __devinit get_pci_mode(adapter_t *adapter, struct chelsio_pci_params *p)
  904. {
  905. static const unsigned short speed_map[] = { 33, 66, 100, 133 };
  906. u32 pci_mode;
  907. pci_read_config_dword(adapter->pdev, A_PCICFG_MODE, &pci_mode);
  908. p->speed = speed_map[G_PCI_MODE_CLK(pci_mode)];
  909. p->width = (pci_mode & F_PCI_MODE_64BIT) ? 64 : 32;
  910. p->is_pcix = (pci_mode & F_PCI_MODE_PCIX) != 0;
  911. }
  912. /*
  913. * Release the structures holding the SW per-Terminator-HW-module state.
  914. */
  915. void t1_free_sw_modules(adapter_t *adapter)
  916. {
  917. unsigned int i;
  918. for_each_port(adapter, i) {
  919. struct cmac *mac = adapter->port[i].mac;
  920. struct cphy *phy = adapter->port[i].phy;
  921. if (mac)
  922. mac->ops->destroy(mac);
  923. if (phy)
  924. phy->ops->destroy(phy);
  925. }
  926. if (adapter->sge)
  927. t1_sge_destroy(adapter->sge);
  928. if (adapter->tp)
  929. t1_tp_destroy(adapter->tp);
  930. if (adapter->espi)
  931. t1_espi_destroy(adapter->espi);
  932. #ifdef CONFIG_CHELSIO_T1_COUGAR
  933. if (adapter->cspi)
  934. t1_cspi_destroy(adapter->cspi);
  935. #endif
  936. }
  937. static void __devinit init_link_config(struct link_config *lc,
  938. const struct board_info *bi)
  939. {
  940. lc->supported = bi->caps;
  941. lc->requested_speed = lc->speed = SPEED_INVALID;
  942. lc->requested_duplex = lc->duplex = DUPLEX_INVALID;
  943. lc->requested_fc = lc->fc = PAUSE_RX | PAUSE_TX;
  944. if (lc->supported & SUPPORTED_Autoneg) {
  945. lc->advertising = lc->supported;
  946. lc->autoneg = AUTONEG_ENABLE;
  947. lc->requested_fc |= PAUSE_AUTONEG;
  948. } else {
  949. lc->advertising = 0;
  950. lc->autoneg = AUTONEG_DISABLE;
  951. }
  952. }
  953. #ifdef CONFIG_CHELSIO_T1_COUGAR
  954. if (bi->clock_cspi && !(adapter->cspi = t1_cspi_create(adapter))) {
  955. CH_ERR("%s: CSPI initialization failed\n",
  956. adapter->name);
  957. goto error;
  958. }
  959. #endif
  960. /*
  961. * Allocate and initialize the data structures that hold the SW state of
  962. * the Terminator HW modules.
  963. */
  964. int __devinit t1_init_sw_modules(adapter_t *adapter,
  965. const struct board_info *bi)
  966. {
  967. unsigned int i;
  968. adapter->params.brd_info = bi;
  969. adapter->params.nports = bi->port_number;
  970. adapter->params.stats_update_period = bi->gmac->stats_update_period;
  971. adapter->sge = t1_sge_create(adapter, &adapter->params.sge);
  972. if (!adapter->sge) {
  973. CH_ERR("%s: SGE initialization failed\n",
  974. adapter->name);
  975. goto error;
  976. }
  977. if (bi->espi_nports && !(adapter->espi = t1_espi_create(adapter))) {
  978. CH_ERR("%s: ESPI initialization failed\n",
  979. adapter->name);
  980. goto error;
  981. }
  982. adapter->tp = t1_tp_create(adapter, &adapter->params.tp);
  983. if (!adapter->tp) {
  984. CH_ERR("%s: TP initialization failed\n",
  985. adapter->name);
  986. goto error;
  987. }
  988. board_init(adapter, bi);
  989. bi->mdio_ops->init(adapter, bi);
  990. if (bi->gphy->reset)
  991. bi->gphy->reset(adapter);
  992. if (bi->gmac->reset)
  993. bi->gmac->reset(adapter);
  994. for_each_port(adapter, i) {
  995. u8 hw_addr[6];
  996. struct cmac *mac;
  997. int phy_addr = bi->mdio_phybaseaddr + i;
  998. adapter->port[i].phy = bi->gphy->create(adapter->port[i].dev,
  999. phy_addr, bi->mdio_ops);
  1000. if (!adapter->port[i].phy) {
  1001. CH_ERR("%s: PHY %d initialization failed\n",
  1002. adapter->name, i);
  1003. goto error;
  1004. }
  1005. adapter->port[i].mac = mac = bi->gmac->create(adapter, i);
  1006. if (!mac) {
  1007. CH_ERR("%s: MAC %d initialization failed\n",
  1008. adapter->name, i);
  1009. goto error;
  1010. }
  1011. /*
  1012. * Get the port's MAC addresses either from the EEPROM if one
  1013. * exists or the one hardcoded in the MAC.
  1014. */
  1015. if (!t1_is_asic(adapter) || bi->chip_mac == CHBT_MAC_DUMMY)
  1016. mac->ops->macaddress_get(mac, hw_addr);
  1017. else if (vpd_macaddress_get(adapter, i, hw_addr)) {
  1018. CH_ERR("%s: could not read MAC address from VPD ROM\n",
  1019. adapter->port[i].dev->name);
  1020. goto error;
  1021. }
  1022. memcpy(adapter->port[i].dev->dev_addr, hw_addr, ETH_ALEN);
  1023. init_link_config(&adapter->port[i].link_config, bi);
  1024. }
  1025. get_pci_mode(adapter, &adapter->params.pci);
  1026. t1_interrupts_clear(adapter);
  1027. return 0;
  1028. error:
  1029. t1_free_sw_modules(adapter);
  1030. return -1;
  1031. }