ixgbe_common.c 103 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825
  1. /*******************************************************************************
  2. Intel 10 Gigabit PCI Express Linux driver
  3. Copyright(c) 1999 - 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. #include <linux/pci.h>
  21. #include <linux/delay.h>
  22. #include <linux/sched.h>
  23. #include <linux/netdevice.h>
  24. #include "ixgbe.h"
  25. #include "ixgbe_common.h"
  26. #include "ixgbe_phy.h"
  27. static s32 ixgbe_acquire_eeprom(struct ixgbe_hw *hw);
  28. static s32 ixgbe_get_eeprom_semaphore(struct ixgbe_hw *hw);
  29. static void ixgbe_release_eeprom_semaphore(struct ixgbe_hw *hw);
  30. static s32 ixgbe_ready_eeprom(struct ixgbe_hw *hw);
  31. static void ixgbe_standby_eeprom(struct ixgbe_hw *hw);
  32. static void ixgbe_shift_out_eeprom_bits(struct ixgbe_hw *hw, u16 data,
  33. u16 count);
  34. static u16 ixgbe_shift_in_eeprom_bits(struct ixgbe_hw *hw, u16 count);
  35. static void ixgbe_raise_eeprom_clk(struct ixgbe_hw *hw, u32 *eec);
  36. static void ixgbe_lower_eeprom_clk(struct ixgbe_hw *hw, u32 *eec);
  37. static void ixgbe_release_eeprom(struct ixgbe_hw *hw);
  38. static s32 ixgbe_mta_vector(struct ixgbe_hw *hw, u8 *mc_addr);
  39. static s32 ixgbe_poll_eerd_eewr_done(struct ixgbe_hw *hw, u32 ee_reg);
  40. static s32 ixgbe_read_eeprom_buffer_bit_bang(struct ixgbe_hw *hw, u16 offset,
  41. u16 words, u16 *data);
  42. static s32 ixgbe_write_eeprom_buffer_bit_bang(struct ixgbe_hw *hw, u16 offset,
  43. u16 words, u16 *data);
  44. static s32 ixgbe_detect_eeprom_page_size_generic(struct ixgbe_hw *hw,
  45. u16 offset);
  46. static s32 ixgbe_disable_pcie_master(struct ixgbe_hw *hw);
  47. /**
  48. * ixgbe_device_supports_autoneg_fc - Check if phy supports autoneg flow
  49. * control
  50. * @hw: pointer to hardware structure
  51. *
  52. * There are several phys that do not support autoneg flow control. This
  53. * function check the device id to see if the associated phy supports
  54. * autoneg flow control.
  55. **/
  56. bool ixgbe_device_supports_autoneg_fc(struct ixgbe_hw *hw)
  57. {
  58. bool supported = false;
  59. ixgbe_link_speed speed;
  60. bool link_up;
  61. switch (hw->phy.media_type) {
  62. case ixgbe_media_type_fiber_fixed:
  63. case ixgbe_media_type_fiber:
  64. hw->mac.ops.check_link(hw, &speed, &link_up, false);
  65. /* if link is down, assume supported */
  66. if (link_up)
  67. supported = speed == IXGBE_LINK_SPEED_1GB_FULL ?
  68. true : false;
  69. else
  70. supported = true;
  71. break;
  72. case ixgbe_media_type_backplane:
  73. supported = true;
  74. break;
  75. case ixgbe_media_type_copper:
  76. /* only some copper devices support flow control autoneg */
  77. switch (hw->device_id) {
  78. case IXGBE_DEV_ID_82599_T3_LOM:
  79. case IXGBE_DEV_ID_X540T:
  80. case IXGBE_DEV_ID_X540T1:
  81. supported = true;
  82. break;
  83. default:
  84. break;
  85. }
  86. default:
  87. break;
  88. }
  89. return supported;
  90. }
  91. /**
  92. * ixgbe_setup_fc - Set up flow control
  93. * @hw: pointer to hardware structure
  94. *
  95. * Called at init time to set up flow control.
  96. **/
  97. static s32 ixgbe_setup_fc(struct ixgbe_hw *hw)
  98. {
  99. s32 ret_val = 0;
  100. u32 reg = 0, reg_bp = 0;
  101. u16 reg_cu = 0;
  102. bool got_lock = false;
  103. /*
  104. * Validate the requested mode. Strict IEEE mode does not allow
  105. * ixgbe_fc_rx_pause because it will cause us to fail at UNH.
  106. */
  107. if (hw->fc.strict_ieee && hw->fc.requested_mode == ixgbe_fc_rx_pause) {
  108. hw_dbg(hw, "ixgbe_fc_rx_pause not valid in strict IEEE mode\n");
  109. ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
  110. goto out;
  111. }
  112. /*
  113. * 10gig parts do not have a word in the EEPROM to determine the
  114. * default flow control setting, so we explicitly set it to full.
  115. */
  116. if (hw->fc.requested_mode == ixgbe_fc_default)
  117. hw->fc.requested_mode = ixgbe_fc_full;
  118. /*
  119. * Set up the 1G and 10G flow control advertisement registers so the
  120. * HW will be able to do fc autoneg once the cable is plugged in. If
  121. * we link at 10G, the 1G advertisement is harmless and vice versa.
  122. */
  123. switch (hw->phy.media_type) {
  124. case ixgbe_media_type_fiber_fixed:
  125. case ixgbe_media_type_fiber:
  126. case ixgbe_media_type_backplane:
  127. reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANA);
  128. reg_bp = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  129. break;
  130. case ixgbe_media_type_copper:
  131. hw->phy.ops.read_reg(hw, MDIO_AN_ADVERTISE,
  132. MDIO_MMD_AN, &reg_cu);
  133. break;
  134. default:
  135. break;
  136. }
  137. /*
  138. * The possible values of fc.requested_mode are:
  139. * 0: Flow control is completely disabled
  140. * 1: Rx flow control is enabled (we can receive pause frames,
  141. * but not send pause frames).
  142. * 2: Tx flow control is enabled (we can send pause frames but
  143. * we do not support receiving pause frames).
  144. * 3: Both Rx and Tx flow control (symmetric) are enabled.
  145. * other: Invalid.
  146. */
  147. switch (hw->fc.requested_mode) {
  148. case ixgbe_fc_none:
  149. /* Flow control completely disabled by software override. */
  150. reg &= ~(IXGBE_PCS1GANA_SYM_PAUSE | IXGBE_PCS1GANA_ASM_PAUSE);
  151. if (hw->phy.media_type == ixgbe_media_type_backplane)
  152. reg_bp &= ~(IXGBE_AUTOC_SYM_PAUSE |
  153. IXGBE_AUTOC_ASM_PAUSE);
  154. else if (hw->phy.media_type == ixgbe_media_type_copper)
  155. reg_cu &= ~(IXGBE_TAF_SYM_PAUSE | IXGBE_TAF_ASM_PAUSE);
  156. break;
  157. case ixgbe_fc_tx_pause:
  158. /*
  159. * Tx Flow control is enabled, and Rx Flow control is
  160. * disabled by software override.
  161. */
  162. reg |= IXGBE_PCS1GANA_ASM_PAUSE;
  163. reg &= ~IXGBE_PCS1GANA_SYM_PAUSE;
  164. if (hw->phy.media_type == ixgbe_media_type_backplane) {
  165. reg_bp |= IXGBE_AUTOC_ASM_PAUSE;
  166. reg_bp &= ~IXGBE_AUTOC_SYM_PAUSE;
  167. } else if (hw->phy.media_type == ixgbe_media_type_copper) {
  168. reg_cu |= IXGBE_TAF_ASM_PAUSE;
  169. reg_cu &= ~IXGBE_TAF_SYM_PAUSE;
  170. }
  171. break;
  172. case ixgbe_fc_rx_pause:
  173. /*
  174. * Rx Flow control is enabled and Tx Flow control is
  175. * disabled by software override. Since there really
  176. * isn't a way to advertise that we are capable of RX
  177. * Pause ONLY, we will advertise that we support both
  178. * symmetric and asymmetric Rx PAUSE, as such we fall
  179. * through to the fc_full statement. Later, we will
  180. * disable the adapter's ability to send PAUSE frames.
  181. */
  182. case ixgbe_fc_full:
  183. /* Flow control (both Rx and Tx) is enabled by SW override. */
  184. reg |= IXGBE_PCS1GANA_SYM_PAUSE | IXGBE_PCS1GANA_ASM_PAUSE;
  185. if (hw->phy.media_type == ixgbe_media_type_backplane)
  186. reg_bp |= IXGBE_AUTOC_SYM_PAUSE |
  187. IXGBE_AUTOC_ASM_PAUSE;
  188. else if (hw->phy.media_type == ixgbe_media_type_copper)
  189. reg_cu |= IXGBE_TAF_SYM_PAUSE | IXGBE_TAF_ASM_PAUSE;
  190. break;
  191. default:
  192. hw_dbg(hw, "Flow control param set incorrectly\n");
  193. ret_val = IXGBE_ERR_CONFIG;
  194. goto out;
  195. break;
  196. }
  197. if (hw->mac.type != ixgbe_mac_X540) {
  198. /*
  199. * Enable auto-negotiation between the MAC & PHY;
  200. * the MAC will advertise clause 37 flow control.
  201. */
  202. IXGBE_WRITE_REG(hw, IXGBE_PCS1GANA, reg);
  203. reg = IXGBE_READ_REG(hw, IXGBE_PCS1GLCTL);
  204. /* Disable AN timeout */
  205. if (hw->fc.strict_ieee)
  206. reg &= ~IXGBE_PCS1GLCTL_AN_1G_TIMEOUT_EN;
  207. IXGBE_WRITE_REG(hw, IXGBE_PCS1GLCTL, reg);
  208. hw_dbg(hw, "Set up FC; PCS1GLCTL = 0x%08X\n", reg);
  209. }
  210. /*
  211. * AUTOC restart handles negotiation of 1G and 10G on backplane
  212. * and copper. There is no need to set the PCS1GCTL register.
  213. *
  214. */
  215. if (hw->phy.media_type == ixgbe_media_type_backplane) {
  216. /* Need the SW/FW semaphore around AUTOC writes if 82599 and
  217. * LESM is on, likewise reset_pipeline requries the lock as
  218. * it also writes AUTOC.
  219. */
  220. if ((hw->mac.type == ixgbe_mac_82599EB) &&
  221. ixgbe_verify_lesm_fw_enabled_82599(hw)) {
  222. ret_val = hw->mac.ops.acquire_swfw_sync(hw,
  223. IXGBE_GSSR_MAC_CSR_SM);
  224. if (ret_val)
  225. goto out;
  226. got_lock = true;
  227. }
  228. IXGBE_WRITE_REG(hw, IXGBE_AUTOC, reg_bp);
  229. if (hw->mac.type == ixgbe_mac_82599EB)
  230. ixgbe_reset_pipeline_82599(hw);
  231. if (got_lock)
  232. hw->mac.ops.release_swfw_sync(hw,
  233. IXGBE_GSSR_MAC_CSR_SM);
  234. } else if ((hw->phy.media_type == ixgbe_media_type_copper) &&
  235. ixgbe_device_supports_autoneg_fc(hw)) {
  236. hw->phy.ops.write_reg(hw, MDIO_AN_ADVERTISE,
  237. MDIO_MMD_AN, reg_cu);
  238. }
  239. hw_dbg(hw, "Set up FC; IXGBE_AUTOC = 0x%08X\n", reg);
  240. out:
  241. return ret_val;
  242. }
  243. /**
  244. * ixgbe_start_hw_generic - Prepare hardware for Tx/Rx
  245. * @hw: pointer to hardware structure
  246. *
  247. * Starts the hardware by filling the bus info structure and media type, clears
  248. * all on chip counters, initializes receive address registers, multicast
  249. * table, VLAN filter table, calls routine to set up link and flow control
  250. * settings, and leaves transmit and receive units disabled and uninitialized
  251. **/
  252. s32 ixgbe_start_hw_generic(struct ixgbe_hw *hw)
  253. {
  254. u32 ctrl_ext;
  255. /* Set the media type */
  256. hw->phy.media_type = hw->mac.ops.get_media_type(hw);
  257. /* Identify the PHY */
  258. hw->phy.ops.identify(hw);
  259. /* Clear the VLAN filter table */
  260. hw->mac.ops.clear_vfta(hw);
  261. /* Clear statistics registers */
  262. hw->mac.ops.clear_hw_cntrs(hw);
  263. /* Set No Snoop Disable */
  264. ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
  265. ctrl_ext |= IXGBE_CTRL_EXT_NS_DIS;
  266. IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
  267. IXGBE_WRITE_FLUSH(hw);
  268. /* Setup flow control */
  269. ixgbe_setup_fc(hw);
  270. /* Clear adapter stopped flag */
  271. hw->adapter_stopped = false;
  272. return 0;
  273. }
  274. /**
  275. * ixgbe_start_hw_gen2 - Init sequence for common device family
  276. * @hw: pointer to hw structure
  277. *
  278. * Performs the init sequence common to the second generation
  279. * of 10 GbE devices.
  280. * Devices in the second generation:
  281. * 82599
  282. * X540
  283. **/
  284. s32 ixgbe_start_hw_gen2(struct ixgbe_hw *hw)
  285. {
  286. u32 i;
  287. u32 regval;
  288. /* Clear the rate limiters */
  289. for (i = 0; i < hw->mac.max_tx_queues; i++) {
  290. IXGBE_WRITE_REG(hw, IXGBE_RTTDQSEL, i);
  291. IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRC, 0);
  292. }
  293. IXGBE_WRITE_FLUSH(hw);
  294. /* Disable relaxed ordering */
  295. for (i = 0; i < hw->mac.max_tx_queues; i++) {
  296. regval = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(i));
  297. regval &= ~IXGBE_DCA_TXCTRL_DESC_WRO_EN;
  298. IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(i), regval);
  299. }
  300. for (i = 0; i < hw->mac.max_rx_queues; i++) {
  301. regval = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
  302. regval &= ~(IXGBE_DCA_RXCTRL_DATA_WRO_EN |
  303. IXGBE_DCA_RXCTRL_HEAD_WRO_EN);
  304. IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(i), regval);
  305. }
  306. return 0;
  307. }
  308. /**
  309. * ixgbe_init_hw_generic - Generic hardware initialization
  310. * @hw: pointer to hardware structure
  311. *
  312. * Initialize the hardware by resetting the hardware, filling the bus info
  313. * structure and media type, clears all on chip counters, initializes receive
  314. * address registers, multicast table, VLAN filter table, calls routine to set
  315. * up link and flow control settings, and leaves transmit and receive units
  316. * disabled and uninitialized
  317. **/
  318. s32 ixgbe_init_hw_generic(struct ixgbe_hw *hw)
  319. {
  320. s32 status;
  321. /* Reset the hardware */
  322. status = hw->mac.ops.reset_hw(hw);
  323. if (status == 0) {
  324. /* Start the HW */
  325. status = hw->mac.ops.start_hw(hw);
  326. }
  327. return status;
  328. }
  329. /**
  330. * ixgbe_clear_hw_cntrs_generic - Generic clear hardware counters
  331. * @hw: pointer to hardware structure
  332. *
  333. * Clears all hardware statistics counters by reading them from the hardware
  334. * Statistics counters are clear on read.
  335. **/
  336. s32 ixgbe_clear_hw_cntrs_generic(struct ixgbe_hw *hw)
  337. {
  338. u16 i = 0;
  339. IXGBE_READ_REG(hw, IXGBE_CRCERRS);
  340. IXGBE_READ_REG(hw, IXGBE_ILLERRC);
  341. IXGBE_READ_REG(hw, IXGBE_ERRBC);
  342. IXGBE_READ_REG(hw, IXGBE_MSPDC);
  343. for (i = 0; i < 8; i++)
  344. IXGBE_READ_REG(hw, IXGBE_MPC(i));
  345. IXGBE_READ_REG(hw, IXGBE_MLFC);
  346. IXGBE_READ_REG(hw, IXGBE_MRFC);
  347. IXGBE_READ_REG(hw, IXGBE_RLEC);
  348. IXGBE_READ_REG(hw, IXGBE_LXONTXC);
  349. IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
  350. if (hw->mac.type >= ixgbe_mac_82599EB) {
  351. IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
  352. IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
  353. } else {
  354. IXGBE_READ_REG(hw, IXGBE_LXONRXC);
  355. IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
  356. }
  357. for (i = 0; i < 8; i++) {
  358. IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
  359. IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
  360. if (hw->mac.type >= ixgbe_mac_82599EB) {
  361. IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
  362. IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
  363. } else {
  364. IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
  365. IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
  366. }
  367. }
  368. if (hw->mac.type >= ixgbe_mac_82599EB)
  369. for (i = 0; i < 8; i++)
  370. IXGBE_READ_REG(hw, IXGBE_PXON2OFFCNT(i));
  371. IXGBE_READ_REG(hw, IXGBE_PRC64);
  372. IXGBE_READ_REG(hw, IXGBE_PRC127);
  373. IXGBE_READ_REG(hw, IXGBE_PRC255);
  374. IXGBE_READ_REG(hw, IXGBE_PRC511);
  375. IXGBE_READ_REG(hw, IXGBE_PRC1023);
  376. IXGBE_READ_REG(hw, IXGBE_PRC1522);
  377. IXGBE_READ_REG(hw, IXGBE_GPRC);
  378. IXGBE_READ_REG(hw, IXGBE_BPRC);
  379. IXGBE_READ_REG(hw, IXGBE_MPRC);
  380. IXGBE_READ_REG(hw, IXGBE_GPTC);
  381. IXGBE_READ_REG(hw, IXGBE_GORCL);
  382. IXGBE_READ_REG(hw, IXGBE_GORCH);
  383. IXGBE_READ_REG(hw, IXGBE_GOTCL);
  384. IXGBE_READ_REG(hw, IXGBE_GOTCH);
  385. if (hw->mac.type == ixgbe_mac_82598EB)
  386. for (i = 0; i < 8; i++)
  387. IXGBE_READ_REG(hw, IXGBE_RNBC(i));
  388. IXGBE_READ_REG(hw, IXGBE_RUC);
  389. IXGBE_READ_REG(hw, IXGBE_RFC);
  390. IXGBE_READ_REG(hw, IXGBE_ROC);
  391. IXGBE_READ_REG(hw, IXGBE_RJC);
  392. IXGBE_READ_REG(hw, IXGBE_MNGPRC);
  393. IXGBE_READ_REG(hw, IXGBE_MNGPDC);
  394. IXGBE_READ_REG(hw, IXGBE_MNGPTC);
  395. IXGBE_READ_REG(hw, IXGBE_TORL);
  396. IXGBE_READ_REG(hw, IXGBE_TORH);
  397. IXGBE_READ_REG(hw, IXGBE_TPR);
  398. IXGBE_READ_REG(hw, IXGBE_TPT);
  399. IXGBE_READ_REG(hw, IXGBE_PTC64);
  400. IXGBE_READ_REG(hw, IXGBE_PTC127);
  401. IXGBE_READ_REG(hw, IXGBE_PTC255);
  402. IXGBE_READ_REG(hw, IXGBE_PTC511);
  403. IXGBE_READ_REG(hw, IXGBE_PTC1023);
  404. IXGBE_READ_REG(hw, IXGBE_PTC1522);
  405. IXGBE_READ_REG(hw, IXGBE_MPTC);
  406. IXGBE_READ_REG(hw, IXGBE_BPTC);
  407. for (i = 0; i < 16; i++) {
  408. IXGBE_READ_REG(hw, IXGBE_QPRC(i));
  409. IXGBE_READ_REG(hw, IXGBE_QPTC(i));
  410. if (hw->mac.type >= ixgbe_mac_82599EB) {
  411. IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
  412. IXGBE_READ_REG(hw, IXGBE_QBRC_H(i));
  413. IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
  414. IXGBE_READ_REG(hw, IXGBE_QBTC_H(i));
  415. IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
  416. } else {
  417. IXGBE_READ_REG(hw, IXGBE_QBRC(i));
  418. IXGBE_READ_REG(hw, IXGBE_QBTC(i));
  419. }
  420. }
  421. if (hw->mac.type == ixgbe_mac_X540) {
  422. if (hw->phy.id == 0)
  423. hw->phy.ops.identify(hw);
  424. hw->phy.ops.read_reg(hw, IXGBE_PCRC8ECL, MDIO_MMD_PCS, &i);
  425. hw->phy.ops.read_reg(hw, IXGBE_PCRC8ECH, MDIO_MMD_PCS, &i);
  426. hw->phy.ops.read_reg(hw, IXGBE_LDPCECL, MDIO_MMD_PCS, &i);
  427. hw->phy.ops.read_reg(hw, IXGBE_LDPCECH, MDIO_MMD_PCS, &i);
  428. }
  429. return 0;
  430. }
  431. /**
  432. * ixgbe_read_pba_string_generic - Reads part number string from EEPROM
  433. * @hw: pointer to hardware structure
  434. * @pba_num: stores the part number string from the EEPROM
  435. * @pba_num_size: part number string buffer length
  436. *
  437. * Reads the part number string from the EEPROM.
  438. **/
  439. s32 ixgbe_read_pba_string_generic(struct ixgbe_hw *hw, u8 *pba_num,
  440. u32 pba_num_size)
  441. {
  442. s32 ret_val;
  443. u16 data;
  444. u16 pba_ptr;
  445. u16 offset;
  446. u16 length;
  447. if (pba_num == NULL) {
  448. hw_dbg(hw, "PBA string buffer was null\n");
  449. return IXGBE_ERR_INVALID_ARGUMENT;
  450. }
  451. ret_val = hw->eeprom.ops.read(hw, IXGBE_PBANUM0_PTR, &data);
  452. if (ret_val) {
  453. hw_dbg(hw, "NVM Read Error\n");
  454. return ret_val;
  455. }
  456. ret_val = hw->eeprom.ops.read(hw, IXGBE_PBANUM1_PTR, &pba_ptr);
  457. if (ret_val) {
  458. hw_dbg(hw, "NVM Read Error\n");
  459. return ret_val;
  460. }
  461. /*
  462. * if data is not ptr guard the PBA must be in legacy format which
  463. * means pba_ptr is actually our second data word for the PBA number
  464. * and we can decode it into an ascii string
  465. */
  466. if (data != IXGBE_PBANUM_PTR_GUARD) {
  467. hw_dbg(hw, "NVM PBA number is not stored as string\n");
  468. /* we will need 11 characters to store the PBA */
  469. if (pba_num_size < 11) {
  470. hw_dbg(hw, "PBA string buffer too small\n");
  471. return IXGBE_ERR_NO_SPACE;
  472. }
  473. /* extract hex string from data and pba_ptr */
  474. pba_num[0] = (data >> 12) & 0xF;
  475. pba_num[1] = (data >> 8) & 0xF;
  476. pba_num[2] = (data >> 4) & 0xF;
  477. pba_num[3] = data & 0xF;
  478. pba_num[4] = (pba_ptr >> 12) & 0xF;
  479. pba_num[5] = (pba_ptr >> 8) & 0xF;
  480. pba_num[6] = '-';
  481. pba_num[7] = 0;
  482. pba_num[8] = (pba_ptr >> 4) & 0xF;
  483. pba_num[9] = pba_ptr & 0xF;
  484. /* put a null character on the end of our string */
  485. pba_num[10] = '\0';
  486. /* switch all the data but the '-' to hex char */
  487. for (offset = 0; offset < 10; offset++) {
  488. if (pba_num[offset] < 0xA)
  489. pba_num[offset] += '0';
  490. else if (pba_num[offset] < 0x10)
  491. pba_num[offset] += 'A' - 0xA;
  492. }
  493. return 0;
  494. }
  495. ret_val = hw->eeprom.ops.read(hw, pba_ptr, &length);
  496. if (ret_val) {
  497. hw_dbg(hw, "NVM Read Error\n");
  498. return ret_val;
  499. }
  500. if (length == 0xFFFF || length == 0) {
  501. hw_dbg(hw, "NVM PBA number section invalid length\n");
  502. return IXGBE_ERR_PBA_SECTION;
  503. }
  504. /* check if pba_num buffer is big enough */
  505. if (pba_num_size < (((u32)length * 2) - 1)) {
  506. hw_dbg(hw, "PBA string buffer too small\n");
  507. return IXGBE_ERR_NO_SPACE;
  508. }
  509. /* trim pba length from start of string */
  510. pba_ptr++;
  511. length--;
  512. for (offset = 0; offset < length; offset++) {
  513. ret_val = hw->eeprom.ops.read(hw, pba_ptr + offset, &data);
  514. if (ret_val) {
  515. hw_dbg(hw, "NVM Read Error\n");
  516. return ret_val;
  517. }
  518. pba_num[offset * 2] = (u8)(data >> 8);
  519. pba_num[(offset * 2) + 1] = (u8)(data & 0xFF);
  520. }
  521. pba_num[offset * 2] = '\0';
  522. return 0;
  523. }
  524. /**
  525. * ixgbe_get_mac_addr_generic - Generic get MAC address
  526. * @hw: pointer to hardware structure
  527. * @mac_addr: Adapter MAC address
  528. *
  529. * Reads the adapter's MAC address from first Receive Address Register (RAR0)
  530. * A reset of the adapter must be performed prior to calling this function
  531. * in order for the MAC address to have been loaded from the EEPROM into RAR0
  532. **/
  533. s32 ixgbe_get_mac_addr_generic(struct ixgbe_hw *hw, u8 *mac_addr)
  534. {
  535. u32 rar_high;
  536. u32 rar_low;
  537. u16 i;
  538. rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(0));
  539. rar_low = IXGBE_READ_REG(hw, IXGBE_RAL(0));
  540. for (i = 0; i < 4; i++)
  541. mac_addr[i] = (u8)(rar_low >> (i*8));
  542. for (i = 0; i < 2; i++)
  543. mac_addr[i+4] = (u8)(rar_high >> (i*8));
  544. return 0;
  545. }
  546. enum ixgbe_bus_width ixgbe_convert_bus_width(u16 link_status)
  547. {
  548. switch (link_status & IXGBE_PCI_LINK_WIDTH) {
  549. case IXGBE_PCI_LINK_WIDTH_1:
  550. return ixgbe_bus_width_pcie_x1;
  551. case IXGBE_PCI_LINK_WIDTH_2:
  552. return ixgbe_bus_width_pcie_x2;
  553. case IXGBE_PCI_LINK_WIDTH_4:
  554. return ixgbe_bus_width_pcie_x4;
  555. case IXGBE_PCI_LINK_WIDTH_8:
  556. return ixgbe_bus_width_pcie_x8;
  557. default:
  558. return ixgbe_bus_width_unknown;
  559. }
  560. }
  561. enum ixgbe_bus_speed ixgbe_convert_bus_speed(u16 link_status)
  562. {
  563. switch (link_status & IXGBE_PCI_LINK_SPEED) {
  564. case IXGBE_PCI_LINK_SPEED_2500:
  565. return ixgbe_bus_speed_2500;
  566. case IXGBE_PCI_LINK_SPEED_5000:
  567. return ixgbe_bus_speed_5000;
  568. case IXGBE_PCI_LINK_SPEED_8000:
  569. return ixgbe_bus_speed_8000;
  570. default:
  571. return ixgbe_bus_speed_unknown;
  572. }
  573. }
  574. /**
  575. * ixgbe_get_bus_info_generic - Generic set PCI bus info
  576. * @hw: pointer to hardware structure
  577. *
  578. * Sets the PCI bus info (speed, width, type) within the ixgbe_hw structure
  579. **/
  580. s32 ixgbe_get_bus_info_generic(struct ixgbe_hw *hw)
  581. {
  582. struct ixgbe_adapter *adapter = hw->back;
  583. struct ixgbe_mac_info *mac = &hw->mac;
  584. u16 link_status;
  585. hw->bus.type = ixgbe_bus_type_pci_express;
  586. /* Get the negotiated link width and speed from PCI config space */
  587. pci_read_config_word(adapter->pdev, IXGBE_PCI_LINK_STATUS,
  588. &link_status);
  589. hw->bus.width = ixgbe_convert_bus_width(link_status);
  590. hw->bus.speed = ixgbe_convert_bus_speed(link_status);
  591. mac->ops.set_lan_id(hw);
  592. return 0;
  593. }
  594. /**
  595. * ixgbe_set_lan_id_multi_port_pcie - Set LAN id for PCIe multiple port devices
  596. * @hw: pointer to the HW structure
  597. *
  598. * Determines the LAN function id by reading memory-mapped registers
  599. * and swaps the port value if requested.
  600. **/
  601. void ixgbe_set_lan_id_multi_port_pcie(struct ixgbe_hw *hw)
  602. {
  603. struct ixgbe_bus_info *bus = &hw->bus;
  604. u32 reg;
  605. reg = IXGBE_READ_REG(hw, IXGBE_STATUS);
  606. bus->func = (reg & IXGBE_STATUS_LAN_ID) >> IXGBE_STATUS_LAN_ID_SHIFT;
  607. bus->lan_id = bus->func;
  608. /* check for a port swap */
  609. reg = IXGBE_READ_REG(hw, IXGBE_FACTPS);
  610. if (reg & IXGBE_FACTPS_LFS)
  611. bus->func ^= 0x1;
  612. }
  613. /**
  614. * ixgbe_stop_adapter_generic - Generic stop Tx/Rx units
  615. * @hw: pointer to hardware structure
  616. *
  617. * Sets the adapter_stopped flag within ixgbe_hw struct. Clears interrupts,
  618. * disables transmit and receive units. The adapter_stopped flag is used by
  619. * the shared code and drivers to determine if the adapter is in a stopped
  620. * state and should not touch the hardware.
  621. **/
  622. s32 ixgbe_stop_adapter_generic(struct ixgbe_hw *hw)
  623. {
  624. u32 reg_val;
  625. u16 i;
  626. /*
  627. * Set the adapter_stopped flag so other driver functions stop touching
  628. * the hardware
  629. */
  630. hw->adapter_stopped = true;
  631. /* Disable the receive unit */
  632. IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, 0);
  633. /* Clear interrupt mask to stop interrupts from being generated */
  634. IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
  635. /* Clear any pending interrupts, flush previous writes */
  636. IXGBE_READ_REG(hw, IXGBE_EICR);
  637. /* Disable the transmit unit. Each queue must be disabled. */
  638. for (i = 0; i < hw->mac.max_tx_queues; i++)
  639. IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(i), IXGBE_TXDCTL_SWFLSH);
  640. /* Disable the receive unit by stopping each queue */
  641. for (i = 0; i < hw->mac.max_rx_queues; i++) {
  642. reg_val = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
  643. reg_val &= ~IXGBE_RXDCTL_ENABLE;
  644. reg_val |= IXGBE_RXDCTL_SWFLSH;
  645. IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(i), reg_val);
  646. }
  647. /* flush all queues disables */
  648. IXGBE_WRITE_FLUSH(hw);
  649. usleep_range(1000, 2000);
  650. /*
  651. * Prevent the PCI-E bus from from hanging by disabling PCI-E master
  652. * access and verify no pending requests
  653. */
  654. return ixgbe_disable_pcie_master(hw);
  655. }
  656. /**
  657. * ixgbe_led_on_generic - Turns on the software controllable LEDs.
  658. * @hw: pointer to hardware structure
  659. * @index: led number to turn on
  660. **/
  661. s32 ixgbe_led_on_generic(struct ixgbe_hw *hw, u32 index)
  662. {
  663. u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
  664. /* To turn on the LED, set mode to ON. */
  665. led_reg &= ~IXGBE_LED_MODE_MASK(index);
  666. led_reg |= IXGBE_LED_ON << IXGBE_LED_MODE_SHIFT(index);
  667. IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
  668. IXGBE_WRITE_FLUSH(hw);
  669. return 0;
  670. }
  671. /**
  672. * ixgbe_led_off_generic - Turns off the software controllable LEDs.
  673. * @hw: pointer to hardware structure
  674. * @index: led number to turn off
  675. **/
  676. s32 ixgbe_led_off_generic(struct ixgbe_hw *hw, u32 index)
  677. {
  678. u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
  679. /* To turn off the LED, set mode to OFF. */
  680. led_reg &= ~IXGBE_LED_MODE_MASK(index);
  681. led_reg |= IXGBE_LED_OFF << IXGBE_LED_MODE_SHIFT(index);
  682. IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
  683. IXGBE_WRITE_FLUSH(hw);
  684. return 0;
  685. }
  686. /**
  687. * ixgbe_init_eeprom_params_generic - Initialize EEPROM params
  688. * @hw: pointer to hardware structure
  689. *
  690. * Initializes the EEPROM parameters ixgbe_eeprom_info within the
  691. * ixgbe_hw struct in order to set up EEPROM access.
  692. **/
  693. s32 ixgbe_init_eeprom_params_generic(struct ixgbe_hw *hw)
  694. {
  695. struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
  696. u32 eec;
  697. u16 eeprom_size;
  698. if (eeprom->type == ixgbe_eeprom_uninitialized) {
  699. eeprom->type = ixgbe_eeprom_none;
  700. /* Set default semaphore delay to 10ms which is a well
  701. * tested value */
  702. eeprom->semaphore_delay = 10;
  703. /* Clear EEPROM page size, it will be initialized as needed */
  704. eeprom->word_page_size = 0;
  705. /*
  706. * Check for EEPROM present first.
  707. * If not present leave as none
  708. */
  709. eec = IXGBE_READ_REG(hw, IXGBE_EEC);
  710. if (eec & IXGBE_EEC_PRES) {
  711. eeprom->type = ixgbe_eeprom_spi;
  712. /*
  713. * SPI EEPROM is assumed here. This code would need to
  714. * change if a future EEPROM is not SPI.
  715. */
  716. eeprom_size = (u16)((eec & IXGBE_EEC_SIZE) >>
  717. IXGBE_EEC_SIZE_SHIFT);
  718. eeprom->word_size = 1 << (eeprom_size +
  719. IXGBE_EEPROM_WORD_SIZE_SHIFT);
  720. }
  721. if (eec & IXGBE_EEC_ADDR_SIZE)
  722. eeprom->address_bits = 16;
  723. else
  724. eeprom->address_bits = 8;
  725. hw_dbg(hw, "Eeprom params: type = %d, size = %d, address bits: "
  726. "%d\n", eeprom->type, eeprom->word_size,
  727. eeprom->address_bits);
  728. }
  729. return 0;
  730. }
  731. /**
  732. * ixgbe_write_eeprom_buffer_bit_bang_generic - Write EEPROM using bit-bang
  733. * @hw: pointer to hardware structure
  734. * @offset: offset within the EEPROM to write
  735. * @words: number of words
  736. * @data: 16 bit word(s) to write to EEPROM
  737. *
  738. * Reads 16 bit word(s) from EEPROM through bit-bang method
  739. **/
  740. s32 ixgbe_write_eeprom_buffer_bit_bang_generic(struct ixgbe_hw *hw, u16 offset,
  741. u16 words, u16 *data)
  742. {
  743. s32 status = 0;
  744. u16 i, count;
  745. hw->eeprom.ops.init_params(hw);
  746. if (words == 0) {
  747. status = IXGBE_ERR_INVALID_ARGUMENT;
  748. goto out;
  749. }
  750. if (offset + words > hw->eeprom.word_size) {
  751. status = IXGBE_ERR_EEPROM;
  752. goto out;
  753. }
  754. /*
  755. * The EEPROM page size cannot be queried from the chip. We do lazy
  756. * initialization. It is worth to do that when we write large buffer.
  757. */
  758. if ((hw->eeprom.word_page_size == 0) &&
  759. (words > IXGBE_EEPROM_PAGE_SIZE_MAX))
  760. ixgbe_detect_eeprom_page_size_generic(hw, offset);
  761. /*
  762. * We cannot hold synchronization semaphores for too long
  763. * to avoid other entity starvation. However it is more efficient
  764. * to read in bursts than synchronizing access for each word.
  765. */
  766. for (i = 0; i < words; i += IXGBE_EEPROM_RD_BUFFER_MAX_COUNT) {
  767. count = (words - i) / IXGBE_EEPROM_RD_BUFFER_MAX_COUNT > 0 ?
  768. IXGBE_EEPROM_RD_BUFFER_MAX_COUNT : (words - i);
  769. status = ixgbe_write_eeprom_buffer_bit_bang(hw, offset + i,
  770. count, &data[i]);
  771. if (status != 0)
  772. break;
  773. }
  774. out:
  775. return status;
  776. }
  777. /**
  778. * ixgbe_write_eeprom_buffer_bit_bang - Writes 16 bit word(s) to EEPROM
  779. * @hw: pointer to hardware structure
  780. * @offset: offset within the EEPROM to be written to
  781. * @words: number of word(s)
  782. * @data: 16 bit word(s) to be written to the EEPROM
  783. *
  784. * If ixgbe_eeprom_update_checksum is not called after this function, the
  785. * EEPROM will most likely contain an invalid checksum.
  786. **/
  787. static s32 ixgbe_write_eeprom_buffer_bit_bang(struct ixgbe_hw *hw, u16 offset,
  788. u16 words, u16 *data)
  789. {
  790. s32 status;
  791. u16 word;
  792. u16 page_size;
  793. u16 i;
  794. u8 write_opcode = IXGBE_EEPROM_WRITE_OPCODE_SPI;
  795. /* Prepare the EEPROM for writing */
  796. status = ixgbe_acquire_eeprom(hw);
  797. if (status == 0) {
  798. if (ixgbe_ready_eeprom(hw) != 0) {
  799. ixgbe_release_eeprom(hw);
  800. status = IXGBE_ERR_EEPROM;
  801. }
  802. }
  803. if (status == 0) {
  804. for (i = 0; i < words; i++) {
  805. ixgbe_standby_eeprom(hw);
  806. /* Send the WRITE ENABLE command (8 bit opcode ) */
  807. ixgbe_shift_out_eeprom_bits(hw,
  808. IXGBE_EEPROM_WREN_OPCODE_SPI,
  809. IXGBE_EEPROM_OPCODE_BITS);
  810. ixgbe_standby_eeprom(hw);
  811. /*
  812. * Some SPI eeproms use the 8th address bit embedded
  813. * in the opcode
  814. */
  815. if ((hw->eeprom.address_bits == 8) &&
  816. ((offset + i) >= 128))
  817. write_opcode |= IXGBE_EEPROM_A8_OPCODE_SPI;
  818. /* Send the Write command (8-bit opcode + addr) */
  819. ixgbe_shift_out_eeprom_bits(hw, write_opcode,
  820. IXGBE_EEPROM_OPCODE_BITS);
  821. ixgbe_shift_out_eeprom_bits(hw, (u16)((offset + i) * 2),
  822. hw->eeprom.address_bits);
  823. page_size = hw->eeprom.word_page_size;
  824. /* Send the data in burst via SPI*/
  825. do {
  826. word = data[i];
  827. word = (word >> 8) | (word << 8);
  828. ixgbe_shift_out_eeprom_bits(hw, word, 16);
  829. if (page_size == 0)
  830. break;
  831. /* do not wrap around page */
  832. if (((offset + i) & (page_size - 1)) ==
  833. (page_size - 1))
  834. break;
  835. } while (++i < words);
  836. ixgbe_standby_eeprom(hw);
  837. usleep_range(10000, 20000);
  838. }
  839. /* Done with writing - release the EEPROM */
  840. ixgbe_release_eeprom(hw);
  841. }
  842. return status;
  843. }
  844. /**
  845. * ixgbe_write_eeprom_generic - Writes 16 bit value to EEPROM
  846. * @hw: pointer to hardware structure
  847. * @offset: offset within the EEPROM to be written to
  848. * @data: 16 bit word to be written to the EEPROM
  849. *
  850. * If ixgbe_eeprom_update_checksum is not called after this function, the
  851. * EEPROM will most likely contain an invalid checksum.
  852. **/
  853. s32 ixgbe_write_eeprom_generic(struct ixgbe_hw *hw, u16 offset, u16 data)
  854. {
  855. s32 status;
  856. hw->eeprom.ops.init_params(hw);
  857. if (offset >= hw->eeprom.word_size) {
  858. status = IXGBE_ERR_EEPROM;
  859. goto out;
  860. }
  861. status = ixgbe_write_eeprom_buffer_bit_bang(hw, offset, 1, &data);
  862. out:
  863. return status;
  864. }
  865. /**
  866. * ixgbe_read_eeprom_buffer_bit_bang_generic - Read EEPROM using bit-bang
  867. * @hw: pointer to hardware structure
  868. * @offset: offset within the EEPROM to be read
  869. * @words: number of word(s)
  870. * @data: read 16 bit words(s) from EEPROM
  871. *
  872. * Reads 16 bit word(s) from EEPROM through bit-bang method
  873. **/
  874. s32 ixgbe_read_eeprom_buffer_bit_bang_generic(struct ixgbe_hw *hw, u16 offset,
  875. u16 words, u16 *data)
  876. {
  877. s32 status = 0;
  878. u16 i, count;
  879. hw->eeprom.ops.init_params(hw);
  880. if (words == 0) {
  881. status = IXGBE_ERR_INVALID_ARGUMENT;
  882. goto out;
  883. }
  884. if (offset + words > hw->eeprom.word_size) {
  885. status = IXGBE_ERR_EEPROM;
  886. goto out;
  887. }
  888. /*
  889. * We cannot hold synchronization semaphores for too long
  890. * to avoid other entity starvation. However it is more efficient
  891. * to read in bursts than synchronizing access for each word.
  892. */
  893. for (i = 0; i < words; i += IXGBE_EEPROM_RD_BUFFER_MAX_COUNT) {
  894. count = (words - i) / IXGBE_EEPROM_RD_BUFFER_MAX_COUNT > 0 ?
  895. IXGBE_EEPROM_RD_BUFFER_MAX_COUNT : (words - i);
  896. status = ixgbe_read_eeprom_buffer_bit_bang(hw, offset + i,
  897. count, &data[i]);
  898. if (status != 0)
  899. break;
  900. }
  901. out:
  902. return status;
  903. }
  904. /**
  905. * ixgbe_read_eeprom_buffer_bit_bang - Read EEPROM using bit-bang
  906. * @hw: pointer to hardware structure
  907. * @offset: offset within the EEPROM to be read
  908. * @words: number of word(s)
  909. * @data: read 16 bit word(s) from EEPROM
  910. *
  911. * Reads 16 bit word(s) from EEPROM through bit-bang method
  912. **/
  913. static s32 ixgbe_read_eeprom_buffer_bit_bang(struct ixgbe_hw *hw, u16 offset,
  914. u16 words, u16 *data)
  915. {
  916. s32 status;
  917. u16 word_in;
  918. u8 read_opcode = IXGBE_EEPROM_READ_OPCODE_SPI;
  919. u16 i;
  920. /* Prepare the EEPROM for reading */
  921. status = ixgbe_acquire_eeprom(hw);
  922. if (status == 0) {
  923. if (ixgbe_ready_eeprom(hw) != 0) {
  924. ixgbe_release_eeprom(hw);
  925. status = IXGBE_ERR_EEPROM;
  926. }
  927. }
  928. if (status == 0) {
  929. for (i = 0; i < words; i++) {
  930. ixgbe_standby_eeprom(hw);
  931. /*
  932. * Some SPI eeproms use the 8th address bit embedded
  933. * in the opcode
  934. */
  935. if ((hw->eeprom.address_bits == 8) &&
  936. ((offset + i) >= 128))
  937. read_opcode |= IXGBE_EEPROM_A8_OPCODE_SPI;
  938. /* Send the READ command (opcode + addr) */
  939. ixgbe_shift_out_eeprom_bits(hw, read_opcode,
  940. IXGBE_EEPROM_OPCODE_BITS);
  941. ixgbe_shift_out_eeprom_bits(hw, (u16)((offset + i) * 2),
  942. hw->eeprom.address_bits);
  943. /* Read the data. */
  944. word_in = ixgbe_shift_in_eeprom_bits(hw, 16);
  945. data[i] = (word_in >> 8) | (word_in << 8);
  946. }
  947. /* End this read operation */
  948. ixgbe_release_eeprom(hw);
  949. }
  950. return status;
  951. }
  952. /**
  953. * ixgbe_read_eeprom_bit_bang_generic - Read EEPROM word using bit-bang
  954. * @hw: pointer to hardware structure
  955. * @offset: offset within the EEPROM to be read
  956. * @data: read 16 bit value from EEPROM
  957. *
  958. * Reads 16 bit value from EEPROM through bit-bang method
  959. **/
  960. s32 ixgbe_read_eeprom_bit_bang_generic(struct ixgbe_hw *hw, u16 offset,
  961. u16 *data)
  962. {
  963. s32 status;
  964. hw->eeprom.ops.init_params(hw);
  965. if (offset >= hw->eeprom.word_size) {
  966. status = IXGBE_ERR_EEPROM;
  967. goto out;
  968. }
  969. status = ixgbe_read_eeprom_buffer_bit_bang(hw, offset, 1, data);
  970. out:
  971. return status;
  972. }
  973. /**
  974. * ixgbe_read_eerd_buffer_generic - Read EEPROM word(s) using EERD
  975. * @hw: pointer to hardware structure
  976. * @offset: offset of word in the EEPROM to read
  977. * @words: number of word(s)
  978. * @data: 16 bit word(s) from the EEPROM
  979. *
  980. * Reads a 16 bit word(s) from the EEPROM using the EERD register.
  981. **/
  982. s32 ixgbe_read_eerd_buffer_generic(struct ixgbe_hw *hw, u16 offset,
  983. u16 words, u16 *data)
  984. {
  985. u32 eerd;
  986. s32 status = 0;
  987. u32 i;
  988. hw->eeprom.ops.init_params(hw);
  989. if (words == 0) {
  990. status = IXGBE_ERR_INVALID_ARGUMENT;
  991. goto out;
  992. }
  993. if (offset >= hw->eeprom.word_size) {
  994. status = IXGBE_ERR_EEPROM;
  995. goto out;
  996. }
  997. for (i = 0; i < words; i++) {
  998. eerd = ((offset + i) << IXGBE_EEPROM_RW_ADDR_SHIFT) |
  999. IXGBE_EEPROM_RW_REG_START;
  1000. IXGBE_WRITE_REG(hw, IXGBE_EERD, eerd);
  1001. status = ixgbe_poll_eerd_eewr_done(hw, IXGBE_NVM_POLL_READ);
  1002. if (status == 0) {
  1003. data[i] = (IXGBE_READ_REG(hw, IXGBE_EERD) >>
  1004. IXGBE_EEPROM_RW_REG_DATA);
  1005. } else {
  1006. hw_dbg(hw, "Eeprom read timed out\n");
  1007. goto out;
  1008. }
  1009. }
  1010. out:
  1011. return status;
  1012. }
  1013. /**
  1014. * ixgbe_detect_eeprom_page_size_generic - Detect EEPROM page size
  1015. * @hw: pointer to hardware structure
  1016. * @offset: offset within the EEPROM to be used as a scratch pad
  1017. *
  1018. * Discover EEPROM page size by writing marching data at given offset.
  1019. * This function is called only when we are writing a new large buffer
  1020. * at given offset so the data would be overwritten anyway.
  1021. **/
  1022. static s32 ixgbe_detect_eeprom_page_size_generic(struct ixgbe_hw *hw,
  1023. u16 offset)
  1024. {
  1025. u16 data[IXGBE_EEPROM_PAGE_SIZE_MAX];
  1026. s32 status = 0;
  1027. u16 i;
  1028. for (i = 0; i < IXGBE_EEPROM_PAGE_SIZE_MAX; i++)
  1029. data[i] = i;
  1030. hw->eeprom.word_page_size = IXGBE_EEPROM_PAGE_SIZE_MAX;
  1031. status = ixgbe_write_eeprom_buffer_bit_bang(hw, offset,
  1032. IXGBE_EEPROM_PAGE_SIZE_MAX, data);
  1033. hw->eeprom.word_page_size = 0;
  1034. if (status != 0)
  1035. goto out;
  1036. status = ixgbe_read_eeprom_buffer_bit_bang(hw, offset, 1, data);
  1037. if (status != 0)
  1038. goto out;
  1039. /*
  1040. * When writing in burst more than the actual page size
  1041. * EEPROM address wraps around current page.
  1042. */
  1043. hw->eeprom.word_page_size = IXGBE_EEPROM_PAGE_SIZE_MAX - data[0];
  1044. hw_dbg(hw, "Detected EEPROM page size = %d words.",
  1045. hw->eeprom.word_page_size);
  1046. out:
  1047. return status;
  1048. }
  1049. /**
  1050. * ixgbe_read_eerd_generic - Read EEPROM word using EERD
  1051. * @hw: pointer to hardware structure
  1052. * @offset: offset of word in the EEPROM to read
  1053. * @data: word read from the EEPROM
  1054. *
  1055. * Reads a 16 bit word from the EEPROM using the EERD register.
  1056. **/
  1057. s32 ixgbe_read_eerd_generic(struct ixgbe_hw *hw, u16 offset, u16 *data)
  1058. {
  1059. return ixgbe_read_eerd_buffer_generic(hw, offset, 1, data);
  1060. }
  1061. /**
  1062. * ixgbe_write_eewr_buffer_generic - Write EEPROM word(s) using EEWR
  1063. * @hw: pointer to hardware structure
  1064. * @offset: offset of word in the EEPROM to write
  1065. * @words: number of words
  1066. * @data: word(s) write to the EEPROM
  1067. *
  1068. * Write a 16 bit word(s) to the EEPROM using the EEWR register.
  1069. **/
  1070. s32 ixgbe_write_eewr_buffer_generic(struct ixgbe_hw *hw, u16 offset,
  1071. u16 words, u16 *data)
  1072. {
  1073. u32 eewr;
  1074. s32 status = 0;
  1075. u16 i;
  1076. hw->eeprom.ops.init_params(hw);
  1077. if (words == 0) {
  1078. status = IXGBE_ERR_INVALID_ARGUMENT;
  1079. goto out;
  1080. }
  1081. if (offset >= hw->eeprom.word_size) {
  1082. status = IXGBE_ERR_EEPROM;
  1083. goto out;
  1084. }
  1085. for (i = 0; i < words; i++) {
  1086. eewr = ((offset + i) << IXGBE_EEPROM_RW_ADDR_SHIFT) |
  1087. (data[i] << IXGBE_EEPROM_RW_REG_DATA) |
  1088. IXGBE_EEPROM_RW_REG_START;
  1089. status = ixgbe_poll_eerd_eewr_done(hw, IXGBE_NVM_POLL_WRITE);
  1090. if (status != 0) {
  1091. hw_dbg(hw, "Eeprom write EEWR timed out\n");
  1092. goto out;
  1093. }
  1094. IXGBE_WRITE_REG(hw, IXGBE_EEWR, eewr);
  1095. status = ixgbe_poll_eerd_eewr_done(hw, IXGBE_NVM_POLL_WRITE);
  1096. if (status != 0) {
  1097. hw_dbg(hw, "Eeprom write EEWR timed out\n");
  1098. goto out;
  1099. }
  1100. }
  1101. out:
  1102. return status;
  1103. }
  1104. /**
  1105. * ixgbe_write_eewr_generic - Write EEPROM word using EEWR
  1106. * @hw: pointer to hardware structure
  1107. * @offset: offset of word in the EEPROM to write
  1108. * @data: word write to the EEPROM
  1109. *
  1110. * Write a 16 bit word to the EEPROM using the EEWR register.
  1111. **/
  1112. s32 ixgbe_write_eewr_generic(struct ixgbe_hw *hw, u16 offset, u16 data)
  1113. {
  1114. return ixgbe_write_eewr_buffer_generic(hw, offset, 1, &data);
  1115. }
  1116. /**
  1117. * ixgbe_poll_eerd_eewr_done - Poll EERD read or EEWR write status
  1118. * @hw: pointer to hardware structure
  1119. * @ee_reg: EEPROM flag for polling
  1120. *
  1121. * Polls the status bit (bit 1) of the EERD or EEWR to determine when the
  1122. * read or write is done respectively.
  1123. **/
  1124. static s32 ixgbe_poll_eerd_eewr_done(struct ixgbe_hw *hw, u32 ee_reg)
  1125. {
  1126. u32 i;
  1127. u32 reg;
  1128. s32 status = IXGBE_ERR_EEPROM;
  1129. for (i = 0; i < IXGBE_EERD_EEWR_ATTEMPTS; i++) {
  1130. if (ee_reg == IXGBE_NVM_POLL_READ)
  1131. reg = IXGBE_READ_REG(hw, IXGBE_EERD);
  1132. else
  1133. reg = IXGBE_READ_REG(hw, IXGBE_EEWR);
  1134. if (reg & IXGBE_EEPROM_RW_REG_DONE) {
  1135. status = 0;
  1136. break;
  1137. }
  1138. udelay(5);
  1139. }
  1140. return status;
  1141. }
  1142. /**
  1143. * ixgbe_acquire_eeprom - Acquire EEPROM using bit-bang
  1144. * @hw: pointer to hardware structure
  1145. *
  1146. * Prepares EEPROM for access using bit-bang method. This function should
  1147. * be called before issuing a command to the EEPROM.
  1148. **/
  1149. static s32 ixgbe_acquire_eeprom(struct ixgbe_hw *hw)
  1150. {
  1151. s32 status = 0;
  1152. u32 eec;
  1153. u32 i;
  1154. if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) != 0)
  1155. status = IXGBE_ERR_SWFW_SYNC;
  1156. if (status == 0) {
  1157. eec = IXGBE_READ_REG(hw, IXGBE_EEC);
  1158. /* Request EEPROM Access */
  1159. eec |= IXGBE_EEC_REQ;
  1160. IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
  1161. for (i = 0; i < IXGBE_EEPROM_GRANT_ATTEMPTS; i++) {
  1162. eec = IXGBE_READ_REG(hw, IXGBE_EEC);
  1163. if (eec & IXGBE_EEC_GNT)
  1164. break;
  1165. udelay(5);
  1166. }
  1167. /* Release if grant not acquired */
  1168. if (!(eec & IXGBE_EEC_GNT)) {
  1169. eec &= ~IXGBE_EEC_REQ;
  1170. IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
  1171. hw_dbg(hw, "Could not acquire EEPROM grant\n");
  1172. hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
  1173. status = IXGBE_ERR_EEPROM;
  1174. }
  1175. /* Setup EEPROM for Read/Write */
  1176. if (status == 0) {
  1177. /* Clear CS and SK */
  1178. eec &= ~(IXGBE_EEC_CS | IXGBE_EEC_SK);
  1179. IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
  1180. IXGBE_WRITE_FLUSH(hw);
  1181. udelay(1);
  1182. }
  1183. }
  1184. return status;
  1185. }
  1186. /**
  1187. * ixgbe_get_eeprom_semaphore - Get hardware semaphore
  1188. * @hw: pointer to hardware structure
  1189. *
  1190. * Sets the hardware semaphores so EEPROM access can occur for bit-bang method
  1191. **/
  1192. static s32 ixgbe_get_eeprom_semaphore(struct ixgbe_hw *hw)
  1193. {
  1194. s32 status = IXGBE_ERR_EEPROM;
  1195. u32 timeout = 2000;
  1196. u32 i;
  1197. u32 swsm;
  1198. /* Get SMBI software semaphore between device drivers first */
  1199. for (i = 0; i < timeout; i++) {
  1200. /*
  1201. * If the SMBI bit is 0 when we read it, then the bit will be
  1202. * set and we have the semaphore
  1203. */
  1204. swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
  1205. if (!(swsm & IXGBE_SWSM_SMBI)) {
  1206. status = 0;
  1207. break;
  1208. }
  1209. udelay(50);
  1210. }
  1211. if (i == timeout) {
  1212. hw_dbg(hw, "Driver can't access the Eeprom - SMBI Semaphore "
  1213. "not granted.\n");
  1214. /*
  1215. * this release is particularly important because our attempts
  1216. * above to get the semaphore may have succeeded, and if there
  1217. * was a timeout, we should unconditionally clear the semaphore
  1218. * bits to free the driver to make progress
  1219. */
  1220. ixgbe_release_eeprom_semaphore(hw);
  1221. udelay(50);
  1222. /*
  1223. * one last try
  1224. * If the SMBI bit is 0 when we read it, then the bit will be
  1225. * set and we have the semaphore
  1226. */
  1227. swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
  1228. if (!(swsm & IXGBE_SWSM_SMBI))
  1229. status = 0;
  1230. }
  1231. /* Now get the semaphore between SW/FW through the SWESMBI bit */
  1232. if (status == 0) {
  1233. for (i = 0; i < timeout; i++) {
  1234. swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
  1235. /* Set the SW EEPROM semaphore bit to request access */
  1236. swsm |= IXGBE_SWSM_SWESMBI;
  1237. IXGBE_WRITE_REG(hw, IXGBE_SWSM, swsm);
  1238. /*
  1239. * If we set the bit successfully then we got the
  1240. * semaphore.
  1241. */
  1242. swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
  1243. if (swsm & IXGBE_SWSM_SWESMBI)
  1244. break;
  1245. udelay(50);
  1246. }
  1247. /*
  1248. * Release semaphores and return error if SW EEPROM semaphore
  1249. * was not granted because we don't have access to the EEPROM
  1250. */
  1251. if (i >= timeout) {
  1252. hw_dbg(hw, "SWESMBI Software EEPROM semaphore "
  1253. "not granted.\n");
  1254. ixgbe_release_eeprom_semaphore(hw);
  1255. status = IXGBE_ERR_EEPROM;
  1256. }
  1257. } else {
  1258. hw_dbg(hw, "Software semaphore SMBI between device drivers "
  1259. "not granted.\n");
  1260. }
  1261. return status;
  1262. }
  1263. /**
  1264. * ixgbe_release_eeprom_semaphore - Release hardware semaphore
  1265. * @hw: pointer to hardware structure
  1266. *
  1267. * This function clears hardware semaphore bits.
  1268. **/
  1269. static void ixgbe_release_eeprom_semaphore(struct ixgbe_hw *hw)
  1270. {
  1271. u32 swsm;
  1272. swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
  1273. /* Release both semaphores by writing 0 to the bits SWESMBI and SMBI */
  1274. swsm &= ~(IXGBE_SWSM_SWESMBI | IXGBE_SWSM_SMBI);
  1275. IXGBE_WRITE_REG(hw, IXGBE_SWSM, swsm);
  1276. IXGBE_WRITE_FLUSH(hw);
  1277. }
  1278. /**
  1279. * ixgbe_ready_eeprom - Polls for EEPROM ready
  1280. * @hw: pointer to hardware structure
  1281. **/
  1282. static s32 ixgbe_ready_eeprom(struct ixgbe_hw *hw)
  1283. {
  1284. s32 status = 0;
  1285. u16 i;
  1286. u8 spi_stat_reg;
  1287. /*
  1288. * Read "Status Register" repeatedly until the LSB is cleared. The
  1289. * EEPROM will signal that the command has been completed by clearing
  1290. * bit 0 of the internal status register. If it's not cleared within
  1291. * 5 milliseconds, then error out.
  1292. */
  1293. for (i = 0; i < IXGBE_EEPROM_MAX_RETRY_SPI; i += 5) {
  1294. ixgbe_shift_out_eeprom_bits(hw, IXGBE_EEPROM_RDSR_OPCODE_SPI,
  1295. IXGBE_EEPROM_OPCODE_BITS);
  1296. spi_stat_reg = (u8)ixgbe_shift_in_eeprom_bits(hw, 8);
  1297. if (!(spi_stat_reg & IXGBE_EEPROM_STATUS_RDY_SPI))
  1298. break;
  1299. udelay(5);
  1300. ixgbe_standby_eeprom(hw);
  1301. }
  1302. /*
  1303. * On some parts, SPI write time could vary from 0-20mSec on 3.3V
  1304. * devices (and only 0-5mSec on 5V devices)
  1305. */
  1306. if (i >= IXGBE_EEPROM_MAX_RETRY_SPI) {
  1307. hw_dbg(hw, "SPI EEPROM Status error\n");
  1308. status = IXGBE_ERR_EEPROM;
  1309. }
  1310. return status;
  1311. }
  1312. /**
  1313. * ixgbe_standby_eeprom - Returns EEPROM to a "standby" state
  1314. * @hw: pointer to hardware structure
  1315. **/
  1316. static void ixgbe_standby_eeprom(struct ixgbe_hw *hw)
  1317. {
  1318. u32 eec;
  1319. eec = IXGBE_READ_REG(hw, IXGBE_EEC);
  1320. /* Toggle CS to flush commands */
  1321. eec |= IXGBE_EEC_CS;
  1322. IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
  1323. IXGBE_WRITE_FLUSH(hw);
  1324. udelay(1);
  1325. eec &= ~IXGBE_EEC_CS;
  1326. IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
  1327. IXGBE_WRITE_FLUSH(hw);
  1328. udelay(1);
  1329. }
  1330. /**
  1331. * ixgbe_shift_out_eeprom_bits - Shift data bits out to the EEPROM.
  1332. * @hw: pointer to hardware structure
  1333. * @data: data to send to the EEPROM
  1334. * @count: number of bits to shift out
  1335. **/
  1336. static void ixgbe_shift_out_eeprom_bits(struct ixgbe_hw *hw, u16 data,
  1337. u16 count)
  1338. {
  1339. u32 eec;
  1340. u32 mask;
  1341. u32 i;
  1342. eec = IXGBE_READ_REG(hw, IXGBE_EEC);
  1343. /*
  1344. * Mask is used to shift "count" bits of "data" out to the EEPROM
  1345. * one bit at a time. Determine the starting bit based on count
  1346. */
  1347. mask = 0x01 << (count - 1);
  1348. for (i = 0; i < count; i++) {
  1349. /*
  1350. * A "1" is shifted out to the EEPROM by setting bit "DI" to a
  1351. * "1", and then raising and then lowering the clock (the SK
  1352. * bit controls the clock input to the EEPROM). A "0" is
  1353. * shifted out to the EEPROM by setting "DI" to "0" and then
  1354. * raising and then lowering the clock.
  1355. */
  1356. if (data & mask)
  1357. eec |= IXGBE_EEC_DI;
  1358. else
  1359. eec &= ~IXGBE_EEC_DI;
  1360. IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
  1361. IXGBE_WRITE_FLUSH(hw);
  1362. udelay(1);
  1363. ixgbe_raise_eeprom_clk(hw, &eec);
  1364. ixgbe_lower_eeprom_clk(hw, &eec);
  1365. /*
  1366. * Shift mask to signify next bit of data to shift in to the
  1367. * EEPROM
  1368. */
  1369. mask = mask >> 1;
  1370. }
  1371. /* We leave the "DI" bit set to "0" when we leave this routine. */
  1372. eec &= ~IXGBE_EEC_DI;
  1373. IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
  1374. IXGBE_WRITE_FLUSH(hw);
  1375. }
  1376. /**
  1377. * ixgbe_shift_in_eeprom_bits - Shift data bits in from the EEPROM
  1378. * @hw: pointer to hardware structure
  1379. **/
  1380. static u16 ixgbe_shift_in_eeprom_bits(struct ixgbe_hw *hw, u16 count)
  1381. {
  1382. u32 eec;
  1383. u32 i;
  1384. u16 data = 0;
  1385. /*
  1386. * In order to read a register from the EEPROM, we need to shift
  1387. * 'count' bits in from the EEPROM. Bits are "shifted in" by raising
  1388. * the clock input to the EEPROM (setting the SK bit), and then reading
  1389. * the value of the "DO" bit. During this "shifting in" process the
  1390. * "DI" bit should always be clear.
  1391. */
  1392. eec = IXGBE_READ_REG(hw, IXGBE_EEC);
  1393. eec &= ~(IXGBE_EEC_DO | IXGBE_EEC_DI);
  1394. for (i = 0; i < count; i++) {
  1395. data = data << 1;
  1396. ixgbe_raise_eeprom_clk(hw, &eec);
  1397. eec = IXGBE_READ_REG(hw, IXGBE_EEC);
  1398. eec &= ~(IXGBE_EEC_DI);
  1399. if (eec & IXGBE_EEC_DO)
  1400. data |= 1;
  1401. ixgbe_lower_eeprom_clk(hw, &eec);
  1402. }
  1403. return data;
  1404. }
  1405. /**
  1406. * ixgbe_raise_eeprom_clk - Raises the EEPROM's clock input.
  1407. * @hw: pointer to hardware structure
  1408. * @eec: EEC register's current value
  1409. **/
  1410. static void ixgbe_raise_eeprom_clk(struct ixgbe_hw *hw, u32 *eec)
  1411. {
  1412. /*
  1413. * Raise the clock input to the EEPROM
  1414. * (setting the SK bit), then delay
  1415. */
  1416. *eec = *eec | IXGBE_EEC_SK;
  1417. IXGBE_WRITE_REG(hw, IXGBE_EEC, *eec);
  1418. IXGBE_WRITE_FLUSH(hw);
  1419. udelay(1);
  1420. }
  1421. /**
  1422. * ixgbe_lower_eeprom_clk - Lowers the EEPROM's clock input.
  1423. * @hw: pointer to hardware structure
  1424. * @eecd: EECD's current value
  1425. **/
  1426. static void ixgbe_lower_eeprom_clk(struct ixgbe_hw *hw, u32 *eec)
  1427. {
  1428. /*
  1429. * Lower the clock input to the EEPROM (clearing the SK bit), then
  1430. * delay
  1431. */
  1432. *eec = *eec & ~IXGBE_EEC_SK;
  1433. IXGBE_WRITE_REG(hw, IXGBE_EEC, *eec);
  1434. IXGBE_WRITE_FLUSH(hw);
  1435. udelay(1);
  1436. }
  1437. /**
  1438. * ixgbe_release_eeprom - Release EEPROM, release semaphores
  1439. * @hw: pointer to hardware structure
  1440. **/
  1441. static void ixgbe_release_eeprom(struct ixgbe_hw *hw)
  1442. {
  1443. u32 eec;
  1444. eec = IXGBE_READ_REG(hw, IXGBE_EEC);
  1445. eec |= IXGBE_EEC_CS; /* Pull CS high */
  1446. eec &= ~IXGBE_EEC_SK; /* Lower SCK */
  1447. IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
  1448. IXGBE_WRITE_FLUSH(hw);
  1449. udelay(1);
  1450. /* Stop requesting EEPROM access */
  1451. eec &= ~IXGBE_EEC_REQ;
  1452. IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
  1453. hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
  1454. /*
  1455. * Delay before attempt to obtain semaphore again to allow FW
  1456. * access. semaphore_delay is in ms we need us for usleep_range
  1457. */
  1458. usleep_range(hw->eeprom.semaphore_delay * 1000,
  1459. hw->eeprom.semaphore_delay * 2000);
  1460. }
  1461. /**
  1462. * ixgbe_calc_eeprom_checksum_generic - Calculates and returns the checksum
  1463. * @hw: pointer to hardware structure
  1464. **/
  1465. u16 ixgbe_calc_eeprom_checksum_generic(struct ixgbe_hw *hw)
  1466. {
  1467. u16 i;
  1468. u16 j;
  1469. u16 checksum = 0;
  1470. u16 length = 0;
  1471. u16 pointer = 0;
  1472. u16 word = 0;
  1473. /* Include 0x0-0x3F in the checksum */
  1474. for (i = 0; i < IXGBE_EEPROM_CHECKSUM; i++) {
  1475. if (hw->eeprom.ops.read(hw, i, &word) != 0) {
  1476. hw_dbg(hw, "EEPROM read failed\n");
  1477. break;
  1478. }
  1479. checksum += word;
  1480. }
  1481. /* Include all data from pointers except for the fw pointer */
  1482. for (i = IXGBE_PCIE_ANALOG_PTR; i < IXGBE_FW_PTR; i++) {
  1483. hw->eeprom.ops.read(hw, i, &pointer);
  1484. /* Make sure the pointer seems valid */
  1485. if (pointer != 0xFFFF && pointer != 0) {
  1486. hw->eeprom.ops.read(hw, pointer, &length);
  1487. if (length != 0xFFFF && length != 0) {
  1488. for (j = pointer+1; j <= pointer+length; j++) {
  1489. hw->eeprom.ops.read(hw, j, &word);
  1490. checksum += word;
  1491. }
  1492. }
  1493. }
  1494. }
  1495. checksum = (u16)IXGBE_EEPROM_SUM - checksum;
  1496. return checksum;
  1497. }
  1498. /**
  1499. * ixgbe_validate_eeprom_checksum_generic - Validate EEPROM checksum
  1500. * @hw: pointer to hardware structure
  1501. * @checksum_val: calculated checksum
  1502. *
  1503. * Performs checksum calculation and validates the EEPROM checksum. If the
  1504. * caller does not need checksum_val, the value can be NULL.
  1505. **/
  1506. s32 ixgbe_validate_eeprom_checksum_generic(struct ixgbe_hw *hw,
  1507. u16 *checksum_val)
  1508. {
  1509. s32 status;
  1510. u16 checksum;
  1511. u16 read_checksum = 0;
  1512. /*
  1513. * Read the first word from the EEPROM. If this times out or fails, do
  1514. * not continue or we could be in for a very long wait while every
  1515. * EEPROM read fails
  1516. */
  1517. status = hw->eeprom.ops.read(hw, 0, &checksum);
  1518. if (status == 0) {
  1519. checksum = hw->eeprom.ops.calc_checksum(hw);
  1520. hw->eeprom.ops.read(hw, IXGBE_EEPROM_CHECKSUM, &read_checksum);
  1521. /*
  1522. * Verify read checksum from EEPROM is the same as
  1523. * calculated checksum
  1524. */
  1525. if (read_checksum != checksum)
  1526. status = IXGBE_ERR_EEPROM_CHECKSUM;
  1527. /* If the user cares, return the calculated checksum */
  1528. if (checksum_val)
  1529. *checksum_val = checksum;
  1530. } else {
  1531. hw_dbg(hw, "EEPROM read failed\n");
  1532. }
  1533. return status;
  1534. }
  1535. /**
  1536. * ixgbe_update_eeprom_checksum_generic - Updates the EEPROM checksum
  1537. * @hw: pointer to hardware structure
  1538. **/
  1539. s32 ixgbe_update_eeprom_checksum_generic(struct ixgbe_hw *hw)
  1540. {
  1541. s32 status;
  1542. u16 checksum;
  1543. /*
  1544. * Read the first word from the EEPROM. If this times out or fails, do
  1545. * not continue or we could be in for a very long wait while every
  1546. * EEPROM read fails
  1547. */
  1548. status = hw->eeprom.ops.read(hw, 0, &checksum);
  1549. if (status == 0) {
  1550. checksum = hw->eeprom.ops.calc_checksum(hw);
  1551. status = hw->eeprom.ops.write(hw, IXGBE_EEPROM_CHECKSUM,
  1552. checksum);
  1553. } else {
  1554. hw_dbg(hw, "EEPROM read failed\n");
  1555. }
  1556. return status;
  1557. }
  1558. /**
  1559. * ixgbe_set_rar_generic - Set Rx address register
  1560. * @hw: pointer to hardware structure
  1561. * @index: Receive address register to write
  1562. * @addr: Address to put into receive address register
  1563. * @vmdq: VMDq "set" or "pool" index
  1564. * @enable_addr: set flag that address is active
  1565. *
  1566. * Puts an ethernet address into a receive address register.
  1567. **/
  1568. s32 ixgbe_set_rar_generic(struct ixgbe_hw *hw, u32 index, u8 *addr, u32 vmdq,
  1569. u32 enable_addr)
  1570. {
  1571. u32 rar_low, rar_high;
  1572. u32 rar_entries = hw->mac.num_rar_entries;
  1573. /* Make sure we are using a valid rar index range */
  1574. if (index >= rar_entries) {
  1575. hw_dbg(hw, "RAR index %d is out of range.\n", index);
  1576. return IXGBE_ERR_INVALID_ARGUMENT;
  1577. }
  1578. /* setup VMDq pool selection before this RAR gets enabled */
  1579. hw->mac.ops.set_vmdq(hw, index, vmdq);
  1580. /*
  1581. * HW expects these in little endian so we reverse the byte
  1582. * order from network order (big endian) to little endian
  1583. */
  1584. rar_low = ((u32)addr[0] |
  1585. ((u32)addr[1] << 8) |
  1586. ((u32)addr[2] << 16) |
  1587. ((u32)addr[3] << 24));
  1588. /*
  1589. * Some parts put the VMDq setting in the extra RAH bits,
  1590. * so save everything except the lower 16 bits that hold part
  1591. * of the address and the address valid bit.
  1592. */
  1593. rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index));
  1594. rar_high &= ~(0x0000FFFF | IXGBE_RAH_AV);
  1595. rar_high |= ((u32)addr[4] | ((u32)addr[5] << 8));
  1596. if (enable_addr != 0)
  1597. rar_high |= IXGBE_RAH_AV;
  1598. IXGBE_WRITE_REG(hw, IXGBE_RAL(index), rar_low);
  1599. IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high);
  1600. return 0;
  1601. }
  1602. /**
  1603. * ixgbe_clear_rar_generic - Remove Rx address register
  1604. * @hw: pointer to hardware structure
  1605. * @index: Receive address register to write
  1606. *
  1607. * Clears an ethernet address from a receive address register.
  1608. **/
  1609. s32 ixgbe_clear_rar_generic(struct ixgbe_hw *hw, u32 index)
  1610. {
  1611. u32 rar_high;
  1612. u32 rar_entries = hw->mac.num_rar_entries;
  1613. /* Make sure we are using a valid rar index range */
  1614. if (index >= rar_entries) {
  1615. hw_dbg(hw, "RAR index %d is out of range.\n", index);
  1616. return IXGBE_ERR_INVALID_ARGUMENT;
  1617. }
  1618. /*
  1619. * Some parts put the VMDq setting in the extra RAH bits,
  1620. * so save everything except the lower 16 bits that hold part
  1621. * of the address and the address valid bit.
  1622. */
  1623. rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index));
  1624. rar_high &= ~(0x0000FFFF | IXGBE_RAH_AV);
  1625. IXGBE_WRITE_REG(hw, IXGBE_RAL(index), 0);
  1626. IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high);
  1627. /* clear VMDq pool/queue selection for this RAR */
  1628. hw->mac.ops.clear_vmdq(hw, index, IXGBE_CLEAR_VMDQ_ALL);
  1629. return 0;
  1630. }
  1631. /**
  1632. * ixgbe_init_rx_addrs_generic - Initializes receive address filters.
  1633. * @hw: pointer to hardware structure
  1634. *
  1635. * Places the MAC address in receive address register 0 and clears the rest
  1636. * of the receive address registers. Clears the multicast table. Assumes
  1637. * the receiver is in reset when the routine is called.
  1638. **/
  1639. s32 ixgbe_init_rx_addrs_generic(struct ixgbe_hw *hw)
  1640. {
  1641. u32 i;
  1642. u32 rar_entries = hw->mac.num_rar_entries;
  1643. /*
  1644. * If the current mac address is valid, assume it is a software override
  1645. * to the permanent address.
  1646. * Otherwise, use the permanent address from the eeprom.
  1647. */
  1648. if (!is_valid_ether_addr(hw->mac.addr)) {
  1649. /* Get the MAC address from the RAR0 for later reference */
  1650. hw->mac.ops.get_mac_addr(hw, hw->mac.addr);
  1651. hw_dbg(hw, " Keeping Current RAR0 Addr =%pM\n", hw->mac.addr);
  1652. } else {
  1653. /* Setup the receive address. */
  1654. hw_dbg(hw, "Overriding MAC Address in RAR[0]\n");
  1655. hw_dbg(hw, " New MAC Addr =%pM\n", hw->mac.addr);
  1656. hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
  1657. /* clear VMDq pool/queue selection for RAR 0 */
  1658. hw->mac.ops.clear_vmdq(hw, 0, IXGBE_CLEAR_VMDQ_ALL);
  1659. }
  1660. hw->addr_ctrl.overflow_promisc = 0;
  1661. hw->addr_ctrl.rar_used_count = 1;
  1662. /* Zero out the other receive addresses. */
  1663. hw_dbg(hw, "Clearing RAR[1-%d]\n", rar_entries - 1);
  1664. for (i = 1; i < rar_entries; i++) {
  1665. IXGBE_WRITE_REG(hw, IXGBE_RAL(i), 0);
  1666. IXGBE_WRITE_REG(hw, IXGBE_RAH(i), 0);
  1667. }
  1668. /* Clear the MTA */
  1669. hw->addr_ctrl.mta_in_use = 0;
  1670. IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, hw->mac.mc_filter_type);
  1671. hw_dbg(hw, " Clearing MTA\n");
  1672. for (i = 0; i < hw->mac.mcft_size; i++)
  1673. IXGBE_WRITE_REG(hw, IXGBE_MTA(i), 0);
  1674. if (hw->mac.ops.init_uta_tables)
  1675. hw->mac.ops.init_uta_tables(hw);
  1676. return 0;
  1677. }
  1678. /**
  1679. * ixgbe_mta_vector - Determines bit-vector in multicast table to set
  1680. * @hw: pointer to hardware structure
  1681. * @mc_addr: the multicast address
  1682. *
  1683. * Extracts the 12 bits, from a multicast address, to determine which
  1684. * bit-vector to set in the multicast table. The hardware uses 12 bits, from
  1685. * incoming rx multicast addresses, to determine the bit-vector to check in
  1686. * the MTA. Which of the 4 combination, of 12-bits, the hardware uses is set
  1687. * by the MO field of the MCSTCTRL. The MO field is set during initialization
  1688. * to mc_filter_type.
  1689. **/
  1690. static s32 ixgbe_mta_vector(struct ixgbe_hw *hw, u8 *mc_addr)
  1691. {
  1692. u32 vector = 0;
  1693. switch (hw->mac.mc_filter_type) {
  1694. case 0: /* use bits [47:36] of the address */
  1695. vector = ((mc_addr[4] >> 4) | (((u16)mc_addr[5]) << 4));
  1696. break;
  1697. case 1: /* use bits [46:35] of the address */
  1698. vector = ((mc_addr[4] >> 3) | (((u16)mc_addr[5]) << 5));
  1699. break;
  1700. case 2: /* use bits [45:34] of the address */
  1701. vector = ((mc_addr[4] >> 2) | (((u16)mc_addr[5]) << 6));
  1702. break;
  1703. case 3: /* use bits [43:32] of the address */
  1704. vector = ((mc_addr[4]) | (((u16)mc_addr[5]) << 8));
  1705. break;
  1706. default: /* Invalid mc_filter_type */
  1707. hw_dbg(hw, "MC filter type param set incorrectly\n");
  1708. break;
  1709. }
  1710. /* vector can only be 12-bits or boundary will be exceeded */
  1711. vector &= 0xFFF;
  1712. return vector;
  1713. }
  1714. /**
  1715. * ixgbe_set_mta - Set bit-vector in multicast table
  1716. * @hw: pointer to hardware structure
  1717. * @hash_value: Multicast address hash value
  1718. *
  1719. * Sets the bit-vector in the multicast table.
  1720. **/
  1721. static void ixgbe_set_mta(struct ixgbe_hw *hw, u8 *mc_addr)
  1722. {
  1723. u32 vector;
  1724. u32 vector_bit;
  1725. u32 vector_reg;
  1726. hw->addr_ctrl.mta_in_use++;
  1727. vector = ixgbe_mta_vector(hw, mc_addr);
  1728. hw_dbg(hw, " bit-vector = 0x%03X\n", vector);
  1729. /*
  1730. * The MTA is a register array of 128 32-bit registers. It is treated
  1731. * like an array of 4096 bits. We want to set bit
  1732. * BitArray[vector_value]. So we figure out what register the bit is
  1733. * in, read it, OR in the new bit, then write back the new value. The
  1734. * register is determined by the upper 7 bits of the vector value and
  1735. * the bit within that register are determined by the lower 5 bits of
  1736. * the value.
  1737. */
  1738. vector_reg = (vector >> 5) & 0x7F;
  1739. vector_bit = vector & 0x1F;
  1740. hw->mac.mta_shadow[vector_reg] |= (1 << vector_bit);
  1741. }
  1742. /**
  1743. * ixgbe_update_mc_addr_list_generic - Updates MAC list of multicast addresses
  1744. * @hw: pointer to hardware structure
  1745. * @netdev: pointer to net device structure
  1746. *
  1747. * The given list replaces any existing list. Clears the MC addrs from receive
  1748. * address registers and the multicast table. Uses unused receive address
  1749. * registers for the first multicast addresses, and hashes the rest into the
  1750. * multicast table.
  1751. **/
  1752. s32 ixgbe_update_mc_addr_list_generic(struct ixgbe_hw *hw,
  1753. struct net_device *netdev)
  1754. {
  1755. struct netdev_hw_addr *ha;
  1756. u32 i;
  1757. /*
  1758. * Set the new number of MC addresses that we are being requested to
  1759. * use.
  1760. */
  1761. hw->addr_ctrl.num_mc_addrs = netdev_mc_count(netdev);
  1762. hw->addr_ctrl.mta_in_use = 0;
  1763. /* Clear mta_shadow */
  1764. hw_dbg(hw, " Clearing MTA\n");
  1765. memset(&hw->mac.mta_shadow, 0, sizeof(hw->mac.mta_shadow));
  1766. /* Update mta shadow */
  1767. netdev_for_each_mc_addr(ha, netdev) {
  1768. hw_dbg(hw, " Adding the multicast addresses:\n");
  1769. ixgbe_set_mta(hw, ha->addr);
  1770. }
  1771. /* Enable mta */
  1772. for (i = 0; i < hw->mac.mcft_size; i++)
  1773. IXGBE_WRITE_REG_ARRAY(hw, IXGBE_MTA(0), i,
  1774. hw->mac.mta_shadow[i]);
  1775. if (hw->addr_ctrl.mta_in_use > 0)
  1776. IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL,
  1777. IXGBE_MCSTCTRL_MFE | hw->mac.mc_filter_type);
  1778. hw_dbg(hw, "ixgbe_update_mc_addr_list_generic Complete\n");
  1779. return 0;
  1780. }
  1781. /**
  1782. * ixgbe_enable_mc_generic - Enable multicast address in RAR
  1783. * @hw: pointer to hardware structure
  1784. *
  1785. * Enables multicast address in RAR and the use of the multicast hash table.
  1786. **/
  1787. s32 ixgbe_enable_mc_generic(struct ixgbe_hw *hw)
  1788. {
  1789. struct ixgbe_addr_filter_info *a = &hw->addr_ctrl;
  1790. if (a->mta_in_use > 0)
  1791. IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, IXGBE_MCSTCTRL_MFE |
  1792. hw->mac.mc_filter_type);
  1793. return 0;
  1794. }
  1795. /**
  1796. * ixgbe_disable_mc_generic - Disable multicast address in RAR
  1797. * @hw: pointer to hardware structure
  1798. *
  1799. * Disables multicast address in RAR and the use of the multicast hash table.
  1800. **/
  1801. s32 ixgbe_disable_mc_generic(struct ixgbe_hw *hw)
  1802. {
  1803. struct ixgbe_addr_filter_info *a = &hw->addr_ctrl;
  1804. if (a->mta_in_use > 0)
  1805. IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, hw->mac.mc_filter_type);
  1806. return 0;
  1807. }
  1808. /**
  1809. * ixgbe_fc_enable_generic - Enable flow control
  1810. * @hw: pointer to hardware structure
  1811. *
  1812. * Enable flow control according to the current settings.
  1813. **/
  1814. s32 ixgbe_fc_enable_generic(struct ixgbe_hw *hw)
  1815. {
  1816. s32 ret_val = 0;
  1817. u32 mflcn_reg, fccfg_reg;
  1818. u32 reg;
  1819. u32 fcrtl, fcrth;
  1820. int i;
  1821. /*
  1822. * Validate the water mark configuration for packet buffer 0. Zero
  1823. * water marks indicate that the packet buffer was not configured
  1824. * and the watermarks for packet buffer 0 should always be configured.
  1825. */
  1826. if (!hw->fc.low_water ||
  1827. !hw->fc.high_water[0] ||
  1828. !hw->fc.pause_time) {
  1829. hw_dbg(hw, "Invalid water mark configuration\n");
  1830. ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
  1831. goto out;
  1832. }
  1833. /* Negotiate the fc mode to use */
  1834. ixgbe_fc_autoneg(hw);
  1835. /* Disable any previous flow control settings */
  1836. mflcn_reg = IXGBE_READ_REG(hw, IXGBE_MFLCN);
  1837. mflcn_reg &= ~(IXGBE_MFLCN_RPFCE_MASK | IXGBE_MFLCN_RFCE);
  1838. fccfg_reg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
  1839. fccfg_reg &= ~(IXGBE_FCCFG_TFCE_802_3X | IXGBE_FCCFG_TFCE_PRIORITY);
  1840. /*
  1841. * The possible values of fc.current_mode are:
  1842. * 0: Flow control is completely disabled
  1843. * 1: Rx flow control is enabled (we can receive pause frames,
  1844. * but not send pause frames).
  1845. * 2: Tx flow control is enabled (we can send pause frames but
  1846. * we do not support receiving pause frames).
  1847. * 3: Both Rx and Tx flow control (symmetric) are enabled.
  1848. * other: Invalid.
  1849. */
  1850. switch (hw->fc.current_mode) {
  1851. case ixgbe_fc_none:
  1852. /*
  1853. * Flow control is disabled by software override or autoneg.
  1854. * The code below will actually disable it in the HW.
  1855. */
  1856. break;
  1857. case ixgbe_fc_rx_pause:
  1858. /*
  1859. * Rx Flow control is enabled and Tx Flow control is
  1860. * disabled by software override. Since there really
  1861. * isn't a way to advertise that we are capable of RX
  1862. * Pause ONLY, we will advertise that we support both
  1863. * symmetric and asymmetric Rx PAUSE. Later, we will
  1864. * disable the adapter's ability to send PAUSE frames.
  1865. */
  1866. mflcn_reg |= IXGBE_MFLCN_RFCE;
  1867. break;
  1868. case ixgbe_fc_tx_pause:
  1869. /*
  1870. * Tx Flow control is enabled, and Rx Flow control is
  1871. * disabled by software override.
  1872. */
  1873. fccfg_reg |= IXGBE_FCCFG_TFCE_802_3X;
  1874. break;
  1875. case ixgbe_fc_full:
  1876. /* Flow control (both Rx and Tx) is enabled by SW override. */
  1877. mflcn_reg |= IXGBE_MFLCN_RFCE;
  1878. fccfg_reg |= IXGBE_FCCFG_TFCE_802_3X;
  1879. break;
  1880. default:
  1881. hw_dbg(hw, "Flow control param set incorrectly\n");
  1882. ret_val = IXGBE_ERR_CONFIG;
  1883. goto out;
  1884. break;
  1885. }
  1886. /* Set 802.3x based flow control settings. */
  1887. mflcn_reg |= IXGBE_MFLCN_DPF;
  1888. IXGBE_WRITE_REG(hw, IXGBE_MFLCN, mflcn_reg);
  1889. IXGBE_WRITE_REG(hw, IXGBE_FCCFG, fccfg_reg);
  1890. fcrtl = (hw->fc.low_water << 10) | IXGBE_FCRTL_XONE;
  1891. /* Set up and enable Rx high/low water mark thresholds, enable XON. */
  1892. for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
  1893. if ((hw->fc.current_mode & ixgbe_fc_tx_pause) &&
  1894. hw->fc.high_water[i]) {
  1895. IXGBE_WRITE_REG(hw, IXGBE_FCRTL_82599(i), fcrtl);
  1896. fcrth = (hw->fc.high_water[i] << 10) | IXGBE_FCRTH_FCEN;
  1897. } else {
  1898. IXGBE_WRITE_REG(hw, IXGBE_FCRTL_82599(i), 0);
  1899. /*
  1900. * In order to prevent Tx hangs when the internal Tx
  1901. * switch is enabled we must set the high water mark
  1902. * to the maximum FCRTH value. This allows the Tx
  1903. * switch to function even under heavy Rx workloads.
  1904. */
  1905. fcrth = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(i)) - 32;
  1906. }
  1907. IXGBE_WRITE_REG(hw, IXGBE_FCRTH_82599(i), fcrth);
  1908. }
  1909. /* Configure pause time (2 TCs per register) */
  1910. reg = hw->fc.pause_time * 0x00010001;
  1911. for (i = 0; i < (MAX_TRAFFIC_CLASS / 2); i++)
  1912. IXGBE_WRITE_REG(hw, IXGBE_FCTTV(i), reg);
  1913. IXGBE_WRITE_REG(hw, IXGBE_FCRTV, hw->fc.pause_time / 2);
  1914. out:
  1915. return ret_val;
  1916. }
  1917. /**
  1918. * ixgbe_negotiate_fc - Negotiate flow control
  1919. * @hw: pointer to hardware structure
  1920. * @adv_reg: flow control advertised settings
  1921. * @lp_reg: link partner's flow control settings
  1922. * @adv_sym: symmetric pause bit in advertisement
  1923. * @adv_asm: asymmetric pause bit in advertisement
  1924. * @lp_sym: symmetric pause bit in link partner advertisement
  1925. * @lp_asm: asymmetric pause bit in link partner advertisement
  1926. *
  1927. * Find the intersection between advertised settings and link partner's
  1928. * advertised settings
  1929. **/
  1930. static s32 ixgbe_negotiate_fc(struct ixgbe_hw *hw, u32 adv_reg, u32 lp_reg,
  1931. u32 adv_sym, u32 adv_asm, u32 lp_sym, u32 lp_asm)
  1932. {
  1933. if ((!(adv_reg)) || (!(lp_reg)))
  1934. return IXGBE_ERR_FC_NOT_NEGOTIATED;
  1935. if ((adv_reg & adv_sym) && (lp_reg & lp_sym)) {
  1936. /*
  1937. * Now we need to check if the user selected Rx ONLY
  1938. * of pause frames. In this case, we had to advertise
  1939. * FULL flow control because we could not advertise RX
  1940. * ONLY. Hence, we must now check to see if we need to
  1941. * turn OFF the TRANSMISSION of PAUSE frames.
  1942. */
  1943. if (hw->fc.requested_mode == ixgbe_fc_full) {
  1944. hw->fc.current_mode = ixgbe_fc_full;
  1945. hw_dbg(hw, "Flow Control = FULL.\n");
  1946. } else {
  1947. hw->fc.current_mode = ixgbe_fc_rx_pause;
  1948. hw_dbg(hw, "Flow Control=RX PAUSE frames only\n");
  1949. }
  1950. } else if (!(adv_reg & adv_sym) && (adv_reg & adv_asm) &&
  1951. (lp_reg & lp_sym) && (lp_reg & lp_asm)) {
  1952. hw->fc.current_mode = ixgbe_fc_tx_pause;
  1953. hw_dbg(hw, "Flow Control = TX PAUSE frames only.\n");
  1954. } else if ((adv_reg & adv_sym) && (adv_reg & adv_asm) &&
  1955. !(lp_reg & lp_sym) && (lp_reg & lp_asm)) {
  1956. hw->fc.current_mode = ixgbe_fc_rx_pause;
  1957. hw_dbg(hw, "Flow Control = RX PAUSE frames only.\n");
  1958. } else {
  1959. hw->fc.current_mode = ixgbe_fc_none;
  1960. hw_dbg(hw, "Flow Control = NONE.\n");
  1961. }
  1962. return 0;
  1963. }
  1964. /**
  1965. * ixgbe_fc_autoneg_fiber - Enable flow control on 1 gig fiber
  1966. * @hw: pointer to hardware structure
  1967. *
  1968. * Enable flow control according on 1 gig fiber.
  1969. **/
  1970. static s32 ixgbe_fc_autoneg_fiber(struct ixgbe_hw *hw)
  1971. {
  1972. u32 pcs_anadv_reg, pcs_lpab_reg, linkstat;
  1973. s32 ret_val = IXGBE_ERR_FC_NOT_NEGOTIATED;
  1974. /*
  1975. * On multispeed fiber at 1g, bail out if
  1976. * - link is up but AN did not complete, or if
  1977. * - link is up and AN completed but timed out
  1978. */
  1979. linkstat = IXGBE_READ_REG(hw, IXGBE_PCS1GLSTA);
  1980. if ((!!(linkstat & IXGBE_PCS1GLSTA_AN_COMPLETE) == 0) ||
  1981. (!!(linkstat & IXGBE_PCS1GLSTA_AN_TIMED_OUT) == 1))
  1982. goto out;
  1983. pcs_anadv_reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANA);
  1984. pcs_lpab_reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANLP);
  1985. ret_val = ixgbe_negotiate_fc(hw, pcs_anadv_reg,
  1986. pcs_lpab_reg, IXGBE_PCS1GANA_SYM_PAUSE,
  1987. IXGBE_PCS1GANA_ASM_PAUSE,
  1988. IXGBE_PCS1GANA_SYM_PAUSE,
  1989. IXGBE_PCS1GANA_ASM_PAUSE);
  1990. out:
  1991. return ret_val;
  1992. }
  1993. /**
  1994. * ixgbe_fc_autoneg_backplane - Enable flow control IEEE clause 37
  1995. * @hw: pointer to hardware structure
  1996. *
  1997. * Enable flow control according to IEEE clause 37.
  1998. **/
  1999. static s32 ixgbe_fc_autoneg_backplane(struct ixgbe_hw *hw)
  2000. {
  2001. u32 links2, anlp1_reg, autoc_reg, links;
  2002. s32 ret_val = IXGBE_ERR_FC_NOT_NEGOTIATED;
  2003. /*
  2004. * On backplane, bail out if
  2005. * - backplane autoneg was not completed, or if
  2006. * - we are 82599 and link partner is not AN enabled
  2007. */
  2008. links = IXGBE_READ_REG(hw, IXGBE_LINKS);
  2009. if ((links & IXGBE_LINKS_KX_AN_COMP) == 0)
  2010. goto out;
  2011. if (hw->mac.type == ixgbe_mac_82599EB) {
  2012. links2 = IXGBE_READ_REG(hw, IXGBE_LINKS2);
  2013. if ((links2 & IXGBE_LINKS2_AN_SUPPORTED) == 0)
  2014. goto out;
  2015. }
  2016. /*
  2017. * Read the 10g AN autoc and LP ability registers and resolve
  2018. * local flow control settings accordingly
  2019. */
  2020. autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  2021. anlp1_reg = IXGBE_READ_REG(hw, IXGBE_ANLP1);
  2022. ret_val = ixgbe_negotiate_fc(hw, autoc_reg,
  2023. anlp1_reg, IXGBE_AUTOC_SYM_PAUSE, IXGBE_AUTOC_ASM_PAUSE,
  2024. IXGBE_ANLP1_SYM_PAUSE, IXGBE_ANLP1_ASM_PAUSE);
  2025. out:
  2026. return ret_val;
  2027. }
  2028. /**
  2029. * ixgbe_fc_autoneg_copper - Enable flow control IEEE clause 37
  2030. * @hw: pointer to hardware structure
  2031. *
  2032. * Enable flow control according to IEEE clause 37.
  2033. **/
  2034. static s32 ixgbe_fc_autoneg_copper(struct ixgbe_hw *hw)
  2035. {
  2036. u16 technology_ability_reg = 0;
  2037. u16 lp_technology_ability_reg = 0;
  2038. hw->phy.ops.read_reg(hw, MDIO_AN_ADVERTISE,
  2039. MDIO_MMD_AN,
  2040. &technology_ability_reg);
  2041. hw->phy.ops.read_reg(hw, MDIO_AN_LPA,
  2042. MDIO_MMD_AN,
  2043. &lp_technology_ability_reg);
  2044. return ixgbe_negotiate_fc(hw, (u32)technology_ability_reg,
  2045. (u32)lp_technology_ability_reg,
  2046. IXGBE_TAF_SYM_PAUSE, IXGBE_TAF_ASM_PAUSE,
  2047. IXGBE_TAF_SYM_PAUSE, IXGBE_TAF_ASM_PAUSE);
  2048. }
  2049. /**
  2050. * ixgbe_fc_autoneg - Configure flow control
  2051. * @hw: pointer to hardware structure
  2052. *
  2053. * Compares our advertised flow control capabilities to those advertised by
  2054. * our link partner, and determines the proper flow control mode to use.
  2055. **/
  2056. void ixgbe_fc_autoneg(struct ixgbe_hw *hw)
  2057. {
  2058. s32 ret_val = IXGBE_ERR_FC_NOT_NEGOTIATED;
  2059. ixgbe_link_speed speed;
  2060. bool link_up;
  2061. /*
  2062. * AN should have completed when the cable was plugged in.
  2063. * Look for reasons to bail out. Bail out if:
  2064. * - FC autoneg is disabled, or if
  2065. * - link is not up.
  2066. *
  2067. * Since we're being called from an LSC, link is already known to be up.
  2068. * So use link_up_wait_to_complete=false.
  2069. */
  2070. if (hw->fc.disable_fc_autoneg)
  2071. goto out;
  2072. hw->mac.ops.check_link(hw, &speed, &link_up, false);
  2073. if (!link_up)
  2074. goto out;
  2075. switch (hw->phy.media_type) {
  2076. /* Autoneg flow control on fiber adapters */
  2077. case ixgbe_media_type_fiber_fixed:
  2078. case ixgbe_media_type_fiber:
  2079. if (speed == IXGBE_LINK_SPEED_1GB_FULL)
  2080. ret_val = ixgbe_fc_autoneg_fiber(hw);
  2081. break;
  2082. /* Autoneg flow control on backplane adapters */
  2083. case ixgbe_media_type_backplane:
  2084. ret_val = ixgbe_fc_autoneg_backplane(hw);
  2085. break;
  2086. /* Autoneg flow control on copper adapters */
  2087. case ixgbe_media_type_copper:
  2088. if (ixgbe_device_supports_autoneg_fc(hw))
  2089. ret_val = ixgbe_fc_autoneg_copper(hw);
  2090. break;
  2091. default:
  2092. break;
  2093. }
  2094. out:
  2095. if (ret_val == 0) {
  2096. hw->fc.fc_was_autonegged = true;
  2097. } else {
  2098. hw->fc.fc_was_autonegged = false;
  2099. hw->fc.current_mode = hw->fc.requested_mode;
  2100. }
  2101. }
  2102. /**
  2103. * ixgbe_disable_pcie_master - Disable PCI-express master access
  2104. * @hw: pointer to hardware structure
  2105. *
  2106. * Disables PCI-Express master access and verifies there are no pending
  2107. * requests. IXGBE_ERR_MASTER_REQUESTS_PENDING is returned if master disable
  2108. * bit hasn't caused the master requests to be disabled, else 0
  2109. * is returned signifying master requests disabled.
  2110. **/
  2111. static s32 ixgbe_disable_pcie_master(struct ixgbe_hw *hw)
  2112. {
  2113. struct ixgbe_adapter *adapter = hw->back;
  2114. s32 status = 0;
  2115. u32 i;
  2116. u16 value;
  2117. /* Always set this bit to ensure any future transactions are blocked */
  2118. IXGBE_WRITE_REG(hw, IXGBE_CTRL, IXGBE_CTRL_GIO_DIS);
  2119. /* Exit if master requests are blocked */
  2120. if (!(IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_GIO))
  2121. goto out;
  2122. /* Poll for master request bit to clear */
  2123. for (i = 0; i < IXGBE_PCI_MASTER_DISABLE_TIMEOUT; i++) {
  2124. udelay(100);
  2125. if (!(IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_GIO))
  2126. goto out;
  2127. }
  2128. /*
  2129. * Two consecutive resets are required via CTRL.RST per datasheet
  2130. * 5.2.5.3.2 Master Disable. We set a flag to inform the reset routine
  2131. * of this need. The first reset prevents new master requests from
  2132. * being issued by our device. We then must wait 1usec or more for any
  2133. * remaining completions from the PCIe bus to trickle in, and then reset
  2134. * again to clear out any effects they may have had on our device.
  2135. */
  2136. hw_dbg(hw, "GIO Master Disable bit didn't clear - requesting resets\n");
  2137. hw->mac.flags |= IXGBE_FLAGS_DOUBLE_RESET_REQUIRED;
  2138. /*
  2139. * Before proceeding, make sure that the PCIe block does not have
  2140. * transactions pending.
  2141. */
  2142. for (i = 0; i < IXGBE_PCI_MASTER_DISABLE_TIMEOUT; i++) {
  2143. udelay(100);
  2144. pci_read_config_word(adapter->pdev, IXGBE_PCI_DEVICE_STATUS,
  2145. &value);
  2146. if (!(value & IXGBE_PCI_DEVICE_STATUS_TRANSACTION_PENDING))
  2147. goto out;
  2148. }
  2149. hw_dbg(hw, "PCIe transaction pending bit also did not clear.\n");
  2150. status = IXGBE_ERR_MASTER_REQUESTS_PENDING;
  2151. out:
  2152. return status;
  2153. }
  2154. /**
  2155. * ixgbe_acquire_swfw_sync - Acquire SWFW semaphore
  2156. * @hw: pointer to hardware structure
  2157. * @mask: Mask to specify which semaphore to acquire
  2158. *
  2159. * Acquires the SWFW semaphore through the GSSR register for the specified
  2160. * function (CSR, PHY0, PHY1, EEPROM, Flash)
  2161. **/
  2162. s32 ixgbe_acquire_swfw_sync(struct ixgbe_hw *hw, u16 mask)
  2163. {
  2164. u32 gssr = 0;
  2165. u32 swmask = mask;
  2166. u32 fwmask = mask << 5;
  2167. u32 timeout = 200;
  2168. u32 i;
  2169. for (i = 0; i < timeout; i++) {
  2170. /*
  2171. * SW NVM semaphore bit is used for access to all
  2172. * SW_FW_SYNC bits (not just NVM)
  2173. */
  2174. if (ixgbe_get_eeprom_semaphore(hw))
  2175. return IXGBE_ERR_SWFW_SYNC;
  2176. gssr = IXGBE_READ_REG(hw, IXGBE_GSSR);
  2177. if (!(gssr & (fwmask | swmask))) {
  2178. gssr |= swmask;
  2179. IXGBE_WRITE_REG(hw, IXGBE_GSSR, gssr);
  2180. ixgbe_release_eeprom_semaphore(hw);
  2181. return 0;
  2182. } else {
  2183. /* Resource is currently in use by FW or SW */
  2184. ixgbe_release_eeprom_semaphore(hw);
  2185. usleep_range(5000, 10000);
  2186. }
  2187. }
  2188. /* If time expired clear the bits holding the lock and retry */
  2189. if (gssr & (fwmask | swmask))
  2190. ixgbe_release_swfw_sync(hw, gssr & (fwmask | swmask));
  2191. usleep_range(5000, 10000);
  2192. return IXGBE_ERR_SWFW_SYNC;
  2193. }
  2194. /**
  2195. * ixgbe_release_swfw_sync - Release SWFW semaphore
  2196. * @hw: pointer to hardware structure
  2197. * @mask: Mask to specify which semaphore to release
  2198. *
  2199. * Releases the SWFW semaphore through the GSSR register for the specified
  2200. * function (CSR, PHY0, PHY1, EEPROM, Flash)
  2201. **/
  2202. void ixgbe_release_swfw_sync(struct ixgbe_hw *hw, u16 mask)
  2203. {
  2204. u32 gssr;
  2205. u32 swmask = mask;
  2206. ixgbe_get_eeprom_semaphore(hw);
  2207. gssr = IXGBE_READ_REG(hw, IXGBE_GSSR);
  2208. gssr &= ~swmask;
  2209. IXGBE_WRITE_REG(hw, IXGBE_GSSR, gssr);
  2210. ixgbe_release_eeprom_semaphore(hw);
  2211. }
  2212. /**
  2213. * ixgbe_disable_rx_buff_generic - Stops the receive data path
  2214. * @hw: pointer to hardware structure
  2215. *
  2216. * Stops the receive data path and waits for the HW to internally
  2217. * empty the Rx security block.
  2218. **/
  2219. s32 ixgbe_disable_rx_buff_generic(struct ixgbe_hw *hw)
  2220. {
  2221. #define IXGBE_MAX_SECRX_POLL 40
  2222. int i;
  2223. int secrxreg;
  2224. secrxreg = IXGBE_READ_REG(hw, IXGBE_SECRXCTRL);
  2225. secrxreg |= IXGBE_SECRXCTRL_RX_DIS;
  2226. IXGBE_WRITE_REG(hw, IXGBE_SECRXCTRL, secrxreg);
  2227. for (i = 0; i < IXGBE_MAX_SECRX_POLL; i++) {
  2228. secrxreg = IXGBE_READ_REG(hw, IXGBE_SECRXSTAT);
  2229. if (secrxreg & IXGBE_SECRXSTAT_SECRX_RDY)
  2230. break;
  2231. else
  2232. /* Use interrupt-safe sleep just in case */
  2233. udelay(1000);
  2234. }
  2235. /* For informational purposes only */
  2236. if (i >= IXGBE_MAX_SECRX_POLL)
  2237. hw_dbg(hw, "Rx unit being enabled before security "
  2238. "path fully disabled. Continuing with init.\n");
  2239. return 0;
  2240. }
  2241. /**
  2242. * ixgbe_enable_rx_buff - Enables the receive data path
  2243. * @hw: pointer to hardware structure
  2244. *
  2245. * Enables the receive data path
  2246. **/
  2247. s32 ixgbe_enable_rx_buff_generic(struct ixgbe_hw *hw)
  2248. {
  2249. int secrxreg;
  2250. secrxreg = IXGBE_READ_REG(hw, IXGBE_SECRXCTRL);
  2251. secrxreg &= ~IXGBE_SECRXCTRL_RX_DIS;
  2252. IXGBE_WRITE_REG(hw, IXGBE_SECRXCTRL, secrxreg);
  2253. IXGBE_WRITE_FLUSH(hw);
  2254. return 0;
  2255. }
  2256. /**
  2257. * ixgbe_enable_rx_dma_generic - Enable the Rx DMA unit
  2258. * @hw: pointer to hardware structure
  2259. * @regval: register value to write to RXCTRL
  2260. *
  2261. * Enables the Rx DMA unit
  2262. **/
  2263. s32 ixgbe_enable_rx_dma_generic(struct ixgbe_hw *hw, u32 regval)
  2264. {
  2265. IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, regval);
  2266. return 0;
  2267. }
  2268. /**
  2269. * ixgbe_blink_led_start_generic - Blink LED based on index.
  2270. * @hw: pointer to hardware structure
  2271. * @index: led number to blink
  2272. **/
  2273. s32 ixgbe_blink_led_start_generic(struct ixgbe_hw *hw, u32 index)
  2274. {
  2275. ixgbe_link_speed speed = 0;
  2276. bool link_up = false;
  2277. u32 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  2278. u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
  2279. s32 ret_val = 0;
  2280. /*
  2281. * Link must be up to auto-blink the LEDs;
  2282. * Force it if link is down.
  2283. */
  2284. hw->mac.ops.check_link(hw, &speed, &link_up, false);
  2285. if (!link_up) {
  2286. /* Need the SW/FW semaphore around AUTOC writes if 82599 and
  2287. * LESM is on.
  2288. */
  2289. bool got_lock = false;
  2290. if ((hw->mac.type == ixgbe_mac_82599EB) &&
  2291. ixgbe_verify_lesm_fw_enabled_82599(hw)) {
  2292. ret_val = hw->mac.ops.acquire_swfw_sync(hw,
  2293. IXGBE_GSSR_MAC_CSR_SM);
  2294. if (ret_val)
  2295. goto out;
  2296. got_lock = true;
  2297. }
  2298. autoc_reg |= IXGBE_AUTOC_AN_RESTART;
  2299. autoc_reg |= IXGBE_AUTOC_FLU;
  2300. IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg);
  2301. IXGBE_WRITE_FLUSH(hw);
  2302. if (got_lock)
  2303. hw->mac.ops.release_swfw_sync(hw,
  2304. IXGBE_GSSR_MAC_CSR_SM);
  2305. usleep_range(10000, 20000);
  2306. }
  2307. led_reg &= ~IXGBE_LED_MODE_MASK(index);
  2308. led_reg |= IXGBE_LED_BLINK(index);
  2309. IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
  2310. IXGBE_WRITE_FLUSH(hw);
  2311. out:
  2312. return ret_val;
  2313. }
  2314. /**
  2315. * ixgbe_blink_led_stop_generic - Stop blinking LED based on index.
  2316. * @hw: pointer to hardware structure
  2317. * @index: led number to stop blinking
  2318. **/
  2319. s32 ixgbe_blink_led_stop_generic(struct ixgbe_hw *hw, u32 index)
  2320. {
  2321. u32 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  2322. u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
  2323. s32 ret_val = 0;
  2324. bool got_lock = false;
  2325. /* Need the SW/FW semaphore around AUTOC writes if 82599 and
  2326. * LESM is on.
  2327. */
  2328. if ((hw->mac.type == ixgbe_mac_82599EB) &&
  2329. ixgbe_verify_lesm_fw_enabled_82599(hw)) {
  2330. ret_val = hw->mac.ops.acquire_swfw_sync(hw,
  2331. IXGBE_GSSR_MAC_CSR_SM);
  2332. if (ret_val)
  2333. goto out;
  2334. got_lock = true;
  2335. }
  2336. autoc_reg &= ~IXGBE_AUTOC_FLU;
  2337. autoc_reg |= IXGBE_AUTOC_AN_RESTART;
  2338. IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg);
  2339. if (hw->mac.type == ixgbe_mac_82599EB)
  2340. ixgbe_reset_pipeline_82599(hw);
  2341. if (got_lock)
  2342. hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_MAC_CSR_SM);
  2343. led_reg &= ~IXGBE_LED_MODE_MASK(index);
  2344. led_reg &= ~IXGBE_LED_BLINK(index);
  2345. led_reg |= IXGBE_LED_LINK_ACTIVE << IXGBE_LED_MODE_SHIFT(index);
  2346. IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
  2347. IXGBE_WRITE_FLUSH(hw);
  2348. out:
  2349. return ret_val;
  2350. }
  2351. /**
  2352. * ixgbe_get_san_mac_addr_offset - Get SAN MAC address offset from the EEPROM
  2353. * @hw: pointer to hardware structure
  2354. * @san_mac_offset: SAN MAC address offset
  2355. *
  2356. * This function will read the EEPROM location for the SAN MAC address
  2357. * pointer, and returns the value at that location. This is used in both
  2358. * get and set mac_addr routines.
  2359. **/
  2360. static s32 ixgbe_get_san_mac_addr_offset(struct ixgbe_hw *hw,
  2361. u16 *san_mac_offset)
  2362. {
  2363. s32 ret_val;
  2364. /*
  2365. * First read the EEPROM pointer to see if the MAC addresses are
  2366. * available.
  2367. */
  2368. ret_val = hw->eeprom.ops.read(hw, IXGBE_SAN_MAC_ADDR_PTR,
  2369. san_mac_offset);
  2370. if (ret_val)
  2371. hw_err(hw, "eeprom read at offset %d failed\n",
  2372. IXGBE_SAN_MAC_ADDR_PTR);
  2373. return ret_val;
  2374. }
  2375. /**
  2376. * ixgbe_get_san_mac_addr_generic - SAN MAC address retrieval from the EEPROM
  2377. * @hw: pointer to hardware structure
  2378. * @san_mac_addr: SAN MAC address
  2379. *
  2380. * Reads the SAN MAC address from the EEPROM, if it's available. This is
  2381. * per-port, so set_lan_id() must be called before reading the addresses.
  2382. * set_lan_id() is called by identify_sfp(), but this cannot be relied
  2383. * upon for non-SFP connections, so we must call it here.
  2384. **/
  2385. s32 ixgbe_get_san_mac_addr_generic(struct ixgbe_hw *hw, u8 *san_mac_addr)
  2386. {
  2387. u16 san_mac_data, san_mac_offset;
  2388. u8 i;
  2389. s32 ret_val;
  2390. /*
  2391. * First read the EEPROM pointer to see if the MAC addresses are
  2392. * available. If they're not, no point in calling set_lan_id() here.
  2393. */
  2394. ret_val = ixgbe_get_san_mac_addr_offset(hw, &san_mac_offset);
  2395. if (ret_val || san_mac_offset == 0 || san_mac_offset == 0xFFFF)
  2396. goto san_mac_addr_clr;
  2397. /* make sure we know which port we need to program */
  2398. hw->mac.ops.set_lan_id(hw);
  2399. /* apply the port offset to the address offset */
  2400. (hw->bus.func) ? (san_mac_offset += IXGBE_SAN_MAC_ADDR_PORT1_OFFSET) :
  2401. (san_mac_offset += IXGBE_SAN_MAC_ADDR_PORT0_OFFSET);
  2402. for (i = 0; i < 3; i++) {
  2403. ret_val = hw->eeprom.ops.read(hw, san_mac_offset,
  2404. &san_mac_data);
  2405. if (ret_val) {
  2406. hw_err(hw, "eeprom read at offset %d failed\n",
  2407. san_mac_offset);
  2408. goto san_mac_addr_clr;
  2409. }
  2410. san_mac_addr[i * 2] = (u8)(san_mac_data);
  2411. san_mac_addr[i * 2 + 1] = (u8)(san_mac_data >> 8);
  2412. san_mac_offset++;
  2413. }
  2414. return 0;
  2415. san_mac_addr_clr:
  2416. /* No addresses available in this EEPROM. It's not necessarily an
  2417. * error though, so just wipe the local address and return.
  2418. */
  2419. for (i = 0; i < 6; i++)
  2420. san_mac_addr[i] = 0xFF;
  2421. return ret_val;
  2422. }
  2423. /**
  2424. * ixgbe_get_pcie_msix_count_generic - Gets MSI-X vector count
  2425. * @hw: pointer to hardware structure
  2426. *
  2427. * Read PCIe configuration space, and get the MSI-X vector count from
  2428. * the capabilities table.
  2429. **/
  2430. u16 ixgbe_get_pcie_msix_count_generic(struct ixgbe_hw *hw)
  2431. {
  2432. struct ixgbe_adapter *adapter = hw->back;
  2433. u16 msix_count = 1;
  2434. u16 max_msix_count;
  2435. u16 pcie_offset;
  2436. switch (hw->mac.type) {
  2437. case ixgbe_mac_82598EB:
  2438. pcie_offset = IXGBE_PCIE_MSIX_82598_CAPS;
  2439. max_msix_count = IXGBE_MAX_MSIX_VECTORS_82598;
  2440. break;
  2441. case ixgbe_mac_82599EB:
  2442. case ixgbe_mac_X540:
  2443. pcie_offset = IXGBE_PCIE_MSIX_82599_CAPS;
  2444. max_msix_count = IXGBE_MAX_MSIX_VECTORS_82599;
  2445. break;
  2446. default:
  2447. return msix_count;
  2448. }
  2449. pci_read_config_word(adapter->pdev, pcie_offset, &msix_count);
  2450. msix_count &= IXGBE_PCIE_MSIX_TBL_SZ_MASK;
  2451. /* MSI-X count is zero-based in HW */
  2452. msix_count++;
  2453. if (msix_count > max_msix_count)
  2454. msix_count = max_msix_count;
  2455. return msix_count;
  2456. }
  2457. /**
  2458. * ixgbe_clear_vmdq_generic - Disassociate a VMDq pool index from a rx address
  2459. * @hw: pointer to hardware struct
  2460. * @rar: receive address register index to disassociate
  2461. * @vmdq: VMDq pool index to remove from the rar
  2462. **/
  2463. s32 ixgbe_clear_vmdq_generic(struct ixgbe_hw *hw, u32 rar, u32 vmdq)
  2464. {
  2465. u32 mpsar_lo, mpsar_hi;
  2466. u32 rar_entries = hw->mac.num_rar_entries;
  2467. /* Make sure we are using a valid rar index range */
  2468. if (rar >= rar_entries) {
  2469. hw_dbg(hw, "RAR index %d is out of range.\n", rar);
  2470. return IXGBE_ERR_INVALID_ARGUMENT;
  2471. }
  2472. mpsar_lo = IXGBE_READ_REG(hw, IXGBE_MPSAR_LO(rar));
  2473. mpsar_hi = IXGBE_READ_REG(hw, IXGBE_MPSAR_HI(rar));
  2474. if (!mpsar_lo && !mpsar_hi)
  2475. goto done;
  2476. if (vmdq == IXGBE_CLEAR_VMDQ_ALL) {
  2477. if (mpsar_lo) {
  2478. IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), 0);
  2479. mpsar_lo = 0;
  2480. }
  2481. if (mpsar_hi) {
  2482. IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), 0);
  2483. mpsar_hi = 0;
  2484. }
  2485. } else if (vmdq < 32) {
  2486. mpsar_lo &= ~(1 << vmdq);
  2487. IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), mpsar_lo);
  2488. } else {
  2489. mpsar_hi &= ~(1 << (vmdq - 32));
  2490. IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), mpsar_hi);
  2491. }
  2492. /* was that the last pool using this rar? */
  2493. if (mpsar_lo == 0 && mpsar_hi == 0 && rar != 0)
  2494. hw->mac.ops.clear_rar(hw, rar);
  2495. done:
  2496. return 0;
  2497. }
  2498. /**
  2499. * ixgbe_set_vmdq_generic - Associate a VMDq pool index with a rx address
  2500. * @hw: pointer to hardware struct
  2501. * @rar: receive address register index to associate with a VMDq index
  2502. * @vmdq: VMDq pool index
  2503. **/
  2504. s32 ixgbe_set_vmdq_generic(struct ixgbe_hw *hw, u32 rar, u32 vmdq)
  2505. {
  2506. u32 mpsar;
  2507. u32 rar_entries = hw->mac.num_rar_entries;
  2508. /* Make sure we are using a valid rar index range */
  2509. if (rar >= rar_entries) {
  2510. hw_dbg(hw, "RAR index %d is out of range.\n", rar);
  2511. return IXGBE_ERR_INVALID_ARGUMENT;
  2512. }
  2513. if (vmdq < 32) {
  2514. mpsar = IXGBE_READ_REG(hw, IXGBE_MPSAR_LO(rar));
  2515. mpsar |= 1 << vmdq;
  2516. IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), mpsar);
  2517. } else {
  2518. mpsar = IXGBE_READ_REG(hw, IXGBE_MPSAR_HI(rar));
  2519. mpsar |= 1 << (vmdq - 32);
  2520. IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), mpsar);
  2521. }
  2522. return 0;
  2523. }
  2524. /**
  2525. * This function should only be involved in the IOV mode.
  2526. * In IOV mode, Default pool is next pool after the number of
  2527. * VFs advertized and not 0.
  2528. * MPSAR table needs to be updated for SAN_MAC RAR [hw->mac.san_mac_rar_index]
  2529. *
  2530. * ixgbe_set_vmdq_san_mac - Associate default VMDq pool index with a rx address
  2531. * @hw: pointer to hardware struct
  2532. * @vmdq: VMDq pool index
  2533. **/
  2534. s32 ixgbe_set_vmdq_san_mac_generic(struct ixgbe_hw *hw, u32 vmdq)
  2535. {
  2536. u32 rar = hw->mac.san_mac_rar_index;
  2537. if (vmdq < 32) {
  2538. IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), 1 << vmdq);
  2539. IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), 0);
  2540. } else {
  2541. IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), 0);
  2542. IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), 1 << (vmdq - 32));
  2543. }
  2544. return 0;
  2545. }
  2546. /**
  2547. * ixgbe_init_uta_tables_generic - Initialize the Unicast Table Array
  2548. * @hw: pointer to hardware structure
  2549. **/
  2550. s32 ixgbe_init_uta_tables_generic(struct ixgbe_hw *hw)
  2551. {
  2552. int i;
  2553. for (i = 0; i < 128; i++)
  2554. IXGBE_WRITE_REG(hw, IXGBE_UTA(i), 0);
  2555. return 0;
  2556. }
  2557. /**
  2558. * ixgbe_find_vlvf_slot - find the vlanid or the first empty slot
  2559. * @hw: pointer to hardware structure
  2560. * @vlan: VLAN id to write to VLAN filter
  2561. *
  2562. * return the VLVF index where this VLAN id should be placed
  2563. *
  2564. **/
  2565. static s32 ixgbe_find_vlvf_slot(struct ixgbe_hw *hw, u32 vlan)
  2566. {
  2567. u32 bits = 0;
  2568. u32 first_empty_slot = 0;
  2569. s32 regindex;
  2570. /* short cut the special case */
  2571. if (vlan == 0)
  2572. return 0;
  2573. /*
  2574. * Search for the vlan id in the VLVF entries. Save off the first empty
  2575. * slot found along the way
  2576. */
  2577. for (regindex = 1; regindex < IXGBE_VLVF_ENTRIES; regindex++) {
  2578. bits = IXGBE_READ_REG(hw, IXGBE_VLVF(regindex));
  2579. if (!bits && !(first_empty_slot))
  2580. first_empty_slot = regindex;
  2581. else if ((bits & 0x0FFF) == vlan)
  2582. break;
  2583. }
  2584. /*
  2585. * If regindex is less than IXGBE_VLVF_ENTRIES, then we found the vlan
  2586. * in the VLVF. Else use the first empty VLVF register for this
  2587. * vlan id.
  2588. */
  2589. if (regindex >= IXGBE_VLVF_ENTRIES) {
  2590. if (first_empty_slot)
  2591. regindex = first_empty_slot;
  2592. else {
  2593. hw_dbg(hw, "No space in VLVF.\n");
  2594. regindex = IXGBE_ERR_NO_SPACE;
  2595. }
  2596. }
  2597. return regindex;
  2598. }
  2599. /**
  2600. * ixgbe_set_vfta_generic - Set VLAN filter table
  2601. * @hw: pointer to hardware structure
  2602. * @vlan: VLAN id to write to VLAN filter
  2603. * @vind: VMDq output index that maps queue to VLAN id in VFVFB
  2604. * @vlan_on: boolean flag to turn on/off VLAN in VFVF
  2605. *
  2606. * Turn on/off specified VLAN in the VLAN filter table.
  2607. **/
  2608. s32 ixgbe_set_vfta_generic(struct ixgbe_hw *hw, u32 vlan, u32 vind,
  2609. bool vlan_on)
  2610. {
  2611. s32 regindex;
  2612. u32 bitindex;
  2613. u32 vfta;
  2614. u32 bits;
  2615. u32 vt;
  2616. u32 targetbit;
  2617. bool vfta_changed = false;
  2618. if (vlan > 4095)
  2619. return IXGBE_ERR_PARAM;
  2620. /*
  2621. * this is a 2 part operation - first the VFTA, then the
  2622. * VLVF and VLVFB if VT Mode is set
  2623. * We don't write the VFTA until we know the VLVF part succeeded.
  2624. */
  2625. /* Part 1
  2626. * The VFTA is a bitstring made up of 128 32-bit registers
  2627. * that enable the particular VLAN id, much like the MTA:
  2628. * bits[11-5]: which register
  2629. * bits[4-0]: which bit in the register
  2630. */
  2631. regindex = (vlan >> 5) & 0x7F;
  2632. bitindex = vlan & 0x1F;
  2633. targetbit = (1 << bitindex);
  2634. vfta = IXGBE_READ_REG(hw, IXGBE_VFTA(regindex));
  2635. if (vlan_on) {
  2636. if (!(vfta & targetbit)) {
  2637. vfta |= targetbit;
  2638. vfta_changed = true;
  2639. }
  2640. } else {
  2641. if ((vfta & targetbit)) {
  2642. vfta &= ~targetbit;
  2643. vfta_changed = true;
  2644. }
  2645. }
  2646. /* Part 2
  2647. * If VT Mode is set
  2648. * Either vlan_on
  2649. * make sure the vlan is in VLVF
  2650. * set the vind bit in the matching VLVFB
  2651. * Or !vlan_on
  2652. * clear the pool bit and possibly the vind
  2653. */
  2654. vt = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
  2655. if (vt & IXGBE_VT_CTL_VT_ENABLE) {
  2656. s32 vlvf_index;
  2657. vlvf_index = ixgbe_find_vlvf_slot(hw, vlan);
  2658. if (vlvf_index < 0)
  2659. return vlvf_index;
  2660. if (vlan_on) {
  2661. /* set the pool bit */
  2662. if (vind < 32) {
  2663. bits = IXGBE_READ_REG(hw,
  2664. IXGBE_VLVFB(vlvf_index*2));
  2665. bits |= (1 << vind);
  2666. IXGBE_WRITE_REG(hw,
  2667. IXGBE_VLVFB(vlvf_index*2),
  2668. bits);
  2669. } else {
  2670. bits = IXGBE_READ_REG(hw,
  2671. IXGBE_VLVFB((vlvf_index*2)+1));
  2672. bits |= (1 << (vind-32));
  2673. IXGBE_WRITE_REG(hw,
  2674. IXGBE_VLVFB((vlvf_index*2)+1),
  2675. bits);
  2676. }
  2677. } else {
  2678. /* clear the pool bit */
  2679. if (vind < 32) {
  2680. bits = IXGBE_READ_REG(hw,
  2681. IXGBE_VLVFB(vlvf_index*2));
  2682. bits &= ~(1 << vind);
  2683. IXGBE_WRITE_REG(hw,
  2684. IXGBE_VLVFB(vlvf_index*2),
  2685. bits);
  2686. bits |= IXGBE_READ_REG(hw,
  2687. IXGBE_VLVFB((vlvf_index*2)+1));
  2688. } else {
  2689. bits = IXGBE_READ_REG(hw,
  2690. IXGBE_VLVFB((vlvf_index*2)+1));
  2691. bits &= ~(1 << (vind-32));
  2692. IXGBE_WRITE_REG(hw,
  2693. IXGBE_VLVFB((vlvf_index*2)+1),
  2694. bits);
  2695. bits |= IXGBE_READ_REG(hw,
  2696. IXGBE_VLVFB(vlvf_index*2));
  2697. }
  2698. }
  2699. /*
  2700. * If there are still bits set in the VLVFB registers
  2701. * for the VLAN ID indicated we need to see if the
  2702. * caller is requesting that we clear the VFTA entry bit.
  2703. * If the caller has requested that we clear the VFTA
  2704. * entry bit but there are still pools/VFs using this VLAN
  2705. * ID entry then ignore the request. We're not worried
  2706. * about the case where we're turning the VFTA VLAN ID
  2707. * entry bit on, only when requested to turn it off as
  2708. * there may be multiple pools and/or VFs using the
  2709. * VLAN ID entry. In that case we cannot clear the
  2710. * VFTA bit until all pools/VFs using that VLAN ID have also
  2711. * been cleared. This will be indicated by "bits" being
  2712. * zero.
  2713. */
  2714. if (bits) {
  2715. IXGBE_WRITE_REG(hw, IXGBE_VLVF(vlvf_index),
  2716. (IXGBE_VLVF_VIEN | vlan));
  2717. if (!vlan_on) {
  2718. /* someone wants to clear the vfta entry
  2719. * but some pools/VFs are still using it.
  2720. * Ignore it. */
  2721. vfta_changed = false;
  2722. }
  2723. }
  2724. else
  2725. IXGBE_WRITE_REG(hw, IXGBE_VLVF(vlvf_index), 0);
  2726. }
  2727. if (vfta_changed)
  2728. IXGBE_WRITE_REG(hw, IXGBE_VFTA(regindex), vfta);
  2729. return 0;
  2730. }
  2731. /**
  2732. * ixgbe_clear_vfta_generic - Clear VLAN filter table
  2733. * @hw: pointer to hardware structure
  2734. *
  2735. * Clears the VLAN filer table, and the VMDq index associated with the filter
  2736. **/
  2737. s32 ixgbe_clear_vfta_generic(struct ixgbe_hw *hw)
  2738. {
  2739. u32 offset;
  2740. for (offset = 0; offset < hw->mac.vft_size; offset++)
  2741. IXGBE_WRITE_REG(hw, IXGBE_VFTA(offset), 0);
  2742. for (offset = 0; offset < IXGBE_VLVF_ENTRIES; offset++) {
  2743. IXGBE_WRITE_REG(hw, IXGBE_VLVF(offset), 0);
  2744. IXGBE_WRITE_REG(hw, IXGBE_VLVFB(offset*2), 0);
  2745. IXGBE_WRITE_REG(hw, IXGBE_VLVFB((offset*2)+1), 0);
  2746. }
  2747. return 0;
  2748. }
  2749. /**
  2750. * ixgbe_check_mac_link_generic - Determine link and speed status
  2751. * @hw: pointer to hardware structure
  2752. * @speed: pointer to link speed
  2753. * @link_up: true when link is up
  2754. * @link_up_wait_to_complete: bool used to wait for link up or not
  2755. *
  2756. * Reads the links register to determine if link is up and the current speed
  2757. **/
  2758. s32 ixgbe_check_mac_link_generic(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
  2759. bool *link_up, bool link_up_wait_to_complete)
  2760. {
  2761. u32 links_reg, links_orig;
  2762. u32 i;
  2763. /* clear the old state */
  2764. links_orig = IXGBE_READ_REG(hw, IXGBE_LINKS);
  2765. links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
  2766. if (links_orig != links_reg) {
  2767. hw_dbg(hw, "LINKS changed from %08X to %08X\n",
  2768. links_orig, links_reg);
  2769. }
  2770. if (link_up_wait_to_complete) {
  2771. for (i = 0; i < IXGBE_LINK_UP_TIME; i++) {
  2772. if (links_reg & IXGBE_LINKS_UP) {
  2773. *link_up = true;
  2774. break;
  2775. } else {
  2776. *link_up = false;
  2777. }
  2778. msleep(100);
  2779. links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
  2780. }
  2781. } else {
  2782. if (links_reg & IXGBE_LINKS_UP)
  2783. *link_up = true;
  2784. else
  2785. *link_up = false;
  2786. }
  2787. if ((links_reg & IXGBE_LINKS_SPEED_82599) ==
  2788. IXGBE_LINKS_SPEED_10G_82599)
  2789. *speed = IXGBE_LINK_SPEED_10GB_FULL;
  2790. else if ((links_reg & IXGBE_LINKS_SPEED_82599) ==
  2791. IXGBE_LINKS_SPEED_1G_82599)
  2792. *speed = IXGBE_LINK_SPEED_1GB_FULL;
  2793. else if ((links_reg & IXGBE_LINKS_SPEED_82599) ==
  2794. IXGBE_LINKS_SPEED_100_82599)
  2795. *speed = IXGBE_LINK_SPEED_100_FULL;
  2796. else
  2797. *speed = IXGBE_LINK_SPEED_UNKNOWN;
  2798. return 0;
  2799. }
  2800. /**
  2801. * ixgbe_get_wwn_prefix_generic - Get alternative WWNN/WWPN prefix from
  2802. * the EEPROM
  2803. * @hw: pointer to hardware structure
  2804. * @wwnn_prefix: the alternative WWNN prefix
  2805. * @wwpn_prefix: the alternative WWPN prefix
  2806. *
  2807. * This function will read the EEPROM from the alternative SAN MAC address
  2808. * block to check the support for the alternative WWNN/WWPN prefix support.
  2809. **/
  2810. s32 ixgbe_get_wwn_prefix_generic(struct ixgbe_hw *hw, u16 *wwnn_prefix,
  2811. u16 *wwpn_prefix)
  2812. {
  2813. u16 offset, caps;
  2814. u16 alt_san_mac_blk_offset;
  2815. /* clear output first */
  2816. *wwnn_prefix = 0xFFFF;
  2817. *wwpn_prefix = 0xFFFF;
  2818. /* check if alternative SAN MAC is supported */
  2819. offset = IXGBE_ALT_SAN_MAC_ADDR_BLK_PTR;
  2820. if (hw->eeprom.ops.read(hw, offset, &alt_san_mac_blk_offset))
  2821. goto wwn_prefix_err;
  2822. if ((alt_san_mac_blk_offset == 0) ||
  2823. (alt_san_mac_blk_offset == 0xFFFF))
  2824. goto wwn_prefix_out;
  2825. /* check capability in alternative san mac address block */
  2826. offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_CAPS_OFFSET;
  2827. if (hw->eeprom.ops.read(hw, offset, &caps))
  2828. goto wwn_prefix_err;
  2829. if (!(caps & IXGBE_ALT_SAN_MAC_ADDR_CAPS_ALTWWN))
  2830. goto wwn_prefix_out;
  2831. /* get the corresponding prefix for WWNN/WWPN */
  2832. offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_WWNN_OFFSET;
  2833. if (hw->eeprom.ops.read(hw, offset, wwnn_prefix))
  2834. hw_err(hw, "eeprom read at offset %d failed\n", offset);
  2835. offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_WWPN_OFFSET;
  2836. if (hw->eeprom.ops.read(hw, offset, wwpn_prefix))
  2837. goto wwn_prefix_err;
  2838. wwn_prefix_out:
  2839. return 0;
  2840. wwn_prefix_err:
  2841. hw_err(hw, "eeprom read at offset %d failed\n", offset);
  2842. return 0;
  2843. }
  2844. /**
  2845. * ixgbe_set_mac_anti_spoofing - Enable/Disable MAC anti-spoofing
  2846. * @hw: pointer to hardware structure
  2847. * @enable: enable or disable switch for anti-spoofing
  2848. * @pf: Physical Function pool - do not enable anti-spoofing for the PF
  2849. *
  2850. **/
  2851. void ixgbe_set_mac_anti_spoofing(struct ixgbe_hw *hw, bool enable, int pf)
  2852. {
  2853. int j;
  2854. int pf_target_reg = pf >> 3;
  2855. int pf_target_shift = pf % 8;
  2856. u32 pfvfspoof = 0;
  2857. if (hw->mac.type == ixgbe_mac_82598EB)
  2858. return;
  2859. if (enable)
  2860. pfvfspoof = IXGBE_SPOOF_MACAS_MASK;
  2861. /*
  2862. * PFVFSPOOF register array is size 8 with 8 bits assigned to
  2863. * MAC anti-spoof enables in each register array element.
  2864. */
  2865. for (j = 0; j < pf_target_reg; j++)
  2866. IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(j), pfvfspoof);
  2867. /*
  2868. * The PF should be allowed to spoof so that it can support
  2869. * emulation mode NICs. Do not set the bits assigned to the PF
  2870. */
  2871. pfvfspoof &= (1 << pf_target_shift) - 1;
  2872. IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(j), pfvfspoof);
  2873. /*
  2874. * Remaining pools belong to the PF so they do not need to have
  2875. * anti-spoofing enabled.
  2876. */
  2877. for (j++; j < IXGBE_PFVFSPOOF_REG_COUNT; j++)
  2878. IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(j), 0);
  2879. }
  2880. /**
  2881. * ixgbe_set_vlan_anti_spoofing - Enable/Disable VLAN anti-spoofing
  2882. * @hw: pointer to hardware structure
  2883. * @enable: enable or disable switch for VLAN anti-spoofing
  2884. * @pf: Virtual Function pool - VF Pool to set for VLAN anti-spoofing
  2885. *
  2886. **/
  2887. void ixgbe_set_vlan_anti_spoofing(struct ixgbe_hw *hw, bool enable, int vf)
  2888. {
  2889. int vf_target_reg = vf >> 3;
  2890. int vf_target_shift = vf % 8 + IXGBE_SPOOF_VLANAS_SHIFT;
  2891. u32 pfvfspoof;
  2892. if (hw->mac.type == ixgbe_mac_82598EB)
  2893. return;
  2894. pfvfspoof = IXGBE_READ_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg));
  2895. if (enable)
  2896. pfvfspoof |= (1 << vf_target_shift);
  2897. else
  2898. pfvfspoof &= ~(1 << vf_target_shift);
  2899. IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg), pfvfspoof);
  2900. }
  2901. /**
  2902. * ixgbe_get_device_caps_generic - Get additional device capabilities
  2903. * @hw: pointer to hardware structure
  2904. * @device_caps: the EEPROM word with the extra device capabilities
  2905. *
  2906. * This function will read the EEPROM location for the device capabilities,
  2907. * and return the word through device_caps.
  2908. **/
  2909. s32 ixgbe_get_device_caps_generic(struct ixgbe_hw *hw, u16 *device_caps)
  2910. {
  2911. hw->eeprom.ops.read(hw, IXGBE_DEVICE_CAPS, device_caps);
  2912. return 0;
  2913. }
  2914. /**
  2915. * ixgbe_set_rxpba_generic - Initialize RX packet buffer
  2916. * @hw: pointer to hardware structure
  2917. * @num_pb: number of packet buffers to allocate
  2918. * @headroom: reserve n KB of headroom
  2919. * @strategy: packet buffer allocation strategy
  2920. **/
  2921. void ixgbe_set_rxpba_generic(struct ixgbe_hw *hw,
  2922. int num_pb,
  2923. u32 headroom,
  2924. int strategy)
  2925. {
  2926. u32 pbsize = hw->mac.rx_pb_size;
  2927. int i = 0;
  2928. u32 rxpktsize, txpktsize, txpbthresh;
  2929. /* Reserve headroom */
  2930. pbsize -= headroom;
  2931. if (!num_pb)
  2932. num_pb = 1;
  2933. /* Divide remaining packet buffer space amongst the number
  2934. * of packet buffers requested using supplied strategy.
  2935. */
  2936. switch (strategy) {
  2937. case (PBA_STRATEGY_WEIGHTED):
  2938. /* pba_80_48 strategy weight first half of packet buffer with
  2939. * 5/8 of the packet buffer space.
  2940. */
  2941. rxpktsize = ((pbsize * 5 * 2) / (num_pb * 8));
  2942. pbsize -= rxpktsize * (num_pb / 2);
  2943. rxpktsize <<= IXGBE_RXPBSIZE_SHIFT;
  2944. for (; i < (num_pb / 2); i++)
  2945. IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), rxpktsize);
  2946. /* Fall through to configure remaining packet buffers */
  2947. case (PBA_STRATEGY_EQUAL):
  2948. /* Divide the remaining Rx packet buffer evenly among the TCs */
  2949. rxpktsize = (pbsize / (num_pb - i)) << IXGBE_RXPBSIZE_SHIFT;
  2950. for (; i < num_pb; i++)
  2951. IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), rxpktsize);
  2952. break;
  2953. default:
  2954. break;
  2955. }
  2956. /*
  2957. * Setup Tx packet buffer and threshold equally for all TCs
  2958. * TXPBTHRESH register is set in K so divide by 1024 and subtract
  2959. * 10 since the largest packet we support is just over 9K.
  2960. */
  2961. txpktsize = IXGBE_TXPBSIZE_MAX / num_pb;
  2962. txpbthresh = (txpktsize / 1024) - IXGBE_TXPKT_SIZE_MAX;
  2963. for (i = 0; i < num_pb; i++) {
  2964. IXGBE_WRITE_REG(hw, IXGBE_TXPBSIZE(i), txpktsize);
  2965. IXGBE_WRITE_REG(hw, IXGBE_TXPBTHRESH(i), txpbthresh);
  2966. }
  2967. /* Clear unused TCs, if any, to zero buffer size*/
  2968. for (; i < IXGBE_MAX_PB; i++) {
  2969. IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), 0);
  2970. IXGBE_WRITE_REG(hw, IXGBE_TXPBSIZE(i), 0);
  2971. IXGBE_WRITE_REG(hw, IXGBE_TXPBTHRESH(i), 0);
  2972. }
  2973. }
  2974. /**
  2975. * ixgbe_calculate_checksum - Calculate checksum for buffer
  2976. * @buffer: pointer to EEPROM
  2977. * @length: size of EEPROM to calculate a checksum for
  2978. *
  2979. * Calculates the checksum for some buffer on a specified length. The
  2980. * checksum calculated is returned.
  2981. **/
  2982. static u8 ixgbe_calculate_checksum(u8 *buffer, u32 length)
  2983. {
  2984. u32 i;
  2985. u8 sum = 0;
  2986. if (!buffer)
  2987. return 0;
  2988. for (i = 0; i < length; i++)
  2989. sum += buffer[i];
  2990. return (u8) (0 - sum);
  2991. }
  2992. /**
  2993. * ixgbe_host_interface_command - Issue command to manageability block
  2994. * @hw: pointer to the HW structure
  2995. * @buffer: contains the command to write and where the return status will
  2996. * be placed
  2997. * @length: length of buffer, must be multiple of 4 bytes
  2998. *
  2999. * Communicates with the manageability block. On success return 0
  3000. * else return IXGBE_ERR_HOST_INTERFACE_COMMAND.
  3001. **/
  3002. static s32 ixgbe_host_interface_command(struct ixgbe_hw *hw, u32 *buffer,
  3003. u32 length)
  3004. {
  3005. u32 hicr, i, bi;
  3006. u32 hdr_size = sizeof(struct ixgbe_hic_hdr);
  3007. u8 buf_len, dword_len;
  3008. s32 ret_val = 0;
  3009. if (length == 0 || length & 0x3 ||
  3010. length > IXGBE_HI_MAX_BLOCK_BYTE_LENGTH) {
  3011. hw_dbg(hw, "Buffer length failure.\n");
  3012. ret_val = IXGBE_ERR_HOST_INTERFACE_COMMAND;
  3013. goto out;
  3014. }
  3015. /* Check that the host interface is enabled. */
  3016. hicr = IXGBE_READ_REG(hw, IXGBE_HICR);
  3017. if ((hicr & IXGBE_HICR_EN) == 0) {
  3018. hw_dbg(hw, "IXGBE_HOST_EN bit disabled.\n");
  3019. ret_val = IXGBE_ERR_HOST_INTERFACE_COMMAND;
  3020. goto out;
  3021. }
  3022. /* Calculate length in DWORDs */
  3023. dword_len = length >> 2;
  3024. /*
  3025. * The device driver writes the relevant command block
  3026. * into the ram area.
  3027. */
  3028. for (i = 0; i < dword_len; i++)
  3029. IXGBE_WRITE_REG_ARRAY(hw, IXGBE_FLEX_MNG,
  3030. i, cpu_to_le32(buffer[i]));
  3031. /* Setting this bit tells the ARC that a new command is pending. */
  3032. IXGBE_WRITE_REG(hw, IXGBE_HICR, hicr | IXGBE_HICR_C);
  3033. for (i = 0; i < IXGBE_HI_COMMAND_TIMEOUT; i++) {
  3034. hicr = IXGBE_READ_REG(hw, IXGBE_HICR);
  3035. if (!(hicr & IXGBE_HICR_C))
  3036. break;
  3037. usleep_range(1000, 2000);
  3038. }
  3039. /* Check command successful completion. */
  3040. if (i == IXGBE_HI_COMMAND_TIMEOUT ||
  3041. (!(IXGBE_READ_REG(hw, IXGBE_HICR) & IXGBE_HICR_SV))) {
  3042. hw_dbg(hw, "Command has failed with no status valid.\n");
  3043. ret_val = IXGBE_ERR_HOST_INTERFACE_COMMAND;
  3044. goto out;
  3045. }
  3046. /* Calculate length in DWORDs */
  3047. dword_len = hdr_size >> 2;
  3048. /* first pull in the header so we know the buffer length */
  3049. for (bi = 0; bi < dword_len; bi++) {
  3050. buffer[bi] = IXGBE_READ_REG_ARRAY(hw, IXGBE_FLEX_MNG, bi);
  3051. le32_to_cpus(&buffer[bi]);
  3052. }
  3053. /* If there is any thing in data position pull it in */
  3054. buf_len = ((struct ixgbe_hic_hdr *)buffer)->buf_len;
  3055. if (buf_len == 0)
  3056. goto out;
  3057. if (length < (buf_len + hdr_size)) {
  3058. hw_dbg(hw, "Buffer not large enough for reply message.\n");
  3059. ret_val = IXGBE_ERR_HOST_INTERFACE_COMMAND;
  3060. goto out;
  3061. }
  3062. /* Calculate length in DWORDs, add 3 for odd lengths */
  3063. dword_len = (buf_len + 3) >> 2;
  3064. /* Pull in the rest of the buffer (bi is where we left off)*/
  3065. for (; bi <= dword_len; bi++) {
  3066. buffer[bi] = IXGBE_READ_REG_ARRAY(hw, IXGBE_FLEX_MNG, bi);
  3067. le32_to_cpus(&buffer[bi]);
  3068. }
  3069. out:
  3070. return ret_val;
  3071. }
  3072. /**
  3073. * ixgbe_set_fw_drv_ver_generic - Sends driver version to firmware
  3074. * @hw: pointer to the HW structure
  3075. * @maj: driver version major number
  3076. * @min: driver version minor number
  3077. * @build: driver version build number
  3078. * @sub: driver version sub build number
  3079. *
  3080. * Sends driver version number to firmware through the manageability
  3081. * block. On success return 0
  3082. * else returns IXGBE_ERR_SWFW_SYNC when encountering an error acquiring
  3083. * semaphore or IXGBE_ERR_HOST_INTERFACE_COMMAND when command fails.
  3084. **/
  3085. s32 ixgbe_set_fw_drv_ver_generic(struct ixgbe_hw *hw, u8 maj, u8 min,
  3086. u8 build, u8 sub)
  3087. {
  3088. struct ixgbe_hic_drv_info fw_cmd;
  3089. int i;
  3090. s32 ret_val = 0;
  3091. if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_SW_MNG_SM) != 0) {
  3092. ret_val = IXGBE_ERR_SWFW_SYNC;
  3093. goto out;
  3094. }
  3095. fw_cmd.hdr.cmd = FW_CEM_CMD_DRIVER_INFO;
  3096. fw_cmd.hdr.buf_len = FW_CEM_CMD_DRIVER_INFO_LEN;
  3097. fw_cmd.hdr.cmd_or_resp.cmd_resv = FW_CEM_CMD_RESERVED;
  3098. fw_cmd.port_num = (u8)hw->bus.func;
  3099. fw_cmd.ver_maj = maj;
  3100. fw_cmd.ver_min = min;
  3101. fw_cmd.ver_build = build;
  3102. fw_cmd.ver_sub = sub;
  3103. fw_cmd.hdr.checksum = 0;
  3104. fw_cmd.hdr.checksum = ixgbe_calculate_checksum((u8 *)&fw_cmd,
  3105. (FW_CEM_HDR_LEN + fw_cmd.hdr.buf_len));
  3106. fw_cmd.pad = 0;
  3107. fw_cmd.pad2 = 0;
  3108. for (i = 0; i <= FW_CEM_MAX_RETRIES; i++) {
  3109. ret_val = ixgbe_host_interface_command(hw, (u32 *)&fw_cmd,
  3110. sizeof(fw_cmd));
  3111. if (ret_val != 0)
  3112. continue;
  3113. if (fw_cmd.hdr.cmd_or_resp.ret_status ==
  3114. FW_CEM_RESP_STATUS_SUCCESS)
  3115. ret_val = 0;
  3116. else
  3117. ret_val = IXGBE_ERR_HOST_INTERFACE_COMMAND;
  3118. break;
  3119. }
  3120. hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_SW_MNG_SM);
  3121. out:
  3122. return ret_val;
  3123. }
  3124. /**
  3125. * ixgbe_clear_tx_pending - Clear pending TX work from the PCIe fifo
  3126. * @hw: pointer to the hardware structure
  3127. *
  3128. * The 82599 and x540 MACs can experience issues if TX work is still pending
  3129. * when a reset occurs. This function prevents this by flushing the PCIe
  3130. * buffers on the system.
  3131. **/
  3132. void ixgbe_clear_tx_pending(struct ixgbe_hw *hw)
  3133. {
  3134. u32 gcr_ext, hlreg0;
  3135. /*
  3136. * If double reset is not requested then all transactions should
  3137. * already be clear and as such there is no work to do
  3138. */
  3139. if (!(hw->mac.flags & IXGBE_FLAGS_DOUBLE_RESET_REQUIRED))
  3140. return;
  3141. /*
  3142. * Set loopback enable to prevent any transmits from being sent
  3143. * should the link come up. This assumes that the RXCTRL.RXEN bit
  3144. * has already been cleared.
  3145. */
  3146. hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
  3147. IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0 | IXGBE_HLREG0_LPBK);
  3148. /* initiate cleaning flow for buffers in the PCIe transaction layer */
  3149. gcr_ext = IXGBE_READ_REG(hw, IXGBE_GCR_EXT);
  3150. IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT,
  3151. gcr_ext | IXGBE_GCR_EXT_BUFFERS_CLEAR);
  3152. /* Flush all writes and allow 20usec for all transactions to clear */
  3153. IXGBE_WRITE_FLUSH(hw);
  3154. udelay(20);
  3155. /* restore previous register values */
  3156. IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
  3157. IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
  3158. }
  3159. static const u8 ixgbe_emc_temp_data[4] = {
  3160. IXGBE_EMC_INTERNAL_DATA,
  3161. IXGBE_EMC_DIODE1_DATA,
  3162. IXGBE_EMC_DIODE2_DATA,
  3163. IXGBE_EMC_DIODE3_DATA
  3164. };
  3165. static const u8 ixgbe_emc_therm_limit[4] = {
  3166. IXGBE_EMC_INTERNAL_THERM_LIMIT,
  3167. IXGBE_EMC_DIODE1_THERM_LIMIT,
  3168. IXGBE_EMC_DIODE2_THERM_LIMIT,
  3169. IXGBE_EMC_DIODE3_THERM_LIMIT
  3170. };
  3171. /**
  3172. * ixgbe_get_ets_data - Extracts the ETS bit data
  3173. * @hw: pointer to hardware structure
  3174. * @ets_cfg: extected ETS data
  3175. * @ets_offset: offset of ETS data
  3176. *
  3177. * Returns error code.
  3178. **/
  3179. static s32 ixgbe_get_ets_data(struct ixgbe_hw *hw, u16 *ets_cfg,
  3180. u16 *ets_offset)
  3181. {
  3182. s32 status = 0;
  3183. status = hw->eeprom.ops.read(hw, IXGBE_ETS_CFG, ets_offset);
  3184. if (status)
  3185. goto out;
  3186. if ((*ets_offset == 0x0000) || (*ets_offset == 0xFFFF)) {
  3187. status = IXGBE_NOT_IMPLEMENTED;
  3188. goto out;
  3189. }
  3190. status = hw->eeprom.ops.read(hw, *ets_offset, ets_cfg);
  3191. if (status)
  3192. goto out;
  3193. if ((*ets_cfg & IXGBE_ETS_TYPE_MASK) != IXGBE_ETS_TYPE_EMC_SHIFTED) {
  3194. status = IXGBE_NOT_IMPLEMENTED;
  3195. goto out;
  3196. }
  3197. out:
  3198. return status;
  3199. }
  3200. /**
  3201. * ixgbe_get_thermal_sensor_data - Gathers thermal sensor data
  3202. * @hw: pointer to hardware structure
  3203. *
  3204. * Returns the thermal sensor data structure
  3205. **/
  3206. s32 ixgbe_get_thermal_sensor_data_generic(struct ixgbe_hw *hw)
  3207. {
  3208. s32 status = 0;
  3209. u16 ets_offset;
  3210. u16 ets_cfg;
  3211. u16 ets_sensor;
  3212. u8 num_sensors;
  3213. u8 i;
  3214. struct ixgbe_thermal_sensor_data *data = &hw->mac.thermal_sensor_data;
  3215. /* Only support thermal sensors attached to physical port 0 */
  3216. if ((IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)) {
  3217. status = IXGBE_NOT_IMPLEMENTED;
  3218. goto out;
  3219. }
  3220. status = ixgbe_get_ets_data(hw, &ets_cfg, &ets_offset);
  3221. if (status)
  3222. goto out;
  3223. num_sensors = (ets_cfg & IXGBE_ETS_NUM_SENSORS_MASK);
  3224. if (num_sensors > IXGBE_MAX_SENSORS)
  3225. num_sensors = IXGBE_MAX_SENSORS;
  3226. for (i = 0; i < num_sensors; i++) {
  3227. u8 sensor_index;
  3228. u8 sensor_location;
  3229. status = hw->eeprom.ops.read(hw, (ets_offset + 1 + i),
  3230. &ets_sensor);
  3231. if (status)
  3232. goto out;
  3233. sensor_index = ((ets_sensor & IXGBE_ETS_DATA_INDEX_MASK) >>
  3234. IXGBE_ETS_DATA_INDEX_SHIFT);
  3235. sensor_location = ((ets_sensor & IXGBE_ETS_DATA_LOC_MASK) >>
  3236. IXGBE_ETS_DATA_LOC_SHIFT);
  3237. if (sensor_location != 0) {
  3238. status = hw->phy.ops.read_i2c_byte(hw,
  3239. ixgbe_emc_temp_data[sensor_index],
  3240. IXGBE_I2C_THERMAL_SENSOR_ADDR,
  3241. &data->sensor[i].temp);
  3242. if (status)
  3243. goto out;
  3244. }
  3245. }
  3246. out:
  3247. return status;
  3248. }
  3249. /**
  3250. * ixgbe_init_thermal_sensor_thresh_generic - Inits thermal sensor thresholds
  3251. * @hw: pointer to hardware structure
  3252. *
  3253. * Inits the thermal sensor thresholds according to the NVM map
  3254. * and save off the threshold and location values into mac.thermal_sensor_data
  3255. **/
  3256. s32 ixgbe_init_thermal_sensor_thresh_generic(struct ixgbe_hw *hw)
  3257. {
  3258. s32 status = 0;
  3259. u16 ets_offset;
  3260. u16 ets_cfg;
  3261. u16 ets_sensor;
  3262. u8 low_thresh_delta;
  3263. u8 num_sensors;
  3264. u8 therm_limit;
  3265. u8 i;
  3266. struct ixgbe_thermal_sensor_data *data = &hw->mac.thermal_sensor_data;
  3267. memset(data, 0, sizeof(struct ixgbe_thermal_sensor_data));
  3268. /* Only support thermal sensors attached to physical port 0 */
  3269. if ((IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)) {
  3270. status = IXGBE_NOT_IMPLEMENTED;
  3271. goto out;
  3272. }
  3273. status = ixgbe_get_ets_data(hw, &ets_cfg, &ets_offset);
  3274. if (status)
  3275. goto out;
  3276. low_thresh_delta = ((ets_cfg & IXGBE_ETS_LTHRES_DELTA_MASK) >>
  3277. IXGBE_ETS_LTHRES_DELTA_SHIFT);
  3278. num_sensors = (ets_cfg & IXGBE_ETS_NUM_SENSORS_MASK);
  3279. if (num_sensors > IXGBE_MAX_SENSORS)
  3280. num_sensors = IXGBE_MAX_SENSORS;
  3281. for (i = 0; i < num_sensors; i++) {
  3282. u8 sensor_index;
  3283. u8 sensor_location;
  3284. if (hw->eeprom.ops.read(hw, ets_offset + 1 + i, &ets_sensor)) {
  3285. hw_err(hw, "eeprom read at offset %d failed\n",
  3286. ets_offset + 1 + i);
  3287. continue;
  3288. }
  3289. sensor_index = ((ets_sensor & IXGBE_ETS_DATA_INDEX_MASK) >>
  3290. IXGBE_ETS_DATA_INDEX_SHIFT);
  3291. sensor_location = ((ets_sensor & IXGBE_ETS_DATA_LOC_MASK) >>
  3292. IXGBE_ETS_DATA_LOC_SHIFT);
  3293. therm_limit = ets_sensor & IXGBE_ETS_DATA_HTHRESH_MASK;
  3294. hw->phy.ops.write_i2c_byte(hw,
  3295. ixgbe_emc_therm_limit[sensor_index],
  3296. IXGBE_I2C_THERMAL_SENSOR_ADDR, therm_limit);
  3297. if (sensor_location == 0)
  3298. continue;
  3299. data->sensor[i].location = sensor_location;
  3300. data->sensor[i].caution_thresh = therm_limit;
  3301. data->sensor[i].max_op_thresh = therm_limit - low_thresh_delta;
  3302. }
  3303. out:
  3304. return status;
  3305. }