i40e_ethtool.c 143 KB

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