ng_ubt_intel.c (d83185d9) | ng_ubt_intel.c (3544d43b) |
---|---|
1/* 2 * ng_ubt_intel.c 3 */ 4 5/*- 6 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 7 * | 1/* 2 * ng_ubt_intel.c 3 */ 4 5/*- 6 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 7 * |
8 * Copyright (c) 2019, 2021 Vladimir Kondratyev <wulf@FreeBSD.org> | 8 * Copyright (c) 2019 Vladimir Kondratyev <wulf@FreeBSD.org> |
9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the --- 36 unchanged lines hidden (view full) --- 53#include <netgraph/ng_message.h> 54#include <netgraph/netgraph.h> 55#include <netgraph/ng_parse.h> 56#include <netgraph/bluetooth/include/ng_bluetooth.h> 57#include <netgraph/bluetooth/include/ng_hci.h> 58#include <netgraph/bluetooth/include/ng_ubt.h> 59#include <netgraph/bluetooth/drivers/ubt/ng_ubt_var.h> 60 | 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the --- 36 unchanged lines hidden (view full) --- 53#include <netgraph/ng_message.h> 54#include <netgraph/netgraph.h> 55#include <netgraph/ng_parse.h> 56#include <netgraph/bluetooth/include/ng_bluetooth.h> 57#include <netgraph/bluetooth/include/ng_hci.h> 58#include <netgraph/bluetooth/include/ng_ubt.h> 59#include <netgraph/bluetooth/drivers/ubt/ng_ubt_var.h> 60 |
61enum { 62 UBT_INTEL_DEVICE_7260, 63 UBT_INTEL_DEVICE_8260, 64}; 65 66struct ubt_intel_version_rp { 67 uint8_t status; 68 uint8_t hw_platform; 69 uint8_t hw_variant; 70 uint8_t hw_revision; 71 uint8_t fw_variant; 72 uint8_t fw_revision; 73 uint8_t fw_build_num; 74 uint8_t fw_build_ww; 75 uint8_t fw_build_yy; 76 uint8_t fw_patch_num; 77} __attribute__ ((packed)); 78 | |
79static device_probe_t ubt_intel_probe; 80 81/* 82 * List of supported bluetooth devices. If you add a new device PID here ensure 83 * that it is blacklisted in ng_ubt.c and is supported by iwmbtfw utility. 84 */ 85 86static const STRUCT_USB_HOST_ID ubt_intel_devs[] = 87{ | 61static device_probe_t ubt_intel_probe; 62 63/* 64 * List of supported bluetooth devices. If you add a new device PID here ensure 65 * that it is blacklisted in ng_ubt.c and is supported by iwmbtfw utility. 66 */ 67 68static const STRUCT_USB_HOST_ID ubt_intel_devs[] = 69{ |
88 /* Intel Wireless 7260/7265 and successors */ 89 { USB_VPI(USB_VENDOR_INTEL2, 0x07dc, UBT_INTEL_DEVICE_7260) }, 90 { USB_VPI(USB_VENDOR_INTEL2, 0x0a2a, UBT_INTEL_DEVICE_7260) }, 91 { USB_VPI(USB_VENDOR_INTEL2, 0x0aa7, UBT_INTEL_DEVICE_7260) }, | |
92 /* Intel Wireless 8260/8265 and successors */ | 70 /* Intel Wireless 8260/8265 and successors */ |
93 { USB_VPI(USB_VENDOR_INTEL2, 0x0a2b, UBT_INTEL_DEVICE_8260) }, 94 { USB_VPI(USB_VENDOR_INTEL2, 0x0aaa, UBT_INTEL_DEVICE_8260) }, 95 { USB_VPI(USB_VENDOR_INTEL2, 0x0025, UBT_INTEL_DEVICE_8260) }, 96 { USB_VPI(USB_VENDOR_INTEL2, 0x0026, UBT_INTEL_DEVICE_8260) }, 97 { USB_VPI(USB_VENDOR_INTEL2, 0x0029, UBT_INTEL_DEVICE_8260) }, | 71 { USB_VPI(USB_VENDOR_INTEL2, 0x0a2b, 0) }, 72 { USB_VPI(USB_VENDOR_INTEL2, 0x0aaa, 0) }, 73 { USB_VPI(USB_VENDOR_INTEL2, 0x0025, 0) }, 74 { USB_VPI(USB_VENDOR_INTEL2, 0x0026, 0) }, 75 { USB_VPI(USB_VENDOR_INTEL2, 0x0029, 0) }, |
98}; 99 100/* | 76}; 77 78/* |
101 * Execute generic HCI command and return response in provided buffer. | 79 * Find if the Intel Wireless 8260/8265 device is in bootloader mode or is 80 * running operational firmware with checking of 4-th byte "Intel version" 81 * HCI command response. The value 0x23 identifies the operational firmware. |
102 */ 103 | 82 */ 83 |
104static usb_error_t 105ubt_intel_do_hci_request(struct usb_device *udev, uint16_t opcode, 106 void *resp, uint8_t resp_len) | 84static bool 85ubt_intel_check_firmware_state(struct usb_device *udev) |
107{ | 86{ |
87#define UBT_INTEL_VER_LEN 13 |
|
108#define UBT_INTEL_HCICMD_TIMEOUT 2000 /* ms */ 109 struct ubt_hci_event_command_compl *evt; | 88#define UBT_INTEL_HCICMD_TIMEOUT 2000 /* ms */ 89 struct ubt_hci_event_command_compl *evt; |
110 struct ubt_hci_cmd cmd; | 90 uint8_t buf[offsetof(struct ubt_hci_event, data) + UBT_INTEL_VER_LEN]; 91 static struct ubt_hci_cmd cmd = { 92 .opcode = htole16(NG_HCI_OPCODE(NG_HCI_OGF_VENDOR, 0x05)), 93 .length = 0, 94 }; |
111 usb_error_t error; 112 | 95 usb_error_t error; 96 |
113 memset(&cmd, 0, sizeof(cmd)); 114 cmd.opcode = htole16(opcode); 115 evt = malloc(offsetof(struct ubt_hci_event_command_compl, data) + 116 resp_len, M_TEMP, M_ZERO | M_WAITOK); 117 evt->header.length = resp_len + UBT_HCI_EVENT_COMPL_HEAD_SIZE; | 97 bzero(buf, sizeof(buf)); 98 evt = (struct ubt_hci_event_command_compl *)buf; 99 evt->header.length = UBT_INTEL_VER_LEN; |
118 119 error = ubt_do_hci_request(udev, &cmd, evt, UBT_INTEL_HCICMD_TIMEOUT); 120 if (error != USB_ERR_NORMAL_COMPLETION) | 100 101 error = ubt_do_hci_request(udev, &cmd, evt, UBT_INTEL_HCICMD_TIMEOUT); 102 if (error != USB_ERR_NORMAL_COMPLETION) |
121 goto exit; | 103 return false; |
122 | 104 |
123 if (evt->header.event == NG_HCI_EVENT_COMMAND_COMPL && 124 evt->header.length == resp_len + UBT_HCI_EVENT_COMPL_HEAD_SIZE) 125 memcpy(resp, evt->data, resp_len); 126 else 127 error = USB_ERR_INVAL; 128exit: 129 free(evt, M_TEMP); 130 return (error); | 105 return (evt->header.event == NG_HCI_EVENT_COMMAND_COMPL && 106 evt->header.length == UBT_INTEL_VER_LEN && 107 evt->data[4] == 0x23); |
131} 132 133/* 134 * Probe for a Intel Wireless Bluetooth device. 135 */ 136 137static int 138ubt_intel_probe(device_t dev) 139{ 140 struct usb_attach_arg *uaa = device_get_ivars(dev); | 108} 109 110/* 111 * Probe for a Intel Wireless Bluetooth device. 112 */ 113 114static int 115ubt_intel_probe(device_t dev) 116{ 117 struct usb_attach_arg *uaa = device_get_ivars(dev); |
141 struct ubt_intel_version_rp version; 142 ng_hci_reset_rp reset; | |
143 int error; 144 145 if (uaa->usb_mode != USB_MODE_HOST) 146 return (ENXIO); 147 148 if (uaa->info.bIfaceIndex != 0) 149 return (ENXIO); 150 151 error = usbd_lookup_id_by_uaa(ubt_intel_devs, sizeof(ubt_intel_devs), 152 uaa); 153 if (error != 0) 154 return (error); 155 | 118 int error; 119 120 if (uaa->usb_mode != USB_MODE_HOST) 121 return (ENXIO); 122 123 if (uaa->info.bIfaceIndex != 0) 124 return (ENXIO); 125 126 error = usbd_lookup_id_by_uaa(ubt_intel_devs, sizeof(ubt_intel_devs), 127 uaa); 128 if (error != 0) 129 return (error); 130 |
156 switch (USB_GET_DRIVER_INFO(uaa)) { 157 case UBT_INTEL_DEVICE_7260: 158 /* 159 * Send HCI Reset command to workaround controller bug with the 160 * first HCI command sent to it returning number of completed 161 * commands as zero. This will reset the number of completed 162 * commands and allow further normal command processing. 163 */ 164 if (ubt_intel_do_hci_request(uaa->device, 165 NG_HCI_OPCODE(NG_HCI_OGF_HC_BASEBAND, NG_HCI_OCF_RESET), 166 &reset, sizeof(reset)) != USB_ERR_NORMAL_COMPLETION) 167 return (ENXIO); 168 if (reset.status != 0) 169 return (ENXIO); 170 /* 171 * fw_patch_num indicates the version of patch the device 172 * currently have. If there is no patch data in the device, 173 * it is always 0x00 and we need to patch the device again. 174 */ 175 if (ubt_intel_do_hci_request(uaa->device, 176 NG_HCI_OPCODE(NG_HCI_OGF_VENDOR, 0x05), 177 &version, sizeof(version)) != USB_ERR_NORMAL_COMPLETION) 178 return (ENXIO); 179 if (version.fw_patch_num == 0) 180 return (ENXIO); 181 break; | 131 if (!ubt_intel_check_firmware_state(uaa->device)) 132 return (ENXIO); |
182 | 133 |
183 case UBT_INTEL_DEVICE_8260: 184 /* 185 * Find if the Intel Wireless 8260/8265 device is in bootloader 186 * mode or is running operational firmware with checking of 187 * variant byte of "Intel version" HCI command response. 188 * The value 0x23 identifies the operational firmware. 189 */ 190 if (ubt_intel_do_hci_request(uaa->device, 191 NG_HCI_OPCODE(NG_HCI_OGF_VENDOR, 0x05), 192 &version, sizeof(version)) != USB_ERR_NORMAL_COMPLETION) 193 return (ENXIO); 194 if (version.fw_variant != 0x23) 195 return (ENXIO); 196 break; 197 198 default: 199 KASSERT(0 == 1, ("Unknown DRIVER_INFO")); 200 } 201 | |
202 return (BUS_PROBE_DEFAULT); 203} 204 205/* 206 * Module interface. Attach and detach methods, netgraph node type 207 * registration and PNP string are inherited from ng_ubt.c driver. 208 */ 209 210static device_method_t ubt_intel_methods[] = 211{ 212 DEVMETHOD(device_probe, ubt_intel_probe), 213 DEVMETHOD_END 214}; 215 | 134 return (BUS_PROBE_DEFAULT); 135} 136 137/* 138 * Module interface. Attach and detach methods, netgraph node type 139 * registration and PNP string are inherited from ng_ubt.c driver. 140 */ 141 142static device_method_t ubt_intel_methods[] = 143{ 144 DEVMETHOD(device_probe, ubt_intel_probe), 145 DEVMETHOD_END 146}; 147 |
216DEFINE_CLASS_1(ubt, ubt_intel_driver, ubt_intel_methods, 217 sizeof(struct ubt_softc), ubt_driver); 218DRIVER_MODULE(ng_ubt_intel, uhub, ubt_intel_driver, 0, 0); | 148static kobj_class_t ubt_baseclasses[] = { &ubt_driver, NULL }; 149static driver_t ubt_intel_driver = 150{ 151 .name = "ubt", 152 .methods = ubt_intel_methods, 153 .size = sizeof(struct ubt_softc), 154 .baseclasses = ubt_baseclasses, 155}; 156 157DRIVER_MODULE(ng_ubt_intel, uhub, ubt_intel_driver, ubt_devclass, 0, 0); |
219MODULE_VERSION(ng_ubt_intel, NG_BLUETOOTH_VERSION); 220MODULE_DEPEND(ng_ubt_intel, netgraph, NG_ABI_VERSION, NG_ABI_VERSION, NG_ABI_VERSION); 221MODULE_DEPEND(ng_ubt_intel, ng_hci, NG_BLUETOOTH_VERSION, NG_BLUETOOTH_VERSION, NG_BLUETOOTH_VERSION); 222MODULE_DEPEND(ng_ubt_intel, usb, 1, 1, 1); | 158MODULE_VERSION(ng_ubt_intel, NG_BLUETOOTH_VERSION); 159MODULE_DEPEND(ng_ubt_intel, netgraph, NG_ABI_VERSION, NG_ABI_VERSION, NG_ABI_VERSION); 160MODULE_DEPEND(ng_ubt_intel, ng_hci, NG_BLUETOOTH_VERSION, NG_BLUETOOTH_VERSION, NG_BLUETOOTH_VERSION); 161MODULE_DEPEND(ng_ubt_intel, usb, 1, 1, 1); |