mac.c 47 KB

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