mac.c 51 KB

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