From nobody Wed Nov 06 23:31:55 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4XkM172K37z5c0Nl; Wed, 06 Nov 2024 23:31:55 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4XkM171gjVz4LtL; Wed, 6 Nov 2024 23:31:55 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1730935915; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Ihtha4jDNtjnYfQJaNatJTzQu/CA1VlGpeCcRDuju9c=; b=IpHIchABucaWQZqlw/TeLf1n+t0YkyHCWRsVFU8z5RN5CvDT6+B1/LpljgJL4IOlrig+z2 K/NnImBkdampntTzmgow8V2cqKpE0Q8ktbtMdEKH384T0T5VhntlIjYEjA9JxhCUUivd/A HWcM1hd3D7DP88f/x0NYCkrQLXl4M2tBvBzl6ItO1gaYt1C8/fhbyI2rvAk2VZGRrpOqrw SI/PFtC6IIguqtWyTrgLC8FLl1FmB4sMreBWP8LJl6hl129Ar/QxQXQtTTkdchyhcs39vm aOiHi5wlLWcN2tkXThjZtR1z4j3uPDVb53pRHrhGkn3mSCLPm+BhVK1pXf2gJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1730935915; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Ihtha4jDNtjnYfQJaNatJTzQu/CA1VlGpeCcRDuju9c=; b=R+VNlFfYgS7H2xRBPcGb1B8muEbRg8Nb71QyGoM9l4KUh2K5vIbxCG+TSQVx8lH+Lv5Zkb iZ98KNYsgdnrhzsPYc1/st/PtPLi2rPGtTY6/5wWuCX1i/Z3kPSoXSFGIpLHvHm7tgagGA CNTliMfVMkeZ0c5s6d1to3i+463LHhGFqvJblckUVSuS8MrQ+BGvH/7gAQ7TzKRFWQAZSi dHlcSi/opQIuPFdwfsvsQeuZu1d3d2TL6KENLfut0tBsdO/PSCKukWb7Q4EyubWa+Kcb86 7ClD37/ewETf2YNQDqzUJaLm84ShGjwDlFEaRl7H0+loLrJ2StKLfvrSrzel9A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1730935915; a=rsa-sha256; cv=none; b=TgRCCqsB2oNrZzK56+fanbuMoIKOHTe0Oc2pBaQNvrAF7bOMNkNdSRITKbNiqaPNDcypqr cDHOc7FN9STASyQrw8HEMoz/5GRB1wEIPit+GGB2fFcs4ejSAld/Pc9MZjHHF+LNDwEY66 CUI1g1/VrAVkbvxneFD36w6oHHBVyqRyZoUMl3FPuNwzaPHqjLATLc+FSczOQyawZ6yVLx MH8tkpqDdcOWDsgfXvFNSvuffDil8KAIIOvEKxZpafw1quQwWwP3K+jcs/K8r203R3ut4i BsHamjM8nateiIG4Vtia0Xl59Cw5u4wHWO6npeoET/eg+HNB6WKNZKtME5Z0vw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4XkM171GMbzL7d; Wed, 6 Nov 2024 23:31:55 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 4A6NVtjA069960; Wed, 6 Nov 2024 23:31:55 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4A6NVt5g069957; Wed, 6 Nov 2024 23:31:55 GMT (envelope-from git) Date: Wed, 6 Nov 2024 23:31:55 GMT Message-Id: <202411062331.4A6NVt5g069957@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Vladimir Kondratyev Subject: git: aa0b938434a8 - main - iwmbtfw(8): Ignore unexpected HCI events List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: wulf X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: aa0b938434a8af8eebf8f2634914f2d9fe8a5dc4 Auto-Submitted: auto-generated The branch main has been updated by wulf: URL: https://cgit.FreeBSD.org/src/commit/?id=aa0b938434a8af8eebf8f2634914f2d9fe8a5dc4 commit aa0b938434a8af8eebf8f2634914f2d9fe8a5dc4 Author: Vladimir Kondratyev AuthorDate: 2024-11-06 23:27:48 +0000 Commit: Vladimir Kondratyev CommitDate: 2024-11-06 23:27:48 +0000 iwmbtfw(8): Ignore unexpected HCI events If Intel firmware is already in operational mode at boot that takes place at warm boot, BT adaptor can generate extra HCI events which interferes with firmware mode detection logic. Ignore them. Sponsored by: Future Crew LLC MFC after: 1 month Differential Revision: https://reviews.freebsd.org/D46737 --- usr.sbin/bluetooth/iwmbtfw/iwmbt_hw.c | 58 +++++++++++++++++++++++++++-------- usr.sbin/bluetooth/iwmbtfw/iwmbt_hw.h | 6 ++++ 2 files changed, 52 insertions(+), 12 deletions(-) diff --git a/usr.sbin/bluetooth/iwmbtfw/iwmbt_hw.c b/usr.sbin/bluetooth/iwmbtfw/iwmbt_hw.c index 05a851f9d85b..1efd24ecf9f6 100644 --- a/usr.sbin/bluetooth/iwmbtfw/iwmbt_hw.c +++ b/usr.sbin/bluetooth/iwmbtfw/iwmbt_hw.c @@ -37,10 +37,13 @@ #include #include #include +#include #include #include +#include + #include "iwmbt_fw.h" #include "iwmbt_hw.h" #include "iwmbt_dbg.h" @@ -95,6 +98,7 @@ static int iwmbt_hci_command(struct libusb_device_handle *hdl, struct iwmbt_hci_cmd *cmd, void *event, int size, int *transferred, int timeout) { + struct timespec to, now, remains; int ret; ret = libusb_control_transfer(hdl, @@ -112,18 +116,47 @@ iwmbt_hci_command(struct libusb_device_handle *hdl, struct iwmbt_hci_cmd *cmd, return (ret); } - ret = libusb_interrupt_transfer(hdl, - IWMBT_INTERRUPT_ENDPOINT_ADDR, - event, - size, - transferred, - timeout); + clock_gettime(CLOCK_MONOTONIC, &now); + to = IWMBT_MSEC2TS(timeout); + timespecadd(&to, &now, &to); - if (ret < 0) - iwmbt_err("libusb_interrupt_transfer() failed: err=%s", - libusb_strerror(ret)); + do { + timespecsub(&to, &now, &remains); + ret = libusb_interrupt_transfer(hdl, + IWMBT_INTERRUPT_ENDPOINT_ADDR, + event, + size, + transferred, + IWMBT_TS2MSEC(remains) + 1); - return (ret); + if (ret < 0) { + iwmbt_err("libusb_interrupt_transfer() failed: err=%s", + libusb_strerror(ret)); + return (ret); + } + + switch (((struct iwmbt_hci_event *)event)->header.event) { + case NG_HCI_EVENT_COMMAND_COMPL: + if (*transferred < + (int)offsetof(struct iwmbt_hci_event_cmd_compl, data)) + break; + if (cmd->opcode != + ((struct iwmbt_hci_event_cmd_compl *)event)->opcode) + break; + /* FALLTHROUGH */ + case 0xFF: + return (0); + default: + break; + } + iwmbt_debug("Stray HCI event: %x", + ((struct iwmbt_hci_event *)event)->header.event); + } while (timespeccmp(&to, &now, >)); + + iwmbt_err("libusb_interrupt_transfer() failed: err=%s", + libusb_strerror(LIBUSB_ERROR_TIMEOUT)); + + return (LIBUSB_ERROR_TIMEOUT); } int @@ -691,6 +724,7 @@ iwmbt_load_ddc(struct libusb_device_handle *hdl, int size, sent = 0; int ret, transferred; uint8_t buf[IWMBT_HCI_MAX_CMD_SIZE]; + uint8_t evt[IWMBT_HCI_MAX_CMD_SIZE]; struct iwmbt_hci_cmd *cmd = (struct iwmbt_hci_cmd *)buf; size = ddc->len; @@ -713,8 +747,8 @@ iwmbt_load_ddc(struct libusb_device_handle *hdl, ret = iwmbt_hci_command(hdl, cmd, - buf, - sizeof(buf), + evt, + sizeof(evt), &transferred, IWMBT_HCI_CMD_TIMEOUT); diff --git a/usr.sbin/bluetooth/iwmbtfw/iwmbt_hw.h b/usr.sbin/bluetooth/iwmbtfw/iwmbt_hw.h index 9467c3807a2a..89ee344fe587 100644 --- a/usr.sbin/bluetooth/iwmbtfw/iwmbt_hw.h +++ b/usr.sbin/bluetooth/iwmbtfw/iwmbt_hw.h @@ -72,6 +72,12 @@ struct iwmbt_hci_event_cmd_compl { #define IWMBT_HCI_MAX_CMD_SIZE 256 #define IWMBT_HCI_MAX_EVENT_SIZE 16 +#define IWMBT_MSEC2TS(msec) \ + (struct timespec) { \ + .tv_sec = (msec) / 1000, \ + .tv_nsec = ((msec) % 1000) * 1000000 \ + }; +#define IWMBT_TS2MSEC(ts) ((ts).tv_sec * 1000 + (ts).tv_nsec / 1000000) #define IWMBT_HCI_CMD_TIMEOUT 2000 /* ms */ #define IWMBT_LOADCMPL_TIMEOUT 5000 /* ms */