PageRenderTime 2653ms CodeModel.GetById 26ms RepoModel.GetById 87ms app.codeStats 1ms

/drivers/net/e1000e/lib.c

https://bitbucket.org/slukk/jb-tsm-kernel-4.2
C | 2692 lines | 1420 code | 329 blank | 943 comment | 272 complexity | 92b9b386eee13e3e9e05269425aa1b88 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, AGPL-1.0

Large files files are truncated, but you can click here to view the full file

  1. /*******************************************************************************
  2. Intel PRO/1000 Linux driver
  3. Copyright(c) 1999 - 2011 Intel Corporation.
  4. This program is free software; you can redistribute it and/or modify it
  5. under the terms and conditions of the GNU General Public License,
  6. version 2, as published by the Free Software Foundation.
  7. This program is distributed in the hope it will be useful, but WITHOUT
  8. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  9. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  10. more details.
  11. You should have received a copy of the GNU General Public License along with
  12. this program; if not, write to the Free Software Foundation, Inc.,
  13. 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  14. The full GNU General Public License is included in this distribution in
  15. the file called "COPYING".
  16. Contact Information:
  17. Linux NICS <linux.nics@intel.com>
  18. e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  19. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  20. *******************************************************************************/
  21. #include "e1000.h"
  22. enum e1000_mng_mode {
  23. e1000_mng_mode_none = 0,
  24. e1000_mng_mode_asf,
  25. e1000_mng_mode_pt,
  26. e1000_mng_mode_ipmi,
  27. e1000_mng_mode_host_if_only
  28. };
  29. #define E1000_FACTPS_MNGCG 0x20000000
  30. /* Intel(R) Active Management Technology signature */
  31. #define E1000_IAMT_SIGNATURE 0x544D4149
  32. /**
  33. * e1000e_get_bus_info_pcie - Get PCIe bus information
  34. * @hw: pointer to the HW structure
  35. *
  36. * Determines and stores the system bus information for a particular
  37. * network interface. The following bus information is determined and stored:
  38. * bus speed, bus width, type (PCIe), and PCIe function.
  39. **/
  40. s32 e1000e_get_bus_info_pcie(struct e1000_hw *hw)
  41. {
  42. struct e1000_mac_info *mac = &hw->mac;
  43. struct e1000_bus_info *bus = &hw->bus;
  44. struct e1000_adapter *adapter = hw->adapter;
  45. u16 pcie_link_status, cap_offset;
  46. cap_offset = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP);
  47. if (!cap_offset) {
  48. bus->width = e1000_bus_width_unknown;
  49. } else {
  50. pci_read_config_word(adapter->pdev,
  51. cap_offset + PCIE_LINK_STATUS,
  52. &pcie_link_status);
  53. bus->width = (enum e1000_bus_width)((pcie_link_status &
  54. PCIE_LINK_WIDTH_MASK) >>
  55. PCIE_LINK_WIDTH_SHIFT);
  56. }
  57. mac->ops.set_lan_id(hw);
  58. return 0;
  59. }
  60. /**
  61. * e1000_set_lan_id_multi_port_pcie - Set LAN id for PCIe multiple port devices
  62. *
  63. * @hw: pointer to the HW structure
  64. *
  65. * Determines the LAN function id by reading memory-mapped registers
  66. * and swaps the port value if requested.
  67. **/
  68. void e1000_set_lan_id_multi_port_pcie(struct e1000_hw *hw)
  69. {
  70. struct e1000_bus_info *bus = &hw->bus;
  71. u32 reg;
  72. /*
  73. * The status register reports the correct function number
  74. * for the device regardless of function swap state.
  75. */
  76. reg = er32(STATUS);
  77. bus->func = (reg & E1000_STATUS_FUNC_MASK) >> E1000_STATUS_FUNC_SHIFT;
  78. }
  79. /**
  80. * e1000_set_lan_id_single_port - Set LAN id for a single port device
  81. * @hw: pointer to the HW structure
  82. *
  83. * Sets the LAN function id to zero for a single port device.
  84. **/
  85. void e1000_set_lan_id_single_port(struct e1000_hw *hw)
  86. {
  87. struct e1000_bus_info *bus = &hw->bus;
  88. bus->func = 0;
  89. }
  90. /**
  91. * e1000_clear_vfta_generic - Clear VLAN filter table
  92. * @hw: pointer to the HW structure
  93. *
  94. * Clears the register array which contains the VLAN filter table by
  95. * setting all the values to 0.
  96. **/
  97. void e1000_clear_vfta_generic(struct e1000_hw *hw)
  98. {
  99. u32 offset;
  100. for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
  101. E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, offset, 0);
  102. e1e_flush();
  103. }
  104. }
  105. /**
  106. * e1000_write_vfta_generic - Write value to VLAN filter table
  107. * @hw: pointer to the HW structure
  108. * @offset: register offset in VLAN filter table
  109. * @value: register value written to VLAN filter table
  110. *
  111. * Writes value at the given offset in the register array which stores
  112. * the VLAN filter table.
  113. **/
  114. void e1000_write_vfta_generic(struct e1000_hw *hw, u32 offset, u32 value)
  115. {
  116. E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, offset, value);
  117. e1e_flush();
  118. }
  119. /**
  120. * e1000e_init_rx_addrs - Initialize receive address's
  121. * @hw: pointer to the HW structure
  122. * @rar_count: receive address registers
  123. *
  124. * Setup the receive address registers by setting the base receive address
  125. * register to the devices MAC address and clearing all the other receive
  126. * address registers to 0.
  127. **/
  128. void e1000e_init_rx_addrs(struct e1000_hw *hw, u16 rar_count)
  129. {
  130. u32 i;
  131. u8 mac_addr[ETH_ALEN] = {0};
  132. /* Setup the receive address */
  133. e_dbg("Programming MAC Address into RAR[0]\n");
  134. e1000e_rar_set(hw, hw->mac.addr, 0);
  135. /* Zero out the other (rar_entry_count - 1) receive addresses */
  136. e_dbg("Clearing RAR[1-%u]\n", rar_count-1);
  137. for (i = 1; i < rar_count; i++)
  138. e1000e_rar_set(hw, mac_addr, i);
  139. }
  140. /**
  141. * e1000_check_alt_mac_addr_generic - Check for alternate MAC addr
  142. * @hw: pointer to the HW structure
  143. *
  144. * Checks the nvm for an alternate MAC address. An alternate MAC address
  145. * can be setup by pre-boot software and must be treated like a permanent
  146. * address and must override the actual permanent MAC address. If an
  147. * alternate MAC address is found it is programmed into RAR0, replacing
  148. * the permanent address that was installed into RAR0 by the Si on reset.
  149. * This function will return SUCCESS unless it encounters an error while
  150. * reading the EEPROM.
  151. **/
  152. s32 e1000_check_alt_mac_addr_generic(struct e1000_hw *hw)
  153. {
  154. u32 i;
  155. s32 ret_val = 0;
  156. u16 offset, nvm_alt_mac_addr_offset, nvm_data;
  157. u8 alt_mac_addr[ETH_ALEN];
  158. ret_val = e1000_read_nvm(hw, NVM_COMPAT, 1, &nvm_data);
  159. if (ret_val)
  160. goto out;
  161. /* Check for LOM (vs. NIC) or one of two valid mezzanine cards */
  162. if (!((nvm_data & NVM_COMPAT_LOM) ||
  163. (hw->adapter->pdev->device == E1000_DEV_ID_82571EB_SERDES_DUAL) ||
  164. (hw->adapter->pdev->device == E1000_DEV_ID_82571EB_SERDES_QUAD) ||
  165. (hw->adapter->pdev->device == E1000_DEV_ID_82571EB_SERDES)))
  166. goto out;
  167. ret_val = e1000_read_nvm(hw, NVM_ALT_MAC_ADDR_PTR, 1,
  168. &nvm_alt_mac_addr_offset);
  169. if (ret_val) {
  170. e_dbg("NVM Read Error\n");
  171. goto out;
  172. }
  173. if (nvm_alt_mac_addr_offset == 0xFFFF) {
  174. /* There is no Alternate MAC Address */
  175. goto out;
  176. }
  177. if (hw->bus.func == E1000_FUNC_1)
  178. nvm_alt_mac_addr_offset += E1000_ALT_MAC_ADDRESS_OFFSET_LAN1;
  179. for (i = 0; i < ETH_ALEN; i += 2) {
  180. offset = nvm_alt_mac_addr_offset + (i >> 1);
  181. ret_val = e1000_read_nvm(hw, offset, 1, &nvm_data);
  182. if (ret_val) {
  183. e_dbg("NVM Read Error\n");
  184. goto out;
  185. }
  186. alt_mac_addr[i] = (u8)(nvm_data & 0xFF);
  187. alt_mac_addr[i + 1] = (u8)(nvm_data >> 8);
  188. }
  189. /* if multicast bit is set, the alternate address will not be used */
  190. if (alt_mac_addr[0] & 0x01) {
  191. e_dbg("Ignoring Alternate Mac Address with MC bit set\n");
  192. goto out;
  193. }
  194. /*
  195. * We have a valid alternate MAC address, and we want to treat it the
  196. * same as the normal permanent MAC address stored by the HW into the
  197. * RAR. Do this by mapping this address into RAR0.
  198. */
  199. e1000e_rar_set(hw, alt_mac_addr, 0);
  200. out:
  201. return ret_val;
  202. }
  203. /**
  204. * e1000e_rar_set - Set receive address register
  205. * @hw: pointer to the HW structure
  206. * @addr: pointer to the receive address
  207. * @index: receive address array register
  208. *
  209. * Sets the receive address array register at index to the address passed
  210. * in by addr.
  211. **/
  212. void e1000e_rar_set(struct e1000_hw *hw, u8 *addr, u32 index)
  213. {
  214. u32 rar_low, rar_high;
  215. /*
  216. * HW expects these in little endian so we reverse the byte order
  217. * from network order (big endian) to little endian
  218. */
  219. rar_low = ((u32) addr[0] |
  220. ((u32) addr[1] << 8) |
  221. ((u32) addr[2] << 16) | ((u32) addr[3] << 24));
  222. rar_high = ((u32) addr[4] | ((u32) addr[5] << 8));
  223. /* If MAC address zero, no need to set the AV bit */
  224. if (rar_low || rar_high)
  225. rar_high |= E1000_RAH_AV;
  226. /*
  227. * Some bridges will combine consecutive 32-bit writes into
  228. * a single burst write, which will malfunction on some parts.
  229. * The flushes avoid this.
  230. */
  231. ew32(RAL(index), rar_low);
  232. e1e_flush();
  233. ew32(RAH(index), rar_high);
  234. e1e_flush();
  235. }
  236. /**
  237. * e1000_hash_mc_addr - Generate a multicast hash value
  238. * @hw: pointer to the HW structure
  239. * @mc_addr: pointer to a multicast address
  240. *
  241. * Generates a multicast address hash value which is used to determine
  242. * the multicast filter table array address and new table value. See
  243. * e1000_mta_set_generic()
  244. **/
  245. static u32 e1000_hash_mc_addr(struct e1000_hw *hw, u8 *mc_addr)
  246. {
  247. u32 hash_value, hash_mask;
  248. u8 bit_shift = 0;
  249. /* Register count multiplied by bits per register */
  250. hash_mask = (hw->mac.mta_reg_count * 32) - 1;
  251. /*
  252. * For a mc_filter_type of 0, bit_shift is the number of left-shifts
  253. * where 0xFF would still fall within the hash mask.
  254. */
  255. while (hash_mask >> bit_shift != 0xFF)
  256. bit_shift++;
  257. /*
  258. * The portion of the address that is used for the hash table
  259. * is determined by the mc_filter_type setting.
  260. * The algorithm is such that there is a total of 8 bits of shifting.
  261. * The bit_shift for a mc_filter_type of 0 represents the number of
  262. * left-shifts where the MSB of mc_addr[5] would still fall within
  263. * the hash_mask. Case 0 does this exactly. Since there are a total
  264. * of 8 bits of shifting, then mc_addr[4] will shift right the
  265. * remaining number of bits. Thus 8 - bit_shift. The rest of the
  266. * cases are a variation of this algorithm...essentially raising the
  267. * number of bits to shift mc_addr[5] left, while still keeping the
  268. * 8-bit shifting total.
  269. *
  270. * For example, given the following Destination MAC Address and an
  271. * mta register count of 128 (thus a 4096-bit vector and 0xFFF mask),
  272. * we can see that the bit_shift for case 0 is 4. These are the hash
  273. * values resulting from each mc_filter_type...
  274. * [0] [1] [2] [3] [4] [5]
  275. * 01 AA 00 12 34 56
  276. * LSB MSB
  277. *
  278. * case 0: hash_value = ((0x34 >> 4) | (0x56 << 4)) & 0xFFF = 0x563
  279. * case 1: hash_value = ((0x34 >> 3) | (0x56 << 5)) & 0xFFF = 0xAC6
  280. * case 2: hash_value = ((0x34 >> 2) | (0x56 << 6)) & 0xFFF = 0x163
  281. * case 3: hash_value = ((0x34 >> 0) | (0x56 << 8)) & 0xFFF = 0x634
  282. */
  283. switch (hw->mac.mc_filter_type) {
  284. default:
  285. case 0:
  286. break;
  287. case 1:
  288. bit_shift += 1;
  289. break;
  290. case 2:
  291. bit_shift += 2;
  292. break;
  293. case 3:
  294. bit_shift += 4;
  295. break;
  296. }
  297. hash_value = hash_mask & (((mc_addr[4] >> (8 - bit_shift)) |
  298. (((u16) mc_addr[5]) << bit_shift)));
  299. return hash_value;
  300. }
  301. /**
  302. * e1000e_update_mc_addr_list_generic - Update Multicast addresses
  303. * @hw: pointer to the HW structure
  304. * @mc_addr_list: array of multicast addresses to program
  305. * @mc_addr_count: number of multicast addresses to program
  306. *
  307. * Updates entire Multicast Table Array.
  308. * The caller must have a packed mc_addr_list of multicast addresses.
  309. **/
  310. void e1000e_update_mc_addr_list_generic(struct e1000_hw *hw,
  311. u8 *mc_addr_list, u32 mc_addr_count)
  312. {
  313. u32 hash_value, hash_bit, hash_reg;
  314. int i;
  315. /* clear mta_shadow */
  316. memset(&hw->mac.mta_shadow, 0, sizeof(hw->mac.mta_shadow));
  317. /* update mta_shadow from mc_addr_list */
  318. for (i = 0; (u32) i < mc_addr_count; i++) {
  319. hash_value = e1000_hash_mc_addr(hw, mc_addr_list);
  320. hash_reg = (hash_value >> 5) & (hw->mac.mta_reg_count - 1);
  321. hash_bit = hash_value & 0x1F;
  322. hw->mac.mta_shadow[hash_reg] |= (1 << hash_bit);
  323. mc_addr_list += (ETH_ALEN);
  324. }
  325. /* replace the entire MTA table */
  326. for (i = hw->mac.mta_reg_count - 1; i >= 0; i--)
  327. E1000_WRITE_REG_ARRAY(hw, E1000_MTA, i, hw->mac.mta_shadow[i]);
  328. e1e_flush();
  329. }
  330. /**
  331. * e1000e_clear_hw_cntrs_base - Clear base hardware counters
  332. * @hw: pointer to the HW structure
  333. *
  334. * Clears the base hardware counters by reading the counter registers.
  335. **/
  336. void e1000e_clear_hw_cntrs_base(struct e1000_hw *hw)
  337. {
  338. er32(CRCERRS);
  339. er32(SYMERRS);
  340. er32(MPC);
  341. er32(SCC);
  342. er32(ECOL);
  343. er32(MCC);
  344. er32(LATECOL);
  345. er32(COLC);
  346. er32(DC);
  347. er32(SEC);
  348. er32(RLEC);
  349. er32(XONRXC);
  350. er32(XONTXC);
  351. er32(XOFFRXC);
  352. er32(XOFFTXC);
  353. er32(FCRUC);
  354. er32(GPRC);
  355. er32(BPRC);
  356. er32(MPRC);
  357. er32(GPTC);
  358. er32(GORCL);
  359. er32(GORCH);
  360. er32(GOTCL);
  361. er32(GOTCH);
  362. er32(RNBC);
  363. er32(RUC);
  364. er32(RFC);
  365. er32(ROC);
  366. er32(RJC);
  367. er32(TORL);
  368. er32(TORH);
  369. er32(TOTL);
  370. er32(TOTH);
  371. er32(TPR);
  372. er32(TPT);
  373. er32(MPTC);
  374. er32(BPTC);
  375. }
  376. /**
  377. * e1000e_check_for_copper_link - Check for link (Copper)
  378. * @hw: pointer to the HW structure
  379. *
  380. * Checks to see of the link status of the hardware has changed. If a
  381. * change in link status has been detected, then we read the PHY registers
  382. * to get the current speed/duplex if link exists.
  383. **/
  384. s32 e1000e_check_for_copper_link(struct e1000_hw *hw)
  385. {
  386. struct e1000_mac_info *mac = &hw->mac;
  387. s32 ret_val;
  388. bool link;
  389. /*
  390. * We only want to go out to the PHY registers to see if Auto-Neg
  391. * has completed and/or if our link status has changed. The
  392. * get_link_status flag is set upon receiving a Link Status
  393. * Change or Rx Sequence Error interrupt.
  394. */
  395. if (!mac->get_link_status)
  396. return 0;
  397. /*
  398. * First we want to see if the MII Status Register reports
  399. * link. If so, then we want to get the current speed/duplex
  400. * of the PHY.
  401. */
  402. ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
  403. if (ret_val)
  404. return ret_val;
  405. if (!link)
  406. return ret_val; /* No link detected */
  407. mac->get_link_status = false;
  408. /*
  409. * Check if there was DownShift, must be checked
  410. * immediately after link-up
  411. */
  412. e1000e_check_downshift(hw);
  413. /*
  414. * If we are forcing speed/duplex, then we simply return since
  415. * we have already determined whether we have link or not.
  416. */
  417. if (!mac->autoneg) {
  418. ret_val = -E1000_ERR_CONFIG;
  419. return ret_val;
  420. }
  421. /*
  422. * Auto-Neg is enabled. Auto Speed Detection takes care
  423. * of MAC speed/duplex configuration. So we only need to
  424. * configure Collision Distance in the MAC.
  425. */
  426. e1000e_config_collision_dist(hw);
  427. /*
  428. * Configure Flow Control now that Auto-Neg has completed.
  429. * First, we need to restore the desired flow control
  430. * settings because we may have had to re-autoneg with a
  431. * different link partner.
  432. */
  433. ret_val = e1000e_config_fc_after_link_up(hw);
  434. if (ret_val)
  435. e_dbg("Error configuring flow control\n");
  436. return ret_val;
  437. }
  438. /**
  439. * e1000e_check_for_fiber_link - Check for link (Fiber)
  440. * @hw: pointer to the HW structure
  441. *
  442. * Checks for link up on the hardware. If link is not up and we have
  443. * a signal, then we need to force link up.
  444. **/
  445. s32 e1000e_check_for_fiber_link(struct e1000_hw *hw)
  446. {
  447. struct e1000_mac_info *mac = &hw->mac;
  448. u32 rxcw;
  449. u32 ctrl;
  450. u32 status;
  451. s32 ret_val;
  452. ctrl = er32(CTRL);
  453. status = er32(STATUS);
  454. rxcw = er32(RXCW);
  455. /*
  456. * If we don't have link (auto-negotiation failed or link partner
  457. * cannot auto-negotiate), the cable is plugged in (we have signal),
  458. * and our link partner is not trying to auto-negotiate with us (we
  459. * are receiving idles or data), we need to force link up. We also
  460. * need to give auto-negotiation time to complete, in case the cable
  461. * was just plugged in. The autoneg_failed flag does this.
  462. */
  463. /* (ctrl & E1000_CTRL_SWDPIN1) == 1 == have signal */
  464. if ((ctrl & E1000_CTRL_SWDPIN1) && (!(status & E1000_STATUS_LU)) &&
  465. (!(rxcw & E1000_RXCW_C))) {
  466. if (mac->autoneg_failed == 0) {
  467. mac->autoneg_failed = 1;
  468. return 0;
  469. }
  470. e_dbg("NOT Rx'ing /C/, disable AutoNeg and force link.\n");
  471. /* Disable auto-negotiation in the TXCW register */
  472. ew32(TXCW, (mac->txcw & ~E1000_TXCW_ANE));
  473. /* Force link-up and also force full-duplex. */
  474. ctrl = er32(CTRL);
  475. ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
  476. ew32(CTRL, ctrl);
  477. /* Configure Flow Control after forcing link up. */
  478. ret_val = e1000e_config_fc_after_link_up(hw);
  479. if (ret_val) {
  480. e_dbg("Error configuring flow control\n");
  481. return ret_val;
  482. }
  483. } else if ((ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
  484. /*
  485. * If we are forcing link and we are receiving /C/ ordered
  486. * sets, re-enable auto-negotiation in the TXCW register
  487. * and disable forced link in the Device Control register
  488. * in an attempt to auto-negotiate with our link partner.
  489. */
  490. e_dbg("Rx'ing /C/, enable AutoNeg and stop forcing link.\n");
  491. ew32(TXCW, mac->txcw);
  492. ew32(CTRL, (ctrl & ~E1000_CTRL_SLU));
  493. mac->serdes_has_link = true;
  494. }
  495. return 0;
  496. }
  497. /**
  498. * e1000e_check_for_serdes_link - Check for link (Serdes)
  499. * @hw: pointer to the HW structure
  500. *
  501. * Checks for link up on the hardware. If link is not up and we have
  502. * a signal, then we need to force link up.
  503. **/
  504. s32 e1000e_check_for_serdes_link(struct e1000_hw *hw)
  505. {
  506. struct e1000_mac_info *mac = &hw->mac;
  507. u32 rxcw;
  508. u32 ctrl;
  509. u32 status;
  510. s32 ret_val;
  511. ctrl = er32(CTRL);
  512. status = er32(STATUS);
  513. rxcw = er32(RXCW);
  514. /*
  515. * If we don't have link (auto-negotiation failed or link partner
  516. * cannot auto-negotiate), and our link partner is not trying to
  517. * auto-negotiate with us (we are receiving idles or data),
  518. * we need to force link up. We also need to give auto-negotiation
  519. * time to complete.
  520. */
  521. /* (ctrl & E1000_CTRL_SWDPIN1) == 1 == have signal */
  522. if ((!(status & E1000_STATUS_LU)) && (!(rxcw & E1000_RXCW_C))) {
  523. if (mac->autoneg_failed == 0) {
  524. mac->autoneg_failed = 1;
  525. return 0;
  526. }
  527. e_dbg("NOT Rx'ing /C/, disable AutoNeg and force link.\n");
  528. /* Disable auto-negotiation in the TXCW register */
  529. ew32(TXCW, (mac->txcw & ~E1000_TXCW_ANE));
  530. /* Force link-up and also force full-duplex. */
  531. ctrl = er32(CTRL);
  532. ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
  533. ew32(CTRL, ctrl);
  534. /* Configure Flow Control after forcing link up. */
  535. ret_val = e1000e_config_fc_after_link_up(hw);
  536. if (ret_val) {
  537. e_dbg("Error configuring flow control\n");
  538. return ret_val;
  539. }
  540. } else if ((ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
  541. /*
  542. * If we are forcing link and we are receiving /C/ ordered
  543. * sets, re-enable auto-negotiation in the TXCW register
  544. * and disable forced link in the Device Control register
  545. * in an attempt to auto-negotiate with our link partner.
  546. */
  547. e_dbg("Rx'ing /C/, enable AutoNeg and stop forcing link.\n");
  548. ew32(TXCW, mac->txcw);
  549. ew32(CTRL, (ctrl & ~E1000_CTRL_SLU));
  550. mac->serdes_has_link = true;
  551. } else if (!(E1000_TXCW_ANE & er32(TXCW))) {
  552. /*
  553. * If we force link for non-auto-negotiation switch, check
  554. * link status based on MAC synchronization for internal
  555. * serdes media type.
  556. */
  557. /* SYNCH bit and IV bit are sticky. */
  558. udelay(10);
  559. rxcw = er32(RXCW);
  560. if (rxcw & E1000_RXCW_SYNCH) {
  561. if (!(rxcw & E1000_RXCW_IV)) {
  562. mac->serdes_has_link = true;
  563. e_dbg("SERDES: Link up - forced.\n");
  564. }
  565. } else {
  566. mac->serdes_has_link = false;
  567. e_dbg("SERDES: Link down - force failed.\n");
  568. }
  569. }
  570. if (E1000_TXCW_ANE & er32(TXCW)) {
  571. status = er32(STATUS);
  572. if (status & E1000_STATUS_LU) {
  573. /* SYNCH bit and IV bit are sticky, so reread rxcw. */
  574. udelay(10);
  575. rxcw = er32(RXCW);
  576. if (rxcw & E1000_RXCW_SYNCH) {
  577. if (!(rxcw & E1000_RXCW_IV)) {
  578. mac->serdes_has_link = true;
  579. e_dbg("SERDES: Link up - autoneg "
  580. "completed successfully.\n");
  581. } else {
  582. mac->serdes_has_link = false;
  583. e_dbg("SERDES: Link down - invalid"
  584. "codewords detected in autoneg.\n");
  585. }
  586. } else {
  587. mac->serdes_has_link = false;
  588. e_dbg("SERDES: Link down - no sync.\n");
  589. }
  590. } else {
  591. mac->serdes_has_link = false;
  592. e_dbg("SERDES: Link down - autoneg failed\n");
  593. }
  594. }
  595. return 0;
  596. }
  597. /**
  598. * e1000_set_default_fc_generic - Set flow control default values
  599. * @hw: pointer to the HW structure
  600. *
  601. * Read the EEPROM for the default values for flow control and store the
  602. * values.
  603. **/
  604. static s32 e1000_set_default_fc_generic(struct e1000_hw *hw)
  605. {
  606. s32 ret_val;
  607. u16 nvm_data;
  608. /*
  609. * Read and store word 0x0F of the EEPROM. This word contains bits
  610. * that determine the hardware's default PAUSE (flow control) mode,
  611. * a bit that determines whether the HW defaults to enabling or
  612. * disabling auto-negotiation, and the direction of the
  613. * SW defined pins. If there is no SW over-ride of the flow
  614. * control setting, then the variable hw->fc will
  615. * be initialized based on a value in the EEPROM.
  616. */
  617. ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &nvm_data);
  618. if (ret_val) {
  619. e_dbg("NVM Read Error\n");
  620. return ret_val;
  621. }
  622. if ((nvm_data & NVM_WORD0F_PAUSE_MASK) == 0)
  623. hw->fc.requested_mode = e1000_fc_none;
  624. else if ((nvm_data & NVM_WORD0F_PAUSE_MASK) ==
  625. NVM_WORD0F_ASM_DIR)
  626. hw->fc.requested_mode = e1000_fc_tx_pause;
  627. else
  628. hw->fc.requested_mode = e1000_fc_full;
  629. return 0;
  630. }
  631. /**
  632. * e1000e_setup_link - Setup flow control and link settings
  633. * @hw: pointer to the HW structure
  634. *
  635. * Determines which flow control settings to use, then configures flow
  636. * control. Calls the appropriate media-specific link configuration
  637. * function. Assuming the adapter has a valid link partner, a valid link
  638. * should be established. Assumes the hardware has previously been reset
  639. * and the transmitter and receiver are not enabled.
  640. **/
  641. s32 e1000e_setup_link(struct e1000_hw *hw)
  642. {
  643. struct e1000_mac_info *mac = &hw->mac;
  644. s32 ret_val;
  645. /*
  646. * In the case of the phy reset being blocked, we already have a link.
  647. * We do not need to set it up again.
  648. */
  649. if (e1000_check_reset_block(hw))
  650. return 0;
  651. /*
  652. * If requested flow control is set to default, set flow control
  653. * based on the EEPROM flow control settings.
  654. */
  655. if (hw->fc.requested_mode == e1000_fc_default) {
  656. ret_val = e1000_set_default_fc_generic(hw);
  657. if (ret_val)
  658. return ret_val;
  659. }
  660. /*
  661. * Save off the requested flow control mode for use later. Depending
  662. * on the link partner's capabilities, we may or may not use this mode.
  663. */
  664. hw->fc.current_mode = hw->fc.requested_mode;
  665. e_dbg("After fix-ups FlowControl is now = %x\n",
  666. hw->fc.current_mode);
  667. /* Call the necessary media_type subroutine to configure the link. */
  668. ret_val = mac->ops.setup_physical_interface(hw);
  669. if (ret_val)
  670. return ret_val;
  671. /*
  672. * Initialize the flow control address, type, and PAUSE timer
  673. * registers to their default values. This is done even if flow
  674. * control is disabled, because it does not hurt anything to
  675. * initialize these registers.
  676. */
  677. e_dbg("Initializing the Flow Control address, type and timer regs\n");
  678. ew32(FCT, FLOW_CONTROL_TYPE);
  679. ew32(FCAH, FLOW_CONTROL_ADDRESS_HIGH);
  680. ew32(FCAL, FLOW_CONTROL_ADDRESS_LOW);
  681. ew32(FCTTV, hw->fc.pause_time);
  682. return e1000e_set_fc_watermarks(hw);
  683. }
  684. /**
  685. * e1000_commit_fc_settings_generic - Configure flow control
  686. * @hw: pointer to the HW structure
  687. *
  688. * Write the flow control settings to the Transmit Config Word Register (TXCW)
  689. * base on the flow control settings in e1000_mac_info.
  690. **/
  691. static s32 e1000_commit_fc_settings_generic(struct e1000_hw *hw)
  692. {
  693. struct e1000_mac_info *mac = &hw->mac;
  694. u32 txcw;
  695. /*
  696. * Check for a software override of the flow control settings, and
  697. * setup the device accordingly. If auto-negotiation is enabled, then
  698. * software will have to set the "PAUSE" bits to the correct value in
  699. * the Transmit Config Word Register (TXCW) and re-start auto-
  700. * negotiation. However, if auto-negotiation is disabled, then
  701. * software will have to manually configure the two flow control enable
  702. * bits in the CTRL register.
  703. *
  704. * The possible values of the "fc" parameter are:
  705. * 0: Flow control is completely disabled
  706. * 1: Rx flow control is enabled (we can receive pause frames,
  707. * but not send pause frames).
  708. * 2: Tx flow control is enabled (we can send pause frames but we
  709. * do not support receiving pause frames).
  710. * 3: Both Rx and Tx flow control (symmetric) are enabled.
  711. */
  712. switch (hw->fc.current_mode) {
  713. case e1000_fc_none:
  714. /* Flow control completely disabled by a software over-ride. */
  715. txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
  716. break;
  717. case e1000_fc_rx_pause:
  718. /*
  719. * Rx Flow control is enabled and Tx Flow control is disabled
  720. * by a software over-ride. Since there really isn't a way to
  721. * advertise that we are capable of Rx Pause ONLY, we will
  722. * advertise that we support both symmetric and asymmetric Rx
  723. * PAUSE. Later, we will disable the adapter's ability to send
  724. * PAUSE frames.
  725. */
  726. txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
  727. break;
  728. case e1000_fc_tx_pause:
  729. /*
  730. * Tx Flow control is enabled, and Rx Flow control is disabled,
  731. * by a software over-ride.
  732. */
  733. txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
  734. break;
  735. case e1000_fc_full:
  736. /*
  737. * Flow control (both Rx and Tx) is enabled by a software
  738. * over-ride.
  739. */
  740. txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
  741. break;
  742. default:
  743. e_dbg("Flow control param set incorrectly\n");
  744. return -E1000_ERR_CONFIG;
  745. break;
  746. }
  747. ew32(TXCW, txcw);
  748. mac->txcw = txcw;
  749. return 0;
  750. }
  751. /**
  752. * e1000_poll_fiber_serdes_link_generic - Poll for link up
  753. * @hw: pointer to the HW structure
  754. *
  755. * Polls for link up by reading the status register, if link fails to come
  756. * up with auto-negotiation, then the link is forced if a signal is detected.
  757. **/
  758. static s32 e1000_poll_fiber_serdes_link_generic(struct e1000_hw *hw)
  759. {
  760. struct e1000_mac_info *mac = &hw->mac;
  761. u32 i, status;
  762. s32 ret_val;
  763. /*
  764. * If we have a signal (the cable is plugged in, or assumed true for
  765. * serdes media) then poll for a "Link-Up" indication in the Device
  766. * Status Register. Time-out if a link isn't seen in 500 milliseconds
  767. * seconds (Auto-negotiation should complete in less than 500
  768. * milliseconds even if the other end is doing it in SW).
  769. */
  770. for (i = 0; i < FIBER_LINK_UP_LIMIT; i++) {
  771. usleep_range(10000, 20000);
  772. status = er32(STATUS);
  773. if (status & E1000_STATUS_LU)
  774. break;
  775. }
  776. if (i == FIBER_LINK_UP_LIMIT) {
  777. e_dbg("Never got a valid link from auto-neg!!!\n");
  778. mac->autoneg_failed = 1;
  779. /*
  780. * AutoNeg failed to achieve a link, so we'll call
  781. * mac->check_for_link. This routine will force the
  782. * link up if we detect a signal. This will allow us to
  783. * communicate with non-autonegotiating link partners.
  784. */
  785. ret_val = mac->ops.check_for_link(hw);
  786. if (ret_val) {
  787. e_dbg("Error while checking for link\n");
  788. return ret_val;
  789. }
  790. mac->autoneg_failed = 0;
  791. } else {
  792. mac->autoneg_failed = 0;
  793. e_dbg("Valid Link Found\n");
  794. }
  795. return 0;
  796. }
  797. /**
  798. * e1000e_setup_fiber_serdes_link - Setup link for fiber/serdes
  799. * @hw: pointer to the HW structure
  800. *
  801. * Configures collision distance and flow control for fiber and serdes
  802. * links. Upon successful setup, poll for link.
  803. **/
  804. s32 e1000e_setup_fiber_serdes_link(struct e1000_hw *hw)
  805. {
  806. u32 ctrl;
  807. s32 ret_val;
  808. ctrl = er32(CTRL);
  809. /* Take the link out of reset */
  810. ctrl &= ~E1000_CTRL_LRST;
  811. e1000e_config_collision_dist(hw);
  812. ret_val = e1000_commit_fc_settings_generic(hw);
  813. if (ret_val)
  814. return ret_val;
  815. /*
  816. * Since auto-negotiation is enabled, take the link out of reset (the
  817. * link will be in reset, because we previously reset the chip). This
  818. * will restart auto-negotiation. If auto-negotiation is successful
  819. * then the link-up status bit will be set and the flow control enable
  820. * bits (RFCE and TFCE) will be set according to their negotiated value.
  821. */
  822. e_dbg("Auto-negotiation enabled\n");
  823. ew32(CTRL, ctrl);
  824. e1e_flush();
  825. usleep_range(1000, 2000);
  826. /*
  827. * For these adapters, the SW definable pin 1 is set when the optics
  828. * detect a signal. If we have a signal, then poll for a "Link-Up"
  829. * indication.
  830. */
  831. if (hw->phy.media_type == e1000_media_type_internal_serdes ||
  832. (er32(CTRL) & E1000_CTRL_SWDPIN1)) {
  833. ret_val = e1000_poll_fiber_serdes_link_generic(hw);
  834. } else {
  835. e_dbg("No signal detected\n");
  836. }
  837. return 0;
  838. }
  839. /**
  840. * e1000e_config_collision_dist - Configure collision distance
  841. * @hw: pointer to the HW structure
  842. *
  843. * Configures the collision distance to the default value and is used
  844. * during link setup. Currently no func pointer exists and all
  845. * implementations are handled in the generic version of this function.
  846. **/
  847. void e1000e_config_collision_dist(struct e1000_hw *hw)
  848. {
  849. u32 tctl;
  850. tctl = er32(TCTL);
  851. tctl &= ~E1000_TCTL_COLD;
  852. tctl |= E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT;
  853. ew32(TCTL, tctl);
  854. e1e_flush();
  855. }
  856. /**
  857. * e1000e_set_fc_watermarks - Set flow control high/low watermarks
  858. * @hw: pointer to the HW structure
  859. *
  860. * Sets the flow control high/low threshold (watermark) registers. If
  861. * flow control XON frame transmission is enabled, then set XON frame
  862. * transmission as well.
  863. **/
  864. s32 e1000e_set_fc_watermarks(struct e1000_hw *hw)
  865. {
  866. u32 fcrtl = 0, fcrth = 0;
  867. /*
  868. * Set the flow control receive threshold registers. Normally,
  869. * these registers will be set to a default threshold that may be
  870. * adjusted later by the driver's runtime code. However, if the
  871. * ability to transmit pause frames is not enabled, then these
  872. * registers will be set to 0.
  873. */
  874. if (hw->fc.current_mode & e1000_fc_tx_pause) {
  875. /*
  876. * We need to set up the Receive Threshold high and low water
  877. * marks as well as (optionally) enabling the transmission of
  878. * XON frames.
  879. */
  880. fcrtl = hw->fc.low_water;
  881. fcrtl |= E1000_FCRTL_XONE;
  882. fcrth = hw->fc.high_water;
  883. }
  884. ew32(FCRTL, fcrtl);
  885. ew32(FCRTH, fcrth);
  886. return 0;
  887. }
  888. /**
  889. * e1000e_force_mac_fc - Force the MAC's flow control settings
  890. * @hw: pointer to the HW structure
  891. *
  892. * Force the MAC's flow control settings. Sets the TFCE and RFCE bits in the
  893. * device control register to reflect the adapter settings. TFCE and RFCE
  894. * need to be explicitly set by software when a copper PHY is used because
  895. * autonegotiation is managed by the PHY rather than the MAC. Software must
  896. * also configure these bits when link is forced on a fiber connection.
  897. **/
  898. s32 e1000e_force_mac_fc(struct e1000_hw *hw)
  899. {
  900. u32 ctrl;
  901. ctrl = er32(CTRL);
  902. /*
  903. * Because we didn't get link via the internal auto-negotiation
  904. * mechanism (we either forced link or we got link via PHY
  905. * auto-neg), we have to manually enable/disable transmit an
  906. * receive flow control.
  907. *
  908. * The "Case" statement below enables/disable flow control
  909. * according to the "hw->fc.current_mode" parameter.
  910. *
  911. * The possible values of the "fc" parameter are:
  912. * 0: Flow control is completely disabled
  913. * 1: Rx flow control is enabled (we can receive pause
  914. * frames but not send pause frames).
  915. * 2: Tx flow control is enabled (we can send pause frames
  916. * frames but we do not receive pause frames).
  917. * 3: Both Rx and Tx flow control (symmetric) is enabled.
  918. * other: No other values should be possible at this point.
  919. */
  920. e_dbg("hw->fc.current_mode = %u\n", hw->fc.current_mode);
  921. switch (hw->fc.current_mode) {
  922. case e1000_fc_none:
  923. ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
  924. break;
  925. case e1000_fc_rx_pause:
  926. ctrl &= (~E1000_CTRL_TFCE);
  927. ctrl |= E1000_CTRL_RFCE;
  928. break;
  929. case e1000_fc_tx_pause:
  930. ctrl &= (~E1000_CTRL_RFCE);
  931. ctrl |= E1000_CTRL_TFCE;
  932. break;
  933. case e1000_fc_full:
  934. ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
  935. break;
  936. default:
  937. e_dbg("Flow control param set incorrectly\n");
  938. return -E1000_ERR_CONFIG;
  939. }
  940. ew32(CTRL, ctrl);
  941. return 0;
  942. }
  943. /**
  944. * e1000e_config_fc_after_link_up - Configures flow control after link
  945. * @hw: pointer to the HW structure
  946. *
  947. * Checks the status of auto-negotiation after link up to ensure that the
  948. * speed and duplex were not forced. If the link needed to be forced, then
  949. * flow control needs to be forced also. If auto-negotiation is enabled
  950. * and did not fail, then we configure flow control based on our link
  951. * partner.
  952. **/
  953. s32 e1000e_config_fc_after_link_up(struct e1000_hw *hw)
  954. {
  955. struct e1000_mac_info *mac = &hw->mac;
  956. s32 ret_val = 0;
  957. u16 mii_status_reg, mii_nway_adv_reg, mii_nway_lp_ability_reg;
  958. u16 speed, duplex;
  959. /*
  960. * Check for the case where we have fiber media and auto-neg failed
  961. * so we had to force link. In this case, we need to force the
  962. * configuration of the MAC to match the "fc" parameter.
  963. */
  964. if (mac->autoneg_failed) {
  965. if (hw->phy.media_type == e1000_media_type_fiber ||
  966. hw->phy.media_type == e1000_media_type_internal_serdes)
  967. ret_val = e1000e_force_mac_fc(hw);
  968. } else {
  969. if (hw->phy.media_type == e1000_media_type_copper)
  970. ret_val = e1000e_force_mac_fc(hw);
  971. }
  972. if (ret_val) {
  973. e_dbg("Error forcing flow control settings\n");
  974. return ret_val;
  975. }
  976. /*
  977. * Check for the case where we have copper media and auto-neg is
  978. * enabled. In this case, we need to check and see if Auto-Neg
  979. * has completed, and if so, how the PHY and link partner has
  980. * flow control configured.
  981. */
  982. if ((hw->phy.media_type == e1000_media_type_copper) && mac->autoneg) {
  983. /*
  984. * Read the MII Status Register and check to see if AutoNeg
  985. * has completed. We read this twice because this reg has
  986. * some "sticky" (latched) bits.
  987. */
  988. ret_val = e1e_rphy(hw, PHY_STATUS, &mii_status_reg);
  989. if (ret_val)
  990. return ret_val;
  991. ret_val = e1e_rphy(hw, PHY_STATUS, &mii_status_reg);
  992. if (ret_val)
  993. return ret_val;
  994. if (!(mii_status_reg & MII_SR_AUTONEG_COMPLETE)) {
  995. e_dbg("Copper PHY and Auto Neg "
  996. "has not completed.\n");
  997. return ret_val;
  998. }
  999. /*
  1000. * The AutoNeg process has completed, so we now need to
  1001. * read both the Auto Negotiation Advertisement
  1002. * Register (Address 4) and the Auto_Negotiation Base
  1003. * Page Ability Register (Address 5) to determine how
  1004. * flow control was negotiated.
  1005. */
  1006. ret_val = e1e_rphy(hw, PHY_AUTONEG_ADV, &mii_nway_adv_reg);
  1007. if (ret_val)
  1008. return ret_val;
  1009. ret_val =
  1010. e1e_rphy(hw, PHY_LP_ABILITY, &mii_nway_lp_ability_reg);
  1011. if (ret_val)
  1012. return ret_val;
  1013. /*
  1014. * Two bits in the Auto Negotiation Advertisement Register
  1015. * (Address 4) and two bits in the Auto Negotiation Base
  1016. * Page Ability Register (Address 5) determine flow control
  1017. * for both the PHY and the link partner. The following
  1018. * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
  1019. * 1999, describes these PAUSE resolution bits and how flow
  1020. * control is determined based upon these settings.
  1021. * NOTE: DC = Don't Care
  1022. *
  1023. * LOCAL DEVICE | LINK PARTNER
  1024. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
  1025. *-------|---------|-------|---------|--------------------
  1026. * 0 | 0 | DC | DC | e1000_fc_none
  1027. * 0 | 1 | 0 | DC | e1000_fc_none
  1028. * 0 | 1 | 1 | 0 | e1000_fc_none
  1029. * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
  1030. * 1 | 0 | 0 | DC | e1000_fc_none
  1031. * 1 | DC | 1 | DC | e1000_fc_full
  1032. * 1 | 1 | 0 | 0 | e1000_fc_none
  1033. * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
  1034. *
  1035. * Are both PAUSE bits set to 1? If so, this implies
  1036. * Symmetric Flow Control is enabled at both ends. The
  1037. * ASM_DIR bits are irrelevant per the spec.
  1038. *
  1039. * For Symmetric Flow Control:
  1040. *
  1041. * LOCAL DEVICE | LINK PARTNER
  1042. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
  1043. *-------|---------|-------|---------|--------------------
  1044. * 1 | DC | 1 | DC | E1000_fc_full
  1045. *
  1046. */
  1047. if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
  1048. (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
  1049. /*
  1050. * Now we need to check if the user selected Rx ONLY
  1051. * of pause frames. In this case, we had to advertise
  1052. * FULL flow control because we could not advertise Rx
  1053. * ONLY. Hence, we must now check to see if we need to
  1054. * turn OFF the TRANSMISSION of PAUSE frames.
  1055. */
  1056. if (hw->fc.requested_mode == e1000_fc_full) {
  1057. hw->fc.current_mode = e1000_fc_full;
  1058. e_dbg("Flow Control = FULL.\r\n");
  1059. } else {
  1060. hw->fc.current_mode = e1000_fc_rx_pause;
  1061. e_dbg("Flow Control = "
  1062. "Rx PAUSE frames only.\r\n");
  1063. }
  1064. }
  1065. /*
  1066. * For receiving PAUSE frames ONLY.
  1067. *
  1068. * LOCAL DEVICE | LINK PARTNER
  1069. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
  1070. *-------|---------|-------|---------|--------------------
  1071. * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
  1072. */
  1073. else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
  1074. (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
  1075. (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
  1076. (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
  1077. hw->fc.current_mode = e1000_fc_tx_pause;
  1078. e_dbg("Flow Control = Tx PAUSE frames only.\r\n");
  1079. }
  1080. /*
  1081. * For transmitting PAUSE frames ONLY.
  1082. *
  1083. * LOCAL DEVICE | LINK PARTNER
  1084. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
  1085. *-------|---------|-------|---------|--------------------
  1086. * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
  1087. */
  1088. else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
  1089. (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
  1090. !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
  1091. (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
  1092. hw->fc.current_mode = e1000_fc_rx_pause;
  1093. e_dbg("Flow Control = Rx PAUSE frames only.\r\n");
  1094. } else {
  1095. /*
  1096. * Per the IEEE spec, at this point flow control
  1097. * should be disabled.
  1098. */
  1099. hw->fc.current_mode = e1000_fc_none;
  1100. e_dbg("Flow Control = NONE.\r\n");
  1101. }
  1102. /*
  1103. * Now we need to do one last check... If we auto-
  1104. * negotiated to HALF DUPLEX, flow control should not be
  1105. * enabled per IEEE 802.3 spec.
  1106. */
  1107. ret_val = mac->ops.get_link_up_info(hw, &speed, &duplex);
  1108. if (ret_val) {
  1109. e_dbg("Error getting link speed and duplex\n");
  1110. return ret_val;
  1111. }
  1112. if (duplex == HALF_DUPLEX)
  1113. hw->fc.current_mode = e1000_fc_none;
  1114. /*
  1115. * Now we call a subroutine to actually force the MAC
  1116. * controller to use the correct flow control settings.
  1117. */
  1118. ret_val = e1000e_force_mac_fc(hw);
  1119. if (ret_val) {
  1120. e_dbg("Error forcing flow control settings\n");
  1121. return ret_val;
  1122. }
  1123. }
  1124. return 0;
  1125. }
  1126. /**
  1127. * e1000e_get_speed_and_duplex_copper - Retrieve current speed/duplex
  1128. * @hw: pointer to the HW structure
  1129. * @speed: stores the current speed
  1130. * @duplex: stores the current duplex
  1131. *
  1132. * Read the status register for the current speed/duplex and store the current
  1133. * speed and duplex for copper connections.
  1134. **/
  1135. s32 e1000e_get_speed_and_duplex_copper(struct e1000_hw *hw, u16 *speed, u16 *duplex)
  1136. {
  1137. u32 status;
  1138. status = er32(STATUS);
  1139. if (status & E1000_STATUS_SPEED_1000)
  1140. *speed = SPEED_1000;
  1141. else if (status & E1000_STATUS_SPEED_100)
  1142. *speed = SPEED_100;
  1143. else
  1144. *speed = SPEED_10;
  1145. if (status & E1000_STATUS_FD)
  1146. *duplex = FULL_DUPLEX;
  1147. else
  1148. *duplex = HALF_DUPLEX;
  1149. e_dbg("%u Mbps, %s Duplex\n",
  1150. *speed == SPEED_1000 ? 1000 : *speed == SPEED_100 ? 100 : 10,
  1151. *duplex == FULL_DUPLEX ? "Full" : "Half");
  1152. return 0;
  1153. }
  1154. /**
  1155. * e1000e_get_speed_and_duplex_fiber_serdes - Retrieve current speed/duplex
  1156. * @hw: pointer to the HW structure
  1157. * @speed: stores the current speed
  1158. * @duplex: stores the current duplex
  1159. *
  1160. * Sets the speed and duplex to gigabit full duplex (the only possible option)
  1161. * for fiber/serdes links.
  1162. **/
  1163. s32 e1000e_get_speed_and_duplex_fiber_serdes(struct e1000_hw *hw, u16 *speed, u16 *duplex)
  1164. {
  1165. *speed = SPEED_1000;
  1166. *duplex = FULL_DUPLEX;
  1167. return 0;
  1168. }
  1169. /**
  1170. * e1000e_get_hw_semaphore - Acquire hardware semaphore
  1171. * @hw: pointer to the HW structure
  1172. *
  1173. * Acquire the HW semaphore to access the PHY or NVM
  1174. **/
  1175. s32 e1000e_get_hw_semaphore(struct e1000_hw *hw)
  1176. {
  1177. u32 swsm;
  1178. s32 timeout = hw->nvm.word_size + 1;
  1179. s32 i = 0;
  1180. /* Get the SW semaphore */
  1181. while (i < timeout) {
  1182. swsm = er32(SWSM);
  1183. if (!(swsm & E1000_SWSM_SMBI))
  1184. break;
  1185. udelay(50);
  1186. i++;
  1187. }
  1188. if (i == timeout) {
  1189. e_dbg("Driver can't access device - SMBI bit is set.\n");
  1190. return -E1000_ERR_NVM;
  1191. }
  1192. /* Get the FW semaphore. */
  1193. for (i = 0; i < timeout; i++) {
  1194. swsm = er32(SWSM);
  1195. ew32(SWSM, swsm | E1000_SWSM_SWESMBI);
  1196. /* Semaphore acquired if bit latched */
  1197. if (er32(SWSM) & E1000_SWSM_SWESMBI)
  1198. break;
  1199. udelay(50);
  1200. }
  1201. if (i == timeout) {
  1202. /* Release semaphores */
  1203. e1000e_put_hw_semaphore(hw);
  1204. e_dbg("Driver can't access the NVM\n");
  1205. return -E1000_ERR_NVM;
  1206. }
  1207. return 0;
  1208. }
  1209. /**
  1210. * e1000e_put_hw_semaphore - Release hardware semaphore
  1211. * @hw: pointer to the HW structure
  1212. *
  1213. * Release hardware semaphore used to access the PHY or NVM
  1214. **/
  1215. void e1000e_put_hw_semaphore(struct e1000_hw *hw)
  1216. {
  1217. u32 swsm;
  1218. swsm = er32(SWSM);
  1219. swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI);
  1220. ew32(SWSM, swsm);
  1221. }
  1222. /**
  1223. * e1000e_get_auto_rd_done - Check for auto read completion
  1224. * @hw: pointer to the HW structure
  1225. *
  1226. * Check EEPROM for Auto Read done bit.
  1227. **/
  1228. s32 e1000e_get_auto_rd_done(struct e1000_hw *hw)
  1229. {
  1230. s32 i = 0;
  1231. while (i < AUTO_READ_DONE_TIMEOUT) {
  1232. if (er32(EECD) & E1000_EECD_AUTO_RD)
  1233. break;
  1234. usleep_range(1000, 2000);
  1235. i++;
  1236. }
  1237. if (i == AUTO_READ_DONE_TIMEOUT) {
  1238. e_dbg("Auto read by HW from NVM has not completed.\n");
  1239. return -E1000_ERR_RESET;
  1240. }
  1241. return 0;
  1242. }
  1243. /**
  1244. * e1000e_valid_led_default - Verify a valid default LED config
  1245. * @hw: pointer to the HW structure
  1246. * @data: pointer to the NVM (EEPROM)
  1247. *
  1248. * Read the EEPROM for the current default LED configuration. If the
  1249. * LED configuration is not valid, set to a valid LED configuration.
  1250. **/
  1251. s32 e1000e_valid_led_default(struct e1000_hw *hw, u16 *data)
  1252. {
  1253. s32 ret_val;
  1254. ret_val = e1000_read_nvm(hw, NVM_ID_LED_SETTINGS, 1, data);
  1255. if (ret_val) {
  1256. e_dbg("NVM Read Error\n");
  1257. return ret_val;
  1258. }
  1259. if (*data == ID_LED_RESERVED_0000 || *data == ID_LED_RESERVED_FFFF)
  1260. *data = ID_LED_DEFAULT;
  1261. return 0;
  1262. }
  1263. /**
  1264. * e1000e_id_led_init -
  1265. * @hw: pointer to the HW structure
  1266. *
  1267. **/
  1268. s32 e1000e_id_led_init(struct e1000_hw *hw)
  1269. {
  1270. struct e1000_mac_info *mac = &hw->mac;
  1271. s32 ret_val;
  1272. const u32 ledctl_mask = 0x000000FF;
  1273. const u32 ledctl_on = E1000_LEDCTL_MODE_LED_ON;
  1274. const u32 ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
  1275. u16 data, i, temp;
  1276. const u16 led_mask = 0x0F;
  1277. ret_val = hw->nvm.ops.valid_led_default(hw, &data);
  1278. if (ret_val)
  1279. return ret_val;
  1280. mac->ledctl_default = er32(LEDCTL);
  1281. mac->ledctl_mode1 = mac->ledctl_default;
  1282. mac->ledctl_mode2 = mac->ledctl_default;
  1283. for (i = 0; i < 4; i++) {
  1284. temp = (data >> (i << 2)) & led_mask;
  1285. switch (temp) {
  1286. case ID_LED_ON1_DEF2:
  1287. case ID_LED_ON1_ON2:
  1288. case ID_LED_ON1_OFF2:
  1289. mac->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
  1290. mac->ledctl_mode1 |= ledctl_on << (i << 3);
  1291. break;
  1292. case ID_LED_OFF1_DEF2:
  1293. case ID_LED_OFF1_ON2:
  1294. case ID_LED_OFF1_OFF2:
  1295. mac->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
  1296. mac->ledctl_mode1 |= ledctl_off << (i << 3);
  1297. break;
  1298. default:
  1299. /* Do nothing */
  1300. break;
  1301. }
  1302. switch (temp) {
  1303. case ID_LED_DEF1_ON2:
  1304. case ID_LED_ON1_ON2:
  1305. case ID_LED_OFF1_ON2:
  1306. mac->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
  1307. mac->ledctl_mode2 |= ledctl_on << (i << 3);
  1308. break;
  1309. case ID_LED_DEF1_OFF2:
  1310. case ID_LED_ON1_OFF2:
  1311. case ID_LED_OFF1_OFF2:
  1312. mac->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
  1313. mac->ledctl_mode2 |= ledctl_off << (i << 3);
  1314. break;
  1315. default:
  1316. /* Do nothing */
  1317. break;
  1318. }
  1319. }
  1320. return 0;
  1321. }
  1322. /**
  1323. * e1000e_setup_led_generic - Configures SW controllable LED
  1324. * @hw: pointer to the HW structure
  1325. *
  1326. * This prepares the SW controllable LED for use and saves the current state
  1327. * of the LED so it can be later restored.
  1328. **/
  1329. s32 e1000e_setup_led_generic(struct e1000_hw *hw)
  1330. {
  1331. u32 ledctl;
  1332. if (hw->mac.ops.setup_led != e1000e_setup_led_generic)
  1333. return -E1000_ERR_CONFIG;
  1334. if (hw->phy.media_type == e1000_media_type_fiber) {
  1335. ledctl = er32(LEDCTL);
  1336. hw->mac.ledctl_default = ledctl;
  1337. /* Turn off LED0 */
  1338. ledctl &= ~(E1000_LEDCTL_LED0_IVRT |
  1339. E1000_LEDCTL_LED0_BLINK |
  1340. E1000_LEDCTL_LED0_MODE_MASK);
  1341. ledctl |= (E1000_LEDCTL_MODE_LED_OFF <<
  1342. E1000_LEDCTL_LED0_MODE_SHIFT);
  1343. ew32(LEDCTL, ledctl);
  1344. } else if (hw->phy.media_type == e1000_media_type_copper) {
  1345. ew32(LEDCTL, hw->mac.ledctl_mode1);
  1346. }
  1347. return 0;
  1348. }
  1349. /**
  1350. * e1000e_cleanup_led_generic - Set LED config to default operation
  1351. * @hw: pointer to the HW structure
  1352. *
  1353. * Remove the current LED configuration and set the LED configuration
  1354. * to the default value, saved from the EEPROM.
  1355. **/
  1356. s32 e1000e_cleanup_led_generic(struct e1000_hw *hw)
  1357. {
  1358. ew32(LEDCTL, hw->mac.ledctl_default);
  1359. return 0;
  1360. }
  1361. /**
  1362. * e1000e_blink_led_generic - Blink LED
  1363. * @hw: pointer to the HW structure
  1364. *
  1365. * Blink the LEDs which are set to be on.
  1366. **/
  1367. s32 e1000e_blink_led_generic(struct e1000_hw *hw)
  1368. {
  1369. u32 ledctl_blink = 0;
  1370. u32 i;
  1371. if (hw->phy.media_type == e1000_media_type_fiber) {
  1372. /* always blink LED0 for PCI-E fiber */
  1373. ledctl_blink = E1000_LEDCTL_LED0_BLINK |
  1374. (E1000_LEDCTL_MODE_LED_ON << E1000_LEDCTL_LED0_MODE_SHIFT);
  1375. } else {
  1376. /*
  1377. * set the blink bit for each LED that's "on" (0x0E)
  1378. * in ledctl_mode2
  1379. */
  1380. ledctl_blink = hw->mac.ledctl_mode2;
  1381. for (i = 0; i < 4; i++)
  1382. if (((hw->mac.ledctl_mode2 >> (i * 8)) & 0xFF) ==
  1383. E1000_LEDCTL_MODE_LED_ON)
  1384. ledctl_blink |= (E1000_LEDCTL_LED0_BLINK <<
  1385. (i * 8));
  1386. }
  1387. ew32(LEDCTL, ledctl_blink);
  1388. return 0;
  1389. }
  1390. /**
  1391. * e1000e_led_on_generic - Turn LED on
  1392. * @hw: pointer to the HW structure
  1393. *
  1394. * Turn LED on.
  1395. **/
  1396. s32 e1000e_led_on_generic(struct e1000_hw *hw)
  1397. {
  1398. u32 ctrl;
  1399. switch (hw->phy.media_type) {
  1400. case e1000_media_type_fiber:
  1401. ctrl = er32(CTRL);
  1402. ctrl &= ~E1000_CTRL_SWDPIN0;
  1403. ctrl |= E1000_CTRL_SWDPIO0;
  1404. ew32(CTRL, ctrl);
  1405. break;
  1406. case e1000_media_type_copper:
  1407. ew32(LEDCTL, hw->mac.ledctl_mode2);
  1408. break;
  1409. default:
  1410. break;
  1411. }
  1412. return 0;
  1413. }
  1414. /**
  1415. * e1000e_led_off_generic - Turn LED off
  1416. * @hw: pointer to the HW structure
  1417. *
  1418. * Turn LED off.
  1419. **/
  1420. s32 e1000e_led_off_generic(struct e1000_hw *hw)
  1421. {
  1422. u32 ctrl;
  1423. switch (hw->phy.media_type) {
  1424. case e1000_media_type_fiber:
  1425. ctrl = er32(CTRL);
  1426. ctrl |= E1000_CTRL_SWDPIN0;
  1427. ctrl |= E1000_CTRL_SWDPIO0;
  1428. ew32(CTRL, ctrl);
  1429. break;
  1430. case e1000_media_type_copper:
  1431. ew32(LEDCTL, hw->mac.ledctl_mode1);
  1432. break;
  1433. default:
  1434. break;
  1435. }
  1436. return 0;
  1437. }
  1438. /**
  1439. * e1000e_set_pcie_no_snoop - Set PCI-express capabilities
  1440. * @hw: pointer to the HW structure
  1441. * @no_snoop: bitmap of snoop events
  1442. *
  1443. * Set the PCI-express register to snoop for events enabled in 'no_snoop'.
  1444. **/
  1445. void e1000e_set_pcie_no_snoop(struct e1000_hw *hw, u32 no_snoop)
  1446. {
  1447. u32 gcr;
  1448. if (no_snoop) {
  1449. gcr = er32(GCR);
  1450. gcr &= ~(PCIE_NO_SNOOP_ALL);
  1451. gcr |= no_snoop;
  1452. ew32(GCR, gcr);
  1453. }
  1454. }
  1455. /**
  1456. * e1000e_disable_pcie_master - Disables PCI-express master access
  1457. * @hw: pointer to the HW structure
  1458. *
  1459. * Returns 0 if successful, else returns -10
  1460. * (-E1000_ERR_MASTER_REQUESTS_PENDING) if master disable bit has not caused
  1461. * the master requests to be disabled.
  1462. *
  1463. * Disables PCI-Express master access and verifies there are no pending
  1464. * requests.
  1465. **/
  1466. s32 e1000e_disable_pcie_master(struct e1000_hw *hw)
  1467. {
  1468. u32 ctrl;
  1469. s32 timeout = MASTER_DISABLE_TIMEOUT;
  1470. ctrl = er32(CTRL);
  1471. ctrl |= E1000_CTRL_GIO_MASTER_DISABLE;
  1472. ew32(CTRL, ctrl);
  1473. while (timeout) {
  1474. if (!(er32(STATUS) &
  1475. E1000_STATUS_GIO_MASTER_ENABLE))
  1476. break;
  1477. udelay(100);
  1478. timeout--;
  1479. }
  1480. if (!timeout) {
  1481. e_dbg("Master requests are pending.\n");
  1482. return -E1000_ERR_MASTER_REQUESTS_PENDING;
  1483. }
  1484. return 0;
  1485. }
  1486. /**
  1487. * e1000e_reset_adaptive - Reset Adaptive Interframe Spacing
  1488. * @hw: pointer to the HW structure
  1489. *
  1490. * Reset the Adaptive Interframe Spacing throttle to default values.
  1491. **/
  1492. void e1000e_reset_adaptive(struct e1000_hw *hw)
  1493. {
  1494. struct e1000_mac_info *mac = &hw->mac;
  1495. if (!mac->adaptive_ifs) {
  1496. e_dbg("Not in Adaptive IFS mode!\n");
  1497. goto out;
  1498. }
  1499. mac->current_ifs_val = 0;
  1500. mac->ifs_min_val = IFS_MIN;
  1501. mac->ifs_max_val = IFS_MAX;
  1502. mac->ifs_step_size = IFS_STEP;
  1503. mac->ifs_ratio = IFS_RATIO;
  1504. mac->in_ifs_mode = false;
  1505. ew32(AIT, 0);
  1506. out:
  1507. return;
  1508. }
  1509. /**
  1510. * e1000e_update_adaptive - Update Adaptive Interframe Spacing
  1511. * @hw: pointer to the HW structure
  1512. *
  1513. * Update the Adaptive Interframe Spacing Throttle value based on the
  1514. * time between transmitted packets and time between collisions.
  1515. **/
  1516. void e1000e_update_adaptive(struct e1000_hw *hw)
  1517. {
  1518. struct e1000_mac_info *mac = &hw->mac;
  1519. if (!mac->adaptive_ifs) {
  1520. e_dbg("Not in Adaptive IFS mode!\n");
  1521. goto out;
  1522. }
  1523. if ((mac->collision_delta * mac->ifs_ratio) > mac->tx_packet_delta) {
  1524. if (mac->tx_packet_delta > MIN_NUM_XMITS) {
  1525. mac->in_ifs_mode = true;
  1526. if (mac->current_ifs_val < mac->ifs_max_val) {
  1527. if (!mac->current_ifs_val)
  1528. mac->current_ifs_val = mac->ifs_min_val;
  1529. else
  1530. mac->current_ifs_val +=
  1531. mac->ifs_step_size;
  1532. ew32(AIT, mac->current_ifs_val);
  1533. }
  1534. }
  1535. } else {
  1536. if (mac->in_ifs_mode &&
  1537. (mac->tx_packet_delta <= MIN_NUM_XMITS)) {
  1538. mac->current_ifs_val = 0;
  1539. mac->in_ifs_mode = false;
  1540. ew32(AIT, 0);
  1541. }
  1542. }
  1543. out:
  1544. return;
  1545. }
  1546. /**
  1547. * e1000_raise_eec_clk - Raise EEPROM clock
  1548. * @hw: pointer to the HW structure
  1549. * @eecd: pointer to the EEPROM
  1550. *
  1551. * Enable/Raise the EEPROM clock bit.
  1552. **/
  1553. static void e1000_raise_eec_clk(struct e1000_hw *hw, u32 *eecd)
  1554. {
  1555. *eecd = *eecd | E1000_EECD_SK;
  1556. ew32(EECD, *eecd);
  1557. e1e_flush();
  1558. udelay(hw->nvm.delay_usec);
  1559. }
  1560. /**
  1561. * e1000_lower_eec_clk - Lower EEPROM clock
  1562. * @hw: pointer to the HW structure
  1563. * @eecd: pointer to the EEPROM
  1564. *
  1565. * Clear/Lower the EEPROM clock bit.
  1566. **/
  1567. static void e1000_lower_eec_clk(struct e1000_hw *hw, u32 *eecd)
  1568. {
  1569. *eecd = *eecd & ~E1000_EECD_SK;
  1570. ew32(EECD, *eecd);
  1571. e1e_flush();
  1572. udelay(hw->nvm.delay_usec);
  1573. }
  1574. /**
  1575. * e1000_shift_out_eec_bits - Shift data bits our to the EEPROM
  1576. * @hw: pointer to the HW structure
  1577. * @data: data to send to the EEPROM
  1578. * @count: number of bits to shift out
  1579. *
  1580. * We need to shift 'count' bits out to the EEPROM. So, the value in the
  1581. * "data" parameter will be shifted out to the EEPROM one bit at a time.
  1582. * In order to do this, "data" must be broken down into bits.
  1583. **/
  1584. static void e1000_shift_out_eec_bits(struct e1000_hw *hw, u16 data, u16 count)
  1585. {
  1586. struct e1000_nvm_info *nvm = &hw->nvm;
  1587. u32 eecd = er32(EECD);
  1588. u32 mask;
  1589. mask = 0x01 << (count - 1);
  1590. if (nvm->type == e1000_nvm_eeprom_spi)
  1591. eecd |= E1000_EECD_DO;
  1592. do {
  1593. eecd &= ~E1000_EECD_DI;
  1594. if (data & mask)

Large files files are truncated, but you can click here to view the full file