netdevice.h 116 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812
  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/pm_qos.h>
  28. #include <linux/timer.h>
  29. #include <linux/bug.h>
  30. #include <linux/delay.h>
  31. #include <linux/atomic.h>
  32. #include <linux/prefetch.h>
  33. #include <asm/cache.h>
  34. #include <asm/byteorder.h>
  35. #include <linux/percpu.h>
  36. #include <linux/rculist.h>
  37. #include <linux/dmaengine.h>
  38. #include <linux/workqueue.h>
  39. #include <linux/dynamic_queue_limits.h>
  40. #include <linux/ethtool.h>
  41. #include <net/net_namespace.h>
  42. #include <net/dsa.h>
  43. #ifdef CONFIG_DCB
  44. #include <net/dcbnl.h>
  45. #endif
  46. #include <net/netprio_cgroup.h>
  47. #include <linux/netdev_features.h>
  48. #include <linux/neighbour.h>
  49. #include <uapi/linux/netdevice.h>
  50. struct netpoll_info;
  51. struct device;
  52. struct phy_device;
  53. /* 802.11 specific */
  54. struct wireless_dev;
  55. void netdev_set_default_ethtool_ops(struct net_device *dev,
  56. const struct ethtool_ops *ops);
  57. /* Backlog congestion levels */
  58. #define NET_RX_SUCCESS 0 /* keep 'em coming, baby */
  59. #define NET_RX_DROP 1 /* packet dropped */
  60. /*
  61. * Transmit return codes: transmit return codes originate from three different
  62. * namespaces:
  63. *
  64. * - qdisc return codes
  65. * - driver transmit return codes
  66. * - errno values
  67. *
  68. * Drivers are allowed to return any one of those in their hard_start_xmit()
  69. * function. Real network devices commonly used with qdiscs should only return
  70. * the driver transmit return codes though - when qdiscs are used, the actual
  71. * transmission happens asynchronously, so the value is not propagated to
  72. * higher layers. Virtual network devices transmit synchronously, in this case
  73. * the driver transmit return codes are consumed by dev_queue_xmit(), all
  74. * others are propagated to higher layers.
  75. */
  76. /* qdisc ->enqueue() return codes. */
  77. #define NET_XMIT_SUCCESS 0x00
  78. #define NET_XMIT_DROP 0x01 /* skb dropped */
  79. #define NET_XMIT_CN 0x02 /* congestion notification */
  80. #define NET_XMIT_POLICED 0x03 /* skb is shot by police */
  81. #define NET_XMIT_MASK 0x0f /* qdisc flags in net/sch_generic.h */
  82. /* NET_XMIT_CN is special. It does not guarantee that this packet is lost. It
  83. * indicates that the device will soon be dropping packets, or already drops
  84. * some packets of the same priority; prompting us to send less aggressively. */
  85. #define net_xmit_eval(e) ((e) == NET_XMIT_CN ? 0 : (e))
  86. #define net_xmit_errno(e) ((e) != NET_XMIT_CN ? -ENOBUFS : 0)
  87. /* Driver transmit return codes */
  88. #define NETDEV_TX_MASK 0xf0
  89. enum netdev_tx {
  90. __NETDEV_TX_MIN = INT_MIN, /* make sure enum is signed */
  91. NETDEV_TX_OK = 0x00, /* driver took care of packet */
  92. NETDEV_TX_BUSY = 0x10, /* driver tx path was busy*/
  93. NETDEV_TX_LOCKED = 0x20, /* driver tx lock was already taken */
  94. };
  95. typedef enum netdev_tx netdev_tx_t;
  96. /*
  97. * Current order: NETDEV_TX_MASK > NET_XMIT_MASK >= 0 is significant;
  98. * hard_start_xmit() return < NET_XMIT_MASK means skb was consumed.
  99. */
  100. static inline bool dev_xmit_complete(int rc)
  101. {
  102. /*
  103. * Positive cases with an skb consumed by a driver:
  104. * - successful transmission (rc == NETDEV_TX_OK)
  105. * - error while transmitting (rc < 0)
  106. * - error while queueing to a different device (rc & NET_XMIT_MASK)
  107. */
  108. if (likely(rc < NET_XMIT_MASK))
  109. return true;
  110. return false;
  111. }
  112. /*
  113. * Compute the worst case header length according to the protocols
  114. * used.
  115. */
  116. #if defined(CONFIG_WLAN) || IS_ENABLED(CONFIG_AX25)
  117. # if defined(CONFIG_MAC80211_MESH)
  118. # define LL_MAX_HEADER 128
  119. # else
  120. # define LL_MAX_HEADER 96
  121. # endif
  122. #else
  123. # define LL_MAX_HEADER 32
  124. #endif
  125. #if !IS_ENABLED(CONFIG_NET_IPIP) && !IS_ENABLED(CONFIG_NET_IPGRE) && \
  126. !IS_ENABLED(CONFIG_IPV6_SIT) && !IS_ENABLED(CONFIG_IPV6_TUNNEL)
  127. #define MAX_HEADER LL_MAX_HEADER
  128. #else
  129. #define MAX_HEADER (LL_MAX_HEADER + 48)
  130. #endif
  131. /*
  132. * Old network device statistics. Fields are native words
  133. * (unsigned long) so they can be read and written atomically.
  134. */
  135. struct net_device_stats {
  136. unsigned long rx_packets;
  137. unsigned long tx_packets;
  138. unsigned long rx_bytes;
  139. unsigned long tx_bytes;
  140. unsigned long rx_errors;
  141. unsigned long tx_errors;
  142. unsigned long rx_dropped;
  143. unsigned long tx_dropped;
  144. unsigned long multicast;
  145. unsigned long collisions;
  146. unsigned long rx_length_errors;
  147. unsigned long rx_over_errors;
  148. unsigned long rx_crc_errors;
  149. unsigned long rx_frame_errors;
  150. unsigned long rx_fifo_errors;
  151. unsigned long rx_missed_errors;
  152. unsigned long tx_aborted_errors;
  153. unsigned long tx_carrier_errors;
  154. unsigned long tx_fifo_errors;
  155. unsigned long tx_heartbeat_errors;
  156. unsigned long tx_window_errors;
  157. unsigned long rx_compressed;
  158. unsigned long tx_compressed;
  159. };
  160. #include <linux/cache.h>
  161. #include <linux/skbuff.h>
  162. #ifdef CONFIG_RPS
  163. #include <linux/static_key.h>
  164. extern struct static_key rps_needed;
  165. #endif
  166. struct neighbour;
  167. struct neigh_parms;
  168. struct sk_buff;
  169. struct netdev_hw_addr {
  170. struct list_head list;
  171. unsigned char addr[MAX_ADDR_LEN];
  172. unsigned char type;
  173. #define NETDEV_HW_ADDR_T_LAN 1
  174. #define NETDEV_HW_ADDR_T_SAN 2
  175. #define NETDEV_HW_ADDR_T_SLAVE 3
  176. #define NETDEV_HW_ADDR_T_UNICAST 4
  177. #define NETDEV_HW_ADDR_T_MULTICAST 5
  178. bool global_use;
  179. int sync_cnt;
  180. int refcount;
  181. int synced;
  182. struct rcu_head rcu_head;
  183. };
  184. struct netdev_hw_addr_list {
  185. struct list_head list;
  186. int count;
  187. };
  188. #define netdev_hw_addr_list_count(l) ((l)->count)
  189. #define netdev_hw_addr_list_empty(l) (netdev_hw_addr_list_count(l) == 0)
  190. #define netdev_hw_addr_list_for_each(ha, l) \
  191. list_for_each_entry(ha, &(l)->list, list)
  192. #define netdev_uc_count(dev) netdev_hw_addr_list_count(&(dev)->uc)
  193. #define netdev_uc_empty(dev) netdev_hw_addr_list_empty(&(dev)->uc)
  194. #define netdev_for_each_uc_addr(ha, dev) \
  195. netdev_hw_addr_list_for_each(ha, &(dev)->uc)
  196. #define netdev_mc_count(dev) netdev_hw_addr_list_count(&(dev)->mc)
  197. #define netdev_mc_empty(dev) netdev_hw_addr_list_empty(&(dev)->mc)
  198. #define netdev_for_each_mc_addr(ha, dev) \
  199. netdev_hw_addr_list_for_each(ha, &(dev)->mc)
  200. struct hh_cache {
  201. u16 hh_len;
  202. u16 __pad;
  203. seqlock_t hh_lock;
  204. /* cached hardware header; allow for machine alignment needs. */
  205. #define HH_DATA_MOD 16
  206. #define HH_DATA_OFF(__len) \
  207. (HH_DATA_MOD - (((__len - 1) & (HH_DATA_MOD - 1)) + 1))
  208. #define HH_DATA_ALIGN(__len) \
  209. (((__len)+(HH_DATA_MOD-1))&~(HH_DATA_MOD - 1))
  210. unsigned long hh_data[HH_DATA_ALIGN(LL_MAX_HEADER) / sizeof(long)];
  211. };
  212. /* Reserve HH_DATA_MOD byte aligned hard_header_len, but at least that much.
  213. * Alternative is:
  214. * dev->hard_header_len ? (dev->hard_header_len +
  215. * (HH_DATA_MOD - 1)) & ~(HH_DATA_MOD - 1) : 0
  216. *
  217. * We could use other alignment values, but we must maintain the
  218. * relationship HH alignment <= LL alignment.
  219. */
  220. #define LL_RESERVED_SPACE(dev) \
  221. ((((dev)->hard_header_len+(dev)->needed_headroom)&~(HH_DATA_MOD - 1)) + HH_DATA_MOD)
  222. #define LL_RESERVED_SPACE_EXTRA(dev,extra) \
  223. ((((dev)->hard_header_len+(dev)->needed_headroom+(extra))&~(HH_DATA_MOD - 1)) + HH_DATA_MOD)
  224. struct header_ops {
  225. int (*create) (struct sk_buff *skb, struct net_device *dev,
  226. unsigned short type, const void *daddr,
  227. const void *saddr, unsigned int len);
  228. int (*parse)(const struct sk_buff *skb, unsigned char *haddr);
  229. int (*rebuild)(struct sk_buff *skb);
  230. int (*cache)(const struct neighbour *neigh, struct hh_cache *hh, __be16 type);
  231. void (*cache_update)(struct hh_cache *hh,
  232. const struct net_device *dev,
  233. const unsigned char *haddr);
  234. };
  235. /* These flag bits are private to the generic network queueing
  236. * layer, they may not be explicitly referenced by any other
  237. * code.
  238. */
  239. enum netdev_state_t {
  240. __LINK_STATE_START,
  241. __LINK_STATE_PRESENT,
  242. __LINK_STATE_NOCARRIER,
  243. __LINK_STATE_LINKWATCH_PENDING,
  244. __LINK_STATE_DORMANT,
  245. };
  246. /*
  247. * This structure holds at boot time configured netdevice settings. They
  248. * are then used in the device probing.
  249. */
  250. struct netdev_boot_setup {
  251. char name[IFNAMSIZ];
  252. struct ifmap map;
  253. };
  254. #define NETDEV_BOOT_SETUP_MAX 8
  255. int __init netdev_boot_setup(char *str);
  256. /*
  257. * Structure for NAPI scheduling similar to tasklet but with weighting
  258. */
  259. struct napi_struct {
  260. /* The poll_list must only be managed by the entity which
  261. * changes the state of the NAPI_STATE_SCHED bit. This means
  262. * whoever atomically sets that bit can add this napi_struct
  263. * to the per-cpu poll_list, and whoever clears that bit
  264. * can remove from the list right before clearing the bit.
  265. */
  266. struct list_head poll_list;
  267. unsigned long state;
  268. int weight;
  269. unsigned int gro_count;
  270. int (*poll)(struct napi_struct *, int);
  271. #ifdef CONFIG_NETPOLL
  272. spinlock_t poll_lock;
  273. int poll_owner;
  274. #endif
  275. struct net_device *dev;
  276. struct sk_buff *gro_list;
  277. struct sk_buff *skb;
  278. struct list_head dev_list;
  279. struct hlist_node napi_hash_node;
  280. unsigned int napi_id;
  281. };
  282. enum {
  283. NAPI_STATE_SCHED, /* Poll is scheduled */
  284. NAPI_STATE_DISABLE, /* Disable pending */
  285. NAPI_STATE_NPSVC, /* Netpoll - don't dequeue from poll_list */
  286. NAPI_STATE_HASHED, /* In NAPI hash */
  287. };
  288. enum gro_result {
  289. GRO_MERGED,
  290. GRO_MERGED_FREE,
  291. GRO_HELD,
  292. GRO_NORMAL,
  293. GRO_DROP,
  294. };
  295. typedef enum gro_result gro_result_t;
  296. /*
  297. * enum rx_handler_result - Possible return values for rx_handlers.
  298. * @RX_HANDLER_CONSUMED: skb was consumed by rx_handler, do not process it
  299. * further.
  300. * @RX_HANDLER_ANOTHER: Do another round in receive path. This is indicated in
  301. * case skb->dev was changed by rx_handler.
  302. * @RX_HANDLER_EXACT: Force exact delivery, no wildcard.
  303. * @RX_HANDLER_PASS: Do nothing, passe the skb as if no rx_handler was called.
  304. *
  305. * rx_handlers are functions called from inside __netif_receive_skb(), to do
  306. * special processing of the skb, prior to delivery to protocol handlers.
  307. *
  308. * Currently, a net_device can only have a single rx_handler registered. Trying
  309. * to register a second rx_handler will return -EBUSY.
  310. *
  311. * To register a rx_handler on a net_device, use netdev_rx_handler_register().
  312. * To unregister a rx_handler on a net_device, use
  313. * netdev_rx_handler_unregister().
  314. *
  315. * Upon return, rx_handler is expected to tell __netif_receive_skb() what to
  316. * do with the skb.
  317. *
  318. * If the rx_handler consumed to skb in some way, it should return
  319. * RX_HANDLER_CONSUMED. This is appropriate when the rx_handler arranged for
  320. * the skb to be delivered in some other ways.
  321. *
  322. * If the rx_handler changed skb->dev, to divert the skb to another
  323. * net_device, it should return RX_HANDLER_ANOTHER. The rx_handler for the
  324. * new device will be called if it exists.
  325. *
  326. * If the rx_handler consider the skb should be ignored, it should return
  327. * RX_HANDLER_EXACT. The skb will only be delivered to protocol handlers that
  328. * are registered on exact device (ptype->dev == skb->dev).
  329. *
  330. * If the rx_handler didn't changed skb->dev, but want the skb to be normally
  331. * delivered, it should return RX_HANDLER_PASS.
  332. *
  333. * A device without a registered rx_handler will behave as if rx_handler
  334. * returned RX_HANDLER_PASS.
  335. */
  336. enum rx_handler_result {
  337. RX_HANDLER_CONSUMED,
  338. RX_HANDLER_ANOTHER,
  339. RX_HANDLER_EXACT,
  340. RX_HANDLER_PASS,
  341. };
  342. typedef enum rx_handler_result rx_handler_result_t;
  343. typedef rx_handler_result_t rx_handler_func_t(struct sk_buff **pskb);
  344. void __napi_schedule(struct napi_struct *n);
  345. static inline bool napi_disable_pending(struct napi_struct *n)
  346. {
  347. return test_bit(NAPI_STATE_DISABLE, &n->state);
  348. }
  349. /**
  350. * napi_schedule_prep - check if napi can be scheduled
  351. * @n: napi context
  352. *
  353. * Test if NAPI routine is already running, and if not mark
  354. * it as running. This is used as a condition variable
  355. * insure only one NAPI poll instance runs. We also make
  356. * sure there is no pending NAPI disable.
  357. */
  358. static inline bool napi_schedule_prep(struct napi_struct *n)
  359. {
  360. return !napi_disable_pending(n) &&
  361. !test_and_set_bit(NAPI_STATE_SCHED, &n->state);
  362. }
  363. /**
  364. * napi_schedule - schedule NAPI poll
  365. * @n: napi context
  366. *
  367. * Schedule NAPI poll routine to be called if it is not already
  368. * running.
  369. */
  370. static inline void napi_schedule(struct napi_struct *n)
  371. {
  372. if (napi_schedule_prep(n))
  373. __napi_schedule(n);
  374. }
  375. /* Try to reschedule poll. Called by dev->poll() after napi_complete(). */
  376. static inline bool napi_reschedule(struct napi_struct *napi)
  377. {
  378. if (napi_schedule_prep(napi)) {
  379. __napi_schedule(napi);
  380. return true;
  381. }
  382. return false;
  383. }
  384. /**
  385. * napi_complete - NAPI processing complete
  386. * @n: napi context
  387. *
  388. * Mark NAPI processing as complete.
  389. */
  390. void __napi_complete(struct napi_struct *n);
  391. void napi_complete(struct napi_struct *n);
  392. /**
  393. * napi_by_id - lookup a NAPI by napi_id
  394. * @napi_id: hashed napi_id
  395. *
  396. * lookup @napi_id in napi_hash table
  397. * must be called under rcu_read_lock()
  398. */
  399. struct napi_struct *napi_by_id(unsigned int napi_id);
  400. /**
  401. * napi_hash_add - add a NAPI to global hashtable
  402. * @napi: napi context
  403. *
  404. * generate a new napi_id and store a @napi under it in napi_hash
  405. */
  406. void napi_hash_add(struct napi_struct *napi);
  407. /**
  408. * napi_hash_del - remove a NAPI from global table
  409. * @napi: napi context
  410. *
  411. * Warning: caller must observe rcu grace period
  412. * before freeing memory containing @napi
  413. */
  414. void napi_hash_del(struct napi_struct *napi);
  415. /**
  416. * napi_disable - prevent NAPI from scheduling
  417. * @n: napi context
  418. *
  419. * Stop NAPI from being scheduled on this context.
  420. * Waits till any outstanding processing completes.
  421. */
  422. static inline void napi_disable(struct napi_struct *n)
  423. {
  424. might_sleep();
  425. set_bit(NAPI_STATE_DISABLE, &n->state);
  426. while (test_and_set_bit(NAPI_STATE_SCHED, &n->state))
  427. msleep(1);
  428. clear_bit(NAPI_STATE_DISABLE, &n->state);
  429. }
  430. /**
  431. * napi_enable - enable NAPI scheduling
  432. * @n: napi context
  433. *
  434. * Resume NAPI from being scheduled on this context.
  435. * Must be paired with napi_disable.
  436. */
  437. static inline void napi_enable(struct napi_struct *n)
  438. {
  439. BUG_ON(!test_bit(NAPI_STATE_SCHED, &n->state));
  440. smp_mb__before_atomic();
  441. clear_bit(NAPI_STATE_SCHED, &n->state);
  442. }
  443. #ifdef CONFIG_SMP
  444. /**
  445. * napi_synchronize - wait until NAPI is not running
  446. * @n: napi context
  447. *
  448. * Wait until NAPI is done being scheduled on this context.
  449. * Waits till any outstanding processing completes but
  450. * does not disable future activations.
  451. */
  452. static inline void napi_synchronize(const struct napi_struct *n)
  453. {
  454. while (test_bit(NAPI_STATE_SCHED, &n->state))
  455. msleep(1);
  456. }
  457. #else
  458. # define napi_synchronize(n) barrier()
  459. #endif
  460. enum netdev_queue_state_t {
  461. __QUEUE_STATE_DRV_XOFF,
  462. __QUEUE_STATE_STACK_XOFF,
  463. __QUEUE_STATE_FROZEN,
  464. };
  465. #define QUEUE_STATE_DRV_XOFF (1 << __QUEUE_STATE_DRV_XOFF)
  466. #define QUEUE_STATE_STACK_XOFF (1 << __QUEUE_STATE_STACK_XOFF)
  467. #define QUEUE_STATE_FROZEN (1 << __QUEUE_STATE_FROZEN)
  468. #define QUEUE_STATE_ANY_XOFF (QUEUE_STATE_DRV_XOFF | QUEUE_STATE_STACK_XOFF)
  469. #define QUEUE_STATE_ANY_XOFF_OR_FROZEN (QUEUE_STATE_ANY_XOFF | \
  470. QUEUE_STATE_FROZEN)
  471. #define QUEUE_STATE_DRV_XOFF_OR_FROZEN (QUEUE_STATE_DRV_XOFF | \
  472. QUEUE_STATE_FROZEN)
  473. /*
  474. * __QUEUE_STATE_DRV_XOFF is used by drivers to stop the transmit queue. The
  475. * netif_tx_* functions below are used to manipulate this flag. The
  476. * __QUEUE_STATE_STACK_XOFF flag is used by the stack to stop the transmit
  477. * queue independently. The netif_xmit_*stopped functions below are called
  478. * to check if the queue has been stopped by the driver or stack (either
  479. * of the XOFF bits are set in the state). Drivers should not need to call
  480. * netif_xmit*stopped functions, they should only be using netif_tx_*.
  481. */
  482. struct netdev_queue {
  483. /*
  484. * read mostly part
  485. */
  486. struct net_device *dev;
  487. struct Qdisc __rcu *qdisc;
  488. struct Qdisc *qdisc_sleeping;
  489. #ifdef CONFIG_SYSFS
  490. struct kobject kobj;
  491. #endif
  492. #if defined(CONFIG_XPS) && defined(CONFIG_NUMA)
  493. int numa_node;
  494. #endif
  495. /*
  496. * write mostly part
  497. */
  498. spinlock_t _xmit_lock ____cacheline_aligned_in_smp;
  499. int xmit_lock_owner;
  500. /*
  501. * please use this field instead of dev->trans_start
  502. */
  503. unsigned long trans_start;
  504. /*
  505. * Number of TX timeouts for this queue
  506. * (/sys/class/net/DEV/Q/trans_timeout)
  507. */
  508. unsigned long trans_timeout;
  509. unsigned long state;
  510. #ifdef CONFIG_BQL
  511. struct dql dql;
  512. #endif
  513. } ____cacheline_aligned_in_smp;
  514. static inline int netdev_queue_numa_node_read(const struct netdev_queue *q)
  515. {
  516. #if defined(CONFIG_XPS) && defined(CONFIG_NUMA)
  517. return q->numa_node;
  518. #else
  519. return NUMA_NO_NODE;
  520. #endif
  521. }
  522. static inline void netdev_queue_numa_node_write(struct netdev_queue *q, int node)
  523. {
  524. #if defined(CONFIG_XPS) && defined(CONFIG_NUMA)
  525. q->numa_node = node;
  526. #endif
  527. }
  528. #ifdef CONFIG_RPS
  529. /*
  530. * This structure holds an RPS map which can be of variable length. The
  531. * map is an array of CPUs.
  532. */
  533. struct rps_map {
  534. unsigned int len;
  535. struct rcu_head rcu;
  536. u16 cpus[0];
  537. };
  538. #define RPS_MAP_SIZE(_num) (sizeof(struct rps_map) + ((_num) * sizeof(u16)))
  539. /*
  540. * The rps_dev_flow structure contains the mapping of a flow to a CPU, the
  541. * tail pointer for that CPU's input queue at the time of last enqueue, and
  542. * a hardware filter index.
  543. */
  544. struct rps_dev_flow {
  545. u16 cpu;
  546. u16 filter;
  547. unsigned int last_qtail;
  548. };
  549. #define RPS_NO_FILTER 0xffff
  550. /*
  551. * The rps_dev_flow_table structure contains a table of flow mappings.
  552. */
  553. struct rps_dev_flow_table {
  554. unsigned int mask;
  555. struct rcu_head rcu;
  556. struct rps_dev_flow flows[0];
  557. };
  558. #define RPS_DEV_FLOW_TABLE_SIZE(_num) (sizeof(struct rps_dev_flow_table) + \
  559. ((_num) * sizeof(struct rps_dev_flow)))
  560. /*
  561. * The rps_sock_flow_table contains mappings of flows to the last CPU
  562. * on which they were processed by the application (set in recvmsg).
  563. */
  564. struct rps_sock_flow_table {
  565. unsigned int mask;
  566. u16 ents[0];
  567. };
  568. #define RPS_SOCK_FLOW_TABLE_SIZE(_num) (sizeof(struct rps_sock_flow_table) + \
  569. ((_num) * sizeof(u16)))
  570. #define RPS_NO_CPU 0xffff
  571. static inline void rps_record_sock_flow(struct rps_sock_flow_table *table,
  572. u32 hash)
  573. {
  574. if (table && hash) {
  575. unsigned int cpu, index = hash & table->mask;
  576. /* We only give a hint, preemption can change cpu under us */
  577. cpu = raw_smp_processor_id();
  578. if (table->ents[index] != cpu)
  579. table->ents[index] = cpu;
  580. }
  581. }
  582. static inline void rps_reset_sock_flow(struct rps_sock_flow_table *table,
  583. u32 hash)
  584. {
  585. if (table && hash)
  586. table->ents[hash & table->mask] = RPS_NO_CPU;
  587. }
  588. extern struct rps_sock_flow_table __rcu *rps_sock_flow_table;
  589. #ifdef CONFIG_RFS_ACCEL
  590. bool rps_may_expire_flow(struct net_device *dev, u16 rxq_index, u32 flow_id,
  591. u16 filter_id);
  592. #endif
  593. #endif /* CONFIG_RPS */
  594. /* This structure contains an instance of an RX queue. */
  595. struct netdev_rx_queue {
  596. #ifdef CONFIG_RPS
  597. struct rps_map __rcu *rps_map;
  598. struct rps_dev_flow_table __rcu *rps_flow_table;
  599. #endif
  600. struct kobject kobj;
  601. struct net_device *dev;
  602. } ____cacheline_aligned_in_smp;
  603. /*
  604. * RX queue sysfs structures and functions.
  605. */
  606. struct rx_queue_attribute {
  607. struct attribute attr;
  608. ssize_t (*show)(struct netdev_rx_queue *queue,
  609. struct rx_queue_attribute *attr, char *buf);
  610. ssize_t (*store)(struct netdev_rx_queue *queue,
  611. struct rx_queue_attribute *attr, const char *buf, size_t len);
  612. };
  613. #ifdef CONFIG_XPS
  614. /*
  615. * This structure holds an XPS map which can be of variable length. The
  616. * map is an array of queues.
  617. */
  618. struct xps_map {
  619. unsigned int len;
  620. unsigned int alloc_len;
  621. struct rcu_head rcu;
  622. u16 queues[0];
  623. };
  624. #define XPS_MAP_SIZE(_num) (sizeof(struct xps_map) + ((_num) * sizeof(u16)))
  625. #define XPS_MIN_MAP_ALLOC ((L1_CACHE_BYTES - sizeof(struct xps_map)) \
  626. / sizeof(u16))
  627. /*
  628. * This structure holds all XPS maps for device. Maps are indexed by CPU.
  629. */
  630. struct xps_dev_maps {
  631. struct rcu_head rcu;
  632. struct xps_map __rcu *cpu_map[0];
  633. };
  634. #define XPS_DEV_MAPS_SIZE (sizeof(struct xps_dev_maps) + \
  635. (nr_cpu_ids * sizeof(struct xps_map *)))
  636. #endif /* CONFIG_XPS */
  637. #define TC_MAX_QUEUE 16
  638. #define TC_BITMASK 15
  639. /* HW offloaded queuing disciplines txq count and offset maps */
  640. struct netdev_tc_txq {
  641. u16 count;
  642. u16 offset;
  643. };
  644. #if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE)
  645. /*
  646. * This structure is to hold information about the device
  647. * configured to run FCoE protocol stack.
  648. */
  649. struct netdev_fcoe_hbainfo {
  650. char manufacturer[64];
  651. char serial_number[64];
  652. char hardware_version[64];
  653. char driver_version[64];
  654. char optionrom_version[64];
  655. char firmware_version[64];
  656. char model[256];
  657. char model_description[256];
  658. };
  659. #endif
  660. #define MAX_PHYS_PORT_ID_LEN 32
  661. /* This structure holds a unique identifier to identify the
  662. * physical port used by a netdevice.
  663. */
  664. struct netdev_phys_port_id {
  665. unsigned char id[MAX_PHYS_PORT_ID_LEN];
  666. unsigned char id_len;
  667. };
  668. typedef u16 (*select_queue_fallback_t)(struct net_device *dev,
  669. struct sk_buff *skb);
  670. /*
  671. * This structure defines the management hooks for network devices.
  672. * The following hooks can be defined; unless noted otherwise, they are
  673. * optional and can be filled with a null pointer.
  674. *
  675. * int (*ndo_init)(struct net_device *dev);
  676. * This function is called once when network device is registered.
  677. * The network device can use this to any late stage initializaton
  678. * or semantic validattion. It can fail with an error code which will
  679. * be propogated back to register_netdev
  680. *
  681. * void (*ndo_uninit)(struct net_device *dev);
  682. * This function is called when device is unregistered or when registration
  683. * fails. It is not called if init fails.
  684. *
  685. * int (*ndo_open)(struct net_device *dev);
  686. * This function is called when network device transistions to the up
  687. * state.
  688. *
  689. * int (*ndo_stop)(struct net_device *dev);
  690. * This function is called when network device transistions to the down
  691. * state.
  692. *
  693. * netdev_tx_t (*ndo_start_xmit)(struct sk_buff *skb,
  694. * struct net_device *dev);
  695. * Called when a packet needs to be transmitted.
  696. * Must return NETDEV_TX_OK , NETDEV_TX_BUSY.
  697. * (can also return NETDEV_TX_LOCKED iff NETIF_F_LLTX)
  698. * Required can not be NULL.
  699. *
  700. * u16 (*ndo_select_queue)(struct net_device *dev, struct sk_buff *skb,
  701. * void *accel_priv, select_queue_fallback_t fallback);
  702. * Called to decide which queue to when device supports multiple
  703. * transmit queues.
  704. *
  705. * void (*ndo_change_rx_flags)(struct net_device *dev, int flags);
  706. * This function is called to allow device receiver to make
  707. * changes to configuration when multicast or promiscious is enabled.
  708. *
  709. * void (*ndo_set_rx_mode)(struct net_device *dev);
  710. * This function is called device changes address list filtering.
  711. * If driver handles unicast address filtering, it should set
  712. * IFF_UNICAST_FLT to its priv_flags.
  713. *
  714. * int (*ndo_set_mac_address)(struct net_device *dev, void *addr);
  715. * This function is called when the Media Access Control address
  716. * needs to be changed. If this interface is not defined, the
  717. * mac address can not be changed.
  718. *
  719. * int (*ndo_validate_addr)(struct net_device *dev);
  720. * Test if Media Access Control address is valid for the device.
  721. *
  722. * int (*ndo_do_ioctl)(struct net_device *dev, struct ifreq *ifr, int cmd);
  723. * Called when a user request an ioctl which can't be handled by
  724. * the generic interface code. If not defined ioctl's return
  725. * not supported error code.
  726. *
  727. * int (*ndo_set_config)(struct net_device *dev, struct ifmap *map);
  728. * Used to set network devices bus interface parameters. This interface
  729. * is retained for legacy reason, new devices should use the bus
  730. * interface (PCI) for low level management.
  731. *
  732. * int (*ndo_change_mtu)(struct net_device *dev, int new_mtu);
  733. * Called when a user wants to change the Maximum Transfer Unit
  734. * of a device. If not defined, any request to change MTU will
  735. * will return an error.
  736. *
  737. * void (*ndo_tx_timeout)(struct net_device *dev);
  738. * Callback uses when the transmitter has not made any progress
  739. * for dev->watchdog ticks.
  740. *
  741. * struct rtnl_link_stats64* (*ndo_get_stats64)(struct net_device *dev,
  742. * struct rtnl_link_stats64 *storage);
  743. * struct net_device_stats* (*ndo_get_stats)(struct net_device *dev);
  744. * Called when a user wants to get the network device usage
  745. * statistics. Drivers must do one of the following:
  746. * 1. Define @ndo_get_stats64 to fill in a zero-initialised
  747. * rtnl_link_stats64 structure passed by the caller.
  748. * 2. Define @ndo_get_stats to update a net_device_stats structure
  749. * (which should normally be dev->stats) and return a pointer to
  750. * it. The structure may be changed asynchronously only if each
  751. * field is written atomically.
  752. * 3. Update dev->stats asynchronously and atomically, and define
  753. * neither operation.
  754. *
  755. * int (*ndo_vlan_rx_add_vid)(struct net_device *dev, __be16 proto, u16t vid);
  756. * If device support VLAN filtering this function is called when a
  757. * VLAN id is registered.
  758. *
  759. * int (*ndo_vlan_rx_kill_vid)(struct net_device *dev, unsigned short vid);
  760. * If device support VLAN filtering this function is called when a
  761. * VLAN id is unregistered.
  762. *
  763. * void (*ndo_poll_controller)(struct net_device *dev);
  764. *
  765. * SR-IOV management functions.
  766. * int (*ndo_set_vf_mac)(struct net_device *dev, int vf, u8* mac);
  767. * int (*ndo_set_vf_vlan)(struct net_device *dev, int vf, u16 vlan, u8 qos);
  768. * int (*ndo_set_vf_rate)(struct net_device *dev, int vf, int min_tx_rate,
  769. * int max_tx_rate);
  770. * int (*ndo_set_vf_spoofchk)(struct net_device *dev, int vf, bool setting);
  771. * int (*ndo_get_vf_config)(struct net_device *dev,
  772. * int vf, struct ifla_vf_info *ivf);
  773. * int (*ndo_set_vf_link_state)(struct net_device *dev, int vf, int link_state);
  774. * int (*ndo_set_vf_port)(struct net_device *dev, int vf,
  775. * struct nlattr *port[]);
  776. * int (*ndo_get_vf_port)(struct net_device *dev, int vf, struct sk_buff *skb);
  777. * int (*ndo_setup_tc)(struct net_device *dev, u8 tc)
  778. * Called to setup 'tc' number of traffic classes in the net device. This
  779. * is always called from the stack with the rtnl lock held and netif tx
  780. * queues stopped. This allows the netdevice to perform queue management
  781. * safely.
  782. *
  783. * Fiber Channel over Ethernet (FCoE) offload functions.
  784. * int (*ndo_fcoe_enable)(struct net_device *dev);
  785. * Called when the FCoE protocol stack wants to start using LLD for FCoE
  786. * so the underlying device can perform whatever needed configuration or
  787. * initialization to support acceleration of FCoE traffic.
  788. *
  789. * int (*ndo_fcoe_disable)(struct net_device *dev);
  790. * Called when the FCoE protocol stack wants to stop using LLD for FCoE
  791. * so the underlying device can perform whatever needed clean-ups to
  792. * stop supporting acceleration of FCoE traffic.
  793. *
  794. * int (*ndo_fcoe_ddp_setup)(struct net_device *dev, u16 xid,
  795. * struct scatterlist *sgl, unsigned int sgc);
  796. * Called when the FCoE Initiator wants to initialize an I/O that
  797. * is a possible candidate for Direct Data Placement (DDP). The LLD can
  798. * perform necessary setup and returns 1 to indicate the device is set up
  799. * successfully to perform DDP on this I/O, otherwise this returns 0.
  800. *
  801. * int (*ndo_fcoe_ddp_done)(struct net_device *dev, u16 xid);
  802. * Called when the FCoE Initiator/Target is done with the DDPed I/O as
  803. * indicated by the FC exchange id 'xid', so the underlying device can
  804. * clean up and reuse resources for later DDP requests.
  805. *
  806. * int (*ndo_fcoe_ddp_target)(struct net_device *dev, u16 xid,
  807. * struct scatterlist *sgl, unsigned int sgc);
  808. * Called when the FCoE Target wants to initialize an I/O that
  809. * is a possible candidate for Direct Data Placement (DDP). The LLD can
  810. * perform necessary setup and returns 1 to indicate the device is set up
  811. * successfully to perform DDP on this I/O, otherwise this returns 0.
  812. *
  813. * int (*ndo_fcoe_get_hbainfo)(struct net_device *dev,
  814. * struct netdev_fcoe_hbainfo *hbainfo);
  815. * Called when the FCoE Protocol stack wants information on the underlying
  816. * device. This information is utilized by the FCoE protocol stack to
  817. * register attributes with Fiber Channel management service as per the
  818. * FC-GS Fabric Device Management Information(FDMI) specification.
  819. *
  820. * int (*ndo_fcoe_get_wwn)(struct net_device *dev, u64 *wwn, int type);
  821. * Called when the underlying device wants to override default World Wide
  822. * Name (WWN) generation mechanism in FCoE protocol stack to pass its own
  823. * World Wide Port Name (WWPN) or World Wide Node Name (WWNN) to the FCoE
  824. * protocol stack to use.
  825. *
  826. * RFS acceleration.
  827. * int (*ndo_rx_flow_steer)(struct net_device *dev, const struct sk_buff *skb,
  828. * u16 rxq_index, u32 flow_id);
  829. * Set hardware filter for RFS. rxq_index is the target queue index;
  830. * flow_id is a flow ID to be passed to rps_may_expire_flow() later.
  831. * Return the filter ID on success, or a negative error code.
  832. *
  833. * Slave management functions (for bridge, bonding, etc).
  834. * int (*ndo_add_slave)(struct net_device *dev, struct net_device *slave_dev);
  835. * Called to make another netdev an underling.
  836. *
  837. * int (*ndo_del_slave)(struct net_device *dev, struct net_device *slave_dev);
  838. * Called to release previously enslaved netdev.
  839. *
  840. * Feature/offload setting functions.
  841. * netdev_features_t (*ndo_fix_features)(struct net_device *dev,
  842. * netdev_features_t features);
  843. * Adjusts the requested feature flags according to device-specific
  844. * constraints, and returns the resulting flags. Must not modify
  845. * the device state.
  846. *
  847. * int (*ndo_set_features)(struct net_device *dev, netdev_features_t features);
  848. * Called to update device configuration to new features. Passed
  849. * feature set might be less than what was returned by ndo_fix_features()).
  850. * Must return >0 or -errno if it changed dev->features itself.
  851. *
  852. * int (*ndo_fdb_add)(struct ndmsg *ndm, struct nlattr *tb[],
  853. * struct net_device *dev,
  854. * const unsigned char *addr, u16 flags)
  855. * Adds an FDB entry to dev for addr.
  856. * int (*ndo_fdb_del)(struct ndmsg *ndm, struct nlattr *tb[],
  857. * struct net_device *dev,
  858. * const unsigned char *addr)
  859. * Deletes the FDB entry from dev coresponding to addr.
  860. * int (*ndo_fdb_dump)(struct sk_buff *skb, struct netlink_callback *cb,
  861. * struct net_device *dev, struct net_device *filter_dev,
  862. * int idx)
  863. * Used to add FDB entries to dump requests. Implementers should add
  864. * entries to skb and update idx with the number of entries.
  865. *
  866. * int (*ndo_bridge_setlink)(struct net_device *dev, struct nlmsghdr *nlh)
  867. * int (*ndo_bridge_getlink)(struct sk_buff *skb, u32 pid, u32 seq,
  868. * struct net_device *dev, u32 filter_mask)
  869. *
  870. * int (*ndo_change_carrier)(struct net_device *dev, bool new_carrier);
  871. * Called to change device carrier. Soft-devices (like dummy, team, etc)
  872. * which do not represent real hardware may define this to allow their
  873. * userspace components to manage their virtual carrier state. Devices
  874. * that determine carrier state from physical hardware properties (eg
  875. * network cables) or protocol-dependent mechanisms (eg
  876. * USB_CDC_NOTIFY_NETWORK_CONNECTION) should NOT implement this function.
  877. *
  878. * int (*ndo_get_phys_port_id)(struct net_device *dev,
  879. * struct netdev_phys_port_id *ppid);
  880. * Called to get ID of physical port of this device. If driver does
  881. * not implement this, it is assumed that the hw is not able to have
  882. * multiple net devices on single physical port.
  883. *
  884. * void (*ndo_add_vxlan_port)(struct net_device *dev,
  885. * sa_family_t sa_family, __be16 port);
  886. * Called by vxlan to notiy a driver about the UDP port and socket
  887. * address family that vxlan is listnening to. It is called only when
  888. * a new port starts listening. The operation is protected by the
  889. * vxlan_net->sock_lock.
  890. *
  891. * void (*ndo_del_vxlan_port)(struct net_device *dev,
  892. * sa_family_t sa_family, __be16 port);
  893. * Called by vxlan to notify the driver about a UDP port and socket
  894. * address family that vxlan is not listening to anymore. The operation
  895. * is protected by the vxlan_net->sock_lock.
  896. *
  897. * void* (*ndo_dfwd_add_station)(struct net_device *pdev,
  898. * struct net_device *dev)
  899. * Called by upper layer devices to accelerate switching or other
  900. * station functionality into hardware. 'pdev is the lowerdev
  901. * to use for the offload and 'dev' is the net device that will
  902. * back the offload. Returns a pointer to the private structure
  903. * the upper layer will maintain.
  904. * void (*ndo_dfwd_del_station)(struct net_device *pdev, void *priv)
  905. * Called by upper layer device to delete the station created
  906. * by 'ndo_dfwd_add_station'. 'pdev' is the net device backing
  907. * the station and priv is the structure returned by the add
  908. * operation.
  909. * netdev_tx_t (*ndo_dfwd_start_xmit)(struct sk_buff *skb,
  910. * struct net_device *dev,
  911. * void *priv);
  912. * Callback to use for xmit over the accelerated station. This
  913. * is used in place of ndo_start_xmit on accelerated net
  914. * devices.
  915. * bool (*ndo_gso_check) (struct sk_buff *skb,
  916. * struct net_device *dev);
  917. * Called by core transmit path to determine if device is capable of
  918. * performing GSO on a packet. The device returns true if it is
  919. * able to GSO the packet, false otherwise. If the return value is
  920. * false the stack will do software GSO.
  921. */
  922. struct net_device_ops {
  923. int (*ndo_init)(struct net_device *dev);
  924. void (*ndo_uninit)(struct net_device *dev);
  925. int (*ndo_open)(struct net_device *dev);
  926. int (*ndo_stop)(struct net_device *dev);
  927. netdev_tx_t (*ndo_start_xmit) (struct sk_buff *skb,
  928. struct net_device *dev);
  929. u16 (*ndo_select_queue)(struct net_device *dev,
  930. struct sk_buff *skb,
  931. void *accel_priv,
  932. select_queue_fallback_t fallback);
  933. void (*ndo_change_rx_flags)(struct net_device *dev,
  934. int flags);
  935. void (*ndo_set_rx_mode)(struct net_device *dev);
  936. int (*ndo_set_mac_address)(struct net_device *dev,
  937. void *addr);
  938. int (*ndo_validate_addr)(struct net_device *dev);
  939. int (*ndo_do_ioctl)(struct net_device *dev,
  940. struct ifreq *ifr, int cmd);
  941. int (*ndo_set_config)(struct net_device *dev,
  942. struct ifmap *map);
  943. int (*ndo_change_mtu)(struct net_device *dev,
  944. int new_mtu);
  945. int (*ndo_neigh_setup)(struct net_device *dev,
  946. struct neigh_parms *);
  947. void (*ndo_tx_timeout) (struct net_device *dev);
  948. struct rtnl_link_stats64* (*ndo_get_stats64)(struct net_device *dev,
  949. struct rtnl_link_stats64 *storage);
  950. struct net_device_stats* (*ndo_get_stats)(struct net_device *dev);
  951. int (*ndo_vlan_rx_add_vid)(struct net_device *dev,
  952. __be16 proto, u16 vid);
  953. int (*ndo_vlan_rx_kill_vid)(struct net_device *dev,
  954. __be16 proto, u16 vid);
  955. #ifdef CONFIG_NET_POLL_CONTROLLER
  956. void (*ndo_poll_controller)(struct net_device *dev);
  957. int (*ndo_netpoll_setup)(struct net_device *dev,
  958. struct netpoll_info *info);
  959. void (*ndo_netpoll_cleanup)(struct net_device *dev);
  960. #endif
  961. #ifdef CONFIG_NET_RX_BUSY_POLL
  962. int (*ndo_busy_poll)(struct napi_struct *dev);
  963. #endif
  964. int (*ndo_set_vf_mac)(struct net_device *dev,
  965. int queue, u8 *mac);
  966. int (*ndo_set_vf_vlan)(struct net_device *dev,
  967. int queue, u16 vlan, u8 qos);
  968. int (*ndo_set_vf_rate)(struct net_device *dev,
  969. int vf, int min_tx_rate,
  970. int max_tx_rate);
  971. int (*ndo_set_vf_spoofchk)(struct net_device *dev,
  972. int vf, bool setting);
  973. int (*ndo_get_vf_config)(struct net_device *dev,
  974. int vf,
  975. struct ifla_vf_info *ivf);
  976. int (*ndo_set_vf_link_state)(struct net_device *dev,
  977. int vf, int link_state);
  978. int (*ndo_set_vf_port)(struct net_device *dev,
  979. int vf,
  980. struct nlattr *port[]);
  981. int (*ndo_get_vf_port)(struct net_device *dev,
  982. int vf, struct sk_buff *skb);
  983. int (*ndo_setup_tc)(struct net_device *dev, u8 tc);
  984. #if IS_ENABLED(CONFIG_FCOE)
  985. int (*ndo_fcoe_enable)(struct net_device *dev);
  986. int (*ndo_fcoe_disable)(struct net_device *dev);
  987. int (*ndo_fcoe_ddp_setup)(struct net_device *dev,
  988. u16 xid,
  989. struct scatterlist *sgl,
  990. unsigned int sgc);
  991. int (*ndo_fcoe_ddp_done)(struct net_device *dev,
  992. u16 xid);
  993. int (*ndo_fcoe_ddp_target)(struct net_device *dev,
  994. u16 xid,
  995. struct scatterlist *sgl,
  996. unsigned int sgc);
  997. int (*ndo_fcoe_get_hbainfo)(struct net_device *dev,
  998. struct netdev_fcoe_hbainfo *hbainfo);
  999. #endif
  1000. #if IS_ENABLED(CONFIG_LIBFCOE)
  1001. #define NETDEV_FCOE_WWNN 0
  1002. #define NETDEV_FCOE_WWPN 1
  1003. int (*ndo_fcoe_get_wwn)(struct net_device *dev,
  1004. u64 *wwn, int type);
  1005. #endif
  1006. #ifdef CONFIG_RFS_ACCEL
  1007. int (*ndo_rx_flow_steer)(struct net_device *dev,
  1008. const struct sk_buff *skb,
  1009. u16 rxq_index,
  1010. u32 flow_id);
  1011. #endif
  1012. int (*ndo_add_slave)(struct net_device *dev,
  1013. struct net_device *slave_dev);
  1014. int (*ndo_del_slave)(struct net_device *dev,
  1015. struct net_device *slave_dev);
  1016. netdev_features_t (*ndo_fix_features)(struct net_device *dev,
  1017. netdev_features_t features);
  1018. int (*ndo_set_features)(struct net_device *dev,
  1019. netdev_features_t features);
  1020. int (*ndo_neigh_construct)(struct neighbour *n);
  1021. void (*ndo_neigh_destroy)(struct neighbour *n);
  1022. int (*ndo_fdb_add)(struct ndmsg *ndm,
  1023. struct nlattr *tb[],
  1024. struct net_device *dev,
  1025. const unsigned char *addr,
  1026. u16 flags);
  1027. int (*ndo_fdb_del)(struct ndmsg *ndm,
  1028. struct nlattr *tb[],
  1029. struct net_device *dev,
  1030. const unsigned char *addr);
  1031. int (*ndo_fdb_dump)(struct sk_buff *skb,
  1032. struct netlink_callback *cb,
  1033. struct net_device *dev,
  1034. struct net_device *filter_dev,
  1035. int idx);
  1036. int (*ndo_bridge_setlink)(struct net_device *dev,
  1037. struct nlmsghdr *nlh);
  1038. int (*ndo_bridge_getlink)(struct sk_buff *skb,
  1039. u32 pid, u32 seq,
  1040. struct net_device *dev,
  1041. u32 filter_mask);
  1042. int (*ndo_bridge_dellink)(struct net_device *dev,
  1043. struct nlmsghdr *nlh);
  1044. int (*ndo_change_carrier)(struct net_device *dev,
  1045. bool new_carrier);
  1046. int (*ndo_get_phys_port_id)(struct net_device *dev,
  1047. struct netdev_phys_port_id *ppid);
  1048. void (*ndo_add_vxlan_port)(struct net_device *dev,
  1049. sa_family_t sa_family,
  1050. __be16 port);
  1051. void (*ndo_del_vxlan_port)(struct net_device *dev,
  1052. sa_family_t sa_family,
  1053. __be16 port);
  1054. void* (*ndo_dfwd_add_station)(struct net_device *pdev,
  1055. struct net_device *dev);
  1056. void (*ndo_dfwd_del_station)(struct net_device *pdev,
  1057. void *priv);
  1058. netdev_tx_t (*ndo_dfwd_start_xmit) (struct sk_buff *skb,
  1059. struct net_device *dev,
  1060. void *priv);
  1061. int (*ndo_get_lock_subclass)(struct net_device *dev);
  1062. bool (*ndo_gso_check) (struct sk_buff *skb,
  1063. struct net_device *dev);
  1064. };
  1065. /**
  1066. * enum net_device_priv_flags - &struct net_device priv_flags
  1067. *
  1068. * These are the &struct net_device, they are only set internally
  1069. * by drivers and used in the kernel. These flags are invisible to
  1070. * userspace, this means that the order of these flags can change
  1071. * during any kernel release.
  1072. *
  1073. * You should have a pretty good reason to be extending these flags.
  1074. *
  1075. * @IFF_802_1Q_VLAN: 802.1Q VLAN device
  1076. * @IFF_EBRIDGE: Ethernet bridging device
  1077. * @IFF_SLAVE_INACTIVE: bonding slave not the curr. active
  1078. * @IFF_MASTER_8023AD: bonding master, 802.3ad
  1079. * @IFF_MASTER_ALB: bonding master, balance-alb
  1080. * @IFF_BONDING: bonding master or slave
  1081. * @IFF_SLAVE_NEEDARP: need ARPs for validation
  1082. * @IFF_ISATAP: ISATAP interface (RFC4214)
  1083. * @IFF_MASTER_ARPMON: bonding master, ARP mon in use
  1084. * @IFF_WAN_HDLC: WAN HDLC device
  1085. * @IFF_XMIT_DST_RELEASE: dev_hard_start_xmit() is allowed to
  1086. * release skb->dst
  1087. * @IFF_DONT_BRIDGE: disallow bridging this ether dev
  1088. * @IFF_DISABLE_NETPOLL: disable netpoll at run-time
  1089. * @IFF_MACVLAN_PORT: device used as macvlan port
  1090. * @IFF_BRIDGE_PORT: device used as bridge port
  1091. * @IFF_OVS_DATAPATH: device used as Open vSwitch datapath port
  1092. * @IFF_TX_SKB_SHARING: The interface supports sharing skbs on transmit
  1093. * @IFF_UNICAST_FLT: Supports unicast filtering
  1094. * @IFF_TEAM_PORT: device used as team port
  1095. * @IFF_SUPP_NOFCS: device supports sending custom FCS
  1096. * @IFF_LIVE_ADDR_CHANGE: device supports hardware address
  1097. * change when it's running
  1098. * @IFF_MACVLAN: Macvlan device
  1099. */
  1100. enum netdev_priv_flags {
  1101. IFF_802_1Q_VLAN = 1<<0,
  1102. IFF_EBRIDGE = 1<<1,
  1103. IFF_SLAVE_INACTIVE = 1<<2,
  1104. IFF_MASTER_8023AD = 1<<3,
  1105. IFF_MASTER_ALB = 1<<4,
  1106. IFF_BONDING = 1<<5,
  1107. IFF_SLAVE_NEEDARP = 1<<6,
  1108. IFF_ISATAP = 1<<7,
  1109. IFF_MASTER_ARPMON = 1<<8,
  1110. IFF_WAN_HDLC = 1<<9,
  1111. IFF_XMIT_DST_RELEASE = 1<<10,
  1112. IFF_DONT_BRIDGE = 1<<11,
  1113. IFF_DISABLE_NETPOLL = 1<<12,
  1114. IFF_MACVLAN_PORT = 1<<13,
  1115. IFF_BRIDGE_PORT = 1<<14,
  1116. IFF_OVS_DATAPATH = 1<<15,
  1117. IFF_TX_SKB_SHARING = 1<<16,
  1118. IFF_UNICAST_FLT = 1<<17,
  1119. IFF_TEAM_PORT = 1<<18,
  1120. IFF_SUPP_NOFCS = 1<<19,
  1121. IFF_LIVE_ADDR_CHANGE = 1<<20,
  1122. IFF_MACVLAN = 1<<21,
  1123. IFF_XMIT_DST_RELEASE_PERM = 1<<22,
  1124. };
  1125. #define IFF_802_1Q_VLAN IFF_802_1Q_VLAN
  1126. #define IFF_EBRIDGE IFF_EBRIDGE
  1127. #define IFF_SLAVE_INACTIVE IFF_SLAVE_INACTIVE
  1128. #define IFF_MASTER_8023AD IFF_MASTER_8023AD
  1129. #define IFF_MASTER_ALB IFF_MASTER_ALB
  1130. #define IFF_BONDING IFF_BONDING
  1131. #define IFF_SLAVE_NEEDARP IFF_SLAVE_NEEDARP
  1132. #define IFF_ISATAP IFF_ISATAP
  1133. #define IFF_MASTER_ARPMON IFF_MASTER_ARPMON
  1134. #define IFF_WAN_HDLC IFF_WAN_HDLC
  1135. #define IFF_XMIT_DST_RELEASE IFF_XMIT_DST_RELEASE
  1136. #define IFF_DONT_BRIDGE IFF_DONT_BRIDGE
  1137. #define IFF_DISABLE_NETPOLL IFF_DISABLE_NETPOLL
  1138. #define IFF_MACVLAN_PORT IFF_MACVLAN_PORT
  1139. #define IFF_BRIDGE_PORT IFF_BRIDGE_PORT
  1140. #define IFF_OVS_DATAPATH IFF_OVS_DATAPATH
  1141. #define IFF_TX_SKB_SHARING IFF_TX_SKB_SHARING
  1142. #define IFF_UNICAST_FLT IFF_UNICAST_FLT
  1143. #define IFF_TEAM_PORT IFF_TEAM_PORT
  1144. #define IFF_SUPP_NOFCS IFF_SUPP_NOFCS
  1145. #define IFF_LIVE_ADDR_CHANGE IFF_LIVE_ADDR_CHANGE
  1146. #define IFF_MACVLAN IFF_MACVLAN
  1147. #define IFF_XMIT_DST_RELEASE_PERM IFF_XMIT_DST_RELEASE_PERM
  1148. /**
  1149. * struct net_device - The DEVICE structure.
  1150. * Actually, this whole structure is a big mistake. It mixes I/O
  1151. * data with strictly "high-level" data, and it has to know about
  1152. * almost every data structure used in the INET module.
  1153. *
  1154. * @name: This is the first field of the "visible" part of this structure
  1155. * (i.e. as seen by users in the "Space.c" file). It is the name
  1156. * of the interface.
  1157. *
  1158. * @name_hlist: Device name hash chain, please keep it close to name[]
  1159. * @ifalias: SNMP alias
  1160. * @mem_end: Shared memory end
  1161. * @mem_start: Shared memory start
  1162. * @base_addr: Device I/O address
  1163. * @irq: Device IRQ number
  1164. *
  1165. * @state: Generic network queuing layer state, see netdev_state_t
  1166. * @dev_list: The global list of network devices
  1167. * @napi_list: List entry, that is used for polling napi devices
  1168. * @unreg_list: List entry, that is used, when we are unregistering the
  1169. * device, see the function unregister_netdev
  1170. * @close_list: List entry, that is used, when we are closing the device
  1171. *
  1172. * @adj_list: Directly linked devices, like slaves for bonding
  1173. * @all_adj_list: All linked devices, *including* neighbours
  1174. * @features: Currently active device features
  1175. * @hw_features: User-changeable features
  1176. *
  1177. * @wanted_features: User-requested features
  1178. * @vlan_features: Mask of features inheritable by VLAN devices
  1179. *
  1180. * @hw_enc_features: Mask of features inherited by encapsulating devices
  1181. * This field indicates what encapsulation
  1182. * offloads the hardware is capable of doing,
  1183. * and drivers will need to set them appropriately.
  1184. *
  1185. * @mpls_features: Mask of features inheritable by MPLS
  1186. *
  1187. * @ifindex: interface index
  1188. * @iflink: unique device identifier
  1189. *
  1190. * @stats: Statistics struct, which was left as a legacy, use
  1191. * rtnl_link_stats64 instead
  1192. *
  1193. * @rx_dropped: Dropped packets by core network,
  1194. * do not use this in drivers
  1195. * @tx_dropped: Dropped packets by core network,
  1196. * do not use this in drivers
  1197. *
  1198. * @carrier_changes: Stats to monitor carrier on<->off transitions
  1199. *
  1200. * @wireless_handlers: List of functions to handle Wireless Extensions,
  1201. * instead of ioctl,
  1202. * see <net/iw_handler.h> for details.
  1203. * @wireless_data: Instance data managed by the core of wireless extensions
  1204. *
  1205. * @netdev_ops: Includes several pointers to callbacks,
  1206. * if one wants to override the ndo_*() functions
  1207. * @ethtool_ops: Management operations
  1208. * @fwd_ops: Management operations
  1209. * @header_ops: Includes callbacks for creating,parsing,rebuilding,etc
  1210. * of Layer 2 headers.
  1211. *
  1212. * @flags: Interface flags (a la BSD)
  1213. * @priv_flags: Like 'flags' but invisible to userspace,
  1214. * see if.h for the definitions
  1215. * @gflags: Global flags ( kept as legacy )
  1216. * @padded: How much padding added by alloc_netdev()
  1217. * @operstate: RFC2863 operstate
  1218. * @link_mode: Mapping policy to operstate
  1219. * @if_port: Selectable AUI, TP, ...
  1220. * @dma: DMA channel
  1221. * @mtu: Interface MTU value
  1222. * @type: Interface hardware type
  1223. * @hard_header_len: Hardware header length
  1224. *
  1225. * @needed_headroom: Extra headroom the hardware may need, but not in all
  1226. * cases can this be guaranteed
  1227. * @needed_tailroom: Extra tailroom the hardware may need, but not in all
  1228. * cases can this be guaranteed. Some cases also use
  1229. * LL_MAX_HEADER instead to allocate the skb
  1230. *
  1231. * interface address info:
  1232. *
  1233. * @perm_addr: Permanent hw address
  1234. * @addr_assign_type: Hw address assignment type
  1235. * @addr_len: Hardware address length
  1236. * @neigh_priv_len; Used in neigh_alloc(),
  1237. * initialized only in atm/clip.c
  1238. * @dev_id: Used to differentiate devices that share
  1239. * the same link layer address
  1240. * @dev_port: Used to differentiate devices that share
  1241. * the same function
  1242. * @addr_list_lock: XXX: need comments on this one
  1243. * @uc: unicast mac addresses
  1244. * @mc: multicast mac addresses
  1245. * @dev_addrs: list of device hw addresses
  1246. * @queues_kset: Group of all Kobjects in the Tx and RX queues
  1247. * @uc_promisc: Counter, that indicates, that promiscuous mode
  1248. * has been enabled due to the need to listen to
  1249. * additional unicast addresses in a device that
  1250. * does not implement ndo_set_rx_mode()
  1251. * @promiscuity: Number of times, the NIC is told to work in
  1252. * Promiscuous mode, if it becomes 0 the NIC will
  1253. * exit from working in Promiscuous mode
  1254. * @allmulti: Counter, enables or disables allmulticast mode
  1255. *
  1256. * @vlan_info: VLAN info
  1257. * @dsa_ptr: dsa specific data
  1258. * @tipc_ptr: TIPC specific data
  1259. * @atalk_ptr: AppleTalk link
  1260. * @ip_ptr: IPv4 specific data
  1261. * @dn_ptr: DECnet specific data
  1262. * @ip6_ptr: IPv6 specific data
  1263. * @ax25_ptr: AX.25 specific data
  1264. * @ieee80211_ptr: IEEE 802.11 specific data, assign before registering
  1265. *
  1266. * @last_rx: Time of last Rx
  1267. * @dev_addr: Hw address (before bcast,
  1268. * because most packets are unicast)
  1269. *
  1270. * @_rx: Array of RX queues
  1271. * @num_rx_queues: Number of RX queues
  1272. * allocated at register_netdev() time
  1273. * @real_num_rx_queues: Number of RX queues currently active in device
  1274. *
  1275. * @rx_handler: handler for received packets
  1276. * @rx_handler_data: XXX: need comments on this one
  1277. * @ingress_queue: XXX: need comments on this one
  1278. * @broadcast: hw bcast address
  1279. *
  1280. * @_tx: Array of TX queues
  1281. * @num_tx_queues: Number of TX queues allocated at alloc_netdev_mq() time
  1282. * @real_num_tx_queues: Number of TX queues currently active in device
  1283. * @qdisc: Root qdisc from userspace point of view
  1284. * @tx_queue_len: Max frames per queue allowed
  1285. * @tx_global_lock: XXX: need comments on this one
  1286. *
  1287. * @xps_maps: XXX: need comments on this one
  1288. *
  1289. * @rx_cpu_rmap: CPU reverse-mapping for RX completion interrupts,
  1290. * indexed by RX queue number. Assigned by driver.
  1291. * This must only be set if the ndo_rx_flow_steer
  1292. * operation is defined
  1293. *
  1294. * @trans_start: Time (in jiffies) of last Tx
  1295. * @watchdog_timeo: Represents the timeout that is used by
  1296. * the watchdog ( see dev_watchdog() )
  1297. * @watchdog_timer: List of timers
  1298. *
  1299. * @pcpu_refcnt: Number of references to this device
  1300. * @todo_list: Delayed register/unregister
  1301. * @index_hlist: Device index hash chain
  1302. * @link_watch_list: XXX: need comments on this one
  1303. *
  1304. * @reg_state: Register/unregister state machine
  1305. * @dismantle: Device is going to be freed
  1306. * @rtnl_link_state: This enum represents the phases of creating
  1307. * a new link
  1308. *
  1309. * @destructor: Called from unregister,
  1310. * can be used to call free_netdev
  1311. * @npinfo: XXX: need comments on this one
  1312. * @nd_net: Network namespace this network device is inside
  1313. *
  1314. * @ml_priv: Mid-layer private
  1315. * @lstats: Loopback statistics
  1316. * @tstats: Tunnel statistics
  1317. * @dstats: Dummy statistics
  1318. * @vstats: Virtual ethernet statistics
  1319. *
  1320. * @garp_port: GARP
  1321. * @mrp_port: MRP
  1322. *
  1323. * @dev: Class/net/name entry
  1324. * @sysfs_groups: Space for optional device, statistics and wireless
  1325. * sysfs groups
  1326. *
  1327. * @sysfs_rx_queue_group: Space for optional per-rx queue attributes
  1328. * @rtnl_link_ops: Rtnl_link_ops
  1329. *
  1330. * @gso_max_size: Maximum size of generic segmentation offload
  1331. * @gso_max_segs: Maximum number of segments that can be passed to the
  1332. * NIC for GSO
  1333. * @gso_min_segs: Minimum number of segments that can be passed to the
  1334. * NIC for GSO
  1335. *
  1336. * @dcbnl_ops: Data Center Bridging netlink ops
  1337. * @num_tc: Number of traffic classes in the net device
  1338. * @tc_to_txq: XXX: need comments on this one
  1339. * @prio_tc_map XXX: need comments on this one
  1340. *
  1341. * @fcoe_ddp_xid: Max exchange id for FCoE LRO by ddp
  1342. *
  1343. * @priomap: XXX: need comments on this one
  1344. * @phydev: Physical device may attach itself
  1345. * for hardware timestamping
  1346. *
  1347. * @qdisc_tx_busylock: XXX: need comments on this one
  1348. *
  1349. * @group: The group, that the device belongs to
  1350. * @pm_qos_req: Power Management QoS object
  1351. *
  1352. * FIXME: cleanup struct net_device such that network protocol info
  1353. * moves out.
  1354. */
  1355. struct net_device {
  1356. char name[IFNAMSIZ];
  1357. struct hlist_node name_hlist;
  1358. char *ifalias;
  1359. /*
  1360. * I/O specific fields
  1361. * FIXME: Merge these and struct ifmap into one
  1362. */
  1363. unsigned long mem_end;
  1364. unsigned long mem_start;
  1365. unsigned long base_addr;
  1366. int irq;
  1367. /*
  1368. * Some hardware also needs these fields (state,dev_list,
  1369. * napi_list,unreg_list,close_list) but they are not
  1370. * part of the usual set specified in Space.c.
  1371. */
  1372. unsigned long state;
  1373. struct list_head dev_list;
  1374. struct list_head napi_list;
  1375. struct list_head unreg_list;
  1376. struct list_head close_list;
  1377. struct {
  1378. struct list_head upper;
  1379. struct list_head lower;
  1380. } adj_list;
  1381. struct {
  1382. struct list_head upper;
  1383. struct list_head lower;
  1384. } all_adj_list;
  1385. netdev_features_t features;
  1386. netdev_features_t hw_features;
  1387. netdev_features_t wanted_features;
  1388. netdev_features_t vlan_features;
  1389. netdev_features_t hw_enc_features;
  1390. netdev_features_t mpls_features;
  1391. int ifindex;
  1392. int iflink;
  1393. struct net_device_stats stats;
  1394. atomic_long_t rx_dropped;
  1395. atomic_long_t tx_dropped;
  1396. atomic_t carrier_changes;
  1397. #ifdef CONFIG_WIRELESS_EXT
  1398. const struct iw_handler_def * wireless_handlers;
  1399. struct iw_public_data * wireless_data;
  1400. #endif
  1401. const struct net_device_ops *netdev_ops;
  1402. const struct ethtool_ops *ethtool_ops;
  1403. const struct forwarding_accel_ops *fwd_ops;
  1404. const struct header_ops *header_ops;
  1405. unsigned int flags;
  1406. unsigned int priv_flags;
  1407. unsigned short gflags;
  1408. unsigned short padded;
  1409. unsigned char operstate;
  1410. unsigned char link_mode;
  1411. unsigned char if_port;
  1412. unsigned char dma;
  1413. unsigned int mtu;
  1414. unsigned short type;
  1415. unsigned short hard_header_len;
  1416. unsigned short needed_headroom;
  1417. unsigned short needed_tailroom;
  1418. /* Interface address info. */
  1419. unsigned char perm_addr[MAX_ADDR_LEN];
  1420. unsigned char addr_assign_type;
  1421. unsigned char addr_len;
  1422. unsigned short neigh_priv_len;
  1423. unsigned short dev_id;
  1424. unsigned short dev_port;
  1425. spinlock_t addr_list_lock;
  1426. struct netdev_hw_addr_list uc;
  1427. struct netdev_hw_addr_list mc;
  1428. struct netdev_hw_addr_list dev_addrs;
  1429. #ifdef CONFIG_SYSFS
  1430. struct kset *queues_kset;
  1431. #endif
  1432. unsigned char name_assign_type;
  1433. bool uc_promisc;
  1434. unsigned int promiscuity;
  1435. unsigned int allmulti;
  1436. /* Protocol specific pointers */
  1437. #if IS_ENABLED(CONFIG_VLAN_8021Q)
  1438. struct vlan_info __rcu *vlan_info;
  1439. #endif
  1440. #if IS_ENABLED(CONFIG_NET_DSA)
  1441. struct dsa_switch_tree *dsa_ptr;
  1442. #endif
  1443. #if IS_ENABLED(CONFIG_TIPC)
  1444. struct tipc_bearer __rcu *tipc_ptr;
  1445. #endif
  1446. void *atalk_ptr;
  1447. struct in_device __rcu *ip_ptr;
  1448. struct dn_dev __rcu *dn_ptr;
  1449. struct inet6_dev __rcu *ip6_ptr;
  1450. void *ax25_ptr;
  1451. struct wireless_dev *ieee80211_ptr;
  1452. /*
  1453. * Cache lines mostly used on receive path (including eth_type_trans())
  1454. */
  1455. unsigned long last_rx;
  1456. /* Interface address info used in eth_type_trans() */
  1457. unsigned char *dev_addr;
  1458. #ifdef CONFIG_SYSFS
  1459. struct netdev_rx_queue *_rx;
  1460. unsigned int num_rx_queues;
  1461. unsigned int real_num_rx_queues;
  1462. #endif
  1463. rx_handler_func_t __rcu *rx_handler;
  1464. void __rcu *rx_handler_data;
  1465. struct netdev_queue __rcu *ingress_queue;
  1466. unsigned char broadcast[MAX_ADDR_LEN];
  1467. /*
  1468. * Cache lines mostly used on transmit path
  1469. */
  1470. struct netdev_queue *_tx ____cacheline_aligned_in_smp;
  1471. unsigned int num_tx_queues;
  1472. unsigned int real_num_tx_queues;
  1473. struct Qdisc *qdisc;
  1474. unsigned long tx_queue_len;
  1475. spinlock_t tx_global_lock;
  1476. #ifdef CONFIG_XPS
  1477. struct xps_dev_maps __rcu *xps_maps;
  1478. #endif
  1479. #ifdef CONFIG_RFS_ACCEL
  1480. struct cpu_rmap *rx_cpu_rmap;
  1481. #endif
  1482. /* These may be needed for future network-power-down code. */
  1483. /*
  1484. * trans_start here is expensive for high speed devices on SMP,
  1485. * please use netdev_queue->trans_start instead.
  1486. */
  1487. unsigned long trans_start;
  1488. int watchdog_timeo;
  1489. struct timer_list watchdog_timer;
  1490. int __percpu *pcpu_refcnt;
  1491. struct list_head todo_list;
  1492. struct hlist_node index_hlist;
  1493. struct list_head link_watch_list;
  1494. enum { NETREG_UNINITIALIZED=0,
  1495. NETREG_REGISTERED, /* completed register_netdevice */
  1496. NETREG_UNREGISTERING, /* called unregister_netdevice */
  1497. NETREG_UNREGISTERED, /* completed unregister todo */
  1498. NETREG_RELEASED, /* called free_netdev */
  1499. NETREG_DUMMY, /* dummy device for NAPI poll */
  1500. } reg_state:8;
  1501. bool dismantle;
  1502. enum {
  1503. RTNL_LINK_INITIALIZED,
  1504. RTNL_LINK_INITIALIZING,
  1505. } rtnl_link_state:16;
  1506. void (*destructor)(struct net_device *dev);
  1507. #ifdef CONFIG_NETPOLL
  1508. struct netpoll_info __rcu *npinfo;
  1509. #endif
  1510. #ifdef CONFIG_NET_NS
  1511. struct net *nd_net;
  1512. #endif
  1513. /* mid-layer private */
  1514. union {
  1515. void *ml_priv;
  1516. struct pcpu_lstats __percpu *lstats;
  1517. struct pcpu_sw_netstats __percpu *tstats;
  1518. struct pcpu_dstats __percpu *dstats;
  1519. struct pcpu_vstats __percpu *vstats;
  1520. };
  1521. struct garp_port __rcu *garp_port;
  1522. struct mrp_port __rcu *mrp_port;
  1523. struct device dev;
  1524. const struct attribute_group *sysfs_groups[4];
  1525. const struct attribute_group *sysfs_rx_queue_group;
  1526. const struct rtnl_link_ops *rtnl_link_ops;
  1527. /* for setting kernel sock attribute on TCP connection setup */
  1528. #define GSO_MAX_SIZE 65536
  1529. unsigned int gso_max_size;
  1530. #define GSO_MAX_SEGS 65535
  1531. u16 gso_max_segs;
  1532. u16 gso_min_segs;
  1533. #ifdef CONFIG_DCB
  1534. const struct dcbnl_rtnl_ops *dcbnl_ops;
  1535. #endif
  1536. u8 num_tc;
  1537. struct netdev_tc_txq tc_to_txq[TC_MAX_QUEUE];
  1538. u8 prio_tc_map[TC_BITMASK + 1];
  1539. #if IS_ENABLED(CONFIG_FCOE)
  1540. unsigned int fcoe_ddp_xid;
  1541. #endif
  1542. #if IS_ENABLED(CONFIG_CGROUP_NET_PRIO)
  1543. struct netprio_map __rcu *priomap;
  1544. #endif
  1545. struct phy_device *phydev;
  1546. struct lock_class_key *qdisc_tx_busylock;
  1547. int group;
  1548. struct pm_qos_request pm_qos_req;
  1549. };
  1550. #define to_net_dev(d) container_of(d, struct net_device, dev)
  1551. #define NETDEV_ALIGN 32
  1552. static inline
  1553. int netdev_get_prio_tc_map(const struct net_device *dev, u32 prio)
  1554. {
  1555. return dev->prio_tc_map[prio & TC_BITMASK];
  1556. }
  1557. static inline
  1558. int netdev_set_prio_tc_map(struct net_device *dev, u8 prio, u8 tc)
  1559. {
  1560. if (tc >= dev->num_tc)
  1561. return -EINVAL;
  1562. dev->prio_tc_map[prio & TC_BITMASK] = tc & TC_BITMASK;
  1563. return 0;
  1564. }
  1565. static inline
  1566. void netdev_reset_tc(struct net_device *dev)
  1567. {
  1568. dev->num_tc = 0;
  1569. memset(dev->tc_to_txq, 0, sizeof(dev->tc_to_txq));
  1570. memset(dev->prio_tc_map, 0, sizeof(dev->prio_tc_map));
  1571. }
  1572. static inline
  1573. int netdev_set_tc_queue(struct net_device *dev, u8 tc, u16 count, u16 offset)
  1574. {
  1575. if (tc >= dev->num_tc)
  1576. return -EINVAL;
  1577. dev->tc_to_txq[tc].count = count;
  1578. dev->tc_to_txq[tc].offset = offset;
  1579. return 0;
  1580. }
  1581. static inline
  1582. int netdev_set_num_tc(struct net_device *dev, u8 num_tc)
  1583. {
  1584. if (num_tc > TC_MAX_QUEUE)
  1585. return -EINVAL;
  1586. dev->num_tc = num_tc;
  1587. return 0;
  1588. }
  1589. static inline
  1590. int netdev_get_num_tc(struct net_device *dev)
  1591. {
  1592. return dev->num_tc;
  1593. }
  1594. static inline
  1595. struct netdev_queue *netdev_get_tx_queue(const struct net_device *dev,
  1596. unsigned int index)
  1597. {
  1598. return &dev->_tx[index];
  1599. }
  1600. static inline struct netdev_queue *skb_get_tx_queue(const struct net_device *dev,
  1601. const struct sk_buff *skb)
  1602. {
  1603. return netdev_get_tx_queue(dev, skb_get_queue_mapping(skb));
  1604. }
  1605. static inline void netdev_for_each_tx_queue(struct net_device *dev,
  1606. void (*f)(struct net_device *,
  1607. struct netdev_queue *,
  1608. void *),
  1609. void *arg)
  1610. {
  1611. unsigned int i;
  1612. for (i = 0; i < dev->num_tx_queues; i++)
  1613. f(dev, &dev->_tx[i], arg);
  1614. }
  1615. struct netdev_queue *netdev_pick_tx(struct net_device *dev,
  1616. struct sk_buff *skb,
  1617. void *accel_priv);
  1618. /*
  1619. * Net namespace inlines
  1620. */
  1621. static inline
  1622. struct net *dev_net(const struct net_device *dev)
  1623. {
  1624. return read_pnet(&dev->nd_net);
  1625. }
  1626. static inline
  1627. void dev_net_set(struct net_device *dev, struct net *net)
  1628. {
  1629. #ifdef CONFIG_NET_NS
  1630. release_net(dev->nd_net);
  1631. dev->nd_net = hold_net(net);
  1632. #endif
  1633. }
  1634. static inline bool netdev_uses_dsa(struct net_device *dev)
  1635. {
  1636. #if IS_ENABLED(CONFIG_NET_DSA)
  1637. if (dev->dsa_ptr != NULL)
  1638. return dsa_uses_tagged_protocol(dev->dsa_ptr);
  1639. #endif
  1640. return false;
  1641. }
  1642. /**
  1643. * netdev_priv - access network device private data
  1644. * @dev: network device
  1645. *
  1646. * Get network device private data
  1647. */
  1648. static inline void *netdev_priv(const struct net_device *dev)
  1649. {
  1650. return (char *)dev + ALIGN(sizeof(struct net_device), NETDEV_ALIGN);
  1651. }
  1652. /* Set the sysfs physical device reference for the network logical device
  1653. * if set prior to registration will cause a symlink during initialization.
  1654. */
  1655. #define SET_NETDEV_DEV(net, pdev) ((net)->dev.parent = (pdev))
  1656. /* Set the sysfs device type for the network logical device to allow
  1657. * fine-grained identification of different network device types. For
  1658. * example Ethernet, Wirelss LAN, Bluetooth, WiMAX etc.
  1659. */
  1660. #define SET_NETDEV_DEVTYPE(net, devtype) ((net)->dev.type = (devtype))
  1661. /* Default NAPI poll() weight
  1662. * Device drivers are strongly advised to not use bigger value
  1663. */
  1664. #define NAPI_POLL_WEIGHT 64
  1665. /**
  1666. * netif_napi_add - initialize a napi context
  1667. * @dev: network device
  1668. * @napi: napi context
  1669. * @poll: polling function
  1670. * @weight: default weight
  1671. *
  1672. * netif_napi_add() must be used to initialize a napi context prior to calling
  1673. * *any* of the other napi related functions.
  1674. */
  1675. void netif_napi_add(struct net_device *dev, struct napi_struct *napi,
  1676. int (*poll)(struct napi_struct *, int), int weight);
  1677. /**
  1678. * netif_napi_del - remove a napi context
  1679. * @napi: napi context
  1680. *
  1681. * netif_napi_del() removes a napi context from the network device napi list
  1682. */
  1683. void netif_napi_del(struct napi_struct *napi);
  1684. struct napi_gro_cb {
  1685. /* Virtual address of skb_shinfo(skb)->frags[0].page + offset. */
  1686. void *frag0;
  1687. /* Length of frag0. */
  1688. unsigned int frag0_len;
  1689. /* This indicates where we are processing relative to skb->data. */
  1690. int data_offset;
  1691. /* This is non-zero if the packet cannot be merged with the new skb. */
  1692. u16 flush;
  1693. /* Save the IP ID here and check when we get to the transport layer */
  1694. u16 flush_id;
  1695. /* Number of segments aggregated. */
  1696. u16 count;
  1697. /* This is non-zero if the packet may be of the same flow. */
  1698. u8 same_flow;
  1699. /* Free the skb? */
  1700. u8 free;
  1701. #define NAPI_GRO_FREE 1
  1702. #define NAPI_GRO_FREE_STOLEN_HEAD 2
  1703. /* jiffies when first packet was created/queued */
  1704. unsigned long age;
  1705. /* Used in ipv6_gro_receive() and foo-over-udp */
  1706. u16 proto;
  1707. /* Used in udp_gro_receive */
  1708. u8 udp_mark:1;
  1709. /* GRO checksum is valid */
  1710. u8 csum_valid:1;
  1711. /* Number of checksums via CHECKSUM_UNNECESSARY */
  1712. u8 csum_cnt:3;
  1713. /* Used in foo-over-udp, set in udp[46]_gro_receive */
  1714. u8 is_ipv6:1;
  1715. /* used to support CHECKSUM_COMPLETE for tunneling protocols */
  1716. __wsum csum;
  1717. /* used in skb_gro_receive() slow path */
  1718. struct sk_buff *last;
  1719. };
  1720. #define NAPI_GRO_CB(skb) ((struct napi_gro_cb *)(skb)->cb)
  1721. struct packet_type {
  1722. __be16 type; /* This is really htons(ether_type). */
  1723. struct net_device *dev; /* NULL is wildcarded here */
  1724. int (*func) (struct sk_buff *,
  1725. struct net_device *,
  1726. struct packet_type *,
  1727. struct net_device *);
  1728. bool (*id_match)(struct packet_type *ptype,
  1729. struct sock *sk);
  1730. void *af_packet_priv;
  1731. struct list_head list;
  1732. };
  1733. struct offload_callbacks {
  1734. struct sk_buff *(*gso_segment)(struct sk_buff *skb,
  1735. netdev_features_t features);
  1736. struct sk_buff **(*gro_receive)(struct sk_buff **head,
  1737. struct sk_buff *skb);
  1738. int (*gro_complete)(struct sk_buff *skb, int nhoff);
  1739. };
  1740. struct packet_offload {
  1741. __be16 type; /* This is really htons(ether_type). */
  1742. struct offload_callbacks callbacks;
  1743. struct list_head list;
  1744. };
  1745. struct udp_offload {
  1746. __be16 port;
  1747. u8 ipproto;
  1748. struct offload_callbacks callbacks;
  1749. };
  1750. /* often modified stats are per cpu, other are shared (netdev->stats) */
  1751. struct pcpu_sw_netstats {
  1752. u64 rx_packets;
  1753. u64 rx_bytes;
  1754. u64 tx_packets;
  1755. u64 tx_bytes;
  1756. struct u64_stats_sync syncp;
  1757. };
  1758. #define netdev_alloc_pcpu_stats(type) \
  1759. ({ \
  1760. typeof(type) __percpu *pcpu_stats = alloc_percpu(type); \
  1761. if (pcpu_stats) { \
  1762. int i; \
  1763. for_each_possible_cpu(i) { \
  1764. typeof(type) *stat; \
  1765. stat = per_cpu_ptr(pcpu_stats, i); \
  1766. u64_stats_init(&stat->syncp); \
  1767. } \
  1768. } \
  1769. pcpu_stats; \
  1770. })
  1771. #include <linux/notifier.h>
  1772. /* netdevice notifier chain. Please remember to update the rtnetlink
  1773. * notification exclusion list in rtnetlink_event() when adding new
  1774. * types.
  1775. */
  1776. #define NETDEV_UP 0x0001 /* For now you can't veto a device up/down */
  1777. #define NETDEV_DOWN 0x0002
  1778. #define NETDEV_REBOOT 0x0003 /* Tell a protocol stack a network interface
  1779. detected a hardware crash and restarted
  1780. - we can use this eg to kick tcp sessions
  1781. once done */
  1782. #define NETDEV_CHANGE 0x0004 /* Notify device state change */
  1783. #define NETDEV_REGISTER 0x0005
  1784. #define NETDEV_UNREGISTER 0x0006
  1785. #define NETDEV_CHANGEMTU 0x0007 /* notify after mtu change happened */
  1786. #define NETDEV_CHANGEADDR 0x0008
  1787. #define NETDEV_GOING_DOWN 0x0009
  1788. #define NETDEV_CHANGENAME 0x000A
  1789. #define NETDEV_FEAT_CHANGE 0x000B
  1790. #define NETDEV_BONDING_FAILOVER 0x000C
  1791. #define NETDEV_PRE_UP 0x000D
  1792. #define NETDEV_PRE_TYPE_CHANGE 0x000E
  1793. #define NETDEV_POST_TYPE_CHANGE 0x000F
  1794. #define NETDEV_POST_INIT 0x0010
  1795. #define NETDEV_UNREGISTER_FINAL 0x0011
  1796. #define NETDEV_RELEASE 0x0012
  1797. #define NETDEV_NOTIFY_PEERS 0x0013
  1798. #define NETDEV_JOIN 0x0014
  1799. #define NETDEV_CHANGEUPPER 0x0015
  1800. #define NETDEV_RESEND_IGMP 0x0016
  1801. #define NETDEV_PRECHANGEMTU 0x0017 /* notify before mtu change happened */
  1802. #define NETDEV_CHANGEINFODATA 0x0018
  1803. int register_netdevice_notifier(struct notifier_block *nb);
  1804. int unregister_netdevice_notifier(struct notifier_block *nb);
  1805. struct netdev_notifier_info {
  1806. struct net_device *dev;
  1807. };
  1808. struct netdev_notifier_change_info {
  1809. struct netdev_notifier_info info; /* must be first */
  1810. unsigned int flags_changed;
  1811. };
  1812. static inline void netdev_notifier_info_init(struct netdev_notifier_info *info,
  1813. struct net_device *dev)
  1814. {
  1815. info->dev = dev;
  1816. }
  1817. static inline struct net_device *
  1818. netdev_notifier_info_to_dev(const struct netdev_notifier_info *info)
  1819. {
  1820. return info->dev;
  1821. }
  1822. int call_netdevice_notifiers(unsigned long val, struct net_device *dev);
  1823. extern rwlock_t dev_base_lock; /* Device list lock */
  1824. #define for_each_netdev(net, d) \
  1825. list_for_each_entry(d, &(net)->dev_base_head, dev_list)
  1826. #define for_each_netdev_reverse(net, d) \
  1827. list_for_each_entry_reverse(d, &(net)->dev_base_head, dev_list)
  1828. #define for_each_netdev_rcu(net, d) \
  1829. list_for_each_entry_rcu(d, &(net)->dev_base_head, dev_list)
  1830. #define for_each_netdev_safe(net, d, n) \
  1831. list_for_each_entry_safe(d, n, &(net)->dev_base_head, dev_list)
  1832. #define for_each_netdev_continue(net, d) \
  1833. list_for_each_entry_continue(d, &(net)->dev_base_head, dev_list)
  1834. #define for_each_netdev_continue_rcu(net, d) \
  1835. list_for_each_entry_continue_rcu(d, &(net)->dev_base_head, dev_list)
  1836. #define for_each_netdev_in_bond_rcu(bond, slave) \
  1837. for_each_netdev_rcu(&init_net, slave) \
  1838. if (netdev_master_upper_dev_get_rcu(slave) == bond)
  1839. #define net_device_entry(lh) list_entry(lh, struct net_device, dev_list)
  1840. static inline struct net_device *next_net_device(struct net_device *dev)
  1841. {
  1842. struct list_head *lh;
  1843. struct net *net;
  1844. net = dev_net(dev);
  1845. lh = dev->dev_list.next;
  1846. return lh == &net->dev_base_head ? NULL : net_device_entry(lh);
  1847. }
  1848. static inline struct net_device *next_net_device_rcu(struct net_device *dev)
  1849. {
  1850. struct list_head *lh;
  1851. struct net *net;
  1852. net = dev_net(dev);
  1853. lh = rcu_dereference(list_next_rcu(&dev->dev_list));
  1854. return lh == &net->dev_base_head ? NULL : net_device_entry(lh);
  1855. }
  1856. static inline struct net_device *first_net_device(struct net *net)
  1857. {
  1858. return list_empty(&net->dev_base_head) ? NULL :
  1859. net_device_entry(net->dev_base_head.next);
  1860. }
  1861. static inline struct net_device *first_net_device_rcu(struct net *net)
  1862. {
  1863. struct list_head *lh = rcu_dereference(list_next_rcu(&net->dev_base_head));
  1864. return lh == &net->dev_base_head ? NULL : net_device_entry(lh);
  1865. }
  1866. int netdev_boot_setup_check(struct net_device *dev);
  1867. unsigned long netdev_boot_base(const char *prefix, int unit);
  1868. struct net_device *dev_getbyhwaddr_rcu(struct net *net, unsigned short type,
  1869. const char *hwaddr);
  1870. struct net_device *dev_getfirstbyhwtype(struct net *net, unsigned short type);
  1871. struct net_device *__dev_getfirstbyhwtype(struct net *net, unsigned short type);
  1872. void dev_add_pack(struct packet_type *pt);
  1873. void dev_remove_pack(struct packet_type *pt);
  1874. void __dev_remove_pack(struct packet_type *pt);
  1875. void dev_add_offload(struct packet_offload *po);
  1876. void dev_remove_offload(struct packet_offload *po);
  1877. struct net_device *__dev_get_by_flags(struct net *net, unsigned short flags,
  1878. unsigned short mask);
  1879. struct net_device *dev_get_by_name(struct net *net, const char *name);
  1880. struct net_device *dev_get_by_name_rcu(struct net *net, const char *name);
  1881. struct net_device *__dev_get_by_name(struct net *net, const char *name);
  1882. int dev_alloc_name(struct net_device *dev, const char *name);
  1883. int dev_open(struct net_device *dev);
  1884. int dev_close(struct net_device *dev);
  1885. void dev_disable_lro(struct net_device *dev);
  1886. int dev_loopback_xmit(struct sk_buff *newskb);
  1887. int dev_queue_xmit(struct sk_buff *skb);
  1888. int dev_queue_xmit_accel(struct sk_buff *skb, void *accel_priv);
  1889. int register_netdevice(struct net_device *dev);
  1890. void unregister_netdevice_queue(struct net_device *dev, struct list_head *head);
  1891. void unregister_netdevice_many(struct list_head *head);
  1892. static inline void unregister_netdevice(struct net_device *dev)
  1893. {
  1894. unregister_netdevice_queue(dev, NULL);
  1895. }
  1896. int netdev_refcnt_read(const struct net_device *dev);
  1897. void free_netdev(struct net_device *dev);
  1898. void netdev_freemem(struct net_device *dev);
  1899. void synchronize_net(void);
  1900. int init_dummy_netdev(struct net_device *dev);
  1901. struct net_device *dev_get_by_index(struct net *net, int ifindex);
  1902. struct net_device *__dev_get_by_index(struct net *net, int ifindex);
  1903. struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex);
  1904. int netdev_get_name(struct net *net, char *name, int ifindex);
  1905. int dev_restart(struct net_device *dev);
  1906. int skb_gro_receive(struct sk_buff **head, struct sk_buff *skb);
  1907. static inline unsigned int skb_gro_offset(const struct sk_buff *skb)
  1908. {
  1909. return NAPI_GRO_CB(skb)->data_offset;
  1910. }
  1911. static inline unsigned int skb_gro_len(const struct sk_buff *skb)
  1912. {
  1913. return skb->len - NAPI_GRO_CB(skb)->data_offset;
  1914. }
  1915. static inline void skb_gro_pull(struct sk_buff *skb, unsigned int len)
  1916. {
  1917. NAPI_GRO_CB(skb)->data_offset += len;
  1918. }
  1919. static inline void *skb_gro_header_fast(struct sk_buff *skb,
  1920. unsigned int offset)
  1921. {
  1922. return NAPI_GRO_CB(skb)->frag0 + offset;
  1923. }
  1924. static inline int skb_gro_header_hard(struct sk_buff *skb, unsigned int hlen)
  1925. {
  1926. return NAPI_GRO_CB(skb)->frag0_len < hlen;
  1927. }
  1928. static inline void *skb_gro_header_slow(struct sk_buff *skb, unsigned int hlen,
  1929. unsigned int offset)
  1930. {
  1931. if (!pskb_may_pull(skb, hlen))
  1932. return NULL;
  1933. NAPI_GRO_CB(skb)->frag0 = NULL;
  1934. NAPI_GRO_CB(skb)->frag0_len = 0;
  1935. return skb->data + offset;
  1936. }
  1937. static inline void *skb_gro_network_header(struct sk_buff *skb)
  1938. {
  1939. return (NAPI_GRO_CB(skb)->frag0 ?: skb->data) +
  1940. skb_network_offset(skb);
  1941. }
  1942. static inline void skb_gro_postpull_rcsum(struct sk_buff *skb,
  1943. const void *start, unsigned int len)
  1944. {
  1945. if (NAPI_GRO_CB(skb)->csum_valid)
  1946. NAPI_GRO_CB(skb)->csum = csum_sub(NAPI_GRO_CB(skb)->csum,
  1947. csum_partial(start, len, 0));
  1948. }
  1949. /* GRO checksum functions. These are logical equivalents of the normal
  1950. * checksum functions (in skbuff.h) except that they operate on the GRO
  1951. * offsets and fields in sk_buff.
  1952. */
  1953. __sum16 __skb_gro_checksum_complete(struct sk_buff *skb);
  1954. static inline bool __skb_gro_checksum_validate_needed(struct sk_buff *skb,
  1955. bool zero_okay,
  1956. __sum16 check)
  1957. {
  1958. return (skb->ip_summed != CHECKSUM_PARTIAL &&
  1959. NAPI_GRO_CB(skb)->csum_cnt == 0 &&
  1960. (!zero_okay || check));
  1961. }
  1962. static inline __sum16 __skb_gro_checksum_validate_complete(struct sk_buff *skb,
  1963. __wsum psum)
  1964. {
  1965. if (NAPI_GRO_CB(skb)->csum_valid &&
  1966. !csum_fold(csum_add(psum, NAPI_GRO_CB(skb)->csum)))
  1967. return 0;
  1968. NAPI_GRO_CB(skb)->csum = psum;
  1969. return __skb_gro_checksum_complete(skb);
  1970. }
  1971. static inline void skb_gro_incr_csum_unnecessary(struct sk_buff *skb)
  1972. {
  1973. if (NAPI_GRO_CB(skb)->csum_cnt > 0) {
  1974. /* Consume a checksum from CHECKSUM_UNNECESSARY */
  1975. NAPI_GRO_CB(skb)->csum_cnt--;
  1976. } else {
  1977. /* Update skb for CHECKSUM_UNNECESSARY and csum_level when we
  1978. * verified a new top level checksum or an encapsulated one
  1979. * during GRO. This saves work if we fallback to normal path.
  1980. */
  1981. __skb_incr_checksum_unnecessary(skb);
  1982. }
  1983. }
  1984. #define __skb_gro_checksum_validate(skb, proto, zero_okay, check, \
  1985. compute_pseudo) \
  1986. ({ \
  1987. __sum16 __ret = 0; \
  1988. if (__skb_gro_checksum_validate_needed(skb, zero_okay, check)) \
  1989. __ret = __skb_gro_checksum_validate_complete(skb, \
  1990. compute_pseudo(skb, proto)); \
  1991. if (__ret) \
  1992. __skb_mark_checksum_bad(skb); \
  1993. else \
  1994. skb_gro_incr_csum_unnecessary(skb); \
  1995. __ret; \
  1996. })
  1997. #define skb_gro_checksum_validate(skb, proto, compute_pseudo) \
  1998. __skb_gro_checksum_validate(skb, proto, false, 0, compute_pseudo)
  1999. #define skb_gro_checksum_validate_zero_check(skb, proto, check, \
  2000. compute_pseudo) \
  2001. __skb_gro_checksum_validate(skb, proto, true, check, compute_pseudo)
  2002. #define skb_gro_checksum_simple_validate(skb) \
  2003. __skb_gro_checksum_validate(skb, 0, false, 0, null_compute_pseudo)
  2004. static inline bool __skb_gro_checksum_convert_check(struct sk_buff *skb)
  2005. {
  2006. return (NAPI_GRO_CB(skb)->csum_cnt == 0 &&
  2007. !NAPI_GRO_CB(skb)->csum_valid);
  2008. }
  2009. static inline void __skb_gro_checksum_convert(struct sk_buff *skb,
  2010. __sum16 check, __wsum pseudo)
  2011. {
  2012. NAPI_GRO_CB(skb)->csum = ~pseudo;
  2013. NAPI_GRO_CB(skb)->csum_valid = 1;
  2014. }
  2015. #define skb_gro_checksum_try_convert(skb, proto, check, compute_pseudo) \
  2016. do { \
  2017. if (__skb_gro_checksum_convert_check(skb)) \
  2018. __skb_gro_checksum_convert(skb, check, \
  2019. compute_pseudo(skb, proto)); \
  2020. } while (0)
  2021. static inline int dev_hard_header(struct sk_buff *skb, struct net_device *dev,
  2022. unsigned short type,
  2023. const void *daddr, const void *saddr,
  2024. unsigned int len)
  2025. {
  2026. if (!dev->header_ops || !dev->header_ops->create)
  2027. return 0;
  2028. return dev->header_ops->create(skb, dev, type, daddr, saddr, len);
  2029. }
  2030. static inline int dev_parse_header(const struct sk_buff *skb,
  2031. unsigned char *haddr)
  2032. {
  2033. const struct net_device *dev = skb->dev;
  2034. if (!dev->header_ops || !dev->header_ops->parse)
  2035. return 0;
  2036. return dev->header_ops->parse(skb, haddr);
  2037. }
  2038. static inline int dev_rebuild_header(struct sk_buff *skb)
  2039. {
  2040. const struct net_device *dev = skb->dev;
  2041. if (!dev->header_ops || !dev->header_ops->rebuild)
  2042. return 0;
  2043. return dev->header_ops->rebuild(skb);
  2044. }
  2045. typedef int gifconf_func_t(struct net_device * dev, char __user * bufptr, int len);
  2046. int register_gifconf(unsigned int family, gifconf_func_t *gifconf);
  2047. static inline int unregister_gifconf(unsigned int family)
  2048. {
  2049. return register_gifconf(family, NULL);
  2050. }
  2051. #ifdef CONFIG_NET_FLOW_LIMIT
  2052. #define FLOW_LIMIT_HISTORY (1 << 7) /* must be ^2 and !overflow buckets */
  2053. struct sd_flow_limit {
  2054. u64 count;
  2055. unsigned int num_buckets;
  2056. unsigned int history_head;
  2057. u16 history[FLOW_LIMIT_HISTORY];
  2058. u8 buckets[];
  2059. };
  2060. extern int netdev_flow_limit_table_len;
  2061. #endif /* CONFIG_NET_FLOW_LIMIT */
  2062. /*
  2063. * Incoming packets are placed on per-cpu queues
  2064. */
  2065. struct softnet_data {
  2066. struct Qdisc *output_queue;
  2067. struct Qdisc **output_queue_tailp;
  2068. struct list_head poll_list;
  2069. struct sk_buff *completion_queue;
  2070. struct sk_buff_head process_queue;
  2071. /* stats */
  2072. unsigned int processed;
  2073. unsigned int time_squeeze;
  2074. unsigned int cpu_collision;
  2075. unsigned int received_rps;
  2076. #ifdef CONFIG_RPS
  2077. struct softnet_data *rps_ipi_list;
  2078. /* Elements below can be accessed between CPUs for RPS */
  2079. struct call_single_data csd ____cacheline_aligned_in_smp;
  2080. struct softnet_data *rps_ipi_next;
  2081. unsigned int cpu;
  2082. unsigned int input_queue_head;
  2083. unsigned int input_queue_tail;
  2084. #endif
  2085. unsigned int dropped;
  2086. struct sk_buff_head input_pkt_queue;
  2087. struct napi_struct backlog;
  2088. #ifdef CONFIG_NET_FLOW_LIMIT
  2089. struct sd_flow_limit __rcu *flow_limit;
  2090. #endif
  2091. };
  2092. static inline void input_queue_head_incr(struct softnet_data *sd)
  2093. {
  2094. #ifdef CONFIG_RPS
  2095. sd->input_queue_head++;
  2096. #endif
  2097. }
  2098. static inline void input_queue_tail_incr_save(struct softnet_data *sd,
  2099. unsigned int *qtail)
  2100. {
  2101. #ifdef CONFIG_RPS
  2102. *qtail = ++sd->input_queue_tail;
  2103. #endif
  2104. }
  2105. DECLARE_PER_CPU_ALIGNED(struct softnet_data, softnet_data);
  2106. void __netif_schedule(struct Qdisc *q);
  2107. void netif_schedule_queue(struct netdev_queue *txq);
  2108. static inline void netif_tx_schedule_all(struct net_device *dev)
  2109. {
  2110. unsigned int i;
  2111. for (i = 0; i < dev->num_tx_queues; i++)
  2112. netif_schedule_queue(netdev_get_tx_queue(dev, i));
  2113. }
  2114. static inline void netif_tx_start_queue(struct netdev_queue *dev_queue)
  2115. {
  2116. clear_bit(__QUEUE_STATE_DRV_XOFF, &dev_queue->state);
  2117. }
  2118. /**
  2119. * netif_start_queue - allow transmit
  2120. * @dev: network device
  2121. *
  2122. * Allow upper layers to call the device hard_start_xmit routine.
  2123. */
  2124. static inline void netif_start_queue(struct net_device *dev)
  2125. {
  2126. netif_tx_start_queue(netdev_get_tx_queue(dev, 0));
  2127. }
  2128. static inline void netif_tx_start_all_queues(struct net_device *dev)
  2129. {
  2130. unsigned int i;
  2131. for (i = 0; i < dev->num_tx_queues; i++) {
  2132. struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
  2133. netif_tx_start_queue(txq);
  2134. }
  2135. }
  2136. void netif_tx_wake_queue(struct netdev_queue *dev_queue);
  2137. /**
  2138. * netif_wake_queue - restart transmit
  2139. * @dev: network device
  2140. *
  2141. * Allow upper layers to call the device hard_start_xmit routine.
  2142. * Used for flow control when transmit resources are available.
  2143. */
  2144. static inline void netif_wake_queue(struct net_device *dev)
  2145. {
  2146. netif_tx_wake_queue(netdev_get_tx_queue(dev, 0));
  2147. }
  2148. static inline void netif_tx_wake_all_queues(struct net_device *dev)
  2149. {
  2150. unsigned int i;
  2151. for (i = 0; i < dev->num_tx_queues; i++) {
  2152. struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
  2153. netif_tx_wake_queue(txq);
  2154. }
  2155. }
  2156. static inline void netif_tx_stop_queue(struct netdev_queue *dev_queue)
  2157. {
  2158. if (WARN_ON(!dev_queue)) {
  2159. pr_info("netif_stop_queue() cannot be called before register_netdev()\n");
  2160. return;
  2161. }
  2162. set_bit(__QUEUE_STATE_DRV_XOFF, &dev_queue->state);
  2163. }
  2164. /**
  2165. * netif_stop_queue - stop transmitted packets
  2166. * @dev: network device
  2167. *
  2168. * Stop upper layers calling the device hard_start_xmit routine.
  2169. * Used for flow control when transmit resources are unavailable.
  2170. */
  2171. static inline void netif_stop_queue(struct net_device *dev)
  2172. {
  2173. netif_tx_stop_queue(netdev_get_tx_queue(dev, 0));
  2174. }
  2175. static inline void netif_tx_stop_all_queues(struct net_device *dev)
  2176. {
  2177. unsigned int i;
  2178. for (i = 0; i < dev->num_tx_queues; i++) {
  2179. struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
  2180. netif_tx_stop_queue(txq);
  2181. }
  2182. }
  2183. static inline bool netif_tx_queue_stopped(const struct netdev_queue *dev_queue)
  2184. {
  2185. return test_bit(__QUEUE_STATE_DRV_XOFF, &dev_queue->state);
  2186. }
  2187. /**
  2188. * netif_queue_stopped - test if transmit queue is flowblocked
  2189. * @dev: network device
  2190. *
  2191. * Test if transmit queue on device is currently unable to send.
  2192. */
  2193. static inline bool netif_queue_stopped(const struct net_device *dev)
  2194. {
  2195. return netif_tx_queue_stopped(netdev_get_tx_queue(dev, 0));
  2196. }
  2197. static inline bool netif_xmit_stopped(const struct netdev_queue *dev_queue)
  2198. {
  2199. return dev_queue->state & QUEUE_STATE_ANY_XOFF;
  2200. }
  2201. static inline bool
  2202. netif_xmit_frozen_or_stopped(const struct netdev_queue *dev_queue)
  2203. {
  2204. return dev_queue->state & QUEUE_STATE_ANY_XOFF_OR_FROZEN;
  2205. }
  2206. static inline bool
  2207. netif_xmit_frozen_or_drv_stopped(const struct netdev_queue *dev_queue)
  2208. {
  2209. return dev_queue->state & QUEUE_STATE_DRV_XOFF_OR_FROZEN;
  2210. }
  2211. /**
  2212. * netdev_txq_bql_enqueue_prefetchw - prefetch bql data for write
  2213. * @dev_queue: pointer to transmit queue
  2214. *
  2215. * BQL enabled drivers might use this helper in their ndo_start_xmit(),
  2216. * to give appropriate hint to the cpu.
  2217. */
  2218. static inline void netdev_txq_bql_enqueue_prefetchw(struct netdev_queue *dev_queue)
  2219. {
  2220. #ifdef CONFIG_BQL
  2221. prefetchw(&dev_queue->dql.num_queued);
  2222. #endif
  2223. }
  2224. /**
  2225. * netdev_txq_bql_complete_prefetchw - prefetch bql data for write
  2226. * @dev_queue: pointer to transmit queue
  2227. *
  2228. * BQL enabled drivers might use this helper in their TX completion path,
  2229. * to give appropriate hint to the cpu.
  2230. */
  2231. static inline void netdev_txq_bql_complete_prefetchw(struct netdev_queue *dev_queue)
  2232. {
  2233. #ifdef CONFIG_BQL
  2234. prefetchw(&dev_queue->dql.limit);
  2235. #endif
  2236. }
  2237. static inline void netdev_tx_sent_queue(struct netdev_queue *dev_queue,
  2238. unsigned int bytes)
  2239. {
  2240. #ifdef CONFIG_BQL
  2241. dql_queued(&dev_queue->dql, bytes);
  2242. if (likely(dql_avail(&dev_queue->dql) >= 0))
  2243. return;
  2244. set_bit(__QUEUE_STATE_STACK_XOFF, &dev_queue->state);
  2245. /*
  2246. * The XOFF flag must be set before checking the dql_avail below,
  2247. * because in netdev_tx_completed_queue we update the dql_completed
  2248. * before checking the XOFF flag.
  2249. */
  2250. smp_mb();
  2251. /* check again in case another CPU has just made room avail */
  2252. if (unlikely(dql_avail(&dev_queue->dql) >= 0))
  2253. clear_bit(__QUEUE_STATE_STACK_XOFF, &dev_queue->state);
  2254. #endif
  2255. }
  2256. /**
  2257. * netdev_sent_queue - report the number of bytes queued to hardware
  2258. * @dev: network device
  2259. * @bytes: number of bytes queued to the hardware device queue
  2260. *
  2261. * Report the number of bytes queued for sending/completion to the network
  2262. * device hardware queue. @bytes should be a good approximation and should
  2263. * exactly match netdev_completed_queue() @bytes
  2264. */
  2265. static inline void netdev_sent_queue(struct net_device *dev, unsigned int bytes)
  2266. {
  2267. netdev_tx_sent_queue(netdev_get_tx_queue(dev, 0), bytes);
  2268. }
  2269. static inline void netdev_tx_completed_queue(struct netdev_queue *dev_queue,
  2270. unsigned int pkts, unsigned int bytes)
  2271. {
  2272. #ifdef CONFIG_BQL
  2273. if (unlikely(!bytes))
  2274. return;
  2275. dql_completed(&dev_queue->dql, bytes);
  2276. /*
  2277. * Without the memory barrier there is a small possiblity that
  2278. * netdev_tx_sent_queue will miss the update and cause the queue to
  2279. * be stopped forever
  2280. */
  2281. smp_mb();
  2282. if (dql_avail(&dev_queue->dql) < 0)
  2283. return;
  2284. if (test_and_clear_bit(__QUEUE_STATE_STACK_XOFF, &dev_queue->state))
  2285. netif_schedule_queue(dev_queue);
  2286. #endif
  2287. }
  2288. /**
  2289. * netdev_completed_queue - report bytes and packets completed by device
  2290. * @dev: network device
  2291. * @pkts: actual number of packets sent over the medium
  2292. * @bytes: actual number of bytes sent over the medium
  2293. *
  2294. * Report the number of bytes and packets transmitted by the network device
  2295. * hardware queue over the physical medium, @bytes must exactly match the
  2296. * @bytes amount passed to netdev_sent_queue()
  2297. */
  2298. static inline void netdev_completed_queue(struct net_device *dev,
  2299. unsigned int pkts, unsigned int bytes)
  2300. {
  2301. netdev_tx_completed_queue(netdev_get_tx_queue(dev, 0), pkts, bytes);
  2302. }
  2303. static inline void netdev_tx_reset_queue(struct netdev_queue *q)
  2304. {
  2305. #ifdef CONFIG_BQL
  2306. clear_bit(__QUEUE_STATE_STACK_XOFF, &q->state);
  2307. dql_reset(&q->dql);
  2308. #endif
  2309. }
  2310. /**
  2311. * netdev_reset_queue - reset the packets and bytes count of a network device
  2312. * @dev_queue: network device
  2313. *
  2314. * Reset the bytes and packet count of a network device and clear the
  2315. * software flow control OFF bit for this network device
  2316. */
  2317. static inline void netdev_reset_queue(struct net_device *dev_queue)
  2318. {
  2319. netdev_tx_reset_queue(netdev_get_tx_queue(dev_queue, 0));
  2320. }
  2321. /**
  2322. * netdev_cap_txqueue - check if selected tx queue exceeds device queues
  2323. * @dev: network device
  2324. * @queue_index: given tx queue index
  2325. *
  2326. * Returns 0 if given tx queue index >= number of device tx queues,
  2327. * otherwise returns the originally passed tx queue index.
  2328. */
  2329. static inline u16 netdev_cap_txqueue(struct net_device *dev, u16 queue_index)
  2330. {
  2331. if (unlikely(queue_index >= dev->real_num_tx_queues)) {
  2332. net_warn_ratelimited("%s selects TX queue %d, but real number of TX queues is %d\n",
  2333. dev->name, queue_index,
  2334. dev->real_num_tx_queues);
  2335. return 0;
  2336. }
  2337. return queue_index;
  2338. }
  2339. /**
  2340. * netif_running - test if up
  2341. * @dev: network device
  2342. *
  2343. * Test if the device has been brought up.
  2344. */
  2345. static inline bool netif_running(const struct net_device *dev)
  2346. {
  2347. return test_bit(__LINK_STATE_START, &dev->state);
  2348. }
  2349. /*
  2350. * Routines to manage the subqueues on a device. We only need start
  2351. * stop, and a check if it's stopped. All other device management is
  2352. * done at the overall netdevice level.
  2353. * Also test the device if we're multiqueue.
  2354. */
  2355. /**
  2356. * netif_start_subqueue - allow sending packets on subqueue
  2357. * @dev: network device
  2358. * @queue_index: sub queue index
  2359. *
  2360. * Start individual transmit queue of a device with multiple transmit queues.
  2361. */
  2362. static inline void netif_start_subqueue(struct net_device *dev, u16 queue_index)
  2363. {
  2364. struct netdev_queue *txq = netdev_get_tx_queue(dev, queue_index);
  2365. netif_tx_start_queue(txq);
  2366. }
  2367. /**
  2368. * netif_stop_subqueue - stop sending packets on subqueue
  2369. * @dev: network device
  2370. * @queue_index: sub queue index
  2371. *
  2372. * Stop individual transmit queue of a device with multiple transmit queues.
  2373. */
  2374. static inline void netif_stop_subqueue(struct net_device *dev, u16 queue_index)
  2375. {
  2376. struct netdev_queue *txq = netdev_get_tx_queue(dev, queue_index);
  2377. netif_tx_stop_queue(txq);
  2378. }
  2379. /**
  2380. * netif_subqueue_stopped - test status of subqueue
  2381. * @dev: network device
  2382. * @queue_index: sub queue index
  2383. *
  2384. * Check individual transmit queue of a device with multiple transmit queues.
  2385. */
  2386. static inline bool __netif_subqueue_stopped(const struct net_device *dev,
  2387. u16 queue_index)
  2388. {
  2389. struct netdev_queue *txq = netdev_get_tx_queue(dev, queue_index);
  2390. return netif_tx_queue_stopped(txq);
  2391. }
  2392. static inline bool netif_subqueue_stopped(const struct net_device *dev,
  2393. struct sk_buff *skb)
  2394. {
  2395. return __netif_subqueue_stopped(dev, skb_get_queue_mapping(skb));
  2396. }
  2397. void netif_wake_subqueue(struct net_device *dev, u16 queue_index);
  2398. #ifdef CONFIG_XPS
  2399. int netif_set_xps_queue(struct net_device *dev, const struct cpumask *mask,
  2400. u16 index);
  2401. #else
  2402. static inline int netif_set_xps_queue(struct net_device *dev,
  2403. const struct cpumask *mask,
  2404. u16 index)
  2405. {
  2406. return 0;
  2407. }
  2408. #endif
  2409. /*
  2410. * Returns a Tx hash for the given packet when dev->real_num_tx_queues is used
  2411. * as a distribution range limit for the returned value.
  2412. */
  2413. static inline u16 skb_tx_hash(const struct net_device *dev,
  2414. struct sk_buff *skb)
  2415. {
  2416. return __skb_tx_hash(dev, skb, dev->real_num_tx_queues);
  2417. }
  2418. /**
  2419. * netif_is_multiqueue - test if device has multiple transmit queues
  2420. * @dev: network device
  2421. *
  2422. * Check if device has multiple transmit queues
  2423. */
  2424. static inline bool netif_is_multiqueue(const struct net_device *dev)
  2425. {
  2426. return dev->num_tx_queues > 1;
  2427. }
  2428. int netif_set_real_num_tx_queues(struct net_device *dev, unsigned int txq);
  2429. #ifdef CONFIG_SYSFS
  2430. int netif_set_real_num_rx_queues(struct net_device *dev, unsigned int rxq);
  2431. #else
  2432. static inline int netif_set_real_num_rx_queues(struct net_device *dev,
  2433. unsigned int rxq)
  2434. {
  2435. return 0;
  2436. }
  2437. #endif
  2438. static inline int netif_copy_real_num_queues(struct net_device *to_dev,
  2439. const struct net_device *from_dev)
  2440. {
  2441. int err;
  2442. err = netif_set_real_num_tx_queues(to_dev,
  2443. from_dev->real_num_tx_queues);
  2444. if (err)
  2445. return err;
  2446. #ifdef CONFIG_SYSFS
  2447. return netif_set_real_num_rx_queues(to_dev,
  2448. from_dev->real_num_rx_queues);
  2449. #else
  2450. return 0;
  2451. #endif
  2452. }
  2453. #ifdef CONFIG_SYSFS
  2454. static inline unsigned int get_netdev_rx_queue_index(
  2455. struct netdev_rx_queue *queue)
  2456. {
  2457. struct net_device *dev = queue->dev;
  2458. int index = queue - dev->_rx;
  2459. BUG_ON(index >= dev->num_rx_queues);
  2460. return index;
  2461. }
  2462. #endif
  2463. #define DEFAULT_MAX_NUM_RSS_QUEUES (8)
  2464. int netif_get_num_default_rss_queues(void);
  2465. enum skb_free_reason {
  2466. SKB_REASON_CONSUMED,
  2467. SKB_REASON_DROPPED,
  2468. };
  2469. void __dev_kfree_skb_irq(struct sk_buff *skb, enum skb_free_reason reason);
  2470. void __dev_kfree_skb_any(struct sk_buff *skb, enum skb_free_reason reason);
  2471. /*
  2472. * It is not allowed to call kfree_skb() or consume_skb() from hardware
  2473. * interrupt context or with hardware interrupts being disabled.
  2474. * (in_irq() || irqs_disabled())
  2475. *
  2476. * We provide four helpers that can be used in following contexts :
  2477. *
  2478. * dev_kfree_skb_irq(skb) when caller drops a packet from irq context,
  2479. * replacing kfree_skb(skb)
  2480. *
  2481. * dev_consume_skb_irq(skb) when caller consumes a packet from irq context.
  2482. * Typically used in place of consume_skb(skb) in TX completion path
  2483. *
  2484. * dev_kfree_skb_any(skb) when caller doesn't know its current irq context,
  2485. * replacing kfree_skb(skb)
  2486. *
  2487. * dev_consume_skb_any(skb) when caller doesn't know its current irq context,
  2488. * and consumed a packet. Used in place of consume_skb(skb)
  2489. */
  2490. static inline void dev_kfree_skb_irq(struct sk_buff *skb)
  2491. {
  2492. __dev_kfree_skb_irq(skb, SKB_REASON_DROPPED);
  2493. }
  2494. static inline void dev_consume_skb_irq(struct sk_buff *skb)
  2495. {
  2496. __dev_kfree_skb_irq(skb, SKB_REASON_CONSUMED);
  2497. }
  2498. static inline void dev_kfree_skb_any(struct sk_buff *skb)
  2499. {
  2500. __dev_kfree_skb_any(skb, SKB_REASON_DROPPED);
  2501. }
  2502. static inline void dev_consume_skb_any(struct sk_buff *skb)
  2503. {
  2504. __dev_kfree_skb_any(skb, SKB_REASON_CONSUMED);
  2505. }
  2506. int netif_rx(struct sk_buff *skb);
  2507. int netif_rx_ni(struct sk_buff *skb);
  2508. int netif_receive_skb(struct sk_buff *skb);
  2509. gro_result_t napi_gro_receive(struct napi_struct *napi, struct sk_buff *skb);
  2510. void napi_gro_flush(struct napi_struct *napi, bool flush_old);
  2511. struct sk_buff *napi_get_frags(struct napi_struct *napi);
  2512. gro_result_t napi_gro_frags(struct napi_struct *napi);
  2513. struct packet_offload *gro_find_receive_by_type(__be16 type);
  2514. struct packet_offload *gro_find_complete_by_type(__be16 type);
  2515. static inline void napi_free_frags(struct napi_struct *napi)
  2516. {
  2517. kfree_skb(napi->skb);
  2518. napi->skb = NULL;
  2519. }
  2520. int netdev_rx_handler_register(struct net_device *dev,
  2521. rx_handler_func_t *rx_handler,
  2522. void *rx_handler_data);
  2523. void netdev_rx_handler_unregister(struct net_device *dev);
  2524. bool dev_valid_name(const char *name);
  2525. int dev_ioctl(struct net *net, unsigned int cmd, void __user *);
  2526. int dev_ethtool(struct net *net, struct ifreq *);
  2527. unsigned int dev_get_flags(const struct net_device *);
  2528. int __dev_change_flags(struct net_device *, unsigned int flags);
  2529. int dev_change_flags(struct net_device *, unsigned int);
  2530. void __dev_notify_flags(struct net_device *, unsigned int old_flags,
  2531. unsigned int gchanges);
  2532. int dev_change_name(struct net_device *, const char *);
  2533. int dev_set_alias(struct net_device *, const char *, size_t);
  2534. int dev_change_net_namespace(struct net_device *, struct net *, const char *);
  2535. int dev_set_mtu(struct net_device *, int);
  2536. void dev_set_group(struct net_device *, int);
  2537. int dev_set_mac_address(struct net_device *, struct sockaddr *);
  2538. int dev_change_carrier(struct net_device *, bool new_carrier);
  2539. int dev_get_phys_port_id(struct net_device *dev,
  2540. struct netdev_phys_port_id *ppid);
  2541. struct sk_buff *validate_xmit_skb_list(struct sk_buff *skb, struct net_device *dev);
  2542. struct sk_buff *dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev,
  2543. struct netdev_queue *txq, int *ret);
  2544. int __dev_forward_skb(struct net_device *dev, struct sk_buff *skb);
  2545. int dev_forward_skb(struct net_device *dev, struct sk_buff *skb);
  2546. bool is_skb_forwardable(struct net_device *dev, struct sk_buff *skb);
  2547. extern int netdev_budget;
  2548. /* Called by rtnetlink.c:rtnl_unlock() */
  2549. void netdev_run_todo(void);
  2550. /**
  2551. * dev_put - release reference to device
  2552. * @dev: network device
  2553. *
  2554. * Release reference to device to allow it to be freed.
  2555. */
  2556. static inline void dev_put(struct net_device *dev)
  2557. {
  2558. this_cpu_dec(*dev->pcpu_refcnt);
  2559. }
  2560. /**
  2561. * dev_hold - get reference to device
  2562. * @dev: network device
  2563. *
  2564. * Hold reference to device to keep it from being freed.
  2565. */
  2566. static inline void dev_hold(struct net_device *dev)
  2567. {
  2568. this_cpu_inc(*dev->pcpu_refcnt);
  2569. }
  2570. /* Carrier loss detection, dial on demand. The functions netif_carrier_on
  2571. * and _off may be called from IRQ context, but it is caller
  2572. * who is responsible for serialization of these calls.
  2573. *
  2574. * The name carrier is inappropriate, these functions should really be
  2575. * called netif_lowerlayer_*() because they represent the state of any
  2576. * kind of lower layer not just hardware media.
  2577. */
  2578. void linkwatch_init_dev(struct net_device *dev);
  2579. void linkwatch_fire_event(struct net_device *dev);
  2580. void linkwatch_forget_dev(struct net_device *dev);
  2581. /**
  2582. * netif_carrier_ok - test if carrier present
  2583. * @dev: network device
  2584. *
  2585. * Check if carrier is present on device
  2586. */
  2587. static inline bool netif_carrier_ok(const struct net_device *dev)
  2588. {
  2589. return !test_bit(__LINK_STATE_NOCARRIER, &dev->state);
  2590. }
  2591. unsigned long dev_trans_start(struct net_device *dev);
  2592. void __netdev_watchdog_up(struct net_device *dev);
  2593. void netif_carrier_on(struct net_device *dev);
  2594. void netif_carrier_off(struct net_device *dev);
  2595. /**
  2596. * netif_dormant_on - mark device as dormant.
  2597. * @dev: network device
  2598. *
  2599. * Mark device as dormant (as per RFC2863).
  2600. *
  2601. * The dormant state indicates that the relevant interface is not
  2602. * actually in a condition to pass packets (i.e., it is not 'up') but is
  2603. * in a "pending" state, waiting for some external event. For "on-
  2604. * demand" interfaces, this new state identifies the situation where the
  2605. * interface is waiting for events to place it in the up state.
  2606. *
  2607. */
  2608. static inline void netif_dormant_on(struct net_device *dev)
  2609. {
  2610. if (!test_and_set_bit(__LINK_STATE_DORMANT, &dev->state))
  2611. linkwatch_fire_event(dev);
  2612. }
  2613. /**
  2614. * netif_dormant_off - set device as not dormant.
  2615. * @dev: network device
  2616. *
  2617. * Device is not in dormant state.
  2618. */
  2619. static inline void netif_dormant_off(struct net_device *dev)
  2620. {
  2621. if (test_and_clear_bit(__LINK_STATE_DORMANT, &dev->state))
  2622. linkwatch_fire_event(dev);
  2623. }
  2624. /**
  2625. * netif_dormant - test if carrier present
  2626. * @dev: network device
  2627. *
  2628. * Check if carrier is present on device
  2629. */
  2630. static inline bool netif_dormant(const struct net_device *dev)
  2631. {
  2632. return test_bit(__LINK_STATE_DORMANT, &dev->state);
  2633. }
  2634. /**
  2635. * netif_oper_up - test if device is operational
  2636. * @dev: network device
  2637. *
  2638. * Check if carrier is operational
  2639. */
  2640. static inline bool netif_oper_up(const struct net_device *dev)
  2641. {
  2642. return (dev->operstate == IF_OPER_UP ||
  2643. dev->operstate == IF_OPER_UNKNOWN /* backward compat */);
  2644. }
  2645. /**
  2646. * netif_device_present - is device available or removed
  2647. * @dev: network device
  2648. *
  2649. * Check if device has not been removed from system.
  2650. */
  2651. static inline bool netif_device_present(struct net_device *dev)
  2652. {
  2653. return test_bit(__LINK_STATE_PRESENT, &dev->state);
  2654. }
  2655. void netif_device_detach(struct net_device *dev);
  2656. void netif_device_attach(struct net_device *dev);
  2657. /*
  2658. * Network interface message level settings
  2659. */
  2660. enum {
  2661. NETIF_MSG_DRV = 0x0001,
  2662. NETIF_MSG_PROBE = 0x0002,
  2663. NETIF_MSG_LINK = 0x0004,
  2664. NETIF_MSG_TIMER = 0x0008,
  2665. NETIF_MSG_IFDOWN = 0x0010,
  2666. NETIF_MSG_IFUP = 0x0020,
  2667. NETIF_MSG_RX_ERR = 0x0040,
  2668. NETIF_MSG_TX_ERR = 0x0080,
  2669. NETIF_MSG_TX_QUEUED = 0x0100,
  2670. NETIF_MSG_INTR = 0x0200,
  2671. NETIF_MSG_TX_DONE = 0x0400,
  2672. NETIF_MSG_RX_STATUS = 0x0800,
  2673. NETIF_MSG_PKTDATA = 0x1000,
  2674. NETIF_MSG_HW = 0x2000,
  2675. NETIF_MSG_WOL = 0x4000,
  2676. };
  2677. #define netif_msg_drv(p) ((p)->msg_enable & NETIF_MSG_DRV)
  2678. #define netif_msg_probe(p) ((p)->msg_enable & NETIF_MSG_PROBE)
  2679. #define netif_msg_link(p) ((p)->msg_enable & NETIF_MSG_LINK)
  2680. #define netif_msg_timer(p) ((p)->msg_enable & NETIF_MSG_TIMER)
  2681. #define netif_msg_ifdown(p) ((p)->msg_enable & NETIF_MSG_IFDOWN)
  2682. #define netif_msg_ifup(p) ((p)->msg_enable & NETIF_MSG_IFUP)
  2683. #define netif_msg_rx_err(p) ((p)->msg_enable & NETIF_MSG_RX_ERR)
  2684. #define netif_msg_tx_err(p) ((p)->msg_enable & NETIF_MSG_TX_ERR)
  2685. #define netif_msg_tx_queued(p) ((p)->msg_enable & NETIF_MSG_TX_QUEUED)
  2686. #define netif_msg_intr(p) ((p)->msg_enable & NETIF_MSG_INTR)
  2687. #define netif_msg_tx_done(p) ((p)->msg_enable & NETIF_MSG_TX_DONE)
  2688. #define netif_msg_rx_status(p) ((p)->msg_enable & NETIF_MSG_RX_STATUS)
  2689. #define netif_msg_pktdata(p) ((p)->msg_enable & NETIF_MSG_PKTDATA)
  2690. #define netif_msg_hw(p) ((p)->msg_enable & NETIF_MSG_HW)
  2691. #define netif_msg_wol(p) ((p)->msg_enable & NETIF_MSG_WOL)
  2692. static inline u32 netif_msg_init(int debug_value, int default_msg_enable_bits)
  2693. {
  2694. /* use default */
  2695. if (debug_value < 0 || debug_value >= (sizeof(u32) * 8))
  2696. return default_msg_enable_bits;
  2697. if (debug_value == 0) /* no output */
  2698. return 0;
  2699. /* set low N bits */
  2700. return (1 << debug_value) - 1;
  2701. }
  2702. static inline void __netif_tx_lock(struct netdev_queue *txq, int cpu)
  2703. {
  2704. spin_lock(&txq->_xmit_lock);
  2705. txq->xmit_lock_owner = cpu;
  2706. }
  2707. static inline void __netif_tx_lock_bh(struct netdev_queue *txq)
  2708. {
  2709. spin_lock_bh(&txq->_xmit_lock);
  2710. txq->xmit_lock_owner = smp_processor_id();
  2711. }
  2712. static inline bool __netif_tx_trylock(struct netdev_queue *txq)
  2713. {
  2714. bool ok = spin_trylock(&txq->_xmit_lock);
  2715. if (likely(ok))
  2716. txq->xmit_lock_owner = smp_processor_id();
  2717. return ok;
  2718. }
  2719. static inline void __netif_tx_unlock(struct netdev_queue *txq)
  2720. {
  2721. txq->xmit_lock_owner = -1;
  2722. spin_unlock(&txq->_xmit_lock);
  2723. }
  2724. static inline void __netif_tx_unlock_bh(struct netdev_queue *txq)
  2725. {
  2726. txq->xmit_lock_owner = -1;
  2727. spin_unlock_bh(&txq->_xmit_lock);
  2728. }
  2729. static inline void txq_trans_update(struct netdev_queue *txq)
  2730. {
  2731. if (txq->xmit_lock_owner != -1)
  2732. txq->trans_start = jiffies;
  2733. }
  2734. /**
  2735. * netif_tx_lock - grab network device transmit lock
  2736. * @dev: network device
  2737. *
  2738. * Get network device transmit lock
  2739. */
  2740. static inline void netif_tx_lock(struct net_device *dev)
  2741. {
  2742. unsigned int i;
  2743. int cpu;
  2744. spin_lock(&dev->tx_global_lock);
  2745. cpu = smp_processor_id();
  2746. for (i = 0; i < dev->num_tx_queues; i++) {
  2747. struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
  2748. /* We are the only thread of execution doing a
  2749. * freeze, but we have to grab the _xmit_lock in
  2750. * order to synchronize with threads which are in
  2751. * the ->hard_start_xmit() handler and already
  2752. * checked the frozen bit.
  2753. */
  2754. __netif_tx_lock(txq, cpu);
  2755. set_bit(__QUEUE_STATE_FROZEN, &txq->state);
  2756. __netif_tx_unlock(txq);
  2757. }
  2758. }
  2759. static inline void netif_tx_lock_bh(struct net_device *dev)
  2760. {
  2761. local_bh_disable();
  2762. netif_tx_lock(dev);
  2763. }
  2764. static inline void netif_tx_unlock(struct net_device *dev)
  2765. {
  2766. unsigned int i;
  2767. for (i = 0; i < dev->num_tx_queues; i++) {
  2768. struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
  2769. /* No need to grab the _xmit_lock here. If the
  2770. * queue is not stopped for another reason, we
  2771. * force a schedule.
  2772. */
  2773. clear_bit(__QUEUE_STATE_FROZEN, &txq->state);
  2774. netif_schedule_queue(txq);
  2775. }
  2776. spin_unlock(&dev->tx_global_lock);
  2777. }
  2778. static inline void netif_tx_unlock_bh(struct net_device *dev)
  2779. {
  2780. netif_tx_unlock(dev);
  2781. local_bh_enable();
  2782. }
  2783. #define HARD_TX_LOCK(dev, txq, cpu) { \
  2784. if ((dev->features & NETIF_F_LLTX) == 0) { \
  2785. __netif_tx_lock(txq, cpu); \
  2786. } \
  2787. }
  2788. #define HARD_TX_TRYLOCK(dev, txq) \
  2789. (((dev->features & NETIF_F_LLTX) == 0) ? \
  2790. __netif_tx_trylock(txq) : \
  2791. true )
  2792. #define HARD_TX_UNLOCK(dev, txq) { \
  2793. if ((dev->features & NETIF_F_LLTX) == 0) { \
  2794. __netif_tx_unlock(txq); \
  2795. } \
  2796. }
  2797. static inline void netif_tx_disable(struct net_device *dev)
  2798. {
  2799. unsigned int i;
  2800. int cpu;
  2801. local_bh_disable();
  2802. cpu = smp_processor_id();
  2803. for (i = 0; i < dev->num_tx_queues; i++) {
  2804. struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
  2805. __netif_tx_lock(txq, cpu);
  2806. netif_tx_stop_queue(txq);
  2807. __netif_tx_unlock(txq);
  2808. }
  2809. local_bh_enable();
  2810. }
  2811. static inline void netif_addr_lock(struct net_device *dev)
  2812. {
  2813. spin_lock(&dev->addr_list_lock);
  2814. }
  2815. static inline void netif_addr_lock_nested(struct net_device *dev)
  2816. {
  2817. int subclass = SINGLE_DEPTH_NESTING;
  2818. if (dev->netdev_ops->ndo_get_lock_subclass)
  2819. subclass = dev->netdev_ops->ndo_get_lock_subclass(dev);
  2820. spin_lock_nested(&dev->addr_list_lock, subclass);
  2821. }
  2822. static inline void netif_addr_lock_bh(struct net_device *dev)
  2823. {
  2824. spin_lock_bh(&dev->addr_list_lock);
  2825. }
  2826. static inline void netif_addr_unlock(struct net_device *dev)
  2827. {
  2828. spin_unlock(&dev->addr_list_lock);
  2829. }
  2830. static inline void netif_addr_unlock_bh(struct net_device *dev)
  2831. {
  2832. spin_unlock_bh(&dev->addr_list_lock);
  2833. }
  2834. /*
  2835. * dev_addrs walker. Should be used only for read access. Call with
  2836. * rcu_read_lock held.
  2837. */
  2838. #define for_each_dev_addr(dev, ha) \
  2839. list_for_each_entry_rcu(ha, &dev->dev_addrs.list, list)
  2840. /* These functions live elsewhere (drivers/net/net_init.c, but related) */
  2841. void ether_setup(struct net_device *dev);
  2842. /* Support for loadable net-drivers */
  2843. struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name,
  2844. unsigned char name_assign_type,
  2845. void (*setup)(struct net_device *),
  2846. unsigned int txqs, unsigned int rxqs);
  2847. #define alloc_netdev(sizeof_priv, name, name_assign_type, setup) \
  2848. alloc_netdev_mqs(sizeof_priv, name, name_assign_type, setup, 1, 1)
  2849. #define alloc_netdev_mq(sizeof_priv, name, name_assign_type, setup, count) \
  2850. alloc_netdev_mqs(sizeof_priv, name, name_assign_type, setup, count, \
  2851. count)
  2852. int register_netdev(struct net_device *dev);
  2853. void unregister_netdev(struct net_device *dev);
  2854. /* General hardware address lists handling functions */
  2855. int __hw_addr_sync(struct netdev_hw_addr_list *to_list,
  2856. struct netdev_hw_addr_list *from_list, int addr_len);
  2857. void __hw_addr_unsync(struct netdev_hw_addr_list *to_list,
  2858. struct netdev_hw_addr_list *from_list, int addr_len);
  2859. int __hw_addr_sync_dev(struct netdev_hw_addr_list *list,
  2860. struct net_device *dev,
  2861. int (*sync)(struct net_device *, const unsigned char *),
  2862. int (*unsync)(struct net_device *,
  2863. const unsigned char *));
  2864. void __hw_addr_unsync_dev(struct netdev_hw_addr_list *list,
  2865. struct net_device *dev,
  2866. int (*unsync)(struct net_device *,
  2867. const unsigned char *));
  2868. void __hw_addr_init(struct netdev_hw_addr_list *list);
  2869. /* Functions used for device addresses handling */
  2870. int dev_addr_add(struct net_device *dev, const unsigned char *addr,
  2871. unsigned char addr_type);
  2872. int dev_addr_del(struct net_device *dev, const unsigned char *addr,
  2873. unsigned char addr_type);
  2874. void dev_addr_flush(struct net_device *dev);
  2875. int dev_addr_init(struct net_device *dev);
  2876. /* Functions used for unicast addresses handling */
  2877. int dev_uc_add(struct net_device *dev, const unsigned char *addr);
  2878. int dev_uc_add_excl(struct net_device *dev, const unsigned char *addr);
  2879. int dev_uc_del(struct net_device *dev, const unsigned char *addr);
  2880. int dev_uc_sync(struct net_device *to, struct net_device *from);
  2881. int dev_uc_sync_multiple(struct net_device *to, struct net_device *from);
  2882. void dev_uc_unsync(struct net_device *to, struct net_device *from);
  2883. void dev_uc_flush(struct net_device *dev);
  2884. void dev_uc_init(struct net_device *dev);
  2885. /**
  2886. * __dev_uc_sync - Synchonize device's unicast list
  2887. * @dev: device to sync
  2888. * @sync: function to call if address should be added
  2889. * @unsync: function to call if address should be removed
  2890. *
  2891. * Add newly added addresses to the interface, and release
  2892. * addresses that have been deleted.
  2893. **/
  2894. static inline int __dev_uc_sync(struct net_device *dev,
  2895. int (*sync)(struct net_device *,
  2896. const unsigned char *),
  2897. int (*unsync)(struct net_device *,
  2898. const unsigned char *))
  2899. {
  2900. return __hw_addr_sync_dev(&dev->uc, dev, sync, unsync);
  2901. }
  2902. /**
  2903. * __dev_uc_unsync - Remove synchronized addresses from device
  2904. * @dev: device to sync
  2905. * @unsync: function to call if address should be removed
  2906. *
  2907. * Remove all addresses that were added to the device by dev_uc_sync().
  2908. **/
  2909. static inline void __dev_uc_unsync(struct net_device *dev,
  2910. int (*unsync)(struct net_device *,
  2911. const unsigned char *))
  2912. {
  2913. __hw_addr_unsync_dev(&dev->uc, dev, unsync);
  2914. }
  2915. /* Functions used for multicast addresses handling */
  2916. int dev_mc_add(struct net_device *dev, const unsigned char *addr);
  2917. int dev_mc_add_global(struct net_device *dev, const unsigned char *addr);
  2918. int dev_mc_add_excl(struct net_device *dev, const unsigned char *addr);
  2919. int dev_mc_del(struct net_device *dev, const unsigned char *addr);
  2920. int dev_mc_del_global(struct net_device *dev, const unsigned char *addr);
  2921. int dev_mc_sync(struct net_device *to, struct net_device *from);
  2922. int dev_mc_sync_multiple(struct net_device *to, struct net_device *from);
  2923. void dev_mc_unsync(struct net_device *to, struct net_device *from);
  2924. void dev_mc_flush(struct net_device *dev);
  2925. void dev_mc_init(struct net_device *dev);
  2926. /**
  2927. * __dev_mc_sync - Synchonize device's multicast list
  2928. * @dev: device to sync
  2929. * @sync: function to call if address should be added
  2930. * @unsync: function to call if address should be removed
  2931. *
  2932. * Add newly added addresses to the interface, and release
  2933. * addresses that have been deleted.
  2934. **/
  2935. static inline int __dev_mc_sync(struct net_device *dev,
  2936. int (*sync)(struct net_device *,
  2937. const unsigned char *),
  2938. int (*unsync)(struct net_device *,
  2939. const unsigned char *))
  2940. {
  2941. return __hw_addr_sync_dev(&dev->mc, dev, sync, unsync);
  2942. }
  2943. /**
  2944. * __dev_mc_unsync - Remove synchronized addresses from device
  2945. * @dev: device to sync
  2946. * @unsync: function to call if address should be removed
  2947. *
  2948. * Remove all addresses that were added to the device by dev_mc_sync().
  2949. **/
  2950. static inline void __dev_mc_unsync(struct net_device *dev,
  2951. int (*unsync)(struct net_device *,
  2952. const unsigned char *))
  2953. {
  2954. __hw_addr_unsync_dev(&dev->mc, dev, unsync);
  2955. }
  2956. /* Functions used for secondary unicast and multicast support */
  2957. void dev_set_rx_mode(struct net_device *dev);
  2958. void __dev_set_rx_mode(struct net_device *dev);
  2959. int dev_set_promiscuity(struct net_device *dev, int inc);
  2960. int dev_set_allmulti(struct net_device *dev, int inc);
  2961. void netdev_state_change(struct net_device *dev);
  2962. void netdev_notify_peers(struct net_device *dev);
  2963. void netdev_features_change(struct net_device *dev);
  2964. /* Load a device via the kmod */
  2965. void dev_load(struct net *net, const char *name);
  2966. struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
  2967. struct rtnl_link_stats64 *storage);
  2968. void netdev_stats_to_stats64(struct rtnl_link_stats64 *stats64,
  2969. const struct net_device_stats *netdev_stats);
  2970. extern int netdev_max_backlog;
  2971. extern int netdev_tstamp_prequeue;
  2972. extern int weight_p;
  2973. extern int bpf_jit_enable;
  2974. bool netdev_has_upper_dev(struct net_device *dev, struct net_device *upper_dev);
  2975. struct net_device *netdev_upper_get_next_dev_rcu(struct net_device *dev,
  2976. struct list_head **iter);
  2977. struct net_device *netdev_all_upper_get_next_dev_rcu(struct net_device *dev,
  2978. struct list_head **iter);
  2979. /* iterate through upper list, must be called under RCU read lock */
  2980. #define netdev_for_each_upper_dev_rcu(dev, updev, iter) \
  2981. for (iter = &(dev)->adj_list.upper, \
  2982. updev = netdev_upper_get_next_dev_rcu(dev, &(iter)); \
  2983. updev; \
  2984. updev = netdev_upper_get_next_dev_rcu(dev, &(iter)))
  2985. /* iterate through upper list, must be called under RCU read lock */
  2986. #define netdev_for_each_all_upper_dev_rcu(dev, updev, iter) \
  2987. for (iter = &(dev)->all_adj_list.upper, \
  2988. updev = netdev_all_upper_get_next_dev_rcu(dev, &(iter)); \
  2989. updev; \
  2990. updev = netdev_all_upper_get_next_dev_rcu(dev, &(iter)))
  2991. void *netdev_lower_get_next_private(struct net_device *dev,
  2992. struct list_head **iter);
  2993. void *netdev_lower_get_next_private_rcu(struct net_device *dev,
  2994. struct list_head **iter);
  2995. #define netdev_for_each_lower_private(dev, priv, iter) \
  2996. for (iter = (dev)->adj_list.lower.next, \
  2997. priv = netdev_lower_get_next_private(dev, &(iter)); \
  2998. priv; \
  2999. priv = netdev_lower_get_next_private(dev, &(iter)))
  3000. #define netdev_for_each_lower_private_rcu(dev, priv, iter) \
  3001. for (iter = &(dev)->adj_list.lower, \
  3002. priv = netdev_lower_get_next_private_rcu(dev, &(iter)); \
  3003. priv; \
  3004. priv = netdev_lower_get_next_private_rcu(dev, &(iter)))
  3005. void *netdev_lower_get_next(struct net_device *dev,
  3006. struct list_head **iter);
  3007. #define netdev_for_each_lower_dev(dev, ldev, iter) \
  3008. for (iter = &(dev)->adj_list.lower, \
  3009. ldev = netdev_lower_get_next(dev, &(iter)); \
  3010. ldev; \
  3011. ldev = netdev_lower_get_next(dev, &(iter)))
  3012. void *netdev_adjacent_get_private(struct list_head *adj_list);
  3013. void *netdev_lower_get_first_private_rcu(struct net_device *dev);
  3014. struct net_device *netdev_master_upper_dev_get(struct net_device *dev);
  3015. struct net_device *netdev_master_upper_dev_get_rcu(struct net_device *dev);
  3016. int netdev_upper_dev_link(struct net_device *dev, struct net_device *upper_dev);
  3017. int netdev_master_upper_dev_link(struct net_device *dev,
  3018. struct net_device *upper_dev);
  3019. int netdev_master_upper_dev_link_private(struct net_device *dev,
  3020. struct net_device *upper_dev,
  3021. void *private);
  3022. void netdev_upper_dev_unlink(struct net_device *dev,
  3023. struct net_device *upper_dev);
  3024. void netdev_adjacent_rename_links(struct net_device *dev, char *oldname);
  3025. void *netdev_lower_dev_get_private(struct net_device *dev,
  3026. struct net_device *lower_dev);
  3027. int dev_get_nest_level(struct net_device *dev,
  3028. bool (*type_check)(struct net_device *dev));
  3029. int skb_checksum_help(struct sk_buff *skb);
  3030. struct sk_buff *__skb_gso_segment(struct sk_buff *skb,
  3031. netdev_features_t features, bool tx_path);
  3032. struct sk_buff *skb_mac_gso_segment(struct sk_buff *skb,
  3033. netdev_features_t features);
  3034. static inline
  3035. struct sk_buff *skb_gso_segment(struct sk_buff *skb, netdev_features_t features)
  3036. {
  3037. return __skb_gso_segment(skb, features, true);
  3038. }
  3039. __be16 skb_network_protocol(struct sk_buff *skb, int *depth);
  3040. static inline bool can_checksum_protocol(netdev_features_t features,
  3041. __be16 protocol)
  3042. {
  3043. return ((features & NETIF_F_GEN_CSUM) ||
  3044. ((features & NETIF_F_V4_CSUM) &&
  3045. protocol == htons(ETH_P_IP)) ||
  3046. ((features & NETIF_F_V6_CSUM) &&
  3047. protocol == htons(ETH_P_IPV6)) ||
  3048. ((features & NETIF_F_FCOE_CRC) &&
  3049. protocol == htons(ETH_P_FCOE)));
  3050. }
  3051. #ifdef CONFIG_BUG
  3052. void netdev_rx_csum_fault(struct net_device *dev);
  3053. #else
  3054. static inline void netdev_rx_csum_fault(struct net_device *dev)
  3055. {
  3056. }
  3057. #endif
  3058. /* rx skb timestamps */
  3059. void net_enable_timestamp(void);
  3060. void net_disable_timestamp(void);
  3061. #ifdef CONFIG_PROC_FS
  3062. int __init dev_proc_init(void);
  3063. #else
  3064. #define dev_proc_init() 0
  3065. #endif
  3066. static inline netdev_tx_t __netdev_start_xmit(const struct net_device_ops *ops,
  3067. struct sk_buff *skb, struct net_device *dev,
  3068. bool more)
  3069. {
  3070. skb->xmit_more = more ? 1 : 0;
  3071. return ops->ndo_start_xmit(skb, dev);
  3072. }
  3073. static inline netdev_tx_t netdev_start_xmit(struct sk_buff *skb, struct net_device *dev,
  3074. struct netdev_queue *txq, bool more)
  3075. {
  3076. const struct net_device_ops *ops = dev->netdev_ops;
  3077. int rc;
  3078. rc = __netdev_start_xmit(ops, skb, dev, more);
  3079. if (rc == NETDEV_TX_OK)
  3080. txq_trans_update(txq);
  3081. return rc;
  3082. }
  3083. int netdev_class_create_file_ns(struct class_attribute *class_attr,
  3084. const void *ns);
  3085. void netdev_class_remove_file_ns(struct class_attribute *class_attr,
  3086. const void *ns);
  3087. static inline int netdev_class_create_file(struct class_attribute *class_attr)
  3088. {
  3089. return netdev_class_create_file_ns(class_attr, NULL);
  3090. }
  3091. static inline void netdev_class_remove_file(struct class_attribute *class_attr)
  3092. {
  3093. netdev_class_remove_file_ns(class_attr, NULL);
  3094. }
  3095. extern struct kobj_ns_type_operations net_ns_type_operations;
  3096. const char *netdev_drivername(const struct net_device *dev);
  3097. void linkwatch_run_queue(void);
  3098. static inline netdev_features_t netdev_intersect_features(netdev_features_t f1,
  3099. netdev_features_t f2)
  3100. {
  3101. if (f1 & NETIF_F_GEN_CSUM)
  3102. f1 |= (NETIF_F_ALL_CSUM & ~NETIF_F_GEN_CSUM);
  3103. if (f2 & NETIF_F_GEN_CSUM)
  3104. f2 |= (NETIF_F_ALL_CSUM & ~NETIF_F_GEN_CSUM);
  3105. f1 &= f2;
  3106. if (f1 & NETIF_F_GEN_CSUM)
  3107. f1 &= ~(NETIF_F_ALL_CSUM & ~NETIF_F_GEN_CSUM);
  3108. return f1;
  3109. }
  3110. static inline netdev_features_t netdev_get_wanted_features(
  3111. struct net_device *dev)
  3112. {
  3113. return (dev->features & ~dev->hw_features) | dev->wanted_features;
  3114. }
  3115. netdev_features_t netdev_increment_features(netdev_features_t all,
  3116. netdev_features_t one, netdev_features_t mask);
  3117. /* Allow TSO being used on stacked device :
  3118. * Performing the GSO segmentation before last device
  3119. * is a performance improvement.
  3120. */
  3121. static inline netdev_features_t netdev_add_tso_features(netdev_features_t features,
  3122. netdev_features_t mask)
  3123. {
  3124. return netdev_increment_features(features, NETIF_F_ALL_TSO, mask);
  3125. }
  3126. int __netdev_update_features(struct net_device *dev);
  3127. void netdev_update_features(struct net_device *dev);
  3128. void netdev_change_features(struct net_device *dev);
  3129. void netif_stacked_transfer_operstate(const struct net_device *rootdev,
  3130. struct net_device *dev);
  3131. netdev_features_t netif_skb_features(struct sk_buff *skb);
  3132. static inline bool net_gso_ok(netdev_features_t features, int gso_type)
  3133. {
  3134. netdev_features_t feature = gso_type << NETIF_F_GSO_SHIFT;
  3135. /* check flags correspondence */
  3136. BUILD_BUG_ON(SKB_GSO_TCPV4 != (NETIF_F_TSO >> NETIF_F_GSO_SHIFT));
  3137. BUILD_BUG_ON(SKB_GSO_UDP != (NETIF_F_UFO >> NETIF_F_GSO_SHIFT));
  3138. BUILD_BUG_ON(SKB_GSO_DODGY != (NETIF_F_GSO_ROBUST >> NETIF_F_GSO_SHIFT));
  3139. BUILD_BUG_ON(SKB_GSO_TCP_ECN != (NETIF_F_TSO_ECN >> NETIF_F_GSO_SHIFT));
  3140. BUILD_BUG_ON(SKB_GSO_TCPV6 != (NETIF_F_TSO6 >> NETIF_F_GSO_SHIFT));
  3141. BUILD_BUG_ON(SKB_GSO_FCOE != (NETIF_F_FSO >> NETIF_F_GSO_SHIFT));
  3142. BUILD_BUG_ON(SKB_GSO_GRE != (NETIF_F_GSO_GRE >> NETIF_F_GSO_SHIFT));
  3143. BUILD_BUG_ON(SKB_GSO_GRE_CSUM != (NETIF_F_GSO_GRE_CSUM >> NETIF_F_GSO_SHIFT));
  3144. BUILD_BUG_ON(SKB_GSO_IPIP != (NETIF_F_GSO_IPIP >> NETIF_F_GSO_SHIFT));
  3145. BUILD_BUG_ON(SKB_GSO_SIT != (NETIF_F_GSO_SIT >> NETIF_F_GSO_SHIFT));
  3146. BUILD_BUG_ON(SKB_GSO_UDP_TUNNEL != (NETIF_F_GSO_UDP_TUNNEL >> NETIF_F_GSO_SHIFT));
  3147. BUILD_BUG_ON(SKB_GSO_UDP_TUNNEL_CSUM != (NETIF_F_GSO_UDP_TUNNEL_CSUM >> NETIF_F_GSO_SHIFT));
  3148. BUILD_BUG_ON(SKB_GSO_MPLS != (NETIF_F_GSO_MPLS >> NETIF_F_GSO_SHIFT));
  3149. return (features & feature) == feature;
  3150. }
  3151. static inline bool skb_gso_ok(struct sk_buff *skb, netdev_features_t features)
  3152. {
  3153. return net_gso_ok(features, skb_shinfo(skb)->gso_type) &&
  3154. (!skb_has_frag_list(skb) || (features & NETIF_F_FRAGLIST));
  3155. }
  3156. static inline bool netif_needs_gso(struct net_device *dev, struct sk_buff *skb,
  3157. netdev_features_t features)
  3158. {
  3159. return skb_is_gso(skb) && (!skb_gso_ok(skb, features) ||
  3160. (dev->netdev_ops->ndo_gso_check &&
  3161. !dev->netdev_ops->ndo_gso_check(skb, dev)) ||
  3162. unlikely((skb->ip_summed != CHECKSUM_PARTIAL) &&
  3163. (skb->ip_summed != CHECKSUM_UNNECESSARY)));
  3164. }
  3165. static inline void netif_set_gso_max_size(struct net_device *dev,
  3166. unsigned int size)
  3167. {
  3168. dev->gso_max_size = size;
  3169. }
  3170. static inline void skb_gso_error_unwind(struct sk_buff *skb, __be16 protocol,
  3171. int pulled_hlen, u16 mac_offset,
  3172. int mac_len)
  3173. {
  3174. skb->protocol = protocol;
  3175. skb->encapsulation = 1;
  3176. skb_push(skb, pulled_hlen);
  3177. skb_reset_transport_header(skb);
  3178. skb->mac_header = mac_offset;
  3179. skb->network_header = skb->mac_header + mac_len;
  3180. skb->mac_len = mac_len;
  3181. }
  3182. static inline bool netif_is_macvlan(struct net_device *dev)
  3183. {
  3184. return dev->priv_flags & IFF_MACVLAN;
  3185. }
  3186. static inline bool netif_is_bond_master(struct net_device *dev)
  3187. {
  3188. return dev->flags & IFF_MASTER && dev->priv_flags & IFF_BONDING;
  3189. }
  3190. static inline bool netif_is_bond_slave(struct net_device *dev)
  3191. {
  3192. return dev->flags & IFF_SLAVE && dev->priv_flags & IFF_BONDING;
  3193. }
  3194. static inline bool netif_supports_nofcs(struct net_device *dev)
  3195. {
  3196. return dev->priv_flags & IFF_SUPP_NOFCS;
  3197. }
  3198. /* This device needs to keep skb dst for qdisc enqueue or ndo_start_xmit() */
  3199. static inline void netif_keep_dst(struct net_device *dev)
  3200. {
  3201. dev->priv_flags &= ~(IFF_XMIT_DST_RELEASE | IFF_XMIT_DST_RELEASE_PERM);
  3202. }
  3203. extern struct pernet_operations __net_initdata loopback_net_ops;
  3204. /* Logging, debugging and troubleshooting/diagnostic helpers. */
  3205. /* netdev_printk helpers, similar to dev_printk */
  3206. static inline const char *netdev_name(const struct net_device *dev)
  3207. {
  3208. if (!dev->name[0] || strchr(dev->name, '%'))
  3209. return "(unnamed net_device)";
  3210. return dev->name;
  3211. }
  3212. static inline const char *netdev_reg_state(const struct net_device *dev)
  3213. {
  3214. switch (dev->reg_state) {
  3215. case NETREG_UNINITIALIZED: return " (uninitialized)";
  3216. case NETREG_REGISTERED: return "";
  3217. case NETREG_UNREGISTERING: return " (unregistering)";
  3218. case NETREG_UNREGISTERED: return " (unregistered)";
  3219. case NETREG_RELEASED: return " (released)";
  3220. case NETREG_DUMMY: return " (dummy)";
  3221. }
  3222. WARN_ONCE(1, "%s: unknown reg_state %d\n", dev->name, dev->reg_state);
  3223. return " (unknown)";
  3224. }
  3225. __printf(3, 4)
  3226. void netdev_printk(const char *level, const struct net_device *dev,
  3227. const char *format, ...);
  3228. __printf(2, 3)
  3229. void netdev_emerg(const struct net_device *dev, const char *format, ...);
  3230. __printf(2, 3)
  3231. void netdev_alert(const struct net_device *dev, const char *format, ...);
  3232. __printf(2, 3)
  3233. void netdev_crit(const struct net_device *dev, const char *format, ...);
  3234. __printf(2, 3)
  3235. void netdev_err(const struct net_device *dev, const char *format, ...);
  3236. __printf(2, 3)
  3237. void netdev_warn(const struct net_device *dev, const char *format, ...);
  3238. __printf(2, 3)
  3239. void netdev_notice(const struct net_device *dev, const char *format, ...);
  3240. __printf(2, 3)
  3241. void netdev_info(const struct net_device *dev, const char *format, ...);
  3242. #define MODULE_ALIAS_NETDEV(device) \
  3243. MODULE_ALIAS("netdev-" device)
  3244. #if defined(CONFIG_DYNAMIC_DEBUG)
  3245. #define netdev_dbg(__dev, format, args...) \
  3246. do { \
  3247. dynamic_netdev_dbg(__dev, format, ##args); \
  3248. } while (0)
  3249. #elif defined(DEBUG)
  3250. #define netdev_dbg(__dev, format, args...) \
  3251. netdev_printk(KERN_DEBUG, __dev, format, ##args)
  3252. #else
  3253. #define netdev_dbg(__dev, format, args...) \
  3254. ({ \
  3255. if (0) \
  3256. netdev_printk(KERN_DEBUG, __dev, format, ##args); \
  3257. })
  3258. #endif
  3259. #if defined(VERBOSE_DEBUG)
  3260. #define netdev_vdbg netdev_dbg
  3261. #else
  3262. #define netdev_vdbg(dev, format, args...) \
  3263. ({ \
  3264. if (0) \
  3265. netdev_printk(KERN_DEBUG, dev, format, ##args); \
  3266. 0; \
  3267. })
  3268. #endif
  3269. /*
  3270. * netdev_WARN() acts like dev_printk(), but with the key difference
  3271. * of using a WARN/WARN_ON to get the message out, including the
  3272. * file/line information and a backtrace.
  3273. */
  3274. #define netdev_WARN(dev, format, args...) \
  3275. WARN(1, "netdevice: %s%s\n" format, netdev_name(dev), \
  3276. netdev_reg_state(dev), ##args)
  3277. /* netif printk helpers, similar to netdev_printk */
  3278. #define netif_printk(priv, type, level, dev, fmt, args...) \
  3279. do { \
  3280. if (netif_msg_##type(priv)) \
  3281. netdev_printk(level, (dev), fmt, ##args); \
  3282. } while (0)
  3283. #define netif_level(level, priv, type, dev, fmt, args...) \
  3284. do { \
  3285. if (netif_msg_##type(priv)) \
  3286. netdev_##level(dev, fmt, ##args); \
  3287. } while (0)
  3288. #define netif_emerg(priv, type, dev, fmt, args...) \
  3289. netif_level(emerg, priv, type, dev, fmt, ##args)
  3290. #define netif_alert(priv, type, dev, fmt, args...) \
  3291. netif_level(alert, priv, type, dev, fmt, ##args)
  3292. #define netif_crit(priv, type, dev, fmt, args...) \
  3293. netif_level(crit, priv, type, dev, fmt, ##args)
  3294. #define netif_err(priv, type, dev, fmt, args...) \
  3295. netif_level(err, priv, type, dev, fmt, ##args)
  3296. #define netif_warn(priv, type, dev, fmt, args...) \
  3297. netif_level(warn, priv, type, dev, fmt, ##args)
  3298. #define netif_notice(priv, type, dev, fmt, args...) \
  3299. netif_level(notice, priv, type, dev, fmt, ##args)
  3300. #define netif_info(priv, type, dev, fmt, args...) \
  3301. netif_level(info, priv, type, dev, fmt, ##args)
  3302. #if defined(CONFIG_DYNAMIC_DEBUG)
  3303. #define netif_dbg(priv, type, netdev, format, args...) \
  3304. do { \
  3305. if (netif_msg_##type(priv)) \
  3306. dynamic_netdev_dbg(netdev, format, ##args); \
  3307. } while (0)
  3308. #elif defined(DEBUG)
  3309. #define netif_dbg(priv, type, dev, format, args...) \
  3310. netif_printk(priv, type, KERN_DEBUG, dev, format, ##args)
  3311. #else
  3312. #define netif_dbg(priv, type, dev, format, args...) \
  3313. ({ \
  3314. if (0) \
  3315. netif_printk(priv, type, KERN_DEBUG, dev, format, ##args); \
  3316. 0; \
  3317. })
  3318. #endif
  3319. #if defined(VERBOSE_DEBUG)
  3320. #define netif_vdbg netif_dbg
  3321. #else
  3322. #define netif_vdbg(priv, type, dev, format, args...) \
  3323. ({ \
  3324. if (0) \
  3325. netif_printk(priv, type, KERN_DEBUG, dev, format, ##args); \
  3326. 0; \
  3327. })
  3328. #endif
  3329. /*
  3330. * The list of packet types we will receive (as opposed to discard)
  3331. * and the routines to invoke.
  3332. *
  3333. * Why 16. Because with 16 the only overlap we get on a hash of the
  3334. * low nibble of the protocol value is RARP/SNAP/X.25.
  3335. *
  3336. * NOTE: That is no longer true with the addition of VLAN tags. Not
  3337. * sure which should go first, but I bet it won't make much
  3338. * difference if we are running VLANs. The good news is that
  3339. * this protocol won't be in the list unless compiled in, so
  3340. * the average user (w/out VLANs) will not be adversely affected.
  3341. * --BLG
  3342. *
  3343. * 0800 IP
  3344. * 8100 802.1Q VLAN
  3345. * 0001 802.3
  3346. * 0002 AX.25
  3347. * 0004 802.2
  3348. * 8035 RARP
  3349. * 0005 SNAP
  3350. * 0805 X.25
  3351. * 0806 ARP
  3352. * 8137 IPX
  3353. * 0009 Localtalk
  3354. * 86DD IPv6
  3355. */
  3356. #define PTYPE_HASH_SIZE (16)
  3357. #define PTYPE_HASH_MASK (PTYPE_HASH_SIZE - 1)
  3358. #endif /* _LINUX_NETDEVICE_H */