atl1c_hw.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586
  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 "atl1c.h"
  26. /*
  27. * check_eeprom_exist
  28. * return 1 if eeprom exist
  29. */
  30. int atl1c_check_eeprom_exist(struct atl1c_hw *hw)
  31. {
  32. u32 data;
  33. AT_READ_REG(hw, REG_TWSI_DEBUG, &data);
  34. if (data & TWSI_DEBUG_DEV_EXIST)
  35. return 1;
  36. return 0;
  37. }
  38. void atl1c_hw_set_mac_addr(struct atl1c_hw *hw)
  39. {
  40. u32 value;
  41. /*
  42. * 00-0B-6A-F6-00-DC
  43. * 0: 6AF600DC 1: 000B
  44. * low dword
  45. */
  46. value = (((u32)hw->mac_addr[2]) << 24) |
  47. (((u32)hw->mac_addr[3]) << 16) |
  48. (((u32)hw->mac_addr[4]) << 8) |
  49. (((u32)hw->mac_addr[5])) ;
  50. AT_WRITE_REG_ARRAY(hw, REG_MAC_STA_ADDR, 0, value);
  51. /* hight dword */
  52. value = (((u32)hw->mac_addr[0]) << 8) |
  53. (((u32)hw->mac_addr[1])) ;
  54. AT_WRITE_REG_ARRAY(hw, REG_MAC_STA_ADDR, 1, value);
  55. }
  56. /*
  57. * atl1c_get_permanent_address
  58. * return 0 if get valid mac address,
  59. */
  60. static int atl1c_get_permanent_address(struct atl1c_hw *hw)
  61. {
  62. u32 addr[2];
  63. u32 i;
  64. u32 otp_ctrl_data;
  65. u32 twsi_ctrl_data;
  66. u8 eth_addr[ETH_ALEN];
  67. u16 phy_data;
  68. bool raise_vol = false;
  69. /* init */
  70. addr[0] = addr[1] = 0;
  71. AT_READ_REG(hw, REG_OTP_CTRL, &otp_ctrl_data);
  72. if (atl1c_check_eeprom_exist(hw)) {
  73. if (hw->nic_type == athr_l1c || hw->nic_type == athr_l2c_b) {
  74. /* Enable OTP CLK */
  75. if (!(otp_ctrl_data & OTP_CTRL_CLK_EN)) {
  76. otp_ctrl_data |= OTP_CTRL_CLK_EN;
  77. AT_WRITE_REG(hw, REG_OTP_CTRL, otp_ctrl_data);
  78. AT_WRITE_FLUSH(hw);
  79. msleep(1);
  80. }
  81. }
  82. if (hw->nic_type == athr_l2c_b ||
  83. hw->nic_type == athr_l2c_b2 ||
  84. hw->nic_type == athr_l1d) {
  85. atl1c_write_phy_reg(hw, MII_DBG_ADDR, 0x00);
  86. if (atl1c_read_phy_reg(hw, MII_DBG_DATA, &phy_data))
  87. goto out;
  88. phy_data &= 0xFF7F;
  89. atl1c_write_phy_reg(hw, MII_DBG_DATA, phy_data);
  90. atl1c_write_phy_reg(hw, MII_DBG_ADDR, 0x3B);
  91. if (atl1c_read_phy_reg(hw, MII_DBG_DATA, &phy_data))
  92. goto out;
  93. phy_data |= 0x8;
  94. atl1c_write_phy_reg(hw, MII_DBG_DATA, phy_data);
  95. udelay(20);
  96. raise_vol = true;
  97. }
  98. AT_READ_REG(hw, REG_TWSI_CTRL, &twsi_ctrl_data);
  99. twsi_ctrl_data |= TWSI_CTRL_SW_LDSTART;
  100. AT_WRITE_REG(hw, REG_TWSI_CTRL, twsi_ctrl_data);
  101. for (i = 0; i < AT_TWSI_EEPROM_TIMEOUT; i++) {
  102. msleep(10);
  103. AT_READ_REG(hw, REG_TWSI_CTRL, &twsi_ctrl_data);
  104. if ((twsi_ctrl_data & TWSI_CTRL_SW_LDSTART) == 0)
  105. break;
  106. }
  107. if (i >= AT_TWSI_EEPROM_TIMEOUT)
  108. return -1;
  109. }
  110. /* Disable OTP_CLK */
  111. if ((hw->nic_type == athr_l1c || hw->nic_type == athr_l2c)) {
  112. if (otp_ctrl_data & OTP_CTRL_CLK_EN) {
  113. otp_ctrl_data &= ~OTP_CTRL_CLK_EN;
  114. AT_WRITE_REG(hw, REG_OTP_CTRL, otp_ctrl_data);
  115. AT_WRITE_FLUSH(hw);
  116. msleep(1);
  117. }
  118. }
  119. if (raise_vol) {
  120. if (hw->nic_type == athr_l2c_b ||
  121. hw->nic_type == athr_l2c_b2 ||
  122. hw->nic_type == athr_l1d) {
  123. atl1c_write_phy_reg(hw, MII_DBG_ADDR, 0x00);
  124. if (atl1c_read_phy_reg(hw, MII_DBG_DATA, &phy_data))
  125. goto out;
  126. phy_data |= 0x80;
  127. atl1c_write_phy_reg(hw, MII_DBG_DATA, phy_data);
  128. atl1c_write_phy_reg(hw, MII_DBG_ADDR, 0x3B);
  129. if (atl1c_read_phy_reg(hw, MII_DBG_DATA, &phy_data))
  130. goto out;
  131. phy_data &= 0xFFF7;
  132. atl1c_write_phy_reg(hw, MII_DBG_DATA, phy_data);
  133. udelay(20);
  134. }
  135. }
  136. /* maybe MAC-address is from BIOS */
  137. AT_READ_REG(hw, REG_MAC_STA_ADDR, &addr[0]);
  138. AT_READ_REG(hw, REG_MAC_STA_ADDR + 4, &addr[1]);
  139. *(u32 *) &eth_addr[2] = swab32(addr[0]);
  140. *(u16 *) &eth_addr[0] = swab16(*(u16 *)&addr[1]);
  141. if (is_valid_ether_addr(eth_addr)) {
  142. memcpy(hw->perm_mac_addr, eth_addr, ETH_ALEN);
  143. return 0;
  144. }
  145. out:
  146. return -1;
  147. }
  148. bool atl1c_read_eeprom(struct atl1c_hw *hw, u32 offset, u32 *p_value)
  149. {
  150. int i;
  151. int ret = false;
  152. u32 otp_ctrl_data;
  153. u32 control;
  154. u32 data;
  155. if (offset & 3)
  156. return ret; /* address do not align */
  157. AT_READ_REG(hw, REG_OTP_CTRL, &otp_ctrl_data);
  158. if (!(otp_ctrl_data & OTP_CTRL_CLK_EN))
  159. AT_WRITE_REG(hw, REG_OTP_CTRL,
  160. (otp_ctrl_data | OTP_CTRL_CLK_EN));
  161. AT_WRITE_REG(hw, REG_EEPROM_DATA_LO, 0);
  162. control = (offset & EEPROM_CTRL_ADDR_MASK) << EEPROM_CTRL_ADDR_SHIFT;
  163. AT_WRITE_REG(hw, REG_EEPROM_CTRL, control);
  164. for (i = 0; i < 10; i++) {
  165. udelay(100);
  166. AT_READ_REG(hw, REG_EEPROM_CTRL, &control);
  167. if (control & EEPROM_CTRL_RW)
  168. break;
  169. }
  170. if (control & EEPROM_CTRL_RW) {
  171. AT_READ_REG(hw, REG_EEPROM_CTRL, &data);
  172. AT_READ_REG(hw, REG_EEPROM_DATA_LO, p_value);
  173. data = data & 0xFFFF;
  174. *p_value = swab32((data << 16) | (*p_value >> 16));
  175. ret = true;
  176. }
  177. if (!(otp_ctrl_data & OTP_CTRL_CLK_EN))
  178. AT_WRITE_REG(hw, REG_OTP_CTRL, otp_ctrl_data);
  179. return ret;
  180. }
  181. /*
  182. * Reads the adapter's MAC address from the EEPROM
  183. *
  184. * hw - Struct containing variables accessed by shared code
  185. */
  186. int atl1c_read_mac_addr(struct atl1c_hw *hw)
  187. {
  188. int err = 0;
  189. err = atl1c_get_permanent_address(hw);
  190. if (err)
  191. random_ether_addr(hw->perm_mac_addr);
  192. memcpy(hw->mac_addr, hw->perm_mac_addr, sizeof(hw->perm_mac_addr));
  193. return 0;
  194. }
  195. /*
  196. * atl1c_hash_mc_addr
  197. * purpose
  198. * set hash value for a multicast address
  199. * hash calcu processing :
  200. * 1. calcu 32bit CRC for multicast address
  201. * 2. reverse crc with MSB to LSB
  202. */
  203. u32 atl1c_hash_mc_addr(struct atl1c_hw *hw, u8 *mc_addr)
  204. {
  205. u32 crc32;
  206. u32 value = 0;
  207. int i;
  208. crc32 = ether_crc_le(6, mc_addr);
  209. for (i = 0; i < 32; i++)
  210. value |= (((crc32 >> i) & 1) << (31 - i));
  211. return value;
  212. }
  213. /*
  214. * Sets the bit in the multicast table corresponding to the hash value.
  215. * hw - Struct containing variables accessed by shared code
  216. * hash_value - Multicast address hash value
  217. */
  218. void atl1c_hash_set(struct atl1c_hw *hw, u32 hash_value)
  219. {
  220. u32 hash_bit, hash_reg;
  221. u32 mta;
  222. /*
  223. * The HASH Table is a register array of 2 32-bit registers.
  224. * It is treated like an array of 64 bits. We want to set
  225. * bit BitArray[hash_value]. So we figure out what register
  226. * the bit is in, read it, OR in the new bit, then write
  227. * back the new value. The register is determined by the
  228. * upper bit of the hash value and the bit within that
  229. * register are determined by the lower 5 bits of the value.
  230. */
  231. hash_reg = (hash_value >> 31) & 0x1;
  232. hash_bit = (hash_value >> 26) & 0x1F;
  233. mta = AT_READ_REG_ARRAY(hw, REG_RX_HASH_TABLE, hash_reg);
  234. mta |= (1 << hash_bit);
  235. AT_WRITE_REG_ARRAY(hw, REG_RX_HASH_TABLE, hash_reg, mta);
  236. }
  237. /*
  238. * Reads the value from a PHY register
  239. * hw - Struct containing variables accessed by shared code
  240. * reg_addr - address of the PHY register to read
  241. */
  242. int atl1c_read_phy_reg(struct atl1c_hw *hw, u16 reg_addr, u16 *phy_data)
  243. {
  244. u32 val;
  245. int i;
  246. val = ((u32)(reg_addr & MDIO_REG_ADDR_MASK)) << MDIO_REG_ADDR_SHIFT |
  247. MDIO_START | MDIO_SUP_PREAMBLE | MDIO_RW |
  248. MDIO_CLK_25_4 << MDIO_CLK_SEL_SHIFT;
  249. AT_WRITE_REG(hw, REG_MDIO_CTRL, val);
  250. for (i = 0; i < MDIO_WAIT_TIMES; i++) {
  251. udelay(2);
  252. AT_READ_REG(hw, REG_MDIO_CTRL, &val);
  253. if (!(val & (MDIO_START | MDIO_BUSY)))
  254. break;
  255. }
  256. if (!(val & (MDIO_START | MDIO_BUSY))) {
  257. *phy_data = (u16)val;
  258. return 0;
  259. }
  260. return -1;
  261. }
  262. /*
  263. * Writes a value to a PHY register
  264. * hw - Struct containing variables accessed by shared code
  265. * reg_addr - address of the PHY register to write
  266. * data - data to write to the PHY
  267. */
  268. int atl1c_write_phy_reg(struct atl1c_hw *hw, u32 reg_addr, u16 phy_data)
  269. {
  270. int i;
  271. u32 val;
  272. val = ((u32)(phy_data & MDIO_DATA_MASK)) << MDIO_DATA_SHIFT |
  273. (reg_addr & MDIO_REG_ADDR_MASK) << MDIO_REG_ADDR_SHIFT |
  274. MDIO_SUP_PREAMBLE | MDIO_START |
  275. MDIO_CLK_25_4 << MDIO_CLK_SEL_SHIFT;
  276. AT_WRITE_REG(hw, REG_MDIO_CTRL, val);
  277. for (i = 0; i < MDIO_WAIT_TIMES; i++) {
  278. udelay(2);
  279. AT_READ_REG(hw, REG_MDIO_CTRL, &val);
  280. if (!(val & (MDIO_START | MDIO_BUSY)))
  281. break;
  282. }
  283. if (!(val & (MDIO_START | MDIO_BUSY)))
  284. return 0;
  285. return -1;
  286. }
  287. /*
  288. * Configures PHY autoneg and flow control advertisement settings
  289. *
  290. * hw - Struct containing variables accessed by shared code
  291. */
  292. static int atl1c_phy_setup_adv(struct atl1c_hw *hw)
  293. {
  294. u16 mii_adv_data = ADVERTISE_DEFAULT_CAP & ~ADVERTISE_SPEED_MASK;
  295. u16 mii_giga_ctrl_data = GIGA_CR_1000T_DEFAULT_CAP &
  296. ~GIGA_CR_1000T_SPEED_MASK;
  297. if (hw->autoneg_advertised & ADVERTISED_10baseT_Half)
  298. mii_adv_data |= ADVERTISE_10HALF;
  299. if (hw->autoneg_advertised & ADVERTISED_10baseT_Full)
  300. mii_adv_data |= ADVERTISE_10FULL;
  301. if (hw->autoneg_advertised & ADVERTISED_100baseT_Half)
  302. mii_adv_data |= ADVERTISE_100HALF;
  303. if (hw->autoneg_advertised & ADVERTISED_100baseT_Full)
  304. mii_adv_data |= ADVERTISE_100FULL;
  305. if (hw->autoneg_advertised & ADVERTISED_Autoneg)
  306. mii_adv_data |= ADVERTISE_10HALF | ADVERTISE_10FULL |
  307. ADVERTISE_100HALF | ADVERTISE_100FULL;
  308. if (hw->link_cap_flags & ATL1C_LINK_CAP_1000M) {
  309. if (hw->autoneg_advertised & ADVERTISED_1000baseT_Half)
  310. mii_giga_ctrl_data |= ADVERTISE_1000HALF;
  311. if (hw->autoneg_advertised & ADVERTISED_1000baseT_Full)
  312. mii_giga_ctrl_data |= ADVERTISE_1000FULL;
  313. if (hw->autoneg_advertised & ADVERTISED_Autoneg)
  314. mii_giga_ctrl_data |= ADVERTISE_1000HALF |
  315. ADVERTISE_1000FULL;
  316. }
  317. if (atl1c_write_phy_reg(hw, MII_ADVERTISE, mii_adv_data) != 0 ||
  318. atl1c_write_phy_reg(hw, MII_GIGA_CR, mii_giga_ctrl_data) != 0)
  319. return -1;
  320. return 0;
  321. }
  322. void atl1c_phy_disable(struct atl1c_hw *hw)
  323. {
  324. AT_WRITE_REGW(hw, REG_GPHY_CTRL,
  325. GPHY_CTRL_PW_WOL_DIS | GPHY_CTRL_EXT_RESET);
  326. }
  327. static void atl1c_phy_magic_data(struct atl1c_hw *hw)
  328. {
  329. u16 data;
  330. data = ANA_LOOP_SEL_10BT | ANA_EN_MASK_TB | ANA_EN_10BT_IDLE |
  331. ((1 & ANA_INTERVAL_SEL_TIMER_MASK) <<
  332. ANA_INTERVAL_SEL_TIMER_SHIFT);
  333. atl1c_write_phy_reg(hw, MII_DBG_ADDR, MII_ANA_CTRL_18);
  334. atl1c_write_phy_reg(hw, MII_DBG_DATA, data);
  335. data = (2 & ANA_SERDES_CDR_BW_MASK) | ANA_MS_PAD_DBG |
  336. ANA_SERDES_EN_DEEM | ANA_SERDES_SEL_HSP | ANA_SERDES_EN_PLL |
  337. ANA_SERDES_EN_LCKDT;
  338. atl1c_write_phy_reg(hw, MII_DBG_ADDR, MII_ANA_CTRL_5);
  339. atl1c_write_phy_reg(hw, MII_DBG_DATA, data);
  340. data = (44 & ANA_LONG_CABLE_TH_100_MASK) |
  341. ((33 & ANA_SHORT_CABLE_TH_100_MASK) <<
  342. ANA_SHORT_CABLE_TH_100_SHIFT) | ANA_BP_BAD_LINK_ACCUM |
  343. ANA_BP_SMALL_BW;
  344. atl1c_write_phy_reg(hw, MII_DBG_ADDR, MII_ANA_CTRL_54);
  345. atl1c_write_phy_reg(hw, MII_DBG_DATA, data);
  346. data = (11 & ANA_IECHO_ADJ_MASK) | ((11 & ANA_IECHO_ADJ_MASK) <<
  347. ANA_IECHO_ADJ_2_SHIFT) | ((8 & ANA_IECHO_ADJ_MASK) <<
  348. ANA_IECHO_ADJ_1_SHIFT) | ((8 & ANA_IECHO_ADJ_MASK) <<
  349. ANA_IECHO_ADJ_0_SHIFT);
  350. atl1c_write_phy_reg(hw, MII_DBG_ADDR, MII_ANA_CTRL_4);
  351. atl1c_write_phy_reg(hw, MII_DBG_DATA, data);
  352. data = ANA_RESTART_CAL | ((7 & ANA_MANUL_SWICH_ON_MASK) <<
  353. ANA_MANUL_SWICH_ON_SHIFT) | ANA_MAN_ENABLE |
  354. ANA_SEL_HSP | ANA_EN_HB | ANA_OEN_125M;
  355. atl1c_write_phy_reg(hw, MII_DBG_ADDR, MII_ANA_CTRL_0);
  356. atl1c_write_phy_reg(hw, MII_DBG_DATA, data);
  357. if (hw->ctrl_flags & ATL1C_HIB_DISABLE) {
  358. atl1c_write_phy_reg(hw, MII_DBG_ADDR, MII_ANA_CTRL_41);
  359. if (atl1c_read_phy_reg(hw, MII_DBG_DATA, &data) != 0)
  360. return;
  361. data &= ~ANA_TOP_PS_EN;
  362. atl1c_write_phy_reg(hw, MII_DBG_DATA, data);
  363. atl1c_write_phy_reg(hw, MII_DBG_ADDR, MII_ANA_CTRL_11);
  364. if (atl1c_read_phy_reg(hw, MII_DBG_DATA, &data) != 0)
  365. return;
  366. data &= ~ANA_PS_HIB_EN;
  367. atl1c_write_phy_reg(hw, MII_DBG_DATA, data);
  368. }
  369. }
  370. int atl1c_phy_reset(struct atl1c_hw *hw)
  371. {
  372. struct atl1c_adapter *adapter = hw->adapter;
  373. struct pci_dev *pdev = adapter->pdev;
  374. u16 phy_data;
  375. u32 phy_ctrl_data = GPHY_CTRL_DEFAULT;
  376. u32 mii_ier_data = IER_LINK_UP | IER_LINK_DOWN;
  377. int err;
  378. if (hw->ctrl_flags & ATL1C_HIB_DISABLE)
  379. phy_ctrl_data &= ~GPHY_CTRL_HIB_EN;
  380. AT_WRITE_REG(hw, REG_GPHY_CTRL, phy_ctrl_data);
  381. AT_WRITE_FLUSH(hw);
  382. msleep(40);
  383. phy_ctrl_data |= GPHY_CTRL_EXT_RESET;
  384. AT_WRITE_REG(hw, REG_GPHY_CTRL, phy_ctrl_data);
  385. AT_WRITE_FLUSH(hw);
  386. msleep(10);
  387. if (hw->nic_type == athr_l2c_b) {
  388. atl1c_write_phy_reg(hw, MII_DBG_ADDR, 0x0A);
  389. atl1c_read_phy_reg(hw, MII_DBG_DATA, &phy_data);
  390. atl1c_write_phy_reg(hw, MII_DBG_DATA, phy_data & 0xDFFF);
  391. }
  392. if (hw->nic_type == athr_l2c_b ||
  393. hw->nic_type == athr_l2c_b2 ||
  394. hw->nic_type == athr_l1d) {
  395. atl1c_write_phy_reg(hw, MII_DBG_ADDR, 0x3B);
  396. atl1c_read_phy_reg(hw, MII_DBG_DATA, &phy_data);
  397. atl1c_write_phy_reg(hw, MII_DBG_DATA, phy_data & 0xFFF7);
  398. msleep(20);
  399. }
  400. /*Enable PHY LinkChange Interrupt */
  401. err = atl1c_write_phy_reg(hw, MII_IER, mii_ier_data);
  402. if (err) {
  403. if (netif_msg_hw(adapter))
  404. dev_err(&pdev->dev,
  405. "Error enable PHY linkChange Interrupt\n");
  406. return err;
  407. }
  408. if (!(hw->ctrl_flags & ATL1C_FPGA_VERSION))
  409. atl1c_phy_magic_data(hw);
  410. return 0;
  411. }
  412. int atl1c_phy_init(struct atl1c_hw *hw)
  413. {
  414. struct atl1c_adapter *adapter = (struct atl1c_adapter *)hw->adapter;
  415. struct pci_dev *pdev = adapter->pdev;
  416. int ret_val;
  417. u16 mii_bmcr_data = BMCR_RESET;
  418. u16 phy_id1, phy_id2;
  419. if ((atl1c_read_phy_reg(hw, MII_PHYSID1, &phy_id1) != 0) ||
  420. (atl1c_read_phy_reg(hw, MII_PHYSID2, &phy_id2) != 0)) {
  421. if (netif_msg_link(adapter))
  422. dev_err(&pdev->dev, "Error get phy ID\n");
  423. return -1;
  424. }
  425. switch (hw->media_type) {
  426. case MEDIA_TYPE_AUTO_SENSOR:
  427. ret_val = atl1c_phy_setup_adv(hw);
  428. if (ret_val) {
  429. if (netif_msg_link(adapter))
  430. dev_err(&pdev->dev,
  431. "Error Setting up Auto-Negotiation\n");
  432. return ret_val;
  433. }
  434. mii_bmcr_data |= BMCR_AUTO_NEG_EN | BMCR_RESTART_AUTO_NEG;
  435. break;
  436. case MEDIA_TYPE_100M_FULL:
  437. mii_bmcr_data |= BMCR_SPEED_100 | BMCR_FULL_DUPLEX;
  438. break;
  439. case MEDIA_TYPE_100M_HALF:
  440. mii_bmcr_data |= BMCR_SPEED_100;
  441. break;
  442. case MEDIA_TYPE_10M_FULL:
  443. mii_bmcr_data |= BMCR_SPEED_10 | BMCR_FULL_DUPLEX;
  444. break;
  445. case MEDIA_TYPE_10M_HALF:
  446. mii_bmcr_data |= BMCR_SPEED_10;
  447. break;
  448. default:
  449. if (netif_msg_link(adapter))
  450. dev_err(&pdev->dev, "Wrong Media type %d\n",
  451. hw->media_type);
  452. return -1;
  453. break;
  454. }
  455. ret_val = atl1c_write_phy_reg(hw, MII_BMCR, mii_bmcr_data);
  456. if (ret_val)
  457. return ret_val;
  458. hw->phy_configured = true;
  459. return 0;
  460. }
  461. /*
  462. * Detects the current speed and duplex settings of the hardware.
  463. *
  464. * hw - Struct containing variables accessed by shared code
  465. * speed - Speed of the connection
  466. * duplex - Duplex setting of the connection
  467. */
  468. int atl1c_get_speed_and_duplex(struct atl1c_hw *hw, u16 *speed, u16 *duplex)
  469. {
  470. int err;
  471. u16 phy_data;
  472. /* Read PHY Specific Status Register (17) */
  473. err = atl1c_read_phy_reg(hw, MII_GIGA_PSSR, &phy_data);
  474. if (err)
  475. return err;
  476. if (!(phy_data & GIGA_PSSR_SPD_DPLX_RESOLVED))
  477. return -1;
  478. switch (phy_data & GIGA_PSSR_SPEED) {
  479. case GIGA_PSSR_1000MBS:
  480. *speed = SPEED_1000;
  481. break;
  482. case GIGA_PSSR_100MBS:
  483. *speed = SPEED_100;
  484. break;
  485. case GIGA_PSSR_10MBS:
  486. *speed = SPEED_10;
  487. break;
  488. default:
  489. return -1;
  490. break;
  491. }
  492. if (phy_data & GIGA_PSSR_DPLX)
  493. *duplex = FULL_DUPLEX;
  494. else
  495. *duplex = HALF_DUPLEX;
  496. return 0;
  497. }
  498. int atl1c_restart_autoneg(struct atl1c_hw *hw)
  499. {
  500. int err = 0;
  501. u16 mii_bmcr_data = BMCR_RESET;
  502. err = atl1c_phy_setup_adv(hw);
  503. if (err)
  504. return err;
  505. mii_bmcr_data |= BMCR_AUTO_NEG_EN | BMCR_RESTART_AUTO_NEG;
  506. return atl1c_write_phy_reg(hw, MII_BMCR, mii_bmcr_data);
  507. }