e1000_mac.c 38 KB

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