mac.c 52 KB

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