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/if.h>
29#include <linux/if_ether.h>
30#include <linux/if_packet.h>
31#include <linux/if_link.h>
32
33#ifdef __KERNEL__
34#include <linux/pm_qos.h>
35#include <linux/timer.h>
36#include <linux/delay.h>
37#include <linux/atomic.h>
38#include <asm/cache.h>
39#include <asm/byteorder.h>
40
41#include <linux/device.h>
42#include <linux/percpu.h>
43#include <linux/rculist.h>
44#include <linux/dmaengine.h>
45#include <linux/workqueue.h>
46#include <linux/dynamic_queue_limits.h>
47
48#include <linux/ethtool.h>
49#include <net/net_namespace.h>
50#include <net/dsa.h>
51#ifdef CONFIG_DCB
52#include <net/dcbnl.h>
53#endif
54#include <net/netprio_cgroup.h>
55
56#include <linux/netdev_features.h>
57
58struct netpoll_info;
59struct phy_device;
60
61struct wireless_dev;
62
63#define SET_ETHTOOL_OPS(netdev,ops) \
64 ( (netdev)->ethtool_ops = (ops) )
65
66
67#define NET_ADDR_PERM 0
68#define NET_ADDR_RANDOM 1
69#define NET_ADDR_STOLEN 2
70
71
72#define NET_RX_SUCCESS 0
73#define NET_RX_DROP 1
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93#define NET_XMIT_SUCCESS 0x00
94#define NET_XMIT_DROP 0x01
95#define NET_XMIT_CN 0x02
96#define NET_XMIT_POLICED 0x03
97#define NET_XMIT_MASK 0x0f
98
99
100
101
102#define net_xmit_eval(e) ((e) == NET_XMIT_CN ? 0 : (e))
103#define net_xmit_errno(e) ((e) != NET_XMIT_CN ? -ENOBUFS : 0)
104
105
106#define NETDEV_TX_MASK 0xf0
107
108enum netdev_tx {
109 __NETDEV_TX_MIN = INT_MIN,
110 NETDEV_TX_OK = 0x00,
111 NETDEV_TX_BUSY = 0x10,
112 NETDEV_TX_LOCKED = 0x20,
113};
114typedef enum netdev_tx netdev_tx_t;
115
116
117
118
119
120static inline bool dev_xmit_complete(int rc)
121{
122
123
124
125
126
127
128 if (likely(rc < NET_XMIT_MASK))
129 return true;
130
131 return false;
132}
133
134#endif
135
136#define MAX_ADDR_LEN 32
137
138
139#define INIT_NETDEV_GROUP 0
140
141#ifdef __KERNEL__
142
143
144
145
146
147#if defined(CONFIG_WLAN) || IS_ENABLED(CONFIG_AX25)
148# if defined(CONFIG_MAC80211_MESH)
149# define LL_MAX_HEADER 128
150# else
151# define LL_MAX_HEADER 96
152# endif
153#elif IS_ENABLED(CONFIG_TR)
154# define LL_MAX_HEADER 48
155#else
156# define LL_MAX_HEADER 32
157#endif
158
159#if !IS_ENABLED(CONFIG_NET_IPIP) && !IS_ENABLED(CONFIG_NET_IPGRE) && \
160 !IS_ENABLED(CONFIG_IPV6_SIT) && !IS_ENABLED(CONFIG_IPV6_TUNNEL)
161#define MAX_HEADER LL_MAX_HEADER
162#else
163#define MAX_HEADER (LL_MAX_HEADER + 48)
164#endif
165
166
167
168
169
170
171struct net_device_stats {
172 unsigned long rx_packets;
173 unsigned long tx_packets;
174 unsigned long rx_bytes;
175 unsigned long tx_bytes;
176 unsigned long rx_errors;
177 unsigned long tx_errors;
178 unsigned long rx_dropped;
179 unsigned long tx_dropped;
180 unsigned long multicast;
181 unsigned long collisions;
182 unsigned long rx_length_errors;
183 unsigned long rx_over_errors;
184 unsigned long rx_crc_errors;
185 unsigned long rx_frame_errors;
186 unsigned long rx_fifo_errors;
187 unsigned long rx_missed_errors;
188 unsigned long tx_aborted_errors;
189 unsigned long tx_carrier_errors;
190 unsigned long tx_fifo_errors;
191 unsigned long tx_heartbeat_errors;
192 unsigned long tx_window_errors;
193 unsigned long rx_compressed;
194 unsigned long tx_compressed;
195};
196
197#endif
198
199
200
201enum {
202 IF_PORT_UNKNOWN = 0,
203 IF_PORT_10BASE2,
204 IF_PORT_10BASET,
205 IF_PORT_AUI,
206 IF_PORT_100BASET,
207 IF_PORT_100BASETX,
208 IF_PORT_100BASEFX
209};
210
211#ifdef __KERNEL__
212
213#include <linux/cache.h>
214#include <linux/skbuff.h>
215
216#ifdef CONFIG_RPS
217#include <linux/jump_label.h>
218extern struct jump_label_key rps_needed;
219#endif
220
221struct neighbour;
222struct neigh_parms;
223struct sk_buff;
224
225struct netdev_hw_addr {
226 struct list_head list;
227 unsigned char addr[MAX_ADDR_LEN];
228 unsigned char type;
229#define NETDEV_HW_ADDR_T_LAN 1
230#define NETDEV_HW_ADDR_T_SAN 2
231#define NETDEV_HW_ADDR_T_SLAVE 3
232#define NETDEV_HW_ADDR_T_UNICAST 4
233#define NETDEV_HW_ADDR_T_MULTICAST 5
234 bool synced;
235 bool global_use;
236 int refcount;
237 struct rcu_head rcu_head;
238};
239
240struct netdev_hw_addr_list {
241 struct list_head list;
242 int count;
243};
244
245#define netdev_hw_addr_list_count(l) ((l)->count)
246#define netdev_hw_addr_list_empty(l) (netdev_hw_addr_list_count(l) == 0)
247#define netdev_hw_addr_list_for_each(ha, l) \
248 list_for_each_entry(ha, &(l)->list, list)
249
250#define netdev_uc_count(dev) netdev_hw_addr_list_count(&(dev)->uc)
251#define netdev_uc_empty(dev) netdev_hw_addr_list_empty(&(dev)->uc)
252#define netdev_for_each_uc_addr(ha, dev) \
253 netdev_hw_addr_list_for_each(ha, &(dev)->uc)
254
255#define netdev_mc_count(dev) netdev_hw_addr_list_count(&(dev)->mc)
256#define netdev_mc_empty(dev) netdev_hw_addr_list_empty(&(dev)->mc)
257#define netdev_for_each_mc_addr(ha, dev) \
258 netdev_hw_addr_list_for_each(ha, &(dev)->mc)
259
260struct hh_cache {
261 u16 hh_len;
262 u16 __pad;
263 seqlock_t hh_lock;
264
265
266#define HH_DATA_MOD 16
267#define HH_DATA_OFF(__len) \
268 (HH_DATA_MOD - (((__len - 1) & (HH_DATA_MOD - 1)) + 1))
269#define HH_DATA_ALIGN(__len) \
270 (((__len)+(HH_DATA_MOD-1))&~(HH_DATA_MOD - 1))
271 unsigned long hh_data[HH_DATA_ALIGN(LL_MAX_HEADER) / sizeof(long)];
272};
273
274
275
276
277
278
279
280
281
282#define LL_RESERVED_SPACE(dev) \
283 ((((dev)->hard_header_len+(dev)->needed_headroom)&~(HH_DATA_MOD - 1)) + HH_DATA_MOD)
284#define LL_RESERVED_SPACE_EXTRA(dev,extra) \
285 ((((dev)->hard_header_len+(dev)->needed_headroom+(extra))&~(HH_DATA_MOD - 1)) + HH_DATA_MOD)
286
287struct header_ops {
288 int (*create) (struct sk_buff *skb, struct net_device *dev,
289 unsigned short type, const void *daddr,
290 const void *saddr, unsigned len);
291 int (*parse)(const struct sk_buff *skb, unsigned char *haddr);
292 int (*rebuild)(struct sk_buff *skb);
293 int (*cache)(const struct neighbour *neigh, struct hh_cache *hh, __be16 type);
294 void (*cache_update)(struct hh_cache *hh,
295 const struct net_device *dev,
296 const unsigned char *haddr);
297};
298
299
300
301
302
303
304enum netdev_state_t {
305 __LINK_STATE_START,
306 __LINK_STATE_PRESENT,
307 __LINK_STATE_NOCARRIER,
308 __LINK_STATE_LINKWATCH_PENDING,
309 __LINK_STATE_DORMANT,
310};
311
312
313
314
315
316
317struct netdev_boot_setup {
318 char name[IFNAMSIZ];
319 struct ifmap map;
320};
321#define NETDEV_BOOT_SETUP_MAX 8
322
323extern int __init netdev_boot_setup(char *str);
324
325
326
327
328struct napi_struct {
329
330
331
332
333
334
335 struct list_head poll_list;
336
337 unsigned long state;
338 int weight;
339 int (*poll)(struct napi_struct *, int);
340#ifdef CONFIG_NETPOLL
341 spinlock_t poll_lock;
342 int poll_owner;
343#endif
344
345 unsigned int gro_count;
346
347 struct net_device *dev;
348 struct list_head dev_list;
349 struct sk_buff *gro_list;
350 struct sk_buff *skb;
351};
352
353enum {
354 NAPI_STATE_SCHED,
355 NAPI_STATE_DISABLE,
356 NAPI_STATE_NPSVC,
357};
358
359enum gro_result {
360 GRO_MERGED,
361 GRO_MERGED_FREE,
362 GRO_HELD,
363 GRO_NORMAL,
364 GRO_DROP,
365};
366typedef enum gro_result gro_result_t;
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409enum rx_handler_result {
410 RX_HANDLER_CONSUMED,
411 RX_HANDLER_ANOTHER,
412 RX_HANDLER_EXACT,
413 RX_HANDLER_PASS,
414};
415typedef enum rx_handler_result rx_handler_result_t;
416typedef rx_handler_result_t rx_handler_func_t(struct sk_buff **pskb);
417
418extern void __napi_schedule(struct napi_struct *n);
419
420static inline int napi_disable_pending(struct napi_struct *n)
421{
422 return test_bit(NAPI_STATE_DISABLE, &n->state);
423}
424
425
426
427
428
429
430
431
432
433
434static inline int napi_schedule_prep(struct napi_struct *n)
435{
436 return !napi_disable_pending(n) &&
437 !test_and_set_bit(NAPI_STATE_SCHED, &n->state);
438}
439
440
441
442
443
444
445
446
447static inline void napi_schedule(struct napi_struct *n)
448{
449 if (napi_schedule_prep(n))
450 __napi_schedule(n);
451}
452
453
454static inline int napi_reschedule(struct napi_struct *napi)
455{
456 if (napi_schedule_prep(napi)) {
457 __napi_schedule(napi);
458 return 1;
459 }
460 return 0;
461}
462
463
464
465
466
467
468
469extern void __napi_complete(struct napi_struct *n);
470extern void napi_complete(struct napi_struct *n);
471
472
473
474
475
476
477
478
479static inline void napi_disable(struct napi_struct *n)
480{
481 set_bit(NAPI_STATE_DISABLE, &n->state);
482 while (test_and_set_bit(NAPI_STATE_SCHED, &n->state))
483 msleep(1);
484 clear_bit(NAPI_STATE_DISABLE, &n->state);
485}
486
487
488
489
490
491
492
493
494static inline void napi_enable(struct napi_struct *n)
495{
496 BUG_ON(!test_bit(NAPI_STATE_SCHED, &n->state));
497 smp_mb__before_clear_bit();
498 clear_bit(NAPI_STATE_SCHED, &n->state);
499}
500
501#ifdef CONFIG_SMP
502
503
504
505
506
507
508
509
510static inline void napi_synchronize(const struct napi_struct *n)
511{
512 while (test_bit(NAPI_STATE_SCHED, &n->state))
513 msleep(1);
514}
515#else
516# define napi_synchronize(n) barrier()
517#endif
518
519enum netdev_queue_state_t {
520 __QUEUE_STATE_DRV_XOFF,
521 __QUEUE_STATE_STACK_XOFF,
522 __QUEUE_STATE_FROZEN,
523#define QUEUE_STATE_ANY_XOFF ((1 << __QUEUE_STATE_DRV_XOFF) | \
524 (1 << __QUEUE_STATE_STACK_XOFF))
525#define QUEUE_STATE_ANY_XOFF_OR_FROZEN (QUEUE_STATE_ANY_XOFF | \
526 (1 << __QUEUE_STATE_FROZEN))
527};
528
529
530
531
532
533
534
535
536
537
538struct netdev_queue {
539
540
541
542 struct net_device *dev;
543 struct Qdisc *qdisc;
544 struct Qdisc *qdisc_sleeping;
545#ifdef CONFIG_SYSFS
546 struct kobject kobj;
547#endif
548#if defined(CONFIG_XPS) && defined(CONFIG_NUMA)
549 int numa_node;
550#endif
551
552
553
554 spinlock_t _xmit_lock ____cacheline_aligned_in_smp;
555 int xmit_lock_owner;
556
557
558
559 unsigned long trans_start;
560
561
562
563
564
565 unsigned long trans_timeout;
566
567 unsigned long state;
568
569#ifdef CONFIG_BQL
570 struct dql dql;
571#endif
572} ____cacheline_aligned_in_smp;
573
574static inline int netdev_queue_numa_node_read(const struct netdev_queue *q)
575{
576#if defined(CONFIG_XPS) && defined(CONFIG_NUMA)
577 return q->numa_node;
578#else
579 return NUMA_NO_NODE;
580#endif
581}
582
583static inline void netdev_queue_numa_node_write(struct netdev_queue *q, int node)
584{
585#if defined(CONFIG_XPS) && defined(CONFIG_NUMA)
586 q->numa_node = node;
587#endif
588}
589
590#ifdef CONFIG_RPS
591
592
593
594
595struct rps_map {
596 unsigned int len;
597 struct rcu_head rcu;
598 u16 cpus[0];
599};
600#define RPS_MAP_SIZE(_num) (sizeof(struct rps_map) + ((_num) * sizeof(u16)))
601
602
603
604
605
606
607struct rps_dev_flow {
608 u16 cpu;
609 u16 filter;
610 unsigned int last_qtail;
611};
612#define RPS_NO_FILTER 0xffff
613
614
615
616
617struct rps_dev_flow_table {
618 unsigned int mask;
619 struct rcu_head rcu;
620 struct work_struct free_work;
621 struct rps_dev_flow flows[0];
622};
623#define RPS_DEV_FLOW_TABLE_SIZE(_num) (sizeof(struct rps_dev_flow_table) + \
624 ((_num) * sizeof(struct rps_dev_flow)))
625
626
627
628
629
630struct rps_sock_flow_table {
631 unsigned int mask;
632 u16 ents[0];
633};
634#define RPS_SOCK_FLOW_TABLE_SIZE(_num) (sizeof(struct rps_sock_flow_table) + \
635 ((_num) * sizeof(u16)))
636
637#define RPS_NO_CPU 0xffff
638
639static inline void rps_record_sock_flow(struct rps_sock_flow_table *table,
640 u32 hash)
641{
642 if (table && hash) {
643 unsigned int cpu, index = hash & table->mask;
644
645
646 cpu = raw_smp_processor_id();
647
648 if (table->ents[index] != cpu)
649 table->ents[index] = cpu;
650 }
651}
652
653static inline void rps_reset_sock_flow(struct rps_sock_flow_table *table,
654 u32 hash)
655{
656 if (table && hash)
657 table->ents[hash & table->mask] = RPS_NO_CPU;
658}
659
660extern struct rps_sock_flow_table __rcu *rps_sock_flow_table;
661
662#ifdef CONFIG_RFS_ACCEL
663extern bool rps_may_expire_flow(struct net_device *dev, u16 rxq_index,
664 u32 flow_id, u16 filter_id);
665#endif
666
667
668struct netdev_rx_queue {
669 struct rps_map __rcu *rps_map;
670 struct rps_dev_flow_table __rcu *rps_flow_table;
671 struct kobject kobj;
672 struct net_device *dev;
673} ____cacheline_aligned_in_smp;
674#endif
675
676#ifdef CONFIG_XPS
677
678
679
680
681struct xps_map {
682 unsigned int len;
683 unsigned int alloc_len;
684 struct rcu_head rcu;
685 u16 queues[0];
686};
687#define XPS_MAP_SIZE(_num) (sizeof(struct xps_map) + ((_num) * sizeof(u16)))
688#define XPS_MIN_MAP_ALLOC ((L1_CACHE_BYTES - sizeof(struct xps_map)) \
689 / sizeof(u16))
690
691
692
693
694struct xps_dev_maps {
695 struct rcu_head rcu;
696 struct xps_map __rcu *cpu_map[0];
697};
698#define XPS_DEV_MAPS_SIZE (sizeof(struct xps_dev_maps) + \
699 (nr_cpu_ids * sizeof(struct xps_map *)))
700#endif
701
702#define TC_MAX_QUEUE 16
703#define TC_BITMASK 15
704
705struct netdev_tc_txq {
706 u16 count;
707 u16 offset;
708};
709
710#if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE)
711
712
713
714
715struct netdev_fcoe_hbainfo {
716 char manufacturer[64];
717 char serial_number[64];
718 char hardware_version[64];
719 char driver_version[64];
720 char optionrom_version[64];
721 char firmware_version[64];
722 char model[256];
723 char model_description[256];
724};
725#endif
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
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
908struct net_device_ops {
909 int (*ndo_init)(struct net_device *dev);
910 void (*ndo_uninit)(struct net_device *dev);
911 int (*ndo_open)(struct net_device *dev);
912 int (*ndo_stop)(struct net_device *dev);
913 netdev_tx_t (*ndo_start_xmit) (struct sk_buff *skb,
914 struct net_device *dev);
915 u16 (*ndo_select_queue)(struct net_device *dev,
916 struct sk_buff *skb);
917 void (*ndo_change_rx_flags)(struct net_device *dev,
918 int flags);
919 void (*ndo_set_rx_mode)(struct net_device *dev);
920 int (*ndo_set_mac_address)(struct net_device *dev,
921 void *addr);
922 int (*ndo_validate_addr)(struct net_device *dev);
923 int (*ndo_do_ioctl)(struct net_device *dev,
924 struct ifreq *ifr, int cmd);
925 int (*ndo_set_config)(struct net_device *dev,
926 struct ifmap *map);
927 int (*ndo_change_mtu)(struct net_device *dev,
928 int new_mtu);
929 int (*ndo_neigh_setup)(struct net_device *dev,
930 struct neigh_parms *);
931 void (*ndo_tx_timeout) (struct net_device *dev);
932
933 struct rtnl_link_stats64* (*ndo_get_stats64)(struct net_device *dev,
934 struct rtnl_link_stats64 *storage);
935 struct net_device_stats* (*ndo_get_stats)(struct net_device *dev);
936
937 int (*ndo_vlan_rx_add_vid)(struct net_device *dev,
938 unsigned short vid);
939 int (*ndo_vlan_rx_kill_vid)(struct net_device *dev,
940 unsigned short vid);
941#ifdef CONFIG_NET_POLL_CONTROLLER
942 void (*ndo_poll_controller)(struct net_device *dev);
943 int (*ndo_netpoll_setup)(struct net_device *dev,
944 struct netpoll_info *info);
945 void (*ndo_netpoll_cleanup)(struct net_device *dev);
946#endif
947 int (*ndo_set_vf_mac)(struct net_device *dev,
948 int queue, u8 *mac);
949 int (*ndo_set_vf_vlan)(struct net_device *dev,
950 int queue, u16 vlan, u8 qos);
951 int (*ndo_set_vf_tx_rate)(struct net_device *dev,
952 int vf, int rate);
953 int (*ndo_set_vf_spoofchk)(struct net_device *dev,
954 int vf, bool setting);
955 int (*ndo_get_vf_config)(struct net_device *dev,
956 int vf,
957 struct ifla_vf_info *ivf);
958 int (*ndo_set_vf_port)(struct net_device *dev,
959 int vf,
960 struct nlattr *port[]);
961 int (*ndo_get_vf_port)(struct net_device *dev,
962 int vf, struct sk_buff *skb);
963 int (*ndo_setup_tc)(struct net_device *dev, u8 tc);
964#if IS_ENABLED(CONFIG_FCOE)
965 int (*ndo_fcoe_enable)(struct net_device *dev);
966 int (*ndo_fcoe_disable)(struct net_device *dev);
967 int (*ndo_fcoe_ddp_setup)(struct net_device *dev,
968 u16 xid,
969 struct scatterlist *sgl,
970 unsigned int sgc);
971 int (*ndo_fcoe_ddp_done)(struct net_device *dev,
972 u16 xid);
973 int (*ndo_fcoe_ddp_target)(struct net_device *dev,
974 u16 xid,
975 struct scatterlist *sgl,
976 unsigned int sgc);
977 int (*ndo_fcoe_get_hbainfo)(struct net_device *dev,
978 struct netdev_fcoe_hbainfo *hbainfo);
979#endif
980
981#if IS_ENABLED(CONFIG_LIBFCOE)
982#define NETDEV_FCOE_WWNN 0
983#define NETDEV_FCOE_WWPN 1
984 int (*ndo_fcoe_get_wwn)(struct net_device *dev,
985 u64 *wwn, int type);
986#endif
987
988#ifdef CONFIG_RFS_ACCEL
989 int (*ndo_rx_flow_steer)(struct net_device *dev,
990 const struct sk_buff *skb,
991 u16 rxq_index,
992 u32 flow_id);
993#endif
994 int (*ndo_add_slave)(struct net_device *dev,
995 struct net_device *slave_dev);
996 int (*ndo_del_slave)(struct net_device *dev,
997 struct net_device *slave_dev);
998 netdev_features_t (*ndo_fix_features)(struct net_device *dev,
999 netdev_features_t features);
1000 int (*ndo_set_features)(struct net_device *dev,
1001 netdev_features_t features);
1002 int (*ndo_neigh_construct)(struct neighbour *n);
1003 void (*ndo_neigh_destroy)(struct neighbour *n);
1004};
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016struct net_device {
1017
1018
1019
1020
1021
1022
1023 char name[IFNAMSIZ];
1024
1025 struct pm_qos_request pm_qos_req;
1026
1027
1028 struct hlist_node name_hlist;
1029
1030 char *ifalias;
1031
1032
1033
1034
1035
1036 unsigned long mem_end;
1037 unsigned long mem_start;
1038 unsigned long base_addr;
1039 unsigned int irq;
1040
1041
1042
1043
1044
1045
1046 unsigned long state;
1047
1048 struct list_head dev_list;
1049 struct list_head napi_list;
1050 struct list_head unreg_list;
1051
1052
1053 netdev_features_t features;
1054
1055 netdev_features_t hw_features;
1056
1057 netdev_features_t wanted_features;
1058
1059 netdev_features_t vlan_features;
1060
1061
1062 int ifindex;
1063 int iflink;
1064
1065 struct net_device_stats stats;
1066 atomic_long_t rx_dropped;
1067
1068
1069
1070#ifdef CONFIG_WIRELESS_EXT
1071
1072
1073 const struct iw_handler_def * wireless_handlers;
1074
1075 struct iw_public_data * wireless_data;
1076#endif
1077
1078 const struct net_device_ops *netdev_ops;
1079 const struct ethtool_ops *ethtool_ops;
1080
1081
1082 const struct header_ops *header_ops;
1083
1084 unsigned int flags;
1085 unsigned int priv_flags;
1086 unsigned short gflags;
1087 unsigned short padded;
1088
1089 unsigned char operstate;
1090 unsigned char link_mode;
1091
1092 unsigned char if_port;
1093 unsigned char dma;
1094
1095 unsigned int mtu;
1096 unsigned short type;
1097 unsigned short hard_header_len;
1098
1099
1100
1101
1102
1103 unsigned short needed_headroom;
1104 unsigned short needed_tailroom;
1105
1106
1107 unsigned char perm_addr[MAX_ADDR_LEN];
1108 unsigned char addr_assign_type;
1109 unsigned char addr_len;
1110 unsigned char neigh_priv_len;
1111 unsigned short dev_id;
1112
1113 spinlock_t addr_list_lock;
1114 struct netdev_hw_addr_list uc;
1115 struct netdev_hw_addr_list mc;
1116 bool uc_promisc;
1117 unsigned int promiscuity;
1118 unsigned int allmulti;
1119
1120
1121
1122
1123#if IS_ENABLED(CONFIG_VLAN_8021Q)
1124 struct vlan_info __rcu *vlan_info;
1125#endif
1126#if IS_ENABLED(CONFIG_NET_DSA)
1127 struct dsa_switch_tree *dsa_ptr;
1128#endif
1129 void *atalk_ptr;
1130 struct in_device __rcu *ip_ptr;
1131 struct dn_dev __rcu *dn_ptr;
1132 struct inet6_dev __rcu *ip6_ptr;
1133 void *ec_ptr;
1134 void *ax25_ptr;
1135 struct wireless_dev *ieee80211_ptr;
1136
1137
1138
1139
1140
1141 unsigned long last_rx;
1142
1143
1144
1145
1146
1147
1148
1149 struct net_device *master;
1150
1151
1152
1153
1154 unsigned char *dev_addr;
1155
1156
1157
1158 struct netdev_hw_addr_list dev_addrs;
1159
1160
1161 unsigned char broadcast[MAX_ADDR_LEN];
1162
1163#ifdef CONFIG_SYSFS
1164 struct kset *queues_kset;
1165#endif
1166
1167#ifdef CONFIG_RPS
1168 struct netdev_rx_queue *_rx;
1169
1170
1171 unsigned int num_rx_queues;
1172
1173
1174 unsigned int real_num_rx_queues;
1175
1176#ifdef CONFIG_RFS_ACCEL
1177
1178
1179
1180 struct cpu_rmap *rx_cpu_rmap;
1181#endif
1182#endif
1183
1184 rx_handler_func_t __rcu *rx_handler;
1185 void __rcu *rx_handler_data;
1186
1187 struct netdev_queue __rcu *ingress_queue;
1188
1189
1190
1191
1192 struct netdev_queue *_tx ____cacheline_aligned_in_smp;
1193
1194
1195 unsigned int num_tx_queues;
1196
1197
1198 unsigned int real_num_tx_queues;
1199
1200
1201 struct Qdisc *qdisc;
1202
1203 unsigned long tx_queue_len;
1204 spinlock_t tx_global_lock;
1205
1206#ifdef CONFIG_XPS
1207 struct xps_dev_maps __rcu *xps_maps;
1208#endif
1209
1210
1211
1212
1213
1214
1215
1216 unsigned long trans_start;
1217
1218 int watchdog_timeo;
1219 struct timer_list watchdog_timer;
1220
1221
1222 int __percpu *pcpu_refcnt;
1223
1224
1225 struct list_head todo_list;
1226
1227 struct hlist_node index_hlist;
1228
1229 struct list_head link_watch_list;
1230
1231
1232 enum { NETREG_UNINITIALIZED=0,
1233 NETREG_REGISTERED,
1234 NETREG_UNREGISTERING,
1235 NETREG_UNREGISTERED,
1236 NETREG_RELEASED,
1237 NETREG_DUMMY,
1238 } reg_state:8;
1239
1240 bool dismantle;
1241
1242 enum {
1243 RTNL_LINK_INITIALIZED,
1244 RTNL_LINK_INITIALIZING,
1245 } rtnl_link_state:16;
1246
1247
1248 void (*destructor)(struct net_device *dev);
1249
1250#ifdef CONFIG_NETPOLL
1251 struct netpoll_info *npinfo;
1252#endif
1253
1254#ifdef CONFIG_NET_NS
1255
1256 struct net *nd_net;
1257#endif
1258
1259
1260 union {
1261 void *ml_priv;
1262 struct pcpu_lstats __percpu *lstats;
1263 struct pcpu_tstats __percpu *tstats;
1264 struct pcpu_dstats __percpu *dstats;
1265 };
1266
1267 struct garp_port __rcu *garp_port;
1268
1269
1270 struct device dev;
1271
1272 const struct attribute_group *sysfs_groups[4];
1273
1274
1275 const struct rtnl_link_ops *rtnl_link_ops;
1276
1277
1278#define GSO_MAX_SIZE 65536
1279 unsigned int gso_max_size;
1280
1281#ifdef CONFIG_DCB
1282
1283 const struct dcbnl_rtnl_ops *dcbnl_ops;
1284#endif
1285 u8 num_tc;
1286 struct netdev_tc_txq tc_to_txq[TC_MAX_QUEUE];
1287 u8 prio_tc_map[TC_BITMASK + 1];
1288
1289#if IS_ENABLED(CONFIG_FCOE)
1290
1291 unsigned int fcoe_ddp_xid;
1292#endif
1293#if IS_ENABLED(CONFIG_NETPRIO_CGROUP)
1294 struct netprio_map __rcu *priomap;
1295#endif
1296
1297 struct phy_device *phydev;
1298
1299
1300 int group;
1301};
1302#define to_net_dev(d) container_of(d, struct net_device, dev)
1303
1304#define NETDEV_ALIGN 32
1305
1306static inline
1307int netdev_get_prio_tc_map(const struct net_device *dev, u32 prio)
1308{
1309 return dev->prio_tc_map[prio & TC_BITMASK];
1310}
1311
1312static inline
1313int netdev_set_prio_tc_map(struct net_device *dev, u8 prio, u8 tc)
1314{
1315 if (tc >= dev->num_tc)
1316 return -EINVAL;
1317
1318 dev->prio_tc_map[prio & TC_BITMASK] = tc & TC_BITMASK;
1319 return 0;
1320}
1321
1322static inline
1323void netdev_reset_tc(struct net_device *dev)
1324{
1325 dev->num_tc = 0;
1326 memset(dev->tc_to_txq, 0, sizeof(dev->tc_to_txq));
1327 memset(dev->prio_tc_map, 0, sizeof(dev->prio_tc_map));
1328}
1329
1330static inline
1331int netdev_set_tc_queue(struct net_device *dev, u8 tc, u16 count, u16 offset)
1332{
1333 if (tc >= dev->num_tc)
1334 return -EINVAL;
1335
1336 dev->tc_to_txq[tc].count = count;
1337 dev->tc_to_txq[tc].offset = offset;
1338 return 0;
1339}
1340
1341static inline
1342int netdev_set_num_tc(struct net_device *dev, u8 num_tc)
1343{
1344 if (num_tc > TC_MAX_QUEUE)
1345 return -EINVAL;
1346
1347 dev->num_tc = num_tc;
1348 return 0;
1349}
1350
1351static inline
1352int netdev_get_num_tc(struct net_device *dev)
1353{
1354 return dev->num_tc;
1355}
1356
1357static inline
1358struct netdev_queue *netdev_get_tx_queue(const struct net_device *dev,
1359 unsigned int index)
1360{
1361 return &dev->_tx[index];
1362}
1363
1364static inline void netdev_for_each_tx_queue(struct net_device *dev,
1365 void (*f)(struct net_device *,
1366 struct netdev_queue *,
1367 void *),
1368 void *arg)
1369{
1370 unsigned int i;
1371
1372 for (i = 0; i < dev->num_tx_queues; i++)
1373 f(dev, &dev->_tx[i], arg);
1374}
1375
1376
1377
1378
1379static inline
1380struct net *dev_net(const struct net_device *dev)
1381{
1382 return read_pnet(&dev->nd_net);
1383}
1384
1385static inline
1386void dev_net_set(struct net_device *dev, struct net *net)
1387{
1388#ifdef CONFIG_NET_NS
1389 release_net(dev->nd_net);
1390 dev->nd_net = hold_net(net);
1391#endif
1392}
1393
1394static inline bool netdev_uses_dsa_tags(struct net_device *dev)
1395{
1396#ifdef CONFIG_NET_DSA_TAG_DSA
1397 if (dev->dsa_ptr != NULL)
1398 return dsa_uses_dsa_tags(dev->dsa_ptr);
1399#endif
1400
1401 return 0;
1402}
1403
1404#ifndef CONFIG_NET_NS
1405static inline void skb_set_dev(struct sk_buff *skb, struct net_device *dev)
1406{
1407 skb->dev = dev;
1408}
1409#else
1410void skb_set_dev(struct sk_buff *skb, struct net_device *dev);
1411#endif
1412
1413static inline bool netdev_uses_trailer_tags(struct net_device *dev)
1414{
1415#ifdef CONFIG_NET_DSA_TAG_TRAILER
1416 if (dev->dsa_ptr != NULL)
1417 return dsa_uses_trailer_tags(dev->dsa_ptr);
1418#endif
1419
1420 return 0;
1421}
1422
1423
1424
1425
1426
1427
1428
1429static inline void *netdev_priv(const struct net_device *dev)
1430{
1431 return (char *)dev + ALIGN(sizeof(struct net_device), NETDEV_ALIGN);
1432}
1433
1434
1435
1436
1437#define SET_NETDEV_DEV(net, pdev) ((net)->dev.parent = (pdev))
1438
1439
1440
1441
1442
1443#define SET_NETDEV_DEVTYPE(net, devtype) ((net)->dev.type = (devtype))
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455void netif_napi_add(struct net_device *dev, struct napi_struct *napi,
1456 int (*poll)(struct napi_struct *, int), int weight);
1457
1458
1459
1460
1461
1462
1463
1464void netif_napi_del(struct napi_struct *napi);
1465
1466struct napi_gro_cb {
1467
1468 void *frag0;
1469
1470
1471 unsigned int frag0_len;
1472
1473
1474 int data_offset;
1475
1476
1477 int same_flow;
1478
1479
1480 int flush;
1481
1482
1483 int count;
1484
1485
1486 int free;
1487};
1488
1489#define NAPI_GRO_CB(skb) ((struct napi_gro_cb *)(skb)->cb)
1490
1491struct packet_type {
1492 __be16 type;
1493 struct net_device *dev;
1494 int (*func) (struct sk_buff *,
1495 struct net_device *,
1496 struct packet_type *,
1497 struct net_device *);
1498 struct sk_buff *(*gso_segment)(struct sk_buff *skb,
1499 netdev_features_t features);
1500 int (*gso_send_check)(struct sk_buff *skb);
1501 struct sk_buff **(*gro_receive)(struct sk_buff **head,
1502 struct sk_buff *skb);
1503 int (*gro_complete)(struct sk_buff *skb);
1504 void *af_packet_priv;
1505 struct list_head list;
1506};
1507
1508#include <linux/notifier.h>
1509
1510
1511
1512
1513
1514#define NETDEV_UP 0x0001
1515#define NETDEV_DOWN 0x0002
1516#define NETDEV_REBOOT 0x0003
1517
1518
1519
1520#define NETDEV_CHANGE 0x0004
1521#define NETDEV_REGISTER 0x0005
1522#define NETDEV_UNREGISTER 0x0006
1523#define NETDEV_CHANGEMTU 0x0007
1524#define NETDEV_CHANGEADDR 0x0008
1525#define NETDEV_GOING_DOWN 0x0009
1526#define NETDEV_CHANGENAME 0x000A
1527#define NETDEV_FEAT_CHANGE 0x000B
1528#define NETDEV_BONDING_FAILOVER 0x000C
1529#define NETDEV_PRE_UP 0x000D
1530#define NETDEV_PRE_TYPE_CHANGE 0x000E
1531#define NETDEV_POST_TYPE_CHANGE 0x000F
1532#define NETDEV_POST_INIT 0x0010
1533#define NETDEV_UNREGISTER_BATCH 0x0011
1534#define NETDEV_RELEASE 0x0012
1535#define NETDEV_NOTIFY_PEERS 0x0013
1536#define NETDEV_JOIN 0x0014
1537
1538extern int register_netdevice_notifier(struct notifier_block *nb);
1539extern int unregister_netdevice_notifier(struct notifier_block *nb);
1540extern int call_netdevice_notifiers(unsigned long val, struct net_device *dev);
1541
1542
1543extern rwlock_t dev_base_lock;
1544
1545
1546#define for_each_netdev(net, d) \
1547 list_for_each_entry(d, &(net)->dev_base_head, dev_list)
1548#define for_each_netdev_reverse(net, d) \
1549 list_for_each_entry_reverse(d, &(net)->dev_base_head, dev_list)
1550#define for_each_netdev_rcu(net, d) \
1551 list_for_each_entry_rcu(d, &(net)->dev_base_head, dev_list)
1552#define for_each_netdev_safe(net, d, n) \
1553 list_for_each_entry_safe(d, n, &(net)->dev_base_head, dev_list)
1554#define for_each_netdev_continue(net, d) \
1555 list_for_each_entry_continue(d, &(net)->dev_base_head, dev_list)
1556#define for_each_netdev_continue_rcu(net, d) \
1557 list_for_each_entry_continue_rcu(d, &(net)->dev_base_head, dev_list)
1558#define net_device_entry(lh) list_entry(lh, struct net_device, dev_list)
1559
1560static inline struct net_device *next_net_device(struct net_device *dev)
1561{
1562 struct list_head *lh;
1563 struct net *net;
1564
1565 net = dev_net(dev);
1566 lh = dev->dev_list.next;
1567 return lh == &net->dev_base_head ? NULL : net_device_entry(lh);
1568}
1569
1570static inline struct net_device *next_net_device_rcu(struct net_device *dev)
1571{
1572 struct list_head *lh;
1573 struct net *net;
1574
1575 net = dev_net(dev);
1576 lh = rcu_dereference(list_next_rcu(&dev->dev_list));
1577 return lh == &net->dev_base_head ? NULL : net_device_entry(lh);
1578}
1579
1580static inline struct net_device *first_net_device(struct net *net)
1581{
1582 return list_empty(&net->dev_base_head) ? NULL :
1583 net_device_entry(net->dev_base_head.next);
1584}
1585
1586static inline struct net_device *first_net_device_rcu(struct net *net)
1587{
1588 struct list_head *lh = rcu_dereference(list_next_rcu(&net->dev_base_head));
1589
1590 return lh == &net->dev_base_head ? NULL : net_device_entry(lh);
1591}
1592
1593extern int netdev_boot_setup_check(struct net_device *dev);
1594extern unsigned long netdev_boot_base(const char *prefix, int unit);
1595extern struct net_device *dev_getbyhwaddr_rcu(struct net *net, unsigned short type,
1596 const char *hwaddr);
1597extern struct net_device *dev_getfirstbyhwtype(struct net *net, unsigned short type);
1598extern struct net_device *__dev_getfirstbyhwtype(struct net *net, unsigned short type);
1599extern void dev_add_pack(struct packet_type *pt);
1600extern void dev_remove_pack(struct packet_type *pt);
1601extern void __dev_remove_pack(struct packet_type *pt);
1602
1603extern struct net_device *dev_get_by_flags_rcu(struct net *net, unsigned short flags,
1604 unsigned short mask);
1605extern struct net_device *dev_get_by_name(struct net *net, const char *name);
1606extern struct net_device *dev_get_by_name_rcu(struct net *net, const char *name);
1607extern struct net_device *__dev_get_by_name(struct net *net, const char *name);
1608extern int dev_alloc_name(struct net_device *dev, const char *name);
1609extern int dev_open(struct net_device *dev);
1610extern int dev_close(struct net_device *dev);
1611extern void dev_disable_lro(struct net_device *dev);
1612extern int dev_queue_xmit(struct sk_buff *skb);
1613extern int register_netdevice(struct net_device *dev);
1614extern void unregister_netdevice_queue(struct net_device *dev,
1615 struct list_head *head);
1616extern void unregister_netdevice_many(struct list_head *head);
1617static inline void unregister_netdevice(struct net_device *dev)
1618{
1619 unregister_netdevice_queue(dev, NULL);
1620}
1621
1622extern int netdev_refcnt_read(const struct net_device *dev);
1623extern void free_netdev(struct net_device *dev);
1624extern void synchronize_net(void);
1625extern int init_dummy_netdev(struct net_device *dev);
1626extern void netdev_resync_ops(struct net_device *dev);
1627
1628extern struct net_device *dev_get_by_index(struct net *net, int ifindex);
1629extern struct net_device *__dev_get_by_index(struct net *net, int ifindex);
1630extern struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex);
1631extern int dev_restart(struct net_device *dev);
1632#ifdef CONFIG_NETPOLL_TRAP
1633extern int netpoll_trap(void);
1634#endif
1635extern int skb_gro_receive(struct sk_buff **head,
1636 struct sk_buff *skb);
1637extern void skb_gro_reset_offset(struct sk_buff *skb);
1638
1639static inline unsigned int skb_gro_offset(const struct sk_buff *skb)
1640{
1641 return NAPI_GRO_CB(skb)->data_offset;
1642}
1643
1644static inline unsigned int skb_gro_len(const struct sk_buff *skb)
1645{
1646 return skb->len - NAPI_GRO_CB(skb)->data_offset;
1647}
1648
1649static inline void skb_gro_pull(struct sk_buff *skb, unsigned int len)
1650{
1651 NAPI_GRO_CB(skb)->data_offset += len;
1652}
1653
1654static inline void *skb_gro_header_fast(struct sk_buff *skb,
1655 unsigned int offset)
1656{
1657 return NAPI_GRO_CB(skb)->frag0 + offset;
1658}
1659
1660static inline int skb_gro_header_hard(struct sk_buff *skb, unsigned int hlen)
1661{
1662 return NAPI_GRO_CB(skb)->frag0_len < hlen;
1663}
1664
1665static inline void *skb_gro_header_slow(struct sk_buff *skb, unsigned int hlen,
1666 unsigned int offset)
1667{
1668 if (!pskb_may_pull(skb, hlen))
1669 return NULL;
1670
1671 NAPI_GRO_CB(skb)->frag0 = NULL;
1672 NAPI_GRO_CB(skb)->frag0_len = 0;
1673 return skb->data + offset;
1674}
1675
1676static inline void *skb_gro_mac_header(struct sk_buff *skb)
1677{
1678 return NAPI_GRO_CB(skb)->frag0 ?: skb_mac_header(skb);
1679}
1680
1681static inline void *skb_gro_network_header(struct sk_buff *skb)
1682{
1683 return (NAPI_GRO_CB(skb)->frag0 ?: skb->data) +
1684 skb_network_offset(skb);
1685}
1686
1687static inline int dev_hard_header(struct sk_buff *skb, struct net_device *dev,
1688 unsigned short type,
1689 const void *daddr, const void *saddr,
1690 unsigned len)
1691{
1692 if (!dev->header_ops || !dev->header_ops->create)
1693 return 0;
1694
1695 return dev->header_ops->create(skb, dev, type, daddr, saddr, len);
1696}
1697
1698static inline int dev_parse_header(const struct sk_buff *skb,
1699 unsigned char *haddr)
1700{
1701 const struct net_device *dev = skb->dev;
1702
1703 if (!dev->header_ops || !dev->header_ops->parse)
1704 return 0;
1705 return dev->header_ops->parse(skb, haddr);
1706}
1707
1708typedef int gifconf_func_t(struct net_device * dev, char __user * bufptr, int len);
1709extern int register_gifconf(unsigned int family, gifconf_func_t * gifconf);
1710static inline int unregister_gifconf(unsigned int family)
1711{
1712 return register_gifconf(family, NULL);
1713}
1714
1715
1716
1717
1718struct softnet_data {
1719 struct Qdisc *output_queue;
1720 struct Qdisc **output_queue_tailp;
1721 struct list_head poll_list;
1722 struct sk_buff *completion_queue;
1723 struct sk_buff_head process_queue;
1724
1725
1726 unsigned int processed;
1727 unsigned int time_squeeze;
1728 unsigned int cpu_collision;
1729 unsigned int received_rps;
1730
1731#ifdef CONFIG_RPS
1732 struct softnet_data *rps_ipi_list;
1733
1734
1735 struct call_single_data csd ____cacheline_aligned_in_smp;
1736 struct softnet_data *rps_ipi_next;
1737 unsigned int cpu;
1738 unsigned int input_queue_head;
1739 unsigned int input_queue_tail;
1740#endif
1741 unsigned dropped;
1742 struct sk_buff_head input_pkt_queue;
1743 struct napi_struct backlog;
1744};
1745
1746static inline void input_queue_head_incr(struct softnet_data *sd)
1747{
1748#ifdef CONFIG_RPS
1749 sd->input_queue_head++;
1750#endif
1751}
1752
1753static inline void input_queue_tail_incr_save(struct softnet_data *sd,
1754 unsigned int *qtail)
1755{
1756#ifdef CONFIG_RPS
1757 *qtail = ++sd->input_queue_tail;
1758#endif
1759}
1760
1761DECLARE_PER_CPU_ALIGNED(struct softnet_data, softnet_data);
1762
1763extern void __netif_schedule(struct Qdisc *q);
1764
1765static inline void netif_schedule_queue(struct netdev_queue *txq)
1766{
1767 if (!(txq->state & QUEUE_STATE_ANY_XOFF))
1768 __netif_schedule(txq->qdisc);
1769}
1770
1771static inline void netif_tx_schedule_all(struct net_device *dev)
1772{
1773 unsigned int i;
1774
1775 for (i = 0; i < dev->num_tx_queues; i++)
1776 netif_schedule_queue(netdev_get_tx_queue(dev, i));
1777}
1778
1779static inline void netif_tx_start_queue(struct netdev_queue *dev_queue)
1780{
1781 clear_bit(__QUEUE_STATE_DRV_XOFF, &dev_queue->state);
1782}
1783
1784
1785
1786
1787
1788
1789
1790static inline void netif_start_queue(struct net_device *dev)
1791{
1792 netif_tx_start_queue(netdev_get_tx_queue(dev, 0));
1793}
1794
1795static inline void netif_tx_start_all_queues(struct net_device *dev)
1796{
1797 unsigned int i;
1798
1799 for (i = 0; i < dev->num_tx_queues; i++) {
1800 struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
1801 netif_tx_start_queue(txq);
1802 }
1803}
1804
1805static inline void netif_tx_wake_queue(struct netdev_queue *dev_queue)
1806{
1807#ifdef CONFIG_NETPOLL_TRAP
1808 if (netpoll_trap()) {
1809 netif_tx_start_queue(dev_queue);
1810 return;
1811 }
1812#endif
1813 if (test_and_clear_bit(__QUEUE_STATE_DRV_XOFF, &dev_queue->state))
1814 __netif_schedule(dev_queue->qdisc);
1815}
1816
1817
1818
1819
1820
1821
1822
1823
1824static inline void netif_wake_queue(struct net_device *dev)
1825{
1826 netif_tx_wake_queue(netdev_get_tx_queue(dev, 0));
1827}
1828
1829static inline void netif_tx_wake_all_queues(struct net_device *dev)
1830{
1831 unsigned int i;
1832
1833 for (i = 0; i < dev->num_tx_queues; i++) {
1834 struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
1835 netif_tx_wake_queue(txq);
1836 }
1837}
1838
1839static inline void netif_tx_stop_queue(struct netdev_queue *dev_queue)
1840{
1841 if (WARN_ON(!dev_queue)) {
1842 pr_info("netif_stop_queue() cannot be called before register_netdev()\n");
1843 return;
1844 }
1845 set_bit(__QUEUE_STATE_DRV_XOFF, &dev_queue->state);
1846}
1847
1848
1849
1850
1851
1852
1853
1854
1855static inline void netif_stop_queue(struct net_device *dev)
1856{
1857 netif_tx_stop_queue(netdev_get_tx_queue(dev, 0));
1858}
1859
1860static inline void netif_tx_stop_all_queues(struct net_device *dev)
1861{
1862 unsigned int i;
1863
1864 for (i = 0; i < dev->num_tx_queues; i++) {
1865 struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
1866 netif_tx_stop_queue(txq);
1867 }
1868}
1869
1870static inline int netif_tx_queue_stopped(const struct netdev_queue *dev_queue)
1871{
1872 return test_bit(__QUEUE_STATE_DRV_XOFF, &dev_queue->state);
1873}
1874
1875
1876
1877
1878
1879
1880
1881static inline int netif_queue_stopped(const struct net_device *dev)
1882{
1883 return netif_tx_queue_stopped(netdev_get_tx_queue(dev, 0));
1884}
1885
1886static inline int netif_xmit_stopped(const struct netdev_queue *dev_queue)
1887{
1888 return dev_queue->state & QUEUE_STATE_ANY_XOFF;
1889}
1890
1891static inline int netif_xmit_frozen_or_stopped(const struct netdev_queue *dev_queue)
1892{
1893 return dev_queue->state & QUEUE_STATE_ANY_XOFF_OR_FROZEN;
1894}
1895
1896static inline void netdev_tx_sent_queue(struct netdev_queue *dev_queue,
1897 unsigned int bytes)
1898{
1899#ifdef CONFIG_BQL
1900 dql_queued(&dev_queue->dql, bytes);
1901 if (unlikely(dql_avail(&dev_queue->dql) < 0)) {
1902 set_bit(__QUEUE_STATE_STACK_XOFF, &dev_queue->state);
1903 if (unlikely(dql_avail(&dev_queue->dql) >= 0))
1904 clear_bit(__QUEUE_STATE_STACK_XOFF,
1905 &dev_queue->state);
1906 }
1907#endif
1908}
1909
1910static inline void netdev_sent_queue(struct net_device *dev, unsigned int bytes)
1911{
1912 netdev_tx_sent_queue(netdev_get_tx_queue(dev, 0), bytes);
1913}
1914
1915static inline void netdev_tx_completed_queue(struct netdev_queue *dev_queue,
1916 unsigned pkts, unsigned bytes)
1917{
1918#ifdef CONFIG_BQL
1919 if (likely(bytes)) {
1920 dql_completed(&dev_queue->dql, bytes);
1921 if (unlikely(test_bit(__QUEUE_STATE_STACK_XOFF,
1922 &dev_queue->state) &&
1923 dql_avail(&dev_queue->dql) >= 0)) {
1924 if (test_and_clear_bit(__QUEUE_STATE_STACK_XOFF,
1925 &dev_queue->state))
1926 netif_schedule_queue(dev_queue);
1927 }
1928 }
1929#endif
1930}
1931
1932static inline void netdev_completed_queue(struct net_device *dev,
1933 unsigned pkts, unsigned bytes)
1934{
1935 netdev_tx_completed_queue(netdev_get_tx_queue(dev, 0), pkts, bytes);
1936}
1937
1938static inline void netdev_tx_reset_queue(struct netdev_queue *q)
1939{
1940#ifdef CONFIG_BQL
1941 dql_reset(&q->dql);
1942#endif
1943}
1944
1945static inline void netdev_reset_queue(struct net_device *dev_queue)
1946{
1947 netdev_tx_reset_queue(netdev_get_tx_queue(dev_queue, 0));
1948}
1949
1950
1951
1952
1953
1954
1955
1956static inline int netif_running(const struct net_device *dev)
1957{
1958 return test_bit(__LINK_STATE_START, &dev->state);
1959}
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975static inline void netif_start_subqueue(struct net_device *dev, u16 queue_index)
1976{
1977 struct netdev_queue *txq = netdev_get_tx_queue(dev, queue_index);
1978
1979 netif_tx_start_queue(txq);
1980}
1981
1982
1983
1984
1985
1986
1987
1988
1989static inline void netif_stop_subqueue(struct net_device *dev, u16 queue_index)
1990{
1991 struct netdev_queue *txq = netdev_get_tx_queue(dev, queue_index);
1992#ifdef CONFIG_NETPOLL_TRAP
1993 if (netpoll_trap())
1994 return;
1995#endif
1996 netif_tx_stop_queue(txq);
1997}
1998
1999
2000
2001
2002
2003
2004
2005
2006static inline int __netif_subqueue_stopped(const struct net_device *dev,
2007 u16 queue_index)
2008{
2009 struct netdev_queue *txq = netdev_get_tx_queue(dev, queue_index);
2010
2011 return netif_tx_queue_stopped(txq);
2012}
2013
2014static inline int netif_subqueue_stopped(const struct net_device *dev,
2015 struct sk_buff *skb)
2016{
2017 return __netif_subqueue_stopped(dev, skb_get_queue_mapping(skb));
2018}
2019
2020
2021
2022
2023
2024
2025
2026
2027static inline void netif_wake_subqueue(struct net_device *dev, u16 queue_index)
2028{
2029 struct netdev_queue *txq = netdev_get_tx_queue(dev, queue_index);
2030#ifdef CONFIG_NETPOLL_TRAP
2031 if (netpoll_trap())
2032 return;
2033#endif
2034 if (test_and_clear_bit(__QUEUE_STATE_DRV_XOFF, &txq->state))
2035 __netif_schedule(txq->qdisc);
2036}
2037
2038
2039
2040
2041
2042static inline u16 skb_tx_hash(const struct net_device *dev,
2043 const struct sk_buff *skb)
2044{
2045 return __skb_tx_hash(dev, skb, dev->real_num_tx_queues);
2046}
2047
2048
2049
2050
2051
2052
2053
2054static inline int netif_is_multiqueue(const struct net_device *dev)
2055{
2056 return dev->num_tx_queues > 1;
2057}
2058
2059extern int netif_set_real_num_tx_queues(struct net_device *dev,
2060 unsigned int txq);
2061
2062#ifdef CONFIG_RPS
2063extern int netif_set_real_num_rx_queues(struct net_device *dev,
2064 unsigned int rxq);
2065#else
2066static inline int netif_set_real_num_rx_queues(struct net_device *dev,
2067 unsigned int rxq)
2068{
2069 return 0;
2070}
2071#endif
2072
2073static inline int netif_copy_real_num_queues(struct net_device *to_dev,
2074 const struct net_device *from_dev)
2075{
2076 netif_set_real_num_tx_queues(to_dev, from_dev->real_num_tx_queues);
2077#ifdef CONFIG_RPS
2078 return netif_set_real_num_rx_queues(to_dev,
2079 from_dev->real_num_rx_queues);
2080#else
2081 return 0;
2082#endif
2083}
2084
2085
2086
2087
2088
2089extern void dev_kfree_skb_irq(struct sk_buff *skb);
2090
2091
2092
2093
2094
2095extern void dev_kfree_skb_any(struct sk_buff *skb);
2096
2097extern int netif_rx(struct sk_buff *skb);
2098extern int netif_rx_ni(struct sk_buff *skb);
2099extern int netif_receive_skb(struct sk_buff *skb);
2100extern gro_result_t dev_gro_receive(struct napi_struct *napi,
2101 struct sk_buff *skb);
2102extern gro_result_t napi_skb_finish(gro_result_t ret, struct sk_buff *skb);
2103extern gro_result_t napi_gro_receive(struct napi_struct *napi,
2104 struct sk_buff *skb);
2105extern void napi_gro_flush(struct napi_struct *napi);
2106extern struct sk_buff * napi_get_frags(struct napi_struct *napi);
2107extern gro_result_t napi_frags_finish(struct napi_struct *napi,
2108 struct sk_buff *skb,
2109 gro_result_t ret);
2110extern struct sk_buff * napi_frags_skb(struct napi_struct *napi);
2111extern gro_result_t napi_gro_frags(struct napi_struct *napi);
2112
2113static inline void napi_free_frags(struct napi_struct *napi)
2114{
2115 kfree_skb(napi->skb);
2116 napi->skb = NULL;
2117}
2118
2119extern int netdev_rx_handler_register(struct net_device *dev,
2120 rx_handler_func_t *rx_handler,
2121 void *rx_handler_data);
2122extern void netdev_rx_handler_unregister(struct net_device *dev);
2123
2124extern int dev_valid_name(const char *name);
2125extern int dev_ioctl(struct net *net, unsigned int cmd, void __user *);
2126extern int dev_ethtool(struct net *net, struct ifreq *);
2127extern unsigned dev_get_flags(const struct net_device *);
2128extern int __dev_change_flags(struct net_device *, unsigned int flags);
2129extern int dev_change_flags(struct net_device *, unsigned);
2130extern void __dev_notify_flags(struct net_device *, unsigned int old_flags);
2131extern int dev_change_name(struct net_device *, const char *);
2132extern int dev_set_alias(struct net_device *, const char *, size_t);
2133extern int dev_change_net_namespace(struct net_device *,
2134 struct net *, const char *);
2135extern int dev_set_mtu(struct net_device *, int);
2136extern void dev_set_group(struct net_device *, int);
2137extern int dev_set_mac_address(struct net_device *,
2138 struct sockaddr *);
2139extern int dev_hard_start_xmit(struct sk_buff *skb,
2140 struct net_device *dev,
2141 struct netdev_queue *txq);
2142extern int dev_forward_skb(struct net_device *dev,
2143 struct sk_buff *skb);
2144
2145extern int netdev_budget;
2146
2147
2148extern void netdev_run_todo(void);
2149
2150
2151
2152
2153
2154
2155
2156static inline void dev_put(struct net_device *dev)
2157{
2158 this_cpu_dec(*dev->pcpu_refcnt);
2159}
2160
2161
2162
2163
2164
2165
2166
2167static inline void dev_hold(struct net_device *dev)
2168{
2169 this_cpu_inc(*dev->pcpu_refcnt);
2170}
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181extern void linkwatch_fire_event(struct net_device *dev);
2182extern void linkwatch_forget_dev(struct net_device *dev);
2183
2184
2185
2186
2187
2188
2189
2190static inline int netif_carrier_ok(const struct net_device *dev)
2191{
2192 return !test_bit(__LINK_STATE_NOCARRIER, &dev->state);
2193}
2194
2195extern unsigned long dev_trans_start(struct net_device *dev);
2196
2197extern void __netdev_watchdog_up(struct net_device *dev);
2198
2199extern void netif_carrier_on(struct net_device *dev);
2200
2201extern void netif_carrier_off(struct net_device *dev);
2202
2203extern void netif_notify_peers(struct net_device *dev);
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218static inline void netif_dormant_on(struct net_device *dev)
2219{
2220 if (!test_and_set_bit(__LINK_STATE_DORMANT, &dev->state))
2221 linkwatch_fire_event(dev);
2222}
2223
2224
2225
2226
2227
2228
2229
2230static inline void netif_dormant_off(struct net_device *dev)
2231{
2232 if (test_and_clear_bit(__LINK_STATE_DORMANT, &dev->state))
2233 linkwatch_fire_event(dev);
2234}
2235
2236
2237
2238
2239
2240
2241
2242static inline int netif_dormant(const struct net_device *dev)
2243{
2244 return test_bit(__LINK_STATE_DORMANT, &dev->state);
2245}
2246
2247
2248
2249
2250
2251
2252
2253
2254static inline int netif_oper_up(const struct net_device *dev)
2255{
2256 return (dev->operstate == IF_OPER_UP ||
2257 dev->operstate == IF_OPER_UNKNOWN );
2258}
2259
2260
2261
2262
2263
2264
2265
2266static inline int netif_device_present(struct net_device *dev)
2267{
2268 return test_bit(__LINK_STATE_PRESENT, &dev->state);
2269}
2270
2271extern void netif_device_detach(struct net_device *dev);
2272
2273extern void netif_device_attach(struct net_device *dev);
2274
2275
2276
2277
2278
2279enum {
2280 NETIF_MSG_DRV = 0x0001,
2281 NETIF_MSG_PROBE = 0x0002,
2282 NETIF_MSG_LINK = 0x0004,
2283 NETIF_MSG_TIMER = 0x0008,
2284 NETIF_MSG_IFDOWN = 0x0010,
2285 NETIF_MSG_IFUP = 0x0020,
2286 NETIF_MSG_RX_ERR = 0x0040,
2287 NETIF_MSG_TX_ERR = 0x0080,
2288 NETIF_MSG_TX_QUEUED = 0x0100,
2289 NETIF_MSG_INTR = 0x0200,
2290 NETIF_MSG_TX_DONE = 0x0400,
2291 NETIF_MSG_RX_STATUS = 0x0800,
2292 NETIF_MSG_PKTDATA = 0x1000,
2293 NETIF_MSG_HW = 0x2000,
2294 NETIF_MSG_WOL = 0x4000,
2295};
2296
2297#define netif_msg_drv(p) ((p)->msg_enable & NETIF_MSG_DRV)
2298#define netif_msg_probe(p) ((p)->msg_enable & NETIF_MSG_PROBE)
2299#define netif_msg_link(p) ((p)->msg_enable & NETIF_MSG_LINK)
2300#define netif_msg_timer(p) ((p)->msg_enable & NETIF_MSG_TIMER)
2301#define netif_msg_ifdown(p) ((p)->msg_enable & NETIF_MSG_IFDOWN)
2302#define netif_msg_ifup(p) ((p)->msg_enable & NETIF_MSG_IFUP)
2303#define netif_msg_rx_err(p) ((p)->msg_enable & NETIF_MSG_RX_ERR)
2304#define netif_msg_tx_err(p) ((p)->msg_enable & NETIF_MSG_TX_ERR)
2305#define netif_msg_tx_queued(p) ((p)->msg_enable & NETIF_MSG_TX_QUEUED)
2306#define netif_msg_intr(p) ((p)->msg_enable & NETIF_MSG_INTR)
2307#define netif_msg_tx_done(p) ((p)->msg_enable & NETIF_MSG_TX_DONE)
2308#define netif_msg_rx_status(p) ((p)->msg_enable & NETIF_MSG_RX_STATUS)
2309#define netif_msg_pktdata(p) ((p)->msg_enable & NETIF_MSG_PKTDATA)
2310#define netif_msg_hw(p) ((p)->msg_enable & NETIF_MSG_HW)
2311#define netif_msg_wol(p) ((p)->msg_enable & NETIF_MSG_WOL)
2312
2313static inline u32 netif_msg_init(int debug_value, int default_msg_enable_bits)
2314{
2315
2316 if (debug_value < 0 || debug_value >= (sizeof(u32) * 8))
2317 return default_msg_enable_bits;
2318 if (debug_value == 0)
2319 return 0;
2320
2321 return (1 << debug_value) - 1;
2322}
2323
2324static inline void __netif_tx_lock(struct netdev_queue *txq, int cpu)
2325{
2326 spin_lock(&txq->_xmit_lock);
2327 txq->xmit_lock_owner = cpu;
2328}
2329
2330static inline void __netif_tx_lock_bh(struct netdev_queue *txq)
2331{
2332 spin_lock_bh(&txq->_xmit_lock);
2333 txq->xmit_lock_owner = smp_processor_id();
2334}
2335
2336static inline int __netif_tx_trylock(struct netdev_queue *txq)
2337{
2338 int ok = spin_trylock(&txq->_xmit_lock);
2339 if (likely(ok))
2340 txq->xmit_lock_owner = smp_processor_id();
2341 return ok;
2342}
2343
2344static inline void __netif_tx_unlock(struct netdev_queue *txq)
2345{
2346 txq->xmit_lock_owner = -1;
2347 spin_unlock(&txq->_xmit_lock);
2348}
2349
2350static inline void __netif_tx_unlock_bh(struct netdev_queue *txq)
2351{
2352 txq->xmit_lock_owner = -1;
2353 spin_unlock_bh(&txq->_xmit_lock);
2354}
2355
2356static inline void txq_trans_update(struct netdev_queue *txq)
2357{
2358 if (txq->xmit_lock_owner != -1)
2359 txq->trans_start = jiffies;
2360}
2361
2362
2363
2364
2365
2366
2367
2368static inline void netif_tx_lock(struct net_device *dev)
2369{
2370 unsigned int i;
2371 int cpu;
2372
2373 spin_lock(&dev->tx_global_lock);
2374 cpu = smp_processor_id();
2375 for (i = 0; i < dev->num_tx_queues; i++) {
2376 struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
2377
2378
2379
2380
2381
2382
2383
2384 __netif_tx_lock(txq, cpu);
2385 set_bit(__QUEUE_STATE_FROZEN, &txq->state);
2386 __netif_tx_unlock(txq);
2387 }
2388}
2389
2390static inline void netif_tx_lock_bh(struct net_device *dev)
2391{
2392 local_bh_disable();
2393 netif_tx_lock(dev);
2394}
2395
2396static inline void netif_tx_unlock(struct net_device *dev)
2397{
2398 unsigned int i;
2399
2400 for (i = 0; i < dev->num_tx_queues; i++) {
2401 struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
2402
2403
2404
2405
2406
2407 clear_bit(__QUEUE_STATE_FROZEN, &txq->state);
2408 netif_schedule_queue(txq);
2409 }
2410 spin_unlock(&dev->tx_global_lock);
2411}
2412
2413static inline void netif_tx_unlock_bh(struct net_device *dev)
2414{
2415 netif_tx_unlock(dev);
2416 local_bh_enable();
2417}
2418
2419#define HARD_TX_LOCK(dev, txq, cpu) { \
2420 if ((dev->features & NETIF_F_LLTX) == 0) { \
2421 __netif_tx_lock(txq, cpu); \
2422 } \
2423}
2424
2425#define HARD_TX_UNLOCK(dev, txq) { \
2426 if ((dev->features & NETIF_F_LLTX) == 0) { \
2427 __netif_tx_unlock(txq); \
2428 } \
2429}
2430
2431static inline void netif_tx_disable(struct net_device *dev)
2432{
2433 unsigned int i;
2434 int cpu;
2435
2436 local_bh_disable();
2437 cpu = smp_processor_id();
2438 for (i = 0; i < dev->num_tx_queues; i++) {
2439 struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
2440
2441 __netif_tx_lock(txq, cpu);
2442 netif_tx_stop_queue(txq);
2443 __netif_tx_unlock(txq);
2444 }
2445 local_bh_enable();
2446}
2447
2448static inline void netif_addr_lock(struct net_device *dev)
2449{
2450 spin_lock(&dev->addr_list_lock);
2451}
2452
2453static inline void netif_addr_lock_nested(struct net_device *dev)
2454{
2455 spin_lock_nested(&dev->addr_list_lock, SINGLE_DEPTH_NESTING);
2456}
2457
2458static inline void netif_addr_lock_bh(struct net_device *dev)
2459{
2460 spin_lock_bh(&dev->addr_list_lock);
2461}
2462
2463static inline void netif_addr_unlock(struct net_device *dev)
2464{
2465 spin_unlock(&dev->addr_list_lock);
2466}
2467
2468static inline void netif_addr_unlock_bh(struct net_device *dev)
2469{
2470 spin_unlock_bh(&dev->addr_list_lock);
2471}
2472
2473
2474
2475
2476
2477#define for_each_dev_addr(dev, ha) \
2478 list_for_each_entry_rcu(ha, &dev->dev_addrs.list, list)
2479
2480
2481
2482extern void ether_setup(struct net_device *dev);
2483
2484
2485extern struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name,
2486 void (*setup)(struct net_device *),
2487 unsigned int txqs, unsigned int rxqs);
2488#define alloc_netdev(sizeof_priv, name, setup) \
2489 alloc_netdev_mqs(sizeof_priv, name, setup, 1, 1)
2490
2491#define alloc_netdev_mq(sizeof_priv, name, setup, count) \
2492 alloc_netdev_mqs(sizeof_priv, name, setup, count, count)
2493
2494extern int register_netdev(struct net_device *dev);
2495extern void unregister_netdev(struct net_device *dev);
2496
2497
2498extern int __hw_addr_add_multiple(struct netdev_hw_addr_list *to_list,
2499 struct netdev_hw_addr_list *from_list,
2500 int addr_len, unsigned char addr_type);
2501extern void __hw_addr_del_multiple(struct netdev_hw_addr_list *to_list,
2502 struct netdev_hw_addr_list *from_list,
2503 int addr_len, unsigned char addr_type);
2504extern int __hw_addr_sync(struct netdev_hw_addr_list *to_list,
2505 struct netdev_hw_addr_list *from_list,
2506 int addr_len);
2507extern void __hw_addr_unsync(struct netdev_hw_addr_list *to_list,
2508 struct netdev_hw_addr_list *from_list,
2509 int addr_len);
2510extern void __hw_addr_flush(struct netdev_hw_addr_list *list);
2511extern void __hw_addr_init(struct netdev_hw_addr_list *list);
2512
2513
2514extern int dev_addr_add(struct net_device *dev, unsigned char *addr,
2515 unsigned char addr_type);
2516extern int dev_addr_del(struct net_device *dev, unsigned char *addr,
2517 unsigned char addr_type);
2518extern int dev_addr_add_multiple(struct net_device *to_dev,
2519 struct net_device *from_dev,
2520 unsigned char addr_type);
2521extern int dev_addr_del_multiple(struct net_device *to_dev,
2522 struct net_device *from_dev,
2523 unsigned char addr_type);
2524extern void dev_addr_flush(struct net_device *dev);
2525extern int dev_addr_init(struct net_device *dev);
2526
2527
2528extern int dev_uc_add(struct net_device *dev, unsigned char *addr);
2529extern int dev_uc_del(struct net_device *dev, unsigned char *addr);
2530extern int dev_uc_sync(struct net_device *to, struct net_device *from);
2531extern void dev_uc_unsync(struct net_device *to, struct net_device *from);
2532extern void dev_uc_flush(struct net_device *dev);
2533extern void dev_uc_init(struct net_device *dev);
2534
2535
2536extern int dev_mc_add(struct net_device *dev, unsigned char *addr);
2537extern int dev_mc_add_global(struct net_device *dev, unsigned char *addr);
2538extern int dev_mc_del(struct net_device *dev, unsigned char *addr);
2539extern int dev_mc_del_global(struct net_device *dev, unsigned char *addr);
2540extern int dev_mc_sync(struct net_device *to, struct net_device *from);
2541extern void dev_mc_unsync(struct net_device *to, struct net_device *from);
2542extern void dev_mc_flush(struct net_device *dev);
2543extern void dev_mc_init(struct net_device *dev);
2544
2545
2546extern void dev_set_rx_mode(struct net_device *dev);
2547extern void __dev_set_rx_mode(struct net_device *dev);
2548extern int dev_set_promiscuity(struct net_device *dev, int inc);
2549extern int dev_set_allmulti(struct net_device *dev, int inc);
2550extern void netdev_state_change(struct net_device *dev);
2551extern int netdev_bonding_change(struct net_device *dev,
2552 unsigned long event);
2553extern void netdev_features_change(struct net_device *dev);
2554
2555extern void dev_load(struct net *net, const char *name);
2556extern void dev_mcast_init(void);
2557extern struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
2558 struct rtnl_link_stats64 *storage);
2559
2560extern int netdev_max_backlog;
2561extern int netdev_tstamp_prequeue;
2562extern int weight_p;
2563extern int bpf_jit_enable;
2564extern int netdev_set_master(struct net_device *dev, struct net_device *master);
2565extern int netdev_set_bond_master(struct net_device *dev,
2566 struct net_device *master);
2567extern int skb_checksum_help(struct sk_buff *skb);
2568extern struct sk_buff *skb_gso_segment(struct sk_buff *skb,
2569 netdev_features_t features);
2570#ifdef CONFIG_BUG
2571extern void netdev_rx_csum_fault(struct net_device *dev);
2572#else
2573static inline void netdev_rx_csum_fault(struct net_device *dev)
2574{
2575}
2576#endif
2577
2578extern void net_enable_timestamp(void);
2579extern void net_disable_timestamp(void);
2580
2581#ifdef CONFIG_PROC_FS
2582extern void *dev_seq_start(struct seq_file *seq, loff_t *pos);
2583extern void *dev_seq_next(struct seq_file *seq, void *v, loff_t *pos);
2584extern void dev_seq_stop(struct seq_file *seq, void *v);
2585extern int dev_seq_open_ops(struct inode *inode, struct file *file,
2586 const struct seq_operations *ops);
2587#endif
2588
2589extern int netdev_class_create_file(struct class_attribute *class_attr);
2590extern void netdev_class_remove_file(struct class_attribute *class_attr);
2591
2592extern struct kobj_ns_type_operations net_ns_type_operations;
2593
2594extern const char *netdev_drivername(const struct net_device *dev);
2595
2596extern void linkwatch_run_queue(void);
2597
2598static inline netdev_features_t netdev_get_wanted_features(
2599 struct net_device *dev)
2600{
2601 return (dev->features & ~dev->hw_features) | dev->wanted_features;
2602}
2603netdev_features_t netdev_increment_features(netdev_features_t all,
2604 netdev_features_t one, netdev_features_t mask);
2605int __netdev_update_features(struct net_device *dev);
2606void netdev_update_features(struct net_device *dev);
2607void netdev_change_features(struct net_device *dev);
2608
2609void netif_stacked_transfer_operstate(const struct net_device *rootdev,
2610 struct net_device *dev);
2611
2612netdev_features_t netif_skb_features(struct sk_buff *skb);
2613
2614static inline int net_gso_ok(netdev_features_t features, int gso_type)
2615{
2616 netdev_features_t feature = gso_type << NETIF_F_GSO_SHIFT;
2617
2618
2619 BUILD_BUG_ON(SKB_GSO_TCPV4 != (NETIF_F_TSO >> NETIF_F_GSO_SHIFT));
2620 BUILD_BUG_ON(SKB_GSO_UDP != (NETIF_F_UFO >> NETIF_F_GSO_SHIFT));
2621 BUILD_BUG_ON(SKB_GSO_DODGY != (NETIF_F_GSO_ROBUST >> NETIF_F_GSO_SHIFT));
2622 BUILD_BUG_ON(SKB_GSO_TCP_ECN != (NETIF_F_TSO_ECN >> NETIF_F_GSO_SHIFT));
2623 BUILD_BUG_ON(SKB_GSO_TCPV6 != (NETIF_F_TSO6 >> NETIF_F_GSO_SHIFT));
2624 BUILD_BUG_ON(SKB_GSO_FCOE != (NETIF_F_FSO >> NETIF_F_GSO_SHIFT));
2625
2626 return (features & feature) == feature;
2627}
2628
2629static inline int skb_gso_ok(struct sk_buff *skb, netdev_features_t features)
2630{
2631 return net_gso_ok(features, skb_shinfo(skb)->gso_type) &&
2632 (!skb_has_frag_list(skb) || (features & NETIF_F_FRAGLIST));
2633}
2634
2635static inline int netif_needs_gso(struct sk_buff *skb,
2636 netdev_features_t features)
2637{
2638 return skb_is_gso(skb) && (!skb_gso_ok(skb, features) ||
2639 unlikely(skb->ip_summed != CHECKSUM_PARTIAL));
2640}
2641
2642static inline void netif_set_gso_max_size(struct net_device *dev,
2643 unsigned int size)
2644{
2645 dev->gso_max_size = size;
2646}
2647
2648static inline int netif_is_bond_slave(struct net_device *dev)
2649{
2650 return dev->flags & IFF_SLAVE && dev->priv_flags & IFF_BONDING;
2651}
2652
2653extern struct pernet_operations __net_initdata loopback_net_ops;
2654
2655
2656
2657
2658
2659static inline const char *netdev_name(const struct net_device *dev)
2660{
2661 if (dev->reg_state != NETREG_REGISTERED)
2662 return "(unregistered net_device)";
2663 return dev->name;
2664}
2665
2666extern int __netdev_printk(const char *level, const struct net_device *dev,
2667 struct va_format *vaf);
2668
2669extern __printf(3, 4)
2670int netdev_printk(const char *level, const struct net_device *dev,
2671 const char *format, ...);
2672extern __printf(2, 3)
2673int netdev_emerg(const struct net_device *dev, const char *format, ...);
2674extern __printf(2, 3)
2675int netdev_alert(const struct net_device *dev, const char *format, ...);
2676extern __printf(2, 3)
2677int netdev_crit(const struct net_device *dev, const char *format, ...);
2678extern __printf(2, 3)
2679int netdev_err(const struct net_device *dev, const char *format, ...);
2680extern __printf(2, 3)
2681int netdev_warn(const struct net_device *dev, const char *format, ...);
2682extern __printf(2, 3)
2683int netdev_notice(const struct net_device *dev, const char *format, ...);
2684extern __printf(2, 3)
2685int netdev_info(const struct net_device *dev, const char *format, ...);
2686
2687#define MODULE_ALIAS_NETDEV(device) \
2688 MODULE_ALIAS("netdev-" device)
2689
2690#if defined(DEBUG)
2691#define netdev_dbg(__dev, format, args...) \
2692 netdev_printk(KERN_DEBUG, __dev, format, ##args)
2693#elif defined(CONFIG_DYNAMIC_DEBUG)
2694#define netdev_dbg(__dev, format, args...) \
2695do { \
2696 dynamic_netdev_dbg(__dev, format, ##args); \
2697} while (0)
2698#else
2699#define netdev_dbg(__dev, format, args...) \
2700({ \
2701 if (0) \
2702 netdev_printk(KERN_DEBUG, __dev, format, ##args); \
2703 0; \
2704})
2705#endif
2706
2707#if defined(VERBOSE_DEBUG)
2708#define netdev_vdbg netdev_dbg
2709#else
2710
2711#define netdev_vdbg(dev, format, args...) \
2712({ \
2713 if (0) \
2714 netdev_printk(KERN_DEBUG, dev, format, ##args); \
2715 0; \
2716})
2717#endif
2718
2719
2720
2721
2722
2723
2724#define netdev_WARN(dev, format, args...) \
2725 WARN(1, "netdevice: %s\n" format, netdev_name(dev), ##args);
2726
2727
2728
2729#define netif_printk(priv, type, level, dev, fmt, args...) \
2730do { \
2731 if (netif_msg_##type(priv)) \
2732 netdev_printk(level, (dev), fmt, ##args); \
2733} while (0)
2734
2735#define netif_level(level, priv, type, dev, fmt, args...) \
2736do { \
2737 if (netif_msg_##type(priv)) \
2738 netdev_##level(dev, fmt, ##args); \
2739} while (0)
2740
2741#define netif_emerg(priv, type, dev, fmt, args...) \
2742 netif_level(emerg, priv, type, dev, fmt, ##args)
2743#define netif_alert(priv, type, dev, fmt, args...) \
2744 netif_level(alert, priv, type, dev, fmt, ##args)
2745#define netif_crit(priv, type, dev, fmt, args...) \
2746 netif_level(crit, priv, type, dev, fmt, ##args)
2747#define netif_err(priv, type, dev, fmt, args...) \
2748 netif_level(err, priv, type, dev, fmt, ##args)
2749#define netif_warn(priv, type, dev, fmt, args...) \
2750 netif_level(warn, priv, type, dev, fmt, ##args)
2751#define netif_notice(priv, type, dev, fmt, args...) \
2752 netif_level(notice, priv, type, dev, fmt, ##args)
2753#define netif_info(priv, type, dev, fmt, args...) \
2754 netif_level(info, priv, type, dev, fmt, ##args)
2755
2756#if defined(DEBUG)
2757#define netif_dbg(priv, type, dev, format, args...) \
2758 netif_printk(priv, type, KERN_DEBUG, dev, format, ##args)
2759#elif defined(CONFIG_DYNAMIC_DEBUG)
2760#define netif_dbg(priv, type, netdev, format, args...) \
2761do { \
2762 if (netif_msg_##type(priv)) \
2763 dynamic_netdev_dbg(netdev, format, ##args); \
2764} while (0)
2765#else
2766#define netif_dbg(priv, type, dev, format, args...) \
2767({ \
2768 if (0) \
2769 netif_printk(priv, type, KERN_DEBUG, dev, format, ##args); \
2770 0; \
2771})
2772#endif
2773
2774#if defined(VERBOSE_DEBUG)
2775#define netif_vdbg netif_dbg
2776#else
2777#define netif_vdbg(priv, type, dev, format, args...) \
2778({ \
2779 if (0) \
2780 netif_printk(priv, type, KERN_DEBUG, dev, format, ##args); \
2781 0; \
2782})
2783#endif
2784
2785#endif
2786
2787#endif
2788