e1000_mac.c 38 KB

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