e1000_82575.c 73 KB

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