netdevice.h 144 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722
  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. enum tc_setup_type {
  705. TC_SETUP_QDISC_MQPRIO,
  706. TC_SETUP_CLSU32,
  707. TC_SETUP_CLSFLOWER,
  708. TC_SETUP_CLSMATCHALL,
  709. TC_SETUP_CLSBPF,
  710. TC_SETUP_BLOCK,
  711. TC_SETUP_QDISC_CBS,
  712. TC_SETUP_QDISC_RED,
  713. TC_SETUP_QDISC_PRIO,
  714. TC_SETUP_QDISC_MQ,
  715. TC_SETUP_QDISC_ETF,
  716. };
  717. /* These structures hold the attributes of bpf state that are being passed
  718. * to the netdevice through the bpf op.
  719. */
  720. enum bpf_netdev_command {
  721. /* Set or clear a bpf program used in the earliest stages of packet
  722. * rx. The prog will have been loaded as BPF_PROG_TYPE_XDP. The callee
  723. * is responsible for calling bpf_prog_put on any old progs that are
  724. * stored. In case of error, the callee need not release the new prog
  725. * reference, but on success it takes ownership and must bpf_prog_put
  726. * when it is no longer used.
  727. */
  728. XDP_SETUP_PROG,
  729. XDP_SETUP_PROG_HW,
  730. /* Check if a bpf program is set on the device. The callee should
  731. * set @prog_attached to one of XDP_ATTACHED_* values, note that "true"
  732. * is equivalent to XDP_ATTACHED_DRV.
  733. */
  734. XDP_QUERY_PROG,
  735. /* BPF program for offload callbacks, invoked at program load time. */
  736. BPF_OFFLOAD_VERIFIER_PREP,
  737. BPF_OFFLOAD_TRANSLATE,
  738. BPF_OFFLOAD_DESTROY,
  739. BPF_OFFLOAD_MAP_ALLOC,
  740. BPF_OFFLOAD_MAP_FREE,
  741. XDP_QUERY_XSK_UMEM,
  742. XDP_SETUP_XSK_UMEM,
  743. };
  744. struct bpf_prog_offload_ops;
  745. struct netlink_ext_ack;
  746. struct xdp_umem;
  747. struct netdev_bpf {
  748. enum bpf_netdev_command command;
  749. union {
  750. /* XDP_SETUP_PROG */
  751. struct {
  752. u32 flags;
  753. struct bpf_prog *prog;
  754. struct netlink_ext_ack *extack;
  755. };
  756. /* XDP_QUERY_PROG */
  757. struct {
  758. u8 prog_attached;
  759. u32 prog_id;
  760. /* flags with which program was installed */
  761. u32 prog_flags;
  762. };
  763. /* BPF_OFFLOAD_VERIFIER_PREP */
  764. struct {
  765. struct bpf_prog *prog;
  766. const struct bpf_prog_offload_ops *ops; /* callee set */
  767. } verifier;
  768. /* BPF_OFFLOAD_TRANSLATE, BPF_OFFLOAD_DESTROY */
  769. struct {
  770. struct bpf_prog *prog;
  771. } offload;
  772. /* BPF_OFFLOAD_MAP_ALLOC, BPF_OFFLOAD_MAP_FREE */
  773. struct {
  774. struct bpf_offloaded_map *offmap;
  775. };
  776. /* XDP_SETUP_XSK_UMEM */
  777. struct {
  778. struct xdp_umem *umem;
  779. u16 queue_id;
  780. } xsk;
  781. };
  782. };
  783. #ifdef CONFIG_XFRM_OFFLOAD
  784. struct xfrmdev_ops {
  785. int (*xdo_dev_state_add) (struct xfrm_state *x);
  786. void (*xdo_dev_state_delete) (struct xfrm_state *x);
  787. void (*xdo_dev_state_free) (struct xfrm_state *x);
  788. bool (*xdo_dev_offload_ok) (struct sk_buff *skb,
  789. struct xfrm_state *x);
  790. void (*xdo_dev_state_advance_esn) (struct xfrm_state *x);
  791. };
  792. #endif
  793. #if IS_ENABLED(CONFIG_TLS_DEVICE)
  794. enum tls_offload_ctx_dir {
  795. TLS_OFFLOAD_CTX_DIR_RX,
  796. TLS_OFFLOAD_CTX_DIR_TX,
  797. };
  798. struct tls_crypto_info;
  799. struct tls_context;
  800. struct tlsdev_ops {
  801. int (*tls_dev_add)(struct net_device *netdev, struct sock *sk,
  802. enum tls_offload_ctx_dir direction,
  803. struct tls_crypto_info *crypto_info,
  804. u32 start_offload_tcp_sn);
  805. void (*tls_dev_del)(struct net_device *netdev,
  806. struct tls_context *ctx,
  807. enum tls_offload_ctx_dir direction);
  808. };
  809. #endif
  810. struct dev_ifalias {
  811. struct rcu_head rcuhead;
  812. char ifalias[];
  813. };
  814. /*
  815. * This structure defines the management hooks for network devices.
  816. * The following hooks can be defined; unless noted otherwise, they are
  817. * optional and can be filled with a null pointer.
  818. *
  819. * int (*ndo_init)(struct net_device *dev);
  820. * This function is called once when a network device is registered.
  821. * The network device can use this for any late stage initialization
  822. * or semantic validation. It can fail with an error code which will
  823. * be propagated back to register_netdev.
  824. *
  825. * void (*ndo_uninit)(struct net_device *dev);
  826. * This function is called when device is unregistered or when registration
  827. * fails. It is not called if init fails.
  828. *
  829. * int (*ndo_open)(struct net_device *dev);
  830. * This function is called when a network device transitions to the up
  831. * state.
  832. *
  833. * int (*ndo_stop)(struct net_device *dev);
  834. * This function is called when a network device transitions to the down
  835. * state.
  836. *
  837. * netdev_tx_t (*ndo_start_xmit)(struct sk_buff *skb,
  838. * struct net_device *dev);
  839. * Called when a packet needs to be transmitted.
  840. * Returns NETDEV_TX_OK. Can return NETDEV_TX_BUSY, but you should stop
  841. * the queue before that can happen; it's for obsolete devices and weird
  842. * corner cases, but the stack really does a non-trivial amount
  843. * of useless work if you return NETDEV_TX_BUSY.
  844. * Required; cannot be NULL.
  845. *
  846. * netdev_features_t (*ndo_features_check)(struct sk_buff *skb,
  847. * struct net_device *dev
  848. * netdev_features_t features);
  849. * Called by core transmit path to determine if device is capable of
  850. * performing offload operations on a given packet. This is to give
  851. * the device an opportunity to implement any restrictions that cannot
  852. * be otherwise expressed by feature flags. The check is called with
  853. * the set of features that the stack has calculated and it returns
  854. * those the driver believes to be appropriate.
  855. *
  856. * u16 (*ndo_select_queue)(struct net_device *dev, struct sk_buff *skb,
  857. * void *accel_priv, 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. void *accel_priv,
  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. int dev_queue_xmit(struct sk_buff *skb);
  2324. int dev_queue_xmit_accel(struct sk_buff *skb, struct net_device *sb_dev);
  2325. int dev_direct_xmit(struct sk_buff *skb, u16 queue_id);
  2326. int register_netdevice(struct net_device *dev);
  2327. void unregister_netdevice_queue(struct net_device *dev, struct list_head *head);
  2328. void unregister_netdevice_many(struct list_head *head);
  2329. static inline void unregister_netdevice(struct net_device *dev)
  2330. {
  2331. unregister_netdevice_queue(dev, NULL);
  2332. }
  2333. int netdev_refcnt_read(const struct net_device *dev);
  2334. void free_netdev(struct net_device *dev);
  2335. void netdev_freemem(struct net_device *dev);
  2336. void synchronize_net(void);
  2337. int init_dummy_netdev(struct net_device *dev);
  2338. DECLARE_PER_CPU(int, xmit_recursion);
  2339. #define XMIT_RECURSION_LIMIT 10
  2340. static inline int dev_recursion_level(void)
  2341. {
  2342. return this_cpu_read(xmit_recursion);
  2343. }
  2344. struct net_device *dev_get_by_index(struct net *net, int ifindex);
  2345. struct net_device *__dev_get_by_index(struct net *net, int ifindex);
  2346. struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex);
  2347. struct net_device *dev_get_by_napi_id(unsigned int napi_id);
  2348. int netdev_get_name(struct net *net, char *name, int ifindex);
  2349. int dev_restart(struct net_device *dev);
  2350. int skb_gro_receive(struct sk_buff *p, struct sk_buff *skb);
  2351. static inline unsigned int skb_gro_offset(const struct sk_buff *skb)
  2352. {
  2353. return NAPI_GRO_CB(skb)->data_offset;
  2354. }
  2355. static inline unsigned int skb_gro_len(const struct sk_buff *skb)
  2356. {
  2357. return skb->len - NAPI_GRO_CB(skb)->data_offset;
  2358. }
  2359. static inline void skb_gro_pull(struct sk_buff *skb, unsigned int len)
  2360. {
  2361. NAPI_GRO_CB(skb)->data_offset += len;
  2362. }
  2363. static inline void *skb_gro_header_fast(struct sk_buff *skb,
  2364. unsigned int offset)
  2365. {
  2366. return NAPI_GRO_CB(skb)->frag0 + offset;
  2367. }
  2368. static inline int skb_gro_header_hard(struct sk_buff *skb, unsigned int hlen)
  2369. {
  2370. return NAPI_GRO_CB(skb)->frag0_len < hlen;
  2371. }
  2372. static inline void skb_gro_frag0_invalidate(struct sk_buff *skb)
  2373. {
  2374. NAPI_GRO_CB(skb)->frag0 = NULL;
  2375. NAPI_GRO_CB(skb)->frag0_len = 0;
  2376. }
  2377. static inline void *skb_gro_header_slow(struct sk_buff *skb, unsigned int hlen,
  2378. unsigned int offset)
  2379. {
  2380. if (!pskb_may_pull(skb, hlen))
  2381. return NULL;
  2382. skb_gro_frag0_invalidate(skb);
  2383. return skb->data + offset;
  2384. }
  2385. static inline void *skb_gro_network_header(struct sk_buff *skb)
  2386. {
  2387. return (NAPI_GRO_CB(skb)->frag0 ?: skb->data) +
  2388. skb_network_offset(skb);
  2389. }
  2390. static inline void skb_gro_postpull_rcsum(struct sk_buff *skb,
  2391. const void *start, unsigned int len)
  2392. {
  2393. if (NAPI_GRO_CB(skb)->csum_valid)
  2394. NAPI_GRO_CB(skb)->csum = csum_sub(NAPI_GRO_CB(skb)->csum,
  2395. csum_partial(start, len, 0));
  2396. }
  2397. /* GRO checksum functions. These are logical equivalents of the normal
  2398. * checksum functions (in skbuff.h) except that they operate on the GRO
  2399. * offsets and fields in sk_buff.
  2400. */
  2401. __sum16 __skb_gro_checksum_complete(struct sk_buff *skb);
  2402. static inline bool skb_at_gro_remcsum_start(struct sk_buff *skb)
  2403. {
  2404. return (NAPI_GRO_CB(skb)->gro_remcsum_start == skb_gro_offset(skb));
  2405. }
  2406. static inline bool __skb_gro_checksum_validate_needed(struct sk_buff *skb,
  2407. bool zero_okay,
  2408. __sum16 check)
  2409. {
  2410. return ((skb->ip_summed != CHECKSUM_PARTIAL ||
  2411. skb_checksum_start_offset(skb) <
  2412. skb_gro_offset(skb)) &&
  2413. !skb_at_gro_remcsum_start(skb) &&
  2414. NAPI_GRO_CB(skb)->csum_cnt == 0 &&
  2415. (!zero_okay || check));
  2416. }
  2417. static inline __sum16 __skb_gro_checksum_validate_complete(struct sk_buff *skb,
  2418. __wsum psum)
  2419. {
  2420. if (NAPI_GRO_CB(skb)->csum_valid &&
  2421. !csum_fold(csum_add(psum, NAPI_GRO_CB(skb)->csum)))
  2422. return 0;
  2423. NAPI_GRO_CB(skb)->csum = psum;
  2424. return __skb_gro_checksum_complete(skb);
  2425. }
  2426. static inline void skb_gro_incr_csum_unnecessary(struct sk_buff *skb)
  2427. {
  2428. if (NAPI_GRO_CB(skb)->csum_cnt > 0) {
  2429. /* Consume a checksum from CHECKSUM_UNNECESSARY */
  2430. NAPI_GRO_CB(skb)->csum_cnt--;
  2431. } else {
  2432. /* Update skb for CHECKSUM_UNNECESSARY and csum_level when we
  2433. * verified a new top level checksum or an encapsulated one
  2434. * during GRO. This saves work if we fallback to normal path.
  2435. */
  2436. __skb_incr_checksum_unnecessary(skb);
  2437. }
  2438. }
  2439. #define __skb_gro_checksum_validate(skb, proto, zero_okay, check, \
  2440. compute_pseudo) \
  2441. ({ \
  2442. __sum16 __ret = 0; \
  2443. if (__skb_gro_checksum_validate_needed(skb, zero_okay, check)) \
  2444. __ret = __skb_gro_checksum_validate_complete(skb, \
  2445. compute_pseudo(skb, proto)); \
  2446. if (!__ret) \
  2447. skb_gro_incr_csum_unnecessary(skb); \
  2448. __ret; \
  2449. })
  2450. #define skb_gro_checksum_validate(skb, proto, compute_pseudo) \
  2451. __skb_gro_checksum_validate(skb, proto, false, 0, compute_pseudo)
  2452. #define skb_gro_checksum_validate_zero_check(skb, proto, check, \
  2453. compute_pseudo) \
  2454. __skb_gro_checksum_validate(skb, proto, true, check, compute_pseudo)
  2455. #define skb_gro_checksum_simple_validate(skb) \
  2456. __skb_gro_checksum_validate(skb, 0, false, 0, null_compute_pseudo)
  2457. static inline bool __skb_gro_checksum_convert_check(struct sk_buff *skb)
  2458. {
  2459. return (NAPI_GRO_CB(skb)->csum_cnt == 0 &&
  2460. !NAPI_GRO_CB(skb)->csum_valid);
  2461. }
  2462. static inline void __skb_gro_checksum_convert(struct sk_buff *skb,
  2463. __sum16 check, __wsum pseudo)
  2464. {
  2465. NAPI_GRO_CB(skb)->csum = ~pseudo;
  2466. NAPI_GRO_CB(skb)->csum_valid = 1;
  2467. }
  2468. #define skb_gro_checksum_try_convert(skb, proto, check, compute_pseudo) \
  2469. do { \
  2470. if (__skb_gro_checksum_convert_check(skb)) \
  2471. __skb_gro_checksum_convert(skb, check, \
  2472. compute_pseudo(skb, proto)); \
  2473. } while (0)
  2474. struct gro_remcsum {
  2475. int offset;
  2476. __wsum delta;
  2477. };
  2478. static inline void skb_gro_remcsum_init(struct gro_remcsum *grc)
  2479. {
  2480. grc->offset = 0;
  2481. grc->delta = 0;
  2482. }
  2483. static inline void *skb_gro_remcsum_process(struct sk_buff *skb, void *ptr,
  2484. unsigned int off, size_t hdrlen,
  2485. int start, int offset,
  2486. struct gro_remcsum *grc,
  2487. bool nopartial)
  2488. {
  2489. __wsum delta;
  2490. size_t plen = hdrlen + max_t(size_t, offset + sizeof(u16), start);
  2491. BUG_ON(!NAPI_GRO_CB(skb)->csum_valid);
  2492. if (!nopartial) {
  2493. NAPI_GRO_CB(skb)->gro_remcsum_start = off + hdrlen + start;
  2494. return ptr;
  2495. }
  2496. ptr = skb_gro_header_fast(skb, off);
  2497. if (skb_gro_header_hard(skb, off + plen)) {
  2498. ptr = skb_gro_header_slow(skb, off + plen, off);
  2499. if (!ptr)
  2500. return NULL;
  2501. }
  2502. delta = remcsum_adjust(ptr + hdrlen, NAPI_GRO_CB(skb)->csum,
  2503. start, offset);
  2504. /* Adjust skb->csum since we changed the packet */
  2505. NAPI_GRO_CB(skb)->csum = csum_add(NAPI_GRO_CB(skb)->csum, delta);
  2506. grc->offset = off + hdrlen + offset;
  2507. grc->delta = delta;
  2508. return ptr;
  2509. }
  2510. static inline void skb_gro_remcsum_cleanup(struct sk_buff *skb,
  2511. struct gro_remcsum *grc)
  2512. {
  2513. void *ptr;
  2514. size_t plen = grc->offset + sizeof(u16);
  2515. if (!grc->delta)
  2516. return;
  2517. ptr = skb_gro_header_fast(skb, grc->offset);
  2518. if (skb_gro_header_hard(skb, grc->offset + sizeof(u16))) {
  2519. ptr = skb_gro_header_slow(skb, plen, grc->offset);
  2520. if (!ptr)
  2521. return;
  2522. }
  2523. remcsum_unadjust((__sum16 *)ptr, grc->delta);
  2524. }
  2525. #ifdef CONFIG_XFRM_OFFLOAD
  2526. static inline void skb_gro_flush_final(struct sk_buff *skb, struct sk_buff *pp, int flush)
  2527. {
  2528. if (PTR_ERR(pp) != -EINPROGRESS)
  2529. NAPI_GRO_CB(skb)->flush |= flush;
  2530. }
  2531. static inline void skb_gro_flush_final_remcsum(struct sk_buff *skb,
  2532. struct sk_buff *pp,
  2533. int flush,
  2534. struct gro_remcsum *grc)
  2535. {
  2536. if (PTR_ERR(pp) != -EINPROGRESS) {
  2537. NAPI_GRO_CB(skb)->flush |= flush;
  2538. skb_gro_remcsum_cleanup(skb, grc);
  2539. skb->remcsum_offload = 0;
  2540. }
  2541. }
  2542. #else
  2543. static inline void skb_gro_flush_final(struct sk_buff *skb, struct sk_buff *pp, int flush)
  2544. {
  2545. NAPI_GRO_CB(skb)->flush |= flush;
  2546. }
  2547. static inline void skb_gro_flush_final_remcsum(struct sk_buff *skb,
  2548. struct sk_buff *pp,
  2549. int flush,
  2550. struct gro_remcsum *grc)
  2551. {
  2552. NAPI_GRO_CB(skb)->flush |= flush;
  2553. skb_gro_remcsum_cleanup(skb, grc);
  2554. skb->remcsum_offload = 0;
  2555. }
  2556. #endif
  2557. static inline int dev_hard_header(struct sk_buff *skb, struct net_device *dev,
  2558. unsigned short type,
  2559. const void *daddr, const void *saddr,
  2560. unsigned int len)
  2561. {
  2562. if (!dev->header_ops || !dev->header_ops->create)
  2563. return 0;
  2564. return dev->header_ops->create(skb, dev, type, daddr, saddr, len);
  2565. }
  2566. static inline int dev_parse_header(const struct sk_buff *skb,
  2567. unsigned char *haddr)
  2568. {
  2569. const struct net_device *dev = skb->dev;
  2570. if (!dev->header_ops || !dev->header_ops->parse)
  2571. return 0;
  2572. return dev->header_ops->parse(skb, haddr);
  2573. }
  2574. /* ll_header must have at least hard_header_len allocated */
  2575. static inline bool dev_validate_header(const struct net_device *dev,
  2576. char *ll_header, int len)
  2577. {
  2578. if (likely(len >= dev->hard_header_len))
  2579. return true;
  2580. if (len < dev->min_header_len)
  2581. return false;
  2582. if (capable(CAP_SYS_RAWIO)) {
  2583. memset(ll_header + len, 0, dev->hard_header_len - len);
  2584. return true;
  2585. }
  2586. if (dev->header_ops && dev->header_ops->validate)
  2587. return dev->header_ops->validate(ll_header, len);
  2588. return false;
  2589. }
  2590. typedef int gifconf_func_t(struct net_device * dev, char __user * bufptr,
  2591. int len, int size);
  2592. int register_gifconf(unsigned int family, gifconf_func_t *gifconf);
  2593. static inline int unregister_gifconf(unsigned int family)
  2594. {
  2595. return register_gifconf(family, NULL);
  2596. }
  2597. #ifdef CONFIG_NET_FLOW_LIMIT
  2598. #define FLOW_LIMIT_HISTORY (1 << 7) /* must be ^2 and !overflow buckets */
  2599. struct sd_flow_limit {
  2600. u64 count;
  2601. unsigned int num_buckets;
  2602. unsigned int history_head;
  2603. u16 history[FLOW_LIMIT_HISTORY];
  2604. u8 buckets[];
  2605. };
  2606. extern int netdev_flow_limit_table_len;
  2607. #endif /* CONFIG_NET_FLOW_LIMIT */
  2608. /*
  2609. * Incoming packets are placed on per-CPU queues
  2610. */
  2611. struct softnet_data {
  2612. struct list_head poll_list;
  2613. struct sk_buff_head process_queue;
  2614. /* stats */
  2615. unsigned int processed;
  2616. unsigned int time_squeeze;
  2617. unsigned int received_rps;
  2618. #ifdef CONFIG_RPS
  2619. struct softnet_data *rps_ipi_list;
  2620. #endif
  2621. #ifdef CONFIG_NET_FLOW_LIMIT
  2622. struct sd_flow_limit __rcu *flow_limit;
  2623. #endif
  2624. struct Qdisc *output_queue;
  2625. struct Qdisc **output_queue_tailp;
  2626. struct sk_buff *completion_queue;
  2627. #ifdef CONFIG_XFRM_OFFLOAD
  2628. struct sk_buff_head xfrm_backlog;
  2629. #endif
  2630. #ifdef CONFIG_RPS
  2631. /* input_queue_head should be written by cpu owning this struct,
  2632. * and only read by other cpus. Worth using a cache line.
  2633. */
  2634. unsigned int input_queue_head ____cacheline_aligned_in_smp;
  2635. /* Elements below can be accessed between CPUs for RPS/RFS */
  2636. call_single_data_t csd ____cacheline_aligned_in_smp;
  2637. struct softnet_data *rps_ipi_next;
  2638. unsigned int cpu;
  2639. unsigned int input_queue_tail;
  2640. #endif
  2641. unsigned int dropped;
  2642. struct sk_buff_head input_pkt_queue;
  2643. struct napi_struct backlog;
  2644. };
  2645. static inline void input_queue_head_incr(struct softnet_data *sd)
  2646. {
  2647. #ifdef CONFIG_RPS
  2648. sd->input_queue_head++;
  2649. #endif
  2650. }
  2651. static inline void input_queue_tail_incr_save(struct softnet_data *sd,
  2652. unsigned int *qtail)
  2653. {
  2654. #ifdef CONFIG_RPS
  2655. *qtail = ++sd->input_queue_tail;
  2656. #endif
  2657. }
  2658. DECLARE_PER_CPU_ALIGNED(struct softnet_data, softnet_data);
  2659. void __netif_schedule(struct Qdisc *q);
  2660. void netif_schedule_queue(struct netdev_queue *txq);
  2661. static inline void netif_tx_schedule_all(struct net_device *dev)
  2662. {
  2663. unsigned int i;
  2664. for (i = 0; i < dev->num_tx_queues; i++)
  2665. netif_schedule_queue(netdev_get_tx_queue(dev, i));
  2666. }
  2667. static __always_inline void netif_tx_start_queue(struct netdev_queue *dev_queue)
  2668. {
  2669. clear_bit(__QUEUE_STATE_DRV_XOFF, &dev_queue->state);
  2670. }
  2671. /**
  2672. * netif_start_queue - allow transmit
  2673. * @dev: network device
  2674. *
  2675. * Allow upper layers to call the device hard_start_xmit routine.
  2676. */
  2677. static inline void netif_start_queue(struct net_device *dev)
  2678. {
  2679. netif_tx_start_queue(netdev_get_tx_queue(dev, 0));
  2680. }
  2681. static inline void netif_tx_start_all_queues(struct net_device *dev)
  2682. {
  2683. unsigned int i;
  2684. for (i = 0; i < dev->num_tx_queues; i++) {
  2685. struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
  2686. netif_tx_start_queue(txq);
  2687. }
  2688. }
  2689. void netif_tx_wake_queue(struct netdev_queue *dev_queue);
  2690. /**
  2691. * netif_wake_queue - restart transmit
  2692. * @dev: network device
  2693. *
  2694. * Allow upper layers to call the device hard_start_xmit routine.
  2695. * Used for flow control when transmit resources are available.
  2696. */
  2697. static inline void netif_wake_queue(struct net_device *dev)
  2698. {
  2699. netif_tx_wake_queue(netdev_get_tx_queue(dev, 0));
  2700. }
  2701. static inline void netif_tx_wake_all_queues(struct net_device *dev)
  2702. {
  2703. unsigned int i;
  2704. for (i = 0; i < dev->num_tx_queues; i++) {
  2705. struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
  2706. netif_tx_wake_queue(txq);
  2707. }
  2708. }
  2709. static __always_inline void netif_tx_stop_queue(struct netdev_queue *dev_queue)
  2710. {
  2711. set_bit(__QUEUE_STATE_DRV_XOFF, &dev_queue->state);
  2712. }
  2713. /**
  2714. * netif_stop_queue - stop transmitted packets
  2715. * @dev: network device
  2716. *
  2717. * Stop upper layers calling the device hard_start_xmit routine.
  2718. * Used for flow control when transmit resources are unavailable.
  2719. */
  2720. static inline void netif_stop_queue(struct net_device *dev)
  2721. {
  2722. netif_tx_stop_queue(netdev_get_tx_queue(dev, 0));
  2723. }
  2724. void netif_tx_stop_all_queues(struct net_device *dev);
  2725. static inline bool netif_tx_queue_stopped(const struct netdev_queue *dev_queue)
  2726. {
  2727. return test_bit(__QUEUE_STATE_DRV_XOFF, &dev_queue->state);
  2728. }
  2729. /**
  2730. * netif_queue_stopped - test if transmit queue is flowblocked
  2731. * @dev: network device
  2732. *
  2733. * Test if transmit queue on device is currently unable to send.
  2734. */
  2735. static inline bool netif_queue_stopped(const struct net_device *dev)
  2736. {
  2737. return netif_tx_queue_stopped(netdev_get_tx_queue(dev, 0));
  2738. }
  2739. static inline bool netif_xmit_stopped(const struct netdev_queue *dev_queue)
  2740. {
  2741. return dev_queue->state & QUEUE_STATE_ANY_XOFF;
  2742. }
  2743. static inline bool
  2744. netif_xmit_frozen_or_stopped(const struct netdev_queue *dev_queue)
  2745. {
  2746. return dev_queue->state & QUEUE_STATE_ANY_XOFF_OR_FROZEN;
  2747. }
  2748. static inline bool
  2749. netif_xmit_frozen_or_drv_stopped(const struct netdev_queue *dev_queue)
  2750. {
  2751. return dev_queue->state & QUEUE_STATE_DRV_XOFF_OR_FROZEN;
  2752. }
  2753. /**
  2754. * netdev_txq_bql_enqueue_prefetchw - prefetch bql data for write
  2755. * @dev_queue: pointer to transmit queue
  2756. *
  2757. * BQL enabled drivers might use this helper in their ndo_start_xmit(),
  2758. * to give appropriate hint to the CPU.
  2759. */
  2760. static inline void netdev_txq_bql_enqueue_prefetchw(struct netdev_queue *dev_queue)
  2761. {
  2762. #ifdef CONFIG_BQL
  2763. prefetchw(&dev_queue->dql.num_queued);
  2764. #endif
  2765. }
  2766. /**
  2767. * netdev_txq_bql_complete_prefetchw - prefetch bql data for write
  2768. * @dev_queue: pointer to transmit queue
  2769. *
  2770. * BQL enabled drivers might use this helper in their TX completion path,
  2771. * to give appropriate hint to the CPU.
  2772. */
  2773. static inline void netdev_txq_bql_complete_prefetchw(struct netdev_queue *dev_queue)
  2774. {
  2775. #ifdef CONFIG_BQL
  2776. prefetchw(&dev_queue->dql.limit);
  2777. #endif
  2778. }
  2779. static inline void netdev_tx_sent_queue(struct netdev_queue *dev_queue,
  2780. unsigned int bytes)
  2781. {
  2782. #ifdef CONFIG_BQL
  2783. dql_queued(&dev_queue->dql, bytes);
  2784. if (likely(dql_avail(&dev_queue->dql) >= 0))
  2785. return;
  2786. set_bit(__QUEUE_STATE_STACK_XOFF, &dev_queue->state);
  2787. /*
  2788. * The XOFF flag must be set before checking the dql_avail below,
  2789. * because in netdev_tx_completed_queue we update the dql_completed
  2790. * before checking the XOFF flag.
  2791. */
  2792. smp_mb();
  2793. /* check again in case another CPU has just made room avail */
  2794. if (unlikely(dql_avail(&dev_queue->dql) >= 0))
  2795. clear_bit(__QUEUE_STATE_STACK_XOFF, &dev_queue->state);
  2796. #endif
  2797. }
  2798. /**
  2799. * netdev_sent_queue - report the number of bytes queued to hardware
  2800. * @dev: network device
  2801. * @bytes: number of bytes queued to the hardware device queue
  2802. *
  2803. * Report the number of bytes queued for sending/completion to the network
  2804. * device hardware queue. @bytes should be a good approximation and should
  2805. * exactly match netdev_completed_queue() @bytes
  2806. */
  2807. static inline void netdev_sent_queue(struct net_device *dev, unsigned int bytes)
  2808. {
  2809. netdev_tx_sent_queue(netdev_get_tx_queue(dev, 0), bytes);
  2810. }
  2811. static inline void netdev_tx_completed_queue(struct netdev_queue *dev_queue,
  2812. unsigned int pkts, unsigned int bytes)
  2813. {
  2814. #ifdef CONFIG_BQL
  2815. if (unlikely(!bytes))
  2816. return;
  2817. dql_completed(&dev_queue->dql, bytes);
  2818. /*
  2819. * Without the memory barrier there is a small possiblity that
  2820. * netdev_tx_sent_queue will miss the update and cause the queue to
  2821. * be stopped forever
  2822. */
  2823. smp_mb();
  2824. if (dql_avail(&dev_queue->dql) < 0)
  2825. return;
  2826. if (test_and_clear_bit(__QUEUE_STATE_STACK_XOFF, &dev_queue->state))
  2827. netif_schedule_queue(dev_queue);
  2828. #endif
  2829. }
  2830. /**
  2831. * netdev_completed_queue - report bytes and packets completed by device
  2832. * @dev: network device
  2833. * @pkts: actual number of packets sent over the medium
  2834. * @bytes: actual number of bytes sent over the medium
  2835. *
  2836. * Report the number of bytes and packets transmitted by the network device
  2837. * hardware queue over the physical medium, @bytes must exactly match the
  2838. * @bytes amount passed to netdev_sent_queue()
  2839. */
  2840. static inline void netdev_completed_queue(struct net_device *dev,
  2841. unsigned int pkts, unsigned int bytes)
  2842. {
  2843. netdev_tx_completed_queue(netdev_get_tx_queue(dev, 0), pkts, bytes);
  2844. }
  2845. static inline void netdev_tx_reset_queue(struct netdev_queue *q)
  2846. {
  2847. #ifdef CONFIG_BQL
  2848. clear_bit(__QUEUE_STATE_STACK_XOFF, &q->state);
  2849. dql_reset(&q->dql);
  2850. #endif
  2851. }
  2852. /**
  2853. * netdev_reset_queue - reset the packets and bytes count of a network device
  2854. * @dev_queue: network device
  2855. *
  2856. * Reset the bytes and packet count of a network device and clear the
  2857. * software flow control OFF bit for this network device
  2858. */
  2859. static inline void netdev_reset_queue(struct net_device *dev_queue)
  2860. {
  2861. netdev_tx_reset_queue(netdev_get_tx_queue(dev_queue, 0));
  2862. }
  2863. /**
  2864. * netdev_cap_txqueue - check if selected tx queue exceeds device queues
  2865. * @dev: network device
  2866. * @queue_index: given tx queue index
  2867. *
  2868. * Returns 0 if given tx queue index >= number of device tx queues,
  2869. * otherwise returns the originally passed tx queue index.
  2870. */
  2871. static inline u16 netdev_cap_txqueue(struct net_device *dev, u16 queue_index)
  2872. {
  2873. if (unlikely(queue_index >= dev->real_num_tx_queues)) {
  2874. net_warn_ratelimited("%s selects TX queue %d, but real number of TX queues is %d\n",
  2875. dev->name, queue_index,
  2876. dev->real_num_tx_queues);
  2877. return 0;
  2878. }
  2879. return queue_index;
  2880. }
  2881. /**
  2882. * netif_running - test if up
  2883. * @dev: network device
  2884. *
  2885. * Test if the device has been brought up.
  2886. */
  2887. static inline bool netif_running(const struct net_device *dev)
  2888. {
  2889. return test_bit(__LINK_STATE_START, &dev->state);
  2890. }
  2891. /*
  2892. * Routines to manage the subqueues on a device. We only need start,
  2893. * stop, and a check if it's stopped. All other device management is
  2894. * done at the overall netdevice level.
  2895. * Also test the device if we're multiqueue.
  2896. */
  2897. /**
  2898. * netif_start_subqueue - allow sending packets on subqueue
  2899. * @dev: network device
  2900. * @queue_index: sub queue index
  2901. *
  2902. * Start individual transmit queue of a device with multiple transmit queues.
  2903. */
  2904. static inline void netif_start_subqueue(struct net_device *dev, u16 queue_index)
  2905. {
  2906. struct netdev_queue *txq = netdev_get_tx_queue(dev, queue_index);
  2907. netif_tx_start_queue(txq);
  2908. }
  2909. /**
  2910. * netif_stop_subqueue - stop sending packets on subqueue
  2911. * @dev: network device
  2912. * @queue_index: sub queue index
  2913. *
  2914. * Stop individual transmit queue of a device with multiple transmit queues.
  2915. */
  2916. static inline void netif_stop_subqueue(struct net_device *dev, u16 queue_index)
  2917. {
  2918. struct netdev_queue *txq = netdev_get_tx_queue(dev, queue_index);
  2919. netif_tx_stop_queue(txq);
  2920. }
  2921. /**
  2922. * netif_subqueue_stopped - test status of subqueue
  2923. * @dev: network device
  2924. * @queue_index: sub queue index
  2925. *
  2926. * Check individual transmit queue of a device with multiple transmit queues.
  2927. */
  2928. static inline bool __netif_subqueue_stopped(const struct net_device *dev,
  2929. u16 queue_index)
  2930. {
  2931. struct netdev_queue *txq = netdev_get_tx_queue(dev, queue_index);
  2932. return netif_tx_queue_stopped(txq);
  2933. }
  2934. static inline bool netif_subqueue_stopped(const struct net_device *dev,
  2935. struct sk_buff *skb)
  2936. {
  2937. return __netif_subqueue_stopped(dev, skb_get_queue_mapping(skb));
  2938. }
  2939. /**
  2940. * netif_wake_subqueue - allow sending packets on subqueue
  2941. * @dev: network device
  2942. * @queue_index: sub queue index
  2943. *
  2944. * Resume individual transmit queue of a device with multiple transmit queues.
  2945. */
  2946. static inline void netif_wake_subqueue(struct net_device *dev, u16 queue_index)
  2947. {
  2948. struct netdev_queue *txq = netdev_get_tx_queue(dev, queue_index);
  2949. netif_tx_wake_queue(txq);
  2950. }
  2951. #ifdef CONFIG_XPS
  2952. int netif_set_xps_queue(struct net_device *dev, const struct cpumask *mask,
  2953. u16 index);
  2954. int __netif_set_xps_queue(struct net_device *dev, const unsigned long *mask,
  2955. u16 index, bool is_rxqs_map);
  2956. /**
  2957. * netif_attr_test_mask - Test a CPU or Rx queue set in a mask
  2958. * @j: CPU/Rx queue index
  2959. * @mask: bitmask of all cpus/rx queues
  2960. * @nr_bits: number of bits in the bitmask
  2961. *
  2962. * Test if a CPU or Rx queue index is set in a mask of all CPU/Rx queues.
  2963. */
  2964. static inline bool netif_attr_test_mask(unsigned long j,
  2965. const unsigned long *mask,
  2966. unsigned int nr_bits)
  2967. {
  2968. cpu_max_bits_warn(j, nr_bits);
  2969. return test_bit(j, mask);
  2970. }
  2971. /**
  2972. * netif_attr_test_online - Test for online CPU/Rx queue
  2973. * @j: CPU/Rx queue index
  2974. * @online_mask: bitmask for CPUs/Rx queues that are online
  2975. * @nr_bits: number of bits in the bitmask
  2976. *
  2977. * Returns true if a CPU/Rx queue is online.
  2978. */
  2979. static inline bool netif_attr_test_online(unsigned long j,
  2980. const unsigned long *online_mask,
  2981. unsigned int nr_bits)
  2982. {
  2983. cpu_max_bits_warn(j, nr_bits);
  2984. if (online_mask)
  2985. return test_bit(j, online_mask);
  2986. return (j < nr_bits);
  2987. }
  2988. /**
  2989. * netif_attrmask_next - get the next CPU/Rx queue in a cpu/Rx queues mask
  2990. * @n: CPU/Rx queue index
  2991. * @srcp: the cpumask/Rx queue mask pointer
  2992. * @nr_bits: number of bits in the bitmask
  2993. *
  2994. * Returns >= nr_bits if no further CPUs/Rx queues set.
  2995. */
  2996. static inline unsigned int netif_attrmask_next(int n, const unsigned long *srcp,
  2997. unsigned int nr_bits)
  2998. {
  2999. /* -1 is a legal arg here. */
  3000. if (n != -1)
  3001. cpu_max_bits_warn(n, nr_bits);
  3002. if (srcp)
  3003. return find_next_bit(srcp, nr_bits, n + 1);
  3004. return n + 1;
  3005. }
  3006. /**
  3007. * netif_attrmask_next_and - get the next CPU/Rx queue in *src1p & *src2p
  3008. * @n: CPU/Rx queue index
  3009. * @src1p: the first CPUs/Rx queues mask pointer
  3010. * @src2p: the second CPUs/Rx queues mask pointer
  3011. * @nr_bits: number of bits in the bitmask
  3012. *
  3013. * Returns >= nr_bits if no further CPUs/Rx queues set in both.
  3014. */
  3015. static inline int netif_attrmask_next_and(int n, const unsigned long *src1p,
  3016. const unsigned long *src2p,
  3017. unsigned int nr_bits)
  3018. {
  3019. /* -1 is a legal arg here. */
  3020. if (n != -1)
  3021. cpu_max_bits_warn(n, nr_bits);
  3022. if (src1p && src2p)
  3023. return find_next_and_bit(src1p, src2p, nr_bits, n + 1);
  3024. else if (src1p)
  3025. return find_next_bit(src1p, nr_bits, n + 1);
  3026. else if (src2p)
  3027. return find_next_bit(src2p, nr_bits, n + 1);
  3028. return n + 1;
  3029. }
  3030. #else
  3031. static inline int netif_set_xps_queue(struct net_device *dev,
  3032. const struct cpumask *mask,
  3033. u16 index)
  3034. {
  3035. return 0;
  3036. }
  3037. #endif
  3038. /**
  3039. * netif_is_multiqueue - test if device has multiple transmit queues
  3040. * @dev: network device
  3041. *
  3042. * Check if device has multiple transmit queues
  3043. */
  3044. static inline bool netif_is_multiqueue(const struct net_device *dev)
  3045. {
  3046. return dev->num_tx_queues > 1;
  3047. }
  3048. int netif_set_real_num_tx_queues(struct net_device *dev, unsigned int txq);
  3049. #ifdef CONFIG_SYSFS
  3050. int netif_set_real_num_rx_queues(struct net_device *dev, unsigned int rxq);
  3051. #else
  3052. static inline int netif_set_real_num_rx_queues(struct net_device *dev,
  3053. unsigned int rxq)
  3054. {
  3055. return 0;
  3056. }
  3057. #endif
  3058. static inline struct netdev_rx_queue *
  3059. __netif_get_rx_queue(struct net_device *dev, unsigned int rxq)
  3060. {
  3061. return dev->_rx + rxq;
  3062. }
  3063. #ifdef CONFIG_SYSFS
  3064. static inline unsigned int get_netdev_rx_queue_index(
  3065. struct netdev_rx_queue *queue)
  3066. {
  3067. struct net_device *dev = queue->dev;
  3068. int index = queue - dev->_rx;
  3069. BUG_ON(index >= dev->num_rx_queues);
  3070. return index;
  3071. }
  3072. #endif
  3073. #define DEFAULT_MAX_NUM_RSS_QUEUES (8)
  3074. int netif_get_num_default_rss_queues(void);
  3075. enum skb_free_reason {
  3076. SKB_REASON_CONSUMED,
  3077. SKB_REASON_DROPPED,
  3078. };
  3079. void __dev_kfree_skb_irq(struct sk_buff *skb, enum skb_free_reason reason);
  3080. void __dev_kfree_skb_any(struct sk_buff *skb, enum skb_free_reason reason);
  3081. /*
  3082. * It is not allowed to call kfree_skb() or consume_skb() from hardware
  3083. * interrupt context or with hardware interrupts being disabled.
  3084. * (in_irq() || irqs_disabled())
  3085. *
  3086. * We provide four helpers that can be used in following contexts :
  3087. *
  3088. * dev_kfree_skb_irq(skb) when caller drops a packet from irq context,
  3089. * replacing kfree_skb(skb)
  3090. *
  3091. * dev_consume_skb_irq(skb) when caller consumes a packet from irq context.
  3092. * Typically used in place of consume_skb(skb) in TX completion path
  3093. *
  3094. * dev_kfree_skb_any(skb) when caller doesn't know its current irq context,
  3095. * replacing kfree_skb(skb)
  3096. *
  3097. * dev_consume_skb_any(skb) when caller doesn't know its current irq context,
  3098. * and consumed a packet. Used in place of consume_skb(skb)
  3099. */
  3100. static inline void dev_kfree_skb_irq(struct sk_buff *skb)
  3101. {
  3102. __dev_kfree_skb_irq(skb, SKB_REASON_DROPPED);
  3103. }
  3104. static inline void dev_consume_skb_irq(struct sk_buff *skb)
  3105. {
  3106. __dev_kfree_skb_irq(skb, SKB_REASON_CONSUMED);
  3107. }
  3108. static inline void dev_kfree_skb_any(struct sk_buff *skb)
  3109. {
  3110. __dev_kfree_skb_any(skb, SKB_REASON_DROPPED);
  3111. }
  3112. static inline void dev_consume_skb_any(struct sk_buff *skb)
  3113. {
  3114. __dev_kfree_skb_any(skb, SKB_REASON_CONSUMED);
  3115. }
  3116. void generic_xdp_tx(struct sk_buff *skb, struct bpf_prog *xdp_prog);
  3117. int do_xdp_generic(struct bpf_prog *xdp_prog, struct sk_buff *skb);
  3118. int netif_rx(struct sk_buff *skb);
  3119. int netif_rx_ni(struct sk_buff *skb);
  3120. int netif_receive_skb(struct sk_buff *skb);
  3121. int netif_receive_skb_core(struct sk_buff *skb);
  3122. void netif_receive_skb_list(struct list_head *head);
  3123. gro_result_t napi_gro_receive(struct napi_struct *napi, struct sk_buff *skb);
  3124. void napi_gro_flush(struct napi_struct *napi, bool flush_old);
  3125. struct sk_buff *napi_get_frags(struct napi_struct *napi);
  3126. gro_result_t napi_gro_frags(struct napi_struct *napi);
  3127. struct packet_offload *gro_find_receive_by_type(__be16 type);
  3128. struct packet_offload *gro_find_complete_by_type(__be16 type);
  3129. static inline void napi_free_frags(struct napi_struct *napi)
  3130. {
  3131. kfree_skb(napi->skb);
  3132. napi->skb = NULL;
  3133. }
  3134. bool netdev_is_rx_handler_busy(struct net_device *dev);
  3135. int netdev_rx_handler_register(struct net_device *dev,
  3136. rx_handler_func_t *rx_handler,
  3137. void *rx_handler_data);
  3138. void netdev_rx_handler_unregister(struct net_device *dev);
  3139. bool dev_valid_name(const char *name);
  3140. int dev_ioctl(struct net *net, unsigned int cmd, struct ifreq *ifr,
  3141. bool *need_copyout);
  3142. int dev_ifconf(struct net *net, struct ifconf *, int);
  3143. int dev_ethtool(struct net *net, struct ifreq *);
  3144. unsigned int dev_get_flags(const struct net_device *);
  3145. int __dev_change_flags(struct net_device *, unsigned int flags);
  3146. int dev_change_flags(struct net_device *, unsigned int);
  3147. void __dev_notify_flags(struct net_device *, unsigned int old_flags,
  3148. unsigned int gchanges);
  3149. int dev_change_name(struct net_device *, const char *);
  3150. int dev_set_alias(struct net_device *, const char *, size_t);
  3151. int dev_get_alias(const struct net_device *, char *, size_t);
  3152. int dev_change_net_namespace(struct net_device *, struct net *, const char *);
  3153. int __dev_set_mtu(struct net_device *, int);
  3154. int dev_set_mtu(struct net_device *, int);
  3155. int dev_change_tx_queue_len(struct net_device *, unsigned long);
  3156. void dev_set_group(struct net_device *, int);
  3157. int dev_set_mac_address(struct net_device *, struct sockaddr *);
  3158. int dev_change_carrier(struct net_device *, bool new_carrier);
  3159. int dev_get_phys_port_id(struct net_device *dev,
  3160. struct netdev_phys_item_id *ppid);
  3161. int dev_get_phys_port_name(struct net_device *dev,
  3162. char *name, size_t len);
  3163. int dev_change_proto_down(struct net_device *dev, bool proto_down);
  3164. struct sk_buff *validate_xmit_skb_list(struct sk_buff *skb, struct net_device *dev, bool *again);
  3165. struct sk_buff *dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev,
  3166. struct netdev_queue *txq, int *ret);
  3167. typedef int (*bpf_op_t)(struct net_device *dev, struct netdev_bpf *bpf);
  3168. int dev_change_xdp_fd(struct net_device *dev, struct netlink_ext_ack *extack,
  3169. int fd, u32 flags);
  3170. void __dev_xdp_query(struct net_device *dev, bpf_op_t xdp_op,
  3171. struct netdev_bpf *xdp);
  3172. int __dev_forward_skb(struct net_device *dev, struct sk_buff *skb);
  3173. int dev_forward_skb(struct net_device *dev, struct sk_buff *skb);
  3174. bool is_skb_forwardable(const struct net_device *dev,
  3175. const struct sk_buff *skb);
  3176. static __always_inline int ____dev_forward_skb(struct net_device *dev,
  3177. struct sk_buff *skb)
  3178. {
  3179. if (skb_orphan_frags(skb, GFP_ATOMIC) ||
  3180. unlikely(!is_skb_forwardable(dev, skb))) {
  3181. atomic_long_inc(&dev->rx_dropped);
  3182. kfree_skb(skb);
  3183. return NET_RX_DROP;
  3184. }
  3185. skb_scrub_packet(skb, true);
  3186. skb->priority = 0;
  3187. return 0;
  3188. }
  3189. void dev_queue_xmit_nit(struct sk_buff *skb, struct net_device *dev);
  3190. extern int netdev_budget;
  3191. extern unsigned int netdev_budget_usecs;
  3192. /* Called by rtnetlink.c:rtnl_unlock() */
  3193. void netdev_run_todo(void);
  3194. /**
  3195. * dev_put - release reference to device
  3196. * @dev: network device
  3197. *
  3198. * Release reference to device to allow it to be freed.
  3199. */
  3200. static inline void dev_put(struct net_device *dev)
  3201. {
  3202. this_cpu_dec(*dev->pcpu_refcnt);
  3203. }
  3204. /**
  3205. * dev_hold - get reference to device
  3206. * @dev: network device
  3207. *
  3208. * Hold reference to device to keep it from being freed.
  3209. */
  3210. static inline void dev_hold(struct net_device *dev)
  3211. {
  3212. this_cpu_inc(*dev->pcpu_refcnt);
  3213. }
  3214. /* Carrier loss detection, dial on demand. The functions netif_carrier_on
  3215. * and _off may be called from IRQ context, but it is caller
  3216. * who is responsible for serialization of these calls.
  3217. *
  3218. * The name carrier is inappropriate, these functions should really be
  3219. * called netif_lowerlayer_*() because they represent the state of any
  3220. * kind of lower layer not just hardware media.
  3221. */
  3222. void linkwatch_init_dev(struct net_device *dev);
  3223. void linkwatch_fire_event(struct net_device *dev);
  3224. void linkwatch_forget_dev(struct net_device *dev);
  3225. /**
  3226. * netif_carrier_ok - test if carrier present
  3227. * @dev: network device
  3228. *
  3229. * Check if carrier is present on device
  3230. */
  3231. static inline bool netif_carrier_ok(const struct net_device *dev)
  3232. {
  3233. return !test_bit(__LINK_STATE_NOCARRIER, &dev->state);
  3234. }
  3235. unsigned long dev_trans_start(struct net_device *dev);
  3236. void __netdev_watchdog_up(struct net_device *dev);
  3237. void netif_carrier_on(struct net_device *dev);
  3238. void netif_carrier_off(struct net_device *dev);
  3239. /**
  3240. * netif_dormant_on - mark device as dormant.
  3241. * @dev: network device
  3242. *
  3243. * Mark device as dormant (as per RFC2863).
  3244. *
  3245. * The dormant state indicates that the relevant interface is not
  3246. * actually in a condition to pass packets (i.e., it is not 'up') but is
  3247. * in a "pending" state, waiting for some external event. For "on-
  3248. * demand" interfaces, this new state identifies the situation where the
  3249. * interface is waiting for events to place it in the up state.
  3250. */
  3251. static inline void netif_dormant_on(struct net_device *dev)
  3252. {
  3253. if (!test_and_set_bit(__LINK_STATE_DORMANT, &dev->state))
  3254. linkwatch_fire_event(dev);
  3255. }
  3256. /**
  3257. * netif_dormant_off - set device as not dormant.
  3258. * @dev: network device
  3259. *
  3260. * Device is not in dormant state.
  3261. */
  3262. static inline void netif_dormant_off(struct net_device *dev)
  3263. {
  3264. if (test_and_clear_bit(__LINK_STATE_DORMANT, &dev->state))
  3265. linkwatch_fire_event(dev);
  3266. }
  3267. /**
  3268. * netif_dormant - test if device is dormant
  3269. * @dev: network device
  3270. *
  3271. * Check if device is dormant.
  3272. */
  3273. static inline bool netif_dormant(const struct net_device *dev)
  3274. {
  3275. return test_bit(__LINK_STATE_DORMANT, &dev->state);
  3276. }
  3277. /**
  3278. * netif_oper_up - test if device is operational
  3279. * @dev: network device
  3280. *
  3281. * Check if carrier is operational
  3282. */
  3283. static inline bool netif_oper_up(const struct net_device *dev)
  3284. {
  3285. return (dev->operstate == IF_OPER_UP ||
  3286. dev->operstate == IF_OPER_UNKNOWN /* backward compat */);
  3287. }
  3288. /**
  3289. * netif_device_present - is device available or removed
  3290. * @dev: network device
  3291. *
  3292. * Check if device has not been removed from system.
  3293. */
  3294. static inline bool netif_device_present(struct net_device *dev)
  3295. {
  3296. return test_bit(__LINK_STATE_PRESENT, &dev->state);
  3297. }
  3298. void netif_device_detach(struct net_device *dev);
  3299. void netif_device_attach(struct net_device *dev);
  3300. /*
  3301. * Network interface message level settings
  3302. */
  3303. enum {
  3304. NETIF_MSG_DRV = 0x0001,
  3305. NETIF_MSG_PROBE = 0x0002,
  3306. NETIF_MSG_LINK = 0x0004,
  3307. NETIF_MSG_TIMER = 0x0008,
  3308. NETIF_MSG_IFDOWN = 0x0010,
  3309. NETIF_MSG_IFUP = 0x0020,
  3310. NETIF_MSG_RX_ERR = 0x0040,
  3311. NETIF_MSG_TX_ERR = 0x0080,
  3312. NETIF_MSG_TX_QUEUED = 0x0100,
  3313. NETIF_MSG_INTR = 0x0200,
  3314. NETIF_MSG_TX_DONE = 0x0400,
  3315. NETIF_MSG_RX_STATUS = 0x0800,
  3316. NETIF_MSG_PKTDATA = 0x1000,
  3317. NETIF_MSG_HW = 0x2000,
  3318. NETIF_MSG_WOL = 0x4000,
  3319. };
  3320. #define netif_msg_drv(p) ((p)->msg_enable & NETIF_MSG_DRV)
  3321. #define netif_msg_probe(p) ((p)->msg_enable & NETIF_MSG_PROBE)
  3322. #define netif_msg_link(p) ((p)->msg_enable & NETIF_MSG_LINK)
  3323. #define netif_msg_timer(p) ((p)->msg_enable & NETIF_MSG_TIMER)
  3324. #define netif_msg_ifdown(p) ((p)->msg_enable & NETIF_MSG_IFDOWN)
  3325. #define netif_msg_ifup(p) ((p)->msg_enable & NETIF_MSG_IFUP)
  3326. #define netif_msg_rx_err(p) ((p)->msg_enable & NETIF_MSG_RX_ERR)
  3327. #define netif_msg_tx_err(p) ((p)->msg_enable & NETIF_MSG_TX_ERR)
  3328. #define netif_msg_tx_queued(p) ((p)->msg_enable & NETIF_MSG_TX_QUEUED)
  3329. #define netif_msg_intr(p) ((p)->msg_enable & NETIF_MSG_INTR)
  3330. #define netif_msg_tx_done(p) ((p)->msg_enable & NETIF_MSG_TX_DONE)
  3331. #define netif_msg_rx_status(p) ((p)->msg_enable & NETIF_MSG_RX_STATUS)
  3332. #define netif_msg_pktdata(p) ((p)->msg_enable & NETIF_MSG_PKTDATA)
  3333. #define netif_msg_hw(p) ((p)->msg_enable & NETIF_MSG_HW)
  3334. #define netif_msg_wol(p) ((p)->msg_enable & NETIF_MSG_WOL)
  3335. static inline u32 netif_msg_init(int debug_value, int default_msg_enable_bits)
  3336. {
  3337. /* use default */
  3338. if (debug_value < 0 || debug_value >= (sizeof(u32) * 8))
  3339. return default_msg_enable_bits;
  3340. if (debug_value == 0) /* no output */
  3341. return 0;
  3342. /* set low N bits */
  3343. return (1 << debug_value) - 1;
  3344. }
  3345. static inline void __netif_tx_lock(struct netdev_queue *txq, int cpu)
  3346. {
  3347. spin_lock(&txq->_xmit_lock);
  3348. txq->xmit_lock_owner = cpu;
  3349. }
  3350. static inline bool __netif_tx_acquire(struct netdev_queue *txq)
  3351. {
  3352. __acquire(&txq->_xmit_lock);
  3353. return true;
  3354. }
  3355. static inline void __netif_tx_release(struct netdev_queue *txq)
  3356. {
  3357. __release(&txq->_xmit_lock);
  3358. }
  3359. static inline void __netif_tx_lock_bh(struct netdev_queue *txq)
  3360. {
  3361. spin_lock_bh(&txq->_xmit_lock);
  3362. txq->xmit_lock_owner = smp_processor_id();
  3363. }
  3364. static inline bool __netif_tx_trylock(struct netdev_queue *txq)
  3365. {
  3366. bool ok = spin_trylock(&txq->_xmit_lock);
  3367. if (likely(ok))
  3368. txq->xmit_lock_owner = smp_processor_id();
  3369. return ok;
  3370. }
  3371. static inline void __netif_tx_unlock(struct netdev_queue *txq)
  3372. {
  3373. txq->xmit_lock_owner = -1;
  3374. spin_unlock(&txq->_xmit_lock);
  3375. }
  3376. static inline void __netif_tx_unlock_bh(struct netdev_queue *txq)
  3377. {
  3378. txq->xmit_lock_owner = -1;
  3379. spin_unlock_bh(&txq->_xmit_lock);
  3380. }
  3381. static inline void txq_trans_update(struct netdev_queue *txq)
  3382. {
  3383. if (txq->xmit_lock_owner != -1)
  3384. txq->trans_start = jiffies;
  3385. }
  3386. /* legacy drivers only, netdev_start_xmit() sets txq->trans_start */
  3387. static inline void netif_trans_update(struct net_device *dev)
  3388. {
  3389. struct netdev_queue *txq = netdev_get_tx_queue(dev, 0);
  3390. if (txq->trans_start != jiffies)
  3391. txq->trans_start = jiffies;
  3392. }
  3393. /**
  3394. * netif_tx_lock - grab network device transmit lock
  3395. * @dev: network device
  3396. *
  3397. * Get network device transmit lock
  3398. */
  3399. static inline void netif_tx_lock(struct net_device *dev)
  3400. {
  3401. unsigned int i;
  3402. int cpu;
  3403. spin_lock(&dev->tx_global_lock);
  3404. cpu = smp_processor_id();
  3405. for (i = 0; i < dev->num_tx_queues; i++) {
  3406. struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
  3407. /* We are the only thread of execution doing a
  3408. * freeze, but we have to grab the _xmit_lock in
  3409. * order to synchronize with threads which are in
  3410. * the ->hard_start_xmit() handler and already
  3411. * checked the frozen bit.
  3412. */
  3413. __netif_tx_lock(txq, cpu);
  3414. set_bit(__QUEUE_STATE_FROZEN, &txq->state);
  3415. __netif_tx_unlock(txq);
  3416. }
  3417. }
  3418. static inline void netif_tx_lock_bh(struct net_device *dev)
  3419. {
  3420. local_bh_disable();
  3421. netif_tx_lock(dev);
  3422. }
  3423. static inline void netif_tx_unlock(struct net_device *dev)
  3424. {
  3425. unsigned int i;
  3426. for (i = 0; i < dev->num_tx_queues; i++) {
  3427. struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
  3428. /* No need to grab the _xmit_lock here. If the
  3429. * queue is not stopped for another reason, we
  3430. * force a schedule.
  3431. */
  3432. clear_bit(__QUEUE_STATE_FROZEN, &txq->state);
  3433. netif_schedule_queue(txq);
  3434. }
  3435. spin_unlock(&dev->tx_global_lock);
  3436. }
  3437. static inline void netif_tx_unlock_bh(struct net_device *dev)
  3438. {
  3439. netif_tx_unlock(dev);
  3440. local_bh_enable();
  3441. }
  3442. #define HARD_TX_LOCK(dev, txq, cpu) { \
  3443. if ((dev->features & NETIF_F_LLTX) == 0) { \
  3444. __netif_tx_lock(txq, cpu); \
  3445. } else { \
  3446. __netif_tx_acquire(txq); \
  3447. } \
  3448. }
  3449. #define HARD_TX_TRYLOCK(dev, txq) \
  3450. (((dev->features & NETIF_F_LLTX) == 0) ? \
  3451. __netif_tx_trylock(txq) : \
  3452. __netif_tx_acquire(txq))
  3453. #define HARD_TX_UNLOCK(dev, txq) { \
  3454. if ((dev->features & NETIF_F_LLTX) == 0) { \
  3455. __netif_tx_unlock(txq); \
  3456. } else { \
  3457. __netif_tx_release(txq); \
  3458. } \
  3459. }
  3460. static inline void netif_tx_disable(struct net_device *dev)
  3461. {
  3462. unsigned int i;
  3463. int cpu;
  3464. local_bh_disable();
  3465. cpu = smp_processor_id();
  3466. for (i = 0; i < dev->num_tx_queues; i++) {
  3467. struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
  3468. __netif_tx_lock(txq, cpu);
  3469. netif_tx_stop_queue(txq);
  3470. __netif_tx_unlock(txq);
  3471. }
  3472. local_bh_enable();
  3473. }
  3474. static inline void netif_addr_lock(struct net_device *dev)
  3475. {
  3476. spin_lock(&dev->addr_list_lock);
  3477. }
  3478. static inline void netif_addr_lock_nested(struct net_device *dev)
  3479. {
  3480. int subclass = SINGLE_DEPTH_NESTING;
  3481. if (dev->netdev_ops->ndo_get_lock_subclass)
  3482. subclass = dev->netdev_ops->ndo_get_lock_subclass(dev);
  3483. spin_lock_nested(&dev->addr_list_lock, subclass);
  3484. }
  3485. static inline void netif_addr_lock_bh(struct net_device *dev)
  3486. {
  3487. spin_lock_bh(&dev->addr_list_lock);
  3488. }
  3489. static inline void netif_addr_unlock(struct net_device *dev)
  3490. {
  3491. spin_unlock(&dev->addr_list_lock);
  3492. }
  3493. static inline void netif_addr_unlock_bh(struct net_device *dev)
  3494. {
  3495. spin_unlock_bh(&dev->addr_list_lock);
  3496. }
  3497. /*
  3498. * dev_addrs walker. Should be used only for read access. Call with
  3499. * rcu_read_lock held.
  3500. */
  3501. #define for_each_dev_addr(dev, ha) \
  3502. list_for_each_entry_rcu(ha, &dev->dev_addrs.list, list)
  3503. /* These functions live elsewhere (drivers/net/net_init.c, but related) */
  3504. void ether_setup(struct net_device *dev);
  3505. /* Support for loadable net-drivers */
  3506. struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name,
  3507. unsigned char name_assign_type,
  3508. void (*setup)(struct net_device *),
  3509. unsigned int txqs, unsigned int rxqs);
  3510. int dev_get_valid_name(struct net *net, struct net_device *dev,
  3511. const char *name);
  3512. #define alloc_netdev(sizeof_priv, name, name_assign_type, setup) \
  3513. alloc_netdev_mqs(sizeof_priv, name, name_assign_type, setup, 1, 1)
  3514. #define alloc_netdev_mq(sizeof_priv, name, name_assign_type, setup, count) \
  3515. alloc_netdev_mqs(sizeof_priv, name, name_assign_type, setup, count, \
  3516. count)
  3517. int register_netdev(struct net_device *dev);
  3518. void unregister_netdev(struct net_device *dev);
  3519. /* General hardware address lists handling functions */
  3520. int __hw_addr_sync(struct netdev_hw_addr_list *to_list,
  3521. struct netdev_hw_addr_list *from_list, int addr_len);
  3522. void __hw_addr_unsync(struct netdev_hw_addr_list *to_list,
  3523. struct netdev_hw_addr_list *from_list, int addr_len);
  3524. int __hw_addr_sync_dev(struct netdev_hw_addr_list *list,
  3525. struct net_device *dev,
  3526. int (*sync)(struct net_device *, const unsigned char *),
  3527. int (*unsync)(struct net_device *,
  3528. const unsigned char *));
  3529. void __hw_addr_unsync_dev(struct netdev_hw_addr_list *list,
  3530. struct net_device *dev,
  3531. int (*unsync)(struct net_device *,
  3532. const unsigned char *));
  3533. void __hw_addr_init(struct netdev_hw_addr_list *list);
  3534. /* Functions used for device addresses handling */
  3535. int dev_addr_add(struct net_device *dev, const unsigned char *addr,
  3536. unsigned char addr_type);
  3537. int dev_addr_del(struct net_device *dev, const unsigned char *addr,
  3538. unsigned char addr_type);
  3539. void dev_addr_flush(struct net_device *dev);
  3540. int dev_addr_init(struct net_device *dev);
  3541. /* Functions used for unicast addresses handling */
  3542. int dev_uc_add(struct net_device *dev, const unsigned char *addr);
  3543. int dev_uc_add_excl(struct net_device *dev, const unsigned char *addr);
  3544. int dev_uc_del(struct net_device *dev, const unsigned char *addr);
  3545. int dev_uc_sync(struct net_device *to, struct net_device *from);
  3546. int dev_uc_sync_multiple(struct net_device *to, struct net_device *from);
  3547. void dev_uc_unsync(struct net_device *to, struct net_device *from);
  3548. void dev_uc_flush(struct net_device *dev);
  3549. void dev_uc_init(struct net_device *dev);
  3550. /**
  3551. * __dev_uc_sync - Synchonize device's unicast list
  3552. * @dev: device to sync
  3553. * @sync: function to call if address should be added
  3554. * @unsync: function to call if address should be removed
  3555. *
  3556. * Add newly added addresses to the interface, and release
  3557. * addresses that have been deleted.
  3558. */
  3559. static inline int __dev_uc_sync(struct net_device *dev,
  3560. int (*sync)(struct net_device *,
  3561. const unsigned char *),
  3562. int (*unsync)(struct net_device *,
  3563. const unsigned char *))
  3564. {
  3565. return __hw_addr_sync_dev(&dev->uc, dev, sync, unsync);
  3566. }
  3567. /**
  3568. * __dev_uc_unsync - Remove synchronized addresses from device
  3569. * @dev: device to sync
  3570. * @unsync: function to call if address should be removed
  3571. *
  3572. * Remove all addresses that were added to the device by dev_uc_sync().
  3573. */
  3574. static inline void __dev_uc_unsync(struct net_device *dev,
  3575. int (*unsync)(struct net_device *,
  3576. const unsigned char *))
  3577. {
  3578. __hw_addr_unsync_dev(&dev->uc, dev, unsync);
  3579. }
  3580. /* Functions used for multicast addresses handling */
  3581. int dev_mc_add(struct net_device *dev, const unsigned char *addr);
  3582. int dev_mc_add_global(struct net_device *dev, const unsigned char *addr);
  3583. int dev_mc_add_excl(struct net_device *dev, const unsigned char *addr);
  3584. int dev_mc_del(struct net_device *dev, const unsigned char *addr);
  3585. int dev_mc_del_global(struct net_device *dev, const unsigned char *addr);
  3586. int dev_mc_sync(struct net_device *to, struct net_device *from);
  3587. int dev_mc_sync_multiple(struct net_device *to, struct net_device *from);
  3588. void dev_mc_unsync(struct net_device *to, struct net_device *from);
  3589. void dev_mc_flush(struct net_device *dev);
  3590. void dev_mc_init(struct net_device *dev);
  3591. /**
  3592. * __dev_mc_sync - Synchonize device's multicast list
  3593. * @dev: device to sync
  3594. * @sync: function to call if address should be added
  3595. * @unsync: function to call if address should be removed
  3596. *
  3597. * Add newly added addresses to the interface, and release
  3598. * addresses that have been deleted.
  3599. */
  3600. static inline int __dev_mc_sync(struct net_device *dev,
  3601. int (*sync)(struct net_device *,
  3602. const unsigned char *),
  3603. int (*unsync)(struct net_device *,
  3604. const unsigned char *))
  3605. {
  3606. return __hw_addr_sync_dev(&dev->mc, dev, sync, unsync);
  3607. }
  3608. /**
  3609. * __dev_mc_unsync - Remove synchronized addresses from device
  3610. * @dev: device to sync
  3611. * @unsync: function to call if address should be removed
  3612. *
  3613. * Remove all addresses that were added to the device by dev_mc_sync().
  3614. */
  3615. static inline void __dev_mc_unsync(struct net_device *dev,
  3616. int (*unsync)(struct net_device *,
  3617. const unsigned char *))
  3618. {
  3619. __hw_addr_unsync_dev(&dev->mc, dev, unsync);
  3620. }
  3621. /* Functions used for secondary unicast and multicast support */
  3622. void dev_set_rx_mode(struct net_device *dev);
  3623. void __dev_set_rx_mode(struct net_device *dev);
  3624. int dev_set_promiscuity(struct net_device *dev, int inc);
  3625. int dev_set_allmulti(struct net_device *dev, int inc);
  3626. void netdev_state_change(struct net_device *dev);
  3627. void netdev_notify_peers(struct net_device *dev);
  3628. void netdev_features_change(struct net_device *dev);
  3629. /* Load a device via the kmod */
  3630. void dev_load(struct net *net, const char *name);
  3631. struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
  3632. struct rtnl_link_stats64 *storage);
  3633. void netdev_stats_to_stats64(struct rtnl_link_stats64 *stats64,
  3634. const struct net_device_stats *netdev_stats);
  3635. extern int netdev_max_backlog;
  3636. extern int netdev_tstamp_prequeue;
  3637. extern int weight_p;
  3638. extern int dev_weight_rx_bias;
  3639. extern int dev_weight_tx_bias;
  3640. extern int dev_rx_weight;
  3641. extern int dev_tx_weight;
  3642. bool netdev_has_upper_dev(struct net_device *dev, struct net_device *upper_dev);
  3643. struct net_device *netdev_upper_get_next_dev_rcu(struct net_device *dev,
  3644. struct list_head **iter);
  3645. struct net_device *netdev_all_upper_get_next_dev_rcu(struct net_device *dev,
  3646. struct list_head **iter);
  3647. /* iterate through upper list, must be called under RCU read lock */
  3648. #define netdev_for_each_upper_dev_rcu(dev, updev, iter) \
  3649. for (iter = &(dev)->adj_list.upper, \
  3650. updev = netdev_upper_get_next_dev_rcu(dev, &(iter)); \
  3651. updev; \
  3652. updev = netdev_upper_get_next_dev_rcu(dev, &(iter)))
  3653. int netdev_walk_all_upper_dev_rcu(struct net_device *dev,
  3654. int (*fn)(struct net_device *upper_dev,
  3655. void *data),
  3656. void *data);
  3657. bool netdev_has_upper_dev_all_rcu(struct net_device *dev,
  3658. struct net_device *upper_dev);
  3659. bool netdev_has_any_upper_dev(struct net_device *dev);
  3660. void *netdev_lower_get_next_private(struct net_device *dev,
  3661. struct list_head **iter);
  3662. void *netdev_lower_get_next_private_rcu(struct net_device *dev,
  3663. struct list_head **iter);
  3664. #define netdev_for_each_lower_private(dev, priv, iter) \
  3665. for (iter = (dev)->adj_list.lower.next, \
  3666. priv = netdev_lower_get_next_private(dev, &(iter)); \
  3667. priv; \
  3668. priv = netdev_lower_get_next_private(dev, &(iter)))
  3669. #define netdev_for_each_lower_private_rcu(dev, priv, iter) \
  3670. for (iter = &(dev)->adj_list.lower, \
  3671. priv = netdev_lower_get_next_private_rcu(dev, &(iter)); \
  3672. priv; \
  3673. priv = netdev_lower_get_next_private_rcu(dev, &(iter)))
  3674. void *netdev_lower_get_next(struct net_device *dev,
  3675. struct list_head **iter);
  3676. #define netdev_for_each_lower_dev(dev, ldev, iter) \
  3677. for (iter = (dev)->adj_list.lower.next, \
  3678. ldev = netdev_lower_get_next(dev, &(iter)); \
  3679. ldev; \
  3680. ldev = netdev_lower_get_next(dev, &(iter)))
  3681. struct net_device *netdev_all_lower_get_next(struct net_device *dev,
  3682. struct list_head **iter);
  3683. struct net_device *netdev_all_lower_get_next_rcu(struct net_device *dev,
  3684. struct list_head **iter);
  3685. int netdev_walk_all_lower_dev(struct net_device *dev,
  3686. int (*fn)(struct net_device *lower_dev,
  3687. void *data),
  3688. void *data);
  3689. int netdev_walk_all_lower_dev_rcu(struct net_device *dev,
  3690. int (*fn)(struct net_device *lower_dev,
  3691. void *data),
  3692. void *data);
  3693. void *netdev_adjacent_get_private(struct list_head *adj_list);
  3694. void *netdev_lower_get_first_private_rcu(struct net_device *dev);
  3695. struct net_device *netdev_master_upper_dev_get(struct net_device *dev);
  3696. struct net_device *netdev_master_upper_dev_get_rcu(struct net_device *dev);
  3697. int netdev_upper_dev_link(struct net_device *dev, struct net_device *upper_dev,
  3698. struct netlink_ext_ack *extack);
  3699. int netdev_master_upper_dev_link(struct net_device *dev,
  3700. struct net_device *upper_dev,
  3701. void *upper_priv, void *upper_info,
  3702. struct netlink_ext_ack *extack);
  3703. void netdev_upper_dev_unlink(struct net_device *dev,
  3704. struct net_device *upper_dev);
  3705. void netdev_adjacent_rename_links(struct net_device *dev, char *oldname);
  3706. void *netdev_lower_dev_get_private(struct net_device *dev,
  3707. struct net_device *lower_dev);
  3708. void netdev_lower_state_changed(struct net_device *lower_dev,
  3709. void *lower_state_info);
  3710. /* RSS keys are 40 or 52 bytes long */
  3711. #define NETDEV_RSS_KEY_LEN 52
  3712. extern u8 netdev_rss_key[NETDEV_RSS_KEY_LEN] __read_mostly;
  3713. void netdev_rss_key_fill(void *buffer, size_t len);
  3714. int dev_get_nest_level(struct net_device *dev);
  3715. int skb_checksum_help(struct sk_buff *skb);
  3716. int skb_crc32c_csum_help(struct sk_buff *skb);
  3717. int skb_csum_hwoffload_help(struct sk_buff *skb,
  3718. const netdev_features_t features);
  3719. struct sk_buff *__skb_gso_segment(struct sk_buff *skb,
  3720. netdev_features_t features, bool tx_path);
  3721. struct sk_buff *skb_mac_gso_segment(struct sk_buff *skb,
  3722. netdev_features_t features);
  3723. struct netdev_bonding_info {
  3724. ifslave slave;
  3725. ifbond master;
  3726. };
  3727. struct netdev_notifier_bonding_info {
  3728. struct netdev_notifier_info info; /* must be first */
  3729. struct netdev_bonding_info bonding_info;
  3730. };
  3731. void netdev_bonding_info_change(struct net_device *dev,
  3732. struct netdev_bonding_info *bonding_info);
  3733. static inline
  3734. struct sk_buff *skb_gso_segment(struct sk_buff *skb, netdev_features_t features)
  3735. {
  3736. return __skb_gso_segment(skb, features, true);
  3737. }
  3738. __be16 skb_network_protocol(struct sk_buff *skb, int *depth);
  3739. static inline bool can_checksum_protocol(netdev_features_t features,
  3740. __be16 protocol)
  3741. {
  3742. if (protocol == htons(ETH_P_FCOE))
  3743. return !!(features & NETIF_F_FCOE_CRC);
  3744. /* Assume this is an IP checksum (not SCTP CRC) */
  3745. if (features & NETIF_F_HW_CSUM) {
  3746. /* Can checksum everything */
  3747. return true;
  3748. }
  3749. switch (protocol) {
  3750. case htons(ETH_P_IP):
  3751. return !!(features & NETIF_F_IP_CSUM);
  3752. case htons(ETH_P_IPV6):
  3753. return !!(features & NETIF_F_IPV6_CSUM);
  3754. default:
  3755. return false;
  3756. }
  3757. }
  3758. #ifdef CONFIG_BUG
  3759. void netdev_rx_csum_fault(struct net_device *dev);
  3760. #else
  3761. static inline void netdev_rx_csum_fault(struct net_device *dev)
  3762. {
  3763. }
  3764. #endif
  3765. /* rx skb timestamps */
  3766. void net_enable_timestamp(void);
  3767. void net_disable_timestamp(void);
  3768. #ifdef CONFIG_PROC_FS
  3769. int __init dev_proc_init(void);
  3770. #else
  3771. #define dev_proc_init() 0
  3772. #endif
  3773. static inline netdev_tx_t __netdev_start_xmit(const struct net_device_ops *ops,
  3774. struct sk_buff *skb, struct net_device *dev,
  3775. bool more)
  3776. {
  3777. skb->xmit_more = more ? 1 : 0;
  3778. return ops->ndo_start_xmit(skb, dev);
  3779. }
  3780. static inline netdev_tx_t netdev_start_xmit(struct sk_buff *skb, struct net_device *dev,
  3781. struct netdev_queue *txq, bool more)
  3782. {
  3783. const struct net_device_ops *ops = dev->netdev_ops;
  3784. int rc;
  3785. rc = __netdev_start_xmit(ops, skb, dev, more);
  3786. if (rc == NETDEV_TX_OK)
  3787. txq_trans_update(txq);
  3788. return rc;
  3789. }
  3790. int netdev_class_create_file_ns(const struct class_attribute *class_attr,
  3791. const void *ns);
  3792. void netdev_class_remove_file_ns(const struct class_attribute *class_attr,
  3793. const void *ns);
  3794. static inline int netdev_class_create_file(const struct class_attribute *class_attr)
  3795. {
  3796. return netdev_class_create_file_ns(class_attr, NULL);
  3797. }
  3798. static inline void netdev_class_remove_file(const struct class_attribute *class_attr)
  3799. {
  3800. netdev_class_remove_file_ns(class_attr, NULL);
  3801. }
  3802. extern const struct kobj_ns_type_operations net_ns_type_operations;
  3803. const char *netdev_drivername(const struct net_device *dev);
  3804. void linkwatch_run_queue(void);
  3805. static inline netdev_features_t netdev_intersect_features(netdev_features_t f1,
  3806. netdev_features_t f2)
  3807. {
  3808. if ((f1 ^ f2) & NETIF_F_HW_CSUM) {
  3809. if (f1 & NETIF_F_HW_CSUM)
  3810. f1 |= (NETIF_F_IP_CSUM|NETIF_F_IPV6_CSUM);
  3811. else
  3812. f2 |= (NETIF_F_IP_CSUM|NETIF_F_IPV6_CSUM);
  3813. }
  3814. return f1 & f2;
  3815. }
  3816. static inline netdev_features_t netdev_get_wanted_features(
  3817. struct net_device *dev)
  3818. {
  3819. return (dev->features & ~dev->hw_features) | dev->wanted_features;
  3820. }
  3821. netdev_features_t netdev_increment_features(netdev_features_t all,
  3822. netdev_features_t one, netdev_features_t mask);
  3823. /* Allow TSO being used on stacked device :
  3824. * Performing the GSO segmentation before last device
  3825. * is a performance improvement.
  3826. */
  3827. static inline netdev_features_t netdev_add_tso_features(netdev_features_t features,
  3828. netdev_features_t mask)
  3829. {
  3830. return netdev_increment_features(features, NETIF_F_ALL_TSO, mask);
  3831. }
  3832. int __netdev_update_features(struct net_device *dev);
  3833. void netdev_update_features(struct net_device *dev);
  3834. void netdev_change_features(struct net_device *dev);
  3835. void netif_stacked_transfer_operstate(const struct net_device *rootdev,
  3836. struct net_device *dev);
  3837. netdev_features_t passthru_features_check(struct sk_buff *skb,
  3838. struct net_device *dev,
  3839. netdev_features_t features);
  3840. netdev_features_t netif_skb_features(struct sk_buff *skb);
  3841. static inline bool net_gso_ok(netdev_features_t features, int gso_type)
  3842. {
  3843. netdev_features_t feature = (netdev_features_t)gso_type << NETIF_F_GSO_SHIFT;
  3844. /* check flags correspondence */
  3845. BUILD_BUG_ON(SKB_GSO_TCPV4 != (NETIF_F_TSO >> NETIF_F_GSO_SHIFT));
  3846. BUILD_BUG_ON(SKB_GSO_DODGY != (NETIF_F_GSO_ROBUST >> NETIF_F_GSO_SHIFT));
  3847. BUILD_BUG_ON(SKB_GSO_TCP_ECN != (NETIF_F_TSO_ECN >> NETIF_F_GSO_SHIFT));
  3848. BUILD_BUG_ON(SKB_GSO_TCP_FIXEDID != (NETIF_F_TSO_MANGLEID >> NETIF_F_GSO_SHIFT));
  3849. BUILD_BUG_ON(SKB_GSO_TCPV6 != (NETIF_F_TSO6 >> NETIF_F_GSO_SHIFT));
  3850. BUILD_BUG_ON(SKB_GSO_FCOE != (NETIF_F_FSO >> NETIF_F_GSO_SHIFT));
  3851. BUILD_BUG_ON(SKB_GSO_GRE != (NETIF_F_GSO_GRE >> NETIF_F_GSO_SHIFT));
  3852. BUILD_BUG_ON(SKB_GSO_GRE_CSUM != (NETIF_F_GSO_GRE_CSUM >> NETIF_F_GSO_SHIFT));
  3853. BUILD_BUG_ON(SKB_GSO_IPXIP4 != (NETIF_F_GSO_IPXIP4 >> NETIF_F_GSO_SHIFT));
  3854. BUILD_BUG_ON(SKB_GSO_IPXIP6 != (NETIF_F_GSO_IPXIP6 >> NETIF_F_GSO_SHIFT));
  3855. BUILD_BUG_ON(SKB_GSO_UDP_TUNNEL != (NETIF_F_GSO_UDP_TUNNEL >> NETIF_F_GSO_SHIFT));
  3856. BUILD_BUG_ON(SKB_GSO_UDP_TUNNEL_CSUM != (NETIF_F_GSO_UDP_TUNNEL_CSUM >> NETIF_F_GSO_SHIFT));
  3857. BUILD_BUG_ON(SKB_GSO_PARTIAL != (NETIF_F_GSO_PARTIAL >> NETIF_F_GSO_SHIFT));
  3858. BUILD_BUG_ON(SKB_GSO_TUNNEL_REMCSUM != (NETIF_F_GSO_TUNNEL_REMCSUM >> NETIF_F_GSO_SHIFT));
  3859. BUILD_BUG_ON(SKB_GSO_SCTP != (NETIF_F_GSO_SCTP >> NETIF_F_GSO_SHIFT));
  3860. BUILD_BUG_ON(SKB_GSO_ESP != (NETIF_F_GSO_ESP >> NETIF_F_GSO_SHIFT));
  3861. BUILD_BUG_ON(SKB_GSO_UDP != (NETIF_F_GSO_UDP >> NETIF_F_GSO_SHIFT));
  3862. BUILD_BUG_ON(SKB_GSO_UDP_L4 != (NETIF_F_GSO_UDP_L4 >> NETIF_F_GSO_SHIFT));
  3863. return (features & feature) == feature;
  3864. }
  3865. static inline bool skb_gso_ok(struct sk_buff *skb, netdev_features_t features)
  3866. {
  3867. return net_gso_ok(features, skb_shinfo(skb)->gso_type) &&
  3868. (!skb_has_frag_list(skb) || (features & NETIF_F_FRAGLIST));
  3869. }
  3870. static inline bool netif_needs_gso(struct sk_buff *skb,
  3871. netdev_features_t features)
  3872. {
  3873. return skb_is_gso(skb) && (!skb_gso_ok(skb, features) ||
  3874. unlikely((skb->ip_summed != CHECKSUM_PARTIAL) &&
  3875. (skb->ip_summed != CHECKSUM_UNNECESSARY)));
  3876. }
  3877. static inline void netif_set_gso_max_size(struct net_device *dev,
  3878. unsigned int size)
  3879. {
  3880. dev->gso_max_size = size;
  3881. }
  3882. static inline void skb_gso_error_unwind(struct sk_buff *skb, __be16 protocol,
  3883. int pulled_hlen, u16 mac_offset,
  3884. int mac_len)
  3885. {
  3886. skb->protocol = protocol;
  3887. skb->encapsulation = 1;
  3888. skb_push(skb, pulled_hlen);
  3889. skb_reset_transport_header(skb);
  3890. skb->mac_header = mac_offset;
  3891. skb->network_header = skb->mac_header + mac_len;
  3892. skb->mac_len = mac_len;
  3893. }
  3894. static inline bool netif_is_macsec(const struct net_device *dev)
  3895. {
  3896. return dev->priv_flags & IFF_MACSEC;
  3897. }
  3898. static inline bool netif_is_macvlan(const struct net_device *dev)
  3899. {
  3900. return dev->priv_flags & IFF_MACVLAN;
  3901. }
  3902. static inline bool netif_is_macvlan_port(const struct net_device *dev)
  3903. {
  3904. return dev->priv_flags & IFF_MACVLAN_PORT;
  3905. }
  3906. static inline bool netif_is_bond_master(const struct net_device *dev)
  3907. {
  3908. return dev->flags & IFF_MASTER && dev->priv_flags & IFF_BONDING;
  3909. }
  3910. static inline bool netif_is_bond_slave(const struct net_device *dev)
  3911. {
  3912. return dev->flags & IFF_SLAVE && dev->priv_flags & IFF_BONDING;
  3913. }
  3914. static inline bool netif_supports_nofcs(struct net_device *dev)
  3915. {
  3916. return dev->priv_flags & IFF_SUPP_NOFCS;
  3917. }
  3918. static inline bool netif_is_l3_master(const struct net_device *dev)
  3919. {
  3920. return dev->priv_flags & IFF_L3MDEV_MASTER;
  3921. }
  3922. static inline bool netif_is_l3_slave(const struct net_device *dev)
  3923. {
  3924. return dev->priv_flags & IFF_L3MDEV_SLAVE;
  3925. }
  3926. static inline bool netif_is_bridge_master(const struct net_device *dev)
  3927. {
  3928. return dev->priv_flags & IFF_EBRIDGE;
  3929. }
  3930. static inline bool netif_is_bridge_port(const struct net_device *dev)
  3931. {
  3932. return dev->priv_flags & IFF_BRIDGE_PORT;
  3933. }
  3934. static inline bool netif_is_ovs_master(const struct net_device *dev)
  3935. {
  3936. return dev->priv_flags & IFF_OPENVSWITCH;
  3937. }
  3938. static inline bool netif_is_ovs_port(const struct net_device *dev)
  3939. {
  3940. return dev->priv_flags & IFF_OVS_DATAPATH;
  3941. }
  3942. static inline bool netif_is_team_master(const struct net_device *dev)
  3943. {
  3944. return dev->priv_flags & IFF_TEAM;
  3945. }
  3946. static inline bool netif_is_team_port(const struct net_device *dev)
  3947. {
  3948. return dev->priv_flags & IFF_TEAM_PORT;
  3949. }
  3950. static inline bool netif_is_lag_master(const struct net_device *dev)
  3951. {
  3952. return netif_is_bond_master(dev) || netif_is_team_master(dev);
  3953. }
  3954. static inline bool netif_is_lag_port(const struct net_device *dev)
  3955. {
  3956. return netif_is_bond_slave(dev) || netif_is_team_port(dev);
  3957. }
  3958. static inline bool netif_is_rxfh_configured(const struct net_device *dev)
  3959. {
  3960. return dev->priv_flags & IFF_RXFH_CONFIGURED;
  3961. }
  3962. static inline bool netif_is_failover(const struct net_device *dev)
  3963. {
  3964. return dev->priv_flags & IFF_FAILOVER;
  3965. }
  3966. static inline bool netif_is_failover_slave(const struct net_device *dev)
  3967. {
  3968. return dev->priv_flags & IFF_FAILOVER_SLAVE;
  3969. }
  3970. /* This device needs to keep skb dst for qdisc enqueue or ndo_start_xmit() */
  3971. static inline void netif_keep_dst(struct net_device *dev)
  3972. {
  3973. dev->priv_flags &= ~(IFF_XMIT_DST_RELEASE | IFF_XMIT_DST_RELEASE_PERM);
  3974. }
  3975. /* return true if dev can't cope with mtu frames that need vlan tag insertion */
  3976. static inline bool netif_reduces_vlan_mtu(struct net_device *dev)
  3977. {
  3978. /* TODO: reserve and use an additional IFF bit, if we get more users */
  3979. return dev->priv_flags & IFF_MACSEC;
  3980. }
  3981. extern struct pernet_operations __net_initdata loopback_net_ops;
  3982. /* Logging, debugging and troubleshooting/diagnostic helpers. */
  3983. /* netdev_printk helpers, similar to dev_printk */
  3984. static inline const char *netdev_name(const struct net_device *dev)
  3985. {
  3986. if (!dev->name[0] || strchr(dev->name, '%'))
  3987. return "(unnamed net_device)";
  3988. return dev->name;
  3989. }
  3990. static inline bool netdev_unregistering(const struct net_device *dev)
  3991. {
  3992. return dev->reg_state == NETREG_UNREGISTERING;
  3993. }
  3994. static inline const char *netdev_reg_state(const struct net_device *dev)
  3995. {
  3996. switch (dev->reg_state) {
  3997. case NETREG_UNINITIALIZED: return " (uninitialized)";
  3998. case NETREG_REGISTERED: return "";
  3999. case NETREG_UNREGISTERING: return " (unregistering)";
  4000. case NETREG_UNREGISTERED: return " (unregistered)";
  4001. case NETREG_RELEASED: return " (released)";
  4002. case NETREG_DUMMY: return " (dummy)";
  4003. }
  4004. WARN_ONCE(1, "%s: unknown reg_state %d\n", dev->name, dev->reg_state);
  4005. return " (unknown)";
  4006. }
  4007. __printf(3, 4)
  4008. void netdev_printk(const char *level, const struct net_device *dev,
  4009. const char *format, ...);
  4010. __printf(2, 3)
  4011. void netdev_emerg(const struct net_device *dev, const char *format, ...);
  4012. __printf(2, 3)
  4013. void netdev_alert(const struct net_device *dev, const char *format, ...);
  4014. __printf(2, 3)
  4015. void netdev_crit(const struct net_device *dev, const char *format, ...);
  4016. __printf(2, 3)
  4017. void netdev_err(const struct net_device *dev, const char *format, ...);
  4018. __printf(2, 3)
  4019. void netdev_warn(const struct net_device *dev, const char *format, ...);
  4020. __printf(2, 3)
  4021. void netdev_notice(const struct net_device *dev, const char *format, ...);
  4022. __printf(2, 3)
  4023. void netdev_info(const struct net_device *dev, const char *format, ...);
  4024. #define netdev_level_once(level, dev, fmt, ...) \
  4025. do { \
  4026. static bool __print_once __read_mostly; \
  4027. \
  4028. if (!__print_once) { \
  4029. __print_once = true; \
  4030. netdev_printk(level, dev, fmt, ##__VA_ARGS__); \
  4031. } \
  4032. } while (0)
  4033. #define netdev_emerg_once(dev, fmt, ...) \
  4034. netdev_level_once(KERN_EMERG, dev, fmt, ##__VA_ARGS__)
  4035. #define netdev_alert_once(dev, fmt, ...) \
  4036. netdev_level_once(KERN_ALERT, dev, fmt, ##__VA_ARGS__)
  4037. #define netdev_crit_once(dev, fmt, ...) \
  4038. netdev_level_once(KERN_CRIT, dev, fmt, ##__VA_ARGS__)
  4039. #define netdev_err_once(dev, fmt, ...) \
  4040. netdev_level_once(KERN_ERR, dev, fmt, ##__VA_ARGS__)
  4041. #define netdev_warn_once(dev, fmt, ...) \
  4042. netdev_level_once(KERN_WARNING, dev, fmt, ##__VA_ARGS__)
  4043. #define netdev_notice_once(dev, fmt, ...) \
  4044. netdev_level_once(KERN_NOTICE, dev, fmt, ##__VA_ARGS__)
  4045. #define netdev_info_once(dev, fmt, ...) \
  4046. netdev_level_once(KERN_INFO, dev, fmt, ##__VA_ARGS__)
  4047. #define MODULE_ALIAS_NETDEV(device) \
  4048. MODULE_ALIAS("netdev-" device)
  4049. #if defined(CONFIG_DYNAMIC_DEBUG)
  4050. #define netdev_dbg(__dev, format, args...) \
  4051. do { \
  4052. dynamic_netdev_dbg(__dev, format, ##args); \
  4053. } while (0)
  4054. #elif defined(DEBUG)
  4055. #define netdev_dbg(__dev, format, args...) \
  4056. netdev_printk(KERN_DEBUG, __dev, format, ##args)
  4057. #else
  4058. #define netdev_dbg(__dev, format, args...) \
  4059. ({ \
  4060. if (0) \
  4061. netdev_printk(KERN_DEBUG, __dev, format, ##args); \
  4062. })
  4063. #endif
  4064. #if defined(VERBOSE_DEBUG)
  4065. #define netdev_vdbg netdev_dbg
  4066. #else
  4067. #define netdev_vdbg(dev, format, args...) \
  4068. ({ \
  4069. if (0) \
  4070. netdev_printk(KERN_DEBUG, dev, format, ##args); \
  4071. 0; \
  4072. })
  4073. #endif
  4074. /*
  4075. * netdev_WARN() acts like dev_printk(), but with the key difference
  4076. * of using a WARN/WARN_ON to get the message out, including the
  4077. * file/line information and a backtrace.
  4078. */
  4079. #define netdev_WARN(dev, format, args...) \
  4080. WARN(1, "netdevice: %s%s: " format, netdev_name(dev), \
  4081. netdev_reg_state(dev), ##args)
  4082. #define netdev_WARN_ONCE(dev, format, args...) \
  4083. WARN_ONCE(1, "netdevice: %s%s: " format, netdev_name(dev), \
  4084. netdev_reg_state(dev), ##args)
  4085. /* netif printk helpers, similar to netdev_printk */
  4086. #define netif_printk(priv, type, level, dev, fmt, args...) \
  4087. do { \
  4088. if (netif_msg_##type(priv)) \
  4089. netdev_printk(level, (dev), fmt, ##args); \
  4090. } while (0)
  4091. #define netif_level(level, priv, type, dev, fmt, args...) \
  4092. do { \
  4093. if (netif_msg_##type(priv)) \
  4094. netdev_##level(dev, fmt, ##args); \
  4095. } while (0)
  4096. #define netif_emerg(priv, type, dev, fmt, args...) \
  4097. netif_level(emerg, priv, type, dev, fmt, ##args)
  4098. #define netif_alert(priv, type, dev, fmt, args...) \
  4099. netif_level(alert, priv, type, dev, fmt, ##args)
  4100. #define netif_crit(priv, type, dev, fmt, args...) \
  4101. netif_level(crit, priv, type, dev, fmt, ##args)
  4102. #define netif_err(priv, type, dev, fmt, args...) \
  4103. netif_level(err, priv, type, dev, fmt, ##args)
  4104. #define netif_warn(priv, type, dev, fmt, args...) \
  4105. netif_level(warn, priv, type, dev, fmt, ##args)
  4106. #define netif_notice(priv, type, dev, fmt, args...) \
  4107. netif_level(notice, priv, type, dev, fmt, ##args)
  4108. #define netif_info(priv, type, dev, fmt, args...) \
  4109. netif_level(info, priv, type, dev, fmt, ##args)
  4110. #if defined(CONFIG_DYNAMIC_DEBUG)
  4111. #define netif_dbg(priv, type, netdev, format, args...) \
  4112. do { \
  4113. if (netif_msg_##type(priv)) \
  4114. dynamic_netdev_dbg(netdev, format, ##args); \
  4115. } while (0)
  4116. #elif defined(DEBUG)
  4117. #define netif_dbg(priv, type, dev, format, args...) \
  4118. netif_printk(priv, type, KERN_DEBUG, dev, format, ##args)
  4119. #else
  4120. #define netif_dbg(priv, type, dev, format, args...) \
  4121. ({ \
  4122. if (0) \
  4123. netif_printk(priv, type, KERN_DEBUG, dev, format, ##args); \
  4124. 0; \
  4125. })
  4126. #endif
  4127. /* if @cond then downgrade to debug, else print at @level */
  4128. #define netif_cond_dbg(priv, type, netdev, cond, level, fmt, args...) \
  4129. do { \
  4130. if (cond) \
  4131. netif_dbg(priv, type, netdev, fmt, ##args); \
  4132. else \
  4133. netif_ ## level(priv, type, netdev, fmt, ##args); \
  4134. } while (0)
  4135. #if defined(VERBOSE_DEBUG)
  4136. #define netif_vdbg netif_dbg
  4137. #else
  4138. #define netif_vdbg(priv, type, dev, format, args...) \
  4139. ({ \
  4140. if (0) \
  4141. netif_printk(priv, type, KERN_DEBUG, dev, format, ##args); \
  4142. 0; \
  4143. })
  4144. #endif
  4145. /*
  4146. * The list of packet types we will receive (as opposed to discard)
  4147. * and the routines to invoke.
  4148. *
  4149. * Why 16. Because with 16 the only overlap we get on a hash of the
  4150. * low nibble of the protocol value is RARP/SNAP/X.25.
  4151. *
  4152. * 0800 IP
  4153. * 0001 802.3
  4154. * 0002 AX.25
  4155. * 0004 802.2
  4156. * 8035 RARP
  4157. * 0005 SNAP
  4158. * 0805 X.25
  4159. * 0806 ARP
  4160. * 8137 IPX
  4161. * 0009 Localtalk
  4162. * 86DD IPv6
  4163. */
  4164. #define PTYPE_HASH_SIZE (16)
  4165. #define PTYPE_HASH_MASK (PTYPE_HASH_SIZE - 1)
  4166. #endif /* _LINUX_NETDEVICE_H */