e1000_mac.c 48 KB

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