atl1e_hw.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. /*
  2. * Copyright(c) 2007 Atheros Corporation. All rights reserved.
  3. *
  4. * Derived from Intel e1000 driver
  5. * Copyright(c) 1999 - 2005 Intel Corporation. All rights reserved.
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the Free
  9. * Software Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful, but WITHOUT
  13. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  15. * more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along with
  18. * this program; if not, write to the Free Software Foundation, Inc., 59
  19. * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  20. */
  21. #include <linux/pci.h>
  22. #include <linux/delay.h>
  23. #include <linux/mii.h>
  24. #include <linux/crc32.h>
  25. #include "atl1e.h"
  26. /*
  27. * check_eeprom_exist
  28. * return 0 if eeprom exist
  29. */
  30. int atl1e_check_eeprom_exist(struct atl1e_hw *hw)
  31. {
  32. u32 value;
  33. value = AT_READ_REG(hw, REG_SPI_FLASH_CTRL);
  34. if (value & SPI_FLASH_CTRL_EN_VPD) {
  35. value &= ~SPI_FLASH_CTRL_EN_VPD;
  36. AT_WRITE_REG(hw, REG_SPI_FLASH_CTRL, value);
  37. }
  38. value = AT_READ_REGW(hw, REG_PCIE_CAP_LIST);
  39. return ((value & 0xFF00) == 0x6C00) ? 0 : 1;
  40. }
  41. void atl1e_hw_set_mac_addr(struct atl1e_hw *hw)
  42. {
  43. u32 value;
  44. /*
  45. * 00-0B-6A-F6-00-DC
  46. * 0: 6AF600DC 1: 000B
  47. * low dword
  48. */
  49. value = (((u32)hw->mac_addr[2]) << 24) |
  50. (((u32)hw->mac_addr[3]) << 16) |
  51. (((u32)hw->mac_addr[4]) << 8) |
  52. (((u32)hw->mac_addr[5])) ;
  53. AT_WRITE_REG_ARRAY(hw, REG_MAC_STA_ADDR, 0, value);
  54. /* hight dword */
  55. value = (((u32)hw->mac_addr[0]) << 8) |
  56. (((u32)hw->mac_addr[1])) ;
  57. AT_WRITE_REG_ARRAY(hw, REG_MAC_STA_ADDR, 1, value);
  58. }
  59. /*
  60. * atl1e_get_permanent_address
  61. * return 0 if get valid mac address,
  62. */
  63. static int atl1e_get_permanent_address(struct atl1e_hw *hw)
  64. {
  65. u32 addr[2];
  66. u32 i;
  67. u32 twsi_ctrl_data;
  68. u8 eth_addr[ETH_ALEN];
  69. if (is_valid_ether_addr(hw->perm_mac_addr))
  70. return 0;
  71. /* init */
  72. addr[0] = addr[1] = 0;
  73. if (!atl1e_check_eeprom_exist(hw)) {
  74. /* eeprom exist */
  75. twsi_ctrl_data = AT_READ_REG(hw, REG_TWSI_CTRL);
  76. twsi_ctrl_data |= TWSI_CTRL_SW_LDSTART;
  77. AT_WRITE_REG(hw, REG_TWSI_CTRL, twsi_ctrl_data);
  78. for (i = 0; i < AT_TWSI_EEPROM_TIMEOUT; i++) {
  79. msleep(10);
  80. twsi_ctrl_data = AT_READ_REG(hw, REG_TWSI_CTRL);
  81. if ((twsi_ctrl_data & TWSI_CTRL_SW_LDSTART) == 0)
  82. break;
  83. }
  84. if (i >= AT_TWSI_EEPROM_TIMEOUT)
  85. return AT_ERR_TIMEOUT;
  86. }
  87. /* maybe MAC-address is from BIOS */
  88. addr[0] = AT_READ_REG(hw, REG_MAC_STA_ADDR);
  89. addr[1] = AT_READ_REG(hw, REG_MAC_STA_ADDR + 4);
  90. *(u32 *) &eth_addr[2] = swab32(addr[0]);
  91. *(u16 *) &eth_addr[0] = swab16(*(u16 *)&addr[1]);
  92. if (is_valid_ether_addr(eth_addr)) {
  93. memcpy(hw->perm_mac_addr, eth_addr, ETH_ALEN);
  94. return 0;
  95. }
  96. return AT_ERR_EEPROM;
  97. }
  98. bool atl1e_write_eeprom(struct atl1e_hw *hw, u32 offset, u32 value)
  99. {
  100. return true;
  101. }
  102. bool atl1e_read_eeprom(struct atl1e_hw *hw, u32 offset, u32 *p_value)
  103. {
  104. int i;
  105. u32 control;
  106. if (offset & 3)
  107. return false; /* address do not align */
  108. AT_WRITE_REG(hw, REG_VPD_DATA, 0);
  109. control = (offset & VPD_CAP_VPD_ADDR_MASK) << VPD_CAP_VPD_ADDR_SHIFT;
  110. AT_WRITE_REG(hw, REG_VPD_CAP, control);
  111. for (i = 0; i < 10; i++) {
  112. msleep(2);
  113. control = AT_READ_REG(hw, REG_VPD_CAP);
  114. if (control & VPD_CAP_VPD_FLAG)
  115. break;
  116. }
  117. if (control & VPD_CAP_VPD_FLAG) {
  118. *p_value = AT_READ_REG(hw, REG_VPD_DATA);
  119. return true;
  120. }
  121. return false; /* timeout */
  122. }
  123. void atl1e_force_ps(struct atl1e_hw *hw)
  124. {
  125. AT_WRITE_REGW(hw, REG_GPHY_CTRL,
  126. GPHY_CTRL_PW_WOL_DIS | GPHY_CTRL_EXT_RESET);
  127. }
  128. /*
  129. * Reads the adapter's MAC address from the EEPROM
  130. *
  131. * hw - Struct containing variables accessed by shared code
  132. */
  133. int atl1e_read_mac_addr(struct atl1e_hw *hw)
  134. {
  135. int err = 0;
  136. err = atl1e_get_permanent_address(hw);
  137. if (err)
  138. return AT_ERR_EEPROM;
  139. memcpy(hw->mac_addr, hw->perm_mac_addr, sizeof(hw->perm_mac_addr));
  140. return 0;
  141. }
  142. /*
  143. * atl1e_hash_mc_addr
  144. * purpose
  145. * set hash value for a multicast address
  146. * hash calcu processing :
  147. * 1. calcu 32bit CRC for multicast address
  148. * 2. reverse crc with MSB to LSB
  149. */
  150. u32 atl1e_hash_mc_addr(struct atl1e_hw *hw, u8 *mc_addr)
  151. {
  152. u32 crc32;
  153. u32 value = 0;
  154. int i;
  155. crc32 = ether_crc_le(6, mc_addr);
  156. crc32 = ~crc32;
  157. for (i = 0; i < 32; i++)
  158. value |= (((crc32 >> i) & 1) << (31 - i));
  159. return value;
  160. }
  161. /*
  162. * Sets the bit in the multicast table corresponding to the hash value.
  163. * hw - Struct containing variables accessed by shared code
  164. * hash_value - Multicast address hash value
  165. */
  166. void atl1e_hash_set(struct atl1e_hw *hw, u32 hash_value)
  167. {
  168. u32 hash_bit, hash_reg;
  169. u32 mta;
  170. /*
  171. * The HASH Table is a register array of 2 32-bit registers.
  172. * It is treated like an array of 64 bits. We want to set
  173. * bit BitArray[hash_value]. So we figure out what register
  174. * the bit is in, read it, OR in the new bit, then write
  175. * back the new value. The register is determined by the
  176. * upper 7 bits of the hash value and the bit within that
  177. * register are determined by the lower 5 bits of the value.
  178. */
  179. hash_reg = (hash_value >> 31) & 0x1;
  180. hash_bit = (hash_value >> 26) & 0x1F;
  181. mta = AT_READ_REG_ARRAY(hw, REG_RX_HASH_TABLE, hash_reg);
  182. mta |= (1 << hash_bit);
  183. AT_WRITE_REG_ARRAY(hw, REG_RX_HASH_TABLE, hash_reg, mta);
  184. }
  185. /*
  186. * Reads the value from a PHY register
  187. * hw - Struct containing variables accessed by shared code
  188. * reg_addr - address of the PHY register to read
  189. */
  190. int atl1e_read_phy_reg(struct atl1e_hw *hw, u16 reg_addr, u16 *phy_data)
  191. {
  192. u32 val;
  193. int i;
  194. val = ((u32)(reg_addr & MDIO_REG_ADDR_MASK)) << MDIO_REG_ADDR_SHIFT |
  195. MDIO_START | MDIO_SUP_PREAMBLE | MDIO_RW |
  196. MDIO_CLK_25_4 << MDIO_CLK_SEL_SHIFT;
  197. AT_WRITE_REG(hw, REG_MDIO_CTRL, val);
  198. wmb();
  199. for (i = 0; i < MDIO_WAIT_TIMES; i++) {
  200. udelay(2);
  201. val = AT_READ_REG(hw, REG_MDIO_CTRL);
  202. if (!(val & (MDIO_START | MDIO_BUSY)))
  203. break;
  204. wmb();
  205. }
  206. if (!(val & (MDIO_START | MDIO_BUSY))) {
  207. *phy_data = (u16)val;
  208. return 0;
  209. }
  210. return AT_ERR_PHY;
  211. }
  212. /*
  213. * Writes a value to a PHY register
  214. * hw - Struct containing variables accessed by shared code
  215. * reg_addr - address of the PHY register to write
  216. * data - data to write to the PHY
  217. */
  218. int atl1e_write_phy_reg(struct atl1e_hw *hw, u32 reg_addr, u16 phy_data)
  219. {
  220. int i;
  221. u32 val;
  222. val = ((u32)(phy_data & MDIO_DATA_MASK)) << MDIO_DATA_SHIFT |
  223. (reg_addr&MDIO_REG_ADDR_MASK) << MDIO_REG_ADDR_SHIFT |
  224. MDIO_SUP_PREAMBLE |
  225. MDIO_START |
  226. MDIO_CLK_25_4 << MDIO_CLK_SEL_SHIFT;
  227. AT_WRITE_REG(hw, REG_MDIO_CTRL, val);
  228. wmb();
  229. for (i = 0; i < MDIO_WAIT_TIMES; i++) {
  230. udelay(2);
  231. val = AT_READ_REG(hw, REG_MDIO_CTRL);
  232. if (!(val & (MDIO_START | MDIO_BUSY)))
  233. break;
  234. wmb();
  235. }
  236. if (!(val & (MDIO_START | MDIO_BUSY)))
  237. return 0;
  238. return AT_ERR_PHY;
  239. }
  240. /*
  241. * atl1e_init_pcie - init PCIE module
  242. */
  243. static void atl1e_init_pcie(struct atl1e_hw *hw)
  244. {
  245. u32 value;
  246. /* comment 2lines below to save more power when sususpend
  247. value = LTSSM_TEST_MODE_DEF;
  248. AT_WRITE_REG(hw, REG_LTSSM_TEST_MODE, value);
  249. */
  250. /* pcie flow control mode change */
  251. value = AT_READ_REG(hw, 0x1008);
  252. value |= 0x8000;
  253. AT_WRITE_REG(hw, 0x1008, value);
  254. }
  255. /*
  256. * Configures PHY autoneg and flow control advertisement settings
  257. *
  258. * hw - Struct containing variables accessed by shared code
  259. */
  260. static int atl1e_phy_setup_autoneg_adv(struct atl1e_hw *hw)
  261. {
  262. s32 ret_val;
  263. u16 mii_autoneg_adv_reg;
  264. u16 mii_1000t_ctrl_reg;
  265. if (0 != hw->mii_autoneg_adv_reg)
  266. return 0;
  267. /* Read the MII Auto-Neg Advertisement Register (Address 4/9). */
  268. mii_autoneg_adv_reg = MII_AR_DEFAULT_CAP_MASK;
  269. mii_1000t_ctrl_reg = MII_AT001_CR_1000T_DEFAULT_CAP_MASK;
  270. /*
  271. * Need to parse autoneg_advertised and set up
  272. * the appropriate PHY registers. First we will parse for
  273. * autoneg_advertised software override. Since we can advertise
  274. * a plethora of combinations, we need to check each bit
  275. * individually.
  276. */
  277. /*
  278. * First we clear all the 10/100 mb speed bits in the Auto-Neg
  279. * Advertisement Register (Address 4) and the 1000 mb speed bits in
  280. * the 1000Base-T control Register (Address 9).
  281. */
  282. mii_autoneg_adv_reg &= ~MII_AR_SPEED_MASK;
  283. mii_1000t_ctrl_reg &= ~MII_AT001_CR_1000T_SPEED_MASK;
  284. /*
  285. * Need to parse MediaType and setup the
  286. * appropriate PHY registers.
  287. */
  288. switch (hw->media_type) {
  289. case MEDIA_TYPE_AUTO_SENSOR:
  290. mii_autoneg_adv_reg |= (MII_AR_10T_HD_CAPS |
  291. MII_AR_10T_FD_CAPS |
  292. MII_AR_100TX_HD_CAPS |
  293. MII_AR_100TX_FD_CAPS);
  294. hw->autoneg_advertised = ADVERTISE_10_HALF |
  295. ADVERTISE_10_FULL |
  296. ADVERTISE_100_HALF |
  297. ADVERTISE_100_FULL;
  298. if (hw->nic_type == athr_l1e) {
  299. mii_1000t_ctrl_reg |=
  300. MII_AT001_CR_1000T_FD_CAPS;
  301. hw->autoneg_advertised |= ADVERTISE_1000_FULL;
  302. }
  303. break;
  304. case MEDIA_TYPE_100M_FULL:
  305. mii_autoneg_adv_reg |= MII_AR_100TX_FD_CAPS;
  306. hw->autoneg_advertised = ADVERTISE_100_FULL;
  307. break;
  308. case MEDIA_TYPE_100M_HALF:
  309. mii_autoneg_adv_reg |= MII_AR_100TX_HD_CAPS;
  310. hw->autoneg_advertised = ADVERTISE_100_HALF;
  311. break;
  312. case MEDIA_TYPE_10M_FULL:
  313. mii_autoneg_adv_reg |= MII_AR_10T_FD_CAPS;
  314. hw->autoneg_advertised = ADVERTISE_10_FULL;
  315. break;
  316. default:
  317. mii_autoneg_adv_reg |= MII_AR_10T_HD_CAPS;
  318. hw->autoneg_advertised = ADVERTISE_10_HALF;
  319. break;
  320. }
  321. /* flow control fixed to enable all */
  322. mii_autoneg_adv_reg |= (MII_AR_ASM_DIR | MII_AR_PAUSE);
  323. hw->mii_autoneg_adv_reg = mii_autoneg_adv_reg;
  324. hw->mii_1000t_ctrl_reg = mii_1000t_ctrl_reg;
  325. ret_val = atl1e_write_phy_reg(hw, MII_ADVERTISE, mii_autoneg_adv_reg);
  326. if (ret_val)
  327. return ret_val;
  328. if (hw->nic_type == athr_l1e || hw->nic_type == athr_l2e_revA) {
  329. ret_val = atl1e_write_phy_reg(hw, MII_AT001_CR,
  330. mii_1000t_ctrl_reg);
  331. if (ret_val)
  332. return ret_val;
  333. }
  334. return 0;
  335. }
  336. /*
  337. * Resets the PHY and make all config validate
  338. *
  339. * hw - Struct containing variables accessed by shared code
  340. *
  341. * Sets bit 15 and 12 of the MII control regiser (for F001 bug)
  342. */
  343. int atl1e_phy_commit(struct atl1e_hw *hw)
  344. {
  345. struct atl1e_adapter *adapter = hw->adapter;
  346. struct pci_dev *pdev = adapter->pdev;
  347. int ret_val;
  348. u16 phy_data;
  349. phy_data = MII_CR_RESET | MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG;
  350. ret_val = atl1e_write_phy_reg(hw, MII_BMCR, phy_data);
  351. if (ret_val) {
  352. u32 val;
  353. int i;
  354. /**************************************
  355. * pcie serdes link may be down !
  356. **************************************/
  357. for (i = 0; i < 25; i++) {
  358. msleep(1);
  359. val = AT_READ_REG(hw, REG_MDIO_CTRL);
  360. if (!(val & (MDIO_START | MDIO_BUSY)))
  361. break;
  362. }
  363. if (0 != (val & (MDIO_START | MDIO_BUSY))) {
  364. dev_err(&pdev->dev,
  365. "pcie linkdown at least for 25ms\n");
  366. return ret_val;
  367. }
  368. dev_err(&pdev->dev, "pcie linkup after %d ms\n", i);
  369. }
  370. return 0;
  371. }
  372. int atl1e_phy_init(struct atl1e_hw *hw)
  373. {
  374. struct atl1e_adapter *adapter = hw->adapter;
  375. struct pci_dev *pdev = adapter->pdev;
  376. s32 ret_val;
  377. u16 phy_val;
  378. if (hw->phy_configured) {
  379. if (hw->re_autoneg) {
  380. hw->re_autoneg = false;
  381. return atl1e_restart_autoneg(hw);
  382. }
  383. return 0;
  384. }
  385. /* RESET GPHY Core */
  386. AT_WRITE_REGW(hw, REG_GPHY_CTRL, GPHY_CTRL_DEFAULT);
  387. msleep(2);
  388. AT_WRITE_REGW(hw, REG_GPHY_CTRL, GPHY_CTRL_DEFAULT |
  389. GPHY_CTRL_EXT_RESET);
  390. msleep(2);
  391. /* patches */
  392. /* p1. eable hibernation mode */
  393. ret_val = atl1e_write_phy_reg(hw, MII_DBG_ADDR, 0xB);
  394. if (ret_val)
  395. return ret_val;
  396. ret_val = atl1e_write_phy_reg(hw, MII_DBG_DATA, 0xBC00);
  397. if (ret_val)
  398. return ret_val;
  399. /* p2. set Class A/B for all modes */
  400. ret_val = atl1e_write_phy_reg(hw, MII_DBG_ADDR, 0);
  401. if (ret_val)
  402. return ret_val;
  403. phy_val = 0x02ef;
  404. /* remove Class AB */
  405. /* phy_val = hw->emi_ca ? 0x02ef : 0x02df; */
  406. ret_val = atl1e_write_phy_reg(hw, MII_DBG_DATA, phy_val);
  407. if (ret_val)
  408. return ret_val;
  409. /* p3. 10B ??? */
  410. ret_val = atl1e_write_phy_reg(hw, MII_DBG_ADDR, 0x12);
  411. if (ret_val)
  412. return ret_val;
  413. ret_val = atl1e_write_phy_reg(hw, MII_DBG_DATA, 0x4C04);
  414. if (ret_val)
  415. return ret_val;
  416. /* p4. 1000T power */
  417. ret_val = atl1e_write_phy_reg(hw, MII_DBG_ADDR, 0x4);
  418. if (ret_val)
  419. return ret_val;
  420. ret_val = atl1e_write_phy_reg(hw, MII_DBG_DATA, 0x8BBB);
  421. if (ret_val)
  422. return ret_val;
  423. ret_val = atl1e_write_phy_reg(hw, MII_DBG_ADDR, 0x5);
  424. if (ret_val)
  425. return ret_val;
  426. ret_val = atl1e_write_phy_reg(hw, MII_DBG_DATA, 0x2C46);
  427. if (ret_val)
  428. return ret_val;
  429. msleep(1);
  430. /*Enable PHY LinkChange Interrupt */
  431. ret_val = atl1e_write_phy_reg(hw, MII_INT_CTRL, 0xC00);
  432. if (ret_val) {
  433. dev_err(&pdev->dev, "Error enable PHY linkChange Interrupt\n");
  434. return ret_val;
  435. }
  436. /* setup AutoNeg parameters */
  437. ret_val = atl1e_phy_setup_autoneg_adv(hw);
  438. if (ret_val) {
  439. dev_err(&pdev->dev, "Error Setting up Auto-Negotiation\n");
  440. return ret_val;
  441. }
  442. /* SW.Reset & En-Auto-Neg to restart Auto-Neg*/
  443. dev_dbg(&pdev->dev, "Restarting Auto-Neg");
  444. ret_val = atl1e_phy_commit(hw);
  445. if (ret_val) {
  446. dev_err(&pdev->dev, "Error Resetting the phy");
  447. return ret_val;
  448. }
  449. hw->phy_configured = true;
  450. return 0;
  451. }
  452. /*
  453. * Reset the transmit and receive units; mask and clear all interrupts.
  454. * hw - Struct containing variables accessed by shared code
  455. * return : 0 or idle status (if error)
  456. */
  457. int atl1e_reset_hw(struct atl1e_hw *hw)
  458. {
  459. struct atl1e_adapter *adapter = hw->adapter;
  460. struct pci_dev *pdev = adapter->pdev;
  461. u32 idle_status_data = 0;
  462. u16 pci_cfg_cmd_word = 0;
  463. int timeout = 0;
  464. /* Workaround for PCI problem when BIOS sets MMRBC incorrectly. */
  465. pci_read_config_word(pdev, PCI_REG_COMMAND, &pci_cfg_cmd_word);
  466. if ((pci_cfg_cmd_word & (CMD_IO_SPACE |
  467. CMD_MEMORY_SPACE | CMD_BUS_MASTER))
  468. != (CMD_IO_SPACE | CMD_MEMORY_SPACE | CMD_BUS_MASTER)) {
  469. pci_cfg_cmd_word |= (CMD_IO_SPACE |
  470. CMD_MEMORY_SPACE | CMD_BUS_MASTER);
  471. pci_write_config_word(pdev, PCI_REG_COMMAND, pci_cfg_cmd_word);
  472. }
  473. /*
  474. * Issue Soft Reset to the MAC. This will reset the chip's
  475. * transmit, receive, DMA. It will not effect
  476. * the current PCI configuration. The global reset bit is self-
  477. * clearing, and should clear within a microsecond.
  478. */
  479. AT_WRITE_REG(hw, REG_MASTER_CTRL,
  480. MASTER_CTRL_LED_MODE | MASTER_CTRL_SOFT_RST);
  481. wmb();
  482. msleep(1);
  483. /* Wait at least 10ms for All module to be Idle */
  484. for (timeout = 0; timeout < AT_HW_MAX_IDLE_DELAY; timeout++) {
  485. idle_status_data = AT_READ_REG(hw, REG_IDLE_STATUS);
  486. if (idle_status_data == 0)
  487. break;
  488. msleep(1);
  489. cpu_relax();
  490. }
  491. if (timeout >= AT_HW_MAX_IDLE_DELAY) {
  492. dev_err(&pdev->dev,
  493. "MAC state machine cann't be idle since"
  494. " disabled for 10ms second\n");
  495. return AT_ERR_TIMEOUT;
  496. }
  497. return 0;
  498. }
  499. /*
  500. * Performs basic configuration of the adapter.
  501. *
  502. * hw - Struct containing variables accessed by shared code
  503. * Assumes that the controller has previously been reset and is in a
  504. * post-reset uninitialized state. Initializes multicast table,
  505. * and Calls routines to setup link
  506. * Leaves the transmit and receive units disabled and uninitialized.
  507. */
  508. int atl1e_init_hw(struct atl1e_hw *hw)
  509. {
  510. s32 ret_val = 0;
  511. atl1e_init_pcie(hw);
  512. /* Zero out the Multicast HASH table */
  513. /* clear the old settings from the multicast hash table */
  514. AT_WRITE_REG(hw, REG_RX_HASH_TABLE, 0);
  515. AT_WRITE_REG_ARRAY(hw, REG_RX_HASH_TABLE, 1, 0);
  516. ret_val = atl1e_phy_init(hw);
  517. return ret_val;
  518. }
  519. /*
  520. * Detects the current speed and duplex settings of the hardware.
  521. *
  522. * hw - Struct containing variables accessed by shared code
  523. * speed - Speed of the connection
  524. * duplex - Duplex setting of the connection
  525. */
  526. int atl1e_get_speed_and_duplex(struct atl1e_hw *hw, u16 *speed, u16 *duplex)
  527. {
  528. int err;
  529. u16 phy_data;
  530. /* Read PHY Specific Status Register (17) */
  531. err = atl1e_read_phy_reg(hw, MII_AT001_PSSR, &phy_data);
  532. if (err)
  533. return err;
  534. if (!(phy_data & MII_AT001_PSSR_SPD_DPLX_RESOLVED))
  535. return AT_ERR_PHY_RES;
  536. switch (phy_data & MII_AT001_PSSR_SPEED) {
  537. case MII_AT001_PSSR_1000MBS:
  538. *speed = SPEED_1000;
  539. break;
  540. case MII_AT001_PSSR_100MBS:
  541. *speed = SPEED_100;
  542. break;
  543. case MII_AT001_PSSR_10MBS:
  544. *speed = SPEED_10;
  545. break;
  546. default:
  547. return AT_ERR_PHY_SPEED;
  548. break;
  549. }
  550. if (phy_data & MII_AT001_PSSR_DPLX)
  551. *duplex = FULL_DUPLEX;
  552. else
  553. *duplex = HALF_DUPLEX;
  554. return 0;
  555. }
  556. int atl1e_restart_autoneg(struct atl1e_hw *hw)
  557. {
  558. int err = 0;
  559. err = atl1e_write_phy_reg(hw, MII_ADVERTISE, hw->mii_autoneg_adv_reg);
  560. if (err)
  561. return err;
  562. if (hw->nic_type == athr_l1e || hw->nic_type == athr_l2e_revA) {
  563. err = atl1e_write_phy_reg(hw, MII_AT001_CR,
  564. hw->mii_1000t_ctrl_reg);
  565. if (err)
  566. return err;
  567. }
  568. err = atl1e_write_phy_reg(hw, MII_BMCR,
  569. MII_CR_RESET | MII_CR_AUTO_NEG_EN |
  570. MII_CR_RESTART_AUTO_NEG);
  571. return err;
  572. }