mac.c 52 KB

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