e1000_mac.c 48 KB

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