From 5b7c4cabbb65f5c469464da6c5f614cbd7f730f2 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Tue, 21 Feb 2023 18:24:12 -0800 Subject: Merge tag 'net-next-6.3' of git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next Pull networking updates from Jakub Kicinski: "Core: - Add dedicated kmem_cache for typical/small skb->head, avoid having to access struct page at kfree time, and improve memory use. - Introduce sysctl to set default RPS configuration for new netdevs. - Define Netlink protocol specification format which can be used to describe messages used by each family and auto-generate parsers. Add tools for generating kernel data structures and uAPI headers. - Expose all net/core sysctls inside netns. - Remove 4s sleep in netpoll if carrier is instantly detected on boot. - Add configurable limit of MDB entries per port, and port-vlan. - Continue populating drop reasons throughout the stack. - Retire a handful of legacy Qdiscs and classifiers. Protocols: - Support IPv4 big TCP (TSO frames larger than 64kB). - Add IP_LOCAL_PORT_RANGE socket option, to control local port range on socket by socket basis. - Track and report in procfs number of MPTCP sockets used. - Support mixing IPv4 and IPv6 flows in the in-kernel MPTCP path manager. - IPv6: don't check net.ipv6.route.max_size and rely on garbage collection to free memory (similarly to IPv4). - Support Penultimate Segment Pop (PSP) flavor in SRv6 (RFC8986). - ICMP: add per-rate limit counters. - Add support for user scanning requests in ieee802154. - Remove static WEP support. - Support minimal Wi-Fi 7 Extremely High Throughput (EHT) rate reporting. - WiFi 7 EHT channel puncturing support (client & AP). BPF: - Add a rbtree data structure following the "next-gen data structure" precedent set by recently added linked list, that is, by using kfunc + kptr instead of adding a new BPF map type. - Expose XDP hints via kfuncs with initial support for RX hash and timestamp metadata. - Add BPF_F_NO_TUNNEL_KEY extension to bpf_skb_set_tunnel_key to better support decap on GRE tunnel devices not operating in collect metadata. - Improve x86 JIT's codegen for PROBE_MEM runtime error checks. - Remove the need for trace_printk_lock for bpf_trace_printk and bpf_trace_vprintk helpers. - Extend libbpf's bpf_tracing.h support for tracing arguments of kprobes/uprobes and syscall as a special case. - Significantly reduce the search time for module symbols by livepatch and BPF. - Enable cpumasks to be used as kptrs, which is useful for tracing programs tracking which tasks end up running on which CPUs in different time intervals. - Add support for BPF trampoline on s390x and riscv64. - Add capability to export the XDP features supported by the NIC. - Add __bpf_kfunc tag for marking kernel functions as kfuncs. - Add cgroup.memory=nobpf kernel parameter option to disable BPF memory accounting for container environments. Netfilter: - Remove the CLUSTERIP target. It has been marked as obsolete for years, and we still have WARN splats wrt races of the out-of-band /proc interface installed by this target. - Add 'destroy' commands to nf_tables. They are identical to the existing 'delete' commands, but do not return an error if the referenced object (set, chain, rule...) did not exist. Driver API: - Improve cpumask_local_spread() locality to help NICs set the right IRQ affinity on AMD platforms. - Separate C22 and C45 MDIO bus transactions more clearly. - Introduce new DCB table to control DSCP rewrite on egress. - Support configuration of Physical Layer Collision Avoidance (PLCA) Reconciliation Sublayer (RS) (802.3cg-2019). Modern version of shared medium Ethernet. - Support for MAC Merge layer (IEEE 802.3-2018 clause 99). Allowing preemption of low priority frames by high priority frames. - Add support for controlling MACSec offload using netlink SET. - Rework devlink instance refcounts to allow registration and de-registration under the instance lock. Split the code into multiple files, drop some of the unnecessarily granular locks and factor out common parts of netlink operation handling. - Add TX frame aggregation parameters (for USB drivers). - Add a new attr TCA_EXT_WARN_MSG to report TC (offload) warning messages with notifications for debug. - Allow offloading of UDP NEW connections via act_ct. - Add support for per action HW stats in TC. - Support hardware miss to TC action (continue processing in SW from a specific point in the action chain). - Warn if old Wireless Extension user space interface is used with modern cfg80211/mac80211 drivers. Do not support Wireless Extensions for Wi-Fi 7 devices at all. Everyone should switch to using nl80211 interface instead. - Improve the CAN bit timing configuration. Use extack to return error messages directly to user space, update the SJW handling, including the definition of a new default value that will benefit CAN-FD controllers, by increasing their oscillator tolerance. New hardware / drivers: - Ethernet: - nVidia BlueField-3 support (control traffic driver) - Ethernet support for imx93 SoCs - Motorcomm yt8531 gigabit Ethernet PHY - onsemi NCN26000 10BASE-T1S PHY (with support for PLCA) - Microchip LAN8841 PHY (incl. cable diagnostics and PTP) - Amlogic gxl MDIO mux - WiFi: - RealTek RTL8188EU (rtl8xxxu) - Qualcomm Wi-Fi 7 devices (ath12k) - CAN: - Renesas R-Car V4H Drivers: - Bluetooth: - Set Per Platform Antenna Gain (PPAG) for Intel controllers. - Ethernet NICs: - Intel (1G, igc): - support TSN / Qbv / packet scheduling features of i226 model - Intel (100G, ice): - use GNSS subsystem instead of TTY - multi-buffer XDP support - extend support for GPIO pins to E823 devices - nVidia/Mellanox: - update the shared buffer configuration on PFC commands - implement PTP adjphase function for HW offset control - TC support for Geneve and GRE with VF tunnel offload - more efficient crypto key management method - multi-port eswitch support - Netronome/Corigine: - add DCB IEEE support - support IPsec offloading for NFP3800 - Freescale/NXP (enetc): - support XDP_REDIRECT for XDP non-linear buffers - improve reconfig, avoid link flap and waiting for idle - support MAC Merge layer - Other NICs: - sfc/ef100: add basic devlink support for ef100 - ionic: rx_push mode operation (writing descriptors via MMIO) - bnxt: use the auxiliary bus abstraction for RDMA - r8169: disable ASPM and reset bus in case of tx timeout - cpsw: support QSGMII mode for J721e CPSW9G - cpts: support pulse-per-second output - ngbe: add an mdio bus driver - usbnet: optimize usbnet_bh() by avoiding unnecessary queuing - r8152: handle devices with FW with NCM support - amd-xgbe: support 10Mbps, 2.5GbE speeds and rx-adaptation - virtio-net: support multi buffer XDP - virtio/vsock: replace virtio_vsock_pkt with sk_buff - tsnep: XDP support - Ethernet high-speed switches: - nVidia/Mellanox (mlxsw): - add support for latency TLV (in FW control messages) - Microchip (sparx5): - separate explicit and implicit traffic forwarding rules, make the implicit rules always active - add support for egress DSCP rewrite - IS0 VCAP support (Ingress Classification) - IS2 VCAP filters (protos, L3 addrs, L4 ports, flags, ToS etc.) - ES2 VCAP support (Egress Access Control) - support for Per-Stream Filtering and Policing (802.1Q, 8.6.5.1) - Ethernet embedded switches: - Marvell (mv88e6xxx): - add MAB (port auth) offload support - enable PTP receive for mv88e6390 - NXP (ocelot): - support MAC Merge layer - support for the the vsc7512 internal copper phys - Microchip: - lan9303: convert to PHYLINK - lan966x: support TC flower filter statistics - lan937x: PTP support for KSZ9563/KSZ8563 and LAN937x - lan937x: support Credit Based Shaper configuration - ksz9477: support Energy Efficient Ethernet - other: - qca8k: convert to regmap read/write API, use bulk operations - rswitch: Improve TX timestamp accuracy - Intel WiFi (iwlwifi): - EHT (Wi-Fi 7) rate reporting - STEP equalizer support: transfer some STEP (connection to radio on platforms with integrated wifi) related parameters from the BIOS to the firmware. - Qualcomm 802.11ax WiFi (ath11k): - IPQ5018 support - Fine Timing Measurement (FTM) responder role support - channel 177 support - MediaTek WiFi (mt76): - per-PHY LED support - mt7996: EHT (Wi-Fi 7) support - Wireless Ethernet Dispatch (WED) reset support - switch to using page pool allocator - RealTek WiFi (rtw89): - support new version of Bluetooth co-existance - Mobile: - rmnet: support TX aggregation" * tag 'net-next-6.3' of git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next: (1872 commits) page_pool: add a comment explaining the fragment counter usage net: ethtool: fix __ethtool_dev_mm_supported() implementation ethtool: pse-pd: Fix double word in comments xsk: add linux/vmalloc.h to xsk.c sefltests: netdevsim: wait for devlink instance after netns removal selftest: fib_tests: Always cleanup before exit net/mlx5e: Align IPsec ASO result memory to be as required by hardware net/mlx5e: TC, Set CT miss to the specific ct action instance net/mlx5e: Rename CHAIN_TO_REG to MAPPED_OBJ_TO_REG net/mlx5: Refactor tc miss handling to a single function net/mlx5: Kconfig: Make tc offload depend on tc skb extension net/sched: flower: Support hardware miss to tc action net/sched: flower: Move filter handle initialization earlier net/sched: cls_api: Support hardware miss to tc action net/sched: Rename user cookie and act cookie sfc: fix builds without CONFIG_RTC_LIB sfc: clean up some inconsistent indentings net/mlx4_en: Introduce flexible array to silence overflow warning net: lan966x: Fix possible deadlock inside PTP net/ulp: Remove redundant ->clone() test in inet_clone_ulp(). ... --- drivers/net/eql.c | 610 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 610 insertions(+) create mode 100644 drivers/net/eql.c (limited to 'drivers/net/eql.c') diff --git a/drivers/net/eql.c b/drivers/net/eql.c new file mode 100644 index 000000000..ca3e4700a --- /dev/null +++ b/drivers/net/eql.c @@ -0,0 +1,610 @@ +/* + * Equalizer Load-balancer for serial network interfaces. + * + * (c) Copyright 1995 Simon "Guru Aleph-Null" Janes + * NCM: Network and Communications Management, Inc. + * + * (c) Copyright 2002 David S. Miller (davem@redhat.com) + * + * This software may be used and distributed according to the terms + * of the GNU General Public License, incorporated herein by reference. + * + * The author may be reached as simon@ncm.com, or C/O + * NCM + * Attn: Simon Janes + * 6803 Whittier Ave + * McLean VA 22101 + * Phone: 1-703-847-0040 ext 103 + */ + +/* + * Sources: + * skeleton.c by Donald Becker. + * Inspirations: + * The Harried and Overworked Alan Cox + * Conspiracies: + * The Alan Cox and Mike McLagan plot to get someone else to do the code, + * which turned out to be me. + */ + +/* + * $Log: eql.c,v $ + * Revision 1.2 1996/04/11 17:51:52 guru + * Added one-line eql_remove_slave patch. + * + * Revision 1.1 1996/04/11 17:44:17 guru + * Initial revision + * + * Revision 3.13 1996/01/21 15:17:18 alan + * tx_queue_len changes. + * reformatted. + * + * Revision 3.12 1995/03/22 21:07:51 anarchy + * Added capable() checks on configuration. + * Moved header file. + * + * Revision 3.11 1995/01/19 23:14:31 guru + * slave_load = (ULONG_MAX - (ULONG_MAX / 2)) - + * (priority_Bps) + bytes_queued * 8; + * + * Revision 3.10 1995/01/19 23:07:53 guru + * back to + * slave_load = (ULONG_MAX - (ULONG_MAX / 2)) - + * (priority_Bps) + bytes_queued; + * + * Revision 3.9 1995/01/19 22:38:20 guru + * slave_load = (ULONG_MAX - (ULONG_MAX / 2)) - + * (priority_Bps) + bytes_queued * 4; + * + * Revision 3.8 1995/01/19 22:30:55 guru + * slave_load = (ULONG_MAX - (ULONG_MAX / 2)) - + * (priority_Bps) + bytes_queued * 2; + * + * Revision 3.7 1995/01/19 21:52:35 guru + * printk's trimmed out. + * + * Revision 3.6 1995/01/19 21:49:56 guru + * This is working pretty well. I gained 1 K/s in speed.. now it's just + * robustness and printk's to be diked out. + * + * Revision 3.5 1995/01/18 22:29:59 guru + * still crashes the kernel when the lock_wait thing is woken up. + * + * Revision 3.4 1995/01/18 21:59:47 guru + * Broken set-bit locking snapshot + * + * Revision 3.3 1995/01/17 22:09:18 guru + * infinite sleep in a lock somewhere.. + * + * Revision 3.2 1995/01/15 16:46:06 guru + * Log trimmed of non-pertinent 1.x branch messages + * + * Revision 3.1 1995/01/15 14:41:45 guru + * New Scheduler and timer stuff... + * + * Revision 1.15 1995/01/15 14:29:02 guru + * Will make 1.14 (now 1.15) the 3.0 branch, and the 1.12 the 2.0 branch, the one + * with the dumber scheduler + * + * Revision 1.14 1995/01/15 02:37:08 guru + * shock.. the kept-new-versions could have zonked working + * stuff.. shudder + * + * Revision 1.13 1995/01/15 02:36:31 guru + * big changes + * + * scheduler was torn out and replaced with something smarter + * + * global names not prefixed with eql_ were renamed to protect + * against namespace collisions + * + * a few more abstract interfaces were added to facilitate any + * potential change of datastructure. the driver is still using + * a linked list of slaves. going to a heap would be a bit of + * an overkill. + * + * this compiles fine with no warnings. + * + * the locking mechanism and timer stuff must be written however, + * this version will not work otherwise + * + * Sorry, I had to rewrite most of this for 2.5.x -DaveM + */ + +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include + +static int eql_open(struct net_device *dev); +static int eql_close(struct net_device *dev); +static int eql_siocdevprivate(struct net_device *dev, struct ifreq *ifr, + void __user *data, int cmd); +static netdev_tx_t eql_slave_xmit(struct sk_buff *skb, struct net_device *dev); + +#define eql_is_slave(dev) ((dev->flags & IFF_SLAVE) == IFF_SLAVE) +#define eql_is_master(dev) ((dev->flags & IFF_MASTER) == IFF_MASTER) + +static void eql_kill_one_slave(slave_queue_t *queue, slave_t *slave); + +static void eql_timer(struct timer_list *t) +{ + equalizer_t *eql = from_timer(eql, t, timer); + struct list_head *this, *tmp, *head; + + spin_lock(&eql->queue.lock); + head = &eql->queue.all_slaves; + list_for_each_safe(this, tmp, head) { + slave_t *slave = list_entry(this, slave_t, list); + + if ((slave->dev->flags & IFF_UP) == IFF_UP) { + slave->bytes_queued -= slave->priority_Bps; + if (slave->bytes_queued < 0) + slave->bytes_queued = 0; + } else { + eql_kill_one_slave(&eql->queue, slave); + } + + } + spin_unlock(&eql->queue.lock); + + eql->timer.expires = jiffies + EQL_DEFAULT_RESCHED_IVAL; + add_timer(&eql->timer); +} + +static const char version[] __initconst = + "Equalizer2002: Simon Janes (simon@ncm.com) and David S. Miller (davem@redhat.com)"; + +static const struct net_device_ops eql_netdev_ops = { + .ndo_open = eql_open, + .ndo_stop = eql_close, + .ndo_siocdevprivate = eql_siocdevprivate, + .ndo_start_xmit = eql_slave_xmit, +}; + +static void __init eql_setup(struct net_device *dev) +{ + equalizer_t *eql = netdev_priv(dev); + + timer_setup(&eql->timer, eql_timer, 0); + eql->timer.expires = jiffies + EQL_DEFAULT_RESCHED_IVAL; + + spin_lock_init(&eql->queue.lock); + INIT_LIST_HEAD(&eql->queue.all_slaves); + eql->queue.master_dev = dev; + + dev->netdev_ops = &eql_netdev_ops; + + /* + * Now we undo some of the things that eth_setup does + * that we don't like + */ + + dev->mtu = EQL_DEFAULT_MTU; /* set to 576 in if_eql.h */ + dev->flags = IFF_MASTER; + + dev->type = ARPHRD_SLIP; + dev->tx_queue_len = 5; /* Hands them off fast */ + netif_keep_dst(dev); +} + +static int eql_open(struct net_device *dev) +{ + equalizer_t *eql = netdev_priv(dev); + + /* XXX We should force this off automatically for the user. */ + netdev_info(dev, + "remember to turn off Van-Jacobson compression on your slave devices\n"); + + BUG_ON(!list_empty(&eql->queue.all_slaves)); + + eql->min_slaves = 1; + eql->max_slaves = EQL_DEFAULT_MAX_SLAVES; /* 4 usually... */ + + add_timer(&eql->timer); + + return 0; +} + +static void eql_kill_one_slave(slave_queue_t *queue, slave_t *slave) +{ + list_del(&slave->list); + queue->num_slaves--; + slave->dev->flags &= ~IFF_SLAVE; + netdev_put(slave->dev, &slave->dev_tracker); + kfree(slave); +} + +static void eql_kill_slave_queue(slave_queue_t *queue) +{ + struct list_head *head, *tmp, *this; + + spin_lock_bh(&queue->lock); + + head = &queue->all_slaves; + list_for_each_safe(this, tmp, head) { + slave_t *s = list_entry(this, slave_t, list); + + eql_kill_one_slave(queue, s); + } + + spin_unlock_bh(&queue->lock); +} + +static int eql_close(struct net_device *dev) +{ + equalizer_t *eql = netdev_priv(dev); + + /* + * The timer has to be stopped first before we start hacking away + * at the data structure it scans every so often... + */ + + del_timer_sync(&eql->timer); + + eql_kill_slave_queue(&eql->queue); + + return 0; +} + +static int eql_enslave(struct net_device *dev, slaving_request_t __user *srq); +static int eql_emancipate(struct net_device *dev, slaving_request_t __user *srq); + +static int eql_g_slave_cfg(struct net_device *dev, slave_config_t __user *sc); +static int eql_s_slave_cfg(struct net_device *dev, slave_config_t __user *sc); + +static int eql_g_master_cfg(struct net_device *dev, master_config_t __user *mc); +static int eql_s_master_cfg(struct net_device *dev, master_config_t __user *mc); + +static int eql_siocdevprivate(struct net_device *dev, struct ifreq *ifr, + void __user *data, int cmd) +{ + if (cmd != EQL_GETMASTRCFG && cmd != EQL_GETSLAVECFG && + !capable(CAP_NET_ADMIN)) + return -EPERM; + + if (in_compat_syscall()) /* to be implemented */ + return -EOPNOTSUPP; + + switch (cmd) { + case EQL_ENSLAVE: + return eql_enslave(dev, data); + case EQL_EMANCIPATE: + return eql_emancipate(dev, data); + case EQL_GETSLAVECFG: + return eql_g_slave_cfg(dev, data); + case EQL_SETSLAVECFG: + return eql_s_slave_cfg(dev, data); + case EQL_GETMASTRCFG: + return eql_g_master_cfg(dev, data); + case EQL_SETMASTRCFG: + return eql_s_master_cfg(dev, data); + default: + return -EOPNOTSUPP; + } +} + +/* queue->lock must be held */ +static slave_t *__eql_schedule_slaves(slave_queue_t *queue) +{ + unsigned long best_load = ~0UL; + struct list_head *this, *tmp, *head; + slave_t *best_slave; + + best_slave = NULL; + + /* Make a pass to set the best slave. */ + head = &queue->all_slaves; + list_for_each_safe(this, tmp, head) { + slave_t *slave = list_entry(this, slave_t, list); + unsigned long slave_load, bytes_queued, priority_Bps; + + /* Go through the slave list once, updating best_slave + * whenever a new best_load is found. + */ + bytes_queued = slave->bytes_queued; + priority_Bps = slave->priority_Bps; + if ((slave->dev->flags & IFF_UP) == IFF_UP) { + slave_load = (~0UL - (~0UL / 2)) - + (priority_Bps) + bytes_queued * 8; + + if (slave_load < best_load) { + best_load = slave_load; + best_slave = slave; + } + } else { + /* We found a dead slave, kill it. */ + eql_kill_one_slave(queue, slave); + } + } + return best_slave; +} + +static netdev_tx_t eql_slave_xmit(struct sk_buff *skb, struct net_device *dev) +{ + equalizer_t *eql = netdev_priv(dev); + slave_t *slave; + + spin_lock(&eql->queue.lock); + + slave = __eql_schedule_slaves(&eql->queue); + if (slave) { + struct net_device *slave_dev = slave->dev; + + skb->dev = slave_dev; + skb->priority = TC_PRIO_FILLER; + slave->bytes_queued += skb->len; + dev_queue_xmit(skb); + dev->stats.tx_packets++; + } else { + dev->stats.tx_dropped++; + dev_kfree_skb(skb); + } + + spin_unlock(&eql->queue.lock); + + return NETDEV_TX_OK; +} + +/* + * Private ioctl functions + */ + +/* queue->lock must be held */ +static slave_t *__eql_find_slave_dev(slave_queue_t *queue, struct net_device *dev) +{ + struct list_head *this, *head; + + head = &queue->all_slaves; + list_for_each(this, head) { + slave_t *slave = list_entry(this, slave_t, list); + + if (slave->dev == dev) + return slave; + } + + return NULL; +} + +static inline int eql_is_full(slave_queue_t *queue) +{ + equalizer_t *eql = netdev_priv(queue->master_dev); + + if (queue->num_slaves >= eql->max_slaves) + return 1; + return 0; +} + +/* queue->lock must be held */ +static int __eql_insert_slave(slave_queue_t *queue, slave_t *slave) +{ + if (!eql_is_full(queue)) { + slave_t *duplicate_slave = NULL; + + duplicate_slave = __eql_find_slave_dev(queue, slave->dev); + if (duplicate_slave) + eql_kill_one_slave(queue, duplicate_slave); + + netdev_hold(slave->dev, &slave->dev_tracker, GFP_ATOMIC); + list_add(&slave->list, &queue->all_slaves); + queue->num_slaves++; + slave->dev->flags |= IFF_SLAVE; + + return 0; + } + + return -ENOSPC; +} + +static int eql_enslave(struct net_device *master_dev, slaving_request_t __user *srqp) +{ + struct net_device *slave_dev; + slaving_request_t srq; + + if (copy_from_user(&srq, srqp, sizeof (slaving_request_t))) + return -EFAULT; + + slave_dev = __dev_get_by_name(&init_net, srq.slave_name); + if (!slave_dev) + return -ENODEV; + + if ((master_dev->flags & IFF_UP) == IFF_UP) { + /* slave is not a master & not already a slave: */ + if (!eql_is_master(slave_dev) && !eql_is_slave(slave_dev)) { + slave_t *s = kzalloc(sizeof(*s), GFP_KERNEL); + equalizer_t *eql = netdev_priv(master_dev); + int ret; + + if (!s) + return -ENOMEM; + + s->dev = slave_dev; + s->priority = srq.priority; + s->priority_bps = srq.priority; + s->priority_Bps = srq.priority / 8; + + spin_lock_bh(&eql->queue.lock); + ret = __eql_insert_slave(&eql->queue, s); + if (ret) + kfree(s); + + spin_unlock_bh(&eql->queue.lock); + + return ret; + } + } + + return -EINVAL; +} + +static int eql_emancipate(struct net_device *master_dev, slaving_request_t __user *srqp) +{ + equalizer_t *eql = netdev_priv(master_dev); + struct net_device *slave_dev; + slaving_request_t srq; + int ret; + + if (copy_from_user(&srq, srqp, sizeof (slaving_request_t))) + return -EFAULT; + + slave_dev = __dev_get_by_name(&init_net, srq.slave_name); + if (!slave_dev) + return -ENODEV; + + ret = -EINVAL; + spin_lock_bh(&eql->queue.lock); + if (eql_is_slave(slave_dev)) { + slave_t *slave = __eql_find_slave_dev(&eql->queue, slave_dev); + if (slave) { + eql_kill_one_slave(&eql->queue, slave); + ret = 0; + } + } + spin_unlock_bh(&eql->queue.lock); + + return ret; +} + +static int eql_g_slave_cfg(struct net_device *dev, slave_config_t __user *scp) +{ + equalizer_t *eql = netdev_priv(dev); + slave_t *slave; + struct net_device *slave_dev; + slave_config_t sc; + int ret; + + if (copy_from_user(&sc, scp, sizeof (slave_config_t))) + return -EFAULT; + + slave_dev = __dev_get_by_name(&init_net, sc.slave_name); + if (!slave_dev) + return -ENODEV; + + ret = -EINVAL; + + spin_lock_bh(&eql->queue.lock); + if (eql_is_slave(slave_dev)) { + slave = __eql_find_slave_dev(&eql->queue, slave_dev); + if (slave) { + sc.priority = slave->priority; + ret = 0; + } + } + spin_unlock_bh(&eql->queue.lock); + + if (!ret && copy_to_user(scp, &sc, sizeof (slave_config_t))) + ret = -EFAULT; + + return ret; +} + +static int eql_s_slave_cfg(struct net_device *dev, slave_config_t __user *scp) +{ + slave_t *slave; + equalizer_t *eql; + struct net_device *slave_dev; + slave_config_t sc; + int ret; + + if (copy_from_user(&sc, scp, sizeof (slave_config_t))) + return -EFAULT; + + slave_dev = __dev_get_by_name(&init_net, sc.slave_name); + if (!slave_dev) + return -ENODEV; + + ret = -EINVAL; + + eql = netdev_priv(dev); + spin_lock_bh(&eql->queue.lock); + if (eql_is_slave(slave_dev)) { + slave = __eql_find_slave_dev(&eql->queue, slave_dev); + if (slave) { + slave->priority = sc.priority; + slave->priority_bps = sc.priority; + slave->priority_Bps = sc.priority / 8; + ret = 0; + } + } + spin_unlock_bh(&eql->queue.lock); + + return ret; +} + +static int eql_g_master_cfg(struct net_device *dev, master_config_t __user *mcp) +{ + equalizer_t *eql; + master_config_t mc; + + memset(&mc, 0, sizeof(master_config_t)); + + if (eql_is_master(dev)) { + eql = netdev_priv(dev); + mc.max_slaves = eql->max_slaves; + mc.min_slaves = eql->min_slaves; + if (copy_to_user(mcp, &mc, sizeof (master_config_t))) + return -EFAULT; + return 0; + } + return -EINVAL; +} + +static int eql_s_master_cfg(struct net_device *dev, master_config_t __user *mcp) +{ + equalizer_t *eql; + master_config_t mc; + + if (copy_from_user(&mc, mcp, sizeof (master_config_t))) + return -EFAULT; + + if (eql_is_master(dev)) { + eql = netdev_priv(dev); + eql->max_slaves = mc.max_slaves; + eql->min_slaves = mc.min_slaves; + return 0; + } + return -EINVAL; +} + +static struct net_device *dev_eql; + +static int __init eql_init_module(void) +{ + int err; + + pr_info("%s\n", version); + + dev_eql = alloc_netdev(sizeof(equalizer_t), "eql", NET_NAME_UNKNOWN, + eql_setup); + if (!dev_eql) + return -ENOMEM; + + err = register_netdev(dev_eql); + if (err) + free_netdev(dev_eql); + return err; +} + +static void __exit eql_cleanup_module(void) +{ + unregister_netdev(dev_eql); + free_netdev(dev_eql); +} + +module_init(eql_init_module); +module_exit(eql_cleanup_module); +MODULE_LICENSE("GPL"); -- cgit v1.2.3