Add Broadcom VK driver
Subsystems (2)
Scott Branden
maintainerv5 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 in other patch series [2] being applied first).
Please note this patch series will not compile without [2].
[1] https://lore.kernel.org/lkml/[email protected]/
[2] https://lore.kernel.org/lkml/[email protected]/
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 (15):
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 BCM_VK_QSTATS
misc: bcm-vk: add sysfs interface
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 | 29 + drivers/misc/bcm-vk/Makefile | 13 + drivers/misc/bcm-vk/README | 99 ++ drivers/misc/bcm-vk/bcm_vk.h | 510 +++++++++ drivers/misc/bcm-vk/bcm_vk_dev.c | 1634 ++++++++++++++++++++++++++++ drivers/misc/bcm-vk/bcm_vk_msg.c | 1363 +++++++++++++++++++++++ drivers/misc/bcm-vk/bcm_vk_msg.h | 169 +++ drivers/misc/bcm-vk/bcm_vk_sg.c | 275 +++++ drivers/misc/bcm-vk/bcm_vk_sg.h | 61 ++ drivers/misc/bcm-vk/bcm_vk_sysfs.c | 1411 ++++++++++++++++++++++++ drivers/misc/bcm-vk/bcm_vk_tty.c | 333 ++++++ include/uapi/linux/misc/bcm_vk.h | 84 ++ 15 files changed, 5990 insertions(+) create mode 100644 drivers/misc/bcm-vk/Kconfig create mode 100644 drivers/misc/bcm-vk/Makefile create mode 100644 drivers/misc/bcm-vk/README 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_sysfs.c 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 v5 1/15 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 v5 2/15 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 | 15 ++++ drivers/misc/bcm-vk/Makefile | 8 ++ drivers/misc/bcm-vk/bcm_vk.h | 29 +++++++ drivers/misc/bcm-vk/bcm_vk_dev.c | 140 +++++++++++++++++++++++++++++++ 6 files changed, 194 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
@@ -469,6 +469,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
@@ -52,6 +52,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 +15 -0
@@ -0,0 +1,15 @@ +# 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 + specific offload processing. + 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 +140 -0
140 lines not on this page · raw message
Signature · 1 line
2.17.1
Scott Branden
maintainerPATCH v5 3/15 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 | 718 +++++++++++++++++++++++++++++++ 2 files changed, 968 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 +718 -0
785 lines not on this page · raw message
Signature · 1 line
2.17.1
kernel test robot
build botRe: [PATCH v5 03/15] misc: bcm-vk: add autoload support
I love your patch! Yet something to improve:
Hi Scott,
I love your patch! Yet something to improve:
[auto build test ERROR on char-misc/char-misc-testing]
[also build test ERROR on soc/for-next kees/for-next/pstore linus/master v5.9-rc7 next-20200930] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Scott-Branden/Add-Broadcom-VK-driver/20201001-093119 base: https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc.git c471bf4b11c7df0f0f9f42b5aeec424dc62d0c7e config: powerpc-allyesconfig (attached as .config) compiler: powerpc64-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/f04a1673933a1af94e44bc650533bbb271e3dcc1
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Scott-Branden/Add-Broadcom-VK-driver/20201001-093119 git checkout f04a1673933a1af94e44bc650533bbb271e3dcc1
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=powerpc
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
drivers/misc/bcm-vk/bcm_vk_dev.c: In function 'bcm_vk_load_image_by_type':
>> drivers/misc/bcm-vk/bcm_vk_dev.c:284:8: error: implicit declaration of function 'request_partial_firmware_into_buf'; did you mean 'request_firmware_into_buf'? [-Werror=implicit-function-declaration]
284 | ret = request_partial_firmware_into_buf(&fw, filename, dev,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| request_firmware_into_bufcc1: some warnings being treated as errors
vim +284 drivers/misc/bcm-vk/bcm_vk_dev.c
206
207 static int bcm_vk_load_image_by_type(struct bcm_vk *vk, u32 load_type,
208 const char *filename)
209 {
210 struct device *dev = &vk->pdev->dev;
211 const struct firmware *fw = NULL;
212 void *bufp = NULL;
213 size_t max_buf, offset;
214 int ret;
215 u64 offset_codepush;
216 u32 codepush;
217 u32 value;
218 dma_addr_t boot_dma_addr;
219 bool is_stdalone;
220
221 if (load_type == VK_IMAGE_TYPE_BOOT1) {
222 /*
223 * After POR, enable VK soft BOOTSRC so bootrom do not clear
224 * the pushed image (the TCM memories).
225 */
226 value = vkread32(vk, BAR_0, BAR_BOOTSRC_SELECT);
227 value |= BOOTSRC_SOFT_ENABLE;
228 vkwrite32(vk, value, BAR_0, BAR_BOOTSRC_SELECT);
229
230 codepush = CODEPUSH_BOOTSTART + CODEPUSH_BOOT1_ENTRY;
231 offset_codepush = BAR_CODEPUSH_SBL;
232
233 /* Write a 1 to request SRAM open bit */
234 vkwrite32(vk, CODEPUSH_BOOTSTART, BAR_0, offset_codepush);
235
236 /* Wait for VK to respond */
237 ret = bcm_vk_wait(vk, BAR_0, BAR_BOOT_STATUS, SRAM_OPEN,
238 SRAM_OPEN, LOAD_IMAGE_TIMEOUT_MS);
239 if (ret < 0) {
240 dev_err(dev, "boot1 wait SRAM err - ret(%d)\n", ret);
241 goto err_buf_out;
242 }
243
244 max_buf = SZ_256K;
245 bufp = dma_alloc_coherent(dev,
246 max_buf,
247 &boot_dma_addr, GFP_KERNEL);
248 if (!bufp) {
249 dev_err(dev, "Error allocating 0x%zx\n", max_buf);
250 ret = -ENOMEM;
251 goto err_buf_out;
252 }
253 } else if (load_type == VK_IMAGE_TYPE_BOOT2) {
254 codepush = CODEPUSH_BOOT2_ENTRY;
255 offset_codepush = BAR_CODEPUSH_SBI;
256
257 /* Wait for VK to respond */
258 ret = bcm_vk_wait(vk, BAR_0, BAR_BOOT_STATUS, DDR_OPEN,
259 DDR_OPEN, LOAD_IMAGE_TIMEOUT_MS);
260 if (ret < 0) {
261 dev_err(dev, "boot2 wait DDR open error - ret(%d)\n",
262 ret);
263 goto err_buf_out;
264 }
265
266 max_buf = SZ_4M;
267 bufp = dma_alloc_coherent(dev,
268 max_buf,
269 &boot_dma_addr, GFP_KERNEL);
270 if (!bufp) {
271 dev_err(dev, "Error allocating 0x%zx\n", max_buf);
272 ret = -ENOMEM;
273 goto err_buf_out;
274 }
275
276 bcm_vk_buf_notify(vk, bufp, boot_dma_addr, max_buf);
277 } else {
278 dev_err(dev, "Error invalid image type 0x%x\n", load_type);
279 ret = -EINVAL;
280 goto err_buf_out;
281 }
282
283 offset = 0;
> 284 ret = request_partial_firmware_into_buf(&fw, filename, dev,
285 bufp, max_buf, offset);
286 if (ret) {
287 dev_err(dev, "Error %d requesting firmware file: %s\n",
288 ret, filename);
289 goto err_firmware_out;
290 }
291 dev_dbg(dev, "size=0x%zx\n", fw->size);
292 if (load_type == VK_IMAGE_TYPE_BOOT1)
293 memcpy_toio(vk->bar[BAR_1] + BAR1_CODEPUSH_BASE_BOOT1,
294 bufp,
295 fw->size);
296
297 dev_dbg(dev, "Signaling 0x%x to 0x%llx\n", codepush, offset_codepush);
298 vkwrite32(vk, codepush, BAR_0, offset_codepush);
299
300 if (load_type == VK_IMAGE_TYPE_BOOT1) {
301 u32 boot_status;
302
303 /* wait until done */
304 ret = bcm_vk_wait(vk, BAR_0, BAR_BOOT_STATUS,
305 BOOT1_RUNNING,
306 BOOT1_RUNNING,
307 BOOT1_STARTUP_TIMEOUT_MS);
308
309 boot_status = vkread32(vk, BAR_0, BAR_BOOT_STATUS);
310 is_stdalone = !BCM_VK_INTF_IS_DOWN(boot_status) &&
311 (boot_status & BOOT_STDALONE_RUNNING);
312 if (ret && !is_stdalone) {
313 dev_err(dev,
314 "Timeout %ld ms waiting for boot1 to come up - ret(%d)\n",
315 BOOT1_STARTUP_TIMEOUT_MS, ret);
316 goto err_firmware_out;
317 } else if (is_stdalone) {
318 u32 reg;
319
320 reg = vkread32(vk, BAR_0, BAR_BOOT1_STDALONE_PROGRESS);
321 if ((reg & BOOT1_STDALONE_PROGRESS_MASK) ==
322 BOOT1_STDALONE_SUCCESS) {
323 dev_info(dev, "Boot1 standalone success\n");
324 ret = 0;
325 } else {
326 dev_err(dev, "Timeout %ld ms - Boot1 standalone failure\n",
327 BOOT1_STARTUP_TIMEOUT_MS);
328 ret = -EINVAL;
329 goto err_firmware_out;
330 }
331 }
332 } else if (load_type == VK_IMAGE_TYPE_BOOT2) {
333 unsigned long timeout;
334
335 timeout = jiffies + msecs_to_jiffies(LOAD_IMAGE_TIMEOUT_MS);
336
337 /* To send more data to VK than max_buf allowed at a time */
338 do {
339 /*
340 * Check for ack from card. when Ack is received,
341 * it means all the data is received by card.
342 * Exit the loop after ack is received.
343 */
344 ret = bcm_vk_wait(vk, BAR_0, BAR_BOOT_STATUS,
345 FW_LOADER_ACK_RCVD_ALL_DATA,
346 FW_LOADER_ACK_RCVD_ALL_DATA,
347 TXFR_COMPLETE_TIMEOUT_MS);
348 if (ret == 0) {
349 dev_dbg(dev, "Exit boot2 download\n");
350 break;
351 } else if (ret == -EFAULT) {
352 dev_err(dev, "Error detected during ACK waiting");
353 goto err_firmware_out;
354 }
355
356 /* exit the loop, if there is no response from card */
357 if (time_after(jiffies, timeout)) {
358 dev_err(dev, "Error. No reply from card\n");
359 ret = -ETIMEDOUT;
360 goto err_firmware_out;
361 }
362
363 /* Wait for VK to open BAR space to copy new data */
364 ret = bcm_vk_wait(vk, BAR_0, offset_codepush,
365 codepush, 0,
366 TXFR_COMPLETE_TIMEOUT_MS);
367 if (ret == 0) {
368 offset += max_buf;
369 ret = request_partial_firmware_into_buf
370 (&fw,
371 filename,
372 dev, bufp,
373 max_buf,
374 offset);
375 if (ret) {
376 dev_err(dev,
377 "Error %d requesting firmware file: %s offset: 0x%zx\n",
378 ret, filename, offset);
379 goto err_firmware_out;
380 }
381 dev_dbg(dev, "size=0x%zx\n", fw->size);
382 dev_dbg(dev, "Signaling 0x%x to 0x%llx\n",
383 codepush, offset_codepush);
384 vkwrite32(vk, codepush, BAR_0, offset_codepush);
385 /* reload timeout after every codepush */
386 timeout = jiffies +
387 msecs_to_jiffies(LOAD_IMAGE_TIMEOUT_MS);
388 } else if (ret == -EFAULT) {
389 dev_err(dev, "Error detected waiting for transfer\n");
390 goto err_firmware_out;
391 }
392 } while (1);
393
394 /* wait for fw status bits to indicate app ready */
395 ret = bcm_vk_wait(vk, BAR_0, VK_BAR_FWSTS,
396 VK_FWSTS_READY,
397 VK_FWSTS_READY,
398 BOOT2_STARTUP_TIMEOUT_MS); 399 if (ret < 0) {
400 dev_err(dev, "Boot2 not ready - ret(%d)\n", ret);
401 goto err_firmware_out;
402 }
403
404 is_stdalone = vkread32(vk, BAR_0, BAR_BOOT_STATUS) &
405 BOOT_STDALONE_RUNNING;
406 if (!is_stdalone) {
407 ret = bcm_vk_intf_ver_chk(vk);
408 if (ret) {
409 dev_err(dev, "failure in intf version check\n");
410 goto err_firmware_out;
411 }
412
413 /* sync & channel other info */
414 ret = bcm_vk_sync_card_info(vk);
415 if (ret) {
416 dev_err(dev, "Syncing Card Info failure\n");
417 goto err_firmware_out;
418 }
419 }
420 }
421
422 err_firmware_out:
423 release_firmware(fw);
424
425 err_buf_out:
426 if (bufp)
427 dma_free_coherent(dev, max_buf, bufp, boot_dma_addr);
428
429 return ret;
430 }
431
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]
Scott Branden
maintainerRe: [PATCH v5 03/15] misc: bcm-vk: add autoload support
Quoted 7 lines · kernel test robot
Hi Scott,
I love your patch! Yet something to improve:
[auto build test ERROR on char-misc/char-misc-testing]
[also build test ERROR on soc/for-next kees/for-next/pstore linus/master v5.9-rc7 next-20200930] [If your patch is applied to the wrong git tree, kindly drop us a note.
Yes, this patch series will not compile as described in the cover letter without Kees' patches:
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 in other patch series [2] being applied first).
Please note this patch series will not compile without [2].
[1] https://lore.kernel.org/lkml/20200706232309.12010-1-scott.branden(a)broadcom.com/
[2] https://lore.kernel.org/lkml/20200729175845.1745471-1-keescook(a)chromium.org/
Quoted 261 lines
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]url: https://github.com/0day-ci/linux/commits/Scott-Branden/Add-Broadcom-VK-driver/20201001-093119 base: https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc.git c471bf4b11c7df0f0f9f42b5aeec424dc62d0c7e config: powerpc-allyesconfig (attached as .config) compiler: powerpc64-linux-gcc (GCC) 9.3.0reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/f04a1673933a1af94e44bc650533bbb271e3dcc1
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Scott-Branden/Add-Broadcom-VK-driver/20201001-093119 git checkoutf04a1673933a1af94e44bc650533bbb271e3dcc1
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=powerpcIf you fix the issue, kindly add following tag as appropriate
Reported-by kernel test robot <[email protected]>All errors (new ones prefixed by >>):
drivers/misc/bcm-vk/bcm_vk_dev.c: In function 'bcm_vk_load_image_by_type':Quoted 1 line
Quoted 1 line
drivers/misc/bcm-vk/bcm_vk_dev.c:284:8: error: implicit declaration of function 'request_partial_firmware_into_buf'; did you mean 'request_firmware_into_buf'? [-Werror=implicit-function-declaration]284 | ret = request_partial_firmware_into_buf(&fw, filename, dev, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | request_firmware_into_bufcc1: some warnings being treated as errors
vim +284
drivers/misc/bcm-vk/bcm_vk_dev.c206 207 static int bcm_vk_load_image_by_type(struct bcm_vk *vk, u32 load_type, 208 const char *filename) 209 { 210 struct device *dev = &vk->pdev->dev; 211 const struct firmware *fw = NULL; 212 void *bufp = NULL; 213 size_t max_buf, offset; 214 int ret; 215 u64 offset_codepush; 216 u32 codepush; 217 u32 value; 218 dma_addr_t boot_dma_addr; 219 bool is_stdalone; 220 221 if (load_type == VK_IMAGE_TYPE_BOOT1) { 222 /* 223 * After POR, enable VK soft BOOTSRC so bootrom do not clear 224 * the pushed image (the TCM memories). 225 */ 226 value = vkread32(vk, BAR_0, BAR_BOOTSRC_SELECT); 227 value |= BOOTSRC_SOFT_ENABLE; 228 vkwrite32(vk, value, BAR_0, BAR_BOOTSRC_SELECT); 229 230 codepush = CODEPUSH_BOOTSTART + CODEPUSH_BOOT1_ENTRY; 231 offset_codepush = BAR_CODEPUSH_SBL; 232 233 /* Write a 1 to request SRAM open bit */ 234 vkwrite32(vk, CODEPUSH_BOOTSTART, BAR_0, offset_codepush); 235 236 /* Wait for VK to respond */ 237 ret = bcm_vk_wait(vk, BAR_0, BAR_BOOT_STATUS, SRAM_OPEN, 238 SRAM_OPEN, LOAD_IMAGE_TIMEOUT_MS); 239 if (ret < 0) { 240 dev_err(dev, "boot1 wait SRAM err - ret(%d)\n", ret); 241 goto err_buf_out; 242 } 243 244 max_buf = SZ_256K; 245 bufp = dma_alloc_coherent(dev, 246 max_buf, 247 &boot_dma_addr, GFP_KERNEL); 248 if (!bufp) { 249 dev_err(dev, "Error allocating 0x%zx\n", max_buf); 250 ret = -ENOMEM; 251 goto err_buf_out; 252 } 253 } else if (load_type == VK_IMAGE_TYPE_BOOT2) { 254 codepush = CODEPUSH_BOOT2_ENTRY; 255 offset_codepush = BAR_CODEPUSH_SBI; 256 257 /* Wait for VK to respond */ 258 ret = bcm_vk_wait(vk, BAR_0, BAR_BOOT_STATUS, DDR_OPEN, 259 DDR_OPEN, LOAD_IMAGE_TIMEOUT_MS); 260 if (ret < 0) { 261 dev_err(dev, "boot2 wait DDR open error - ret(%d)\n", 262 ret); 263 goto err_buf_out; 264 } 265 266 max_buf = SZ_4M; 267 bufp = dma_alloc_coherent(dev, 268 max_buf, 269 &boot_dma_addr, GFP_KERNEL); 270 if (!bufp) { 271 dev_err(dev, "Error allocating 0x%zx\n", max_buf); 272 ret = -ENOMEM; 273 goto err_buf_out; 274 } 275 276 bcm_vk_buf_notify(vk, bufp, boot_dma_addr, max_buf); 277 } else { 278 dev_err(dev, "Error invalid image type 0x%x\n", load_type); 279 ret = -EINVAL; 280 goto err_buf_out; 281 } 282 283 offset = 0;Quoted 1 line
284 ret = request_partial_firmware_into_buf(&fw, filename, dev,
285 bufp, max_buf, offset); 286 if (ret) { 287 dev_err(dev, "Error %d requesting firmware file: %s\n", 288 ret, filename); 289 goto err_firmware_out; 290 } 291 dev_dbg(dev, "size=0x%zx\n", fw->size); 292 if (load_type == VK_IMAGE_TYPE_BOOT1) 293 memcpy_toio(vk->bar[BAR_1] + BAR1_CODEPUSH_BASE_BOOT1, 294 bufp, 295 fw->size); 296 297 dev_dbg(dev, "Signaling 0x%x to 0x%llx\n", codepush, offset_codepush); 298 vkwrite32(vk, codepush, BAR_0, offset_codepush); 299 300 if (load_type == VK_IMAGE_TYPE_BOOT1) { 301 u32 boot_status; 302 303 /* wait until done */ 304 ret = bcm_vk_wait(vk, BAR_0, BAR_BOOT_STATUS, 305 BOOT1_RUNNING, 306 BOOT1_RUNNING, 307 BOOT1_STARTUP_TIMEOUT_MS); 308 309 boot_status = vkread32(vk, BAR_0, BAR_BOOT_STATUS); 310 is_stdalone = !BCM_VK_INTF_IS_DOWN(boot_status) && 311 (boot_status & BOOT_STDALONE_RUNNING); 312 if (ret && !is_stdalone) { 313 dev_err(dev, 314 "Timeout %ld ms waiting for boot1 to come up - ret(%d)\n", 315 BOOT1_STARTUP_TIMEOUT_MS, ret); 316 goto err_firmware_out; 317 } else if (is_stdalone) { 318 u32 reg; 319 320 reg = vkread32(vk, BAR_0, BAR_BOOT1_STDALONE_PROGRESS); 321 if ((reg & BOOT1_STDALONE_PROGRESS_MASK) == 322 BOOT1_STDALONE_SUCCESS) { 323 dev_info(dev, "Boot1 standalone success\n"); 324 ret = 0; 325 } else { 326 dev_err(dev, "Timeout %ld ms - Boot1 standalone failure\n", 327 BOOT1_STARTUP_TIMEOUT_MS); 328 ret = -EINVAL; 329 goto err_firmware_out; 330 } 331 } 332 } else if (load_type == VK_IMAGE_TYPE_BOOT2) { 333 unsigned long timeout; 334 335 timeout = jiffies + msecs_to_jiffies(LOAD_IMAGE_TIMEOUT_MS); 336 337 /* To send more data to VK than max_buf allowed at a time */ 338 do { 339 /* 340 * Check for ack from card. when Ack is received, 341 * it means all the data is received by card. 342 * Exit the loop after ack is received. 343 */ 344 ret = bcm_vk_wait(vk, BAR_0, BAR_BOOT_STATUS, 345 FW_LOADER_ACK_RCVD_ALL_DATA, 346 FW_LOADER_ACK_RCVD_ALL_DATA, 347 TXFR_COMPLETE_TIMEOUT_MS); 348 if (ret == 0) { 349 dev_dbg(dev, "Exit boot2 download\n"); 350 break; 351 } else if (ret == -EFAULT) { 352 dev_err(dev, "Error detected during ACK waiting"); 353 goto err_firmware_out; 354 } 355 356 /* exit the loop, if there is no response from card */ 357 if (time_after(jiffies, timeout)) { 358 dev_err(dev, "Error. No reply from card\n"); 359 ret = -ETIMEDOUT; 360 goto err_firmware_out; 361 } 362 363 /* Wait for VK to open BAR space to copy new data */ 364 ret = bcm_vk_wait(vk, BAR_0, offset_codepush, 365 codepush, 0, 366 TXFR_COMPLETE_TIMEOUT_MS); 367 if (ret == 0) { 368 offset += max_buf; 369 ret = request_partial_firmware_into_buf 370 (&fw, 371 filename, 372 dev, bufp, 373 max_buf, 374 offset); 375 if (ret) { 376 dev_err(dev, 377 "Error %d requesting firmware file: %s offset: 0x%zx\n", 378 ret, filename, offset); 379 goto err_firmware_out; 380 } 381 dev_dbg(dev, "size=0x%zx\n", fw->size); 382 dev_dbg(dev, "Signaling 0x%x to 0x%llx\n", 383 codepush, offset_codepush); 384 vkwrite32(vk, codepush, BAR_0, offset_codepush); 385 /* reload timeout after every codepush */ 386 timeout = jiffies + 387 msecs_to_jiffies(LOAD_IMAGE_TIMEOUT_MS); 388 } else if (ret == -EFAULT) { 389 dev_err(dev, "Error detected waiting for transfer\n"); 390 goto err_firmware_out; 391 } 392 } while (1); 393 394 /* wait for fw status bits to indicate app ready */ 395 ret = bcm_vk_wait(vk, BAR_0, VK_BAR_FWSTS, 396 VK_FWSTS_READY, 397 VK_FWSTS_READY, 398 BOOT2_STARTUP_TIMEOUT_MS); 399 if (ret < 0) { 400 dev_err(dev, "Boot2 not ready - ret(%d)\n", ret); 401 goto err_firmware_out; 402 } 403 404 is_stdalone = vkread32(vk, BAR_0, BAR_BOOT_STATUS) & 405 BOOT_STDALONE_RUNNING; 406 if (!is_stdalone) { 407 ret = bcm_vk_intf_ver_chk(vk); 408 if (ret) { 409 dev_err(dev, "failure in intf version check\n"); 410 goto err_firmware_out; 411 } 412 413 /* sync & channel other info */ 414 ret = bcm_vk_sync_card_info(vk); 415 if (ret) { 416 dev_err(dev, "Syncing Card Info failure\n"); 417 goto err_firmware_out; 418 } 419 } 420 } 421 422 err_firmware_out: 423 release_firmware(fw); 424 425 err_buf_out: 426 if (bufp) 427 dma_free_coherent(dev, max_buf, bufp, boot_dma_addr); 428 429 return ret; 430 } 431---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Re: [kbuild-all] Re: [PATCH v5 03/15] misc: bcm-vk: add autoload support
Quoted 16 lines · Scott Branden
Quoted 7 lines · kernel test robot
Hi Scott,
I love your patch! Yet something to improve:
[auto build test ERROR on char-misc/char-misc-testing]
[also build test ERROR on soc/for-next kees/for-next/pstore linus/master v5.9-rc7 next-20200930] [If your patch is applied to the wrong git tree, kindly drop us a note.Yes, this patch series will not compile as described in the cover letter without Kees' patches:
This patch series drops previous patches in [1] that were incorporated by Kees Cook into patch series "Introduce partial
kernel_read_file()support" [2].
Quoted 5 lines
Remaining patches are contained in this series to add Broadcom VK driver. (which depends on
request_firmware_into_bufAPI addition in other patch series [2] being applied first).Please note this patch series will not compile without [2].
Thanks for the detail info, and sorry for the wrong report. Currently we are not able to analyz the info in cover letter which may lead to wrong base used. If possible, you can give a try to use --base option when git format patch, this provides more hints to us when looking for a base.
Quoted 274 lines
[1] https://lore.kernel.org/lkml/20200706232309.12010-1-scott.branden(a)broadcom.com/
[2] https://lore.kernel.org/lkml/20200729175845.1745471-1-keescook(a)chromium.org/Quoted 258 lines
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]url: https://github.com/0day-ci/linux/commits/Scott-Branden/Add-Broadcom-VK-driver/20201001-093119 base: https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc.git c471bf4b11c7df0f0f9f42b5aeec424dc62d0c7e config: powerpc-allyesconfig (attached as .config) compiler: powerpc64-linux-gcc (GCC) 9.3.0reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/f04a1673933a1af94e44bc650533bbb271e3dcc1
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Scott-Branden/Add-Broadcom-VK-driver/20201001-093119 git checkoutf04a1673933a1af94e44bc650533bbb271e3dcc1
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=powerpcIf you fix the issue, kindly add following tag as appropriate
Reported-by kernel test robot <[email protected]>All errors (new ones prefixed by >>):
drivers/misc/bcm-vk/bcm_vk_dev.c: In function 'bcm_vk_load_image_by_type':Quoted 1 line
Quoted 1 line
drivers/misc/bcm-vk/bcm_vk_dev.c:284:8: error: implicit declaration of function 'request_partial_firmware_into_buf'; did you mean 'request_firmware_into_buf'? [-Werror=implicit-function-declaration]284 | ret = request_partial_firmware_into_buf(&fw, filename, dev, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | request_firmware_into_bufcc1: some warnings being treated as errors
vim +284
drivers/misc/bcm-vk/bcm_vk_dev.c206 207 static int bcm_vk_load_image_by_type(struct bcm_vk *vk, u32 load_type, 208 const char *filename) 209 { 210 struct device *dev = &vk->pdev->dev; 211 const struct firmware *fw = NULL; 212 void *bufp = NULL; 213 size_t max_buf, offset; 214 int ret; 215 u64 offset_codepush; 216 u32 codepush; 217 u32 value; 218 dma_addr_t boot_dma_addr; 219 bool is_stdalone; 220 221 if (load_type == VK_IMAGE_TYPE_BOOT1) { 222 /* 223 * After POR, enable VK soft BOOTSRC so bootrom do not clear 224 * the pushed image (the TCM memories). 225 */ 226 value = vkread32(vk, BAR_0, BAR_BOOTSRC_SELECT); 227 value |= BOOTSRC_SOFT_ENABLE; 228 vkwrite32(vk, value, BAR_0, BAR_BOOTSRC_SELECT); 229 230 codepush = CODEPUSH_BOOTSTART + CODEPUSH_BOOT1_ENTRY; 231 offset_codepush = BAR_CODEPUSH_SBL; 232 233 /* Write a 1 to request SRAM open bit */ 234 vkwrite32(vk, CODEPUSH_BOOTSTART, BAR_0, offset_codepush); 235 236 /* Wait for VK to respond */ 237 ret = bcm_vk_wait(vk, BAR_0, BAR_BOOT_STATUS, SRAM_OPEN, 238 SRAM_OPEN, LOAD_IMAGE_TIMEOUT_MS); 239 if (ret < 0) { 240 dev_err(dev, "boot1 wait SRAM err - ret(%d)\n", ret); 241 goto err_buf_out; 242 } 243 244 max_buf = SZ_256K; 245 bufp = dma_alloc_coherent(dev, 246 max_buf, 247 &boot_dma_addr, GFP_KERNEL); 248 if (!bufp) { 249 dev_err(dev, "Error allocating 0x%zx\n", max_buf); 250 ret = -ENOMEM; 251 goto err_buf_out; 252 } 253 } else if (load_type == VK_IMAGE_TYPE_BOOT2) { 254 codepush = CODEPUSH_BOOT2_ENTRY; 255 offset_codepush = BAR_CODEPUSH_SBI; 256 257 /* Wait for VK to respond */ 258 ret = bcm_vk_wait(vk, BAR_0, BAR_BOOT_STATUS, DDR_OPEN, 259 DDR_OPEN, LOAD_IMAGE_TIMEOUT_MS); 260 if (ret < 0) { 261 dev_err(dev, "boot2 wait DDR open error - ret(%d)\n", 262 ret); 263 goto err_buf_out; 264 } 265 266 max_buf = SZ_4M; 267 bufp = dma_alloc_coherent(dev, 268 max_buf, 269 &boot_dma_addr, GFP_KERNEL); 270 if (!bufp) { 271 dev_err(dev, "Error allocating 0x%zx\n", max_buf); 272 ret = -ENOMEM; 273 goto err_buf_out; 274 } 275 276 bcm_vk_buf_notify(vk, bufp, boot_dma_addr, max_buf); 277 } else { 278 dev_err(dev, "Error invalid image type 0x%x\n", load_type); 279 ret = -EINVAL; 280 goto err_buf_out; 281 } 282 283 offset = 0;Quoted 1 line
284 ret = request_partial_firmware_into_buf(&fw, filename, dev,
285 bufp, max_buf, offset); 286 if (ret) { 287 dev_err(dev, "Error %d requesting firmware file: %s\n", 288 ret, filename); 289 goto err_firmware_out; 290 } 291 dev_dbg(dev, "size=0x%zx\n", fw->size); 292 if (load_type == VK_IMAGE_TYPE_BOOT1) 293 memcpy_toio(vk->bar[BAR_1] + BAR1_CODEPUSH_BASE_BOOT1, 294 bufp, 295 fw->size); 296 297 dev_dbg(dev, "Signaling 0x%x to 0x%llx\n", codepush, offset_codepush); 298 vkwrite32(vk, codepush, BAR_0, offset_codepush); 299 300 if (load_type == VK_IMAGE_TYPE_BOOT1) { 301 u32 boot_status; 302 303 /* wait until done */ 304 ret = bcm_vk_wait(vk, BAR_0, BAR_BOOT_STATUS, 305 BOOT1_RUNNING, 306 BOOT1_RUNNING, 307 BOOT1_STARTUP_TIMEOUT_MS); 308 309 boot_status = vkread32(vk, BAR_0, BAR_BOOT_STATUS); 310 is_stdalone = !BCM_VK_INTF_IS_DOWN(boot_status) && 311 (boot_status & BOOT_STDALONE_RUNNING); 312 if (ret && !is_stdalone) { 313 dev_err(dev, 314 "Timeout %ld ms waiting for boot1 to come up - ret(%d)\n", 315 BOOT1_STARTUP_TIMEOUT_MS, ret); 316 goto err_firmware_out; 317 } else if (is_stdalone) { 318 u32 reg; 319 320 reg = vkread32(vk, BAR_0, BAR_BOOT1_STDALONE_PROGRESS); 321 if ((reg & BOOT1_STDALONE_PROGRESS_MASK) == 322 BOOT1_STDALONE_SUCCESS) { 323 dev_info(dev, "Boot1 standalone success\n"); 324 ret = 0; 325 } else { 326 dev_err(dev, "Timeout %ld ms - Boot1 standalone failure\n", 327 BOOT1_STARTUP_TIMEOUT_MS); 328 ret = -EINVAL; 329 goto err_firmware_out; 330 } 331 } 332 } else if (load_type == VK_IMAGE_TYPE_BOOT2) { 333 unsigned long timeout; 334 335 timeout = jiffies + msecs_to_jiffies(LOAD_IMAGE_TIMEOUT_MS); 336 337 /* To send more data to VK than max_buf allowed at a time */ 338 do { 339 /* 340 * Check for ack from card. when Ack is received, 341 * it means all the data is received by card. 342 * Exit the loop after ack is received. 343 */ 344 ret = bcm_vk_wait(vk, BAR_0, BAR_BOOT_STATUS, 345 FW_LOADER_ACK_RCVD_ALL_DATA, 346 FW_LOADER_ACK_RCVD_ALL_DATA, 347 TXFR_COMPLETE_TIMEOUT_MS); 348 if (ret == 0) { 349 dev_dbg(dev, "Exit boot2 download\n"); 350 break; 351 } else if (ret == -EFAULT) { 352 dev_err(dev, "Error detected during ACK waiting"); 353 goto err_firmware_out; 354 } 355 356 /* exit the loop, if there is no response from card */ 357 if (time_after(jiffies, timeout)) { 358 dev_err(dev, "Error. No reply from card\n"); 359 ret = -ETIMEDOUT; 360 goto err_firmware_out; 361 } 362 363 /* Wait for VK to open BAR space to copy new data */ 364 ret = bcm_vk_wait(vk, BAR_0, offset_codepush, 365 codepush, 0, 366 TXFR_COMPLETE_TIMEOUT_MS); 367 if (ret == 0) { 368 offset += max_buf; 369 ret = request_partial_firmware_into_buf 370 (&fw, 371 filename, 372 dev, bufp, 373 max_buf, 374 offset); 375 if (ret) { 376 dev_err(dev, 377 "Error %d requesting firmware file: %s offset: 0x%zx\n", 378 ret, filename, offset); 379 goto err_firmware_out; 380 } 381 dev_dbg(dev, "size=0x%zx\n", fw->size); 382 dev_dbg(dev, "Signaling 0x%x to 0x%llx\n", 383 codepush, offset_codepush); 384 vkwrite32(vk, codepush, BAR_0, offset_codepush); 385 /* reload timeout after every codepush */ 386 timeout = jiffies + 387 msecs_to_jiffies(LOAD_IMAGE_TIMEOUT_MS); 388 } else if (ret == -EFAULT) { 389 dev_err(dev, "Error detected waiting for transfer\n"); 390 goto err_firmware_out; 391 } 392 } while (1); 393 394 /* wait for fw status bits to indicate app ready */ 395 ret = bcm_vk_wait(vk, BAR_0, VK_BAR_FWSTS, 396 VK_FWSTS_READY, 397 VK_FWSTS_READY, 398 BOOT2_STARTUP_TIMEOUT_MS); 399 if (ret < 0) { 400 dev_err(dev, "Boot2 not ready - ret(%d)\n", ret); 401 goto err_firmware_out; 402 } 403 404 is_stdalone = vkread32(vk, BAR_0, BAR_BOOT_STATUS) & 405 BOOT_STDALONE_RUNNING; 406 if (!is_stdalone) { 407 ret = bcm_vk_intf_ver_chk(vk); 408 if (ret) { 409 dev_err(dev, "failure in intf version check\n"); 410 goto err_firmware_out; 411 } 412 413 /* sync & channel other info */ 414 ret = bcm_vk_sync_card_info(vk); 415 if (ret) { 416 dev_err(dev, "Syncing Card Info failure\n"); 417 goto err_firmware_out; 418 } 419 } 420 } 421 422 err_firmware_out: 423 release_firmware(fw); 424 425 err_buf_out: 426 if (bufp) 427 dma_free_coherent(dev, max_buf, bufp, boot_dma_addr); 428 429 return ret; 430 } 431Quoted 3 lines
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org_______________________________________________
kbuild-all mailing list -- kbuild-all(a)lists.01.org To unsubscribe send an email to kbuild-all-leave(a)lists.01.org
Scott Branden
maintainerPATCH v5 4/15 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>
@@ -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);
@@ -777,6 +801,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,
@@ -791,6 +816,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);
@@ -799,6 +831,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 v5 5/15 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
@@ -630,6 +630,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;
@@ -742,6 +752,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.
@@ -750,7 +769,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",
@@ -762,6 +781,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);
@@ -812,6 +835,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 v5 6/15 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 | 126 +++++++++++++++++++++++++++++++ drivers/misc/bcm-vk/bcm_vk_msg.h | 31 ++++++++ 5 files changed, 198 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>
@@ -630,6 +631,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) {
@@ -652,10 +659,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" );
@@ -732,6 +742,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) {
@@ -820,6 +831,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;
@@ -863,6 +884,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 +126 -0
126 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 v5 7/15 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 v5 8/15 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 | 58 +++++++++++++++++++++ drivers/misc/bcm-vk/bcm_vk_dev.c | 87 ++++++++++++++++++++++++++++++++ 2 files changed, 145 insertions(+)
drivers/misc/bcm-vk/bcm_vk.h +58 -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,47 @@ 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 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 +292,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 +87 -0
99 lines not on this page · raw message
Signature · 1 line
2.17.1
Scott Branden
maintainerPATCH v5 9/15 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 | 120 ++++ drivers/misc/bcm-vk/bcm_vk_dev.c | 302 +++++++- drivers/misc/bcm-vk/bcm_vk_msg.c | 1151 ++++++++++++++++++++++++++++++ drivers/misc/bcm-vk/bcm_vk_msg.h | 126 ++++ drivers/misc/bcm-vk/bcm_vk_sg.c | 275 +++++++ drivers/misc/bcm-vk/bcm_vk_sg.h | 61 ++ 7 files changed, 2035 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 +120 -0
197 lines not on this page · raw message
drivers/misc/bcm-vk/bcm_vk_dev.c +300 -2
407 lines not on this page · raw message
drivers/misc/bcm-vk/bcm_vk_msg.c +1151 -0
1,193 lines not on this page · raw message
drivers/misc/bcm-vk/bcm_vk_msg.h +126 -0
149 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
Re: [PATCH v5 09/15] misc: bcm-vk: add VK messaging support
Quoted 2 lines · Scott Branden
Add message support in order to be able to communicate to VK card via message queues.
trivia:
drivers/misc/bcm-vk/bcm_vk.h struct bcm_vk { · line 400
Quoted 6 lines
drivers/misc/bcm-vk/bcm_vk.h +6
-0+/* structure that is used to faciliate displaying of register content */ +struct bcm_vk_entry { +const u32 mask; +const u32 exp_val; +const char *str; +};
[]
drivers/misc/bcm-vk/bcm_vk_dev.c static uint nr_scratch_pages = VK_BAR1_SCRATCH_DEF_NR_PAGES; · line 114
Quoted 4 lines
drivers/misc/bcm-vk/bcm_vk_dev.c +4
-0+/* +* alerts that could be generated from peer +*/ +struct bcm_vk_entry const bcm_vk_peer_err[BCM_VK_PEER_ERR_NUM ] = {
const struct bcm_vk_entry
Quoted 4 lines
drivers/misc/bcm-vk/bcm_vk_dev.c +4
-0+ {ERR_LOG_UECC, ERR_LOG_UECC, "uecc"}, + {ERR_LOG_SSIM_BUSY, ERR_LOG_SSIM_BUSY, "ssim_busy"}, + {ERR_LOG_AFBC_BUSY, ERR_LOG_AFBC_BUSY, "afbc_busy"}, + {ERR_LOG_HIGH_TEMP_ERR, ERR_LOG_HIGH_TEMP_ERR, "high_temp"},
drivers/misc/bcm-vk/bcm_vk_dev.c static uint nr_scratch_pages = VK_BAR1_SCRATCH_DEF_NR_PAGES; · line 128
Quoted 10 lines
drivers/misc/bcm-vk/bcm_vk_dev.c +10
-0+ {ERR_LOG_WDOG_TIMEOUT, ERR_LOG_WDOG_TIMEOUT, "wdog_timeout"}, + {ERR_LOG_SYS_FAULT, ERR_LOG_SYS_FAULT, "sys_fault"}, + {ERR_LOG_RAMDUMP, ERR_LOG_RAMDUMP, "ramdump"}, + {ERR_LOG_MEM_ALLOC_FAIL, ERR_LOG_MEM_ALLOC_FAIL, "malloc_fail warn"}, + {ERR_LOG_LOW_TEMP_WARN, ERR_LOG_LOW_TEMP_WARN, "low_temp warn"}, + {ERR_LOG_ECC, ERR_LOG_ECC, "ecc"}, +}; + +/* alerts detected by the host */ +struct bcm_vk_entry const bcm_vk_host_err[BCM_VK_HOST_ERR_NUM] = {
here too
drivers/misc/bcm-vk/bcm_vk_dev.c static uint nr_scratch_pages = VK_BAR1_SCRATCH_DEF_NR_PAGES; · line 132
Quoted 4 lines
drivers/misc/bcm-vk/bcm_vk_dev.c +4
-0+ {ERR_LOG_HOST_PCIE_DWN, ERR_LOG_HOST_PCIE_DWN, "PCIe_down"}, + {ERR_LOG_HOST_HB_FAIL, ERR_LOG_HOST_HB_FAIL, "hb_fail"}, + {ERR_LOG_HOST_INTF_V_FAIL, ERR_LOG_HOST_INTF_V_FAIL, "intf_ver_fail"}, +};
[]
drivers/misc/bcm-vk/bcm_vk_dev.c static int bcm_vk_probe(struct pci_dev *pdev, const struct pci_device_id *ent) · line 1257
Quoted 8 lines
drivers/misc/bcm-vk/bcm_vk_dev.c +3
-0@@ -970,6 +1251,9 @@ static int bcm_vk_probe(struct pci_dev *pdev, const struct pci_device_id *ent) } } +/* enable hb */ +bcm_vk_hb_init (vk); +dev_dbg (dev,"BCM-VK:%u created, 0x%p\n" , id, vk);
Not much purpose in displaying the pointer.
Scott Branden
maintainerRe: [PATCH v5 09/15] misc: bcm-vk: add VK messaging support
Quoted 4 lines · Joe Perches
Quoted 2 lines · Scott Branden
Add message support in order to be able to communicate to VK card via message queues.
trivia:
will remove comment below.
Quoted 8 lines
drivers/misc/bcm-vk/bcm_vk.h struct bcm_vk { · line 400
Quoted 7 lines
drivers/misc/bcm-vk/bcm_vk.h +6
-0+/* structure that is used to faciliate displaying of register content */ +struct bcm_vk_entry { +const u32 mask; +const u32 exp_val; +const char *str; +};[]
I think you want a newline added here.
Quoted 5 lines
drivers/misc/bcm-vk/bcm_vk_dev.c static uint nr_scratch_pages = VK_BAR1_SCRATCH_DEF_NR_PAGES; · line 114
Quoted 4 lines
drivers/misc/bcm-vk/bcm_vk_dev.c +4
-0+/* +* alerts that could be generated from peer +*/ +struct bcm_vk_entry const bcm_vk_peer_err[BCM_VK_PEER_ERR_NUM ] = {const struct
bcm_vk_entry
will add the const's
Quoted 16 lines
Quoted 5 lines
drivers/misc/bcm-vk/bcm_vk_dev.c +4
-0+ {ERR_LOG_UECC, ERR_LOG_UECC, "uecc"}, + {ERR_LOG_SSIM_BUSY, ERR_LOG_SSIM_BUSY, "ssim_busy"}, + {ERR_LOG_AFBC_BUSY, ERR_LOG_AFBC_BUSY, "afbc_busy"}, + {ERR_LOG_HIGH_TEMP_ERR, ERR_LOG_HIGH_TEMP_ERR, "high_temp"},drivers/misc/bcm-vk/bcm_vk_dev.c static uint nr_scratch_pages = VK_BAR1_SCRATCH_DEF_NR_PAGES; · line 128
Quoted 10 lines
drivers/misc/bcm-vk/bcm_vk_dev.c +10
-0+ {ERR_LOG_WDOG_TIMEOUT, ERR_LOG_WDOG_TIMEOUT, "wdog_timeout"}, + {ERR_LOG_SYS_FAULT, ERR_LOG_SYS_FAULT, "sys_fault"}, + {ERR_LOG_RAMDUMP, ERR_LOG_RAMDUMP, "ramdump"}, + {ERR_LOG_MEM_ALLOC_FAIL, ERR_LOG_MEM_ALLOC_FAIL, "malloc_fail warn"}, + {ERR_LOG_LOW_TEMP_WARN, ERR_LOG_LOW_TEMP_WARN, "low_temp warn"}, + {ERR_LOG_ECC, ERR_LOG_ECC, "ecc"}, +}; + +/* alerts detected by the host */ +struct bcm_vk_entry const bcm_vk_host_err[BCM_VK_HOST_ERR_NUM] = {here too
thanks.
Quoted 10 lines
drivers/misc/bcm-vk/bcm_vk_dev.c static uint nr_scratch_pages = VK_BAR1_SCRATCH_DEF_NR_PAGES; · line 132
Quoted 5 lines
drivers/misc/bcm-vk/bcm_vk_dev.c +4
-0+ {ERR_LOG_HOST_PCIE_DWN, ERR_LOG_HOST_PCIE_DWN, "PCIe_down"}, + {ERR_LOG_HOST_HB_FAIL, ERR_LOG_HOST_HB_FAIL, "hb_fail"}, + {ERR_LOG_HOST_INTF_V_FAIL, ERR_LOG_HOST_INTF_V_FAIL, "intf_ver_fail"}, +};[]
Quoted 4 lines
(quoted diff) +0
-0@@ -970,6 +1251,9 @@ static int bcm_vk_probe(struct pci_dev *pdev, const struct pci_device_id *ent) } }
Quoted 5 lines
drivers/misc/bcm-vk/bcm_vk_dev.c static int bcm_vk_probe(struct pci_dev *pdev, const struct pci_device_id *ent) · line 1257
Quoted 4 lines
drivers/misc/bcm-vk/bcm_vk_dev.c +3
-0+/* enable hb */ +bcm_vk_hb_init (vk); +dev_dbg (dev,"BCM-VK:%u created, 0x%p\n" , id, vk);Not much purpose in displaying the pointer.
ok.
Quoted 2 lines
thanks for the review.
Scott Branden
maintainerPATCH v5 10/15 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
@@ -463,6 +463,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
211 lines not on this page · raw message
drivers/misc/bcm-vk/bcm_vk_msg.c +38 -2
@@ -204,6 +204,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;
@@ -232,6 +241,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;
@@ -376,6 +386,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 */
@@ -700,13 +716,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; }
@@ -1110,6 +1135,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 v5 11/15 misc: bcm-vk: add BCM_VK_QSTATS
In reply to Scott BrandenAdd BCM_VK_QSTATS Kconfig option to allow for enabling debug VK queue statistics.
These statistics keep track of max, abs_max, and average for the messages queues.
--- drivers/misc/bcm-vk/Kconfig | 14 +++++++++ drivers/misc/bcm-vk/bcm_vk_dev.c | 9 ++++++ drivers/misc/bcm-vk/bcm_vk_msg.c | 52 +++++++++++++++++++++++++++++++- drivers/misc/bcm-vk/bcm_vk_msg.h | 12 ++++++++ 4 files changed, 86 insertions(+), 1 deletion(-)
drivers/misc/bcm-vk/Kconfig +14 -0
@@ -13,3 +13,17 @@ config BCM_VK accelerators via /dev/bcm-vk.N devices. If unsure, say N. + +if BCM_VK + +config BCM_VK_QSTATS + bool "VK Queue Statistics" + help + Turn on to enable Queue Statistics. + These are useful for debugging purposes. + Some performance loss by enabling this debug config. + For properly operating PCIe hardware no need to enable this. + + If unsure, say N. + +endif
drivers/misc/bcm-vk/bcm_vk_dev.c +9 -0
@@ -1097,6 +1097,15 @@ static int bcm_vk_trigger_reset(struct bcm_vk *vk)vkwrite32 (vk,0 ,BAR_0 ,BAR_INTF_VER );memset (&vk->host_alert,0 ,sizeof (vk->host_alert));memset (&vk->peer_alert,0 ,sizeof (vk->peer_alert)); +#if defined(CONFIG_BCM_VK_QSTATS ) +/* clear qstats */ +for (i =0 ; i <VK_MSGQ_MAX_NR ; i++) { +memset (&vk->to_v_msg_chan.qstats[i].qcnts,0 , +sizeof (vk->to_v_msg_chan.qstats[i].qcnts)); +memset (&vk->to_h_msg_chan.qstats[i].qcnts,0 , +sizeof (vk->to_h_msg_chan.qstats[i].qcnts)); + } +#endif /* clear 4096 bits of bitmap */ bitmap_clear (vk->bmap,0 ,VK_MSG_ID_BITMAP_SIZE );
drivers/misc/bcm-vk/bcm_vk_msg.c +51 -1
77 lines not on this page · raw message
drivers/misc/bcm-vk/bcm_vk_msg.h +12 -0
@@ -125,6 +125,14 @@ struct bcm_vk_qs_cnts {u32 max_abs;/* the abs max since reset */ }; +#if defined(CONFIG_BCM_VK_QSTATS ) +/* stats structure */ +struct bcm_vk_qstats { +u32 q_num; +struct bcm_vk_qs_cnts qcnts; +}; +#endif +/* control channel structure for either to_v or to_h communication */ struct bcm_vk_msg_chan {u32 q_nr;
@@ -138,6 +146,10 @@ struct bcm_vk_msg_chan {struct list_head pendq[VK_MSGQ_MAX_NR ];/* static queue info from the sync */ struct bcm_vk_sync_qinfo sync_qinfo[VK_MSGQ_MAX_NR ]; +#if defined(CONFIG_BCM_VK_QSTATS ) +/* qstats */ +struct bcm_vk_qstats qstats[VK_MSGQ_MAX_NR ]; +#endif };/* total number of supported ctx, 32 ctx each for 5 components */
Signature · 1 line
2.17.1
Re: [PATCH v5 11/15] misc: bcm-vk: add BCM_VK_QSTATS
Quoted 10 lines · Scott Branden
Add
BCM_VK_QSTATSKconfigoption to allow for enabling debug VK queue statistics.These statistics keep track of max,
abs_max, and average for the messages queues.Co-developed-by Desmond Yan <[email protected]>Signed-off-by Desmond Yan <[email protected]>Signed-off-by Scott Branden <[email protected]>---
[snip]
drivers/misc/bcm-vk/bcm_vk_dev.c static int bcm_vk_trigger_reset(struct bcm_vk *vk) · line 1110
Quoted 11 lines
drivers/misc/bcm-vk/bcm_vk_dev.c +9
-0+#if defined(CONFIG_BCM_VK_QSTATS ) +/* clear qstats */ +for (i =0 ; i <VK_MSGQ_MAX_NR ; i++) { +memset (&vk->to_v_msg_chan.qstats[i].qcnts,0 , +sizeof (vk->to_v_msg_chan.qstats[i].qcnts)); +memset (&vk->to_h_msg_chan.qstats[i].qcnts,0 , +sizeof (vk->to_h_msg_chan.qstats[i].qcnts)); + } +#endif /* clear 4096 bits of bitmap */ bitmap_clear (vk->bmap,0 ,VK_MSG_ID_BITMAP_SIZE );
It was not clear from looking at this patch how are the statistics exposed and how does one actually get them?
Signature · 1 line
Florian
Scott Branden
maintainerRe: [PATCH v5 11/15] misc: bcm-vk: add BCM_VK_QSTATS
Quoted 16 lines · Florian Fainelli
Quoted 10 lines · Scott Branden
Add
BCM_VK_QSTATSKconfigoption to allow for enabling debug VK queue statistics.These statistics keep track of max,
abs_max, and average for the messages queues.Co-developed-by Desmond Yan <[email protected]>Signed-off-by Desmond Yan <[email protected]>Signed-off-by Scott Branden <[email protected]>---
[snip]
Quoted 13 lines
Quoted 11 lines
drivers/misc/bcm-vk/bcm_vk_dev.c +9
-0+#if defined(CONFIG_BCM_VK_QSTATS ) + /* clear qstats */ + for (i = 0; i < VK_MSGQ_MAX_NR; i++) { + memset(&vk->to_v_msg_chan.qstats[i].qcnts, 0, + sizeof(vk->to_v_msg_chan.qstats[i].qcnts)); + memset(&vk->to_h_msg_chan.qstats[i].qcnts, 0, + sizeof(vk->to_h_msg_chan.qstats[i].qcnts)); + } +#endif /* clear 4096 bits of bitmap */
bitmap_clear(vk->bmap, 0, VK_MSG_ID_BITMAP_SIZE);It was not clear from looking at this patch how are the statistics exposed and how does one actually get them?
The QSTATS, since it is only for debug purpose, it will dump out periodically based on processed_num. Nothing fancy as we only compile it in in extreme case for recreating a scenario.
The following is the part:
+ if (++qcnts->cnt >= BCM_VK_QSTATS_ACC_CNT) {
+ /* log average and clear counters */
+ dev_info(&vk->pdev->dev,
+ "%s[%d]: Max: [%3d/%3d] Acc %d num %d, Aver %d\n", + tag, qstats->q_num,
+ qcnts->max_occ, qcnts->max_abs,
+ qcnts->acc_sum,
+ qcnts->cnt,
+ qcnts->acc_sum / qcnts->cnt);
+
+ qcnts->cnt = 0;
+ qcnts->max_occ = 0;
+ qcnts->acc_sum = 0;
Re: [PATCH v5 11/15] misc: bcm-vk: add BCM_VK_QSTATS
Quoted 32 lines · Scott Branden
Quoted 16 lines · Florian Fainelli
Quoted 10 lines · Scott Branden
Add
BCM_VK_QSTATSKconfigoption to allow for enabling debug VK queue statistics.These statistics keep track of max,
abs_max, and average for the messages queues.Co-developed-by Desmond Yan <[email protected]>Signed-off-by Desmond Yan <[email protected]>Signed-off-by Scott Branden <[email protected]>---
[snip]
Quoted 13 lines
drivers/misc/bcm-vk/bcm_vk_dev.c static int bcm_vk_trigger_reset(struct bcm_vk *vk) · line 1110
Quoted 11 lines
drivers/misc/bcm-vk/bcm_vk_dev.c +9
-0+#if defined(CONFIG_BCM_VK_QSTATS ) + /* clear qstats */ + for (i = 0; i < VK_MSGQ_MAX_NR; i++) { + memset(&vk->to_v_msg_chan.qstats[i].qcnts, 0, + sizeof(vk->to_v_msg_chan.qstats[i].qcnts)); + memset(&vk->to_h_msg_chan.qstats[i].qcnts, 0, + sizeof(vk->to_h_msg_chan.qstats[i].qcnts)); + } +#endif /* clear 4096 bits of bitmap */ bitmap_clear(vk->bmap, 0, VK_MSG_ID_BITMAP_SIZE);It was not clear from looking at this patch how are the statistics exposed and how does one actually get them?
Quoted 2 lines
The QSTATS, since it is only for debug purpose, it will dump out periodically based on
processed_num. Nothing fancy as we only compile it in in extreme case for recreating a scenario.
But what kind of interface is that? Cannot you at least expose those through sysfs if nothing else?
Signature · 1 line
Florian
Scott Branden
maintainerRe: [PATCH v5 11/15] misc: bcm-vk: add BCM_VK_QSTATS
Quoted 35 lines · Florian Fainelli
Quoted 32 lines · Scott Branden
Quoted 29 lines · Florian Fainelli
Quoted 10 lines · Scott Branden
Add
BCM_VK_QSTATSKconfigoption to allow for enabling debug VK queue statistics.These statistics keep track of max,
abs_max, and average for the messages queues.Co-developed-by Desmond Yan <[email protected]>Signed-off-by Desmond Yan <[email protected]>Signed-off-by Scott Branden <[email protected]>---
[snip]
Quoted 11 lines
drivers/misc/bcm-vk/bcm_vk_dev.c +9
-0+#if defined(CONFIG_BCM_VK_QSTATS ) + /* clear qstats */ + for (i = 0; i < VK_MSGQ_MAX_NR; i++) { + memset(&vk->to_v_msg_chan.qstats[i].qcnts, 0, + sizeof(vk->to_v_msg_chan.qstats[i].qcnts)); + memset(&vk->to_h_msg_chan.qstats[i].qcnts, 0, + sizeof(vk->to_h_msg_chan.qstats[i].qcnts)); + } +#endif /* clear 4096 bits of bitmap */
bitmap_clear(vk->bmap, 0, VK_MSG_ID_BITMAP_SIZE);It was not clear from looking at this patch how are the statistics exposed and how does one actually get them?
Quoted 4 lines
Quoted 2 lines
The QSTATS, since it is only for debug purpose, it will dump out periodically based on
processed_num. Nothing fancy as we only compile it in in extreme case for recreating a scenario.But what kind of interface is that? Cannot you at least expose those through sysfs if nothing else?
A sysfs interface would not be as useful as we want the dmesg timestamp information.
QSTATS are purely for development/debug issues and enabled via a CONFIG option that won't be turned on by normal users. Will change to dev_dbg.
Greg Kroah-Hartman
maintainerRe: [PATCH v5 11/15] misc: bcm-vk: add BCM_VK_QSTATS
In reply to Scott BrandenQuoted 37 lines · Scott Branden
Quoted 16 lines · Florian Fainelli
Quoted 10 lines · Scott Branden
Add
BCM_VK_QSTATSKconfigoption to allow for enabling debug VK queue statistics.These statistics keep track of max,
abs_max, and average for the messages queues.Co-developed-by Desmond Yan <[email protected]>Signed-off-by Desmond Yan <[email protected]>Signed-off-by Scott Branden <[email protected]>---
[snip]
Quoted 13 lines
Quoted 11 lines
drivers/misc/bcm-vk/bcm_vk_dev.c +9
-0+#if defined(CONFIG_BCM_VK_QSTATS ) + /* clear qstats */ + for (i = 0; i < VK_MSGQ_MAX_NR; i++) { + memset(&vk->to_v_msg_chan.qstats[i].qcnts, 0, + sizeof(vk->to_v_msg_chan.qstats[i].qcnts)); + memset(&vk->to_h_msg_chan.qstats[i].qcnts, 0, + sizeof(vk->to_h_msg_chan.qstats[i].qcnts)); + } +#endif /* clear 4096 bits of bitmap */
bitmap_clear(vk->bmap, 0, VK_MSG_ID_BITMAP_SIZE);It was not clear from looking at this patch how are the statistics exposed and how does one actually get them?
The QSTATS, since it is only for debug purpose, it will dump out periodically based on
processed_num. Nothing fancy as we only compile it in in extreme case for recreating a scenario.The following is the part:
Quoted 9 lines
+ if (++qcnts->cnt >=
BCM_VK_QSTATS_ACC_CNT) {
+ /* log average and clear counters */
+ dev_info(&vk->pdev->dev,
+ "%s[%d]: Max: [%3d/%3d] Acc %d num %d, Aver %d\n", + tag,qstats->q_num,
+qcnts->max_occ,qcnts->max_abs,
+qcnts->acc_sum,
+qcnts->cnt,
+qcnts->acc_sum/qcnts->cnt);
Ah, that's not ok, don't flood the kernel log for non-error things please. If you need to "report" stuff, when all is going well, use the other common interfaces for that.
Again, drivers, when all is working, are quiet.
thanks,
greg k-h
Scott Branden
maintainerRe: [PATCH v5 11/15] misc: bcm-vk: add BCM_VK_QSTATS
Quoted 43 lines · Greg Kroah-Hartman
Quoted 33 lines · Scott Branden
Quoted 14 lines · Florian Fainelli
Quoted 10 lines · Scott Branden
Add
BCM_VK_QSTATSKconfigoption to allow for enabling debug VK queue statistics.These statistics keep track of max,
abs_max, and average for the messages queues.Co-developed-by Desmond Yan <[email protected]>Signed-off-by Desmond Yan <[email protected]>Signed-off-by Scott Branden <[email protected]>---
[snip]
Quoted 12 lines
Quoted 11 lines
drivers/misc/bcm-vk/bcm_vk_dev.c +9
-0+#if defined(CONFIG_BCM_VK_QSTATS ) + /* clear qstats */ + for (i = 0; i < VK_MSGQ_MAX_NR; i++) { + memset(&vk->to_v_msg_chan.qstats[i].qcnts, 0, + sizeof(vk->to_v_msg_chan.qstats[i].qcnts)); + memset(&vk->to_h_msg_chan.qstats[i].qcnts, 0, + sizeof(vk->to_h_msg_chan.qstats[i].qcnts)); + } +#endif /* clear 4096 bits of bitmap */
bitmap_clear(vk->bmap, 0, VK_MSG_ID_BITMAP_SIZE);It was not clear from looking at this patch how are the statistics exposed and how does one actually get them?
The QSTATS, since it is only for debug purpose, it will dump out periodically based on
processed_num. Nothing fancy as we only compile it in in extreme case for recreating a scenario.The following is the part:
Quoted 9 lines
+ if (++qcnts->cnt >=
BCM_VK_QSTATS_ACC_CNT) {
+ /* log average and clear counters */
+ dev_info(&vk->pdev->dev,
+ "%s[%d]: Max: [%3d/%3d] Acc %d num %d, Aver %d\n", + tag,qstats->q_num,
+qcnts->max_occ,qcnts->max_abs,
+qcnts->acc_sum,
+qcnts->cnt,
+qcnts->acc_sum/qcnts->cnt);
Quoted 5 lines
Ah, that's not ok, don't flood the kernel log for non-error things please. If you need to "report" stuff, when all is going well, use the other common interfaces for that.
Again, drivers, when all is working, are quiet.
Will change to dev_dbg.
Quoted 4 lines
thanks,
greg k-h
Scott Branden
maintainerPATCH v5 12/15 misc: bcm-vk: add sysfs interface
In reply to Scott BrandenAdd sysfs support to query the VK card status and monitor sense points. The vk-card-status and vk-card-mon details are provided in the README file in the bcm-vk driver directory.
--- drivers/misc/bcm-vk/Makefile | 3 +- drivers/misc/bcm-vk/README | 99 ++ drivers/misc/bcm-vk/bcm_vk.h | 2 + drivers/misc/bcm-vk/bcm_vk_dev.c | 8 + drivers/misc/bcm-vk/bcm_vk_sysfs.c | 1411 ++++++++++++++++++++++++++++ 5 files changed, 1522 insertions(+), 1 deletion(-) create mode 100644 drivers/misc/bcm-vk/README create mode 100644 drivers/misc/bcm-vk/bcm_vk_sysfs.c
drivers/misc/bcm-vk/Makefile +2 -1
@@ -7,5 +7,6 @@ obj-$(CONFIG_BCM_VK) += bcm_vk.o bcm_vk-objs := \ bcm_vk_dev.o \ bcm_vk_msg.o \ - bcm_vk_sg.o + bcm_vk_sg.o \ + bcm_vk_sysfs.o
drivers/misc/bcm-vk/README new file +99 -0
99 lines not on this page · raw message
drivers/misc/bcm-vk/bcm_vk.h +2 -0
@@ -476,5 +476,7 @@ void bcm_vk_hb_deinit(struct bcm_vk *vk);void bcm_vk_handle_notf (struct bcm_vk *vk);bool bcm_vk_drv_access_ok (struct bcm_vk *vk);void bcm_vk_set_host_alert (struct bcm_vk *vk,u32 bit_mask); +int bcm_vk_sysfs_init (struct pci_dev *pdev,struct miscdevice *misc_device); +void bcm_vk_sysfs_exit (struct pci_dev *pdev,struct miscdevice *misc_device);#endif
drivers/misc/bcm-vk/bcm_vk_dev.c +8 -0
@@ -1381,6 +1381,10 @@ static int bcm_vk_probe(struct pci_dev *pdev, const struct pci_device_id *ent)/* sync other info */ bcm_vk_sync_card_info (vk); + err =bcm_vk_sysfs_init (pdev, misc_device); +if (err) + goto err_destroy_workqueue; +/* register for panic notifier */ vk->panic_nb.notifier_call = bcm_vk_on_panic; err = atomic_notifier_chain_register(&panic_notifier_list,
@@ -1490,6 +1494,10 @@ static void bcm_vk_remove(struct pci_dev *pdev)atomic_notifier_chain_unregister (&panic_notifier_list, &vk->panic_nb); +bcm_vk_sysfs_exit (pdev, misc_device); + +bcm_vk_msg_remove (vk); +if (vk->tdma_vaddr)dma_free_coherent (&pdev->dev, nr_scratch_pages *PAGE_SIZE , vk->tdma_vaddr, vk->tdma_addr);
drivers/misc/bcm-vk/bcm_vk_sysfs.c new file +1411 -0
1,411 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [PATCH v5 12/15] misc: bcm-vk: add sysfs interface
Quoted 8 lines · Scott Branden
Add sysfs support to query the VK card status and monitor sense points. The vk-card-status and vk-card-mon details are provided in the README file in the bcm-vk driver directory.
Co-developed-by Desmond Yan <[email protected]>Signed-off-by Desmond Yan <[email protected]>Signed-off-by Scott Branden <[email protected]>---
[snip]
Quoted 37 lines
drivers/misc/bcm-vk/README new file +37
-0+vk-card-status/ + bus ---> device PCIe bus + card_state ---> summary of current card states + chip_id + firmware_status ---> summary of all firmware status + firmware_version ---> summary of all firmware versions + freq_core_mhz ---> running frequency in mHz + freq_mem_mhz ---> memory frequency in mHz + mem_size_mb ---> memory size in MByte + os_state ---> current running state + reset_reason ---> last reset reason + rev_boot1 ---> boot1 firmware revision + rev_boot2 ---> boot2 firmware revision + rev_driver ---> host driver revision + rev_flash_rom ---> Flash ROM revision + sotp_boot1_rev_id ---> minimum boot1 revision required + sotp_boot2_rev_id ---> minimum boot2 revision required + sotp_dauth_1 ---> authentication key hash + sotp_dauth_1_valid ---> authentication key validity + sotp_dauth_1_active_status -> authentication key active or not + sotp_dauth_2 + sotp_dauth_2_valid + sotp_dauth_2_active_status + sotp_dauth_3 + sotp_dauth_3_valid + sotp_dauth_3_active_status + sotp_dauth_4 + sotp_dauth_4_valid + sotp_dauth_4_active_status + temp_threshold_lower_c ---> thermal low threshold in Celsius + temp_threshold_upper_c ---> thermal high threshold in Celsius + uptime_s ---> os up time in seconds + +vk-card-mon/ + alert_afbc_busy ---> AFBC block stuck + alert_ecc ---> uncorrectable ECC error(s) occurred + alert_ecc_warn ---> correctable ECC error(s) occurred
drivers/misc/bcm-vk/README line 70
Quoted 10 lines
drivers/misc/bcm-vk/README new file +10
-0+ alert_heartbeat_fail ---> host detects heartbeat discontinuation + from card + alert_high_temp ---> high temperature threshold crossed + alert_intf_ver_fail ---> interface not compatible based on version + alert_low_temp_warn ---> low temperature threshold crossed + alert_malloc_fail_warn ---> mem allocation failure(s) occurred + alert_pcie_down ---> host detect pcie intf going down + alert_ssim_busy ---> ssim block busy + alert_sys_fault ---> system fault + alert_wdog_timeout ---> watchdog timeout
Almost all of these should be supported using the HWMON framework instead of custom attributes that do not follow the HWMON naming conventions.
drivers/misc/bcm-vk/README line 73
Quoted 3 lines
drivers/misc/bcm-vk/README new file +3
-0+ firmware_status_reg + mem_ecc ---> correctable ECC error count + mem_uecc ---> uncorrectable ECC error count
Implementing an EDAC driver would be a bit overkill unless you have a way to signal ECC errors towards the host?
drivers/misc/bcm-vk/README line 78
Quoted 5 lines
drivers/misc/bcm-vk/README new file +5
-0+ boot_status_reg ---> boot status of card + pwr_state ---> power state, 1-full, 2-reduced, 3-lowest + temperature_sensor_1_c ---> CPU die temperature in Celsius + temperature_sensor_2_c ---> DDR0 temperature in Celsius + temperature_sensor_3_c ---> DDR1 temperature in Celsius
Likewise.
drivers/misc/bcm-vk/README line 87
Quoted 9 lines
drivers/misc/bcm-vk/README new file +9
-0+ utilization ---> runtime video transcoding consumption summary + utilization_pix ---> percentage of pixel processing used + utilization_pix_used ---> pixel processing used + utilization_pix_max ---> max pixel processing value which maps 100% load + utilization_codec ---> percentage of codec sessions used + utilization_codec_used ---> codec sessions currently used + utilization_codec_max ---> max codec sessions allowed + voltage_18_mv ---> 1.8v voltage rail in mv + voltage_33_mv ---> 3.3v voltage rail in mv
Likewise
Review
Quoted 2 lines
(quoted diff) +2
-0+ +The sysfs entry supports only the read operation.
entries.
Signature · 1 line
Florian
Scott Branden
maintainerRe: [PATCH v5 12/15] misc: bcm-vk: add sysfs interface
Quoted 55 lines · Florian Fainelli
Quoted 8 lines · Scott Branden
Add sysfs support to query the VK card status and monitor sense points. The vk-card-status and vk-card-mon details are provided in the README file in the bcm-vk driver directory.
Co-developed-by Desmond Yan <[email protected]>Signed-off-by Desmond Yan <[email protected]>Signed-off-by Scott Branden <[email protected]>---
[snip]
Quoted 41 lines
drivers/misc/bcm-vk/README new file +41
-0+vk-card-status/ + bus ---> device PCIe bus + card_state ---> summary of current card states + chip_id + firmware_status ---> summary of all firmware status + firmware_version ---> summary of all firmware versions + freq_core_mhz ---> running frequency in mHz + freq_mem_mhz ---> memory frequency in mHz + mem_size_mb ---> memory size in MByte + os_state ---> current running state + reset_reason ---> last reset reason + rev_boot1 ---> boot1 firmware revision + rev_boot2 ---> boot2 firmware revision + rev_driver ---> host driver revision + rev_flash_rom ---> Flash ROM revision + sotp_boot1_rev_id ---> minimum boot1 revision required + sotp_boot2_rev_id ---> minimum boot2 revision required + sotp_dauth_1 ---> authentication key hash + sotp_dauth_1_valid ---> authentication key validity + sotp_dauth_1_active_status -> authentication key active or not + sotp_dauth_2 + sotp_dauth_2_valid + sotp_dauth_2_active_status + sotp_dauth_3 + sotp_dauth_3_valid + sotp_dauth_3_active_status + sotp_dauth_4 + sotp_dauth_4_valid + sotp_dauth_4_active_status + temp_threshold_lower_c ---> thermal low threshold in Celsius + temp_threshold_upper_c ---> thermal high threshold in Celsius + uptime_s ---> os up time in seconds + +vk-card-mon/ + alert_afbc_busy ---> AFBC block stuck + alert_ecc ---> uncorrectable ECC error(s) occurred + alert_ecc_warn ---> correctable ECC error(s) occurred + alert_heartbeat_fail ---> host detects heartbeat discontinuation + from card + alert_high_temp ---> high temperature threshold crossed + alert_intf_ver_fail ---> interface not compatible based on version
Quoted 8 lines
Quoted 6 lines
+ alert_low_temp_warn ---> low temperature threshold crossed + alert_malloc_fail_warn ---> mem allocation failure(s) occurred + alert_pcie_down ---> host detect pcie intf going down + alert_ssim_busy ---> ssim block busy
+ alert_sys_fault ---> system fault
+ alert_wdog_timeout ---> watchdog timeoutAlmost all of these should be supported using the HWMON framework instead of custom attributes that do not follow the HWMON naming conventions.
Makes sense - we'll look at hwmon framework.
Quoted 6 lines
Quoted 4 lines
+
firmware_status_reg
+ mem_ecc ---> correctable ECC error count + mem_uecc ---> uncorrectable ECC error countImplementing an EDAC driver would be a bit overkill unless you have a way to signal ECC errors towards the host?
Yes, EDAC driver would be overkill here.
Quoted 26 lines
Quoted 7 lines
+ boot_status_reg ---> boot status of card
+ pwr_state ---> power state, 1-full, 2-reduced, 3-lowest + temperature_sensor_1_c ---> CPU die temperature in Celsius + temperature_sensor_2_c ---> DDR0 temperature in Celsius + temperature_sensor_3_c ---> DDR1 temperature in CelsiusLikewise.
Quoted 9 lines
+ utilization ---> runtime video transcoding consumption summary + utilization_pix ---> percentage of pixel processing used
+ utilization_pix_used ---> pixel processing used
+ utilization_pix_max ---> max pixel processing value which maps 100% load + utilization_codec ---> percentage of codec sessions used
+ utilization_codec_used ---> codec sessions currently used
+ utilization_codec_max ---> max codec sessions allowed
+ voltage_18_mv ---> 1.8v voltage rail in mv
+ voltage_33_mv ---> 3.3v voltage rail in mvLikewise
Review
Quoted 2 lines
(quoted diff) +2
-0+ +The sysfs entry supports only the read operation.entries.
Scott Branden
maintainerPATCH v5 13/15 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
@@ -1177,6 +1177,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 ;
@@ -1215,6 +1238,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 v5 14/15 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
@@ -3714,6 +3714,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 v5 15/15 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 | 3 +- drivers/misc/bcm-vk/bcm_vk.h | 28 +++ drivers/misc/bcm-vk/bcm_vk_dev.c | 27 ++- drivers/misc/bcm-vk/bcm_vk_tty.c | 333 +++++++++++++++++++++++++++++++ 4 files changed, 389 insertions(+), 2 deletions(-) create mode 100644 drivers/misc/bcm-vk/bcm_vk_tty.c
drivers/misc/bcm-vk/Makefile +2 -1
@@ -8,5 +8,6 @@ bcm_vk-objs := \ bcm_vk_dev.o \ bcm_vk_msg.o \ bcm_vk_sg.o \ - bcm_vk_sysfs.o + bcm_vk_sysfs.o \ + 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))
@@ -251,6 +256,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
@@ -342,6 +360,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;
@@ -461,6 +485,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);
@@ -471,6 +496,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 +26 -1
@@ -499,6 +499,7 @@ void bcm_vk_blk_drv_access(struct bcm_vk *vk) } } } +bcm_vk_tty_terminate_tty_user (vk);spin_unlock (&vk->ctx_lock); }
@@ -1361,6 +1362,19 @@ static int bcm_vk_probe(struct pci_dev *pdev, const struct pci_device_id *ent) } vk->num_irqs++; +for (i =0 ; + (i <VK_MSIX_TTY_MAX ) && (vk->num_irqs < irq); + i++, vk->num_irqs++) { + err =devm_request_irq (dev,pci_irq_vector (pdev, vk->num_irqs), + bcm_vk_tty_irqhandler, +IRQF_SHARED ,DRV_MODULE_NAME , vk); +if (err) { +dev_err (dev,"failed request tty IRQ %d for MSIX %d\n" , + pdev->irq + vk->num_irqs, vk->num_irqs +1 ); + goto err_irq; + } + vk->tty[i].irq_enabled = true; + } id =ida_simple_get (&bcm_vk_ida,0 ,0 ,GFP_KERNEL );if (id <0 ) {
@@ -1418,6 +1432,11 @@ static int bcm_vk_probe(struct pci_dev *pdev, const struct pci_device_id *ent) goto err_destroy_workqueue; } +snprintf (name,sizeof (name),KBUILD_MODNAME ".%d_ttyVK" , id); + err =bcm_vk_tty_init (vk, name); +if (err) + goto err_unregister_panic_notifier; +/* * 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.
@@ -1426,7 +1445,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_unregister_panic_notifier; + goto err_bcm_vk_tty_exit; }else { dev_err(dev, "Auto-load skipped - BROM not in proper state (0x%x)\n",
@@ -1441,6 +1460,9 @@ static int bcm_vk_probe(struct pci_dev *pdev, const struct pci_device_id *ent)return 0 ; +err_bcm_vk_tty_exit: +bcm_vk_tty_exit (vk); + err_unregister_panic_notifier:atomic_notifier_chain_unregister (&panic_notifier_list, &vk->panic_nb);
@@ -1521,6 +1543,7 @@ static void bcm_vk_remove(struct pci_dev *pdev)bcm_vk_sysfs_exit (pdev, misc_device);bcm_vk_msg_remove (vk); +bcm_vk_tty_exit (vk);if (vk->tdma_vaddr) dma_free_coherent(&pdev->dev, nr_scratch_pages * PAGE_SIZE,
@@ -1540,6 +1563,8 @@ static void bcm_vk_remove(struct pci_dev *pdev)cancel_work_sync (&vk->wq_work);destroy_workqueue (vk->wq_thread); +cancel_work_sync (&vk->tty_wq_work); +destroy_workqueue (vk->tty_wq_thread);for (i =0 ; i <MAX_BAR ; i++) {if (vk->bar[i])
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
Re: [PATCH v5 15/15] misc: bcm-vk: add ttyVK support
Quoted 7 lines · Scott Branden
Add 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_ttyVKywhere:
x is the instance of the VK card
y is the tty device number on the VK cardSigned-off-by Scott Branden <[email protected]>
Was it not possible to:
- emulate a standard 8250 UART and just expose an additional bar + MSI vector such that one could get a debug UART out of this device with little to no work on the host side?
- or use virtio console and implement virtio on the firmware that runs on VK?
It's not a lot of code, but it just feels like this should not have to be done at all.
Signature · 1 line
Florian
Scott Branden
maintainerRe: [PATCH v5 15/15] misc: bcm-vk: add ttyVK support
Hi Florian,
Quoted 9 lines · Florian Fainelli
Quoted 6 lines · Scott Branden
Add 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_ttyVKywhere:
x is the instance of the VK card
y is the tty device number on the VK card
Quoted 5 lines
Quoted 1 line
Signed-off-by Scott Branden <[email protected]>Was it not possible to:
- emulate a standard 8250 UART and just expose an additional bar + MSI vector such that one could get a debug UART out of this device with little to no work on the host side?
I don't see how such emulation is simpler than what we have. For a standard 8250 UART implementation how would we emulate a FIFO in memory accessible over PCIe. I don't see how to do that with shared memory? Also, we don't have an additional bar available on the PCIe device. There is currently little to no work on the device side using a circular buffer with read and write pointers.
Quoted 2 lines
- or use virtio console and implement virtio on the firmware that runs on VK?
Not that possible as the debug/console UARTs are used inside and outside of linux on the VK card.
Quoted 2 lines
It's not a lot of code, but it just feels like this should not have to be done at all.
If there was a simpler way to do it, yes, I would like a "UART" running over PCIe shared memory via a circular buffer. And that is what the code we developed does.
Quoted 4 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].
Quoted 8 lines
Remaining patches are contained in this series to add Broadcom VK driver. (which depends on
request_firmware_into_bufAPI addition in other patch series [2] being applied first).Please note this patch series will not compile without [2].
[1] https://lore.kernel.org/lkml/[email protected]/
[2] https://lore.kernel.org/lkml/[email protected]/
Disclaimer: I am well aware that it is the complete wild west right now as far as accelerators go and that every vendor (that I happen to work for, just not in the same group as Scott) is just seeking to get their drivers included upstream and hopefully for good reasons.
From a cursory look however, it sounds like there could be a little better re-utilization of standards, standard framework and interfaces:
- about 2/3 of your sysfs attributes should incline you to implement a HWMON device, not a complicated one, but anything that indicates current, power, temperature, alerts etc. should be considered
- cannot the firmware loading be supported over remoteproc somehow?
- could not the TTY interface be using virtio or an existing UART?
- what is the format of the message over BAR2 that you expose in patch 13?
Is there a reference user-space implementation that you can link to this patch submission in case people are curious?
Thanks
Signature · 1 line
Florian
Hi,
Quoted 12 lines · Florian Fainelli
Quoted 10 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 in other patch series [2] being applied first).Please note this patch series will not compile without [2].
Quoted 7 lines
Quoted 2 lines
[1] https://lore.kernel.org/lkml/[email protected]/
[2] https://lore.kernel.org/lkml/[email protected]/Disclaimer: I am well aware that it is the complete wild west right now as far as accelerators go and that every vendor (that I happen to work for, just not in the same group as Scott) is just seeking to get their drivers included upstream and hopefully for good reasons.
I'm not sure there are ever bad reasons to get code upstreamed?
I've mentioned this before, but until we see the code and implementations we can guess where the likely commonality is, but we'll always miss some of it and overdesign other parts of it. The path of allowing some entropy to later be refactored and made common is something we've done pretty much everywhere, and it's an approach that's been proven to work. While those who have already taken that journey think it's "just a matter of jumping to the end state and just do things the way they did in the end" is shortsighted: They're not at a static endpoint and futureproof solution themselves. Some of these things just need to play out naturally over time.
Luckily, most kernel-facing interfaces are fairly simple and sit as isolated drivers today, so it doesn't add maintainer burden across the rest of the kernel so the cost of letting some of this code in isn't huge. For a few things such as the hwmon and tty aspects it makes sense to integrate better just as you suggested, but the "subdrivers" for that are fairly simple and don't add a lot of dependencies on intricate or complex subsystem features.
Some devices, such as Habana's latest one, is looking at more complex integrations with other subsystems (RDMA/networking), and there's plenty of discussion going on there.
Quoted 2 lines
From a cursory look however, it sounds like there could be a little
better re-utilization of standards, standard framework and interfaces:
I think most of these points are valid, but also not dealbreakers. I'll add my opinions on a couple of them below.
Quoted 3 lines
- about 2/3 of your sysfs attributes should incline you to implement a HWMON device, not a complicated one, but anything that indicates current, power, temperature, alerts etc. should be considered
This likely makes sense, and hopefully isn't too much work to move. Just like with TTY below, if it needs more time it might make sense to take it out of this patchset and follow up with it, since it's useful but not strictly required functionality for the rest of the driver/device.
Quoted 1 line
- cannot the firmware loading be supported over remoteproc somehow?
remoteproc is really useful for devices living in a shared SoC, needing memory carveout, and run control of the coprocessor. In this case the programming model is different, there's a normal/regular PCIe host/device relationship and the process of loading firmware onto a device is something we do in lots of drivers without using remoteproc. I don't think we need to bring that framework into these kind of drivers, unless there are tighter coupling between the host/device to consider for some reason.
Quoted 1 line
- could not the TTY interface be using virtio or an existing UART?
hvc is super convenient to integrate with since all you need is a getchar and putchar implementation, but the others would work as well. I don't have a strong opinion on path forward on this, and if TTY ends up holding up the rest of the driver it might make sense to leave that piece out and merge the rest. I'm not sure we're at that junction quite yet though?
Quoted 4 lines
- what is the format of the message over BAR2 that you expose in patch 13?
Is there a reference user-space implementation that you can link to this patch submission in case people are curious?
-Olof
Scott Branden
maintainerQuoted 13 lines · Florian Fainelli
Quoted 10 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 in other patch series [2] being applied first).Please note this patch series will not compile without [2].
Quoted 8 lines
Quoted 2 lines
[1] https://lore.kernel.org/lkml/[email protected]/
[2] https://lore.kernel.org/lkml/[email protected]/Disclaimer: I am well aware that it is the complete wild west right now as far as accelerators go and that every vendor (that I happen to work for, just not in the same group as Scott) is just seeking to get their drivers included upstream and hopefully for good reasons.
From a cursory look however, it sounds like there could be a little better re-utilization of standards, standard framework and interfaces:
- about 2/3 of your sysfs attributes should incline you to implement a HWMON device, not a complicated one, but anything that indicates current, power, temperature, alerts etc. should be considered
yes, commented in the patch. we'll look at it.
Quoted 2 lines
- cannot the firmware loading be supported over remoteproc somehow?
It doesn't follow remoteproc usage, Olof commented.
Quoted 2 lines
- could not the TTY interface be using virtio or an existing UART?
commented in the patch. I don't see how that would work with existing solutions but open to a simple solution if such exists.
Quoted 2 lines
- what is the format of the message over BAR2 that you expose in patch 13?
proprietary log messages retrieve via user space app and run through post processing
Quoted 2 lines
Is there a reference user-space implementation that you can link to this patch submission in case people are curious?
Published and commented to Greg K-H about this yesterday.
Here is the vk interface library, vkil, and associated unittest and card utilities.
https://github.com/Broadcom/vkil/
Quoted 2 lines
Thanks