From patchwork Thu Mar 23 21:10:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manish Mandlik X-Patchwork-Id: 13186092 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 E7973C74A5B for ; Thu, 23 Mar 2023 21:10:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231417AbjCWVKb (ORCPT ); Thu, 23 Mar 2023 17:10:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231128AbjCWVK3 (ORCPT ); Thu, 23 Mar 2023 17:10:29 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 903A624CAD for ; Thu, 23 Mar 2023 14:10:27 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id i11-20020a256d0b000000b0086349255277so23829945ybc.8 for ; Thu, 23 Mar 2023 14:10:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1679605827; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=vb8xGekqLZEVswI0VXnWBbiOZDnEjcKbHS0+1g7cZR4=; b=L+DAp2MOt1+8vAsdO/zxTmqAUl6PsMPqtBeQXy0P2jSvlukJIyVJjOqgOPy+UKV0H1 x8mmXxHbULbceu1L/ka66cuA4w8ZH/XyUJ44nLaTPk7I9F//Ec4Wo6lS8yM9lkJN3ypB l1f0sysmj7ibeMdHoDuVJQhymiW98UsjMmaM+yvpS2So+/jfS44Ufv2LizHWFmuZULEV VmubLNxsmTe3nS8ksdXCCb9k1Ue5Etede03yupybyDCPn0AtuvPa42GQciMCtb8rWtff T56hLVMzbANMVRr9jAYbjE0Hhp41GCzLeGyLKVbaJjl1U3dpdeLdjuhn0ZwyItVTW5Pj uNGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679605827; 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=vb8xGekqLZEVswI0VXnWBbiOZDnEjcKbHS0+1g7cZR4=; b=qm/clA8nMedDiy8KZBf5wjvlxA9HJpbi+/p45/5g8SL+UesHXXnEmgoc8eyWu00JpF F8HAfmUo0Sq1ec+YbJKVb1LAW3EsX/QCJDh1uPptw3BFqY2TlglypaCCnXvNVF0Nyppz kNUasjBSYnl/KeCuYXaaSfQofAaGd7LtxrZEqS0NhWiJBZ44pk2DAwQN72LVvgF1mhDl 2tBLRvAejEOVLFwoYkYIRD7ke1MxKyx+ZIpT8xvMdEUZznZM6DrnogbGcI+qJk8Rsa2s PYwYDHKxHsCNUsQYnWHGMnMdzkl3LPs2doWOr1XvVytyzzNvn5MKVY1Z3RRDlkwOgKTu d04g== X-Gm-Message-State: AAQBX9c8SQxNA7LcRdCbzEPIfCqDnBoFME1tltTKU+PF77NHCoX8GI+Q SBKApmmXz8Y0Nt1tH8dx5F8g9jBgV9hm8g== X-Google-Smtp-Source: AKy350bu4TW4l20Z3Ldxb/R0F1xir4olYbbOOl5RxmNznamXu2tiEKHzmbLClVF0jJHQciyDqGDlbu6V9qqTdg== X-Received: from mmandlik-cloudtop.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:2893]) (user=mmandlik job=sendgmr) by 2002:a81:a782:0:b0:541:a17f:c77d with SMTP id e124-20020a81a782000000b00541a17fc77dmr2498836ywh.10.1679605826783; Thu, 23 Mar 2023 14:10:26 -0700 (PDT) Date: Thu, 23 Mar 2023 14:10:16 -0700 In-Reply-To: <20230323140942.v8.1.I9b4e4818bab450657b19cda3497d363c9baa616e@changeid> Mime-Version: 1.0 References: <20230323140942.v8.1.I9b4e4818bab450657b19cda3497d363c9baa616e@changeid> X-Mailer: git-send-email 2.40.0.348.gf938b09366-goog Message-ID: <20230323140942.v8.2.Ief9a81a3643d2291f6db2b3695c3a6e0159467dc@changeid> Subject: [PATCH v8 2/4] Bluetooth: Add vhci devcoredump support From: Manish Mandlik To: marcel@holtmann.org, luiz.dentz@gmail.com Cc: linux-bluetooth@vger.kernel.org, chromeos-bluetooth-upstreaming@chromium.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 --- 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..1c3c27b7e9b6 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_devcoredump_register(hdev, vhci_coredump, vhci_coredump_hdr, NULL); + + ret = hci_devcoredump_init(hdev, skb->len); + if (ret) { + BT_ERR("Failed to generate devcoredump"); + kfree_skb(skb); + return ret; + } + + hci_devcoredump_append(hdev, skb); + hci_devcoredump_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);