netdevice.h 144 KB

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