public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Jiri Pirko <jiri@resnulli.us>
To: "Robert P. J. Day" <rpjday@crashcourse.ca>
Cc: Linux kernel ntedev mailing list <netdev@vger.kernel.org>
Subject: Re: consequences of setting net_device_ops ndo_change_carrier()?
Date: Sat, 4 Aug 2018 13:47:20 +0200	[thread overview]
Message-ID: <20180804114720.GC2015@nanopsycho> (raw)
In-Reply-To: <alpine.LFD.2.21.1808040646290.25800@localhost.localdomain>

Sat, Aug 04, 2018 at 01:06:58PM CEST, rpjday@crashcourse.ca wrote:
>
>  i'll try to keep this (relatively) short as there may be a simple
>answer to this, or it could just be a stupid question -- sort of
>related to previous question (thank you, florian).
>
>  currently messing with networking device involving FPGA and some
>quad-port transceivers, and noticed that, when one unplugs or plugs a
>device into one of the ports, there is no change in the contents of
>the corresponding sysfs files /sys/class/net/<ifname>/carrier (or
>operstate, for that matter, which might be related to this as well).
>doing this with a "regular" port on my linux laptop certainly
>confirmed that the carrier file would switch between 0 and 1, and
>operstate would switch between up and down, so i know what behaviour i
>was *expecting* if things were ostensibly working properly.
>
>  long story short, i pawed through the driver code only to stumble

What driver? Has to be out of tree as I don't see any in the existing
kernel using .ndo_change_carrier (aside of team and dummy)


>over this in the ethernet driver for the device:
>
>  static const struct net_device_ops netdev_netdev_ops = {
>  ... snip ...
>        .ndo_change_carrier     = netdev_change_carrier,
>  ... snip ...
>  };
>
>and
>
>  static int
>  netdev_change_carrier(struct net_device *dev, bool new_carrier)
>  {
>        if (new_carrier)
>                netif_carrier_on(dev);
>        else
>                netif_carrier_off(dev);
>        return 0;
>  }
>
>as i mentioned before, i am really new to kernel networking code, so i
>did a quick search and found this in netdevice.h:
>
>* int (*ndo_change_carrier)(struct net_device *dev, bool new_carrier);
> *      Called to change device carrier. Soft-devices (like dummy, team, etc)
> *      which do not represent real hardware may define this to allow their
> *      userspace components to manage their virtual carrier state. Devices
> *      that determine carrier state from physical hardware properties (eg
> *      network cables) or protocol-dependent mechanisms (eg
> *      USB_CDC_NOTIFY_NETWORK_CONNECTION) should NOT implement this function.
> *
>
>although i still don't fully understand the purpose of that field, it
>makes me *very* nervous to read that that routine is for "soft"
>devices, and ***not*** for devices that attempt to determine carrier
>state from physical hardware properties. i searched the kernel code
>base for other drivers that set that field, and found only what is
>mentioned in that comment -- dummy.c, of_dummy_mac.c and team.c.
>
>  the testers for this unit are complaining that they are somehow not
>being notified when they plug and unplug devices from the ports -- is
>this why? what would be the purpose of assigning a routine to that
>field? as i read it (and i could be wrong), my impression is that you
>can have the driver *either* determine the carrier state from physical
>properties, *or* allow userspace control, but not both, is that
>correct?

Correct. Your device is physical device, it knows how to get the state
of the carrier itself.


>
>  i'm about to ask the original authors why they did the above, but

I guess that the reason is that they had no clue what they are doing :)


>i'd like to feel that it's not a stupid question if there's something
>really clever going on here. is this just a development debugging
>feature that would normally be removed at production? or what?
>
>rday
>
>-- 
>
>========================================================================
>Robert P. J. Day                                 Ottawa, Ontario, CANADA
>                  http://crashcourse.ca/dokuwiki
>
>Twitter:                                       http://twitter.com/rpjday
>LinkedIn:                               http://ca.linkedin.com/in/rpjday
>========================================================================

  reply	other threads:[~2018-08-04 13:50 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-04 11:06 consequences of setting net_device_ops ndo_change_carrier()? Robert P. J. Day
2018-08-04 11:47 ` Jiri Pirko [this message]
2018-08-04 11:57   ` Robert P. J. Day
2018-08-04 17:26     ` Stephen Hemminger
2018-08-04 17:32       ` Robert P. J. Day
2018-08-05  1:11 ` Andrew Lunn
2018-08-05 10:43   ` Robert P. J. Day
2018-08-05 14:58     ` Andrew Lunn

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=20180804114720.GC2015@nanopsycho \
    --to=jiri@resnulli.us \
    --cc=netdev@vger.kernel.org \
    --cc=rpjday@crashcourse.ca \
    /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