From patchwork Tue Mar 28 16:42:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manish Mandlik X-Patchwork-Id: 13191354 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 87D3EC761AF for ; Tue, 28 Mar 2023 16:42:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229806AbjC1Qmt (ORCPT ); Tue, 28 Mar 2023 12:42:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229589AbjC1Qmr (ORCPT ); Tue, 28 Mar 2023 12:42:47 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 522BD9778 for ; Tue, 28 Mar 2023 09:42:45 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id e186-20020a2537c3000000b00b72501acf50so12689297yba.20 for ; Tue, 28 Mar 2023 09:42:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1680021764; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=sVqYiqqONgJinnmUNat86CZDMiZZiJLuOgYyNlqZ0G4=; b=YzSg/dxn12AXMZGR4PZHWXYmubtTWVftbnNXFSbaOpsDfG2DswYExmXfmFLbRqvM3k tlFsIKs369BYwzvWnxdg27fVO0TR37LvM6aog8UdLoMcHpgzt4+A4FB9kQ4AHAfHFCNE TqSJKXH2rHeqhvWalOlQFVZ0adddTg+WdIQ/ZeE1wxStTCGa3z/hIoPQmwHJntsDAtTU NKxGnVXPTLInviqdQ1qIFbAs/yyapWInkSHMXWowYSMCF7GHGRCrej+Tu9Z59/XPtWRg 10INxw77xWiAsOCg9ZtkWKWt4VMaMrBtHS+t3UZCUGOQ+lH5A8GtAjLnbwlDLevatcAE Mtuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680021764; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=sVqYiqqONgJinnmUNat86CZDMiZZiJLuOgYyNlqZ0G4=; b=SR1/7xQ2LDLQwG/TkrmxK5Fy+nPPkO5sHuPkfxXyEoAGUq5XlMT6uqV6nLZwJqCCuV xXB3qfmCFr2YXM7nX92Q2SemSHfeWt/9iZv20JNS6VWFQU9kLoPFfLG6AjoVUMx8biIe 2WRubKUrBpaSMJT8I9Lu93afeZRDSUEsjPfcd5nT85keee05PNS7z89Ilq8PG8c0tK/d hhz1QQ0u7v9CzCSjdoD1DZB/EDxe6Hd1B2+qYWUj84kKvuO8pQi5e96uDh4XyqlxO3UG M4QwPcdO1QyWlzrWnO3NlPCrPoZFd1iT5L8I7ERhRTSyx9g7DOXyNqt/2gWgmldivsL0 JrnQ== X-Gm-Message-State: AAQBX9e4W5UOpv++xdxRn4EGN6DU4hBsp22HV2/6QGQcHOuk9PjJyw4h IX7hudWKCQqru53MzI4f4bWw/XZmwArtOg== X-Google-Smtp-Source: AKy350ZdF5XB6NGqz4AFBj0o9/gHdRDuFwjjD5sa8NXdDLsWlwsAh8BmUU/+FdYpZNwctVLYwkKI8mynGHsVSw== X-Received: from mmandlik-cloudtop.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:2893]) (user=mmandlik job=sendgmr) by 2002:a81:b65f:0:b0:545:611c:8d19 with SMTP id h31-20020a81b65f000000b00545611c8d19mr7765281ywk.4.1680021764629; Tue, 28 Mar 2023 09:42:44 -0700 (PDT) Date: Tue, 28 Mar 2023 09:42:38 -0700 In-Reply-To: <20230328094207.v11.1.I9b4e4818bab450657b19cda3497d363c9baa616e@changeid> Mime-Version: 1.0 References: <20230328094207.v11.1.I9b4e4818bab450657b19cda3497d363c9baa616e@changeid> X-Mailer: git-send-email 2.40.0.348.gf938b09366-goog Message-ID: <20230328094207.v11.2.Ief9a81a3643d2291f6db2b3695c3a6e0159467dc@changeid> Subject: [PATCH v11 2/4] Bluetooth: Add vhci devcoredump support From: Manish Mandlik To: marcel@holtmann.org, luiz.dentz@gmail.com Cc: chromeos-bluetooth-upstreaming@chromium.org, linux-bluetooth@vger.kernel.org, Manish Mandlik , Johan Hedberg , linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Add devcoredump support for vhci that creates forcce_devcoredump debugfs entry. This is used for mgmt-tester tests. Signed-off-by: Manish Mandlik --- (no changes since v9) Changes in v9: - Rename hci_devcoredump_*() to hci_devcd_*() Changes in v8: - Update vhci_coredump_hdr() to use skb Changes in v7: - New patch in the series drivers/bluetooth/Kconfig | 1 + drivers/bluetooth/hci_vhci.c | 64 ++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/drivers/bluetooth/Kconfig b/drivers/bluetooth/Kconfig index 5a1a7bec3c42..7bc7a765ad69 100644 --- a/drivers/bluetooth/Kconfig +++ b/drivers/bluetooth/Kconfig @@ -363,6 +363,7 @@ config BT_HCIBLUECARD config BT_HCIVHCI tristate "HCI VHCI (Virtual HCI device) driver" + select WANT_DEV_COREDUMP help Bluetooth Virtual HCI device driver. This driver is required if you want to use HCI Emulation software. diff --git a/drivers/bluetooth/hci_vhci.c b/drivers/bluetooth/hci_vhci.c index c443c3b0a4da..a265dcaf8275 100644 --- a/drivers/bluetooth/hci_vhci.c +++ b/drivers/bluetooth/hci_vhci.c @@ -278,6 +278,67 @@ static int vhci_setup(struct hci_dev *hdev) return 0; } +static void vhci_coredump(struct hci_dev *hdev) +{ + /* No need to do anything */ +} + +static void vhci_coredump_hdr(struct hci_dev *hdev, struct sk_buff *skb) +{ + char buf[80]; + + snprintf(buf, sizeof(buf), "Controller Name: vhci_ctrl\n"); + skb_put_data(skb, buf, strlen(buf)); + + snprintf(buf, sizeof(buf), "Firmware Version: vhci_fw\n"); + skb_put_data(skb, buf, strlen(buf)); + + snprintf(buf, sizeof(buf), "Driver: vhci_drv\n"); + skb_put_data(skb, buf, strlen(buf)); + + snprintf(buf, sizeof(buf), "Vendor: vhci\n"); + skb_put_data(skb, buf, strlen(buf)); +} + +static ssize_t force_devcoredump_write(struct file *file, + const char __user *user_buf, + size_t count, loff_t *ppos) +{ + struct vhci_data *data = file->private_data; + struct hci_dev *hdev = data->hdev; + struct sk_buff *skb = NULL; + char buf[512]; + int ret; + + ret = simple_write_to_buffer(&buf, sizeof(buf), ppos, user_buf, count); + if (ret < count) + return ret; + + skb = alloc_skb(count, GFP_ATOMIC); + if (!skb) + return -ENOMEM; + skb_put_data(skb, &buf, count); + + hci_devcd_register(hdev, vhci_coredump, vhci_coredump_hdr, NULL); + + ret = hci_devcd_init(hdev, skb->len); + if (ret) { + BT_ERR("Failed to generate devcoredump"); + kfree_skb(skb); + return ret; + } + + hci_devcd_append(hdev, skb); + hci_devcd_complete(hdev); + + return count; +} + +static const struct file_operations force_devcoredump_fops = { + .open = simple_open, + .write = force_devcoredump_write, +}; + static int __vhci_create_device(struct vhci_data *data, __u8 opcode) { struct hci_dev *hdev; @@ -355,6 +416,9 @@ static int __vhci_create_device(struct vhci_data *data, __u8 opcode) debugfs_create_file("aosp_capable", 0644, hdev->debugfs, data, &aosp_capable_fops); + debugfs_create_file("force_devcoredump", 0644, hdev->debugfs, data, + &force_devcoredump_fops); + hci_skb_pkt_type(skb) = HCI_VENDOR_PKT; skb_put_u8(skb, 0xff);