From 36883c5516b32b512b9034a561e00b3bed50eb0b Mon Sep 17 00:00:00 2001 From: Hugo Santos Date: Wed, 4 Apr 2007 12:50:54 +0000 Subject: [PATCH] ipro1000: added ETHER_GET_LINK_STATE support * use em_media_status to get link status * added IFM_1000_SX (Fiber Optic) to net/if_media.h git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20551 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/posix/net/if_media.h | 1 + .../kernel/drivers/network/ipro1000/device.c | 25 +++++++++++++------ .../drivers/network/ipro1000/if_compat.h | 5 ++-- .../kernel/drivers/network/ipro1000/if_em.c | 4 +-- 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/headers/posix/net/if_media.h b/headers/posix/net/if_media.h index 0b1ba1354b..3ea0dd6e36 100644 --- a/headers/posix/net/if_media.h +++ b/headers/posix/net/if_media.h @@ -29,6 +29,7 @@ #define IFM_10_T 3 /* 10Base-T - RJ45 */ #define IFM_100_TX 6 /* 100Base-TX - RJ45 */ #define IFM_1000_T 16 /* 1000Base-T - RJ45 */ +#define IFM_1000_SX 18 /* 1000Base-SX - Fiber Optic */ /* General options */ diff --git a/src/add-ons/kernel/drivers/network/ipro1000/device.c b/src/add-ons/kernel/drivers/network/ipro1000/device.c index 21ec25c967..d4f6b34f3f 100644 --- a/src/add-ons/kernel/drivers/network/ipro1000/device.c +++ b/src/add-ons/kernel/drivers/network/ipro1000/device.c @@ -43,6 +43,7 @@ static int32 gOpenMask = 0; int em_attach(device_t); int em_detach(device_t); +void em_media_status(struct ifnet *, struct ifmediareq *); static void @@ -338,20 +339,28 @@ ipro1000_control(void *cookie, uint32 op, void *arg, size_t len) return B_OK; #ifdef HAIKU_TARGET_PLATFORM_HAIKU -#if 0 case ETHER_GET_LINK_STATE: { + struct ifnet ifp = { .if_softc = device->adapter }; + struct ifmediareq mediareq; ether_link_state_t state; - state.media = (info->link ? IFM_ACTIVE : 0) - | (info->full_duplex ? IFM_FULL_DUPLEX : IFM_HALF_DUPLEX) - | (info->speed == LINK_SPEED_100_MBIT ? IFM_100_TX : IFM_10_T); - state.speed = info->speed == LINK_SPEED_100_MBIT - ? 100000 : 10000; + + if (len < sizeof(ether_link_state_t)) + return ENOBUFS; + + em_media_status(&ifp, &mediareq); + + state.media = mediareq.ifm_active; + if (mediareq.ifm_active & IFM_10_T) + state.speed = 10000; + else if (mediareq.ifm_active & IFM_100_TX) + state.speed = 100000; + else + state.speed = 1000000; state.quality = 1000; - return user_memcpy(buffer, &state, sizeof(ether_link_state_t)); + return user_memcpy(arg, &state, sizeof(ether_link_state_t)); } -#endif #endif default: diff --git a/src/add-ons/kernel/drivers/network/ipro1000/if_compat.h b/src/add-ons/kernel/drivers/network/ipro1000/if_compat.h index 157ec35a2b..25a142cbbb 100644 --- a/src/add-ons/kernel/drivers/network/ipro1000/if_compat.h +++ b/src/add-ons/kernel/drivers/network/ipro1000/if_compat.h @@ -20,6 +20,7 @@ #define __IF_COMPAT_H #include +#include #define __FreeBSD_version 500001 @@ -39,10 +40,10 @@ #define IFCAP_RXCSUM 0x0020 #ifdef HAIKU_TARGET_PLATFORM_HAIKU +# define IFM_AVALID 0 # define IFM_FDX IFM_FULL_DUPLEX # define IFM_HDX IFM_HALF_DUPLEX -# define IFM_1000_TX 17 -# define IFM_1000_SX 18 +# define IFM_1000_TX IFM_1000_T #else # define IFM_ACTIVE 0x0001 # define IFM_FDX 0x0002 diff --git a/src/add-ons/kernel/drivers/network/ipro1000/if_em.c b/src/add-ons/kernel/drivers/network/ipro1000/if_em.c index f0650ab0f4..452c930ce9 100644 --- a/src/add-ons/kernel/drivers/network/ipro1000/if_em.c +++ b/src/add-ons/kernel/drivers/network/ipro1000/if_em.c @@ -814,7 +814,6 @@ event_handler(void *cookie) } -#if 0 /********************************************************************* * * Media Ioctl callback @@ -823,7 +822,7 @@ event_handler(void *cookie) * the interface using ifconfig. * **********************************************************************/ -static void +void em_media_status(struct ifnet *ifp, struct ifmediareq *ifmr) { struct adapter * adapter = ifp->if_softc; @@ -880,6 +879,7 @@ em_media_status(struct ifnet *ifp, struct ifmediareq *ifmr) return; } +#if 0 /********************************************************************* * * Media Ioctl callback