e1000_mac.c 38 KB

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