PageRenderTime 53ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/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
  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)
  1595. eecd |= E1000_EECD_DI;
  1596. ew32(EECD, eecd);
  1597. e1e_flush();
  1598. udelay(nvm->delay_usec);
  1599. e1000_raise_eec_clk(hw, &eecd);
  1600. e1000_lower_eec_clk(hw, &eecd);
  1601. mask >>= 1;
  1602. } while (mask);
  1603. eecd &= ~E1000_EECD_DI;
  1604. ew32(EECD, eecd);
  1605. }
  1606. /**
  1607. * e1000_shift_in_eec_bits - Shift data bits in from the EEPROM
  1608. * @hw: pointer to the HW structure
  1609. * @count: number of bits to shift in
  1610. *
  1611. * In order to read a register from the EEPROM, we need to shift 'count' bits
  1612. * in from the EEPROM. Bits are "shifted in" by raising the clock input to
  1613. * the EEPROM (setting the SK bit), and then reading the value of the data out
  1614. * "DO" bit. During this "shifting in" process the data in "DI" bit should
  1615. * always be clear.
  1616. **/
  1617. static u16 e1000_shift_in_eec_bits(struct e1000_hw *hw, u16 count)
  1618. {
  1619. u32 eecd;
  1620. u32 i;
  1621. u16 data;
  1622. eecd = er32(EECD);
  1623. eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
  1624. data = 0;
  1625. for (i = 0; i < count; i++) {
  1626. data <<= 1;
  1627. e1000_raise_eec_clk(hw, &eecd);
  1628. eecd = er32(EECD);
  1629. eecd &= ~E1000_EECD_DI;
  1630. if (eecd & E1000_EECD_DO)
  1631. data |= 1;
  1632. e1000_lower_eec_clk(hw, &eecd);
  1633. }
  1634. return data;
  1635. }
  1636. /**
  1637. * e1000e_poll_eerd_eewr_done - Poll for EEPROM read/write completion
  1638. * @hw: pointer to the HW structure
  1639. * @ee_reg: EEPROM flag for polling
  1640. *
  1641. * Polls the EEPROM status bit for either read or write completion based
  1642. * upon the value of 'ee_reg'.
  1643. **/
  1644. s32 e1000e_poll_eerd_eewr_done(struct e1000_hw *hw, int ee_reg)
  1645. {
  1646. u32 attempts = 100000;
  1647. u32 i, reg = 0;
  1648. for (i = 0; i < attempts; i++) {
  1649. if (ee_reg == E1000_NVM_POLL_READ)
  1650. reg = er32(EERD);
  1651. else
  1652. reg = er32(EEWR);
  1653. if (reg & E1000_NVM_RW_REG_DONE)
  1654. return 0;
  1655. udelay(5);
  1656. }
  1657. return -E1000_ERR_NVM;
  1658. }
  1659. /**
  1660. * e1000e_acquire_nvm - Generic request for access to EEPROM
  1661. * @hw: pointer to the HW structure
  1662. *
  1663. * Set the EEPROM access request bit and wait for EEPROM access grant bit.
  1664. * Return successful if access grant bit set, else clear the request for
  1665. * EEPROM access and return -E1000_ERR_NVM (-1).
  1666. **/
  1667. s32 e1000e_acquire_nvm(struct e1000_hw *hw)
  1668. {
  1669. u32 eecd = er32(EECD);
  1670. s32 timeout = E1000_NVM_GRANT_ATTEMPTS;
  1671. ew32(EECD, eecd | E1000_EECD_REQ);
  1672. eecd = er32(EECD);
  1673. while (timeout) {
  1674. if (eecd & E1000_EECD_GNT)
  1675. break;
  1676. udelay(5);
  1677. eecd = er32(EECD);
  1678. timeout--;
  1679. }
  1680. if (!timeout) {
  1681. eecd &= ~E1000_EECD_REQ;
  1682. ew32(EECD, eecd);
  1683. e_dbg("Could not acquire NVM grant\n");
  1684. return -E1000_ERR_NVM;
  1685. }
  1686. return 0;
  1687. }
  1688. /**
  1689. * e1000_standby_nvm - Return EEPROM to standby state
  1690. * @hw: pointer to the HW structure
  1691. *
  1692. * Return the EEPROM to a standby state.
  1693. **/
  1694. static void e1000_standby_nvm(struct e1000_hw *hw)
  1695. {
  1696. struct e1000_nvm_info *nvm = &hw->nvm;
  1697. u32 eecd = er32(EECD);
  1698. if (nvm->type == e1000_nvm_eeprom_spi) {
  1699. /* Toggle CS to flush commands */
  1700. eecd |= E1000_EECD_CS;
  1701. ew32(EECD, eecd);
  1702. e1e_flush();
  1703. udelay(nvm->delay_usec);
  1704. eecd &= ~E1000_EECD_CS;
  1705. ew32(EECD, eecd);
  1706. e1e_flush();
  1707. udelay(nvm->delay_usec);
  1708. }
  1709. }
  1710. /**
  1711. * e1000_stop_nvm - Terminate EEPROM command
  1712. * @hw: pointer to the HW structure
  1713. *
  1714. * Terminates the current command by inverting the EEPROM's chip select pin.
  1715. **/
  1716. static void e1000_stop_nvm(struct e1000_hw *hw)
  1717. {
  1718. u32 eecd;
  1719. eecd = er32(EECD);
  1720. if (hw->nvm.type == e1000_nvm_eeprom_spi) {
  1721. /* Pull CS high */
  1722. eecd |= E1000_EECD_CS;
  1723. e1000_lower_eec_clk(hw, &eecd);
  1724. }
  1725. }
  1726. /**
  1727. * e1000e_release_nvm - Release exclusive access to EEPROM
  1728. * @hw: pointer to the HW structure
  1729. *
  1730. * Stop any current commands to the EEPROM and clear the EEPROM request bit.
  1731. **/
  1732. void e1000e_release_nvm(struct e1000_hw *hw)
  1733. {
  1734. u32 eecd;
  1735. e1000_stop_nvm(hw);
  1736. eecd = er32(EECD);
  1737. eecd &= ~E1000_EECD_REQ;
  1738. ew32(EECD, eecd);
  1739. }
  1740. /**
  1741. * e1000_ready_nvm_eeprom - Prepares EEPROM for read/write
  1742. * @hw: pointer to the HW structure
  1743. *
  1744. * Setups the EEPROM for reading and writing.
  1745. **/
  1746. static s32 e1000_ready_nvm_eeprom(struct e1000_hw *hw)
  1747. {
  1748. struct e1000_nvm_info *nvm = &hw->nvm;
  1749. u32 eecd = er32(EECD);
  1750. u8 spi_stat_reg;
  1751. if (nvm->type == e1000_nvm_eeprom_spi) {
  1752. u16 timeout = NVM_MAX_RETRY_SPI;
  1753. /* Clear SK and CS */
  1754. eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
  1755. ew32(EECD, eecd);
  1756. udelay(1);
  1757. /*
  1758. * Read "Status Register" repeatedly until the LSB is cleared.
  1759. * The EEPROM will signal that the command has been completed
  1760. * by clearing bit 0 of the internal status register. If it's
  1761. * not cleared within 'timeout', then error out.
  1762. */
  1763. while (timeout) {
  1764. e1000_shift_out_eec_bits(hw, NVM_RDSR_OPCODE_SPI,
  1765. hw->nvm.opcode_bits);
  1766. spi_stat_reg = (u8)e1000_shift_in_eec_bits(hw, 8);
  1767. if (!(spi_stat_reg & NVM_STATUS_RDY_SPI))
  1768. break;
  1769. udelay(5);
  1770. e1000_standby_nvm(hw);
  1771. timeout--;
  1772. }
  1773. if (!timeout) {
  1774. e_dbg("SPI NVM Status error\n");
  1775. return -E1000_ERR_NVM;
  1776. }
  1777. }
  1778. return 0;
  1779. }
  1780. /**
  1781. * e1000e_read_nvm_eerd - Reads EEPROM using EERD register
  1782. * @hw: pointer to the HW structure
  1783. * @offset: offset of word in the EEPROM to read
  1784. * @words: number of words to read
  1785. * @data: word read from the EEPROM
  1786. *
  1787. * Reads a 16 bit word from the EEPROM using the EERD register.
  1788. **/
  1789. s32 e1000e_read_nvm_eerd(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
  1790. {
  1791. struct e1000_nvm_info *nvm = &hw->nvm;
  1792. u32 i, eerd = 0;
  1793. s32 ret_val = 0;
  1794. /*
  1795. * A check for invalid values: offset too large, too many words,
  1796. * too many words for the offset, and not enough words.
  1797. */
  1798. if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
  1799. (words == 0)) {
  1800. e_dbg("nvm parameter(s) out of bounds\n");
  1801. return -E1000_ERR_NVM;
  1802. }
  1803. for (i = 0; i < words; i++) {
  1804. eerd = ((offset+i) << E1000_NVM_RW_ADDR_SHIFT) +
  1805. E1000_NVM_RW_REG_START;
  1806. ew32(EERD, eerd);
  1807. ret_val = e1000e_poll_eerd_eewr_done(hw, E1000_NVM_POLL_READ);
  1808. if (ret_val)
  1809. break;
  1810. data[i] = (er32(EERD) >> E1000_NVM_RW_REG_DATA);
  1811. }
  1812. return ret_val;
  1813. }
  1814. /**
  1815. * e1000e_write_nvm_spi - Write to EEPROM using SPI
  1816. * @hw: pointer to the HW structure
  1817. * @offset: offset within the EEPROM to be written to
  1818. * @words: number of words to write
  1819. * @data: 16 bit word(s) to be written to the EEPROM
  1820. *
  1821. * Writes data to EEPROM at offset using SPI interface.
  1822. *
  1823. * If e1000e_update_nvm_checksum is not called after this function , the
  1824. * EEPROM will most likely contain an invalid checksum.
  1825. **/
  1826. s32 e1000e_write_nvm_spi(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
  1827. {
  1828. struct e1000_nvm_info *nvm = &hw->nvm;
  1829. s32 ret_val;
  1830. u16 widx = 0;
  1831. /*
  1832. * A check for invalid values: offset too large, too many words,
  1833. * and not enough words.
  1834. */
  1835. if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
  1836. (words == 0)) {
  1837. e_dbg("nvm parameter(s) out of bounds\n");
  1838. return -E1000_ERR_NVM;
  1839. }
  1840. ret_val = nvm->ops.acquire(hw);
  1841. if (ret_val)
  1842. return ret_val;
  1843. while (widx < words) {
  1844. u8 write_opcode = NVM_WRITE_OPCODE_SPI;
  1845. ret_val = e1000_ready_nvm_eeprom(hw);
  1846. if (ret_val) {
  1847. nvm->ops.release(hw);
  1848. return ret_val;
  1849. }
  1850. e1000_standby_nvm(hw);
  1851. /* Send the WRITE ENABLE command (8 bit opcode) */
  1852. e1000_shift_out_eec_bits(hw, NVM_WREN_OPCODE_SPI,
  1853. nvm->opcode_bits);
  1854. e1000_standby_nvm(hw);
  1855. /*
  1856. * Some SPI eeproms use the 8th address bit embedded in the
  1857. * opcode
  1858. */
  1859. if ((nvm->address_bits == 8) && (offset >= 128))
  1860. write_opcode |= NVM_A8_OPCODE_SPI;
  1861. /* Send the Write command (8-bit opcode + addr) */
  1862. e1000_shift_out_eec_bits(hw, write_opcode, nvm->opcode_bits);
  1863. e1000_shift_out_eec_bits(hw, (u16)((offset + widx) * 2),
  1864. nvm->address_bits);
  1865. /* Loop to allow for up to whole page write of eeprom */
  1866. while (widx < words) {
  1867. u16 word_out = data[widx];
  1868. word_out = (word_out >> 8) | (word_out << 8);
  1869. e1000_shift_out_eec_bits(hw, word_out, 16);
  1870. widx++;
  1871. if ((((offset + widx) * 2) % nvm->page_size) == 0) {
  1872. e1000_standby_nvm(hw);
  1873. break;
  1874. }
  1875. }
  1876. }
  1877. usleep_range(10000, 20000);
  1878. nvm->ops.release(hw);
  1879. return 0;
  1880. }
  1881. /**
  1882. * e1000_read_pba_string_generic - Read device part number
  1883. * @hw: pointer to the HW structure
  1884. * @pba_num: pointer to device part number
  1885. * @pba_num_size: size of part number buffer
  1886. *
  1887. * Reads the product board assembly (PBA) number from the EEPROM and stores
  1888. * the value in pba_num.
  1889. **/
  1890. s32 e1000_read_pba_string_generic(struct e1000_hw *hw, u8 *pba_num,
  1891. u32 pba_num_size)
  1892. {
  1893. s32 ret_val;
  1894. u16 nvm_data;
  1895. u16 pba_ptr;
  1896. u16 offset;
  1897. u16 length;
  1898. if (pba_num == NULL) {
  1899. e_dbg("PBA string buffer was null\n");
  1900. ret_val = E1000_ERR_INVALID_ARGUMENT;
  1901. goto out;
  1902. }
  1903. ret_val = e1000_read_nvm(hw, NVM_PBA_OFFSET_0, 1, &nvm_data);
  1904. if (ret_val) {
  1905. e_dbg("NVM Read Error\n");
  1906. goto out;
  1907. }
  1908. ret_val = e1000_read_nvm(hw, NVM_PBA_OFFSET_1, 1, &pba_ptr);
  1909. if (ret_val) {
  1910. e_dbg("NVM Read Error\n");
  1911. goto out;
  1912. }
  1913. /*
  1914. * if nvm_data is not ptr guard the PBA must be in legacy format which
  1915. * means pba_ptr is actually our second data word for the PBA number
  1916. * and we can decode it into an ascii string
  1917. */
  1918. if (nvm_data != NVM_PBA_PTR_GUARD) {
  1919. e_dbg("NVM PBA number is not stored as string\n");
  1920. /* we will need 11 characters to store the PBA */
  1921. if (pba_num_size < 11) {
  1922. e_dbg("PBA string buffer too small\n");
  1923. return E1000_ERR_NO_SPACE;
  1924. }
  1925. /* extract hex string from data and pba_ptr */
  1926. pba_num[0] = (nvm_data >> 12) & 0xF;
  1927. pba_num[1] = (nvm_data >> 8) & 0xF;
  1928. pba_num[2] = (nvm_data >> 4) & 0xF;
  1929. pba_num[3] = nvm_data & 0xF;
  1930. pba_num[4] = (pba_ptr >> 12) & 0xF;
  1931. pba_num[5] = (pba_ptr >> 8) & 0xF;
  1932. pba_num[6] = '-';
  1933. pba_num[7] = 0;
  1934. pba_num[8] = (pba_ptr >> 4) & 0xF;
  1935. pba_num[9] = pba_ptr & 0xF;
  1936. /* put a null character on the end of our string */
  1937. pba_num[10] = '\0';
  1938. /* switch all the data but the '-' to hex char */
  1939. for (offset = 0; offset < 10; offset++) {
  1940. if (pba_num[offset] < 0xA)
  1941. pba_num[offset] += '0';
  1942. else if (pba_num[offset] < 0x10)
  1943. pba_num[offset] += 'A' - 0xA;
  1944. }
  1945. goto out;
  1946. }
  1947. ret_val = e1000_read_nvm(hw, pba_ptr, 1, &length);
  1948. if (ret_val) {
  1949. e_dbg("NVM Read Error\n");
  1950. goto out;
  1951. }
  1952. if (length == 0xFFFF || length == 0) {
  1953. e_dbg("NVM PBA number section invalid length\n");
  1954. ret_val = E1000_ERR_NVM_PBA_SECTION;
  1955. goto out;
  1956. }
  1957. /* check if pba_num buffer is big enough */
  1958. if (pba_num_size < (((u32)length * 2) - 1)) {
  1959. e_dbg("PBA string buffer too small\n");
  1960. ret_val = E1000_ERR_NO_SPACE;
  1961. goto out;
  1962. }
  1963. /* trim pba length from start of string */
  1964. pba_ptr++;
  1965. length--;
  1966. for (offset = 0; offset < length; offset++) {
  1967. ret_val = e1000_read_nvm(hw, pba_ptr + offset, 1, &nvm_data);
  1968. if (ret_val) {
  1969. e_dbg("NVM Read Error\n");
  1970. goto out;
  1971. }
  1972. pba_num[offset * 2] = (u8)(nvm_data >> 8);
  1973. pba_num[(offset * 2) + 1] = (u8)(nvm_data & 0xFF);
  1974. }
  1975. pba_num[offset * 2] = '\0';
  1976. out:
  1977. return ret_val;
  1978. }
  1979. /**
  1980. * e1000_read_mac_addr_generic - Read device MAC address
  1981. * @hw: pointer to the HW structure
  1982. *
  1983. * Reads the device MAC address from the EEPROM and stores the value.
  1984. * Since devices with two ports use the same EEPROM, we increment the
  1985. * last bit in the MAC address for the second port.
  1986. **/
  1987. s32 e1000_read_mac_addr_generic(struct e1000_hw *hw)
  1988. {
  1989. u32 rar_high;
  1990. u32 rar_low;
  1991. u16 i;
  1992. rar_high = er32(RAH(0));
  1993. rar_low = er32(RAL(0));
  1994. for (i = 0; i < E1000_RAL_MAC_ADDR_LEN; i++)
  1995. hw->mac.perm_addr[i] = (u8)(rar_low >> (i*8));
  1996. for (i = 0; i < E1000_RAH_MAC_ADDR_LEN; i++)
  1997. hw->mac.perm_addr[i+4] = (u8)(rar_high >> (i*8));
  1998. for (i = 0; i < ETH_ALEN; i++)
  1999. hw->mac.addr[i] = hw->mac.perm_addr[i];
  2000. return 0;
  2001. }
  2002. /**
  2003. * e1000e_validate_nvm_checksum_generic - Validate EEPROM checksum
  2004. * @hw: pointer to the HW structure
  2005. *
  2006. * Calculates the EEPROM checksum by reading/adding each word of the EEPROM
  2007. * and then verifies that the sum of the EEPROM is equal to 0xBABA.
  2008. **/
  2009. s32 e1000e_validate_nvm_checksum_generic(struct e1000_hw *hw)
  2010. {
  2011. s32 ret_val;
  2012. u16 checksum = 0;
  2013. u16 i, nvm_data;
  2014. for (i = 0; i < (NVM_CHECKSUM_REG + 1); i++) {
  2015. ret_val = e1000_read_nvm(hw, i, 1, &nvm_data);
  2016. if (ret_val) {
  2017. e_dbg("NVM Read Error\n");
  2018. return ret_val;
  2019. }
  2020. checksum += nvm_data;
  2021. }
  2022. if (checksum != (u16) NVM_SUM) {
  2023. e_dbg("NVM Checksum Invalid\n");
  2024. return -E1000_ERR_NVM;
  2025. }
  2026. return 0;
  2027. }
  2028. /**
  2029. * e1000e_update_nvm_checksum_generic - Update EEPROM checksum
  2030. * @hw: pointer to the HW structure
  2031. *
  2032. * Updates the EEPROM checksum by reading/adding each word of the EEPROM
  2033. * up to the checksum. Then calculates the EEPROM checksum and writes the
  2034. * value to the EEPROM.
  2035. **/
  2036. s32 e1000e_update_nvm_checksum_generic(struct e1000_hw *hw)
  2037. {
  2038. s32 ret_val;
  2039. u16 checksum = 0;
  2040. u16 i, nvm_data;
  2041. for (i = 0; i < NVM_CHECKSUM_REG; i++) {
  2042. ret_val = e1000_read_nvm(hw, i, 1, &nvm_data);
  2043. if (ret_val) {
  2044. e_dbg("NVM Read Error while updating checksum.\n");
  2045. return ret_val;
  2046. }
  2047. checksum += nvm_data;
  2048. }
  2049. checksum = (u16) NVM_SUM - checksum;
  2050. ret_val = e1000_write_nvm(hw, NVM_CHECKSUM_REG, 1, &checksum);
  2051. if (ret_val)
  2052. e_dbg("NVM Write Error while updating checksum.\n");
  2053. return ret_val;
  2054. }
  2055. /**
  2056. * e1000e_reload_nvm - Reloads EEPROM
  2057. * @hw: pointer to the HW structure
  2058. *
  2059. * Reloads the EEPROM by setting the "Reinitialize from EEPROM" bit in the
  2060. * extended control register.
  2061. **/
  2062. void e1000e_reload_nvm(struct e1000_hw *hw)
  2063. {
  2064. u32 ctrl_ext;
  2065. udelay(10);
  2066. ctrl_ext = er32(CTRL_EXT);
  2067. ctrl_ext |= E1000_CTRL_EXT_EE_RST;
  2068. ew32(CTRL_EXT, ctrl_ext);
  2069. e1e_flush();
  2070. }
  2071. /**
  2072. * e1000_calculate_checksum - Calculate checksum for buffer
  2073. * @buffer: pointer to EEPROM
  2074. * @length: size of EEPROM to calculate a checksum for
  2075. *
  2076. * Calculates the checksum for some buffer on a specified length. The
  2077. * checksum calculated is returned.
  2078. **/
  2079. static u8 e1000_calculate_checksum(u8 *buffer, u32 length)
  2080. {
  2081. u32 i;
  2082. u8 sum = 0;
  2083. if (!buffer)
  2084. return 0;
  2085. for (i = 0; i < length; i++)
  2086. sum += buffer[i];
  2087. return (u8) (0 - sum);
  2088. }
  2089. /**
  2090. * e1000_mng_enable_host_if - Checks host interface is enabled
  2091. * @hw: pointer to the HW structure
  2092. *
  2093. * Returns E1000_success upon success, else E1000_ERR_HOST_INTERFACE_COMMAND
  2094. *
  2095. * This function checks whether the HOST IF is enabled for command operation
  2096. * and also checks whether the previous command is completed. It busy waits
  2097. * in case of previous command is not completed.
  2098. **/
  2099. static s32 e1000_mng_enable_host_if(struct e1000_hw *hw)
  2100. {
  2101. u32 hicr;
  2102. u8 i;
  2103. if (!(hw->mac.arc_subsystem_valid)) {
  2104. e_dbg("ARC subsystem not valid.\n");
  2105. return -E1000_ERR_HOST_INTERFACE_COMMAND;
  2106. }
  2107. /* Check that the host interface is enabled. */
  2108. hicr = er32(HICR);
  2109. if ((hicr & E1000_HICR_EN) == 0) {
  2110. e_dbg("E1000_HOST_EN bit disabled.\n");
  2111. return -E1000_ERR_HOST_INTERFACE_COMMAND;
  2112. }
  2113. /* check the previous command is completed */
  2114. for (i = 0; i < E1000_MNG_DHCP_COMMAND_TIMEOUT; i++) {
  2115. hicr = er32(HICR);
  2116. if (!(hicr & E1000_HICR_C))
  2117. break;
  2118. mdelay(1);
  2119. }
  2120. if (i == E1000_MNG_DHCP_COMMAND_TIMEOUT) {
  2121. e_dbg("Previous command timeout failed .\n");
  2122. return -E1000_ERR_HOST_INTERFACE_COMMAND;
  2123. }
  2124. return 0;
  2125. }
  2126. /**
  2127. * e1000e_check_mng_mode_generic - check management mode
  2128. * @hw: pointer to the HW structure
  2129. *
  2130. * Reads the firmware semaphore register and returns true (>0) if
  2131. * manageability is enabled, else false (0).
  2132. **/
  2133. bool e1000e_check_mng_mode_generic(struct e1000_hw *hw)
  2134. {
  2135. u32 fwsm = er32(FWSM);
  2136. return (fwsm & E1000_FWSM_MODE_MASK) ==
  2137. (E1000_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT);
  2138. }
  2139. /**
  2140. * e1000e_enable_tx_pkt_filtering - Enable packet filtering on Tx
  2141. * @hw: pointer to the HW structure
  2142. *
  2143. * Enables packet filtering on transmit packets if manageability is enabled
  2144. * and host interface is enabled.
  2145. **/
  2146. bool e1000e_enable_tx_pkt_filtering(struct e1000_hw *hw)
  2147. {
  2148. struct e1000_host_mng_dhcp_cookie *hdr = &hw->mng_cookie;
  2149. u32 *buffer = (u32 *)&hw->mng_cookie;
  2150. u32 offset;
  2151. s32 ret_val, hdr_csum, csum;
  2152. u8 i, len;
  2153. hw->mac.tx_pkt_filtering = true;
  2154. /* No manageability, no filtering */
  2155. if (!e1000e_check_mng_mode(hw)) {
  2156. hw->mac.tx_pkt_filtering = false;
  2157. goto out;
  2158. }
  2159. /*
  2160. * If we can't read from the host interface for whatever
  2161. * reason, disable filtering.
  2162. */
  2163. ret_val = e1000_mng_enable_host_if(hw);
  2164. if (ret_val) {
  2165. hw->mac.tx_pkt_filtering = false;
  2166. goto out;
  2167. }
  2168. /* Read in the header. Length and offset are in dwords. */
  2169. len = E1000_MNG_DHCP_COOKIE_LENGTH >> 2;
  2170. offset = E1000_MNG_DHCP_COOKIE_OFFSET >> 2;
  2171. for (i = 0; i < len; i++)
  2172. *(buffer + i) = E1000_READ_REG_ARRAY(hw, E1000_HOST_IF, offset + i);
  2173. hdr_csum = hdr->checksum;
  2174. hdr->checksum = 0;
  2175. csum = e1000_calculate_checksum((u8 *)hdr,
  2176. E1000_MNG_DHCP_COOKIE_LENGTH);
  2177. /*
  2178. * If either the checksums or signature don't match, then
  2179. * the cookie area isn't considered valid, in which case we
  2180. * take the safe route of assuming Tx filtering is enabled.
  2181. */
  2182. if ((hdr_csum != csum) || (hdr->signature != E1000_IAMT_SIGNATURE)) {
  2183. hw->mac.tx_pkt_filtering = true;
  2184. goto out;
  2185. }
  2186. /* Cookie area is valid, make the final check for filtering. */
  2187. if (!(hdr->status & E1000_MNG_DHCP_COOKIE_STATUS_PARSING)) {
  2188. hw->mac.tx_pkt_filtering = false;
  2189. goto out;
  2190. }
  2191. out:
  2192. return hw->mac.tx_pkt_filtering;
  2193. }
  2194. /**
  2195. * e1000_mng_write_cmd_header - Writes manageability command header
  2196. * @hw: pointer to the HW structure
  2197. * @hdr: pointer to the host interface command header
  2198. *
  2199. * Writes the command header after does the checksum calculation.
  2200. **/
  2201. static s32 e1000_mng_write_cmd_header(struct e1000_hw *hw,
  2202. struct e1000_host_mng_command_header *hdr)
  2203. {
  2204. u16 i, length = sizeof(struct e1000_host_mng_command_header);
  2205. /* Write the whole command header structure with new checksum. */
  2206. hdr->checksum = e1000_calculate_checksum((u8 *)hdr, length);
  2207. length >>= 2;
  2208. /* Write the relevant command block into the ram area. */
  2209. for (i = 0; i < length; i++) {
  2210. E1000_WRITE_REG_ARRAY(hw, E1000_HOST_IF, i,
  2211. *((u32 *) hdr + i));
  2212. e1e_flush();
  2213. }
  2214. return 0;
  2215. }
  2216. /**
  2217. * e1000_mng_host_if_write - Write to the manageability host interface
  2218. * @hw: pointer to the HW structure
  2219. * @buffer: pointer to the host interface buffer
  2220. * @length: size of the buffer
  2221. * @offset: location in the buffer to write to
  2222. * @sum: sum of the data (not checksum)
  2223. *
  2224. * This function writes the buffer content at the offset given on the host if.
  2225. * It also does alignment considerations to do the writes in most efficient
  2226. * way. Also fills up the sum of the buffer in *buffer parameter.
  2227. **/
  2228. static s32 e1000_mng_host_if_write(struct e1000_hw *hw, u8 *buffer,
  2229. u16 length, u16 offset, u8 *sum)
  2230. {
  2231. u8 *tmp;
  2232. u8 *bufptr = buffer;
  2233. u32 data = 0;
  2234. u16 remaining, i, j, prev_bytes;
  2235. /* sum = only sum of the data and it is not checksum */
  2236. if (length == 0 || offset + length > E1000_HI_MAX_MNG_DATA_LENGTH)
  2237. return -E1000_ERR_PARAM;
  2238. tmp = (u8 *)&data;
  2239. prev_bytes = offset & 0x3;
  2240. offset >>= 2;
  2241. if (prev_bytes) {
  2242. data = E1000_READ_REG_ARRAY(hw, E1000_HOST_IF, offset);
  2243. for (j = prev_bytes; j < sizeof(u32); j++) {
  2244. *(tmp + j) = *bufptr++;
  2245. *sum += *(tmp + j);
  2246. }
  2247. E1000_WRITE_REG_ARRAY(hw, E1000_HOST_IF, offset, data);
  2248. length -= j - prev_bytes;
  2249. offset++;
  2250. }
  2251. remaining = length & 0x3;
  2252. length -= remaining;
  2253. /* Calculate length in DWORDs */
  2254. length >>= 2;
  2255. /*
  2256. * The device driver writes the relevant command block into the
  2257. * ram area.
  2258. */
  2259. for (i = 0; i < length; i++) {
  2260. for (j = 0; j < sizeof(u32); j++) {
  2261. *(tmp + j) = *bufptr++;
  2262. *sum += *(tmp + j);
  2263. }
  2264. E1000_WRITE_REG_ARRAY(hw, E1000_HOST_IF, offset + i, data);
  2265. }
  2266. if (remaining) {
  2267. for (j = 0; j < sizeof(u32); j++) {
  2268. if (j < remaining)
  2269. *(tmp + j) = *bufptr++;
  2270. else
  2271. *(tmp + j) = 0;
  2272. *sum += *(tmp + j);
  2273. }
  2274. E1000_WRITE_REG_ARRAY(hw, E1000_HOST_IF, offset + i, data);
  2275. }
  2276. return 0;
  2277. }
  2278. /**
  2279. * e1000e_mng_write_dhcp_info - Writes DHCP info to host interface
  2280. * @hw: pointer to the HW structure
  2281. * @buffer: pointer to the host interface
  2282. * @length: size of the buffer
  2283. *
  2284. * Writes the DHCP information to the host interface.
  2285. **/
  2286. s32 e1000e_mng_write_dhcp_info(struct e1000_hw *hw, u8 *buffer, u16 length)
  2287. {
  2288. struct e1000_host_mng_command_header hdr;
  2289. s32 ret_val;
  2290. u32 hicr;
  2291. hdr.command_id = E1000_MNG_DHCP_TX_PAYLOAD_CMD;
  2292. hdr.command_length = length;
  2293. hdr.reserved1 = 0;
  2294. hdr.reserved2 = 0;
  2295. hdr.checksum = 0;
  2296. /* Enable the host interface */
  2297. ret_val = e1000_mng_enable_host_if(hw);
  2298. if (ret_val)
  2299. return ret_val;
  2300. /* Populate the host interface with the contents of "buffer". */
  2301. ret_val = e1000_mng_host_if_write(hw, buffer, length,
  2302. sizeof(hdr), &(hdr.checksum));
  2303. if (ret_val)
  2304. return ret_val;
  2305. /* Write the manageability command header */
  2306. ret_val = e1000_mng_write_cmd_header(hw, &hdr);
  2307. if (ret_val)
  2308. return ret_val;
  2309. /* Tell the ARC a new command is pending. */
  2310. hicr = er32(HICR);
  2311. ew32(HICR, hicr | E1000_HICR_C);
  2312. return 0;
  2313. }
  2314. /**
  2315. * e1000e_enable_mng_pass_thru - Check if management passthrough is needed
  2316. * @hw: pointer to the HW structure
  2317. *
  2318. * Verifies the hardware needs to leave interface enabled so that frames can
  2319. * be directed to and from the management interface.
  2320. **/
  2321. bool e1000e_enable_mng_pass_thru(struct e1000_hw *hw)
  2322. {
  2323. u32 manc;
  2324. u32 fwsm, factps;
  2325. bool ret_val = false;
  2326. manc = er32(MANC);
  2327. if (!(manc & E1000_MANC_RCV_TCO_EN))
  2328. goto out;
  2329. if (hw->mac.has_fwsm) {
  2330. fwsm = er32(FWSM);
  2331. factps = er32(FACTPS);
  2332. if (!(factps & E1000_FACTPS_MNGCG) &&
  2333. ((fwsm & E1000_FWSM_MODE_MASK) ==
  2334. (e1000_mng_mode_pt << E1000_FWSM_MODE_SHIFT))) {
  2335. ret_val = true;
  2336. goto out;
  2337. }
  2338. } else if ((hw->mac.type == e1000_82574) ||
  2339. (hw->mac.type == e1000_82583)) {
  2340. u16 data;
  2341. factps = er32(FACTPS);
  2342. e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &data);
  2343. if (!(factps & E1000_FACTPS_MNGCG) &&
  2344. ((data & E1000_NVM_INIT_CTRL2_MNGM) ==
  2345. (e1000_mng_mode_pt << 13))) {
  2346. ret_val = true;
  2347. goto out;
  2348. }
  2349. } else if ((manc & E1000_MANC_SMBUS_EN) &&
  2350. !(manc & E1000_MANC_ASF_EN)) {
  2351. ret_val = true;
  2352. goto out;
  2353. }
  2354. out:
  2355. return ret_val;
  2356. }