code:
/*-
 * Copyright (c) 2009 Andrew Thompson
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * $FreeBSD: release/9.0.0/sys/dev/usb/usbdi.h 225469 2011-09-10 15:55:36Z hselasky $
 */
#ifndef _USB_USBDI_H_
#define _USB_USBDI_H_

struct usb_fifo;
struct usb_xfer;
struct usb_device;
struct usb_attach_arg;
struct usb_interface;
struct usb_endpoint;
struct usb_page_cache;
struct usb_page_search;
struct usb_process;
struct usb_proc_msg;
struct usb_mbuf;
struct usb_fs_privdata;
struct mbuf;

typedef enum {	/* keep in sync with usb_errstr_table */
	USB_ERR_NORMAL_COMPLETION = 0,
	USB_ERR_PENDING_REQUESTS,	/* 1 */
	USB_ERR_NOT_STARTED,		/* 2 */
	USB_ERR_INVAL,			/* 3 */
	USB_ERR_NOMEM,			/* 4 */
	USB_ERR_CANCELLED,		/* 5 */
	USB_ERR_BAD_ADDRESS,		/* 6 */
	USB_ERR_BAD_BUFSIZE,		/* 7 */
	USB_ERR_BAD_FLAG,		/* 8 */
	USB_ERR_NO_CALLBACK,		/* 9 */
	USB_ERR_IN_USE,			/* 10 */
	USB_ERR_NO_ADDR,		/* 11 */
	USB_ERR_NO_PIPE,		/* 12 */
	USB_ERR_ZERO_NFRAMES,		/* 13 */
	USB_ERR_ZERO_MAXP,		/* 14 */
	USB_ERR_SET_ADDR_FAILED,	/* 15 */
	USB_ERR_NO_POWER,		/* 16 */
	USB_ERR_TOO_DEEP,		/* 17 */
	USB_ERR_IOERROR,		/* 18 */
	USB_ERR_NOT_CONFIGURED,		/* 19 */
	USB_ERR_TIMEOUT,		/* 20 */
	USB_ERR_SHORT_XFER,		/* 21 */
	USB_ERR_STALLED,		/* 22 */
	USB_ERR_INTERRUPTED,		/* 23 */
	USB_ERR_DMA_LOAD_FAILED,	/* 24 */
	USB_ERR_BAD_CONTEXT,		/* 25 */
	USB_ERR_NO_ROOT_HUB,		/* 26 */
	USB_ERR_NO_INTR_THREAD,		/* 27 */
	USB_ERR_NOT_LOCKED,		/* 28 */
	USB_ERR_MAX
} usb_error_t;

/*
 * Flags for transfers
 */
#define	USB_FORCE_SHORT_XFER	0x0001	/* force a short transmit last */
#define	USB_SHORT_XFER_OK	0x0004	/* allow short reads */
#define	USB_DELAY_STATUS_STAGE	0x0010	/* insert delay before STATUS stage */
#define	USB_USER_DATA_PTR	0x0020	/* internal flag */
#define	USB_MULTI_SHORT_OK	0x0040	/* allow multiple short frames */
#define	USB_MANUAL_STATUS	0x0080	/* manual ctrl status */

#define	USB_NO_TIMEOUT 0
#define	USB_DEFAULT_TIMEOUT 5000	/* 5000 ms = 5 seconds */

#if defined(_KERNEL)
/* typedefs */

typedef void (usb_callback_t)(struct usb_xfer *, usb_error_t);
typedef void (usb_proc_callback_t)(struct usb_proc_msg *);
typedef usb_error_t (usb_handle_req_t)(struct usb_device *,
    struct usb_device_request *, const void **, uint16_t *);

typedef int (usb_fifo_open_t)(struct usb_fifo *fifo, int fflags);
typedef void (usb_fifo_close_t)(struct usb_fifo *fifo, int fflags);
typedef int (usb_fifo_ioctl_t)(struct usb_fifo *fifo, u_long cmd, void *addr, int fflags);
typedef void (usb_fifo_cmd_t)(struct usb_fifo *fifo);
typedef void (usb_fifo_filter_t)(struct usb_fifo *fifo, struct usb_mbuf *m);

/* USB events */
#include <sys/eventhandler.h>
typedef void (*usb_dev_configured_t)(void *, struct usb_device *,
    struct usb_attach_arg *);
EVENTHANDLER_DECLARE(usb_dev_configured, usb_dev_configured_t);

/*
 * The following macros are used used to convert milliseconds into
 * HZ. We use 1024 instead of 1000 milliseconds per second to save a
 * full division.
 */
#define	USB_MS_HZ 1024

#define	USB_MS_TO_TICKS(ms) \
  (((uint32_t)((((uint32_t)(ms)) * ((uint32_t)(hz))) + USB_MS_HZ - 1)) / USB_MS_HZ)

/*
 * Common queue structure for USB transfers.
 */
struct usb_xfer_queue {
	TAILQ_HEAD(, usb_xfer) head;
	struct usb_xfer *curr;		/* current USB transfer processed */
	void    (*command) (struct usb_xfer_queue *pq);
	uint8_t	recurse_1:1;
	uint8_t	recurse_2:1;
};

/*
 * The following structure defines an USB endpoint
 * USB endpoint.
 */
struct usb_endpoint {
	struct usb_xfer_queue endpoint_q;	/* queue of USB transfers */

	struct usb_endpoint_descriptor *edesc;
	struct usb_endpoint_ss_comp_descriptor *ecomp;
	struct usb_pipe_methods *methods;	/* set by HC driver */

	uint16_t isoc_next;

	uint8_t	toggle_next:1;		/* next data toggle value */
	uint8_t	is_stalled:1;		/* set if endpoint is stalled */
	uint8_t	is_synced:1;		/* set if we a synchronised */
	uint8_t	unused:5;
	uint8_t	iface_index;		/* not used by "default endpoint" */

	uint8_t refcount_alloc;		/* allocation refcount */
	uint8_t refcount_bw;		/* bandwidth refcount */
#define	USB_EP_REF_MAX 0x3f

	/* High-Speed resource allocation (valid if "refcount_bw" > 0) */

	uint8_t	usb_smask;		/* USB start mask */
	uint8_t	usb_cmask;		/* USB complete mask */
	uint8_t	usb_uframe;		/* USB microframe */
};

/*
 * The following structure defines an USB interface.
 */
struct usb_interface {
	struct usb_interface_descriptor *idesc;
	device_t subdev;
	uint8_t	alt_index;
	uint8_t	parent_iface_index;

	/* Linux compat */
	struct usb_host_interface *altsetting;
	struct usb_host_interface *cur_altsetting;
	struct usb_device *linux_udev;
	void   *bsd_priv_sc;		/* device specific information */
	char   *pnpinfo;		/* additional PnP-info for this interface */
	uint8_t	num_altsetting;		/* number of alternate settings */
	uint8_t	bsd_iface_index;
};

/*
 * The following structure defines a set of USB transfer flags.
 */
struct usb_xfer_flags {
	uint8_t	force_short_xfer:1;	/* force a short transmit transfer
					 * last */
	uint8_t	short_xfer_ok:1;	/* allow short receive transfers */
	uint8_t	short_frames_ok:1;	/* allow short frames */
	uint8_t	pipe_bof:1;		/* block pipe on failure */
	uint8_t	proxy_buffer:1;		/* makes buffer size a factor of
					 * "max_frame_size" */
	uint8_t	ext_buffer:1;		/* uses external DMA buffer */
	uint8_t	manual_status:1;	/* non automatic status stage on
					 * control transfers */
	uint8_t	no_pipe_ok:1;		/* set if "USB_ERR_NO_PIPE" error can
					 * be ignored */
	uint8_t	stall_pipe:1;		/* set if the endpoint belonging to
					 * this USB transfer should be stalled
					 * before starting this transfer! */
	uint8_t pre_scale_frames:1;	/* "usb_config->frames" is
					 * assumed to give the
					 * buffering time in
					 * milliseconds and is
					 * converted into the nearest
					 * number of frames when the
					 * USB transfer is setup. This
					 * option only has effect for
					 * ISOCHRONOUS transfers.
					 */
};

/*
 * The following structure define an USB configuration, that basically
 * is used when setting up an USB transfer.
 */
struct usb_config {
	usb_callback_t *callback;	/* USB transfer callback */
	usb_frlength_t bufsize;	/* total pipe buffer size in bytes */
	usb_frcount_t frames;		/* maximum number of USB frames */
	usb_timeout_t interval;	/* interval in milliseconds */
#define	USB_DEFAULT_INTERVAL	0
	usb_timeout_t timeout;		/* transfer timeout in milliseconds */
	struct usb_xfer_flags flags;	/* transfer flags */
	enum usb_hc_mode usb_mode;	/* host or device mode */
	uint8_t	type;			/* pipe type */
	uint8_t	endpoint;		/* pipe number */
	uint8_t	direction;		/* pipe direction */
	uint8_t	ep_index;		/* pipe index match to use */
	uint8_t	if_index;		/* "ifaces" index to use */
};

/*
 * Use these macro when defining USB device ID arrays if you want to
 * have your driver module automatically loaded in host, device or
 * both modes respectivly:
 */
#define	STRUCT_USB_HOST_ID \
    struct usb_device_id __section("usb_host_id")
#define	STRUCT_USB_DEVICE_ID \
    struct usb_device_id __section("usb_device_id")
#define	STRUCT_USB_DUAL_ID \
    struct usb_device_id __section("usb_dual_id")

/*
 * The following structure is used when looking up an USB driver for
 * an USB device. It is inspired by the Linux structure called
 * "usb_device_id".
 */
struct usb_device_id {

	/* Hook for driver specific information */
	unsigned long driver_info;

	/* Used for product specific matches; the BCD range is inclusive */
	uint16_t idVendor;
	uint16_t idProduct;
	uint16_t bcdDevice_lo;
	uint16_t bcdDevice_hi;

	/* Used for device class matches */
	uint8_t	bDeviceClass;
	uint8_t	bDeviceSubClass;
	uint8_t	bDeviceProtocol;

	/* Used for interface class matches */
	uint8_t	bInterfaceClass;
	uint8_t	bInterfaceSubClass;
	uint8_t	bInterfaceProtocol;

	/* Select which fields to match against */
	uint8_t	match_flag_vendor:1;
	uint8_t	match_flag_product:1;
	uint8_t	match_flag_dev_lo:1;
	uint8_t	match_flag_dev_hi:1;

	uint8_t	match_flag_dev_class:1;
	uint8_t	match_flag_dev_subclass:1;
	uint8_t	match_flag_dev_protocol:1;
	uint8_t	match_flag_int_class:1;

	uint8_t	match_flag_int_subclass:1;
	uint8_t	match_flag_int_protocol:1;
	uint8_t match_flag_unused:6;

#if USB_HAVE_COMPAT_LINUX
	/* which fields to match against */
	uint16_t match_flags;
#define	USB_DEVICE_ID_MATCH_VENDOR		0x0001
#define	USB_DEVICE_ID_MATCH_PRODUCT		0x0002
#define	USB_DEVICE_ID_MATCH_DEV_LO		0x0004
#define	USB_DEVICE_ID_MATCH_DEV_HI		0x0008
#define	USB_DEVICE_ID_MATCH_DEV_CLASS		0x0010
#define	USB_DEVICE_ID_MATCH_DEV_SUBCLASS	0x0020
#define	USB_DEVICE_ID_MATCH_DEV_PROTOCOL	0x0040
#define	USB_DEVICE_ID_MATCH_INT_CLASS		0x0080
#define	USB_DEVICE_ID_MATCH_INT_SUBCLASS	0x0100
#define	USB_DEVICE_ID_MATCH_INT_PROTOCOL	0x0200
#endif
} __aligned(32);

/* check that the size of the structure above is correct */
extern char usb_device_id_assert[(sizeof(struct usb_device_id) == 32) ? 1 : -1];

#define	USB_VENDOR(vend)			\
  .match_flag_vendor = 1, .idVendor = (vend)

#define	USB_PRODUCT(prod)			\
  .match_flag_product = 1, .idProduct = (prod)

#define	USB_VP(vend,prod)			\
  USB_VENDOR(vend), USB_PRODUCT(prod)

#define	USB_VPI(vend,prod,info)			\
  USB_VENDOR(vend), USB_PRODUCT(prod), USB_DRIVER_INFO(info)

#define	USB_DEV_BCD_GTEQ(lo)	/* greater than or equal */ \
  .match_flag_dev_lo = 1, .bcdDevice_lo = (lo)

#define	USB_DEV_BCD_LTEQ(hi)	/* less than or equal */ \
  .match_flag_dev_hi = 1, .bcdDevice_hi = (hi)

#define	USB_DEV_CLASS(dc)			\
  .match_flag_dev_class = 1, .bDeviceClass = (dc)

#define	USB_DEV_SUBCLASS(dsc)			\
  .match_flag_dev_subclass = 1, .bDeviceSubClass = (dsc)

#define	USB_DEV_PROTOCOL(dp)			\
  .match_flag_dev_protocol = 1, .bDeviceProtocol = (dp)

#define	USB_IFACE_CLASS(ic)			\
  .match_flag_int_class = 1, .bInterfaceClass = (ic)

#define	USB_IFACE_SUBCLASS(isc)			\
  .match_flag_int_subclass = 1, .bInterfaceSubClass = (isc)

#define	USB_IFACE_PROTOCOL(ip)			\
  .match_flag_int_protocol = 1, .bInterfaceProtocol = (ip)

#define	USB_IF_CSI(class,subclass,info)			\
  USB_IFACE_CLASS(class), USB_IFACE_SUBCLASS(subclass), USB_DRIVER_INFO(info)

#define	USB_DRIVER_INFO(n)			\
  .driver_info = (n)

#define	USB_GET_DRIVER_INFO(did)		\
  (did)->driver_info

/*
 * The following structure keeps information that is used to match
 * against an array of "usb_device_id" elements.
 */
struct usbd_lookup_info {
	uint16_t idVendor;
	uint16_t idProduct;
	uint16_t bcdDevice;
	uint8_t	bDeviceClass;
	uint8_t	bDeviceSubClass;
	uint8_t	bDeviceProtocol;
	uint8_t	bInterfaceClass;
	uint8_t	bInterfaceSubClass;
	uint8_t	bInterfaceProtocol;
	uint8_t	bIfaceIndex;
	uint8_t	bIfaceNum;
	uint8_t	bConfigIndex;
	uint8_t	bConfigNum;
};

/* Structure used by probe and attach */

struct usb_attach_arg {
	struct usbd_lookup_info info;
	device_t temp_dev;		/* for internal use */
	unsigned long driver_info;	/* for internal use */
	void *driver_ivar;
	struct usb_device *device;	/* current device */
	struct usb_interface *iface;	/* current interface */
	enum usb_hc_mode usb_mode;	/* host or device mode */
	uint8_t	port;
	uint8_t dev_state;
#define UAA_DEV_READY		0
#define UAA_DEV_DISABLED	1
#define UAA_DEV_EJECTING	2
};

/*
 * The following is a wrapper for the callout structure to ease
 * porting the code to other platforms.
 */
struct usb_callout {
	struct callout co;
};
#define	usb_callout_init_mtx(c,m,f) callout_init_mtx(&(c)->co,m,f)
#define	usb_callout_reset(c,t,f,d) callout_reset(&(c)->co,t,f,d)
#define	usb_callout_stop(c) callout_stop(&(c)->co)
#define	usb_callout_drain(c) callout_drain(&(c)->co)
#define	usb_callout_pending(c) callout_pending(&(c)->co)

/* USB transfer states */

#define	USB_ST_SETUP       0
#define	USB_ST_TRANSFERRED 1
#define	USB_ST_ERROR       2

/* USB handle request states */
#define	USB_HR_NOT_COMPLETE	0
#define	USB_HR_COMPLETE_OK	1
#define	USB_HR_COMPLETE_ERR	2

/*
 * The following macro will return the current state of an USB
 * transfer like defined by the "USB_ST_XXX" enums.
 */
#define	USB_GET_STATE(xfer) (usbd_xfer_state(xfer))

/*
 * The following structure defines the USB process message header.
 */
struct usb_proc_msg {
	TAILQ_ENTRY(usb_proc_msg) pm_qentry;
	usb_proc_callback_t *pm_callback;
	usb_size_t pm_num;
};

#define	USB_FIFO_TX 0
#define	USB_FIFO_RX 1

/*
 * Locking note for the following functions.  All the
 * "usb_fifo_cmd_t" and "usb_fifo_filter_t" functions are called
 * locked. The others are called unlocked.
 */
struct usb_fifo_methods {
	usb_fifo_open_t *f_open;
	usb_fifo_close_t *f_close;
	usb_fifo_ioctl_t *f_ioctl;
	/*
	 * NOTE: The post-ioctl callback is called after the USB reference
	 * gets locked in the IOCTL handler:
	 */
	usb_fifo_ioctl_t *f_ioctl_post;
	usb_fifo_cmd_t *f_start_read;
	usb_fifo_cmd_t *f_stop_read;
	usb_fifo_cmd_t *f_start_write;
	usb_fifo_cmd_t *f_stop_write;
	usb_fifo_filter_t *f_filter_read;
	usb_fifo_filter_t *f_filter_write;
	const char *basename[4];
	const char *postfix[4];
};

struct usb_fifo_sc {
	struct usb_fifo *fp[2];
	struct usb_fs_privdata *dev;
};

const char *usbd_errstr(usb_error_t error);
void	*usbd_find_descriptor(struct usb_device *udev, void *id,
	    uint8_t iface_index, uint8_t type, uint8_t type_mask,
	    uint8_t subtype, uint8_t subtype_mask);
struct usb_config_descriptor *usbd_get_config_descriptor(
	    struct usb_device *udev);
struct usb_device_descriptor *usbd_get_device_descriptor(
	    struct usb_device *udev);
struct usb_interface *usbd_get_iface(struct usb_device *udev,
	    uint8_t iface_index);
struct usb_interface_descriptor *usbd_get_interface_descriptor(
	    struct usb_interface *iface);
struct usb_endpoint *usbd_get_endpoint(struct usb_device *udev, uint8_t iface_index,
		    const struct usb_config *setup);
struct usb_endpoint *usbd_get_ep_by_addr(struct usb_device *udev, uint8_t ea_val);
usb_error_t	usbd_interface_count(struct usb_device *udev, uint8_t *count);
enum usb_hc_mode usbd_get_mode(struct usb_device *udev);
enum usb_dev_speed usbd_get_speed(struct usb_device *udev);
void	device_set_usb_desc(device_t dev);
void	usb_pause_mtx(struct mtx *mtx, int _ticks);
usb_error_t	usbd_set_pnpinfo(struct usb_device *udev,
			uint8_t iface_index, const char *pnpinfo);
usb_error_t	usbd_add_dynamic_quirk(struct usb_device *udev,
			uint16_t quirk);

const struct usb_device_id *usbd_lookup_id_by_info(
	    const struct usb_device_id *id, usb_size_t sizeof_id,
	    const struct usbd_lookup_info *info);
int	usbd_lookup_id_by_uaa(const struct usb_device_id *id,
	    usb_size_t sizeof_id, struct usb_attach_arg *uaa);

usb_error_t usbd_do_request_flags(struct usb_device *udev, struct mtx *mtx,
		    struct usb_device_request *req, void *data, uint16_t flags,
		    uint16_t *actlen, usb_timeout_t timeout);
#define	usbd_do_request(u,m,r,d) \
  usbd_do_request_flags(u,m,r,d,0,NULL,USB_DEFAULT_TIMEOUT)

uint8_t	usbd_clear_stall_callback(struct usb_xfer *xfer1,
	    struct usb_xfer *xfer2);
uint8_t	usbd_get_interface_altindex(struct usb_interface *iface);
usb_error_t usbd_set_alt_interface_index(struct usb_device *udev,
	    uint8_t iface_index, uint8_t alt_index);
uint32_t usbd_get_isoc_fps(struct usb_device *udev);
usb_error_t usbd_transfer_setup(struct usb_device *udev,
	    const uint8_t *ifaces, struct usb_xfer **pxfer,
	    const struct usb_config *setup_start, uint16_t n_setup,
	    void *priv_sc, struct mtx *priv_mtx);
void	usbd_transfer_submit(struct usb_xfer *xfer);
void	usbd_transfer_clear_stall(struct usb_xfer *xfer);
void	usbd_transfer_drain(struct usb_xfer *xfer);
uint8_t	usbd_transfer_pending(struct usb_xfer *xfer);
void	usbd_transfer_start(struct usb_xfer *xfer);
void	usbd_transfer_stop(struct usb_xfer *xfer);
void	usbd_transfer_unsetup(struct usb_xfer **pxfer, uint16_t n_setup);
void	usbd_transfer_poll(struct usb_xfer **ppxfer, uint16_t max);
void	usbd_set_parent_iface(struct usb_device *udev, uint8_t iface_index,
	    uint8_t parent_index);
uint8_t	usbd_get_bus_index(struct usb_device *udev);
uint8_t	usbd_get_device_index(struct usb_device *udev);
void	usbd_set_power_mode(struct usb_device *udev, uint8_t power_mode);
uint8_t	usbd_filter_power_mode(struct usb_device *udev, uint8_t power_mode);
uint8_t	usbd_device_attached(struct usb_device *udev);

usb_frlength_t
	usbd_xfer_old_frame_length(struct usb_xfer *xfer, usb_frcount_t frindex);
void	usbd_xfer_status(struct usb_xfer *xfer, int *actlen, int *sumlen,
	    int *aframes, int *nframes);
struct usb_page_cache *usbd_xfer_get_frame(struct usb_xfer *xfer,
	    usb_frcount_t frindex);
void	*usbd_xfer_softc(struct usb_xfer *xfer);
void	*usbd_xfer_get_priv(struct usb_xfer *xfer);
void	usbd_xfer_set_priv(struct usb_xfer *xfer, void *);
void	usbd_xfer_set_interval(struct usb_xfer *xfer, int);
uint8_t	usbd_xfer_state(struct usb_xfer *xfer);
void	usbd_xfer_set_frame_data(struct usb_xfer *xfer, usb_frcount_t frindex,
	    void *ptr, usb_frlength_t len);
void	usbd_xfer_frame_data(struct usb_xfer *xfer, usb_frcount_t frindex,
	    void **ptr, int *len);
void	usbd_xfer_set_frame_offset(struct usb_xfer *xfer, usb_frlength_t offset,
	    usb_frcount_t frindex);
usb_frlength_t usbd_xfer_max_len(struct usb_xfer *xfer);
usb_frlength_t usbd_xfer_max_framelen(struct usb_xfer *xfer);
usb_frcount_t usbd_xfer_max_frames(struct usb_xfer *xfer);
uint8_t	usbd_xfer_get_fps_shift(struct usb_xfer *xfer);
usb_frlength_t usbd_xfer_frame_len(struct usb_xfer *xfer,
	    usb_frcount_t frindex);
void	usbd_xfer_set_frame_len(struct usb_xfer *xfer, usb_frcount_t frindex,
	    usb_frlength_t len);
void	usbd_xfer_set_timeout(struct usb_xfer *xfer, int timeout);
void	usbd_xfer_set_frames(struct usb_xfer *xfer, usb_frcount_t n);
void	usbd_xfer_set_stall(struct usb_xfer *xfer);
int	usbd_xfer_is_stalled(struct usb_xfer *xfer);
void	usbd_xfer_set_flag(struct usb_xfer *xfer, int flag);
void	usbd_xfer_clr_flag(struct usb_xfer *xfer, int flag);
uint16_t usbd_xfer_get_timestamp(struct usb_xfer *xfer);

void	usbd_copy_in(struct usb_page_cache *cache, usb_frlength_t offset,
	    const void *ptr, usb_frlength_t len);
int	usbd_copy_in_user(struct usb_page_cache *cache, usb_frlength_t offset,
	    const void *ptr, usb_frlength_t len);
void	usbd_copy_out(struct usb_page_cache *cache, usb_frlength_t offset,
	    void *ptr, usb_frlength_t len);
int	usbd_copy_out_user(struct usb_page_cache *cache, usb_frlength_t offset,
	    void *ptr, usb_frlength_t len);
void	usbd_get_page(struct usb_page_cache *pc, usb_frlength_t offset,
	    struct usb_page_search *res);
void	usbd_m_copy_in(struct usb_page_cache *cache, usb_frlength_t dst_offset,
	    struct mbuf *m, usb_size_t src_offset, usb_frlength_t src_len);
void	usbd_frame_zero(struct usb_page_cache *cache, usb_frlength_t offset,
	    usb_frlength_t len);
void	usbd_start_re_enumerate(struct usb_device *udev);

int	usb_fifo_attach(struct usb_device *udev, void *priv_sc,
	    struct mtx *priv_mtx, struct usb_fifo_methods *pm,
	    struct usb_fifo_sc *f_sc, uint16_t unit, uint16_t subunit,
	    uint8_t iface_index, uid_t uid, gid_t gid, int mode);
void	usb_fifo_detach(struct usb_fifo_sc *f_sc);
int	usb_fifo_alloc_buffer(struct usb_fifo *f, uint32_t bufsize,
	    uint16_t nbuf);
void	usb_fifo_free_buffer(struct usb_fifo *f);
uint32_t usb_fifo_put_bytes_max(struct usb_fifo *fifo);
void	usb_fifo_put_data(struct usb_fifo *fifo, struct usb_page_cache *pc,
	    usb_frlength_t offset, usb_frlength_t len, uint8_t what);
void	usb_fifo_put_data_linear(struct usb_fifo *fifo, void *ptr,
	    usb_size_t len, uint8_t what);
uint8_t	usb_fifo_put_data_buffer(struct usb_fifo *f, void *ptr, usb_size_t len);
void	usb_fifo_put_data_error(struct usb_fifo *fifo);
uint8_t	usb_fifo_get_data(struct usb_fifo *fifo, struct usb_page_cache *pc,
	    usb_frlength_t offset, usb_frlength_t len, usb_frlength_t *actlen,
	    uint8_t what);
uint8_t	usb_fifo_get_data_linear(struct usb_fifo *fifo, void *ptr,
	    usb_size_t len, usb_size_t *actlen, uint8_t what);
uint8_t	usb_fifo_get_data_buffer(struct usb_fifo *f, void **pptr,
	    usb_size_t *plen);
void	usb_fifo_reset(struct usb_fifo *f);
void	usb_fifo_wakeup(struct usb_fifo *f);
void	usb_fifo_get_data_error(struct usb_fifo *fifo);
void	*usb_fifo_softc(struct usb_fifo *fifo);
void	usb_fifo_set_close_zlp(struct usb_fifo *, uint8_t);
void	usb_fifo_set_write_defrag(struct usb_fifo *, uint8_t);
void	usb_fifo_free(struct usb_fifo *f);
#endif /* _KERNEL */
#endif /* _USB_USBDI_H_ */


code:
/*-
 * Copyright (c) 2009 Andrew Thompson
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * $FreeBSD: release/9.0.0/sys/dev/usb/usbdi_util.h 213435 2010-10-04 23:18:05Z hselasky $
 */
#ifndef _USB_USBDI_UTIL_H_
#define _USB_USBDI_UTIL_H_

struct cv;

/* structures */

struct usb_idesc_parse_state {
	struct usb_descriptor *desc;
	uint8_t iface_index;		/* current interface index */
	uint8_t iface_no_last;
	uint8_t iface_index_alt;	/* current alternate setting */
};

/* prototypes */

usb_error_t usbd_do_request_proc(struct usb_device *udev, struct usb_process *pproc,
		    struct usb_device_request *req, void *data, uint16_t flags,
		    uint16_t *actlen, usb_timeout_t timeout);

struct usb_descriptor *usb_desc_foreach(struct usb_config_descriptor *cd,
	    struct usb_descriptor *desc);
struct usb_interface_descriptor *usb_idesc_foreach(
	    struct usb_config_descriptor *cd,
	    struct usb_idesc_parse_state *ps);
struct usb_endpoint_descriptor *usb_edesc_foreach(
	    struct usb_config_descriptor *cd,
	    struct usb_endpoint_descriptor *ped);
struct usb_endpoint_ss_comp_descriptor *usb_ed_comp_foreach(
	    struct usb_config_descriptor *cd,
	    struct usb_endpoint_ss_comp_descriptor *ped);
uint8_t usbd_get_no_descriptors(struct usb_config_descriptor *cd,
	    uint8_t type);
uint8_t usbd_get_no_alts(struct usb_config_descriptor *cd,
	    struct usb_interface_descriptor *id);

usb_error_t usbd_req_get_report(struct usb_device *udev, struct mtx *mtx,
		    void *data, uint16_t len, uint8_t iface_index, uint8_t type,
		    uint8_t id);
usb_error_t usbd_req_get_report_descriptor(struct usb_device *udev,
		    struct mtx *mtx, void *d, uint16_t size,
		    uint8_t iface_index);
usb_error_t usbd_req_get_string_any(struct usb_device *udev, struct mtx *mtx,
		    char *buf, uint16_t len, uint8_t string_index);
usb_error_t usbd_req_get_string_desc(struct usb_device *udev, struct mtx *mtx,
		    void *sdesc, uint16_t max_len, uint16_t lang_id,
		    uint8_t string_index);
usb_error_t usbd_req_set_config(struct usb_device *udev, struct mtx *mtx,
		    uint8_t conf);
usb_error_t usbd_req_set_alt_interface_no(struct usb_device *udev,
		    struct mtx *mtx, uint8_t iface_index, uint8_t alt_no);
usb_error_t usbd_req_set_idle(struct usb_device *udev, struct mtx *mtx,
		    uint8_t iface_index, uint8_t duration, uint8_t id);
usb_error_t usbd_req_set_protocol(struct usb_device *udev, struct mtx *mtx,
		    uint8_t iface_index, uint16_t report);
usb_error_t usbd_req_set_report(struct usb_device *udev, struct mtx *mtx,
		    void *data, uint16_t len, uint8_t iface_index,
		    uint8_t type, uint8_t id);

/* The following functions will not return NULL strings. */

const char *usb_get_manufacturer(struct usb_device *);
const char *usb_get_product(struct usb_device *);
const char *usb_get_serial(struct usb_device *);

#endif /* _USB_USBDI_UTIL_H_ */

repo_name: veiledmerc/mira

license: mit


code:
/* $FreeBSD: release/9.0.0/sys/dev/usb/usbhid.h 223755 2011-07-04 07:37:28Z hselasky $ */
/*-
 * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
 * Copyright (c) 1998 The NetBSD Foundation, Inc. All rights reserved.
 * Copyright (c) 1998 Lennart Augustsson. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

#ifndef _USB_HID_H_
#define	_USB_HID_H_

#include <dev/usb/usb_endian.h>

#define	UR_GET_HID_DESCRIPTOR	0x06
#define	UDESC_HID		0x21
#define	UDESC_REPORT		0x22
#define	UDESC_PHYSICAL		0x23
#define	UR_SET_HID_DESCRIPTOR	0x07
#define	UR_GET_REPORT		0x01
#define	UR_SET_REPORT		0x09
#define	UR_GET_IDLE		0x02
#define	UR_SET_IDLE		0x0a
#define	UR_GET_PROTOCOL		0x03
#define	UR_SET_PROTOCOL		0x0b

struct usb_hid_descriptor {
	uByte	bLength;
	uByte	bDescriptorType;
	uWord	bcdHID;
	uByte	bCountryCode;
	uByte	bNumDescriptors;
	struct {
		uByte	bDescriptorType;
		uWord	wDescriptorLength;
	}	descrs[1];
} __packed;

#define	USB_HID_DESCRIPTOR_SIZE(n) (9+((n)*3))

/* Usage pages */
#define	HUP_UNDEFINED		0x0000
#define	HUP_GENERIC_DESKTOP	0x0001
#define	HUP_SIMULATION		0x0002
#define	HUP_VR_CONTROLS		0x0003
#define	HUP_SPORTS_CONTROLS	0x0004
#define	HUP_GAMING_CONTROLS	0x0005
#define	HUP_KEYBOARD		0x0007
#define	HUP_LEDS		0x0008
#define	HUP_BUTTON		0x0009
#define	HUP_ORDINALS		0x000a
#define	HUP_TELEPHONY		0x000b
#define	HUP_CONSUMER		0x000c
#define	HUP_DIGITIZERS		0x000d
#define	HUP_PHYSICAL_IFACE	0x000e
#define	HUP_UNICODE		0x0010
#define	HUP_ALPHANUM_DISPLAY	0x0014
#define	HUP_MONITOR		0x0080
#define	HUP_MONITOR_ENUM_VAL	0x0081
#define	HUP_VESA_VC		0x0082
#define	HUP_VESA_CMD		0x0083
#define	HUP_POWER		0x0084
#define	HUP_BATTERY_SYSTEM	0x0085
#define	HUP_BARCODE_SCANNER	0x008b
#define	HUP_SCALE		0x008c
#define	HUP_CAMERA_CONTROL	0x0090
#define	HUP_ARCADE		0x0091
#define	HUP_MICROSOFT		0xff00

/* Usages, generic desktop */
#define	HUG_POINTER		0x0001
#define	HUG_MOUSE		0x0002
#define	HUG_JOYSTICK		0x0004
#define	HUG_GAME_PAD		0x0005
#define	HUG_KEYBOARD		0x0006
#define	HUG_KEYPAD		0x0007
#define	HUG_X			0x0030
#define	HUG_Y			0x0031
#define	HUG_Z			0x0032
#define	HUG_RX			0x0033
#define	HUG_RY			0x0034
#define	HUG_RZ			0x0035
#define	HUG_SLIDER		0x0036
#define	HUG_DIAL		0x0037
#define	HUG_WHEEL		0x0038
#define	HUG_HAT_SWITCH		0x0039
#define	HUG_COUNTED_BUFFER	0x003a
#define	HUG_BYTE_COUNT		0x003b
#define	HUG_MOTION_WAKEUP	0x003c
#define	HUG_VX			0x0040
#define	HUG_VY			0x0041
#define	HUG_VZ			0x0042
#define	HUG_VBRX		0x0043
#define	HUG_VBRY		0x0044
#define	HUG_VBRZ		0x0045
#define	HUG_VNO			0x0046
#define	HUG_TWHEEL		0x0048	/* M$ Wireless Intellimouse Wheel */
#define	HUG_SYSTEM_CONTROL	0x0080
#define	HUG_SYSTEM_POWER_DOWN	0x0081
#define	HUG_SYSTEM_SLEEP	0x0082
#define	HUG_SYSTEM_WAKEUP	0x0083
#define	HUG_SYSTEM_CONTEXT_MENU	0x0084
#define	HUG_SYSTEM_MAIN_MENU	0x0085
#define	HUG_SYSTEM_APP_MENU	0x0086
#define	HUG_SYSTEM_MENU_HELP	0x0087
#define	HUG_SYSTEM_MENU_EXIT	0x0088
#define	HUG_SYSTEM_MENU_SELECT	0x0089
#define	HUG_SYSTEM_MENU_RIGHT	0x008a
#define	HUG_SYSTEM_MENU_LEFT	0x008b
#define	HUG_SYSTEM_MENU_UP	0x008c
#define	HUG_SYSTEM_MENU_DOWN	0x008d
#define	HUG_APPLE_EJECT		0x00b8

/* Usages Digitizers */
#define	HUD_UNDEFINED		0x0000
#define	HUD_TIP_PRESSURE	0x0030
#define	HUD_BARREL_PRESSURE	0x0031
#define	HUD_IN_RANGE		0x0032
#define	HUD_TOUCH		0x0033
#define	HUD_UNTOUCH		0x0034
#define	HUD_TAP			0x0035
#define	HUD_QUALITY		0x0036
#define	HUD_DATA_VALID		0x0037
#define	HUD_TRANSDUCER_INDEX	0x0038
#define	HUD_TABLET_FKEYS	0x0039
#define	HUD_PROGRAM_CHANGE_KEYS	0x003a
#define	HUD_BATTERY_STRENGTH	0x003b
#define	HUD_INVERT		0x003c
#define	HUD_X_TILT		0x003d
#define	HUD_Y_TILT		0x003e
#define	HUD_AZIMUTH		0x003f
#define	HUD_ALTITUDE		0x0040
#define	HUD_TWIST		0x0041
#define	HUD_TIP_SWITCH		0x0042
#define	HUD_SEC_TIP_SWITCH	0x0043
#define	HUD_BARREL_SWITCH	0x0044
#define	HUD_ERASER		0x0045
#define	HUD_TABLET_PICK		0x0046

/* Usages, Consumer */
#define	HUC_AC_PAN		0x0238

#define	HID_USAGE2(p,u) (((p) << 16) | (u))

#define	UHID_INPUT_REPORT 0x01
#define	UHID_OUTPUT_REPORT 0x02
#define	UHID_FEATURE_REPORT 0x03

/* Bits in the input/output/feature items */
#define	HIO_CONST	0x001
#define	HIO_VARIABLE	0x002
#define	HIO_RELATIVE	0x004
#define	HIO_WRAP	0x008
#define	HIO_NONLINEAR	0x010
#define	HIO_NOPREF	0x020
#define	HIO_NULLSTATE	0x040
#define	HIO_VOLATILE	0x080
#define	HIO_BUFBYTES	0x100

#ifdef _KERNEL
struct usb_config_descriptor;

enum hid_kind {
	hid_input, hid_output, hid_feature, hid_collection, hid_endcollection
};

struct hid_location {
	uint32_t size;
	uint32_t count;
	uint32_t pos;
};

struct hid_item {
	/* Global */
	int32_t	_usage_page;
	int32_t	logical_minimum;
	int32_t	logical_maximum;
	int32_t	physical_minimum;
	int32_t	physical_maximum;
	int32_t	unit_exponent;
	int32_t	unit;
	int32_t	report_ID;
	/* Local */
	int32_t	usage;
	int32_t	usage_minimum;
	int32_t	usage_maximum;
	int32_t	designator_index;
	int32_t	designator_minimum;
	int32_t	designator_maximum;
	int32_t	string_index;
	int32_t	string_minimum;
	int32_t	string_maximum;
	int32_t	set_delimiter;
	/* Misc */
	int32_t	collection;
	int	collevel;
	enum hid_kind kind;
	uint32_t flags;
	/* Location */
	struct hid_location loc;
};

/* prototypes from "usb_hid.c" */

struct hid_data *hid_start_parse(const void *d, usb_size_t len, int kindset);
void	hid_end_parse(struct hid_data *s);
int	hid_get_item(struct hid_data *s, struct hid_item *h);
int	hid_report_size(const void *buf, usb_size_t len, enum hid_kind k,
	    uint8_t *id);
int	hid_locate(const void *desc, usb_size_t size, uint32_t usage,
	    enum hid_kind kind, uint8_t index, struct hid_location *loc,
	    uint32_t *flags, uint8_t *id);
int32_t hid_get_data(const uint8_t *buf, usb_size_t len,
	    struct hid_location *loc);
uint32_t hid_get_data_unsigned(const uint8_t *buf, usb_size_t len,
	    struct hid_location *loc);
void hid_put_data_unsigned(uint8_t *buf, usb_size_t len,
	    struct hid_location *loc, unsigned int value);
int	hid_is_collection(const void *desc, usb_size_t size, uint32_t usage);
struct usb_hid_descriptor *hid_get_descriptor_from_usb(
	    struct usb_config_descriptor *cd,
	    struct usb_interface_descriptor *id);
usb_error_t usbd_req_get_hid_desc(struct usb_device *udev, struct mtx *mtx,
	    void **descp, uint16_t *sizep, struct malloc_type *mem,
	    uint8_t iface_index);
#endif					/* _KERNEL */
#endif					/* _USB_HID_H_ */


code:
/*-
 * Copyright (c) 2003
 *	Fraunhofer Institute for Open Communication Systems (FhG Fokus).
 * 	All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * Author: Hartmut Brandt <harti@freebsd.org>
 *
 * $FreeBSD: release/9.0.0/sys/dev/utopia/idtphy.h 139749 2005-01-06 01:43:34Z imp $
 *
 * Register definitions for the following chips:
 *	IDT 77105
 *	IDT 77155
 */
#ifndef _DEV_UTOPIA_IDTPHY_H
#define	_DEV_UTOPIA_IDTPHY_H

#define	IDTPHY_REGO_MCR		0x00
#define	IDTPHY_REGN_MCR		"Master Control Register"
#define	IDTPHY_REGX_MCR		"\020\010UPLO\7DREC\6ECEI\5TDPC\4DRIC\3HALTTX\2BYTEM\1EI"
#define	IDTPHY_REGM_MCR_UPL0	0x80
#define	IDTPHY_REGM_MCR_DREC	0x40
#define	IDTPHY_REGM_MCR_ECEI	0x20
#define	IDTPHY_REGM_MCR_TDPC	0x10
#define	IDTPHY_REGM_MCR_DRIC	0x08
#define	IDTPHY_REGM_MCR_HALTTX	0x04
#define	IDTPHY_REGM_MCR_BYTEM	0x02
#define	IDTPHY_REGM_MCR_EI	0x01

#define	IDTPHY_REGO_ISTAT	0x01
#define	IDTPHY_REGN_ISTAT	"Interrupt Status"
#define	IDTPHY_REGX_ISTAT	"\020\7GOOD\6HECE\5SCRE\4TPE\3RSCC\2RSE\1RFO"
#define	IDTPHY_REGM_ISTAT_GOOD	0x40	/* good signal bit */
#define	IDTPHY_REGM_ISTAT_HECE	0x20	/* HEC error */
#define	IDTPHY_REGM_ISTAT_SCRE	0x10	/* short cell received error */
#define	IDTPHY_REGM_ISTAT_TPE	0x08	/* transmit parity error */
#define	IDTPHY_REGM_ISTAT_RSCC	0x04	/* receive signal condition change */
#define	IDTPHY_REGM_ISTAT_RSE	0x02	/* receive symbol error */
#define	IDTPHY_REGM_ISTAT_RFO	0x01	/* read FIFO overrun */

#define	IDTPHY_REGO_DIAG	0x02
#define	IDTPHY_REGN_DIAG	"Diagnostic Control"
#define	IDTPHY_REGX_DIAG	"\020\010FTD\7ROS\6MULTI\5RFLUSH\4ITPE\3IHECE\11\3\0NORM\11\3\2PLOOP\11\3\3LLOOP"
#define	IDTPHY_REGM_DIAG_FTD	0x80	/* Force TxClav Deassert */
#define	IDTPHY_REGM_DIAG_ROS	0x40	/* RxClav Operation Select */
#define	IDTPHY_REGM_DIAG_MULTI	0x20	/* Multi-phy operation */
#define	IDTPHY_REGM_DIAG_RFLUSH	0x10	/* clear receive Fifo */
#define	IDTPHY_REGM_DIAG_ITPE	0x08	/* insert transmit payload error */
#define	IDTPHY_REGM_DIAG_IHECE	0x04	/* insert transmit HEC error */
#define	IDTPHY_REGM_DIAG_LOOP	0x03	/* loopback mode */
#define	IDTPHY_REGM_DIAG_LOOP_NONE	0x00	/* normal */
#define	IDTPHY_REGM_DIAG_LOOP_PHY	0x02	/* PHY loopback */
#define	IDTPHY_REGM_DIAG_LOOP_LINE	0x03	/* Line loopback */

#define	IDTPHY_REGO_LHEC	0x03
#define	IDTPHY_REGN_LHEC	"LED Driver and HEC Status/Control"
#define	IDTPHY_REGX_LHEC	"\020\7DRHEC\6DTHEC\11\x18\0CYC1\11\x18\1CYC2\11\x18\2CYC4\11\x18\3CYC8\3FIFOE\2TXLED\1RXLED"
#define	IDTPHY_REGM_LHEC_DRHEC	0x40	/* disable receive HEC */
#define	IDTPHY_REGM_LHEC_DTHEC	0x20	/* disable transmit HEC */
#define	IDTPHY_REGM_LHEC_RXREF	0x18	/* RxRef pulse width */
#define	IDTPHY_REGM_LHEC_RXREF1	0x00	/* 1 pulse */
#define	IDTPHY_REGM_LHEC_RXREF2	0x08	/* 2 pulse */
#define	IDTPHY_REGM_LHEC_RXREF4	0x10	/* 4 pulse */
#define	IDTPHY_REGM_LHEC_RXREF8	0x18	/* 8 pulse */
#define	IDTPHY_REGM_LHEC_FIFOE	0x04	/* Fifo empty */
#define	IDTPHY_REGM_LHEC_TXLED	0x02	/* Tx LED status */
#define	IDTPHY_REGM_LHEC_RXLED	0x01	/* Rx LED status */

#define	IDTPHY_REGO_CNT		0x04	/* +0x05 */
#define	IDTPHY_REGN_CNT		"Counter"

#define	IDTPHY_REGO_CNTS	0x06
#define	IDTPHY_REGN_CNTS	"Counter select"
#define	IDTPHY_REGX_CNTS	"\020\4SEC\3TX\2RX\1HECE"
#define	IDTPHY_REGM_CNTS_SEC	0x08	/* symbol error counter */
#define	IDTPHY_REGM_CNTS_TX	0x04	/* Tx cells */
#define	IDTPHY_REGM_CNTS_RX	0x02	/* Rx cells */
#define	IDTPHY_REGM_CNTS_HECE	0x01	/* HEC errors */

#define	IDTPHY_PRINT_77105					\
	{ /* 00 */						\
	  UTP_REGT_BITS,	IDTPHY_REGO_MCR,		\
	  IDTPHY_REGN_MCR,	IDTPHY_REGX_MCR },		\
	{ /* 01 */						\
	  UTP_REGT_BITS,	IDTPHY_REGO_ISTAT,		\
	  IDTPHY_REGN_ISTAT,	IDTPHY_REGX_ISTAT },		\
	{ /* 02 */						\
	  UTP_REGT_BITS,	IDTPHY_REGO_DIAG,		\
	  IDTPHY_REGN_DIAG,	IDTPHY_REGX_DIAG },		\
	{ /* 03 */						\
	  UTP_REGT_BITS,	IDTPHY_REGO_LHEC,		\
	  IDTPHY_REGN_LHEC,	IDTPHY_REGX_LHEC },		\
	{ /* 04, 05 */						\
	  UTP_REGT_INT16,	IDTPHY_REGO_CNT,		\
	  IDTPHY_REGN_CNT,	NULL },				\
	{ /* 06 */						\
	  UTP_REGT_BITS,	IDTPHY_REGO_CNTS,		\
	  IDTPHY_REGN_CNTS,	IDTPHY_REGX_CNTS }

#define	IDTPHY_REGO_MRID	0x00
#define	IDTPHY_REGN_MRID	"Master Reset & ID"
#define	IDTPHY_REGM_MRID_RESET	0x80	/* software reset */
#define	IDTPHY_REGM_MRID_TYPE	0x70	/* type */
#define	IDTPHY_REGM_MRID_155	0x30	/* idt77155 type */
#define	IDTPHY_REGM_MRID_ID	0x0f	/* revision */
#define	IDTPHY_REGX_MRID	\
	    "\020\010mstReset\12\x70\12type\12\xf\12id"

#define	IDTPHY_REGO_CONF	0x01
#define	IDTPHY_REGN_CONF	"Configuration"
#define	IDTPHY_REGM_CONF_AFEBE	0x40	/* autoFEBE */
#define	IDTPHY_REGM_CONF_ALRDI	0x20	/* autoLRDI */
#define	IDTPHY_REGM_CONF_APRDI	0x10	/* autoPRDI */
#define	IDTPHY_REGM_CONF_TCAIN	0x08	/* TCAInv */
#define	IDTPHY_REGM_CONF_RCAIN	0x04	/* RCAInv */
#define	IDTPHY_REGM_CONF_RXDIN	0x02	/* RXDInv */
#define	IDTPHY_REGM_CONF_RESV	0x81
#define	IDTPHY_REGX_CONF	\
	    "\020\07autoFEBE\6autoLRDI\5autoPRDI\4TCAInv\3RCAInv\2RXDInv"

#define	IDTPHY_REGO_INT		0x02
#define	IDTPHY_REGN_INT		"Interrupt"
#define	IDTPHY_REGM_INT_TXOOLI	0x80	/* txOOLInt */
#define	IDTPHY_REGM_INT_RXLOCI	0x40	/* rxLOCInt */
#define	IDTPHY_REGM_INT_RXOOLI	0x20	/* rxOOLInt */
#define	IDTPHY_REGM_INT_TXCDI	0x10	/* txCDi */
#define	IDTPHY_REGM_INT_RXCDI	0x08	/* rxCDi */
#define	IDTPHY_REGM_INT_RXPOHI	0x04	/* rxPOHi */
#define	IDTPHY_REGM_INT_RXLOHI	0x02	/* rxLOHi */
#define	IDTPHY_REGM_INT_RXSOHI	0x01	/* rxSOHi */
#define	IDTPHY_REGX_INT		\
	    "\020\10txOOLInt\7rxLOCInt\6rxOOLInt\5txCDi\4rxCDi\3rxPOHi" \
	    "\2rxLOHi\1rxSOHi"

#define	IDTPHY_REGO_MCM		0x04
#define	IDTPHY_REGN_MCM		"Master Clock Monitor"
#define	IDTPHY_REGM_MCM_RRCLK	0x08	/* rrclkReg */
#define	IDTPHY_REGM_MCM_TRCLK	0x04	/* trclkReg */
#define	IDTPHY_REGM_MCM_RCLK	0x02	/* rclkReg */
#define	IDTPHY_REGM_MCM_TCLK	0x01	/* tclkReg */
#define	IDTPHY_REGM_MCM_RESV	0xf0
#define	IDTPHY_REGX_MCM		\
	    "\020\4rrclkReg\3trclkReg\2rclkReg\1tclkReg"

#define	IDTPHY_REGO_MCTL	0x05
#define	IDTPHY_REGN_MCTL	"Master Control"
#define	IDTPHY_REGM_MCTL_LOCI	0x80	/* rxLOCIEn */
#define	IDTPHY_REGM_MCTL_LOC	0x40	/* LOC */
#define	IDTPHY_REGM_MCTL_FIXP	0x20	/* txFixptr */
#define	IDTPHY_REGM_MCTL_LLOOP	0x04	/* txLLoop */
#define	IDTPHY_REGM_MCTL_DLOOP	0x02	/* rxDLoop */
#define	IDTPHY_REGM_MCTL_TLOOP	0x01	/* rxLoopT */
#define	IDTPHY_REGM_MCTL_RESV	0x18
#define	IDTPHY_REGX_MCTL	\
	    "\020\10rxLOCIEn\7LOC\6txFixptr\3txLLoop\2rxDLoop\1rxLoopT"

#define	IDTPHY_REGO_TXC		0x06
#define	IDTPHY_REGN_TXC		"Transmit Clock Synthesis C/S"
#define	IDTPHY_REGM_TXC_TXOOL	0x08	/* txOOL */
#define	IDTPHY_REGM_TXC_TXOOLI	0x02	/* txOOLIEn */
#define	IDTPHY_REGM_TXC_TXREF	0x01	/* txrefSel */
#define	IDTPHY_REGM_TXC_RESV	0xf4
#define	IDTPHY_REGX_TXC		\
	    "\020\4txOOL\2txOOLIEn\1txrefSel"

#define	IDTPHY_REGO_RXC		0x07
#define	IDTPHY_REGN_RXC		"Receive Clock/Data Recovery C/S"
#define	IDTPHY_REGM_RXC_RXOOL	0x08	/* rxOOL */
#define	IDTPHY_REGM_RXC_RXOOLI	0x02	/* rxOOLIEn */
#define	IDTPHY_REGM_RXC_RXREF	0x01	/* rxrefSel */
#define	IDTPHY_REGM_RXC_RESV	0xf4
#define	IDTPHY_REGX_RXC		\
	    "\020\4rxOOL\2rxOOLIEn\1rxrefSel"

#define	IDTPHY_REGO_RSOC	0x10
#define	IDTPHY_REGN_RSOC	"Receive Overhead Control"
#define	IDTPHY_REGM_RSOC_DSCR	0x40	/* scrDis */
#define	IDTPHY_REGM_RSOC_FOOF	0x20	/* frcOOF */
#define	IDTPHY_REGM_RSOC_B1IE	0x08	/* B1ErrIEn */
#define	IDTPHY_REGM_RSOC_LOSI	0x04	/* LOSIEn */
#define	IDTPHY_REGM_RSOC_LOFI	0x02	/* LOFIEn */
#define	IDTPHY_REGM_RSOC_OOFI	0x01	/* OOFIEn */
#define	IDTPHY_REGM_RSOC_RESV	0x90
#define	IDTPHY_REGX_RSOC	\
	    "\020\7scrDis\6frcOOF\4B1ErrIEn\3LOSIEn\2LOFIEn\1OOFIEn"

#define	IDTPHY_REGO_RSOS	0x11
#define	IDTPHY_REGN_RSOS	"Receive Overhead Status"
#define	IDTPHY_REGM_RSOS_C1INT	0x80	/* C1Int */
#define	IDTPHY_REGM_RSOS_B1INT	0x40	/* B1ErrInt */
#define	IDTPHY_REGM_RSOS_LOSI	0x20	/* LOSInt */
#define	IDTPHY_REGM_RSOS_LOFI	0x10	/* LOFInt */
#define	IDTPHY_REGM_RSOS_OOFI	0x08	/* OOFInt */
#define	IDTPHY_REGM_RSOS_LOS	0x04	/* LOS */
#define	IDTPHY_REGM_RSOS_LOF	0x02	/* LOF */
#define	IDTPHY_REGM_RSOS_OOF	0x01	/* OOF */
#define	IDTPHY_REGX_RSOS	\
	    "\020\10C1Int\7B1ErrInt\6LOSInt\5LOFInt\4OOFint\3LOS\2LOF\1OOF"

#define	IDTPHY_REGO_BIPC	0x12	/* + 0x13 LE */
#define	IDTPHY_REGN_BIPC	"Receive Section BIP Errors"

#define	IDTPHY_REGO_TSOC	0x14
#define	IDTPHY_REGN_TSOC	"Transmit Overhead Control"
#define	IDTPHY_REGM_TSOC_DSCR	0x40	/* scrDis */
#define	IDTPHY_REGM_TSOC_LAISI	0x01	/* LAISIns */
#define	IDTPHY_REGM_TSOC_RESV	0xbe
#define	IDTPHY_REGX_TSOC	\
	    "\020\7scrDis\1LAISIns"

#define	IDTPHY_REGO_TSOC2	0x15
#define	IDTPHY_REGN_TSOC2	"Transmit Overhead Control 2"
#define	IDTPHY_REGM_TSOC2_LOSI	0x04	/* LOSIns */
#define	IDTPHY_REGM_TSOC2_B1INV	0x02	/* B1Inv */
#define	IDTPHY_REGM_TSOC2_IFE	0x01	/* frErrIns */
#define	IDTPHY_REGM_TSOC2_RESV	0xf8
#define	IDTPHY_REGX_TSOC2	\
	    "\020\3LOSIns\2B1Inv\1frErrIns"

#define	IDTPHY_REGO_RLOS	0x18
#define	IDTPHY_REGN_RLOS	"Receive Line Overhead Status"
#define	IDTPHY_REGM_RLOS_B2W	0x80	/* B2Word */
#define	IDTPHY_REGM_RLOS_LAIS	0x02	/* LAIS */
#define	IDTPHY_REGM_RLOS_LRDI	0x01	/* LRDI */
#define	IDTPHY_REGM_RLOS_RESV	0x7c
#define	IDTPHY_REGX_RLOS	\
	    "\020\10B2Word\2LAIS\1LRDI"

#define	IDTPHY_REGO_RLOI	0x19
#define	IDTPHY_REGN_RLOI	"Receive Line Overhead Interrupt"
#define	IDTPHY_REGM_RLOI_LFEBEE	0x80	/* LFEBEIEn */
#define	IDTPHY_REGM_RLOI_B2EE	0x40	/* B2ErrIEn */
#define	IDTPHY_REGM_RLOI_LAISE	0x20	/* LAISIEn */
#define	IDTPHY_REGM_RLOI_LRDIE	0x10	/* LRDIIEn */
#define	IDTPHY_REGM_RLOI_LFEBEI	0x08	/* LFEBEInt */
#define	IDTPHY_REGM_RLOI_B2EI	0x04	/* B2ErrInt */
#define	IDTPHY_REGM_RLOI_LAISI	0x02	/* LAISInt */
#define	IDTPHY_REGM_RLOI_LRDII	0x01	/* LRDIInt */
#define	IDTPHY_REGX_RLOI	\
	    "\020\10LFEBEIEn\7B2ErrIEn\6LAISIEn\5LRDIIEn\4LFEBEInt\3B2ErrInt" \
	    "\2LAISInt\1LRDIInt"

#define	IDTPHY_REGO_B2EC	0x1a	/* + 0x1b, 0x1c, 20bit LE */
#define	IDTPHY_REGN_B2EC	"B2 Errors"

#define	IDTPHY_REGO_FEBEC	0x1d	/* + 0x1e, 0x1f, 20bit LE */
#define	IDTPHY_REGN_FEBEC	"Line FEBE Errors"

#define	IDTPHY_REGO_TLOS	0x20
#define	IDTPHY_REGN_TLOS	"Transmit Line Overhead Status"
#define	IDTPHY_REGM_TLOS_LRDI	0x01	/* LRDI */
#define	IDTPHY_REGM_TLOS_RESV	0xfe
#define	IDTPHY_REGX_TLOS	\
	    "\020\1LRDI"

#define	IDTPHY_REGO_TLOC	0x21
#define	IDTPHY_REGN_TLOC	"Transmit Line Overhead Control"
#define	IDTPHY_REGM_TLOC_B2INV	0x01	/* B2Inv */
#define	IDTPHY_REGM_TLOC_RESV	0xfe
#define	IDTPHY_REGX_TLOC	\
	    "\020\1B2Inv"

#define	IDTPHY_REGO_TK1		0x24
#define	IDTPHY_REGN_TK1		"Transmit K1"

#define	IDTPHY_REGO_TK2		0x25
#define	IDTPHY_REGN_TK2		"Transmit K2"

#define	IDTPHY_REGO_RK1		0x26
#define	IDTPHY_REGN_RK1		"Receive K1"

#define	IDTPHY_REGO_RK2		0x27
#define	IDTPHY_REGN_RK2		"Receive K2"

#define	IDTPHY_REGO_RPOS	0x30
#define	IDTPHY_REGN_RPOS	"Receive Path Overhead Status"
#define	IDTPHY_REGM_RPOS_LOP	0x20	/* LOP */
#define	IDTPHY_REGM_RPOS_PAIS	0x08	/* PAIS */
#define	IDTPHY_REGM_RPOS_PRDI	0x04	/* PRDI */
#define	IDTPHY_REGM_RPOS_RESV	0xd3
#define	IDTPHY_REGX_RPOS	\
	    "\020\6LOP\4PAIS\3PRDI"

#define	IDTPHY_REGO_RPOI	0x31
#define	IDTPHY_REGN_RPOI	"Receive Path Overhead Interrupt"
#define	IDTPHY_REGM_RPOI_C2I	0x80	/* C2Int */
#define	IDTPHY_REGM_RPOI_LOPI	0x20	/* LOPInt */
#define	IDTPHY_REGM_RPOI_PAISI	0x08	/* PAISInt */
#define	IDTPHY_REGM_RPOI_PRDII	0x04	/* PRDIInt */
#define	IDTPHY_REGM_RPOI_B3EI	0x02	/* B3ErrInt */
#define	IDTPHY_REGM_RPOI_PFEBEI	0x01	/* PFEBEInt */
#define	IDTPHY_REGM_RPOI_RESV	0x50
#define	IDTPHY_REGX_RPOI	\
	    "\020\10C2Int\6LOPInt\4PAISInt\3PRDIInt\2B3ErrInt\1PFEBEInt"

#define	IDTPHY_REGO_RPIE	0x33
#define	IDTPHY_REGN_RPIE	"Receive Path Interrupt Enable"
#define	IDTPHY_REGM_RPIE_C2E	0x80	/* C2IEn */
#define	IDTPHY_REGM_RPIE_LOPE	0x20	/* LOPIEn */
#define	IDTPHY_REGM_RPIE_PAISE	0x08	/* PAISIEn */
#define	IDTPHY_REGM_RPIE_PRDIE	0x04	/* PRDIIEn */
#define	IDTPHY_REGM_RPIE_B3EE	0x02	/* B3ErrIEn */
#define	IDTPHY_REGM_RPIE_PFEBEE	0x01	/* PFEBEIEn */
#define	IDTPHY_REGM_RPIE_RESV	0x50
#define	IDTPHY_REGX_RPIE	\
	    "\020\10CSIEn\6LOPIEn\4PAISIEn\3PRDIIEn\2B3ErrIEn\1PFEBEIEn"

#define	IDTPHY_REGO_RC2		0x37
#define	IDTPHY_REGN_RC2		"Receive C2"

#define	IDTPHY_REGO_B3EC	0x38	/* + 0x39, LE, 16bit */
#define	IDTPHY_REGN_B3EC	"B3 Errors"

#define	IDTPHY_REGO_PFEBEC	0x3a	/* + 0x3b, LE, 16bit */
#define	IDTPHY_REGN_PFEBEC	"Path FEBE Errors"

#define	IDTPHY_REGO_RPEC	0x3d
#define	IDTPHY_REGN_RPEC	"Receive Path BIP Error Control"
#define	IDTPHY_REGM_RPEC_B3C	0x20	/* blkBIP */
#define	IDTPHY_REGM_RPEC_RESV	0xdf
#define	IDTPHY_REGX_RPEC	\
	    "\020\6blkBIP"

#define	IDTPHY_REGO_TPOC	0x40
#define	IDTPHY_REGN_TPOC	"Transmit Path Control"
#define	IDTPHY_REGM_TPOC_B3INV	0x02	/* B3Inv */
#define	IDTPHY_REGM_TPOC_PAISI	0x01	/* PAISIns */
#define	IDTPHY_REGM_TPOC_RESC	0xfc
#define	IDTPHY_REGX_TPOC	\
	   "\020\2B3Inv\1PAISIns"

#define	IDTPHY_REGO_TPTC	0x41
#define	IDTPHY_REGN_TPTC	"Transmit Pointer Control"
#define	IDTPHY_REGM_TPTC_FPTR	0x40	/* frcPtr */
#define	IDTPHY_REGM_TPTC_STUFF	0x20	/* stuffCtl */
#define	IDTPHY_REGM_TPTC_PTR	0x10	/* Ptr */
#define	IDTPHY_REGM_TPTC_NDF	0x08	/* NDF */
#define	IDTPHY_REGM_TPTC_DECP	0x04	/* decPtr */
#define	IDTPHY_REGM_TPTC_INCP	0x02	/* incPtr */
#define	IDTPHY_REGM_TPTC_RESV	0x81
#define	IDTPHY_REGX_TPTC	\
	    "\020\7frcPtr\6stuffCtl\5Ptr\4NDF\3decPtr\2incPtr"

#define	IDTPHY_REGO_PTRL	0x45
#define	IDTPHY_REGN_PTRL	"Transmit Pointer LSB"
#define	IDTPHY_REGX_PTRL	\
	    "\020\12\xff\20arbPtr"

#define	IDTPHY_REGO_PTRM	0x46
#define	IDTPHY_REGN_PTRM	"Transmit Pointer MSB"
#define	IDTPHY_REGM_PTRM_NDF	0xf0	/* NDFVal */
#define	IDTPHY_REGS_PTRM_NDF	4
#define	IDTPHY_REGM_PTRM_SS	0x0c	/* ssBit */
#define	IDTPHY_REGM_PTRM_SONET	0x00
#define	IDTPHY_REGM_PTRM_SDH	0x08
#define	IDTPHY_REGM_PTRM_PTR	0x03
#define	IDTPHY_REGX_PTRM	\
	    "\020\12\xf0\20NDFVal\12\xc\20ssBit\12\x3\20arbPtr"

#define	IDTPHY_REGO_TC2		0x48
#define	IDTPHY_REGN_TC2		"Transmit C2"

#define	IDTPHY_REGO_TPOC2	0x49
#define	IDTPHY_REGN_TPOC2	"Transmit Path Control 2"
#define	IDTPHY_REGM_TPOC2_FEBE	0xf0	/* PFEBEIns */
#define	IDTPHY_REGS_TPOC2_FEBE	4
#define	IDTPHY_REGM_TPOC2_PRDII	0x08	/* PRDIIns */
#define	IDTPHY_REGM_TPOC2_G1	0x07	/* G1Ins */
#define	IDTPHY_REGX_TPOC2	\
	    "\020\12\xf0\20PFEBEIns\4PRDIIns\12\x7\20G1Ins"

#define	IDTPHY_REGO_RCC		0x50
#define	IDTPHY_REGN_RCC		"Receive Cell Control"
#define	IDTPHY_REGM_RCC_OCD	0x80	/* OCD */
#define	IDTPHY_REGM_RCC_PARTY	0x40	/* parity */
#define	IDTPHY_REGM_RCC_PASS	0x20	/* pass */
#define	IDTPHY_REGM_RCC_DCOR	0x10	/* corDis */
#define	IDTPHY_REGM_RCC_DHEC	0x08	/* HECdis */
#define	IDTPHY_REGM_RCC_ADD	0x04	/* csetAdd */
#define	IDTPHY_REGM_RCC_DSCR	0x02	/* scrDis */
#define	IDTPHY_REGM_RCC_RFIFO	0x01	/* rxFIFOrst */
#define	IDTPHY_REGX_RCC		\
	    "\020\10OCD\7parity\6pass\5corDis\4HECdis\3csetAdd" \
	    "\2scrDis\1rxFIFOrst"

#define	IDTPHY_REGO_RCI		0x51
#define	IDTPHY_REGN_RCI		"Receive Cell Interrupt"
#define	IDTPHY_REGM_RCI_OCDE	0x80	/* OCDIEn */
#define	IDTPHY_REGM_RCI_HECE	0x40	/* HECIEn */
#define	IDTPHY_REGM_RCI_OVFE	0x20	/* ovfIEn */
#define	IDTPHY_REGM_RCI_OCDI	0x10	/* OCDInt */
#define	IDTPHY_REGM_RCI_CORI	0x08	/* corInt */
#define	IDTPHY_REGM_RCI_UCORI	0x04	/* uncorInt */
#define	IDTPHY_REGM_RCI_OVFI	0x02	/* ovfInt */
#define	IDTPHY_REGM_RCI_RESV	0x01
#define	IDTPHY_REGX_RCI		\
	    "\020\10OCDIEn\7HECIEn\6ovfIEn\5OCDInt\4corInt\3uncorInt\2ovfInt"

#define	IDTPHY_REGO_CMH		0x52
#define	IDTPHY_REGN_CMH		"Receive Cell Match Header"
#define	IDTPHY_REGM_CMH_GFC	0xf0	/* GFC */
#define	IDTPHY_REGS_CMH_GFC	4
#define	IDTPHY_REGM_CMH_PTI	0x0e	/* PTI */
#define	IDTPHY_REGS_CMH_PTI	1
#define	IDTPHY_REGM_CMH_CLP	0x01	/* CLP */
#define	IDTPHY_REGX_CMH		\
	    "\020\12\xf0\20GFC\12\xe\20PTI\12\x1\20CLP"

#define	IDTPHY_REGO_CMHM	0x53
#define	IDTPHY_REGN_CMHM	"Receive Cell Match Header Mask"
#define	IDTPHY_REGM_CMHM_GFC	0xf0	/* mskGFC */
#define	IDTPHY_REGS_CMHM_GFC	4
#define	IDTPHY_REGM_CMHM_PTI	0x0e	/* mskPTI */
#define	IDTPHY_REGS_CMHM_PTI	1
#define	IDTPHY_REGM_CMHM_CLP	0x01	/* mskCLP */
#define	IDTPHY_REGX_CMHM	\
	    "\020\12\xf0\20mskGFC\12\xe\20mskPTI\12\x1\20mskCLP"

#define	IDTPHY_REGO_CEC		0x54
#define	IDTPHY_REGN_CEC		"Correctable Errors"

#define	IDTPHY_REGO_UEC		0x55
#define	IDTPHY_REGN_UEC		"Uncorrectable Errors"

#define	IDTPHY_REGO_RCCNT	0x56	/* +0x57, 0x58, LE, 19bit */
#define	IDTPHY_REGN_RCCNT	"Receive Cells"

#define	IDTPHY_REGO_RCCF	0x59
#define	IDTPHY_REGN_RCCF	"Receive Cell Configuration"
#define	IDTPHY_REGM_RCCF_GFCE	0xf0	/* GFCen */
#define	IDTPHY_REGS_RCCF_GFCE	4
#define	IDTPHY_REGM_RCCF_FIXS	0x08	/* FixSen */
#define	IDTPHY_REGM_RCCF_RCAL	0x04	/* RCAlevel */
#define	IDTPHY_REGM_RCCF_HECF	0x03	/* HECftr */
#define	IDTPHY_REGX_RCCF	\
	    "\020\12\xf0\20GFCen\4FixSen\3RCAlevel\12\x3\20HECftr"

#define	IDTPHY_REGO_RXID	0x5a
#define	IDTPHY_REGN_RXID	"Receive ID Address"
#define	IDTPHY_REGM_RXID_ID	0x03	/* IDAddr */
#define	IDTPHY_REGM_RXID_RESV	0xfc
#define	IDTPHY_REGX_RXID	\
	    "\020\12\x3\20IDAddr"

#define	IDTPHY_REGO_TCC		0x60
#define	IDTPHY_REGN_TCC		"Transmit Cell Control"
#define	IDTPHY_REGM_TCC_FIFOE	0x80	/* fovrIEn */
#define	IDTPHY_REGM_TCC_SOCI	0x40	/* socInt */
#define	IDTPHY_REGM_TCC_FIFOI	0x20	/* fovrInt */
#define	IDTPHY_REGM_TCC_HECINV	0x10	/* HECInv */
#define	IDTPHY_REGM_TCC_HECDIS	0x08	/* HECDis */
#define	IDTPHY_REGM_TCC_ADD	0x04	/* csetAdd */
#define	IDTPHY_REGM_TCC_DSCR	0x02	/* scrDis */
#define	IDTPHY_REGM_TCC_FIFOR	0x01	/* txFIFOrst */
#define	IDTPHY_REGX_TCC		\
	    "\020\10fovrIEn\7socInt\6fovrInt\5HECInv\4HECDis\3csetAdd" \
	    "\2scrDis\1txFIFOrst"

#define	IDTPHY_REGO_TCHP	0x61
#define	IDTPHY_REGN_TCHP	"Transmit Idle Cell Header"
#define	IDTPHY_REGM_TCHP_GFC	0xf0	/* GFCtx */
#define	IDTPHY_REGS_TCHP_GFC	4
#define	IDTPHY_REGM_TCHP_PTI	0x0e	/* PTItx */
#define	IDTPHY_REGS_TCHP_PTI	1
#define	IDTPHY_REGM_TCHP_CLP	0x01	/* CLPtx */
#define	IDTPHY_REGX_TCHP	\
	    "\020\12\xf0\20GFCtx\12\xe\20PTItx\12\x1\20CLPtx"

#define	IDTPHY_REGO_TPLD	0x62
#define	IDTPHY_REGN_TPLD	"Transmit Idle Cell Payload"

#define	IDTPHY_REGO_TCC2	0x63
#define	IDTPHY_REGN_TCC2	"Transmit Cell Configuration 2"
#define	IDTPHY_REGM_TCC2_PARITY	0x80	/* parity */
#define	IDTPHY_REGM_TCC2_PARE	0x40	/* parIEn */
#define	IDTPHY_REGM_TCC2_PARI	0x10	/* parInt */
#define	IDTPHY_REGM_TCC2_FIFO	0x0c	/* FIFOdpth */
#define	IDTPHY_REGS_TCC2_FIFO	2
#define	IDTPHY_REGM_TCC2_TCAL	0x02	/* TCAlevel */
#define	IDTPHY_REGM_TCC2_RESV	0x01
#define	IDTPHY_REGX_TCC2	\
	    "\020\10parity\7parIEn\5parInt\12\xc\20FIFOdpth\2TCAlevel"

#define	IDTPHY_REGO_TXCNT	0x64	/* +65,66 LE 19bit */
#define	IDTPHY_REGN_TXCNT	"Transmit Cells"

#define	IDTPHY_REGO_TCC3	0x67
#define	IDTPHY_REGN_TCC3	"Transmit Cell Configuration 3"
#define	IDTPHY_REGM_TCC3_GFCE	0xf0	/* txGFCen */
#define	IDTPHY_REGS_TCC3_GFCE	4
#define	IDTPHY_REGM_TCC3_FIXE	0x08	/* txFixSen */
#define	IDTPHY_REGM_TCC3_H4ID	0x04	/* H4InsDis */
#define	IDTPHY_REGM_TCC3_FIXB	0x03	/* fixByte */
#define	IDTPHY_REGM_TCC3_FIX00	0x00	/* 0x00 */
#define	IDTPHY_REGM_TCC3_FIX55	0x01	/* 0x55 */
#define	IDTPHY_REGM_TCC3_FIXAA	0x02	/* 0xAA */
#define	IDTPHY_REGM_TCC3_FIXFF	0x03	/* 0xFF */
#define	IDTPHY_REGX_TCC3	\
	    "\020\12\xf0\20txGFCen\4txFixSen\3H4InsDis" \
	    "\11\x3\x0FIX00\11\x3\x1FIX55\11\x3\x2FIXAA\11\x3\x3FIXFF"

#define	IDTPHY_REGO_TXID	0x68
#define	IDTPHY_REGN_TXID	"Transmit ID Address"
#define	IDTPHY_REGM_TXID_ID	0x03	/* txIDAddr */
#define	IDTPHY_REGM_TXID_RESV	0xfc
#define	IDTPHY_REGX_TXID	\
	    "\020\12\x3\20txIDAddr"

#define	IDTPHY_REGO_RBER	0x70
#define	IDTPHY_REGN_RBER	"Receive BER S/C"
#define	IDTPHY_REGM_RBER_FAILE	0x08	/* FailIEn */
#define	IDTPHY_REGM_RBER_WARNE	0x04	/* WarnIEn */
#define	IDTPHY_REGM_RBER_FAIL	0x02	/* BERfail */
#define	IDTPHY_REGM_RBER_WARN	0x01	/* BERwarn */
#define	IDTPHY_REGM_RBER_RESV	0xf0
#define	IDTPHY_REGX_RBER	\
	    "\020\4FailIEn\3WarnIEn\2BERfail\1BERwarn"

#define	IDTPHY_REGO_BFTH	0x71
#define	IDTPHY_REGN_BFTH	"Receive BER Fail Threshold"

#define	IDTPHY_REGO_BFWIN	0x72
#define	IDTPHY_REGN_BFWIN	"Receive BER Fail Window"

#define	IDTPHY_REGO_BFDEN	0x73	/* +74, 16bit LE */
#define	IDTPHY_REGN_BFDEN	"Receive BER Fail Denominator"

#define	IDTPHY_REGO_BWTH	0x75
#define	IDTPHY_REGN_BWTH	"Receive BER Warn Threshold"

#define	IDTPHY_REGO_BWWIN	0x76
#define	IDTPHY_REGN_BWWIN	"Receive BER Warn Window"

#define	IDTPHY_REGO_BWDEN	0x77	/* +78, 16bit LE */
#define	IDTPHY_REGN_BWDEN	"Receive BER Warn Denomiator"

#define	IDTPHY_REGO_OPEC	0x7f
#define	IDTPHY_REGN_OPEC	"Output PECL Control"
#define	IDTPHY_REGM_OPEC_TXC	0x04	/* pcctl_tc */
#define	IDTPHY_REGM_OPEC_TXD	0x02	/* pcctl_td */
#define	IDTPHY_REGM_OPEC_RXDO	0x01	/* pcctl_r */
#define	IDTPHY_REGM_OPEC_RESV	0xf8
#define	IDTPHY_REGX_OPEC	\
	    "\020\3pctl_tc\2pcctl_td\1pcctl_r"

#define	IDTPHY_PRINT_77155					\
	{ /* 00 */						\
	  UTP_REGT_BITS,	IDTPHY_REGO_MRID,		\
	  IDTPHY_REGN_MRID,	IDTPHY_REGX_MRID },		\
	{ /* 01 */						\
	  UTP_REGT_BITS,	IDTPHY_REGO_CONF,		\
	  IDTPHY_REGN_CONF,	IDTPHY_REGX_CONF },		\
	{ /* 02 */						\
	  UTP_REGT_BITS,	IDTPHY_REGO_INT,		\
	  IDTPHY_REGN_INT,	IDTPHY_REGX_INT },		\
	  /* 03 unused */					\
	{ /* 04 */						\
	  UTP_REGT_BITS,	IDTPHY_REGO_MCM,		\
	  IDTPHY_REGN_MCM,	IDTPHY_REGX_MCM },		\
	{ /* 05 */						\
	  UTP_REGT_BITS,	IDTPHY_REGO_MCTL,		\
	  IDTPHY_REGN_MCTL,	IDTPHY_REGX_MCTL },		\
	{ /* 06 */						\
	  UTP_REGT_BITS,	IDTPHY_REGO_TXC,		\
	  IDTPHY_REGN_TXC,	IDTPHY_REGX_TXC },		\
	{ /* 07 */						\
	  UTP_REGT_BITS,	IDTPHY_REGO_RXC,		\
	  IDTPHY_REGN_RXC,	IDTPHY_REGX_RXC },		\
	  /* 08-0f unused */					\
	{ /* 10 */						\
	  UTP_REGT_BITS,	IDTPHY_REGO_RSOC,		\
	  IDTPHY_REGN_RSOC,	IDTPHY_REGX_RSOC },		\
	{ /* 11 */						\
	  UTP_REGT_BITS,	IDTPHY_REGO_RSOS,		\
	  IDTPHY_REGN_RSOS,	IDTPHY_REGX_RSOS },		\
	{ /* 12, 13 */						\
	  UTP_REGT_INT16,	IDTPHY_REGO_BIPC,		\
	  IDTPHY_REGN_BIPC,	NULL },				\
	{ /* 14 */						\
	  UTP_REGT_BITS,	IDTPHY_REGO_TSOC,		\
	  IDTPHY_REGN_TSOC,	IDTPHY_REGX_TSOC },		\
	{ /* 15 */						\
	  UTP_REGT_BITS,	IDTPHY_REGO_TSOC2,		\
	  IDTPHY_REGN_TSOC2,	IDTPHY_REGX_TSOC2 },		\
	  /* 16, 17 unused */					\
	{ /* 18 */						\
	  UTP_REGT_BITS,	IDTPHY_REGO_RLOS,		\
	  IDTPHY_REGN_RLOS,	IDTPHY_REGX_RLOS },		\
	{ /* 19 */						\
	  UTP_REGT_BITS,	IDTPHY_REGO_RLOI,		\
	  IDTPHY_REGN_RLOI,	IDTPHY_REGX_RLOI },		\
	{ /* 1a-1c */						\
	  UTP_REGT_INT20,	IDTPHY_REGO_B2EC,		\
	  IDTPHY_REGN_B2EC,	NULL },				\
	{ /* 1d-1f */						\
	  UTP_REGT_INT20,	IDTPHY_REGO_FEBEC,		\
	  IDTPHY_REGN_FEBEC,	NULL },				\
	{ /* 20 */						\
	  UTP_REGT_BITS,	IDTPHY_REGO_TLOS,		\
	  IDTPHY_REGN_TLOS,	IDTPHY_REGX_TLOS },		\
	{ /* 21 */						\
	  UTP_REGT_BITS,	IDTPHY_REGO_TLOC,		\
	  IDTPHY_REGN_TLOC,	IDTPHY_REGX_TLOC },		\
	  /* 22, 23 unused */					\
	{ /* 24 */						\
	  UTP_REGT_INT8,	IDTPHY_REGO_TK1,		\
	  IDTPHY_REGN_TK1,	NULL },				\
	{ /* 25 */						\
	  UTP_REGT_INT8,	IDTPHY_REGO_TK2,		\
	  IDTPHY_REGN_TK2,	NULL },				\
	{ /* 26 */						\
	  UTP_REGT_INT8,	IDTPHY_REGO_RK1,		\
	  IDTPHY_REGN_RK1,	NULL },				\
	{ /* 27 */						\
	  UTP_REGT_INT8,	IDTPHY_REGO_RK2,		\
	  IDTPHY_REGN_RK2,	NULL },				\
	  /* 28-2f unused */					\
	{ /* 30 */						\
	  UTP_REGT_BITS,	IDTPHY_REGO_RPOS,		\
	  IDTPHY_REGN_RPOS,	IDTPHY_REGX_RPOS },		\
	{ /* 31 */						\
	  UTP_REGT_BITS,	IDTPHY_REGO_RPOI,		\
	  IDTPHY_REGN_RPOI,	IDTPHY_REGX_RPOI },		\
	  /* 32 unused */					\
	{ /* 33 */						\
	  UTP_REGT_BITS,	IDTPHY_REGO_RPIE,		\
	  IDTPHY_REGN_RPIE,	IDTPHY_REGX_RPIE },		\
	  /* 34-36 unused */					\
	{ /* 37 */						\
	  UTP_REGT_INT8,	IDTPHY_REGO_RC2,		\
	  IDTPHY_REGN_RC2,	NULL },				\
	{ /* 38-39 */						\
	  UTP_REGT_INT16,	IDTPHY_REGO_B3EC,		\
	  IDTPHY_REGN_B3EC,	NULL },				\
	{ /* 3a-3b */						\
	  UTP_REGT_INT16,	IDTPHY_REGO_PFEBEC,		\
	  IDTPHY_REGN_PFEBEC,	NULL },				\
	  /* 3c unused */					\
	{ /* 3d */						\
	  UTP_REGT_BITS,	IDTPHY_REGO_RPEC,		\
	  IDTPHY_REGN_RPEC,	IDTPHY_REGX_RPEC },		\
	  /* 3e, 3f unused */					\
	{ /* 40 */						\
	  UTP_REGT_BITS,	IDTPHY_REGO_TPOC,		\
	  IDTPHY_REGN_TPOC,	IDTPHY_REGX_TPOC },		\
	{ /* 41 */						\
	  UTP_REGT_BITS,	IDTPHY_REGO_TPTC,		\
	  IDTPHY_REGN_TPTC,	IDTPHY_REGX_TPTC },		\
	  /* 42-44 unused */					\
	{ /* 45 */						\
	  UTP_REGT_BITS,	IDTPHY_REGO_PTRL,		\
	  IDTPHY_REGN_PTRL,	IDTPHY_REGX_PTRL },		\
	{ /* 46 */						\
	  UTP_REGT_BITS,	IDTPHY_REGO_PTRM,		\
	  IDTPHY_REGN_PTRM,	IDTPHY_REGX_PTRM },		\
	  /* 47 unused */					\
	{ /* 48 */						\
	  UTP_REGT_INT8,	IDTPHY_REGO_TC2,		\
	  IDTPHY_REGN_TC2,	NULL },				\
	{ /* 49 */						\
	  UTP_REGT_BITS,	IDTPHY_REGO_TPOC2,		\
	  IDTPHY_REGN_TPOC2,	IDTPHY_REGX_TPOC2 },		\
	  /* 4a-4f unused */					\
	{ /* 50 */						\
	  UTP_REGT_BITS,	IDTPHY_REGO_RCC,		\
	  IDTPHY_REGN_RCC,	IDTPHY_REGX_RCC },		\
	{ /* 51 */						\
	  UTP_REGT_BITS,	IDTPHY_REGO_RCI,		\
	  IDTPHY_REGN_RCI,	IDTPHY_REGX_RCI },		\
	{ /* 52 */						\
	  UTP_REGT_BITS,	IDTPHY_REGO_CMH,		\
	  IDTPHY_REGN_CMH,	IDTPHY_REGX_CMH },		\
	{ /* 53 */						\
	  UTP_REGT_BITS,	IDTPHY_REGO_CMHM,		\
	  IDTPHY_REGN_CMHM,	IDTPHY_REGX_CMHM },		\
	{ /* 54 */						\
	  UTP_REGT_INT8,	IDTPHY_REGO_CEC,		\
	  IDTPHY_REGN_CEC,	NULL },				\
	{ /* 55 */						\
	  UTP_REGT_INT8,	IDTPHY_REGO_UEC,		\
	  IDTPHY_REGN_UEC,	NULL },				\
	{ /* 56-58 */						\
	  UTP_REGT_INT19,	IDTPHY_REGO_RCCNT,		\
	  IDTPHY_REGN_RCCNT,	NULL },				\
	{ /* 59 */						\
	  UTP_REGT_BITS,	IDTPHY_REGO_RCCF,		\
	  IDTPHY_REGN_RCCF,	IDTPHY_REGX_RCCF },		\
	{ /* 5a */						\
	  UTP_REGT_BITS,	IDTPHY_REGO_RXID,		\
	  IDTPHY_REGN_RXID,	IDTPHY_REGX_RXID },		\
	  /* 5b-5f unused */					\
	{ /* 60 */						\
	  UTP_REGT_BITS,	IDTPHY_REGO_TCC,		\
	  IDTPHY_REGN_TCC,	IDTPHY_REGX_TCC },		\
	{ /* 61 */						\
	  UTP_REGT_BITS,	IDTPHY_REGO_TCHP,		\
	  IDTPHY_REGN_TCHP,	IDTPHY_REGX_TCHP },		\
	{ /* 62 */						\
	  UTP_REGT_INT8,	IDTPHY_REGO_TPLD,		\
	  IDTPHY_REGN_TPLD,	NULL },				\
	{ /* 63 */						\
	  UTP_REGT_BITS,	IDTPHY_REGO_TCC2,		\
	  IDTPHY_REGN_TCC2,	IDTPHY_REGX_TCC2 },		\
	{ /* 64-66 */						\
	  UTP_REGT_INT19,	IDTPHY_REGO_TXCNT,		\
	  IDTPHY_REGN_TXCNT,	NULL },				\
	{ /* 67 */						\
	  UTP_REGT_BITS,	IDTPHY_REGO_TCC3,		\
	  IDTPHY_REGN_TCC3,	IDTPHY_REGX_TCC3 },		\
	{ /* 68 */						\
	  UTP_REGT_BITS,	IDTPHY_REGO_TXID,		\
	  IDTPHY_REGN_TXID,	IDTPHY_REGX_TXID },		\
	  /* 69-6f unused */					\
	{ /* 70 */						\
	  UTP_REGT_BITS,	IDTPHY_REGO_RBER,		\
	  IDTPHY_REGN_RBER,	IDTPHY_REGX_RBER },		\
	{ /* 71 */						\
	  UTP_REGT_INT8,	IDTPHY_REGO_BFTH,		\
	  IDTPHY_REGN_BFTH,	NULL },				\
	{ /* 72 */						\
	  UTP_REGT_INT8,	IDTPHY_REGO_BFWIN,		\
	  IDTPHY_REGN_BFWIN,	NULL },				\
	{ /* 73,74 */						\
	  UTP_REGT_INT16,	IDTPHY_REGO_BFDEN,		\
	  IDTPHY_REGN_BFDEN,	NULL },				\
	{ /* 75 */						\
	  UTP_REGT_INT8,	IDTPHY_REGO_BWTH,		\
	  IDTPHY_REGN_BWTH,	NULL },				\
	{ /* 76 */						\
	  UTP_REGT_INT8,	IDTPHY_REGO_BWWIN,		\
	  IDTPHY_REGN_BWWIN,	NULL },				\
	{ /* 77,78 */						\
	  UTP_REGT_INT16,	IDTPHY_REGO_BWDEN,		\
	  IDTPHY_REGN_BWDEN,	NULL },				\
	  /* 79-7e unused */					\
	{ /* 7f */						\
	  UTP_REGT_BITS,	IDTPHY_REGO_OPEC,		\
	  IDTPHY_REGN_OPEC,	IDTPHY_REGX_OPEC }

#endif	/* _DEV_UTOPIA_IDTPHY_H */