igc_mac.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881
  1. // SPDX-License-Identifier: GPL-2.0
  2. /* Copyright (c) 2018 Intel Corporation */
  3. #include <linux/pci.h>
  4. #include <linux/delay.h>
  5. #include "igc_mac.h"
  6. #include "igc_hw.h"
  7. /**
  8. * igc_disable_pcie_master - Disables PCI-express master access
  9. * @hw: pointer to the HW structure
  10. *
  11. * Returns 0 (0) if successful, else returns -10
  12. * (-IGC_ERR_MASTER_REQUESTS_PENDING) if master disable bit has not caused
  13. * the master requests to be disabled.
  14. *
  15. * Disables PCI-Express master access and verifies there are no pending
  16. * requests.
  17. */
  18. s32 igc_disable_pcie_master(struct igc_hw *hw)
  19. {
  20. s32 timeout = MASTER_DISABLE_TIMEOUT;
  21. s32 ret_val = 0;
  22. u32 ctrl;
  23. ctrl = rd32(IGC_CTRL);
  24. ctrl |= IGC_CTRL_GIO_MASTER_DISABLE;
  25. wr32(IGC_CTRL, ctrl);
  26. while (timeout) {
  27. if (!(rd32(IGC_STATUS) &
  28. IGC_STATUS_GIO_MASTER_ENABLE))
  29. break;
  30. usleep_range(2000, 3000);
  31. timeout--;
  32. }
  33. if (!timeout) {
  34. hw_dbg("Master requests are pending.\n");
  35. ret_val = -IGC_ERR_MASTER_REQUESTS_PENDING;
  36. goto out;
  37. }
  38. out:
  39. return ret_val;
  40. }
  41. /**
  42. * igc_init_rx_addrs - Initialize receive addresses
  43. * @hw: pointer to the HW structure
  44. * @rar_count: receive address registers
  45. *
  46. * Setup the receive address registers by setting the base receive address
  47. * register to the devices MAC address and clearing all the other receive
  48. * address registers to 0.
  49. */
  50. void igc_init_rx_addrs(struct igc_hw *hw, u16 rar_count)
  51. {
  52. u8 mac_addr[ETH_ALEN] = {0};
  53. u32 i;
  54. /* Setup the receive address */
  55. hw_dbg("Programming MAC Address into RAR[0]\n");
  56. hw->mac.ops.rar_set(hw, hw->mac.addr, 0);
  57. /* Zero out the other (rar_entry_count - 1) receive addresses */
  58. hw_dbg("Clearing RAR[1-%u]\n", rar_count - 1);
  59. for (i = 1; i < rar_count; i++)
  60. hw->mac.ops.rar_set(hw, mac_addr, i);
  61. }
  62. /**
  63. * igc_set_fc_watermarks - Set flow control high/low watermarks
  64. * @hw: pointer to the HW structure
  65. *
  66. * Sets the flow control high/low threshold (watermark) registers. If
  67. * flow control XON frame transmission is enabled, then set XON frame
  68. * transmission as well.
  69. */
  70. static s32 igc_set_fc_watermarks(struct igc_hw *hw)
  71. {
  72. u32 fcrtl = 0, fcrth = 0;
  73. /* Set the flow control receive threshold registers. Normally,
  74. * these registers will be set to a default threshold that may be
  75. * adjusted later by the driver's runtime code. However, if the
  76. * ability to transmit pause frames is not enabled, then these
  77. * registers will be set to 0.
  78. */
  79. if (hw->fc.current_mode & igc_fc_tx_pause) {
  80. /* We need to set up the Receive Threshold high and low water
  81. * marks as well as (optionally) enabling the transmission of
  82. * XON frames.
  83. */
  84. fcrtl = hw->fc.low_water;
  85. if (hw->fc.send_xon)
  86. fcrtl |= IGC_FCRTL_XONE;
  87. fcrth = hw->fc.high_water;
  88. }
  89. wr32(IGC_FCRTL, fcrtl);
  90. wr32(IGC_FCRTH, fcrth);
  91. return 0;
  92. }
  93. /**
  94. * igc_setup_link - Setup flow control and link settings
  95. * @hw: pointer to the HW structure
  96. *
  97. * Determines which flow control settings to use, then configures flow
  98. * control. Calls the appropriate media-specific link configuration
  99. * function. Assuming the adapter has a valid link partner, a valid link
  100. * should be established. Assumes the hardware has previously been reset
  101. * and the transmitter and receiver are not enabled.
  102. */
  103. s32 igc_setup_link(struct igc_hw *hw)
  104. {
  105. s32 ret_val = 0;
  106. /* In the case of the phy reset being blocked, we already have a link.
  107. * We do not need to set it up again.
  108. */
  109. if (igc_check_reset_block(hw))
  110. goto out;
  111. /* If requested flow control is set to default, set flow control
  112. * to the both 'rx' and 'tx' pause frames.
  113. */
  114. if (hw->fc.requested_mode == igc_fc_default)
  115. hw->fc.requested_mode = igc_fc_full;
  116. /* We want to save off the original Flow Control configuration just
  117. * in case we get disconnected and then reconnected into a different
  118. * hub or switch with different Flow Control capabilities.
  119. */
  120. hw->fc.current_mode = hw->fc.requested_mode;
  121. hw_dbg("After fix-ups FlowControl is now = %x\n", hw->fc.current_mode);
  122. /* Call the necessary media_type subroutine to configure the link. */
  123. ret_val = hw->mac.ops.setup_physical_interface(hw);
  124. if (ret_val)
  125. goto out;
  126. /* Initialize the flow control address, type, and PAUSE timer
  127. * registers to their default values. This is done even if flow
  128. * control is disabled, because it does not hurt anything to
  129. * initialize these registers.
  130. */
  131. hw_dbg("Initializing the Flow Control address, type and timer regs\n");
  132. wr32(IGC_FCT, FLOW_CONTROL_TYPE);
  133. wr32(IGC_FCAH, FLOW_CONTROL_ADDRESS_HIGH);
  134. wr32(IGC_FCAL, FLOW_CONTROL_ADDRESS_LOW);
  135. wr32(IGC_FCTTV, hw->fc.pause_time);
  136. ret_val = igc_set_fc_watermarks(hw);
  137. out:
  138. return ret_val;
  139. }
  140. /**
  141. * igc_force_mac_fc - Force the MAC's flow control settings
  142. * @hw: pointer to the HW structure
  143. *
  144. * Force the MAC's flow control settings. Sets the TFCE and RFCE bits in the
  145. * device control register to reflect the adapter settings. TFCE and RFCE
  146. * need to be explicitly set by software when a copper PHY is used because
  147. * autonegotiation is managed by the PHY rather than the MAC. Software must
  148. * also configure these bits when link is forced on a fiber connection.
  149. */
  150. s32 igc_force_mac_fc(struct igc_hw *hw)
  151. {
  152. s32 ret_val = 0;
  153. u32 ctrl;
  154. ctrl = rd32(IGC_CTRL);
  155. /* Because we didn't get link via the internal auto-negotiation
  156. * mechanism (we either forced link or we got link via PHY
  157. * auto-neg), we have to manually enable/disable transmit an
  158. * receive flow control.
  159. *
  160. * The "Case" statement below enables/disable flow control
  161. * according to the "hw->fc.current_mode" parameter.
  162. *
  163. * The possible values of the "fc" parameter are:
  164. * 0: Flow control is completely disabled
  165. * 1: Rx flow control is enabled (we can receive pause
  166. * frames but not send pause frames).
  167. * 2: Tx flow control is enabled (we can send pause frames
  168. * but we do not receive pause frames).
  169. * 3: Both Rx and TX flow control (symmetric) is enabled.
  170. * other: No other values should be possible at this point.
  171. */
  172. hw_dbg("hw->fc.current_mode = %u\n", hw->fc.current_mode);
  173. switch (hw->fc.current_mode) {
  174. case igc_fc_none:
  175. ctrl &= (~(IGC_CTRL_TFCE | IGC_CTRL_RFCE));
  176. break;
  177. case igc_fc_rx_pause:
  178. ctrl &= (~IGC_CTRL_TFCE);
  179. ctrl |= IGC_CTRL_RFCE;
  180. break;
  181. case igc_fc_tx_pause:
  182. ctrl &= (~IGC_CTRL_RFCE);
  183. ctrl |= IGC_CTRL_TFCE;
  184. break;
  185. case igc_fc_full:
  186. ctrl |= (IGC_CTRL_TFCE | IGC_CTRL_RFCE);
  187. break;
  188. default:
  189. hw_dbg("Flow control param set incorrectly\n");
  190. ret_val = -IGC_ERR_CONFIG;
  191. goto out;
  192. }
  193. wr32(IGC_CTRL, ctrl);
  194. out:
  195. return ret_val;
  196. }
  197. /**
  198. * igc_clear_hw_cntrs_base - Clear base hardware counters
  199. * @hw: pointer to the HW structure
  200. *
  201. * Clears the base hardware counters by reading the counter registers.
  202. */
  203. void igc_clear_hw_cntrs_base(struct igc_hw *hw)
  204. {
  205. rd32(IGC_CRCERRS);
  206. rd32(IGC_MPC);
  207. rd32(IGC_SCC);
  208. rd32(IGC_ECOL);
  209. rd32(IGC_MCC);
  210. rd32(IGC_LATECOL);
  211. rd32(IGC_COLC);
  212. rd32(IGC_RERC);
  213. rd32(IGC_DC);
  214. rd32(IGC_RLEC);
  215. rd32(IGC_XONRXC);
  216. rd32(IGC_XONTXC);
  217. rd32(IGC_XOFFRXC);
  218. rd32(IGC_XOFFTXC);
  219. rd32(IGC_FCRUC);
  220. rd32(IGC_GPRC);
  221. rd32(IGC_BPRC);
  222. rd32(IGC_MPRC);
  223. rd32(IGC_GPTC);
  224. rd32(IGC_GORCL);
  225. rd32(IGC_GORCH);
  226. rd32(IGC_GOTCL);
  227. rd32(IGC_GOTCH);
  228. rd32(IGC_RNBC);
  229. rd32(IGC_RUC);
  230. rd32(IGC_RFC);
  231. rd32(IGC_ROC);
  232. rd32(IGC_RJC);
  233. rd32(IGC_TORL);
  234. rd32(IGC_TORH);
  235. rd32(IGC_TOTL);
  236. rd32(IGC_TOTH);
  237. rd32(IGC_TPR);
  238. rd32(IGC_TPT);
  239. rd32(IGC_MPTC);
  240. rd32(IGC_BPTC);
  241. rd32(IGC_PRC64);
  242. rd32(IGC_PRC127);
  243. rd32(IGC_PRC255);
  244. rd32(IGC_PRC511);
  245. rd32(IGC_PRC1023);
  246. rd32(IGC_PRC1522);
  247. rd32(IGC_PTC64);
  248. rd32(IGC_PTC127);
  249. rd32(IGC_PTC255);
  250. rd32(IGC_PTC511);
  251. rd32(IGC_PTC1023);
  252. rd32(IGC_PTC1522);
  253. rd32(IGC_ALGNERRC);
  254. rd32(IGC_RXERRC);
  255. rd32(IGC_TNCRS);
  256. rd32(IGC_HTDPMC);
  257. rd32(IGC_TSCTC);
  258. rd32(IGC_MGTPRC);
  259. rd32(IGC_MGTPDC);
  260. rd32(IGC_MGTPTC);
  261. rd32(IGC_IAC);
  262. rd32(IGC_RPTHC);
  263. rd32(IGC_TLPIC);
  264. rd32(IGC_RLPIC);
  265. rd32(IGC_HGPTC);
  266. rd32(IGC_RXDMTC);
  267. rd32(IGC_HGORCL);
  268. rd32(IGC_HGORCH);
  269. rd32(IGC_HGOTCL);
  270. rd32(IGC_HGOTCH);
  271. rd32(IGC_LENERRS);
  272. }
  273. /**
  274. * igc_rar_set - Set receive address register
  275. * @hw: pointer to the HW structure
  276. * @addr: pointer to the receive address
  277. * @index: receive address array register
  278. *
  279. * Sets the receive address array register at index to the address passed
  280. * in by addr.
  281. */
  282. void igc_rar_set(struct igc_hw *hw, u8 *addr, u32 index)
  283. {
  284. u32 rar_low, rar_high;
  285. /* HW expects these in little endian so we reverse the byte order
  286. * from network order (big endian) to little endian
  287. */
  288. rar_low = ((u32)addr[0] |
  289. ((u32)addr[1] << 8) |
  290. ((u32)addr[2] << 16) | ((u32)addr[3] << 24));
  291. rar_high = ((u32)addr[4] | ((u32)addr[5] << 8));
  292. /* If MAC address zero, no need to set the AV bit */
  293. if (rar_low || rar_high)
  294. rar_high |= IGC_RAH_AV;
  295. /* Some bridges will combine consecutive 32-bit writes into
  296. * a single burst write, which will malfunction on some parts.
  297. * The flushes avoid this.
  298. */
  299. wr32(IGC_RAL(index), rar_low);
  300. wrfl();
  301. wr32(IGC_RAH(index), rar_high);
  302. wrfl();
  303. }
  304. /**
  305. * igc_check_for_copper_link - Check for link (Copper)
  306. * @hw: pointer to the HW structure
  307. *
  308. * Checks to see of the link status of the hardware has changed. If a
  309. * change in link status has been detected, then we read the PHY registers
  310. * to get the current speed/duplex if link exists.
  311. */
  312. s32 igc_check_for_copper_link(struct igc_hw *hw)
  313. {
  314. struct igc_mac_info *mac = &hw->mac;
  315. bool link = false;
  316. s32 ret_val;
  317. /* We only want to go out to the PHY registers to see if Auto-Neg
  318. * has completed and/or if our link status has changed. The
  319. * get_link_status flag is set upon receiving a Link Status
  320. * Change or Rx Sequence Error interrupt.
  321. */
  322. if (!mac->get_link_status) {
  323. ret_val = 0;
  324. goto out;
  325. }
  326. /* First we want to see if the MII Status Register reports
  327. * link. If so, then we want to get the current speed/duplex
  328. * of the PHY.
  329. */
  330. ret_val = igc_phy_has_link(hw, 1, 0, &link);
  331. if (ret_val)
  332. goto out;
  333. if (!link)
  334. goto out; /* No link detected */
  335. mac->get_link_status = false;
  336. /* Check if there was DownShift, must be checked
  337. * immediately after link-up
  338. */
  339. igc_check_downshift(hw);
  340. /* If we are forcing speed/duplex, then we simply return since
  341. * we have already determined whether we have link or not.
  342. */
  343. if (!mac->autoneg) {
  344. ret_val = -IGC_ERR_CONFIG;
  345. goto out;
  346. }
  347. /* Auto-Neg is enabled. Auto Speed Detection takes care
  348. * of MAC speed/duplex configuration. So we only need to
  349. * configure Collision Distance in the MAC.
  350. */
  351. igc_config_collision_dist(hw);
  352. /* Configure Flow Control now that Auto-Neg has completed.
  353. * First, we need to restore the desired flow control
  354. * settings because we may have had to re-autoneg with a
  355. * different link partner.
  356. */
  357. ret_val = igc_config_fc_after_link_up(hw);
  358. if (ret_val)
  359. hw_dbg("Error configuring flow control\n");
  360. out:
  361. /* Now that we are aware of our link settings, we can set the LTR
  362. * thresholds.
  363. */
  364. ret_val = igc_set_ltr_i225(hw, link);
  365. return ret_val;
  366. }
  367. /**
  368. * igc_config_collision_dist - Configure collision distance
  369. * @hw: pointer to the HW structure
  370. *
  371. * Configures the collision distance to the default value and is used
  372. * during link setup. Currently no func pointer exists and all
  373. * implementations are handled in the generic version of this function.
  374. */
  375. void igc_config_collision_dist(struct igc_hw *hw)
  376. {
  377. u32 tctl;
  378. tctl = rd32(IGC_TCTL);
  379. tctl &= ~IGC_TCTL_COLD;
  380. tctl |= IGC_COLLISION_DISTANCE << IGC_COLD_SHIFT;
  381. wr32(IGC_TCTL, tctl);
  382. wrfl();
  383. }
  384. /**
  385. * igc_config_fc_after_link_up - Configures flow control after link
  386. * @hw: pointer to the HW structure
  387. *
  388. * Checks the status of auto-negotiation after link up to ensure that the
  389. * speed and duplex were not forced. If the link needed to be forced, then
  390. * flow control needs to be forced also. If auto-negotiation is enabled
  391. * and did not fail, then we configure flow control based on our link
  392. * partner.
  393. */
  394. s32 igc_config_fc_after_link_up(struct igc_hw *hw)
  395. {
  396. u16 mii_status_reg, mii_nway_adv_reg, mii_nway_lp_ability_reg;
  397. struct igc_mac_info *mac = &hw->mac;
  398. u16 speed, duplex;
  399. s32 ret_val = 0;
  400. /* Check for the case where we have fiber media and auto-neg failed
  401. * so we had to force link. In this case, we need to force the
  402. * configuration of the MAC to match the "fc" parameter.
  403. */
  404. if (mac->autoneg_failed)
  405. ret_val = igc_force_mac_fc(hw);
  406. if (ret_val) {
  407. hw_dbg("Error forcing flow control settings\n");
  408. goto out;
  409. }
  410. /* Check for the case where we have copper media and auto-neg is
  411. * enabled. In this case, we need to check and see if Auto-Neg
  412. * has completed, and if so, how the PHY and link partner has
  413. * flow control configured.
  414. */
  415. if (mac->autoneg) {
  416. /* Read the MII Status Register and check to see if AutoNeg
  417. * has completed. We read this twice because this reg has
  418. * some "sticky" (latched) bits.
  419. */
  420. ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS,
  421. &mii_status_reg);
  422. if (ret_val)
  423. goto out;
  424. ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS,
  425. &mii_status_reg);
  426. if (ret_val)
  427. goto out;
  428. if (!(mii_status_reg & MII_SR_AUTONEG_COMPLETE)) {
  429. hw_dbg("Copper PHY and Auto Neg has not completed.\n");
  430. goto out;
  431. }
  432. /* The AutoNeg process has completed, so we now need to
  433. * read both the Auto Negotiation Advertisement
  434. * Register (Address 4) and the Auto_Negotiation Base
  435. * Page Ability Register (Address 5) to determine how
  436. * flow control was negotiated.
  437. */
  438. ret_val = hw->phy.ops.read_reg(hw, PHY_AUTONEG_ADV,
  439. &mii_nway_adv_reg);
  440. if (ret_val)
  441. goto out;
  442. ret_val = hw->phy.ops.read_reg(hw, PHY_LP_ABILITY,
  443. &mii_nway_lp_ability_reg);
  444. if (ret_val)
  445. goto out;
  446. /* Two bits in the Auto Negotiation Advertisement Register
  447. * (Address 4) and two bits in the Auto Negotiation Base
  448. * Page Ability Register (Address 5) determine flow control
  449. * for both the PHY and the link partner. The following
  450. * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
  451. * 1999, describes these PAUSE resolution bits and how flow
  452. * control is determined based upon these settings.
  453. * NOTE: DC = Don't Care
  454. *
  455. * LOCAL DEVICE | LINK PARTNER
  456. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
  457. *-------|---------|-------|---------|--------------------
  458. * 0 | 0 | DC | DC | igc_fc_none
  459. * 0 | 1 | 0 | DC | igc_fc_none
  460. * 0 | 1 | 1 | 0 | igc_fc_none
  461. * 0 | 1 | 1 | 1 | igc_fc_tx_pause
  462. * 1 | 0 | 0 | DC | igc_fc_none
  463. * 1 | DC | 1 | DC | igc_fc_full
  464. * 1 | 1 | 0 | 0 | igc_fc_none
  465. * 1 | 1 | 0 | 1 | igc_fc_rx_pause
  466. *
  467. * Are both PAUSE bits set to 1? If so, this implies
  468. * Symmetric Flow Control is enabled at both ends. The
  469. * ASM_DIR bits are irrelevant per the spec.
  470. *
  471. * For Symmetric Flow Control:
  472. *
  473. * LOCAL DEVICE | LINK PARTNER
  474. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
  475. *-------|---------|-------|---------|--------------------
  476. * 1 | DC | 1 | DC | IGC_fc_full
  477. *
  478. */
  479. if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
  480. (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
  481. /* Now we need to check if the user selected RX ONLY
  482. * of pause frames. In this case, we had to advertise
  483. * FULL flow control because we could not advertise RX
  484. * ONLY. Hence, we must now check to see if we need to
  485. * turn OFF the TRANSMISSION of PAUSE frames.
  486. */
  487. if (hw->fc.requested_mode == igc_fc_full) {
  488. hw->fc.current_mode = igc_fc_full;
  489. hw_dbg("Flow Control = FULL.\n");
  490. } else {
  491. hw->fc.current_mode = igc_fc_rx_pause;
  492. hw_dbg("Flow Control = RX PAUSE frames only.\n");
  493. }
  494. }
  495. /* For receiving PAUSE frames ONLY.
  496. *
  497. * LOCAL DEVICE | LINK PARTNER
  498. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
  499. *-------|---------|-------|---------|--------------------
  500. * 0 | 1 | 1 | 1 | igc_fc_tx_pause
  501. */
  502. else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
  503. (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
  504. (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
  505. (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
  506. hw->fc.current_mode = igc_fc_tx_pause;
  507. hw_dbg("Flow Control = TX PAUSE frames only.\n");
  508. }
  509. /* For transmitting PAUSE frames ONLY.
  510. *
  511. * LOCAL DEVICE | LINK PARTNER
  512. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
  513. *-------|---------|-------|---------|--------------------
  514. * 1 | 1 | 0 | 1 | igc_fc_rx_pause
  515. */
  516. else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
  517. (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
  518. !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
  519. (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
  520. hw->fc.current_mode = igc_fc_rx_pause;
  521. hw_dbg("Flow Control = RX PAUSE frames only.\n");
  522. }
  523. /* Per the IEEE spec, at this point flow control should be
  524. * disabled. However, we want to consider that we could
  525. * be connected to a legacy switch that doesn't advertise
  526. * desired flow control, but can be forced on the link
  527. * partner. So if we advertised no flow control, that is
  528. * what we will resolve to. If we advertised some kind of
  529. * receive capability (Rx Pause Only or Full Flow Control)
  530. * and the link partner advertised none, we will configure
  531. * ourselves to enable Rx Flow Control only. We can do
  532. * this safely for two reasons: If the link partner really
  533. * didn't want flow control enabled, and we enable Rx, no
  534. * harm done since we won't be receiving any PAUSE frames
  535. * anyway. If the intent on the link partner was to have
  536. * flow control enabled, then by us enabling RX only, we
  537. * can at least receive pause frames and process them.
  538. * This is a good idea because in most cases, since we are
  539. * predominantly a server NIC, more times than not we will
  540. * be asked to delay transmission of packets than asking
  541. * our link partner to pause transmission of frames.
  542. */
  543. else if ((hw->fc.requested_mode == igc_fc_none) ||
  544. (hw->fc.requested_mode == igc_fc_tx_pause) ||
  545. (hw->fc.strict_ieee)) {
  546. hw->fc.current_mode = igc_fc_none;
  547. hw_dbg("Flow Control = NONE.\n");
  548. } else {
  549. hw->fc.current_mode = igc_fc_rx_pause;
  550. hw_dbg("Flow Control = RX PAUSE frames only.\n");
  551. }
  552. /* Now we need to do one last check... If we auto-
  553. * negotiated to HALF DUPLEX, flow control should not be
  554. * enabled per IEEE 802.3 spec.
  555. */
  556. ret_val = hw->mac.ops.get_speed_and_duplex(hw, &speed, &duplex);
  557. if (ret_val) {
  558. hw_dbg("Error getting link speed and duplex\n");
  559. goto out;
  560. }
  561. if (duplex == HALF_DUPLEX)
  562. hw->fc.current_mode = igc_fc_none;
  563. /* Now we call a subroutine to actually force the MAC
  564. * controller to use the correct flow control settings.
  565. */
  566. ret_val = igc_force_mac_fc(hw);
  567. if (ret_val) {
  568. hw_dbg("Error forcing flow control settings\n");
  569. goto out;
  570. }
  571. }
  572. out:
  573. return ret_val;
  574. }
  575. /**
  576. * igc_get_auto_rd_done - Check for auto read completion
  577. * @hw: pointer to the HW structure
  578. *
  579. * Check EEPROM for Auto Read done bit.
  580. */
  581. s32 igc_get_auto_rd_done(struct igc_hw *hw)
  582. {
  583. s32 ret_val = 0;
  584. s32 i = 0;
  585. while (i < AUTO_READ_DONE_TIMEOUT) {
  586. if (rd32(IGC_EECD) & IGC_EECD_AUTO_RD)
  587. break;
  588. usleep_range(1000, 2000);
  589. i++;
  590. }
  591. if (i == AUTO_READ_DONE_TIMEOUT) {
  592. hw_dbg("Auto read by HW from NVM has not completed.\n");
  593. ret_val = -IGC_ERR_RESET;
  594. goto out;
  595. }
  596. out:
  597. return ret_val;
  598. }
  599. /**
  600. * igc_get_speed_and_duplex_copper - Retrieve current speed/duplex
  601. * @hw: pointer to the HW structure
  602. * @speed: stores the current speed
  603. * @duplex: stores the current duplex
  604. *
  605. * Read the status register for the current speed/duplex and store the current
  606. * speed and duplex for copper connections.
  607. */
  608. s32 igc_get_speed_and_duplex_copper(struct igc_hw *hw, u16 *speed,
  609. u16 *duplex)
  610. {
  611. u32 status;
  612. status = rd32(IGC_STATUS);
  613. if (status & IGC_STATUS_SPEED_1000) {
  614. /* For I225, STATUS will indicate 1G speed in both 1 Gbps
  615. * and 2.5 Gbps link modes. An additional bit is used
  616. * to differentiate between 1 Gbps and 2.5 Gbps.
  617. */
  618. if (hw->mac.type == igc_i225 &&
  619. (status & IGC_STATUS_SPEED_2500)) {
  620. *speed = SPEED_2500;
  621. hw_dbg("2500 Mbs, ");
  622. } else {
  623. *speed = SPEED_1000;
  624. hw_dbg("1000 Mbs, ");
  625. }
  626. } else if (status & IGC_STATUS_SPEED_100) {
  627. *speed = SPEED_100;
  628. hw_dbg("100 Mbs, ");
  629. } else {
  630. *speed = SPEED_10;
  631. hw_dbg("10 Mbs, ");
  632. }
  633. if (status & IGC_STATUS_FD) {
  634. *duplex = FULL_DUPLEX;
  635. hw_dbg("Full Duplex\n");
  636. } else {
  637. *duplex = HALF_DUPLEX;
  638. hw_dbg("Half Duplex\n");
  639. }
  640. return 0;
  641. }
  642. /**
  643. * igc_put_hw_semaphore - Release hardware semaphore
  644. * @hw: pointer to the HW structure
  645. *
  646. * Release hardware semaphore used to access the PHY or NVM
  647. */
  648. void igc_put_hw_semaphore(struct igc_hw *hw)
  649. {
  650. u32 swsm;
  651. swsm = rd32(IGC_SWSM);
  652. swsm &= ~(IGC_SWSM_SMBI | IGC_SWSM_SWESMBI);
  653. wr32(IGC_SWSM, swsm);
  654. }
  655. /**
  656. * igc_enable_mng_pass_thru - Enable processing of ARP's
  657. * @hw: pointer to the HW structure
  658. *
  659. * Verifies the hardware needs to leave interface enabled so that frames can
  660. * be directed to and from the management interface.
  661. */
  662. bool igc_enable_mng_pass_thru(struct igc_hw *hw)
  663. {
  664. bool ret_val = false;
  665. u32 fwsm, factps;
  666. u32 manc;
  667. if (!hw->mac.asf_firmware_present)
  668. goto out;
  669. manc = rd32(IGC_MANC);
  670. if (!(manc & IGC_MANC_RCV_TCO_EN))
  671. goto out;
  672. if (hw->mac.arc_subsystem_valid) {
  673. fwsm = rd32(IGC_FWSM);
  674. factps = rd32(IGC_FACTPS);
  675. if (!(factps & IGC_FACTPS_MNGCG) &&
  676. ((fwsm & IGC_FWSM_MODE_MASK) ==
  677. (igc_mng_mode_pt << IGC_FWSM_MODE_SHIFT))) {
  678. ret_val = true;
  679. goto out;
  680. }
  681. } else {
  682. if ((manc & IGC_MANC_SMBUS_EN) &&
  683. !(manc & IGC_MANC_ASF_EN)) {
  684. ret_val = true;
  685. goto out;
  686. }
  687. }
  688. out:
  689. return ret_val;
  690. }
  691. /**
  692. * igc_hash_mc_addr - Generate a multicast hash value
  693. * @hw: pointer to the HW structure
  694. * @mc_addr: pointer to a multicast address
  695. *
  696. * Generates a multicast address hash value which is used to determine
  697. * the multicast filter table array address and new table value. See
  698. * igc_mta_set()
  699. **/
  700. static u32 igc_hash_mc_addr(struct igc_hw *hw, u8 *mc_addr)
  701. {
  702. u32 hash_value, hash_mask;
  703. u8 bit_shift = 0;
  704. /* Register count multiplied by bits per register */
  705. hash_mask = (hw->mac.mta_reg_count * 32) - 1;
  706. /* For a mc_filter_type of 0, bit_shift is the number of left-shifts
  707. * where 0xFF would still fall within the hash mask.
  708. */
  709. while (hash_mask >> bit_shift != 0xFF)
  710. bit_shift++;
  711. /* The portion of the address that is used for the hash table
  712. * is determined by the mc_filter_type setting.
  713. * The algorithm is such that there is a total of 8 bits of shifting.
  714. * The bit_shift for a mc_filter_type of 0 represents the number of
  715. * left-shifts where the MSB of mc_addr[5] would still fall within
  716. * the hash_mask. Case 0 does this exactly. Since there are a total
  717. * of 8 bits of shifting, then mc_addr[4] will shift right the
  718. * remaining number of bits. Thus 8 - bit_shift. The rest of the
  719. * cases are a variation of this algorithm...essentially raising the
  720. * number of bits to shift mc_addr[5] left, while still keeping the
  721. * 8-bit shifting total.
  722. *
  723. * For example, given the following Destination MAC Address and an
  724. * MTA register count of 128 (thus a 4096-bit vector and 0xFFF mask),
  725. * we can see that the bit_shift for case 0 is 4. These are the hash
  726. * values resulting from each mc_filter_type...
  727. * [0] [1] [2] [3] [4] [5]
  728. * 01 AA 00 12 34 56
  729. * LSB MSB
  730. *
  731. * case 0: hash_value = ((0x34 >> 4) | (0x56 << 4)) & 0xFFF = 0x563
  732. * case 1: hash_value = ((0x34 >> 3) | (0x56 << 5)) & 0xFFF = 0xAC6
  733. * case 2: hash_value = ((0x34 >> 2) | (0x56 << 6)) & 0xFFF = 0x163
  734. * case 3: hash_value = ((0x34 >> 0) | (0x56 << 8)) & 0xFFF = 0x634
  735. */
  736. switch (hw->mac.mc_filter_type) {
  737. default:
  738. case 0:
  739. break;
  740. case 1:
  741. bit_shift += 1;
  742. break;
  743. case 2:
  744. bit_shift += 2;
  745. break;
  746. case 3:
  747. bit_shift += 4;
  748. break;
  749. }
  750. hash_value = hash_mask & (((mc_addr[4] >> (8 - bit_shift)) |
  751. (((u16)mc_addr[5]) << bit_shift)));
  752. return hash_value;
  753. }
  754. /**
  755. * igc_update_mc_addr_list - Update Multicast addresses
  756. * @hw: pointer to the HW structure
  757. * @mc_addr_list: array of multicast addresses to program
  758. * @mc_addr_count: number of multicast addresses to program
  759. *
  760. * Updates entire Multicast Table Array.
  761. * The caller must have a packed mc_addr_list of multicast addresses.
  762. **/
  763. void igc_update_mc_addr_list(struct igc_hw *hw,
  764. u8 *mc_addr_list, u32 mc_addr_count)
  765. {
  766. u32 hash_value, hash_bit, hash_reg;
  767. int i;
  768. /* clear mta_shadow */
  769. memset(&hw->mac.mta_shadow, 0, sizeof(hw->mac.mta_shadow));
  770. /* update mta_shadow from mc_addr_list */
  771. for (i = 0; (u32)i < mc_addr_count; i++) {
  772. hash_value = igc_hash_mc_addr(hw, mc_addr_list);
  773. hash_reg = (hash_value >> 5) & (hw->mac.mta_reg_count - 1);
  774. hash_bit = hash_value & 0x1F;
  775. hw->mac.mta_shadow[hash_reg] |= BIT(hash_bit);
  776. mc_addr_list += ETH_ALEN;
  777. }
  778. /* replace the entire MTA table */
  779. for (i = hw->mac.mta_reg_count - 1; i >= 0; i--)
  780. array_wr32(IGC_MTA, i, hw->mac.mta_shadow[i]);
  781. wrfl();
  782. }