Cleanup link state change notification:

o add new if_link_state_change routine that deals with link state changes
o change mii to use if_link_state_change
This commit is contained in:
Sam Leffler 2004-12-08 05:45:59 +00:00
parent 4873d1754f
commit 94f5c9cfc0
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=138542
3 changed files with 40 additions and 30 deletions

View File

@ -228,47 +228,30 @@ miibus_statchg(dev)
return;
}
void (*vlan_link_state_p)(struct ifnet *, int); /* XXX: private from if_vlan */
static void
miibus_linkchg(dev)
device_t dev;
device_t dev;
{
struct mii_data *mii;
struct ifnet *ifp;
device_t parent;
int link, link_state;
struct mii_data *mii;
device_t parent;
int link_state;
parent = device_get_parent(dev);
MIIBUS_LINKCHG(parent);
mii = device_get_softc(dev);
if (mii->mii_media_status & IFM_AVALID) {
if (mii->mii_media_status & IFM_ACTIVE)
link_state = LINK_STATE_UP;
else
link_state = LINK_STATE_DOWN;
} else
link_state = LINK_STATE_UNKNOWN;
/*
* Note that each NIC's softc must start with an ifnet structure.
*/
ifp = device_get_softc(parent);
if (mii->mii_media_status & IFM_AVALID) {
if (mii->mii_media_status & IFM_ACTIVE) {
link = NOTE_LINKUP;
link_state = LINK_STATE_UP;
} else {
link = NOTE_LINKDOWN;
link_state = LINK_STATE_DOWN;
}
} else {
link = NOTE_LINKINV;
link_state = LINK_STATE_UNKNOWN;
}
/* Notify that the link state has changed. */
if (ifp->if_link_state != link_state) {
ifp->if_link_state = link_state;
rt_ifmsg(ifp);
KNOTE_UNLOCKED(&ifp->if_klist, link);
if (ifp->if_nvlans != 0)
(*vlan_link_state_p)(ifp, link);
}
if_link_state_change(device_get_softc(parent), link_state);
}
static void

View File

@ -955,6 +955,32 @@ if_route(struct ifnet *ifp, int flag, int fam)
#endif
}
void (*vlan_link_state_p)(struct ifnet *, int); /* XXX: private from if_vlan */
/*
* Handle a change in the interface link state.
*/
void
if_link_state_change(struct ifnet *ifp, int link_state)
{
int link;
/* Notify that the link state has changed. */
if (ifp->if_link_state != link_state) {
ifp->if_link_state = link_state;
rt_ifmsg(ifp);
if (link_state == LINK_STATE_UP)
link = NOTE_LINKUP;
else if (link_state == LINK_STATE_DOWN)
link = NOTE_LINKDOWN;
else
link = NOTE_LINKINV;
KNOTE_UNLOCKED(&ifp->if_klist, link);
if (ifp->if_nvlans != 0)
(*vlan_link_state_p)(ifp, link);
}
}
/*
* Mark an interface down and notify protocols of
* the transition.

View File

@ -629,6 +629,7 @@ int if_delmulti(struct ifnet *, struct sockaddr *);
void if_detach(struct ifnet *);
void if_down(struct ifnet *);
void if_initname(struct ifnet *, const char *, int);
void if_link_state_change(struct ifnet *, int);
int if_printf(struct ifnet *, const char *, ...) __printflike(2, 3);
int if_setlladdr(struct ifnet *, const u_char *, int);
void if_up(struct ifnet *);