Subject: Interface detach branch available
To: None <current-users@netbsd.org>
From: Ken Hornstein <kenh@cmf.nrl.navy.mil>
List: current-users
Date: 12/14/1998 17:45:32
As some people have already noted, last week I created a new branch
(called kenh-if-detach) and put code on that branch to do interface
detaching.

To provide some history, the lion's share of this code was originally
done by Bill Studenmund.  Bill got to the point where it was ready to
be used on a "real" system with detachable interfaces, so I took it over
and banged on it a bit to fill in a few missing spots.

The good news: The way it stands now, it seems to be working for me.  I
can detach my 3c589 and it will remove the interface from the interface
list, delete all of the routes associated with the interface, etc etc
... all the right things happen.

The bad news: implementing this requires a number of changes to the
networking code.  Reference counts are now maintained on all ifnet
structures and ifa structures.  The most annoying side effect of this
is that the struct ifnet in the ethercom structure is changed from
a member to a pointer, so many drivers need to be gone through and
have "."'s changed into "->".

Ethernet card drivers need to be modified to support this new code.
I believe most of the drivers already have the basic support (i.e. -
they should "just work" in the most basic mode).  Probably the best
driver to copy in this case is the elink3 driver.  In a nutshell, you
need to:

- call if_alloc() to allocate a new ifnet structure
- Point the ethercom structure to this new ifnet structure
- Point if_ifcom to the address of the ethercom structure.

In terms of adding detach support, you should first modify your device
driver to support generic attach/detach events via the autoconf mechanism.
This basically involves creating new driver activate and detach entry
points.  When these entry points are created, the PCMCIA system will
automatically call these functions at the appropriate time.

In your deactivate function, you should:

- Call if_deactivate(), which disables the device output routines to
  prevent further packets from going out the interface.
- Perform any device-specific deactivation

In your detach function, you should

- Free any device resources allocated by the device driver (like PCMCIA
  address space or allocated memory)
- Call if_detach() to get rid of all traces of the device.

Again, see the ep driver (both the pcmcia front-end and the elink3 backend
code) for an example (can you tell I only own a 3com PCMCIA card? :-/)

As mentioned above, this is all available on the 'kenh-if-detach' CVS
branch.  Right now there is one outstanding bug that I know of, but I'm
working on it.

Comments welcome.  If people could try this out _before_ the 1.4 release
branch gets cut, it would be really great, as real hot-swappable PCMCIA
device support would be a wonderful addition to 1.4.  Enjoy!

--Ken