e1000_82575.c 77 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910
  1. /* Intel(R) Gigabit Ethernet Linux driver
  2. * Copyright(c) 2007-2015 Intel Corporation.
  3. *
  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. *
  8. * This program is distributed in the hope it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. * more details.
  12. *
  13. * You should have received a copy of the GNU General Public License along with
  14. * this program; if not, see <http://www.gnu.org/licenses/>.
  15. *
  16. * The full GNU General Public License is included in this distribution in
  17. * the file called "COPYING".
  18. *
  19. * Contact Information:
  20. * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  21. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  22. */
  23. /* e1000_82575
  24. * e1000_82576
  25. */
  26. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  27. #include <linux/types.h>
  28. #include <linux/if_ether.h>
  29. #include <linux/i2c.h>
  30. #include "e1000_mac.h"
  31. #include "e1000_82575.h"
  32. #include "e1000_i210.h"
  33. static s32 igb_get_invariants_82575(struct e1000_hw *);
  34. static s32 igb_acquire_phy_82575(struct e1000_hw *);
  35. static void igb_release_phy_82575(struct e1000_hw *);
  36. static s32 igb_acquire_nvm_82575(struct e1000_hw *);
  37. static void igb_release_nvm_82575(struct e1000_hw *);
  38. static s32 igb_check_for_link_82575(struct e1000_hw *);
  39. static s32 igb_get_cfg_done_82575(struct e1000_hw *);
  40. static s32 igb_init_hw_82575(struct e1000_hw *);
  41. static s32 igb_phy_hw_reset_sgmii_82575(struct e1000_hw *);
  42. static s32 igb_read_phy_reg_sgmii_82575(struct e1000_hw *, u32, u16 *);
  43. static s32 igb_read_phy_reg_82580(struct e1000_hw *, u32, u16 *);
  44. static s32 igb_write_phy_reg_82580(struct e1000_hw *, u32, u16);
  45. static s32 igb_reset_hw_82575(struct e1000_hw *);
  46. static s32 igb_reset_hw_82580(struct e1000_hw *);
  47. static s32 igb_set_d0_lplu_state_82575(struct e1000_hw *, bool);
  48. static s32 igb_set_d0_lplu_state_82580(struct e1000_hw *, bool);
  49. static s32 igb_set_d3_lplu_state_82580(struct e1000_hw *, bool);
  50. static s32 igb_setup_copper_link_82575(struct e1000_hw *);
  51. static s32 igb_setup_serdes_link_82575(struct e1000_hw *);
  52. static s32 igb_write_phy_reg_sgmii_82575(struct e1000_hw *, u32, u16);
  53. static void igb_clear_hw_cntrs_82575(struct e1000_hw *);
  54. static s32 igb_acquire_swfw_sync_82575(struct e1000_hw *, u16);
  55. static s32 igb_get_pcs_speed_and_duplex_82575(struct e1000_hw *, u16 *,
  56. u16 *);
  57. static s32 igb_get_phy_id_82575(struct e1000_hw *);
  58. static void igb_release_swfw_sync_82575(struct e1000_hw *, u16);
  59. static bool igb_sgmii_active_82575(struct e1000_hw *);
  60. static s32 igb_reset_init_script_82575(struct e1000_hw *);
  61. static s32 igb_read_mac_addr_82575(struct e1000_hw *);
  62. static s32 igb_set_pcie_completion_timeout(struct e1000_hw *hw);
  63. static s32 igb_reset_mdicnfg_82580(struct e1000_hw *hw);
  64. static s32 igb_validate_nvm_checksum_82580(struct e1000_hw *hw);
  65. static s32 igb_update_nvm_checksum_82580(struct e1000_hw *hw);
  66. static s32 igb_validate_nvm_checksum_i350(struct e1000_hw *hw);
  67. static s32 igb_update_nvm_checksum_i350(struct e1000_hw *hw);
  68. static const u16 e1000_82580_rxpbs_table[] = {
  69. 36, 72, 144, 1, 2, 4, 8, 16, 35, 70, 140 };
  70. /**
  71. * igb_sgmii_uses_mdio_82575 - Determine if I2C pins are for external MDIO
  72. * @hw: pointer to the HW structure
  73. *
  74. * Called to determine if the I2C pins are being used for I2C or as an
  75. * external MDIO interface since the two options are mutually exclusive.
  76. **/
  77. static bool igb_sgmii_uses_mdio_82575(struct e1000_hw *hw)
  78. {
  79. u32 reg = 0;
  80. bool ext_mdio = false;
  81. switch (hw->mac.type) {
  82. case e1000_82575:
  83. case e1000_82576:
  84. reg = rd32(E1000_MDIC);
  85. ext_mdio = !!(reg & E1000_MDIC_DEST);
  86. break;
  87. case e1000_82580:
  88. case e1000_i350:
  89. case e1000_i354:
  90. case e1000_i210:
  91. case e1000_i211:
  92. reg = rd32(E1000_MDICNFG);
  93. ext_mdio = !!(reg & E1000_MDICNFG_EXT_MDIO);
  94. break;
  95. default:
  96. break;
  97. }
  98. return ext_mdio;
  99. }
  100. /**
  101. * igb_check_for_link_media_swap - Check which M88E1112 interface linked
  102. * @hw: pointer to the HW structure
  103. *
  104. * Poll the M88E1112 interfaces to see which interface achieved link.
  105. */
  106. static s32 igb_check_for_link_media_swap(struct e1000_hw *hw)
  107. {
  108. struct e1000_phy_info *phy = &hw->phy;
  109. s32 ret_val;
  110. u16 data;
  111. u8 port = 0;
  112. /* Check the copper medium. */
  113. ret_val = phy->ops.write_reg(hw, E1000_M88E1112_PAGE_ADDR, 0);
  114. if (ret_val)
  115. return ret_val;
  116. ret_val = phy->ops.read_reg(hw, E1000_M88E1112_STATUS, &data);
  117. if (ret_val)
  118. return ret_val;
  119. if (data & E1000_M88E1112_STATUS_LINK)
  120. port = E1000_MEDIA_PORT_COPPER;
  121. /* Check the other medium. */
  122. ret_val = phy->ops.write_reg(hw, E1000_M88E1112_PAGE_ADDR, 1);
  123. if (ret_val)
  124. return ret_val;
  125. ret_val = phy->ops.read_reg(hw, E1000_M88E1112_STATUS, &data);
  126. if (ret_val)
  127. return ret_val;
  128. if (data & E1000_M88E1112_STATUS_LINK)
  129. port = E1000_MEDIA_PORT_OTHER;
  130. /* Determine if a swap needs to happen. */
  131. if (port && (hw->dev_spec._82575.media_port != port)) {
  132. hw->dev_spec._82575.media_port = port;
  133. hw->dev_spec._82575.media_changed = true;
  134. }
  135. if (port == E1000_MEDIA_PORT_COPPER) {
  136. /* reset page to 0 */
  137. ret_val = phy->ops.write_reg(hw, E1000_M88E1112_PAGE_ADDR, 0);
  138. if (ret_val)
  139. return ret_val;
  140. igb_check_for_link_82575(hw);
  141. } else {
  142. igb_check_for_link_82575(hw);
  143. /* reset page to 0 */
  144. ret_val = phy->ops.write_reg(hw, E1000_M88E1112_PAGE_ADDR, 0);
  145. if (ret_val)
  146. return ret_val;
  147. }
  148. return 0;
  149. }
  150. /**
  151. * igb_init_phy_params_82575 - Init PHY func ptrs.
  152. * @hw: pointer to the HW structure
  153. **/
  154. static s32 igb_init_phy_params_82575(struct e1000_hw *hw)
  155. {
  156. struct e1000_phy_info *phy = &hw->phy;
  157. s32 ret_val = 0;
  158. u32 ctrl_ext;
  159. if (hw->phy.media_type != e1000_media_type_copper) {
  160. phy->type = e1000_phy_none;
  161. goto out;
  162. }
  163. phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
  164. phy->reset_delay_us = 100;
  165. ctrl_ext = rd32(E1000_CTRL_EXT);
  166. if (igb_sgmii_active_82575(hw)) {
  167. phy->ops.reset = igb_phy_hw_reset_sgmii_82575;
  168. ctrl_ext |= E1000_CTRL_I2C_ENA;
  169. } else {
  170. phy->ops.reset = igb_phy_hw_reset;
  171. ctrl_ext &= ~E1000_CTRL_I2C_ENA;
  172. }
  173. wr32(E1000_CTRL_EXT, ctrl_ext);
  174. igb_reset_mdicnfg_82580(hw);
  175. if (igb_sgmii_active_82575(hw) && !igb_sgmii_uses_mdio_82575(hw)) {
  176. phy->ops.read_reg = igb_read_phy_reg_sgmii_82575;
  177. phy->ops.write_reg = igb_write_phy_reg_sgmii_82575;
  178. } else {
  179. switch (hw->mac.type) {
  180. case e1000_82580:
  181. case e1000_i350:
  182. case e1000_i354:
  183. phy->ops.read_reg = igb_read_phy_reg_82580;
  184. phy->ops.write_reg = igb_write_phy_reg_82580;
  185. break;
  186. case e1000_i210:
  187. case e1000_i211:
  188. phy->ops.read_reg = igb_read_phy_reg_gs40g;
  189. phy->ops.write_reg = igb_write_phy_reg_gs40g;
  190. break;
  191. default:
  192. phy->ops.read_reg = igb_read_phy_reg_igp;
  193. phy->ops.write_reg = igb_write_phy_reg_igp;
  194. }
  195. }
  196. /* set lan id */
  197. hw->bus.func = (rd32(E1000_STATUS) & E1000_STATUS_FUNC_MASK) >>
  198. E1000_STATUS_FUNC_SHIFT;
  199. /* Set phy->phy_addr and phy->id. */
  200. ret_val = igb_get_phy_id_82575(hw);
  201. if (ret_val)
  202. return ret_val;
  203. /* Verify phy id and set remaining function pointers */
  204. switch (phy->id) {
  205. case M88E1543_E_PHY_ID:
  206. case M88E1512_E_PHY_ID:
  207. case I347AT4_E_PHY_ID:
  208. case M88E1112_E_PHY_ID:
  209. case M88E1111_I_PHY_ID:
  210. phy->type = e1000_phy_m88;
  211. phy->ops.check_polarity = igb_check_polarity_m88;
  212. phy->ops.get_phy_info = igb_get_phy_info_m88;
  213. if (phy->id != M88E1111_I_PHY_ID)
  214. phy->ops.get_cable_length =
  215. igb_get_cable_length_m88_gen2;
  216. else
  217. phy->ops.get_cable_length = igb_get_cable_length_m88;
  218. phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_m88;
  219. /* Check if this PHY is configured for media swap. */
  220. if (phy->id == M88E1112_E_PHY_ID) {
  221. u16 data;
  222. ret_val = phy->ops.write_reg(hw,
  223. E1000_M88E1112_PAGE_ADDR,
  224. 2);
  225. if (ret_val)
  226. goto out;
  227. ret_val = phy->ops.read_reg(hw,
  228. E1000_M88E1112_MAC_CTRL_1,
  229. &data);
  230. if (ret_val)
  231. goto out;
  232. data = (data & E1000_M88E1112_MAC_CTRL_1_MODE_MASK) >>
  233. E1000_M88E1112_MAC_CTRL_1_MODE_SHIFT;
  234. if (data == E1000_M88E1112_AUTO_COPPER_SGMII ||
  235. data == E1000_M88E1112_AUTO_COPPER_BASEX)
  236. hw->mac.ops.check_for_link =
  237. igb_check_for_link_media_swap;
  238. }
  239. if (phy->id == M88E1512_E_PHY_ID) {
  240. ret_val = igb_initialize_M88E1512_phy(hw);
  241. if (ret_val)
  242. goto out;
  243. }
  244. break;
  245. case IGP03E1000_E_PHY_ID:
  246. phy->type = e1000_phy_igp_3;
  247. phy->ops.get_phy_info = igb_get_phy_info_igp;
  248. phy->ops.get_cable_length = igb_get_cable_length_igp_2;
  249. phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_igp;
  250. phy->ops.set_d0_lplu_state = igb_set_d0_lplu_state_82575;
  251. phy->ops.set_d3_lplu_state = igb_set_d3_lplu_state;
  252. break;
  253. case I82580_I_PHY_ID:
  254. case I350_I_PHY_ID:
  255. phy->type = e1000_phy_82580;
  256. phy->ops.force_speed_duplex =
  257. igb_phy_force_speed_duplex_82580;
  258. phy->ops.get_cable_length = igb_get_cable_length_82580;
  259. phy->ops.get_phy_info = igb_get_phy_info_82580;
  260. phy->ops.set_d0_lplu_state = igb_set_d0_lplu_state_82580;
  261. phy->ops.set_d3_lplu_state = igb_set_d3_lplu_state_82580;
  262. break;
  263. case I210_I_PHY_ID:
  264. phy->type = e1000_phy_i210;
  265. phy->ops.check_polarity = igb_check_polarity_m88;
  266. phy->ops.get_phy_info = igb_get_phy_info_m88;
  267. phy->ops.get_cable_length = igb_get_cable_length_m88_gen2;
  268. phy->ops.set_d0_lplu_state = igb_set_d0_lplu_state_82580;
  269. phy->ops.set_d3_lplu_state = igb_set_d3_lplu_state_82580;
  270. phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_m88;
  271. break;
  272. default:
  273. ret_val = -E1000_ERR_PHY;
  274. goto out;
  275. }
  276. out:
  277. return ret_val;
  278. }
  279. /**
  280. * igb_init_nvm_params_82575 - Init NVM func ptrs.
  281. * @hw: pointer to the HW structure
  282. **/
  283. static s32 igb_init_nvm_params_82575(struct e1000_hw *hw)
  284. {
  285. struct e1000_nvm_info *nvm = &hw->nvm;
  286. u32 eecd = rd32(E1000_EECD);
  287. u16 size;
  288. size = (u16)((eecd & E1000_EECD_SIZE_EX_MASK) >>
  289. E1000_EECD_SIZE_EX_SHIFT);
  290. /* Added to a constant, "size" becomes the left-shift value
  291. * for setting word_size.
  292. */
  293. size += NVM_WORD_SIZE_BASE_SHIFT;
  294. /* Just in case size is out of range, cap it to the largest
  295. * EEPROM size supported
  296. */
  297. if (size > 15)
  298. size = 15;
  299. nvm->word_size = 1 << size;
  300. nvm->opcode_bits = 8;
  301. nvm->delay_usec = 1;
  302. switch (nvm->override) {
  303. case e1000_nvm_override_spi_large:
  304. nvm->page_size = 32;
  305. nvm->address_bits = 16;
  306. break;
  307. case e1000_nvm_override_spi_small:
  308. nvm->page_size = 8;
  309. nvm->address_bits = 8;
  310. break;
  311. default:
  312. nvm->page_size = eecd & E1000_EECD_ADDR_BITS ? 32 : 8;
  313. nvm->address_bits = eecd & E1000_EECD_ADDR_BITS ?
  314. 16 : 8;
  315. break;
  316. }
  317. if (nvm->word_size == (1 << 15))
  318. nvm->page_size = 128;
  319. nvm->type = e1000_nvm_eeprom_spi;
  320. /* NVM Function Pointers */
  321. nvm->ops.acquire = igb_acquire_nvm_82575;
  322. nvm->ops.release = igb_release_nvm_82575;
  323. nvm->ops.write = igb_write_nvm_spi;
  324. nvm->ops.validate = igb_validate_nvm_checksum;
  325. nvm->ops.update = igb_update_nvm_checksum;
  326. if (nvm->word_size < (1 << 15))
  327. nvm->ops.read = igb_read_nvm_eerd;
  328. else
  329. nvm->ops.read = igb_read_nvm_spi;
  330. /* override generic family function pointers for specific descendants */
  331. switch (hw->mac.type) {
  332. case e1000_82580:
  333. nvm->ops.validate = igb_validate_nvm_checksum_82580;
  334. nvm->ops.update = igb_update_nvm_checksum_82580;
  335. break;
  336. case e1000_i354:
  337. case e1000_i350:
  338. nvm->ops.validate = igb_validate_nvm_checksum_i350;
  339. nvm->ops.update = igb_update_nvm_checksum_i350;
  340. break;
  341. default:
  342. break;
  343. }
  344. return 0;
  345. }
  346. /**
  347. * igb_init_mac_params_82575 - Init MAC func ptrs.
  348. * @hw: pointer to the HW structure
  349. **/
  350. static s32 igb_init_mac_params_82575(struct e1000_hw *hw)
  351. {
  352. struct e1000_mac_info *mac = &hw->mac;
  353. struct e1000_dev_spec_82575 *dev_spec = &hw->dev_spec._82575;
  354. /* Set mta register count */
  355. mac->mta_reg_count = 128;
  356. /* Set rar entry count */
  357. switch (mac->type) {
  358. case e1000_82576:
  359. mac->rar_entry_count = E1000_RAR_ENTRIES_82576;
  360. break;
  361. case e1000_82580:
  362. mac->rar_entry_count = E1000_RAR_ENTRIES_82580;
  363. break;
  364. case e1000_i350:
  365. case e1000_i354:
  366. mac->rar_entry_count = E1000_RAR_ENTRIES_I350;
  367. break;
  368. default:
  369. mac->rar_entry_count = E1000_RAR_ENTRIES_82575;
  370. break;
  371. }
  372. /* reset */
  373. if (mac->type >= e1000_82580)
  374. mac->ops.reset_hw = igb_reset_hw_82580;
  375. else
  376. mac->ops.reset_hw = igb_reset_hw_82575;
  377. if (mac->type >= e1000_i210) {
  378. mac->ops.acquire_swfw_sync = igb_acquire_swfw_sync_i210;
  379. mac->ops.release_swfw_sync = igb_release_swfw_sync_i210;
  380. } else {
  381. mac->ops.acquire_swfw_sync = igb_acquire_swfw_sync_82575;
  382. mac->ops.release_swfw_sync = igb_release_swfw_sync_82575;
  383. }
  384. /* Set if part includes ASF firmware */
  385. mac->asf_firmware_present = true;
  386. /* Set if manageability features are enabled. */
  387. mac->arc_subsystem_valid =
  388. (rd32(E1000_FWSM) & E1000_FWSM_MODE_MASK)
  389. ? true : false;
  390. /* enable EEE on i350 parts and later parts */
  391. if (mac->type >= e1000_i350)
  392. dev_spec->eee_disable = false;
  393. else
  394. dev_spec->eee_disable = true;
  395. /* Allow a single clear of the SW semaphore on I210 and newer */
  396. if (mac->type >= e1000_i210)
  397. dev_spec->clear_semaphore_once = true;
  398. /* physical interface link setup */
  399. mac->ops.setup_physical_interface =
  400. (hw->phy.media_type == e1000_media_type_copper)
  401. ? igb_setup_copper_link_82575
  402. : igb_setup_serdes_link_82575;
  403. if (mac->type == e1000_82580) {
  404. switch (hw->device_id) {
  405. /* feature not supported on these id's */
  406. case E1000_DEV_ID_DH89XXCC_SGMII:
  407. case E1000_DEV_ID_DH89XXCC_SERDES:
  408. case E1000_DEV_ID_DH89XXCC_BACKPLANE:
  409. case E1000_DEV_ID_DH89XXCC_SFP:
  410. break;
  411. default:
  412. hw->dev_spec._82575.mas_capable = true;
  413. break;
  414. }
  415. }
  416. return 0;
  417. }
  418. /**
  419. * igb_set_sfp_media_type_82575 - derives SFP module media type.
  420. * @hw: pointer to the HW structure
  421. *
  422. * The media type is chosen based on SFP module.
  423. * compatibility flags retrieved from SFP ID EEPROM.
  424. **/
  425. static s32 igb_set_sfp_media_type_82575(struct e1000_hw *hw)
  426. {
  427. s32 ret_val = E1000_ERR_CONFIG;
  428. u32 ctrl_ext = 0;
  429. struct e1000_dev_spec_82575 *dev_spec = &hw->dev_spec._82575;
  430. struct e1000_sfp_flags *eth_flags = &dev_spec->eth_flags;
  431. u8 tranceiver_type = 0;
  432. s32 timeout = 3;
  433. /* Turn I2C interface ON and power on sfp cage */
  434. ctrl_ext = rd32(E1000_CTRL_EXT);
  435. ctrl_ext &= ~E1000_CTRL_EXT_SDP3_DATA;
  436. wr32(E1000_CTRL_EXT, ctrl_ext | E1000_CTRL_I2C_ENA);
  437. wrfl();
  438. /* Read SFP module data */
  439. while (timeout) {
  440. ret_val = igb_read_sfp_data_byte(hw,
  441. E1000_I2CCMD_SFP_DATA_ADDR(E1000_SFF_IDENTIFIER_OFFSET),
  442. &tranceiver_type);
  443. if (ret_val == 0)
  444. break;
  445. msleep(100);
  446. timeout--;
  447. }
  448. if (ret_val != 0)
  449. goto out;
  450. ret_val = igb_read_sfp_data_byte(hw,
  451. E1000_I2CCMD_SFP_DATA_ADDR(E1000_SFF_ETH_FLAGS_OFFSET),
  452. (u8 *)eth_flags);
  453. if (ret_val != 0)
  454. goto out;
  455. /* Check if there is some SFP module plugged and powered */
  456. if ((tranceiver_type == E1000_SFF_IDENTIFIER_SFP) ||
  457. (tranceiver_type == E1000_SFF_IDENTIFIER_SFF)) {
  458. dev_spec->module_plugged = true;
  459. if (eth_flags->e1000_base_lx || eth_flags->e1000_base_sx) {
  460. hw->phy.media_type = e1000_media_type_internal_serdes;
  461. } else if (eth_flags->e100_base_fx) {
  462. dev_spec->sgmii_active = true;
  463. hw->phy.media_type = e1000_media_type_internal_serdes;
  464. } else if (eth_flags->e1000_base_t) {
  465. dev_spec->sgmii_active = true;
  466. hw->phy.media_type = e1000_media_type_copper;
  467. } else {
  468. hw->phy.media_type = e1000_media_type_unknown;
  469. hw_dbg("PHY module has not been recognized\n");
  470. goto out;
  471. }
  472. } else {
  473. hw->phy.media_type = e1000_media_type_unknown;
  474. }
  475. ret_val = 0;
  476. out:
  477. /* Restore I2C interface setting */
  478. wr32(E1000_CTRL_EXT, ctrl_ext);
  479. return ret_val;
  480. }
  481. static s32 igb_get_invariants_82575(struct e1000_hw *hw)
  482. {
  483. struct e1000_mac_info *mac = &hw->mac;
  484. struct e1000_dev_spec_82575 *dev_spec = &hw->dev_spec._82575;
  485. s32 ret_val;
  486. u32 ctrl_ext = 0;
  487. u32 link_mode = 0;
  488. switch (hw->device_id) {
  489. case E1000_DEV_ID_82575EB_COPPER:
  490. case E1000_DEV_ID_82575EB_FIBER_SERDES:
  491. case E1000_DEV_ID_82575GB_QUAD_COPPER:
  492. mac->type = e1000_82575;
  493. break;
  494. case E1000_DEV_ID_82576:
  495. case E1000_DEV_ID_82576_NS:
  496. case E1000_DEV_ID_82576_NS_SERDES:
  497. case E1000_DEV_ID_82576_FIBER:
  498. case E1000_DEV_ID_82576_SERDES:
  499. case E1000_DEV_ID_82576_QUAD_COPPER:
  500. case E1000_DEV_ID_82576_QUAD_COPPER_ET2:
  501. case E1000_DEV_ID_82576_SERDES_QUAD:
  502. mac->type = e1000_82576;
  503. break;
  504. case E1000_DEV_ID_82580_COPPER:
  505. case E1000_DEV_ID_82580_FIBER:
  506. case E1000_DEV_ID_82580_QUAD_FIBER:
  507. case E1000_DEV_ID_82580_SERDES:
  508. case E1000_DEV_ID_82580_SGMII:
  509. case E1000_DEV_ID_82580_COPPER_DUAL:
  510. case E1000_DEV_ID_DH89XXCC_SGMII:
  511. case E1000_DEV_ID_DH89XXCC_SERDES:
  512. case E1000_DEV_ID_DH89XXCC_BACKPLANE:
  513. case E1000_DEV_ID_DH89XXCC_SFP:
  514. mac->type = e1000_82580;
  515. break;
  516. case E1000_DEV_ID_I350_COPPER:
  517. case E1000_DEV_ID_I350_FIBER:
  518. case E1000_DEV_ID_I350_SERDES:
  519. case E1000_DEV_ID_I350_SGMII:
  520. mac->type = e1000_i350;
  521. break;
  522. case E1000_DEV_ID_I210_COPPER:
  523. case E1000_DEV_ID_I210_FIBER:
  524. case E1000_DEV_ID_I210_SERDES:
  525. case E1000_DEV_ID_I210_SGMII:
  526. case E1000_DEV_ID_I210_COPPER_FLASHLESS:
  527. case E1000_DEV_ID_I210_SERDES_FLASHLESS:
  528. mac->type = e1000_i210;
  529. break;
  530. case E1000_DEV_ID_I211_COPPER:
  531. mac->type = e1000_i211;
  532. break;
  533. case E1000_DEV_ID_I354_BACKPLANE_1GBPS:
  534. case E1000_DEV_ID_I354_SGMII:
  535. case E1000_DEV_ID_I354_BACKPLANE_2_5GBPS:
  536. mac->type = e1000_i354;
  537. break;
  538. default:
  539. return -E1000_ERR_MAC_INIT;
  540. }
  541. /* Set media type */
  542. /* The 82575 uses bits 22:23 for link mode. The mode can be changed
  543. * based on the EEPROM. We cannot rely upon device ID. There
  544. * is no distinguishable difference between fiber and internal
  545. * SerDes mode on the 82575. There can be an external PHY attached
  546. * on the SGMII interface. For this, we'll set sgmii_active to true.
  547. */
  548. hw->phy.media_type = e1000_media_type_copper;
  549. dev_spec->sgmii_active = false;
  550. dev_spec->module_plugged = false;
  551. ctrl_ext = rd32(E1000_CTRL_EXT);
  552. link_mode = ctrl_ext & E1000_CTRL_EXT_LINK_MODE_MASK;
  553. switch (link_mode) {
  554. case E1000_CTRL_EXT_LINK_MODE_1000BASE_KX:
  555. hw->phy.media_type = e1000_media_type_internal_serdes;
  556. break;
  557. case E1000_CTRL_EXT_LINK_MODE_SGMII:
  558. /* Get phy control interface type set (MDIO vs. I2C)*/
  559. if (igb_sgmii_uses_mdio_82575(hw)) {
  560. hw->phy.media_type = e1000_media_type_copper;
  561. dev_spec->sgmii_active = true;
  562. break;
  563. }
  564. /* fall through for I2C based SGMII */
  565. case E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES:
  566. /* read media type from SFP EEPROM */
  567. ret_val = igb_set_sfp_media_type_82575(hw);
  568. if ((ret_val != 0) ||
  569. (hw->phy.media_type == e1000_media_type_unknown)) {
  570. /* If media type was not identified then return media
  571. * type defined by the CTRL_EXT settings.
  572. */
  573. hw->phy.media_type = e1000_media_type_internal_serdes;
  574. if (link_mode == E1000_CTRL_EXT_LINK_MODE_SGMII) {
  575. hw->phy.media_type = e1000_media_type_copper;
  576. dev_spec->sgmii_active = true;
  577. }
  578. break;
  579. }
  580. /* do not change link mode for 100BaseFX */
  581. if (dev_spec->eth_flags.e100_base_fx)
  582. break;
  583. /* change current link mode setting */
  584. ctrl_ext &= ~E1000_CTRL_EXT_LINK_MODE_MASK;
  585. if (hw->phy.media_type == e1000_media_type_copper)
  586. ctrl_ext |= E1000_CTRL_EXT_LINK_MODE_SGMII;
  587. else
  588. ctrl_ext |= E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES;
  589. wr32(E1000_CTRL_EXT, ctrl_ext);
  590. break;
  591. default:
  592. break;
  593. }
  594. /* mac initialization and operations */
  595. ret_val = igb_init_mac_params_82575(hw);
  596. if (ret_val)
  597. goto out;
  598. /* NVM initialization */
  599. ret_val = igb_init_nvm_params_82575(hw);
  600. switch (hw->mac.type) {
  601. case e1000_i210:
  602. case e1000_i211:
  603. ret_val = igb_init_nvm_params_i210(hw);
  604. break;
  605. default:
  606. break;
  607. }
  608. if (ret_val)
  609. goto out;
  610. /* if part supports SR-IOV then initialize mailbox parameters */
  611. switch (mac->type) {
  612. case e1000_82576:
  613. case e1000_i350:
  614. igb_init_mbx_params_pf(hw);
  615. break;
  616. default:
  617. break;
  618. }
  619. /* setup PHY parameters */
  620. ret_val = igb_init_phy_params_82575(hw);
  621. out:
  622. return ret_val;
  623. }
  624. /**
  625. * igb_acquire_phy_82575 - Acquire rights to access PHY
  626. * @hw: pointer to the HW structure
  627. *
  628. * Acquire access rights to the correct PHY. This is a
  629. * function pointer entry point called by the api module.
  630. **/
  631. static s32 igb_acquire_phy_82575(struct e1000_hw *hw)
  632. {
  633. u16 mask = E1000_SWFW_PHY0_SM;
  634. if (hw->bus.func == E1000_FUNC_1)
  635. mask = E1000_SWFW_PHY1_SM;
  636. else if (hw->bus.func == E1000_FUNC_2)
  637. mask = E1000_SWFW_PHY2_SM;
  638. else if (hw->bus.func == E1000_FUNC_3)
  639. mask = E1000_SWFW_PHY3_SM;
  640. return hw->mac.ops.acquire_swfw_sync(hw, mask);
  641. }
  642. /**
  643. * igb_release_phy_82575 - Release rights to access PHY
  644. * @hw: pointer to the HW structure
  645. *
  646. * A wrapper to release access rights to the correct PHY. This is a
  647. * function pointer entry point called by the api module.
  648. **/
  649. static void igb_release_phy_82575(struct e1000_hw *hw)
  650. {
  651. u16 mask = E1000_SWFW_PHY0_SM;
  652. if (hw->bus.func == E1000_FUNC_1)
  653. mask = E1000_SWFW_PHY1_SM;
  654. else if (hw->bus.func == E1000_FUNC_2)
  655. mask = E1000_SWFW_PHY2_SM;
  656. else if (hw->bus.func == E1000_FUNC_3)
  657. mask = E1000_SWFW_PHY3_SM;
  658. hw->mac.ops.release_swfw_sync(hw, mask);
  659. }
  660. /**
  661. * igb_read_phy_reg_sgmii_82575 - Read PHY register using sgmii
  662. * @hw: pointer to the HW structure
  663. * @offset: register offset to be read
  664. * @data: pointer to the read data
  665. *
  666. * Reads the PHY register at offset using the serial gigabit media independent
  667. * interface and stores the retrieved information in data.
  668. **/
  669. static s32 igb_read_phy_reg_sgmii_82575(struct e1000_hw *hw, u32 offset,
  670. u16 *data)
  671. {
  672. s32 ret_val = -E1000_ERR_PARAM;
  673. if (offset > E1000_MAX_SGMII_PHY_REG_ADDR) {
  674. hw_dbg("PHY Address %u is out of range\n", offset);
  675. goto out;
  676. }
  677. ret_val = hw->phy.ops.acquire(hw);
  678. if (ret_val)
  679. goto out;
  680. ret_val = igb_read_phy_reg_i2c(hw, offset, data);
  681. hw->phy.ops.release(hw);
  682. out:
  683. return ret_val;
  684. }
  685. /**
  686. * igb_write_phy_reg_sgmii_82575 - Write PHY register using sgmii
  687. * @hw: pointer to the HW structure
  688. * @offset: register offset to write to
  689. * @data: data to write at register offset
  690. *
  691. * Writes the data to PHY register at the offset using the serial gigabit
  692. * media independent interface.
  693. **/
  694. static s32 igb_write_phy_reg_sgmii_82575(struct e1000_hw *hw, u32 offset,
  695. u16 data)
  696. {
  697. s32 ret_val = -E1000_ERR_PARAM;
  698. if (offset > E1000_MAX_SGMII_PHY_REG_ADDR) {
  699. hw_dbg("PHY Address %d is out of range\n", offset);
  700. goto out;
  701. }
  702. ret_val = hw->phy.ops.acquire(hw);
  703. if (ret_val)
  704. goto out;
  705. ret_val = igb_write_phy_reg_i2c(hw, offset, data);
  706. hw->phy.ops.release(hw);
  707. out:
  708. return ret_val;
  709. }
  710. /**
  711. * igb_get_phy_id_82575 - Retrieve PHY addr and id
  712. * @hw: pointer to the HW structure
  713. *
  714. * Retrieves the PHY address and ID for both PHY's which do and do not use
  715. * sgmi interface.
  716. **/
  717. static s32 igb_get_phy_id_82575(struct e1000_hw *hw)
  718. {
  719. struct e1000_phy_info *phy = &hw->phy;
  720. s32 ret_val = 0;
  721. u16 phy_id;
  722. u32 ctrl_ext;
  723. u32 mdic;
  724. /* Extra read required for some PHY's on i354 */
  725. if (hw->mac.type == e1000_i354)
  726. igb_get_phy_id(hw);
  727. /* For SGMII PHYs, we try the list of possible addresses until
  728. * we find one that works. For non-SGMII PHYs
  729. * (e.g. integrated copper PHYs), an address of 1 should
  730. * work. The result of this function should mean phy->phy_addr
  731. * and phy->id are set correctly.
  732. */
  733. if (!(igb_sgmii_active_82575(hw))) {
  734. phy->addr = 1;
  735. ret_val = igb_get_phy_id(hw);
  736. goto out;
  737. }
  738. if (igb_sgmii_uses_mdio_82575(hw)) {
  739. switch (hw->mac.type) {
  740. case e1000_82575:
  741. case e1000_82576:
  742. mdic = rd32(E1000_MDIC);
  743. mdic &= E1000_MDIC_PHY_MASK;
  744. phy->addr = mdic >> E1000_MDIC_PHY_SHIFT;
  745. break;
  746. case e1000_82580:
  747. case e1000_i350:
  748. case e1000_i354:
  749. case e1000_i210:
  750. case e1000_i211:
  751. mdic = rd32(E1000_MDICNFG);
  752. mdic &= E1000_MDICNFG_PHY_MASK;
  753. phy->addr = mdic >> E1000_MDICNFG_PHY_SHIFT;
  754. break;
  755. default:
  756. ret_val = -E1000_ERR_PHY;
  757. goto out;
  758. }
  759. ret_val = igb_get_phy_id(hw);
  760. goto out;
  761. }
  762. /* Power on sgmii phy if it is disabled */
  763. ctrl_ext = rd32(E1000_CTRL_EXT);
  764. wr32(E1000_CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_SDP3_DATA);
  765. wrfl();
  766. msleep(300);
  767. /* The address field in the I2CCMD register is 3 bits and 0 is invalid.
  768. * Therefore, we need to test 1-7
  769. */
  770. for (phy->addr = 1; phy->addr < 8; phy->addr++) {
  771. ret_val = igb_read_phy_reg_sgmii_82575(hw, PHY_ID1, &phy_id);
  772. if (ret_val == 0) {
  773. hw_dbg("Vendor ID 0x%08X read at address %u\n",
  774. phy_id, phy->addr);
  775. /* At the time of this writing, The M88 part is
  776. * the only supported SGMII PHY product.
  777. */
  778. if (phy_id == M88_VENDOR)
  779. break;
  780. } else {
  781. hw_dbg("PHY address %u was unreadable\n", phy->addr);
  782. }
  783. }
  784. /* A valid PHY type couldn't be found. */
  785. if (phy->addr == 8) {
  786. phy->addr = 0;
  787. ret_val = -E1000_ERR_PHY;
  788. goto out;
  789. } else {
  790. ret_val = igb_get_phy_id(hw);
  791. }
  792. /* restore previous sfp cage power state */
  793. wr32(E1000_CTRL_EXT, ctrl_ext);
  794. out:
  795. return ret_val;
  796. }
  797. /**
  798. * igb_phy_hw_reset_sgmii_82575 - Performs a PHY reset
  799. * @hw: pointer to the HW structure
  800. *
  801. * Resets the PHY using the serial gigabit media independent interface.
  802. **/
  803. static s32 igb_phy_hw_reset_sgmii_82575(struct e1000_hw *hw)
  804. {
  805. struct e1000_phy_info *phy = &hw->phy;
  806. s32 ret_val;
  807. /* This isn't a true "hard" reset, but is the only reset
  808. * available to us at this time.
  809. */
  810. hw_dbg("Soft resetting SGMII attached PHY...\n");
  811. /* SFP documentation requires the following to configure the SPF module
  812. * to work on SGMII. No further documentation is given.
  813. */
  814. ret_val = hw->phy.ops.write_reg(hw, 0x1B, 0x8084);
  815. if (ret_val)
  816. goto out;
  817. ret_val = igb_phy_sw_reset(hw);
  818. if (ret_val)
  819. goto out;
  820. if (phy->id == M88E1512_E_PHY_ID)
  821. ret_val = igb_initialize_M88E1512_phy(hw);
  822. out:
  823. return ret_val;
  824. }
  825. /**
  826. * igb_set_d0_lplu_state_82575 - Set Low Power Linkup D0 state
  827. * @hw: pointer to the HW structure
  828. * @active: true to enable LPLU, false to disable
  829. *
  830. * Sets the LPLU D0 state according to the active flag. When
  831. * activating LPLU this function also disables smart speed
  832. * and vice versa. LPLU will not be activated unless the
  833. * device autonegotiation advertisement meets standards of
  834. * either 10 or 10/100 or 10/100/1000 at all duplexes.
  835. * This is a function pointer entry point only called by
  836. * PHY setup routines.
  837. **/
  838. static s32 igb_set_d0_lplu_state_82575(struct e1000_hw *hw, bool active)
  839. {
  840. struct e1000_phy_info *phy = &hw->phy;
  841. s32 ret_val;
  842. u16 data;
  843. ret_val = phy->ops.read_reg(hw, IGP02E1000_PHY_POWER_MGMT, &data);
  844. if (ret_val)
  845. goto out;
  846. if (active) {
  847. data |= IGP02E1000_PM_D0_LPLU;
  848. ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
  849. data);
  850. if (ret_val)
  851. goto out;
  852. /* When LPLU is enabled, we should disable SmartSpeed */
  853. ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
  854. &data);
  855. data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  856. ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
  857. data);
  858. if (ret_val)
  859. goto out;
  860. } else {
  861. data &= ~IGP02E1000_PM_D0_LPLU;
  862. ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
  863. data);
  864. /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
  865. * during Dx states where the power conservation is most
  866. * important. During driver activity we should enable
  867. * SmartSpeed, so performance is maintained.
  868. */
  869. if (phy->smart_speed == e1000_smart_speed_on) {
  870. ret_val = phy->ops.read_reg(hw,
  871. IGP01E1000_PHY_PORT_CONFIG, &data);
  872. if (ret_val)
  873. goto out;
  874. data |= IGP01E1000_PSCFR_SMART_SPEED;
  875. ret_val = phy->ops.write_reg(hw,
  876. IGP01E1000_PHY_PORT_CONFIG, data);
  877. if (ret_val)
  878. goto out;
  879. } else if (phy->smart_speed == e1000_smart_speed_off) {
  880. ret_val = phy->ops.read_reg(hw,
  881. IGP01E1000_PHY_PORT_CONFIG, &data);
  882. if (ret_val)
  883. goto out;
  884. data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  885. ret_val = phy->ops.write_reg(hw,
  886. IGP01E1000_PHY_PORT_CONFIG, data);
  887. if (ret_val)
  888. goto out;
  889. }
  890. }
  891. out:
  892. return ret_val;
  893. }
  894. /**
  895. * igb_set_d0_lplu_state_82580 - Set Low Power Linkup D0 state
  896. * @hw: pointer to the HW structure
  897. * @active: true to enable LPLU, false to disable
  898. *
  899. * Sets the LPLU D0 state according to the active flag. When
  900. * activating LPLU this function also disables smart speed
  901. * and vice versa. LPLU will not be activated unless the
  902. * device autonegotiation advertisement meets standards of
  903. * either 10 or 10/100 or 10/100/1000 at all duplexes.
  904. * This is a function pointer entry point only called by
  905. * PHY setup routines.
  906. **/
  907. static s32 igb_set_d0_lplu_state_82580(struct e1000_hw *hw, bool active)
  908. {
  909. struct e1000_phy_info *phy = &hw->phy;
  910. u16 data;
  911. data = rd32(E1000_82580_PHY_POWER_MGMT);
  912. if (active) {
  913. data |= E1000_82580_PM_D0_LPLU;
  914. /* When LPLU is enabled, we should disable SmartSpeed */
  915. data &= ~E1000_82580_PM_SPD;
  916. } else {
  917. data &= ~E1000_82580_PM_D0_LPLU;
  918. /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
  919. * during Dx states where the power conservation is most
  920. * important. During driver activity we should enable
  921. * SmartSpeed, so performance is maintained.
  922. */
  923. if (phy->smart_speed == e1000_smart_speed_on)
  924. data |= E1000_82580_PM_SPD;
  925. else if (phy->smart_speed == e1000_smart_speed_off)
  926. data &= ~E1000_82580_PM_SPD; }
  927. wr32(E1000_82580_PHY_POWER_MGMT, data);
  928. return 0;
  929. }
  930. /**
  931. * igb_set_d3_lplu_state_82580 - Sets low power link up state for D3
  932. * @hw: pointer to the HW structure
  933. * @active: boolean used to enable/disable lplu
  934. *
  935. * Success returns 0, Failure returns 1
  936. *
  937. * The low power link up (lplu) state is set to the power management level D3
  938. * and SmartSpeed is disabled when active is true, else clear lplu for D3
  939. * and enable Smartspeed. LPLU and Smartspeed are mutually exclusive. LPLU
  940. * is used during Dx states where the power conservation is most important.
  941. * During driver activity, SmartSpeed should be enabled so performance is
  942. * maintained.
  943. **/
  944. static s32 igb_set_d3_lplu_state_82580(struct e1000_hw *hw, bool active)
  945. {
  946. struct e1000_phy_info *phy = &hw->phy;
  947. u16 data;
  948. data = rd32(E1000_82580_PHY_POWER_MGMT);
  949. if (!active) {
  950. data &= ~E1000_82580_PM_D3_LPLU;
  951. /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
  952. * during Dx states where the power conservation is most
  953. * important. During driver activity we should enable
  954. * SmartSpeed, so performance is maintained.
  955. */
  956. if (phy->smart_speed == e1000_smart_speed_on)
  957. data |= E1000_82580_PM_SPD;
  958. else if (phy->smart_speed == e1000_smart_speed_off)
  959. data &= ~E1000_82580_PM_SPD;
  960. } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
  961. (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
  962. (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
  963. data |= E1000_82580_PM_D3_LPLU;
  964. /* When LPLU is enabled, we should disable SmartSpeed */
  965. data &= ~E1000_82580_PM_SPD;
  966. }
  967. wr32(E1000_82580_PHY_POWER_MGMT, data);
  968. return 0;
  969. }
  970. /**
  971. * igb_acquire_nvm_82575 - Request for access to EEPROM
  972. * @hw: pointer to the HW structure
  973. *
  974. * Acquire the necessary semaphores for exclusive access to the EEPROM.
  975. * Set the EEPROM access request bit and wait for EEPROM access grant bit.
  976. * Return successful if access grant bit set, else clear the request for
  977. * EEPROM access and return -E1000_ERR_NVM (-1).
  978. **/
  979. static s32 igb_acquire_nvm_82575(struct e1000_hw *hw)
  980. {
  981. s32 ret_val;
  982. ret_val = hw->mac.ops.acquire_swfw_sync(hw, E1000_SWFW_EEP_SM);
  983. if (ret_val)
  984. goto out;
  985. ret_val = igb_acquire_nvm(hw);
  986. if (ret_val)
  987. hw->mac.ops.release_swfw_sync(hw, E1000_SWFW_EEP_SM);
  988. out:
  989. return ret_val;
  990. }
  991. /**
  992. * igb_release_nvm_82575 - Release exclusive access to EEPROM
  993. * @hw: pointer to the HW structure
  994. *
  995. * Stop any current commands to the EEPROM and clear the EEPROM request bit,
  996. * then release the semaphores acquired.
  997. **/
  998. static void igb_release_nvm_82575(struct e1000_hw *hw)
  999. {
  1000. igb_release_nvm(hw);
  1001. hw->mac.ops.release_swfw_sync(hw, E1000_SWFW_EEP_SM);
  1002. }
  1003. /**
  1004. * igb_acquire_swfw_sync_82575 - Acquire SW/FW semaphore
  1005. * @hw: pointer to the HW structure
  1006. * @mask: specifies which semaphore to acquire
  1007. *
  1008. * Acquire the SW/FW semaphore to access the PHY or NVM. The mask
  1009. * will also specify which port we're acquiring the lock for.
  1010. **/
  1011. static s32 igb_acquire_swfw_sync_82575(struct e1000_hw *hw, u16 mask)
  1012. {
  1013. u32 swfw_sync;
  1014. u32 swmask = mask;
  1015. u32 fwmask = mask << 16;
  1016. s32 ret_val = 0;
  1017. s32 i = 0, timeout = 200;
  1018. while (i < timeout) {
  1019. if (igb_get_hw_semaphore(hw)) {
  1020. ret_val = -E1000_ERR_SWFW_SYNC;
  1021. goto out;
  1022. }
  1023. swfw_sync = rd32(E1000_SW_FW_SYNC);
  1024. if (!(swfw_sync & (fwmask | swmask)))
  1025. break;
  1026. /* Firmware currently using resource (fwmask)
  1027. * or other software thread using resource (swmask)
  1028. */
  1029. igb_put_hw_semaphore(hw);
  1030. mdelay(5);
  1031. i++;
  1032. }
  1033. if (i == timeout) {
  1034. hw_dbg("Driver can't access resource, SW_FW_SYNC timeout.\n");
  1035. ret_val = -E1000_ERR_SWFW_SYNC;
  1036. goto out;
  1037. }
  1038. swfw_sync |= swmask;
  1039. wr32(E1000_SW_FW_SYNC, swfw_sync);
  1040. igb_put_hw_semaphore(hw);
  1041. out:
  1042. return ret_val;
  1043. }
  1044. /**
  1045. * igb_release_swfw_sync_82575 - Release SW/FW semaphore
  1046. * @hw: pointer to the HW structure
  1047. * @mask: specifies which semaphore to acquire
  1048. *
  1049. * Release the SW/FW semaphore used to access the PHY or NVM. The mask
  1050. * will also specify which port we're releasing the lock for.
  1051. **/
  1052. static void igb_release_swfw_sync_82575(struct e1000_hw *hw, u16 mask)
  1053. {
  1054. u32 swfw_sync;
  1055. while (igb_get_hw_semaphore(hw) != 0)
  1056. ; /* Empty */
  1057. swfw_sync = rd32(E1000_SW_FW_SYNC);
  1058. swfw_sync &= ~mask;
  1059. wr32(E1000_SW_FW_SYNC, swfw_sync);
  1060. igb_put_hw_semaphore(hw);
  1061. }
  1062. /**
  1063. * igb_get_cfg_done_82575 - Read config done bit
  1064. * @hw: pointer to the HW structure
  1065. *
  1066. * Read the management control register for the config done bit for
  1067. * completion status. NOTE: silicon which is EEPROM-less will fail trying
  1068. * to read the config done bit, so an error is *ONLY* logged and returns
  1069. * 0. If we were to return with error, EEPROM-less silicon
  1070. * would not be able to be reset or change link.
  1071. **/
  1072. static s32 igb_get_cfg_done_82575(struct e1000_hw *hw)
  1073. {
  1074. s32 timeout = PHY_CFG_TIMEOUT;
  1075. u32 mask = E1000_NVM_CFG_DONE_PORT_0;
  1076. if (hw->bus.func == 1)
  1077. mask = E1000_NVM_CFG_DONE_PORT_1;
  1078. else if (hw->bus.func == E1000_FUNC_2)
  1079. mask = E1000_NVM_CFG_DONE_PORT_2;
  1080. else if (hw->bus.func == E1000_FUNC_3)
  1081. mask = E1000_NVM_CFG_DONE_PORT_3;
  1082. while (timeout) {
  1083. if (rd32(E1000_EEMNGCTL) & mask)
  1084. break;
  1085. usleep_range(1000, 2000);
  1086. timeout--;
  1087. }
  1088. if (!timeout)
  1089. hw_dbg("MNG configuration cycle has not completed.\n");
  1090. /* If EEPROM is not marked present, init the PHY manually */
  1091. if (((rd32(E1000_EECD) & E1000_EECD_PRES) == 0) &&
  1092. (hw->phy.type == e1000_phy_igp_3))
  1093. igb_phy_init_script_igp3(hw);
  1094. return 0;
  1095. }
  1096. /**
  1097. * igb_get_link_up_info_82575 - Get link speed/duplex info
  1098. * @hw: pointer to the HW structure
  1099. * @speed: stores the current speed
  1100. * @duplex: stores the current duplex
  1101. *
  1102. * This is a wrapper function, if using the serial gigabit media independent
  1103. * interface, use PCS to retrieve the link speed and duplex information.
  1104. * Otherwise, use the generic function to get the link speed and duplex info.
  1105. **/
  1106. static s32 igb_get_link_up_info_82575(struct e1000_hw *hw, u16 *speed,
  1107. u16 *duplex)
  1108. {
  1109. s32 ret_val;
  1110. if (hw->phy.media_type != e1000_media_type_copper)
  1111. ret_val = igb_get_pcs_speed_and_duplex_82575(hw, speed,
  1112. duplex);
  1113. else
  1114. ret_val = igb_get_speed_and_duplex_copper(hw, speed,
  1115. duplex);
  1116. return ret_val;
  1117. }
  1118. /**
  1119. * igb_check_for_link_82575 - Check for link
  1120. * @hw: pointer to the HW structure
  1121. *
  1122. * If sgmii is enabled, then use the pcs register to determine link, otherwise
  1123. * use the generic interface for determining link.
  1124. **/
  1125. static s32 igb_check_for_link_82575(struct e1000_hw *hw)
  1126. {
  1127. s32 ret_val;
  1128. u16 speed, duplex;
  1129. if (hw->phy.media_type != e1000_media_type_copper) {
  1130. ret_val = igb_get_pcs_speed_and_duplex_82575(hw, &speed,
  1131. &duplex);
  1132. /* Use this flag to determine if link needs to be checked or
  1133. * not. If we have link clear the flag so that we do not
  1134. * continue to check for link.
  1135. */
  1136. hw->mac.get_link_status = !hw->mac.serdes_has_link;
  1137. /* Configure Flow Control now that Auto-Neg has completed.
  1138. * First, we need to restore the desired flow control
  1139. * settings because we may have had to re-autoneg with a
  1140. * different link partner.
  1141. */
  1142. ret_val = igb_config_fc_after_link_up(hw);
  1143. if (ret_val)
  1144. hw_dbg("Error configuring flow control\n");
  1145. } else {
  1146. ret_val = igb_check_for_copper_link(hw);
  1147. }
  1148. return ret_val;
  1149. }
  1150. /**
  1151. * igb_power_up_serdes_link_82575 - Power up the serdes link after shutdown
  1152. * @hw: pointer to the HW structure
  1153. **/
  1154. void igb_power_up_serdes_link_82575(struct e1000_hw *hw)
  1155. {
  1156. u32 reg;
  1157. if ((hw->phy.media_type != e1000_media_type_internal_serdes) &&
  1158. !igb_sgmii_active_82575(hw))
  1159. return;
  1160. /* Enable PCS to turn on link */
  1161. reg = rd32(E1000_PCS_CFG0);
  1162. reg |= E1000_PCS_CFG_PCS_EN;
  1163. wr32(E1000_PCS_CFG0, reg);
  1164. /* Power up the laser */
  1165. reg = rd32(E1000_CTRL_EXT);
  1166. reg &= ~E1000_CTRL_EXT_SDP3_DATA;
  1167. wr32(E1000_CTRL_EXT, reg);
  1168. /* flush the write to verify completion */
  1169. wrfl();
  1170. usleep_range(1000, 2000);
  1171. }
  1172. /**
  1173. * igb_get_pcs_speed_and_duplex_82575 - Retrieve current speed/duplex
  1174. * @hw: pointer to the HW structure
  1175. * @speed: stores the current speed
  1176. * @duplex: stores the current duplex
  1177. *
  1178. * Using the physical coding sub-layer (PCS), retrieve the current speed and
  1179. * duplex, then store the values in the pointers provided.
  1180. **/
  1181. static s32 igb_get_pcs_speed_and_duplex_82575(struct e1000_hw *hw, u16 *speed,
  1182. u16 *duplex)
  1183. {
  1184. struct e1000_mac_info *mac = &hw->mac;
  1185. u32 pcs, status;
  1186. /* Set up defaults for the return values of this function */
  1187. mac->serdes_has_link = false;
  1188. *speed = 0;
  1189. *duplex = 0;
  1190. /* Read the PCS Status register for link state. For non-copper mode,
  1191. * the status register is not accurate. The PCS status register is
  1192. * used instead.
  1193. */
  1194. pcs = rd32(E1000_PCS_LSTAT);
  1195. /* The link up bit determines when link is up on autoneg. The sync ok
  1196. * gets set once both sides sync up and agree upon link. Stable link
  1197. * can be determined by checking for both link up and link sync ok
  1198. */
  1199. if ((pcs & E1000_PCS_LSTS_LINK_OK) && (pcs & E1000_PCS_LSTS_SYNK_OK)) {
  1200. mac->serdes_has_link = true;
  1201. /* Detect and store PCS speed */
  1202. if (pcs & E1000_PCS_LSTS_SPEED_1000)
  1203. *speed = SPEED_1000;
  1204. else if (pcs & E1000_PCS_LSTS_SPEED_100)
  1205. *speed = SPEED_100;
  1206. else
  1207. *speed = SPEED_10;
  1208. /* Detect and store PCS duplex */
  1209. if (pcs & E1000_PCS_LSTS_DUPLEX_FULL)
  1210. *duplex = FULL_DUPLEX;
  1211. else
  1212. *duplex = HALF_DUPLEX;
  1213. /* Check if it is an I354 2.5Gb backplane connection. */
  1214. if (mac->type == e1000_i354) {
  1215. status = rd32(E1000_STATUS);
  1216. if ((status & E1000_STATUS_2P5_SKU) &&
  1217. !(status & E1000_STATUS_2P5_SKU_OVER)) {
  1218. *speed = SPEED_2500;
  1219. *duplex = FULL_DUPLEX;
  1220. hw_dbg("2500 Mbs, ");
  1221. hw_dbg("Full Duplex\n");
  1222. }
  1223. }
  1224. }
  1225. return 0;
  1226. }
  1227. /**
  1228. * igb_shutdown_serdes_link_82575 - Remove link during power down
  1229. * @hw: pointer to the HW structure
  1230. *
  1231. * In the case of fiber serdes, shut down optics and PCS on driver unload
  1232. * when management pass thru is not enabled.
  1233. **/
  1234. void igb_shutdown_serdes_link_82575(struct e1000_hw *hw)
  1235. {
  1236. u32 reg;
  1237. if (hw->phy.media_type != e1000_media_type_internal_serdes &&
  1238. igb_sgmii_active_82575(hw))
  1239. return;
  1240. if (!igb_enable_mng_pass_thru(hw)) {
  1241. /* Disable PCS to turn off link */
  1242. reg = rd32(E1000_PCS_CFG0);
  1243. reg &= ~E1000_PCS_CFG_PCS_EN;
  1244. wr32(E1000_PCS_CFG0, reg);
  1245. /* shutdown the laser */
  1246. reg = rd32(E1000_CTRL_EXT);
  1247. reg |= E1000_CTRL_EXT_SDP3_DATA;
  1248. wr32(E1000_CTRL_EXT, reg);
  1249. /* flush the write to verify completion */
  1250. wrfl();
  1251. usleep_range(1000, 2000);
  1252. }
  1253. }
  1254. /**
  1255. * igb_reset_hw_82575 - Reset hardware
  1256. * @hw: pointer to the HW structure
  1257. *
  1258. * This resets the hardware into a known state. This is a
  1259. * function pointer entry point called by the api module.
  1260. **/
  1261. static s32 igb_reset_hw_82575(struct e1000_hw *hw)
  1262. {
  1263. u32 ctrl;
  1264. s32 ret_val;
  1265. /* Prevent the PCI-E bus from sticking if there is no TLP connection
  1266. * on the last TLP read/write transaction when MAC is reset.
  1267. */
  1268. ret_val = igb_disable_pcie_master(hw);
  1269. if (ret_val)
  1270. hw_dbg("PCI-E Master disable polling has failed.\n");
  1271. /* set the completion timeout for interface */
  1272. ret_val = igb_set_pcie_completion_timeout(hw);
  1273. if (ret_val)
  1274. hw_dbg("PCI-E Set completion timeout has failed.\n");
  1275. hw_dbg("Masking off all interrupts\n");
  1276. wr32(E1000_IMC, 0xffffffff);
  1277. wr32(E1000_RCTL, 0);
  1278. wr32(E1000_TCTL, E1000_TCTL_PSP);
  1279. wrfl();
  1280. usleep_range(10000, 20000);
  1281. ctrl = rd32(E1000_CTRL);
  1282. hw_dbg("Issuing a global reset to MAC\n");
  1283. wr32(E1000_CTRL, ctrl | E1000_CTRL_RST);
  1284. ret_val = igb_get_auto_rd_done(hw);
  1285. if (ret_val) {
  1286. /* When auto config read does not complete, do not
  1287. * return with an error. This can happen in situations
  1288. * where there is no eeprom and prevents getting link.
  1289. */
  1290. hw_dbg("Auto Read Done did not complete\n");
  1291. }
  1292. /* If EEPROM is not present, run manual init scripts */
  1293. if ((rd32(E1000_EECD) & E1000_EECD_PRES) == 0)
  1294. igb_reset_init_script_82575(hw);
  1295. /* Clear any pending interrupt events. */
  1296. wr32(E1000_IMC, 0xffffffff);
  1297. rd32(E1000_ICR);
  1298. /* Install any alternate MAC address into RAR0 */
  1299. ret_val = igb_check_alt_mac_addr(hw);
  1300. return ret_val;
  1301. }
  1302. /**
  1303. * igb_init_hw_82575 - Initialize hardware
  1304. * @hw: pointer to the HW structure
  1305. *
  1306. * This inits the hardware readying it for operation.
  1307. **/
  1308. static s32 igb_init_hw_82575(struct e1000_hw *hw)
  1309. {
  1310. struct e1000_mac_info *mac = &hw->mac;
  1311. s32 ret_val;
  1312. u16 i, rar_count = mac->rar_entry_count;
  1313. if ((hw->mac.type >= e1000_i210) &&
  1314. !(igb_get_flash_presence_i210(hw))) {
  1315. ret_val = igb_pll_workaround_i210(hw);
  1316. if (ret_val)
  1317. return ret_val;
  1318. }
  1319. /* Initialize identification LED */
  1320. ret_val = igb_id_led_init(hw);
  1321. if (ret_val) {
  1322. hw_dbg("Error initializing identification LED\n");
  1323. /* This is not fatal and we should not stop init due to this */
  1324. }
  1325. /* Disabling VLAN filtering */
  1326. hw_dbg("Initializing the IEEE VLAN\n");
  1327. if ((hw->mac.type == e1000_i350) || (hw->mac.type == e1000_i354))
  1328. igb_clear_vfta_i350(hw);
  1329. else
  1330. igb_clear_vfta(hw);
  1331. /* Setup the receive address */
  1332. igb_init_rx_addrs(hw, rar_count);
  1333. /* Zero out the Multicast HASH table */
  1334. hw_dbg("Zeroing the MTA\n");
  1335. for (i = 0; i < mac->mta_reg_count; i++)
  1336. array_wr32(E1000_MTA, i, 0);
  1337. /* Zero out the Unicast HASH table */
  1338. hw_dbg("Zeroing the UTA\n");
  1339. for (i = 0; i < mac->uta_reg_count; i++)
  1340. array_wr32(E1000_UTA, i, 0);
  1341. /* Setup link and flow control */
  1342. ret_val = igb_setup_link(hw);
  1343. /* Clear all of the statistics registers (clear on read). It is
  1344. * important that we do this after we have tried to establish link
  1345. * because the symbol error count will increment wildly if there
  1346. * is no link.
  1347. */
  1348. igb_clear_hw_cntrs_82575(hw);
  1349. return ret_val;
  1350. }
  1351. /**
  1352. * igb_setup_copper_link_82575 - Configure copper link settings
  1353. * @hw: pointer to the HW structure
  1354. *
  1355. * Configures the link for auto-neg or forced speed and duplex. Then we check
  1356. * for link, once link is established calls to configure collision distance
  1357. * and flow control are called.
  1358. **/
  1359. static s32 igb_setup_copper_link_82575(struct e1000_hw *hw)
  1360. {
  1361. u32 ctrl;
  1362. s32 ret_val;
  1363. u32 phpm_reg;
  1364. ctrl = rd32(E1000_CTRL);
  1365. ctrl |= E1000_CTRL_SLU;
  1366. ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
  1367. wr32(E1000_CTRL, ctrl);
  1368. /* Clear Go Link Disconnect bit on supported devices */
  1369. switch (hw->mac.type) {
  1370. case e1000_82580:
  1371. case e1000_i350:
  1372. case e1000_i210:
  1373. case e1000_i211:
  1374. phpm_reg = rd32(E1000_82580_PHY_POWER_MGMT);
  1375. phpm_reg &= ~E1000_82580_PM_GO_LINKD;
  1376. wr32(E1000_82580_PHY_POWER_MGMT, phpm_reg);
  1377. break;
  1378. default:
  1379. break;
  1380. }
  1381. ret_val = igb_setup_serdes_link_82575(hw);
  1382. if (ret_val)
  1383. goto out;
  1384. if (igb_sgmii_active_82575(hw) && !hw->phy.reset_disable) {
  1385. /* allow time for SFP cage time to power up phy */
  1386. msleep(300);
  1387. ret_val = hw->phy.ops.reset(hw);
  1388. if (ret_val) {
  1389. hw_dbg("Error resetting the PHY.\n");
  1390. goto out;
  1391. }
  1392. }
  1393. switch (hw->phy.type) {
  1394. case e1000_phy_i210:
  1395. case e1000_phy_m88:
  1396. switch (hw->phy.id) {
  1397. case I347AT4_E_PHY_ID:
  1398. case M88E1112_E_PHY_ID:
  1399. case M88E1543_E_PHY_ID:
  1400. case M88E1512_E_PHY_ID:
  1401. case I210_I_PHY_ID:
  1402. ret_val = igb_copper_link_setup_m88_gen2(hw);
  1403. break;
  1404. default:
  1405. ret_val = igb_copper_link_setup_m88(hw);
  1406. break;
  1407. }
  1408. break;
  1409. case e1000_phy_igp_3:
  1410. ret_val = igb_copper_link_setup_igp(hw);
  1411. break;
  1412. case e1000_phy_82580:
  1413. ret_val = igb_copper_link_setup_82580(hw);
  1414. break;
  1415. default:
  1416. ret_val = -E1000_ERR_PHY;
  1417. break;
  1418. }
  1419. if (ret_val)
  1420. goto out;
  1421. ret_val = igb_setup_copper_link(hw);
  1422. out:
  1423. return ret_val;
  1424. }
  1425. /**
  1426. * igb_setup_serdes_link_82575 - Setup link for serdes
  1427. * @hw: pointer to the HW structure
  1428. *
  1429. * Configure the physical coding sub-layer (PCS) link. The PCS link is
  1430. * used on copper connections where the serialized gigabit media independent
  1431. * interface (sgmii), or serdes fiber is being used. Configures the link
  1432. * for auto-negotiation or forces speed/duplex.
  1433. **/
  1434. static s32 igb_setup_serdes_link_82575(struct e1000_hw *hw)
  1435. {
  1436. u32 ctrl_ext, ctrl_reg, reg, anadv_reg;
  1437. bool pcs_autoneg;
  1438. s32 ret_val = 0;
  1439. u16 data;
  1440. if ((hw->phy.media_type != e1000_media_type_internal_serdes) &&
  1441. !igb_sgmii_active_82575(hw))
  1442. return ret_val;
  1443. /* On the 82575, SerDes loopback mode persists until it is
  1444. * explicitly turned off or a power cycle is performed. A read to
  1445. * the register does not indicate its status. Therefore, we ensure
  1446. * loopback mode is disabled during initialization.
  1447. */
  1448. wr32(E1000_SCTL, E1000_SCTL_DISABLE_SERDES_LOOPBACK);
  1449. /* power on the sfp cage if present and turn on I2C */
  1450. ctrl_ext = rd32(E1000_CTRL_EXT);
  1451. ctrl_ext &= ~E1000_CTRL_EXT_SDP3_DATA;
  1452. ctrl_ext |= E1000_CTRL_I2C_ENA;
  1453. wr32(E1000_CTRL_EXT, ctrl_ext);
  1454. ctrl_reg = rd32(E1000_CTRL);
  1455. ctrl_reg |= E1000_CTRL_SLU;
  1456. if (hw->mac.type == e1000_82575 || hw->mac.type == e1000_82576) {
  1457. /* set both sw defined pins */
  1458. ctrl_reg |= E1000_CTRL_SWDPIN0 | E1000_CTRL_SWDPIN1;
  1459. /* Set switch control to serdes energy detect */
  1460. reg = rd32(E1000_CONNSW);
  1461. reg |= E1000_CONNSW_ENRGSRC;
  1462. wr32(E1000_CONNSW, reg);
  1463. }
  1464. reg = rd32(E1000_PCS_LCTL);
  1465. /* default pcs_autoneg to the same setting as mac autoneg */
  1466. pcs_autoneg = hw->mac.autoneg;
  1467. switch (ctrl_ext & E1000_CTRL_EXT_LINK_MODE_MASK) {
  1468. case E1000_CTRL_EXT_LINK_MODE_SGMII:
  1469. /* sgmii mode lets the phy handle forcing speed/duplex */
  1470. pcs_autoneg = true;
  1471. /* autoneg time out should be disabled for SGMII mode */
  1472. reg &= ~(E1000_PCS_LCTL_AN_TIMEOUT);
  1473. break;
  1474. case E1000_CTRL_EXT_LINK_MODE_1000BASE_KX:
  1475. /* disable PCS autoneg and support parallel detect only */
  1476. pcs_autoneg = false;
  1477. default:
  1478. if (hw->mac.type == e1000_82575 ||
  1479. hw->mac.type == e1000_82576) {
  1480. ret_val = hw->nvm.ops.read(hw, NVM_COMPAT, 1, &data);
  1481. if (ret_val) {
  1482. hw_dbg(KERN_DEBUG "NVM Read Error\n\n");
  1483. return ret_val;
  1484. }
  1485. if (data & E1000_EEPROM_PCS_AUTONEG_DISABLE_BIT)
  1486. pcs_autoneg = false;
  1487. }
  1488. /* non-SGMII modes only supports a speed of 1000/Full for the
  1489. * link so it is best to just force the MAC and let the pcs
  1490. * link either autoneg or be forced to 1000/Full
  1491. */
  1492. ctrl_reg |= E1000_CTRL_SPD_1000 | E1000_CTRL_FRCSPD |
  1493. E1000_CTRL_FD | E1000_CTRL_FRCDPX;
  1494. /* set speed of 1000/Full if speed/duplex is forced */
  1495. reg |= E1000_PCS_LCTL_FSV_1000 | E1000_PCS_LCTL_FDV_FULL;
  1496. break;
  1497. }
  1498. wr32(E1000_CTRL, ctrl_reg);
  1499. /* New SerDes mode allows for forcing speed or autonegotiating speed
  1500. * at 1gb. Autoneg should be default set by most drivers. This is the
  1501. * mode that will be compatible with older link partners and switches.
  1502. * However, both are supported by the hardware and some drivers/tools.
  1503. */
  1504. reg &= ~(E1000_PCS_LCTL_AN_ENABLE | E1000_PCS_LCTL_FLV_LINK_UP |
  1505. E1000_PCS_LCTL_FSD | E1000_PCS_LCTL_FORCE_LINK);
  1506. if (pcs_autoneg) {
  1507. /* Set PCS register for autoneg */
  1508. reg |= E1000_PCS_LCTL_AN_ENABLE | /* Enable Autoneg */
  1509. E1000_PCS_LCTL_AN_RESTART; /* Restart autoneg */
  1510. /* Disable force flow control for autoneg */
  1511. reg &= ~E1000_PCS_LCTL_FORCE_FCTRL;
  1512. /* Configure flow control advertisement for autoneg */
  1513. anadv_reg = rd32(E1000_PCS_ANADV);
  1514. anadv_reg &= ~(E1000_TXCW_ASM_DIR | E1000_TXCW_PAUSE);
  1515. switch (hw->fc.requested_mode) {
  1516. case e1000_fc_full:
  1517. case e1000_fc_rx_pause:
  1518. anadv_reg |= E1000_TXCW_ASM_DIR;
  1519. anadv_reg |= E1000_TXCW_PAUSE;
  1520. break;
  1521. case e1000_fc_tx_pause:
  1522. anadv_reg |= E1000_TXCW_ASM_DIR;
  1523. break;
  1524. default:
  1525. break;
  1526. }
  1527. wr32(E1000_PCS_ANADV, anadv_reg);
  1528. hw_dbg("Configuring Autoneg:PCS_LCTL=0x%08X\n", reg);
  1529. } else {
  1530. /* Set PCS register for forced link */
  1531. reg |= E1000_PCS_LCTL_FSD; /* Force Speed */
  1532. /* Force flow control for forced link */
  1533. reg |= E1000_PCS_LCTL_FORCE_FCTRL;
  1534. hw_dbg("Configuring Forced Link:PCS_LCTL=0x%08X\n", reg);
  1535. }
  1536. wr32(E1000_PCS_LCTL, reg);
  1537. if (!pcs_autoneg && !igb_sgmii_active_82575(hw))
  1538. igb_force_mac_fc(hw);
  1539. return ret_val;
  1540. }
  1541. /**
  1542. * igb_sgmii_active_82575 - Return sgmii state
  1543. * @hw: pointer to the HW structure
  1544. *
  1545. * 82575 silicon has a serialized gigabit media independent interface (sgmii)
  1546. * which can be enabled for use in the embedded applications. Simply
  1547. * return the current state of the sgmii interface.
  1548. **/
  1549. static bool igb_sgmii_active_82575(struct e1000_hw *hw)
  1550. {
  1551. struct e1000_dev_spec_82575 *dev_spec = &hw->dev_spec._82575;
  1552. return dev_spec->sgmii_active;
  1553. }
  1554. /**
  1555. * igb_reset_init_script_82575 - Inits HW defaults after reset
  1556. * @hw: pointer to the HW structure
  1557. *
  1558. * Inits recommended HW defaults after a reset when there is no EEPROM
  1559. * detected. This is only for the 82575.
  1560. **/
  1561. static s32 igb_reset_init_script_82575(struct e1000_hw *hw)
  1562. {
  1563. if (hw->mac.type == e1000_82575) {
  1564. hw_dbg("Running reset init script for 82575\n");
  1565. /* SerDes configuration via SERDESCTRL */
  1566. igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x00, 0x0C);
  1567. igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x01, 0x78);
  1568. igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x1B, 0x23);
  1569. igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x23, 0x15);
  1570. /* CCM configuration via CCMCTL register */
  1571. igb_write_8bit_ctrl_reg(hw, E1000_CCMCTL, 0x14, 0x00);
  1572. igb_write_8bit_ctrl_reg(hw, E1000_CCMCTL, 0x10, 0x00);
  1573. /* PCIe lanes configuration */
  1574. igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x00, 0xEC);
  1575. igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x61, 0xDF);
  1576. igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x34, 0x05);
  1577. igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x2F, 0x81);
  1578. /* PCIe PLL Configuration */
  1579. igb_write_8bit_ctrl_reg(hw, E1000_SCCTL, 0x02, 0x47);
  1580. igb_write_8bit_ctrl_reg(hw, E1000_SCCTL, 0x14, 0x00);
  1581. igb_write_8bit_ctrl_reg(hw, E1000_SCCTL, 0x10, 0x00);
  1582. }
  1583. return 0;
  1584. }
  1585. /**
  1586. * igb_read_mac_addr_82575 - Read device MAC address
  1587. * @hw: pointer to the HW structure
  1588. **/
  1589. static s32 igb_read_mac_addr_82575(struct e1000_hw *hw)
  1590. {
  1591. s32 ret_val = 0;
  1592. /* If there's an alternate MAC address place it in RAR0
  1593. * so that it will override the Si installed default perm
  1594. * address.
  1595. */
  1596. ret_val = igb_check_alt_mac_addr(hw);
  1597. if (ret_val)
  1598. goto out;
  1599. ret_val = igb_read_mac_addr(hw);
  1600. out:
  1601. return ret_val;
  1602. }
  1603. /**
  1604. * igb_power_down_phy_copper_82575 - Remove link during PHY power down
  1605. * @hw: pointer to the HW structure
  1606. *
  1607. * In the case of a PHY power down to save power, or to turn off link during a
  1608. * driver unload, or wake on lan is not enabled, remove the link.
  1609. **/
  1610. void igb_power_down_phy_copper_82575(struct e1000_hw *hw)
  1611. {
  1612. /* If the management interface is not enabled, then power down */
  1613. if (!(igb_enable_mng_pass_thru(hw) || igb_check_reset_block(hw)))
  1614. igb_power_down_phy_copper(hw);
  1615. }
  1616. /**
  1617. * igb_clear_hw_cntrs_82575 - Clear device specific hardware counters
  1618. * @hw: pointer to the HW structure
  1619. *
  1620. * Clears the hardware counters by reading the counter registers.
  1621. **/
  1622. static void igb_clear_hw_cntrs_82575(struct e1000_hw *hw)
  1623. {
  1624. igb_clear_hw_cntrs_base(hw);
  1625. rd32(E1000_PRC64);
  1626. rd32(E1000_PRC127);
  1627. rd32(E1000_PRC255);
  1628. rd32(E1000_PRC511);
  1629. rd32(E1000_PRC1023);
  1630. rd32(E1000_PRC1522);
  1631. rd32(E1000_PTC64);
  1632. rd32(E1000_PTC127);
  1633. rd32(E1000_PTC255);
  1634. rd32(E1000_PTC511);
  1635. rd32(E1000_PTC1023);
  1636. rd32(E1000_PTC1522);
  1637. rd32(E1000_ALGNERRC);
  1638. rd32(E1000_RXERRC);
  1639. rd32(E1000_TNCRS);
  1640. rd32(E1000_CEXTERR);
  1641. rd32(E1000_TSCTC);
  1642. rd32(E1000_TSCTFC);
  1643. rd32(E1000_MGTPRC);
  1644. rd32(E1000_MGTPDC);
  1645. rd32(E1000_MGTPTC);
  1646. rd32(E1000_IAC);
  1647. rd32(E1000_ICRXOC);
  1648. rd32(E1000_ICRXPTC);
  1649. rd32(E1000_ICRXATC);
  1650. rd32(E1000_ICTXPTC);
  1651. rd32(E1000_ICTXATC);
  1652. rd32(E1000_ICTXQEC);
  1653. rd32(E1000_ICTXQMTC);
  1654. rd32(E1000_ICRXDMTC);
  1655. rd32(E1000_CBTMPC);
  1656. rd32(E1000_HTDPMC);
  1657. rd32(E1000_CBRMPC);
  1658. rd32(E1000_RPTHC);
  1659. rd32(E1000_HGPTC);
  1660. rd32(E1000_HTCBDPC);
  1661. rd32(E1000_HGORCL);
  1662. rd32(E1000_HGORCH);
  1663. rd32(E1000_HGOTCL);
  1664. rd32(E1000_HGOTCH);
  1665. rd32(E1000_LENERRS);
  1666. /* This register should not be read in copper configurations */
  1667. if (hw->phy.media_type == e1000_media_type_internal_serdes ||
  1668. igb_sgmii_active_82575(hw))
  1669. rd32(E1000_SCVPC);
  1670. }
  1671. /**
  1672. * igb_rx_fifo_flush_82575 - Clean rx fifo after RX enable
  1673. * @hw: pointer to the HW structure
  1674. *
  1675. * After rx enable if manageability is enabled then there is likely some
  1676. * bad data at the start of the fifo and possibly in the DMA fifo. This
  1677. * function clears the fifos and flushes any packets that came in as rx was
  1678. * being enabled.
  1679. **/
  1680. void igb_rx_fifo_flush_82575(struct e1000_hw *hw)
  1681. {
  1682. u32 rctl, rlpml, rxdctl[4], rfctl, temp_rctl, rx_enabled;
  1683. int i, ms_wait;
  1684. /* disable IPv6 options as per hardware errata */
  1685. rfctl = rd32(E1000_RFCTL);
  1686. rfctl |= E1000_RFCTL_IPV6_EX_DIS;
  1687. wr32(E1000_RFCTL, rfctl);
  1688. if (hw->mac.type != e1000_82575 ||
  1689. !(rd32(E1000_MANC) & E1000_MANC_RCV_TCO_EN))
  1690. return;
  1691. /* Disable all RX queues */
  1692. for (i = 0; i < 4; i++) {
  1693. rxdctl[i] = rd32(E1000_RXDCTL(i));
  1694. wr32(E1000_RXDCTL(i),
  1695. rxdctl[i] & ~E1000_RXDCTL_QUEUE_ENABLE);
  1696. }
  1697. /* Poll all queues to verify they have shut down */
  1698. for (ms_wait = 0; ms_wait < 10; ms_wait++) {
  1699. usleep_range(1000, 2000);
  1700. rx_enabled = 0;
  1701. for (i = 0; i < 4; i++)
  1702. rx_enabled |= rd32(E1000_RXDCTL(i));
  1703. if (!(rx_enabled & E1000_RXDCTL_QUEUE_ENABLE))
  1704. break;
  1705. }
  1706. if (ms_wait == 10)
  1707. hw_dbg("Queue disable timed out after 10ms\n");
  1708. /* Clear RLPML, RCTL.SBP, RFCTL.LEF, and set RCTL.LPE so that all
  1709. * incoming packets are rejected. Set enable and wait 2ms so that
  1710. * any packet that was coming in as RCTL.EN was set is flushed
  1711. */
  1712. wr32(E1000_RFCTL, rfctl & ~E1000_RFCTL_LEF);
  1713. rlpml = rd32(E1000_RLPML);
  1714. wr32(E1000_RLPML, 0);
  1715. rctl = rd32(E1000_RCTL);
  1716. temp_rctl = rctl & ~(E1000_RCTL_EN | E1000_RCTL_SBP);
  1717. temp_rctl |= E1000_RCTL_LPE;
  1718. wr32(E1000_RCTL, temp_rctl);
  1719. wr32(E1000_RCTL, temp_rctl | E1000_RCTL_EN);
  1720. wrfl();
  1721. usleep_range(2000, 3000);
  1722. /* Enable RX queues that were previously enabled and restore our
  1723. * previous state
  1724. */
  1725. for (i = 0; i < 4; i++)
  1726. wr32(E1000_RXDCTL(i), rxdctl[i]);
  1727. wr32(E1000_RCTL, rctl);
  1728. wrfl();
  1729. wr32(E1000_RLPML, rlpml);
  1730. wr32(E1000_RFCTL, rfctl);
  1731. /* Flush receive errors generated by workaround */
  1732. rd32(E1000_ROC);
  1733. rd32(E1000_RNBC);
  1734. rd32(E1000_MPC);
  1735. }
  1736. /**
  1737. * igb_set_pcie_completion_timeout - set pci-e completion timeout
  1738. * @hw: pointer to the HW structure
  1739. *
  1740. * The defaults for 82575 and 82576 should be in the range of 50us to 50ms,
  1741. * however the hardware default for these parts is 500us to 1ms which is less
  1742. * than the 10ms recommended by the pci-e spec. To address this we need to
  1743. * increase the value to either 10ms to 200ms for capability version 1 config,
  1744. * or 16ms to 55ms for version 2.
  1745. **/
  1746. static s32 igb_set_pcie_completion_timeout(struct e1000_hw *hw)
  1747. {
  1748. u32 gcr = rd32(E1000_GCR);
  1749. s32 ret_val = 0;
  1750. u16 pcie_devctl2;
  1751. /* only take action if timeout value is defaulted to 0 */
  1752. if (gcr & E1000_GCR_CMPL_TMOUT_MASK)
  1753. goto out;
  1754. /* if capabilities version is type 1 we can write the
  1755. * timeout of 10ms to 200ms through the GCR register
  1756. */
  1757. if (!(gcr & E1000_GCR_CAP_VER2)) {
  1758. gcr |= E1000_GCR_CMPL_TMOUT_10ms;
  1759. goto out;
  1760. }
  1761. /* for version 2 capabilities we need to write the config space
  1762. * directly in order to set the completion timeout value for
  1763. * 16ms to 55ms
  1764. */
  1765. ret_val = igb_read_pcie_cap_reg(hw, PCIE_DEVICE_CONTROL2,
  1766. &pcie_devctl2);
  1767. if (ret_val)
  1768. goto out;
  1769. pcie_devctl2 |= PCIE_DEVICE_CONTROL2_16ms;
  1770. ret_val = igb_write_pcie_cap_reg(hw, PCIE_DEVICE_CONTROL2,
  1771. &pcie_devctl2);
  1772. out:
  1773. /* disable completion timeout resend */
  1774. gcr &= ~E1000_GCR_CMPL_TMOUT_RESEND;
  1775. wr32(E1000_GCR, gcr);
  1776. return ret_val;
  1777. }
  1778. /**
  1779. * igb_vmdq_set_anti_spoofing_pf - enable or disable anti-spoofing
  1780. * @hw: pointer to the hardware struct
  1781. * @enable: state to enter, either enabled or disabled
  1782. * @pf: Physical Function pool - do not set anti-spoofing for the PF
  1783. *
  1784. * enables/disables L2 switch anti-spoofing functionality.
  1785. **/
  1786. void igb_vmdq_set_anti_spoofing_pf(struct e1000_hw *hw, bool enable, int pf)
  1787. {
  1788. u32 reg_val, reg_offset;
  1789. switch (hw->mac.type) {
  1790. case e1000_82576:
  1791. reg_offset = E1000_DTXSWC;
  1792. break;
  1793. case e1000_i350:
  1794. case e1000_i354:
  1795. reg_offset = E1000_TXSWC;
  1796. break;
  1797. default:
  1798. return;
  1799. }
  1800. reg_val = rd32(reg_offset);
  1801. if (enable) {
  1802. reg_val |= (E1000_DTXSWC_MAC_SPOOF_MASK |
  1803. E1000_DTXSWC_VLAN_SPOOF_MASK);
  1804. /* The PF can spoof - it has to in order to
  1805. * support emulation mode NICs
  1806. */
  1807. reg_val ^= (1 << pf | 1 << (pf + MAX_NUM_VFS));
  1808. } else {
  1809. reg_val &= ~(E1000_DTXSWC_MAC_SPOOF_MASK |
  1810. E1000_DTXSWC_VLAN_SPOOF_MASK);
  1811. }
  1812. wr32(reg_offset, reg_val);
  1813. }
  1814. /**
  1815. * igb_vmdq_set_loopback_pf - enable or disable vmdq loopback
  1816. * @hw: pointer to the hardware struct
  1817. * @enable: state to enter, either enabled or disabled
  1818. *
  1819. * enables/disables L2 switch loopback functionality.
  1820. **/
  1821. void igb_vmdq_set_loopback_pf(struct e1000_hw *hw, bool enable)
  1822. {
  1823. u32 dtxswc;
  1824. switch (hw->mac.type) {
  1825. case e1000_82576:
  1826. dtxswc = rd32(E1000_DTXSWC);
  1827. if (enable)
  1828. dtxswc |= E1000_DTXSWC_VMDQ_LOOPBACK_EN;
  1829. else
  1830. dtxswc &= ~E1000_DTXSWC_VMDQ_LOOPBACK_EN;
  1831. wr32(E1000_DTXSWC, dtxswc);
  1832. break;
  1833. case e1000_i354:
  1834. case e1000_i350:
  1835. dtxswc = rd32(E1000_TXSWC);
  1836. if (enable)
  1837. dtxswc |= E1000_DTXSWC_VMDQ_LOOPBACK_EN;
  1838. else
  1839. dtxswc &= ~E1000_DTXSWC_VMDQ_LOOPBACK_EN;
  1840. wr32(E1000_TXSWC, dtxswc);
  1841. break;
  1842. default:
  1843. /* Currently no other hardware supports loopback */
  1844. break;
  1845. }
  1846. }
  1847. /**
  1848. * igb_vmdq_set_replication_pf - enable or disable vmdq replication
  1849. * @hw: pointer to the hardware struct
  1850. * @enable: state to enter, either enabled or disabled
  1851. *
  1852. * enables/disables replication of packets across multiple pools.
  1853. **/
  1854. void igb_vmdq_set_replication_pf(struct e1000_hw *hw, bool enable)
  1855. {
  1856. u32 vt_ctl = rd32(E1000_VT_CTL);
  1857. if (enable)
  1858. vt_ctl |= E1000_VT_CTL_VM_REPL_EN;
  1859. else
  1860. vt_ctl &= ~E1000_VT_CTL_VM_REPL_EN;
  1861. wr32(E1000_VT_CTL, vt_ctl);
  1862. }
  1863. /**
  1864. * igb_read_phy_reg_82580 - Read 82580 MDI control register
  1865. * @hw: pointer to the HW structure
  1866. * @offset: register offset to be read
  1867. * @data: pointer to the read data
  1868. *
  1869. * Reads the MDI control register in the PHY at offset and stores the
  1870. * information read to data.
  1871. **/
  1872. static s32 igb_read_phy_reg_82580(struct e1000_hw *hw, u32 offset, u16 *data)
  1873. {
  1874. s32 ret_val;
  1875. ret_val = hw->phy.ops.acquire(hw);
  1876. if (ret_val)
  1877. goto out;
  1878. ret_val = igb_read_phy_reg_mdic(hw, offset, data);
  1879. hw->phy.ops.release(hw);
  1880. out:
  1881. return ret_val;
  1882. }
  1883. /**
  1884. * igb_write_phy_reg_82580 - Write 82580 MDI control register
  1885. * @hw: pointer to the HW structure
  1886. * @offset: register offset to write to
  1887. * @data: data to write to register at offset
  1888. *
  1889. * Writes data to MDI control register in the PHY at offset.
  1890. **/
  1891. static s32 igb_write_phy_reg_82580(struct e1000_hw *hw, u32 offset, u16 data)
  1892. {
  1893. s32 ret_val;
  1894. ret_val = hw->phy.ops.acquire(hw);
  1895. if (ret_val)
  1896. goto out;
  1897. ret_val = igb_write_phy_reg_mdic(hw, offset, data);
  1898. hw->phy.ops.release(hw);
  1899. out:
  1900. return ret_val;
  1901. }
  1902. /**
  1903. * igb_reset_mdicnfg_82580 - Reset MDICNFG destination and com_mdio bits
  1904. * @hw: pointer to the HW structure
  1905. *
  1906. * This resets the the MDICNFG.Destination and MDICNFG.Com_MDIO bits based on
  1907. * the values found in the EEPROM. This addresses an issue in which these
  1908. * bits are not restored from EEPROM after reset.
  1909. **/
  1910. static s32 igb_reset_mdicnfg_82580(struct e1000_hw *hw)
  1911. {
  1912. s32 ret_val = 0;
  1913. u32 mdicnfg;
  1914. u16 nvm_data = 0;
  1915. if (hw->mac.type != e1000_82580)
  1916. goto out;
  1917. if (!igb_sgmii_active_82575(hw))
  1918. goto out;
  1919. ret_val = hw->nvm.ops.read(hw, NVM_INIT_CONTROL3_PORT_A +
  1920. NVM_82580_LAN_FUNC_OFFSET(hw->bus.func), 1,
  1921. &nvm_data);
  1922. if (ret_val) {
  1923. hw_dbg("NVM Read Error\n");
  1924. goto out;
  1925. }
  1926. mdicnfg = rd32(E1000_MDICNFG);
  1927. if (nvm_data & NVM_WORD24_EXT_MDIO)
  1928. mdicnfg |= E1000_MDICNFG_EXT_MDIO;
  1929. if (nvm_data & NVM_WORD24_COM_MDIO)
  1930. mdicnfg |= E1000_MDICNFG_COM_MDIO;
  1931. wr32(E1000_MDICNFG, mdicnfg);
  1932. out:
  1933. return ret_val;
  1934. }
  1935. /**
  1936. * igb_reset_hw_82580 - Reset hardware
  1937. * @hw: pointer to the HW structure
  1938. *
  1939. * This resets function or entire device (all ports, etc.)
  1940. * to a known state.
  1941. **/
  1942. static s32 igb_reset_hw_82580(struct e1000_hw *hw)
  1943. {
  1944. s32 ret_val = 0;
  1945. /* BH SW mailbox bit in SW_FW_SYNC */
  1946. u16 swmbsw_mask = E1000_SW_SYNCH_MB;
  1947. u32 ctrl;
  1948. bool global_device_reset = hw->dev_spec._82575.global_device_reset;
  1949. hw->dev_spec._82575.global_device_reset = false;
  1950. /* due to hw errata, global device reset doesn't always
  1951. * work on 82580
  1952. */
  1953. if (hw->mac.type == e1000_82580)
  1954. global_device_reset = false;
  1955. /* Get current control state. */
  1956. ctrl = rd32(E1000_CTRL);
  1957. /* Prevent the PCI-E bus from sticking if there is no TLP connection
  1958. * on the last TLP read/write transaction when MAC is reset.
  1959. */
  1960. ret_val = igb_disable_pcie_master(hw);
  1961. if (ret_val)
  1962. hw_dbg("PCI-E Master disable polling has failed.\n");
  1963. hw_dbg("Masking off all interrupts\n");
  1964. wr32(E1000_IMC, 0xffffffff);
  1965. wr32(E1000_RCTL, 0);
  1966. wr32(E1000_TCTL, E1000_TCTL_PSP);
  1967. wrfl();
  1968. usleep_range(10000, 11000);
  1969. /* Determine whether or not a global dev reset is requested */
  1970. if (global_device_reset &&
  1971. hw->mac.ops.acquire_swfw_sync(hw, swmbsw_mask))
  1972. global_device_reset = false;
  1973. if (global_device_reset &&
  1974. !(rd32(E1000_STATUS) & E1000_STAT_DEV_RST_SET))
  1975. ctrl |= E1000_CTRL_DEV_RST;
  1976. else
  1977. ctrl |= E1000_CTRL_RST;
  1978. wr32(E1000_CTRL, ctrl);
  1979. wrfl();
  1980. /* Add delay to insure DEV_RST has time to complete */
  1981. if (global_device_reset)
  1982. usleep_range(5000, 6000);
  1983. ret_val = igb_get_auto_rd_done(hw);
  1984. if (ret_val) {
  1985. /* When auto config read does not complete, do not
  1986. * return with an error. This can happen in situations
  1987. * where there is no eeprom and prevents getting link.
  1988. */
  1989. hw_dbg("Auto Read Done did not complete\n");
  1990. }
  1991. /* clear global device reset status bit */
  1992. wr32(E1000_STATUS, E1000_STAT_DEV_RST_SET);
  1993. /* Clear any pending interrupt events. */
  1994. wr32(E1000_IMC, 0xffffffff);
  1995. rd32(E1000_ICR);
  1996. ret_val = igb_reset_mdicnfg_82580(hw);
  1997. if (ret_val)
  1998. hw_dbg("Could not reset MDICNFG based on EEPROM\n");
  1999. /* Install any alternate MAC address into RAR0 */
  2000. ret_val = igb_check_alt_mac_addr(hw);
  2001. /* Release semaphore */
  2002. if (global_device_reset)
  2003. hw->mac.ops.release_swfw_sync(hw, swmbsw_mask);
  2004. return ret_val;
  2005. }
  2006. /**
  2007. * igb_rxpbs_adjust_82580 - adjust RXPBS value to reflect actual RX PBA size
  2008. * @data: data received by reading RXPBS register
  2009. *
  2010. * The 82580 uses a table based approach for packet buffer allocation sizes.
  2011. * This function converts the retrieved value into the correct table value
  2012. * 0x0 0x1 0x2 0x3 0x4 0x5 0x6 0x7
  2013. * 0x0 36 72 144 1 2 4 8 16
  2014. * 0x8 35 70 140 rsv rsv rsv rsv rsv
  2015. */
  2016. u16 igb_rxpbs_adjust_82580(u32 data)
  2017. {
  2018. u16 ret_val = 0;
  2019. if (data < ARRAY_SIZE(e1000_82580_rxpbs_table))
  2020. ret_val = e1000_82580_rxpbs_table[data];
  2021. return ret_val;
  2022. }
  2023. /**
  2024. * igb_validate_nvm_checksum_with_offset - Validate EEPROM
  2025. * checksum
  2026. * @hw: pointer to the HW structure
  2027. * @offset: offset in words of the checksum protected region
  2028. *
  2029. * Calculates the EEPROM checksum by reading/adding each word of the EEPROM
  2030. * and then verifies that the sum of the EEPROM is equal to 0xBABA.
  2031. **/
  2032. static s32 igb_validate_nvm_checksum_with_offset(struct e1000_hw *hw,
  2033. u16 offset)
  2034. {
  2035. s32 ret_val = 0;
  2036. u16 checksum = 0;
  2037. u16 i, nvm_data;
  2038. for (i = offset; i < ((NVM_CHECKSUM_REG + offset) + 1); i++) {
  2039. ret_val = hw->nvm.ops.read(hw, i, 1, &nvm_data);
  2040. if (ret_val) {
  2041. hw_dbg("NVM Read Error\n");
  2042. goto out;
  2043. }
  2044. checksum += nvm_data;
  2045. }
  2046. if (checksum != (u16) NVM_SUM) {
  2047. hw_dbg("NVM Checksum Invalid\n");
  2048. ret_val = -E1000_ERR_NVM;
  2049. goto out;
  2050. }
  2051. out:
  2052. return ret_val;
  2053. }
  2054. /**
  2055. * igb_update_nvm_checksum_with_offset - Update EEPROM
  2056. * checksum
  2057. * @hw: pointer to the HW structure
  2058. * @offset: offset in words of the checksum protected region
  2059. *
  2060. * Updates the EEPROM checksum by reading/adding each word of the EEPROM
  2061. * up to the checksum. Then calculates the EEPROM checksum and writes the
  2062. * value to the EEPROM.
  2063. **/
  2064. static s32 igb_update_nvm_checksum_with_offset(struct e1000_hw *hw, u16 offset)
  2065. {
  2066. s32 ret_val;
  2067. u16 checksum = 0;
  2068. u16 i, nvm_data;
  2069. for (i = offset; i < (NVM_CHECKSUM_REG + offset); i++) {
  2070. ret_val = hw->nvm.ops.read(hw, i, 1, &nvm_data);
  2071. if (ret_val) {
  2072. hw_dbg("NVM Read Error while updating checksum.\n");
  2073. goto out;
  2074. }
  2075. checksum += nvm_data;
  2076. }
  2077. checksum = (u16) NVM_SUM - checksum;
  2078. ret_val = hw->nvm.ops.write(hw, (NVM_CHECKSUM_REG + offset), 1,
  2079. &checksum);
  2080. if (ret_val)
  2081. hw_dbg("NVM Write Error while updating checksum.\n");
  2082. out:
  2083. return ret_val;
  2084. }
  2085. /**
  2086. * igb_validate_nvm_checksum_82580 - Validate EEPROM checksum
  2087. * @hw: pointer to the HW structure
  2088. *
  2089. * Calculates the EEPROM section checksum by reading/adding each word of
  2090. * the EEPROM and then verifies that the sum of the EEPROM is
  2091. * equal to 0xBABA.
  2092. **/
  2093. static s32 igb_validate_nvm_checksum_82580(struct e1000_hw *hw)
  2094. {
  2095. s32 ret_val = 0;
  2096. u16 eeprom_regions_count = 1;
  2097. u16 j, nvm_data;
  2098. u16 nvm_offset;
  2099. ret_val = hw->nvm.ops.read(hw, NVM_COMPATIBILITY_REG_3, 1, &nvm_data);
  2100. if (ret_val) {
  2101. hw_dbg("NVM Read Error\n");
  2102. goto out;
  2103. }
  2104. if (nvm_data & NVM_COMPATIBILITY_BIT_MASK) {
  2105. /* if checksums compatibility bit is set validate checksums
  2106. * for all 4 ports.
  2107. */
  2108. eeprom_regions_count = 4;
  2109. }
  2110. for (j = 0; j < eeprom_regions_count; j++) {
  2111. nvm_offset = NVM_82580_LAN_FUNC_OFFSET(j);
  2112. ret_val = igb_validate_nvm_checksum_with_offset(hw,
  2113. nvm_offset);
  2114. if (ret_val != 0)
  2115. goto out;
  2116. }
  2117. out:
  2118. return ret_val;
  2119. }
  2120. /**
  2121. * igb_update_nvm_checksum_82580 - Update EEPROM checksum
  2122. * @hw: pointer to the HW structure
  2123. *
  2124. * Updates the EEPROM section checksums for all 4 ports by reading/adding
  2125. * each word of the EEPROM up to the checksum. Then calculates the EEPROM
  2126. * checksum and writes the value to the EEPROM.
  2127. **/
  2128. static s32 igb_update_nvm_checksum_82580(struct e1000_hw *hw)
  2129. {
  2130. s32 ret_val;
  2131. u16 j, nvm_data;
  2132. u16 nvm_offset;
  2133. ret_val = hw->nvm.ops.read(hw, NVM_COMPATIBILITY_REG_3, 1, &nvm_data);
  2134. if (ret_val) {
  2135. hw_dbg("NVM Read Error while updating checksum compatibility bit.\n");
  2136. goto out;
  2137. }
  2138. if ((nvm_data & NVM_COMPATIBILITY_BIT_MASK) == 0) {
  2139. /* set compatibility bit to validate checksums appropriately */
  2140. nvm_data = nvm_data | NVM_COMPATIBILITY_BIT_MASK;
  2141. ret_val = hw->nvm.ops.write(hw, NVM_COMPATIBILITY_REG_3, 1,
  2142. &nvm_data);
  2143. if (ret_val) {
  2144. hw_dbg("NVM Write Error while updating checksum compatibility bit.\n");
  2145. goto out;
  2146. }
  2147. }
  2148. for (j = 0; j < 4; j++) {
  2149. nvm_offset = NVM_82580_LAN_FUNC_OFFSET(j);
  2150. ret_val = igb_update_nvm_checksum_with_offset(hw, nvm_offset);
  2151. if (ret_val)
  2152. goto out;
  2153. }
  2154. out:
  2155. return ret_val;
  2156. }
  2157. /**
  2158. * igb_validate_nvm_checksum_i350 - Validate EEPROM checksum
  2159. * @hw: pointer to the HW structure
  2160. *
  2161. * Calculates the EEPROM section checksum by reading/adding each word of
  2162. * the EEPROM and then verifies that the sum of the EEPROM is
  2163. * equal to 0xBABA.
  2164. **/
  2165. static s32 igb_validate_nvm_checksum_i350(struct e1000_hw *hw)
  2166. {
  2167. s32 ret_val = 0;
  2168. u16 j;
  2169. u16 nvm_offset;
  2170. for (j = 0; j < 4; j++) {
  2171. nvm_offset = NVM_82580_LAN_FUNC_OFFSET(j);
  2172. ret_val = igb_validate_nvm_checksum_with_offset(hw,
  2173. nvm_offset);
  2174. if (ret_val != 0)
  2175. goto out;
  2176. }
  2177. out:
  2178. return ret_val;
  2179. }
  2180. /**
  2181. * igb_update_nvm_checksum_i350 - Update EEPROM checksum
  2182. * @hw: pointer to the HW structure
  2183. *
  2184. * Updates the EEPROM section checksums for all 4 ports by reading/adding
  2185. * each word of the EEPROM up to the checksum. Then calculates the EEPROM
  2186. * checksum and writes the value to the EEPROM.
  2187. **/
  2188. static s32 igb_update_nvm_checksum_i350(struct e1000_hw *hw)
  2189. {
  2190. s32 ret_val = 0;
  2191. u16 j;
  2192. u16 nvm_offset;
  2193. for (j = 0; j < 4; j++) {
  2194. nvm_offset = NVM_82580_LAN_FUNC_OFFSET(j);
  2195. ret_val = igb_update_nvm_checksum_with_offset(hw, nvm_offset);
  2196. if (ret_val != 0)
  2197. goto out;
  2198. }
  2199. out:
  2200. return ret_val;
  2201. }
  2202. /**
  2203. * __igb_access_emi_reg - Read/write EMI register
  2204. * @hw: pointer to the HW structure
  2205. * @addr: EMI address to program
  2206. * @data: pointer to value to read/write from/to the EMI address
  2207. * @read: boolean flag to indicate read or write
  2208. **/
  2209. static s32 __igb_access_emi_reg(struct e1000_hw *hw, u16 address,
  2210. u16 *data, bool read)
  2211. {
  2212. s32 ret_val = 0;
  2213. ret_val = hw->phy.ops.write_reg(hw, E1000_EMIADD, address);
  2214. if (ret_val)
  2215. return ret_val;
  2216. if (read)
  2217. ret_val = hw->phy.ops.read_reg(hw, E1000_EMIDATA, data);
  2218. else
  2219. ret_val = hw->phy.ops.write_reg(hw, E1000_EMIDATA, *data);
  2220. return ret_val;
  2221. }
  2222. /**
  2223. * igb_read_emi_reg - Read Extended Management Interface register
  2224. * @hw: pointer to the HW structure
  2225. * @addr: EMI address to program
  2226. * @data: value to be read from the EMI address
  2227. **/
  2228. s32 igb_read_emi_reg(struct e1000_hw *hw, u16 addr, u16 *data)
  2229. {
  2230. return __igb_access_emi_reg(hw, addr, data, true);
  2231. }
  2232. /**
  2233. * igb_set_eee_i350 - Enable/disable EEE support
  2234. * @hw: pointer to the HW structure
  2235. * @adv1G: boolean flag enabling 1G EEE advertisement
  2236. * @adv100m: boolean flag enabling 100M EEE advertisement
  2237. *
  2238. * Enable/disable EEE based on setting in dev_spec structure.
  2239. *
  2240. **/
  2241. s32 igb_set_eee_i350(struct e1000_hw *hw, bool adv1G, bool adv100M)
  2242. {
  2243. u32 ipcnfg, eeer;
  2244. if ((hw->mac.type < e1000_i350) ||
  2245. (hw->phy.media_type != e1000_media_type_copper))
  2246. goto out;
  2247. ipcnfg = rd32(E1000_IPCNFG);
  2248. eeer = rd32(E1000_EEER);
  2249. /* enable or disable per user setting */
  2250. if (!(hw->dev_spec._82575.eee_disable)) {
  2251. u32 eee_su = rd32(E1000_EEE_SU);
  2252. if (adv100M)
  2253. ipcnfg |= E1000_IPCNFG_EEE_100M_AN;
  2254. else
  2255. ipcnfg &= ~E1000_IPCNFG_EEE_100M_AN;
  2256. if (adv1G)
  2257. ipcnfg |= E1000_IPCNFG_EEE_1G_AN;
  2258. else
  2259. ipcnfg &= ~E1000_IPCNFG_EEE_1G_AN;
  2260. eeer |= (E1000_EEER_TX_LPI_EN | E1000_EEER_RX_LPI_EN |
  2261. E1000_EEER_LPI_FC);
  2262. /* This bit should not be set in normal operation. */
  2263. if (eee_su & E1000_EEE_SU_LPI_CLK_STP)
  2264. hw_dbg("LPI Clock Stop Bit should not be set!\n");
  2265. } else {
  2266. ipcnfg &= ~(E1000_IPCNFG_EEE_1G_AN |
  2267. E1000_IPCNFG_EEE_100M_AN);
  2268. eeer &= ~(E1000_EEER_TX_LPI_EN |
  2269. E1000_EEER_RX_LPI_EN |
  2270. E1000_EEER_LPI_FC);
  2271. }
  2272. wr32(E1000_IPCNFG, ipcnfg);
  2273. wr32(E1000_EEER, eeer);
  2274. rd32(E1000_IPCNFG);
  2275. rd32(E1000_EEER);
  2276. out:
  2277. return 0;
  2278. }
  2279. /**
  2280. * igb_set_eee_i354 - Enable/disable EEE support
  2281. * @hw: pointer to the HW structure
  2282. * @adv1G: boolean flag enabling 1G EEE advertisement
  2283. * @adv100m: boolean flag enabling 100M EEE advertisement
  2284. *
  2285. * Enable/disable EEE legacy mode based on setting in dev_spec structure.
  2286. *
  2287. **/
  2288. s32 igb_set_eee_i354(struct e1000_hw *hw, bool adv1G, bool adv100M)
  2289. {
  2290. struct e1000_phy_info *phy = &hw->phy;
  2291. s32 ret_val = 0;
  2292. u16 phy_data;
  2293. if ((hw->phy.media_type != e1000_media_type_copper) ||
  2294. ((phy->id != M88E1543_E_PHY_ID) &&
  2295. (phy->id != M88E1512_E_PHY_ID)))
  2296. goto out;
  2297. if (!hw->dev_spec._82575.eee_disable) {
  2298. /* Switch to PHY page 18. */
  2299. ret_val = phy->ops.write_reg(hw, E1000_M88E1543_PAGE_ADDR, 18);
  2300. if (ret_val)
  2301. goto out;
  2302. ret_val = phy->ops.read_reg(hw, E1000_M88E1543_EEE_CTRL_1,
  2303. &phy_data);
  2304. if (ret_val)
  2305. goto out;
  2306. phy_data |= E1000_M88E1543_EEE_CTRL_1_MS;
  2307. ret_val = phy->ops.write_reg(hw, E1000_M88E1543_EEE_CTRL_1,
  2308. phy_data);
  2309. if (ret_val)
  2310. goto out;
  2311. /* Return the PHY to page 0. */
  2312. ret_val = phy->ops.write_reg(hw, E1000_M88E1543_PAGE_ADDR, 0);
  2313. if (ret_val)
  2314. goto out;
  2315. /* Turn on EEE advertisement. */
  2316. ret_val = igb_read_xmdio_reg(hw, E1000_EEE_ADV_ADDR_I354,
  2317. E1000_EEE_ADV_DEV_I354,
  2318. &phy_data);
  2319. if (ret_val)
  2320. goto out;
  2321. if (adv100M)
  2322. phy_data |= E1000_EEE_ADV_100_SUPPORTED;
  2323. else
  2324. phy_data &= ~E1000_EEE_ADV_100_SUPPORTED;
  2325. if (adv1G)
  2326. phy_data |= E1000_EEE_ADV_1000_SUPPORTED;
  2327. else
  2328. phy_data &= ~E1000_EEE_ADV_1000_SUPPORTED;
  2329. ret_val = igb_write_xmdio_reg(hw, E1000_EEE_ADV_ADDR_I354,
  2330. E1000_EEE_ADV_DEV_I354,
  2331. phy_data);
  2332. } else {
  2333. /* Turn off EEE advertisement. */
  2334. ret_val = igb_read_xmdio_reg(hw, E1000_EEE_ADV_ADDR_I354,
  2335. E1000_EEE_ADV_DEV_I354,
  2336. &phy_data);
  2337. if (ret_val)
  2338. goto out;
  2339. phy_data &= ~(E1000_EEE_ADV_100_SUPPORTED |
  2340. E1000_EEE_ADV_1000_SUPPORTED);
  2341. ret_val = igb_write_xmdio_reg(hw, E1000_EEE_ADV_ADDR_I354,
  2342. E1000_EEE_ADV_DEV_I354,
  2343. phy_data);
  2344. }
  2345. out:
  2346. return ret_val;
  2347. }
  2348. /**
  2349. * igb_get_eee_status_i354 - Get EEE status
  2350. * @hw: pointer to the HW structure
  2351. * @status: EEE status
  2352. *
  2353. * Get EEE status by guessing based on whether Tx or Rx LPI indications have
  2354. * been received.
  2355. **/
  2356. s32 igb_get_eee_status_i354(struct e1000_hw *hw, bool *status)
  2357. {
  2358. struct e1000_phy_info *phy = &hw->phy;
  2359. s32 ret_val = 0;
  2360. u16 phy_data;
  2361. /* Check if EEE is supported on this device. */
  2362. if ((hw->phy.media_type != e1000_media_type_copper) ||
  2363. ((phy->id != M88E1543_E_PHY_ID) &&
  2364. (phy->id != M88E1512_E_PHY_ID)))
  2365. goto out;
  2366. ret_val = igb_read_xmdio_reg(hw, E1000_PCS_STATUS_ADDR_I354,
  2367. E1000_PCS_STATUS_DEV_I354,
  2368. &phy_data);
  2369. if (ret_val)
  2370. goto out;
  2371. *status = phy_data & (E1000_PCS_STATUS_TX_LPI_RCVD |
  2372. E1000_PCS_STATUS_RX_LPI_RCVD) ? true : false;
  2373. out:
  2374. return ret_val;
  2375. }
  2376. static const u8 e1000_emc_temp_data[4] = {
  2377. E1000_EMC_INTERNAL_DATA,
  2378. E1000_EMC_DIODE1_DATA,
  2379. E1000_EMC_DIODE2_DATA,
  2380. E1000_EMC_DIODE3_DATA
  2381. };
  2382. static const u8 e1000_emc_therm_limit[4] = {
  2383. E1000_EMC_INTERNAL_THERM_LIMIT,
  2384. E1000_EMC_DIODE1_THERM_LIMIT,
  2385. E1000_EMC_DIODE2_THERM_LIMIT,
  2386. E1000_EMC_DIODE3_THERM_LIMIT
  2387. };
  2388. #ifdef CONFIG_IGB_HWMON
  2389. /**
  2390. * igb_get_thermal_sensor_data_generic - Gathers thermal sensor data
  2391. * @hw: pointer to hardware structure
  2392. *
  2393. * Updates the temperatures in mac.thermal_sensor_data
  2394. **/
  2395. static s32 igb_get_thermal_sensor_data_generic(struct e1000_hw *hw)
  2396. {
  2397. u16 ets_offset;
  2398. u16 ets_cfg;
  2399. u16 ets_sensor;
  2400. u8 num_sensors;
  2401. u8 sensor_index;
  2402. u8 sensor_location;
  2403. u8 i;
  2404. struct e1000_thermal_sensor_data *data = &hw->mac.thermal_sensor_data;
  2405. if ((hw->mac.type != e1000_i350) || (hw->bus.func != 0))
  2406. return E1000_NOT_IMPLEMENTED;
  2407. data->sensor[0].temp = (rd32(E1000_THMJT) & 0xFF);
  2408. /* Return the internal sensor only if ETS is unsupported */
  2409. hw->nvm.ops.read(hw, NVM_ETS_CFG, 1, &ets_offset);
  2410. if ((ets_offset == 0x0000) || (ets_offset == 0xFFFF))
  2411. return 0;
  2412. hw->nvm.ops.read(hw, ets_offset, 1, &ets_cfg);
  2413. if (((ets_cfg & NVM_ETS_TYPE_MASK) >> NVM_ETS_TYPE_SHIFT)
  2414. != NVM_ETS_TYPE_EMC)
  2415. return E1000_NOT_IMPLEMENTED;
  2416. num_sensors = (ets_cfg & NVM_ETS_NUM_SENSORS_MASK);
  2417. if (num_sensors > E1000_MAX_SENSORS)
  2418. num_sensors = E1000_MAX_SENSORS;
  2419. for (i = 1; i < num_sensors; i++) {
  2420. hw->nvm.ops.read(hw, (ets_offset + i), 1, &ets_sensor);
  2421. sensor_index = ((ets_sensor & NVM_ETS_DATA_INDEX_MASK) >>
  2422. NVM_ETS_DATA_INDEX_SHIFT);
  2423. sensor_location = ((ets_sensor & NVM_ETS_DATA_LOC_MASK) >>
  2424. NVM_ETS_DATA_LOC_SHIFT);
  2425. if (sensor_location != 0)
  2426. hw->phy.ops.read_i2c_byte(hw,
  2427. e1000_emc_temp_data[sensor_index],
  2428. E1000_I2C_THERMAL_SENSOR_ADDR,
  2429. &data->sensor[i].temp);
  2430. }
  2431. return 0;
  2432. }
  2433. /**
  2434. * igb_init_thermal_sensor_thresh_generic - Sets thermal sensor thresholds
  2435. * @hw: pointer to hardware structure
  2436. *
  2437. * Sets the thermal sensor thresholds according to the NVM map
  2438. * and save off the threshold and location values into mac.thermal_sensor_data
  2439. **/
  2440. static s32 igb_init_thermal_sensor_thresh_generic(struct e1000_hw *hw)
  2441. {
  2442. u16 ets_offset;
  2443. u16 ets_cfg;
  2444. u16 ets_sensor;
  2445. u8 low_thresh_delta;
  2446. u8 num_sensors;
  2447. u8 sensor_index;
  2448. u8 sensor_location;
  2449. u8 therm_limit;
  2450. u8 i;
  2451. struct e1000_thermal_sensor_data *data = &hw->mac.thermal_sensor_data;
  2452. if ((hw->mac.type != e1000_i350) || (hw->bus.func != 0))
  2453. return E1000_NOT_IMPLEMENTED;
  2454. memset(data, 0, sizeof(struct e1000_thermal_sensor_data));
  2455. data->sensor[0].location = 0x1;
  2456. data->sensor[0].caution_thresh =
  2457. (rd32(E1000_THHIGHTC) & 0xFF);
  2458. data->sensor[0].max_op_thresh =
  2459. (rd32(E1000_THLOWTC) & 0xFF);
  2460. /* Return the internal sensor only if ETS is unsupported */
  2461. hw->nvm.ops.read(hw, NVM_ETS_CFG, 1, &ets_offset);
  2462. if ((ets_offset == 0x0000) || (ets_offset == 0xFFFF))
  2463. return 0;
  2464. hw->nvm.ops.read(hw, ets_offset, 1, &ets_cfg);
  2465. if (((ets_cfg & NVM_ETS_TYPE_MASK) >> NVM_ETS_TYPE_SHIFT)
  2466. != NVM_ETS_TYPE_EMC)
  2467. return E1000_NOT_IMPLEMENTED;
  2468. low_thresh_delta = ((ets_cfg & NVM_ETS_LTHRES_DELTA_MASK) >>
  2469. NVM_ETS_LTHRES_DELTA_SHIFT);
  2470. num_sensors = (ets_cfg & NVM_ETS_NUM_SENSORS_MASK);
  2471. for (i = 1; i <= num_sensors; i++) {
  2472. hw->nvm.ops.read(hw, (ets_offset + i), 1, &ets_sensor);
  2473. sensor_index = ((ets_sensor & NVM_ETS_DATA_INDEX_MASK) >>
  2474. NVM_ETS_DATA_INDEX_SHIFT);
  2475. sensor_location = ((ets_sensor & NVM_ETS_DATA_LOC_MASK) >>
  2476. NVM_ETS_DATA_LOC_SHIFT);
  2477. therm_limit = ets_sensor & NVM_ETS_DATA_HTHRESH_MASK;
  2478. hw->phy.ops.write_i2c_byte(hw,
  2479. e1000_emc_therm_limit[sensor_index],
  2480. E1000_I2C_THERMAL_SENSOR_ADDR,
  2481. therm_limit);
  2482. if ((i < E1000_MAX_SENSORS) && (sensor_location != 0)) {
  2483. data->sensor[i].location = sensor_location;
  2484. data->sensor[i].caution_thresh = therm_limit;
  2485. data->sensor[i].max_op_thresh = therm_limit -
  2486. low_thresh_delta;
  2487. }
  2488. }
  2489. return 0;
  2490. }
  2491. #endif
  2492. static struct e1000_mac_operations e1000_mac_ops_82575 = {
  2493. .init_hw = igb_init_hw_82575,
  2494. .check_for_link = igb_check_for_link_82575,
  2495. .rar_set = igb_rar_set,
  2496. .read_mac_addr = igb_read_mac_addr_82575,
  2497. .get_speed_and_duplex = igb_get_link_up_info_82575,
  2498. #ifdef CONFIG_IGB_HWMON
  2499. .get_thermal_sensor_data = igb_get_thermal_sensor_data_generic,
  2500. .init_thermal_sensor_thresh = igb_init_thermal_sensor_thresh_generic,
  2501. #endif
  2502. };
  2503. static struct e1000_phy_operations e1000_phy_ops_82575 = {
  2504. .acquire = igb_acquire_phy_82575,
  2505. .get_cfg_done = igb_get_cfg_done_82575,
  2506. .release = igb_release_phy_82575,
  2507. .write_i2c_byte = igb_write_i2c_byte,
  2508. .read_i2c_byte = igb_read_i2c_byte,
  2509. };
  2510. static struct e1000_nvm_operations e1000_nvm_ops_82575 = {
  2511. .acquire = igb_acquire_nvm_82575,
  2512. .read = igb_read_nvm_eerd,
  2513. .release = igb_release_nvm_82575,
  2514. .write = igb_write_nvm_spi,
  2515. };
  2516. const struct e1000_info e1000_82575_info = {
  2517. .get_invariants = igb_get_invariants_82575,
  2518. .mac_ops = &e1000_mac_ops_82575,
  2519. .phy_ops = &e1000_phy_ops_82575,
  2520. .nvm_ops = &e1000_nvm_ops_82575,
  2521. };