You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

e1000e_mac.c 51KB

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