e1000_mac.c 40 KB

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