bnx2x_ethtool.c 99 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708
  1. /* bnx2x_ethtool.c: QLogic Everest network driver.
  2. *
  3. * Copyright (c) 2007-2013 Broadcom Corporation
  4. * Copyright (c) 2014 QLogic Corporation
  5. * All rights reserved
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation.
  10. *
  11. * Maintained by: Ariel Elior <ariel.elior@qlogic.com>
  12. * Written by: Eliezer Tamir
  13. * Based on code from Michael Chan's bnx2 driver
  14. * UDP CSUM errata workaround by Arik Gendelman
  15. * Slowpath and fastpath rework by Vladislav Zolotarov
  16. * Statistics and Link management by Yitchak Gertner
  17. *
  18. */
  19. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  20. #include <linux/ethtool.h>
  21. #include <linux/netdevice.h>
  22. #include <linux/types.h>
  23. #include <linux/sched.h>
  24. #include <linux/crc32.h>
  25. #include "bnx2x.h"
  26. #include "bnx2x_cmn.h"
  27. #include "bnx2x_dump.h"
  28. #include "bnx2x_init.h"
  29. /* Note: in the format strings below %s is replaced by the queue-name which is
  30. * either its index or 'fcoe' for the fcoe queue. Make sure the format string
  31. * length does not exceed ETH_GSTRING_LEN - MAX_QUEUE_NAME_LEN + 2
  32. */
  33. #define MAX_QUEUE_NAME_LEN 4
  34. static const struct {
  35. long offset;
  36. int size;
  37. char string[ETH_GSTRING_LEN];
  38. } bnx2x_q_stats_arr[] = {
  39. /* 1 */ { Q_STATS_OFFSET32(total_bytes_received_hi), 8, "[%s]: rx_bytes" },
  40. { Q_STATS_OFFSET32(total_unicast_packets_received_hi),
  41. 8, "[%s]: rx_ucast_packets" },
  42. { Q_STATS_OFFSET32(total_multicast_packets_received_hi),
  43. 8, "[%s]: rx_mcast_packets" },
  44. { Q_STATS_OFFSET32(total_broadcast_packets_received_hi),
  45. 8, "[%s]: rx_bcast_packets" },
  46. { Q_STATS_OFFSET32(no_buff_discard_hi), 8, "[%s]: rx_discards" },
  47. { Q_STATS_OFFSET32(rx_err_discard_pkt),
  48. 4, "[%s]: rx_phy_ip_err_discards"},
  49. { Q_STATS_OFFSET32(rx_skb_alloc_failed),
  50. 4, "[%s]: rx_skb_alloc_discard" },
  51. { Q_STATS_OFFSET32(hw_csum_err), 4, "[%s]: rx_csum_offload_errors" },
  52. { Q_STATS_OFFSET32(driver_xoff), 4, "[%s]: tx_exhaustion_events" },
  53. { Q_STATS_OFFSET32(total_bytes_transmitted_hi), 8, "[%s]: tx_bytes" },
  54. /* 10 */{ Q_STATS_OFFSET32(total_unicast_packets_transmitted_hi),
  55. 8, "[%s]: tx_ucast_packets" },
  56. { Q_STATS_OFFSET32(total_multicast_packets_transmitted_hi),
  57. 8, "[%s]: tx_mcast_packets" },
  58. { Q_STATS_OFFSET32(total_broadcast_packets_transmitted_hi),
  59. 8, "[%s]: tx_bcast_packets" },
  60. { Q_STATS_OFFSET32(total_tpa_aggregations_hi),
  61. 8, "[%s]: tpa_aggregations" },
  62. { Q_STATS_OFFSET32(total_tpa_aggregated_frames_hi),
  63. 8, "[%s]: tpa_aggregated_frames"},
  64. { Q_STATS_OFFSET32(total_tpa_bytes_hi), 8, "[%s]: tpa_bytes"},
  65. { Q_STATS_OFFSET32(driver_filtered_tx_pkt),
  66. 4, "[%s]: driver_filtered_tx_pkt" }
  67. };
  68. #define BNX2X_NUM_Q_STATS ARRAY_SIZE(bnx2x_q_stats_arr)
  69. static const struct {
  70. long offset;
  71. int size;
  72. bool is_port_stat;
  73. char string[ETH_GSTRING_LEN];
  74. } bnx2x_stats_arr[] = {
  75. /* 1 */ { STATS_OFFSET32(total_bytes_received_hi),
  76. 8, false, "rx_bytes" },
  77. { STATS_OFFSET32(error_bytes_received_hi),
  78. 8, false, "rx_error_bytes" },
  79. { STATS_OFFSET32(total_unicast_packets_received_hi),
  80. 8, false, "rx_ucast_packets" },
  81. { STATS_OFFSET32(total_multicast_packets_received_hi),
  82. 8, false, "rx_mcast_packets" },
  83. { STATS_OFFSET32(total_broadcast_packets_received_hi),
  84. 8, false, "rx_bcast_packets" },
  85. { STATS_OFFSET32(rx_stat_dot3statsfcserrors_hi),
  86. 8, true, "rx_crc_errors" },
  87. { STATS_OFFSET32(rx_stat_dot3statsalignmenterrors_hi),
  88. 8, true, "rx_align_errors" },
  89. { STATS_OFFSET32(rx_stat_etherstatsundersizepkts_hi),
  90. 8, true, "rx_undersize_packets" },
  91. { STATS_OFFSET32(etherstatsoverrsizepkts_hi),
  92. 8, true, "rx_oversize_packets" },
  93. /* 10 */{ STATS_OFFSET32(rx_stat_etherstatsfragments_hi),
  94. 8, true, "rx_fragments" },
  95. { STATS_OFFSET32(rx_stat_etherstatsjabbers_hi),
  96. 8, true, "rx_jabbers" },
  97. { STATS_OFFSET32(no_buff_discard_hi),
  98. 8, false, "rx_discards" },
  99. { STATS_OFFSET32(mac_filter_discard),
  100. 4, true, "rx_filtered_packets" },
  101. { STATS_OFFSET32(mf_tag_discard),
  102. 4, true, "rx_mf_tag_discard" },
  103. { STATS_OFFSET32(pfc_frames_received_hi),
  104. 8, true, "pfc_frames_received" },
  105. { STATS_OFFSET32(pfc_frames_sent_hi),
  106. 8, true, "pfc_frames_sent" },
  107. { STATS_OFFSET32(brb_drop_hi),
  108. 8, true, "rx_brb_discard" },
  109. { STATS_OFFSET32(brb_truncate_hi),
  110. 8, true, "rx_brb_truncate" },
  111. { STATS_OFFSET32(pause_frames_received_hi),
  112. 8, true, "rx_pause_frames" },
  113. { STATS_OFFSET32(rx_stat_maccontrolframesreceived_hi),
  114. 8, true, "rx_mac_ctrl_frames" },
  115. { STATS_OFFSET32(nig_timer_max),
  116. 4, true, "rx_constant_pause_events" },
  117. /* 20 */{ STATS_OFFSET32(rx_err_discard_pkt),
  118. 4, false, "rx_phy_ip_err_discards"},
  119. { STATS_OFFSET32(rx_skb_alloc_failed),
  120. 4, false, "rx_skb_alloc_discard" },
  121. { STATS_OFFSET32(hw_csum_err),
  122. 4, false, "rx_csum_offload_errors" },
  123. { STATS_OFFSET32(driver_xoff),
  124. 4, false, "tx_exhaustion_events" },
  125. { STATS_OFFSET32(total_bytes_transmitted_hi),
  126. 8, false, "tx_bytes" },
  127. { STATS_OFFSET32(tx_stat_ifhcoutbadoctets_hi),
  128. 8, true, "tx_error_bytes" },
  129. { STATS_OFFSET32(total_unicast_packets_transmitted_hi),
  130. 8, false, "tx_ucast_packets" },
  131. { STATS_OFFSET32(total_multicast_packets_transmitted_hi),
  132. 8, false, "tx_mcast_packets" },
  133. { STATS_OFFSET32(total_broadcast_packets_transmitted_hi),
  134. 8, false, "tx_bcast_packets" },
  135. { STATS_OFFSET32(tx_stat_dot3statsinternalmactransmiterrors_hi),
  136. 8, true, "tx_mac_errors" },
  137. { STATS_OFFSET32(rx_stat_dot3statscarriersenseerrors_hi),
  138. 8, true, "tx_carrier_errors" },
  139. /* 30 */{ STATS_OFFSET32(tx_stat_dot3statssinglecollisionframes_hi),
  140. 8, true, "tx_single_collisions" },
  141. { STATS_OFFSET32(tx_stat_dot3statsmultiplecollisionframes_hi),
  142. 8, true, "tx_multi_collisions" },
  143. { STATS_OFFSET32(tx_stat_dot3statsdeferredtransmissions_hi),
  144. 8, true, "tx_deferred" },
  145. { STATS_OFFSET32(tx_stat_dot3statsexcessivecollisions_hi),
  146. 8, true, "tx_excess_collisions" },
  147. { STATS_OFFSET32(tx_stat_dot3statslatecollisions_hi),
  148. 8, true, "tx_late_collisions" },
  149. { STATS_OFFSET32(tx_stat_etherstatscollisions_hi),
  150. 8, true, "tx_total_collisions" },
  151. { STATS_OFFSET32(tx_stat_etherstatspkts64octets_hi),
  152. 8, true, "tx_64_byte_packets" },
  153. { STATS_OFFSET32(tx_stat_etherstatspkts65octetsto127octets_hi),
  154. 8, true, "tx_65_to_127_byte_packets" },
  155. { STATS_OFFSET32(tx_stat_etherstatspkts128octetsto255octets_hi),
  156. 8, true, "tx_128_to_255_byte_packets" },
  157. { STATS_OFFSET32(tx_stat_etherstatspkts256octetsto511octets_hi),
  158. 8, true, "tx_256_to_511_byte_packets" },
  159. /* 40 */{ STATS_OFFSET32(tx_stat_etherstatspkts512octetsto1023octets_hi),
  160. 8, true, "tx_512_to_1023_byte_packets" },
  161. { STATS_OFFSET32(etherstatspkts1024octetsto1522octets_hi),
  162. 8, true, "tx_1024_to_1522_byte_packets" },
  163. { STATS_OFFSET32(etherstatspktsover1522octets_hi),
  164. 8, true, "tx_1523_to_9022_byte_packets" },
  165. { STATS_OFFSET32(pause_frames_sent_hi),
  166. 8, true, "tx_pause_frames" },
  167. { STATS_OFFSET32(total_tpa_aggregations_hi),
  168. 8, false, "tpa_aggregations" },
  169. { STATS_OFFSET32(total_tpa_aggregated_frames_hi),
  170. 8, false, "tpa_aggregated_frames"},
  171. { STATS_OFFSET32(total_tpa_bytes_hi),
  172. 8, false, "tpa_bytes"},
  173. { STATS_OFFSET32(recoverable_error),
  174. 4, false, "recoverable_errors" },
  175. { STATS_OFFSET32(unrecoverable_error),
  176. 4, false, "unrecoverable_errors" },
  177. { STATS_OFFSET32(driver_filtered_tx_pkt),
  178. 4, false, "driver_filtered_tx_pkt" },
  179. { STATS_OFFSET32(eee_tx_lpi),
  180. 4, true, "Tx LPI entry count"},
  181. { STATS_OFFSET32(ptp_skip_tx_ts),
  182. 4, false, "ptp_skipped_tx_tstamp" },
  183. };
  184. #define BNX2X_NUM_STATS ARRAY_SIZE(bnx2x_stats_arr)
  185. static int bnx2x_get_port_type(struct bnx2x *bp)
  186. {
  187. int port_type;
  188. u32 phy_idx = bnx2x_get_cur_phy_idx(bp);
  189. switch (bp->link_params.phy[phy_idx].media_type) {
  190. case ETH_PHY_SFPP_10G_FIBER:
  191. case ETH_PHY_SFP_1G_FIBER:
  192. case ETH_PHY_XFP_FIBER:
  193. case ETH_PHY_KR:
  194. case ETH_PHY_CX4:
  195. port_type = PORT_FIBRE;
  196. break;
  197. case ETH_PHY_DA_TWINAX:
  198. port_type = PORT_DA;
  199. break;
  200. case ETH_PHY_BASE_T:
  201. port_type = PORT_TP;
  202. break;
  203. case ETH_PHY_NOT_PRESENT:
  204. port_type = PORT_NONE;
  205. break;
  206. case ETH_PHY_UNSPECIFIED:
  207. default:
  208. port_type = PORT_OTHER;
  209. break;
  210. }
  211. return port_type;
  212. }
  213. static int bnx2x_get_vf_link_ksettings(struct net_device *dev,
  214. struct ethtool_link_ksettings *cmd)
  215. {
  216. struct bnx2x *bp = netdev_priv(dev);
  217. u32 supported, advertising;
  218. ethtool_convert_link_mode_to_legacy_u32(&supported,
  219. cmd->link_modes.supported);
  220. ethtool_convert_link_mode_to_legacy_u32(&advertising,
  221. cmd->link_modes.advertising);
  222. if (bp->state == BNX2X_STATE_OPEN) {
  223. if (test_bit(BNX2X_LINK_REPORT_FD,
  224. &bp->vf_link_vars.link_report_flags))
  225. cmd->base.duplex = DUPLEX_FULL;
  226. else
  227. cmd->base.duplex = DUPLEX_HALF;
  228. cmd->base.speed = bp->vf_link_vars.line_speed;
  229. } else {
  230. cmd->base.duplex = DUPLEX_UNKNOWN;
  231. cmd->base.speed = SPEED_UNKNOWN;
  232. }
  233. cmd->base.port = PORT_OTHER;
  234. cmd->base.phy_address = 0;
  235. cmd->base.autoneg = AUTONEG_DISABLE;
  236. DP(BNX2X_MSG_ETHTOOL, "ethtool_cmd: cmd %d\n"
  237. " supported 0x%x advertising 0x%x speed %u\n"
  238. " duplex %d port %d phy_address %d\n"
  239. " autoneg %d\n",
  240. cmd->base.cmd, supported, advertising,
  241. cmd->base.speed,
  242. cmd->base.duplex, cmd->base.port, cmd->base.phy_address,
  243. cmd->base.autoneg);
  244. return 0;
  245. }
  246. static int bnx2x_get_link_ksettings(struct net_device *dev,
  247. struct ethtool_link_ksettings *cmd)
  248. {
  249. struct bnx2x *bp = netdev_priv(dev);
  250. int cfg_idx = bnx2x_get_link_cfg_idx(bp);
  251. u32 media_type;
  252. u32 supported, advertising, lp_advertising;
  253. ethtool_convert_link_mode_to_legacy_u32(&lp_advertising,
  254. cmd->link_modes.lp_advertising);
  255. /* Dual Media boards present all available port types */
  256. supported = bp->port.supported[cfg_idx] |
  257. (bp->port.supported[cfg_idx ^ 1] &
  258. (SUPPORTED_TP | SUPPORTED_FIBRE));
  259. advertising = bp->port.advertising[cfg_idx];
  260. media_type = bp->link_params.phy[bnx2x_get_cur_phy_idx(bp)].media_type;
  261. if (media_type == ETH_PHY_SFP_1G_FIBER) {
  262. supported &= ~(SUPPORTED_10000baseT_Full);
  263. advertising &= ~(ADVERTISED_10000baseT_Full);
  264. }
  265. if ((bp->state == BNX2X_STATE_OPEN) && bp->link_vars.link_up &&
  266. !(bp->flags & MF_FUNC_DIS)) {
  267. cmd->base.duplex = bp->link_vars.duplex;
  268. if (IS_MF(bp) && !BP_NOMCP(bp))
  269. cmd->base.speed = bnx2x_get_mf_speed(bp);
  270. else
  271. cmd->base.speed = bp->link_vars.line_speed;
  272. } else {
  273. cmd->base.duplex = DUPLEX_UNKNOWN;
  274. cmd->base.speed = SPEED_UNKNOWN;
  275. }
  276. cmd->base.port = bnx2x_get_port_type(bp);
  277. cmd->base.phy_address = bp->mdio.prtad;
  278. if (bp->link_params.req_line_speed[cfg_idx] == SPEED_AUTO_NEG)
  279. cmd->base.autoneg = AUTONEG_ENABLE;
  280. else
  281. cmd->base.autoneg = AUTONEG_DISABLE;
  282. /* Publish LP advertised speeds and FC */
  283. if (bp->link_vars.link_status & LINK_STATUS_AUTO_NEGOTIATE_COMPLETE) {
  284. u32 status = bp->link_vars.link_status;
  285. lp_advertising |= ADVERTISED_Autoneg;
  286. if (status & LINK_STATUS_LINK_PARTNER_SYMMETRIC_PAUSE)
  287. lp_advertising |= ADVERTISED_Pause;
  288. if (status & LINK_STATUS_LINK_PARTNER_ASYMMETRIC_PAUSE)
  289. lp_advertising |= ADVERTISED_Asym_Pause;
  290. if (status & LINK_STATUS_LINK_PARTNER_10THD_CAPABLE)
  291. lp_advertising |= ADVERTISED_10baseT_Half;
  292. if (status & LINK_STATUS_LINK_PARTNER_10TFD_CAPABLE)
  293. lp_advertising |= ADVERTISED_10baseT_Full;
  294. if (status & LINK_STATUS_LINK_PARTNER_100TXHD_CAPABLE)
  295. lp_advertising |= ADVERTISED_100baseT_Half;
  296. if (status & LINK_STATUS_LINK_PARTNER_100TXFD_CAPABLE)
  297. lp_advertising |= ADVERTISED_100baseT_Full;
  298. if (status & LINK_STATUS_LINK_PARTNER_1000THD_CAPABLE)
  299. lp_advertising |= ADVERTISED_1000baseT_Half;
  300. if (status & LINK_STATUS_LINK_PARTNER_1000TFD_CAPABLE) {
  301. if (media_type == ETH_PHY_KR) {
  302. lp_advertising |=
  303. ADVERTISED_1000baseKX_Full;
  304. } else {
  305. lp_advertising |=
  306. ADVERTISED_1000baseT_Full;
  307. }
  308. }
  309. if (status & LINK_STATUS_LINK_PARTNER_2500XFD_CAPABLE)
  310. lp_advertising |= ADVERTISED_2500baseX_Full;
  311. if (status & LINK_STATUS_LINK_PARTNER_10GXFD_CAPABLE) {
  312. if (media_type == ETH_PHY_KR) {
  313. lp_advertising |=
  314. ADVERTISED_10000baseKR_Full;
  315. } else {
  316. lp_advertising |=
  317. ADVERTISED_10000baseT_Full;
  318. }
  319. }
  320. if (status & LINK_STATUS_LINK_PARTNER_20GXFD_CAPABLE)
  321. lp_advertising |= ADVERTISED_20000baseKR2_Full;
  322. }
  323. ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported,
  324. supported);
  325. ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.advertising,
  326. advertising);
  327. ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.lp_advertising,
  328. lp_advertising);
  329. DP(BNX2X_MSG_ETHTOOL, "ethtool_cmd: cmd %d\n"
  330. " supported 0x%x advertising 0x%x speed %u\n"
  331. " duplex %d port %d phy_address %d\n"
  332. " autoneg %d\n",
  333. cmd->base.cmd, supported, advertising,
  334. cmd->base.speed,
  335. cmd->base.duplex, cmd->base.port, cmd->base.phy_address,
  336. cmd->base.autoneg);
  337. return 0;
  338. }
  339. static int bnx2x_set_link_ksettings(struct net_device *dev,
  340. const struct ethtool_link_ksettings *cmd)
  341. {
  342. struct bnx2x *bp = netdev_priv(dev);
  343. u32 advertising, cfg_idx, old_multi_phy_config, new_multi_phy_config;
  344. u32 speed, phy_idx;
  345. u32 supported;
  346. u8 duplex = cmd->base.duplex;
  347. ethtool_convert_link_mode_to_legacy_u32(&supported,
  348. cmd->link_modes.supported);
  349. ethtool_convert_link_mode_to_legacy_u32(&advertising,
  350. cmd->link_modes.advertising);
  351. if (IS_MF_SD(bp))
  352. return 0;
  353. DP(BNX2X_MSG_ETHTOOL, "ethtool_cmd: cmd %d\n"
  354. " supported 0x%x advertising 0x%x speed %u\n"
  355. " duplex %d port %d phy_address %d\n"
  356. " autoneg %d\n",
  357. cmd->base.cmd, supported, advertising,
  358. cmd->base.speed,
  359. cmd->base.duplex, cmd->base.port, cmd->base.phy_address,
  360. cmd->base.autoneg);
  361. speed = cmd->base.speed;
  362. /* If received a request for an unknown duplex, assume full*/
  363. if (duplex == DUPLEX_UNKNOWN)
  364. duplex = DUPLEX_FULL;
  365. if (IS_MF_SI(bp)) {
  366. u32 part;
  367. u32 line_speed = bp->link_vars.line_speed;
  368. /* use 10G if no link detected */
  369. if (!line_speed)
  370. line_speed = 10000;
  371. if (bp->common.bc_ver < REQ_BC_VER_4_SET_MF_BW) {
  372. DP(BNX2X_MSG_ETHTOOL,
  373. "To set speed BC %X or higher is required, please upgrade BC\n",
  374. REQ_BC_VER_4_SET_MF_BW);
  375. return -EINVAL;
  376. }
  377. part = (speed * 100) / line_speed;
  378. if (line_speed < speed || !part) {
  379. DP(BNX2X_MSG_ETHTOOL,
  380. "Speed setting should be in a range from 1%% to 100%% of actual line speed\n");
  381. return -EINVAL;
  382. }
  383. if (bp->state != BNX2X_STATE_OPEN)
  384. /* store value for following "load" */
  385. bp->pending_max = part;
  386. else
  387. bnx2x_update_max_mf_config(bp, part);
  388. return 0;
  389. }
  390. cfg_idx = bnx2x_get_link_cfg_idx(bp);
  391. old_multi_phy_config = bp->link_params.multi_phy_config;
  392. if (cmd->base.port != bnx2x_get_port_type(bp)) {
  393. switch (cmd->base.port) {
  394. case PORT_TP:
  395. if (!(bp->port.supported[0] & SUPPORTED_TP ||
  396. bp->port.supported[1] & SUPPORTED_TP)) {
  397. DP(BNX2X_MSG_ETHTOOL,
  398. "Unsupported port type\n");
  399. return -EINVAL;
  400. }
  401. bp->link_params.multi_phy_config &=
  402. ~PORT_HW_CFG_PHY_SELECTION_MASK;
  403. if (bp->link_params.multi_phy_config &
  404. PORT_HW_CFG_PHY_SWAPPED_ENABLED)
  405. bp->link_params.multi_phy_config |=
  406. PORT_HW_CFG_PHY_SELECTION_SECOND_PHY;
  407. else
  408. bp->link_params.multi_phy_config |=
  409. PORT_HW_CFG_PHY_SELECTION_FIRST_PHY;
  410. break;
  411. case PORT_FIBRE:
  412. case PORT_DA:
  413. case PORT_NONE:
  414. if (!(bp->port.supported[0] & SUPPORTED_FIBRE ||
  415. bp->port.supported[1] & SUPPORTED_FIBRE)) {
  416. DP(BNX2X_MSG_ETHTOOL,
  417. "Unsupported port type\n");
  418. return -EINVAL;
  419. }
  420. bp->link_params.multi_phy_config &=
  421. ~PORT_HW_CFG_PHY_SELECTION_MASK;
  422. if (bp->link_params.multi_phy_config &
  423. PORT_HW_CFG_PHY_SWAPPED_ENABLED)
  424. bp->link_params.multi_phy_config |=
  425. PORT_HW_CFG_PHY_SELECTION_FIRST_PHY;
  426. else
  427. bp->link_params.multi_phy_config |=
  428. PORT_HW_CFG_PHY_SELECTION_SECOND_PHY;
  429. break;
  430. default:
  431. DP(BNX2X_MSG_ETHTOOL, "Unsupported port type\n");
  432. return -EINVAL;
  433. }
  434. }
  435. /* Save new config in case command complete successfully */
  436. new_multi_phy_config = bp->link_params.multi_phy_config;
  437. /* Get the new cfg_idx */
  438. cfg_idx = bnx2x_get_link_cfg_idx(bp);
  439. /* Restore old config in case command failed */
  440. bp->link_params.multi_phy_config = old_multi_phy_config;
  441. DP(BNX2X_MSG_ETHTOOL, "cfg_idx = %x\n", cfg_idx);
  442. if (cmd->base.autoneg == AUTONEG_ENABLE) {
  443. u32 an_supported_speed = bp->port.supported[cfg_idx];
  444. if (bp->link_params.phy[EXT_PHY1].type ==
  445. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
  446. an_supported_speed |= (SUPPORTED_100baseT_Half |
  447. SUPPORTED_100baseT_Full);
  448. if (!(bp->port.supported[cfg_idx] & SUPPORTED_Autoneg)) {
  449. DP(BNX2X_MSG_ETHTOOL, "Autoneg not supported\n");
  450. return -EINVAL;
  451. }
  452. /* advertise the requested speed and duplex if supported */
  453. if (advertising & ~an_supported_speed) {
  454. DP(BNX2X_MSG_ETHTOOL,
  455. "Advertisement parameters are not supported\n");
  456. return -EINVAL;
  457. }
  458. bp->link_params.req_line_speed[cfg_idx] = SPEED_AUTO_NEG;
  459. bp->link_params.req_duplex[cfg_idx] = duplex;
  460. bp->port.advertising[cfg_idx] = (ADVERTISED_Autoneg |
  461. advertising);
  462. if (advertising) {
  463. bp->link_params.speed_cap_mask[cfg_idx] = 0;
  464. if (advertising & ADVERTISED_10baseT_Half) {
  465. bp->link_params.speed_cap_mask[cfg_idx] |=
  466. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF;
  467. }
  468. if (advertising & ADVERTISED_10baseT_Full)
  469. bp->link_params.speed_cap_mask[cfg_idx] |=
  470. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL;
  471. if (advertising & ADVERTISED_100baseT_Full)
  472. bp->link_params.speed_cap_mask[cfg_idx] |=
  473. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL;
  474. if (advertising & ADVERTISED_100baseT_Half) {
  475. bp->link_params.speed_cap_mask[cfg_idx] |=
  476. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF;
  477. }
  478. if (advertising & ADVERTISED_1000baseT_Half) {
  479. bp->link_params.speed_cap_mask[cfg_idx] |=
  480. PORT_HW_CFG_SPEED_CAPABILITY_D0_1G;
  481. }
  482. if (advertising & (ADVERTISED_1000baseT_Full |
  483. ADVERTISED_1000baseKX_Full))
  484. bp->link_params.speed_cap_mask[cfg_idx] |=
  485. PORT_HW_CFG_SPEED_CAPABILITY_D0_1G;
  486. if (advertising & (ADVERTISED_10000baseT_Full |
  487. ADVERTISED_10000baseKX4_Full |
  488. ADVERTISED_10000baseKR_Full))
  489. bp->link_params.speed_cap_mask[cfg_idx] |=
  490. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G;
  491. if (advertising & ADVERTISED_20000baseKR2_Full)
  492. bp->link_params.speed_cap_mask[cfg_idx] |=
  493. PORT_HW_CFG_SPEED_CAPABILITY_D0_20G;
  494. }
  495. } else { /* forced speed */
  496. /* advertise the requested speed and duplex if supported */
  497. switch (speed) {
  498. case SPEED_10:
  499. if (duplex == DUPLEX_FULL) {
  500. if (!(bp->port.supported[cfg_idx] &
  501. SUPPORTED_10baseT_Full)) {
  502. DP(BNX2X_MSG_ETHTOOL,
  503. "10M full not supported\n");
  504. return -EINVAL;
  505. }
  506. advertising = (ADVERTISED_10baseT_Full |
  507. ADVERTISED_TP);
  508. } else {
  509. if (!(bp->port.supported[cfg_idx] &
  510. SUPPORTED_10baseT_Half)) {
  511. DP(BNX2X_MSG_ETHTOOL,
  512. "10M half not supported\n");
  513. return -EINVAL;
  514. }
  515. advertising = (ADVERTISED_10baseT_Half |
  516. ADVERTISED_TP);
  517. }
  518. break;
  519. case SPEED_100:
  520. if (duplex == DUPLEX_FULL) {
  521. if (!(bp->port.supported[cfg_idx] &
  522. SUPPORTED_100baseT_Full)) {
  523. DP(BNX2X_MSG_ETHTOOL,
  524. "100M full not supported\n");
  525. return -EINVAL;
  526. }
  527. advertising = (ADVERTISED_100baseT_Full |
  528. ADVERTISED_TP);
  529. } else {
  530. if (!(bp->port.supported[cfg_idx] &
  531. SUPPORTED_100baseT_Half)) {
  532. DP(BNX2X_MSG_ETHTOOL,
  533. "100M half not supported\n");
  534. return -EINVAL;
  535. }
  536. advertising = (ADVERTISED_100baseT_Half |
  537. ADVERTISED_TP);
  538. }
  539. break;
  540. case SPEED_1000:
  541. if (duplex != DUPLEX_FULL) {
  542. DP(BNX2X_MSG_ETHTOOL,
  543. "1G half not supported\n");
  544. return -EINVAL;
  545. }
  546. if (bp->port.supported[cfg_idx] &
  547. SUPPORTED_1000baseT_Full) {
  548. advertising = (ADVERTISED_1000baseT_Full |
  549. ADVERTISED_TP);
  550. } else if (bp->port.supported[cfg_idx] &
  551. SUPPORTED_1000baseKX_Full) {
  552. advertising = ADVERTISED_1000baseKX_Full;
  553. } else {
  554. DP(BNX2X_MSG_ETHTOOL,
  555. "1G full not supported\n");
  556. return -EINVAL;
  557. }
  558. break;
  559. case SPEED_2500:
  560. if (duplex != DUPLEX_FULL) {
  561. DP(BNX2X_MSG_ETHTOOL,
  562. "2.5G half not supported\n");
  563. return -EINVAL;
  564. }
  565. if (!(bp->port.supported[cfg_idx]
  566. & SUPPORTED_2500baseX_Full)) {
  567. DP(BNX2X_MSG_ETHTOOL,
  568. "2.5G full not supported\n");
  569. return -EINVAL;
  570. }
  571. advertising = (ADVERTISED_2500baseX_Full |
  572. ADVERTISED_TP);
  573. break;
  574. case SPEED_10000:
  575. if (duplex != DUPLEX_FULL) {
  576. DP(BNX2X_MSG_ETHTOOL,
  577. "10G half not supported\n");
  578. return -EINVAL;
  579. }
  580. phy_idx = bnx2x_get_cur_phy_idx(bp);
  581. if ((bp->port.supported[cfg_idx] &
  582. SUPPORTED_10000baseT_Full) &&
  583. (bp->link_params.phy[phy_idx].media_type !=
  584. ETH_PHY_SFP_1G_FIBER)) {
  585. advertising = (ADVERTISED_10000baseT_Full |
  586. ADVERTISED_FIBRE);
  587. } else if (bp->port.supported[cfg_idx] &
  588. SUPPORTED_10000baseKR_Full) {
  589. advertising = (ADVERTISED_10000baseKR_Full |
  590. ADVERTISED_FIBRE);
  591. } else {
  592. DP(BNX2X_MSG_ETHTOOL,
  593. "10G full not supported\n");
  594. return -EINVAL;
  595. }
  596. break;
  597. default:
  598. DP(BNX2X_MSG_ETHTOOL, "Unsupported speed %u\n", speed);
  599. return -EINVAL;
  600. }
  601. bp->link_params.req_line_speed[cfg_idx] = speed;
  602. bp->link_params.req_duplex[cfg_idx] = duplex;
  603. bp->port.advertising[cfg_idx] = advertising;
  604. }
  605. DP(BNX2X_MSG_ETHTOOL, "req_line_speed %d\n"
  606. " req_duplex %d advertising 0x%x\n",
  607. bp->link_params.req_line_speed[cfg_idx],
  608. bp->link_params.req_duplex[cfg_idx],
  609. bp->port.advertising[cfg_idx]);
  610. /* Set new config */
  611. bp->link_params.multi_phy_config = new_multi_phy_config;
  612. if (netif_running(dev)) {
  613. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  614. bnx2x_force_link_reset(bp);
  615. bnx2x_link_set(bp);
  616. }
  617. return 0;
  618. }
  619. #define DUMP_ALL_PRESETS 0x1FFF
  620. #define DUMP_MAX_PRESETS 13
  621. static int __bnx2x_get_preset_regs_len(struct bnx2x *bp, u32 preset)
  622. {
  623. if (CHIP_IS_E1(bp))
  624. return dump_num_registers[0][preset-1];
  625. else if (CHIP_IS_E1H(bp))
  626. return dump_num_registers[1][preset-1];
  627. else if (CHIP_IS_E2(bp))
  628. return dump_num_registers[2][preset-1];
  629. else if (CHIP_IS_E3A0(bp))
  630. return dump_num_registers[3][preset-1];
  631. else if (CHIP_IS_E3B0(bp))
  632. return dump_num_registers[4][preset-1];
  633. else
  634. return 0;
  635. }
  636. static int __bnx2x_get_regs_len(struct bnx2x *bp)
  637. {
  638. u32 preset_idx;
  639. int regdump_len = 0;
  640. /* Calculate the total preset regs length */
  641. for (preset_idx = 1; preset_idx <= DUMP_MAX_PRESETS; preset_idx++)
  642. regdump_len += __bnx2x_get_preset_regs_len(bp, preset_idx);
  643. return regdump_len;
  644. }
  645. static int bnx2x_get_regs_len(struct net_device *dev)
  646. {
  647. struct bnx2x *bp = netdev_priv(dev);
  648. int regdump_len = 0;
  649. if (IS_VF(bp))
  650. return 0;
  651. regdump_len = __bnx2x_get_regs_len(bp);
  652. regdump_len *= 4;
  653. regdump_len += sizeof(struct dump_header);
  654. return regdump_len;
  655. }
  656. #define IS_E1_REG(chips) ((chips & DUMP_CHIP_E1) == DUMP_CHIP_E1)
  657. #define IS_E1H_REG(chips) ((chips & DUMP_CHIP_E1H) == DUMP_CHIP_E1H)
  658. #define IS_E2_REG(chips) ((chips & DUMP_CHIP_E2) == DUMP_CHIP_E2)
  659. #define IS_E3A0_REG(chips) ((chips & DUMP_CHIP_E3A0) == DUMP_CHIP_E3A0)
  660. #define IS_E3B0_REG(chips) ((chips & DUMP_CHIP_E3B0) == DUMP_CHIP_E3B0)
  661. #define IS_REG_IN_PRESET(presets, idx) \
  662. ((presets & (1 << (idx-1))) == (1 << (idx-1)))
  663. /******* Paged registers info selectors ********/
  664. static const u32 *__bnx2x_get_page_addr_ar(struct bnx2x *bp)
  665. {
  666. if (CHIP_IS_E2(bp))
  667. return page_vals_e2;
  668. else if (CHIP_IS_E3(bp))
  669. return page_vals_e3;
  670. else
  671. return NULL;
  672. }
  673. static u32 __bnx2x_get_page_reg_num(struct bnx2x *bp)
  674. {
  675. if (CHIP_IS_E2(bp))
  676. return PAGE_MODE_VALUES_E2;
  677. else if (CHIP_IS_E3(bp))
  678. return PAGE_MODE_VALUES_E3;
  679. else
  680. return 0;
  681. }
  682. static const u32 *__bnx2x_get_page_write_ar(struct bnx2x *bp)
  683. {
  684. if (CHIP_IS_E2(bp))
  685. return page_write_regs_e2;
  686. else if (CHIP_IS_E3(bp))
  687. return page_write_regs_e3;
  688. else
  689. return NULL;
  690. }
  691. static u32 __bnx2x_get_page_write_num(struct bnx2x *bp)
  692. {
  693. if (CHIP_IS_E2(bp))
  694. return PAGE_WRITE_REGS_E2;
  695. else if (CHIP_IS_E3(bp))
  696. return PAGE_WRITE_REGS_E3;
  697. else
  698. return 0;
  699. }
  700. static const struct reg_addr *__bnx2x_get_page_read_ar(struct bnx2x *bp)
  701. {
  702. if (CHIP_IS_E2(bp))
  703. return page_read_regs_e2;
  704. else if (CHIP_IS_E3(bp))
  705. return page_read_regs_e3;
  706. else
  707. return NULL;
  708. }
  709. static u32 __bnx2x_get_page_read_num(struct bnx2x *bp)
  710. {
  711. if (CHIP_IS_E2(bp))
  712. return PAGE_READ_REGS_E2;
  713. else if (CHIP_IS_E3(bp))
  714. return PAGE_READ_REGS_E3;
  715. else
  716. return 0;
  717. }
  718. static bool bnx2x_is_reg_in_chip(struct bnx2x *bp,
  719. const struct reg_addr *reg_info)
  720. {
  721. if (CHIP_IS_E1(bp))
  722. return IS_E1_REG(reg_info->chips);
  723. else if (CHIP_IS_E1H(bp))
  724. return IS_E1H_REG(reg_info->chips);
  725. else if (CHIP_IS_E2(bp))
  726. return IS_E2_REG(reg_info->chips);
  727. else if (CHIP_IS_E3A0(bp))
  728. return IS_E3A0_REG(reg_info->chips);
  729. else if (CHIP_IS_E3B0(bp))
  730. return IS_E3B0_REG(reg_info->chips);
  731. else
  732. return false;
  733. }
  734. static bool bnx2x_is_wreg_in_chip(struct bnx2x *bp,
  735. const struct wreg_addr *wreg_info)
  736. {
  737. if (CHIP_IS_E1(bp))
  738. return IS_E1_REG(wreg_info->chips);
  739. else if (CHIP_IS_E1H(bp))
  740. return IS_E1H_REG(wreg_info->chips);
  741. else if (CHIP_IS_E2(bp))
  742. return IS_E2_REG(wreg_info->chips);
  743. else if (CHIP_IS_E3A0(bp))
  744. return IS_E3A0_REG(wreg_info->chips);
  745. else if (CHIP_IS_E3B0(bp))
  746. return IS_E3B0_REG(wreg_info->chips);
  747. else
  748. return false;
  749. }
  750. /**
  751. * bnx2x_read_pages_regs - read "paged" registers
  752. *
  753. * @bp device handle
  754. * @p output buffer
  755. *
  756. * Reads "paged" memories: memories that may only be read by first writing to a
  757. * specific address ("write address") and then reading from a specific address
  758. * ("read address"). There may be more than one write address per "page" and
  759. * more than one read address per write address.
  760. */
  761. static void bnx2x_read_pages_regs(struct bnx2x *bp, u32 *p, u32 preset)
  762. {
  763. u32 i, j, k, n;
  764. /* addresses of the paged registers */
  765. const u32 *page_addr = __bnx2x_get_page_addr_ar(bp);
  766. /* number of paged registers */
  767. int num_pages = __bnx2x_get_page_reg_num(bp);
  768. /* write addresses */
  769. const u32 *write_addr = __bnx2x_get_page_write_ar(bp);
  770. /* number of write addresses */
  771. int write_num = __bnx2x_get_page_write_num(bp);
  772. /* read addresses info */
  773. const struct reg_addr *read_addr = __bnx2x_get_page_read_ar(bp);
  774. /* number of read addresses */
  775. int read_num = __bnx2x_get_page_read_num(bp);
  776. u32 addr, size;
  777. for (i = 0; i < num_pages; i++) {
  778. for (j = 0; j < write_num; j++) {
  779. REG_WR(bp, write_addr[j], page_addr[i]);
  780. for (k = 0; k < read_num; k++) {
  781. if (IS_REG_IN_PRESET(read_addr[k].presets,
  782. preset)) {
  783. size = read_addr[k].size;
  784. for (n = 0; n < size; n++) {
  785. addr = read_addr[k].addr + n*4;
  786. *p++ = REG_RD(bp, addr);
  787. }
  788. }
  789. }
  790. }
  791. }
  792. }
  793. static int __bnx2x_get_preset_regs(struct bnx2x *bp, u32 *p, u32 preset)
  794. {
  795. u32 i, j, addr;
  796. const struct wreg_addr *wreg_addr_p = NULL;
  797. if (CHIP_IS_E1(bp))
  798. wreg_addr_p = &wreg_addr_e1;
  799. else if (CHIP_IS_E1H(bp))
  800. wreg_addr_p = &wreg_addr_e1h;
  801. else if (CHIP_IS_E2(bp))
  802. wreg_addr_p = &wreg_addr_e2;
  803. else if (CHIP_IS_E3A0(bp))
  804. wreg_addr_p = &wreg_addr_e3;
  805. else if (CHIP_IS_E3B0(bp))
  806. wreg_addr_p = &wreg_addr_e3b0;
  807. /* Read the idle_chk registers */
  808. for (i = 0; i < IDLE_REGS_COUNT; i++) {
  809. if (bnx2x_is_reg_in_chip(bp, &idle_reg_addrs[i]) &&
  810. IS_REG_IN_PRESET(idle_reg_addrs[i].presets, preset)) {
  811. for (j = 0; j < idle_reg_addrs[i].size; j++)
  812. *p++ = REG_RD(bp, idle_reg_addrs[i].addr + j*4);
  813. }
  814. }
  815. /* Read the regular registers */
  816. for (i = 0; i < REGS_COUNT; i++) {
  817. if (bnx2x_is_reg_in_chip(bp, &reg_addrs[i]) &&
  818. IS_REG_IN_PRESET(reg_addrs[i].presets, preset)) {
  819. for (j = 0; j < reg_addrs[i].size; j++)
  820. *p++ = REG_RD(bp, reg_addrs[i].addr + j*4);
  821. }
  822. }
  823. /* Read the CAM registers */
  824. if (bnx2x_is_wreg_in_chip(bp, wreg_addr_p) &&
  825. IS_REG_IN_PRESET(wreg_addr_p->presets, preset)) {
  826. for (i = 0; i < wreg_addr_p->size; i++) {
  827. *p++ = REG_RD(bp, wreg_addr_p->addr + i*4);
  828. /* In case of wreg_addr register, read additional
  829. registers from read_regs array
  830. */
  831. for (j = 0; j < wreg_addr_p->read_regs_count; j++) {
  832. addr = *(wreg_addr_p->read_regs);
  833. *p++ = REG_RD(bp, addr + j*4);
  834. }
  835. }
  836. }
  837. /* Paged registers are supported in E2 & E3 only */
  838. if (CHIP_IS_E2(bp) || CHIP_IS_E3(bp)) {
  839. /* Read "paged" registers */
  840. bnx2x_read_pages_regs(bp, p, preset);
  841. }
  842. return 0;
  843. }
  844. static void __bnx2x_get_regs(struct bnx2x *bp, u32 *p)
  845. {
  846. u32 preset_idx;
  847. /* Read all registers, by reading all preset registers */
  848. for (preset_idx = 1; preset_idx <= DUMP_MAX_PRESETS; preset_idx++) {
  849. /* Skip presets with IOR */
  850. if ((preset_idx == 2) ||
  851. (preset_idx == 5) ||
  852. (preset_idx == 8) ||
  853. (preset_idx == 11))
  854. continue;
  855. __bnx2x_get_preset_regs(bp, p, preset_idx);
  856. p += __bnx2x_get_preset_regs_len(bp, preset_idx);
  857. }
  858. }
  859. static void bnx2x_get_regs(struct net_device *dev,
  860. struct ethtool_regs *regs, void *_p)
  861. {
  862. u32 *p = _p;
  863. struct bnx2x *bp = netdev_priv(dev);
  864. struct dump_header dump_hdr = {0};
  865. regs->version = 2;
  866. memset(p, 0, regs->len);
  867. if (!netif_running(bp->dev))
  868. return;
  869. /* Disable parity attentions as long as following dump may
  870. * cause false alarms by reading never written registers. We
  871. * will re-enable parity attentions right after the dump.
  872. */
  873. bnx2x_disable_blocks_parity(bp);
  874. dump_hdr.header_size = (sizeof(struct dump_header) / 4) - 1;
  875. dump_hdr.preset = DUMP_ALL_PRESETS;
  876. dump_hdr.version = BNX2X_DUMP_VERSION;
  877. /* dump_meta_data presents OR of CHIP and PATH. */
  878. if (CHIP_IS_E1(bp)) {
  879. dump_hdr.dump_meta_data = DUMP_CHIP_E1;
  880. } else if (CHIP_IS_E1H(bp)) {
  881. dump_hdr.dump_meta_data = DUMP_CHIP_E1H;
  882. } else if (CHIP_IS_E2(bp)) {
  883. dump_hdr.dump_meta_data = DUMP_CHIP_E2 |
  884. (BP_PATH(bp) ? DUMP_PATH_1 : DUMP_PATH_0);
  885. } else if (CHIP_IS_E3A0(bp)) {
  886. dump_hdr.dump_meta_data = DUMP_CHIP_E3A0 |
  887. (BP_PATH(bp) ? DUMP_PATH_1 : DUMP_PATH_0);
  888. } else if (CHIP_IS_E3B0(bp)) {
  889. dump_hdr.dump_meta_data = DUMP_CHIP_E3B0 |
  890. (BP_PATH(bp) ? DUMP_PATH_1 : DUMP_PATH_0);
  891. }
  892. memcpy(p, &dump_hdr, sizeof(struct dump_header));
  893. p += dump_hdr.header_size + 1;
  894. /* This isn't really an error, but since attention handling is going
  895. * to print the GRC timeouts using this macro, we use the same.
  896. */
  897. BNX2X_ERR("Generating register dump. Might trigger harmless GRC timeouts\n");
  898. /* Actually read the registers */
  899. __bnx2x_get_regs(bp, p);
  900. /* Re-enable parity attentions */
  901. bnx2x_clear_blocks_parity(bp);
  902. bnx2x_enable_blocks_parity(bp);
  903. }
  904. static int bnx2x_get_preset_regs_len(struct net_device *dev, u32 preset)
  905. {
  906. struct bnx2x *bp = netdev_priv(dev);
  907. int regdump_len = 0;
  908. regdump_len = __bnx2x_get_preset_regs_len(bp, preset);
  909. regdump_len *= 4;
  910. regdump_len += sizeof(struct dump_header);
  911. return regdump_len;
  912. }
  913. static int bnx2x_set_dump(struct net_device *dev, struct ethtool_dump *val)
  914. {
  915. struct bnx2x *bp = netdev_priv(dev);
  916. /* Use the ethtool_dump "flag" field as the dump preset index */
  917. if (val->flag < 1 || val->flag > DUMP_MAX_PRESETS)
  918. return -EINVAL;
  919. bp->dump_preset_idx = val->flag;
  920. return 0;
  921. }
  922. static int bnx2x_get_dump_flag(struct net_device *dev,
  923. struct ethtool_dump *dump)
  924. {
  925. struct bnx2x *bp = netdev_priv(dev);
  926. dump->version = BNX2X_DUMP_VERSION;
  927. dump->flag = bp->dump_preset_idx;
  928. /* Calculate the requested preset idx length */
  929. dump->len = bnx2x_get_preset_regs_len(dev, bp->dump_preset_idx);
  930. DP(BNX2X_MSG_ETHTOOL, "Get dump preset %d length=%d\n",
  931. bp->dump_preset_idx, dump->len);
  932. return 0;
  933. }
  934. static int bnx2x_get_dump_data(struct net_device *dev,
  935. struct ethtool_dump *dump,
  936. void *buffer)
  937. {
  938. u32 *p = buffer;
  939. struct bnx2x *bp = netdev_priv(dev);
  940. struct dump_header dump_hdr = {0};
  941. /* Disable parity attentions as long as following dump may
  942. * cause false alarms by reading never written registers. We
  943. * will re-enable parity attentions right after the dump.
  944. */
  945. bnx2x_disable_blocks_parity(bp);
  946. dump_hdr.header_size = (sizeof(struct dump_header) / 4) - 1;
  947. dump_hdr.preset = bp->dump_preset_idx;
  948. dump_hdr.version = BNX2X_DUMP_VERSION;
  949. DP(BNX2X_MSG_ETHTOOL, "Get dump data of preset %d\n", dump_hdr.preset);
  950. /* dump_meta_data presents OR of CHIP and PATH. */
  951. if (CHIP_IS_E1(bp)) {
  952. dump_hdr.dump_meta_data = DUMP_CHIP_E1;
  953. } else if (CHIP_IS_E1H(bp)) {
  954. dump_hdr.dump_meta_data = DUMP_CHIP_E1H;
  955. } else if (CHIP_IS_E2(bp)) {
  956. dump_hdr.dump_meta_data = DUMP_CHIP_E2 |
  957. (BP_PATH(bp) ? DUMP_PATH_1 : DUMP_PATH_0);
  958. } else if (CHIP_IS_E3A0(bp)) {
  959. dump_hdr.dump_meta_data = DUMP_CHIP_E3A0 |
  960. (BP_PATH(bp) ? DUMP_PATH_1 : DUMP_PATH_0);
  961. } else if (CHIP_IS_E3B0(bp)) {
  962. dump_hdr.dump_meta_data = DUMP_CHIP_E3B0 |
  963. (BP_PATH(bp) ? DUMP_PATH_1 : DUMP_PATH_0);
  964. }
  965. memcpy(p, &dump_hdr, sizeof(struct dump_header));
  966. p += dump_hdr.header_size + 1;
  967. /* Actually read the registers */
  968. __bnx2x_get_preset_regs(bp, p, dump_hdr.preset);
  969. /* Re-enable parity attentions */
  970. bnx2x_clear_blocks_parity(bp);
  971. bnx2x_enable_blocks_parity(bp);
  972. return 0;
  973. }
  974. static void bnx2x_get_drvinfo(struct net_device *dev,
  975. struct ethtool_drvinfo *info)
  976. {
  977. struct bnx2x *bp = netdev_priv(dev);
  978. strlcpy(info->driver, DRV_MODULE_NAME, sizeof(info->driver));
  979. strlcpy(info->version, DRV_MODULE_VERSION, sizeof(info->version));
  980. bnx2x_fill_fw_str(bp, info->fw_version, sizeof(info->fw_version));
  981. strlcpy(info->bus_info, pci_name(bp->pdev), sizeof(info->bus_info));
  982. }
  983. static void bnx2x_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  984. {
  985. struct bnx2x *bp = netdev_priv(dev);
  986. if (bp->flags & NO_WOL_FLAG) {
  987. wol->supported = 0;
  988. wol->wolopts = 0;
  989. } else {
  990. wol->supported = WAKE_MAGIC;
  991. if (bp->wol)
  992. wol->wolopts = WAKE_MAGIC;
  993. else
  994. wol->wolopts = 0;
  995. }
  996. memset(&wol->sopass, 0, sizeof(wol->sopass));
  997. }
  998. static int bnx2x_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  999. {
  1000. struct bnx2x *bp = netdev_priv(dev);
  1001. if (wol->wolopts & ~WAKE_MAGIC) {
  1002. DP(BNX2X_MSG_ETHTOOL, "WOL not supported\n");
  1003. return -EINVAL;
  1004. }
  1005. if (wol->wolopts & WAKE_MAGIC) {
  1006. if (bp->flags & NO_WOL_FLAG) {
  1007. DP(BNX2X_MSG_ETHTOOL, "WOL not supported\n");
  1008. return -EINVAL;
  1009. }
  1010. bp->wol = 1;
  1011. } else
  1012. bp->wol = 0;
  1013. if (SHMEM2_HAS(bp, curr_cfg))
  1014. SHMEM2_WR(bp, curr_cfg, CURR_CFG_MET_OS);
  1015. return 0;
  1016. }
  1017. static u32 bnx2x_get_msglevel(struct net_device *dev)
  1018. {
  1019. struct bnx2x *bp = netdev_priv(dev);
  1020. return bp->msg_enable;
  1021. }
  1022. static void bnx2x_set_msglevel(struct net_device *dev, u32 level)
  1023. {
  1024. struct bnx2x *bp = netdev_priv(dev);
  1025. if (capable(CAP_NET_ADMIN)) {
  1026. /* dump MCP trace */
  1027. if (IS_PF(bp) && (level & BNX2X_MSG_MCP))
  1028. bnx2x_fw_dump_lvl(bp, KERN_INFO);
  1029. bp->msg_enable = level;
  1030. }
  1031. }
  1032. static int bnx2x_nway_reset(struct net_device *dev)
  1033. {
  1034. struct bnx2x *bp = netdev_priv(dev);
  1035. if (!bp->port.pmf)
  1036. return 0;
  1037. if (netif_running(dev)) {
  1038. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  1039. bnx2x_force_link_reset(bp);
  1040. bnx2x_link_set(bp);
  1041. }
  1042. return 0;
  1043. }
  1044. static u32 bnx2x_get_link(struct net_device *dev)
  1045. {
  1046. struct bnx2x *bp = netdev_priv(dev);
  1047. if (bp->flags & MF_FUNC_DIS || (bp->state != BNX2X_STATE_OPEN))
  1048. return 0;
  1049. if (IS_VF(bp))
  1050. return !test_bit(BNX2X_LINK_REPORT_LINK_DOWN,
  1051. &bp->vf_link_vars.link_report_flags);
  1052. return bp->link_vars.link_up;
  1053. }
  1054. static int bnx2x_get_eeprom_len(struct net_device *dev)
  1055. {
  1056. struct bnx2x *bp = netdev_priv(dev);
  1057. return bp->common.flash_size;
  1058. }
  1059. /* Per pf misc lock must be acquired before the per port mcp lock. Otherwise,
  1060. * had we done things the other way around, if two pfs from the same port would
  1061. * attempt to access nvram at the same time, we could run into a scenario such
  1062. * as:
  1063. * pf A takes the port lock.
  1064. * pf B succeeds in taking the same lock since they are from the same port.
  1065. * pf A takes the per pf misc lock. Performs eeprom access.
  1066. * pf A finishes. Unlocks the per pf misc lock.
  1067. * Pf B takes the lock and proceeds to perform it's own access.
  1068. * pf A unlocks the per port lock, while pf B is still working (!).
  1069. * mcp takes the per port lock and corrupts pf B's access (and/or has it's own
  1070. * access corrupted by pf B)
  1071. */
  1072. static int bnx2x_acquire_nvram_lock(struct bnx2x *bp)
  1073. {
  1074. int port = BP_PORT(bp);
  1075. int count, i;
  1076. u32 val;
  1077. /* acquire HW lock: protect against other PFs in PF Direct Assignment */
  1078. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_NVRAM);
  1079. /* adjust timeout for emulation/FPGA */
  1080. count = BNX2X_NVRAM_TIMEOUT_COUNT;
  1081. if (CHIP_REV_IS_SLOW(bp))
  1082. count *= 100;
  1083. /* request access to nvram interface */
  1084. REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
  1085. (MCPR_NVM_SW_ARB_ARB_REQ_SET1 << port));
  1086. for (i = 0; i < count*10; i++) {
  1087. val = REG_RD(bp, MCP_REG_MCPR_NVM_SW_ARB);
  1088. if (val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port))
  1089. break;
  1090. udelay(5);
  1091. }
  1092. if (!(val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port))) {
  1093. DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
  1094. "cannot get access to nvram interface\n");
  1095. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_NVRAM);
  1096. return -EBUSY;
  1097. }
  1098. return 0;
  1099. }
  1100. static int bnx2x_release_nvram_lock(struct bnx2x *bp)
  1101. {
  1102. int port = BP_PORT(bp);
  1103. int count, i;
  1104. u32 val;
  1105. /* adjust timeout for emulation/FPGA */
  1106. count = BNX2X_NVRAM_TIMEOUT_COUNT;
  1107. if (CHIP_REV_IS_SLOW(bp))
  1108. count *= 100;
  1109. /* relinquish nvram interface */
  1110. REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
  1111. (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << port));
  1112. for (i = 0; i < count*10; i++) {
  1113. val = REG_RD(bp, MCP_REG_MCPR_NVM_SW_ARB);
  1114. if (!(val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port)))
  1115. break;
  1116. udelay(5);
  1117. }
  1118. if (val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port)) {
  1119. DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
  1120. "cannot free access to nvram interface\n");
  1121. return -EBUSY;
  1122. }
  1123. /* release HW lock: protect against other PFs in PF Direct Assignment */
  1124. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_NVRAM);
  1125. return 0;
  1126. }
  1127. static void bnx2x_enable_nvram_access(struct bnx2x *bp)
  1128. {
  1129. u32 val;
  1130. val = REG_RD(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE);
  1131. /* enable both bits, even on read */
  1132. REG_WR(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE,
  1133. (val | MCPR_NVM_ACCESS_ENABLE_EN |
  1134. MCPR_NVM_ACCESS_ENABLE_WR_EN));
  1135. }
  1136. static void bnx2x_disable_nvram_access(struct bnx2x *bp)
  1137. {
  1138. u32 val;
  1139. val = REG_RD(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE);
  1140. /* disable both bits, even after read */
  1141. REG_WR(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE,
  1142. (val & ~(MCPR_NVM_ACCESS_ENABLE_EN |
  1143. MCPR_NVM_ACCESS_ENABLE_WR_EN)));
  1144. }
  1145. static int bnx2x_nvram_read_dword(struct bnx2x *bp, u32 offset, __be32 *ret_val,
  1146. u32 cmd_flags)
  1147. {
  1148. int count, i, rc;
  1149. u32 val;
  1150. /* build the command word */
  1151. cmd_flags |= MCPR_NVM_COMMAND_DOIT;
  1152. /* need to clear DONE bit separately */
  1153. REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, MCPR_NVM_COMMAND_DONE);
  1154. /* address of the NVRAM to read from */
  1155. REG_WR(bp, MCP_REG_MCPR_NVM_ADDR,
  1156. (offset & MCPR_NVM_ADDR_NVM_ADDR_VALUE));
  1157. /* issue a read command */
  1158. REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, cmd_flags);
  1159. /* adjust timeout for emulation/FPGA */
  1160. count = BNX2X_NVRAM_TIMEOUT_COUNT;
  1161. if (CHIP_REV_IS_SLOW(bp))
  1162. count *= 100;
  1163. /* wait for completion */
  1164. *ret_val = 0;
  1165. rc = -EBUSY;
  1166. for (i = 0; i < count; i++) {
  1167. udelay(5);
  1168. val = REG_RD(bp, MCP_REG_MCPR_NVM_COMMAND);
  1169. if (val & MCPR_NVM_COMMAND_DONE) {
  1170. val = REG_RD(bp, MCP_REG_MCPR_NVM_READ);
  1171. /* we read nvram data in cpu order
  1172. * but ethtool sees it as an array of bytes
  1173. * converting to big-endian will do the work
  1174. */
  1175. *ret_val = cpu_to_be32(val);
  1176. rc = 0;
  1177. break;
  1178. }
  1179. }
  1180. if (rc == -EBUSY)
  1181. DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
  1182. "nvram read timeout expired\n");
  1183. return rc;
  1184. }
  1185. int bnx2x_nvram_read(struct bnx2x *bp, u32 offset, u8 *ret_buf,
  1186. int buf_size)
  1187. {
  1188. int rc;
  1189. u32 cmd_flags;
  1190. __be32 val;
  1191. if ((offset & 0x03) || (buf_size & 0x03) || (buf_size == 0)) {
  1192. DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
  1193. "Invalid parameter: offset 0x%x buf_size 0x%x\n",
  1194. offset, buf_size);
  1195. return -EINVAL;
  1196. }
  1197. if (offset + buf_size > bp->common.flash_size) {
  1198. DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
  1199. "Invalid parameter: offset (0x%x) + buf_size (0x%x) > flash_size (0x%x)\n",
  1200. offset, buf_size, bp->common.flash_size);
  1201. return -EINVAL;
  1202. }
  1203. /* request access to nvram interface */
  1204. rc = bnx2x_acquire_nvram_lock(bp);
  1205. if (rc)
  1206. return rc;
  1207. /* enable access to nvram interface */
  1208. bnx2x_enable_nvram_access(bp);
  1209. /* read the first word(s) */
  1210. cmd_flags = MCPR_NVM_COMMAND_FIRST;
  1211. while ((buf_size > sizeof(u32)) && (rc == 0)) {
  1212. rc = bnx2x_nvram_read_dword(bp, offset, &val, cmd_flags);
  1213. memcpy(ret_buf, &val, 4);
  1214. /* advance to the next dword */
  1215. offset += sizeof(u32);
  1216. ret_buf += sizeof(u32);
  1217. buf_size -= sizeof(u32);
  1218. cmd_flags = 0;
  1219. }
  1220. if (rc == 0) {
  1221. cmd_flags |= MCPR_NVM_COMMAND_LAST;
  1222. rc = bnx2x_nvram_read_dword(bp, offset, &val, cmd_flags);
  1223. memcpy(ret_buf, &val, 4);
  1224. }
  1225. /* disable access to nvram interface */
  1226. bnx2x_disable_nvram_access(bp);
  1227. bnx2x_release_nvram_lock(bp);
  1228. return rc;
  1229. }
  1230. static int bnx2x_nvram_read32(struct bnx2x *bp, u32 offset, u32 *buf,
  1231. int buf_size)
  1232. {
  1233. int rc;
  1234. rc = bnx2x_nvram_read(bp, offset, (u8 *)buf, buf_size);
  1235. if (!rc) {
  1236. __be32 *be = (__be32 *)buf;
  1237. while ((buf_size -= 4) >= 0)
  1238. *buf++ = be32_to_cpu(*be++);
  1239. }
  1240. return rc;
  1241. }
  1242. static bool bnx2x_is_nvm_accessible(struct bnx2x *bp)
  1243. {
  1244. int rc = 1;
  1245. u16 pm = 0;
  1246. struct net_device *dev = pci_get_drvdata(bp->pdev);
  1247. if (bp->pdev->pm_cap)
  1248. rc = pci_read_config_word(bp->pdev,
  1249. bp->pdev->pm_cap + PCI_PM_CTRL, &pm);
  1250. if ((rc && !netif_running(dev)) ||
  1251. (!rc && ((pm & PCI_PM_CTRL_STATE_MASK) != (__force u16)PCI_D0)))
  1252. return false;
  1253. return true;
  1254. }
  1255. static int bnx2x_get_eeprom(struct net_device *dev,
  1256. struct ethtool_eeprom *eeprom, u8 *eebuf)
  1257. {
  1258. struct bnx2x *bp = netdev_priv(dev);
  1259. if (!bnx2x_is_nvm_accessible(bp)) {
  1260. DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
  1261. "cannot access eeprom when the interface is down\n");
  1262. return -EAGAIN;
  1263. }
  1264. DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM, "ethtool_eeprom: cmd %d\n"
  1265. " magic 0x%x offset 0x%x (%d) len 0x%x (%d)\n",
  1266. eeprom->cmd, eeprom->magic, eeprom->offset, eeprom->offset,
  1267. eeprom->len, eeprom->len);
  1268. /* parameters already validated in ethtool_get_eeprom */
  1269. return bnx2x_nvram_read(bp, eeprom->offset, eebuf, eeprom->len);
  1270. }
  1271. static int bnx2x_get_module_eeprom(struct net_device *dev,
  1272. struct ethtool_eeprom *ee,
  1273. u8 *data)
  1274. {
  1275. struct bnx2x *bp = netdev_priv(dev);
  1276. int rc = -EINVAL, phy_idx;
  1277. u8 *user_data = data;
  1278. unsigned int start_addr = ee->offset, xfer_size = 0;
  1279. if (!bnx2x_is_nvm_accessible(bp)) {
  1280. DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
  1281. "cannot access eeprom when the interface is down\n");
  1282. return -EAGAIN;
  1283. }
  1284. phy_idx = bnx2x_get_cur_phy_idx(bp);
  1285. /* Read A0 section */
  1286. if (start_addr < ETH_MODULE_SFF_8079_LEN) {
  1287. /* Limit transfer size to the A0 section boundary */
  1288. if (start_addr + ee->len > ETH_MODULE_SFF_8079_LEN)
  1289. xfer_size = ETH_MODULE_SFF_8079_LEN - start_addr;
  1290. else
  1291. xfer_size = ee->len;
  1292. bnx2x_acquire_phy_lock(bp);
  1293. rc = bnx2x_read_sfp_module_eeprom(&bp->link_params.phy[phy_idx],
  1294. &bp->link_params,
  1295. I2C_DEV_ADDR_A0,
  1296. start_addr,
  1297. xfer_size,
  1298. user_data);
  1299. bnx2x_release_phy_lock(bp);
  1300. if (rc) {
  1301. DP(BNX2X_MSG_ETHTOOL, "Failed reading A0 section\n");
  1302. return -EINVAL;
  1303. }
  1304. user_data += xfer_size;
  1305. start_addr += xfer_size;
  1306. }
  1307. /* Read A2 section */
  1308. if ((start_addr >= ETH_MODULE_SFF_8079_LEN) &&
  1309. (start_addr < ETH_MODULE_SFF_8472_LEN)) {
  1310. xfer_size = ee->len - xfer_size;
  1311. /* Limit transfer size to the A2 section boundary */
  1312. if (start_addr + xfer_size > ETH_MODULE_SFF_8472_LEN)
  1313. xfer_size = ETH_MODULE_SFF_8472_LEN - start_addr;
  1314. start_addr -= ETH_MODULE_SFF_8079_LEN;
  1315. bnx2x_acquire_phy_lock(bp);
  1316. rc = bnx2x_read_sfp_module_eeprom(&bp->link_params.phy[phy_idx],
  1317. &bp->link_params,
  1318. I2C_DEV_ADDR_A2,
  1319. start_addr,
  1320. xfer_size,
  1321. user_data);
  1322. bnx2x_release_phy_lock(bp);
  1323. if (rc) {
  1324. DP(BNX2X_MSG_ETHTOOL, "Failed reading A2 section\n");
  1325. return -EINVAL;
  1326. }
  1327. }
  1328. return rc;
  1329. }
  1330. static int bnx2x_get_module_info(struct net_device *dev,
  1331. struct ethtool_modinfo *modinfo)
  1332. {
  1333. struct bnx2x *bp = netdev_priv(dev);
  1334. int phy_idx, rc;
  1335. u8 sff8472_comp, diag_type;
  1336. if (!bnx2x_is_nvm_accessible(bp)) {
  1337. DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
  1338. "cannot access eeprom when the interface is down\n");
  1339. return -EAGAIN;
  1340. }
  1341. phy_idx = bnx2x_get_cur_phy_idx(bp);
  1342. bnx2x_acquire_phy_lock(bp);
  1343. rc = bnx2x_read_sfp_module_eeprom(&bp->link_params.phy[phy_idx],
  1344. &bp->link_params,
  1345. I2C_DEV_ADDR_A0,
  1346. SFP_EEPROM_SFF_8472_COMP_ADDR,
  1347. SFP_EEPROM_SFF_8472_COMP_SIZE,
  1348. &sff8472_comp);
  1349. bnx2x_release_phy_lock(bp);
  1350. if (rc) {
  1351. DP(BNX2X_MSG_ETHTOOL, "Failed reading SFF-8472 comp field\n");
  1352. return -EINVAL;
  1353. }
  1354. bnx2x_acquire_phy_lock(bp);
  1355. rc = bnx2x_read_sfp_module_eeprom(&bp->link_params.phy[phy_idx],
  1356. &bp->link_params,
  1357. I2C_DEV_ADDR_A0,
  1358. SFP_EEPROM_DIAG_TYPE_ADDR,
  1359. SFP_EEPROM_DIAG_TYPE_SIZE,
  1360. &diag_type);
  1361. bnx2x_release_phy_lock(bp);
  1362. if (rc) {
  1363. DP(BNX2X_MSG_ETHTOOL, "Failed reading Diag Type field\n");
  1364. return -EINVAL;
  1365. }
  1366. if (!sff8472_comp ||
  1367. (diag_type & SFP_EEPROM_DIAG_ADDR_CHANGE_REQ) ||
  1368. !(diag_type & SFP_EEPROM_DDM_IMPLEMENTED)) {
  1369. modinfo->type = ETH_MODULE_SFF_8079;
  1370. modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
  1371. } else {
  1372. modinfo->type = ETH_MODULE_SFF_8472;
  1373. modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN;
  1374. }
  1375. return 0;
  1376. }
  1377. static int bnx2x_nvram_write_dword(struct bnx2x *bp, u32 offset, u32 val,
  1378. u32 cmd_flags)
  1379. {
  1380. int count, i, rc;
  1381. /* build the command word */
  1382. cmd_flags |= MCPR_NVM_COMMAND_DOIT | MCPR_NVM_COMMAND_WR;
  1383. /* need to clear DONE bit separately */
  1384. REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, MCPR_NVM_COMMAND_DONE);
  1385. /* write the data */
  1386. REG_WR(bp, MCP_REG_MCPR_NVM_WRITE, val);
  1387. /* address of the NVRAM to write to */
  1388. REG_WR(bp, MCP_REG_MCPR_NVM_ADDR,
  1389. (offset & MCPR_NVM_ADDR_NVM_ADDR_VALUE));
  1390. /* issue the write command */
  1391. REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, cmd_flags);
  1392. /* adjust timeout for emulation/FPGA */
  1393. count = BNX2X_NVRAM_TIMEOUT_COUNT;
  1394. if (CHIP_REV_IS_SLOW(bp))
  1395. count *= 100;
  1396. /* wait for completion */
  1397. rc = -EBUSY;
  1398. for (i = 0; i < count; i++) {
  1399. udelay(5);
  1400. val = REG_RD(bp, MCP_REG_MCPR_NVM_COMMAND);
  1401. if (val & MCPR_NVM_COMMAND_DONE) {
  1402. rc = 0;
  1403. break;
  1404. }
  1405. }
  1406. if (rc == -EBUSY)
  1407. DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
  1408. "nvram write timeout expired\n");
  1409. return rc;
  1410. }
  1411. #define BYTE_OFFSET(offset) (8 * (offset & 0x03))
  1412. static int bnx2x_nvram_write1(struct bnx2x *bp, u32 offset, u8 *data_buf,
  1413. int buf_size)
  1414. {
  1415. int rc;
  1416. u32 cmd_flags, align_offset, val;
  1417. __be32 val_be;
  1418. if (offset + buf_size > bp->common.flash_size) {
  1419. DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
  1420. "Invalid parameter: offset (0x%x) + buf_size (0x%x) > flash_size (0x%x)\n",
  1421. offset, buf_size, bp->common.flash_size);
  1422. return -EINVAL;
  1423. }
  1424. /* request access to nvram interface */
  1425. rc = bnx2x_acquire_nvram_lock(bp);
  1426. if (rc)
  1427. return rc;
  1428. /* enable access to nvram interface */
  1429. bnx2x_enable_nvram_access(bp);
  1430. cmd_flags = (MCPR_NVM_COMMAND_FIRST | MCPR_NVM_COMMAND_LAST);
  1431. align_offset = (offset & ~0x03);
  1432. rc = bnx2x_nvram_read_dword(bp, align_offset, &val_be, cmd_flags);
  1433. if (rc == 0) {
  1434. /* nvram data is returned as an array of bytes
  1435. * convert it back to cpu order
  1436. */
  1437. val = be32_to_cpu(val_be);
  1438. val &= ~le32_to_cpu((__force __le32)
  1439. (0xff << BYTE_OFFSET(offset)));
  1440. val |= le32_to_cpu((__force __le32)
  1441. (*data_buf << BYTE_OFFSET(offset)));
  1442. rc = bnx2x_nvram_write_dword(bp, align_offset, val,
  1443. cmd_flags);
  1444. }
  1445. /* disable access to nvram interface */
  1446. bnx2x_disable_nvram_access(bp);
  1447. bnx2x_release_nvram_lock(bp);
  1448. return rc;
  1449. }
  1450. static int bnx2x_nvram_write(struct bnx2x *bp, u32 offset, u8 *data_buf,
  1451. int buf_size)
  1452. {
  1453. int rc;
  1454. u32 cmd_flags;
  1455. u32 val;
  1456. u32 written_so_far;
  1457. if (buf_size == 1) /* ethtool */
  1458. return bnx2x_nvram_write1(bp, offset, data_buf, buf_size);
  1459. if ((offset & 0x03) || (buf_size & 0x03) || (buf_size == 0)) {
  1460. DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
  1461. "Invalid parameter: offset 0x%x buf_size 0x%x\n",
  1462. offset, buf_size);
  1463. return -EINVAL;
  1464. }
  1465. if (offset + buf_size > bp->common.flash_size) {
  1466. DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
  1467. "Invalid parameter: offset (0x%x) + buf_size (0x%x) > flash_size (0x%x)\n",
  1468. offset, buf_size, bp->common.flash_size);
  1469. return -EINVAL;
  1470. }
  1471. /* request access to nvram interface */
  1472. rc = bnx2x_acquire_nvram_lock(bp);
  1473. if (rc)
  1474. return rc;
  1475. /* enable access to nvram interface */
  1476. bnx2x_enable_nvram_access(bp);
  1477. written_so_far = 0;
  1478. cmd_flags = MCPR_NVM_COMMAND_FIRST;
  1479. while ((written_so_far < buf_size) && (rc == 0)) {
  1480. if (written_so_far == (buf_size - sizeof(u32)))
  1481. cmd_flags |= MCPR_NVM_COMMAND_LAST;
  1482. else if (((offset + 4) % BNX2X_NVRAM_PAGE_SIZE) == 0)
  1483. cmd_flags |= MCPR_NVM_COMMAND_LAST;
  1484. else if ((offset % BNX2X_NVRAM_PAGE_SIZE) == 0)
  1485. cmd_flags |= MCPR_NVM_COMMAND_FIRST;
  1486. memcpy(&val, data_buf, 4);
  1487. /* Notice unlike bnx2x_nvram_read_dword() this will not
  1488. * change val using be32_to_cpu(), which causes data to flip
  1489. * if the eeprom is read and then written back. This is due
  1490. * to tools utilizing this functionality that would break
  1491. * if this would be resolved.
  1492. */
  1493. rc = bnx2x_nvram_write_dword(bp, offset, val, cmd_flags);
  1494. /* advance to the next dword */
  1495. offset += sizeof(u32);
  1496. data_buf += sizeof(u32);
  1497. written_so_far += sizeof(u32);
  1498. /* At end of each 4Kb page, release nvram lock to allow MFW
  1499. * chance to take it for its own use.
  1500. */
  1501. if ((cmd_flags & MCPR_NVM_COMMAND_LAST) &&
  1502. (written_so_far < buf_size)) {
  1503. DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
  1504. "Releasing NVM lock after offset 0x%x\n",
  1505. (u32)(offset - sizeof(u32)));
  1506. bnx2x_release_nvram_lock(bp);
  1507. usleep_range(1000, 2000);
  1508. rc = bnx2x_acquire_nvram_lock(bp);
  1509. if (rc)
  1510. return rc;
  1511. }
  1512. cmd_flags = 0;
  1513. }
  1514. /* disable access to nvram interface */
  1515. bnx2x_disable_nvram_access(bp);
  1516. bnx2x_release_nvram_lock(bp);
  1517. return rc;
  1518. }
  1519. static int bnx2x_set_eeprom(struct net_device *dev,
  1520. struct ethtool_eeprom *eeprom, u8 *eebuf)
  1521. {
  1522. struct bnx2x *bp = netdev_priv(dev);
  1523. int port = BP_PORT(bp);
  1524. int rc = 0;
  1525. u32 ext_phy_config;
  1526. if (!bnx2x_is_nvm_accessible(bp)) {
  1527. DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
  1528. "cannot access eeprom when the interface is down\n");
  1529. return -EAGAIN;
  1530. }
  1531. DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM, "ethtool_eeprom: cmd %d\n"
  1532. " magic 0x%x offset 0x%x (%d) len 0x%x (%d)\n",
  1533. eeprom->cmd, eeprom->magic, eeprom->offset, eeprom->offset,
  1534. eeprom->len, eeprom->len);
  1535. /* parameters already validated in ethtool_set_eeprom */
  1536. /* PHY eeprom can be accessed only by the PMF */
  1537. if ((eeprom->magic >= 0x50485900) && (eeprom->magic <= 0x504859FF) &&
  1538. !bp->port.pmf) {
  1539. DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
  1540. "wrong magic or interface is not pmf\n");
  1541. return -EINVAL;
  1542. }
  1543. ext_phy_config =
  1544. SHMEM_RD(bp,
  1545. dev_info.port_hw_config[port].external_phy_config);
  1546. if (eeprom->magic == 0x50485950) {
  1547. /* 'PHYP' (0x50485950): prepare phy for FW upgrade */
  1548. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  1549. bnx2x_acquire_phy_lock(bp);
  1550. rc |= bnx2x_link_reset(&bp->link_params,
  1551. &bp->link_vars, 0);
  1552. if (XGXS_EXT_PHY_TYPE(ext_phy_config) ==
  1553. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101)
  1554. bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_0,
  1555. MISC_REGISTERS_GPIO_HIGH, port);
  1556. bnx2x_release_phy_lock(bp);
  1557. bnx2x_link_report(bp);
  1558. } else if (eeprom->magic == 0x50485952) {
  1559. /* 'PHYR' (0x50485952): re-init link after FW upgrade */
  1560. if (bp->state == BNX2X_STATE_OPEN) {
  1561. bnx2x_acquire_phy_lock(bp);
  1562. rc |= bnx2x_link_reset(&bp->link_params,
  1563. &bp->link_vars, 1);
  1564. rc |= bnx2x_phy_init(&bp->link_params,
  1565. &bp->link_vars);
  1566. bnx2x_release_phy_lock(bp);
  1567. bnx2x_calc_fc_adv(bp);
  1568. }
  1569. } else if (eeprom->magic == 0x53985943) {
  1570. /* 'PHYC' (0x53985943): PHY FW upgrade completed */
  1571. if (XGXS_EXT_PHY_TYPE(ext_phy_config) ==
  1572. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101) {
  1573. /* DSP Remove Download Mode */
  1574. bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_0,
  1575. MISC_REGISTERS_GPIO_LOW, port);
  1576. bnx2x_acquire_phy_lock(bp);
  1577. bnx2x_sfx7101_sp_sw_reset(bp,
  1578. &bp->link_params.phy[EXT_PHY1]);
  1579. /* wait 0.5 sec to allow it to run */
  1580. msleep(500);
  1581. bnx2x_ext_phy_hw_reset(bp, port);
  1582. msleep(500);
  1583. bnx2x_release_phy_lock(bp);
  1584. }
  1585. } else
  1586. rc = bnx2x_nvram_write(bp, eeprom->offset, eebuf, eeprom->len);
  1587. return rc;
  1588. }
  1589. static int bnx2x_get_coalesce(struct net_device *dev,
  1590. struct ethtool_coalesce *coal)
  1591. {
  1592. struct bnx2x *bp = netdev_priv(dev);
  1593. memset(coal, 0, sizeof(struct ethtool_coalesce));
  1594. coal->rx_coalesce_usecs = bp->rx_ticks;
  1595. coal->tx_coalesce_usecs = bp->tx_ticks;
  1596. return 0;
  1597. }
  1598. static int bnx2x_set_coalesce(struct net_device *dev,
  1599. struct ethtool_coalesce *coal)
  1600. {
  1601. struct bnx2x *bp = netdev_priv(dev);
  1602. bp->rx_ticks = (u16)coal->rx_coalesce_usecs;
  1603. if (bp->rx_ticks > BNX2X_MAX_COALESCE_TOUT)
  1604. bp->rx_ticks = BNX2X_MAX_COALESCE_TOUT;
  1605. bp->tx_ticks = (u16)coal->tx_coalesce_usecs;
  1606. if (bp->tx_ticks > BNX2X_MAX_COALESCE_TOUT)
  1607. bp->tx_ticks = BNX2X_MAX_COALESCE_TOUT;
  1608. if (netif_running(dev))
  1609. bnx2x_update_coalesce(bp);
  1610. return 0;
  1611. }
  1612. static void bnx2x_get_ringparam(struct net_device *dev,
  1613. struct ethtool_ringparam *ering)
  1614. {
  1615. struct bnx2x *bp = netdev_priv(dev);
  1616. ering->rx_max_pending = MAX_RX_AVAIL;
  1617. /* If size isn't already set, we give an estimation of the number
  1618. * of buffers we'll have. We're neglecting some possible conditions
  1619. * [we couldn't know for certain at this point if number of queues
  1620. * might shrink] but the number would be correct for the likely
  1621. * scenario.
  1622. */
  1623. if (bp->rx_ring_size)
  1624. ering->rx_pending = bp->rx_ring_size;
  1625. else if (BNX2X_NUM_RX_QUEUES(bp))
  1626. ering->rx_pending = MAX_RX_AVAIL / BNX2X_NUM_RX_QUEUES(bp);
  1627. else
  1628. ering->rx_pending = MAX_RX_AVAIL;
  1629. ering->tx_max_pending = IS_MF_FCOE_AFEX(bp) ? 0 : MAX_TX_AVAIL;
  1630. ering->tx_pending = bp->tx_ring_size;
  1631. }
  1632. static int bnx2x_set_ringparam(struct net_device *dev,
  1633. struct ethtool_ringparam *ering)
  1634. {
  1635. struct bnx2x *bp = netdev_priv(dev);
  1636. DP(BNX2X_MSG_ETHTOOL,
  1637. "set ring params command parameters: rx_pending = %d, tx_pending = %d\n",
  1638. ering->rx_pending, ering->tx_pending);
  1639. if (pci_num_vf(bp->pdev)) {
  1640. DP(BNX2X_MSG_IOV,
  1641. "VFs are enabled, can not change ring parameters\n");
  1642. return -EPERM;
  1643. }
  1644. if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
  1645. DP(BNX2X_MSG_ETHTOOL,
  1646. "Handling parity error recovery. Try again later\n");
  1647. return -EAGAIN;
  1648. }
  1649. if ((ering->rx_pending > MAX_RX_AVAIL) ||
  1650. (ering->rx_pending < (bp->disable_tpa ? MIN_RX_SIZE_NONTPA :
  1651. MIN_RX_SIZE_TPA)) ||
  1652. (ering->tx_pending > (IS_MF_STORAGE_ONLY(bp) ? 0 : MAX_TX_AVAIL)) ||
  1653. (ering->tx_pending <= MAX_SKB_FRAGS + 4)) {
  1654. DP(BNX2X_MSG_ETHTOOL, "Command parameters not supported\n");
  1655. return -EINVAL;
  1656. }
  1657. bp->rx_ring_size = ering->rx_pending;
  1658. bp->tx_ring_size = ering->tx_pending;
  1659. return bnx2x_reload_if_running(dev);
  1660. }
  1661. static void bnx2x_get_pauseparam(struct net_device *dev,
  1662. struct ethtool_pauseparam *epause)
  1663. {
  1664. struct bnx2x *bp = netdev_priv(dev);
  1665. int cfg_idx = bnx2x_get_link_cfg_idx(bp);
  1666. int cfg_reg;
  1667. epause->autoneg = (bp->link_params.req_flow_ctrl[cfg_idx] ==
  1668. BNX2X_FLOW_CTRL_AUTO);
  1669. if (!epause->autoneg)
  1670. cfg_reg = bp->link_params.req_flow_ctrl[cfg_idx];
  1671. else
  1672. cfg_reg = bp->link_params.req_fc_auto_adv;
  1673. epause->rx_pause = ((cfg_reg & BNX2X_FLOW_CTRL_RX) ==
  1674. BNX2X_FLOW_CTRL_RX);
  1675. epause->tx_pause = ((cfg_reg & BNX2X_FLOW_CTRL_TX) ==
  1676. BNX2X_FLOW_CTRL_TX);
  1677. DP(BNX2X_MSG_ETHTOOL, "ethtool_pauseparam: cmd %d\n"
  1678. " autoneg %d rx_pause %d tx_pause %d\n",
  1679. epause->cmd, epause->autoneg, epause->rx_pause, epause->tx_pause);
  1680. }
  1681. static int bnx2x_set_pauseparam(struct net_device *dev,
  1682. struct ethtool_pauseparam *epause)
  1683. {
  1684. struct bnx2x *bp = netdev_priv(dev);
  1685. u32 cfg_idx = bnx2x_get_link_cfg_idx(bp);
  1686. if (IS_MF(bp))
  1687. return 0;
  1688. DP(BNX2X_MSG_ETHTOOL, "ethtool_pauseparam: cmd %d\n"
  1689. " autoneg %d rx_pause %d tx_pause %d\n",
  1690. epause->cmd, epause->autoneg, epause->rx_pause, epause->tx_pause);
  1691. bp->link_params.req_flow_ctrl[cfg_idx] = BNX2X_FLOW_CTRL_AUTO;
  1692. if (epause->rx_pause)
  1693. bp->link_params.req_flow_ctrl[cfg_idx] |= BNX2X_FLOW_CTRL_RX;
  1694. if (epause->tx_pause)
  1695. bp->link_params.req_flow_ctrl[cfg_idx] |= BNX2X_FLOW_CTRL_TX;
  1696. if (bp->link_params.req_flow_ctrl[cfg_idx] == BNX2X_FLOW_CTRL_AUTO)
  1697. bp->link_params.req_flow_ctrl[cfg_idx] = BNX2X_FLOW_CTRL_NONE;
  1698. if (epause->autoneg) {
  1699. if (!(bp->port.supported[cfg_idx] & SUPPORTED_Autoneg)) {
  1700. DP(BNX2X_MSG_ETHTOOL, "autoneg not supported\n");
  1701. return -EINVAL;
  1702. }
  1703. if (bp->link_params.req_line_speed[cfg_idx] == SPEED_AUTO_NEG) {
  1704. bp->link_params.req_flow_ctrl[cfg_idx] =
  1705. BNX2X_FLOW_CTRL_AUTO;
  1706. }
  1707. bp->link_params.req_fc_auto_adv = 0;
  1708. if (epause->rx_pause)
  1709. bp->link_params.req_fc_auto_adv |= BNX2X_FLOW_CTRL_RX;
  1710. if (epause->tx_pause)
  1711. bp->link_params.req_fc_auto_adv |= BNX2X_FLOW_CTRL_TX;
  1712. if (!bp->link_params.req_fc_auto_adv)
  1713. bp->link_params.req_fc_auto_adv |= BNX2X_FLOW_CTRL_NONE;
  1714. }
  1715. DP(BNX2X_MSG_ETHTOOL,
  1716. "req_flow_ctrl 0x%x\n", bp->link_params.req_flow_ctrl[cfg_idx]);
  1717. if (netif_running(dev)) {
  1718. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  1719. bnx2x_force_link_reset(bp);
  1720. bnx2x_link_set(bp);
  1721. }
  1722. return 0;
  1723. }
  1724. static const char bnx2x_tests_str_arr[BNX2X_NUM_TESTS_SF][ETH_GSTRING_LEN] = {
  1725. "register_test (offline) ",
  1726. "memory_test (offline) ",
  1727. "int_loopback_test (offline)",
  1728. "ext_loopback_test (offline)",
  1729. "nvram_test (online) ",
  1730. "interrupt_test (online) ",
  1731. "link_test (online) "
  1732. };
  1733. enum {
  1734. BNX2X_PRI_FLAG_ISCSI,
  1735. BNX2X_PRI_FLAG_FCOE,
  1736. BNX2X_PRI_FLAG_STORAGE,
  1737. BNX2X_PRI_FLAG_LEN,
  1738. };
  1739. static const char bnx2x_private_arr[BNX2X_PRI_FLAG_LEN][ETH_GSTRING_LEN] = {
  1740. "iSCSI offload support",
  1741. "FCoE offload support",
  1742. "Storage only interface"
  1743. };
  1744. static u32 bnx2x_eee_to_adv(u32 eee_adv)
  1745. {
  1746. u32 modes = 0;
  1747. if (eee_adv & SHMEM_EEE_100M_ADV)
  1748. modes |= ADVERTISED_100baseT_Full;
  1749. if (eee_adv & SHMEM_EEE_1G_ADV)
  1750. modes |= ADVERTISED_1000baseT_Full;
  1751. if (eee_adv & SHMEM_EEE_10G_ADV)
  1752. modes |= ADVERTISED_10000baseT_Full;
  1753. return modes;
  1754. }
  1755. static u32 bnx2x_adv_to_eee(u32 modes, u32 shift)
  1756. {
  1757. u32 eee_adv = 0;
  1758. if (modes & ADVERTISED_100baseT_Full)
  1759. eee_adv |= SHMEM_EEE_100M_ADV;
  1760. if (modes & ADVERTISED_1000baseT_Full)
  1761. eee_adv |= SHMEM_EEE_1G_ADV;
  1762. if (modes & ADVERTISED_10000baseT_Full)
  1763. eee_adv |= SHMEM_EEE_10G_ADV;
  1764. return eee_adv << shift;
  1765. }
  1766. static int bnx2x_get_eee(struct net_device *dev, struct ethtool_eee *edata)
  1767. {
  1768. struct bnx2x *bp = netdev_priv(dev);
  1769. u32 eee_cfg;
  1770. if (!SHMEM2_HAS(bp, eee_status[BP_PORT(bp)])) {
  1771. DP(BNX2X_MSG_ETHTOOL, "BC Version does not support EEE\n");
  1772. return -EOPNOTSUPP;
  1773. }
  1774. eee_cfg = bp->link_vars.eee_status;
  1775. edata->supported =
  1776. bnx2x_eee_to_adv((eee_cfg & SHMEM_EEE_SUPPORTED_MASK) >>
  1777. SHMEM_EEE_SUPPORTED_SHIFT);
  1778. edata->advertised =
  1779. bnx2x_eee_to_adv((eee_cfg & SHMEM_EEE_ADV_STATUS_MASK) >>
  1780. SHMEM_EEE_ADV_STATUS_SHIFT);
  1781. edata->lp_advertised =
  1782. bnx2x_eee_to_adv((eee_cfg & SHMEM_EEE_LP_ADV_STATUS_MASK) >>
  1783. SHMEM_EEE_LP_ADV_STATUS_SHIFT);
  1784. /* SHMEM value is in 16u units --> Convert to 1u units. */
  1785. edata->tx_lpi_timer = (eee_cfg & SHMEM_EEE_TIMER_MASK) << 4;
  1786. edata->eee_enabled = (eee_cfg & SHMEM_EEE_REQUESTED_BIT) ? 1 : 0;
  1787. edata->eee_active = (eee_cfg & SHMEM_EEE_ACTIVE_BIT) ? 1 : 0;
  1788. edata->tx_lpi_enabled = (eee_cfg & SHMEM_EEE_LPI_REQUESTED_BIT) ? 1 : 0;
  1789. return 0;
  1790. }
  1791. static int bnx2x_set_eee(struct net_device *dev, struct ethtool_eee *edata)
  1792. {
  1793. struct bnx2x *bp = netdev_priv(dev);
  1794. u32 eee_cfg;
  1795. u32 advertised;
  1796. if (IS_MF(bp))
  1797. return 0;
  1798. if (!SHMEM2_HAS(bp, eee_status[BP_PORT(bp)])) {
  1799. DP(BNX2X_MSG_ETHTOOL, "BC Version does not support EEE\n");
  1800. return -EOPNOTSUPP;
  1801. }
  1802. eee_cfg = bp->link_vars.eee_status;
  1803. if (!(eee_cfg & SHMEM_EEE_SUPPORTED_MASK)) {
  1804. DP(BNX2X_MSG_ETHTOOL, "Board does not support EEE!\n");
  1805. return -EOPNOTSUPP;
  1806. }
  1807. advertised = bnx2x_adv_to_eee(edata->advertised,
  1808. SHMEM_EEE_ADV_STATUS_SHIFT);
  1809. if ((advertised != (eee_cfg & SHMEM_EEE_ADV_STATUS_MASK))) {
  1810. DP(BNX2X_MSG_ETHTOOL,
  1811. "Direct manipulation of EEE advertisement is not supported\n");
  1812. return -EINVAL;
  1813. }
  1814. if (edata->tx_lpi_timer > EEE_MODE_TIMER_MASK) {
  1815. DP(BNX2X_MSG_ETHTOOL,
  1816. "Maximal Tx Lpi timer supported is %x(u)\n",
  1817. EEE_MODE_TIMER_MASK);
  1818. return -EINVAL;
  1819. }
  1820. if (edata->tx_lpi_enabled &&
  1821. (edata->tx_lpi_timer < EEE_MODE_NVRAM_AGGRESSIVE_TIME)) {
  1822. DP(BNX2X_MSG_ETHTOOL,
  1823. "Minimal Tx Lpi timer supported is %d(u)\n",
  1824. EEE_MODE_NVRAM_AGGRESSIVE_TIME);
  1825. return -EINVAL;
  1826. }
  1827. /* All is well; Apply changes*/
  1828. if (edata->eee_enabled)
  1829. bp->link_params.eee_mode |= EEE_MODE_ADV_LPI;
  1830. else
  1831. bp->link_params.eee_mode &= ~EEE_MODE_ADV_LPI;
  1832. if (edata->tx_lpi_enabled)
  1833. bp->link_params.eee_mode |= EEE_MODE_ENABLE_LPI;
  1834. else
  1835. bp->link_params.eee_mode &= ~EEE_MODE_ENABLE_LPI;
  1836. bp->link_params.eee_mode &= ~EEE_MODE_TIMER_MASK;
  1837. bp->link_params.eee_mode |= (edata->tx_lpi_timer &
  1838. EEE_MODE_TIMER_MASK) |
  1839. EEE_MODE_OVERRIDE_NVRAM |
  1840. EEE_MODE_OUTPUT_TIME;
  1841. /* Restart link to propagate changes */
  1842. if (netif_running(dev)) {
  1843. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  1844. bnx2x_force_link_reset(bp);
  1845. bnx2x_link_set(bp);
  1846. }
  1847. return 0;
  1848. }
  1849. enum {
  1850. BNX2X_CHIP_E1_OFST = 0,
  1851. BNX2X_CHIP_E1H_OFST,
  1852. BNX2X_CHIP_E2_OFST,
  1853. BNX2X_CHIP_E3_OFST,
  1854. BNX2X_CHIP_E3B0_OFST,
  1855. BNX2X_CHIP_MAX_OFST
  1856. };
  1857. #define BNX2X_CHIP_MASK_E1 (1 << BNX2X_CHIP_E1_OFST)
  1858. #define BNX2X_CHIP_MASK_E1H (1 << BNX2X_CHIP_E1H_OFST)
  1859. #define BNX2X_CHIP_MASK_E2 (1 << BNX2X_CHIP_E2_OFST)
  1860. #define BNX2X_CHIP_MASK_E3 (1 << BNX2X_CHIP_E3_OFST)
  1861. #define BNX2X_CHIP_MASK_E3B0 (1 << BNX2X_CHIP_E3B0_OFST)
  1862. #define BNX2X_CHIP_MASK_ALL ((1 << BNX2X_CHIP_MAX_OFST) - 1)
  1863. #define BNX2X_CHIP_MASK_E1X (BNX2X_CHIP_MASK_E1 | BNX2X_CHIP_MASK_E1H)
  1864. static int bnx2x_test_registers(struct bnx2x *bp)
  1865. {
  1866. int idx, i, rc = -ENODEV;
  1867. u32 wr_val = 0, hw;
  1868. int port = BP_PORT(bp);
  1869. static const struct {
  1870. u32 hw;
  1871. u32 offset0;
  1872. u32 offset1;
  1873. u32 mask;
  1874. } reg_tbl[] = {
  1875. /* 0 */ { BNX2X_CHIP_MASK_ALL,
  1876. BRB1_REG_PAUSE_LOW_THRESHOLD_0, 4, 0x000003ff },
  1877. { BNX2X_CHIP_MASK_ALL,
  1878. DORQ_REG_DB_ADDR0, 4, 0xffffffff },
  1879. { BNX2X_CHIP_MASK_E1X,
  1880. HC_REG_AGG_INT_0, 4, 0x000003ff },
  1881. { BNX2X_CHIP_MASK_ALL,
  1882. PBF_REG_MAC_IF0_ENABLE, 4, 0x00000001 },
  1883. { BNX2X_CHIP_MASK_E1X | BNX2X_CHIP_MASK_E2 | BNX2X_CHIP_MASK_E3,
  1884. PBF_REG_P0_INIT_CRD, 4, 0x000007ff },
  1885. { BNX2X_CHIP_MASK_E3B0,
  1886. PBF_REG_INIT_CRD_Q0, 4, 0x000007ff },
  1887. { BNX2X_CHIP_MASK_ALL,
  1888. PRS_REG_CID_PORT_0, 4, 0x00ffffff },
  1889. { BNX2X_CHIP_MASK_ALL,
  1890. PXP2_REG_PSWRQ_CDU0_L2P, 4, 0x000fffff },
  1891. { BNX2X_CHIP_MASK_ALL,
  1892. PXP2_REG_RQ_CDU0_EFIRST_MEM_ADDR, 8, 0x0003ffff },
  1893. { BNX2X_CHIP_MASK_ALL,
  1894. PXP2_REG_PSWRQ_TM0_L2P, 4, 0x000fffff },
  1895. /* 10 */ { BNX2X_CHIP_MASK_ALL,
  1896. PXP2_REG_RQ_USDM0_EFIRST_MEM_ADDR, 8, 0x0003ffff },
  1897. { BNX2X_CHIP_MASK_ALL,
  1898. PXP2_REG_PSWRQ_TSDM0_L2P, 4, 0x000fffff },
  1899. { BNX2X_CHIP_MASK_ALL,
  1900. QM_REG_CONNNUM_0, 4, 0x000fffff },
  1901. { BNX2X_CHIP_MASK_ALL,
  1902. TM_REG_LIN0_MAX_ACTIVE_CID, 4, 0x0003ffff },
  1903. { BNX2X_CHIP_MASK_ALL,
  1904. SRC_REG_KEYRSS0_0, 40, 0xffffffff },
  1905. { BNX2X_CHIP_MASK_ALL,
  1906. SRC_REG_KEYRSS0_7, 40, 0xffffffff },
  1907. { BNX2X_CHIP_MASK_ALL,
  1908. XCM_REG_WU_DA_SET_TMR_CNT_FLG_CMD00, 4, 0x00000001 },
  1909. { BNX2X_CHIP_MASK_ALL,
  1910. XCM_REG_WU_DA_CNT_CMD00, 4, 0x00000003 },
  1911. { BNX2X_CHIP_MASK_ALL,
  1912. XCM_REG_GLB_DEL_ACK_MAX_CNT_0, 4, 0x000000ff },
  1913. { BNX2X_CHIP_MASK_ALL,
  1914. NIG_REG_LLH0_T_BIT, 4, 0x00000001 },
  1915. /* 20 */ { BNX2X_CHIP_MASK_E1X | BNX2X_CHIP_MASK_E2,
  1916. NIG_REG_EMAC0_IN_EN, 4, 0x00000001 },
  1917. { BNX2X_CHIP_MASK_E1X | BNX2X_CHIP_MASK_E2,
  1918. NIG_REG_BMAC0_IN_EN, 4, 0x00000001 },
  1919. { BNX2X_CHIP_MASK_ALL,
  1920. NIG_REG_XCM0_OUT_EN, 4, 0x00000001 },
  1921. { BNX2X_CHIP_MASK_ALL,
  1922. NIG_REG_BRB0_OUT_EN, 4, 0x00000001 },
  1923. { BNX2X_CHIP_MASK_ALL,
  1924. NIG_REG_LLH0_XCM_MASK, 4, 0x00000007 },
  1925. { BNX2X_CHIP_MASK_ALL,
  1926. NIG_REG_LLH0_ACPI_PAT_6_LEN, 68, 0x000000ff },
  1927. { BNX2X_CHIP_MASK_ALL,
  1928. NIG_REG_LLH0_ACPI_PAT_0_CRC, 68, 0xffffffff },
  1929. { BNX2X_CHIP_MASK_ALL,
  1930. NIG_REG_LLH0_DEST_MAC_0_0, 160, 0xffffffff },
  1931. { BNX2X_CHIP_MASK_ALL,
  1932. NIG_REG_LLH0_DEST_IP_0_1, 160, 0xffffffff },
  1933. { BNX2X_CHIP_MASK_ALL,
  1934. NIG_REG_LLH0_IPV4_IPV6_0, 160, 0x00000001 },
  1935. /* 30 */ { BNX2X_CHIP_MASK_ALL,
  1936. NIG_REG_LLH0_DEST_UDP_0, 160, 0x0000ffff },
  1937. { BNX2X_CHIP_MASK_ALL,
  1938. NIG_REG_LLH0_DEST_TCP_0, 160, 0x0000ffff },
  1939. { BNX2X_CHIP_MASK_ALL,
  1940. NIG_REG_LLH0_VLAN_ID_0, 160, 0x00000fff },
  1941. { BNX2X_CHIP_MASK_E1X | BNX2X_CHIP_MASK_E2,
  1942. NIG_REG_XGXS_SERDES0_MODE_SEL, 4, 0x00000001 },
  1943. { BNX2X_CHIP_MASK_ALL,
  1944. NIG_REG_LED_CONTROL_OVERRIDE_TRAFFIC_P0, 4, 0x00000001},
  1945. { BNX2X_CHIP_MASK_ALL,
  1946. NIG_REG_STATUS_INTERRUPT_PORT0, 4, 0x07ffffff },
  1947. { BNX2X_CHIP_MASK_E1X | BNX2X_CHIP_MASK_E2,
  1948. NIG_REG_XGXS0_CTRL_EXTREMOTEMDIOST, 24, 0x00000001 },
  1949. { BNX2X_CHIP_MASK_E1X | BNX2X_CHIP_MASK_E2,
  1950. NIG_REG_SERDES0_CTRL_PHY_ADDR, 16, 0x0000001f },
  1951. { BNX2X_CHIP_MASK_ALL, 0xffffffff, 0, 0x00000000 }
  1952. };
  1953. if (!bnx2x_is_nvm_accessible(bp)) {
  1954. DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
  1955. "cannot access eeprom when the interface is down\n");
  1956. return rc;
  1957. }
  1958. if (CHIP_IS_E1(bp))
  1959. hw = BNX2X_CHIP_MASK_E1;
  1960. else if (CHIP_IS_E1H(bp))
  1961. hw = BNX2X_CHIP_MASK_E1H;
  1962. else if (CHIP_IS_E2(bp))
  1963. hw = BNX2X_CHIP_MASK_E2;
  1964. else if (CHIP_IS_E3B0(bp))
  1965. hw = BNX2X_CHIP_MASK_E3B0;
  1966. else /* e3 A0 */
  1967. hw = BNX2X_CHIP_MASK_E3;
  1968. /* Repeat the test twice:
  1969. * First by writing 0x00000000, second by writing 0xffffffff
  1970. */
  1971. for (idx = 0; idx < 2; idx++) {
  1972. switch (idx) {
  1973. case 0:
  1974. wr_val = 0;
  1975. break;
  1976. case 1:
  1977. wr_val = 0xffffffff;
  1978. break;
  1979. }
  1980. for (i = 0; reg_tbl[i].offset0 != 0xffffffff; i++) {
  1981. u32 offset, mask, save_val, val;
  1982. if (!(hw & reg_tbl[i].hw))
  1983. continue;
  1984. offset = reg_tbl[i].offset0 + port*reg_tbl[i].offset1;
  1985. mask = reg_tbl[i].mask;
  1986. save_val = REG_RD(bp, offset);
  1987. REG_WR(bp, offset, wr_val & mask);
  1988. val = REG_RD(bp, offset);
  1989. /* Restore the original register's value */
  1990. REG_WR(bp, offset, save_val);
  1991. /* verify value is as expected */
  1992. if ((val & mask) != (wr_val & mask)) {
  1993. DP(BNX2X_MSG_ETHTOOL,
  1994. "offset 0x%x: val 0x%x != 0x%x mask 0x%x\n",
  1995. offset, val, wr_val, mask);
  1996. goto test_reg_exit;
  1997. }
  1998. }
  1999. }
  2000. rc = 0;
  2001. test_reg_exit:
  2002. return rc;
  2003. }
  2004. static int bnx2x_test_memory(struct bnx2x *bp)
  2005. {
  2006. int i, j, rc = -ENODEV;
  2007. u32 val, index;
  2008. static const struct {
  2009. u32 offset;
  2010. int size;
  2011. } mem_tbl[] = {
  2012. { CCM_REG_XX_DESCR_TABLE, CCM_REG_XX_DESCR_TABLE_SIZE },
  2013. { CFC_REG_ACTIVITY_COUNTER, CFC_REG_ACTIVITY_COUNTER_SIZE },
  2014. { CFC_REG_LINK_LIST, CFC_REG_LINK_LIST_SIZE },
  2015. { DMAE_REG_CMD_MEM, DMAE_REG_CMD_MEM_SIZE },
  2016. { TCM_REG_XX_DESCR_TABLE, TCM_REG_XX_DESCR_TABLE_SIZE },
  2017. { UCM_REG_XX_DESCR_TABLE, UCM_REG_XX_DESCR_TABLE_SIZE },
  2018. { XCM_REG_XX_DESCR_TABLE, XCM_REG_XX_DESCR_TABLE_SIZE },
  2019. { 0xffffffff, 0 }
  2020. };
  2021. static const struct {
  2022. char *name;
  2023. u32 offset;
  2024. u32 hw_mask[BNX2X_CHIP_MAX_OFST];
  2025. } prty_tbl[] = {
  2026. { "CCM_PRTY_STS", CCM_REG_CCM_PRTY_STS,
  2027. {0x3ffc0, 0, 0, 0} },
  2028. { "CFC_PRTY_STS", CFC_REG_CFC_PRTY_STS,
  2029. {0x2, 0x2, 0, 0} },
  2030. { "DMAE_PRTY_STS", DMAE_REG_DMAE_PRTY_STS,
  2031. {0, 0, 0, 0} },
  2032. { "TCM_PRTY_STS", TCM_REG_TCM_PRTY_STS,
  2033. {0x3ffc0, 0, 0, 0} },
  2034. { "UCM_PRTY_STS", UCM_REG_UCM_PRTY_STS,
  2035. {0x3ffc0, 0, 0, 0} },
  2036. { "XCM_PRTY_STS", XCM_REG_XCM_PRTY_STS,
  2037. {0x3ffc1, 0, 0, 0} },
  2038. { NULL, 0xffffffff, {0, 0, 0, 0} }
  2039. };
  2040. if (!bnx2x_is_nvm_accessible(bp)) {
  2041. DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
  2042. "cannot access eeprom when the interface is down\n");
  2043. return rc;
  2044. }
  2045. if (CHIP_IS_E1(bp))
  2046. index = BNX2X_CHIP_E1_OFST;
  2047. else if (CHIP_IS_E1H(bp))
  2048. index = BNX2X_CHIP_E1H_OFST;
  2049. else if (CHIP_IS_E2(bp))
  2050. index = BNX2X_CHIP_E2_OFST;
  2051. else /* e3 */
  2052. index = BNX2X_CHIP_E3_OFST;
  2053. /* pre-Check the parity status */
  2054. for (i = 0; prty_tbl[i].offset != 0xffffffff; i++) {
  2055. val = REG_RD(bp, prty_tbl[i].offset);
  2056. if (val & ~(prty_tbl[i].hw_mask[index])) {
  2057. DP(BNX2X_MSG_ETHTOOL,
  2058. "%s is 0x%x\n", prty_tbl[i].name, val);
  2059. goto test_mem_exit;
  2060. }
  2061. }
  2062. /* Go through all the memories */
  2063. for (i = 0; mem_tbl[i].offset != 0xffffffff; i++)
  2064. for (j = 0; j < mem_tbl[i].size; j++)
  2065. REG_RD(bp, mem_tbl[i].offset + j*4);
  2066. /* Check the parity status */
  2067. for (i = 0; prty_tbl[i].offset != 0xffffffff; i++) {
  2068. val = REG_RD(bp, prty_tbl[i].offset);
  2069. if (val & ~(prty_tbl[i].hw_mask[index])) {
  2070. DP(BNX2X_MSG_ETHTOOL,
  2071. "%s is 0x%x\n", prty_tbl[i].name, val);
  2072. goto test_mem_exit;
  2073. }
  2074. }
  2075. rc = 0;
  2076. test_mem_exit:
  2077. return rc;
  2078. }
  2079. static void bnx2x_wait_for_link(struct bnx2x *bp, u8 link_up, u8 is_serdes)
  2080. {
  2081. int cnt = 1400;
  2082. if (link_up) {
  2083. while (bnx2x_link_test(bp, is_serdes) && cnt--)
  2084. msleep(20);
  2085. if (cnt <= 0 && bnx2x_link_test(bp, is_serdes))
  2086. DP(BNX2X_MSG_ETHTOOL, "Timeout waiting for link up\n");
  2087. cnt = 1400;
  2088. while (!bp->link_vars.link_up && cnt--)
  2089. msleep(20);
  2090. if (cnt <= 0 && !bp->link_vars.link_up)
  2091. DP(BNX2X_MSG_ETHTOOL,
  2092. "Timeout waiting for link init\n");
  2093. }
  2094. }
  2095. static int bnx2x_run_loopback(struct bnx2x *bp, int loopback_mode)
  2096. {
  2097. unsigned int pkt_size, num_pkts, i;
  2098. struct sk_buff *skb;
  2099. unsigned char *packet;
  2100. struct bnx2x_fastpath *fp_rx = &bp->fp[0];
  2101. struct bnx2x_fastpath *fp_tx = &bp->fp[0];
  2102. struct bnx2x_fp_txdata *txdata = fp_tx->txdata_ptr[0];
  2103. u16 tx_start_idx, tx_idx;
  2104. u16 rx_start_idx, rx_idx;
  2105. u16 pkt_prod, bd_prod;
  2106. struct sw_tx_bd *tx_buf;
  2107. struct eth_tx_start_bd *tx_start_bd;
  2108. dma_addr_t mapping;
  2109. union eth_rx_cqe *cqe;
  2110. u8 cqe_fp_flags, cqe_fp_type;
  2111. struct sw_rx_bd *rx_buf;
  2112. u16 len;
  2113. int rc = -ENODEV;
  2114. u8 *data;
  2115. struct netdev_queue *txq = netdev_get_tx_queue(bp->dev,
  2116. txdata->txq_index);
  2117. /* check the loopback mode */
  2118. switch (loopback_mode) {
  2119. case BNX2X_PHY_LOOPBACK:
  2120. if (bp->link_params.loopback_mode != LOOPBACK_XGXS) {
  2121. DP(BNX2X_MSG_ETHTOOL, "PHY loopback not supported\n");
  2122. return -EINVAL;
  2123. }
  2124. break;
  2125. case BNX2X_MAC_LOOPBACK:
  2126. if (CHIP_IS_E3(bp)) {
  2127. int cfg_idx = bnx2x_get_link_cfg_idx(bp);
  2128. if (bp->port.supported[cfg_idx] &
  2129. (SUPPORTED_10000baseT_Full |
  2130. SUPPORTED_20000baseMLD2_Full |
  2131. SUPPORTED_20000baseKR2_Full))
  2132. bp->link_params.loopback_mode = LOOPBACK_XMAC;
  2133. else
  2134. bp->link_params.loopback_mode = LOOPBACK_UMAC;
  2135. } else
  2136. bp->link_params.loopback_mode = LOOPBACK_BMAC;
  2137. bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  2138. break;
  2139. case BNX2X_EXT_LOOPBACK:
  2140. if (bp->link_params.loopback_mode != LOOPBACK_EXT) {
  2141. DP(BNX2X_MSG_ETHTOOL,
  2142. "Can't configure external loopback\n");
  2143. return -EINVAL;
  2144. }
  2145. break;
  2146. default:
  2147. DP(BNX2X_MSG_ETHTOOL, "Command parameters not supported\n");
  2148. return -EINVAL;
  2149. }
  2150. /* prepare the loopback packet */
  2151. pkt_size = (((bp->dev->mtu < ETH_MAX_PACKET_SIZE) ?
  2152. bp->dev->mtu : ETH_MAX_PACKET_SIZE) + ETH_HLEN);
  2153. skb = netdev_alloc_skb(bp->dev, fp_rx->rx_buf_size);
  2154. if (!skb) {
  2155. DP(BNX2X_MSG_ETHTOOL, "Can't allocate skb\n");
  2156. rc = -ENOMEM;
  2157. goto test_loopback_exit;
  2158. }
  2159. packet = skb_put(skb, pkt_size);
  2160. memcpy(packet, bp->dev->dev_addr, ETH_ALEN);
  2161. eth_zero_addr(packet + ETH_ALEN);
  2162. memset(packet + 2*ETH_ALEN, 0x77, (ETH_HLEN - 2*ETH_ALEN));
  2163. for (i = ETH_HLEN; i < pkt_size; i++)
  2164. packet[i] = (unsigned char) (i & 0xff);
  2165. mapping = dma_map_single(&bp->pdev->dev, skb->data,
  2166. skb_headlen(skb), DMA_TO_DEVICE);
  2167. if (unlikely(dma_mapping_error(&bp->pdev->dev, mapping))) {
  2168. rc = -ENOMEM;
  2169. dev_kfree_skb(skb);
  2170. DP(BNX2X_MSG_ETHTOOL, "Unable to map SKB\n");
  2171. goto test_loopback_exit;
  2172. }
  2173. /* send the loopback packet */
  2174. num_pkts = 0;
  2175. tx_start_idx = le16_to_cpu(*txdata->tx_cons_sb);
  2176. rx_start_idx = le16_to_cpu(*fp_rx->rx_cons_sb);
  2177. netdev_tx_sent_queue(txq, skb->len);
  2178. pkt_prod = txdata->tx_pkt_prod++;
  2179. tx_buf = &txdata->tx_buf_ring[TX_BD(pkt_prod)];
  2180. tx_buf->first_bd = txdata->tx_bd_prod;
  2181. tx_buf->skb = skb;
  2182. tx_buf->flags = 0;
  2183. bd_prod = TX_BD(txdata->tx_bd_prod);
  2184. tx_start_bd = &txdata->tx_desc_ring[bd_prod].start_bd;
  2185. tx_start_bd->addr_hi = cpu_to_le32(U64_HI(mapping));
  2186. tx_start_bd->addr_lo = cpu_to_le32(U64_LO(mapping));
  2187. tx_start_bd->nbd = cpu_to_le16(2); /* start + pbd */
  2188. tx_start_bd->nbytes = cpu_to_le16(skb_headlen(skb));
  2189. tx_start_bd->vlan_or_ethertype = cpu_to_le16(pkt_prod);
  2190. tx_start_bd->bd_flags.as_bitfield = ETH_TX_BD_FLAGS_START_BD;
  2191. SET_FLAG(tx_start_bd->general_data,
  2192. ETH_TX_START_BD_HDR_NBDS,
  2193. 1);
  2194. SET_FLAG(tx_start_bd->general_data,
  2195. ETH_TX_START_BD_PARSE_NBDS,
  2196. 0);
  2197. /* turn on parsing and get a BD */
  2198. bd_prod = TX_BD(NEXT_TX_IDX(bd_prod));
  2199. if (CHIP_IS_E1x(bp)) {
  2200. u16 global_data = 0;
  2201. struct eth_tx_parse_bd_e1x *pbd_e1x =
  2202. &txdata->tx_desc_ring[bd_prod].parse_bd_e1x;
  2203. memset(pbd_e1x, 0, sizeof(struct eth_tx_parse_bd_e1x));
  2204. SET_FLAG(global_data,
  2205. ETH_TX_PARSE_BD_E1X_ETH_ADDR_TYPE, UNICAST_ADDRESS);
  2206. pbd_e1x->global_data = cpu_to_le16(global_data);
  2207. } else {
  2208. u32 parsing_data = 0;
  2209. struct eth_tx_parse_bd_e2 *pbd_e2 =
  2210. &txdata->tx_desc_ring[bd_prod].parse_bd_e2;
  2211. memset(pbd_e2, 0, sizeof(struct eth_tx_parse_bd_e2));
  2212. SET_FLAG(parsing_data,
  2213. ETH_TX_PARSE_BD_E2_ETH_ADDR_TYPE, UNICAST_ADDRESS);
  2214. pbd_e2->parsing_data = cpu_to_le32(parsing_data);
  2215. }
  2216. wmb();
  2217. txdata->tx_db.data.prod += 2;
  2218. /* make sure descriptor update is observed by the HW */
  2219. wmb();
  2220. DOORBELL_RELAXED(bp, txdata->cid, txdata->tx_db.raw);
  2221. mmiowb();
  2222. barrier();
  2223. num_pkts++;
  2224. txdata->tx_bd_prod += 2; /* start + pbd */
  2225. udelay(100);
  2226. tx_idx = le16_to_cpu(*txdata->tx_cons_sb);
  2227. if (tx_idx != tx_start_idx + num_pkts)
  2228. goto test_loopback_exit;
  2229. /* Unlike HC IGU won't generate an interrupt for status block
  2230. * updates that have been performed while interrupts were
  2231. * disabled.
  2232. */
  2233. if (bp->common.int_block == INT_BLOCK_IGU) {
  2234. /* Disable local BHes to prevent a dead-lock situation between
  2235. * sch_direct_xmit() and bnx2x_run_loopback() (calling
  2236. * bnx2x_tx_int()), as both are taking netif_tx_lock().
  2237. */
  2238. local_bh_disable();
  2239. bnx2x_tx_int(bp, txdata);
  2240. local_bh_enable();
  2241. }
  2242. rx_idx = le16_to_cpu(*fp_rx->rx_cons_sb);
  2243. if (rx_idx != rx_start_idx + num_pkts)
  2244. goto test_loopback_exit;
  2245. cqe = &fp_rx->rx_comp_ring[RCQ_BD(fp_rx->rx_comp_cons)];
  2246. cqe_fp_flags = cqe->fast_path_cqe.type_error_flags;
  2247. cqe_fp_type = cqe_fp_flags & ETH_FAST_PATH_RX_CQE_TYPE;
  2248. if (!CQE_TYPE_FAST(cqe_fp_type) || (cqe_fp_flags & ETH_RX_ERROR_FALGS))
  2249. goto test_loopback_rx_exit;
  2250. len = le16_to_cpu(cqe->fast_path_cqe.pkt_len_or_gro_seg_len);
  2251. if (len != pkt_size)
  2252. goto test_loopback_rx_exit;
  2253. rx_buf = &fp_rx->rx_buf_ring[RX_BD(fp_rx->rx_bd_cons)];
  2254. dma_sync_single_for_cpu(&bp->pdev->dev,
  2255. dma_unmap_addr(rx_buf, mapping),
  2256. fp_rx->rx_buf_size, DMA_FROM_DEVICE);
  2257. data = rx_buf->data + NET_SKB_PAD + cqe->fast_path_cqe.placement_offset;
  2258. for (i = ETH_HLEN; i < pkt_size; i++)
  2259. if (*(data + i) != (unsigned char) (i & 0xff))
  2260. goto test_loopback_rx_exit;
  2261. rc = 0;
  2262. test_loopback_rx_exit:
  2263. fp_rx->rx_bd_cons = NEXT_RX_IDX(fp_rx->rx_bd_cons);
  2264. fp_rx->rx_bd_prod = NEXT_RX_IDX(fp_rx->rx_bd_prod);
  2265. fp_rx->rx_comp_cons = NEXT_RCQ_IDX(fp_rx->rx_comp_cons);
  2266. fp_rx->rx_comp_prod = NEXT_RCQ_IDX(fp_rx->rx_comp_prod);
  2267. /* Update producers */
  2268. bnx2x_update_rx_prod(bp, fp_rx, fp_rx->rx_bd_prod, fp_rx->rx_comp_prod,
  2269. fp_rx->rx_sge_prod);
  2270. test_loopback_exit:
  2271. bp->link_params.loopback_mode = LOOPBACK_NONE;
  2272. return rc;
  2273. }
  2274. static int bnx2x_test_loopback(struct bnx2x *bp)
  2275. {
  2276. int rc = 0, res;
  2277. if (BP_NOMCP(bp))
  2278. return rc;
  2279. if (!netif_running(bp->dev))
  2280. return BNX2X_LOOPBACK_FAILED;
  2281. bnx2x_netif_stop(bp, 1);
  2282. bnx2x_acquire_phy_lock(bp);
  2283. res = bnx2x_run_loopback(bp, BNX2X_PHY_LOOPBACK);
  2284. if (res) {
  2285. DP(BNX2X_MSG_ETHTOOL, " PHY loopback failed (res %d)\n", res);
  2286. rc |= BNX2X_PHY_LOOPBACK_FAILED;
  2287. }
  2288. res = bnx2x_run_loopback(bp, BNX2X_MAC_LOOPBACK);
  2289. if (res) {
  2290. DP(BNX2X_MSG_ETHTOOL, " MAC loopback failed (res %d)\n", res);
  2291. rc |= BNX2X_MAC_LOOPBACK_FAILED;
  2292. }
  2293. bnx2x_release_phy_lock(bp);
  2294. bnx2x_netif_start(bp);
  2295. return rc;
  2296. }
  2297. static int bnx2x_test_ext_loopback(struct bnx2x *bp)
  2298. {
  2299. int rc;
  2300. u8 is_serdes =
  2301. (bp->link_vars.link_status & LINK_STATUS_SERDES_LINK) > 0;
  2302. if (BP_NOMCP(bp))
  2303. return -ENODEV;
  2304. if (!netif_running(bp->dev))
  2305. return BNX2X_EXT_LOOPBACK_FAILED;
  2306. bnx2x_nic_unload(bp, UNLOAD_NORMAL, false);
  2307. rc = bnx2x_nic_load(bp, LOAD_LOOPBACK_EXT);
  2308. if (rc) {
  2309. DP(BNX2X_MSG_ETHTOOL,
  2310. "Can't perform self-test, nic_load (for external lb) failed\n");
  2311. return -ENODEV;
  2312. }
  2313. bnx2x_wait_for_link(bp, 1, is_serdes);
  2314. bnx2x_netif_stop(bp, 1);
  2315. rc = bnx2x_run_loopback(bp, BNX2X_EXT_LOOPBACK);
  2316. if (rc)
  2317. DP(BNX2X_MSG_ETHTOOL, "EXT loopback failed (res %d)\n", rc);
  2318. bnx2x_netif_start(bp);
  2319. return rc;
  2320. }
  2321. struct code_entry {
  2322. u32 sram_start_addr;
  2323. u32 code_attribute;
  2324. #define CODE_IMAGE_TYPE_MASK 0xf0800003
  2325. #define CODE_IMAGE_VNTAG_PROFILES_DATA 0xd0000003
  2326. #define CODE_IMAGE_LENGTH_MASK 0x007ffffc
  2327. #define CODE_IMAGE_TYPE_EXTENDED_DIR 0xe0000000
  2328. u32 nvm_start_addr;
  2329. };
  2330. #define CODE_ENTRY_MAX 16
  2331. #define CODE_ENTRY_EXTENDED_DIR_IDX 15
  2332. #define MAX_IMAGES_IN_EXTENDED_DIR 64
  2333. #define NVRAM_DIR_OFFSET 0x14
  2334. #define EXTENDED_DIR_EXISTS(code) \
  2335. ((code & CODE_IMAGE_TYPE_MASK) == CODE_IMAGE_TYPE_EXTENDED_DIR && \
  2336. (code & CODE_IMAGE_LENGTH_MASK) != 0)
  2337. #define CRC32_RESIDUAL 0xdebb20e3
  2338. #define CRC_BUFF_SIZE 256
  2339. static int bnx2x_nvram_crc(struct bnx2x *bp,
  2340. int offset,
  2341. int size,
  2342. u8 *buff)
  2343. {
  2344. u32 crc = ~0;
  2345. int rc = 0, done = 0;
  2346. DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
  2347. "NVRAM CRC from 0x%08x to 0x%08x\n", offset, offset + size);
  2348. while (done < size) {
  2349. int count = min_t(int, size - done, CRC_BUFF_SIZE);
  2350. rc = bnx2x_nvram_read(bp, offset + done, buff, count);
  2351. if (rc)
  2352. return rc;
  2353. crc = crc32_le(crc, buff, count);
  2354. done += count;
  2355. }
  2356. if (crc != CRC32_RESIDUAL)
  2357. rc = -EINVAL;
  2358. return rc;
  2359. }
  2360. static int bnx2x_test_nvram_dir(struct bnx2x *bp,
  2361. struct code_entry *entry,
  2362. u8 *buff)
  2363. {
  2364. size_t size = entry->code_attribute & CODE_IMAGE_LENGTH_MASK;
  2365. u32 type = entry->code_attribute & CODE_IMAGE_TYPE_MASK;
  2366. int rc;
  2367. /* Zero-length images and AFEX profiles do not have CRC */
  2368. if (size == 0 || type == CODE_IMAGE_VNTAG_PROFILES_DATA)
  2369. return 0;
  2370. rc = bnx2x_nvram_crc(bp, entry->nvm_start_addr, size, buff);
  2371. if (rc)
  2372. DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
  2373. "image %x has failed crc test (rc %d)\n", type, rc);
  2374. return rc;
  2375. }
  2376. static int bnx2x_test_dir_entry(struct bnx2x *bp, u32 addr, u8 *buff)
  2377. {
  2378. int rc;
  2379. struct code_entry entry;
  2380. rc = bnx2x_nvram_read32(bp, addr, (u32 *)&entry, sizeof(entry));
  2381. if (rc)
  2382. return rc;
  2383. return bnx2x_test_nvram_dir(bp, &entry, buff);
  2384. }
  2385. static int bnx2x_test_nvram_ext_dirs(struct bnx2x *bp, u8 *buff)
  2386. {
  2387. u32 rc, cnt, dir_offset = NVRAM_DIR_OFFSET;
  2388. struct code_entry entry;
  2389. int i;
  2390. rc = bnx2x_nvram_read32(bp,
  2391. dir_offset +
  2392. sizeof(entry) * CODE_ENTRY_EXTENDED_DIR_IDX,
  2393. (u32 *)&entry, sizeof(entry));
  2394. if (rc)
  2395. return rc;
  2396. if (!EXTENDED_DIR_EXISTS(entry.code_attribute))
  2397. return 0;
  2398. rc = bnx2x_nvram_read32(bp, entry.nvm_start_addr,
  2399. &cnt, sizeof(u32));
  2400. if (rc)
  2401. return rc;
  2402. dir_offset = entry.nvm_start_addr + 8;
  2403. for (i = 0; i < cnt && i < MAX_IMAGES_IN_EXTENDED_DIR; i++) {
  2404. rc = bnx2x_test_dir_entry(bp, dir_offset +
  2405. sizeof(struct code_entry) * i,
  2406. buff);
  2407. if (rc)
  2408. return rc;
  2409. }
  2410. return 0;
  2411. }
  2412. static int bnx2x_test_nvram_dirs(struct bnx2x *bp, u8 *buff)
  2413. {
  2414. u32 rc, dir_offset = NVRAM_DIR_OFFSET;
  2415. int i;
  2416. DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM, "NVRAM DIRS CRC test-set\n");
  2417. for (i = 0; i < CODE_ENTRY_EXTENDED_DIR_IDX; i++) {
  2418. rc = bnx2x_test_dir_entry(bp, dir_offset +
  2419. sizeof(struct code_entry) * i,
  2420. buff);
  2421. if (rc)
  2422. return rc;
  2423. }
  2424. return bnx2x_test_nvram_ext_dirs(bp, buff);
  2425. }
  2426. struct crc_pair {
  2427. int offset;
  2428. int size;
  2429. };
  2430. static int bnx2x_test_nvram_tbl(struct bnx2x *bp,
  2431. const struct crc_pair *nvram_tbl, u8 *buf)
  2432. {
  2433. int i;
  2434. for (i = 0; nvram_tbl[i].size; i++) {
  2435. int rc = bnx2x_nvram_crc(bp, nvram_tbl[i].offset,
  2436. nvram_tbl[i].size, buf);
  2437. if (rc) {
  2438. DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
  2439. "nvram_tbl[%d] has failed crc test (rc %d)\n",
  2440. i, rc);
  2441. return rc;
  2442. }
  2443. }
  2444. return 0;
  2445. }
  2446. static int bnx2x_test_nvram(struct bnx2x *bp)
  2447. {
  2448. static const struct crc_pair nvram_tbl[] = {
  2449. { 0, 0x14 }, /* bootstrap */
  2450. { 0x14, 0xec }, /* dir */
  2451. { 0x100, 0x350 }, /* manuf_info */
  2452. { 0x450, 0xf0 }, /* feature_info */
  2453. { 0x640, 0x64 }, /* upgrade_key_info */
  2454. { 0x708, 0x70 }, /* manuf_key_info */
  2455. { 0, 0 }
  2456. };
  2457. static const struct crc_pair nvram_tbl2[] = {
  2458. { 0x7e8, 0x350 }, /* manuf_info2 */
  2459. { 0xb38, 0xf0 }, /* feature_info */
  2460. { 0, 0 }
  2461. };
  2462. u8 *buf;
  2463. int rc;
  2464. u32 magic;
  2465. if (BP_NOMCP(bp))
  2466. return 0;
  2467. buf = kmalloc(CRC_BUFF_SIZE, GFP_KERNEL);
  2468. if (!buf) {
  2469. DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM, "kmalloc failed\n");
  2470. rc = -ENOMEM;
  2471. goto test_nvram_exit;
  2472. }
  2473. rc = bnx2x_nvram_read32(bp, 0, &magic, sizeof(magic));
  2474. if (rc) {
  2475. DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
  2476. "magic value read (rc %d)\n", rc);
  2477. goto test_nvram_exit;
  2478. }
  2479. if (magic != 0x669955aa) {
  2480. DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
  2481. "wrong magic value (0x%08x)\n", magic);
  2482. rc = -ENODEV;
  2483. goto test_nvram_exit;
  2484. }
  2485. DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM, "Port 0 CRC test-set\n");
  2486. rc = bnx2x_test_nvram_tbl(bp, nvram_tbl, buf);
  2487. if (rc)
  2488. goto test_nvram_exit;
  2489. if (!CHIP_IS_E1x(bp) && !CHIP_IS_57811xx(bp)) {
  2490. u32 hide = SHMEM_RD(bp, dev_info.shared_hw_config.config2) &
  2491. SHARED_HW_CFG_HIDE_PORT1;
  2492. if (!hide) {
  2493. DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
  2494. "Port 1 CRC test-set\n");
  2495. rc = bnx2x_test_nvram_tbl(bp, nvram_tbl2, buf);
  2496. if (rc)
  2497. goto test_nvram_exit;
  2498. }
  2499. }
  2500. rc = bnx2x_test_nvram_dirs(bp, buf);
  2501. test_nvram_exit:
  2502. kfree(buf);
  2503. return rc;
  2504. }
  2505. /* Send an EMPTY ramrod on the first queue */
  2506. static int bnx2x_test_intr(struct bnx2x *bp)
  2507. {
  2508. struct bnx2x_queue_state_params params = {NULL};
  2509. if (!netif_running(bp->dev)) {
  2510. DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
  2511. "cannot access eeprom when the interface is down\n");
  2512. return -ENODEV;
  2513. }
  2514. params.q_obj = &bp->sp_objs->q_obj;
  2515. params.cmd = BNX2X_Q_CMD_EMPTY;
  2516. __set_bit(RAMROD_COMP_WAIT, &params.ramrod_flags);
  2517. return bnx2x_queue_state_change(bp, &params);
  2518. }
  2519. static void bnx2x_self_test(struct net_device *dev,
  2520. struct ethtool_test *etest, u64 *buf)
  2521. {
  2522. struct bnx2x *bp = netdev_priv(dev);
  2523. u8 is_serdes, link_up;
  2524. int rc, cnt = 0;
  2525. if (pci_num_vf(bp->pdev)) {
  2526. DP(BNX2X_MSG_IOV,
  2527. "VFs are enabled, can not perform self test\n");
  2528. return;
  2529. }
  2530. if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
  2531. netdev_err(bp->dev,
  2532. "Handling parity error recovery. Try again later\n");
  2533. etest->flags |= ETH_TEST_FL_FAILED;
  2534. return;
  2535. }
  2536. DP(BNX2X_MSG_ETHTOOL,
  2537. "Self-test command parameters: offline = %d, external_lb = %d\n",
  2538. (etest->flags & ETH_TEST_FL_OFFLINE),
  2539. (etest->flags & ETH_TEST_FL_EXTERNAL_LB)>>2);
  2540. memset(buf, 0, sizeof(u64) * BNX2X_NUM_TESTS(bp));
  2541. if (bnx2x_test_nvram(bp) != 0) {
  2542. if (!IS_MF(bp))
  2543. buf[4] = 1;
  2544. else
  2545. buf[0] = 1;
  2546. etest->flags |= ETH_TEST_FL_FAILED;
  2547. }
  2548. if (!netif_running(dev)) {
  2549. DP(BNX2X_MSG_ETHTOOL, "Interface is down\n");
  2550. return;
  2551. }
  2552. is_serdes = (bp->link_vars.link_status & LINK_STATUS_SERDES_LINK) > 0;
  2553. link_up = bp->link_vars.link_up;
  2554. /* offline tests are not supported in MF mode */
  2555. if ((etest->flags & ETH_TEST_FL_OFFLINE) && !IS_MF(bp)) {
  2556. int port = BP_PORT(bp);
  2557. u32 val;
  2558. /* save current value of input enable for TX port IF */
  2559. val = REG_RD(bp, NIG_REG_EGRESS_UMP0_IN_EN + port*4);
  2560. /* disable input for TX port IF */
  2561. REG_WR(bp, NIG_REG_EGRESS_UMP0_IN_EN + port*4, 0);
  2562. bnx2x_nic_unload(bp, UNLOAD_NORMAL, false);
  2563. rc = bnx2x_nic_load(bp, LOAD_DIAG);
  2564. if (rc) {
  2565. etest->flags |= ETH_TEST_FL_FAILED;
  2566. DP(BNX2X_MSG_ETHTOOL,
  2567. "Can't perform self-test, nic_load (for offline) failed\n");
  2568. return;
  2569. }
  2570. /* wait until link state is restored */
  2571. bnx2x_wait_for_link(bp, 1, is_serdes);
  2572. if (bnx2x_test_registers(bp) != 0) {
  2573. buf[0] = 1;
  2574. etest->flags |= ETH_TEST_FL_FAILED;
  2575. }
  2576. if (bnx2x_test_memory(bp) != 0) {
  2577. buf[1] = 1;
  2578. etest->flags |= ETH_TEST_FL_FAILED;
  2579. }
  2580. buf[2] = bnx2x_test_loopback(bp); /* internal LB */
  2581. if (buf[2] != 0)
  2582. etest->flags |= ETH_TEST_FL_FAILED;
  2583. if (etest->flags & ETH_TEST_FL_EXTERNAL_LB) {
  2584. buf[3] = bnx2x_test_ext_loopback(bp); /* external LB */
  2585. if (buf[3] != 0)
  2586. etest->flags |= ETH_TEST_FL_FAILED;
  2587. etest->flags |= ETH_TEST_FL_EXTERNAL_LB_DONE;
  2588. }
  2589. bnx2x_nic_unload(bp, UNLOAD_NORMAL, false);
  2590. /* restore input for TX port IF */
  2591. REG_WR(bp, NIG_REG_EGRESS_UMP0_IN_EN + port*4, val);
  2592. rc = bnx2x_nic_load(bp, LOAD_NORMAL);
  2593. if (rc) {
  2594. etest->flags |= ETH_TEST_FL_FAILED;
  2595. DP(BNX2X_MSG_ETHTOOL,
  2596. "Can't perform self-test, nic_load (for online) failed\n");
  2597. return;
  2598. }
  2599. /* wait until link state is restored */
  2600. bnx2x_wait_for_link(bp, link_up, is_serdes);
  2601. }
  2602. if (bnx2x_test_intr(bp) != 0) {
  2603. if (!IS_MF(bp))
  2604. buf[5] = 1;
  2605. else
  2606. buf[1] = 1;
  2607. etest->flags |= ETH_TEST_FL_FAILED;
  2608. }
  2609. if (link_up) {
  2610. cnt = 100;
  2611. while (bnx2x_link_test(bp, is_serdes) && --cnt)
  2612. msleep(20);
  2613. }
  2614. if (!cnt) {
  2615. if (!IS_MF(bp))
  2616. buf[6] = 1;
  2617. else
  2618. buf[2] = 1;
  2619. etest->flags |= ETH_TEST_FL_FAILED;
  2620. }
  2621. }
  2622. #define IS_PORT_STAT(i) (bnx2x_stats_arr[i].is_port_stat)
  2623. #define HIDE_PORT_STAT(bp) IS_VF(bp)
  2624. /* ethtool statistics are displayed for all regular ethernet queues and the
  2625. * fcoe L2 queue if not disabled
  2626. */
  2627. static int bnx2x_num_stat_queues(struct bnx2x *bp)
  2628. {
  2629. return BNX2X_NUM_ETH_QUEUES(bp);
  2630. }
  2631. static int bnx2x_get_sset_count(struct net_device *dev, int stringset)
  2632. {
  2633. struct bnx2x *bp = netdev_priv(dev);
  2634. int i, num_strings = 0;
  2635. switch (stringset) {
  2636. case ETH_SS_STATS:
  2637. if (is_multi(bp)) {
  2638. num_strings = bnx2x_num_stat_queues(bp) *
  2639. BNX2X_NUM_Q_STATS;
  2640. } else
  2641. num_strings = 0;
  2642. if (HIDE_PORT_STAT(bp)) {
  2643. for (i = 0; i < BNX2X_NUM_STATS; i++)
  2644. if (!IS_PORT_STAT(i))
  2645. num_strings++;
  2646. } else
  2647. num_strings += BNX2X_NUM_STATS;
  2648. return num_strings;
  2649. case ETH_SS_TEST:
  2650. return BNX2X_NUM_TESTS(bp);
  2651. case ETH_SS_PRIV_FLAGS:
  2652. return BNX2X_PRI_FLAG_LEN;
  2653. default:
  2654. return -EINVAL;
  2655. }
  2656. }
  2657. static u32 bnx2x_get_private_flags(struct net_device *dev)
  2658. {
  2659. struct bnx2x *bp = netdev_priv(dev);
  2660. u32 flags = 0;
  2661. flags |= (!(bp->flags & NO_ISCSI_FLAG) ? 1 : 0) << BNX2X_PRI_FLAG_ISCSI;
  2662. flags |= (!(bp->flags & NO_FCOE_FLAG) ? 1 : 0) << BNX2X_PRI_FLAG_FCOE;
  2663. flags |= (!!IS_MF_STORAGE_ONLY(bp)) << BNX2X_PRI_FLAG_STORAGE;
  2664. return flags;
  2665. }
  2666. static void bnx2x_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
  2667. {
  2668. struct bnx2x *bp = netdev_priv(dev);
  2669. int i, j, k, start;
  2670. char queue_name[MAX_QUEUE_NAME_LEN+1];
  2671. switch (stringset) {
  2672. case ETH_SS_STATS:
  2673. k = 0;
  2674. if (is_multi(bp)) {
  2675. for_each_eth_queue(bp, i) {
  2676. memset(queue_name, 0, sizeof(queue_name));
  2677. snprintf(queue_name, sizeof(queue_name),
  2678. "%d", i);
  2679. for (j = 0; j < BNX2X_NUM_Q_STATS; j++)
  2680. snprintf(buf + (k + j)*ETH_GSTRING_LEN,
  2681. ETH_GSTRING_LEN,
  2682. bnx2x_q_stats_arr[j].string,
  2683. queue_name);
  2684. k += BNX2X_NUM_Q_STATS;
  2685. }
  2686. }
  2687. for (i = 0, j = 0; i < BNX2X_NUM_STATS; i++) {
  2688. if (HIDE_PORT_STAT(bp) && IS_PORT_STAT(i))
  2689. continue;
  2690. strcpy(buf + (k + j)*ETH_GSTRING_LEN,
  2691. bnx2x_stats_arr[i].string);
  2692. j++;
  2693. }
  2694. break;
  2695. case ETH_SS_TEST:
  2696. /* First 4 tests cannot be done in MF mode */
  2697. if (!IS_MF(bp))
  2698. start = 0;
  2699. else
  2700. start = 4;
  2701. memcpy(buf, bnx2x_tests_str_arr + start,
  2702. ETH_GSTRING_LEN * BNX2X_NUM_TESTS(bp));
  2703. break;
  2704. case ETH_SS_PRIV_FLAGS:
  2705. memcpy(buf, bnx2x_private_arr,
  2706. ETH_GSTRING_LEN * BNX2X_PRI_FLAG_LEN);
  2707. break;
  2708. }
  2709. }
  2710. static void bnx2x_get_ethtool_stats(struct net_device *dev,
  2711. struct ethtool_stats *stats, u64 *buf)
  2712. {
  2713. struct bnx2x *bp = netdev_priv(dev);
  2714. u32 *hw_stats, *offset;
  2715. int i, j, k = 0;
  2716. if (is_multi(bp)) {
  2717. for_each_eth_queue(bp, i) {
  2718. hw_stats = (u32 *)&bp->fp_stats[i].eth_q_stats;
  2719. for (j = 0; j < BNX2X_NUM_Q_STATS; j++) {
  2720. if (bnx2x_q_stats_arr[j].size == 0) {
  2721. /* skip this counter */
  2722. buf[k + j] = 0;
  2723. continue;
  2724. }
  2725. offset = (hw_stats +
  2726. bnx2x_q_stats_arr[j].offset);
  2727. if (bnx2x_q_stats_arr[j].size == 4) {
  2728. /* 4-byte counter */
  2729. buf[k + j] = (u64) *offset;
  2730. continue;
  2731. }
  2732. /* 8-byte counter */
  2733. buf[k + j] = HILO_U64(*offset, *(offset + 1));
  2734. }
  2735. k += BNX2X_NUM_Q_STATS;
  2736. }
  2737. }
  2738. hw_stats = (u32 *)&bp->eth_stats;
  2739. for (i = 0, j = 0; i < BNX2X_NUM_STATS; i++) {
  2740. if (HIDE_PORT_STAT(bp) && IS_PORT_STAT(i))
  2741. continue;
  2742. if (bnx2x_stats_arr[i].size == 0) {
  2743. /* skip this counter */
  2744. buf[k + j] = 0;
  2745. j++;
  2746. continue;
  2747. }
  2748. offset = (hw_stats + bnx2x_stats_arr[i].offset);
  2749. if (bnx2x_stats_arr[i].size == 4) {
  2750. /* 4-byte counter */
  2751. buf[k + j] = (u64) *offset;
  2752. j++;
  2753. continue;
  2754. }
  2755. /* 8-byte counter */
  2756. buf[k + j] = HILO_U64(*offset, *(offset + 1));
  2757. j++;
  2758. }
  2759. }
  2760. static int bnx2x_set_phys_id(struct net_device *dev,
  2761. enum ethtool_phys_id_state state)
  2762. {
  2763. struct bnx2x *bp = netdev_priv(dev);
  2764. if (!bnx2x_is_nvm_accessible(bp)) {
  2765. DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
  2766. "cannot access eeprom when the interface is down\n");
  2767. return -EAGAIN;
  2768. }
  2769. switch (state) {
  2770. case ETHTOOL_ID_ACTIVE:
  2771. return 1; /* cycle on/off once per second */
  2772. case ETHTOOL_ID_ON:
  2773. bnx2x_acquire_phy_lock(bp);
  2774. bnx2x_set_led(&bp->link_params, &bp->link_vars,
  2775. LED_MODE_ON, SPEED_1000);
  2776. bnx2x_release_phy_lock(bp);
  2777. break;
  2778. case ETHTOOL_ID_OFF:
  2779. bnx2x_acquire_phy_lock(bp);
  2780. bnx2x_set_led(&bp->link_params, &bp->link_vars,
  2781. LED_MODE_FRONT_PANEL_OFF, 0);
  2782. bnx2x_release_phy_lock(bp);
  2783. break;
  2784. case ETHTOOL_ID_INACTIVE:
  2785. bnx2x_acquire_phy_lock(bp);
  2786. bnx2x_set_led(&bp->link_params, &bp->link_vars,
  2787. LED_MODE_OPER,
  2788. bp->link_vars.line_speed);
  2789. bnx2x_release_phy_lock(bp);
  2790. }
  2791. return 0;
  2792. }
  2793. static int bnx2x_get_rss_flags(struct bnx2x *bp, struct ethtool_rxnfc *info)
  2794. {
  2795. switch (info->flow_type) {
  2796. case TCP_V4_FLOW:
  2797. case TCP_V6_FLOW:
  2798. info->data = RXH_IP_SRC | RXH_IP_DST |
  2799. RXH_L4_B_0_1 | RXH_L4_B_2_3;
  2800. break;
  2801. case UDP_V4_FLOW:
  2802. if (bp->rss_conf_obj.udp_rss_v4)
  2803. info->data = RXH_IP_SRC | RXH_IP_DST |
  2804. RXH_L4_B_0_1 | RXH_L4_B_2_3;
  2805. else
  2806. info->data = RXH_IP_SRC | RXH_IP_DST;
  2807. break;
  2808. case UDP_V6_FLOW:
  2809. if (bp->rss_conf_obj.udp_rss_v6)
  2810. info->data = RXH_IP_SRC | RXH_IP_DST |
  2811. RXH_L4_B_0_1 | RXH_L4_B_2_3;
  2812. else
  2813. info->data = RXH_IP_SRC | RXH_IP_DST;
  2814. break;
  2815. case IPV4_FLOW:
  2816. case IPV6_FLOW:
  2817. info->data = RXH_IP_SRC | RXH_IP_DST;
  2818. break;
  2819. default:
  2820. info->data = 0;
  2821. break;
  2822. }
  2823. return 0;
  2824. }
  2825. static int bnx2x_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info,
  2826. u32 *rules __always_unused)
  2827. {
  2828. struct bnx2x *bp = netdev_priv(dev);
  2829. switch (info->cmd) {
  2830. case ETHTOOL_GRXRINGS:
  2831. info->data = BNX2X_NUM_ETH_QUEUES(bp);
  2832. return 0;
  2833. case ETHTOOL_GRXFH:
  2834. return bnx2x_get_rss_flags(bp, info);
  2835. default:
  2836. DP(BNX2X_MSG_ETHTOOL, "Command parameters not supported\n");
  2837. return -EOPNOTSUPP;
  2838. }
  2839. }
  2840. static int bnx2x_set_rss_flags(struct bnx2x *bp, struct ethtool_rxnfc *info)
  2841. {
  2842. int udp_rss_requested;
  2843. DP(BNX2X_MSG_ETHTOOL,
  2844. "Set rss flags command parameters: flow type = %d, data = %llu\n",
  2845. info->flow_type, info->data);
  2846. switch (info->flow_type) {
  2847. case TCP_V4_FLOW:
  2848. case TCP_V6_FLOW:
  2849. /* For TCP only 4-tupple hash is supported */
  2850. if (info->data ^ (RXH_IP_SRC | RXH_IP_DST |
  2851. RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  2852. DP(BNX2X_MSG_ETHTOOL,
  2853. "Command parameters not supported\n");
  2854. return -EINVAL;
  2855. }
  2856. return 0;
  2857. case UDP_V4_FLOW:
  2858. case UDP_V6_FLOW:
  2859. /* For UDP either 2-tupple hash or 4-tupple hash is supported */
  2860. if (info->data == (RXH_IP_SRC | RXH_IP_DST |
  2861. RXH_L4_B_0_1 | RXH_L4_B_2_3))
  2862. udp_rss_requested = 1;
  2863. else if (info->data == (RXH_IP_SRC | RXH_IP_DST))
  2864. udp_rss_requested = 0;
  2865. else
  2866. return -EINVAL;
  2867. if (CHIP_IS_E1x(bp) && udp_rss_requested) {
  2868. DP(BNX2X_MSG_ETHTOOL,
  2869. "57710, 57711 boards don't support RSS according to UDP 4-tuple\n");
  2870. return -EINVAL;
  2871. }
  2872. if ((info->flow_type == UDP_V4_FLOW) &&
  2873. (bp->rss_conf_obj.udp_rss_v4 != udp_rss_requested)) {
  2874. bp->rss_conf_obj.udp_rss_v4 = udp_rss_requested;
  2875. DP(BNX2X_MSG_ETHTOOL,
  2876. "rss re-configured, UDP 4-tupple %s\n",
  2877. udp_rss_requested ? "enabled" : "disabled");
  2878. if (bp->state == BNX2X_STATE_OPEN)
  2879. return bnx2x_rss(bp, &bp->rss_conf_obj, false,
  2880. true);
  2881. } else if ((info->flow_type == UDP_V6_FLOW) &&
  2882. (bp->rss_conf_obj.udp_rss_v6 != udp_rss_requested)) {
  2883. bp->rss_conf_obj.udp_rss_v6 = udp_rss_requested;
  2884. DP(BNX2X_MSG_ETHTOOL,
  2885. "rss re-configured, UDP 4-tupple %s\n",
  2886. udp_rss_requested ? "enabled" : "disabled");
  2887. if (bp->state == BNX2X_STATE_OPEN)
  2888. return bnx2x_rss(bp, &bp->rss_conf_obj, false,
  2889. true);
  2890. }
  2891. return 0;
  2892. case IPV4_FLOW:
  2893. case IPV6_FLOW:
  2894. /* For IP only 2-tupple hash is supported */
  2895. if (info->data ^ (RXH_IP_SRC | RXH_IP_DST)) {
  2896. DP(BNX2X_MSG_ETHTOOL,
  2897. "Command parameters not supported\n");
  2898. return -EINVAL;
  2899. }
  2900. return 0;
  2901. case SCTP_V4_FLOW:
  2902. case AH_ESP_V4_FLOW:
  2903. case AH_V4_FLOW:
  2904. case ESP_V4_FLOW:
  2905. case SCTP_V6_FLOW:
  2906. case AH_ESP_V6_FLOW:
  2907. case AH_V6_FLOW:
  2908. case ESP_V6_FLOW:
  2909. case IP_USER_FLOW:
  2910. case ETHER_FLOW:
  2911. /* RSS is not supported for these protocols */
  2912. if (info->data) {
  2913. DP(BNX2X_MSG_ETHTOOL,
  2914. "Command parameters not supported\n");
  2915. return -EINVAL;
  2916. }
  2917. return 0;
  2918. default:
  2919. return -EINVAL;
  2920. }
  2921. }
  2922. static int bnx2x_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info)
  2923. {
  2924. struct bnx2x *bp = netdev_priv(dev);
  2925. switch (info->cmd) {
  2926. case ETHTOOL_SRXFH:
  2927. return bnx2x_set_rss_flags(bp, info);
  2928. default:
  2929. DP(BNX2X_MSG_ETHTOOL, "Command parameters not supported\n");
  2930. return -EOPNOTSUPP;
  2931. }
  2932. }
  2933. static u32 bnx2x_get_rxfh_indir_size(struct net_device *dev)
  2934. {
  2935. return T_ETH_INDIRECTION_TABLE_SIZE;
  2936. }
  2937. static int bnx2x_get_rxfh(struct net_device *dev, u32 *indir, u8 *key,
  2938. u8 *hfunc)
  2939. {
  2940. struct bnx2x *bp = netdev_priv(dev);
  2941. u8 ind_table[T_ETH_INDIRECTION_TABLE_SIZE] = {0};
  2942. size_t i;
  2943. if (hfunc)
  2944. *hfunc = ETH_RSS_HASH_TOP;
  2945. if (!indir)
  2946. return 0;
  2947. /* Get the current configuration of the RSS indirection table */
  2948. bnx2x_get_rss_ind_table(&bp->rss_conf_obj, ind_table);
  2949. /*
  2950. * We can't use a memcpy() as an internal storage of an
  2951. * indirection table is a u8 array while indir->ring_index
  2952. * points to an array of u32.
  2953. *
  2954. * Indirection table contains the FW Client IDs, so we need to
  2955. * align the returned table to the Client ID of the leading RSS
  2956. * queue.
  2957. */
  2958. for (i = 0; i < T_ETH_INDIRECTION_TABLE_SIZE; i++)
  2959. indir[i] = ind_table[i] - bp->fp->cl_id;
  2960. return 0;
  2961. }
  2962. static int bnx2x_set_rxfh(struct net_device *dev, const u32 *indir,
  2963. const u8 *key, const u8 hfunc)
  2964. {
  2965. struct bnx2x *bp = netdev_priv(dev);
  2966. size_t i;
  2967. /* We require at least one supported parameter to be changed and no
  2968. * change in any of the unsupported parameters
  2969. */
  2970. if (key ||
  2971. (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP))
  2972. return -EOPNOTSUPP;
  2973. if (!indir)
  2974. return 0;
  2975. for (i = 0; i < T_ETH_INDIRECTION_TABLE_SIZE; i++) {
  2976. /*
  2977. * The same as in bnx2x_get_rxfh: we can't use a memcpy()
  2978. * as an internal storage of an indirection table is a u8 array
  2979. * while indir->ring_index points to an array of u32.
  2980. *
  2981. * Indirection table contains the FW Client IDs, so we need to
  2982. * align the received table to the Client ID of the leading RSS
  2983. * queue
  2984. */
  2985. bp->rss_conf_obj.ind_table[i] = indir[i] + bp->fp->cl_id;
  2986. }
  2987. if (bp->state == BNX2X_STATE_OPEN)
  2988. return bnx2x_config_rss_eth(bp, false);
  2989. return 0;
  2990. }
  2991. /**
  2992. * bnx2x_get_channels - gets the number of RSS queues.
  2993. *
  2994. * @dev: net device
  2995. * @channels: returns the number of max / current queues
  2996. */
  2997. static void bnx2x_get_channels(struct net_device *dev,
  2998. struct ethtool_channels *channels)
  2999. {
  3000. struct bnx2x *bp = netdev_priv(dev);
  3001. channels->max_combined = BNX2X_MAX_RSS_COUNT(bp);
  3002. channels->combined_count = BNX2X_NUM_ETH_QUEUES(bp);
  3003. }
  3004. /**
  3005. * bnx2x_change_num_queues - change the number of RSS queues.
  3006. *
  3007. * @bp: bnx2x private structure
  3008. *
  3009. * Re-configure interrupt mode to get the new number of MSI-X
  3010. * vectors and re-add NAPI objects.
  3011. */
  3012. static void bnx2x_change_num_queues(struct bnx2x *bp, int num_rss)
  3013. {
  3014. bnx2x_disable_msi(bp);
  3015. bp->num_ethernet_queues = num_rss;
  3016. bp->num_queues = bp->num_ethernet_queues + bp->num_cnic_queues;
  3017. BNX2X_DEV_INFO("set number of queues to %d\n", bp->num_queues);
  3018. bnx2x_set_int_mode(bp);
  3019. }
  3020. /**
  3021. * bnx2x_set_channels - sets the number of RSS queues.
  3022. *
  3023. * @dev: net device
  3024. * @channels: includes the number of queues requested
  3025. */
  3026. static int bnx2x_set_channels(struct net_device *dev,
  3027. struct ethtool_channels *channels)
  3028. {
  3029. struct bnx2x *bp = netdev_priv(dev);
  3030. DP(BNX2X_MSG_ETHTOOL,
  3031. "set-channels command parameters: rx = %d, tx = %d, other = %d, combined = %d\n",
  3032. channels->rx_count, channels->tx_count, channels->other_count,
  3033. channels->combined_count);
  3034. if (pci_num_vf(bp->pdev)) {
  3035. DP(BNX2X_MSG_IOV, "VFs are enabled, can not set channels\n");
  3036. return -EPERM;
  3037. }
  3038. /* We don't support separate rx / tx channels.
  3039. * We don't allow setting 'other' channels.
  3040. */
  3041. if (channels->rx_count || channels->tx_count || channels->other_count
  3042. || (channels->combined_count == 0) ||
  3043. (channels->combined_count > BNX2X_MAX_RSS_COUNT(bp))) {
  3044. DP(BNX2X_MSG_ETHTOOL, "command parameters not supported\n");
  3045. return -EINVAL;
  3046. }
  3047. /* Check if there was a change in the active parameters */
  3048. if (channels->combined_count == BNX2X_NUM_ETH_QUEUES(bp)) {
  3049. DP(BNX2X_MSG_ETHTOOL, "No change in active parameters\n");
  3050. return 0;
  3051. }
  3052. /* Set the requested number of queues in bp context.
  3053. * Note that the actual number of queues created during load may be
  3054. * less than requested if memory is low.
  3055. */
  3056. if (unlikely(!netif_running(dev))) {
  3057. bnx2x_change_num_queues(bp, channels->combined_count);
  3058. return 0;
  3059. }
  3060. bnx2x_nic_unload(bp, UNLOAD_NORMAL, true);
  3061. bnx2x_change_num_queues(bp, channels->combined_count);
  3062. return bnx2x_nic_load(bp, LOAD_NORMAL);
  3063. }
  3064. static int bnx2x_get_ts_info(struct net_device *dev,
  3065. struct ethtool_ts_info *info)
  3066. {
  3067. struct bnx2x *bp = netdev_priv(dev);
  3068. if (bp->flags & PTP_SUPPORTED) {
  3069. info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
  3070. SOF_TIMESTAMPING_RX_SOFTWARE |
  3071. SOF_TIMESTAMPING_SOFTWARE |
  3072. SOF_TIMESTAMPING_TX_HARDWARE |
  3073. SOF_TIMESTAMPING_RX_HARDWARE |
  3074. SOF_TIMESTAMPING_RAW_HARDWARE;
  3075. if (bp->ptp_clock)
  3076. info->phc_index = ptp_clock_index(bp->ptp_clock);
  3077. else
  3078. info->phc_index = -1;
  3079. info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
  3080. (1 << HWTSTAMP_FILTER_PTP_V1_L4_EVENT) |
  3081. (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
  3082. (1 << HWTSTAMP_FILTER_PTP_V2_EVENT);
  3083. info->tx_types = (1 << HWTSTAMP_TX_OFF)|(1 << HWTSTAMP_TX_ON);
  3084. return 0;
  3085. }
  3086. return ethtool_op_get_ts_info(dev, info);
  3087. }
  3088. static const struct ethtool_ops bnx2x_ethtool_ops = {
  3089. .get_drvinfo = bnx2x_get_drvinfo,
  3090. .get_regs_len = bnx2x_get_regs_len,
  3091. .get_regs = bnx2x_get_regs,
  3092. .get_dump_flag = bnx2x_get_dump_flag,
  3093. .get_dump_data = bnx2x_get_dump_data,
  3094. .set_dump = bnx2x_set_dump,
  3095. .get_wol = bnx2x_get_wol,
  3096. .set_wol = bnx2x_set_wol,
  3097. .get_msglevel = bnx2x_get_msglevel,
  3098. .set_msglevel = bnx2x_set_msglevel,
  3099. .nway_reset = bnx2x_nway_reset,
  3100. .get_link = bnx2x_get_link,
  3101. .get_eeprom_len = bnx2x_get_eeprom_len,
  3102. .get_eeprom = bnx2x_get_eeprom,
  3103. .set_eeprom = bnx2x_set_eeprom,
  3104. .get_coalesce = bnx2x_get_coalesce,
  3105. .set_coalesce = bnx2x_set_coalesce,
  3106. .get_ringparam = bnx2x_get_ringparam,
  3107. .set_ringparam = bnx2x_set_ringparam,
  3108. .get_pauseparam = bnx2x_get_pauseparam,
  3109. .set_pauseparam = bnx2x_set_pauseparam,
  3110. .self_test = bnx2x_self_test,
  3111. .get_sset_count = bnx2x_get_sset_count,
  3112. .get_priv_flags = bnx2x_get_private_flags,
  3113. .get_strings = bnx2x_get_strings,
  3114. .set_phys_id = bnx2x_set_phys_id,
  3115. .get_ethtool_stats = bnx2x_get_ethtool_stats,
  3116. .get_rxnfc = bnx2x_get_rxnfc,
  3117. .set_rxnfc = bnx2x_set_rxnfc,
  3118. .get_rxfh_indir_size = bnx2x_get_rxfh_indir_size,
  3119. .get_rxfh = bnx2x_get_rxfh,
  3120. .set_rxfh = bnx2x_set_rxfh,
  3121. .get_channels = bnx2x_get_channels,
  3122. .set_channels = bnx2x_set_channels,
  3123. .get_module_info = bnx2x_get_module_info,
  3124. .get_module_eeprom = bnx2x_get_module_eeprom,
  3125. .get_eee = bnx2x_get_eee,
  3126. .set_eee = bnx2x_set_eee,
  3127. .get_ts_info = bnx2x_get_ts_info,
  3128. .get_link_ksettings = bnx2x_get_link_ksettings,
  3129. .set_link_ksettings = bnx2x_set_link_ksettings,
  3130. };
  3131. static const struct ethtool_ops bnx2x_vf_ethtool_ops = {
  3132. .get_drvinfo = bnx2x_get_drvinfo,
  3133. .get_msglevel = bnx2x_get_msglevel,
  3134. .set_msglevel = bnx2x_set_msglevel,
  3135. .get_link = bnx2x_get_link,
  3136. .get_coalesce = bnx2x_get_coalesce,
  3137. .get_ringparam = bnx2x_get_ringparam,
  3138. .set_ringparam = bnx2x_set_ringparam,
  3139. .get_sset_count = bnx2x_get_sset_count,
  3140. .get_strings = bnx2x_get_strings,
  3141. .get_ethtool_stats = bnx2x_get_ethtool_stats,
  3142. .get_rxnfc = bnx2x_get_rxnfc,
  3143. .set_rxnfc = bnx2x_set_rxnfc,
  3144. .get_rxfh_indir_size = bnx2x_get_rxfh_indir_size,
  3145. .get_rxfh = bnx2x_get_rxfh,
  3146. .set_rxfh = bnx2x_set_rxfh,
  3147. .get_channels = bnx2x_get_channels,
  3148. .set_channels = bnx2x_set_channels,
  3149. .get_link_ksettings = bnx2x_get_vf_link_ksettings,
  3150. };
  3151. void bnx2x_set_ethtool_ops(struct bnx2x *bp, struct net_device *netdev)
  3152. {
  3153. netdev->ethtool_ops = (IS_PF(bp)) ?
  3154. &bnx2x_ethtool_ops : &bnx2x_vf_ethtool_ops;
  3155. }