diff mbox

atmtcp: add sysfs attr for changing atm carrier signal state.

Message ID 1286135485-27355-1-git-send-email-karl@hiramoto.org
State Rejected, archived
Delegated to: David Miller
Headers show

Commit Message

Karl Hiramoto Oct. 3, 2010, 7:51 p.m. UTC
This will be used for device testing carrier signal changes in other parts of
the atm stack.

Carrier lost set by:
echo -n 0 > /sys/class/atm/atmtcp0/carrier

Carrier detected:
echo -n 1 > /sys/class/atm/atmtcp0/carrier

Signed-off-by: Karl Hiramoto <karl@hiramoto.org>
---
 drivers/atm/atmtcp.c |   59 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 59 insertions(+), 0 deletions(-)

Comments

David Miller Oct. 3, 2010, 8 p.m. UTC | #1
From: Karl Hiramoto <karl@hiramoto.org>
Date: Sun,  3 Oct 2010 21:51:25 +0200

> This will be used for device testing carrier signal changes in other parts of
> the atm stack.
> 
> Carrier lost set by:
> echo -n 0 > /sys/class/atm/atmtcp0/carrier
> 
> Carrier detected:
> echo -n 1 > /sys/class/atm/atmtcp0/carrier
> 
> Signed-off-by: Karl Hiramoto <karl@hiramoto.org>

We already have enough sysfs hacky knobs.

And for something as fundamental as setting the carrier status, it's
not acceptable to add a device-type specific control.

Use something we have already, either via core device state management
(via netlink or ifconfig's ioctls) or ethtool.

Thanks.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
index b910181..7540e33 100644
--- a/drivers/atm/atmtcp.c
+++ b/drivers/atm/atmtcp.c
@@ -210,6 +210,18 @@  static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
 		atomic_inc(&vcc->stats->tx_err);
 		return -ENOLINK;
 	}
+
+	if (vcc->dev->signal == ATM_PHY_SIG_LOST) {
+		pr_warning(DEV_LABEL ": Dropping TX pkt, upper layer not handling carrier signal lost\n");
+		if (vcc->pop)
+			vcc->pop(vcc, skb);
+		else
+			dev_kfree_skb(skb);
+
+		atomic_inc(&vcc->stats->tx_err);
+		return -ENOLINK;
+	}
+
 	size = skb->len+sizeof(struct atmtcp_hdr);
 	new_skb = atm_alloc_charge(out_vcc,size,GFP_ATOMIC);
 	if (!new_skb) {
@@ -304,6 +316,12 @@  static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
 		atomic_inc(&vcc->stats->tx_err);
 		goto done;
 	}
+
+	if (out_vcc->dev->signal == ATM_PHY_SIG_LOST) {
+		pr_debug(DEV_LABEL ": Dropping RX pkt while no carrier signal\n");
+		result = -ENOLINK;
+		goto done;
+	}
 	skb_pull(skb,sizeof(struct atmtcp_hdr));
 	new_skb = atm_alloc_charge(out_vcc,skb->len,GFP_KERNEL);
 	if (!new_skb) {
@@ -356,6 +374,43 @@  static struct atm_dev atmtcp_control_dev = {
 	.lock		= __SPIN_LOCK_UNLOCKED(atmtcp_control_dev.lock)
 };
 
+static ssize_t __set_signal(struct device *dev,
+		struct device_attribute *attr,
+		const char *buf, size_t len)
+{
+	struct atm_dev *atm_dev = container_of(dev, struct atm_dev, class_dev);
+	int signal;
+
+	if (sscanf(buf, "%d", &signal) == 1) {
+
+		if (signal < ATM_PHY_SIG_LOST || signal > ATM_PHY_SIG_FOUND)
+			signal = ATM_PHY_SIG_UNKNOWN;
+
+		atm_dev_signal_change(atm_dev, signal);
+		return 1;
+	}
+	return -EINVAL;
+}
+
+static ssize_t __show_signal(struct device *dev,
+	struct device_attribute *attr, char *buf)
+{
+	struct atm_dev *atm_dev = container_of(dev, struct atm_dev, class_dev);
+	return sprintf(buf, "%d\n", atm_dev->signal);
+}
+
+static DEVICE_ATTR(signal, 0644, __show_signal, __set_signal);
+
+static struct attribute *atmtcp_attrs[] = {
+	&dev_attr_signal.attr,
+	NULL
+};
+
+static struct attribute_group atmtcp_group_attrs = {
+	.name = NULL, /* We want them in dev's root folder */
+	.attrs = atmtcp_attrs
+};
+
 
 static int atmtcp_create(int itf,int persist,struct atm_dev **result)
 {
@@ -376,6 +431,10 @@  static int atmtcp_create(int itf,int persist,struct atm_dev **result)
 	dev->dev_data = dev_data;
 	PRIV(dev)->vcc = NULL;
 	PRIV(dev)->persist = persist;
+
+	if (sysfs_create_group(&dev->class_dev.kobj, &atmtcp_group_attrs))
+		dev_err(&dev->class_dev, "Could not register sysfs attrs for atmtcp\n");
+
 	if (result) *result = dev;
 	return 0;
 }