ixgbe_common.c 95 KB

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