Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /* net/sched/sch_teql.c	"True" (or "trivial") link equalizer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Authors:	Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/if_arp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/moduleparam.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <net/dst.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <net/neighbour.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <net/pkt_sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)    How to setup it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)    ----------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)    After loading this module you will find a new device teqlN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)    and new qdisc with the same name. To join a slave to the equalizer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)    you should just set this qdisc on a device f.e.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)    # tc qdisc add dev eth0 root teql0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)    # tc qdisc add dev eth1 root teql0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)    That's all. Full PnP 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)    Applicability.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)    --------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)    1. Slave devices MUST be active devices, i.e., they must raise the tbusy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)       signal and generate EOI events. If you want to equalize virtual devices
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40)       like tunnels, use a normal eql device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41)    2. This device puts no limitations on physical slave characteristics
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42)       f.e. it will equalize 9600baud line and 100Mb ethernet perfectly :-)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43)       Certainly, large difference in link speeds will make the resulting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44)       eqalized link unusable, because of huge packet reordering.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45)       I estimate an upper useful difference as ~10 times.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46)    3. If the slave requires address resolution, only protocols using
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47)       neighbour cache (IPv4/IPv6) will work over the equalized link.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)       Other protocols are still allowed to use the slave device directly,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49)       which will not break load balancing, though native slave
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50)       traffic will have the highest priority.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) struct teql_master {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	struct Qdisc_ops qops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	struct Qdisc *slaves;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	struct list_head master_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	unsigned long	tx_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	unsigned long	tx_packets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	unsigned long	tx_errors;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	unsigned long	tx_dropped;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) struct teql_sched_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	struct Qdisc *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	struct teql_master *m;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	struct sk_buff_head q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) #define NEXT_SLAVE(q) (((struct teql_sched_data *)qdisc_priv(q))->next)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) #define FMASK (IFF_BROADCAST | IFF_POINTOPOINT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) /* "teql*" qdisc routines */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) teql_enqueue(struct sk_buff *skb, struct Qdisc *sch, struct sk_buff **to_free)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	struct net_device *dev = qdisc_dev(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	struct teql_sched_data *q = qdisc_priv(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	if (q->q.qlen < dev->tx_queue_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		__skb_queue_tail(&q->q, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		return NET_XMIT_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	return qdisc_drop(skb, sch, to_free);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) static struct sk_buff *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) teql_dequeue(struct Qdisc *sch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	struct teql_sched_data *dat = qdisc_priv(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	struct netdev_queue *dat_queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	struct Qdisc *q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	skb = __skb_dequeue(&dat->q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	dat_queue = netdev_get_tx_queue(dat->m->dev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	q = rcu_dereference_bh(dat_queue->qdisc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	if (skb == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		struct net_device *m = qdisc_dev(q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		if (m) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 			dat->m->slaves = sch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 			netif_wake_queue(m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		qdisc_bstats_update(sch, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	sch->q.qlen = dat->q.qlen + q->q.qlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	return skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) static struct sk_buff *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) teql_peek(struct Qdisc *sch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	/* teql is meant to be used as root qdisc */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) teql_reset(struct Qdisc *sch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	struct teql_sched_data *dat = qdisc_priv(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	skb_queue_purge(&dat->q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	sch->q.qlen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) teql_destroy(struct Qdisc *sch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	struct Qdisc *q, *prev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	struct teql_sched_data *dat = qdisc_priv(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	struct teql_master *master = dat->m;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	if (!master)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	prev = master->slaves;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	if (prev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 			q = NEXT_SLAVE(prev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 			if (q == sch) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 				NEXT_SLAVE(prev) = NEXT_SLAVE(q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 				if (q == master->slaves) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 					master->slaves = NEXT_SLAVE(q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 					if (q == master->slaves) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 						struct netdev_queue *txq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 						spinlock_t *root_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 						txq = netdev_get_tx_queue(master->dev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 						master->slaves = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 						root_lock = qdisc_root_sleeping_lock(rtnl_dereference(txq->qdisc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 						spin_lock_bh(root_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 						qdisc_reset(rtnl_dereference(txq->qdisc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 						spin_unlock_bh(root_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 				skb_queue_purge(&dat->q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		} while ((prev = q) != master->slaves);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) static int teql_qdisc_init(struct Qdisc *sch, struct nlattr *opt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 			   struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	struct net_device *dev = qdisc_dev(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	struct teql_master *m = (struct teql_master *)sch->ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	struct teql_sched_data *q = qdisc_priv(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	if (dev->hard_header_len > m->dev->hard_header_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	if (m->dev == dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 		return -ELOOP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	q->m = m;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	skb_queue_head_init(&q->q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	if (m->slaves) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		if (m->dev->flags & IFF_UP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 			if ((m->dev->flags & IFF_POINTOPOINT &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 			     !(dev->flags & IFF_POINTOPOINT)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 			    (m->dev->flags & IFF_BROADCAST &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 			     !(dev->flags & IFF_BROADCAST)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 			    (m->dev->flags & IFF_MULTICAST &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 			     !(dev->flags & IFF_MULTICAST)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 			    dev->mtu < m->dev->mtu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 				return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 			if (!(dev->flags&IFF_POINTOPOINT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 				m->dev->flags &= ~IFF_POINTOPOINT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 			if (!(dev->flags&IFF_BROADCAST))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 				m->dev->flags &= ~IFF_BROADCAST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 			if (!(dev->flags&IFF_MULTICAST))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 				m->dev->flags &= ~IFF_MULTICAST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 			if (dev->mtu < m->dev->mtu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 				m->dev->mtu = dev->mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		q->next = NEXT_SLAVE(m->slaves);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		NEXT_SLAVE(m->slaves) = sch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		q->next = sch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		m->slaves = sch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		m->dev->mtu = dev->mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		m->dev->flags = (m->dev->flags&~FMASK)|(dev->flags&FMASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) __teql_resolve(struct sk_buff *skb, struct sk_buff *skb_res,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	       struct net_device *dev, struct netdev_queue *txq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	       struct dst_entry *dst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	struct neighbour *n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	n = dst_neigh_lookup_skb(dst, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	if (!n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	if (dst->dev != dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		struct neighbour *mn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		mn = __neigh_lookup_errno(n->tbl, n->primary_key, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		neigh_release(n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		if (IS_ERR(mn))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 			return PTR_ERR(mn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 		n = mn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	if (neigh_event_send(n, skb_res) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 		char haddr[MAX_ADDR_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 		neigh_ha_snapshot(haddr, n, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 		err = dev_hard_header(skb, dev, ntohs(skb_protocol(skb, false)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 				      haddr, NULL, skb->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 		if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 			err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 		err = (skb_res == NULL) ? -EAGAIN : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	neigh_release(n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) static inline int teql_resolve(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 			       struct sk_buff *skb_res,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 			       struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 			       struct netdev_queue *txq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	struct dst_entry *dst = skb_dst(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	int res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	if (rcu_access_pointer(txq->qdisc) == &noop_qdisc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	if (!dev->header_ops || !dst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	res = __teql_resolve(skb, skb_res, dev, txq, dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) static netdev_tx_t teql_master_xmit(struct sk_buff *skb, struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	struct teql_master *master = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	struct Qdisc *start, *q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	int busy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	int nores;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	int subq = skb_get_queue_mapping(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	struct sk_buff *skb_res = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	start = master->slaves;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) restart:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	nores = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	busy = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	q = start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	if (!q)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 		goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 		struct net_device *slave = qdisc_dev(q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 		struct netdev_queue *slave_txq = netdev_get_tx_queue(slave, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 		if (slave_txq->qdisc_sleeping != q)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 		if (netif_xmit_stopped(netdev_get_tx_queue(slave, subq)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 		    !netif_running(slave)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 			busy = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 		switch (teql_resolve(skb, skb_res, slave, slave_txq)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 		case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 			if (__netif_tx_trylock(slave_txq)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 				unsigned int length = qdisc_pkt_len(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 				if (!netif_xmit_frozen_or_stopped(slave_txq) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 				    netdev_start_xmit(skb, slave, slave_txq, false) ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 				    NETDEV_TX_OK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 					__netif_tx_unlock(slave_txq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 					master->slaves = NEXT_SLAVE(q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 					netif_wake_queue(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 					master->tx_packets++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 					master->tx_bytes += length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 					return NETDEV_TX_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 				__netif_tx_unlock(slave_txq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 			if (netif_xmit_stopped(netdev_get_tx_queue(dev, 0)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 				busy = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 		case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 			master->slaves = NEXT_SLAVE(q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 			return NETDEV_TX_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 			nores = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 		__skb_pull(skb, skb_network_offset(skb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	} while ((q = NEXT_SLAVE(q)) != start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	if (nores && skb_res == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 		skb_res = skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 		goto restart;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	if (busy) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 		netif_stop_queue(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 		return NETDEV_TX_BUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	master->tx_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) drop:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	master->tx_dropped++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	dev_kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	return NETDEV_TX_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) static int teql_master_open(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	struct Qdisc *q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	struct teql_master *m = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	int mtu = 0xFFFE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	unsigned int flags = IFF_NOARP | IFF_MULTICAST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	if (m->slaves == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 		return -EUNATCH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	flags = FMASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	q = m->slaves;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 		struct net_device *slave = qdisc_dev(q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 		if (slave == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 			return -EUNATCH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 		if (slave->mtu < mtu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 			mtu = slave->mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 		if (slave->hard_header_len > LL_MAX_HEADER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 		/* If all the slaves are BROADCAST, master is BROADCAST
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 		   If all the slaves are PtP, master is PtP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 		   Otherwise, master is NBMA.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 		if (!(slave->flags&IFF_POINTOPOINT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 			flags &= ~IFF_POINTOPOINT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 		if (!(slave->flags&IFF_BROADCAST))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 			flags &= ~IFF_BROADCAST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 		if (!(slave->flags&IFF_MULTICAST))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 			flags &= ~IFF_MULTICAST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	} while ((q = NEXT_SLAVE(q)) != m->slaves);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	m->dev->mtu = mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	m->dev->flags = (m->dev->flags&~FMASK) | flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	netif_start_queue(m->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) static int teql_master_close(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	netif_stop_queue(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) static void teql_master_stats64(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 				struct rtnl_link_stats64 *stats)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	struct teql_master *m = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	stats->tx_packets	= m->tx_packets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	stats->tx_bytes		= m->tx_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	stats->tx_errors	= m->tx_errors;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	stats->tx_dropped	= m->tx_dropped;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) static int teql_master_mtu(struct net_device *dev, int new_mtu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	struct teql_master *m = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	struct Qdisc *q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	q = m->slaves;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	if (q) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 		do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 			if (new_mtu > qdisc_dev(q)->mtu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 				return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 		} while ((q = NEXT_SLAVE(q)) != m->slaves);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	dev->mtu = new_mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) static const struct net_device_ops teql_netdev_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	.ndo_open	= teql_master_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	.ndo_stop	= teql_master_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	.ndo_start_xmit	= teql_master_xmit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	.ndo_get_stats64 = teql_master_stats64,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	.ndo_change_mtu	= teql_master_mtu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) static __init void teql_master_setup(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	struct teql_master *master = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	struct Qdisc_ops *ops = &master->qops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	master->dev	= dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	ops->priv_size  = sizeof(struct teql_sched_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	ops->enqueue	=	teql_enqueue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	ops->dequeue	=	teql_dequeue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	ops->peek	=	teql_peek;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	ops->init	=	teql_qdisc_init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	ops->reset	=	teql_reset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	ops->destroy	=	teql_destroy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	ops->owner	=	THIS_MODULE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	dev->netdev_ops =       &teql_netdev_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	dev->type		= ARPHRD_VOID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	dev->mtu		= 1500;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	dev->min_mtu		= 68;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	dev->max_mtu		= 65535;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	dev->tx_queue_len	= 100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	dev->flags		= IFF_NOARP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	dev->hard_header_len	= LL_MAX_HEADER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	netif_keep_dst(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) static LIST_HEAD(master_dev_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) static int max_equalizers = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) module_param(max_equalizers, int, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) MODULE_PARM_DESC(max_equalizers, "Max number of link equalizers");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) static int __init teql_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 	int err = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 	for (i = 0; i < max_equalizers; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 		struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 		struct teql_master *master;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 		dev = alloc_netdev(sizeof(struct teql_master), "teql%d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 				   NET_NAME_UNKNOWN, teql_master_setup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 		if (!dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 			err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 		if ((err = register_netdev(dev))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 			free_netdev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 		master = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 		strlcpy(master->qops.id, dev->name, IFNAMSIZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 		err = register_qdisc(&master->qops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 		if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 			unregister_netdev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 			free_netdev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 		list_add_tail(&master->master_list, &master_dev_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 	return i ? 0 : err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) static void __exit teql_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 	struct teql_master *master, *nxt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 	list_for_each_entry_safe(master, nxt, &master_dev_list, master_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 		list_del(&master->master_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 		unregister_qdisc(&master->qops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 		unregister_netdev(master->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 		free_netdev(master->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) module_init(teql_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) module_exit(teql_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) MODULE_LICENSE("GPL");