df-link-state.patch
| b/sys/dev/netif/em/if_em.c Thu Mar 15 20:05:40 2007 +0200 | ||
|---|---|---|
| 1788 | 1788 |
static void |
| 1789 | 1789 |
em_update_link_status(struct adapter *adapter) |
| 1790 | 1790 |
{
|
| 1791 |
struct ifnet *ifp; |
|
| 1792 |
ifp = &adapter->interface_data.ac_if; |
|
| 1793 | ||
| 1791 | 1794 |
if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU) {
|
| 1792 | 1795 |
if (adapter->link_active == 0) {
|
| 1793 | 1796 |
em_get_speed_and_duplex(&adapter->hw, |
| ... | ... | |
| 1812 | 1815 |
} |
| 1813 | 1816 |
adapter->link_active = 1; |
| 1814 | 1817 |
adapter->smartspeed = 0; |
| 1815 |
#ifdef notyet |
|
| 1816 | 1818 |
ifp->if_baudrate = adapter->link_speed * 1000000; |
| 1817 |
if_link_state_change(ifp, LINK_STATE_UP);
|
|
| 1818 |
#endif |
|
| 1819 |
ifp->if_link_state = LINK_STATE_UP;
|
|
| 1820 |
if_link_state_change(ifp); |
|
| 1819 | 1821 |
} |
| 1820 | 1822 |
} else {
|
| 1821 | 1823 |
if (adapter->link_active == 1) {
|
| 1822 |
#ifdef notyet |
|
| 1823 | 1824 |
ifp->if_baudrate = 0; |
| 1824 |
#endif |
|
| 1825 | 1825 |
adapter->link_speed = 0; |
| 1826 | 1826 |
adapter->link_duplex = 0; |
| 1827 | 1827 |
if (bootverbose) {
|
| ... | ... | |
| 1829 | 1829 |
"Link is Down\n"); |
| 1830 | 1830 |
} |
| 1831 | 1831 |
adapter->link_active = 0; |
| 1832 |
#ifdef notyet |
|
| 1833 |
if_link_state_change(ifp, LINK_STATE_DOWN); |
|
| 1834 |
#endif |
|
| 1832 |
ifp->if_link_state = LINK_STATE_DOWN; |
|
| 1833 |
if_link_state_change(ifp); |
|
| 1835 | 1834 |
} |
| 1836 | 1835 |
} |
| 1837 | 1836 |
} |
| b/sys/dev/netif/mii_layer/mii_physubr.c Thu Mar 15 20:10:03 2007 +0200 | ||
|---|---|---|
| 500 | 500 |
return (0); |
| 501 | 501 |
} |
| 502 | 502 | |
| 503 |
#ifdef notyet |
|
| 504 |
static void |
|
| 503 |
static int |
|
| 505 | 504 |
mii_phy_statusmsg(struct mii_softc *sc) |
| 506 | 505 |
{
|
| 507 | 506 |
struct mii_data *mii = sc->mii_pdata; |
| 508 | 507 |
struct ifnet *ifp = mii->mii_ifp; |
| 509 |
int s; |
|
| 510 | ||
| 511 |
crit_enter(); |
|
| 508 |
int baudrate, link_state, announce = 0; |
|
| 509 | ||
| 512 | 510 |
if (mii->mii_media_status & IFM_AVALID) {
|
| 513 | 511 |
if (mii->mii_media_status & IFM_ACTIVE) |
| 514 |
if_link_state_change(ifp, LINK_STATE_UP);
|
|
| 512 |
link_state = LINK_STATE_UP;
|
|
| 515 | 513 |
else |
| 516 |
if_link_state_change(ifp, LINK_STATE_DOWN);
|
|
| 514 |
link_state = LINK_STATE_DOWN;
|
|
| 517 | 515 |
} else |
| 518 |
if_link_state_change(ifp, LINK_STATE_UNKNOWN); |
|
| 519 |
crit_exit(); |
|
| 520 | ||
| 521 |
ifp->if_baudrate = ifmedia_baudrate(mii->mii_media_active); |
|
| 522 |
} |
|
| 523 |
#endif |
|
| 516 |
link_state = LINK_STATE_UNKNOWN; |
|
| 517 | ||
| 518 |
baudrate = ifmedia_baudrate(mii->mii_media_active); |
|
| 519 | ||
| 520 |
if (link_state != ifp->if_link_state) {
|
|
| 521 |
ifp->if_link_state = link_state; |
|
| 522 |
/* |
|
| 523 |
* XXX Right here we'd like to notify protocols |
|
| 524 |
* XXX that the link status has changed, so that |
|
| 525 |
* XXX e.g. Duplicate Address Detection can restart. |
|
| 526 |
*/ |
|
| 527 |
announce = 1; |
|
| 528 |
} |
|
| 529 | ||
| 530 |
if (baudrate != ifp->if_baudrate) {
|
|
| 531 |
ifp->if_baudrate = baudrate; |
|
| 532 |
announce = 1; |
|
| 533 |
} |
|
| 534 | ||
| 535 |
return (announce); |
|
| 536 |
} |
|
| 524 | 537 | |
| 525 | 538 |
void |
| 526 | 539 |
mii_phy_update(struct mii_softc *sc, int cmd) |
| 527 | 540 |
{
|
| 528 | 541 |
struct mii_data *mii = sc->mii_pdata; |
| 542 |
struct ifnet *ifp = mii->mii_ifp; |
|
| 543 |
int announce; |
|
| 529 | 544 | |
| 530 | 545 |
if (sc->mii_media_active != mii->mii_media_active || |
| 531 | 546 |
sc->mii_media_status != mii->mii_media_status || |
| 532 | 547 |
cmd == MII_MEDIACHG) {
|
| 533 |
#ifdef notyet |
|
| 534 |
mii_phy_statusmsg(sc); |
|
| 535 |
#endif |
|
| 548 |
announce = mii_phy_statusmsg(sc); |
|
| 536 | 549 |
MIIBUS_STATCHG(sc->mii_dev); |
| 537 | 550 |
sc->mii_media_active = mii->mii_media_active; |
| 538 | 551 |
sc->mii_media_status = mii->mii_media_status; |
| 552 | ||
| 553 |
if (announce) {
|
|
| 554 |
crit_enter(); |
|
| 555 |
if_link_state_change(ifp); |
|
| 556 |
crit_exit(); |
|
| 557 |
} |
|
| 539 | 558 |
} |
| 540 | 559 |
} |
| 541 | 560 | |
| b/sys/net/if.c Fri Mar 16 06:58:52 2007 +0200 | ||
|---|---|---|
| 975 | 975 |
{
|
| 976 | 976 | |
| 977 | 977 |
if_route(ifp, IFF_UP, AF_UNSPEC); |
| 978 |
} |
|
| 979 | ||
| 980 |
/* |
|
| 981 |
* Process a link state change. |
|
| 982 |
* NOTE: must be called at splsoftnet or equivalent. |
|
| 983 |
*/ |
|
| 984 |
void |
|
| 985 |
if_link_state_change(struct ifnet *ifp) |
|
| 986 |
{
|
|
| 987 |
rt_ifmsg(ifp); |
|
| 978 | 988 |
} |
| 979 | 989 | |
| 980 | 990 |
/* |
| b/sys/net/if.h Thu Mar 15 20:08:58 2007 +0200 | ||
|---|---|---|
| 56 | 56 | |
| 57 | 57 |
#endif |
| 58 | 58 | |
| 59 |
/* |
|
| 60 |
* Values for if_link_state. |
|
| 61 |
*/ |
|
| 62 |
#define LINK_STATE_UNKNOWN 0 /* link invalid/unknown */ |
|
| 63 |
#define LINK_STATE_DOWN 1 /* link is down */ |
|
| 64 |
#define LINK_STATE_UP 2 /* link is up */ |
|
| 65 | ||
| 59 | 66 |
struct ifnet; |
| 60 | 67 | |
| 61 | 68 |
/* |
| ... | ... | |
| 111 | 118 |
u_char ifi_xmitquota; /* polling quota for xmit intrs */ |
| 112 | 119 |
u_long ifi_mtu; /* maximum transmission unit */ |
| 113 | 120 |
u_long ifi_metric; /* routing metric (external only) */ |
| 121 |
u_long ifi_link_state; /* current link state */ |
|
| 114 | 122 |
u_long ifi_baudrate; /* linespeed */ |
| 115 | 123 |
/* volatile statistics */ |
| 116 | 124 |
u_long ifi_ipackets; /* packets received on interface */ |
| b/sys/net/if_media.c Thu Mar 15 13:57:11 2007 +0200 | ||
|---|---|---|
| 360 | 360 |
return match; |
| 361 | 361 |
} |
| 362 | 362 | |
| 363 |
struct ifmedia_baudrate ifmedia_baudrate_descriptions[] = |
|
| 364 |
IFM_BAUDRATE_DESCRIPTIONS; |
|
| 365 | ||
| 366 |
int |
|
| 367 |
ifmedia_baudrate(int mword) |
|
| 368 |
{
|
|
| 369 |
int i; |
|
| 370 | ||
| 371 |
for (i = 0; ifmedia_baudrate_descriptions[i].ifmb_word != 0; i++) {
|
|
| 372 |
if ((mword & (IFM_NMASK|IFM_TMASK)) == |
|
| 373 |
ifmedia_baudrate_descriptions[i].ifmb_word) |
|
| 374 |
return (ifmedia_baudrate_descriptions[i].ifmb_baudrate); |
|
| 375 |
} |
|
| 376 | ||
| 377 |
/* Not known. */ |
|
| 378 |
return (0); |
|
| 379 |
} |
|
| 380 | ||
| 363 | 381 |
#ifdef IFMEDIA_DEBUG |
| 364 | 382 |
struct ifmedia_description ifm_type_descriptions[] = |
| 365 | 383 |
IFM_TYPE_DESCRIPTIONS; |
| b/sys/net/if_media.h Fri Mar 16 06:56:20 2007 +0200 | ||
|---|---|---|
| 115 | 115 |
int ifmedia_ioctl(struct ifnet *ifp, struct ifreq *ifr, |
| 116 | 116 |
struct ifmedia *ifm, u_long cmd); |
| 117 | 117 | |
| 118 |
/* Compute baudrate for a given media. */ |
|
| 119 |
int ifmedia_baudrate(int); |
|
| 118 | 120 |
#endif /*_KERNEL */ |
| 119 | 121 | |
| 120 | 122 |
/* |
| ... | ... | |
| 541 | 543 |
{ 0, NULL }, \
|
| 542 | 544 |
} |
| 543 | 545 | |
| 546 |
/* |
|
| 547 |
* Baudrate descriptions for the various media types. |
|
| 548 |
*/ |
|
| 549 |
struct ifmedia_baudrate {
|
|
| 550 |
int ifmb_word; /* media word */ |
|
| 551 |
int ifmb_baudrate; /* corresponding baudrate */ |
|
| 552 |
}; |
|
| 553 | ||
| 554 |
#define IFM_BAUDRATE_DESCRIPTIONS { \
|
|
| 555 |
{ IFM_ETHER|IFM_10_T, IF_Mbps(10) }, \
|
|
| 556 |
{ IFM_ETHER|IFM_10_2, IF_Mbps(10) }, \
|
|
| 557 |
{ IFM_ETHER|IFM_10_5, IF_Mbps(10) }, \
|
|
| 558 |
{ IFM_ETHER|IFM_100_TX, IF_Mbps(100) }, \
|
|
| 559 |
{ IFM_ETHER|IFM_100_FX, IF_Mbps(100) }, \
|
|
| 560 |
{ IFM_ETHER|IFM_100_T4, IF_Mbps(100) }, \
|
|
| 561 |
{ IFM_ETHER|IFM_100_VG, IF_Mbps(100) }, \
|
|
| 562 |
{ IFM_ETHER|IFM_100_T2, IF_Mbps(100) }, \
|
|
| 563 |
{ IFM_ETHER|IFM_1000_SX, IF_Mbps(1000) }, \
|
|
| 564 |
{ IFM_ETHER|IFM_10_STP, IF_Mbps(10) }, \
|
|
| 565 |
{ IFM_ETHER|IFM_10_FL, IF_Mbps(10) }, \
|
|
| 566 |
{ IFM_ETHER|IFM_1000_LX, IF_Mbps(1000) }, \
|
|
| 567 |
{ IFM_ETHER|IFM_1000_CX, IF_Mbps(1000) }, \
|
|
| 568 |
{ IFM_ETHER|IFM_1000_T, IF_Mbps(1000) }, \
|
|
| 569 |
{ IFM_ETHER|IFM_HPNA_1, IF_Mbps(1) }, \
|
|
| 570 |
\ |
|
| 571 |
{ IFM_TOKEN|IFM_TOK_STP4, IF_Mbps(4) }, \
|
|
| 572 |
{ IFM_TOKEN|IFM_TOK_STP16, IF_Mbps(16) }, \
|
|
| 573 |
{ IFM_TOKEN|IFM_TOK_UTP4, IF_Mbps(4) }, \
|
|
| 574 |
{ IFM_TOKEN|IFM_TOK_UTP16, IF_Mbps(16) }, \
|
|
| 575 |
\ |
|
| 576 |
{ IFM_FDDI|IFM_FDDI_SMF, IF_Mbps(100) }, \
|
|
| 577 |
{ IFM_FDDI|IFM_FDDI_MMF, IF_Mbps(100) }, \
|
|
| 578 |
{ IFM_FDDI|IFM_FDDI_UTP, IF_Mbps(100) }, \
|
|
| 579 |
\ |
|
| 580 |
{ IFM_IEEE80211|IFM_IEEE80211_FH1, IF_Mbps(1) }, \
|
|
| 581 |
{ IFM_IEEE80211|IFM_IEEE80211_FH2, IF_Mbps(2) }, \
|
|
| 582 |
{ IFM_IEEE80211|IFM_IEEE80211_DS1, IF_Mbps(1) }, \
|
|
| 583 |
{ IFM_IEEE80211|IFM_IEEE80211_DS2, IF_Mbps(2) }, \
|
|
| 584 |
{ IFM_IEEE80211|IFM_IEEE80211_DS5, IF_Mbps(5) }, \
|
|
| 585 |
{ IFM_IEEE80211|IFM_IEEE80211_DS11, IF_Mbps(11) }, \
|
|
| 586 |
{ IFM_IEEE80211|IFM_IEEE80211_DS22, IF_Mbps(22) }, \
|
|
| 587 |
{ IFM_IEEE80211|IFM_IEEE80211_OFDM6, IF_Mbps(6) }, \
|
|
| 588 |
{ IFM_IEEE80211|IFM_IEEE80211_OFDM9, IF_Mbps(9) }, \
|
|
| 589 |
{ IFM_IEEE80211|IFM_IEEE80211_OFDM12, IF_Mbps(12) }, \
|
|
| 590 |
{ IFM_IEEE80211|IFM_IEEE80211_OFDM18, IF_Mbps(18) }, \
|
|
| 591 |
{ IFM_IEEE80211|IFM_IEEE80211_OFDM24, IF_Mbps(24) }, \
|
|
| 592 |
{ IFM_IEEE80211|IFM_IEEE80211_OFDM36, IF_Mbps(36) }, \
|
|
| 593 |
{ IFM_IEEE80211|IFM_IEEE80211_OFDM48, IF_Mbps(48) }, \
|
|
| 594 |
{ IFM_IEEE80211|IFM_IEEE80211_OFDM54, IF_Mbps(54) }, \
|
|
| 595 |
{ IFM_IEEE80211|IFM_IEEE80211_OFDM72, IF_Mbps(72) }, \
|
|
| 596 |
\ |
|
| 597 |
{ 0, 0 }, \
|
|
| 598 |
} |
|
| 544 | 599 |
#endif /* _NET_IF_MEDIA_H_ */ |
| b/sys/net/if_var.h Thu Mar 15 14:18:56 2007 +0200 | ||
|---|---|---|
| 228 | 228 |
#define if_addrlen if_data.ifi_addrlen |
| 229 | 229 |
#define if_hdrlen if_data.ifi_hdrlen |
| 230 | 230 |
#define if_metric if_data.ifi_metric |
| 231 |
#define if_link_state if_data.ifi_link_state |
|
| 231 | 232 |
#define if_baudrate if_data.ifi_baudrate |
| 232 | 233 |
#define if_hwassist if_data.ifi_hwassist |
| 233 | 234 |
#define if_ipackets if_data.ifi_ipackets |
| ... | ... | |
| 462 | 463 |
int if_delmulti(struct ifnet *, struct sockaddr *); |
| 463 | 464 |
void if_detach(struct ifnet *); |
| 464 | 465 |
void if_down(struct ifnet *); |
| 466 |
void if_link_state_change(struct ifnet *); |
|
| 465 | 467 |
void if_initname(struct ifnet *, const char *, int); |
| 466 | 468 |
int if_printf(struct ifnet *, const char *, ...) __printflike(2, 3); |
| 467 | 469 |
void if_route(struct ifnet *, int flag, int fam); |