netdevice.h 161 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * INET An implementation of the TCP/IP protocol suite for the LINUX
  4. * operating system. INET is implemented using the BSD Socket
  5. * interface as the means of communication with the user level.
  6. *
  7. * Definitions for the Interfaces handler.
  8. *
  9. * Version: @(#)dev.h 1.0.10 08/12/93
  10. *
  11. * Authors: Ross Biro
  12. * Fred N. van Kempen, <[email protected]>
  13. * Corey Minyard <[email protected]>
  14. * Donald J. Becker, <[email protected]>
  15. * Alan Cox, <[email protected]>
  16. * Bjorn Ekwall. <[email protected]>
  17. * Pekka Riikonen <[email protected]>
  18. *
  19. * Moved to /usr/include/linux for NET3
  20. */
  21. #ifndef _LINUX_NETDEVICE_H
  22. #define _LINUX_NETDEVICE_H
  23. #include <linux/timer.h>
  24. #include <linux/bug.h>
  25. #include <linux/delay.h>
  26. #include <linux/atomic.h>
  27. #include <linux/prefetch.h>
  28. #include <asm/cache.h>
  29. #include <asm/byteorder.h>
  30. #include <asm/local.h>
  31. #include <linux/percpu.h>
  32. #include <linux/rculist.h>
  33. #include <linux/workqueue.h>
  34. #include <linux/dynamic_queue_limits.h>
  35. #include <net/net_namespace.h>
  36. #ifdef CONFIG_DCB
  37. #include <net/dcbnl.h>
  38. #endif
  39. #include <net/netprio_cgroup.h>
  40. #include <net/xdp.h>
  41. #include <linux/netdev_features.h>
  42. #include <linux/neighbour.h>
  43. #include <uapi/linux/netdevice.h>
  44. #include <uapi/linux/if_bonding.h>
  45. #include <uapi/linux/pkt_cls.h>
  46. #include <linux/hashtable.h>
  47. #include <linux/rbtree.h>
  48. #include <net/net_trackers.h>
  49. #include <net/net_debug.h>
  50. #include <linux/android_kabi.h>
  51. struct netpoll_info;
  52. struct device;
  53. struct ethtool_ops;
  54. struct phy_device;
  55. struct dsa_port;
  56. struct ip_tunnel_parm;
  57. struct macsec_context;
  58. struct macsec_ops;
  59. struct netdev_name_node;
  60. struct sd_flow_limit;
  61. struct sfp_bus;
  62. /* 802.11 specific */
  63. struct wireless_dev;
  64. /* 802.15.4 specific */
  65. struct wpan_dev;
  66. struct mpls_dev;
  67. /* UDP Tunnel offloads */
  68. struct udp_tunnel_info;
  69. struct udp_tunnel_nic_info;
  70. struct udp_tunnel_nic;
  71. struct bpf_prog;
  72. struct xdp_buff;
  73. void synchronize_net(void);
  74. void netdev_set_default_ethtool_ops(struct net_device *dev,
  75. const struct ethtool_ops *ops);
  76. /* Backlog congestion levels */
  77. #define NET_RX_SUCCESS 0 /* keep 'em coming, baby */
  78. #define NET_RX_DROP 1 /* packet dropped */
  79. #define MAX_NEST_DEV 8
  80. /*
  81. * Transmit return codes: transmit return codes originate from three different
  82. * namespaces:
  83. *
  84. * - qdisc return codes
  85. * - driver transmit return codes
  86. * - errno values
  87. *
  88. * Drivers are allowed to return any one of those in their hard_start_xmit()
  89. * function. Real network devices commonly used with qdiscs should only return
  90. * the driver transmit return codes though - when qdiscs are used, the actual
  91. * transmission happens asynchronously, so the value is not propagated to
  92. * higher layers. Virtual network devices transmit synchronously; in this case
  93. * the driver transmit return codes are consumed by dev_queue_xmit(), and all
  94. * others are propagated to higher layers.
  95. */
  96. /* qdisc ->enqueue() return codes. */
  97. #define NET_XMIT_SUCCESS 0x00
  98. #define NET_XMIT_DROP 0x01 /* skb dropped */
  99. #define NET_XMIT_CN 0x02 /* congestion notification */
  100. #define NET_XMIT_MASK 0x0f /* qdisc flags in net/sch_generic.h */
  101. /* NET_XMIT_CN is special. It does not guarantee that this packet is lost. It
  102. * indicates that the device will soon be dropping packets, or already drops
  103. * some packets of the same priority; prompting us to send less aggressively. */
  104. #define net_xmit_eval(e) ((e) == NET_XMIT_CN ? 0 : (e))
  105. #define net_xmit_errno(e) ((e) != NET_XMIT_CN ? -ENOBUFS : 0)
  106. /* Driver transmit return codes */
  107. #define NETDEV_TX_MASK 0xf0
  108. enum netdev_tx {
  109. __NETDEV_TX_MIN = INT_MIN, /* make sure enum is signed */
  110. NETDEV_TX_OK = 0x00, /* driver took care of packet */
  111. NETDEV_TX_BUSY = 0x10, /* driver tx path was busy*/
  112. };
  113. typedef enum netdev_tx netdev_tx_t;
  114. /*
  115. * Current order: NETDEV_TX_MASK > NET_XMIT_MASK >= 0 is significant;
  116. * hard_start_xmit() return < NET_XMIT_MASK means skb was consumed.
  117. */
  118. static inline bool dev_xmit_complete(int rc)
  119. {
  120. /*
  121. * Positive cases with an skb consumed by a driver:
  122. * - successful transmission (rc == NETDEV_TX_OK)
  123. * - error while transmitting (rc < 0)
  124. * - error while queueing to a different device (rc & NET_XMIT_MASK)
  125. */
  126. if (likely(rc < NET_XMIT_MASK))
  127. return true;
  128. return false;
  129. }
  130. /*
  131. * Compute the worst-case header length according to the protocols
  132. * used.
  133. */
  134. #if defined(CONFIG_HYPERV_NET)
  135. # define LL_MAX_HEADER 128
  136. #elif defined(CONFIG_WLAN) || IS_ENABLED(CONFIG_AX25)
  137. # if defined(CONFIG_MAC80211_MESH)
  138. # define LL_MAX_HEADER 128
  139. # else
  140. # define LL_MAX_HEADER 96
  141. # endif
  142. #else
  143. # define LL_MAX_HEADER 32
  144. #endif
  145. #if !IS_ENABLED(CONFIG_NET_IPIP) && !IS_ENABLED(CONFIG_NET_IPGRE) && \
  146. !IS_ENABLED(CONFIG_IPV6_SIT) && !IS_ENABLED(CONFIG_IPV6_TUNNEL)
  147. #define MAX_HEADER LL_MAX_HEADER
  148. #else
  149. #define MAX_HEADER (LL_MAX_HEADER + 48)
  150. #endif
  151. /*
  152. * Old network device statistics. Fields are native words
  153. * (unsigned long) so they can be read and written atomically.
  154. */
  155. #define NET_DEV_STAT(FIELD) \
  156. union { \
  157. unsigned long FIELD; \
  158. atomic_long_t __##FIELD; \
  159. }
  160. struct net_device_stats {
  161. NET_DEV_STAT(rx_packets);
  162. NET_DEV_STAT(tx_packets);
  163. NET_DEV_STAT(rx_bytes);
  164. NET_DEV_STAT(tx_bytes);
  165. NET_DEV_STAT(rx_errors);
  166. NET_DEV_STAT(tx_errors);
  167. NET_DEV_STAT(rx_dropped);
  168. NET_DEV_STAT(tx_dropped);
  169. NET_DEV_STAT(multicast);
  170. NET_DEV_STAT(collisions);
  171. NET_DEV_STAT(rx_length_errors);
  172. NET_DEV_STAT(rx_over_errors);
  173. NET_DEV_STAT(rx_crc_errors);
  174. NET_DEV_STAT(rx_frame_errors);
  175. NET_DEV_STAT(rx_fifo_errors);
  176. NET_DEV_STAT(rx_missed_errors);
  177. NET_DEV_STAT(tx_aborted_errors);
  178. NET_DEV_STAT(tx_carrier_errors);
  179. NET_DEV_STAT(tx_fifo_errors);
  180. NET_DEV_STAT(tx_heartbeat_errors);
  181. NET_DEV_STAT(tx_window_errors);
  182. NET_DEV_STAT(rx_compressed);
  183. NET_DEV_STAT(tx_compressed);
  184. };
  185. #undef NET_DEV_STAT
  186. /* per-cpu stats, allocated on demand.
  187. * Try to fit them in a single cache line, for dev_get_stats() sake.
  188. */
  189. struct net_device_core_stats {
  190. unsigned long rx_dropped;
  191. unsigned long tx_dropped;
  192. unsigned long rx_nohandler;
  193. unsigned long rx_otherhost_dropped;
  194. } __aligned(4 * sizeof(unsigned long));
  195. #include <linux/cache.h>
  196. #include <linux/skbuff.h>
  197. #ifdef CONFIG_RPS
  198. #include <linux/static_key.h>
  199. extern struct static_key_false rps_needed;
  200. extern struct static_key_false rfs_needed;
  201. #endif
  202. struct neighbour;
  203. struct neigh_parms;
  204. struct sk_buff;
  205. struct netdev_hw_addr {
  206. struct list_head list;
  207. struct rb_node node;
  208. unsigned char addr[MAX_ADDR_LEN];
  209. unsigned char type;
  210. #define NETDEV_HW_ADDR_T_LAN 1
  211. #define NETDEV_HW_ADDR_T_SAN 2
  212. #define NETDEV_HW_ADDR_T_UNICAST 3
  213. #define NETDEV_HW_ADDR_T_MULTICAST 4
  214. bool global_use;
  215. int sync_cnt;
  216. int refcount;
  217. int synced;
  218. struct rcu_head rcu_head;
  219. };
  220. struct netdev_hw_addr_list {
  221. struct list_head list;
  222. int count;
  223. /* Auxiliary tree for faster lookup on addition and deletion */
  224. struct rb_root tree;
  225. };
  226. #define netdev_hw_addr_list_count(l) ((l)->count)
  227. #define netdev_hw_addr_list_empty(l) (netdev_hw_addr_list_count(l) == 0)
  228. #define netdev_hw_addr_list_for_each(ha, l) \
  229. list_for_each_entry(ha, &(l)->list, list)
  230. #define netdev_uc_count(dev) netdev_hw_addr_list_count(&(dev)->uc)
  231. #define netdev_uc_empty(dev) netdev_hw_addr_list_empty(&(dev)->uc)
  232. #define netdev_for_each_uc_addr(ha, dev) \
  233. netdev_hw_addr_list_for_each(ha, &(dev)->uc)
  234. #define netdev_for_each_synced_uc_addr(_ha, _dev) \
  235. netdev_for_each_uc_addr((_ha), (_dev)) \
  236. if ((_ha)->sync_cnt)
  237. #define netdev_mc_count(dev) netdev_hw_addr_list_count(&(dev)->mc)
  238. #define netdev_mc_empty(dev) netdev_hw_addr_list_empty(&(dev)->mc)
  239. #define netdev_for_each_mc_addr(ha, dev) \
  240. netdev_hw_addr_list_for_each(ha, &(dev)->mc)
  241. #define netdev_for_each_synced_mc_addr(_ha, _dev) \
  242. netdev_for_each_mc_addr((_ha), (_dev)) \
  243. if ((_ha)->sync_cnt)
  244. struct hh_cache {
  245. unsigned int hh_len;
  246. seqlock_t hh_lock;
  247. /* cached hardware header; allow for machine alignment needs. */
  248. #define HH_DATA_MOD 16
  249. #define HH_DATA_OFF(__len) \
  250. (HH_DATA_MOD - (((__len - 1) & (HH_DATA_MOD - 1)) + 1))
  251. #define HH_DATA_ALIGN(__len) \
  252. (((__len)+(HH_DATA_MOD-1))&~(HH_DATA_MOD - 1))
  253. unsigned long hh_data[HH_DATA_ALIGN(LL_MAX_HEADER) / sizeof(long)];
  254. };
  255. /* Reserve HH_DATA_MOD byte-aligned hard_header_len, but at least that much.
  256. * Alternative is:
  257. * dev->hard_header_len ? (dev->hard_header_len +
  258. * (HH_DATA_MOD - 1)) & ~(HH_DATA_MOD - 1) : 0
  259. *
  260. * We could use other alignment values, but we must maintain the
  261. * relationship HH alignment <= LL alignment.
  262. */
  263. #define LL_RESERVED_SPACE(dev) \
  264. ((((dev)->hard_header_len + READ_ONCE((dev)->needed_headroom)) \
  265. & ~(HH_DATA_MOD - 1)) + HH_DATA_MOD)
  266. #define LL_RESERVED_SPACE_EXTRA(dev,extra) \
  267. ((((dev)->hard_header_len + READ_ONCE((dev)->needed_headroom) + (extra)) \
  268. & ~(HH_DATA_MOD - 1)) + HH_DATA_MOD)
  269. struct header_ops {
  270. int (*create) (struct sk_buff *skb, struct net_device *dev,
  271. unsigned short type, const void *daddr,
  272. const void *saddr, unsigned int len);
  273. int (*parse)(const struct sk_buff *skb, unsigned char *haddr);
  274. int (*cache)(const struct neighbour *neigh, struct hh_cache *hh, __be16 type);
  275. void (*cache_update)(struct hh_cache *hh,
  276. const struct net_device *dev,
  277. const unsigned char *haddr);
  278. bool (*validate)(const char *ll_header, unsigned int len);
  279. __be16 (*parse_protocol)(const struct sk_buff *skb);
  280. ANDROID_KABI_RESERVE(1);
  281. ANDROID_KABI_RESERVE(2);
  282. };
  283. /* These flag bits are private to the generic network queueing
  284. * layer; they may not be explicitly referenced by any other
  285. * code.
  286. */
  287. enum netdev_state_t {
  288. __LINK_STATE_START,
  289. __LINK_STATE_PRESENT,
  290. __LINK_STATE_NOCARRIER,
  291. __LINK_STATE_LINKWATCH_PENDING,
  292. __LINK_STATE_DORMANT,
  293. __LINK_STATE_TESTING,
  294. };
  295. struct gro_list {
  296. struct list_head list;
  297. int count;
  298. };
  299. /*
  300. * size of gro hash buckets, must less than bit number of
  301. * napi_struct::gro_bitmask
  302. */
  303. #define GRO_HASH_BUCKETS 8
  304. /*
  305. * Structure for NAPI scheduling similar to tasklet but with weighting
  306. */
  307. struct napi_struct {
  308. /* The poll_list must only be managed by the entity which
  309. * changes the state of the NAPI_STATE_SCHED bit. This means
  310. * whoever atomically sets that bit can add this napi_struct
  311. * to the per-CPU poll_list, and whoever clears that bit
  312. * can remove from the list right before clearing the bit.
  313. */
  314. struct list_head poll_list;
  315. unsigned long state;
  316. int weight;
  317. int defer_hard_irqs_count;
  318. unsigned long gro_bitmask;
  319. int (*poll)(struct napi_struct *, int);
  320. #ifdef CONFIG_NETPOLL
  321. int poll_owner;
  322. #endif
  323. struct net_device *dev;
  324. struct gro_list gro_hash[GRO_HASH_BUCKETS];
  325. struct sk_buff *skb;
  326. struct list_head rx_list; /* Pending GRO_NORMAL skbs */
  327. int rx_count; /* length of rx_list */
  328. struct hrtimer timer;
  329. struct list_head dev_list;
  330. struct hlist_node napi_hash_node;
  331. unsigned int napi_id;
  332. struct task_struct *thread;
  333. ANDROID_KABI_RESERVE(1);
  334. ANDROID_KABI_RESERVE(2);
  335. ANDROID_KABI_RESERVE(3);
  336. ANDROID_KABI_RESERVE(4);
  337. };
  338. enum {
  339. NAPI_STATE_SCHED, /* Poll is scheduled */
  340. NAPI_STATE_MISSED, /* reschedule a napi */
  341. NAPI_STATE_DISABLE, /* Disable pending */
  342. NAPI_STATE_NPSVC, /* Netpoll - don't dequeue from poll_list */
  343. NAPI_STATE_LISTED, /* NAPI added to system lists */
  344. NAPI_STATE_NO_BUSY_POLL, /* Do not add in napi_hash, no busy polling */
  345. NAPI_STATE_IN_BUSY_POLL, /* sk_busy_loop() owns this NAPI */
  346. NAPI_STATE_PREFER_BUSY_POLL, /* prefer busy-polling over softirq processing*/
  347. NAPI_STATE_THREADED, /* The poll is performed inside its own thread*/
  348. NAPI_STATE_SCHED_THREADED, /* Napi is currently scheduled in threaded mode */
  349. };
  350. enum {
  351. NAPIF_STATE_SCHED = BIT(NAPI_STATE_SCHED),
  352. NAPIF_STATE_MISSED = BIT(NAPI_STATE_MISSED),
  353. NAPIF_STATE_DISABLE = BIT(NAPI_STATE_DISABLE),
  354. NAPIF_STATE_NPSVC = BIT(NAPI_STATE_NPSVC),
  355. NAPIF_STATE_LISTED = BIT(NAPI_STATE_LISTED),
  356. NAPIF_STATE_NO_BUSY_POLL = BIT(NAPI_STATE_NO_BUSY_POLL),
  357. NAPIF_STATE_IN_BUSY_POLL = BIT(NAPI_STATE_IN_BUSY_POLL),
  358. NAPIF_STATE_PREFER_BUSY_POLL = BIT(NAPI_STATE_PREFER_BUSY_POLL),
  359. NAPIF_STATE_THREADED = BIT(NAPI_STATE_THREADED),
  360. NAPIF_STATE_SCHED_THREADED = BIT(NAPI_STATE_SCHED_THREADED),
  361. };
  362. enum gro_result {
  363. GRO_MERGED,
  364. GRO_MERGED_FREE,
  365. GRO_HELD,
  366. GRO_NORMAL,
  367. GRO_CONSUMED,
  368. };
  369. typedef enum gro_result gro_result_t;
  370. /*
  371. * enum rx_handler_result - Possible return values for rx_handlers.
  372. * @RX_HANDLER_CONSUMED: skb was consumed by rx_handler, do not process it
  373. * further.
  374. * @RX_HANDLER_ANOTHER: Do another round in receive path. This is indicated in
  375. * case skb->dev was changed by rx_handler.
  376. * @RX_HANDLER_EXACT: Force exact delivery, no wildcard.
  377. * @RX_HANDLER_PASS: Do nothing, pass the skb as if no rx_handler was called.
  378. *
  379. * rx_handlers are functions called from inside __netif_receive_skb(), to do
  380. * special processing of the skb, prior to delivery to protocol handlers.
  381. *
  382. * Currently, a net_device can only have a single rx_handler registered. Trying
  383. * to register a second rx_handler will return -EBUSY.
  384. *
  385. * To register a rx_handler on a net_device, use netdev_rx_handler_register().
  386. * To unregister a rx_handler on a net_device, use
  387. * netdev_rx_handler_unregister().
  388. *
  389. * Upon return, rx_handler is expected to tell __netif_receive_skb() what to
  390. * do with the skb.
  391. *
  392. * If the rx_handler consumed the skb in some way, it should return
  393. * RX_HANDLER_CONSUMED. This is appropriate when the rx_handler arranged for
  394. * the skb to be delivered in some other way.
  395. *
  396. * If the rx_handler changed skb->dev, to divert the skb to another
  397. * net_device, it should return RX_HANDLER_ANOTHER. The rx_handler for the
  398. * new device will be called if it exists.
  399. *
  400. * If the rx_handler decides the skb should be ignored, it should return
  401. * RX_HANDLER_EXACT. The skb will only be delivered to protocol handlers that
  402. * are registered on exact device (ptype->dev == skb->dev).
  403. *
  404. * If the rx_handler didn't change skb->dev, but wants the skb to be normally
  405. * delivered, it should return RX_HANDLER_PASS.
  406. *
  407. * A device without a registered rx_handler will behave as if rx_handler
  408. * returned RX_HANDLER_PASS.
  409. */
  410. enum rx_handler_result {
  411. RX_HANDLER_CONSUMED,
  412. RX_HANDLER_ANOTHER,
  413. RX_HANDLER_EXACT,
  414. RX_HANDLER_PASS,
  415. };
  416. typedef enum rx_handler_result rx_handler_result_t;
  417. typedef rx_handler_result_t rx_handler_func_t(struct sk_buff **pskb);
  418. void __napi_schedule(struct napi_struct *n);
  419. void __napi_schedule_irqoff(struct napi_struct *n);
  420. static inline bool napi_disable_pending(struct napi_struct *n)
  421. {
  422. return test_bit(NAPI_STATE_DISABLE, &n->state);
  423. }
  424. static inline bool napi_prefer_busy_poll(struct napi_struct *n)
  425. {
  426. return test_bit(NAPI_STATE_PREFER_BUSY_POLL, &n->state);
  427. }
  428. bool napi_schedule_prep(struct napi_struct *n);
  429. /**
  430. * napi_schedule - schedule NAPI poll
  431. * @n: NAPI context
  432. *
  433. * Schedule NAPI poll routine to be called if it is not already
  434. * running.
  435. */
  436. static inline void napi_schedule(struct napi_struct *n)
  437. {
  438. if (napi_schedule_prep(n))
  439. __napi_schedule(n);
  440. }
  441. /**
  442. * napi_schedule_irqoff - schedule NAPI poll
  443. * @n: NAPI context
  444. *
  445. * Variant of napi_schedule(), assuming hard irqs are masked.
  446. */
  447. static inline void napi_schedule_irqoff(struct napi_struct *n)
  448. {
  449. if (napi_schedule_prep(n))
  450. __napi_schedule_irqoff(n);
  451. }
  452. /* Try to reschedule poll. Called by dev->poll() after napi_complete(). */
  453. static inline bool napi_reschedule(struct napi_struct *napi)
  454. {
  455. if (napi_schedule_prep(napi)) {
  456. __napi_schedule(napi);
  457. return true;
  458. }
  459. return false;
  460. }
  461. bool napi_complete_done(struct napi_struct *n, int work_done);
  462. /**
  463. * napi_complete - NAPI processing complete
  464. * @n: NAPI context
  465. *
  466. * Mark NAPI processing as complete.
  467. * Consider using napi_complete_done() instead.
  468. * Return false if device should avoid rearming interrupts.
  469. */
  470. static inline bool napi_complete(struct napi_struct *n)
  471. {
  472. return napi_complete_done(n, 0);
  473. }
  474. int dev_set_threaded(struct net_device *dev, bool threaded);
  475. /**
  476. * napi_disable - prevent NAPI from scheduling
  477. * @n: NAPI context
  478. *
  479. * Stop NAPI from being scheduled on this context.
  480. * Waits till any outstanding processing completes.
  481. */
  482. void napi_disable(struct napi_struct *n);
  483. void napi_enable(struct napi_struct *n);
  484. /**
  485. * napi_synchronize - wait until NAPI is not running
  486. * @n: NAPI context
  487. *
  488. * Wait until NAPI is done being scheduled on this context.
  489. * Waits till any outstanding processing completes but
  490. * does not disable future activations.
  491. */
  492. static inline void napi_synchronize(const struct napi_struct *n)
  493. {
  494. if (IS_ENABLED(CONFIG_SMP))
  495. while (test_bit(NAPI_STATE_SCHED, &n->state))
  496. msleep(1);
  497. else
  498. barrier();
  499. }
  500. /**
  501. * napi_if_scheduled_mark_missed - if napi is running, set the
  502. * NAPIF_STATE_MISSED
  503. * @n: NAPI context
  504. *
  505. * If napi is running, set the NAPIF_STATE_MISSED, and return true if
  506. * NAPI is scheduled.
  507. **/
  508. static inline bool napi_if_scheduled_mark_missed(struct napi_struct *n)
  509. {
  510. unsigned long val, new;
  511. val = READ_ONCE(n->state);
  512. do {
  513. if (val & NAPIF_STATE_DISABLE)
  514. return true;
  515. if (!(val & NAPIF_STATE_SCHED))
  516. return false;
  517. new = val | NAPIF_STATE_MISSED;
  518. } while (!try_cmpxchg(&n->state, &val, new));
  519. return true;
  520. }
  521. enum netdev_queue_state_t {
  522. __QUEUE_STATE_DRV_XOFF,
  523. __QUEUE_STATE_STACK_XOFF,
  524. __QUEUE_STATE_FROZEN,
  525. };
  526. #define QUEUE_STATE_DRV_XOFF (1 << __QUEUE_STATE_DRV_XOFF)
  527. #define QUEUE_STATE_STACK_XOFF (1 << __QUEUE_STATE_STACK_XOFF)
  528. #define QUEUE_STATE_FROZEN (1 << __QUEUE_STATE_FROZEN)
  529. #define QUEUE_STATE_ANY_XOFF (QUEUE_STATE_DRV_XOFF | QUEUE_STATE_STACK_XOFF)
  530. #define QUEUE_STATE_ANY_XOFF_OR_FROZEN (QUEUE_STATE_ANY_XOFF | \
  531. QUEUE_STATE_FROZEN)
  532. #define QUEUE_STATE_DRV_XOFF_OR_FROZEN (QUEUE_STATE_DRV_XOFF | \
  533. QUEUE_STATE_FROZEN)
  534. /*
  535. * __QUEUE_STATE_DRV_XOFF is used by drivers to stop the transmit queue. The
  536. * netif_tx_* functions below are used to manipulate this flag. The
  537. * __QUEUE_STATE_STACK_XOFF flag is used by the stack to stop the transmit
  538. * queue independently. The netif_xmit_*stopped functions below are called
  539. * to check if the queue has been stopped by the driver or stack (either
  540. * of the XOFF bits are set in the state). Drivers should not need to call
  541. * netif_xmit*stopped functions, they should only be using netif_tx_*.
  542. */
  543. struct netdev_queue {
  544. /*
  545. * read-mostly part
  546. */
  547. struct net_device *dev;
  548. netdevice_tracker dev_tracker;
  549. struct Qdisc __rcu *qdisc;
  550. struct Qdisc __rcu *qdisc_sleeping;
  551. #ifdef CONFIG_SYSFS
  552. struct kobject kobj;
  553. #endif
  554. #if defined(CONFIG_XPS) && defined(CONFIG_NUMA)
  555. int numa_node;
  556. #endif
  557. unsigned long tx_maxrate;
  558. /*
  559. * Number of TX timeouts for this queue
  560. * (/sys/class/net/DEV/Q/trans_timeout)
  561. */
  562. atomic_long_t trans_timeout;
  563. /* Subordinate device that the queue has been assigned to */
  564. struct net_device *sb_dev;
  565. #ifdef CONFIG_XDP_SOCKETS
  566. struct xsk_buff_pool *pool;
  567. #endif
  568. /*
  569. * write-mostly part
  570. */
  571. spinlock_t _xmit_lock ____cacheline_aligned_in_smp;
  572. int xmit_lock_owner;
  573. /*
  574. * Time (in jiffies) of last Tx
  575. */
  576. unsigned long trans_start;
  577. unsigned long state;
  578. #ifdef CONFIG_BQL
  579. struct dql dql;
  580. #endif
  581. ANDROID_KABI_RESERVE(1);
  582. ANDROID_KABI_RESERVE(2);
  583. ANDROID_KABI_RESERVE(3);
  584. ANDROID_KABI_RESERVE(4);
  585. } ____cacheline_aligned_in_smp;
  586. extern int sysctl_fb_tunnels_only_for_init_net;
  587. extern int sysctl_devconf_inherit_init_net;
  588. /*
  589. * sysctl_fb_tunnels_only_for_init_net == 0 : For all netns
  590. * == 1 : For initns only
  591. * == 2 : For none.
  592. */
  593. static inline bool net_has_fallback_tunnels(const struct net *net)
  594. {
  595. #if IS_ENABLED(CONFIG_SYSCTL)
  596. int fb_tunnels_only_for_init_net = READ_ONCE(sysctl_fb_tunnels_only_for_init_net);
  597. return !fb_tunnels_only_for_init_net ||
  598. (net_eq(net, &init_net) && fb_tunnels_only_for_init_net == 1);
  599. #else
  600. return true;
  601. #endif
  602. }
  603. static inline int net_inherit_devconf(void)
  604. {
  605. #if IS_ENABLED(CONFIG_SYSCTL)
  606. return READ_ONCE(sysctl_devconf_inherit_init_net);
  607. #else
  608. return 0;
  609. #endif
  610. }
  611. static inline int netdev_queue_numa_node_read(const struct netdev_queue *q)
  612. {
  613. #if defined(CONFIG_XPS) && defined(CONFIG_NUMA)
  614. return q->numa_node;
  615. #else
  616. return NUMA_NO_NODE;
  617. #endif
  618. }
  619. static inline void netdev_queue_numa_node_write(struct netdev_queue *q, int node)
  620. {
  621. #if defined(CONFIG_XPS) && defined(CONFIG_NUMA)
  622. q->numa_node = node;
  623. #endif
  624. }
  625. #ifdef CONFIG_RPS
  626. /*
  627. * This structure holds an RPS map which can be of variable length. The
  628. * map is an array of CPUs.
  629. */
  630. struct rps_map {
  631. unsigned int len;
  632. struct rcu_head rcu;
  633. u16 cpus[];
  634. };
  635. #define RPS_MAP_SIZE(_num) (sizeof(struct rps_map) + ((_num) * sizeof(u16)))
  636. /*
  637. * The rps_dev_flow structure contains the mapping of a flow to a CPU, the
  638. * tail pointer for that CPU's input queue at the time of last enqueue, and
  639. * a hardware filter index.
  640. */
  641. struct rps_dev_flow {
  642. u16 cpu;
  643. u16 filter;
  644. unsigned int last_qtail;
  645. };
  646. #define RPS_NO_FILTER 0xffff
  647. /*
  648. * The rps_dev_flow_table structure contains a table of flow mappings.
  649. */
  650. struct rps_dev_flow_table {
  651. unsigned int mask;
  652. struct rcu_head rcu;
  653. struct rps_dev_flow flows[];
  654. };
  655. #define RPS_DEV_FLOW_TABLE_SIZE(_num) (sizeof(struct rps_dev_flow_table) + \
  656. ((_num) * sizeof(struct rps_dev_flow)))
  657. /*
  658. * The rps_sock_flow_table contains mappings of flows to the last CPU
  659. * on which they were processed by the application (set in recvmsg).
  660. * Each entry is a 32bit value. Upper part is the high-order bits
  661. * of flow hash, lower part is CPU number.
  662. * rps_cpu_mask is used to partition the space, depending on number of
  663. * possible CPUs : rps_cpu_mask = roundup_pow_of_two(nr_cpu_ids) - 1
  664. * For example, if 64 CPUs are possible, rps_cpu_mask = 0x3f,
  665. * meaning we use 32-6=26 bits for the hash.
  666. */
  667. struct rps_sock_flow_table {
  668. u32 mask;
  669. u32 ents[] ____cacheline_aligned_in_smp;
  670. };
  671. #define RPS_SOCK_FLOW_TABLE_SIZE(_num) (offsetof(struct rps_sock_flow_table, ents[_num]))
  672. #define RPS_NO_CPU 0xffff
  673. extern u32 rps_cpu_mask;
  674. extern struct rps_sock_flow_table __rcu *rps_sock_flow_table;
  675. static inline void rps_record_sock_flow(struct rps_sock_flow_table *table,
  676. u32 hash)
  677. {
  678. if (table && hash) {
  679. unsigned int index = hash & table->mask;
  680. u32 val = hash & ~rps_cpu_mask;
  681. /* We only give a hint, preemption can change CPU under us */
  682. val |= raw_smp_processor_id();
  683. /* The following WRITE_ONCE() is paired with the READ_ONCE()
  684. * here, and another one in get_rps_cpu().
  685. */
  686. if (READ_ONCE(table->ents[index]) != val)
  687. WRITE_ONCE(table->ents[index], val);
  688. }
  689. }
  690. #ifdef CONFIG_RFS_ACCEL
  691. bool rps_may_expire_flow(struct net_device *dev, u16 rxq_index, u32 flow_id,
  692. u16 filter_id);
  693. #endif
  694. #endif /* CONFIG_RPS */
  695. /* This structure contains an instance of an RX queue. */
  696. struct netdev_rx_queue {
  697. struct xdp_rxq_info xdp_rxq;
  698. #ifdef CONFIG_RPS
  699. struct rps_map __rcu *rps_map;
  700. struct rps_dev_flow_table __rcu *rps_flow_table;
  701. #endif
  702. struct kobject kobj;
  703. struct net_device *dev;
  704. netdevice_tracker dev_tracker;
  705. #ifdef CONFIG_XDP_SOCKETS
  706. struct xsk_buff_pool *pool;
  707. #endif
  708. ANDROID_KABI_RESERVE(1);
  709. ANDROID_KABI_RESERVE(2);
  710. ANDROID_KABI_RESERVE(3);
  711. ANDROID_KABI_RESERVE(4);
  712. } ____cacheline_aligned_in_smp;
  713. /*
  714. * RX queue sysfs structures and functions.
  715. */
  716. struct rx_queue_attribute {
  717. struct attribute attr;
  718. ssize_t (*show)(struct netdev_rx_queue *queue, char *buf);
  719. ssize_t (*store)(struct netdev_rx_queue *queue,
  720. const char *buf, size_t len);
  721. };
  722. /* XPS map type and offset of the xps map within net_device->xps_maps[]. */
  723. enum xps_map_type {
  724. XPS_CPUS = 0,
  725. XPS_RXQS,
  726. XPS_MAPS_MAX,
  727. };
  728. #ifdef CONFIG_XPS
  729. /*
  730. * This structure holds an XPS map which can be of variable length. The
  731. * map is an array of queues.
  732. */
  733. struct xps_map {
  734. unsigned int len;
  735. unsigned int alloc_len;
  736. struct rcu_head rcu;
  737. u16 queues[];
  738. };
  739. #define XPS_MAP_SIZE(_num) (sizeof(struct xps_map) + ((_num) * sizeof(u16)))
  740. #define XPS_MIN_MAP_ALLOC ((L1_CACHE_ALIGN(offsetof(struct xps_map, queues[1])) \
  741. - sizeof(struct xps_map)) / sizeof(u16))
  742. /*
  743. * This structure holds all XPS maps for device. Maps are indexed by CPU.
  744. *
  745. * We keep track of the number of cpus/rxqs used when the struct is allocated,
  746. * in nr_ids. This will help not accessing out-of-bound memory.
  747. *
  748. * We keep track of the number of traffic classes used when the struct is
  749. * allocated, in num_tc. This will be used to navigate the maps, to ensure we're
  750. * not crossing its upper bound, as the original dev->num_tc can be updated in
  751. * the meantime.
  752. */
  753. struct xps_dev_maps {
  754. struct rcu_head rcu;
  755. unsigned int nr_ids;
  756. s16 num_tc;
  757. struct xps_map __rcu *attr_map[]; /* Either CPUs map or RXQs map */
  758. };
  759. #define XPS_CPU_DEV_MAPS_SIZE(_tcs) (sizeof(struct xps_dev_maps) + \
  760. (nr_cpu_ids * (_tcs) * sizeof(struct xps_map *)))
  761. #define XPS_RXQ_DEV_MAPS_SIZE(_tcs, _rxqs) (sizeof(struct xps_dev_maps) +\
  762. (_rxqs * (_tcs) * sizeof(struct xps_map *)))
  763. #endif /* CONFIG_XPS */
  764. #define TC_MAX_QUEUE 16
  765. #define TC_BITMASK 15
  766. /* HW offloaded queuing disciplines txq count and offset maps */
  767. struct netdev_tc_txq {
  768. u16 count;
  769. u16 offset;
  770. };
  771. #if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE)
  772. /*
  773. * This structure is to hold information about the device
  774. * configured to run FCoE protocol stack.
  775. */
  776. struct netdev_fcoe_hbainfo {
  777. char manufacturer[64];
  778. char serial_number[64];
  779. char hardware_version[64];
  780. char driver_version[64];
  781. char optionrom_version[64];
  782. char firmware_version[64];
  783. char model[256];
  784. char model_description[256];
  785. };
  786. #endif
  787. #define MAX_PHYS_ITEM_ID_LEN 32
  788. /* This structure holds a unique identifier to identify some
  789. * physical item (port for example) used by a netdevice.
  790. */
  791. struct netdev_phys_item_id {
  792. unsigned char id[MAX_PHYS_ITEM_ID_LEN];
  793. unsigned char id_len;
  794. };
  795. static inline bool netdev_phys_item_id_same(struct netdev_phys_item_id *a,
  796. struct netdev_phys_item_id *b)
  797. {
  798. return a->id_len == b->id_len &&
  799. memcmp(a->id, b->id, a->id_len) == 0;
  800. }
  801. typedef u16 (*select_queue_fallback_t)(struct net_device *dev,
  802. struct sk_buff *skb,
  803. struct net_device *sb_dev);
  804. enum net_device_path_type {
  805. DEV_PATH_ETHERNET = 0,
  806. DEV_PATH_VLAN,
  807. DEV_PATH_BRIDGE,
  808. DEV_PATH_PPPOE,
  809. DEV_PATH_DSA,
  810. DEV_PATH_MTK_WDMA,
  811. };
  812. struct net_device_path {
  813. enum net_device_path_type type;
  814. const struct net_device *dev;
  815. union {
  816. struct {
  817. u16 id;
  818. __be16 proto;
  819. u8 h_dest[ETH_ALEN];
  820. } encap;
  821. struct {
  822. enum {
  823. DEV_PATH_BR_VLAN_KEEP,
  824. DEV_PATH_BR_VLAN_TAG,
  825. DEV_PATH_BR_VLAN_UNTAG,
  826. DEV_PATH_BR_VLAN_UNTAG_HW,
  827. } vlan_mode;
  828. u16 vlan_id;
  829. __be16 vlan_proto;
  830. } bridge;
  831. struct {
  832. int port;
  833. u16 proto;
  834. } dsa;
  835. struct {
  836. u8 wdma_idx;
  837. u8 queue;
  838. u16 wcid;
  839. u8 bss;
  840. } mtk_wdma;
  841. };
  842. };
  843. #define NET_DEVICE_PATH_STACK_MAX 5
  844. #define NET_DEVICE_PATH_VLAN_MAX 2
  845. struct net_device_path_stack {
  846. int num_paths;
  847. struct net_device_path path[NET_DEVICE_PATH_STACK_MAX];
  848. };
  849. struct net_device_path_ctx {
  850. const struct net_device *dev;
  851. u8 daddr[ETH_ALEN];
  852. int num_vlans;
  853. struct {
  854. u16 id;
  855. __be16 proto;
  856. } vlan[NET_DEVICE_PATH_VLAN_MAX];
  857. };
  858. enum tc_setup_type {
  859. TC_QUERY_CAPS,
  860. TC_SETUP_QDISC_MQPRIO,
  861. TC_SETUP_CLSU32,
  862. TC_SETUP_CLSFLOWER,
  863. TC_SETUP_CLSMATCHALL,
  864. TC_SETUP_CLSBPF,
  865. TC_SETUP_BLOCK,
  866. TC_SETUP_QDISC_CBS,
  867. TC_SETUP_QDISC_RED,
  868. TC_SETUP_QDISC_PRIO,
  869. TC_SETUP_QDISC_MQ,
  870. TC_SETUP_QDISC_ETF,
  871. TC_SETUP_ROOT_QDISC,
  872. TC_SETUP_QDISC_GRED,
  873. TC_SETUP_QDISC_TAPRIO,
  874. TC_SETUP_FT,
  875. TC_SETUP_QDISC_ETS,
  876. TC_SETUP_QDISC_TBF,
  877. TC_SETUP_QDISC_FIFO,
  878. TC_SETUP_QDISC_HTB,
  879. TC_SETUP_ACT,
  880. };
  881. /* These structures hold the attributes of bpf state that are being passed
  882. * to the netdevice through the bpf op.
  883. */
  884. enum bpf_netdev_command {
  885. /* Set or clear a bpf program used in the earliest stages of packet
  886. * rx. The prog will have been loaded as BPF_PROG_TYPE_XDP. The callee
  887. * is responsible for calling bpf_prog_put on any old progs that are
  888. * stored. In case of error, the callee need not release the new prog
  889. * reference, but on success it takes ownership and must bpf_prog_put
  890. * when it is no longer used.
  891. */
  892. XDP_SETUP_PROG,
  893. XDP_SETUP_PROG_HW,
  894. /* BPF program for offload callbacks, invoked at program load time. */
  895. BPF_OFFLOAD_MAP_ALLOC,
  896. BPF_OFFLOAD_MAP_FREE,
  897. XDP_SETUP_XSK_POOL,
  898. };
  899. struct bpf_prog_offload_ops;
  900. struct netlink_ext_ack;
  901. struct xdp_umem;
  902. struct xdp_dev_bulk_queue;
  903. struct bpf_xdp_link;
  904. enum bpf_xdp_mode {
  905. XDP_MODE_SKB = 0,
  906. XDP_MODE_DRV = 1,
  907. XDP_MODE_HW = 2,
  908. __MAX_XDP_MODE
  909. };
  910. struct bpf_xdp_entity {
  911. struct bpf_prog *prog;
  912. struct bpf_xdp_link *link;
  913. };
  914. struct netdev_bpf {
  915. enum bpf_netdev_command command;
  916. union {
  917. /* XDP_SETUP_PROG */
  918. struct {
  919. u32 flags;
  920. struct bpf_prog *prog;
  921. struct netlink_ext_ack *extack;
  922. };
  923. /* BPF_OFFLOAD_MAP_ALLOC, BPF_OFFLOAD_MAP_FREE */
  924. struct {
  925. struct bpf_offloaded_map *offmap;
  926. };
  927. /* XDP_SETUP_XSK_POOL */
  928. struct {
  929. struct xsk_buff_pool *pool;
  930. u16 queue_id;
  931. } xsk;
  932. };
  933. };
  934. /* Flags for ndo_xsk_wakeup. */
  935. #define XDP_WAKEUP_RX (1 << 0)
  936. #define XDP_WAKEUP_TX (1 << 1)
  937. #ifdef CONFIG_XFRM_OFFLOAD
  938. struct xfrmdev_ops {
  939. int (*xdo_dev_state_add) (struct xfrm_state *x);
  940. void (*xdo_dev_state_delete) (struct xfrm_state *x);
  941. void (*xdo_dev_state_free) (struct xfrm_state *x);
  942. bool (*xdo_dev_offload_ok) (struct sk_buff *skb,
  943. struct xfrm_state *x);
  944. void (*xdo_dev_state_advance_esn) (struct xfrm_state *x);
  945. ANDROID_KABI_RESERVE(1);
  946. ANDROID_KABI_RESERVE(2);
  947. ANDROID_KABI_RESERVE(3);
  948. ANDROID_KABI_RESERVE(4);
  949. };
  950. #endif
  951. struct dev_ifalias {
  952. struct rcu_head rcuhead;
  953. char ifalias[];
  954. };
  955. struct devlink;
  956. struct tlsdev_ops;
  957. struct netdev_net_notifier {
  958. struct list_head list;
  959. struct notifier_block *nb;
  960. };
  961. /*
  962. * This structure defines the management hooks for network devices.
  963. * The following hooks can be defined; unless noted otherwise, they are
  964. * optional and can be filled with a null pointer.
  965. *
  966. * int (*ndo_init)(struct net_device *dev);
  967. * This function is called once when a network device is registered.
  968. * The network device can use this for any late stage initialization
  969. * or semantic validation. It can fail with an error code which will
  970. * be propagated back to register_netdev.
  971. *
  972. * void (*ndo_uninit)(struct net_device *dev);
  973. * This function is called when device is unregistered or when registration
  974. * fails. It is not called if init fails.
  975. *
  976. * int (*ndo_open)(struct net_device *dev);
  977. * This function is called when a network device transitions to the up
  978. * state.
  979. *
  980. * int (*ndo_stop)(struct net_device *dev);
  981. * This function is called when a network device transitions to the down
  982. * state.
  983. *
  984. * netdev_tx_t (*ndo_start_xmit)(struct sk_buff *skb,
  985. * struct net_device *dev);
  986. * Called when a packet needs to be transmitted.
  987. * Returns NETDEV_TX_OK. Can return NETDEV_TX_BUSY, but you should stop
  988. * the queue before that can happen; it's for obsolete devices and weird
  989. * corner cases, but the stack really does a non-trivial amount
  990. * of useless work if you return NETDEV_TX_BUSY.
  991. * Required; cannot be NULL.
  992. *
  993. * netdev_features_t (*ndo_features_check)(struct sk_buff *skb,
  994. * struct net_device *dev
  995. * netdev_features_t features);
  996. * Called by core transmit path to determine if device is capable of
  997. * performing offload operations on a given packet. This is to give
  998. * the device an opportunity to implement any restrictions that cannot
  999. * be otherwise expressed by feature flags. The check is called with
  1000. * the set of features that the stack has calculated and it returns
  1001. * those the driver believes to be appropriate.
  1002. *
  1003. * u16 (*ndo_select_queue)(struct net_device *dev, struct sk_buff *skb,
  1004. * struct net_device *sb_dev);
  1005. * Called to decide which queue to use when device supports multiple
  1006. * transmit queues.
  1007. *
  1008. * void (*ndo_change_rx_flags)(struct net_device *dev, int flags);
  1009. * This function is called to allow device receiver to make
  1010. * changes to configuration when multicast or promiscuous is enabled.
  1011. *
  1012. * void (*ndo_set_rx_mode)(struct net_device *dev);
  1013. * This function is called device changes address list filtering.
  1014. * If driver handles unicast address filtering, it should set
  1015. * IFF_UNICAST_FLT in its priv_flags.
  1016. *
  1017. * int (*ndo_set_mac_address)(struct net_device *dev, void *addr);
  1018. * This function is called when the Media Access Control address
  1019. * needs to be changed. If this interface is not defined, the
  1020. * MAC address can not be changed.
  1021. *
  1022. * int (*ndo_validate_addr)(struct net_device *dev);
  1023. * Test if Media Access Control address is valid for the device.
  1024. *
  1025. * int (*ndo_do_ioctl)(struct net_device *dev, struct ifreq *ifr, int cmd);
  1026. * Old-style ioctl entry point. This is used internally by the
  1027. * appletalk and ieee802154 subsystems but is no longer called by
  1028. * the device ioctl handler.
  1029. *
  1030. * int (*ndo_siocbond)(struct net_device *dev, struct ifreq *ifr, int cmd);
  1031. * Used by the bonding driver for its device specific ioctls:
  1032. * SIOCBONDENSLAVE, SIOCBONDRELEASE, SIOCBONDSETHWADDR, SIOCBONDCHANGEACTIVE,
  1033. * SIOCBONDSLAVEINFOQUERY, and SIOCBONDINFOQUERY
  1034. *
  1035. * * int (*ndo_eth_ioctl)(struct net_device *dev, struct ifreq *ifr, int cmd);
  1036. * Called for ethernet specific ioctls: SIOCGMIIPHY, SIOCGMIIREG,
  1037. * SIOCSMIIREG, SIOCSHWTSTAMP and SIOCGHWTSTAMP.
  1038. *
  1039. * int (*ndo_set_config)(struct net_device *dev, struct ifmap *map);
  1040. * Used to set network devices bus interface parameters. This interface
  1041. * is retained for legacy reasons; new devices should use the bus
  1042. * interface (PCI) for low level management.
  1043. *
  1044. * int (*ndo_change_mtu)(struct net_device *dev, int new_mtu);
  1045. * Called when a user wants to change the Maximum Transfer Unit
  1046. * of a device.
  1047. *
  1048. * void (*ndo_tx_timeout)(struct net_device *dev, unsigned int txqueue);
  1049. * Callback used when the transmitter has not made any progress
  1050. * for dev->watchdog ticks.
  1051. *
  1052. * void (*ndo_get_stats64)(struct net_device *dev,
  1053. * struct rtnl_link_stats64 *storage);
  1054. * struct net_device_stats* (*ndo_get_stats)(struct net_device *dev);
  1055. * Called when a user wants to get the network device usage
  1056. * statistics. Drivers must do one of the following:
  1057. * 1. Define @ndo_get_stats64 to fill in a zero-initialised
  1058. * rtnl_link_stats64 structure passed by the caller.
  1059. * 2. Define @ndo_get_stats to update a net_device_stats structure
  1060. * (which should normally be dev->stats) and return a pointer to
  1061. * it. The structure may be changed asynchronously only if each
  1062. * field is written atomically.
  1063. * 3. Update dev->stats asynchronously and atomically, and define
  1064. * neither operation.
  1065. *
  1066. * bool (*ndo_has_offload_stats)(const struct net_device *dev, int attr_id)
  1067. * Return true if this device supports offload stats of this attr_id.
  1068. *
  1069. * int (*ndo_get_offload_stats)(int attr_id, const struct net_device *dev,
  1070. * void *attr_data)
  1071. * Get statistics for offload operations by attr_id. Write it into the
  1072. * attr_data pointer.
  1073. *
  1074. * int (*ndo_vlan_rx_add_vid)(struct net_device *dev, __be16 proto, u16 vid);
  1075. * If device supports VLAN filtering this function is called when a
  1076. * VLAN id is registered.
  1077. *
  1078. * int (*ndo_vlan_rx_kill_vid)(struct net_device *dev, __be16 proto, u16 vid);
  1079. * If device supports VLAN filtering this function is called when a
  1080. * VLAN id is unregistered.
  1081. *
  1082. * void (*ndo_poll_controller)(struct net_device *dev);
  1083. *
  1084. * SR-IOV management functions.
  1085. * int (*ndo_set_vf_mac)(struct net_device *dev, int vf, u8* mac);
  1086. * int (*ndo_set_vf_vlan)(struct net_device *dev, int vf, u16 vlan,
  1087. * u8 qos, __be16 proto);
  1088. * int (*ndo_set_vf_rate)(struct net_device *dev, int vf, int min_tx_rate,
  1089. * int max_tx_rate);
  1090. * int (*ndo_set_vf_spoofchk)(struct net_device *dev, int vf, bool setting);
  1091. * int (*ndo_set_vf_trust)(struct net_device *dev, int vf, bool setting);
  1092. * int (*ndo_get_vf_config)(struct net_device *dev,
  1093. * int vf, struct ifla_vf_info *ivf);
  1094. * int (*ndo_set_vf_link_state)(struct net_device *dev, int vf, int link_state);
  1095. * int (*ndo_set_vf_port)(struct net_device *dev, int vf,
  1096. * struct nlattr *port[]);
  1097. *
  1098. * Enable or disable the VF ability to query its RSS Redirection Table and
  1099. * Hash Key. This is needed since on some devices VF share this information
  1100. * with PF and querying it may introduce a theoretical security risk.
  1101. * int (*ndo_set_vf_rss_query_en)(struct net_device *dev, int vf, bool setting);
  1102. * int (*ndo_get_vf_port)(struct net_device *dev, int vf, struct sk_buff *skb);
  1103. * int (*ndo_setup_tc)(struct net_device *dev, enum tc_setup_type type,
  1104. * void *type_data);
  1105. * Called to setup any 'tc' scheduler, classifier or action on @dev.
  1106. * This is always called from the stack with the rtnl lock held and netif
  1107. * tx queues stopped. This allows the netdevice to perform queue
  1108. * management safely.
  1109. *
  1110. * Fiber Channel over Ethernet (FCoE) offload functions.
  1111. * int (*ndo_fcoe_enable)(struct net_device *dev);
  1112. * Called when the FCoE protocol stack wants to start using LLD for FCoE
  1113. * so the underlying device can perform whatever needed configuration or
  1114. * initialization to support acceleration of FCoE traffic.
  1115. *
  1116. * int (*ndo_fcoe_disable)(struct net_device *dev);
  1117. * Called when the FCoE protocol stack wants to stop using LLD for FCoE
  1118. * so the underlying device can perform whatever needed clean-ups to
  1119. * stop supporting acceleration of FCoE traffic.
  1120. *
  1121. * int (*ndo_fcoe_ddp_setup)(struct net_device *dev, u16 xid,
  1122. * struct scatterlist *sgl, unsigned int sgc);
  1123. * Called when the FCoE Initiator wants to initialize an I/O that
  1124. * is a possible candidate for Direct Data Placement (DDP). The LLD can
  1125. * perform necessary setup and returns 1 to indicate the device is set up
  1126. * successfully to perform DDP on this I/O, otherwise this returns 0.
  1127. *
  1128. * int (*ndo_fcoe_ddp_done)(struct net_device *dev, u16 xid);
  1129. * Called when the FCoE Initiator/Target is done with the DDPed I/O as
  1130. * indicated by the FC exchange id 'xid', so the underlying device can
  1131. * clean up and reuse resources for later DDP requests.
  1132. *
  1133. * int (*ndo_fcoe_ddp_target)(struct net_device *dev, u16 xid,
  1134. * struct scatterlist *sgl, unsigned int sgc);
  1135. * Called when the FCoE Target wants to initialize an I/O that
  1136. * is a possible candidate for Direct Data Placement (DDP). The LLD can
  1137. * perform necessary setup and returns 1 to indicate the device is set up
  1138. * successfully to perform DDP on this I/O, otherwise this returns 0.
  1139. *
  1140. * int (*ndo_fcoe_get_hbainfo)(struct net_device *dev,
  1141. * struct netdev_fcoe_hbainfo *hbainfo);
  1142. * Called when the FCoE Protocol stack wants information on the underlying
  1143. * device. This information is utilized by the FCoE protocol stack to
  1144. * register attributes with Fiber Channel management service as per the
  1145. * FC-GS Fabric Device Management Information(FDMI) specification.
  1146. *
  1147. * int (*ndo_fcoe_get_wwn)(struct net_device *dev, u64 *wwn, int type);
  1148. * Called when the underlying device wants to override default World Wide
  1149. * Name (WWN) generation mechanism in FCoE protocol stack to pass its own
  1150. * World Wide Port Name (WWPN) or World Wide Node Name (WWNN) to the FCoE
  1151. * protocol stack to use.
  1152. *
  1153. * RFS acceleration.
  1154. * int (*ndo_rx_flow_steer)(struct net_device *dev, const struct sk_buff *skb,
  1155. * u16 rxq_index, u32 flow_id);
  1156. * Set hardware filter for RFS. rxq_index is the target queue index;
  1157. * flow_id is a flow ID to be passed to rps_may_expire_flow() later.
  1158. * Return the filter ID on success, or a negative error code.
  1159. *
  1160. * Slave management functions (for bridge, bonding, etc).
  1161. * int (*ndo_add_slave)(struct net_device *dev, struct net_device *slave_dev);
  1162. * Called to make another netdev an underling.
  1163. *
  1164. * int (*ndo_del_slave)(struct net_device *dev, struct net_device *slave_dev);
  1165. * Called to release previously enslaved netdev.
  1166. *
  1167. * struct net_device *(*ndo_get_xmit_slave)(struct net_device *dev,
  1168. * struct sk_buff *skb,
  1169. * bool all_slaves);
  1170. * Get the xmit slave of master device. If all_slaves is true, function
  1171. * assume all the slaves can transmit.
  1172. *
  1173. * Feature/offload setting functions.
  1174. * netdev_features_t (*ndo_fix_features)(struct net_device *dev,
  1175. * netdev_features_t features);
  1176. * Adjusts the requested feature flags according to device-specific
  1177. * constraints, and returns the resulting flags. Must not modify
  1178. * the device state.
  1179. *
  1180. * int (*ndo_set_features)(struct net_device *dev, netdev_features_t features);
  1181. * Called to update device configuration to new features. Passed
  1182. * feature set might be less than what was returned by ndo_fix_features()).
  1183. * Must return >0 or -errno if it changed dev->features itself.
  1184. *
  1185. * int (*ndo_fdb_add)(struct ndmsg *ndm, struct nlattr *tb[],
  1186. * struct net_device *dev,
  1187. * const unsigned char *addr, u16 vid, u16 flags,
  1188. * struct netlink_ext_ack *extack);
  1189. * Adds an FDB entry to dev for addr.
  1190. * int (*ndo_fdb_del)(struct ndmsg *ndm, struct nlattr *tb[],
  1191. * struct net_device *dev,
  1192. * const unsigned char *addr, u16 vid)
  1193. * Deletes the FDB entry from dev coresponding to addr.
  1194. * int (*ndo_fdb_del_bulk)(struct ndmsg *ndm, struct nlattr *tb[],
  1195. * struct net_device *dev,
  1196. * u16 vid,
  1197. * struct netlink_ext_ack *extack);
  1198. * int (*ndo_fdb_dump)(struct sk_buff *skb, struct netlink_callback *cb,
  1199. * struct net_device *dev, struct net_device *filter_dev,
  1200. * int *idx)
  1201. * Used to add FDB entries to dump requests. Implementers should add
  1202. * entries to skb and update idx with the number of entries.
  1203. *
  1204. * int (*ndo_bridge_setlink)(struct net_device *dev, struct nlmsghdr *nlh,
  1205. * u16 flags, struct netlink_ext_ack *extack)
  1206. * int (*ndo_bridge_getlink)(struct sk_buff *skb, u32 pid, u32 seq,
  1207. * struct net_device *dev, u32 filter_mask,
  1208. * int nlflags)
  1209. * int (*ndo_bridge_dellink)(struct net_device *dev, struct nlmsghdr *nlh,
  1210. * u16 flags);
  1211. *
  1212. * int (*ndo_change_carrier)(struct net_device *dev, bool new_carrier);
  1213. * Called to change device carrier. Soft-devices (like dummy, team, etc)
  1214. * which do not represent real hardware may define this to allow their
  1215. * userspace components to manage their virtual carrier state. Devices
  1216. * that determine carrier state from physical hardware properties (eg
  1217. * network cables) or protocol-dependent mechanisms (eg
  1218. * USB_CDC_NOTIFY_NETWORK_CONNECTION) should NOT implement this function.
  1219. *
  1220. * int (*ndo_get_phys_port_id)(struct net_device *dev,
  1221. * struct netdev_phys_item_id *ppid);
  1222. * Called to get ID of physical port of this device. If driver does
  1223. * not implement this, it is assumed that the hw is not able to have
  1224. * multiple net devices on single physical port.
  1225. *
  1226. * int (*ndo_get_port_parent_id)(struct net_device *dev,
  1227. * struct netdev_phys_item_id *ppid)
  1228. * Called to get the parent ID of the physical port of this device.
  1229. *
  1230. * void* (*ndo_dfwd_add_station)(struct net_device *pdev,
  1231. * struct net_device *dev)
  1232. * Called by upper layer devices to accelerate switching or other
  1233. * station functionality into hardware. 'pdev is the lowerdev
  1234. * to use for the offload and 'dev' is the net device that will
  1235. * back the offload. Returns a pointer to the private structure
  1236. * the upper layer will maintain.
  1237. * void (*ndo_dfwd_del_station)(struct net_device *pdev, void *priv)
  1238. * Called by upper layer device to delete the station created
  1239. * by 'ndo_dfwd_add_station'. 'pdev' is the net device backing
  1240. * the station and priv is the structure returned by the add
  1241. * operation.
  1242. * int (*ndo_set_tx_maxrate)(struct net_device *dev,
  1243. * int queue_index, u32 maxrate);
  1244. * Called when a user wants to set a max-rate limitation of specific
  1245. * TX queue.
  1246. * int (*ndo_get_iflink)(const struct net_device *dev);
  1247. * Called to get the iflink value of this device.
  1248. * int (*ndo_fill_metadata_dst)(struct net_device *dev, struct sk_buff *skb);
  1249. * This function is used to get egress tunnel information for given skb.
  1250. * This is useful for retrieving outer tunnel header parameters while
  1251. * sampling packet.
  1252. * void (*ndo_set_rx_headroom)(struct net_device *dev, int needed_headroom);
  1253. * This function is used to specify the headroom that the skb must
  1254. * consider when allocation skb during packet reception. Setting
  1255. * appropriate rx headroom value allows avoiding skb head copy on
  1256. * forward. Setting a negative value resets the rx headroom to the
  1257. * default value.
  1258. * int (*ndo_bpf)(struct net_device *dev, struct netdev_bpf *bpf);
  1259. * This function is used to set or query state related to XDP on the
  1260. * netdevice and manage BPF offload. See definition of
  1261. * enum bpf_netdev_command for details.
  1262. * int (*ndo_xdp_xmit)(struct net_device *dev, int n, struct xdp_frame **xdp,
  1263. * u32 flags);
  1264. * This function is used to submit @n XDP packets for transmit on a
  1265. * netdevice. Returns number of frames successfully transmitted, frames
  1266. * that got dropped are freed/returned via xdp_return_frame().
  1267. * Returns negative number, means general error invoking ndo, meaning
  1268. * no frames were xmit'ed and core-caller will free all frames.
  1269. * struct net_device *(*ndo_xdp_get_xmit_slave)(struct net_device *dev,
  1270. * struct xdp_buff *xdp);
  1271. * Get the xmit slave of master device based on the xdp_buff.
  1272. * int (*ndo_xsk_wakeup)(struct net_device *dev, u32 queue_id, u32 flags);
  1273. * This function is used to wake up the softirq, ksoftirqd or kthread
  1274. * responsible for sending and/or receiving packets on a specific
  1275. * queue id bound to an AF_XDP socket. The flags field specifies if
  1276. * only RX, only Tx, or both should be woken up using the flags
  1277. * XDP_WAKEUP_RX and XDP_WAKEUP_TX.
  1278. * struct devlink_port *(*ndo_get_devlink_port)(struct net_device *dev);
  1279. * Get devlink port instance associated with a given netdev.
  1280. * Called with a reference on the netdevice and devlink locks only,
  1281. * rtnl_lock is not held.
  1282. * int (*ndo_tunnel_ctl)(struct net_device *dev, struct ip_tunnel_parm *p,
  1283. * int cmd);
  1284. * Add, change, delete or get information on an IPv4 tunnel.
  1285. * struct net_device *(*ndo_get_peer_dev)(struct net_device *dev);
  1286. * If a device is paired with a peer device, return the peer instance.
  1287. * The caller must be under RCU read context.
  1288. * int (*ndo_fill_forward_path)(struct net_device_path_ctx *ctx, struct net_device_path *path);
  1289. * Get the forwarding path to reach the real device from the HW destination address
  1290. * ktime_t (*ndo_get_tstamp)(struct net_device *dev,
  1291. * const struct skb_shared_hwtstamps *hwtstamps,
  1292. * bool cycles);
  1293. * Get hardware timestamp based on normal/adjustable time or free running
  1294. * cycle counter. This function is required if physical clock supports a
  1295. * free running cycle counter.
  1296. */
  1297. struct net_device_ops {
  1298. int (*ndo_init)(struct net_device *dev);
  1299. void (*ndo_uninit)(struct net_device *dev);
  1300. int (*ndo_open)(struct net_device *dev);
  1301. int (*ndo_stop)(struct net_device *dev);
  1302. netdev_tx_t (*ndo_start_xmit)(struct sk_buff *skb,
  1303. struct net_device *dev);
  1304. netdev_features_t (*ndo_features_check)(struct sk_buff *skb,
  1305. struct net_device *dev,
  1306. netdev_features_t features);
  1307. u16 (*ndo_select_queue)(struct net_device *dev,
  1308. struct sk_buff *skb,
  1309. struct net_device *sb_dev);
  1310. void (*ndo_change_rx_flags)(struct net_device *dev,
  1311. int flags);
  1312. void (*ndo_set_rx_mode)(struct net_device *dev);
  1313. int (*ndo_set_mac_address)(struct net_device *dev,
  1314. void *addr);
  1315. int (*ndo_validate_addr)(struct net_device *dev);
  1316. int (*ndo_do_ioctl)(struct net_device *dev,
  1317. struct ifreq *ifr, int cmd);
  1318. int (*ndo_eth_ioctl)(struct net_device *dev,
  1319. struct ifreq *ifr, int cmd);
  1320. int (*ndo_siocbond)(struct net_device *dev,
  1321. struct ifreq *ifr, int cmd);
  1322. int (*ndo_siocwandev)(struct net_device *dev,
  1323. struct if_settings *ifs);
  1324. int (*ndo_siocdevprivate)(struct net_device *dev,
  1325. struct ifreq *ifr,
  1326. void __user *data, int cmd);
  1327. int (*ndo_set_config)(struct net_device *dev,
  1328. struct ifmap *map);
  1329. int (*ndo_change_mtu)(struct net_device *dev,
  1330. int new_mtu);
  1331. int (*ndo_neigh_setup)(struct net_device *dev,
  1332. struct neigh_parms *);
  1333. void (*ndo_tx_timeout) (struct net_device *dev,
  1334. unsigned int txqueue);
  1335. void (*ndo_get_stats64)(struct net_device *dev,
  1336. struct rtnl_link_stats64 *storage);
  1337. bool (*ndo_has_offload_stats)(const struct net_device *dev, int attr_id);
  1338. int (*ndo_get_offload_stats)(int attr_id,
  1339. const struct net_device *dev,
  1340. void *attr_data);
  1341. struct net_device_stats* (*ndo_get_stats)(struct net_device *dev);
  1342. int (*ndo_vlan_rx_add_vid)(struct net_device *dev,
  1343. __be16 proto, u16 vid);
  1344. int (*ndo_vlan_rx_kill_vid)(struct net_device *dev,
  1345. __be16 proto, u16 vid);
  1346. #ifdef CONFIG_NET_POLL_CONTROLLER
  1347. void (*ndo_poll_controller)(struct net_device *dev);
  1348. int (*ndo_netpoll_setup)(struct net_device *dev,
  1349. struct netpoll_info *info);
  1350. void (*ndo_netpoll_cleanup)(struct net_device *dev);
  1351. #endif
  1352. int (*ndo_set_vf_mac)(struct net_device *dev,
  1353. int queue, u8 *mac);
  1354. int (*ndo_set_vf_vlan)(struct net_device *dev,
  1355. int queue, u16 vlan,
  1356. u8 qos, __be16 proto);
  1357. int (*ndo_set_vf_rate)(struct net_device *dev,
  1358. int vf, int min_tx_rate,
  1359. int max_tx_rate);
  1360. int (*ndo_set_vf_spoofchk)(struct net_device *dev,
  1361. int vf, bool setting);
  1362. int (*ndo_set_vf_trust)(struct net_device *dev,
  1363. int vf, bool setting);
  1364. int (*ndo_get_vf_config)(struct net_device *dev,
  1365. int vf,
  1366. struct ifla_vf_info *ivf);
  1367. int (*ndo_set_vf_link_state)(struct net_device *dev,
  1368. int vf, int link_state);
  1369. int (*ndo_get_vf_stats)(struct net_device *dev,
  1370. int vf,
  1371. struct ifla_vf_stats
  1372. *vf_stats);
  1373. int (*ndo_set_vf_port)(struct net_device *dev,
  1374. int vf,
  1375. struct nlattr *port[]);
  1376. int (*ndo_get_vf_port)(struct net_device *dev,
  1377. int vf, struct sk_buff *skb);
  1378. int (*ndo_get_vf_guid)(struct net_device *dev,
  1379. int vf,
  1380. struct ifla_vf_guid *node_guid,
  1381. struct ifla_vf_guid *port_guid);
  1382. int (*ndo_set_vf_guid)(struct net_device *dev,
  1383. int vf, u64 guid,
  1384. int guid_type);
  1385. int (*ndo_set_vf_rss_query_en)(
  1386. struct net_device *dev,
  1387. int vf, bool setting);
  1388. int (*ndo_setup_tc)(struct net_device *dev,
  1389. enum tc_setup_type type,
  1390. void *type_data);
  1391. #if IS_ENABLED(CONFIG_FCOE)
  1392. int (*ndo_fcoe_enable)(struct net_device *dev);
  1393. int (*ndo_fcoe_disable)(struct net_device *dev);
  1394. int (*ndo_fcoe_ddp_setup)(struct net_device *dev,
  1395. u16 xid,
  1396. struct scatterlist *sgl,
  1397. unsigned int sgc);
  1398. int (*ndo_fcoe_ddp_done)(struct net_device *dev,
  1399. u16 xid);
  1400. int (*ndo_fcoe_ddp_target)(struct net_device *dev,
  1401. u16 xid,
  1402. struct scatterlist *sgl,
  1403. unsigned int sgc);
  1404. int (*ndo_fcoe_get_hbainfo)(struct net_device *dev,
  1405. struct netdev_fcoe_hbainfo *hbainfo);
  1406. #endif
  1407. #if IS_ENABLED(CONFIG_LIBFCOE)
  1408. #define NETDEV_FCOE_WWNN 0
  1409. #define NETDEV_FCOE_WWPN 1
  1410. int (*ndo_fcoe_get_wwn)(struct net_device *dev,
  1411. u64 *wwn, int type);
  1412. #endif
  1413. #ifdef CONFIG_RFS_ACCEL
  1414. int (*ndo_rx_flow_steer)(struct net_device *dev,
  1415. const struct sk_buff *skb,
  1416. u16 rxq_index,
  1417. u32 flow_id);
  1418. #endif
  1419. int (*ndo_add_slave)(struct net_device *dev,
  1420. struct net_device *slave_dev,
  1421. struct netlink_ext_ack *extack);
  1422. int (*ndo_del_slave)(struct net_device *dev,
  1423. struct net_device *slave_dev);
  1424. struct net_device* (*ndo_get_xmit_slave)(struct net_device *dev,
  1425. struct sk_buff *skb,
  1426. bool all_slaves);
  1427. struct net_device* (*ndo_sk_get_lower_dev)(struct net_device *dev,
  1428. struct sock *sk);
  1429. netdev_features_t (*ndo_fix_features)(struct net_device *dev,
  1430. netdev_features_t features);
  1431. int (*ndo_set_features)(struct net_device *dev,
  1432. netdev_features_t features);
  1433. int (*ndo_neigh_construct)(struct net_device *dev,
  1434. struct neighbour *n);
  1435. void (*ndo_neigh_destroy)(struct net_device *dev,
  1436. struct neighbour *n);
  1437. int (*ndo_fdb_add)(struct ndmsg *ndm,
  1438. struct nlattr *tb[],
  1439. struct net_device *dev,
  1440. const unsigned char *addr,
  1441. u16 vid,
  1442. u16 flags,
  1443. struct netlink_ext_ack *extack);
  1444. int (*ndo_fdb_del)(struct ndmsg *ndm,
  1445. struct nlattr *tb[],
  1446. struct net_device *dev,
  1447. const unsigned char *addr,
  1448. u16 vid, struct netlink_ext_ack *extack);
  1449. int (*ndo_fdb_del_bulk)(struct ndmsg *ndm,
  1450. struct nlattr *tb[],
  1451. struct net_device *dev,
  1452. u16 vid,
  1453. struct netlink_ext_ack *extack);
  1454. int (*ndo_fdb_dump)(struct sk_buff *skb,
  1455. struct netlink_callback *cb,
  1456. struct net_device *dev,
  1457. struct net_device *filter_dev,
  1458. int *idx);
  1459. int (*ndo_fdb_get)(struct sk_buff *skb,
  1460. struct nlattr *tb[],
  1461. struct net_device *dev,
  1462. const unsigned char *addr,
  1463. u16 vid, u32 portid, u32 seq,
  1464. struct netlink_ext_ack *extack);
  1465. int (*ndo_bridge_setlink)(struct net_device *dev,
  1466. struct nlmsghdr *nlh,
  1467. u16 flags,
  1468. struct netlink_ext_ack *extack);
  1469. int (*ndo_bridge_getlink)(struct sk_buff *skb,
  1470. u32 pid, u32 seq,
  1471. struct net_device *dev,
  1472. u32 filter_mask,
  1473. int nlflags);
  1474. int (*ndo_bridge_dellink)(struct net_device *dev,
  1475. struct nlmsghdr *nlh,
  1476. u16 flags);
  1477. int (*ndo_change_carrier)(struct net_device *dev,
  1478. bool new_carrier);
  1479. int (*ndo_get_phys_port_id)(struct net_device *dev,
  1480. struct netdev_phys_item_id *ppid);
  1481. int (*ndo_get_port_parent_id)(struct net_device *dev,
  1482. struct netdev_phys_item_id *ppid);
  1483. int (*ndo_get_phys_port_name)(struct net_device *dev,
  1484. char *name, size_t len);
  1485. void* (*ndo_dfwd_add_station)(struct net_device *pdev,
  1486. struct net_device *dev);
  1487. void (*ndo_dfwd_del_station)(struct net_device *pdev,
  1488. void *priv);
  1489. int (*ndo_set_tx_maxrate)(struct net_device *dev,
  1490. int queue_index,
  1491. u32 maxrate);
  1492. int (*ndo_get_iflink)(const struct net_device *dev);
  1493. int (*ndo_fill_metadata_dst)(struct net_device *dev,
  1494. struct sk_buff *skb);
  1495. void (*ndo_set_rx_headroom)(struct net_device *dev,
  1496. int needed_headroom);
  1497. int (*ndo_bpf)(struct net_device *dev,
  1498. struct netdev_bpf *bpf);
  1499. int (*ndo_xdp_xmit)(struct net_device *dev, int n,
  1500. struct xdp_frame **xdp,
  1501. u32 flags);
  1502. struct net_device * (*ndo_xdp_get_xmit_slave)(struct net_device *dev,
  1503. struct xdp_buff *xdp);
  1504. int (*ndo_xsk_wakeup)(struct net_device *dev,
  1505. u32 queue_id, u32 flags);
  1506. struct devlink_port * (*ndo_get_devlink_port)(struct net_device *dev);
  1507. int (*ndo_tunnel_ctl)(struct net_device *dev,
  1508. struct ip_tunnel_parm *p, int cmd);
  1509. struct net_device * (*ndo_get_peer_dev)(struct net_device *dev);
  1510. int (*ndo_fill_forward_path)(struct net_device_path_ctx *ctx,
  1511. struct net_device_path *path);
  1512. ktime_t (*ndo_get_tstamp)(struct net_device *dev,
  1513. const struct skb_shared_hwtstamps *hwtstamps,
  1514. bool cycles);
  1515. ANDROID_KABI_RESERVE(1);
  1516. ANDROID_KABI_RESERVE(2);
  1517. ANDROID_KABI_RESERVE(3);
  1518. ANDROID_KABI_RESERVE(4);
  1519. ANDROID_KABI_RESERVE(5);
  1520. ANDROID_KABI_RESERVE(6);
  1521. ANDROID_KABI_RESERVE(7);
  1522. ANDROID_KABI_RESERVE(8);
  1523. };
  1524. /**
  1525. * enum netdev_priv_flags - &struct net_device priv_flags
  1526. *
  1527. * These are the &struct net_device, they are only set internally
  1528. * by drivers and used in the kernel. These flags are invisible to
  1529. * userspace; this means that the order of these flags can change
  1530. * during any kernel release.
  1531. *
  1532. * You should have a pretty good reason to be extending these flags.
  1533. *
  1534. * @IFF_802_1Q_VLAN: 802.1Q VLAN device
  1535. * @IFF_EBRIDGE: Ethernet bridging device
  1536. * @IFF_BONDING: bonding master or slave
  1537. * @IFF_ISATAP: ISATAP interface (RFC4214)
  1538. * @IFF_WAN_HDLC: WAN HDLC device
  1539. * @IFF_XMIT_DST_RELEASE: dev_hard_start_xmit() is allowed to
  1540. * release skb->dst
  1541. * @IFF_DONT_BRIDGE: disallow bridging this ether dev
  1542. * @IFF_DISABLE_NETPOLL: disable netpoll at run-time
  1543. * @IFF_MACVLAN_PORT: device used as macvlan port
  1544. * @IFF_BRIDGE_PORT: device used as bridge port
  1545. * @IFF_OVS_DATAPATH: device used as Open vSwitch datapath port
  1546. * @IFF_TX_SKB_SHARING: The interface supports sharing skbs on transmit
  1547. * @IFF_UNICAST_FLT: Supports unicast filtering
  1548. * @IFF_TEAM_PORT: device used as team port
  1549. * @IFF_SUPP_NOFCS: device supports sending custom FCS
  1550. * @IFF_LIVE_ADDR_CHANGE: device supports hardware address
  1551. * change when it's running
  1552. * @IFF_MACVLAN: Macvlan device
  1553. * @IFF_XMIT_DST_RELEASE_PERM: IFF_XMIT_DST_RELEASE not taking into account
  1554. * underlying stacked devices
  1555. * @IFF_L3MDEV_MASTER: device is an L3 master device
  1556. * @IFF_NO_QUEUE: device can run without qdisc attached
  1557. * @IFF_OPENVSWITCH: device is a Open vSwitch master
  1558. * @IFF_L3MDEV_SLAVE: device is enslaved to an L3 master device
  1559. * @IFF_TEAM: device is a team device
  1560. * @IFF_RXFH_CONFIGURED: device has had Rx Flow indirection table configured
  1561. * @IFF_PHONY_HEADROOM: the headroom value is controlled by an external
  1562. * entity (i.e. the master device for bridged veth)
  1563. * @IFF_MACSEC: device is a MACsec device
  1564. * @IFF_NO_RX_HANDLER: device doesn't support the rx_handler hook
  1565. * @IFF_FAILOVER: device is a failover master device
  1566. * @IFF_FAILOVER_SLAVE: device is lower dev of a failover master device
  1567. * @IFF_L3MDEV_RX_HANDLER: only invoke the rx handler of L3 master device
  1568. * @IFF_LIVE_RENAME_OK: rename is allowed while device is up and running
  1569. * @IFF_TX_SKB_NO_LINEAR: device/driver is capable of xmitting frames with
  1570. * skb_headlen(skb) == 0 (data starts from frag0)
  1571. * @IFF_CHANGE_PROTO_DOWN: device supports setting carrier via IFLA_PROTO_DOWN
  1572. */
  1573. enum netdev_priv_flags {
  1574. IFF_802_1Q_VLAN = 1<<0,
  1575. IFF_EBRIDGE = 1<<1,
  1576. IFF_BONDING = 1<<2,
  1577. IFF_ISATAP = 1<<3,
  1578. IFF_WAN_HDLC = 1<<4,
  1579. IFF_XMIT_DST_RELEASE = 1<<5,
  1580. IFF_DONT_BRIDGE = 1<<6,
  1581. IFF_DISABLE_NETPOLL = 1<<7,
  1582. IFF_MACVLAN_PORT = 1<<8,
  1583. IFF_BRIDGE_PORT = 1<<9,
  1584. IFF_OVS_DATAPATH = 1<<10,
  1585. IFF_TX_SKB_SHARING = 1<<11,
  1586. IFF_UNICAST_FLT = 1<<12,
  1587. IFF_TEAM_PORT = 1<<13,
  1588. IFF_SUPP_NOFCS = 1<<14,
  1589. IFF_LIVE_ADDR_CHANGE = 1<<15,
  1590. IFF_MACVLAN = 1<<16,
  1591. IFF_XMIT_DST_RELEASE_PERM = 1<<17,
  1592. IFF_L3MDEV_MASTER = 1<<18,
  1593. IFF_NO_QUEUE = 1<<19,
  1594. IFF_OPENVSWITCH = 1<<20,
  1595. IFF_L3MDEV_SLAVE = 1<<21,
  1596. IFF_TEAM = 1<<22,
  1597. IFF_RXFH_CONFIGURED = 1<<23,
  1598. IFF_PHONY_HEADROOM = 1<<24,
  1599. IFF_MACSEC = 1<<25,
  1600. IFF_NO_RX_HANDLER = 1<<26,
  1601. IFF_FAILOVER = 1<<27,
  1602. IFF_FAILOVER_SLAVE = 1<<28,
  1603. IFF_L3MDEV_RX_HANDLER = 1<<29,
  1604. IFF_LIVE_RENAME_OK = 1<<30,
  1605. IFF_TX_SKB_NO_LINEAR = BIT_ULL(31),
  1606. IFF_CHANGE_PROTO_DOWN = BIT_ULL(32),
  1607. };
  1608. #define IFF_802_1Q_VLAN IFF_802_1Q_VLAN
  1609. #define IFF_EBRIDGE IFF_EBRIDGE
  1610. #define IFF_BONDING IFF_BONDING
  1611. #define IFF_ISATAP IFF_ISATAP
  1612. #define IFF_WAN_HDLC IFF_WAN_HDLC
  1613. #define IFF_XMIT_DST_RELEASE IFF_XMIT_DST_RELEASE
  1614. #define IFF_DONT_BRIDGE IFF_DONT_BRIDGE
  1615. #define IFF_DISABLE_NETPOLL IFF_DISABLE_NETPOLL
  1616. #define IFF_MACVLAN_PORT IFF_MACVLAN_PORT
  1617. #define IFF_BRIDGE_PORT IFF_BRIDGE_PORT
  1618. #define IFF_OVS_DATAPATH IFF_OVS_DATAPATH
  1619. #define IFF_TX_SKB_SHARING IFF_TX_SKB_SHARING
  1620. #define IFF_UNICAST_FLT IFF_UNICAST_FLT
  1621. #define IFF_TEAM_PORT IFF_TEAM_PORT
  1622. #define IFF_SUPP_NOFCS IFF_SUPP_NOFCS
  1623. #define IFF_LIVE_ADDR_CHANGE IFF_LIVE_ADDR_CHANGE
  1624. #define IFF_MACVLAN IFF_MACVLAN
  1625. #define IFF_XMIT_DST_RELEASE_PERM IFF_XMIT_DST_RELEASE_PERM
  1626. #define IFF_L3MDEV_MASTER IFF_L3MDEV_MASTER
  1627. #define IFF_NO_QUEUE IFF_NO_QUEUE
  1628. #define IFF_OPENVSWITCH IFF_OPENVSWITCH
  1629. #define IFF_L3MDEV_SLAVE IFF_L3MDEV_SLAVE
  1630. #define IFF_TEAM IFF_TEAM
  1631. #define IFF_RXFH_CONFIGURED IFF_RXFH_CONFIGURED
  1632. #define IFF_PHONY_HEADROOM IFF_PHONY_HEADROOM
  1633. #define IFF_MACSEC IFF_MACSEC
  1634. #define IFF_NO_RX_HANDLER IFF_NO_RX_HANDLER
  1635. #define IFF_FAILOVER IFF_FAILOVER
  1636. #define IFF_FAILOVER_SLAVE IFF_FAILOVER_SLAVE
  1637. #define IFF_L3MDEV_RX_HANDLER IFF_L3MDEV_RX_HANDLER
  1638. #define IFF_LIVE_RENAME_OK IFF_LIVE_RENAME_OK
  1639. #define IFF_TX_SKB_NO_LINEAR IFF_TX_SKB_NO_LINEAR
  1640. /* Specifies the type of the struct net_device::ml_priv pointer */
  1641. enum netdev_ml_priv_type {
  1642. ML_PRIV_NONE,
  1643. ML_PRIV_CAN,
  1644. };
  1645. /**
  1646. * struct net_device - The DEVICE structure.
  1647. *
  1648. * Actually, this whole structure is a big mistake. It mixes I/O
  1649. * data with strictly "high-level" data, and it has to know about
  1650. * almost every data structure used in the INET module.
  1651. *
  1652. * @name: This is the first field of the "visible" part of this structure
  1653. * (i.e. as seen by users in the "Space.c" file). It is the name
  1654. * of the interface.
  1655. *
  1656. * @name_node: Name hashlist node
  1657. * @ifalias: SNMP alias
  1658. * @mem_end: Shared memory end
  1659. * @mem_start: Shared memory start
  1660. * @base_addr: Device I/O address
  1661. * @irq: Device IRQ number
  1662. *
  1663. * @state: Generic network queuing layer state, see netdev_state_t
  1664. * @dev_list: The global list of network devices
  1665. * @napi_list: List entry used for polling NAPI devices
  1666. * @unreg_list: List entry when we are unregistering the
  1667. * device; see the function unregister_netdev
  1668. * @close_list: List entry used when we are closing the device
  1669. * @ptype_all: Device-specific packet handlers for all protocols
  1670. * @ptype_specific: Device-specific, protocol-specific packet handlers
  1671. *
  1672. * @adj_list: Directly linked devices, like slaves for bonding
  1673. * @features: Currently active device features
  1674. * @hw_features: User-changeable features
  1675. *
  1676. * @wanted_features: User-requested features
  1677. * @vlan_features: Mask of features inheritable by VLAN devices
  1678. *
  1679. * @hw_enc_features: Mask of features inherited by encapsulating devices
  1680. * This field indicates what encapsulation
  1681. * offloads the hardware is capable of doing,
  1682. * and drivers will need to set them appropriately.
  1683. *
  1684. * @mpls_features: Mask of features inheritable by MPLS
  1685. * @gso_partial_features: value(s) from NETIF_F_GSO\*
  1686. *
  1687. * @ifindex: interface index
  1688. * @group: The group the device belongs to
  1689. *
  1690. * @stats: Statistics struct, which was left as a legacy, use
  1691. * rtnl_link_stats64 instead
  1692. *
  1693. * @core_stats: core networking counters,
  1694. * do not use this in drivers
  1695. * @carrier_up_count: Number of times the carrier has been up
  1696. * @carrier_down_count: Number of times the carrier has been down
  1697. *
  1698. * @wireless_handlers: List of functions to handle Wireless Extensions,
  1699. * instead of ioctl,
  1700. * see <net/iw_handler.h> for details.
  1701. * @wireless_data: Instance data managed by the core of wireless extensions
  1702. *
  1703. * @netdev_ops: Includes several pointers to callbacks,
  1704. * if one wants to override the ndo_*() functions
  1705. * @ethtool_ops: Management operations
  1706. * @l3mdev_ops: Layer 3 master device operations
  1707. * @ndisc_ops: Includes callbacks for different IPv6 neighbour
  1708. * discovery handling. Necessary for e.g. 6LoWPAN.
  1709. * @xfrmdev_ops: Transformation offload operations
  1710. * @tlsdev_ops: Transport Layer Security offload operations
  1711. * @header_ops: Includes callbacks for creating,parsing,caching,etc
  1712. * of Layer 2 headers.
  1713. *
  1714. * @flags: Interface flags (a la BSD)
  1715. * @priv_flags: Like 'flags' but invisible to userspace,
  1716. * see if.h for the definitions
  1717. * @gflags: Global flags ( kept as legacy )
  1718. * @padded: How much padding added by alloc_netdev()
  1719. * @operstate: RFC2863 operstate
  1720. * @link_mode: Mapping policy to operstate
  1721. * @if_port: Selectable AUI, TP, ...
  1722. * @dma: DMA channel
  1723. * @mtu: Interface MTU value
  1724. * @min_mtu: Interface Minimum MTU value
  1725. * @max_mtu: Interface Maximum MTU value
  1726. * @type: Interface hardware type
  1727. * @hard_header_len: Maximum hardware header length.
  1728. * @min_header_len: Minimum hardware header length
  1729. *
  1730. * @needed_headroom: Extra headroom the hardware may need, but not in all
  1731. * cases can this be guaranteed
  1732. * @needed_tailroom: Extra tailroom the hardware may need, but not in all
  1733. * cases can this be guaranteed. Some cases also use
  1734. * LL_MAX_HEADER instead to allocate the skb
  1735. *
  1736. * interface address info:
  1737. *
  1738. * @perm_addr: Permanent hw address
  1739. * @addr_assign_type: Hw address assignment type
  1740. * @addr_len: Hardware address length
  1741. * @upper_level: Maximum depth level of upper devices.
  1742. * @lower_level: Maximum depth level of lower devices.
  1743. * @neigh_priv_len: Used in neigh_alloc()
  1744. * @dev_id: Used to differentiate devices that share
  1745. * the same link layer address
  1746. * @dev_port: Used to differentiate devices that share
  1747. * the same function
  1748. * @addr_list_lock: XXX: need comments on this one
  1749. * @name_assign_type: network interface name assignment type
  1750. * @uc_promisc: Counter that indicates promiscuous mode
  1751. * has been enabled due to the need to listen to
  1752. * additional unicast addresses in a device that
  1753. * does not implement ndo_set_rx_mode()
  1754. * @uc: unicast mac addresses
  1755. * @mc: multicast mac addresses
  1756. * @dev_addrs: list of device hw addresses
  1757. * @queues_kset: Group of all Kobjects in the Tx and RX queues
  1758. * @promiscuity: Number of times the NIC is told to work in
  1759. * promiscuous mode; if it becomes 0 the NIC will
  1760. * exit promiscuous mode
  1761. * @allmulti: Counter, enables or disables allmulticast mode
  1762. *
  1763. * @vlan_info: VLAN info
  1764. * @dsa_ptr: dsa specific data
  1765. * @tipc_ptr: TIPC specific data
  1766. * @atalk_ptr: AppleTalk link
  1767. * @ip_ptr: IPv4 specific data
  1768. * @ip6_ptr: IPv6 specific data
  1769. * @ax25_ptr: AX.25 specific data
  1770. * @ieee80211_ptr: IEEE 802.11 specific data, assign before registering
  1771. * @ieee802154_ptr: IEEE 802.15.4 low-rate Wireless Personal Area Network
  1772. * device struct
  1773. * @mpls_ptr: mpls_dev struct pointer
  1774. * @mctp_ptr: MCTP specific data
  1775. *
  1776. * @dev_addr: Hw address (before bcast,
  1777. * because most packets are unicast)
  1778. *
  1779. * @_rx: Array of RX queues
  1780. * @num_rx_queues: Number of RX queues
  1781. * allocated at register_netdev() time
  1782. * @real_num_rx_queues: Number of RX queues currently active in device
  1783. * @xdp_prog: XDP sockets filter program pointer
  1784. * @gro_flush_timeout: timeout for GRO layer in NAPI
  1785. * @napi_defer_hard_irqs: If not zero, provides a counter that would
  1786. * allow to avoid NIC hard IRQ, on busy queues.
  1787. *
  1788. * @rx_handler: handler for received packets
  1789. * @rx_handler_data: XXX: need comments on this one
  1790. * @miniq_ingress: ingress/clsact qdisc specific data for
  1791. * ingress processing
  1792. * @ingress_queue: XXX: need comments on this one
  1793. * @nf_hooks_ingress: netfilter hooks executed for ingress packets
  1794. * @broadcast: hw bcast address
  1795. *
  1796. * @rx_cpu_rmap: CPU reverse-mapping for RX completion interrupts,
  1797. * indexed by RX queue number. Assigned by driver.
  1798. * This must only be set if the ndo_rx_flow_steer
  1799. * operation is defined
  1800. * @index_hlist: Device index hash chain
  1801. *
  1802. * @_tx: Array of TX queues
  1803. * @num_tx_queues: Number of TX queues allocated at alloc_netdev_mq() time
  1804. * @real_num_tx_queues: Number of TX queues currently active in device
  1805. * @qdisc: Root qdisc from userspace point of view
  1806. * @tx_queue_len: Max frames per queue allowed
  1807. * @tx_global_lock: XXX: need comments on this one
  1808. * @xdp_bulkq: XDP device bulk queue
  1809. * @xps_maps: all CPUs/RXQs maps for XPS device
  1810. *
  1811. * @xps_maps: XXX: need comments on this one
  1812. * @miniq_egress: clsact qdisc specific data for
  1813. * egress processing
  1814. * @nf_hooks_egress: netfilter hooks executed for egress packets
  1815. * @qdisc_hash: qdisc hash table
  1816. * @watchdog_timeo: Represents the timeout that is used by
  1817. * the watchdog (see dev_watchdog())
  1818. * @watchdog_timer: List of timers
  1819. *
  1820. * @proto_down_reason: reason a netdev interface is held down
  1821. * @pcpu_refcnt: Number of references to this device
  1822. * @dev_refcnt: Number of references to this device
  1823. * @refcnt_tracker: Tracker directory for tracked references to this device
  1824. * @todo_list: Delayed register/unregister
  1825. * @link_watch_list: XXX: need comments on this one
  1826. *
  1827. * @reg_state: Register/unregister state machine
  1828. * @dismantle: Device is going to be freed
  1829. * @rtnl_link_state: This enum represents the phases of creating
  1830. * a new link
  1831. *
  1832. * @needs_free_netdev: Should unregister perform free_netdev?
  1833. * @priv_destructor: Called from unregister
  1834. * @npinfo: XXX: need comments on this one
  1835. * @nd_net: Network namespace this network device is inside
  1836. *
  1837. * @ml_priv: Mid-layer private
  1838. * @ml_priv_type: Mid-layer private type
  1839. * @lstats: Loopback statistics
  1840. * @tstats: Tunnel statistics
  1841. * @dstats: Dummy statistics
  1842. * @vstats: Virtual ethernet statistics
  1843. *
  1844. * @garp_port: GARP
  1845. * @mrp_port: MRP
  1846. *
  1847. * @dm_private: Drop monitor private
  1848. *
  1849. * @dev: Class/net/name entry
  1850. * @sysfs_groups: Space for optional device, statistics and wireless
  1851. * sysfs groups
  1852. *
  1853. * @sysfs_rx_queue_group: Space for optional per-rx queue attributes
  1854. * @rtnl_link_ops: Rtnl_link_ops
  1855. *
  1856. * @gso_max_size: Maximum size of generic segmentation offload
  1857. * @tso_max_size: Device (as in HW) limit on the max TSO request size
  1858. * @gso_max_segs: Maximum number of segments that can be passed to the
  1859. * NIC for GSO
  1860. * @tso_max_segs: Device (as in HW) limit on the max TSO segment count
  1861. *
  1862. * @dcbnl_ops: Data Center Bridging netlink ops
  1863. * @num_tc: Number of traffic classes in the net device
  1864. * @tc_to_txq: XXX: need comments on this one
  1865. * @prio_tc_map: XXX: need comments on this one
  1866. *
  1867. * @fcoe_ddp_xid: Max exchange id for FCoE LRO by ddp
  1868. *
  1869. * @priomap: XXX: need comments on this one
  1870. * @phydev: Physical device may attach itself
  1871. * for hardware timestamping
  1872. * @sfp_bus: attached &struct sfp_bus structure.
  1873. *
  1874. * @qdisc_tx_busylock: lockdep class annotating Qdisc->busylock spinlock
  1875. *
  1876. * @proto_down: protocol port state information can be sent to the
  1877. * switch driver and used to set the phys state of the
  1878. * switch port.
  1879. *
  1880. * @wol_enabled: Wake-on-LAN is enabled
  1881. *
  1882. * @threaded: napi threaded mode is enabled
  1883. *
  1884. * @net_notifier_list: List of per-net netdev notifier block
  1885. * that follow this device when it is moved
  1886. * to another network namespace.
  1887. *
  1888. * @macsec_ops: MACsec offloading ops
  1889. *
  1890. * @udp_tunnel_nic_info: static structure describing the UDP tunnel
  1891. * offload capabilities of the device
  1892. * @udp_tunnel_nic: UDP tunnel offload state
  1893. * @xdp_state: stores info on attached XDP BPF programs
  1894. *
  1895. * @nested_level: Used as a parameter of spin_lock_nested() of
  1896. * dev->addr_list_lock.
  1897. * @unlink_list: As netif_addr_lock() can be called recursively,
  1898. * keep a list of interfaces to be deleted.
  1899. * @gro_max_size: Maximum size of aggregated packet in generic
  1900. * receive offload (GRO)
  1901. *
  1902. * @dev_addr_shadow: Copy of @dev_addr to catch direct writes.
  1903. * @linkwatch_dev_tracker: refcount tracker used by linkwatch.
  1904. * @watchdog_dev_tracker: refcount tracker used by watchdog.
  1905. * @dev_registered_tracker: tracker for reference held while
  1906. * registered
  1907. * @offload_xstats_l3: L3 HW stats for this netdevice.
  1908. *
  1909. * FIXME: cleanup struct net_device such that network protocol info
  1910. * moves out.
  1911. */
  1912. struct net_device {
  1913. char name[IFNAMSIZ];
  1914. struct netdev_name_node *name_node;
  1915. struct dev_ifalias __rcu *ifalias;
  1916. /*
  1917. * I/O specific fields
  1918. * FIXME: Merge these and struct ifmap into one
  1919. */
  1920. unsigned long mem_end;
  1921. unsigned long mem_start;
  1922. unsigned long base_addr;
  1923. /*
  1924. * Some hardware also needs these fields (state,dev_list,
  1925. * napi_list,unreg_list,close_list) but they are not
  1926. * part of the usual set specified in Space.c.
  1927. */
  1928. unsigned long state;
  1929. struct list_head dev_list;
  1930. struct list_head napi_list;
  1931. struct list_head unreg_list;
  1932. struct list_head close_list;
  1933. struct list_head ptype_all;
  1934. struct list_head ptype_specific;
  1935. struct {
  1936. struct list_head upper;
  1937. struct list_head lower;
  1938. } adj_list;
  1939. /* Read-mostly cache-line for fast-path access */
  1940. unsigned int flags;
  1941. unsigned long long priv_flags;
  1942. const struct net_device_ops *netdev_ops;
  1943. int ifindex;
  1944. unsigned short gflags;
  1945. unsigned short hard_header_len;
  1946. /* Note : dev->mtu is often read without holding a lock.
  1947. * Writers usually hold RTNL.
  1948. * It is recommended to use READ_ONCE() to annotate the reads,
  1949. * and to use WRITE_ONCE() to annotate the writes.
  1950. */
  1951. unsigned int mtu;
  1952. unsigned short needed_headroom;
  1953. unsigned short needed_tailroom;
  1954. netdev_features_t features;
  1955. netdev_features_t hw_features;
  1956. netdev_features_t wanted_features;
  1957. netdev_features_t vlan_features;
  1958. netdev_features_t hw_enc_features;
  1959. netdev_features_t mpls_features;
  1960. netdev_features_t gso_partial_features;
  1961. unsigned int min_mtu;
  1962. unsigned int max_mtu;
  1963. unsigned short type;
  1964. unsigned char min_header_len;
  1965. unsigned char name_assign_type;
  1966. int group;
  1967. struct net_device_stats stats; /* not used by modern drivers */
  1968. struct net_device_core_stats __percpu *core_stats;
  1969. /* Stats to monitor link on/off, flapping */
  1970. atomic_t carrier_up_count;
  1971. atomic_t carrier_down_count;
  1972. /* Android KMI hack to allow vendors to have their own wifi changes in modules */
  1973. #ifdef __GENKSYMS__
  1974. void *wireless_handlers;
  1975. void *wireless_data;
  1976. #else
  1977. const struct iw_handler_def *wireless_handlers;
  1978. struct iw_public_data *wireless_data;
  1979. #endif
  1980. const struct ethtool_ops *ethtool_ops;
  1981. #ifdef CONFIG_NET_L3_MASTER_DEV
  1982. const struct l3mdev_ops *l3mdev_ops;
  1983. #endif
  1984. #if IS_ENABLED(CONFIG_IPV6)
  1985. const struct ndisc_ops *ndisc_ops;
  1986. #endif
  1987. #ifdef CONFIG_XFRM_OFFLOAD
  1988. const struct xfrmdev_ops *xfrmdev_ops;
  1989. #endif
  1990. #if IS_ENABLED(CONFIG_TLS_DEVICE)
  1991. const struct tlsdev_ops *tlsdev_ops;
  1992. #endif
  1993. const struct header_ops *header_ops;
  1994. unsigned char operstate;
  1995. unsigned char link_mode;
  1996. unsigned char if_port;
  1997. unsigned char dma;
  1998. /* Interface address info. */
  1999. unsigned char perm_addr[MAX_ADDR_LEN];
  2000. unsigned char addr_assign_type;
  2001. unsigned char addr_len;
  2002. unsigned char upper_level;
  2003. unsigned char lower_level;
  2004. unsigned short neigh_priv_len;
  2005. unsigned short dev_id;
  2006. unsigned short dev_port;
  2007. unsigned short padded;
  2008. spinlock_t addr_list_lock;
  2009. int irq;
  2010. struct netdev_hw_addr_list uc;
  2011. struct netdev_hw_addr_list mc;
  2012. struct netdev_hw_addr_list dev_addrs;
  2013. #ifdef CONFIG_SYSFS
  2014. struct kset *queues_kset;
  2015. #endif
  2016. #ifdef CONFIG_LOCKDEP
  2017. struct list_head unlink_list;
  2018. #endif
  2019. unsigned int promiscuity;
  2020. unsigned int allmulti;
  2021. bool uc_promisc;
  2022. #ifdef CONFIG_LOCKDEP
  2023. unsigned char nested_level;
  2024. #endif
  2025. /* Protocol-specific pointers */
  2026. struct in_device __rcu *ip_ptr;
  2027. struct inet6_dev __rcu *ip6_ptr;
  2028. #if IS_ENABLED(CONFIG_VLAN_8021Q)
  2029. struct vlan_info __rcu *vlan_info;
  2030. #endif
  2031. #if IS_ENABLED(CONFIG_NET_DSA)
  2032. struct dsa_port *dsa_ptr;
  2033. #endif
  2034. #if IS_ENABLED(CONFIG_TIPC)
  2035. struct tipc_bearer __rcu *tipc_ptr;
  2036. #endif
  2037. #if IS_ENABLED(CONFIG_ATALK)
  2038. void *atalk_ptr;
  2039. #endif
  2040. #if IS_ENABLED(CONFIG_AX25)
  2041. void *ax25_ptr;
  2042. #endif
  2043. /* Android KMI hack to allow vendors to have their own wifi changes in modules */
  2044. #ifdef __GENKSYMS__
  2045. void *ieee80211_ptr;
  2046. #else
  2047. struct wireless_dev *ieee80211_ptr;
  2048. #endif
  2049. #if IS_ENABLED(CONFIG_IEEE802154) || IS_ENABLED(CONFIG_6LOWPAN)
  2050. struct wpan_dev *ieee802154_ptr;
  2051. #endif
  2052. #if IS_ENABLED(CONFIG_MPLS_ROUTING)
  2053. struct mpls_dev __rcu *mpls_ptr;
  2054. #endif
  2055. #if IS_ENABLED(CONFIG_MCTP)
  2056. struct mctp_dev __rcu *mctp_ptr;
  2057. #endif
  2058. /*
  2059. * Cache lines mostly used on receive path (including eth_type_trans())
  2060. */
  2061. /* Interface address info used in eth_type_trans() */
  2062. const unsigned char *dev_addr;
  2063. struct netdev_rx_queue *_rx;
  2064. unsigned int num_rx_queues;
  2065. unsigned int real_num_rx_queues;
  2066. struct bpf_prog __rcu *xdp_prog;
  2067. unsigned long gro_flush_timeout;
  2068. int napi_defer_hard_irqs;
  2069. #define GRO_LEGACY_MAX_SIZE 65536u
  2070. /* TCP minimal MSS is 8 (TCP_MIN_GSO_SIZE),
  2071. * and shinfo->gso_segs is a 16bit field.
  2072. */
  2073. #define GRO_MAX_SIZE (8 * 65535u)
  2074. unsigned int gro_max_size;
  2075. rx_handler_func_t __rcu *rx_handler;
  2076. void __rcu *rx_handler_data;
  2077. #ifdef CONFIG_NET_CLS_ACT
  2078. struct mini_Qdisc __rcu *miniq_ingress;
  2079. #endif
  2080. struct netdev_queue __rcu *ingress_queue;
  2081. #ifdef CONFIG_NETFILTER_INGRESS
  2082. struct nf_hook_entries __rcu *nf_hooks_ingress;
  2083. #endif
  2084. unsigned char broadcast[MAX_ADDR_LEN];
  2085. #ifdef CONFIG_RFS_ACCEL
  2086. struct cpu_rmap *rx_cpu_rmap;
  2087. #endif
  2088. struct hlist_node index_hlist;
  2089. /*
  2090. * Cache lines mostly used on transmit path
  2091. */
  2092. struct netdev_queue *_tx ____cacheline_aligned_in_smp;
  2093. unsigned int num_tx_queues;
  2094. unsigned int real_num_tx_queues;
  2095. struct Qdisc __rcu *qdisc;
  2096. unsigned int tx_queue_len;
  2097. spinlock_t tx_global_lock;
  2098. struct xdp_dev_bulk_queue __percpu *xdp_bulkq;
  2099. #ifdef CONFIG_XPS
  2100. struct xps_dev_maps __rcu *xps_maps[XPS_MAPS_MAX];
  2101. #endif
  2102. #ifdef CONFIG_NET_CLS_ACT
  2103. struct mini_Qdisc __rcu *miniq_egress;
  2104. #endif
  2105. #ifdef CONFIG_NETFILTER_EGRESS
  2106. struct nf_hook_entries __rcu *nf_hooks_egress;
  2107. #endif
  2108. #ifdef CONFIG_NET_SCHED
  2109. DECLARE_HASHTABLE (qdisc_hash, 4);
  2110. #endif
  2111. /* These may be needed for future network-power-down code. */
  2112. struct timer_list watchdog_timer;
  2113. int watchdog_timeo;
  2114. u32 proto_down_reason;
  2115. struct list_head todo_list;
  2116. #ifdef CONFIG_PCPU_DEV_REFCNT
  2117. int __percpu *pcpu_refcnt;
  2118. #else
  2119. refcount_t dev_refcnt;
  2120. #endif
  2121. struct ref_tracker_dir refcnt_tracker;
  2122. struct list_head link_watch_list;
  2123. enum { NETREG_UNINITIALIZED=0,
  2124. NETREG_REGISTERED, /* completed register_netdevice */
  2125. NETREG_UNREGISTERING, /* called unregister_netdevice */
  2126. NETREG_UNREGISTERED, /* completed unregister todo */
  2127. NETREG_RELEASED, /* called free_netdev */
  2128. NETREG_DUMMY, /* dummy device for NAPI poll */
  2129. } reg_state:8;
  2130. bool dismantle;
  2131. enum {
  2132. RTNL_LINK_INITIALIZED,
  2133. RTNL_LINK_INITIALIZING,
  2134. } rtnl_link_state:16;
  2135. bool needs_free_netdev;
  2136. void (*priv_destructor)(struct net_device *dev);
  2137. #ifdef CONFIG_NETPOLL
  2138. struct netpoll_info __rcu *npinfo;
  2139. #endif
  2140. possible_net_t nd_net;
  2141. /* mid-layer private */
  2142. void *ml_priv;
  2143. enum netdev_ml_priv_type ml_priv_type;
  2144. union {
  2145. struct pcpu_lstats __percpu *lstats;
  2146. struct pcpu_sw_netstats __percpu *tstats;
  2147. struct pcpu_dstats __percpu *dstats;
  2148. };
  2149. #if IS_ENABLED(CONFIG_GARP)
  2150. struct garp_port __rcu *garp_port;
  2151. #endif
  2152. #if IS_ENABLED(CONFIG_MRP)
  2153. struct mrp_port __rcu *mrp_port;
  2154. #endif
  2155. #if IS_ENABLED(CONFIG_NET_DROP_MONITOR)
  2156. struct dm_hw_stat_delta __rcu *dm_private;
  2157. #endif
  2158. struct device dev;
  2159. const struct attribute_group *sysfs_groups[4];
  2160. const struct attribute_group *sysfs_rx_queue_group;
  2161. const struct rtnl_link_ops *rtnl_link_ops;
  2162. /* for setting kernel sock attribute on TCP connection setup */
  2163. #define GSO_MAX_SEGS 65535u
  2164. #define GSO_LEGACY_MAX_SIZE 65536u
  2165. /* TCP minimal MSS is 8 (TCP_MIN_GSO_SIZE),
  2166. * and shinfo->gso_segs is a 16bit field.
  2167. */
  2168. #define GSO_MAX_SIZE (8 * GSO_MAX_SEGS)
  2169. unsigned int gso_max_size;
  2170. #define TSO_LEGACY_MAX_SIZE 65536
  2171. #define TSO_MAX_SIZE UINT_MAX
  2172. unsigned int tso_max_size;
  2173. u16 gso_max_segs;
  2174. #define TSO_MAX_SEGS U16_MAX
  2175. u16 tso_max_segs;
  2176. #ifdef CONFIG_DCB
  2177. const struct dcbnl_rtnl_ops *dcbnl_ops;
  2178. #endif
  2179. s16 num_tc;
  2180. struct netdev_tc_txq tc_to_txq[TC_MAX_QUEUE];
  2181. u8 prio_tc_map[TC_BITMASK + 1];
  2182. #if IS_ENABLED(CONFIG_FCOE)
  2183. unsigned int fcoe_ddp_xid;
  2184. #endif
  2185. #if IS_ENABLED(CONFIG_CGROUP_NET_PRIO)
  2186. struct netprio_map __rcu *priomap;
  2187. #endif
  2188. struct phy_device *phydev;
  2189. struct sfp_bus *sfp_bus;
  2190. struct lock_class_key *qdisc_tx_busylock;
  2191. bool proto_down;
  2192. unsigned wol_enabled:1;
  2193. unsigned threaded:1;
  2194. struct list_head net_notifier_list;
  2195. #if IS_ENABLED(CONFIG_MACSEC)
  2196. /* MACsec management functions */
  2197. const struct macsec_ops *macsec_ops;
  2198. #endif
  2199. const struct udp_tunnel_nic_info *udp_tunnel_nic_info;
  2200. struct udp_tunnel_nic *udp_tunnel_nic;
  2201. /* protected by rtnl_lock */
  2202. struct bpf_xdp_entity xdp_state[__MAX_XDP_MODE];
  2203. u8 dev_addr_shadow[MAX_ADDR_LEN];
  2204. netdevice_tracker linkwatch_dev_tracker;
  2205. netdevice_tracker watchdog_dev_tracker;
  2206. netdevice_tracker dev_registered_tracker;
  2207. struct rtnl_hw_stats64 *offload_xstats_l3;
  2208. ANDROID_KABI_RESERVE(1);
  2209. ANDROID_KABI_RESERVE(2);
  2210. ANDROID_KABI_RESERVE(3);
  2211. ANDROID_KABI_RESERVE(4);
  2212. ANDROID_KABI_RESERVE(5);
  2213. ANDROID_KABI_RESERVE(6);
  2214. ANDROID_KABI_RESERVE(7);
  2215. ANDROID_KABI_RESERVE(8);
  2216. };
  2217. #define to_net_dev(d) container_of(d, struct net_device, dev)
  2218. static inline bool netif_elide_gro(const struct net_device *dev)
  2219. {
  2220. if (!(dev->features & NETIF_F_GRO) || dev->xdp_prog)
  2221. return true;
  2222. return false;
  2223. }
  2224. #define NETDEV_ALIGN 32
  2225. static inline
  2226. int netdev_get_prio_tc_map(const struct net_device *dev, u32 prio)
  2227. {
  2228. return dev->prio_tc_map[prio & TC_BITMASK];
  2229. }
  2230. static inline
  2231. int netdev_set_prio_tc_map(struct net_device *dev, u8 prio, u8 tc)
  2232. {
  2233. if (tc >= dev->num_tc)
  2234. return -EINVAL;
  2235. dev->prio_tc_map[prio & TC_BITMASK] = tc & TC_BITMASK;
  2236. return 0;
  2237. }
  2238. int netdev_txq_to_tc(struct net_device *dev, unsigned int txq);
  2239. void netdev_reset_tc(struct net_device *dev);
  2240. int netdev_set_tc_queue(struct net_device *dev, u8 tc, u16 count, u16 offset);
  2241. int netdev_set_num_tc(struct net_device *dev, u8 num_tc);
  2242. static inline
  2243. int netdev_get_num_tc(struct net_device *dev)
  2244. {
  2245. return dev->num_tc;
  2246. }
  2247. static inline void net_prefetch(void *p)
  2248. {
  2249. prefetch(p);
  2250. #if L1_CACHE_BYTES < 128
  2251. prefetch((u8 *)p + L1_CACHE_BYTES);
  2252. #endif
  2253. }
  2254. static inline void net_prefetchw(void *p)
  2255. {
  2256. prefetchw(p);
  2257. #if L1_CACHE_BYTES < 128
  2258. prefetchw((u8 *)p + L1_CACHE_BYTES);
  2259. #endif
  2260. }
  2261. void netdev_unbind_sb_channel(struct net_device *dev,
  2262. struct net_device *sb_dev);
  2263. int netdev_bind_sb_channel_queue(struct net_device *dev,
  2264. struct net_device *sb_dev,
  2265. u8 tc, u16 count, u16 offset);
  2266. int netdev_set_sb_channel(struct net_device *dev, u16 channel);
  2267. static inline int netdev_get_sb_channel(struct net_device *dev)
  2268. {
  2269. return max_t(int, -dev->num_tc, 0);
  2270. }
  2271. static inline
  2272. struct netdev_queue *netdev_get_tx_queue(const struct net_device *dev,
  2273. unsigned int index)
  2274. {
  2275. DEBUG_NET_WARN_ON_ONCE(index >= dev->num_tx_queues);
  2276. return &dev->_tx[index];
  2277. }
  2278. static inline struct netdev_queue *skb_get_tx_queue(const struct net_device *dev,
  2279. const struct sk_buff *skb)
  2280. {
  2281. return netdev_get_tx_queue(dev, skb_get_queue_mapping(skb));
  2282. }
  2283. static inline void netdev_for_each_tx_queue(struct net_device *dev,
  2284. void (*f)(struct net_device *,
  2285. struct netdev_queue *,
  2286. void *),
  2287. void *arg)
  2288. {
  2289. unsigned int i;
  2290. for (i = 0; i < dev->num_tx_queues; i++)
  2291. f(dev, &dev->_tx[i], arg);
  2292. }
  2293. #define netdev_lockdep_set_classes(dev) \
  2294. { \
  2295. static struct lock_class_key qdisc_tx_busylock_key; \
  2296. static struct lock_class_key qdisc_xmit_lock_key; \
  2297. static struct lock_class_key dev_addr_list_lock_key; \
  2298. unsigned int i; \
  2299. \
  2300. (dev)->qdisc_tx_busylock = &qdisc_tx_busylock_key; \
  2301. lockdep_set_class(&(dev)->addr_list_lock, \
  2302. &dev_addr_list_lock_key); \
  2303. for (i = 0; i < (dev)->num_tx_queues; i++) \
  2304. lockdep_set_class(&(dev)->_tx[i]._xmit_lock, \
  2305. &qdisc_xmit_lock_key); \
  2306. }
  2307. u16 netdev_pick_tx(struct net_device *dev, struct sk_buff *skb,
  2308. struct net_device *sb_dev);
  2309. struct netdev_queue *netdev_core_pick_tx(struct net_device *dev,
  2310. struct sk_buff *skb,
  2311. struct net_device *sb_dev);
  2312. /* returns the headroom that the master device needs to take in account
  2313. * when forwarding to this dev
  2314. */
  2315. static inline unsigned netdev_get_fwd_headroom(struct net_device *dev)
  2316. {
  2317. return dev->priv_flags & IFF_PHONY_HEADROOM ? 0 : dev->needed_headroom;
  2318. }
  2319. static inline void netdev_set_rx_headroom(struct net_device *dev, int new_hr)
  2320. {
  2321. if (dev->netdev_ops->ndo_set_rx_headroom)
  2322. dev->netdev_ops->ndo_set_rx_headroom(dev, new_hr);
  2323. }
  2324. /* set the device rx headroom to the dev's default */
  2325. static inline void netdev_reset_rx_headroom(struct net_device *dev)
  2326. {
  2327. netdev_set_rx_headroom(dev, -1);
  2328. }
  2329. static inline void *netdev_get_ml_priv(struct net_device *dev,
  2330. enum netdev_ml_priv_type type)
  2331. {
  2332. if (dev->ml_priv_type != type)
  2333. return NULL;
  2334. return dev->ml_priv;
  2335. }
  2336. static inline void netdev_set_ml_priv(struct net_device *dev,
  2337. void *ml_priv,
  2338. enum netdev_ml_priv_type type)
  2339. {
  2340. WARN(dev->ml_priv_type && dev->ml_priv_type != type,
  2341. "Overwriting already set ml_priv_type (%u) with different ml_priv_type (%u)!\n",
  2342. dev->ml_priv_type, type);
  2343. WARN(!dev->ml_priv_type && dev->ml_priv,
  2344. "Overwriting already set ml_priv and ml_priv_type is ML_PRIV_NONE!\n");
  2345. dev->ml_priv = ml_priv;
  2346. dev->ml_priv_type = type;
  2347. }
  2348. /*
  2349. * Net namespace inlines
  2350. */
  2351. static inline
  2352. struct net *dev_net(const struct net_device *dev)
  2353. {
  2354. return read_pnet(&dev->nd_net);
  2355. }
  2356. static inline
  2357. void dev_net_set(struct net_device *dev, struct net *net)
  2358. {
  2359. write_pnet(&dev->nd_net, net);
  2360. }
  2361. /**
  2362. * netdev_priv - access network device private data
  2363. * @dev: network device
  2364. *
  2365. * Get network device private data
  2366. */
  2367. static inline void *netdev_priv(const struct net_device *dev)
  2368. {
  2369. return (char *)dev + ALIGN(sizeof(struct net_device), NETDEV_ALIGN);
  2370. }
  2371. /* Set the sysfs physical device reference for the network logical device
  2372. * if set prior to registration will cause a symlink during initialization.
  2373. */
  2374. #define SET_NETDEV_DEV(net, pdev) ((net)->dev.parent = (pdev))
  2375. /* Set the sysfs device type for the network logical device to allow
  2376. * fine-grained identification of different network device types. For
  2377. * example Ethernet, Wireless LAN, Bluetooth, WiMAX etc.
  2378. */
  2379. #define SET_NETDEV_DEVTYPE(net, devtype) ((net)->dev.type = (devtype))
  2380. /* Default NAPI poll() weight
  2381. * Device drivers are strongly advised to not use bigger value
  2382. */
  2383. #define NAPI_POLL_WEIGHT 64
  2384. void netif_napi_add_weight(struct net_device *dev, struct napi_struct *napi,
  2385. int (*poll)(struct napi_struct *, int), int weight);
  2386. /**
  2387. * netif_napi_add() - initialize a NAPI context
  2388. * @dev: network device
  2389. * @napi: NAPI context
  2390. * @poll: polling function
  2391. *
  2392. * netif_napi_add() must be used to initialize a NAPI context prior to calling
  2393. * *any* of the other NAPI-related functions.
  2394. */
  2395. static inline void
  2396. netif_napi_add(struct net_device *dev, struct napi_struct *napi,
  2397. int (*poll)(struct napi_struct *, int))
  2398. {
  2399. netif_napi_add_weight(dev, napi, poll, NAPI_POLL_WEIGHT);
  2400. }
  2401. static inline void
  2402. netif_napi_add_tx_weight(struct net_device *dev,
  2403. struct napi_struct *napi,
  2404. int (*poll)(struct napi_struct *, int),
  2405. int weight)
  2406. {
  2407. set_bit(NAPI_STATE_NO_BUSY_POLL, &napi->state);
  2408. netif_napi_add_weight(dev, napi, poll, weight);
  2409. }
  2410. /**
  2411. * netif_napi_add_tx() - initialize a NAPI context to be used for Tx only
  2412. * @dev: network device
  2413. * @napi: NAPI context
  2414. * @poll: polling function
  2415. *
  2416. * This variant of netif_napi_add() should be used from drivers using NAPI
  2417. * to exclusively poll a TX queue.
  2418. * This will avoid we add it into napi_hash[], thus polluting this hash table.
  2419. */
  2420. static inline void netif_napi_add_tx(struct net_device *dev,
  2421. struct napi_struct *napi,
  2422. int (*poll)(struct napi_struct *, int))
  2423. {
  2424. netif_napi_add_tx_weight(dev, napi, poll, NAPI_POLL_WEIGHT);
  2425. }
  2426. /**
  2427. * __netif_napi_del - remove a NAPI context
  2428. * @napi: NAPI context
  2429. *
  2430. * Warning: caller must observe RCU grace period before freeing memory
  2431. * containing @napi. Drivers might want to call this helper to combine
  2432. * all the needed RCU grace periods into a single one.
  2433. */
  2434. void __netif_napi_del(struct napi_struct *napi);
  2435. /**
  2436. * netif_napi_del - remove a NAPI context
  2437. * @napi: NAPI context
  2438. *
  2439. * netif_napi_del() removes a NAPI context from the network device NAPI list
  2440. */
  2441. static inline void netif_napi_del(struct napi_struct *napi)
  2442. {
  2443. __netif_napi_del(napi);
  2444. synchronize_net();
  2445. }
  2446. struct packet_type {
  2447. __be16 type; /* This is really htons(ether_type). */
  2448. bool ignore_outgoing;
  2449. struct net_device *dev; /* NULL is wildcarded here */
  2450. netdevice_tracker dev_tracker;
  2451. int (*func) (struct sk_buff *,
  2452. struct net_device *,
  2453. struct packet_type *,
  2454. struct net_device *);
  2455. void (*list_func) (struct list_head *,
  2456. struct packet_type *,
  2457. struct net_device *);
  2458. bool (*id_match)(struct packet_type *ptype,
  2459. struct sock *sk);
  2460. struct net *af_packet_net;
  2461. void *af_packet_priv;
  2462. struct list_head list;
  2463. ANDROID_KABI_RESERVE(1);
  2464. ANDROID_KABI_RESERVE(2);
  2465. ANDROID_KABI_RESERVE(3);
  2466. ANDROID_KABI_RESERVE(4);
  2467. };
  2468. struct offload_callbacks {
  2469. struct sk_buff *(*gso_segment)(struct sk_buff *skb,
  2470. netdev_features_t features);
  2471. struct sk_buff *(*gro_receive)(struct list_head *head,
  2472. struct sk_buff *skb);
  2473. int (*gro_complete)(struct sk_buff *skb, int nhoff);
  2474. };
  2475. struct packet_offload {
  2476. __be16 type; /* This is really htons(ether_type). */
  2477. u16 priority;
  2478. struct offload_callbacks callbacks;
  2479. struct list_head list;
  2480. };
  2481. /* often modified stats are per-CPU, other are shared (netdev->stats) */
  2482. struct pcpu_sw_netstats {
  2483. u64_stats_t rx_packets;
  2484. u64_stats_t rx_bytes;
  2485. u64_stats_t tx_packets;
  2486. u64_stats_t tx_bytes;
  2487. struct u64_stats_sync syncp;
  2488. } __aligned(4 * sizeof(u64));
  2489. struct pcpu_lstats {
  2490. u64_stats_t packets;
  2491. u64_stats_t bytes;
  2492. struct u64_stats_sync syncp;
  2493. } __aligned(2 * sizeof(u64));
  2494. void dev_lstats_read(struct net_device *dev, u64 *packets, u64 *bytes);
  2495. static inline void dev_sw_netstats_rx_add(struct net_device *dev, unsigned int len)
  2496. {
  2497. struct pcpu_sw_netstats *tstats = this_cpu_ptr(dev->tstats);
  2498. u64_stats_update_begin(&tstats->syncp);
  2499. u64_stats_add(&tstats->rx_bytes, len);
  2500. u64_stats_inc(&tstats->rx_packets);
  2501. u64_stats_update_end(&tstats->syncp);
  2502. }
  2503. static inline void dev_sw_netstats_tx_add(struct net_device *dev,
  2504. unsigned int packets,
  2505. unsigned int len)
  2506. {
  2507. struct pcpu_sw_netstats *tstats = this_cpu_ptr(dev->tstats);
  2508. u64_stats_update_begin(&tstats->syncp);
  2509. u64_stats_add(&tstats->tx_bytes, len);
  2510. u64_stats_add(&tstats->tx_packets, packets);
  2511. u64_stats_update_end(&tstats->syncp);
  2512. }
  2513. static inline void dev_lstats_add(struct net_device *dev, unsigned int len)
  2514. {
  2515. struct pcpu_lstats *lstats = this_cpu_ptr(dev->lstats);
  2516. u64_stats_update_begin(&lstats->syncp);
  2517. u64_stats_add(&lstats->bytes, len);
  2518. u64_stats_inc(&lstats->packets);
  2519. u64_stats_update_end(&lstats->syncp);
  2520. }
  2521. #define __netdev_alloc_pcpu_stats(type, gfp) \
  2522. ({ \
  2523. typeof(type) __percpu *pcpu_stats = alloc_percpu_gfp(type, gfp);\
  2524. if (pcpu_stats) { \
  2525. int __cpu; \
  2526. for_each_possible_cpu(__cpu) { \
  2527. typeof(type) *stat; \
  2528. stat = per_cpu_ptr(pcpu_stats, __cpu); \
  2529. u64_stats_init(&stat->syncp); \
  2530. } \
  2531. } \
  2532. pcpu_stats; \
  2533. })
  2534. #define netdev_alloc_pcpu_stats(type) \
  2535. __netdev_alloc_pcpu_stats(type, GFP_KERNEL)
  2536. #define devm_netdev_alloc_pcpu_stats(dev, type) \
  2537. ({ \
  2538. typeof(type) __percpu *pcpu_stats = devm_alloc_percpu(dev, type);\
  2539. if (pcpu_stats) { \
  2540. int __cpu; \
  2541. for_each_possible_cpu(__cpu) { \
  2542. typeof(type) *stat; \
  2543. stat = per_cpu_ptr(pcpu_stats, __cpu); \
  2544. u64_stats_init(&stat->syncp); \
  2545. } \
  2546. } \
  2547. pcpu_stats; \
  2548. })
  2549. enum netdev_lag_tx_type {
  2550. NETDEV_LAG_TX_TYPE_UNKNOWN,
  2551. NETDEV_LAG_TX_TYPE_RANDOM,
  2552. NETDEV_LAG_TX_TYPE_BROADCAST,
  2553. NETDEV_LAG_TX_TYPE_ROUNDROBIN,
  2554. NETDEV_LAG_TX_TYPE_ACTIVEBACKUP,
  2555. NETDEV_LAG_TX_TYPE_HASH,
  2556. };
  2557. enum netdev_lag_hash {
  2558. NETDEV_LAG_HASH_NONE,
  2559. NETDEV_LAG_HASH_L2,
  2560. NETDEV_LAG_HASH_L34,
  2561. NETDEV_LAG_HASH_L23,
  2562. NETDEV_LAG_HASH_E23,
  2563. NETDEV_LAG_HASH_E34,
  2564. NETDEV_LAG_HASH_VLAN_SRCMAC,
  2565. NETDEV_LAG_HASH_UNKNOWN,
  2566. };
  2567. struct netdev_lag_upper_info {
  2568. enum netdev_lag_tx_type tx_type;
  2569. enum netdev_lag_hash hash_type;
  2570. };
  2571. struct netdev_lag_lower_state_info {
  2572. u8 link_up : 1,
  2573. tx_enabled : 1;
  2574. };
  2575. #include <linux/notifier.h>
  2576. /* netdevice notifier chain. Please remember to update netdev_cmd_to_name()
  2577. * and the rtnetlink notification exclusion list in rtnetlink_event() when
  2578. * adding new types.
  2579. */
  2580. enum netdev_cmd {
  2581. NETDEV_UP = 1, /* For now you can't veto a device up/down */
  2582. NETDEV_DOWN,
  2583. NETDEV_REBOOT, /* Tell a protocol stack a network interface
  2584. detected a hardware crash and restarted
  2585. - we can use this eg to kick tcp sessions
  2586. once done */
  2587. NETDEV_CHANGE, /* Notify device state change */
  2588. NETDEV_REGISTER,
  2589. NETDEV_UNREGISTER,
  2590. NETDEV_CHANGEMTU, /* notify after mtu change happened */
  2591. NETDEV_CHANGEADDR, /* notify after the address change */
  2592. NETDEV_PRE_CHANGEADDR, /* notify before the address change */
  2593. NETDEV_GOING_DOWN,
  2594. NETDEV_CHANGENAME,
  2595. NETDEV_FEAT_CHANGE,
  2596. NETDEV_BONDING_FAILOVER,
  2597. NETDEV_PRE_UP,
  2598. NETDEV_PRE_TYPE_CHANGE,
  2599. NETDEV_POST_TYPE_CHANGE,
  2600. NETDEV_POST_INIT,
  2601. NETDEV_RELEASE,
  2602. NETDEV_NOTIFY_PEERS,
  2603. NETDEV_JOIN,
  2604. NETDEV_CHANGEUPPER,
  2605. NETDEV_RESEND_IGMP,
  2606. NETDEV_PRECHANGEMTU, /* notify before mtu change happened */
  2607. NETDEV_CHANGEINFODATA,
  2608. NETDEV_BONDING_INFO,
  2609. NETDEV_PRECHANGEUPPER,
  2610. NETDEV_CHANGELOWERSTATE,
  2611. NETDEV_UDP_TUNNEL_PUSH_INFO,
  2612. NETDEV_UDP_TUNNEL_DROP_INFO,
  2613. NETDEV_CHANGE_TX_QUEUE_LEN,
  2614. NETDEV_CVLAN_FILTER_PUSH_INFO,
  2615. NETDEV_CVLAN_FILTER_DROP_INFO,
  2616. NETDEV_SVLAN_FILTER_PUSH_INFO,
  2617. NETDEV_SVLAN_FILTER_DROP_INFO,
  2618. NETDEV_OFFLOAD_XSTATS_ENABLE,
  2619. NETDEV_OFFLOAD_XSTATS_DISABLE,
  2620. NETDEV_OFFLOAD_XSTATS_REPORT_USED,
  2621. NETDEV_OFFLOAD_XSTATS_REPORT_DELTA,
  2622. };
  2623. const char *netdev_cmd_to_name(enum netdev_cmd cmd);
  2624. int register_netdevice_notifier(struct notifier_block *nb);
  2625. int unregister_netdevice_notifier(struct notifier_block *nb);
  2626. int register_netdevice_notifier_net(struct net *net, struct notifier_block *nb);
  2627. int unregister_netdevice_notifier_net(struct net *net,
  2628. struct notifier_block *nb);
  2629. int register_netdevice_notifier_dev_net(struct net_device *dev,
  2630. struct notifier_block *nb,
  2631. struct netdev_net_notifier *nn);
  2632. int unregister_netdevice_notifier_dev_net(struct net_device *dev,
  2633. struct notifier_block *nb,
  2634. struct netdev_net_notifier *nn);
  2635. struct netdev_notifier_info {
  2636. struct net_device *dev;
  2637. struct netlink_ext_ack *extack;
  2638. };
  2639. struct netdev_notifier_info_ext {
  2640. struct netdev_notifier_info info; /* must be first */
  2641. union {
  2642. u32 mtu;
  2643. } ext;
  2644. };
  2645. struct netdev_notifier_change_info {
  2646. struct netdev_notifier_info info; /* must be first */
  2647. unsigned int flags_changed;
  2648. };
  2649. struct netdev_notifier_changeupper_info {
  2650. struct netdev_notifier_info info; /* must be first */
  2651. struct net_device *upper_dev; /* new upper dev */
  2652. bool master; /* is upper dev master */
  2653. bool linking; /* is the notification for link or unlink */
  2654. void *upper_info; /* upper dev info */
  2655. };
  2656. struct netdev_notifier_changelowerstate_info {
  2657. struct netdev_notifier_info info; /* must be first */
  2658. void *lower_state_info; /* is lower dev state */
  2659. };
  2660. struct netdev_notifier_pre_changeaddr_info {
  2661. struct netdev_notifier_info info; /* must be first */
  2662. const unsigned char *dev_addr;
  2663. };
  2664. enum netdev_offload_xstats_type {
  2665. NETDEV_OFFLOAD_XSTATS_TYPE_L3 = 1,
  2666. };
  2667. struct netdev_notifier_offload_xstats_info {
  2668. struct netdev_notifier_info info; /* must be first */
  2669. enum netdev_offload_xstats_type type;
  2670. union {
  2671. /* NETDEV_OFFLOAD_XSTATS_REPORT_DELTA */
  2672. struct netdev_notifier_offload_xstats_rd *report_delta;
  2673. /* NETDEV_OFFLOAD_XSTATS_REPORT_USED */
  2674. struct netdev_notifier_offload_xstats_ru *report_used;
  2675. };
  2676. };
  2677. int netdev_offload_xstats_enable(struct net_device *dev,
  2678. enum netdev_offload_xstats_type type,
  2679. struct netlink_ext_ack *extack);
  2680. int netdev_offload_xstats_disable(struct net_device *dev,
  2681. enum netdev_offload_xstats_type type);
  2682. bool netdev_offload_xstats_enabled(const struct net_device *dev,
  2683. enum netdev_offload_xstats_type type);
  2684. int netdev_offload_xstats_get(struct net_device *dev,
  2685. enum netdev_offload_xstats_type type,
  2686. struct rtnl_hw_stats64 *stats, bool *used,
  2687. struct netlink_ext_ack *extack);
  2688. void
  2689. netdev_offload_xstats_report_delta(struct netdev_notifier_offload_xstats_rd *rd,
  2690. const struct rtnl_hw_stats64 *stats);
  2691. void
  2692. netdev_offload_xstats_report_used(struct netdev_notifier_offload_xstats_ru *ru);
  2693. void netdev_offload_xstats_push_delta(struct net_device *dev,
  2694. enum netdev_offload_xstats_type type,
  2695. const struct rtnl_hw_stats64 *stats);
  2696. static inline void netdev_notifier_info_init(struct netdev_notifier_info *info,
  2697. struct net_device *dev)
  2698. {
  2699. info->dev = dev;
  2700. info->extack = NULL;
  2701. }
  2702. static inline struct net_device *
  2703. netdev_notifier_info_to_dev(const struct netdev_notifier_info *info)
  2704. {
  2705. return info->dev;
  2706. }
  2707. static inline struct netlink_ext_ack *
  2708. netdev_notifier_info_to_extack(const struct netdev_notifier_info *info)
  2709. {
  2710. return info->extack;
  2711. }
  2712. int call_netdevice_notifiers(unsigned long val, struct net_device *dev);
  2713. extern rwlock_t dev_base_lock; /* Device list lock */
  2714. #define for_each_netdev(net, d) \
  2715. list_for_each_entry(d, &(net)->dev_base_head, dev_list)
  2716. #define for_each_netdev_reverse(net, d) \
  2717. list_for_each_entry_reverse(d, &(net)->dev_base_head, dev_list)
  2718. #define for_each_netdev_rcu(net, d) \
  2719. list_for_each_entry_rcu(d, &(net)->dev_base_head, dev_list)
  2720. #define for_each_netdev_safe(net, d, n) \
  2721. list_for_each_entry_safe(d, n, &(net)->dev_base_head, dev_list)
  2722. #define for_each_netdev_continue(net, d) \
  2723. list_for_each_entry_continue(d, &(net)->dev_base_head, dev_list)
  2724. #define for_each_netdev_continue_reverse(net, d) \
  2725. list_for_each_entry_continue_reverse(d, &(net)->dev_base_head, \
  2726. dev_list)
  2727. #define for_each_netdev_continue_rcu(net, d) \
  2728. list_for_each_entry_continue_rcu(d, &(net)->dev_base_head, dev_list)
  2729. #define for_each_netdev_in_bond_rcu(bond, slave) \
  2730. for_each_netdev_rcu(&init_net, slave) \
  2731. if (netdev_master_upper_dev_get_rcu(slave) == (bond))
  2732. #define net_device_entry(lh) list_entry(lh, struct net_device, dev_list)
  2733. static inline struct net_device *next_net_device(struct net_device *dev)
  2734. {
  2735. struct list_head *lh;
  2736. struct net *net;
  2737. net = dev_net(dev);
  2738. lh = dev->dev_list.next;
  2739. return lh == &net->dev_base_head ? NULL : net_device_entry(lh);
  2740. }
  2741. static inline struct net_device *next_net_device_rcu(struct net_device *dev)
  2742. {
  2743. struct list_head *lh;
  2744. struct net *net;
  2745. net = dev_net(dev);
  2746. lh = rcu_dereference(list_next_rcu(&dev->dev_list));
  2747. return lh == &net->dev_base_head ? NULL : net_device_entry(lh);
  2748. }
  2749. static inline struct net_device *first_net_device(struct net *net)
  2750. {
  2751. return list_empty(&net->dev_base_head) ? NULL :
  2752. net_device_entry(net->dev_base_head.next);
  2753. }
  2754. static inline struct net_device *first_net_device_rcu(struct net *net)
  2755. {
  2756. struct list_head *lh = rcu_dereference(list_next_rcu(&net->dev_base_head));
  2757. return lh == &net->dev_base_head ? NULL : net_device_entry(lh);
  2758. }
  2759. int netdev_boot_setup_check(struct net_device *dev);
  2760. struct net_device *dev_getbyhwaddr_rcu(struct net *net, unsigned short type,
  2761. const char *hwaddr);
  2762. struct net_device *dev_getfirstbyhwtype(struct net *net, unsigned short type);
  2763. void dev_add_pack(struct packet_type *pt);
  2764. void dev_remove_pack(struct packet_type *pt);
  2765. void __dev_remove_pack(struct packet_type *pt);
  2766. void dev_add_offload(struct packet_offload *po);
  2767. void dev_remove_offload(struct packet_offload *po);
  2768. int dev_get_iflink(const struct net_device *dev);
  2769. int dev_fill_metadata_dst(struct net_device *dev, struct sk_buff *skb);
  2770. int dev_fill_forward_path(const struct net_device *dev, const u8 *daddr,
  2771. struct net_device_path_stack *stack);
  2772. struct net_device *__dev_get_by_flags(struct net *net, unsigned short flags,
  2773. unsigned short mask);
  2774. struct net_device *dev_get_by_name(struct net *net, const char *name);
  2775. struct net_device *dev_get_by_name_rcu(struct net *net, const char *name);
  2776. struct net_device *__dev_get_by_name(struct net *net, const char *name);
  2777. bool netdev_name_in_use(struct net *net, const char *name);
  2778. int dev_alloc_name(struct net_device *dev, const char *name);
  2779. int dev_open(struct net_device *dev, struct netlink_ext_ack *extack);
  2780. void dev_close(struct net_device *dev);
  2781. void dev_close_many(struct list_head *head, bool unlink);
  2782. void dev_disable_lro(struct net_device *dev);
  2783. int dev_loopback_xmit(struct net *net, struct sock *sk, struct sk_buff *newskb);
  2784. u16 dev_pick_tx_zero(struct net_device *dev, struct sk_buff *skb,
  2785. struct net_device *sb_dev);
  2786. u16 dev_pick_tx_cpu_id(struct net_device *dev, struct sk_buff *skb,
  2787. struct net_device *sb_dev);
  2788. int __dev_queue_xmit(struct sk_buff *skb, struct net_device *sb_dev);
  2789. int __dev_direct_xmit(struct sk_buff *skb, u16 queue_id);
  2790. static inline int dev_queue_xmit(struct sk_buff *skb)
  2791. {
  2792. return __dev_queue_xmit(skb, NULL);
  2793. }
  2794. static inline int dev_queue_xmit_accel(struct sk_buff *skb,
  2795. struct net_device *sb_dev)
  2796. {
  2797. return __dev_queue_xmit(skb, sb_dev);
  2798. }
  2799. static inline int dev_direct_xmit(struct sk_buff *skb, u16 queue_id)
  2800. {
  2801. int ret;
  2802. ret = __dev_direct_xmit(skb, queue_id);
  2803. if (!dev_xmit_complete(ret))
  2804. kfree_skb(skb);
  2805. return ret;
  2806. }
  2807. int register_netdevice(struct net_device *dev);
  2808. void unregister_netdevice_queue(struct net_device *dev, struct list_head *head);
  2809. void unregister_netdevice_many(struct list_head *head);
  2810. static inline void unregister_netdevice(struct net_device *dev)
  2811. {
  2812. unregister_netdevice_queue(dev, NULL);
  2813. }
  2814. int netdev_refcnt_read(const struct net_device *dev);
  2815. void free_netdev(struct net_device *dev);
  2816. void netdev_freemem(struct net_device *dev);
  2817. int init_dummy_netdev(struct net_device *dev);
  2818. struct net_device *netdev_get_xmit_slave(struct net_device *dev,
  2819. struct sk_buff *skb,
  2820. bool all_slaves);
  2821. struct net_device *netdev_sk_get_lowest_dev(struct net_device *dev,
  2822. struct sock *sk);
  2823. struct net_device *dev_get_by_index(struct net *net, int ifindex);
  2824. struct net_device *__dev_get_by_index(struct net *net, int ifindex);
  2825. struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex);
  2826. struct net_device *dev_get_by_napi_id(unsigned int napi_id);
  2827. int dev_restart(struct net_device *dev);
  2828. static inline int dev_hard_header(struct sk_buff *skb, struct net_device *dev,
  2829. unsigned short type,
  2830. const void *daddr, const void *saddr,
  2831. unsigned int len)
  2832. {
  2833. if (!dev->header_ops || !dev->header_ops->create)
  2834. return 0;
  2835. return dev->header_ops->create(skb, dev, type, daddr, saddr, len);
  2836. }
  2837. static inline int dev_parse_header(const struct sk_buff *skb,
  2838. unsigned char *haddr)
  2839. {
  2840. const struct net_device *dev = skb->dev;
  2841. if (!dev->header_ops || !dev->header_ops->parse)
  2842. return 0;
  2843. return dev->header_ops->parse(skb, haddr);
  2844. }
  2845. static inline __be16 dev_parse_header_protocol(const struct sk_buff *skb)
  2846. {
  2847. const struct net_device *dev = skb->dev;
  2848. if (!dev->header_ops || !dev->header_ops->parse_protocol)
  2849. return 0;
  2850. return dev->header_ops->parse_protocol(skb);
  2851. }
  2852. /* ll_header must have at least hard_header_len allocated */
  2853. static inline bool dev_validate_header(const struct net_device *dev,
  2854. char *ll_header, int len)
  2855. {
  2856. if (likely(len >= dev->hard_header_len))
  2857. return true;
  2858. if (len < dev->min_header_len)
  2859. return false;
  2860. if (capable(CAP_SYS_RAWIO)) {
  2861. memset(ll_header + len, 0, dev->hard_header_len - len);
  2862. return true;
  2863. }
  2864. if (dev->header_ops && dev->header_ops->validate)
  2865. return dev->header_ops->validate(ll_header, len);
  2866. return false;
  2867. }
  2868. static inline bool dev_has_header(const struct net_device *dev)
  2869. {
  2870. return dev->header_ops && dev->header_ops->create;
  2871. }
  2872. /*
  2873. * Incoming packets are placed on per-CPU queues
  2874. */
  2875. struct softnet_data {
  2876. struct list_head poll_list;
  2877. struct sk_buff_head process_queue;
  2878. /* stats */
  2879. unsigned int processed;
  2880. unsigned int time_squeeze;
  2881. unsigned int received_rps;
  2882. #ifdef CONFIG_RPS
  2883. struct softnet_data *rps_ipi_list;
  2884. #endif
  2885. #ifdef CONFIG_NET_FLOW_LIMIT
  2886. struct sd_flow_limit __rcu *flow_limit;
  2887. #endif
  2888. struct Qdisc *output_queue;
  2889. struct Qdisc **output_queue_tailp;
  2890. struct sk_buff *completion_queue;
  2891. #ifdef CONFIG_XFRM_OFFLOAD
  2892. struct sk_buff_head xfrm_backlog;
  2893. #endif
  2894. /* written and read only by owning cpu: */
  2895. struct {
  2896. u16 recursion;
  2897. u8 more;
  2898. #ifdef CONFIG_NET_EGRESS
  2899. u8 skip_txqueue;
  2900. #endif
  2901. } xmit;
  2902. #ifdef CONFIG_RPS
  2903. /* input_queue_head should be written by cpu owning this struct,
  2904. * and only read by other cpus. Worth using a cache line.
  2905. */
  2906. unsigned int input_queue_head ____cacheline_aligned_in_smp;
  2907. /* Elements below can be accessed between CPUs for RPS/RFS */
  2908. call_single_data_t csd ____cacheline_aligned_in_smp;
  2909. struct softnet_data *rps_ipi_next;
  2910. unsigned int cpu;
  2911. unsigned int input_queue_tail;
  2912. #endif
  2913. unsigned int dropped;
  2914. struct sk_buff_head input_pkt_queue;
  2915. struct napi_struct backlog;
  2916. /* Another possibly contended cache line */
  2917. spinlock_t defer_lock ____cacheline_aligned_in_smp;
  2918. int defer_count;
  2919. int defer_ipi_scheduled;
  2920. struct sk_buff *defer_list;
  2921. call_single_data_t defer_csd;
  2922. };
  2923. static inline void input_queue_head_incr(struct softnet_data *sd)
  2924. {
  2925. #ifdef CONFIG_RPS
  2926. sd->input_queue_head++;
  2927. #endif
  2928. }
  2929. static inline void input_queue_tail_incr_save(struct softnet_data *sd,
  2930. unsigned int *qtail)
  2931. {
  2932. #ifdef CONFIG_RPS
  2933. *qtail = ++sd->input_queue_tail;
  2934. #endif
  2935. }
  2936. DECLARE_PER_CPU_ALIGNED(struct softnet_data, softnet_data);
  2937. static inline int dev_recursion_level(void)
  2938. {
  2939. return this_cpu_read(softnet_data.xmit.recursion);
  2940. }
  2941. #define XMIT_RECURSION_LIMIT 8
  2942. static inline bool dev_xmit_recursion(void)
  2943. {
  2944. return unlikely(__this_cpu_read(softnet_data.xmit.recursion) >
  2945. XMIT_RECURSION_LIMIT);
  2946. }
  2947. static inline void dev_xmit_recursion_inc(void)
  2948. {
  2949. __this_cpu_inc(softnet_data.xmit.recursion);
  2950. }
  2951. static inline void dev_xmit_recursion_dec(void)
  2952. {
  2953. __this_cpu_dec(softnet_data.xmit.recursion);
  2954. }
  2955. void __netif_schedule(struct Qdisc *q);
  2956. void netif_schedule_queue(struct netdev_queue *txq);
  2957. static inline void netif_tx_schedule_all(struct net_device *dev)
  2958. {
  2959. unsigned int i;
  2960. for (i = 0; i < dev->num_tx_queues; i++)
  2961. netif_schedule_queue(netdev_get_tx_queue(dev, i));
  2962. }
  2963. static __always_inline void netif_tx_start_queue(struct netdev_queue *dev_queue)
  2964. {
  2965. clear_bit(__QUEUE_STATE_DRV_XOFF, &dev_queue->state);
  2966. }
  2967. /**
  2968. * netif_start_queue - allow transmit
  2969. * @dev: network device
  2970. *
  2971. * Allow upper layers to call the device hard_start_xmit routine.
  2972. */
  2973. static inline void netif_start_queue(struct net_device *dev)
  2974. {
  2975. netif_tx_start_queue(netdev_get_tx_queue(dev, 0));
  2976. }
  2977. static inline void netif_tx_start_all_queues(struct net_device *dev)
  2978. {
  2979. unsigned int i;
  2980. for (i = 0; i < dev->num_tx_queues; i++) {
  2981. struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
  2982. netif_tx_start_queue(txq);
  2983. }
  2984. }
  2985. void netif_tx_wake_queue(struct netdev_queue *dev_queue);
  2986. /**
  2987. * netif_wake_queue - restart transmit
  2988. * @dev: network device
  2989. *
  2990. * Allow upper layers to call the device hard_start_xmit routine.
  2991. * Used for flow control when transmit resources are available.
  2992. */
  2993. static inline void netif_wake_queue(struct net_device *dev)
  2994. {
  2995. netif_tx_wake_queue(netdev_get_tx_queue(dev, 0));
  2996. }
  2997. static inline void netif_tx_wake_all_queues(struct net_device *dev)
  2998. {
  2999. unsigned int i;
  3000. for (i = 0; i < dev->num_tx_queues; i++) {
  3001. struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
  3002. netif_tx_wake_queue(txq);
  3003. }
  3004. }
  3005. static __always_inline void netif_tx_stop_queue(struct netdev_queue *dev_queue)
  3006. {
  3007. set_bit(__QUEUE_STATE_DRV_XOFF, &dev_queue->state);
  3008. }
  3009. /**
  3010. * netif_stop_queue - stop transmitted packets
  3011. * @dev: network device
  3012. *
  3013. * Stop upper layers calling the device hard_start_xmit routine.
  3014. * Used for flow control when transmit resources are unavailable.
  3015. */
  3016. static inline void netif_stop_queue(struct net_device *dev)
  3017. {
  3018. netif_tx_stop_queue(netdev_get_tx_queue(dev, 0));
  3019. }
  3020. void netif_tx_stop_all_queues(struct net_device *dev);
  3021. static inline bool netif_tx_queue_stopped(const struct netdev_queue *dev_queue)
  3022. {
  3023. return test_bit(__QUEUE_STATE_DRV_XOFF, &dev_queue->state);
  3024. }
  3025. /**
  3026. * netif_queue_stopped - test if transmit queue is flowblocked
  3027. * @dev: network device
  3028. *
  3029. * Test if transmit queue on device is currently unable to send.
  3030. */
  3031. static inline bool netif_queue_stopped(const struct net_device *dev)
  3032. {
  3033. return netif_tx_queue_stopped(netdev_get_tx_queue(dev, 0));
  3034. }
  3035. static inline bool netif_xmit_stopped(const struct netdev_queue *dev_queue)
  3036. {
  3037. return dev_queue->state & QUEUE_STATE_ANY_XOFF;
  3038. }
  3039. static inline bool
  3040. netif_xmit_frozen_or_stopped(const struct netdev_queue *dev_queue)
  3041. {
  3042. return dev_queue->state & QUEUE_STATE_ANY_XOFF_OR_FROZEN;
  3043. }
  3044. static inline bool
  3045. netif_xmit_frozen_or_drv_stopped(const struct netdev_queue *dev_queue)
  3046. {
  3047. return dev_queue->state & QUEUE_STATE_DRV_XOFF_OR_FROZEN;
  3048. }
  3049. /**
  3050. * netdev_queue_set_dql_min_limit - set dql minimum limit
  3051. * @dev_queue: pointer to transmit queue
  3052. * @min_limit: dql minimum limit
  3053. *
  3054. * Forces xmit_more() to return true until the minimum threshold
  3055. * defined by @min_limit is reached (or until the tx queue is
  3056. * empty). Warning: to be use with care, misuse will impact the
  3057. * latency.
  3058. */
  3059. static inline void netdev_queue_set_dql_min_limit(struct netdev_queue *dev_queue,
  3060. unsigned int min_limit)
  3061. {
  3062. #ifdef CONFIG_BQL
  3063. dev_queue->dql.min_limit = min_limit;
  3064. #endif
  3065. }
  3066. /**
  3067. * netdev_txq_bql_enqueue_prefetchw - prefetch bql data for write
  3068. * @dev_queue: pointer to transmit queue
  3069. *
  3070. * BQL enabled drivers might use this helper in their ndo_start_xmit(),
  3071. * to give appropriate hint to the CPU.
  3072. */
  3073. static inline void netdev_txq_bql_enqueue_prefetchw(struct netdev_queue *dev_queue)
  3074. {
  3075. #ifdef CONFIG_BQL
  3076. prefetchw(&dev_queue->dql.num_queued);
  3077. #endif
  3078. }
  3079. /**
  3080. * netdev_txq_bql_complete_prefetchw - prefetch bql data for write
  3081. * @dev_queue: pointer to transmit queue
  3082. *
  3083. * BQL enabled drivers might use this helper in their TX completion path,
  3084. * to give appropriate hint to the CPU.
  3085. */
  3086. static inline void netdev_txq_bql_complete_prefetchw(struct netdev_queue *dev_queue)
  3087. {
  3088. #ifdef CONFIG_BQL
  3089. prefetchw(&dev_queue->dql.limit);
  3090. #endif
  3091. }
  3092. /**
  3093. * netdev_tx_sent_queue - report the number of bytes queued to a given tx queue
  3094. * @dev_queue: network device queue
  3095. * @bytes: number of bytes queued to the device queue
  3096. *
  3097. * Report the number of bytes queued for sending/completion to the network
  3098. * device hardware queue. @bytes should be a good approximation and should
  3099. * exactly match netdev_completed_queue() @bytes.
  3100. * This is typically called once per packet, from ndo_start_xmit().
  3101. */
  3102. static inline void netdev_tx_sent_queue(struct netdev_queue *dev_queue,
  3103. unsigned int bytes)
  3104. {
  3105. #ifdef CONFIG_BQL
  3106. dql_queued(&dev_queue->dql, bytes);
  3107. if (likely(dql_avail(&dev_queue->dql) >= 0))
  3108. return;
  3109. set_bit(__QUEUE_STATE_STACK_XOFF, &dev_queue->state);
  3110. /*
  3111. * The XOFF flag must be set before checking the dql_avail below,
  3112. * because in netdev_tx_completed_queue we update the dql_completed
  3113. * before checking the XOFF flag.
  3114. */
  3115. smp_mb();
  3116. /* check again in case another CPU has just made room avail */
  3117. if (unlikely(dql_avail(&dev_queue->dql) >= 0))
  3118. clear_bit(__QUEUE_STATE_STACK_XOFF, &dev_queue->state);
  3119. #endif
  3120. }
  3121. /* Variant of netdev_tx_sent_queue() for drivers that are aware
  3122. * that they should not test BQL status themselves.
  3123. * We do want to change __QUEUE_STATE_STACK_XOFF only for the last
  3124. * skb of a batch.
  3125. * Returns true if the doorbell must be used to kick the NIC.
  3126. */
  3127. static inline bool __netdev_tx_sent_queue(struct netdev_queue *dev_queue,
  3128. unsigned int bytes,
  3129. bool xmit_more)
  3130. {
  3131. if (xmit_more) {
  3132. #ifdef CONFIG_BQL
  3133. dql_queued(&dev_queue->dql, bytes);
  3134. #endif
  3135. return netif_tx_queue_stopped(dev_queue);
  3136. }
  3137. netdev_tx_sent_queue(dev_queue, bytes);
  3138. return true;
  3139. }
  3140. /**
  3141. * netdev_sent_queue - report the number of bytes queued to hardware
  3142. * @dev: network device
  3143. * @bytes: number of bytes queued to the hardware device queue
  3144. *
  3145. * Report the number of bytes queued for sending/completion to the network
  3146. * device hardware queue#0. @bytes should be a good approximation and should
  3147. * exactly match netdev_completed_queue() @bytes.
  3148. * This is typically called once per packet, from ndo_start_xmit().
  3149. */
  3150. static inline void netdev_sent_queue(struct net_device *dev, unsigned int bytes)
  3151. {
  3152. netdev_tx_sent_queue(netdev_get_tx_queue(dev, 0), bytes);
  3153. }
  3154. static inline bool __netdev_sent_queue(struct net_device *dev,
  3155. unsigned int bytes,
  3156. bool xmit_more)
  3157. {
  3158. return __netdev_tx_sent_queue(netdev_get_tx_queue(dev, 0), bytes,
  3159. xmit_more);
  3160. }
  3161. /**
  3162. * netdev_tx_completed_queue - report number of packets/bytes at TX completion.
  3163. * @dev_queue: network device queue
  3164. * @pkts: number of packets (currently ignored)
  3165. * @bytes: number of bytes dequeued from the device queue
  3166. *
  3167. * Must be called at most once per TX completion round (and not per
  3168. * individual packet), so that BQL can adjust its limits appropriately.
  3169. */
  3170. static inline void netdev_tx_completed_queue(struct netdev_queue *dev_queue,
  3171. unsigned int pkts, unsigned int bytes)
  3172. {
  3173. #ifdef CONFIG_BQL
  3174. if (unlikely(!bytes))
  3175. return;
  3176. dql_completed(&dev_queue->dql, bytes);
  3177. /*
  3178. * Without the memory barrier there is a small possiblity that
  3179. * netdev_tx_sent_queue will miss the update and cause the queue to
  3180. * be stopped forever
  3181. */
  3182. smp_mb();
  3183. if (unlikely(dql_avail(&dev_queue->dql) < 0))
  3184. return;
  3185. if (test_and_clear_bit(__QUEUE_STATE_STACK_XOFF, &dev_queue->state))
  3186. netif_schedule_queue(dev_queue);
  3187. #endif
  3188. }
  3189. /**
  3190. * netdev_completed_queue - report bytes and packets completed by device
  3191. * @dev: network device
  3192. * @pkts: actual number of packets sent over the medium
  3193. * @bytes: actual number of bytes sent over the medium
  3194. *
  3195. * Report the number of bytes and packets transmitted by the network device
  3196. * hardware queue over the physical medium, @bytes must exactly match the
  3197. * @bytes amount passed to netdev_sent_queue()
  3198. */
  3199. static inline void netdev_completed_queue(struct net_device *dev,
  3200. unsigned int pkts, unsigned int bytes)
  3201. {
  3202. netdev_tx_completed_queue(netdev_get_tx_queue(dev, 0), pkts, bytes);
  3203. }
  3204. static inline void netdev_tx_reset_queue(struct netdev_queue *q)
  3205. {
  3206. #ifdef CONFIG_BQL
  3207. clear_bit(__QUEUE_STATE_STACK_XOFF, &q->state);
  3208. dql_reset(&q->dql);
  3209. #endif
  3210. }
  3211. /**
  3212. * netdev_reset_queue - reset the packets and bytes count of a network device
  3213. * @dev_queue: network device
  3214. *
  3215. * Reset the bytes and packet count of a network device and clear the
  3216. * software flow control OFF bit for this network device
  3217. */
  3218. static inline void netdev_reset_queue(struct net_device *dev_queue)
  3219. {
  3220. netdev_tx_reset_queue(netdev_get_tx_queue(dev_queue, 0));
  3221. }
  3222. /**
  3223. * netdev_cap_txqueue - check if selected tx queue exceeds device queues
  3224. * @dev: network device
  3225. * @queue_index: given tx queue index
  3226. *
  3227. * Returns 0 if given tx queue index >= number of device tx queues,
  3228. * otherwise returns the originally passed tx queue index.
  3229. */
  3230. static inline u16 netdev_cap_txqueue(struct net_device *dev, u16 queue_index)
  3231. {
  3232. if (unlikely(queue_index >= dev->real_num_tx_queues)) {
  3233. net_warn_ratelimited("%s selects TX queue %d, but real number of TX queues is %d\n",
  3234. dev->name, queue_index,
  3235. dev->real_num_tx_queues);
  3236. return 0;
  3237. }
  3238. return queue_index;
  3239. }
  3240. /**
  3241. * netif_running - test if up
  3242. * @dev: network device
  3243. *
  3244. * Test if the device has been brought up.
  3245. */
  3246. static inline bool netif_running(const struct net_device *dev)
  3247. {
  3248. return test_bit(__LINK_STATE_START, &dev->state);
  3249. }
  3250. /*
  3251. * Routines to manage the subqueues on a device. We only need start,
  3252. * stop, and a check if it's stopped. All other device management is
  3253. * done at the overall netdevice level.
  3254. * Also test the device if we're multiqueue.
  3255. */
  3256. /**
  3257. * netif_start_subqueue - allow sending packets on subqueue
  3258. * @dev: network device
  3259. * @queue_index: sub queue index
  3260. *
  3261. * Start individual transmit queue of a device with multiple transmit queues.
  3262. */
  3263. static inline void netif_start_subqueue(struct net_device *dev, u16 queue_index)
  3264. {
  3265. struct netdev_queue *txq = netdev_get_tx_queue(dev, queue_index);
  3266. netif_tx_start_queue(txq);
  3267. }
  3268. /**
  3269. * netif_stop_subqueue - stop sending packets on subqueue
  3270. * @dev: network device
  3271. * @queue_index: sub queue index
  3272. *
  3273. * Stop individual transmit queue of a device with multiple transmit queues.
  3274. */
  3275. static inline void netif_stop_subqueue(struct net_device *dev, u16 queue_index)
  3276. {
  3277. struct netdev_queue *txq = netdev_get_tx_queue(dev, queue_index);
  3278. netif_tx_stop_queue(txq);
  3279. }
  3280. /**
  3281. * __netif_subqueue_stopped - test status of subqueue
  3282. * @dev: network device
  3283. * @queue_index: sub queue index
  3284. *
  3285. * Check individual transmit queue of a device with multiple transmit queues.
  3286. */
  3287. static inline bool __netif_subqueue_stopped(const struct net_device *dev,
  3288. u16 queue_index)
  3289. {
  3290. struct netdev_queue *txq = netdev_get_tx_queue(dev, queue_index);
  3291. return netif_tx_queue_stopped(txq);
  3292. }
  3293. /**
  3294. * netif_subqueue_stopped - test status of subqueue
  3295. * @dev: network device
  3296. * @skb: sub queue buffer pointer
  3297. *
  3298. * Check individual transmit queue of a device with multiple transmit queues.
  3299. */
  3300. static inline bool netif_subqueue_stopped(const struct net_device *dev,
  3301. struct sk_buff *skb)
  3302. {
  3303. return __netif_subqueue_stopped(dev, skb_get_queue_mapping(skb));
  3304. }
  3305. /**
  3306. * netif_wake_subqueue - allow sending packets on subqueue
  3307. * @dev: network device
  3308. * @queue_index: sub queue index
  3309. *
  3310. * Resume individual transmit queue of a device with multiple transmit queues.
  3311. */
  3312. static inline void netif_wake_subqueue(struct net_device *dev, u16 queue_index)
  3313. {
  3314. struct netdev_queue *txq = netdev_get_tx_queue(dev, queue_index);
  3315. netif_tx_wake_queue(txq);
  3316. }
  3317. #ifdef CONFIG_XPS
  3318. int netif_set_xps_queue(struct net_device *dev, const struct cpumask *mask,
  3319. u16 index);
  3320. int __netif_set_xps_queue(struct net_device *dev, const unsigned long *mask,
  3321. u16 index, enum xps_map_type type);
  3322. /**
  3323. * netif_attr_test_mask - Test a CPU or Rx queue set in a mask
  3324. * @j: CPU/Rx queue index
  3325. * @mask: bitmask of all cpus/rx queues
  3326. * @nr_bits: number of bits in the bitmask
  3327. *
  3328. * Test if a CPU or Rx queue index is set in a mask of all CPU/Rx queues.
  3329. */
  3330. static inline bool netif_attr_test_mask(unsigned long j,
  3331. const unsigned long *mask,
  3332. unsigned int nr_bits)
  3333. {
  3334. cpu_max_bits_warn(j, nr_bits);
  3335. return test_bit(j, mask);
  3336. }
  3337. /**
  3338. * netif_attr_test_online - Test for online CPU/Rx queue
  3339. * @j: CPU/Rx queue index
  3340. * @online_mask: bitmask for CPUs/Rx queues that are online
  3341. * @nr_bits: number of bits in the bitmask
  3342. *
  3343. * Returns true if a CPU/Rx queue is online.
  3344. */
  3345. static inline bool netif_attr_test_online(unsigned long j,
  3346. const unsigned long *online_mask,
  3347. unsigned int nr_bits)
  3348. {
  3349. cpu_max_bits_warn(j, nr_bits);
  3350. if (online_mask)
  3351. return test_bit(j, online_mask);
  3352. return (j < nr_bits);
  3353. }
  3354. /**
  3355. * netif_attrmask_next - get the next CPU/Rx queue in a cpu/Rx queues mask
  3356. * @n: CPU/Rx queue index
  3357. * @srcp: the cpumask/Rx queue mask pointer
  3358. * @nr_bits: number of bits in the bitmask
  3359. *
  3360. * Returns >= nr_bits if no further CPUs/Rx queues set.
  3361. */
  3362. static inline unsigned int netif_attrmask_next(int n, const unsigned long *srcp,
  3363. unsigned int nr_bits)
  3364. {
  3365. /* -1 is a legal arg here. */
  3366. if (n != -1)
  3367. cpu_max_bits_warn(n, nr_bits);
  3368. if (srcp)
  3369. return find_next_bit(srcp, nr_bits, n + 1);
  3370. return n + 1;
  3371. }
  3372. /**
  3373. * netif_attrmask_next_and - get the next CPU/Rx queue in \*src1p & \*src2p
  3374. * @n: CPU/Rx queue index
  3375. * @src1p: the first CPUs/Rx queues mask pointer
  3376. * @src2p: the second CPUs/Rx queues mask pointer
  3377. * @nr_bits: number of bits in the bitmask
  3378. *
  3379. * Returns >= nr_bits if no further CPUs/Rx queues set in both.
  3380. */
  3381. static inline int netif_attrmask_next_and(int n, const unsigned long *src1p,
  3382. const unsigned long *src2p,
  3383. unsigned int nr_bits)
  3384. {
  3385. /* -1 is a legal arg here. */
  3386. if (n != -1)
  3387. cpu_max_bits_warn(n, nr_bits);
  3388. if (src1p && src2p)
  3389. return find_next_and_bit(src1p, src2p, nr_bits, n + 1);
  3390. else if (src1p)
  3391. return find_next_bit(src1p, nr_bits, n + 1);
  3392. else if (src2p)
  3393. return find_next_bit(src2p, nr_bits, n + 1);
  3394. return n + 1;
  3395. }
  3396. #else
  3397. static inline int netif_set_xps_queue(struct net_device *dev,
  3398. const struct cpumask *mask,
  3399. u16 index)
  3400. {
  3401. return 0;
  3402. }
  3403. static inline int __netif_set_xps_queue(struct net_device *dev,
  3404. const unsigned long *mask,
  3405. u16 index, enum xps_map_type type)
  3406. {
  3407. return 0;
  3408. }
  3409. #endif
  3410. /**
  3411. * netif_is_multiqueue - test if device has multiple transmit queues
  3412. * @dev: network device
  3413. *
  3414. * Check if device has multiple transmit queues
  3415. */
  3416. static inline bool netif_is_multiqueue(const struct net_device *dev)
  3417. {
  3418. return dev->num_tx_queues > 1;
  3419. }
  3420. int netif_set_real_num_tx_queues(struct net_device *dev, unsigned int txq);
  3421. #ifdef CONFIG_SYSFS
  3422. int netif_set_real_num_rx_queues(struct net_device *dev, unsigned int rxq);
  3423. #else
  3424. static inline int netif_set_real_num_rx_queues(struct net_device *dev,
  3425. unsigned int rxqs)
  3426. {
  3427. dev->real_num_rx_queues = rxqs;
  3428. return 0;
  3429. }
  3430. #endif
  3431. int netif_set_real_num_queues(struct net_device *dev,
  3432. unsigned int txq, unsigned int rxq);
  3433. static inline struct netdev_rx_queue *
  3434. __netif_get_rx_queue(struct net_device *dev, unsigned int rxq)
  3435. {
  3436. return dev->_rx + rxq;
  3437. }
  3438. #ifdef CONFIG_SYSFS
  3439. static inline unsigned int get_netdev_rx_queue_index(
  3440. struct netdev_rx_queue *queue)
  3441. {
  3442. struct net_device *dev = queue->dev;
  3443. int index = queue - dev->_rx;
  3444. BUG_ON(index >= dev->num_rx_queues);
  3445. return index;
  3446. }
  3447. #endif
  3448. int netif_get_num_default_rss_queues(void);
  3449. enum skb_free_reason {
  3450. SKB_REASON_CONSUMED,
  3451. SKB_REASON_DROPPED,
  3452. };
  3453. void __dev_kfree_skb_irq(struct sk_buff *skb, enum skb_free_reason reason);
  3454. void __dev_kfree_skb_any(struct sk_buff *skb, enum skb_free_reason reason);
  3455. /*
  3456. * It is not allowed to call kfree_skb() or consume_skb() from hardware
  3457. * interrupt context or with hardware interrupts being disabled.
  3458. * (in_hardirq() || irqs_disabled())
  3459. *
  3460. * We provide four helpers that can be used in following contexts :
  3461. *
  3462. * dev_kfree_skb_irq(skb) when caller drops a packet from irq context,
  3463. * replacing kfree_skb(skb)
  3464. *
  3465. * dev_consume_skb_irq(skb) when caller consumes a packet from irq context.
  3466. * Typically used in place of consume_skb(skb) in TX completion path
  3467. *
  3468. * dev_kfree_skb_any(skb) when caller doesn't know its current irq context,
  3469. * replacing kfree_skb(skb)
  3470. *
  3471. * dev_consume_skb_any(skb) when caller doesn't know its current irq context,
  3472. * and consumed a packet. Used in place of consume_skb(skb)
  3473. */
  3474. static inline void dev_kfree_skb_irq(struct sk_buff *skb)
  3475. {
  3476. __dev_kfree_skb_irq(skb, SKB_REASON_DROPPED);
  3477. }
  3478. static inline void dev_consume_skb_irq(struct sk_buff *skb)
  3479. {
  3480. __dev_kfree_skb_irq(skb, SKB_REASON_CONSUMED);
  3481. }
  3482. static inline void dev_kfree_skb_any(struct sk_buff *skb)
  3483. {
  3484. __dev_kfree_skb_any(skb, SKB_REASON_DROPPED);
  3485. }
  3486. static inline void dev_consume_skb_any(struct sk_buff *skb)
  3487. {
  3488. __dev_kfree_skb_any(skb, SKB_REASON_CONSUMED);
  3489. }
  3490. u32 bpf_prog_run_generic_xdp(struct sk_buff *skb, struct xdp_buff *xdp,
  3491. struct bpf_prog *xdp_prog);
  3492. void generic_xdp_tx(struct sk_buff *skb, struct bpf_prog *xdp_prog);
  3493. int do_xdp_generic(struct bpf_prog *xdp_prog, struct sk_buff *skb);
  3494. int netif_rx(struct sk_buff *skb);
  3495. int __netif_rx(struct sk_buff *skb);
  3496. int netif_receive_skb(struct sk_buff *skb);
  3497. int netif_receive_skb_core(struct sk_buff *skb);
  3498. void netif_receive_skb_list_internal(struct list_head *head);
  3499. void netif_receive_skb_list(struct list_head *head);
  3500. gro_result_t napi_gro_receive(struct napi_struct *napi, struct sk_buff *skb);
  3501. void napi_gro_flush(struct napi_struct *napi, bool flush_old);
  3502. struct sk_buff *napi_get_frags(struct napi_struct *napi);
  3503. void napi_get_frags_check(struct napi_struct *napi);
  3504. gro_result_t napi_gro_frags(struct napi_struct *napi);
  3505. struct packet_offload *gro_find_receive_by_type(__be16 type);
  3506. struct packet_offload *gro_find_complete_by_type(__be16 type);
  3507. static inline void napi_free_frags(struct napi_struct *napi)
  3508. {
  3509. kfree_skb(napi->skb);
  3510. napi->skb = NULL;
  3511. }
  3512. bool netdev_is_rx_handler_busy(struct net_device *dev);
  3513. int netdev_rx_handler_register(struct net_device *dev,
  3514. rx_handler_func_t *rx_handler,
  3515. void *rx_handler_data);
  3516. void netdev_rx_handler_unregister(struct net_device *dev);
  3517. bool dev_valid_name(const char *name);
  3518. static inline bool is_socket_ioctl_cmd(unsigned int cmd)
  3519. {
  3520. return _IOC_TYPE(cmd) == SOCK_IOC_TYPE;
  3521. }
  3522. int get_user_ifreq(struct ifreq *ifr, void __user **ifrdata, void __user *arg);
  3523. int put_user_ifreq(struct ifreq *ifr, void __user *arg);
  3524. int dev_ioctl(struct net *net, unsigned int cmd, struct ifreq *ifr,
  3525. void __user *data, bool *need_copyout);
  3526. int dev_ifconf(struct net *net, struct ifconf __user *ifc);
  3527. int dev_ethtool(struct net *net, struct ifreq *ifr, void __user *userdata);
  3528. unsigned int dev_get_flags(const struct net_device *);
  3529. int __dev_change_flags(struct net_device *dev, unsigned int flags,
  3530. struct netlink_ext_ack *extack);
  3531. int dev_change_flags(struct net_device *dev, unsigned int flags,
  3532. struct netlink_ext_ack *extack);
  3533. void __dev_notify_flags(struct net_device *, unsigned int old_flags,
  3534. unsigned int gchanges);
  3535. int dev_set_alias(struct net_device *, const char *, size_t);
  3536. int dev_get_alias(const struct net_device *, char *, size_t);
  3537. int __dev_change_net_namespace(struct net_device *dev, struct net *net,
  3538. const char *pat, int new_ifindex);
  3539. static inline
  3540. int dev_change_net_namespace(struct net_device *dev, struct net *net,
  3541. const char *pat)
  3542. {
  3543. return __dev_change_net_namespace(dev, net, pat, 0);
  3544. }
  3545. int __dev_set_mtu(struct net_device *, int);
  3546. int dev_set_mtu(struct net_device *, int);
  3547. int dev_pre_changeaddr_notify(struct net_device *dev, const char *addr,
  3548. struct netlink_ext_ack *extack);
  3549. int dev_set_mac_address(struct net_device *dev, struct sockaddr *sa,
  3550. struct netlink_ext_ack *extack);
  3551. int dev_set_mac_address_user(struct net_device *dev, struct sockaddr *sa,
  3552. struct netlink_ext_ack *extack);
  3553. int dev_get_mac_address(struct sockaddr *sa, struct net *net, char *dev_name);
  3554. int dev_get_port_parent_id(struct net_device *dev,
  3555. struct netdev_phys_item_id *ppid, bool recurse);
  3556. bool netdev_port_same_parent_id(struct net_device *a, struct net_device *b);
  3557. struct sk_buff *validate_xmit_skb_list(struct sk_buff *skb, struct net_device *dev, bool *again);
  3558. struct sk_buff *dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev,
  3559. struct netdev_queue *txq, int *ret);
  3560. int bpf_xdp_link_attach(const union bpf_attr *attr, struct bpf_prog *prog);
  3561. u8 dev_xdp_prog_count(struct net_device *dev);
  3562. u32 dev_xdp_prog_id(struct net_device *dev, enum bpf_xdp_mode mode);
  3563. int __dev_forward_skb(struct net_device *dev, struct sk_buff *skb);
  3564. int dev_forward_skb(struct net_device *dev, struct sk_buff *skb);
  3565. int dev_forward_skb_nomtu(struct net_device *dev, struct sk_buff *skb);
  3566. bool is_skb_forwardable(const struct net_device *dev,
  3567. const struct sk_buff *skb);
  3568. static __always_inline bool __is_skb_forwardable(const struct net_device *dev,
  3569. const struct sk_buff *skb,
  3570. const bool check_mtu)
  3571. {
  3572. const u32 vlan_hdr_len = 4; /* VLAN_HLEN */
  3573. unsigned int len;
  3574. if (!(dev->flags & IFF_UP))
  3575. return false;
  3576. if (!check_mtu)
  3577. return true;
  3578. len = dev->mtu + dev->hard_header_len + vlan_hdr_len;
  3579. if (skb->len <= len)
  3580. return true;
  3581. /* if TSO is enabled, we don't care about the length as the packet
  3582. * could be forwarded without being segmented before
  3583. */
  3584. if (skb_is_gso(skb))
  3585. return true;
  3586. return false;
  3587. }
  3588. struct net_device_core_stats __percpu *netdev_core_stats_alloc(struct net_device *dev);
  3589. static inline struct net_device_core_stats __percpu *dev_core_stats(struct net_device *dev)
  3590. {
  3591. /* This READ_ONCE() pairs with the write in netdev_core_stats_alloc() */
  3592. struct net_device_core_stats __percpu *p = READ_ONCE(dev->core_stats);
  3593. if (likely(p))
  3594. return p;
  3595. return netdev_core_stats_alloc(dev);
  3596. }
  3597. #define DEV_CORE_STATS_INC(FIELD) \
  3598. static inline void dev_core_stats_##FIELD##_inc(struct net_device *dev) \
  3599. { \
  3600. struct net_device_core_stats __percpu *p; \
  3601. \
  3602. p = dev_core_stats(dev); \
  3603. if (p) \
  3604. this_cpu_inc(p->FIELD); \
  3605. }
  3606. DEV_CORE_STATS_INC(rx_dropped)
  3607. DEV_CORE_STATS_INC(tx_dropped)
  3608. DEV_CORE_STATS_INC(rx_nohandler)
  3609. DEV_CORE_STATS_INC(rx_otherhost_dropped)
  3610. static __always_inline int ____dev_forward_skb(struct net_device *dev,
  3611. struct sk_buff *skb,
  3612. const bool check_mtu)
  3613. {
  3614. if (skb_orphan_frags(skb, GFP_ATOMIC) ||
  3615. unlikely(!__is_skb_forwardable(dev, skb, check_mtu))) {
  3616. dev_core_stats_rx_dropped_inc(dev);
  3617. kfree_skb(skb);
  3618. return NET_RX_DROP;
  3619. }
  3620. skb_scrub_packet(skb, !net_eq(dev_net(dev), dev_net(skb->dev)));
  3621. skb->priority = 0;
  3622. return 0;
  3623. }
  3624. bool dev_nit_active(struct net_device *dev);
  3625. void dev_queue_xmit_nit(struct sk_buff *skb, struct net_device *dev);
  3626. static inline void __dev_put(struct net_device *dev)
  3627. {
  3628. if (dev) {
  3629. #ifdef CONFIG_PCPU_DEV_REFCNT
  3630. this_cpu_dec(*dev->pcpu_refcnt);
  3631. #else
  3632. refcount_dec(&dev->dev_refcnt);
  3633. #endif
  3634. }
  3635. }
  3636. static inline void __dev_hold(struct net_device *dev)
  3637. {
  3638. if (dev) {
  3639. #ifdef CONFIG_PCPU_DEV_REFCNT
  3640. this_cpu_inc(*dev->pcpu_refcnt);
  3641. #else
  3642. refcount_inc(&dev->dev_refcnt);
  3643. #endif
  3644. }
  3645. }
  3646. static inline void __netdev_tracker_alloc(struct net_device *dev,
  3647. netdevice_tracker *tracker,
  3648. gfp_t gfp)
  3649. {
  3650. #ifdef CONFIG_NET_DEV_REFCNT_TRACKER
  3651. ref_tracker_alloc(&dev->refcnt_tracker, tracker, gfp);
  3652. #endif
  3653. }
  3654. /* netdev_tracker_alloc() can upgrade a prior untracked reference
  3655. * taken by dev_get_by_name()/dev_get_by_index() to a tracked one.
  3656. */
  3657. static inline void netdev_tracker_alloc(struct net_device *dev,
  3658. netdevice_tracker *tracker, gfp_t gfp)
  3659. {
  3660. #ifdef CONFIG_NET_DEV_REFCNT_TRACKER
  3661. refcount_dec(&dev->refcnt_tracker.no_tracker);
  3662. __netdev_tracker_alloc(dev, tracker, gfp);
  3663. #endif
  3664. }
  3665. static inline void netdev_tracker_free(struct net_device *dev,
  3666. netdevice_tracker *tracker)
  3667. {
  3668. #ifdef CONFIG_NET_DEV_REFCNT_TRACKER
  3669. ref_tracker_free(&dev->refcnt_tracker, tracker);
  3670. #endif
  3671. }
  3672. static inline void netdev_hold(struct net_device *dev,
  3673. netdevice_tracker *tracker, gfp_t gfp)
  3674. {
  3675. if (dev) {
  3676. __dev_hold(dev);
  3677. __netdev_tracker_alloc(dev, tracker, gfp);
  3678. }
  3679. }
  3680. static inline void netdev_put(struct net_device *dev,
  3681. netdevice_tracker *tracker)
  3682. {
  3683. if (dev) {
  3684. netdev_tracker_free(dev, tracker);
  3685. __dev_put(dev);
  3686. }
  3687. }
  3688. /**
  3689. * dev_hold - get reference to device
  3690. * @dev: network device
  3691. *
  3692. * Hold reference to device to keep it from being freed.
  3693. * Try using netdev_hold() instead.
  3694. */
  3695. static inline void dev_hold(struct net_device *dev)
  3696. {
  3697. netdev_hold(dev, NULL, GFP_ATOMIC);
  3698. }
  3699. /**
  3700. * dev_put - release reference to device
  3701. * @dev: network device
  3702. *
  3703. * Release reference to device to allow it to be freed.
  3704. * Try using netdev_put() instead.
  3705. */
  3706. static inline void dev_put(struct net_device *dev)
  3707. {
  3708. netdev_put(dev, NULL);
  3709. }
  3710. static inline void netdev_ref_replace(struct net_device *odev,
  3711. struct net_device *ndev,
  3712. netdevice_tracker *tracker,
  3713. gfp_t gfp)
  3714. {
  3715. if (odev)
  3716. netdev_tracker_free(odev, tracker);
  3717. __dev_hold(ndev);
  3718. __dev_put(odev);
  3719. if (ndev)
  3720. __netdev_tracker_alloc(ndev, tracker, gfp);
  3721. }
  3722. /* Carrier loss detection, dial on demand. The functions netif_carrier_on
  3723. * and _off may be called from IRQ context, but it is caller
  3724. * who is responsible for serialization of these calls.
  3725. *
  3726. * The name carrier is inappropriate, these functions should really be
  3727. * called netif_lowerlayer_*() because they represent the state of any
  3728. * kind of lower layer not just hardware media.
  3729. */
  3730. void linkwatch_fire_event(struct net_device *dev);
  3731. /**
  3732. * netif_carrier_ok - test if carrier present
  3733. * @dev: network device
  3734. *
  3735. * Check if carrier is present on device
  3736. */
  3737. static inline bool netif_carrier_ok(const struct net_device *dev)
  3738. {
  3739. return !test_bit(__LINK_STATE_NOCARRIER, &dev->state);
  3740. }
  3741. unsigned long dev_trans_start(struct net_device *dev);
  3742. void __netdev_watchdog_up(struct net_device *dev);
  3743. void netif_carrier_on(struct net_device *dev);
  3744. void netif_carrier_off(struct net_device *dev);
  3745. void netif_carrier_event(struct net_device *dev);
  3746. /**
  3747. * netif_dormant_on - mark device as dormant.
  3748. * @dev: network device
  3749. *
  3750. * Mark device as dormant (as per RFC2863).
  3751. *
  3752. * The dormant state indicates that the relevant interface is not
  3753. * actually in a condition to pass packets (i.e., it is not 'up') but is
  3754. * in a "pending" state, waiting for some external event. For "on-
  3755. * demand" interfaces, this new state identifies the situation where the
  3756. * interface is waiting for events to place it in the up state.
  3757. */
  3758. static inline void netif_dormant_on(struct net_device *dev)
  3759. {
  3760. if (!test_and_set_bit(__LINK_STATE_DORMANT, &dev->state))
  3761. linkwatch_fire_event(dev);
  3762. }
  3763. /**
  3764. * netif_dormant_off - set device as not dormant.
  3765. * @dev: network device
  3766. *
  3767. * Device is not in dormant state.
  3768. */
  3769. static inline void netif_dormant_off(struct net_device *dev)
  3770. {
  3771. if (test_and_clear_bit(__LINK_STATE_DORMANT, &dev->state))
  3772. linkwatch_fire_event(dev);
  3773. }
  3774. /**
  3775. * netif_dormant - test if device is dormant
  3776. * @dev: network device
  3777. *
  3778. * Check if device is dormant.
  3779. */
  3780. static inline bool netif_dormant(const struct net_device *dev)
  3781. {
  3782. return test_bit(__LINK_STATE_DORMANT, &dev->state);
  3783. }
  3784. /**
  3785. * netif_testing_on - mark device as under test.
  3786. * @dev: network device
  3787. *
  3788. * Mark device as under test (as per RFC2863).
  3789. *
  3790. * The testing state indicates that some test(s) must be performed on
  3791. * the interface. After completion, of the test, the interface state
  3792. * will change to up, dormant, or down, as appropriate.
  3793. */
  3794. static inline void netif_testing_on(struct net_device *dev)
  3795. {
  3796. if (!test_and_set_bit(__LINK_STATE_TESTING, &dev->state))
  3797. linkwatch_fire_event(dev);
  3798. }
  3799. /**
  3800. * netif_testing_off - set device as not under test.
  3801. * @dev: network device
  3802. *
  3803. * Device is not in testing state.
  3804. */
  3805. static inline void netif_testing_off(struct net_device *dev)
  3806. {
  3807. if (test_and_clear_bit(__LINK_STATE_TESTING, &dev->state))
  3808. linkwatch_fire_event(dev);
  3809. }
  3810. /**
  3811. * netif_testing - test if device is under test
  3812. * @dev: network device
  3813. *
  3814. * Check if device is under test
  3815. */
  3816. static inline bool netif_testing(const struct net_device *dev)
  3817. {
  3818. return test_bit(__LINK_STATE_TESTING, &dev->state);
  3819. }
  3820. /**
  3821. * netif_oper_up - test if device is operational
  3822. * @dev: network device
  3823. *
  3824. * Check if carrier is operational
  3825. */
  3826. static inline bool netif_oper_up(const struct net_device *dev)
  3827. {
  3828. return (dev->operstate == IF_OPER_UP ||
  3829. dev->operstate == IF_OPER_UNKNOWN /* backward compat */);
  3830. }
  3831. /**
  3832. * netif_device_present - is device available or removed
  3833. * @dev: network device
  3834. *
  3835. * Check if device has not been removed from system.
  3836. */
  3837. static inline bool netif_device_present(const struct net_device *dev)
  3838. {
  3839. return test_bit(__LINK_STATE_PRESENT, &dev->state);
  3840. }
  3841. void netif_device_detach(struct net_device *dev);
  3842. void netif_device_attach(struct net_device *dev);
  3843. /*
  3844. * Network interface message level settings
  3845. */
  3846. enum {
  3847. NETIF_MSG_DRV_BIT,
  3848. NETIF_MSG_PROBE_BIT,
  3849. NETIF_MSG_LINK_BIT,
  3850. NETIF_MSG_TIMER_BIT,
  3851. NETIF_MSG_IFDOWN_BIT,
  3852. NETIF_MSG_IFUP_BIT,
  3853. NETIF_MSG_RX_ERR_BIT,
  3854. NETIF_MSG_TX_ERR_BIT,
  3855. NETIF_MSG_TX_QUEUED_BIT,
  3856. NETIF_MSG_INTR_BIT,
  3857. NETIF_MSG_TX_DONE_BIT,
  3858. NETIF_MSG_RX_STATUS_BIT,
  3859. NETIF_MSG_PKTDATA_BIT,
  3860. NETIF_MSG_HW_BIT,
  3861. NETIF_MSG_WOL_BIT,
  3862. /* When you add a new bit above, update netif_msg_class_names array
  3863. * in net/ethtool/common.c
  3864. */
  3865. NETIF_MSG_CLASS_COUNT,
  3866. };
  3867. /* Both ethtool_ops interface and internal driver implementation use u32 */
  3868. static_assert(NETIF_MSG_CLASS_COUNT <= 32);
  3869. #define __NETIF_MSG_BIT(bit) ((u32)1 << (bit))
  3870. #define __NETIF_MSG(name) __NETIF_MSG_BIT(NETIF_MSG_ ## name ## _BIT)
  3871. #define NETIF_MSG_DRV __NETIF_MSG(DRV)
  3872. #define NETIF_MSG_PROBE __NETIF_MSG(PROBE)
  3873. #define NETIF_MSG_LINK __NETIF_MSG(LINK)
  3874. #define NETIF_MSG_TIMER __NETIF_MSG(TIMER)
  3875. #define NETIF_MSG_IFDOWN __NETIF_MSG(IFDOWN)
  3876. #define NETIF_MSG_IFUP __NETIF_MSG(IFUP)
  3877. #define NETIF_MSG_RX_ERR __NETIF_MSG(RX_ERR)
  3878. #define NETIF_MSG_TX_ERR __NETIF_MSG(TX_ERR)
  3879. #define NETIF_MSG_TX_QUEUED __NETIF_MSG(TX_QUEUED)
  3880. #define NETIF_MSG_INTR __NETIF_MSG(INTR)
  3881. #define NETIF_MSG_TX_DONE __NETIF_MSG(TX_DONE)
  3882. #define NETIF_MSG_RX_STATUS __NETIF_MSG(RX_STATUS)
  3883. #define NETIF_MSG_PKTDATA __NETIF_MSG(PKTDATA)
  3884. #define NETIF_MSG_HW __NETIF_MSG(HW)
  3885. #define NETIF_MSG_WOL __NETIF_MSG(WOL)
  3886. #define netif_msg_drv(p) ((p)->msg_enable & NETIF_MSG_DRV)
  3887. #define netif_msg_probe(p) ((p)->msg_enable & NETIF_MSG_PROBE)
  3888. #define netif_msg_link(p) ((p)->msg_enable & NETIF_MSG_LINK)
  3889. #define netif_msg_timer(p) ((p)->msg_enable & NETIF_MSG_TIMER)
  3890. #define netif_msg_ifdown(p) ((p)->msg_enable & NETIF_MSG_IFDOWN)
  3891. #define netif_msg_ifup(p) ((p)->msg_enable & NETIF_MSG_IFUP)
  3892. #define netif_msg_rx_err(p) ((p)->msg_enable & NETIF_MSG_RX_ERR)
  3893. #define netif_msg_tx_err(p) ((p)->msg_enable & NETIF_MSG_TX_ERR)
  3894. #define netif_msg_tx_queued(p) ((p)->msg_enable & NETIF_MSG_TX_QUEUED)
  3895. #define netif_msg_intr(p) ((p)->msg_enable & NETIF_MSG_INTR)
  3896. #define netif_msg_tx_done(p) ((p)->msg_enable & NETIF_MSG_TX_DONE)
  3897. #define netif_msg_rx_status(p) ((p)->msg_enable & NETIF_MSG_RX_STATUS)
  3898. #define netif_msg_pktdata(p) ((p)->msg_enable & NETIF_MSG_PKTDATA)
  3899. #define netif_msg_hw(p) ((p)->msg_enable & NETIF_MSG_HW)
  3900. #define netif_msg_wol(p) ((p)->msg_enable & NETIF_MSG_WOL)
  3901. static inline u32 netif_msg_init(int debug_value, int default_msg_enable_bits)
  3902. {
  3903. /* use default */
  3904. if (debug_value < 0 || debug_value >= (sizeof(u32) * 8))
  3905. return default_msg_enable_bits;
  3906. if (debug_value == 0) /* no output */
  3907. return 0;
  3908. /* set low N bits */
  3909. return (1U << debug_value) - 1;
  3910. }
  3911. static inline void __netif_tx_lock(struct netdev_queue *txq, int cpu)
  3912. {
  3913. spin_lock(&txq->_xmit_lock);
  3914. /* Pairs with READ_ONCE() in __dev_queue_xmit() */
  3915. WRITE_ONCE(txq->xmit_lock_owner, cpu);
  3916. }
  3917. static inline bool __netif_tx_acquire(struct netdev_queue *txq)
  3918. {
  3919. __acquire(&txq->_xmit_lock);
  3920. return true;
  3921. }
  3922. static inline void __netif_tx_release(struct netdev_queue *txq)
  3923. {
  3924. __release(&txq->_xmit_lock);
  3925. }
  3926. static inline void __netif_tx_lock_bh(struct netdev_queue *txq)
  3927. {
  3928. spin_lock_bh(&txq->_xmit_lock);
  3929. /* Pairs with READ_ONCE() in __dev_queue_xmit() */
  3930. WRITE_ONCE(txq->xmit_lock_owner, smp_processor_id());
  3931. }
  3932. static inline bool __netif_tx_trylock(struct netdev_queue *txq)
  3933. {
  3934. bool ok = spin_trylock(&txq->_xmit_lock);
  3935. if (likely(ok)) {
  3936. /* Pairs with READ_ONCE() in __dev_queue_xmit() */
  3937. WRITE_ONCE(txq->xmit_lock_owner, smp_processor_id());
  3938. }
  3939. return ok;
  3940. }
  3941. static inline void __netif_tx_unlock(struct netdev_queue *txq)
  3942. {
  3943. /* Pairs with READ_ONCE() in __dev_queue_xmit() */
  3944. WRITE_ONCE(txq->xmit_lock_owner, -1);
  3945. spin_unlock(&txq->_xmit_lock);
  3946. }
  3947. static inline void __netif_tx_unlock_bh(struct netdev_queue *txq)
  3948. {
  3949. /* Pairs with READ_ONCE() in __dev_queue_xmit() */
  3950. WRITE_ONCE(txq->xmit_lock_owner, -1);
  3951. spin_unlock_bh(&txq->_xmit_lock);
  3952. }
  3953. /*
  3954. * txq->trans_start can be read locklessly from dev_watchdog()
  3955. */
  3956. static inline void txq_trans_update(struct netdev_queue *txq)
  3957. {
  3958. if (txq->xmit_lock_owner != -1)
  3959. WRITE_ONCE(txq->trans_start, jiffies);
  3960. }
  3961. static inline void txq_trans_cond_update(struct netdev_queue *txq)
  3962. {
  3963. unsigned long now = jiffies;
  3964. if (READ_ONCE(txq->trans_start) != now)
  3965. WRITE_ONCE(txq->trans_start, now);
  3966. }
  3967. /* legacy drivers only, netdev_start_xmit() sets txq->trans_start */
  3968. static inline void netif_trans_update(struct net_device *dev)
  3969. {
  3970. struct netdev_queue *txq = netdev_get_tx_queue(dev, 0);
  3971. txq_trans_cond_update(txq);
  3972. }
  3973. /**
  3974. * netif_tx_lock - grab network device transmit lock
  3975. * @dev: network device
  3976. *
  3977. * Get network device transmit lock
  3978. */
  3979. void netif_tx_lock(struct net_device *dev);
  3980. static inline void netif_tx_lock_bh(struct net_device *dev)
  3981. {
  3982. local_bh_disable();
  3983. netif_tx_lock(dev);
  3984. }
  3985. void netif_tx_unlock(struct net_device *dev);
  3986. static inline void netif_tx_unlock_bh(struct net_device *dev)
  3987. {
  3988. netif_tx_unlock(dev);
  3989. local_bh_enable();
  3990. }
  3991. #define HARD_TX_LOCK(dev, txq, cpu) { \
  3992. if ((dev->features & NETIF_F_LLTX) == 0) { \
  3993. __netif_tx_lock(txq, cpu); \
  3994. } else { \
  3995. __netif_tx_acquire(txq); \
  3996. } \
  3997. }
  3998. #define HARD_TX_TRYLOCK(dev, txq) \
  3999. (((dev->features & NETIF_F_LLTX) == 0) ? \
  4000. __netif_tx_trylock(txq) : \
  4001. __netif_tx_acquire(txq))
  4002. #define HARD_TX_UNLOCK(dev, txq) { \
  4003. if ((dev->features & NETIF_F_LLTX) == 0) { \
  4004. __netif_tx_unlock(txq); \
  4005. } else { \
  4006. __netif_tx_release(txq); \
  4007. } \
  4008. }
  4009. static inline void netif_tx_disable(struct net_device *dev)
  4010. {
  4011. unsigned int i;
  4012. int cpu;
  4013. local_bh_disable();
  4014. cpu = smp_processor_id();
  4015. spin_lock(&dev->tx_global_lock);
  4016. for (i = 0; i < dev->num_tx_queues; i++) {
  4017. struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
  4018. __netif_tx_lock(txq, cpu);
  4019. netif_tx_stop_queue(txq);
  4020. __netif_tx_unlock(txq);
  4021. }
  4022. spin_unlock(&dev->tx_global_lock);
  4023. local_bh_enable();
  4024. }
  4025. static inline void netif_addr_lock(struct net_device *dev)
  4026. {
  4027. unsigned char nest_level = 0;
  4028. #ifdef CONFIG_LOCKDEP
  4029. nest_level = dev->nested_level;
  4030. #endif
  4031. spin_lock_nested(&dev->addr_list_lock, nest_level);
  4032. }
  4033. static inline void netif_addr_lock_bh(struct net_device *dev)
  4034. {
  4035. unsigned char nest_level = 0;
  4036. #ifdef CONFIG_LOCKDEP
  4037. nest_level = dev->nested_level;
  4038. #endif
  4039. local_bh_disable();
  4040. spin_lock_nested(&dev->addr_list_lock, nest_level);
  4041. }
  4042. static inline void netif_addr_unlock(struct net_device *dev)
  4043. {
  4044. spin_unlock(&dev->addr_list_lock);
  4045. }
  4046. static inline void netif_addr_unlock_bh(struct net_device *dev)
  4047. {
  4048. spin_unlock_bh(&dev->addr_list_lock);
  4049. }
  4050. /*
  4051. * dev_addrs walker. Should be used only for read access. Call with
  4052. * rcu_read_lock held.
  4053. */
  4054. #define for_each_dev_addr(dev, ha) \
  4055. list_for_each_entry_rcu(ha, &dev->dev_addrs.list, list)
  4056. /* These functions live elsewhere (drivers/net/net_init.c, but related) */
  4057. void ether_setup(struct net_device *dev);
  4058. /* Support for loadable net-drivers */
  4059. struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name,
  4060. unsigned char name_assign_type,
  4061. void (*setup)(struct net_device *),
  4062. unsigned int txqs, unsigned int rxqs);
  4063. #define alloc_netdev(sizeof_priv, name, name_assign_type, setup) \
  4064. alloc_netdev_mqs(sizeof_priv, name, name_assign_type, setup, 1, 1)
  4065. #define alloc_netdev_mq(sizeof_priv, name, name_assign_type, setup, count) \
  4066. alloc_netdev_mqs(sizeof_priv, name, name_assign_type, setup, count, \
  4067. count)
  4068. int register_netdev(struct net_device *dev);
  4069. void unregister_netdev(struct net_device *dev);
  4070. int devm_register_netdev(struct device *dev, struct net_device *ndev);
  4071. /* General hardware address lists handling functions */
  4072. int __hw_addr_sync(struct netdev_hw_addr_list *to_list,
  4073. struct netdev_hw_addr_list *from_list, int addr_len);
  4074. void __hw_addr_unsync(struct netdev_hw_addr_list *to_list,
  4075. struct netdev_hw_addr_list *from_list, int addr_len);
  4076. int __hw_addr_sync_dev(struct netdev_hw_addr_list *list,
  4077. struct net_device *dev,
  4078. int (*sync)(struct net_device *, const unsigned char *),
  4079. int (*unsync)(struct net_device *,
  4080. const unsigned char *));
  4081. int __hw_addr_ref_sync_dev(struct netdev_hw_addr_list *list,
  4082. struct net_device *dev,
  4083. int (*sync)(struct net_device *,
  4084. const unsigned char *, int),
  4085. int (*unsync)(struct net_device *,
  4086. const unsigned char *, int));
  4087. void __hw_addr_ref_unsync_dev(struct netdev_hw_addr_list *list,
  4088. struct net_device *dev,
  4089. int (*unsync)(struct net_device *,
  4090. const unsigned char *, int));
  4091. void __hw_addr_unsync_dev(struct netdev_hw_addr_list *list,
  4092. struct net_device *dev,
  4093. int (*unsync)(struct net_device *,
  4094. const unsigned char *));
  4095. void __hw_addr_init(struct netdev_hw_addr_list *list);
  4096. /* Functions used for device addresses handling */
  4097. void dev_addr_mod(struct net_device *dev, unsigned int offset,
  4098. const void *addr, size_t len);
  4099. static inline void
  4100. __dev_addr_set(struct net_device *dev, const void *addr, size_t len)
  4101. {
  4102. dev_addr_mod(dev, 0, addr, len);
  4103. }
  4104. static inline void dev_addr_set(struct net_device *dev, const u8 *addr)
  4105. {
  4106. __dev_addr_set(dev, addr, dev->addr_len);
  4107. }
  4108. int dev_addr_add(struct net_device *dev, const unsigned char *addr,
  4109. unsigned char addr_type);
  4110. int dev_addr_del(struct net_device *dev, const unsigned char *addr,
  4111. unsigned char addr_type);
  4112. /* Functions used for unicast addresses handling */
  4113. int dev_uc_add(struct net_device *dev, const unsigned char *addr);
  4114. int dev_uc_add_excl(struct net_device *dev, const unsigned char *addr);
  4115. int dev_uc_del(struct net_device *dev, const unsigned char *addr);
  4116. int dev_uc_sync(struct net_device *to, struct net_device *from);
  4117. int dev_uc_sync_multiple(struct net_device *to, struct net_device *from);
  4118. void dev_uc_unsync(struct net_device *to, struct net_device *from);
  4119. void dev_uc_flush(struct net_device *dev);
  4120. void dev_uc_init(struct net_device *dev);
  4121. /**
  4122. * __dev_uc_sync - Synchonize device's unicast list
  4123. * @dev: device to sync
  4124. * @sync: function to call if address should be added
  4125. * @unsync: function to call if address should be removed
  4126. *
  4127. * Add newly added addresses to the interface, and release
  4128. * addresses that have been deleted.
  4129. */
  4130. static inline int __dev_uc_sync(struct net_device *dev,
  4131. int (*sync)(struct net_device *,
  4132. const unsigned char *),
  4133. int (*unsync)(struct net_device *,
  4134. const unsigned char *))
  4135. {
  4136. return __hw_addr_sync_dev(&dev->uc, dev, sync, unsync);
  4137. }
  4138. /**
  4139. * __dev_uc_unsync - Remove synchronized addresses from device
  4140. * @dev: device to sync
  4141. * @unsync: function to call if address should be removed
  4142. *
  4143. * Remove all addresses that were added to the device by dev_uc_sync().
  4144. */
  4145. static inline void __dev_uc_unsync(struct net_device *dev,
  4146. int (*unsync)(struct net_device *,
  4147. const unsigned char *))
  4148. {
  4149. __hw_addr_unsync_dev(&dev->uc, dev, unsync);
  4150. }
  4151. /* Functions used for multicast addresses handling */
  4152. int dev_mc_add(struct net_device *dev, const unsigned char *addr);
  4153. int dev_mc_add_global(struct net_device *dev, const unsigned char *addr);
  4154. int dev_mc_add_excl(struct net_device *dev, const unsigned char *addr);
  4155. int dev_mc_del(struct net_device *dev, const unsigned char *addr);
  4156. int dev_mc_del_global(struct net_device *dev, const unsigned char *addr);
  4157. int dev_mc_sync(struct net_device *to, struct net_device *from);
  4158. int dev_mc_sync_multiple(struct net_device *to, struct net_device *from);
  4159. void dev_mc_unsync(struct net_device *to, struct net_device *from);
  4160. void dev_mc_flush(struct net_device *dev);
  4161. void dev_mc_init(struct net_device *dev);
  4162. /**
  4163. * __dev_mc_sync - Synchonize device's multicast list
  4164. * @dev: device to sync
  4165. * @sync: function to call if address should be added
  4166. * @unsync: function to call if address should be removed
  4167. *
  4168. * Add newly added addresses to the interface, and release
  4169. * addresses that have been deleted.
  4170. */
  4171. static inline int __dev_mc_sync(struct net_device *dev,
  4172. int (*sync)(struct net_device *,
  4173. const unsigned char *),
  4174. int (*unsync)(struct net_device *,
  4175. const unsigned char *))
  4176. {
  4177. return __hw_addr_sync_dev(&dev->mc, dev, sync, unsync);
  4178. }
  4179. /**
  4180. * __dev_mc_unsync - Remove synchronized addresses from device
  4181. * @dev: device to sync
  4182. * @unsync: function to call if address should be removed
  4183. *
  4184. * Remove all addresses that were added to the device by dev_mc_sync().
  4185. */
  4186. static inline void __dev_mc_unsync(struct net_device *dev,
  4187. int (*unsync)(struct net_device *,
  4188. const unsigned char *))
  4189. {
  4190. __hw_addr_unsync_dev(&dev->mc, dev, unsync);
  4191. }
  4192. /* Functions used for secondary unicast and multicast support */
  4193. void dev_set_rx_mode(struct net_device *dev);
  4194. int dev_set_promiscuity(struct net_device *dev, int inc);
  4195. int dev_set_allmulti(struct net_device *dev, int inc);
  4196. void netdev_state_change(struct net_device *dev);
  4197. void __netdev_notify_peers(struct net_device *dev);
  4198. void netdev_notify_peers(struct net_device *dev);
  4199. void netdev_features_change(struct net_device *dev);
  4200. /* Load a device via the kmod */
  4201. void dev_load(struct net *net, const char *name);
  4202. struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
  4203. struct rtnl_link_stats64 *storage);
  4204. void netdev_stats_to_stats64(struct rtnl_link_stats64 *stats64,
  4205. const struct net_device_stats *netdev_stats);
  4206. void dev_fetch_sw_netstats(struct rtnl_link_stats64 *s,
  4207. const struct pcpu_sw_netstats __percpu *netstats);
  4208. void dev_get_tstats64(struct net_device *dev, struct rtnl_link_stats64 *s);
  4209. extern int netdev_max_backlog;
  4210. extern int dev_rx_weight;
  4211. extern int dev_tx_weight;
  4212. extern int gro_normal_batch;
  4213. enum {
  4214. NESTED_SYNC_IMM_BIT,
  4215. NESTED_SYNC_TODO_BIT,
  4216. };
  4217. #define __NESTED_SYNC_BIT(bit) ((u32)1 << (bit))
  4218. #define __NESTED_SYNC(name) __NESTED_SYNC_BIT(NESTED_SYNC_ ## name ## _BIT)
  4219. #define NESTED_SYNC_IMM __NESTED_SYNC(IMM)
  4220. #define NESTED_SYNC_TODO __NESTED_SYNC(TODO)
  4221. struct netdev_nested_priv {
  4222. unsigned char flags;
  4223. void *data;
  4224. };
  4225. bool netdev_has_upper_dev(struct net_device *dev, struct net_device *upper_dev);
  4226. struct net_device *netdev_upper_get_next_dev_rcu(struct net_device *dev,
  4227. struct list_head **iter);
  4228. /* iterate through upper list, must be called under RCU read lock */
  4229. #define netdev_for_each_upper_dev_rcu(dev, updev, iter) \
  4230. for (iter = &(dev)->adj_list.upper, \
  4231. updev = netdev_upper_get_next_dev_rcu(dev, &(iter)); \
  4232. updev; \
  4233. updev = netdev_upper_get_next_dev_rcu(dev, &(iter)))
  4234. int netdev_walk_all_upper_dev_rcu(struct net_device *dev,
  4235. int (*fn)(struct net_device *upper_dev,
  4236. struct netdev_nested_priv *priv),
  4237. struct netdev_nested_priv *priv);
  4238. bool netdev_has_upper_dev_all_rcu(struct net_device *dev,
  4239. struct net_device *upper_dev);
  4240. bool netdev_has_any_upper_dev(struct net_device *dev);
  4241. void *netdev_lower_get_next_private(struct net_device *dev,
  4242. struct list_head **iter);
  4243. void *netdev_lower_get_next_private_rcu(struct net_device *dev,
  4244. struct list_head **iter);
  4245. #define netdev_for_each_lower_private(dev, priv, iter) \
  4246. for (iter = (dev)->adj_list.lower.next, \
  4247. priv = netdev_lower_get_next_private(dev, &(iter)); \
  4248. priv; \
  4249. priv = netdev_lower_get_next_private(dev, &(iter)))
  4250. #define netdev_for_each_lower_private_rcu(dev, priv, iter) \
  4251. for (iter = &(dev)->adj_list.lower, \
  4252. priv = netdev_lower_get_next_private_rcu(dev, &(iter)); \
  4253. priv; \
  4254. priv = netdev_lower_get_next_private_rcu(dev, &(iter)))
  4255. void *netdev_lower_get_next(struct net_device *dev,
  4256. struct list_head **iter);
  4257. #define netdev_for_each_lower_dev(dev, ldev, iter) \
  4258. for (iter = (dev)->adj_list.lower.next, \
  4259. ldev = netdev_lower_get_next(dev, &(iter)); \
  4260. ldev; \
  4261. ldev = netdev_lower_get_next(dev, &(iter)))
  4262. struct net_device *netdev_next_lower_dev_rcu(struct net_device *dev,
  4263. struct list_head **iter);
  4264. int netdev_walk_all_lower_dev(struct net_device *dev,
  4265. int (*fn)(struct net_device *lower_dev,
  4266. struct netdev_nested_priv *priv),
  4267. struct netdev_nested_priv *priv);
  4268. int netdev_walk_all_lower_dev_rcu(struct net_device *dev,
  4269. int (*fn)(struct net_device *lower_dev,
  4270. struct netdev_nested_priv *priv),
  4271. struct netdev_nested_priv *priv);
  4272. void *netdev_adjacent_get_private(struct list_head *adj_list);
  4273. void *netdev_lower_get_first_private_rcu(struct net_device *dev);
  4274. struct net_device *netdev_master_upper_dev_get(struct net_device *dev);
  4275. struct net_device *netdev_master_upper_dev_get_rcu(struct net_device *dev);
  4276. int netdev_upper_dev_link(struct net_device *dev, struct net_device *upper_dev,
  4277. struct netlink_ext_ack *extack);
  4278. int netdev_master_upper_dev_link(struct net_device *dev,
  4279. struct net_device *upper_dev,
  4280. void *upper_priv, void *upper_info,
  4281. struct netlink_ext_ack *extack);
  4282. void netdev_upper_dev_unlink(struct net_device *dev,
  4283. struct net_device *upper_dev);
  4284. int netdev_adjacent_change_prepare(struct net_device *old_dev,
  4285. struct net_device *new_dev,
  4286. struct net_device *dev,
  4287. struct netlink_ext_ack *extack);
  4288. void netdev_adjacent_change_commit(struct net_device *old_dev,
  4289. struct net_device *new_dev,
  4290. struct net_device *dev);
  4291. void netdev_adjacent_change_abort(struct net_device *old_dev,
  4292. struct net_device *new_dev,
  4293. struct net_device *dev);
  4294. void netdev_adjacent_rename_links(struct net_device *dev, char *oldname);
  4295. void *netdev_lower_dev_get_private(struct net_device *dev,
  4296. struct net_device *lower_dev);
  4297. void netdev_lower_state_changed(struct net_device *lower_dev,
  4298. void *lower_state_info);
  4299. /* RSS keys are 40 or 52 bytes long */
  4300. #define NETDEV_RSS_KEY_LEN 52
  4301. extern u8 netdev_rss_key[NETDEV_RSS_KEY_LEN] __read_mostly;
  4302. void netdev_rss_key_fill(void *buffer, size_t len);
  4303. int skb_checksum_help(struct sk_buff *skb);
  4304. int skb_crc32c_csum_help(struct sk_buff *skb);
  4305. int skb_csum_hwoffload_help(struct sk_buff *skb,
  4306. const netdev_features_t features);
  4307. struct sk_buff *__skb_gso_segment(struct sk_buff *skb,
  4308. netdev_features_t features, bool tx_path);
  4309. struct sk_buff *skb_eth_gso_segment(struct sk_buff *skb,
  4310. netdev_features_t features, __be16 type);
  4311. struct sk_buff *skb_mac_gso_segment(struct sk_buff *skb,
  4312. netdev_features_t features);
  4313. struct netdev_bonding_info {
  4314. ifslave slave;
  4315. ifbond master;
  4316. };
  4317. struct netdev_notifier_bonding_info {
  4318. struct netdev_notifier_info info; /* must be first */
  4319. struct netdev_bonding_info bonding_info;
  4320. };
  4321. void netdev_bonding_info_change(struct net_device *dev,
  4322. struct netdev_bonding_info *bonding_info);
  4323. #if IS_ENABLED(CONFIG_ETHTOOL_NETLINK)
  4324. void ethtool_notify(struct net_device *dev, unsigned int cmd, const void *data);
  4325. #else
  4326. static inline void ethtool_notify(struct net_device *dev, unsigned int cmd,
  4327. const void *data)
  4328. {
  4329. }
  4330. #endif
  4331. static inline
  4332. struct sk_buff *skb_gso_segment(struct sk_buff *skb, netdev_features_t features)
  4333. {
  4334. return __skb_gso_segment(skb, features, true);
  4335. }
  4336. __be16 skb_network_protocol(struct sk_buff *skb, int *depth);
  4337. static inline bool can_checksum_protocol(netdev_features_t features,
  4338. __be16 protocol)
  4339. {
  4340. if (protocol == htons(ETH_P_FCOE))
  4341. return !!(features & NETIF_F_FCOE_CRC);
  4342. /* Assume this is an IP checksum (not SCTP CRC) */
  4343. if (features & NETIF_F_HW_CSUM) {
  4344. /* Can checksum everything */
  4345. return true;
  4346. }
  4347. switch (protocol) {
  4348. case htons(ETH_P_IP):
  4349. return !!(features & NETIF_F_IP_CSUM);
  4350. case htons(ETH_P_IPV6):
  4351. return !!(features & NETIF_F_IPV6_CSUM);
  4352. default:
  4353. return false;
  4354. }
  4355. }
  4356. #ifdef CONFIG_BUG
  4357. void netdev_rx_csum_fault(struct net_device *dev, struct sk_buff *skb);
  4358. #else
  4359. static inline void netdev_rx_csum_fault(struct net_device *dev,
  4360. struct sk_buff *skb)
  4361. {
  4362. }
  4363. #endif
  4364. /* rx skb timestamps */
  4365. void net_enable_timestamp(void);
  4366. void net_disable_timestamp(void);
  4367. static inline ktime_t netdev_get_tstamp(struct net_device *dev,
  4368. const struct skb_shared_hwtstamps *hwtstamps,
  4369. bool cycles)
  4370. {
  4371. const struct net_device_ops *ops = dev->netdev_ops;
  4372. if (ops->ndo_get_tstamp)
  4373. return ops->ndo_get_tstamp(dev, hwtstamps, cycles);
  4374. return hwtstamps->hwtstamp;
  4375. }
  4376. static inline netdev_tx_t __netdev_start_xmit(const struct net_device_ops *ops,
  4377. struct sk_buff *skb, struct net_device *dev,
  4378. bool more)
  4379. {
  4380. __this_cpu_write(softnet_data.xmit.more, more);
  4381. return ops->ndo_start_xmit(skb, dev);
  4382. }
  4383. static inline bool netdev_xmit_more(void)
  4384. {
  4385. return __this_cpu_read(softnet_data.xmit.more);
  4386. }
  4387. static inline netdev_tx_t netdev_start_xmit(struct sk_buff *skb, struct net_device *dev,
  4388. struct netdev_queue *txq, bool more)
  4389. {
  4390. const struct net_device_ops *ops = dev->netdev_ops;
  4391. netdev_tx_t rc;
  4392. rc = __netdev_start_xmit(ops, skb, dev, more);
  4393. if (rc == NETDEV_TX_OK)
  4394. txq_trans_update(txq);
  4395. return rc;
  4396. }
  4397. int netdev_class_create_file_ns(const struct class_attribute *class_attr,
  4398. const void *ns);
  4399. void netdev_class_remove_file_ns(const struct class_attribute *class_attr,
  4400. const void *ns);
  4401. extern const struct kobj_ns_type_operations net_ns_type_operations;
  4402. const char *netdev_drivername(const struct net_device *dev);
  4403. static inline netdev_features_t netdev_intersect_features(netdev_features_t f1,
  4404. netdev_features_t f2)
  4405. {
  4406. if ((f1 ^ f2) & NETIF_F_HW_CSUM) {
  4407. if (f1 & NETIF_F_HW_CSUM)
  4408. f1 |= (NETIF_F_IP_CSUM|NETIF_F_IPV6_CSUM);
  4409. else
  4410. f2 |= (NETIF_F_IP_CSUM|NETIF_F_IPV6_CSUM);
  4411. }
  4412. return f1 & f2;
  4413. }
  4414. static inline netdev_features_t netdev_get_wanted_features(
  4415. struct net_device *dev)
  4416. {
  4417. return (dev->features & ~dev->hw_features) | dev->wanted_features;
  4418. }
  4419. netdev_features_t netdev_increment_features(netdev_features_t all,
  4420. netdev_features_t one, netdev_features_t mask);
  4421. /* Allow TSO being used on stacked device :
  4422. * Performing the GSO segmentation before last device
  4423. * is a performance improvement.
  4424. */
  4425. static inline netdev_features_t netdev_add_tso_features(netdev_features_t features,
  4426. netdev_features_t mask)
  4427. {
  4428. return netdev_increment_features(features, NETIF_F_ALL_TSO, mask);
  4429. }
  4430. int __netdev_update_features(struct net_device *dev);
  4431. void netdev_update_features(struct net_device *dev);
  4432. void netdev_change_features(struct net_device *dev);
  4433. void netif_stacked_transfer_operstate(const struct net_device *rootdev,
  4434. struct net_device *dev);
  4435. netdev_features_t passthru_features_check(struct sk_buff *skb,
  4436. struct net_device *dev,
  4437. netdev_features_t features);
  4438. netdev_features_t netif_skb_features(struct sk_buff *skb);
  4439. static inline bool net_gso_ok(netdev_features_t features, int gso_type)
  4440. {
  4441. netdev_features_t feature = (netdev_features_t)gso_type << NETIF_F_GSO_SHIFT;
  4442. /* check flags correspondence */
  4443. BUILD_BUG_ON(SKB_GSO_TCPV4 != (NETIF_F_TSO >> NETIF_F_GSO_SHIFT));
  4444. BUILD_BUG_ON(SKB_GSO_DODGY != (NETIF_F_GSO_ROBUST >> NETIF_F_GSO_SHIFT));
  4445. BUILD_BUG_ON(SKB_GSO_TCP_ECN != (NETIF_F_TSO_ECN >> NETIF_F_GSO_SHIFT));
  4446. BUILD_BUG_ON(SKB_GSO_TCP_FIXEDID != (NETIF_F_TSO_MANGLEID >> NETIF_F_GSO_SHIFT));
  4447. BUILD_BUG_ON(SKB_GSO_TCPV6 != (NETIF_F_TSO6 >> NETIF_F_GSO_SHIFT));
  4448. BUILD_BUG_ON(SKB_GSO_FCOE != (NETIF_F_FSO >> NETIF_F_GSO_SHIFT));
  4449. BUILD_BUG_ON(SKB_GSO_GRE != (NETIF_F_GSO_GRE >> NETIF_F_GSO_SHIFT));
  4450. BUILD_BUG_ON(SKB_GSO_GRE_CSUM != (NETIF_F_GSO_GRE_CSUM >> NETIF_F_GSO_SHIFT));
  4451. BUILD_BUG_ON(SKB_GSO_IPXIP4 != (NETIF_F_GSO_IPXIP4 >> NETIF_F_GSO_SHIFT));
  4452. BUILD_BUG_ON(SKB_GSO_IPXIP6 != (NETIF_F_GSO_IPXIP6 >> NETIF_F_GSO_SHIFT));
  4453. BUILD_BUG_ON(SKB_GSO_UDP_TUNNEL != (NETIF_F_GSO_UDP_TUNNEL >> NETIF_F_GSO_SHIFT));
  4454. BUILD_BUG_ON(SKB_GSO_UDP_TUNNEL_CSUM != (NETIF_F_GSO_UDP_TUNNEL_CSUM >> NETIF_F_GSO_SHIFT));
  4455. BUILD_BUG_ON(SKB_GSO_PARTIAL != (NETIF_F_GSO_PARTIAL >> NETIF_F_GSO_SHIFT));
  4456. BUILD_BUG_ON(SKB_GSO_TUNNEL_REMCSUM != (NETIF_F_GSO_TUNNEL_REMCSUM >> NETIF_F_GSO_SHIFT));
  4457. BUILD_BUG_ON(SKB_GSO_SCTP != (NETIF_F_GSO_SCTP >> NETIF_F_GSO_SHIFT));
  4458. BUILD_BUG_ON(SKB_GSO_ESP != (NETIF_F_GSO_ESP >> NETIF_F_GSO_SHIFT));
  4459. BUILD_BUG_ON(SKB_GSO_UDP != (NETIF_F_GSO_UDP >> NETIF_F_GSO_SHIFT));
  4460. BUILD_BUG_ON(SKB_GSO_UDP_L4 != (NETIF_F_GSO_UDP_L4 >> NETIF_F_GSO_SHIFT));
  4461. BUILD_BUG_ON(SKB_GSO_FRAGLIST != (NETIF_F_GSO_FRAGLIST >> NETIF_F_GSO_SHIFT));
  4462. return (features & feature) == feature;
  4463. }
  4464. static inline bool skb_gso_ok(struct sk_buff *skb, netdev_features_t features)
  4465. {
  4466. return net_gso_ok(features, skb_shinfo(skb)->gso_type) &&
  4467. (!skb_has_frag_list(skb) || (features & NETIF_F_FRAGLIST));
  4468. }
  4469. static inline bool netif_needs_gso(struct sk_buff *skb,
  4470. netdev_features_t features)
  4471. {
  4472. return skb_is_gso(skb) && (!skb_gso_ok(skb, features) ||
  4473. unlikely((skb->ip_summed != CHECKSUM_PARTIAL) &&
  4474. (skb->ip_summed != CHECKSUM_UNNECESSARY)));
  4475. }
  4476. void netif_set_tso_max_size(struct net_device *dev, unsigned int size);
  4477. void netif_set_tso_max_segs(struct net_device *dev, unsigned int segs);
  4478. void netif_inherit_tso_max(struct net_device *to,
  4479. const struct net_device *from);
  4480. static inline void skb_gso_error_unwind(struct sk_buff *skb, __be16 protocol,
  4481. int pulled_hlen, u16 mac_offset,
  4482. int mac_len)
  4483. {
  4484. skb->protocol = protocol;
  4485. skb->encapsulation = 1;
  4486. skb_push(skb, pulled_hlen);
  4487. skb_reset_transport_header(skb);
  4488. skb->mac_header = mac_offset;
  4489. skb->network_header = skb->mac_header + mac_len;
  4490. skb->mac_len = mac_len;
  4491. }
  4492. static inline bool netif_is_macsec(const struct net_device *dev)
  4493. {
  4494. return dev->priv_flags & IFF_MACSEC;
  4495. }
  4496. static inline bool netif_is_macvlan(const struct net_device *dev)
  4497. {
  4498. return dev->priv_flags & IFF_MACVLAN;
  4499. }
  4500. static inline bool netif_is_macvlan_port(const struct net_device *dev)
  4501. {
  4502. return dev->priv_flags & IFF_MACVLAN_PORT;
  4503. }
  4504. static inline bool netif_is_bond_master(const struct net_device *dev)
  4505. {
  4506. return dev->flags & IFF_MASTER && dev->priv_flags & IFF_BONDING;
  4507. }
  4508. static inline bool netif_is_bond_slave(const struct net_device *dev)
  4509. {
  4510. return dev->flags & IFF_SLAVE && dev->priv_flags & IFF_BONDING;
  4511. }
  4512. static inline bool netif_supports_nofcs(struct net_device *dev)
  4513. {
  4514. return dev->priv_flags & IFF_SUPP_NOFCS;
  4515. }
  4516. static inline bool netif_has_l3_rx_handler(const struct net_device *dev)
  4517. {
  4518. return dev->priv_flags & IFF_L3MDEV_RX_HANDLER;
  4519. }
  4520. static inline bool netif_is_l3_master(const struct net_device *dev)
  4521. {
  4522. return dev->priv_flags & IFF_L3MDEV_MASTER;
  4523. }
  4524. static inline bool netif_is_l3_slave(const struct net_device *dev)
  4525. {
  4526. return dev->priv_flags & IFF_L3MDEV_SLAVE;
  4527. }
  4528. static inline int dev_sdif(const struct net_device *dev)
  4529. {
  4530. #ifdef CONFIG_NET_L3_MASTER_DEV
  4531. if (netif_is_l3_slave(dev))
  4532. return dev->ifindex;
  4533. #endif
  4534. return 0;
  4535. }
  4536. static inline bool netif_is_bridge_master(const struct net_device *dev)
  4537. {
  4538. return dev->priv_flags & IFF_EBRIDGE;
  4539. }
  4540. static inline bool netif_is_bridge_port(const struct net_device *dev)
  4541. {
  4542. return dev->priv_flags & IFF_BRIDGE_PORT;
  4543. }
  4544. static inline bool netif_is_ovs_master(const struct net_device *dev)
  4545. {
  4546. return dev->priv_flags & IFF_OPENVSWITCH;
  4547. }
  4548. static inline bool netif_is_ovs_port(const struct net_device *dev)
  4549. {
  4550. return dev->priv_flags & IFF_OVS_DATAPATH;
  4551. }
  4552. static inline bool netif_is_any_bridge_port(const struct net_device *dev)
  4553. {
  4554. return netif_is_bridge_port(dev) || netif_is_ovs_port(dev);
  4555. }
  4556. static inline bool netif_is_team_master(const struct net_device *dev)
  4557. {
  4558. return dev->priv_flags & IFF_TEAM;
  4559. }
  4560. static inline bool netif_is_team_port(const struct net_device *dev)
  4561. {
  4562. return dev->priv_flags & IFF_TEAM_PORT;
  4563. }
  4564. static inline bool netif_is_lag_master(const struct net_device *dev)
  4565. {
  4566. return netif_is_bond_master(dev) || netif_is_team_master(dev);
  4567. }
  4568. static inline bool netif_is_lag_port(const struct net_device *dev)
  4569. {
  4570. return netif_is_bond_slave(dev) || netif_is_team_port(dev);
  4571. }
  4572. static inline bool netif_is_rxfh_configured(const struct net_device *dev)
  4573. {
  4574. return dev->priv_flags & IFF_RXFH_CONFIGURED;
  4575. }
  4576. static inline bool netif_is_failover(const struct net_device *dev)
  4577. {
  4578. return dev->priv_flags & IFF_FAILOVER;
  4579. }
  4580. static inline bool netif_is_failover_slave(const struct net_device *dev)
  4581. {
  4582. return dev->priv_flags & IFF_FAILOVER_SLAVE;
  4583. }
  4584. /* This device needs to keep skb dst for qdisc enqueue or ndo_start_xmit() */
  4585. static inline void netif_keep_dst(struct net_device *dev)
  4586. {
  4587. dev->priv_flags &= ~(IFF_XMIT_DST_RELEASE | IFF_XMIT_DST_RELEASE_PERM);
  4588. }
  4589. /* return true if dev can't cope with mtu frames that need vlan tag insertion */
  4590. static inline bool netif_reduces_vlan_mtu(struct net_device *dev)
  4591. {
  4592. /* TODO: reserve and use an additional IFF bit, if we get more users */
  4593. return netif_is_macsec(dev);
  4594. }
  4595. extern struct pernet_operations __net_initdata loopback_net_ops;
  4596. /* Logging, debugging and troubleshooting/diagnostic helpers. */
  4597. /* netdev_printk helpers, similar to dev_printk */
  4598. static inline const char *netdev_name(const struct net_device *dev)
  4599. {
  4600. if (!dev->name[0] || strchr(dev->name, '%'))
  4601. return "(unnamed net_device)";
  4602. return dev->name;
  4603. }
  4604. static inline bool netdev_unregistering(const struct net_device *dev)
  4605. {
  4606. return dev->reg_state == NETREG_UNREGISTERING;
  4607. }
  4608. static inline const char *netdev_reg_state(const struct net_device *dev)
  4609. {
  4610. switch (dev->reg_state) {
  4611. case NETREG_UNINITIALIZED: return " (uninitialized)";
  4612. case NETREG_REGISTERED: return "";
  4613. case NETREG_UNREGISTERING: return " (unregistering)";
  4614. case NETREG_UNREGISTERED: return " (unregistered)";
  4615. case NETREG_RELEASED: return " (released)";
  4616. case NETREG_DUMMY: return " (dummy)";
  4617. }
  4618. WARN_ONCE(1, "%s: unknown reg_state %d\n", dev->name, dev->reg_state);
  4619. return " (unknown)";
  4620. }
  4621. #define MODULE_ALIAS_NETDEV(device) \
  4622. MODULE_ALIAS("netdev-" device)
  4623. /*
  4624. * netdev_WARN() acts like dev_printk(), but with the key difference
  4625. * of using a WARN/WARN_ON to get the message out, including the
  4626. * file/line information and a backtrace.
  4627. */
  4628. #define netdev_WARN(dev, format, args...) \
  4629. WARN(1, "netdevice: %s%s: " format, netdev_name(dev), \
  4630. netdev_reg_state(dev), ##args)
  4631. #define netdev_WARN_ONCE(dev, format, args...) \
  4632. WARN_ONCE(1, "netdevice: %s%s: " format, netdev_name(dev), \
  4633. netdev_reg_state(dev), ##args)
  4634. /*
  4635. * The list of packet types we will receive (as opposed to discard)
  4636. * and the routines to invoke.
  4637. *
  4638. * Why 16. Because with 16 the only overlap we get on a hash of the
  4639. * low nibble of the protocol value is RARP/SNAP/X.25.
  4640. *
  4641. * 0800 IP
  4642. * 0001 802.3
  4643. * 0002 AX.25
  4644. * 0004 802.2
  4645. * 8035 RARP
  4646. * 0005 SNAP
  4647. * 0805 X.25
  4648. * 0806 ARP
  4649. * 8137 IPX
  4650. * 0009 Localtalk
  4651. * 86DD IPv6
  4652. */
  4653. #define PTYPE_HASH_SIZE (16)
  4654. #define PTYPE_HASH_MASK (PTYPE_HASH_SIZE - 1)
  4655. extern struct list_head ptype_all __read_mostly;
  4656. extern struct list_head ptype_base[PTYPE_HASH_SIZE] __read_mostly;
  4657. extern struct net_device *blackhole_netdev;
  4658. /* Note: Avoid these macros in fast path, prefer per-cpu or per-queue counters. */
  4659. #define DEV_STATS_INC(DEV, FIELD) atomic_long_inc(&(DEV)->stats.__##FIELD)
  4660. #define DEV_STATS_ADD(DEV, FIELD, VAL) \
  4661. atomic_long_add((VAL), &(DEV)->stats.__##FIELD)
  4662. #define DEV_STATS_READ(DEV, FIELD) atomic_long_read(&(DEV)->stats.__##FIELD)
  4663. #endif /* _LINUX_NETDEVICE_H */