Add Broadcom VK driver
Subsystems (2)
Scott Branden
maintainerv10 cover Add Broadcom VK driver
This patch series drops previous patches in [1] that were incorporated by Kees Cook into patch series "Introduce partial kernel_read_file() support" [2].
Remaining patches are contained in this series to add Broadcom VK driver. (which depends on request_firmware_into_buf API addition which has now been accepted into the upstream kernel as of v5.10-rc1).
[1] https://lore.kernel.org/lkml/[email protected]/
[2] https://lore.kernel.org/lkml/[email protected]/
Changes from v9:
- fix compile if CONFIG_TTY not set
- use if-else statement instead of conditional expression in set_q_num
- generate bcm_vk_msg_remove call in proper patch
(was generated in tty patch when should be in msg patch)
Changes from v8:
- add ack's by Olof Johansson
Changes from v7:
- add more information in Kconfig help description
Changes from v6:
- drop QSTATS patch as it needs to be reviewed if trace_printk makes sense
- add wdog and IPC interface alerts
- add boundary check to msgq and peerlog
- clear additional registers on reset
Changes from v5:
- dropped sysfs patch from series for now as rework to use hwmon
- tty patch still at end of series to drop if another solution available
- updated cover letter commit to point to Kees' latest patch submission in [2]
- specified --base with Kees' patches applied (kernel branches don't have these yet)
- removed trivial comment
- moved location of const to before the struct in two declarations
- changed dev_info to dev_warn and only print when irq don't match expected
- changed dev_info to dev_dbg when printing debug QSTATS
- removed unnecessary %p print
Changes from v4:
- fixed memory leak in probe function on failure
- changed -1 to -EBUSY in bcm_vk_tty return code
- move bcm_vk_tty patch to end of patch series so it
can be dropped from current patch series if needed
and rearchitected if needed.
Changes from v3:
- split driver into more incremental commits for acceptance/review
- lowered some dev_info to dev_dbg
- remove ANSI stdint types and replace with linux u8, etc types
- changed an EIO return to EPFNOSUPPORT
- move vk_msg_cmd internal to driver to not expose to UAPI at this time
Changes from v2:
- open code BIT macro in uapi header
- A0/B0 boot improvements
Changes from v1:
- declare bcm_vk_intf_ver_chk as static
Scott Branden (13):
bcm-vk: add bcm_vk UAPI
misc: bcm-vk: add Broadcom VK driver
misc: bcm-vk: add autoload support
misc: bcm-vk: add misc device to Broadcom VK driver
misc: bcm-vk: add triggers when host panic or reboots to notify card
misc: bcm-vk: add open/release
misc: bcm-vk: add ioctl load_image
misc: bcm-vk: add get_card_info, peerlog_info, and proc_mon_info
misc: bcm-vk: add VK messaging support
misc: bcm-vk: reset_pid support
misc: bcm-vk: add mmap function for exposing BAR2
MAINTAINERS: bcm-vk: add maintainer for Broadcom VK Driver
misc: bcm-vk: add ttyVK support
MAINTAINERS | 7 + drivers/misc/Kconfig | 1 + drivers/misc/Makefile | 1 + drivers/misc/bcm-vk/Kconfig | 17 + drivers/misc/bcm-vk/Makefile | 12 + drivers/misc/bcm-vk/bcm_vk.h | 513 +++++++++ drivers/misc/bcm-vk/bcm_vk_dev.c | 1664 ++++++++++++++++++++++++++++++ drivers/misc/bcm-vk/bcm_vk_msg.c | 1356 ++++++++++++++++++++++++ drivers/misc/bcm-vk/bcm_vk_msg.h | 163 +++ drivers/misc/bcm-vk/bcm_vk_sg.c | 275 +++++ drivers/misc/bcm-vk/bcm_vk_sg.h | 61 ++ drivers/misc/bcm-vk/bcm_vk_tty.c | 333 ++++++ include/uapi/linux/misc/bcm_vk.h | 84 ++ 13 files changed, 4487 insertions(+) create mode 100644 drivers/misc/bcm-vk/Kconfig create mode 100644 drivers/misc/bcm-vk/Makefile create mode 100644 drivers/misc/bcm-vk/bcm_vk.h create mode 100644 drivers/misc/bcm-vk/bcm_vk_dev.c create mode 100644 drivers/misc/bcm-vk/bcm_vk_msg.c create mode 100644 drivers/misc/bcm-vk/bcm_vk_msg.h create mode 100644 drivers/misc/bcm-vk/bcm_vk_sg.c create mode 100644 drivers/misc/bcm-vk/bcm_vk_sg.h create mode 100644 drivers/misc/bcm-vk/bcm_vk_tty.c create mode 100644 include/uapi/linux/misc/bcm_vk.h
Signature · 1 line
2.17.1
Scott Branden
maintainerPATCH v10 1/13 bcm-vk: add bcm_vk UAPI
Add user space api for bcm-vk driver.
Provide ioctl api to load images and issue reset command to card. FW status registers in PCI BAR space also defined as part of API so that user space is able to interpret these memory locations as needed via direct PCIe access.
--- include/uapi/linux/misc/bcm_vk.h | 84 ++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 include/uapi/linux/misc/bcm_vk.h
include/uapi/linux/misc/bcm_vk.h new file +84 -0
@@ -0,0 +1,84 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* +* Copyright 2018-2020 Broadcom. +*/ + +#ifndef __UAPI_LINUX_MISC_BCM_VK_H +#define __UAPI_LINUX_MISC_BCM_VK_H + +#include <linux/ioctl.h> +#include <linux/types.h> + +#define BCM_VK_MAX_FILENAME 64 + +struct vk_image { +__u32 type;/* Type of image */ +#define VK_IMAGE_TYPE_BOOT1 1/* 1st stage (load to SRAM) */ +#define VK_IMAGE_TYPE_BOOT2 2/* 2nd stage (load to DDR) */ +__u8 filename[BCM_VK_MAX_FILENAME ];/* Filename of image */ +}; + +struct vk_reset { +__u32 arg1; +__u32 arg2; +}; + +#define VK_MAGIC 0x5e + +/* Load image to Valkyrie */ +#define VK_IOCTL_LOAD_IMAGE _IOW(VK_MAGIC, 0x2, struct vk_image) + +/* Send Reset to Valkyrie */ +#define VK_IOCTL_RESET _IOW(VK_MAGIC, 0x4, struct vk_reset) + +/* +* Firmware Status accessed directly via BAR space +*/ +#define VK_BAR_FWSTS 0x41c +#define VK_BAR_COP_FWSTS 0x428 +/* VK_FWSTS definitions */ +#define VK_FWSTS_RELOCATION_ENTRY (1UL << 0) +#define VK_FWSTS_RELOCATION_EXIT (1UL << 1) +#define VK_FWSTS_INIT_START (1UL << 2) +#define VK_FWSTS_ARCH_INIT_DONE (1UL << 3) +#define VK_FWSTS_PRE_KNL1_INIT_DONE (1UL << 4) +#define VK_FWSTS_PRE_KNL2_INIT_DONE (1UL << 5) +#define VK_FWSTS_POST_KNL_INIT_DONE (1UL << 6) +#define VK_FWSTS_INIT_DONE (1UL << 7) +#define VK_FWSTS_APP_INIT_START (1UL << 8) +#define VK_FWSTS_APP_INIT_DONE (1UL << 9) +#define VK_FWSTS_MASK 0xffffffff +#define VK_FWSTS_READY (VK_FWSTS_INIT_START | \ + VK_FWSTS_ARCH_INIT_DONE | \ + VK_FWSTS_PRE_KNL1_INIT_DONE | \ + VK_FWSTS_PRE_KNL2_INIT_DONE | \ + VK_FWSTS_POST_KNL_INIT_DONE | \ + VK_FWSTS_INIT_DONE | \ + VK_FWSTS_APP_INIT_START | \ + VK_FWSTS_APP_INIT_DONE) +/* Deinit */ +#define VK_FWSTS_APP_DEINIT_START (1UL << 23) +#define VK_FWSTS_APP_DEINIT_DONE (1UL << 24) +#define VK_FWSTS_DRV_DEINIT_START (1UL << 25) +#define VK_FWSTS_DRV_DEINIT_DONE (1UL << 26) +#define VK_FWSTS_RESET_DONE (1UL << 27) +#define VK_FWSTS_DEINIT_TRIGGERED (VK_FWSTS_APP_DEINIT_START | \ + VK_FWSTS_APP_DEINIT_DONE | \ + VK_FWSTS_DRV_DEINIT_START | \ + VK_FWSTS_DRV_DEINIT_DONE) +/* Last nibble for reboot reason */ +#define VK_FWSTS_RESET_REASON_SHIFT 28 +#define VK_FWSTS_RESET_REASON_MASK (0xf << VK_FWSTS_RESET_REASON_SHIFT) +#define VK_FWSTS_RESET_SYS_PWRUP (0x0 << VK_FWSTS_RESET_REASON_SHIFT) +#define VK_FWSTS_RESET_MBOX_DB (0x1 << VK_FWSTS_RESET_REASON_SHIFT) +#define VK_FWSTS_RESET_M7_WDOG (0x2 << VK_FWSTS_RESET_REASON_SHIFT) +#define VK_FWSTS_RESET_TEMP (0x3 << VK_FWSTS_RESET_REASON_SHIFT) +#define VK_FWSTS_RESET_PCI_FLR (0x4 << VK_FWSTS_RESET_REASON_SHIFT) +#define VK_FWSTS_RESET_PCI_HOT (0x5 << VK_FWSTS_RESET_REASON_SHIFT) +#define VK_FWSTS_RESET_PCI_WARM (0x6 << VK_FWSTS_RESET_REASON_SHIFT) +#define VK_FWSTS_RESET_PCI_COLD (0x7 << VK_FWSTS_RESET_REASON_SHIFT) +#define VK_FWSTS_RESET_L1 (0x8 << VK_FWSTS_RESET_REASON_SHIFT) +#define VK_FWSTS_RESET_L0 (0x9 << VK_FWSTS_RESET_REASON_SHIFT) +#define VK_FWSTS_RESET_UNKNOWN (0xf << VK_FWSTS_RESET_REASON_SHIFT) + +#endif /* __UAPI_LINUX_MISC_BCM_VK_H */
Signature · 1 line
2.17.1
Scott Branden
maintainerPATCH v10 2/13 misc: bcm-vk: add Broadcom VK driver
In reply to Scott BrandenAdd initial version of Broadcom VK driver to enumerate PCI device IDs of Valkyrie and Viper device IDs.
VK based cards provide real-time high performance, high throughput, low latency offload compute engine operations.
They are used for multiple parallel offload tasks as:
audio, video and image processing and crypto operations.
Further commits add additional features to driver beyond probe/remove.
--- drivers/misc/Kconfig | 1 + drivers/misc/Makefile | 1 + drivers/misc/bcm-vk/Kconfig | 17 ++++ drivers/misc/bcm-vk/Makefile | 8 ++ drivers/misc/bcm-vk/bcm_vk.h | 29 +++++++ drivers/misc/bcm-vk/bcm_vk_dev.c | 141 +++++++++++++++++++++++++++++++ 6 files changed, 197 insertions(+) create mode 100644 drivers/misc/bcm-vk/Kconfig create mode 100644 drivers/misc/bcm-vk/Makefile create mode 100644 drivers/misc/bcm-vk/bcm_vk.h create mode 100644 drivers/misc/bcm-vk/bcm_vk_dev.c
drivers/misc/Kconfig +1 -0
@@ -478,6 +478,7 @@ source "drivers/misc/genwqe/Kconfig" source "drivers/misc/echo/Kconfig" source "drivers/misc/cxl/Kconfig" source "drivers/misc/ocxl/Kconfig" +source "drivers/misc/bcm-vk/Kconfig" source "drivers/misc/cardreader/Kconfig" source "drivers/misc/habanalabs/Kconfig" source "drivers/misc/uacce/Kconfig"
drivers/misc/Makefile +1 -0
@@ -51,6 +51,7 @@ obj-$(CONFIG_ECHO) += echo/ obj-$(CONFIG_CXL_BASE) += cxl/ obj-$(CONFIG_PCI_ENDPOINT_TEST) += pci_endpoint_test.o obj-$(CONFIG_OCXL) += ocxl/ +obj-$(CONFIG_BCM_VK) += bcm-vk/ obj-y += cardreader/ obj-$(CONFIG_PVPANIC) += pvpanic.o obj-$(CONFIG_HABANA_AI) += habanalabs/
drivers/misc/bcm-vk/Kconfig new file +17 -0
@@ -0,0 +1,17 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Broadcom VK device +# +config BCM_VK + tristate "Support for Broadcom VK Accelerators" + depends on PCI_MSI + help + Select this option to enable support for Broadcom + VK Accelerators. VK is used for performing + multiple specific offload processing tasks in parallel. + Such offload tasks assist in such operations as video + transcoding, compression, and crypto tasks. + This driver enables userspace programs to access these + accelerators via /dev/bcm-vk.N devices. + + If unsure, say N.
drivers/misc/bcm-vk/Makefile new file +8 -0
@@ -0,0 +1,8 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Makefile for Broadcom VK driver +# + +obj-$(CONFIG_BCM_VK) += bcm_vk.o +bcm_vk-objs := \ + bcm_vk_dev.o
drivers/misc/bcm-vk/bcm_vk.h new file +29 -0
@@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright 2018-2020 Broadcom. +*/ + +#ifndef BCM_VK_H +#define BCM_VK_H + +#include <linux/pci.h> + +#define DRV_MODULE_NAME "bcm-vk" + +/* VK device supports a maximum of 3 bars */ +#define MAX_BAR 3 + +enum pci_barno { +BAR_0 =0 , +BAR_1 , +BAR_2 +}; + +#define BCM_VK_NUM_TTY 2 + +struct bcm_vk { +struct pci_dev *pdev; +void __iomem *bar[MAX_BAR ]; +}; + +#endif
drivers/misc/bcm-vk/bcm_vk_dev.c new file +141 -0
141 lines not on this page · raw message
Signature · 1 line
2.17.1
Scott Branden
maintainerPATCH v10 3/13 misc: bcm-vk: add autoload support
In reply to Scott BrandenAdd support to load and boot images on card automatically.
The kernel module parameter auto_load can be passed in as false to disable such support on probe.
As well, nr_scratch_pages can be specified to allocate more or less scratch memory on init as needed for desired card operation.
--- drivers/misc/bcm-vk/bcm_vk.h | 250 +++++++++++ drivers/misc/bcm-vk/bcm_vk_dev.c | 723 +++++++++++++++++++++++++++++++ 2 files changed, 973 insertions(+)
drivers/misc/bcm-vk/bcm_vk.h +250 -0
@@ -6,10 +6,187 @@#ifndef BCM_VK_H #define BCM_VK_H +#include <linux/firmware.h> #include <linux/pci.h> +#include <linux/sched/signal.h> #define DRV_MODULE_NAME "bcm-vk" +/* +* Load Image is completed in two stages: +* +* 1) When the VK device boot-up, M7 CPU runs and executes the BootROM. +* The Secure Boot Loader (SBL) as part of the BootROM will run +* to open up ITCM for host to push BOOT1 image. +* SBL will authenticate the image before jumping to BOOT1 image. +* +* 2) Because BOOT1 image is a secured image, we also called it the +* Secure Boot Image (SBI). At second stage, SBI will initialize DDR +* and wait for host to push BOOT2 image to DDR. +* SBI will authenticate the image before jumping to BOOT2 image. +* +*/ +/* Location of registers of interest in BAR0 */ + +/* Request register for Secure Boot Loader (SBL) download */ +#define BAR_CODEPUSH_SBL 0x400 +/* Start of ITCM */ +#define CODEPUSH_BOOT1_ENTRY 0x00400000 +#define CODEPUSH_MASK 0xfffff000 +#define CODEPUSH_BOOTSTART BIT(0) + +/* Boot Status register */ +#define BAR_BOOT_STATUS 0x404 + +#define SRAM_OPEN BIT(16) +#define DDR_OPEN BIT(17) + +/* Firmware loader progress status definitions */ +#define FW_LOADER_ACK_SEND_MORE_DATA BIT(18) +#define FW_LOADER_ACK_IN_PROGRESS BIT(19) +#define FW_LOADER_ACK_RCVD_ALL_DATA BIT(20) + +/* Boot1/2 is running in standalone mode */ +#define BOOT_STDALONE_RUNNING BIT(21) + +/* definitions for boot status register */ +#define BOOT_STATE_MASK (0xffffffff & \ + ~(FW_LOADER_ACK_SEND_MORE_DATA | \ + FW_LOADER_ACK_IN_PROGRESS | \ + BOOT_STDALONE_RUNNING)) + +#define BOOT_ERR_SHIFT 4 +#define BOOT_ERR_MASK (0xf << BOOT_ERR_SHIFT) +#define BOOT_PROG_MASK 0xf + +#define BROM_STATUS_NOT_RUN 0x2 +#define BROM_NOT_RUN (SRAM_OPEN | BROM_STATUS_NOT_RUN) +#define BROM_STATUS_COMPLETE 0x6 +#define BROM_RUNNING (SRAM_OPEN | BROM_STATUS_COMPLETE) +#define BOOT1_STATUS_COMPLETE 0x6 +#define BOOT1_RUNNING (DDR_OPEN | BOOT1_STATUS_COMPLETE) +#define BOOT2_STATUS_COMPLETE 0x6 +#define BOOT2_RUNNING (FW_LOADER_ACK_RCVD_ALL_DATA | \ + BOOT2_STATUS_COMPLETE) + +/* Boot request for Secure Boot Image (SBI) */ +#define BAR_CODEPUSH_SBI 0x408 +/* 64M mapped to BAR2 */ +#define CODEPUSH_BOOT2_ENTRY 0x60000000 + +#define BAR_CARD_STATUS 0x410 + +#define BAR_BOOT1_STDALONE_PROGRESS 0x420 +#define BOOT1_STDALONE_SUCCESS (BIT(13) | BIT(14)) +#define BOOT1_STDALONE_PROGRESS_MASK BOOT1_STDALONE_SUCCESS + +#define BAR_METADATA_VERSION 0x440 +#define BAR_OS_UPTIME 0x444 +#define BAR_CHIP_ID 0x448 +#define MAJOR_SOC_REV (_chip_id) (((_chip_id) >> 20) & 0xf) + +#define BAR_CARD_TEMPERATURE 0x45c + +#define BAR_CARD_VOLTAGE 0x460 + +#define BAR_CARD_ERR_LOG 0x464 + +#define BAR_CARD_ERR_MEM 0x468 + +#define BAR_CARD_PWR_AND_THRE 0x46c + +#define BAR_CARD_STATIC_INFO 0x470 + +#define BAR_INTF_VER 0x47c +#define BAR_INTF_VER_MAJOR_SHIFT 16 +#define BAR_INTF_VER_MASK 0xffff +/* +* major and minor semantic version numbers supported +* Please update as required on interface changes +*/ +#define SEMANTIC_MAJOR 1 +#define SEMANTIC_MINOR 0 + +/* +* first door bell reg, ie for queue = 0. Only need the first one, as +* we will use the queue number to derive the others +*/ +#define VK_BAR0_REGSEG_DB_BASE 0x484 +#define VK_BAR0_REGSEG_DB_REG_GAP 8/* +* DB register gap, +* DB1 at 0x48c and DB2 at 0x494 +*/ + +/* reset register and specific values */ +#define VK_BAR0_RESET_DB_NUM 3 +#define VK_BAR0_RESET_DB_SOFT 0xffffffff +#define VK_BAR0_RESET_DB_HARD 0xfffffffd +#define VK_BAR0_RESET_RAMPDUMP 0xa0000000 + +#define VK_BAR0_Q_DB_BASE (q_num) (VK_BAR0_REGSEG_DB_BASE + \ + ((q_num) * VK_BAR0_REGSEG_DB_REG_GAP)) +#define VK_BAR0_RESET_DB_BASE (VK_BAR0_REGSEG_DB_BASE + \ + (VK_BAR0_RESET_DB_NUM * VK_BAR0_REGSEG_DB_REG_GAP)) + +#define BAR_BOOTSRC_SELECT 0xc78 +/* BOOTSRC definitions */ +#define BOOTSRC_SOFT_ENABLE BIT(14) + +/* Card OS Firmware version size */ +#define BAR_FIRMWARE_TAG_SIZE 50 +#define FIRMWARE_STATUS_PRE_INIT_DONE 0x1f + +/* +* BAR1 +*/ + +/* BAR1 message q definition */ + +/* indicate if msgq ctrl in BAR1 is populated */ +#define VK_BAR1_MSGQ_DEF_RDY 0x60c0 +/* ready marker value for the above location, normal boot2 */ +#define VK_BAR1_MSGQ_RDY_MARKER 0xbeefcafe +/* ready marker value for the above location, normal boot2 */ +#define VK_BAR1_DIAG_RDY_MARKER 0xdeadcafe +/* number of msgqs in BAR1 */ +#define VK_BAR1_MSGQ_NR 0x60c4 +/* BAR1 queue control structure offset */ +#define VK_BAR1_MSGQ_CTRL_OFF 0x60c8 + +/* BAR1 ucode and boot1 version tag */ +#define VK_BAR1_UCODE_VER_TAG 0x6170 +#define VK_BAR1_BOOT1_VER_TAG 0x61b0 +#define VK_BAR1_VER_TAG_SIZE 64 + +/* Memory to hold the DMA buffer memory address allocated for boot2 download */ +#define VK_BAR1_DMA_BUF_OFF_HI 0x61e0 +#define VK_BAR1_DMA_BUF_OFF_LO (VK_BAR1_DMA_BUF_OFF_HI + 4) +#define VK_BAR1_DMA_BUF_SZ (VK_BAR1_DMA_BUF_OFF_HI + 8) + +/* Scratch memory allocated on host for VK */ +#define VK_BAR1_SCRATCH_OFF_HI 0x61f0 +#define VK_BAR1_SCRATCH_OFF_LO (VK_BAR1_SCRATCH_OFF_HI + 4) +#define VK_BAR1_SCRATCH_SZ_ADDR (VK_BAR1_SCRATCH_OFF_HI + 8) +#define VK_BAR1_SCRATCH_DEF_NR_PAGES 32 + +/* BAR1 DAUTH info */ +#define VK_BAR1_DAUTH_BASE_ADDR 0x6200 +#define VK_BAR1_DAUTH_STORE_SIZE 0x48 +#define VK_BAR1_DAUTH_VALID_SIZE 0x8 +#define VK_BAR1_DAUTH_MAX 4 +#define VK_BAR1_DAUTH_STORE_ADDR (x) \ + (VK_BAR1_DAUTH_BASE_ADDR + \ + (x) * (VK_BAR1_DAUTH_STORE_SIZE + VK_BAR1_DAUTH_VALID_SIZE)) +#define VK_BAR1_DAUTH_VALID_ADDR (x) \ + (VK_BAR1_DAUTH_STORE_ADDR(x) + VK_BAR1_DAUTH_STORE_SIZE) + +/* BAR1 SOTP AUTH and REVID info */ +#define VK_BAR1_SOTP_REVID_BASE_ADDR 0x6340 +#define VK_BAR1_SOTP_REVID_SIZE 0x10 +#define VK_BAR1_SOTP_REVID_MAX 2 +#define VK_BAR1_SOTP_REVID_ADDR (x) \ + (VK_BAR1_SOTP_REVID_BASE_ADDR + (x) * VK_BAR1_SOTP_REVID_SIZE) +/* VK device supports a maximum of 3 bars */ #define MAX_BAR 3
@@ -21,9 +198,82 @@ enum pci_barno {#define BCM_VK_NUM_TTY 2 +/* DAUTH related info */ +struct bcm_vk_dauth_key { +char store[VK_BAR1_DAUTH_STORE_SIZE ]; +char valid[VK_BAR1_DAUTH_VALID_SIZE ]; +}; + +struct bcm_vk_dauth_info { +struct bcm_vk_dauth_key keys[VK_BAR1_DAUTH_MAX ]; +}; +struct bcm_vk {struct pci_dev *pdev;void __iomem *bar[MAX_BAR ]; + +struct bcm_vk_dauth_info dauth_info; + +int devid;/* dev id allocated */ + +struct workqueue_struct *wq_thread; +struct work_struct wq_work;/* work queue for deferred job */ +unsigned long wq_offload[1 ];/* various flags on wq requested */ +void *tdma_vaddr;/* test dma segment virtual addr */ +dma_addr_t tdma_addr;/* test dma segment bus addr */ +}; + +/* wq offload work items bits definitions */ +enum bcm_vk_wq_offload_flags { +BCM_VK_WQ_DWNLD_PEND =0 , +BCM_VK_WQ_DWNLD_AUTO =1 , }; +/* +* check if PCIe interface is down on read. Use it when it is +* certain that _val should never be all ones. +*/ +#define BCM_VK_INTF_IS_DOWN (val) ((val) == 0xffffffff) + +static inline u32 vkread32 (struct bcm_vk *vk,enum pci_barno bar,u64 offset) +{ +return readl (vk->bar[bar] + offset); +} + +static inline void vkwrite32 (struct bcm_vk *vk, +u32 value, +enum pci_barno bar, +u64 offset) +{ +writel (value, vk->bar[bar] + offset); +} + +static inline u8 vkread8 (struct bcm_vk *vk,enum pci_barno bar,u64 offset) +{ +return readb (vk->bar[bar] + offset); +} + +static inline void vkwrite8 (struct bcm_vk *vk, +u8 value, +enum pci_barno bar, +u64 offset) +{ +writeb (value, vk->bar[bar] + offset); +} + +static inline bool bcm_vk_msgq_marker_valid (struct bcm_vk *vk) +{ +u32 rdy_marker =0 ; +u32 fw_status; + + fw_status =vkread32 (vk,BAR_0 ,VK_BAR_FWSTS ); + +if ((fw_status &VK_FWSTS_READY ) ==VK_FWSTS_READY ) + rdy_marker =vkread32 (vk,BAR_1 ,VK_BAR1_MSGQ_DEF_RDY ); + +return (rdy_marker ==VK_BAR1_MSGQ_RDY_MARKER ); +} + +int bcm_vk_auto_load_all_images (struct bcm_vk *vk); +#endif
drivers/misc/bcm-vk/bcm_vk_dev.c +723 -0
790 lines not on this page · raw message
Signature · 1 line
2.17.1
Scott Branden
maintainerPATCH v10 4/13 misc: bcm-vk: add misc device to Broadcom VK driver
In reply to Scott BrandenAdd 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.
--- drivers/misc/bcm-vk/bcm_vk.h | 2 ++ drivers/misc/bcm-vk/bcm_vk_dev.c | 36 +++++++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-)
drivers/misc/bcm-vk/bcm_vk.h +2 -0
@@ -7,6 +7,7 @@#define BCM_VK_H #include <linux/firmware.h> +#include <linux/miscdevice.h> #include <linux/pci.h> #include <linux/sched/signal.h>
@@ -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;
drivers/misc/bcm-vk/bcm_vk_dev.c +35 -1
@@ -7,6 +7,7 @@#include <linux/dma-mapping.h> #include <linux/firmware.h> #include <linux/fs.h> +#include <linux/idr.h> #include <linux/module.h> #include <linux/pci.h> #include <linux/pci_regs.h>
@@ -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);
Signature · 1 line
2.17.1
Scott Branden
maintainerPATCH v10 5/13 misc: bcm-vk: add triggers when host panic or reboots to notify card
In reply to Scott BrandenPass down an interrupt to card in case of panic or reboot so that card can take appropriate action to perform a clean reset. Uses kernel notifier block either directly (register on panic list), or implicitly (add shutdown method for PCI device).
--- drivers/misc/bcm-vk/bcm_vk.h | 2 ++ drivers/misc/bcm-vk/bcm_vk_dev.c | 29 ++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-)
drivers/misc/bcm-vk/bcm_vk.h +2 -0
@@ -223,6 +223,8 @@ struct bcm_vk {unsigned long wq_offload[1 ];/* various flags on wq requested */ void *tdma_vaddr;/* test dma segment virtual addr */ dma_addr_t tdma_addr;/* test dma segment bus addr */ + +struct notifier_block panic_nb; };/* wq offload work items bits definitions */
drivers/misc/bcm-vk/bcm_vk_dev.c +28 -1
@@ -635,6 +635,16 @@ static int bcm_vk_trigger_reset(struct bcm_vk *vk)return 0 ; } +static int bcm_vk_on_panic (struct notifier_block *nb, +unsigned long e,void *p) +{ + struct bcm_vk *vk = container_of(nb, struct bcm_vk, panic_nb); + +bcm_to_v_reset_doorbell (vk,VK_BAR0_RESET_DB_HARD ); + +return 0 ; +} +static int bcm_vk_probe (struct pci_dev *pdev,const struct pci_device_id *ent) {int err;
@@ -748,6 +758,15 @@ static int bcm_vk_probe(struct pci_dev *pdev, const struct pci_device_id *ent)/* sync other info */ bcm_vk_sync_card_info (vk); +/* register for panic notifier */ + vk->panic_nb.notifier_call = bcm_vk_on_panic; + err =atomic_notifier_chain_register (&panic_notifier_list, + &vk->panic_nb); +if (err) { +dev_err (dev,"Fail to register panic notifier\n" ); + goto err_destroy_workqueue; + } +/* * lets trigger an auto download. We don't want to do it serially here * because at probing time, it is not supposed to block for a long time.
@@ -756,7 +775,7 @@ static int bcm_vk_probe(struct pci_dev *pdev, const struct pci_device_id *ent)if (auto_load) {if ((boot_status &BOOT_STATE_MASK ) ==BROM_RUNNING ) {if (bcm_vk_trigger_autoload (vk)) - goto err_destroy_workqueue; + goto err_unregister_panic_notifier; }else { dev_err(dev, "Auto-load skipped - BROM not in proper state (0x%x)\n",
@@ -768,6 +787,10 @@ static int bcm_vk_probe(struct pci_dev *pdev, const struct pci_device_id *ent)return 0 ; +err_unregister_panic_notifier: +atomic_notifier_chain_unregister (&panic_notifier_list, + &vk->panic_nb); + err_destroy_workqueue:destroy_workqueue (vk->wq_thread);
@@ -818,6 +841,10 @@ static void bcm_vk_remove(struct pci_dev *pdev)bcm_vk_trigger_reset (vk);usleep_range (BCM_VK_UCODE_BOOT_US ,BCM_VK_UCODE_BOOT_MAX_US ); +/* unregister panic notifier */ +atomic_notifier_chain_unregister (&panic_notifier_list, + &vk->panic_nb); +if (vk->tdma_vaddr)dma_free_coherent (&pdev->dev, nr_scratch_pages *PAGE_SIZE , vk->tdma_vaddr, vk->tdma_addr);
Signature · 1 line
2.17.1
Scott Branden
maintainerPATCH v10 6/13 misc: bcm-vk: add open/release
In reply to Scott BrandenAdd open/release to replace private data with context for other methods to use. Reason for the context is because it is allowed for multiple sessions to open sysfs. For each file open, when upper layer queries the response, only those that are tied to a specified open should be returned.
--- drivers/misc/bcm-vk/Makefile | 4 +- drivers/misc/bcm-vk/bcm_vk.h | 15 ++++ drivers/misc/bcm-vk/bcm_vk_dev.c | 23 ++++++ drivers/misc/bcm-vk/bcm_vk_msg.c | 127 +++++++++++++++++++++++++++++++ drivers/misc/bcm-vk/bcm_vk_msg.h | 31 ++++++++ 5 files changed, 199 insertions(+), 1 deletion(-) create mode 100644 drivers/misc/bcm-vk/bcm_vk_msg.c create mode 100644 drivers/misc/bcm-vk/bcm_vk_msg.h
drivers/misc/bcm-vk/Makefile +3 -1
@@ -5,4 +5,6 @@ obj-$(CONFIG_BCM_VK) += bcm_vk.o bcm_vk-objs := \ - bcm_vk_dev.o + bcm_vk_dev.o \ + bcm_vk_msg.o +
drivers/misc/bcm-vk/bcm_vk.h +15 -0
@@ -7,9 +7,14 @@#define BCM_VK_H #include <linux/firmware.h> +#include <linux/kref.h> #include <linux/miscdevice.h> +#include <linux/mutex.h> #include <linux/pci.h> #include <linux/sched/signal.h> +#include <uapi/linux/misc/bcm_vk.h> + +#include "bcm_vk_msg.h" #define DRV_MODULE_NAME "bcm-vk"
@@ -218,6 +223,13 @@ struct bcm_vk {struct miscdevice miscdev;int devid;/* dev id allocated */ +/* Reference-counting to handle file operations */ +struct kref kref; + +spinlock_t ctx_lock;/* Spinlock for component context */ +struct bcm_vk_ctx ctx[VK_CMPT_CTX_MAX ]; +struct bcm_vk_ht_entry pid_ht[VK_PID_HT_SZ ]; +struct workqueue_struct *wq_thread;struct work_struct wq_work;/* work queue for deferred job */ unsigned long wq_offload[1 ];/* various flags on wq requested */
@@ -278,6 +290,9 @@ static inline bool bcm_vk_msgq_marker_valid(struct bcm_vk *vk) return (rdy_marker == VK_BAR1_MSGQ_RDY_MARKER); } +int bcm_vk_open (struct inode *inode,struct file *p_file); +int bcm_vk_release (struct inode *inode,struct file *p_file); +void bcm_vk_release_data (struct kref *kref);int bcm_vk_auto_load_all_images (struct bcm_vk *vk);#endif
drivers/misc/bcm-vk/bcm_vk_dev.c +23 -0
@@ -8,6 +8,7 @@#include <linux/firmware.h> #include <linux/fs.h> #include <linux/idr.h> +#include <linux/kref.h> #include <linux/module.h> #include <linux/pci.h> #include <linux/pci_regs.h>
@@ -635,6 +636,12 @@ static int bcm_vk_trigger_reset(struct bcm_vk *vk)return 0 ; } +static const struct file_operations bcm_vk_fops = { + .owner =THIS_MODULE , + .open = bcm_vk_open, + .release = bcm_vk_release, +}; +static int bcm_vk_on_panic (struct notifier_block *nb,unsigned long e,void *p) {
@@ -657,10 +664,13 @@ static int bcm_vk_probe(struct pci_dev *pdev, const struct pci_device_id *ent)struct miscdevice *misc_device;u32 boot_status; +/* allocate vk structure which is tied to kref for freeing */ vk =kzalloc (sizeof (*vk),GFP_KERNEL );if (!vk)return -ENOMEM ; +kref_init (&vk->kref); + err =pci_enable_device (pdev);if (err) {dev_err (dev,"Cannot enable PCI device\n" );
@@ -738,6 +748,7 @@ static int bcm_vk_probe(struct pci_dev *pdev, const struct pci_device_id *ent) err = -ENOMEM ; goto err_ida_remove; } + misc_device->fops = &bcm_vk_fops, err =misc_register (misc_device);if (err) {
@@ -826,6 +837,16 @@ static int bcm_vk_probe(struct pci_dev *pdev, const struct pci_device_id *ent)return err; } +void bcm_vk_release_data (struct kref *kref) +{ + struct bcm_vk *vk = container_of(kref, struct bcm_vk, kref); +struct pci_dev *pdev = vk->pdev; + +dev_dbg (&pdev->dev,"BCM-VK:%d release data 0x%p\n" , vk->devid, vk); +pci_dev_put (pdev); +kfree (vk); +} +static void bcm_vk_remove (struct pci_dev *pdev) {int i;
@@ -869,6 +890,8 @@ static void bcm_vk_remove(struct pci_dev *pdev)pci_release_regions (pdev);pci_free_irq_vectors (pdev);pci_disable_device (pdev); + +kref_put (&vk->kref, bcm_vk_release_data); }static void bcm_vk_shutdown (struct pci_dev *pdev)
drivers/misc/bcm-vk/bcm_vk_msg.c new file +127 -0
127 lines not on this page · raw message
drivers/misc/bcm-vk/bcm_vk_msg.h new file +31 -0
@@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright 2018-2020 Broadcom. +*/ + +#ifndef BCM_VK_MSG_H +#define BCM_VK_MSG_H + +/* context per session opening of sysfs */ +struct bcm_vk_ctx { +struct list_head node;/* use for linkage in Hash Table */ +unsigned int idx; +bool in_use; +pid_t pid; +u32 hash_idx; +struct miscdevice *miscdev; +}; + +/* pid hash table entry */ +struct bcm_vk_ht_entry { +struct list_head head; +}; + +/* total number of supported ctx, 32 ctx each for 5 components */ +#define VK_CMPT_CTX_MAX (32 * 5) + +/* hash table defines to store the opened FDs */ +#define VK_PID_HT_SHIFT_BIT 7/* 128 */ +#define VK_PID_HT_SZ BIT(VK_PID_HT_SHIFT_BIT) + +#endif
Signature · 1 line
2.17.1
Scott Branden
maintainerPATCH v10 7/13 misc: bcm-vk: add ioctl load_image
In reply to Scott BrandenAdd ioctl support to issue load_image operation to VK card.
--- drivers/misc/bcm-vk/bcm_vk.h | 3 + drivers/misc/bcm-vk/bcm_vk_dev.c | 95 ++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+)
drivers/misc/bcm-vk/bcm_vk.h +3 -0
@@ -12,6 +12,7 @@#include <linux/mutex.h> #include <linux/pci.h> #include <linux/sched/signal.h> +#include <linux/uaccess.h> #include <uapi/linux/misc/bcm_vk.h> #include "bcm_vk_msg.h"
@@ -220,6 +221,8 @@ struct bcm_vk {struct bcm_vk_dauth_info dauth_info; +/* mutex to protect the ioctls */ +struct mutex mutex;struct miscdevice miscdev;int devid;/* dev id allocated */
drivers/misc/bcm-vk/bcm_vk_dev.c +95 -0
123 lines not on this page · raw message
Signature · 1 line
2.17.1
Scott Branden
maintainerPATCH v10 8/13 misc: bcm-vk: add get_card_info, peerlog_info, and proc_mon_info
In reply to Scott BrandenAdd support to get card_info (details about card), peerlog_info (to get details of peerlog on card), and proc_mon_info (process monitoring on card).
This info is used for collection of logs via direct read of BAR space and by sysfs access (in a follow on commit).
--- drivers/misc/bcm-vk/bcm_vk.h | 60 ++++++++++++++++++ drivers/misc/bcm-vk/bcm_vk_dev.c | 105 +++++++++++++++++++++++++++++++ 2 files changed, 165 insertions(+)
drivers/misc/bcm-vk/bcm_vk.h +60 -0
@@ -205,6 +205,21 @@ enum pci_barno {#define BCM_VK_NUM_TTY 2 +/* VK device max power state, supports 3, full, reduced and low */ +#define MAX_OPP 3 +#define MAX_CARD_INFO_TAG_SIZE 64 + +struct bcm_vk_card_info { +u32 version; +char os_tag[MAX_CARD_INFO_TAG_SIZE ]; +char cmpt_tag[MAX_CARD_INFO_TAG_SIZE ]; +u32 cpu_freq_mhz; +u32 cpu_scale[MAX_OPP ]; +u32 ddr_freq_mhz; +u32 ddr_size_MB; +u32 video_core_freq_mhz; +}; +/* DAUTH related info */ struct bcm_vk_dauth_key {char store[VK_BAR1_DAUTH_STORE_SIZE ];
@@ -215,10 +230,49 @@ struct bcm_vk_dauth_info {struct bcm_vk_dauth_key keys[VK_BAR1_DAUTH_MAX ]; }; +/* +* Control structure of logging messages from the card. This +* buffer is for logmsg that comes from vk +*/ +struct bcm_vk_peer_log { +u32 rd_idx; +u32 wr_idx; +u32 buf_size; +u32 mask; +char data[0 ]; +}; + +/* max buf size allowed */ +#define BCM_VK_PEER_LOG_BUF_MAX SZ_16K +/* max size per line of peer log */ +#define BCM_VK_PEER_LOG_LINE_MAX 256 + +/* +* single entry for processing type + utilization +*/ +#define BCM_VK_PROC_TYPE_TAG_LEN 8 +struct bcm_vk_proc_mon_entry_t { +char tag[BCM_VK_PROC_TYPE_TAG_LEN ]; +u32 used; +u32 max;/**< max capacity */ +}; + +/** +* Structure for run time utilization +*/ +#define BCM_VK_PROC_MON_MAX 8/* max entries supported */ +struct bcm_vk_proc_mon_info { +u32 num;/**< no of entries */ +u32 entry_size;/**< per entry size */ +struct bcm_vk_proc_mon_entry_t entries[BCM_VK_PROC_MON_MAX ]; +}; +struct bcm_vk {struct pci_dev *pdev;void __iomem *bar[MAX_BAR ]; +struct bcm_vk_card_info card_info; +struct bcm_vk_proc_mon_info proc_mon_info;struct bcm_vk_dauth_info dauth_info;/* mutex to protect the ioctls */
@@ -240,6 +294,12 @@ struct bcm_vk {dma_addr_t tdma_addr;/* test dma segment bus addr */ struct notifier_block panic_nb; + +/* offset of the peer log control in BAR2 */ +u32 peerlog_off; +struct bcm_vk_peer_log peerlog_info;/* record of peer log info */ +/* offset of processing monitoring info in BAR2 */ +u32 proc_mon_off; };/* wq offload work items bits definitions */
drivers/misc/bcm-vk/bcm_vk_dev.c +105 -0
117 lines not on this page · raw message
Signature · 1 line
2.17.1
Scott Branden
maintainerPATCH v10 9/13 misc: bcm-vk: add VK messaging support
In reply to Scott BrandenAdd message support in order to be able to communicate to VK card via message queues.
This info is used for debug purposes via collection of logs via direct read of BAR space and by sysfs access (in a follow on commit).
--- drivers/misc/bcm-vk/Makefile | 3 +- drivers/misc/bcm-vk/bcm_vk.h | 123 +++ drivers/misc/bcm-vk/bcm_vk_dev.c | 311 +++++++- drivers/misc/bcm-vk/bcm_vk_msg.c | 1193 ++++++++++++++++++++++++++++++ drivers/misc/bcm-vk/bcm_vk_msg.h | 132 ++++ drivers/misc/bcm-vk/bcm_vk_sg.c | 275 +++++++ drivers/misc/bcm-vk/bcm_vk_sg.h | 61 ++ 7 files changed, 2095 insertions(+), 3 deletions(-) create mode 100644 drivers/misc/bcm-vk/bcm_vk_sg.c create mode 100644 drivers/misc/bcm-vk/bcm_vk_sg.h
drivers/misc/bcm-vk/Makefile +2 -1
@@ -6,5 +6,6 @@ obj-$(CONFIG_BCM_VK) += bcm_vk.o bcm_vk-objs := \ bcm_vk_dev.o \ - bcm_vk_msg.o + bcm_vk_msg.o \ + bcm_vk_sg.o
drivers/misc/bcm-vk/bcm_vk.h +123 -0
200 lines not on this page · raw message
drivers/misc/bcm-vk/bcm_vk_dev.c +309 -2
422 lines not on this page · raw message
drivers/misc/bcm-vk/bcm_vk_msg.c +1193 -0
1,235 lines not on this page · raw message
drivers/misc/bcm-vk/bcm_vk_msg.h +132 -0
155 lines not on this page · raw message
drivers/misc/bcm-vk/bcm_vk_sg.c new file +275 -0
275 lines not on this page · raw message
drivers/misc/bcm-vk/bcm_vk_sg.h new file +61 -0
61 lines not on this page · raw message
Signature · 1 line
2.17.1
Scott Branden
maintainerPATCH v10 10/13 misc: bcm-vk: reset_pid support
In reply to Scott BrandenAdd reset support via ioctl.
Kill user processes that are open when VK card is reset.
If a particular PID has issued the reset request do not kill that process as it issued the ioctl.
--- drivers/misc/bcm-vk/bcm_vk.h | 1 + drivers/misc/bcm-vk/bcm_vk_dev.c | 158 +++++++++++++++++++++++++++++-- drivers/misc/bcm-vk/bcm_vk_msg.c | 40 +++++++- 3 files changed, 191 insertions(+), 8 deletions(-)
drivers/misc/bcm-vk/bcm_vk.h +1 -0
@@ -468,6 +468,7 @@ irqreturn_t bcm_vk_msgq_irqhandler(int irq, void *dev_id);irqreturn_t bcm_vk_notf_irqhandler (int irq,void *dev_id);int bcm_vk_msg_init (struct bcm_vk *vk);void bcm_vk_msg_remove (struct bcm_vk *vk); +void bcm_vk_drain_msg_on_reset (struct bcm_vk *vk);int bcm_vk_sync_msgq (struct bcm_vk *vk,bool force_sync);void bcm_vk_blk_drv_access (struct bcm_vk *vk);s32 bcm_to_h_msg_dequeue (struct bcm_vk *vk);
drivers/misc/bcm-vk/bcm_vk_dev.c +152 -6
216 lines not on this page · raw message
drivers/misc/bcm-vk/bcm_vk_msg.c +38 -2
@@ -215,6 +215,15 @@ static struct bcm_vk_ctx *bcm_vk_get_ctx(struct bcm_vk *vk, const pid_t pid)spin_lock (&vk->ctx_lock); +/* check if it is in reset, if so, don't allow */ +if (vk->reset_pid) { +dev_err (&vk->pdev->dev, +"No context allowed during reset by pid %d\n" , + vk->reset_pid); + + goto in_reset_exit; + } +for (i =0 ; i <ARRAY_SIZE (vk->ctx); i++) {if (!vk->ctx[i].in_use) { vk->ctx[i].in_use = true;
@@ -243,6 +252,7 @@ static struct bcm_vk_ctx *bcm_vk_get_ctx(struct bcm_vk *vk, const pid_t pid)init_waitqueue_head (&ctx->rd_wq); all_in_use_exit: +in_reset_exit:spin_unlock (&vk->ctx_lock);return ctx;
@@ -387,6 +397,12 @@ static void bcm_vk_drain_all_pend(struct device *dev, num, ctx->idx); } +void bcm_vk_drain_msg_on_reset (struct bcm_vk *vk) +{ +bcm_vk_drain_all_pend (&vk->pdev->dev, &vk->to_v_msg_chan,NULL ); +bcm_vk_drain_all_pend (&vk->pdev->dev, &vk->to_h_msg_chan,NULL ); +} +/* * Function to sync up the messages queue info that is provided by BAR1 */
@@ -718,13 +734,22 @@ static int bcm_vk_handle_last_sess(struct bcm_vk *vk, const pid_t pid,/* * don't send down or do anything if message queue is not initialized +* and if it is the reset session, clear it. */ -if (!bcm_vk_drv_access_ok (vk)) +if (!bcm_vk_drv_access_ok (vk)) { +if (vk->reset_pid == pid) + vk->reset_pid =0 ;return -EPERM ; + }dev_dbg (dev,"No more sessions, shut down pid %d\n" , pid); - rc =bcm_vk_send_shutdown_msg (vk,VK_SHUTDOWN_PID , pid, q_num); +/* only need to do it if it is not the reset process */ +if (vk->reset_pid != pid) + rc =bcm_vk_send_shutdown_msg (vk,VK_SHUTDOWN_PID , pid, q_num); +else +/* put reset_pid to 0 if it is exiting last session */ + vk->reset_pid =0 ;return rc; }
@@ -1128,6 +1153,17 @@ ssize_t bcm_vk_write(struct file *p_file,int dir;struct _vk_data *data; +/* +* check if we are in reset, if so, no buffer transfer is +* allowed and return error. +*/ +if (vk->reset_pid) { +dev_dbg (dev,"No Transfer allowed during reset, pid %d.\n" , + ctx->pid); + rc = -EACCES ; + goto write_free_msgid; + } + num_planes = entry->to_v_msg[0 ].cmd &VK_CMD_PLANES_MASK ;if ((entry->to_v_msg[0 ].cmd &VK_CMD_MASK ) ==VK_CMD_DOWNLOAD ) dir =DMA_FROM_DEVICE ;
Signature · 1 line
2.17.1
Scott Branden
maintainerPATCH v10 11/13 misc: bcm-vk: add mmap function for exposing BAR2
In reply to Scott BrandenAdd mmap function that allows host application to open up BAR2 memory for remote spooling out messages from the VK logger.
--- drivers/misc/bcm-vk/bcm_vk_dev.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
drivers/misc/bcm-vk/bcm_vk_dev.c +24 -0
@@ -1199,6 +1199,29 @@ static long bcm_vk_reset(struct bcm_vk *vk, struct vk_reset __user *arg)return ret; } +static int bcm_vk_mmap (struct file *file,struct vm_area_struct *vma) +{ +struct bcm_vk_ctx *ctx = file->private_data; + struct bcm_vk *vk = container_of(ctx->miscdev, struct bcm_vk, miscdev); +unsigned long pg_size; + +/* only BAR2 is mmap possible, which is bar num 4 due to 64bit */ +#define VK_MMAPABLE_BAR 4 + + pg_size = ((pci_resource_len (vk->pdev,VK_MMAPABLE_BAR ) -1 ) + >>PAGE_SHIFT ) +1 ; +if (vma->vm_pgoff +vma_pages (vma) > pg_size) +return -EINVAL ; + + vma->vm_pgoff += (pci_resource_start (vk->pdev,VK_MMAPABLE_BAR ) + >>PAGE_SHIFT ); + vma->vm_page_prot =pgprot_noncached (vma->vm_page_prot); + +return io_remap_pfn_range (vma, vma->vm_start, vma->vm_pgoff, + vma->vm_end - vma->vm_start, + vma->vm_page_prot); +} +static long bcm_vk_ioctl (struct file *file,unsigned int cmd,unsigned long arg) {long ret = -EINVAL ;
@@ -1237,6 +1260,7 @@ static const struct file_operations bcm_vk_fops = { .write = bcm_vk_write, .poll = bcm_vk_poll, .release = bcm_vk_release, + .mmap = bcm_vk_mmap, .unlocked_ioctl = bcm_vk_ioctl, };
Signature · 1 line
2.17.1
Scott Branden
maintainerPATCH v10 12/13 MAINTAINERS: bcm-vk: add maintainer for Broadcom VK Driver
In reply to Scott BrandenAdd maintainer entry for new Broadcom VK Driver
--- MAINTAINERS | 7 +++++++ 1 file changed, 7 insertions(+)
MAINTAINERS +7 -0
@@ -3744,6 +3744,13 @@ L: [email protected] S: Supported F: drivers/net/ethernet/broadcom/tg3.* +BROADCOM VK DRIVER +M: Scott Branden <[email protected]> +L: [email protected] +S: Supported +F: drivers/misc/bcm-vk/ +F: include/uapi/linux/misc/bcm_vk.h + BROCADE BFA FC SCSI DRIVER M: Anil Gurumurthy <[email protected]> M: Sudarsana Kalluru <[email protected]>
Signature · 1 line
2.17.1
Scott Branden
maintainerPATCH v10 13/13 misc: bcm-vk: add ttyVK support
In reply to Scott BrandenAdd ttyVK support to driver to allow console access to VK card from host.
Device node will be in the follow form /dev/bcm-vk.x_ttyVKy where:
x is the instance of the VK card
y is the tty device number on the VK card
--- drivers/misc/bcm-vk/Makefile | 1 + drivers/misc/bcm-vk/bcm_vk.h | 28 +++ drivers/misc/bcm-vk/bcm_vk_dev.c | 41 +++- drivers/misc/bcm-vk/bcm_vk_tty.c | 333 +++++++++++++++++++++++++++++++ 4 files changed, 402 insertions(+), 1 deletion(-) create mode 100644 drivers/misc/bcm-vk/bcm_vk_tty.c
drivers/misc/bcm-vk/Makefile +1 -0
@@ -9,3 +9,4 @@ bcm_vk-objs := \ bcm_vk_msg.o \ bcm_vk_sg.o +bcm_vk-$(CONFIG_TTY) += bcm_vk_tty.o
drivers/misc/bcm-vk/bcm_vk.h +28 -0
@@ -8,12 +8,14 @@#include <linux/atomic.h> #include <linux/firmware.h> +#include <linux/irq.h> #include <linux/kref.h> #include <linux/miscdevice.h> #include <linux/mutex.h> #include <linux/pci.h> #include <linux/poll.h> #include <linux/sched/signal.h> +#include <linux/tty.h> #include <linux/uaccess.h> #include <uapi/linux/misc/bcm_vk.h>
@@ -84,6 +86,9 @@#define CODEPUSH_BOOT2_ENTRY 0x60000000#define BAR_CARD_STATUS 0x410 +/* CARD_STATUS definitions */ +#define CARD_STATUS_TTYVK0_READY BIT(0) +#define CARD_STATUS_TTYVK1_READY BIT(1)#define BAR_BOOT1_STDALONE_PROGRESS 0x420#define BOOT1_STDALONE_SUCCESS (BIT(13) | BIT(14))
@@ -255,6 +260,19 @@ enum pci_barno {#define BCM_VK_NUM_TTY 2 +struct bcm_vk_tty { +struct tty_port port; +u32 to_offset;/* bar offset to use */ +u32 to_size;/* to VK buffer size */ +u32 wr;/* write offset shadow */ +u32 from_offset;/* bar offset to use */ +u32 from_size;/* from VK buffer size */ +u32 rd;/* read offset shadow */ +pid_t pid; +bool irq_enabled; +bool is_opened;/* tracks tty open/close */ +}; +/* VK device max power state, supports 3, full, reduced and low */ #define MAX_OPP 3#define MAX_CARD_INFO_TAG_SIZE 64
@@ -348,6 +366,12 @@ struct bcm_vk {struct miscdevice miscdev;int devid;/* dev id allocated */ +struct tty_driver *tty_drv; +struct timer_list serial_timer; +struct bcm_vk_tty tty[BCM_VK_NUM_TTY ]; +struct workqueue_struct *tty_wq_thread; +struct work_struct tty_wq_work; +/* Reference-counting to handle file operations */ struct kref kref;
@@ -466,6 +490,7 @@ int bcm_vk_release(struct inode *inode, struct file *p_file);void bcm_vk_release_data (struct kref *kref);irqreturn_t bcm_vk_msgq_irqhandler (int irq,void *dev_id);irqreturn_t bcm_vk_notf_irqhandler (int irq,void *dev_id); +irqreturn_t bcm_vk_tty_irqhandler (int irq,void *dev_id);int bcm_vk_msg_init (struct bcm_vk *vk);void bcm_vk_msg_remove (struct bcm_vk *vk);void bcm_vk_drain_msg_on_reset (struct bcm_vk *vk);
@@ -476,6 +501,9 @@ int bcm_vk_send_shutdown_msg(struct bcm_vk *vk, u32 shut_type, const pid_t pid, const u32 q_num);void bcm_to_v_q_doorbell (struct bcm_vk *vk,u32 q_num,u32 db_val);int bcm_vk_auto_load_all_images (struct bcm_vk *vk); +int bcm_vk_tty_init (struct bcm_vk *vk,char *name); +void bcm_vk_tty_exit (struct bcm_vk *vk); +void bcm_vk_tty_terminate_tty_user (struct bcm_vk *vk);void bcm_vk_hb_init (struct bcm_vk *vk);void bcm_vk_hb_deinit (struct bcm_vk *vk);void bcm_vk_handle_notf (struct bcm_vk *vk);
drivers/misc/bcm-vk/bcm_vk_dev.c +40 -1
84 lines not on this page · raw message
drivers/misc/bcm-vk/bcm_vk_tty.c new file +333 -0
333 lines not on this page · raw message
Signature · 1 line
2.17.1
Scott,
Quoted 9 lines · Scott Branden
This patch series drops previous patches in [1] that were incorporated by Kees Cook into patch series "Introduce partial
kernel_read_file()support" [2].Remaining patches are contained in this series to add Broadcom VK driver. (which depends on
request_firmware_into_bufAPI addition which has now been accepted into the upstream kernel as of v5.10-rc1).
Quoted 8 lines
[1] https://lore.kernel.org/lkml/[email protected]/
[2] https://lore.kernel.org/lkml/[email protected]/Changes from v9:
- fix compile ifCONFIG_TTYnot set
- use if-else statement instead of conditional expression inset_q_num
- generatebcm_vk_msg_removecall in proper patch
(was generated in tty patch when should be in msg patch)
Did I miss something? Greg already applied v9, so any fixes on top needs to be new patches.
-Olof
Scott Branden
maintainerQuoted 15 lines · Olof Johansson
Scott,
Quoted 11 lines · Scott Branden
This patch series drops previous patches in [1] that were incorporated by Kees Cook into patch series "Introduce partial
kernel_read_file()support" [2].Remaining patches are contained in this series to add Broadcom VK driver. (which depends on
request_firmware_into_bufAPI addition which has now been accepted into the upstream kernel as of v5.10-rc1).[1] https://lore.kernel.org/lkml/[email protected]/
[2] https://lore.kernel.org/lkml/[email protected]/
Quoted 7 lines
Quoted 5 lines
Changes from v9:
- fix compile ifCONFIG_TTYnot set
- use if-else statement instead of conditional expression inset_q_num
- generatebcm_vk_msg_removecall in proper patch
(was generated in tty patch when should be in msg patch)Did I miss something? Greg already applied v9, so any fixes on top needs to be new patches.
Sorry, was unfamiliar with the process of having changes in linux-next needing correcting. I sent out new patches to correct these issues against linux-next now.
Quoted 3 lines
-Olof
Thanks for providing correct process.
Scott