e1000_mac.c 37 KB

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