e1000_mac.c 38 KB

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