e1000_mac.c 47 KB

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