Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp4238707pxb; Tue, 17 Nov 2020 15:28:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJz6ItF04RIlFEKHXpX+tG1lQ7scctUdzhu/FnGvn9N5qCgKxX6OOn4S9kf0MNe3A1ok5IHB X-Received: by 2002:a50:da4b:: with SMTP id a11mr23407571edk.109.1605655684027; Tue, 17 Nov 2020 15:28:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605655684; cv=none; d=google.com; s=arc-20160816; b=AoRQS1PWb1nfHEArN7JhP7Ukg21I/ILE0Q/MYkroqV6PWvohLbY5oTluNd4XvJRAu/ FawbGrqhRG6yCHJLNxgzlJLJ6t7dqD1umeeEV85uKnmxpEcPks30EmmE+U/+tjgWgGgH 87Vs7VkRdW3MkKkTblbL68M1kgfF90FSnzi2EiSv/d1qE6UgK8YLK+iL1syROTAuEStR YHalUGeq45fqCm3gxnRL5TM7gb+SjABwjsA29qLK/JjGO7a6eqF7/lH6y3QXK7CdNPqN FEDn0fokAFESGlEcYRcDuSz4jH4VW1pTNhZ9Od895t999l2PrTZmSJGzI5F+Fj+ka9jX OuPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=IWvC/9lmLXawXRr/E+qLrLVml7D3dbTfUiZKC/xB8fQ=; b=o/scIYBdb69wtE3khLXlKCn15ZXPAbue7eORclrdDok4cxn3gg+ebmP5UXs14dj2uL xRUeP9/TqqhTJ4gR+BqTxDa+/fgveyhylSlGYfCM/mHIANjxgQ6Oi2xzuN7ysr5BNlu6 QB+o+qvtlTzPFcWkv1vHDHdM1y3j/y0NquWGD+XR6QyxVj/Gcgja/+Fd0eDL3JoBbOLJ cbjILyhRCP1Lfkotb8J8/rbzM2mggqv7H81UFEvjy4NEKs3jORmmI4E7A8iTjwonev9q HLG2h1TUV8As5SYAAHt67YcQYVBDKeTPjqmUSPGq9zXau2lrFe40StGnc4NwobH/+HMM hbNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=eJbnh2lH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id by4si13900474ejc.732.2020.11.17.15.27.41; Tue, 17 Nov 2020 15:28:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=eJbnh2lH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729377AbgKQXYW (ORCPT + 99 others); Tue, 17 Nov 2020 18:24:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40540 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725779AbgKQXYW (ORCPT ); Tue, 17 Nov 2020 18:24:22 -0500 Received: from mail-oi1-x263.google.com (mail-oi1-x263.google.com [IPv6:2607:f8b0:4864:20::263]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C85B7C0613CF for ; Tue, 17 Nov 2020 15:24:21 -0800 (PST) Received: by mail-oi1-x263.google.com with SMTP id f11so108402oij.6 for ; Tue, 17 Nov 2020 15:24:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=IWvC/9lmLXawXRr/E+qLrLVml7D3dbTfUiZKC/xB8fQ=; b=eJbnh2lHvRpZCaIyBTDO0qlsAYwECcI+HkQ+PQQOu58wm1C9oane1o0Usi4WO0tdEZ WURic6FhFGjSNZnXYsKgjV6QB9wtpsW1KKuJNKTigtSEAdvu/YfEY5sLxk7dSQ+AnY3S MO2ER8P98LidW6jpGtihO/vOukgzMTb0OMkoY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=IWvC/9lmLXawXRr/E+qLrLVml7D3dbTfUiZKC/xB8fQ=; b=pvzlNiplnnUwU+tqIuE56DEvR/5yTl39zCRfQ9L4g/BFGJ1tMPudFCNa+eu8ZckUC2 fSP6chG1u3HV/FfhMvU7UeE6cDi4KRUjs7rty+RTV9X+7TsVBRUyq32pQNBrUW3Mt+sr RAmWiCRn5QJGuhe7Dk92uh7N7ZGlArj9uIjO7KCK0rtGf/CoDrrUYJ6Q2qwawxiuFPpY ewc3JWR30xISPw01ACnVIyTGYsQ1ouu1vnxFKCD/oCxVqdOSOwoKpKI4dRi0PvkLwDxd 2aLkgvoG/3GmCuNmNQnVi6MRNYe3ZM5OgqV240aPtyhrww5pZGAz+FO4MabrjVwDLzga kvoA== X-Gm-Message-State: AOAM532Ju/FyLPPHd5IdUGLamGVkW2MF4tXQ3V37owPfZlLdympgmLhu qqCdcfi8jADLijmKe5h7nhsoqE92Mh4Y6OshO6ITihH7gd4d X-Received: by 2002:aca:c311:: with SMTP id t17mr1076970oif.46.1605655461084; Tue, 17 Nov 2020 15:24:21 -0800 (PST) Received: from lbrmn-lnxub113.broadcom.net ([192.19.228.250]) by smtp-relay.gmail.com with ESMTPS id q22sm5867076otg.13.2020.11.17.15.24.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Nov 2020 15:24:21 -0800 (PST) X-Relaying-Domain: broadcom.com From: Scott Branden To: Arnd Bergmann , Greg Kroah-Hartman , Scott Branden , Desmond Yan Cc: Kees Cook , linux-kernel@vger.kernel.org, bcm-kernel-feedback-list@broadcom.com, Olof Johansson Subject: [PATCH v7 04/13] misc: bcm-vk: add misc device to Broadcom VK driver Date: Tue, 17 Nov 2020 15:23:11 -0800 Message-Id: <20201117232320.4958-5-scott.branden@broadcom.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201117232320.4958-1-scott.branden@broadcom.com> References: <20201117232320.4958-1-scott.branden@broadcom.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add misc device base support to create and remove devnode. Additional misc functions for open/read/write/release/ioctl/sysfs, etc will be added in follow on commits to allow for individual review. Co-developed-by: Desmond Yan Signed-off-by: Desmond Yan Signed-off-by: Scott Branden --- drivers/misc/bcm-vk/bcm_vk.h | 2 ++ drivers/misc/bcm-vk/bcm_vk_dev.c | 36 +++++++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/drivers/misc/bcm-vk/bcm_vk.h b/drivers/misc/bcm-vk/bcm_vk.h index c4fb61a84e41..0a366db693c8 100644 --- a/drivers/misc/bcm-vk/bcm_vk.h +++ b/drivers/misc/bcm-vk/bcm_vk.h @@ -7,6 +7,7 @@ #define BCM_VK_H #include +#include #include #include @@ -214,6 +215,7 @@ struct bcm_vk { struct bcm_vk_dauth_info dauth_info; + struct miscdevice miscdev; int devid; /* dev id allocated */ struct workqueue_struct *wq_thread; diff --git a/drivers/misc/bcm-vk/bcm_vk_dev.c b/drivers/misc/bcm-vk/bcm_vk_dev.c index adc3103c7012..4ecd5b5f80d3 100644 --- a/drivers/misc/bcm-vk/bcm_vk_dev.c +++ b/drivers/misc/bcm-vk/bcm_vk_dev.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -643,6 +644,7 @@ static int bcm_vk_probe(struct pci_dev *pdev, const struct pci_device_id *ent) char name[20]; struct bcm_vk *vk; struct device *dev = &pdev->dev; + struct miscdevice *misc_device; u32 boot_status; vk = kzalloc(sizeof(*vk), GFP_KERNEL); @@ -719,6 +721,19 @@ static int bcm_vk_probe(struct pci_dev *pdev, const struct pci_device_id *ent) vk->devid = id; snprintf(name, sizeof(name), DRV_MODULE_NAME ".%d", id); + misc_device = &vk->miscdev; + misc_device->minor = MISC_DYNAMIC_MINOR; + misc_device->name = kstrdup(name, GFP_KERNEL); + if (!misc_device->name) { + err = -ENOMEM; + goto err_ida_remove; + } + + err = misc_register(misc_device); + if (err) { + dev_err(dev, "failed to register device\n"); + goto err_kfree_name; + } INIT_WORK(&vk->wq_work, bcm_vk_wq_handler); @@ -727,7 +742,7 @@ static int bcm_vk_probe(struct pci_dev *pdev, const struct pci_device_id *ent) if (!vk->wq_thread) { dev_err(dev, "Fail to create workqueue thread\n"); err = -ENOMEM; - goto err_ida_remove; + goto err_misc_deregister; } /* sync other info */ @@ -749,11 +764,20 @@ static int bcm_vk_probe(struct pci_dev *pdev, const struct pci_device_id *ent) } } + dev_dbg(dev, "BCM-VK:%u created\n", id); + return 0; err_destroy_workqueue: destroy_workqueue(vk->wq_thread); +err_misc_deregister: + misc_deregister(misc_device); + +err_kfree_name: + kfree(misc_device->name); + misc_device->name = NULL; + err_ida_remove: ida_simple_remove(&bcm_vk_ida, id); @@ -783,6 +807,7 @@ static void bcm_vk_remove(struct pci_dev *pdev) { int i; struct bcm_vk *vk = pci_get_drvdata(pdev); + struct miscdevice *misc_device = &vk->miscdev; /* * Trigger a reset to card and wait enough time for UCODE to rerun, @@ -797,6 +822,13 @@ static void bcm_vk_remove(struct pci_dev *pdev) dma_free_coherent(&pdev->dev, nr_scratch_pages * PAGE_SIZE, vk->tdma_vaddr, vk->tdma_addr); + /* remove if name is set which means misc dev registered */ + if (misc_device->name) { + misc_deregister(misc_device); + kfree(misc_device->name); + ida_simple_remove(&bcm_vk_ida, vk->devid); + } + cancel_work_sync(&vk->wq_work); destroy_workqueue(vk->wq_thread); @@ -805,6 +837,8 @@ static void bcm_vk_remove(struct pci_dev *pdev) pci_iounmap(pdev, vk->bar[i]); } + dev_dbg(&pdev->dev, "BCM-VK:%d released\n", vk->devid); + pci_release_regions(pdev); pci_free_irq_vectors(pdev); pci_disable_device(pdev); -- 2.17.1