e1000_mac.c 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421
  1. /*******************************************************************************
  2. Intel(R) Gigabit Ethernet Linux driver
  3. Copyright(c) 2007-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. e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  18. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  19. *******************************************************************************/
  20. #include <linux/if_ether.h>
  21. #include <linux/delay.h>
  22. #include <linux/pci.h>
  23. #include <linux/netdevice.h>
  24. #include "e1000_mac.h"
  25. #include "igb.h"
  26. static s32 igb_set_default_fc(struct e1000_hw *hw);
  27. static s32 igb_set_fc_watermarks(struct e1000_hw *hw);
  28. /**
  29. * igb_get_bus_info_pcie - Get PCIe bus information
  30. * @hw: pointer to the HW structure
  31. *
  32. * Determines and stores the system bus information for a particular
  33. * network interface. The following bus information is determined and stored:
  34. * bus speed, bus width, type (PCIe), and PCIe function.
  35. **/
  36. s32 igb_get_bus_info_pcie(struct e1000_hw *hw)
  37. {
  38. struct e1000_bus_info *bus = &hw->bus;
  39. s32 ret_val;
  40. u32 reg;
  41. u16 pcie_link_status;
  42. bus->type = e1000_bus_type_pci_express;
  43. ret_val = igb_read_pcie_cap_reg(hw,
  44. PCI_EXP_LNKSTA,
  45. &pcie_link_status);
  46. if (ret_val) {
  47. bus->width = e1000_bus_width_unknown;
  48. bus->speed = e1000_bus_speed_unknown;
  49. } else {
  50. switch (pcie_link_status & PCI_EXP_LNKSTA_CLS) {
  51. case PCI_EXP_LNKSTA_CLS_2_5GB:
  52. bus->speed = e1000_bus_speed_2500;
  53. break;
  54. case PCI_EXP_LNKSTA_CLS_5_0GB:
  55. bus->speed = e1000_bus_speed_5000;
  56. break;
  57. default:
  58. bus->speed = e1000_bus_speed_unknown;
  59. break;
  60. }
  61. bus->width = (enum e1000_bus_width)((pcie_link_status &
  62. PCI_EXP_LNKSTA_NLW) >>
  63. PCI_EXP_LNKSTA_NLW_SHIFT);
  64. }
  65. reg = rd32(E1000_STATUS);
  66. bus->func = (reg & E1000_STATUS_FUNC_MASK) >> E1000_STATUS_FUNC_SHIFT;
  67. return 0;
  68. }
  69. /**
  70. * igb_clear_vfta - Clear VLAN filter table
  71. * @hw: pointer to the HW structure
  72. *
  73. * Clears the register array which contains the VLAN filter table by
  74. * setting all the values to 0.
  75. **/
  76. void igb_clear_vfta(struct e1000_hw *hw)
  77. {
  78. u32 offset;
  79. for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
  80. array_wr32(E1000_VFTA, offset, 0);
  81. wrfl();
  82. }
  83. }
  84. /**
  85. * igb_write_vfta - Write value to VLAN filter table
  86. * @hw: pointer to the HW structure
  87. * @offset: register offset in VLAN filter table
  88. * @value: register value written to VLAN filter table
  89. *
  90. * Writes value at the given offset in the register array which stores
  91. * the VLAN filter table.
  92. **/
  93. static void igb_write_vfta(struct e1000_hw *hw, u32 offset, u32 value)
  94. {
  95. array_wr32(E1000_VFTA, offset, value);
  96. wrfl();
  97. }
  98. /**
  99. * igb_init_rx_addrs - Initialize receive address's
  100. * @hw: pointer to the HW structure
  101. * @rar_count: receive address registers
  102. *
  103. * Setups the receive address registers by setting the base receive address
  104. * register to the devices MAC address and clearing all the other receive
  105. * address registers to 0.
  106. **/
  107. void igb_init_rx_addrs(struct e1000_hw *hw, u16 rar_count)
  108. {
  109. u32 i;
  110. u8 mac_addr[ETH_ALEN] = {0};
  111. /* Setup the receive address */
  112. hw_dbg("Programming MAC Address into RAR[0]\n");
  113. hw->mac.ops.rar_set(hw, hw->mac.addr, 0);
  114. /* Zero out the other (rar_entry_count - 1) receive addresses */
  115. hw_dbg("Clearing RAR[1-%u]\n", rar_count-1);
  116. for (i = 1; i < rar_count; i++)
  117. hw->mac.ops.rar_set(hw, mac_addr, i);
  118. }
  119. /**
  120. * igb_vfta_set - enable or disable vlan in VLAN filter table
  121. * @hw: pointer to the HW structure
  122. * @vid: VLAN id to add or remove
  123. * @add: if true add filter, if false remove
  124. *
  125. * Sets or clears a bit in the VLAN filter table array based on VLAN id
  126. * and if we are adding or removing the filter
  127. **/
  128. s32 igb_vfta_set(struct e1000_hw *hw, u32 vid, bool add)
  129. {
  130. u32 index = (vid >> E1000_VFTA_ENTRY_SHIFT) & E1000_VFTA_ENTRY_MASK;
  131. u32 mask = 1 << (vid & E1000_VFTA_ENTRY_BIT_SHIFT_MASK);
  132. u32 vfta = array_rd32(E1000_VFTA, index);
  133. s32 ret_val = 0;
  134. /* bit was set/cleared before we started */
  135. if ((!!(vfta & mask)) == add) {
  136. ret_val = -E1000_ERR_CONFIG;
  137. } else {
  138. if (add)
  139. vfta |= mask;
  140. else
  141. vfta &= ~mask;
  142. }
  143. igb_write_vfta(hw, index, vfta);
  144. return ret_val;
  145. }
  146. /**
  147. * igb_check_alt_mac_addr - Check for alternate MAC addr
  148. * @hw: pointer to the HW structure
  149. *
  150. * Checks the nvm for an alternate MAC address. An alternate MAC address
  151. * can be setup by pre-boot software and must be treated like a permanent
  152. * address and must override the actual permanent MAC address. If an
  153. * alternate MAC address is fopund it is saved in the hw struct and
  154. * prgrammed into RAR0 and the cuntion returns success, otherwise the
  155. * function returns an error.
  156. **/
  157. s32 igb_check_alt_mac_addr(struct e1000_hw *hw)
  158. {
  159. u32 i;
  160. s32 ret_val = 0;
  161. u16 offset, nvm_alt_mac_addr_offset, nvm_data;
  162. u8 alt_mac_addr[ETH_ALEN];
  163. ret_val = hw->nvm.ops.read(hw, NVM_ALT_MAC_ADDR_PTR, 1,
  164. &nvm_alt_mac_addr_offset);
  165. if (ret_val) {
  166. hw_dbg("NVM Read Error\n");
  167. goto out;
  168. }
  169. if (nvm_alt_mac_addr_offset == 0xFFFF) {
  170. /* There is no Alternate MAC Address */
  171. goto out;
  172. }
  173. if (hw->bus.func == E1000_FUNC_1)
  174. nvm_alt_mac_addr_offset += E1000_ALT_MAC_ADDRESS_OFFSET_LAN1;
  175. for (i = 0; i < ETH_ALEN; i += 2) {
  176. offset = nvm_alt_mac_addr_offset + (i >> 1);
  177. ret_val = hw->nvm.ops.read(hw, offset, 1, &nvm_data);
  178. if (ret_val) {
  179. hw_dbg("NVM Read Error\n");
  180. goto out;
  181. }
  182. alt_mac_addr[i] = (u8)(nvm_data & 0xFF);
  183. alt_mac_addr[i + 1] = (u8)(nvm_data >> 8);
  184. }
  185. /* if multicast bit is set, the alternate address will not be used */
  186. if (alt_mac_addr[0] & 0x01) {
  187. hw_dbg("Ignoring Alternate Mac Address with MC bit set\n");
  188. goto out;
  189. }
  190. /*
  191. * We have a valid alternate MAC address, and we want to treat it the
  192. * same as the normal permanent MAC address stored by the HW into the
  193. * RAR. Do this by mapping this address into RAR0.
  194. */
  195. hw->mac.ops.rar_set(hw, alt_mac_addr, 0);
  196. out:
  197. return ret_val;
  198. }
  199. /**
  200. * igb_rar_set - Set receive address register
  201. * @hw: pointer to the HW structure
  202. * @addr: pointer to the receive address
  203. * @index: receive address array register
  204. *
  205. * Sets the receive address array register at index to the address passed
  206. * in by addr.
  207. **/
  208. void igb_rar_set(struct e1000_hw *hw, u8 *addr, u32 index)
  209. {
  210. u32 rar_low, rar_high;
  211. /*
  212. * HW expects these in little endian so we reverse the byte order
  213. * from network order (big endian) to little endian
  214. */
  215. rar_low = ((u32) addr[0] |
  216. ((u32) addr[1] << 8) |
  217. ((u32) addr[2] << 16) | ((u32) addr[3] << 24));
  218. rar_high = ((u32) addr[4] | ((u32) addr[5] << 8));
  219. /* If MAC address zero, no need to set the AV bit */
  220. if (rar_low || rar_high)
  221. rar_high |= E1000_RAH_AV;
  222. /*
  223. * Some bridges will combine consecutive 32-bit writes into
  224. * a single burst write, which will malfunction on some parts.
  225. * The flushes avoid this.
  226. */
  227. wr32(E1000_RAL(index), rar_low);
  228. wrfl();
  229. wr32(E1000_RAH(index), rar_high);
  230. wrfl();
  231. }
  232. /**
  233. * igb_mta_set - Set multicast filter table address
  234. * @hw: pointer to the HW structure
  235. * @hash_value: determines the MTA register and bit to set
  236. *
  237. * The multicast table address is a register array of 32-bit registers.
  238. * The hash_value is used to determine what register the bit is in, the
  239. * current value is read, the new bit is OR'd in and the new value is
  240. * written back into the register.
  241. **/
  242. void igb_mta_set(struct e1000_hw *hw, u32 hash_value)
  243. {
  244. u32 hash_bit, hash_reg, mta;
  245. /*
  246. * The MTA is a register array of 32-bit registers. It is
  247. * treated like an array of (32*mta_reg_count) bits. We want to
  248. * set bit BitArray[hash_value]. So we figure out what register
  249. * the bit is in, read it, OR in the new bit, then write
  250. * back the new value. The (hw->mac.mta_reg_count - 1) serves as a
  251. * mask to bits 31:5 of the hash value which gives us the
  252. * register we're modifying. The hash bit within that register
  253. * is determined by the lower 5 bits of the hash value.
  254. */
  255. hash_reg = (hash_value >> 5) & (hw->mac.mta_reg_count - 1);
  256. hash_bit = hash_value & 0x1F;
  257. mta = array_rd32(E1000_MTA, hash_reg);
  258. mta |= (1 << hash_bit);
  259. array_wr32(E1000_MTA, hash_reg, mta);
  260. wrfl();
  261. }
  262. /**
  263. * igb_hash_mc_addr - Generate a multicast hash value
  264. * @hw: pointer to the HW structure
  265. * @mc_addr: pointer to a multicast address
  266. *
  267. * Generates a multicast address hash value which is used to determine
  268. * the multicast filter table array address and new table value. See
  269. * igb_mta_set()
  270. **/
  271. static u32 igb_hash_mc_addr(struct e1000_hw *hw, u8 *mc_addr)
  272. {
  273. u32 hash_value, hash_mask;
  274. u8 bit_shift = 0;
  275. /* Register count multiplied by bits per register */
  276. hash_mask = (hw->mac.mta_reg_count * 32) - 1;
  277. /*
  278. * For a mc_filter_type of 0, bit_shift is the number of left-shifts
  279. * where 0xFF would still fall within the hash mask.
  280. */
  281. while (hash_mask >> bit_shift != 0xFF)
  282. bit_shift++;
  283. /*
  284. * The portion of the address that is used for the hash table
  285. * is determined by the mc_filter_type setting.
  286. * The algorithm is such that there is a total of 8 bits of shifting.
  287. * The bit_shift for a mc_filter_type of 0 represents the number of
  288. * left-shifts where the MSB of mc_addr[5] would still fall within
  289. * the hash_mask. Case 0 does this exactly. Since there are a total
  290. * of 8 bits of shifting, then mc_addr[4] will shift right the
  291. * remaining number of bits. Thus 8 - bit_shift. The rest of the
  292. * cases are a variation of this algorithm...essentially raising the
  293. * number of bits to shift mc_addr[5] left, while still keeping the
  294. * 8-bit shifting total.
  295. *
  296. * For example, given the following Destination MAC Address and an
  297. * mta register count of 128 (thus a 4096-bit vector and 0xFFF mask),
  298. * we can see that the bit_shift for case 0 is 4. These are the hash
  299. * values resulting from each mc_filter_type...
  300. * [0] [1] [2] [3] [4] [5]
  301. * 01 AA 00 12 34 56
  302. * LSB MSB
  303. *
  304. * case 0: hash_value = ((0x34 >> 4) | (0x56 << 4)) & 0xFFF = 0x563
  305. * case 1: hash_value = ((0x34 >> 3) | (0x56 << 5)) & 0xFFF = 0xAC6
  306. * case 2: hash_value = ((0x34 >> 2) | (0x56 << 6)) & 0xFFF = 0x163
  307. * case 3: hash_value = ((0x34 >> 0) | (0x56 << 8)) & 0xFFF = 0x634
  308. */
  309. switch (hw->mac.mc_filter_type) {
  310. default:
  311. case 0:
  312. break;
  313. case 1:
  314. bit_shift += 1;
  315. break;
  316. case 2:
  317. bit_shift += 2;
  318. break;
  319. case 3:
  320. bit_shift += 4;
  321. break;
  322. }
  323. hash_value = hash_mask & (((mc_addr[4] >> (8 - bit_shift)) |
  324. (((u16) mc_addr[5]) << bit_shift)));
  325. return hash_value;
  326. }
  327. /**
  328. * igb_update_mc_addr_list - Update Multicast addresses
  329. * @hw: pointer to the HW structure
  330. * @mc_addr_list: array of multicast addresses to program
  331. * @mc_addr_count: number of multicast addresses to program
  332. *
  333. * Updates entire Multicast Table Array.
  334. * The caller must have a packed mc_addr_list of multicast addresses.
  335. **/
  336. void igb_update_mc_addr_list(struct e1000_hw *hw,
  337. u8 *mc_addr_list, u32 mc_addr_count)
  338. {
  339. u32 hash_value, hash_bit, hash_reg;
  340. int i;
  341. /* clear mta_shadow */
  342. memset(&hw->mac.mta_shadow, 0, sizeof(hw->mac.mta_shadow));
  343. /* update mta_shadow from mc_addr_list */
  344. for (i = 0; (u32) i < mc_addr_count; i++) {
  345. hash_value = igb_hash_mc_addr(hw, mc_addr_list);
  346. hash_reg = (hash_value >> 5) & (hw->mac.mta_reg_count - 1);
  347. hash_bit = hash_value & 0x1F;
  348. hw->mac.mta_shadow[hash_reg] |= (1 << hash_bit);
  349. mc_addr_list += (ETH_ALEN);
  350. }
  351. /* replace the entire MTA table */
  352. for (i = hw->mac.mta_reg_count - 1; i >= 0; i--)
  353. array_wr32(E1000_MTA, i, hw->mac.mta_shadow[i]);
  354. wrfl();
  355. }
  356. /**
  357. * igb_clear_hw_cntrs_base - Clear base hardware counters
  358. * @hw: pointer to the HW structure
  359. *
  360. * Clears the base hardware counters by reading the counter registers.
  361. **/
  362. void igb_clear_hw_cntrs_base(struct e1000_hw *hw)
  363. {
  364. rd32(E1000_CRCERRS);
  365. rd32(E1000_SYMERRS);
  366. rd32(E1000_MPC);
  367. rd32(E1000_SCC);
  368. rd32(E1000_ECOL);
  369. rd32(E1000_MCC);
  370. rd32(E1000_LATECOL);
  371. rd32(E1000_COLC);
  372. rd32(E1000_DC);
  373. rd32(E1000_SEC);
  374. rd32(E1000_RLEC);
  375. rd32(E1000_XONRXC);
  376. rd32(E1000_XONTXC);
  377. rd32(E1000_XOFFRXC);
  378. rd32(E1000_XOFFTXC);
  379. rd32(E1000_FCRUC);
  380. rd32(E1000_GPRC);
  381. rd32(E1000_BPRC);
  382. rd32(E1000_MPRC);
  383. rd32(E1000_GPTC);
  384. rd32(E1000_GORCL);
  385. rd32(E1000_GORCH);
  386. rd32(E1000_GOTCL);
  387. rd32(E1000_GOTCH);
  388. rd32(E1000_RNBC);
  389. rd32(E1000_RUC);
  390. rd32(E1000_RFC);
  391. rd32(E1000_ROC);
  392. rd32(E1000_RJC);
  393. rd32(E1000_TORL);
  394. rd32(E1000_TORH);
  395. rd32(E1000_TOTL);
  396. rd32(E1000_TOTH);
  397. rd32(E1000_TPR);
  398. rd32(E1000_TPT);
  399. rd32(E1000_MPTC);
  400. rd32(E1000_BPTC);
  401. }
  402. /**
  403. * igb_check_for_copper_link - Check for link (Copper)
  404. * @hw: pointer to the HW structure
  405. *
  406. * Checks to see of the link status of the hardware has changed. If a
  407. * change in link status has been detected, then we read the PHY registers
  408. * to get the current speed/duplex if link exists.
  409. **/
  410. s32 igb_check_for_copper_link(struct e1000_hw *hw)
  411. {
  412. struct e1000_mac_info *mac = &hw->mac;
  413. s32 ret_val;
  414. bool link;
  415. /*
  416. * We only want to go out to the PHY registers to see if Auto-Neg
  417. * has completed and/or if our link status has changed. The
  418. * get_link_status flag is set upon receiving a Link Status
  419. * Change or Rx Sequence Error interrupt.
  420. */
  421. if (!mac->get_link_status) {
  422. ret_val = 0;
  423. goto out;
  424. }
  425. /*
  426. * First we want to see if the MII Status Register reports
  427. * link. If so, then we want to get the current speed/duplex
  428. * of the PHY.
  429. */
  430. ret_val = igb_phy_has_link(hw, 1, 0, &link);
  431. if (ret_val)
  432. goto out;
  433. if (!link)
  434. goto out; /* No link detected */
  435. mac->get_link_status = false;
  436. /*
  437. * Check if there was DownShift, must be checked
  438. * immediately after link-up
  439. */
  440. igb_check_downshift(hw);
  441. /*
  442. * If we are forcing speed/duplex, then we simply return since
  443. * we have already determined whether we have link or not.
  444. */
  445. if (!mac->autoneg) {
  446. ret_val = -E1000_ERR_CONFIG;
  447. goto out;
  448. }
  449. /*
  450. * Auto-Neg is enabled. Auto Speed Detection takes care
  451. * of MAC speed/duplex configuration. So we only need to
  452. * configure Collision Distance in the MAC.
  453. */
  454. igb_config_collision_dist(hw);
  455. /*
  456. * Configure Flow Control now that Auto-Neg has completed.
  457. * First, we need to restore the desired flow control
  458. * settings because we may have had to re-autoneg with a
  459. * different link partner.
  460. */
  461. ret_val = igb_config_fc_after_link_up(hw);
  462. if (ret_val)
  463. hw_dbg("Error configuring flow control\n");
  464. out:
  465. return ret_val;
  466. }
  467. /**
  468. * igb_setup_link - Setup flow control and link settings
  469. * @hw: pointer to the HW structure
  470. *
  471. * Determines which flow control settings to use, then configures flow
  472. * control. Calls the appropriate media-specific link configuration
  473. * function. Assuming the adapter has a valid link partner, a valid link
  474. * should be established. Assumes the hardware has previously been reset
  475. * and the transmitter and receiver are not enabled.
  476. **/
  477. s32 igb_setup_link(struct e1000_hw *hw)
  478. {
  479. s32 ret_val = 0;
  480. /*
  481. * In the case of the phy reset being blocked, we already have a link.
  482. * We do not need to set it up again.
  483. */
  484. if (igb_check_reset_block(hw))
  485. goto out;
  486. /*
  487. * If requested flow control is set to default, set flow control
  488. * based on the EEPROM flow control settings.
  489. */
  490. if (hw->fc.requested_mode == e1000_fc_default) {
  491. ret_val = igb_set_default_fc(hw);
  492. if (ret_val)
  493. goto out;
  494. }
  495. /*
  496. * We want to save off the original Flow Control configuration just
  497. * in case we get disconnected and then reconnected into a different
  498. * hub or switch with different Flow Control capabilities.
  499. */
  500. hw->fc.current_mode = hw->fc.requested_mode;
  501. hw_dbg("After fix-ups FlowControl is now = %x\n", hw->fc.current_mode);
  502. /* Call the necessary media_type subroutine to configure the link. */
  503. ret_val = hw->mac.ops.setup_physical_interface(hw);
  504. if (ret_val)
  505. goto out;
  506. /*
  507. * Initialize the flow control address, type, and PAUSE timer
  508. * registers to their default values. This is done even if flow
  509. * control is disabled, because it does not hurt anything to
  510. * initialize these registers.
  511. */
  512. hw_dbg("Initializing the Flow Control address, type and timer regs\n");
  513. wr32(E1000_FCT, FLOW_CONTROL_TYPE);
  514. wr32(E1000_FCAH, FLOW_CONTROL_ADDRESS_HIGH);
  515. wr32(E1000_FCAL, FLOW_CONTROL_ADDRESS_LOW);
  516. wr32(E1000_FCTTV, hw->fc.pause_time);
  517. ret_val = igb_set_fc_watermarks(hw);
  518. out:
  519. return ret_val;
  520. }
  521. /**
  522. * igb_config_collision_dist - Configure collision distance
  523. * @hw: pointer to the HW structure
  524. *
  525. * Configures the collision distance to the default value and is used
  526. * during link setup. Currently no func pointer exists and all
  527. * implementations are handled in the generic version of this function.
  528. **/
  529. void igb_config_collision_dist(struct e1000_hw *hw)
  530. {
  531. u32 tctl;
  532. tctl = rd32(E1000_TCTL);
  533. tctl &= ~E1000_TCTL_COLD;
  534. tctl |= E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT;
  535. wr32(E1000_TCTL, tctl);
  536. wrfl();
  537. }
  538. /**
  539. * igb_set_fc_watermarks - Set flow control high/low watermarks
  540. * @hw: pointer to the HW structure
  541. *
  542. * Sets the flow control high/low threshold (watermark) registers. If
  543. * flow control XON frame transmission is enabled, then set XON frame
  544. * tansmission as well.
  545. **/
  546. static s32 igb_set_fc_watermarks(struct e1000_hw *hw)
  547. {
  548. s32 ret_val = 0;
  549. u32 fcrtl = 0, fcrth = 0;
  550. /*
  551. * Set the flow control receive threshold registers. Normally,
  552. * these registers will be set to a default threshold that may be
  553. * adjusted later by the driver's runtime code. However, if the
  554. * ability to transmit pause frames is not enabled, then these
  555. * registers will be set to 0.
  556. */
  557. if (hw->fc.current_mode & e1000_fc_tx_pause) {
  558. /*
  559. * We need to set up the Receive Threshold high and low water
  560. * marks as well as (optionally) enabling the transmission of
  561. * XON frames.
  562. */
  563. fcrtl = hw->fc.low_water;
  564. if (hw->fc.send_xon)
  565. fcrtl |= E1000_FCRTL_XONE;
  566. fcrth = hw->fc.high_water;
  567. }
  568. wr32(E1000_FCRTL, fcrtl);
  569. wr32(E1000_FCRTH, fcrth);
  570. return ret_val;
  571. }
  572. /**
  573. * igb_set_default_fc - Set flow control default values
  574. * @hw: pointer to the HW structure
  575. *
  576. * Read the EEPROM for the default values for flow control and store the
  577. * values.
  578. **/
  579. static s32 igb_set_default_fc(struct e1000_hw *hw)
  580. {
  581. s32 ret_val = 0;
  582. u16 nvm_data;
  583. /*
  584. * Read and store word 0x0F of the EEPROM. This word contains bits
  585. * that determine the hardware's default PAUSE (flow control) mode,
  586. * a bit that determines whether the HW defaults to enabling or
  587. * disabling auto-negotiation, and the direction of the
  588. * SW defined pins. If there is no SW over-ride of the flow
  589. * control setting, then the variable hw->fc will
  590. * be initialized based on a value in the EEPROM.
  591. */
  592. ret_val = hw->nvm.ops.read(hw, NVM_INIT_CONTROL2_REG, 1, &nvm_data);
  593. if (ret_val) {
  594. hw_dbg("NVM Read Error\n");
  595. goto out;
  596. }
  597. if ((nvm_data & NVM_WORD0F_PAUSE_MASK) == 0)
  598. hw->fc.requested_mode = e1000_fc_none;
  599. else if ((nvm_data & NVM_WORD0F_PAUSE_MASK) ==
  600. NVM_WORD0F_ASM_DIR)
  601. hw->fc.requested_mode = e1000_fc_tx_pause;
  602. else
  603. hw->fc.requested_mode = e1000_fc_full;
  604. out:
  605. return ret_val;
  606. }
  607. /**
  608. * igb_force_mac_fc - Force the MAC's flow control settings
  609. * @hw: pointer to the HW structure
  610. *
  611. * Force the MAC's flow control settings. Sets the TFCE and RFCE bits in the
  612. * device control register to reflect the adapter settings. TFCE and RFCE
  613. * need to be explicitly set by software when a copper PHY is used because
  614. * autonegotiation is managed by the PHY rather than the MAC. Software must
  615. * also configure these bits when link is forced on a fiber connection.
  616. **/
  617. s32 igb_force_mac_fc(struct e1000_hw *hw)
  618. {
  619. u32 ctrl;
  620. s32 ret_val = 0;
  621. ctrl = rd32(E1000_CTRL);
  622. /*
  623. * Because we didn't get link via the internal auto-negotiation
  624. * mechanism (we either forced link or we got link via PHY
  625. * auto-neg), we have to manually enable/disable transmit an
  626. * receive flow control.
  627. *
  628. * The "Case" statement below enables/disable flow control
  629. * according to the "hw->fc.current_mode" parameter.
  630. *
  631. * The possible values of the "fc" parameter are:
  632. * 0: Flow control is completely disabled
  633. * 1: Rx flow control is enabled (we can receive pause
  634. * frames but not send pause frames).
  635. * 2: Tx flow control is enabled (we can send pause frames
  636. * frames but we do not receive pause frames).
  637. * 3: Both Rx and TX flow control (symmetric) is enabled.
  638. * other: No other values should be possible at this point.
  639. */
  640. hw_dbg("hw->fc.current_mode = %u\n", hw->fc.current_mode);
  641. switch (hw->fc.current_mode) {
  642. case e1000_fc_none:
  643. ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
  644. break;
  645. case e1000_fc_rx_pause:
  646. ctrl &= (~E1000_CTRL_TFCE);
  647. ctrl |= E1000_CTRL_RFCE;
  648. break;
  649. case e1000_fc_tx_pause:
  650. ctrl &= (~E1000_CTRL_RFCE);
  651. ctrl |= E1000_CTRL_TFCE;
  652. break;
  653. case e1000_fc_full:
  654. ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
  655. break;
  656. default:
  657. hw_dbg("Flow control param set incorrectly\n");
  658. ret_val = -E1000_ERR_CONFIG;
  659. goto out;
  660. }
  661. wr32(E1000_CTRL, ctrl);
  662. out:
  663. return ret_val;
  664. }
  665. /**
  666. * igb_config_fc_after_link_up - Configures flow control after link
  667. * @hw: pointer to the HW structure
  668. *
  669. * Checks the status of auto-negotiation after link up to ensure that the
  670. * speed and duplex were not forced. If the link needed to be forced, then
  671. * flow control needs to be forced also. If auto-negotiation is enabled
  672. * and did not fail, then we configure flow control based on our link
  673. * partner.
  674. **/
  675. s32 igb_config_fc_after_link_up(struct e1000_hw *hw)
  676. {
  677. struct e1000_mac_info *mac = &hw->mac;
  678. s32 ret_val = 0;
  679. u16 mii_status_reg, mii_nway_adv_reg, mii_nway_lp_ability_reg;
  680. u16 speed, duplex;
  681. /*
  682. * Check for the case where we have fiber media and auto-neg failed
  683. * so we had to force link. In this case, we need to force the
  684. * configuration of the MAC to match the "fc" parameter.
  685. */
  686. if (mac->autoneg_failed) {
  687. if (hw->phy.media_type == e1000_media_type_internal_serdes)
  688. ret_val = igb_force_mac_fc(hw);
  689. } else {
  690. if (hw->phy.media_type == e1000_media_type_copper)
  691. ret_val = igb_force_mac_fc(hw);
  692. }
  693. if (ret_val) {
  694. hw_dbg("Error forcing flow control settings\n");
  695. goto out;
  696. }
  697. /*
  698. * Check for the case where we have copper media and auto-neg is
  699. * enabled. In this case, we need to check and see if Auto-Neg
  700. * has completed, and if so, how the PHY and link partner has
  701. * flow control configured.
  702. */
  703. if ((hw->phy.media_type == e1000_media_type_copper) && mac->autoneg) {
  704. /*
  705. * Read the MII Status Register and check to see if AutoNeg
  706. * has completed. We read this twice because this reg has
  707. * some "sticky" (latched) bits.
  708. */
  709. ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS,
  710. &mii_status_reg);
  711. if (ret_val)
  712. goto out;
  713. ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS,
  714. &mii_status_reg);
  715. if (ret_val)
  716. goto out;
  717. if (!(mii_status_reg & MII_SR_AUTONEG_COMPLETE)) {
  718. hw_dbg("Copper PHY and Auto Neg "
  719. "has not completed.\n");
  720. goto out;
  721. }
  722. /*
  723. * The AutoNeg process has completed, so we now need to
  724. * read both the Auto Negotiation Advertisement
  725. * Register (Address 4) and the Auto_Negotiation Base
  726. * Page Ability Register (Address 5) to determine how
  727. * flow control was negotiated.
  728. */
  729. ret_val = hw->phy.ops.read_reg(hw, PHY_AUTONEG_ADV,
  730. &mii_nway_adv_reg);
  731. if (ret_val)
  732. goto out;
  733. ret_val = hw->phy.ops.read_reg(hw, PHY_LP_ABILITY,
  734. &mii_nway_lp_ability_reg);
  735. if (ret_val)
  736. goto out;
  737. /*
  738. * Two bits in the Auto Negotiation Advertisement Register
  739. * (Address 4) and two bits in the Auto Negotiation Base
  740. * Page Ability Register (Address 5) determine flow control
  741. * for both the PHY and the link partner. The following
  742. * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
  743. * 1999, describes these PAUSE resolution bits and how flow
  744. * control is determined based upon these settings.
  745. * NOTE: DC = Don't Care
  746. *
  747. * LOCAL DEVICE | LINK PARTNER
  748. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
  749. *-------|---------|-------|---------|--------------------
  750. * 0 | 0 | DC | DC | e1000_fc_none
  751. * 0 | 1 | 0 | DC | e1000_fc_none
  752. * 0 | 1 | 1 | 0 | e1000_fc_none
  753. * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
  754. * 1 | 0 | 0 | DC | e1000_fc_none
  755. * 1 | DC | 1 | DC | e1000_fc_full
  756. * 1 | 1 | 0 | 0 | e1000_fc_none
  757. * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
  758. *
  759. * Are both PAUSE bits set to 1? If so, this implies
  760. * Symmetric Flow Control is enabled at both ends. The
  761. * ASM_DIR bits are irrelevant per the spec.
  762. *
  763. * For Symmetric Flow Control:
  764. *
  765. * LOCAL DEVICE | LINK PARTNER
  766. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
  767. *-------|---------|-------|---------|--------------------
  768. * 1 | DC | 1 | DC | E1000_fc_full
  769. *
  770. */
  771. if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
  772. (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
  773. /*
  774. * Now we need to check if the user selected RX ONLY
  775. * of pause frames. In this case, we had to advertise
  776. * FULL flow control because we could not advertise RX
  777. * ONLY. Hence, we must now check to see if we need to
  778. * turn OFF the TRANSMISSION of PAUSE frames.
  779. */
  780. if (hw->fc.requested_mode == e1000_fc_full) {
  781. hw->fc.current_mode = e1000_fc_full;
  782. hw_dbg("Flow Control = FULL.\r\n");
  783. } else {
  784. hw->fc.current_mode = e1000_fc_rx_pause;
  785. hw_dbg("Flow Control = "
  786. "RX PAUSE frames only.\r\n");
  787. }
  788. }
  789. /*
  790. * For receiving PAUSE frames ONLY.
  791. *
  792. * LOCAL DEVICE | LINK PARTNER
  793. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
  794. *-------|---------|-------|---------|--------------------
  795. * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
  796. */
  797. else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
  798. (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
  799. (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
  800. (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
  801. hw->fc.current_mode = e1000_fc_tx_pause;
  802. hw_dbg("Flow Control = TX PAUSE frames only.\r\n");
  803. }
  804. /*
  805. * For transmitting PAUSE frames ONLY.
  806. *
  807. * LOCAL DEVICE | LINK PARTNER
  808. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
  809. *-------|---------|-------|---------|--------------------
  810. * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
  811. */
  812. else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
  813. (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
  814. !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
  815. (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
  816. hw->fc.current_mode = e1000_fc_rx_pause;
  817. hw_dbg("Flow Control = RX PAUSE frames only.\r\n");
  818. }
  819. /*
  820. * Per the IEEE spec, at this point flow control should be
  821. * disabled. However, we want to consider that we could
  822. * be connected to a legacy switch that doesn't advertise
  823. * desired flow control, but can be forced on the link
  824. * partner. So if we advertised no flow control, that is
  825. * what we will resolve to. If we advertised some kind of
  826. * receive capability (Rx Pause Only or Full Flow Control)
  827. * and the link partner advertised none, we will configure
  828. * ourselves to enable Rx Flow Control only. We can do
  829. * this safely for two reasons: If the link partner really
  830. * didn't want flow control enabled, and we enable Rx, no
  831. * harm done since we won't be receiving any PAUSE frames
  832. * anyway. If the intent on the link partner was to have
  833. * flow control enabled, then by us enabling RX only, we
  834. * can at least receive pause frames and process them.
  835. * This is a good idea because in most cases, since we are
  836. * predominantly a server NIC, more times than not we will
  837. * be asked to delay transmission of packets than asking
  838. * our link partner to pause transmission of frames.
  839. */
  840. else if ((hw->fc.requested_mode == e1000_fc_none ||
  841. hw->fc.requested_mode == e1000_fc_tx_pause) ||
  842. hw->fc.strict_ieee) {
  843. hw->fc.current_mode = e1000_fc_none;
  844. hw_dbg("Flow Control = NONE.\r\n");
  845. } else {
  846. hw->fc.current_mode = e1000_fc_rx_pause;
  847. hw_dbg("Flow Control = RX PAUSE frames only.\r\n");
  848. }
  849. /*
  850. * Now we need to do one last check... If we auto-
  851. * negotiated to HALF DUPLEX, flow control should not be
  852. * enabled per IEEE 802.3 spec.
  853. */
  854. ret_val = hw->mac.ops.get_speed_and_duplex(hw, &speed, &duplex);
  855. if (ret_val) {
  856. hw_dbg("Error getting link speed and duplex\n");
  857. goto out;
  858. }
  859. if (duplex == HALF_DUPLEX)
  860. hw->fc.current_mode = e1000_fc_none;
  861. /*
  862. * Now we call a subroutine to actually force the MAC
  863. * controller to use the correct flow control settings.
  864. */
  865. ret_val = igb_force_mac_fc(hw);
  866. if (ret_val) {
  867. hw_dbg("Error forcing flow control settings\n");
  868. goto out;
  869. }
  870. }
  871. out:
  872. return ret_val;
  873. }
  874. /**
  875. * igb_get_speed_and_duplex_copper - Retrieve current speed/duplex
  876. * @hw: pointer to the HW structure
  877. * @speed: stores the current speed
  878. * @duplex: stores the current duplex
  879. *
  880. * Read the status register for the current speed/duplex and store the current
  881. * speed and duplex for copper connections.
  882. **/
  883. s32 igb_get_speed_and_duplex_copper(struct e1000_hw *hw, u16 *speed,
  884. u16 *duplex)
  885. {
  886. u32 status;
  887. status = rd32(E1000_STATUS);
  888. if (status & E1000_STATUS_SPEED_1000) {
  889. *speed = SPEED_1000;
  890. hw_dbg("1000 Mbs, ");
  891. } else if (status & E1000_STATUS_SPEED_100) {
  892. *speed = SPEED_100;
  893. hw_dbg("100 Mbs, ");
  894. } else {
  895. *speed = SPEED_10;
  896. hw_dbg("10 Mbs, ");
  897. }
  898. if (status & E1000_STATUS_FD) {
  899. *duplex = FULL_DUPLEX;
  900. hw_dbg("Full Duplex\n");
  901. } else {
  902. *duplex = HALF_DUPLEX;
  903. hw_dbg("Half Duplex\n");
  904. }
  905. return 0;
  906. }
  907. /**
  908. * igb_get_hw_semaphore - Acquire hardware semaphore
  909. * @hw: pointer to the HW structure
  910. *
  911. * Acquire the HW semaphore to access the PHY or NVM
  912. **/
  913. s32 igb_get_hw_semaphore(struct e1000_hw *hw)
  914. {
  915. u32 swsm;
  916. s32 ret_val = 0;
  917. s32 timeout = hw->nvm.word_size + 1;
  918. s32 i = 0;
  919. /* Get the SW semaphore */
  920. while (i < timeout) {
  921. swsm = rd32(E1000_SWSM);
  922. if (!(swsm & E1000_SWSM_SMBI))
  923. break;
  924. udelay(50);
  925. i++;
  926. }
  927. if (i == timeout) {
  928. hw_dbg("Driver can't access device - SMBI bit is set.\n");
  929. ret_val = -E1000_ERR_NVM;
  930. goto out;
  931. }
  932. /* Get the FW semaphore. */
  933. for (i = 0; i < timeout; i++) {
  934. swsm = rd32(E1000_SWSM);
  935. wr32(E1000_SWSM, swsm | E1000_SWSM_SWESMBI);
  936. /* Semaphore acquired if bit latched */
  937. if (rd32(E1000_SWSM) & E1000_SWSM_SWESMBI)
  938. break;
  939. udelay(50);
  940. }
  941. if (i == timeout) {
  942. /* Release semaphores */
  943. igb_put_hw_semaphore(hw);
  944. hw_dbg("Driver can't access the NVM\n");
  945. ret_val = -E1000_ERR_NVM;
  946. goto out;
  947. }
  948. out:
  949. return ret_val;
  950. }
  951. /**
  952. * igb_put_hw_semaphore - Release hardware semaphore
  953. * @hw: pointer to the HW structure
  954. *
  955. * Release hardware semaphore used to access the PHY or NVM
  956. **/
  957. void igb_put_hw_semaphore(struct e1000_hw *hw)
  958. {
  959. u32 swsm;
  960. swsm = rd32(E1000_SWSM);
  961. swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI);
  962. wr32(E1000_SWSM, swsm);
  963. }
  964. /**
  965. * igb_get_auto_rd_done - Check for auto read completion
  966. * @hw: pointer to the HW structure
  967. *
  968. * Check EEPROM for Auto Read done bit.
  969. **/
  970. s32 igb_get_auto_rd_done(struct e1000_hw *hw)
  971. {
  972. s32 i = 0;
  973. s32 ret_val = 0;
  974. while (i < AUTO_READ_DONE_TIMEOUT) {
  975. if (rd32(E1000_EECD) & E1000_EECD_AUTO_RD)
  976. break;
  977. msleep(1);
  978. i++;
  979. }
  980. if (i == AUTO_READ_DONE_TIMEOUT) {
  981. hw_dbg("Auto read by HW from NVM has not completed.\n");
  982. ret_val = -E1000_ERR_RESET;
  983. goto out;
  984. }
  985. out:
  986. return ret_val;
  987. }
  988. /**
  989. * igb_valid_led_default - Verify a valid default LED config
  990. * @hw: pointer to the HW structure
  991. * @data: pointer to the NVM (EEPROM)
  992. *
  993. * Read the EEPROM for the current default LED configuration. If the
  994. * LED configuration is not valid, set to a valid LED configuration.
  995. **/
  996. static s32 igb_valid_led_default(struct e1000_hw *hw, u16 *data)
  997. {
  998. s32 ret_val;
  999. ret_val = hw->nvm.ops.read(hw, NVM_ID_LED_SETTINGS, 1, data);
  1000. if (ret_val) {
  1001. hw_dbg("NVM Read Error\n");
  1002. goto out;
  1003. }
  1004. if (*data == ID_LED_RESERVED_0000 || *data == ID_LED_RESERVED_FFFF) {
  1005. switch(hw->phy.media_type) {
  1006. case e1000_media_type_internal_serdes:
  1007. *data = ID_LED_DEFAULT_82575_SERDES;
  1008. break;
  1009. case e1000_media_type_copper:
  1010. default:
  1011. *data = ID_LED_DEFAULT;
  1012. break;
  1013. }
  1014. }
  1015. out:
  1016. return ret_val;
  1017. }
  1018. /**
  1019. * igb_id_led_init -
  1020. * @hw: pointer to the HW structure
  1021. *
  1022. **/
  1023. s32 igb_id_led_init(struct e1000_hw *hw)
  1024. {
  1025. struct e1000_mac_info *mac = &hw->mac;
  1026. s32 ret_val;
  1027. const u32 ledctl_mask = 0x000000FF;
  1028. const u32 ledctl_on = E1000_LEDCTL_MODE_LED_ON;
  1029. const u32 ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
  1030. u16 data, i, temp;
  1031. const u16 led_mask = 0x0F;
  1032. ret_val = igb_valid_led_default(hw, &data);
  1033. if (ret_val)
  1034. goto out;
  1035. mac->ledctl_default = rd32(E1000_LEDCTL);
  1036. mac->ledctl_mode1 = mac->ledctl_default;
  1037. mac->ledctl_mode2 = mac->ledctl_default;
  1038. for (i = 0; i < 4; i++) {
  1039. temp = (data >> (i << 2)) & led_mask;
  1040. switch (temp) {
  1041. case ID_LED_ON1_DEF2:
  1042. case ID_LED_ON1_ON2:
  1043. case ID_LED_ON1_OFF2:
  1044. mac->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
  1045. mac->ledctl_mode1 |= ledctl_on << (i << 3);
  1046. break;
  1047. case ID_LED_OFF1_DEF2:
  1048. case ID_LED_OFF1_ON2:
  1049. case ID_LED_OFF1_OFF2:
  1050. mac->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
  1051. mac->ledctl_mode1 |= ledctl_off << (i << 3);
  1052. break;
  1053. default:
  1054. /* Do nothing */
  1055. break;
  1056. }
  1057. switch (temp) {
  1058. case ID_LED_DEF1_ON2:
  1059. case ID_LED_ON1_ON2:
  1060. case ID_LED_OFF1_ON2:
  1061. mac->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
  1062. mac->ledctl_mode2 |= ledctl_on << (i << 3);
  1063. break;
  1064. case ID_LED_DEF1_OFF2:
  1065. case ID_LED_ON1_OFF2:
  1066. case ID_LED_OFF1_OFF2:
  1067. mac->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
  1068. mac->ledctl_mode2 |= ledctl_off << (i << 3);
  1069. break;
  1070. default:
  1071. /* Do nothing */
  1072. break;
  1073. }
  1074. }
  1075. out:
  1076. return ret_val;
  1077. }
  1078. /**
  1079. * igb_cleanup_led - Set LED config to default operation
  1080. * @hw: pointer to the HW structure
  1081. *
  1082. * Remove the current LED configuration and set the LED configuration
  1083. * to the default value, saved from the EEPROM.
  1084. **/
  1085. s32 igb_cleanup_led(struct e1000_hw *hw)
  1086. {
  1087. wr32(E1000_LEDCTL, hw->mac.ledctl_default);
  1088. return 0;
  1089. }
  1090. /**
  1091. * igb_blink_led - Blink LED
  1092. * @hw: pointer to the HW structure
  1093. *
  1094. * Blink the led's which are set to be on.
  1095. **/
  1096. s32 igb_blink_led(struct e1000_hw *hw)
  1097. {
  1098. u32 ledctl_blink = 0;
  1099. u32 i;
  1100. /*
  1101. * set the blink bit for each LED that's "on" (0x0E)
  1102. * in ledctl_mode2
  1103. */
  1104. ledctl_blink = hw->mac.ledctl_mode2;
  1105. for (i = 0; i < 4; i++)
  1106. if (((hw->mac.ledctl_mode2 >> (i * 8)) & 0xFF) ==
  1107. E1000_LEDCTL_MODE_LED_ON)
  1108. ledctl_blink |= (E1000_LEDCTL_LED0_BLINK <<
  1109. (i * 8));
  1110. wr32(E1000_LEDCTL, ledctl_blink);
  1111. return 0;
  1112. }
  1113. /**
  1114. * igb_led_off - Turn LED off
  1115. * @hw: pointer to the HW structure
  1116. *
  1117. * Turn LED off.
  1118. **/
  1119. s32 igb_led_off(struct e1000_hw *hw)
  1120. {
  1121. switch (hw->phy.media_type) {
  1122. case e1000_media_type_copper:
  1123. wr32(E1000_LEDCTL, hw->mac.ledctl_mode1);
  1124. break;
  1125. default:
  1126. break;
  1127. }
  1128. return 0;
  1129. }
  1130. /**
  1131. * igb_disable_pcie_master - Disables PCI-express master access
  1132. * @hw: pointer to the HW structure
  1133. *
  1134. * Returns 0 (0) if successful, else returns -10
  1135. * (-E1000_ERR_MASTER_REQUESTS_PENDING) if master disable bit has not casued
  1136. * the master requests to be disabled.
  1137. *
  1138. * Disables PCI-Express master access and verifies there are no pending
  1139. * requests.
  1140. **/
  1141. s32 igb_disable_pcie_master(struct e1000_hw *hw)
  1142. {
  1143. u32 ctrl;
  1144. s32 timeout = MASTER_DISABLE_TIMEOUT;
  1145. s32 ret_val = 0;
  1146. if (hw->bus.type != e1000_bus_type_pci_express)
  1147. goto out;
  1148. ctrl = rd32(E1000_CTRL);
  1149. ctrl |= E1000_CTRL_GIO_MASTER_DISABLE;
  1150. wr32(E1000_CTRL, ctrl);
  1151. while (timeout) {
  1152. if (!(rd32(E1000_STATUS) &
  1153. E1000_STATUS_GIO_MASTER_ENABLE))
  1154. break;
  1155. udelay(100);
  1156. timeout--;
  1157. }
  1158. if (!timeout) {
  1159. hw_dbg("Master requests are pending.\n");
  1160. ret_val = -E1000_ERR_MASTER_REQUESTS_PENDING;
  1161. goto out;
  1162. }
  1163. out:
  1164. return ret_val;
  1165. }
  1166. /**
  1167. * igb_validate_mdi_setting - Verify MDI/MDIx settings
  1168. * @hw: pointer to the HW structure
  1169. *
  1170. * Verify that when not using auto-negotitation that MDI/MDIx is correctly
  1171. * set, which is forced to MDI mode only.
  1172. **/
  1173. s32 igb_validate_mdi_setting(struct e1000_hw *hw)
  1174. {
  1175. s32 ret_val = 0;
  1176. if (!hw->mac.autoneg && (hw->phy.mdix == 0 || hw->phy.mdix == 3)) {
  1177. hw_dbg("Invalid MDI setting detected\n");
  1178. hw->phy.mdix = 1;
  1179. ret_val = -E1000_ERR_CONFIG;
  1180. goto out;
  1181. }
  1182. out:
  1183. return ret_val;
  1184. }
  1185. /**
  1186. * igb_write_8bit_ctrl_reg - Write a 8bit CTRL register
  1187. * @hw: pointer to the HW structure
  1188. * @reg: 32bit register offset such as E1000_SCTL
  1189. * @offset: register offset to write to
  1190. * @data: data to write at register offset
  1191. *
  1192. * Writes an address/data control type register. There are several of these
  1193. * and they all have the format address << 8 | data and bit 31 is polled for
  1194. * completion.
  1195. **/
  1196. s32 igb_write_8bit_ctrl_reg(struct e1000_hw *hw, u32 reg,
  1197. u32 offset, u8 data)
  1198. {
  1199. u32 i, regvalue = 0;
  1200. s32 ret_val = 0;
  1201. /* Set up the address and data */
  1202. regvalue = ((u32)data) | (offset << E1000_GEN_CTL_ADDRESS_SHIFT);
  1203. wr32(reg, regvalue);
  1204. /* Poll the ready bit to see if the MDI read completed */
  1205. for (i = 0; i < E1000_GEN_POLL_TIMEOUT; i++) {
  1206. udelay(5);
  1207. regvalue = rd32(reg);
  1208. if (regvalue & E1000_GEN_CTL_READY)
  1209. break;
  1210. }
  1211. if (!(regvalue & E1000_GEN_CTL_READY)) {
  1212. hw_dbg("Reg %08x did not indicate ready\n", reg);
  1213. ret_val = -E1000_ERR_PHY;
  1214. goto out;
  1215. }
  1216. out:
  1217. return ret_val;
  1218. }
  1219. /**
  1220. * igb_enable_mng_pass_thru - Enable processing of ARP's
  1221. * @hw: pointer to the HW structure
  1222. *
  1223. * Verifies the hardware needs to leave interface enabled so that frames can
  1224. * be directed to and from the management interface.
  1225. **/
  1226. bool igb_enable_mng_pass_thru(struct e1000_hw *hw)
  1227. {
  1228. u32 manc;
  1229. u32 fwsm, factps;
  1230. bool ret_val = false;
  1231. if (!hw->mac.asf_firmware_present)
  1232. goto out;
  1233. manc = rd32(E1000_MANC);
  1234. if (!(manc & E1000_MANC_RCV_TCO_EN))
  1235. goto out;
  1236. if (hw->mac.arc_subsystem_valid) {
  1237. fwsm = rd32(E1000_FWSM);
  1238. factps = rd32(E1000_FACTPS);
  1239. if (!(factps & E1000_FACTPS_MNGCG) &&
  1240. ((fwsm & E1000_FWSM_MODE_MASK) ==
  1241. (e1000_mng_mode_pt << E1000_FWSM_MODE_SHIFT))) {
  1242. ret_val = true;
  1243. goto out;
  1244. }
  1245. } else {
  1246. if ((manc & E1000_MANC_SMBUS_EN) &&
  1247. !(manc & E1000_MANC_ASF_EN)) {
  1248. ret_val = true;
  1249. goto out;
  1250. }
  1251. }
  1252. out:
  1253. return ret_val;
  1254. }