lib.c 67 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576
  1. /*******************************************************************************
  2. Intel PRO/1000 Linux driver
  3. Copyright(c) 1999 - 2009 Intel Corporation.
  4. This program is free software; you can redistribute it and/or modify it
  5. under the terms and conditions of the GNU General Public License,
  6. version 2, as published by the Free Software Foundation.
  7. This program is distributed in the hope it will be useful, but WITHOUT
  8. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  9. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  10. more details.
  11. You should have received a copy of the GNU General Public License along with
  12. this program; if not, write to the Free Software Foundation, Inc.,
  13. 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  14. The full GNU General Public License is included in this distribution in
  15. the file called "COPYING".
  16. Contact Information:
  17. Linux NICS <linux.nics@intel.com>
  18. e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  19. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  20. *******************************************************************************/
  21. #include "e1000.h"
  22. enum e1000_mng_mode {
  23. e1000_mng_mode_none = 0,
  24. e1000_mng_mode_asf,
  25. e1000_mng_mode_pt,
  26. e1000_mng_mode_ipmi,
  27. e1000_mng_mode_host_if_only
  28. };
  29. #define E1000_FACTPS_MNGCG 0x20000000
  30. /* Intel(R) Active Management Technology signature */
  31. #define E1000_IAMT_SIGNATURE 0x544D4149
  32. /**
  33. * e1000e_get_bus_info_pcie - Get PCIe bus information
  34. * @hw: pointer to the HW structure
  35. *
  36. * Determines and stores the system bus information for a particular
  37. * network interface. The following bus information is determined and stored:
  38. * bus speed, bus width, type (PCIe), and PCIe function.
  39. **/
  40. s32 e1000e_get_bus_info_pcie(struct e1000_hw *hw)
  41. {
  42. struct e1000_mac_info *mac = &hw->mac;
  43. struct e1000_bus_info *bus = &hw->bus;
  44. struct e1000_adapter *adapter = hw->adapter;
  45. u16 pcie_link_status, cap_offset;
  46. cap_offset = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP);
  47. if (!cap_offset) {
  48. bus->width = e1000_bus_width_unknown;
  49. } else {
  50. pci_read_config_word(adapter->pdev,
  51. cap_offset + PCIE_LINK_STATUS,
  52. &pcie_link_status);
  53. bus->width = (enum e1000_bus_width)((pcie_link_status &
  54. PCIE_LINK_WIDTH_MASK) >>
  55. PCIE_LINK_WIDTH_SHIFT);
  56. }
  57. mac->ops.set_lan_id(hw);
  58. return 0;
  59. }
  60. /**
  61. * e1000_set_lan_id_multi_port_pcie - Set LAN id for PCIe multiple port devices
  62. *
  63. * @hw: pointer to the HW structure
  64. *
  65. * Determines the LAN function id by reading memory-mapped registers
  66. * and swaps the port value if requested.
  67. **/
  68. void e1000_set_lan_id_multi_port_pcie(struct e1000_hw *hw)
  69. {
  70. struct e1000_bus_info *bus = &hw->bus;
  71. u32 reg;
  72. /*
  73. * The status register reports the correct function number
  74. * for the device regardless of function swap state.
  75. */
  76. reg = er32(STATUS);
  77. bus->func = (reg & E1000_STATUS_FUNC_MASK) >> E1000_STATUS_FUNC_SHIFT;
  78. }
  79. /**
  80. * e1000_set_lan_id_single_port - Set LAN id for a single port device
  81. * @hw: pointer to the HW structure
  82. *
  83. * Sets the LAN function id to zero for a single port device.
  84. **/
  85. void e1000_set_lan_id_single_port(struct e1000_hw *hw)
  86. {
  87. struct e1000_bus_info *bus = &hw->bus;
  88. bus->func = 0;
  89. }
  90. /**
  91. * e1000_clear_vfta_generic - 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 e1000_clear_vfta_generic(struct e1000_hw *hw)
  98. {
  99. u32 offset;
  100. for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
  101. E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, offset, 0);
  102. e1e_flush();
  103. }
  104. }
  105. /**
  106. * e1000_write_vfta_generic - 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 e1000_write_vfta_generic(struct e1000_hw *hw, u32 offset, u32 value)
  115. {
  116. E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, offset, value);
  117. e1e_flush();
  118. }
  119. /**
  120. * e1000e_init_rx_addrs - Initialize receive address's
  121. * @hw: pointer to the HW structure
  122. * @rar_count: receive address registers
  123. *
  124. * Setups the receive address registers by setting the base receive address
  125. * register to the devices MAC address and clearing all the other receive
  126. * address registers to 0.
  127. **/
  128. void e1000e_init_rx_addrs(struct e1000_hw *hw, u16 rar_count)
  129. {
  130. u32 i;
  131. u8 mac_addr[ETH_ALEN] = {0};
  132. /* Setup the receive address */
  133. e_dbg("Programming MAC Address into RAR[0]\n");
  134. e1000e_rar_set(hw, hw->mac.addr, 0);
  135. /* Zero out the other (rar_entry_count - 1) receive addresses */
  136. e_dbg("Clearing RAR[1-%u]\n", rar_count-1);
  137. for (i = 1; i < rar_count; i++)
  138. e1000e_rar_set(hw, mac_addr, i);
  139. }
  140. /**
  141. * e1000_check_alt_mac_addr_generic - Check for alternate MAC addr
  142. * @hw: pointer to the HW structure
  143. *
  144. * Checks the nvm for an alternate MAC address. An alternate MAC address
  145. * can be setup by pre-boot software and must be treated like a permanent
  146. * address and must override the actual permanent MAC address. If an
  147. * alternate MAC address is found it is programmed into RAR0, replacing
  148. * the permanent address that was installed into RAR0 by the Si on reset.
  149. * This function will return SUCCESS unless it encounters an error while
  150. * reading the EEPROM.
  151. **/
  152. s32 e1000_check_alt_mac_addr_generic(struct e1000_hw *hw)
  153. {
  154. u32 i;
  155. s32 ret_val = 0;
  156. u16 offset, nvm_alt_mac_addr_offset, nvm_data;
  157. u8 alt_mac_addr[ETH_ALEN];
  158. ret_val = e1000_read_nvm(hw, NVM_ALT_MAC_ADDR_PTR, 1,
  159. &nvm_alt_mac_addr_offset);
  160. if (ret_val) {
  161. e_dbg("NVM Read Error\n");
  162. goto out;
  163. }
  164. if (nvm_alt_mac_addr_offset == 0xFFFF) {
  165. /* There is no Alternate MAC Address */
  166. goto out;
  167. }
  168. if (hw->bus.func == E1000_FUNC_1)
  169. nvm_alt_mac_addr_offset += E1000_ALT_MAC_ADDRESS_OFFSET_LAN1;
  170. for (i = 0; i < ETH_ALEN; i += 2) {
  171. offset = nvm_alt_mac_addr_offset + (i >> 1);
  172. ret_val = e1000_read_nvm(hw, offset, 1, &nvm_data);
  173. if (ret_val) {
  174. e_dbg("NVM Read Error\n");
  175. goto out;
  176. }
  177. alt_mac_addr[i] = (u8)(nvm_data & 0xFF);
  178. alt_mac_addr[i + 1] = (u8)(nvm_data >> 8);
  179. }
  180. /* if multicast bit is set, the alternate address will not be used */
  181. if (alt_mac_addr[0] & 0x01) {
  182. e_dbg("Ignoring Alternate Mac Address with MC bit set\n");
  183. goto out;
  184. }
  185. /*
  186. * We have a valid alternate MAC address, and we want to treat it the
  187. * same as the normal permanent MAC address stored by the HW into the
  188. * RAR. Do this by mapping this address into RAR0.
  189. */
  190. e1000e_rar_set(hw, alt_mac_addr, 0);
  191. out:
  192. return ret_val;
  193. }
  194. /**
  195. * e1000e_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 e1000e_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 MAC address zero, no need to set the AV bit */
  215. if (rar_low || rar_high)
  216. rar_high |= E1000_RAH_AV;
  217. /*
  218. * Some bridges will combine consecutive 32-bit writes into
  219. * a single burst write, which will malfunction on some parts.
  220. * The flushes avoid this.
  221. */
  222. ew32(RAL(index), rar_low);
  223. e1e_flush();
  224. ew32(RAH(index), rar_high);
  225. e1e_flush();
  226. }
  227. /**
  228. * e1000_hash_mc_addr - Generate a multicast hash value
  229. * @hw: pointer to the HW structure
  230. * @mc_addr: pointer to a multicast address
  231. *
  232. * Generates a multicast address hash value which is used to determine
  233. * the multicast filter table array address and new table value. See
  234. * e1000_mta_set_generic()
  235. **/
  236. static u32 e1000_hash_mc_addr(struct e1000_hw *hw, u8 *mc_addr)
  237. {
  238. u32 hash_value, hash_mask;
  239. u8 bit_shift = 0;
  240. /* Register count multiplied by bits per register */
  241. hash_mask = (hw->mac.mta_reg_count * 32) - 1;
  242. /*
  243. * For a mc_filter_type of 0, bit_shift is the number of left-shifts
  244. * where 0xFF would still fall within the hash mask.
  245. */
  246. while (hash_mask >> bit_shift != 0xFF)
  247. bit_shift++;
  248. /*
  249. * The portion of the address that is used for the hash table
  250. * is determined by the mc_filter_type setting.
  251. * The algorithm is such that there is a total of 8 bits of shifting.
  252. * The bit_shift for a mc_filter_type of 0 represents the number of
  253. * left-shifts where the MSB of mc_addr[5] would still fall within
  254. * the hash_mask. Case 0 does this exactly. Since there are a total
  255. * of 8 bits of shifting, then mc_addr[4] will shift right the
  256. * remaining number of bits. Thus 8 - bit_shift. The rest of the
  257. * cases are a variation of this algorithm...essentially raising the
  258. * number of bits to shift mc_addr[5] left, while still keeping the
  259. * 8-bit shifting total.
  260. *
  261. * For example, given the following Destination MAC Address and an
  262. * mta register count of 128 (thus a 4096-bit vector and 0xFFF mask),
  263. * we can see that the bit_shift for case 0 is 4. These are the hash
  264. * values resulting from each mc_filter_type...
  265. * [0] [1] [2] [3] [4] [5]
  266. * 01 AA 00 12 34 56
  267. * LSB MSB
  268. *
  269. * case 0: hash_value = ((0x34 >> 4) | (0x56 << 4)) & 0xFFF = 0x563
  270. * case 1: hash_value = ((0x34 >> 3) | (0x56 << 5)) & 0xFFF = 0xAC6
  271. * case 2: hash_value = ((0x34 >> 2) | (0x56 << 6)) & 0xFFF = 0x163
  272. * case 3: hash_value = ((0x34 >> 0) | (0x56 << 8)) & 0xFFF = 0x634
  273. */
  274. switch (hw->mac.mc_filter_type) {
  275. default:
  276. case 0:
  277. break;
  278. case 1:
  279. bit_shift += 1;
  280. break;
  281. case 2:
  282. bit_shift += 2;
  283. break;
  284. case 3:
  285. bit_shift += 4;
  286. break;
  287. }
  288. hash_value = hash_mask & (((mc_addr[4] >> (8 - bit_shift)) |
  289. (((u16) mc_addr[5]) << bit_shift)));
  290. return hash_value;
  291. }
  292. /**
  293. * e1000e_update_mc_addr_list_generic - Update Multicast addresses
  294. * @hw: pointer to the HW structure
  295. * @mc_addr_list: array of multicast addresses to program
  296. * @mc_addr_count: number of multicast addresses to program
  297. *
  298. * Updates entire Multicast Table Array.
  299. * The caller must have a packed mc_addr_list of multicast addresses.
  300. **/
  301. void e1000e_update_mc_addr_list_generic(struct e1000_hw *hw,
  302. u8 *mc_addr_list, u32 mc_addr_count)
  303. {
  304. u32 hash_value, hash_bit, hash_reg;
  305. int i;
  306. /* clear mta_shadow */
  307. memset(&hw->mac.mta_shadow, 0, sizeof(hw->mac.mta_shadow));
  308. /* update mta_shadow from mc_addr_list */
  309. for (i = 0; (u32) i < mc_addr_count; i++) {
  310. hash_value = e1000_hash_mc_addr(hw, mc_addr_list);
  311. hash_reg = (hash_value >> 5) & (hw->mac.mta_reg_count - 1);
  312. hash_bit = hash_value & 0x1F;
  313. hw->mac.mta_shadow[hash_reg] |= (1 << hash_bit);
  314. mc_addr_list += (ETH_ALEN);
  315. }
  316. /* replace the entire MTA table */
  317. for (i = hw->mac.mta_reg_count - 1; i >= 0; i--)
  318. E1000_WRITE_REG_ARRAY(hw, E1000_MTA, i, hw->mac.mta_shadow[i]);
  319. e1e_flush();
  320. }
  321. /**
  322. * e1000e_clear_hw_cntrs_base - Clear base hardware counters
  323. * @hw: pointer to the HW structure
  324. *
  325. * Clears the base hardware counters by reading the counter registers.
  326. **/
  327. void e1000e_clear_hw_cntrs_base(struct e1000_hw *hw)
  328. {
  329. er32(CRCERRS);
  330. er32(SYMERRS);
  331. er32(MPC);
  332. er32(SCC);
  333. er32(ECOL);
  334. er32(MCC);
  335. er32(LATECOL);
  336. er32(COLC);
  337. er32(DC);
  338. er32(SEC);
  339. er32(RLEC);
  340. er32(XONRXC);
  341. er32(XONTXC);
  342. er32(XOFFRXC);
  343. er32(XOFFTXC);
  344. er32(FCRUC);
  345. er32(GPRC);
  346. er32(BPRC);
  347. er32(MPRC);
  348. er32(GPTC);
  349. er32(GORCL);
  350. er32(GORCH);
  351. er32(GOTCL);
  352. er32(GOTCH);
  353. er32(RNBC);
  354. er32(RUC);
  355. er32(RFC);
  356. er32(ROC);
  357. er32(RJC);
  358. er32(TORL);
  359. er32(TORH);
  360. er32(TOTL);
  361. er32(TOTH);
  362. er32(TPR);
  363. er32(TPT);
  364. er32(MPTC);
  365. er32(BPTC);
  366. }
  367. /**
  368. * e1000e_check_for_copper_link - Check for link (Copper)
  369. * @hw: pointer to the HW structure
  370. *
  371. * Checks to see of the link status of the hardware has changed. If a
  372. * change in link status has been detected, then we read the PHY registers
  373. * to get the current speed/duplex if link exists.
  374. **/
  375. s32 e1000e_check_for_copper_link(struct e1000_hw *hw)
  376. {
  377. struct e1000_mac_info *mac = &hw->mac;
  378. s32 ret_val;
  379. bool link;
  380. /*
  381. * We only want to go out to the PHY registers to see if Auto-Neg
  382. * has completed and/or if our link status has changed. The
  383. * get_link_status flag is set upon receiving a Link Status
  384. * Change or Rx Sequence Error interrupt.
  385. */
  386. if (!mac->get_link_status)
  387. return 0;
  388. /*
  389. * First we want to see if the MII Status Register reports
  390. * link. If so, then we want to get the current speed/duplex
  391. * of the PHY.
  392. */
  393. ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
  394. if (ret_val)
  395. return ret_val;
  396. if (!link)
  397. return ret_val; /* No link detected */
  398. mac->get_link_status = false;
  399. /*
  400. * Check if there was DownShift, must be checked
  401. * immediately after link-up
  402. */
  403. e1000e_check_downshift(hw);
  404. /*
  405. * If we are forcing speed/duplex, then we simply return since
  406. * we have already determined whether we have link or not.
  407. */
  408. if (!mac->autoneg) {
  409. ret_val = -E1000_ERR_CONFIG;
  410. return ret_val;
  411. }
  412. /*
  413. * Auto-Neg is enabled. Auto Speed Detection takes care
  414. * of MAC speed/duplex configuration. So we only need to
  415. * configure Collision Distance in the MAC.
  416. */
  417. e1000e_config_collision_dist(hw);
  418. /*
  419. * Configure Flow Control now that Auto-Neg has completed.
  420. * First, we need to restore the desired flow control
  421. * settings because we may have had to re-autoneg with a
  422. * different link partner.
  423. */
  424. ret_val = e1000e_config_fc_after_link_up(hw);
  425. if (ret_val) {
  426. e_dbg("Error configuring flow control\n");
  427. }
  428. return ret_val;
  429. }
  430. /**
  431. * e1000e_check_for_fiber_link - Check for link (Fiber)
  432. * @hw: pointer to the HW structure
  433. *
  434. * Checks for link up on the hardware. If link is not up and we have
  435. * a signal, then we need to force link up.
  436. **/
  437. s32 e1000e_check_for_fiber_link(struct e1000_hw *hw)
  438. {
  439. struct e1000_mac_info *mac = &hw->mac;
  440. u32 rxcw;
  441. u32 ctrl;
  442. u32 status;
  443. s32 ret_val;
  444. ctrl = er32(CTRL);
  445. status = er32(STATUS);
  446. rxcw = er32(RXCW);
  447. /*
  448. * If we don't have link (auto-negotiation failed or link partner
  449. * cannot auto-negotiate), the cable is plugged in (we have signal),
  450. * and our link partner is not trying to auto-negotiate with us (we
  451. * are receiving idles or data), we need to force link up. We also
  452. * need to give auto-negotiation time to complete, in case the cable
  453. * was just plugged in. The autoneg_failed flag does this.
  454. */
  455. /* (ctrl & E1000_CTRL_SWDPIN1) == 1 == have signal */
  456. if ((ctrl & E1000_CTRL_SWDPIN1) && (!(status & E1000_STATUS_LU)) &&
  457. (!(rxcw & E1000_RXCW_C))) {
  458. if (mac->autoneg_failed == 0) {
  459. mac->autoneg_failed = 1;
  460. return 0;
  461. }
  462. e_dbg("NOT RXing /C/, disable AutoNeg and force link.\n");
  463. /* Disable auto-negotiation in the TXCW register */
  464. ew32(TXCW, (mac->txcw & ~E1000_TXCW_ANE));
  465. /* Force link-up and also force full-duplex. */
  466. ctrl = er32(CTRL);
  467. ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
  468. ew32(CTRL, ctrl);
  469. /* Configure Flow Control after forcing link up. */
  470. ret_val = e1000e_config_fc_after_link_up(hw);
  471. if (ret_val) {
  472. e_dbg("Error configuring flow control\n");
  473. return ret_val;
  474. }
  475. } else if ((ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
  476. /*
  477. * If we are forcing link and we are receiving /C/ ordered
  478. * sets, re-enable auto-negotiation in the TXCW register
  479. * and disable forced link in the Device Control register
  480. * in an attempt to auto-negotiate with our link partner.
  481. */
  482. e_dbg("RXing /C/, enable AutoNeg and stop forcing link.\n");
  483. ew32(TXCW, mac->txcw);
  484. ew32(CTRL, (ctrl & ~E1000_CTRL_SLU));
  485. mac->serdes_has_link = true;
  486. }
  487. return 0;
  488. }
  489. /**
  490. * e1000e_check_for_serdes_link - Check for link (Serdes)
  491. * @hw: pointer to the HW structure
  492. *
  493. * Checks for link up on the hardware. If link is not up and we have
  494. * a signal, then we need to force link up.
  495. **/
  496. s32 e1000e_check_for_serdes_link(struct e1000_hw *hw)
  497. {
  498. struct e1000_mac_info *mac = &hw->mac;
  499. u32 rxcw;
  500. u32 ctrl;
  501. u32 status;
  502. s32 ret_val;
  503. ctrl = er32(CTRL);
  504. status = er32(STATUS);
  505. rxcw = er32(RXCW);
  506. /*
  507. * If we don't have link (auto-negotiation failed or link partner
  508. * cannot auto-negotiate), and our link partner is not trying to
  509. * auto-negotiate with us (we are receiving idles or data),
  510. * we need to force link up. We also need to give auto-negotiation
  511. * time to complete.
  512. */
  513. /* (ctrl & E1000_CTRL_SWDPIN1) == 1 == have signal */
  514. if ((!(status & E1000_STATUS_LU)) && (!(rxcw & E1000_RXCW_C))) {
  515. if (mac->autoneg_failed == 0) {
  516. mac->autoneg_failed = 1;
  517. return 0;
  518. }
  519. e_dbg("NOT RXing /C/, disable AutoNeg and force link.\n");
  520. /* Disable auto-negotiation in the TXCW register */
  521. ew32(TXCW, (mac->txcw & ~E1000_TXCW_ANE));
  522. /* Force link-up and also force full-duplex. */
  523. ctrl = er32(CTRL);
  524. ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
  525. ew32(CTRL, ctrl);
  526. /* Configure Flow Control after forcing link up. */
  527. ret_val = e1000e_config_fc_after_link_up(hw);
  528. if (ret_val) {
  529. e_dbg("Error configuring flow control\n");
  530. return ret_val;
  531. }
  532. } else if ((ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
  533. /*
  534. * If we are forcing link and we are receiving /C/ ordered
  535. * sets, re-enable auto-negotiation in the TXCW register
  536. * and disable forced link in the Device Control register
  537. * in an attempt to auto-negotiate with our link partner.
  538. */
  539. e_dbg("RXing /C/, enable AutoNeg and stop forcing link.\n");
  540. ew32(TXCW, mac->txcw);
  541. ew32(CTRL, (ctrl & ~E1000_CTRL_SLU));
  542. mac->serdes_has_link = true;
  543. } else if (!(E1000_TXCW_ANE & er32(TXCW))) {
  544. /*
  545. * If we force link for non-auto-negotiation switch, check
  546. * link status based on MAC synchronization for internal
  547. * serdes media type.
  548. */
  549. /* SYNCH bit and IV bit are sticky. */
  550. udelay(10);
  551. rxcw = er32(RXCW);
  552. if (rxcw & E1000_RXCW_SYNCH) {
  553. if (!(rxcw & E1000_RXCW_IV)) {
  554. mac->serdes_has_link = true;
  555. e_dbg("SERDES: Link up - forced.\n");
  556. }
  557. } else {
  558. mac->serdes_has_link = false;
  559. e_dbg("SERDES: Link down - force failed.\n");
  560. }
  561. }
  562. if (E1000_TXCW_ANE & er32(TXCW)) {
  563. status = er32(STATUS);
  564. if (status & E1000_STATUS_LU) {
  565. /* SYNCH bit and IV bit are sticky, so reread rxcw. */
  566. udelay(10);
  567. rxcw = er32(RXCW);
  568. if (rxcw & E1000_RXCW_SYNCH) {
  569. if (!(rxcw & E1000_RXCW_IV)) {
  570. mac->serdes_has_link = true;
  571. e_dbg("SERDES: Link up - autoneg "
  572. "completed successfully.\n");
  573. } else {
  574. mac->serdes_has_link = false;
  575. e_dbg("SERDES: Link down - invalid"
  576. "codewords detected in autoneg.\n");
  577. }
  578. } else {
  579. mac->serdes_has_link = false;
  580. e_dbg("SERDES: Link down - no sync.\n");
  581. }
  582. } else {
  583. mac->serdes_has_link = false;
  584. e_dbg("SERDES: Link down - autoneg failed\n");
  585. }
  586. }
  587. return 0;
  588. }
  589. /**
  590. * e1000_set_default_fc_generic - Set flow control default values
  591. * @hw: pointer to the HW structure
  592. *
  593. * Read the EEPROM for the default values for flow control and store the
  594. * values.
  595. **/
  596. static s32 e1000_set_default_fc_generic(struct e1000_hw *hw)
  597. {
  598. s32 ret_val;
  599. u16 nvm_data;
  600. /*
  601. * Read and store word 0x0F of the EEPROM. This word contains bits
  602. * that determine the hardware's default PAUSE (flow control) mode,
  603. * a bit that determines whether the HW defaults to enabling or
  604. * disabling auto-negotiation, and the direction of the
  605. * SW defined pins. If there is no SW over-ride of the flow
  606. * control setting, then the variable hw->fc will
  607. * be initialized based on a value in the EEPROM.
  608. */
  609. ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &nvm_data);
  610. if (ret_val) {
  611. e_dbg("NVM Read Error\n");
  612. return ret_val;
  613. }
  614. if ((nvm_data & NVM_WORD0F_PAUSE_MASK) == 0)
  615. hw->fc.requested_mode = e1000_fc_none;
  616. else if ((nvm_data & NVM_WORD0F_PAUSE_MASK) ==
  617. NVM_WORD0F_ASM_DIR)
  618. hw->fc.requested_mode = e1000_fc_tx_pause;
  619. else
  620. hw->fc.requested_mode = e1000_fc_full;
  621. return 0;
  622. }
  623. /**
  624. * e1000e_setup_link - Setup flow control and link settings
  625. * @hw: pointer to the HW structure
  626. *
  627. * Determines which flow control settings to use, then configures flow
  628. * control. Calls the appropriate media-specific link configuration
  629. * function. Assuming the adapter has a valid link partner, a valid link
  630. * should be established. Assumes the hardware has previously been reset
  631. * and the transmitter and receiver are not enabled.
  632. **/
  633. s32 e1000e_setup_link(struct e1000_hw *hw)
  634. {
  635. struct e1000_mac_info *mac = &hw->mac;
  636. s32 ret_val;
  637. /*
  638. * In the case of the phy reset being blocked, we already have a link.
  639. * We do not need to set it up again.
  640. */
  641. if (e1000_check_reset_block(hw))
  642. return 0;
  643. /*
  644. * If requested flow control is set to default, set flow control
  645. * based on the EEPROM flow control settings.
  646. */
  647. if (hw->fc.requested_mode == e1000_fc_default) {
  648. ret_val = e1000_set_default_fc_generic(hw);
  649. if (ret_val)
  650. return ret_val;
  651. }
  652. /*
  653. * Save off the requested flow control mode for use later. Depending
  654. * on the link partner's capabilities, we may or may not use this mode.
  655. */
  656. hw->fc.current_mode = hw->fc.requested_mode;
  657. e_dbg("After fix-ups FlowControl is now = %x\n",
  658. hw->fc.current_mode);
  659. /* Call the necessary media_type subroutine to configure the link. */
  660. ret_val = mac->ops.setup_physical_interface(hw);
  661. if (ret_val)
  662. return ret_val;
  663. /*
  664. * Initialize the flow control address, type, and PAUSE timer
  665. * registers to their default values. This is done even if flow
  666. * control is disabled, because it does not hurt anything to
  667. * initialize these registers.
  668. */
  669. e_dbg("Initializing the Flow Control address, type and timer regs\n");
  670. ew32(FCT, FLOW_CONTROL_TYPE);
  671. ew32(FCAH, FLOW_CONTROL_ADDRESS_HIGH);
  672. ew32(FCAL, FLOW_CONTROL_ADDRESS_LOW);
  673. ew32(FCTTV, hw->fc.pause_time);
  674. return e1000e_set_fc_watermarks(hw);
  675. }
  676. /**
  677. * e1000_commit_fc_settings_generic - Configure flow control
  678. * @hw: pointer to the HW structure
  679. *
  680. * Write the flow control settings to the Transmit Config Word Register (TXCW)
  681. * base on the flow control settings in e1000_mac_info.
  682. **/
  683. static s32 e1000_commit_fc_settings_generic(struct e1000_hw *hw)
  684. {
  685. struct e1000_mac_info *mac = &hw->mac;
  686. u32 txcw;
  687. /*
  688. * Check for a software override of the flow control settings, and
  689. * setup the device accordingly. If auto-negotiation is enabled, then
  690. * software will have to set the "PAUSE" bits to the correct value in
  691. * the Transmit Config Word Register (TXCW) and re-start auto-
  692. * negotiation. However, if auto-negotiation is disabled, then
  693. * software will have to manually configure the two flow control enable
  694. * bits in the CTRL register.
  695. *
  696. * The possible values of the "fc" parameter are:
  697. * 0: Flow control is completely disabled
  698. * 1: Rx flow control is enabled (we can receive pause frames,
  699. * but not send pause frames).
  700. * 2: Tx flow control is enabled (we can send pause frames but we
  701. * do not support receiving pause frames).
  702. * 3: Both Rx and Tx flow control (symmetric) are enabled.
  703. */
  704. switch (hw->fc.current_mode) {
  705. case e1000_fc_none:
  706. /* Flow control completely disabled by a software over-ride. */
  707. txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
  708. break;
  709. case e1000_fc_rx_pause:
  710. /*
  711. * Rx Flow control is enabled and Tx Flow control is disabled
  712. * by a software over-ride. Since there really isn't a way to
  713. * advertise that we are capable of Rx Pause ONLY, we will
  714. * advertise that we support both symmetric and asymmetric Rx
  715. * PAUSE. Later, we will disable the adapter's ability to send
  716. * PAUSE frames.
  717. */
  718. txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
  719. break;
  720. case e1000_fc_tx_pause:
  721. /*
  722. * Tx Flow control is enabled, and Rx Flow control is disabled,
  723. * by a software over-ride.
  724. */
  725. txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
  726. break;
  727. case e1000_fc_full:
  728. /*
  729. * Flow control (both Rx and Tx) is enabled by a software
  730. * over-ride.
  731. */
  732. txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
  733. break;
  734. default:
  735. e_dbg("Flow control param set incorrectly\n");
  736. return -E1000_ERR_CONFIG;
  737. break;
  738. }
  739. ew32(TXCW, txcw);
  740. mac->txcw = txcw;
  741. return 0;
  742. }
  743. /**
  744. * e1000_poll_fiber_serdes_link_generic - Poll for link up
  745. * @hw: pointer to the HW structure
  746. *
  747. * Polls for link up by reading the status register, if link fails to come
  748. * up with auto-negotiation, then the link is forced if a signal is detected.
  749. **/
  750. static s32 e1000_poll_fiber_serdes_link_generic(struct e1000_hw *hw)
  751. {
  752. struct e1000_mac_info *mac = &hw->mac;
  753. u32 i, status;
  754. s32 ret_val;
  755. /*
  756. * If we have a signal (the cable is plugged in, or assumed true for
  757. * serdes media) then poll for a "Link-Up" indication in the Device
  758. * Status Register. Time-out if a link isn't seen in 500 milliseconds
  759. * seconds (Auto-negotiation should complete in less than 500
  760. * milliseconds even if the other end is doing it in SW).
  761. */
  762. for (i = 0; i < FIBER_LINK_UP_LIMIT; i++) {
  763. msleep(10);
  764. status = er32(STATUS);
  765. if (status & E1000_STATUS_LU)
  766. break;
  767. }
  768. if (i == FIBER_LINK_UP_LIMIT) {
  769. e_dbg("Never got a valid link from auto-neg!!!\n");
  770. mac->autoneg_failed = 1;
  771. /*
  772. * AutoNeg failed to achieve a link, so we'll call
  773. * mac->check_for_link. This routine will force the
  774. * link up if we detect a signal. This will allow us to
  775. * communicate with non-autonegotiating link partners.
  776. */
  777. ret_val = mac->ops.check_for_link(hw);
  778. if (ret_val) {
  779. e_dbg("Error while checking for link\n");
  780. return ret_val;
  781. }
  782. mac->autoneg_failed = 0;
  783. } else {
  784. mac->autoneg_failed = 0;
  785. e_dbg("Valid Link Found\n");
  786. }
  787. return 0;
  788. }
  789. /**
  790. * e1000e_setup_fiber_serdes_link - Setup link for fiber/serdes
  791. * @hw: pointer to the HW structure
  792. *
  793. * Configures collision distance and flow control for fiber and serdes
  794. * links. Upon successful setup, poll for link.
  795. **/
  796. s32 e1000e_setup_fiber_serdes_link(struct e1000_hw *hw)
  797. {
  798. u32 ctrl;
  799. s32 ret_val;
  800. ctrl = er32(CTRL);
  801. /* Take the link out of reset */
  802. ctrl &= ~E1000_CTRL_LRST;
  803. e1000e_config_collision_dist(hw);
  804. ret_val = e1000_commit_fc_settings_generic(hw);
  805. if (ret_val)
  806. return ret_val;
  807. /*
  808. * Since auto-negotiation is enabled, take the link out of reset (the
  809. * link will be in reset, because we previously reset the chip). This
  810. * will restart auto-negotiation. If auto-negotiation is successful
  811. * then the link-up status bit will be set and the flow control enable
  812. * bits (RFCE and TFCE) will be set according to their negotiated value.
  813. */
  814. e_dbg("Auto-negotiation enabled\n");
  815. ew32(CTRL, ctrl);
  816. e1e_flush();
  817. msleep(1);
  818. /*
  819. * For these adapters, the SW definable pin 1 is set when the optics
  820. * detect a signal. If we have a signal, then poll for a "Link-Up"
  821. * indication.
  822. */
  823. if (hw->phy.media_type == e1000_media_type_internal_serdes ||
  824. (er32(CTRL) & E1000_CTRL_SWDPIN1)) {
  825. ret_val = e1000_poll_fiber_serdes_link_generic(hw);
  826. } else {
  827. e_dbg("No signal detected\n");
  828. }
  829. return 0;
  830. }
  831. /**
  832. * e1000e_config_collision_dist - Configure collision distance
  833. * @hw: pointer to the HW structure
  834. *
  835. * Configures the collision distance to the default value and is used
  836. * during link setup. Currently no func pointer exists and all
  837. * implementations are handled in the generic version of this function.
  838. **/
  839. void e1000e_config_collision_dist(struct e1000_hw *hw)
  840. {
  841. u32 tctl;
  842. tctl = er32(TCTL);
  843. tctl &= ~E1000_TCTL_COLD;
  844. tctl |= E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT;
  845. ew32(TCTL, tctl);
  846. e1e_flush();
  847. }
  848. /**
  849. * e1000e_set_fc_watermarks - Set flow control high/low watermarks
  850. * @hw: pointer to the HW structure
  851. *
  852. * Sets the flow control high/low threshold (watermark) registers. If
  853. * flow control XON frame transmission is enabled, then set XON frame
  854. * transmission as well.
  855. **/
  856. s32 e1000e_set_fc_watermarks(struct e1000_hw *hw)
  857. {
  858. u32 fcrtl = 0, fcrth = 0;
  859. /*
  860. * Set the flow control receive threshold registers. Normally,
  861. * these registers will be set to a default threshold that may be
  862. * adjusted later by the driver's runtime code. However, if the
  863. * ability to transmit pause frames is not enabled, then these
  864. * registers will be set to 0.
  865. */
  866. if (hw->fc.current_mode & e1000_fc_tx_pause) {
  867. /*
  868. * We need to set up the Receive Threshold high and low water
  869. * marks as well as (optionally) enabling the transmission of
  870. * XON frames.
  871. */
  872. fcrtl = hw->fc.low_water;
  873. fcrtl |= E1000_FCRTL_XONE;
  874. fcrth = hw->fc.high_water;
  875. }
  876. ew32(FCRTL, fcrtl);
  877. ew32(FCRTH, fcrth);
  878. return 0;
  879. }
  880. /**
  881. * e1000e_force_mac_fc - Force the MAC's flow control settings
  882. * @hw: pointer to the HW structure
  883. *
  884. * Force the MAC's flow control settings. Sets the TFCE and RFCE bits in the
  885. * device control register to reflect the adapter settings. TFCE and RFCE
  886. * need to be explicitly set by software when a copper PHY is used because
  887. * autonegotiation is managed by the PHY rather than the MAC. Software must
  888. * also configure these bits when link is forced on a fiber connection.
  889. **/
  890. s32 e1000e_force_mac_fc(struct e1000_hw *hw)
  891. {
  892. u32 ctrl;
  893. ctrl = er32(CTRL);
  894. /*
  895. * Because we didn't get link via the internal auto-negotiation
  896. * mechanism (we either forced link or we got link via PHY
  897. * auto-neg), we have to manually enable/disable transmit an
  898. * receive flow control.
  899. *
  900. * The "Case" statement below enables/disable flow control
  901. * according to the "hw->fc.current_mode" parameter.
  902. *
  903. * The possible values of the "fc" parameter are:
  904. * 0: Flow control is completely disabled
  905. * 1: Rx flow control is enabled (we can receive pause
  906. * frames but not send pause frames).
  907. * 2: Tx flow control is enabled (we can send pause frames
  908. * frames but we do not receive pause frames).
  909. * 3: Both Rx and Tx flow control (symmetric) is enabled.
  910. * other: No other values should be possible at this point.
  911. */
  912. e_dbg("hw->fc.current_mode = %u\n", hw->fc.current_mode);
  913. switch (hw->fc.current_mode) {
  914. case e1000_fc_none:
  915. ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
  916. break;
  917. case e1000_fc_rx_pause:
  918. ctrl &= (~E1000_CTRL_TFCE);
  919. ctrl |= E1000_CTRL_RFCE;
  920. break;
  921. case e1000_fc_tx_pause:
  922. ctrl &= (~E1000_CTRL_RFCE);
  923. ctrl |= E1000_CTRL_TFCE;
  924. break;
  925. case e1000_fc_full:
  926. ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
  927. break;
  928. default:
  929. e_dbg("Flow control param set incorrectly\n");
  930. return -E1000_ERR_CONFIG;
  931. }
  932. ew32(CTRL, ctrl);
  933. return 0;
  934. }
  935. /**
  936. * e1000e_config_fc_after_link_up - Configures flow control after link
  937. * @hw: pointer to the HW structure
  938. *
  939. * Checks the status of auto-negotiation after link up to ensure that the
  940. * speed and duplex were not forced. If the link needed to be forced, then
  941. * flow control needs to be forced also. If auto-negotiation is enabled
  942. * and did not fail, then we configure flow control based on our link
  943. * partner.
  944. **/
  945. s32 e1000e_config_fc_after_link_up(struct e1000_hw *hw)
  946. {
  947. struct e1000_mac_info *mac = &hw->mac;
  948. s32 ret_val = 0;
  949. u16 mii_status_reg, mii_nway_adv_reg, mii_nway_lp_ability_reg;
  950. u16 speed, duplex;
  951. /*
  952. * Check for the case where we have fiber media and auto-neg failed
  953. * so we had to force link. In this case, we need to force the
  954. * configuration of the MAC to match the "fc" parameter.
  955. */
  956. if (mac->autoneg_failed) {
  957. if (hw->phy.media_type == e1000_media_type_fiber ||
  958. hw->phy.media_type == e1000_media_type_internal_serdes)
  959. ret_val = e1000e_force_mac_fc(hw);
  960. } else {
  961. if (hw->phy.media_type == e1000_media_type_copper)
  962. ret_val = e1000e_force_mac_fc(hw);
  963. }
  964. if (ret_val) {
  965. e_dbg("Error forcing flow control settings\n");
  966. return ret_val;
  967. }
  968. /*
  969. * Check for the case where we have copper media and auto-neg is
  970. * enabled. In this case, we need to check and see if Auto-Neg
  971. * has completed, and if so, how the PHY and link partner has
  972. * flow control configured.
  973. */
  974. if ((hw->phy.media_type == e1000_media_type_copper) && mac->autoneg) {
  975. /*
  976. * Read the MII Status Register and check to see if AutoNeg
  977. * has completed. We read this twice because this reg has
  978. * some "sticky" (latched) bits.
  979. */
  980. ret_val = e1e_rphy(hw, PHY_STATUS, &mii_status_reg);
  981. if (ret_val)
  982. return ret_val;
  983. ret_val = e1e_rphy(hw, PHY_STATUS, &mii_status_reg);
  984. if (ret_val)
  985. return ret_val;
  986. if (!(mii_status_reg & MII_SR_AUTONEG_COMPLETE)) {
  987. e_dbg("Copper PHY and Auto Neg "
  988. "has not completed.\n");
  989. return ret_val;
  990. }
  991. /*
  992. * The AutoNeg process has completed, so we now need to
  993. * read both the Auto Negotiation Advertisement
  994. * Register (Address 4) and the Auto_Negotiation Base
  995. * Page Ability Register (Address 5) to determine how
  996. * flow control was negotiated.
  997. */
  998. ret_val = e1e_rphy(hw, PHY_AUTONEG_ADV, &mii_nway_adv_reg);
  999. if (ret_val)
  1000. return ret_val;
  1001. ret_val = e1e_rphy(hw, PHY_LP_ABILITY, &mii_nway_lp_ability_reg);
  1002. if (ret_val)
  1003. return ret_val;
  1004. /*
  1005. * Two bits in the Auto Negotiation Advertisement Register
  1006. * (Address 4) and two bits in the Auto Negotiation Base
  1007. * Page Ability Register (Address 5) determine flow control
  1008. * for both the PHY and the link partner. The following
  1009. * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
  1010. * 1999, describes these PAUSE resolution bits and how flow
  1011. * control is determined based upon these settings.
  1012. * NOTE: DC = Don't Care
  1013. *
  1014. * LOCAL DEVICE | LINK PARTNER
  1015. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
  1016. *-------|---------|-------|---------|--------------------
  1017. * 0 | 0 | DC | DC | e1000_fc_none
  1018. * 0 | 1 | 0 | DC | e1000_fc_none
  1019. * 0 | 1 | 1 | 0 | e1000_fc_none
  1020. * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
  1021. * 1 | 0 | 0 | DC | e1000_fc_none
  1022. * 1 | DC | 1 | DC | e1000_fc_full
  1023. * 1 | 1 | 0 | 0 | e1000_fc_none
  1024. * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
  1025. *
  1026. * Are both PAUSE bits set to 1? If so, this implies
  1027. * Symmetric Flow Control is enabled at both ends. The
  1028. * ASM_DIR bits are irrelevant per the spec.
  1029. *
  1030. * For Symmetric Flow Control:
  1031. *
  1032. * LOCAL DEVICE | LINK PARTNER
  1033. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
  1034. *-------|---------|-------|---------|--------------------
  1035. * 1 | DC | 1 | DC | E1000_fc_full
  1036. *
  1037. */
  1038. if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
  1039. (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
  1040. /*
  1041. * Now we need to check if the user selected Rx ONLY
  1042. * of pause frames. In this case, we had to advertise
  1043. * FULL flow control because we could not advertise Rx
  1044. * ONLY. Hence, we must now check to see if we need to
  1045. * turn OFF the TRANSMISSION of PAUSE frames.
  1046. */
  1047. if (hw->fc.requested_mode == e1000_fc_full) {
  1048. hw->fc.current_mode = e1000_fc_full;
  1049. e_dbg("Flow Control = FULL.\r\n");
  1050. } else {
  1051. hw->fc.current_mode = e1000_fc_rx_pause;
  1052. e_dbg("Flow Control = "
  1053. "RX PAUSE frames only.\r\n");
  1054. }
  1055. }
  1056. /*
  1057. * For receiving PAUSE frames ONLY.
  1058. *
  1059. * LOCAL DEVICE | LINK PARTNER
  1060. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
  1061. *-------|---------|-------|---------|--------------------
  1062. * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
  1063. */
  1064. else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
  1065. (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
  1066. (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
  1067. (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
  1068. hw->fc.current_mode = e1000_fc_tx_pause;
  1069. e_dbg("Flow Control = Tx PAUSE frames only.\r\n");
  1070. }
  1071. /*
  1072. * For transmitting PAUSE frames ONLY.
  1073. *
  1074. * LOCAL DEVICE | LINK PARTNER
  1075. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
  1076. *-------|---------|-------|---------|--------------------
  1077. * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
  1078. */
  1079. else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
  1080. (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
  1081. !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
  1082. (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
  1083. hw->fc.current_mode = e1000_fc_rx_pause;
  1084. e_dbg("Flow Control = Rx PAUSE frames only.\r\n");
  1085. } else {
  1086. /*
  1087. * Per the IEEE spec, at this point flow control
  1088. * should be disabled.
  1089. */
  1090. hw->fc.current_mode = e1000_fc_none;
  1091. e_dbg("Flow Control = NONE.\r\n");
  1092. }
  1093. /*
  1094. * Now we need to do one last check... If we auto-
  1095. * negotiated to HALF DUPLEX, flow control should not be
  1096. * enabled per IEEE 802.3 spec.
  1097. */
  1098. ret_val = mac->ops.get_link_up_info(hw, &speed, &duplex);
  1099. if (ret_val) {
  1100. e_dbg("Error getting link speed and duplex\n");
  1101. return ret_val;
  1102. }
  1103. if (duplex == HALF_DUPLEX)
  1104. hw->fc.current_mode = e1000_fc_none;
  1105. /*
  1106. * Now we call a subroutine to actually force the MAC
  1107. * controller to use the correct flow control settings.
  1108. */
  1109. ret_val = e1000e_force_mac_fc(hw);
  1110. if (ret_val) {
  1111. e_dbg("Error forcing flow control settings\n");
  1112. return ret_val;
  1113. }
  1114. }
  1115. return 0;
  1116. }
  1117. /**
  1118. * e1000e_get_speed_and_duplex_copper - Retrieve current speed/duplex
  1119. * @hw: pointer to the HW structure
  1120. * @speed: stores the current speed
  1121. * @duplex: stores the current duplex
  1122. *
  1123. * Read the status register for the current speed/duplex and store the current
  1124. * speed and duplex for copper connections.
  1125. **/
  1126. s32 e1000e_get_speed_and_duplex_copper(struct e1000_hw *hw, u16 *speed, u16 *duplex)
  1127. {
  1128. u32 status;
  1129. status = er32(STATUS);
  1130. if (status & E1000_STATUS_SPEED_1000)
  1131. *speed = SPEED_1000;
  1132. else if (status & E1000_STATUS_SPEED_100)
  1133. *speed = SPEED_100;
  1134. else
  1135. *speed = SPEED_10;
  1136. if (status & E1000_STATUS_FD)
  1137. *duplex = FULL_DUPLEX;
  1138. else
  1139. *duplex = HALF_DUPLEX;
  1140. e_dbg("%u Mbps, %s Duplex\n",
  1141. *speed == SPEED_1000 ? 1000 : *speed == SPEED_100 ? 100 : 10,
  1142. *duplex == FULL_DUPLEX ? "Full" : "Half");
  1143. return 0;
  1144. }
  1145. /**
  1146. * e1000e_get_speed_and_duplex_fiber_serdes - Retrieve current speed/duplex
  1147. * @hw: pointer to the HW structure
  1148. * @speed: stores the current speed
  1149. * @duplex: stores the current duplex
  1150. *
  1151. * Sets the speed and duplex to gigabit full duplex (the only possible option)
  1152. * for fiber/serdes links.
  1153. **/
  1154. s32 e1000e_get_speed_and_duplex_fiber_serdes(struct e1000_hw *hw, u16 *speed, u16 *duplex)
  1155. {
  1156. *speed = SPEED_1000;
  1157. *duplex = FULL_DUPLEX;
  1158. return 0;
  1159. }
  1160. /**
  1161. * e1000e_get_hw_semaphore - Acquire hardware semaphore
  1162. * @hw: pointer to the HW structure
  1163. *
  1164. * Acquire the HW semaphore to access the PHY or NVM
  1165. **/
  1166. s32 e1000e_get_hw_semaphore(struct e1000_hw *hw)
  1167. {
  1168. u32 swsm;
  1169. s32 timeout = hw->nvm.word_size + 1;
  1170. s32 i = 0;
  1171. /* Get the SW semaphore */
  1172. while (i < timeout) {
  1173. swsm = er32(SWSM);
  1174. if (!(swsm & E1000_SWSM_SMBI))
  1175. break;
  1176. udelay(50);
  1177. i++;
  1178. }
  1179. if (i == timeout) {
  1180. e_dbg("Driver can't access device - SMBI bit is set.\n");
  1181. return -E1000_ERR_NVM;
  1182. }
  1183. /* Get the FW semaphore. */
  1184. for (i = 0; i < timeout; i++) {
  1185. swsm = er32(SWSM);
  1186. ew32(SWSM, swsm | E1000_SWSM_SWESMBI);
  1187. /* Semaphore acquired if bit latched */
  1188. if (er32(SWSM) & E1000_SWSM_SWESMBI)
  1189. break;
  1190. udelay(50);
  1191. }
  1192. if (i == timeout) {
  1193. /* Release semaphores */
  1194. e1000e_put_hw_semaphore(hw);
  1195. e_dbg("Driver can't access the NVM\n");
  1196. return -E1000_ERR_NVM;
  1197. }
  1198. return 0;
  1199. }
  1200. /**
  1201. * e1000e_put_hw_semaphore - Release hardware semaphore
  1202. * @hw: pointer to the HW structure
  1203. *
  1204. * Release hardware semaphore used to access the PHY or NVM
  1205. **/
  1206. void e1000e_put_hw_semaphore(struct e1000_hw *hw)
  1207. {
  1208. u32 swsm;
  1209. swsm = er32(SWSM);
  1210. swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI);
  1211. ew32(SWSM, swsm);
  1212. }
  1213. /**
  1214. * e1000e_get_auto_rd_done - Check for auto read completion
  1215. * @hw: pointer to the HW structure
  1216. *
  1217. * Check EEPROM for Auto Read done bit.
  1218. **/
  1219. s32 e1000e_get_auto_rd_done(struct e1000_hw *hw)
  1220. {
  1221. s32 i = 0;
  1222. while (i < AUTO_READ_DONE_TIMEOUT) {
  1223. if (er32(EECD) & E1000_EECD_AUTO_RD)
  1224. break;
  1225. msleep(1);
  1226. i++;
  1227. }
  1228. if (i == AUTO_READ_DONE_TIMEOUT) {
  1229. e_dbg("Auto read by HW from NVM has not completed.\n");
  1230. return -E1000_ERR_RESET;
  1231. }
  1232. return 0;
  1233. }
  1234. /**
  1235. * e1000e_valid_led_default - Verify a valid default LED config
  1236. * @hw: pointer to the HW structure
  1237. * @data: pointer to the NVM (EEPROM)
  1238. *
  1239. * Read the EEPROM for the current default LED configuration. If the
  1240. * LED configuration is not valid, set to a valid LED configuration.
  1241. **/
  1242. s32 e1000e_valid_led_default(struct e1000_hw *hw, u16 *data)
  1243. {
  1244. s32 ret_val;
  1245. ret_val = e1000_read_nvm(hw, NVM_ID_LED_SETTINGS, 1, data);
  1246. if (ret_val) {
  1247. e_dbg("NVM Read Error\n");
  1248. return ret_val;
  1249. }
  1250. if (*data == ID_LED_RESERVED_0000 || *data == ID_LED_RESERVED_FFFF)
  1251. *data = ID_LED_DEFAULT;
  1252. return 0;
  1253. }
  1254. /**
  1255. * e1000e_id_led_init -
  1256. * @hw: pointer to the HW structure
  1257. *
  1258. **/
  1259. s32 e1000e_id_led_init(struct e1000_hw *hw)
  1260. {
  1261. struct e1000_mac_info *mac = &hw->mac;
  1262. s32 ret_val;
  1263. const u32 ledctl_mask = 0x000000FF;
  1264. const u32 ledctl_on = E1000_LEDCTL_MODE_LED_ON;
  1265. const u32 ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
  1266. u16 data, i, temp;
  1267. const u16 led_mask = 0x0F;
  1268. ret_val = hw->nvm.ops.valid_led_default(hw, &data);
  1269. if (ret_val)
  1270. return ret_val;
  1271. mac->ledctl_default = er32(LEDCTL);
  1272. mac->ledctl_mode1 = mac->ledctl_default;
  1273. mac->ledctl_mode2 = mac->ledctl_default;
  1274. for (i = 0; i < 4; i++) {
  1275. temp = (data >> (i << 2)) & led_mask;
  1276. switch (temp) {
  1277. case ID_LED_ON1_DEF2:
  1278. case ID_LED_ON1_ON2:
  1279. case ID_LED_ON1_OFF2:
  1280. mac->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
  1281. mac->ledctl_mode1 |= ledctl_on << (i << 3);
  1282. break;
  1283. case ID_LED_OFF1_DEF2:
  1284. case ID_LED_OFF1_ON2:
  1285. case ID_LED_OFF1_OFF2:
  1286. mac->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
  1287. mac->ledctl_mode1 |= ledctl_off << (i << 3);
  1288. break;
  1289. default:
  1290. /* Do nothing */
  1291. break;
  1292. }
  1293. switch (temp) {
  1294. case ID_LED_DEF1_ON2:
  1295. case ID_LED_ON1_ON2:
  1296. case ID_LED_OFF1_ON2:
  1297. mac->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
  1298. mac->ledctl_mode2 |= ledctl_on << (i << 3);
  1299. break;
  1300. case ID_LED_DEF1_OFF2:
  1301. case ID_LED_ON1_OFF2:
  1302. case ID_LED_OFF1_OFF2:
  1303. mac->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
  1304. mac->ledctl_mode2 |= ledctl_off << (i << 3);
  1305. break;
  1306. default:
  1307. /* Do nothing */
  1308. break;
  1309. }
  1310. }
  1311. return 0;
  1312. }
  1313. /**
  1314. * e1000e_setup_led_generic - Configures SW controllable LED
  1315. * @hw: pointer to the HW structure
  1316. *
  1317. * This prepares the SW controllable LED for use and saves the current state
  1318. * of the LED so it can be later restored.
  1319. **/
  1320. s32 e1000e_setup_led_generic(struct e1000_hw *hw)
  1321. {
  1322. u32 ledctl;
  1323. if (hw->mac.ops.setup_led != e1000e_setup_led_generic) {
  1324. return -E1000_ERR_CONFIG;
  1325. }
  1326. if (hw->phy.media_type == e1000_media_type_fiber) {
  1327. ledctl = er32(LEDCTL);
  1328. hw->mac.ledctl_default = ledctl;
  1329. /* Turn off LED0 */
  1330. ledctl &= ~(E1000_LEDCTL_LED0_IVRT |
  1331. E1000_LEDCTL_LED0_BLINK |
  1332. E1000_LEDCTL_LED0_MODE_MASK);
  1333. ledctl |= (E1000_LEDCTL_MODE_LED_OFF <<
  1334. E1000_LEDCTL_LED0_MODE_SHIFT);
  1335. ew32(LEDCTL, ledctl);
  1336. } else if (hw->phy.media_type == e1000_media_type_copper) {
  1337. ew32(LEDCTL, hw->mac.ledctl_mode1);
  1338. }
  1339. return 0;
  1340. }
  1341. /**
  1342. * e1000e_cleanup_led_generic - Set LED config to default operation
  1343. * @hw: pointer to the HW structure
  1344. *
  1345. * Remove the current LED configuration and set the LED configuration
  1346. * to the default value, saved from the EEPROM.
  1347. **/
  1348. s32 e1000e_cleanup_led_generic(struct e1000_hw *hw)
  1349. {
  1350. ew32(LEDCTL, hw->mac.ledctl_default);
  1351. return 0;
  1352. }
  1353. /**
  1354. * e1000e_blink_led - Blink LED
  1355. * @hw: pointer to the HW structure
  1356. *
  1357. * Blink the LEDs which are set to be on.
  1358. **/
  1359. s32 e1000e_blink_led(struct e1000_hw *hw)
  1360. {
  1361. u32 ledctl_blink = 0;
  1362. u32 i;
  1363. if (hw->phy.media_type == e1000_media_type_fiber) {
  1364. /* always blink LED0 for PCI-E fiber */
  1365. ledctl_blink = E1000_LEDCTL_LED0_BLINK |
  1366. (E1000_LEDCTL_MODE_LED_ON << E1000_LEDCTL_LED0_MODE_SHIFT);
  1367. } else {
  1368. /*
  1369. * set the blink bit for each LED that's "on" (0x0E)
  1370. * in ledctl_mode2
  1371. */
  1372. ledctl_blink = hw->mac.ledctl_mode2;
  1373. for (i = 0; i < 4; i++)
  1374. if (((hw->mac.ledctl_mode2 >> (i * 8)) & 0xFF) ==
  1375. E1000_LEDCTL_MODE_LED_ON)
  1376. ledctl_blink |= (E1000_LEDCTL_LED0_BLINK <<
  1377. (i * 8));
  1378. }
  1379. ew32(LEDCTL, ledctl_blink);
  1380. return 0;
  1381. }
  1382. /**
  1383. * e1000e_led_on_generic - Turn LED on
  1384. * @hw: pointer to the HW structure
  1385. *
  1386. * Turn LED on.
  1387. **/
  1388. s32 e1000e_led_on_generic(struct e1000_hw *hw)
  1389. {
  1390. u32 ctrl;
  1391. switch (hw->phy.media_type) {
  1392. case e1000_media_type_fiber:
  1393. ctrl = er32(CTRL);
  1394. ctrl &= ~E1000_CTRL_SWDPIN0;
  1395. ctrl |= E1000_CTRL_SWDPIO0;
  1396. ew32(CTRL, ctrl);
  1397. break;
  1398. case e1000_media_type_copper:
  1399. ew32(LEDCTL, hw->mac.ledctl_mode2);
  1400. break;
  1401. default:
  1402. break;
  1403. }
  1404. return 0;
  1405. }
  1406. /**
  1407. * e1000e_led_off_generic - Turn LED off
  1408. * @hw: pointer to the HW structure
  1409. *
  1410. * Turn LED off.
  1411. **/
  1412. s32 e1000e_led_off_generic(struct e1000_hw *hw)
  1413. {
  1414. u32 ctrl;
  1415. switch (hw->phy.media_type) {
  1416. case e1000_media_type_fiber:
  1417. ctrl = er32(CTRL);
  1418. ctrl |= E1000_CTRL_SWDPIN0;
  1419. ctrl |= E1000_CTRL_SWDPIO0;
  1420. ew32(CTRL, ctrl);
  1421. break;
  1422. case e1000_media_type_copper:
  1423. ew32(LEDCTL, hw->mac.ledctl_mode1);
  1424. break;
  1425. default:
  1426. break;
  1427. }
  1428. return 0;
  1429. }
  1430. /**
  1431. * e1000e_set_pcie_no_snoop - Set PCI-express capabilities
  1432. * @hw: pointer to the HW structure
  1433. * @no_snoop: bitmap of snoop events
  1434. *
  1435. * Set the PCI-express register to snoop for events enabled in 'no_snoop'.
  1436. **/
  1437. void e1000e_set_pcie_no_snoop(struct e1000_hw *hw, u32 no_snoop)
  1438. {
  1439. u32 gcr;
  1440. if (no_snoop) {
  1441. gcr = er32(GCR);
  1442. gcr &= ~(PCIE_NO_SNOOP_ALL);
  1443. gcr |= no_snoop;
  1444. ew32(GCR, gcr);
  1445. }
  1446. }
  1447. /**
  1448. * e1000e_disable_pcie_master - Disables PCI-express master access
  1449. * @hw: pointer to the HW structure
  1450. *
  1451. * Returns 0 if successful, else returns -10
  1452. * (-E1000_ERR_MASTER_REQUESTS_PENDING) if master disable bit has not caused
  1453. * the master requests to be disabled.
  1454. *
  1455. * Disables PCI-Express master access and verifies there are no pending
  1456. * requests.
  1457. **/
  1458. s32 e1000e_disable_pcie_master(struct e1000_hw *hw)
  1459. {
  1460. u32 ctrl;
  1461. s32 timeout = MASTER_DISABLE_TIMEOUT;
  1462. ctrl = er32(CTRL);
  1463. ctrl |= E1000_CTRL_GIO_MASTER_DISABLE;
  1464. ew32(CTRL, ctrl);
  1465. while (timeout) {
  1466. if (!(er32(STATUS) &
  1467. E1000_STATUS_GIO_MASTER_ENABLE))
  1468. break;
  1469. udelay(100);
  1470. timeout--;
  1471. }
  1472. if (!timeout) {
  1473. e_dbg("Master requests are pending.\n");
  1474. return -E1000_ERR_MASTER_REQUESTS_PENDING;
  1475. }
  1476. return 0;
  1477. }
  1478. /**
  1479. * e1000e_reset_adaptive - Reset Adaptive Interframe Spacing
  1480. * @hw: pointer to the HW structure
  1481. *
  1482. * Reset the Adaptive Interframe Spacing throttle to default values.
  1483. **/
  1484. void e1000e_reset_adaptive(struct e1000_hw *hw)
  1485. {
  1486. struct e1000_mac_info *mac = &hw->mac;
  1487. if (!mac->adaptive_ifs) {
  1488. e_dbg("Not in Adaptive IFS mode!\n");
  1489. goto out;
  1490. }
  1491. mac->current_ifs_val = 0;
  1492. mac->ifs_min_val = IFS_MIN;
  1493. mac->ifs_max_val = IFS_MAX;
  1494. mac->ifs_step_size = IFS_STEP;
  1495. mac->ifs_ratio = IFS_RATIO;
  1496. mac->in_ifs_mode = false;
  1497. ew32(AIT, 0);
  1498. out:
  1499. return;
  1500. }
  1501. /**
  1502. * e1000e_update_adaptive - Update Adaptive Interframe Spacing
  1503. * @hw: pointer to the HW structure
  1504. *
  1505. * Update the Adaptive Interframe Spacing Throttle value based on the
  1506. * time between transmitted packets and time between collisions.
  1507. **/
  1508. void e1000e_update_adaptive(struct e1000_hw *hw)
  1509. {
  1510. struct e1000_mac_info *mac = &hw->mac;
  1511. if (!mac->adaptive_ifs) {
  1512. e_dbg("Not in Adaptive IFS mode!\n");
  1513. goto out;
  1514. }
  1515. if ((mac->collision_delta * mac->ifs_ratio) > mac->tx_packet_delta) {
  1516. if (mac->tx_packet_delta > MIN_NUM_XMITS) {
  1517. mac->in_ifs_mode = true;
  1518. if (mac->current_ifs_val < mac->ifs_max_val) {
  1519. if (!mac->current_ifs_val)
  1520. mac->current_ifs_val = mac->ifs_min_val;
  1521. else
  1522. mac->current_ifs_val +=
  1523. mac->ifs_step_size;
  1524. ew32(AIT, mac->current_ifs_val);
  1525. }
  1526. }
  1527. } else {
  1528. if (mac->in_ifs_mode &&
  1529. (mac->tx_packet_delta <= MIN_NUM_XMITS)) {
  1530. mac->current_ifs_val = 0;
  1531. mac->in_ifs_mode = false;
  1532. ew32(AIT, 0);
  1533. }
  1534. }
  1535. out:
  1536. return;
  1537. }
  1538. /**
  1539. * e1000_raise_eec_clk - Raise EEPROM clock
  1540. * @hw: pointer to the HW structure
  1541. * @eecd: pointer to the EEPROM
  1542. *
  1543. * Enable/Raise the EEPROM clock bit.
  1544. **/
  1545. static void e1000_raise_eec_clk(struct e1000_hw *hw, u32 *eecd)
  1546. {
  1547. *eecd = *eecd | E1000_EECD_SK;
  1548. ew32(EECD, *eecd);
  1549. e1e_flush();
  1550. udelay(hw->nvm.delay_usec);
  1551. }
  1552. /**
  1553. * e1000_lower_eec_clk - Lower EEPROM clock
  1554. * @hw: pointer to the HW structure
  1555. * @eecd: pointer to the EEPROM
  1556. *
  1557. * Clear/Lower the EEPROM clock bit.
  1558. **/
  1559. static void e1000_lower_eec_clk(struct e1000_hw *hw, u32 *eecd)
  1560. {
  1561. *eecd = *eecd & ~E1000_EECD_SK;
  1562. ew32(EECD, *eecd);
  1563. e1e_flush();
  1564. udelay(hw->nvm.delay_usec);
  1565. }
  1566. /**
  1567. * e1000_shift_out_eec_bits - Shift data bits our to the EEPROM
  1568. * @hw: pointer to the HW structure
  1569. * @data: data to send to the EEPROM
  1570. * @count: number of bits to shift out
  1571. *
  1572. * We need to shift 'count' bits out to the EEPROM. So, the value in the
  1573. * "data" parameter will be shifted out to the EEPROM one bit at a time.
  1574. * In order to do this, "data" must be broken down into bits.
  1575. **/
  1576. static void e1000_shift_out_eec_bits(struct e1000_hw *hw, u16 data, u16 count)
  1577. {
  1578. struct e1000_nvm_info *nvm = &hw->nvm;
  1579. u32 eecd = er32(EECD);
  1580. u32 mask;
  1581. mask = 0x01 << (count - 1);
  1582. if (nvm->type == e1000_nvm_eeprom_spi)
  1583. eecd |= E1000_EECD_DO;
  1584. do {
  1585. eecd &= ~E1000_EECD_DI;
  1586. if (data & mask)
  1587. eecd |= E1000_EECD_DI;
  1588. ew32(EECD, eecd);
  1589. e1e_flush();
  1590. udelay(nvm->delay_usec);
  1591. e1000_raise_eec_clk(hw, &eecd);
  1592. e1000_lower_eec_clk(hw, &eecd);
  1593. mask >>= 1;
  1594. } while (mask);
  1595. eecd &= ~E1000_EECD_DI;
  1596. ew32(EECD, eecd);
  1597. }
  1598. /**
  1599. * e1000_shift_in_eec_bits - Shift data bits in from the EEPROM
  1600. * @hw: pointer to the HW structure
  1601. * @count: number of bits to shift in
  1602. *
  1603. * In order to read a register from the EEPROM, we need to shift 'count' bits
  1604. * in from the EEPROM. Bits are "shifted in" by raising the clock input to
  1605. * the EEPROM (setting the SK bit), and then reading the value of the data out
  1606. * "DO" bit. During this "shifting in" process the data in "DI" bit should
  1607. * always be clear.
  1608. **/
  1609. static u16 e1000_shift_in_eec_bits(struct e1000_hw *hw, u16 count)
  1610. {
  1611. u32 eecd;
  1612. u32 i;
  1613. u16 data;
  1614. eecd = er32(EECD);
  1615. eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
  1616. data = 0;
  1617. for (i = 0; i < count; i++) {
  1618. data <<= 1;
  1619. e1000_raise_eec_clk(hw, &eecd);
  1620. eecd = er32(EECD);
  1621. eecd &= ~E1000_EECD_DI;
  1622. if (eecd & E1000_EECD_DO)
  1623. data |= 1;
  1624. e1000_lower_eec_clk(hw, &eecd);
  1625. }
  1626. return data;
  1627. }
  1628. /**
  1629. * e1000e_poll_eerd_eewr_done - Poll for EEPROM read/write completion
  1630. * @hw: pointer to the HW structure
  1631. * @ee_reg: EEPROM flag for polling
  1632. *
  1633. * Polls the EEPROM status bit for either read or write completion based
  1634. * upon the value of 'ee_reg'.
  1635. **/
  1636. s32 e1000e_poll_eerd_eewr_done(struct e1000_hw *hw, int ee_reg)
  1637. {
  1638. u32 attempts = 100000;
  1639. u32 i, reg = 0;
  1640. for (i = 0; i < attempts; i++) {
  1641. if (ee_reg == E1000_NVM_POLL_READ)
  1642. reg = er32(EERD);
  1643. else
  1644. reg = er32(EEWR);
  1645. if (reg & E1000_NVM_RW_REG_DONE)
  1646. return 0;
  1647. udelay(5);
  1648. }
  1649. return -E1000_ERR_NVM;
  1650. }
  1651. /**
  1652. * e1000e_acquire_nvm - Generic request for access to EEPROM
  1653. * @hw: pointer to the HW structure
  1654. *
  1655. * Set the EEPROM access request bit and wait for EEPROM access grant bit.
  1656. * Return successful if access grant bit set, else clear the request for
  1657. * EEPROM access and return -E1000_ERR_NVM (-1).
  1658. **/
  1659. s32 e1000e_acquire_nvm(struct e1000_hw *hw)
  1660. {
  1661. u32 eecd = er32(EECD);
  1662. s32 timeout = E1000_NVM_GRANT_ATTEMPTS;
  1663. ew32(EECD, eecd | E1000_EECD_REQ);
  1664. eecd = er32(EECD);
  1665. while (timeout) {
  1666. if (eecd & E1000_EECD_GNT)
  1667. break;
  1668. udelay(5);
  1669. eecd = er32(EECD);
  1670. timeout--;
  1671. }
  1672. if (!timeout) {
  1673. eecd &= ~E1000_EECD_REQ;
  1674. ew32(EECD, eecd);
  1675. e_dbg("Could not acquire NVM grant\n");
  1676. return -E1000_ERR_NVM;
  1677. }
  1678. return 0;
  1679. }
  1680. /**
  1681. * e1000_standby_nvm - Return EEPROM to standby state
  1682. * @hw: pointer to the HW structure
  1683. *
  1684. * Return the EEPROM to a standby state.
  1685. **/
  1686. static void e1000_standby_nvm(struct e1000_hw *hw)
  1687. {
  1688. struct e1000_nvm_info *nvm = &hw->nvm;
  1689. u32 eecd = er32(EECD);
  1690. if (nvm->type == e1000_nvm_eeprom_spi) {
  1691. /* Toggle CS to flush commands */
  1692. eecd |= E1000_EECD_CS;
  1693. ew32(EECD, eecd);
  1694. e1e_flush();
  1695. udelay(nvm->delay_usec);
  1696. eecd &= ~E1000_EECD_CS;
  1697. ew32(EECD, eecd);
  1698. e1e_flush();
  1699. udelay(nvm->delay_usec);
  1700. }
  1701. }
  1702. /**
  1703. * e1000_stop_nvm - Terminate EEPROM command
  1704. * @hw: pointer to the HW structure
  1705. *
  1706. * Terminates the current command by inverting the EEPROM's chip select pin.
  1707. **/
  1708. static void e1000_stop_nvm(struct e1000_hw *hw)
  1709. {
  1710. u32 eecd;
  1711. eecd = er32(EECD);
  1712. if (hw->nvm.type == e1000_nvm_eeprom_spi) {
  1713. /* Pull CS high */
  1714. eecd |= E1000_EECD_CS;
  1715. e1000_lower_eec_clk(hw, &eecd);
  1716. }
  1717. }
  1718. /**
  1719. * e1000e_release_nvm - Release exclusive access to EEPROM
  1720. * @hw: pointer to the HW structure
  1721. *
  1722. * Stop any current commands to the EEPROM and clear the EEPROM request bit.
  1723. **/
  1724. void e1000e_release_nvm(struct e1000_hw *hw)
  1725. {
  1726. u32 eecd;
  1727. e1000_stop_nvm(hw);
  1728. eecd = er32(EECD);
  1729. eecd &= ~E1000_EECD_REQ;
  1730. ew32(EECD, eecd);
  1731. }
  1732. /**
  1733. * e1000_ready_nvm_eeprom - Prepares EEPROM for read/write
  1734. * @hw: pointer to the HW structure
  1735. *
  1736. * Setups the EEPROM for reading and writing.
  1737. **/
  1738. static s32 e1000_ready_nvm_eeprom(struct e1000_hw *hw)
  1739. {
  1740. struct e1000_nvm_info *nvm = &hw->nvm;
  1741. u32 eecd = er32(EECD);
  1742. u16 timeout = 0;
  1743. u8 spi_stat_reg;
  1744. if (nvm->type == e1000_nvm_eeprom_spi) {
  1745. /* Clear SK and CS */
  1746. eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
  1747. ew32(EECD, eecd);
  1748. udelay(1);
  1749. timeout = NVM_MAX_RETRY_SPI;
  1750. /*
  1751. * Read "Status Register" repeatedly until the LSB is cleared.
  1752. * The EEPROM will signal that the command has been completed
  1753. * by clearing bit 0 of the internal status register. If it's
  1754. * not cleared within 'timeout', then error out.
  1755. */
  1756. while (timeout) {
  1757. e1000_shift_out_eec_bits(hw, NVM_RDSR_OPCODE_SPI,
  1758. hw->nvm.opcode_bits);
  1759. spi_stat_reg = (u8)e1000_shift_in_eec_bits(hw, 8);
  1760. if (!(spi_stat_reg & NVM_STATUS_RDY_SPI))
  1761. break;
  1762. udelay(5);
  1763. e1000_standby_nvm(hw);
  1764. timeout--;
  1765. }
  1766. if (!timeout) {
  1767. e_dbg("SPI NVM Status error\n");
  1768. return -E1000_ERR_NVM;
  1769. }
  1770. }
  1771. return 0;
  1772. }
  1773. /**
  1774. * e1000e_read_nvm_eerd - Reads EEPROM using EERD register
  1775. * @hw: pointer to the HW structure
  1776. * @offset: offset of word in the EEPROM to read
  1777. * @words: number of words to read
  1778. * @data: word read from the EEPROM
  1779. *
  1780. * Reads a 16 bit word from the EEPROM using the EERD register.
  1781. **/
  1782. s32 e1000e_read_nvm_eerd(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
  1783. {
  1784. struct e1000_nvm_info *nvm = &hw->nvm;
  1785. u32 i, eerd = 0;
  1786. s32 ret_val = 0;
  1787. /*
  1788. * A check for invalid values: offset too large, too many words,
  1789. * too many words for the offset, and not enough words.
  1790. */
  1791. if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
  1792. (words == 0)) {
  1793. e_dbg("nvm parameter(s) out of bounds\n");
  1794. return -E1000_ERR_NVM;
  1795. }
  1796. for (i = 0; i < words; i++) {
  1797. eerd = ((offset+i) << E1000_NVM_RW_ADDR_SHIFT) +
  1798. E1000_NVM_RW_REG_START;
  1799. ew32(EERD, eerd);
  1800. ret_val = e1000e_poll_eerd_eewr_done(hw, E1000_NVM_POLL_READ);
  1801. if (ret_val)
  1802. break;
  1803. data[i] = (er32(EERD) >> E1000_NVM_RW_REG_DATA);
  1804. }
  1805. return ret_val;
  1806. }
  1807. /**
  1808. * e1000e_write_nvm_spi - Write to EEPROM using SPI
  1809. * @hw: pointer to the HW structure
  1810. * @offset: offset within the EEPROM to be written to
  1811. * @words: number of words to write
  1812. * @data: 16 bit word(s) to be written to the EEPROM
  1813. *
  1814. * Writes data to EEPROM at offset using SPI interface.
  1815. *
  1816. * If e1000e_update_nvm_checksum is not called after this function , the
  1817. * EEPROM will most likely contain an invalid checksum.
  1818. **/
  1819. s32 e1000e_write_nvm_spi(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
  1820. {
  1821. struct e1000_nvm_info *nvm = &hw->nvm;
  1822. s32 ret_val;
  1823. u16 widx = 0;
  1824. /*
  1825. * A check for invalid values: offset too large, too many words,
  1826. * and not enough words.
  1827. */
  1828. if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
  1829. (words == 0)) {
  1830. e_dbg("nvm parameter(s) out of bounds\n");
  1831. return -E1000_ERR_NVM;
  1832. }
  1833. ret_val = nvm->ops.acquire(hw);
  1834. if (ret_val)
  1835. return ret_val;
  1836. msleep(10);
  1837. while (widx < words) {
  1838. u8 write_opcode = NVM_WRITE_OPCODE_SPI;
  1839. ret_val = e1000_ready_nvm_eeprom(hw);
  1840. if (ret_val) {
  1841. nvm->ops.release(hw);
  1842. return ret_val;
  1843. }
  1844. e1000_standby_nvm(hw);
  1845. /* Send the WRITE ENABLE command (8 bit opcode) */
  1846. e1000_shift_out_eec_bits(hw, NVM_WREN_OPCODE_SPI,
  1847. nvm->opcode_bits);
  1848. e1000_standby_nvm(hw);
  1849. /*
  1850. * Some SPI eeproms use the 8th address bit embedded in the
  1851. * opcode
  1852. */
  1853. if ((nvm->address_bits == 8) && (offset >= 128))
  1854. write_opcode |= NVM_A8_OPCODE_SPI;
  1855. /* Send the Write command (8-bit opcode + addr) */
  1856. e1000_shift_out_eec_bits(hw, write_opcode, nvm->opcode_bits);
  1857. e1000_shift_out_eec_bits(hw, (u16)((offset + widx) * 2),
  1858. nvm->address_bits);
  1859. /* Loop to allow for up to whole page write of eeprom */
  1860. while (widx < words) {
  1861. u16 word_out = data[widx];
  1862. word_out = (word_out >> 8) | (word_out << 8);
  1863. e1000_shift_out_eec_bits(hw, word_out, 16);
  1864. widx++;
  1865. if ((((offset + widx) * 2) % nvm->page_size) == 0) {
  1866. e1000_standby_nvm(hw);
  1867. break;
  1868. }
  1869. }
  1870. }
  1871. msleep(10);
  1872. nvm->ops.release(hw);
  1873. return 0;
  1874. }
  1875. /**
  1876. * e1000_read_mac_addr_generic - Read device MAC address
  1877. * @hw: pointer to the HW structure
  1878. *
  1879. * Reads the device MAC address from the EEPROM and stores the value.
  1880. * Since devices with two ports use the same EEPROM, we increment the
  1881. * last bit in the MAC address for the second port.
  1882. **/
  1883. s32 e1000_read_mac_addr_generic(struct e1000_hw *hw)
  1884. {
  1885. u32 rar_high;
  1886. u32 rar_low;
  1887. u16 i;
  1888. rar_high = er32(RAH(0));
  1889. rar_low = er32(RAL(0));
  1890. for (i = 0; i < E1000_RAL_MAC_ADDR_LEN; i++)
  1891. hw->mac.perm_addr[i] = (u8)(rar_low >> (i*8));
  1892. for (i = 0; i < E1000_RAH_MAC_ADDR_LEN; i++)
  1893. hw->mac.perm_addr[i+4] = (u8)(rar_high >> (i*8));
  1894. for (i = 0; i < ETH_ALEN; i++)
  1895. hw->mac.addr[i] = hw->mac.perm_addr[i];
  1896. return 0;
  1897. }
  1898. /**
  1899. * e1000e_validate_nvm_checksum_generic - Validate EEPROM checksum
  1900. * @hw: pointer to the HW structure
  1901. *
  1902. * Calculates the EEPROM checksum by reading/adding each word of the EEPROM
  1903. * and then verifies that the sum of the EEPROM is equal to 0xBABA.
  1904. **/
  1905. s32 e1000e_validate_nvm_checksum_generic(struct e1000_hw *hw)
  1906. {
  1907. s32 ret_val;
  1908. u16 checksum = 0;
  1909. u16 i, nvm_data;
  1910. for (i = 0; i < (NVM_CHECKSUM_REG + 1); i++) {
  1911. ret_val = e1000_read_nvm(hw, i, 1, &nvm_data);
  1912. if (ret_val) {
  1913. e_dbg("NVM Read Error\n");
  1914. return ret_val;
  1915. }
  1916. checksum += nvm_data;
  1917. }
  1918. if (checksum != (u16) NVM_SUM) {
  1919. e_dbg("NVM Checksum Invalid\n");
  1920. return -E1000_ERR_NVM;
  1921. }
  1922. return 0;
  1923. }
  1924. /**
  1925. * e1000e_update_nvm_checksum_generic - Update EEPROM checksum
  1926. * @hw: pointer to the HW structure
  1927. *
  1928. * Updates the EEPROM checksum by reading/adding each word of the EEPROM
  1929. * up to the checksum. Then calculates the EEPROM checksum and writes the
  1930. * value to the EEPROM.
  1931. **/
  1932. s32 e1000e_update_nvm_checksum_generic(struct e1000_hw *hw)
  1933. {
  1934. s32 ret_val;
  1935. u16 checksum = 0;
  1936. u16 i, nvm_data;
  1937. for (i = 0; i < NVM_CHECKSUM_REG; i++) {
  1938. ret_val = e1000_read_nvm(hw, i, 1, &nvm_data);
  1939. if (ret_val) {
  1940. e_dbg("NVM Read Error while updating checksum.\n");
  1941. return ret_val;
  1942. }
  1943. checksum += nvm_data;
  1944. }
  1945. checksum = (u16) NVM_SUM - checksum;
  1946. ret_val = e1000_write_nvm(hw, NVM_CHECKSUM_REG, 1, &checksum);
  1947. if (ret_val)
  1948. e_dbg("NVM Write Error while updating checksum.\n");
  1949. return ret_val;
  1950. }
  1951. /**
  1952. * e1000e_reload_nvm - Reloads EEPROM
  1953. * @hw: pointer to the HW structure
  1954. *
  1955. * Reloads the EEPROM by setting the "Reinitialize from EEPROM" bit in the
  1956. * extended control register.
  1957. **/
  1958. void e1000e_reload_nvm(struct e1000_hw *hw)
  1959. {
  1960. u32 ctrl_ext;
  1961. udelay(10);
  1962. ctrl_ext = er32(CTRL_EXT);
  1963. ctrl_ext |= E1000_CTRL_EXT_EE_RST;
  1964. ew32(CTRL_EXT, ctrl_ext);
  1965. e1e_flush();
  1966. }
  1967. /**
  1968. * e1000_calculate_checksum - Calculate checksum for buffer
  1969. * @buffer: pointer to EEPROM
  1970. * @length: size of EEPROM to calculate a checksum for
  1971. *
  1972. * Calculates the checksum for some buffer on a specified length. The
  1973. * checksum calculated is returned.
  1974. **/
  1975. static u8 e1000_calculate_checksum(u8 *buffer, u32 length)
  1976. {
  1977. u32 i;
  1978. u8 sum = 0;
  1979. if (!buffer)
  1980. return 0;
  1981. for (i = 0; i < length; i++)
  1982. sum += buffer[i];
  1983. return (u8) (0 - sum);
  1984. }
  1985. /**
  1986. * e1000_mng_enable_host_if - Checks host interface is enabled
  1987. * @hw: pointer to the HW structure
  1988. *
  1989. * Returns E1000_success upon success, else E1000_ERR_HOST_INTERFACE_COMMAND
  1990. *
  1991. * This function checks whether the HOST IF is enabled for command operation
  1992. * and also checks whether the previous command is completed. It busy waits
  1993. * in case of previous command is not completed.
  1994. **/
  1995. static s32 e1000_mng_enable_host_if(struct e1000_hw *hw)
  1996. {
  1997. u32 hicr;
  1998. u8 i;
  1999. /* Check that the host interface is enabled. */
  2000. hicr = er32(HICR);
  2001. if ((hicr & E1000_HICR_EN) == 0) {
  2002. e_dbg("E1000_HOST_EN bit disabled.\n");
  2003. return -E1000_ERR_HOST_INTERFACE_COMMAND;
  2004. }
  2005. /* check the previous command is completed */
  2006. for (i = 0; i < E1000_MNG_DHCP_COMMAND_TIMEOUT; i++) {
  2007. hicr = er32(HICR);
  2008. if (!(hicr & E1000_HICR_C))
  2009. break;
  2010. mdelay(1);
  2011. }
  2012. if (i == E1000_MNG_DHCP_COMMAND_TIMEOUT) {
  2013. e_dbg("Previous command timeout failed .\n");
  2014. return -E1000_ERR_HOST_INTERFACE_COMMAND;
  2015. }
  2016. return 0;
  2017. }
  2018. /**
  2019. * e1000e_check_mng_mode_generic - check management mode
  2020. * @hw: pointer to the HW structure
  2021. *
  2022. * Reads the firmware semaphore register and returns true (>0) if
  2023. * manageability is enabled, else false (0).
  2024. **/
  2025. bool e1000e_check_mng_mode_generic(struct e1000_hw *hw)
  2026. {
  2027. u32 fwsm = er32(FWSM);
  2028. return (fwsm & E1000_FWSM_MODE_MASK) ==
  2029. (E1000_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT);
  2030. }
  2031. /**
  2032. * e1000e_enable_tx_pkt_filtering - Enable packet filtering on Tx
  2033. * @hw: pointer to the HW structure
  2034. *
  2035. * Enables packet filtering on transmit packets if manageability is enabled
  2036. * and host interface is enabled.
  2037. **/
  2038. bool e1000e_enable_tx_pkt_filtering(struct e1000_hw *hw)
  2039. {
  2040. struct e1000_host_mng_dhcp_cookie *hdr = &hw->mng_cookie;
  2041. u32 *buffer = (u32 *)&hw->mng_cookie;
  2042. u32 offset;
  2043. s32 ret_val, hdr_csum, csum;
  2044. u8 i, len;
  2045. hw->mac.tx_pkt_filtering = true;
  2046. /* No manageability, no filtering */
  2047. if (!e1000e_check_mng_mode(hw)) {
  2048. hw->mac.tx_pkt_filtering = false;
  2049. goto out;
  2050. }
  2051. /*
  2052. * If we can't read from the host interface for whatever
  2053. * reason, disable filtering.
  2054. */
  2055. ret_val = e1000_mng_enable_host_if(hw);
  2056. if (ret_val) {
  2057. hw->mac.tx_pkt_filtering = false;
  2058. goto out;
  2059. }
  2060. /* Read in the header. Length and offset are in dwords. */
  2061. len = E1000_MNG_DHCP_COOKIE_LENGTH >> 2;
  2062. offset = E1000_MNG_DHCP_COOKIE_OFFSET >> 2;
  2063. for (i = 0; i < len; i++)
  2064. *(buffer + i) = E1000_READ_REG_ARRAY(hw, E1000_HOST_IF, offset + i);
  2065. hdr_csum = hdr->checksum;
  2066. hdr->checksum = 0;
  2067. csum = e1000_calculate_checksum((u8 *)hdr,
  2068. E1000_MNG_DHCP_COOKIE_LENGTH);
  2069. /*
  2070. * If either the checksums or signature don't match, then
  2071. * the cookie area isn't considered valid, in which case we
  2072. * take the safe route of assuming Tx filtering is enabled.
  2073. */
  2074. if ((hdr_csum != csum) || (hdr->signature != E1000_IAMT_SIGNATURE)) {
  2075. hw->mac.tx_pkt_filtering = true;
  2076. goto out;
  2077. }
  2078. /* Cookie area is valid, make the final check for filtering. */
  2079. if (!(hdr->status & E1000_MNG_DHCP_COOKIE_STATUS_PARSING)) {
  2080. hw->mac.tx_pkt_filtering = false;
  2081. goto out;
  2082. }
  2083. out:
  2084. return hw->mac.tx_pkt_filtering;
  2085. }
  2086. /**
  2087. * e1000_mng_write_cmd_header - Writes manageability command header
  2088. * @hw: pointer to the HW structure
  2089. * @hdr: pointer to the host interface command header
  2090. *
  2091. * Writes the command header after does the checksum calculation.
  2092. **/
  2093. static s32 e1000_mng_write_cmd_header(struct e1000_hw *hw,
  2094. struct e1000_host_mng_command_header *hdr)
  2095. {
  2096. u16 i, length = sizeof(struct e1000_host_mng_command_header);
  2097. /* Write the whole command header structure with new checksum. */
  2098. hdr->checksum = e1000_calculate_checksum((u8 *)hdr, length);
  2099. length >>= 2;
  2100. /* Write the relevant command block into the ram area. */
  2101. for (i = 0; i < length; i++) {
  2102. E1000_WRITE_REG_ARRAY(hw, E1000_HOST_IF, i,
  2103. *((u32 *) hdr + i));
  2104. e1e_flush();
  2105. }
  2106. return 0;
  2107. }
  2108. /**
  2109. * e1000_mng_host_if_write - Write to the manageability host interface
  2110. * @hw: pointer to the HW structure
  2111. * @buffer: pointer to the host interface buffer
  2112. * @length: size of the buffer
  2113. * @offset: location in the buffer to write to
  2114. * @sum: sum of the data (not checksum)
  2115. *
  2116. * This function writes the buffer content at the offset given on the host if.
  2117. * It also does alignment considerations to do the writes in most efficient
  2118. * way. Also fills up the sum of the buffer in *buffer parameter.
  2119. **/
  2120. static s32 e1000_mng_host_if_write(struct e1000_hw *hw, u8 *buffer,
  2121. u16 length, u16 offset, u8 *sum)
  2122. {
  2123. u8 *tmp;
  2124. u8 *bufptr = buffer;
  2125. u32 data = 0;
  2126. u16 remaining, i, j, prev_bytes;
  2127. /* sum = only sum of the data and it is not checksum */
  2128. if (length == 0 || offset + length > E1000_HI_MAX_MNG_DATA_LENGTH)
  2129. return -E1000_ERR_PARAM;
  2130. tmp = (u8 *)&data;
  2131. prev_bytes = offset & 0x3;
  2132. offset >>= 2;
  2133. if (prev_bytes) {
  2134. data = E1000_READ_REG_ARRAY(hw, E1000_HOST_IF, offset);
  2135. for (j = prev_bytes; j < sizeof(u32); j++) {
  2136. *(tmp + j) = *bufptr++;
  2137. *sum += *(tmp + j);
  2138. }
  2139. E1000_WRITE_REG_ARRAY(hw, E1000_HOST_IF, offset, data);
  2140. length -= j - prev_bytes;
  2141. offset++;
  2142. }
  2143. remaining = length & 0x3;
  2144. length -= remaining;
  2145. /* Calculate length in DWORDs */
  2146. length >>= 2;
  2147. /*
  2148. * The device driver writes the relevant command block into the
  2149. * ram area.
  2150. */
  2151. for (i = 0; i < length; i++) {
  2152. for (j = 0; j < sizeof(u32); j++) {
  2153. *(tmp + j) = *bufptr++;
  2154. *sum += *(tmp + j);
  2155. }
  2156. E1000_WRITE_REG_ARRAY(hw, E1000_HOST_IF, offset + i, data);
  2157. }
  2158. if (remaining) {
  2159. for (j = 0; j < sizeof(u32); j++) {
  2160. if (j < remaining)
  2161. *(tmp + j) = *bufptr++;
  2162. else
  2163. *(tmp + j) = 0;
  2164. *sum += *(tmp + j);
  2165. }
  2166. E1000_WRITE_REG_ARRAY(hw, E1000_HOST_IF, offset + i, data);
  2167. }
  2168. return 0;
  2169. }
  2170. /**
  2171. * e1000e_mng_write_dhcp_info - Writes DHCP info to host interface
  2172. * @hw: pointer to the HW structure
  2173. * @buffer: pointer to the host interface
  2174. * @length: size of the buffer
  2175. *
  2176. * Writes the DHCP information to the host interface.
  2177. **/
  2178. s32 e1000e_mng_write_dhcp_info(struct e1000_hw *hw, u8 *buffer, u16 length)
  2179. {
  2180. struct e1000_host_mng_command_header hdr;
  2181. s32 ret_val;
  2182. u32 hicr;
  2183. hdr.command_id = E1000_MNG_DHCP_TX_PAYLOAD_CMD;
  2184. hdr.command_length = length;
  2185. hdr.reserved1 = 0;
  2186. hdr.reserved2 = 0;
  2187. hdr.checksum = 0;
  2188. /* Enable the host interface */
  2189. ret_val = e1000_mng_enable_host_if(hw);
  2190. if (ret_val)
  2191. return ret_val;
  2192. /* Populate the host interface with the contents of "buffer". */
  2193. ret_val = e1000_mng_host_if_write(hw, buffer, length,
  2194. sizeof(hdr), &(hdr.checksum));
  2195. if (ret_val)
  2196. return ret_val;
  2197. /* Write the manageability command header */
  2198. ret_val = e1000_mng_write_cmd_header(hw, &hdr);
  2199. if (ret_val)
  2200. return ret_val;
  2201. /* Tell the ARC a new command is pending. */
  2202. hicr = er32(HICR);
  2203. ew32(HICR, hicr | E1000_HICR_C);
  2204. return 0;
  2205. }
  2206. /**
  2207. * e1000e_enable_mng_pass_thru - Enable processing of ARP's
  2208. * @hw: pointer to the HW structure
  2209. *
  2210. * Verifies the hardware needs to allow ARPs to be processed by the host.
  2211. **/
  2212. bool e1000e_enable_mng_pass_thru(struct e1000_hw *hw)
  2213. {
  2214. u32 manc;
  2215. u32 fwsm, factps;
  2216. bool ret_val = false;
  2217. manc = er32(MANC);
  2218. if (!(manc & E1000_MANC_RCV_TCO_EN) ||
  2219. !(manc & E1000_MANC_EN_MAC_ADDR_FILTER))
  2220. return ret_val;
  2221. if (hw->mac.arc_subsystem_valid) {
  2222. fwsm = er32(FWSM);
  2223. factps = er32(FACTPS);
  2224. if (!(factps & E1000_FACTPS_MNGCG) &&
  2225. ((fwsm & E1000_FWSM_MODE_MASK) ==
  2226. (e1000_mng_mode_pt << E1000_FWSM_MODE_SHIFT))) {
  2227. ret_val = true;
  2228. return ret_val;
  2229. }
  2230. } else {
  2231. if ((manc & E1000_MANC_SMBUS_EN) &&
  2232. !(manc & E1000_MANC_ASF_EN)) {
  2233. ret_val = true;
  2234. return ret_val;
  2235. }
  2236. }
  2237. return ret_val;
  2238. }
  2239. s32 e1000e_read_pba_num(struct e1000_hw *hw, u32 *pba_num)
  2240. {
  2241. s32 ret_val;
  2242. u16 nvm_data;
  2243. ret_val = e1000_read_nvm(hw, NVM_PBA_OFFSET_0, 1, &nvm_data);
  2244. if (ret_val) {
  2245. e_dbg("NVM Read Error\n");
  2246. return ret_val;
  2247. }
  2248. *pba_num = (u32)(nvm_data << 16);
  2249. ret_val = e1000_read_nvm(hw, NVM_PBA_OFFSET_1, 1, &nvm_data);
  2250. if (ret_val) {
  2251. e_dbg("NVM Read Error\n");
  2252. return ret_val;
  2253. }
  2254. *pba_num |= nvm_data;
  2255. return 0;
  2256. }