e1000_mac.c 41 KB

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