i40e_ethtool.c 148 KB

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