atl1e_hw.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  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. */
  147. u32 atl1e_hash_mc_addr(struct atl1e_hw *hw, u8 *mc_addr)
  148. {
  149. u32 crc32;
  150. u32 value = 0;
  151. int i;
  152. crc32 = ether_crc_le(6, mc_addr);
  153. for (i = 0; i < 32; i++)
  154. value |= (((crc32 >> i) & 1) << (31 - i));
  155. return value;
  156. }
  157. /*
  158. * Sets the bit in the multicast table corresponding to the hash value.
  159. * hw - Struct containing variables accessed by shared code
  160. * hash_value - Multicast address hash value
  161. */
  162. void atl1e_hash_set(struct atl1e_hw *hw, u32 hash_value)
  163. {
  164. u32 hash_bit, hash_reg;
  165. u32 mta;
  166. /*
  167. * The HASH Table is a register array of 2 32-bit registers.
  168. * It is treated like an array of 64 bits. We want to set
  169. * bit BitArray[hash_value]. So we figure out what register
  170. * the bit is in, read it, OR in the new bit, then write
  171. * back the new value. The register is determined by the
  172. * upper 7 bits of the hash value and the bit within that
  173. * register are determined by the lower 5 bits of the value.
  174. */
  175. hash_reg = (hash_value >> 31) & 0x1;
  176. hash_bit = (hash_value >> 26) & 0x1F;
  177. mta = AT_READ_REG_ARRAY(hw, REG_RX_HASH_TABLE, hash_reg);
  178. mta |= (1 << hash_bit);
  179. AT_WRITE_REG_ARRAY(hw, REG_RX_HASH_TABLE, hash_reg, mta);
  180. }
  181. /*
  182. * Reads the value from a PHY register
  183. * hw - Struct containing variables accessed by shared code
  184. * reg_addr - address of the PHY register to read
  185. */
  186. int atl1e_read_phy_reg(struct atl1e_hw *hw, u16 reg_addr, u16 *phy_data)
  187. {
  188. u32 val;
  189. int i;
  190. val = ((u32)(reg_addr & MDIO_REG_ADDR_MASK)) << MDIO_REG_ADDR_SHIFT |
  191. MDIO_START | MDIO_SUP_PREAMBLE | MDIO_RW |
  192. MDIO_CLK_25_4 << MDIO_CLK_SEL_SHIFT;
  193. AT_WRITE_REG(hw, REG_MDIO_CTRL, val);
  194. wmb();
  195. for (i = 0; i < MDIO_WAIT_TIMES; i++) {
  196. udelay(2);
  197. val = AT_READ_REG(hw, REG_MDIO_CTRL);
  198. if (!(val & (MDIO_START | MDIO_BUSY)))
  199. break;
  200. wmb();
  201. }
  202. if (!(val & (MDIO_START | MDIO_BUSY))) {
  203. *phy_data = (u16)val;
  204. return 0;
  205. }
  206. return AT_ERR_PHY;
  207. }
  208. /*
  209. * Writes a value to a PHY register
  210. * hw - Struct containing variables accessed by shared code
  211. * reg_addr - address of the PHY register to write
  212. * data - data to write to the PHY
  213. */
  214. int atl1e_write_phy_reg(struct atl1e_hw *hw, u32 reg_addr, u16 phy_data)
  215. {
  216. int i;
  217. u32 val;
  218. val = ((u32)(phy_data & MDIO_DATA_MASK)) << MDIO_DATA_SHIFT |
  219. (reg_addr&MDIO_REG_ADDR_MASK) << MDIO_REG_ADDR_SHIFT |
  220. MDIO_SUP_PREAMBLE |
  221. MDIO_START |
  222. MDIO_CLK_25_4 << MDIO_CLK_SEL_SHIFT;
  223. AT_WRITE_REG(hw, REG_MDIO_CTRL, val);
  224. wmb();
  225. for (i = 0; i < MDIO_WAIT_TIMES; i++) {
  226. udelay(2);
  227. val = AT_READ_REG(hw, REG_MDIO_CTRL);
  228. if (!(val & (MDIO_START | MDIO_BUSY)))
  229. break;
  230. wmb();
  231. }
  232. if (!(val & (MDIO_START | MDIO_BUSY)))
  233. return 0;
  234. return AT_ERR_PHY;
  235. }
  236. /*
  237. * atl1e_init_pcie - init PCIE module
  238. */
  239. static void atl1e_init_pcie(struct atl1e_hw *hw)
  240. {
  241. u32 value;
  242. /* comment 2lines below to save more power when sususpend
  243. value = LTSSM_TEST_MODE_DEF;
  244. AT_WRITE_REG(hw, REG_LTSSM_TEST_MODE, value);
  245. */
  246. /* pcie flow control mode change */
  247. value = AT_READ_REG(hw, 0x1008);
  248. value |= 0x8000;
  249. AT_WRITE_REG(hw, 0x1008, value);
  250. }
  251. /*
  252. * Configures PHY autoneg and flow control advertisement settings
  253. *
  254. * hw - Struct containing variables accessed by shared code
  255. */
  256. static int atl1e_phy_setup_autoneg_adv(struct atl1e_hw *hw)
  257. {
  258. s32 ret_val;
  259. u16 mii_autoneg_adv_reg;
  260. u16 mii_1000t_ctrl_reg;
  261. if (0 != hw->mii_autoneg_adv_reg)
  262. return 0;
  263. /* Read the MII Auto-Neg Advertisement Register (Address 4/9). */
  264. mii_autoneg_adv_reg = MII_AR_DEFAULT_CAP_MASK;
  265. mii_1000t_ctrl_reg = MII_AT001_CR_1000T_DEFAULT_CAP_MASK;
  266. /*
  267. * Need to parse autoneg_advertised and set up
  268. * the appropriate PHY registers. First we will parse for
  269. * autoneg_advertised software override. Since we can advertise
  270. * a plethora of combinations, we need to check each bit
  271. * individually.
  272. */
  273. /*
  274. * First we clear all the 10/100 mb speed bits in the Auto-Neg
  275. * Advertisement Register (Address 4) and the 1000 mb speed bits in
  276. * the 1000Base-T control Register (Address 9).
  277. */
  278. mii_autoneg_adv_reg &= ~ADVERTISE_ALL;
  279. mii_1000t_ctrl_reg &= ~MII_AT001_CR_1000T_SPEED_MASK;
  280. /*
  281. * Need to parse MediaType and setup the
  282. * appropriate PHY registers.
  283. */
  284. switch (hw->media_type) {
  285. case MEDIA_TYPE_AUTO_SENSOR:
  286. mii_autoneg_adv_reg |= ADVERTISE_ALL;
  287. hw->autoneg_advertised = ADVERTISE_ALL;
  288. if (hw->nic_type == athr_l1e) {
  289. mii_1000t_ctrl_reg |= ADVERTISE_1000FULL;
  290. hw->autoneg_advertised |= ADVERTISE_1000_FULL;
  291. }
  292. break;
  293. case MEDIA_TYPE_100M_FULL:
  294. mii_autoneg_adv_reg |= ADVERTISE_100FULL;
  295. hw->autoneg_advertised = ADVERTISE_100_FULL;
  296. break;
  297. case MEDIA_TYPE_100M_HALF:
  298. mii_autoneg_adv_reg |= ADVERTISE_100_HALF;
  299. hw->autoneg_advertised = ADVERTISE_100_HALF;
  300. break;
  301. case MEDIA_TYPE_10M_FULL:
  302. mii_autoneg_adv_reg |= ADVERTISE_10_FULL;
  303. hw->autoneg_advertised = ADVERTISE_10_FULL;
  304. break;
  305. default:
  306. mii_autoneg_adv_reg |= ADVERTISE_10_HALF;
  307. hw->autoneg_advertised = ADVERTISE_10_HALF;
  308. break;
  309. }
  310. /* flow control fixed to enable all */
  311. mii_autoneg_adv_reg |= (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP);
  312. hw->mii_autoneg_adv_reg = mii_autoneg_adv_reg;
  313. hw->mii_1000t_ctrl_reg = mii_1000t_ctrl_reg;
  314. ret_val = atl1e_write_phy_reg(hw, MII_ADVERTISE, mii_autoneg_adv_reg);
  315. if (ret_val)
  316. return ret_val;
  317. if (hw->nic_type == athr_l1e || hw->nic_type == athr_l2e_revA) {
  318. ret_val = atl1e_write_phy_reg(hw, MII_CTRL1000,
  319. mii_1000t_ctrl_reg);
  320. if (ret_val)
  321. return ret_val;
  322. }
  323. return 0;
  324. }
  325. /*
  326. * Resets the PHY and make all config validate
  327. *
  328. * hw - Struct containing variables accessed by shared code
  329. *
  330. * Sets bit 15 and 12 of the MII control regiser (for F001 bug)
  331. */
  332. int atl1e_phy_commit(struct atl1e_hw *hw)
  333. {
  334. struct atl1e_adapter *adapter = hw->adapter;
  335. int ret_val;
  336. u16 phy_data;
  337. phy_data = BMCR_RESET | BMCR_ANENABLE | BMCR_ANRESTART;
  338. ret_val = atl1e_write_phy_reg(hw, MII_BMCR, phy_data);
  339. if (ret_val) {
  340. u32 val;
  341. int i;
  342. /**************************************
  343. * pcie serdes link may be down !
  344. **************************************/
  345. for (i = 0; i < 25; i++) {
  346. msleep(1);
  347. val = AT_READ_REG(hw, REG_MDIO_CTRL);
  348. if (!(val & (MDIO_START | MDIO_BUSY)))
  349. break;
  350. }
  351. if (0 != (val & (MDIO_START | MDIO_BUSY))) {
  352. netdev_err(adapter->netdev,
  353. "pcie linkdown at least for 25ms\n");
  354. return ret_val;
  355. }
  356. netdev_err(adapter->netdev, "pcie linkup after %d ms\n", i);
  357. }
  358. return 0;
  359. }
  360. int atl1e_phy_init(struct atl1e_hw *hw)
  361. {
  362. struct atl1e_adapter *adapter = hw->adapter;
  363. s32 ret_val;
  364. u16 phy_val;
  365. if (hw->phy_configured) {
  366. if (hw->re_autoneg) {
  367. hw->re_autoneg = false;
  368. return atl1e_restart_autoneg(hw);
  369. }
  370. return 0;
  371. }
  372. /* RESET GPHY Core */
  373. AT_WRITE_REGW(hw, REG_GPHY_CTRL, GPHY_CTRL_DEFAULT);
  374. msleep(2);
  375. AT_WRITE_REGW(hw, REG_GPHY_CTRL, GPHY_CTRL_DEFAULT |
  376. GPHY_CTRL_EXT_RESET);
  377. msleep(2);
  378. /* patches */
  379. /* p1. eable hibernation mode */
  380. ret_val = atl1e_write_phy_reg(hw, MII_DBG_ADDR, 0xB);
  381. if (ret_val)
  382. return ret_val;
  383. ret_val = atl1e_write_phy_reg(hw, MII_DBG_DATA, 0xBC00);
  384. if (ret_val)
  385. return ret_val;
  386. /* p2. set Class A/B for all modes */
  387. ret_val = atl1e_write_phy_reg(hw, MII_DBG_ADDR, 0);
  388. if (ret_val)
  389. return ret_val;
  390. phy_val = 0x02ef;
  391. /* remove Class AB */
  392. /* phy_val = hw->emi_ca ? 0x02ef : 0x02df; */
  393. ret_val = atl1e_write_phy_reg(hw, MII_DBG_DATA, phy_val);
  394. if (ret_val)
  395. return ret_val;
  396. /* p3. 10B ??? */
  397. ret_val = atl1e_write_phy_reg(hw, MII_DBG_ADDR, 0x12);
  398. if (ret_val)
  399. return ret_val;
  400. ret_val = atl1e_write_phy_reg(hw, MII_DBG_DATA, 0x4C04);
  401. if (ret_val)
  402. return ret_val;
  403. /* p4. 1000T power */
  404. ret_val = atl1e_write_phy_reg(hw, MII_DBG_ADDR, 0x4);
  405. if (ret_val)
  406. return ret_val;
  407. ret_val = atl1e_write_phy_reg(hw, MII_DBG_DATA, 0x8BBB);
  408. if (ret_val)
  409. return ret_val;
  410. ret_val = atl1e_write_phy_reg(hw, MII_DBG_ADDR, 0x5);
  411. if (ret_val)
  412. return ret_val;
  413. ret_val = atl1e_write_phy_reg(hw, MII_DBG_DATA, 0x2C46);
  414. if (ret_val)
  415. return ret_val;
  416. msleep(1);
  417. /*Enable PHY LinkChange Interrupt */
  418. ret_val = atl1e_write_phy_reg(hw, MII_INT_CTRL, 0xC00);
  419. if (ret_val) {
  420. netdev_err(adapter->netdev,
  421. "Error enable PHY linkChange Interrupt\n");
  422. return ret_val;
  423. }
  424. /* setup AutoNeg parameters */
  425. ret_val = atl1e_phy_setup_autoneg_adv(hw);
  426. if (ret_val) {
  427. netdev_err(adapter->netdev,
  428. "Error Setting up Auto-Negotiation\n");
  429. return ret_val;
  430. }
  431. /* SW.Reset & En-Auto-Neg to restart Auto-Neg*/
  432. netdev_dbg(adapter->netdev, "Restarting Auto-Negotiation\n");
  433. ret_val = atl1e_phy_commit(hw);
  434. if (ret_val) {
  435. netdev_err(adapter->netdev, "Error resetting the phy\n");
  436. return ret_val;
  437. }
  438. hw->phy_configured = true;
  439. return 0;
  440. }
  441. /*
  442. * Reset the transmit and receive units; mask and clear all interrupts.
  443. * hw - Struct containing variables accessed by shared code
  444. * return : 0 or idle status (if error)
  445. */
  446. int atl1e_reset_hw(struct atl1e_hw *hw)
  447. {
  448. struct atl1e_adapter *adapter = hw->adapter;
  449. struct pci_dev *pdev = adapter->pdev;
  450. u32 idle_status_data = 0;
  451. u16 pci_cfg_cmd_word = 0;
  452. int timeout = 0;
  453. /* Workaround for PCI problem when BIOS sets MMRBC incorrectly. */
  454. pci_read_config_word(pdev, PCI_REG_COMMAND, &pci_cfg_cmd_word);
  455. if ((pci_cfg_cmd_word & (CMD_IO_SPACE |
  456. CMD_MEMORY_SPACE | CMD_BUS_MASTER))
  457. != (CMD_IO_SPACE | CMD_MEMORY_SPACE | CMD_BUS_MASTER)) {
  458. pci_cfg_cmd_word |= (CMD_IO_SPACE |
  459. CMD_MEMORY_SPACE | CMD_BUS_MASTER);
  460. pci_write_config_word(pdev, PCI_REG_COMMAND, pci_cfg_cmd_word);
  461. }
  462. /*
  463. * Issue Soft Reset to the MAC. This will reset the chip's
  464. * transmit, receive, DMA. It will not effect
  465. * the current PCI configuration. The global reset bit is self-
  466. * clearing, and should clear within a microsecond.
  467. */
  468. AT_WRITE_REG(hw, REG_MASTER_CTRL,
  469. MASTER_CTRL_LED_MODE | MASTER_CTRL_SOFT_RST);
  470. wmb();
  471. msleep(1);
  472. /* Wait at least 10ms for All module to be Idle */
  473. for (timeout = 0; timeout < AT_HW_MAX_IDLE_DELAY; timeout++) {
  474. idle_status_data = AT_READ_REG(hw, REG_IDLE_STATUS);
  475. if (idle_status_data == 0)
  476. break;
  477. msleep(1);
  478. cpu_relax();
  479. }
  480. if (timeout >= AT_HW_MAX_IDLE_DELAY) {
  481. netdev_err(adapter->netdev,
  482. "MAC state machine can't be idle since disabled for 10ms second\n");
  483. return AT_ERR_TIMEOUT;
  484. }
  485. return 0;
  486. }
  487. /*
  488. * Performs basic configuration of the adapter.
  489. *
  490. * hw - Struct containing variables accessed by shared code
  491. * Assumes that the controller has previously been reset and is in a
  492. * post-reset uninitialized state. Initializes multicast table,
  493. * and Calls routines to setup link
  494. * Leaves the transmit and receive units disabled and uninitialized.
  495. */
  496. int atl1e_init_hw(struct atl1e_hw *hw)
  497. {
  498. s32 ret_val = 0;
  499. atl1e_init_pcie(hw);
  500. /* Zero out the Multicast HASH table */
  501. /* clear the old settings from the multicast hash table */
  502. AT_WRITE_REG(hw, REG_RX_HASH_TABLE, 0);
  503. AT_WRITE_REG_ARRAY(hw, REG_RX_HASH_TABLE, 1, 0);
  504. ret_val = atl1e_phy_init(hw);
  505. return ret_val;
  506. }
  507. /*
  508. * Detects the current speed and duplex settings of the hardware.
  509. *
  510. * hw - Struct containing variables accessed by shared code
  511. * speed - Speed of the connection
  512. * duplex - Duplex setting of the connection
  513. */
  514. int atl1e_get_speed_and_duplex(struct atl1e_hw *hw, u16 *speed, u16 *duplex)
  515. {
  516. int err;
  517. u16 phy_data;
  518. /* Read PHY Specific Status Register (17) */
  519. err = atl1e_read_phy_reg(hw, MII_AT001_PSSR, &phy_data);
  520. if (err)
  521. return err;
  522. if (!(phy_data & MII_AT001_PSSR_SPD_DPLX_RESOLVED))
  523. return AT_ERR_PHY_RES;
  524. switch (phy_data & MII_AT001_PSSR_SPEED) {
  525. case MII_AT001_PSSR_1000MBS:
  526. *speed = SPEED_1000;
  527. break;
  528. case MII_AT001_PSSR_100MBS:
  529. *speed = SPEED_100;
  530. break;
  531. case MII_AT001_PSSR_10MBS:
  532. *speed = SPEED_10;
  533. break;
  534. default:
  535. return AT_ERR_PHY_SPEED;
  536. }
  537. if (phy_data & MII_AT001_PSSR_DPLX)
  538. *duplex = FULL_DUPLEX;
  539. else
  540. *duplex = HALF_DUPLEX;
  541. return 0;
  542. }
  543. int atl1e_restart_autoneg(struct atl1e_hw *hw)
  544. {
  545. int err = 0;
  546. err = atl1e_write_phy_reg(hw, MII_ADVERTISE, hw->mii_autoneg_adv_reg);
  547. if (err)
  548. return err;
  549. if (hw->nic_type == athr_l1e || hw->nic_type == athr_l2e_revA) {
  550. err = atl1e_write_phy_reg(hw, MII_CTRL1000,
  551. hw->mii_1000t_ctrl_reg);
  552. if (err)
  553. return err;
  554. }
  555. err = atl1e_write_phy_reg(hw, MII_BMCR,
  556. BMCR_RESET | BMCR_ANENABLE | BMCR_ANRESTART);
  557. return err;
  558. }