summaryrefslogtreecommitdiffstats
path: root/drivers/net/eql.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2026-09-13 12:27:00 -0700
committerLinus Torvalds <torvalds@linux-foundation.org>2026-09-13 12:27:00 -0700
commit22098763a10d9c1340827fcf6edab66f153b27f0 (patch)
tree3962f95a34df034652ff93686cdd156c7197f2d9 /drivers/net/eql.c
downloadlinux-stable-22098763a10d9c1340827fcf6edab66f153b27f0.tar.gz
linux-stable-22098763a10d9c1340827fcf6edab66f153b27f0.zip
Merge tag 'trace-v7.3-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-tracegrafted
Pull tracing fixes from Steven Rostedt: - Don't destroy user event fields when removal fails User event fields are destroyed before the event is removed from visibility. But that can fail leaving the still visible event with no fields. Move the destroying of the fields to after the event is successfully removed from visibility. - Initialize function graph state is fork before calling copy_exec_state() For non-CLONE_VM forks, copy_exec_state() allocates a new task_exec_state. If that allocation fails, ftrace_graph_exit_task() will free the tasks ret_stack pointer. Since that pointer is still using the parent's ret_stack, it mistakenly frees the parent's pointer too. Call ftrace_graph_init() on the task first which will NULL out the new tasks's ret_stack and if the copy fails, it will not free anything. - Remove FGRAPH_MAX_INDEX The macro FGRAPH_MAX_INDEX was added but never used. Remove it. - Save ent_size in function graph printing of nested functions The function graph tracer needs to look at the next event to see if the next event is the return of the current function entry. If it is, it prints a single line: ktime_get(); Otherwise it prints it like a nested function: tick_nohz_irq_exit() { ktime_get(); kcpustat_irq_exit(); } In order to look at the next event, it must save the current event so that it has the information to print from it. It saves the event in the iterator descriptor called "ent". What it doesn't save is the ent_size of the event which is now used to know if the function graph arguments are to be printed. The peek doesn't save the size so the size used happens to be that of the size of the last event that was seen. Save the entry event size in the iterator descriptor so that the correct size is used. - Fix several errors with freeing data in the histogram code The histogram code had a lot of leaked or or incorrect accounting when failures happen. Correct them. - Fix histogram regression of .percent and .graph modifiers Up until 6.3 histogram values could have "percent" or "graph" modifiers that changed how they were printed. But a change that added restricting histograms values from being strings, stack traces and other modifiers inadvertently prevented them from using the percent and graph modifiers, which were legal use cases for values. Put back the percent and graph modifiers. - Fix various typos in the comments - Set the trace_clock before initializing a histogram with clock argument The histogram API allows the user to specific which trace clock to use via a "clock=" string. The histogram is set up first before the clock is checked. If the passed in clock is not valid, it exits without fully fixing up the histogram leaving it on the list and a use-after-free can trigger. Update the clock argument first and if it fails then exit gracefully before the histogram trigger is placed on any lists. - Restore :mod: trailer after parsing in ftrace_set_clr_event The function ftrace_set_clr_event() modifies the parse string and needs to put it back to what was passed in. It searches for ":mod:" via a strsep() but fails to put back the first ':' in the string. Add back the ':' in the passed in string. - Take trace_array reference when opening a tracer options file The options files are dynamically created and some tracers add their own options. When a tracer adds their own list of options, the trace_array holding them has an array to hold the list of options for each tracer. This array increases in size via a krealloc(), and the new entry gets a newly allocated array to hold the options of the new tracer being added. The element in each entry of the tracer's option array holds a pointer back to the trace_array, a pointer to the tracer it is associated to, a pointer to the flags of the option. The issue is that these arrays are freed when the trace_array is freed when its instance it represents is removed from the instances directory. There's a race that an open of one of these options files can happen when the instance is being removed. Add a new helper function to be called by the open function of the options file to iterate all existing trace_arrays under a lock and find the one that has the given option element in one of it's tracer arrays. If found, then update the associated trace_array's reference counter to keep it from being freed. If not found, have the open call return -ENODEV. - Disable interrupts when acquiring the lock in rb_wake_up_waiters() The function rb_wake_up_waiters() assumes it will be called in interrupt context and does not disable irqs when taking cpu_buffer->reader_lock, which can be called in hard interrupt context. The issue is in PREEMPT_RT, this function is called in thread context leaving this lock open to a deadlock. Take the lock with interrupts disabled. - Use rcu_assign_pointer() for tmp_ops filter hash The tmp_ops used in update_ftrace_direct_mod() assigns its filter_hash field directly, but that field is annotated as __rcu and sparse complains. Assign it with rcu_assign_pointer() - Fix use-after-free in enable_trigger_private_data_free() The trace_event_call is accessed through the event_trigger_data's trace_event_file pointer to put the trace_event_call on freeing. The issue is that the trace_event_file data may have been freed already causing a use-after-free. Add a field to the event_trigger_data that points directly to the trace_event_call so that it can decrement its reference directly without needing to go through the trace_event_file. - Fix accounting of buffer data remote headers trace_buffer_desc_size() and trace_remote_alloc_buffer() undercount the number of pages is needed for the asked for size as it doesn't take into account the meta data on each page. Add a helper function to do the calculation properly and use that in these functions. - Catch nr_page_va overflow in ring_buffer_desc sizing The number of pages per remote ring buffer is capped by ring_buffer_desc::nr_page_va (32 bits). A buffer_size large enough to overflow that field would silently allocate a descriptor smaller than what was asked for. - Do not resize the subbuf order if any per_cpu buffer is disabled The mmapping of ring buffers disables resizing the subbuffers, but it is done per-cpu whereas the subbuf size change is done for all the per_cpu buffers under the buffer->mutex. It could change the size of some while the mapping is happening on others. Have the resize of the subbuf order check all the per_cpu buffers under the lock to see if any of them is disabled before starting and causing an inconsistency between buffers that are being mapped. * tag 'trace-v7.3-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace: (25 commits) ring-buffer: Check resize_disabled before publishing the new subbuf order tracing/remotes: Catch nr_page_va overflow in ring_buffer_desc sizing tracing/remotes: Account for ring buffer page header in size calculation tracing: Don't dereference trace_event_file in deferred trigger free ftrace: Use rcu_assign_pointer() for tmp_ops filter hash ring-buffer: Acquire the lock with irqsave in rb_wake_up_waiters() tracing: Take trace_array reference when opening a tracer options file tracing: Fix ring_buffer_read_page_size() kernel-doc tracing: Restore :mod: trailer after parsing in ftrace_set_clr_event() tracing: Fix memory corruption from a "STACKTRACE" histogram key tracing: Fix memory corruption from the histogram stacktrace modifier tracing: Undo the registration when enabling the histogram trigger fails tracing: Take the reference before publishing the named histogram trigger tracing: Set the trace clock before registering the histogram trigger tracing: Fix typo "preceeded" in comment tracing: Fix typo "availabe" in comment tracing: Let histogram values keep the percent and graph modifiers tracing: Keep the entry count when the histogram stats allocation fails tracing: Free histogram the field rejected for a bad modifier tracing: Free histogram the var ref when its initialization fails ...
Diffstat (limited to 'drivers/net/eql.c')
-rw-r--r--drivers/net/eql.c611
1 files changed, 611 insertions, 0 deletions
diff --git a/drivers/net/eql.c b/drivers/net/eql.c
new file mode 100644
index 000000000..06083b984
--- /dev/null
+++ b/drivers/net/eql.c
@@ -0,0 +1,611 @@
+/*
+ * 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 <linux/compat.h>
+#include <linux/capability.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/timer.h>
+#include <linux/netdevice.h>
+#include <net/net_namespace.h>
+
+#include <linux/if.h>
+#include <linux/if_arp.h>
+#include <linux/if_eql.h>
+#include <linux/pkt_sched.h>
+
+#include <linux/uaccess.h>
+
+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 = timer_container_of(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...
+ */
+
+ timer_delete_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_obj(*s);
+ 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_DESCRIPTION("Equalizer Load-balancer for serial network interfaces");
+MODULE_LICENSE("GPL");