netdevice.h 104 KB

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