netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] atmtcp: add sysfs attr for changing atm carrier signal state.
@ 2010-10-03 19:51 Karl Hiramoto
  2010-10-03 20:00 ` David Miller
  0 siblings, 1 reply; 2+ messages in thread
From: Karl Hiramoto @ 2010-10-03 19:51 UTC (permalink / raw)
  To: netdev, linux-atm-general; +Cc: chas, davem, Karl Hiramoto

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(-)

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;
 }
-- 
1.7.2.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] atmtcp: add sysfs attr for changing atm carrier signal state.
  2010-10-03 19:51 [PATCH] atmtcp: add sysfs attr for changing atm carrier signal state Karl Hiramoto
@ 2010-10-03 20:00 ` David Miller
  0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2010-10-03 20:00 UTC (permalink / raw)
  To: karl; +Cc: netdev, linux-atm-general, chas

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.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-10-03 20:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-10-03 19:51 [PATCH] atmtcp: add sysfs attr for changing atm carrier signal state Karl Hiramoto
2010-10-03 20:00 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).