i40e_ethtool.c 125 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243
  1. /*******************************************************************************
  2. *
  3. * Intel Ethernet Controller XL710 Family Linux Driver
  4. * Copyright(c) 2013 - 2016 Intel Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms and conditions of the GNU General Public License,
  8. * version 2, as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. * The full GNU General Public License is included in this distribution in
  19. * the file called "COPYING".
  20. *
  21. * Contact Information:
  22. * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  23. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  24. *
  25. ******************************************************************************/
  26. /* ethtool support for i40e */
  27. #include "i40e.h"
  28. #include "i40e_diag.h"
  29. struct i40e_stats {
  30. char stat_string[ETH_GSTRING_LEN];
  31. int sizeof_stat;
  32. int stat_offset;
  33. };
  34. #define I40E_STAT(_type, _name, _stat) { \
  35. .stat_string = _name, \
  36. .sizeof_stat = FIELD_SIZEOF(_type, _stat), \
  37. .stat_offset = offsetof(_type, _stat) \
  38. }
  39. #define I40E_NETDEV_STAT(_net_stat) \
  40. I40E_STAT(struct rtnl_link_stats64, #_net_stat, _net_stat)
  41. #define I40E_PF_STAT(_name, _stat) \
  42. I40E_STAT(struct i40e_pf, _name, _stat)
  43. #define I40E_VSI_STAT(_name, _stat) \
  44. I40E_STAT(struct i40e_vsi, _name, _stat)
  45. #define I40E_VEB_STAT(_name, _stat) \
  46. I40E_STAT(struct i40e_veb, _name, _stat)
  47. static const struct i40e_stats i40e_gstrings_net_stats[] = {
  48. I40E_NETDEV_STAT(rx_packets),
  49. I40E_NETDEV_STAT(tx_packets),
  50. I40E_NETDEV_STAT(rx_bytes),
  51. I40E_NETDEV_STAT(tx_bytes),
  52. I40E_NETDEV_STAT(rx_errors),
  53. I40E_NETDEV_STAT(tx_errors),
  54. I40E_NETDEV_STAT(rx_dropped),
  55. I40E_NETDEV_STAT(tx_dropped),
  56. I40E_NETDEV_STAT(collisions),
  57. I40E_NETDEV_STAT(rx_length_errors),
  58. I40E_NETDEV_STAT(rx_crc_errors),
  59. };
  60. static const struct i40e_stats i40e_gstrings_veb_stats[] = {
  61. I40E_VEB_STAT("rx_bytes", stats.rx_bytes),
  62. I40E_VEB_STAT("tx_bytes", stats.tx_bytes),
  63. I40E_VEB_STAT("rx_unicast", stats.rx_unicast),
  64. I40E_VEB_STAT("tx_unicast", stats.tx_unicast),
  65. I40E_VEB_STAT("rx_multicast", stats.rx_multicast),
  66. I40E_VEB_STAT("tx_multicast", stats.tx_multicast),
  67. I40E_VEB_STAT("rx_broadcast", stats.rx_broadcast),
  68. I40E_VEB_STAT("tx_broadcast", stats.tx_broadcast),
  69. I40E_VEB_STAT("rx_discards", stats.rx_discards),
  70. I40E_VEB_STAT("tx_discards", stats.tx_discards),
  71. I40E_VEB_STAT("tx_errors", stats.tx_errors),
  72. I40E_VEB_STAT("rx_unknown_protocol", stats.rx_unknown_protocol),
  73. };
  74. static const struct i40e_stats i40e_gstrings_misc_stats[] = {
  75. I40E_VSI_STAT("rx_unicast", eth_stats.rx_unicast),
  76. I40E_VSI_STAT("tx_unicast", eth_stats.tx_unicast),
  77. I40E_VSI_STAT("rx_multicast", eth_stats.rx_multicast),
  78. I40E_VSI_STAT("tx_multicast", eth_stats.tx_multicast),
  79. I40E_VSI_STAT("rx_broadcast", eth_stats.rx_broadcast),
  80. I40E_VSI_STAT("tx_broadcast", eth_stats.tx_broadcast),
  81. I40E_VSI_STAT("rx_unknown_protocol", eth_stats.rx_unknown_protocol),
  82. I40E_VSI_STAT("tx_linearize", tx_linearize),
  83. I40E_VSI_STAT("tx_force_wb", tx_force_wb),
  84. I40E_VSI_STAT("rx_alloc_fail", rx_buf_failed),
  85. I40E_VSI_STAT("rx_pg_alloc_fail", rx_page_failed),
  86. };
  87. /* These PF_STATs might look like duplicates of some NETDEV_STATs,
  88. * but they are separate. This device supports Virtualization, and
  89. * as such might have several netdevs supporting VMDq and FCoE going
  90. * through a single port. The NETDEV_STATs are for individual netdevs
  91. * seen at the top of the stack, and the PF_STATs are for the physical
  92. * function at the bottom of the stack hosting those netdevs.
  93. *
  94. * The PF_STATs are appended to the netdev stats only when ethtool -S
  95. * is queried on the base PF netdev, not on the VMDq or FCoE netdev.
  96. */
  97. static const struct i40e_stats i40e_gstrings_stats[] = {
  98. I40E_PF_STAT("rx_bytes", stats.eth.rx_bytes),
  99. I40E_PF_STAT("tx_bytes", stats.eth.tx_bytes),
  100. I40E_PF_STAT("rx_unicast", stats.eth.rx_unicast),
  101. I40E_PF_STAT("tx_unicast", stats.eth.tx_unicast),
  102. I40E_PF_STAT("rx_multicast", stats.eth.rx_multicast),
  103. I40E_PF_STAT("tx_multicast", stats.eth.tx_multicast),
  104. I40E_PF_STAT("rx_broadcast", stats.eth.rx_broadcast),
  105. I40E_PF_STAT("tx_broadcast", stats.eth.tx_broadcast),
  106. I40E_PF_STAT("tx_errors", stats.eth.tx_errors),
  107. I40E_PF_STAT("rx_dropped", stats.eth.rx_discards),
  108. I40E_PF_STAT("tx_dropped_link_down", stats.tx_dropped_link_down),
  109. I40E_PF_STAT("rx_crc_errors", stats.crc_errors),
  110. I40E_PF_STAT("illegal_bytes", stats.illegal_bytes),
  111. I40E_PF_STAT("mac_local_faults", stats.mac_local_faults),
  112. I40E_PF_STAT("mac_remote_faults", stats.mac_remote_faults),
  113. I40E_PF_STAT("tx_timeout", tx_timeout_count),
  114. I40E_PF_STAT("rx_csum_bad", hw_csum_rx_error),
  115. I40E_PF_STAT("rx_length_errors", stats.rx_length_errors),
  116. I40E_PF_STAT("link_xon_rx", stats.link_xon_rx),
  117. I40E_PF_STAT("link_xoff_rx", stats.link_xoff_rx),
  118. I40E_PF_STAT("link_xon_tx", stats.link_xon_tx),
  119. I40E_PF_STAT("link_xoff_tx", stats.link_xoff_tx),
  120. I40E_PF_STAT("rx_size_64", stats.rx_size_64),
  121. I40E_PF_STAT("rx_size_127", stats.rx_size_127),
  122. I40E_PF_STAT("rx_size_255", stats.rx_size_255),
  123. I40E_PF_STAT("rx_size_511", stats.rx_size_511),
  124. I40E_PF_STAT("rx_size_1023", stats.rx_size_1023),
  125. I40E_PF_STAT("rx_size_1522", stats.rx_size_1522),
  126. I40E_PF_STAT("rx_size_big", stats.rx_size_big),
  127. I40E_PF_STAT("tx_size_64", stats.tx_size_64),
  128. I40E_PF_STAT("tx_size_127", stats.tx_size_127),
  129. I40E_PF_STAT("tx_size_255", stats.tx_size_255),
  130. I40E_PF_STAT("tx_size_511", stats.tx_size_511),
  131. I40E_PF_STAT("tx_size_1023", stats.tx_size_1023),
  132. I40E_PF_STAT("tx_size_1522", stats.tx_size_1522),
  133. I40E_PF_STAT("tx_size_big", stats.tx_size_big),
  134. I40E_PF_STAT("rx_undersize", stats.rx_undersize),
  135. I40E_PF_STAT("rx_fragments", stats.rx_fragments),
  136. I40E_PF_STAT("rx_oversize", stats.rx_oversize),
  137. I40E_PF_STAT("rx_jabber", stats.rx_jabber),
  138. I40E_PF_STAT("VF_admin_queue_requests", vf_aq_requests),
  139. I40E_PF_STAT("arq_overflows", arq_overflows),
  140. I40E_PF_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared),
  141. I40E_PF_STAT("tx_hwtstamp_skipped", tx_hwtstamp_skipped),
  142. I40E_PF_STAT("fdir_flush_cnt", fd_flush_cnt),
  143. I40E_PF_STAT("fdir_atr_match", stats.fd_atr_match),
  144. I40E_PF_STAT("fdir_atr_tunnel_match", stats.fd_atr_tunnel_match),
  145. I40E_PF_STAT("fdir_atr_status", stats.fd_atr_status),
  146. I40E_PF_STAT("fdir_sb_match", stats.fd_sb_match),
  147. I40E_PF_STAT("fdir_sb_status", stats.fd_sb_status),
  148. /* LPI stats */
  149. I40E_PF_STAT("tx_lpi_status", stats.tx_lpi_status),
  150. I40E_PF_STAT("rx_lpi_status", stats.rx_lpi_status),
  151. I40E_PF_STAT("tx_lpi_count", stats.tx_lpi_count),
  152. I40E_PF_STAT("rx_lpi_count", stats.rx_lpi_count),
  153. };
  154. #define I40E_QUEUE_STATS_LEN(n) \
  155. (((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs \
  156. * 2 /* Tx and Rx together */ \
  157. * (sizeof(struct i40e_queue_stats) / sizeof(u64)))
  158. #define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats)
  159. #define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats)
  160. #define I40E_MISC_STATS_LEN ARRAY_SIZE(i40e_gstrings_misc_stats)
  161. #define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
  162. I40E_MISC_STATS_LEN + \
  163. I40E_QUEUE_STATS_LEN((n)))
  164. #define I40E_PFC_STATS_LEN ( \
  165. (FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \
  166. FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \
  167. FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \
  168. FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \
  169. FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \
  170. / sizeof(u64))
  171. #define I40E_VEB_TC_STATS_LEN ( \
  172. (FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_packets) + \
  173. FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_bytes) + \
  174. FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_packets) + \
  175. FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_bytes)) \
  176. / sizeof(u64))
  177. #define I40E_VEB_STATS_LEN ARRAY_SIZE(i40e_gstrings_veb_stats)
  178. #define I40E_VEB_STATS_TOTAL (I40E_VEB_STATS_LEN + I40E_VEB_TC_STATS_LEN)
  179. #define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \
  180. I40E_PFC_STATS_LEN + \
  181. I40E_VSI_STATS_LEN((n)))
  182. enum i40e_ethtool_test_id {
  183. I40E_ETH_TEST_REG = 0,
  184. I40E_ETH_TEST_EEPROM,
  185. I40E_ETH_TEST_INTR,
  186. I40E_ETH_TEST_LINK,
  187. };
  188. static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = {
  189. "Register test (offline)",
  190. "Eeprom test (offline)",
  191. "Interrupt test (offline)",
  192. "Link test (on/offline)"
  193. };
  194. #define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
  195. struct i40e_priv_flags {
  196. char flag_string[ETH_GSTRING_LEN];
  197. u64 flag;
  198. bool read_only;
  199. };
  200. #define I40E_PRIV_FLAG(_name, _flag, _read_only) { \
  201. .flag_string = _name, \
  202. .flag = _flag, \
  203. .read_only = _read_only, \
  204. }
  205. static const struct i40e_priv_flags i40e_gstrings_priv_flags[] = {
  206. /* NOTE: MFP setting cannot be changed */
  207. I40E_PRIV_FLAG("MFP", I40E_FLAG_MFP_ENABLED, 1),
  208. I40E_PRIV_FLAG("LinkPolling", I40E_FLAG_LINK_POLLING_ENABLED, 0),
  209. I40E_PRIV_FLAG("flow-director-atr", I40E_FLAG_FD_ATR_ENABLED, 0),
  210. I40E_PRIV_FLAG("veb-stats", I40E_FLAG_VEB_STATS_ENABLED, 0),
  211. I40E_PRIV_FLAG("hw-atr-eviction", I40E_FLAG_HW_ATR_EVICT_ENABLED, 0),
  212. I40E_PRIV_FLAG("legacy-rx", I40E_FLAG_LEGACY_RX, 0),
  213. };
  214. #define I40E_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40e_gstrings_priv_flags)
  215. /* Private flags with a global effect, restricted to PF 0 */
  216. static const struct i40e_priv_flags i40e_gl_gstrings_priv_flags[] = {
  217. I40E_PRIV_FLAG("vf-true-promisc-support",
  218. I40E_FLAG_TRUE_PROMISC_SUPPORT, 0),
  219. };
  220. #define I40E_GL_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40e_gl_gstrings_priv_flags)
  221. /**
  222. * i40e_partition_setting_complaint - generic complaint for MFP restriction
  223. * @pf: the PF struct
  224. **/
  225. static void i40e_partition_setting_complaint(struct i40e_pf *pf)
  226. {
  227. dev_info(&pf->pdev->dev,
  228. "The link settings are allowed to be changed only from the first partition of a given port. Please switch to the first partition in order to change the setting.\n");
  229. }
  230. /**
  231. * i40e_phy_type_to_ethtool - convert the phy_types to ethtool link modes
  232. * @phy_types: PHY types to convert
  233. * @supported: pointer to the ethtool supported variable to fill in
  234. * @advertising: pointer to the ethtool advertising variable to fill in
  235. *
  236. **/
  237. static void i40e_phy_type_to_ethtool(struct i40e_pf *pf, u32 *supported,
  238. u32 *advertising)
  239. {
  240. struct i40e_link_status *hw_link_info = &pf->hw.phy.link_info;
  241. u64 phy_types = pf->hw.phy.phy_types;
  242. *supported = 0x0;
  243. *advertising = 0x0;
  244. if (phy_types & I40E_CAP_PHY_TYPE_SGMII) {
  245. *supported |= SUPPORTED_Autoneg |
  246. SUPPORTED_1000baseT_Full;
  247. *advertising |= ADVERTISED_Autoneg;
  248. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
  249. *advertising |= ADVERTISED_1000baseT_Full;
  250. if (pf->hw_features & I40E_HW_100M_SGMII_CAPABLE) {
  251. *supported |= SUPPORTED_100baseT_Full;
  252. *advertising |= ADVERTISED_100baseT_Full;
  253. }
  254. }
  255. if (phy_types & I40E_CAP_PHY_TYPE_XAUI ||
  256. phy_types & I40E_CAP_PHY_TYPE_XFI ||
  257. phy_types & I40E_CAP_PHY_TYPE_SFI ||
  258. phy_types & I40E_CAP_PHY_TYPE_10GBASE_SFPP_CU ||
  259. phy_types & I40E_CAP_PHY_TYPE_10GBASE_AOC)
  260. *supported |= SUPPORTED_10000baseT_Full;
  261. if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1_CU ||
  262. phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1 ||
  263. phy_types & I40E_CAP_PHY_TYPE_10GBASE_T ||
  264. phy_types & I40E_CAP_PHY_TYPE_10GBASE_SR ||
  265. phy_types & I40E_CAP_PHY_TYPE_10GBASE_LR) {
  266. *supported |= SUPPORTED_Autoneg |
  267. SUPPORTED_10000baseT_Full;
  268. *advertising |= ADVERTISED_Autoneg;
  269. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
  270. *advertising |= ADVERTISED_10000baseT_Full;
  271. }
  272. if (phy_types & I40E_CAP_PHY_TYPE_XLAUI ||
  273. phy_types & I40E_CAP_PHY_TYPE_XLPPI ||
  274. phy_types & I40E_CAP_PHY_TYPE_40GBASE_AOC)
  275. *supported |= SUPPORTED_40000baseCR4_Full;
  276. if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4_CU ||
  277. phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4) {
  278. *supported |= SUPPORTED_Autoneg |
  279. SUPPORTED_40000baseCR4_Full;
  280. *advertising |= ADVERTISED_Autoneg;
  281. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_40GB)
  282. *advertising |= ADVERTISED_40000baseCR4_Full;
  283. }
  284. if (phy_types & I40E_CAP_PHY_TYPE_100BASE_TX) {
  285. *supported |= SUPPORTED_Autoneg |
  286. SUPPORTED_100baseT_Full;
  287. *advertising |= ADVERTISED_Autoneg;
  288. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
  289. *advertising |= ADVERTISED_100baseT_Full;
  290. }
  291. if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_T ||
  292. phy_types & I40E_CAP_PHY_TYPE_1000BASE_SX ||
  293. phy_types & I40E_CAP_PHY_TYPE_1000BASE_LX ||
  294. phy_types & I40E_CAP_PHY_TYPE_1000BASE_T_OPTICAL) {
  295. *supported |= SUPPORTED_Autoneg |
  296. SUPPORTED_1000baseT_Full;
  297. *advertising |= ADVERTISED_Autoneg;
  298. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
  299. *advertising |= ADVERTISED_1000baseT_Full;
  300. }
  301. if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_SR4)
  302. *supported |= SUPPORTED_40000baseSR4_Full;
  303. if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_LR4)
  304. *supported |= SUPPORTED_40000baseLR4_Full;
  305. if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_KR4) {
  306. *supported |= SUPPORTED_40000baseKR4_Full |
  307. SUPPORTED_Autoneg;
  308. *advertising |= ADVERTISED_40000baseKR4_Full |
  309. ADVERTISED_Autoneg;
  310. }
  311. if (phy_types & I40E_CAP_PHY_TYPE_20GBASE_KR2) {
  312. *supported |= SUPPORTED_20000baseKR2_Full |
  313. SUPPORTED_Autoneg;
  314. *advertising |= ADVERTISED_Autoneg;
  315. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_20GB)
  316. *advertising |= ADVERTISED_20000baseKR2_Full;
  317. }
  318. if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_KR) {
  319. if (!(pf->hw_features & I40E_HW_HAVE_CRT_RETIMER))
  320. *supported |= SUPPORTED_10000baseKR_Full |
  321. SUPPORTED_Autoneg;
  322. *advertising |= ADVERTISED_Autoneg;
  323. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
  324. if (!(pf->hw_features & I40E_HW_HAVE_CRT_RETIMER))
  325. *advertising |= ADVERTISED_10000baseKR_Full;
  326. }
  327. if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_KX4) {
  328. *supported |= SUPPORTED_10000baseKX4_Full |
  329. SUPPORTED_Autoneg;
  330. *advertising |= ADVERTISED_Autoneg;
  331. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
  332. *advertising |= ADVERTISED_10000baseKX4_Full;
  333. }
  334. if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_KX) {
  335. if (!(pf->hw_features & I40E_HW_HAVE_CRT_RETIMER))
  336. *supported |= SUPPORTED_1000baseKX_Full |
  337. SUPPORTED_Autoneg;
  338. *advertising |= ADVERTISED_Autoneg;
  339. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
  340. if (!(pf->hw_features & I40E_HW_HAVE_CRT_RETIMER))
  341. *advertising |= ADVERTISED_1000baseKX_Full;
  342. }
  343. if (phy_types & I40E_CAP_PHY_TYPE_25GBASE_KR ||
  344. phy_types & I40E_CAP_PHY_TYPE_25GBASE_CR ||
  345. phy_types & I40E_CAP_PHY_TYPE_25GBASE_SR ||
  346. phy_types & I40E_CAP_PHY_TYPE_25GBASE_LR) {
  347. *supported |= SUPPORTED_Autoneg;
  348. *advertising |= ADVERTISED_Autoneg;
  349. }
  350. }
  351. /**
  352. * i40e_get_settings_link_up - Get the Link settings for when link is up
  353. * @hw: hw structure
  354. * @ecmd: ethtool command to fill in
  355. * @netdev: network interface device structure
  356. *
  357. **/
  358. static void i40e_get_settings_link_up(struct i40e_hw *hw,
  359. struct ethtool_link_ksettings *cmd,
  360. struct net_device *netdev,
  361. struct i40e_pf *pf)
  362. {
  363. struct i40e_link_status *hw_link_info = &hw->phy.link_info;
  364. u32 link_speed = hw_link_info->link_speed;
  365. u32 e_advertising = 0x0;
  366. u32 e_supported = 0x0;
  367. u32 supported, advertising;
  368. ethtool_convert_link_mode_to_legacy_u32(&supported,
  369. cmd->link_modes.supported);
  370. ethtool_convert_link_mode_to_legacy_u32(&advertising,
  371. cmd->link_modes.advertising);
  372. /* Initialize supported and advertised settings based on phy settings */
  373. switch (hw_link_info->phy_type) {
  374. case I40E_PHY_TYPE_40GBASE_CR4:
  375. case I40E_PHY_TYPE_40GBASE_CR4_CU:
  376. supported = SUPPORTED_Autoneg |
  377. SUPPORTED_40000baseCR4_Full;
  378. advertising = ADVERTISED_Autoneg |
  379. ADVERTISED_40000baseCR4_Full;
  380. break;
  381. case I40E_PHY_TYPE_XLAUI:
  382. case I40E_PHY_TYPE_XLPPI:
  383. case I40E_PHY_TYPE_40GBASE_AOC:
  384. supported = SUPPORTED_40000baseCR4_Full;
  385. break;
  386. case I40E_PHY_TYPE_40GBASE_SR4:
  387. supported = SUPPORTED_40000baseSR4_Full;
  388. break;
  389. case I40E_PHY_TYPE_40GBASE_LR4:
  390. supported = SUPPORTED_40000baseLR4_Full;
  391. break;
  392. case I40E_PHY_TYPE_10GBASE_SR:
  393. case I40E_PHY_TYPE_10GBASE_LR:
  394. case I40E_PHY_TYPE_1000BASE_SX:
  395. case I40E_PHY_TYPE_1000BASE_LX:
  396. supported = SUPPORTED_10000baseT_Full;
  397. if (hw_link_info->module_type[2] &
  398. I40E_MODULE_TYPE_1000BASE_SX ||
  399. hw_link_info->module_type[2] &
  400. I40E_MODULE_TYPE_1000BASE_LX) {
  401. supported |= SUPPORTED_1000baseT_Full;
  402. if (hw_link_info->requested_speeds &
  403. I40E_LINK_SPEED_1GB)
  404. advertising |= ADVERTISED_1000baseT_Full;
  405. }
  406. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
  407. advertising |= ADVERTISED_10000baseT_Full;
  408. break;
  409. case I40E_PHY_TYPE_10GBASE_T:
  410. case I40E_PHY_TYPE_1000BASE_T:
  411. case I40E_PHY_TYPE_100BASE_TX:
  412. supported = SUPPORTED_Autoneg |
  413. SUPPORTED_10000baseT_Full |
  414. SUPPORTED_1000baseT_Full |
  415. SUPPORTED_100baseT_Full;
  416. advertising = ADVERTISED_Autoneg;
  417. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
  418. advertising |= ADVERTISED_10000baseT_Full;
  419. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
  420. advertising |= ADVERTISED_1000baseT_Full;
  421. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
  422. advertising |= ADVERTISED_100baseT_Full;
  423. break;
  424. case I40E_PHY_TYPE_1000BASE_T_OPTICAL:
  425. supported = SUPPORTED_Autoneg |
  426. SUPPORTED_1000baseT_Full;
  427. advertising = ADVERTISED_Autoneg |
  428. ADVERTISED_1000baseT_Full;
  429. break;
  430. case I40E_PHY_TYPE_10GBASE_CR1_CU:
  431. case I40E_PHY_TYPE_10GBASE_CR1:
  432. supported = SUPPORTED_Autoneg |
  433. SUPPORTED_10000baseT_Full;
  434. advertising = ADVERTISED_Autoneg |
  435. ADVERTISED_10000baseT_Full;
  436. break;
  437. case I40E_PHY_TYPE_XAUI:
  438. case I40E_PHY_TYPE_XFI:
  439. case I40E_PHY_TYPE_SFI:
  440. case I40E_PHY_TYPE_10GBASE_SFPP_CU:
  441. case I40E_PHY_TYPE_10GBASE_AOC:
  442. supported = SUPPORTED_10000baseT_Full;
  443. advertising = SUPPORTED_10000baseT_Full;
  444. break;
  445. case I40E_PHY_TYPE_SGMII:
  446. supported = SUPPORTED_Autoneg |
  447. SUPPORTED_1000baseT_Full;
  448. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
  449. advertising |= ADVERTISED_1000baseT_Full;
  450. if (pf->hw_features & I40E_HW_100M_SGMII_CAPABLE) {
  451. supported |= SUPPORTED_100baseT_Full;
  452. if (hw_link_info->requested_speeds &
  453. I40E_LINK_SPEED_100MB)
  454. advertising |= ADVERTISED_100baseT_Full;
  455. }
  456. break;
  457. case I40E_PHY_TYPE_40GBASE_KR4:
  458. case I40E_PHY_TYPE_20GBASE_KR2:
  459. case I40E_PHY_TYPE_10GBASE_KR:
  460. case I40E_PHY_TYPE_10GBASE_KX4:
  461. case I40E_PHY_TYPE_1000BASE_KX:
  462. supported |= SUPPORTED_40000baseKR4_Full |
  463. SUPPORTED_20000baseKR2_Full |
  464. SUPPORTED_10000baseKR_Full |
  465. SUPPORTED_10000baseKX4_Full |
  466. SUPPORTED_1000baseKX_Full |
  467. SUPPORTED_Autoneg;
  468. advertising |= ADVERTISED_40000baseKR4_Full |
  469. ADVERTISED_20000baseKR2_Full |
  470. ADVERTISED_10000baseKR_Full |
  471. ADVERTISED_10000baseKX4_Full |
  472. ADVERTISED_1000baseKX_Full |
  473. ADVERTISED_Autoneg;
  474. break;
  475. case I40E_PHY_TYPE_25GBASE_KR:
  476. case I40E_PHY_TYPE_25GBASE_CR:
  477. case I40E_PHY_TYPE_25GBASE_SR:
  478. case I40E_PHY_TYPE_25GBASE_LR:
  479. supported = SUPPORTED_Autoneg;
  480. advertising = ADVERTISED_Autoneg;
  481. /* TODO: add speeds when ethtool is ready to support*/
  482. break;
  483. default:
  484. /* if we got here and link is up something bad is afoot */
  485. netdev_info(netdev, "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
  486. hw_link_info->phy_type);
  487. }
  488. /* Now that we've worked out everything that could be supported by the
  489. * current PHY type, get what is supported by the NVM and them to
  490. * get what is truly supported
  491. */
  492. i40e_phy_type_to_ethtool(pf, &e_supported,
  493. &e_advertising);
  494. supported = supported & e_supported;
  495. advertising = advertising & e_advertising;
  496. /* Set speed and duplex */
  497. switch (link_speed) {
  498. case I40E_LINK_SPEED_40GB:
  499. cmd->base.speed = SPEED_40000;
  500. break;
  501. case I40E_LINK_SPEED_25GB:
  502. #ifdef SPEED_25000
  503. cmd->base.speed = SPEED_25000;
  504. #else
  505. netdev_info(netdev,
  506. "Speed is 25G, display not supported by this version of ethtool.\n");
  507. #endif
  508. break;
  509. case I40E_LINK_SPEED_20GB:
  510. cmd->base.speed = SPEED_20000;
  511. break;
  512. case I40E_LINK_SPEED_10GB:
  513. cmd->base.speed = SPEED_10000;
  514. break;
  515. case I40E_LINK_SPEED_1GB:
  516. cmd->base.speed = SPEED_1000;
  517. break;
  518. case I40E_LINK_SPEED_100MB:
  519. cmd->base.speed = SPEED_100;
  520. break;
  521. default:
  522. break;
  523. }
  524. cmd->base.duplex = DUPLEX_FULL;
  525. ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported,
  526. supported);
  527. ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.advertising,
  528. advertising);
  529. }
  530. /**
  531. * i40e_get_settings_link_down - Get the Link settings for when link is down
  532. * @hw: hw structure
  533. * @ecmd: ethtool command to fill in
  534. *
  535. * Reports link settings that can be determined when link is down
  536. **/
  537. static void i40e_get_settings_link_down(struct i40e_hw *hw,
  538. struct ethtool_link_ksettings *cmd,
  539. struct i40e_pf *pf)
  540. {
  541. u32 supported, advertising;
  542. /* link is down and the driver needs to fall back on
  543. * supported phy types to figure out what info to display
  544. */
  545. i40e_phy_type_to_ethtool(pf, &supported, &advertising);
  546. ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported,
  547. supported);
  548. ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.advertising,
  549. advertising);
  550. /* With no link speed and duplex are unknown */
  551. cmd->base.speed = SPEED_UNKNOWN;
  552. cmd->base.duplex = DUPLEX_UNKNOWN;
  553. }
  554. /**
  555. * i40e_get_settings - Get Link Speed and Duplex settings
  556. * @netdev: network interface device structure
  557. * @ecmd: ethtool command
  558. *
  559. * Reports speed/duplex settings based on media_type
  560. **/
  561. static int i40e_get_link_ksettings(struct net_device *netdev,
  562. struct ethtool_link_ksettings *cmd)
  563. {
  564. struct i40e_netdev_priv *np = netdev_priv(netdev);
  565. struct i40e_pf *pf = np->vsi->back;
  566. struct i40e_hw *hw = &pf->hw;
  567. struct i40e_link_status *hw_link_info = &hw->phy.link_info;
  568. bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
  569. u32 advertising;
  570. if (link_up)
  571. i40e_get_settings_link_up(hw, cmd, netdev, pf);
  572. else
  573. i40e_get_settings_link_down(hw, cmd, pf);
  574. /* Now set the settings that don't rely on link being up/down */
  575. /* Set autoneg settings */
  576. cmd->base.autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
  577. AUTONEG_ENABLE : AUTONEG_DISABLE);
  578. switch (hw->phy.media_type) {
  579. case I40E_MEDIA_TYPE_BACKPLANE:
  580. ethtool_link_ksettings_add_link_mode(cmd, supported,
  581. Autoneg);
  582. ethtool_link_ksettings_add_link_mode(cmd, supported,
  583. Backplane);
  584. ethtool_link_ksettings_add_link_mode(cmd, advertising,
  585. Autoneg);
  586. ethtool_link_ksettings_add_link_mode(cmd, advertising,
  587. Backplane);
  588. cmd->base.port = PORT_NONE;
  589. break;
  590. case I40E_MEDIA_TYPE_BASET:
  591. ethtool_link_ksettings_add_link_mode(cmd, supported, TP);
  592. ethtool_link_ksettings_add_link_mode(cmd, advertising, TP);
  593. cmd->base.port = PORT_TP;
  594. break;
  595. case I40E_MEDIA_TYPE_DA:
  596. case I40E_MEDIA_TYPE_CX4:
  597. ethtool_link_ksettings_add_link_mode(cmd, supported, FIBRE);
  598. ethtool_link_ksettings_add_link_mode(cmd, advertising, FIBRE);
  599. cmd->base.port = PORT_DA;
  600. break;
  601. case I40E_MEDIA_TYPE_FIBER:
  602. ethtool_link_ksettings_add_link_mode(cmd, supported, FIBRE);
  603. cmd->base.port = PORT_FIBRE;
  604. break;
  605. case I40E_MEDIA_TYPE_UNKNOWN:
  606. default:
  607. cmd->base.port = PORT_OTHER;
  608. break;
  609. }
  610. /* Set flow control settings */
  611. ethtool_link_ksettings_add_link_mode(cmd, supported, Pause);
  612. switch (hw->fc.requested_mode) {
  613. case I40E_FC_FULL:
  614. ethtool_link_ksettings_add_link_mode(cmd, advertising,
  615. Pause);
  616. break;
  617. case I40E_FC_TX_PAUSE:
  618. ethtool_link_ksettings_add_link_mode(cmd, advertising,
  619. Asym_Pause);
  620. break;
  621. case I40E_FC_RX_PAUSE:
  622. ethtool_link_ksettings_add_link_mode(cmd, advertising,
  623. Pause);
  624. ethtool_link_ksettings_add_link_mode(cmd, advertising,
  625. Asym_Pause);
  626. break;
  627. default:
  628. ethtool_convert_link_mode_to_legacy_u32(
  629. &advertising, cmd->link_modes.advertising);
  630. advertising &= ~(ADVERTISED_Pause | ADVERTISED_Asym_Pause);
  631. ethtool_convert_legacy_u32_to_link_mode(
  632. cmd->link_modes.advertising, advertising);
  633. break;
  634. }
  635. return 0;
  636. }
  637. /**
  638. * i40e_set_settings - Set Speed and Duplex
  639. * @netdev: network interface device structure
  640. * @ecmd: ethtool command
  641. *
  642. * Set speed/duplex per media_types advertised/forced
  643. **/
  644. static int i40e_set_link_ksettings(struct net_device *netdev,
  645. const struct ethtool_link_ksettings *cmd)
  646. {
  647. struct i40e_netdev_priv *np = netdev_priv(netdev);
  648. struct i40e_aq_get_phy_abilities_resp abilities;
  649. struct i40e_aq_set_phy_config config;
  650. struct i40e_pf *pf = np->vsi->back;
  651. struct i40e_vsi *vsi = np->vsi;
  652. struct i40e_hw *hw = &pf->hw;
  653. struct ethtool_link_ksettings safe_cmd;
  654. struct ethtool_link_ksettings copy_cmd;
  655. i40e_status status = 0;
  656. bool change = false;
  657. int timeout = 50;
  658. int err = 0;
  659. u32 autoneg;
  660. u32 advertise;
  661. u32 tmp;
  662. /* Changing port settings is not supported if this isn't the
  663. * port's controlling PF
  664. */
  665. if (hw->partition_id != 1) {
  666. i40e_partition_setting_complaint(pf);
  667. return -EOPNOTSUPP;
  668. }
  669. if (vsi != pf->vsi[pf->lan_vsi])
  670. return -EOPNOTSUPP;
  671. if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
  672. hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
  673. hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE &&
  674. hw->phy.media_type != I40E_MEDIA_TYPE_DA &&
  675. hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
  676. return -EOPNOTSUPP;
  677. if (hw->device_id == I40E_DEV_ID_KX_B ||
  678. hw->device_id == I40E_DEV_ID_KX_C ||
  679. hw->device_id == I40E_DEV_ID_20G_KR2 ||
  680. hw->device_id == I40E_DEV_ID_20G_KR2_A) {
  681. netdev_info(netdev, "Changing settings is not supported on backplane.\n");
  682. return -EOPNOTSUPP;
  683. }
  684. /* copy the cmd to copy_cmd to avoid modifying the origin */
  685. memcpy(&copy_cmd, cmd, sizeof(struct ethtool_link_ksettings));
  686. /* get our own copy of the bits to check against */
  687. memset(&safe_cmd, 0, sizeof(struct ethtool_link_ksettings));
  688. i40e_get_link_ksettings(netdev, &safe_cmd);
  689. /* save autoneg and speed out of cmd */
  690. autoneg = cmd->base.autoneg;
  691. ethtool_convert_link_mode_to_legacy_u32(&advertise,
  692. cmd->link_modes.advertising);
  693. /* set autoneg and speed back to what they currently are */
  694. copy_cmd.base.autoneg = safe_cmd.base.autoneg;
  695. ethtool_convert_link_mode_to_legacy_u32(
  696. &tmp, safe_cmd.link_modes.advertising);
  697. ethtool_convert_legacy_u32_to_link_mode(
  698. copy_cmd.link_modes.advertising, tmp);
  699. copy_cmd.base.cmd = safe_cmd.base.cmd;
  700. /* If copy_cmd and safe_cmd are not the same now, then they are
  701. * trying to set something that we do not support
  702. */
  703. if (memcmp(&copy_cmd, &safe_cmd, sizeof(struct ethtool_link_ksettings)))
  704. return -EOPNOTSUPP;
  705. while (test_and_set_bit(__I40E_CONFIG_BUSY, pf->state)) {
  706. timeout--;
  707. if (!timeout)
  708. return -EBUSY;
  709. usleep_range(1000, 2000);
  710. }
  711. /* Get the current phy config */
  712. status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
  713. NULL);
  714. if (status) {
  715. err = -EAGAIN;
  716. goto done;
  717. }
  718. /* Copy abilities to config in case autoneg is not
  719. * set below
  720. */
  721. memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
  722. config.abilities = abilities.abilities;
  723. /* Check autoneg */
  724. if (autoneg == AUTONEG_ENABLE) {
  725. /* If autoneg was not already enabled */
  726. if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
  727. /* If autoneg is not supported, return error */
  728. if (!ethtool_link_ksettings_test_link_mode(
  729. &safe_cmd, supported, Autoneg)) {
  730. netdev_info(netdev, "Autoneg not supported on this phy\n");
  731. err = -EINVAL;
  732. goto done;
  733. }
  734. /* Autoneg is allowed to change */
  735. config.abilities = abilities.abilities |
  736. I40E_AQ_PHY_ENABLE_AN;
  737. change = true;
  738. }
  739. } else {
  740. /* If autoneg is currently enabled */
  741. if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
  742. /* If autoneg is supported 10GBASE_T is the only PHY
  743. * that can disable it, so otherwise return error
  744. */
  745. if (ethtool_link_ksettings_test_link_mode(
  746. &safe_cmd, supported, Autoneg) &&
  747. hw->phy.link_info.phy_type !=
  748. I40E_PHY_TYPE_10GBASE_T) {
  749. netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
  750. err = -EINVAL;
  751. goto done;
  752. }
  753. /* Autoneg is allowed to change */
  754. config.abilities = abilities.abilities &
  755. ~I40E_AQ_PHY_ENABLE_AN;
  756. change = true;
  757. }
  758. }
  759. ethtool_convert_link_mode_to_legacy_u32(&tmp,
  760. safe_cmd.link_modes.supported);
  761. if (advertise & ~tmp) {
  762. err = -EINVAL;
  763. goto done;
  764. }
  765. if (advertise & ADVERTISED_100baseT_Full)
  766. config.link_speed |= I40E_LINK_SPEED_100MB;
  767. if (advertise & ADVERTISED_1000baseT_Full ||
  768. advertise & ADVERTISED_1000baseKX_Full)
  769. config.link_speed |= I40E_LINK_SPEED_1GB;
  770. if (advertise & ADVERTISED_10000baseT_Full ||
  771. advertise & ADVERTISED_10000baseKX4_Full ||
  772. advertise & ADVERTISED_10000baseKR_Full)
  773. config.link_speed |= I40E_LINK_SPEED_10GB;
  774. if (advertise & ADVERTISED_20000baseKR2_Full)
  775. config.link_speed |= I40E_LINK_SPEED_20GB;
  776. if (advertise & ADVERTISED_40000baseKR4_Full ||
  777. advertise & ADVERTISED_40000baseCR4_Full ||
  778. advertise & ADVERTISED_40000baseSR4_Full ||
  779. advertise & ADVERTISED_40000baseLR4_Full)
  780. config.link_speed |= I40E_LINK_SPEED_40GB;
  781. /* If speed didn't get set, set it to what it currently is.
  782. * This is needed because if advertise is 0 (as it is when autoneg
  783. * is disabled) then speed won't get set.
  784. */
  785. if (!config.link_speed)
  786. config.link_speed = abilities.link_speed;
  787. if (change || (abilities.link_speed != config.link_speed)) {
  788. /* copy over the rest of the abilities */
  789. config.phy_type = abilities.phy_type;
  790. config.phy_type_ext = abilities.phy_type_ext;
  791. config.eee_capability = abilities.eee_capability;
  792. config.eeer = abilities.eeer_val;
  793. config.low_power_ctrl = abilities.d3_lpan;
  794. config.fec_config = abilities.fec_cfg_curr_mod_ext_info &
  795. I40E_AQ_PHY_FEC_CONFIG_MASK;
  796. /* save the requested speeds */
  797. hw->phy.link_info.requested_speeds = config.link_speed;
  798. /* set link and auto negotiation so changes take effect */
  799. config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
  800. /* If link is up put link down */
  801. if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) {
  802. /* Tell the OS link is going down, the link will go
  803. * back up when fw says it is ready asynchronously
  804. */
  805. i40e_print_link_message(vsi, false);
  806. netif_carrier_off(netdev);
  807. netif_tx_stop_all_queues(netdev);
  808. }
  809. /* make the aq call */
  810. status = i40e_aq_set_phy_config(hw, &config, NULL);
  811. if (status) {
  812. netdev_info(netdev, "Set phy config failed, err %s aq_err %s\n",
  813. i40e_stat_str(hw, status),
  814. i40e_aq_str(hw, hw->aq.asq_last_status));
  815. err = -EAGAIN;
  816. goto done;
  817. }
  818. status = i40e_update_link_info(hw);
  819. if (status)
  820. netdev_dbg(netdev, "Updating link info failed with err %s aq_err %s\n",
  821. i40e_stat_str(hw, status),
  822. i40e_aq_str(hw, hw->aq.asq_last_status));
  823. } else {
  824. netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
  825. }
  826. done:
  827. clear_bit(__I40E_CONFIG_BUSY, pf->state);
  828. return err;
  829. }
  830. static int i40e_nway_reset(struct net_device *netdev)
  831. {
  832. /* restart autonegotiation */
  833. struct i40e_netdev_priv *np = netdev_priv(netdev);
  834. struct i40e_pf *pf = np->vsi->back;
  835. struct i40e_hw *hw = &pf->hw;
  836. bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
  837. i40e_status ret = 0;
  838. ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
  839. if (ret) {
  840. netdev_info(netdev, "link restart failed, err %s aq_err %s\n",
  841. i40e_stat_str(hw, ret),
  842. i40e_aq_str(hw, hw->aq.asq_last_status));
  843. return -EIO;
  844. }
  845. return 0;
  846. }
  847. /**
  848. * i40e_get_pauseparam - Get Flow Control status
  849. * Return tx/rx-pause status
  850. **/
  851. static void i40e_get_pauseparam(struct net_device *netdev,
  852. struct ethtool_pauseparam *pause)
  853. {
  854. struct i40e_netdev_priv *np = netdev_priv(netdev);
  855. struct i40e_pf *pf = np->vsi->back;
  856. struct i40e_hw *hw = &pf->hw;
  857. struct i40e_link_status *hw_link_info = &hw->phy.link_info;
  858. struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
  859. pause->autoneg =
  860. ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
  861. AUTONEG_ENABLE : AUTONEG_DISABLE);
  862. /* PFC enabled so report LFC as off */
  863. if (dcbx_cfg->pfc.pfcenable) {
  864. pause->rx_pause = 0;
  865. pause->tx_pause = 0;
  866. return;
  867. }
  868. if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
  869. pause->rx_pause = 1;
  870. } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
  871. pause->tx_pause = 1;
  872. } else if (hw->fc.current_mode == I40E_FC_FULL) {
  873. pause->rx_pause = 1;
  874. pause->tx_pause = 1;
  875. }
  876. }
  877. /**
  878. * i40e_set_pauseparam - Set Flow Control parameter
  879. * @netdev: network interface device structure
  880. * @pause: return tx/rx flow control status
  881. **/
  882. static int i40e_set_pauseparam(struct net_device *netdev,
  883. struct ethtool_pauseparam *pause)
  884. {
  885. struct i40e_netdev_priv *np = netdev_priv(netdev);
  886. struct i40e_pf *pf = np->vsi->back;
  887. struct i40e_vsi *vsi = np->vsi;
  888. struct i40e_hw *hw = &pf->hw;
  889. struct i40e_link_status *hw_link_info = &hw->phy.link_info;
  890. struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
  891. bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
  892. i40e_status status;
  893. u8 aq_failures;
  894. int err = 0;
  895. /* Changing the port's flow control is not supported if this isn't the
  896. * port's controlling PF
  897. */
  898. if (hw->partition_id != 1) {
  899. i40e_partition_setting_complaint(pf);
  900. return -EOPNOTSUPP;
  901. }
  902. if (vsi != pf->vsi[pf->lan_vsi])
  903. return -EOPNOTSUPP;
  904. if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
  905. AUTONEG_ENABLE : AUTONEG_DISABLE)) {
  906. netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
  907. return -EOPNOTSUPP;
  908. }
  909. /* If we have link and don't have autoneg */
  910. if (!test_bit(__I40E_DOWN, pf->state) &&
  911. !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
  912. /* Send message that it might not necessarily work*/
  913. netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
  914. }
  915. if (dcbx_cfg->pfc.pfcenable) {
  916. netdev_info(netdev,
  917. "Priority flow control enabled. Cannot set link flow control.\n");
  918. return -EOPNOTSUPP;
  919. }
  920. if (pause->rx_pause && pause->tx_pause)
  921. hw->fc.requested_mode = I40E_FC_FULL;
  922. else if (pause->rx_pause && !pause->tx_pause)
  923. hw->fc.requested_mode = I40E_FC_RX_PAUSE;
  924. else if (!pause->rx_pause && pause->tx_pause)
  925. hw->fc.requested_mode = I40E_FC_TX_PAUSE;
  926. else if (!pause->rx_pause && !pause->tx_pause)
  927. hw->fc.requested_mode = I40E_FC_NONE;
  928. else
  929. return -EINVAL;
  930. /* Tell the OS link is going down, the link will go back up when fw
  931. * says it is ready asynchronously
  932. */
  933. i40e_print_link_message(vsi, false);
  934. netif_carrier_off(netdev);
  935. netif_tx_stop_all_queues(netdev);
  936. /* Set the fc mode and only restart an if link is up*/
  937. status = i40e_set_fc(hw, &aq_failures, link_up);
  938. if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
  939. netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with err %s aq_err %s\n",
  940. i40e_stat_str(hw, status),
  941. i40e_aq_str(hw, hw->aq.asq_last_status));
  942. err = -EAGAIN;
  943. }
  944. if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
  945. netdev_info(netdev, "Set fc failed on the set_phy_config call with err %s aq_err %s\n",
  946. i40e_stat_str(hw, status),
  947. i40e_aq_str(hw, hw->aq.asq_last_status));
  948. err = -EAGAIN;
  949. }
  950. if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
  951. netdev_info(netdev, "Set fc failed on the get_link_info call with err %s aq_err %s\n",
  952. i40e_stat_str(hw, status),
  953. i40e_aq_str(hw, hw->aq.asq_last_status));
  954. err = -EAGAIN;
  955. }
  956. if (!test_bit(__I40E_DOWN, pf->state)) {
  957. /* Give it a little more time to try to come back */
  958. msleep(75);
  959. if (!test_bit(__I40E_DOWN, pf->state))
  960. return i40e_nway_reset(netdev);
  961. }
  962. return err;
  963. }
  964. static u32 i40e_get_msglevel(struct net_device *netdev)
  965. {
  966. struct i40e_netdev_priv *np = netdev_priv(netdev);
  967. struct i40e_pf *pf = np->vsi->back;
  968. u32 debug_mask = pf->hw.debug_mask;
  969. if (debug_mask)
  970. netdev_info(netdev, "i40e debug_mask: 0x%08X\n", debug_mask);
  971. return pf->msg_enable;
  972. }
  973. static void i40e_set_msglevel(struct net_device *netdev, u32 data)
  974. {
  975. struct i40e_netdev_priv *np = netdev_priv(netdev);
  976. struct i40e_pf *pf = np->vsi->back;
  977. if (I40E_DEBUG_USER & data)
  978. pf->hw.debug_mask = data;
  979. else
  980. pf->msg_enable = data;
  981. }
  982. static int i40e_get_regs_len(struct net_device *netdev)
  983. {
  984. int reg_count = 0;
  985. int i;
  986. for (i = 0; i40e_reg_list[i].offset != 0; i++)
  987. reg_count += i40e_reg_list[i].elements;
  988. return reg_count * sizeof(u32);
  989. }
  990. static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
  991. void *p)
  992. {
  993. struct i40e_netdev_priv *np = netdev_priv(netdev);
  994. struct i40e_pf *pf = np->vsi->back;
  995. struct i40e_hw *hw = &pf->hw;
  996. u32 *reg_buf = p;
  997. unsigned int i, j, ri;
  998. u32 reg;
  999. /* Tell ethtool which driver-version-specific regs output we have.
  1000. *
  1001. * At some point, if we have ethtool doing special formatting of
  1002. * this data, it will rely on this version number to know how to
  1003. * interpret things. Hence, this needs to be updated if/when the
  1004. * diags register table is changed.
  1005. */
  1006. regs->version = 1;
  1007. /* loop through the diags reg table for what to print */
  1008. ri = 0;
  1009. for (i = 0; i40e_reg_list[i].offset != 0; i++) {
  1010. for (j = 0; j < i40e_reg_list[i].elements; j++) {
  1011. reg = i40e_reg_list[i].offset
  1012. + (j * i40e_reg_list[i].stride);
  1013. reg_buf[ri++] = rd32(hw, reg);
  1014. }
  1015. }
  1016. }
  1017. static int i40e_get_eeprom(struct net_device *netdev,
  1018. struct ethtool_eeprom *eeprom, u8 *bytes)
  1019. {
  1020. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1021. struct i40e_hw *hw = &np->vsi->back->hw;
  1022. struct i40e_pf *pf = np->vsi->back;
  1023. int ret_val = 0, len, offset;
  1024. u8 *eeprom_buff;
  1025. u16 i, sectors;
  1026. bool last;
  1027. u32 magic;
  1028. #define I40E_NVM_SECTOR_SIZE 4096
  1029. if (eeprom->len == 0)
  1030. return -EINVAL;
  1031. /* check for NVMUpdate access method */
  1032. magic = hw->vendor_id | (hw->device_id << 16);
  1033. if (eeprom->magic && eeprom->magic != magic) {
  1034. struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom;
  1035. int errno = 0;
  1036. /* make sure it is the right magic for NVMUpdate */
  1037. if ((eeprom->magic >> 16) != hw->device_id)
  1038. errno = -EINVAL;
  1039. else if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
  1040. test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
  1041. errno = -EBUSY;
  1042. else
  1043. ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
  1044. if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM))
  1045. dev_info(&pf->pdev->dev,
  1046. "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
  1047. ret_val, hw->aq.asq_last_status, errno,
  1048. (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
  1049. cmd->offset, cmd->data_size);
  1050. return errno;
  1051. }
  1052. /* normal ethtool get_eeprom support */
  1053. eeprom->magic = hw->vendor_id | (hw->device_id << 16);
  1054. eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
  1055. if (!eeprom_buff)
  1056. return -ENOMEM;
  1057. ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
  1058. if (ret_val) {
  1059. dev_info(&pf->pdev->dev,
  1060. "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
  1061. ret_val, hw->aq.asq_last_status);
  1062. goto free_buff;
  1063. }
  1064. sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
  1065. sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
  1066. len = I40E_NVM_SECTOR_SIZE;
  1067. last = false;
  1068. for (i = 0; i < sectors; i++) {
  1069. if (i == (sectors - 1)) {
  1070. len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
  1071. last = true;
  1072. }
  1073. offset = eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
  1074. ret_val = i40e_aq_read_nvm(hw, 0x0, offset, len,
  1075. (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
  1076. last, NULL);
  1077. if (ret_val && hw->aq.asq_last_status == I40E_AQ_RC_EPERM) {
  1078. dev_info(&pf->pdev->dev,
  1079. "read NVM failed, invalid offset 0x%x\n",
  1080. offset);
  1081. break;
  1082. } else if (ret_val &&
  1083. hw->aq.asq_last_status == I40E_AQ_RC_EACCES) {
  1084. dev_info(&pf->pdev->dev,
  1085. "read NVM failed, access, offset 0x%x\n",
  1086. offset);
  1087. break;
  1088. } else if (ret_val) {
  1089. dev_info(&pf->pdev->dev,
  1090. "read NVM failed offset %d err=%d status=0x%x\n",
  1091. offset, ret_val, hw->aq.asq_last_status);
  1092. break;
  1093. }
  1094. }
  1095. i40e_release_nvm(hw);
  1096. memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
  1097. free_buff:
  1098. kfree(eeprom_buff);
  1099. return ret_val;
  1100. }
  1101. static int i40e_get_eeprom_len(struct net_device *netdev)
  1102. {
  1103. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1104. struct i40e_hw *hw = &np->vsi->back->hw;
  1105. u32 val;
  1106. #define X722_EEPROM_SCOPE_LIMIT 0x5B9FFF
  1107. if (hw->mac.type == I40E_MAC_X722) {
  1108. val = X722_EEPROM_SCOPE_LIMIT + 1;
  1109. return val;
  1110. }
  1111. val = (rd32(hw, I40E_GLPCI_LBARCTRL)
  1112. & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
  1113. >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
  1114. /* register returns value in power of 2, 64Kbyte chunks. */
  1115. val = (64 * 1024) * BIT(val);
  1116. return val;
  1117. }
  1118. static int i40e_set_eeprom(struct net_device *netdev,
  1119. struct ethtool_eeprom *eeprom, u8 *bytes)
  1120. {
  1121. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1122. struct i40e_hw *hw = &np->vsi->back->hw;
  1123. struct i40e_pf *pf = np->vsi->back;
  1124. struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom;
  1125. int ret_val = 0;
  1126. int errno = 0;
  1127. u32 magic;
  1128. /* normal ethtool set_eeprom is not supported */
  1129. magic = hw->vendor_id | (hw->device_id << 16);
  1130. if (eeprom->magic == magic)
  1131. errno = -EOPNOTSUPP;
  1132. /* check for NVMUpdate access method */
  1133. else if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
  1134. errno = -EINVAL;
  1135. else if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
  1136. test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
  1137. errno = -EBUSY;
  1138. else
  1139. ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
  1140. if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM))
  1141. dev_info(&pf->pdev->dev,
  1142. "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
  1143. ret_val, hw->aq.asq_last_status, errno,
  1144. (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
  1145. cmd->offset, cmd->data_size);
  1146. return errno;
  1147. }
  1148. static void i40e_get_drvinfo(struct net_device *netdev,
  1149. struct ethtool_drvinfo *drvinfo)
  1150. {
  1151. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1152. struct i40e_vsi *vsi = np->vsi;
  1153. struct i40e_pf *pf = vsi->back;
  1154. strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
  1155. strlcpy(drvinfo->version, i40e_driver_version_str,
  1156. sizeof(drvinfo->version));
  1157. strlcpy(drvinfo->fw_version, i40e_nvm_version_str(&pf->hw),
  1158. sizeof(drvinfo->fw_version));
  1159. strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
  1160. sizeof(drvinfo->bus_info));
  1161. drvinfo->n_priv_flags = I40E_PRIV_FLAGS_STR_LEN;
  1162. if (pf->hw.pf_id == 0)
  1163. drvinfo->n_priv_flags += I40E_GL_PRIV_FLAGS_STR_LEN;
  1164. }
  1165. static void i40e_get_ringparam(struct net_device *netdev,
  1166. struct ethtool_ringparam *ring)
  1167. {
  1168. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1169. struct i40e_pf *pf = np->vsi->back;
  1170. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  1171. ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
  1172. ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
  1173. ring->rx_mini_max_pending = 0;
  1174. ring->rx_jumbo_max_pending = 0;
  1175. ring->rx_pending = vsi->rx_rings[0]->count;
  1176. ring->tx_pending = vsi->tx_rings[0]->count;
  1177. ring->rx_mini_pending = 0;
  1178. ring->rx_jumbo_pending = 0;
  1179. }
  1180. static bool i40e_active_tx_ring_index(struct i40e_vsi *vsi, u16 index)
  1181. {
  1182. if (i40e_enabled_xdp_vsi(vsi)) {
  1183. return index < vsi->num_queue_pairs ||
  1184. (index >= vsi->alloc_queue_pairs &&
  1185. index < vsi->alloc_queue_pairs + vsi->num_queue_pairs);
  1186. }
  1187. return index < vsi->num_queue_pairs;
  1188. }
  1189. static int i40e_set_ringparam(struct net_device *netdev,
  1190. struct ethtool_ringparam *ring)
  1191. {
  1192. struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
  1193. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1194. struct i40e_hw *hw = &np->vsi->back->hw;
  1195. struct i40e_vsi *vsi = np->vsi;
  1196. struct i40e_pf *pf = vsi->back;
  1197. u32 new_rx_count, new_tx_count;
  1198. u16 tx_alloc_queue_pairs;
  1199. int timeout = 50;
  1200. int i, err = 0;
  1201. if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
  1202. return -EINVAL;
  1203. if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
  1204. ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
  1205. ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
  1206. ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
  1207. netdev_info(netdev,
  1208. "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
  1209. ring->tx_pending, ring->rx_pending,
  1210. I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
  1211. return -EINVAL;
  1212. }
  1213. new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
  1214. new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
  1215. /* if nothing to do return success */
  1216. if ((new_tx_count == vsi->tx_rings[0]->count) &&
  1217. (new_rx_count == vsi->rx_rings[0]->count))
  1218. return 0;
  1219. while (test_and_set_bit(__I40E_CONFIG_BUSY, pf->state)) {
  1220. timeout--;
  1221. if (!timeout)
  1222. return -EBUSY;
  1223. usleep_range(1000, 2000);
  1224. }
  1225. if (!netif_running(vsi->netdev)) {
  1226. /* simple case - set for the next time the netdev is started */
  1227. for (i = 0; i < vsi->num_queue_pairs; i++) {
  1228. vsi->tx_rings[i]->count = new_tx_count;
  1229. vsi->rx_rings[i]->count = new_rx_count;
  1230. if (i40e_enabled_xdp_vsi(vsi))
  1231. vsi->xdp_rings[i]->count = new_tx_count;
  1232. }
  1233. goto done;
  1234. }
  1235. /* We can't just free everything and then setup again,
  1236. * because the ISRs in MSI-X mode get passed pointers
  1237. * to the Tx and Rx ring structs.
  1238. */
  1239. /* alloc updated Tx and XDP Tx resources */
  1240. tx_alloc_queue_pairs = vsi->alloc_queue_pairs *
  1241. (i40e_enabled_xdp_vsi(vsi) ? 2 : 1);
  1242. if (new_tx_count != vsi->tx_rings[0]->count) {
  1243. netdev_info(netdev,
  1244. "Changing Tx descriptor count from %d to %d.\n",
  1245. vsi->tx_rings[0]->count, new_tx_count);
  1246. tx_rings = kcalloc(tx_alloc_queue_pairs,
  1247. sizeof(struct i40e_ring), GFP_KERNEL);
  1248. if (!tx_rings) {
  1249. err = -ENOMEM;
  1250. goto done;
  1251. }
  1252. for (i = 0; i < tx_alloc_queue_pairs; i++) {
  1253. if (!i40e_active_tx_ring_index(vsi, i))
  1254. continue;
  1255. tx_rings[i] = *vsi->tx_rings[i];
  1256. tx_rings[i].count = new_tx_count;
  1257. /* the desc and bi pointers will be reallocated in the
  1258. * setup call
  1259. */
  1260. tx_rings[i].desc = NULL;
  1261. tx_rings[i].rx_bi = NULL;
  1262. err = i40e_setup_tx_descriptors(&tx_rings[i]);
  1263. if (err) {
  1264. while (i) {
  1265. i--;
  1266. if (!i40e_active_tx_ring_index(vsi, i))
  1267. continue;
  1268. i40e_free_tx_resources(&tx_rings[i]);
  1269. }
  1270. kfree(tx_rings);
  1271. tx_rings = NULL;
  1272. goto done;
  1273. }
  1274. }
  1275. }
  1276. /* alloc updated Rx resources */
  1277. if (new_rx_count != vsi->rx_rings[0]->count) {
  1278. netdev_info(netdev,
  1279. "Changing Rx descriptor count from %d to %d\n",
  1280. vsi->rx_rings[0]->count, new_rx_count);
  1281. rx_rings = kcalloc(vsi->alloc_queue_pairs,
  1282. sizeof(struct i40e_ring), GFP_KERNEL);
  1283. if (!rx_rings) {
  1284. err = -ENOMEM;
  1285. goto free_tx;
  1286. }
  1287. for (i = 0; i < vsi->num_queue_pairs; i++) {
  1288. struct i40e_ring *ring;
  1289. u16 unused;
  1290. /* clone ring and setup updated count */
  1291. rx_rings[i] = *vsi->rx_rings[i];
  1292. rx_rings[i].count = new_rx_count;
  1293. /* the desc and bi pointers will be reallocated in the
  1294. * setup call
  1295. */
  1296. rx_rings[i].desc = NULL;
  1297. rx_rings[i].rx_bi = NULL;
  1298. /* this is to allow wr32 to have something to write to
  1299. * during early allocation of Rx buffers
  1300. */
  1301. rx_rings[i].tail = hw->hw_addr + I40E_PRTGEN_STATUS;
  1302. err = i40e_setup_rx_descriptors(&rx_rings[i]);
  1303. if (err)
  1304. goto rx_unwind;
  1305. /* now allocate the Rx buffers to make sure the OS
  1306. * has enough memory, any failure here means abort
  1307. */
  1308. ring = &rx_rings[i];
  1309. unused = I40E_DESC_UNUSED(ring);
  1310. err = i40e_alloc_rx_buffers(ring, unused);
  1311. rx_unwind:
  1312. if (err) {
  1313. do {
  1314. i40e_free_rx_resources(&rx_rings[i]);
  1315. } while (i--);
  1316. kfree(rx_rings);
  1317. rx_rings = NULL;
  1318. goto free_tx;
  1319. }
  1320. }
  1321. }
  1322. /* Bring interface down, copy in the new ring info,
  1323. * then restore the interface
  1324. */
  1325. i40e_down(vsi);
  1326. if (tx_rings) {
  1327. for (i = 0; i < tx_alloc_queue_pairs; i++) {
  1328. if (i40e_active_tx_ring_index(vsi, i)) {
  1329. i40e_free_tx_resources(vsi->tx_rings[i]);
  1330. *vsi->tx_rings[i] = tx_rings[i];
  1331. }
  1332. }
  1333. kfree(tx_rings);
  1334. tx_rings = NULL;
  1335. }
  1336. if (rx_rings) {
  1337. for (i = 0; i < vsi->num_queue_pairs; i++) {
  1338. i40e_free_rx_resources(vsi->rx_rings[i]);
  1339. /* get the real tail offset */
  1340. rx_rings[i].tail = vsi->rx_rings[i]->tail;
  1341. /* this is to fake out the allocation routine
  1342. * into thinking it has to realloc everything
  1343. * but the recycling logic will let us re-use
  1344. * the buffers allocated above
  1345. */
  1346. rx_rings[i].next_to_use = 0;
  1347. rx_rings[i].next_to_clean = 0;
  1348. rx_rings[i].next_to_alloc = 0;
  1349. /* do a struct copy */
  1350. *vsi->rx_rings[i] = rx_rings[i];
  1351. }
  1352. kfree(rx_rings);
  1353. rx_rings = NULL;
  1354. }
  1355. i40e_up(vsi);
  1356. free_tx:
  1357. /* error cleanup if the Rx allocations failed after getting Tx */
  1358. if (tx_rings) {
  1359. for (i = 0; i < tx_alloc_queue_pairs; i++) {
  1360. if (i40e_active_tx_ring_index(vsi, i))
  1361. i40e_free_tx_resources(vsi->tx_rings[i]);
  1362. }
  1363. kfree(tx_rings);
  1364. tx_rings = NULL;
  1365. }
  1366. done:
  1367. clear_bit(__I40E_CONFIG_BUSY, pf->state);
  1368. return err;
  1369. }
  1370. static int i40e_get_sset_count(struct net_device *netdev, int sset)
  1371. {
  1372. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1373. struct i40e_vsi *vsi = np->vsi;
  1374. struct i40e_pf *pf = vsi->back;
  1375. switch (sset) {
  1376. case ETH_SS_TEST:
  1377. return I40E_TEST_LEN;
  1378. case ETH_SS_STATS:
  1379. if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1) {
  1380. int len = I40E_PF_STATS_LEN(netdev);
  1381. if ((pf->lan_veb != I40E_NO_VEB) &&
  1382. (pf->flags & I40E_FLAG_VEB_STATS_ENABLED))
  1383. len += I40E_VEB_STATS_TOTAL;
  1384. return len;
  1385. } else {
  1386. return I40E_VSI_STATS_LEN(netdev);
  1387. }
  1388. case ETH_SS_PRIV_FLAGS:
  1389. return I40E_PRIV_FLAGS_STR_LEN +
  1390. (pf->hw.pf_id == 0 ? I40E_GL_PRIV_FLAGS_STR_LEN : 0);
  1391. default:
  1392. return -EOPNOTSUPP;
  1393. }
  1394. }
  1395. static void i40e_get_ethtool_stats(struct net_device *netdev,
  1396. struct ethtool_stats *stats, u64 *data)
  1397. {
  1398. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1399. struct i40e_ring *tx_ring, *rx_ring;
  1400. struct i40e_vsi *vsi = np->vsi;
  1401. struct i40e_pf *pf = vsi->back;
  1402. unsigned int j;
  1403. int i = 0;
  1404. char *p;
  1405. struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
  1406. unsigned int start;
  1407. i40e_update_stats(vsi);
  1408. for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
  1409. p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
  1410. data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
  1411. sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
  1412. }
  1413. for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
  1414. p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
  1415. data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
  1416. sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
  1417. }
  1418. rcu_read_lock();
  1419. for (j = 0; j < vsi->num_queue_pairs; j++) {
  1420. tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
  1421. if (!tx_ring)
  1422. continue;
  1423. /* process Tx ring statistics */
  1424. do {
  1425. start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
  1426. data[i] = tx_ring->stats.packets;
  1427. data[i + 1] = tx_ring->stats.bytes;
  1428. } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
  1429. i += 2;
  1430. /* Rx ring is the 2nd half of the queue pair */
  1431. rx_ring = &tx_ring[1];
  1432. do {
  1433. start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
  1434. data[i] = rx_ring->stats.packets;
  1435. data[i + 1] = rx_ring->stats.bytes;
  1436. } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
  1437. i += 2;
  1438. }
  1439. rcu_read_unlock();
  1440. if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
  1441. return;
  1442. if ((pf->lan_veb != I40E_NO_VEB) &&
  1443. (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
  1444. struct i40e_veb *veb = pf->veb[pf->lan_veb];
  1445. for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
  1446. p = (char *)veb;
  1447. p += i40e_gstrings_veb_stats[j].stat_offset;
  1448. data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
  1449. sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
  1450. }
  1451. for (j = 0; j < I40E_MAX_TRAFFIC_CLASS; j++) {
  1452. data[i++] = veb->tc_stats.tc_tx_packets[j];
  1453. data[i++] = veb->tc_stats.tc_tx_bytes[j];
  1454. data[i++] = veb->tc_stats.tc_rx_packets[j];
  1455. data[i++] = veb->tc_stats.tc_rx_bytes[j];
  1456. }
  1457. }
  1458. for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
  1459. p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
  1460. data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
  1461. sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
  1462. }
  1463. for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
  1464. data[i++] = pf->stats.priority_xon_tx[j];
  1465. data[i++] = pf->stats.priority_xoff_tx[j];
  1466. }
  1467. for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
  1468. data[i++] = pf->stats.priority_xon_rx[j];
  1469. data[i++] = pf->stats.priority_xoff_rx[j];
  1470. }
  1471. for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
  1472. data[i++] = pf->stats.priority_xon_2_xoff[j];
  1473. }
  1474. static void i40e_get_strings(struct net_device *netdev, u32 stringset,
  1475. u8 *data)
  1476. {
  1477. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1478. struct i40e_vsi *vsi = np->vsi;
  1479. struct i40e_pf *pf = vsi->back;
  1480. char *p = (char *)data;
  1481. unsigned int i;
  1482. switch (stringset) {
  1483. case ETH_SS_TEST:
  1484. memcpy(data, i40e_gstrings_test,
  1485. I40E_TEST_LEN * ETH_GSTRING_LEN);
  1486. break;
  1487. case ETH_SS_STATS:
  1488. for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
  1489. snprintf(p, ETH_GSTRING_LEN, "%s",
  1490. i40e_gstrings_net_stats[i].stat_string);
  1491. p += ETH_GSTRING_LEN;
  1492. }
  1493. for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
  1494. snprintf(p, ETH_GSTRING_LEN, "%s",
  1495. i40e_gstrings_misc_stats[i].stat_string);
  1496. p += ETH_GSTRING_LEN;
  1497. }
  1498. for (i = 0; i < vsi->num_queue_pairs; i++) {
  1499. snprintf(p, ETH_GSTRING_LEN, "tx-%d.tx_packets", i);
  1500. p += ETH_GSTRING_LEN;
  1501. snprintf(p, ETH_GSTRING_LEN, "tx-%d.tx_bytes", i);
  1502. p += ETH_GSTRING_LEN;
  1503. snprintf(p, ETH_GSTRING_LEN, "rx-%d.rx_packets", i);
  1504. p += ETH_GSTRING_LEN;
  1505. snprintf(p, ETH_GSTRING_LEN, "rx-%d.rx_bytes", i);
  1506. p += ETH_GSTRING_LEN;
  1507. }
  1508. if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
  1509. return;
  1510. if ((pf->lan_veb != I40E_NO_VEB) &&
  1511. (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
  1512. for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
  1513. snprintf(p, ETH_GSTRING_LEN, "veb.%s",
  1514. i40e_gstrings_veb_stats[i].stat_string);
  1515. p += ETH_GSTRING_LEN;
  1516. }
  1517. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  1518. snprintf(p, ETH_GSTRING_LEN,
  1519. "veb.tc_%d_tx_packets", i);
  1520. p += ETH_GSTRING_LEN;
  1521. snprintf(p, ETH_GSTRING_LEN,
  1522. "veb.tc_%d_tx_bytes", i);
  1523. p += ETH_GSTRING_LEN;
  1524. snprintf(p, ETH_GSTRING_LEN,
  1525. "veb.tc_%d_rx_packets", i);
  1526. p += ETH_GSTRING_LEN;
  1527. snprintf(p, ETH_GSTRING_LEN,
  1528. "veb.tc_%d_rx_bytes", i);
  1529. p += ETH_GSTRING_LEN;
  1530. }
  1531. }
  1532. for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
  1533. snprintf(p, ETH_GSTRING_LEN, "port.%s",
  1534. i40e_gstrings_stats[i].stat_string);
  1535. p += ETH_GSTRING_LEN;
  1536. }
  1537. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
  1538. snprintf(p, ETH_GSTRING_LEN,
  1539. "port.tx_priority_%d_xon", i);
  1540. p += ETH_GSTRING_LEN;
  1541. snprintf(p, ETH_GSTRING_LEN,
  1542. "port.tx_priority_%d_xoff", i);
  1543. p += ETH_GSTRING_LEN;
  1544. }
  1545. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
  1546. snprintf(p, ETH_GSTRING_LEN,
  1547. "port.rx_priority_%d_xon", i);
  1548. p += ETH_GSTRING_LEN;
  1549. snprintf(p, ETH_GSTRING_LEN,
  1550. "port.rx_priority_%d_xoff", i);
  1551. p += ETH_GSTRING_LEN;
  1552. }
  1553. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
  1554. snprintf(p, ETH_GSTRING_LEN,
  1555. "port.rx_priority_%d_xon_2_xoff", i);
  1556. p += ETH_GSTRING_LEN;
  1557. }
  1558. /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
  1559. break;
  1560. case ETH_SS_PRIV_FLAGS:
  1561. for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
  1562. snprintf(p, ETH_GSTRING_LEN, "%s",
  1563. i40e_gstrings_priv_flags[i].flag_string);
  1564. p += ETH_GSTRING_LEN;
  1565. }
  1566. if (pf->hw.pf_id != 0)
  1567. break;
  1568. for (i = 0; i < I40E_GL_PRIV_FLAGS_STR_LEN; i++) {
  1569. snprintf(p, ETH_GSTRING_LEN, "%s",
  1570. i40e_gl_gstrings_priv_flags[i].flag_string);
  1571. p += ETH_GSTRING_LEN;
  1572. }
  1573. break;
  1574. default:
  1575. break;
  1576. }
  1577. }
  1578. static int i40e_get_ts_info(struct net_device *dev,
  1579. struct ethtool_ts_info *info)
  1580. {
  1581. struct i40e_pf *pf = i40e_netdev_to_pf(dev);
  1582. /* only report HW timestamping if PTP is enabled */
  1583. if (!(pf->flags & I40E_FLAG_PTP))
  1584. return ethtool_op_get_ts_info(dev, info);
  1585. info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
  1586. SOF_TIMESTAMPING_RX_SOFTWARE |
  1587. SOF_TIMESTAMPING_SOFTWARE |
  1588. SOF_TIMESTAMPING_TX_HARDWARE |
  1589. SOF_TIMESTAMPING_RX_HARDWARE |
  1590. SOF_TIMESTAMPING_RAW_HARDWARE;
  1591. if (pf->ptp_clock)
  1592. info->phc_index = ptp_clock_index(pf->ptp_clock);
  1593. else
  1594. info->phc_index = -1;
  1595. info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
  1596. info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
  1597. BIT(HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
  1598. BIT(HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
  1599. BIT(HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ);
  1600. if (pf->hw_features & I40E_HW_PTP_L4_CAPABLE)
  1601. info->rx_filters |= BIT(HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
  1602. BIT(HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
  1603. BIT(HWTSTAMP_FILTER_PTP_V2_EVENT) |
  1604. BIT(HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
  1605. BIT(HWTSTAMP_FILTER_PTP_V2_SYNC) |
  1606. BIT(HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
  1607. BIT(HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
  1608. BIT(HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ);
  1609. return 0;
  1610. }
  1611. static int i40e_link_test(struct net_device *netdev, u64 *data)
  1612. {
  1613. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1614. struct i40e_pf *pf = np->vsi->back;
  1615. i40e_status status;
  1616. bool link_up = false;
  1617. netif_info(pf, hw, netdev, "link test\n");
  1618. status = i40e_get_link_status(&pf->hw, &link_up);
  1619. if (status) {
  1620. netif_err(pf, drv, netdev, "link query timed out, please retry test\n");
  1621. *data = 1;
  1622. return *data;
  1623. }
  1624. if (link_up)
  1625. *data = 0;
  1626. else
  1627. *data = 1;
  1628. return *data;
  1629. }
  1630. static int i40e_reg_test(struct net_device *netdev, u64 *data)
  1631. {
  1632. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1633. struct i40e_pf *pf = np->vsi->back;
  1634. netif_info(pf, hw, netdev, "register test\n");
  1635. *data = i40e_diag_reg_test(&pf->hw);
  1636. return *data;
  1637. }
  1638. static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
  1639. {
  1640. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1641. struct i40e_pf *pf = np->vsi->back;
  1642. netif_info(pf, hw, netdev, "eeprom test\n");
  1643. *data = i40e_diag_eeprom_test(&pf->hw);
  1644. /* forcebly clear the NVM Update state machine */
  1645. pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT;
  1646. return *data;
  1647. }
  1648. static int i40e_intr_test(struct net_device *netdev, u64 *data)
  1649. {
  1650. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1651. struct i40e_pf *pf = np->vsi->back;
  1652. u16 swc_old = pf->sw_int_count;
  1653. netif_info(pf, hw, netdev, "interrupt test\n");
  1654. wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
  1655. (I40E_PFINT_DYN_CTL0_INTENA_MASK |
  1656. I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK |
  1657. I40E_PFINT_DYN_CTL0_ITR_INDX_MASK |
  1658. I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK |
  1659. I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK));
  1660. usleep_range(1000, 2000);
  1661. *data = (swc_old == pf->sw_int_count);
  1662. return *data;
  1663. }
  1664. static inline bool i40e_active_vfs(struct i40e_pf *pf)
  1665. {
  1666. struct i40e_vf *vfs = pf->vf;
  1667. int i;
  1668. for (i = 0; i < pf->num_alloc_vfs; i++)
  1669. if (test_bit(I40E_VF_STATE_ACTIVE, &vfs[i].vf_states))
  1670. return true;
  1671. return false;
  1672. }
  1673. static inline bool i40e_active_vmdqs(struct i40e_pf *pf)
  1674. {
  1675. return !!i40e_find_vsi_by_type(pf, I40E_VSI_VMDQ2);
  1676. }
  1677. static void i40e_diag_test(struct net_device *netdev,
  1678. struct ethtool_test *eth_test, u64 *data)
  1679. {
  1680. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1681. bool if_running = netif_running(netdev);
  1682. struct i40e_pf *pf = np->vsi->back;
  1683. if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
  1684. /* Offline tests */
  1685. netif_info(pf, drv, netdev, "offline testing starting\n");
  1686. set_bit(__I40E_TESTING, pf->state);
  1687. if (i40e_active_vfs(pf) || i40e_active_vmdqs(pf)) {
  1688. dev_warn(&pf->pdev->dev,
  1689. "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
  1690. data[I40E_ETH_TEST_REG] = 1;
  1691. data[I40E_ETH_TEST_EEPROM] = 1;
  1692. data[I40E_ETH_TEST_INTR] = 1;
  1693. data[I40E_ETH_TEST_LINK] = 1;
  1694. eth_test->flags |= ETH_TEST_FL_FAILED;
  1695. clear_bit(__I40E_TESTING, pf->state);
  1696. goto skip_ol_tests;
  1697. }
  1698. /* If the device is online then take it offline */
  1699. if (if_running)
  1700. /* indicate we're in test mode */
  1701. i40e_close(netdev);
  1702. else
  1703. /* This reset does not affect link - if it is
  1704. * changed to a type of reset that does affect
  1705. * link then the following link test would have
  1706. * to be moved to before the reset
  1707. */
  1708. i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED), true);
  1709. if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
  1710. eth_test->flags |= ETH_TEST_FL_FAILED;
  1711. if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
  1712. eth_test->flags |= ETH_TEST_FL_FAILED;
  1713. if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
  1714. eth_test->flags |= ETH_TEST_FL_FAILED;
  1715. /* run reg test last, a reset is required after it */
  1716. if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
  1717. eth_test->flags |= ETH_TEST_FL_FAILED;
  1718. clear_bit(__I40E_TESTING, pf->state);
  1719. i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED), true);
  1720. if (if_running)
  1721. i40e_open(netdev);
  1722. } else {
  1723. /* Online tests */
  1724. netif_info(pf, drv, netdev, "online testing starting\n");
  1725. if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
  1726. eth_test->flags |= ETH_TEST_FL_FAILED;
  1727. /* Offline only tests, not run in online; pass by default */
  1728. data[I40E_ETH_TEST_REG] = 0;
  1729. data[I40E_ETH_TEST_EEPROM] = 0;
  1730. data[I40E_ETH_TEST_INTR] = 0;
  1731. }
  1732. skip_ol_tests:
  1733. netif_info(pf, drv, netdev, "testing finished\n");
  1734. }
  1735. static void i40e_get_wol(struct net_device *netdev,
  1736. struct ethtool_wolinfo *wol)
  1737. {
  1738. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1739. struct i40e_pf *pf = np->vsi->back;
  1740. struct i40e_hw *hw = &pf->hw;
  1741. u16 wol_nvm_bits;
  1742. /* NVM bit on means WoL disabled for the port */
  1743. i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
  1744. if ((BIT(hw->port) & wol_nvm_bits) || (hw->partition_id != 1)) {
  1745. wol->supported = 0;
  1746. wol->wolopts = 0;
  1747. } else {
  1748. wol->supported = WAKE_MAGIC;
  1749. wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
  1750. }
  1751. }
  1752. /**
  1753. * i40e_set_wol - set the WakeOnLAN configuration
  1754. * @netdev: the netdev in question
  1755. * @wol: the ethtool WoL setting data
  1756. **/
  1757. static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
  1758. {
  1759. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1760. struct i40e_pf *pf = np->vsi->back;
  1761. struct i40e_vsi *vsi = np->vsi;
  1762. struct i40e_hw *hw = &pf->hw;
  1763. u16 wol_nvm_bits;
  1764. /* WoL not supported if this isn't the controlling PF on the port */
  1765. if (hw->partition_id != 1) {
  1766. i40e_partition_setting_complaint(pf);
  1767. return -EOPNOTSUPP;
  1768. }
  1769. if (vsi != pf->vsi[pf->lan_vsi])
  1770. return -EOPNOTSUPP;
  1771. /* NVM bit on means WoL disabled for the port */
  1772. i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
  1773. if (BIT(hw->port) & wol_nvm_bits)
  1774. return -EOPNOTSUPP;
  1775. /* only magic packet is supported */
  1776. if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
  1777. return -EOPNOTSUPP;
  1778. /* is this a new value? */
  1779. if (pf->wol_en != !!wol->wolopts) {
  1780. pf->wol_en = !!wol->wolopts;
  1781. device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
  1782. }
  1783. return 0;
  1784. }
  1785. static int i40e_set_phys_id(struct net_device *netdev,
  1786. enum ethtool_phys_id_state state)
  1787. {
  1788. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1789. i40e_status ret = 0;
  1790. struct i40e_pf *pf = np->vsi->back;
  1791. struct i40e_hw *hw = &pf->hw;
  1792. int blink_freq = 2;
  1793. u16 temp_status;
  1794. switch (state) {
  1795. case ETHTOOL_ID_ACTIVE:
  1796. if (!(pf->hw_features & I40E_HW_PHY_CONTROLS_LEDS)) {
  1797. pf->led_status = i40e_led_get(hw);
  1798. } else {
  1799. i40e_aq_set_phy_debug(hw, I40E_PHY_DEBUG_ALL, NULL);
  1800. ret = i40e_led_get_phy(hw, &temp_status,
  1801. &pf->phy_led_val);
  1802. pf->led_status = temp_status;
  1803. }
  1804. return blink_freq;
  1805. case ETHTOOL_ID_ON:
  1806. if (!(pf->hw_features & I40E_HW_PHY_CONTROLS_LEDS))
  1807. i40e_led_set(hw, 0xf, false);
  1808. else
  1809. ret = i40e_led_set_phy(hw, true, pf->led_status, 0);
  1810. break;
  1811. case ETHTOOL_ID_OFF:
  1812. if (!(pf->hw_features & I40E_HW_PHY_CONTROLS_LEDS))
  1813. i40e_led_set(hw, 0x0, false);
  1814. else
  1815. ret = i40e_led_set_phy(hw, false, pf->led_status, 0);
  1816. break;
  1817. case ETHTOOL_ID_INACTIVE:
  1818. if (!(pf->hw_features & I40E_HW_PHY_CONTROLS_LEDS)) {
  1819. i40e_led_set(hw, pf->led_status, false);
  1820. } else {
  1821. ret = i40e_led_set_phy(hw, false, pf->led_status,
  1822. (pf->phy_led_val |
  1823. I40E_PHY_LED_MODE_ORIG));
  1824. i40e_aq_set_phy_debug(hw, 0, NULL);
  1825. }
  1826. break;
  1827. default:
  1828. break;
  1829. }
  1830. if (ret)
  1831. return -ENOENT;
  1832. else
  1833. return 0;
  1834. }
  1835. /* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
  1836. * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
  1837. * 125us (8000 interrupts per second) == ITR(62)
  1838. */
  1839. /**
  1840. * __i40e_get_coalesce - get per-queue coalesce settings
  1841. * @netdev: the netdev to check
  1842. * @ec: ethtool coalesce data structure
  1843. * @queue: which queue to pick
  1844. *
  1845. * Gets the per-queue settings for coalescence. Specifically Rx and Tx usecs
  1846. * are per queue. If queue is <0 then we default to queue 0 as the
  1847. * representative value.
  1848. **/
  1849. static int __i40e_get_coalesce(struct net_device *netdev,
  1850. struct ethtool_coalesce *ec,
  1851. int queue)
  1852. {
  1853. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1854. struct i40e_ring *rx_ring, *tx_ring;
  1855. struct i40e_vsi *vsi = np->vsi;
  1856. ec->tx_max_coalesced_frames_irq = vsi->work_limit;
  1857. ec->rx_max_coalesced_frames_irq = vsi->work_limit;
  1858. /* rx and tx usecs has per queue value. If user doesn't specify the queue,
  1859. * return queue 0's value to represent.
  1860. */
  1861. if (queue < 0) {
  1862. queue = 0;
  1863. } else if (queue >= vsi->num_queue_pairs) {
  1864. return -EINVAL;
  1865. }
  1866. rx_ring = vsi->rx_rings[queue];
  1867. tx_ring = vsi->tx_rings[queue];
  1868. if (ITR_IS_DYNAMIC(rx_ring->rx_itr_setting))
  1869. ec->use_adaptive_rx_coalesce = 1;
  1870. if (ITR_IS_DYNAMIC(tx_ring->tx_itr_setting))
  1871. ec->use_adaptive_tx_coalesce = 1;
  1872. ec->rx_coalesce_usecs = rx_ring->rx_itr_setting & ~I40E_ITR_DYNAMIC;
  1873. ec->tx_coalesce_usecs = tx_ring->tx_itr_setting & ~I40E_ITR_DYNAMIC;
  1874. /* we use the _usecs_high to store/set the interrupt rate limit
  1875. * that the hardware supports, that almost but not quite
  1876. * fits the original intent of the ethtool variable,
  1877. * the rx_coalesce_usecs_high limits total interrupts
  1878. * per second from both tx/rx sources.
  1879. */
  1880. ec->rx_coalesce_usecs_high = vsi->int_rate_limit;
  1881. ec->tx_coalesce_usecs_high = vsi->int_rate_limit;
  1882. return 0;
  1883. }
  1884. /**
  1885. * i40e_get_coalesce - get a netdev's coalesce settings
  1886. * @netdev: the netdev to check
  1887. * @ec: ethtool coalesce data structure
  1888. *
  1889. * Gets the coalesce settings for a particular netdev. Note that if user has
  1890. * modified per-queue settings, this only guarantees to represent queue 0. See
  1891. * __i40e_get_coalesce for more details.
  1892. **/
  1893. static int i40e_get_coalesce(struct net_device *netdev,
  1894. struct ethtool_coalesce *ec)
  1895. {
  1896. return __i40e_get_coalesce(netdev, ec, -1);
  1897. }
  1898. /**
  1899. * i40e_get_per_queue_coalesce - gets coalesce settings for particular queue
  1900. * @netdev: netdev structure
  1901. * @ec: ethtool's coalesce settings
  1902. * @queue: the particular queue to read
  1903. *
  1904. * Will read a specific queue's coalesce settings
  1905. **/
  1906. static int i40e_get_per_queue_coalesce(struct net_device *netdev, u32 queue,
  1907. struct ethtool_coalesce *ec)
  1908. {
  1909. return __i40e_get_coalesce(netdev, ec, queue);
  1910. }
  1911. /**
  1912. * i40e_set_itr_per_queue - set ITR values for specific queue
  1913. * @vsi: the VSI to set values for
  1914. * @ec: coalesce settings from ethtool
  1915. * @queue: the queue to modify
  1916. *
  1917. * Change the ITR settings for a specific queue.
  1918. **/
  1919. static void i40e_set_itr_per_queue(struct i40e_vsi *vsi,
  1920. struct ethtool_coalesce *ec,
  1921. int queue)
  1922. {
  1923. struct i40e_pf *pf = vsi->back;
  1924. struct i40e_hw *hw = &pf->hw;
  1925. struct i40e_q_vector *q_vector;
  1926. u16 vector, intrl;
  1927. intrl = i40e_intrl_usec_to_reg(vsi->int_rate_limit);
  1928. vsi->rx_rings[queue]->rx_itr_setting = ec->rx_coalesce_usecs;
  1929. vsi->tx_rings[queue]->tx_itr_setting = ec->tx_coalesce_usecs;
  1930. if (ec->use_adaptive_rx_coalesce)
  1931. vsi->rx_rings[queue]->rx_itr_setting |= I40E_ITR_DYNAMIC;
  1932. else
  1933. vsi->rx_rings[queue]->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
  1934. if (ec->use_adaptive_tx_coalesce)
  1935. vsi->tx_rings[queue]->tx_itr_setting |= I40E_ITR_DYNAMIC;
  1936. else
  1937. vsi->tx_rings[queue]->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
  1938. q_vector = vsi->rx_rings[queue]->q_vector;
  1939. q_vector->rx.itr = ITR_TO_REG(vsi->rx_rings[queue]->rx_itr_setting);
  1940. vector = vsi->base_vector + q_vector->v_idx;
  1941. wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1), q_vector->rx.itr);
  1942. q_vector = vsi->tx_rings[queue]->q_vector;
  1943. q_vector->tx.itr = ITR_TO_REG(vsi->tx_rings[queue]->tx_itr_setting);
  1944. vector = vsi->base_vector + q_vector->v_idx;
  1945. wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1), q_vector->tx.itr);
  1946. wr32(hw, I40E_PFINT_RATEN(vector - 1), intrl);
  1947. i40e_flush(hw);
  1948. }
  1949. /**
  1950. * __i40e_set_coalesce - set coalesce settings for particular queue
  1951. * @netdev: the netdev to change
  1952. * @ec: ethtool coalesce settings
  1953. * @queue: the queue to change
  1954. *
  1955. * Sets the coalesce settings for a particular queue.
  1956. **/
  1957. static int __i40e_set_coalesce(struct net_device *netdev,
  1958. struct ethtool_coalesce *ec,
  1959. int queue)
  1960. {
  1961. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1962. u16 intrl_reg, cur_rx_itr, cur_tx_itr;
  1963. struct i40e_vsi *vsi = np->vsi;
  1964. struct i40e_pf *pf = vsi->back;
  1965. int i;
  1966. if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
  1967. vsi->work_limit = ec->tx_max_coalesced_frames_irq;
  1968. if (queue < 0) {
  1969. cur_rx_itr = vsi->rx_rings[0]->rx_itr_setting;
  1970. cur_tx_itr = vsi->tx_rings[0]->tx_itr_setting;
  1971. } else if (queue < vsi->num_queue_pairs) {
  1972. cur_rx_itr = vsi->rx_rings[queue]->rx_itr_setting;
  1973. cur_tx_itr = vsi->tx_rings[queue]->tx_itr_setting;
  1974. } else {
  1975. netif_info(pf, drv, netdev, "Invalid queue value, queue range is 0 - %d\n",
  1976. vsi->num_queue_pairs - 1);
  1977. return -EINVAL;
  1978. }
  1979. cur_tx_itr &= ~I40E_ITR_DYNAMIC;
  1980. cur_rx_itr &= ~I40E_ITR_DYNAMIC;
  1981. /* tx_coalesce_usecs_high is ignored, use rx-usecs-high instead */
  1982. if (ec->tx_coalesce_usecs_high != vsi->int_rate_limit) {
  1983. netif_info(pf, drv, netdev, "tx-usecs-high is not used, please program rx-usecs-high\n");
  1984. return -EINVAL;
  1985. }
  1986. if (ec->rx_coalesce_usecs_high > INTRL_REG_TO_USEC(I40E_MAX_INTRL)) {
  1987. netif_info(pf, drv, netdev, "Invalid value, rx-usecs-high range is 0-%lu\n",
  1988. INTRL_REG_TO_USEC(I40E_MAX_INTRL));
  1989. return -EINVAL;
  1990. }
  1991. if (ec->rx_coalesce_usecs != cur_rx_itr &&
  1992. ec->use_adaptive_rx_coalesce) {
  1993. netif_info(pf, drv, netdev, "RX interrupt moderation cannot be changed if adaptive-rx is enabled.\n");
  1994. return -EINVAL;
  1995. }
  1996. if (ec->rx_coalesce_usecs > (I40E_MAX_ITR << 1)) {
  1997. netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
  1998. return -EINVAL;
  1999. }
  2000. if (ec->tx_coalesce_usecs != cur_tx_itr &&
  2001. ec->use_adaptive_tx_coalesce) {
  2002. netif_info(pf, drv, netdev, "TX interrupt moderation cannot be changed if adaptive-tx is enabled.\n");
  2003. return -EINVAL;
  2004. }
  2005. if (ec->tx_coalesce_usecs > (I40E_MAX_ITR << 1)) {
  2006. netif_info(pf, drv, netdev, "Invalid value, tx-usecs range is 0-8160\n");
  2007. return -EINVAL;
  2008. }
  2009. if (ec->use_adaptive_rx_coalesce && !cur_rx_itr)
  2010. ec->rx_coalesce_usecs = I40E_MIN_ITR << 1;
  2011. if (ec->use_adaptive_tx_coalesce && !cur_tx_itr)
  2012. ec->tx_coalesce_usecs = I40E_MIN_ITR << 1;
  2013. intrl_reg = i40e_intrl_usec_to_reg(ec->rx_coalesce_usecs_high);
  2014. vsi->int_rate_limit = INTRL_REG_TO_USEC(intrl_reg);
  2015. if (vsi->int_rate_limit != ec->rx_coalesce_usecs_high) {
  2016. netif_info(pf, drv, netdev, "Interrupt rate limit rounded down to %d\n",
  2017. vsi->int_rate_limit);
  2018. }
  2019. /* rx and tx usecs has per queue value. If user doesn't specify the queue,
  2020. * apply to all queues.
  2021. */
  2022. if (queue < 0) {
  2023. for (i = 0; i < vsi->num_queue_pairs; i++)
  2024. i40e_set_itr_per_queue(vsi, ec, i);
  2025. } else {
  2026. i40e_set_itr_per_queue(vsi, ec, queue);
  2027. }
  2028. return 0;
  2029. }
  2030. /**
  2031. * i40e_set_coalesce - set coalesce settings for every queue on the netdev
  2032. * @netdev: the netdev to change
  2033. * @ec: ethtool coalesce settings
  2034. *
  2035. * This will set each queue to the same coalesce settings.
  2036. **/
  2037. static int i40e_set_coalesce(struct net_device *netdev,
  2038. struct ethtool_coalesce *ec)
  2039. {
  2040. return __i40e_set_coalesce(netdev, ec, -1);
  2041. }
  2042. /**
  2043. * i40e_set_per_queue_coalesce - set specific queue's coalesce settings
  2044. * @netdev: the netdev to change
  2045. * @ec: ethtool's coalesce settings
  2046. * @queue: the queue to change
  2047. *
  2048. * Sets the specified queue's coalesce settings.
  2049. **/
  2050. static int i40e_set_per_queue_coalesce(struct net_device *netdev, u32 queue,
  2051. struct ethtool_coalesce *ec)
  2052. {
  2053. return __i40e_set_coalesce(netdev, ec, queue);
  2054. }
  2055. /**
  2056. * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
  2057. * @pf: pointer to the physical function struct
  2058. * @cmd: ethtool rxnfc command
  2059. *
  2060. * Returns Success if the flow is supported, else Invalid Input.
  2061. **/
  2062. static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
  2063. {
  2064. struct i40e_hw *hw = &pf->hw;
  2065. u8 flow_pctype = 0;
  2066. u64 i_set = 0;
  2067. cmd->data = 0;
  2068. switch (cmd->flow_type) {
  2069. case TCP_V4_FLOW:
  2070. flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
  2071. break;
  2072. case UDP_V4_FLOW:
  2073. flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
  2074. break;
  2075. case TCP_V6_FLOW:
  2076. flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_TCP;
  2077. break;
  2078. case UDP_V6_FLOW:
  2079. flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_UDP;
  2080. break;
  2081. case SCTP_V4_FLOW:
  2082. case AH_ESP_V4_FLOW:
  2083. case AH_V4_FLOW:
  2084. case ESP_V4_FLOW:
  2085. case IPV4_FLOW:
  2086. case SCTP_V6_FLOW:
  2087. case AH_ESP_V6_FLOW:
  2088. case AH_V6_FLOW:
  2089. case ESP_V6_FLOW:
  2090. case IPV6_FLOW:
  2091. /* Default is src/dest for IP, no matter the L4 hashing */
  2092. cmd->data |= RXH_IP_SRC | RXH_IP_DST;
  2093. break;
  2094. default:
  2095. return -EINVAL;
  2096. }
  2097. /* Read flow based hash input set register */
  2098. if (flow_pctype) {
  2099. i_set = (u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0,
  2100. flow_pctype)) |
  2101. ((u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1,
  2102. flow_pctype)) << 32);
  2103. }
  2104. /* Process bits of hash input set */
  2105. if (i_set) {
  2106. if (i_set & I40E_L4_SRC_MASK)
  2107. cmd->data |= RXH_L4_B_0_1;
  2108. if (i_set & I40E_L4_DST_MASK)
  2109. cmd->data |= RXH_L4_B_2_3;
  2110. if (cmd->flow_type == TCP_V4_FLOW ||
  2111. cmd->flow_type == UDP_V4_FLOW) {
  2112. if (i_set & I40E_L3_SRC_MASK)
  2113. cmd->data |= RXH_IP_SRC;
  2114. if (i_set & I40E_L3_DST_MASK)
  2115. cmd->data |= RXH_IP_DST;
  2116. } else if (cmd->flow_type == TCP_V6_FLOW ||
  2117. cmd->flow_type == UDP_V6_FLOW) {
  2118. if (i_set & I40E_L3_V6_SRC_MASK)
  2119. cmd->data |= RXH_IP_SRC;
  2120. if (i_set & I40E_L3_V6_DST_MASK)
  2121. cmd->data |= RXH_IP_DST;
  2122. }
  2123. }
  2124. return 0;
  2125. }
  2126. /**
  2127. * i40e_check_mask - Check whether a mask field is set
  2128. * @mask: the full mask value
  2129. * @field; mask of the field to check
  2130. *
  2131. * If the given mask is fully set, return positive value. If the mask for the
  2132. * field is fully unset, return zero. Otherwise return a negative error code.
  2133. **/
  2134. static int i40e_check_mask(u64 mask, u64 field)
  2135. {
  2136. u64 value = mask & field;
  2137. if (value == field)
  2138. return 1;
  2139. else if (!value)
  2140. return 0;
  2141. else
  2142. return -1;
  2143. }
  2144. /**
  2145. * i40e_parse_rx_flow_user_data - Deconstruct user-defined data
  2146. * @fsp: pointer to rx flow specification
  2147. * @data: pointer to userdef data structure for storage
  2148. *
  2149. * Read the user-defined data and deconstruct the value into a structure. No
  2150. * other code should read the user-defined data, so as to ensure that every
  2151. * place consistently reads the value correctly.
  2152. *
  2153. * The user-defined field is a 64bit Big Endian format value, which we
  2154. * deconstruct by reading bits or bit fields from it. Single bit flags shall
  2155. * be defined starting from the highest bits, while small bit field values
  2156. * shall be defined starting from the lowest bits.
  2157. *
  2158. * Returns 0 if the data is valid, and non-zero if the userdef data is invalid
  2159. * and the filter should be rejected. The data structure will always be
  2160. * modified even if FLOW_EXT is not set.
  2161. *
  2162. **/
  2163. static int i40e_parse_rx_flow_user_data(struct ethtool_rx_flow_spec *fsp,
  2164. struct i40e_rx_flow_userdef *data)
  2165. {
  2166. u64 value, mask;
  2167. int valid;
  2168. /* Zero memory first so it's always consistent. */
  2169. memset(data, 0, sizeof(*data));
  2170. if (!(fsp->flow_type & FLOW_EXT))
  2171. return 0;
  2172. value = be64_to_cpu(*((__be64 *)fsp->h_ext.data));
  2173. mask = be64_to_cpu(*((__be64 *)fsp->m_ext.data));
  2174. #define I40E_USERDEF_FLEX_WORD GENMASK_ULL(15, 0)
  2175. #define I40E_USERDEF_FLEX_OFFSET GENMASK_ULL(31, 16)
  2176. #define I40E_USERDEF_FLEX_FILTER GENMASK_ULL(31, 0)
  2177. valid = i40e_check_mask(mask, I40E_USERDEF_FLEX_FILTER);
  2178. if (valid < 0) {
  2179. return -EINVAL;
  2180. } else if (valid) {
  2181. data->flex_word = value & I40E_USERDEF_FLEX_WORD;
  2182. data->flex_offset =
  2183. (value & I40E_USERDEF_FLEX_OFFSET) >> 16;
  2184. data->flex_filter = true;
  2185. }
  2186. return 0;
  2187. }
  2188. /**
  2189. * i40e_fill_rx_flow_user_data - Fill in user-defined data field
  2190. * @fsp: pointer to rx_flow specification
  2191. *
  2192. * Reads the userdef data structure and properly fills in the user defined
  2193. * fields of the rx_flow_spec.
  2194. **/
  2195. static void i40e_fill_rx_flow_user_data(struct ethtool_rx_flow_spec *fsp,
  2196. struct i40e_rx_flow_userdef *data)
  2197. {
  2198. u64 value = 0, mask = 0;
  2199. if (data->flex_filter) {
  2200. value |= data->flex_word;
  2201. value |= (u64)data->flex_offset << 16;
  2202. mask |= I40E_USERDEF_FLEX_FILTER;
  2203. }
  2204. if (value || mask)
  2205. fsp->flow_type |= FLOW_EXT;
  2206. *((__be64 *)fsp->h_ext.data) = cpu_to_be64(value);
  2207. *((__be64 *)fsp->m_ext.data) = cpu_to_be64(mask);
  2208. }
  2209. /**
  2210. * i40e_get_ethtool_fdir_all - Populates the rule count of a command
  2211. * @pf: Pointer to the physical function struct
  2212. * @cmd: The command to get or set Rx flow classification rules
  2213. * @rule_locs: Array of used rule locations
  2214. *
  2215. * This function populates both the total and actual rule count of
  2216. * the ethtool flow classification command
  2217. *
  2218. * Returns 0 on success or -EMSGSIZE if entry not found
  2219. **/
  2220. static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
  2221. struct ethtool_rxnfc *cmd,
  2222. u32 *rule_locs)
  2223. {
  2224. struct i40e_fdir_filter *rule;
  2225. struct hlist_node *node2;
  2226. int cnt = 0;
  2227. /* report total rule count */
  2228. cmd->data = i40e_get_fd_cnt_all(pf);
  2229. hlist_for_each_entry_safe(rule, node2,
  2230. &pf->fdir_filter_list, fdir_node) {
  2231. if (cnt == cmd->rule_cnt)
  2232. return -EMSGSIZE;
  2233. rule_locs[cnt] = rule->fd_id;
  2234. cnt++;
  2235. }
  2236. cmd->rule_cnt = cnt;
  2237. return 0;
  2238. }
  2239. /**
  2240. * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
  2241. * @pf: Pointer to the physical function struct
  2242. * @cmd: The command to get or set Rx flow classification rules
  2243. *
  2244. * This function looks up a filter based on the Rx flow classification
  2245. * command and fills the flow spec info for it if found
  2246. *
  2247. * Returns 0 on success or -EINVAL if filter not found
  2248. **/
  2249. static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
  2250. struct ethtool_rxnfc *cmd)
  2251. {
  2252. struct ethtool_rx_flow_spec *fsp =
  2253. (struct ethtool_rx_flow_spec *)&cmd->fs;
  2254. struct i40e_rx_flow_userdef userdef = {0};
  2255. struct i40e_fdir_filter *rule = NULL;
  2256. struct hlist_node *node2;
  2257. u64 input_set;
  2258. u16 index;
  2259. hlist_for_each_entry_safe(rule, node2,
  2260. &pf->fdir_filter_list, fdir_node) {
  2261. if (fsp->location <= rule->fd_id)
  2262. break;
  2263. }
  2264. if (!rule || fsp->location != rule->fd_id)
  2265. return -EINVAL;
  2266. fsp->flow_type = rule->flow_type;
  2267. if (fsp->flow_type == IP_USER_FLOW) {
  2268. fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
  2269. fsp->h_u.usr_ip4_spec.proto = 0;
  2270. fsp->m_u.usr_ip4_spec.proto = 0;
  2271. }
  2272. /* Reverse the src and dest notion, since the HW views them from
  2273. * Tx perspective where as the user expects it from Rx filter view.
  2274. */
  2275. fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
  2276. fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
  2277. fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip;
  2278. fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip;
  2279. switch (rule->flow_type) {
  2280. case SCTP_V4_FLOW:
  2281. index = I40E_FILTER_PCTYPE_NONF_IPV4_SCTP;
  2282. break;
  2283. case TCP_V4_FLOW:
  2284. index = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
  2285. break;
  2286. case UDP_V4_FLOW:
  2287. index = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
  2288. break;
  2289. case IP_USER_FLOW:
  2290. index = I40E_FILTER_PCTYPE_NONF_IPV4_OTHER;
  2291. break;
  2292. default:
  2293. /* If we have stored a filter with a flow type not listed here
  2294. * it is almost certainly a driver bug. WARN(), and then
  2295. * assign the input_set as if all fields are enabled to avoid
  2296. * reading unassigned memory.
  2297. */
  2298. WARN(1, "Missing input set index for flow_type %d\n",
  2299. rule->flow_type);
  2300. input_set = 0xFFFFFFFFFFFFFFFFULL;
  2301. goto no_input_set;
  2302. }
  2303. input_set = i40e_read_fd_input_set(pf, index);
  2304. no_input_set:
  2305. if (input_set & I40E_L3_SRC_MASK)
  2306. fsp->m_u.tcp_ip4_spec.ip4src = htonl(0xFFFF);
  2307. if (input_set & I40E_L3_DST_MASK)
  2308. fsp->m_u.tcp_ip4_spec.ip4dst = htonl(0xFFFF);
  2309. if (input_set & I40E_L4_SRC_MASK)
  2310. fsp->m_u.tcp_ip4_spec.psrc = htons(0xFFFFFFFF);
  2311. if (input_set & I40E_L4_DST_MASK)
  2312. fsp->m_u.tcp_ip4_spec.pdst = htons(0xFFFFFFFF);
  2313. if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
  2314. fsp->ring_cookie = RX_CLS_FLOW_DISC;
  2315. else
  2316. fsp->ring_cookie = rule->q_index;
  2317. if (rule->dest_vsi != pf->vsi[pf->lan_vsi]->id) {
  2318. struct i40e_vsi *vsi;
  2319. vsi = i40e_find_vsi_from_id(pf, rule->dest_vsi);
  2320. if (vsi && vsi->type == I40E_VSI_SRIOV) {
  2321. /* VFs are zero-indexed by the driver, but ethtool
  2322. * expects them to be one-indexed, so add one here
  2323. */
  2324. u64 ring_vf = vsi->vf_id + 1;
  2325. ring_vf <<= ETHTOOL_RX_FLOW_SPEC_RING_VF_OFF;
  2326. fsp->ring_cookie |= ring_vf;
  2327. }
  2328. }
  2329. if (rule->flex_filter) {
  2330. userdef.flex_filter = true;
  2331. userdef.flex_word = be16_to_cpu(rule->flex_word);
  2332. userdef.flex_offset = rule->flex_offset;
  2333. }
  2334. i40e_fill_rx_flow_user_data(fsp, &userdef);
  2335. return 0;
  2336. }
  2337. /**
  2338. * i40e_get_rxnfc - command to get RX flow classification rules
  2339. * @netdev: network interface device structure
  2340. * @cmd: ethtool rxnfc command
  2341. *
  2342. * Returns Success if the command is supported.
  2343. **/
  2344. static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
  2345. u32 *rule_locs)
  2346. {
  2347. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2348. struct i40e_vsi *vsi = np->vsi;
  2349. struct i40e_pf *pf = vsi->back;
  2350. int ret = -EOPNOTSUPP;
  2351. switch (cmd->cmd) {
  2352. case ETHTOOL_GRXRINGS:
  2353. cmd->data = vsi->num_queue_pairs;
  2354. ret = 0;
  2355. break;
  2356. case ETHTOOL_GRXFH:
  2357. ret = i40e_get_rss_hash_opts(pf, cmd);
  2358. break;
  2359. case ETHTOOL_GRXCLSRLCNT:
  2360. cmd->rule_cnt = pf->fdir_pf_active_filters;
  2361. /* report total rule count */
  2362. cmd->data = i40e_get_fd_cnt_all(pf);
  2363. ret = 0;
  2364. break;
  2365. case ETHTOOL_GRXCLSRULE:
  2366. ret = i40e_get_ethtool_fdir_entry(pf, cmd);
  2367. break;
  2368. case ETHTOOL_GRXCLSRLALL:
  2369. ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
  2370. break;
  2371. default:
  2372. break;
  2373. }
  2374. return ret;
  2375. }
  2376. /**
  2377. * i40e_get_rss_hash_bits - Read RSS Hash bits from register
  2378. * @nfc: pointer to user request
  2379. * @i_setc bits currently set
  2380. *
  2381. * Returns value of bits to be set per user request
  2382. **/
  2383. static u64 i40e_get_rss_hash_bits(struct ethtool_rxnfc *nfc, u64 i_setc)
  2384. {
  2385. u64 i_set = i_setc;
  2386. u64 src_l3 = 0, dst_l3 = 0;
  2387. if (nfc->data & RXH_L4_B_0_1)
  2388. i_set |= I40E_L4_SRC_MASK;
  2389. else
  2390. i_set &= ~I40E_L4_SRC_MASK;
  2391. if (nfc->data & RXH_L4_B_2_3)
  2392. i_set |= I40E_L4_DST_MASK;
  2393. else
  2394. i_set &= ~I40E_L4_DST_MASK;
  2395. if (nfc->flow_type == TCP_V6_FLOW || nfc->flow_type == UDP_V6_FLOW) {
  2396. src_l3 = I40E_L3_V6_SRC_MASK;
  2397. dst_l3 = I40E_L3_V6_DST_MASK;
  2398. } else if (nfc->flow_type == TCP_V4_FLOW ||
  2399. nfc->flow_type == UDP_V4_FLOW) {
  2400. src_l3 = I40E_L3_SRC_MASK;
  2401. dst_l3 = I40E_L3_DST_MASK;
  2402. } else {
  2403. /* Any other flow type are not supported here */
  2404. return i_set;
  2405. }
  2406. if (nfc->data & RXH_IP_SRC)
  2407. i_set |= src_l3;
  2408. else
  2409. i_set &= ~src_l3;
  2410. if (nfc->data & RXH_IP_DST)
  2411. i_set |= dst_l3;
  2412. else
  2413. i_set &= ~dst_l3;
  2414. return i_set;
  2415. }
  2416. /**
  2417. * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
  2418. * @pf: pointer to the physical function struct
  2419. * @cmd: ethtool rxnfc command
  2420. *
  2421. * Returns Success if the flow input set is supported.
  2422. **/
  2423. static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
  2424. {
  2425. struct i40e_hw *hw = &pf->hw;
  2426. u64 hena = (u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0)) |
  2427. ((u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1)) << 32);
  2428. u8 flow_pctype = 0;
  2429. u64 i_set, i_setc;
  2430. if (pf->flags & I40E_FLAG_MFP_ENABLED) {
  2431. dev_err(&pf->pdev->dev,
  2432. "Change of RSS hash input set is not supported when MFP mode is enabled\n");
  2433. return -EOPNOTSUPP;
  2434. }
  2435. /* RSS does not support anything other than hashing
  2436. * to queues on src and dst IPs and ports
  2437. */
  2438. if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
  2439. RXH_L4_B_0_1 | RXH_L4_B_2_3))
  2440. return -EINVAL;
  2441. switch (nfc->flow_type) {
  2442. case TCP_V4_FLOW:
  2443. flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
  2444. if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
  2445. hena |=
  2446. BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
  2447. break;
  2448. case TCP_V6_FLOW:
  2449. flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_TCP;
  2450. if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
  2451. hena |=
  2452. BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
  2453. if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
  2454. hena |=
  2455. BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK);
  2456. break;
  2457. case UDP_V4_FLOW:
  2458. flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
  2459. if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
  2460. hena |=
  2461. BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) |
  2462. BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP);
  2463. hena |= BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
  2464. break;
  2465. case UDP_V6_FLOW:
  2466. flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_UDP;
  2467. if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
  2468. hena |=
  2469. BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) |
  2470. BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP);
  2471. hena |= BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
  2472. break;
  2473. case AH_ESP_V4_FLOW:
  2474. case AH_V4_FLOW:
  2475. case ESP_V4_FLOW:
  2476. case SCTP_V4_FLOW:
  2477. if ((nfc->data & RXH_L4_B_0_1) ||
  2478. (nfc->data & RXH_L4_B_2_3))
  2479. return -EINVAL;
  2480. hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
  2481. break;
  2482. case AH_ESP_V6_FLOW:
  2483. case AH_V6_FLOW:
  2484. case ESP_V6_FLOW:
  2485. case SCTP_V6_FLOW:
  2486. if ((nfc->data & RXH_L4_B_0_1) ||
  2487. (nfc->data & RXH_L4_B_2_3))
  2488. return -EINVAL;
  2489. hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
  2490. break;
  2491. case IPV4_FLOW:
  2492. hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
  2493. BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
  2494. break;
  2495. case IPV6_FLOW:
  2496. hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
  2497. BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
  2498. break;
  2499. default:
  2500. return -EINVAL;
  2501. }
  2502. if (flow_pctype) {
  2503. i_setc = (u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0,
  2504. flow_pctype)) |
  2505. ((u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1,
  2506. flow_pctype)) << 32);
  2507. i_set = i40e_get_rss_hash_bits(nfc, i_setc);
  2508. i40e_write_rx_ctl(hw, I40E_GLQF_HASH_INSET(0, flow_pctype),
  2509. (u32)i_set);
  2510. i40e_write_rx_ctl(hw, I40E_GLQF_HASH_INSET(1, flow_pctype),
  2511. (u32)(i_set >> 32));
  2512. hena |= BIT_ULL(flow_pctype);
  2513. }
  2514. i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (u32)hena);
  2515. i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
  2516. i40e_flush(hw);
  2517. return 0;
  2518. }
  2519. /**
  2520. * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
  2521. * @vsi: Pointer to the targeted VSI
  2522. * @input: The filter to update or NULL to indicate deletion
  2523. * @sw_idx: Software index to the filter
  2524. * @cmd: The command to get or set Rx flow classification rules
  2525. *
  2526. * This function updates (or deletes) a Flow Director entry from
  2527. * the hlist of the corresponding PF
  2528. *
  2529. * Returns 0 on success
  2530. **/
  2531. static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
  2532. struct i40e_fdir_filter *input,
  2533. u16 sw_idx,
  2534. struct ethtool_rxnfc *cmd)
  2535. {
  2536. struct i40e_fdir_filter *rule, *parent;
  2537. struct i40e_pf *pf = vsi->back;
  2538. struct hlist_node *node2;
  2539. int err = -EINVAL;
  2540. parent = NULL;
  2541. rule = NULL;
  2542. hlist_for_each_entry_safe(rule, node2,
  2543. &pf->fdir_filter_list, fdir_node) {
  2544. /* hash found, or no matching entry */
  2545. if (rule->fd_id >= sw_idx)
  2546. break;
  2547. parent = rule;
  2548. }
  2549. /* if there is an old rule occupying our place remove it */
  2550. if (rule && (rule->fd_id == sw_idx)) {
  2551. /* Remove this rule, since we're either deleting it, or
  2552. * replacing it.
  2553. */
  2554. err = i40e_add_del_fdir(vsi, rule, false);
  2555. hlist_del(&rule->fdir_node);
  2556. kfree(rule);
  2557. pf->fdir_pf_active_filters--;
  2558. }
  2559. /* If we weren't given an input, this is a delete, so just return the
  2560. * error code indicating if there was an entry at the requested slot
  2561. */
  2562. if (!input)
  2563. return err;
  2564. /* Otherwise, install the new rule as requested */
  2565. INIT_HLIST_NODE(&input->fdir_node);
  2566. /* add filter to the list */
  2567. if (parent)
  2568. hlist_add_behind(&input->fdir_node, &parent->fdir_node);
  2569. else
  2570. hlist_add_head(&input->fdir_node,
  2571. &pf->fdir_filter_list);
  2572. /* update counts */
  2573. pf->fdir_pf_active_filters++;
  2574. return 0;
  2575. }
  2576. /**
  2577. * i40e_prune_flex_pit_list - Cleanup unused entries in FLX_PIT table
  2578. * @pf: pointer to PF structure
  2579. *
  2580. * This function searches the list of filters and determines which FLX_PIT
  2581. * entries are still required. It will prune any entries which are no longer
  2582. * in use after the deletion.
  2583. **/
  2584. static void i40e_prune_flex_pit_list(struct i40e_pf *pf)
  2585. {
  2586. struct i40e_flex_pit *entry, *tmp;
  2587. struct i40e_fdir_filter *rule;
  2588. /* First, we'll check the l3 table */
  2589. list_for_each_entry_safe(entry, tmp, &pf->l3_flex_pit_list, list) {
  2590. bool found = false;
  2591. hlist_for_each_entry(rule, &pf->fdir_filter_list, fdir_node) {
  2592. if (rule->flow_type != IP_USER_FLOW)
  2593. continue;
  2594. if (rule->flex_filter &&
  2595. rule->flex_offset == entry->src_offset) {
  2596. found = true;
  2597. break;
  2598. }
  2599. }
  2600. /* If we didn't find the filter, then we can prune this entry
  2601. * from the list.
  2602. */
  2603. if (!found) {
  2604. list_del(&entry->list);
  2605. kfree(entry);
  2606. }
  2607. }
  2608. /* Followed by the L4 table */
  2609. list_for_each_entry_safe(entry, tmp, &pf->l4_flex_pit_list, list) {
  2610. bool found = false;
  2611. hlist_for_each_entry(rule, &pf->fdir_filter_list, fdir_node) {
  2612. /* Skip this filter if it's L3, since we already
  2613. * checked those in the above loop
  2614. */
  2615. if (rule->flow_type == IP_USER_FLOW)
  2616. continue;
  2617. if (rule->flex_filter &&
  2618. rule->flex_offset == entry->src_offset) {
  2619. found = true;
  2620. break;
  2621. }
  2622. }
  2623. /* If we didn't find the filter, then we can prune this entry
  2624. * from the list.
  2625. */
  2626. if (!found) {
  2627. list_del(&entry->list);
  2628. kfree(entry);
  2629. }
  2630. }
  2631. }
  2632. /**
  2633. * i40e_del_fdir_entry - Deletes a Flow Director filter entry
  2634. * @vsi: Pointer to the targeted VSI
  2635. * @cmd: The command to get or set Rx flow classification rules
  2636. *
  2637. * The function removes a Flow Director filter entry from the
  2638. * hlist of the corresponding PF
  2639. *
  2640. * Returns 0 on success
  2641. */
  2642. static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
  2643. struct ethtool_rxnfc *cmd)
  2644. {
  2645. struct ethtool_rx_flow_spec *fsp =
  2646. (struct ethtool_rx_flow_spec *)&cmd->fs;
  2647. struct i40e_pf *pf = vsi->back;
  2648. int ret = 0;
  2649. if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
  2650. test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
  2651. return -EBUSY;
  2652. if (test_bit(__I40E_FD_FLUSH_REQUESTED, pf->state))
  2653. return -EBUSY;
  2654. ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
  2655. i40e_prune_flex_pit_list(pf);
  2656. i40e_fdir_check_and_reenable(pf);
  2657. return ret;
  2658. }
  2659. /**
  2660. * i40e_unused_pit_index - Find an unused PIT index for given list
  2661. * @pf: the PF data structure
  2662. *
  2663. * Find the first unused flexible PIT index entry. We search both the L3 and
  2664. * L4 flexible PIT lists so that the returned index is unique and unused by
  2665. * either currently programmed L3 or L4 filters. We use a bit field as storage
  2666. * to track which indexes are already used.
  2667. **/
  2668. static u8 i40e_unused_pit_index(struct i40e_pf *pf)
  2669. {
  2670. unsigned long available_index = 0xFF;
  2671. struct i40e_flex_pit *entry;
  2672. /* We need to make sure that the new index isn't in use by either L3
  2673. * or L4 filters so that IP_USER_FLOW filters can program both L3 and
  2674. * L4 to use the same index.
  2675. */
  2676. list_for_each_entry(entry, &pf->l4_flex_pit_list, list)
  2677. clear_bit(entry->pit_index, &available_index);
  2678. list_for_each_entry(entry, &pf->l3_flex_pit_list, list)
  2679. clear_bit(entry->pit_index, &available_index);
  2680. return find_first_bit(&available_index, 8);
  2681. }
  2682. /**
  2683. * i40e_find_flex_offset - Find an existing flex src_offset
  2684. * @flex_pit_list: L3 or L4 flex PIT list
  2685. * @src_offset: new src_offset to find
  2686. *
  2687. * Searches the flex_pit_list for an existing offset. If no offset is
  2688. * currently programmed, then this will return an ERR_PTR if there is no space
  2689. * to add a new offset, otherwise it returns NULL.
  2690. **/
  2691. static
  2692. struct i40e_flex_pit *i40e_find_flex_offset(struct list_head *flex_pit_list,
  2693. u16 src_offset)
  2694. {
  2695. struct i40e_flex_pit *entry;
  2696. int size = 0;
  2697. /* Search for the src_offset first. If we find a matching entry
  2698. * already programmed, we can simply re-use it.
  2699. */
  2700. list_for_each_entry(entry, flex_pit_list, list) {
  2701. size++;
  2702. if (entry->src_offset == src_offset)
  2703. return entry;
  2704. }
  2705. /* If we haven't found an entry yet, then the provided src offset has
  2706. * not yet been programmed. We will program the src offset later on,
  2707. * but we need to indicate whether there is enough space to do so
  2708. * here. We'll make use of ERR_PTR for this purpose.
  2709. */
  2710. if (size >= I40E_FLEX_PIT_TABLE_SIZE)
  2711. return ERR_PTR(-ENOSPC);
  2712. return NULL;
  2713. }
  2714. /**
  2715. * i40e_add_flex_offset - Add src_offset to flex PIT table list
  2716. * @flex_pit_list: L3 or L4 flex PIT list
  2717. * @src_offset: new src_offset to add
  2718. * @pit_index: the PIT index to program
  2719. *
  2720. * This function programs the new src_offset to the list. It is expected that
  2721. * i40e_find_flex_offset has already been tried and returned NULL, indicating
  2722. * that this offset is not programmed, and that the list has enough space to
  2723. * store another offset.
  2724. *
  2725. * Returns 0 on success, and negative value on error.
  2726. **/
  2727. static int i40e_add_flex_offset(struct list_head *flex_pit_list,
  2728. u16 src_offset,
  2729. u8 pit_index)
  2730. {
  2731. struct i40e_flex_pit *new_pit, *entry;
  2732. new_pit = kzalloc(sizeof(*entry), GFP_KERNEL);
  2733. if (!new_pit)
  2734. return -ENOMEM;
  2735. new_pit->src_offset = src_offset;
  2736. new_pit->pit_index = pit_index;
  2737. /* We need to insert this item such that the list is sorted by
  2738. * src_offset in ascending order.
  2739. */
  2740. list_for_each_entry(entry, flex_pit_list, list) {
  2741. if (new_pit->src_offset < entry->src_offset) {
  2742. list_add_tail(&new_pit->list, &entry->list);
  2743. return 0;
  2744. }
  2745. /* If we found an entry with our offset already programmed we
  2746. * can simply return here, after freeing the memory. However,
  2747. * if the pit_index does not match we need to report an error.
  2748. */
  2749. if (new_pit->src_offset == entry->src_offset) {
  2750. int err = 0;
  2751. /* If the PIT index is not the same we can't re-use
  2752. * the entry, so we must report an error.
  2753. */
  2754. if (new_pit->pit_index != entry->pit_index)
  2755. err = -EINVAL;
  2756. kfree(new_pit);
  2757. return err;
  2758. }
  2759. }
  2760. /* If we reached here, then we haven't yet added the item. This means
  2761. * that we should add the item at the end of the list.
  2762. */
  2763. list_add_tail(&new_pit->list, flex_pit_list);
  2764. return 0;
  2765. }
  2766. /**
  2767. * __i40e_reprogram_flex_pit - Re-program specific FLX_PIT table
  2768. * @pf: Pointer to the PF structure
  2769. * @flex_pit_list: list of flexible src offsets in use
  2770. * #flex_pit_start: index to first entry for this section of the table
  2771. *
  2772. * In order to handle flexible data, the hardware uses a table of values
  2773. * called the FLX_PIT table. This table is used to indicate which sections of
  2774. * the input correspond to what PIT index values. Unfortunately, hardware is
  2775. * very restrictive about programming this table. Entries must be ordered by
  2776. * src_offset in ascending order, without duplicates. Additionally, unused
  2777. * entries must be set to the unused index value, and must have valid size and
  2778. * length according to the src_offset ordering.
  2779. *
  2780. * This function will reprogram the FLX_PIT register from a book-keeping
  2781. * structure that we guarantee is already ordered correctly, and has no more
  2782. * than 3 entries.
  2783. *
  2784. * To make things easier, we only support flexible values of one word length,
  2785. * rather than allowing variable length flexible values.
  2786. **/
  2787. static void __i40e_reprogram_flex_pit(struct i40e_pf *pf,
  2788. struct list_head *flex_pit_list,
  2789. int flex_pit_start)
  2790. {
  2791. struct i40e_flex_pit *entry = NULL;
  2792. u16 last_offset = 0;
  2793. int i = 0, j = 0;
  2794. /* First, loop over the list of flex PIT entries, and reprogram the
  2795. * registers.
  2796. */
  2797. list_for_each_entry(entry, flex_pit_list, list) {
  2798. /* We have to be careful when programming values for the
  2799. * largest SRC_OFFSET value. It is possible that adding
  2800. * additional empty values at the end would overflow the space
  2801. * for the SRC_OFFSET in the FLX_PIT register. To avoid this,
  2802. * we check here and add the empty values prior to adding the
  2803. * largest value.
  2804. *
  2805. * To determine this, we will use a loop from i+1 to 3, which
  2806. * will determine whether the unused entries would have valid
  2807. * SRC_OFFSET. Note that there cannot be extra entries past
  2808. * this value, because the only valid values would have been
  2809. * larger than I40E_MAX_FLEX_SRC_OFFSET, and thus would not
  2810. * have been added to the list in the first place.
  2811. */
  2812. for (j = i + 1; j < 3; j++) {
  2813. u16 offset = entry->src_offset + j;
  2814. int index = flex_pit_start + i;
  2815. u32 value = I40E_FLEX_PREP_VAL(I40E_FLEX_DEST_UNUSED,
  2816. 1,
  2817. offset - 3);
  2818. if (offset > I40E_MAX_FLEX_SRC_OFFSET) {
  2819. i40e_write_rx_ctl(&pf->hw,
  2820. I40E_PRTQF_FLX_PIT(index),
  2821. value);
  2822. i++;
  2823. }
  2824. }
  2825. /* Now, we can program the actual value into the table */
  2826. i40e_write_rx_ctl(&pf->hw,
  2827. I40E_PRTQF_FLX_PIT(flex_pit_start + i),
  2828. I40E_FLEX_PREP_VAL(entry->pit_index + 50,
  2829. 1,
  2830. entry->src_offset));
  2831. i++;
  2832. }
  2833. /* In order to program the last entries in the table, we need to
  2834. * determine the valid offset. If the list is empty, we'll just start
  2835. * with 0. Otherwise, we'll start with the last item offset and add 1.
  2836. * This ensures that all entries have valid sizes. If we don't do this
  2837. * correctly, the hardware will disable flexible field parsing.
  2838. */
  2839. if (!list_empty(flex_pit_list))
  2840. last_offset = list_prev_entry(entry, list)->src_offset + 1;
  2841. for (; i < 3; i++, last_offset++) {
  2842. i40e_write_rx_ctl(&pf->hw,
  2843. I40E_PRTQF_FLX_PIT(flex_pit_start + i),
  2844. I40E_FLEX_PREP_VAL(I40E_FLEX_DEST_UNUSED,
  2845. 1,
  2846. last_offset));
  2847. }
  2848. }
  2849. /**
  2850. * i40e_reprogram_flex_pit - Reprogram all FLX_PIT tables after input set change
  2851. * @pf: pointer to the PF structure
  2852. *
  2853. * This function reprograms both the L3 and L4 FLX_PIT tables. See the
  2854. * internal helper function for implementation details.
  2855. **/
  2856. static void i40e_reprogram_flex_pit(struct i40e_pf *pf)
  2857. {
  2858. __i40e_reprogram_flex_pit(pf, &pf->l3_flex_pit_list,
  2859. I40E_FLEX_PIT_IDX_START_L3);
  2860. __i40e_reprogram_flex_pit(pf, &pf->l4_flex_pit_list,
  2861. I40E_FLEX_PIT_IDX_START_L4);
  2862. /* We also need to program the L3 and L4 GLQF ORT register */
  2863. i40e_write_rx_ctl(&pf->hw,
  2864. I40E_GLQF_ORT(I40E_L3_GLQF_ORT_IDX),
  2865. I40E_ORT_PREP_VAL(I40E_FLEX_PIT_IDX_START_L3,
  2866. 3, 1));
  2867. i40e_write_rx_ctl(&pf->hw,
  2868. I40E_GLQF_ORT(I40E_L4_GLQF_ORT_IDX),
  2869. I40E_ORT_PREP_VAL(I40E_FLEX_PIT_IDX_START_L4,
  2870. 3, 1));
  2871. }
  2872. /**
  2873. * i40e_flow_str - Converts a flow_type into a human readable string
  2874. * @flow_type: the flow type from a flow specification
  2875. *
  2876. * Currently only flow types we support are included here, and the string
  2877. * value attempts to match what ethtool would use to configure this flow type.
  2878. **/
  2879. static const char *i40e_flow_str(struct ethtool_rx_flow_spec *fsp)
  2880. {
  2881. switch (fsp->flow_type & ~FLOW_EXT) {
  2882. case TCP_V4_FLOW:
  2883. return "tcp4";
  2884. case UDP_V4_FLOW:
  2885. return "udp4";
  2886. case SCTP_V4_FLOW:
  2887. return "sctp4";
  2888. case IP_USER_FLOW:
  2889. return "ip4";
  2890. default:
  2891. return "unknown";
  2892. }
  2893. }
  2894. /**
  2895. * i40e_pit_index_to_mask - Return the FLEX mask for a given PIT index
  2896. * @pit_index: PIT index to convert
  2897. *
  2898. * Returns the mask for a given PIT index. Will return 0 if the pit_index is
  2899. * of range.
  2900. **/
  2901. static u64 i40e_pit_index_to_mask(int pit_index)
  2902. {
  2903. switch (pit_index) {
  2904. case 0:
  2905. return I40E_FLEX_50_MASK;
  2906. case 1:
  2907. return I40E_FLEX_51_MASK;
  2908. case 2:
  2909. return I40E_FLEX_52_MASK;
  2910. case 3:
  2911. return I40E_FLEX_53_MASK;
  2912. case 4:
  2913. return I40E_FLEX_54_MASK;
  2914. case 5:
  2915. return I40E_FLEX_55_MASK;
  2916. case 6:
  2917. return I40E_FLEX_56_MASK;
  2918. case 7:
  2919. return I40E_FLEX_57_MASK;
  2920. default:
  2921. return 0;
  2922. }
  2923. }
  2924. /**
  2925. * i40e_print_input_set - Show changes between two input sets
  2926. * @vsi: the vsi being configured
  2927. * @old: the old input set
  2928. * @new: the new input set
  2929. *
  2930. * Print the difference between old and new input sets by showing which series
  2931. * of words are toggled on or off. Only displays the bits we actually support
  2932. * changing.
  2933. **/
  2934. static void i40e_print_input_set(struct i40e_vsi *vsi, u64 old, u64 new)
  2935. {
  2936. struct i40e_pf *pf = vsi->back;
  2937. bool old_value, new_value;
  2938. int i;
  2939. old_value = !!(old & I40E_L3_SRC_MASK);
  2940. new_value = !!(new & I40E_L3_SRC_MASK);
  2941. if (old_value != new_value)
  2942. netif_info(pf, drv, vsi->netdev, "L3 source address: %s -> %s\n",
  2943. old_value ? "ON" : "OFF",
  2944. new_value ? "ON" : "OFF");
  2945. old_value = !!(old & I40E_L3_DST_MASK);
  2946. new_value = !!(new & I40E_L3_DST_MASK);
  2947. if (old_value != new_value)
  2948. netif_info(pf, drv, vsi->netdev, "L3 destination address: %s -> %s\n",
  2949. old_value ? "ON" : "OFF",
  2950. new_value ? "ON" : "OFF");
  2951. old_value = !!(old & I40E_L4_SRC_MASK);
  2952. new_value = !!(new & I40E_L4_SRC_MASK);
  2953. if (old_value != new_value)
  2954. netif_info(pf, drv, vsi->netdev, "L4 source port: %s -> %s\n",
  2955. old_value ? "ON" : "OFF",
  2956. new_value ? "ON" : "OFF");
  2957. old_value = !!(old & I40E_L4_DST_MASK);
  2958. new_value = !!(new & I40E_L4_DST_MASK);
  2959. if (old_value != new_value)
  2960. netif_info(pf, drv, vsi->netdev, "L4 destination port: %s -> %s\n",
  2961. old_value ? "ON" : "OFF",
  2962. new_value ? "ON" : "OFF");
  2963. old_value = !!(old & I40E_VERIFY_TAG_MASK);
  2964. new_value = !!(new & I40E_VERIFY_TAG_MASK);
  2965. if (old_value != new_value)
  2966. netif_info(pf, drv, vsi->netdev, "SCTP verification tag: %s -> %s\n",
  2967. old_value ? "ON" : "OFF",
  2968. new_value ? "ON" : "OFF");
  2969. /* Show change of flexible filter entries */
  2970. for (i = 0; i < I40E_FLEX_INDEX_ENTRIES; i++) {
  2971. u64 flex_mask = i40e_pit_index_to_mask(i);
  2972. old_value = !!(old & flex_mask);
  2973. new_value = !!(new & flex_mask);
  2974. if (old_value != new_value)
  2975. netif_info(pf, drv, vsi->netdev, "FLEX index %d: %s -> %s\n",
  2976. i,
  2977. old_value ? "ON" : "OFF",
  2978. new_value ? "ON" : "OFF");
  2979. }
  2980. netif_info(pf, drv, vsi->netdev, " Current input set: %0llx\n",
  2981. old);
  2982. netif_info(pf, drv, vsi->netdev, "Requested input set: %0llx\n",
  2983. new);
  2984. }
  2985. /**
  2986. * i40e_check_fdir_input_set - Check that a given rx_flow_spec mask is valid
  2987. * @vsi: pointer to the targeted VSI
  2988. * @fsp: pointer to Rx flow specification
  2989. * @userdef: userdefined data from flow specification
  2990. *
  2991. * Ensures that a given ethtool_rx_flow_spec has a valid mask. Some support
  2992. * for partial matches exists with a few limitations. First, hardware only
  2993. * supports masking by word boundary (2 bytes) and not per individual bit.
  2994. * Second, hardware is limited to using one mask for a flow type and cannot
  2995. * use a separate mask for each filter.
  2996. *
  2997. * To support these limitations, if we already have a configured filter for
  2998. * the specified type, this function enforces that new filters of the type
  2999. * match the configured input set. Otherwise, if we do not have a filter of
  3000. * the specified type, we allow the input set to be updated to match the
  3001. * desired filter.
  3002. *
  3003. * To help ensure that administrators understand why filters weren't displayed
  3004. * as supported, we print a diagnostic message displaying how the input set
  3005. * would change and warning to delete the preexisting filters if required.
  3006. *
  3007. * Returns 0 on successful input set match, and a negative return code on
  3008. * failure.
  3009. **/
  3010. static int i40e_check_fdir_input_set(struct i40e_vsi *vsi,
  3011. struct ethtool_rx_flow_spec *fsp,
  3012. struct i40e_rx_flow_userdef *userdef)
  3013. {
  3014. struct i40e_pf *pf = vsi->back;
  3015. struct ethtool_tcpip4_spec *tcp_ip4_spec;
  3016. struct ethtool_usrip4_spec *usr_ip4_spec;
  3017. u64 current_mask, new_mask;
  3018. bool new_flex_offset = false;
  3019. bool flex_l3 = false;
  3020. u16 *fdir_filter_count;
  3021. u16 index, src_offset = 0;
  3022. u8 pit_index = 0;
  3023. int err;
  3024. switch (fsp->flow_type & ~FLOW_EXT) {
  3025. case SCTP_V4_FLOW:
  3026. index = I40E_FILTER_PCTYPE_NONF_IPV4_SCTP;
  3027. fdir_filter_count = &pf->fd_sctp4_filter_cnt;
  3028. break;
  3029. case TCP_V4_FLOW:
  3030. index = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
  3031. fdir_filter_count = &pf->fd_tcp4_filter_cnt;
  3032. break;
  3033. case UDP_V4_FLOW:
  3034. index = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
  3035. fdir_filter_count = &pf->fd_udp4_filter_cnt;
  3036. break;
  3037. case IP_USER_FLOW:
  3038. index = I40E_FILTER_PCTYPE_NONF_IPV4_OTHER;
  3039. fdir_filter_count = &pf->fd_ip4_filter_cnt;
  3040. flex_l3 = true;
  3041. break;
  3042. default:
  3043. return -EOPNOTSUPP;
  3044. }
  3045. /* Read the current input set from register memory. */
  3046. current_mask = i40e_read_fd_input_set(pf, index);
  3047. new_mask = current_mask;
  3048. /* Determine, if any, the required changes to the input set in order
  3049. * to support the provided mask.
  3050. *
  3051. * Hardware only supports masking at word (2 byte) granularity and does
  3052. * not support full bitwise masking. This implementation simplifies
  3053. * even further and only supports fully enabled or fully disabled
  3054. * masks for each field, even though we could split the ip4src and
  3055. * ip4dst fields.
  3056. */
  3057. switch (fsp->flow_type & ~FLOW_EXT) {
  3058. case SCTP_V4_FLOW:
  3059. new_mask &= ~I40E_VERIFY_TAG_MASK;
  3060. /* Fall through */
  3061. case TCP_V4_FLOW:
  3062. case UDP_V4_FLOW:
  3063. tcp_ip4_spec = &fsp->m_u.tcp_ip4_spec;
  3064. /* IPv4 source address */
  3065. if (tcp_ip4_spec->ip4src == htonl(0xFFFFFFFF))
  3066. new_mask |= I40E_L3_SRC_MASK;
  3067. else if (!tcp_ip4_spec->ip4src)
  3068. new_mask &= ~I40E_L3_SRC_MASK;
  3069. else
  3070. return -EOPNOTSUPP;
  3071. /* IPv4 destination address */
  3072. if (tcp_ip4_spec->ip4dst == htonl(0xFFFFFFFF))
  3073. new_mask |= I40E_L3_DST_MASK;
  3074. else if (!tcp_ip4_spec->ip4dst)
  3075. new_mask &= ~I40E_L3_DST_MASK;
  3076. else
  3077. return -EOPNOTSUPP;
  3078. /* L4 source port */
  3079. if (tcp_ip4_spec->psrc == htons(0xFFFF))
  3080. new_mask |= I40E_L4_SRC_MASK;
  3081. else if (!tcp_ip4_spec->psrc)
  3082. new_mask &= ~I40E_L4_SRC_MASK;
  3083. else
  3084. return -EOPNOTSUPP;
  3085. /* L4 destination port */
  3086. if (tcp_ip4_spec->pdst == htons(0xFFFF))
  3087. new_mask |= I40E_L4_DST_MASK;
  3088. else if (!tcp_ip4_spec->pdst)
  3089. new_mask &= ~I40E_L4_DST_MASK;
  3090. else
  3091. return -EOPNOTSUPP;
  3092. /* Filtering on Type of Service is not supported. */
  3093. if (tcp_ip4_spec->tos)
  3094. return -EOPNOTSUPP;
  3095. break;
  3096. case IP_USER_FLOW:
  3097. usr_ip4_spec = &fsp->m_u.usr_ip4_spec;
  3098. /* IPv4 source address */
  3099. if (usr_ip4_spec->ip4src == htonl(0xFFFFFFFF))
  3100. new_mask |= I40E_L3_SRC_MASK;
  3101. else if (!usr_ip4_spec->ip4src)
  3102. new_mask &= ~I40E_L3_SRC_MASK;
  3103. else
  3104. return -EOPNOTSUPP;
  3105. /* IPv4 destination address */
  3106. if (usr_ip4_spec->ip4dst == htonl(0xFFFFFFFF))
  3107. new_mask |= I40E_L3_DST_MASK;
  3108. else if (!usr_ip4_spec->ip4dst)
  3109. new_mask &= ~I40E_L3_DST_MASK;
  3110. else
  3111. return -EOPNOTSUPP;
  3112. /* First 4 bytes of L4 header */
  3113. if (usr_ip4_spec->l4_4_bytes == htonl(0xFFFFFFFF))
  3114. new_mask |= I40E_L4_SRC_MASK | I40E_L4_DST_MASK;
  3115. else if (!usr_ip4_spec->l4_4_bytes)
  3116. new_mask &= ~(I40E_L4_SRC_MASK | I40E_L4_DST_MASK);
  3117. else
  3118. return -EOPNOTSUPP;
  3119. /* Filtering on Type of Service is not supported. */
  3120. if (usr_ip4_spec->tos)
  3121. return -EOPNOTSUPP;
  3122. /* Filtering on IP version is not supported */
  3123. if (usr_ip4_spec->ip_ver)
  3124. return -EINVAL;
  3125. /* Filtering on L4 protocol is not supported */
  3126. if (usr_ip4_spec->proto)
  3127. return -EINVAL;
  3128. break;
  3129. default:
  3130. return -EOPNOTSUPP;
  3131. }
  3132. /* First, clear all flexible filter entries */
  3133. new_mask &= ~I40E_FLEX_INPUT_MASK;
  3134. /* If we have a flexible filter, try to add this offset to the correct
  3135. * flexible filter PIT list. Once finished, we can update the mask.
  3136. * If the src_offset changed, we will get a new mask value which will
  3137. * trigger an input set change.
  3138. */
  3139. if (userdef->flex_filter) {
  3140. struct i40e_flex_pit *l3_flex_pit = NULL, *flex_pit = NULL;
  3141. /* Flexible offset must be even, since the flexible payload
  3142. * must be aligned on 2-byte boundary.
  3143. */
  3144. if (userdef->flex_offset & 0x1) {
  3145. dev_warn(&pf->pdev->dev,
  3146. "Flexible data offset must be 2-byte aligned\n");
  3147. return -EINVAL;
  3148. }
  3149. src_offset = userdef->flex_offset >> 1;
  3150. /* FLX_PIT source offset value is only so large */
  3151. if (src_offset > I40E_MAX_FLEX_SRC_OFFSET) {
  3152. dev_warn(&pf->pdev->dev,
  3153. "Flexible data must reside within first 64 bytes of the packet payload\n");
  3154. return -EINVAL;
  3155. }
  3156. /* See if this offset has already been programmed. If we get
  3157. * an ERR_PTR, then the filter is not safe to add. Otherwise,
  3158. * if we get a NULL pointer, this means we will need to add
  3159. * the offset.
  3160. */
  3161. flex_pit = i40e_find_flex_offset(&pf->l4_flex_pit_list,
  3162. src_offset);
  3163. if (IS_ERR(flex_pit))
  3164. return PTR_ERR(flex_pit);
  3165. /* IP_USER_FLOW filters match both L4 (ICMP) and L3 (unknown)
  3166. * packet types, and thus we need to program both L3 and L4
  3167. * flexible values. These must have identical flexible index,
  3168. * as otherwise we can't correctly program the input set. So
  3169. * we'll find both an L3 and L4 index and make sure they are
  3170. * the same.
  3171. */
  3172. if (flex_l3) {
  3173. l3_flex_pit =
  3174. i40e_find_flex_offset(&pf->l3_flex_pit_list,
  3175. src_offset);
  3176. if (IS_ERR(l3_flex_pit))
  3177. return PTR_ERR(l3_flex_pit);
  3178. if (flex_pit) {
  3179. /* If we already had a matching L4 entry, we
  3180. * need to make sure that the L3 entry we
  3181. * obtained uses the same index.
  3182. */
  3183. if (l3_flex_pit) {
  3184. if (l3_flex_pit->pit_index !=
  3185. flex_pit->pit_index) {
  3186. return -EINVAL;
  3187. }
  3188. } else {
  3189. new_flex_offset = true;
  3190. }
  3191. } else {
  3192. flex_pit = l3_flex_pit;
  3193. }
  3194. }
  3195. /* If we didn't find an existing flex offset, we need to
  3196. * program a new one. However, we don't immediately program it
  3197. * here because we will wait to program until after we check
  3198. * that it is safe to change the input set.
  3199. */
  3200. if (!flex_pit) {
  3201. new_flex_offset = true;
  3202. pit_index = i40e_unused_pit_index(pf);
  3203. } else {
  3204. pit_index = flex_pit->pit_index;
  3205. }
  3206. /* Update the mask with the new offset */
  3207. new_mask |= i40e_pit_index_to_mask(pit_index);
  3208. }
  3209. /* If the mask and flexible filter offsets for this filter match the
  3210. * currently programmed values we don't need any input set change, so
  3211. * this filter is safe to install.
  3212. */
  3213. if (new_mask == current_mask && !new_flex_offset)
  3214. return 0;
  3215. netif_info(pf, drv, vsi->netdev, "Input set change requested for %s flows:\n",
  3216. i40e_flow_str(fsp));
  3217. i40e_print_input_set(vsi, current_mask, new_mask);
  3218. if (new_flex_offset) {
  3219. netif_info(pf, drv, vsi->netdev, "FLEX index %d: Offset -> %d",
  3220. pit_index, src_offset);
  3221. }
  3222. /* Hardware input sets are global across multiple ports, so even the
  3223. * main port cannot change them when in MFP mode as this would impact
  3224. * any filters on the other ports.
  3225. */
  3226. if (pf->flags & I40E_FLAG_MFP_ENABLED) {
  3227. netif_err(pf, drv, vsi->netdev, "Cannot change Flow Director input sets while MFP is enabled\n");
  3228. return -EOPNOTSUPP;
  3229. }
  3230. /* This filter requires us to update the input set. However, hardware
  3231. * only supports one input set per flow type, and does not support
  3232. * separate masks for each filter. This means that we can only support
  3233. * a single mask for all filters of a specific type.
  3234. *
  3235. * If we have preexisting filters, they obviously depend on the
  3236. * current programmed input set. Display a diagnostic message in this
  3237. * case explaining why the filter could not be accepted.
  3238. */
  3239. if (*fdir_filter_count) {
  3240. netif_err(pf, drv, vsi->netdev, "Cannot change input set for %s flows until %d preexisting filters are removed\n",
  3241. i40e_flow_str(fsp),
  3242. *fdir_filter_count);
  3243. return -EOPNOTSUPP;
  3244. }
  3245. i40e_write_fd_input_set(pf, index, new_mask);
  3246. /* Add the new offset and update table, if necessary */
  3247. if (new_flex_offset) {
  3248. err = i40e_add_flex_offset(&pf->l4_flex_pit_list, src_offset,
  3249. pit_index);
  3250. if (err)
  3251. return err;
  3252. if (flex_l3) {
  3253. err = i40e_add_flex_offset(&pf->l3_flex_pit_list,
  3254. src_offset,
  3255. pit_index);
  3256. if (err)
  3257. return err;
  3258. }
  3259. i40e_reprogram_flex_pit(pf);
  3260. }
  3261. return 0;
  3262. }
  3263. /**
  3264. * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
  3265. * @vsi: pointer to the targeted VSI
  3266. * @cmd: command to get or set RX flow classification rules
  3267. *
  3268. * Add Flow Director filters for a specific flow spec based on their
  3269. * protocol. Returns 0 if the filters were successfully added.
  3270. **/
  3271. static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
  3272. struct ethtool_rxnfc *cmd)
  3273. {
  3274. struct i40e_rx_flow_userdef userdef;
  3275. struct ethtool_rx_flow_spec *fsp;
  3276. struct i40e_fdir_filter *input;
  3277. u16 dest_vsi = 0, q_index = 0;
  3278. struct i40e_pf *pf;
  3279. int ret = -EINVAL;
  3280. u8 dest_ctl;
  3281. if (!vsi)
  3282. return -EINVAL;
  3283. pf = vsi->back;
  3284. if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
  3285. return -EOPNOTSUPP;
  3286. if (pf->flags & I40E_FLAG_FD_SB_AUTO_DISABLED)
  3287. return -ENOSPC;
  3288. if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
  3289. test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
  3290. return -EBUSY;
  3291. if (test_bit(__I40E_FD_FLUSH_REQUESTED, pf->state))
  3292. return -EBUSY;
  3293. fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
  3294. /* Parse the user-defined field */
  3295. if (i40e_parse_rx_flow_user_data(fsp, &userdef))
  3296. return -EINVAL;
  3297. /* Extended MAC field is not supported */
  3298. if (fsp->flow_type & FLOW_MAC_EXT)
  3299. return -EINVAL;
  3300. ret = i40e_check_fdir_input_set(vsi, fsp, &userdef);
  3301. if (ret)
  3302. return ret;
  3303. if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
  3304. pf->hw.func_caps.fd_filters_guaranteed)) {
  3305. return -EINVAL;
  3306. }
  3307. /* ring_cookie is either the drop index, or is a mask of the queue
  3308. * index and VF id we wish to target.
  3309. */
  3310. if (fsp->ring_cookie == RX_CLS_FLOW_DISC) {
  3311. dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
  3312. } else {
  3313. u32 ring = ethtool_get_flow_spec_ring(fsp->ring_cookie);
  3314. u8 vf = ethtool_get_flow_spec_ring_vf(fsp->ring_cookie);
  3315. if (!vf) {
  3316. if (ring >= vsi->num_queue_pairs)
  3317. return -EINVAL;
  3318. dest_vsi = vsi->id;
  3319. } else {
  3320. /* VFs are zero-indexed, so we subtract one here */
  3321. vf--;
  3322. if (vf >= pf->num_alloc_vfs)
  3323. return -EINVAL;
  3324. if (ring >= pf->vf[vf].num_queue_pairs)
  3325. return -EINVAL;
  3326. dest_vsi = pf->vf[vf].lan_vsi_id;
  3327. }
  3328. dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
  3329. q_index = ring;
  3330. }
  3331. input = kzalloc(sizeof(*input), GFP_KERNEL);
  3332. if (!input)
  3333. return -ENOMEM;
  3334. input->fd_id = fsp->location;
  3335. input->q_index = q_index;
  3336. input->dest_vsi = dest_vsi;
  3337. input->dest_ctl = dest_ctl;
  3338. input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
  3339. input->cnt_index = I40E_FD_SB_STAT_IDX(pf->hw.pf_id);
  3340. input->dst_ip = fsp->h_u.tcp_ip4_spec.ip4src;
  3341. input->src_ip = fsp->h_u.tcp_ip4_spec.ip4dst;
  3342. input->flow_type = fsp->flow_type & ~FLOW_EXT;
  3343. input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
  3344. /* Reverse the src and dest notion, since the HW expects them to be from
  3345. * Tx perspective where as the input from user is from Rx filter view.
  3346. */
  3347. input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
  3348. input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
  3349. input->dst_ip = fsp->h_u.tcp_ip4_spec.ip4src;
  3350. input->src_ip = fsp->h_u.tcp_ip4_spec.ip4dst;
  3351. if (userdef.flex_filter) {
  3352. input->flex_filter = true;
  3353. input->flex_word = cpu_to_be16(userdef.flex_word);
  3354. input->flex_offset = userdef.flex_offset;
  3355. }
  3356. ret = i40e_add_del_fdir(vsi, input, true);
  3357. if (ret)
  3358. goto free_input;
  3359. /* Add the input filter to the fdir_input_list, possibly replacing
  3360. * a previous filter. Do not free the input structure after adding it
  3361. * to the list as this would cause a use-after-free bug.
  3362. */
  3363. i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
  3364. return 0;
  3365. free_input:
  3366. kfree(input);
  3367. return ret;
  3368. }
  3369. /**
  3370. * i40e_set_rxnfc - command to set RX flow classification rules
  3371. * @netdev: network interface device structure
  3372. * @cmd: ethtool rxnfc command
  3373. *
  3374. * Returns Success if the command is supported.
  3375. **/
  3376. static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
  3377. {
  3378. struct i40e_netdev_priv *np = netdev_priv(netdev);
  3379. struct i40e_vsi *vsi = np->vsi;
  3380. struct i40e_pf *pf = vsi->back;
  3381. int ret = -EOPNOTSUPP;
  3382. switch (cmd->cmd) {
  3383. case ETHTOOL_SRXFH:
  3384. ret = i40e_set_rss_hash_opt(pf, cmd);
  3385. break;
  3386. case ETHTOOL_SRXCLSRLINS:
  3387. ret = i40e_add_fdir_ethtool(vsi, cmd);
  3388. break;
  3389. case ETHTOOL_SRXCLSRLDEL:
  3390. ret = i40e_del_fdir_entry(vsi, cmd);
  3391. break;
  3392. default:
  3393. break;
  3394. }
  3395. return ret;
  3396. }
  3397. /**
  3398. * i40e_max_channels - get Max number of combined channels supported
  3399. * @vsi: vsi pointer
  3400. **/
  3401. static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
  3402. {
  3403. /* TODO: This code assumes DCB and FD is disabled for now. */
  3404. return vsi->alloc_queue_pairs;
  3405. }
  3406. /**
  3407. * i40e_get_channels - Get the current channels enabled and max supported etc.
  3408. * @netdev: network interface device structure
  3409. * @ch: ethtool channels structure
  3410. *
  3411. * We don't support separate tx and rx queues as channels. The other count
  3412. * represents how many queues are being used for control. max_combined counts
  3413. * how many queue pairs we can support. They may not be mapped 1 to 1 with
  3414. * q_vectors since we support a lot more queue pairs than q_vectors.
  3415. **/
  3416. static void i40e_get_channels(struct net_device *dev,
  3417. struct ethtool_channels *ch)
  3418. {
  3419. struct i40e_netdev_priv *np = netdev_priv(dev);
  3420. struct i40e_vsi *vsi = np->vsi;
  3421. struct i40e_pf *pf = vsi->back;
  3422. /* report maximum channels */
  3423. ch->max_combined = i40e_max_channels(vsi);
  3424. /* report info for other vector */
  3425. ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
  3426. ch->max_other = ch->other_count;
  3427. /* Note: This code assumes DCB is disabled for now. */
  3428. ch->combined_count = vsi->num_queue_pairs;
  3429. }
  3430. /**
  3431. * i40e_set_channels - Set the new channels count.
  3432. * @netdev: network interface device structure
  3433. * @ch: ethtool channels structure
  3434. *
  3435. * The new channels count may not be the same as requested by the user
  3436. * since it gets rounded down to a power of 2 value.
  3437. **/
  3438. static int i40e_set_channels(struct net_device *dev,
  3439. struct ethtool_channels *ch)
  3440. {
  3441. const u8 drop = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
  3442. struct i40e_netdev_priv *np = netdev_priv(dev);
  3443. unsigned int count = ch->combined_count;
  3444. struct i40e_vsi *vsi = np->vsi;
  3445. struct i40e_pf *pf = vsi->back;
  3446. struct i40e_fdir_filter *rule;
  3447. struct hlist_node *node2;
  3448. int new_count;
  3449. int err = 0;
  3450. /* We do not support setting channels for any other VSI at present */
  3451. if (vsi->type != I40E_VSI_MAIN)
  3452. return -EINVAL;
  3453. /* verify they are not requesting separate vectors */
  3454. if (!count || ch->rx_count || ch->tx_count)
  3455. return -EINVAL;
  3456. /* verify other_count has not changed */
  3457. if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
  3458. return -EINVAL;
  3459. /* verify the number of channels does not exceed hardware limits */
  3460. if (count > i40e_max_channels(vsi))
  3461. return -EINVAL;
  3462. /* verify that the number of channels does not invalidate any current
  3463. * flow director rules
  3464. */
  3465. hlist_for_each_entry_safe(rule, node2,
  3466. &pf->fdir_filter_list, fdir_node) {
  3467. if (rule->dest_ctl != drop && count <= rule->q_index) {
  3468. dev_warn(&pf->pdev->dev,
  3469. "Existing user defined filter %d assigns flow to queue %d\n",
  3470. rule->fd_id, rule->q_index);
  3471. err = -EINVAL;
  3472. }
  3473. }
  3474. if (err) {
  3475. dev_err(&pf->pdev->dev,
  3476. "Existing filter rules must be deleted to reduce combined channel count to %d\n",
  3477. count);
  3478. return err;
  3479. }
  3480. /* update feature limits from largest to smallest supported values */
  3481. /* TODO: Flow director limit, DCB etc */
  3482. /* use rss_reconfig to rebuild with new queue count and update traffic
  3483. * class queue mapping
  3484. */
  3485. new_count = i40e_reconfig_rss_queues(pf, count);
  3486. if (new_count > 0)
  3487. return 0;
  3488. else
  3489. return -EINVAL;
  3490. }
  3491. /**
  3492. * i40e_get_rxfh_key_size - get the RSS hash key size
  3493. * @netdev: network interface device structure
  3494. *
  3495. * Returns the table size.
  3496. **/
  3497. static u32 i40e_get_rxfh_key_size(struct net_device *netdev)
  3498. {
  3499. return I40E_HKEY_ARRAY_SIZE;
  3500. }
  3501. /**
  3502. * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size
  3503. * @netdev: network interface device structure
  3504. *
  3505. * Returns the table size.
  3506. **/
  3507. static u32 i40e_get_rxfh_indir_size(struct net_device *netdev)
  3508. {
  3509. return I40E_HLUT_ARRAY_SIZE;
  3510. }
  3511. static int i40e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
  3512. u8 *hfunc)
  3513. {
  3514. struct i40e_netdev_priv *np = netdev_priv(netdev);
  3515. struct i40e_vsi *vsi = np->vsi;
  3516. u8 *lut, *seed = NULL;
  3517. int ret;
  3518. u16 i;
  3519. if (hfunc)
  3520. *hfunc = ETH_RSS_HASH_TOP;
  3521. if (!indir)
  3522. return 0;
  3523. seed = key;
  3524. lut = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
  3525. if (!lut)
  3526. return -ENOMEM;
  3527. ret = i40e_get_rss(vsi, seed, lut, I40E_HLUT_ARRAY_SIZE);
  3528. if (ret)
  3529. goto out;
  3530. for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
  3531. indir[i] = (u32)(lut[i]);
  3532. out:
  3533. kfree(lut);
  3534. return ret;
  3535. }
  3536. /**
  3537. * i40e_set_rxfh - set the rx flow hash indirection table
  3538. * @netdev: network interface device structure
  3539. * @indir: indirection table
  3540. * @key: hash key
  3541. *
  3542. * Returns -EINVAL if the table specifies an invalid queue id, otherwise
  3543. * returns 0 after programming the table.
  3544. **/
  3545. static int i40e_set_rxfh(struct net_device *netdev, const u32 *indir,
  3546. const u8 *key, const u8 hfunc)
  3547. {
  3548. struct i40e_netdev_priv *np = netdev_priv(netdev);
  3549. struct i40e_vsi *vsi = np->vsi;
  3550. struct i40e_pf *pf = vsi->back;
  3551. u8 *seed = NULL;
  3552. u16 i;
  3553. if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
  3554. return -EOPNOTSUPP;
  3555. if (key) {
  3556. if (!vsi->rss_hkey_user) {
  3557. vsi->rss_hkey_user = kzalloc(I40E_HKEY_ARRAY_SIZE,
  3558. GFP_KERNEL);
  3559. if (!vsi->rss_hkey_user)
  3560. return -ENOMEM;
  3561. }
  3562. memcpy(vsi->rss_hkey_user, key, I40E_HKEY_ARRAY_SIZE);
  3563. seed = vsi->rss_hkey_user;
  3564. }
  3565. if (!vsi->rss_lut_user) {
  3566. vsi->rss_lut_user = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
  3567. if (!vsi->rss_lut_user)
  3568. return -ENOMEM;
  3569. }
  3570. /* Each 32 bits pointed by 'indir' is stored with a lut entry */
  3571. if (indir)
  3572. for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
  3573. vsi->rss_lut_user[i] = (u8)(indir[i]);
  3574. else
  3575. i40e_fill_rss_lut(pf, vsi->rss_lut_user, I40E_HLUT_ARRAY_SIZE,
  3576. vsi->rss_size);
  3577. return i40e_config_rss(vsi, seed, vsi->rss_lut_user,
  3578. I40E_HLUT_ARRAY_SIZE);
  3579. }
  3580. /**
  3581. * i40e_get_priv_flags - report device private flags
  3582. * @dev: network interface device structure
  3583. *
  3584. * The get string set count and the string set should be matched for each
  3585. * flag returned. Add new strings for each flag to the i40e_gstrings_priv_flags
  3586. * array.
  3587. *
  3588. * Returns a u32 bitmap of flags.
  3589. **/
  3590. static u32 i40e_get_priv_flags(struct net_device *dev)
  3591. {
  3592. struct i40e_netdev_priv *np = netdev_priv(dev);
  3593. struct i40e_vsi *vsi = np->vsi;
  3594. struct i40e_pf *pf = vsi->back;
  3595. u32 i, j, ret_flags = 0;
  3596. for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
  3597. const struct i40e_priv_flags *priv_flags;
  3598. priv_flags = &i40e_gstrings_priv_flags[i];
  3599. if (priv_flags->flag & pf->flags)
  3600. ret_flags |= BIT(i);
  3601. }
  3602. if (pf->hw.pf_id != 0)
  3603. return ret_flags;
  3604. for (j = 0; j < I40E_GL_PRIV_FLAGS_STR_LEN; j++) {
  3605. const struct i40e_priv_flags *priv_flags;
  3606. priv_flags = &i40e_gl_gstrings_priv_flags[j];
  3607. if (priv_flags->flag & pf->flags)
  3608. ret_flags |= BIT(i + j);
  3609. }
  3610. return ret_flags;
  3611. }
  3612. /**
  3613. * i40e_set_priv_flags - set private flags
  3614. * @dev: network interface device structure
  3615. * @flags: bit flags to be set
  3616. **/
  3617. static int i40e_set_priv_flags(struct net_device *dev, u32 flags)
  3618. {
  3619. struct i40e_netdev_priv *np = netdev_priv(dev);
  3620. struct i40e_vsi *vsi = np->vsi;
  3621. struct i40e_pf *pf = vsi->back;
  3622. u64 orig_flags, new_flags, changed_flags;
  3623. u32 i, j;
  3624. orig_flags = READ_ONCE(pf->flags);
  3625. new_flags = orig_flags;
  3626. for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
  3627. const struct i40e_priv_flags *priv_flags;
  3628. priv_flags = &i40e_gstrings_priv_flags[i];
  3629. if (flags & BIT(i))
  3630. new_flags |= priv_flags->flag;
  3631. else
  3632. new_flags &= ~(priv_flags->flag);
  3633. /* If this is a read-only flag, it can't be changed */
  3634. if (priv_flags->read_only &&
  3635. ((orig_flags ^ new_flags) & ~BIT(i)))
  3636. return -EOPNOTSUPP;
  3637. }
  3638. if (pf->hw.pf_id != 0)
  3639. goto flags_complete;
  3640. for (j = 0; j < I40E_GL_PRIV_FLAGS_STR_LEN; j++) {
  3641. const struct i40e_priv_flags *priv_flags;
  3642. priv_flags = &i40e_gl_gstrings_priv_flags[j];
  3643. if (flags & BIT(i + j))
  3644. new_flags |= priv_flags->flag;
  3645. else
  3646. new_flags &= ~(priv_flags->flag);
  3647. /* If this is a read-only flag, it can't be changed */
  3648. if (priv_flags->read_only &&
  3649. ((orig_flags ^ new_flags) & ~BIT(i)))
  3650. return -EOPNOTSUPP;
  3651. }
  3652. flags_complete:
  3653. /* Before we finalize any flag changes, we need to perform some
  3654. * checks to ensure that the changes are supported and safe.
  3655. */
  3656. /* ATR eviction is not supported on all devices */
  3657. if ((new_flags & I40E_FLAG_HW_ATR_EVICT_ENABLED) &&
  3658. !(pf->hw_features & I40E_HW_ATR_EVICT_CAPABLE))
  3659. return -EOPNOTSUPP;
  3660. /* Compare and exchange the new flags into place. If we failed, that
  3661. * is if cmpxchg64 returns anything but the old value, this means that
  3662. * something else has modified the flags variable since we copied it
  3663. * originally. We'll just punt with an error and log something in the
  3664. * message buffer.
  3665. */
  3666. if (cmpxchg64(&pf->flags, orig_flags, new_flags) != orig_flags) {
  3667. dev_warn(&pf->pdev->dev,
  3668. "Unable to update pf->flags as it was modified by another thread...\n");
  3669. return -EAGAIN;
  3670. }
  3671. changed_flags = orig_flags ^ new_flags;
  3672. /* Process any additional changes needed as a result of flag changes.
  3673. * The changed_flags value reflects the list of bits that were
  3674. * changed in the code above.
  3675. */
  3676. /* Flush current ATR settings if ATR was disabled */
  3677. if ((changed_flags & I40E_FLAG_FD_ATR_ENABLED) &&
  3678. !(pf->flags & I40E_FLAG_FD_ATR_ENABLED)) {
  3679. pf->flags |= I40E_FLAG_FD_ATR_AUTO_DISABLED;
  3680. set_bit(__I40E_FD_FLUSH_REQUESTED, pf->state);
  3681. }
  3682. if (changed_flags & I40E_FLAG_TRUE_PROMISC_SUPPORT) {
  3683. u16 sw_flags = 0, valid_flags = 0;
  3684. int ret;
  3685. if (!(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT))
  3686. sw_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
  3687. valid_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
  3688. ret = i40e_aq_set_switch_config(&pf->hw, sw_flags, valid_flags,
  3689. NULL);
  3690. if (ret && pf->hw.aq.asq_last_status != I40E_AQ_RC_ESRCH) {
  3691. dev_info(&pf->pdev->dev,
  3692. "couldn't set switch config bits, err %s aq_err %s\n",
  3693. i40e_stat_str(&pf->hw, ret),
  3694. i40e_aq_str(&pf->hw,
  3695. pf->hw.aq.asq_last_status));
  3696. /* not a fatal problem, just keep going */
  3697. }
  3698. }
  3699. /* Issue reset to cause things to take effect, as additional bits
  3700. * are added we will need to create a mask of bits requiring reset
  3701. */
  3702. if ((changed_flags & I40E_FLAG_VEB_STATS_ENABLED) ||
  3703. ((changed_flags & I40E_FLAG_LEGACY_RX) && netif_running(dev)))
  3704. i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED), true);
  3705. return 0;
  3706. }
  3707. static const struct ethtool_ops i40e_ethtool_ops = {
  3708. .get_drvinfo = i40e_get_drvinfo,
  3709. .get_regs_len = i40e_get_regs_len,
  3710. .get_regs = i40e_get_regs,
  3711. .nway_reset = i40e_nway_reset,
  3712. .get_link = ethtool_op_get_link,
  3713. .get_wol = i40e_get_wol,
  3714. .set_wol = i40e_set_wol,
  3715. .set_eeprom = i40e_set_eeprom,
  3716. .get_eeprom_len = i40e_get_eeprom_len,
  3717. .get_eeprom = i40e_get_eeprom,
  3718. .get_ringparam = i40e_get_ringparam,
  3719. .set_ringparam = i40e_set_ringparam,
  3720. .get_pauseparam = i40e_get_pauseparam,
  3721. .set_pauseparam = i40e_set_pauseparam,
  3722. .get_msglevel = i40e_get_msglevel,
  3723. .set_msglevel = i40e_set_msglevel,
  3724. .get_rxnfc = i40e_get_rxnfc,
  3725. .set_rxnfc = i40e_set_rxnfc,
  3726. .self_test = i40e_diag_test,
  3727. .get_strings = i40e_get_strings,
  3728. .set_phys_id = i40e_set_phys_id,
  3729. .get_sset_count = i40e_get_sset_count,
  3730. .get_ethtool_stats = i40e_get_ethtool_stats,
  3731. .get_coalesce = i40e_get_coalesce,
  3732. .set_coalesce = i40e_set_coalesce,
  3733. .get_rxfh_key_size = i40e_get_rxfh_key_size,
  3734. .get_rxfh_indir_size = i40e_get_rxfh_indir_size,
  3735. .get_rxfh = i40e_get_rxfh,
  3736. .set_rxfh = i40e_set_rxfh,
  3737. .get_channels = i40e_get_channels,
  3738. .set_channels = i40e_set_channels,
  3739. .get_ts_info = i40e_get_ts_info,
  3740. .get_priv_flags = i40e_get_priv_flags,
  3741. .set_priv_flags = i40e_set_priv_flags,
  3742. .get_per_queue_coalesce = i40e_get_per_queue_coalesce,
  3743. .set_per_queue_coalesce = i40e_set_per_queue_coalesce,
  3744. .get_link_ksettings = i40e_get_link_ksettings,
  3745. .set_link_ksettings = i40e_set_link_ksettings,
  3746. };
  3747. void i40e_set_ethtool_ops(struct net_device *netdev)
  3748. {
  3749. netdev->ethtool_ops = &i40e_ethtool_ops;
  3750. }