mac.c 52 KB

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