atl1e_hw.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  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 &= ~MII_AR_SPEED_MASK;
  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 |= (MII_AR_10T_HD_CAPS |
  287. MII_AR_10T_FD_CAPS |
  288. MII_AR_100TX_HD_CAPS |
  289. MII_AR_100TX_FD_CAPS);
  290. hw->autoneg_advertised = ADVERTISE_10_HALF |
  291. ADVERTISE_10_FULL |
  292. ADVERTISE_100_HALF |
  293. ADVERTISE_100_FULL;
  294. if (hw->nic_type == athr_l1e) {
  295. mii_1000t_ctrl_reg |=
  296. MII_AT001_CR_1000T_FD_CAPS;
  297. hw->autoneg_advertised |= ADVERTISE_1000_FULL;
  298. }
  299. break;
  300. case MEDIA_TYPE_100M_FULL:
  301. mii_autoneg_adv_reg |= MII_AR_100TX_FD_CAPS;
  302. hw->autoneg_advertised = ADVERTISE_100_FULL;
  303. break;
  304. case MEDIA_TYPE_100M_HALF:
  305. mii_autoneg_adv_reg |= MII_AR_100TX_HD_CAPS;
  306. hw->autoneg_advertised = ADVERTISE_100_HALF;
  307. break;
  308. case MEDIA_TYPE_10M_FULL:
  309. mii_autoneg_adv_reg |= MII_AR_10T_FD_CAPS;
  310. hw->autoneg_advertised = ADVERTISE_10_FULL;
  311. break;
  312. default:
  313. mii_autoneg_adv_reg |= MII_AR_10T_HD_CAPS;
  314. hw->autoneg_advertised = ADVERTISE_10_HALF;
  315. break;
  316. }
  317. /* flow control fixed to enable all */
  318. mii_autoneg_adv_reg |= (MII_AR_ASM_DIR | MII_AR_PAUSE);
  319. hw->mii_autoneg_adv_reg = mii_autoneg_adv_reg;
  320. hw->mii_1000t_ctrl_reg = mii_1000t_ctrl_reg;
  321. ret_val = atl1e_write_phy_reg(hw, MII_ADVERTISE, mii_autoneg_adv_reg);
  322. if (ret_val)
  323. return ret_val;
  324. if (hw->nic_type == athr_l1e || hw->nic_type == athr_l2e_revA) {
  325. ret_val = atl1e_write_phy_reg(hw, MII_AT001_CR,
  326. mii_1000t_ctrl_reg);
  327. if (ret_val)
  328. return ret_val;
  329. }
  330. return 0;
  331. }
  332. /*
  333. * Resets the PHY and make all config validate
  334. *
  335. * hw - Struct containing variables accessed by shared code
  336. *
  337. * Sets bit 15 and 12 of the MII control regiser (for F001 bug)
  338. */
  339. int atl1e_phy_commit(struct atl1e_hw *hw)
  340. {
  341. struct atl1e_adapter *adapter = hw->adapter;
  342. struct pci_dev *pdev = adapter->pdev;
  343. int ret_val;
  344. u16 phy_data;
  345. phy_data = MII_CR_RESET | MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG;
  346. ret_val = atl1e_write_phy_reg(hw, MII_BMCR, phy_data);
  347. if (ret_val) {
  348. u32 val;
  349. int i;
  350. /**************************************
  351. * pcie serdes link may be down !
  352. **************************************/
  353. for (i = 0; i < 25; i++) {
  354. msleep(1);
  355. val = AT_READ_REG(hw, REG_MDIO_CTRL);
  356. if (!(val & (MDIO_START | MDIO_BUSY)))
  357. break;
  358. }
  359. if (0 != (val & (MDIO_START | MDIO_BUSY))) {
  360. dev_err(&pdev->dev,
  361. "pcie linkdown at least for 25ms\n");
  362. return ret_val;
  363. }
  364. dev_err(&pdev->dev, "pcie linkup after %d ms\n", i);
  365. }
  366. return 0;
  367. }
  368. int atl1e_phy_init(struct atl1e_hw *hw)
  369. {
  370. struct atl1e_adapter *adapter = hw->adapter;
  371. struct pci_dev *pdev = adapter->pdev;
  372. s32 ret_val;
  373. u16 phy_val;
  374. if (hw->phy_configured) {
  375. if (hw->re_autoneg) {
  376. hw->re_autoneg = false;
  377. return atl1e_restart_autoneg(hw);
  378. }
  379. return 0;
  380. }
  381. /* RESET GPHY Core */
  382. AT_WRITE_REGW(hw, REG_GPHY_CTRL, GPHY_CTRL_DEFAULT);
  383. msleep(2);
  384. AT_WRITE_REGW(hw, REG_GPHY_CTRL, GPHY_CTRL_DEFAULT |
  385. GPHY_CTRL_EXT_RESET);
  386. msleep(2);
  387. /* patches */
  388. /* p1. eable hibernation mode */
  389. ret_val = atl1e_write_phy_reg(hw, MII_DBG_ADDR, 0xB);
  390. if (ret_val)
  391. return ret_val;
  392. ret_val = atl1e_write_phy_reg(hw, MII_DBG_DATA, 0xBC00);
  393. if (ret_val)
  394. return ret_val;
  395. /* p2. set Class A/B for all modes */
  396. ret_val = atl1e_write_phy_reg(hw, MII_DBG_ADDR, 0);
  397. if (ret_val)
  398. return ret_val;
  399. phy_val = 0x02ef;
  400. /* remove Class AB */
  401. /* phy_val = hw->emi_ca ? 0x02ef : 0x02df; */
  402. ret_val = atl1e_write_phy_reg(hw, MII_DBG_DATA, phy_val);
  403. if (ret_val)
  404. return ret_val;
  405. /* p3. 10B ??? */
  406. ret_val = atl1e_write_phy_reg(hw, MII_DBG_ADDR, 0x12);
  407. if (ret_val)
  408. return ret_val;
  409. ret_val = atl1e_write_phy_reg(hw, MII_DBG_DATA, 0x4C04);
  410. if (ret_val)
  411. return ret_val;
  412. /* p4. 1000T power */
  413. ret_val = atl1e_write_phy_reg(hw, MII_DBG_ADDR, 0x4);
  414. if (ret_val)
  415. return ret_val;
  416. ret_val = atl1e_write_phy_reg(hw, MII_DBG_DATA, 0x8BBB);
  417. if (ret_val)
  418. return ret_val;
  419. ret_val = atl1e_write_phy_reg(hw, MII_DBG_ADDR, 0x5);
  420. if (ret_val)
  421. return ret_val;
  422. ret_val = atl1e_write_phy_reg(hw, MII_DBG_DATA, 0x2C46);
  423. if (ret_val)
  424. return ret_val;
  425. msleep(1);
  426. /*Enable PHY LinkChange Interrupt */
  427. ret_val = atl1e_write_phy_reg(hw, MII_INT_CTRL, 0xC00);
  428. if (ret_val) {
  429. dev_err(&pdev->dev, "Error enable PHY linkChange Interrupt\n");
  430. return ret_val;
  431. }
  432. /* setup AutoNeg parameters */
  433. ret_val = atl1e_phy_setup_autoneg_adv(hw);
  434. if (ret_val) {
  435. dev_err(&pdev->dev, "Error Setting up Auto-Negotiation\n");
  436. return ret_val;
  437. }
  438. /* SW.Reset & En-Auto-Neg to restart Auto-Neg*/
  439. dev_dbg(&pdev->dev, "Restarting Auto-Neg");
  440. ret_val = atl1e_phy_commit(hw);
  441. if (ret_val) {
  442. dev_err(&pdev->dev, "Error Resetting the phy");
  443. return ret_val;
  444. }
  445. hw->phy_configured = true;
  446. return 0;
  447. }
  448. /*
  449. * Reset the transmit and receive units; mask and clear all interrupts.
  450. * hw - Struct containing variables accessed by shared code
  451. * return : 0 or idle status (if error)
  452. */
  453. int atl1e_reset_hw(struct atl1e_hw *hw)
  454. {
  455. struct atl1e_adapter *adapter = hw->adapter;
  456. struct pci_dev *pdev = adapter->pdev;
  457. u32 idle_status_data = 0;
  458. u16 pci_cfg_cmd_word = 0;
  459. int timeout = 0;
  460. /* Workaround for PCI problem when BIOS sets MMRBC incorrectly. */
  461. pci_read_config_word(pdev, PCI_REG_COMMAND, &pci_cfg_cmd_word);
  462. if ((pci_cfg_cmd_word & (CMD_IO_SPACE |
  463. CMD_MEMORY_SPACE | CMD_BUS_MASTER))
  464. != (CMD_IO_SPACE | CMD_MEMORY_SPACE | CMD_BUS_MASTER)) {
  465. pci_cfg_cmd_word |= (CMD_IO_SPACE |
  466. CMD_MEMORY_SPACE | CMD_BUS_MASTER);
  467. pci_write_config_word(pdev, PCI_REG_COMMAND, pci_cfg_cmd_word);
  468. }
  469. /*
  470. * Issue Soft Reset to the MAC. This will reset the chip's
  471. * transmit, receive, DMA. It will not effect
  472. * the current PCI configuration. The global reset bit is self-
  473. * clearing, and should clear within a microsecond.
  474. */
  475. AT_WRITE_REG(hw, REG_MASTER_CTRL,
  476. MASTER_CTRL_LED_MODE | MASTER_CTRL_SOFT_RST);
  477. wmb();
  478. msleep(1);
  479. /* Wait at least 10ms for All module to be Idle */
  480. for (timeout = 0; timeout < AT_HW_MAX_IDLE_DELAY; timeout++) {
  481. idle_status_data = AT_READ_REG(hw, REG_IDLE_STATUS);
  482. if (idle_status_data == 0)
  483. break;
  484. msleep(1);
  485. cpu_relax();
  486. }
  487. if (timeout >= AT_HW_MAX_IDLE_DELAY) {
  488. dev_err(&pdev->dev,
  489. "MAC state machine cann't be idle since"
  490. " disabled for 10ms second\n");
  491. return AT_ERR_TIMEOUT;
  492. }
  493. return 0;
  494. }
  495. /*
  496. * Performs basic configuration of the adapter.
  497. *
  498. * hw - Struct containing variables accessed by shared code
  499. * Assumes that the controller has previously been reset and is in a
  500. * post-reset uninitialized state. Initializes multicast table,
  501. * and Calls routines to setup link
  502. * Leaves the transmit and receive units disabled and uninitialized.
  503. */
  504. int atl1e_init_hw(struct atl1e_hw *hw)
  505. {
  506. s32 ret_val = 0;
  507. atl1e_init_pcie(hw);
  508. /* Zero out the Multicast HASH table */
  509. /* clear the old settings from the multicast hash table */
  510. AT_WRITE_REG(hw, REG_RX_HASH_TABLE, 0);
  511. AT_WRITE_REG_ARRAY(hw, REG_RX_HASH_TABLE, 1, 0);
  512. ret_val = atl1e_phy_init(hw);
  513. return ret_val;
  514. }
  515. /*
  516. * Detects the current speed and duplex settings of the hardware.
  517. *
  518. * hw - Struct containing variables accessed by shared code
  519. * speed - Speed of the connection
  520. * duplex - Duplex setting of the connection
  521. */
  522. int atl1e_get_speed_and_duplex(struct atl1e_hw *hw, u16 *speed, u16 *duplex)
  523. {
  524. int err;
  525. u16 phy_data;
  526. /* Read PHY Specific Status Register (17) */
  527. err = atl1e_read_phy_reg(hw, MII_AT001_PSSR, &phy_data);
  528. if (err)
  529. return err;
  530. if (!(phy_data & MII_AT001_PSSR_SPD_DPLX_RESOLVED))
  531. return AT_ERR_PHY_RES;
  532. switch (phy_data & MII_AT001_PSSR_SPEED) {
  533. case MII_AT001_PSSR_1000MBS:
  534. *speed = SPEED_1000;
  535. break;
  536. case MII_AT001_PSSR_100MBS:
  537. *speed = SPEED_100;
  538. break;
  539. case MII_AT001_PSSR_10MBS:
  540. *speed = SPEED_10;
  541. break;
  542. default:
  543. return AT_ERR_PHY_SPEED;
  544. break;
  545. }
  546. if (phy_data & MII_AT001_PSSR_DPLX)
  547. *duplex = FULL_DUPLEX;
  548. else
  549. *duplex = HALF_DUPLEX;
  550. return 0;
  551. }
  552. int atl1e_restart_autoneg(struct atl1e_hw *hw)
  553. {
  554. int err = 0;
  555. err = atl1e_write_phy_reg(hw, MII_ADVERTISE, hw->mii_autoneg_adv_reg);
  556. if (err)
  557. return err;
  558. if (hw->nic_type == athr_l1e || hw->nic_type == athr_l2e_revA) {
  559. err = atl1e_write_phy_reg(hw, MII_AT001_CR,
  560. hw->mii_1000t_ctrl_reg);
  561. if (err)
  562. return err;
  563. }
  564. err = atl1e_write_phy_reg(hw, MII_BMCR,
  565. MII_CR_RESET | MII_CR_AUTO_NEG_EN |
  566. MII_CR_RESTART_AUTO_NEG);
  567. return err;
  568. }