netdevice.h 144 KB

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