Changeset View
Changeset View
Standalone View
Standalone View
sys/netgraph/bluetooth/drivers/ubt/ng_ubt_intel.c
/* | /* | ||||
* ng_ubt_intel.c | * ng_ubt_intel.c | ||||
*/ | */ | ||||
/*- | /*- | ||||
* SPDX-License-Identifier: BSD-2-Clause | * SPDX-License-Identifier: BSD-2-Clause | ||||
* | * | ||||
* Copyright (c) 2019, 2021 Vladimir Kondratyev <wulf@FreeBSD.org> | * Copyright (c) 2019, 2021 Vladimir Kondratyev <wulf@FreeBSD.org> | ||||
* Copyright (c) 2023 Future Crew LLC. | |||||
* | * | ||||
* Redistribution and use in source and binary forms, with or without | * Redistribution and use in source and binary forms, with or without | ||||
* modification, are permitted provided that the following conditions | * modification, are permitted provided that the following conditions | ||||
* are met: | * are met: | ||||
* 1. Redistributions of source code must retain the above copyright | * 1. Redistributions of source code must retain the above copyright | ||||
* notice, this list of conditions and the following disclaimer. | * notice, this list of conditions and the following disclaimer. | ||||
* 2. Redistributions in binary form must reproduce the above copyright | * 2. Redistributions in binary form must reproduce the above copyright | ||||
* notice, this list of conditions and the following disclaimer in the | * notice, this list of conditions and the following disclaimer in the | ||||
Show All 34 Lines | |||||
#include <netgraph/ng_message.h> | #include <netgraph/ng_message.h> | ||||
#include <netgraph/netgraph.h> | #include <netgraph/netgraph.h> | ||||
#include <netgraph/ng_parse.h> | #include <netgraph/ng_parse.h> | ||||
#include <netgraph/bluetooth/include/ng_bluetooth.h> | #include <netgraph/bluetooth/include/ng_bluetooth.h> | ||||
#include <netgraph/bluetooth/include/ng_hci.h> | #include <netgraph/bluetooth/include/ng_hci.h> | ||||
#include <netgraph/bluetooth/include/ng_ubt.h> | #include <netgraph/bluetooth/include/ng_ubt.h> | ||||
#include <netgraph/bluetooth/drivers/ubt/ng_ubt_var.h> | #include <netgraph/bluetooth/drivers/ubt/ng_ubt_var.h> | ||||
#define UBT_INTEL_HCICMD_TIMEOUT 2000 /* ms */ | |||||
#define UBT_INTEL_TLV_IMAGE_TYPE 0x1c | |||||
enum { | enum { | ||||
UBT_INTEL_DEVICE_7260, | UBT_INTEL_DEVICE_7260, | ||||
UBT_INTEL_DEVICE_8260, | UBT_INTEL_DEVICE_8260, | ||||
UBT_INTEL_DEVICE_9260, | |||||
}; | }; | ||||
struct ubt_intel_version_rp { | struct ubt_intel_version_rp { | ||||
uint8_t status; | uint8_t status; | ||||
uint8_t hw_platform; | uint8_t hw_platform; | ||||
uint8_t hw_variant; | uint8_t hw_variant; | ||||
uint8_t hw_revision; | uint8_t hw_revision; | ||||
uint8_t fw_variant; | uint8_t fw_variant; | ||||
Show All 18 Lines | static const STRUCT_USB_HOST_ID ubt_intel_devs[] = | ||||
{ USB_VPI(USB_VENDOR_INTEL2, 0x0a2a, UBT_INTEL_DEVICE_7260) }, | { USB_VPI(USB_VENDOR_INTEL2, 0x0a2a, UBT_INTEL_DEVICE_7260) }, | ||||
{ USB_VPI(USB_VENDOR_INTEL2, 0x0aa7, UBT_INTEL_DEVICE_7260) }, | { USB_VPI(USB_VENDOR_INTEL2, 0x0aa7, UBT_INTEL_DEVICE_7260) }, | ||||
/* Intel Wireless 8260/8265 and successors */ | /* Intel Wireless 8260/8265 and successors */ | ||||
{ USB_VPI(USB_VENDOR_INTEL2, 0x0a2b, UBT_INTEL_DEVICE_8260) }, | { USB_VPI(USB_VENDOR_INTEL2, 0x0a2b, UBT_INTEL_DEVICE_8260) }, | ||||
{ USB_VPI(USB_VENDOR_INTEL2, 0x0aaa, UBT_INTEL_DEVICE_8260) }, | { USB_VPI(USB_VENDOR_INTEL2, 0x0aaa, UBT_INTEL_DEVICE_8260) }, | ||||
{ USB_VPI(USB_VENDOR_INTEL2, 0x0025, UBT_INTEL_DEVICE_8260) }, | { USB_VPI(USB_VENDOR_INTEL2, 0x0025, UBT_INTEL_DEVICE_8260) }, | ||||
{ USB_VPI(USB_VENDOR_INTEL2, 0x0026, UBT_INTEL_DEVICE_8260) }, | { USB_VPI(USB_VENDOR_INTEL2, 0x0026, UBT_INTEL_DEVICE_8260) }, | ||||
{ USB_VPI(USB_VENDOR_INTEL2, 0x0029, UBT_INTEL_DEVICE_8260) }, | { USB_VPI(USB_VENDOR_INTEL2, 0x0029, UBT_INTEL_DEVICE_8260) }, | ||||
/* Intel Wireless 9260/9560 and successors */ | |||||
{ USB_VPI(USB_VENDOR_INTEL2, 0x0032, UBT_INTEL_DEVICE_9260) }, | |||||
{ USB_VPI(USB_VENDOR_INTEL2, 0x0033, UBT_INTEL_DEVICE_9260) }, | |||||
}; | }; | ||||
/* | /* | ||||
* Execute generic HCI command and return response in provided buffer. | * Execute generic HCI command and return response in provided buffer. | ||||
*/ | */ | ||||
static usb_error_t | static usb_error_t | ||||
ubt_intel_do_hci_request(struct usb_device *udev, uint16_t opcode, | ubt_intel_do_hci_request(struct usb_device *udev, uint16_t opcode, | ||||
void *resp, uint8_t resp_len) | void *resp, uint8_t resp_len) | ||||
{ | { | ||||
#define UBT_INTEL_HCICMD_TIMEOUT 2000 /* ms */ | |||||
struct ubt_hci_event_command_compl *evt; | struct ubt_hci_event_command_compl *evt; | ||||
struct ubt_hci_cmd cmd; | struct ubt_hci_cmd cmd; | ||||
usb_error_t error; | usb_error_t error; | ||||
memset(&cmd, 0, sizeof(cmd)); | memset(&cmd, 0, sizeof(cmd)); | ||||
cmd.opcode = htole16(opcode); | cmd.opcode = htole16(opcode); | ||||
evt = malloc(offsetof(struct ubt_hci_event_command_compl, data) + | evt = malloc(offsetof(struct ubt_hci_event_command_compl, data) + | ||||
resp_len, M_TEMP, M_ZERO | M_WAITOK); | resp_len, M_TEMP, M_ZERO | M_WAITOK); | ||||
evt->header.length = resp_len + UBT_HCI_EVENT_COMPL_HEAD_SIZE; | evt->header.length = resp_len + UBT_HCI_EVENT_COMPL_HEAD_SIZE; | ||||
error = ubt_do_hci_request(udev, &cmd, evt, UBT_INTEL_HCICMD_TIMEOUT); | error = ubt_do_hci_request(udev, &cmd, evt, UBT_INTEL_HCICMD_TIMEOUT); | ||||
if (error != USB_ERR_NORMAL_COMPLETION) | if (error != USB_ERR_NORMAL_COMPLETION) | ||||
goto exit; | goto exit; | ||||
if (evt->header.event == NG_HCI_EVENT_COMMAND_COMPL && | if (evt->header.event == NG_HCI_EVENT_COMMAND_COMPL && | ||||
evt->header.length == resp_len + UBT_HCI_EVENT_COMPL_HEAD_SIZE) | evt->header.length == resp_len + UBT_HCI_EVENT_COMPL_HEAD_SIZE) | ||||
memcpy(resp, evt->data, resp_len); | memcpy(resp, evt->data, resp_len); | ||||
else | else | ||||
error = USB_ERR_INVAL; | error = USB_ERR_INVAL; | ||||
exit: | exit: | ||||
free(evt, M_TEMP); | free(evt, M_TEMP); | ||||
return (error); | return (error); | ||||
} | } | ||||
static uint8_t | |||||
ubt_intel_get_img_type(struct usb_device *udev) | |||||
{ | |||||
#define UBT_INTEL_MAX_EVT_SIZE 256 | |||||
static struct ubt_hci_cmd cmd = { | |||||
.opcode = htole16(NG_HCI_OPCODE(NG_HCI_OGF_VENDOR, 0x05)), | |||||
bz: This is the same command as for 7260/8260 to get the version, just with different len/data? | |||||
Done Inline ActionsYes, they did. 7260/8260 returns structure of fixed size, while 9260 returns list of key->value pairs. wulf: Yes, they did. 7260/8260 returns structure of fixed size, while 9260 returns list of key->value… | |||||
.length = 1, | |||||
.data = { 0xff }, | |||||
}; | |||||
struct ubt_hci_event_command_compl *evt; | |||||
usb_error_t error; | |||||
uint8_t status, datalen, type, len, img_type = 0; | |||||
uint8_t *data; | |||||
evt = malloc(UBT_INTEL_MAX_EVT_SIZE, M_TEMP, M_ZERO | M_WAITOK); | |||||
evt->header.length = | |||||
UBT_INTEL_MAX_EVT_SIZE - sizeof(struct ubt_hci_evhdr); | |||||
error = ubt_do_hci_request(udev, &cmd, evt, UBT_INTEL_HCICMD_TIMEOUT); | |||||
if (error != USB_ERR_NORMAL_COMPLETION) | |||||
goto exit; | |||||
Done Inline ActionsIs there any need to check evt->header.event == NG_HCI_EVENT_COMMAND_COMPL here too (as we do for 7260/8260)? bz: Is there any need to check evt->header.event == NG_HCI_EVENT_COMMAND_COMPL here too (as we do… | |||||
Done Inline ActionsThat handled in D46736 wulf: That handled in D46736 | |||||
datalen = evt->header.length - UBT_HCI_EVENT_COMPL_HEAD_SIZE; | |||||
data = evt->data; | |||||
status = *data++; | |||||
if (status != 0) | |||||
goto exit; | |||||
datalen--; | |||||
while (datalen >= 2) { | |||||
type = *data++; | |||||
len = *data++; | |||||
datalen -= 2; | |||||
if (datalen < len) | |||||
break; | |||||
if (type == UBT_INTEL_TLV_IMAGE_TYPE && len == 1) { | |||||
Not Done Inline Actionsany reference (or potential #define) for these magic numbers? (0x1c, 0x03)? emaste: any reference (or potential `#define`) for these magic numbers? (0x1c, 0x03)? | |||||
img_type = *data; | |||||
break; | |||||
} | |||||
datalen -= len; | |||||
data += len; | |||||
} | |||||
exit: | |||||
free(evt, M_TEMP); | |||||
return (img_type); | |||||
} | |||||
/* | /* | ||||
* Probe for a Intel Wireless Bluetooth device. | * Probe for a Intel Wireless Bluetooth device. | ||||
*/ | */ | ||||
static int | static int | ||||
ubt_intel_probe(device_t dev) | ubt_intel_probe(device_t dev) | ||||
{ | { | ||||
struct usb_attach_arg *uaa = device_get_ivars(dev); | struct usb_attach_arg *uaa = device_get_ivars(dev); | ||||
struct ubt_intel_version_rp version; | struct ubt_intel_version_rp version; | ||||
ng_hci_reset_rp reset; | ng_hci_reset_rp reset; | ||||
int error; | int error; | ||||
uint8_t img_type; | |||||
if (uaa->usb_mode != USB_MODE_HOST) | if (uaa->usb_mode != USB_MODE_HOST) | ||||
return (ENXIO); | return (ENXIO); | ||||
if (uaa->info.bIfaceIndex != 0) | if (uaa->info.bIfaceIndex != 0) | ||||
return (ENXIO); | return (ENXIO); | ||||
error = usbd_lookup_id_by_uaa(ubt_intel_devs, sizeof(ubt_intel_devs), | error = usbd_lookup_id_by_uaa(ubt_intel_devs, sizeof(ubt_intel_devs), | ||||
Show All 35 Lines | case UBT_INTEL_DEVICE_8260: | ||||
* variant byte of "Intel version" HCI command response. | * variant byte of "Intel version" HCI command response. | ||||
* The value 0x23 identifies the operational firmware. | * The value 0x23 identifies the operational firmware. | ||||
*/ | */ | ||||
if (ubt_intel_do_hci_request(uaa->device, | if (ubt_intel_do_hci_request(uaa->device, | ||||
NG_HCI_OPCODE(NG_HCI_OGF_VENDOR, 0x05), | NG_HCI_OPCODE(NG_HCI_OGF_VENDOR, 0x05), | ||||
&version, sizeof(version)) != USB_ERR_NORMAL_COMPLETION) | &version, sizeof(version)) != USB_ERR_NORMAL_COMPLETION) | ||||
return (ENXIO); | return (ENXIO); | ||||
if (version.fw_variant != 0x23) | if (version.fw_variant != 0x23) | ||||
return (ENXIO); | |||||
break; | |||||
case UBT_INTEL_DEVICE_9260: | |||||
/* | |||||
* Find if the Intel Wireless 9260/9560 device is in bootloader | |||||
* mode or is running operational firmware with checking of | |||||
* image type byte of "Intel version" HCI command response. | |||||
* The value 0x03 identifies the operational firmware. | |||||
*/ | |||||
img_type = ubt_intel_get_img_type(uaa->device); | |||||
if (img_type != 0x03) | |||||
return (ENXIO); | return (ENXIO); | ||||
break; | break; | ||||
default: | default: | ||||
KASSERT(0 == 1, ("Unknown DRIVER_INFO")); | KASSERT(0 == 1, ("Unknown DRIVER_INFO")); | ||||
} | } | ||||
return (BUS_PROBE_DEFAULT); | return (BUS_PROBE_DEFAULT); | ||||
Show All 20 Lines |
This is the same command as for 7260/8260 to get the version, just with different len/data? Did they change the interface for the 9260?