lib.c 66 KB

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