1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25#ifndef _LINUX_NETDEVICE_H
26#define _LINUX_NETDEVICE_H
27
28#include <linux/pm_qos.h>
29#include <linux/timer.h>
30#include <linux/bug.h>
31#include <linux/delay.h>
32#include <linux/atomic.h>
33#include <asm/cache.h>
34#include <asm/byteorder.h>
35
36#include <linux/percpu.h>
37#include <linux/rculist.h>
38#include <linux/dmaengine.h>
39#include <linux/workqueue.h>
40#include <linux/dynamic_queue_limits.h>
41
42#include <linux/ethtool.h>
43#include <net/net_namespace.h>
44#include <net/dsa.h>
45#ifdef CONFIG_DCB
46#include <net/dcbnl.h>
47#endif
48#include <net/netprio_cgroup.h>
49
50#include <linux/netdev_features.h>
51#include <linux/neighbour.h>
52#include <uapi/linux/netdevice.h>
53
54struct netpoll_info;
55struct device;
56struct phy_device;
57
58struct wireless_dev;
59
60#define SET_ETHTOOL_OPS(netdev,ops) \
61 ( (netdev)->ethtool_ops = (ops) )
62
63void netdev_set_default_ethtool_ops(struct net_device *dev,
64 const struct ethtool_ops *ops);
65
66
67#define NET_RX_SUCCESS 0
68#define NET_RX_DROP 1
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88#define NET_XMIT_SUCCESS 0x00
89#define NET_XMIT_DROP 0x01
90#define NET_XMIT_CN 0x02
91#define NET_XMIT_POLICED 0x03
92#define NET_XMIT_MASK 0x0f
93
94
95
96
97#define net_xmit_eval(e) ((e) == NET_XMIT_CN ? 0 : (e))
98#define net_xmit_errno(e) ((e) != NET_XMIT_CN ? -ENOBUFS : 0)
99
100
101#define NETDEV_TX_MASK 0xf0
102
103enum netdev_tx {
104 __NETDEV_TX_MIN = INT_MIN,
105 NETDEV_TX_OK = 0x00,
106 NETDEV_TX_BUSY = 0x10,
107 NETDEV_TX_LOCKED = 0x20,
108};
109typedef enum netdev_tx netdev_tx_t;
110
111
112
113
114
115static inline bool dev_xmit_complete(int rc)
116{
117
118
119
120
121
122
123 if (likely(rc < NET_XMIT_MASK))
124 return true;
125
126 return false;
127}
128
129
130
131
132
133
134#if defined(CONFIG_WLAN) || IS_ENABLED(CONFIG_AX25)
135# if defined(CONFIG_MAC80211_MESH)
136# define LL_MAX_HEADER 128
137# else
138# define LL_MAX_HEADER 96
139# endif
140#else
141# define LL_MAX_HEADER 32
142#endif
143
144#if !IS_ENABLED(CONFIG_NET_IPIP) && !IS_ENABLED(CONFIG_NET_IPGRE) && \
145 !IS_ENABLED(CONFIG_IPV6_SIT) && !IS_ENABLED(CONFIG_IPV6_TUNNEL)
146#define MAX_HEADER LL_MAX_HEADER
147#else
148#define MAX_HEADER (LL_MAX_HEADER + 48)
149#endif
150
151
152
153
154
155
156struct net_device_stats {
157 unsigned long rx_packets;
158 unsigned long tx_packets;
159 unsigned long rx_bytes;
160 unsigned long tx_bytes;
161 unsigned long rx_errors;
162 unsigned long tx_errors;
163 unsigned long rx_dropped;
164 unsigned long tx_dropped;
165 unsigned long multicast;
166 unsigned long collisions;
167 unsigned long rx_length_errors;
168 unsigned long rx_over_errors;
169 unsigned long rx_crc_errors;
170 unsigned long rx_frame_errors;
171 unsigned long rx_fifo_errors;
172 unsigned long rx_missed_errors;
173 unsigned long tx_aborted_errors;
174 unsigned long tx_carrier_errors;
175 unsigned long tx_fifo_errors;
176 unsigned long tx_heartbeat_errors;
177 unsigned long tx_window_errors;
178 unsigned long rx_compressed;
179 unsigned long tx_compressed;
180};
181
182
183#include <linux/cache.h>
184#include <linux/skbuff.h>
185
186#ifdef CONFIG_RPS
187#include <linux/static_key.h>
188extern struct static_key rps_needed;
189#endif
190
191struct neighbour;
192struct neigh_parms;
193struct sk_buff;
194
195struct netdev_hw_addr {
196 struct list_head list;
197 unsigned char addr[MAX_ADDR_LEN];
198 unsigned char type;
199#define NETDEV_HW_ADDR_T_LAN 1
200#define NETDEV_HW_ADDR_T_SAN 2
201#define NETDEV_HW_ADDR_T_SLAVE 3
202#define NETDEV_HW_ADDR_T_UNICAST 4
203#define NETDEV_HW_ADDR_T_MULTICAST 5
204 bool global_use;
205 int sync_cnt;
206 int refcount;
207 int synced;
208 struct rcu_head rcu_head;
209};
210
211struct netdev_hw_addr_list {
212 struct list_head list;
213 int count;
214};
215
216#define netdev_hw_addr_list_count(l) ((l)->count)
217#define netdev_hw_addr_list_empty(l) (netdev_hw_addr_list_count(l) == 0)
218#define netdev_hw_addr_list_for_each(ha, l) \
219 list_for_each_entry(ha, &(l)->list, list)
220
221#define netdev_uc_count(dev) netdev_hw_addr_list_count(&(dev)->uc)
222#define netdev_uc_empty(dev) netdev_hw_addr_list_empty(&(dev)->uc)
223#define netdev_for_each_uc_addr(ha, dev) \
224 netdev_hw_addr_list_for_each(ha, &(dev)->uc)
225
226#define netdev_mc_count(dev) netdev_hw_addr_list_count(&(dev)->mc)
227#define netdev_mc_empty(dev) netdev_hw_addr_list_empty(&(dev)->mc)
228#define netdev_for_each_mc_addr(ha, dev) \
229 netdev_hw_addr_list_for_each(ha, &(dev)->mc)
230
231struct hh_cache {
232 u16 hh_len;
233 u16 __pad;
234 seqlock_t hh_lock;
235
236
237#define HH_DATA_MOD 16
238#define HH_DATA_OFF(__len) \
239 (HH_DATA_MOD - (((__len - 1) & (HH_DATA_MOD - 1)) + 1))
240#define HH_DATA_ALIGN(__len) \
241 (((__len)+(HH_DATA_MOD-1))&~(HH_DATA_MOD - 1))
242 unsigned long hh_data[HH_DATA_ALIGN(LL_MAX_HEADER) / sizeof(long)];
243};
244
245
246
247
248
249
250
251
252
253#define LL_RESERVED_SPACE(dev) \
254 ((((dev)->hard_header_len+(dev)->needed_headroom)&~(HH_DATA_MOD - 1)) + HH_DATA_MOD)
255#define LL_RESERVED_SPACE_EXTRA(dev,extra) \
256 ((((dev)->hard_header_len+(dev)->needed_headroom+(extra))&~(HH_DATA_MOD - 1)) + HH_DATA_MOD)
257
258struct header_ops {
259 int (*create) (struct sk_buff *skb, struct net_device *dev,
260 unsigned short type, const void *daddr,
261 const void *saddr, unsigned int len);
262 int (*parse)(const struct sk_buff *skb, unsigned char *haddr);
263 int (*rebuild)(struct sk_buff *skb);
264 int (*cache)(const struct neighbour *neigh, struct hh_cache *hh, __be16 type);
265 void (*cache_update)(struct hh_cache *hh,
266 const struct net_device *dev,
267 const unsigned char *haddr);
268};
269
270
271
272
273
274
275enum netdev_state_t {
276 __LINK_STATE_START,
277 __LINK_STATE_PRESENT,
278 __LINK_STATE_NOCARRIER,
279 __LINK_STATE_LINKWATCH_PENDING,
280 __LINK_STATE_DORMANT,
281};
282
283
284
285
286
287
288struct netdev_boot_setup {
289 char name[IFNAMSIZ];
290 struct ifmap map;
291};
292#define NETDEV_BOOT_SETUP_MAX 8
293
294int __init netdev_boot_setup(char *str);
295
296
297
298
299struct napi_struct {
300
301
302
303
304
305
306 struct list_head poll_list;
307
308 unsigned long state;
309 int weight;
310 unsigned int gro_count;
311 int (*poll)(struct napi_struct *, int);
312#ifdef CONFIG_NETPOLL
313 spinlock_t poll_lock;
314 int poll_owner;
315#endif
316 struct net_device *dev;
317 struct sk_buff *gro_list;
318 struct sk_buff *skb;
319 struct list_head dev_list;
320 struct hlist_node napi_hash_node;
321 unsigned int napi_id;
322};
323
324enum {
325 NAPI_STATE_SCHED,
326 NAPI_STATE_DISABLE,
327 NAPI_STATE_NPSVC,
328 NAPI_STATE_HASHED,
329};
330
331enum gro_result {
332 GRO_MERGED,
333 GRO_MERGED_FREE,
334 GRO_HELD,
335 GRO_NORMAL,
336 GRO_DROP,
337};
338typedef enum gro_result gro_result_t;
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381enum rx_handler_result {
382 RX_HANDLER_CONSUMED,
383 RX_HANDLER_ANOTHER,
384 RX_HANDLER_EXACT,
385 RX_HANDLER_PASS,
386};
387typedef enum rx_handler_result rx_handler_result_t;
388typedef rx_handler_result_t rx_handler_func_t(struct sk_buff **pskb);
389
390void __napi_schedule(struct napi_struct *n);
391
392static inline bool napi_disable_pending(struct napi_struct *n)
393{
394 return test_bit(NAPI_STATE_DISABLE, &n->state);
395}
396
397
398
399
400
401
402
403
404
405
406static inline bool napi_schedule_prep(struct napi_struct *n)
407{
408 return !napi_disable_pending(n) &&
409 !test_and_set_bit(NAPI_STATE_SCHED, &n->state);
410}
411
412
413
414
415
416
417
418
419static inline void napi_schedule(struct napi_struct *n)
420{
421 if (napi_schedule_prep(n))
422 __napi_schedule(n);
423}
424
425
426static inline bool napi_reschedule(struct napi_struct *napi)
427{
428 if (napi_schedule_prep(napi)) {
429 __napi_schedule(napi);
430 return true;
431 }
432 return false;
433}
434
435
436
437
438
439
440
441void __napi_complete(struct napi_struct *n);
442void napi_complete(struct napi_struct *n);
443
444
445
446
447
448
449
450
451struct napi_struct *napi_by_id(unsigned int napi_id);
452
453
454
455
456
457
458
459void napi_hash_add(struct napi_struct *napi);
460
461
462
463
464
465
466
467
468void napi_hash_del(struct napi_struct *napi);
469
470
471
472
473
474
475
476
477static inline void napi_disable(struct napi_struct *n)
478{
479 might_sleep();
480 set_bit(NAPI_STATE_DISABLE, &n->state);
481 while (test_and_set_bit(NAPI_STATE_SCHED, &n->state))
482 msleep(1);
483 clear_bit(NAPI_STATE_DISABLE, &n->state);
484}
485
486
487
488
489
490
491
492
493static inline void napi_enable(struct napi_struct *n)
494{
495 BUG_ON(!test_bit(NAPI_STATE_SCHED, &n->state));
496 smp_mb__before_clear_bit();
497 clear_bit(NAPI_STATE_SCHED, &n->state);
498}
499
500#ifdef CONFIG_SMP
501
502
503
504
505
506
507
508
509static inline void napi_synchronize(const struct napi_struct *n)
510{
511 while (test_bit(NAPI_STATE_SCHED, &n->state))
512 msleep(1);
513}
514#else
515# define napi_synchronize(n) barrier()
516#endif
517
518enum netdev_queue_state_t {
519 __QUEUE_STATE_DRV_XOFF,
520 __QUEUE_STATE_STACK_XOFF,
521 __QUEUE_STATE_FROZEN,
522};
523
524#define QUEUE_STATE_DRV_XOFF (1 << __QUEUE_STATE_DRV_XOFF)
525#define QUEUE_STATE_STACK_XOFF (1 << __QUEUE_STATE_STACK_XOFF)
526#define QUEUE_STATE_FROZEN (1 << __QUEUE_STATE_FROZEN)
527
528#define QUEUE_STATE_ANY_XOFF (QUEUE_STATE_DRV_XOFF | QUEUE_STATE_STACK_XOFF)
529#define QUEUE_STATE_ANY_XOFF_OR_FROZEN (QUEUE_STATE_ANY_XOFF | \
530 QUEUE_STATE_FROZEN)
531#define QUEUE_STATE_DRV_XOFF_OR_FROZEN (QUEUE_STATE_DRV_XOFF | \
532 QUEUE_STATE_FROZEN)
533
534
535
536
537
538
539
540
541
542
543
544struct netdev_queue {
545
546
547
548 struct net_device *dev;
549 struct Qdisc *qdisc;
550 struct Qdisc *qdisc_sleeping;
551#ifdef CONFIG_SYSFS
552 struct kobject kobj;
553#endif
554#if defined(CONFIG_XPS) && defined(CONFIG_NUMA)
555 int numa_node;
556#endif
557
558
559
560 spinlock_t _xmit_lock ____cacheline_aligned_in_smp;
561 int xmit_lock_owner;
562
563
564
565 unsigned long trans_start;
566
567
568
569
570
571 unsigned long trans_timeout;
572
573 unsigned long state;
574
575#ifdef CONFIG_BQL
576 struct dql dql;
577#endif
578} ____cacheline_aligned_in_smp;
579
580static inline int netdev_queue_numa_node_read(const struct netdev_queue *q)
581{
582#if defined(CONFIG_XPS) && defined(CONFIG_NUMA)
583 return q->numa_node;
584#else
585 return NUMA_NO_NODE;
586#endif
587}
588
589static inline void netdev_queue_numa_node_write(struct netdev_queue *q, int node)
590{
591#if defined(CONFIG_XPS) && defined(CONFIG_NUMA)
592 q->numa_node = node;
593#endif
594}
595
596#ifdef CONFIG_RPS
597
598
599
600
601struct rps_map {
602 unsigned int len;
603 struct rcu_head rcu;
604 u16 cpus[0];
605};
606#define RPS_MAP_SIZE(_num) (sizeof(struct rps_map) + ((_num) * sizeof(u16)))
607
608
609
610
611
612
613struct rps_dev_flow {
614 u16 cpu;
615 u16 filter;
616 unsigned int last_qtail;
617};
618#define RPS_NO_FILTER 0xffff
619
620
621
622
623struct rps_dev_flow_table {
624 unsigned int mask;
625 struct rcu_head rcu;
626 struct rps_dev_flow flows[0];
627};
628#define RPS_DEV_FLOW_TABLE_SIZE(_num) (sizeof(struct rps_dev_flow_table) + \
629 ((_num) * sizeof(struct rps_dev_flow)))
630
631
632
633
634
635struct rps_sock_flow_table {
636 unsigned int mask;
637 u16 ents[0];
638};
639#define RPS_SOCK_FLOW_TABLE_SIZE(_num) (sizeof(struct rps_sock_flow_table) + \
640 ((_num) * sizeof(u16)))
641
642#define RPS_NO_CPU 0xffff
643
644static inline void rps_record_sock_flow(struct rps_sock_flow_table *table,
645 u32 hash)
646{
647 if (table && hash) {
648 unsigned int cpu, index = hash & table->mask;
649
650
651 cpu = raw_smp_processor_id();
652
653 if (table->ents[index] != cpu)
654 table->ents[index] = cpu;
655 }
656}
657
658static inline void rps_reset_sock_flow(struct rps_sock_flow_table *table,
659 u32 hash)
660{
661 if (table && hash)
662 table->ents[hash & table->mask] = RPS_NO_CPU;
663}
664
665extern struct rps_sock_flow_table __rcu *rps_sock_flow_table;
666
667#ifdef CONFIG_RFS_ACCEL
668bool rps_may_expire_flow(struct net_device *dev, u16 rxq_index, u32 flow_id,
669 u16 filter_id);
670#endif
671#endif
672
673
674struct netdev_rx_queue {
675#ifdef CONFIG_RPS
676 struct rps_map __rcu *rps_map;
677 struct rps_dev_flow_table __rcu *rps_flow_table;
678#endif
679 struct kobject kobj;
680 struct net_device *dev;
681} ____cacheline_aligned_in_smp;
682
683
684
685
686struct rx_queue_attribute {
687 struct attribute attr;
688 ssize_t (*show)(struct netdev_rx_queue *queue,
689 struct rx_queue_attribute *attr, char *buf);
690 ssize_t (*store)(struct netdev_rx_queue *queue,
691 struct rx_queue_attribute *attr, const char *buf, size_t len);
692};
693
694#ifdef CONFIG_XPS
695
696
697
698
699struct xps_map {
700 unsigned int len;
701 unsigned int alloc_len;
702 struct rcu_head rcu;
703 u16 queues[0];
704};
705#define XPS_MAP_SIZE(_num) (sizeof(struct xps_map) + ((_num) * sizeof(u16)))
706#define XPS_MIN_MAP_ALLOC ((L1_CACHE_BYTES - sizeof(struct xps_map)) \
707 / sizeof(u16))
708
709
710
711
712struct xps_dev_maps {
713 struct rcu_head rcu;
714 struct xps_map __rcu *cpu_map[0];
715};
716#define XPS_DEV_MAPS_SIZE (sizeof(struct xps_dev_maps) + \
717 (nr_cpu_ids * sizeof(struct xps_map *)))
718#endif
719
720#define TC_MAX_QUEUE 16
721#define TC_BITMASK 15
722
723struct netdev_tc_txq {
724 u16 count;
725 u16 offset;
726};
727
728#if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE)
729
730
731
732
733struct netdev_fcoe_hbainfo {
734 char manufacturer[64];
735 char serial_number[64];
736 char hardware_version[64];
737 char driver_version[64];
738 char optionrom_version[64];
739 char firmware_version[64];
740 char model[256];
741 char model_description[256];
742};
743#endif
744
745#define MAX_PHYS_PORT_ID_LEN 32
746
747
748
749
750struct netdev_phys_port_id {
751 unsigned char id[MAX_PHYS_PORT_ID_LEN];
752 unsigned char id_len;
753};
754
755typedef u16 (*select_queue_fallback_t)(struct net_device *dev,
756 struct sk_buff *skb);
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002struct net_device_ops {
1003 int (*ndo_init)(struct net_device *dev);
1004 void (*ndo_uninit)(struct net_device *dev);
1005 int (*ndo_open)(struct net_device *dev);
1006 int (*ndo_stop)(struct net_device *dev);
1007 netdev_tx_t (*ndo_start_xmit) (struct sk_buff *skb,
1008 struct net_device *dev);
1009 u16 (*ndo_select_queue)(struct net_device *dev,
1010 struct sk_buff *skb,
1011 void *accel_priv,
1012 select_queue_fallback_t fallback);
1013 void (*ndo_change_rx_flags)(struct net_device *dev,
1014 int flags);
1015 void (*ndo_set_rx_mode)(struct net_device *dev);
1016 int (*ndo_set_mac_address)(struct net_device *dev,
1017 void *addr);
1018 int (*ndo_validate_addr)(struct net_device *dev);
1019 int (*ndo_do_ioctl)(struct net_device *dev,
1020 struct ifreq *ifr, int cmd);
1021 int (*ndo_set_config)(struct net_device *dev,
1022 struct ifmap *map);
1023 int (*ndo_change_mtu)(struct net_device *dev,
1024 int new_mtu);
1025 int (*ndo_neigh_setup)(struct net_device *dev,
1026 struct neigh_parms *);
1027 void (*ndo_tx_timeout) (struct net_device *dev);
1028
1029 struct rtnl_link_stats64* (*ndo_get_stats64)(struct net_device *dev,
1030 struct rtnl_link_stats64 *storage);
1031 struct net_device_stats* (*ndo_get_stats)(struct net_device *dev);
1032
1033 int (*ndo_vlan_rx_add_vid)(struct net_device *dev,
1034 __be16 proto, u16 vid);
1035 int (*ndo_vlan_rx_kill_vid)(struct net_device *dev,
1036 __be16 proto, u16 vid);
1037#ifdef CONFIG_NET_POLL_CONTROLLER
1038 void (*ndo_poll_controller)(struct net_device *dev);
1039 int (*ndo_netpoll_setup)(struct net_device *dev,
1040 struct netpoll_info *info);
1041 void (*ndo_netpoll_cleanup)(struct net_device *dev);
1042#endif
1043#ifdef CONFIG_NET_RX_BUSY_POLL
1044 int (*ndo_busy_poll)(struct napi_struct *dev);
1045#endif
1046 int (*ndo_set_vf_mac)(struct net_device *dev,
1047 int queue, u8 *mac);
1048 int (*ndo_set_vf_vlan)(struct net_device *dev,
1049 int queue, u16 vlan, u8 qos);
1050 int (*ndo_set_vf_tx_rate)(struct net_device *dev,
1051 int vf, int rate);
1052 int (*ndo_set_vf_spoofchk)(struct net_device *dev,
1053 int vf, bool setting);
1054 int (*ndo_get_vf_config)(struct net_device *dev,
1055 int vf,
1056 struct ifla_vf_info *ivf);
1057 int (*ndo_set_vf_link_state)(struct net_device *dev,
1058 int vf, int link_state);
1059 int (*ndo_set_vf_port)(struct net_device *dev,
1060 int vf,
1061 struct nlattr *port[]);
1062 int (*ndo_get_vf_port)(struct net_device *dev,
1063 int vf, struct sk_buff *skb);
1064 int (*ndo_setup_tc)(struct net_device *dev, u8 tc);
1065#if IS_ENABLED(CONFIG_FCOE)
1066 int (*ndo_fcoe_enable)(struct net_device *dev);
1067 int (*ndo_fcoe_disable)(struct net_device *dev);
1068 int (*ndo_fcoe_ddp_setup)(struct net_device *dev,
1069 u16 xid,
1070 struct scatterlist *sgl,
1071 unsigned int sgc);
1072 int (*ndo_fcoe_ddp_done)(struct net_device *dev,
1073 u16 xid);
1074 int (*ndo_fcoe_ddp_target)(struct net_device *dev,
1075 u16 xid,
1076 struct scatterlist *sgl,
1077 unsigned int sgc);
1078 int (*ndo_fcoe_get_hbainfo)(struct net_device *dev,
1079 struct netdev_fcoe_hbainfo *hbainfo);
1080#endif
1081
1082#if IS_ENABLED(CONFIG_LIBFCOE)
1083#define NETDEV_FCOE_WWNN 0
1084#define NETDEV_FCOE_WWPN 1
1085 int (*ndo_fcoe_get_wwn)(struct net_device *dev,
1086 u64 *wwn, int type);
1087#endif
1088
1089#ifdef CONFIG_RFS_ACCEL
1090 int (*ndo_rx_flow_steer)(struct net_device *dev,
1091 const struct sk_buff *skb,
1092 u16 rxq_index,
1093 u32 flow_id);
1094#endif
1095 int (*ndo_add_slave)(struct net_device *dev,
1096 struct net_device *slave_dev);
1097 int (*ndo_del_slave)(struct net_device *dev,
1098 struct net_device *slave_dev);
1099 netdev_features_t (*ndo_fix_features)(struct net_device *dev,
1100 netdev_features_t features);
1101 int (*ndo_set_features)(struct net_device *dev,
1102 netdev_features_t features);
1103 int (*ndo_neigh_construct)(struct neighbour *n);
1104 void (*ndo_neigh_destroy)(struct neighbour *n);
1105
1106 int (*ndo_fdb_add)(struct ndmsg *ndm,
1107 struct nlattr *tb[],
1108 struct net_device *dev,
1109 const unsigned char *addr,
1110 u16 flags);
1111 int (*ndo_fdb_del)(struct ndmsg *ndm,
1112 struct nlattr *tb[],
1113 struct net_device *dev,
1114 const unsigned char *addr);
1115 int (*ndo_fdb_dump)(struct sk_buff *skb,
1116 struct netlink_callback *cb,
1117 struct net_device *dev,
1118 int idx);
1119
1120 int (*ndo_bridge_setlink)(struct net_device *dev,
1121 struct nlmsghdr *nlh);
1122 int (*ndo_bridge_getlink)(struct sk_buff *skb,
1123 u32 pid, u32 seq,
1124 struct net_device *dev,
1125 u32 filter_mask);
1126 int (*ndo_bridge_dellink)(struct net_device *dev,
1127 struct nlmsghdr *nlh);
1128 int (*ndo_change_carrier)(struct net_device *dev,
1129 bool new_carrier);
1130 int (*ndo_get_phys_port_id)(struct net_device *dev,
1131 struct netdev_phys_port_id *ppid);
1132 void (*ndo_add_vxlan_port)(struct net_device *dev,
1133 sa_family_t sa_family,
1134 __be16 port);
1135 void (*ndo_del_vxlan_port)(struct net_device *dev,
1136 sa_family_t sa_family,
1137 __be16 port);
1138
1139 void* (*ndo_dfwd_add_station)(struct net_device *pdev,
1140 struct net_device *dev);
1141 void (*ndo_dfwd_del_station)(struct net_device *pdev,
1142 void *priv);
1143
1144 netdev_tx_t (*ndo_dfwd_start_xmit) (struct sk_buff *skb,
1145 struct net_device *dev,
1146 void *priv);
1147 int (*ndo_get_lock_subclass)(struct net_device *dev);
1148};
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185enum netdev_priv_flags {
1186 IFF_802_1Q_VLAN = 1<<0,
1187 IFF_EBRIDGE = 1<<1,
1188 IFF_SLAVE_INACTIVE = 1<<2,
1189 IFF_MASTER_8023AD = 1<<3,
1190 IFF_MASTER_ALB = 1<<4,
1191 IFF_BONDING = 1<<5,
1192 IFF_SLAVE_NEEDARP = 1<<6,
1193 IFF_ISATAP = 1<<7,
1194 IFF_MASTER_ARPMON = 1<<8,
1195 IFF_WAN_HDLC = 1<<9,
1196 IFF_XMIT_DST_RELEASE = 1<<10,
1197 IFF_DONT_BRIDGE = 1<<11,
1198 IFF_DISABLE_NETPOLL = 1<<12,
1199 IFF_MACVLAN_PORT = 1<<13,
1200 IFF_BRIDGE_PORT = 1<<14,
1201 IFF_OVS_DATAPATH = 1<<15,
1202 IFF_TX_SKB_SHARING = 1<<16,
1203 IFF_UNICAST_FLT = 1<<17,
1204 IFF_TEAM_PORT = 1<<18,
1205 IFF_SUPP_NOFCS = 1<<19,
1206 IFF_LIVE_ADDR_CHANGE = 1<<20,
1207 IFF_MACVLAN = 1<<21,
1208};
1209
1210#define IFF_802_1Q_VLAN IFF_802_1Q_VLAN
1211#define IFF_EBRIDGE IFF_EBRIDGE
1212#define IFF_SLAVE_INACTIVE IFF_SLAVE_INACTIVE
1213#define IFF_MASTER_8023AD IFF_MASTER_8023AD
1214#define IFF_MASTER_ALB IFF_MASTER_ALB
1215#define IFF_BONDING IFF_BONDING
1216#define IFF_SLAVE_NEEDARP IFF_SLAVE_NEEDARP
1217#define IFF_ISATAP IFF_ISATAP
1218#define IFF_MASTER_ARPMON IFF_MASTER_ARPMON
1219#define IFF_WAN_HDLC IFF_WAN_HDLC
1220#define IFF_XMIT_DST_RELEASE IFF_XMIT_DST_RELEASE
1221#define IFF_DONT_BRIDGE IFF_DONT_BRIDGE
1222#define IFF_DISABLE_NETPOLL IFF_DISABLE_NETPOLL
1223#define IFF_MACVLAN_PORT IFF_MACVLAN_PORT
1224#define IFF_BRIDGE_PORT IFF_BRIDGE_PORT
1225#define IFF_OVS_DATAPATH IFF_OVS_DATAPATH
1226#define IFF_TX_SKB_SHARING IFF_TX_SKB_SHARING
1227#define IFF_UNICAST_FLT IFF_UNICAST_FLT
1228#define IFF_TEAM_PORT IFF_TEAM_PORT
1229#define IFF_SUPP_NOFCS IFF_SUPP_NOFCS
1230#define IFF_LIVE_ADDR_CHANGE IFF_LIVE_ADDR_CHANGE
1231#define IFF_MACVLAN IFF_MACVLAN
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243struct net_device {
1244
1245
1246
1247
1248
1249
1250 char name[IFNAMSIZ];
1251
1252
1253 struct hlist_node name_hlist;
1254
1255
1256 char *ifalias;
1257
1258
1259
1260
1261
1262 unsigned long mem_end;
1263 unsigned long mem_start;
1264 unsigned long base_addr;
1265 int irq;
1266
1267
1268
1269
1270
1271
1272 unsigned long state;
1273
1274 struct list_head dev_list;
1275 struct list_head napi_list;
1276 struct list_head unreg_list;
1277 struct list_head close_list;
1278
1279
1280 struct {
1281 struct list_head upper;
1282 struct list_head lower;
1283 } adj_list;
1284
1285
1286 struct {
1287 struct list_head upper;
1288 struct list_head lower;
1289 } all_adj_list;
1290
1291
1292
1293 netdev_features_t features;
1294
1295 netdev_features_t hw_features;
1296
1297 netdev_features_t wanted_features;
1298
1299 netdev_features_t vlan_features;
1300
1301
1302
1303
1304
1305 netdev_features_t hw_enc_features;
1306
1307 netdev_features_t mpls_features;
1308
1309
1310 int ifindex;
1311 int iflink;
1312
1313 struct net_device_stats stats;
1314
1315
1316 atomic_long_t rx_dropped;
1317 atomic_long_t tx_dropped;
1318
1319
1320 atomic_t carrier_changes;
1321
1322#ifdef CONFIG_WIRELESS_EXT
1323
1324
1325 const struct iw_handler_def * wireless_handlers;
1326
1327 struct iw_public_data * wireless_data;
1328#endif
1329
1330 const struct net_device_ops *netdev_ops;
1331 const struct ethtool_ops *ethtool_ops;
1332 const struct forwarding_accel_ops *fwd_ops;
1333
1334
1335 const struct header_ops *header_ops;
1336
1337 unsigned int flags;
1338 unsigned int priv_flags;
1339
1340 unsigned short gflags;
1341 unsigned short padded;
1342
1343 unsigned char operstate;
1344 unsigned char link_mode;
1345
1346 unsigned char if_port;
1347 unsigned char dma;
1348
1349 unsigned int mtu;
1350 unsigned short type;
1351 unsigned short hard_header_len;
1352
1353
1354
1355
1356
1357 unsigned short needed_headroom;
1358 unsigned short needed_tailroom;
1359
1360
1361 unsigned char perm_addr[MAX_ADDR_LEN];
1362 unsigned char addr_assign_type;
1363 unsigned char addr_len;
1364 unsigned short neigh_priv_len;
1365 unsigned short dev_id;
1366
1367
1368
1369 unsigned short dev_port;
1370
1371
1372
1373 spinlock_t addr_list_lock;
1374 struct netdev_hw_addr_list uc;
1375 struct netdev_hw_addr_list mc;
1376 struct netdev_hw_addr_list dev_addrs;
1377
1378
1379#ifdef CONFIG_SYSFS
1380 struct kset *queues_kset;
1381#endif
1382
1383 bool uc_promisc;
1384 unsigned int promiscuity;
1385 unsigned int allmulti;
1386
1387
1388
1389
1390#if IS_ENABLED(CONFIG_VLAN_8021Q)
1391 struct vlan_info __rcu *vlan_info;
1392#endif
1393#if IS_ENABLED(CONFIG_NET_DSA)
1394 struct dsa_switch_tree *dsa_ptr;
1395#endif
1396#if IS_ENABLED(CONFIG_TIPC)
1397 struct tipc_bearer __rcu *tipc_ptr;
1398#endif
1399 void *atalk_ptr;
1400 struct in_device __rcu *ip_ptr;
1401 struct dn_dev __rcu *dn_ptr;
1402 struct inet6_dev __rcu *ip6_ptr;
1403 void *ax25_ptr;
1404 struct wireless_dev *ieee80211_ptr;
1405
1406
1407
1408
1409
1410 unsigned long last_rx;
1411
1412
1413 unsigned char *dev_addr;
1414
1415
1416
1417
1418#ifdef CONFIG_SYSFS
1419 struct netdev_rx_queue *_rx;
1420
1421
1422 unsigned int num_rx_queues;
1423
1424
1425 unsigned int real_num_rx_queues;
1426
1427#endif
1428
1429 rx_handler_func_t __rcu *rx_handler;
1430 void __rcu *rx_handler_data;
1431
1432 struct netdev_queue __rcu *ingress_queue;
1433 unsigned char broadcast[MAX_ADDR_LEN];
1434
1435
1436
1437
1438
1439 struct netdev_queue *_tx ____cacheline_aligned_in_smp;
1440
1441
1442 unsigned int num_tx_queues;
1443
1444
1445 unsigned int real_num_tx_queues;
1446
1447
1448 struct Qdisc *qdisc;
1449
1450 unsigned long tx_queue_len;
1451 spinlock_t tx_global_lock;
1452
1453#ifdef CONFIG_XPS
1454 struct xps_dev_maps __rcu *xps_maps;
1455#endif
1456#ifdef CONFIG_RFS_ACCEL
1457
1458
1459
1460 struct cpu_rmap *rx_cpu_rmap;
1461#endif
1462
1463
1464
1465
1466
1467
1468
1469 unsigned long trans_start;
1470
1471 int watchdog_timeo;
1472 struct timer_list watchdog_timer;
1473
1474
1475 int __percpu *pcpu_refcnt;
1476
1477
1478 struct list_head todo_list;
1479
1480 struct hlist_node index_hlist;
1481
1482 struct list_head link_watch_list;
1483
1484
1485 enum { NETREG_UNINITIALIZED=0,
1486 NETREG_REGISTERED,
1487 NETREG_UNREGISTERING,
1488 NETREG_UNREGISTERED,
1489 NETREG_RELEASED,
1490 NETREG_DUMMY,
1491 } reg_state:8;
1492
1493 bool dismantle;
1494
1495 enum {
1496 RTNL_LINK_INITIALIZED,
1497 RTNL_LINK_INITIALIZING,
1498 } rtnl_link_state:16;
1499
1500
1501 void (*destructor)(struct net_device *dev);
1502
1503#ifdef CONFIG_NETPOLL
1504 struct netpoll_info __rcu *npinfo;
1505#endif
1506
1507#ifdef CONFIG_NET_NS
1508
1509 struct net *nd_net;
1510#endif
1511
1512
1513 union {
1514 void *ml_priv;
1515 struct pcpu_lstats __percpu *lstats;
1516 struct pcpu_sw_netstats __percpu *tstats;
1517 struct pcpu_dstats __percpu *dstats;
1518 struct pcpu_vstats __percpu *vstats;
1519 };
1520
1521 struct garp_port __rcu *garp_port;
1522
1523 struct mrp_port __rcu *mrp_port;
1524
1525
1526 struct device dev;
1527
1528 const struct attribute_group *sysfs_groups[4];
1529
1530 const struct attribute_group *sysfs_rx_queue_group;
1531
1532
1533 const struct rtnl_link_ops *rtnl_link_ops;
1534
1535
1536#define GSO_MAX_SIZE 65536
1537 unsigned int gso_max_size;
1538#define GSO_MAX_SEGS 65535
1539 u16 gso_max_segs;
1540
1541#ifdef CONFIG_DCB
1542
1543 const struct dcbnl_rtnl_ops *dcbnl_ops;
1544#endif
1545 u8 num_tc;
1546 struct netdev_tc_txq tc_to_txq[TC_MAX_QUEUE];
1547 u8 prio_tc_map[TC_BITMASK + 1];
1548
1549#if IS_ENABLED(CONFIG_FCOE)
1550
1551 unsigned int fcoe_ddp_xid;
1552#endif
1553#if IS_ENABLED(CONFIG_CGROUP_NET_PRIO)
1554 struct netprio_map __rcu *priomap;
1555#endif
1556
1557 struct phy_device *phydev;
1558
1559 struct lock_class_key *qdisc_tx_busylock;
1560
1561
1562 int group;
1563
1564 struct pm_qos_request pm_qos_req;
1565};
1566#define to_net_dev(d) container_of(d, struct net_device, dev)
1567
1568#define NETDEV_ALIGN 32
1569
1570static inline
1571int netdev_get_prio_tc_map(const struct net_device *dev, u32 prio)
1572{
1573 return dev->prio_tc_map[prio & TC_BITMASK];
1574}
1575
1576static inline
1577int netdev_set_prio_tc_map(struct net_device *dev, u8 prio, u8 tc)
1578{
1579 if (tc >= dev->num_tc)
1580 return -EINVAL;
1581
1582 dev->prio_tc_map[prio & TC_BITMASK] = tc & TC_BITMASK;
1583 return 0;
1584}
1585
1586static inline
1587void netdev_reset_tc(struct net_device *dev)
1588{
1589 dev->num_tc = 0;
1590 memset(dev->tc_to_txq, 0, sizeof(dev->tc_to_txq));
1591 memset(dev->prio_tc_map, 0, sizeof(dev->prio_tc_map));
1592}
1593
1594static inline
1595int netdev_set_tc_queue(struct net_device *dev, u8 tc, u16 count, u16 offset)
1596{
1597 if (tc >= dev->num_tc)
1598 return -EINVAL;
1599
1600 dev->tc_to_txq[tc].count = count;
1601 dev->tc_to_txq[tc].offset = offset;
1602 return 0;
1603}
1604
1605static inline
1606int netdev_set_num_tc(struct net_device *dev, u8 num_tc)
1607{
1608 if (num_tc > TC_MAX_QUEUE)
1609 return -EINVAL;
1610
1611 dev->num_tc = num_tc;
1612 return 0;
1613}
1614
1615static inline
1616int netdev_get_num_tc(struct net_device *dev)
1617{
1618 return dev->num_tc;
1619}
1620
1621static inline
1622struct netdev_queue *netdev_get_tx_queue(const struct net_device *dev,
1623 unsigned int index)
1624{
1625 return &dev->_tx[index];
1626}
1627
1628static inline void netdev_for_each_tx_queue(struct net_device *dev,
1629 void (*f)(struct net_device *,
1630 struct netdev_queue *,
1631 void *),
1632 void *arg)
1633{
1634 unsigned int i;
1635
1636 for (i = 0; i < dev->num_tx_queues; i++)
1637 f(dev, &dev->_tx[i], arg);
1638}
1639
1640struct netdev_queue *netdev_pick_tx(struct net_device *dev,
1641 struct sk_buff *skb,
1642 void *accel_priv);
1643
1644
1645
1646
1647static inline
1648struct net *dev_net(const struct net_device *dev)
1649{
1650 return read_pnet(&dev->nd_net);
1651}
1652
1653static inline
1654void dev_net_set(struct net_device *dev, struct net *net)
1655{
1656#ifdef CONFIG_NET_NS
1657 release_net(dev->nd_net);
1658 dev->nd_net = hold_net(net);
1659#endif
1660}
1661
1662static inline bool netdev_uses_dsa_tags(struct net_device *dev)
1663{
1664#ifdef CONFIG_NET_DSA_TAG_DSA
1665 if (dev->dsa_ptr != NULL)
1666 return dsa_uses_dsa_tags(dev->dsa_ptr);
1667#endif
1668
1669 return 0;
1670}
1671
1672static inline bool netdev_uses_trailer_tags(struct net_device *dev)
1673{
1674#ifdef CONFIG_NET_DSA_TAG_TRAILER
1675 if (dev->dsa_ptr != NULL)
1676 return dsa_uses_trailer_tags(dev->dsa_ptr);
1677#endif
1678
1679 return 0;
1680}
1681
1682
1683
1684
1685
1686
1687
1688static inline void *netdev_priv(const struct net_device *dev)
1689{
1690 return (char *)dev + ALIGN(sizeof(struct net_device), NETDEV_ALIGN);
1691}
1692
1693
1694
1695
1696#define SET_NETDEV_DEV(net, pdev) ((net)->dev.parent = (pdev))
1697
1698
1699
1700
1701
1702#define SET_NETDEV_DEVTYPE(net, devtype) ((net)->dev.type = (devtype))
1703
1704
1705
1706
1707#define NAPI_POLL_WEIGHT 64
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719void netif_napi_add(struct net_device *dev, struct napi_struct *napi,
1720 int (*poll)(struct napi_struct *, int), int weight);
1721
1722
1723
1724
1725
1726
1727
1728void netif_napi_del(struct napi_struct *napi);
1729
1730struct napi_gro_cb {
1731
1732 void *frag0;
1733
1734
1735 unsigned int frag0_len;
1736
1737
1738 int data_offset;
1739
1740
1741 u16 flush;
1742
1743
1744 u16 flush_id;
1745
1746
1747 u16 count;
1748
1749
1750 u8 same_flow;
1751
1752
1753 u8 free;
1754#define NAPI_GRO_FREE 1
1755#define NAPI_GRO_FREE_STOLEN_HEAD 2
1756
1757
1758 unsigned long age;
1759
1760
1761 u16 proto;
1762
1763
1764 u16 udp_mark;
1765
1766
1767 __wsum csum;
1768
1769
1770 struct sk_buff *last;
1771};
1772
1773#define NAPI_GRO_CB(skb) ((struct napi_gro_cb *)(skb)->cb)
1774
1775struct packet_type {
1776 __be16 type;
1777 struct net_device *dev;
1778 int (*func) (struct sk_buff *,
1779 struct net_device *,
1780 struct packet_type *,
1781 struct net_device *);
1782 bool (*id_match)(struct packet_type *ptype,
1783 struct sock *sk);
1784 void *af_packet_priv;
1785 struct list_head list;
1786};
1787
1788struct offload_callbacks {
1789 struct sk_buff *(*gso_segment)(struct sk_buff *skb,
1790 netdev_features_t features);
1791 int (*gso_send_check)(struct sk_buff *skb);
1792 struct sk_buff **(*gro_receive)(struct sk_buff **head,
1793 struct sk_buff *skb);
1794 int (*gro_complete)(struct sk_buff *skb, int nhoff);
1795};
1796
1797struct packet_offload {
1798 __be16 type;
1799 struct offload_callbacks callbacks;
1800 struct list_head list;
1801};
1802
1803struct udp_offload {
1804 __be16 port;
1805 struct offload_callbacks callbacks;
1806};
1807
1808
1809struct pcpu_sw_netstats {
1810 u64 rx_packets;
1811 u64 rx_bytes;
1812 u64 tx_packets;
1813 u64 tx_bytes;
1814 struct u64_stats_sync syncp;
1815};
1816
1817#define netdev_alloc_pcpu_stats(type) \
1818({ \
1819 typeof(type) __percpu *pcpu_stats = alloc_percpu(type); \
1820 if (pcpu_stats) { \
1821 int i; \
1822 for_each_possible_cpu(i) { \
1823 typeof(type) *stat; \
1824 stat = per_cpu_ptr(pcpu_stats, i); \
1825 u64_stats_init(&stat->syncp); \
1826 } \
1827 } \
1828 pcpu_stats; \
1829})
1830
1831#include <linux/notifier.h>
1832
1833
1834
1835
1836
1837#define NETDEV_UP 0x0001
1838#define NETDEV_DOWN 0x0002
1839#define NETDEV_REBOOT 0x0003
1840
1841
1842
1843#define NETDEV_CHANGE 0x0004
1844#define NETDEV_REGISTER 0x0005
1845#define NETDEV_UNREGISTER 0x0006
1846#define NETDEV_CHANGEMTU 0x0007
1847#define NETDEV_CHANGEADDR 0x0008
1848#define NETDEV_GOING_DOWN 0x0009
1849#define NETDEV_CHANGENAME 0x000A
1850#define NETDEV_FEAT_CHANGE 0x000B
1851#define NETDEV_BONDING_FAILOVER 0x000C
1852#define NETDEV_PRE_UP 0x000D
1853#define NETDEV_PRE_TYPE_CHANGE 0x000E
1854#define NETDEV_POST_TYPE_CHANGE 0x000F
1855#define NETDEV_POST_INIT 0x0010
1856#define NETDEV_UNREGISTER_FINAL 0x0011
1857#define NETDEV_RELEASE 0x0012
1858#define NETDEV_NOTIFY_PEERS 0x0013
1859#define NETDEV_JOIN 0x0014
1860#define NETDEV_CHANGEUPPER 0x0015
1861#define NETDEV_RESEND_IGMP 0x0016
1862#define NETDEV_PRECHANGEMTU 0x0017
1863
1864int register_netdevice_notifier(struct notifier_block *nb);
1865int unregister_netdevice_notifier(struct notifier_block *nb);
1866
1867struct netdev_notifier_info {
1868 struct net_device *dev;
1869};
1870
1871struct netdev_notifier_change_info {
1872 struct netdev_notifier_info info;
1873 unsigned int flags_changed;
1874};
1875
1876static inline void netdev_notifier_info_init(struct netdev_notifier_info *info,
1877 struct net_device *dev)
1878{
1879 info->dev = dev;
1880}
1881
1882static inline struct net_device *
1883netdev_notifier_info_to_dev(const struct netdev_notifier_info *info)
1884{
1885 return info->dev;
1886}
1887
1888int call_netdevice_notifiers(unsigned long val, struct net_device *dev);
1889
1890
1891extern rwlock_t dev_base_lock;
1892
1893#define for_each_netdev(net, d) \
1894 list_for_each_entry(d, &(net)->dev_base_head, dev_list)
1895#define for_each_netdev_reverse(net, d) \
1896 list_for_each_entry_reverse(d, &(net)->dev_base_head, dev_list)
1897#define for_each_netdev_rcu(net, d) \
1898 list_for_each_entry_rcu(d, &(net)->dev_base_head, dev_list)
1899#define for_each_netdev_safe(net, d, n) \
1900 list_for_each_entry_safe(d, n, &(net)->dev_base_head, dev_list)
1901#define for_each_netdev_continue(net, d) \
1902 list_for_each_entry_continue(d, &(net)->dev_base_head, dev_list)
1903#define for_each_netdev_continue_rcu(net, d) \
1904 list_for_each_entry_continue_rcu(d, &(net)->dev_base_head, dev_list)
1905#define for_each_netdev_in_bond_rcu(bond, slave) \
1906 for_each_netdev_rcu(&init_net, slave) \
1907 if (netdev_master_upper_dev_get_rcu(slave) == bond)
1908#define net_device_entry(lh) list_entry(lh, struct net_device, dev_list)
1909
1910static inline struct net_device *next_net_device(struct net_device *dev)
1911{
1912 struct list_head *lh;
1913 struct net *net;
1914
1915 net = dev_net(dev);
1916 lh = dev->dev_list.next;
1917 return lh == &net->dev_base_head ? NULL : net_device_entry(lh);
1918}
1919
1920static inline struct net_device *next_net_device_rcu(struct net_device *dev)
1921{
1922 struct list_head *lh;
1923 struct net *net;
1924
1925 net = dev_net(dev);
1926 lh = rcu_dereference(list_next_rcu(&dev->dev_list));
1927 return lh == &net->dev_base_head ? NULL : net_device_entry(lh);
1928}
1929
1930static inline struct net_device *first_net_device(struct net *net)
1931{
1932 return list_empty(&net->dev_base_head) ? NULL :
1933 net_device_entry(net->dev_base_head.next);
1934}
1935
1936static inline struct net_device *first_net_device_rcu(struct net *net)
1937{
1938 struct list_head *lh = rcu_dereference(list_next_rcu(&net->dev_base_head));
1939
1940 return lh == &net->dev_base_head ? NULL : net_device_entry(lh);
1941}
1942
1943int netdev_boot_setup_check(struct net_device *dev);
1944unsigned long netdev_boot_base(const char *prefix, int unit);
1945struct net_device *dev_getbyhwaddr_rcu(struct net *net, unsigned short type,
1946 const char *hwaddr);
1947struct net_device *dev_getfirstbyhwtype(struct net *net, unsigned short type);
1948struct net_device *__dev_getfirstbyhwtype(struct net *net, unsigned short type);
1949void dev_add_pack(struct packet_type *pt);
1950void dev_remove_pack(struct packet_type *pt);
1951void __dev_remove_pack(struct packet_type *pt);
1952void dev_add_offload(struct packet_offload *po);
1953void dev_remove_offload(struct packet_offload *po);
1954
1955struct net_device *dev_get_by_flags_rcu(struct net *net, unsigned short flags,
1956 unsigned short mask);
1957struct net_device *dev_get_by_name(struct net *net, const char *name);
1958struct net_device *dev_get_by_name_rcu(struct net *net, const char *name);
1959struct net_device *__dev_get_by_name(struct net *net, const char *name);
1960int dev_alloc_name(struct net_device *dev, const char *name);
1961int dev_open(struct net_device *dev);
1962int dev_close(struct net_device *dev);
1963void dev_disable_lro(struct net_device *dev);
1964int dev_loopback_xmit(struct sk_buff *newskb);
1965int dev_queue_xmit(struct sk_buff *skb);
1966int dev_queue_xmit_accel(struct sk_buff *skb, void *accel_priv);
1967int register_netdevice(struct net_device *dev);
1968void unregister_netdevice_queue(struct net_device *dev, struct list_head *head);
1969void unregister_netdevice_many(struct list_head *head);
1970static inline void unregister_netdevice(struct net_device *dev)
1971{
1972 unregister_netdevice_queue(dev, NULL);
1973}
1974
1975int netdev_refcnt_read(const struct net_device *dev);
1976void free_netdev(struct net_device *dev);
1977void netdev_freemem(struct net_device *dev);
1978void synchronize_net(void);
1979int init_dummy_netdev(struct net_device *dev);
1980
1981struct net_device *dev_get_by_index(struct net *net, int ifindex);
1982struct net_device *__dev_get_by_index(struct net *net, int ifindex);
1983struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex);
1984int netdev_get_name(struct net *net, char *name, int ifindex);
1985int dev_restart(struct net_device *dev);
1986int skb_gro_receive(struct sk_buff **head, struct sk_buff *skb);
1987
1988static inline unsigned int skb_gro_offset(const struct sk_buff *skb)
1989{
1990 return NAPI_GRO_CB(skb)->data_offset;
1991}
1992
1993static inline unsigned int skb_gro_len(const struct sk_buff *skb)
1994{
1995 return skb->len - NAPI_GRO_CB(skb)->data_offset;
1996}
1997
1998static inline void skb_gro_pull(struct sk_buff *skb, unsigned int len)
1999{
2000 NAPI_GRO_CB(skb)->data_offset += len;
2001}
2002
2003static inline void *skb_gro_header_fast(struct sk_buff *skb,
2004 unsigned int offset)
2005{
2006 return NAPI_GRO_CB(skb)->frag0 + offset;
2007}
2008
2009static inline int skb_gro_header_hard(struct sk_buff *skb, unsigned int hlen)
2010{
2011 return NAPI_GRO_CB(skb)->frag0_len < hlen;
2012}
2013
2014static inline void *skb_gro_header_slow(struct sk_buff *skb, unsigned int hlen,
2015 unsigned int offset)
2016{
2017 if (!pskb_may_pull(skb, hlen))
2018 return NULL;
2019
2020 NAPI_GRO_CB(skb)->frag0 = NULL;
2021 NAPI_GRO_CB(skb)->frag0_len = 0;
2022 return skb->data + offset;
2023}
2024
2025static inline void *skb_gro_network_header(struct sk_buff *skb)
2026{
2027 return (NAPI_GRO_CB(skb)->frag0 ?: skb->data) +
2028 skb_network_offset(skb);
2029}
2030
2031static inline void skb_gro_postpull_rcsum(struct sk_buff *skb,
2032 const void *start, unsigned int len)
2033{
2034 if (skb->ip_summed == CHECKSUM_COMPLETE)
2035 NAPI_GRO_CB(skb)->csum = csum_sub(NAPI_GRO_CB(skb)->csum,
2036 csum_partial(start, len, 0));
2037}
2038
2039static inline int dev_hard_header(struct sk_buff *skb, struct net_device *dev,
2040 unsigned short type,
2041 const void *daddr, const void *saddr,
2042 unsigned int len)
2043{
2044 if (!dev->header_ops || !dev->header_ops->create)
2045 return 0;
2046
2047 return dev->header_ops->create(skb, dev, type, daddr, saddr, len);
2048}
2049
2050static inline int dev_parse_header(const struct sk_buff *skb,
2051 unsigned char *haddr)
2052{
2053 const struct net_device *dev = skb->dev;
2054
2055 if (!dev->header_ops || !dev->header_ops->parse)
2056 return 0;
2057 return dev->header_ops->parse(skb, haddr);
2058}
2059
2060static inline int dev_rebuild_header(struct sk_buff *skb)
2061{
2062 const struct net_device *dev = skb->dev;
2063
2064 if (!dev->header_ops || !dev->header_ops->rebuild)
2065 return 0;
2066 return dev->header_ops->rebuild(skb);
2067}
2068
2069typedef int gifconf_func_t(struct net_device * dev, char __user * bufptr, int len);
2070int register_gifconf(unsigned int family, gifconf_func_t *gifconf);
2071static inline int unregister_gifconf(unsigned int family)
2072{
2073 return register_gifconf(family, NULL);
2074}
2075
2076#ifdef CONFIG_NET_FLOW_LIMIT
2077#define FLOW_LIMIT_HISTORY (1 << 7)
2078struct sd_flow_limit {
2079 u64 count;
2080 unsigned int num_buckets;
2081 unsigned int history_head;
2082 u16 history[FLOW_LIMIT_HISTORY];
2083 u8 buckets[];
2084};
2085
2086extern int netdev_flow_limit_table_len;
2087#endif
2088
2089
2090
2091
2092struct softnet_data {
2093 struct Qdisc *output_queue;
2094 struct Qdisc **output_queue_tailp;
2095 struct list_head poll_list;
2096 struct sk_buff *completion_queue;
2097 struct sk_buff_head process_queue;
2098
2099
2100 unsigned int processed;
2101 unsigned int time_squeeze;
2102 unsigned int cpu_collision;
2103 unsigned int received_rps;
2104
2105#ifdef CONFIG_RPS
2106 struct softnet_data *rps_ipi_list;
2107
2108
2109 struct call_single_data csd ____cacheline_aligned_in_smp;
2110 struct softnet_data *rps_ipi_next;
2111 unsigned int cpu;
2112 unsigned int input_queue_head;
2113 unsigned int input_queue_tail;
2114#endif
2115 unsigned int dropped;
2116 struct sk_buff_head input_pkt_queue;
2117 struct napi_struct backlog;
2118
2119#ifdef CONFIG_NET_FLOW_LIMIT
2120 struct sd_flow_limit __rcu *flow_limit;
2121#endif
2122};
2123
2124static inline void input_queue_head_incr(struct softnet_data *sd)
2125{
2126#ifdef CONFIG_RPS
2127 sd->input_queue_head++;
2128#endif
2129}
2130
2131static inline void input_queue_tail_incr_save(struct softnet_data *sd,
2132 unsigned int *qtail)
2133{
2134#ifdef CONFIG_RPS
2135 *qtail = ++sd->input_queue_tail;
2136#endif
2137}
2138
2139DECLARE_PER_CPU_ALIGNED(struct softnet_data, softnet_data);
2140
2141void __netif_schedule(struct Qdisc *q);
2142
2143static inline void netif_schedule_queue(struct netdev_queue *txq)
2144{
2145 if (!(txq->state & QUEUE_STATE_ANY_XOFF))
2146 __netif_schedule(txq->qdisc);
2147}
2148
2149static inline void netif_tx_schedule_all(struct net_device *dev)
2150{
2151 unsigned int i;
2152
2153 for (i = 0; i < dev->num_tx_queues; i++)
2154 netif_schedule_queue(netdev_get_tx_queue(dev, i));
2155}
2156
2157static inline void netif_tx_start_queue(struct netdev_queue *dev_queue)
2158{
2159 clear_bit(__QUEUE_STATE_DRV_XOFF, &dev_queue->state);
2160}
2161
2162
2163
2164
2165
2166
2167
2168static inline void netif_start_queue(struct net_device *dev)
2169{
2170 netif_tx_start_queue(netdev_get_tx_queue(dev, 0));
2171}
2172
2173static inline void netif_tx_start_all_queues(struct net_device *dev)
2174{
2175 unsigned int i;
2176
2177 for (i = 0; i < dev->num_tx_queues; i++) {
2178 struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
2179 netif_tx_start_queue(txq);
2180 }
2181}
2182
2183static inline void netif_tx_wake_queue(struct netdev_queue *dev_queue)
2184{
2185 if (test_and_clear_bit(__QUEUE_STATE_DRV_XOFF, &dev_queue->state))
2186 __netif_schedule(dev_queue->qdisc);
2187}
2188
2189
2190
2191
2192
2193
2194
2195
2196static inline void netif_wake_queue(struct net_device *dev)
2197{
2198 netif_tx_wake_queue(netdev_get_tx_queue(dev, 0));
2199}
2200
2201static inline void netif_tx_wake_all_queues(struct net_device *dev)
2202{
2203 unsigned int i;
2204
2205 for (i = 0; i < dev->num_tx_queues; i++) {
2206 struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
2207 netif_tx_wake_queue(txq);
2208 }
2209}
2210
2211static inline void netif_tx_stop_queue(struct netdev_queue *dev_queue)
2212{
2213 if (WARN_ON(!dev_queue)) {
2214 pr_info("netif_stop_queue() cannot be called before register_netdev()\n");
2215 return;
2216 }
2217 set_bit(__QUEUE_STATE_DRV_XOFF, &dev_queue->state);
2218}
2219
2220
2221
2222
2223
2224
2225
2226
2227static inline void netif_stop_queue(struct net_device *dev)
2228{
2229 netif_tx_stop_queue(netdev_get_tx_queue(dev, 0));
2230}
2231
2232static inline void netif_tx_stop_all_queues(struct net_device *dev)
2233{
2234 unsigned int i;
2235
2236 for (i = 0; i < dev->num_tx_queues; i++) {
2237 struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
2238 netif_tx_stop_queue(txq);
2239 }
2240}
2241
2242static inline bool netif_tx_queue_stopped(const struct netdev_queue *dev_queue)
2243{
2244 return test_bit(__QUEUE_STATE_DRV_XOFF, &dev_queue->state);
2245}
2246
2247
2248
2249
2250
2251
2252
2253static inline bool netif_queue_stopped(const struct net_device *dev)
2254{
2255 return netif_tx_queue_stopped(netdev_get_tx_queue(dev, 0));
2256}
2257
2258static inline bool netif_xmit_stopped(const struct netdev_queue *dev_queue)
2259{
2260 return dev_queue->state & QUEUE_STATE_ANY_XOFF;
2261}
2262
2263static inline bool
2264netif_xmit_frozen_or_stopped(const struct netdev_queue *dev_queue)
2265{
2266 return dev_queue->state & QUEUE_STATE_ANY_XOFF_OR_FROZEN;
2267}
2268
2269static inline bool
2270netif_xmit_frozen_or_drv_stopped(const struct netdev_queue *dev_queue)
2271{
2272 return dev_queue->state & QUEUE_STATE_DRV_XOFF_OR_FROZEN;
2273}
2274
2275static inline void netdev_tx_sent_queue(struct netdev_queue *dev_queue,
2276 unsigned int bytes)
2277{
2278#ifdef CONFIG_BQL
2279 dql_queued(&dev_queue->dql, bytes);
2280
2281 if (likely(dql_avail(&dev_queue->dql) >= 0))
2282 return;
2283
2284 set_bit(__QUEUE_STATE_STACK_XOFF, &dev_queue->state);
2285
2286
2287
2288
2289
2290
2291 smp_mb();
2292
2293
2294 if (unlikely(dql_avail(&dev_queue->dql) >= 0))
2295 clear_bit(__QUEUE_STATE_STACK_XOFF, &dev_queue->state);
2296#endif
2297}
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308static inline void netdev_sent_queue(struct net_device *dev, unsigned int bytes)
2309{
2310 netdev_tx_sent_queue(netdev_get_tx_queue(dev, 0), bytes);
2311}
2312
2313static inline void netdev_tx_completed_queue(struct netdev_queue *dev_queue,
2314 unsigned int pkts, unsigned int bytes)
2315{
2316#ifdef CONFIG_BQL
2317 if (unlikely(!bytes))
2318 return;
2319
2320 dql_completed(&dev_queue->dql, bytes);
2321
2322
2323
2324
2325
2326
2327 smp_mb();
2328
2329 if (dql_avail(&dev_queue->dql) < 0)
2330 return;
2331
2332 if (test_and_clear_bit(__QUEUE_STATE_STACK_XOFF, &dev_queue->state))
2333 netif_schedule_queue(dev_queue);
2334#endif
2335}
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347static inline void netdev_completed_queue(struct net_device *dev,
2348 unsigned int pkts, unsigned int bytes)
2349{
2350 netdev_tx_completed_queue(netdev_get_tx_queue(dev, 0), pkts, bytes);
2351}
2352
2353static inline void netdev_tx_reset_queue(struct netdev_queue *q)
2354{
2355#ifdef CONFIG_BQL
2356 clear_bit(__QUEUE_STATE_STACK_XOFF, &q->state);
2357 dql_reset(&q->dql);
2358#endif
2359}
2360
2361
2362
2363
2364
2365
2366
2367
2368static inline void netdev_reset_queue(struct net_device *dev_queue)
2369{
2370 netdev_tx_reset_queue(netdev_get_tx_queue(dev_queue, 0));
2371}
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381static inline u16 netdev_cap_txqueue(struct net_device *dev, u16 queue_index)
2382{
2383 if (unlikely(queue_index >= dev->real_num_tx_queues)) {
2384 net_warn_ratelimited("%s selects TX queue %d, but real number of TX queues is %d\n",
2385 dev->name, queue_index,
2386 dev->real_num_tx_queues);
2387 return 0;
2388 }
2389
2390 return queue_index;
2391}
2392
2393
2394
2395
2396
2397
2398
2399static inline bool netif_running(const struct net_device *dev)
2400{
2401 return test_bit(__LINK_STATE_START, &dev->state);
2402}
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418static inline void netif_start_subqueue(struct net_device *dev, u16 queue_index)
2419{
2420 struct netdev_queue *txq = netdev_get_tx_queue(dev, queue_index);
2421
2422 netif_tx_start_queue(txq);
2423}
2424
2425
2426
2427
2428
2429
2430
2431
2432static inline void netif_stop_subqueue(struct net_device *dev, u16 queue_index)
2433{
2434 struct netdev_queue *txq = netdev_get_tx_queue(dev, queue_index);
2435 netif_tx_stop_queue(txq);
2436}
2437
2438
2439
2440
2441
2442
2443
2444
2445static inline bool __netif_subqueue_stopped(const struct net_device *dev,
2446 u16 queue_index)
2447{
2448 struct netdev_queue *txq = netdev_get_tx_queue(dev, queue_index);
2449
2450 return netif_tx_queue_stopped(txq);
2451}
2452
2453static inline bool netif_subqueue_stopped(const struct net_device *dev,
2454 struct sk_buff *skb)
2455{
2456 return __netif_subqueue_stopped(dev, skb_get_queue_mapping(skb));
2457}
2458
2459
2460
2461
2462
2463
2464
2465
2466static inline void netif_wake_subqueue(struct net_device *dev, u16 queue_index)
2467{
2468 struct netdev_queue *txq = netdev_get_tx_queue(dev, queue_index);
2469 if (test_and_clear_bit(__QUEUE_STATE_DRV_XOFF, &txq->state))
2470 __netif_schedule(txq->qdisc);
2471}
2472
2473#ifdef CONFIG_XPS
2474int netif_set_xps_queue(struct net_device *dev, const struct cpumask *mask,
2475 u16 index);
2476#else
2477static inline int netif_set_xps_queue(struct net_device *dev,
2478 const struct cpumask *mask,
2479 u16 index)
2480{
2481 return 0;
2482}
2483#endif
2484
2485
2486
2487
2488
2489static inline u16 skb_tx_hash(const struct net_device *dev,
2490 const struct sk_buff *skb)
2491{
2492 return __skb_tx_hash(dev, skb, dev->real_num_tx_queues);
2493}
2494
2495
2496
2497
2498
2499
2500
2501static inline bool netif_is_multiqueue(const struct net_device *dev)
2502{
2503 return dev->num_tx_queues > 1;
2504}
2505
2506int netif_set_real_num_tx_queues(struct net_device *dev, unsigned int txq);
2507
2508#ifdef CONFIG_SYSFS
2509int netif_set_real_num_rx_queues(struct net_device *dev, unsigned int rxq);
2510#else
2511static inline int netif_set_real_num_rx_queues(struct net_device *dev,
2512 unsigned int rxq)
2513{
2514 return 0;
2515}
2516#endif
2517
2518static inline int netif_copy_real_num_queues(struct net_device *to_dev,
2519 const struct net_device *from_dev)
2520{
2521 int err;
2522
2523 err = netif_set_real_num_tx_queues(to_dev,
2524 from_dev->real_num_tx_queues);
2525 if (err)
2526 return err;
2527#ifdef CONFIG_SYSFS
2528 return netif_set_real_num_rx_queues(to_dev,
2529 from_dev->real_num_rx_queues);
2530#else
2531 return 0;
2532#endif
2533}
2534
2535#ifdef CONFIG_SYSFS
2536static inline unsigned int get_netdev_rx_queue_index(
2537 struct netdev_rx_queue *queue)
2538{
2539 struct net_device *dev = queue->dev;
2540 int index = queue - dev->_rx;
2541
2542 BUG_ON(index >= dev->num_rx_queues);
2543 return index;
2544}
2545#endif
2546
2547#define DEFAULT_MAX_NUM_RSS_QUEUES (8)
2548int netif_get_num_default_rss_queues(void);
2549
2550enum skb_free_reason {
2551 SKB_REASON_CONSUMED,
2552 SKB_REASON_DROPPED,
2553};
2554
2555void __dev_kfree_skb_irq(struct sk_buff *skb, enum skb_free_reason reason);
2556void __dev_kfree_skb_any(struct sk_buff *skb, enum skb_free_reason reason);
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577static inline void dev_kfree_skb_irq(struct sk_buff *skb)
2578{
2579 __dev_kfree_skb_irq(skb, SKB_REASON_DROPPED);
2580}
2581
2582static inline void dev_consume_skb_irq(struct sk_buff *skb)
2583{
2584 __dev_kfree_skb_irq(skb, SKB_REASON_CONSUMED);
2585}
2586
2587static inline void dev_kfree_skb_any(struct sk_buff *skb)
2588{
2589 __dev_kfree_skb_any(skb, SKB_REASON_DROPPED);
2590}
2591
2592static inline void dev_consume_skb_any(struct sk_buff *skb)
2593{
2594 __dev_kfree_skb_any(skb, SKB_REASON_CONSUMED);
2595}
2596
2597int netif_rx(struct sk_buff *skb);
2598int netif_rx_ni(struct sk_buff *skb);
2599int netif_receive_skb(struct sk_buff *skb);
2600gro_result_t napi_gro_receive(struct napi_struct *napi, struct sk_buff *skb);
2601void napi_gro_flush(struct napi_struct *napi, bool flush_old);
2602struct sk_buff *napi_get_frags(struct napi_struct *napi);
2603gro_result_t napi_gro_frags(struct napi_struct *napi);
2604struct packet_offload *gro_find_receive_by_type(__be16 type);
2605struct packet_offload *gro_find_complete_by_type(__be16 type);
2606
2607static inline void napi_free_frags(struct napi_struct *napi)
2608{
2609 kfree_skb(napi->skb);
2610 napi->skb = NULL;
2611}
2612
2613int netdev_rx_handler_register(struct net_device *dev,
2614 rx_handler_func_t *rx_handler,
2615 void *rx_handler_data);
2616void netdev_rx_handler_unregister(struct net_device *dev);
2617
2618bool dev_valid_name(const char *name);
2619int dev_ioctl(struct net *net, unsigned int cmd, void __user *);
2620int dev_ethtool(struct net *net, struct ifreq *);
2621unsigned int dev_get_flags(const struct net_device *);
2622int __dev_change_flags(struct net_device *, unsigned int flags);
2623int dev_change_flags(struct net_device *, unsigned int);
2624void __dev_notify_flags(struct net_device *, unsigned int old_flags,
2625 unsigned int gchanges);
2626int dev_change_name(struct net_device *, const char *);
2627int dev_set_alias(struct net_device *, const char *, size_t);
2628int dev_change_net_namespace(struct net_device *, struct net *, const char *);
2629int dev_set_mtu(struct net_device *, int);
2630void dev_set_group(struct net_device *, int);
2631int dev_set_mac_address(struct net_device *, struct sockaddr *);
2632int dev_change_carrier(struct net_device *, bool new_carrier);
2633int dev_get_phys_port_id(struct net_device *dev,
2634 struct netdev_phys_port_id *ppid);
2635int dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev,
2636 struct netdev_queue *txq);
2637int dev_forward_skb(struct net_device *dev, struct sk_buff *skb);
2638bool is_skb_forwardable(struct net_device *dev, struct sk_buff *skb);
2639
2640extern int netdev_budget;
2641
2642
2643void netdev_run_todo(void);
2644
2645
2646
2647
2648
2649
2650
2651static inline void dev_put(struct net_device *dev)
2652{
2653 this_cpu_dec(*dev->pcpu_refcnt);
2654}
2655
2656
2657
2658
2659
2660
2661
2662static inline void dev_hold(struct net_device *dev)
2663{
2664 this_cpu_inc(*dev->pcpu_refcnt);
2665}
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676void linkwatch_init_dev(struct net_device *dev);
2677void linkwatch_fire_event(struct net_device *dev);
2678void linkwatch_forget_dev(struct net_device *dev);
2679
2680
2681
2682
2683
2684
2685
2686static inline bool netif_carrier_ok(const struct net_device *dev)
2687{
2688 return !test_bit(__LINK_STATE_NOCARRIER, &dev->state);
2689}
2690
2691unsigned long dev_trans_start(struct net_device *dev);
2692
2693void __netdev_watchdog_up(struct net_device *dev);
2694
2695void netif_carrier_on(struct net_device *dev);
2696
2697void netif_carrier_off(struct net_device *dev);
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712static inline void netif_dormant_on(struct net_device *dev)
2713{
2714 if (!test_and_set_bit(__LINK_STATE_DORMANT, &dev->state))
2715 linkwatch_fire_event(dev);
2716}
2717
2718
2719
2720
2721
2722
2723
2724static inline void netif_dormant_off(struct net_device *dev)
2725{
2726 if (test_and_clear_bit(__LINK_STATE_DORMANT, &dev->state))
2727 linkwatch_fire_event(dev);
2728}
2729
2730
2731
2732
2733
2734
2735
2736static inline bool netif_dormant(const struct net_device *dev)
2737{
2738 return test_bit(__LINK_STATE_DORMANT, &dev->state);
2739}
2740
2741
2742
2743
2744
2745
2746
2747
2748static inline bool netif_oper_up(const struct net_device *dev)
2749{
2750 return (dev->operstate == IF_OPER_UP ||
2751 dev->operstate == IF_OPER_UNKNOWN );
2752}
2753
2754
2755
2756
2757
2758
2759
2760static inline bool netif_device_present(struct net_device *dev)
2761{
2762 return test_bit(__LINK_STATE_PRESENT, &dev->state);
2763}
2764
2765void netif_device_detach(struct net_device *dev);
2766
2767void netif_device_attach(struct net_device *dev);
2768
2769
2770
2771
2772
2773enum {
2774 NETIF_MSG_DRV = 0x0001,
2775 NETIF_MSG_PROBE = 0x0002,
2776 NETIF_MSG_LINK = 0x0004,
2777 NETIF_MSG_TIMER = 0x0008,
2778 NETIF_MSG_IFDOWN = 0x0010,
2779 NETIF_MSG_IFUP = 0x0020,
2780 NETIF_MSG_RX_ERR = 0x0040,
2781 NETIF_MSG_TX_ERR = 0x0080,
2782 NETIF_MSG_TX_QUEUED = 0x0100,
2783 NETIF_MSG_INTR = 0x0200,
2784 NETIF_MSG_TX_DONE = 0x0400,
2785 NETIF_MSG_RX_STATUS = 0x0800,
2786 NETIF_MSG_PKTDATA = 0x1000,
2787 NETIF_MSG_HW = 0x2000,
2788 NETIF_MSG_WOL = 0x4000,
2789};
2790
2791#define netif_msg_drv(p) ((p)->msg_enable & NETIF_MSG_DRV)
2792#define netif_msg_probe(p) ((p)->msg_enable & NETIF_MSG_PROBE)
2793#define netif_msg_link(p) ((p)->msg_enable & NETIF_MSG_LINK)
2794#define netif_msg_timer(p) ((p)->msg_enable & NETIF_MSG_TIMER)
2795#define netif_msg_ifdown(p) ((p)->msg_enable & NETIF_MSG_IFDOWN)
2796#define netif_msg_ifup(p) ((p)->msg_enable & NETIF_MSG_IFUP)
2797#define netif_msg_rx_err(p) ((p)->msg_enable & NETIF_MSG_RX_ERR)
2798#define netif_msg_tx_err(p) ((p)->msg_enable & NETIF_MSG_TX_ERR)
2799#define netif_msg_tx_queued(p) ((p)->msg_enable & NETIF_MSG_TX_QUEUED)
2800#define netif_msg_intr(p) ((p)->msg_enable & NETIF_MSG_INTR)
2801#define netif_msg_tx_done(p) ((p)->msg_enable & NETIF_MSG_TX_DONE)
2802#define netif_msg_rx_status(p) ((p)->msg_enable & NETIF_MSG_RX_STATUS)
2803#define netif_msg_pktdata(p) ((p)->msg_enable & NETIF_MSG_PKTDATA)
2804#define netif_msg_hw(p) ((p)->msg_enable & NETIF_MSG_HW)
2805#define netif_msg_wol(p) ((p)->msg_enable & NETIF_MSG_WOL)
2806
2807static inline u32 netif_msg_init(int debug_value, int default_msg_enable_bits)
2808{
2809
2810 if (debug_value < 0 || debug_value >= (sizeof(u32) * 8))
2811 return default_msg_enable_bits;
2812 if (debug_value == 0)
2813 return 0;
2814
2815 return (1 << debug_value) - 1;
2816}
2817
2818static inline void __netif_tx_lock(struct netdev_queue *txq, int cpu)
2819{
2820 spin_lock(&txq->_xmit_lock);
2821 txq->xmit_lock_owner = cpu;
2822}
2823
2824static inline void __netif_tx_lock_bh(struct netdev_queue *txq)
2825{
2826 spin_lock_bh(&txq->_xmit_lock);
2827 txq->xmit_lock_owner = smp_processor_id();
2828}
2829
2830static inline bool __netif_tx_trylock(struct netdev_queue *txq)
2831{
2832 bool ok = spin_trylock(&txq->_xmit_lock);
2833 if (likely(ok))
2834 txq->xmit_lock_owner = smp_processor_id();
2835 return ok;
2836}
2837
2838static inline void __netif_tx_unlock(struct netdev_queue *txq)
2839{
2840 txq->xmit_lock_owner = -1;
2841 spin_unlock(&txq->_xmit_lock);
2842}
2843
2844static inline void __netif_tx_unlock_bh(struct netdev_queue *txq)
2845{
2846 txq->xmit_lock_owner = -1;
2847 spin_unlock_bh(&txq->_xmit_lock);
2848}
2849
2850static inline void txq_trans_update(struct netdev_queue *txq)
2851{
2852 if (txq->xmit_lock_owner != -1)
2853 txq->trans_start = jiffies;
2854}
2855
2856
2857
2858
2859
2860
2861
2862static inline void netif_tx_lock(struct net_device *dev)
2863{
2864 unsigned int i;
2865 int cpu;
2866
2867 spin_lock(&dev->tx_global_lock);
2868 cpu = smp_processor_id();
2869 for (i = 0; i < dev->num_tx_queues; i++) {
2870 struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
2871
2872
2873
2874
2875
2876
2877
2878 __netif_tx_lock(txq, cpu);
2879 set_bit(__QUEUE_STATE_FROZEN, &txq->state);
2880 __netif_tx_unlock(txq);
2881 }
2882}
2883
2884static inline void netif_tx_lock_bh(struct net_device *dev)
2885{
2886 local_bh_disable();
2887 netif_tx_lock(dev);
2888}
2889
2890static inline void netif_tx_unlock(struct net_device *dev)
2891{
2892 unsigned int i;
2893
2894 for (i = 0; i < dev->num_tx_queues; i++) {
2895 struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
2896
2897
2898
2899
2900
2901 clear_bit(__QUEUE_STATE_FROZEN, &txq->state);
2902 netif_schedule_queue(txq);
2903 }
2904 spin_unlock(&dev->tx_global_lock);
2905}
2906
2907static inline void netif_tx_unlock_bh(struct net_device *dev)
2908{
2909 netif_tx_unlock(dev);
2910 local_bh_enable();
2911}
2912
2913#define HARD_TX_LOCK(dev, txq, cpu) { \
2914 if ((dev->features & NETIF_F_LLTX) == 0) { \
2915 __netif_tx_lock(txq, cpu); \
2916 } \
2917}
2918
2919#define HARD_TX_TRYLOCK(dev, txq) \
2920 (((dev->features & NETIF_F_LLTX) == 0) ? \
2921 __netif_tx_trylock(txq) : \
2922 true )
2923
2924#define HARD_TX_UNLOCK(dev, txq) { \
2925 if ((dev->features & NETIF_F_LLTX) == 0) { \
2926 __netif_tx_unlock(txq); \
2927 } \
2928}
2929
2930static inline void netif_tx_disable(struct net_device *dev)
2931{
2932 unsigned int i;
2933 int cpu;
2934
2935 local_bh_disable();
2936 cpu = smp_processor_id();
2937 for (i = 0; i < dev->num_tx_queues; i++) {
2938 struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
2939
2940 __netif_tx_lock(txq, cpu);
2941 netif_tx_stop_queue(txq);
2942 __netif_tx_unlock(txq);
2943 }
2944 local_bh_enable();
2945}
2946
2947static inline void netif_addr_lock(struct net_device *dev)
2948{
2949 spin_lock(&dev->addr_list_lock);
2950}
2951
2952static inline void netif_addr_lock_nested(struct net_device *dev)
2953{
2954 int subclass = SINGLE_DEPTH_NESTING;
2955
2956 if (dev->netdev_ops->ndo_get_lock_subclass)
2957 subclass = dev->netdev_ops->ndo_get_lock_subclass(dev);
2958
2959 spin_lock_nested(&dev->addr_list_lock, subclass);
2960}
2961
2962static inline void netif_addr_lock_bh(struct net_device *dev)
2963{
2964 spin_lock_bh(&dev->addr_list_lock);
2965}
2966
2967static inline void netif_addr_unlock(struct net_device *dev)
2968{
2969 spin_unlock(&dev->addr_list_lock);
2970}
2971
2972static inline void netif_addr_unlock_bh(struct net_device *dev)
2973{
2974 spin_unlock_bh(&dev->addr_list_lock);
2975}
2976
2977
2978
2979
2980
2981#define for_each_dev_addr(dev, ha) \
2982 list_for_each_entry_rcu(ha, &dev->dev_addrs.list, list)
2983
2984
2985
2986void ether_setup(struct net_device *dev);
2987
2988
2989struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name,
2990 void (*setup)(struct net_device *),
2991 unsigned int txqs, unsigned int rxqs);
2992#define alloc_netdev(sizeof_priv, name, setup) \
2993 alloc_netdev_mqs(sizeof_priv, name, setup, 1, 1)
2994
2995#define alloc_netdev_mq(sizeof_priv, name, setup, count) \
2996 alloc_netdev_mqs(sizeof_priv, name, setup, count, count)
2997
2998int register_netdev(struct net_device *dev);
2999void unregister_netdev(struct net_device *dev);
3000
3001
3002int __hw_addr_sync(struct netdev_hw_addr_list *to_list,
3003 struct netdev_hw_addr_list *from_list, int addr_len);
3004void __hw_addr_unsync(struct netdev_hw_addr_list *to_list,
3005 struct netdev_hw_addr_list *from_list, int addr_len);
3006void __hw_addr_init(struct netdev_hw_addr_list *list);
3007
3008
3009int dev_addr_add(struct net_device *dev, const unsigned char *addr,
3010 unsigned char addr_type);
3011int dev_addr_del(struct net_device *dev, const unsigned char *addr,
3012 unsigned char addr_type);
3013void dev_addr_flush(struct net_device *dev);
3014int dev_addr_init(struct net_device *dev);
3015
3016
3017int dev_uc_add(struct net_device *dev, const unsigned char *addr);
3018int dev_uc_add_excl(struct net_device *dev, const unsigned char *addr);
3019int dev_uc_del(struct net_device *dev, const unsigned char *addr);
3020int dev_uc_sync(struct net_device *to, struct net_device *from);
3021int dev_uc_sync_multiple(struct net_device *to, struct net_device *from);
3022void dev_uc_unsync(struct net_device *to, struct net_device *from);
3023void dev_uc_flush(struct net_device *dev);
3024void dev_uc_init(struct net_device *dev);
3025
3026
3027int dev_mc_add(struct net_device *dev, const unsigned char *addr);
3028int dev_mc_add_global(struct net_device *dev, const unsigned char *addr);
3029int dev_mc_add_excl(struct net_device *dev, const unsigned char *addr);
3030int dev_mc_del(struct net_device *dev, const unsigned char *addr);
3031int dev_mc_del_global(struct net_device *dev, const unsigned char *addr);
3032int dev_mc_sync(struct net_device *to, struct net_device *from);
3033int dev_mc_sync_multiple(struct net_device *to, struct net_device *from);
3034void dev_mc_unsync(struct net_device *to, struct net_device *from);
3035void dev_mc_flush(struct net_device *dev);
3036void dev_mc_init(struct net_device *dev);
3037
3038
3039void dev_set_rx_mode(struct net_device *dev);
3040void __dev_set_rx_mode(struct net_device *dev);
3041int dev_set_promiscuity(struct net_device *dev, int inc);
3042int dev_set_allmulti(struct net_device *dev, int inc);
3043void netdev_state_change(struct net_device *dev);
3044void netdev_notify_peers(struct net_device *dev);
3045void netdev_features_change(struct net_device *dev);
3046
3047void dev_load(struct net *net, const char *name);
3048struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
3049 struct rtnl_link_stats64 *storage);
3050void netdev_stats_to_stats64(struct rtnl_link_stats64 *stats64,
3051 const struct net_device_stats *netdev_stats);
3052
3053extern int netdev_max_backlog;
3054extern int netdev_tstamp_prequeue;
3055extern int weight_p;
3056extern int bpf_jit_enable;
3057
3058bool netdev_has_upper_dev(struct net_device *dev, struct net_device *upper_dev);
3059struct net_device *netdev_upper_get_next_dev_rcu(struct net_device *dev,
3060 struct list_head **iter);
3061struct net_device *netdev_all_upper_get_next_dev_rcu(struct net_device *dev,
3062 struct list_head **iter);
3063
3064
3065#define netdev_for_each_upper_dev_rcu(dev, updev, iter) \
3066 for (iter = &(dev)->adj_list.upper, \
3067 updev = netdev_upper_get_next_dev_rcu(dev, &(iter)); \
3068 updev; \
3069 updev = netdev_upper_get_next_dev_rcu(dev, &(iter)))
3070
3071
3072#define netdev_for_each_all_upper_dev_rcu(dev, updev, iter) \
3073 for (iter = &(dev)->all_adj_list.upper, \
3074 updev = netdev_all_upper_get_next_dev_rcu(dev, &(iter)); \
3075 updev; \
3076 updev = netdev_all_upper_get_next_dev_rcu(dev, &(iter)))
3077
3078void *netdev_lower_get_next_private(struct net_device *dev,
3079 struct list_head **iter);
3080void *netdev_lower_get_next_private_rcu(struct net_device *dev,
3081 struct list_head **iter);
3082
3083#define netdev_for_each_lower_private(dev, priv, iter) \
3084 for (iter = (dev)->adj_list.lower.next, \
3085 priv = netdev_lower_get_next_private(dev, &(iter)); \
3086 priv; \
3087 priv = netdev_lower_get_next_private(dev, &(iter)))
3088
3089#define netdev_for_each_lower_private_rcu(dev, priv, iter) \
3090 for (iter = &(dev)->adj_list.lower, \
3091 priv = netdev_lower_get_next_private_rcu(dev, &(iter)); \
3092 priv; \
3093 priv = netdev_lower_get_next_private_rcu(dev, &(iter)))
3094
3095void *netdev_lower_get_next(struct net_device *dev,
3096 struct list_head **iter);
3097#define netdev_for_each_lower_dev(dev, ldev, iter) \
3098 for (iter = &(dev)->adj_list.lower, \
3099 ldev = netdev_lower_get_next(dev, &(iter)); \
3100 ldev; \
3101 ldev = netdev_lower_get_next(dev, &(iter)))
3102
3103void *netdev_adjacent_get_private(struct list_head *adj_list);
3104void *netdev_lower_get_first_private_rcu(struct net_device *dev);
3105struct net_device *netdev_master_upper_dev_get(struct net_device *dev);
3106struct net_device *netdev_master_upper_dev_get_rcu(struct net_device *dev);
3107int netdev_upper_dev_link(struct net_device *dev, struct net_device *upper_dev);
3108int netdev_master_upper_dev_link(struct net_device *dev,
3109 struct net_device *upper_dev);
3110int netdev_master_upper_dev_link_private(struct net_device *dev,
3111 struct net_device *upper_dev,
3112 void *private);
3113void netdev_upper_dev_unlink(struct net_device *dev,
3114 struct net_device *upper_dev);
3115void netdev_adjacent_rename_links(struct net_device *dev, char *oldname);
3116void *netdev_lower_dev_get_private(struct net_device *dev,
3117 struct net_device *lower_dev);
3118int dev_get_nest_level(struct net_device *dev,
3119 bool (*type_check)(struct net_device *dev));
3120int skb_checksum_help(struct sk_buff *skb);
3121struct sk_buff *__skb_gso_segment(struct sk_buff *skb,
3122 netdev_features_t features, bool tx_path);
3123struct sk_buff *skb_mac_gso_segment(struct sk_buff *skb,
3124 netdev_features_t features);
3125
3126static inline
3127struct sk_buff *skb_gso_segment(struct sk_buff *skb, netdev_features_t features)
3128{
3129 return __skb_gso_segment(skb, features, true);
3130}
3131__be16 skb_network_protocol(struct sk_buff *skb, int *depth);
3132
3133static inline bool can_checksum_protocol(netdev_features_t features,
3134 __be16 protocol)
3135{
3136 return ((features & NETIF_F_GEN_CSUM) ||
3137 ((features & NETIF_F_V4_CSUM) &&
3138 protocol == htons(ETH_P_IP)) ||
3139 ((features & NETIF_F_V6_CSUM) &&
3140 protocol == htons(ETH_P_IPV6)) ||
3141 ((features & NETIF_F_FCOE_CRC) &&
3142 protocol == htons(ETH_P_FCOE)));
3143}
3144
3145#ifdef CONFIG_BUG
3146void netdev_rx_csum_fault(struct net_device *dev);
3147#else
3148static inline void netdev_rx_csum_fault(struct net_device *dev)
3149{
3150}
3151#endif
3152
3153void net_enable_timestamp(void);
3154void net_disable_timestamp(void);
3155
3156#ifdef CONFIG_PROC_FS
3157int __init dev_proc_init(void);
3158#else
3159#define dev_proc_init() 0
3160#endif
3161
3162int netdev_class_create_file_ns(struct class_attribute *class_attr,
3163 const void *ns);
3164void netdev_class_remove_file_ns(struct class_attribute *class_attr,
3165 const void *ns);
3166
3167static inline int netdev_class_create_file(struct class_attribute *class_attr)
3168{
3169 return netdev_class_create_file_ns(class_attr, NULL);
3170}
3171
3172static inline void netdev_class_remove_file(struct class_attribute *class_attr)
3173{
3174 netdev_class_remove_file_ns(class_attr, NULL);
3175}
3176
3177extern struct kobj_ns_type_operations net_ns_type_operations;
3178
3179const char *netdev_drivername(const struct net_device *dev);
3180
3181void linkwatch_run_queue(void);
3182
3183static inline netdev_features_t netdev_get_wanted_features(
3184 struct net_device *dev)
3185{
3186 return (dev->features & ~dev->hw_features) | dev->wanted_features;
3187}
3188netdev_features_t netdev_increment_features(netdev_features_t all,
3189 netdev_features_t one, netdev_features_t mask);
3190
3191
3192
3193
3194
3195static inline netdev_features_t netdev_add_tso_features(netdev_features_t features,
3196 netdev_features_t mask)
3197{
3198 return netdev_increment_features(features, NETIF_F_ALL_TSO, mask);
3199}
3200
3201int __netdev_update_features(struct net_device *dev);
3202void netdev_update_features(struct net_device *dev);
3203void netdev_change_features(struct net_device *dev);
3204
3205void netif_stacked_transfer_operstate(const struct net_device *rootdev,
3206 struct net_device *dev);
3207
3208netdev_features_t netif_skb_features(struct sk_buff *skb);
3209
3210static inline bool net_gso_ok(netdev_features_t features, int gso_type)
3211{
3212 netdev_features_t feature = gso_type << NETIF_F_GSO_SHIFT;
3213
3214
3215 BUILD_BUG_ON(SKB_GSO_TCPV4 != (NETIF_F_TSO >> NETIF_F_GSO_SHIFT));
3216 BUILD_BUG_ON(SKB_GSO_UDP != (NETIF_F_UFO >> NETIF_F_GSO_SHIFT));
3217 BUILD_BUG_ON(SKB_GSO_DODGY != (NETIF_F_GSO_ROBUST >> NETIF_F_GSO_SHIFT));
3218 BUILD_BUG_ON(SKB_GSO_TCP_ECN != (NETIF_F_TSO_ECN >> NETIF_F_GSO_SHIFT));
3219 BUILD_BUG_ON(SKB_GSO_TCPV6 != (NETIF_F_TSO6 >> NETIF_F_GSO_SHIFT));
3220 BUILD_BUG_ON(SKB_GSO_FCOE != (NETIF_F_FSO >> NETIF_F_GSO_SHIFT));
3221
3222 return (features & feature) == feature;
3223}
3224
3225static inline bool skb_gso_ok(struct sk_buff *skb, netdev_features_t features)
3226{
3227 return net_gso_ok(features, skb_shinfo(skb)->gso_type) &&
3228 (!skb_has_frag_list(skb) || (features & NETIF_F_FRAGLIST));
3229}
3230
3231static inline bool netif_needs_gso(struct sk_buff *skb,
3232 netdev_features_t features)
3233{
3234 return skb_is_gso(skb) && (!skb_gso_ok(skb, features) ||
3235 unlikely((skb->ip_summed != CHECKSUM_PARTIAL) &&
3236 (skb->ip_summed != CHECKSUM_UNNECESSARY)));
3237}
3238
3239static inline void netif_set_gso_max_size(struct net_device *dev,
3240 unsigned int size)
3241{
3242 dev->gso_max_size = size;
3243}
3244
3245static inline void skb_gso_error_unwind(struct sk_buff *skb, __be16 protocol,
3246 int pulled_hlen, u16 mac_offset,
3247 int mac_len)
3248{
3249 skb->protocol = protocol;
3250 skb->encapsulation = 1;
3251 skb_push(skb, pulled_hlen);
3252 skb_reset_transport_header(skb);
3253 skb->mac_header = mac_offset;
3254 skb->network_header = skb->mac_header + mac_len;
3255 skb->mac_len = mac_len;
3256}
3257
3258static inline bool netif_is_macvlan(struct net_device *dev)
3259{
3260 return dev->priv_flags & IFF_MACVLAN;
3261}
3262
3263static inline bool netif_is_bond_master(struct net_device *dev)
3264{
3265 return dev->flags & IFF_MASTER && dev->priv_flags & IFF_BONDING;
3266}
3267
3268static inline bool netif_is_bond_slave(struct net_device *dev)
3269{
3270 return dev->flags & IFF_SLAVE && dev->priv_flags & IFF_BONDING;
3271}
3272
3273static inline bool netif_supports_nofcs(struct net_device *dev)
3274{
3275 return dev->priv_flags & IFF_SUPP_NOFCS;
3276}
3277
3278extern struct pernet_operations __net_initdata loopback_net_ops;
3279
3280
3281
3282
3283
3284static inline const char *netdev_name(const struct net_device *dev)
3285{
3286 if (dev->reg_state != NETREG_REGISTERED)
3287 return "(unregistered net_device)";
3288 return dev->name;
3289}
3290
3291__printf(3, 4)
3292int netdev_printk(const char *level, const struct net_device *dev,
3293 const char *format, ...);
3294__printf(2, 3)
3295int netdev_emerg(const struct net_device *dev, const char *format, ...);
3296__printf(2, 3)
3297int netdev_alert(const struct net_device *dev, const char *format, ...);
3298__printf(2, 3)
3299int netdev_crit(const struct net_device *dev, const char *format, ...);
3300__printf(2, 3)
3301int netdev_err(const struct net_device *dev, const char *format, ...);
3302__printf(2, 3)
3303int netdev_warn(const struct net_device *dev, const char *format, ...);
3304__printf(2, 3)
3305int netdev_notice(const struct net_device *dev, const char *format, ...);
3306__printf(2, 3)
3307int netdev_info(const struct net_device *dev, const char *format, ...);
3308
3309#define MODULE_ALIAS_NETDEV(device) \
3310 MODULE_ALIAS("netdev-" device)
3311
3312#if defined(CONFIG_DYNAMIC_DEBUG)
3313#define netdev_dbg(__dev, format, args...) \
3314do { \
3315 dynamic_netdev_dbg(__dev, format, ##args); \
3316} while (0)
3317#elif defined(DEBUG)
3318#define netdev_dbg(__dev, format, args...) \
3319 netdev_printk(KERN_DEBUG, __dev, format, ##args)
3320#else
3321#define netdev_dbg(__dev, format, args...) \
3322({ \
3323 if (0) \
3324 netdev_printk(KERN_DEBUG, __dev, format, ##args); \
3325 0; \
3326})
3327#endif
3328
3329#if defined(VERBOSE_DEBUG)
3330#define netdev_vdbg netdev_dbg
3331#else
3332
3333#define netdev_vdbg(dev, format, args...) \
3334({ \
3335 if (0) \
3336 netdev_printk(KERN_DEBUG, dev, format, ##args); \
3337 0; \
3338})
3339#endif
3340
3341
3342
3343
3344
3345
3346#define netdev_WARN(dev, format, args...) \
3347 WARN(1, "netdevice: %s\n" format, netdev_name(dev), ##args)
3348
3349
3350
3351#define netif_printk(priv, type, level, dev, fmt, args...) \
3352do { \
3353 if (netif_msg_##type(priv)) \
3354 netdev_printk(level, (dev), fmt, ##args); \
3355} while (0)
3356
3357#define netif_level(level, priv, type, dev, fmt, args...) \
3358do { \
3359 if (netif_msg_##type(priv)) \
3360 netdev_##level(dev, fmt, ##args); \
3361} while (0)
3362
3363#define netif_emerg(priv, type, dev, fmt, args...) \
3364 netif_level(emerg, priv, type, dev, fmt, ##args)
3365#define netif_alert(priv, type, dev, fmt, args...) \
3366 netif_level(alert, priv, type, dev, fmt, ##args)
3367#define netif_crit(priv, type, dev, fmt, args...) \
3368 netif_level(crit, priv, type, dev, fmt, ##args)
3369#define netif_err(priv, type, dev, fmt, args...) \
3370 netif_level(err, priv, type, dev, fmt, ##args)
3371#define netif_warn(priv, type, dev, fmt, args...) \
3372 netif_level(warn, priv, type, dev, fmt, ##args)
3373#define netif_notice(priv, type, dev, fmt, args...) \
3374 netif_level(notice, priv, type, dev, fmt, ##args)
3375#define netif_info(priv, type, dev, fmt, args...) \
3376 netif_level(info, priv, type, dev, fmt, ##args)
3377
3378#if defined(CONFIG_DYNAMIC_DEBUG)
3379#define netif_dbg(priv, type, netdev, format, args...) \
3380do { \
3381 if (netif_msg_##type(priv)) \
3382 dynamic_netdev_dbg(netdev, format, ##args); \
3383} while (0)
3384#elif defined(DEBUG)
3385#define netif_dbg(priv, type, dev, format, args...) \
3386 netif_printk(priv, type, KERN_DEBUG, dev, format, ##args)
3387#else
3388#define netif_dbg(priv, type, dev, format, args...) \
3389({ \
3390 if (0) \
3391 netif_printk(priv, type, KERN_DEBUG, dev, format, ##args); \
3392 0; \
3393})
3394#endif
3395
3396#if defined(VERBOSE_DEBUG)
3397#define netif_vdbg netif_dbg
3398#else
3399#define netif_vdbg(priv, type, dev, format, args...) \
3400({ \
3401 if (0) \
3402 netif_printk(priv, type, KERN_DEBUG, dev, format, ##args); \
3403 0; \
3404})
3405#endif
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434#define PTYPE_HASH_SIZE (16)
3435#define PTYPE_HASH_MASK (PTYPE_HASH_SIZE - 1)
3436
3437#endif
3438