ixgbe_common.c 113 KB

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