e1000_82575.c 79 KB

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