Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3403020pxk; Mon, 28 Sep 2020 17:14:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJynyoJpOrDXnIey0AiFzLdaLuj4sQO2bXBPTHAAaf8q61FVjP94htZSm+YnnDaARotXZZDD X-Received: by 2002:aa7:d68c:: with SMTP id d12mr545114edr.274.1601338498010; Mon, 28 Sep 2020 17:14:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601338498; cv=none; d=google.com; s=arc-20160816; b=QwyRUHcMgCk5jYXbFOLrmuSmpqZ+UntmQERpZ7FUMiUNH8dHXL1eGDWoI0VzdlLUjP JfQdQEhj3ELc/fAU+akm2QoHbxzpJQZbeyLnvCPgGGxMaulQgunCxYW8TfM5fjrB1HnJ 7BYzlmVw4+tyR7iRURX17AFDCrnINbbPY40axpJjGAWSmhKCyfNjjgd4dOgG5DIwIP79 x4nXF1I7x0Y8sfc9YcuAC7PgpKeeHoU5oXqgz1KjF/NmMrwx7fw8RGfDzhgQvR93afIa BM5CKobcpaQCqj+FWZ88JmmwXHA+R02fEu7dm6YZkZVJ9NeqbFP1sd3UWLseqXgumMYh qGlQ== 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=e01dV72PhVXckVmmseLxTWhtW5vQVL68iuUA5f0aj7c=; b=PYPB8dDamtf4qjpqS47rZCWhVgkez+2ryFgJZLZcq3NU2D3aUFZrbuEu47NjyEsWKW AT4WEq2LP00Wje7w+gm3kiX059kwm2u6pfOruvT8aNlJc2V6oRTuponDukdVA8zSuoCr mgHU/Gm7XuwjljxDxsiQzr74sra9ctzEz/DttdI+PNfXvqGsXMn3ZZiCEqGnWMmPvabW wu+GYdKtJgjYKliMPWCQCtecW7ofPDYM5ZTC/2Ms89YW+h9rNsx5dp7zDy0AAj+PBhDi AhDaDN4YxuieoT7qEdCdOnZQG9lC0JpNv9tWOO15+oiC+gR7DbET0ZCvDJCW2opTnFGE h1Ng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=TbdGNplA; 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 p8si1584065edr.224.2020.09.28.17.14.30; Mon, 28 Sep 2020 17:14:58 -0700 (PDT) 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=TbdGNplA; 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 S1727185AbgI2AMw (ORCPT + 99 others); Mon, 28 Sep 2020 20:12:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727177AbgI2AMs (ORCPT ); Mon, 28 Sep 2020 20:12:48 -0400 Received: from mail-pf1-x463.google.com (mail-pf1-x463.google.com [IPv6:2607:f8b0:4864:20::463]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD856C0613D3 for ; Mon, 28 Sep 2020 17:12:47 -0700 (PDT) Received: by mail-pf1-x463.google.com with SMTP id b124so2746793pfg.13 for ; Mon, 28 Sep 2020 17:12:47 -0700 (PDT) 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=e01dV72PhVXckVmmseLxTWhtW5vQVL68iuUA5f0aj7c=; b=TbdGNplAh2RLlDUFKbenetNEA1JUmz0IuK7oh8p2eAEaRbPAmunTGe1UeaufPTi/be RQp5YnfL18G2ylmjFpFIxCaDmX/f592U6NctFr3qs6YueEhZay6VOtmPeyA6QHWsOJDZ qPnc7UfZx4dI2mtfeJ643qZwF4WEJqEClfBcQ= 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=e01dV72PhVXckVmmseLxTWhtW5vQVL68iuUA5f0aj7c=; b=dAn+NeFK56AgAVVo7L5qF/xE/iwHdFUzkIV5u+8x7J449/fSjhcqRqNrMqOWpE0bc8 u+VHZ6s7gTlyP0b62lZFs4IOo38Jhk6je0gj+Jc0QkvO7fSlZKl7gcvUwKtbC2gu/uOE DiJGiZOnVtaMeYNe2UJDJBCENNp3TkpMZB/KSnNryrWZ1D/bmVc2A7tW19MPMW2Pdnpm 1kLP8t7MnBg/oF+0atL4pQfR+6Sn1LOYxOisAXPyV9QDADan8fBE76QUoEXI6n/xX/YQ YIVY8lwO9Lp1V2mH2a9h3dsVWvfKr5o1LpbYKJ/hYB9lFi+qEzWQEr+eGhR0YVxoSWLr JUPw== X-Gm-Message-State: AOAM531XqW/Q+e8CTztfYIvOUo/2MyGYPI/jVOEyyrnNQ/ObUId2rl2y 6ZhzFYxcIE+VJnWifgkhZ/Gl9TrBdlRHFcRQPKyNiWMoIW2c X-Received: by 2002:a65:498a:: with SMTP id r10mr1089352pgs.400.1601338367292; Mon, 28 Sep 2020 17:12:47 -0700 (PDT) Received: from lbrmn-lnxub113.broadcom.net ([192.19.228.250]) by smtp-relay.gmail.com with ESMTPS id t1sm1047973pjr.8.2020.09.28.17.12.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Sep 2020 17:12:47 -0700 (PDT) X-Relaying-Domain: broadcom.com From: Scott Branden To: Arnd Bergmann , Greg Kroah-Hartman , Scott Branden Cc: Kees Cook , linux-kernel@vger.kernel.org, bcm-kernel-feedback-list@broadcom.com, Desmond Yan Subject: [PATCH v4 04/16] misc: bcm-vk: add misc device to Broadcom VK driver Date: Mon, 28 Sep 2020 17:11:57 -0700 Message-Id: <20200929001209.16393-5-scott.branden@broadcom.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200929001209.16393-1-scott.branden@broadcom.com> References: <20200929001209.16393-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 36f04fd0a54e..cb2e315881d6 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 @@ -638,6 +639,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); @@ -713,6 +715,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); @@ -721,7 +736,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 */ @@ -743,11 +758,20 @@ static int bcm_vk_probe(struct pci_dev *pdev, const struct pci_device_id *ent) } } + dev_dbg(dev, "BCM-VK:%u created, 0x%p\n", id, vk); + 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); @@ -774,6 +798,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, @@ -788,6 +813,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); @@ -796,6 +828,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