lib.c 66 KB

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