1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2019 Vladimir Kondratyev <wulf@FreeBSD.org>
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 AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  */
27 #ifndef	__IWMBT_HW_H__
28 #define	__IWMBT_HW_H__
29 
30 /* USB control request (HCI command) structure */
31 struct iwmbt_hci_cmd {
32 	uint16_t	opcode;
33 	uint8_t		length;
34 	uint8_t		data[];
35 } __attribute__ ((packed));
36 
37 #define IWMBT_HCI_CMD_SIZE(cmd) \
38 	((cmd)->length + offsetof(struct iwmbt_hci_cmd, data))
39 
40 /* USB interrupt transfer HCI event header structure */
41 struct iwmbt_hci_evhdr {
42 	uint8_t		event;
43 	uint8_t		length;
44 } __attribute__ ((packed));
45 
46 /* USB interrupt transfer (generic HCI event) structure */
47 struct iwmbt_hci_event {
48 	struct iwmbt_hci_evhdr	header;
49 	uint8_t			data[];
50 } __attribute__ ((packed));
51 
52 /* USB interrupt transfer (HCI command completion event) structure */
53 struct iwmbt_hci_event_cmd_compl {
54 	struct iwmbt_hci_evhdr	header;
55 	uint8_t			numpkt;
56 	uint16_t		opcode;
57 	uint8_t			data[];
58 } __attribute__ ((packed));
59 
60 #define IWMBT_HCI_EVT_COMPL_SIZE(payload) \
61 	(offsetof(struct iwmbt_hci_event_cmd_compl, data) + sizeof(payload))
62 
63 #define	IWMBT_CONTROL_ENDPOINT_ADDR	0x00
64 #define	IWMBT_INTERRUPT_ENDPOINT_ADDR	0x81
65 #define	IWMBT_BULK_IN_ENDPOINT_ADDR	0x82
66 #define	IWMBT_BULK_OUT_ENDPOINT_ADDR	0x02
67 
68 #define	IWMBT_HCI_MAX_CMD_SIZE		256
69 #define	IWMBT_HCI_MAX_EVENT_SIZE	16
70 
71 #define	IWMBT_HCI_CMD_TIMEOUT		2000	/* ms */
72 #define	IWMBT_LOADCMPL_TIMEOUT		5000	/* ms */
73 
74 extern	int iwmbt_patch_fwfile(struct libusb_device_handle *hdl,
75 	    const struct iwmbt_firmware *fw);
76 extern	int iwmbt_load_fwfile(struct libusb_device_handle *hdl,
77 	    const struct iwmbt_firmware *fw, uint32_t *boot_param);
78 extern	int iwmbt_enter_manufacturer(struct libusb_device_handle *hdl);
79 extern	int iwmbt_exit_manufacturer(struct libusb_device_handle *hdl,
80 	    int mode);
81 extern	int iwmbt_get_version(struct libusb_device_handle *hdl,
82 	    struct iwmbt_version *version);
83 extern	int iwmbt_get_boot_params(struct libusb_device_handle *hdl,
84 	    struct iwmbt_boot_params *params);
85 extern	int iwmbt_intel_reset(struct libusb_device_handle *hdl,
86 	    uint32_t boot_param);
87 extern	int iwmbt_load_ddc(struct libusb_device_handle *hdl,
88 	    const struct iwmbt_firmware *ddc);
89 extern	int iwmbt_set_event_mask(struct libusb_device_handle *hdl);
90 
91 #endif
92