mac.c 51 KB

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