* Re: [PATCH RFC 0/8] LLDP implementation for Linux
From: John Fastabend @ 2012-06-25 19:00 UTC (permalink / raw)
To: Eldad Zack; +Cc: netdev
In-Reply-To: <1340648900-6547-1-git-send-email-eldad@fogrefinery.com>
On 6/25/2012 11:28 AM, Eldad Zack wrote:
> Hi all,
>
> This series of patches provides a partial LLDP (IEEE Std 802.1ab)
> implementation.
>
> I'd really appreciate a review of it.
>
> LLDP is a simple discovery protocol which advertises the identification and
> other info (such as MTU or capabilities) of device on the link. It can also
> help debug misconfigurations on the link layer (wrong MTU, wrong VLAN).
>
Why do you want to implement this in the kernel? We've been doing this
in user space for sometime without any issues and has some noted
advantages. Reduces kernel bloat, easier to add extend, etc.
Take a look at
http://www.open-lldp.org/open-lldp
What are we missing? Can we address any deficiencies here rather than
embedded this into the kernel.
> Some notes/questions:
>
> * Applies against net-next and mainline.
>
> * Included in this series is only LLDP output code.
> This is not an issue since input and output are decoupled in LLDP anyway.
> I'm working on the input code as well and will post it at some point in the
> future.
>
> * Sysctl is used to do (some) configuration. This is done globally right now.
> Before I add per-device sysctls: is it at all appropriate to use sysctl
> here?
No, netlink is much nicer for these types of things. User space
can register for events and stay in sync and also all the other
relevant events are using netlink UP/DOWN/DORMANT events for
example.
>
> * By default, transmission is suppressed. To arm it, set
> /proc/sys/net/lldp/lldp_op_mode
> to 1.
>
> * I've tested it on x86_64 and (qemu'd) x86.
>
> * I've tested it on my machine and it works with Ethernet and WLAN.
>
> * The last patch ("8021q/vlan: process NETDEV_GOING_DOWN") is needed
> to be able to send shutdown PDU on VLAN interfaces, but has otherwise
> no effect.
>
Do this in user space and you can handle all these events without
changing existing infrastructure.
> * Is there a better way to deal with 16-bit endianness other than masking and
> shifting, when one field is more than a byte long (in this case 7/9)?
>
> * I usually only work on it on weekends, so I might be slow in responding back.
Please consider user space implementations (you don't have to use
mine) or let us know why we _need_ this in the kernel.
>
> Thanks in advance if you're taking the time to review it or test it!
>
I'll scan the patches shortly.
Thanks,
John
^ permalink raw reply
* Re: [PATCH RFC 0/8] LLDP implementation for Linux
From: Stephen Hemminger @ 2012-06-25 18:54 UTC (permalink / raw)
To: Eldad Zack; +Cc: netdev
In-Reply-To: <1340648900-6547-1-git-send-email-eldad@fogrefinery.com>
Since LLDP is a control protocol what is wrong with the existing
implementation in userspace?
https://github.com/vincentbernat/lldpd/wiki
^ permalink raw reply
* Re: [PATCH 1/8] if_ether.h: Add LLDP ethertype
From: Eldad Zack @ 2012-06-25 18:48 UTC (permalink / raw)
To: netdev
In-Reply-To: <1340648900-6547-2-git-send-email-eldad@fogrefinery.com>
On Mon, 25 Jun 2012, Eldad Zack wrote:
> The LLDP ethertype is defined in IEEE Std 802.1ab (2005), clause 8.3.
>
> Signed-off-by: Eldad Zack <eldad@fogrefinery.com>
I'll reiterate here, since the previous mail won't show up on patchwork:
I just noticed that I didn't change the subject on the following
patches to PATCH RFC -- Sorry for the inconvenience!
Eldad
^ permalink raw reply
* Re: [RFC net-next (v2) 12/14] ixgbe: set maximal number of default RSS queues
From: Ben Hutchings @ 2012-06-25 18:44 UTC (permalink / raw)
To: Alexander Duyck
Cc: eilong, Yuval Mintz, davem, netdev, Jeff Kirsher, John Fastabend
In-Reply-To: <4FE8B019.4030807@intel.com>
On Mon, 2012-06-25 at 11:38 -0700, Alexander Duyck wrote:
> On 06/25/2012 10:53 AM, Eilon Greenstein wrote:
> > On Mon, 2012-06-25 at 08:44 -0700, Alexander Duyck wrote:
> >> This doesn't limit queues, only interrupt vectors. As I told you before
> >> you should look at the ixgbe_set_rss_queues function if you actually
> >> want to limit the number of RSS queues.
> > How about this:
> > diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_lib.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_lib.c
> > index af1a531..23a8609 100644
> > --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_lib.c
> > +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_lib.c
> > @@ -277,6 +277,8 @@ static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter)
> > bool ret = false;
> > struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_RSS];
> >
> > + f->indices = min_t(int, netif_get_num_default_rss_queues(), f->indices);
> > +
> > if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
> > f->mask = 0xF;
> > adapter->num_rx_queues = f->indices;
> > @@ -302,7 +304,9 @@ static inline bool ixgbe_set_fdir_queues(struct ixgbe_adapter *adapter)
> > bool ret = false;
> > struct ixgbe_ring_feature *f_fdir = &adapter->ring_feature[RING_F_FDIR];
> >
> > - f_fdir->indices = min_t(int, num_online_cpus(), f_fdir->indices);
> > + f_fdir->indices = min_t(int, netif_get_num_default_rss_queues(),
> > + f_fdir->indices);
> > +
> > f_fdir->mask = 0;
> >
> > /*
> > @@ -339,8 +343,7 @@ static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter *adapter)
> > if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
> > return false;
> >
> > - f->indices = min_t(int, num_online_cpus(), f->indices);
> > -
> > + f->indices = min_t(int, f->indices, netif_get_num_default_rss_queues());
> > adapter->num_rx_queues = 1;
> > adapter->num_tx_queues = 1;
> >
> This makes much more sense, but still needs a few minor changes. The
> first change I would recommend is to not alter ixgbe_set_fdir_queues
> since that controls flow director queues, not RSS queues. The second
> would be to update ixgbe_set_dcb_queues since that does RSS per DCB
> traffic class and will also need to be updated.
There is a difference between the stated aim (reduce memory allocated
for RX buffers) and this implementation (limit number of RSS queues
only). If we agree on that aim then we should be limiting the total
number of RX queues.
Ben.
--
Ben Hutchings, Staff Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
^ permalink raw reply
* RE: [RFC net-next (v2) 11/14] igb: set maximal number of default RSS queues
From: Ben Hutchings @ 2012-06-25 18:38 UTC (permalink / raw)
To: Vick, Matthew
Cc: Yuval Mintz, davem@davemloft.net, netdev@vger.kernel.org,
eilong@broadcom.com, Kirsher, Jeffrey T
In-Reply-To: <06DFBC1E25D8024DB214DC7F41A3CD3448870CE4@ORSMSX101.amr.corp.intel.com>
On Mon, 2012-06-25 at 17:31 +0000, Vick, Matthew wrote:
> > -----Original Message-----
> > From: netdev-owner@vger.kernel.org [mailto:netdev-
> > owner@vger.kernel.org] On Behalf Of Yuval Mintz
> > Sent: Monday, June 25, 2012 4:46 AM
> > To: davem@davemloft.net; netdev@vger.kernel.org
> > Cc: eilong@broadcom.com; Yuval Mintz; Kirsher, Jeffrey T
> > Subject: [RFC net-next (v2) 11/14] igb: set maximal number of default
> > RSS queues
> >
> > Signed-off-by: Yuval Mintz <yuvalmin@broadcom.com>
> > Signed-off-by: Eilon Greenstein <eilong@broadcom.com>
> >
> > Cc: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
> > ---
> > drivers/net/ethernet/intel/igb/igb_main.c | 3 ++-
> > 1 files changed, 2 insertions(+), 1 deletions(-)
> >
> > diff --git a/drivers/net/ethernet/intel/igb/igb_main.c
> > b/drivers/net/ethernet/intel/igb/igb_main.c
> > index 01ced68..b11ee60 100644
> > --- a/drivers/net/ethernet/intel/igb/igb_main.c
> > +++ b/drivers/net/ethernet/intel/igb/igb_main.c
> > @@ -2465,7 +2465,8 @@ static int __devinit igb_sw_init(struct
> > igb_adapter *adapter)
> > break;
> > }
> >
> > - adapter->rss_queues = min_t(u32, max_rss_queues,
> > num_online_cpus());
> > + adapter->rss_queues = min_t(u32, max_rss_queues,
> > + netif_get_num_default_rss_queues());
> >
> > /* Determine if we need to pair queues. */
> > switch (hw->mac.type) {
> > --
> > 1.7.9.rc2
>
> Since igb supports a maximum of 8 RSS queues anyway, it's generally
> unaffected by this change.
I'm interested in providing a global configuration mechanism for this,
which is why I asked Yuval to introduce this function.
> That being said, I'm confused about what you're trying to
> accomplish--is it to standardize the number of RSS queues or limit the
> number of interrupts by default? Or is it the former with a hope that
> it will trickle down to the latter?
>
> For example, if you take an igb device that supports 8 RSS queues
> (say, I350) and you change the default to 4 RSS queues, you will end
> up with the same number of interrupt vectors being requested as we
> will disable queue pairing and request separate vectors for Rx/Tx
> queues. I haven't looked at the other drivers affected by this RFC,
> but it's possible other drivers behave the same way.
sfc also supports those two modes, but under control of a module
parameter. If it's a common enough feature then perhaps it should also
be subject to global configuration (though that might be confusing if
most drivers continue to support only one mode).
Ben.
--
Ben Hutchings, Staff Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
^ permalink raw reply
* Re: [RFC net-next (v2) 12/14] ixgbe: set maximal number of default RSS queues
From: Alexander Duyck @ 2012-06-25 18:38 UTC (permalink / raw)
To: eilong; +Cc: Yuval Mintz, davem, netdev, Jeff Kirsher, John Fastabend
In-Reply-To: <1340646818.2486.27.camel@lb-tlvb-eilong.il.broadcom.com>
On 06/25/2012 10:53 AM, Eilon Greenstein wrote:
> On Mon, 2012-06-25 at 08:44 -0700, Alexander Duyck wrote:
>> This doesn't limit queues, only interrupt vectors. As I told you before
>> you should look at the ixgbe_set_rss_queues function if you actually
>> want to limit the number of RSS queues.
> How about this:
> diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_lib.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_lib.c
> index af1a531..23a8609 100644
> --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_lib.c
> +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_lib.c
> @@ -277,6 +277,8 @@ static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter)
> bool ret = false;
> struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_RSS];
>
> + f->indices = min_t(int, netif_get_num_default_rss_queues(), f->indices);
> +
> if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
> f->mask = 0xF;
> adapter->num_rx_queues = f->indices;
> @@ -302,7 +304,9 @@ static inline bool ixgbe_set_fdir_queues(struct ixgbe_adapter *adapter)
> bool ret = false;
> struct ixgbe_ring_feature *f_fdir = &adapter->ring_feature[RING_F_FDIR];
>
> - f_fdir->indices = min_t(int, num_online_cpus(), f_fdir->indices);
> + f_fdir->indices = min_t(int, netif_get_num_default_rss_queues(),
> + f_fdir->indices);
> +
> f_fdir->mask = 0;
>
> /*
> @@ -339,8 +343,7 @@ static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter *adapter)
> if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
> return false;
>
> - f->indices = min_t(int, num_online_cpus(), f->indices);
> -
> + f->indices = min_t(int, f->indices, netif_get_num_default_rss_queues());
> adapter->num_rx_queues = 1;
> adapter->num_tx_queues = 1;
>
This makes much more sense, but still needs a few minor changes. The
first change I would recommend is to not alter ixgbe_set_fdir_queues
since that controls flow director queues, not RSS queues. The second
would be to update ixgbe_set_dcb_queues since that does RSS per DCB
traffic class and will also need to be updated.
Thanks,
Alex
^ permalink raw reply
* Re: [PATCH RFC 0/8] LLDP implementation for Linux
From: Eldad Zack @ 2012-06-25 18:33 UTC (permalink / raw)
To: netdev
In-Reply-To: <1340648900-6547-1-git-send-email-eldad@fogrefinery.com>
On Mon, 25 Jun 2012, Eldad Zack wrote:
> Hi all,
>
> This series of patches provides a partial LLDP (IEEE Std 802.1ab)
> implementation.
>
I just noticed that I didn't change the subject on the following
patches to PATCH RFC -- Sorry for the inconvenience!
Eldad
^ permalink raw reply
* [PATCH 8/8] 8021q/vlan: process NETDEV_GOING_DOWN
From: Eldad Zack @ 2012-06-25 18:28 UTC (permalink / raw)
To: netdev; +Cc: Eldad Zack
In-Reply-To: <1340648900-6547-1-git-send-email-eldad@fogrefinery.com>
In the current flow, when you take down a physical device that has
VLANs configured on it, the NETDEV_GOING_DOWN notification will be
sent too late, i.e., no data can be sent to the wire anymore.
static int __dev_close_many(struct list_head *head)
{
...
list_for_each_entry(dev, head, unreg_list) {
call_netdevice_notifiers(NETDEV_GOING_DOWN, dev);
...
}
...
list_for_each_entry(dev, head, unreg_list) {
if (ops->ndo_stop)
ops->ndo_stop(dev);
}
...
}
static int dev_close_many(struct list_head *head)
{
...
__dev_close_many(head);
list_for_each_entry(dev, head, unreg_list) {
rtmsg_ifinfo(RTM_NEWLINK, dev, IFF_UP|IFF_RUNNING);
call_netdevice_notifiers(NETDEV_DOWN, dev);
}
}
In a setup like this: eth0 with VLANs 2, 3 the flow would be:
eth0 - NETDEV_GOING_DOWN
ndo_stop is called on the device
eth0.2 - NETDEV_GOING_DOWN
eth0.2 - NETDEV_DOWN
eth0.3 - NETDEV_GOING_DOWN
eth0.3 - NETDEV_DOWN
eth0 - NETDEV_DOWN
If instead NETDEV_GOING_DOWN is processed, the flow would be:
eth0.2 - NETDEV_GOING_DOWN
eth0.2 - NETDEV_DOWN
eth0.3 - NETDEV_GOING_DOWN
eth0.3 - NETDEV_DOWN
eth0 - NETDEV_GOING_DOWN
eth0 - NETDEV_DOWN
ndo_stop is called on the device
Signed-off-by: Eldad Zack <eldad@fogrefinery.com>
---
net/8021q/vlan.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
index 6089f0c..fd87ecc 100644
--- a/net/8021q/vlan.c
+++ b/net/8021q/vlan.c
@@ -402,6 +402,12 @@ static int vlan_device_event(struct notifier_block *unused, unsigned long event,
break;
+ case NETDEV_GOING_DOWN: /* NETDEV_DOWN */
+ /* If the parent device is going down it will call ndo_stop after
+ * it sends out NETDEV_GOING_DOWN but before sending out NETDEV_DOWN,
+ * The effect of which is, that no data can be sent anymore
+ * by the time the VLAN device sends out its NETDEV_GOING_DOWN.
+ */
case NETDEV_DOWN:
/* Put all VLANs for this dev in the down state too. */
for (i = 0; i < VLAN_N_VID; i++) {
--
1.7.10
^ permalink raw reply related
* [PATCH 7/8] LLDP: Kconfig and Makefile
From: Eldad Zack @ 2012-06-25 18:28 UTC (permalink / raw)
To: netdev; +Cc: Eldad Zack
In-Reply-To: <1340648900-6547-1-git-send-email-eldad@fogrefinery.com>
Adds Kconfig and Makefile for LLDP, and sources these in
net/Makefile and net/Kconfig.
Signed-off-by: Eldad Zack <eldad@fogrefinery.com>
---
net/Kconfig | 1 +
net/Makefile | 1 +
net/lldp/Kconfig | 21 +++++++++++++++++++++
net/lldp/Makefile | 7 +++++++
4 files changed, 30 insertions(+)
create mode 100644 net/lldp/Kconfig
create mode 100644 net/lldp/Makefile
diff --git a/net/Kconfig b/net/Kconfig
index 245831b..cb724f2 100644
--- a/net/Kconfig
+++ b/net/Kconfig
@@ -216,6 +216,7 @@ source "net/dcb/Kconfig"
source "net/dns_resolver/Kconfig"
source "net/batman-adv/Kconfig"
source "net/openvswitch/Kconfig"
+source "net/lldp/Kconfig"
config RPS
boolean
diff --git a/net/Makefile b/net/Makefile
index 4f4ee08..39fbb8b 100644
--- a/net/Makefile
+++ b/net/Makefile
@@ -70,3 +70,4 @@ obj-$(CONFIG_CEPH_LIB) += ceph/
obj-$(CONFIG_BATMAN_ADV) += batman-adv/
obj-$(CONFIG_NFC) += nfc/
obj-$(CONFIG_OPENVSWITCH) += openvswitch/
+obj-$(CONFIG_LLDP) += lldp/
diff --git a/net/lldp/Kconfig b/net/lldp/Kconfig
new file mode 100644
index 0000000..0c59fbf
--- /dev/null
+++ b/net/lldp/Kconfig
@@ -0,0 +1,21 @@
+#
+# Link Layer Discovery Protocol (LLDP)
+# IEEE Std 802.1ab
+#
+
+config LLDP
+ tristate "Link Layer Discovery Protocol (LLDP) Support"
+ depends on EXPERIMENTAL
+ default n
+ ---help---
+ Enables experimental support for the LLDP protocol described in
+ IEEE Std 802.1ab.
+
+ The LLDP protocol allows nodes to advertise their identification,
+ configuration and capabilities to neighbors on the same link.
+ Currently, only advertisement is implemented.
+
+ To compile this code as a module, choose M here: the
+ module will be called lldp.
+
+ If unsure say N.
diff --git a/net/lldp/Makefile b/net/lldp/Makefile
new file mode 100644
index 0000000..e3c609f
--- /dev/null
+++ b/net/lldp/Makefile
@@ -0,0 +1,7 @@
+#
+# Makefile for the Linux Link Layer Discovery Protocol (LLDP) implementation.
+#
+
+obj-$(CONFIG_LLDP) += lldp.o
+
+lldp-objs := lldp_core.o lldp_output.o lldpdu.o sysctl_net_lldp.o
--
1.7.10
^ permalink raw reply related
* [PATCH 6/8] LLDP: Core routines
From: Eldad Zack @ 2012-06-25 18:28 UTC (permalink / raw)
To: netdev; +Cc: Eldad Zack
In-Reply-To: <1340648900-6547-1-git-send-email-eldad@fogrefinery.com>
* Core LLDP routines: handles modules registration,
netdevice notifications and timers.
* Adds specific data pointer to netdevice.
Signed-off-by: Eldad Zack <eldad@fogrefinery.com>
---
include/linux/netdevice.h | 4 +
net/lldp/lldp_core.c | 214 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 218 insertions(+)
create mode 100644 net/lldp/lldp_core.c
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index d94cb14..813475a 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -61,6 +61,7 @@ struct device;
struct phy_device;
/* 802.11 specific */
struct wireless_dev;
+struct lldp_ptr;
/* source back-compat hooks */
#define SET_ETHTOOL_OPS(netdev,ops) \
( (netdev)->ethtool_ops = (ops) )
@@ -1158,6 +1159,9 @@ struct net_device {
void *ax25_ptr; /* AX.25 specific data */
struct wireless_dev *ieee80211_ptr; /* IEEE 802.11 specific data,
assign before registering */
+#if IS_ENABLED(CONFIG_LLDP)
+ struct lldp_dev __rcu *lldp_ptr; /* LLDP specific data */
+#endif
/*
* Cache lines mostly used on receive path (including eth_type_trans())
diff --git a/net/lldp/lldp_core.c b/net/lldp/lldp_core.c
new file mode 100644
index 0000000..3d4a1f1
--- /dev/null
+++ b/net/lldp/lldp_core.c
@@ -0,0 +1,214 @@
+/* LLDP Link Layer Discovery Protocol impementation for Linux
+ * IEEE Std 802.1ab
+ *
+ * Author: Eldad Zack <eldad@fogrefinery.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+#define pr_fmt(fmt) "LLDP " fmt
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/timer.h>
+#include <linux/if_ether.h>
+#include <linux/etherdevice.h>
+#include <linux/if_arp.h>
+#include <linux/netdevice.h>
+#include <linux/skbuff.h>
+#include "lldp.h"
+
+int sysctl_lldp_operational_mode = LLDP_SYSCTL_OP_SUPPRESS;
+int sysctl_lldp_transmit_interval = LLDP_DEFAULT_MSG_TX_INTERVAL;
+int sysctl_lldp_hold_multiplier = LLDP_DEFAULT_MSG_TX_HOLD_MULT;
+
+bool is_valid_lldp_dev(struct net_device *dev)
+{
+ bool ret;
+
+ if (!is_valid_ether_addr(dev->dev_addr))
+ return false;
+
+ ret = (!(dev->flags & IFF_LOOPBACK) &&
+ (dev->type == ARPHRD_ETHER) &&
+ (dev->addr_len == ETH_ALEN));
+
+ return ret;
+}
+
+int init_lldp_dev_info(struct net_device *dev)
+{
+ struct lldp_dev *ldev;
+
+ if (dev == NULL)
+ return -EINVAL;
+
+ if (dev->lldp_ptr != NULL)
+ return 0;
+
+ ldev = kzalloc(sizeof(struct lldp_dev), GFP_ATOMIC);
+ if (ldev == NULL)
+ return -ENOMEM;
+
+ rcu_read_lock();
+ dev->lldp_ptr = ldev;
+ rcu_read_unlock();
+
+ return 0;
+}
+
+void lldp_timer_handler(unsigned long data)
+{
+ struct net_device *dev = (struct net_device *) data;
+ struct lldp_dev *ldev;
+ struct timer_list *tx_timer;
+
+ BUG_ON(dev == NULL);
+
+ rcu_read_lock();
+ if (dev->lldp_ptr == NULL) { /* device went down */
+ rcu_read_unlock();
+ return;
+ }
+
+ ldev = dev->lldp_ptr;
+ tx_timer = ldev->tx_timer;
+
+ if (sysctl_lldp_operational_mode & LLDP_SYSCTL_OP_TX)
+ lldp_send(dev);
+
+ mod_timer(tx_timer, jiffies +
+ msecs_to_jiffies(1000 * sysctl_lldp_transmit_interval));
+ rcu_read_unlock();
+}
+
+void lldp_add_dev(struct net_device *dev)
+{
+ int err;
+ struct lldp_dev *ldev;
+ struct timer_list *tx_timer;
+
+ err = init_lldp_dev_info(dev);
+ if (err < 0) {
+ pr_err("could not start on device %s (%d)\n", dev->name, err);
+ return;
+ }
+
+ rcu_read_lock();
+ ldev = dev->lldp_ptr;
+ rcu_read_unlock();
+
+ if (ldev->tx_timer != NULL)
+ return;
+
+ tx_timer = kzalloc(sizeof(struct timer_list), GFP_ATOMIC);
+ if (tx_timer == NULL) {
+ pr_err("no memory available (device %s)\n", dev->name);
+ return;
+ }
+
+ setup_timer(tx_timer, lldp_timer_handler, (unsigned long) dev);
+
+ rcu_read_lock();
+ ldev->tx_timer = tx_timer;
+ rcu_read_unlock();
+
+ /* Send the first frame without waiting. The timer handler
+ * will schedule it.
+ */
+ lldp_timer_handler((unsigned long) dev);
+
+ pr_info("started on device %s\n", dev->name);
+}
+
+static void lldp_del_dev(struct net_device *dev)
+{
+ struct lldp_dev *ldev;
+ struct timer_list *tx_timer;
+
+ if (dev == NULL)
+ return;
+
+ rcu_read_lock();
+ ldev = (struct lldp_dev *)dev->lldp_ptr;
+ if (ldev == NULL) {
+ rcu_read_unlock();
+ return;
+ }
+
+ tx_timer = ldev->tx_timer;
+ if (tx_timer != NULL) {
+ ldev->tx_timer = NULL;
+ del_timer(tx_timer);
+ kfree(tx_timer);
+ }
+
+ dev->lldp_ptr = NULL;
+ kfree(ldev);
+ rcu_read_unlock();
+
+ pr_info("stopped on device %s\n", dev->name);
+}
+
+static int lldp_notify(struct notifier_block *nb, unsigned long event,
+ void *data)
+{
+ struct net_device *dev = (struct net_device *) data;
+
+ if (dev == NULL)
+ return NOTIFY_DONE;
+
+ if (!is_valid_lldp_dev(dev))
+ return NOTIFY_DONE;
+
+ switch (event) {
+ case NETDEV_UP: /* NETDEV_CHANGE */
+ case NETDEV_CHANGE:
+ lldp_add_dev(dev);
+ break;
+ case NETDEV_GOING_DOWN:
+ /* Shutdown PDU, Clause 10.2.1.2 */
+ lldp_send_shutdown(dev);
+ break;
+ case NETDEV_UNREGISTER: /* NETDEV_DOWN */
+ case NETDEV_DOWN:
+ lldp_del_dev(dev);
+ break;
+ }
+
+ return NOTIFY_OK;
+};
+
+static struct notifier_block lldp_dev_notify = {
+ .notifier_call = lldp_notify,
+};
+
+static int __init lldp_init(void)
+{
+ pr_info("module initializing\n");
+
+ register_netdevice_notifier(&lldp_dev_notify);
+ lldp_register_sysctl();
+ return 0;
+}
+
+static void __exit lldp_fini(void)
+{
+ struct net_device *dev;
+
+ lldp_unregister_sysctl();
+ unregister_netdevice_notifier(&lldp_dev_notify);
+
+ for_each_netdev(&init_net, dev)
+ lldp_del_dev(dev);
+
+ pr_info("module stopped\n");
+}
+
+module_init(lldp_init);
+module_exit(lldp_fini);
+
+MODULE_LICENSE("GPL");
--
1.7.10
^ permalink raw reply related
* [PATCH 5/8] LLDP: Output routines
From: Eldad Zack @ 2012-06-25 18:28 UTC (permalink / raw)
To: netdev; +Cc: Eldad Zack
In-Reply-To: <1340648900-6547-1-git-send-email-eldad@fogrefinery.com>
Handles the transmission of LLDPDUs.
Gets the TLV list, allocates the sk_buff according to the
space requirements of the TLV list, writes it to the sk_buff and
if all goes well, sends it to the wire.
Signed-off-by: Eldad Zack <eldad@fogrefinery.com>
---
net/lldp/lldp_output.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 67 insertions(+)
create mode 100644 net/lldp/lldp_output.c
diff --git a/net/lldp/lldp_output.c b/net/lldp/lldp_output.c
new file mode 100644
index 0000000..45e6293
--- /dev/null
+++ b/net/lldp/lldp_output.c
@@ -0,0 +1,67 @@
+/* LLDP Link Layer Discovery Protocol impementation for Linux
+ * IEEE Std 802.1ab
+ *
+ * Author: Eldad Zack <eldad@fogrefinery.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/if_ether.h>
+#include <linux/netdevice.h>
+#include <linux/skbuff.h>
+#include "lldp.h"
+
+static u8 lldp_dst_address[] = LLDP_MULTICAST_ADDR;
+
+inline struct sk_buff *lldp_create(struct net_device *dev, bool is_shutdown)
+{
+ struct sk_buff *skb;
+ struct list_head head;
+ int head_len = LL_RESERVED_SPACE(dev);
+ int tail_len = dev->needed_tailroom;
+ int lldp_len;
+
+ INIT_LIST_HEAD(&head);
+
+ lldp_tlv_construct_list(&head, dev, is_shutdown);
+ lldp_len = lldp_tlv_list_len(&head);
+
+ skb = alloc_skb(head_len + lldp_len + tail_len, GFP_ATOMIC);
+ if (skb == NULL)
+ goto done;
+
+ skb_reserve(skb, head_len);
+ skb_reset_network_header(skb);
+
+ lldp_tlv_put_skb_list(skb, &head);
+
+ skb->dev = dev;
+ skb->protocol = htons(ETH_P_LLDP);
+
+ if (dev_hard_header(skb, dev, ETH_P_LLDP, lldp_dst_address,
+ dev->dev_addr, skb->len) < 0) {
+ kfree_skb(skb);
+ skb = NULL;
+ }
+
+done:
+ lldp_tlv_destruct_list(&head);
+ return skb;
+}
+
+void __lldp_send(struct net_device *dev, bool is_shutdown)
+{
+ struct sk_buff *skb;
+
+ skb = lldp_create(dev, is_shutdown);
+
+ if (skb == NULL)
+ return;
+
+ dev_queue_xmit(skb);
+}
--
1.7.10
^ permalink raw reply related
* [PATCH 4/8] LLDP: PDU-handling routines
From: Eldad Zack @ 2012-06-25 18:28 UTC (permalink / raw)
To: netdev; +Cc: Eldad Zack
In-Reply-To: <1340648900-6547-1-git-send-email-eldad@fogrefinery.com>
Routines for creation and parsing of LLPDUs.
Highlights:
* lldp_construct_pdu_list() constructs a list of TLVs
according to device and configuration.
* lldp_tlv_list_len() calculates the space needed to
send the above TLV list to the wire. Used when an sk_buff
is allocated.
* lldp_put_tlv_skb_list() writes the TLV list to the sk_buff.
Signed-off-by: Eldad Zack <eldad@fogrefinery.com>
---
net/lldp/lldpdu.c | 307 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 307 insertions(+)
create mode 100644 net/lldp/lldpdu.c
diff --git a/net/lldp/lldpdu.c b/net/lldp/lldpdu.c
new file mode 100644
index 0000000..e71ddd7
--- /dev/null
+++ b/net/lldp/lldpdu.c
@@ -0,0 +1,307 @@
+/* LLDP Link Layer Discovery Protocol impementation for Linux
+ * IEEE Std 802.1ab
+ *
+ * Author: Eldad Zack <eldad@fogrefinery.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/if_ether.h>
+#include <linux/if_vlan.h>
+#include <linux/netdevice.h>
+#include <linux/skbuff.h>
+#include <linux/utsname.h>
+#include "lldp.h"
+
+const unsigned char oui_802_1[LLDP_OUI_LEN] = LLDP_OUI_802_1;
+const unsigned char oui_802_3[LLDP_OUI_LEN] = LLDP_OUI_802_3;
+
+int lldp_tlv_list_len(struct list_head *head)
+{
+ struct lldp_tlv *tlv;
+ int len = 0;
+
+ list_for_each_entry(tlv, head, lh)
+ len += tlv->entry_len;
+
+ return len;
+}
+
+void lldp_tlv_calc_entry_len(struct lldp_tlv *tlv)
+{
+ uint16_t elen;
+
+ BUG_ON(tlv == NULL);
+ BUG_ON(tlv->len > LLDP_LEN_MAX);
+
+ elen = 2; /* TLV Header */
+
+ if (tlv->subtype > 0)
+ elen += 1;
+
+ BUG_ON((tlv->oui != NULL) &&
+ (tlv->type != LLDP_TLV_ORGANIZATIONAL));
+ if (tlv->oui != NULL)
+ elen += LLDP_OUI_LEN;
+
+ elen += tlv->len; /* Actual data length */
+
+ tlv->entry_len = elen;
+}
+
+void __lldp_add_tlv_list(struct list_head *head, unsigned short type,
+ unsigned short len, unsigned char *data,
+ unsigned char subtype, const unsigned char *oui)
+{
+ struct lldp_tlv *tlv;
+
+ BUG_ON(len > LLDP_LEN_MAX);
+ BUG_ON(head == NULL);
+
+ tlv = kzalloc(sizeof(struct lldp_tlv), GFP_ATOMIC);
+
+ tlv->type = type;
+ tlv->len = len;
+
+ tlv->val = kmalloc(len, GFP_ATOMIC);
+ memcpy(tlv->val, data, len);
+
+ tlv->subtype = subtype;
+
+ if (type == LLDP_TLV_ORGANIZATIONAL) {
+ BUG_ON(oui == NULL);
+
+ tlv->oui = kmalloc(LLDP_OUI_LEN, GFP_ATOMIC);
+ memcpy(tlv->oui, oui, LLDP_OUI_LEN);
+ }
+
+ lldp_tlv_calc_entry_len(tlv);
+
+ list_add_tail(&(tlv->lh), head);
+}
+
+inline void lldp_add_tlv_list(struct list_head *head, unsigned short type,
+ unsigned short len, unsigned char *data)
+{
+ __lldp_add_tlv_list(head, type, len, data, 0, NULL);
+}
+
+inline void lldp_add_tlv_subtype_list(struct list_head *head,
+ unsigned short type,
+ unsigned short len, unsigned char *data,
+ unsigned char subtype)
+{
+ __lldp_add_tlv_list(head, type, len, data, subtype, NULL);
+}
+
+inline void lldp_add_oui_tlv_list(struct list_head *head,
+ const unsigned char *oui,
+ unsigned short len, unsigned char *data,
+ unsigned char subtype)
+{
+ __lldp_add_tlv_list(head, LLDP_TLV_ORGANIZATIONAL, len, data,
+ subtype, oui);
+}
+
+inline void lldp_add_tlv_chassis_id(struct list_head *head,
+ struct net_device *dev)
+{
+ lldp_add_tlv_subtype_list(head, LLDP_TLV_CHASSIS_ID, ETH_ALEN,
+ dev->dev_addr, LLDP_ST_CHID_MAC_ADDR);
+}
+
+inline void lldp_add_tlv_port_id(struct list_head *head, struct net_device *dev)
+{
+ lldp_add_tlv_subtype_list(head, LLDP_TLV_PORT_ID, strlen(dev->name),
+ dev->name, LLDP_ST_PORTID_IFNAME);
+}
+
+inline void lldp_add_tlv_ttl(struct list_head *head, struct net_device *dev,
+ bool is_shutdown)
+{
+ uint16_t ttl;
+
+ if (is_shutdown) {
+ ttl = 0;
+ } else {
+ ttl = htons(sysctl_lldp_transmit_interval *
+ sysctl_lldp_hold_multiplier);
+ }
+
+ lldp_add_tlv_list(head, LLDP_TLV_TIME_TO_LIVE, sizeof(ttl),
+ (unsigned char *) &ttl);
+}
+
+inline void lldp_add_tlv_vlan(struct list_head *head, struct net_device *dev)
+{
+#if IS_ENABLED(CONFIG_VLAN_8021Q)
+ if (dev->flags & IFF_802_1Q_VLAN) {
+ uint16_t vlan = htons(vlan_dev_vlan_id(dev));
+ /* Clause F.2.1: Value of 0 signifies that the system
+ * does not know the VLAN ID or doesn"t support it.
+ */
+ if (vlan != 0) {
+ lldp_add_oui_tlv_list(head, oui_802_1, sizeof(vlan),
+ (unsigned char *) &vlan,
+ LLDP_802_1_PORT_VLANID);
+ }
+ }
+#endif
+}
+
+inline void lldp_add_tlv_mtu(struct list_head *head, struct net_device *dev)
+{
+ uint16_t mtu;
+
+ mtu = htons(dev->mtu);
+ lldp_add_oui_tlv_list(head, oui_802_3, sizeof(mtu),
+ (unsigned char *) &mtu, LLDP_802_3_MTU);
+}
+
+inline void lldp_add_tlv_port_description(struct list_head *head,
+ struct net_device *dev)
+{
+ char *desc = dev->ifalias;
+ if (desc == NULL)
+ return;
+
+ lldp_add_tlv_list(head, LLDP_TLV_PORT_DESCRIPTION, strlen(desc), desc);
+}
+
+inline void lldp_add_tlv_system_name(struct list_head *head,
+ struct net_device *dev)
+{
+ char *name = utsname()->nodename;
+ if (name == NULL)
+ return;
+
+ lldp_add_tlv_list(head, LLDP_TLV_SYSTEM_NAME, strlen(name), name);
+}
+
+inline void lldp_add_tlv_system_description(struct list_head *head,
+ struct net_device *dev)
+{
+ char *desc = utsname()->sysname;
+ if (desc == NULL)
+ return;
+
+ lldp_add_tlv_list(head, LLDP_TLV_SYSTEM_DESCRIPTION,
+ strlen(desc), desc);
+}
+
+inline void lldp_add_tlv_system_capabilities(struct list_head *head,
+ struct net_device *dev)
+{
+ struct lldp_caps caps;
+
+ caps.sys = htons(LLDP_CAP_BRIDGE | LLDP_CAP_ROUTER);
+ caps.enabled = htons(LLDP_CAP_ROUTER);
+
+ lldp_add_tlv_list(head, LLDP_TLV_SYSTEM_CAPABILITIES,
+ sizeof(struct lldp_caps), (unsigned char *) &caps);
+}
+
+void lldp_tlv_construct_list(struct list_head *head, struct net_device *dev,
+ bool is_shutdown)
+{
+ BUG_ON(head == NULL);
+
+ /* Mandatory TLVs with strict order */
+ lldp_add_tlv_chassis_id(head, dev);
+ lldp_add_tlv_port_id(head, dev);
+ lldp_add_tlv_ttl(head, dev, is_shutdown);
+
+ /* Shutdown PDU is limited to mandatory TLVs only */
+ if (is_shutdown)
+ goto end;
+
+ /* Optional TLVs */
+ lldp_add_tlv_port_description(head, dev);
+ lldp_add_tlv_system_name(head, dev);
+ lldp_add_tlv_system_description(head, dev);
+ lldp_add_tlv_system_capabilities(head, dev);
+
+ /* Additional 802.1 and 802.3 private TLVs */
+ lldp_add_tlv_vlan(head, dev); /* Annex F.1 */
+ lldp_add_tlv_mtu(head, dev); /* Annex G.5 */
+
+end:
+ /* End TLV */
+ lldp_add_tlv_list(head, LLDP_TLV_END, 0, NULL);
+}
+
+void lldp_tlv_destruct(struct lldp_tlv *tlv)
+{
+ if (tlv->oui != NULL)
+ kfree(tlv->oui);
+
+ if (tlv->val != NULL)
+ kfree(tlv->val);
+}
+
+void lldp_tlv_destruct_list(struct list_head *head)
+{
+ struct lldp_tlv *tlv, *tmp;
+
+ if (head == NULL)
+ return;
+
+ if (list_empty(head))
+ return;
+
+ list_for_each_entry_safe(tlv, tmp, head, lh) {
+ list_del(&tlv->lh);
+ lldp_tlv_destruct(tlv);
+ kfree(tlv);
+ }
+}
+
+inline uint16_t tlv_hdr(struct lldp_tlv *tlv)
+{
+ int len = tlv->entry_len - LLDP_TLV_HDR_LEN;
+
+ BUG_ON(tlv == NULL);
+ BUG_ON(len < 0);
+
+ return htons(((tlv->type << LLDP_TYPE_SHIFT) & LLDP_TYPE_MASK) |
+ (len & LLDP_LEN_MASK));
+}
+
+void lldp_tlv_put_skb_list(struct sk_buff *skb, struct list_head *head)
+{
+ struct lldp_tlv *tlv;
+ struct list_head *p;
+ unsigned char *buf;
+ u16 hdr;
+
+ list_for_each(p, head) {
+ tlv = list_entry(p, struct lldp_tlv, lh);
+
+ hdr = tlv_hdr(tlv);
+ buf = skb_put(skb, sizeof(hdr));
+ memcpy(buf, &hdr, sizeof(hdr));
+
+ BUG_ON((tlv->oui != NULL) &&
+ (tlv->type != LLDP_TLV_ORGANIZATIONAL));
+ if (tlv->oui != NULL) {
+ buf = skb_put(skb, LLDP_OUI_LEN);
+ memcpy(buf, tlv->oui, LLDP_OUI_LEN);
+ }
+
+ if (tlv->subtype > 0) {
+ buf = skb_put(skb, sizeof(unsigned char));
+ *buf = tlv->subtype;
+ }
+
+ if (tlv->len > 0) {
+ BUG_ON(tlv->val == NULL);
+ buf = skb_put(skb, tlv->len);
+ memcpy(buf, tlv->val, tlv->len);
+ }
+ }
+}
--
1.7.10
^ permalink raw reply related
* [PATCH 3/8] LLDP: Sysctl interface
From: Eldad Zack @ 2012-06-25 18:28 UTC (permalink / raw)
To: netdev; +Cc: Eldad Zack
In-Reply-To: <1340648900-6547-1-git-send-email-eldad@fogrefinery.com>
Add 3 config items to LLDP via sysctl:
* Operational mode
* Message transmission interval
* Hold multiplier
Signed-off-by: Eldad Zack <eldad@fogrefinery.com>
---
net/lldp/sysctl_net_lldp.c | 94 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 94 insertions(+)
create mode 100644 net/lldp/sysctl_net_lldp.c
diff --git a/net/lldp/sysctl_net_lldp.c b/net/lldp/sysctl_net_lldp.c
new file mode 100644
index 0000000..dd5f5e3
--- /dev/null
+++ b/net/lldp/sysctl_net_lldp.c
@@ -0,0 +1,94 @@
+/* LLDP Link Layer Discovery Protocol impementation for Linux
+ * IEEE Std 802.1ab
+ *
+ * Author: Eldad Zack <eldad@fogrefinery.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+#include <linux/sysctl.h>
+#include <linux/skbuff.h>
+#include <linux/socket.h>
+#include <linux/netdevice.h>
+#include <linux/init.h>
+#include "lldp.h"
+
+static int lldp_ttl_min = 1;
+static int lldp_ttl_max = 65535;
+
+/* Validate: (10.5.3, 10.5.4.1)
+ * 0 < transmit_interval * hold_multiplier <= 65535
+ */
+static int proc_dointvec_lldp_validate_ttl(ctl_table *table, int write,
+ void __user *buffer,
+ size_t *lenp, loff_t *ppos)
+{
+ int val, val2, ttl, ret;
+
+ ctl_table tmp = {
+ .data = &val,
+ .maxlen = sizeof(int),
+ .mode = table->mode,
+ .extra1 = &lldp_ttl_min,
+ .extra2 = &lldp_ttl_max,
+ };
+
+ if (!write)
+ return proc_dointvec(table, write, buffer, lenp, ppos);
+
+ ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
+ if (ret == 0) {
+ val2 = *((int *)table->extra1);
+ ttl = val * val2;
+
+ if ((ttl >= lldp_ttl_min) && (ttl <= lldp_ttl_max))
+ *((int *)table->data) = val;
+ else
+ return -EINVAL;
+ }
+
+ return ret;
+}
+
+static struct ctl_table_header *lldp_table_header;
+
+static struct ctl_table lldp_table[] = {
+ {
+ .procname = "lldp_op_mode",
+ .data = &sysctl_lldp_operational_mode,
+ .maxlen = sizeof(int),
+ .mode = 0644,
+ .proc_handler = proc_dointvec,
+ },
+ {
+ .procname = "transmit_interval",
+ .data = &sysctl_lldp_transmit_interval,
+ .maxlen = sizeof(int),
+ .mode = 0644,
+ .proc_handler = proc_dointvec_lldp_validate_ttl,
+ .extra1 = &sysctl_lldp_hold_multiplier,
+ },
+ {
+ .procname = "hold_multiplier",
+ .data = &sysctl_lldp_hold_multiplier,
+ .maxlen = sizeof(int),
+ .mode = 0644,
+ .proc_handler = proc_dointvec_lldp_validate_ttl,
+ .extra1 = &sysctl_lldp_transmit_interval,
+ },
+ { 0, },
+};
+
+void __init lldp_register_sysctl(void)
+{
+ lldp_table_header = register_net_sysctl(&init_net, "net/lldp",
+ lldp_table);
+}
+
+void __exit lldp_unregister_sysctl(void)
+{
+ unregister_net_sysctl_table(lldp_table_header);
+}
--
1.7.10
^ permalink raw reply related
* [PATCH 2/8] LLDP: Header
From: Eldad Zack @ 2012-06-25 18:28 UTC (permalink / raw)
To: netdev; +Cc: Eldad Zack
In-Reply-To: <1340648900-6547-1-git-send-email-eldad@fogrefinery.com>
Constants and declarations for the Linux LLDP implementation.
The struct to be added netdevice is defined here.
Highlights:
* TLV struct
* TLV types
* TLV subtypes for Chassis ID and Port ID TLVs
* Capabilities bits and struct
* IEEE private OUIs and their subtypes (802.1, 802.3)
* Multicast address for LLDP
Signed-off-by: Eldad Zack <eldad@fogrefinery.com>
---
net/lldp/lldp.h | 155 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 155 insertions(+)
create mode 100644 net/lldp/lldp.h
diff --git a/net/lldp/lldp.h b/net/lldp/lldp.h
new file mode 100644
index 0000000..d88feea
--- /dev/null
+++ b/net/lldp/lldp.h
@@ -0,0 +1,155 @@
+/* LLDP Link Layer Discovery Protocol impementation for Linux
+ * IEEE Std 802.1ab
+ *
+ * Author: Eldad Zack <eldad@fogrefinery.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+#ifndef _LINUX_LLDP_H
+#define _LINUX_LLDP_H
+#include <linux/types.h>
+
+/* LLDP Multicast Address (Clause 8.1) */
+#define LLDP_MULTICAST_ADDR { 0x01, 0x80, 0xc2, 0x00, 0x00, 0x0e }
+
+/* Basic TLV format (Clause 9.4)
+ * TLV header: 16 bits
+ *
+ * LSB
+ * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * : Length : Type :
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *
+ * Information string 0-511 bytes
+ */
+#define LLDP_TLV_HDR_LEN 2
+#define LLDP_TYPE_MASK 0xfe00
+#define LLDP_TYPE_SHIFT 9
+#define LLDP_LEN_MASK 0x01ff
+#define LLDP_LEN_MAX 511
+
+/* LLDP TLV types (Clause 9.4.1)
+ * TLVs number 0 to 3 are mandatory, the rest are optional.
+ */
+#define LLDP_TLV_END 0
+#define LLDP_TLV_CHASSIS_ID 1
+#define LLDP_TLV_PORT_ID 2
+#define LLDP_TLV_TIME_TO_LIVE 3
+#define LLDP_TLV_PORT_DESCRIPTION 4
+#define LLDP_TLV_SYSTEM_NAME 5
+#define LLDP_TLV_SYSTEM_DESCRIPTION 6
+#define LLDP_TLV_SYSTEM_CAPABILITIES 7
+#define LLDP_TLV_MANAGEMENT_ADDRESS 8
+/* Reserved: 9-126 */
+#define LLDP_TLV_ORGANIZATIONAL 127 /* Private TLVs */
+
+/* Chassis ID Subtypes, Reserved: 0,8-255. (Clause 9.5.2) */
+#define LLDP_ST_CHID_COMPONENT 1 /* Chassis component */
+#define LLDP_ST_CHID_IFALIAS 2 /* ifAlias (RFC 2863) */
+#define LLDP_ST_CHID_PORT_COMPONENT 3
+#define LLDP_ST_CHID_MAC_ADDR 4
+#define LLDP_ST_CHID_NET_ADDR 5
+#define LLDP_ST_CHID_IFNAME 6
+#define LLDP_ST_CHID_LOCAL 7
+
+/* Port ID Subtypes, Reserved: 0,8-255. (Clause 9.5.3) */
+#define LLDP_ST_PORTID_IFALIAS 1 /* ifAlias (RFC 2863) */
+#define LLDP_ST_PORTID_PORT_COMPONENT 2
+#define LLDP_ST_PORTID_MAC_ADDR 3
+#define LLDP_ST_PORTID_NET_ADDR 4
+#define LLDP_ST_PORTID_IFNAME 5 /* ifName (RFC 2863) */
+#define LLDP_ST_PORTID_AGENT_CIR_ID 6 /* Agent Circuit ID */
+#define LLDP_ST_PORTID_LOCAL 7
+
+/* System Capabilities (Clause 9.5.8.1)
+ * "Station Only" (bit 7) is mutually exclusive with
+ * all the other options.
+ */
+#define LLDP_CAP_OTHER 0x0001
+#define LLDP_CAP_REPEATER 0x0002
+#define LLDP_CAP_BRIDGE 0x0004
+#define LLDP_CAP_WLAN_AP 0x0008
+#define LLDP_CAP_ROUTER 0x0010
+#define LLDP_CAP_TELEPHONE 0x0020
+#define LLDP_CAP_DOCSIS 0x0040
+#define LLDP_CAP_STATION_ONLY 0x0080
+
+/* Organizationally Specific TLVs (Clause 9.6)
+ */
+#define LLDP_OUI_LEN 3
+#define LLDP_OUI_802_1 { 0x00, 0x80, 0xc2 }
+#define LLDP_OUI_802_3 { 0x00, 0x12, 0x0f }
+
+/* Annex F: 802.1 OUI Subtypes */
+#define LLDP_802_1_PORT_VLANID 1
+#define LLDP_802_1_PORT_PROT_VLAID 2
+#define LLDP_802_1_VLAN_NAME 3
+#define LLDP_802_1_PROTOCOL_ID 4
+
+/* Annex G: 802.3 OUI Subtypes */
+#define LLDP_802_3_MAC_PHY 1
+#define LLDP_802_3_PMD 2
+#define LLDP_802_3_LAG 3
+#define LLDP_802_3_MTU 4
+
+/* Default transmission parameters (Clause 10.5.3.3) */
+#define LLDP_DEFAULT_MSG_TX_INTERVAL 30
+#define LLDP_DEFAULT_MSG_TX_HOLD_MULT 4
+
+struct lldp_tlv {
+ struct list_head lh;
+ uint16_t type;
+ uint16_t len;
+ unsigned char *val;
+ unsigned char subtype;
+ unsigned char *oui;
+ uint16_t entry_len;
+};
+
+struct lldp_caps {
+ u16 sys;
+ u16 enabled;
+} __packed;
+
+/* lldp_tx */
+void __lldp_send(struct net_device *dev, bool is_shutdown);
+
+static inline void lldp_send(struct net_device *dev)
+{
+ __lldp_send(dev, false);
+}
+
+static inline void lldp_send_shutdown(struct net_device *dev)
+{
+ __lldp_send(dev, true);
+}
+
+/* lldpdu */
+void lldp_tlv_construct_list(struct list_head *head, struct net_device *dev,
+ bool is_shutdown);
+void lldp_tlv_destruct_list(struct list_head *head);
+void lldp_tlv_put_skb_list(struct sk_buff *skb, struct list_head *head);
+int lldp_tlv_list_len(struct list_head *head);
+
+/* netdevice */
+struct __rcu lldp_dev {
+ struct timer_list *tx_timer;
+};
+
+/* sysctl */
+void __init lldp_register_sysctl(void);
+void __exit lldp_unregister_sysctl(void);
+
+#define LLDP_SYSCTL_OP_SUPPRESS 0x00
+#define LLDP_SYSCTL_OP_TX 0x01
+
+extern int sysctl_lldp_operational_mode;
+extern int sysctl_lldp_transmit_interval;
+extern int sysctl_lldp_hold_multiplier;
+
+#endif /* _LINUX_LLDP_H */
--
1.7.10
^ permalink raw reply related
* [PATCH 1/8] if_ether.h: Add LLDP ethertype
From: Eldad Zack @ 2012-06-25 18:28 UTC (permalink / raw)
To: netdev; +Cc: Eldad Zack
In-Reply-To: <1340648900-6547-1-git-send-email-eldad@fogrefinery.com>
The LLDP ethertype is defined in IEEE Std 802.1ab (2005), clause 8.3.
Signed-off-by: Eldad Zack <eldad@fogrefinery.com>
---
include/linux/if_ether.h | 1 +
1 file changed, 1 insertion(+)
diff --git a/include/linux/if_ether.h b/include/linux/if_ether.h
index 56d907a..a5f0612 100644
--- a/include/linux/if_ether.h
+++ b/include/linux/if_ether.h
@@ -81,6 +81,7 @@
#define ETH_P_8021AD 0x88A8 /* 802.1ad Service VLAN */
#define ETH_P_802_EX1 0x88B5 /* 802.1 Local Experimental 1. */
#define ETH_P_TIPC 0x88CA /* TIPC */
+#define ETH_P_LLDP 0x88CC /* 802.1ab Link Layer Discovery */
#define ETH_P_8021AH 0x88E7 /* 802.1ah Backbone Service Tag */
#define ETH_P_1588 0x88F7 /* IEEE 1588 Timesync */
#define ETH_P_FCOE 0x8906 /* Fibre Channel over Ethernet */
--
1.7.10
^ permalink raw reply related
* [PATCH RFC 0/8] LLDP implementation for Linux
From: Eldad Zack @ 2012-06-25 18:28 UTC (permalink / raw)
To: netdev; +Cc: Eldad Zack
Hi all,
This series of patches provides a partial LLDP (IEEE Std 802.1ab)
implementation.
I'd really appreciate a review of it.
LLDP is a simple discovery protocol which advertises the identification and
other info (such as MTU or capabilities) of device on the link. It can also
help debug misconfigurations on the link layer (wrong MTU, wrong VLAN).
Some notes/questions:
* Applies against net-next and mainline.
* Included in this series is only LLDP output code.
This is not an issue since input and output are decoupled in LLDP anyway.
I'm working on the input code as well and will post it at some point in the
future.
* Sysctl is used to do (some) configuration. This is done globally right now.
Before I add per-device sysctls: is it at all appropriate to use sysctl
here?
* By default, transmission is suppressed. To arm it, set
/proc/sys/net/lldp/lldp_op_mode
to 1.
* I've tested it on x86_64 and (qemu'd) x86.
* I've tested it on my machine and it works with Ethernet and WLAN.
* The last patch ("8021q/vlan: process NETDEV_GOING_DOWN") is needed
to be able to send shutdown PDU on VLAN interfaces, but has otherwise
no effect.
* Is there a better way to deal with 16-bit endianness other than masking and
shifting, when one field is more than a byte long (in this case 7/9)?
* I usually only work on it on weekends, so I might be slow in responding back.
Thanks in advance if you're taking the time to review it or test it!
Signed-off-by: Eldad Zack <eldad@fogrefinery.com>
^ permalink raw reply
* Re: [RFC net-next (v2) 14/14] ixgbevf: set maximal number of default RSS queues
From: Eilon Greenstein @ 2012-06-25 18:28 UTC (permalink / raw)
To: Alexander Duyck; +Cc: Yuval Mintz, davem, netdev, Jeff Kirsher, Greg Rose
In-Reply-To: <4FE892CD.1020804@intel.com>
On Mon, 2012-06-25 at 09:33 -0700, Alexander Duyck wrote:
> I suggest you locate where we set "adapter->num_rx_queues" and attempt
> to address the issue there.
I see what you mean. On one hand, you use the num_rx_queues as if it can
get higher numbers and the code seems to be ready for that with all the
for loops in place, but on the other hand, it is hard coded to 1 at
ixgbevf_set_num_queues and it seems weird to add min function with
explicit '1'. Do you suggest to leave this driver alone hoping that if
in the future the '1' will change the author will remember to use the
default value?
Thanks,
Eilon
^ permalink raw reply
* RE: [RFC net-next (v2) 11/14] igb: set maximal number of default RSS queues
From: Eilon Greenstein @ 2012-06-25 18:20 UTC (permalink / raw)
To: Vick, Matthew
Cc: Yuval Mintz, davem@davemloft.net, netdev@vger.kernel.org,
Kirsher, Jeffrey T
In-Reply-To: <06DFBC1E25D8024DB214DC7F41A3CD3448870CE4@ORSMSX101.amr.corp.intel.com>
On Mon, 2012-06-25 at 17:31 +0000, Vick, Matthew wrote:
> > -----Original Message-----
> > From: netdev-owner@vger.kernel.org [mailto:netdev-
> > owner@vger.kernel.org] On Behalf Of Yuval Mintz
> > Sent: Monday, June 25, 2012 4:46 AM
> > To: davem@davemloft.net; netdev@vger.kernel.org
> > Cc: eilong@broadcom.com; Yuval Mintz; Kirsher, Jeffrey T
> > Subject: [RFC net-next (v2) 11/14] igb: set maximal number of default
> > RSS queues
> >
> > Signed-off-by: Yuval Mintz <yuvalmin@broadcom.com>
> > Signed-off-by: Eilon Greenstein <eilong@broadcom.com>
> >
> > Cc: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
> > ---
> > drivers/net/ethernet/intel/igb/igb_main.c | 3 ++-
> > 1 files changed, 2 insertions(+), 1 deletions(-)
> >
> > diff --git a/drivers/net/ethernet/intel/igb/igb_main.c
> > b/drivers/net/ethernet/intel/igb/igb_main.c
> > index 01ced68..b11ee60 100644
> > --- a/drivers/net/ethernet/intel/igb/igb_main.c
> > +++ b/drivers/net/ethernet/intel/igb/igb_main.c
> > @@ -2465,7 +2465,8 @@ static int __devinit igb_sw_init(struct
> > igb_adapter *adapter)
> > break;
> > }
> >
> > - adapter->rss_queues = min_t(u32, max_rss_queues,
> > num_online_cpus());
> > + adapter->rss_queues = min_t(u32, max_rss_queues,
> > + netif_get_num_default_rss_queues());
> >
> > /* Determine if we need to pair queues. */
> > switch (hw->mac.type) {
> > --
> > 1.7.9.rc2
>
> Since igb supports a maximum of 8 RSS queues anyway, it's generally unaffected by this change. That being said, I'm confused about what you're trying to accomplish--is it to standardize the number of RSS queues or limit the number of interrupts by default? Or is it the former with a hope that it will trickle down to the latter?
>
> For example, if you take an igb device that supports 8 RSS queues (say, I350) and you change the default to 4 RSS queues, you will end up with the same number of interrupt vectors being requested as we will disable queue pairing and request separate vectors for Rx/Tx queues. I haven't looked at the other drivers affected by this RFC, but it's possible other drivers behave the same way.
The main motivation is the Rx rings that consume significant amount of
memory. The MSI-X vectors are a nice byproduct, but the logic you
describe still sounds good for this kind of low numbers.
^ permalink raw reply
* Re: [net-next RFC V4 PATCH 0/4] Multiqueue virtio-net
From: Shirley Ma @ 2012-06-25 18:01 UTC (permalink / raw)
To: Jason Wang
Cc: krkumar2, habanero, kvm, mst, netdev, linux-kernel,
virtualization, edumazet, tahm, jwhan, davem
In-Reply-To: <20120625090829.7263.65026.stgit@amd-6168-8-1.englab.nay.redhat.com>
Hello Jason,
Good work. Do you have local guest to guest results?
Thanks
Shirley
^ permalink raw reply
* Re: [RFC net-next (v2) 12/14] ixgbe: set maximal number of default RSS queues
From: Eilon Greenstein @ 2012-06-25 17:53 UTC (permalink / raw)
To: Alexander Duyck; +Cc: Yuval Mintz, davem, netdev, Jeff Kirsher, John Fastabend
In-Reply-To: <4FE88770.7070007@intel.com>
On Mon, 2012-06-25 at 08:44 -0700, Alexander Duyck wrote:
> This doesn't limit queues, only interrupt vectors. As I told you before
> you should look at the ixgbe_set_rss_queues function if you actually
> want to limit the number of RSS queues.
How about this:
diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_lib.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_lib.c
index af1a531..23a8609 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_lib.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_lib.c
@@ -277,6 +277,8 @@ static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter)
bool ret = false;
struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_RSS];
+ f->indices = min_t(int, netif_get_num_default_rss_queues(), f->indices);
+
if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
f->mask = 0xF;
adapter->num_rx_queues = f->indices;
@@ -302,7 +304,9 @@ static inline bool ixgbe_set_fdir_queues(struct ixgbe_adapter *adapter)
bool ret = false;
struct ixgbe_ring_feature *f_fdir = &adapter->ring_feature[RING_F_FDIR];
- f_fdir->indices = min_t(int, num_online_cpus(), f_fdir->indices);
+ f_fdir->indices = min_t(int, netif_get_num_default_rss_queues(),
+ f_fdir->indices);
+
f_fdir->mask = 0;
/*
@@ -339,8 +343,7 @@ static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter *adapter)
if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
return false;
- f->indices = min_t(int, num_online_cpus(), f->indices);
-
+ f->indices = min_t(int, f->indices, netif_get_num_default_rss_queues());
adapter->num_rx_queues = 1;
adapter->num_tx_queues = 1;
^ permalink raw reply related
* [net-next 11/11] caif-hsi: Remove use of module parameters
From: sjur.brandeland @ 2012-06-25 17:49 UTC (permalink / raw)
To: davem; +Cc: netdev, sjurbren, Sjur Brændeland
In-Reply-To: <1340646583-21059-1-git-send-email-sjur.brandeland@stericsson.com>
From: Sjur Brændeland <sjur.brandeland@stericsson.com>
Remove use of module parameters on caif hsi device, as
rtnl configuration parameters are already supported.
All caif hsi configuration data is put in cfhsi_config,
and default values in hsi_default_config.
Signed-off-by: Sjur Brændeland <sjur.brandeland@stericsson.com>
---
drivers/net/caif/caif_hsi.c | 151 ++++++++++++++++++++----------------------
include/net/caif/caif_hsi.h | 14 +++-
2 files changed, 82 insertions(+), 83 deletions(-)
diff --git a/drivers/net/caif/caif_hsi.c b/drivers/net/caif/caif_hsi.c
index 0927c10..1c2bd01 100644
--- a/drivers/net/caif/caif_hsi.c
+++ b/drivers/net/caif/caif_hsi.c
@@ -32,51 +32,39 @@ MODULE_DESCRIPTION("CAIF HSI driver");
#define PAD_POW2(x, pow) ((((x)&((pow)-1)) == 0) ? 0 :\
(((pow)-((x)&((pow)-1)))))
-static int inactivity_timeout = 1000;
-module_param(inactivity_timeout, int, S_IRUGO | S_IWUSR);
-MODULE_PARM_DESC(inactivity_timeout, "Inactivity timeout on HSI, ms.");
+static const struct cfhsi_config hsi_default_config = {
-static int aggregation_timeout = 1;
-module_param(aggregation_timeout, int, S_IRUGO | S_IWUSR);
-MODULE_PARM_DESC(aggregation_timeout, "Aggregation timeout on HSI, ms.");
+ /* Inactivity timeout on HSI, ms */
+ .inactivity_timeout = HZ,
-/*
- * HSI padding options.
- * Warning: must be a base of 2 (& operation used) and can not be zero !
- */
-static int hsi_head_align = 4;
-module_param(hsi_head_align, int, S_IRUGO);
-MODULE_PARM_DESC(hsi_head_align, "HSI head alignment.");
+ /* Aggregation timeout (ms) of zero means no aggregation is done*/
+ .aggregation_timeout = 1,
-static int hsi_tail_align = 4;
-module_param(hsi_tail_align, int, S_IRUGO);
-MODULE_PARM_DESC(hsi_tail_align, "HSI tail alignment.");
-
-/*
- * HSI link layer flowcontrol thresholds.
- * Warning: A high threshold value migth increase throughput but it will at
- * the same time prevent channel prioritization and increase the risk of
- * flooding the modem. The high threshold should be above the low.
- */
-static int hsi_high_threshold = 100;
-module_param(hsi_high_threshold, int, S_IRUGO);
-MODULE_PARM_DESC(hsi_high_threshold, "HSI high threshold (FLOW OFF).");
+ /*
+ * HSI link layer flow-control thresholds.
+ * Threshold values for the HSI packet queue. Flow-control will be
+ * asserted when the number of packets exceeds q_high_mark. It will
+ * not be de-asserted before the number of packets drops below
+ * q_low_mark.
+ * Warning: A high threshold value might increase throughput but it
+ * will at the same time prevent channel prioritization and increase
+ * the risk of flooding the modem. The high threshold should be above
+ * the low.
+ */
+ .q_high_mark = 100,
+ .q_low_mark = 50,
-static int hsi_low_threshold = 50;
-module_param(hsi_low_threshold, int, S_IRUGO);
-MODULE_PARM_DESC(hsi_low_threshold, "HSI high threshold (FLOW ON).");
+ /*
+ * HSI padding options.
+ * Warning: must be a base of 2 (& operation used) and can not be zero !
+ */
+ .head_align = 4,
+ .tail_align = 4,
+};
#define ON 1
#define OFF 0
-/*
- * Threshold values for the HSI packet queue. Flowcontrol will be asserted
- * when the number of packets exceeds HIGH_WATER_MARK. It will not be
- * de-asserted before the number of packets drops below LOW_WATER_MARK.
- */
-#define LOW_WATER_MARK hsi_low_threshold
-#define HIGH_WATER_MARK hsi_high_threshold
-
static LIST_HEAD(cfhsi_list);
static void cfhsi_inactivity_tout(unsigned long arg)
@@ -99,8 +87,8 @@ static void cfhsi_update_aggregation_stats(struct cfhsi *cfhsi,
int hpad, tpad, len;
info = (struct caif_payload_info *)&skb->cb;
- hpad = 1 + PAD_POW2((info->hdr_len + 1), hsi_head_align);
- tpad = PAD_POW2((skb->len + hpad), hsi_tail_align);
+ hpad = 1 + PAD_POW2((info->hdr_len + 1), cfhsi->cfg.head_align);
+ tpad = PAD_POW2((skb->len + hpad), cfhsi->cfg.tail_align);
len = skb->len + hpad + tpad;
if (direction > 0)
@@ -113,7 +101,7 @@ static bool cfhsi_can_send_aggregate(struct cfhsi *cfhsi)
{
int i;
- if (cfhsi->aggregation_timeout == 0)
+ if (cfhsi->cfg.aggregation_timeout == 0)
return true;
for (i = 0; i < CFHSI_PRIO_BEBK; ++i) {
@@ -169,7 +157,7 @@ static void cfhsi_abort_tx(struct cfhsi *cfhsi)
cfhsi->tx_state = CFHSI_TX_STATE_IDLE;
if (!test_bit(CFHSI_SHUTDOWN, &cfhsi->bits))
mod_timer(&cfhsi->inactivity_timer,
- jiffies + cfhsi->inactivity_timeout);
+ jiffies + cfhsi->cfg.inactivity_timeout);
spin_unlock_bh(&cfhsi->lock);
}
@@ -250,8 +238,8 @@ static int cfhsi_tx_frm(struct cfhsi_desc *desc, struct cfhsi *cfhsi)
/* Calculate needed head alignment and tail alignment. */
info = (struct caif_payload_info *)&skb->cb;
- hpad = 1 + PAD_POW2((info->hdr_len + 1), hsi_head_align);
- tpad = PAD_POW2((skb->len + hpad), hsi_tail_align);
+ hpad = 1 + PAD_POW2((info->hdr_len + 1), cfhsi->cfg.head_align);
+ tpad = PAD_POW2((skb->len + hpad), cfhsi->cfg.tail_align);
/* Check if frame still fits with added alignment. */
if ((skb->len + hpad + tpad) <= CFHSI_MAX_EMB_FRM_SZ) {
@@ -292,8 +280,8 @@ static int cfhsi_tx_frm(struct cfhsi_desc *desc, struct cfhsi *cfhsi)
/* Calculate needed head alignment and tail alignment. */
info = (struct caif_payload_info *)&skb->cb;
- hpad = 1 + PAD_POW2((info->hdr_len + 1), hsi_head_align);
- tpad = PAD_POW2((skb->len + hpad), hsi_tail_align);
+ hpad = 1 + PAD_POW2((info->hdr_len + 1), cfhsi->cfg.head_align);
+ tpad = PAD_POW2((skb->len + hpad), cfhsi->cfg.tail_align);
/* Fill in CAIF frame length in descriptor. */
desc->cffrm_len[nfrms] = hpad + skb->len + tpad;
@@ -364,7 +352,7 @@ static void cfhsi_start_tx(struct cfhsi *cfhsi)
cfhsi->tx_state = CFHSI_TX_STATE_IDLE;
/* Start inactivity timer. */
mod_timer(&cfhsi->inactivity_timer,
- jiffies + cfhsi->inactivity_timeout);
+ jiffies + cfhsi->cfg.inactivity_timeout);
spin_unlock_bh(&cfhsi->lock);
break;
}
@@ -390,7 +378,7 @@ static void cfhsi_tx_done(struct cfhsi *cfhsi)
*/
spin_lock_bh(&cfhsi->lock);
if (cfhsi->flow_off_sent &&
- cfhsi_tx_queue_len(cfhsi) <= cfhsi->q_low_mark &&
+ cfhsi_tx_queue_len(cfhsi) <= cfhsi->cfg.q_low_mark &&
cfhsi->cfdev.flowctrl) {
cfhsi->flow_off_sent = 0;
@@ -402,7 +390,7 @@ static void cfhsi_tx_done(struct cfhsi *cfhsi)
cfhsi_start_tx(cfhsi);
} else {
mod_timer(&cfhsi->aggregation_timer,
- jiffies + cfhsi->aggregation_timeout);
+ jiffies + cfhsi->cfg.aggregation_timeout);
spin_unlock_bh(&cfhsi->lock);
}
@@ -645,7 +633,7 @@ static void cfhsi_rx_done(struct cfhsi *cfhsi)
/* Update inactivity timer if pending. */
spin_lock_bh(&cfhsi->lock);
mod_timer_pending(&cfhsi->inactivity_timer,
- jiffies + cfhsi->inactivity_timeout);
+ jiffies + cfhsi->cfg.inactivity_timeout);
spin_unlock_bh(&cfhsi->lock);
if (cfhsi->rx_state.state == CFHSI_RX_STATE_DESC) {
@@ -880,7 +868,7 @@ wake_ack:
__func__);
/* Start inactivity timer. */
mod_timer(&cfhsi->inactivity_timer,
- jiffies + cfhsi->inactivity_timeout);
+ jiffies + cfhsi->cfg.inactivity_timeout);
spin_unlock_bh(&cfhsi->lock);
return;
}
@@ -1071,7 +1059,7 @@ static int cfhsi_xmit(struct sk_buff *skb, struct net_device *dev)
/* Send flow off if number of packets is above high water mark. */
if (!cfhsi->flow_off_sent &&
- cfhsi_tx_queue_len(cfhsi) > cfhsi->q_high_mark &&
+ cfhsi_tx_queue_len(cfhsi) > cfhsi->cfg.q_high_mark &&
cfhsi->cfdev.flowctrl) {
cfhsi->flow_off_sent = 1;
cfhsi->cfdev.flowctrl(cfhsi->ndev, OFF);
@@ -1143,6 +1131,7 @@ static void cfhsi_setup(struct net_device *dev)
cfhsi->cfdev.use_stx = false;
cfhsi->cfdev.use_fcs = false;
cfhsi->ndev = dev;
+ cfhsi->cfg = hsi_default_config;
}
static int cfhsi_open(struct net_device *ndev)
@@ -1158,9 +1147,6 @@ static int cfhsi_open(struct net_device *ndev)
/* Set flow info */
cfhsi->flow_off_sent = 0;
- cfhsi->q_low_mark = LOW_WATER_MARK;
- cfhsi->q_high_mark = HIGH_WATER_MARK;
-
/*
* Allocate a TX buffer with the size of a HSI packet descriptors
@@ -1188,20 +1174,8 @@ static int cfhsi_open(struct net_device *ndev)
goto err_alloc_rx_flip;
}
- /* Pre-calculate inactivity timeout. */
- if (inactivity_timeout != -1) {
- cfhsi->inactivity_timeout =
- inactivity_timeout * HZ / 1000;
- if (!cfhsi->inactivity_timeout)
- cfhsi->inactivity_timeout = 1;
- else if (cfhsi->inactivity_timeout > NEXT_TIMER_MAX_DELTA)
- cfhsi->inactivity_timeout = NEXT_TIMER_MAX_DELTA;
- } else {
- cfhsi->inactivity_timeout = NEXT_TIMER_MAX_DELTA;
- }
-
/* Initialize aggregation timeout */
- cfhsi->aggregation_timeout = aggregation_timeout;
+ cfhsi->cfg.aggregation_timeout = hsi_default_config.aggregation_timeout;
/* Initialize recieve vaiables. */
cfhsi->rx_ptr = cfhsi->rx_buf;
@@ -1350,24 +1324,39 @@ static void cfhsi_netlink_parms(struct nlattr *data[], struct cfhsi *cfhsi)
}
i = __IFLA_CAIF_HSI_INACTIVITY_TOUT;
- if (data[i])
- inactivity_timeout = nla_get_u32(data[i]);
+ /*
+ * Inactivity timeout in millisecs. Lowest possible value is 1,
+ * and highest possible is NEXT_TIMER_MAX_DELTA.
+ */
+ if (data[i]) {
+ u32 inactivity_timeout = nla_get_u32(data[i]);
+ /* Pre-calculate inactivity timeout. */
+ cfhsi->cfg.inactivity_timeout = inactivity_timeout * HZ / 1000;
+ if (cfhsi->cfg.inactivity_timeout == 0)
+ cfhsi->cfg.inactivity_timeout = 1;
+ else if (cfhsi->cfg.inactivity_timeout > NEXT_TIMER_MAX_DELTA)
+ cfhsi->cfg.inactivity_timeout = NEXT_TIMER_MAX_DELTA;
+ }
i = __IFLA_CAIF_HSI_AGGREGATION_TOUT;
if (data[i])
- aggregation_timeout = nla_get_u32(data[i]);
+ cfhsi->cfg.aggregation_timeout = nla_get_u32(data[i]);
i = __IFLA_CAIF_HSI_HEAD_ALIGN;
if (data[i])
- hsi_head_align = nla_get_u32(data[i]);
+ cfhsi->cfg.head_align = nla_get_u32(data[i]);
i = __IFLA_CAIF_HSI_TAIL_ALIGN;
if (data[i])
- hsi_tail_align = nla_get_u32(data[i]);
+ cfhsi->cfg.tail_align = nla_get_u32(data[i]);
i = __IFLA_CAIF_HSI_QHIGH_WATERMARK;
if (data[i])
- hsi_high_threshold = nla_get_u32(data[i]);
+ cfhsi->cfg.q_high_mark = nla_get_u32(data[i]);
+
+ i = __IFLA_CAIF_HSI_QLOW_WATERMARK;
+ if (data[i])
+ cfhsi->cfg.q_low_mark = nla_get_u32(data[i]);
}
static int caif_hsi_changelink(struct net_device *dev, struct nlattr *tb[],
@@ -1398,16 +1387,20 @@ static size_t caif_hsi_get_size(const struct net_device *dev)
static int caif_hsi_fill_info(struct sk_buff *skb, const struct net_device *dev)
{
+ struct cfhsi *cfhsi = netdev_priv(dev);
+
if (nla_put_u32(skb, __IFLA_CAIF_HSI_INACTIVITY_TOUT,
- inactivity_timeout) ||
+ cfhsi->cfg.inactivity_timeout) ||
nla_put_u32(skb, __IFLA_CAIF_HSI_AGGREGATION_TOUT,
- aggregation_timeout) ||
- nla_put_u32(skb, __IFLA_CAIF_HSI_HEAD_ALIGN, hsi_head_align) ||
- nla_put_u32(skb, __IFLA_CAIF_HSI_TAIL_ALIGN, hsi_tail_align) ||
+ cfhsi->cfg.aggregation_timeout) ||
+ nla_put_u32(skb, __IFLA_CAIF_HSI_HEAD_ALIGN,
+ cfhsi->cfg.head_align) ||
+ nla_put_u32(skb, __IFLA_CAIF_HSI_TAIL_ALIGN,
+ cfhsi->cfg.tail_align) ||
nla_put_u32(skb, __IFLA_CAIF_HSI_QHIGH_WATERMARK,
- hsi_high_threshold) ||
+ cfhsi->cfg.q_high_mark) ||
nla_put_u32(skb, __IFLA_CAIF_HSI_QLOW_WATERMARK,
- hsi_low_threshold))
+ cfhsi->cfg.q_low_mark))
return -EMSGSIZE;
return 0;
diff --git a/include/net/caif/caif_hsi.h b/include/net/caif/caif_hsi.h
index 6dc7dc2..bcb9cc3 100644
--- a/include/net/caif/caif_hsi.h
+++ b/include/net/caif/caif_hsi.h
@@ -132,6 +132,15 @@ enum {
CFHSI_PRIO_LAST,
};
+struct cfhsi_config {
+ u32 inactivity_timeout;
+ u32 aggregation_timeout;
+ u32 head_align;
+ u32 tail_align;
+ u32 q_high_mark;
+ u32 q_low_mark;
+};
+
/* Structure implemented by CAIF HSI drivers. */
struct cfhsi {
struct caif_dev_common cfdev;
@@ -142,7 +151,7 @@ struct cfhsi {
struct cfhsi_ops *ops;
int tx_state;
struct cfhsi_rx_state rx_state;
- unsigned long inactivity_timeout;
+ struct cfhsi_config cfg;
int rx_len;
u8 *rx_ptr;
u8 *tx_buf;
@@ -150,8 +159,6 @@ struct cfhsi {
u8 *rx_flip_buf;
spinlock_t lock;
int flow_off_sent;
- u32 q_low_mark;
- u32 q_high_mark;
struct list_head list;
struct work_struct wake_up_work;
struct work_struct wake_down_work;
@@ -164,7 +171,6 @@ struct cfhsi {
struct timer_list rx_slowpath_timer;
/* TX aggregation */
- unsigned long aggregation_timeout;
int aggregation_len;
struct timer_list aggregation_timer;
--
1.7.5.4
^ permalink raw reply related
* [net-next 10/11] caif-hsi: Replace platform device with ops structure.
From: sjur.brandeland @ 2012-06-25 17:49 UTC (permalink / raw)
To: davem; +Cc: netdev, sjurbren, Sjur Brændeland
In-Reply-To: <1340646583-21059-1-git-send-email-sjur.brandeland@stericsson.com>
From: Sjur Brændeland <sjur.brandeland@stericsson.com>
Remove use of struct platform_device, and replace it with
struct cfhsi_ops. Updated variable names in the same
spirit:
cfhsi_get_dev to cfhsi_get_ops,
cfhsi->dev to cfhsi->ops and,
cfhsi->dev.drv to cfhsi->ops->cb_ops.
Signed-off-by: Sjur Brændeland <sjur.brandeland@stericsson.com>
---
drivers/net/caif/caif_hsi.c | 109 ++++++++++++++++++++-----------------------
include/net/caif/caif_hsi.h | 38 ++++++++--------
2 files changed, 70 insertions(+), 77 deletions(-)
diff --git a/drivers/net/caif/caif_hsi.c b/drivers/net/caif/caif_hsi.c
index a14f85c..0927c10 100644
--- a/drivers/net/caif/caif_hsi.c
+++ b/drivers/net/caif/caif_hsi.c
@@ -11,7 +11,6 @@
#include <linux/init.h>
#include <linux/module.h>
#include <linux/device.h>
-#include <linux/platform_device.h>
#include <linux/netdevice.h>
#include <linux/string.h>
#include <linux/list.h>
@@ -184,7 +183,7 @@ static int cfhsi_flush_fifo(struct cfhsi *cfhsi)
__func__);
do {
- ret = cfhsi->dev->cfhsi_fifo_occupancy(cfhsi->dev,
+ ret = cfhsi->ops->cfhsi_fifo_occupancy(cfhsi->ops,
&fifo_occupancy);
if (ret) {
netdev_warn(cfhsi->ndev,
@@ -197,8 +196,8 @@ static int cfhsi_flush_fifo(struct cfhsi *cfhsi)
fifo_occupancy = min(sizeof(buffer), fifo_occupancy);
set_bit(CFHSI_FLUSH_FIFO, &cfhsi->bits);
- ret = cfhsi->dev->cfhsi_rx(buffer, fifo_occupancy,
- cfhsi->dev);
+ ret = cfhsi->ops->cfhsi_rx(buffer, fifo_occupancy,
+ cfhsi->ops);
if (ret) {
clear_bit(CFHSI_FLUSH_FIFO, &cfhsi->bits);
netdev_warn(cfhsi->ndev,
@@ -371,7 +370,7 @@ static void cfhsi_start_tx(struct cfhsi *cfhsi)
}
/* Set up new transfer. */
- res = cfhsi->dev->cfhsi_tx(cfhsi->tx_buf, len, cfhsi->dev);
+ res = cfhsi->ops->cfhsi_tx(cfhsi->tx_buf, len, cfhsi->ops);
if (WARN_ON(res < 0))
netdev_err(cfhsi->ndev, "%s: TX error %d.\n",
__func__, res);
@@ -410,11 +409,11 @@ static void cfhsi_tx_done(struct cfhsi *cfhsi)
return;
}
-static void cfhsi_tx_done_cb(struct cfhsi_drv *drv)
+static void cfhsi_tx_done_cb(struct cfhsi_cb_ops *cb_ops)
{
struct cfhsi *cfhsi;
- cfhsi = container_of(drv, struct cfhsi, drv);
+ cfhsi = container_of(cb_ops, struct cfhsi, cb_ops);
netdev_dbg(cfhsi->ndev, "%s.\n",
__func__);
@@ -476,8 +475,8 @@ static int cfhsi_rx_desc(struct cfhsi_desc *desc, struct cfhsi *cfhsi)
skb->dev = cfhsi->ndev;
/*
- * We are called from a arch specific platform device.
- * Unfortunately we don't know what context we're
+ * We are in a callback handler and
+ * unfortunately we don't know what context we're
* running in.
*/
if (in_interrupt())
@@ -607,7 +606,7 @@ static int cfhsi_rx_pld(struct cfhsi_desc *desc, struct cfhsi *cfhsi)
skb->dev = cfhsi->ndev;
/*
- * We're called from a platform device,
+ * We're called in callback from HSI
* and don't know the context we're running in.
*/
if (in_interrupt())
@@ -711,8 +710,8 @@ static void cfhsi_rx_done(struct cfhsi *cfhsi)
netdev_dbg(cfhsi->ndev, "%s: Start RX.\n",
__func__);
- res = cfhsi->dev->cfhsi_rx(rx_ptr, rx_len,
- cfhsi->dev);
+ res = cfhsi->ops->cfhsi_rx(rx_ptr, rx_len,
+ cfhsi->ops);
if (WARN_ON(res < 0)) {
netdev_err(cfhsi->ndev, "%s: RX error %d.\n",
__func__, res);
@@ -765,11 +764,11 @@ static void cfhsi_rx_slowpath(unsigned long arg)
cfhsi_rx_done(cfhsi);
}
-static void cfhsi_rx_done_cb(struct cfhsi_drv *drv)
+static void cfhsi_rx_done_cb(struct cfhsi_cb_ops *cb_ops)
{
struct cfhsi *cfhsi;
- cfhsi = container_of(drv, struct cfhsi, drv);
+ cfhsi = container_of(cb_ops, struct cfhsi, cb_ops);
netdev_dbg(cfhsi->ndev, "%s.\n",
__func__);
@@ -803,7 +802,7 @@ static void cfhsi_wake_up(struct work_struct *work)
}
/* Activate wake line. */
- cfhsi->dev->cfhsi_wake_up(cfhsi->dev);
+ cfhsi->ops->cfhsi_wake_up(cfhsi->ops);
netdev_dbg(cfhsi->ndev, "%s: Start waiting.\n",
__func__);
@@ -819,7 +818,7 @@ static void cfhsi_wake_up(struct work_struct *work)
__func__, ret);
clear_bit(CFHSI_WAKE_UP, &cfhsi->bits);
- cfhsi->dev->cfhsi_wake_down(cfhsi->dev);
+ cfhsi->ops->cfhsi_wake_down(cfhsi->ops);
return;
} else if (!ret) {
bool ca_wake = false;
@@ -830,14 +829,14 @@ static void cfhsi_wake_up(struct work_struct *work)
__func__);
/* Check FIFO to check if modem has sent something. */
- WARN_ON(cfhsi->dev->cfhsi_fifo_occupancy(cfhsi->dev,
+ WARN_ON(cfhsi->ops->cfhsi_fifo_occupancy(cfhsi->ops,
&fifo_occupancy));
netdev_dbg(cfhsi->ndev, "%s: Bytes in FIFO: %u.\n",
__func__, (unsigned) fifo_occupancy);
/* Check if we misssed the interrupt. */
- WARN_ON(cfhsi->dev->cfhsi_get_peer_wake(cfhsi->dev,
+ WARN_ON(cfhsi->ops->cfhsi_get_peer_wake(cfhsi->ops,
&ca_wake));
if (ca_wake) {
@@ -852,7 +851,7 @@ static void cfhsi_wake_up(struct work_struct *work)
}
clear_bit(CFHSI_WAKE_UP, &cfhsi->bits);
- cfhsi->dev->cfhsi_wake_down(cfhsi->dev);
+ cfhsi->ops->cfhsi_wake_down(cfhsi->ops);
return;
}
wake_ack:
@@ -865,7 +864,7 @@ wake_ack:
/* Resume read operation. */
netdev_dbg(cfhsi->ndev, "%s: Start RX.\n", __func__);
- res = cfhsi->dev->cfhsi_rx(cfhsi->rx_ptr, cfhsi->rx_len, cfhsi->dev);
+ res = cfhsi->ops->cfhsi_rx(cfhsi->rx_ptr, cfhsi->rx_len, cfhsi->ops);
if (WARN_ON(res < 0))
netdev_err(cfhsi->ndev, "%s: RX err %d.\n", __func__, res);
@@ -896,7 +895,7 @@ wake_ack:
if (likely(len > 0)) {
/* Set up new transfer. */
- res = cfhsi->dev->cfhsi_tx(cfhsi->tx_buf, len, cfhsi->dev);
+ res = cfhsi->ops->cfhsi_tx(cfhsi->tx_buf, len, cfhsi->ops);
if (WARN_ON(res < 0)) {
netdev_err(cfhsi->ndev, "%s: TX error %d.\n",
__func__, res);
@@ -923,7 +922,7 @@ static void cfhsi_wake_down(struct work_struct *work)
return;
/* Deactivate wake line. */
- cfhsi->dev->cfhsi_wake_down(cfhsi->dev);
+ cfhsi->ops->cfhsi_wake_down(cfhsi->ops);
/* Wait for acknowledge. */
ret = CFHSI_WAKE_TOUT;
@@ -942,7 +941,7 @@ static void cfhsi_wake_down(struct work_struct *work)
netdev_err(cfhsi->ndev, "%s: Timeout.\n", __func__);
/* Check if we misssed the interrupt. */
- WARN_ON(cfhsi->dev->cfhsi_get_peer_wake(cfhsi->dev,
+ WARN_ON(cfhsi->ops->cfhsi_get_peer_wake(cfhsi->ops,
&ca_wake));
if (!ca_wake)
netdev_err(cfhsi->ndev, "%s: CA Wake missed !.\n",
@@ -951,7 +950,7 @@ static void cfhsi_wake_down(struct work_struct *work)
/* Check FIFO occupancy. */
while (retry) {
- WARN_ON(cfhsi->dev->cfhsi_fifo_occupancy(cfhsi->dev,
+ WARN_ON(cfhsi->ops->cfhsi_fifo_occupancy(cfhsi->ops,
&fifo_occupancy));
if (!fifo_occupancy)
@@ -969,8 +968,7 @@ static void cfhsi_wake_down(struct work_struct *work)
clear_bit(CFHSI_AWAKE, &cfhsi->bits);
/* Cancel pending RX requests. */
- cfhsi->dev->cfhsi_rx_cancel(cfhsi->dev);
-
+ cfhsi->ops->cfhsi_rx_cancel(cfhsi->ops);
}
static void cfhsi_out_of_sync(struct work_struct *work)
@@ -984,11 +982,11 @@ static void cfhsi_out_of_sync(struct work_struct *work)
rtnl_unlock();
}
-static void cfhsi_wake_up_cb(struct cfhsi_drv *drv)
+static void cfhsi_wake_up_cb(struct cfhsi_cb_ops *cb_ops)
{
struct cfhsi *cfhsi = NULL;
- cfhsi = container_of(drv, struct cfhsi, drv);
+ cfhsi = container_of(cb_ops, struct cfhsi, cb_ops);
netdev_dbg(cfhsi->ndev, "%s.\n",
__func__);
@@ -1003,11 +1001,11 @@ static void cfhsi_wake_up_cb(struct cfhsi_drv *drv)
queue_work(cfhsi->wq, &cfhsi->wake_up_work);
}
-static void cfhsi_wake_down_cb(struct cfhsi_drv *drv)
+static void cfhsi_wake_down_cb(struct cfhsi_cb_ops *cb_ops)
{
struct cfhsi *cfhsi = NULL;
- cfhsi = container_of(drv, struct cfhsi, drv);
+ cfhsi = container_of(cb_ops, struct cfhsi, cb_ops);
netdev_dbg(cfhsi->ndev, "%s.\n",
__func__);
@@ -1110,7 +1108,7 @@ static int cfhsi_xmit(struct sk_buff *skb, struct net_device *dev)
WARN_ON(!len);
/* Set up new transfer. */
- res = cfhsi->dev->cfhsi_tx(cfhsi->tx_buf, len, cfhsi->dev);
+ res = cfhsi->ops->cfhsi_tx(cfhsi->tx_buf, len, cfhsi->ops);
if (WARN_ON(res < 0)) {
netdev_err(cfhsi->ndev, "%s: TX error %d.\n",
__func__, res);
@@ -1125,19 +1123,19 @@ static int cfhsi_xmit(struct sk_buff *skb, struct net_device *dev)
return 0;
}
-static const struct net_device_ops cfhsi_ops;
+static const struct net_device_ops cfhsi_netdevops;
static void cfhsi_setup(struct net_device *dev)
{
int i;
struct cfhsi *cfhsi = netdev_priv(dev);
dev->features = 0;
- dev->netdev_ops = &cfhsi_ops;
dev->type = ARPHRD_CAIF;
dev->flags = IFF_POINTOPOINT | IFF_NOARP;
dev->mtu = CFHSI_MAX_CAIF_FRAME_SZ;
dev->tx_queue_len = 0;
dev->destructor = free_netdev;
+ dev->netdev_ops = &cfhsi_netdevops;
for (i = 0; i < CFHSI_PRIO_LAST; ++i)
skb_queue_head_init(&cfhsi->qhead[i]);
cfhsi->cfdev.link_select = CAIF_LINK_HIGH_BANDW;
@@ -1213,10 +1211,10 @@ static int cfhsi_open(struct net_device *ndev)
spin_lock_init(&cfhsi->lock);
/* Set up the driver. */
- cfhsi->drv.tx_done_cb = cfhsi_tx_done_cb;
- cfhsi->drv.rx_done_cb = cfhsi_rx_done_cb;
- cfhsi->drv.wake_up_cb = cfhsi_wake_up_cb;
- cfhsi->drv.wake_down_cb = cfhsi_wake_down_cb;
+ cfhsi->cb_ops.tx_done_cb = cfhsi_tx_done_cb;
+ cfhsi->cb_ops.rx_done_cb = cfhsi_rx_done_cb;
+ cfhsi->cb_ops.wake_up_cb = cfhsi_wake_up_cb;
+ cfhsi->cb_ops.wake_down_cb = cfhsi_wake_down_cb;
/* Initialize the work queues. */
INIT_WORK(&cfhsi->wake_up_work, cfhsi_wake_up);
@@ -1230,7 +1228,7 @@ static int cfhsi_open(struct net_device *ndev)
clear_bit(CFHSI_AWAKE, &cfhsi->bits);
/* Create work thread. */
- cfhsi->wq = create_singlethread_workqueue(cfhsi->pdev->name);
+ cfhsi->wq = create_singlethread_workqueue(cfhsi->ndev->name);
if (!cfhsi->wq) {
netdev_err(cfhsi->ndev, "%s: Failed to create work queue.\n",
__func__);
@@ -1257,7 +1255,7 @@ static int cfhsi_open(struct net_device *ndev)
cfhsi->aggregation_timer.function = cfhsi_aggregation_tout;
/* Activate HSI interface. */
- res = cfhsi->dev->cfhsi_up(cfhsi->dev);
+ res = cfhsi->ops->cfhsi_up(cfhsi->ops);
if (res) {
netdev_err(cfhsi->ndev,
"%s: can't activate HSI interface: %d.\n",
@@ -1275,7 +1273,7 @@ static int cfhsi_open(struct net_device *ndev)
return res;
err_net_reg:
- cfhsi->dev->cfhsi_down(cfhsi->dev);
+ cfhsi->ops->cfhsi_down(cfhsi->ops);
err_activate:
destroy_workqueue(cfhsi->wq);
err_create_wq:
@@ -1305,7 +1303,7 @@ static int cfhsi_close(struct net_device *ndev)
del_timer_sync(&cfhsi->aggregation_timer);
/* Cancel pending RX request (if any) */
- cfhsi->dev->cfhsi_rx_cancel(cfhsi->dev);
+ cfhsi->ops->cfhsi_rx_cancel(cfhsi->ops);
/* Destroy workqueue */
destroy_workqueue(cfhsi->wq);
@@ -1318,7 +1316,7 @@ static int cfhsi_close(struct net_device *ndev)
cfhsi_abort_tx(cfhsi);
/* Deactivate interface */
- cfhsi->dev->cfhsi_down(cfhsi->dev);
+ cfhsi->ops->cfhsi_down(cfhsi->ops);
/* Free buffers. */
kfree(tx_buf);
@@ -1335,7 +1333,7 @@ static void cfhsi_uninit(struct net_device *dev)
list_del(&cfhsi->list);
}
-static const struct net_device_ops cfhsi_ops = {
+static const struct net_device_ops cfhsi_netdevops = {
.ndo_uninit = cfhsi_uninit,
.ndo_open = cfhsi_open,
.ndo_stop = cfhsi_close,
@@ -1419,7 +1417,7 @@ static int caif_hsi_newlink(struct net *src_net, struct net_device *dev,
struct nlattr *tb[], struct nlattr *data[])
{
struct cfhsi *cfhsi = NULL;
- struct platform_device *(*get_dev)(void);
+ struct cfhsi_ops *(*get_ops)(void);
ASSERT_RTNL();
@@ -1427,36 +1425,31 @@ static int caif_hsi_newlink(struct net *src_net, struct net_device *dev,
cfhsi_netlink_parms(data, cfhsi);
dev_net_set(cfhsi->ndev, src_net);
- get_dev = symbol_get(cfhsi_get_device);
- if (!get_dev) {
- pr_err("%s: failed to get the cfhsi device symbol\n", __func__);
+ get_ops = symbol_get(cfhsi_get_ops);
+ if (!get_ops) {
+ pr_err("%s: failed to get the cfhsi_ops\n", __func__);
return -ENODEV;
}
/* Assign the HSI device. */
- cfhsi->pdev = (*get_dev)();
- if (!cfhsi->pdev) {
- pr_err("%s: failed to get the cfhsi device\n", __func__);
+ cfhsi->ops = (*get_ops)();
+ if (!cfhsi->ops) {
+ pr_err("%s: failed to get the cfhsi_ops\n", __func__);
goto err;
}
- /* Assign the HSI device. */
- cfhsi->dev = cfhsi->pdev->dev.platform_data;
-
/* Assign the driver to this HSI device. */
- cfhsi->dev->drv = &cfhsi->drv;
-
+ cfhsi->ops->cb_ops = &cfhsi->cb_ops;
if (register_netdevice(dev)) {
- pr_warn("%s: device rtml registration failed\n", __func__);
+ pr_warn("%s: caif_hsi device registration failed\n", __func__);
goto err;
-
}
/* Add CAIF HSI device to list. */
list_add_tail(&cfhsi->list, &cfhsi_list);
return 0;
err:
- symbol_put(cfhsi_get_device);
+ symbol_put(cfhsi_get_ops);
return -ENODEV;
}
diff --git a/include/net/caif/caif_hsi.h b/include/net/caif/caif_hsi.h
index a77b2bd..6dc7dc2 100644
--- a/include/net/caif/caif_hsi.h
+++ b/include/net/caif/caif_hsi.h
@@ -93,25 +93,25 @@ struct cfhsi_desc {
#endif
/* Structure implemented by the CAIF HSI driver. */
-struct cfhsi_drv {
- void (*tx_done_cb) (struct cfhsi_drv *drv);
- void (*rx_done_cb) (struct cfhsi_drv *drv);
- void (*wake_up_cb) (struct cfhsi_drv *drv);
- void (*wake_down_cb) (struct cfhsi_drv *drv);
+struct cfhsi_cb_ops {
+ void (*tx_done_cb) (struct cfhsi_cb_ops *drv);
+ void (*rx_done_cb) (struct cfhsi_cb_ops *drv);
+ void (*wake_up_cb) (struct cfhsi_cb_ops *drv);
+ void (*wake_down_cb) (struct cfhsi_cb_ops *drv);
};
/* Structure implemented by HSI device. */
-struct cfhsi_dev {
- int (*cfhsi_up) (struct cfhsi_dev *dev);
- int (*cfhsi_down) (struct cfhsi_dev *dev);
- int (*cfhsi_tx) (u8 *ptr, int len, struct cfhsi_dev *dev);
- int (*cfhsi_rx) (u8 *ptr, int len, struct cfhsi_dev *dev);
- int (*cfhsi_wake_up) (struct cfhsi_dev *dev);
- int (*cfhsi_wake_down) (struct cfhsi_dev *dev);
- int (*cfhsi_get_peer_wake) (struct cfhsi_dev *dev, bool *status);
- int (*cfhsi_fifo_occupancy)(struct cfhsi_dev *dev, size_t *occupancy);
- int (*cfhsi_rx_cancel)(struct cfhsi_dev *dev);
- struct cfhsi_drv *drv;
+struct cfhsi_ops {
+ int (*cfhsi_up) (struct cfhsi_ops *dev);
+ int (*cfhsi_down) (struct cfhsi_ops *dev);
+ int (*cfhsi_tx) (u8 *ptr, int len, struct cfhsi_ops *dev);
+ int (*cfhsi_rx) (u8 *ptr, int len, struct cfhsi_ops *dev);
+ int (*cfhsi_wake_up) (struct cfhsi_ops *dev);
+ int (*cfhsi_wake_down) (struct cfhsi_ops *dev);
+ int (*cfhsi_get_peer_wake) (struct cfhsi_ops *dev, bool *status);
+ int (*cfhsi_fifo_occupancy) (struct cfhsi_ops *dev, size_t *occupancy);
+ int (*cfhsi_rx_cancel)(struct cfhsi_ops *dev);
+ struct cfhsi_cb_ops *cb_ops;
};
/* Structure holds status of received CAIF frames processing */
@@ -138,8 +138,8 @@ struct cfhsi {
struct net_device *ndev;
struct platform_device *pdev;
struct sk_buff_head qhead[CFHSI_PRIO_LAST];
- struct cfhsi_drv drv;
- struct cfhsi_dev *dev;
+ struct cfhsi_cb_ops cb_ops;
+ struct cfhsi_ops *ops;
int tx_state;
struct cfhsi_rx_state rx_state;
unsigned long inactivity_timeout;
@@ -190,6 +190,6 @@ enum ifla_caif_hsi {
__IFLA_CAIF_HSI_MAX
};
-extern struct platform_device *cfhsi_get_device(void);
+extern struct cfhsi_ops *cfhsi_get_ops(void);
#endif /* CAIF_HSI_H_ */
--
1.7.5.4
^ permalink raw reply related
* [net-next 09/11] caif-hsi: Add rtnl support
From: sjur.brandeland @ 2012-06-25 17:49 UTC (permalink / raw)
To: davem; +Cc: netdev, sjurbren, Sjur Brændeland
In-Reply-To: <1340646583-21059-1-git-send-email-sjur.brandeland@stericsson.com>
From: Sjur Brændeland <sjur.brandeland@stericsson.com>
Add RTNL support for managing the caif hsi interface.
The HSI HW interface is no longer registering as a device,
instead we use symbol_get to get hold of the HSI API.
Signed-off-by: Sjur Brændeland <sjur.brandeland@stericsson.com>
---
drivers/net/caif/caif_hsi.c | 226 ++++++++++++++++++++++++++-----------------
include/net/caif/caif_hsi.h | 21 ++++-
2 files changed, 157 insertions(+), 90 deletions(-)
diff --git a/drivers/net/caif/caif_hsi.c b/drivers/net/caif/caif_hsi.c
index d80759e..a14f85c 100644
--- a/drivers/net/caif/caif_hsi.c
+++ b/drivers/net/caif/caif_hsi.c
@@ -20,7 +20,7 @@
#include <linux/sched.h>
#include <linux/if_arp.h>
#include <linux/timer.h>
-#include <linux/rtnetlink.h>
+#include <net/rtnetlink.h>
#include <linux/pkt_sched.h>
#include <net/caif/caif_layer.h>
#include <net/caif/caif_hsi.h>
@@ -79,7 +79,6 @@ MODULE_PARM_DESC(hsi_low_threshold, "HSI high threshold (FLOW ON).");
#define HIGH_WATER_MARK hsi_high_threshold
static LIST_HEAD(cfhsi_list);
-static spinlock_t cfhsi_list_lock;
static void cfhsi_inactivity_tout(unsigned long arg)
{
@@ -1148,42 +1147,6 @@ static void cfhsi_setup(struct net_device *dev)
cfhsi->ndev = dev;
}
-int cfhsi_probe(struct platform_device *pdev)
-{
- struct cfhsi *cfhsi = NULL;
- struct net_device *ndev;
-
- int res;
-
- ndev = alloc_netdev(sizeof(struct cfhsi), "cfhsi%d", cfhsi_setup);
- if (!ndev)
- return -ENODEV;
-
- cfhsi = netdev_priv(ndev);
- cfhsi->ndev = ndev;
- cfhsi->pdev = pdev;
-
- /* Assign the HSI device. */
- cfhsi->dev = pdev->dev.platform_data;
-
- /* Assign the driver to this HSI device. */
- cfhsi->dev->drv = &cfhsi->drv;
-
- /* Register network device. */
- res = register_netdev(ndev);
- if (res) {
- dev_err(&ndev->dev, "%s: Registration error: %d.\n",
- __func__, res);
- free_netdev(ndev);
- }
- /* Add CAIF HSI device to list. */
- spin_lock(&cfhsi_list_lock);
- list_add_tail(&cfhsi->list, &cfhsi_list);
- spin_unlock(&cfhsi_list_lock);
-
- return res;
-}
-
static int cfhsi_open(struct net_device *ndev)
{
struct cfhsi *cfhsi = netdev_priv(ndev);
@@ -1364,85 +1327,170 @@ static int cfhsi_close(struct net_device *ndev)
return 0;
}
+static void cfhsi_uninit(struct net_device *dev)
+{
+ struct cfhsi *cfhsi = netdev_priv(dev);
+ ASSERT_RTNL();
+ symbol_put(cfhsi_get_device);
+ list_del(&cfhsi->list);
+}
+
static const struct net_device_ops cfhsi_ops = {
+ .ndo_uninit = cfhsi_uninit,
.ndo_open = cfhsi_open,
.ndo_stop = cfhsi_close,
.ndo_start_xmit = cfhsi_xmit
};
-int cfhsi_remove(struct platform_device *pdev)
+static void cfhsi_netlink_parms(struct nlattr *data[], struct cfhsi *cfhsi)
{
- struct list_head *list_node;
- struct list_head *n;
- struct cfhsi *cfhsi = NULL;
- struct cfhsi_dev *dev;
+ int i;
- dev = (struct cfhsi_dev *)pdev->dev.platform_data;
- spin_lock(&cfhsi_list_lock);
- list_for_each_safe(list_node, n, &cfhsi_list) {
- cfhsi = list_entry(list_node, struct cfhsi, list);
- /* Find the corresponding device. */
- if (cfhsi->dev == dev) {
- /* Remove from list. */
- list_del(list_node);
- spin_unlock(&cfhsi_list_lock);
- return 0;
- }
+ if (!data) {
+ pr_debug("no params data found\n");
+ return;
}
- spin_unlock(&cfhsi_list_lock);
- return -ENODEV;
+
+ i = __IFLA_CAIF_HSI_INACTIVITY_TOUT;
+ if (data[i])
+ inactivity_timeout = nla_get_u32(data[i]);
+
+ i = __IFLA_CAIF_HSI_AGGREGATION_TOUT;
+ if (data[i])
+ aggregation_timeout = nla_get_u32(data[i]);
+
+ i = __IFLA_CAIF_HSI_HEAD_ALIGN;
+ if (data[i])
+ hsi_head_align = nla_get_u32(data[i]);
+
+ i = __IFLA_CAIF_HSI_TAIL_ALIGN;
+ if (data[i])
+ hsi_tail_align = nla_get_u32(data[i]);
+
+ i = __IFLA_CAIF_HSI_QHIGH_WATERMARK;
+ if (data[i])
+ hsi_high_threshold = nla_get_u32(data[i]);
+}
+
+static int caif_hsi_changelink(struct net_device *dev, struct nlattr *tb[],
+ struct nlattr *data[])
+{
+ cfhsi_netlink_parms(data, netdev_priv(dev));
+ netdev_state_change(dev);
+ return 0;
}
-struct platform_driver cfhsi_plat_drv = {
- .probe = cfhsi_probe,
- .remove = cfhsi_remove,
- .driver = {
- .name = "cfhsi",
- .owner = THIS_MODULE,
- },
+static const struct nla_policy caif_hsi_policy[__IFLA_CAIF_HSI_MAX + 1] = {
+ [__IFLA_CAIF_HSI_INACTIVITY_TOUT] = { .type = NLA_U32, .len = 4 },
+ [__IFLA_CAIF_HSI_AGGREGATION_TOUT] = { .type = NLA_U32, .len = 4 },
+ [__IFLA_CAIF_HSI_HEAD_ALIGN] = { .type = NLA_U32, .len = 4 },
+ [__IFLA_CAIF_HSI_TAIL_ALIGN] = { .type = NLA_U32, .len = 4 },
+ [__IFLA_CAIF_HSI_QHIGH_WATERMARK] = { .type = NLA_U32, .len = 4 },
+ [__IFLA_CAIF_HSI_QLOW_WATERMARK] = { .type = NLA_U32, .len = 4 },
};
-static void __exit cfhsi_exit_module(void)
+static size_t caif_hsi_get_size(const struct net_device *dev)
+{
+ int i;
+ size_t s = 0;
+ for (i = __IFLA_CAIF_HSI_UNSPEC + 1; i < __IFLA_CAIF_HSI_MAX; i++)
+ s += nla_total_size(caif_hsi_policy[i].len);
+ return s;
+}
+
+static int caif_hsi_fill_info(struct sk_buff *skb, const struct net_device *dev)
+{
+ if (nla_put_u32(skb, __IFLA_CAIF_HSI_INACTIVITY_TOUT,
+ inactivity_timeout) ||
+ nla_put_u32(skb, __IFLA_CAIF_HSI_AGGREGATION_TOUT,
+ aggregation_timeout) ||
+ nla_put_u32(skb, __IFLA_CAIF_HSI_HEAD_ALIGN, hsi_head_align) ||
+ nla_put_u32(skb, __IFLA_CAIF_HSI_TAIL_ALIGN, hsi_tail_align) ||
+ nla_put_u32(skb, __IFLA_CAIF_HSI_QHIGH_WATERMARK,
+ hsi_high_threshold) ||
+ nla_put_u32(skb, __IFLA_CAIF_HSI_QLOW_WATERMARK,
+ hsi_low_threshold))
+ return -EMSGSIZE;
+
+ return 0;
+}
+
+static int caif_hsi_newlink(struct net *src_net, struct net_device *dev,
+ struct nlattr *tb[], struct nlattr *data[])
{
- struct list_head *list_node;
- struct list_head *n;
struct cfhsi *cfhsi = NULL;
+ struct platform_device *(*get_dev)(void);
- spin_lock(&cfhsi_list_lock);
- list_for_each_safe(list_node, n, &cfhsi_list) {
- cfhsi = list_entry(list_node, struct cfhsi, list);
+ ASSERT_RTNL();
+
+ cfhsi = netdev_priv(dev);
+ cfhsi_netlink_parms(data, cfhsi);
+ dev_net_set(cfhsi->ndev, src_net);
+
+ get_dev = symbol_get(cfhsi_get_device);
+ if (!get_dev) {
+ pr_err("%s: failed to get the cfhsi device symbol\n", __func__);
+ return -ENODEV;
+ }
+
+ /* Assign the HSI device. */
+ cfhsi->pdev = (*get_dev)();
+ if (!cfhsi->pdev) {
+ pr_err("%s: failed to get the cfhsi device\n", __func__);
+ goto err;
+ }
- /* Remove from list. */
- list_del(list_node);
- spin_unlock(&cfhsi_list_lock);
+ /* Assign the HSI device. */
+ cfhsi->dev = cfhsi->pdev->dev.platform_data;
+
+ /* Assign the driver to this HSI device. */
+ cfhsi->dev->drv = &cfhsi->drv;
- unregister_netdevice(cfhsi->ndev);
+ if (register_netdevice(dev)) {
+ pr_warn("%s: device rtml registration failed\n", __func__);
+ goto err;
- spin_lock(&cfhsi_list_lock);
}
- spin_unlock(&cfhsi_list_lock);
+ /* Add CAIF HSI device to list. */
+ list_add_tail(&cfhsi->list, &cfhsi_list);
- /* Unregister platform driver. */
- platform_driver_unregister(&cfhsi_plat_drv);
+ return 0;
+err:
+ symbol_put(cfhsi_get_device);
+ return -ENODEV;
}
-static int __init cfhsi_init_module(void)
+static struct rtnl_link_ops caif_hsi_link_ops __read_mostly = {
+ .kind = "cfhsi",
+ .priv_size = sizeof(struct cfhsi),
+ .setup = cfhsi_setup,
+ .maxtype = __IFLA_CAIF_HSI_MAX,
+ .policy = caif_hsi_policy,
+ .newlink = caif_hsi_newlink,
+ .changelink = caif_hsi_changelink,
+ .get_size = caif_hsi_get_size,
+ .fill_info = caif_hsi_fill_info,
+};
+
+static void __exit cfhsi_exit_module(void)
{
- int result;
+ struct list_head *list_node;
+ struct list_head *n;
+ struct cfhsi *cfhsi;
- /* Initialize spin lock. */
- spin_lock_init(&cfhsi_list_lock);
+ rtnl_link_unregister(&caif_hsi_link_ops);
- /* Register platform driver. */
- result = platform_driver_register(&cfhsi_plat_drv);
- if (result) {
- printk(KERN_ERR "Could not register platform HSI driver: %d.\n",
- result);
- goto err_dev_register;
+ rtnl_lock();
+ list_for_each_safe(list_node, n, &cfhsi_list) {
+ cfhsi = list_entry(list_node, struct cfhsi, list);
+ unregister_netdev(cfhsi->ndev);
}
+ rtnl_unlock();
+}
- err_dev_register:
- return result;
+static int __init cfhsi_init_module(void)
+{
+ return rtnl_link_register(&caif_hsi_link_ops);
}
module_init(cfhsi_init_module);
diff --git a/include/net/caif/caif_hsi.h b/include/net/caif/caif_hsi.h
index 439dadc..a77b2bd 100644
--- a/include/net/caif/caif_hsi.h
+++ b/include/net/caif/caif_hsi.h
@@ -170,7 +170,26 @@ struct cfhsi {
unsigned long bits;
};
-
extern struct platform_driver cfhsi_driver;
+/**
+ * enum ifla_caif_hsi - CAIF HSI NetlinkRT parameters.
+ * @IFLA_CAIF_HSI_INACTIVITY_TOUT: Inactivity timeout before
+ * taking the HSI wakeline down, in milliseconds.
+ * When using RT Netlink to create, destroy or configure a CAIF HSI interface,
+ * enum ifla_caif_hsi is used to specify the configuration attributes.
+ */
+enum ifla_caif_hsi {
+ __IFLA_CAIF_HSI_UNSPEC,
+ __IFLA_CAIF_HSI_INACTIVITY_TOUT,
+ __IFLA_CAIF_HSI_AGGREGATION_TOUT,
+ __IFLA_CAIF_HSI_HEAD_ALIGN,
+ __IFLA_CAIF_HSI_TAIL_ALIGN,
+ __IFLA_CAIF_HSI_QHIGH_WATERMARK,
+ __IFLA_CAIF_HSI_QLOW_WATERMARK,
+ __IFLA_CAIF_HSI_MAX
+};
+
+extern struct platform_device *cfhsi_get_device(void);
+
#endif /* CAIF_HSI_H_ */
--
1.7.5.4
^ permalink raw reply related
* [net-next 08/11] Documentation/networking/caif: Update documentation
From: sjur.brandeland @ 2012-06-25 17:49 UTC (permalink / raw)
To: davem; +Cc: netdev, sjurbren, Sjur Brændeland, Sjur Brændeland
In-Reply-To: <1340646583-21059-1-git-send-email-sjur.brandeland@stericsson.com>
From: Sjur Brændeland <sjur.brandeland@stericsson.com>
Update drawing and remove description of old features.
Add HSI and USB link layers to the drawing.
Reported-by: Joerg Reisenweber <joerg.reisenweber@stericssion.com>
Signed-off-by: Sjur Brændeland <sjur.brandeland@stericssion.com>
---
Documentation/networking/caif/Linux-CAIF.txt | 91 ++++++++------------------
1 files changed, 27 insertions(+), 64 deletions(-)
diff --git a/Documentation/networking/caif/Linux-CAIF.txt b/Documentation/networking/caif/Linux-CAIF.txt
index e52fd62..0aa4bd3 100644
--- a/Documentation/networking/caif/Linux-CAIF.txt
+++ b/Documentation/networking/caif/Linux-CAIF.txt
@@ -19,60 +19,36 @@ and host. Currently, UART and Loopback are available for Linux.
Architecture:
------------
The implementation of CAIF is divided into:
-* CAIF Socket Layer, Kernel API, and Net Device.
+* CAIF Socket Layer and GPRS IP Interface.
* CAIF Core Protocol Implementation
* CAIF Link Layer, implemented as NET devices.
RTNL
!
- ! +------+ +------+ +------+
- ! +------+! +------+! +------+!
- ! ! Sock !! !Kernel!! ! Net !!
- ! ! API !+ ! API !+ ! Dev !+ <- CAIF Client APIs
- ! +------+ +------! +------+
- ! ! ! !
- ! +----------!----------+
- ! +------+ <- CAIF Protocol Implementation
- +-------> ! CAIF !
- ! Core !
- +------+
- +--------!--------+
- ! !
- +------+ +-----+
- ! ! ! TTY ! <- Link Layer (Net Devices)
- +------+ +-----+
-
-
-Using the Kernel API
-----------------------
-The Kernel API is used for accessing CAIF channels from the
-kernel.
-The user of the API has to implement two callbacks for receive
-and control.
-The receive callback gives a CAIF packet as a SKB. The control
-callback will
-notify of channel initialization complete, and flow-on/flow-
-off.
-
-
- struct caif_device caif_dev = {
- .caif_config = {
- .name = "MYDEV"
- .type = CAIF_CHTY_AT
- }
- .receive_cb = my_receive,
- .control_cb = my_control,
- };
- caif_add_device(&caif_dev);
- caif_transmit(&caif_dev, skb);
-
-See the caif_kernel.h for details about the CAIF kernel API.
+ ! +------+ +------+
+ ! +------+! +------+!
+ ! ! IP !! !Socket!!
+ +-------> !interf!+ ! API !+ <- CAIF Client APIs
+ ! +------+ +------!
+ ! ! !
+ ! +-----------+
+ ! !
+ ! +------+ <- CAIF Core Protocol
+ ! ! CAIF !
+ ! ! Core !
+ ! +------+
+ ! +----------!---------+
+ ! ! ! !
+ ! +------+ +-----+ +------+
+ +--> ! HSI ! ! TTY ! ! USB ! <- Link Layer (Net Devices)
+ +------+ +-----+ +------+
+
I M P L E M E N T A T I O N
===========================
-===========================
+
CAIF Core Protocol Layer
=========================================
@@ -88,17 +64,13 @@ The Core CAIF implementation contains:
- Simple implementation of CAIF.
- Layered architecture (a la Streams), each layer in the CAIF
specification is implemented in a separate c-file.
- - Clients must implement PHY layer to access physical HW
- with receive and transmit functions.
- Clients must call configuration function to add PHY layer.
- Clients must implement CAIF layer to consume/produce
CAIF payload with receive and transmit functions.
- Clients must call configuration function to add and connect the
Client layer.
- When receiving / transmitting CAIF Packets (cfpkt), ownership is passed
- to the called function (except for framing layers' receive functions
- or if a transmit function returns an error, in which case the caller
- must free the packet).
+ to the called function (except for framing layers' receive function)
Layered Architecture
--------------------
@@ -109,11 +81,6 @@ Implementation. The support functions include:
CAIF Packet has functions for creating, destroying and adding content
and for adding/extracting header and trailers to protocol packets.
- - CFLST CAIF list implementation.
-
- - CFGLUE CAIF Glue. Contains OS Specifics, such as memory
- allocation, endianness, etc.
-
The CAIF Protocol implementation contains:
- CFCNFG CAIF Configuration layer. Configures the CAIF Protocol
@@ -128,7 +95,7 @@ The CAIF Protocol implementation contains:
control and remote shutdown requests.
- CFVEI CAIF VEI layer. Handles CAIF AT Channels on VEI (Virtual
- External Interface). This layer encodes/decodes VEI frames.
+ External Interface). This layer encodes/decodes VEI frames.
- CFDGML CAIF Datagram layer. Handles CAIF Datagram layer (IP
traffic), encodes/decodes Datagram frames.
@@ -170,7 +137,7 @@ The CAIF Protocol implementation contains:
+---------+ +---------+
! !
+---------+ +---------+
- | | | Serial |
+ | | | Serial |
| | | CFSERL |
+---------+ +---------+
@@ -186,24 +153,20 @@ In this layered approach the following "rules" apply.
layer->dn->transmit(layer->dn, packet);
-Linux Driver Implementation
+CAIF Socket and IP interface
===========================
-Linux GPRS Net Device and CAIF socket are implemented on top of the
-CAIF Core protocol. The Net device and CAIF socket have an instance of
+The IP interface and CAIF socket API are implemented on top of the
+CAIF Core protocol. The IP Interface and CAIF socket have an instance of
'struct cflayer', just like the CAIF Core protocol stack.
Net device and Socket implement the 'receive()' function defined by
'struct cflayer', just like the rest of the CAIF stack. In this way, transmit and
receive of packets is handled as by the rest of the layers: the 'dn->transmit()'
function is called in order to transmit data.
-The layer on top of the CAIF Core implementation is
-sometimes referred to as the "Client layer".
-
-
Configuration of Link Layer
---------------------------
-The Link Layer is implemented as Linux net devices (struct net_device).
+The Link Layer is implemented as Linux network devices (struct net_device).
Payload handling and registration is done using standard Linux mechanisms.
The CAIF Protocol relies on a loss-less link layer without implementing
--
1.7.5.4
^ permalink raw reply related
* [net-next 07/11] caif-hsi: Remove uncecessary assignments
From: sjur.brandeland @ 2012-06-25 17:49 UTC (permalink / raw)
To: davem; +Cc: netdev, sjurbren, Sjur Brændeland, Sjur Brændeland
In-Reply-To: <1340646583-21059-1-git-send-email-sjur.brandeland@stericsson.com>
From: Sjur Brændeland <sjur.brandeland@stericsson.com>
Remove assignment at declaration when not needed.
Signed-off-by: Sjur Brændeland <sjur.brandeland@stericssion.com>
---
drivers/net/caif/caif_hsi.c | 10 +++++-----
1 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/drivers/net/caif/caif_hsi.c b/drivers/net/caif/caif_hsi.c
index f7997a7..d80759e 100644
--- a/drivers/net/caif/caif_hsi.c
+++ b/drivers/net/caif/caif_hsi.c
@@ -246,8 +246,8 @@ static int cfhsi_tx_frm(struct cfhsi_desc *desc, struct cfhsi *cfhsi)
/* Check if we can embed a CAIF frame. */
if (skb->len < CFHSI_MAX_EMB_FRM_SZ) {
struct caif_payload_info *info;
- int hpad = 0;
- int tpad = 0;
+ int hpad;
+ int tpad;
/* Calculate needed head alignment and tail alignment. */
info = (struct caif_payload_info *)&skb->cb;
@@ -282,8 +282,8 @@ static int cfhsi_tx_frm(struct cfhsi_desc *desc, struct cfhsi *cfhsi)
pfrm = desc->emb_frm + CFHSI_MAX_EMB_FRM_SZ;
while (nfrms < CFHSI_MAX_PKTS) {
struct caif_payload_info *info;
- int hpad = 0;
- int tpad = 0;
+ int hpad;
+ int tpad;
if (!skb)
skb = cfhsi_dequeue(cfhsi);
@@ -573,7 +573,7 @@ static int cfhsi_rx_pld(struct cfhsi_desc *desc, struct cfhsi *cfhsi)
struct sk_buff *skb;
u8 *dst = NULL;
u8 *pcffrm = NULL;
- int len = 0;
+ int len;
/* CAIF frame starts after head padding. */
pcffrm = pfrm + *pfrm + 1;
--
1.7.5.4
^ permalink raw reply related
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox