mac.c 52 KB

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