1 /* $OpenBSD: if_wi_usb.h,v 1.3 2015/06/12 15:47:31 mpi Exp $ */ 2 3 /* 4 * Copyright (c) 2003 Dale Rahn. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * 26 * Effort sponsored in part by the Defense Advanced Research Projects 27 * Agency (DARPA) and Air Force Research Laboratory, Air Force 28 * Materiel Command, USAF, under agreement number F30602-01-2-0537. 29 */ 30 31 #define WI_USB_ENDPT_TX 1 32 #define WI_USB_ENDPT_RX 2 33 #define WI_USB_ENDPT_INTR 3 34 #define WI_USB_ENDPT_MAX 4 35 36 37 /* XXX */ 38 #define WI_USB_DATA_MAXLEN WI_DEFAULT_DATALEN 39 #define WI_USB_BUFSZ 2368 /* MAX PACKET LEN ??? n%64 == 0 */ 40 #define WI_USB_INTR_INTERVAL 100 /* ms */ 41 42 struct wi_usb_softc; 43 44 struct wi_usb_chain { 45 struct wi_usb_softc *wi_usb_sc; 46 struct usbd_xfer *wi_usb_xfer; 47 void *wi_usb_buf; 48 struct mbuf *wi_usb_mbuf; 49 int wi_usb_idx; 50 }; 51 #define WI_USB_TX_LIST_CNT 1 52 #define WI_USB_RX_LIST_CNT 1 53 54 struct wi_rridreq { 55 u_int16_t type; /* 0x00 */ 56 u_int16_t frmlen; /* 0x02 */ 57 u_int16_t rid; /* 0x04 */ 58 u_int8_t pad[58]; /* 0x06 + sizeof(.) == 64 */ 59 }; 60 struct wi_rridresp { 61 u_int16_t type; /* 0x00 */ 62 u_int16_t frmlen; /* 0x02 */ 63 u_int16_t rid; /* 0x04 */ 64 u_int8_t data[1658]; /* 0x06 */ 65 /* sizeof(struct wi_rridresp) == WI_USB_BUFSZ */ 66 }; 67 struct wi_wridreq { 68 u_int16_t type; /* 0x00 */ 69 u_int16_t frmlen; /* 0x02 */ 70 u_int16_t rid; /* 0x04 */ 71 u_int8_t data[2048]; /* 0x06 */ 72 }; 73 struct wi_wridresp { 74 u_int16_t type; 75 u_int16_t status; 76 u_int16_t resp0; 77 u_int16_t resp1; 78 u_int16_t resp2; 79 }; 80 struct wi_info { 81 u_int16_t type; 82 u_int16_t info; 83 }; 84 85 86 #define WI_USB_CMD_INIT 0x0 87 #define WI_USB_CMD_ENABLE 0x1 88 #define WI_USB_CMD_DISABLE 0x2 89 #define WI_USB_CMD_DIAG 0x3 90 91 struct wi_cmdreq { 92 u_int16_t type; 93 u_int16_t cmd; 94 u_int16_t param0; 95 u_int16_t param1; 96 u_int16_t param2; 97 u_int8_t pad[54]; 98 }; 99 struct wi_cmdresp { 100 u_int16_t type; 101 u_int16_t status; 102 u_int16_t resp0; 103 u_int16_t resp1; 104 u_int16_t resp2; 105 }; 106 107 typedef union { 108 u_int16_t type; 109 struct wi_rridreq rridreq; 110 struct wi_rridresp rridresp; 111 struct wi_cmdreq cmdreq; 112 struct wi_cmdresp cmdresp; 113 } wi_usb_usbin; 114 #define WI_USB_INTR_PKTLEN 8 115 116 #define WI_USB_TX_TIMEOUT 10000 /* ms */ 117 118 119 /* Should be sent to the bulkout endpoint */ 120 #define WI_USB_TXFRM 0 121 #define WI_USB_CMDREQ 1 122 #define WI_USB_WRIDREQ 2 123 #define WI_USB_RRIDREQ 3 124 #define WI_USB_WMEMREQ 4 125 #define WI_USB_RMEMREQ 5 126 127 /* Received from the bulkin endpoint */ 128 #define WI_USB_ISTXFRM(a) (((a) & 0xf000) == 0x0000) 129 #define WI_USB_ISRXFRM(a) (((a) & 0xf000) == 0x2000) 130 131 #define WI_USB_INFOFRM 0x8000 132 #define WI_USB_CMDRESP 0x8001 133 #define WI_USB_WRIDRESP 0x8002 134 #define WI_USB_RRIDRESP 0x8003 135 #define WI_USB_WMEMRESP 0x8004 136 #define WI_USB_RMEMRESP 0x8005 137 #define WI_USB_BUFAVAIL 0x8006 138 #define WI_USB_ERROR 0x8007 139 140 #define WI_GET_IFP(sc) &(sc)->sc_wi.sc_ic.ic_if 141 142 /* USB */ 143 int wi_cmd_usb(struct wi_softc *sc, int cmd, int val0, int val1, int val2); 144 int wi_read_record_usb(struct wi_softc *sc, struct wi_ltv_gen *ltv); 145 int wi_write_record_usb(struct wi_softc *sc, struct wi_ltv_gen *ltv); 146 int wi_read_data_usb(struct wi_softc *sc, int id, int off, caddr_t buf, 147 int len); 148 int wi_write_data_usb(struct wi_softc *sc, int id, int off, caddr_t buf, 149 int len); 150 int wi_alloc_nicmem_usb(struct wi_softc *sc, int len, int *id); 151 int wi_get_fid_usb(struct wi_softc *sc, int fid); 152 void wi_init_usb(struct wi_softc *sc); 153 154 void wi_start_usb(struct ifnet *ifp); 155 int wi_ioctl_usb(struct ifnet *, u_long, caddr_t); 156 void wi_inquire_usb(void *xsc); 157 void wi_watchdog_usb(struct ifnet *ifp); 158