netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Richter <stefanr@s5r6.in-berlin.de>
To: Maxim Levitsky <maximlevitsky@gmail.com>
Cc: Peter Stuge <peter@stuge.se>,
	<linux1394-devel@lists.sourceforge.net>,
	netdev@vger.kernel.org
Subject: [PATCH update] firewire: net: add carrier detection
Date: Sun, 12 Dec 2010 18:09:16 +0100	[thread overview]
Message-ID: <20101212180916.71a57a71@stein> (raw)
In-Reply-To: <1291809485.5421.0.camel@maxim-laptop>

From: Maxim Levitsky <maximlevitsky@gmail.com>

To make userland, e.g. NetworkManager work with firewire, we need to
detect whether cable is plugged or not.  Simple and correct way of doing
that is just counting number of peers.  No peers - no link and vice
versa.

Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
---
Update:  Moved netif_carrier_on/off calls into lock-protected sections.

 drivers/firewire/net.c |   10 ++++++++++
 1 file changed, 10 insertions(+)

Index: b/drivers/firewire/net.c
===================================================================
--- a/drivers/firewire/net.c
+++ b/drivers/firewire/net.c
@@ -179,6 +179,7 @@ struct fwnet_device {
 	/* Number of tx datagrams that have been queued but not yet acked */
 	int queued_datagrams;
 
+	int peer_count;
 	struct list_head peer_list;
 	struct fw_card *card;
 	struct net_device *netdev;
@@ -1405,6 +1406,10 @@ static int fwnet_change_mtu(struct net_d
 	return 0;
 }
 
+static const struct ethtool_ops fwnet_ethtool_ops = {
+	.get_link	= ethtool_op_get_link,
+};
+
 static const struct net_device_ops fwnet_netdev_ops = {
 	.ndo_open       = fwnet_open,
 	.ndo_stop	= fwnet_stop,
@@ -1423,6 +1428,7 @@ static void fwnet_init_dev(struct net_de
 	net->hard_header_len	= FWNET_HLEN;
 	net->type		= ARPHRD_IEEE1394;
 	net->tx_queue_len	= FWNET_TX_QUEUE_LEN;
+	net->ethtool_ops	= &fwnet_ethtool_ops;
 }
 
 /* caller must hold fwnet_device_mutex */
@@ -1463,6 +1469,8 @@ static int fwnet_add_peer(struct fwnet_d
 
 	spin_lock_irq(&dev->lock);
 	list_add_tail(&peer->peer_link, &dev->peer_list);
+	if (++dev->peer_count > 1)
+		netif_carrier_on(dev->netdev);
 	spin_unlock_irq(&dev->lock);
 
 	return 0;
@@ -1549,6 +1557,8 @@ static void fwnet_remove_peer(struct fwn
 
 	spin_lock_irq(&peer->dev->lock);
 	list_del(&peer->peer_link);
+	if (--peer->dev->peer_count == 1)
+		netif_carrier_off(peer->dev->netdev);
 	spin_unlock_irq(&peer->dev->lock);
 
 	list_for_each_entry_safe(pd, pd_next, &peer->pd_list, pd_link)


-- 
Stefan Richter
-=====-==-=- ==-- -==--
http://arcgraph.de/sr/

  parent reply	other threads:[~2010-12-12 17:09 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-29  2:09 [PATCH 0/5 V2] Firewire networking assorted fixes Maxim Levitsky
2010-11-29  2:09 ` [PATCH 1/5] firewire: ohci: restore GUID on resume Maxim Levitsky
2010-11-29  2:09 ` [PATCH 2/5] firewire: ohci: restart ISO DMA contexts on resume from low power mode Maxim Levitsky
2010-11-29  2:09 ` [PATCH 3/5] NET: IPV4: ARP: allow to invalidate specific ARP entries Maxim Levitsky
2010-12-04 23:15   ` Maxim Levitsky
2010-12-05  8:19     ` Eric Dumazet
2010-12-05 11:23       ` [PATCH] net: RCU conversion of dev_getbyhwaddr() and arp_ioctl() Eric Dumazet
2010-12-05 12:03         ` [PATCH net-2.6] llc: fix a device refcount imbalance Eric Dumazet
2010-12-08 17:59           ` David Miller
2010-12-09  3:46             ` Maxim Levitsky
2010-12-16 21:49               ` Maxim Levitsky
2010-12-08 18:05         ` [PATCH] net: RCU conversion of dev_getbyhwaddr() and arp_ioctl() David Miller
2010-12-08 18:07           ` Eric Dumazet
2010-12-08 18:10             ` David Miller
2010-12-08 18:11               ` Eric Dumazet
2011-01-07 12:47   ` [PATCH 3/5] NET: IPV4: ARP: allow to invalidate specific ARP entries Maxim Levitsky
2011-01-07 12:57     ` Eric Dumazet
2011-01-07 13:15       ` Maxim Levitsky
2011-01-08 23:57       ` Maxim Levitsky
2011-01-11  0:11         ` David Miller
2010-11-29  2:09 ` [PATCH 4/5] firewire: net: invalidate ARP entries of removed nodes Maxim Levitsky
2010-11-29  2:09 ` [PATCH 5/5] firewire: net: ratelimit error messages Maxim Levitsky
2010-11-29 15:02 ` [PATCH 0/5 V2] Firewire networking assorted fixes Stefan Richter
2010-12-04 23:14 ` Maxim Levitsky
2010-12-08  3:32 ` Maxim Levitsky
2010-12-09  1:42   ` Maxim Levitsky
     [not found]   ` <20101208040559.20639.qmail@stuge.se>
     [not found]     ` <1291809485.5421.0.camel@maxim-laptop>
2010-12-12 17:09       ` Stefan Richter [this message]
2010-12-12 23:05         ` [PATCH update] firewire: net: add carrier detection Ben Hutchings
2010-12-13  0:46           ` [PATCH update 2] " Stefan Richter
2010-12-13 23:01             ` [PATCH update 3] " Stefan Richter
2010-12-14 23:46               ` Maxim Levitsky
2010-12-16  1:17               ` Dan Williams

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20101212180916.71a57a71@stein \
    --to=stefanr@s5r6.in-berlin.de \
    --cc=linux1394-devel@lists.sourceforge.net \
    --cc=maximlevitsky@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=peter@stuge.se \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).