ixgbe_common.c 115 KB

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