e1000_mac.c 40 KB

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