lib.c 67 KB

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