ixgbe_common.c 81 KB

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