e1000_mac.c 38 KB

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