MFC: add dummy support for ifmedia subsystem. This allows devd to see cdce as

an ethernet device and configure IP etc.
This commit is contained in:
sobomax 2005-12-29 05:30:39 +00:00
parent 4b06402089
commit cc18a2f3dd
2 changed files with 32 additions and 0 deletions

View File

@ -56,6 +56,7 @@ __FBSDID("$FreeBSD$");
#include <net/if_arp.h>
#include <net/ethernet.h>
#include <net/if_types.h>
#include <net/if_media.h>
#include <net/bpf.h>
@ -91,6 +92,8 @@ Static void cdce_init(void *);
Static void cdce_reset(struct cdce_softc *);
Static void cdce_stop(struct cdce_softc *);
Static void cdce_rxstart(struct ifnet *);
Static int cdce_ifmedia_upd(struct ifnet *ifp);
Static void cdce_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr);
Static const struct cdce_type cdce_devs[] = {
{{ USB_VENDOR_PROLIFIC, USB_PRODUCT_PROLIFIC_PL2501 }, CDCE_NO_UNION },
@ -256,6 +259,7 @@ USB_ATTACH(cdce)
mtx_init(&sc->cdce_mtx, USBDEVNAME(sc->cdce_dev), MTX_NETWORK_LOCK,
MTX_DEF | MTX_RECURSE);
ifmedia_init(&sc->cdce_ifmedia, 0, cdce_ifmedia_upd, cdce_ifmedia_sts);
CDCE_LOCK(sc);
ue = (const usb_cdc_ethernet_descriptor_t *)usb_find_desc(dev,
@ -306,6 +310,10 @@ USB_ATTACH(cdce)
sc->q.ifp = ifp;
sc->q.if_rxstart = cdce_rxstart;
/* No IFM type for 11Mbps USB, so go with 10baseT */
ifmedia_add(&sc->cdce_ifmedia, IFM_ETHER | IFM_10_T, 0, 0);
ifmedia_set(&sc->cdce_ifmedia, IFM_ETHER | IFM_10_T);
ether_ifattach(ifp, eaddr);
usb_register_netisr();
@ -330,6 +338,7 @@ USB_DETACH(cdce)
ether_ifdetach(ifp);
if_free(ifp);
ifmedia_removeall(&sc->cdce_ifmedia);
CDCE_UNLOCK(sc);
mtx_destroy(&sc->cdce_mtx);
@ -469,6 +478,7 @@ Static int
cdce_ioctl(struct ifnet *ifp, u_long command, caddr_t data)
{
struct cdce_softc *sc = ifp->if_softc;
struct ifreq *ifr = (struct ifreq *)data;
int error = 0;
if (sc->cdce_dying)
@ -486,6 +496,11 @@ cdce_ioctl(struct ifnet *ifp, u_long command, caddr_t data)
error = 0;
break;
case SIOCSIFMEDIA:
case SIOCGIFMEDIA:
error = ifmedia_ioctl(ifp, ifr, &sc->cdce_ifmedia, command);
break;
default:
error = ether_ioctl(ifp, command, data);
break;
@ -717,3 +732,19 @@ cdce_rxstart(struct ifnet *ifp)
CDCE_UNLOCK(sc);
return;
}
Static int
cdce_ifmedia_upd(struct ifnet *ifp)
{
/* no-op, cdce has only 1 possible media type */
return 0;
}
Static void
cdce_ifmedia_sts(struct ifnet * const ifp, struct ifmediareq *req)
{
req->ifm_status = IFM_AVALID | IFM_ACTIVE;
req->ifm_active = IFM_ETHER | IFM_10_T;
}

View File

@ -45,6 +45,7 @@ struct cdce_type {
struct cdce_softc {
struct ifnet *cdce_ifp;
#define GET_IFP(sc) ((sc)->cdce_ifp)
struct ifmedia cdce_ifmedia;
usbd_device_handle cdce_udev;
usbd_interface_handle cdce_data_iface;