mac.c 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800
  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. 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. }
  702. ew32(TXCW, txcw);
  703. mac->txcw = txcw;
  704. return 0;
  705. }
  706. /**
  707. * e1000_poll_fiber_serdes_link_generic - Poll for link up
  708. * @hw: pointer to the HW structure
  709. *
  710. * Polls for link up by reading the status register, if link fails to come
  711. * up with auto-negotiation, then the link is forced if a signal is detected.
  712. **/
  713. static s32 e1000_poll_fiber_serdes_link_generic(struct e1000_hw *hw)
  714. {
  715. struct e1000_mac_info *mac = &hw->mac;
  716. u32 i, status;
  717. s32 ret_val;
  718. /* If we have a signal (the cable is plugged in, or assumed true for
  719. * serdes media) then poll for a "Link-Up" indication in the Device
  720. * Status Register. Time-out if a link isn't seen in 500 milliseconds
  721. * seconds (Auto-negotiation should complete in less than 500
  722. * milliseconds even if the other end is doing it in SW).
  723. */
  724. for (i = 0; i < FIBER_LINK_UP_LIMIT; i++) {
  725. usleep_range(10000, 20000);
  726. status = er32(STATUS);
  727. if (status & E1000_STATUS_LU)
  728. break;
  729. }
  730. if (i == FIBER_LINK_UP_LIMIT) {
  731. e_dbg("Never got a valid link from auto-neg!!!\n");
  732. mac->autoneg_failed = true;
  733. /* AutoNeg failed to achieve a link, so we'll call
  734. * mac->check_for_link. This routine will force the
  735. * link up if we detect a signal. This will allow us to
  736. * communicate with non-autonegotiating link partners.
  737. */
  738. ret_val = mac->ops.check_for_link(hw);
  739. if (ret_val) {
  740. e_dbg("Error while checking for link\n");
  741. return ret_val;
  742. }
  743. mac->autoneg_failed = false;
  744. } else {
  745. mac->autoneg_failed = false;
  746. e_dbg("Valid Link Found\n");
  747. }
  748. return 0;
  749. }
  750. /**
  751. * e1000e_setup_fiber_serdes_link - Setup link for fiber/serdes
  752. * @hw: pointer to the HW structure
  753. *
  754. * Configures collision distance and flow control for fiber and serdes
  755. * links. Upon successful setup, poll for link.
  756. **/
  757. s32 e1000e_setup_fiber_serdes_link(struct e1000_hw *hw)
  758. {
  759. u32 ctrl;
  760. s32 ret_val;
  761. ctrl = er32(CTRL);
  762. /* Take the link out of reset */
  763. ctrl &= ~E1000_CTRL_LRST;
  764. hw->mac.ops.config_collision_dist(hw);
  765. ret_val = e1000_commit_fc_settings_generic(hw);
  766. if (ret_val)
  767. return ret_val;
  768. /* Since auto-negotiation is enabled, take the link out of reset (the
  769. * link will be in reset, because we previously reset the chip). This
  770. * will restart auto-negotiation. If auto-negotiation is successful
  771. * then the link-up status bit will be set and the flow control enable
  772. * bits (RFCE and TFCE) will be set according to their negotiated value.
  773. */
  774. e_dbg("Auto-negotiation enabled\n");
  775. ew32(CTRL, ctrl);
  776. e1e_flush();
  777. usleep_range(1000, 2000);
  778. /* For these adapters, the SW definable pin 1 is set when the optics
  779. * detect a signal. If we have a signal, then poll for a "Link-Up"
  780. * indication.
  781. */
  782. if (hw->phy.media_type == e1000_media_type_internal_serdes ||
  783. (er32(CTRL) & E1000_CTRL_SWDPIN1)) {
  784. ret_val = e1000_poll_fiber_serdes_link_generic(hw);
  785. } else {
  786. e_dbg("No signal detected\n");
  787. }
  788. return ret_val;
  789. }
  790. /**
  791. * e1000e_config_collision_dist_generic - Configure collision distance
  792. * @hw: pointer to the HW structure
  793. *
  794. * Configures the collision distance to the default value and is used
  795. * during link setup.
  796. **/
  797. void e1000e_config_collision_dist_generic(struct e1000_hw *hw)
  798. {
  799. u32 tctl;
  800. tctl = er32(TCTL);
  801. tctl &= ~E1000_TCTL_COLD;
  802. tctl |= E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT;
  803. ew32(TCTL, tctl);
  804. e1e_flush();
  805. }
  806. /**
  807. * e1000e_set_fc_watermarks - Set flow control high/low watermarks
  808. * @hw: pointer to the HW structure
  809. *
  810. * Sets the flow control high/low threshold (watermark) registers. If
  811. * flow control XON frame transmission is enabled, then set XON frame
  812. * transmission as well.
  813. **/
  814. s32 e1000e_set_fc_watermarks(struct e1000_hw *hw)
  815. {
  816. u32 fcrtl = 0, fcrth = 0;
  817. /* Set the flow control receive threshold registers. Normally,
  818. * these registers will be set to a default threshold that may be
  819. * adjusted later by the driver's runtime code. However, if the
  820. * ability to transmit pause frames is not enabled, then these
  821. * registers will be set to 0.
  822. */
  823. if (hw->fc.current_mode & e1000_fc_tx_pause) {
  824. /* We need to set up the Receive Threshold high and low water
  825. * marks as well as (optionally) enabling the transmission of
  826. * XON frames.
  827. */
  828. fcrtl = hw->fc.low_water;
  829. if (hw->fc.send_xon)
  830. fcrtl |= E1000_FCRTL_XONE;
  831. fcrth = hw->fc.high_water;
  832. }
  833. ew32(FCRTL, fcrtl);
  834. ew32(FCRTH, fcrth);
  835. return 0;
  836. }
  837. /**
  838. * e1000e_force_mac_fc - Force the MAC's flow control settings
  839. * @hw: pointer to the HW structure
  840. *
  841. * Force the MAC's flow control settings. Sets the TFCE and RFCE bits in the
  842. * device control register to reflect the adapter settings. TFCE and RFCE
  843. * need to be explicitly set by software when a copper PHY is used because
  844. * autonegotiation is managed by the PHY rather than the MAC. Software must
  845. * also configure these bits when link is forced on a fiber connection.
  846. **/
  847. s32 e1000e_force_mac_fc(struct e1000_hw *hw)
  848. {
  849. u32 ctrl;
  850. ctrl = er32(CTRL);
  851. /* Because we didn't get link via the internal auto-negotiation
  852. * mechanism (we either forced link or we got link via PHY
  853. * auto-neg), we have to manually enable/disable transmit an
  854. * receive flow control.
  855. *
  856. * The "Case" statement below enables/disable flow control
  857. * according to the "hw->fc.current_mode" parameter.
  858. *
  859. * The possible values of the "fc" parameter are:
  860. * 0: Flow control is completely disabled
  861. * 1: Rx flow control is enabled (we can receive pause
  862. * frames but not send pause frames).
  863. * 2: Tx flow control is enabled (we can send pause frames
  864. * frames but we do not receive pause frames).
  865. * 3: Both Rx and Tx flow control (symmetric) is enabled.
  866. * other: No other values should be possible at this point.
  867. */
  868. e_dbg("hw->fc.current_mode = %u\n", hw->fc.current_mode);
  869. switch (hw->fc.current_mode) {
  870. case e1000_fc_none:
  871. ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
  872. break;
  873. case e1000_fc_rx_pause:
  874. ctrl &= (~E1000_CTRL_TFCE);
  875. ctrl |= E1000_CTRL_RFCE;
  876. break;
  877. case e1000_fc_tx_pause:
  878. ctrl &= (~E1000_CTRL_RFCE);
  879. ctrl |= E1000_CTRL_TFCE;
  880. break;
  881. case e1000_fc_full:
  882. ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
  883. break;
  884. default:
  885. e_dbg("Flow control param set incorrectly\n");
  886. return -E1000_ERR_CONFIG;
  887. }
  888. ew32(CTRL, ctrl);
  889. return 0;
  890. }
  891. /**
  892. * e1000e_config_fc_after_link_up - Configures flow control after link
  893. * @hw: pointer to the HW structure
  894. *
  895. * Checks the status of auto-negotiation after link up to ensure that the
  896. * speed and duplex were not forced. If the link needed to be forced, then
  897. * flow control needs to be forced also. If auto-negotiation is enabled
  898. * and did not fail, then we configure flow control based on our link
  899. * partner.
  900. **/
  901. s32 e1000e_config_fc_after_link_up(struct e1000_hw *hw)
  902. {
  903. struct e1000_mac_info *mac = &hw->mac;
  904. s32 ret_val = 0;
  905. u32 pcs_status_reg, pcs_adv_reg, pcs_lp_ability_reg, pcs_ctrl_reg;
  906. u16 mii_status_reg, mii_nway_adv_reg, mii_nway_lp_ability_reg;
  907. u16 speed, duplex;
  908. /* Check for the case where we have fiber media and auto-neg failed
  909. * so we had to force link. In this case, we need to force the
  910. * configuration of the MAC to match the "fc" parameter.
  911. */
  912. if (mac->autoneg_failed) {
  913. if (hw->phy.media_type == e1000_media_type_fiber ||
  914. hw->phy.media_type == e1000_media_type_internal_serdes)
  915. ret_val = e1000e_force_mac_fc(hw);
  916. } else {
  917. if (hw->phy.media_type == e1000_media_type_copper)
  918. ret_val = e1000e_force_mac_fc(hw);
  919. }
  920. if (ret_val) {
  921. e_dbg("Error forcing flow control settings\n");
  922. return ret_val;
  923. }
  924. /* Check for the case where we have copper media and auto-neg is
  925. * enabled. In this case, we need to check and see if Auto-Neg
  926. * has completed, and if so, how the PHY and link partner has
  927. * flow control configured.
  928. */
  929. if ((hw->phy.media_type == e1000_media_type_copper) && mac->autoneg) {
  930. /* Read the MII Status Register and check to see if AutoNeg
  931. * has completed. We read this twice because this reg has
  932. * some "sticky" (latched) bits.
  933. */
  934. ret_val = e1e_rphy(hw, MII_BMSR, &mii_status_reg);
  935. if (ret_val)
  936. return ret_val;
  937. ret_val = e1e_rphy(hw, MII_BMSR, &mii_status_reg);
  938. if (ret_val)
  939. return ret_val;
  940. if (!(mii_status_reg & BMSR_ANEGCOMPLETE)) {
  941. e_dbg("Copper PHY and Auto Neg has not completed.\n");
  942. return ret_val;
  943. }
  944. /* The AutoNeg process has completed, so we now need to
  945. * read both the Auto Negotiation Advertisement
  946. * Register (Address 4) and the Auto_Negotiation Base
  947. * Page Ability Register (Address 5) to determine how
  948. * flow control was negotiated.
  949. */
  950. ret_val = e1e_rphy(hw, MII_ADVERTISE, &mii_nway_adv_reg);
  951. if (ret_val)
  952. return ret_val;
  953. ret_val = e1e_rphy(hw, MII_LPA, &mii_nway_lp_ability_reg);
  954. if (ret_val)
  955. return ret_val;
  956. /* Two bits in the Auto Negotiation Advertisement Register
  957. * (Address 4) and two bits in the Auto Negotiation Base
  958. * Page Ability Register (Address 5) determine flow control
  959. * for both the PHY and the link partner. The following
  960. * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
  961. * 1999, describes these PAUSE resolution bits and how flow
  962. * control is determined based upon these settings.
  963. * NOTE: DC = Don't Care
  964. *
  965. * LOCAL DEVICE | LINK PARTNER
  966. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
  967. *-------|---------|-------|---------|--------------------
  968. * 0 | 0 | DC | DC | e1000_fc_none
  969. * 0 | 1 | 0 | DC | e1000_fc_none
  970. * 0 | 1 | 1 | 0 | e1000_fc_none
  971. * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
  972. * 1 | 0 | 0 | DC | e1000_fc_none
  973. * 1 | DC | 1 | DC | e1000_fc_full
  974. * 1 | 1 | 0 | 0 | e1000_fc_none
  975. * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
  976. *
  977. * Are both PAUSE bits set to 1? If so, this implies
  978. * Symmetric Flow Control is enabled at both ends. The
  979. * ASM_DIR bits are irrelevant per the spec.
  980. *
  981. * For Symmetric Flow Control:
  982. *
  983. * LOCAL DEVICE | LINK PARTNER
  984. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
  985. *-------|---------|-------|---------|--------------------
  986. * 1 | DC | 1 | DC | E1000_fc_full
  987. *
  988. */
  989. if ((mii_nway_adv_reg & ADVERTISE_PAUSE_CAP) &&
  990. (mii_nway_lp_ability_reg & LPA_PAUSE_CAP)) {
  991. /* Now we need to check if the user selected Rx ONLY
  992. * of pause frames. In this case, we had to advertise
  993. * FULL flow control because we could not advertise Rx
  994. * ONLY. Hence, we must now check to see if we need to
  995. * turn OFF the TRANSMISSION of PAUSE frames.
  996. */
  997. if (hw->fc.requested_mode == e1000_fc_full) {
  998. hw->fc.current_mode = e1000_fc_full;
  999. e_dbg("Flow Control = FULL.\n");
  1000. } else {
  1001. hw->fc.current_mode = e1000_fc_rx_pause;
  1002. e_dbg("Flow Control = Rx PAUSE frames only.\n");
  1003. }
  1004. }
  1005. /* For receiving PAUSE frames ONLY.
  1006. *
  1007. * LOCAL DEVICE | LINK PARTNER
  1008. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
  1009. *-------|---------|-------|---------|--------------------
  1010. * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
  1011. */
  1012. else if (!(mii_nway_adv_reg & ADVERTISE_PAUSE_CAP) &&
  1013. (mii_nway_adv_reg & ADVERTISE_PAUSE_ASYM) &&
  1014. (mii_nway_lp_ability_reg & LPA_PAUSE_CAP) &&
  1015. (mii_nway_lp_ability_reg & LPA_PAUSE_ASYM)) {
  1016. hw->fc.current_mode = e1000_fc_tx_pause;
  1017. e_dbg("Flow Control = Tx PAUSE frames only.\n");
  1018. }
  1019. /* For transmitting PAUSE frames ONLY.
  1020. *
  1021. * LOCAL DEVICE | LINK PARTNER
  1022. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
  1023. *-------|---------|-------|---------|--------------------
  1024. * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
  1025. */
  1026. else if ((mii_nway_adv_reg & ADVERTISE_PAUSE_CAP) &&
  1027. (mii_nway_adv_reg & ADVERTISE_PAUSE_ASYM) &&
  1028. !(mii_nway_lp_ability_reg & LPA_PAUSE_CAP) &&
  1029. (mii_nway_lp_ability_reg & LPA_PAUSE_ASYM)) {
  1030. hw->fc.current_mode = e1000_fc_rx_pause;
  1031. e_dbg("Flow Control = Rx PAUSE frames only.\n");
  1032. } else {
  1033. /* Per the IEEE spec, at this point flow control
  1034. * should be disabled.
  1035. */
  1036. hw->fc.current_mode = e1000_fc_none;
  1037. e_dbg("Flow Control = NONE.\n");
  1038. }
  1039. /* Now we need to do one last check... If we auto-
  1040. * negotiated to HALF DUPLEX, flow control should not be
  1041. * enabled per IEEE 802.3 spec.
  1042. */
  1043. ret_val = mac->ops.get_link_up_info(hw, &speed, &duplex);
  1044. if (ret_val) {
  1045. e_dbg("Error getting link speed and duplex\n");
  1046. return ret_val;
  1047. }
  1048. if (duplex == HALF_DUPLEX)
  1049. hw->fc.current_mode = e1000_fc_none;
  1050. /* Now we call a subroutine to actually force the MAC
  1051. * controller to use the correct flow control settings.
  1052. */
  1053. ret_val = e1000e_force_mac_fc(hw);
  1054. if (ret_val) {
  1055. e_dbg("Error forcing flow control settings\n");
  1056. return ret_val;
  1057. }
  1058. }
  1059. /* Check for the case where we have SerDes media and auto-neg is
  1060. * enabled. In this case, we need to check and see if Auto-Neg
  1061. * has completed, and if so, how the PHY and link partner has
  1062. * flow control configured.
  1063. */
  1064. if ((hw->phy.media_type == e1000_media_type_internal_serdes) &&
  1065. mac->autoneg) {
  1066. /* Read the PCS_LSTS and check to see if AutoNeg
  1067. * has completed.
  1068. */
  1069. pcs_status_reg = er32(PCS_LSTAT);
  1070. if (!(pcs_status_reg & E1000_PCS_LSTS_AN_COMPLETE)) {
  1071. e_dbg("PCS Auto Neg has not completed.\n");
  1072. return ret_val;
  1073. }
  1074. /* The AutoNeg process has completed, so we now need to
  1075. * read both the Auto Negotiation Advertisement
  1076. * Register (PCS_ANADV) and the Auto_Negotiation Base
  1077. * Page Ability Register (PCS_LPAB) to determine how
  1078. * flow control was negotiated.
  1079. */
  1080. pcs_adv_reg = er32(PCS_ANADV);
  1081. pcs_lp_ability_reg = er32(PCS_LPAB);
  1082. /* Two bits in the Auto Negotiation Advertisement Register
  1083. * (PCS_ANADV) and two bits in the Auto Negotiation Base
  1084. * Page Ability Register (PCS_LPAB) determine flow control
  1085. * for both the PHY and the link partner. The following
  1086. * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
  1087. * 1999, describes these PAUSE resolution bits and how flow
  1088. * control is determined based upon these settings.
  1089. * NOTE: DC = Don't Care
  1090. *
  1091. * LOCAL DEVICE | LINK PARTNER
  1092. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
  1093. *-------|---------|-------|---------|--------------------
  1094. * 0 | 0 | DC | DC | e1000_fc_none
  1095. * 0 | 1 | 0 | DC | e1000_fc_none
  1096. * 0 | 1 | 1 | 0 | e1000_fc_none
  1097. * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
  1098. * 1 | 0 | 0 | DC | e1000_fc_none
  1099. * 1 | DC | 1 | DC | e1000_fc_full
  1100. * 1 | 1 | 0 | 0 | e1000_fc_none
  1101. * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
  1102. *
  1103. * Are both PAUSE bits set to 1? If so, this implies
  1104. * Symmetric Flow Control is enabled at both ends. The
  1105. * ASM_DIR bits are irrelevant per the spec.
  1106. *
  1107. * For Symmetric Flow Control:
  1108. *
  1109. * LOCAL DEVICE | LINK PARTNER
  1110. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
  1111. *-------|---------|-------|---------|--------------------
  1112. * 1 | DC | 1 | DC | e1000_fc_full
  1113. *
  1114. */
  1115. if ((pcs_adv_reg & E1000_TXCW_PAUSE) &&
  1116. (pcs_lp_ability_reg & E1000_TXCW_PAUSE)) {
  1117. /* Now we need to check if the user selected Rx ONLY
  1118. * of pause frames. In this case, we had to advertise
  1119. * FULL flow control because we could not advertise Rx
  1120. * ONLY. Hence, we must now check to see if we need to
  1121. * turn OFF the TRANSMISSION of PAUSE frames.
  1122. */
  1123. if (hw->fc.requested_mode == e1000_fc_full) {
  1124. hw->fc.current_mode = e1000_fc_full;
  1125. e_dbg("Flow Control = FULL.\n");
  1126. } else {
  1127. hw->fc.current_mode = e1000_fc_rx_pause;
  1128. e_dbg("Flow Control = Rx PAUSE frames only.\n");
  1129. }
  1130. }
  1131. /* For receiving PAUSE frames ONLY.
  1132. *
  1133. * LOCAL DEVICE | LINK PARTNER
  1134. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
  1135. *-------|---------|-------|---------|--------------------
  1136. * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
  1137. */
  1138. else if (!(pcs_adv_reg & E1000_TXCW_PAUSE) &&
  1139. (pcs_adv_reg & E1000_TXCW_ASM_DIR) &&
  1140. (pcs_lp_ability_reg & E1000_TXCW_PAUSE) &&
  1141. (pcs_lp_ability_reg & E1000_TXCW_ASM_DIR)) {
  1142. hw->fc.current_mode = e1000_fc_tx_pause;
  1143. e_dbg("Flow Control = Tx PAUSE frames only.\n");
  1144. }
  1145. /* For transmitting PAUSE frames ONLY.
  1146. *
  1147. * LOCAL DEVICE | LINK PARTNER
  1148. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
  1149. *-------|---------|-------|---------|--------------------
  1150. * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
  1151. */
  1152. else if ((pcs_adv_reg & E1000_TXCW_PAUSE) &&
  1153. (pcs_adv_reg & E1000_TXCW_ASM_DIR) &&
  1154. !(pcs_lp_ability_reg & E1000_TXCW_PAUSE) &&
  1155. (pcs_lp_ability_reg & E1000_TXCW_ASM_DIR)) {
  1156. hw->fc.current_mode = e1000_fc_rx_pause;
  1157. e_dbg("Flow Control = Rx PAUSE frames only.\n");
  1158. } else {
  1159. /* Per the IEEE spec, at this point flow control
  1160. * should be disabled.
  1161. */
  1162. hw->fc.current_mode = e1000_fc_none;
  1163. e_dbg("Flow Control = NONE.\n");
  1164. }
  1165. /* Now we call a subroutine to actually force the MAC
  1166. * controller to use the correct flow control settings.
  1167. */
  1168. pcs_ctrl_reg = er32(PCS_LCTL);
  1169. pcs_ctrl_reg |= E1000_PCS_LCTL_FORCE_FCTRL;
  1170. ew32(PCS_LCTL, pcs_ctrl_reg);
  1171. ret_val = e1000e_force_mac_fc(hw);
  1172. if (ret_val) {
  1173. e_dbg("Error forcing flow control settings\n");
  1174. return ret_val;
  1175. }
  1176. }
  1177. return 0;
  1178. }
  1179. /**
  1180. * e1000e_get_speed_and_duplex_copper - Retrieve current speed/duplex
  1181. * @hw: pointer to the HW structure
  1182. * @speed: stores the current speed
  1183. * @duplex: stores the current duplex
  1184. *
  1185. * Read the status register for the current speed/duplex and store the current
  1186. * speed and duplex for copper connections.
  1187. **/
  1188. s32 e1000e_get_speed_and_duplex_copper(struct e1000_hw *hw, u16 *speed,
  1189. u16 *duplex)
  1190. {
  1191. u32 status;
  1192. status = er32(STATUS);
  1193. if (status & E1000_STATUS_SPEED_1000)
  1194. *speed = SPEED_1000;
  1195. else if (status & E1000_STATUS_SPEED_100)
  1196. *speed = SPEED_100;
  1197. else
  1198. *speed = SPEED_10;
  1199. if (status & E1000_STATUS_FD)
  1200. *duplex = FULL_DUPLEX;
  1201. else
  1202. *duplex = HALF_DUPLEX;
  1203. e_dbg("%u Mbps, %s Duplex\n",
  1204. *speed == SPEED_1000 ? 1000 : *speed == SPEED_100 ? 100 : 10,
  1205. *duplex == FULL_DUPLEX ? "Full" : "Half");
  1206. return 0;
  1207. }
  1208. /**
  1209. * e1000e_get_speed_and_duplex_fiber_serdes - Retrieve current speed/duplex
  1210. * @hw: pointer to the HW structure
  1211. * @speed: stores the current speed
  1212. * @duplex: stores the current duplex
  1213. *
  1214. * Sets the speed and duplex to gigabit full duplex (the only possible option)
  1215. * for fiber/serdes links.
  1216. **/
  1217. s32 e1000e_get_speed_and_duplex_fiber_serdes(struct e1000_hw __always_unused
  1218. *hw, u16 *speed, u16 *duplex)
  1219. {
  1220. *speed = SPEED_1000;
  1221. *duplex = FULL_DUPLEX;
  1222. return 0;
  1223. }
  1224. /**
  1225. * e1000e_get_hw_semaphore - Acquire hardware semaphore
  1226. * @hw: pointer to the HW structure
  1227. *
  1228. * Acquire the HW semaphore to access the PHY or NVM
  1229. **/
  1230. s32 e1000e_get_hw_semaphore(struct e1000_hw *hw)
  1231. {
  1232. u32 swsm;
  1233. s32 timeout = hw->nvm.word_size + 1;
  1234. s32 i = 0;
  1235. /* Get the SW semaphore */
  1236. while (i < timeout) {
  1237. swsm = er32(SWSM);
  1238. if (!(swsm & E1000_SWSM_SMBI))
  1239. break;
  1240. usleep_range(50, 100);
  1241. i++;
  1242. }
  1243. if (i == timeout) {
  1244. e_dbg("Driver can't access device - SMBI bit is set.\n");
  1245. return -E1000_ERR_NVM;
  1246. }
  1247. /* Get the FW semaphore. */
  1248. for (i = 0; i < timeout; i++) {
  1249. swsm = er32(SWSM);
  1250. ew32(SWSM, swsm | E1000_SWSM_SWESMBI);
  1251. /* Semaphore acquired if bit latched */
  1252. if (er32(SWSM) & E1000_SWSM_SWESMBI)
  1253. break;
  1254. usleep_range(50, 100);
  1255. }
  1256. if (i == timeout) {
  1257. /* Release semaphores */
  1258. e1000e_put_hw_semaphore(hw);
  1259. e_dbg("Driver can't access the NVM\n");
  1260. return -E1000_ERR_NVM;
  1261. }
  1262. return 0;
  1263. }
  1264. /**
  1265. * e1000e_put_hw_semaphore - Release hardware semaphore
  1266. * @hw: pointer to the HW structure
  1267. *
  1268. * Release hardware semaphore used to access the PHY or NVM
  1269. **/
  1270. void e1000e_put_hw_semaphore(struct e1000_hw *hw)
  1271. {
  1272. u32 swsm;
  1273. swsm = er32(SWSM);
  1274. swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI);
  1275. ew32(SWSM, swsm);
  1276. }
  1277. /**
  1278. * e1000e_get_auto_rd_done - Check for auto read completion
  1279. * @hw: pointer to the HW structure
  1280. *
  1281. * Check EEPROM for Auto Read done bit.
  1282. **/
  1283. s32 e1000e_get_auto_rd_done(struct e1000_hw *hw)
  1284. {
  1285. s32 i = 0;
  1286. while (i < AUTO_READ_DONE_TIMEOUT) {
  1287. if (er32(EECD) & E1000_EECD_AUTO_RD)
  1288. break;
  1289. usleep_range(1000, 2000);
  1290. i++;
  1291. }
  1292. if (i == AUTO_READ_DONE_TIMEOUT) {
  1293. e_dbg("Auto read by HW from NVM has not completed.\n");
  1294. return -E1000_ERR_RESET;
  1295. }
  1296. return 0;
  1297. }
  1298. /**
  1299. * e1000e_valid_led_default - Verify a valid default LED config
  1300. * @hw: pointer to the HW structure
  1301. * @data: pointer to the NVM (EEPROM)
  1302. *
  1303. * Read the EEPROM for the current default LED configuration. If the
  1304. * LED configuration is not valid, set to a valid LED configuration.
  1305. **/
  1306. s32 e1000e_valid_led_default(struct e1000_hw *hw, u16 *data)
  1307. {
  1308. s32 ret_val;
  1309. ret_val = e1000_read_nvm(hw, NVM_ID_LED_SETTINGS, 1, data);
  1310. if (ret_val) {
  1311. e_dbg("NVM Read Error\n");
  1312. return ret_val;
  1313. }
  1314. if (*data == ID_LED_RESERVED_0000 || *data == ID_LED_RESERVED_FFFF)
  1315. *data = ID_LED_DEFAULT;
  1316. return 0;
  1317. }
  1318. /**
  1319. * e1000e_id_led_init_generic -
  1320. * @hw: pointer to the HW structure
  1321. *
  1322. **/
  1323. s32 e1000e_id_led_init_generic(struct e1000_hw *hw)
  1324. {
  1325. struct e1000_mac_info *mac = &hw->mac;
  1326. s32 ret_val;
  1327. const u32 ledctl_mask = 0x000000FF;
  1328. const u32 ledctl_on = E1000_LEDCTL_MODE_LED_ON;
  1329. const u32 ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
  1330. u16 data, i, temp;
  1331. const u16 led_mask = 0x0F;
  1332. ret_val = hw->nvm.ops.valid_led_default(hw, &data);
  1333. if (ret_val)
  1334. return ret_val;
  1335. mac->ledctl_default = er32(LEDCTL);
  1336. mac->ledctl_mode1 = mac->ledctl_default;
  1337. mac->ledctl_mode2 = mac->ledctl_default;
  1338. for (i = 0; i < 4; i++) {
  1339. temp = (data >> (i << 2)) & led_mask;
  1340. switch (temp) {
  1341. case ID_LED_ON1_DEF2:
  1342. case ID_LED_ON1_ON2:
  1343. case ID_LED_ON1_OFF2:
  1344. mac->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
  1345. mac->ledctl_mode1 |= ledctl_on << (i << 3);
  1346. break;
  1347. case ID_LED_OFF1_DEF2:
  1348. case ID_LED_OFF1_ON2:
  1349. case ID_LED_OFF1_OFF2:
  1350. mac->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
  1351. mac->ledctl_mode1 |= ledctl_off << (i << 3);
  1352. break;
  1353. default:
  1354. /* Do nothing */
  1355. break;
  1356. }
  1357. switch (temp) {
  1358. case ID_LED_DEF1_ON2:
  1359. case ID_LED_ON1_ON2:
  1360. case ID_LED_OFF1_ON2:
  1361. mac->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
  1362. mac->ledctl_mode2 |= ledctl_on << (i << 3);
  1363. break;
  1364. case ID_LED_DEF1_OFF2:
  1365. case ID_LED_ON1_OFF2:
  1366. case ID_LED_OFF1_OFF2:
  1367. mac->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
  1368. mac->ledctl_mode2 |= ledctl_off << (i << 3);
  1369. break;
  1370. default:
  1371. /* Do nothing */
  1372. break;
  1373. }
  1374. }
  1375. return 0;
  1376. }
  1377. /**
  1378. * e1000e_setup_led_generic - Configures SW controllable LED
  1379. * @hw: pointer to the HW structure
  1380. *
  1381. * This prepares the SW controllable LED for use and saves the current state
  1382. * of the LED so it can be later restored.
  1383. **/
  1384. s32 e1000e_setup_led_generic(struct e1000_hw *hw)
  1385. {
  1386. u32 ledctl;
  1387. if (hw->mac.ops.setup_led != e1000e_setup_led_generic)
  1388. return -E1000_ERR_CONFIG;
  1389. if (hw->phy.media_type == e1000_media_type_fiber) {
  1390. ledctl = er32(LEDCTL);
  1391. hw->mac.ledctl_default = ledctl;
  1392. /* Turn off LED0 */
  1393. ledctl &= ~(E1000_LEDCTL_LED0_IVRT | E1000_LEDCTL_LED0_BLINK |
  1394. E1000_LEDCTL_LED0_MODE_MASK);
  1395. ledctl |= (E1000_LEDCTL_MODE_LED_OFF <<
  1396. E1000_LEDCTL_LED0_MODE_SHIFT);
  1397. ew32(LEDCTL, ledctl);
  1398. } else if (hw->phy.media_type == e1000_media_type_copper) {
  1399. ew32(LEDCTL, hw->mac.ledctl_mode1);
  1400. }
  1401. return 0;
  1402. }
  1403. /**
  1404. * e1000e_cleanup_led_generic - Set LED config to default operation
  1405. * @hw: pointer to the HW structure
  1406. *
  1407. * Remove the current LED configuration and set the LED configuration
  1408. * to the default value, saved from the EEPROM.
  1409. **/
  1410. s32 e1000e_cleanup_led_generic(struct e1000_hw *hw)
  1411. {
  1412. ew32(LEDCTL, hw->mac.ledctl_default);
  1413. return 0;
  1414. }
  1415. /**
  1416. * e1000e_blink_led_generic - Blink LED
  1417. * @hw: pointer to the HW structure
  1418. *
  1419. * Blink the LEDs which are set to be on.
  1420. **/
  1421. s32 e1000e_blink_led_generic(struct e1000_hw *hw)
  1422. {
  1423. u32 ledctl_blink = 0;
  1424. u32 i;
  1425. if (hw->phy.media_type == e1000_media_type_fiber) {
  1426. /* always blink LED0 for PCI-E fiber */
  1427. ledctl_blink = E1000_LEDCTL_LED0_BLINK |
  1428. (E1000_LEDCTL_MODE_LED_ON << E1000_LEDCTL_LED0_MODE_SHIFT);
  1429. } else {
  1430. /* Set the blink bit for each LED that's "on" (0x0E)
  1431. * (or "off" if inverted) in ledctl_mode2. The blink
  1432. * logic in hardware only works when mode is set to "on"
  1433. * so it must be changed accordingly when the mode is
  1434. * "off" and inverted.
  1435. */
  1436. ledctl_blink = hw->mac.ledctl_mode2;
  1437. for (i = 0; i < 32; i += 8) {
  1438. u32 mode = (hw->mac.ledctl_mode2 >> i) &
  1439. E1000_LEDCTL_LED0_MODE_MASK;
  1440. u32 led_default = hw->mac.ledctl_default >> i;
  1441. if ((!(led_default & E1000_LEDCTL_LED0_IVRT) &&
  1442. (mode == E1000_LEDCTL_MODE_LED_ON)) ||
  1443. ((led_default & E1000_LEDCTL_LED0_IVRT) &&
  1444. (mode == E1000_LEDCTL_MODE_LED_OFF))) {
  1445. ledctl_blink &=
  1446. ~(E1000_LEDCTL_LED0_MODE_MASK << i);
  1447. ledctl_blink |= (E1000_LEDCTL_LED0_BLINK |
  1448. E1000_LEDCTL_MODE_LED_ON) << i;
  1449. }
  1450. }
  1451. }
  1452. ew32(LEDCTL, ledctl_blink);
  1453. return 0;
  1454. }
  1455. /**
  1456. * e1000e_led_on_generic - Turn LED on
  1457. * @hw: pointer to the HW structure
  1458. *
  1459. * Turn LED on.
  1460. **/
  1461. s32 e1000e_led_on_generic(struct e1000_hw *hw)
  1462. {
  1463. u32 ctrl;
  1464. switch (hw->phy.media_type) {
  1465. case e1000_media_type_fiber:
  1466. ctrl = er32(CTRL);
  1467. ctrl &= ~E1000_CTRL_SWDPIN0;
  1468. ctrl |= E1000_CTRL_SWDPIO0;
  1469. ew32(CTRL, ctrl);
  1470. break;
  1471. case e1000_media_type_copper:
  1472. ew32(LEDCTL, hw->mac.ledctl_mode2);
  1473. break;
  1474. default:
  1475. break;
  1476. }
  1477. return 0;
  1478. }
  1479. /**
  1480. * e1000e_led_off_generic - Turn LED off
  1481. * @hw: pointer to the HW structure
  1482. *
  1483. * Turn LED off.
  1484. **/
  1485. s32 e1000e_led_off_generic(struct e1000_hw *hw)
  1486. {
  1487. u32 ctrl;
  1488. switch (hw->phy.media_type) {
  1489. case e1000_media_type_fiber:
  1490. ctrl = er32(CTRL);
  1491. ctrl |= E1000_CTRL_SWDPIN0;
  1492. ctrl |= E1000_CTRL_SWDPIO0;
  1493. ew32(CTRL, ctrl);
  1494. break;
  1495. case e1000_media_type_copper:
  1496. ew32(LEDCTL, hw->mac.ledctl_mode1);
  1497. break;
  1498. default:
  1499. break;
  1500. }
  1501. return 0;
  1502. }
  1503. /**
  1504. * e1000e_set_pcie_no_snoop - Set PCI-express capabilities
  1505. * @hw: pointer to the HW structure
  1506. * @no_snoop: bitmap of snoop events
  1507. *
  1508. * Set the PCI-express register to snoop for events enabled in 'no_snoop'.
  1509. **/
  1510. void e1000e_set_pcie_no_snoop(struct e1000_hw *hw, u32 no_snoop)
  1511. {
  1512. u32 gcr;
  1513. if (no_snoop) {
  1514. gcr = er32(GCR);
  1515. gcr &= ~(PCIE_NO_SNOOP_ALL);
  1516. gcr |= no_snoop;
  1517. ew32(GCR, gcr);
  1518. }
  1519. }
  1520. /**
  1521. * e1000e_disable_pcie_master - Disables PCI-express master access
  1522. * @hw: pointer to the HW structure
  1523. *
  1524. * Returns 0 if successful, else returns -10
  1525. * (-E1000_ERR_MASTER_REQUESTS_PENDING) if master disable bit has not caused
  1526. * the master requests to be disabled.
  1527. *
  1528. * Disables PCI-Express master access and verifies there are no pending
  1529. * requests.
  1530. **/
  1531. s32 e1000e_disable_pcie_master(struct e1000_hw *hw)
  1532. {
  1533. u32 ctrl;
  1534. s32 timeout = MASTER_DISABLE_TIMEOUT;
  1535. ctrl = er32(CTRL);
  1536. ctrl |= E1000_CTRL_GIO_MASTER_DISABLE;
  1537. ew32(CTRL, ctrl);
  1538. while (timeout) {
  1539. if (!(er32(STATUS) & E1000_STATUS_GIO_MASTER_ENABLE))
  1540. break;
  1541. usleep_range(100, 200);
  1542. timeout--;
  1543. }
  1544. if (!timeout) {
  1545. e_dbg("Master requests are pending.\n");
  1546. return -E1000_ERR_MASTER_REQUESTS_PENDING;
  1547. }
  1548. return 0;
  1549. }
  1550. /**
  1551. * e1000e_reset_adaptive - Reset Adaptive Interframe Spacing
  1552. * @hw: pointer to the HW structure
  1553. *
  1554. * Reset the Adaptive Interframe Spacing throttle to default values.
  1555. **/
  1556. void e1000e_reset_adaptive(struct e1000_hw *hw)
  1557. {
  1558. struct e1000_mac_info *mac = &hw->mac;
  1559. if (!mac->adaptive_ifs) {
  1560. e_dbg("Not in Adaptive IFS mode!\n");
  1561. return;
  1562. }
  1563. mac->current_ifs_val = 0;
  1564. mac->ifs_min_val = IFS_MIN;
  1565. mac->ifs_max_val = IFS_MAX;
  1566. mac->ifs_step_size = IFS_STEP;
  1567. mac->ifs_ratio = IFS_RATIO;
  1568. mac->in_ifs_mode = false;
  1569. ew32(AIT, 0);
  1570. }
  1571. /**
  1572. * e1000e_update_adaptive - Update Adaptive Interframe Spacing
  1573. * @hw: pointer to the HW structure
  1574. *
  1575. * Update the Adaptive Interframe Spacing Throttle value based on the
  1576. * time between transmitted packets and time between collisions.
  1577. **/
  1578. void e1000e_update_adaptive(struct e1000_hw *hw)
  1579. {
  1580. struct e1000_mac_info *mac = &hw->mac;
  1581. if (!mac->adaptive_ifs) {
  1582. e_dbg("Not in Adaptive IFS mode!\n");
  1583. return;
  1584. }
  1585. if ((mac->collision_delta * mac->ifs_ratio) > mac->tx_packet_delta) {
  1586. if (mac->tx_packet_delta > MIN_NUM_XMITS) {
  1587. mac->in_ifs_mode = true;
  1588. if (mac->current_ifs_val < mac->ifs_max_val) {
  1589. if (!mac->current_ifs_val)
  1590. mac->current_ifs_val = mac->ifs_min_val;
  1591. else
  1592. mac->current_ifs_val +=
  1593. mac->ifs_step_size;
  1594. ew32(AIT, mac->current_ifs_val);
  1595. }
  1596. }
  1597. } else {
  1598. if (mac->in_ifs_mode &&
  1599. (mac->tx_packet_delta <= MIN_NUM_XMITS)) {
  1600. mac->current_ifs_val = 0;
  1601. mac->in_ifs_mode = false;
  1602. ew32(AIT, 0);
  1603. }
  1604. }
  1605. }