xref: /openbsd-src/sys/dev/usb/if_wi_usb.h (revision 7ebc5b51da5611c78123bf2a163bb4cee0fee6d5)
1*7ebc5b51Smpi /*	$OpenBSD: if_wi_usb.h,v 1.3 2015/06/12 15:47:31 mpi Exp $ */
237837c73Sdrahn 
337837c73Sdrahn /*
437837c73Sdrahn  * Copyright (c) 2003 Dale Rahn. All rights reserved.
537837c73Sdrahn  *
637837c73Sdrahn  * Redistribution and use in source and binary forms, with or without
737837c73Sdrahn  * modification, are permitted provided that the following conditions
837837c73Sdrahn  * are met:
937837c73Sdrahn  * 1. Redistributions of source code must retain the above copyright
1037837c73Sdrahn  *    notice, this list of conditions and the following disclaimer.
1137837c73Sdrahn  * 2. Redistributions in binary form must reproduce the above copyright
1237837c73Sdrahn  *    notice, this list of conditions and the following disclaimer in the
1337837c73Sdrahn  *    documentation and/or other materials provided with the distribution.
1437837c73Sdrahn  *
1537837c73Sdrahn  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1637837c73Sdrahn  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1737837c73Sdrahn  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1837837c73Sdrahn  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
1937837c73Sdrahn  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2037837c73Sdrahn  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2137837c73Sdrahn  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2237837c73Sdrahn  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2337837c73Sdrahn  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2437837c73Sdrahn  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2537837c73Sdrahn  *
2637837c73Sdrahn  * Effort sponsored in part by the Defense Advanced Research Projects
2737837c73Sdrahn  * Agency (DARPA) and Air Force Research Laboratory, Air Force
2837837c73Sdrahn  * Materiel Command, USAF, under agreement number F30602-01-2-0537.
2937837c73Sdrahn  */
3037837c73Sdrahn 
3137837c73Sdrahn #define WI_USB_ENDPT_TX		1
3237837c73Sdrahn #define WI_USB_ENDPT_RX		2
3337837c73Sdrahn #define WI_USB_ENDPT_INTR	3
3437837c73Sdrahn #define WI_USB_ENDPT_MAX	4
3537837c73Sdrahn 
3637837c73Sdrahn 
3737837c73Sdrahn /* XXX */
3837837c73Sdrahn #define WI_USB_DATA_MAXLEN	WI_DEFAULT_DATALEN
3937837c73Sdrahn #define WI_USB_BUFSZ		2368	/* MAX PACKET LEN ???  n%64 == 0 */
4037837c73Sdrahn #define WI_USB_INTR_INTERVAL	100	/* ms */
4137837c73Sdrahn 
4237837c73Sdrahn struct wi_usb_softc;
4337837c73Sdrahn 
4437837c73Sdrahn struct wi_usb_chain {
4537837c73Sdrahn 	struct wi_usb_softc	*wi_usb_sc;
4637837c73Sdrahn 	struct usbd_xfer	*wi_usb_xfer;
4737837c73Sdrahn 	void			*wi_usb_buf;
4837837c73Sdrahn 	struct mbuf		*wi_usb_mbuf;
4937837c73Sdrahn 	int			wi_usb_idx;
5037837c73Sdrahn };
5137837c73Sdrahn #define WI_USB_TX_LIST_CNT	1
5237837c73Sdrahn #define WI_USB_RX_LIST_CNT	1
5337837c73Sdrahn 
5437837c73Sdrahn struct wi_rridreq {
5537837c73Sdrahn 	u_int16_t		type;		/* 0x00 */
5637837c73Sdrahn 	u_int16_t		frmlen;		/* 0x02 */
5737837c73Sdrahn 	u_int16_t		rid;		/* 0x04 */
5837837c73Sdrahn 	u_int8_t		pad[58]; 	/* 0x06	+ sizeof(.) == 64 */
5937837c73Sdrahn };
6037837c73Sdrahn struct wi_rridresp {
6137837c73Sdrahn 	u_int16_t		type;		/* 0x00 */
6237837c73Sdrahn 	u_int16_t		frmlen;		/* 0x02 */
6337837c73Sdrahn 	u_int16_t		rid;		/* 0x04 */
6437837c73Sdrahn 	u_int8_t		data[1658];	/* 0x06 */
6537837c73Sdrahn 	/* sizeof(struct wi_rridresp) == WI_USB_BUFSZ */
6637837c73Sdrahn };
6737837c73Sdrahn struct wi_wridreq {
6837837c73Sdrahn 	u_int16_t		type;		/* 0x00 */
6937837c73Sdrahn 	u_int16_t		frmlen;		/* 0x02 */
7037837c73Sdrahn 	u_int16_t		rid;		/* 0x04 */
7137837c73Sdrahn 	u_int8_t		data[2048];	/* 0x06 */
7237837c73Sdrahn };
7337837c73Sdrahn struct wi_wridresp {
7437837c73Sdrahn 	u_int16_t		type;
7537837c73Sdrahn 	u_int16_t		status;
7637837c73Sdrahn 	u_int16_t		resp0;
7737837c73Sdrahn 	u_int16_t		resp1;
7837837c73Sdrahn 	u_int16_t		resp2;
7937837c73Sdrahn };
8037837c73Sdrahn struct wi_info {
8137837c73Sdrahn 	u_int16_t		type;
8237837c73Sdrahn 	u_int16_t		info;
8337837c73Sdrahn };
8437837c73Sdrahn 
8537837c73Sdrahn 
8637837c73Sdrahn #define WI_USB_CMD_INIT		0x0
8737837c73Sdrahn #define WI_USB_CMD_ENABLE	0x1
8837837c73Sdrahn #define WI_USB_CMD_DISABLE	0x2
8937837c73Sdrahn #define WI_USB_CMD_DIAG		0x3
9037837c73Sdrahn 
9137837c73Sdrahn struct wi_cmdreq {
9237837c73Sdrahn 	u_int16_t		type;
9337837c73Sdrahn 	u_int16_t		cmd;
9437837c73Sdrahn 	u_int16_t		param0;
9537837c73Sdrahn 	u_int16_t		param1;
9637837c73Sdrahn 	u_int16_t		param2;
9737837c73Sdrahn 	u_int8_t		pad[54];
9837837c73Sdrahn };
9937837c73Sdrahn struct wi_cmdresp {
10037837c73Sdrahn 	u_int16_t		type;
10137837c73Sdrahn 	u_int16_t		status;
10237837c73Sdrahn 	u_int16_t		resp0;
10337837c73Sdrahn 	u_int16_t		resp1;
10437837c73Sdrahn 	u_int16_t		resp2;
10537837c73Sdrahn };
10637837c73Sdrahn 
10737837c73Sdrahn typedef union {
10837837c73Sdrahn 	u_int16_t		type;
10937837c73Sdrahn 	struct wi_rridreq	rridreq;
11037837c73Sdrahn 	struct wi_rridresp	rridresp;
11137837c73Sdrahn 	struct wi_cmdreq	cmdreq;
11237837c73Sdrahn 	struct wi_cmdresp	cmdresp;
11337837c73Sdrahn } wi_usb_usbin;
11437837c73Sdrahn #define WI_USB_INTR_PKTLEN	8
11537837c73Sdrahn 
11637837c73Sdrahn #define WI_USB_TX_TIMEOUT	10000 /* ms */
11737837c73Sdrahn 
11837837c73Sdrahn 
11937837c73Sdrahn /* Should be sent to the bulkout endpoint */
12037837c73Sdrahn #define WI_USB_TXFRM		0
12137837c73Sdrahn #define WI_USB_CMDREQ		1
12237837c73Sdrahn #define WI_USB_WRIDREQ		2
12337837c73Sdrahn #define WI_USB_RRIDREQ		3
12437837c73Sdrahn #define WI_USB_WMEMREQ		4
12537837c73Sdrahn #define WI_USB_RMEMREQ		5
12637837c73Sdrahn 
12737837c73Sdrahn /* Received from the bulkin endpoint */
12837837c73Sdrahn #define WI_USB_ISTXFRM(a)	(((a) & 0xf000) == 0x0000)
12937837c73Sdrahn #define WI_USB_ISRXFRM(a)	(((a) & 0xf000) == 0x2000)
13037837c73Sdrahn 
13137837c73Sdrahn #define WI_USB_INFOFRM		0x8000
13237837c73Sdrahn #define WI_USB_CMDRESP		0x8001
13337837c73Sdrahn #define WI_USB_WRIDRESP		0x8002
13437837c73Sdrahn #define WI_USB_RRIDRESP		0x8003
13537837c73Sdrahn #define WI_USB_WMEMRESP		0x8004
13637837c73Sdrahn #define WI_USB_RMEMRESP		0x8005
13737837c73Sdrahn #define WI_USB_BUFAVAIL		0x8006
13837837c73Sdrahn #define WI_USB_ERROR		0x8007
13937837c73Sdrahn 
14055f29f42Sjsg #define WI_GET_IFP(sc)		&(sc)->sc_wi.sc_ic.ic_if
14137837c73Sdrahn 
14237837c73Sdrahn /* USB */
14337837c73Sdrahn int wi_cmd_usb(struct wi_softc *sc, int cmd, int val0, int val1, int val2);
14437837c73Sdrahn int wi_read_record_usb(struct wi_softc *sc, struct wi_ltv_gen *ltv);
14537837c73Sdrahn int wi_write_record_usb(struct wi_softc *sc, struct wi_ltv_gen *ltv);
14637837c73Sdrahn int wi_read_data_usb(struct wi_softc *sc, int id, int off, caddr_t buf,
14737837c73Sdrahn     int len);
14837837c73Sdrahn int wi_write_data_usb(struct wi_softc *sc, int id, int off, caddr_t buf,
14937837c73Sdrahn     int len);
15037837c73Sdrahn int wi_alloc_nicmem_usb(struct wi_softc *sc, int len, int *id);
15137837c73Sdrahn int wi_get_fid_usb(struct wi_softc *sc, int fid);
15237837c73Sdrahn void wi_init_usb(struct wi_softc *sc);
15337837c73Sdrahn 
15437837c73Sdrahn void wi_start_usb(struct ifnet *ifp);
15537837c73Sdrahn int wi_ioctl_usb(struct ifnet *, u_long, caddr_t);
15637837c73Sdrahn void wi_inquire_usb(void *xsc);
15737837c73Sdrahn void wi_watchdog_usb(struct ifnet *ifp);
158