summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authorattilio <attilio@FreeBSD.org>2011-05-04 15:45:23 +0000
committerattilio <attilio@FreeBSD.org>2011-05-04 15:45:23 +0000
commit0987be4d6b2d0935772f9e136a600dabcdb316ab (patch)
treea9b925ba1a5fdc0e238501e54950446a18a65638 /sys
parented9b4cbe96f6aed547db56209b74fb5ecbae994b (diff)
parent81efd57a3570aca185e180b83421df560284b1fe (diff)
downloadFreeBSD-src-0987be4d6b2d0935772f9e136a600dabcdb316ab.zip
FreeBSD-src-0987be4d6b2d0935772f9e136a600dabcdb316ab.tar.gz
MFC
Diffstat (limited to 'sys')
-rw-r--r--sys/cddl/compat/opensolaris/sys/systm.h3
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_ioctl.c4
-rw-r--r--sys/compat/linux/linux_ioctl.c310
-rw-r--r--sys/compat/linux/linux_ioctl.h97
-rw-r--r--sys/compat/linux/linux_videodev.h4
-rw-r--r--sys/compat/linux/linux_videodev2.h1179
-rw-r--r--sys/compat/linux/linux_videodev2_compat.h137
-rw-r--r--sys/dev/ae/if_ae.c6
-rw-r--r--sys/dev/age/if_age.c6
-rw-r--r--sys/dev/alc/if_alc.c6
-rw-r--r--sys/dev/ale/if_ale.c6
-rw-r--r--sys/dev/ath/ath_hal/ar5416/ar5416_reset.c7
-rw-r--r--sys/dev/bce/if_bce.c9
-rw-r--r--sys/dev/bfe/if_bfe.c9
-rw-r--r--sys/dev/bge/if_bge.c5
-rw-r--r--sys/dev/dc/dcphy.c38
-rw-r--r--sys/dev/dc/pnphy.c35
-rw-r--r--sys/dev/ed/if_ed_pccard.c16
-rw-r--r--sys/dev/et/if_et.c9
-rw-r--r--sys/dev/fxp/if_fxp.c8
-rw-r--r--sys/dev/hme/if_hme.c2
-rw-r--r--sys/dev/jme/if_jme.c6
-rw-r--r--sys/dev/lge/if_lge.c9
-rw-r--r--sys/dev/mii/acphy.c35
-rw-r--r--sys/dev/mii/amphy.c47
-rw-r--r--sys/dev/mii/atphy.c63
-rw-r--r--sys/dev/mii/axphy.c37
-rw-r--r--sys/dev/mii/bmtphy.c65
-rw-r--r--sys/dev/mii/brgphy.c174
-rw-r--r--sys/dev/mii/ciphy.c69
-rw-r--r--sys/dev/mii/e1000phy.c121
-rw-r--r--sys/dev/mii/exphy.c44
-rw-r--r--sys/dev/mii/gentbi.c31
-rw-r--r--sys/dev/mii/icsphy.c70
-rw-r--r--sys/dev/mii/inphy.c49
-rw-r--r--sys/dev/mii/ip1000phy.c70
-rw-r--r--sys/dev/mii/jmphy.c66
-rw-r--r--sys/dev/mii/lxtphy.c39
-rw-r--r--sys/dev/mii/mii.c46
-rw-r--r--sys/dev/mii/mii.h10
-rw-r--r--sys/dev/mii/mii_physubr.c53
-rw-r--r--sys/dev/mii/miidevs365
-rw-r--r--sys/dev/mii/miivar.h84
-rw-r--r--sys/dev/mii/mlphy.c52
-rw-r--r--sys/dev/mii/nsgphy.c35
-rw-r--r--sys/dev/mii/nsphy.c58
-rw-r--r--sys/dev/mii/nsphyter.c58
-rw-r--r--sys/dev/mii/pnaphy.c37
-rw-r--r--sys/dev/mii/qsphy.c38
-rw-r--r--sys/dev/mii/rdcphy.c43
-rw-r--r--sys/dev/mii/rgephy.c79
-rw-r--r--sys/dev/mii/rlphy.c77
-rw-r--r--sys/dev/mii/rlswitch.c38
-rw-r--r--sys/dev/mii/ruephy.c43
-rw-r--r--sys/dev/mii/smcphy.c58
-rw-r--r--sys/dev/mii/tdkphy.c47
-rw-r--r--sys/dev/mii/tlphy.c77
-rw-r--r--sys/dev/mii/truephy.c41
-rw-r--r--sys/dev/mii/ukphy.c40
-rw-r--r--sys/dev/mii/xmphy.c37
-rw-r--r--sys/dev/nfe/if_nfe.c12
-rw-r--r--sys/dev/nge/if_nge.c6
-rw-r--r--sys/dev/nve/if_nve.c10
-rw-r--r--sys/dev/pcn/if_pcn.c5
-rw-r--r--sys/dev/sf/if_sf.c8
-rw-r--r--sys/dev/sge/if_sge.c8
-rw-r--r--sys/dev/sis/if_sis.c8
-rw-r--r--sys/dev/ste/if_ste.c6
-rw-r--r--sys/dev/tx/if_tx.c11
-rw-r--r--sys/dev/usb/net/if_aue.c9
-rw-r--r--sys/dev/usb/net/if_axe.c9
-rw-r--r--sys/dev/usb/net/if_rue.c9
-rw-r--r--sys/dev/usb/net/if_udav.c9
-rw-r--r--sys/dev/vr/if_vr.c6
-rw-r--r--sys/dev/vte/if_vte.c6
-rw-r--r--sys/dev/wb/if_wb.c18
-rw-r--r--sys/fs/nfs/nfs_commonport.c60
-rw-r--r--sys/fs/nfsclient/nfs_clsubs.c2
-rw-r--r--sys/fs/nfsclient/nfs_clvfsops.c4
-rw-r--r--sys/fs/nfsclient/nfs_clvnops.c3
-rw-r--r--sys/geom/geom_dev.c3
-rw-r--r--sys/geom/label/g_label.c2
-rw-r--r--sys/kern/kern_conf.c61
-rw-r--r--sys/mips/atheros/if_arge.c6
-rw-r--r--sys/mips/cavium/octe/octe.c10
-rw-r--r--sys/mips/idt/if_kr.c6
-rw-r--r--sys/modules/mii/Makefile1
-rw-r--r--sys/net80211/ieee80211_adhoc.c6
-rw-r--r--sys/net80211/ieee80211_hostap.c6
-rw-r--r--sys/net80211/ieee80211_input.h98
-rw-r--r--sys/net80211/ieee80211_mesh.c5
-rw-r--r--sys/net80211/ieee80211_sta.c6
-rw-r--r--sys/net80211/ieee80211_wds.c6
-rw-r--r--sys/netinet/sctp_asconf.c3
-rw-r--r--sys/netinet/sctp_auth.c3
-rw-r--r--sys/netinet/sctputil.c3
-rw-r--r--sys/netinet6/sctp6_usrreq.c4
-rw-r--r--sys/nfs/nfs_diskless.c2
-rw-r--r--sys/nfs/nfssvc.h3
-rw-r--r--sys/nfsclient/nfs_vfsops.c4
-rw-r--r--sys/nfsclient/nfs_vnops.c3
-rw-r--r--sys/nfsclient/nfsargs.h1
-rw-r--r--sys/sys/conf.h2
103 files changed, 3014 insertions, 1746 deletions
diff --git a/sys/cddl/compat/opensolaris/sys/systm.h b/sys/cddl/compat/opensolaris/sys/systm.h
index 136960e..fe0e199 100644
--- a/sys/cddl/compat/opensolaris/sys/systm.h
+++ b/sys/cddl/compat/opensolaris/sys/systm.h
@@ -42,9 +42,6 @@
#define delay(x) pause("soldelay", (x))
-#define xcopyin(u, k, s) copyin(u, k, s)
-#define xcopyout(k, u, s) copyout(k, u, s)
-
#endif /* _KERNEL */
#endif /* _OPENSOLARIS_SYS_SYSTM_H_ */
diff --git a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_ioctl.c b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_ioctl.c
index 153f957..f8912ca 100644
--- a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_ioctl.c
+++ b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_ioctl.c
@@ -4068,9 +4068,9 @@ zfs_ioc_userspace_many(zfs_cmd_t *zc)
buf, &zc->zc_nvlist_dst_size);
if (error == 0) {
- error = xcopyout(buf,
+ error = ddi_copyout(buf,
(void *)(uintptr_t)zc->zc_nvlist_dst,
- zc->zc_nvlist_dst_size);
+ zc->zc_nvlist_dst_size, zc->zc_iflags);
}
kmem_free(buf, bufsize);
zfsvfs_rele(zfsvfs, FTAG);
diff --git a/sys/compat/linux/linux_ioctl.c b/sys/compat/linux/linux_ioctl.c
index 4237f6f..5532c93 100644
--- a/sys/compat/linux/linux_ioctl.c
+++ b/sys/compat/linux/linux_ioctl.c
@@ -57,8 +57,12 @@ __FBSDID("$FreeBSD$");
#include <sys/soundcard.h>
#include <sys/stdint.h>
#include <sys/sx.h>
+#include <sys/sysctl.h>
#include <sys/tty.h>
#include <sys/uio.h>
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <sys/resourcevar.h>
#include <net/if.h>
#include <net/if_dl.h>
@@ -83,8 +87,14 @@ __FBSDID("$FreeBSD$");
#include <compat/linux/linux_videodev.h>
#include <compat/linux/linux_videodev_compat.h>
+#include <compat/linux/linux_videodev2.h>
+#include <compat/linux/linux_videodev2_compat.h>
+
CTASSERT(LINUX_IFNAMSIZ == IFNAMSIZ);
+FEATURE(linuxulator_v4l, "V4L ioctl wrapper support in the linuxulator");
+FEATURE(linuxulator_v4l2, "V4L2 ioctl wrapper support in the linuxulator");
+
static linux_ioctl_function_t linux_ioctl_cdrom;
static linux_ioctl_function_t linux_ioctl_vfat;
static linux_ioctl_function_t linux_ioctl_console;
@@ -97,6 +107,7 @@ static linux_ioctl_function_t linux_ioctl_private;
static linux_ioctl_function_t linux_ioctl_drm;
static linux_ioctl_function_t linux_ioctl_sg;
static linux_ioctl_function_t linux_ioctl_v4l;
+static linux_ioctl_function_t linux_ioctl_v4l2;
static linux_ioctl_function_t linux_ioctl_special;
static linux_ioctl_function_t linux_ioctl_fbsd_usb;
@@ -124,6 +135,8 @@ static struct linux_ioctl_handler sg_handler =
{ linux_ioctl_sg, LINUX_IOCTL_SG_MIN, LINUX_IOCTL_SG_MAX };
static struct linux_ioctl_handler video_handler =
{ linux_ioctl_v4l, LINUX_IOCTL_VIDEO_MIN, LINUX_IOCTL_VIDEO_MAX };
+static struct linux_ioctl_handler video2_handler =
+{ linux_ioctl_v4l2, LINUX_IOCTL_VIDEO2_MIN, LINUX_IOCTL_VIDEO2_MAX };
static struct linux_ioctl_handler fbsd_usb =
{ linux_ioctl_fbsd_usb, FBSD_LUSB_MIN, FBSD_LUSB_MAX };
@@ -139,6 +152,7 @@ DATA_SET(linux_ioctl_handler_set, private_handler);
DATA_SET(linux_ioctl_handler_set, drm_handler);
DATA_SET(linux_ioctl_handler_set, sg_handler);
DATA_SET(linux_ioctl_handler_set, video_handler);
+DATA_SET(linux_ioctl_handler_set, video2_handler);
DATA_SET(linux_ioctl_handler_set, fbsd_usb);
struct handler_element
@@ -2988,6 +3002,302 @@ linux_ioctl_special(struct thread *td, struct linux_ioctl_args *args)
return (error);
}
+static int
+linux_to_bsd_v4l2_standard(struct l_v4l2_standard *lvstd, struct v4l2_standard *vstd)
+{
+ vstd->index = lvstd->index;
+ vstd->id = lvstd->id;
+ memcpy(&vstd->name, &lvstd->name, sizeof(*lvstd) - offsetof(struct l_v4l2_standard, name));
+ return (0);
+}
+
+static int
+bsd_to_linux_v4l2_standard(struct v4l2_standard *vstd, struct l_v4l2_standard *lvstd)
+{
+ lvstd->index = vstd->index;
+ lvstd->id = vstd->id;
+ memcpy(&lvstd->name, &vstd->name, sizeof(*lvstd) - offsetof(struct l_v4l2_standard, name));
+ return (0);
+}
+
+static int
+linux_to_bsd_v4l2_buffer(struct l_v4l2_buffer *lvb, struct v4l2_buffer *vb)
+{
+ vb->index = lvb->index;
+ vb->type = lvb->type;
+ vb->bytesused = lvb->bytesused;
+ vb->flags = lvb->flags;
+ vb->field = lvb->field;
+ vb->timestamp.tv_sec = lvb->timestamp.tv_sec;
+ vb->timestamp.tv_usec = lvb->timestamp.tv_usec;
+ memcpy(&vb->timecode, &lvb->timecode, sizeof (lvb->timecode));
+ vb->sequence = lvb->sequence;
+ vb->memory = lvb->memory;
+ if (lvb->memory == V4L2_MEMORY_USERPTR)
+ /* possible pointer size conversion */
+ vb->m.userptr = (unsigned long)PTRIN(lvb->m.userptr);
+ else
+ vb->m.offset = lvb->m.offset;
+ vb->length = lvb->length;
+ vb->input = lvb->input;
+ vb->reserved = lvb->reserved;
+ return (0);
+}
+
+static int
+bsd_to_linux_v4l2_buffer(struct v4l2_buffer *vb, struct l_v4l2_buffer *lvb)
+{
+ lvb->index = vb->index;
+ lvb->type = vb->type;
+ lvb->bytesused = vb->bytesused;
+ lvb->flags = vb->flags;
+ lvb->field = vb->field;
+ lvb->timestamp.tv_sec = vb->timestamp.tv_sec;
+ lvb->timestamp.tv_usec = vb->timestamp.tv_usec;
+ memcpy(&lvb->timecode, &vb->timecode, sizeof (vb->timecode));
+ lvb->sequence = vb->sequence;
+ lvb->memory = vb->memory;
+ if (vb->memory == V4L2_MEMORY_USERPTR)
+ /* possible pointer size conversion */
+ lvb->m.userptr = PTROUT(vb->m.userptr);
+ else
+ lvb->m.offset = vb->m.offset;
+ lvb->length = vb->length;
+ lvb->input = vb->input;
+ lvb->reserved = vb->reserved;
+ return (0);
+}
+
+static int
+linux_to_bsd_v4l2_format(struct l_v4l2_format *lvf, struct v4l2_format *vf)
+{
+ vf->type = lvf->type;
+ if (lvf->type == V4L2_BUF_TYPE_VIDEO_OVERLAY
+#ifdef V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
+ || lvf->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
+#endif
+ )
+ /*
+ * XXX TODO - needs 32 -> 64 bit conversion:
+ * (unused by webcams?)
+ */
+ return EINVAL;
+ memcpy(&vf->fmt, &lvf->fmt, sizeof(vf->fmt));
+ return 0;
+}
+
+static int
+bsd_to_linux_v4l2_format(struct v4l2_format *vf, struct l_v4l2_format *lvf)
+{
+ lvf->type = vf->type;
+ if (vf->type == V4L2_BUF_TYPE_VIDEO_OVERLAY
+#ifdef V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
+ || vf->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
+#endif
+ )
+ /*
+ * XXX TODO - needs 32 -> 64 bit conversion:
+ * (unused by webcams?)
+ */
+ return EINVAL;
+ memcpy(&lvf->fmt, &vf->fmt, sizeof(vf->fmt));
+ return 0;
+}
+static int
+linux_ioctl_v4l2(struct thread *td, struct linux_ioctl_args *args)
+{
+ struct file *fp;
+ int error;
+ struct v4l2_format vformat;
+ struct l_v4l2_format l_vformat;
+ struct v4l2_standard vstd;
+ struct l_v4l2_standard l_vstd;
+ struct l_v4l2_buffer l_vbuf;
+ struct v4l2_buffer vbuf;
+ struct v4l2_input vinp;
+
+ switch (args->cmd & 0xffff) {
+ case LINUX_VIDIOC_RESERVED:
+ case LINUX_VIDIOC_LOG_STATUS:
+ if ((args->cmd & IOC_DIRMASK) != LINUX_IOC_VOID)
+ return ENOIOCTL;
+ args->cmd = (args->cmd & 0xffff) | IOC_VOID;
+ break;
+
+ case LINUX_VIDIOC_OVERLAY:
+ case LINUX_VIDIOC_STREAMON:
+ case LINUX_VIDIOC_STREAMOFF:
+ case LINUX_VIDIOC_S_STD:
+ case LINUX_VIDIOC_S_TUNER:
+ case LINUX_VIDIOC_S_AUDIO:
+ case LINUX_VIDIOC_S_AUDOUT:
+ case LINUX_VIDIOC_S_MODULATOR:
+ case LINUX_VIDIOC_S_FREQUENCY:
+ case LINUX_VIDIOC_S_CROP:
+ case LINUX_VIDIOC_S_JPEGCOMP:
+ case LINUX_VIDIOC_S_PRIORITY:
+ case LINUX_VIDIOC_DBG_S_REGISTER:
+ case LINUX_VIDIOC_S_HW_FREQ_SEEK:
+ case LINUX_VIDIOC_SUBSCRIBE_EVENT:
+ case LINUX_VIDIOC_UNSUBSCRIBE_EVENT:
+ args->cmd = (args->cmd & ~IOC_DIRMASK) | IOC_IN;
+ break;
+
+ case LINUX_VIDIOC_QUERYCAP:
+ case LINUX_VIDIOC_G_STD:
+ case LINUX_VIDIOC_G_AUDIO:
+ case LINUX_VIDIOC_G_INPUT:
+ case LINUX_VIDIOC_G_OUTPUT:
+ case LINUX_VIDIOC_G_AUDOUT:
+ case LINUX_VIDIOC_G_JPEGCOMP:
+ case LINUX_VIDIOC_QUERYSTD:
+ case LINUX_VIDIOC_G_PRIORITY:
+ case LINUX_VIDIOC_QUERY_DV_PRESET:
+ args->cmd = (args->cmd & ~IOC_DIRMASK) | IOC_OUT;
+ break;
+
+ case LINUX_VIDIOC_ENUM_FMT:
+ case LINUX_VIDIOC_REQBUFS:
+ case LINUX_VIDIOC_G_PARM:
+ case LINUX_VIDIOC_S_PARM:
+ case LINUX_VIDIOC_G_CTRL:
+ case LINUX_VIDIOC_S_CTRL:
+ case LINUX_VIDIOC_G_TUNER:
+ case LINUX_VIDIOC_QUERYCTRL:
+ case LINUX_VIDIOC_QUERYMENU:
+ case LINUX_VIDIOC_S_INPUT:
+ case LINUX_VIDIOC_S_OUTPUT:
+ case LINUX_VIDIOC_ENUMOUTPUT:
+ case LINUX_VIDIOC_G_MODULATOR:
+ case LINUX_VIDIOC_G_FREQUENCY:
+ case LINUX_VIDIOC_CROPCAP:
+ case LINUX_VIDIOC_G_CROP:
+ case LINUX_VIDIOC_ENUMAUDIO:
+ case LINUX_VIDIOC_ENUMAUDOUT:
+ case LINUX_VIDIOC_G_SLICED_VBI_CAP:
+#ifdef VIDIOC_ENUM_FRAMESIZES
+ case LINUX_VIDIOC_ENUM_FRAMESIZES:
+ case LINUX_VIDIOC_ENUM_FRAMEINTERVALS:
+ case LINUX_VIDIOC_ENCODER_CMD:
+ case LINUX_VIDIOC_TRY_ENCODER_CMD:
+#endif
+ case LINUX_VIDIOC_DBG_G_REGISTER:
+ case LINUX_VIDIOC_DBG_G_CHIP_IDENT:
+ case LINUX_VIDIOC_ENUM_DV_PRESETS:
+ case LINUX_VIDIOC_S_DV_PRESET:
+ case LINUX_VIDIOC_G_DV_PRESET:
+ case LINUX_VIDIOC_S_DV_TIMINGS:
+ case LINUX_VIDIOC_G_DV_TIMINGS:
+ args->cmd = (args->cmd & ~IOC_DIRMASK) | IOC_INOUT;
+ break;
+
+ case LINUX_VIDIOC_G_FMT:
+ case LINUX_VIDIOC_S_FMT:
+ case LINUX_VIDIOC_TRY_FMT:
+ error = copyin((void *)args->arg, &l_vformat, sizeof(l_vformat));
+ if (error)
+ return (error);
+ if ((error = fget(td, args->fd, &fp)) != 0)
+ return (error);
+ if (linux_to_bsd_v4l2_format(&l_vformat, &vformat) != 0)
+ error = EINVAL;
+ else if ((args->cmd & 0xffff) == LINUX_VIDIOC_G_FMT)
+ error = fo_ioctl(fp, VIDIOC_G_FMT, &vformat,
+ td->td_ucred, td);
+ else if ((args->cmd & 0xffff) == LINUX_VIDIOC_S_FMT)
+ error = fo_ioctl(fp, VIDIOC_S_FMT, &vformat,
+ td->td_ucred, td);
+ else
+ error = fo_ioctl(fp, VIDIOC_TRY_FMT, &vformat,
+ td->td_ucred, td);
+ bsd_to_linux_v4l2_format(&vformat, &l_vformat);
+ copyout(&l_vformat, (void *)args->arg, sizeof(l_vformat));
+ fdrop(fp, td);
+ return (error);
+
+ case LINUX_VIDIOC_ENUMSTD:
+ error = copyin((void *)args->arg, &l_vstd, sizeof(l_vstd));
+ if (error)
+ return (error);
+ linux_to_bsd_v4l2_standard(&l_vstd, &vstd);
+ if ((error = fget(td, args->fd, &fp)) != 0)
+ return (error);
+ error = fo_ioctl(fp, VIDIOC_ENUMSTD, (caddr_t)&vstd,
+ td->td_ucred, td);
+ if (error) {
+ fdrop(fp, td);
+ return (error);
+ }
+ bsd_to_linux_v4l2_standard(&vstd, &l_vstd);
+ error = copyout(&l_vstd, (void *)args->arg, sizeof(l_vstd));
+ fdrop(fp, td);
+ return (error);
+
+ case LINUX_VIDIOC_ENUMINPUT:
+ /*
+ * The Linux struct l_v4l2_input differs only in size,
+ * it has no padding at the end.
+ */
+ error = copyin((void *)args->arg, &vinp,
+ sizeof(struct l_v4l2_input));
+ if (error != 0)
+ return (error);
+ if ((error = fget(td, args->fd, &fp)) != 0)
+ return (error);
+ error = fo_ioctl(fp, VIDIOC_ENUMINPUT, (caddr_t)&vinp,
+ td->td_ucred, td);
+ if (error) {
+ fdrop(fp, td);
+ return (error);
+ }
+ error = copyout(&vinp, (void *)args->arg,
+ sizeof(struct l_v4l2_input));
+ fdrop(fp, td);
+ return (error);
+
+ case LINUX_VIDIOC_QUERYBUF:
+ case LINUX_VIDIOC_QBUF:
+ case LINUX_VIDIOC_DQBUF:
+ error = copyin((void *)args->arg, &l_vbuf, sizeof(l_vbuf));
+ if (error)
+ return (error);
+ if ((error = fget(td, args->fd, &fp)) != 0)
+ return (error);
+ linux_to_bsd_v4l2_buffer(&l_vbuf, &vbuf);
+ if ((args->cmd & 0xffff) == LINUX_VIDIOC_QUERYBUF)
+ error = fo_ioctl(fp, VIDIOC_QUERYBUF, &vbuf,
+ td->td_ucred, td);
+ else if ((args->cmd & 0xffff) == LINUX_VIDIOC_QBUF)
+ error = fo_ioctl(fp, VIDIOC_QBUF, &vbuf,
+ td->td_ucred, td);
+ else
+ error = fo_ioctl(fp, VIDIOC_DQBUF, &vbuf,
+ td->td_ucred, td);
+ bsd_to_linux_v4l2_buffer(&vbuf, &l_vbuf);
+ copyout(&l_vbuf, (void *)args->arg, sizeof(l_vbuf));
+ fdrop(fp, td);
+ return (error);
+
+ /*
+ * XXX TODO - these need 32 -> 64 bit conversion:
+ * (are any of them needed for webcams?)
+ */
+ case LINUX_VIDIOC_G_FBUF:
+ case LINUX_VIDIOC_S_FBUF:
+
+ case LINUX_VIDIOC_G_EXT_CTRLS:
+ case LINUX_VIDIOC_S_EXT_CTRLS:
+ case LINUX_VIDIOC_TRY_EXT_CTRLS:
+
+ case LINUX_VIDIOC_DQEVENT:
+
+ default: return (ENOIOCTL);
+ }
+
+ error = ioctl(td, (struct ioctl_args *)args);
+ return (error);
+}
+
/*
* Support for emulators/linux-libusb. This port uses FBSD_LUSB* macros
* instead of USB* ones. This lets us to provide correct values for cmd.
diff --git a/sys/compat/linux/linux_ioctl.h b/sys/compat/linux/linux_ioctl.h
index 08ccf88..c075231 100644
--- a/sys/compat/linux/linux_ioctl.h
+++ b/sys/compat/linux/linux_ioctl.h
@@ -32,6 +32,17 @@
#define _LINUX_IOCTL_H_
/*
+ * ioctl
+ *
+ * XXX comments in Linux' <asm-generic/ioctl.h> indicate these
+ * could be arch-dependant...
+ */
+#define LINUX_IOC_VOID 0
+#define LINUX_IOC_IN 0x40000000
+#define LINUX_IOC_OUT 0x80000000
+#define LINUX_IOC_INOUT (LINUX_IOC_IN|LINUX_IOC_OUT)
+
+/*
* disk
*/
#define LINUX_BLKROSET 0x125d
@@ -612,6 +623,92 @@ int linux_ifname(struct ifnet *, char *, size_t);
#define LINUX_IOCTL_VIDEO_MIN LINUX_VIDIOCGCAP
#define LINUX_IOCTL_VIDEO_MAX LINUX_VIDIOCSVBIFMT
+/* videodev2 aka V4L2 */
+
+#define LINUX_VIDIOC_QUERYCAP 0x5600 /* 0x80685600 */
+#define LINUX_VIDIOC_RESERVED 0x5601 /* 0x00005601 */
+#define LINUX_VIDIOC_ENUM_FMT 0x5602 /* 0xc0405602 */
+#define LINUX_VIDIOC_G_FMT 0x5604 /* 0xc0cc5604 */
+#define LINUX_VIDIOC_S_FMT 0x5605 /* 0xc0cc5605 */
+#define LINUX_VIDIOC_REQBUFS 0x5608 /* 0xc0145608 */
+#define LINUX_VIDIOC_QUERYBUF 0x5609 /* 0xc0445609 */
+#define LINUX_VIDIOC_G_FBUF 0x560a /* 0x802c560a */
+#define LINUX_VIDIOC_S_FBUF 0x560b /* 0x402c560b */
+#define LINUX_VIDIOC_OVERLAY 0x560e /* 0x4004560e */
+#define LINUX_VIDIOC_QBUF 0x560f /* 0xc044560f */
+#define LINUX_VIDIOC_DQBUF 0x5611 /* 0xc0445611 */
+#define LINUX_VIDIOC_STREAMON 0x5612 /* 0x40045612 */
+#define LINUX_VIDIOC_STREAMOFF 0x5613 /* 0x40045613 */
+#define LINUX_VIDIOC_G_PARM 0x5615 /* 0xc0cc5615 */
+#define LINUX_VIDIOC_S_PARM 0x5616 /* 0xc0cc5616 */
+#define LINUX_VIDIOC_G_STD 0x5617 /* 0x80085617 */
+#define LINUX_VIDIOC_S_STD 0x5618 /* 0x40085618 */
+#define LINUX_VIDIOC_ENUMSTD 0x5619 /* 0xc0405619 */
+#define LINUX_VIDIOC_ENUMINPUT 0x561a /* 0xc04c561a */
+#define LINUX_VIDIOC_G_CTRL 0x561b /* 0xc008561b */
+#define LINUX_VIDIOC_S_CTRL 0x561c /* 0xc008561c */
+#define LINUX_VIDIOC_G_TUNER 0x561d /* 0xc054561d */
+#define LINUX_VIDIOC_S_TUNER 0x561e /* 0x4054561e */
+#define LINUX_VIDIOC_G_AUDIO 0x5621 /* 0x80345621 */
+#define LINUX_VIDIOC_S_AUDIO 0x5622 /* 0x40345622 */
+#define LINUX_VIDIOC_QUERYCTRL 0x5624 /* 0xc0445624 */
+#define LINUX_VIDIOC_QUERYMENU 0x5625 /* 0xc02c5625 */
+#define LINUX_VIDIOC_G_INPUT 0x5626 /* 0x80045626 */
+#define LINUX_VIDIOC_S_INPUT 0x5627 /* 0xc0045627 */
+#define LINUX_VIDIOC_G_OUTPUT 0x562e /* 0x8004562e */
+#define LINUX_VIDIOC_S_OUTPUT 0x562f /* 0xc004562f */
+#define LINUX_VIDIOC_ENUMOUTPUT 0x5630 /* 0xc0485630 */
+#define LINUX_VIDIOC_G_AUDOUT 0x5631 /* 0x80345631 */
+#define LINUX_VIDIOC_S_AUDOUT 0x5632 /* 0x40345632 */
+#define LINUX_VIDIOC_G_MODULATOR 0x5636 /* 0xc0445636 */
+#define LINUX_VIDIOC_S_MODULATOR 0x5637 /* 0x40445637 */
+#define LINUX_VIDIOC_G_FREQUENCY 0x5638 /* 0xc02c5638 */
+#define LINUX_VIDIOC_S_FREQUENCY 0x5639 /* 0x402c5639 */
+#define LINUX_VIDIOC_CROPCAP 0x563a /* 0xc02c563a */
+#define LINUX_VIDIOC_G_CROP 0x563b /* 0xc014563b */
+#define LINUX_VIDIOC_S_CROP 0x563c /* 0x4014563c */
+#define LINUX_VIDIOC_G_JPEGCOMP 0x563d /* 0x808c563d */
+#define LINUX_VIDIOC_S_JPEGCOMP 0x563e /* 0x408c563e */
+#define LINUX_VIDIOC_QUERYSTD 0x563f /* 0x8008563f */
+#define LINUX_VIDIOC_TRY_FMT 0x5640 /* 0xc0cc5640 */
+#define LINUX_VIDIOC_ENUMAUDIO 0x5641 /* 0xc0345641 */
+#define LINUX_VIDIOC_ENUMAUDOUT 0x5642 /* 0xc0345642 */
+#define LINUX_VIDIOC_G_PRIORITY 0x5643 /* 0x80045643 */
+#define LINUX_VIDIOC_S_PRIORITY 0x5644 /* 0x40045644 */
+#define LINUX_VIDIOC_G_SLICED_VBI_CAP 0x5645 /* 0xc0745645 */
+#define LINUX_VIDIOC_LOG_STATUS 0x5646 /* 0x00005646 */
+#define LINUX_VIDIOC_G_EXT_CTRLS 0x5647 /* 0xc0185647 */
+#define LINUX_VIDIOC_S_EXT_CTRLS 0x5648 /* 0xc0185648 */
+#define LINUX_VIDIOC_TRY_EXT_CTRLS 0x5649 /* 0xc0185649 */
+#define LINUX_VIDIOC_ENUM_FRAMESIZES 0x564a /* 0xc02c564a */
+#define LINUX_VIDIOC_ENUM_FRAMEINTERVALS 0x564b /* 0xc034564b */
+#define LINUX_VIDIOC_G_ENC_INDEX 0x564c /* 0x8818564c */
+#define LINUX_VIDIOC_ENCODER_CMD 0x564d /* 0xc028564d */
+#define LINUX_VIDIOC_TRY_ENCODER_CMD 0x564e /* 0xc028564e */
+#define LINUX_VIDIOC_DBG_S_REGISTER 0x564f /* 0x4038564f */
+#define LINUX_VIDIOC_DBG_G_REGISTER 0x5650 /* 0xc0385650 */
+#define LINUX_VIDIOC_DBG_G_CHIP_IDENT 0x5651 /* 0xc02c5651 */
+#define LINUX_VIDIOC_S_HW_FREQ_SEEK 0x5652 /* 0x40305652 */
+#define LINUX_VIDIOC_ENUM_DV_PRESETS 0x5653 /* 0xc0405653 */
+#define LINUX_VIDIOC_S_DV_PRESET 0x5654 /* 0xc0145654 */
+#define LINUX_VIDIOC_G_DV_PRESET 0x5655 /* 0xc0145655 */
+#define LINUX_VIDIOC_QUERY_DV_PRESET 0x5656 /* 0x80145656 */
+#define LINUX_VIDIOC_S_DV_TIMINGS 0x5657 /* 0xc0845657 */
+#define LINUX_VIDIOC_G_DV_TIMINGS 0x5658 /* 0xc0845658 */
+#define LINUX_VIDIOC_DQEVENT 0x5659 /* 0x80785659 */
+#define LINUX_VIDIOC_SUBSCRIBE_EVENT 0x565a /* 0x4020565a */
+#define LINUX_VIDIOC_UNSUBSCRIBE_EVENT 0x565b /* 0x4020565b */
+
+#define LINUX_VIDIOC_OVERLAY_OLD 0x560e /* 0xc004560e */
+#define LINUX_VIDIOC_S_PARM_OLD 0x5616 /* 0x40cc5616 */
+#define LINUX_VIDIOC_S_CTRL_OLD 0x561c /* 0x4008561c */
+#define LINUX_VIDIOC_G_AUDIO_OLD 0x5621 /* 0xc0345621 */
+#define LINUX_VIDIOC_G_AUDOUT_OLD 0x5631 /* 0xc0345631 */
+#define LINUX_VIDIOC_CROPCAP_OLD 0x563a /* 0x802c563a */
+
+#define LINUX_IOCTL_VIDEO2_MIN LINUX_VIDIOC_QUERYCAP
+#define LINUX_IOCTL_VIDEO2_MAX LINUX_VIDIOC_UNSUBSCRIBE_EVENT
+
/*
* Our libusb(8) calls emulated within linux(4).
*/
diff --git a/sys/compat/linux/linux_videodev.h b/sys/compat/linux/linux_videodev.h
index f6606ae..a2e5121 100644
--- a/sys/compat/linux/linux_videodev.h
+++ b/sys/compat/linux/linux_videodev.h
@@ -1,8 +1,8 @@
/*
* This header comes from linux, but it has no license. The author
* (Alan Cox @ Redhat) gave explicit permissions to use it in FreeBSD.
- * The freeBSD vendor branch for v4l gives a more detailed description
- * about this.
+ * The FreeBSD vendor branch for v4l gives a more detailed description
+ * about this in the README.
*
* $FreeBSD$
*/
diff --git a/sys/compat/linux/linux_videodev2.h b/sys/compat/linux/linux_videodev2.h
new file mode 100644
index 0000000..b10ba80
--- /dev/null
+++ b/sys/compat/linux/linux_videodev2.h
@@ -0,0 +1,1179 @@
+/*
+ * This header comes from linux, but it has no license. The author
+ * (Bill Dirks) gave explicit permissions to use it in FreeBSD.
+ * The FreeBSD vendor branch for v4l gives a more detailed description
+ * about this in the README.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef __LINUX_VIDEODEV2_H
+#define __LINUX_VIDEODEV2_H
+/*
+ * Video for Linux Two
+ *
+ * Header file for v4l or V4L2 drivers and applications, for
+ * Linux kernels 2.2.x or 2.4.x.
+ *
+ * See http://bytesex.org/v4l/ for API specs and other
+ * v4l2 documentation.
+ *
+ * Author: Bill Dirks <bdirks@pacbell.net>
+ * Justin Schoeman
+ * et al.
+ */
+#ifdef __FreeBSD__
+#define __user
+typedef uint64_t __u64;
+typedef int64_t __s64;
+#else
+#ifdef __KERNEL__
+#include <linux/time.h> /* need struct timeval */
+#include <linux/poll.h>
+#include <linux/device.h>
+#include <linux/mutex.h>
+#endif
+#include <linux/compiler.h> /* need __user */
+#endif
+
+
+#define OBSOLETE_OWNER 1 /* It will be removed for 2.6.17 */
+#define HAVE_V4L2 1
+
+/*
+ * Common stuff for both V4L1 and V4L2
+ * Moved from videodev.h
+ */
+
+#define VIDEO_MAX_FRAME 32
+
+#define VID_TYPE_CAPTURE 1 /* Can capture */
+#define VID_TYPE_TUNER 2 /* Can tune */
+#define VID_TYPE_TELETEXT 4 /* Does teletext */
+#define VID_TYPE_OVERLAY 8 /* Overlay onto frame buffer */
+#define VID_TYPE_CHROMAKEY 16 /* Overlay by chromakey */
+#define VID_TYPE_CLIPPING 32 /* Can clip */
+#define VID_TYPE_FRAMERAM 64 /* Uses the frame buffer memory */
+#define VID_TYPE_SCALES 128 /* Scalable */
+#define VID_TYPE_MONOCHROME 256 /* Monochrome only */
+#define VID_TYPE_SUBCAPTURE 512 /* Can capture subareas of the image */
+#define VID_TYPE_MPEG_DECODER 1024 /* Can decode MPEG streams */
+#define VID_TYPE_MPEG_ENCODER 2048 /* Can encode MPEG streams */
+#define VID_TYPE_MJPEG_DECODER 4096 /* Can decode MJPEG streams */
+#define VID_TYPE_MJPEG_ENCODER 8192 /* Can encode MJPEG streams */
+
+#ifdef __KERNEL__
+
+/* Minor device allocation */
+#define MINOR_VFL_TYPE_GRABBER_MIN 0
+#define MINOR_VFL_TYPE_GRABBER_MAX 63
+#define MINOR_VFL_TYPE_RADIO_MIN 64
+#define MINOR_VFL_TYPE_RADIO_MAX 127
+#define MINOR_VFL_TYPE_VTX_MIN 192
+#define MINOR_VFL_TYPE_VTX_MAX 223
+#define MINOR_VFL_TYPE_VBI_MIN 224
+#define MINOR_VFL_TYPE_VBI_MAX 255
+
+#define VFL_TYPE_GRABBER 0
+#define VFL_TYPE_VBI 1
+#define VFL_TYPE_RADIO 2
+#define VFL_TYPE_VTX 3
+
+struct video_device
+{
+ /* device info */
+ struct device *dev;
+ char name[32];
+ int type; /* v4l1 */
+ int type2; /* v4l2 */
+ int hardware;
+ int minor;
+
+ /* device ops + callbacks */
+ const struct file_operations *fops;
+ void (*release)(struct video_device *vfd);
+
+
+#if OBSOLETE_OWNER /* to be removed in 2.6.15 */
+ /* obsolete -- fops->owner is used instead */
+ struct module *owner;
+ /* dev->driver_data will be used instead some day.
+ * Use the video_{get|set}_drvdata() helper functions,
+ * so the switch over will be transparent for you.
+ * Or use {pci|usb}_{get|set}_drvdata() directly. */
+ void *priv;
+#endif
+
+ /* for videodev.c intenal usage -- please don't touch */
+ int users; /* video_exclusive_{open|close} ... */
+ struct mutex lock; /* ... helper function uses these */
+ char devfs_name[64]; /* devfs */
+ struct class_device class_dev; /* sysfs */
+};
+
+#define VIDEO_MAJOR 81
+
+extern int video_register_device(struct video_device *, int type, int nr);
+extern void video_unregister_device(struct video_device *);
+extern int video_usercopy(struct inode *inode, struct file *file,
+ unsigned int cmd, unsigned long arg,
+ int (*func)(struct inode *inode, struct file *file,
+ unsigned int cmd, void *arg));
+
+/* helper functions to alloc / release struct video_device, the
+ later can be used for video_device->release() */
+struct video_device *video_device_alloc(void);
+void video_device_release(struct video_device *vfd);
+
+#endif
+
+/*
+ * M I S C E L L A N E O U S
+ */
+
+/* Four-character-code (FOURCC) */
+#define v4l2_fourcc(a,b,c,d)\
+ (((__u32)(a)<<0)|((__u32)(b)<<8)|((__u32)(c)<<16)|((__u32)(d)<<24))
+
+/*
+ * E N U M S
+ */
+enum v4l2_field {
+ V4L2_FIELD_ANY = 0, /* driver can choose from none,
+ top, bottom, interlaced
+ depending on whatever it thinks
+ is approximate ... */
+ V4L2_FIELD_NONE = 1, /* this device has no fields ... */
+ V4L2_FIELD_TOP = 2, /* top field only */
+ V4L2_FIELD_BOTTOM = 3, /* bottom field only */
+ V4L2_FIELD_INTERLACED = 4, /* both fields interlaced */
+ V4L2_FIELD_SEQ_TB = 5, /* both fields sequential into one
+ buffer, top-bottom order */
+ V4L2_FIELD_SEQ_BT = 6, /* same as above + bottom-top order */
+ V4L2_FIELD_ALTERNATE = 7, /* both fields alternating into
+ separate buffers */
+};
+#define V4L2_FIELD_HAS_TOP(field) \
+ ((field) == V4L2_FIELD_TOP ||\
+ (field) == V4L2_FIELD_INTERLACED ||\
+ (field) == V4L2_FIELD_SEQ_TB ||\
+ (field) == V4L2_FIELD_SEQ_BT)
+#define V4L2_FIELD_HAS_BOTTOM(field) \
+ ((field) == V4L2_FIELD_BOTTOM ||\
+ (field) == V4L2_FIELD_INTERLACED ||\
+ (field) == V4L2_FIELD_SEQ_TB ||\
+ (field) == V4L2_FIELD_SEQ_BT)
+#define V4L2_FIELD_HAS_BOTH(field) \
+ ((field) == V4L2_FIELD_INTERLACED ||\
+ (field) == V4L2_FIELD_SEQ_TB ||\
+ (field) == V4L2_FIELD_SEQ_BT)
+
+enum v4l2_buf_type {
+ V4L2_BUF_TYPE_VIDEO_CAPTURE = 1,
+ V4L2_BUF_TYPE_VIDEO_OUTPUT = 2,
+ V4L2_BUF_TYPE_VIDEO_OVERLAY = 3,
+ V4L2_BUF_TYPE_VBI_CAPTURE = 4,
+ V4L2_BUF_TYPE_VBI_OUTPUT = 5,
+#if 1
+ /* Experimental Sliced VBI */
+ V4L2_BUF_TYPE_SLICED_VBI_CAPTURE = 6,
+ V4L2_BUF_TYPE_SLICED_VBI_OUTPUT = 7,
+#endif
+ V4L2_BUF_TYPE_PRIVATE = 0x80,
+};
+
+enum v4l2_ctrl_type {
+ V4L2_CTRL_TYPE_INTEGER = 1,
+ V4L2_CTRL_TYPE_BOOLEAN = 2,
+ V4L2_CTRL_TYPE_MENU = 3,
+ V4L2_CTRL_TYPE_BUTTON = 4,
+};
+
+enum v4l2_tuner_type {
+ V4L2_TUNER_RADIO = 1,
+ V4L2_TUNER_ANALOG_TV = 2,
+ V4L2_TUNER_DIGITAL_TV = 3,
+};
+
+enum v4l2_memory {
+ V4L2_MEMORY_MMAP = 1,
+ V4L2_MEMORY_USERPTR = 2,
+ V4L2_MEMORY_OVERLAY = 3,
+};
+
+/* see also http://vektor.theorem.ca/graphics/ycbcr/ */
+enum v4l2_colorspace {
+ /* ITU-R 601 -- broadcast NTSC/PAL */
+ V4L2_COLORSPACE_SMPTE170M = 1,
+
+ /* 1125-Line (US) HDTV */
+ V4L2_COLORSPACE_SMPTE240M = 2,
+
+ /* HD and modern captures. */
+ V4L2_COLORSPACE_REC709 = 3,
+
+ /* broken BT878 extents (601, luma range 16-253 instead of 16-235) */
+ V4L2_COLORSPACE_BT878 = 4,
+
+ /* These should be useful. Assume 601 extents. */
+ V4L2_COLORSPACE_470_SYSTEM_M = 5,
+ V4L2_COLORSPACE_470_SYSTEM_BG = 6,
+
+ /* I know there will be cameras that send this. So, this is
+ * unspecified chromaticities and full 0-255 on each of the
+ * Y'CbCr components
+ */
+ V4L2_COLORSPACE_JPEG = 7,
+
+ /* For RGB colourspaces, this is probably a good start. */
+ V4L2_COLORSPACE_SRGB = 8,
+};
+
+enum v4l2_priority {
+ V4L2_PRIORITY_UNSET = 0, /* not initialized */
+ V4L2_PRIORITY_BACKGROUND = 1,
+ V4L2_PRIORITY_INTERACTIVE = 2,
+ V4L2_PRIORITY_RECORD = 3,
+ V4L2_PRIORITY_DEFAULT = V4L2_PRIORITY_INTERACTIVE,
+};
+
+struct v4l2_rect {
+ __s32 left;
+ __s32 top;
+ __s32 width;
+ __s32 height;
+};
+
+struct v4l2_fract {
+ __u32 numerator;
+ __u32 denominator;
+};
+
+/*
+ * D R I V E R C A P A B I L I T I E S
+ */
+struct v4l2_capability
+{
+ __u8 driver[16]; /* i.e. "bttv" */
+ __u8 card[32]; /* i.e. "Hauppauge WinTV" */
+ __u8 bus_info[32]; /* "PCI:" + pci_name(pci_dev) */
+ __u32 version; /* should use KERNEL_VERSION() */
+ __u32 capabilities; /* Device capabilities */
+ __u32 reserved[4];
+};
+
+/* Values for 'capabilities' field */
+#define V4L2_CAP_VIDEO_CAPTURE 0x00000001 /* Is a video capture device */
+#define V4L2_CAP_VIDEO_OUTPUT 0x00000002 /* Is a video output device */
+#define V4L2_CAP_VIDEO_OVERLAY 0x00000004 /* Can do video overlay */
+#define V4L2_CAP_VBI_CAPTURE 0x00000010 /* Is a raw VBI capture device */
+#define V4L2_CAP_VBI_OUTPUT 0x00000020 /* Is a raw VBI output device */
+#if 1
+#define V4L2_CAP_SLICED_VBI_CAPTURE 0x00000040 /* Is a sliced VBI capture device */
+#define V4L2_CAP_SLICED_VBI_OUTPUT 0x00000080 /* Is a sliced VBI output device */
+#endif
+#define V4L2_CAP_RDS_CAPTURE 0x00000100 /* RDS data capture */
+
+#define V4L2_CAP_TUNER 0x00010000 /* has a tuner */
+#define V4L2_CAP_AUDIO 0x00020000 /* has audio support */
+#define V4L2_CAP_RADIO 0x00040000 /* is a radio device */
+
+#define V4L2_CAP_READWRITE 0x01000000 /* read/write systemcalls */
+#define V4L2_CAP_ASYNCIO 0x02000000 /* async I/O */
+#define V4L2_CAP_STREAMING 0x04000000 /* streaming I/O ioctls */
+
+/*
+ * V I D E O I M A G E F O R M A T
+ */
+
+struct v4l2_pix_format
+{
+ __u32 width;
+ __u32 height;
+ __u32 pixelformat;
+ enum v4l2_field field;
+ __u32 bytesperline; /* for padding, zero if unused */
+ __u32 sizeimage;
+ enum v4l2_colorspace colorspace;
+ __u32 priv; /* private data, depends on pixelformat */
+};
+
+/* Pixel format FOURCC depth Description */
+#define V4L2_PIX_FMT_RGB332 v4l2_fourcc('R','G','B','1') /* 8 RGB-3-3-2 */
+#define V4L2_PIX_FMT_RGB555 v4l2_fourcc('R','G','B','O') /* 16 RGB-5-5-5 */
+#define V4L2_PIX_FMT_RGB565 v4l2_fourcc('R','G','B','P') /* 16 RGB-5-6-5 */
+#define V4L2_PIX_FMT_RGB555X v4l2_fourcc('R','G','B','Q') /* 16 RGB-5-5-5 BE */
+#define V4L2_PIX_FMT_RGB565X v4l2_fourcc('R','G','B','R') /* 16 RGB-5-6-5 BE */
+#define V4L2_PIX_FMT_BGR24 v4l2_fourcc('B','G','R','3') /* 24 BGR-8-8-8 */
+#define V4L2_PIX_FMT_RGB24 v4l2_fourcc('R','G','B','3') /* 24 RGB-8-8-8 */
+#define V4L2_PIX_FMT_BGR32 v4l2_fourcc('B','G','R','4') /* 32 BGR-8-8-8-8 */
+#define V4L2_PIX_FMT_RGB32 v4l2_fourcc('R','G','B','4') /* 32 RGB-8-8-8-8 */
+#define V4L2_PIX_FMT_GREY v4l2_fourcc('G','R','E','Y') /* 8 Greyscale */
+#define V4L2_PIX_FMT_YVU410 v4l2_fourcc('Y','V','U','9') /* 9 YVU 4:1:0 */
+#define V4L2_PIX_FMT_YVU420 v4l2_fourcc('Y','V','1','2') /* 12 YVU 4:2:0 */
+#define V4L2_PIX_FMT_YUYV v4l2_fourcc('Y','U','Y','V') /* 16 YUV 4:2:2 */
+#define V4L2_PIX_FMT_UYVY v4l2_fourcc('U','Y','V','Y') /* 16 YUV 4:2:2 */
+#define V4L2_PIX_FMT_YUV422P v4l2_fourcc('4','2','2','P') /* 16 YVU422 planar */
+#define V4L2_PIX_FMT_YUV411P v4l2_fourcc('4','1','1','P') /* 16 YVU411 planar */
+#define V4L2_PIX_FMT_Y41P v4l2_fourcc('Y','4','1','P') /* 12 YUV 4:1:1 */
+
+/* two planes -- one Y, one Cr + Cb interleaved */
+#define V4L2_PIX_FMT_NV12 v4l2_fourcc('N','V','1','2') /* 12 Y/CbCr 4:2:0 */
+#define V4L2_PIX_FMT_NV21 v4l2_fourcc('N','V','2','1') /* 12 Y/CrCb 4:2:0 */
+
+/* The following formats are not defined in the V4L2 specification */
+#define V4L2_PIX_FMT_YUV410 v4l2_fourcc('Y','U','V','9') /* 9 YUV 4:1:0 */
+#define V4L2_PIX_FMT_YUV420 v4l2_fourcc('Y','U','1','2') /* 12 YUV 4:2:0 */
+#define V4L2_PIX_FMT_YYUV v4l2_fourcc('Y','Y','U','V') /* 16 YUV 4:2:2 */
+#define V4L2_PIX_FMT_HI240 v4l2_fourcc('H','I','2','4') /* 8 8-bit color */
+
+/* see http://www.siliconimaging.com/RGB%20Bayer.htm */
+#define V4L2_PIX_FMT_SBGGR8 v4l2_fourcc('B','A','8','1') /* 8 BGBG.. GRGR.. */
+
+/* compressed formats */
+#define V4L2_PIX_FMT_MJPEG v4l2_fourcc('M','J','P','G') /* Motion-JPEG */
+#define V4L2_PIX_FMT_JPEG v4l2_fourcc('J','P','E','G') /* JFIF JPEG */
+#define V4L2_PIX_FMT_DV v4l2_fourcc('d','v','s','d') /* 1394 */
+#define V4L2_PIX_FMT_MPEG v4l2_fourcc('M','P','E','G') /* MPEG */
+
+/* Vendor-specific formats */
+#define V4L2_PIX_FMT_WNVA v4l2_fourcc('W','N','V','A') /* Winnov hw compress */
+#define V4L2_PIX_FMT_SN9C10X v4l2_fourcc('S','9','1','0') /* SN9C10x compression */
+#define V4L2_PIX_FMT_PWC1 v4l2_fourcc('P','W','C','1') /* pwc older webcam */
+#define V4L2_PIX_FMT_PWC2 v4l2_fourcc('P','W','C','2') /* pwc newer webcam */
+#define V4L2_PIX_FMT_ET61X251 v4l2_fourcc('E','6','2','5') /* ET61X251 compression */
+
+/*
+ * F O R M A T E N U M E R A T I O N
+ */
+struct v4l2_fmtdesc
+{
+ __u32 index; /* Format number */
+ enum v4l2_buf_type type; /* buffer type */
+ __u32 flags;
+ __u8 description[32]; /* Description string */
+ __u32 pixelformat; /* Format fourcc */
+ __u32 reserved[4];
+};
+
+#define V4L2_FMT_FLAG_COMPRESSED 0x0001
+
+
+/*
+ * T I M E C O D E
+ */
+struct v4l2_timecode
+{
+ __u32 type;
+ __u32 flags;
+ __u8 frames;
+ __u8 seconds;
+ __u8 minutes;
+ __u8 hours;
+ __u8 userbits[4];
+};
+
+/* Type */
+#define V4L2_TC_TYPE_24FPS 1
+#define V4L2_TC_TYPE_25FPS 2
+#define V4L2_TC_TYPE_30FPS 3
+#define V4L2_TC_TYPE_50FPS 4
+#define V4L2_TC_TYPE_60FPS 5
+
+/* Flags */
+#define V4L2_TC_FLAG_DROPFRAME 0x0001 /* "drop-frame" mode */
+#define V4L2_TC_FLAG_COLORFRAME 0x0002
+#define V4L2_TC_USERBITS_field 0x000C
+#define V4L2_TC_USERBITS_USERDEFINED 0x0000
+#define V4L2_TC_USERBITS_8BITCHARS 0x0008
+/* The above is based on SMPTE timecodes */
+
+
+/*
+ * M P E G C O M P R E S S I O N P A R A M E T E R S
+ *
+ * ### WARNING: this is still work-in-progress right now, most likely
+ * ### there will be some incompatible changes.
+ *
+ */
+
+
+enum v4l2_bitrate_mode {
+ V4L2_BITRATE_NONE = 0, /* not specified */
+ V4L2_BITRATE_CBR, /* constant bitrate */
+ V4L2_BITRATE_VBR, /* variable bitrate */
+};
+struct v4l2_bitrate {
+ /* rates are specified in kbit/sec */
+ enum v4l2_bitrate_mode mode;
+ __u32 min;
+ __u32 target; /* use this one for CBR */
+ __u32 max;
+};
+
+enum v4l2_mpeg_streamtype {
+ V4L2_MPEG_SS_1, /* MPEG-1 system stream */
+ V4L2_MPEG_PS_2, /* MPEG-2 program stream */
+ V4L2_MPEG_TS_2, /* MPEG-2 transport stream */
+ V4L2_MPEG_PS_DVD, /* MPEG-2 program stream with DVD header fixups */
+};
+enum v4l2_mpeg_audiotype {
+ V4L2_MPEG_AU_2_I, /* MPEG-2 layer 1 */
+ V4L2_MPEG_AU_2_II, /* MPEG-2 layer 2 */
+ V4L2_MPEG_AU_2_III, /* MPEG-2 layer 3 */
+ V4L2_MPEG_AC3, /* AC3 */
+ V4L2_MPEG_LPCM, /* LPCM */
+};
+enum v4l2_mpeg_videotype {
+ V4L2_MPEG_VI_1, /* MPEG-1 */
+ V4L2_MPEG_VI_2, /* MPEG-2 */
+};
+enum v4l2_mpeg_aspectratio {
+ V4L2_MPEG_ASPECT_SQUARE = 1, /* square pixel */
+ V4L2_MPEG_ASPECT_4_3 = 2, /* 4 : 3 */
+ V4L2_MPEG_ASPECT_16_9 = 3, /* 16 : 9 */
+ V4L2_MPEG_ASPECT_1_221 = 4, /* 1 : 2,21 */
+};
+
+struct v4l2_mpeg_compression {
+ /* general */
+ enum v4l2_mpeg_streamtype st_type;
+ struct v4l2_bitrate st_bitrate;
+
+ /* transport streams */
+ __u16 ts_pid_pmt;
+ __u16 ts_pid_audio;
+ __u16 ts_pid_video;
+ __u16 ts_pid_pcr;
+
+ /* program stream */
+ __u16 ps_size;
+ __u16 reserved_1; /* align */
+
+ /* audio */
+ enum v4l2_mpeg_audiotype au_type;
+ struct v4l2_bitrate au_bitrate;
+ __u32 au_sample_rate;
+ __u8 au_pesid;
+ __u8 reserved_2[3]; /* align */
+
+ /* video */
+ enum v4l2_mpeg_videotype vi_type;
+ enum v4l2_mpeg_aspectratio vi_aspect_ratio;
+ struct v4l2_bitrate vi_bitrate;
+ __u32 vi_frame_rate;
+ __u16 vi_frames_per_gop;
+ __u16 vi_bframes_count;
+ __u8 vi_pesid;
+ __u8 reserved_3[3]; /* align */
+
+ /* misc flags */
+ __u32 closed_gops:1;
+ __u32 pulldown:1;
+ __u32 reserved_4:30; /* align */
+
+ /* I don't expect the above being perfect yet ;) */
+ __u32 reserved_5[8];
+};
+
+struct v4l2_jpegcompression
+{
+ int quality;
+
+ int APPn; /* Number of APP segment to be written,
+ * must be 0..15 */
+ int APP_len; /* Length of data in JPEG APPn segment */
+ char APP_data[60]; /* Data in the JPEG APPn segment. */
+
+ int COM_len; /* Length of data in JPEG COM segment */
+ char COM_data[60]; /* Data in JPEG COM segment */
+
+ __u32 jpeg_markers; /* Which markers should go into the JPEG
+ * output. Unless you exactly know what
+ * you do, leave them untouched.
+ * Inluding less markers will make the
+ * resulting code smaller, but there will
+ * be fewer aplications which can read it.
+ * The presence of the APP and COM marker
+ * is influenced by APP_len and COM_len
+ * ONLY, not by this property! */
+
+#define V4L2_JPEG_MARKER_DHT (1<<3) /* Define Huffman Tables */
+#define V4L2_JPEG_MARKER_DQT (1<<4) /* Define Quantization Tables */
+#define V4L2_JPEG_MARKER_DRI (1<<5) /* Define Restart Interval */
+#define V4L2_JPEG_MARKER_COM (1<<6) /* Comment segment */
+#define V4L2_JPEG_MARKER_APP (1<<7) /* App segment, driver will
+ * allways use APP0 */
+};
+
+
+/*
+ * M E M O R Y - M A P P I N G B U F F E R S
+ */
+struct v4l2_requestbuffers
+{
+ __u32 count;
+ enum v4l2_buf_type type;
+ enum v4l2_memory memory;
+ __u32 reserved[2];
+};
+
+struct v4l2_buffer
+{
+ __u32 index;
+ enum v4l2_buf_type type;
+ __u32 bytesused;
+ __u32 flags;
+ enum v4l2_field field;
+ struct timeval timestamp;
+ struct v4l2_timecode timecode;
+ __u32 sequence;
+
+ /* memory location */
+ enum v4l2_memory memory;
+ union {
+ __u32 offset;
+ unsigned long userptr;
+ } m;
+ __u32 length;
+ __u32 input;
+ __u32 reserved;
+};
+
+/* Flags for 'flags' field */
+#define V4L2_BUF_FLAG_MAPPED 0x0001 /* Buffer is mapped (flag) */
+#define V4L2_BUF_FLAG_QUEUED 0x0002 /* Buffer is queued for processing */
+#define V4L2_BUF_FLAG_DONE 0x0004 /* Buffer is ready */
+#define V4L2_BUF_FLAG_KEYFRAME 0x0008 /* Image is a keyframe (I-frame) */
+#define V4L2_BUF_FLAG_PFRAME 0x0010 /* Image is a P-frame */
+#define V4L2_BUF_FLAG_BFRAME 0x0020 /* Image is a B-frame */
+#define V4L2_BUF_FLAG_TIMECODE 0x0100 /* timecode field is valid */
+#define V4L2_BUF_FLAG_INPUT 0x0200 /* input field is valid */
+
+/*
+ * O V E R L A Y P R E V I E W
+ */
+struct v4l2_framebuffer
+{
+ __u32 capability;
+ __u32 flags;
+/* FIXME: in theory we should pass something like PCI device + memory
+ * region + offset instead of some physical address */
+ void* base;
+ struct v4l2_pix_format fmt;
+};
+/* Flags for the 'capability' field. Read only */
+#define V4L2_FBUF_CAP_EXTERNOVERLAY 0x0001
+#define V4L2_FBUF_CAP_CHROMAKEY 0x0002
+#define V4L2_FBUF_CAP_LIST_CLIPPING 0x0004
+#define V4L2_FBUF_CAP_BITMAP_CLIPPING 0x0008
+/* Flags for the 'flags' field. */
+#define V4L2_FBUF_FLAG_PRIMARY 0x0001
+#define V4L2_FBUF_FLAG_OVERLAY 0x0002
+#define V4L2_FBUF_FLAG_CHROMAKEY 0x0004
+
+struct v4l2_clip
+{
+ struct v4l2_rect c;
+ struct v4l2_clip __user *next;
+};
+
+struct v4l2_window
+{
+ struct v4l2_rect w;
+ enum v4l2_field field;
+ __u32 chromakey;
+ struct v4l2_clip __user *clips;
+ __u32 clipcount;
+ void __user *bitmap;
+};
+
+
+/*
+ * C A P T U R E P A R A M E T E R S
+ */
+struct v4l2_captureparm
+{
+ __u32 capability; /* Supported modes */
+ __u32 capturemode; /* Current mode */
+ struct v4l2_fract timeperframe; /* Time per frame in .1us units */
+ __u32 extendedmode; /* Driver-specific extensions */
+ __u32 readbuffers; /* # of buffers for read */
+ __u32 reserved[4];
+};
+/* Flags for 'capability' and 'capturemode' fields */
+#define V4L2_MODE_HIGHQUALITY 0x0001 /* High quality imaging mode */
+#define V4L2_CAP_TIMEPERFRAME 0x1000 /* timeperframe field is supported */
+
+struct v4l2_outputparm
+{
+ __u32 capability; /* Supported modes */
+ __u32 outputmode; /* Current mode */
+ struct v4l2_fract timeperframe; /* Time per frame in seconds */
+ __u32 extendedmode; /* Driver-specific extensions */
+ __u32 writebuffers; /* # of buffers for write */
+ __u32 reserved[4];
+};
+
+/*
+ * I N P U T I M A G E C R O P P I N G
+ */
+
+struct v4l2_cropcap {
+ enum v4l2_buf_type type;
+ struct v4l2_rect bounds;
+ struct v4l2_rect defrect;
+ struct v4l2_fract pixelaspect;
+};
+
+struct v4l2_crop {
+ enum v4l2_buf_type type;
+ struct v4l2_rect c;
+};
+
+/*
+ * A N A L O G V I D E O S T A N D A R D
+ */
+
+typedef __u64 v4l2_std_id;
+
+/* one bit for each */
+#define V4L2_STD_PAL_B ((v4l2_std_id)0x00000001)
+#define V4L2_STD_PAL_B1 ((v4l2_std_id)0x00000002)
+#define V4L2_STD_PAL_G ((v4l2_std_id)0x00000004)
+#define V4L2_STD_PAL_H ((v4l2_std_id)0x00000008)
+#define V4L2_STD_PAL_I ((v4l2_std_id)0x00000010)
+#define V4L2_STD_PAL_D ((v4l2_std_id)0x00000020)
+#define V4L2_STD_PAL_D1 ((v4l2_std_id)0x00000040)
+#define V4L2_STD_PAL_K ((v4l2_std_id)0x00000080)
+
+#define V4L2_STD_PAL_M ((v4l2_std_id)0x00000100)
+#define V4L2_STD_PAL_N ((v4l2_std_id)0x00000200)
+#define V4L2_STD_PAL_Nc ((v4l2_std_id)0x00000400)
+#define V4L2_STD_PAL_60 ((v4l2_std_id)0x00000800)
+
+#define V4L2_STD_NTSC_M ((v4l2_std_id)0x00001000)
+#define V4L2_STD_NTSC_M_JP ((v4l2_std_id)0x00002000)
+#define V4L2_STD_NTSC_443 ((v4l2_std_id)0x00004000)
+#define V4L2_STD_NTSC_M_KR ((v4l2_std_id)0x00008000)
+
+#define V4L2_STD_SECAM_B ((v4l2_std_id)0x00010000)
+#define V4L2_STD_SECAM_D ((v4l2_std_id)0x00020000)
+#define V4L2_STD_SECAM_G ((v4l2_std_id)0x00040000)
+#define V4L2_STD_SECAM_H ((v4l2_std_id)0x00080000)
+#define V4L2_STD_SECAM_K ((v4l2_std_id)0x00100000)
+#define V4L2_STD_SECAM_K1 ((v4l2_std_id)0x00200000)
+#define V4L2_STD_SECAM_L ((v4l2_std_id)0x00400000)
+#define V4L2_STD_SECAM_LC ((v4l2_std_id)0x00800000)
+
+/* ATSC/HDTV */
+#define V4L2_STD_ATSC_8_VSB ((v4l2_std_id)0x01000000)
+#define V4L2_STD_ATSC_16_VSB ((v4l2_std_id)0x02000000)
+
+/* some merged standards */
+#define V4L2_STD_MN (V4L2_STD_PAL_M|V4L2_STD_PAL_N|V4L2_STD_PAL_Nc|V4L2_STD_NTSC)
+#define V4L2_STD_B (V4L2_STD_PAL_B|V4L2_STD_PAL_B1|V4L2_STD_SECAM_B)
+#define V4L2_STD_GH (V4L2_STD_PAL_G|V4L2_STD_PAL_H|V4L2_STD_SECAM_G|V4L2_STD_SECAM_H)
+#define V4L2_STD_DK (V4L2_STD_PAL_DK|V4L2_STD_SECAM_DK)
+
+/* some common needed stuff */
+#define V4L2_STD_PAL_BG (V4L2_STD_PAL_B |\
+ V4L2_STD_PAL_B1 |\
+ V4L2_STD_PAL_G)
+#define V4L2_STD_PAL_DK (V4L2_STD_PAL_D |\
+ V4L2_STD_PAL_D1 |\
+ V4L2_STD_PAL_K)
+#define V4L2_STD_PAL (V4L2_STD_PAL_BG |\
+ V4L2_STD_PAL_DK |\
+ V4L2_STD_PAL_H |\
+ V4L2_STD_PAL_I)
+#define V4L2_STD_NTSC (V4L2_STD_NTSC_M |\
+ V4L2_STD_NTSC_M_JP |\
+ V4L2_STD_NTSC_M_KR)
+#define V4L2_STD_SECAM_DK (V4L2_STD_SECAM_D |\
+ V4L2_STD_SECAM_K |\
+ V4L2_STD_SECAM_K1)
+#define V4L2_STD_SECAM (V4L2_STD_SECAM_B |\
+ V4L2_STD_SECAM_G |\
+ V4L2_STD_SECAM_H |\
+ V4L2_STD_SECAM_DK |\
+ V4L2_STD_SECAM_L |\
+ V4L2_STD_SECAM_LC)
+
+#define V4L2_STD_525_60 (V4L2_STD_PAL_M |\
+ V4L2_STD_PAL_60 |\
+ V4L2_STD_NTSC |\
+ V4L2_STD_NTSC_443)
+#define V4L2_STD_625_50 (V4L2_STD_PAL |\
+ V4L2_STD_PAL_N |\
+ V4L2_STD_PAL_Nc |\
+ V4L2_STD_SECAM)
+#define V4L2_STD_ATSC (V4L2_STD_ATSC_8_VSB |\
+ V4L2_STD_ATSC_16_VSB)
+
+#define V4L2_STD_UNKNOWN 0
+#define V4L2_STD_ALL (V4L2_STD_525_60 |\
+ V4L2_STD_625_50)
+
+struct v4l2_standard
+{
+ __u32 index;
+ v4l2_std_id id;
+ __u8 name[24];
+ struct v4l2_fract frameperiod; /* Frames, not fields */
+ __u32 framelines;
+ __u32 reserved[4];
+};
+
+
+/*
+ * V I D E O I N P U T S
+ */
+struct v4l2_input
+{
+ __u32 index; /* Which input */
+ __u8 name[32]; /* Label */
+ __u32 type; /* Type of input */
+ __u32 audioset; /* Associated audios (bitfield) */
+ __u32 tuner; /* Associated tuner */
+ v4l2_std_id std;
+ __u32 status;
+ __u32 reserved[4];
+};
+/* Values for the 'type' field */
+#define V4L2_INPUT_TYPE_TUNER 1
+#define V4L2_INPUT_TYPE_CAMERA 2
+
+/* field 'status' - general */
+#define V4L2_IN_ST_NO_POWER 0x00000001 /* Attached device is off */
+#define V4L2_IN_ST_NO_SIGNAL 0x00000002
+#define V4L2_IN_ST_NO_COLOR 0x00000004
+
+/* field 'status' - analog */
+#define V4L2_IN_ST_NO_H_LOCK 0x00000100 /* No horizontal sync lock */
+#define V4L2_IN_ST_COLOR_KILL 0x00000200 /* Color killer is active */
+
+/* field 'status' - digital */
+#define V4L2_IN_ST_NO_SYNC 0x00010000 /* No synchronization lock */
+#define V4L2_IN_ST_NO_EQU 0x00020000 /* No equalizer lock */
+#define V4L2_IN_ST_NO_CARRIER 0x00040000 /* Carrier recovery failed */
+
+/* field 'status' - VCR and set-top box */
+#define V4L2_IN_ST_MACROVISION 0x01000000 /* Macrovision detected */
+#define V4L2_IN_ST_NO_ACCESS 0x02000000 /* Conditional access denied */
+#define V4L2_IN_ST_VTR 0x04000000 /* VTR time constant */
+
+/*
+ * V I D E O O U T P U T S
+ */
+struct v4l2_output
+{
+ __u32 index; /* Which output */
+ __u8 name[32]; /* Label */
+ __u32 type; /* Type of output */
+ __u32 audioset; /* Associated audios (bitfield) */
+ __u32 modulator; /* Associated modulator */
+ v4l2_std_id std;
+ __u32 reserved[4];
+};
+/* Values for the 'type' field */
+#define V4L2_OUTPUT_TYPE_MODULATOR 1
+#define V4L2_OUTPUT_TYPE_ANALOG 2
+#define V4L2_OUTPUT_TYPE_ANALOGVGAOVERLAY 3
+
+/*
+ * C O N T R O L S
+ */
+struct v4l2_control
+{
+ __u32 id;
+ __s32 value;
+};
+
+/* Used in the VIDIOC_QUERYCTRL ioctl for querying controls */
+struct v4l2_queryctrl
+{
+ __u32 id;
+ enum v4l2_ctrl_type type;
+ __u8 name[32]; /* Whatever */
+ __s32 minimum; /* Note signedness */
+ __s32 maximum;
+ __s32 step;
+ __s32 default_value;
+ __u32 flags;
+ __u32 reserved[2];
+};
+
+/* Used in the VIDIOC_QUERYMENU ioctl for querying menu items */
+struct v4l2_querymenu
+{
+ __u32 id;
+ __u32 index;
+ __u8 name[32]; /* Whatever */
+ __u32 reserved;
+};
+
+/* Control flags */
+#define V4L2_CTRL_FLAG_DISABLED 0x0001
+#define V4L2_CTRL_FLAG_GRABBED 0x0002
+
+/* Control IDs defined by V4L2 */
+#define V4L2_CID_BASE 0x00980900
+/* IDs reserved for driver specific controls */
+#define V4L2_CID_PRIVATE_BASE 0x08000000
+
+#define V4L2_CID_BRIGHTNESS (V4L2_CID_BASE+0)
+#define V4L2_CID_CONTRAST (V4L2_CID_BASE+1)
+#define V4L2_CID_SATURATION (V4L2_CID_BASE+2)
+#define V4L2_CID_HUE (V4L2_CID_BASE+3)
+#define V4L2_CID_AUDIO_VOLUME (V4L2_CID_BASE+5)
+#define V4L2_CID_AUDIO_BALANCE (V4L2_CID_BASE+6)
+#define V4L2_CID_AUDIO_BASS (V4L2_CID_BASE+7)
+#define V4L2_CID_AUDIO_TREBLE (V4L2_CID_BASE+8)
+#define V4L2_CID_AUDIO_MUTE (V4L2_CID_BASE+9)
+#define V4L2_CID_AUDIO_LOUDNESS (V4L2_CID_BASE+10)
+#define V4L2_CID_BLACK_LEVEL (V4L2_CID_BASE+11)
+#define V4L2_CID_AUTO_WHITE_BALANCE (V4L2_CID_BASE+12)
+#define V4L2_CID_DO_WHITE_BALANCE (V4L2_CID_BASE+13)
+#define V4L2_CID_RED_BALANCE (V4L2_CID_BASE+14)
+#define V4L2_CID_BLUE_BALANCE (V4L2_CID_BASE+15)
+#define V4L2_CID_GAMMA (V4L2_CID_BASE+16)
+#define V4L2_CID_WHITENESS (V4L2_CID_GAMMA) /* ? Not sure */
+#define V4L2_CID_EXPOSURE (V4L2_CID_BASE+17)
+#define V4L2_CID_AUTOGAIN (V4L2_CID_BASE+18)
+#define V4L2_CID_GAIN (V4L2_CID_BASE+19)
+#define V4L2_CID_HFLIP (V4L2_CID_BASE+20)
+#define V4L2_CID_VFLIP (V4L2_CID_BASE+21)
+#define V4L2_CID_HCENTER (V4L2_CID_BASE+22)
+#define V4L2_CID_VCENTER (V4L2_CID_BASE+23)
+#define V4L2_CID_LASTP1 (V4L2_CID_BASE+24) /* last CID + 1 */
+
+/*
+ * T U N I N G
+ */
+struct v4l2_tuner
+{
+ __u32 index;
+ __u8 name[32];
+ enum v4l2_tuner_type type;
+ __u32 capability;
+ __u32 rangelow;
+ __u32 rangehigh;
+ __u32 rxsubchans;
+ __u32 audmode;
+ __s32 signal;
+ __s32 afc;
+ __u32 reserved[4];
+};
+
+struct v4l2_modulator
+{
+ __u32 index;
+ __u8 name[32];
+ __u32 capability;
+ __u32 rangelow;
+ __u32 rangehigh;
+ __u32 txsubchans;
+ __u32 reserved[4];
+};
+
+/* Flags for the 'capability' field */
+#define V4L2_TUNER_CAP_LOW 0x0001
+#define V4L2_TUNER_CAP_NORM 0x0002
+#define V4L2_TUNER_CAP_STEREO 0x0010
+#define V4L2_TUNER_CAP_LANG2 0x0020
+#define V4L2_TUNER_CAP_SAP 0x0020
+#define V4L2_TUNER_CAP_LANG1 0x0040
+
+/* Flags for the 'rxsubchans' field */
+#define V4L2_TUNER_SUB_MONO 0x0001
+#define V4L2_TUNER_SUB_STEREO 0x0002
+#define V4L2_TUNER_SUB_LANG2 0x0004
+#define V4L2_TUNER_SUB_SAP 0x0004
+#define V4L2_TUNER_SUB_LANG1 0x0008
+
+/* Values for the 'audmode' field */
+#define V4L2_TUNER_MODE_MONO 0x0000
+#define V4L2_TUNER_MODE_STEREO 0x0001
+#define V4L2_TUNER_MODE_LANG2 0x0002
+#define V4L2_TUNER_MODE_SAP 0x0002
+#define V4L2_TUNER_MODE_LANG1 0x0003
+#define V4L2_TUNER_MODE_LANG1_LANG2 0x0004
+
+struct v4l2_frequency
+{
+ __u32 tuner;
+ enum v4l2_tuner_type type;
+ __u32 frequency;
+ __u32 reserved[8];
+};
+
+/*
+ * A U D I O
+ */
+struct v4l2_audio
+{
+ __u32 index;
+ __u8 name[32];
+ __u32 capability;
+ __u32 mode;
+ __u32 reserved[2];
+};
+/* Flags for the 'capability' field */
+#define V4L2_AUDCAP_STEREO 0x00001
+#define V4L2_AUDCAP_AVL 0x00002
+
+/* Flags for the 'mode' field */
+#define V4L2_AUDMODE_AVL 0x00001
+
+struct v4l2_audioout
+{
+ __u32 index;
+ __u8 name[32];
+ __u32 capability;
+ __u32 mode;
+ __u32 reserved[2];
+};
+
+/*
+ * D A T A S E R V I C E S ( V B I )
+ *
+ * Data services API by Michael Schimek
+ */
+
+/* Raw VBI */
+
+struct v4l2_vbi_format
+{
+ __u32 sampling_rate; /* in 1 Hz */
+ __u32 offset;
+ __u32 samples_per_line;
+ __u32 sample_format; /* V4L2_PIX_FMT_* */
+ __s32 start[2];
+ __u32 count[2];
+ __u32 flags; /* V4L2_VBI_* */
+ __u32 reserved[2]; /* must be zero */
+};
+
+/* VBI flags */
+#define V4L2_VBI_UNSYNC (1<< 0)
+#define V4L2_VBI_INTERLACED (1<< 1)
+
+#if 1
+/* Sliced VBI
+ *
+ * This implements is a proposal V4L2 API to allow SLICED VBI
+ * required for some hardware encoders. It should change without
+ * notice in the definitive implementation.
+ */
+
+struct v4l2_sliced_vbi_format
+{
+ __u16 service_set;
+ /* service_lines[0][...] specifies lines 0-23 (1-23 used) of the first field
+ service_lines[1][...] specifies lines 0-23 (1-23 used) of the second field
+ (equals frame lines 313-336 for 625 line video
+ standards, 263-286 for 525 line standards) */
+ __u16 service_lines[2][24];
+ __u32 io_size;
+ __u32 reserved[2]; /* must be zero */
+};
+
+/* Teletext World System Teletext
+ (WST), defined on ITU-R BT.653-2 */
+#define V4L2_SLICED_TELETEXT_B (0x0001)
+/* Video Program System, defined on ETS 300 231*/
+#define V4L2_SLICED_VPS (0x0400)
+/* Closed Caption, defined on EIA-608 */
+#define V4L2_SLICED_CAPTION_525 (0x1000)
+/* Wide Screen System, defined on ITU-R BT1119.1 */
+#define V4L2_SLICED_WSS_625 (0x4000)
+
+#define V4L2_SLICED_VBI_525 (V4L2_SLICED_CAPTION_525)
+#define V4L2_SLICED_VBI_625 (V4L2_SLICED_TELETEXT_B | V4L2_SLICED_VPS | V4L2_SLICED_WSS_625)
+
+
+struct v4l2_sliced_vbi_cap
+{
+ __u16 service_set;
+ /* service_lines[0][...] specifies lines 0-23 (1-23 used) of the first field
+ service_lines[1][...] specifies lines 0-23 (1-23 used) of the second field
+ (equals frame lines 313-336 for 625 line video
+ standards, 263-286 for 525 line standards) */
+ __u16 service_lines[2][24];
+ __u32 reserved[4]; /* must be 0 */
+};
+
+struct v4l2_sliced_vbi_data
+{
+ __u32 id;
+ __u32 field; /* 0: first field, 1: second field */
+ __u32 line; /* 1-23 */
+ __u32 reserved; /* must be 0 */
+ __u8 data[48];
+};
+#endif
+
+/*
+ * A G G R E G A T E S T R U C T U R E S
+ */
+
+/* Stream data format
+ */
+struct v4l2_format
+{
+ enum v4l2_buf_type type;
+ union
+ {
+ struct v4l2_pix_format pix; // V4L2_BUF_TYPE_VIDEO_CAPTURE
+ struct v4l2_window win; // V4L2_BUF_TYPE_VIDEO_OVERLAY
+ struct v4l2_vbi_format vbi; // V4L2_BUF_TYPE_VBI_CAPTURE
+#if 1
+ struct v4l2_sliced_vbi_format sliced; // V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
+#endif
+ __u8 raw_data[200]; // user-defined
+ } fmt;
+};
+
+
+/* Stream type-dependent parameters
+ */
+struct v4l2_streamparm
+{
+ enum v4l2_buf_type type;
+ union
+ {
+ struct v4l2_captureparm capture;
+ struct v4l2_outputparm output;
+ __u8 raw_data[200]; /* user-defined */
+ } parm;
+};
+
+
+
+/*
+ * I O C T L C O D E S F O R V I D E O D E V I C E S
+ *
+ */
+#define VIDIOC_QUERYCAP _IOR ('V', 0, struct v4l2_capability)
+#define VIDIOC_RESERVED _IO ('V', 1)
+#define VIDIOC_ENUM_FMT _IOWR ('V', 2, struct v4l2_fmtdesc)
+#define VIDIOC_G_FMT _IOWR ('V', 4, struct v4l2_format)
+#define VIDIOC_S_FMT _IOWR ('V', 5, struct v4l2_format)
+#define VIDIOC_G_MPEGCOMP _IOR ('V', 6, struct v4l2_mpeg_compression)
+#define VIDIOC_S_MPEGCOMP _IOW ('V', 7, struct v4l2_mpeg_compression)
+#define VIDIOC_REQBUFS _IOWR ('V', 8, struct v4l2_requestbuffers)
+#define VIDIOC_QUERYBUF _IOWR ('V', 9, struct v4l2_buffer)
+#define VIDIOC_G_FBUF _IOR ('V', 10, struct v4l2_framebuffer)
+#define VIDIOC_S_FBUF _IOW ('V', 11, struct v4l2_framebuffer)
+#define VIDIOC_OVERLAY _IOW ('V', 14, int)
+#define VIDIOC_QBUF _IOWR ('V', 15, struct v4l2_buffer)
+#define VIDIOC_DQBUF _IOWR ('V', 17, struct v4l2_buffer)
+#define VIDIOC_STREAMON _IOW ('V', 18, int)
+#define VIDIOC_STREAMOFF _IOW ('V', 19, int)
+#define VIDIOC_G_PARM _IOWR ('V', 21, struct v4l2_streamparm)
+#define VIDIOC_S_PARM _IOWR ('V', 22, struct v4l2_streamparm)
+#define VIDIOC_G_STD _IOR ('V', 23, v4l2_std_id)
+#define VIDIOC_S_STD _IOW ('V', 24, v4l2_std_id)
+#define VIDIOC_ENUMSTD _IOWR ('V', 25, struct v4l2_standard)
+#define VIDIOC_ENUMINPUT _IOWR ('V', 26, struct v4l2_input)
+#define VIDIOC_G_CTRL _IOWR ('V', 27, struct v4l2_control)
+#define VIDIOC_S_CTRL _IOWR ('V', 28, struct v4l2_control)
+#define VIDIOC_G_TUNER _IOWR ('V', 29, struct v4l2_tuner)
+#define VIDIOC_S_TUNER _IOW ('V', 30, struct v4l2_tuner)
+#define VIDIOC_G_AUDIO _IOR ('V', 33, struct v4l2_audio)
+#define VIDIOC_S_AUDIO _IOW ('V', 34, struct v4l2_audio)
+#define VIDIOC_QUERYCTRL _IOWR ('V', 36, struct v4l2_queryctrl)
+#define VIDIOC_QUERYMENU _IOWR ('V', 37, struct v4l2_querymenu)
+#define VIDIOC_G_INPUT _IOR ('V', 38, int)
+#define VIDIOC_S_INPUT _IOWR ('V', 39, int)
+#define VIDIOC_G_OUTPUT _IOR ('V', 46, int)
+#define VIDIOC_S_OUTPUT _IOWR ('V', 47, int)
+#define VIDIOC_ENUMOUTPUT _IOWR ('V', 48, struct v4l2_output)
+#define VIDIOC_G_AUDOUT _IOR ('V', 49, struct v4l2_audioout)
+#define VIDIOC_S_AUDOUT _IOW ('V', 50, struct v4l2_audioout)
+#define VIDIOC_G_MODULATOR _IOWR ('V', 54, struct v4l2_modulator)
+#define VIDIOC_S_MODULATOR _IOW ('V', 55, struct v4l2_modulator)
+#define VIDIOC_G_FREQUENCY _IOWR ('V', 56, struct v4l2_frequency)
+#define VIDIOC_S_FREQUENCY _IOW ('V', 57, struct v4l2_frequency)
+#define VIDIOC_CROPCAP _IOWR ('V', 58, struct v4l2_cropcap)
+#define VIDIOC_G_CROP _IOWR ('V', 59, struct v4l2_crop)
+#define VIDIOC_S_CROP _IOW ('V', 60, struct v4l2_crop)
+#define VIDIOC_G_JPEGCOMP _IOR ('V', 61, struct v4l2_jpegcompression)
+#define VIDIOC_S_JPEGCOMP _IOW ('V', 62, struct v4l2_jpegcompression)
+#define VIDIOC_QUERYSTD _IOR ('V', 63, v4l2_std_id)
+#define VIDIOC_TRY_FMT _IOWR ('V', 64, struct v4l2_format)
+#define VIDIOC_ENUMAUDIO _IOWR ('V', 65, struct v4l2_audio)
+#define VIDIOC_ENUMAUDOUT _IOWR ('V', 66, struct v4l2_audioout)
+#define VIDIOC_G_PRIORITY _IOR ('V', 67, enum v4l2_priority)
+#define VIDIOC_S_PRIORITY _IOW ('V', 68, enum v4l2_priority)
+#if 1
+#define VIDIOC_G_SLICED_VBI_CAP _IOR ('V', 69, struct v4l2_sliced_vbi_cap)
+#endif
+#define VIDIOC_LOG_STATUS _IO ('V', 70)
+
+/* for compatibility, will go away some day */
+#define VIDIOC_OVERLAY_OLD _IOWR ('V', 14, int)
+#define VIDIOC_S_PARM_OLD _IOW ('V', 22, struct v4l2_streamparm)
+#define VIDIOC_S_CTRL_OLD _IOW ('V', 28, struct v4l2_control)
+#define VIDIOC_G_AUDIO_OLD _IOWR ('V', 33, struct v4l2_audio)
+#define VIDIOC_G_AUDOUT_OLD _IOWR ('V', 49, struct v4l2_audioout)
+#define VIDIOC_CROPCAP_OLD _IOR ('V', 58, struct v4l2_cropcap)
+
+#define BASE_VIDIOC_PRIVATE 192 /* 192-255 are private */
+
+
+#ifdef __KERNEL__
+/*
+ *
+ * V 4 L 2 D R I V E R H E L P E R A P I
+ *
+ * Some commonly needed functions for drivers (v4l2-common.o module)
+ */
+#include <linux/fs.h>
+
+/* Video standard functions */
+extern unsigned int v4l2_video_std_fps(struct v4l2_standard *vs);
+extern int v4l2_video_std_construct(struct v4l2_standard *vs,
+ int id, char *name);
+
+/* prority handling */
+struct v4l2_prio_state {
+ atomic_t prios[4];
+};
+int v4l2_prio_init(struct v4l2_prio_state *global);
+int v4l2_prio_change(struct v4l2_prio_state *global, enum v4l2_priority *local,
+ enum v4l2_priority new);
+int v4l2_prio_open(struct v4l2_prio_state *global, enum v4l2_priority *local);
+int v4l2_prio_close(struct v4l2_prio_state *global, enum v4l2_priority *local);
+enum v4l2_priority v4l2_prio_max(struct v4l2_prio_state *global);
+int v4l2_prio_check(struct v4l2_prio_state *global, enum v4l2_priority *local);
+
+/* names for fancy debug output */
+extern char *v4l2_field_names[];
+extern char *v4l2_type_names[];
+
+/* Compatibility layer interface -- v4l1-compat module */
+typedef int (*v4l2_kioctl)(struct inode *inode, struct file *file,
+ unsigned int cmd, void *arg);
+
+#ifdef CONFIG_VIDEO_V4L1_COMPAT
+int v4l_compat_translate_ioctl(struct inode *inode, struct file *file,
+ int cmd, void *arg, v4l2_kioctl driver_ioctl);
+#else
+#define v4l_compat_translate_ioctl(inode,file,cmd,arg,ioctl) -EINVAL
+#endif
+
+/* 32 Bits compatibility layer for 64 bits processors */
+extern long v4l_compat_ioctl32(struct file *file, unsigned int cmd,
+ unsigned long arg);
+
+
+#endif /* __KERNEL__ */
+#endif /* __LINUX_VIDEODEV2_H */
+
+/*
+ * Local variables:
+ * c-basic-offset: 8
+ * End:
+ */
diff --git a/sys/compat/linux/linux_videodev2_compat.h b/sys/compat/linux/linux_videodev2_compat.h
new file mode 100644
index 0000000..0d9a3a3
--- /dev/null
+++ b/sys/compat/linux/linux_videodev2_compat.h
@@ -0,0 +1,137 @@
+/*
+ * $FreeBSD$
+ */
+
+/*
+ * This file defines compatibility versions of several video structures
+ * defined in the Linux videodev2.h header (linux_videodev2.h). The
+ * structures defined in this file are the ones that have been determined
+ * to have 32- to 64-bit size dependencies.
+ */
+
+#ifndef _LINUX_VIDEODEV2_COMPAT_H_
+#define _LINUX_VIDEODEV2_COMPAT_H_
+
+struct l_v4l2_buffer {
+ uint32_t index;
+ enum v4l2_buf_type type;
+ uint32_t bytesused;
+ uint32_t flags;
+ enum v4l2_field field;
+ l_timeval timestamp;
+ struct v4l2_timecode timecode;
+ uint32_t sequence;
+
+ /* memory location */
+ enum v4l2_memory memory;
+ union {
+ uint32_t offset;
+ l_ulong userptr;
+ } m;
+ uint32_t length;
+ uint32_t input;
+ uint32_t reserved;
+};
+
+struct l_v4l2_framebuffer {
+ uint32_t capability;
+ uint32_t flags;
+/* FIXME: in theory we should pass something like PCI device + memory
+ * region + offset instead of some physical address */
+ l_uintptr_t base;
+ struct v4l2_pix_format fmt;
+};
+
+struct l_v4l2_clip {
+ struct v4l2_rect c;
+ l_uintptr_t next;
+};
+
+struct l_v4l2_window {
+ struct v4l2_rect w;
+ enum v4l2_field field;
+ uint32_t chromakey;
+ l_uintptr_t clips;
+ uint32_t clipcount;
+ l_uintptr_t bitmap;
+ uint8_t global_alpha;
+};
+
+struct l_v4l2_standard {
+ uint32_t index;
+ v4l2_std_id id;
+ uint8_t name[24];
+ struct v4l2_fract frameperiod; /* Frames, not fields */
+ uint32_t framelines;
+ uint32_t reserved[4];
+}
+#ifdef COMPAT_LINUX32 /* 32bit linuxolator */
+__attribute__ ((packed))
+#endif
+;
+
+struct l_v4l2_ext_control {
+ uint32_t id;
+ uint32_t size;
+ uint32_t reserved2[1];
+ union {
+ int32_t value;
+ int64_t value64;
+ l_uintptr_t string;
+ } u;
+} __attribute__ ((packed));
+
+struct l_v4l2_ext_controls {
+ uint32_t ctrl_class;
+ uint32_t count;
+ uint32_t error_idx;
+ uint32_t reserved[2];
+ l_uintptr_t controls;
+};
+
+struct l_v4l2_format {
+ enum v4l2_buf_type type;
+ union {
+ struct v4l2_pix_format pix; /* V4L2_BUF_TYPE_VIDEO_CAPTURE */
+ struct l_v4l2_window win; /* V4L2_BUF_TYPE_VIDEO_OVERLAY */
+ struct v4l2_vbi_format vbi; /* V4L2_BUF_TYPE_VBI_CAPTURE */
+ struct v4l2_sliced_vbi_format sliced; /* V4L2_BUF_TYPE_SLICED_VBI_CAPTURE */
+ uint8_t raw_data[200]; /* user-defined */
+ } fmt;
+}
+#ifdef COMPAT_LINUX32 /* 32bit linuxolator */
+__attribute__ ((packed))
+#endif
+;
+
+#ifdef VIDIOC_DQEVENT
+struct l_v4l2_event {
+ uint32_t type;
+ union {
+ struct v4l2_event_vsync vsync;
+ uint8_t data[64];
+ } u;
+ uint32_t pending;
+ uint32_t sequence;
+ struct l_timespec timestamp;
+ uint32_t reserved[9];
+};
+#endif
+
+struct l_v4l2_input {
+ uint32_t index; /* Which input */
+ uint8_t name[32]; /* Label */
+ uint32_t type; /* Type of input */
+ uint32_t audioset; /* Associated audios (bitfield) */
+ uint32_t tuner; /* Associated tuner */
+ v4l2_std_id std;
+ uint32_t status;
+ uint32_t capabilities;
+ uint32_t reserved[3];
+}
+#ifdef COMPAT_LINUX32 /* 32bit linuxolator */
+__attribute__ ((packed))
+#endif
+;
+
+#endif /* _LINUX_VIDEODEV2_COMPAT_H_ */
diff --git a/sys/dev/ae/if_ae.c b/sys/dev/ae/if_ae.c
index eb9260d..96329fd 100644
--- a/sys/dev/ae/if_ae.c
+++ b/sys/dev/ae/if_ae.c
@@ -903,10 +903,8 @@ ae_mediachange(struct ifnet *ifp)
KASSERT(sc != NULL, ("[ae, %d]: sc is NULL", __LINE__));
AE_LOCK(sc);
mii = device_get_softc(sc->miibus);
- if (mii->mii_instance != 0) {
- LIST_FOREACH(mii_sc, &mii->mii_phys, mii_list)
- mii_phy_reset(mii_sc);
- }
+ LIST_FOREACH(mii_sc, &mii->mii_phys, mii_list)
+ PHY_RESET(mii_sc);
error = mii_mediachg(mii);
AE_UNLOCK(sc);
diff --git a/sys/dev/age/if_age.c b/sys/dev/age/if_age.c
index 0735ca9..a1ab8c7 100644
--- a/sys/dev/age/if_age.c
+++ b/sys/dev/age/if_age.c
@@ -301,10 +301,8 @@ age_mediachange(struct ifnet *ifp)
sc = ifp->if_softc;
AGE_LOCK(sc);
mii = device_get_softc(sc->age_miibus);
- if (mii->mii_instance != 0) {
- LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
- mii_phy_reset(miisc);
- }
+ LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
+ PHY_RESET(miisc);
error = mii_mediachg(mii);
AGE_UNLOCK(sc);
diff --git a/sys/dev/alc/if_alc.c b/sys/dev/alc/if_alc.c
index 7bad91b..ff0424e 100644
--- a/sys/dev/alc/if_alc.c
+++ b/sys/dev/alc/if_alc.c
@@ -365,10 +365,8 @@ alc_mediachange(struct ifnet *ifp)
sc = ifp->if_softc;
ALC_LOCK(sc);
mii = device_get_softc(sc->alc_miibus);
- if (mii->mii_instance != 0) {
- LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
- mii_phy_reset(miisc);
- }
+ LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
+ PHY_RESET(miisc);
error = mii_mediachg(mii);
ALC_UNLOCK(sc);
diff --git a/sys/dev/ale/if_ale.c b/sys/dev/ale/if_ale.c
index e4272df..bdee4d8 100644
--- a/sys/dev/ale/if_ale.c
+++ b/sys/dev/ale/if_ale.c
@@ -286,10 +286,8 @@ ale_mediachange(struct ifnet *ifp)
sc = ifp->if_softc;
ALE_LOCK(sc);
mii = device_get_softc(sc->ale_miibus);
- if (mii->mii_instance != 0) {
- LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
- mii_phy_reset(miisc);
- }
+ LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
+ PHY_RESET(miisc);
error = mii_mediachg(mii);
ALE_UNLOCK(sc);
diff --git a/sys/dev/ath/ath_hal/ar5416/ar5416_reset.c b/sys/dev/ath/ath_hal/ar5416/ar5416_reset.c
index 3700448..95bd966 100644
--- a/sys/dev/ath/ath_hal/ar5416/ar5416_reset.c
+++ b/sys/dev/ath/ath_hal/ar5416/ar5416_reset.c
@@ -168,13 +168,6 @@ ar5416Reset(struct ath_hal *ah, HAL_OPMODE opmode,
if (AR_SREV_MERLIN_10_OR_LATER(ah))
OS_REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, AR_GPIO_JTAG_DISABLE);
- if (AR_SREV_KITE(ah)) {
- uint32_t val;
- val = OS_REG_READ(ah, AR_PHY_HEAVY_CLIP_FACTOR_RIFS);
- val &= ~AR_PHY_RIFS_INIT_DELAY;
- OS_REG_WRITE(ah, AR_PHY_HEAVY_CLIP_FACTOR_RIFS, val);
- }
-
AH5416(ah)->ah_writeIni(ah, chan);
/* Override ini values (that can be overriden in this fashion) */
diff --git a/sys/dev/bce/if_bce.c b/sys/dev/bce/if_bce.c
index 7d0e47e..c048f3f 100644
--- a/sys/dev/bce/if_bce.c
+++ b/sys/dev/bce/if_bce.c
@@ -6141,6 +6141,7 @@ bce_ifmedia_upd_locked(struct ifnet *ifp)
{
struct bce_softc *sc = ifp->if_softc;
struct mii_data *mii;
+ struct mii_softc *miisc;
int error;
DBENTER(BCE_VERBOSE_PHY);
@@ -6153,12 +6154,8 @@ bce_ifmedia_upd_locked(struct ifnet *ifp)
/* Make sure the MII bus has been enumerated. */
if (mii) {
sc->bce_link_up = FALSE;
- if (mii->mii_instance) {
- struct mii_softc *miisc;
-
- LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
- mii_phy_reset(miisc);
- }
+ LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
+ PHY_RESET(miisc);
error = mii_mediachg(mii);
}
diff --git a/sys/dev/bfe/if_bfe.c b/sys/dev/bfe/if_bfe.c
index f384f6d..7f970f4 100644
--- a/sys/dev/bfe/if_bfe.c
+++ b/sys/dev/bfe/if_bfe.c
@@ -1736,18 +1736,15 @@ bfe_ifmedia_upd(struct ifnet *ifp)
{
struct bfe_softc *sc;
struct mii_data *mii;
+ struct mii_softc *miisc;
int error;
sc = ifp->if_softc;
BFE_LOCK(sc);
mii = device_get_softc(sc->bfe_miibus);
- if (mii->mii_instance) {
- struct mii_softc *miisc;
- for (miisc = LIST_FIRST(&mii->mii_phys); miisc != NULL;
- miisc = LIST_NEXT(miisc, mii_list))
- mii_phy_reset(miisc);
- }
+ LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
+ PHY_RESET(miisc);
error = mii_mediachg(mii);
BFE_UNLOCK(sc);
diff --git a/sys/dev/bge/if_bge.c b/sys/dev/bge/if_bge.c
index 01bf938..76496aa 100644
--- a/sys/dev/bge/if_bge.c
+++ b/sys/dev/bge/if_bge.c
@@ -4854,9 +4854,8 @@ bge_ifmedia_upd_locked(struct ifnet *ifp)
sc->bge_link_evt++;
mii = device_get_softc(sc->bge_miibus);
- if (mii->mii_instance)
- LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
- mii_phy_reset(miisc);
+ LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
+ PHY_RESET(miisc);
mii_mediachg(mii);
/*
diff --git a/sys/dev/dc/dcphy.c b/sys/dev/dc/dcphy.c
index 99aca0f..f4fc512 100644
--- a/sys/dev/dc/dcphy.c
+++ b/sys/dev/dc/dcphy.c
@@ -114,6 +114,12 @@ static void dcphy_status(struct mii_softc *);
static void dcphy_reset(struct mii_softc *);
static int dcphy_auto(struct mii_softc *);
+static const struct mii_phy_funcs dcphy_funcs = {
+ dcphy_service,
+ dcphy_status,
+ dcphy_reset
+};
+
static int
dcphy_probe(device_t dev)
{
@@ -138,30 +144,16 @@ static int
dcphy_attach(device_t dev)
{
struct mii_softc *sc;
- struct mii_attach_args *ma;
- struct mii_data *mii;
struct dc_softc *dc_sc;
device_t brdev;
sc = device_get_softc(dev);
- ma = device_get_ivars(dev);
- sc->mii_dev = device_get_parent(dev);
- mii = ma->mii_data;
- LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list);
- sc->mii_flags = miibus_get_flags(dev);
- sc->mii_inst = mii->mii_instance++;
- sc->mii_phy = ma->mii_phyno;
- sc->mii_service = dcphy_service;
- sc->mii_pdata = mii;
+ mii_phy_dev_attach(dev, MIIF_NOISOLATE | MIIF_NOMANPAUSE,
+ &dcphy_funcs, 0);
- /*
- * Apparently, we can neither isolate nor do loopback.
- */
- sc->mii_flags |= MIIF_NOISOLATE | MIIF_NOLOOP;
-
- /*dcphy_reset(sc);*/
- dc_sc = mii->mii_ifp->if_softc;
+ /*PHY_RESET(sc);*/
+ dc_sc = sc->mii_pdata->mii_ifp->if_softc;
CSR_WRITE_4(dc_sc, DC_10BTSTAT, 0);
CSR_WRITE_4(dc_sc, DC_10BTCTRL, 0);
@@ -182,7 +174,7 @@ dcphy_attach(device_t dev)
break;
}
- sc->mii_capabilities &= ma->mii_capmask;
+ sc->mii_capabilities &= sc->mii_capmask;
device_printf(dev, " ");
mii_phy_add_media(sc);
printf("\n");
@@ -219,11 +211,11 @@ dcphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
switch (IFM_SUBTYPE(ife->ifm_media)) {
case IFM_AUTO:
- /*dcphy_reset(sc);*/
- (void) dcphy_auto(sc);
+ /*PHY_RESET(sc);*/
+ (void)dcphy_auto(sc);
break;
case IFM_100_TX:
- dcphy_reset(sc);
+ PHY_RESET(sc);
DC_CLRBIT(dc_sc, DC_10BTCTRL, DC_TCTL_AUTONEGENBL);
mode |= DC_NETCFG_PORTSEL | DC_NETCFG_PCS |
DC_NETCFG_SCRAMBLER;
@@ -292,7 +284,7 @@ dcphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
}
/* Update the media status. */
- dcphy_status(sc);
+ PHY_STATUS(sc);
/* Callback if something changed. */
mii_phy_update(sc, cmd);
diff --git a/sys/dev/dc/pnphy.c b/sys/dev/dc/pnphy.c
index 760b782..6468fbf 100644
--- a/sys/dev/dc/pnphy.c
+++ b/sys/dev/dc/pnphy.c
@@ -90,6 +90,13 @@ DRIVER_MODULE(pnphy, miibus, pnphy_driver, pnphy_devclass, 0, 0);
static int pnphy_service(struct mii_softc *, struct mii_data *, int);
static void pnphy_status(struct mii_softc *);
+static void pnphy_reset(struct mii_softc *);
+
+static const struct mii_phy_funcs pnphy_funcs = {
+ pnphy_service,
+ pnphy_status,
+ pnphy_reset
+};
static int
pnphy_probe(device_t dev)
@@ -115,29 +122,15 @@ static int
pnphy_attach(device_t dev)
{
struct mii_softc *sc;
- struct mii_attach_args *ma;
- struct mii_data *mii;
sc = device_get_softc(dev);
- ma = device_get_ivars(dev);
- sc->mii_dev = device_get_parent(dev);
- mii = ma->mii_data;
- LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list);
-
- sc->mii_flags = miibus_get_flags(dev);
- sc->mii_inst = mii->mii_instance++;
- sc->mii_phy = ma->mii_phyno;
- sc->mii_service = pnphy_service;
- sc->mii_pdata = mii;
- /*
- * Apparently, we can neither isolate nor do loopback.
- */
- sc->mii_flags |= MIIF_NOISOLATE | MIIF_NOLOOP;
+ mii_phy_dev_attach(dev, MIIF_NOISOLATE | MIIF_NOMANPAUSE,
+ &pnphy_funcs, 0);
sc->mii_capabilities =
BMSR_100TXFDX | BMSR_100TXHDX | BMSR_10TFDX | BMSR_10THDX;
- sc->mii_capabilities &= ma->mii_capmask;
+ sc->mii_capabilities &= sc->mii_capmask;
device_printf(dev, " ");
mii_phy_add_media(sc);
printf("\n");
@@ -194,7 +187,7 @@ pnphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
}
/* Update the media status. */
- pnphy_status(sc);
+ PHY_STATUS(sc);
/* Callback if something changed. */
mii_phy_update(sc, cmd);
@@ -226,3 +219,9 @@ pnphy_status(struct mii_softc *sc)
else
mii->mii_media_active |= IFM_HDX;
}
+
+static void
+pnphy_reset(struct mii_softc *sc __unused)
+{
+
+}
diff --git a/sys/dev/ed/if_ed_pccard.c b/sys/dev/ed/if_ed_pccard.c
index ed8704b..780f5f3 100644
--- a/sys/dev/ed/if_ed_pccard.c
+++ b/sys/dev/ed/if_ed_pccard.c
@@ -401,17 +401,9 @@ ed_pccard_kick_phy(struct ed_softc *sc)
struct mii_softc *miisc;
struct mii_data *mii;
- /*
- * Many of the PHYs that wind up on PC Cards are weird in
- * this way. Generally, we don't need to worry so much about
- * the Isolation protocol since there's only one PHY in
- * these designs, so this workaround is reasonable.
- */
mii = device_get_softc(sc->miibus);
- LIST_FOREACH(miisc, &mii->mii_phys, mii_list) {
- miisc->mii_flags |= MIIF_FORCEANEG;
- mii_phy_reset(miisc);
- }
+ LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
+ PHY_RESET(miisc);
return (mii_mediachg(mii));
}
@@ -582,13 +574,13 @@ ed_pccard_attach(device_t dev)
ed_pccard_dl100xx_mii_reset(sc);
(void)mii_attach(dev, &sc->miibus, sc->ifp, ed_ifmedia_upd,
ed_ifmedia_sts, BMSR_DEFCAPMASK, MII_PHY_ANY,
- MII_OFFSET_ANY, 0);
+ MII_OFFSET_ANY, MIIF_FORCEANEG);
} else if (sc->chip_type == ED_CHIP_TYPE_AX88190 ||
sc->chip_type == ED_CHIP_TYPE_AX88790 ||
sc->chip_type == ED_CHIP_TYPE_TC5299J) {
error = mii_attach(dev, &sc->miibus, sc->ifp, ed_ifmedia_upd,
ed_ifmedia_sts, BMSR_DEFCAPMASK, MII_PHY_ANY,
- MII_OFFSET_ANY, 0);
+ MII_OFFSET_ANY, MIIF_FORCEANEG);
if (error != 0) {
device_printf(dev, "attaching PHYs failed\n");
goto bad;
diff --git a/sys/dev/et/if_et.c b/sys/dev/et/if_et.c
index d337efd..82c6217 100644
--- a/sys/dev/et/if_et.c
+++ b/sys/dev/et/if_et.c
@@ -515,13 +515,10 @@ et_ifmedia_upd_locked(struct ifnet *ifp)
{
struct et_softc *sc = ifp->if_softc;
struct mii_data *mii = device_get_softc(sc->sc_miibus);
+ struct mii_softc *miisc;
- if (mii->mii_instance != 0) {
- struct mii_softc *miisc;
-
- LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
- mii_phy_reset(miisc);
- }
+ LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
+ PHY_RESET(miisc);
mii_mediachg(mii);
return (0);
diff --git a/sys/dev/fxp/if_fxp.c b/sys/dev/fxp/if_fxp.c
index 70d863c..e02d580 100644
--- a/sys/dev/fxp/if_fxp.c
+++ b/sys/dev/fxp/if_fxp.c
@@ -2555,14 +2555,12 @@ fxp_ifmedia_upd(struct ifnet *ifp)
{
struct fxp_softc *sc = ifp->if_softc;
struct mii_data *mii;
+ struct mii_softc *miisc;
mii = device_get_softc(sc->miibus);
FXP_LOCK(sc);
- if (mii->mii_instance) {
- struct mii_softc *miisc;
- LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
- mii_phy_reset(miisc);
- }
+ LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
+ PHY_RESET(miisc);
mii_mediachg(mii);
FXP_UNLOCK(sc);
return (0);
diff --git a/sys/dev/hme/if_hme.c b/sys/dev/hme/if_hme.c
index 6f76c90..63d27d1 100644
--- a/sys/dev/hme/if_hme.c
+++ b/sys/dev/hme/if_hme.c
@@ -1566,7 +1566,7 @@ hme_mediachange_locked(struct hme_softc *sc)
*/
if (sc->sc_phys[0] != -1 && sc->sc_phys[1] != -1)
LIST_FOREACH(child, &sc->sc_mii->mii_phys, mii_list)
- mii_phy_reset(child);
+ PHY_RESET(child);
return (mii_mediachg(sc->sc_mii));
}
diff --git a/sys/dev/jme/if_jme.c b/sys/dev/jme/if_jme.c
index 6fc328e..eda1807 100644
--- a/sys/dev/jme/if_jme.c
+++ b/sys/dev/jme/if_jme.c
@@ -318,10 +318,8 @@ jme_mediachange(struct ifnet *ifp)
sc = ifp->if_softc;
JME_LOCK(sc);
mii = device_get_softc(sc->jme_miibus);
- if (mii->mii_instance != 0) {
- LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
- mii_phy_reset(miisc);
- }
+ LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
+ PHY_RESET(miisc);
error = mii_mediachg(mii);
JME_UNLOCK(sc);
diff --git a/sys/dev/lge/if_lge.c b/sys/dev/lge/if_lge.c
index ab488df..b57d347 100644
--- a/sys/dev/lge/if_lge.c
+++ b/sys/dev/lge/if_lge.c
@@ -1402,18 +1402,15 @@ lge_ifmedia_upd_locked(ifp)
{
struct lge_softc *sc;
struct mii_data *mii;
+ struct mii_softc *miisc;
sc = ifp->if_softc;
LGE_LOCK_ASSERT(sc);
mii = device_get_softc(sc->lge_miibus);
sc->lge_link = 0;
- if (mii->mii_instance) {
- struct mii_softc *miisc;
- for (miisc = LIST_FIRST(&mii->mii_phys); miisc != NULL;
- miisc = LIST_NEXT(miisc, mii_list))
- mii_phy_reset(miisc);
- }
+ LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
+ PHY_RESET(miisc);
mii_mediachg(mii);
}
diff --git a/sys/dev/mii/acphy.c b/sys/dev/mii/acphy.c
index 7013dbf..58e546e 100644
--- a/sys/dev/mii/acphy.c
+++ b/sys/dev/mii/acphy.c
@@ -105,13 +105,19 @@ static void acphy_reset(struct mii_softc *);
static void acphy_status(struct mii_softc *);
static const struct mii_phydesc acphys[] = {
- MII_PHY_DESC(xxALTIMA, AC101),
- MII_PHY_DESC(xxALTIMA, AC101L),
+ MII_PHY_DESC(ALTIMA, AC101),
+ MII_PHY_DESC(ALTIMA, AC101L),
/* XXX This is reported to work, but it's not from any data sheet. */
- MII_PHY_DESC(xxALTIMA, ACXXX),
+ MII_PHY_DESC(ALTIMA, ACXXX),
MII_PHY_END
};
+static const struct mii_phy_funcs acphy_funcs = {
+ acphy_service,
+ acphy_status,
+ acphy_reset
+};
+
static int
acphy_probe(device_t dev)
{
@@ -123,27 +129,17 @@ static int
acphy_attach(device_t dev)
{
struct mii_softc *sc;
- struct mii_attach_args *ma;
- struct mii_data *mii;
sc = device_get_softc(dev);
- ma = device_get_ivars(dev);
- sc->mii_dev = device_get_parent(dev);
- mii = ma->mii_data;
- LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list);
- sc->mii_flags = miibus_get_flags(dev);
- sc->mii_inst = mii->mii_instance++;
- sc->mii_phy = ma->mii_phyno;
- sc->mii_service = acphy_service;
- sc->mii_pdata = mii;
+ mii_phy_dev_attach(dev, MIIF_NOMANPAUSE, &acphy_funcs, 0);
- acphy_reset(sc);
+ PHY_RESET(sc);
- sc->mii_capabilities = PHY_READ(sc, MII_BMSR) & ma->mii_capmask;
+ sc->mii_capabilities = PHY_READ(sc, MII_BMSR) & sc->mii_capmask;
device_printf(dev, " ");
-#define ADD(m, c) ifmedia_add(&mii->mii_media, (m), (c), NULL)
+#define ADD(m, c) ifmedia_add(&sc->mii_pdata->mii_media, (m), (c), NULL)
if ((PHY_READ(sc, MII_ACPHY_MCTL) & AC_MCTL_FX_SEL) != 0) {
sc->mii_flags |= MIIF_HAVEFIBER;
ADD(IFM_MAKEWORD(IFM_ETHER, IFM_100_FX, 0, sc->mii_inst),
@@ -200,7 +196,7 @@ acphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
}
/* Update the media status. */
- acphy_status(sc);
+ PHY_STATUS(sc);
/* Callback if something changed. */
mii_phy_update(sc, cmd);
@@ -245,7 +241,8 @@ acphy_status(struct mii_softc *sc)
mii->mii_media_active |= IFM_10_T;
if (diag & AC_DIAG_DUPLEX)
- mii->mii_media_active |= IFM_FDX;
+ mii->mii_media_active |=
+ IFM_FDX | mii_phy_flowstatus(sc);
else
mii->mii_media_active |= IFM_HDX;
} else
diff --git a/sys/dev/mii/amphy.c b/sys/dev/mii/amphy.c
index 010fe90..c5f5f5c 100644
--- a/sys/dev/mii/amphy.c
+++ b/sys/dev/mii/amphy.c
@@ -83,12 +83,18 @@ static int amphy_service(struct mii_softc *, struct mii_data *, int);
static void amphy_status(struct mii_softc *);
static const struct mii_phydesc amphys[] = {
- MII_PHY_DESC(DAVICOM, DM9102),
- MII_PHY_DESC(xxAMD, 79C873),
+ MII_PHY_DESC(xxDAVICOM, DM9102),
MII_PHY_DESC(xxDAVICOM, DM9101),
+ MII_PHY_DESC(yyDAVICOM, DM9101),
MII_PHY_END
};
+static const struct mii_phy_funcs amphy_funcs = {
+ amphy_service,
+ amphy_status,
+ mii_phy_reset
+};
+
static int
amphy_probe(device_t dev)
{
@@ -99,37 +105,8 @@ amphy_probe(device_t dev)
static int
amphy_attach(device_t dev)
{
- struct mii_softc *sc;
- struct mii_attach_args *ma;
- struct mii_data *mii;
-
- sc = device_get_softc(dev);
- ma = device_get_ivars(dev);
- sc->mii_dev = device_get_parent(dev);
- mii = ma->mii_data;
- LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list);
-
- sc->mii_flags = miibus_get_flags(dev);
- sc->mii_inst = mii->mii_instance++;
- sc->mii_phy = ma->mii_phyno;
- sc->mii_service = amphy_service;
- sc->mii_pdata = mii;
-
-#define ADD(m, c) ifmedia_add(&mii->mii_media, (m), (c), NULL)
-
-#if 0
- ADD(IFM_MAKEWORD(IFM_ETHER, IFM_100_TX, IFM_LOOP, sc->mii_inst),
- MII_MEDIA_100_TX);
-#endif
-
- mii_phy_reset(sc);
-
- sc->mii_capabilities = PHY_READ(sc, MII_BMSR) & ma->mii_capmask;
- device_printf(dev, " ");
- mii_phy_add_media(sc);
- printf("\n");
-#undef ADD
- MIIBUS_MEDIAINIT(sc->mii_dev);
+
+ mii_phy_dev_attach(dev, MIIF_NOMANPAUSE, &amphy_funcs, 1);
return (0);
}
@@ -158,7 +135,7 @@ amphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
}
/* Update the media status. */
- amphy_status(sc);
+ PHY_STATUS(sc);
/* Callback if something changed. */
mii_phy_update(sc, cmd);
@@ -231,6 +208,8 @@ amphy_status(struct mii_softc *sc)
mii->mii_media_active |= IFM_10_T|IFM_HDX;
else if (par & DSCSR_10HDX)
mii->mii_media_active |= IFM_10_T|IFM_HDX;
+ if ((mii->mii_media_active & IFM_FDX) != 0)
+ mii->mii_media_active |= mii_phy_flowstatus(sc);
} else
mii->mii_media_active = ife->ifm_media;
}
diff --git a/sys/dev/mii/atphy.c b/sys/dev/mii/atphy.c
index 6e261a5..0d80ba1 100644
--- a/sys/dev/mii/atphy.c
+++ b/sys/dev/mii/atphy.c
@@ -53,13 +53,6 @@ __FBSDID("$FreeBSD$");
static int atphy_probe(device_t);
static int atphy_attach(device_t);
-struct atphy_softc {
- struct mii_softc mii_sc;
- int mii_oui;
- int mii_model;
- int mii_rev;
-};
-
static device_method_t atphy_methods[] = {
/* Device interface. */
DEVMETHOD(device_probe, atphy_probe),
@@ -73,7 +66,7 @@ static devclass_t atphy_devclass;
static driver_t atphy_driver = {
"atphy",
atphy_methods,
- sizeof(struct atphy_softc)
+ sizeof(struct mii_softc)
};
DRIVER_MODULE(atphy, miibus, atphy_driver, atphy_devclass, 0, 0);
@@ -85,12 +78,18 @@ static uint16_t atphy_anar(struct ifmedia_entry *);
static int atphy_setmedia(struct mii_softc *, int);
static const struct mii_phydesc atphys[] = {
- MII_PHY_DESC(ATHEROS, F1),
- MII_PHY_DESC(ATHEROS, F1_7),
- MII_PHY_DESC(ATHEROS, F2),
+ MII_PHY_DESC(xxATHEROS, F1),
+ MII_PHY_DESC(xxATHEROS, F1_7),
+ MII_PHY_DESC(xxATHEROS, F2),
MII_PHY_END
};
+static const struct mii_phy_funcs atphy_funcs = {
+ atphy_service,
+ atphy_status,
+ atphy_reset
+};
+
static int
atphy_probe(device_t dev)
{
@@ -101,41 +100,8 @@ atphy_probe(device_t dev)
static int
atphy_attach(device_t dev)
{
- struct atphy_softc *asc;
- struct mii_softc *sc;
- struct mii_attach_args *ma;
- struct mii_data *mii;
-
- asc = device_get_softc(dev);
- sc = &asc->mii_sc;
- ma = device_get_ivars(dev);
- sc->mii_dev = device_get_parent(dev);
- mii = ma->mii_data;
- LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list);
-
- sc->mii_flags = miibus_get_flags(dev);
- sc->mii_inst = mii->mii_instance++;
- sc->mii_phy = ma->mii_phyno;
- sc->mii_service = atphy_service;
- sc->mii_pdata = mii;
-
- asc->mii_oui = MII_OUI(ma->mii_id1, ma->mii_id2);
- asc->mii_model = MII_MODEL(ma->mii_id2);
- asc->mii_rev = MII_REV(ma->mii_id2);
- if (bootverbose)
- device_printf(dev, "OUI 0x%06x, model 0x%04x, rev. %d\n",
- asc->mii_oui, asc->mii_model, asc->mii_rev);
-
- atphy_reset(sc);
-
- sc->mii_capabilities = PHY_READ(sc, MII_BMSR) & ma->mii_capmask;
- if (sc->mii_capabilities & BMSR_EXTSTAT)
- sc->mii_extcapabilities = PHY_READ(sc, MII_EXTSR);
- device_printf(dev, " ");
- mii_phy_add_media(sc);
- printf("\n");
-
- MIIBUS_MEDIAINIT(sc->mii_dev);
+
+ mii_phy_dev_attach(dev, MIIF_NOMANPAUSE, &atphy_funcs, 1);
return (0);
}
@@ -244,7 +210,7 @@ done:
}
/* Update the media status. */
- atphy_status(sc);
+ PHY_STATUS(sc);
/* Callback if something changed. */
mii_phy_update(sc, cmd);
@@ -318,12 +284,9 @@ static void
atphy_reset(struct mii_softc *sc)
{
struct ifmedia_entry *ife = sc->mii_pdata->mii_media.ifm_cur;
- struct atphy_softc *asc;
uint32_t reg;
int i;
- asc = (struct atphy_softc *)sc;
-
/* Take PHY out of power down mode. */
PHY_WRITE(sc, 29, 0x29);
PHY_WRITE(sc, 30, 0);
diff --git a/sys/dev/mii/axphy.c b/sys/dev/mii/axphy.c
index 3349d3f..7e83f4b 100644
--- a/sys/dev/mii/axphy.c
+++ b/sys/dev/mii/axphy.c
@@ -73,10 +73,16 @@ static int axphy_service(struct mii_softc *, struct mii_data *, int);
static void axphy_status(struct mii_softc *);
static const struct mii_phydesc axphys[] = {
- MII_PHY_DESC(ASIX, AX88X9X),
+ MII_PHY_DESC(xxASIX, AX88X9X),
MII_PHY_END
};
+static const struct mii_phy_funcs axphy_funcs = {
+ axphy_service,
+ axphy_status,
+ mii_phy_reset
+};
+
static int
axphy_probe(device_t dev)
{
@@ -88,31 +94,11 @@ static int
axphy_attach(device_t dev)
{
struct mii_softc *sc;
- struct mii_attach_args *ma;
- struct mii_data *mii;
sc = device_get_softc(dev);
- ma = device_get_ivars(dev);
- sc->mii_dev = device_get_parent(dev);
- mii = ma->mii_data;
- LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list);
-
- sc->mii_flags = miibus_get_flags(dev);
- sc->mii_inst = mii->mii_instance++;
- sc->mii_phy = ma->mii_phyno;
- sc->mii_service = axphy_service;
- sc->mii_pdata = mii;
-
- sc->mii_flags |= MIIF_NOISOLATE;
-
- mii_phy_reset(sc);
-
- sc->mii_capabilities = PHY_READ(sc, MII_BMSR) & ma->mii_capmask;
- device_printf(dev, " ");
- mii_phy_add_media(sc);
- printf("\n");
- MIIBUS_MEDIAINIT(sc->mii_dev);
+ mii_phy_dev_attach(dev, MIIF_NOISOLATE | MIIF_NOMANPAUSE,
+ &axphy_funcs, 1);
mii_phy_setmedia(sc);
return (0);
@@ -143,7 +129,7 @@ axphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
}
/* Update the media status. */
- axphy_status(sc);
+ PHY_STATUS(sc);
/* Callback if something changed. */
mii_phy_update(sc, cmd);
@@ -187,7 +173,8 @@ axphy_status(struct mii_softc *sc)
else
mii->mii_media_active |= IFM_10_T;
if (scr & SCR_FDX)
- mii->mii_media_active |= IFM_FDX;
+ mii->mii_media_active |=
+ IFM_FDX | mii_phy_flowstatus(sc);
else
mii->mii_media_active |= IFM_HDX;
#endif
diff --git a/sys/dev/mii/bmtphy.c b/sys/dev/mii/bmtphy.c
index 6f53349..84933b7 100644
--- a/sys/dev/mii/bmtphy.c
+++ b/sys/dev/mii/bmtphy.c
@@ -85,11 +85,6 @@ __FBSDID("$FreeBSD$");
static int bmtphy_probe(device_t);
static int bmtphy_attach(device_t);
-struct bmtphy_softc {
- struct mii_softc mii_sc;
- int mii_model;
-};
-
static device_method_t bmtphy_methods[] = {
/* Device interface */
DEVMETHOD(device_probe, bmtphy_probe),
@@ -105,7 +100,7 @@ static devclass_t bmtphy_devclass;
static driver_t bmtphy_driver = {
"bmtphy",
bmtphy_methods,
- sizeof(struct bmtphy_softc)
+ sizeof(struct mii_softc)
};
DRIVER_MODULE(bmtphy, miibus, bmtphy_driver, bmtphy_devclass, 0, 0);
@@ -115,20 +110,26 @@ static void bmtphy_status(struct mii_softc *);
static void bmtphy_reset(struct mii_softc *);
static const struct mii_phydesc bmtphys_dp[] = {
- MII_PHY_DESC(BROADCOM, BCM4401),
- MII_PHY_DESC(BROADCOM, BCM5201),
- MII_PHY_DESC(BROADCOM, BCM5214),
- MII_PHY_DESC(BROADCOM, BCM5221),
- MII_PHY_DESC(BROADCOM, BCM5222),
+ MII_PHY_DESC(xxBROADCOM, BCM4401),
+ MII_PHY_DESC(xxBROADCOM, BCM5201),
+ MII_PHY_DESC(xxBROADCOM, BCM5214),
+ MII_PHY_DESC(xxBROADCOM, BCM5221),
+ MII_PHY_DESC(xxBROADCOM, BCM5222),
MII_PHY_END
};
static const struct mii_phydesc bmtphys_lp[] = {
- MII_PHY_DESC(BROADCOM, 3C905B),
- MII_PHY_DESC(BROADCOM, 3C905C),
+ MII_PHY_DESC(xxBROADCOM, 3C905B),
+ MII_PHY_DESC(xxBROADCOM, 3C905C),
MII_PHY_END
};
+static const struct mii_phy_funcs bmtphy_funcs = {
+ bmtphy_service,
+ bmtphy_status,
+ bmtphy_reset
+};
+
static int
bmtphy_probe(device_t dev)
{
@@ -145,37 +146,8 @@ bmtphy_probe(device_t dev)
static int
bmtphy_attach(device_t dev)
{
- struct bmtphy_softc *bsc;
- struct mii_softc *sc;
- struct mii_attach_args *ma;
- struct mii_data *mii;
-
- bsc = device_get_softc(dev);
- sc = &bsc->mii_sc;
- ma = device_get_ivars(dev);
- sc->mii_dev = device_get_parent(dev);
- mii = ma->mii_data;
- LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list);
-
- sc->mii_flags = miibus_get_flags(dev);
- sc->mii_inst = mii->mii_instance++;
- sc->mii_phy = ma->mii_phyno;
- sc->mii_service = bmtphy_service;
- sc->mii_pdata = mii;
-
- sc->mii_flags |= MIIF_NOMANPAUSE;
-
- bsc->mii_model = MII_MODEL(ma->mii_id2);
-
- bmtphy_reset(sc);
-
- sc->mii_capabilities = PHY_READ(sc, MII_BMSR) & ma->mii_capmask;
- device_printf(dev, " ");
- mii_phy_add_media(sc);
- printf("\n");
-
- MIIBUS_MEDIAINIT(sc->mii_dev);
+ mii_phy_dev_attach(dev, MIIF_NOMANPAUSE, &bmtphy_funcs, 1);
return (0);
}
@@ -204,7 +176,7 @@ bmtphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
}
/* Update the media status. */
- bmtphy_status(sc);
+ PHY_STATUS(sc);
/* Callback if something changed. */
mii_phy_update(sc, cmd);
@@ -267,14 +239,11 @@ bmtphy_status(struct mii_softc *sc)
static void
bmtphy_reset(struct mii_softc *sc)
{
- struct bmtphy_softc *bsc;
u_int16_t data;
- bsc = (struct bmtphy_softc *)sc;
-
mii_phy_reset(sc);
- if (bsc->mii_model == MII_MODEL_BROADCOM_BCM5221) {
+ if (sc->mii_mpd_model == MII_MODEL_xxBROADCOM_BCM5221) {
/* Enable shadow register mode. */
data = PHY_READ(sc, 0x1f);
PHY_WRITE(sc, 0x1f, data | 0x0080);
diff --git a/sys/dev/mii/brgphy.c b/sys/dev/mii/brgphy.c
index e3d890b..ef5fc27 100644
--- a/sys/dev/mii/brgphy.c
+++ b/sys/dev/mii/brgphy.c
@@ -68,9 +68,6 @@ static int brgphy_attach(device_t);
struct brgphy_softc {
struct mii_softc mii_sc;
- int mii_oui;
- int mii_model;
- int mii_rev;
int serdes_flags; /* Keeps track of the serdes type used */
#define BRGPHY_5706S 0x0001
#define BRGPHY_5708S 0x0002
@@ -117,37 +114,43 @@ static void brgphy_ethernet_wirespeed(struct mii_softc *);
static void brgphy_jumbo_settings(struct mii_softc *, u_long);
static const struct mii_phydesc brgphys[] = {
- MII_PHY_DESC(xxBROADCOM, BCM5400),
- MII_PHY_DESC(xxBROADCOM, BCM5401),
- MII_PHY_DESC(xxBROADCOM, BCM5411),
- MII_PHY_DESC(xxBROADCOM, BCM54K2),
- MII_PHY_DESC(xxBROADCOM, BCM5701),
- MII_PHY_DESC(xxBROADCOM, BCM5703),
- MII_PHY_DESC(xxBROADCOM, BCM5704),
- MII_PHY_DESC(xxBROADCOM, BCM5705),
- MII_PHY_DESC(xxBROADCOM, BCM5706),
- MII_PHY_DESC(xxBROADCOM, BCM5714),
- MII_PHY_DESC(xxBROADCOM, BCM5750),
- MII_PHY_DESC(xxBROADCOM, BCM5752),
- MII_PHY_DESC(xxBROADCOM, BCM5754),
- MII_PHY_DESC(xxBROADCOM, BCM5780),
- MII_PHY_DESC(xxBROADCOM, BCM5708C),
- MII_PHY_DESC(xxBROADCOM_ALT1, BCM5482S),
- MII_PHY_DESC(xxBROADCOM_ALT1, BCM5755),
- MII_PHY_DESC(xxBROADCOM_ALT1, BCM5787),
- MII_PHY_DESC(xxBROADCOM_ALT1, BCM5708S),
- MII_PHY_DESC(xxBROADCOM_ALT1, BCM5709CAX),
- MII_PHY_DESC(xxBROADCOM_ALT1, BCM5722),
- MII_PHY_DESC(xxBROADCOM_ALT1, BCM5784),
- MII_PHY_DESC(xxBROADCOM_ALT1, BCM5709C),
- MII_PHY_DESC(xxBROADCOM_ALT1, BCM5761),
- MII_PHY_DESC(xxBROADCOM_ALT1, BCM5709S),
- MII_PHY_DESC(xxBROADCOM_ALT2, BCM5717C),
- MII_PHY_DESC(xxBROADCOM_ALT2, BCM57765),
- MII_PHY_DESC(BROADCOM2, BCM5906),
+ MII_PHY_DESC(BROADCOM, BCM5400),
+ MII_PHY_DESC(BROADCOM, BCM5401),
+ MII_PHY_DESC(BROADCOM, BCM5411),
+ MII_PHY_DESC(BROADCOM, BCM54K2),
+ MII_PHY_DESC(BROADCOM, BCM5701),
+ MII_PHY_DESC(BROADCOM, BCM5703),
+ MII_PHY_DESC(BROADCOM, BCM5704),
+ MII_PHY_DESC(BROADCOM, BCM5705),
+ MII_PHY_DESC(BROADCOM, BCM5706),
+ MII_PHY_DESC(BROADCOM, BCM5714),
+ MII_PHY_DESC(BROADCOM, BCM5421),
+ MII_PHY_DESC(BROADCOM, BCM5750),
+ MII_PHY_DESC(BROADCOM, BCM5752),
+ MII_PHY_DESC(BROADCOM, BCM5780),
+ MII_PHY_DESC(BROADCOM, BCM5708C),
+ MII_PHY_DESC(BROADCOM2, BCM5482),
+ MII_PHY_DESC(BROADCOM2, BCM5708S),
+ MII_PHY_DESC(BROADCOM2, BCM5709C),
+ MII_PHY_DESC(BROADCOM2, BCM5709S),
+ MII_PHY_DESC(BROADCOM2, BCM5709CAX),
+ MII_PHY_DESC(BROADCOM2, BCM5722),
+ MII_PHY_DESC(BROADCOM2, BCM5755),
+ MII_PHY_DESC(BROADCOM2, BCM5754),
+ MII_PHY_DESC(BROADCOM2, BCM5761),
+ MII_PHY_DESC(BROADCOM2, BCM5784),
+ MII_PHY_DESC(BROADCOM3, BCM5717C),
+ MII_PHY_DESC(BROADCOM3, BCM57765),
+ MII_PHY_DESC(xxBROADCOM_ALT1, BCM5906),
MII_PHY_END
};
+static const struct mii_phy_funcs brgphy_funcs = {
+ brgphy_service,
+ brgphy_status,
+ brgphy_reset
+};
+
#define HS21_PRODUCT_ID "IBM eServer BladeCenter HS21"
#define HS21_BCM_CHIPID 0x57081021
@@ -186,49 +189,22 @@ brgphy_attach(device_t dev)
struct bge_softc *bge_sc = NULL;
struct bce_softc *bce_sc = NULL;
struct mii_softc *sc;
- struct mii_attach_args *ma;
- struct mii_data *mii;
struct ifnet *ifp;
bsc = device_get_softc(dev);
sc = &bsc->mii_sc;
- ma = device_get_ivars(dev);
- sc->mii_dev = device_get_parent(dev);
- mii = ma->mii_data;
- LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list);
-
- /* Initialize mii_softc structure */
- sc->mii_flags = miibus_get_flags(dev);
- sc->mii_inst = mii->mii_instance++;
- sc->mii_phy = ma->mii_phyno;
- sc->mii_service = brgphy_service;
- sc->mii_pdata = mii;
- /*
- * At least some variants wedge when isolating, at least some also
- * don't support loopback.
- */
- sc->mii_flags |= MIIF_NOISOLATE | MIIF_NOLOOP | MIIF_NOMANPAUSE;
+ mii_phy_dev_attach(dev, MIIF_NOISOLATE | MIIF_NOMANPAUSE,
+ &brgphy_funcs, 0);
- /* Initialize brgphy_softc structure */
- bsc->mii_oui = MII_OUI(ma->mii_id1, ma->mii_id2);
- bsc->mii_model = MII_MODEL(ma->mii_id2);
- bsc->mii_rev = MII_REV(ma->mii_id2);
bsc->serdes_flags = 0;
- if (bootverbose)
- device_printf(dev, "OUI 0x%06x, model 0x%04x, rev. %d\n",
- bsc->mii_oui, bsc->mii_model, bsc->mii_rev);
-
/* Handle any special cases based on the PHY ID */
- switch (bsc->mii_oui) {
+ switch (sc->mii_mpd_oui) {
case MII_OUI_BROADCOM:
- case MII_OUI_BROADCOM2:
- break;
- case MII_OUI_xxBROADCOM:
- switch (bsc->mii_model) {
- case MII_MODEL_xxBROADCOM_BCM5706:
- case MII_MODEL_xxBROADCOM_BCM5714:
+ switch (sc->mii_mpd_model) {
+ case MII_MODEL_BROADCOM_BCM5706:
+ case MII_MODEL_BROADCOM_BCM5714:
/*
* The 5464 PHY used in the 5706 supports both copper
* and fiber interfaces over GMII. Need to check the
@@ -245,23 +221,18 @@ brgphy_attach(device_t dev)
}
break;
} break;
- case MII_OUI_xxBROADCOM_ALT1:
- switch (bsc->mii_model) {
- case MII_MODEL_xxBROADCOM_ALT1_BCM5708S:
+ case MII_OUI_BROADCOM2:
+ switch (sc->mii_mpd_model) {
+ case MII_MODEL_BROADCOM2_BCM5708S:
bsc->serdes_flags |= BRGPHY_5708S;
sc->mii_flags |= MIIF_HAVEFIBER;
break;
- case MII_MODEL_xxBROADCOM_ALT1_BCM5709S:
+ case MII_MODEL_BROADCOM2_BCM5709S:
bsc->serdes_flags |= BRGPHY_5709S;
sc->mii_flags |= MIIF_HAVEFIBER;
break;
}
break;
- case MII_OUI_xxBROADCOM_ALT2:
- /* No special handling yet. */
- break;
- default:
- device_printf(dev, "Unrecognized OUI for PHY!\n");
}
ifp = sc->mii_pdata->mii_ifp;
@@ -273,15 +244,15 @@ brgphy_attach(device_t dev)
bce_sc = ifp->if_softc;
}
- brgphy_reset(sc);
+ PHY_RESET(sc);
/* Read the PHY's capabilities. */
- sc->mii_capabilities = PHY_READ(sc, MII_BMSR) & ma->mii_capmask;
+ sc->mii_capabilities = PHY_READ(sc, MII_BMSR) & sc->mii_capmask;
if (sc->mii_capabilities & BMSR_EXTSTAT)
sc->mii_extcapabilities = PHY_READ(sc, MII_EXTSR);
device_printf(dev, " ");
-#define ADD(m, c) ifmedia_add(&mii->mii_media, (m), (c), NULL)
+#define ADD(m, c) ifmedia_add(&sc->mii_pdata->mii_media, (m), (c), NULL)
/* Add the supported media types */
if ((sc->mii_flags & MIIF_HAVEFIBER) == 0) {
@@ -322,7 +293,6 @@ brgphy_attach(device_t dev)
static int
brgphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
{
- struct brgphy_softc *bsc = (struct brgphy_softc *)sc;
struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
int val;
@@ -335,7 +305,7 @@ brgphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
break;
/* Todo: Why is this here? Is it really needed? */
- brgphy_reset(sc); /* XXX hardware bug work-around */
+ PHY_RESET(sc); /* XXX hardware bug work-around */
switch (IFM_SUBTYPE(ife->ifm_media)) {
case IFM_AUTO:
@@ -390,7 +360,7 @@ brgphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
}
/* Update the media status. */
- brgphy_status(sc);
+ PHY_STATUS(sc);
/*
* Callback if something changed. Note that we need to poke
@@ -399,28 +369,24 @@ brgphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
if (sc->mii_media_active != mii->mii_media_active ||
sc->mii_media_status != mii->mii_media_status ||
cmd == MII_MEDIACHG) {
- switch (bsc->mii_oui) {
+ switch (sc->mii_mpd_oui) {
case MII_OUI_BROADCOM:
- break;
- case MII_OUI_xxBROADCOM:
- switch (bsc->mii_model) {
- case MII_MODEL_xxBROADCOM_BCM5400:
+ switch (sc->mii_mpd_model) {
+ case MII_MODEL_BROADCOM_BCM5400:
bcm5401_load_dspcode(sc);
break;
- case MII_MODEL_xxBROADCOM_BCM5401:
- if (bsc->mii_rev == 1 || bsc->mii_rev == 3)
+ case MII_MODEL_BROADCOM_BCM5401:
+ if (sc->mii_mpd_rev == 1 || sc->mii_mpd_rev == 3)
bcm5401_load_dspcode(sc);
break;
- case MII_MODEL_xxBROADCOM_BCM5411:
+ case MII_MODEL_BROADCOM_BCM5411:
bcm5411_load_dspcode(sc);
break;
- case MII_MODEL_xxBROADCOM_BCM54K2:
+ case MII_MODEL_BROADCOM_BCM54K2:
bcm54k2_load_dspcode(sc);
break;
}
break;
- case MII_OUI_xxBROADCOM_ALT1:
- break;
}
}
mii_phy_update(sc, cmd);
@@ -625,10 +591,9 @@ brgphy_status(struct mii_softc *sc)
static void
brgphy_mii_phy_auto(struct mii_softc *sc, int media)
{
- struct brgphy_softc *bsc = (struct brgphy_softc *)sc;
int anar, ktcr = 0;
- brgphy_reset(sc);
+ PHY_RESET(sc);
if ((sc->mii_flags & MIIF_HAVEFIBER) == 0) {
anar = BMSR_MEDIA_TO_ANAR(sc->mii_capabilities) | ANAR_CSMA;
@@ -645,7 +610,7 @@ brgphy_mii_phy_auto(struct mii_softc *sc, int media)
}
ktcr = BRGPHY_1000CTL_AFD | BRGPHY_1000CTL_AHD;
- if (bsc->mii_model == MII_MODEL_xxBROADCOM_BCM5701)
+ if (sc->mii_mpd_model == MII_MODEL_BROADCOM_BCM5701)
ktcr |= BRGPHY_1000CTL_MSE | BRGPHY_1000CTL_MSC;
PHY_WRITE(sc, BRGPHY_MII_1000CTL, ktcr);
ktcr = PHY_READ(sc, BRGPHY_MII_1000CTL);
@@ -875,12 +840,11 @@ brgphy_ethernet_wirespeed(struct mii_softc *sc)
static void
brgphy_jumbo_settings(struct mii_softc *sc, u_long mtu)
{
- struct brgphy_softc *bsc = (struct brgphy_softc *)sc;
uint32_t val;
/* Set or clear jumbo frame settings in the PHY. */
if (mtu > ETHER_MAX_LEN) {
- if (bsc->mii_model == MII_MODEL_xxBROADCOM_BCM5401) {
+ if (sc->mii_mpd_model == MII_MODEL_BROADCOM_BCM5401) {
/* BCM5401 PHY cannot read-modify-write. */
PHY_WRITE(sc, BRGPHY_MII_AUXCTL, 0x4c20);
} else {
@@ -908,7 +872,6 @@ brgphy_jumbo_settings(struct mii_softc *sc, u_long mtu)
static void
brgphy_reset(struct mii_softc *sc)
{
- struct brgphy_softc *bsc = (struct brgphy_softc *)sc;
struct bge_softc *bge_sc = NULL;
struct bce_softc *bce_sc = NULL;
struct ifnet *ifp;
@@ -918,29 +881,24 @@ brgphy_reset(struct mii_softc *sc)
mii_phy_reset(sc);
/* Handle any PHY specific procedures following the reset. */
- switch (bsc->mii_oui) {
+ switch (sc->mii_mpd_oui) {
case MII_OUI_BROADCOM:
- break;
- case MII_OUI_xxBROADCOM:
- switch (bsc->mii_model) {
- case MII_MODEL_xxBROADCOM_BCM5400:
+ switch (sc->mii_mpd_model) {
+ case MII_MODEL_BROADCOM_BCM5400:
bcm5401_load_dspcode(sc);
break;
- case MII_MODEL_xxBROADCOM_BCM5401:
- if (bsc->mii_rev == 1 || bsc->mii_rev == 3)
+ case MII_MODEL_BROADCOM_BCM5401:
+ if (sc->mii_mpd_rev == 1 || sc->mii_mpd_rev == 3)
bcm5401_load_dspcode(sc);
break;
- case MII_MODEL_xxBROADCOM_BCM5411:
+ case MII_MODEL_BROADCOM_BCM5411:
bcm5411_load_dspcode(sc);
break;
- case MII_MODEL_xxBROADCOM_BCM54K2:
+ case MII_MODEL_BROADCOM_BCM54K2:
bcm54k2_load_dspcode(sc);
break;
}
break;
- case MII_OUI_xxBROADCOM_ALT1:
- case MII_OUI_xxBROADCOM_ALT2:
- break;
}
ifp = sc->mii_pdata->mii_ifp;
diff --git a/sys/dev/mii/ciphy.c b/sys/dev/mii/ciphy.c
index 919680b..2133c76 100644
--- a/sys/dev/mii/ciphy.c
+++ b/sys/dev/mii/ciphy.c
@@ -86,16 +86,22 @@ static void ciphy_reset(struct mii_softc *);
static void ciphy_fixup(struct mii_softc *);
static const struct mii_phydesc ciphys[] = {
- MII_PHY_DESC(CICADA, CS8201),
- MII_PHY_DESC(CICADA, CS8201A),
- MII_PHY_DESC(CICADA, CS8201B),
- MII_PHY_DESC(CICADA, CS8204),
- MII_PHY_DESC(CICADA, VSC8211),
- MII_PHY_DESC(CICADA, CS8244),
- MII_PHY_DESC(VITESSE, VSC8601),
+ MII_PHY_DESC(xxCICADA, CS8201),
+ MII_PHY_DESC(xxCICADA, CS8201A),
+ MII_PHY_DESC(xxCICADA, CS8201B),
+ MII_PHY_DESC(xxCICADA, CS8204),
+ MII_PHY_DESC(xxCICADA, VSC8211),
+ MII_PHY_DESC(xxCICADA, CS8244),
+ MII_PHY_DESC(xxVITESSE, VSC8601),
MII_PHY_END
};
+static const struct mii_phy_funcs ciphy_funcs = {
+ ciphy_service,
+ ciphy_status,
+ ciphy_reset
+};
+
static int
ciphy_probe(device_t dev)
{
@@ -106,34 +112,9 @@ ciphy_probe(device_t dev)
static int
ciphy_attach(device_t dev)
{
- struct mii_softc *sc;
- struct mii_attach_args *ma;
- struct mii_data *mii;
-
- sc = device_get_softc(dev);
- ma = device_get_ivars(dev);
- sc->mii_dev = device_get_parent(dev);
- mii = ma->mii_data;
- LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list);
-
- sc->mii_flags = miibus_get_flags(dev);
- sc->mii_inst = mii->mii_instance++;
- sc->mii_phy = ma->mii_phyno;
- sc->mii_service = ciphy_service;
- sc->mii_pdata = mii;
-
- sc->mii_flags |= MIIF_NOISOLATE;
-
- ciphy_reset(sc);
-
- sc->mii_capabilities = PHY_READ(sc, MII_BMSR) & ma->mii_capmask;
- if (sc->mii_capabilities & BMSR_EXTSTAT)
- sc->mii_extcapabilities = PHY_READ(sc, MII_EXTSR);
- device_printf(dev, " ");
- mii_phy_add_media(sc);
- printf("\n");
-
- MIIBUS_MEDIAINIT(sc->mii_dev);
+
+ mii_phy_dev_attach(dev, MIIF_NOISOLATE | MIIF_NOMANPAUSE,
+ &ciphy_funcs, 1);
return (0);
}
@@ -239,7 +220,7 @@ setit:
}
/* Update the media status. */
- ciphy_status(sc);
+ PHY_STATUS(sc);
/*
* Callback if something changed. Note that we need to poke
@@ -299,7 +280,7 @@ ciphy_status(struct mii_softc *sc)
}
if (bmsr & CIPHY_AUXCSR_FDX)
- mii->mii_media_active |= IFM_FDX;
+ mii->mii_media_active |= IFM_FDX | mii_phy_flowstatus(sc);
else
mii->mii_media_active |= IFM_HDX;
@@ -349,8 +330,8 @@ ciphy_fixup(struct mii_softc *sc)
}
switch (model) {
- case MII_MODEL_CICADA_CS8204:
- case MII_MODEL_CICADA_CS8201:
+ case MII_MODEL_xxCICADA_CS8204:
+ case MII_MODEL_xxCICADA_CS8201:
/* Turn off "aux mode" (whatever that means) */
PHY_SETBIT(sc, CIPHY_MII_AUXCSR, CIPHY_AUXCSR_MDPPS);
@@ -371,8 +352,8 @@ ciphy_fixup(struct mii_softc *sc)
break;
- case MII_MODEL_CICADA_CS8201A:
- case MII_MODEL_CICADA_CS8201B:
+ case MII_MODEL_xxCICADA_CS8201A:
+ case MII_MODEL_xxCICADA_CS8201B:
/*
* Work around speed polling bug in VT3119/VT3216
@@ -386,9 +367,9 @@ ciphy_fixup(struct mii_softc *sc)
}
break;
- case MII_MODEL_CICADA_VSC8211:
- case MII_MODEL_CICADA_CS8244:
- case MII_MODEL_VITESSE_VSC8601:
+ case MII_MODEL_xxCICADA_VSC8211:
+ case MII_MODEL_xxCICADA_CS8244:
+ case MII_MODEL_xxVITESSE_VSC8601:
break;
default:
device_printf(sc->mii_dev, "unknown CICADA PHY model %x\n",
diff --git a/sys/dev/mii/e1000phy.c b/sys/dev/mii/e1000phy.c
index 25f3092..b0d7069 100644
--- a/sys/dev/mii/e1000phy.c
+++ b/sys/dev/mii/e1000phy.c
@@ -65,11 +65,6 @@ __FBSDID("$FreeBSD$");
static int e1000phy_probe(device_t);
static int e1000phy_attach(device_t);
-struct e1000phy_softc {
- struct mii_softc mii_sc;
- int mii_model;
-};
-
static device_method_t e1000phy_methods[] = {
/* device interface */
DEVMETHOD(device_probe, e1000phy_probe),
@@ -83,7 +78,7 @@ static devclass_t e1000phy_devclass;
static driver_t e1000phy_driver = {
"e1000phy",
e1000phy_methods,
- sizeof(struct e1000phy_softc)
+ sizeof(struct mii_softc)
};
DRIVER_MODULE(e1000phy, miibus, e1000phy_driver, e1000phy_devclass, 0, 0);
@@ -91,32 +86,38 @@ DRIVER_MODULE(e1000phy, miibus, e1000phy_driver, e1000phy_devclass, 0, 0);
static int e1000phy_service(struct mii_softc *, struct mii_data *, int);
static void e1000phy_status(struct mii_softc *);
static void e1000phy_reset(struct mii_softc *);
-static int e1000phy_mii_phy_auto(struct e1000phy_softc *, int);
+static int e1000phy_mii_phy_auto(struct mii_softc *, int);
static const struct mii_phydesc e1000phys[] = {
MII_PHY_DESC(MARVELL, E1000),
MII_PHY_DESC(MARVELL, E1011),
MII_PHY_DESC(MARVELL, E1000_3),
- MII_PHY_DESC(MARVELL, E1000S),
MII_PHY_DESC(MARVELL, E1000_5),
- MII_PHY_DESC(MARVELL, E1101),
- MII_PHY_DESC(MARVELL, E3082),
- MII_PHY_DESC(MARVELL, E1112),
- MII_PHY_DESC(MARVELL, E1149),
MII_PHY_DESC(MARVELL, E1111),
- MII_PHY_DESC(MARVELL, E1116),
- MII_PHY_DESC(MARVELL, E1116R),
- MII_PHY_DESC(MARVELL, E1118),
- MII_PHY_DESC(MARVELL, E3016),
- MII_PHY_DESC(MARVELL, PHYG65G),
MII_PHY_DESC(xxMARVELL, E1000),
MII_PHY_DESC(xxMARVELL, E1011),
MII_PHY_DESC(xxMARVELL, E1000_3),
+ MII_PHY_DESC(xxMARVELL, E1000S),
MII_PHY_DESC(xxMARVELL, E1000_5),
+ MII_PHY_DESC(xxMARVELL, E1101),
+ MII_PHY_DESC(xxMARVELL, E3082),
+ MII_PHY_DESC(xxMARVELL, E1112),
+ MII_PHY_DESC(xxMARVELL, E1149),
MII_PHY_DESC(xxMARVELL, E1111),
+ MII_PHY_DESC(xxMARVELL, E1116),
+ MII_PHY_DESC(xxMARVELL, E1116R),
+ MII_PHY_DESC(xxMARVELL, E1118),
+ MII_PHY_DESC(xxMARVELL, E3016),
+ MII_PHY_DESC(xxMARVELL, PHYG65G),
MII_PHY_END
};
+static const struct mii_phy_funcs e1000phy_funcs = {
+ e1000phy_service,
+ e1000phy_status,
+ e1000phy_reset
+};
+
static int
e1000phy_probe(device_t dev)
{
@@ -127,40 +128,25 @@ e1000phy_probe(device_t dev)
static int
e1000phy_attach(device_t dev)
{
- struct e1000phy_softc *esc;
struct mii_softc *sc;
- struct mii_attach_args *ma;
- struct mii_data *mii;
struct ifnet *ifp;
- esc = device_get_softc(dev);
- sc = &esc->mii_sc;
- ma = device_get_ivars(dev);
- sc->mii_dev = device_get_parent(dev);
- mii = ma->mii_data;
- LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list);
-
- sc->mii_flags = miibus_get_flags(dev);
- sc->mii_inst = mii->mii_instance++;
- sc->mii_phy = ma->mii_phyno;
- sc->mii_service = e1000phy_service;
- sc->mii_pdata = mii;
+ sc = device_get_softc(dev);
- sc->mii_flags |= MIIF_NOMANPAUSE;
+ mii_phy_dev_attach(dev, MIIF_NOMANPAUSE, &e1000phy_funcs, 0);
- esc->mii_model = MII_MODEL(ma->mii_id2);
ifp = sc->mii_pdata->mii_ifp;
if (strcmp(ifp->if_dname, "msk") == 0 &&
(sc->mii_flags & MIIF_MACPRIV0) != 0)
sc->mii_flags |= MIIF_PHYPRIV0;
- switch (esc->mii_model) {
- case MII_MODEL_MARVELL_E1011:
- case MII_MODEL_MARVELL_E1112:
+ switch (sc->mii_mpd_model) {
+ case MII_MODEL_xxMARVELL_E1011:
+ case MII_MODEL_xxMARVELL_E1112:
if (PHY_READ(sc, E1000_ESSR) & E1000_ESSR_FIBER_LINK)
sc->mii_flags |= MIIF_HAVEFIBER;
break;
- case MII_MODEL_MARVELL_E1149:
+ case MII_MODEL_xxMARVELL_E1149:
/*
* Some 88E1149 PHY's page select is initialized to
* point to other bank instead of copper/fiber bank
@@ -176,9 +162,9 @@ e1000phy_attach(device_t dev)
break;
}
- e1000phy_reset(sc);
+ PHY_RESET(sc);
- sc->mii_capabilities = PHY_READ(sc, MII_BMSR) & ma->mii_capmask;
+ sc->mii_capabilities = PHY_READ(sc, MII_BMSR) & sc->mii_capmask;
if (sc->mii_capabilities & BMSR_EXTSTAT)
sc->mii_extcapabilities = PHY_READ(sc, MII_EXTSR);
device_printf(dev, " ");
@@ -192,15 +178,13 @@ e1000phy_attach(device_t dev)
static void
e1000phy_reset(struct mii_softc *sc)
{
- struct e1000phy_softc *esc;
uint16_t reg, page;
- esc = (struct e1000phy_softc *)sc;
reg = PHY_READ(sc, E1000_SCR);
if ((sc->mii_flags & MIIF_HAVEFIBER) != 0) {
reg &= ~E1000_SCR_AUTO_X_MODE;
PHY_WRITE(sc, E1000_SCR, reg);
- if (esc->mii_model == MII_MODEL_MARVELL_E1112) {
+ if (sc->mii_mpd_model == MII_MODEL_xxMARVELL_E1112) {
/* Select 1000BASE-X only mode. */
page = PHY_READ(sc, E1000_EADR);
PHY_WRITE(sc, E1000_EADR, 2);
@@ -218,25 +202,25 @@ e1000phy_reset(struct mii_softc *sc)
PHY_WRITE(sc, E1000_EADR, page);
}
} else {
- switch (esc->mii_model) {
- case MII_MODEL_MARVELL_E1111:
- case MII_MODEL_MARVELL_E1112:
- case MII_MODEL_MARVELL_E1116:
- case MII_MODEL_MARVELL_E1118:
- case MII_MODEL_MARVELL_E1149:
- case MII_MODEL_MARVELL_PHYG65G:
+ switch (sc->mii_mpd_model) {
+ case MII_MODEL_xxMARVELL_E1111:
+ case MII_MODEL_xxMARVELL_E1112:
+ case MII_MODEL_xxMARVELL_E1116:
+ case MII_MODEL_xxMARVELL_E1118:
+ case MII_MODEL_xxMARVELL_E1149:
+ case MII_MODEL_xxMARVELL_PHYG65G:
/* Disable energy detect mode. */
reg &= ~E1000_SCR_EN_DETECT_MASK;
reg |= E1000_SCR_AUTO_X_MODE;
- if (esc->mii_model == MII_MODEL_MARVELL_E1116)
+ if (sc->mii_mpd_model == MII_MODEL_xxMARVELL_E1116)
reg &= ~E1000_SCR_POWER_DOWN;
reg |= E1000_SCR_ASSERT_CRS_ON_TX;
break;
- case MII_MODEL_MARVELL_E3082:
+ case MII_MODEL_xxMARVELL_E3082:
reg |= (E1000_SCR_AUTO_X_MODE >> 1);
reg |= E1000_SCR_ASSERT_CRS_ON_TX;
break;
- case MII_MODEL_MARVELL_E3016:
+ case MII_MODEL_xxMARVELL_E3016:
reg |= E1000_SCR_AUTO_MDIX;
reg &= ~(E1000_SCR_EN_DETECT |
E1000_SCR_SCRAMBLER_DISABLE);
@@ -249,14 +233,14 @@ e1000phy_reset(struct mii_softc *sc)
reg |= E1000_SCR_ASSERT_CRS_ON_TX;
break;
}
- if (esc->mii_model != MII_MODEL_MARVELL_E3016) {
+ if (sc->mii_mpd_model != MII_MODEL_xxMARVELL_E3016) {
/* Auto correction for reversed cable polarity. */
reg &= ~E1000_SCR_POLARITY_REVERSAL;
}
PHY_WRITE(sc, E1000_SCR, reg);
- if (esc->mii_model == MII_MODEL_MARVELL_E1116 ||
- esc->mii_model == MII_MODEL_MARVELL_E1149) {
+ if (sc->mii_mpd_model == MII_MODEL_xxMARVELL_E1116 ||
+ sc->mii_mpd_model == MII_MODEL_xxMARVELL_E1149) {
PHY_WRITE(sc, E1000_EADR, 2);
reg = PHY_READ(sc, E1000_SCR);
reg |= E1000_SCR_RGMII_POWER_UP;
@@ -265,12 +249,12 @@ e1000phy_reset(struct mii_softc *sc)
}
}
- switch (esc->mii_model) {
- case MII_MODEL_MARVELL_E3082:
- case MII_MODEL_MARVELL_E1112:
- case MII_MODEL_MARVELL_E1118:
+ switch (sc->mii_mpd_model) {
+ case MII_MODEL_xxMARVELL_E3082:
+ case MII_MODEL_xxMARVELL_E1112:
+ case MII_MODEL_xxMARVELL_E1118:
break;
- case MII_MODEL_MARVELL_E1116:
+ case MII_MODEL_xxMARVELL_E1116:
page = PHY_READ(sc, E1000_EADR);
/* Select page 3, LED control register. */
PHY_WRITE(sc, E1000_EADR, 3);
@@ -284,7 +268,7 @@ e1000phy_reset(struct mii_softc *sc)
E1000_BLINK_RATE(E1000_BLINK_84MS));
PHY_WRITE(sc, E1000_EADR, page);
break;
- case MII_MODEL_MARVELL_E3016:
+ case MII_MODEL_xxMARVELL_E3016:
/* LED2 -> ACT, LED1 -> LINK, LED0 -> SPEED. */
PHY_WRITE(sc, 0x16, 0x0B << 8 | 0x05 << 4 | 0x04);
/* Integrated register calibration workaround. */
@@ -309,7 +293,6 @@ static int
e1000phy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
{
struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
- struct e1000phy_softc *esc = (struct e1000phy_softc *)sc;
uint16_t speed, gig;
int reg;
@@ -325,7 +308,7 @@ e1000phy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
break;
if (IFM_SUBTYPE(ife->ifm_media) == IFM_AUTO) {
- e1000phy_mii_phy_auto(esc, ife->ifm_media);
+ e1000phy_mii_phy_auto(sc, ife->ifm_media);
break;
}
@@ -412,13 +395,13 @@ done:
break;
sc->mii_ticks = 0;
- e1000phy_reset(sc);
- e1000phy_mii_phy_auto(esc, ife->ifm_media);
+ PHY_RESET(sc);
+ e1000phy_mii_phy_auto(sc, ife->ifm_media);
break;
}
/* Update the media status. */
- e1000phy_status(sc);
+ PHY_STATUS(sc);
/* Callback if something changed. */
mii_phy_update(sc, cmd);
@@ -489,12 +472,10 @@ e1000phy_status(struct mii_softc *sc)
}
static int
-e1000phy_mii_phy_auto(struct e1000phy_softc *esc, int media)
+e1000phy_mii_phy_auto(struct mii_softc *sc, int media)
{
- struct mii_softc *sc;
uint16_t reg;
- sc = &esc->mii_sc;
if ((sc->mii_flags & MIIF_HAVEFIBER) == 0) {
reg = PHY_READ(sc, E1000_AR);
reg &= ~(E1000_AR_PAUSE | E1000_AR_ASM_DIR);
diff --git a/sys/dev/mii/exphy.c b/sys/dev/mii/exphy.c
index a5b03dc..04add67 100644
--- a/sys/dev/mii/exphy.c
+++ b/sys/dev/mii/exphy.c
@@ -111,10 +111,16 @@ static void exphy_reset(struct mii_softc *);
*/
static const struct mii_phydesc exphys[] = {
{ 0, 0, "3Com internal media interface" },
- MII_PHY_DESC(BROADCOM, 3C905C),
+ MII_PHY_DESC(xxBROADCOM, 3C905C),
MII_PHY_END
};
-
+
+static const struct mii_phy_funcs exphy_funcs = {
+ exphy_service,
+ ukphy_status,
+ exphy_reset
+};
+
static int
exphy_probe(device_t dev)
{
@@ -128,40 +134,12 @@ exphy_probe(device_t dev)
static int
exphy_attach(device_t dev)
{
- struct mii_softc *sc;
- struct mii_attach_args *ma;
- struct mii_data *mii;
-
- sc = device_get_softc(dev);
- ma = device_get_ivars(dev);
- sc->mii_dev = device_get_parent(dev);
- mii = ma->mii_data;
- LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list);
-
- sc->mii_flags = miibus_get_flags(dev);
- sc->mii_inst = mii->mii_instance++;
- sc->mii_phy = ma->mii_phyno;
- sc->mii_service = exphy_service;
- sc->mii_pdata = mii;
/*
* The 3Com PHY can never be isolated.
*/
- sc->mii_flags |= MIIF_NOISOLATE;
-
-#define ADD(m, c) ifmedia_add(&mii->mii_media, (m), (c), NULL)
-
- ADD(IFM_MAKEWORD(IFM_ETHER, IFM_100_TX, IFM_LOOP, sc->mii_inst),
- MII_MEDIA_100_TX);
-
- exphy_reset(sc);
-
- sc->mii_capabilities = PHY_READ(sc, MII_BMSR) & ma->mii_capmask;
- device_printf(dev, " ");
- mii_phy_add_media(sc);
- printf("\n");
-#undef ADD
- MIIBUS_MEDIAINIT(sc->mii_dev);
+ mii_phy_dev_attach(dev, MIIF_NOISOLATE | MIIF_NOMANPAUSE,
+ &exphy_funcs, 1);
return (0);
}
@@ -198,7 +176,7 @@ exphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
}
/* Update the media status. */
- ukphy_status(sc);
+ PHY_STATUS(sc);
/* Callback if something changed. */
mii_phy_update(sc, cmd);
diff --git a/sys/dev/mii/gentbi.c b/sys/dev/mii/gentbi.c
index a36f16a..bf5319b 100644
--- a/sys/dev/mii/gentbi.c
+++ b/sys/dev/mii/gentbi.c
@@ -111,6 +111,12 @@ DRIVER_MODULE(gentbi, miibus, gentbi_driver, gentbi_devclass, 0, 0);
static int gentbi_service(struct mii_softc *, struct mii_data *, int);
static void gentbi_status(struct mii_softc *);
+static const struct mii_phy_funcs gentbi_funcs = {
+ gentbi_service,
+ gentbi_status,
+ mii_phy_reset
+};
+
static int
gentbi_probe(device_t dev)
{
@@ -152,36 +158,19 @@ static int
gentbi_attach(device_t dev)
{
struct mii_softc *sc;
- struct mii_attach_args *ma;
- struct mii_data *mii;
sc = device_get_softc(dev);
- ma = device_get_ivars(dev);
- sc->mii_dev = device_get_parent(dev);
- mii = ma->mii_data;
- LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list);
-
- if (bootverbose)
- device_printf(dev, "OUI 0x%06x, model 0x%04x, rev. %d\n",
- MII_OUI(ma->mii_id1, ma->mii_id2),
- MII_MODEL(ma->mii_id2), MII_REV(ma->mii_id2));
-
- sc->mii_flags = miibus_get_flags(dev);
- sc->mii_inst = mii->mii_instance++;
- sc->mii_phy = ma->mii_phyno;
- sc->mii_service = gentbi_service;
- sc->mii_pdata = mii;
- sc->mii_flags |= MIIF_NOMANPAUSE;
+ mii_phy_dev_attach(dev, MIIF_NOMANPAUSE, &gentbi_funcs, 0);
- mii_phy_reset(sc);
+ PHY_RESET(sc);
/*
* Mask out all media in the BMSR. We only are really interested
* in "auto".
*/
sc->mii_capabilities =
- PHY_READ(sc, MII_BMSR) & ma->mii_capmask & ~BMSR_MEDIAMASK;
+ PHY_READ(sc, MII_BMSR) & sc->mii_capmask & ~BMSR_MEDIAMASK;
if (sc->mii_capabilities & BMSR_EXTSTAT)
sc->mii_extcapabilities = PHY_READ(sc, MII_EXTSR);
@@ -218,7 +207,7 @@ gentbi_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
}
/* Update the media status. */
- gentbi_status(sc);
+ PHY_STATUS(sc);
/* Callback if something changed. */
mii_phy_update(sc, cmd);
diff --git a/sys/dev/mii/icsphy.c b/sys/dev/mii/icsphy.c
index 849a14b..90ec374 100644
--- a/sys/dev/mii/icsphy.c
+++ b/sys/dev/mii/icsphy.c
@@ -83,11 +83,6 @@ __FBSDID("$FreeBSD$");
static int icsphy_probe(device_t dev);
static int icsphy_attach(device_t dev);
-struct icsphy_softc {
- struct mii_softc mii_sc;
- int mii_model;
-};
-
static device_method_t icsphy_methods[] = {
/* device interface */
DEVMETHOD(device_probe, icsphy_probe),
@@ -102,7 +97,7 @@ static devclass_t icsphy_devclass;
static driver_t icsphy_driver = {
"icsphy",
icsphy_methods,
- sizeof(struct icsphy_softc)
+ sizeof(struct mii_softc)
};
DRIVER_MODULE(icsphy, miibus, icsphy_driver, icsphy_devclass, 0, 0);
@@ -112,13 +107,19 @@ static void icsphy_status(struct mii_softc *);
static void icsphy_reset(struct mii_softc *);
static const struct mii_phydesc icsphys[] = {
- MII_PHY_DESC(xxICS, 1889),
- MII_PHY_DESC(xxICS, 1890),
- MII_PHY_DESC(xxICS, 1892),
- MII_PHY_DESC(xxICS, 1893),
+ MII_PHY_DESC(ICS, 1889),
+ MII_PHY_DESC(ICS, 1890),
+ MII_PHY_DESC(ICS, 1892),
+ MII_PHY_DESC(ICS, 1893),
MII_PHY_END
};
+static const struct mii_phy_funcs icsphy_funcs = {
+ icsphy_service,
+ icsphy_status,
+ icsphy_reset
+};
+
static int
icsphy_probe(device_t dev)
{
@@ -129,40 +130,9 @@ icsphy_probe(device_t dev)
static int
icsphy_attach(device_t dev)
{
- struct icsphy_softc *isc;
- struct mii_softc *sc;
- struct mii_attach_args *ma;
- struct mii_data *mii;
-
- isc = device_get_softc(dev);
- sc = &isc->mii_sc;
- ma = device_get_ivars(dev);
- sc->mii_dev = device_get_parent(dev);
- mii = ma->mii_data;
- LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list);
-
- sc->mii_flags = miibus_get_flags(dev);
- sc->mii_inst = mii->mii_instance++;
- sc->mii_phy = ma->mii_phyno;
- sc->mii_service = icsphy_service;
- sc->mii_pdata = mii;
-
- sc->mii_flags |= MIIF_NOISOLATE;
-
- ifmedia_add(&mii->mii_media,
- IFM_MAKEWORD(IFM_ETHER, IFM_100_TX, IFM_LOOP, sc->mii_inst),
- MII_MEDIA_100_TX, NULL);
-
- isc->mii_model = MII_MODEL(ma->mii_id2);
- icsphy_reset(sc);
-
- sc->mii_capabilities = PHY_READ(sc, MII_BMSR) & ma->mii_capmask;
- device_printf(dev, " ");
- mii_phy_add_media(sc);
- printf("\n");
-
- MIIBUS_MEDIAINIT(sc->mii_dev);
+ mii_phy_dev_attach(dev, MIIF_NOISOLATE | MIIF_NOMANPAUSE,
+ &icsphy_funcs, 1);
return (0);
}
@@ -191,7 +161,7 @@ icsphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
}
/* Update the media status. */
- icsphy_status(sc);
+ PHY_STATUS(sc);
/* Callback if something changed. */
mii_phy_update(sc, cmd);
@@ -240,7 +210,8 @@ icsphy_status(struct mii_softc *sc)
else
mii->mii_media_active |= IFM_10_T;
if (qpr & QPR_FDX)
- mii->mii_media_active |= IFM_FDX;
+ mii->mii_media_active |=
+ IFM_FDX | mii_phy_flowstatus(sc);
else
mii->mii_media_active |= IFM_HDX;
} else
@@ -250,16 +221,15 @@ icsphy_status(struct mii_softc *sc)
static void
icsphy_reset(struct mii_softc *sc)
{
- struct icsphy_softc *isc = (struct icsphy_softc *)sc;
mii_phy_reset(sc);
/* set powerdown feature */
- switch (isc->mii_model) {
- case MII_MODEL_xxICS_1890:
- case MII_MODEL_xxICS_1893:
+ switch (sc->mii_mpd_model) {
+ case MII_MODEL_ICS_1890:
+ case MII_MODEL_ICS_1893:
PHY_WRITE(sc, MII_ICSPHY_ECR2, ECR2_100AUTOPWRDN);
break;
- case MII_MODEL_xxICS_1892:
+ case MII_MODEL_ICS_1892:
PHY_WRITE(sc, MII_ICSPHY_ECR2,
ECR2_10AUTOPWRDN|ECR2_100AUTOPWRDN);
break;
diff --git a/sys/dev/mii/inphy.c b/sys/dev/mii/inphy.c
index 30ba9ae..e6a601c 100644
--- a/sys/dev/mii/inphy.c
+++ b/sys/dev/mii/inphy.c
@@ -80,14 +80,20 @@ static void inphy_status(struct mii_softc *);
static void inphy_reset(struct mii_softc *);
static const struct mii_phydesc inphys[] = {
- MII_PHY_DESC(INTEL, I82553C),
- MII_PHY_DESC(INTEL, I82555),
- MII_PHY_DESC(INTEL, I82562EM),
- MII_PHY_DESC(INTEL, I82562ET),
- MII_PHY_DESC(xxINTEL, I82553AB),
+ MII_PHY_DESC(xxINTEL, I82553),
+ MII_PHY_DESC(yyINTEL, I82553),
+ MII_PHY_DESC(yyINTEL, I82555),
+ MII_PHY_DESC(yyINTEL, I82562EM),
+ MII_PHY_DESC(yyINTEL, I82562ET),
MII_PHY_END
};
+static const struct mii_phy_funcs inphy_funcs = {
+ inphy_service,
+ inphy_status,
+ inphy_reset
+};
+
static int
inphy_probe(device_t dev)
{
@@ -98,37 +104,8 @@ inphy_probe(device_t dev)
static int
inphy_attach(device_t dev)
{
- struct mii_softc *sc;
- struct mii_attach_args *ma;
- struct mii_data *mii;
-
- sc = device_get_softc(dev);
- ma = device_get_ivars(dev);
- sc->mii_dev = device_get_parent(dev);
- mii = ma->mii_data;
- LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list);
-
- sc->mii_flags = miibus_get_flags(dev);
- sc->mii_inst = mii->mii_instance++;
- sc->mii_phy = ma->mii_phyno;
- sc->mii_service = inphy_service;
- sc->mii_pdata = mii;
-
- sc->mii_flags |= MIIF_NOMANPAUSE;
-
- ifmedia_add(&mii->mii_media,
- IFM_MAKEWORD(IFM_ETHER, IFM_100_TX, IFM_LOOP, sc->mii_inst),
- MII_MEDIA_100_TX, NULL);
-
- inphy_reset(sc);
-
- sc->mii_capabilities = PHY_READ(sc, MII_BMSR) & ma->mii_capmask;
- device_printf(dev, " ");
- mii_phy_add_media(sc);
- printf("\n");
-
- MIIBUS_MEDIAINIT(sc->mii_dev);
+ mii_phy_dev_attach(dev, MIIF_NOMANPAUSE, &inphy_funcs, 1);
return (0);
}
@@ -157,7 +134,7 @@ inphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
}
/* Update the media status. */
- inphy_status(sc);
+ PHY_STATUS(sc);
/* Callback if something changed. */
mii_phy_update(sc, cmd);
diff --git a/sys/dev/mii/ip1000phy.c b/sys/dev/mii/ip1000phy.c
index d8a5242..3d90e7e 100644
--- a/sys/dev/mii/ip1000phy.c
+++ b/sys/dev/mii/ip1000phy.c
@@ -57,12 +57,6 @@ __FBSDID("$FreeBSD$");
static int ip1000phy_probe(device_t);
static int ip1000phy_attach(device_t);
-struct ip1000phy_softc {
- struct mii_softc mii_sc;
- int model;
- int revision;
-};
-
static device_method_t ip1000phy_methods[] = {
/* device interface */
DEVMETHOD(device_probe, ip1000phy_probe),
@@ -87,11 +81,17 @@ static void ip1000phy_reset(struct mii_softc *);
static int ip1000phy_mii_phy_auto(struct mii_softc *, int);
static const struct mii_phydesc ip1000phys[] = {
- MII_PHY_DESC(ICPLUS, IP1000A),
- MII_PHY_DESC(ICPLUS, IP1001),
+ MII_PHY_DESC(xxICPLUS, IP1000A),
+ MII_PHY_DESC(xxICPLUS, IP1001),
MII_PHY_END
};
+static const struct mii_phy_funcs ip1000phy_funcs = {
+ ip1000phy_service,
+ ip1000phy_status,
+ ip1000phy_reset
+};
+
static int
ip1000phy_probe(device_t dev)
{
@@ -102,43 +102,16 @@ ip1000phy_probe(device_t dev)
static int
ip1000phy_attach(device_t dev)
{
- struct ip1000phy_softc *isc;
- struct mii_softc *sc;
struct mii_attach_args *ma;
- struct mii_data *mii;
+ u_int flags;
- isc = device_get_softc(dev);
- sc = &isc->mii_sc;
ma = device_get_ivars(dev);
- sc->mii_dev = device_get_parent(dev);
- mii = ma->mii_data;
- LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list);
-
- sc->mii_flags = miibus_get_flags(dev);
- sc->mii_inst = mii->mii_instance++;
- sc->mii_phy = ma->mii_phyno;
- sc->mii_service = ip1000phy_service;
- sc->mii_pdata = mii;
-
- sc->mii_flags |= MIIF_NOISOLATE | MIIF_NOMANPAUSE;
-
- isc->model = MII_MODEL(ma->mii_id2);
- isc->revision = MII_REV(ma->mii_id2);
- if (isc->model == MII_MODEL_ICPLUS_IP1000A &&
- strcmp(mii->mii_ifp->if_dname, "stge") == 0 &&
- (sc->mii_flags & MIIF_MACPRIV0) != 0)
- sc->mii_flags |= MIIF_PHYPRIV0;
-
- sc->mii_capabilities = PHY_READ(sc, MII_BMSR) & ma->mii_capmask;
- if (sc->mii_capabilities & BMSR_EXTSTAT)
- sc->mii_extcapabilities = PHY_READ(sc, MII_EXTSR);
- device_printf(dev, " ");
-
- ip1000phy_reset(sc);
- mii_phy_add_media(sc);
- printf("\n");
-
- MIIBUS_MEDIAINIT(sc->mii_dev);
+ flags = MIIF_NOISOLATE | MIIF_NOMANPAUSE;
+ if (MII_MODEL(ma->mii_id2) == MII_MODEL_xxICPLUS_IP1000A &&
+ strcmp(ma->mii_data->mii_ifp->if_dname, "stge") == 0 &&
+ (miibus_get_flags(dev) & MIIF_MACPRIV0) != 0)
+ flags |= MIIF_PHYPRIV0;
+ mii_phy_dev_attach(dev, flags, &ip1000phy_funcs, 0);
return (0);
}
@@ -160,7 +133,7 @@ ip1000phy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
break;
}
- ip1000phy_reset(sc);
+ PHY_RESET(sc);
switch (IFM_SUBTYPE(ife->ifm_media)) {
case IFM_AUTO:
(void)ip1000phy_mii_phy_auto(sc, ife->ifm_media);
@@ -245,7 +218,7 @@ done:
}
/* Update the media status. */
- ip1000phy_status(sc);
+ PHY_STATUS(sc);
/* Callback if something changed. */
mii_phy_update(sc, cmd);
@@ -255,12 +228,9 @@ done:
static void
ip1000phy_status(struct mii_softc *sc)
{
- struct ip1000phy_softc *isc;
struct mii_data *mii = sc->mii_pdata;
uint32_t bmsr, bmcr, stat;
- isc = (struct ip1000phy_softc *)sc;
-
mii->mii_media_status = IFM_AVALID;
mii->mii_media_active = IFM_ETHER;
@@ -281,7 +251,7 @@ ip1000phy_status(struct mii_softc *sc)
}
}
- if (isc->model == MII_MODEL_ICPLUS_IP1001) {
+ if (sc->mii_mpd_model == MII_MODEL_xxICPLUS_IP1001) {
stat = PHY_READ(sc, IP1000PHY_LSR);
switch (stat & IP1000PHY_LSR_SPEED_MASK) {
case IP1000PHY_LSR_SPEED_10:
@@ -339,12 +309,10 @@ ip1000phy_status(struct mii_softc *sc)
static int
ip1000phy_mii_phy_auto(struct mii_softc *sc, int media)
{
- struct ip1000phy_softc *isc;
uint32_t reg;
- isc = (struct ip1000phy_softc *)sc;
reg = 0;
- if (isc->model == MII_MODEL_ICPLUS_IP1001) {
+ if (sc->mii_mpd_model == MII_MODEL_xxICPLUS_IP1001) {
reg = PHY_READ(sc, IP1000PHY_MII_ANAR);
reg &= ~(IP1000PHY_ANAR_PAUSE | IP1000PHY_ANAR_APAUSE);
reg |= IP1000PHY_ANAR_NP;
diff --git a/sys/dev/mii/jmphy.c b/sys/dev/mii/jmphy.c
index 5659219..1e3eb55 100644
--- a/sys/dev/mii/jmphy.c
+++ b/sys/dev/mii/jmphy.c
@@ -56,13 +56,6 @@ static void jmphy_reset(struct mii_softc *);
static uint16_t jmphy_anar(struct ifmedia_entry *);
static int jmphy_setmedia(struct mii_softc *, struct ifmedia_entry *);
-struct jmphy_softc {
- struct mii_softc mii_sc;
- int mii_oui;
- int mii_model;
- int mii_rev;
-};
-
static device_method_t jmphy_methods[] = {
/* Device interface. */
DEVMETHOD(device_probe, jmphy_probe),
@@ -76,7 +69,7 @@ static devclass_t jmphy_devclass;
static driver_t jmphy_driver = {
"jmphy",
jmphy_methods,
- sizeof(struct jmphy_softc)
+ sizeof(struct mii_softc)
};
DRIVER_MODULE(jmphy, miibus, jmphy_driver, jmphy_devclass, 0, 0);
@@ -90,6 +83,12 @@ static const struct mii_phydesc jmphys[] = {
MII_PHY_END
};
+static const struct mii_phy_funcs jmphy_funcs = {
+ jmphy_service,
+ jmphy_status,
+ jmphy_reset
+};
+
static int
jmphy_probe(device_t dev)
{
@@ -100,46 +99,15 @@ jmphy_probe(device_t dev)
static int
jmphy_attach(device_t dev)
{
- struct jmphy_softc *jsc;
- struct mii_softc *sc;
struct mii_attach_args *ma;
- struct mii_data *mii;
- struct ifnet *ifp;
+ u_int flags;
- jsc = device_get_softc(dev);
- sc = &jsc->mii_sc;
ma = device_get_ivars(dev);
- sc->mii_dev = device_get_parent(dev);
- mii = ma->mii_data;
- LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list);
-
- sc->mii_flags = miibus_get_flags(dev);
- sc->mii_inst = mii->mii_instance++;
- sc->mii_phy = ma->mii_phyno;
- sc->mii_service = jmphy_service;
- sc->mii_pdata = mii;
-
- ifp = sc->mii_pdata->mii_ifp;
- if (strcmp(ifp->if_dname, "jme") == 0 &&
- (sc->mii_flags & MIIF_MACPRIV0) != 0)
- sc->mii_flags |= MIIF_PHYPRIV0;
- jsc->mii_oui = MII_OUI(ma->mii_id1, ma->mii_id2);
- jsc->mii_model = MII_MODEL(ma->mii_id2);
- jsc->mii_rev = MII_REV(ma->mii_id2);
- if (bootverbose)
- device_printf(dev, "OUI 0x%06x, model 0x%04x, rev. %d\n",
- jsc->mii_oui, jsc->mii_model, jsc->mii_rev);
-
- jmphy_reset(sc);
-
- sc->mii_capabilities = PHY_READ(sc, MII_BMSR) & ma->mii_capmask;
- if (sc->mii_capabilities & BMSR_EXTSTAT)
- sc->mii_extcapabilities = PHY_READ(sc, MII_EXTSR);
- device_printf(dev, " ");
- mii_phy_add_media(sc);
- printf("\n");
-
- MIIBUS_MEDIAINIT(sc->mii_dev);
+ flags = 0;
+ if (strcmp(ma->mii_data->mii_ifp->if_dname, "jme") == 0 &&
+ (miibus_get_flags(dev) & MIIF_MACPRIV0) != 0)
+ flags |= MIIF_PHYPRIV0;
+ mii_phy_dev_attach(dev, flags, &jmphy_funcs, 1);
return (0);
}
@@ -196,7 +164,7 @@ jmphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
}
/* Update the media status. */
- jmphy_status(sc);
+ PHY_STATUS(sc);
/* Callback if something changed. */
mii_phy_update(sc, cmd);
@@ -269,12 +237,9 @@ jmphy_status(struct mii_softc *sc)
static void
jmphy_reset(struct mii_softc *sc)
{
- struct jmphy_softc *jsc;
uint16_t t2cr, val;
int i;
- jsc = (struct jmphy_softc *)sc;
-
/* Disable sleep mode. */
PHY_WRITE(sc, JMPHY_TMCTL,
PHY_READ(sc, JMPHY_TMCTL) & ~JMPHY_TMCTL_SLEEP_ENB);
@@ -369,9 +334,6 @@ jmphy_setmedia(struct mii_softc *sc, struct ifmedia_entry *ife)
return (EINVAL);
}
- if ((ife->ifm_media & IFM_LOOP) != 0)
- bmcr |= BMCR_LOOP;
-
anar = jmphy_anar(ife);
if ((IFM_SUBTYPE(ife->ifm_media) == IFM_AUTO ||
(ife->ifm_media & IFM_FDX) != 0) &&
diff --git a/sys/dev/mii/lxtphy.c b/sys/dev/mii/lxtphy.c
index 44b40ff..f223ec6 100644
--- a/sys/dev/mii/lxtphy.c
+++ b/sys/dev/mii/lxtphy.c
@@ -106,6 +106,7 @@ DRIVER_MODULE(lxtphy, miibus, lxtphy_driver, lxtphy_devclass, 0, 0);
static int lxtphy_service(struct mii_softc *, struct mii_data *, int);
static void lxtphy_status(struct mii_softc *);
+static void lxtphy_reset(struct mii_softc *);
static void lxtphy_set_tp(struct mii_softc *);
static void lxtphy_set_fx(struct mii_softc *);
@@ -114,6 +115,12 @@ static const struct mii_phydesc lxtphys[] = {
MII_PHY_END
};
+static const struct mii_phy_funcs lxtphy_funcs = {
+ lxtphy_service,
+ lxtphy_status,
+ lxtphy_reset
+};
+
static int
lxtphy_probe(device_t dev)
{
@@ -125,27 +132,17 @@ static int
lxtphy_attach(device_t dev)
{
struct mii_softc *sc;
- struct mii_attach_args *ma;
- struct mii_data *mii;
sc = device_get_softc(dev);
- ma = device_get_ivars(dev);
- sc->mii_dev = device_get_parent(dev);
- mii = ma->mii_data;
- LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list);
- sc->mii_flags = miibus_get_flags(dev);
- sc->mii_inst = mii->mii_instance++;
- sc->mii_phy = ma->mii_phyno;
- sc->mii_service = lxtphy_service;
- sc->mii_pdata = mii;
+ mii_phy_dev_attach(dev, MIIF_NOMANPAUSE, &lxtphy_funcs, 0);
- mii_phy_reset(sc);
+ PHY_RESET(sc);
- sc->mii_capabilities = PHY_READ(sc, MII_BMSR) & ma->mii_capmask;
+ sc->mii_capabilities = PHY_READ(sc, MII_BMSR) & sc->mii_capmask;
device_printf(dev, " ");
-#define ADD(m, c) ifmedia_add(&mii->mii_media, (m), (c), NULL)
+#define ADD(m, c) ifmedia_add(&sc->mii_pdata->mii_media, (m), (c), NULL)
ADD(IFM_MAKEWORD(IFM_ETHER, IFM_100_FX, 0, sc->mii_inst),
MII_MEDIA_100_TX);
printf("100baseFX, ");
@@ -192,7 +189,7 @@ lxtphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
}
/* Update the media status. */
- lxtphy_status(sc);
+ PHY_STATUS(sc);
/* Callback if something changed. */
mii_phy_update(sc, cmd);
@@ -240,7 +237,8 @@ lxtphy_status(struct mii_softc *sc)
else
mii->mii_media_active |= IFM_10_T;
if (csr & CSR_DUPLEX)
- mii->mii_media_active |= IFM_FDX;
+ mii->mii_media_active |=
+ IFM_FDX | mii_phy_flowstatus(sc);
else
mii->mii_media_active |= IFM_HDX;
} else
@@ -248,6 +246,15 @@ lxtphy_status(struct mii_softc *sc)
}
static void
+lxtphy_reset(struct mii_softc *sc)
+{
+
+ mii_phy_reset(sc);
+ PHY_WRITE(sc, MII_LXTPHY_IER,
+ PHY_READ(sc, MII_LXTPHY_IER) & ~IER_INTEN);
+}
+
+static void
lxtphy_set_tp(struct mii_softc *sc)
{
int cfg;
diff --git a/sys/dev/mii/mii.c b/sys/dev/mii/mii.c
index 8485691..fbdd0ea 100644
--- a/sys/dev/mii/mii.c
+++ b/sys/dev/mii/mii.c
@@ -44,7 +44,7 @@ __FBSDID("$FreeBSD$");
#include <sys/socket.h>
#include <sys/malloc.h>
#include <sys/module.h>
-#include <sys/bus.h>
+#include <sys/bus.h>
#include <net/if.h>
#include <net/if_media.h>
@@ -69,6 +69,7 @@ static int miibus_writereg(device_t, int, int, int);
static void miibus_statchg(device_t);
static void miibus_linkchg(device_t);
static void miibus_mediainit(device_t);
+static unsigned char mii_bitreverse(unsigned char x);
static device_method_t miibus_methods[] = {
/* device interface */
@@ -87,9 +88,9 @@ static device_method_t miibus_methods[] = {
/* MII interface */
DEVMETHOD(miibus_readreg, miibus_readreg),
DEVMETHOD(miibus_writereg, miibus_writereg),
- DEVMETHOD(miibus_statchg, miibus_statchg),
- DEVMETHOD(miibus_linkchg, miibus_linkchg),
- DEVMETHOD(miibus_mediainit, miibus_mediainit),
+ DEVMETHOD(miibus_statchg, miibus_statchg),
+ DEVMETHOD(miibus_linkchg, miibus_linkchg),
+ DEVMETHOD(miibus_mediainit, miibus_mediainit),
{ 0, 0 }
};
@@ -265,7 +266,7 @@ miibus_linkchg(device_t 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;
@@ -361,7 +362,7 @@ mii_attach(device_t dev, device_t *miibus, struct ifnet *ifp,
* has been allocated.
*/
ma.mii_data = device_get_softc(*miibus);
- }
+ }
ma.mii_capmask = capmask;
@@ -392,7 +393,7 @@ mii_attach(device_t dev, device_t *miibus, struct ifnet *ifp,
* Check to see if there is a PHY at this address. Note,
* many braindead PHYs report 0/0 in their ID registers,
* so we test for media in the BMSR.
- */
+ */
bmsr = MIIBUS_READREG(dev, ma.mii_phyno, MII_BMSR);
if (bmsr == 0 || bmsr == 0xffff ||
(bmsr & (BMSR_EXTSTAT | BMSR_MEDIAMASK)) == 0) {
@@ -411,10 +412,11 @@ mii_attach(device_t dev, device_t *miibus, struct ifnet *ifp,
* Extract the IDs. Braindead PHYs will be handled by
* the `ukphy' driver, as we have no ID information to
* match on.
- */
+ */
ma.mii_id1 = MIIBUS_READREG(dev, ma.mii_phyno, MII_PHYIDR1);
ma.mii_id2 = MIIBUS_READREG(dev, ma.mii_phyno, MII_PHYIDR2);
+ ma.mii_offset = offset;
args = malloc(sizeof(struct mii_attach_args), M_DEVBUF,
M_NOWAIT);
if (args == NULL)
@@ -486,7 +488,7 @@ mii_mediachg(struct mii_data *mii)
BMCR_ISO);
continue;
}
- rv = (*child->mii_service)(child, mii, MII_MEDIACHG);
+ rv = PHY_SERVICE(child, mii, MII_MEDIACHG);
if (rv)
return (rv);
}
@@ -509,7 +511,7 @@ mii_tick(struct mii_data *mii)
*/
if (IFM_INST(ife->ifm_media) != child->mii_inst)
continue;
- (void)(*child->mii_service)(child, mii, MII_TICK);
+ (void)PHY_SERVICE(child, mii, MII_TICK);
}
}
@@ -531,7 +533,7 @@ mii_pollstat(struct mii_data *mii)
*/
if (IFM_INST(ife->ifm_media) != child->mii_inst)
continue;
- (void)(*child->mii_service)(child, mii, MII_POLLSTAT);
+ (void)PHY_SERVICE(child, mii, MII_POLLSTAT);
}
}
@@ -546,3 +548,25 @@ mii_down(struct mii_data *mii)
LIST_FOREACH(child, &mii->mii_phys, mii_list)
mii_phy_down(child);
}
+
+static unsigned char
+mii_bitreverse(unsigned char x)
+{
+ static unsigned char nibbletab[16] = {
+ 0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15
+ };
+
+ return ((nibbletab[x & 15] << 4) | nibbletab[x >> 4]);
+}
+
+u_int
+mii_oui(u_int id1, u_int id2)
+{
+ u_int h;
+
+ h = (id1 << 6) | (id2 >> 10);
+
+ return ((mii_bitreverse(h >> 16) << 16) |
+ (mii_bitreverse((h >> 8) & 0xff) << 8) |
+ mii_bitreverse(h & 0xff));
+}
diff --git a/sys/dev/mii/mii.h b/sys/dev/mii/mii.h
index 1d887d2..668fb8f 100644
--- a/sys/dev/mii/mii.h
+++ b/sys/dev/mii/mii.h
@@ -89,15 +89,9 @@
* info available in register 15, but 802.3 section 22.2.4.3 also
* states that that all 1000 Mb/s capable PHYs will set this bit to 1.
*/
-#if 0
-#define BMSR_MEDIAMASK (BMSR_100T4|BMSR_100TXFDX|BMSR_100TXHDX|BMSR_10TFDX| \
- BMSR_10THDX|BMSR_ANEG)
-#else
-/* NetBSD uses: */
#define BMSR_MEDIAMASK (BMSR_100T4|BMSR_100TXFDX|BMSR_100TXHDX| \
BMSR_10TFDX|BMSR_10THDX|BMSR_100T2FDX|BMSR_100T2HDX)
-#endif
/*
* Convert BMSR media capabilities to ANAR bits for autonegotiation.
@@ -112,10 +106,6 @@
#define IDR2_MODEL 0x03f0 /* vendor model */
#define IDR2_REV 0x000f /* vendor revision */
-#define MII_OUI(id1, id2) (((id1) << 6) | ((id2) >> 10))
-#define MII_MODEL(id2) (((id2) & IDR2_MODEL) >> 4)
-#define MII_REV(id2) ((id2) & IDR2_REV)
-
#define MII_ANAR 0x04 /* Autonegotiation advertisement (rw) */
/* section 28.2.4.1 and 37.2.6.1 */
#define ANAR_NP 0x8000 /* Next page (ro) */
diff --git a/sys/dev/mii/mii_physubr.c b/sys/dev/mii/mii_physubr.c
index caba52d..b3013ba 100644
--- a/sys/dev/mii/mii_physubr.c
+++ b/sys/dev/mii/mii_physubr.c
@@ -150,9 +150,6 @@ mii_phy_setmedia(struct mii_softc *sc)
}
}
- if ((ife->ifm_media & IFM_LOOP) != 0)
- bmcr |= BMCR_LOOP;
-
PHY_WRITE(sc, MII_ANAR, anar);
PHY_WRITE(sc, MII_BMCR, bmcr);
if ((sc->mii_flags & MIIF_HAVE_GTCR) != 0)
@@ -251,7 +248,7 @@ mii_phy_tick(struct mii_softc *sc)
return (EJUSTRETURN);
sc->mii_ticks = 0;
- mii_phy_reset(sc);
+ PHY_RESET(sc);
mii_phy_auto(sc);
return (0);
}
@@ -332,9 +329,11 @@ mii_phy_add_media(struct mii_softc *sc)
#define ADD(m, c) ifmedia_add(&mii->mii_media, (m), (c), NULL)
#define PRINT(s) printf("%s%s", sep, s); sep = ", "
- if ((sc->mii_flags & MIIF_NOISOLATE) == 0)
+ if ((sc->mii_flags & MIIF_NOISOLATE) == 0) {
ADD(IFM_MAKEWORD(IFM_ETHER, IFM_NONE, 0, sc->mii_inst),
MII_MEDIA_NONE);
+ PRINT("none");
+ }
/*
* There are different interpretations for the bits in
@@ -521,6 +520,50 @@ mii_phy_dev_probe(device_t dev, const struct mii_phydesc *mpd, int mrv)
return (ENXIO);
}
+void
+mii_phy_dev_attach(device_t dev, u_int flags, const struct mii_phy_funcs *mpf,
+ int add_media)
+{
+ struct mii_softc *sc;
+ struct mii_attach_args *ma;
+ struct mii_data *mii;
+
+ sc = device_get_softc(dev);
+ ma = device_get_ivars(dev);
+ sc->mii_dev = device_get_parent(dev);
+ mii = ma->mii_data;
+ LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list);
+
+ sc->mii_flags = flags | miibus_get_flags(dev);
+ sc->mii_mpd_oui = MII_OUI(ma->mii_id1, ma->mii_id2);
+ sc->mii_mpd_model = MII_MODEL(ma->mii_id2);
+ sc->mii_mpd_rev = MII_REV(ma->mii_id2);
+ sc->mii_capmask = ma->mii_capmask;
+ sc->mii_inst = mii->mii_instance++;
+ sc->mii_phy = ma->mii_phyno;
+ sc->mii_offset = ma->mii_offset;
+ sc->mii_funcs = mpf;
+ sc->mii_pdata = mii;
+
+ if (bootverbose)
+ device_printf(dev, "OUI 0x%06x, model 0x%04x, rev. %d\n",
+ sc->mii_mpd_oui, sc->mii_mpd_model, sc->mii_mpd_rev);
+
+ if (add_media == 0)
+ return;
+
+ PHY_RESET(sc);
+
+ sc->mii_capabilities = PHY_READ(sc, MII_BMSR) & sc->mii_capmask;
+ if (sc->mii_capabilities & BMSR_EXTSTAT)
+ sc->mii_extcapabilities = PHY_READ(sc, MII_EXTSR);
+ device_printf(dev, " ");
+ mii_phy_add_media(sc);
+ printf("\n");
+
+ MIIBUS_MEDIAINIT(sc->mii_dev);
+}
+
/*
* Return the flow control status flag from MII_ANAR & MII_ANLPAR.
*/
diff --git a/sys/dev/mii/miidevs b/sys/dev/mii/miidevs
index 0f2230b..7532b29 100644
--- a/sys/dev/mii/miidevs
+++ b/sys/dev/mii/miidevs
@@ -1,5 +1,5 @@
$FreeBSD$
-/*$NetBSD: miidevs,v 1.6 1999/05/14 11:37:30 drochner Exp $*/
+/*$NetBSD: miidevs,v 1.99 2011/01/26 18:39:04 bouyer Exp $*/
/*-
* Copyright (c) 1998, 1999 The NetBSD Foundation, Inc.
@@ -35,69 +35,77 @@ $FreeBSD$
* List of known MII OUIs.
* For a complete list see http://standards.ieee.org/regauth/oui/
*
- * XXX Vendors do obviously not agree how OUIs (18 bit) are mapped
- * to the 16 bits available in the id registers. The MII_OUI() macro
- * in "mii.h" reflects the most obvious way. If a vendor uses a
- * different mapping, an "xx" prefixed OUI is defined here which is
- * mangled accordingly to compensate.
+ * XXX Vendors do obviously not agree how OUIs (24 bit) are mapped
+ * to the 22 bits available in the id registers.
+ * IEEE 802.3u-1995, subclause 22.2.4.3.1, figure 22-12, depicts the right
+ * mapping; the bit positions are defined in IEEE 802-1990, figure 5.2.
+ * (There is a formal 802.3 interpretation, number 1-07/98 of July 09 1998,
+ * about this.)
+ * The MII_OUI() macro in "mii.h" reflects this.
+ * If a vendor uses a different mapping, an "xx" prefixed OUI is defined here
+ * which is mangled accordingly to compensate.
*/
-oui AGERE 0x00a0bc Agere Systems
+oui AGERE 0x00053d Agere Systems
oui ALTIMA 0x0010a9 Altima Communications
oui AMD 0x00001a Advanced Micro Devices
-oui ASIX 0x00602e Asix Semiconductor
-oui ATHEROS 0x001374 Atheros Communications
oui BROADCOM 0x001018 Broadcom Corporation
oui BROADCOM2 0x000af7 Broadcom Corporation
+oui BROADCOM3 0x001be9 Broadcom Corporation
oui CICADA 0x0003F1 Cicada Semiconductor
oui DAVICOM 0x00606e Davicom Semiconductor
+oui ENABLESEMI 0x0010dd Enable Semiconductor
oui ICPLUS 0x0090c3 IC Plus Corp.
oui ICS 0x00a0be Integrated Circuit Systems
-oui INTEL 0x00aa00 Intel
-oui JATO 0x00e083 Jato Technologies
-oui JMICRON 0x001b8c JMicron Technologies
+oui INTEL 0x00aa00 Intel Corporation
+oui JMICRON 0x00d831 JMicron Technologies
oui LEVEL1 0x00207b Level 1
+oui MARVELL 0x005043 Marvell Semiconductor
+oui MYSON 0x00c0b4 Myson Technology
oui NATSEMI 0x080017 National Semiconductor
+oui PMCSIERRA 0x00e004 PMC-Sierra
oui QUALSEMI 0x006051 Quality Semiconductor
-oui RDC 0x000bb4 RDC Semiconductor
-oui REALTEK 0x000020 RealTek Semicondctor
-oui SEEQ 0x00a07d Seeq
+oui RDC 0x00d02d RDC Semiconductor
+oui REALTEK 0x00e04c RealTek Semicondctor
+oui SEEQ 0x00a07d Seeq Technology
oui SIS 0x00e006 Silicon Integrated Systems
-oui SMSC 0x0005be SMSC
-oui TDK 0x00c039 TDK
oui TI 0x080028 Texas Instruments
-oui VITESSE 0x0001c1 Vitesse Semiconductor
+oui TSC 0x00c039 TDK Semiconductor
oui XAQTI 0x00e0ae XaQti Corp.
-oui MARVELL 0x005043 Marvell Semiconductor
-oui xxMARVELL 0x000ac2 Marvell Semiconductor
-/* in the 79c873, AMD uses another OUI (which matches Davicom!) */
-oui xxAMD 0x00606e Advanced Micro Devices
+/* Some Intel 82553's use an alternative OUI. */
+oui xxINTEL 0x001f00 Intel Corporation
-/* Intel 82553 A/B steppings */
-oui xxINTEL 0x00f800 Intel
+/* Some VIA 6122's use an alternative OUI. */
+oui xxCICADA 0x00c08f Cicada Semiconductor
-/* some vendors have the bits swapped within bytes
- (ie, ordered as on the wire) */
-oui xxALTIMA 0x000895 Altima Communications
+/* bad bitorder (bits "g" and "h" (= MSBs byte 1) lost) */
+oui yyAMD 0x000058 Advanced Micro Devices
+oui xxATHEROS 0x00c82e Atheros Communications
oui xxBROADCOM 0x000818 Broadcom Corporation
oui xxBROADCOM_ALT1 0x0050ef Broadcom Corporation
-oui xxBROADCOM_ALT2 0x00d897 Broadcom Corporation
-oui xxICS 0x00057d Integrated Circuit Systems
-oui xxSEEQ 0x0005be Seeq
-oui xxSIS 0x000760 Silicon Integrated Systems
-oui xxTI 0x100014 Texas Instruments
-oui xxXAQTI 0x350700 XaQti Corp.
+oui xxDAVICOM 0x000676 Davicom Semiconductor
+oui yyINTEL 0x005500 Intel Corporation
+oui xxJATO 0x0007c1 Jato Technologies
+oui xxMARVELL 0x000ac2 Marvell Semiconductor
+oui xxMYSON 0x00032d Myson Technology
+oui xxNATSEMI 0x1000e8 National Semiconductor
+oui xxQUALSEMI 0x00068a Quality Semiconductor
+oui xxTSC 0x00039c TDK Semiconductor
+oui xxVITESSE 0x008083 Vitesse Semiconductor
-/* Level 1 is completely different - from right to left.
- (Two bits get lost in the third OUI byte.) */
-oui xxLEVEL1 0x1e0400 Level 1
+/* bad byteorder (bits "q" and "r" (= LSBs byte 3) lost) */
+oui xxLEVEL1 0x782000 Level 1
+oui xxXAQTI 0xace000 XaQti Corp.
/* Don't know what's going on here. */
-oui xxDAVICOM 0x006040 Davicom Semiconductor
-
-/* This is the OUI of the gigE PHY in the RealTek 8169S/8110S/8211B chips */
-oui xxREALTEK 0x000732
+oui xxASIX 0x000674 Asix Semiconductor
+oui yyDAVICOM 0x000602 Davicom Semiconductor
+oui xxICPLUS 0x0009c3 IC Plus Corp.
+oui xxPMCSIERRA 0x0009c0 PMC-Sierra
+oui xxPMCSIERRA2 0x009057 PMC-Sierra
+oui xxREALTEK 0x000732 RealTek Semicondctor
+oui yyREALTEK 0x000004 RealTek Semicondctor
/*
* List of known models. Grouped by oui.
@@ -108,93 +116,109 @@ model AGERE ET1011 0x0001 ET1011 10/100/1000baseT PHY
model AGERE ET1011C 0x0004 ET1011C 10/100/1000baseT PHY
/* Altima Communications PHYs */
-model xxALTIMA AC101 0x0021 AC101 10/100 media interface
-model xxALTIMA AC101L 0x0012 AC101L 10/100 media interface
-model xxALTIMA ACXXX 0x0001 ACXXX 10/100 media interface
+model ALTIMA ACXXX 0x0001 ACXXX 10/100 media interface
+model ALTIMA AC101L 0x0012 AC101L 10/100 media interface
+model ALTIMA AC101 0x0021 AC101 10/100 media interface
+/* AMD Am79C87[45] have ALTIMA OUI */
+model ALTIMA Am79C875 0x0014 Am79C875 10/100 media interface
+model ALTIMA Am79C874 0x0021 Am79C874 10/100 media interface
/* Advanced Micro Devices PHYs */
-model AMD 79c973phy 0x0036 Am79c973 internal PHY
-model AMD 79c978 0x0039 Am79c978 HomePNA PHY
-model xxAMD 79C873 0x0000 Am79C873/DM9101 10/100 media interface
-
-/* Asix semiconductor PHYs. */
-model ASIX AX88X9X 0x0031 Ax88x9x internal PHY
-
-/* Atheros Communications/Attansic PHYs. */
-model ATHEROS F1 0x0001 Atheros F1 10/100/1000 PHY
-model ATHEROS F2 0x0002 Atheros F2 10/100 PHY
-model ATHEROS F1_7 0x0007 Atheros F1 10/100/1000 PHY
-
-/* Broadcom Corp. PHYs. */
-model BROADCOM 3C905B 0x0012 3c905B 10/100 internal PHY
-model BROADCOM 3C905C 0x0017 3c905C 10/100 internal PHY
-model BROADCOM BCM5201 0x0021 BCM5201 10/100baseTX PHY
-model BROADCOM BCM5214 0x0028 BCM5214 Quad 10/100 PHY
-model BROADCOM BCM5221 0x001e BCM5221 10/100baseTX PHY
-model BROADCOM BCM5222 0x0032 BCM5222 Dual 10/100 PHY
-model BROADCOM BCM4401 0x0036 BCM4401 10/100baseTX PHY
-model xxBROADCOM BCM5400 0x0004 Broadcom 1000baseTX PHY
-model xxBROADCOM BCM5401 0x0005 BCM5401 10/100/1000baseTX PHY
-model xxBROADCOM BCM5411 0x0007 BCM5411 10/100/1000baseTX PHY
-model xxBROADCOM BCM5754 0x000e BCM5754 10/100/1000baseTX PHY
-model xxBROADCOM BCM5752 0x0010 BCM5752 10/100/1000baseTX PHY
-model xxBROADCOM BCM5701 0x0011 BCM5701 10/100/1000baseTX PHY
-model xxBROADCOM BCM5706 0x0015 BCM5706 10/100/1000baseTX/SX PHY
-model xxBROADCOM BCM5703 0x0016 BCM5703 10/100/1000baseTX PHY
-model xxBROADCOM BCM5704 0x0019 BCM5704 10/100/1000baseTX PHY
-model xxBROADCOM BCM5705 0x001a BCM5705 10/100/1000baseTX PHY
-model xxBROADCOM BCM5750 0x0018 BCM5750 10/100/1000baseTX PHY
-model xxBROADCOM BCM54K2 0x002e BCM54K2 10/100/1000baseTX PHY
-model xxBROADCOM BCM5714 0x0034 BCM5714 10/100/1000baseTX PHY
-model xxBROADCOM BCM5780 0x0035 BCM5780 10/100/1000baseTX PHY
-model xxBROADCOM BCM5708C 0x0036 BCM5708C 10/100/1000baseTX PHY
-model xxBROADCOM_ALT1 BCM5482S 0x000b BCM5482S Dual-Port 10/100/1000baseX/FX PHY
-model xxBROADCOM_ALT1 BCM5755 0x000c BCM5755 10/100/1000baseTX PHY
-model xxBROADCOM_ALT1 BCM5787 0x000e BCM5787 10/100/1000baseTX PHY
-model xxBROADCOM_ALT1 BCM5708S 0x0015 BCM5708S 1000/2500BaseSX PHY
-model xxBROADCOM_ALT1 BCM5709CAX 0x002c BCM5709C(AX) 10/100/1000baseTX PHY
-model xxBROADCOM_ALT1 BCM5722 0x002d BCM5722 10/100/1000baseTX PHY
-model xxBROADCOM_ALT1 BCM5784 0x003a BCM5784 10/100/1000baseTX PHY
-model xxBROADCOM_ALT1 BCM5709C 0x003c BCM5709C 10/100/1000baseTX PHY
-model xxBROADCOM_ALT1 BCM5761 0x003d BCM5761 10/100/1000baseTX PHY
-model xxBROADCOM_ALT1 BCM5709S 0x003f BCM5709S 1000/2500baseSX PHY
-model xxBROADCOM_ALT2 BCM5717C 0x0020 BCM5717C 10/100/1000baseTX PHY
-model xxBROADCOM_ALT2 BCM57765 0x0024 BCM57765 10/100/1000baseTX PHY
-model BROADCOM2 BCM5906 0x0004 BCM5906 10/100baseTX PHY
+/* see Davicom DM9101 for Am79C873 */
+model yyAMD 79C972_10T 0x0001 Am79C972 internal 10BASE-T interface
+model yyAMD 79c973phy 0x0036 Am79C973 internal 10/100 media interface
+model yyAMD 79c901 0x0037 Am79C901 10BASE-T interface
+model yyAMD 79c901home 0x0039 Am79C901 HomePNA 1.0 interface
+
+/* Atheros Communications/Attansic PHYs */
+model xxATHEROS F1 0x0001 Atheros F1 10/100/1000 PHY
+model xxATHEROS F2 0x0002 Atheros F2 10/100 PHY
+model xxATHEROS F1_7 0x0007 Atheros F1 10/100/1000 PHY
+
+/* Asix semiconductor PHYs */
+model xxASIX AX88X9X 0x0031 Ax88x9x internal PHY
+
+/* Broadcom Corp. PHYs */
+model xxBROADCOM 3C905B 0x0012 Broadcom 3c905B internal PHY
+model xxBROADCOM 3C905C 0x0017 Broadcom 3c905C internal PHY
+model xxBROADCOM BCM5201 0x0021 BCM5201 10/100 media interface
+model xxBROADCOM BCM5214 0x0028 BCM5214 Quad 10/100 media interface
+model xxBROADCOM BCM5221 0x001e BCM5221 10/100 media interface
+model xxBROADCOM BCM5222 0x0032 BCM5222 Dual 10/100 media interface
+model xxBROADCOM BCM4401 0x0036 BCM4401 10/100 media interface
+model BROADCOM BCM5400 0x0004 BCM5400 1000BASE-T media interface
+model BROADCOM BCM5401 0x0005 BCM5401 1000BASE-T media interface
+model BROADCOM BCM5411 0x0007 BCM5411 1000BASE-T media interface
+model BROADCOM BCM5464 0x000b BCM5464 1000BASE-T media interface
+model BROADCOM BCM5461 0x000c BCM5461 1000BASE-T media interface
+model BROADCOM BCM5462 0x000d BCM5462 1000BASE-T media interface
+model BROADCOM BCM5421 0x000e BCM5421 1000BASE-T media interface
+model BROADCOM BCM5752 0x0010 BCM5752 1000BASE-T media interface
+model BROADCOM BCM5701 0x0011 BCM5701 1000BASE-T media interface
+model BROADCOM BCM5706 0x0015 BCM5706 1000BASE-T/SX media interface
+model BROADCOM BCM5703 0x0016 BCM5703 1000BASE-T media interface
+model BROADCOM BCM5750 0x0018 BCM5750 1000BASE-T media interface
+model BROADCOM BCM5704 0x0019 BCM5704 1000BASE-T media interface
+model BROADCOM BCM5705 0x001a BCM5705 1000BASE-T media interface
+model BROADCOM BCM54K2 0x002e BCM54K2 1000BASE-T media interface
+model BROADCOM BCM5714 0x0034 BCM5714 1000BASE-T media interface
+model BROADCOM BCM5780 0x0035 BCM5780 1000BASE-T media interface
+model BROADCOM BCM5708C 0x0036 BCM5708C 1000BASE-T media interface
+model BROADCOM2 BCM5906 0x0004 BCM5906 10/100baseTX media interface
+model BROADCOM2 BCM5481 0x000a BCM5481 1000BASE-T media interface
+model BROADCOM2 BCM5482 0x000b BCM5482 1000BASE-T media interface
+model BROADCOM2 BCM5755 0x000c BCM5755 1000BASE-T media interface
+model BROADCOM2 BCM5754 0x000e BCM5754/5787 1000BASE-T media interface
+model BROADCOM2 BCM5708S 0x0015 BCM5708S 1000/2500baseSX PHY
+model BROADCOM2 BCM5709CAX 0x002c BCM5709CAX 10/100/1000baseT PHY
+model BROADCOM2 BCM5722 0x002d BCM5722 1000BASE-T media interface
+model BROADCOM2 BCM5784 0x003a BCM5784 10/100/1000baseT PHY
+model BROADCOM2 BCM5709C 0x003c BCM5709 10/100/1000baseT PHY
+model BROADCOM2 BCM5761 0x003d BCM5761 10/100/1000baseT PHY
+model BROADCOM2 BCM5709S 0x003f BCM5709S 1000/2500baseSX PHY
+model BROADCOM3 BCM5717C 0x0020 BCM5717C 1000BASE-T media interface
+model BROADCOM3 BCM57765 0x0024 BCM57765 1000BASE-T media interface
+model xxBROADCOM_ALT1 BCM5906 0x0004 BCM5906 10/100baseTX media interface
/* Cicada Semiconductor PHYs (now owned by Vitesse?) */
-model CICADA CS8201 0x0001 Cicada CS8201 10/100/1000TX PHY
-model CICADA CS8204 0x0004 Cicada CS8204 10/100/1000TX PHY
-model CICADA VSC8211 0x000b Cicada VSC8211 10/100/1000TX PHY
-model CICADA CS8201A 0x0020 Cicada CS8201 10/100/1000TX PHY
-model CICADA CS8201B 0x0021 Cicada CS8201 10/100/1000TX PHY
-model CICADA CS8244 0x002c Cicada CS8244 10/100/1000TX PHY
-model VITESSE VSC8601 0x0002 Vitesse VSC8601 10/100/1000TX PHY
+model xxCICADA CS8201 0x0001 Cicada CS8201 10/100/1000TX PHY
+model xxCICADA CS8204 0x0004 Cicada CS8204 10/100/1000TX PHY
+model xxCICADA VSC8211 0x000b Cicada VSC8211 10/100/1000TX PHY
+model xxCICADA CS8201A 0x0020 Cicada CS8201 10/100/1000TX PHY
+model xxCICADA CS8201B 0x0021 Cicada CS8201 10/100/1000TX PHY
+model xxCICADA CS8244 0x002c Cicada CS8244 10/100/1000TX PHY
+model xxVITESSE VSC8601 0x0002 Vitesse VSC8601 10/100/1000TX PHY
/* Davicom Semiconductor PHYs */
-model DAVICOM DM9102 0x0004 DM9102 10/100 media interface
-model xxDAVICOM DM9101 0x0000 DM9101 10/100 media interface
-
-/* Integrated Circuit Systems PHYs */
-model xxICS 1889 0x0001 ICS1889 10/100 media interface
-model xxICS 1890 0x0002 ICS1890 10/100 media interface
-model xxICS 1892 0x0003 ICS1892 10/100 media interface
-model xxICS 1893 0x0004 ICS1893 10/100 media interface
+/* AMD Am79C873 seems to be a relabeled DM9101 */
+model xxDAVICOM DM9101 0x0000 DM9101 (AMD Am79C873) 10/100 media interface
+model xxDAVICOM DM9102 0x0004 DM9102 10/100 media interface
+model yyDAVICOM DM9101 0x0000 DM9101 10/100 media interface
/* IC Plus Corp. PHYs */
-model ICPLUS IP101 0x0005 IC Plus 10/100 PHY
-model ICPLUS IP1000A 0x0008 IC Plus 10/100/1000 media interface
-model ICPLUS IP1001 0x0019 IC Plus IP1001 10/100/1000 media interface
+model xxICPLUS IP101 0x0005 IP101 10/100 PHY
+model xxICPLUS IP1000A 0x0008 IP100A 10/100/1000 media interface
+model xxICPLUS IP1001 0x0019 IP1001 10/100/1000 media interface
-/* Intel PHYs */
-model xxINTEL I82553AB 0x0000 i83553 10/100 media interface
-model INTEL I82555 0x0015 i82555 10/100 media interface
-model INTEL I82562EM 0x0032 i82562EM 10/100 media interface
-model INTEL I82562ET 0x0033 i82562ET 10/100 media interface
-model INTEL I82553C 0x0035 i82553 10/100 media interface
+/* Integrated Circuit Systems PHYs */
+model ICS 1889 0x0001 ICS1889 10/100 media interface
+model ICS 1890 0x0002 ICS1890 10/100 media interface
+model ICS 1892 0x0003 ICS1892 10/100 media interface
+model ICS 1893 0x0004 ICS1893 10/100 media interface
+
+/* Intel Corporation PHYs */
+model xxINTEL I82553 0x0000 i82553 10/100 media interface
+model yyINTEL I82555 0x0015 i82555 10/100 media interface
+model yyINTEL I82562EH 0x0017 i82562EH HomePNA interface
+model yyINTEL I82562G 0x0031 i82562G 10/100 media interface
+model yyINTEL I82562EM 0x0032 i82562EM 10/100 media interface
+model yyINTEL I82562ET 0x0033 i82562ET 10/100 media interface
+model yyINTEL I82553 0x0035 i82553 10/100 media interface
+model yyINTEL I82566 0x0039 i82566 10/100/1000 media interface
+model INTEL I82577 0x0005 i82577 10/100/1000 media interface
/* Jato Technologies PHYs */
-model JATO BASEX 0x0000 Jato 1000baseX media interface
+model xxJATO BASEX 0x0000 Jato 1000baseX media interface
/* JMicron Technologies PHYs */
model JMICRON JMP211 0x0021 JMP211 10/100/1000 media interface
@@ -202,66 +226,79 @@ model JMICRON JMP202 0x0022 JMP202 10/100 media interface
/* Level 1 PHYs */
model xxLEVEL1 LXT970 0x0000 LXT970 10/100 media interface
+model LEVEL1 LXT971 0x000e LXT971/2 10/100 media interface
+model LEVEL1 LXT973 0x0021 LXT973 10/100 Dual PHY
+model LEVEL1 LXT974 0x0004 LXT974 10/100 Quad PHY
+model LEVEL1 LXT975 0x0005 LXT975 10/100 Quad PHY
+model LEVEL1 LXT1000_OLD 0x0003 LXT1000 1000BASE-T media interface
+model LEVEL1 LXT1000 0x000c LXT1000 1000BASE-T media interface
+
+/* Marvell Semiconductor PHYs */
+model xxMARVELL E1000 0x0000 Marvell 88E1000 Gigabit PHY
+model xxMARVELL E1011 0x0002 Marvell 88E1011 Gigabit PHY
+model xxMARVELL E1000_3 0x0003 Marvell 88E1000 Gigabit PHY
+model xxMARVELL E1000S 0x0004 Marvell 88E1000S Gigabit PHY
+model xxMARVELL E1000_5 0x0005 Marvell 88E1000 Gigabit PHY
+model xxMARVELL E1101 0x0006 Marvell 88E1101 Gigabit PHY
+model xxMARVELL E3082 0x0008 Marvell 88E3082 10/100 Fast Ethernet PHY
+model xxMARVELL E1112 0x0009 Marvell 88E1112 Gigabit PHY
+model xxMARVELL E1149 0x000b Marvell 88E1149 Gigabit PHY
+model xxMARVELL E1111 0x000c Marvell 88E1111 Gigabit PHY
+model xxMARVELL E1116 0x0021 Marvell 88E1116 Gigabit PHY
+model xxMARVELL E1116R 0x0024 Marvell 88E1116R Gigabit PHY
+model xxMARVELL E1118 0x0022 Marvell 88E1118 Gigabit PHY
+model xxMARVELL E3016 0x0026 Marvell 88E3016 10/100 Fast Ethernet PHY
+model xxMARVELL PHYG65G 0x0027 Marvell PHYG65G Gigabit PHY
+model MARVELL E1000 0x0005 Marvell 88E1000 Gigabit PHY
+model MARVELL E1011 0x0002 Marvell 88E1011 Gigabit PHY
+model MARVELL E1000_3 0x0003 Marvell 88E1000 Gigabit PHY
+model MARVELL E1000_5 0x0005 Marvell 88E1000 Gigabit PHY
+model MARVELL E1111 0x000c Marvell 88E1111 Gigabit PHY
/* National Semiconductor PHYs */
-model NATSEMI DP83840 0x0000 DP83840 10/100 media interface
-model NATSEMI DP83843 0x0001 DP83843 10/100 media interface
-model NATSEMI DP83815 0x0002 DP83815 10/100 media interface
-model NATSEMI DP83847 0x0003 DP83847 10/100 media interface
-model NATSEMI DP83891 0x0005 DP83891 10/100/1000 media interface
-model NATSEMI DP83861 0x0006 DP83861 10/100/1000 media interface
-model NATSEMI DP83865 0x0007 DP83865 10/100/1000 media interface
+model xxNATSEMI DP83840 0x0000 DP83840 10/100 media interface
+model xxNATSEMI DP83843 0x0001 DP83843 10/100 media interface
+model xxNATSEMI DP83815 0x0002 DP83815 10/100 media interface
+model xxNATSEMI DP83847 0x0003 DP83847 10/100 media interface
+model xxNATSEMI DP83891 0x0005 DP83891 1000BASE-T media interface
+model xxNATSEMI DP83861 0x0006 DP83861 1000BASE-T media interface
+model xxNATSEMI DP83865 0x0007 DP83865 1000BASE-T media interface
+
+/* PMC Sierra PHYs */
+model xxPMCSIERRA PM8351 0x0000 PM8351 OctalPHY Gigabit interface
+model xxPMCSIERRA2 PM8352 0x0002 PM8352 OctalPHY Gigabit interface
+model xxPMCSIERRA2 PM8353 0x0003 PM8353 QuadPHY Gigabit interface
+model PMCSIERRA PM8354 0x0004 PM8354 QuadPHY Gigabit interface
/* Quality Semiconductor PHYs */
-model QUALSEMI QS6612 0x0000 QS6612 10/100 media interface
+model xxQUALSEMI QS6612 0x0000 QS6612 10/100 media interface
/* RDC Semiconductor PHYs */
model RDC R6040 0x0003 R6040 10/100 media interface
-/* RealTek Semiconductor PHYs */
-model REALTEK RTL8201L 0x0020 RTL8201L 10/100 media interface
-model xxREALTEK RTL8305SC 0x0005 RTL8305SC 10/100 802.1q switch
-model xxREALTEK RTL8201E 0x0008 RTL8201E 10/100 media interface
-model xxREALTEK RTL8169S 0x0011 RTL8169S/8110S/8211B media interface
+/* RealTek Semicondctor PHYs */
+model yyREALTEK RTL8201L 0x0020 RTL8201L 10/100 media interface
+model xxREALTEK RTL8169S 0x0011 RTL8169S/8110S/8211 1000BASE-T media interface
+model REALTEK RTL8305SC 0x0005 RTL8305SC 10/100 802.1q switch
+model REALTEK RTL8201E 0x0008 RTL8201E 10/100 media interface
+model REALTEK RTL8169S 0x0011 RTL8169S/8110S/8211 1000BASE-T media interface
-/* Seeq PHYs */
-model xxSEEQ 80220 0x0003 Seeq 80220 10/100 media interface
-model xxSEEQ 84220 0x0004 Seeq 84220 10/100 media interface
+/* Seeq Seeq PHYs */
+model SEEQ 80220 0x0003 Seeq 80220 10/100 media interface
+model SEEQ 84220 0x0004 Seeq 84220 10/100 media interface
+model SEEQ 80225 0x0008 Seeq 80225 10/100 media interface
/* Silicon Integrated Systems PHYs */
-model xxSIS 900 0x0000 SiS 900 10/100 media interface
-
-/* SMSC PHYs */
-model SMSC LAN83C183 0x0004 SMSC LAN83C183 10/100 media interface
-
-/* TDK */
-model TDK 78Q2120 0x0014 TDK 78Q2120 media interface
+model SIS 900 0x0000 SiS 900 10/100 media interface
/* Texas Instruments PHYs */
-model xxTI TLAN10T 0x0001 ThunderLAN 10baseT media interface
-model xxTI 100VGPMI 0x0002 ThunderLAN 100VG-AnyLan media interface
+model TI TLAN10T 0x0001 ThunderLAN 10BASE-T media interface
+model TI 100VGPMI 0x0002 ThunderLAN 100VG-AnyLan media interface
+model TI TNETE2101 0x0003 TNETE2101 media interface
-/* XaQti Corp. PHYs. */
-model XAQTI XMACII 0x0000 XaQti Corp. XMAC II gigabit interface
+/* TDK Semiconductor PHYs */
+model xxTSC 78Q2120 0x0014 78Q2120 10/100 media interface
+model xxTSC 78Q2121 0x0015 78Q2121 100BASE-TX media interface
-/* Marvell Semiconductor PHYs */
-model MARVELL E1000 0x0000 Marvell 88E1000 Gigabit PHY
-model MARVELL E1011 0x0002 Marvell 88E1011 Gigabit PHY
-model MARVELL E1000_3 0x0003 Marvell 88E1000 Gigabit PHY
-model MARVELL E1000S 0x0004 Marvell 88E1000S Gigabit PHY
-model MARVELL E1000_5 0x0005 Marvell 88E1000 Gigabit PHY
-model MARVELL E1101 0x0006 Marvell 88E1101 Gigabit PHY
-model MARVELL E3082 0x0008 Marvell 88E3082 10/100 Fast Ethernet PHY
-model MARVELL E1112 0x0009 Marvell 88E1112 Gigabit PHY
-model MARVELL E1149 0x000b Marvell 88E1149 Gigabit PHY
-model MARVELL E1111 0x000c Marvell 88E1111 Gigabit PHY
-model MARVELL E1116 0x0021 Marvell 88E1116 Gigabit PHY
-model MARVELL E1116R 0x0024 Marvell 88E1116R Gigabit PHY
-model MARVELL E1118 0x0022 Marvell 88E1118 Gigabit PHY
-model MARVELL E3016 0x0026 Marvell 88E3016 10/100 Fast Ethernet PHY
-model MARVELL PHYG65G 0x0027 Marvell PHYG65G Gigabit PHY
-model xxMARVELL E1000 0x0005 Marvell 88E1000 Gigabit PHY
-model xxMARVELL E1011 0x0002 Marvell 88E1011 Gigabit PHY
-model xxMARVELL E1000_3 0x0003 Marvell 88E1000 Gigabit PHY
-model xxMARVELL E1000_5 0x0005 Marvell 88E1000 Gigabit PHY
-model xxMARVELL E1111 0x000c Marvell 88E1111 Gigabit PHY
+/* XaQti Corp. PHYs */
+model xxXAQTI XMACII 0x0000 XaQti Corp. XMAC II gigabit interface
diff --git a/sys/dev/mii/miivar.h b/sys/dev/mii/miivar.h
index d9eab72..9af5b4e 100644
--- a/sys/dev/mii/miivar.h
+++ b/sys/dev/mii/miivar.h
@@ -38,7 +38,7 @@
#include <sys/queue.h>
/*
- * Media Independent Interface configuration defintions.
+ * Media Independent Interface data structure defintions
*/
struct mii_softc;
@@ -65,13 +65,13 @@ struct mii_data {
* request is made.
*/
LIST_HEAD(mii_listhead, mii_softc) mii_phys;
- int mii_instance;
+ u_int mii_instance;
/*
* PHY driver fills this in with active media status.
*/
- int mii_media_status;
- int mii_media_active;
+ u_int mii_media_status;
+ u_int mii_media_active;
/*
* Calls from MII layer into network interface driver.
@@ -83,10 +83,13 @@ struct mii_data {
typedef struct mii_data mii_data_t;
/*
- * This call is used by the MII layer to call into the PHY driver
- * to perform a `service request'.
+ * Functions provided by the PHY to perform various functions.
*/
-typedef int (*mii_downcall_t)(struct mii_softc *, struct mii_data *, int);
+struct mii_phy_funcs {
+ int (*pf_service)(struct mii_softc *, struct mii_data *, int);
+ void (*pf_status)(struct mii_softc *);
+ void (*pf_reset)(struct mii_softc *);
+};
/*
* Requests that can be made to the downcall.
@@ -105,26 +108,35 @@ struct mii_softc {
LIST_ENTRY(mii_softc) mii_list; /* entry on parent's PHY list */
- int mii_phy; /* our MII address */
- int mii_inst; /* instance for ifmedia */
+ uint32_t mii_mpd_oui; /* the PHY's OUI (MII_OUI())*/
+ uint32_t mii_mpd_model; /* the PHY's model (MII_MODEL())*/
+ uint32_t mii_mpd_rev; /* the PHY's revision (MII_REV())*/
+ u_int mii_capmask; /* capability mask for BMSR */
+ u_int mii_phy; /* our MII address */
+ u_int mii_offset; /* first PHY, second PHY, etc. */
+ u_int mii_inst; /* instance for ifmedia */
+
+ /* Our PHY functions. */
+ const struct mii_phy_funcs *mii_funcs;
- mii_downcall_t mii_service; /* our downcall */
struct mii_data *mii_pdata; /* pointer to parent's mii_data */
- int mii_flags; /* misc. flags; see below */
- int mii_capabilities; /* capabilities from BMSR */
- int mii_extcapabilities; /* extended capabilities */
- int mii_ticks; /* MII_TICK counter */
- int mii_anegticks; /* ticks before retrying aneg */
- int mii_media_active; /* last active media */
- int mii_media_status; /* last active status */
+ u_int mii_flags; /* misc. flags; see below */
+ u_int mii_capabilities; /* capabilities from BMSR */
+ u_int mii_extcapabilities; /* extended capabilities */
+ u_int mii_ticks; /* MII_TICK counter */
+ u_int mii_anegticks; /* ticks before retrying aneg */
+ u_int mii_media_active; /* last active media */
+ u_int mii_media_status; /* last active status */
};
typedef struct mii_softc mii_softc_t;
/* mii_flags */
#define MIIF_INITDONE 0x00000001 /* has been initialized (mii_data) */
#define MIIF_NOISOLATE 0x00000002 /* do not isolate the PHY */
+#if 0
#define MIIF_NOLOOP 0x00000004 /* no loopback capability */
+#endif
#define MIIF_DOINGAUTO 0x00000008 /* doing autonegotiation (mii_softc) */
#define MIIF_AUTOTSLEEP 0x00000010 /* use tsleep(), not callout() */
#define MIIF_HAVEFIBER 0x00000020 /* from parent: has fiber interface */
@@ -161,10 +173,11 @@ typedef struct mii_softc mii_softc_t;
*/
struct mii_attach_args {
struct mii_data *mii_data; /* pointer to parent data */
- int mii_phyno; /* MII address */
- int mii_id1; /* PHY ID register 1 */
- int mii_id2; /* PHY ID register 2 */
- int mii_capmask; /* capability mask from BMSR */
+ u_int mii_phyno; /* MII address */
+ u_int mii_offset; /* first PHY, second PHY, etc. */
+ uint32_t mii_id1; /* PHY ID register 1 */
+ uint32_t mii_id2; /* PHY ID register 2 */
+ u_int mii_capmask; /* capability mask for BMSR */
};
typedef struct mii_attach_args mii_attach_args_t;
@@ -172,8 +185,8 @@ typedef struct mii_attach_args mii_attach_args_t;
* Used to match a PHY.
*/
struct mii_phydesc {
- u_int32_t mpd_oui; /* the PHY's OUI */
- u_int32_t mpd_model; /* the PHY's model */
+ uint32_t mpd_oui; /* the PHY's OUI */
+ uint32_t mpd_model; /* the PHY's model */
const char *mpd_name; /* the PHY's name */
};
#define MII_PHY_DESC(a, b) { MII_OUI_ ## a, MII_MODEL_ ## a ## _ ## b, \
@@ -184,9 +197,9 @@ struct mii_phydesc {
* An array of these structures map MII media types to BMCR/ANAR settings.
*/
struct mii_media {
- int mm_bmcr; /* BMCR settings for this media */
- int mm_anar; /* ANAR settings for this media */
- int mm_gtcr; /* 100base-T2 or 1000base-T CR */
+ u_int mm_bmcr; /* BMCR settings for this media */
+ u_int mm_anar; /* ANAR settings for this media */
+ u_int mm_gtcr; /* 100base-T2 or 1000base-T CR */
};
#define MII_MEDIA_NONE 0
@@ -209,6 +222,15 @@ struct mii_media {
#define PHY_WRITE(p, r, v) \
MIIBUS_WRITEREG((p)->mii_dev, (p)->mii_phy, (r), (v))
+#define PHY_SERVICE(p, d, o) \
+ (*(p)->mii_funcs->pf_service)((p), (d), (o))
+
+#define PHY_STATUS(p) \
+ (*(p)->mii_funcs->pf_status)(p)
+
+#define PHY_RESET(p) \
+ (*(p)->mii_funcs->pf_reset)(p)
+
enum miibus_device_ivars {
MIIBUS_IVAR_FLAGS
};
@@ -219,7 +241,7 @@ enum miibus_device_ivars {
#define MIIBUS_ACCESSOR(var, ivar, type) \
__BUS_ACCESSOR(miibus, var, MIIBUS, ivar, type)
-MIIBUS_ACCESSOR(flags, FLAGS, int)
+MIIBUS_ACCESSOR(flags, FLAGS, u_int)
extern devclass_t miibus_devclass;
extern driver_t miibus_driver;
@@ -250,8 +272,16 @@ const struct mii_phydesc * mii_phy_match(const struct mii_attach_args *ma,
const struct mii_phydesc * mii_phy_match_gen(const struct mii_attach_args *ma,
const struct mii_phydesc *mpd, size_t endlen);
int mii_phy_dev_probe(device_t dev, const struct mii_phydesc *mpd, int mrv);
+void mii_phy_dev_attach(device_t dev, u_int flags,
+ const struct mii_phy_funcs *mpf, int add_media);
void ukphy_status(struct mii_softc *);
+
+u_int mii_oui(u_int, u_int);
+#define MII_OUI(id1, id2) mii_oui(id1, id2)
+#define MII_MODEL(id2) (((id2) & IDR2_MODEL) >> 4)
+#define MII_REV(id2) ((id2) & IDR2_REV)
+
#endif /* _KERNEL */
#endif /* _DEV_MII_MIIVAR_H_ */
diff --git a/sys/dev/mii/mlphy.c b/sys/dev/mii/mlphy.c
index ccfcd79..3708b4a 100644
--- a/sys/dev/mii/mlphy.c
+++ b/sys/dev/mii/mlphy.c
@@ -102,6 +102,12 @@ static int mlphy_service(struct mii_softc *, struct mii_data *, int);
static void mlphy_reset(struct mii_softc *);
static void mlphy_status(struct mii_softc *);
+static const struct mii_phy_funcs mlphy_funcs = {
+ mlphy_service,
+ mlphy_status,
+ mlphy_reset
+};
+
static int
mlphy_probe(dev)
device_t dev;
@@ -137,37 +143,21 @@ mlphy_attach(dev)
{
struct mlphy_softc *msc;
struct mii_softc *sc;
- struct mii_attach_args *ma;
- struct mii_data *mii;
msc = device_get_softc(dev);
sc = &msc->ml_mii;
msc->ml_dev = dev;
- ma = device_get_ivars(dev);
- sc->mii_dev = device_get_parent(dev);
- mii = ma->mii_data;
- LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list);
-
- sc->mii_flags = miibus_get_flags(dev);
- sc->mii_inst = mii->mii_instance++;
- sc->mii_phy = ma->mii_phyno;
- sc->mii_service = mlphy_service;
- sc->mii_pdata = mii;
+ mii_phy_dev_attach(dev, MIIF_NOMANPAUSE, &mlphy_funcs, 0);
-#define ADD(m, c) ifmedia_add(&mii->mii_media, (m), (c), NULL)
+ PHY_RESET(sc);
- ADD(IFM_MAKEWORD(IFM_ETHER, IFM_100_TX, IFM_LOOP, sc->mii_inst),
- MII_MEDIA_100_TX);
-
- mii_phy_reset(sc);
-
- sc->mii_capabilities = PHY_READ(sc, MII_BMSR) & ma->mii_capmask;
+ sc->mii_capabilities = PHY_READ(sc, MII_BMSR) & sc->mii_capmask;
/* Let the companion PHY (if any) only handle the media we don't. */
- ma->mii_capmask = ~sc->mii_capabilities;
+ sc->mii_capmask = ~sc->mii_capabilities;
device_printf(dev, " ");
mii_phy_add_media(sc);
printf("\n");
-#undef ADD
+
MIIBUS_MEDIAINIT(sc->mii_dev);
return (0);
}
@@ -230,7 +220,7 @@ mlphy_service(xsc, mii, cmd)
*/
msc->ml_state = ML_STATE_AUTO_SELF;
if (other != NULL) {
- mii_phy_reset(other);
+ PHY_RESET(other);
PHY_WRITE(other, MII_BMCR, BMCR_ISO);
}
(void)mii_phy_auto(sc);
@@ -247,7 +237,7 @@ mlphy_service(xsc, mii, cmd)
* BMCR data is stored in the ifmedia entry.
*/
if (other != NULL) {
- mii_phy_reset(other);
+ PHY_RESET(other);
PHY_WRITE(other, MII_BMCR, ife->ifm_data);
}
mii_phy_setmedia(sc);
@@ -262,7 +252,7 @@ mlphy_service(xsc, mii, cmd)
* BMCR data is stored in the ifmedia entry.
*/
if (other != NULL) {
- mii_phy_reset(other);
+ PHY_RESET(other);
PHY_WRITE(other, MII_BMCR, BMCR_ISO);
}
mii_phy_setmedia(sc);
@@ -307,7 +297,7 @@ mlphy_service(xsc, mii, cmd)
if (reg & BMSR_LINK) {
if (!msc->ml_linked) {
msc->ml_linked = 1;
- mlphy_status(sc);
+ PHY_STATUS(sc);
}
break;
}
@@ -321,10 +311,10 @@ mlphy_service(xsc, mii, cmd)
sc->mii_ticks = 0;
msc->ml_linked = 0;
mii->mii_media_active = IFM_NONE;
- mii_phy_reset(sc);
+ PHY_RESET(sc);
msc->ml_state = ML_STATE_AUTO_SELF;
if (other != NULL) {
- mii_phy_reset(other);
+ PHY_RESET(other);
PHY_WRITE(other, MII_BMCR, BMCR_ISO);
}
mii_phy_auto(sc);
@@ -337,7 +327,7 @@ mlphy_service(xsc, mii, cmd)
other_inst = other->mii_inst;
other->mii_inst = sc->mii_inst;
if (IFM_INST(ife->ifm_media) == other->mii_inst)
- (void)(*other->mii_service)(other, mii, MII_POLLSTAT);
+ (void)PHY_SERVICE(other, mii, MII_POLLSTAT);
other->mii_inst = other_inst;
sc->mii_media_active = other->mii_media_active;
sc->mii_media_status = other->mii_media_status;
@@ -386,15 +376,15 @@ mlphy_status(sc)
if (IFM_SUBTYPE(mii->mii_media_active) != IFM_10_T) {
msc->ml_state = ML_STATE_AUTO_SELF;
- mii_phy_reset(other);
+ PHY_RESET(other);
PHY_WRITE(other, MII_BMCR, BMCR_ISO);
}
if (IFM_SUBTYPE(mii->mii_media_active) == IFM_10_T) {
msc->ml_state = ML_STATE_AUTO_OTHER;
- mlphy_reset(&msc->ml_mii);
+ PHY_RESET(&msc->ml_mii);
PHY_WRITE(&msc->ml_mii, MII_BMCR, BMCR_ISO);
- mii_phy_reset(other);
+ PHY_RESET(other);
mii_phy_auto(other);
}
}
diff --git a/sys/dev/mii/nsgphy.c b/sys/dev/mii/nsgphy.c
index 15fcebb..cd18acf 100644
--- a/sys/dev/mii/nsgphy.c
+++ b/sys/dev/mii/nsgphy.c
@@ -100,12 +100,18 @@ static int nsgphy_service(struct mii_softc *, struct mii_data *,int);
static void nsgphy_status(struct mii_softc *);
static const struct mii_phydesc nsgphys[] = {
- MII_PHY_DESC(NATSEMI, DP83861),
- MII_PHY_DESC(NATSEMI, DP83865),
- MII_PHY_DESC(NATSEMI, DP83891),
+ MII_PHY_DESC(xxNATSEMI, DP83861),
+ MII_PHY_DESC(xxNATSEMI, DP83865),
+ MII_PHY_DESC(xxNATSEMI, DP83891),
MII_PHY_END
};
+static const struct mii_phy_funcs nsgphy_funcs = {
+ nsgphy_service,
+ nsgphy_status,
+ mii_phy_reset
+};
+
static int
nsgphy_probe(device_t dev)
{
@@ -117,34 +123,19 @@ static int
nsgphy_attach(device_t dev)
{
struct mii_softc *sc;
- struct mii_attach_args *ma;
- struct mii_data *mii;
sc = device_get_softc(dev);
- ma = device_get_ivars(dev);
- if (bootverbose)
- device_printf(dev, "<rev. %d>\n", MII_REV(ma->mii_id2));
- device_printf(dev, " ");
- sc->mii_dev = device_get_parent(dev);
- mii = ma->mii_data;
- LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list);
-
- sc->mii_flags = miibus_get_flags(dev);
- sc->mii_inst = mii->mii_instance++;
- sc->mii_phy = ma->mii_phyno;
- sc->mii_service = nsgphy_service;
- sc->mii_pdata = mii;
- sc->mii_flags |= MIIF_NOMANPAUSE;
+ mii_phy_dev_attach(dev, MIIF_NOMANPAUSE, &nsgphy_funcs, 0);
- mii_phy_reset(sc);
+ PHY_RESET(sc);
/*
* NB: the PHY has the 10BASE-T BMSR bits hard-wired to 0,
* even though it supports 10BASE-T.
*/
sc->mii_capabilities = (PHY_READ(sc, MII_BMSR) |
- BMSR_10TFDX | BMSR_10THDX) & ma->mii_capmask;
+ BMSR_10TFDX | BMSR_10THDX) & sc->mii_capmask;
/*
* Note that as documented manual 1000BASE-T modes of DP83865 only
* work together with other National Semiconductor PHYs.
@@ -184,7 +175,7 @@ nsgphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
}
/* Update the media status. */
- nsgphy_status(sc);
+ PHY_STATUS(sc);
/* Callback if something changed. */
mii_phy_update(sc, cmd);
diff --git a/sys/dev/mii/nsphy.c b/sys/dev/mii/nsphy.c
index af805ca..86a69b6 100644
--- a/sys/dev/mii/nsphy.c
+++ b/sys/dev/mii/nsphy.c
@@ -108,10 +108,16 @@ static void nsphy_status(struct mii_softc *);
static void nsphy_reset(struct mii_softc *);
static const struct mii_phydesc nsphys[] = {
- MII_PHY_DESC(NATSEMI, DP83840),
+ MII_PHY_DESC(xxNATSEMI, DP83840),
MII_PHY_END
};
+static const struct mii_phy_funcs nsphy_funcs = {
+ nsphy_service,
+ nsphy_status,
+ nsphy_reset
+};
+
static int
nsphy_probe(device_t dev)
{
@@ -122,52 +128,17 @@ nsphy_probe(device_t dev)
static int
nsphy_attach(device_t dev)
{
- struct mii_softc *sc;
- struct mii_attach_args *ma;
- struct mii_data *mii;
const char *nic;
+ u_int flags;
- sc = device_get_softc(dev);
- ma = device_get_ivars(dev);
- sc->mii_dev = device_get_parent(dev);
- mii = ma->mii_data;
- LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list);
-
- sc->mii_flags = miibus_get_flags(dev);
- sc->mii_inst = mii->mii_instance++;
- sc->mii_phy = ma->mii_phyno;
- sc->mii_service = nsphy_service;
- sc->mii_pdata = mii;
-
- nic = device_get_name(device_get_parent(sc->mii_dev));
+ nic = device_get_name(device_get_parent(device_get_parent(dev)));
+ flags = MIIF_NOMANPAUSE;
/*
* Am79C971 wedge when isolating all of their external PHYs.
*/
if (strcmp(nic, "pcn") == 0)
- sc->mii_flags |= MIIF_NOISOLATE;
-
-#if 1
-
-#define ADD(m, c) ifmedia_add(&mii->mii_media, (m), (c), NULL)
-
- /*
- * XXX IFM_LOOP should be handled by mii_phy_add_media() based
- * on MIIF_NOLOOP.
- */
- if ((sc->mii_flags & MIIF_NOLOOP) == 0)
- ADD(IFM_MAKEWORD(IFM_ETHER, IFM_100_TX, IFM_LOOP,
- sc->mii_inst), MII_MEDIA_100_TX);
-
-#endif
-
- nsphy_reset(sc);
-
- sc->mii_capabilities = PHY_READ(sc, MII_BMSR) & ma->mii_capmask;
- device_printf(dev, " ");
- mii_phy_add_media(sc);
- printf("\n");
-
- MIIBUS_MEDIAINIT(sc->mii_dev);
+ flags |= MIIF_NOISOLATE;
+ mii_phy_dev_attach(dev, flags, &nsphy_funcs, 1);
return (0);
}
@@ -233,7 +204,7 @@ nsphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
}
/* Update the media status. */
- nsphy_status(sc);
+ PHY_STATUS(sc);
/* Callback if something changed. */
mii_phy_update(sc, cmd);
@@ -296,6 +267,9 @@ nsphy_status(struct mii_softc *sc)
mii->mii_media_active |= IFM_10_T|IFM_HDX;
else
mii->mii_media_active |= IFM_NONE;
+ if ((mii->mii_media_active & IFM_FDX) != 0)
+ mii->mii_media_active |=
+ mii_phy_flowstatus(sc);
return;
}
diff --git a/sys/dev/mii/nsphyter.c b/sys/dev/mii/nsphyter.c
index c302181..facdebb 100644
--- a/sys/dev/mii/nsphyter.c
+++ b/sys/dev/mii/nsphyter.c
@@ -110,63 +110,31 @@ static int nsphyter_service(struct mii_softc *, struct mii_data *, int);
static void nsphyter_status(struct mii_softc *);
static void nsphyter_reset(struct mii_softc *);
-static const struct mii_phydesc nsphys[] = {
- MII_PHY_DESC(NATSEMI, DP83815),
- MII_PHY_DESC(NATSEMI, DP83843),
- MII_PHY_DESC(NATSEMI, DP83847),
+static const struct mii_phydesc nsphyters[] = {
+ MII_PHY_DESC(xxNATSEMI, DP83815),
+ MII_PHY_DESC(xxNATSEMI, DP83843),
+ MII_PHY_DESC(xxNATSEMI, DP83847),
MII_PHY_END
};
+static const struct mii_phy_funcs nsphyter_funcs = {
+ nsphyter_service,
+ nsphyter_status,
+ nsphyter_reset
+};
+
static int
nsphyter_probe(device_t dev)
{
- return (mii_phy_dev_probe(dev, nsphys, BUS_PROBE_DEFAULT));
+ return (mii_phy_dev_probe(dev, nsphyters, BUS_PROBE_DEFAULT));
}
static int
nsphyter_attach(device_t dev)
{
- struct mii_softc *sc;
- struct mii_attach_args *ma;
- struct mii_data *mii;
-
- sc = device_get_softc(dev);
- ma = device_get_ivars(dev);
- sc->mii_dev = device_get_parent(dev);
- mii = ma->mii_data;
- LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list);
-
- sc->mii_flags = miibus_get_flags(dev);
- sc->mii_inst = mii->mii_instance++;
- sc->mii_phy = ma->mii_phyno;
- sc->mii_service = nsphyter_service;
- sc->mii_pdata = mii;
-
- sc->mii_flags |= MIIF_NOMANPAUSE;
-
-#if 1
-
-#define ADD(m, c) ifmedia_add(&mii->mii_media, (m), (c), NULL)
-
- /*
- * XXX IFM_LOOP should be handled by mii_phy_add_media() based
- * on MIIF_NOLOOP.
- */
- if ((sc->mii_flags & MIIF_NOLOOP) == 0)
- ADD(IFM_MAKEWORD(IFM_ETHER, IFM_100_TX, IFM_LOOP,
- sc->mii_inst), MII_MEDIA_100_TX);
-
-#endif
-
- nsphyter_reset(sc);
-
- sc->mii_capabilities = PHY_READ(sc, MII_BMSR) & ma->mii_capmask;
- device_printf(dev, " ");
- mii_phy_add_media(sc);
- printf("\n");
- MIIBUS_MEDIAINIT(sc->mii_dev);
+ mii_phy_dev_attach(dev, MIIF_NOMANPAUSE, &nsphyter_funcs, 1);
return (0);
}
@@ -195,7 +163,7 @@ nsphyter_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
}
/* Update the media status. */
- nsphyter_status(sc);
+ PHY_STATUS(sc);
/* Callback if something changed. */
mii_phy_update(sc, cmd);
diff --git a/sys/dev/mii/pnaphy.c b/sys/dev/mii/pnaphy.c
index 159575b..0e77c4f 100644
--- a/sys/dev/mii/pnaphy.c
+++ b/sys/dev/mii/pnaphy.c
@@ -85,10 +85,16 @@ DRIVER_MODULE(pnaphy, miibus, pnaphy_driver, pnaphy_devclass, 0, 0);
static int pnaphy_service(struct mii_softc *, struct mii_data *,int);
static const struct mii_phydesc pnaphys[] = {
- MII_PHY_DESC(AMD, 79c978),
+ MII_PHY_DESC(yyAMD, 79c901home),
MII_PHY_END
};
+static const struct mii_phy_funcs pnaphy_funcs = {
+ pnaphy_service,
+ ukphy_status,
+ mii_phy_reset
+};
+
static int
pnaphy_probe(device_t dev)
{
@@ -99,32 +105,9 @@ pnaphy_probe(device_t dev)
static int
pnaphy_attach(device_t dev)
{
- struct mii_softc *sc;
- struct mii_attach_args *ma;
- struct mii_data *mii;
-
- sc = device_get_softc(dev);
- ma = device_get_ivars(dev);
- sc->mii_dev = device_get_parent(dev);
- mii = ma->mii_data;
- LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list);
-
- sc->mii_flags = miibus_get_flags(dev);
- sc->mii_inst = mii->mii_instance++;
- sc->mii_phy = ma->mii_phyno;
- sc->mii_service = pnaphy_service;
- sc->mii_pdata = mii;
-
- sc->mii_flags |= MIIF_NOISOLATE | MIIF_NOLOOP | MIIF_IS_HPNA;
-
- mii_phy_reset(sc);
-
- sc->mii_capabilities = PHY_READ(sc, MII_BMSR) & ma->mii_capmask;
- device_printf(dev, " ");
- mii_phy_add_media(sc);
- printf("\n");
- MIIBUS_MEDIAINIT(sc->mii_dev);
+ mii_phy_dev_attach(dev, MIIF_NOISOLATE | MIIF_IS_HPNA |
+ MIIF_NOMANPAUSE, &pnaphy_funcs, 1);
return (0);
}
@@ -160,7 +143,7 @@ pnaphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
}
/* Update the media status. */
- ukphy_status(sc);
+ PHY_STATUS(sc);
if (IFM_SUBTYPE(mii->mii_media_active) == IFM_10_T)
mii->mii_media_active = IFM_ETHER | IFM_HPNA_1;
diff --git a/sys/dev/mii/qsphy.c b/sys/dev/mii/qsphy.c
index 19fc77d..a504504 100644
--- a/sys/dev/mii/qsphy.c
+++ b/sys/dev/mii/qsphy.c
@@ -109,10 +109,16 @@ static void qsphy_reset(struct mii_softc *);
static void qsphy_status(struct mii_softc *);
static const struct mii_phydesc qsphys[] = {
- MII_PHY_DESC(QUALSEMI, QS6612),
+ MII_PHY_DESC(xxQUALSEMI, QS6612),
MII_PHY_END
};
+static const struct mii_phy_funcs qsphy_funcs = {
+ qsphy_service,
+ qsphy_status,
+ qsphy_reset
+};
+
static int
qsphy_probe(device_t dev)
{
@@ -123,30 +129,8 @@ qsphy_probe(device_t dev)
static int
qsphy_attach(device_t dev)
{
- struct mii_softc *sc;
- struct mii_attach_args *ma;
- struct mii_data *mii;
-
- sc = device_get_softc(dev);
- ma = device_get_ivars(dev);
- sc->mii_dev = device_get_parent(dev);
- mii = ma->mii_data;
- LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list);
-
- sc->mii_flags = miibus_get_flags(dev);
- sc->mii_inst = mii->mii_instance++;
- sc->mii_phy = ma->mii_phyno;
- sc->mii_service = qsphy_service;
- sc->mii_pdata = mii;
-
- qsphy_reset(sc);
-
- sc->mii_capabilities = PHY_READ(sc, MII_BMSR) & ma->mii_capmask;
- device_printf(dev, " ");
- mii_phy_add_media(sc);
- printf("\n");
-
- MIIBUS_MEDIAINIT(sc->mii_dev);
+
+ mii_phy_dev_attach(dev, MIIF_NOMANPAUSE, &qsphy_funcs, 1);
return (0);
}
@@ -182,7 +166,7 @@ qsphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
}
/* Update the media status. */
- qsphy_status(sc);
+ PHY_STATUS(sc);
/* Callback if something changed. */
mii_phy_update(sc, cmd);
@@ -238,6 +222,8 @@ qsphy_status(struct mii_softc *sc)
mii->mii_media_active |= IFM_NONE;
break;
}
+ if ((mii->mii_media_active & IFM_FDX) != 0)
+ mii->mii_media_active |= mii_phy_flowstatus(sc);
}
static void
diff --git a/sys/dev/mii/rdcphy.c b/sys/dev/mii/rdcphy.c
index cdc3f8a..cf5db88 100644
--- a/sys/dev/mii/rdcphy.c
+++ b/sys/dev/mii/rdcphy.c
@@ -55,7 +55,6 @@ static device_attach_t rdcphy_attach;
struct rdcphy_softc {
struct mii_softc mii_sc;
- int mii_model;
int mii_link_tick;
#define RDCPHY_MANNEG_TICK 3
};
@@ -87,6 +86,12 @@ static const struct mii_phydesc rdcphys[] = {
MII_PHY_END
};
+static const struct mii_phy_funcs rdcphy_funcs = {
+ rdcphy_service,
+ rdcphy_status,
+ mii_phy_reset
+};
+
static int
rdcphy_probe(device_t dev)
{
@@ -97,40 +102,8 @@ rdcphy_probe(device_t dev)
static int
rdcphy_attach(device_t dev)
{
- struct rdcphy_softc *rsc;
- struct mii_softc *sc;
- struct mii_attach_args *ma;
- struct mii_data *mii;
- rsc = device_get_softc(dev);
- sc = &rsc->mii_sc;
- ma = device_get_ivars(dev);
- sc->mii_dev = device_get_parent(dev);
- mii = ma->mii_data;
- LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list);
-
- sc->mii_flags = miibus_get_flags(dev);
- sc->mii_inst = mii->mii_instance++;
- sc->mii_phy = ma->mii_phyno;
- sc->mii_service = rdcphy_service;
- sc->mii_pdata = mii;
-
- rsc->mii_model = MII_MODEL(ma->mii_id2);
- if (bootverbose)
- device_printf(dev, "OUI 0x%06x, model 0x%04x, rev. %d\n",
- MII_OUI(ma->mii_id1, ma->mii_id2), MII_MODEL(ma->mii_id2),
- MII_REV(ma->mii_id2));
-
- mii_phy_reset(sc);
-
- sc->mii_capabilities = PHY_READ(sc, MII_BMSR) & ma->mii_capmask;
- if (sc->mii_capabilities & BMSR_EXTSTAT)
- sc->mii_extcapabilities = PHY_READ(sc, MII_EXTSR);
- device_printf(dev, " ");
- mii_phy_add_media(sc);
- printf("\n");
-
- MIIBUS_MEDIAINIT(sc->mii_dev);
+ mii_phy_dev_attach(dev, MIIF_NOMANPAUSE, &rdcphy_funcs, 1);
return (0);
}
@@ -205,7 +178,7 @@ rdcphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
}
/* Update the media status. */
- rdcphy_status(sc);
+ PHY_STATUS(sc);
/* Callback if something changed. */
mii_phy_update(sc, cmd);
diff --git a/sys/dev/mii/rgephy.c b/sys/dev/mii/rgephy.c
index 1884f2d..6d54542 100644
--- a/sys/dev/mii/rgephy.c
+++ b/sys/dev/mii/rgephy.c
@@ -62,12 +62,6 @@ __FBSDID("$FreeBSD$");
static int rgephy_probe(device_t);
static int rgephy_attach(device_t);
-struct rgephy_softc {
- struct mii_softc mii_sc;
- int mii_model;
- int mii_revision;
-};
-
static device_method_t rgephy_methods[] = {
/* device interface */
DEVMETHOD(device_probe, rgephy_probe),
@@ -82,7 +76,7 @@ static devclass_t rgephy_devclass;
static driver_t rgephy_driver = {
"rgephy",
rgephy_methods,
- sizeof(struct rgephy_softc)
+ sizeof(struct mii_softc)
};
DRIVER_MODULE(rgephy, miibus, rgephy_driver, rgephy_devclass, 0, 0);
@@ -95,10 +89,16 @@ static void rgephy_loop(struct mii_softc *);
static void rgephy_load_dspcode(struct mii_softc *);
static const struct mii_phydesc rgephys[] = {
- MII_PHY_DESC(xxREALTEK, RTL8169S),
+ MII_PHY_DESC(REALTEK, RTL8169S),
MII_PHY_END
};
+static const struct mii_phy_funcs rgephy_funcs = {
+ rgephy_service,
+ rgephy_status,
+ rgephy_reset
+};
+
static int
rgephy_probe(device_t dev)
{
@@ -109,52 +109,30 @@ rgephy_probe(device_t dev)
static int
rgephy_attach(device_t dev)
{
- struct rgephy_softc *rsc;
struct mii_softc *sc;
- struct mii_attach_args *ma;
- struct mii_data *mii;
-
- rsc = device_get_softc(dev);
- sc = &rsc->mii_sc;
- ma = device_get_ivars(dev);
- sc->mii_dev = device_get_parent(dev);
- mii = ma->mii_data;
- LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list);
-
- sc->mii_flags = miibus_get_flags(dev);
- sc->mii_inst = mii->mii_instance++;
- sc->mii_phy = ma->mii_phyno;
- sc->mii_service = rgephy_service;
- sc->mii_pdata = mii;
- rsc->mii_model = MII_MODEL(ma->mii_id2);
- rsc->mii_revision = MII_REV(ma->mii_id2);
+ sc = device_get_softc(dev);
-#define ADD(m, c) ifmedia_add(&mii->mii_media, (m), (c), NULL)
-
-#if 0
- ADD(IFM_MAKEWORD(IFM_ETHER, IFM_100_TX, IFM_LOOP, sc->mii_inst),
- MII_MEDIA_100_TX);
-#endif
+ mii_phy_dev_attach(dev, 0, &rgephy_funcs, 0);
/* RTL8169S do not report auto-sense; add manually. */
sc->mii_capabilities = (PHY_READ(sc, MII_BMSR) | BMSR_ANEG) &
- ma->mii_capmask;
+ sc->mii_capmask;
if (sc->mii_capabilities & BMSR_EXTSTAT)
sc->mii_extcapabilities = PHY_READ(sc, MII_EXTSR);
device_printf(dev, " ");
mii_phy_add_media(sc);
printf("\n");
-#undef ADD
/*
* Allow IFM_FLAG0 to be set indicating that auto-negotiation with
* manual configuration, which is used to work around issues with
* certain setups by default, should not be triggered as it may in
* turn cause harm in some edge cases.
*/
- mii->mii_media.ifm_mask |= IFM_FLAG0;
+ sc->mii_pdata->mii_media.ifm_mask |= IFM_FLAG0;
+
+ PHY_RESET(sc);
- rgephy_reset(sc);
MIIBUS_MEDIAINIT(sc->mii_dev);
return (0);
}
@@ -162,12 +140,9 @@ rgephy_attach(device_t dev)
static int
rgephy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
{
- struct rgephy_softc *rsc;
struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
int reg, speed, gig, anar;
- rsc = (struct rgephy_softc *)sc;
-
switch (cmd) {
case MII_POLLSTAT:
break;
@@ -179,7 +154,7 @@ rgephy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
break;
- rgephy_reset(sc); /* XXX hardware bug work-around */
+ PHY_RESET(sc); /* XXX hardware bug work-around */
anar = PHY_READ(sc, RGEPHY_MII_ANAR);
anar &= ~(RGEPHY_ANAR_PC | RGEPHY_ANAR_ASP |
@@ -268,7 +243,7 @@ setit:
* Check to see if we have link. If we do, we don't
* need to restart the autonegotiation process.
*/
- if (rsc->mii_revision >= 2) {
+ if (sc->mii_mpd_rev >= 2) {
/* RTL8211B(L) */
reg = PHY_READ(sc, RGEPHY_MII_SSR);
if (reg & RGEPHY_SSR_LINK) {
@@ -297,7 +272,7 @@ setit:
}
/* Update the media status. */
- rgephy_status(sc);
+ PHY_STATUS(sc);
/*
* Callback if something changed. Note that we need to poke
@@ -316,7 +291,6 @@ setit:
static void
rgephy_status(struct mii_softc *sc)
{
- struct rgephy_softc *rsc;
struct mii_data *mii = sc->mii_pdata;
int bmsr, bmcr;
uint16_t ssr;
@@ -324,8 +298,7 @@ rgephy_status(struct mii_softc *sc)
mii->mii_media_status = IFM_AVALID;
mii->mii_media_active = IFM_ETHER;
- rsc = (struct rgephy_softc *)sc;
- if (rsc->mii_revision >= 2) {
+ if (sc->mii_mpd_rev >= 2) {
ssr = PHY_READ(sc, RGEPHY_MII_SSR);
if (ssr & RGEPHY_SSR_LINK)
mii->mii_media_status |= IFM_ACTIVE;
@@ -355,7 +328,7 @@ rgephy_status(struct mii_softc *sc)
}
}
- if (rsc->mii_revision >= 2) {
+ if (sc->mii_mpd_rev >= 2) {
ssr = PHY_READ(sc, RGEPHY_MII_SSR);
switch (ssr & RGEPHY_SSR_SPD_MASK) {
case RGEPHY_SSR_S1000:
@@ -405,7 +378,7 @@ rgephy_mii_phy_auto(struct mii_softc *sc, int media)
int anar;
rgephy_loop(sc);
- rgephy_reset(sc);
+ PHY_RESET(sc);
anar = BMSR_MEDIA_TO_ANAR(sc->mii_capabilities) | ANAR_CSMA;
if ((media & IFM_FLOW) != 0 || (sc->mii_flags & MIIF_FORCEPAUSE) != 0)
@@ -425,11 +398,9 @@ rgephy_mii_phy_auto(struct mii_softc *sc, int media)
static void
rgephy_loop(struct mii_softc *sc)
{
- struct rgephy_softc *rsc;
int i;
- rsc = (struct rgephy_softc *)sc;
- if (rsc->mii_revision < 2) {
+ if (sc->mii_mpd_rev < 2) {
PHY_WRITE(sc, RGEPHY_MII_BMCR, RGEPHY_BMCR_PDOWN);
DELAY(1000);
}
@@ -460,11 +431,9 @@ rgephy_loop(struct mii_softc *sc)
static void
rgephy_load_dspcode(struct mii_softc *sc)
{
- struct rgephy_softc *rsc;
int val;
- rsc = (struct rgephy_softc *)sc;
- if (rsc->mii_revision >= 2)
+ if (sc->mii_mpd_rev >= 2)
return;
PHY_WRITE(sc, 31, 0x0001);
@@ -513,11 +482,9 @@ rgephy_load_dspcode(struct mii_softc *sc)
static void
rgephy_reset(struct mii_softc *sc)
{
- struct rgephy_softc *rsc;
uint16_t ssr;
- rsc = (struct rgephy_softc *)sc;
- if (rsc->mii_revision == 3) {
+ if (sc->mii_mpd_rev == 3) {
/* RTL8211C(L) */
ssr = PHY_READ(sc, RGEPHY_MII_SSR);
if ((ssr & RGEPHY_SSR_ALDPS) != 0) {
diff --git a/sys/dev/mii/rlphy.c b/sys/dev/mii/rlphy.c
index 02dab48..b285f7f 100644
--- a/sys/dev/mii/rlphy.c
+++ b/sys/dev/mii/rlphy.c
@@ -57,11 +57,6 @@ __FBSDID("$FreeBSD$");
#include "miibus_if.h"
-struct rlphy_softc {
- struct mii_softc sc_mii; /* generic PHY */
- int sc_is_RTL8201L; /* is an external RTL8201L PHY */
-};
-
static int rlphy_probe(device_t);
static int rlphy_attach(device_t);
@@ -79,7 +74,7 @@ static devclass_t rlphy_devclass;
static driver_t rlphy_driver = {
"rlphy",
rlphy_methods,
- sizeof(struct rlphy_softc)
+ sizeof(struct mii_softc)
};
DRIVER_MODULE(rlphy, miibus, rlphy_driver, rlphy_devclass, 0, 0);
@@ -97,12 +92,18 @@ static const struct mii_phydesc rlintphys[] = {
};
static const struct mii_phydesc rlphys[] = {
- MII_PHY_DESC(REALTEK, RTL8201L),
- MII_PHY_DESC(xxREALTEK, RTL8201E),
- MII_PHY_DESC(ICPLUS, IP101),
+ MII_PHY_DESC(yyREALTEK, RTL8201L),
+ MII_PHY_DESC(REALTEK, RTL8201E),
+ MII_PHY_DESC(xxICPLUS, IP101),
MII_PHY_END
};
+static const struct mii_phy_funcs rlphy_funcs = {
+ rlphy_service,
+ rlphy_status,
+ mii_phy_reset
+};
+
static int
rlphy_probe(device_t dev)
{
@@ -122,50 +123,12 @@ rlphy_probe(device_t dev)
static int
rlphy_attach(device_t dev)
{
- struct mii_softc *sc;
- struct mii_attach_args *ma;
- struct mii_data *mii;
- struct rlphy_softc *rsc;
-
- sc = device_get_softc(dev);
- ma = device_get_ivars(dev);
- sc->mii_dev = device_get_parent(dev);
- mii = ma->mii_data;
-
- /*
- * Check whether we're the RTL8201L PHY and remember so the status
- * routine can query the proper register for speed detection.
- */
- rsc = (struct rlphy_softc *)sc;
- if (mii_phy_dev_probe(dev, rlphys, 0) == 0)
- rsc->sc_is_RTL8201L++;
-
- LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list);
-
- sc->mii_flags = miibus_get_flags(dev);
- sc->mii_inst = mii->mii_instance++;
- sc->mii_phy = ma->mii_phyno;
- sc->mii_service = rlphy_service;
- sc->mii_pdata = mii;
/*
* The RealTek PHY can never be isolated.
*/
- sc->mii_flags |= MIIF_NOISOLATE;
-
-#define ADD(m, c) ifmedia_add(&mii->mii_media, (m), (c), NULL)
-
- ADD(IFM_MAKEWORD(IFM_ETHER, IFM_100_TX, IFM_LOOP, sc->mii_inst),
- MII_MEDIA_100_TX);
-
- mii_phy_reset(sc);
-
- sc->mii_capabilities = PHY_READ(sc, MII_BMSR) & ma->mii_capmask;
- device_printf(dev, " ");
- mii_phy_add_media(sc);
- printf("\n");
-#undef ADD
- MIIBUS_MEDIAINIT(sc->mii_dev);
+ mii_phy_dev_attach(dev, MIIF_NOISOLATE | MIIF_NOMANPAUSE,
+ &rlphy_funcs, 1);
return (0);
}
@@ -202,7 +165,7 @@ rlphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
}
/* Update the media status. */
- rlphy_status(sc);
+ PHY_STATUS(sc);
/* Callback if something changed. */
mii_phy_update(sc, cmd);
@@ -212,7 +175,6 @@ rlphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
static void
rlphy_status(struct mii_softc *phy)
{
- struct rlphy_softc *rsc =(struct rlphy_softc *)phy;
struct mii_data *mii = phy->mii_pdata;
struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
int bmsr, bmcr, anlpar;
@@ -260,6 +222,9 @@ rlphy_status(struct mii_softc *phy)
mii->mii_media_active |= IFM_10_T|IFM_HDX;
else
mii->mii_media_active |= IFM_NONE;
+ if ((mii->mii_media_active & IFM_FDX) != 0)
+ mii->mii_media_active |=
+ mii_phy_flowstatus(phy);
return;
}
/*
@@ -280,16 +245,16 @@ rlphy_status(struct mii_softc *phy)
* To determine the link speed, we have to do one
* of two things:
*
- * - If this is a standalone RealTek RTL8201(L) PHY,
- * we can determine the link speed by testing bit 0
- * in the magic, vendor-specific register at offset
- * 0x19.
+ * - If this is a standalone RealTek RTL8201(L) or
+ * workalike PHY, we can determine the link speed by
+ * testing bit 0 in the magic, vendor-specific register
+ * at offset 0x19.
*
* - If this is a RealTek MAC with integrated PHY, we
* can test the 'SPEED10' bit of the MAC's media status
* register.
*/
- if (rsc->sc_is_RTL8201L) {
+ if (!(phy->mii_mpd_model == 0 && phy->mii_mpd_rev == 0)) {
if (PHY_READ(phy, 0x0019) & 0x01)
mii->mii_media_active |= IFM_100_TX;
else
diff --git a/sys/dev/mii/rlswitch.c b/sys/dev/mii/rlswitch.c
index 0c1b62f..67c4ec3 100644
--- a/sys/dev/mii/rlswitch.c
+++ b/sys/dev/mii/rlswitch.c
@@ -91,10 +91,16 @@ static void rlswitch_phydump(device_t dev);
#endif
static const struct mii_phydesc rlswitches[] = {
- MII_PHY_DESC(xxREALTEK, RTL8305SC),
+ MII_PHY_DESC(REALTEK, RTL8305SC),
MII_PHY_END
};
+static const struct mii_phy_funcs rlswitch_funcs = {
+ rlswitch_service,
+ rlswitch_status,
+ mii_phy_reset
+};
+
static int
rlswitch_probe(device_t dev)
{
@@ -111,38 +117,19 @@ static int
rlswitch_attach(device_t dev)
{
struct mii_softc *sc;
- struct mii_attach_args *ma;
- struct mii_data *mii;
sc = device_get_softc(dev);
- ma = device_get_ivars(dev);
- sc->mii_dev = device_get_parent(dev);
- mii = ma->mii_data;
- LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list);
-
- sc->mii_flags = miibus_get_flags(dev);
- sc->mii_inst = mii->mii_instance++;
- sc->mii_phy = ma->mii_phyno;
- sc->mii_service = rlswitch_service;
- sc->mii_pdata = mii;
/*
* We handle all pseudo PHYs in a single instance.
*/
- sc->mii_flags |= MIIF_NOISOLATE;
-
-#define ADD(m, c) ifmedia_add(&mii->mii_media, (m), (c), NULL)
-
-#if 0
- ADD(IFM_MAKEWORD(IFM_ETHER, IFM_100_TX, IFM_LOOP, sc->mii_inst),
- MII_MEDIA_100_TX);
-#endif
+ mii_phy_dev_attach(dev, MIIF_NOISOLATE | MIIF_NOMANPAUSE,
+ &rlswitch_funcs, 0);
- sc->mii_capabilities = BMSR_100TXFDX & ma->mii_capmask;
+ sc->mii_capabilities = BMSR_100TXFDX & sc->mii_capmask;
device_printf(dev, " ");
mii_phy_add_media(sc);
printf("\n");
-#undef ADD
#ifdef RL_DEBUG
rlswitch_phydump(dev);
#endif
@@ -375,7 +362,7 @@ rlswitch_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
}
/* Update the media status. */
- rlswitch_status(sc);
+ PHY_STATUS(sc);
/* Callback if something changed. */
// mii_phy_update(sc, cmd);
@@ -390,7 +377,8 @@ rlswitch_status(struct mii_softc *phy)
mii->mii_media_status = IFM_AVALID;
mii->mii_media_active = IFM_ETHER;
mii->mii_media_status |= IFM_ACTIVE;
- mii->mii_media_active |= IFM_100_TX|IFM_FDX;
+ mii->mii_media_active |=
+ IFM_100_TX | IFM_FDX | mii_phy_flowstatus(phy);
}
#ifdef RL_DEBUG
diff --git a/sys/dev/mii/ruephy.c b/sys/dev/mii/ruephy.c
index fc2a6b94..a0d5441 100644
--- a/sys/dev/mii/ruephy.c
+++ b/sys/dev/mii/ruephy.c
@@ -88,6 +88,12 @@ static const struct mii_phydesc ruephys[] = {
MII_PHY_END
};
+static const struct mii_phy_funcs ruephy_funcs = {
+ ruephy_service,
+ ruephy_status,
+ ruephy_reset
+};
+
static int
ruephy_probe(device_t dev)
{
@@ -101,35 +107,9 @@ ruephy_probe(device_t dev)
static int
ruephy_attach(device_t dev)
{
- struct mii_softc *sc;
- struct mii_attach_args *ma;
- struct mii_data *mii;
-
- sc = device_get_softc(dev);
- ma = device_get_ivars(dev);
- sc->mii_dev = device_get_parent(dev);
- mii = ma->mii_data;
- LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list);
-
- sc->mii_flags = miibus_get_flags(dev);
- sc->mii_inst = mii->mii_instance++;
- sc->mii_phy = ma->mii_phyno;
- sc->mii_service = ruephy_service;
- sc->mii_pdata = mii;
-
- /*
- * Apparently, we can neither isolate nor do loopback on this PHY.
- */
- sc->mii_flags |= MIIF_NOISOLATE | MIIF_NOLOOP;
-
- ruephy_reset(sc);
-
- sc->mii_capabilities = PHY_READ(sc, MII_BMSR) & ma->mii_capmask;
- device_printf(dev, " ");
- mii_phy_add_media(sc);
- printf("\n");
- MIIBUS_MEDIAINIT(sc->mii_dev);
+ mii_phy_dev_attach(dev, MIIF_NOISOLATE | MIIF_NOMANPAUSE,
+ &ruephy_funcs, 1);
return (0);
}
@@ -181,14 +161,14 @@ ruephy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
break;
sc->mii_ticks = 0;
- ruephy_reset(sc);
+ PHY_RESET(sc);
if (mii_phy_auto(sc) == EJUSTRETURN)
return (0);
break;
}
/* Update the media status. */
- ruephy_status(sc);
+ PHY_STATUS(sc);
/* Callback if something changed. */
mii_phy_update(sc, cmd);
@@ -244,7 +224,8 @@ ruephy_status(struct mii_softc *phy)
mii->mii_media_active |= IFM_10_T;
if (msr & RUEPHY_MSR_DUPLEX)
- mii->mii_media_active |= IFM_FDX;
+ mii->mii_media_active |=
+ IFM_FDX | mii_phy_flowstatus(phy);
else
mii->mii_media_active |= IFM_HDX;
} else
diff --git a/sys/dev/mii/smcphy.c b/sys/dev/mii/smcphy.c
index a04e39f..b04a919 100644
--- a/sys/dev/mii/smcphy.c
+++ b/sys/dev/mii/smcphy.c
@@ -53,7 +53,7 @@ static int smcphy_probe(device_t);
static int smcphy_attach(device_t);
static int smcphy_service(struct mii_softc *, struct mii_data *, int);
-static int smcphy_reset(struct mii_softc *);
+static void smcphy_reset(struct mii_softc *);
static void smcphy_auto(struct mii_softc *, int);
static device_method_t smcphy_methods[] = {
@@ -77,10 +77,16 @@ static driver_t smcphy_driver = {
DRIVER_MODULE(smcphy, miibus, smcphy_driver, smcphy_devclass, 0, 0);
static const struct mii_phydesc smcphys[] = {
- MII_PHY_DESC(SMSC, LAN83C183),
+ MII_PHY_DESC(SEEQ, 84220),
MII_PHY_END
};
+static const struct mii_phy_funcs smcphy_funcs = {
+ smcphy_service,
+ ukphy_status,
+ smcphy_reset
+};
+
static int
smcphy_probe(device_t dev)
{
@@ -91,37 +97,12 @@ smcphy_probe(device_t dev)
static int
smcphy_attach(device_t dev)
{
- struct mii_softc *sc;
- struct mii_attach_args *ma;
- struct mii_data *mii;
+ struct mii_softc *sc;
sc = device_get_softc(dev);
- ma = device_get_ivars(dev);
- sc->mii_dev = device_get_parent(dev);
- mii = ma->mii_data;
- LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list);
-
- sc->mii_flags = miibus_get_flags(dev);
- sc->mii_inst = mii->mii_instance++;
- sc->mii_phy = ma->mii_phyno;
- sc->mii_service = smcphy_service;
- sc->mii_pdata = mii;
-
- sc->mii_flags |= MIIF_NOISOLATE | MIIF_NOLOOP;
-
- if (smcphy_reset(sc) != 0) {
- device_printf(dev, "reset failed\n");
- }
-
- /* Mask interrupts, we poll instead. */
- PHY_WRITE(sc, 0x1e, 0xffc0);
- sc->mii_capabilities = PHY_READ(sc, MII_BMSR) & ma->mii_capmask;
- device_printf(dev, " ");
- mii_phy_add_media(sc);
- printf("\n");
-
- MIIBUS_MEDIAINIT(sc->mii_dev);
+ mii_phy_dev_attach(dev, MIIF_NOISOLATE | MIIF_NOMANPAUSE,
+ &smcphy_funcs, 1);
mii_phy_setmedia(sc);
return (0);
@@ -184,22 +165,20 @@ smcphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
}
sc->mii_ticks = 0;
- if (smcphy_reset(sc) != 0) {
- device_printf(sc->mii_dev, "reset failed\n");
- }
+ PHY_RESET(sc);
smcphy_auto(sc, ife->ifm_media);
break;
}
/* Update the media status. */
- ukphy_status(sc);
+ PHY_STATUS(sc);
/* Callback if something changed. */
mii_phy_update(sc, cmd);
return (0);
}
-static int
+static void
smcphy_reset(struct mii_softc *sc)
{
u_int bmcr;
@@ -214,12 +193,13 @@ smcphy_reset(struct mii_softc *sc)
break;
}
- if (bmcr & BMCR_RESET) {
- return (EIO);
- }
+ if (bmcr & BMCR_RESET)
+ device_printf(sc->mii_dev, "reset failed\n");
PHY_WRITE(sc, MII_BMCR, 0x3000);
- return (0);
+
+ /* Mask interrupts, we poll instead. */
+ PHY_WRITE(sc, 0x1e, 0xffc0);
}
static void
diff --git a/sys/dev/mii/tdkphy.c b/sys/dev/mii/tdkphy.c
index df08c5e..83868ad 100644
--- a/sys/dev/mii/tdkphy.c
+++ b/sys/dev/mii/tdkphy.c
@@ -88,10 +88,16 @@ static int tdkphy_service(struct mii_softc *, struct mii_data *, int);
static void tdkphy_status(struct mii_softc *);
static const struct mii_phydesc tdkphys[] = {
- MII_PHY_DESC(TDK, 78Q2120),
+ MII_PHY_DESC(xxTSC, 78Q2120),
MII_PHY_END
};
+static const struct mii_phy_funcs tdkphy_funcs = {
+ tdkphy_service,
+ tdkphy_status,
+ mii_phy_reset
+};
+
static int
tdkphy_probe(device_t dev)
{
@@ -102,39 +108,8 @@ tdkphy_probe(device_t dev)
static int
tdkphy_attach(device_t dev)
{
- struct mii_softc *sc;
- struct mii_attach_args *ma;
- struct mii_data *mii;
- sc = device_get_softc(dev);
- ma = device_get_ivars(dev);
- sc->mii_dev = device_get_parent(dev);
- mii = ma->mii_data;
- LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list);
-
- if (bootverbose)
- device_printf(dev, "OUI 0x%06x, model 0x%04x, rev. %d\n",
- MII_OUI(ma->mii_id1, ma->mii_id2),
- MII_MODEL(ma->mii_id2), MII_REV(ma->mii_id2));
-
- sc->mii_flags = miibus_get_flags(dev);
- sc->mii_inst = mii->mii_instance++;
- sc->mii_phy = ma->mii_phyno;
- sc->mii_service = tdkphy_service;
- sc->mii_pdata = mii;
-
- /*
- * Apparently, we can't do loopback on this PHY.
- */
- sc->mii_flags |= MIIF_NOLOOP;
-
- mii_phy_reset(sc);
-
- sc->mii_capabilities = PHY_READ(sc, MII_BMSR) & ma->mii_capmask;
- device_printf(dev, " ");
- mii_phy_add_media(sc);
- printf("\n");
-
- MIIBUS_MEDIAINIT(sc->mii_dev);
+
+ mii_phy_dev_attach(dev, MIIF_NOMANPAUSE, &tdkphy_funcs, 1);
return (0);
}
@@ -163,7 +138,7 @@ tdkphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
}
/* Update the media status. */
- tdkphy_status(sc);
+ PHY_STATUS(sc);
if (sc->mii_pdata->mii_media_active & IFM_FDX)
PHY_WRITE(sc, MII_BMCR, PHY_READ(sc, MII_BMCR) | BMCR_FDX);
else
@@ -247,6 +222,8 @@ tdkphy_status(struct mii_softc *phy)
mii->mii_media_active |= IFM_10_T;
}
}
+ if ((mii->mii_media_active & IFM_FDX) != 0)
+ mii->mii_media_active |= mii_phy_flowstatus(phy);
} else
mii->mii_media_active = ife->ifm_media;
}
diff --git a/sys/dev/mii/tlphy.c b/sys/dev/mii/tlphy.c
index d23cfb3..c99c754 100644
--- a/sys/dev/mii/tlphy.c
+++ b/sys/dev/mii/tlphy.c
@@ -113,13 +113,19 @@ DRIVER_MODULE(tlphy, miibus, tlphy_driver, tlphy_devclass, 0, 0);
static int tlphy_service(struct mii_softc *, struct mii_data *, int);
static int tlphy_auto(struct tlphy_softc *);
static void tlphy_acomp(struct tlphy_softc *);
-static void tlphy_status(struct tlphy_softc *);
+static void tlphy_status(struct mii_softc *);
static const struct mii_phydesc tlphys[] = {
- MII_PHY_DESC(xxTI, TLAN10T),
+ MII_PHY_DESC(TI, TLAN10T),
MII_PHY_END
};
+static const struct mii_phy_funcs tlphy_funcs = {
+ tlphy_service,
+ tlphy_status,
+ mii_phy_reset
+};
+
static int
tlphy_probe(device_t dev)
{
@@ -134,24 +140,13 @@ static int
tlphy_attach(device_t dev)
{
device_t *devlist;
- struct tlphy_softc *sc;
- struct mii_softc *other;
- struct mii_attach_args *ma;
- struct mii_data *mii;
+ struct mii_softc *other, *sc_mii;
const char *sep = "";
int capmask, devs, i;
- sc = device_get_softc(dev);
- ma = device_get_ivars(dev);
- sc->sc_mii.mii_dev = device_get_parent(dev);
- mii = device_get_softc(sc->sc_mii.mii_dev);
- LIST_INSERT_HEAD(&mii->mii_phys, &sc->sc_mii, mii_list);
+ sc_mii = device_get_softc(dev);
- sc->sc_mii.mii_flags = miibus_get_flags(dev);
- sc->sc_mii.mii_inst = mii->mii_instance;
- sc->sc_mii.mii_phy = ma->mii_phyno;
- sc->sc_mii.mii_service = tlphy_service;
- sc->sc_mii.mii_pdata = mii;
+ mii_phy_dev_attach(dev, MIIF_NOMANPAUSE, &tlphy_funcs, 0);
/*
* Note that if we're on a device that also supports 100baseTX,
@@ -160,8 +155,8 @@ tlphy_attach(device_t dev)
* UTP connector.
*/
capmask = BMSR_DEFCAPMASK;
- if (mii->mii_instance &&
- device_get_children(sc->sc_mii.mii_dev, &devlist, &devs) == 0) {
+ if (sc_mii->mii_inst &&
+ device_get_children(sc_mii->mii_dev, &devlist, &devs) == 0) {
for (i = 0; i < devs; i++) {
if (devlist[i] != dev) {
other = device_get_softc(devlist[i]);
@@ -172,43 +167,38 @@ tlphy_attach(device_t dev)
free(devlist, M_TEMP);
}
- mii->mii_instance++;
-
- mii_phy_reset(&sc->sc_mii);
-
- sc->sc_mii.mii_capabilities =
- PHY_READ(&sc->sc_mii, MII_BMSR) & capmask;
+ PHY_RESET(sc_mii);
-#define ADD(m, c) ifmedia_add(&mii->mii_media, (m), (c), NULL)
-
- ADD(IFM_MAKEWORD(IFM_ETHER, IFM_10_T, IFM_LOOP, sc->sc_mii.mii_inst),
- MII_MEDIA_100_TX);
+ sc_mii->mii_capabilities = PHY_READ(sc_mii, MII_BMSR) & capmask;
+#define ADD(m, c) \
+ ifmedia_add(&sc_mii->mii_pdata->mii_media, (m), (c), NULL)
#define PRINT(s) printf("%s%s", sep, s); sep = ", "
- if ((sc->sc_mii.mii_flags & (MIIF_MACPRIV0 | MIIF_MACPRIV1)) != 0 &&
- (sc->sc_mii.mii_capabilities & BMSR_MEDIAMASK) != 0)
+ if ((sc_mii->mii_flags & (MIIF_MACPRIV0 | MIIF_MACPRIV1)) != 0 &&
+ (sc_mii->mii_capabilities & BMSR_MEDIAMASK) != 0)
device_printf(dev, " ");
- if ((sc->sc_mii.mii_flags & MIIF_MACPRIV0) != 0) {
- ADD(IFM_MAKEWORD(IFM_ETHER, IFM_10_2, 0, sc->sc_mii.mii_inst),
+ if ((sc_mii->mii_flags & MIIF_MACPRIV0) != 0) {
+ ADD(IFM_MAKEWORD(IFM_ETHER, IFM_10_2, 0, sc_mii->mii_inst),
0);
PRINT("10base2/BNC");
}
- if ((sc->sc_mii.mii_flags & MIIF_MACPRIV1) != 0) {
- ADD(IFM_MAKEWORD(IFM_ETHER, IFM_10_5, 0, sc->sc_mii.mii_inst),
+ if ((sc_mii->mii_flags & MIIF_MACPRIV1) != 0) {
+ ADD(IFM_MAKEWORD(IFM_ETHER, IFM_10_5, 0, sc_mii->mii_inst),
0);
PRINT("10base5/AUI");
}
- if ((sc->sc_mii.mii_capabilities & BMSR_MEDIAMASK) != 0) {
+ if ((sc_mii->mii_capabilities & BMSR_MEDIAMASK) != 0) {
printf("%s", sep);
- mii_phy_add_media(&sc->sc_mii);
+ mii_phy_add_media(sc_mii);
}
- if ((sc->sc_mii.mii_flags & (MIIF_MACPRIV0 | MIIF_MACPRIV1)) != 0 &&
- (sc->sc_mii.mii_capabilities & BMSR_MEDIAMASK) != 0)
+ if ((sc_mii->mii_flags & (MIIF_MACPRIV0 | MIIF_MACPRIV1)) != 0 &&
+ (sc_mii->mii_capabilities & BMSR_MEDIAMASK) != 0)
printf("\n");
#undef ADD
#undef PRINT
- MIIBUS_MEDIAINIT(sc->sc_mii.mii_dev);
+
+ MIIBUS_MEDIAINIT(sc_mii->mii_dev);
return (0);
}
@@ -287,13 +277,13 @@ tlphy_service(struct mii_softc *self, struct mii_data *mii, int cmd)
break;
sc->sc_mii.mii_ticks = 0;
- mii_phy_reset(&sc->sc_mii);
+ PHY_RESET(&sc->sc_mii);
(void)tlphy_auto(sc);
return (0);
}
/* Update the media status. */
- tlphy_status(sc);
+ PHY_STATUS(self);
/* Callback if something changed. */
mii_phy_update(&sc->sc_mii, cmd);
@@ -301,8 +291,9 @@ tlphy_service(struct mii_softc *self, struct mii_data *mii, int cmd)
}
static void
-tlphy_status(struct tlphy_softc *sc)
+tlphy_status(struct mii_softc *self)
{
+ struct tlphy_softc *sc = (struct tlphy_softc *)self;
struct mii_data *mii = sc->sc_mii.mii_pdata;
int bmsr, bmcr, tlctrl;
@@ -338,7 +329,7 @@ tlphy_status(struct tlphy_softc *sc)
* just have to report what's in the BMCR.
*/
if (bmcr & BMCR_FDX)
- mii->mii_media_active |= IFM_FDX;
+ mii->mii_media_active |= IFM_FDX | mii_phy_flowstatus(self);
else
mii->mii_media_active |= IFM_HDX;
mii->mii_media_active |= IFM_10_T;
diff --git a/sys/dev/mii/truephy.c b/sys/dev/mii/truephy.c
index bb99df2..86480f1 100644
--- a/sys/dev/mii/truephy.c
+++ b/sys/dev/mii/truephy.c
@@ -91,6 +91,12 @@ static driver_t truephy_driver = {
DRIVER_MODULE(truephy, miibus, truephy_driver, truephy_devclass, 0, 0);
+static const struct mii_phy_funcs truephy_funcs = {
+ truephy_service,
+ truephy_status,
+ truephy_reset
+};
+
static const struct truephy_dsp {
uint16_t index;
uint16_t data;
@@ -140,31 +146,15 @@ static int
truephy_attach(device_t dev)
{
struct mii_softc *sc;
- struct mii_attach_args *ma;
- struct mii_data *mii;
sc = device_get_softc(dev);
- ma = device_get_ivars(dev);
-
- sc->mii_phy = ma->mii_phyno;
- sc->mii_dev = device_get_parent(dev);
- mii = ma->mii_data;
- LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list);
- sc->mii_flags = miibus_get_flags(dev);
- sc->mii_inst = mii->mii_instance++;
- sc->mii_phy = ma->mii_phyno;
- sc->mii_service = truephy_service;
- sc->mii_pdata = mii;
+ mii_phy_dev_attach(dev, MIIF_NOISOLATE | MIIF_NOMANPAUSE,
+ &truephy_funcs, 0);
- sc->mii_flags |= MIIF_NOISOLATE | MIIF_NOLOOP;
-
- if (MII_MODEL(ma->mii_id2) == MII_MODEL_AGERE_ET1011)
- mii_phy_reset(sc);
- else
- truephy_reset(sc);
+ PHY_RESET(sc);
- sc->mii_capabilities = PHY_READ(sc, MII_BMSR) & ma->mii_capmask;
+ sc->mii_capabilities = PHY_READ(sc, MII_BMSR) & sc->mii_capmask;
if (sc->mii_capabilities & BMSR_EXTSTAT) {
sc->mii_extcapabilities = PHY_READ(sc, MII_EXTSR);
/* No 1000baseT half-duplex support */
@@ -210,7 +200,7 @@ truephy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
if (IFM_SUBTYPE(ife->ifm_media) == IFM_1000_T) {
PHY_WRITE(sc, MII_BMCR,
- bmcr | BMCR_AUTOEN | BMCR_STARTNEG);
+ bmcr | BMCR_AUTOEN | BMCR_STARTNEG);
}
}
break;
@@ -222,7 +212,7 @@ truephy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
}
/* Update the media status. */
- truephy_status(sc);
+ PHY_STATUS(sc);
/* Callback if something changed. */
mii_phy_update(sc, cmd);
@@ -234,6 +224,11 @@ truephy_reset(struct mii_softc *sc)
{
int i;
+ if (sc->mii_mpd_model == MII_MODEL_AGERE_ET1011) {
+ mii_phy_reset(sc);
+ return;
+ }
+
for (i = 0; i < 2; ++i) {
PHY_READ(sc, MII_PHYIDR1);
PHY_READ(sc, MII_PHYIDR2);
@@ -326,7 +321,7 @@ truephy_status(struct mii_softc *sc)
}
if (sr & TRUEPHY_SR_FDX)
- mii->mii_media_active |= IFM_FDX;
+ mii->mii_media_active |= IFM_FDX | mii_phy_flowstatus(sc);
else
mii->mii_media_active |= IFM_HDX;
}
diff --git a/sys/dev/mii/ukphy.c b/sys/dev/mii/ukphy.c
index 10842b7..9697176 100644
--- a/sys/dev/mii/ukphy.c
+++ b/sys/dev/mii/ukphy.c
@@ -101,6 +101,12 @@ DRIVER_MODULE(ukphy, miibus, ukphy_driver, ukphy_devclass, 0, 0);
static int ukphy_service(struct mii_softc *, struct mii_data *, int);
+static const struct mii_phy_funcs ukphy_funcs = {
+ ukphy_service,
+ ukphy_status,
+ mii_phy_reset
+};
+
static int
ukphy_probe(device_t dev)
{
@@ -116,38 +122,10 @@ static int
ukphy_attach(device_t dev)
{
struct mii_softc *sc;
- struct mii_attach_args *ma;
- struct mii_data *mii;
sc = device_get_softc(dev);
- ma = device_get_ivars(dev);
- sc->mii_dev = device_get_parent(dev);
- mii = ma->mii_data;
- LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list);
-
- if (bootverbose)
- device_printf(dev, "OUI 0x%06x, model 0x%04x, rev. %d\n",
- MII_OUI(ma->mii_id1, ma->mii_id2),
- MII_MODEL(ma->mii_id2), MII_REV(ma->mii_id2));
-
- sc->mii_flags = miibus_get_flags(dev);
- sc->mii_inst = mii->mii_instance++;
- sc->mii_phy = ma->mii_phyno;
- sc->mii_service = ukphy_service;
- sc->mii_pdata = mii;
-
- sc->mii_flags |= MIIF_NOMANPAUSE;
-
- mii_phy_reset(sc);
-
- sc->mii_capabilities = PHY_READ(sc, MII_BMSR) & ma->mii_capmask;
- if (sc->mii_capabilities & BMSR_EXTSTAT)
- sc->mii_extcapabilities = PHY_READ(sc, MII_EXTSR);
- device_printf(dev, " ");
- mii_phy_add_media(sc);
- printf("\n");
-
- MIIBUS_MEDIAINIT(sc->mii_dev);
+
+ mii_phy_dev_attach(dev, MIIF_NOMANPAUSE, &ukphy_funcs, 1);
mii_phy_setmedia(sc);
return (0);
@@ -178,7 +156,7 @@ ukphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
}
/* Update the media status. */
- ukphy_status(sc);
+ PHY_STATUS(sc);
/* Callback if something changed. */
mii_phy_update(sc, cmd);
diff --git a/sys/dev/mii/xmphy.c b/sys/dev/mii/xmphy.c
index 9867f0e..75d3e27 100644
--- a/sys/dev/mii/xmphy.c
+++ b/sys/dev/mii/xmphy.c
@@ -84,11 +84,17 @@ static void xmphy_status(struct mii_softc *);
static int xmphy_mii_phy_auto(struct mii_softc *);
static const struct mii_phydesc xmphys[] = {
- { MII_OUI_xxXAQTI, MII_MODEL_XAQTI_XMACII, MII_STR_XAQTI_XMACII },
- MII_PHY_DESC(JATO, BASEX),
+ MII_PHY_DESC(xxJATO, BASEX),
+ MII_PHY_DESC(xxXAQTI, XMACII),
MII_PHY_END
};
+static const struct mii_phy_funcs xmphy_funcs = {
+ xmphy_service,
+ xmphy_status,
+ mii_phy_reset
+};
+
static int
xmphy_probe(device_t dev)
{
@@ -100,28 +106,17 @@ static int
xmphy_attach(device_t dev)
{
struct mii_softc *sc;
- struct mii_attach_args *ma;
- struct mii_data *mii;
const char *sep = "";
sc = device_get_softc(dev);
- ma = device_get_ivars(dev);
- sc->mii_dev = device_get_parent(dev);
- mii = ma->mii_data;
- LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list);
-
- sc->mii_flags = miibus_get_flags(dev);
- sc->mii_inst = mii->mii_instance++;
- sc->mii_phy = ma->mii_phyno;
- sc->mii_service = xmphy_service;
- sc->mii_pdata = mii;
-
- sc->mii_flags |= MIIF_NOISOLATE;
+
+ mii_phy_dev_attach(dev, MIIF_NOISOLATE | MIIF_NOMANPAUSE,
+ &xmphy_funcs, 0);
sc->mii_anegticks = MII_ANEGTICKS;
- mii_phy_reset(sc);
+ PHY_RESET(sc);
-#define ADD(m, c) ifmedia_add(&mii->mii_media, (m), (c), NULL)
+#define ADD(m, c) ifmedia_add(&sc->mii_pdata->mii_media, (m), (c), NULL)
#define PRINT(s) printf("%s%s", sep, s); sep = ", "
device_printf(dev, " ");
@@ -134,6 +129,7 @@ xmphy_attach(device_t dev)
PRINT("auto");
printf("\n");
+
#undef ADD
#undef PRINT
@@ -170,7 +166,7 @@ xmphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
(void)xmphy_mii_phy_auto(sc);
break;
case IFM_1000_SX:
- mii_phy_reset(sc);
+ PHY_RESET(sc);
if ((ife->ifm_media & IFM_FDX) != 0) {
PHY_WRITE(sc, XMPHY_MII_ANAR, XMPHY_ANAR_FDX);
PHY_WRITE(sc, XMPHY_MII_BMCR, XMPHY_BMCR_FDX);
@@ -212,7 +208,7 @@ xmphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
sc->mii_ticks = 0;
- mii_phy_reset(sc);
+ PHY_RESET(sc);
xmphy_mii_phy_auto(sc);
return (0);
}
@@ -247,7 +243,6 @@ xmphy_status(struct mii_softc *sc)
if (bmcr & XMPHY_BMCR_LOOP)
mii->mii_media_active |= IFM_LOOP;
-
if (bmcr & XMPHY_BMCR_AUTOEN) {
if ((bmsr & XMPHY_BMSR_ACOMP) == 0) {
if (bmsr & XMPHY_BMSR_LINK) {
diff --git a/sys/dev/nfe/if_nfe.c b/sys/dev/nfe/if_nfe.c
index 094fe03..6cdfa34 100644
--- a/sys/dev/nfe/if_nfe.c
+++ b/sys/dev/nfe/if_nfe.c
@@ -3295,14 +3295,10 @@ nfe_set_linkspeed(struct nfe_softc *sc)
break;
}
}
- phyno = 0;
- if (mii->mii_instance) {
- miisc = LIST_FIRST(&mii->mii_phys);
- phyno = miisc->mii_phy;
- LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
- mii_phy_reset(miisc);
- } else
- return;
+ miisc = LIST_FIRST(&mii->mii_phys);
+ phyno = miisc->mii_phy;
+ LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
+ PHY_RESET(miisc);
nfe_miibus_writereg(sc->nfe_dev, phyno, MII_100T2CR, 0);
nfe_miibus_writereg(sc->nfe_dev, phyno,
MII_ANAR, ANAR_TX_FD | ANAR_TX | ANAR_10_FD | ANAR_10 | ANAR_CSMA);
diff --git a/sys/dev/nge/if_nge.c b/sys/dev/nge/if_nge.c
index ef92ff5..dd16606 100644
--- a/sys/dev/nge/if_nge.c
+++ b/sys/dev/nge/if_nge.c
@@ -2396,10 +2396,8 @@ nge_mediachange(struct ifnet *ifp)
sc = ifp->if_softc;
NGE_LOCK(sc);
mii = device_get_softc(sc->nge_miibus);
- if (mii->mii_instance) {
- LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
- mii_phy_reset(miisc);
- }
+ LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
+ PHY_RESET(miisc);
error = mii_mediachg(mii);
NGE_UNLOCK(sc);
diff --git a/sys/dev/nve/if_nve.c b/sys/dev/nve/if_nve.c
index b04ac19..7bb5c58 100644
--- a/sys/dev/nve/if_nve.c
+++ b/sys/dev/nve/if_nve.c
@@ -1177,19 +1177,15 @@ nve_ifmedia_upd_locked(struct ifnet *ifp)
{
struct nve_softc *sc = ifp->if_softc;
struct mii_data *mii;
+ struct mii_softc *miisc;
DEBUGOUT(NVE_DEBUG_MII, "nve: nve_ifmedia_upd\n");
NVE_LOCK_ASSERT(sc);
mii = device_get_softc(sc->miibus);
- if (mii->mii_instance) {
- struct mii_softc *miisc;
- for (miisc = LIST_FIRST(&mii->mii_phys); miisc != NULL;
- miisc = LIST_NEXT(miisc, mii_list)) {
- mii_phy_reset(miisc);
- }
- }
+ LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
+ PHY_RESET(miisc);
mii_mediachg(mii);
}
diff --git a/sys/dev/pcn/if_pcn.c b/sys/dev/pcn/if_pcn.c
index d7314a9..2ebd35c 100644
--- a/sys/dev/pcn/if_pcn.c
+++ b/sys/dev/pcn/if_pcn.c
@@ -634,14 +634,13 @@ pcn_attach(dev)
ifp->if_snd.ifq_maxlen = PCN_TX_LIST_CNT - 1;
/*
- * Do MII setup. Note that loopback support isn't implemented.
+ * Do MII setup.
* See the comment in pcn_miibus_readreg() for why we can't
* universally pass MIIF_NOISOLATE here.
*/
sc->pcn_extphyaddr = -1;
error = mii_attach(dev, &sc->pcn_miibus, ifp, pcn_ifmedia_upd,
- pcn_ifmedia_sts, BMSR_DEFCAPMASK, MII_PHY_ANY, MII_OFFSET_ANY,
- MIIF_NOLOOP);
+ pcn_ifmedia_sts, BMSR_DEFCAPMASK, MII_PHY_ANY, MII_OFFSET_ANY, 0);
if (error != 0) {
device_printf(dev, "attaching PHYs failed\n");
goto fail;
diff --git a/sys/dev/sf/if_sf.c b/sys/dev/sf/if_sf.c
index 7edb976..e919f55 100644
--- a/sys/dev/sf/if_sf.c
+++ b/sys/dev/sf/if_sf.c
@@ -528,17 +528,15 @@ sf_ifmedia_upd(struct ifnet *ifp)
{
struct sf_softc *sc;
struct mii_data *mii;
+ struct mii_softc *miisc;
int error;
sc = ifp->if_softc;
SF_LOCK(sc);
mii = device_get_softc(sc->sf_miibus);
- if (mii->mii_instance) {
- struct mii_softc *miisc;
- LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
- mii_phy_reset(miisc);
- }
+ LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
+ PHY_RESET(miisc);
error = mii_mediachg(mii);
SF_UNLOCK(sc);
diff --git a/sys/dev/sge/if_sge.c b/sys/dev/sge/if_sge.c
index f379590..03bf900 100644
--- a/sys/dev/sge/if_sge.c
+++ b/sys/dev/sge/if_sge.c
@@ -1715,16 +1715,14 @@ sge_ifmedia_upd(struct ifnet *ifp)
{
struct sge_softc *sc;
struct mii_data *mii;
+ struct mii_softc *miisc;
int error;
sc = ifp->if_softc;
SGE_LOCK(sc);
mii = device_get_softc(sc->sge_miibus);
- if (mii->mii_instance) {
- struct mii_softc *miisc;
- LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
- mii_phy_reset(miisc);
- }
+ LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
+ PHY_RESET(miisc);
error = mii_mediachg(mii);
SGE_UNLOCK(sc);
diff --git a/sys/dev/sis/if_sis.c b/sys/dev/sis/if_sis.c
index 39bd584..63417a0 100644
--- a/sys/dev/sis/if_sis.c
+++ b/sys/dev/sis/if_sis.c
@@ -2209,17 +2209,15 @@ sis_ifmedia_upd(struct ifnet *ifp)
{
struct sis_softc *sc;
struct mii_data *mii;
+ struct mii_softc *miisc;
int error;
sc = ifp->if_softc;
SIS_LOCK(sc);
mii = device_get_softc(sc->sis_miibus);
- if (mii->mii_instance) {
- struct mii_softc *miisc;
- LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
- mii_phy_reset(miisc);
- }
+ LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
+ PHY_RESET(miisc);
error = mii_mediachg(mii);
SIS_UNLOCK(sc);
diff --git a/sys/dev/ste/if_ste.c b/sys/dev/ste/if_ste.c
index 3074538..846761c 100644
--- a/sys/dev/ste/if_ste.c
+++ b/sys/dev/ste/if_ste.c
@@ -458,10 +458,8 @@ ste_ifmedia_upd(struct ifnet *ifp)
sc = ifp->if_softc;
STE_LOCK(sc);
mii = device_get_softc(sc->ste_miibus);
- if (mii->mii_instance) {
- LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
- mii_phy_reset(miisc);
- }
+ LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
+ PHY_RESET(miisc);
error = mii_mediachg(mii);
STE_UNLOCK(sc);
diff --git a/sys/dev/tx/if_tx.c b/sys/dev/tx/if_tx.c
index 12843ac..c977909 100644
--- a/sys/dev/tx/if_tx.c
+++ b/sys/dev/tx/if_tx.c
@@ -1053,8 +1053,7 @@ epic_ifmedia_upd_locked(struct ifnet *ifp)
sc->phyid = EPIC_UNKN_PHY;
/* Lookup selected PHY. */
- for (miisc = LIST_FIRST(&mii->mii_phys); miisc != NULL;
- miisc = LIST_NEXT(miisc, mii_list)) {
+ LIST_FOREACH(miisc, &mii->mii_phys, mii_list) {
if (IFM_INST(media) == miisc->mii_inst) {
sc->physc = miisc;
break;
@@ -1071,12 +1070,12 @@ epic_ifmedia_upd_locked(struct ifnet *ifp)
oui = MII_OUI(id1, id2);
model = MII_MODEL(id2);
switch (oui) {
- case MII_OUI_QUALSEMI:
- if (model == MII_MODEL_QUALSEMI_QS6612)
+ case MII_OUI_xxQUALSEMI:
+ if (model == MII_MODEL_xxQUALSEMI_QS6612)
sc->phyid = EPIC_QS6612_PHY;
break;
- case MII_OUI_xxALTIMA:
- if (model == MII_MODEL_xxALTIMA_AC101)
+ case MII_OUI_ALTIMA:
+ if (model == MII_MODEL_ALTIMA_AC101)
sc->phyid = EPIC_AC101_PHY;
break;
case MII_OUI_xxLEVEL1:
diff --git a/sys/dev/usb/net/if_aue.c b/sys/dev/usb/net/if_aue.c
index 6ef7f8b..3716844 100644
--- a/sys/dev/usb/net/if_aue.c
+++ b/sys/dev/usb/net/if_aue.c
@@ -1011,16 +1011,13 @@ aue_ifmedia_upd(struct ifnet *ifp)
{
struct aue_softc *sc = ifp->if_softc;
struct mii_data *mii = GET_MII(sc);
+ struct mii_softc *miisc;
AUE_LOCK_ASSERT(sc, MA_OWNED);
sc->sc_flags &= ~AUE_FLAG_LINK;
- if (mii->mii_instance) {
- struct mii_softc *miisc;
-
- LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
- mii_phy_reset(miisc);
- }
+ LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
+ PHY_RESET(miisc);
mii_mediachg(mii);
return (0);
}
diff --git a/sys/dev/usb/net/if_axe.c b/sys/dev/usb/net/if_axe.c
index 56e7012..fbe63de 100644
--- a/sys/dev/usb/net/if_axe.c
+++ b/sys/dev/usb/net/if_axe.c
@@ -417,16 +417,13 @@ axe_ifmedia_upd(struct ifnet *ifp)
{
struct axe_softc *sc = ifp->if_softc;
struct mii_data *mii = GET_MII(sc);
+ struct mii_softc *miisc;
int error;
AXE_LOCK_ASSERT(sc, MA_OWNED);
- if (mii->mii_instance) {
- struct mii_softc *miisc;
-
- LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
- mii_phy_reset(miisc);
- }
+ LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
+ PHY_RESET(miisc);
error = mii_mediachg(mii);
return (error);
}
diff --git a/sys/dev/usb/net/if_rue.c b/sys/dev/usb/net/if_rue.c
index f5ac14e..1dadd57 100644
--- a/sys/dev/usb/net/if_rue.c
+++ b/sys/dev/usb/net/if_rue.c
@@ -868,16 +868,13 @@ rue_ifmedia_upd(struct ifnet *ifp)
{
struct rue_softc *sc = ifp->if_softc;
struct mii_data *mii = GET_MII(sc);
+ struct mii_softc *miisc;
RUE_LOCK_ASSERT(sc, MA_OWNED);
sc->sc_flags &= ~RUE_FLAG_LINK;
- if (mii->mii_instance) {
- struct mii_softc *miisc;
-
- LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
- mii_phy_reset(miisc);
- }
+ LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
+ PHY_RESET(miisc);
mii_mediachg(mii);
return (0);
}
diff --git a/sys/dev/usb/net/if_udav.c b/sys/dev/usb/net/if_udav.c
index 0ab237f..a1a0a8d 100644
--- a/sys/dev/usb/net/if_udav.c
+++ b/sys/dev/usb/net/if_udav.c
@@ -732,16 +732,13 @@ udav_ifmedia_upd(struct ifnet *ifp)
{
struct udav_softc *sc = ifp->if_softc;
struct mii_data *mii = GET_MII(sc);
+ struct mii_softc *miisc;
UDAV_LOCK_ASSERT(sc, MA_OWNED);
sc->sc_flags &= ~UDAV_FLAG_LINK;
- if (mii->mii_instance) {
- struct mii_softc *miisc;
-
- LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
- mii_phy_reset(miisc);
- }
+ LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
+ PHY_RESET(miisc);
mii_mediachg(mii);
return (0);
}
diff --git a/sys/dev/vr/if_vr.c b/sys/dev/vr/if_vr.c
index 4dabdc3..906ee1c 100644
--- a/sys/dev/vr/if_vr.c
+++ b/sys/dev/vr/if_vr.c
@@ -2141,10 +2141,8 @@ vr_ifmedia_upd(struct ifnet *ifp)
sc = ifp->if_softc;
VR_LOCK(sc);
mii = device_get_softc(sc->vr_miibus);
- if (mii->mii_instance) {
- LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
- mii_phy_reset(miisc);
- }
+ LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
+ PHY_RESET(miisc);
error = mii_mediachg(mii);
VR_UNLOCK(sc);
diff --git a/sys/dev/vte/if_vte.c b/sys/dev/vte/if_vte.c
index 5dec0f4..1b38dec 100644
--- a/sys/dev/vte/if_vte.c
+++ b/sys/dev/vte/if_vte.c
@@ -312,10 +312,8 @@ vte_mediachange_locked(struct ifnet *ifp)
sc = ifp->if_softc;
mii = device_get_softc(sc->vte_miibus);
- if (mii->mii_instance != 0) {
- LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
- mii_phy_reset(miisc);
- }
+ LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
+ PHY_RESET(miisc);
error = mii_mediachg(mii);
return (error);
diff --git a/sys/dev/wb/if_wb.c b/sys/dev/wb/if_wb.c
index 33ad95a..f924d3e 100644
--- a/sys/dev/wb/if_wb.c
+++ b/sys/dev/wb/if_wb.c
@@ -681,6 +681,7 @@ wb_reset(sc)
{
register int i;
struct mii_data *mii;
+ struct mii_softc *miisc;
CSR_WRITE_4(sc, WB_NETCFG, 0);
CSR_WRITE_4(sc, WB_BUSCTL, 0);
@@ -705,16 +706,8 @@ wb_reset(sc)
return;
mii = device_get_softc(sc->wb_miibus);
- if (mii == NULL)
- return;
-
- if (mii->mii_instance) {
- struct mii_softc *miisc;
- LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
- mii_phy_reset(miisc);
- }
-
- return;
+ LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
+ PHY_RESET(miisc);
}
static void
@@ -725,9 +718,6 @@ wb_fixmedia(sc)
struct ifnet *ifp;
u_int32_t media;
- if (sc->wb_miibus == NULL)
- return;
-
mii = device_get_softc(sc->wb_miibus);
ifp = sc->wb_ifp;
@@ -742,8 +732,6 @@ wb_fixmedia(sc)
return;
ifmedia_set(&mii->mii_media, media);
-
- return;
}
/*
diff --git a/sys/fs/nfs/nfs_commonport.c b/sys/fs/nfs/nfs_commonport.c
index d9780e4..ee37cbc 100644
--- a/sys/fs/nfs/nfs_commonport.c
+++ b/sys/fs/nfs/nfs_commonport.c
@@ -404,8 +404,64 @@ nfssvc_call(struct thread *p, struct nfssvc_args *uap, struct ucred *cred)
} else if (uap->flag & NFSSVC_GETSTATS) {
error = copyout(&newnfsstats,
CAST_USER_ADDR_T(uap->argp), sizeof (newnfsstats));
- if ((uap->flag & NFSSVC_ZEROSTATS) != 0 && error == 0)
- bzero(&newnfsstats, sizeof(newnfsstats));
+ if (error == 0) {
+ if ((uap->flag & NFSSVC_ZEROCLTSTATS) != 0) {
+ newnfsstats.attrcache_hits = 0;
+ newnfsstats.attrcache_misses = 0;
+ newnfsstats.lookupcache_hits = 0;
+ newnfsstats.lookupcache_misses = 0;
+ newnfsstats.direofcache_hits = 0;
+ newnfsstats.direofcache_misses = 0;
+ newnfsstats.accesscache_hits = 0;
+ newnfsstats.accesscache_misses = 0;
+ newnfsstats.biocache_reads = 0;
+ newnfsstats.read_bios = 0;
+ newnfsstats.read_physios = 0;
+ newnfsstats.biocache_writes = 0;
+ newnfsstats.write_bios = 0;
+ newnfsstats.write_physios = 0;
+ newnfsstats.biocache_readlinks = 0;
+ newnfsstats.readlink_bios = 0;
+ newnfsstats.biocache_readdirs = 0;
+ newnfsstats.readdir_bios = 0;
+ newnfsstats.rpcretries = 0;
+ newnfsstats.rpcrequests = 0;
+ newnfsstats.rpctimeouts = 0;
+ newnfsstats.rpcunexpected = 0;
+ newnfsstats.rpcinvalid = 0;
+ bzero(newnfsstats.rpccnt,
+ sizeof(newnfsstats.rpccnt));
+ }
+ if ((uap->flag & NFSSVC_ZEROSRVSTATS) != 0) {
+ newnfsstats.srvrpc_errs = 0;
+ newnfsstats.srv_errs = 0;
+ newnfsstats.srvcache_inproghits = 0;
+ newnfsstats.srvcache_idemdonehits = 0;
+ newnfsstats.srvcache_nonidemdonehits = 0;
+ newnfsstats.srvcache_misses = 0;
+ newnfsstats.srvcache_tcppeak = 0;
+ newnfsstats.srvcache_size = 0;
+ newnfsstats.srvclients = 0;
+ newnfsstats.srvopenowners = 0;
+ newnfsstats.srvopens = 0;
+ newnfsstats.srvlockowners = 0;
+ newnfsstats.srvlocks = 0;
+ newnfsstats.srvdelegates = 0;
+ newnfsstats.clopenowners = 0;
+ newnfsstats.clopens = 0;
+ newnfsstats.cllockowners = 0;
+ newnfsstats.cllocks = 0;
+ newnfsstats.cldelegates = 0;
+ newnfsstats.cllocalopenowners = 0;
+ newnfsstats.cllocalopens = 0;
+ newnfsstats.cllocallockowners = 0;
+ newnfsstats.cllocallocks = 0;
+ bzero(newnfsstats.srvrpccnt,
+ sizeof(newnfsstats.srvrpccnt));
+ bzero(newnfsstats.cbrpccnt,
+ sizeof(newnfsstats.cbrpccnt));
+ }
+ }
return (error);
} else if (uap->flag & NFSSVC_NFSUSERDPORT) {
u_short sockport;
diff --git a/sys/fs/nfsclient/nfs_clsubs.c b/sys/fs/nfsclient/nfs_clsubs.c
index 2ea475e..7bff646 100644
--- a/sys/fs/nfsclient/nfs_clsubs.c
+++ b/sys/fs/nfsclient/nfs_clsubs.c
@@ -167,7 +167,7 @@ ncl_printf(const char *fmt, ...)
mtx_lock(&Giant);
va_start(ap, fmt);
- printf(fmt, ap);
+ vprintf(fmt, ap);
va_end(ap);
mtx_unlock(&Giant);
}
diff --git a/sys/fs/nfsclient/nfs_clvfsops.c b/sys/fs/nfsclient/nfs_clvfsops.c
index 9280f41..8b4fc6a 100644
--- a/sys/fs/nfsclient/nfs_clvfsops.c
+++ b/sys/fs/nfsclient/nfs_clvfsops.c
@@ -716,7 +716,7 @@ static const char *nfs_opts[] = { "from", "nfs_args",
"retrans", "acregmin", "acregmax", "acdirmin", "acdirmax", "resvport",
"readahead", "hostname", "timeout", "addr", "fh", "nfsv3", "sec",
"principal", "nfsv4", "gssname", "allgssname", "dirpath",
- "negnametimeo",
+ "negnametimeo", "nocto",
NULL };
/*
@@ -833,6 +833,8 @@ nfs_mount(struct mount *mp)
}
if (vfs_getopt(mp->mnt_optnew, "allgssname", NULL, NULL) == 0)
args.flags |= NFSMNT_ALLGSSNAME;
+ if (vfs_getopt(mp->mnt_optnew, "nocto", NULL, NULL) == 0)
+ args.flags |= NFSMNT_NOCTO;
if (vfs_getopt(mp->mnt_optnew, "readdirsize", (void **)&opt, NULL) == 0) {
if (opt == NULL) {
vfs_mount_error(mp, "illegal readdirsize");
diff --git a/sys/fs/nfsclient/nfs_clvnops.c b/sys/fs/nfsclient/nfs_clvnops.c
index cc9563a..6dc709f 100644
--- a/sys/fs/nfsclient/nfs_clvnops.c
+++ b/sys/fs/nfsclient/nfs_clvnops.c
@@ -1026,7 +1026,8 @@ nfs_lookup(struct vop_lookup_args *ap)
*/
newvp = *vpp;
newnp = VTONFS(newvp);
- if ((flags & (ISLASTCN | ISOPEN)) == (ISLASTCN | ISOPEN) &&
+ if (!(nmp->nm_flag & NFSMNT_NOCTO) &&
+ (flags & (ISLASTCN | ISOPEN)) == (ISLASTCN | ISOPEN) &&
!(newnp->n_flag & NMODIFIED)) {
mtx_lock(&newnp->n_mtx);
newnp->n_attrstamp = 0;
diff --git a/sys/geom/geom_dev.c b/sys/geom/geom_dev.c
index 909cb91..f291b32 100644
--- a/sys/geom/geom_dev.c
+++ b/sys/geom/geom_dev.c
@@ -148,7 +148,8 @@ g_dev_taste(struct g_class *mp, struct g_provider *pp, int insist __unused)
snprintf(buf, sizeof(buf), "%s%s",
val, gp->name + len);
freeenv(val);
- adev = make_dev_alias(dev, buf);
+ make_dev_alias_p(MAKEDEV_CHECKNAME | MAKEDEV_WAITOK,
+ &adev, dev, "%s", buf);
break;
}
}
diff --git a/sys/geom/label/g_label.c b/sys/geom/label/g_label.c
index bee7a85..0d8a3b4 100644
--- a/sys/geom/label/g_label.c
+++ b/sys/geom/label/g_label.c
@@ -164,6 +164,8 @@ g_label_create(struct gctl_req *req, struct g_class *mp, struct g_provider *pp,
pp2 = LIST_FIRST(&gp->provider);
if (pp2 == NULL)
continue;
+ if ((pp2->flags & G_PF_ORPHAN) != 0)
+ continue;
if (strcmp(pp2->name, name) == 0) {
G_LABEL_DEBUG(1, "Label %s(%s) already exists (%s).",
label, name, pp->name);
diff --git a/sys/kern/kern_conf.c b/sys/kern/kern_conf.c
index 721c01e..b2be5cc 100644
--- a/sys/kern/kern_conf.c
+++ b/sys/kern/kern_conf.c
@@ -893,23 +893,34 @@ dev_depends(struct cdev *pdev, struct cdev *cdev)
dev_unlock();
}
-struct cdev *
-make_dev_alias(struct cdev *pdev, const char *fmt, ...)
+static int
+make_dev_alias_v(int flags, struct cdev **cdev, struct cdev *pdev,
+ const char *fmt, va_list ap)
{
struct cdev *dev;
- va_list ap;
int error;
- KASSERT(pdev != NULL, ("NULL pdev"));
- dev = devfs_alloc(MAKEDEV_WAITOK);
+ KASSERT(pdev != NULL, ("make_dev_alias_v: pdev is NULL"));
+ KASSERT((flags & MAKEDEV_WAITOK) == 0 || (flags & MAKEDEV_NOWAIT) == 0,
+ ("make_dev_alias_v: both WAITOK and NOWAIT specified"));
+ KASSERT((flags & ~(MAKEDEV_WAITOK | MAKEDEV_NOWAIT |
+ MAKEDEV_CHECKNAME)) == 0,
+ ("make_dev_alias_v: invalid flags specified (flags=%02x)", flags));
+
+ dev = devfs_alloc(flags);
+ if (dev == NULL)
+ return (ENOMEM);
dev_lock();
dev->si_flags |= SI_ALIAS;
- va_start(ap, fmt);
error = prep_devname(dev, fmt, ap);
- va_end(ap);
if (error != 0) {
- panic("make_dev_alias: bad si_name (error=%d, si_name=%s)",
- error, dev->si_name);
+ if ((flags & MAKEDEV_CHECKNAME) == 0) {
+ panic("make_dev_alias_v: bad si_name "
+ "(error=%d, si_name=%s)", error, dev->si_name);
+ }
+ dev_unlock();
+ devfs_free(dev);
+ return (error);
}
dev->si_flags |= SI_NAMED;
devfs_create(dev);
@@ -917,11 +928,41 @@ make_dev_alias(struct cdev *pdev, const char *fmt, ...)
clean_unrhdrl(devfs_inos);
dev_unlock();
- notify_create(dev, MAKEDEV_WAITOK);
+ notify_create(dev, flags);
+ *cdev = dev;
+
+ return (0);
+}
+
+struct cdev *
+make_dev_alias(struct cdev *pdev, const char *fmt, ...)
+{
+ struct cdev *dev;
+ va_list ap;
+ int res;
+
+ va_start(ap, fmt);
+ res = make_dev_alias_v(MAKEDEV_WAITOK, &dev, pdev, fmt, ap);
+ va_end(ap);
+ KASSERT(res == 0 && dev != NULL,
+ ("make_dev_alias: failed make_dev_alias_v (error=%d)", res));
return (dev);
}
+int
+make_dev_alias_p(int flags, struct cdev **cdev, struct cdev *pdev,
+ const char *fmt, ...)
+{
+ va_list ap;
+ int res;
+
+ va_start(ap, fmt);
+ res = make_dev_alias_v(flags, cdev, pdev, fmt, ap);
+ va_end(ap);
+ return (res);
+}
+
static void
destroy_devl(struct cdev *dev)
{
diff --git a/sys/mips/atheros/if_arge.c b/sys/mips/atheros/if_arge.c
index ba7ee07..92cc161 100644
--- a/sys/mips/atheros/if_arge.c
+++ b/sys/mips/atheros/if_arge.c
@@ -1179,10 +1179,8 @@ arge_ifmedia_upd(struct ifnet *ifp)
sc = ifp->if_softc;
ARGE_LOCK(sc);
mii = device_get_softc(sc->arge_miibus);
- if (mii->mii_instance) {
- LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
- mii_phy_reset(miisc);
- }
+ LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
+ PHY_RESET(miisc);
error = mii_mediachg(mii);
ARGE_UNLOCK(sc);
diff --git a/sys/mips/cavium/octe/octe.c b/sys/mips/cavium/octe/octe.c
index 9f275d1..c989695 100644
--- a/sys/mips/cavium/octe/octe.c
+++ b/sys/mips/cavium/octe/octe.c
@@ -329,16 +329,12 @@ octe_mii_medchange(struct ifnet *ifp)
{
cvm_oct_private_t *priv;
struct mii_data *mii;
+ struct mii_softc *miisc;
priv = ifp->if_softc;
mii = device_get_softc(priv->miibus);
-
- if (mii->mii_instance) {
- struct mii_softc *miisc;
-
- LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
- mii_phy_reset(miisc);
- }
+ LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
+ PHY_RESET(miisc);
mii_mediachg(mii);
return (0);
diff --git a/sys/mips/idt/if_kr.c b/sys/mips/idt/if_kr.c
index edba950..43b8df5 100644
--- a/sys/mips/idt/if_kr.c
+++ b/sys/mips/idt/if_kr.c
@@ -925,10 +925,8 @@ kr_ifmedia_upd(struct ifnet *ifp)
sc = ifp->if_softc;
KR_LOCK(sc);
mii = device_get_softc(sc->kr_miibus);
- if (mii->mii_instance) {
- LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
- mii_phy_reset(miisc);
- }
+ LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
+ PHY_RESET(miisc);
error = mii_mediachg(mii);
KR_UNLOCK(sc);
diff --git a/sys/modules/mii/Makefile b/sys/modules/mii/Makefile
index 82d344b..2dd9811 100644
--- a/sys/modules/mii/Makefile
+++ b/sys/modules/mii/Makefile
@@ -14,7 +14,6 @@ SRCS+= xmphy.c
EXPORT_SYMS= mii_attach \
mii_mediachg \
- mii_phy_reset \
mii_pollstat \
mii_tick
diff --git a/sys/net80211/ieee80211_adhoc.c b/sys/net80211/ieee80211_adhoc.c
index 35bc345..8d9bcce 100644
--- a/sys/net80211/ieee80211_adhoc.c
+++ b/sys/net80211/ieee80211_adhoc.c
@@ -285,7 +285,6 @@ doprint(struct ieee80211vap *vap, int subtype)
static int
adhoc_input(struct ieee80211_node *ni, struct mbuf *m, int rssi, int nf)
{
-#define SEQ_LEQ(a,b) ((int)((a)-(b)) <= 0)
#define HAS_SEQ(type) ((type & 0x4) == 0)
struct ieee80211vap *vap = ni->ni_vap;
struct ieee80211com *ic = ni->ni_ic;
@@ -412,9 +411,7 @@ adhoc_input(struct ieee80211_node *ni, struct mbuf *m, int rssi, int nf)
TID_TO_WME_AC(tid) >= WME_AC_VI)
ic->ic_wme.wme_hipri_traffic++;
rxseq = le16toh(*(uint16_t *)wh->i_seq);
- if ((ni->ni_flags & IEEE80211_NODE_HT) == 0 &&
- (wh->i_fc[1] & IEEE80211_FC1_RETRY) &&
- SEQ_LEQ(rxseq, ni->ni_rxseqs[tid])) {
+ if (! ieee80211_check_rxseq(ni, wh)) {
/* duplicate, discard */
IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_INPUT,
bssid, "duplicate",
@@ -660,7 +657,6 @@ out:
m_freem(m);
}
return type;
-#undef SEQ_LEQ
}
static int
diff --git a/sys/net80211/ieee80211_hostap.c b/sys/net80211/ieee80211_hostap.c
index e3e1492..e190450 100644
--- a/sys/net80211/ieee80211_hostap.c
+++ b/sys/net80211/ieee80211_hostap.c
@@ -472,7 +472,6 @@ doprint(struct ieee80211vap *vap, int subtype)
static int
hostap_input(struct ieee80211_node *ni, struct mbuf *m, int rssi, int nf)
{
-#define SEQ_LEQ(a,b) ((int)((a)-(b)) <= 0)
#define HAS_SEQ(type) ((type & 0x4) == 0)
struct ieee80211vap *vap = ni->ni_vap;
struct ieee80211com *ic = ni->ni_ic;
@@ -572,9 +571,7 @@ hostap_input(struct ieee80211_node *ni, struct mbuf *m, int rssi, int nf)
TID_TO_WME_AC(tid) >= WME_AC_VI)
ic->ic_wme.wme_hipri_traffic++;
rxseq = le16toh(*(uint16_t *)wh->i_seq);
- if ((ni->ni_flags & IEEE80211_NODE_HT) == 0 &&
- (wh->i_fc[1] & IEEE80211_FC1_RETRY) &&
- SEQ_LEQ(rxseq, ni->ni_rxseqs[tid])) {
+ if (! ieee80211_check_rxseq(ni, wh)) {
/* duplicate, discard */
IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_INPUT,
bssid, "duplicate",
@@ -914,7 +911,6 @@ out:
m_freem(m);
}
return type;
-#undef SEQ_LEQ
}
static void
diff --git a/sys/net80211/ieee80211_input.h b/sys/net80211/ieee80211_input.h
index 5b38ddd..b90f46a 100644
--- a/sys/net80211/ieee80211_input.h
+++ b/sys/net80211/ieee80211_input.h
@@ -142,6 +142,104 @@ ishtinfooui(const uint8_t *frm)
return frm[1] > 3 && LE_READ_4(frm+2) == ((BCM_OUI_HTINFO<<24)|BCM_OUI);
}
+#include <sys/endian.h> /* For le16toh() */
+
+/*
+ * Check the current frame sequence number against the current TID
+ * state and return whether it's in sequence or should be dropped.
+ *
+ * Since out of order packet and duplicate packet eliminations should
+ * be done by the AMPDU RX code, this routine blindly accepts all
+ * frames from a HT station w/ a TID that is currently doing AMPDU-RX.
+ * HT stations without WME or where the TID is not doing AMPDU-RX
+ * are checked like non-HT stations.
+ *
+ * The routine only eliminates packets whose sequence/fragment
+ * match or are less than the last seen sequence/fragment number
+ * AND are retransmits It doesn't try to eliminate out of order packets.
+ *
+ * Since all frames after sequence number 4095 will be less than 4095
+ * (as the seqnum wraps), handle that special case so packets aren't
+ * incorrectly dropped - ie, if the next packet is sequence number 0
+ * but a retransmit since the initial packet didn't make it.
+ */
+static __inline int
+ieee80211_check_rxseq(struct ieee80211_node *ni, struct ieee80211_frame *wh)
+{
+#define SEQ_LEQ(a,b) ((int)((a)-(b)) <= 0)
+#define SEQ_EQ(a,b) ((int)((a)-(b)) == 0)
+#define HAS_SEQ(type) ((type & 0x4) == 0)
+#define SEQNO(a) ((a) >> IEEE80211_SEQ_SEQ_SHIFT)
+#define FRAGNO(a) ((a) & IEEE80211_SEQ_FRAG_MASK)
+ uint16_t rxseq;
+ uint8_t type;
+ uint8_t tid;
+ struct ieee80211_rx_ampdu *rap;
+
+ rxseq = le16toh(*(uint16_t *)wh->i_seq);
+ type = wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK;
+
+ /* Types with no sequence number are always treated valid */
+ if (! HAS_SEQ(type))
+ return 1;
+
+ tid = ieee80211_gettid(wh);
+
+ /*
+ * Only do the HT AMPDU check for WME stations; non-WME HT stations
+ * shouldn't exist outside of debugging. We should at least
+ * handle that.
+ */
+ if (tid < WME_NUM_TID) {
+ rap = &ni->ni_rx_ampdu[tid];
+ /* HT nodes currently doing RX AMPDU are always valid */
+ if ((ni->ni_flags & IEEE80211_NODE_HT) &&
+ (rap->rxa_flags & IEEE80211_AGGR_RUNNING))
+ return 1;
+ }
+
+ /*
+ * Otherwise, retries for packets below or equal to the last
+ * seen sequence number should be dropped.
+ */
+
+ /*
+ * Treat frame seqnum 4095 as special due to boundary
+ * wrapping conditions.
+ */
+ if (SEQNO(ni->ni_rxseqs[tid]) == 4095) {
+ /*
+ * Drop retransmits on seqnum 4095/current fragment for itself.
+ */
+ if (SEQ_EQ(rxseq, ni->ni_rxseqs[tid]) &&
+ (wh->i_fc[1] & IEEE80211_FC1_RETRY))
+ return 0;
+ /*
+ * Treat any subsequent frame as fine if the last seen frame
+ * is 4095 and it's not a retransmit for the same sequence
+ * number. However, this doesn't capture incorrectly ordered
+ * fragments w/ sequence number 4095. It shouldn't be seen
+ * in practice, but see the comment above for further info.
+ */
+ return 1;
+ }
+
+ /*
+ * At this point we assume that retransmitted seq/frag numbers below
+ * the current can simply be eliminated.
+ */
+ if ((wh->i_fc[1] & IEEE80211_FC1_RETRY) &&
+ SEQ_LEQ(rxseq, ni->ni_rxseqs[tid]))
+ return 0;
+
+ return 1;
+#undef SEQ_LEQ
+#undef SEQ_EQ
+#undef HAS_SEQ
+#undef SEQNO
+#undef FRAGNO
+}
+
void ieee80211_deliver_data(struct ieee80211vap *,
struct ieee80211_node *, struct mbuf *);
struct mbuf *ieee80211_defrag(struct ieee80211_node *,
diff --git a/sys/net80211/ieee80211_mesh.c b/sys/net80211/ieee80211_mesh.c
index 4cf2aac..571a733 100644
--- a/sys/net80211/ieee80211_mesh.c
+++ b/sys/net80211/ieee80211_mesh.c
@@ -1040,7 +1040,6 @@ mesh_isucastforme(struct ieee80211vap *vap, const struct ieee80211_frame *wh,
static int
mesh_input(struct ieee80211_node *ni, struct mbuf *m, int rssi, int nf)
{
-#define SEQ_LEQ(a,b) ((int)((a)-(b)) <= 0)
#define HAS_SEQ(type) ((type & 0x4) == 0)
struct ieee80211vap *vap = ni->ni_vap;
struct ieee80211com *ic = ni->ni_ic;
@@ -1094,9 +1093,7 @@ mesh_input(struct ieee80211_node *ni, struct mbuf *m, int rssi, int nf)
TID_TO_WME_AC(tid) >= WME_AC_VI)
ic->ic_wme.wme_hipri_traffic++;
rxseq = le16toh(*(uint16_t *)wh->i_seq);
- if ((ni->ni_flags & IEEE80211_NODE_HT) == 0 &&
- (wh->i_fc[1] & IEEE80211_FC1_RETRY) &&
- SEQ_LEQ(rxseq, ni->ni_rxseqs[tid])) {
+ if (! ieee80211_check_rxseq(ni, wh)) {
/* duplicate, discard */
IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_INPUT,
wh->i_addr1, "duplicate",
diff --git a/sys/net80211/ieee80211_sta.c b/sys/net80211/ieee80211_sta.c
index f8d488a..5444459 100644
--- a/sys/net80211/ieee80211_sta.c
+++ b/sys/net80211/ieee80211_sta.c
@@ -512,7 +512,6 @@ doprint(struct ieee80211vap *vap, int subtype)
static int
sta_input(struct ieee80211_node *ni, struct mbuf *m, int rssi, int nf)
{
-#define SEQ_LEQ(a,b) ((int)((a)-(b)) <= 0)
#define HAS_SEQ(type) ((type & 0x4) == 0)
struct ieee80211vap *vap = ni->ni_vap;
struct ieee80211com *ic = ni->ni_ic;
@@ -591,9 +590,7 @@ sta_input(struct ieee80211_node *ni, struct mbuf *m, int rssi, int nf)
TID_TO_WME_AC(tid) >= WME_AC_VI)
ic->ic_wme.wme_hipri_traffic++;
rxseq = le16toh(*(uint16_t *)wh->i_seq);
- if ((ni->ni_flags & IEEE80211_NODE_HT) == 0 &&
- (wh->i_fc[1] & IEEE80211_FC1_RETRY) &&
- SEQ_LEQ(rxseq, ni->ni_rxseqs[tid])) {
+ if (! ieee80211_check_rxseq(ni, wh)) {
/* duplicate, discard */
IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_INPUT,
bssid, "duplicate",
@@ -910,7 +907,6 @@ out:
m_freem(m);
}
return type;
-#undef SEQ_LEQ
}
static void
diff --git a/sys/net80211/ieee80211_wds.c b/sys/net80211/ieee80211_wds.c
index 926ef57..ed82fac 100644
--- a/sys/net80211/ieee80211_wds.c
+++ b/sys/net80211/ieee80211_wds.c
@@ -406,7 +406,6 @@ wds_newstate(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
static int
wds_input(struct ieee80211_node *ni, struct mbuf *m, int rssi, int nf)
{
-#define SEQ_LEQ(a,b) ((int)((a)-(b)) <= 0)
#define HAS_SEQ(type) ((type & 0x4) == 0)
struct ieee80211vap *vap = ni->ni_vap;
struct ieee80211com *ic = ni->ni_ic;
@@ -495,9 +494,7 @@ wds_input(struct ieee80211_node *ni, struct mbuf *m, int rssi, int nf)
TID_TO_WME_AC(tid) >= WME_AC_VI)
ic->ic_wme.wme_hipri_traffic++;
rxseq = le16toh(*(uint16_t *)wh->i_seq);
- if ((ni->ni_flags & IEEE80211_NODE_HT) == 0 &&
- (wh->i_fc[1] & IEEE80211_FC1_RETRY) &&
- SEQ_LEQ(rxseq, ni->ni_rxseqs[tid])) {
+ if (! ieee80211_check_rxseq(ni, wh)) {
/* duplicate, discard */
IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_INPUT,
wh->i_addr1, "duplicate",
@@ -741,7 +738,6 @@ out:
m_freem(m);
}
return type;
-#undef SEQ_LEQ
}
static void
diff --git a/sys/netinet/sctp_asconf.c b/sys/netinet/sctp_asconf.c
index 1c0a454..a6db580 100644
--- a/sys/netinet/sctp_asconf.c
+++ b/sys/netinet/sctp_asconf.c
@@ -2813,7 +2813,6 @@ sctp_compose_asconf(struct sctp_tcb *stcb, int *retlen, int addr_locked)
lookup->ph.param_length = htons(SCTP_SIZE32(p_size));
memcpy(lookup->addr, addr_ptr, addr_size);
SCTP_BUF_LEN(m_asconf_chk) += SCTP_SIZE32(p_size);
- lookup_used = 1;
} else {
/* uh oh... don't have any address?? */
SCTPDBG(SCTP_DEBUG_ASCONF1,
@@ -2823,7 +2822,6 @@ sctp_compose_asconf(struct sctp_tcb *stcb, int *retlen, int addr_locked)
lookup->ph.param_length = htons(SCTP_SIZE32(sizeof(struct sctp_ipv4addr_param)));
bzero(lookup->addr, sizeof(struct in_addr));
SCTP_BUF_LEN(m_asconf_chk) += SCTP_SIZE32(sizeof(struct sctp_ipv4addr_param));
- lookup_used = 1;
}
}
/* chain it all together */
@@ -2930,6 +2928,7 @@ sctp_process_initack_addresses(struct sctp_tcb *stcb, struct mbuf *m,
}
sin.sin_addr.s_addr = a4p->addr;
sa = (struct sockaddr *)&sin;
+ break;
}
#endif
default:
diff --git a/sys/netinet/sctp_auth.c b/sys/netinet/sctp_auth.c
index 08d48f7..eb5a77b 100644
--- a/sys/netinet/sctp_auth.c
+++ b/sys/netinet/sctp_auth.c
@@ -1949,9 +1949,6 @@ sctp_validate_init_auth_params(struct mbuf *m, int offset, int limit)
case SCTP_ASCONF_ACK:
peer_supports_asconf = 1;
break;
- case SCTP_AUTHENTICATION:
- peer_supports_auth = 1;
- break;
default:
/* one we don't care about */
break;
diff --git a/sys/netinet/sctputil.c b/sys/netinet/sctputil.c
index ae39e9d..974aa62 100644
--- a/sys/netinet/sctputil.c
+++ b/sys/netinet/sctputil.c
@@ -3850,8 +3850,6 @@ sctp_abort_an_association(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
#endif
)
{
- uint32_t vtag;
-
#if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
struct socket *so;
@@ -3872,7 +3870,6 @@ sctp_abort_an_association(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
} else {
stcb->asoc.state |= SCTP_STATE_WAS_ABORTED;
}
- vtag = stcb->asoc.peer_vtag;
/* notify the ulp */
if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0)
sctp_abort_notification(stcb, error, so_locked);
diff --git a/sys/netinet6/sctp6_usrreq.c b/sys/netinet6/sctp6_usrreq.c
index 10eed08..62efcd6 100644
--- a/sys/netinet6/sctp6_usrreq.c
+++ b/sys/netinet6/sctp6_usrreq.c
@@ -1066,10 +1066,8 @@ sctp6_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, EINVAL);
return EINVAL;
}
- } else
+ }
#endif /* INET */
- addr = addr; /* for true v6 address case */
-
/* Now do we connect? */
if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
stcb = LIST_FIRST(&inp->sctp_asoc_list);
diff --git a/sys/nfs/nfs_diskless.c b/sys/nfs/nfs_diskless.c
index fad6ef0..26f5036 100644
--- a/sys/nfs/nfs_diskless.c
+++ b/sys/nfs/nfs_diskless.c
@@ -112,6 +112,8 @@ nfs_parse_options(const char *envopts, struct nfs_args *nd)
nd->flags |= NFSMNT_NOCONN;
else if (strcmp(o, "nolockd") == 0)
nd->flags |= NFSMNT_NOLOCKD;
+ else if (strcmp(o, "nocto") == 0)
+ nd->flags |= NFSMNT_NOCTO;
else if (strcmp(o, "nfsv2") == 0)
nd->flags &= ~(NFSMNT_NFSV3 | NFSMNT_NFSV4);
else if (strcmp(o, "nfsv3") == 0) {
diff --git a/sys/nfs/nfssvc.h b/sys/nfs/nfssvc.h
index e226e2b..2615d07 100644
--- a/sys/nfs/nfssvc.h
+++ b/sys/nfs/nfssvc.h
@@ -64,6 +64,7 @@
#define NFSSVC_CBADDSOCK 0x00200000
#define NFSSVC_GETSTATS 0x00400000
#define NFSSVC_BACKUPSTABLE 0x00800000
-#define NFSSVC_ZEROSTATS 0x01000000 /* modifier for GETSTATS */
+#define NFSSVC_ZEROCLTSTATS 0x01000000 /* modifier for GETSTATS */
+#define NFSSVC_ZEROSRVSTATS 0x02000000 /* modifier for GETSTATS */
#endif /* _NFS_NFSSVC_H */
diff --git a/sys/nfsclient/nfs_vfsops.c b/sys/nfsclient/nfs_vfsops.c
index ec60c94..ba3f41d 100644
--- a/sys/nfsclient/nfs_vfsops.c
+++ b/sys/nfsclient/nfs_vfsops.c
@@ -786,7 +786,7 @@ static const char *nfs_opts[] = { "from", "nfs_args",
"readahead", "readdirsize", "soft", "hard", "mntudp", "tcp", "udp",
"wsize", "rsize", "retrans", "acregmin", "acregmax", "acdirmin",
"acdirmax", "deadthresh", "hostname", "timeout", "addr", "fh", "nfsv3",
- "sec", "maxgroups", "principal", "negnametimeo",
+ "sec", "maxgroups", "principal", "negnametimeo", "nocto",
NULL };
/*
@@ -901,6 +901,8 @@ nfs_mount(struct mount *mp)
args.sotype = SOCK_STREAM;
if (vfs_getopt(mp->mnt_optnew, "nfsv3", NULL, NULL) == 0)
args.flags |= NFSMNT_NFSV3;
+ if (vfs_getopt(mp->mnt_optnew, "nocto", NULL, NULL) == 0)
+ args.flags |= NFSMNT_NOCTO;
if (vfs_getopt(mp->mnt_optnew, "readdirsize", (void **)&opt, NULL) == 0) {
if (opt == NULL) {
vfs_mount_error(mp, "illegal readdirsize");
diff --git a/sys/nfsclient/nfs_vnops.c b/sys/nfsclient/nfs_vnops.c
index cb2a126..33506a4 100644
--- a/sys/nfsclient/nfs_vnops.c
+++ b/sys/nfsclient/nfs_vnops.c
@@ -960,7 +960,8 @@ nfs_lookup(struct vop_lookup_args *ap)
*/
newvp = *vpp;
newnp = VTONFS(newvp);
- if ((flags & (ISLASTCN | ISOPEN)) == (ISLASTCN | ISOPEN) &&
+ if (!(nmp->nm_flag & NFSMNT_NOCTO) &&
+ (flags & (ISLASTCN | ISOPEN)) == (ISLASTCN | ISOPEN) &&
!(newnp->n_flag & NMODIFIED)) {
mtx_lock(&newnp->n_mtx);
newnp->n_attrstamp = 0;
diff --git a/sys/nfsclient/nfsargs.h b/sys/nfsclient/nfsargs.h
index a46677a..f71a555 100644
--- a/sys/nfsclient/nfsargs.h
+++ b/sys/nfsclient/nfsargs.h
@@ -97,5 +97,6 @@ struct nfs_args {
#define NFSMNT_PRIVACY 0x04000000 /* Use privacy with RPCSEC_GSS */
#define NFSMNT_ALLGSSNAME 0x08000000 /* Use principal for all accesses */
#define NFSMNT_STRICT3530 0x10000000 /* Adhere strictly to RFC3530 */
+#define NFSMNT_NOCTO 0x20000000 /* Don't flush attrcache on open */
#endif
diff --git a/sys/sys/conf.h b/sys/sys/conf.h
index 5f1ef18..31fd34d 100644
--- a/sys/sys/conf.h
+++ b/sys/sys/conf.h
@@ -278,6 +278,8 @@ int make_dev_p(int _flags, struct cdev **_cdev, struct cdevsw *_devsw,
const char *_fmt, ...) __printflike(8, 9);
struct cdev *make_dev_alias(struct cdev *_pdev, const char *_fmt, ...)
__printflike(2, 3);
+int make_dev_alias_p(int _flags, struct cdev **_cdev, struct cdev *_pdev,
+ const char *_fmt, ...) __printflike(4, 5);
void dev_lock(void);
void dev_unlock(void);
void setconf(void);
OpenPOWER on IntegriCloud