e1000_mac.c 45 KB

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