summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorMike Belopuhov <mikeb@cvs.openbsd.org>2012-11-08 19:48:38 +0000
committerMike Belopuhov <mikeb@cvs.openbsd.org>2012-11-08 19:48:38 +0000
commite395d0367c6b596246f562def3772556f5bc1505 (patch)
treef13550ebd27c234b4233669fb15e19030813656a /sys
parent80ef207a0f4678048cd4c10eef92dddf78e8c316 (diff)
make link state update code more comprehensible by using some ideas from myx(4)
Diffstat (limited to 'sys')
-rw-r--r--sys/dev/pci/if_oce.c101
-rw-r--r--sys/dev/pci/if_ocevar.h20
2 files changed, 40 insertions, 81 deletions
diff --git a/sys/dev/pci/if_oce.c b/sys/dev/pci/if_oce.c
index b41cd3bf0a8..9aaf03e711d 100644
--- a/sys/dev/pci/if_oce.c
+++ b/sys/dev/pci/if_oce.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_oce.c,v 1.48 2012/11/08 18:56:54 mikeb Exp $ */
+/* $OpenBSD: if_oce.c,v 1.49 2012/11/08 19:48:37 mikeb Exp $ */
/*
* Copyright (c) 2012 Mike Belopuhov
@@ -116,7 +116,7 @@ void oce_intr_disable(struct oce_softc *sc);
void oce_media_status(struct ifnet *ifp, struct ifmediareq *ifmr);
int oce_media_change(struct ifnet *ifp);
-void oce_update_link_status(struct oce_softc *sc);
+void oce_link_status(struct oce_softc *sc);
void oce_link_event(struct oce_softc *sc,
struct oce_async_cqe_link_state *acqe);
@@ -734,44 +734,34 @@ oce_intr_disable(struct oce_softc *sc)
}
void
-oce_update_link_status(struct oce_softc *sc)
+oce_link_status(struct oce_softc *sc)
{
struct ifnet *ifp = &sc->arpcom.ac_if;
- int speed = 0;
-
- if (sc->link_status) {
- if (sc->link_active == 0) {
- switch (sc->link_speed) {
- case 1: /* 10 Mbps */
- speed = 10;
- break;
- case 2: /* 100 Mbps */
- speed = 100;
- break;
- case 3: /* 1 Gbps */
- speed = 1000;
- break;
- case 4: /* 10 Gbps */
- speed = 10000;
- break;
- }
- sc->link_active = 1;
- ifp->if_baudrate = speed * 1000000ULL;
- }
- if (!LINK_STATE_IS_UP(ifp->if_link_state)) {
- ifp->if_link_state = LINK_STATE_FULL_DUPLEX;
- if_link_state_change(ifp);
- }
- } else {
- if (sc->link_active == 1) {
- ifp->if_baudrate = 0;
- sc->link_active = 0;
- }
- if (ifp->if_link_state != LINK_STATE_DOWN) {
- ifp->if_link_state = LINK_STATE_DOWN;
- if_link_state_change(ifp);
+ int link_state = LINK_STATE_DOWN;
+
+ if (sc->link_up)
+ link_state = LINK_STATE_FULL_DUPLEX;
+ if (ifp->if_link_state == link_state)
+ return;
+ if (link_state != LINK_STATE_DOWN) {
+ switch (sc->link_speed) {
+ case 1:
+ ifp->if_baudrate = IF_Mbps(10);
+ break;
+ case 2:
+ ifp->if_baudrate = IF_Mbps(100);
+ break;
+ case 3:
+ ifp->if_baudrate = IF_Gbps(1);
+ break;
+ case 4:
+ ifp->if_baudrate = IF_Gbps(10);
+ break;
}
- }
+ } else
+ ifp->if_baudrate = 0;
+ ifp->if_link_state = link_state;
+ if_link_state_change(ifp);
}
void
@@ -783,9 +773,9 @@ oce_media_status(struct ifnet *ifp, struct ifmediareq *ifmr)
ifmr->ifm_active = IFM_ETHER;
if (oce_get_link_status(sc) == 0)
- oce_update_link_status(sc);
+ oce_link_status(sc);
- if (!sc->link_status) {
+ if (!sc->link_up) {
ifmr->ifm_active |= IFM_NONE;
return;
}
@@ -1610,7 +1600,7 @@ oce_init(void *arg)
oce_arm_eq(eq, 0, TRUE, FALSE);
if (oce_get_link_status(sc) == 0)
- oce_update_link_status(sc);
+ oce_link_status(sc);
ifp->if_flags |= IFF_RUNNING;
ifp->if_flags &= ~IFF_OACTIVE;
@@ -1628,17 +1618,11 @@ void
oce_link_event(struct oce_softc *sc, struct oce_async_cqe_link_state *acqe)
{
/* Update Link status */
- if ((acqe->u0.s.link_status & ~ASYNC_EVENT_LOGICAL) ==
- ASYNC_EVENT_LINK_UP)
- sc->link_status = ASYNC_EVENT_LINK_UP;
- else
- sc->link_status = ASYNC_EVENT_LINK_DOWN;
-
+ sc->link_up = ((acqe->u0.s.link_status & ~ASYNC_EVENT_LOGICAL) ==
+ ASYNC_EVENT_LINK_UP);
/* Update speed */
sc->link_speed = acqe->u0.s.speed;
- sc->qos_link_speed = (uint32_t) acqe->u0.s.qos_link_speed * 10;
-
- oce_update_link_status(sc);
+ oce_link_status(sc);
}
/* Handle the Completion Queue for the Mailbox/Async notifications */
@@ -2943,7 +2927,6 @@ int
oce_get_link_status(struct oce_softc *sc)
{
struct mbx_query_common_link_config cmd;
- struct link_status link;
int err;
bzero(&cmd, sizeof(cmd));
@@ -2953,24 +2936,14 @@ oce_get_link_status(struct oce_softc *sc)
if (err)
return (err);
- bcopy(&cmd.params.rsp, &link, sizeof(struct link_status));
- link.logical_link_status = letoh32(link.logical_link_status);
- link.qos_link_speed = letoh16(link.qos_link_speed);
-
- if (link.logical_link_status == NTWK_LOGICAL_LINK_UP)
- sc->link_status = NTWK_LOGICAL_LINK_UP;
- else
- sc->link_status = NTWK_LOGICAL_LINK_DOWN;
+ sc->link_up = (letoh32(cmd.params.rsp.logical_link_status) ==
+ NTWK_LOGICAL_LINK_UP);
- if (link.mac_speed > 0 && link.mac_speed < 5)
- sc->link_speed = link.mac_speed;
+ if (cmd.params.rsp.mac_speed < 5)
+ sc->link_speed = cmd.params.rsp.mac_speed;
else
sc->link_speed = 0;
- sc->duplex = link.mac_duplex;
-
- sc->qos_link_speed = (uint32_t )link.qos_link_speed * 10;
-
return (0);
}
diff --git a/sys/dev/pci/if_ocevar.h b/sys/dev/pci/if_ocevar.h
index 0f4fba17a72..2115ccfe2c3 100644
--- a/sys/dev/pci/if_ocevar.h
+++ b/sys/dev/pci/if_ocevar.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_ocevar.h,v 1.7 2012/11/08 18:56:54 mikeb Exp $ */
+/* $OpenBSD: if_ocevar.h,v 1.8 2012/11/08 19:48:37 mikeb Exp $ */
/*-
* Copyright (C) 2012 Emulex
@@ -258,17 +258,6 @@ struct oce_rq {
int rss;
};
-struct link_status {
- uint8_t physical_port;
- uint8_t mac_duplex;
- uint8_t mac_speed;
- uint8_t mac_fault;
- uint8_t mgmt_mac_duplex;
- uint8_t mgmt_mac_speed;
- uint16_t qos_link_speed;
- uint32_t logical_link_status;
-} __packed;
-
#define OCE_F_BE2 0x00000001
#define OCE_F_BE3 0x00000002
#define OCE_F_BE3_NATIVE 0x00000004
@@ -297,11 +286,8 @@ struct oce_softc {
struct arpcom arpcom;
struct ifmedia media;
- int link_active;
- uint8_t link_status;
- uint8_t link_speed;
- uint8_t duplex;
- uint32_t qos_link_speed;
+ ushort link_up;
+ ushort link_speed;
struct oce_dma_mem bsmbx;