soc: Add TmFifo driver for Mellanox BlueField Soc
Subsystems (6)
PATCH 1/4 soc: Add TmFifo driver for Mellanox BlueField Soc
This commit adds the TmFifo driver for Mellanox BlueField Soc. TmFifo is a shared FIFO which enables external host machine to exchange data with the SoC via USB or PCIe. The driver is based on virtio framework and has console and network access enabled.
--- drivers/soc/Kconfig | 1 + drivers/soc/Makefile | 1 + drivers/soc/mellanox/Kconfig | 18 + drivers/soc/mellanox/Makefile | 5 + drivers/soc/mellanox/tmfifo.c | 1265 ++++++++++++++++++++++++++++++++++++ drivers/soc/mellanox/tmfifo_regs.h | 112 ++++ 6 files changed, 1402 insertions(+) create mode 100644 drivers/soc/mellanox/Kconfig create mode 100644 drivers/soc/mellanox/Makefile create mode 100644 drivers/soc/mellanox/tmfifo.c create mode 100644 drivers/soc/mellanox/tmfifo_regs.h
drivers/soc/Kconfig +1 -0
@@ -7,6 +7,7 @@ source "drivers/soc/bcm/Kconfig" source "drivers/soc/fsl/Kconfig" source "drivers/soc/imx/Kconfig" source "drivers/soc/mediatek/Kconfig" +source "drivers/soc/mellanox/Kconfig" source "drivers/soc/qcom/Kconfig" source "drivers/soc/renesas/Kconfig" source "drivers/soc/rockchip/Kconfig"
drivers/soc/Makefile +1 -0
@@ -13,6 +13,7 @@ obj-$(CONFIG_ARCH_GEMINI) += gemini/ obj-$(CONFIG_ARCH_MXC) += imx/ obj-$(CONFIG_SOC_XWAY) += lantiq/ obj-y += mediatek/ +obj-$(CONFIG_SOC_MLNX) += mellanox/ obj-$(CONFIG_ARCH_MESON) += amlogic/ obj-$(CONFIG_ARCH_QCOM) += qcom/ obj-y += renesas/
drivers/soc/mellanox/Kconfig new file +18 -0
@@ -0,0 +1,18 @@ +menuconfig SOC_MLNX + bool "Mellanox SoC drivers" + default y if ARCH_MLNX_BLUEFIELD + +if ARCH_MLNX_BLUEFIELD || COMPILE_TEST + +config MLNX_BLUEFIELD_TMFIFO + tristate "Mellanox BlueField SoC TmFifo driver" + depends on ARM64 + default m + select VIRTIO_CONSOLE + select VIRTIO_NET + help + Say y here to enable TmFifo support. The TmFifo driver provides the + virtio driver framework for the TMFIFO of Mellanox BlueField SoC and + the implementation of a console and network driver. + +endif # ARCH_MLNX_BLUEFIELD
drivers/soc/mellanox/Makefile new file +5 -0
@@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Makefile for Mellanox SoC drivers. +# +obj-$(CONFIG_MLNX_BLUEFIELD_TMFIFO) += tmfifo.o
drivers/soc/mellanox/tmfifo.c new file +1265 -0
1,265 lines not on this page · raw message
drivers/soc/mellanox/tmfifo_regs.h new file +112 -0
112 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH 2/4 arm64: Add Mellanox BlueField SoC config option
This commit introduces config option for Mellanox BlueField SoC, which can be used to build the SoC specific drivers, and enables it by default in configs/defconfig.
--- arch/arm64/Kconfig.platforms | 6 ++++++ arch/arm64/configs/defconfig | 1 + 2 files changed, 7 insertions(+)
arch/arm64/Kconfig.platforms +6 -0
@@ -110,6 +110,12 @@ config ARCH_MESON help This enables support for the Amlogic S905 SoCs. +config ARCH_MLNX_BLUEFIELD + bool "Mellanox BlueField SoC Family" + select SOC_MLNX + help + This enables support for the Mellanox BlueField SoC. + config ARCH_MVEBU bool "Marvell EBU SoC Family" select ARMADA_AP806_SYSCON
arch/arm64/configs/defconfig +1 -0
@@ -43,6 +43,7 @@ CONFIG_ARCH_LG1K=y CONFIG_ARCH_HISI=y CONFIG_ARCH_MEDIATEK=y CONFIG_ARCH_MESON=y +CONFIG_ARCH_MLNX_BLUEFIELD=y CONFIG_ARCH_MVEBU=y CONFIG_ARCH_QCOM=y CONFIG_ARCH_ROCKCHIP=y
Signature · 1 line
1.8.3.1
PATCH 3/4 dt-bindings: soc: Add TmFifo binding for Mellanox BlueField SoC
In reply to Liming Sun--- .../devicetree/bindings/soc/mellanox/tmfifo.txt | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Documentation/devicetree/bindings/soc/mellanox/tmfifo.txt
Documentation/devicetree/bindings/soc/mellanox/tmfifo.txt new file +20 -0
@@ -0,0 +1,20 @@ +* Mellanox BlueField SoC TmFifo + +BlueField TmFifo provides a shared FIFO between the target and the +external host machine, which can be accessed via USB or PCIe. + +Required properties: + +- compatible: Should be "mellanox,bf-tmfifo" +- reg: Physical base address and length of Rx/Tx block +- interrupts: The interrupt number of Rx low water mark, Rx high water mark + Tx low water mark, Tx high water mark respectively. + +Example: + +tmfifo at 800a20 { + compatible = "mellanox,bf-tmfifo"; + reg = <0x00800a20 0x00000018 + 0x00800a40 0x00000018>; + interrupts = <41, 42, 43, 44>; +};
Signature · 1 line
1.8.3.1
PATCH 4/4 MAINTAINERS: Add entry for Mellanox Bluefield Soc
In reply to Liming SunAdd maintainer information for Mellanox BlueField SoC.
--- MAINTAINERS | 8 ++++++++ 1 file changed, 8 insertions(+)
MAINTAINERS +8 -0
@@ -1636,6 +1636,14 @@ L: linux-mediatek at lists.infradead.org (moderated for non-subscribers) S: Maintained F: drivers/phy/mediatek/phy-mtk-tphy.c +ARM/Mellanox BlueField SoC support +M: David Woods <[email protected]> +M: Liming Sun <[email protected]> +L: linux-arm-kernel at lists.infradead.org (moderated for non-subscribers) +S: Maintained +F: drivers/soc/mellanox/* +F: Documentation/devicetree/bindings/soc/mellanox/tmfifo.txt + ARM/MICREL KS8695 ARCHITECTURE M: Greg Ungerer <[email protected]> L: linux-arm-kernel at lists.infradead.org (moderated for non-subscribers)
Signature · 1 line
1.8.3.1
PATCH 1/4 soc: Add TmFifo driver for Mellanox BlueField Soc
In reply to Liming SunOn 25/05/18 17:06, Liming Sun wrote:
[...]
drivers/soc/mellanox/tmfifo.c line 1
Quoted 7 lines
drivers/soc/mellanox/tmfifo.c new file +1
-0@@ -0,0 +1,1265 @@ +// SPDX-License-Identifier: GPL-2.0
This tag doesn't match the included license text...
Quoted 31 lines
drivers/soc/mellanox/tmfifo.c new file +31
-0+/* +* Copyright (c) 2018, Mellanox Technologies. All rights reserved. +* +* This software is available to you under a choice of one of two +* licenses. You may choose to be licensed under the terms of the GNU +* General Public License (GPL) Version 2, available from the file +* COPYING in the main directory of this source tree, or the +* OpenIB.org BSD license below: +* +* Redistribution and use in source and binary forms, with or +* without modification, are permitted provided that the following +* conditions are met: +* +* - Redistributions of source code must retain the above +* copyright notice, this list of conditions and the following +* disclaimer. +* +* - Redistributions in binary form must reproduce the above +* copyright notice, this list of conditions and the following +* disclaimer in the documentation and/or other materials +* provided with the distribution. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +*/
[...]
drivers/soc/mellanox/tmfifo.c line 69
Quoted 8 lines
drivers/soc/mellanox/tmfifo.c new file +8
-0+/* Several utility macros to get/set the register fields. */ +#define TMFIFO_GET_FIELD (reg, field) \ + (((reg) >> field##_SHIFT) & ((1UL << field##_WIDTH) - 1)) + +#define TMFIFO_SET_FIELD (reg, field, value) ({ \ + u64 _mask = ((1UL << field##_WIDTH) - 1) << field##_SHIFT; \ + ((reg) & ~_mask) | (((value) << field##_SHIFT) & _mask); \ +})
There's no need to reinvent <linux/bitfield.h>
[...]
drivers/soc/mellanox/tmfifo.c line 1264
Quoted 3 lines
drivers/soc/mellanox/tmfifo.c new file +3
-0+MODULE_DESCRIPTION ("Mellanox BlueField SoC TMFIFO Driver" ); +MODULE_AUTHOR ("Mellanox Technologies, Ltd" ); +MODULE_LICENSE ("GPL" );
...and this implies yet another different license (since it indicates "GPLv2 or later")
drivers/soc/mellanox/tmfifo_regs.h line 1
Quoted 8 lines
drivers/soc/mellanox/tmfifo.c new file +1
-0+MODULE_VERSION ("0.7" );drivers/soc/mellanox/tmfifo_regs.h new file +1
-0@@ -0,0 +1,112 @@ +// SPDX-License-Identifier: GPL-2.0
Again, this doesn't match the included text. Also, the SPDX comment style is /* */ for headers.
Quoted 31 lines
drivers/soc/mellanox/tmfifo_regs.h new file +31
-0+/* +* Copyright (c) 2018, Mellanox Technologies. All rights reserved. +* +* This software is available to you under a choice of one of two +* licenses. You may choose to be licensed under the terms of the GNU +* General Public License (GPL) Version 2, available from the file +* COPYING in the main directory of this source tree, or the +* OpenIB.org BSD license below: +* +* Redistribution and use in source and binary forms, with or +* without modification, are permitted provided that the following +* conditions are met: +* +* - Redistributions of source code must retain the above +* copyright notice, this list of conditions and the following +* disclaimer. +* +* - Redistributions in binary form must reproduce the above +* copyright notice, this list of conditions and the following +* disclaimer in the documentation and/or other materials +* provided with the distribution. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +*/
[...]
Quoted 7 lines
drivers/soc/mellanox/tmfifo_regs.h new file +7
-0+#ifdef __ASSEMBLER__ +#define _64bit (x) x +#else /* __ASSEMBLER__ */ +#ifdef __tile__ +#define _64bit (x) x ## UL +#else /* __tile__ */ +#define _64bit (x) x ## ULL
drivers/soc/mellanox/tmfifo_regs.h line 53
Quoted 10 lines
drivers/soc/mellanox/tmfifo_regs.h new file +10
-0+#endif /* __tile__ */ +#endif /* __ASSEMBLER */ + +#ifdef __KERNEL__ +#include <linux/types.h> +#else +#include <stdint.h> +#endif + +#ifndef __DOXYGEN__
Given that this is a private header under drivers/, is any of that lot necessary?
Robin.
PATCH 1/4 soc: Add TmFifo driver for Mellanox BlueField Soc
Thanks for the comments! Uploaded patch series v2. Please also see response inline.
- Liming
Quoted 10 lines
-----Original Message-----
From: Robin Murphy [mailto:robin.murphy at arm.com]
Sent: Friday, May 25, 2018 1:15 PM
To: Liming Sun <[email protected]>; Olof Johansson <[email protected]>; Arnd Bergmann <[email protected]>; David Woods <[email protected]>
Cc: devicetree at vger.kernel.org; linux-arm-kernel at lists.infradead.org
Subject: Re: [PATCH v1 1/4] soc: Add TmFifo driver for Mellanox BlueField SocOn 25/05/18 17:06, Liming Sun wrote:
[...]
Quoted 9 lines
drivers/soc/mellanox/tmfifo.c line 1
Quoted 7 lines
drivers/soc/mellanox/tmfifo.c new file +1
-0@@ -0,0 +1,1265 @@ +// SPDX-License-Identifier: GPL-2.0 This tag doesn't match the included license text...
Fixed in patch v2-1/4.
Quoted 40 lines
Quoted 14 lines
drivers/soc/mellanox/tmfifo.c new file +13
-0+/* +* Copyright (c) 2018, Mellanox Technologies. All rights reserved. +* +* This software is available to you under a choice of one of two +* licenses. You may choose to be licensed under the terms of the GNU +* General Public License (GPL) Version 2, available from the file +* COPYING in the main directory of this source tree, or the +* OpenIB.org BSD license below: +* +* Redistribution and use in source and binary forms, with or +* without modification, are permitted provided that the following +* conditions are met: +* drivers/soc/mellanox/tmfifo.c
Quoted 10 lines
drivers/soc/mellanox/tmfifo.c new file +10
-0+* - Redistributions of source code must retain the above +* copyright notice, this list of conditions and the following +* disclaimer. +* +* - Redistributions in binary form must reproduce the above +* copyright notice, this list of conditions and the following +* disclaimer in the documentation and/or other materials +* provided with the distribution. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
drivers/soc/mellanox/tmfifo.c line 25
Quoted 1 line
drivers/soc/mellanox/tmfifo.c new file +1
-0+* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
drivers/soc/mellanox/tmfifo.c line 27
Quoted 2 lines
drivers/soc/mellanox/tmfifo.c new file +2
-0+* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
drivers/soc/mellanox/tmfifo.c line 28
Quoted 1 line
drivers/soc/mellanox/tmfifo.c new file +1
-0+* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
drivers/soc/mellanox/tmfifo.c line 29
Quoted 1 line
drivers/soc/mellanox/tmfifo.c new file +1
-0+* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
drivers/soc/mellanox/tmfifo.c line 30
Quoted 1 line
drivers/soc/mellanox/tmfifo.c new file +1
-0+* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
Quoted 2 lines
drivers/soc/mellanox/tmfifo.c new file +2
-0+* SOFTWARE. +*/ [...]
Quoted 10 lines
drivers/soc/mellanox/tmfifo.c line 69
Quoted 8 lines
drivers/soc/mellanox/tmfifo.c new file +8
-0+/* Several utility macros to get/set the register fields. */ +#define TMFIFO_GET_FIELD (reg, field) \ + (((reg) >> field##_SHIFT) & ((1UL << field##_WIDTH) - 1)) + +#define TMFIFO_SET_FIELD (reg, field, value) ({ \ + u64 _mask = ((1UL << field##_WIDTH) - 1) << field##_SHIFT; \ + ((reg) & ~_mask) | (((value) << field##_SHIFT) & _mask); \ +})There's no need to reinvent <
linux/bitfield.h>
Updated in patch v2-1/4.
Quoted 8 lines
[...]
drivers/soc/mellanox/tmfifo.c line 1264
Quoted 3 lines
drivers/soc/mellanox/tmfifo.c new file +3
-0+MODULE_DESCRIPTION ("Mellanox BlueField SoC TMFIFO Driver" ); +MODULE_AUTHOR ("Mellanox Technologies, Ltd" ); +MODULE_LICENSE ("GPL" );...and this implies yet another different license (since it indicates "GPLv2 or later")
Fixed in patch v2-1/4.
Quoted 4 lines
Review
Quoted 3 lines
drivers/soc/mellanox/tmfifo.c new file +1
-0+MODULE_VERSION ("0.7" );(quoted diff) +0
-0
b/drivers/soc/mellanox/tmfifo_regs.h
Quoted 9 lines
drivers/soc/mellanox/tmfifo_regs.h line 1
Quoted 6 lines
new file mode 100644
index 0000000..b07f353drivers/soc/mellanox/tmfifo_regs.h new file +1
-0@@ -0,0 +1,112 @@ +// SPDX-License-Identifier: GPL-2.0 Again, this doesn't match the included text. Also, the SPDX comment style is /* */ for headers.
Updated in patch v2-1/4.
Quoted 52 lines
Quoted 14 lines
drivers/soc/mellanox/tmfifo_regs.h new file +13
-0+/* +* Copyright (c) 2018, Mellanox Technologies. All rights reserved. +* +* This software is available to you under a choice of one of two +* licenses. You may choose to be licensed under the terms of the GNU +* General Public License (GPL) Version 2, available from the file +* COPYING in the main directory of this source tree, or the +* OpenIB.org BSD license below: +* +* Redistribution and use in source and binary forms, with or +* without modification, are permitted provided that the following +* conditions are met: +* drivers/soc/mellanox/tmfifo_regs.h line 24
Quoted 10 lines
drivers/soc/mellanox/tmfifo_regs.h new file +10
-0+* - Redistributions of source code must retain the above +* copyright notice, this list of conditions and the following +* disclaimer. +* +* - Redistributions in binary form must reproduce the above +* copyright notice, this list of conditions and the following +* disclaimer in the documentation and/or other materials +* provided with the distribution. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
drivers/soc/mellanox/tmfifo_regs.h line 25
Quoted 1 line
drivers/soc/mellanox/tmfifo_regs.h new file +1
-0+* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
drivers/soc/mellanox/tmfifo_regs.h line 27
Quoted 2 lines
drivers/soc/mellanox/tmfifo_regs.h new file +2
-0+* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
drivers/soc/mellanox/tmfifo_regs.h line 28
Quoted 1 line
drivers/soc/mellanox/tmfifo_regs.h new file +1
-0+* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
drivers/soc/mellanox/tmfifo_regs.h line 29
Quoted 1 line
drivers/soc/mellanox/tmfifo_regs.h new file +1
-0+* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
drivers/soc/mellanox/tmfifo_regs.h line 30
Quoted 1 line
drivers/soc/mellanox/tmfifo_regs.h new file +1
-0+* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
Quoted 2 lines
drivers/soc/mellanox/tmfifo_regs.h new file +2
-0+* SOFTWARE. +*/ [...]
Quoted 12 lines
drivers/soc/mellanox/tmfifo_regs.h new file +12
-0+#ifdef __ASSEMBLER__ +#define _64bit (x) x +#else /* __ASSEMBLER__ */ +#ifdef __tile__ +#define _64bit (x) x ## UL +#else /* __tile__ */ +#define _64bit (x) x ## ULL +#endif /* __tile__ */ +#endif /* __ASSEMBLER */ + +#ifdef __KERNEL__ +#include <linux/types.h>
Quoted 8 lines
drivers/soc/mellanox/tmfifo_regs.h line 53
Quoted 5 lines
drivers/soc/mellanox/tmfifo_regs.h new file +5
-0+#else +#include <stdint.h> +#endif + +#ifndef __DOXYGEN__Given that this is a private header under
drivers/, is any of that lot necessary?
Simplified and updated it in patch v2-1/4.
Quoted 2 lines
Robin.
PATCH v2 1/4 soc: Add TmFifo driver for Mellanox BlueField Soc
In reply to Liming SunThis commit adds the TmFifo driver for Mellanox BlueField Soc. TmFifo is a shared FIFO which enables external host machine to exchange data with the SoC via USB or PCIe. The driver is based on virtio framework and has console and network access enabled.
--- drivers/soc/Kconfig | 1 + drivers/soc/Makefile | 1 + drivers/soc/mellanox/Kconfig | 18 + drivers/soc/mellanox/Makefile | 5 + drivers/soc/mellanox/tmfifo.c | 1239 ++++++++++++++++++++++++++++++++++++ drivers/soc/mellanox/tmfifo_regs.h | 75 +++ 6 files changed, 1339 insertions(+) create mode 100644 drivers/soc/mellanox/Kconfig create mode 100644 drivers/soc/mellanox/Makefile create mode 100644 drivers/soc/mellanox/tmfifo.c create mode 100644 drivers/soc/mellanox/tmfifo_regs.h
drivers/soc/Kconfig +1 -0
@@ -7,6 +7,7 @@ source "drivers/soc/bcm/Kconfig" source "drivers/soc/fsl/Kconfig" source "drivers/soc/imx/Kconfig" source "drivers/soc/mediatek/Kconfig" +source "drivers/soc/mellanox/Kconfig" source "drivers/soc/qcom/Kconfig" source "drivers/soc/renesas/Kconfig" source "drivers/soc/rockchip/Kconfig"
drivers/soc/Makefile +1 -0
@@ -13,6 +13,7 @@ obj-$(CONFIG_ARCH_GEMINI) += gemini/ obj-$(CONFIG_ARCH_MXC) += imx/ obj-$(CONFIG_SOC_XWAY) += lantiq/ obj-y += mediatek/ +obj-$(CONFIG_SOC_MLNX) += mellanox/ obj-$(CONFIG_ARCH_MESON) += amlogic/ obj-$(CONFIG_ARCH_QCOM) += qcom/ obj-y += renesas/
drivers/soc/mellanox/Kconfig new file +18 -0
@@ -0,0 +1,18 @@ +menuconfig SOC_MLNX + bool "Mellanox SoC drivers" + default y if ARCH_MLNX_BLUEFIELD + +if ARCH_MLNX_BLUEFIELD || COMPILE_TEST + +config MLNX_BLUEFIELD_TMFIFO + tristate "Mellanox BlueField SoC TmFifo driver" + depends on ARM64 + default m + select VIRTIO_CONSOLE + select VIRTIO_NET + help + Say y here to enable TmFifo support. The TmFifo driver provides the + virtio driver framework for the TMFIFO of Mellanox BlueField SoC and + the implementation of a console and network driver. + +endif # ARCH_MLNX_BLUEFIELD
drivers/soc/mellanox/Makefile new file +5 -0
@@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Makefile for Mellanox SoC drivers. +# +obj-$(CONFIG_MLNX_BLUEFIELD_TMFIFO) += tmfifo.o
drivers/soc/mellanox/tmfifo.c new file +1239 -0
1,239 lines not on this page · raw message
drivers/soc/mellanox/tmfifo_regs.h new file +75 -0
75 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v2 2/4 arm64: Add Mellanox BlueField SoC config option
This commit introduces config option for Mellanox BlueField SoC, which can be used to build the SoC specific drivers, and enables it by default in configs/defconfig.
--- arch/arm64/Kconfig.platforms | 6 ++++++ arch/arm64/configs/defconfig | 1 + 2 files changed, 7 insertions(+)
arch/arm64/Kconfig.platforms +6 -0
@@ -110,6 +110,12 @@ config ARCH_MESON help This enables support for the Amlogic S905 SoCs. +config ARCH_MLNX_BLUEFIELD + bool "Mellanox BlueField SoC Family" + select SOC_MLNX + help + This enables support for the Mellanox BlueField SoC. + config ARCH_MVEBU bool "Marvell EBU SoC Family" select ARMADA_AP806_SYSCON
arch/arm64/configs/defconfig +1 -0
@@ -43,6 +43,7 @@ CONFIG_ARCH_LG1K=y CONFIG_ARCH_HISI=y CONFIG_ARCH_MEDIATEK=y CONFIG_ARCH_MESON=y +CONFIG_ARCH_MLNX_BLUEFIELD=y CONFIG_ARCH_MVEBU=y CONFIG_ARCH_QCOM=y CONFIG_ARCH_ROCKCHIP=y
Signature · 1 line
1.8.3.1
PATCH v2 3/4 dt-bindings: soc: Add TmFifo binding for Mellanox BlueField SoC
In reply to Liming Sun--- .../devicetree/bindings/soc/mellanox/tmfifo.txt | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Documentation/devicetree/bindings/soc/mellanox/tmfifo.txt
Documentation/devicetree/bindings/soc/mellanox/tmfifo.txt new file +20 -0
@@ -0,0 +1,20 @@ +* Mellanox BlueField SoC TmFifo + +BlueField TmFifo provides a shared FIFO between the target and the +external host machine, which can be accessed via USB or PCIe. + +Required properties: + +- compatible: Should be "mellanox,bf-tmfifo" +- reg: Physical base address and length of Rx/Tx block +- interrupts: The interrupt number of Rx low water mark, Rx high water mark + Tx low water mark, Tx high water mark respectively. + +Example: + +tmfifo at 800a20 { + compatible = "mellanox,bf-tmfifo"; + reg = <0x00800a20 0x00000018 + 0x00800a40 0x00000018>; + interrupts = <41, 42, 43, 44>; +};
Signature · 1 line
1.8.3.1
Rob Herring
maintainerPATCH v2 3/4 dt-bindings: soc: Add TmFifo binding for Mellanox BlueField SoC
On Fri, May 25, 2018 at 04:17:15PM -0400, Liming Sun wrote:
Commit msg?
Quoted 13 lines
Reviewed-by David Woods <[email protected]>Signed-off-by Liming Sun <[email protected]>--- .../devicetree/bindings/soc/mellanox/tmfifo.txt | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Documentation/devicetree/bindings/soc/mellanox/tmfifo.txtDocumentation/devicetree/bindings/soc/mellanox/tmfifo.txt new file +0
-0
Documentation/devicetree/bindings/soc/mellanox/tmfifo.txt line 4
Quoted 4 lines
Documentation/devicetree/bindings/soc/mellanox/tmfifo.txt new file +4
-0@@ -0,0 +1,20 @@ +* Mellanox BlueField SoC TmFifo + +BlueField TmFifo provides a shared FIFO between the target and the +external host machine, which can be accessed via USB or PCIe.
A FIFO for what? I'd like to find a better spot than bindings/soc/
Quoted 23 lines
Documentation/devicetree/bindings/soc/mellanox/tmfifo.txt new file +16
-0+ +Required properties: + +- compatible: Should be "mellanox,bf-tmfifo" +- reg: Physical base address and length of Rx/Tx block +- interrupts: The interrupt number of Rx low water mark, Rx high water mark + Tx low water mark, Tx high water mark respectively. + +Example: + +tmfifo at 800a20 { + compatible = "mellanox,bf-tmfifo"; + reg = <0x00800a20 0x00000018 + 0x00800a40 0x00000018>; + interrupts = <41, 42, 43, 44>; +};Signature · 6 lines
1.8.3.1 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo at vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v2 3/4 dt-bindings: soc: Add TmFifo binding for Mellanox BlueField SoC
Thanks for the comments. Please see response inline.
Quoted 11 lines
-----Original Message-----
From: Rob Herring [mailto:robh at kernel.org]
Sent: Wednesday, May 30, 2018 11:44 PM
To: Liming Sun <[email protected]>
Cc: Olof Johansson <[email protected]>; Arnd Bergmann <[email protected]>; David Woods <[email protected]>; Robin Murphy <[email protected]>; devicetree at vger.kernel.org; linux-arm- kernel at lists.infradead.org
Subject: Re: [PATCH v2 3/4] dt-bindings: soc: Add TmFifo binding for Mellanox BlueField SoC
Quoted 3 lines
On Fri, May 25, 2018 at 04:17:15PM -0400, Liming Sun wrote:
Commit msg?
Updated in patch v3 3/4.
Quoted 12 lines
Quoted 5 lines
Reviewed-by David Woods <[email protected]>Signed-off-by Liming Sun <[email protected]>--- .../devicetree/bindings/soc/mellanox/tmfifo.txt | 20++++++++++++++++++++
Quoted 2 lines
1 file changed, 20 insertions(+) create mode 100644
Documentation/devicetree/bindings/soc/mellanox/tmfifo.txtReview
Quoted 2 lines
(quoted diff) +0
-0
b/Documentation/devicetree/bindings/soc/mellanox/tmfifo.txt
Quoted 11 lines
Documentation/devicetree/bindings/soc/mellanox/tmfifo.txt line 4
Quoted 9 lines
new file mode 100644
index 0000000..0a362f5Documentation/devicetree/bindings/soc/mellanox/tmfifo.txt new file +4
-0@@ -0,0 +1,20 @@ +* Mellanox BlueField SoC TmFifo + +BlueField TmFifo provides a shared FIFO between the target and the +external host machine, which can be accessed via USB or PCIe.A FIFO for what? I'd like to find a better spot than bindings/soc/
This is a generic HW FIFO which can be accessed by the SoC SW and external Host machine to exchange any data. In the current Linux tmfifo driver, this FIFO has been used (demuxed) to implement a virtual console and network interface based on virtio framework.
Updated the tmfifo.txt in patch v3 3/4 with the above explanation. Please advise if there is a better place for this file.
Quoted 24 lines
Documentation/devicetree/bindings/soc/mellanox/tmfifo.txt
Quoted 6 lines
Documentation/devicetree/bindings/soc/mellanox/tmfifo.txt new file +6
-0+ +Required properties: + +- compatible: Should be "mellanox,bf-tmfifo" +- reg: Physical base address and length of Rx/Tx block +- interrupts: The interrupt number of Rx low water mark, Rx high watermark
Quoted 17 lines
Documentation/devicetree/bindings/soc/mellanox/tmfifo.txt new file +10
-1+ Tx low water mark, Tx high water mark respectively. + +Example: + +tmfifo at 800a20 { + compatible = "mellanox,bf-tmfifo"; + reg = <0x00800a20 0x00000018 + 0x00800a40 0x00000018>; + interrupts = <41, 42, 43, 44>; +}; --1.8.3.1
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v2 4/4 MAINTAINERS: Add entry for Mellanox Bluefield Soc
In reply to Liming SunAdd maintainer information for Mellanox BlueField SoC.
--- MAINTAINERS | 8 ++++++++ 1 file changed, 8 insertions(+)
MAINTAINERS +8 -0
@@ -1636,6 +1636,14 @@ L: linux-mediatek at lists.infradead.org (moderated for non-subscribers) S: Maintained F: drivers/phy/mediatek/phy-mtk-tphy.c +ARM/Mellanox BlueField SoC support +M: David Woods <[email protected]> +M: Liming Sun <[email protected]> +L: linux-arm-kernel at lists.infradead.org (moderated for non-subscribers) +S: Maintained +F: drivers/soc/mellanox/* +F: Documentation/devicetree/bindings/soc/mellanox/tmfifo.txt + ARM/MICREL KS8695 ARCHITECTURE M: Greg Ungerer <[email protected]> L: linux-arm-kernel at lists.infradead.org (moderated for non-subscribers)
Signature · 1 line
1.8.3.1
PATCH v3 1/4 soc: Add TmFifo driver for Mellanox BlueField Soc
In reply to Liming SunThis commit adds the TmFifo driver for Mellanox BlueField Soc. TmFifo is a shared FIFO which enables external host machine to exchange data with the SoC via USB or PCIe. The driver is based on virtio framework and has console and network access enabled.
--- drivers/soc/Kconfig | 1 + drivers/soc/Makefile | 1 + drivers/soc/mellanox/Kconfig | 18 + drivers/soc/mellanox/Makefile | 5 + drivers/soc/mellanox/tmfifo.c | 1239 ++++++++++++++++++++++++++++++++++++ drivers/soc/mellanox/tmfifo_regs.h | 75 +++ 6 files changed, 1339 insertions(+) create mode 100644 drivers/soc/mellanox/Kconfig create mode 100644 drivers/soc/mellanox/Makefile create mode 100644 drivers/soc/mellanox/tmfifo.c create mode 100644 drivers/soc/mellanox/tmfifo_regs.h
drivers/soc/Kconfig +1 -0
@@ -7,6 +7,7 @@ source "drivers/soc/bcm/Kconfig" source "drivers/soc/fsl/Kconfig" source "drivers/soc/imx/Kconfig" source "drivers/soc/mediatek/Kconfig" +source "drivers/soc/mellanox/Kconfig" source "drivers/soc/qcom/Kconfig" source "drivers/soc/renesas/Kconfig" source "drivers/soc/rockchip/Kconfig"
drivers/soc/Makefile +1 -0
@@ -13,6 +13,7 @@ obj-$(CONFIG_ARCH_GEMINI) += gemini/ obj-$(CONFIG_ARCH_MXC) += imx/ obj-$(CONFIG_SOC_XWAY) += lantiq/ obj-y += mediatek/ +obj-$(CONFIG_SOC_MLNX) += mellanox/ obj-$(CONFIG_ARCH_MESON) += amlogic/ obj-$(CONFIG_ARCH_QCOM) += qcom/ obj-y += renesas/
drivers/soc/mellanox/Kconfig new file +18 -0
@@ -0,0 +1,18 @@ +menuconfig SOC_MLNX + bool "Mellanox SoC drivers" + default y if ARCH_MLNX_BLUEFIELD + +if ARCH_MLNX_BLUEFIELD || COMPILE_TEST + +config MLNX_BLUEFIELD_TMFIFO + tristate "Mellanox BlueField SoC TmFifo driver" + depends on ARM64 + default m + select VIRTIO_CONSOLE + select VIRTIO_NET + help + Say y here to enable TmFifo support. The TmFifo driver provides the + virtio driver framework for the TMFIFO of Mellanox BlueField SoC and + the implementation of a console and network driver. + +endif # ARCH_MLNX_BLUEFIELD
drivers/soc/mellanox/Makefile new file +5 -0
@@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Makefile for Mellanox SoC drivers. +# +obj-$(CONFIG_MLNX_BLUEFIELD_TMFIFO) += tmfifo.o
drivers/soc/mellanox/tmfifo.c new file +1239 -0
1,239 lines not on this page · raw message
drivers/soc/mellanox/tmfifo_regs.h new file +75 -0
75 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v3 2/4 arm64: Add Mellanox BlueField SoC config option
This commit introduces config option for Mellanox BlueField SoC, which can be used to build the SoC specific drivers, and enables it by default in configs/defconfig.
--- arch/arm64/Kconfig.platforms | 6 ++++++ arch/arm64/configs/defconfig | 1 + 2 files changed, 7 insertions(+)
arch/arm64/Kconfig.platforms +6 -0
@@ -110,6 +110,12 @@ config ARCH_MESON help This enables support for the Amlogic S905 SoCs. +config ARCH_MLNX_BLUEFIELD + bool "Mellanox BlueField SoC Family" + select SOC_MLNX + help + This enables support for the Mellanox BlueField SoC. + config ARCH_MVEBU bool "Marvell EBU SoC Family" select ARMADA_AP806_SYSCON
arch/arm64/configs/defconfig +1 -0
@@ -43,6 +43,7 @@ CONFIG_ARCH_LG1K=y CONFIG_ARCH_HISI=y CONFIG_ARCH_MEDIATEK=y CONFIG_ARCH_MESON=y +CONFIG_ARCH_MLNX_BLUEFIELD=y CONFIG_ARCH_MVEBU=y CONFIG_ARCH_QCOM=y CONFIG_ARCH_ROCKCHIP=y
Signature · 1 line
1.8.3.1
PATCH v3 3/4 dt-bindings: soc: Add TmFifo binding for Mellanox BlueField SoC
In reply to Liming SunAdd devicetree bindings for the TmFifo which is found on Mellanox BlueField SoCs.
--- .../devicetree/bindings/soc/mellanox/tmfifo.txt | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Documentation/devicetree/bindings/soc/mellanox/tmfifo.txt
Documentation/devicetree/bindings/soc/mellanox/tmfifo.txt new file +23 -0
@@ -0,0 +1,23 @@ +* Mellanox BlueField SoC TmFifo + +BlueField TmFifo provides a shared FIFO between the target and the +external host machine, which can be accessed by external host via +USB or PCIe. In the current tmfifo driver, this FIFO has been demuxed +to implement virtual console and network interface based on the virtio +framework. + +Required properties: + +- compatible: Should be "mellanox,bf-tmfifo" +- reg: Physical base address and length of Rx/Tx block +- interrupts: The interrupt number of Rx low water mark, Rx high water mark + Tx low water mark, Tx high water mark respectively. + +Example: + +tmfifo at 800a20 { + compatible = "mellanox,bf-tmfifo"; + reg = <0x00800a20 0x00000018 + 0x00800a40 0x00000018>; + interrupts = <41, 42, 43, 44>; +};
Signature · 1 line
1.8.3.1
Rob Herring
maintainerPATCH v3 3/4 dt-bindings: soc: Add TmFifo binding for Mellanox BlueField SoC
Quoted 9 lines · Liming Sun
Add devicetree bindings for the TmFifo which is found on Mellanox BlueField SoCs.
Reviewed-by David Woods <[email protected]>Signed-off-by Liming Sun <[email protected]>--- .../devicetree/bindings/soc/mellanox/tmfifo.txt | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Documentation/devicetree/bindings/soc/mellanox/tmfifo.txt
PATCH v3 4/4 MAINTAINERS: Add entry for Mellanox Bluefield Soc
In reply to Liming SunAdd maintainer information for Mellanox BlueField SoC.
--- MAINTAINERS | 8 ++++++++ 1 file changed, 8 insertions(+)
MAINTAINERS +8 -0
@@ -1636,6 +1636,14 @@ L: linux-mediatek at lists.infradead.org (moderated for non-subscribers) S: Maintained F: drivers/phy/mediatek/phy-mtk-tphy.c +ARM/Mellanox BlueField SoC support +M: David Woods <[email protected]> +M: Liming Sun <[email protected]> +L: linux-arm-kernel at lists.infradead.org (moderated for non-subscribers) +S: Maintained +F: drivers/soc/mellanox/* +F: Documentation/devicetree/bindings/soc/mellanox/tmfifo.txt + ARM/MICREL KS8695 ARCHITECTURE M: Greg Ungerer <[email protected]> L: linux-arm-kernel at lists.infradead.org (moderated for non-subscribers)
Signature · 1 line
1.8.3.1
PATCH v4 1/4 soc: Add TmFifo driver for Mellanox BlueField Soc
In reply to Liming SunThis commit adds the TmFifo driver for Mellanox BlueField Soc. TmFifo is a shared FIFO which enables external host machine to exchange data with the SoC via USB or PCIe. The driver is based on virtio framework and has console and network access enabled.
--- drivers/soc/Kconfig | 1 + drivers/soc/Makefile | 1 + drivers/soc/mellanox/Kconfig | 18 + drivers/soc/mellanox/Makefile | 5 + drivers/soc/mellanox/tmfifo.c | 1239 ++++++++++++++++++++++++++++++++++++ drivers/soc/mellanox/tmfifo_regs.h | 75 +++ 6 files changed, 1339 insertions(+) create mode 100644 drivers/soc/mellanox/Kconfig create mode 100644 drivers/soc/mellanox/Makefile create mode 100644 drivers/soc/mellanox/tmfifo.c create mode 100644 drivers/soc/mellanox/tmfifo_regs.h
drivers/soc/Kconfig +1 -0
@@ -7,6 +7,7 @@ source "drivers/soc/bcm/Kconfig" source "drivers/soc/fsl/Kconfig" source "drivers/soc/imx/Kconfig" source "drivers/soc/mediatek/Kconfig" +source "drivers/soc/mellanox/Kconfig" source "drivers/soc/qcom/Kconfig" source "drivers/soc/renesas/Kconfig" source "drivers/soc/rockchip/Kconfig"
drivers/soc/Makefile +1 -0
@@ -13,6 +13,7 @@ obj-$(CONFIG_ARCH_GEMINI) += gemini/ obj-$(CONFIG_ARCH_MXC) += imx/ obj-$(CONFIG_SOC_XWAY) += lantiq/ obj-y += mediatek/ +obj-$(CONFIG_SOC_MLNX) += mellanox/ obj-$(CONFIG_ARCH_MESON) += amlogic/ obj-y += qcom/ obj-y += renesas/
drivers/soc/mellanox/Kconfig new file +18 -0
@@ -0,0 +1,18 @@ +menuconfig SOC_MLNX + bool "Mellanox SoC drivers" + default y if ARCH_MLNX_BLUEFIELD + +if ARCH_MLNX_BLUEFIELD || COMPILE_TEST + +config MLNX_BLUEFIELD_TMFIFO + tristate "Mellanox BlueField SoC TmFifo driver" + depends on ARM64 + default m + select VIRTIO_CONSOLE + select VIRTIO_NET + help + Say y here to enable TmFifo support. The TmFifo driver provides the + virtio driver framework for the TMFIFO of Mellanox BlueField SoC and + the implementation of a console and network driver. + +endif # ARCH_MLNX_BLUEFIELD
drivers/soc/mellanox/Makefile new file +5 -0
@@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Makefile for Mellanox SoC drivers. +# +obj-$(CONFIG_MLNX_BLUEFIELD_TMFIFO) += tmfifo.o
drivers/soc/mellanox/tmfifo.c new file +1239 -0
1,239 lines not on this page · raw message
drivers/soc/mellanox/tmfifo_regs.h new file +75 -0
75 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v4 2/4 arm64: Add Mellanox BlueField SoC config option
This commit introduces config option for Mellanox BlueField SoC, which can be used to build the SoC specific drivers, and enables it by default in configs/defconfig.
--- arch/arm64/Kconfig.platforms | 6 ++++++ arch/arm64/configs/defconfig | 1 + 2 files changed, 7 insertions(+)
arch/arm64/Kconfig.platforms +6 -0
@@ -110,6 +110,12 @@ config ARCH_MESON help This enables support for the Amlogic S905 SoCs. +config ARCH_MLNX_BLUEFIELD + bool "Mellanox BlueField SoC Family" + select SOC_MLNX + help + This enables support for the Mellanox BlueField SoC. + config ARCH_MVEBU bool "Marvell EBU SoC Family" select ARMADA_AP806_SYSCON
arch/arm64/configs/defconfig +1 -0
@@ -43,6 +43,7 @@ CONFIG_ARCH_LG1K=y CONFIG_ARCH_HISI=y CONFIG_ARCH_MEDIATEK=y CONFIG_ARCH_MESON=y +CONFIG_ARCH_MLNX_BLUEFIELD=y CONFIG_ARCH_MVEBU=y CONFIG_ARCH_QCOM=y CONFIG_ARCH_ROCKCHIP=y
Signature · 1 line
1.8.3.1
PATCH v4 2/4 arm64: Add Mellanox BlueField SoC config option
Quoted 10 lines · Liming Sun
This commit introduces config option for Mellanox BlueField SoC, which can be used to build the SoC specific drivers, and enables it by default in configs/defconfig.
Reviewed-by David Woods <[email protected]>Signed-off-by Liming Sun <[email protected]>--- arch/arm64/Kconfig.platforms | 6 ++++++ arch/arm64/configs/defconfig | 1 + 2 files changed, 7 insertions(+)
I'm sorry for missing your series in the past. We should definitely merge the platform support soon. Do you also have device tree files for reference systems or even production hardware?
I need to have a separate look at the fifo driver.
Unfortunately, you have sent these patches during the merge window, which is the time during which we don't pick up new work. Let's plan to pick these up after 4.20-rc1, and please resend to arm at kernel.org if we manage to forget about it again.
Arnd
PATCH v4 2/4 arm64: Add Mellanox BlueField SoC config option
Thanks Arnd for the comments! Please see my response inline.
- Liming
Quoted 23 lines
-----Original Message-----
From: arndbergmann at gmail.com [mailto:arndbergmann at gmail.com] On Behalf Of Arnd Bergmann
Sent: Thursday, October 25, 2018 11:38 AM
To: Liming Sun <[email protected]>
Cc: Olof Johansson <[email protected]>; David Woods <[email protected]>; Robin Murphy <[email protected]>; arm- soc <[email protected]>; devicetree at vger.kernel.org; linux-arm- kernel at lists.infradead.org
Subject: Re: [PATCH v4 2/4] arm64: Add Mellanox BlueField SoC config optionQuoted 10 lines · Liming Sun
This commit introduces config option for Mellanox BlueField SoC, which can be used to build the SoC specific drivers, and enables it by default in configs/defconfig.
Reviewed-by David Woods <[email protected]>Signed-off-by Liming Sun <[email protected]>--- arch/arm64/Kconfig.platforms | 6 ++++++ arch/arm64/configs/defconfig | 1 + 2 files changed, 7 insertions(+)
Quoted 5 lines
Reviewed-by Arnd Bergmann <[email protected]>I'm sorry for missing your series in the past. We should definitely merge the platform support soon. Do you also have device tree files for reference systems or even production hardware?
We have obsoleted the device tree, and mainly support ACPI now on Reference/Production HW. Below is the TMFIFO definition in the ACPI DSDT table.
// RShim TMFIFO
Device(RSH0) {
Name(_HID, "MLNXBF01")
Name(_UID, Zero)
Name(_CCA, 1)
Name(_CRS, ResourceTemplate() {
Memory32Fixed(ReadWrite, 0x00800a20, 0x00000018)
Memory32Fixed(ReadWrite, 0x00800a40, 0x00000018)
Interrupt(ResourceConsumer, Edge, ActiveHigh, Exclusive)
{ BF1_RSH0_TM_HTT_LWM_INT,
BF1_RSH0_TM_HTT_HWM_INT,
BF1_RSH0_TM_TTH_LWM_INT,
BF1_RSH0_TM_TTH_HWM_INT
}
})
}The full ACPI implementation can be found in the 1.0 release:
http://www.mellanox.com/downloads/BlueField/BlueField-1.0.0.10521/BlueField-1.0.0.10521.tar.xz
Inside this tarball, we can see the "src/edk2/" directory which has the edk2 patch file including all the ACPI implementation.
Quoted 9 lines
I need to have a separate look at the fifo driver.
Unfortunately, you have sent these patches during the merge window, which is the time during which we don't pick up new work. Let's plan to pick these up after 4.20-rc1, and please resend to arm at kernel.org if we manage to forget about it again.
Arnd
Thanks for the information. I'll resend it to make sure not to miss the date.
PATCH v4 2/4 arm64: Add Mellanox BlueField SoC config option
Quoted 50 lines · Liming Sun
Quoted 23 lines
-----Original Message-----
From: arndbergmann at gmail.com [mailto:arndbergmann at gmail.com] On Behalf Of Arnd Bergmann
Sent: Thursday, October 25, 2018 11:38 AM
To: Liming Sun <[email protected]>
Cc: Olof Johansson <[email protected]>; David Woods <[email protected]>; Robin Murphy <[email protected]>; arm- soc <[email protected]>; devicetree at vger.kernel.org; linux-arm- kernel at lists.infradead.org
Subject: Re: [PATCH v4 2/4] arm64: Add Mellanox BlueField SoC config optionQuoted 10 lines · Liming Sun
This commit introduces config option for Mellanox BlueField SoC, which can be used to build the SoC specific drivers, and enables it by default in configs/defconfig.
Reviewed-by David Woods <[email protected]>Signed-off-by Liming Sun <[email protected]>--- arch/arm64/Kconfig.platforms | 6 ++++++ arch/arm64/configs/defconfig | 1 + 2 files changed, 7 insertions(+)Quoted 5 lines
Reviewed-by Arnd Bergmann <[email protected]>I'm sorry for missing your series in the past. We should definitely merge the platform support soon. Do you also have device tree files for reference systems or even production hardware?
We have obsoleted the device tree, and mainly support ACPI now on Reference/Production HW. Below is the TMFIFO definition in the ACPI DSDT table.
// RShim TMFIFO Device(RSH0) { Name(_HID, "MLNXBF01") Name(_UID, Zero) Name(_CCA, 1) Name(_CRS, ResourceTemplate() { Memory32Fixed(ReadWrite, 0x00800a20, 0x00000018) Memory32Fixed(ReadWrite, 0x00800a40, 0x00000018) Interrupt(ResourceConsumer, Edge, ActiveHigh, Exclusive) { BF1_RSH0_TM_HTT_LWM_INT, BF1_RSH0_TM_HTT_HWM_INT, BF1_RSH0_TM_TTH_LWM_INT, BF1_RSH0_TM_TTH_HWM_INT } }) }
Quoted 3 lines
The full ACPI implementation can be found in the 1.0 release:
http://www.mellanox.com/downloads/BlueField/BlueField-1.0.0.10521/BlueField-1.0.0.10521.tar.xz
Inside this tarball, we can see the "src/edk2/" directory which has the edk2 patch file including all the ACPI implementation.
It would be nice if you could still include the dts sources in the submission. Since this is not a classic server hardware, DT is probably more suitable here, and there are likely use cases that won't work with ACPI, so it's good to have a starting point for your users if they need to override the ACPI tables with a DT, or build systems with a simpler boot loader.
Arnd
PATCH v4 2/4 arm64: Add Mellanox BlueField SoC config option
Thanks! Please see response inline.
- Liming
Quoted 67 lines
-----Original Message-----
From: Arnd Bergmann [mailto:arnd at arndb.de]
Sent: Friday, October 26, 2018 3:32 PM
To: Liming Sun <[email protected]>
Cc: Olof Johansson <[email protected]>; David Woods <[email protected]>; Robin Murphy <[email protected]>; arm- soc <[email protected]>; DTML <[email protected]>; Linux ARM <[email protected]>
Subject: Re: [PATCH v4 2/4] arm64: Add Mellanox BlueField SoC config optionQuoted 7 lines · Liming Sun
Quoted 7 lines
-----Original Message-----
From: arndbergmann at gmail.com [mailto:arndbergmann at gmail.com] On Behalf Of Arnd Bergmann
Sent: Thursday, October 25, 2018 11:38 AM
To: Liming Sun <[email protected]>
Cc: Olof Johansson <[email protected]>; David Woods <[email protected]>; Robin Murphy <[email protected]>;arm-
Quoted 3 lines
Quoted 3 lines
soc <[email protected]>; devicetree at vger.kernel.org; linux-arm- kernel at lists.infradead.org
Subject: Re: [PATCH v4 2/4] arm64: Add Mellanox BlueField SoC configoption
Quoted 13 lines
Quoted 13 lines · Liming Sun
Quoted 10 lines
This commit introduces config option for Mellanox BlueField SoC, which can be used to build the SoC specific drivers, and enables it by default in configs/defconfig.
Reviewed-by David Woods <[email protected]>Signed-off-by Liming Sun <[email protected]>--- arch/arm64/Kconfig.platforms | 6 ++++++ arch/arm64/configs/defconfig | 1 + 2 files changed, 7 insertions(+)Quoted 4 lines
Quoted 4 lines
Reviewed-by Arnd Bergmann <[email protected]>I'm sorry for missing your series in the past. We should definitely merge the platform support soon. Do you also have device tree files for
reference
Quoted 23 lines
Quoted 1 line
systems or even production hardware?
We have obsoleted the device tree, and mainly support ACPI now on Reference/Production HW. Below is the TMFIFO definition in the ACPI DSDT table.
// RShim TMFIFO Device(RSH0) { Name(_HID, "MLNXBF01") Name(_UID, Zero) Name(_CCA, 1) Name(_CRS, ResourceTemplate() { Memory32Fixed(ReadWrite, 0x00800a20, 0x00000018) Memory32Fixed(ReadWrite, 0x00800a40, 0x00000018) Interrupt(ResourceConsumer, Edge, ActiveHigh, Exclusive) { BF1_RSH0_TM_HTT_LWM_INT, BF1_RSH0_TM_HTT_HWM_INT, BF1_RSH0_TM_TTH_LWM_INT, BF1_RSH0_TM_TTH_HWM_INT } }) }Quoted 2 lines
The full ACPI implementation can be found in the 1.0 release:
http://www.mellanox.com/downloads/BlueField/BlueField-1.0.0.10521/BlueField-1.0.0.10521.tar.xz
Quoted 8 lines
Quoted 1 line
Inside this tarball, we can see the "src/edk2/" directory which has the edk2
patch file including all the ACPI implementation.
It would be nice if you could still include the dts sources in the submission. Since this is not a classic server hardware, DT is probably more suitable here, and there are likely use cases that won't work with ACPI, so it's good to have a starting point for your users if they need to override the ACPI tables with a DT, or build systems with a simpler boot loader.
Sure, I'll keep this DT change for reference. A little explanation that Mellanox BlueField SOC could be PCIe NIC or standalone device (server) form which can do PXE boot, CentOS installation even on the NIC, etc. The same software/driver works on both. DT seems not working well for some requirement/features like NVDIMM (which requires ACPI DSM). That's why we switched to ACPI though DT support is preserved.
Quoted 2 lines
Arnd
PATCH v4 2/4 arm64: Add Mellanox BlueField SoC config option
Quoted 10 lines · Liming Sun
Quoted 5 lines
It would be nice if you could still include the dts sources in the submission. Since this is not a classic server hardware, DT is probably more suitable here, and there are likely use cases that won't work with ACPI, so it's good to have a starting point for your users if they need to override the ACPI tables with a DT, or build systems with a simpler boot loader.
Sure, I'll keep this DT change for reference. A little explanation that Mellanox BlueField SOC could be PCIe NIC or standalone device (server) form which can do PXE boot, CentOS installation even on the NIC, etc. The same software/driver works on both.
Ok, good.
Quoted 3 lines
DT seems not working well for some requirement/features like
NVDIMM (which requires ACPI DSM). That's why we switched to ACPI though DT support is preserved.
This is probably something we need to look at separately, I'm sure we will want to use NVDIMM with DT based systems in the future. Can you explain what the DSM is used for here? Is this something that could be done in software in the NVDIMM hardware specific driver?
Arnd
PATCH v4 2/4 arm64: Add Mellanox BlueField SoC config option
Please see my response below.
Quoted 28 lines
-----Original Message-----
From: Arnd Bergmann [mailto:arnd at arndb.de]
Sent: Monday, October 29, 2018 11:26 AM
To: Liming Sun <[email protected]>
Cc: Olof Johansson <[email protected]>; David Woods <[email protected]>; Robin Murphy <[email protected]>; arm- soc <[email protected]>; DTML <[email protected]>; Linux ARM <[email protected]>
Subject: Re: [PATCH v4 2/4] arm64: Add Mellanox BlueField SoC config optionQuoted 8 lines · Liming Sun
Quoted 5 lines
It would be nice if you could still include the dts sources in the submission. Since this is not a classic server hardware, DT is probably more suitable here, and there are likely use cases that won't work with ACPI, so it's good to have a starting point for your users if they need to override the ACPI tables with a DT, or build systems with a simpler boot loader.
Sure, I'll keep this DT change for reference. A little explanation that Mellanox BlueField SOC could be PCIe NIC or standalone device (server)
form which
Quoted 1 line
can do PXE boot, CentOS installation even on the NIC, etc. The same
software/driver
Quoted 1 line
works on both.
Ok, good.
Quoted 2 lines
DT seems not working well for some requirement/features like
NVDIMM (which requires ACPI DSM). That's why we switched to ACPI
Quoted 8 lines
though
Quoted 1 line
DT support is preserved.
This is probably something we need to look at separately, I'm sure we will want
to use NVDIMM with DT based systems in the future. Can you explain what the DSM is used for here? Is this something that could be done in software in the NVDIMM hardware specific driver?
The DSM is kind of running logic instead of configuration which is provided by system firmware. It's defined in the UEFI spec and supported by Linux. In the NVDIMM case here, it's used to do Address Range Scrub (ARS), I2C access (such as reading the DIMM SPD information), runtime health check, etc.
DSM is kind of requirement by NVDIMM, such as
https://pmem.io/documents/NVDIMM_DSM_Interface_Example.pdf
https://docs.microsoft.com/en-us/windows-hardware/drivers/storage/-dsm-interface-for-byte-addressable-energy-backed-function-class--function-interface-1-
By following the ACPI DSM definitions, there is no extra drivers needed in Linux due to the existing ACPI framework. Since it's 'standard' APIs in UEFI, it has potential to support other OS other than Linux.
Hardware specific driver might be able to do some of the functionality, or even 'simulate' some of the ACPI implementation or APIs. I guess it might need a framework for it which I haven't thought a lot of details yet :)
Quoted 2 lines
Arnd
PATCH v4 3/4 dt-bindings: soc: Add TmFifo binding for Mellanox BlueField SoC
In reply to Liming SunAdd devicetree bindings for the TmFifo which is found on Mellanox BlueField SoCs.
--- .../devicetree/bindings/soc/mellanox/tmfifo.txt | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Documentation/devicetree/bindings/soc/mellanox/tmfifo.txt
Documentation/devicetree/bindings/soc/mellanox/tmfifo.txt new file +23 -0
@@ -0,0 +1,23 @@ +* Mellanox BlueField SoC TmFifo + +BlueField TmFifo provides a shared FIFO between the target and the +external host machine, which can be accessed by external host via +USB or PCIe. In the current tmfifo driver, this FIFO has been demuxed +to implement virtual console and network interface based on the virtio +framework. + +Required properties: + +- compatible: Should be "mellanox,bf-tmfifo" +- reg: Physical base address and length of Rx/Tx block +- interrupts: The interrupt number of Rx low water mark, Rx high water mark + Tx low water mark, Tx high water mark respectively. + +Example: + +tmfifo at 800a20 { + compatible = "mellanox,bf-tmfifo"; + reg = <0x00800a20 0x00000018 + 0x00800a40 0x00000018>; + interrupts = <41, 42, 43, 44>; +};
Signature · 1 line
1.8.3.1
PATCH v4 3/4 dt-bindings: soc: Add TmFifo binding for Mellanox BlueField SoC
Quoted 34 lines · Liming Sun
Add devicetree bindings for the TmFifo which is found on Mellanox BlueField SoCs.
Reviewed-by Rob Herring <[email protected]>Reviewed-by David Woods <[email protected]>Signed-off-by Liming Sun <[email protected]>--- .../devicetree/bindings/soc/mellanox/tmfifo.txt | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644
Documentation/devicetree/bindings/soc/mellanox/tmfifo.txtDocumentation/devicetree/bindings/soc/mellanox/tmfifo.txt new file +13
-0@@ -0,0 +1,23 @@ +* Mellanox BlueField SoC TmFifo + +BlueField TmFifo provides a shared FIFO between the target and the +external host machine, which can be accessed by external host via +USB or PCIe. In the current tmfifo driver, this FIFO has been demuxed +to implement virtual console and network interface based on the virtio +framework. + +Required properties: + +- compatible: Should be "mellanox,bf-tmfifo" +- reg: Physical base address and length of Rx/Tx block +- interrupts: The interrupt number of Rx low water mark, Rx high watermark
Documentation/devicetree/bindings/soc/mellanox/tmfifo.txt line 14
Quoted 1 line
Documentation/devicetree/bindings/soc/mellanox/tmfifo.txt new file +1
-0+ Tx low water mark, Tx high water mark respectively.
This sounds like it might fit into the mailbox subsystem, and perhaps it should use the mailbox DT bindings. Have you had a look at that?
Arnd
PATCH v4 3/4 dt-bindings: soc: Add TmFifo binding for Mellanox BlueField SoC
Thanks Arnd for the comments! Please see the response inline.
- Liming
Quoted 44 lines
-----Original Message-----
From: arndbergmann at gmail.com [mailto:arndbergmann at gmail.com] On Behalf Of Arnd Bergmann
Sent: Thursday, October 25, 2018 11:33 AM
To: Liming Sun <[email protected]>
Cc: Olof Johansson <[email protected]>; David Woods <[email protected]>; Robin Murphy <[email protected]>; arm- soc <[email protected]>; devicetree at vger.kernel.org; linux-arm- kernel at lists.infradead.org
Subject: Re: [PATCH v4 3/4] dt-bindings: soc: Add TmFifo binding for Mellanox BlueField SoCQuoted 31 lines · Liming Sun
Add devicetree bindings for the TmFifo which is found on Mellanox BlueField SoCs.
Reviewed-by Rob Herring <[email protected]>Reviewed-by David Woods <[email protected]>Signed-off-by Liming Sun <[email protected]>--- .../devicetree/bindings/soc/mellanox/tmfifo.txt | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644
Documentation/devicetree/bindings/soc/mellanox/tmfifo.txtDocumentation/devicetree/bindings/soc/mellanox/tmfifo.txt new file +11
-0@@ -0,0 +1,23 @@ +* Mellanox BlueField SoC TmFifo + +BlueField TmFifo provides a shared FIFO between the target and the +external host machine, which can be accessed by external host via +USB or PCIe. In the current tmfifo driver, this FIFO has been demuxed +to implement virtual console and network interface based on the virtio +framework. + +Required properties: + +- compatible: Should be "mellanox,bf-tmfifo"
Quoted 8 lines
Documentation/devicetree/bindings/soc/mellanox/tmfifo.txt line 14
Quoted 4 lines
Documentation/devicetree/bindings/soc/mellanox/tmfifo.txt new file +2
-0+- reg: Physical base address and length of Rx/Tx block +- interrupts: The interrupt number of Rx low water mark, Rx high watermark
Documentation/devicetree/bindings/soc/mellanox/tmfifo.txt new file +1
-0+ Tx low water mark, Tx high water mark respectively.This sounds like it might fit into the mailbox subsystem, and perhaps it should use the mailbox DT bindings. Have you had a look at that?
This commit of dt-bindings is mainly to solve the warning of checkpatch.pl. Like the response to patch 2/4, ACPI is actually used now instead of device tree. The TMFIFO definition in the ACPI DSDT table would be something like below.
// RShim TMFIFO
Device(RSH0) {
Name(_HID, "MLNXBF01")
Name(_UID, Zero)
Name(_CCA, 1)
Name(_CRS, ResourceTemplate() {
Memory32Fixed(ReadWrite, 0x00800a20, 0x00000018)
Memory32Fixed(ReadWrite, 0x00800a40, 0x00000018)
Interrupt(ResourceConsumer, Edge, ActiveHigh, Exclusive)
{ BF1_RSH0_TM_HTT_LWM_INT,
BF1_RSH0_TM_HTT_HWM_INT,
BF1_RSH0_TM_TTH_LWM_INT,
BF1_RSH0_TM_TTH_HWM_INT
}
})
}Any suggestion how it should be added into Linux Documentation, or maybe I should just remove this commit from this patch series?
As for the sub-component of this driver, the "soc" might be better fit than the mailbox for some reasons. It's a communication between extern machines and the SoC via USB / PCIe, like pushing boot stream, console and network mgmt. Some of the features, like pushing boot stream, doesn't communicate with the ARM core. The boot stream is pushed to the SoC HW logic directly. I'll add the host-side virtio-based driver in patch v5.
Quoted 2 lines
Arnd
PATCH v4 3/4 dt-bindings: soc: Add TmFifo binding for Mellanox BlueField SoC
Quoted 46 lines · Liming Sun
Quoted 16 lines
-----Original Message-----
From: arndbergmann at gmail.com [mailto:arndbergmann at gmail.com] OnQuoted 14 lines
Documentation/devicetree/bindings/soc/mellanox/tmfifo.txt new file +11
-0@@ -0,0 +1,23 @@ +* Mellanox BlueField SoC TmFifo + +BlueField TmFifo provides a shared FIFO between the target and the +external host machine, which can be accessed by external host via +USB or PCIe. In the current tmfifo driver, this FIFO has been demuxed +to implement virtual console and network interface based on the virtio +framework. + +Required properties: + +- compatible: Should be "mellanox,bf-tmfifo"Quoted 8 lines
Quoted 4 lines
Documentation/devicetree/bindings/soc/mellanox/tmfifo.txt new file +2
-0+- reg: Physical base address and length of Rx/Tx block +- interrupts: The interrupt number of Rx low water mark, Rx high watermark
+ Tx low water mark, Tx high water mark respectively.This sounds like it might fit into the mailbox subsystem, and perhaps it should use the mailbox DT bindings. Have you had a look at that?
This commit of dt-bindings is mainly to solve the warning of checkpatch.pl. Like the response to patch 2/4, ACPI is actually used now instead of device tree. The TMFIFO definition in the ACPI DSDT table would be something like below.
// RShim TMFIFO Device(RSH0) { Name(_HID, "MLNXBF01") Name(_UID, Zero) Name(_CCA, 1) Name(_CRS, ResourceTemplate() { Memory32Fixed(ReadWrite, 0x00800a20, 0x00000018) Memory32Fixed(ReadWrite, 0x00800a40, 0x00000018) Interrupt(ResourceConsumer, Edge, ActiveHigh, Exclusive) { BF1_RSH0_TM_HTT_LWM_INT, BF1_RSH0_TM_HTT_HWM_INT, BF1_RSH0_TM_TTH_LWM_INT, BF1_RSH0_TM_TTH_HWM_INT } }) }
Quoted 2 lines
Any suggestion how it should be added into Linux Documentation, or maybe I should just remove this commit from this patch series?
Maybe the best way here would be to not use ACPI for the case where bluefin is integrated into a PCIe endpoint, since ACPI is not as flexible here and generally relies on having an SBSA compliant hardware that you no longer have if you require random platform devices for booting from and for your console.
For the case where a bluefin SoC is used in a standalone system, having ACPI makes more sense, as that lets you install Red Hat Linux or other operating systems that rely on SBBR and SBSA.
Quoted 5 lines
As for the sub-component of this driver, the "soc" might be better fit than the mailbox for some reasons. It's a communication between extern machines and the SoC via USB / PCIe, like pushing boot stream, console and network mgmt. Some of the features, like pushing boot stream, doesn't communicate with the ARM core. The boot stream is pushed to the SoC HW logic directly. I'll add the host-side virtio-based driver in patch v5.
Right, the drivers/mailbox subsystem was not the right idea here, I noticed that myself after actually reading the driver. Drivers/soc may also not be the best fit, since this is not really about it being a SoC, but rather a way to encapsulate virtual devices. The mic driver I mentioned is in drivers/misc, but I don't like to add stuff there if we can avoid it.
drivers/virtio, drivers/bus or drivers/mfd might also be an option that could fit better than drivers/soc, or you could have your own subdir below drivers/ as some others do. Finally, drivers/platform/mellanox might be a reasonable choice, and it would let you keep both sides of the driver in one place.
Arnd
PATCH v4 3/4 dt-bindings: soc: Add TmFifo binding for Mellanox BlueField SoC
Thanks for the comments! Please see my response/questions inline.
Quoted 71 lines
-----Original Message-----
From: Arnd Bergmann [mailto:arnd at arndb.de]
Sent: Friday, October 26, 2018 4:34 PM
To: Liming Sun <[email protected]>
Cc: Olof Johansson <[email protected]>; David Woods <[email protected]>; Robin Murphy <[email protected]>; arm- soc <[email protected]>; DTML <[email protected]>; Linux ARM <[email protected]>
Subject: Re: [PATCH v4 3/4] dt-bindings: soc: Add TmFifo binding for Mellanox BlueField SoCQuoted 18 lines · Liming Sun
Quoted 18 lines
-----Original Message-----
From: arndbergmann at gmail.com [mailto:arndbergmann at gmail.com] OnQuoted 6 lines
Documentation/devicetree/bindings/soc/mellanox/tmfifo.txt new file +3
-0@@ -0,0 +1,23 @@ +* Mellanox BlueField SoC TmFifo + +BlueField TmFifo provides a shared FIFO between the target and theDocumentation/devicetree/bindings/soc/mellanox/tmfifo.txt line 13
Quoted 10 lines
Documentation/devicetree/bindings/soc/mellanox/tmfifo.txt new file +10
-0+external host machine, which can be accessed by external host via +USB or PCIe. In the current tmfifo driver, this FIFO has been demuxed +to implement virtual console and network interface based on the virtio +framework. + +Required properties: + +- compatible: Should be "mellanox,bf-tmfifo" +- reg: Physical base address and length of Rx/Tx block +- interrupts: The interrupt number of Rx low water mark, Rx highwater
Quoted 9 lines
Quoted 6 lines
Quoted 2 lines
mark
+ Tx low water mark, Tx high water mark respectively.This sounds like it might fit into the mailbox subsystem, and perhaps it should use the mailbox DT bindings. Have you had a look at that?
This commit of dt-bindings is mainly to solve the warning of checkpatch.pl. Like the response to patch 2/4, ACPI is actually used now instead of device
tree.
Quoted 1 line
The TMFIFO definition in the ACPI DSDT table would be something like
below.
Quoted 18 lines
// RShim TMFIFO Device(RSH0) { Name(_HID, "MLNXBF01") Name(_UID, Zero) Name(_CCA, 1) Name(_CRS, ResourceTemplate() { Memory32Fixed(ReadWrite, 0x00800a20, 0x00000018) Memory32Fixed(ReadWrite, 0x00800a40, 0x00000018) Interrupt(ResourceConsumer, Edge, ActiveHigh, Exclusive) { BF1_RSH0_TM_HTT_LWM_INT, BF1_RSH0_TM_HTT_HWM_INT, BF1_RSH0_TM_TTH_LWM_INT, BF1_RSH0_TM_TTH_HWM_INT } }) }Quoted 1 line
Any suggestion how it should be added into Linux Documentation, or maybe
I
Quoted 1 line
should just remove this commit from this patch series?
Maybe the best way here would be to not use ACPI for the case where bluefin is integrated into a PCIe endpoint, since ACPI is not as flexible here and generally relies on having an SBSA compliant hardware that you no longer have if you require random platform devices for booting from and for your console.
Quoted 3 lines
For the case where a bluefin SoC is used in a standalone system, having ACPI makes more sense, as that lets you install Red Hat Linux or other operating systems that rely on SBBR and SBSA.
A little explanation for this SoC:
In the PCIe case, it's not just an endpoint. It can work in a PCIe "multi-host" mode which behaves just like standalone system, such as doing PXE boot and CentOS or other OS installation on the eMMC and boot from it. It can run fully isolated from the x86 host. Below is a link of brief introduction.
http://www.mellanox.com/related-docs/prod_adapter_cards/PB_BlueField_Smart_NIC.pdf
So for now the same SW with ACPI configuration is used on all the boards for simplicity. But I think DT could definitely be used on customized board or when needed.
Quoted 19 lines
Quoted 2 lines
As for the sub-component of this driver, the "soc" might be better fit than
the mailbox
Quoted 1 line
for some reasons. It's a communication between extern machines and the
SoC via
Quoted 1 line
USB / PCIe, like pushing boot stream, console and network mgmt. Some of
the features,
Quoted 1 line
like pushing boot stream, doesn't communicate with the ARM core. The
boot stream
Quoted 1 line
is pushed to the SoC HW logic directly. I'll add the host-side virtio-based
driver in patch v5.
Right, the
drivers/mailboxsubsystem was not the right idea here, I noticed that myself after actually reading the driver. Drivers/soc may also not be the best fit, since this is not really about it being a SoC, but rather a way to encapsulate virtual devices. The mic driver I mentioned is indrivers/misc, but I don't like to add stuff there if we can avoid it.
Quoted 5 lines
drivers/virtio,drivers/busordrivers/mfdmight also be an option that could fit better thandrivers/soc, or you could have your own subdir belowdrivers/as some others do. Finally,drivers/platform/mellanoxmight be a reasonable choice, and it would let you keep both sides of the driver in one place.
We actually have more drivers coming for this SoC, such for I2C, GPIO, PKA, performance counter, L3 cache profile, etc, which could be found at the link below
https://git.launchpad.net/~dcwoods/ubuntu/+source/linux/+git/cosmic/log/?h=mellanox_bluefield
Since it's not just the FIFO driver, any suggestion which one would be better, the "soc" or still the 'platform' ? Thanks!
Quoted 2 lines
Arnd
RE: [PATCH v4 3/4] dt-bindings: soc: Add TmFifo binding for Mellanox BlueField SoC
In reply to Arnd BergmannArnd,
According to the emails and discussions I saw recently, I think that your comments "Finally, drivers/platform/mellanox might be a reasonable choice, and it would let you keep both sides of the driver in one place." does make more sense.
I'll try to resubmit the changes under the drivers/platform/mellanox directory.
Thanks!
Liming
Quoted 88 lines
-----Original Message-----
From: Arnd Bergmann <[email protected]>
Sent: Friday, October 26, 2018 4:34 PM
To: Liming Sun <[email protected]>
Cc: Olof Johansson <[email protected]>; David Woods <[email protected]>; Robin Murphy <[email protected]>; arm-soc <[email protected]>; DTML <[email protected]>; Linux ARM <[email protected]>
Subject: Re: [PATCH v4 3/4] dt-bindings: soc: Add TmFifo binding for Mellanox BlueField SoCQuoted 46 lines · Liming Sun
Quoted 16 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] OnQuoted 14 lines
Documentation/devicetree/bindings/soc/mellanox/tmfifo.txt new file +11
-0@@ -0,0 +1,23 @@ +* Mellanox BlueField SoC TmFifo + +BlueField TmFifo provides a shared FIFO between the target and the +external host machine, which can be accessed by external host via +USB or PCIe. In the current tmfifo driver, this FIFO has been demuxed +to implement virtual console and network interface based on the virtio +framework. + +Required properties: + +- compatible: Should be "mellanox,bf-tmfifo"Quoted 8 lines
Quoted 4 lines
Documentation/devicetree/bindings/soc/mellanox/tmfifo.txt new file +2
-0+- reg: Physical base address and length of Rx/Tx block +- interrupts: The interrupt number of Rx low water mark, Rx high watermark
+ Tx low water mark, Tx high water mark respectively.This sounds like it might fit into the mailbox subsystem, and perhaps it should use the mailbox DT bindings. Have you had a look at that?
This commit of dt-bindings is mainly to solve the warning of checkpatch.pl. Like the response to patch 2/4, ACPI is actually used now instead of device tree. The TMFIFO definition in the ACPI DSDT table would be something like below.
// RShim TMFIFO Device(RSH0) { Name(_HID, "MLNXBF01") Name(_UID, Zero) Name(_CCA, 1) Name(_CRS, ResourceTemplate() { Memory32Fixed(ReadWrite, 0x00800a20, 0x00000018) Memory32Fixed(ReadWrite, 0x00800a40, 0x00000018) Interrupt(ResourceConsumer, Edge, ActiveHigh, Exclusive) { BF1_RSH0_TM_HTT_LWM_INT, BF1_RSH0_TM_HTT_HWM_INT, BF1_RSH0_TM_TTH_LWM_INT, BF1_RSH0_TM_TTH_HWM_INT } }) }Quoted 2 lines
Any suggestion how it should be added into Linux Documentation, or maybe I should just remove this commit from this patch series?
Maybe the best way here would be to not use ACPI for the case where bluefin is integrated into a PCIe endpoint, since ACPI is not as flexible here and generally relies on having an SBSA compliant hardware that you no longer have if you require random platform devices for booting from and for your console.
For the case where a bluefin SoC is used in a standalone system, having ACPI makes more sense, as that lets you install Red Hat Linux or other operating systems that rely on SBBR and SBSA.
Quoted 5 lines
As for the sub-component of this driver, the "soc" might be better fit than the mailbox for some reasons. It's a communication between extern machines and the SoC via USB / PCIe, like pushing boot stream, console and network mgmt. Some of the features, like pushing boot stream, doesn't communicate with the ARM core. The boot stream is pushed to the SoC HW logic directly. I'll add the host-side virtio-based driver in patch v5.
Right, the
drivers/mailboxsubsystem was not the right idea here, I noticed that myself after actually reading the driver. Drivers/soc may also not be the best fit, since this is not really about it being a SoC, but rather a way to encapsulate virtual devices. The mic driver I mentioned is indrivers/misc, but I don't like to add stuff there if we can avoid it.
drivers/virtio,drivers/busordrivers/mfdmight also be an option that could fit better thandrivers/soc, or you could have your own subdir belowdrivers/as some others do. Finally,drivers/platform/mellanoxmight be a reasonable choice, and it would let you keep both sides of the driver in one place.Arnd
PATCH v4 4/4 MAINTAINERS: Add entry for Mellanox Bluefield Soc
In reply to Liming SunAdd maintainer information for Mellanox BlueField SoC.
--- MAINTAINERS | 8 ++++++++ 1 file changed, 8 insertions(+)
MAINTAINERS +8 -0
@@ -1649,6 +1649,14 @@ L: linux-mediatek at lists.infradead.org (moderated for non-subscribers) S: Maintained F: drivers/phy/mediatek/phy-mtk-tphy.c +ARM/Mellanox BlueField SoC support +M: David Woods <[email protected]> +M: Liming Sun <[email protected]> +L: linux-arm-kernel at lists.infradead.org (moderated for non-subscribers) +S: Maintained +F: drivers/soc/mellanox/* +F: Documentation/devicetree/bindings/soc/mellanox/tmfifo.txt + ARM/MICREL KS8695 ARCHITECTURE M: Greg Ungerer <[email protected]> L: linux-arm-kernel at lists.infradead.org (moderated for non-subscribers)
Signature · 1 line
1.8.3.1
PATCH v4 1/4 soc: Add TmFifo driver for Mellanox BlueField Soc
In reply to Liming SunQuoted 7 lines · Liming Sun
This commit adds the TmFifo driver for Mellanox BlueField Soc. TmFifo is a shared FIFO which enables external host machine to exchange data with the SoC via USB or PCIe. The driver is based on virtio framework and has console and network access enabled.
Reviewed-by David Woods <[email protected]>Signed-off-by Liming Sun <[email protected]>
I definitely like the idea of using virtio-net and virtio-console here, this is a great way of reusing the existing high-level drivers, and i similar in concept (but also much simpler) to what we have in drivers/misc/mic/ for another Linux-running machine that can be a PCIe add-on card.
Have you also posted the other half of this driver? I'd like to see how it all fits together.
A few style comments:
drivers/soc/mellanox/tmfifo.c line 46
Quoted 5 lines
drivers/soc/mellanox/tmfifo.c new file +5
-0+ +#define TMFIFO_GET_FIELD (reg, mask) FIELD_GET(mask, reg) + +#define TMFIFO_SET_FIELD (reg, mask, value) \ + ((reg & ~mask) | FIELD_PREP(mask, value))
I think it would be nicer to use FIELD_GET/FIELD_PREP in the code directly, and avoid adding extra wrappers around them.
drivers/soc/mellanox/tmfifo.c line 58
Quoted 11 lines
drivers/soc/mellanox/tmfifo.c new file +11
-0+/* Vring size. */ +#define TMFIFO_VRING_SIZE 1024 + +/* Console Tx buffer size. */ +#define TMFIFO_CONS_TX_BUF_SIZE (32 * 1024) + +/* Use a timer for house-keeping. */ +static int tmfifo_timer_interval =HZ /10 ; + +/* Global lock. */ +static struct mutex tmfifo_lock;
Maybe use 'static DEFINE_MUTEX(tmfifo_lock) here and remove the initialization call.
Quoted 5 lines
drivers/soc/mellanox/tmfifo.c new file +5
-0+/* Virtio ring size. */ +static int tmfifo_vring_size =TMFIFO_VRING_SIZE ; +module_param (tmfifo_vring_size, int,0444 ); +MODULE_PARM_DESC (tmfifo_vring_size,"Size of the vring." ); +
drivers/soc/mellanox/tmfifo.c line 74
Quoted 10 lines
drivers/soc/mellanox/tmfifo.c new file +10
-0+struct tmfifo ; + +/* A flag to indicate TmFifo ready. */ +static bool tmfifo_ready; + +/* Virtual devices sharing the TM FIFO. */ +#define TMFIFO_VDEV_MAX (VIRTIO_ID_CONSOLE + 1) + +/* Spin lock. */ +static DEFINE_SPINLOCK (tmfifo_spin_lock);
Generally speaking, it's nicer to write a driver in a way that avoids global variables and make the flags and locks all members of a device specific structure.
drivers/soc/mellanox/tmfifo.c line 122
Quoted 13 lines
drivers/soc/mellanox/tmfifo.c new file +13
-0+struct tmfifo_vdev { +struct virtio_device vdev;/* virtual device */ +u8 status; +u64 features; +union {/* virtio config space */ +struct virtio_console_config cons; +struct virtio_net_config net; + } config; +struct tmfifo_vring vrings[TMFIFO_VRING_NUM ]; +u8 *tx_buf;/* tx buffer */ +u32 tx_head;/* tx buffer head */ +u32 tx_tail;/* tx buffer tail */ +};
I suppose you did this to keep the driver simple, but it seems a little inflexible
to only support two specific device types. Wouldn't we also want e.g. 9pfs or virtio_blk in some configurations?
Quoted 7 lines
drivers/soc/mellanox/tmfifo.c new file +7
-0+ +#define TMFIFO_VDEV_TX_BUF_AVAIL (vdev) \ + (((vdev)->tx_tail >= (vdev)->tx_head) ? \ + (TMFIFO_CONS_TX_BUF_SIZE - 8 - ((vdev)->tx_tail - (vdev)->tx_head)) : \ + ((vdev)->tx_head - (vdev)->tx_tail - 8)) + +#define TMFIFO_VDEV_TX_BUF_PUSH (vdev, len) do { \
drivers/soc/mellanox/tmfifo.c line 139
Quoted 10 lines
drivers/soc/mellanox/tmfifo.c new file +10
-0+ (vdev)->tx_tail += (len); \ +if ((vdev)->tx_tail >=TMFIFO_CONS_TX_BUF_SIZE ) \ + (vdev)->tx_tail -=TMFIFO_CONS_TX_BUF_SIZE ; \ +} while (0) + +#define TMFIFO_VDEV_TX_BUF_POP (vdev, len) do { \ + (vdev)->tx_head += (len); \ + if ((vdev)->tx_head >= TMFIFO_CONS_TX_BUF_SIZE) \ + (vdev)->tx_head -= TMFIFO_CONS_TX_BUF_SIZE; \ +} while (0)
It would be nicer to turn these into inline functions rather than macros.
Quoted 28 lines
drivers/soc/mellanox/tmfifo.c new file +28
-0+/* TMFIFO device structure */ +struct tmfifo { +struct tmfifo_vdev *vdev[TMFIFO_VDEV_MAX ];/* virtual devices */ +struct platform_device *pdev;/* platform device */ +struct mutex lock; +void __iomem *rx_base;/* mapped register base */ +void __iomem *tx_base;/* mapped register base */ +int tx_fifo_size;/* number of entries of the Tx FIFO */ +int rx_fifo_size;/* number of entries of the Rx FIFO */ +unsigned long pend_events;/* pending bits for deferred process */ +int irq[TM_IRQ_CNT ];/* irq numbers */ +struct work_struct work;/* work struct for deferred process */ +struct timer_list timer;/* keepalive timer */ +struct tmfifo_vring *vring[2 ];/* current Tx/Rx ring */ +}; + +union tmfifo_msg_hdr { +struct { +u8 type;/* message type */ +__be16 len;/* payload length */ +u8 unused[5 ];/* reserved, set to 0 */ + } __packed; +u64 data; +}; + +/* +* Default MAC. +* This MAC address will be read from EFI persistent variable if
Quoted 6 lines
configured.
+ * It can also be reconfigured with standard Linux tools.
+ */
+static u8 tmfifo_net_default_mac[6] = {0x00,0x1A,0xCA,0xFF,0xFF,0x01};
+
Is a predefined MAC address better than a random one here?
For DT based systems, we tend to also call of_get_mac_address() in order to allow setting a unique address from firmware.
drivers/soc/mellanox/tmfifo.c line 185
Quoted 5 lines
drivers/soc/mellanox/tmfifo.c new file +5
-0+/* Forward declaration. */ +static void tmfifo_virtio_rxtx (struct virtqueue *vq,bool is_rx); +static void tmfifo_release_pkt (struct virtio_device *vdev, +struct tmfifo_vring *vring, +struct vring_desc **desc);
Try to avoid forward declarations by reordering the functions according to how they get called.
drivers/soc/mellanox/tmfifo.c line 309
Quoted 12 lines
drivers/soc/mellanox/tmfifo.c new file +12
-0+ +/* Interrupt handler. */ +static irqreturn_t tmfifo_irq_handler (int irq,void *dev_id) +{ +int i = (uintptr_t )dev_id %sizeof (void *); +struct tmfifo *fifo = dev_id - i; + +if (i <TM_IRQ_CNT && !test_and_set_bit (i, &fifo->pend_events)) +schedule_work (&fifo->work); + +return IRQ_HANDLED ; +}
Maybe using a request_threaded_irq() would be a better way to defer the handler into IRQ context.
Arnd
PATCH v4 1/4 soc: Add TmFifo driver for Mellanox BlueField Soc
Thanks Arnd for the comments! Please see the response inline.
- Liming
Quoted 21 lines
-----Original Message-----
From: arndbergmann at gmail.com [mailto:arndbergmann at gmail.com] On Behalf Of Arnd Bergmann
Sent: Thursday, October 25, 2018 11:58 AM
To: Liming Sun <[email protected]>
Cc: Olof Johansson <[email protected]>; David Woods <[email protected]>; Robin Murphy <[email protected]>; arm- soc <[email protected]>; devicetree at vger.kernel.org; linux-arm- kernel at lists.infradead.org
Subject: Re: [PATCH v4 1/4] soc: Add TmFifo driver for Mellanox BlueField SocQuoted 7 lines · Liming Sun
This commit adds the TmFifo driver for Mellanox BlueField Soc. TmFifo is a shared FIFO which enables external host machine to exchange data with the SoC via USB or PCIe. The driver is based on virtio framework and has console and network access enabled.
Reviewed-by David Woods <[email protected]>Signed-off-by Liming Sun <[email protected]>
Quoted 8 lines
I definitely like the idea of using virtio-net and virtio-console here, this is a great way of reusing the existing high-level drivers, and i similar in concept (but also much simpler) to what we have in
drivers/misc/mic/for another Linux-running machine that can be a PCIe add-on card.Have you also posted the other half of this driver? I'd like to see how it all fits together.
I'll add the (x86) host side driver into this patch series v5 as a separate commit.
Quoted 11 lines
A few style comments:
drivers/soc/mellanox/tmfifo.c line 46
Quoted 5 lines
drivers/soc/mellanox/tmfifo.c new file +5
-0+ +#define TMFIFO_GET_FIELD (reg, mask) FIELD_GET(mask, reg) + +#define TMFIFO_SET_FIELD (reg, mask, value) \ + ((reg & ~mask) | FIELD_PREP(mask, value))I think it would be nicer to use FIELD_GET/FIELD_PREP in the code directly, and avoid adding extra wrappers around them.
Will update it in patch v5.
Quoted 15 lines
drivers/soc/mellanox/tmfifo.c line 58
Quoted 12 lines
drivers/soc/mellanox/tmfifo.c new file +11
-0+/* Vring size. */ +#define TMFIFO_VRING_SIZE 1024 + +/* Console Tx buffer size. */ +#define TMFIFO_CONS_TX_BUF_SIZE (32 * 1024) + +/* Use a timer for house-keeping. */ +static int tmfifo_timer_interval =HZ /10 ; + +/* Global lock. */ +static struct mutex tmfifo_lock;Maybe use 'static
DEFINE_MUTEX(tmfifo_lock)here and remove the initialization call.
Will update it in patch v5.
Quoted 12 lines
Quoted 12 lines
drivers/soc/mellanox/tmfifo.c new file +11
-0+/* Virtio ring size. */ +static int tmfifo_vring_size =TMFIFO_VRING_SIZE ; +module_param (tmfifo_vring_size, int,0444 ); +MODULE_PARM_DESC (tmfifo_vring_size,"Size of the vring." ); + +struct tmfifo ; + +/* A flag to indicate TmFifo ready. */ +static bool tmfifo_ready; + +/* Virtual devices sharing the TM FIFO. */
Quoted 8 lines
drivers/soc/mellanox/tmfifo.c line 74
Quoted 4 lines
drivers/soc/mellanox/tmfifo.c new file +4
-0+#define TMFIFO_VDEV_MAX (VIRTIO_ID_CONSOLE + 1) + +/* Spin lock. */ +static DEFINE_SPINLOCK (tmfifo_spin_lock);Generally speaking, it's nicer to write a driver in a way that avoids global variables and make the flags and locks all members of a device specific structure.
Will update it in patch v5.
Quoted 11 lines
Quoted 11 lines
drivers/soc/mellanox/tmfifo.c new file +10
-0+struct tmfifo_vdev { +struct virtio_device vdev;/* virtual device */ +u8 status; +u64 features; +union {/* virtio config space */ +struct virtio_console_config cons; +struct virtio_net_config net; + } config; +struct tmfifo_vring vrings[TMFIFO_VRING_NUM ]; +u8 *tx_buf;/* tx buffer */
Quoted 8 lines
drivers/soc/mellanox/tmfifo.c line 122
Quoted 3 lines
drivers/soc/mellanox/tmfifo.c new file +3
-0+u32 tx_head;/* tx buffer head */ +u32 tx_tail;/* tx buffer tail */ +};I suppose you did this to keep the driver simple, but it seems a little inflexible
to only support two specific device types. Wouldn't we also want e.g. 9pfs orvirtio_blkin some configurations?
We could definitely add more when needed, which should be straightforward due to the virtio framework. For now only network and console are supported and ben been verified.
Quoted 6 lines
drivers/soc/mellanox/tmfifo.c
Quoted 5 lines
drivers/soc/mellanox/tmfifo.c new file +4
-0+ +#define TMFIFO_VDEV_TX_BUF_AVAIL (vdev) \ + (((vdev)->tx_tail >= (vdev)->tx_head) ? \ + (TMFIFO_CONS_TX_BUF_SIZE - 8 - ((vdev)->tx_tail - (vdev)->tx_head)): \
Quoted 15 lines
drivers/soc/mellanox/tmfifo.c line 139
Quoted 13 lines
drivers/soc/mellanox/tmfifo.c new file +13
-0+ ((vdev)->tx_head - (vdev)->tx_tail - 8)) + +#define TMFIFO_VDEV_TX_BUF_PUSH (vdev, len) do { \ + (vdev)->tx_tail += (len); \ + if ((vdev)->tx_tail >= TMFIFO_CONS_TX_BUF_SIZE) \ + (vdev)->tx_tail -= TMFIFO_CONS_TX_BUF_SIZE; \ +} while (0) + +#define TMFIFO_VDEV_TX_BUF_POP (vdev, len) do { \ + (vdev)->tx_head += (len); \ + if ((vdev)->tx_head >= TMFIFO_CONS_TX_BUF_SIZE) \ + (vdev)->tx_head -= TMFIFO_CONS_TX_BUF_SIZE; \ +} while (0)It would be nicer to turn these into inline functions rather than macros.
Will update it in patch v5.
Quoted 40 lines
drivers/soc/mellanox/tmfifo.c
Quoted 11 lines
drivers/soc/mellanox/tmfifo.c new file +10
-0+/* TMFIFO device structure */ +struct tmfifo { +struct tmfifo_vdev *vdev[TMFIFO_VDEV_MAX ];/* virtual devices */ +struct platform_device *pdev;/* platform device */ +struct mutex lock; +void __iomem *rx_base;/* mapped register base */ +void __iomem *tx_base;/* mapped register base */ +int tx_fifo_size;/* number of entries of the Tx FIFO */ +int rx_fifo_size;/* number of entries of the Rx FIFO */ +unsigned long pend_events;/* pending bits for deferred process */
Review
Quoted 2 lines
(quoted diff) +2
-0+ int irq[TM_IRQ_CNT]; /* irq numbers */ + struct work_struct work; /* work struct for deferred process*/
Quoted 16 lines
drivers/soc/mellanox/tmfifo.c new file +16
-0+struct timer_list timer;/* keepalive timer */ +struct tmfifo_vring *vring[2 ];/* current Tx/Rx ring */ +}; + +union tmfifo_msg_hdr { +struct { +u8 type;/* message type */ +__be16 len;/* payload length */ +u8 unused[5 ];/* reserved, set to 0 */ + } __packed; +u64 data; +}; + +/* +* Default MAC. +* This MAC address will be read from EFI persistent variable if Quoted 6 lines
configured.
+ * It can also be reconfigured with standard Linux tools.
+ */
+static u8 tmfifo_net_default_mac[6] = {0x00,0x1A,0xCA,0xFF,0xFF,0x01};
+Is a predefined MAC address better than a random one here?
Quoted 2 lines
For DT based systems, we tend to also call
of_get_mac_address()in order to allow setting a unique address from firmware.
A predefined default MAC address is simpler in this case, which makes DHCP or PXE boot easier in development environment.
For production, the MAC address is stored in persistent UEFI variable on the eeprom, which is read in function tmfifo_get_cfg_mac() which calls efi.get_variable() to get the MAC address.
Quoted 9 lines
drivers/soc/mellanox/tmfifo.c line 185
Quoted 6 lines
drivers/soc/mellanox/tmfifo.c new file +5
-0+/* Forward declaration. */ +static void tmfifo_virtio_rxtx (struct virtqueue *vq,bool is_rx); +static void tmfifo_release_pkt (struct virtio_device *vdev, +struct tmfifo_vring *vring, +struct vring_desc **desc);Try to avoid forward declarations by reordering the functions according to how they get called.
Will update it in patch v5.
Quoted 16 lines
drivers/soc/mellanox/tmfifo.c line 309
Quoted 13 lines
drivers/soc/mellanox/tmfifo.c new file +12
-0+ +/* Interrupt handler. */ +static irqreturn_t tmfifo_irq_handler (int irq,void *dev_id) +{ +int i = (uintptr_t )dev_id %sizeof (void *); +struct tmfifo *fifo = dev_id - i; + +if (i <TM_IRQ_CNT && !test_and_set_bit (i, &fifo->pend_events)) +schedule_work (&fifo->work); + +return IRQ_HANDLED ; +}Maybe using a
request_threaded_irq()would be a better way to defer the handler into IRQ context.
Not sure if I understand this comment correctly... In this case, the implemented handler has some mutex_lock() used, which tries to make the logic simple since multiple services (network & console) are sharing the same fifo. Thus schedule_work() is used.
Quoted 2 lines
Arnd
PATCH v4 1/4 soc: Add TmFifo driver for Mellanox BlueField Soc
Quoted 33 lines · Liming Sun
Quoted 24 lines
-----Original Message-----
From: arndbergmann at gmail.com [mailto:arndbergmann at gmail.com] On Behalf Of Arnd Bergmann
Sent: Thursday, October 25, 2018 11:58 AM
To: Liming Sun <[email protected]>
Cc: Olof Johansson <[email protected]>; David Woods <[email protected]>; Robin Murphy <[email protected]>; arm- soc <[email protected]>; devicetree at vger.kernel.org; linux-arm- kernel at lists.infradead.org
Subject: Re: [PATCH v4 1/4] soc: Add TmFifo driver for Mellanox BlueField SocQuoted 11 lines · Liming Sun
drivers/soc/mellanox/tmfifo.c new file +11
-0+struct tmfifo_vdev { +struct virtio_device vdev;/* virtual device */ +u8 status; +u64 features; +union {/* virtio config space */ +struct virtio_console_config cons; +struct virtio_net_config net; + } config; +struct tmfifo_vring vrings[TMFIFO_VRING_NUM ]; +u8 *tx_buf;/* tx buffer */ +u32 tx_head;/* tx buffer head */ Quoted 8 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ u32 tx_tail; /* tx buffer tail */ +};I suppose you did this to keep the driver simple, but it seems a little inflexible
to only support two specific device types. Wouldn't we also want e.g. 9pfs
orvirtio_blkin some configurations?
Quoted 3 lines
We could definitely add more when needed, which should be straightforward due to the virtio framework. For now only network and console are supported and ben been verified.
Wouldn't that require a new PCI ID to have the driver on the host side match what this side does? I guess I'll see when you post the other driver.
Quoted 42 lines
Quoted 39 lines
drivers/soc/mellanox/tmfifo.c
Quoted 10 lines
drivers/soc/mellanox/tmfifo.c new file +10
-0+/* TMFIFO device structure */ +struct tmfifo { +struct tmfifo_vdev *vdev[TMFIFO_VDEV_MAX ];/* virtual devices */ +struct platform_device *pdev;/* platform device */ +struct mutex lock; +void __iomem *rx_base;/* mapped register base */ +void __iomem *tx_base;/* mapped register base */ +int tx_fifo_size;/* number of entries of the Tx FIFO */ +int rx_fifo_size;/* number of entries of the Rx FIFO */ +unsigned long pend_events;/* pending bits for deferred process */
Review
Quoted 2 lines
(quoted diff) +2
-0+ int irq[TM_IRQ_CNT]; /* irq numbers */ + struct work_struct work; /* work struct for deferred process*/
Quoted 16 lines
drivers/soc/mellanox/tmfifo.c new file +16
-0+struct timer_list timer;/* keepalive timer */ +struct tmfifo_vring *vring[2 ];/* current Tx/Rx ring */ +}; + +union tmfifo_msg_hdr { +struct { +u8 type;/* message type */ +__be16 len;/* payload length */ +u8 unused[5 ];/* reserved, set to 0 */ + } __packed; +u64 data; +}; + +/* +* Default MAC. +* This MAC address will be read from EFI persistent variable if Quoted 6 lines
configured.
+ * It can also be reconfigured with standard Linux tools.
+ */
+static u8 tmfifo_net_default_mac[6] = {0x00,0x1A,0xCA,0xFF,0xFF,0x01};
+Is a predefined MAC address better than a random one here?
Quoted 2 lines
For DT based systems, we tend to also call
of_get_mac_address()in order to allow setting a unique address from firmware.
Quoted 6 lines
A predefined default MAC address is simpler in this case, which makes DHCP or PXE boot easier in development environment.
For production, the MAC address is stored in persistent UEFI variable on the eeprom, which is read in function
tmfifo_get_cfg_mac()which callsefi.get_variable()to get the MAC address.
Ok, fair enough. Generally speaking the recommended way of doing this is to update the DT properties from eeprom when a network driver has no way to store the mac address itself, but I suppose you always have UEFI anyway, and this also makes it work in the same way across both DT and ACPI.
Quoted 15 lines
Quoted 6 lines
Quoted 6 lines
drivers/soc/mellanox/tmfifo.c new file +6
-0+/* Interrupt handler. */ +static irqreturn_t tmfifo_irq_handler (int irq,void *dev_id) +{ +int i = (uintptr_t )dev_id %sizeof (void *); +struct tmfifo *fifo = dev_id - i; +Quoted 8 lines
drivers/soc/mellanox/tmfifo.c line 309
Quoted 5 lines
drivers/soc/mellanox/tmfifo.c new file +5
-0+if (i <TM_IRQ_CNT && !test_and_set_bit (i, &fifo->pend_events)) +schedule_work (&fifo->work); + +return IRQ_HANDLED ; +}Maybe using a
request_threaded_irq()would be a better way to defer the handler into IRQ context.
Quoted 6 lines
Not sure if I understand this comment correctly... In this case, the implemented handler
has somemutex_lock()used, which tries to make the logic simple since multiple services
(network & console) are sharing the same fifo. Thusschedule_work()is used.
schedule_work() and threaded IRQs are just two different ways of deferring into process context where you can do the mutex_lock(). The effect is almost the same, but work queues can be delayed for a substantial amount of time depending on what other work functions have been queued at the same time, and request_threaded_irq() is the more normal way of doing this specifically for an IRQ handler, probably saving a couple of lines of source code.
If you have any kind of real-time requirement, you can also assign a specific realtime priority to that interrupt thread.
Arnd
PATCH v4 1/4 soc: Add TmFifo driver for Mellanox BlueField Soc
Thanks. Please see my response inline.
Quoted 48 lines
-----Original Message-----
From: arndbergmann at gmail.com [mailto:arndbergmann at gmail.com] On Behalf Of Arnd Bergmann
Sent: Friday, October 26, 2018 2:35 PM
To: Liming Sun <[email protected]>
Cc: Olof Johansson <[email protected]>; David Woods <[email protected]>; Robin Murphy <[email protected]>; arm- soc <[email protected]>; devicetree at vger.kernel.org; linux-arm- kernel at lists.infradead.org
Subject: Re: [PATCH v4 1/4] soc: Add TmFifo driver for Mellanox BlueField SocQuoted 7 lines · Liming Sun
Quoted 7 lines
-----Original Message-----
From: arndbergmann at gmail.com [mailto:arndbergmann at gmail.com] On Behalf Of Arnd Bergmann
Sent: Thursday, October 25, 2018 11:58 AM
To: Liming Sun <[email protected]>
Cc: Olof Johansson <[email protected]>; David Woods <[email protected]>; Robin Murphy <[email protected]>;arm-
Quoted 26 lines
Quoted 17 lines
soc <[email protected]>; devicetree at vger.kernel.org; linux-arm- kernel at lists.infradead.org
Subject: Re: [PATCH v4 1/4] soc: Add TmFifo driver for Mellanox BlueField SocQuoted 11 lines · Liming Sun
drivers/soc/mellanox/tmfifo.c new file +11
-0+struct tmfifo_vdev { +struct virtio_device vdev;/* virtual device */ +u8 status; +u64 features; +union {/* virtio config space */ +struct virtio_console_config cons; +struct virtio_net_config net; + } config; +struct tmfifo_vring vrings[TMFIFO_VRING_NUM ]; +u8 *tx_buf;/* tx buffer */ +u32 tx_head;/* tx buffer head */ Quoted 8 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ u32 tx_tail; /* tx buffer tail */ +};I suppose you did this to keep the driver simple, but it seems a little inflexible
to only support two specific device types. Wouldn't we also want e.g. 9pfs
orvirtio_blkin some configurations?Quoted 1 line
We could definitely add more when needed, which should be
Quoted 8 lines
straightforward
Quoted 1 line
due to the virtio framework. For now only network and console are
supported
Quoted 1 line
and ben been verified.
Wouldn't that require a new PCI ID to have the driver on the host side match what this side does? I guess I'll see when you post the other driver.
Yes, the PCI ID is in the host side driver which will be included in patch v5.
Quoted 50 lines
Quoted 43 lines
Quoted 40 lines
drivers/soc/mellanox/tmfifo.c
Quoted 11 lines
drivers/soc/mellanox/tmfifo.c new file +10
-0+/* TMFIFO device structure */ +struct tmfifo { +struct tmfifo_vdev *vdev[TMFIFO_VDEV_MAX ];/* virtual devices */ +struct platform_device *pdev;/* platform device */ +struct mutex lock; +void __iomem *rx_base;/* mapped register base */ +void __iomem *tx_base;/* mapped register base */ +int tx_fifo_size;/* number of entries of the Tx FIFO */ +int rx_fifo_size;/* number of entries of the Rx FIFO */ +unsigned long pend_events;/* pending bits for deferred process */
Review
Quoted 2 lines
(quoted diff) +2
-0+ int irq[TM_IRQ_CNT]; /* irq numbers */ + struct work_struct work; /* work struct for deferred process*/
Quoted 16 lines
drivers/soc/mellanox/tmfifo.c new file +16
-0+struct timer_list timer;/* keepalive timer */ +struct tmfifo_vring *vring[2 ];/* current Tx/Rx ring */ +}; + +union tmfifo_msg_hdr { +struct { +u8 type;/* message type */ +__be16 len;/* payload length */ +u8 unused[5 ];/* reserved, set to 0 */ + } __packed; +u64 data; +}; + +/* +* Default MAC. +* This MAC address will be read from EFI persistent variable if Quoted 6 lines
configured.
+ * It can also be reconfigured with standard Linux tools.
+ */
+static u8 tmfifo_net_default_mac[6] = {0x00,0x1A,0xCA,0xFF,0xFF,0x01};
+Is a predefined MAC address better than a random one here?
Quoted 2 lines
For DT based systems, we tend to also call
of_get_mac_address()in order to allow setting a unique address from firmware.Quoted 6 lines
A predefined default MAC address is simpler in this case, which makes DHCP or PXE boot easier in development environment.
For production, the MAC address is stored in persistent UEFI variable on the eeprom, which is read in function
tmfifo_get_cfg_mac()which callsefi.get_variable()to get the MAC address.
Quoted 5 lines
Ok, fair enough. Generally speaking the recommended way of doing this is to update the DT properties from eeprom when a network driver has no way to store the mac address itself, but I suppose you always have UEFI anyway, and this also makes it work in the same way across both DT and ACPI.
Yes, we always have UEFI available.
Quoted 31 lines
Quoted 16 lines
Quoted 15 lines
drivers/soc/mellanox/tmfifo.c line 309
Quoted 12 lines
drivers/soc/mellanox/tmfifo.c new file +11
-0+/* Interrupt handler. */ +static irqreturn_t tmfifo_irq_handler (int irq,void *dev_id) +{ +int i = (uintptr_t )dev_id %sizeof (void *); +struct tmfifo *fifo = dev_id - i; + +if (i <TM_IRQ_CNT && !test_and_set_bit (i, &fifo->pend_events)) +schedule_work (&fifo->work); + +return IRQ_HANDLED ; +}Maybe using a
request_threaded_irq()would be a better way to defer the handler into IRQ context.Quoted 6 lines
Not sure if I understand this comment correctly... In this case, the implemented handler
has somemutex_lock()used, which tries to make the logic simple since multiple services
(network & console) are sharing the same fifo. Thusschedule_work()is used.
schedule_work()and threaded IRQs are just two different ways of deferring into process context where you can do themutex_lock(). The effect is almost the same, but work queues can be delayed for a substantial amount of time depending on what other work functions have been queued at the same time, andrequest_threaded_irq()is the more normal way of doing this specifically for an IRQ handler, probably saving a couple of lines of source code.
Quoted 2 lines
If you have any kind of real-time requirement, you can also assign a specific realtime priority to that interrupt thread.
Good information! Currently this FIFO is mainly for mgmt purpose. I'll try the threaded IRQs approach to see whether it can be easily converted and make it into the v5 patch. If not easily, probably a separate commit to improve it later?
Quoted 2 lines
Arnd
PATCH v4 1/4 soc: Add TmFifo driver for Mellanox BlueField Soc
Quoted 30 lines · Liming Sun
Quoted 30 lines
Quoted 15 lines
Quoted 6 lines
Quoted 6 lines
drivers/soc/mellanox/tmfifo.c new file +6
-0+/* Interrupt handler. */ +static irqreturn_t tmfifo_irq_handler (int irq,void *dev_id) +{ +int i = (uintptr_t )dev_id %sizeof (void *); +struct tmfifo *fifo = dev_id - i; +Quoted 8 lines
drivers/soc/mellanox/tmfifo.c line 309
Quoted 5 lines
drivers/soc/mellanox/tmfifo.c new file +5
-0+if (i <TM_IRQ_CNT && !test_and_set_bit (i, &fifo->pend_events)) +schedule_work (&fifo->work); + +return IRQ_HANDLED ; +}Maybe using a
request_threaded_irq()would be a better way to defer the handler into IRQ context.Quoted 6 lines
Not sure if I understand this comment correctly... In this case, the implemented handler
has somemutex_lock()used, which tries to make the logic simple since multiple services
(network & console) are sharing the same fifo. Thusschedule_work()is used.
schedule_work()and threaded IRQs are just two different ways of deferring into process context where you can do themutex_lock(). The effect is almost the same, but work queues can be delayed for a substantial amount of time depending on what other work functions have been queued at the same time, andrequest_threaded_irq()is the more normal way of doing this specifically for an IRQ handler, probably saving a couple of lines of source code.
Quoted 6 lines
Quoted 2 lines
If you have any kind of real-time requirement, you can also assign a specific realtime priority to that interrupt thread.
Good information! Currently this FIFO is mainly for mgmt purpose. I'll try the threaded IRQs approach to see whether it can be easily converted and make it into the v5 patch. If not easily, probably a separate commit to improve it later?
Sure, no problem. This is not an important change, but I also think it should be easy to do, in particular as it is meant to simplify the code.
Arnd
Just an update that I have uploaded new patch series v6, which includes the other half of the driver that runs on the external USB host machine, and also tries to resolve the previous comments.
The v6 patches could also be found at
https://patchwork.kernel.org/project/linux-arm-kernel/list/?submitter=176699
Thanks!
-----Original Message-----
From: [email protected] <[email protected]> On Behalf Of Arnd Bergmann
Sent: Thursday, October 25, 2018 11:58 AM
To: Liming Sun <[email protected]>
Cc: Olof Johansson <[email protected]>; David Woods <[email protected]>; Robin Murphy <[email protected]>; arm-soc <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH v4 1/4] soc: Add TmFifo driver for Mellanox BlueField Soc
Quoted 7 lines · Liming Sun
This commit adds the TmFifo driver for Mellanox BlueField Soc. TmFifo is a shared FIFO which enables external host machine to exchange data with the SoC via USB or PCIe. The driver is based on virtio framework and has console and network access enabled.
Reviewed-by David Woods <[email protected]>Signed-off-by Liming Sun <[email protected]>
I definitely like the idea of using virtio-net and virtio-console here, this is a great way of reusing the existing high-level drivers, and i similar in concept (but also much simpler) to what we have in drivers/misc/mic/ for another Linux-running machine that can be a PCIe add-on card.
Have you also posted the other half of this driver? I'd like to see how it all fits together.
A few style comments:
drivers/soc/mellanox/tmfifo.c line 46
Quoted 5 lines
drivers/soc/mellanox/tmfifo.c new file +5
-0+ +#define TMFIFO_GET_FIELD (reg, mask) FIELD_GET(mask, reg) + +#define TMFIFO_SET_FIELD (reg, mask, value) \ + ((reg & ~mask) | FIELD_PREP(mask, value))
I think it would be nicer to use FIELD_GET/FIELD_PREP in the code directly, and avoid adding extra wrappers around them.
drivers/soc/mellanox/tmfifo.c line 58
Quoted 11 lines
drivers/soc/mellanox/tmfifo.c new file +11
-0+/* Vring size. */ +#define TMFIFO_VRING_SIZE 1024 + +/* Console Tx buffer size. */ +#define TMFIFO_CONS_TX_BUF_SIZE (32 * 1024) + +/* Use a timer for house-keeping. */ +static int tmfifo_timer_interval =HZ /10 ; + +/* Global lock. */ +static struct mutex tmfifo_lock;
Maybe use 'static DEFINE_MUTEX(tmfifo_lock) here and remove the initialization call.
Quoted 4 lines
drivers/soc/mellanox/tmfifo.c new file +4
-0+/* Virtio ring size. */ +static int tmfifo_vring_size =TMFIFO_VRING_SIZE ; +module_param (tmfifo_vring_size, int,0444 ); +MODULE_PARM_DESC (tmfifo_vring_size,"Size of the vring." );
drivers/soc/mellanox/tmfifo.c line 74
Quoted 10 lines
drivers/soc/mellanox/tmfifo.c new file +10
-0+ +struct tmfifo ; + +/* A flag to indicate TmFifo ready. */ static bool tmfifo_ready; + +/* Virtual devices sharing the TM FIFO. */ +#define TMFIFO_VDEV_MAX (VIRTIO_ID_CONSOLE + 1) + +/* Spin lock. */ +static DEFINE_SPINLOCK (tmfifo_spin_lock);
Generally speaking, it's nicer to write a driver in a way that avoids global variables and make the flags and locks all members of a device specific structure.
drivers/soc/mellanox/tmfifo.c line 122
Quoted 13 lines
drivers/soc/mellanox/tmfifo.c new file +13
-0+struct tmfifo_vdev { +struct virtio_device vdev;/* virtual device */ +u8 status; +u64 features; +union {/* virtio config space */ +struct virtio_console_config cons; +struct virtio_net_config net; + } config; +struct tmfifo_vring vrings[TMFIFO_VRING_NUM ]; +u8 *tx_buf;/* tx buffer */ +u32 tx_head;/* tx buffer head */ +u32 tx_tail;/* tx buffer tail */ +};
I suppose you did this to keep the driver simple, but it seems a little inflexible to only support two specific device types. Wouldn't we also want e.g. 9pfs or virtio_blk in some configurations?
Quoted 5 lines
drivers/soc/mellanox/tmfifo.c new file +5
-0+ +#define TMFIFO_VDEV_TX_BUF_AVAIL (vdev) \ + (((vdev)->tx_tail >= (vdev)->tx_head) ? \ + (TMFIFO_CONS_TX_BUF_SIZE - 8 - ((vdev)->tx_tail - (vdev)->tx_head)) : \ + ((vdev)->tx_head - (vdev)->tx_tail - 8))
drivers/soc/mellanox/tmfifo.c
Quoted 10 lines
drivers/soc/mellanox/tmfifo.c new file +10
-0+ +#define TMFIFO_VDEV_TX_BUF_PUSH (vdev, len) do { \ + (vdev)->tx_tail += (len); \ + if ((vdev)->tx_tail >= TMFIFO_CONS_TX_BUF_SIZE) \ + (vdev)->tx_tail -= TMFIFO_CONS_TX_BUF_SIZE; \ } while (0) + +#define TMFIFO_VDEV_TX_BUF_POP (vdev, len) do { \ + (vdev)->tx_head += (len); \ + if ((vdev)->tx_head >= TMFIFO_CONS_TX_BUF_SIZE) \ + (vdev)->tx_head -= TMFIFO_CONS_TX_BUF_SIZE; \ } while (0)
It would be nicer to turn these into inline functions rather than macros.
Quoted 28 lines
drivers/soc/mellanox/tmfifo.c new file +28
-0+/* TMFIFO device structure */ +struct tmfifo { +struct tmfifo_vdev *vdev[TMFIFO_VDEV_MAX ];/* virtual devices */ +struct platform_device *pdev;/* platform device */ +struct mutex lock; +void __iomem *rx_base;/* mapped register base */ +void __iomem *tx_base;/* mapped register base */ +int tx_fifo_size;/* number of entries of the Tx FIFO */ +int rx_fifo_size;/* number of entries of the Rx FIFO */ +unsigned long pend_events;/* pending bits for deferred process */ +int irq[TM_IRQ_CNT ];/* irq numbers */ +struct work_struct work;/* work struct for deferred process */ +struct timer_list timer;/* keepalive timer */ +struct tmfifo_vring *vring[2 ];/* current Tx/Rx ring */ +}; + +union tmfifo_msg_hdr { +struct { +u8 type;/* message type */ +__be16 len;/* payload length */ +u8 unused[5 ];/* reserved, set to 0 */ + } __packed; +u64 data; +}; + +/* +* Default MAC. +* This MAC address will be read from EFI persistent variable if
Quoted 6 lines
configured.
+ * It can also be reconfigured with standard Linux tools.
+ */
+static u8 tmfifo_net_default_mac[6] = {0x00,0x1A,0xCA,0xFF,0xFF,0x01};
+
Is a predefined MAC address better than a random one here?
For DT based systems, we tend to also call of_get_mac_address() in order to allow setting a unique address from firmware.
drivers/soc/mellanox/tmfifo.c line 185
Quoted 5 lines
drivers/soc/mellanox/tmfifo.c new file +5
-0+/* Forward declaration. */ +static void tmfifo_virtio_rxtx (struct virtqueue *vq,bool is_rx); +static void tmfifo_release_pkt (struct virtio_device *vdev, +struct tmfifo_vring *vring, +struct vring_desc **desc);
Try to avoid forward declarations by reordering the functions according to how they get called.
drivers/soc/mellanox/tmfifo.c line 309
Quoted 11 lines
drivers/soc/mellanox/tmfifo.c new file +11
-0+ +/* Interrupt handler. */ +static irqreturn_t tmfifo_irq_handler (int irq,void *dev_id) { +int i = (uintptr_t )dev_id %sizeof (void *); +struct tmfifo *fifo = dev_id - i; + +if (i <TM_IRQ_CNT && !test_and_set_bit (i, &fifo->pend_events)) +schedule_work (&fifo->work); + +return IRQ_HANDLED ; +}
Maybe using a request_threaded_irq() would be a better way to defer the handler into IRQ context.
Arnd
PATCH v5 1/5 soc: Add TmFifo driver for Mellanox BlueField Soc
In reply to Liming SunThis commit adds the TmFifo driver for Mellanox BlueField Soc. TmFifo is a shared FIFO which enables external host machine to exchange data with the SoC via USB or PCIe. The driver is based on virtio framework and has console and network access enabled.
--- drivers/soc/Kconfig | 1 + drivers/soc/Makefile | 1 + drivers/soc/mellanox/Kconfig | 18 + drivers/soc/mellanox/Makefile | 5 + drivers/soc/mellanox/tmfifo.c | 1236 ++++++++++++++++++++++++++++++++++++ drivers/soc/mellanox/tmfifo_regs.h | 76 +++ 6 files changed, 1337 insertions(+) create mode 100644 drivers/soc/mellanox/Kconfig create mode 100644 drivers/soc/mellanox/Makefile create mode 100644 drivers/soc/mellanox/tmfifo.c create mode 100644 drivers/soc/mellanox/tmfifo_regs.h
drivers/soc/Kconfig +1 -0
@@ -7,6 +7,7 @@ source "drivers/soc/bcm/Kconfig" source "drivers/soc/fsl/Kconfig" source "drivers/soc/imx/Kconfig" source "drivers/soc/mediatek/Kconfig" +source "drivers/soc/mellanox/Kconfig" source "drivers/soc/qcom/Kconfig" source "drivers/soc/renesas/Kconfig" source "drivers/soc/rockchip/Kconfig"
drivers/soc/Makefile +1 -0
@@ -13,6 +13,7 @@ obj-$(CONFIG_ARCH_GEMINI) += gemini/ obj-$(CONFIG_ARCH_MXC) += imx/ obj-$(CONFIG_SOC_XWAY) += lantiq/ obj-y += mediatek/ +obj-$(CONFIG_SOC_MLNX) += mellanox/ obj-$(CONFIG_ARCH_MESON) += amlogic/ obj-y += qcom/ obj-y += renesas/
drivers/soc/mellanox/Kconfig new file +18 -0
@@ -0,0 +1,18 @@ +menuconfig SOC_MLNX + bool "Mellanox SoC drivers" + default y if ARCH_MLNX_BLUEFIELD + +if ARCH_MLNX_BLUEFIELD || COMPILE_TEST + +config MLNX_BLUEFIELD_TMFIFO + tristate "Mellanox BlueField SoC TmFifo driver" + depends on ARM64 + default m + select VIRTIO_CONSOLE + select VIRTIO_NET + help + Say y here to enable TmFifo support. The TmFifo driver provides the + virtio driver framework for the TMFIFO of Mellanox BlueField SoC and + the implementation of a console and network driver. + +endif # ARCH_MLNX_BLUEFIELD
drivers/soc/mellanox/Makefile new file +5 -0
@@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Makefile for Mellanox SoC drivers. +# +obj-$(CONFIG_MLNX_BLUEFIELD_TMFIFO) += tmfifo.o
drivers/soc/mellanox/tmfifo.c new file +1236 -0
1,236 lines not on this page · raw message
drivers/soc/mellanox/tmfifo_regs.h new file +76 -0
76 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v5 2/5 arm64: Add Mellanox BlueField SoC config option
This commit introduces config option for Mellanox BlueField SoC, which can be used to build the SoC specific drivers, and enables it by default in configs/defconfig.
--- arch/arm64/Kconfig.platforms | 6 ++++++ arch/arm64/configs/defconfig | 1 + 2 files changed, 7 insertions(+)
arch/arm64/Kconfig.platforms +6 -0
@@ -110,6 +110,12 @@ config ARCH_MESON help This enables support for the Amlogic S905 SoCs. +config ARCH_MLNX_BLUEFIELD + bool "Mellanox BlueField SoC Family" + select SOC_MLNX + help + This enables support for the Mellanox BlueField SoC. + config ARCH_MVEBU bool "Marvell EBU SoC Family" select ARMADA_AP806_SYSCON
arch/arm64/configs/defconfig +1 -0
@@ -43,6 +43,7 @@ CONFIG_ARCH_LG1K=y CONFIG_ARCH_HISI=y CONFIG_ARCH_MEDIATEK=y CONFIG_ARCH_MESON=y +CONFIG_ARCH_MLNX_BLUEFIELD=y CONFIG_ARCH_MVEBU=y CONFIG_ARCH_QCOM=y CONFIG_ARCH_ROCKCHIP=y
Signature · 1 line
1.8.3.1
PATCH v5 3/5 dt-bindings: soc: Add TmFifo binding for Mellanox BlueField SoC
In reply to Liming SunAdd devicetree bindings for the TmFifo which is found on Mellanox BlueField SoCs.
--- .../devicetree/bindings/soc/mellanox/tmfifo.txt | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Documentation/devicetree/bindings/soc/mellanox/tmfifo.txt
Documentation/devicetree/bindings/soc/mellanox/tmfifo.txt new file +23 -0
@@ -0,0 +1,23 @@ +* Mellanox BlueField SoC TmFifo + +BlueField TmFifo provides a shared FIFO between the target and the +external host machine, which can be accessed by external host via +USB or PCIe. In the current tmfifo driver, this FIFO has been demuxed +to implement virtual console and network interface based on the virtio +framework. + +Required properties: + +- compatible: Should be "mellanox,bf-tmfifo" +- reg: Physical base address and length of Rx/Tx block +- interrupts: The interrupt number of Rx low water mark, Rx high water mark + Tx low water mark, Tx high water mark respectively. + +Example: + +tmfifo at 800a20 { + compatible = "mellanox,bf-tmfifo"; + reg = <0x00800a20 0x00000018 + 0x00800a40 0x00000018>; + interrupts = <41, 42, 43, 44>; +};
Signature · 1 line
1.8.3.1
PATCH v5 4/5 MAINTAINERS: Add entry for Mellanox Bluefield Soc
In reply to Liming SunAdd maintainer information for Mellanox BlueField SoC.
--- MAINTAINERS | 8 ++++++++ 1 file changed, 8 insertions(+)
MAINTAINERS +8 -0
@@ -1649,6 +1649,14 @@ L: linux-mediatek at lists.infradead.org (moderated for non-subscribers) S: Maintained F: drivers/phy/mediatek/phy-mtk-tphy.c +ARM/Mellanox BlueField SoC support +M: David Woods <[email protected]> +M: Liming Sun <[email protected]> +L: linux-arm-kernel at lists.infradead.org (moderated for non-subscribers) +S: Maintained +F: drivers/soc/mellanox/* +F: Documentation/devicetree/bindings/soc/mellanox/tmfifo.txt + ARM/MICREL KS8695 ARCHITECTURE M: Greg Ungerer <[email protected]> L: linux-arm-kernel at lists.infradead.org (moderated for non-subscribers)
Signature · 1 line
1.8.3.1
PATCH v5 5/5 soc: mellanox: Add host side drivers to support Mellanox BlueField SoCs.
In reply to Liming SunAn external host can connect to a Mellanox BlueField SoC using an interface called the Rshim. The rshim driver provides console, networking and boot services over this interface. There are three possible transports for connecting a host to the rshim and there is a back-end driver for each of them.
rshim_usb - connection via a USB port.
rshim_pcie - connections via PCI express, this is used for boards
in a PCIe form-factor.
rshim_pcie_lf - connectsion via PCI express when the device is
in "livefish" mode where FW is not loaded yet.
--- drivers/soc/mellanox/Kconfig | 8 + drivers/soc/mellanox/Makefile | 1 + drivers/soc/mellanox/host/Makefile | 2 + drivers/soc/mellanox/host/rshim.c | 2673 +++++++++++++++++++++++++++++ drivers/soc/mellanox/host/rshim.h | 361 ++++ drivers/soc/mellanox/host/rshim_net.c | 834 +++++++++ drivers/soc/mellanox/host/rshim_pcie.c | 478 ++++++ drivers/soc/mellanox/host/rshim_pcie_lf.c | 695 ++++++++ drivers/soc/mellanox/host/rshim_regs.h | 163 ++ drivers/soc/mellanox/host/rshim_usb.c | 1035 +++++++++++ 10 files changed, 6250 insertions(+) create mode 100644 drivers/soc/mellanox/host/Makefile create mode 100644 drivers/soc/mellanox/host/rshim.c create mode 100644 drivers/soc/mellanox/host/rshim.h create mode 100644 drivers/soc/mellanox/host/rshim_net.c create mode 100644 drivers/soc/mellanox/host/rshim_pcie.c create mode 100644 drivers/soc/mellanox/host/rshim_pcie_lf.c create mode 100644 drivers/soc/mellanox/host/rshim_regs.h create mode 100644 drivers/soc/mellanox/host/rshim_usb.c
drivers/soc/mellanox/Kconfig +8 -0
@@ -16,3 +16,11 @@ config MLNX_BLUEFIELD_TMFIFO the implementation of a console and network driver. endif # ARCH_MLNX_BLUEFIELD + +config MLNX_BLUEFIELD_HOST + tristate "Mellnox BlueField host side drivers" + help + If you say yes to this option, then support will be added + for control and communication of Mellanox BlueField SoCs + from an external host via USB or PCI-express. +
drivers/soc/mellanox/Makefile +1 -0
@@ -3,3 +3,4 @@ # Makefile for Mellanox SoC drivers. # obj-$(CONFIG_MLNX_BLUEFIELD_TMFIFO) += tmfifo.o +obj-$(CONFIG_MLNX_BLUEFIELD_HOST) += host/
drivers/soc/mellanox/host/Makefile new file +2 -0
@@ -0,0 +1,2 @@ +obj-m := rshim.o rshim_net.o rshim_usb.o rshim_pcie.o rshim_pcie_lf.o +
drivers/soc/mellanox/host/rshim.c new file +2673 -0
2,673 lines not on this page · raw message
drivers/soc/mellanox/host/rshim.h new file +361 -0
310 lines not on this page · raw message
drivers/soc/mellanox/host/rshim_net.c new file +834 -0
834 lines not on this page · raw message
drivers/soc/mellanox/host/rshim_pcie.c new file +478 -0
478 lines not on this page · raw message
drivers/soc/mellanox/host/rshim_pcie_lf.c new file +695 -0
695 lines not on this page · raw message
drivers/soc/mellanox/host/rshim_regs.h new file +163 -0
163 lines not on this page · raw message
drivers/soc/mellanox/host/rshim_usb.c new file +1035 -0
1,035 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.8.3.1
Part of the diff is not shown here. View the raw message.
PATCH v6 1/9 soc: Add TmFifo driver for Mellanox BlueField Soc
In reply to Liming SunThis commit adds the TmFifo driver for Mellanox BlueField Soc. TmFifo is a shared FIFO which enables external host machine to exchange data with the SoC via USB or PCIe. The driver is based on virtio framework and has console and network access enabled.
--- drivers/soc/Kconfig | 1 + drivers/soc/Makefile | 1 + drivers/soc/mellanox/Kconfig | 18 + drivers/soc/mellanox/Makefile | 5 + drivers/soc/mellanox/tmfifo.c | 1236 ++++++++++++++++++++++++++++++++++++ drivers/soc/mellanox/tmfifo_regs.h | 76 +++ 6 files changed, 1337 insertions(+) create mode 100644 drivers/soc/mellanox/Kconfig create mode 100644 drivers/soc/mellanox/Makefile create mode 100644 drivers/soc/mellanox/tmfifo.c create mode 100644 drivers/soc/mellanox/tmfifo_regs.h
drivers/soc/Kconfig +1 -0
@@ -7,6 +7,7 @@ source "drivers/soc/bcm/Kconfig" source "drivers/soc/fsl/Kconfig" source "drivers/soc/imx/Kconfig" source "drivers/soc/mediatek/Kconfig" +source "drivers/soc/mellanox/Kconfig" source "drivers/soc/qcom/Kconfig" source "drivers/soc/renesas/Kconfig" source "drivers/soc/rockchip/Kconfig"
drivers/soc/Makefile +1 -0
@@ -13,6 +13,7 @@ obj-$(CONFIG_ARCH_GEMINI) += gemini/ obj-$(CONFIG_ARCH_MXC) += imx/ obj-$(CONFIG_SOC_XWAY) += lantiq/ obj-y += mediatek/ +obj-$(CONFIG_SOC_MLNX) += mellanox/ obj-$(CONFIG_ARCH_MESON) += amlogic/ obj-y += qcom/ obj-y += renesas/
drivers/soc/mellanox/Kconfig new file +18 -0
@@ -0,0 +1,18 @@ +menuconfig SOC_MLNX + bool "Mellanox SoC drivers" + default y if ARCH_MLNX_BLUEFIELD + +if ARCH_MLNX_BLUEFIELD || COMPILE_TEST + +config MLNX_BLUEFIELD_TMFIFO + tristate "Mellanox BlueField SoC TmFifo driver" + depends on ARM64 + default m + select VIRTIO_CONSOLE + select VIRTIO_NET + help + Say y here to enable TmFifo support. The TmFifo driver provides the + virtio driver framework for the TMFIFO of Mellanox BlueField SoC and + the implementation of a console and network driver. + +endif # ARCH_MLNX_BLUEFIELD
drivers/soc/mellanox/Makefile new file +5 -0
@@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Makefile for Mellanox SoC drivers. +# +obj-$(CONFIG_MLNX_BLUEFIELD_TMFIFO) += tmfifo.o
drivers/soc/mellanox/tmfifo.c new file +1236 -0
1,236 lines not on this page · raw message
drivers/soc/mellanox/tmfifo_regs.h new file +76 -0
76 lines not on this page · raw message
Signature · 1 line
1.8.3.1
On 01/11/2018 17:23, Liming Sun wrote:> This commit adds the TmFifo driver for Mellanox BlueField Soc.
Quoted 19 lines
TmFifo is a shared FIFO which enables external host machine to exchange data with the SoC via USB or PCIe. The driver is based on virtio framework and has console and network access enabled.
Reviewed-by David Woods <[email protected]>Signed-off-by Liming Sun <[email protected]>--- drivers/soc/Kconfig | 1 + drivers/soc/Makefile | 1 + drivers/soc/mellanox/Kconfig | 18 + drivers/soc/mellanox/Makefile | 5 + drivers/soc/mellanox/tmfifo.c | 1236 ++++++++++++++++++++++++++++++++++++ drivers/soc/mellanox/tmfifo_regs.h | 76 +++ 6 files changed, 1337 insertions(+) create mode 100644 drivers/soc/mellanox/Kconfig create mode 100644 drivers/soc/mellanox/Makefile create mode 100644 drivers/soc/mellanox/tmfifo.c create mode 100644 drivers/soc/mellanox/tmfifo_regs.h
[...]
Quoted 13 lines
drivers/soc/mellanox/tmfifo.c new file +13
-0+ +/* Interrupt handler. */ +static irqreturn_t tmfifo_irq_handler (int irq,void *dev_id) +{ +int i = (uintptr_t )dev_id %sizeof (void *); +struct tmfifo *fifo = dev_id - i; + +if (i <TM_IRQ_CNT && !test_and_set_bit (i, &fifo->pend_events)) +schedule_work (&fifo->work); + +return IRQ_HANDLED ; +} +
[...]
Quoted 39 lines
drivers/soc/mellanox/tmfifo.c new file +39
-0+ +/* Probe the TMFIFO. */ +static int tmfifo_probe (struct platform_device *pdev) +{ +u64 ctl; +struct tmfifo *fifo; +struct resource *rx_res, *tx_res; +struct virtio_net_config net_config; +int i, ret; + +/* Get the resource of the Rx & Tx FIFO. */ + rx_res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + tx_res =platform_get_resource (pdev,IORESOURCE_MEM ,1 ); +if (!rx_res || !tx_res) { + ret = -EINVAL ; + goto err; + } + +if (request_mem_region (rx_res->start, +resource_size (rx_res),"bf-tmfifo" ) ==NULL ) { + ret = -EBUSY ; + goto early_err; + } + +if (request_mem_region (tx_res->start, +resource_size (tx_res),"bf-tmfifo" ) ==NULL ) { +release_mem_region (rx_res->start,resource_size (rx_res)); + ret = -EBUSY ; + goto early_err; + } + + ret = -ENOMEM ; + fifo =kzalloc (sizeof (struct tmfifo ),GFP_KERNEL ); +if (!fifo) + goto err; + + fifo->pdev = pdev; +platform_set_drvdata (pdev, fifo); +
drivers/soc/mellanox/tmfifo.c line 1126
Quoted 10 lines
drivers/soc/mellanox/tmfifo.c new file +10
-0+spin_lock_init (&fifo->spin_lock); +INIT_WORK (&fifo->work, tmfifo_work_handler); + +timer_setup (&fifo->timer, tmfifo_timer,0 ); + fifo->timer.function = tmfifo_timer; + +for (i =0 ; i <TM_IRQ_CNT ; i++) { + fifo->irq[i] =platform_get_irq (pdev, i); + ret =request_irq (fifo->irq[i], tmfifo_irq_handler,0 , +"tmfifo" , (u8 *)fifo + i);
I think it would be better if you create a struct that passes a pointer to fifo and the ID instead of "hiding" the ID inside the address.
Regards,
Matthias
Thanks Matthias for the comments and sorry for the holiday delay. The recommended changes have been posted in patch v7 1/9.
Thanks,
Liming
Quoted 103 lines
-----Original Message-----
From: Matthias Brugger <[email protected]>
Sent: Wednesday, December 12, 2018 6:08 PM
To: Liming Sun <[email protected]>; [email protected]; Olof Johansson <[email protected]>; Arnd Bergmann <[email protected]>; David Woods <[email protected]>; Robin Murphy <[email protected]>; arm-soc <[email protected]>
Cc: [email protected]; [email protected]; [email protected] >> Matthias Brugger <[email protected]>
Subject: Re: [PATCH v6 1/9] soc: Add TmFifo driver for Mellanox BlueField SocOn 01/11/2018 17:23, Liming Sun wrote:> This commit adds the TmFifo driver for Mellanox BlueField Soc.
Quoted 19 lines
TmFifo is a shared FIFO which enables external host machine to exchange data with the SoC via USB or PCIe. The driver is based on virtio framework and has console and network access enabled.
Reviewed-by David Woods <[email protected]>Signed-off-by Liming Sun <[email protected]>--- drivers/soc/Kconfig | 1 + drivers/soc/Makefile | 1 + drivers/soc/mellanox/Kconfig | 18 + drivers/soc/mellanox/Makefile | 5 + drivers/soc/mellanox/tmfifo.c | 1236 ++++++++++++++++++++++++++++++++++++ drivers/soc/mellanox/tmfifo_regs.h | 76 +++ 6 files changed, 1337 insertions(+) create mode 100644 drivers/soc/mellanox/Kconfig create mode 100644 drivers/soc/mellanox/Makefile create mode 100644 drivers/soc/mellanox/tmfifo.c create mode 100644 drivers/soc/mellanox/tmfifo_regs.h[...]
Quoted 13 lines
drivers/soc/mellanox/tmfifo.c new file +13
-0+ +/* Interrupt handler. */ +static irqreturn_t tmfifo_irq_handler (int irq,void *dev_id) +{ +int i = (uintptr_t )dev_id %sizeof (void *); +struct tmfifo *fifo = dev_id - i; + +if (i <TM_IRQ_CNT && !test_and_set_bit (i, &fifo->pend_events)) +schedule_work (&fifo->work); + +return IRQ_HANDLED ; +} +[...]
Quoted 39 lines
drivers/soc/mellanox/tmfifo.c new file +39
-0+ +/* Probe the TMFIFO. */ +static int tmfifo_probe (struct platform_device *pdev) +{ +u64 ctl; +struct tmfifo *fifo; +struct resource *rx_res, *tx_res; +struct virtio_net_config net_config; +int i, ret; + +/* Get the resource of the Rx & Tx FIFO. */ + rx_res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + tx_res =platform_get_resource (pdev,IORESOURCE_MEM ,1 ); +if (!rx_res || !tx_res) { + ret = -EINVAL ; + goto err; + } + +if (request_mem_region (rx_res->start, +resource_size (rx_res),"bf-tmfifo" ) ==NULL ) { + ret = -EBUSY ; + goto early_err; + } + +if (request_mem_region (tx_res->start, +resource_size (tx_res),"bf-tmfifo" ) ==NULL ) { +release_mem_region (rx_res->start,resource_size (rx_res)); + ret = -EBUSY ; + goto early_err; + } + + ret = -ENOMEM ; + fifo =kzalloc (sizeof (struct tmfifo ),GFP_KERNEL ); +if (!fifo) + goto err; + + fifo->pdev = pdev; +platform_set_drvdata (pdev, fifo); +drivers/soc/mellanox/tmfifo.c line 1126
Quoted 10 lines
drivers/soc/mellanox/tmfifo.c new file +10
-0+spin_lock_init (&fifo->spin_lock); +INIT_WORK (&fifo->work, tmfifo_work_handler); + +timer_setup (&fifo->timer, tmfifo_timer,0 ); + fifo->timer.function = tmfifo_timer; + +for (i =0 ; i <TM_IRQ_CNT ; i++) { + fifo->irq[i] =platform_get_irq (pdev, i); + ret =request_irq (fifo->irq[i], tmfifo_irq_handler,0 , +"tmfifo" , (u8 *)fifo + i);I think it would be better if you create a struct that passes a pointer to fifo and the ID instead of "hiding" the ID inside the address.
Regards,
Matthias
PATCH v6 1/9 soc: Add TmFifo driver for Mellanox BlueField Soc
In reply to Liming SunThis commit adds the TmFifo driver for Mellanox BlueField Soc. TmFifo is a shared FIFO which enables external host machine to exchange data with the SoC via USB or PCIe. The driver is based on virtio framework and has console and network access enabled.
--- drivers/soc/Kconfig | 1 + drivers/soc/Makefile | 1 + drivers/soc/mellanox/Kconfig | 18 + drivers/soc/mellanox/Makefile | 5 + drivers/soc/mellanox/tmfifo.c | 1236 ++++++++++++++++++++++++++++++++++++ drivers/soc/mellanox/tmfifo_regs.h | 76 +++ 6 files changed, 1337 insertions(+) create mode 100644 drivers/soc/mellanox/Kconfig create mode 100644 drivers/soc/mellanox/Makefile create mode 100644 drivers/soc/mellanox/tmfifo.c create mode 100644 drivers/soc/mellanox/tmfifo_regs.h
drivers/soc/Kconfig +1 -0
@@ -7,6 +7,7 @@ source "drivers/soc/bcm/Kconfig" source "drivers/soc/fsl/Kconfig" source "drivers/soc/imx/Kconfig" source "drivers/soc/mediatek/Kconfig" +source "drivers/soc/mellanox/Kconfig" source "drivers/soc/qcom/Kconfig" source "drivers/soc/renesas/Kconfig" source "drivers/soc/rockchip/Kconfig"
drivers/soc/Makefile +1 -0
@@ -13,6 +13,7 @@ obj-$(CONFIG_ARCH_GEMINI) += gemini/ obj-$(CONFIG_ARCH_MXC) += imx/ obj-$(CONFIG_SOC_XWAY) += lantiq/ obj-y += mediatek/ +obj-$(CONFIG_SOC_MLNX) += mellanox/ obj-$(CONFIG_ARCH_MESON) += amlogic/ obj-y += qcom/ obj-y += renesas/
drivers/soc/mellanox/Kconfig new file +18 -0
@@ -0,0 +1,18 @@ +menuconfig SOC_MLNX + bool "Mellanox SoC drivers" + default y if ARCH_MLNX_BLUEFIELD + +if ARCH_MLNX_BLUEFIELD || COMPILE_TEST + +config MLNX_BLUEFIELD_TMFIFO + tristate "Mellanox BlueField SoC TmFifo driver" + depends on ARM64 + default m + select VIRTIO_CONSOLE + select VIRTIO_NET + help + Say y here to enable TmFifo support. The TmFifo driver provides the + virtio driver framework for the TMFIFO of Mellanox BlueField SoC and + the implementation of a console and network driver. + +endif # ARCH_MLNX_BLUEFIELD
drivers/soc/mellanox/Makefile new file +5 -0
@@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Makefile for Mellanox SoC drivers. +# +obj-$(CONFIG_MLNX_BLUEFIELD_TMFIFO) += tmfifo.o
drivers/soc/mellanox/tmfifo.c new file +1236 -0
1,236 lines not on this page · raw message
drivers/soc/mellanox/tmfifo_regs.h new file +76 -0
76 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v6 2/9 arm64: Add Mellanox BlueField SoC config option
This commit introduces config option for Mellanox BlueField SoC, which can be used to build the SoC specific drivers, and enables it by default in configs/defconfig.
--- arch/arm64/Kconfig.platforms | 6 ++++++ arch/arm64/configs/defconfig | 1 + 2 files changed, 7 insertions(+)
arch/arm64/Kconfig.platforms +6 -0
@@ -117,6 +117,12 @@ config ARCH_MESON help This enables support for the Amlogic S905 SoCs. +config ARCH_MLNX_BLUEFIELD + bool "Mellanox BlueField SoC Family" + select SOC_MLNX + help + This enables support for the Mellanox BlueField SoC. + config ARCH_MVEBU bool "Marvell EBU SoC Family" select ARMADA_AP806_SYSCON
arch/arm64/configs/defconfig +1 -0
@@ -44,6 +44,7 @@ CONFIG_ARCH_LG1K=y CONFIG_ARCH_HISI=y CONFIG_ARCH_MEDIATEK=y CONFIG_ARCH_MESON=y +CONFIG_ARCH_MLNX_BLUEFIELD=y CONFIG_ARCH_MVEBU=y CONFIG_ARCH_QCOM=y CONFIG_ARCH_ROCKCHIP=y
Signature · 1 line
1.8.3.1
PATCH v6 3/9 dt-bindings: soc: Add TmFifo binding for Mellanox BlueField SoC
In reply to Liming SunAdd devicetree bindings for the TmFifo which is found on Mellanox BlueField SoCs.
--- .../devicetree/bindings/soc/mellanox/tmfifo.txt | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Documentation/devicetree/bindings/soc/mellanox/tmfifo.txt
Documentation/devicetree/bindings/soc/mellanox/tmfifo.txt new file +23 -0
@@ -0,0 +1,23 @@ +* Mellanox BlueField SoC TmFifo + +BlueField TmFifo provides a shared FIFO between the target and the +external host machine, which can be accessed by external host via +USB or PCIe. In the current tmfifo driver, this FIFO has been demuxed +to implement virtual console and network interface based on the virtio +framework. + +Required properties: + +- compatible: Should be "mellanox,bf-tmfifo" +- reg: Physical base address and length of Rx/Tx block +- interrupts: The interrupt number of Rx low water mark, Rx high water mark + Tx low water mark, Tx high water mark respectively. + +Example: + +tmfifo at 800a20 { + compatible = "mellanox,bf-tmfifo"; + reg = <0x00800a20 0x00000018 + 0x00800a40 0x00000018>; + interrupts = <41, 42, 43, 44>; +};
Signature · 1 line
1.8.3.1
PATCH v6 4/9 MAINTAINERS: Add entry for Mellanox Bluefield Soc
In reply to Liming SunAdd maintainer information for Mellanox BlueField SoC.
--- MAINTAINERS | 8 ++++++++ 1 file changed, 8 insertions(+)
MAINTAINERS +8 -0
@@ -1694,6 +1694,14 @@ S: Maintained F: drivers/phy/mediatek/ F: Documentation/devicetree/bindings/phy/phy-mtk-* +ARM/Mellanox BlueField SoC support +M: David Woods <[email protected]> +M: Liming Sun <[email protected]> +L: linux-arm-kernel at lists.infradead.org (moderated for non-subscribers) +S: Maintained +F: drivers/soc/mellanox/* +F: Documentation/devicetree/bindings/soc/mellanox/tmfifo.txt + ARM/MICREL KS8695 ARCHITECTURE M: Greg Ungerer <[email protected]> L: linux-arm-kernel at lists.infradead.org (moderated for non-subscribers)
Signature · 1 line
1.8.3.1
PATCH v6 5/9 soc: mellanox: host: Add the common host side Rshim driver
In reply to Liming SunAn external host can connect to a Mellanox BlueField SoC via an interface called Rshim. The Rshim driver provides boot, console, and networking services over this interface. This commit is the common driver where the other backend (transport) driver will use.
--- drivers/soc/mellanox/Kconfig | 8 + drivers/soc/mellanox/Makefile | 1 + drivers/soc/mellanox/host/Makefile | 2 + drivers/soc/mellanox/host/rshim.c | 2673 ++++++++++++++++++++++++++++++++ drivers/soc/mellanox/host/rshim.h | 361 +++++ drivers/soc/mellanox/host/rshim_regs.h | 152 ++ 6 files changed, 3197 insertions(+) create mode 100644 drivers/soc/mellanox/host/Makefile create mode 100644 drivers/soc/mellanox/host/rshim.c create mode 100644 drivers/soc/mellanox/host/rshim.h create mode 100644 drivers/soc/mellanox/host/rshim_regs.h
drivers/soc/mellanox/Kconfig +8 -0
@@ -16,3 +16,11 @@ config MLNX_BLUEFIELD_TMFIFO the implementation of a console and network driver. endif # ARCH_MLNX_BLUEFIELD + +config MLNX_BLUEFIELD_HOST + tristate "Mellnox BlueField host side drivers" + help + If you say yes to this option, then support will be added + for control and communication of Mellanox BlueField SoCs + from an external host via USB or PCI-express. +
drivers/soc/mellanox/Makefile +1 -0
@@ -3,3 +3,4 @@ # Makefile for Mellanox SoC drivers. # obj-$(CONFIG_MLNX_BLUEFIELD_TMFIFO) += tmfifo.o +obj-$(CONFIG_MLNX_BLUEFIELD_HOST) += host/
drivers/soc/mellanox/host/Makefile new file +2 -0
@@ -0,0 +1,2 @@ +obj-m := rshim.o +
drivers/soc/mellanox/host/rshim.c new file +2673 -0
2,673 lines not on this page · raw message
drivers/soc/mellanox/host/rshim.h new file +361 -0
310 lines not on this page · raw message
drivers/soc/mellanox/host/rshim_regs.h new file +152 -0
152 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.8.3.1
Part of the diff is not shown here. View the raw message.
Re: [PATCH v6 5/9] soc: mellanox: host: Add the common host side Rshim driver
Quoted 9 lines · Liming Sun
An external host can connect to a Mellanox BlueField SoC via an interface called Rshim. The Rshim driver provides boot, console, and networking services over this interface. This commit is the common driver where the other backend (transport) driver will use.
Reviewed-by David Woods <[email protected]>Signed-off-by Liming Sun <[email protected]>
Hi Liming,
I've taken a new look at your patch series for drivers/soc/ now, thanks for your continued submissions.
This is again just a set of very high-level comments, but I think we should resolve some of the fundamental questions first. Incidentally, Vincent Whitchurch has recently posted another patch series with a very similar intention, but for other hardware and taking a different approach.
In both cases, the idea is to use virtio based drivers to provide services from a host machine into another Linux instance running on an embedded system behind a PCIe slot or similar. Your Bluefield SoC patches are well written, but are intentionally kept specific to a particular use case and tied to one piece of hardware. In contrast, Vincent uses the existing code from drivers/misc/mic/vop/ that is equally hardware specific, but he extends it to be applicable to other hardware as well.
It would be good if you could look at each other's approaches to see where we could take it from here. I think ideally we should have a common driver framework for doing the same thing across both of your devices and as well as others.
That would also resolve my main concern about the drivers, which is the placement in drivers/soc/ for a set of drivers that are unlike most drivers in that directory not mean for running on the SoC itself in order drive unusual functionality on the SoC, but are (at least partially) meant for running on a host machine to communicate with that SoC over PCIe or USB.
As an example, your network driver should really be placed in drivers/net/, though it is unclear to me how it relates to the existing virtio_net driver. In the case of mic/vop, the idea is to use virtio_net on the device side, but have vhost_net or a user space implementation on the host side, but that is apparently not what you do here. Can you explain why?
Another high-level question I have is on how your various drivers relate to one another. This should normally be explained in the 0/9 email, but I don't seem to have received such a mail. I see that you have multiple back-end drivers for the underlying transport, with one of them based on USB. Have you come up with a way to use the same high-level driver such as the network link over this USB back-end, or is this for something else?
Arnd
RE: [PATCH v6 5/9] soc: mellanox: host: Add the common host side Rshim driver
Thanks Arnd for the comments. The 0/9 email was sent out just now to add more details about the design and changes. Please also see my response below.
- Liming
Quoted 40 lines
-----Original Message-----
From: Arnd Bergmann <[email protected]>
Sent: Friday, January 18, 2019 11:02 AM
To: Liming Sun <[email protected]>
Cc: Olof Johansson <[email protected]>; David Woods <[email protected]>; Robin Murphy <[email protected]>; arm-soc <[email protected]>; DTML <[email protected]>; Linux ARM <[email protected]>; Vincent Whitchurch <[email protected]>; linux-pci <[email protected]>; [email protected]; Christoph Hellwig <[email protected]>
Subject: Re: [PATCH v6 5/9] soc: mellanox: host: Add the common host side Rshim driverQuoted 9 lines · Liming Sun
An external host can connect to a Mellanox BlueField SoC via an interface called Rshim. The Rshim driver provides boot, console, and networking services over this interface. This commit is the common driver where the other backend (transport) driver will use.
Reviewed-by David Woods <[email protected]>Signed-off-by Liming Sun <[email protected]>Hi Liming,
I've taken a new look at your patch series for
drivers/soc/now, thanks for your continued submissions.This is again just a set of very high-level comments, but I think we should resolve some of the fundamental questions first. Incidentally, Vincent Whitchurch has recently posted another patch series with a very similar intention, but for other hardware and taking a different approach.
In both cases, the idea is to use virtio based drivers to provide services from a host machine into another Linux instance running on an embedded system behind a PCIe slot or similar. Your Bluefield SoC patches are well written, but are intentionally kept specific to a particular use case and tied to one piece of hardware. In contrast, Vincent uses the existing code from
drivers/misc/mic/vop/that is equally hardware specific, but he extends it to be applicable to other hardware as well.
Quoted 4 lines
It would be good if you could look at each other's approaches to see where we could take it from here. I think ideally we should have a common driver framework for doing the same thing across both of your devices and as well as others.
Yes, I checked drivers/misc/mic/vop and Vincent Whitchurch's patches (Virtio-over-PCIe on non-MIC) and related comments. I kind of feel that besides the common virtio infrastructure, there seems not much to be reused in the rest of implementation yet, though they are trying to do the similar things. (Feel free to correct me if I misunderstood it.)
I just submitted the patch 0/9 to explain some details of the rshim component and the driver patches. Could you help take a look?
The rshim driver of BlueField SoC has a few more functionalities which are very HW-specific. Some needs driver support from both ARM target and the external host, some only needs external host driver support.
As for common framework, we used to implement the drivers based on the remote proc (Documentation/remoteproc.txt), which seems more close to what we wanted (in my humble opinion). Later due to more functionalities to add and the lack of remote proc in old kernels, we changed to use virtio framework directly, which seems very helpful and saved quite some driver work.
Quoted 9 lines
That would also resolve my main concern about the drivers, which is the placement in
drivers/soc/for a set of drivers that are unlike most drivers in that directory not mean for running on the SoC itself in order drive unusual functionality on the SoC, but are (at least partially) meant for running on a host machine to communicate with that SoC over PCIe or USB.
Quoted 7 lines
As an example, your network driver should really be placed in
drivers/net/, though it is unclear to me how it relates to the existingvirtio_netdriver. In the case of mic/vop, the idea is to usevirtio_neton the device side, but havevhost_netor a user space implementation on the host side, but that is apparently not what you do here. Can you explain why?
Yes, I actually have the same concerns where the host side drivers should go. For now ther're just added for code review purpose. drivers/soc/ seems not a good place. One thought is to move the rshim_net, rshim_pcie and rshim_pcie_lf backend driver to drivers/net/ethernet/Mellanox/rshim/ and move the rshim common driver to drivers/char as it creates the character devices?
The device side of this patch uses the virtio_net driver as well.
The host side is not just for networking, which was mentioned in the 0/9 patch. The host side driver manages the whole rshim component and is called the 'rshim' driver. It includes driver to access the TmFifo, where virtio_net is used to provide networking support. It needs to talk to the common driver then the USB or PCIe backend driver. It seems to me that vhost_net doesn't quite fit this model and might make it over-complicated.
Quoted 9 lines
Another high-level question I have is on how your various drivers relate to one another. This should normally be explained in the 0/9 email, but I don't seem to have received such a mail. I see that you have multiple back-end drivers for the underlying transport, with one of them based on USB. Have you come up with a way to use the same high-level driver such as the network link over this USB back-end, or is this for something else?
Yes, 0/9 has been sent. Sorry I should have provided since beginning.
The USB (or PCIe) provide the general transport to access the RShim component, for networking, console, register access, boot service, etc. So it's not just for network link. The implementation seems very HW specific, such as providing APIs like rshim_usb_read_rshim() and rshim_usb_write_rshim(). In PCIe backend it has similar APIs like rshim_pcie_read(), rshim_pcie_write().
Not very clear about what you meant the " the same high-level driver such as the network link over this USB back-end". Do you mean using any existing network over USB framework or provide some mechanism to be reused by other network over USB driver?
By the way, the 0/9 has been sent. Could you help take a look whether it clarifies a little bit or not?
Quoted 2 lines
Arnd
Re: [PATCH v6 5/9] soc: mellanox: host: Add the common host side Rshim driver
In reply to Arnd BergmannQuoted 31 lines · Arnd Bergmann
Quoted 9 lines · Liming Sun
An external host can connect to a Mellanox BlueField SoC via an interface called Rshim. The Rshim driver provides boot, console, and networking services over this interface. This commit is the common driver where the other backend (transport) driver will use.
Reviewed-by David Woods <[email protected]>Signed-off-by Liming Sun <[email protected]>Hi Liming,
I've taken a new look at your patch series for
drivers/soc/now, thanks for your continued submissions.This is again just a set of very high-level comments, but I think we should resolve some of the fundamental questions first. Incidentally, Vincent Whitchurch has recently posted another patch series with a very similar intention, but for other hardware and taking a different approach.
In both cases, the idea is to use virtio based drivers to provide services from a host machine into another Linux instance running on an embedded system behind a PCIe slot or similar. Your Bluefield SoC patches are well written, but are intentionally kept specific to a particular use case and tied to one piece of hardware. In contrast, Vincent uses the existing code from
drivers/misc/mic/vop/that is equally hardware specific, but he extends it to be applicable to other hardware as well.
Quoted 4 lines
It would be good if you could look at each other's approaches to see where we could take it from here. I think ideally we should have a common driver framework for doing the same thing across both of your devices and as well as others.
As far as I can see the biggest difference is that Rshim appears to support interfaces which do not have shared memory between the host and the card, which means that it has to jump through a lot more hoops to make virtio work.
For example, the card side seems to use normal virtio-net and virto-console drivers, but the drivers/soc/mellanox/tmfifo.c driver, also running on the card, appears to have to actually look inside the virtqueues and shuffle the data over the TmFifo interface, and this driver has hard-coded support for only network and console, since it apparently needs to know the details of how the virtio drivers use their virtqueues (see tmfifo_virtio_rxtx()).
And the host side appears to _also_ run the virtio-net driver and there the drivers/soc/mellanox/host/rshim_net.c code instead has to look inside the virtqueues and shuffle the data over the other side of the TmFifo interface.
So to me this looks very different from a traditional virtio driver/device setup (which is what mic/vop uses). I may be missing something, but I don't quite understand why it's even using virtio in the first place.
Re: [PATCH v6 5/9] soc: mellanox: host: Add the common host side Rshim driver
________________________________
From: Vincent Whitchurch <[email protected]>
Sent: Tuesday, January 22, 2019 7:20 AM
To: Arnd Bergmann
Cc: Liming Sun; Olof Johansson; David Woods; Robin Murphy; arm-soc; DTML; Linux ARM; linux-pci; [email protected]; Christoph Hellwig; [email protected]
Subject: Re: [PATCH v6 5/9] soc: mellanox: host: Add the common host side Rshim driver
Quoted 54 lines · Arnd Bergmann
Quoted 31 lines · Liming Sun
Quoted 9 lines
An external host can connect to a Mellanox BlueField SoC via an interface called Rshim. The Rshim driver provides boot, console, and networking services over this interface. This commit is the common driver where the other backend (transport) driver will use.
Reviewed-by David Woods <[email protected]>Signed-off-by Liming Sun <[email protected]>Hi Liming,
I've taken a new look at your patch series for
drivers/soc/now, thanks for your continued submissions.This is again just a set of very high-level comments, but I think we should resolve some of the fundamental questions first. Incidentally, Vincent Whitchurch has recently posted another patch series with a very similar intention, but for other hardware and taking a different approach.
In both cases, the idea is to use virtio based drivers to provide services from a host machine into another Linux instance running on an embedded system behind a PCIe slot or similar. Your Bluefield SoC patches are well written, but are intentionally kept specific to a particular use case and tied to one piece of hardware. In contrast, Vincent uses the existing code from
drivers/misc/mic/vop/that is equally hardware specific, but he extends it to be applicable to other hardware as well.Quoted 4 lines
It would be good if you could look at each other's approaches to see where we could take it from here. I think ideally we should have a common driver framework for doing the same thing across both of your devices and as well as others.
As far as I can see the biggest difference is that Rshim appears to support interfaces which do not have shared memory between the host and the card, which means that it has to jump through a lot more hoops to make virtio work.
For example, the card side seems to use normal virtio-net and virto-console drivers, but the
drivers/soc/mellanox/tmfifo.cdriver, also running on the card, appears to have to actually look inside the virtqueues and shuffle the data over the TmFifo interface, and this driver has hard-coded support for only network and console, since it apparently needs to know the details of how the virtio drivers use their virtqueues (seetmfifo_virtio_rxtx()).And the host side appears to _also_ run the virtio-net driver and there the
drivers/soc/mellanox/host/rshim_net.ccode instead has to look inside the virtqueues and shuffle the data over the other side of the TmFifo interface.
Quoted 4 lines
So to me this looks very different from a traditional virtio driver/device setup (which is what mic/vop uses). I may be missing something, but I don't quite understand why it's even using virtio in the first place.
Thanks Vincent! This appears to be very good summary of this driver does on the tmfifo part and the difference between mic/vop. The fifo is accessed by register instead of shared memory.
The reason to use virtio framework is that it can be easily used to add more virtual devices as needed without implementing driver details for each one. For example, the device side supports console and networking for now over the FIFO. It only needs to implement function tmfifo_virtio_rxtx() once to take care of the virtqueues Rx/Tx, which are shared by all virtual devices. With minimum changes, we could easily add another device over tmfifo, like a virtio block device, since the queue handling is already there.
The host side handles the virtqueues as well in rshim_net.c. It behaves like a peer-to-peer to the device side while the tmfifo behaves like a 'wire' (transport) to pass data between the host and the device without worrying about the data details.
Re: [PATCH v6 5/9] soc: mellanox: host: Add the common host side Rshim driver
From: Vincent Whitchurch <[email protected]>
Sent: Tuesday, January 22, 2019 7:20 AM
To: Arnd Bergmann
Cc: Liming Sun; Olof Johansson; David Woods; Robin Murphy; arm-soc; DTML; Linux ARM; linux-pci; [email protected]; Christoph Hellwig; [email protected]
Subject: Re: [PATCH v6 5/9] soc: mellanox: host: Add the common host side Rshim driver
Quoted 54 lines · Arnd Bergmann
Quoted 31 lines · Liming Sun
Quoted 9 lines
An external host can connect to a Mellanox BlueField SoC via an interface called Rshim. The Rshim driver provides boot, console, and networking services over this interface. This commit is the common driver where the other backend (transport) driver will use.
Reviewed-by David Woods <[email protected]>Signed-off-by Liming Sun <[email protected]>Hi Liming,
I've taken a new look at your patch series for
drivers/soc/now, thanks for your continued submissions.This is again just a set of very high-level comments, but I think we should resolve some of the fundamental questions first. Incidentally, Vincent Whitchurch has recently posted another patch series with a very similar intention, but for other hardware and taking a different approach.
In both cases, the idea is to use virtio based drivers to provide services from a host machine into another Linux instance running on an embedded system behind a PCIe slot or similar. Your Bluefield SoC patches are well written, but are intentionally kept specific to a particular use case and tied to one piece of hardware. In contrast, Vincent uses the existing code from
drivers/misc/mic/vop/that is equally hardware specific, but he extends it to be applicable to other hardware as well.Quoted 4 lines
It would be good if you could look at each other's approaches to see where we could take it from here. I think ideally we should have a common driver framework for doing the same thing across both of your devices and as well as others.
As far as I can see the biggest difference is that Rshim appears to support interfaces which do not have shared memory between the host and the card, which means that it has to jump through a lot more hoops to make virtio work.
For example, the card side seems to use normal virtio-net and virto-console drivers, but the
drivers/soc/mellanox/tmfifo.cdriver, also running on the card, appears to have to actually look inside the virtqueues and shuffle the data over the TmFifo interface, and this driver has hard-coded support for only network and console, since it apparently needs to know the details of how the virtio drivers use their virtqueues (seetmfifo_virtio_rxtx()).And the host side appears to _also_ run the virtio-net driver and there the
drivers/soc/mellanox/host/rshim_net.ccode instead has to look inside the virtqueues and shuffle the data over the other side of the TmFifo interface.
Quoted 4 lines
So to me this looks very different from a traditional virtio driver/device setup (which is what mic/vop uses). I may be missing something, but I don't quite understand why it's even using virtio in the first place.
Thanks Vincent! This appears to be very good summary of this driver does on the tmfifo part and the difference between mic/vop. The fifo is accessed by register instead of shared memory.
The reason to use virtio framework is that it can be easily used to add more virtual devices as needed without implementing driver details for each one. For example, the device side supports console and networking for now over the FIFO. It only needs to implement function tmfifo_virtio_rxtx() once to take care of the virtqueues Rx/Tx, which are shared by all virtual devices. With minimum changes, we could easily add another device over tmfifo, like a virtio block device, since the queue handling is already there.
The host side handles the virtqueues as well in rshim_net.c. It behaves like a peer-to-peer to the device side while the tmfifo behaves like a 'wire' (transport) to pass data between the host and the device without worrying about the data details.
PATCH v6 6/9 soc: mellanox: host: Add networking support over Rshim
In reply to Liming SunThis commit adds networking support over the Rshim interface of the BlueField SoC. It communicates with the target (ARM) side via the Rshim TmFifo.
--- drivers/soc/mellanox/host/Makefile | 2 +- drivers/soc/mellanox/host/rshim_net.c | 834 ++++++++++++++++++++++++++++++++++ 2 files changed, 835 insertions(+), 1 deletion(-) create mode 100644 drivers/soc/mellanox/host/rshim_net.c
drivers/soc/mellanox/host/Makefile +1 -1
@@ -1,2 +1,2 @@ -obj-m := rshim.o +obj-m := rshim.o rshim_net.o
drivers/soc/mellanox/host/rshim_net.c new file +834 -0
834 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v6 7/9 soc: mellanox: host: Add the Rshim USB backend driver
In reply to Liming SunThis commit adds the USB backend driver to access the Rshim interface on the BlueField SoC. It can be used when a USB cable is connected to the Smart NIC or standalone device.
--- drivers/soc/mellanox/host/Makefile | 2 +- drivers/soc/mellanox/host/rshim_usb.c | 1035 +++++++++++++++++++++++++++++++++ 2 files changed, 1036 insertions(+), 1 deletion(-) create mode 100644 drivers/soc/mellanox/host/rshim_usb.c
drivers/soc/mellanox/host/Makefile +1 -1
@@ -1,2 +1,2 @@ -obj-m := rshim.o rshim_net.o +obj-m := rshim.o rshim_net.o rshim_usb.o
drivers/soc/mellanox/host/rshim_usb.c new file +1035 -0
1,035 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v6 8/9 soc: mellanox: host: Add the Rshim PCIe backend driver
In reply to Liming SunThis commit adds the PCIe backend driver to access the Rshim interface on the BlueField SoC, such as on the Smart NIC.
--- drivers/soc/mellanox/host/Makefile | 2 +- drivers/soc/mellanox/host/rshim_pcie.c | 478 +++++++++++++++++++++++++++++++++ 2 files changed, 479 insertions(+), 1 deletion(-) create mode 100644 drivers/soc/mellanox/host/rshim_pcie.c
drivers/soc/mellanox/host/Makefile +1 -1
@@ -1,2 +1,2 @@ -obj-m := rshim.o rshim_net.o rshim_usb.o +obj-m := rshim.o rshim_net.o rshim_usb.o rshim_pcie.o
drivers/soc/mellanox/host/rshim_pcie.c new file +478 -0
478 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v6 9/9 soc: mellanox: host: Add the Rshim PCIe live-fish backend driver
In reply to Liming SunThis commit adds the PCIe live-fish backend driver to access the Rshim interface on the BlueField SoC, such as on the Smart NIC. It is slow access and can be used for live-fish mode when the NIC firmware hasn't been programmed yet.
--- drivers/soc/mellanox/host/Makefile | 2 +- drivers/soc/mellanox/host/rshim_pcie_lf.c | 695 ++++++++++++++++++++++++++++++ 2 files changed, 696 insertions(+), 1 deletion(-) create mode 100644 drivers/soc/mellanox/host/rshim_pcie_lf.c
drivers/soc/mellanox/host/Makefile +1 -1
@@ -1,2 +1,2 @@ -obj-m := rshim.o rshim_net.o rshim_usb.o rshim_pcie.o +obj-m := rshim.o rshim_net.o rshim_usb.o rshim_pcie.o rshim_pcie_lf.o
drivers/soc/mellanox/host/rshim_pcie_lf.c new file +695 -0
695 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v7 1/9 soc: Add TmFifo driver for Mellanox BlueField Soc
In reply to Liming SunThis commit adds the TmFifo driver for Mellanox BlueField Soc. TmFifo is a shared FIFO which enables external host machine to exchange data with the SoC via USB or PCIe. The driver is based on virtio framework and has console and network access enabled.
--- drivers/soc/Kconfig | 1 + drivers/soc/Makefile | 1 + drivers/soc/mellanox/Kconfig | 18 + drivers/soc/mellanox/Makefile | 5 + drivers/soc/mellanox/tmfifo.c | 1244 ++++++++++++++++++++++++++++++++++++ drivers/soc/mellanox/tmfifo_regs.h | 76 +++ 6 files changed, 1345 insertions(+) create mode 100644 drivers/soc/mellanox/Kconfig create mode 100644 drivers/soc/mellanox/Makefile create mode 100644 drivers/soc/mellanox/tmfifo.c create mode 100644 drivers/soc/mellanox/tmfifo_regs.h
drivers/soc/Kconfig +1 -0
@@ -7,6 +7,7 @@ source "drivers/soc/bcm/Kconfig" source "drivers/soc/fsl/Kconfig" source "drivers/soc/imx/Kconfig" source "drivers/soc/mediatek/Kconfig" +source "drivers/soc/mellanox/Kconfig" source "drivers/soc/qcom/Kconfig" source "drivers/soc/renesas/Kconfig" source "drivers/soc/rockchip/Kconfig"
drivers/soc/Makefile +1 -0
@@ -13,6 +13,7 @@ obj-$(CONFIG_ARCH_GEMINI) += gemini/ obj-$(CONFIG_ARCH_MXC) += imx/ obj-$(CONFIG_SOC_XWAY) += lantiq/ obj-y += mediatek/ +obj-$(CONFIG_SOC_MLNX) += mellanox/ obj-$(CONFIG_ARCH_MESON) += amlogic/ obj-y += qcom/ obj-y += renesas/
drivers/soc/mellanox/Kconfig new file +18 -0
@@ -0,0 +1,18 @@ +menuconfig SOC_MLNX + bool "Mellanox SoC drivers" + default y if ARCH_MLNX_BLUEFIELD + +if ARCH_MLNX_BLUEFIELD || COMPILE_TEST + +config MLNX_BLUEFIELD_TMFIFO + tristate "Mellanox BlueField SoC TmFifo driver" + depends on ARM64 + default m + select VIRTIO_CONSOLE + select VIRTIO_NET + help + Say y here to enable TmFifo support. The TmFifo driver provides the + virtio driver framework for the TMFIFO of Mellanox BlueField SoC and + the implementation of a console and network driver. + +endif # ARCH_MLNX_BLUEFIELD
drivers/soc/mellanox/Makefile new file +5 -0
@@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Makefile for Mellanox SoC drivers. +# +obj-$(CONFIG_MLNX_BLUEFIELD_TMFIFO) += tmfifo.o
drivers/soc/mellanox/tmfifo.c new file +1244 -0
1,244 lines not on this page · raw message
drivers/soc/mellanox/tmfifo_regs.h new file +76 -0
76 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v7 2/9 arm64: Add Mellanox BlueField SoC config option
This commit introduces config option for Mellanox BlueField SoC, which can be used to build the SoC specific drivers, and enables it by default in configs/defconfig.
--- arch/arm64/Kconfig.platforms | 6 ++++++ arch/arm64/configs/defconfig | 1 + 2 files changed, 7 insertions(+)
arch/arm64/Kconfig.platforms +6 -0
@@ -119,6 +119,12 @@ config ARCH_MESON help This enables support for the Amlogic S905 SoCs. +config ARCH_MLNX_BLUEFIELD + bool "Mellanox BlueField SoC Family" + select SOC_MLNX + help + This enables support for the Mellanox BlueField SoC. + config ARCH_MVEBU bool "Marvell EBU SoC Family" select ARMADA_AP806_SYSCON
arch/arm64/configs/defconfig +1 -0
@@ -44,6 +44,7 @@ CONFIG_ARCH_LG1K=y CONFIG_ARCH_HISI=y CONFIG_ARCH_MEDIATEK=y CONFIG_ARCH_MESON=y +CONFIG_ARCH_MLNX_BLUEFIELD=y CONFIG_ARCH_MVEBU=y CONFIG_ARCH_QCOM=y CONFIG_ARCH_ROCKCHIP=y
Signature · 1 line
1.8.3.1
PATCH v7 3/9 dt-bindings: soc: Add TmFifo binding for Mellanox BlueField SoC
In reply to Liming SunAdd devicetree bindings for the TmFifo which is found on Mellanox BlueField SoCs.
--- .../devicetree/bindings/soc/mellanox/tmfifo.txt | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Documentation/devicetree/bindings/soc/mellanox/tmfifo.txt
Documentation/devicetree/bindings/soc/mellanox/tmfifo.txt new file +23 -0
@@ -0,0 +1,23 @@ +* Mellanox BlueField SoC TmFifo + +BlueField TmFifo provides a shared FIFO between the target and the +external host machine, which can be accessed by external host via +USB or PCIe. In the current tmfifo driver, this FIFO has been demuxed +to implement virtual console and network interface based on the virtio +framework. + +Required properties: + +- compatible: Should be "mellanox,bf-tmfifo" +- reg: Physical base address and length of Rx/Tx block +- interrupts: The interrupt number of Rx low water mark, Rx high water mark + Tx low water mark, Tx high water mark respectively. + +Example: + +tmfifo@800a20 { + compatible = "mellanox,bf-tmfifo"; + reg = <0x00800a20 0x00000018 + 0x00800a40 0x00000018>; + interrupts = <41, 42, 43, 44>; +};
Signature · 1 line
1.8.3.1
PATCH v7 4/9 MAINTAINERS: Add entry for Mellanox Bluefield Soc
In reply to Liming SunAdd maintainer information for Mellanox BlueField SoC.
--- MAINTAINERS | 8 ++++++++ 1 file changed, 8 insertions(+)
MAINTAINERS +8 -0
@@ -1759,6 +1759,14 @@ S: Maintained F: drivers/phy/mediatek/ F: Documentation/devicetree/bindings/phy/phy-mtk-* +ARM/Mellanox BlueField SoC support +M: David Woods <[email protected]> +M: Liming Sun <[email protected]> +L: [email protected] (moderated for non-subscribers) +S: Maintained +F: drivers/soc/mellanox/* +F: Documentation/devicetree/bindings/soc/mellanox/tmfifo.txt + ARM/MICREL KS8695 ARCHITECTURE M: Greg Ungerer <[email protected]> L: [email protected] (moderated for non-subscribers)
Signature · 1 line
1.8.3.1
PATCH v7 5/9 soc: mellanox: host: Add the common host side Rshim driver
In reply to Liming SunAn external host can connect to a Mellanox BlueField SoC via an interface called Rshim. The Rshim driver provides boot, console, and networking services over this interface. This commit is the common driver where the other backend (transport) driver will use.
--- drivers/soc/mellanox/Kconfig | 8 + drivers/soc/mellanox/Makefile | 1 + drivers/soc/mellanox/host/Makefile | 2 + drivers/soc/mellanox/host/rshim.c | 2673 ++++++++++++++++++++++++++++++++ drivers/soc/mellanox/host/rshim.h | 361 +++++ drivers/soc/mellanox/host/rshim_regs.h | 152 ++ 6 files changed, 3197 insertions(+) create mode 100644 drivers/soc/mellanox/host/Makefile create mode 100644 drivers/soc/mellanox/host/rshim.c create mode 100644 drivers/soc/mellanox/host/rshim.h create mode 100644 drivers/soc/mellanox/host/rshim_regs.h
drivers/soc/mellanox/Kconfig +8 -0
@@ -16,3 +16,11 @@ config MLNX_BLUEFIELD_TMFIFO the implementation of a console and network driver. endif # ARCH_MLNX_BLUEFIELD + +config MLNX_BLUEFIELD_HOST + tristate "Mellnox BlueField host side drivers" + help + If you say yes to this option, then support will be added + for control and communication of Mellanox BlueField SoCs + from an external host via USB or PCI-express. +
drivers/soc/mellanox/Makefile +1 -0
@@ -3,3 +3,4 @@ # Makefile for Mellanox SoC drivers. # obj-$(CONFIG_MLNX_BLUEFIELD_TMFIFO) += tmfifo.o +obj-$(CONFIG_MLNX_BLUEFIELD_HOST) += host/
drivers/soc/mellanox/host/Makefile new file +2 -0
@@ -0,0 +1,2 @@ +obj-m := rshim.o +
drivers/soc/mellanox/host/rshim.c new file +2673 -0
2,673 lines not on this page · raw message
drivers/soc/mellanox/host/rshim.h new file +361 -0
310 lines not on this page · raw message
drivers/soc/mellanox/host/rshim_regs.h new file +152 -0
152 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.8.3.1
Part of the diff is not shown here. View the raw message.
PATCH v7 6/9 soc: mellanox: host: Add networking support over Rshim
In reply to Liming SunThis commit adds networking support over the Rshim interface of the BlueField SoC. It communicates with the target (ARM) side via the Rshim TmFifo.
--- drivers/soc/mellanox/host/Makefile | 2 +- drivers/soc/mellanox/host/rshim_net.c | 834 ++++++++++++++++++++++++++++++++++ 2 files changed, 835 insertions(+), 1 deletion(-) create mode 100644 drivers/soc/mellanox/host/rshim_net.c
drivers/soc/mellanox/host/Makefile +1 -1
@@ -1,2 +1,2 @@ -obj-m := rshim.o +obj-m := rshim.o rshim_net.o
drivers/soc/mellanox/host/rshim_net.c new file +834 -0
834 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v7 7/9 soc: mellanox: host: Add the Rshim USB backend driver
In reply to Liming SunThis commit adds the USB backend driver to access the Rshim interface on the BlueField SoC. It can be used when a USB cable is connected to the Smart NIC or standalone device.
--- drivers/soc/mellanox/host/Makefile | 2 +- drivers/soc/mellanox/host/rshim_usb.c | 1035 +++++++++++++++++++++++++++++++++ 2 files changed, 1036 insertions(+), 1 deletion(-) create mode 100644 drivers/soc/mellanox/host/rshim_usb.c
drivers/soc/mellanox/host/Makefile +1 -1
@@ -1,2 +1,2 @@ -obj-m := rshim.o rshim_net.o +obj-m := rshim.o rshim_net.o rshim_usb.o
drivers/soc/mellanox/host/rshim_usb.c new file +1035 -0
1,035 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v7 8/9 soc: mellanox: host: Add the Rshim PCIe backend driver
In reply to Liming SunThis commit adds the PCIe backend driver to access the Rshim interface on the BlueField SoC, such as on the Smart NIC.
--- drivers/soc/mellanox/host/Makefile | 2 +- drivers/soc/mellanox/host/rshim_pcie.c | 478 +++++++++++++++++++++++++++++++++ 2 files changed, 479 insertions(+), 1 deletion(-) create mode 100644 drivers/soc/mellanox/host/rshim_pcie.c
drivers/soc/mellanox/host/Makefile +1 -1
@@ -1,2 +1,2 @@ -obj-m := rshim.o rshim_net.o rshim_usb.o +obj-m := rshim.o rshim_net.o rshim_usb.o rshim_pcie.o
drivers/soc/mellanox/host/rshim_pcie.c new file +478 -0
478 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v7 9/9 soc: mellanox: host: Add the Rshim PCIe live-fish backend driver
In reply to Liming SunThis commit adds the PCIe live-fish backend driver to access the Rshim interface on the BlueField SoC, such as on the Smart NIC. It is slow access and can be used for live-fish mode when the NIC firmware hasn't been programmed yet.
--- drivers/soc/mellanox/host/Makefile | 2 +- drivers/soc/mellanox/host/rshim_pcie_lf.c | 695 ++++++++++++++++++++++++++++++ 2 files changed, 696 insertions(+), 1 deletion(-) create mode 100644 drivers/soc/mellanox/host/rshim_pcie_lf.c
drivers/soc/mellanox/host/Makefile +1 -1
@@ -1,2 +1,2 @@ -obj-m := rshim.o rshim_net.o rshim_usb.o rshim_pcie.o +obj-m := rshim.o rshim_net.o rshim_usb.o rshim_pcie.o rshim_pcie_lf.o
drivers/soc/mellanox/host/rshim_pcie_lf.c new file +695 -0
695 lines not on this page · raw message
Signature · 1 line
1.8.3.1
Quoted 20 lines · Liming Sun
This commit adds the TmFifo driver for Mellanox BlueField Soc. TmFifo is a shared FIFO which enables external host machine to exchange data with the SoC via USB or PCIe. The driver is based on virtio framework and has console and network access enabled.
Reviewed-by David Woods <[email protected]>Signed-off-by Liming Sun <[email protected]>--- drivers/soc/Kconfig | 1 + drivers/soc/Makefile | 1 + drivers/soc/mellanox/Kconfig | 18 + drivers/soc/mellanox/Makefile | 5 + drivers/soc/mellanox/tmfifo.c | 1244 ++++++++++++++++++++++++++++++++++++ drivers/soc/mellanox/tmfifo_regs.h | 76 +++ 6 files changed, 1345 insertions(+) create mode 100644 drivers/soc/mellanox/Kconfig create mode 100644 drivers/soc/mellanox/Makefile create mode 100644 drivers/soc/mellanox/tmfifo.c create mode 100644 drivers/soc/mellanox/tmfifo_regs.h
[..]
Quoted 5 lines
drivers/soc/mellanox/tmfifo.c new file +0
-0
[..]
drivers/soc/mellanox/tmfifo.c line 56
Quoted 11 lines
drivers/soc/mellanox/tmfifo.c new file +11
-0+ +/* Console Tx buffer size. */ +#define TMFIFO_CONS_TX_BUF_SIZE (32 * 1024) + +/* House-keeping timer interval. */ +static int tmfifo_timer_interval =HZ /10 ; +module_param (tmfifo_timer_interval, int,0644 ); +MODULE_PARM_DESC (tmfifo_timer_interval,"timer interval" ); + +/* Global lock. */ +static DEFINE_MUTEX (tmfifo_lock);
Why do we need that? To synchronize between different tmfifo driver instances?
Quoted 72 lines
drivers/soc/mellanox/tmfifo.c new file +71
-0+ +/* Virtio ring size. */ +static int tmfifo_vring_size =TMFIFO_VRING_SIZE ; +module_param (tmfifo_vring_size, int,0444 ); +MODULE_PARM_DESC (tmfifo_vring_size,"Size of the vring" ); + +/* Struct declaration. */ +struct tmfifo ; + +/* Virtual devices sharing the TM FIFO. */ +#define TMFIFO_VDEV_MAX (VIRTIO_ID_CONSOLE + 1) + +/* Structure to maintain the ring state. */ +struct tmfifo_vring { +void *va;/* virtual address */ +dma_addr_t dma;/* dma address */ +struct virtqueue *vq;/* virtqueue pointer */ +struct vring_desc *desc;/* current desc */ +struct vring_desc *desc_head;/* current desc head */ +int cur_len;/* processed len in current desc */ +int rem_len;/* remaining length to be processed */ +int size;/* vring size */ +int align;/* vring alignment */ +int id;/* vring id */ +int vdev_id;/* TMFIFO_VDEV_xxx */ +u32 pkt_len;/* packet total length */ +__virtio16 next_avail;/* next avail desc id */ +struct tmfifo *fifo;/* pointer back to the tmfifo */ +}; + +/* Interrupt types. */ +enum { +TM_RX_LWM_IRQ ,/* Rx low water mark irq */ +TM_RX_HWM_IRQ ,/* Rx high water mark irq */ +TM_TX_LWM_IRQ ,/* Tx low water mark irq */ +TM_TX_HWM_IRQ ,/* Tx high water mark irq */ +TM_IRQ_CNT +}; + +/* Ring types (Rx & Tx). */ +enum { +TMFIFO_VRING_RX ,/* Rx ring */ +TMFIFO_VRING_TX ,/* Tx ring */ +TMFIFO_VRING_NUM +}; + +struct tmfifo_vdev { +struct virtio_device vdev;/* virtual device */ +u8 status; +u64 features; +union {/* virtio config space */ +struct virtio_console_config cons; +struct virtio_net_config net; + } config; +struct tmfifo_vring vrings[TMFIFO_VRING_NUM ]; +u8 *tx_buf;/* tx buffer */ +u32 tx_head;/* tx buffer head */ +u32 tx_tail;/* tx buffer tail */ +}; + +struct tmfifo_irq_info { +struct tmfifo *fifo;/* tmfifo structure */ +int irq;/* interrupt number */ +int index;/* array index */ +}; + +/* TMFIFO device structure */ +struct tmfifo { +struct tmfifo_vdev *vdev[TMFIFO_VDEV_MAX ];/* virtual devices */ +struct platform_device *pdev;/* platform device */ +struct mutex lock;
Quoted 1 line
From what I understand we use this lock to syncronize between
tmfifo_create_vdev, tmfifo_delete_vdev and tmfifo_work_handler.
Create happens in probe and delete in remove, so we don't need a lock here. So the only reason I can see we need this lock here is, to make sure that we don't mess up between create a vdev and being already in the work handler. That can only happen, if an IRQ was triggered. If we enable the IRQs after creating the vdev, we don't need the lock at all.
Quoted 33 lines
drivers/soc/mellanox/tmfifo.c new file +33
-0+void __iomem *rx_base;/* mapped register base */ +void __iomem *tx_base;/* mapped register base */ +int tx_fifo_size;/* number of entries of the Tx FIFO */ +int rx_fifo_size;/* number of entries of the Rx FIFO */ +unsigned long pend_events;/* pending bits for deferred process */ +struct tmfifo_irq_info irq_info[TM_IRQ_CNT ];/* irq info */ +struct work_struct work;/* work struct for deferred process */ +struct timer_list timer;/* keepalive timer */ +struct tmfifo_vring *vring[2 ];/* current Tx/Rx ring */ +bool is_ready;/* ready flag */ +spinlock_t spin_lock;/* spin lock */ +}; + +union tmfifo_msg_hdr { +struct { +u8 type;/* message type */ +__be16 len;/* payload length */ +u8 unused[5 ];/* reserved, set to 0 */ + } __packed; +u64 data; +}; + +/* +* Default MAC. +* This MAC address will be read from EFI persistent variable if configured. +* It can also be reconfigured with standard Linux tools. +*/ +static u8 tmfifo_net_default_mac[6 ] = {0x00 ,0x1A ,0xCA ,0xFF ,0xFF ,0x01 }; + +/* MTU setting of the virtio-net interface. */ +#define TMFIFO_NET_MTU 1500 + +/* Supported virtio-net features. */
drivers/soc/mellanox/tmfifo.c line 170
Quoted 10 lines
drivers/soc/mellanox/tmfifo.c new file +10
-0+#define TMFIFO_NET_FEATURES ((1UL << VIRTIO_NET_F_MTU) | \ + (1UL << VIRTIO_NET_F_STATUS) | \ + (1UL << VIRTIO_NET_F_MAC)) + +/* Return the available Tx buffer space. */ +static inline int tmfifo_vdev_tx_buf_avail (struct tmfifo_vdev *vdev) +{ +return ((vdev->tx_tail >= vdev->tx_head) ? + (TMFIFO_CONS_TX_BUF_SIZE -8 - (vdev->tx_tail - + vdev->tx_head)) : (vdev->tx_head - vdev->tx_tail -8 ));
Why do we need to subtract 8 from the available buffer size?
drivers/soc/mellanox/tmfifo.c line 178
Quoted 8 lines
drivers/soc/mellanox/tmfifo.c new file +8
-0+} + +/* Update Tx buffer pointer after pushing data. */ +static inline void tmfifo_vdev_tx_buf_push (struct tmfifo_vdev *vdev,u32 len) +{ + vdev->tx_tail += len; +if (vdev->tx_tail >=TMFIFO_CONS_TX_BUF_SIZE ) + vdev->tx_tail -=TMFIFO_CONS_TX_BUF_SIZE ;
I would have expectedvdev->tx_tail = (vdev->tx_tail + len) % TMFIFO_CONS_TX_BUF_SIZE;
But I suppose your code executes faster.
What I miss is some code to assure that no ring buffer overflow/underrun can happen.
Quoted 10 lines
drivers/soc/mellanox/tmfifo.c new file +10
-0+} + +/* Update Tx buffer pointer after popping data. */ +static inline void tmfifo_vdev_tx_buf_pop (struct tmfifo_vdev *vdev,u32 len) +{ + vdev->tx_head += len; +if (vdev->tx_head >=TMFIFO_CONS_TX_BUF_SIZE ) + vdev->tx_head -=TMFIFO_CONS_TX_BUF_SIZE ; +} +
[...]
Quoted 9 lines
drivers/soc/mellanox/tmfifo.c new file +9
-0+ +/* Rx & Tx processing of a virtual queue. */ +static void tmfifo_virtio_rxtx(struct virtqueue *vq, bool is_rx)> +{ +struct tmfifo_vring *vring; +struct tmfifo *fifo; +struct vring *vr; +struct virtio_device *vdev; +u64 sts, data; +int num_avail =0 , hdr_len, tx_reserve;
drivers/soc/mellanox/tmfifo.c line 463
Quoted 10 lines
drivers/soc/mellanox/tmfifo.c new file +10
-0+void *addr; +u32 len, idx; +struct vring_desc *desc; +unsigned long flags; +struct tmfifo_vdev *cons; + +if (!vq) +return ; + + vring = (struct tmfifo_vring *)vq->priv;
You can pass strict tmfifo_vring* instead of virtqueue as function parameter, then you don't have to do this.
drivers/soc/mellanox/tmfifo.c line 473
Quoted 10 lines
drivers/soc/mellanox/tmfifo.c new file +10
-0+ fifo = vring->fifo; + vr = (struct vring *)virtqueue_get_vring (vq); + +if (!fifo->vdev[vring->vdev_id]) +return ; + vdev = &fifo->vdev[vring->vdev_id]->vdev; + cons = fifo->vdev[VIRTIO_ID_CONSOLE ]; + +/* Don't continue if another vring is running. */ +if (fifo->vring[is_rx] !=NULL && fifo->vring[is_rx] != vring)
How can that happen?
Quoted 14 lines
drivers/soc/mellanox/tmfifo.c new file +14
-0+return ; + +/* tx_reserve is used to reserved some room in FIFO for console. */ +if (vring->vdev_id ==VIRTIO_ID_NET ) { + hdr_len =sizeof (struct virtio_net_hdr ); + tx_reserve = fifo->tx_fifo_size /16 ; + }else { +BUG_ON (vring->vdev_id !=VIRTIO_ID_CONSOLE ); + hdr_len =0 ; + tx_reserve =1 ; + } + + desc = vring->desc; +
[...]
drivers/soc/mellanox/tmfifo.c line 747
Quoted 13 lines
drivers/soc/mellanox/tmfifo.c new file +13
-0+ +/* Work handler for Rx, Tx or activity monitoring. */ +static void tmfifo_work_handler (struct work_struct *work) +{ +int i; +struct tmfifo_vdev *tm_vdev; + struct tmfifo *fifo = container_of(work, struct tmfifo, work); + +if (!fifo->is_ready) +return ; + +mutex_lock (&fifo->lock); +
So you don't want to queue up more work when remove is called. As is_ready is not atomic you could deadlock here:
remove work_handler
mutex_lock
if(!is_ready)
mutex_lock <- sleepsis_ready = false
...
cancel_work_sync <- deadlock
Quoted 28 lines
drivers/soc/mellanox/tmfifo.c new file +28
-0+/* Tx. */ +if (test_and_clear_bit (TM_TX_LWM_IRQ , &fifo->pend_events) && + fifo->irq_info[TM_TX_LWM_IRQ ].irq) { +for (i =0 ; i <TMFIFO_VDEV_MAX ; i++) { + tm_vdev = fifo->vdev[i]; +if (tm_vdev !=NULL ) { +tmfifo_virtio_rxtx ( + tm_vdev->vrings[TMFIFO_VRING_TX ].vq, + false); + } + } + } + +/* Rx. */ +if (test_and_clear_bit (TM_RX_HWM_IRQ , &fifo->pend_events) && + fifo->irq_info[TM_RX_HWM_IRQ ].irq) { +for (i =0 ; i <TMFIFO_VDEV_MAX ; i++) { + tm_vdev = fifo->vdev[i]; +if (tm_vdev !=NULL ) { +tmfifo_virtio_rxtx ( + tm_vdev->vrings[TMFIFO_VRING_RX ].vq, + true); + } + } + } + +mutex_unlock (&fifo->lock); +}
[...]
Quoted 16 lines
drivers/soc/mellanox/tmfifo.c new file +16
-0+ +/* Probe the TMFIFO. */ +static int tmfifo_probe (struct platform_device *pdev) +{ +u64 ctl; +struct tmfifo *fifo; +struct resource *rx_res, *tx_res; +struct virtio_net_config net_config; +int i, ret; + +/* Get the resource of the Rx & Tx FIFO. */ + rx_res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + tx_res =platform_get_resource (pdev,IORESOURCE_MEM ,1 ); +if (!rx_res || !tx_res) { + ret = -EINVAL ; + goto err;
drivers/soc/mellanox/tmfifo.c line 1109
Quoted 10 lines
drivers/soc/mellanox/tmfifo.c new file +10
-0+ } + +if (request_mem_region (rx_res->start, +resource_size (rx_res),"bf-tmfifo" ) ==NULL ) { + ret = -EBUSY ; + goto early_err; + } + +if (request_mem_region (tx_res->start, +resource_size (tx_res),"bf-tmfifo" ) ==NULL ) {
Can't we use devm_request_mem_region and get rid of the release_mem_region here and in the remove function?
Regards,
Matthias
Quoted 218 lines
drivers/soc/mellanox/tmfifo.c new file +135
-0+release_mem_region (rx_res->start,resource_size (rx_res)); + ret = -EBUSY ; + goto early_err; + } + + ret = -ENOMEM ; + fifo =kzalloc (sizeof (struct tmfifo ),GFP_KERNEL ); +if (!fifo) + goto err; + + fifo->pdev = pdev; +platform_set_drvdata (pdev, fifo); + +spin_lock_init (&fifo->spin_lock); +INIT_WORK (&fifo->work, tmfifo_work_handler); + +timer_setup (&fifo->timer, tmfifo_timer,0 ); + fifo->timer.function = tmfifo_timer; + +for (i =0 ; i <TM_IRQ_CNT ; i++) { + fifo->irq_info[i].index = i; + fifo->irq_info[i].fifo = fifo; + fifo->irq_info[i].irq =platform_get_irq (pdev, i); + ret =request_irq (fifo->irq_info[i].irq, tmfifo_irq_handler,0 , +"tmfifo" , &fifo->irq_info[i]); +if (ret) { +pr_err ("Unable to request irq\n" ); + fifo->irq_info[i].irq =0 ; + goto err; + } + } + + fifo->rx_base =ioremap (rx_res->start,resource_size (rx_res)); +if (!fifo->rx_base) + goto err; + + fifo->tx_base =ioremap (tx_res->start,resource_size (tx_res)); +if (!fifo->tx_base) + goto err; + +/* Get Tx FIFO size and set the low/high watermark. */ + ctl =readq (fifo->tx_base +TMFIFO_TX_CTL ); + fifo->tx_fifo_size = +FIELD_GET (TMFIFO_TX_CTL__MAX_ENTRIES_MASK , ctl); + ctl = (ctl & ~TMFIFO_TX_CTL__LWM_MASK ) | +FIELD_PREP (TMFIFO_TX_CTL__LWM_MASK , fifo->tx_fifo_size /2 ); + ctl = (ctl & ~TMFIFO_TX_CTL__HWM_MASK ) | +FIELD_PREP (TMFIFO_TX_CTL__HWM_MASK , fifo->tx_fifo_size -1 ); +writeq (ctl, fifo->tx_base +TMFIFO_TX_CTL ); + +/* Get Rx FIFO size and set the low/high watermark. */ + ctl =readq (fifo->rx_base +TMFIFO_RX_CTL ); + fifo->rx_fifo_size = +FIELD_GET (TMFIFO_RX_CTL__MAX_ENTRIES_MASK , ctl); + ctl = (ctl & ~TMFIFO_RX_CTL__LWM_MASK ) | +FIELD_PREP (TMFIFO_RX_CTL__LWM_MASK ,0 ); + ctl = (ctl & ~TMFIFO_RX_CTL__HWM_MASK ) | +FIELD_PREP (TMFIFO_RX_CTL__HWM_MASK ,1 ); +writeq (ctl, fifo->rx_base +TMFIFO_RX_CTL ); + +mutex_init (&fifo->lock); + +/* Create the console vdev. */ + ret =tmfifo_create_vdev (fifo,VIRTIO_ID_CONSOLE ,0 ,NULL ,0 ); +if (ret) + goto err; + +/* Create the network vdev. */ +memset (&net_config,0 ,sizeof (net_config)); + net_config.mtu =TMFIFO_NET_MTU ; + net_config.status =VIRTIO_NET_S_LINK_UP ; +memcpy (net_config.mac, tmfifo_net_default_mac,6 ); +tmfifo_get_cfg_mac (net_config.mac); + ret =tmfifo_create_vdev (fifo,VIRTIO_ID_NET ,TMFIFO_NET_FEATURES , + &net_config,sizeof (net_config)); +if (ret) + goto err; + +mod_timer (&fifo->timer, jiffies + tmfifo_timer_interval); + + fifo->is_ready = true; + +return 0 ; + +err: +tmfifo_remove (pdev); +early_err: +dev_err (&pdev->dev,"Probe Failed\n" ); +return ret; +} + +static const struct of_device_id tmfifo_match[] = { + { .compatible ="mellanox,bf-tmfifo" }, + {}, +}; +MODULE_DEVICE_TABLE (of, tmfifo_match); + +static const struct acpi_device_id bf_tmfifo_acpi_match[] = { + {"MLNXBF01" ,0 }, + {}, +}; +MODULE_DEVICE_TABLE (acpi, bf_tmfifo_acpi_match); + +static struct platform_driver tmfifo_driver = { + .probe = tmfifo_probe, + .remove = tmfifo_remove, + .driver = { + .name ="bf-tmfifo" , + .of_match_table = tmfifo_match, + .acpi_match_table =ACPI_PTR (bf_tmfifo_acpi_match), + }, +}; + +static int __init tmfifo_init (void ) +{ +int ret; + + ret =platform_driver_register (&tmfifo_driver); +if (ret) +pr_err ("Failed to register tmfifo driver.\n" ); + +return ret; +} + +static void __exit tmfifo_exit(void) +{ +platform_driver_unregister (&tmfifo_driver); +} + +module_init (tmfifo_init); +module_exit (tmfifo_exit); + +MODULE_DESCRIPTION ("Mellanox BlueField SoC TMFIFO Driver" ); +MODULE_LICENSE ("GPL v2" ); +MODULE_AUTHOR ("Mellanox Technologies" );drivers/soc/mellanox/tmfifo_regs.h new file +76
-0@@ -0,0 +1,76 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2018, Mellanox Technologies. All rights reserved. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 and +* only version 2 as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#ifndef __TMFIFO_REGS_H__ +#define __TMFIFO_REGS_H__ + +#include <linux/types.h> + +#define TMFIFO_TX_DATA 0x0 + +#define TMFIFO_TX_STS 0x8 +#define TMFIFO_TX_STS__LENGTH 0x0001 +#define TMFIFO_TX_STS__COUNT_SHIFT 0 +#define TMFIFO_TX_STS__COUNT_WIDTH 9 +#define TMFIFO_TX_STS__COUNT_RESET_VAL 0 +#define TMFIFO_TX_STS__COUNT_RMASK 0x1ff +#define TMFIFO_TX_STS__COUNT_MASK 0x1ff + +#define TMFIFO_TX_CTL 0x10 +#define TMFIFO_TX_CTL__LENGTH 0x0001 +#define TMFIFO_TX_CTL__LWM_SHIFT 0 +#define TMFIFO_TX_CTL__LWM_WIDTH 8 +#define TMFIFO_TX_CTL__LWM_RESET_VAL 128 +#define TMFIFO_TX_CTL__LWM_RMASK 0xff +#define TMFIFO_TX_CTL__LWM_MASK 0xff +#define TMFIFO_TX_CTL__HWM_SHIFT 8 +#define TMFIFO_TX_CTL__HWM_WIDTH 8 +#define TMFIFO_TX_CTL__HWM_RESET_VAL 128 +#define TMFIFO_TX_CTL__HWM_RMASK 0xff +#define TMFIFO_TX_CTL__HWM_MASK 0xff00 +#define TMFIFO_TX_CTL__MAX_ENTRIES_SHIFT 32 +#define TMFIFO_TX_CTL__MAX_ENTRIES_WIDTH 9 +#define TMFIFO_TX_CTL__MAX_ENTRIES_RESET_VAL 256 +#define TMFIFO_TX_CTL__MAX_ENTRIES_RMASK 0x1ff +#define TMFIFO_TX_CTL__MAX_ENTRIES_MASK 0x1ff00000000ULL + +#define TMFIFO_RX_DATA 0x0 + +#define TMFIFO_RX_STS 0x8 +#define TMFIFO_RX_STS__LENGTH 0x0001 +#define TMFIFO_RX_STS__COUNT_SHIFT 0 +#define TMFIFO_RX_STS__COUNT_WIDTH 9 +#define TMFIFO_RX_STS__COUNT_RESET_VAL 0 +#define TMFIFO_RX_STS__COUNT_RMASK 0x1ff +#define TMFIFO_RX_STS__COUNT_MASK 0x1ff + +#define TMFIFO_RX_CTL 0x10 +#define TMFIFO_RX_CTL__LENGTH 0x0001 +#define TMFIFO_RX_CTL__LWM_SHIFT 0 +#define TMFIFO_RX_CTL__LWM_WIDTH 8 +#define TMFIFO_RX_CTL__LWM_RESET_VAL 128 +#define TMFIFO_RX_CTL__LWM_RMASK 0xff +#define TMFIFO_RX_CTL__LWM_MASK 0xff +#define TMFIFO_RX_CTL__HWM_SHIFT 8 +#define TMFIFO_RX_CTL__HWM_WIDTH 8 +#define TMFIFO_RX_CTL__HWM_RESET_VAL 128 +#define TMFIFO_RX_CTL__HWM_RMASK 0xff +#define TMFIFO_RX_CTL__HWM_MASK 0xff00 +#define TMFIFO_RX_CTL__MAX_ENTRIES_SHIFT 32 +#define TMFIFO_RX_CTL__MAX_ENTRIES_WIDTH 9 +#define TMFIFO_RX_CTL__MAX_ENTRIES_RESET_VAL 256 +#define TMFIFO_RX_CTL__MAX_ENTRIES_RMASK 0x1ff +#define TMFIFO_RX_CTL__MAX_ENTRIES_MASK 0x1ff00000000ULL + +#endif /* !defined(__TMFIFO_REGS_H__) */
v7 cover Mellanox BlueField ARM SoC Rshim driver
In reply to Liming SunThis patch series implements Linux driver support for the Rshim component on Mellanox BlueField ARM SoC.
1. Overview of the Rshim component
The Rshim component provides a connection among different other components of the SoC and can be accessed externally via USB or PCIe. USB access is available on standard appliance and SmartNIC. PCIe access is for SmartNIC only.
Quoted 1 line
From user perspective, Rshim provides the following
functionalities.
1.1 Boot FIFO
The Boot FIFO is polled by the boot ROM. At a later booting phase it's read by UEFI as well to load the Linux kernel.
The Boot FIFO is a one-way direction FIFO. The data could come from different sources.
a) On-chip eMMC, which is the default configuration.
After chip reset, HW will generate eMMC commands, which triggers the boot stream on the eMMC boot partition to show up in Boot FIFO.
This one doesn't need any Linux driver.
b) Injected externally from USB or PCIe.
External host could overwrite the boot mode and inject boot stream into the Boot FIFO over USB or PCIe. It's used in board bring-up, fault recovering or debugging.
This one usually needs driver support in the external host.
1.2 TmFifo
TmFifo are FIFOs which can be used for communication between the SoC ARM core and the external side. Each direction has its own FIFO.
TmFifo needs driver support on both the SoC side and the external host side.
1.3 Rshim register space access
Rshim register space could be accessed externally via USB or PCIe. It's used for configuration, debugging, etc. More specifically, it could be used to access the ARM CoreSight component which could do on-chip debugging, such as for boot loader, drivers, or crash information collection.
This one needs driver support from external host.
2. Driver Introduction
This patch series provides several drivers.
*) Patch 1/9 ~ 4/9 (tmfifo.c, tmfifo_regs.h, Kconfig, Makefile)
They provide Linux driver support for the TmFifo on the SoC side (see above 1.2).
*) Patch 5/9 ~ 9/9
They provide Linux driver support for the external host.
- Patch 5/9 (rshim.c, rshim.h, rshim_regs.h, Makefile)
It provides common functionalities and register access to the RShim component. Several character devices are created like below for easy user-access.
/dev/rshim<N>/boot
This device file is used to inject boot stream into the Boot FIFO, such as
'cat boot-image > /dev/rshim<N>/boot'
This one is to implement the above function 1.1.b
/dev/rshim<N>/rshim
This device file is used to access Rshim register space like a plat file.
/dev/rshim<N>/console
This device file is used to access the virtual console to the SoC via the TmFifo (see above functionality 1.2). It can be used by any standard tools like minicom, screen, etc.
- Patch 6/9 (rshim_net.c)
This patch provides virtual networking support over the Rshim TmFifo (see above functionality 1.2).
- Patch 7/9 (rshim_usb.c)
This is the USB backend driver, which implements the details to access the RShim component via USB. It supports endpoints, USB bulk-transfer and interrupts. After loaded by ACPI, it triggers the loading of the common driver and network driver, and provides low-level APIs to the common driver.
Below is an example of the networking calling stack.
Linux Network Stack --> virtio_net --> rshim_net --> rshim common driver --> rshim USB backend driver
- Patch 8/9 (rshim_pcie.c)
This is the PCIe backend driver, which implements the details to access the RShim component via PCIe when the HCA firmware is ready. In such case, the Rshim component is exposed as a standard PCIe PF and it's register space can be mapped in BAR0.
Linux Network Stack --> virtio_net --> rshim_net --> rshim common driver --> rshim PCIe backend driver
- Patch 9/9 (rshim_pcie_lf.c)
Similarly, this is another PCIe backend driver, but provides slow access when the HCA firmware is not ready. In such as, the BAR0 mapping is not available. The Rshim register access is done via a slow access gateway. The below calling stack is also similar.
Linux Network Stack --> virtio_net --> rshim_net --> rshim common driver --> rshim PCIe livefish backend driver
Liming Sun (9):
soc: Add TmFifo driver for Mellanox BlueField Soc
arm64: Add Mellanox BlueField SoC config option
dt-bindings: soc: Add TmFifo binding for Mellanox BlueField SoC
MAINTAINERS: Add entry for Mellanox Bluefield Soc
soc: mellanox: host: Add the common host side Rshim driver
soc: mellanox: host: Add networking support over Rshim
soc: mellanox: host: Add the Rshim USB backend driver
soc: mellanox: host: Add the Rshim PCIe backend driver
soc: mellanox: host: Add the Rshim PCIe live-fish backend driver
.../devicetree/bindings/soc/mellanox/tmfifo.txt | 23 + MAINTAINERS | 8 + arch/arm64/Kconfig.platforms | 6 + arch/arm64/configs/defconfig | 1 + drivers/soc/Kconfig | 1 + drivers/soc/Makefile | 1 + drivers/soc/mellanox/Kconfig | 26 + drivers/soc/mellanox/Makefile | 6 + drivers/soc/mellanox/host/Makefile | 2 + drivers/soc/mellanox/host/rshim.c | 2673 ++++++++++++++++++++ drivers/soc/mellanox/host/rshim.h | 361 +++ drivers/soc/mellanox/host/rshim_net.c | 834 ++++++ drivers/soc/mellanox/host/rshim_pcie.c | 478 ++++ drivers/soc/mellanox/host/rshim_pcie_lf.c | 695 +++++ drivers/soc/mellanox/host/rshim_regs.h | 152 ++ drivers/soc/mellanox/host/rshim_usb.c | 1035 ++++++++ drivers/soc/mellanox/tmfifo.c | 1244 +++++++++ drivers/soc/mellanox/tmfifo_regs.h | 76 + 18 files changed, 7622 insertions(+) create mode 100644 Documentation/devicetree/bindings/soc/mellanox/tmfifo.txt create mode 100644 drivers/soc/mellanox/Kconfig create mode 100644 drivers/soc/mellanox/Makefile create mode 100644 drivers/soc/mellanox/host/Makefile create mode 100644 drivers/soc/mellanox/host/rshim.c create mode 100644 drivers/soc/mellanox/host/rshim.h create mode 100644 drivers/soc/mellanox/host/rshim_net.c create mode 100644 drivers/soc/mellanox/host/rshim_pcie.c create mode 100644 drivers/soc/mellanox/host/rshim_pcie_lf.c create mode 100644 drivers/soc/mellanox/host/rshim_regs.h create mode 100644 drivers/soc/mellanox/host/rshim_usb.c create mode 100644 drivers/soc/mellanox/tmfifo.c create mode 100644 drivers/soc/mellanox/tmfifo_regs.h
Signature · 1 line
1.8.3.1
Re: [PATCH v7 0/9] Mellanox BlueField ARM SoC Rshim driver
Quoted 6 lines · Liming Sun
Liming Sun (9):
soc: Add TmFifo driver for Mellanox BlueField Soc
arm64: Add Mellanox BlueField SoC config option
dt-bindings: soc: Add TmFifo binding for Mellanox BlueField SoC
MAINTAINERS: Add entry for Mellanox Bluefield Soc
Could you send the arch/arm64 changes to [email protected] for inclusion? I'm not sure what the status of the rshim driver is now, but we should probably merge the base support through the soc tree.
Arnd
v8 cover TmFifo platform driver for Mellanox BlueField SoC
In reply to Liming SunThis patch series implements the device side platform driver support for the TmFifo on Mellanox BlueField SoC.
TmFifo is part of the RShim component. It provides FIFOs to communicate with external host machine via USB or PCIe (SmartNic case). External host machine has driver to access the RShim component as well, which is not covered in this patch series.
This patch series was submitted to drivers/soc in previous versions. This version (v8) re-submit it to drivers/platform according to the received comments / suggestions.
Patch v8 1/2 has changes according to some comments from Vadim Pasternak during Mellanox internal review.
Patch v8 2/2 was reviewed by Rob Herring before, but might need a second look since the location of the driver code is moved.
Liming Sun (2):
platform/mellanox: Add TmFifo driver for Mellanox BlueField Soc
dt-bindings: soc: Add TmFifo binding for Mellanox BlueField SoC
.../devicetree/bindings/soc/mellanox/tmfifo.txt | 23 + drivers/platform/mellanox/Kconfig | 13 +- drivers/platform/mellanox/Makefile | 1 + drivers/platform/mellanox/mlxbf-tmfifo-regs.h | 67 + drivers/platform/mellanox/mlxbf-tmfifo.c | 1289 ++++++++++++++++++++ 5 files changed, 1392 insertions(+), 1 deletion(-) create mode 100644 Documentation/devicetree/bindings/soc/mellanox/tmfifo.txt create mode 100644 drivers/platform/mellanox/mlxbf-tmfifo-regs.h create mode 100644 drivers/platform/mellanox/mlxbf-tmfifo.c
Signature · 1 line
1.8.3.1
PATCH v8 1/2 platform/mellanox: Add TmFifo driver for Mellanox BlueField Soc
This commit adds the TmFifo platform driver for Mellanox BlueField Soc. TmFifo is a shared FIFO which enables external host machine to exchange data with the SoC via USB or PCIe. The driver is based on virtio framework and has console and network access enabled.
--- drivers/platform/mellanox/Kconfig | 13 +- drivers/platform/mellanox/Makefile | 1 + drivers/platform/mellanox/mlxbf-tmfifo-regs.h | 67 ++ drivers/platform/mellanox/mlxbf-tmfifo.c | 1289 +++++++++++++++++++++++++ 4 files changed, 1369 insertions(+), 1 deletion(-) create mode 100644 drivers/platform/mellanox/mlxbf-tmfifo-regs.h create mode 100644 drivers/platform/mellanox/mlxbf-tmfifo.c
drivers/platform/mellanox/Kconfig +12 -1
@@ -5,7 +5,7 @@ menuconfig MELLANOX_PLATFORM bool "Platform support for Mellanox hardware" - depends on X86 || ARM || COMPILE_TEST + depends on X86 || ARM || ARM64 || COMPILE_TEST ---help--- Say Y here to get to see options for platform support for Mellanox systems. This option alone does not add any kernel code.
@@ -34,4 +34,15 @@ config MLXREG_IO to system resets operation, system reset causes monitoring and some kinds of mux selection. +config MLXBF_TMFIFO + tristate "Mellanox BlueField SoC TmFifo platform driver" + depends on ARM64 + default m + select VIRTIO_CONSOLE + select VIRTIO_NET + help + Say y here to enable TmFifo support. The TmFifo driver provides + platform driver support for the TmFifo which supports console + and networking based on the virtio framework. + endif # MELLANOX_PLATFORM
drivers/platform/mellanox/Makefile +1 -0
@@ -5,3 +5,4 @@ # obj-$(CONFIG_MLXREG_HOTPLUG) += mlxreg-hotplug.o obj-$(CONFIG_MLXREG_IO) += mlxreg-io.o +obj-$(CONFIG_MLXBF_TMFIFO) += mlxbf-tmfifo.o
drivers/platform/mellanox/mlxbf-tmfifo-regs.h new file +67 -0
67 lines not on this page · raw message
drivers/platform/mellanox/mlxbf-tmfifo.c new file +1289 -0
1,289 lines not on this page · raw message
Signature · 1 line
1.8.3.1
Re: [PATCH v8 1/2] platform/mellanox: Add TmFifo driver for Mellanox BlueField Soc
Quoted 8 lines · Liming Sun
This commit adds the TmFifo platform driver for Mellanox BlueField Soc. TmFifo is a shared FIFO which enables external host machine to exchange data with the SoC via USB or PCIe. The driver is based on virtio framework and has console and network access enabled.
Reviewed-by David Woods <[email protected]>Signed-off-by Liming Sun <[email protected]>
Please, go through this series taking into account review I just did for your another patch.
On top of that, see recent (for few years I think) drivers what modern APIs they are using, e.g. devm_.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v8 1/2] platform/mellanox: Add TmFifo driver for Mellanox BlueField Soc
Thanks Andy!
V9 has been posted with the devm_ changes and coding style fixes according to the received comments in the other patch. It also has changes for comments from Vadim during Mellanox internal review.
Regards,
Liming
________________________________
From: Andy Shevchenko <[email protected]>
Sent: Tuesday, January 29, 2019 5:06 PM
To: Liming Sun
Cc: Rob Herring; Mark Rutland; Arnd Bergmann; David Woods; Andy Shevchenko; Darren Hart; Vadim Pasternak; devicetree; Linux Kernel Mailing List; Platform Driver
Subject: Re: [PATCH v8 1/2] platform/mellanox: Add TmFifo driver for Mellanox BlueField Soc
Quoted 8 lines · Liming Sun
This commit adds the TmFifo platform driver for Mellanox BlueField Soc. TmFifo is a shared FIFO which enables external host machine to exchange data with the SoC via USB or PCIe. The driver is based on virtio framework and has console and network access enabled.
Reviewed-by David Woods <[email protected]>Signed-off-by Liming Sun <[email protected]>
Please, go through this series taking into account review I just did for your another patch.
On top of that, see recent (for few years I think) drivers what modern APIs they are using, e.g. devm_.
--
With Best Regards,
Andy Shevchenko
RE: [PATCH v8 1/2] platform/mellanox: Add TmFifo driver for Mellanox BlueField Soc
In reply to Andy ShevchenkoThanks Andy. Sorry I had email issue earlier today. Not sure the reply was sent out or not. So sent another one just in case...
v9 of this patch has been posted to address the 'devm_' comment. It also has the coding-style changes according to the comments I got for another patch.
Regards,
Liming
Quoted 30 lines
-----Original Message-----
From: Andy Shevchenko <[email protected]>
Sent: Tuesday, January 29, 2019 5:07 PM
To: Liming Sun <[email protected]>
Cc: Rob Herring <[email protected]>; Mark Rutland <[email protected]>; Arnd Bergmann <[email protected]>; David Woods <[email protected]>; Andy Shevchenko <[email protected]>; Darren Hart <[email protected]>; Vadim Pasternak <[email protected]>; devicetree <[email protected]>; Linux Kernel Mailing List <[email protected]>; Platform Driver <[email protected]>
Subject: Re: [PATCH v8 1/2] platform/mellanox: Add TmFifo driver for Mellanox BlueField SocQuoted 8 lines · Liming Sun
This commit adds the TmFifo platform driver for Mellanox BlueField Soc. TmFifo is a shared FIFO which enables external host machine to exchange data with the SoC via USB or PCIe. The driver is based on virtio framework and has console and network access enabled.
Reviewed-by David Woods <[email protected]>Signed-off-by Liming Sun <[email protected]>Please, go through this series taking into account review I just did for your another patch.
On top of that, see recent (for few years I think) drivers what modern APIs they are using, e.g.
devm_.--
With Best Regards,
Andy Shevchenko
RE: [PATCH v8 1/2] platform/mellanox: Add TmFifo driver for Mellanox BlueField Soc
In reply to Liming SunQuoted 46 lines
-----Original Message-----
From: Liming Sun <[email protected]>
Sent: Monday, January 28, 2019 7:28 PM
To: Rob Herring <[email protected]>; Mark Rutland <[email protected]>; Arnd Bergmann <[email protected]>; David Woods <[email protected]>; Andy Shevchenko <[email protected]>; Darren Hart <[email protected]>; Vadim Pasternak <[email protected]>
Cc: Liming Sun <[email protected]>; [email protected]; linux- [email protected]; [email protected]
Subject: [PATCH v8 1/2] platform/mellanox: Add TmFifo driver for Mellanox BlueField SocThis commit adds the TmFifo platform driver for Mellanox BlueField Soc. TmFifo is a shared FIFO which enables external host machine to exchange data with the SoC via USB or PCIe. The driver is based on virtio framework and has console and network access enabled.
Reviewed-by David Woods <[email protected]>Signed-off-by Liming Sun <[email protected]>--- drivers/platform/mellanox/Kconfig | 13 +- drivers/platform/mellanox/Makefile | 1 + drivers/platform/mellanox/mlxbf-tmfifo-regs.h | 67 ++ drivers/platform/mellanox/mlxbf-tmfifo.c | 1289 +++++++++++++++++++++++++ 4 files changed, 1369 insertions(+), 1 deletion(-) create mode 100644 drivers/platform/mellanox/mlxbf-tmfifo-regs.h create mode 100644 drivers/platform/mellanox/mlxbf-tmfifo.cdrivers/platform/mellanox/Kconfig +1
-1@@ -5,7 +5,7 @@ menuconfig MELLANOX_PLATFORM bool "Platform support for Mellanox hardware" - depends on X86 || ARM || COMPILE_TEST + depends on X86 || ARM || ARM64 || COMPILE_TEST ---help--- Say Y here to get to see options for platform support for Mellanox systems. This option alone does not add any kernel code.
drivers/platform/mellanox/Kconfig config MLXREG_IO · line 39
Quoted 6 lines
drivers/platform/mellanox/Kconfig +3
-0@@ -34,4 +34,15 @@ config MLXREG_IO to system resets operation, system reset causes monitoring and some kinds of mux selection. +config MLXBF_TMFIFO + tristate "Mellanox BlueField SoC TmFifo platform driver" + depends on ARM64
Why you make it dependent on ARM64?
Should not it work on any host, x86?
drivers/platform/mellanox/Kconfig config MLXREG_IO · line 40
Quoted 1 line
drivers/platform/mellanox/Kconfig +1
-0+ default m
User who needs it should select this option.
No need default 'm'.
Quoted 121 lines
drivers/platform/mellanox/Kconfig +7
-0+ select VIRTIO_CONSOLE + select VIRTIO_NET + help + Say y here to enable TmFifo support. The TmFifo driver provides + platform driver support for the TmFifo which supports console + and networking based on the virtio framework. + endif # MELLANOX_PLATFORMdrivers/platform/mellanox/Makefile +1
-0@@ -5,3 +5,4 @@ # obj-$(CONFIG_MLXREG_HOTPLUG) += mlxreg-hotplug.o obj-$(CONFIG_MLXREG_IO) += mlxreg-io.o +obj-$(CONFIG_MLXBF_TMFIFO) += mlxbf-tmfifo.odrivers/platform/mellanox/mlxbf-tmfifo-regs.h new file +23
-0@@ -0,0 +1,67 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2019, Mellanox Technologies. All rights reserved. +*/ + +#ifndef __MLXBF_TMFIFO_REGS_H__ +#define __MLXBF_TMFIFO_REGS_H__ + +#include <linux/types.h> + +#define MLXBF_TMFIFO_TX_DATA 0x0 + +#define MLXBF_TMFIFO_TX_STS 0x8 +#define MLXBF_TMFIFO_TX_STS__LENGTH 0x0001 #define +MLXBF_TMFIFO_TX_STS__COUNT_SHIFT 0 #define +MLXBF_TMFIFO_TX_STS__COUNT_WIDTH 9 #define +MLXBF_TMFIFO_TX_STS__COUNT_RESET_VAL 0 #define +MLXBF_TMFIFO_TX_STS__COUNT_RMASK 0x1ff #define +MLXBF_TMFIFO_TX_STS__COUNT_MASK 0x1ff + +#define MLXBF_TMFIFO_TX_CTL 0x10 +#define MLXBF_TMFIFO_TX_CTL__LENGTH 0x0001 #define +MLXBF_TMFIFO_TX_CTL__LWM_SHIFT 0 #define
MLXBF_TMFIFO_TX_CTL__LWM_WIDTH
+8 #defineMLXBF_TMFIFO_TX_CTL__LWM_RESET_VAL128 #definedrivers/platform/mellanox/mlxbf-tmfifo-regs.h new file +3
-0+MLXBF_TMFIFO_TX_CTL__LWM_RMASK 0xff #define +MLXBF_TMFIFO_TX_CTL__LWM_MASK 0xff #define +MLXBF_TMFIFO_TX_CTL__HWM_SHIFT 8 #define
MLXBF_TMFIFO_TX_CTL__HWM_WIDTH
+8 #defineMLXBF_TMFIFO_TX_CTL__HWM_RESET_VAL128 #definedrivers/platform/mellanox/mlxbf-tmfifo-regs.h new file +21
-0+MLXBF_TMFIFO_TX_CTL__HWM_RMASK 0xff #define +MLXBF_TMFIFO_TX_CTL__HWM_MASK 0xff00 #define +MLXBF_TMFIFO_TX_CTL__MAX_ENTRIES_SHIFT 32 #define +MLXBF_TMFIFO_TX_CTL__MAX_ENTRIES_WIDTH 9 #define +MLXBF_TMFIFO_TX_CTL__MAX_ENTRIES_RESET_VAL 256 #define +MLXBF_TMFIFO_TX_CTL__MAX_ENTRIES_RMASK 0x1ff #define +MLXBF_TMFIFO_TX_CTL__MAX_ENTRIES_MASK 0x1ff00000000ULL + +#define MLXBF_TMFIFO_RX_DATA 0x0 + +#define MLXBF_TMFIFO_RX_STS 0x8 +#define MLXBF_TMFIFO_RX_STS__LENGTH 0x0001 #define +MLXBF_TMFIFO_RX_STS__COUNT_SHIFT 0 #define +MLXBF_TMFIFO_RX_STS__COUNT_WIDTH 9 #define +MLXBF_TMFIFO_RX_STS__COUNT_RESET_VAL 0 #define +MLXBF_TMFIFO_RX_STS__COUNT_RMASK 0x1ff #define +MLXBF_TMFIFO_RX_STS__COUNT_MASK 0x1ff + +#define MLXBF_TMFIFO_RX_CTL 0x10 +#define MLXBF_TMFIFO_RX_CTL__LENGTH 0x0001 #define +MLXBF_TMFIFO_RX_CTL__LWM_SHIFT 0 #define
MLXBF_TMFIFO_RX_CTL__LWM_WIDTH
+8 #defineMLXBF_TMFIFO_RX_CTL__LWM_RESET_VAL128 #definedrivers/platform/mellanox/mlxbf-tmfifo-regs.h new file +3
-0+MLXBF_TMFIFO_RX_CTL__LWM_RMASK 0xff #define +MLXBF_TMFIFO_RX_CTL__LWM_MASK 0xff #define +MLXBF_TMFIFO_RX_CTL__HWM_SHIFT 8 #define
MLXBF_TMFIFO_RX_CTL__HWM_WIDTH
+8 #defineMLXBF_TMFIFO_RX_CTL__HWM_RESET_VAL128 #definedrivers/platform/mellanox/mlxbf-tmfifo-regs.h new file +9
-0+MLXBF_TMFIFO_RX_CTL__HWM_RMASK 0xff #define +MLXBF_TMFIFO_RX_CTL__HWM_MASK 0xff00 #define +MLXBF_TMFIFO_RX_CTL__MAX_ENTRIES_SHIFT 32 #define +MLXBF_TMFIFO_RX_CTL__MAX_ENTRIES_WIDTH 9 #define +MLXBF_TMFIFO_RX_CTL__MAX_ENTRIES_RESET_VAL 256 #define +MLXBF_TMFIFO_RX_CTL__MAX_ENTRIES_RMASK 0x1ff #define +MLXBF_TMFIFO_RX_CTL__MAX_ENTRIES_MASK 0x1ff00000000ULL + +#endif /* !defined(__MLXBF_TMFIFO_REGS_H__) */ drivers/platform/mellanox/mlxbf-tmfifo.c new file +22
-0@@ -0,0 +1,1289 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Mellanox BlueField SoC TmFifo driver +* +* Copyright (C) 2019 Mellanox Technologies */ + +#include <linux/acpi.h> +#include <linux/bitfield.h> +#include <linux/cache.h> +#include <linux/device.h> +#include <linux/dma-mapping.h> +#include <linux/efi.h> +#include <linux/io.h> +#include <linux/interrupt.h> +#include <linux/irq.h> +#include <linux/kernel.h> +#include <linux/math64.h> +#include <linux/module.h> +#include <linux/moduleparam.h> +#include <linux/mutex.h> +#include <linux/platform_device.h> +#include <linux/resource.h>
drivers/platform/mellanox/mlxbf-tmfifo.c line 32
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +10
-0+#include <linux/slab.h> +#include <linux/types.h> +#include <linux/version.h> +#include <linux/virtio.h> +#include <linux/virtio_config.h> +#include <linux/virtio_console.h> +#include <linux/virtio_ids.h> +#include <linux/virtio_net.h> +#include <linux/virtio_ring.h> +#include <asm/byteorder.h>
Is it must ti include from asm?
Could it be replaced with something like
#include <linux/byteorder/generic.h>
Quoted 120 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +77
-0+ +#include "mlxbf-tmfifo-regs.h" + +/* Vring size. */ +#define MLXBF_TMFIFO_VRING_SIZE 1024 + +/* Console Tx buffer size. */ +#define MLXBF_TMFIFO_CONS_TX_BUF_SIZE (32 * 1024) + +/* House-keeping timer interval. */ +static int mlxbf_tmfifo_timer_interval =HZ /10 ; + +/* Global lock. */ +static DEFINE_MUTEX (mlxbf_tmfifo_lock); + +/* Virtual devices sharing the TM FIFO. */ +#define MLXBF_TMFIFO_VDEV_MAX (VIRTIO_ID_CONSOLE + 1) + +/* Struct declaration. */ +struct mlxbf_tmfifo ; + +/* Structure to maintain the ring state. */ struct mlxbf_tmfifo_vring { +void *va;/* virtual address */ +dma_addr_t dma;/* dma address */ +struct virtqueue *vq;/* virtqueue pointer */ +struct vring_desc *desc;/* current desc */ +struct vring_desc *desc_head;/* current desc head */ +int cur_len;/* processed len in current desc */ +int rem_len;/* remaining length to be processed */ +int size;/* vring size */ +int align;/* vring alignment */ +int id;/* vring id */ +int vdev_id;/* TMFIFO_VDEV_xxx */ +u32 pkt_len;/* packet total length */ +__virtio16 next_avail;/* next avail desc id */ +struct mlxbf_tmfifo *fifo;/* pointer back to the tmfifo */ +}; + +/* Interrupt types. */ +enum { +MLXBF_TM_RX_LWM_IRQ ,/* Rx low water mark irq */ +MLXBF_TM_RX_HWM_IRQ ,/* Rx high water mark irq */ +MLXBF_TM_TX_LWM_IRQ ,/* Tx low water mark irq */ +MLXBF_TM_TX_HWM_IRQ ,/* Tx high water mark irq */ +MLXBF_TM_IRQ_CNT +}; + +/* Ring types (Rx & Tx). */ +enum { +MLXBF_TMFIFO_VRING_RX ,/* Rx ring */ +MLXBF_TMFIFO_VRING_TX ,/* Tx ring */ +MLXBF_TMFIFO_VRING_NUM +}; + +struct mlxbf_tmfifo_vdev { +struct virtio_device vdev;/* virtual device */ +u8 status; +u64 features; +union {/* virtio config space */ +struct virtio_console_config cons; +struct virtio_net_config net; + } config; +struct mlxbf_tmfifo_vring vrings[MLXBF_TMFIFO_VRING_NUM ]; +u8 *tx_buf;/* tx buffer */ +u32 tx_head;/* tx buffer head */ +u32 tx_tail;/* tx buffer tail */ +}; + +struct mlxbf_tmfifo_irq_info { +struct mlxbf_tmfifo *fifo;/* tmfifo structure */ +int irq;/* interrupt number */ +int index;/* array index */ +}; + +/* TMFIFO device structure */ +struct mlxbf_tmfifo { +struct mlxbf_tmfifo_vdev *vdev[MLXBF_TMFIFO_VDEV_MAX ];/* devices */
drivers/platform/mellanox/mlxbf-tmfifo.c new file +8
-0+struct platform_device *pdev;/* platform device */ +struct mutex lock;/* fifo lock */ +void __iomem *rx_base;/* mapped register base */ +void __iomem *tx_base;/* mapped register base */ +int tx_fifo_size;/* number of entries of the Tx FIFO */ +int rx_fifo_size;/* number of entries of the Rx FIFO */ +unsigned long pend_events;/* pending bits for deferred process */ +struct mlxbf_tmfifo_irq_info irq_info[MLXBF_TM_IRQ_CNT ];/* irq info */
drivers/platform/mellanox/mlxbf-tmfifo.c new file +32
-0+struct work_struct work;/* work struct for deferred process */ +struct timer_list timer;/* keepalive timer */ +struct mlxbf_tmfifo_vring *vring[2 ];/* current Tx/Rx ring */ +bool is_ready;/* ready flag */ +spinlock_t spin_lock;/* spin lock */ +}; + +union mlxbf_tmfifo_msg_hdr { +struct { +u8 type;/* message type */ +__be16 len;/* payload length */ +u8 unused[5 ];/* reserved, set to 0 */ + } __packed; +u64 data; +}; + +/* +* Default MAC. +* This MAC address will be read from EFI persistent variable if configured. +* It can also be reconfigured with standard Linux tools. +*/ +static u8 mlxbf_tmfifo_net_default_mac[6 ] = { +0x00 ,0x1A ,0xCA ,0xFF ,0xFF ,0x01 }; + +/* MTU setting of the virtio-net interface. */ +#define MLXBF_TMFIFO_NET_MTU 1500 + +/* Maximum L2 header length. */ +#define MLXBF_TMFIFO_NET_L2_OVERHEAD 36 + +/* Supported virtio-net features. */ +#define MLXBF_TMFIFO_NET_FEATURES ((1UL << VIRTIO_NET_F_MTU)| \
drivers/platform/mellanox/mlxbf-tmfifo.c
Quoted 9 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +9
-0+ (1UL << VIRTIO_NET_F_STATUS) | \ + (1UL << VIRTIO_NET_F_MAC)) + +/* Return the consumed Tx buffer space. */ static int +mlxbf_tmfifo_vdev_tx_buf_len (struct mlxbf_tmfifo_vdev *vdev) { +return ((vdev->tx_tail >= vdev->tx_head) ? + (vdev->tx_tail - vdev->tx_head) : + (MLXBF_TMFIFO_CONS_TX_BUF_SIZE - vdev->tx_head + +vdev->tx_tail)); }
I would suggest to split the above.
drivers/platform/mellanox/mlxbf-tmfifo.c line 166
Quoted 4 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +4
-0+ +/* Return the available Tx buffer space. */ static int +mlxbf_tmfifo_vdev_tx_buf_avail (struct mlxbf_tmfifo_vdev *vdev) { + return (MLXBF_TMFIFO_CONS_TX_BUF_SIZE - 8 -
Thins about some extra define for
"MLXBF_TMFIFO_CONS_TX_BUF_SIZE - 8"
Quoted 96 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +39
-0+ mlxbf_tmfifo_vdev_tx_buf_len(vdev)); +} + +/* Update Tx buffer pointer after pushing data. */ static void +mlxbf_tmfifo_vdev_tx_buf_push (struct mlxbf_tmfifo_vdev *vdev, +u32 len) +{ + vdev->tx_tail += len; +if (vdev->tx_tail >=MLXBF_TMFIFO_CONS_TX_BUF_SIZE ) + vdev->tx_tail -=MLXBF_TMFIFO_CONS_TX_BUF_SIZE ; } + +/* Update Tx buffer pointer after popping data. */ static void +mlxbf_tmfifo_vdev_tx_buf_pop (struct mlxbf_tmfifo_vdev *vdev, +u32 len) +{ + vdev->tx_head += len; +if (vdev->tx_head >=MLXBF_TMFIFO_CONS_TX_BUF_SIZE ) + vdev->tx_head -=MLXBF_TMFIFO_CONS_TX_BUF_SIZE ; } + +/* Allocate vrings for the fifo. */ +static int mlxbf_tmfifo_alloc_vrings (struct mlxbf_tmfifo *fifo, +struct mlxbf_tmfifo_vdev *tm_vdev, +int vdev_id) +{ +struct mlxbf_tmfifo_vring *vring; +dma_addr_t dma; +int i, size; +void *va; + +for (i =0 ; i <ARRAY_SIZE (tm_vdev->vrings); i++) { + vring = &tm_vdev->vrings[i]; + vring->fifo = fifo; + vring->size =MLXBF_TMFIFO_VRING_SIZE ; + vring->align =SMP_CACHE_BYTES ; + vring->id = i; + vring->vdev_id = vdev_id; + + size =PAGE_ALIGN (vring_size (vring->size, vring->align)); + va = dma_alloc_coherent(tm_vdev->vdev.dev.parent, size,&dma,
drivers/platform/mellanox/mlxbf-tmfifo.c new file +56
-0+ GFP_KERNEL); +if (!va) { +dev_err (tm_vdev->vdev.dev.parent, +"vring allocation failed\n" ); +return -EINVAL ; + } + + vring->va = va; + vring->dma = dma; + } + +return 0 ; +} + +/* Free vrings of the fifo device. */ +static void mlxbf_tmfifo_free_vrings (struct mlxbf_tmfifo *fifo,int +vdev_id) { +struct mlxbf_tmfifo_vdev *tm_vdev = fifo->vdev[vdev_id]; +struct mlxbf_tmfifo_vring *vring; +int i, size; + +for (i =0 ; i <ARRAY_SIZE (tm_vdev->vrings); i++) { + vring = &tm_vdev->vrings[i]; + + size =PAGE_ALIGN (vring_size (vring->size, vring->align)); +if (vring->va) { +dma_free_coherent (tm_vdev->vdev.dev.parent, size, + vring->va, vring->dma); + vring->va =NULL ; +if (vring->vq) { +vring_del_virtqueue (vring->vq); + vring->vq =NULL ; + } + } + } +} + +/* Free interrupts of the fifo device. */ static void +mlxbf_tmfifo_free_irqs (struct mlxbf_tmfifo *fifo) { +int i, irq; + +for (i =0 ; i <MLXBF_TM_IRQ_CNT ; i++) { + irq = fifo->irq_info[i].irq; +if (irq) { + fifo->irq_info[i].irq =0 ; +disable_irq (irq); +free_irq (irq, (u8 *)fifo + i); + } + } +} + +/* Interrupt handler. */ +static irqreturn_t mlxbf_tmfifo_irq_handler (int irq,void *arg) { +struct mlxbf_tmfifo_irq_info *irq_info; + + irq_info = (struct mlxbf_tmfifo_irq_info *)arg;
drivers/platform/mellanox/mlxbf-tmfifo.c
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +10
-0+ +if (irq_info->index <MLXBF_TM_IRQ_CNT && + !test_and_set_bit (irq_info->index, &irq_info->fifo->pend_events)) +schedule_work (&irq_info->fifo->work); + +return IRQ_HANDLED ; +} + +/* Nothing to do for now. */ +static void mlxbf_tmfifo_virtio_dev_release (struct device *dev) { }
If there is nothing to do - no reason to have it.
Quoted 113 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +50
-0+ +/* Get the next packet descriptor from the vring. */ static inline +struct vring_desc *mlxbf_tmfifo_virtio_get_next_desc (struct virtqueue +*vq) { +struct mlxbf_tmfifo_vring *vring; +unsigned int idx, head; +struct vring *vr; + + vring = (struct mlxbf_tmfifo_vring *)vq->priv; + vr = (struct vring *)virtqueue_get_vring (vq); + +if (!vr || vring->next_avail == vr->avail->idx) +return NULL ; + + idx = vring->next_avail % vr->num; + head = vr->avail->ring[idx]; +BUG_ON (head >= vr->num); + vring->next_avail++; +return &vr->desc[head]; +} + +static inline void mlxbf_tmfifo_virtio_release_desc ( +struct virtio_device *vdev,struct vring *vr, +struct vring_desc *desc,u32 len) +{ +unsigned int idx; + + idx = vr->used->idx % vr->num; + vr->used->ring[idx].id = desc - vr->desc; + vr->used->ring[idx].len =cpu_to_virtio32 (vdev, len); + +/* Virtio could poll and check the 'idx' to decide +* whether the desc is done or not. Add a memory +* barrier here to make sure the update above completes +* before updating the idx. +*/ +mb (); + vr->used->idx++; +} + +/* Get the total length of a descriptor chain. */ static inline u32 +mlxbf_tmfifo_virtio_get_pkt_len (struct virtio_device *vdev, +struct vring_desc *desc, +struct vring *vr) +{ +u32 len =0 , idx; + +while (desc) { + len +=virtio32_to_cpu (vdev, desc->len); + if (!(virtio16_to_cpu(vdev, desc->flags) &
VRING_DESC_F_NEXT))drivers/platform/mellanox/mlxbf-tmfifo.c new file +32
-0+break ; + idx =virtio16_to_cpu (vdev, desc->next); + desc = &vr->desc[idx]; + } + +return len; +} + +static void mlxbf_tmfifo_release_pkt (struct virtio_device *vdev, +struct mlxbf_tmfifo_vring *vring, +struct vring_desc **desc) +{ +struct vring *vr = (struct vring *)virtqueue_get_vring (vring->vq); +struct vring_desc *desc_head; +uint32_t pkt_len =0 ; + +if (!vr) +return ; + +if (desc !=NULL && *desc !=NULL && vring->desc_head !=NULL ) { + desc_head = vring->desc_head; + pkt_len = vring->pkt_len; + }else { + desc_head =mlxbf_tmfifo_virtio_get_next_desc (vring->vq); +if (desc_head !=NULL ) { + pkt_len =mlxbf_tmfifo_virtio_get_pkt_len ( + vdev, desc_head, vr); + } + } + +if (desc_head !=NULL ) + mlxbf_tmfifo_virtio_release_desc(vdev, vr, desc_head,
pkt_len);drivers/platform/mellanox/mlxbf-tmfifo.c new file +29
-0+ +if (desc !=NULL ) + *desc =NULL ; + vring->pkt_len =0 ; +} + +/* House-keeping timer. */ +static void mlxbf_tmfifo_timer (struct timer_list *arg) { +struct mlxbf_tmfifo *fifo; + + fifo = container_of(arg, struct mlxbf_tmfifo, timer); + +/* +* Wake up the work handler to poll the Rx FIFO in case interrupt +* missing or any leftover bytes stuck in the FIFO. +*/ +test_and_set_bit (MLXBF_TM_RX_HWM_IRQ , &fifo->pend_events); + +/* +* Wake up Tx handler in case virtio has queued too many packets +* and are waiting for buffer return. +*/ +test_and_set_bit (MLXBF_TM_TX_LWM_IRQ , &fifo->pend_events); + +schedule_work (&fifo->work); + +mod_timer (&fifo->timer, jiffies + mlxbf_tmfifo_timer_interval); } + +/* Buffer the console output. */
drivers/platform/mellanox/mlxbf-tmfifo.c line 401
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +10
-0+static void mlxbf_tmfifo_console_output (struct mlxbf_tmfifo_vdev *cons, +struct virtqueue *vq) +{ +struct vring *vr = (struct vring *)virtqueue_get_vring (vq); +struct vring_desc *head_desc, *desc =NULL ; +struct virtio_device *vdev = &cons->vdev; +u32 len, pkt_len, idx; +void *addr; + +for (;;) {
It's better to modify it as while(on some condition)
drivers/platform/mellanox/mlxbf-tmfifo.c line 410
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +6
-0+ head_desc =mlxbf_tmfifo_virtio_get_next_desc (vq); +if (head_desc ==NULL ) +break ; + +/* Release the packet if no more space. */ + pkt_len = mlxbf_tmfifo_virtio_get_pkt_len(vdev, head_desc,vr);
drivers/platform/mellanox/mlxbf-tmfifo.c new file +3
-0+if (pkt_len >mlxbf_tmfifo_vdev_tx_buf_avail (cons)) { +mlxbf_tmfifo_virtio_release_desc (vdev, vr, head_desc, + pkt_len);
Why do you break line here?
drivers/platform/mellanox/mlxbf-tmfifo.c line 421
Quoted 11 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +11
-0+break ; + } + + desc = head_desc; + +while (desc !=NULL ) { + addr =phys_to_virt (virtio64_to_cpu (vdev, desc->addr)); + len =virtio32_to_cpu (vdev, desc->len); + +if (len <=MLXBF_TMFIFO_CONS_TX_BUF_SIZE - + cons->tx_tail) {
Why do you break line here? Also below I see few strange breaks.
Quoted 50 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +1
-0+ memcpy(cons->tx_buf + cons->tx_tail, addr,len);
drivers/platform/mellanox/mlxbf-tmfifo.c new file +6
-0+ }else { +u32 seg; + + seg =MLXBF_TMFIFO_CONS_TX_BUF_SIZE - + cons->tx_tail; + memcpy(cons->tx_buf + cons->tx_tail, addr,seg);
drivers/platform/mellanox/mlxbf-tmfifo.c new file +13
-0+ addr += seg; +memcpy (cons->tx_buf, addr, len - seg); + } +mlxbf_tmfifo_vdev_tx_buf_push (cons, len); + +if (!(virtio16_to_cpu (vdev, desc->flags) & +VRING_DESC_F_NEXT )) +break ; + idx =virtio16_to_cpu (vdev, desc->next); + desc = &vr->desc[idx]; + } + + mlxbf_tmfifo_virtio_release_desc(vdev, vr, head_desc,
pkt_len);drivers/platform/mellanox/mlxbf-tmfifo.c new file +27
-0+ } +} + +/* Rx & Tx processing of a virtual queue. */ static void +mlxbf_tmfifo_virtio_rxtx (struct virtqueue *vq,bool is_rx) { +int num_avail =0 , hdr_len, tx_reserve; +struct mlxbf_tmfifo_vring *vring; +struct mlxbf_tmfifo_vdev *cons; +struct virtio_device *vdev; +struct mlxbf_tmfifo *fifo; +struct vring_desc *desc; +unsigned long flags; +struct vring *vr; +u64 sts, data; +u32 len, idx; +void *addr; + +if (!vq) +return ; + + vring = (struct mlxbf_tmfifo_vring *)vq->priv; + fifo = vring->fifo; + vr = (struct vring *)virtqueue_get_vring (vq); + +if (!fifo->vdev[vring->vdev_id]) +return ; + vdev = &fifo->vdev[vring->vdev_id]->vdev;
drivers/platform/mellanox/mlxbf-tmfifo.c line 479
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +10
-0+ cons = fifo->vdev[VIRTIO_ID_CONSOLE ]; + +/* Don't continue if another vring is running. */ +if (fifo->vring[is_rx] !=NULL && fifo->vring[is_rx] != vring) +return ; + +/* tx_reserve is used to reserved some room in FIFO for console. */ +if (vring->vdev_id ==VIRTIO_ID_NET ) { + hdr_len =sizeof (struct virtio_net_hdr ); + tx_reserve = fifo->tx_fifo_size /16 ;
Use some define instead of 16/
drivers/platform/mellanox/mlxbf-tmfifo.c line 488
Quoted 9 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +9
-0+ }else { +BUG_ON (vring->vdev_id !=VIRTIO_ID_CONSOLE ); + hdr_len =0 ; + tx_reserve =1 ; + } + + desc = vring->desc; + +while (1 ) {
I see there are few drivers in platform which use while (1) But it looks better to use while(some condition) and instead of break change this condition to false.
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +4
-0+/* Get available FIFO space. */ +if (num_avail ==0 ) { +if (is_rx) { +/* Get the number of available words in FIFO. */
drivers/platform/mellanox/mlxbf-tmfifo.c new file +4
-0+ sts =readq (fifo->rx_base + +MLXBF_TMFIFO_RX_STS ); + num_avail = FIELD_GET( +MLXBF_TMFIFO_RX_STS__COUNT_MASK, sts);
num_avail = FIELD_GET(TMFIFO_RX_STS__COUNT_MASK, sts);
drivers/platform/mellanox/mlxbf-tmfifo.c line 508
Quoted 13 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +11
-0+ +/* Don't continue if nothing in FIFO. */ +if (num_avail <=0 ) +break ; + }else { +/* Get available space in FIFO. */ + sts =readq (fifo->tx_base + +MLXBF_TMFIFO_TX_STS ); + num_avail = fifo->tx_fifo_size - tx_reserve - + FIELD_GET( +
MLXBF_TMFIFO_TX_STS__COUNT_MASK,drivers/platform/mellanox/mlxbf-tmfifo.c new file +1
-0+ sts);
Same as above.
Quoted 178 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +36
-0+ +if (num_avail <=0 ) +break ; + } + } + +/* Console output always comes from the Tx buffer. */ +if (!is_rx && vring->vdev_id ==VIRTIO_ID_CONSOLE && + cons !=NULL && cons->tx_buf !=NULL ) { +union mlxbf_tmfifo_msg_hdr hdr; +int size; + + size =mlxbf_tmfifo_vdev_tx_buf_len (cons); +if (num_avail <2 || size ==0 ) +return ; +if (size +sizeof (hdr) > num_avail *sizeof (u64)) + size = num_avail *sizeof (u64) -sizeof (hdr); +/* Write header. */ + hdr.data =0 ; + hdr.type =VIRTIO_ID_CONSOLE ; + hdr.len =htons (size); +writeq (cpu_to_le64 (hdr.data), + fifo->tx_base +MLXBF_TMFIFO_TX_DATA ); + +spin_lock_irqsave (&fifo->spin_lock, flags); +while (size >0 ) { + addr = cons->tx_buf + cons->tx_head; + +if (cons->tx_head +sizeof (u64) <= +MLXBF_TMFIFO_CONS_TX_BUF_SIZE ) { +memcpy (&data, addr,sizeof (u64)); + }else { +int partial; + + partial = +
MLXBF_TMFIFO_CONS_TX_BUF_SIZE-drivers/platform/mellanox/mlxbf-tmfifo.c new file +74
-0+ cons->tx_head; + + memcpy(&data, addr, partial); + memcpy((u8 *)&data + partial, + cons->tx_buf, + sizeof(u64) - partial); + } + writeq(data, + fifo->tx_base + MLXBF_TMFIFO_TX_DATA); + + if (size >= sizeof(u64)) { + mlxbf_tmfifo_vdev_tx_buf_pop( + cons, sizeof(u64)); + size -= sizeof(u64); + } else { + mlxbf_tmfifo_vdev_tx_buf_pop( + cons, size); + size = 0; + } + } + spin_unlock_irqrestore(&fifo->spin_lock, flags); + return; + } + + /* Get the desc of next packet. */ + if (!desc) { + /* Save the head desc of the chain. */ + vring->desc_head = + mlxbf_tmfifo_virtio_get_next_desc(vq); + if (!vring->desc_head) { + vring->desc = NULL; + return; + } + desc = vring->desc_head; + vring->desc = desc; + + if (is_rx && vring->vdev_id == VIRTIO_ID_NET) { + struct virtio_net_hdr *net_hdr; + + /* Initialize the packet header. */ + net_hdr = (struct virtio_net_hdr *) + phys_to_virt(virtio64_to_cpu( + vdev, desc->addr)); + memset(net_hdr, 0, sizeof(*net_hdr)); + } + } + + /* Beginning of each packet. */ + if (vring->pkt_len == 0) { + int vdev_id, vring_change = 0; + union mlxbf_tmfifo_msg_hdr hdr; + + num_avail--; + + /* Read/Write packet length. */ + if (is_rx) { + hdr.data = readq(fifo->rx_base + + MLXBF_TMFIFO_RX_DATA); + hdr.data = le64_to_cpu(hdr.data); + + /* Skip the length 0 packet (keepalive). */ + if (hdr.len == 0) + continue; + + /* Check packet type. */ + if (hdr.type == VIRTIO_ID_NET) { + struct virtio_net_config *config; + + vdev_id = VIRTIO_ID_NET; + hdr_len = sizeof(struct virtio_net_hdr); + config = + &fifo->vdev[vdev_id]->config.net; + if (ntohs(hdr.len) > config->mtu + +
MLXBF_TMFIFO_NET_L2_OVERHEAD)drivers/platform/mellanox/mlxbf-tmfifo.c new file +22
-0+continue ; + }else if (hdr.type ==VIRTIO_ID_CONSOLE ) { + vdev_id =VIRTIO_ID_CONSOLE ; + hdr_len =0 ; + }else { +continue ; + } + +/* +* Check whether the new packet still belongs +* to this vring or not. If not, update the +* pkt_len of the new vring and return. +*/ +if (vdev_id != vring->vdev_id) { +struct mlxbf_tmfifo_vdev *dev2 = + fifo->vdev[vdev_id]; + +if (!dev2) +break ; + vring->desc = desc; + vring = + &dev2-Quoted 1 line
vrings[MLXBF_TMFIFO_VRING_RX];
drivers/platform/mellanox/mlxbf-tmfifo.c new file +40
-0+ vring_change =1 ; + } + vring->pkt_len =ntohs (hdr.len) + hdr_len; + }else { + vring->pkt_len = +mlxbf_tmfifo_virtio_get_pkt_len ( + vdev, desc, vr); + + hdr.data =0 ; + hdr.type = (vring->vdev_id ==VIRTIO_ID_NET ) ? +VIRTIO_ID_NET : +VIRTIO_ID_CONSOLE ; + hdr.len =htons (vring->pkt_len - hdr_len); +writeq (cpu_to_le64 (hdr.data), + fifo->tx_base +MLXBF_TMFIFO_TX_DATA ); + } + + vring->cur_len = hdr_len; + vring->rem_len = vring->pkt_len; + fifo->vring[is_rx] = vring; + +if (vring_change) +return ; +continue ; + } + +/* Check available space in this desc. */ + len =virtio32_to_cpu (vdev, desc->len); +if (len > vring->rem_len) + len = vring->rem_len; + +/* Check if the current desc is already done. */ +if (vring->cur_len == len) + goto check_done; + + addr =phys_to_virt (virtio64_to_cpu (vdev, desc->addr)); + +/* Read a word from FIFO for Rx. */ +if (is_rx) { + data = readq(fifo->rx_base +
MLXBF_TMFIFO_RX_DATA);drivers/platform/mellanox/mlxbf-tmfifo.c new file +2
-0+ data =le64_to_cpu (data); + }
drivers/platform/mellanox/mlxbf-tmfifo.c line 692
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +10
-0+ +if (vring->cur_len +sizeof (u64) <= len) { +/* The whole word. */ +if (is_rx) { +memcpy (addr + vring->cur_len, &data, +sizeof (u64)); + }else { +memcpy (&data, addr + vring->cur_len, +sizeof (u64)); + }
Why not just.
Also few places like this one below.
if (is_rx) memcpy(addr + vring->cur_len, &data, sizeof(u64)); else memcpy(&data, addr + vring->cur_len, sizeof(u64));
Quoted 42 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +42
-0+ vring->cur_len +=sizeof (u64); + }else { +/* Leftover bytes. */ +BUG_ON (vring->cur_len > len); +if (is_rx) { +memcpy (addr + vring->cur_len, &data, + len - vring->cur_len); + }else { +memcpy (&data, addr + vring->cur_len, + len - vring->cur_len); + } + vring->cur_len = len; + } + +/* Write the word into FIFO for Tx. */ +if (!is_rx) { +writeq (cpu_to_le64 (data), + fifo->tx_base +MLXBF_TMFIFO_TX_DATA ); + } + + num_avail--; + +check_done: +/* Check whether this desc is full or completed. */ +if (vring->cur_len == len) { + vring->cur_len =0 ; + vring->rem_len -= len; + +/* Get the next desc on the chain. */ +if (vring->rem_len >0 && + (virtio16_to_cpu (vdev, desc->flags) & +VRING_DESC_F_NEXT )) { + idx =virtio16_to_cpu (vdev, desc->next); + desc = &vr->desc[idx]; +continue ; + } + +/* Done and release the desc. */ +mlxbf_tmfifo_release_pkt (vdev, vring, &desc); + fifo->vring[is_rx] =NULL ; + +/* Notify upper layer that packet is done. */
drivers/platform/mellanox/mlxbf-tmfifo.c line 744
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +10
-0+spin_lock_irqsave (&fifo->spin_lock, flags); +vring_interrupt (0 , vq); +spin_unlock_irqrestore (&fifo->spin_lock, flags); +continue ; + } + } + +/* Save the current desc. */ + vring->desc = desc; +}
I suggest to split mlxbf_tmfifo_virtio_rxtx() into few small routines.
Quoted 20 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +17
-0+ +/* The notify function is called when new buffers are posted. */ static +bool mlxbf_tmfifo_virtio_notify(struct virtqueue *vq) { + struct mlxbf_tmfifo_vring *vring; + struct mlxbf_tmfifo *fifo; + unsigned long flags; + + vring = (struct mlxbf_tmfifo_vring *)vq->priv; + fifo = vring->fifo; + + /* + * Virtio maintains vrings in pairs, even number ring for Rx + * and odd number ring for Tx. + */ + if (!(vring->id & 1)) { + /* Set the RX HWM bit to start Rx. */ + if (!test_and_set_bit(MLXBF_TM_RX_HWM_IRQ, &fifo-Quoted 1 line
pend_events))drivers/platform/mellanox/mlxbf-tmfifo.c new file +2
-0+schedule_work (&fifo->work); + }else {
drivers/platform/mellanox/mlxbf-tmfifo.c line 774
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +10
-0+/* +* Console could make blocking call with interrupts disabled. +* In such case, the vring needs to be served right away. For +* other cases, just set the TX LWM bit to start Tx in the +* worker handler. +*/ +if (vring->vdev_id ==VIRTIO_ID_CONSOLE ) { +spin_lock_irqsave (&fifo->spin_lock, flags); +mlxbf_tmfifo_console_output ( + fifo->vdev[VIRTIO_ID_CONSOLE ], vq);
mlxbf_tmfifo_console_output(fifo->vdev[VIRTIO_ID_CONSOLE], vq);
drivers/platform/mellanox/mlxbf-tmfifo.c line 779
Quoted 5 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +5
-0+spin_unlock_irqrestore (&fifo->spin_lock, flags); +schedule_work (&fifo->work); + }else if (!test_and_set_bit (MLXBF_TM_TX_LWM_IRQ , + &fifo->pend_events)) +schedule_work (&fifo->work);
If {
} else if {
}For consistency.
Quoted 20 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +19
-0+ } + +return true; +} + +/* Work handler for Rx and Tx case. */ +static void mlxbf_tmfifo_work_handler (struct work_struct *work) { +struct mlxbf_tmfifo_vdev *tm_vdev; +struct mlxbf_tmfifo *fifo; +int i; + + fifo = container_of(work, struct mlxbf_tmfifo, work); +if (!fifo->is_ready) +return ; + +mutex_lock (&fifo->lock); + +/* Tx (Send data to the TmFifo). */ + if (test_and_clear_bit(MLXBF_TM_TX_LWM_IRQ, &fifo->pend_events)&&
drivers/platform/mellanox/mlxbf-tmfifo.c
Quoted 2 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +2
-0+ fifo->irq_info[MLXBF_TM_TX_LWM_IRQ].irq) { +for (i =0 ; i <MLXBF_TMFIFO_VDEV_MAX ; i++) {
I suggest to define local variable vq.
And have below:
mlxbf_tmfifo_virtio_rxtx(vq, false);
Quoted 13 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +4
-0+ tm_vdev = fifo->vdev[i]; +if (tm_vdev !=NULL ) { + mlxbf_tmfifo_virtio_rxtx( + tm_vdev-Quoted 1 line
vrings[MLXBF_TMFIFO_VRING_TX].vq,
drivers/platform/mellanox/mlxbf-tmfifo.c new file +7
-0+ false); + } + } + } + +/* Rx (Receive data from the TmFifo). */ + if (test_and_clear_bit(MLXBF_TM_RX_HWM_IRQ, &fifo->pend_events)&&
drivers/platform/mellanox/mlxbf-tmfifo.c line 815
Quoted 3 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +3
-0+ fifo->irq_info[MLXBF_TM_RX_HWM_IRQ].irq) { +for (i =0 ; i <MLXBF_TMFIFO_VDEV_MAX ; i++) { + tm_vdev = fifo->vdev[i];
Same as above.
Quoted 59 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +3
-0+if (tm_vdev !=NULL ) { + mlxbf_tmfifo_virtio_rxtx( + tm_vdev-Quoted 1 line
vrings[MLXBF_TMFIFO_VRING_RX].vq,
drivers/platform/mellanox/mlxbf-tmfifo.c new file +55
-0+ true); + } + } + } + +mutex_unlock (&fifo->lock); +} + +/* Get the array of feature bits for this device. */ static u64 +mlxbf_tmfifo_virtio_get_features (struct virtio_device *vdev) { +struct mlxbf_tmfifo_vdev *tm_vdev; + + tm_vdev = container_of(vdev, struct mlxbf_tmfifo_vdev, vdev); +return tm_vdev->features; +} + +/* Confirm device features to use. */ +static int mlxbf_tmfifo_virtio_finalize_features (struct virtio_device +*vdev) { +struct mlxbf_tmfifo_vdev *tm_vdev; + + tm_vdev = container_of(vdev, struct mlxbf_tmfifo_vdev, vdev); + tm_vdev->features = vdev->features; + +return 0 ; +} + +/* Free virtqueues found by find_vqs(). */ static void +mlxbf_tmfifo_virtio_del_vqs (struct virtio_device *vdev) { +struct mlxbf_tmfifo_vdev *tm_vdev; +struct mlxbf_tmfifo_vring *vring; +struct virtqueue *vq; +int i; + + tm_vdev = container_of(vdev, struct mlxbf_tmfifo_vdev, vdev); + +for (i =0 ; i <ARRAY_SIZE (tm_vdev->vrings); i++) { + vring = &tm_vdev->vrings[i]; + +/* Release the pending packet. */ +if (vring->desc !=NULL ) { +mlxbf_tmfifo_release_pkt (&tm_vdev->vdev, vring, + &vring->desc); + } + + vq = vring->vq; +if (vq) { + vring->vq =NULL ; +vring_del_virtqueue (vq); + } + } +} + +/* Create and initialize the virtual queues. */ static int +mlxbf_tmfifo_virtio_find_vqs(struct virtio_device *vdev,
drivers/platform/mellanox/mlxbf-tmfifo.c line 885
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +10
-0+unsigned int nvqs, + struct virtqueue *vqs[], + vq_callback_t *callbacks[], + const char * const names[], + const bool *ctx, + struct irq_affinity *desc) +{ + struct mlxbf_tmfifo_vdev *tm_vdev; +struct mlxbf_tmfifo_vring *vring; +int i, ret = -EINVAL , size;
Don't initialize ret with -EINVAL.
Quoted 63 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +63
-0+struct virtqueue *vq; + + tm_vdev = container_of(vdev, struct mlxbf_tmfifo_vdev, vdev); +if (nvqs >ARRAY_SIZE (tm_vdev->vrings)) +return -EINVAL ; + +for (i =0 ; i < nvqs; ++i) { +if (!names[i]) + goto error; + vring = &tm_vdev->vrings[i]; + +/* zero vring */ + size =vring_size (vring->size, vring->align); +memset (vring->va,0 , size); + vq =vring_new_virtqueue (i, vring->size, vring->align, vdev, + false, false, vring->va, + mlxbf_tmfifo_virtio_notify, + callbacks[i], names[i]); +if (!vq) { +dev_err (&vdev->dev,"vring_new_virtqueue failed\n" ); + ret = -ENOMEM ; + goto error; + } + + vqs[i] = vq; + vring->vq = vq; + vq->priv = vring; + } + +return 0 ; + +error: +mlxbf_tmfifo_virtio_del_vqs (vdev); +return ret; +} + +/* Read the status byte. */ +static u8 mlxbf_tmfifo_virtio_get_status (struct virtio_device *vdev) { +struct mlxbf_tmfifo_vdev *tm_vdev; + + tm_vdev = container_of(vdev, struct mlxbf_tmfifo_vdev, vdev); + +return tm_vdev->status; +} + +/* Write the status byte. */ +static void mlxbf_tmfifo_virtio_set_status (struct virtio_device *vdev, +u8 status) +{ +struct mlxbf_tmfifo_vdev *tm_vdev; + + tm_vdev = container_of(vdev, struct mlxbf_tmfifo_vdev, vdev); + tm_vdev->status = status; +} + +/* Reset the device. Not much here for now. */ static void +mlxbf_tmfifo_virtio_reset (struct virtio_device *vdev) { +struct mlxbf_tmfifo_vdev *tm_vdev; + + tm_vdev = container_of(vdev, struct mlxbf_tmfifo_vdev, vdev); + tm_vdev->status =0 ; +} +
drivers/platform/mellanox/mlxbf-tmfifo.c line 960
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +10
-0+/* Read the value of a configuration field. */ static void +mlxbf_tmfifo_virtio_get (struct virtio_device *vdev, +unsigned int offset, +void *buf, +unsigned int len) +{ +struct mlxbf_tmfifo_vdev *tm_vdev; + + tm_vdev = container_of(vdev, struct mlxbf_tmfifo_vdev, vdev); +
unsigned int pos = offset + len; if (pos > sizeof(tm_vdev->config) || pos < len)
Quoted 8 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +8
-0+if (offset + len >sizeof (tm_vdev->config) || offset + len < len) { +dev_err (vdev->dev.parent,"virtio_get access out of bounds\n" ); +return ; + } + +memcpy (buf, (u8 *)&tm_vdev->config + offset, len); } + +/* Write the value of a configuration field. */ static void
drivers/platform/mellanox/mlxbf-tmfifo.c line 979
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +10
-0+mlxbf_tmfifo_virtio_set(struct virtio_device *vdev, + unsigned int offset, + const void *buf, + unsigned int len) +{ + struct mlxbf_tmfifo_vdev *tm_vdev; + + tm_vdev = container_of(vdev, struct mlxbf_tmfifo_vdev, vdev); + +if (offset + len >sizeof (tm_vdev->config) || offset + len < len) {
Same as above.
Quoted 92 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +54
-0+dev_err (vdev->dev.parent,"virtio_get access out of bounds\n" ); +return ; + } + +memcpy ((u8 *)&tm_vdev->config + offset, buf, len); } + +/* Virtio config operations. */ +static const struct virtio_config_ops mlxbf_tmfifo_virtio_config_ops = { + .get_features = mlxbf_tmfifo_virtio_get_features, + .finalize_features = mlxbf_tmfifo_virtio_finalize_features, + .find_vqs = mlxbf_tmfifo_virtio_find_vqs, + .del_vqs = mlxbf_tmfifo_virtio_del_vqs, + .reset = mlxbf_tmfifo_virtio_reset, + .set_status = mlxbf_tmfifo_virtio_set_status, + .get_status = mlxbf_tmfifo_virtio_get_status, + .get = mlxbf_tmfifo_virtio_get, + .set = mlxbf_tmfifo_virtio_set, +}; + +/* Create vdev type in a tmfifo. */ +int mlxbf_tmfifo_create_vdev (struct mlxbf_tmfifo *fifo,int vdev_id, +u64 features,void *config,u32 size) { +struct mlxbf_tmfifo_vdev *tm_vdev; +int ret =0 ; + +mutex_lock (&fifo->lock); + + tm_vdev = fifo->vdev[vdev_id]; +if (tm_vdev !=NULL ) { +pr_err ("vdev %d already exists\n" , vdev_id); + ret = -EEXIST ; + goto already_exist; + } + + tm_vdev =kzalloc (sizeof (*tm_vdev),GFP_KERNEL ); +if (!tm_vdev) { + ret = -ENOMEM ; + goto already_exist; + } + + tm_vdev->vdev.id.device = vdev_id; + tm_vdev->vdev.config = &mlxbf_tmfifo_virtio_config_ops; + tm_vdev->vdev.dev.parent = &fifo->pdev->dev; + tm_vdev->vdev.dev.release = mlxbf_tmfifo_virtio_dev_release; + tm_vdev->features = features; +if (config) +memcpy (&tm_vdev->config, config, size); +if (mlxbf_tmfifo_alloc_vrings (fifo, tm_vdev, vdev_id)) { +pr_err ("Unable to allocate vring\n" ); + ret = -ENOMEM ; + goto alloc_vring_fail; + } +if (vdev_id ==VIRTIO_ID_CONSOLE ) { + tm_vdev->tx_buf =kmalloc(MLXBF_TMFIFO_CONS_TX_BUF_SIZE,
drivers/platform/mellanox/mlxbf-tmfifo.c new file +37
-0+ GFP_KERNEL); + } + fifo->vdev[vdev_id] = tm_vdev; + +/* Register the virtio device. */ + ret =register_virtio_device (&tm_vdev->vdev); +if (ret) { +dev_err (&fifo->pdev->dev,"register_virtio_device() failed\n" ); + goto register_fail; + } + +mutex_unlock (&fifo->lock); +return 0 ; + +register_fail: +mlxbf_tmfifo_free_vrings (fifo, vdev_id); + fifo->vdev[vdev_id] =NULL ; +alloc_vring_fail: +kfree (tm_vdev); +already_exist: +mutex_unlock (&fifo->lock); +return ret; +} + +/* Delete vdev type from a tmfifo. */ +int mlxbf_tmfifo_delete_vdev (struct mlxbf_tmfifo *fifo,int vdev_id) { +struct mlxbf_tmfifo_vdev *tm_vdev; + +mutex_lock (&fifo->lock); + +/* Unregister vdev. */ + tm_vdev = fifo->vdev[vdev_id]; +if (tm_vdev) { +unregister_virtio_device (&tm_vdev->vdev); +mlxbf_tmfifo_free_vrings (fifo, vdev_id); +kfree (tm_vdev->tx_buf); +kfree (tm_vdev);
drivers/platform/mellanox/mlxbf-tmfifo.c
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +10
-0+ fifo->vdev[vdev_id] =NULL ; + } + +mutex_unlock (&fifo->lock); + +return 0 ; +} + +/* Device remove function. */ +static int mlxbf_tmfifo_remove (struct platform_device *pdev) {
Locate it after probe.
If you'll use all devm_, like Andy noted:devm_ioremapdevm_ioremap_resourcedevm_kzallocdevm_request_mem_region
you can drop all kfree, release_mem_region, iounmap
And make the below as a separate routine, something like mlxbf_tmfifo_cleanup(), if you still need it.
Quoted 37 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +37
-0+struct mlxbf_tmfifo *fifo =platform_get_drvdata (pdev); +struct resource *rx_res, *tx_res; +int i; + +if (fifo) { +mutex_lock (&mlxbf_tmfifo_lock); + + fifo->is_ready = false; + +/* Stop the timer. */ +del_timer_sync (&fifo->timer); + +/* Release interrupts. */ +mlxbf_tmfifo_free_irqs (fifo); + +/* Cancel the pending work. */ +cancel_work_sync (&fifo->work); + +for (i =0 ; i <MLXBF_TMFIFO_VDEV_MAX ; i++) +mlxbf_tmfifo_delete_vdev (fifo, i); + +/* Release IO resources. */ +if (fifo->rx_base) +iounmap (fifo->rx_base); +if (fifo->tx_base) +iounmap (fifo->tx_base); + +platform_set_drvdata (pdev,NULL ); +kfree (fifo); + +mutex_unlock (&mlxbf_tmfifo_lock); + } + + rx_res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +if (rx_res) +release_mem_region (rx_res->start,resource_size (rx_res)); + tx_res =platform_get_resource (pdev,IORESOURCE_MEM ,1 );
drivers/platform/mellanox/mlxbf-tmfifo.c line 1132
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +10
-0+if (tx_res) +release_mem_region (tx_res->start,resource_size (tx_res)); + +return 0 ; +} + +/* Read the configured network MAC address from efi variable. */ static +void mlxbf_tmfifo_get_cfg_mac (u8 *mac) { +efi_char16_t name[] = { +'R' ,'s' ,'h' ,'i' ,'m' ,'M' ,'a' ,'c' ,'A' ,'d' ,'d' ,'r' ,0 };
Could it be moved out and set like:
static const efi_char16_t mlxbf_tmfifo_efi_name[] = "..."; Could you check if the are some examples in kernel, please?
Quoted 160 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +80
-0+efi_guid_t guid =EFI_GLOBAL_VARIABLE_GUID ; +efi_status_t status; +unsigned long size; +u8 buf[6 ]; + + size =sizeof (buf); + status = efi.get_variable (name, &guid,NULL , &size, buf); +if (status ==EFI_SUCCESS && size ==sizeof (buf)) +memcpy (mac, buf,sizeof (buf)); +} + +/* Probe the TMFIFO. */ +static int mlxbf_tmfifo_probe (struct platform_device *pdev) { +struct virtio_net_config net_config; +struct resource *rx_res, *tx_res; +struct mlxbf_tmfifo *fifo; +int i, ret; +u64 ctl; + +/* Get the resource of the Rx & Tx FIFO. */ + rx_res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + tx_res =platform_get_resource (pdev,IORESOURCE_MEM ,1 ); +if (!rx_res || !tx_res) { + ret = -EINVAL ; + goto err; + } + +if (request_mem_region (rx_res->start, +resource_size (rx_res),"bf-tmfifo" ) ==NULL ) { + ret = -EBUSY ; + goto early_err; + } + +if (request_mem_region (tx_res->start, +resource_size (tx_res),"bf-tmfifo" ) ==NULL ) { +release_mem_region (rx_res->start,resource_size (rx_res)); + ret = -EBUSY ; + goto early_err; + } + + ret = -ENOMEM ; + fifo =kzalloc (sizeof (struct mlxbf_tmfifo ),GFP_KERNEL ); +if (!fifo) + goto err; + + fifo->pdev = pdev; +platform_set_drvdata (pdev, fifo); + +spin_lock_init (&fifo->spin_lock); +INIT_WORK (&fifo->work, mlxbf_tmfifo_work_handler); + +timer_setup (&fifo->timer, mlxbf_tmfifo_timer,0 ); + fifo->timer.function = mlxbf_tmfifo_timer; + +for (i =0 ; i <MLXBF_TM_IRQ_CNT ; i++) { + fifo->irq_info[i].index = i; + fifo->irq_info[i].fifo = fifo; + fifo->irq_info[i].irq =platform_get_irq (pdev, i); + ret =request_irq (fifo->irq_info[i].irq, + mlxbf_tmfifo_irq_handler,0 , +"tmfifo" , &fifo->irq_info[i]); +if (ret) { +pr_err ("Unable to request irq\n" ); + fifo->irq_info[i].irq =0 ; + goto err; + } + } + + fifo->rx_base =ioremap (rx_res->start,resource_size (rx_res)); +if (!fifo->rx_base) + goto err; + + fifo->tx_base =ioremap (tx_res->start,resource_size (tx_res)); +if (!fifo->tx_base) + goto err; + +/* Get Tx FIFO size and set the low/high watermark. */ + ctl =readq (fifo->tx_base +MLXBF_TMFIFO_TX_CTL ); + fifo->tx_fifo_size = + FIELD_GET(MLXBF_TMFIFO_TX_CTL__MAX_ENTRIES_MASK,ctl);
drivers/platform/mellanox/mlxbf-tmfifo.c new file +12
-0+ ctl = (ctl & ~MLXBF_TMFIFO_TX_CTL__LWM_MASK ) | +FIELD_PREP (MLXBF_TMFIFO_TX_CTL__LWM_MASK , + fifo->tx_fifo_size /2 ); + ctl = (ctl & ~MLXBF_TMFIFO_TX_CTL__HWM_MASK ) | +FIELD_PREP (MLXBF_TMFIFO_TX_CTL__HWM_MASK , + fifo->tx_fifo_size -1 ); +writeq (ctl, fifo->tx_base +MLXBF_TMFIFO_TX_CTL ); + +/* Get Rx FIFO size and set the low/high watermark. */ + ctl =readq (fifo->rx_base +MLXBF_TMFIFO_RX_CTL ); + fifo->rx_fifo_size = + FIELD_GET(MLXBF_TMFIFO_RX_CTL__MAX_ENTRIES_MASK,ctl);
drivers/platform/mellanox/mlxbf-tmfifo.c new file +21
-0+ ctl = (ctl & ~MLXBF_TMFIFO_RX_CTL__LWM_MASK ) | +FIELD_PREP (MLXBF_TMFIFO_RX_CTL__LWM_MASK ,0 ); + ctl = (ctl & ~MLXBF_TMFIFO_RX_CTL__HWM_MASK ) | +FIELD_PREP (MLXBF_TMFIFO_RX_CTL__HWM_MASK ,1 ); +writeq (ctl, fifo->rx_base +MLXBF_TMFIFO_RX_CTL ); + +mutex_init (&fifo->lock); + +/* Create the console vdev. */ + ret =mlxbf_tmfifo_create_vdev (fifo,VIRTIO_ID_CONSOLE ,0 ,NULL ,0 ); +if (ret) + goto err; + +/* Create the network vdev. */ +memset (&net_config,0 ,sizeof (net_config)); + net_config.mtu =MLXBF_TMFIFO_NET_MTU ; + net_config.status =VIRTIO_NET_S_LINK_UP ; +memcpy (net_config.mac, mlxbf_tmfifo_net_default_mac,6 ); +mlxbf_tmfifo_get_cfg_mac (net_config.mac); + ret = mlxbf_tmfifo_create_vdev(fifo, VIRTIO_ID_NET, + MLXBF_TMFIFO_NET_FEATURES, &net_config,
sizeof(net_config));drivers/platform/mellanox/mlxbf-tmfifo.c new file +42
-1+if (ret) + goto err; + +mod_timer (&fifo->timer, jiffies + mlxbf_tmfifo_timer_interval); + + fifo->is_ready = true; + +return 0 ; + +err: +mlxbf_tmfifo_remove (pdev); +early_err: +dev_err (&pdev->dev,"Probe Failed\n" ); +return ret; +} + +static const struct of_device_id mlxbf_tmfifo_match[] = { + { .compatible ="mellanox,bf-tmfifo" }, + {}, +}; +MODULE_DEVICE_TABLE (of, mlxbf_tmfifo_match); + +static const struct acpi_device_id mlxbf_tmfifo_acpi_match[] = { + {"MLNXBF01" ,0 }, + {}, +}; +MODULE_DEVICE_TABLE (acpi, mlxbf_tmfifo_acpi_match); + +static struct platform_driver mlxbf_tmfifo_driver = { + .probe = mlxbf_tmfifo_probe, + .remove = mlxbf_tmfifo_remove, + .driver = { + .name ="bf-tmfifo" , + .of_match_table = mlxbf_tmfifo_match, + .acpi_match_table =ACPI_PTR (mlxbf_tmfifo_acpi_match), + }, +}; + +module_platform_driver (mlxbf_tmfifo_driver); + +MODULE_DESCRIPTION ("Mellanox BlueField SoC TmFifo Driver" ); +MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Mellanox Technologies" ); --1.8.3.1
Re: [PATCH v8 1/2] platform/mellanox: Add TmFifo driver for Mellanox BlueField Soc
Thanks Vadim! The v9 has been posted to solve these comments. (Also thanks a lot for the comments in the internal review.)
Regards,
Liming
________________________________
From: Vadim Pasternak
Sent: Wednesday, January 30, 2019 1:24 AM
To: Liming Sun; Rob Herring; Mark Rutland; Arnd Bergmann; David Woods; Andy Shevchenko; Darren Hart
Cc: Liming Sun; [email protected]; [email protected]; [email protected]
Subject: RE: [PATCH v8 1/2] platform/mellanox: Add TmFifo driver for Mellanox BlueField Soc
Quoted 44 lines
-----Original Message-----
From: Liming Sun <[email protected]>
Sent: Monday, January 28, 2019 7:28 PM
To: Rob Herring <[email protected]>; Mark Rutland <[email protected]>; Arnd Bergmann <[email protected]>; David Woods <[email protected]>; Andy Shevchenko <[email protected]>; Darren Hart <[email protected]>; Vadim Pasternak <[email protected]>
Cc: Liming Sun <[email protected]>; [email protected]; linux- [email protected]; [email protected]
Subject: [PATCH v8 1/2] platform/mellanox: Add TmFifo driver for Mellanox BlueField SocThis commit adds the TmFifo platform driver for Mellanox BlueField Soc. TmFifo is a shared FIFO which enables external host machine to exchange data with the SoC via USB or PCIe. The driver is based on virtio framework and has console and network access enabled.
Reviewed-by David Woods <[email protected]>Signed-off-by Liming Sun <[email protected]>--- drivers/platform/mellanox/Kconfig | 13 +- drivers/platform/mellanox/Makefile | 1 + drivers/platform/mellanox/mlxbf-tmfifo-regs.h | 67 ++ drivers/platform/mellanox/mlxbf-tmfifo.c | 1289 +++++++++++++++++++++++++ 4 files changed, 1369 insertions(+), 1 deletion(-) create mode 100644 drivers/platform/mellanox/mlxbf-tmfifo-regs.h create mode 100644 drivers/platform/mellanox/mlxbf-tmfifo.cdrivers/platform/mellanox/Kconfig +1
-1@@ -5,7 +5,7 @@ menuconfig MELLANOX_PLATFORM bool "Platform support for Mellanox hardware" - depends on X86 || ARM || COMPILE_TEST + depends on X86 || ARM || ARM64 || COMPILE_TEST ---help--- Say Y here to get to see options for platform support for Mellanox systems. This option alone does not add any kernel code.
drivers/platform/mellanox/Kconfig config MLXREG_IO · line 39
Quoted 6 lines
drivers/platform/mellanox/Kconfig +3
-0@@ -34,4 +34,15 @@ config MLXREG_IO to system resets operation, system reset causes monitoring and some kinds of mux selection. +config MLXBF_TMFIFO + tristate "Mellanox BlueField SoC TmFifo platform driver" + depends on ARM64
Why you make it dependent on ARM64?
Should not it work on any host, x86?
drivers/platform/mellanox/Kconfig config MLXREG_IO · line 40
Quoted 1 line
drivers/platform/mellanox/Kconfig +1
-0+ default m
User who needs it should select this option.
No need default 'm'.
Quoted 121 lines
drivers/platform/mellanox/Kconfig +7
-0+ select VIRTIO_CONSOLE + select VIRTIO_NET + help + Say y here to enable TmFifo support. The TmFifo driver provides + platform driver support for the TmFifo which supports console + and networking based on the virtio framework. + endif # MELLANOX_PLATFORMdrivers/platform/mellanox/Makefile +1
-0@@ -5,3 +5,4 @@ # obj-$(CONFIG_MLXREG_HOTPLUG) += mlxreg-hotplug.o obj-$(CONFIG_MLXREG_IO) += mlxreg-io.o +obj-$(CONFIG_MLXBF_TMFIFO) += mlxbf-tmfifo.odrivers/platform/mellanox/mlxbf-tmfifo-regs.h new file +23
-0@@ -0,0 +1,67 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2019, Mellanox Technologies. All rights reserved. +*/ + +#ifndef __MLXBF_TMFIFO_REGS_H__ +#define __MLXBF_TMFIFO_REGS_H__ + +#include <linux/types.h> + +#define MLXBF_TMFIFO_TX_DATA 0x0 + +#define MLXBF_TMFIFO_TX_STS 0x8 +#define MLXBF_TMFIFO_TX_STS__LENGTH 0x0001 #define +MLXBF_TMFIFO_TX_STS__COUNT_SHIFT 0 #define +MLXBF_TMFIFO_TX_STS__COUNT_WIDTH 9 #define +MLXBF_TMFIFO_TX_STS__COUNT_RESET_VAL 0 #define +MLXBF_TMFIFO_TX_STS__COUNT_RMASK 0x1ff #define +MLXBF_TMFIFO_TX_STS__COUNT_MASK 0x1ff + +#define MLXBF_TMFIFO_TX_CTL 0x10 +#define MLXBF_TMFIFO_TX_CTL__LENGTH 0x0001 #define +MLXBF_TMFIFO_TX_CTL__LWM_SHIFT 0 #define
MLXBF_TMFIFO_TX_CTL__LWM_WIDTH
+8 #defineMLXBF_TMFIFO_TX_CTL__LWM_RESET_VAL128 #definedrivers/platform/mellanox/mlxbf-tmfifo-regs.h new file +3
-0+MLXBF_TMFIFO_TX_CTL__LWM_RMASK 0xff #define +MLXBF_TMFIFO_TX_CTL__LWM_MASK 0xff #define +MLXBF_TMFIFO_TX_CTL__HWM_SHIFT 8 #define
MLXBF_TMFIFO_TX_CTL__HWM_WIDTH
+8 #defineMLXBF_TMFIFO_TX_CTL__HWM_RESET_VAL128 #definedrivers/platform/mellanox/mlxbf-tmfifo-regs.h new file +21
-0+MLXBF_TMFIFO_TX_CTL__HWM_RMASK 0xff #define +MLXBF_TMFIFO_TX_CTL__HWM_MASK 0xff00 #define +MLXBF_TMFIFO_TX_CTL__MAX_ENTRIES_SHIFT 32 #define +MLXBF_TMFIFO_TX_CTL__MAX_ENTRIES_WIDTH 9 #define +MLXBF_TMFIFO_TX_CTL__MAX_ENTRIES_RESET_VAL 256 #define +MLXBF_TMFIFO_TX_CTL__MAX_ENTRIES_RMASK 0x1ff #define +MLXBF_TMFIFO_TX_CTL__MAX_ENTRIES_MASK 0x1ff00000000ULL + +#define MLXBF_TMFIFO_RX_DATA 0x0 + +#define MLXBF_TMFIFO_RX_STS 0x8 +#define MLXBF_TMFIFO_RX_STS__LENGTH 0x0001 #define +MLXBF_TMFIFO_RX_STS__COUNT_SHIFT 0 #define +MLXBF_TMFIFO_RX_STS__COUNT_WIDTH 9 #define +MLXBF_TMFIFO_RX_STS__COUNT_RESET_VAL 0 #define +MLXBF_TMFIFO_RX_STS__COUNT_RMASK 0x1ff #define +MLXBF_TMFIFO_RX_STS__COUNT_MASK 0x1ff + +#define MLXBF_TMFIFO_RX_CTL 0x10 +#define MLXBF_TMFIFO_RX_CTL__LENGTH 0x0001 #define +MLXBF_TMFIFO_RX_CTL__LWM_SHIFT 0 #define
MLXBF_TMFIFO_RX_CTL__LWM_WIDTH
+8 #defineMLXBF_TMFIFO_RX_CTL__LWM_RESET_VAL128 #definedrivers/platform/mellanox/mlxbf-tmfifo-regs.h new file +3
-0+MLXBF_TMFIFO_RX_CTL__LWM_RMASK 0xff #define +MLXBF_TMFIFO_RX_CTL__LWM_MASK 0xff #define +MLXBF_TMFIFO_RX_CTL__HWM_SHIFT 8 #define
MLXBF_TMFIFO_RX_CTL__HWM_WIDTH
+8 #defineMLXBF_TMFIFO_RX_CTL__HWM_RESET_VAL128 #definedrivers/platform/mellanox/mlxbf-tmfifo-regs.h new file +9
-0+MLXBF_TMFIFO_RX_CTL__HWM_RMASK 0xff #define +MLXBF_TMFIFO_RX_CTL__HWM_MASK 0xff00 #define +MLXBF_TMFIFO_RX_CTL__MAX_ENTRIES_SHIFT 32 #define +MLXBF_TMFIFO_RX_CTL__MAX_ENTRIES_WIDTH 9 #define +MLXBF_TMFIFO_RX_CTL__MAX_ENTRIES_RESET_VAL 256 #define +MLXBF_TMFIFO_RX_CTL__MAX_ENTRIES_RMASK 0x1ff #define +MLXBF_TMFIFO_RX_CTL__MAX_ENTRIES_MASK 0x1ff00000000ULL + +#endif /* !defined(__MLXBF_TMFIFO_REGS_H__) */ drivers/platform/mellanox/mlxbf-tmfifo.c new file +22
-0@@ -0,0 +1,1289 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Mellanox BlueField SoC TmFifo driver +* +* Copyright (C) 2019 Mellanox Technologies */ + +#include <linux/acpi.h> +#include <linux/bitfield.h> +#include <linux/cache.h> +#include <linux/device.h> +#include <linux/dma-mapping.h> +#include <linux/efi.h> +#include <linux/io.h> +#include <linux/interrupt.h> +#include <linux/irq.h> +#include <linux/kernel.h> +#include <linux/math64.h> +#include <linux/module.h> +#include <linux/moduleparam.h> +#include <linux/mutex.h> +#include <linux/platform_device.h> +#include <linux/resource.h>
drivers/platform/mellanox/mlxbf-tmfifo.c line 32
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +10
-0+#include <linux/slab.h> +#include <linux/types.h> +#include <linux/version.h> +#include <linux/virtio.h> +#include <linux/virtio_config.h> +#include <linux/virtio_console.h> +#include <linux/virtio_ids.h> +#include <linux/virtio_net.h> +#include <linux/virtio_ring.h> +#include <asm/byteorder.h>
Is it must ti include from asm?
Could it be replaced with something like
#include <linux/byteorder/generic.h>
Quoted 120 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +77
-0+ +#include "mlxbf-tmfifo-regs.h" + +/* Vring size. */ +#define MLXBF_TMFIFO_VRING_SIZE 1024 + +/* Console Tx buffer size. */ +#define MLXBF_TMFIFO_CONS_TX_BUF_SIZE (32 * 1024) + +/* House-keeping timer interval. */ +static int mlxbf_tmfifo_timer_interval =HZ /10 ; + +/* Global lock. */ +static DEFINE_MUTEX (mlxbf_tmfifo_lock); + +/* Virtual devices sharing the TM FIFO. */ +#define MLXBF_TMFIFO_VDEV_MAX (VIRTIO_ID_CONSOLE + 1) + +/* Struct declaration. */ +struct mlxbf_tmfifo ; + +/* Structure to maintain the ring state. */ struct mlxbf_tmfifo_vring { +void *va;/* virtual address */ +dma_addr_t dma;/* dma address */ +struct virtqueue *vq;/* virtqueue pointer */ +struct vring_desc *desc;/* current desc */ +struct vring_desc *desc_head;/* current desc head */ +int cur_len;/* processed len in current desc */ +int rem_len;/* remaining length to be processed */ +int size;/* vring size */ +int align;/* vring alignment */ +int id;/* vring id */ +int vdev_id;/* TMFIFO_VDEV_xxx */ +u32 pkt_len;/* packet total length */ +__virtio16 next_avail;/* next avail desc id */ +struct mlxbf_tmfifo *fifo;/* pointer back to the tmfifo */ +}; + +/* Interrupt types. */ +enum { +MLXBF_TM_RX_LWM_IRQ ,/* Rx low water mark irq */ +MLXBF_TM_RX_HWM_IRQ ,/* Rx high water mark irq */ +MLXBF_TM_TX_LWM_IRQ ,/* Tx low water mark irq */ +MLXBF_TM_TX_HWM_IRQ ,/* Tx high water mark irq */ +MLXBF_TM_IRQ_CNT +}; + +/* Ring types (Rx & Tx). */ +enum { +MLXBF_TMFIFO_VRING_RX ,/* Rx ring */ +MLXBF_TMFIFO_VRING_TX ,/* Tx ring */ +MLXBF_TMFIFO_VRING_NUM +}; + +struct mlxbf_tmfifo_vdev { +struct virtio_device vdev;/* virtual device */ +u8 status; +u64 features; +union {/* virtio config space */ +struct virtio_console_config cons; +struct virtio_net_config net; + } config; +struct mlxbf_tmfifo_vring vrings[MLXBF_TMFIFO_VRING_NUM ]; +u8 *tx_buf;/* tx buffer */ +u32 tx_head;/* tx buffer head */ +u32 tx_tail;/* tx buffer tail */ +}; + +struct mlxbf_tmfifo_irq_info { +struct mlxbf_tmfifo *fifo;/* tmfifo structure */ +int irq;/* interrupt number */ +int index;/* array index */ +}; + +/* TMFIFO device structure */ +struct mlxbf_tmfifo { +struct mlxbf_tmfifo_vdev *vdev[MLXBF_TMFIFO_VDEV_MAX ];/* devices */
drivers/platform/mellanox/mlxbf-tmfifo.c new file +8
-0+struct platform_device *pdev;/* platform device */ +struct mutex lock;/* fifo lock */ +void __iomem *rx_base;/* mapped register base */ +void __iomem *tx_base;/* mapped register base */ +int tx_fifo_size;/* number of entries of the Tx FIFO */ +int rx_fifo_size;/* number of entries of the Rx FIFO */ +unsigned long pend_events;/* pending bits for deferred process */ +struct mlxbf_tmfifo_irq_info irq_info[MLXBF_TM_IRQ_CNT ];/* irq info */
drivers/platform/mellanox/mlxbf-tmfifo.c new file +32
-0+struct work_struct work;/* work struct for deferred process */ +struct timer_list timer;/* keepalive timer */ +struct mlxbf_tmfifo_vring *vring[2 ];/* current Tx/Rx ring */ +bool is_ready;/* ready flag */ +spinlock_t spin_lock;/* spin lock */ +}; + +union mlxbf_tmfifo_msg_hdr { +struct { +u8 type;/* message type */ +__be16 len;/* payload length */ +u8 unused[5 ];/* reserved, set to 0 */ + } __packed; +u64 data; +}; + +/* +* Default MAC. +* This MAC address will be read from EFI persistent variable if configured. +* It can also be reconfigured with standard Linux tools. +*/ +static u8 mlxbf_tmfifo_net_default_mac[6 ] = { +0x00 ,0x1A ,0xCA ,0xFF ,0xFF ,0x01 }; + +/* MTU setting of the virtio-net interface. */ +#define MLXBF_TMFIFO_NET_MTU 1500 + +/* Maximum L2 header length. */ +#define MLXBF_TMFIFO_NET_L2_OVERHEAD 36 + +/* Supported virtio-net features. */ +#define MLXBF_TMFIFO_NET_FEATURES ((1UL << VIRTIO_NET_F_MTU)| \
drivers/platform/mellanox/mlxbf-tmfifo.c
Quoted 9 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +9
-0+ (1UL << VIRTIO_NET_F_STATUS) | \ + (1UL << VIRTIO_NET_F_MAC)) + +/* Return the consumed Tx buffer space. */ static int +mlxbf_tmfifo_vdev_tx_buf_len (struct mlxbf_tmfifo_vdev *vdev) { +return ((vdev->tx_tail >= vdev->tx_head) ? + (vdev->tx_tail - vdev->tx_head) : + (MLXBF_TMFIFO_CONS_TX_BUF_SIZE - vdev->tx_head + +vdev->tx_tail)); }
I would suggest to split the above.
drivers/platform/mellanox/mlxbf-tmfifo.c line 166
Quoted 4 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +4
-0+ +/* Return the available Tx buffer space. */ static int +mlxbf_tmfifo_vdev_tx_buf_avail (struct mlxbf_tmfifo_vdev *vdev) { + return (MLXBF_TMFIFO_CONS_TX_BUF_SIZE - 8 -
Thins about some extra define for
"MLXBF_TMFIFO_CONS_TX_BUF_SIZE - 8"
Quoted 96 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +39
-0+ mlxbf_tmfifo_vdev_tx_buf_len(vdev)); +} + +/* Update Tx buffer pointer after pushing data. */ static void +mlxbf_tmfifo_vdev_tx_buf_push (struct mlxbf_tmfifo_vdev *vdev, +u32 len) +{ + vdev->tx_tail += len; +if (vdev->tx_tail >=MLXBF_TMFIFO_CONS_TX_BUF_SIZE ) + vdev->tx_tail -=MLXBF_TMFIFO_CONS_TX_BUF_SIZE ; } + +/* Update Tx buffer pointer after popping data. */ static void +mlxbf_tmfifo_vdev_tx_buf_pop (struct mlxbf_tmfifo_vdev *vdev, +u32 len) +{ + vdev->tx_head += len; +if (vdev->tx_head >=MLXBF_TMFIFO_CONS_TX_BUF_SIZE ) + vdev->tx_head -=MLXBF_TMFIFO_CONS_TX_BUF_SIZE ; } + +/* Allocate vrings for the fifo. */ +static int mlxbf_tmfifo_alloc_vrings (struct mlxbf_tmfifo *fifo, +struct mlxbf_tmfifo_vdev *tm_vdev, +int vdev_id) +{ +struct mlxbf_tmfifo_vring *vring; +dma_addr_t dma; +int i, size; +void *va; + +for (i =0 ; i <ARRAY_SIZE (tm_vdev->vrings); i++) { + vring = &tm_vdev->vrings[i]; + vring->fifo = fifo; + vring->size =MLXBF_TMFIFO_VRING_SIZE ; + vring->align =SMP_CACHE_BYTES ; + vring->id = i; + vring->vdev_id = vdev_id; + + size =PAGE_ALIGN (vring_size (vring->size, vring->align)); + va = dma_alloc_coherent(tm_vdev->vdev.dev.parent, size,&dma,
drivers/platform/mellanox/mlxbf-tmfifo.c new file +56
-0+ GFP_KERNEL); +if (!va) { +dev_err (tm_vdev->vdev.dev.parent, +"vring allocation failed\n" ); +return -EINVAL ; + } + + vring->va = va; + vring->dma = dma; + } + +return 0 ; +} + +/* Free vrings of the fifo device. */ +static void mlxbf_tmfifo_free_vrings (struct mlxbf_tmfifo *fifo,int +vdev_id) { +struct mlxbf_tmfifo_vdev *tm_vdev = fifo->vdev[vdev_id]; +struct mlxbf_tmfifo_vring *vring; +int i, size; + +for (i =0 ; i <ARRAY_SIZE (tm_vdev->vrings); i++) { + vring = &tm_vdev->vrings[i]; + + size =PAGE_ALIGN (vring_size (vring->size, vring->align)); +if (vring->va) { +dma_free_coherent (tm_vdev->vdev.dev.parent, size, + vring->va, vring->dma); + vring->va =NULL ; +if (vring->vq) { +vring_del_virtqueue (vring->vq); + vring->vq =NULL ; + } + } + } +} + +/* Free interrupts of the fifo device. */ static void +mlxbf_tmfifo_free_irqs (struct mlxbf_tmfifo *fifo) { +int i, irq; + +for (i =0 ; i <MLXBF_TM_IRQ_CNT ; i++) { + irq = fifo->irq_info[i].irq; +if (irq) { + fifo->irq_info[i].irq =0 ; +disable_irq (irq); +free_irq (irq, (u8 *)fifo + i); + } + } +} + +/* Interrupt handler. */ +static irqreturn_t mlxbf_tmfifo_irq_handler (int irq,void *arg) { +struct mlxbf_tmfifo_irq_info *irq_info; + + irq_info = (struct mlxbf_tmfifo_irq_info *)arg;
drivers/platform/mellanox/mlxbf-tmfifo.c
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +10
-0+ +if (irq_info->index <MLXBF_TM_IRQ_CNT && + !test_and_set_bit (irq_info->index, &irq_info->fifo->pend_events)) +schedule_work (&irq_info->fifo->work); + +return IRQ_HANDLED ; +} + +/* Nothing to do for now. */ +static void mlxbf_tmfifo_virtio_dev_release (struct device *dev) { }
If there is nothing to do - no reason to have it.
Quoted 113 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +50
-0+ +/* Get the next packet descriptor from the vring. */ static inline +struct vring_desc *mlxbf_tmfifo_virtio_get_next_desc (struct virtqueue +*vq) { +struct mlxbf_tmfifo_vring *vring; +unsigned int idx, head; +struct vring *vr; + + vring = (struct mlxbf_tmfifo_vring *)vq->priv; + vr = (struct vring *)virtqueue_get_vring (vq); + +if (!vr || vring->next_avail == vr->avail->idx) +return NULL ; + + idx = vring->next_avail % vr->num; + head = vr->avail->ring[idx]; +BUG_ON (head >= vr->num); + vring->next_avail++; +return &vr->desc[head]; +} + +static inline void mlxbf_tmfifo_virtio_release_desc ( +struct virtio_device *vdev,struct vring *vr, +struct vring_desc *desc,u32 len) +{ +unsigned int idx; + + idx = vr->used->idx % vr->num; + vr->used->ring[idx].id = desc - vr->desc; + vr->used->ring[idx].len =cpu_to_virtio32 (vdev, len); + +/* Virtio could poll and check the 'idx' to decide +* whether the desc is done or not. Add a memory +* barrier here to make sure the update above completes +* before updating the idx. +*/ +mb (); + vr->used->idx++; +} + +/* Get the total length of a descriptor chain. */ static inline u32 +mlxbf_tmfifo_virtio_get_pkt_len (struct virtio_device *vdev, +struct vring_desc *desc, +struct vring *vr) +{ +u32 len =0 , idx; + +while (desc) { + len +=virtio32_to_cpu (vdev, desc->len); + if (!(virtio16_to_cpu(vdev, desc->flags) &
VRING_DESC_F_NEXT))drivers/platform/mellanox/mlxbf-tmfifo.c new file +32
-0+break ; + idx =virtio16_to_cpu (vdev, desc->next); + desc = &vr->desc[idx]; + } + +return len; +} + +static void mlxbf_tmfifo_release_pkt (struct virtio_device *vdev, +struct mlxbf_tmfifo_vring *vring, +struct vring_desc **desc) +{ +struct vring *vr = (struct vring *)virtqueue_get_vring (vring->vq); +struct vring_desc *desc_head; +uint32_t pkt_len =0 ; + +if (!vr) +return ; + +if (desc !=NULL && *desc !=NULL && vring->desc_head !=NULL ) { + desc_head = vring->desc_head; + pkt_len = vring->pkt_len; + }else { + desc_head =mlxbf_tmfifo_virtio_get_next_desc (vring->vq); +if (desc_head !=NULL ) { + pkt_len =mlxbf_tmfifo_virtio_get_pkt_len ( + vdev, desc_head, vr); + } + } + +if (desc_head !=NULL ) + mlxbf_tmfifo_virtio_release_desc(vdev, vr, desc_head,
pkt_len);drivers/platform/mellanox/mlxbf-tmfifo.c new file +29
-0+ +if (desc !=NULL ) + *desc =NULL ; + vring->pkt_len =0 ; +} + +/* House-keeping timer. */ +static void mlxbf_tmfifo_timer (struct timer_list *arg) { +struct mlxbf_tmfifo *fifo; + + fifo = container_of(arg, struct mlxbf_tmfifo, timer); + +/* +* Wake up the work handler to poll the Rx FIFO in case interrupt +* missing or any leftover bytes stuck in the FIFO. +*/ +test_and_set_bit (MLXBF_TM_RX_HWM_IRQ , &fifo->pend_events); + +/* +* Wake up Tx handler in case virtio has queued too many packets +* and are waiting for buffer return. +*/ +test_and_set_bit (MLXBF_TM_TX_LWM_IRQ , &fifo->pend_events); + +schedule_work (&fifo->work); + +mod_timer (&fifo->timer, jiffies + mlxbf_tmfifo_timer_interval); } + +/* Buffer the console output. */
drivers/platform/mellanox/mlxbf-tmfifo.c line 401
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +10
-0+static void mlxbf_tmfifo_console_output (struct mlxbf_tmfifo_vdev *cons, +struct virtqueue *vq) +{ +struct vring *vr = (struct vring *)virtqueue_get_vring (vq); +struct vring_desc *head_desc, *desc =NULL ; +struct virtio_device *vdev = &cons->vdev; +u32 len, pkt_len, idx; +void *addr; + +for (;;) {
It's better to modify it as while(on some condition)
drivers/platform/mellanox/mlxbf-tmfifo.c line 410
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +6
-0+ head_desc =mlxbf_tmfifo_virtio_get_next_desc (vq); +if (head_desc ==NULL ) +break ; + +/* Release the packet if no more space. */ + pkt_len = mlxbf_tmfifo_virtio_get_pkt_len(vdev, head_desc,vr);
drivers/platform/mellanox/mlxbf-tmfifo.c new file +3
-0+if (pkt_len >mlxbf_tmfifo_vdev_tx_buf_avail (cons)) { +mlxbf_tmfifo_virtio_release_desc (vdev, vr, head_desc, + pkt_len);
Why do you break line here?
drivers/platform/mellanox/mlxbf-tmfifo.c line 421
Quoted 11 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +11
-0+break ; + } + + desc = head_desc; + +while (desc !=NULL ) { + addr =phys_to_virt (virtio64_to_cpu (vdev, desc->addr)); + len =virtio32_to_cpu (vdev, desc->len); + +if (len <=MLXBF_TMFIFO_CONS_TX_BUF_SIZE - + cons->tx_tail) {
Why do you break line here? Also below I see few strange breaks.
Quoted 50 lines
+ memcpy(cons->tx_buf +
cons->tx_tail, addr,
len);drivers/platform/mellanox/mlxbf-tmfifo.c new file +6
-0+ }else { +u32 seg; + + seg =MLXBF_TMFIFO_CONS_TX_BUF_SIZE - + cons->tx_tail; + memcpy(cons->tx_buf + cons->tx_tail, addr,seg);
drivers/platform/mellanox/mlxbf-tmfifo.c new file +13
-0+ addr += seg; +memcpy (cons->tx_buf, addr, len - seg); + } +mlxbf_tmfifo_vdev_tx_buf_push (cons, len); + +if (!(virtio16_to_cpu (vdev, desc->flags) & +VRING_DESC_F_NEXT )) +break ; + idx =virtio16_to_cpu (vdev, desc->next); + desc = &vr->desc[idx]; + } + + mlxbf_tmfifo_virtio_release_desc(vdev, vr, head_desc,
pkt_len);drivers/platform/mellanox/mlxbf-tmfifo.c new file +27
-0+ } +} + +/* Rx & Tx processing of a virtual queue. */ static void +mlxbf_tmfifo_virtio_rxtx (struct virtqueue *vq,bool is_rx) { +int num_avail =0 , hdr_len, tx_reserve; +struct mlxbf_tmfifo_vring *vring; +struct mlxbf_tmfifo_vdev *cons; +struct virtio_device *vdev; +struct mlxbf_tmfifo *fifo; +struct vring_desc *desc; +unsigned long flags; +struct vring *vr; +u64 sts, data; +u32 len, idx; +void *addr; + +if (!vq) +return ; + + vring = (struct mlxbf_tmfifo_vring *)vq->priv; + fifo = vring->fifo; + vr = (struct vring *)virtqueue_get_vring (vq); + +if (!fifo->vdev[vring->vdev_id]) +return ; + vdev = &fifo->vdev[vring->vdev_id]->vdev;
drivers/platform/mellanox/mlxbf-tmfifo.c line 479
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +10
-0+ cons = fifo->vdev[VIRTIO_ID_CONSOLE ]; + +/* Don't continue if another vring is running. */ +if (fifo->vring[is_rx] !=NULL && fifo->vring[is_rx] != vring) +return ; + +/* tx_reserve is used to reserved some room in FIFO for console. */ +if (vring->vdev_id ==VIRTIO_ID_NET ) { + hdr_len =sizeof (struct virtio_net_hdr ); + tx_reserve = fifo->tx_fifo_size /16 ;
Use some define instead of 16/
drivers/platform/mellanox/mlxbf-tmfifo.c line 488
Quoted 9 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +9
-0+ }else { +BUG_ON (vring->vdev_id !=VIRTIO_ID_CONSOLE ); + hdr_len =0 ; + tx_reserve =1 ; + } + + desc = vring->desc; + +while (1 ) {
I see there are few drivers in platform which use while (1) But it looks better to use while(some condition) and instead of break change this condition to false.
drivers/platform/mellanox/mlxbf-tmfifo.c
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +4
-0+/* Get available FIFO space. */ +if (num_avail ==0 ) { +if (is_rx) { +/* Get the number of available words in FIFO. */
drivers/platform/mellanox/mlxbf-tmfifo.c new file +4
-0+ sts =readq (fifo->rx_base + +MLXBF_TMFIFO_RX_STS ); + num_avail =FIELD_GET ( +MLXBF_TMFIFO_RX_STS__COUNT_MASK , sts);
num_avail = FIELD_GET(TMFIFO_RX_STS__COUNT_MASK, sts);
drivers/platform/mellanox/mlxbf-tmfifo.c
Quoted 13 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +12
-0+ +/* Don't continue if nothing in FIFO. */ +if (num_avail <=0 ) +break ; + }else { +/* Get available space in FIFO. */ + sts =readq (fifo->tx_base + +MLXBF_TMFIFO_TX_STS ); + num_avail = fifo->tx_fifo_size - tx_reserve - +FIELD_GET ( +MLXBF_TMFIFO_TX_STS__COUNT_MASK , + sts);
Same as above.
Quoted 178 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +132
-0+ +if (num_avail <=0 ) +break ; + } + } + +/* Console output always comes from the Tx buffer. */ +if (!is_rx && vring->vdev_id ==VIRTIO_ID_CONSOLE && + cons !=NULL && cons->tx_buf !=NULL ) { +union mlxbf_tmfifo_msg_hdr hdr; +int size; + + size =mlxbf_tmfifo_vdev_tx_buf_len (cons); +if (num_avail <2 || size ==0 ) +return ; +if (size +sizeof (hdr) > num_avail *sizeof (u64)) + size = num_avail *sizeof (u64) -sizeof (hdr); +/* Write header. */ + hdr.data =0 ; + hdr.type =VIRTIO_ID_CONSOLE ; + hdr.len =htons (size); +writeq (cpu_to_le64 (hdr.data), + fifo->tx_base +MLXBF_TMFIFO_TX_DATA ); + +spin_lock_irqsave (&fifo->spin_lock, flags); +while (size >0 ) { + addr = cons->tx_buf + cons->tx_head; + +if (cons->tx_head +sizeof (u64) <= +MLXBF_TMFIFO_CONS_TX_BUF_SIZE ) { +memcpy (&data, addr,sizeof (u64)); + }else { +int partial; + + partial = +MLXBF_TMFIFO_CONS_TX_BUF_SIZE - + cons->tx_head; + +memcpy (&data, addr, partial); +memcpy ((u8 *)&data + partial, + cons->tx_buf, +sizeof (u64) - partial); + } +writeq (data, + fifo->tx_base +MLXBF_TMFIFO_TX_DATA ); + +if (size >=sizeof (u64)) { +mlxbf_tmfifo_vdev_tx_buf_pop ( + cons,sizeof (u64)); + size -=sizeof (u64); + }else { +mlxbf_tmfifo_vdev_tx_buf_pop ( + cons, size); + size =0 ; + } + } +spin_unlock_irqrestore (&fifo->spin_lock, flags); +return ; + } + +/* Get the desc of next packet. */ +if (!desc) { +/* Save the head desc of the chain. */ + vring->desc_head = +mlxbf_tmfifo_virtio_get_next_desc (vq); +if (!vring->desc_head) { + vring->desc =NULL ; +return ; + } + desc = vring->desc_head; + vring->desc = desc; + +if (is_rx && vring->vdev_id ==VIRTIO_ID_NET ) { +struct virtio_net_hdr *net_hdr; + +/* Initialize the packet header. */ + net_hdr = (struct virtio_net_hdr *) +phys_to_virt (virtio64_to_cpu ( + vdev, desc->addr)); +memset (net_hdr,0 ,sizeof (*net_hdr)); + } + } + +/* Beginning of each packet. */ +if (vring->pkt_len ==0 ) { +int vdev_id, vring_change =0 ; +union mlxbf_tmfifo_msg_hdr hdr; + + num_avail--; + +/* Read/Write packet length. */ +if (is_rx) { + hdr.data =readq (fifo->rx_base + +MLXBF_TMFIFO_RX_DATA ); + hdr.data =le64_to_cpu (hdr.data); + +/* Skip the length 0 packet (keepalive). */ +if (hdr.len ==0 ) +continue ; + +/* Check packet type. */ +if (hdr.type ==VIRTIO_ID_NET ) { +struct virtio_net_config *config; + + vdev_id =VIRTIO_ID_NET ; + hdr_len =sizeof (struct virtio_net_hdr ); + config = + &fifo->vdev[vdev_id]->config.net; +if (ntohs (hdr.len) > config->mtu + +MLXBF_TMFIFO_NET_L2_OVERHEAD ) +continue ; + }else if (hdr.type ==VIRTIO_ID_CONSOLE ) { + vdev_id =VIRTIO_ID_CONSOLE ; + hdr_len =0 ; + }else { +continue ; + } + +/* +* Check whether the new packet still belongs +* to this vring or not. If not, update the +* pkt_len of the new vring and return. +*/ +if (vdev_id != vring->vdev_id) { +struct mlxbf_tmfifo_vdev *dev2 = + fifo->vdev[vdev_id]; + +if (!dev2) +break ; + vring->desc = desc; + vring = + &dev2-Quoted 1 line
vrings[MLXBF_TMFIFO_VRING_RX];
drivers/platform/mellanox/mlxbf-tmfifo.c new file +40
-0+ vring_change =1 ; + } + vring->pkt_len =ntohs (hdr.len) + hdr_len; + }else { + vring->pkt_len = +mlxbf_tmfifo_virtio_get_pkt_len ( + vdev, desc, vr); + + hdr.data =0 ; + hdr.type = (vring->vdev_id ==VIRTIO_ID_NET ) ? +VIRTIO_ID_NET : +VIRTIO_ID_CONSOLE ; + hdr.len =htons (vring->pkt_len - hdr_len); +writeq (cpu_to_le64 (hdr.data), + fifo->tx_base +MLXBF_TMFIFO_TX_DATA ); + } + + vring->cur_len = hdr_len; + vring->rem_len = vring->pkt_len; + fifo->vring[is_rx] = vring; + +if (vring_change) +return ; +continue ; + } + +/* Check available space in this desc. */ + len =virtio32_to_cpu (vdev, desc->len); +if (len > vring->rem_len) + len = vring->rem_len; + +/* Check if the current desc is already done. */ +if (vring->cur_len == len) + goto check_done; + + addr =phys_to_virt (virtio64_to_cpu (vdev, desc->addr)); + +/* Read a word from FIFO for Rx. */ +if (is_rx) { + data = readq(fifo->rx_base +
MLXBF_TMFIFO_RX_DATA);drivers/platform/mellanox/mlxbf-tmfifo.c new file +2
-0+ data =le64_to_cpu (data); + }
drivers/platform/mellanox/mlxbf-tmfifo.c line 692
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +10
-0+ +if (vring->cur_len +sizeof (u64) <= len) { +/* The whole word. */ +if (is_rx) { +memcpy (addr + vring->cur_len, &data, +sizeof (u64)); + }else { +memcpy (&data, addr + vring->cur_len, +sizeof (u64)); + }
Why not just.
Also few places like this one below.
if (is_rx)
memcpy(addr + vring->cur_len, &data, sizeof(u64));
else
memcpy(&data, addr + vring->cur_len, sizeof(u64));Quoted 42 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +42
-0+ vring->cur_len +=sizeof (u64); + }else { +/* Leftover bytes. */ +BUG_ON (vring->cur_len > len); +if (is_rx) { +memcpy (addr + vring->cur_len, &data, + len - vring->cur_len); + }else { +memcpy (&data, addr + vring->cur_len, + len - vring->cur_len); + } + vring->cur_len = len; + } + +/* Write the word into FIFO for Tx. */ +if (!is_rx) { +writeq (cpu_to_le64 (data), + fifo->tx_base +MLXBF_TMFIFO_TX_DATA ); + } + + num_avail--; + +check_done: +/* Check whether this desc is full or completed. */ +if (vring->cur_len == len) { + vring->cur_len =0 ; + vring->rem_len -= len; + +/* Get the next desc on the chain. */ +if (vring->rem_len >0 && + (virtio16_to_cpu (vdev, desc->flags) & +VRING_DESC_F_NEXT )) { + idx =virtio16_to_cpu (vdev, desc->next); + desc = &vr->desc[idx]; +continue ; + } + +/* Done and release the desc. */ +mlxbf_tmfifo_release_pkt (vdev, vring, &desc); + fifo->vring[is_rx] =NULL ; + +/* Notify upper layer that packet is done. */
drivers/platform/mellanox/mlxbf-tmfifo.c line 744
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +10
-0+spin_lock_irqsave (&fifo->spin_lock, flags); +vring_interrupt (0 , vq); +spin_unlock_irqrestore (&fifo->spin_lock, flags); +continue ; + } + } + +/* Save the current desc. */ + vring->desc = desc; +}
I suggest to split mlxbf_tmfifo_virtio_rxtx() into few small routines.
Quoted 20 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +17
-0+ +/* The notify function is called when new buffers are posted. */ static +bool mlxbf_tmfifo_virtio_notify(struct virtqueue *vq) { + struct mlxbf_tmfifo_vring *vring; + struct mlxbf_tmfifo *fifo; + unsigned long flags; + + vring = (struct mlxbf_tmfifo_vring *)vq->priv; + fifo = vring->fifo; + + /* + * Virtio maintains vrings in pairs, even number ring for Rx + * and odd number ring for Tx. + */ + if (!(vring->id & 1)) { + /* Set the RX HWM bit to start Rx. */ + if (!test_and_set_bit(MLXBF_TM_RX_HWM_IRQ, &fifo-Quoted 1 line
pend_events))drivers/platform/mellanox/mlxbf-tmfifo.c new file +2
-0+schedule_work (&fifo->work); + }else {
drivers/platform/mellanox/mlxbf-tmfifo.c line 774
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +10
-0+/* +* Console could make blocking call with interrupts disabled. +* In such case, the vring needs to be served right away. For +* other cases, just set the TX LWM bit to start Tx in the +* worker handler. +*/ +if (vring->vdev_id ==VIRTIO_ID_CONSOLE ) { +spin_lock_irqsave (&fifo->spin_lock, flags); +mlxbf_tmfifo_console_output ( + fifo->vdev[VIRTIO_ID_CONSOLE ], vq);
mlxbf_tmfifo_console_output(fifo->vdev[VIRTIO_ID_CONSOLE], vq);
drivers/platform/mellanox/mlxbf-tmfifo.c line 779
Quoted 5 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +5
-0+spin_unlock_irqrestore (&fifo->spin_lock, flags); +schedule_work (&fifo->work); + }else if (!test_and_set_bit (MLXBF_TM_TX_LWM_IRQ , + &fifo->pend_events)) +schedule_work (&fifo->work);
If {
} else if {
}For consistency.
Quoted 20 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +19
-0+ } + +return true; +} + +/* Work handler for Rx and Tx case. */ +static void mlxbf_tmfifo_work_handler (struct work_struct *work) { +struct mlxbf_tmfifo_vdev *tm_vdev; +struct mlxbf_tmfifo *fifo; +int i; + + fifo = container_of(work, struct mlxbf_tmfifo, work); +if (!fifo->is_ready) +return ; + +mutex_lock (&fifo->lock); + +/* Tx (Send data to the TmFifo). */ + if (test_and_clear_bit(MLXBF_TM_TX_LWM_IRQ, &fifo->pend_events)&&
drivers/platform/mellanox/mlxbf-tmfifo.c
Quoted 2 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +2
-0+ fifo->irq_info[MLXBF_TM_TX_LWM_IRQ].irq) { +for (i =0 ; i <MLXBF_TMFIFO_VDEV_MAX ; i++) {
I suggest to define local variable vq.
And have below:
mlxbf_tmfifo_virtio_rxtx(vq, false);
Quoted 13 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +4
-0+ tm_vdev = fifo->vdev[i]; +if (tm_vdev !=NULL ) { + mlxbf_tmfifo_virtio_rxtx( + tm_vdev-Quoted 1 line
vrings[MLXBF_TMFIFO_VRING_TX].vq,
drivers/platform/mellanox/mlxbf-tmfifo.c new file +7
-0+ false); + } + } + } + +/* Rx (Receive data from the TmFifo). */ + if (test_and_clear_bit(MLXBF_TM_RX_HWM_IRQ, &fifo->pend_events)&&
drivers/platform/mellanox/mlxbf-tmfifo.c line 815
Quoted 3 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +3
-0+ fifo->irq_info[MLXBF_TM_RX_HWM_IRQ].irq) { +for (i =0 ; i <MLXBF_TMFIFO_VDEV_MAX ; i++) { + tm_vdev = fifo->vdev[i];
Same as above.
Quoted 59 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +3
-0+if (tm_vdev !=NULL ) { + mlxbf_tmfifo_virtio_rxtx( + tm_vdev-Quoted 1 line
vrings[MLXBF_TMFIFO_VRING_RX].vq,
drivers/platform/mellanox/mlxbf-tmfifo.c new file +55
-0+ true); + } + } + } + +mutex_unlock (&fifo->lock); +} + +/* Get the array of feature bits for this device. */ static u64 +mlxbf_tmfifo_virtio_get_features (struct virtio_device *vdev) { +struct mlxbf_tmfifo_vdev *tm_vdev; + + tm_vdev = container_of(vdev, struct mlxbf_tmfifo_vdev, vdev); +return tm_vdev->features; +} + +/* Confirm device features to use. */ +static int mlxbf_tmfifo_virtio_finalize_features (struct virtio_device +*vdev) { +struct mlxbf_tmfifo_vdev *tm_vdev; + + tm_vdev = container_of(vdev, struct mlxbf_tmfifo_vdev, vdev); + tm_vdev->features = vdev->features; + +return 0 ; +} + +/* Free virtqueues found by find_vqs(). */ static void +mlxbf_tmfifo_virtio_del_vqs (struct virtio_device *vdev) { +struct mlxbf_tmfifo_vdev *tm_vdev; +struct mlxbf_tmfifo_vring *vring; +struct virtqueue *vq; +int i; + + tm_vdev = container_of(vdev, struct mlxbf_tmfifo_vdev, vdev); + +for (i =0 ; i <ARRAY_SIZE (tm_vdev->vrings); i++) { + vring = &tm_vdev->vrings[i]; + +/* Release the pending packet. */ +if (vring->desc !=NULL ) { +mlxbf_tmfifo_release_pkt (&tm_vdev->vdev, vring, + &vring->desc); + } + + vq = vring->vq; +if (vq) { + vring->vq =NULL ; +vring_del_virtqueue (vq); + } + } +} + +/* Create and initialize the virtual queues. */ static int +mlxbf_tmfifo_virtio_find_vqs(struct virtio_device *vdev,
drivers/platform/mellanox/mlxbf-tmfifo.c line 885
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +10
-0+unsigned int nvqs, + struct virtqueue *vqs[], + vq_callback_t *callbacks[], + const char * const names[], + const bool *ctx, + struct irq_affinity *desc) +{ + struct mlxbf_tmfifo_vdev *tm_vdev; +struct mlxbf_tmfifo_vring *vring; +int i, ret = -EINVAL , size;
Don't initialize ret with -EINVAL.
Quoted 63 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +63
-0+struct virtqueue *vq; + + tm_vdev = container_of(vdev, struct mlxbf_tmfifo_vdev, vdev); +if (nvqs >ARRAY_SIZE (tm_vdev->vrings)) +return -EINVAL ; + +for (i =0 ; i < nvqs; ++i) { +if (!names[i]) + goto error; + vring = &tm_vdev->vrings[i]; + +/* zero vring */ + size =vring_size (vring->size, vring->align); +memset (vring->va,0 , size); + vq =vring_new_virtqueue (i, vring->size, vring->align, vdev, + false, false, vring->va, + mlxbf_tmfifo_virtio_notify, + callbacks[i], names[i]); +if (!vq) { +dev_err (&vdev->dev,"vring_new_virtqueue failed\n" ); + ret = -ENOMEM ; + goto error; + } + + vqs[i] = vq; + vring->vq = vq; + vq->priv = vring; + } + +return 0 ; + +error: +mlxbf_tmfifo_virtio_del_vqs (vdev); +return ret; +} + +/* Read the status byte. */ +static u8 mlxbf_tmfifo_virtio_get_status (struct virtio_device *vdev) { +struct mlxbf_tmfifo_vdev *tm_vdev; + + tm_vdev = container_of(vdev, struct mlxbf_tmfifo_vdev, vdev); + +return tm_vdev->status; +} + +/* Write the status byte. */ +static void mlxbf_tmfifo_virtio_set_status (struct virtio_device *vdev, +u8 status) +{ +struct mlxbf_tmfifo_vdev *tm_vdev; + + tm_vdev = container_of(vdev, struct mlxbf_tmfifo_vdev, vdev); + tm_vdev->status = status; +} + +/* Reset the device. Not much here for now. */ static void +mlxbf_tmfifo_virtio_reset (struct virtio_device *vdev) { +struct mlxbf_tmfifo_vdev *tm_vdev; + + tm_vdev = container_of(vdev, struct mlxbf_tmfifo_vdev, vdev); + tm_vdev->status =0 ; +} +
drivers/platform/mellanox/mlxbf-tmfifo.c line 960
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +10
-0+/* Read the value of a configuration field. */ static void +mlxbf_tmfifo_virtio_get (struct virtio_device *vdev, +unsigned int offset, +void *buf, +unsigned int len) +{ +struct mlxbf_tmfifo_vdev *tm_vdev; + + tm_vdev = container_of(vdev, struct mlxbf_tmfifo_vdev, vdev); +
unsigned int pos = offset + len;
if (pos > sizeof(tm_vdev->config) || pos < len)Quoted 8 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +8
-0+if (offset + len >sizeof (tm_vdev->config) || offset + len < len) { +dev_err (vdev->dev.parent,"virtio_get access out of bounds\n" ); +return ; + } + +memcpy (buf, (u8 *)&tm_vdev->config + offset, len); } + +/* Write the value of a configuration field. */ static void
drivers/platform/mellanox/mlxbf-tmfifo.c line 979
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +10
-0+mlxbf_tmfifo_virtio_set(struct virtio_device *vdev, + unsigned int offset, + const void *buf, + unsigned int len) +{ + struct mlxbf_tmfifo_vdev *tm_vdev; + + tm_vdev = container_of(vdev, struct mlxbf_tmfifo_vdev, vdev); + +if (offset + len >sizeof (tm_vdev->config) || offset + len < len) {
Same as above.
Quoted 92 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +54
-0+dev_err (vdev->dev.parent,"virtio_get access out of bounds\n" ); +return ; + } + +memcpy ((u8 *)&tm_vdev->config + offset, buf, len); } + +/* Virtio config operations. */ +static const struct virtio_config_ops mlxbf_tmfifo_virtio_config_ops = { + .get_features = mlxbf_tmfifo_virtio_get_features, + .finalize_features = mlxbf_tmfifo_virtio_finalize_features, + .find_vqs = mlxbf_tmfifo_virtio_find_vqs, + .del_vqs = mlxbf_tmfifo_virtio_del_vqs, + .reset = mlxbf_tmfifo_virtio_reset, + .set_status = mlxbf_tmfifo_virtio_set_status, + .get_status = mlxbf_tmfifo_virtio_get_status, + .get = mlxbf_tmfifo_virtio_get, + .set = mlxbf_tmfifo_virtio_set, +}; + +/* Create vdev type in a tmfifo. */ +int mlxbf_tmfifo_create_vdev (struct mlxbf_tmfifo *fifo,int vdev_id, +u64 features,void *config,u32 size) { +struct mlxbf_tmfifo_vdev *tm_vdev; +int ret =0 ; + +mutex_lock (&fifo->lock); + + tm_vdev = fifo->vdev[vdev_id]; +if (tm_vdev !=NULL ) { +pr_err ("vdev %d already exists\n" , vdev_id); + ret = -EEXIST ; + goto already_exist; + } + + tm_vdev =kzalloc (sizeof (*tm_vdev),GFP_KERNEL ); +if (!tm_vdev) { + ret = -ENOMEM ; + goto already_exist; + } + + tm_vdev->vdev.id.device = vdev_id; + tm_vdev->vdev.config = &mlxbf_tmfifo_virtio_config_ops; + tm_vdev->vdev.dev.parent = &fifo->pdev->dev; + tm_vdev->vdev.dev.release = mlxbf_tmfifo_virtio_dev_release; + tm_vdev->features = features; +if (config) +memcpy (&tm_vdev->config, config, size); +if (mlxbf_tmfifo_alloc_vrings (fifo, tm_vdev, vdev_id)) { +pr_err ("Unable to allocate vring\n" ); + ret = -ENOMEM ; + goto alloc_vring_fail; + } +if (vdev_id ==VIRTIO_ID_CONSOLE ) { + tm_vdev->tx_buf =kmalloc(MLXBF_TMFIFO_CONS_TX_BUF_SIZE,
drivers/platform/mellanox/mlxbf-tmfifo.c new file +37
-0+ GFP_KERNEL); + } + fifo->vdev[vdev_id] = tm_vdev; + +/* Register the virtio device. */ + ret =register_virtio_device (&tm_vdev->vdev); +if (ret) { +dev_err (&fifo->pdev->dev,"register_virtio_device() failed\n" ); + goto register_fail; + } + +mutex_unlock (&fifo->lock); +return 0 ; + +register_fail: +mlxbf_tmfifo_free_vrings (fifo, vdev_id); + fifo->vdev[vdev_id] =NULL ; +alloc_vring_fail: +kfree (tm_vdev); +already_exist: +mutex_unlock (&fifo->lock); +return ret; +} + +/* Delete vdev type from a tmfifo. */ +int mlxbf_tmfifo_delete_vdev (struct mlxbf_tmfifo *fifo,int vdev_id) { +struct mlxbf_tmfifo_vdev *tm_vdev; + +mutex_lock (&fifo->lock); + +/* Unregister vdev. */ + tm_vdev = fifo->vdev[vdev_id]; +if (tm_vdev) { +unregister_virtio_device (&tm_vdev->vdev); +mlxbf_tmfifo_free_vrings (fifo, vdev_id); +kfree (tm_vdev->tx_buf); +kfree (tm_vdev);
drivers/platform/mellanox/mlxbf-tmfifo.c
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +10
-0+ fifo->vdev[vdev_id] =NULL ; + } + +mutex_unlock (&fifo->lock); + +return 0 ; +} + +/* Device remove function. */ +static int mlxbf_tmfifo_remove (struct platform_device *pdev) {
Locate it after probe.
If you'll use all devm_, like Andy noted:devm_ioremapdevm_ioremap_resourcedevm_kzallocdevm_request_mem_region
you can drop all kfree, release_mem_region, iounmap
And make the below as a separate routine, something like mlxbf_tmfifo_cleanup(), if you still need it.
Quoted 37 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +37
-0+struct mlxbf_tmfifo *fifo =platform_get_drvdata (pdev); +struct resource *rx_res, *tx_res; +int i; + +if (fifo) { +mutex_lock (&mlxbf_tmfifo_lock); + + fifo->is_ready = false; + +/* Stop the timer. */ +del_timer_sync (&fifo->timer); + +/* Release interrupts. */ +mlxbf_tmfifo_free_irqs (fifo); + +/* Cancel the pending work. */ +cancel_work_sync (&fifo->work); + +for (i =0 ; i <MLXBF_TMFIFO_VDEV_MAX ; i++) +mlxbf_tmfifo_delete_vdev (fifo, i); + +/* Release IO resources. */ +if (fifo->rx_base) +iounmap (fifo->rx_base); +if (fifo->tx_base) +iounmap (fifo->tx_base); + +platform_set_drvdata (pdev,NULL ); +kfree (fifo); + +mutex_unlock (&mlxbf_tmfifo_lock); + } + + rx_res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +if (rx_res) +release_mem_region (rx_res->start,resource_size (rx_res)); + tx_res =platform_get_resource (pdev,IORESOURCE_MEM ,1 );
drivers/platform/mellanox/mlxbf-tmfifo.c line 1132
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +10
-0+if (tx_res) +release_mem_region (tx_res->start,resource_size (tx_res)); + +return 0 ; +} + +/* Read the configured network MAC address from efi variable. */ static +void mlxbf_tmfifo_get_cfg_mac (u8 *mac) { +efi_char16_t name[] = { +'R' ,'s' ,'h' ,'i' ,'m' ,'M' ,'a' ,'c' ,'A' ,'d' ,'d' ,'r' ,0 };
Could it be moved out and set like:
static const efi_char16_t mlxbf_tmfifo_efi_name[] = "..."; Could you check if the are some examples in kernel, please?
Quoted 160 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +80
-0+efi_guid_t guid =EFI_GLOBAL_VARIABLE_GUID ; +efi_status_t status; +unsigned long size; +u8 buf[6 ]; + + size =sizeof (buf); + status = efi.get_variable (name, &guid,NULL , &size, buf); +if (status ==EFI_SUCCESS && size ==sizeof (buf)) +memcpy (mac, buf,sizeof (buf)); +} + +/* Probe the TMFIFO. */ +static int mlxbf_tmfifo_probe (struct platform_device *pdev) { +struct virtio_net_config net_config; +struct resource *rx_res, *tx_res; +struct mlxbf_tmfifo *fifo; +int i, ret; +u64 ctl; + +/* Get the resource of the Rx & Tx FIFO. */ + rx_res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + tx_res =platform_get_resource (pdev,IORESOURCE_MEM ,1 ); +if (!rx_res || !tx_res) { + ret = -EINVAL ; + goto err; + } + +if (request_mem_region (rx_res->start, +resource_size (rx_res),"bf-tmfifo" ) ==NULL ) { + ret = -EBUSY ; + goto early_err; + } + +if (request_mem_region (tx_res->start, +resource_size (tx_res),"bf-tmfifo" ) ==NULL ) { +release_mem_region (rx_res->start,resource_size (rx_res)); + ret = -EBUSY ; + goto early_err; + } + + ret = -ENOMEM ; + fifo =kzalloc (sizeof (struct mlxbf_tmfifo ),GFP_KERNEL ); +if (!fifo) + goto err; + + fifo->pdev = pdev; +platform_set_drvdata (pdev, fifo); + +spin_lock_init (&fifo->spin_lock); +INIT_WORK (&fifo->work, mlxbf_tmfifo_work_handler); + +timer_setup (&fifo->timer, mlxbf_tmfifo_timer,0 ); + fifo->timer.function = mlxbf_tmfifo_timer; + +for (i =0 ; i <MLXBF_TM_IRQ_CNT ; i++) { + fifo->irq_info[i].index = i; + fifo->irq_info[i].fifo = fifo; + fifo->irq_info[i].irq =platform_get_irq (pdev, i); + ret =request_irq (fifo->irq_info[i].irq, + mlxbf_tmfifo_irq_handler,0 , +"tmfifo" , &fifo->irq_info[i]); +if (ret) { +pr_err ("Unable to request irq\n" ); + fifo->irq_info[i].irq =0 ; + goto err; + } + } + + fifo->rx_base =ioremap (rx_res->start,resource_size (rx_res)); +if (!fifo->rx_base) + goto err; + + fifo->tx_base =ioremap (tx_res->start,resource_size (tx_res)); +if (!fifo->tx_base) + goto err; + +/* Get Tx FIFO size and set the low/high watermark. */ + ctl =readq (fifo->tx_base +MLXBF_TMFIFO_TX_CTL ); + fifo->tx_fifo_size = + FIELD_GET(MLXBF_TMFIFO_TX_CTL__MAX_ENTRIES_MASK,ctl);
drivers/platform/mellanox/mlxbf-tmfifo.c new file +12
-0+ ctl = (ctl & ~MLXBF_TMFIFO_TX_CTL__LWM_MASK ) | +FIELD_PREP (MLXBF_TMFIFO_TX_CTL__LWM_MASK , + fifo->tx_fifo_size /2 ); + ctl = (ctl & ~MLXBF_TMFIFO_TX_CTL__HWM_MASK ) | +FIELD_PREP (MLXBF_TMFIFO_TX_CTL__HWM_MASK , + fifo->tx_fifo_size -1 ); +writeq (ctl, fifo->tx_base +MLXBF_TMFIFO_TX_CTL ); + +/* Get Rx FIFO size and set the low/high watermark. */ + ctl =readq (fifo->rx_base +MLXBF_TMFIFO_RX_CTL ); + fifo->rx_fifo_size = + FIELD_GET(MLXBF_TMFIFO_RX_CTL__MAX_ENTRIES_MASK,ctl);
drivers/platform/mellanox/mlxbf-tmfifo.c new file +21
-0+ ctl = (ctl & ~MLXBF_TMFIFO_RX_CTL__LWM_MASK ) | +FIELD_PREP (MLXBF_TMFIFO_RX_CTL__LWM_MASK ,0 ); + ctl = (ctl & ~MLXBF_TMFIFO_RX_CTL__HWM_MASK ) | +FIELD_PREP (MLXBF_TMFIFO_RX_CTL__HWM_MASK ,1 ); +writeq (ctl, fifo->rx_base +MLXBF_TMFIFO_RX_CTL ); + +mutex_init (&fifo->lock); + +/* Create the console vdev. */ + ret =mlxbf_tmfifo_create_vdev (fifo,VIRTIO_ID_CONSOLE ,0 ,NULL ,0 ); +if (ret) + goto err; + +/* Create the network vdev. */ +memset (&net_config,0 ,sizeof (net_config)); + net_config.mtu =MLXBF_TMFIFO_NET_MTU ; + net_config.status =VIRTIO_NET_S_LINK_UP ; +memcpy (net_config.mac, mlxbf_tmfifo_net_default_mac,6 ); +mlxbf_tmfifo_get_cfg_mac (net_config.mac); + ret = mlxbf_tmfifo_create_vdev(fifo, VIRTIO_ID_NET, + MLXBF_TMFIFO_NET_FEATURES, &net_config,
sizeof(net_config));drivers/platform/mellanox/mlxbf-tmfifo.c new file +42
-1+if (ret) + goto err; + +mod_timer (&fifo->timer, jiffies + mlxbf_tmfifo_timer_interval); + + fifo->is_ready = true; + +return 0 ; + +err: +mlxbf_tmfifo_remove (pdev); +early_err: +dev_err (&pdev->dev,"Probe Failed\n" ); +return ret; +} + +static const struct of_device_id mlxbf_tmfifo_match[] = { + { .compatible ="mellanox,bf-tmfifo" }, + {}, +}; +MODULE_DEVICE_TABLE (of, mlxbf_tmfifo_match); + +static const struct acpi_device_id mlxbf_tmfifo_acpi_match[] = { + {"MLNXBF01" ,0 }, + {}, +}; +MODULE_DEVICE_TABLE (acpi, mlxbf_tmfifo_acpi_match); + +static struct platform_driver mlxbf_tmfifo_driver = { + .probe = mlxbf_tmfifo_probe, + .remove = mlxbf_tmfifo_remove, + .driver = { + .name ="bf-tmfifo" , + .of_match_table = mlxbf_tmfifo_match, + .acpi_match_table =ACPI_PTR (mlxbf_tmfifo_acpi_match), + }, +}; + +module_platform_driver (mlxbf_tmfifo_driver); + +MODULE_DESCRIPTION ("Mellanox BlueField SoC TmFifo Driver" ); +MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Mellanox Technologies" ); --1.8.3.1
PATCH v8 2/2 dt-bindings: soc: Add TmFifo binding for Mellanox BlueField SoC
In reply to Liming SunAdd devicetree bindings for the TmFifo which is found on Mellanox BlueField SoCs.
--- .../devicetree/bindings/soc/mellanox/tmfifo.txt | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Documentation/devicetree/bindings/soc/mellanox/tmfifo.txt
Documentation/devicetree/bindings/soc/mellanox/tmfifo.txt new file +23 -0
@@ -0,0 +1,23 @@ +* Mellanox BlueField SoC TmFifo + +BlueField TmFifo provides a shared FIFO between the target and the +external host machine, which can be accessed by external host via +USB or PCIe. In the current tmfifo driver, this FIFO has been demuxed +to implement virtual console and network interface based on the virtio +framework. + +Required properties: + +- compatible: Should be "mellanox,bf-tmfifo" +- reg: Physical base address and length of Rx/Tx block +- interrupts: The interrupt number of Rx low water mark, Rx high water mark + Tx low water mark, Tx high water mark respectively. + +Example: + +tmfifo@800a20 { + compatible = "mellanox,bf-tmfifo"; + reg = <0x00800a20 0x00000018 + 0x00800a40 0x00000018>; + interrupts = <41, 42, 43, 44>; +};
Signature · 1 line
1.8.3.1
PATCH v9 1/1 platform/mellanox: Add TmFifo driver for Mellanox BlueField Soc
In reply to Liming SunThis commit adds the TmFifo platform driver for Mellanox BlueField Soc. TmFifo is a shared FIFO which enables external host machine to exchange data with the SoC via USB or PCIe. The driver is based on virtio framework and has console and network access enabled.
---
v9: Fix coding styles. Adjust code to use devm_xxx() APIs.
Removed the DT binding documentation since only ACPI is supported for now by UEFI on the SoC.
v8: Re-submit under drivers/platform/mellanox with target-size
platform driver only.
v7: Added host side drivers into the same patch set. v5~v6: Coding style fix.
v1~v4: Initial version for directory drivers/soc/mellanox.
--- drivers/platform/mellanox/Kconfig | 10 +- drivers/platform/mellanox/Makefile | 1 + drivers/platform/mellanox/mlxbf-tmfifo-regs.h | 67 ++ drivers/platform/mellanox/mlxbf-tmfifo.c | 1361 +++++++++++++++++++++++++ 4 files changed, 1438 insertions(+), 1 deletion(-) create mode 100644 drivers/platform/mellanox/mlxbf-tmfifo-regs.h create mode 100644 drivers/platform/mellanox/mlxbf-tmfifo.c
drivers/platform/mellanox/Kconfig +9 -1
@@ -5,7 +5,7 @@ menuconfig MELLANOX_PLATFORM bool "Platform support for Mellanox hardware" - depends on X86 || ARM || COMPILE_TEST + depends on X86 || ARM || ARM64 || COMPILE_TEST ---help--- Say Y here to get to see options for platform support for Mellanox systems. This option alone does not add any kernel code.
@@ -34,4 +34,12 @@ config MLXREG_IO to system resets operation, system reset causes monitoring and some kinds of mux selection. +config MLXBF_TMFIFO + tristate "Mellanox BlueField SoC TmFifo platform driver" + depends on ARM64 && ACPI && VIRTIO_CONSOLE && VIRTIO_NET + help + Say y here to enable TmFifo support. The TmFifo driver provides + platform driver support for the TmFifo which supports console + and networking based on the virtio framework. + endif # MELLANOX_PLATFORM
drivers/platform/mellanox/Makefile +1 -0
@@ -5,3 +5,4 @@ # obj-$(CONFIG_MLXREG_HOTPLUG) += mlxreg-hotplug.o obj-$(CONFIG_MLXREG_IO) += mlxreg-io.o +obj-$(CONFIG_MLXBF_TMFIFO) += mlxbf-tmfifo.o
drivers/platform/mellanox/mlxbf-tmfifo-regs.h new file +67 -0
67 lines not on this page · raw message
drivers/platform/mellanox/mlxbf-tmfifo.c new file +1361 -0
1,361 lines not on this page · raw message
Signature · 1 line
1.8.3.1
Re: [PATCH v9] platform/mellanox: Add TmFifo driver for Mellanox BlueField Soc
Quoted 5 lines · Liming Sun
This commit adds the TmFifo platform driver for Mellanox BlueField Soc. TmFifo is a shared FIFO which enables external host machine to exchange data with the SoC via USB or PCIe. The driver is based on virtio framework and has console and network access enabled.
Thanks for an update, my comments below.
Again, to Mellanox: guys, please, establish internal mailing list for review and don't come with such quality of code.
Next time I would like to see Reviewed-by from Mellanox people I know, like Vadim or Leon.
drivers/platform/mellanox/Kconfig config MLXREG_IO · line 39
Quoted 4 lines
drivers/platform/mellanox/Kconfig +3
-0+config MLXBF_TMFIFO + tristate "Mellanox BlueField SoC TmFifo platform driver" + depends on ARM64 && ACPI && VIRTIO_CONSOLE && VIRTIO_NET
Split this to three logical parts.
drivers/platform/mellanox/Kconfig config MLXREG_IO
Quoted 8 lines
drivers/platform/mellanox/Kconfig +5
-0+ help + Say y here to enable TmFifo support. The TmFifo driver provides + platform driver support for the TmFifo which supports console + and networking based on the virtio framework. obj-$(CONFIG_MLXREG_HOTPLUG) += mlxreg-hotplug.o obj-$(CONFIG_MLXREG_IO) += mlxreg-io.o +obj-$(CONFIG_MLXBF_TMFIFO) += mlxbf-tmfifo.o
I would suggest to keep it sorted.
Quoted 1 line
+#define
MLXBF_TMFIFO_TX_DATA0x0
I suggest to use same fixed format for offsets.
Here, for example, 0x00 would be better.
drivers/platform/mellanox/mlxbf-tmfifo-regs.h line 19
Quoted 2 lines
drivers/platform/mellanox/mlxbf-tmfifo-regs.h new file +2
-0+#define MLXBF_TMFIFO_TX_STS__COUNT_RMASK 0x1ff +#define MLXBF_TMFIFO_TX_STS__COUNT_MASK 0x1ff
#include <linux/bits.h>
...GENMASK()
drivers/platform/mellanox/mlxbf-tmfifo-regs.h line 37
Quoted 8 lines
drivers/platform/mellanox/mlxbf-tmfifo-regs.h new file +6
-0+#define MLXBF_TMFIFO_TX_CTL__LWM_RMASK 0xff +#define MLXBF_TMFIFO_TX_CTL__LWM_MASK 0xff +#define MLXBF_TMFIFO_TX_CTL__HWM_RMASK 0xff +#define MLXBF_TMFIFO_TX_CTL__HWM_MASK 0xff00 +#define MLXBF_TMFIFO_TX_CTL__MAX_ENTRIES_RMASK 0x1ff +#define MLXBF_TMFIFO_TX_CTL__MAX_ENTRIES_MASK 0x1ff00000000ULL
GENMASK() / GENMASK_ULL()
drivers/platform/mellanox/mlxbf-tmfifo-regs.h line 47
Quoted 2 lines
drivers/platform/mellanox/mlxbf-tmfifo-regs.h new file +2
-0+#define MLXBF_TMFIFO_RX_STS__COUNT_RMASK 0x1ff +#define MLXBF_TMFIFO_RX_STS__COUNT_MASK 0x1ff
GENMASK()
drivers/platform/mellanox/mlxbf-tmfifo-regs.h line 65
Quoted 8 lines
drivers/platform/mellanox/mlxbf-tmfifo-regs.h new file +6
-0+#define MLXBF_TMFIFO_RX_CTL__LWM_RMASK 0xff +#define MLXBF_TMFIFO_RX_CTL__LWM_MASK 0xff +#define MLXBF_TMFIFO_RX_CTL__HWM_RMASK 0xff +#define MLXBF_TMFIFO_RX_CTL__HWM_MASK 0xff00 +#define MLXBF_TMFIFO_RX_CTL__MAX_ENTRIES_RMASK 0x1ff +#define MLXBF_TMFIFO_RX_CTL__MAX_ENTRIES_MASK 0x1ff00000000ULL
Ditto.
Quoted 16 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +16
-0+#include <linux/acpi.h> +#include <linux/byteorder/generic.h> +#include <linux/bitfield.h> +#include <linux/cache.h> +#include <linux/device.h> +#include <linux/dma-mapping.h> +#include <linux/efi.h> +#include <linux/io.h> +#include <linux/interrupt.h> +#include <linux/irq.h> +#include <linux/kernel.h> +#include <linux/math64.h> +#include <linux/module.h> +#include <linux/moduleparam.h> +#include <linux/mutex.h> +#include <linux/platform_device.h>
drivers/platform/mellanox/mlxbf-tmfifo.c line 33
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +10
-0+#include <linux/resource.h> +#include <linux/slab.h> +#include <linux/types.h> +#include <linux/version.h> +#include <linux/virtio.h> +#include <linux/virtio_config.h> +#include <linux/virtio_console.h> +#include <linux/virtio_ids.h> +#include <linux/virtio_net.h> +#include <linux/virtio_ring.h>
Do you need all of them?
Quoted 1 line
+#define
MLXBF_TMFIFO_VRING_SIZE1024
SZ_1K ?
drivers/platform/mellanox/mlxbf-tmfifo.c line 41
Quoted 2 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +2
-0+/* Console Tx buffer size. */ +#define MLXBF_TMFIFO_CONS_TX_BUF_SIZE (32 * 1024)
SZ_32K ?
drivers/platform/mellanox/mlxbf-tmfifo.c line 50
Quoted 4 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +3
-0+/* House-keeping timer interval. */ +static int mlxbf_tmfifo_timer_interval =HZ /10 ; +/* Global lock. */
Noise. Either explain what it protects, or remove.
drivers/platform/mellanox/mlxbf-tmfifo.c line 65
Quoted 3 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +2
-0+static DEFINE_MUTEX (mlxbf_tmfifo_lock); +/* Struct declaration. */
Noise.
Quoted 7 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +7
-0+/* Structure to maintain the ring state. */ +struct mlxbf_tmfifo_vring { +void *va;/* virtual address */ +dma_addr_t dma;/* dma address */ +struct virtqueue *vq;/* virtqueue pointer */ +struct vring_desc *desc;/* current desc */ +struct vring_desc *desc_head;/* current desc head */
drivers/platform/mellanox/mlxbf-tmfifo.c line 84
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +10
-0+int cur_len;/* processed len in current desc */ +int rem_len;/* remaining length to be processed */ +int size;/* vring size */ +int align;/* vring alignment */ +int id;/* vring id */ +int vdev_id;/* TMFIFO_VDEV_xxx */ +u32 pkt_len;/* packet total length */ +u16 next_avail;/* next avail desc id */ +struct mlxbf_tmfifo *fifo;/* pointer back to the tmfifo */ +};
Perhaps kernel-doc?
drivers/platform/mellanox/mlxbf-tmfifo.c line 92
Quoted 7 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +7
-0+/* Interrupt types. */ +enum { +MLXBF_TM_RX_LWM_IRQ ,/* Rx low water mark irq */ +MLXBF_TM_RX_HWM_IRQ ,/* Rx high water mark irq */ +MLXBF_TM_TX_LWM_IRQ ,/* Tx low water mark irq */ +MLXBF_TM_TX_HWM_IRQ ,/* Tx high water mark irq */ +MLXBF_TM_IRQ_CNT
CNT...
drivers/platform/mellanox/mlxbf-tmfifo.c line 99
Quoted 7 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +7
-0+}; + +/* Ring types (Rx & Tx). */ +enum { +MLXBF_TMFIFO_VRING_RX ,/* Rx ring */ +MLXBF_TMFIFO_VRING_TX ,/* Tx ring */ +MLXBF_TMFIFO_VRING_NUM
...NUM
Perhaps one style for max numbers?
drivers/platform/mellanox/mlxbf-tmfifo.c line 110
Quoted 12 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +11
-0+}; + +/* Structure for the virtual device. */ +struct mlxbf_tmfifo_vdev { +struct virtio_device vdev;/* virtual device */ +u8 status; +u64 features; +union {/* virtio config space */ +struct virtio_console_config cons; +struct virtio_net_config net; + } config;
Describe, which field allows to distinguish what type of the data is in a union.
drivers/platform/mellanox/mlxbf-tmfifo.c line 115
Quoted 5 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +5
-0+struct mlxbf_tmfifo_vring vrings[MLXBF_TMFIFO_VRING_NUM ]; +u8 *tx_buf;/* tx buffer */ +u32 tx_head;/* tx buffer head */ +u32 tx_tail;/* tx buffer tail */ +};
kernel-doc?
drivers/platform/mellanox/mlxbf-tmfifo.c line 122
Quoted 6 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +6
-0+/* Structure of the interrupt information. */ +struct mlxbf_tmfifo_irq_info { +struct mlxbf_tmfifo *fifo;/* tmfifo structure */ +int irq;/* interrupt number */ +int index;/* array index */ +};
Ditto.
Quoted 8 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +8
-0+ +/* Structure of the TmFifo information. */ +struct mlxbf_tmfifo { +struct mlxbf_tmfifo_vdev *vdev[MLXBF_TMFIFO_VDEV_MAX ];/* devices */ +struct platform_device *pdev;/* platform device */ +struct mutex lock;/* fifo lock */ +void __iomem *rx_base;/* mapped register base */ +void __iomem *tx_base;/* mapped register base */
drivers/platform/mellanox/mlxbf-tmfifo.c line 140
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +10
-0+int tx_fifo_size;/* number of entries of the Tx FIFO */ +int rx_fifo_size;/* number of entries of the Rx FIFO */ +unsigned long pend_events;/* pending bits for deferred process */ +struct mlxbf_tmfifo_irq_info irq_info[MLXBF_TM_IRQ_CNT ];/* irq info */ +struct work_struct work;/* work struct for deferred process */ +struct timer_list timer;/* keepalive timer */ +struct mlxbf_tmfifo_vring *vring[2 ];/* current Tx/Rx ring */ +bool is_ready;/* ready flag */ +spinlock_t spin_lock;/* spin lock */ +};
Ditto.
Quoted 1 line
+/* Use a union struction for 64-bit little/big endian. */
What does this mean?
drivers/platform/mellanox/mlxbf-tmfifo.c line 154
Quoted 12 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +12
-0+union mlxbf_tmfifo_data_64bit { +u64 data; +__le64 data_le; +}; + +/* Message header used to demux data in the TmFifo. */ +union mlxbf_tmfifo_msg_hdr { +struct { +u8 type;/* message type */ +__be16 len;/* payload length */ +u8 unused[5 ];/* reserved, set to 0 */ + } __packed;
It's already packed. No?
drivers/platform/mellanox/mlxbf-tmfifo.c line 170
Quoted 5 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +4
-0+union mlxbf_tmfifo_data_64bit u;/* 64-bit data */ +}; +/* MTU setting of the virtio-net interface. */ +#define MLXBF_TMFIFO_NET_MTU 1500
Don't we have this globally defined?
drivers/platform/mellanox/mlxbf-tmfifo.c line 178
Quoted 4 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +4
-0+/* Supported virtio-net features. */ +#define MLXBF_TMFIFO_NET_FEATURES ((1UL << VIRTIO_NET_F_MTU) | \ + (1UL << VIRTIO_NET_F_STATUS) | \ + (1UL << VIRTIO_NET_F_MAC))
BIT_UL() ?
Quoted 1 line
+/* Function declarations. */
Noise.
Quoted 1 line
+static int
mlxbf_tmfifo_remove(struct platform_device *pdev);
Why do you need forward declaration for this?
drivers/platform/mellanox/mlxbf-tmfifo.c line 191
Quoted 7 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +7
-0+/* Return the consumed Tx buffer space. */ +static int mlxbf_tmfifo_vdev_tx_buf_len (struct mlxbf_tmfifo_vdev *vdev) +{ +return ((vdev->tx_tail >= vdev->tx_head) ? + (vdev->tx_tail - vdev->tx_head) : + (MLXBF_TMFIFO_CONS_TX_BUF_SIZE - vdev->tx_head + + vdev->tx_tail));
Split this for better reading.
drivers/platform/mellanox/mlxbf-tmfifo.c line 198
Quoted 7 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +7
-0+} + +/* Return the available Tx buffer space. */ +static int mlxbf_tmfifo_vdev_tx_buf_avail (struct mlxbf_tmfifo_vdev *vdev) +{ +return (MLXBF_TMFIFO_CONS_TX_BUF_RSV_SIZE - +mlxbf_tmfifo_vdev_tx_buf_len (vdev));
Redundant parens.
Moreover, you might consider temporary variable for better reading.
Quoted 20 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +20
-0+} + +/* Update Rx/Tx buffer index pointer. */ +static void mlxbf_tmfifo_vdev_tx_buf_index_inc (u32 *index,u32 len) +{ + *index += len; +if (*index >=MLXBF_TMFIFO_CONS_TX_BUF_SIZE ) + *index -=MLXBF_TMFIFO_CONS_TX_BUF_SIZE ; +} + +/* Allocate vrings for the fifo. */ +static int mlxbf_tmfifo_alloc_vrings (struct mlxbf_tmfifo *fifo, +struct mlxbf_tmfifo_vdev *tm_vdev, +int vdev_id) +{ +struct mlxbf_tmfifo_vring *vring; +dma_addr_t dma; +int i, size; +void *va; +
drivers/platform/mellanox/mlxbf-tmfifo.c line 227
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +9
-0+for (i =0 ; i <ARRAY_SIZE (tm_vdev->vrings); i++) { + vring = &tm_vdev->vrings[i]; + vring->fifo = fifo; + vring->size =MLXBF_TMFIFO_VRING_SIZE ; + vring->align =SMP_CACHE_BYTES ; + vring->id = i; + vring->vdev_id = vdev_id; + + size =PAGE_ALIGN (vring_size (vring->size, vring->align));
Why do you need this?dma_alloc_coherent() allocates memory on page granularity anyway.
drivers/platform/mellanox/mlxbf-tmfifo.c line 231
Quoted 5 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +4
-0+ va =dma_alloc_coherent (tm_vdev->vdev.dev.parent, size, &dma, +GFP_KERNEL ); +if (!va) { + dev_err(tm_vdev->vdev.dev.parent,
Would be much easy if you have temporary variable for this device.
Quoted 7 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +7
-0+ "dma_alloc_coherent failed\n"); +return -ENOMEM ; + } + + vring->va = va; + vring->dma = dma; + }
drivers/platform/mellanox/mlxbf-tmfifo.c line 285
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +9
-0+ +return 0 ; +} +/* Interrupt handler. */ +static irqreturn_t mlxbf_tmfifo_irq_handler (int irq,void *arg) +{ +struct mlxbf_tmfifo_irq_info *irq_info; + + irq_info = (struct mlxbf_tmfifo_irq_info *)arg;
Useless casting.
Assignment can be done in definition block.
Quoted 5 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +5
-0+if (irq_info->index <MLXBF_TM_IRQ_CNT && + !test_and_set_bit (irq_info->index, &irq_info->fifo->pend_events)) +schedule_work (&irq_info->fifo->work); + +return IRQ_HANDLED ;
drivers/platform/mellanox/mlxbf-tmfifo.c line 301
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +10
-0+} + +/* Get the next packet descriptor from the vring. */ +static struct vring_desc *mlxbf_tmfifo_get_next_desc (struct virtqueue *vq) +{ +struct mlxbf_tmfifo_vring *vring; +unsigned int idx, head; +struct vring *vr; + + vr = (struct vring *)virtqueue_get_vring (vq);
Return type is different? Is it safe to cast? Why?
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (!vr) + return NULL;
+ blank line
Quoted 1 line
+ vring = (struct
mlxbf_tmfifo_vring*)vq->priv;
Do you need explicit casting?
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (vring->next_avail == virtio16_to_cpu(vq->vdev, vr->avail->idx)) + return NULL;
+blank line
Quoted 16 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +16
-0+ idx = vring->next_avail % vr->num; + head =virtio16_to_cpu (vq->vdev, vr->avail->ring[idx]); +if (WARN_ON (head >= vr->num)) +return NULL ; + vring->next_avail++; + +return &vr->desc[head]; +} + +/* Release virtio descriptor. */ +static void mlxbf_tmfifo_release_desc (struct virtio_device *vdev, +struct vring *vr,struct vring_desc *desc, +u32 len) +{ +u16 idx, vr_idx; +
drivers/platform/mellanox/mlxbf-tmfifo.c line 332
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +10
-0+ vr_idx =virtio16_to_cpu (vdev, vr->used->idx); + idx = vr_idx % vr->num; + vr->used->ring[idx].id =cpu_to_virtio32 (vdev, desc - vr->desc); + vr->used->ring[idx].len =cpu_to_virtio32 (vdev, len); + +/* Virtio could poll and check the 'idx' to decide +* whether the desc is done or not. Add a memory +* barrier here to make sure the update above completes +* before updating the idx. +*/
Multi-line comment style is broken.
drivers/platform/mellanox/mlxbf-tmfifo.c line 412
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +8
-0+mb (); + vr->used->idx =cpu_to_virtio16 (vdev, vr_idx +1 ); +} +/* House-keeping timer. */ +static void mlxbf_tmfifo_timer (struct timer_list *arg) +{ +struct mlxbf_tmfifo *fifo; + fifo = container_of(arg, struct mlxbf_tmfifo, timer);
Can't be done in the definition block?
drivers/platform/mellanox/mlxbf-tmfifo.c line 418
Quoted 5 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +5
-0+/* +* Wake up the work handler to poll the Rx FIFO in case interrupt +* missing or any leftover bytes stuck in the FIFO. +*/ +test_and_set_bit (MLXBF_TM_RX_HWM_IRQ , &fifo->pend_events);
How do you utilize test results?
drivers/platform/mellanox/mlxbf-tmfifo.c line 424
Quoted 6 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +6
-0+ +/* +* Wake up Tx handler in case virtio has queued too many packets +* and are waiting for buffer return. +*/ +test_and_set_bit (MLXBF_TM_TX_LWM_IRQ , &fifo->pend_events);
Ditto.
drivers/platform/mellanox/mlxbf-tmfifo.c line 542
Quoted 9 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +8
-0+ +schedule_work (&fifo->work); + +mod_timer (&fifo->timer, jiffies + mlxbf_tmfifo_timer_interval); +} +/* Adjust the size to available space. */ +if (size +sizeof (hdr) > avail *sizeof (u64)) + size = avail *sizeof (u64) -sizeof (hdr);
Can avail be 0?
drivers/platform/mellanox/mlxbf-tmfifo.c line 549
Quoted 7 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +6
-0+/* Write header. */ + hdr.u.data =0 ; + hdr.type =VIRTIO_ID_CONSOLE ; + hdr.len =htons (size); + hdr.u.data_le =cpu_to_le64 (hdr.u.data); +writeq (hdr.u.data, fifo->tx_base +MLXBF_TMFIFO_TX_DATA );
So, this one is not protected anyhow? Potential race condition?
Quoted 25 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +25
-0+ +spin_lock_irqsave (&fifo->spin_lock, flags); + +while (size >0 ) { + addr = cons->tx_buf + cons->tx_head; + +if (cons->tx_head +sizeof (u64) <= +MLXBF_TMFIFO_CONS_TX_BUF_SIZE ) { +memcpy (&data, addr,sizeof (u64)); + }else { + partial =MLXBF_TMFIFO_CONS_TX_BUF_SIZE - cons->tx_head; +memcpy (&data, addr, partial); +memcpy ((u8 *)&data + partial, cons->tx_buf, +sizeof (u64) - partial); + } +writeq (data, fifo->tx_base +MLXBF_TMFIFO_TX_DATA ); + +if (size >=sizeof (u64)) { +mlxbf_tmfifo_vdev_tx_buf_index_inc (&cons->tx_head, +sizeof (u64)); + size -=sizeof (u64); + }else { +mlxbf_tmfifo_vdev_tx_buf_index_inc (&cons->tx_head, + size); + size =0 ;
drivers/platform/mellanox/mlxbf-tmfifo.c
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +9
-0+ } + } + +spin_unlock_irqrestore (&fifo->spin_lock, flags); +} +/* Rx/Tx one word (8 bytes) if not done. */ +if (vring->cur_len != len) +mlxbf_tmfifo_rxtx_word (fifo, vdev, vring, desc, is_rx, avail, + len);
In such case better to keep it in one line.
Quoted 6 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +6
-0+/* Get the array of feature bits for this device. */ +static u64 mlxbf_tmfifo_virtio_get_features (struct virtio_device *vdev) +{ +struct mlxbf_tmfifo_vdev *tm_vdev; + + tm_vdev = container_of(vdev, struct mlxbf_tmfifo_vdev, vdev);
drivers/platform/mellanox/mlxbf-tmfifo.c line 931
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +9
-0+return tm_vdev->features; +} + +/* Confirm device features to use. */ +static int mlxbf_tmfifo_virtio_finalize_features (struct virtio_device *vdev) +{ +struct mlxbf_tmfifo_vdev *tm_vdev; + + tm_vdev = container_of(vdev, struct mlxbf_tmfifo_vdev, vdev);
This is candidate to be a macro
#define mlxbt_vdev_to_tmfifo(...) ...
Quoted 35 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +34
-0+ tm_vdev->features = vdev->features; + +return 0 ; +} +/* Create vdev type in a tmfifo. */ +static int mlxbf_tmfifo_create_vdev (struct device *dev, +struct mlxbf_tmfifo *fifo, +int vdev_id,u64 features, +void *config,u32 size) +{ +struct mlxbf_tmfifo_vdev *tm_vdev; +int ret =0 ; + +mutex_lock (&fifo->lock); + + tm_vdev = fifo->vdev[vdev_id]; +if (tm_vdev) { +dev_err (dev,"vdev %d already exists\n" , vdev_id); + ret = -EEXIST ; + goto fail; + } + + tm_vdev =devm_kzalloc (dev,sizeof (*tm_vdev),GFP_KERNEL ); +if (!tm_vdev) { + ret = -ENOMEM ; + goto fail; + } + + tm_vdev->vdev.id.device = vdev_id; + tm_vdev->vdev.config = &mlxbf_tmfifo_virtio_config_ops; + tm_vdev->vdev.dev.parent = &fifo->pdev->dev; + tm_vdev->features = features; +if (config) +memcpy (&tm_vdev->config, config, size);
drivers/platform/mellanox/mlxbf-tmfifo.c line 1128
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +9
-0+if (mlxbf_tmfifo_alloc_vrings (fifo, tm_vdev, vdev_id)) { +dev_err (dev,"unable to allocate vring\n" ); + ret = -ENOMEM ; + goto fail; + } +if (vdev_id ==VIRTIO_ID_CONSOLE ) + tm_vdev->tx_buf =devm_kmalloc (dev, +MLXBF_TMFIFO_CONS_TX_BUF_SIZE , +GFP_KERNEL );
Are you sure devm_ suits here?
Quoted 24 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +23
-0+ fifo->vdev[vdev_id] = tm_vdev; + +/* Register the virtio device. */ + ret =register_virtio_device (&tm_vdev->vdev); +if (ret) { +dev_err (&fifo->pdev->dev,"register_virtio_device failed\n" ); + goto register_fail; + } + +mutex_unlock (&fifo->lock); +return 0 ; + +register_fail: +mlxbf_tmfifo_free_vrings (fifo, vdev_id); + fifo->vdev[vdev_id] =NULL ; +fail: +mutex_unlock (&fifo->lock); +return ret; +} +/* Read the configured network MAC address from efi variable. */ +static void mlxbf_tmfifo_get_cfg_mac (u8 *mac) +{ +efi_guid_t guid =EFI_GLOBAL_VARIABLE_GUID ;
drivers/platform/mellanox/mlxbf-tmfifo.c line 1182
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +10
-0+efi_status_t status; +unsigned long size; +u8 buf[6 ]; + + size =sizeof (buf); + status = efi.get_variable (mlxbf_tmfifo_efi_name, &guid,NULL , &size, + buf); +if (status ==EFI_SUCCESS && size ==sizeof (buf)) +memcpy (mac, buf,sizeof (buf)); +}
Shouldn't be rather helper in EFI lib in kernel?
Quoted 55 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +52
-0+/* Probe the TMFIFO. */ +static int mlxbf_tmfifo_probe (struct platform_device *pdev) +{ +struct virtio_net_config net_config; +struct resource *rx_res, *tx_res; +struct mlxbf_tmfifo *fifo; +int i, ret; + +/* Get the resource of the Rx FIFO. */ + rx_res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +if (!rx_res) +return -ENODEV ; + +/* Get the resource of the Tx FIFO. */ + tx_res =platform_get_resource (pdev,IORESOURCE_MEM ,1 ); +if (!tx_res) +return -ENODEV ; + +if (!devm_request_mem_region (&pdev->dev, rx_res->start, +resource_size (rx_res),"bf-tmfifo" )) +return -EBUSY ; + +if (!devm_request_mem_region (&pdev->dev, tx_res->start, +resource_size (tx_res),"bf-tmfifo" )) +return -EBUSY ; + + fifo =devm_kzalloc (&pdev->dev,sizeof (*fifo),GFP_KERNEL ); +if (!fifo) +return -ENOMEM ; + + fifo->pdev = pdev; +platform_set_drvdata (pdev, fifo); + +spin_lock_init (&fifo->spin_lock); +INIT_WORK (&fifo->work, mlxbf_tmfifo_work_handler); + +timer_setup (&fifo->timer, mlxbf_tmfifo_timer,0 ); + +for (i =0 ; i <MLXBF_TM_IRQ_CNT ; i++) { + fifo->irq_info[i].index = i; + fifo->irq_info[i].fifo = fifo; + fifo->irq_info[i].irq =platform_get_irq (pdev, i); + ret =devm_request_irq (&pdev->dev, fifo->irq_info[i].irq, + mlxbf_tmfifo_irq_handler,0 , +"tmfifo" , &fifo->irq_info[i]); +if (ret) { +dev_err (&pdev->dev,"devm_request_irq failed\n" ); + fifo->irq_info[i].irq =0 ; +return ret; + } + } +
drivers/platform/mellanox/mlxbf-tmfifo.c line 1295
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +9
-0+ fifo->rx_base =devm_ioremap (&pdev->dev, rx_res->start, +resource_size (rx_res)); +if (!fifo->rx_base) +return -ENOMEM ; + + fifo->tx_base =devm_ioremap (&pdev->dev, tx_res->start, +resource_size (tx_res)); +if (!fifo->tx_base) +return -ENOMEM ;
Switch to devm_ioremap_resource().
However, I think you probably need memremap().
Quoted 1 line
+
mutex_init(&fifo->lock);
Isn't too late for initializing this one?
drivers/platform/mellanox/mlxbf-tmfifo.c line 1334
Quoted 7 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +6
-0+/* Device remove function. */ +static int mlxbf_tmfifo_remove (struct platform_device *pdev) +{ +struct mlxbf_tmfifo *fifo =platform_get_drvdata (pdev); + +if (fifo)
How is it possible to be not true?
drivers/platform/mellanox/mlxbf-tmfifo.c line 1337
Quoted 4 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +3
-0+mlxbf_tmfifo_cleanup (fifo); + +platform_set_drvdata (pdev,NULL );
Redundant.
drivers/platform/mellanox/mlxbf-tmfifo.c line 1360
Quoted 5 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +4
-0+ +return 0 ; +} +MODULE_LICENSE ("GPL" );
Is it correct?
Signature · 2 lines
With Best Regards, Andy Shevchenko
RE: [PATCH v9] platform/mellanox: Add TmFifo driver for Mellanox BlueField Soc
Thanks Andy. We actually had some internal reviews as you mentioned. I'll try to solve the comments and update the 'Reviewed-by' in next revision.
Regards,
Liming
Quoted 712 lines
-----Original Message-----
From: Andy Shevchenko <[email protected]>
Sent: Wednesday, February 13, 2019 1:11 PM
To: Liming Sun <[email protected]>
Cc: David Woods <[email protected]>; Andy Shevchenko <[email protected]>; Darren Hart <[email protected]>; Vadim Pasternak <[email protected]>; Linux Kernel Mailing List <[email protected]>; Platform Driver <platform-driver- [email protected]>
Subject: Re: [PATCH v9] platform/mellanox: Add TmFifo driver for Mellanox BlueField SocQuoted 5 lines · Liming Sun
This commit adds the TmFifo platform driver for Mellanox BlueField Soc. TmFifo is a shared FIFO which enables external host machine to exchange data with the SoC via USB or PCIe. The driver is based on virtio framework and has console and network access enabled.
Thanks for an update, my comments below.
Again, to Mellanox: guys, please, establish internal mailing list for review and don't come with such quality of code.
Next time I would like to see Reviewed-by from Mellanox people I know, like Vadim or Leon.
drivers/platform/mellanox/Kconfig config MLXREG_IO · line 39
Quoted 4 lines
drivers/platform/mellanox/Kconfig +3
-0+config MLXBF_TMFIFO + tristate "Mellanox BlueField SoC TmFifo platform driver" + depends on ARM64 && ACPI && VIRTIO_CONSOLE && VIRTIO_NETSplit this to three logical parts.
drivers/platform/mellanox/Kconfig config MLXREG_IO
Quoted 8 lines
drivers/platform/mellanox/Kconfig +5
-0+ help + Say y here to enable TmFifo support. The TmFifo driver provides + platform driver support for the TmFifo which supports console + and networking based on the virtio framework. obj-$(CONFIG_MLXREG_HOTPLUG) += mlxreg-hotplug.o obj-$(CONFIG_MLXREG_IO) += mlxreg-io.o +obj-$(CONFIG_MLXBF_TMFIFO) += mlxbf-tmfifo.oI would suggest to keep it sorted.
Quoted 1 line
+#define
MLXBF_TMFIFO_TX_DATA0x0I suggest to use same fixed format for offsets.
Here, for example,0x00would be better.drivers/platform/mellanox/mlxbf-tmfifo-regs.h line 19
Quoted 2 lines
drivers/platform/mellanox/mlxbf-tmfifo-regs.h new file +2
-0+#define MLXBF_TMFIFO_TX_STS__COUNT_RMASK 0x1ff +#define MLXBF_TMFIFO_TX_STS__COUNT_MASK 0x1ff#include <
linux/bits.h>
...GENMASK()drivers/platform/mellanox/mlxbf-tmfifo-regs.h line 37
Quoted 8 lines
drivers/platform/mellanox/mlxbf-tmfifo-regs.h new file +6
-0+#define MLXBF_TMFIFO_TX_CTL__LWM_RMASK 0xff +#define MLXBF_TMFIFO_TX_CTL__LWM_MASK 0xff +#define MLXBF_TMFIFO_TX_CTL__HWM_RMASK 0xff +#define MLXBF_TMFIFO_TX_CTL__HWM_MASK 0xff00 +#define MLXBF_TMFIFO_TX_CTL__MAX_ENTRIES_RMASK 0x1ff +#define MLXBF_TMFIFO_TX_CTL__MAX_ENTRIES_MASK 0x1ff00000000ULL
GENMASK()/GENMASK_ULL()drivers/platform/mellanox/mlxbf-tmfifo-regs.h line 47
Quoted 2 lines
drivers/platform/mellanox/mlxbf-tmfifo-regs.h new file +2
-0+#define MLXBF_TMFIFO_RX_STS__COUNT_RMASK 0x1ff +#define MLXBF_TMFIFO_RX_STS__COUNT_MASK 0x1ff
GENMASK()drivers/platform/mellanox/mlxbf-tmfifo-regs.h line 65
Quoted 8 lines
drivers/platform/mellanox/mlxbf-tmfifo-regs.h new file +6
-0+#define MLXBF_TMFIFO_RX_CTL__LWM_RMASK 0xff +#define MLXBF_TMFIFO_RX_CTL__LWM_MASK 0xff +#define MLXBF_TMFIFO_RX_CTL__HWM_RMASK 0xff +#define MLXBF_TMFIFO_RX_CTL__HWM_MASK 0xff00 +#define MLXBF_TMFIFO_RX_CTL__MAX_ENTRIES_RMASK 0x1ff +#define MLXBF_TMFIFO_RX_CTL__MAX_ENTRIES_MASK 0x1ff00000000ULLDitto.
Quoted 16 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +16
-0+#include <linux/acpi.h> +#include <linux/byteorder/generic.h> +#include <linux/bitfield.h> +#include <linux/cache.h> +#include <linux/device.h> +#include <linux/dma-mapping.h> +#include <linux/efi.h> +#include <linux/io.h> +#include <linux/interrupt.h> +#include <linux/irq.h> +#include <linux/kernel.h> +#include <linux/math64.h> +#include <linux/module.h> +#include <linux/moduleparam.h> +#include <linux/mutex.h> +#include <linux/platform_device.h> drivers/platform/mellanox/mlxbf-tmfifo.c line 33
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +10
-0+#include <linux/resource.h> +#include <linux/slab.h> +#include <linux/types.h> +#include <linux/version.h> +#include <linux/virtio.h> +#include <linux/virtio_config.h> +#include <linux/virtio_console.h> +#include <linux/virtio_ids.h> +#include <linux/virtio_net.h> +#include <linux/virtio_ring.h> Do you need all of them?
Quoted 1 line
+#define
MLXBF_TMFIFO_VRING_SIZE1024
SZ_1K?drivers/platform/mellanox/mlxbf-tmfifo.c line 41
Quoted 2 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +2
-0+/* Console Tx buffer size. */ +#define MLXBF_TMFIFO_CONS_TX_BUF_SIZE (32 * 1024)
SZ_32K?drivers/platform/mellanox/mlxbf-tmfifo.c line 50
Quoted 4 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +3
-0+/* House-keeping timer interval. */ +static int mlxbf_tmfifo_timer_interval =HZ /10 ; +/* Global lock. */ Noise. Either explain what it protects, or remove.
drivers/platform/mellanox/mlxbf-tmfifo.c line 65
Quoted 3 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +2
-0+static DEFINE_MUTEX (mlxbf_tmfifo_lock); +/* Struct declaration. */ Noise.
Quoted 7 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +7
-0+/* Structure to maintain the ring state. */ +struct mlxbf_tmfifo_vring { +void *va;/* virtual address */ +dma_addr_t dma;/* dma address */ +struct virtqueue *vq;/* virtqueue pointer */ +struct vring_desc *desc;/* current desc */ +struct vring_desc *desc_head;/* current desc head */ drivers/platform/mellanox/mlxbf-tmfifo.c line 84
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +10
-0+int cur_len;/* processed len in current desc */ +int rem_len;/* remaining length to be processed */ +int size;/* vring size */ +int align;/* vring alignment */ +int id;/* vring id */ +int vdev_id;/* TMFIFO_VDEV_xxx */ +u32 pkt_len;/* packet total length */ +u16 next_avail;/* next avail desc id */ +struct mlxbf_tmfifo *fifo;/* pointer back to the tmfifo */ +};Perhaps kernel-doc?
drivers/platform/mellanox/mlxbf-tmfifo.c line 92
Quoted 7 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +7
-0+/* Interrupt types. */ +enum { +MLXBF_TM_RX_LWM_IRQ ,/* Rx low water mark irq */ +MLXBF_TM_RX_HWM_IRQ ,/* Rx high water mark irq */ +MLXBF_TM_TX_LWM_IRQ ,/* Tx low water mark irq */ +MLXBF_TM_TX_HWM_IRQ ,/* Tx high water mark irq */ +MLXBF_TM_IRQ_CNT CNT...
drivers/platform/mellanox/mlxbf-tmfifo.c line 99
Quoted 7 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +7
-0+}; + +/* Ring types (Rx & Tx). */ +enum { +MLXBF_TMFIFO_VRING_RX ,/* Rx ring */ +MLXBF_TMFIFO_VRING_TX ,/* Tx ring */ +MLXBF_TMFIFO_VRING_NUM ...NUM
Perhaps one style for max numbers?
drivers/platform/mellanox/mlxbf-tmfifo.c line 110
Quoted 12 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +11
-0+}; + +/* Structure for the virtual device. */ +struct mlxbf_tmfifo_vdev { +struct virtio_device vdev;/* virtual device */ +u8 status; +u64 features; +union {/* virtio config space */ +struct virtio_console_config cons; +struct virtio_net_config net; + } config;Describe, which field allows to distinguish what type of the data is in a union.
drivers/platform/mellanox/mlxbf-tmfifo.c line 115
Quoted 5 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +5
-0+struct mlxbf_tmfifo_vring vrings[MLXBF_TMFIFO_VRING_NUM ]; +u8 *tx_buf;/* tx buffer */ +u32 tx_head;/* tx buffer head */ +u32 tx_tail;/* tx buffer tail */ +};kernel-doc?
drivers/platform/mellanox/mlxbf-tmfifo.c line 122
Quoted 6 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +6
-0+/* Structure of the interrupt information. */ +struct mlxbf_tmfifo_irq_info { +struct mlxbf_tmfifo *fifo;/* tmfifo structure */ +int irq;/* interrupt number */ +int index;/* array index */ +};Ditto.
Quoted 8 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +8
-0+ +/* Structure of the TmFifo information. */ +struct mlxbf_tmfifo { +struct mlxbf_tmfifo_vdev *vdev[MLXBF_TMFIFO_VDEV_MAX ];/* devices */ +struct platform_device *pdev;/* platform device */ +struct mutex lock;/* fifo lock */ +void __iomem *rx_base;/* mapped register base */ +void __iomem *tx_base;/* mapped register base */ drivers/platform/mellanox/mlxbf-tmfifo.c line 140
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +10
-0+int tx_fifo_size;/* number of entries of the Tx FIFO */ +int rx_fifo_size;/* number of entries of the Rx FIFO */ +unsigned long pend_events;/* pending bits for deferred process */ +struct mlxbf_tmfifo_irq_info irq_info[MLXBF_TM_IRQ_CNT ];/* irq info */ +struct work_struct work;/* work struct for deferred process */ +struct timer_list timer;/* keepalive timer */ +struct mlxbf_tmfifo_vring *vring[2 ];/* current Tx/Rx ring */ +bool is_ready;/* ready flag */ +spinlock_t spin_lock;/* spin lock */ +};Ditto.
Quoted 1 line
+/* Use a union struction for 64-bit little/big endian. */
What does this mean?
drivers/platform/mellanox/mlxbf-tmfifo.c line 154
Quoted 12 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +12
-0+union mlxbf_tmfifo_data_64bit { +u64 data; +__le64 data_le; +}; + +/* Message header used to demux data in the TmFifo. */ +union mlxbf_tmfifo_msg_hdr { +struct { +u8 type;/* message type */ +__be16 len;/* payload length */ +u8 unused[5 ];/* reserved, set to 0 */ + } __packed;It's already packed. No?
drivers/platform/mellanox/mlxbf-tmfifo.c line 170
Quoted 5 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +4
-0+union mlxbf_tmfifo_data_64bit u;/* 64-bit data */ +}; +/* MTU setting of the virtio-net interface. */ +#define MLXBF_TMFIFO_NET_MTU 1500Don't we have this globally defined?
drivers/platform/mellanox/mlxbf-tmfifo.c line 178
Quoted 4 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +4
-0+/* Supported virtio-net features. */ +#define MLXBF_TMFIFO_NET_FEATURES ((1UL << VIRTIO_NET_F_MTU) | \ + (1UL << VIRTIO_NET_F_STATUS) | \ + (1UL << VIRTIO_NET_F_MAC))
BIT_UL()?Quoted 1 line
+/* Function declarations. */
Noise.
Quoted 1 line
+static int
mlxbf_tmfifo_remove(struct platform_device *pdev);Why do you need forward declaration for this?
drivers/platform/mellanox/mlxbf-tmfifo.c line 191
Quoted 7 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +7
-0+/* Return the consumed Tx buffer space. */ +static int mlxbf_tmfifo_vdev_tx_buf_len (struct mlxbf_tmfifo_vdev *vdev) +{ +return ((vdev->tx_tail >= vdev->tx_head) ? + (vdev->tx_tail - vdev->tx_head) : + (MLXBF_TMFIFO_CONS_TX_BUF_SIZE - vdev->tx_head + + vdev->tx_tail));Split this for better reading.
drivers/platform/mellanox/mlxbf-tmfifo.c line 198
Quoted 7 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +7
-0+} + +/* Return the available Tx buffer space. */ +static int mlxbf_tmfifo_vdev_tx_buf_avail (struct mlxbf_tmfifo_vdev *vdev) +{ +return (MLXBF_TMFIFO_CONS_TX_BUF_RSV_SIZE - +mlxbf_tmfifo_vdev_tx_buf_len (vdev));Redundant parens.
Moreover, you might consider temporary variable for better reading.Quoted 20 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +20
-0+} + +/* Update Rx/Tx buffer index pointer. */ +static void mlxbf_tmfifo_vdev_tx_buf_index_inc (u32 *index,u32 len) +{ + *index += len; +if (*index >=MLXBF_TMFIFO_CONS_TX_BUF_SIZE ) + *index -=MLXBF_TMFIFO_CONS_TX_BUF_SIZE ; +} + +/* Allocate vrings for the fifo. */ +static int mlxbf_tmfifo_alloc_vrings (struct mlxbf_tmfifo *fifo, +struct mlxbf_tmfifo_vdev *tm_vdev, +int vdev_id) +{ +struct mlxbf_tmfifo_vring *vring; +dma_addr_t dma; +int i, size; +void *va; +drivers/platform/mellanox/mlxbf-tmfifo.c line 227
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +9
-0+for (i =0 ; i <ARRAY_SIZE (tm_vdev->vrings); i++) { + vring = &tm_vdev->vrings[i]; + vring->fifo = fifo; + vring->size =MLXBF_TMFIFO_VRING_SIZE ; + vring->align =SMP_CACHE_BYTES ; + vring->id = i; + vring->vdev_id = vdev_id; + + size =PAGE_ALIGN (vring_size (vring->size, vring->align));Why do you need this?
dma_alloc_coherent()allocates memory on page granularity anyway.drivers/platform/mellanox/mlxbf-tmfifo.c line 231
Quoted 5 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +4
-0+ va =dma_alloc_coherent (tm_vdev->vdev.dev.parent, size, &dma, +GFP_KERNEL ); +if (!va) { + dev_err(tm_vdev->vdev.dev.parent,Would be much easy if you have temporary variable for this device.
Quoted 7 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +7
-0+ "dma_alloc_coherent failed\n"); +return -ENOMEM ; + } + + vring->va = va; + vring->dma = dma; + }drivers/platform/mellanox/mlxbf-tmfifo.c line 285
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +9
-0+ +return 0 ; +} +/* Interrupt handler. */ +static irqreturn_t mlxbf_tmfifo_irq_handler (int irq,void *arg) +{ +struct mlxbf_tmfifo_irq_info *irq_info; + + irq_info = (struct mlxbf_tmfifo_irq_info *)arg;Useless casting.
Assignment can be done in definition block.Quoted 5 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +5
-0+if (irq_info->index <MLXBF_TM_IRQ_CNT && + !test_and_set_bit (irq_info->index, &irq_info->fifo->pend_events)) +schedule_work (&irq_info->fifo->work); + +return IRQ_HANDLED ;drivers/platform/mellanox/mlxbf-tmfifo.c line 301
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +10
-0+} + +/* Get the next packet descriptor from the vring. */ +static struct vring_desc *mlxbf_tmfifo_get_next_desc (struct virtqueue *vq) +{ +struct mlxbf_tmfifo_vring *vring; +unsigned int idx, head; +struct vring *vr; + + vr = (struct vring *)virtqueue_get_vring (vq);Return type is different? Is it safe to cast? Why?
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (!vr) + return NULL;+ blank line
Quoted 1 line
+ vring = (struct
mlxbf_tmfifo_vring*)vq->priv;Do you need explicit casting?
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (vring->next_avail == virtio16_to_cpu(vq->vdev, vr->avail->idx)) + return NULL;+blank line
Quoted 16 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +16
-0+ idx = vring->next_avail % vr->num; + head =virtio16_to_cpu (vq->vdev, vr->avail->ring[idx]); +if (WARN_ON (head >= vr->num)) +return NULL ; + vring->next_avail++; + +return &vr->desc[head]; +} + +/* Release virtio descriptor. */ +static void mlxbf_tmfifo_release_desc (struct virtio_device *vdev, +struct vring *vr,struct vring_desc *desc, +u32 len) +{ +u16 idx, vr_idx; +drivers/platform/mellanox/mlxbf-tmfifo.c line 332
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +10
-0+ vr_idx =virtio16_to_cpu (vdev, vr->used->idx); + idx = vr_idx % vr->num; + vr->used->ring[idx].id =cpu_to_virtio32 (vdev, desc - vr->desc); + vr->used->ring[idx].len =cpu_to_virtio32 (vdev, len); + +/* Virtio could poll and check the 'idx' to decide +* whether the desc is done or not. Add a memory +* barrier here to make sure the update above completes +* before updating the idx. +*/ Multi-line comment style is broken.
drivers/platform/mellanox/mlxbf-tmfifo.c line 412
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +8
-0+mb (); + vr->used->idx =cpu_to_virtio16 (vdev, vr_idx +1 ); +} +/* House-keeping timer. */ +static void mlxbf_tmfifo_timer (struct timer_list *arg) +{ +struct mlxbf_tmfifo *fifo; + fifo = container_of(arg, struct mlxbf_tmfifo, timer);Can't be done in the definition block?
drivers/platform/mellanox/mlxbf-tmfifo.c line 418
Quoted 5 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +5
-0+/* +* Wake up the work handler to poll the Rx FIFO in case interrupt +* missing or any leftover bytes stuck in the FIFO. +*/ +test_and_set_bit (MLXBF_TM_RX_HWM_IRQ , &fifo->pend_events);How do you utilize test results?
drivers/platform/mellanox/mlxbf-tmfifo.c line 424
Quoted 6 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +6
-0+ +/* +* Wake up Tx handler in case virtio has queued too many packets +* and are waiting for buffer return. +*/ +test_and_set_bit (MLXBF_TM_TX_LWM_IRQ , &fifo->pend_events);Ditto.
drivers/platform/mellanox/mlxbf-tmfifo.c line 542
Quoted 9 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +8
-0+ +schedule_work (&fifo->work); + +mod_timer (&fifo->timer, jiffies + mlxbf_tmfifo_timer_interval); +} +/* Adjust the size to available space. */ +if (size +sizeof (hdr) > avail *sizeof (u64)) + size = avail *sizeof (u64) -sizeof (hdr);Can avail be 0?
drivers/platform/mellanox/mlxbf-tmfifo.c line 549
Quoted 7 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +6
-0+/* Write header. */ + hdr.u.data =0 ; + hdr.type =VIRTIO_ID_CONSOLE ; + hdr.len =htons (size); + hdr.u.data_le =cpu_to_le64 (hdr.u.data); +writeq (hdr.u.data, fifo->tx_base +MLXBF_TMFIFO_TX_DATA );So, this one is not protected anyhow? Potential race condition?
Quoted 25 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +25
-0+ +spin_lock_irqsave (&fifo->spin_lock, flags); + +while (size >0 ) { + addr = cons->tx_buf + cons->tx_head; + +if (cons->tx_head +sizeof (u64) <= +MLXBF_TMFIFO_CONS_TX_BUF_SIZE ) { +memcpy (&data, addr,sizeof (u64)); + }else { + partial =MLXBF_TMFIFO_CONS_TX_BUF_SIZE - cons->tx_head; +memcpy (&data, addr, partial); +memcpy ((u8 *)&data + partial, cons->tx_buf, +sizeof (u64) - partial); + } +writeq (data, fifo->tx_base +MLXBF_TMFIFO_TX_DATA ); + +if (size >=sizeof (u64)) { +mlxbf_tmfifo_vdev_tx_buf_index_inc (&cons->tx_head, +sizeof (u64)); + size -=sizeof (u64); + }else { +mlxbf_tmfifo_vdev_tx_buf_index_inc (&cons->tx_head, + size); + size =0 ;drivers/platform/mellanox/mlxbf-tmfifo.c
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +9
-0+ } + } + +spin_unlock_irqrestore (&fifo->spin_lock, flags); +} +/* Rx/Tx one word (8 bytes) if not done. */ +if (vring->cur_len != len) +mlxbf_tmfifo_rxtx_word (fifo, vdev, vring, desc, is_rx, avail, + len);In such case better to keep it in one line.
Quoted 6 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +6
-0+/* Get the array of feature bits for this device. */ +static u64 mlxbf_tmfifo_virtio_get_features (struct virtio_device *vdev) +{ +struct mlxbf_tmfifo_vdev *tm_vdev; + + tm_vdev = container_of(vdev, struct mlxbf_tmfifo_vdev, vdev);drivers/platform/mellanox/mlxbf-tmfifo.c line 931
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +9
-0+return tm_vdev->features; +} + +/* Confirm device features to use. */ +static int mlxbf_tmfifo_virtio_finalize_features (struct virtio_device *vdev) +{ +struct mlxbf_tmfifo_vdev *tm_vdev; + + tm_vdev = container_of(vdev, struct mlxbf_tmfifo_vdev, vdev);This is candidate to be a macro
#define
mlxbt_vdev_to_tmfifo(...)...Quoted 35 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +34
-0+ tm_vdev->features = vdev->features; + +return 0 ; +} +/* Create vdev type in a tmfifo. */ +static int mlxbf_tmfifo_create_vdev (struct device *dev, +struct mlxbf_tmfifo *fifo, +int vdev_id,u64 features, +void *config,u32 size) +{ +struct mlxbf_tmfifo_vdev *tm_vdev; +int ret =0 ; + +mutex_lock (&fifo->lock); + + tm_vdev = fifo->vdev[vdev_id]; +if (tm_vdev) { +dev_err (dev,"vdev %d already exists\n" , vdev_id); + ret = -EEXIST ; + goto fail; + } + + tm_vdev =devm_kzalloc (dev,sizeof (*tm_vdev),GFP_KERNEL ); +if (!tm_vdev) { + ret = -ENOMEM ; + goto fail; + } + + tm_vdev->vdev.id.device = vdev_id; + tm_vdev->vdev.config = &mlxbf_tmfifo_virtio_config_ops; + tm_vdev->vdev.dev.parent = &fifo->pdev->dev; + tm_vdev->features = features; +if (config) +memcpy (&tm_vdev->config, config, size);drivers/platform/mellanox/mlxbf-tmfifo.c line 1128
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +9
-0+if (mlxbf_tmfifo_alloc_vrings (fifo, tm_vdev, vdev_id)) { +dev_err (dev,"unable to allocate vring\n" ); + ret = -ENOMEM ; + goto fail; + } +if (vdev_id ==VIRTIO_ID_CONSOLE ) + tm_vdev->tx_buf =devm_kmalloc (dev, +MLXBF_TMFIFO_CONS_TX_BUF_SIZE , +GFP_KERNEL );Are you sure
devm_suits here?Quoted 24 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +23
-0+ fifo->vdev[vdev_id] = tm_vdev; + +/* Register the virtio device. */ + ret =register_virtio_device (&tm_vdev->vdev); +if (ret) { +dev_err (&fifo->pdev->dev,"register_virtio_device failed\n" ); + goto register_fail; + } + +mutex_unlock (&fifo->lock); +return 0 ; + +register_fail: +mlxbf_tmfifo_free_vrings (fifo, vdev_id); + fifo->vdev[vdev_id] =NULL ; +fail: +mutex_unlock (&fifo->lock); +return ret; +} +/* Read the configured network MAC address from efi variable. */ +static void mlxbf_tmfifo_get_cfg_mac (u8 *mac) +{ +efi_guid_t guid =EFI_GLOBAL_VARIABLE_GUID ;drivers/platform/mellanox/mlxbf-tmfifo.c line 1182
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +10
-0+efi_status_t status; +unsigned long size; +u8 buf[6 ]; + + size =sizeof (buf); + status = efi.get_variable (mlxbf_tmfifo_efi_name, &guid,NULL , &size, + buf); +if (status ==EFI_SUCCESS && size ==sizeof (buf)) +memcpy (mac, buf,sizeof (buf)); +}Shouldn't be rather helper in EFI lib in kernel?
Quoted 55 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +52
-0+/* Probe the TMFIFO. */ +static int mlxbf_tmfifo_probe (struct platform_device *pdev) +{ +struct virtio_net_config net_config; +struct resource *rx_res, *tx_res; +struct mlxbf_tmfifo *fifo; +int i, ret; + +/* Get the resource of the Rx FIFO. */ + rx_res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +if (!rx_res) +return -ENODEV ; + +/* Get the resource of the Tx FIFO. */ + tx_res =platform_get_resource (pdev,IORESOURCE_MEM ,1 ); +if (!tx_res) +return -ENODEV ; + +if (!devm_request_mem_region (&pdev->dev, rx_res->start, +resource_size (rx_res),"bf-tmfifo" )) +return -EBUSY ; + +if (!devm_request_mem_region (&pdev->dev, tx_res->start, +resource_size (tx_res),"bf-tmfifo" )) +return -EBUSY ; + + fifo =devm_kzalloc (&pdev->dev,sizeof (*fifo),GFP_KERNEL ); +if (!fifo) +return -ENOMEM ; + + fifo->pdev = pdev; +platform_set_drvdata (pdev, fifo); + +spin_lock_init (&fifo->spin_lock); +INIT_WORK (&fifo->work, mlxbf_tmfifo_work_handler); + +timer_setup (&fifo->timer, mlxbf_tmfifo_timer,0 ); + +for (i =0 ; i <MLXBF_TM_IRQ_CNT ; i++) { + fifo->irq_info[i].index = i; + fifo->irq_info[i].fifo = fifo; + fifo->irq_info[i].irq =platform_get_irq (pdev, i); + ret =devm_request_irq (&pdev->dev, fifo->irq_info[i].irq, + mlxbf_tmfifo_irq_handler,0 , +"tmfifo" , &fifo->irq_info[i]); +if (ret) { +dev_err (&pdev->dev,"devm_request_irq failed\n" ); + fifo->irq_info[i].irq =0 ; +return ret; + } + } +drivers/platform/mellanox/mlxbf-tmfifo.c line 1295
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +9
-0+ fifo->rx_base =devm_ioremap (&pdev->dev, rx_res->start, +resource_size (rx_res)); +if (!fifo->rx_base) +return -ENOMEM ; + + fifo->tx_base =devm_ioremap (&pdev->dev, tx_res->start, +resource_size (tx_res)); +if (!fifo->tx_base) +return -ENOMEM ;Switch to
devm_ioremap_resource().
However, I think you probably needmemremap().Quoted 1 line
+
mutex_init(&fifo->lock);Isn't too late for initializing this one?
drivers/platform/mellanox/mlxbf-tmfifo.c line 1334
Quoted 7 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +6
-0+/* Device remove function. */ +static int mlxbf_tmfifo_remove (struct platform_device *pdev) +{ +struct mlxbf_tmfifo *fifo =platform_get_drvdata (pdev); + +if (fifo)How is it possible to be not true?
drivers/platform/mellanox/mlxbf-tmfifo.c line 1337
Quoted 4 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +3
-0+mlxbf_tmfifo_cleanup (fifo); + +platform_set_drvdata (pdev,NULL );Redundant.
drivers/platform/mellanox/mlxbf-tmfifo.c line 1360
Quoted 5 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +4
-0+ +return 0 ; +} +MODULE_LICENSE ("GPL" );Is it correct?
--
With Best Regards,
Andy Shevchenko
RE: [PATCH v9] platform/mellanox: Add TmFifo driver for Mellanox BlueField Soc
In reply to Andy ShevchenkoThanks Andy. Please see my response and questions on some of the comments below.
Regards,
Liming
Quoted 13 lines
-----Original Message-----
From: Andy Shevchenko <[email protected]>
Sent: Wednesday, February 13, 2019 1:11 PM
To: Liming Sun <[email protected]>
Cc: David Woods <[email protected]>; Andy Shevchenko <[email protected]>; Darren Hart <[email protected]>; Vadim Pasternak <[email protected]>; Linux Kernel Mailing List <[email protected]>; Platform Driver <platform-driver- [email protected]>
Subject: Re: [PATCH v9] platform/mellanox: Add TmFifo driver for Mellanox BlueField SocQuoted 1 line · Liming Sun
...
Quoted 8 lines
Quoted 1 line
+/* Use a union struction for 64-bit little/big endian. */
What does this mean?
drivers/platform/mellanox/mlxbf-tmfifo.c line 146
Quoted 4 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +4
-0+union mlxbf_tmfifo_data_64bit { +u64 data; +__le64 data_le; +};
The purpose is to send 8 bytes into the FIFO without data casting in writeq().
Below is the example with the cast.
u64 data = 0x1234;__le64 data_le;data_le = cpu_to_le64(data)writeq(*(u64 *)&data_le, fifo->tx_base + MLXBF_TMFIFO_TX_DATA);
Below is the alternative trying to use union to avoid the cast.
mlxbf_tmfifo_data_64bit u;
u.data = 0x1234;
u. data_le = cpu_to_le64(u.data); writeq(u.data_le, fifo->tx_base + MLXBF_TMFIFO_TX_DATA);
Which way might be better or any other suggestions?
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c line 154
Quoted 8 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +8
-0+ +/* Message header used to demux data in the TmFifo. */ +union mlxbf_tmfifo_msg_hdr { +struct { +u8 type;/* message type */ +__be16 len;/* payload length */ +u8 unused[5 ];/* reserved, set to 0 */ + } __packed;It's already packed. No?
The '__packed' is needed here. Without it the compiler will make the structure size exceeding 8 bytes which is not desired.
Quoted 8 lines
...
drivers/platform/mellanox/mlxbf-tmfifo.c line 1128
Quoted 5 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +4
-0+if (vdev_id ==VIRTIO_ID_CONSOLE ) + tm_vdev->tx_buf =devm_kmalloc (dev, +MLXBF_TMFIFO_CONS_TX_BUF_SIZE , +GFP_KERNEL );Are you sure
devm_suits here?
The 'tx_buf' are normal buffer to hold the console output. It seems ok to use devm_kmalloc so it could automatically freed on driver detach. Please correct me if I am wrong.
Quoted 9 lines
drivers/platform/mellanox/mlxbf-tmfifo.c line 1295
Quoted 6 lines
...
drivers/platform/mellanox/mlxbf-tmfifo.c new file +5
-0+ + fifo->tx_base =devm_ioremap (&pdev->dev, tx_res->start, +resource_size (tx_res)); +if (!fifo->tx_base) +return -ENOMEM ;Switch to
devm_ioremap_resource().
However, I think you probably needmemremap().
This is device registers accessed by arm64 core.
In arm64/include/asm/io.h, several apis are defined the same.
#define ioremap(addr, size) __ioremap((addr), (size), __pgprot(PROT_DEVICE_nGnRE))
#define ioremap_nocache(addr, size) __ioremap((addr), (size), __pgprot(PROT_DEVICE_nGnRE))
#define ioremap_wt(addr, size) __ioremap((addr), (size), __pgprot(PROT_DEVICE_nGnRE))
How about using devm_ioremap_nocache()?
It could take advantage of the devm_xx() api.
Quoted 6 lines
...
Is it correct?--
With Best Regards,
Andy Shevchenko
RE: [PATCH v9] platform/mellanox: Add TmFifo driver for Mellanox BlueField Soc
In reply to Andy ShevchenkoThanks Andy for the comments. Please see the responses below. I'll also post the v10 patch after this email.
Regards,
Liming
Quoted 16 lines
-----Original Message-----
From: Andy Shevchenko <[email protected]>
Sent: Wednesday, February 13, 2019 1:11 PM
To: Liming Sun <[email protected]>
Cc: David Woods <[email protected]>; Andy Shevchenko <[email protected]>; Darren Hart <[email protected]>; Vadim Pasternak <[email protected]>; Linux Kernel Mailing List <[email protected]>; Platform Driver <platform-driver- [email protected]>
Subject: Re: [PATCH v9] platform/mellanox: Add TmFifo driver for Mellanox BlueField SocQuoted 5 lines · Liming Sun
This commit adds the TmFifo platform driver for Mellanox BlueField Soc. TmFifo is a shared FIFO which enables external host machine to exchange data with the SoC via USB or PCIe. The driver is based on virtio framework and has console and network access enabled.
Quoted 4 lines
Thanks for an update, my comments below.
Again, to Mellanox: guys, please, establish internal mailing list for review and don't come with such quality of code.
Yes, the patch went through internal review. I updated the Reviewed-by section of the commit message.
Quoted 10 lines
Next time I would like to see Reviewed-by from Mellanox people I know, like Vadim or Leon.
drivers/platform/mellanox/Kconfig config MLXREG_IO · line 39
Quoted 4 lines
drivers/platform/mellanox/Kconfig +3
-0+config MLXBF_TMFIFO + tristate "Mellanox BlueField SoC TmFifo platform driver" + depends on ARM64 && ACPI && VIRTIO_CONSOLE && VIRTIO_NETSplit this to three logical parts.
Updated in v10.
Quoted 11 lines
drivers/platform/mellanox/Kconfig config MLXREG_IO
Quoted 9 lines
drivers/platform/mellanox/Kconfig +5
-0+ help + Say y here to enable TmFifo support. The TmFifo driver provides + platform driver support for the TmFifo which supports console + and networking based on the virtio framework. obj-$(CONFIG_MLXREG_HOTPLUG) += mlxreg-hotplug.o obj-$(CONFIG_MLXREG_IO) += mlxreg-io.o +obj-$(CONFIG_MLXBF_TMFIFO) += mlxbf-tmfifo.oI would suggest to keep it sorted.
Updated in v10.
Quoted 6 lines
Quoted 2 lines
+#define
MLXBF_TMFIFO_TX_DATA0x0I suggest to use same fixed format for offsets.
Here, for example,0x00would be better.
Quoted 6 lines
drivers/platform/mellanox/mlxbf-tmfifo-regs.h line 19
Quoted 2 lines
drivers/platform/mellanox/mlxbf-tmfifo-regs.h new file +2
-0+#define MLXBF_TMFIFO_TX_STS__COUNT_RMASK 0x1ff +#define MLXBF_TMFIFO_TX_STS__COUNT_MASK 0x1ff#include <
linux/bits.h>
...GENMASK()
Updated in v10.
Quoted 11 lines
drivers/platform/mellanox/mlxbf-tmfifo-regs.h line 37
Quoted 9 lines
drivers/platform/mellanox/mlxbf-tmfifo-regs.h new file +6
-0+#define MLXBF_TMFIFO_TX_CTL__LWM_RMASK 0xff +#define MLXBF_TMFIFO_TX_CTL__LWM_MASK 0xff +#define MLXBF_TMFIFO_TX_CTL__HWM_RMASK 0xff +#define MLXBF_TMFIFO_TX_CTL__HWM_MASK 0xff00 +#define MLXBF_TMFIFO_TX_CTL__MAX_ENTRIES_RMASK 0x1ff +#define MLXBF_TMFIFO_TX_CTL__MAX_ENTRIES_MASK 0x1ff00000000ULL
GENMASK()/GENMASK_ULL()
Updated in v10.
Quoted 5 lines
drivers/platform/mellanox/mlxbf-tmfifo-regs.h line 47
Quoted 3 lines
drivers/platform/mellanox/mlxbf-tmfifo-regs.h new file +2
-0+#define MLXBF_TMFIFO_RX_STS__COUNT_RMASK 0x1ff +#define MLXBF_TMFIFO_RX_STS__COUNT_MASK 0x1ff
GENMASK()
Updated in v10.
Quoted 11 lines
drivers/platform/mellanox/mlxbf-tmfifo-regs.h line 65
Quoted 9 lines
drivers/platform/mellanox/mlxbf-tmfifo-regs.h new file +6
-0+#define MLXBF_TMFIFO_RX_CTL__LWM_RMASK 0xff +#define MLXBF_TMFIFO_RX_CTL__LWM_MASK 0xff +#define MLXBF_TMFIFO_RX_CTL__HWM_RMASK 0xff +#define MLXBF_TMFIFO_RX_CTL__HWM_MASK 0xff00 +#define MLXBF_TMFIFO_RX_CTL__MAX_ENTRIES_RMASK 0x1ff +#define MLXBF_TMFIFO_RX_CTL__MAX_ENTRIES_MASK 0x1ff00000000ULLDitto.
Updated in v10.
Quoted 21 lines
Quoted 21 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +20
-0+#include <linux/acpi.h> +#include <linux/byteorder/generic.h> +#include <linux/bitfield.h> +#include <linux/cache.h> +#include <linux/device.h> +#include <linux/dma-mapping.h> +#include <linux/efi.h> +#include <linux/io.h> +#include <linux/interrupt.h> +#include <linux/irq.h> +#include <linux/kernel.h> +#include <linux/math64.h> +#include <linux/module.h> +#include <linux/moduleparam.h> +#include <linux/mutex.h> +#include <linux/platform_device.h> +#include <linux/resource.h> +#include <linux/slab.h> +#include <linux/types.h> +#include <linux/version.h>
Quoted 8 lines
drivers/platform/mellanox/mlxbf-tmfifo.c line 33
Quoted 6 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +6
-0+#include <linux/virtio.h> +#include <linux/virtio_config.h> +#include <linux/virtio_console.h> +#include <linux/virtio_ids.h> +#include <linux/virtio_net.h> +#include <linux/virtio_ring.h> Do you need all of them?
Cleaned up quite a few and updated in v10.
Quoted 4 lines
Quoted 2 lines
+#define
MLXBF_TMFIFO_VRING_SIZE1024
SZ_1K?
Updated in v10.
Quoted 5 lines
drivers/platform/mellanox/mlxbf-tmfifo.c line 41
Quoted 3 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +2
-0+/* Console Tx buffer size. */ +#define MLXBF_TMFIFO_CONS_TX_BUF_SIZE (32 * 1024)
SZ_32K?
Updated in v10.
Quoted 7 lines
drivers/platform/mellanox/mlxbf-tmfifo.c line 50
Quoted 5 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +3
-0+/* House-keeping timer interval. */ +static int mlxbf_tmfifo_timer_interval =HZ /10 ; +/* Global lock. */ Noise. Either explain what it protects, or remove.
Removed in v10.
Quoted 6 lines
drivers/platform/mellanox/mlxbf-tmfifo.c line 65
Quoted 4 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +2
-0+static DEFINE_MUTEX (mlxbf_tmfifo_lock); +/* Struct declaration. */ Noise.
Removed in v10.
Quoted 12 lines
Quoted 12 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +11
-0+/* Structure to maintain the ring state. */ +struct mlxbf_tmfifo_vring { +void *va;/* virtual address */ +dma_addr_t dma;/* dma address */ +struct virtqueue *vq;/* virtqueue pointer */ +struct vring_desc *desc;/* current desc */ +struct vring_desc *desc_head;/* current desc head */ +int cur_len;/* processed len in current desc */ +int rem_len;/* remaining length to be processed */ +int size;/* vring size */ +int align;/* vring alignment */
Quoted 8 lines
drivers/platform/mellanox/mlxbf-tmfifo.c line 84
Quoted 6 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +6
-0+int id;/* vring id */ +int vdev_id;/* TMFIFO_VDEV_xxx */ +u32 pkt_len;/* packet total length */ +u16 next_avail;/* next avail desc id */ +struct mlxbf_tmfifo *fifo;/* pointer back to the tmfifo */ +};Perhaps kernel-doc?
Updated in v10.
Quoted 21 lines
drivers/platform/mellanox/mlxbf-tmfifo.c line 92
Quoted 8 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +7
-0+/* Interrupt types. */ +enum { +MLXBF_TM_RX_LWM_IRQ ,/* Rx low water mark irq */ +MLXBF_TM_RX_HWM_IRQ ,/* Rx high water mark irq */ +MLXBF_TM_TX_LWM_IRQ ,/* Tx low water mark irq */ +MLXBF_TM_TX_HWM_IRQ ,/* Tx high water mark irq */ +MLXBF_TM_IRQ_CNT CNT...
drivers/platform/mellanox/mlxbf-tmfifo.c line 99
Quoted 7 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +7
-0+}; + +/* Ring types (Rx & Tx). */ +enum { +MLXBF_TMFIFO_VRING_RX ,/* Rx ring */ +MLXBF_TMFIFO_VRING_TX ,/* Tx ring */ +MLXBF_TMFIFO_VRING_NUM ...NUM
Quoted 1 line
Perhaps one style for max numbers?
Updated in v10.
Quoted 15 lines
drivers/platform/mellanox/mlxbf-tmfifo.c line 110
Quoted 13 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +11
-0+}; + +/* Structure for the virtual device. */ +struct mlxbf_tmfifo_vdev { +struct virtio_device vdev;/* virtual device */ +u8 status; +u64 features; +union {/* virtio config space */ +struct virtio_console_config cons; +struct virtio_net_config net; + } config;Describe, which field allows to distinguish what type of the data is in a union.
Added comments in v10.
Quoted 8 lines
drivers/platform/mellanox/mlxbf-tmfifo.c line 115
Quoted 6 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +5
-0+struct mlxbf_tmfifo_vring vrings[MLXBF_TMFIFO_VRING_NUM ]; +u8 *tx_buf;/* tx buffer */ +u32 tx_head;/* tx buffer head */ +u32 tx_tail;/* tx buffer tail */ +};kernel-doc?
Updated in v10
Quoted 9 lines
drivers/platform/mellanox/mlxbf-tmfifo.c line 122
Quoted 7 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +6
-0+/* Structure of the interrupt information. */ +struct mlxbf_tmfifo_irq_info { +struct mlxbf_tmfifo *fifo;/* tmfifo structure */ +int irq;/* interrupt number */ +int index;/* array index */ +};Ditto.
Updated in v10
Quoted 13 lines
Quoted 13 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +12
-0+ +/* Structure of the TmFifo information. */ +struct mlxbf_tmfifo { +struct mlxbf_tmfifo_vdev *vdev[MLXBF_TMFIFO_VDEV_MAX ];/* devices */ +struct platform_device *pdev;/* platform device */ +struct mutex lock;/* fifo lock */ +void __iomem *rx_base;/* mapped register base */ +void __iomem *tx_base;/* mapped register base */ +int tx_fifo_size;/* number of entries of the Tx FIFO */ +int rx_fifo_size;/* number of entries of the Rx FIFO */ +unsigned long pend_events;/* pending bits for deferred process */ +struct mlxbf_tmfifo_irq_info irq_info[MLXBF_TM_IRQ_CNT ];/* irq info */
Quoted 8 lines
drivers/platform/mellanox/mlxbf-tmfifo.c line 140
Quoted 6 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +6
-0+struct work_struct work;/* work struct for deferred process */ +struct timer_list timer;/* keepalive timer */ +struct mlxbf_tmfifo_vring *vring[2 ];/* current Tx/Rx ring */ +bool is_ready;/* ready flag */ +spinlock_t spin_lock;/* spin lock */ +};Ditto.
Updated in v10
Quoted 4 lines
Quoted 2 lines
+/* Use a union struction for 64-bit little/big endian. */
What does this mean?
Updated in v10 with the following comments to explain it.
/*
* It's expected to send 64-bit little-endian value (__le64) into the TmFifo.
* readq() and writeq() expect u64 instead. A union structure is used here
* to workaround the explicit casting usage like writeq(*(u64 *)&data_le). */
Quoted 15 lines
drivers/platform/mellanox/mlxbf-tmfifo.c line 154
Quoted 13 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +12
-0+union mlxbf_tmfifo_data_64bit { +u64 data; +__le64 data_le; +}; + +/* Message header used to demux data in the TmFifo. */ +union mlxbf_tmfifo_msg_hdr { +struct { +u8 type;/* message type */ +__be16 len;/* payload length */ +u8 unused[5 ];/* reserved, set to 0 */ + } __packed;It's already packed. No?
It's not packed by default due to the 16-bit len. We need the '__packed' to make sure the size of the structure is 8 bytes.
Quoted 8 lines
drivers/platform/mellanox/mlxbf-tmfifo.c line 170
Quoted 6 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +4
-0+union mlxbf_tmfifo_data_64bit u;/* 64-bit data */ +}; +/* MTU setting of the virtio-net interface. */ +#define MLXBF_TMFIFO_NET_MTU 1500Don't we have this globally defined?
Updated in v10
Quoted 7 lines
drivers/platform/mellanox/mlxbf-tmfifo.c line 178
Quoted 5 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +4
-0+/* Supported virtio-net features. */ +#define MLXBF_TMFIFO_NET_FEATURES ((1UL << VIRTIO_NET_F_MTU) | \ + (1UL << VIRTIO_NET_F_STATUS) | \ + (1UL << VIRTIO_NET_F_MAC))
BIT_UL()?
Updated in v10
Quoted 4 lines
Quoted 2 lines
+/* Function declarations. */
Noise.
Removed in v10
Quoted 4 lines
Quoted 2 lines
+static int
mlxbf_tmfifo_remove(struct platform_device *pdev);Why do you need forward declaration for this?
Removed in v10
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c line 191
Quoted 8 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +7
-0+/* Return the consumed Tx buffer space. */ +static int mlxbf_tmfifo_vdev_tx_buf_len (struct mlxbf_tmfifo_vdev *vdev) +{ +return ((vdev->tx_tail >= vdev->tx_head) ? + (vdev->tx_tail - vdev->tx_head) : + (MLXBF_TMFIFO_CONS_TX_BUF_SIZE - vdev->tx_head + + vdev->tx_tail));Split this for better reading.
Updated in v10
Quoted 11 lines
drivers/platform/mellanox/mlxbf-tmfifo.c line 198
Quoted 8 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +7
-0+} + +/* Return the available Tx buffer space. */ +static int mlxbf_tmfifo_vdev_tx_buf_avail (struct mlxbf_tmfifo_vdev *vdev) +{ +return (MLXBF_TMFIFO_CONS_TX_BUF_RSV_SIZE - +mlxbf_tmfifo_vdev_tx_buf_len (vdev));Redundant parens.
Moreover, you might consider temporary variable for better reading.
Updated in v10
Quoted 30 lines
Quoted 29 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +28
-0+} + +/* Update Rx/Tx buffer index pointer. */ +static void mlxbf_tmfifo_vdev_tx_buf_index_inc (u32 *index,u32 len) +{ + *index += len; +if (*index >=MLXBF_TMFIFO_CONS_TX_BUF_SIZE ) + *index -=MLXBF_TMFIFO_CONS_TX_BUF_SIZE ; +} + +/* Allocate vrings for the fifo. */ +static int mlxbf_tmfifo_alloc_vrings (struct mlxbf_tmfifo *fifo, +struct mlxbf_tmfifo_vdev *tm_vdev, +int vdev_id) +{ +struct mlxbf_tmfifo_vring *vring; +dma_addr_t dma; +int i, size; +void *va; + +for (i =0 ; i <ARRAY_SIZE (tm_vdev->vrings); i++) { + vring = &tm_vdev->vrings[i]; + vring->fifo = fifo; + vring->size =MLXBF_TMFIFO_VRING_SIZE ; + vring->align =SMP_CACHE_BYTES ; + vring->id = i; + vring->vdev_id = vdev_id; +
Quoted 4 lines
Quoted 1 line
+ size =
PAGE_ALIGN(vring_size(vring->size, vring->align));Why do you need this?
dma_alloc_coherent()allocates memory on page granularity anyway.
Updated in v10
Quoted 8 lines
drivers/platform/mellanox/mlxbf-tmfifo.c line 231
Quoted 6 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +4
-0+ va =dma_alloc_coherent (tm_vdev->vdev.dev.parent, size, &dma, +GFP_KERNEL ); +if (!va) { + dev_err(tm_vdev->vdev.dev.parent,Would be much easy if you have temporary variable for this device.
Updated in v10
Quoted 12 lines
Quoted 11 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +10
-0+ "dma_alloc_coherent failed\n"); +return -ENOMEM ; + } + + vring->va = va; + vring->dma = dma; + } + +return 0 ; +}
Quoted 9 lines
drivers/platform/mellanox/mlxbf-tmfifo.c line 285
Quoted 6 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +6
-0+/* Interrupt handler. */ +static irqreturn_t mlxbf_tmfifo_irq_handler (int irq,void *arg) +{ +struct mlxbf_tmfifo_irq_info *irq_info; + + irq_info = (struct mlxbf_tmfifo_irq_info *)arg;Useless casting.
Assignment can be done in definition block.
Updated in v10
Quoted 10 lines
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +9
-0+if (irq_info->index <MLXBF_TM_IRQ_CNT && + !test_and_set_bit (irq_info->index, &irq_info->fifo->pend_events)) +schedule_work (&irq_info->fifo->work); + +return IRQ_HANDLED ; +} + +/* Get the next packet descriptor from the vring. */ +static struct vring_desc *mlxbf_tmfifo_get_next_desc (struct virtqueue *vq)
Quoted 8 lines
drivers/platform/mellanox/mlxbf-tmfifo.c line 301
Quoted 6 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +6
-0+{ +struct mlxbf_tmfifo_vring *vring; +unsigned int idx, head; +struct vring *vr; + + vr = (struct vring *)virtqueue_get_vring (vq);Return type is different? Is it safe to cast? Why?
It's 'const' casting. Fixed in v10 to use 'const struct vring *vr' instead.
Quoted 5 lines
Review
Quoted 3 lines
(quoted diff) +2
-0+ if (!vr) + return NULL;+ blank line
Updated in v10
Quoted 4 lines
Quoted 2 lines
+ vring = (struct
mlxbf_tmfifo_vring*)vq->priv;Do you need explicit casting?
Updated in v10
Quoted 5 lines
Review
Quoted 3 lines
(quoted diff) +2
-0+ if (vring->next_avail == virtio16_to_cpu(vq->vdev, vr->avail->idx)) + return NULL;+blank line
Updated in v10
Quoted 21 lines
Quoted 21 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +20
-0+ idx = vring->next_avail % vr->num; + head =virtio16_to_cpu (vq->vdev, vr->avail->ring[idx]); +if (WARN_ON (head >= vr->num)) +return NULL ; + vring->next_avail++; + +return &vr->desc[head]; +} + +/* Release virtio descriptor. */ +static void mlxbf_tmfifo_release_desc (struct virtio_device *vdev, +struct vring *vr,struct vring_desc *desc, +u32 len) +{ +u16 idx, vr_idx; + + vr_idx =virtio16_to_cpu (vdev, vr->used->idx); + idx = vr_idx % vr->num; + vr->used->ring[idx].id =cpu_to_virtio32 (vdev, desc - vr->desc); + vr->used->ring[idx].len =cpu_to_virtio32 (vdev, len);
Quoted 8 lines
drivers/platform/mellanox/mlxbf-tmfifo.c line 332
Quoted 6 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +6
-0+ +/* Virtio could poll and check the 'idx' to decide +* whether the desc is done or not. Add a memory +* barrier here to make sure the update above completes +* before updating the idx. +*/ Multi-line comment style is broken.
Updated in v10
Quoted 5 lines
Quoted 4 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +3
-0+mb (); + vr->used->idx =cpu_to_virtio16 (vdev, vr_idx +1 ); +}
Quoted 8 lines
drivers/platform/mellanox/mlxbf-tmfifo.c line 412
Quoted 6 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +5
-0+/* House-keeping timer. */ +static void mlxbf_tmfifo_timer (struct timer_list *arg) +{ +struct mlxbf_tmfifo *fifo; + fifo = container_of(arg, struct mlxbf_tmfifo, timer);Can't be done in the definition block?
Updated in v10
Quoted 8 lines
drivers/platform/mellanox/mlxbf-tmfifo.c line 418
Quoted 6 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +5
-0+/* +* Wake up the work handler to poll the Rx FIFO in case interrupt +* missing or any leftover bytes stuck in the FIFO. +*/ +test_and_set_bit (MLXBF_TM_RX_HWM_IRQ , &fifo->pend_events);How do you utilize test results?
Fixed in v10
Quoted 9 lines
drivers/platform/mellanox/mlxbf-tmfifo.c line 424
Quoted 7 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +6
-0+ +/* +* Wake up Tx handler in case virtio has queued too many packets +* and are waiting for buffer return. +*/ +test_and_set_bit (MLXBF_TM_TX_LWM_IRQ , &fifo->pend_events);Ditto.
Fixed in v10
Quoted 7 lines
Quoted 6 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +5
-0+ +schedule_work (&fifo->work); + +mod_timer (&fifo->timer, jiffies + mlxbf_tmfifo_timer_interval); +}
Quoted 5 lines
drivers/platform/mellanox/mlxbf-tmfifo.c line 542
Quoted 3 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +3
-0+/* Adjust the size to available space. */ +if (size +sizeof (hdr) > avail *sizeof (u64)) + size = avail *sizeof (u64) -sizeof (hdr);Can avail be 0?
It won't be 0. There is a check at the beginning of this function. The function will return is avail is too small.
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c line 549
Quoted 8 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +6
-0+/* Write header. */ + hdr.u.data =0 ; + hdr.type =VIRTIO_ID_CONSOLE ; + hdr.len =htons (size); + hdr.u.data_le =cpu_to_le64 (hdr.u.data); +writeq (hdr.u.data, fifo->tx_base +MLXBF_TMFIFO_TX_DATA );So, this one is not protected anyhow? Potential race condition?
The spin-lock is to protect reference to the ‘tx_buf’, not the read/write of the fifo. The fifo read/write is protected by mutex. Added a comment in v10 to avoid such confusion.
Quoted 32 lines
Quoted 31 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +30
-0+ +spin_lock_irqsave (&fifo->spin_lock, flags); + +while (size >0 ) { + addr = cons->tx_buf + cons->tx_head; + +if (cons->tx_head +sizeof (u64) <= +MLXBF_TMFIFO_CONS_TX_BUF_SIZE ) { +memcpy (&data, addr,sizeof (u64)); + }else { + partial =MLXBF_TMFIFO_CONS_TX_BUF_SIZE - cons->tx_head; +memcpy (&data, addr, partial); +memcpy ((u8 *)&data + partial, cons->tx_buf, +sizeof (u64) - partial); + } +writeq (data, fifo->tx_base +MLXBF_TMFIFO_TX_DATA ); + +if (size >=sizeof (u64)) { +mlxbf_tmfifo_vdev_tx_buf_index_inc (&cons->tx_head, +sizeof (u64)); + size -=sizeof (u64); + }else { +mlxbf_tmfifo_vdev_tx_buf_index_inc (&cons->tx_head, + size); + size =0 ; + } + } + +spin_unlock_irqrestore (&fifo->spin_lock, flags); +}
Quoted 6 lines
drivers/platform/mellanox/mlxbf-tmfifo.c line 754
Quoted 4 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +4
-0+/* Rx/Tx one word (8 bytes) if not done. */ +if (vring->cur_len != len) +mlxbf_tmfifo_rxtx_word (fifo, vdev, vring, desc, is_rx, avail, + len);In such case better to keep it in one line.
Updated in v10
Quoted 16 lines
Quoted 15 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +14
-0+/* Get the array of feature bits for this device. */ +static u64 mlxbf_tmfifo_virtio_get_features (struct virtio_device *vdev) +{ +struct mlxbf_tmfifo_vdev *tm_vdev; + + tm_vdev = container_of(vdev, struct mlxbf_tmfifo_vdev, vdev); +return tm_vdev->features; +} + +/* Confirm device features to use. */ +static int mlxbf_tmfifo_virtio_finalize_features (struct virtio_device *vdev) +{ +struct mlxbf_tmfifo_vdev *tm_vdev; +
Quoted 5 lines
Quoted 1 line
+
tm_vdev=container_of(vdev, struct mlxbf_tmfifo_vdev, vdev);This is candidate to be a macro
#define
mlxbt_vdev_to_tmfifo(...)...
Updated in v10
Quoted 43 lines
Quoted 42 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +40
-0+ tm_vdev->features = vdev->features; + +return 0 ; +} +/* Create vdev type in a tmfifo. */ +static int mlxbf_tmfifo_create_vdev (struct device *dev, +struct mlxbf_tmfifo *fifo, +int vdev_id,u64 features, +void *config,u32 size) +{ +struct mlxbf_tmfifo_vdev *tm_vdev; +int ret =0 ; + +mutex_lock (&fifo->lock); + + tm_vdev = fifo->vdev[vdev_id]; +if (tm_vdev) { +dev_err (dev,"vdev %d already exists\n" , vdev_id); + ret = -EEXIST ; + goto fail; + } + + tm_vdev =devm_kzalloc (dev,sizeof (*tm_vdev),GFP_KERNEL ); +if (!tm_vdev) { + ret = -ENOMEM ; + goto fail; + } + + tm_vdev->vdev.id.device = vdev_id; + tm_vdev->vdev.config = &mlxbf_tmfifo_virtio_config_ops; + tm_vdev->vdev.dev.parent = &fifo->pdev->dev; + tm_vdev->features = features; +if (config) +memcpy (&tm_vdev->config, config, size); +if (mlxbf_tmfifo_alloc_vrings (fifo, tm_vdev, vdev_id)) { +dev_err (dev,"unable to allocate vring\n" ); + ret = -ENOMEM ; + goto fail; + } +if (vdev_id ==VIRTIO_ID_CONSOLE )
Quoted 5 lines
drivers/platform/mellanox/mlxbf-tmfifo.c line 1128
Quoted 3 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +3
-0+ tm_vdev->tx_buf =devm_kmalloc (dev, +MLXBF_TMFIFO_CONS_TX_BUF_SIZE , +GFP_KERNEL );Are you sure
devm_suits here?
I think it's ok. The tx_buf is normal memory for output buffer. It's running on SoC and the TmFifo is always there. So it's allocated at init and supposed to be released on module remove.
Quoted 21 lines
Quoted 20 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +19
-0+ fifo->vdev[vdev_id] = tm_vdev; + +/* Register the virtio device. */ + ret =register_virtio_device (&tm_vdev->vdev); +if (ret) { +dev_err (&fifo->pdev->dev,"register_virtio_device failed\n" ); + goto register_fail; + } + +mutex_unlock (&fifo->lock); +return 0 ; + +register_fail: +mlxbf_tmfifo_free_vrings (fifo, vdev_id); + fifo->vdev[vdev_id] =NULL ; +fail: +mutex_unlock (&fifo->lock); +return ret; +}
Quoted 16 lines
Quoted 4 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +4
-0+/* Read the configured network MAC address from efi variable. */ +static void mlxbf_tmfifo_get_cfg_mac (u8 *mac) +{ +efi_guid_t guid =EFI_GLOBAL_VARIABLE_GUID ;drivers/platform/mellanox/mlxbf-tmfifo.c line 1182
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +10
-0+efi_status_t status; +unsigned long size; +u8 buf[6 ]; + + size =sizeof (buf); + status = efi.get_variable (mlxbf_tmfifo_efi_name, &guid,NULL , &size, + buf); +if (status ==EFI_SUCCESS && size ==sizeof (buf)) +memcpy (mac, buf,sizeof (buf)); +}Shouldn't be rather helper in EFI lib in kernel?
It's a little strange that there seems no such existing lib function. I searched a little bit in kernel tree like below, they seem using the efi.get_variable() approach.arch/x86/kernel/ima_arch.cdrivers/scsi/isci/probe_roms.c security/integrity/platform_certs/load_uefi.c
Quoted 67 lines
Quoted 56 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +52
-0+/* Probe the TMFIFO. */ +static int mlxbf_tmfifo_probe (struct platform_device *pdev) +{ +struct virtio_net_config net_config; +struct resource *rx_res, *tx_res; +struct mlxbf_tmfifo *fifo; +int i, ret; + +/* Get the resource of the Rx FIFO. */ + rx_res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +if (!rx_res) +return -ENODEV ; + +/* Get the resource of the Tx FIFO. */ + tx_res =platform_get_resource (pdev,IORESOURCE_MEM ,1 ); +if (!tx_res) +return -ENODEV ; + +if (!devm_request_mem_region (&pdev->dev, rx_res->start, +resource_size (rx_res),"bf-tmfifo" )) +return -EBUSY ; + +if (!devm_request_mem_region (&pdev->dev, tx_res->start, +resource_size (tx_res),"bf-tmfifo" )) +return -EBUSY ; + + fifo =devm_kzalloc (&pdev->dev,sizeof (*fifo),GFP_KERNEL ); +if (!fifo) +return -ENOMEM ; + + fifo->pdev = pdev; +platform_set_drvdata (pdev, fifo); + +spin_lock_init (&fifo->spin_lock); +INIT_WORK (&fifo->work, mlxbf_tmfifo_work_handler); + +timer_setup (&fifo->timer, mlxbf_tmfifo_timer,0 ); + +for (i =0 ; i <MLXBF_TM_IRQ_CNT ; i++) { + fifo->irq_info[i].index = i; + fifo->irq_info[i].fifo = fifo; + fifo->irq_info[i].irq =platform_get_irq (pdev, i); + ret =devm_request_irq (&pdev->dev, fifo->irq_info[i].irq, + mlxbf_tmfifo_irq_handler,0 , +"tmfifo" , &fifo->irq_info[i]); +if (ret) { +dev_err (&pdev->dev,"devm_request_irq failed\n" ); + fifo->irq_info[i].irq =0 ; +return ret; + } + } +drivers/platform/mellanox/mlxbf-tmfifo.c line 1295
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +9
-0+ fifo->rx_base =devm_ioremap (&pdev->dev, rx_res->start, +resource_size (rx_res)); +if (!fifo->rx_base) +return -ENOMEM ; + + fifo->tx_base =devm_ioremap (&pdev->dev, tx_res->start, +resource_size (tx_res)); +if (!fifo->tx_base) +return -ENOMEM ;
Quoted 2 lines
Switch to
devm_ioremap_resource().
However, I think you probably needmemremap().
Updated in v10 to use devm_ioremap_resource().
The map is just for several registers which is not meant to be cache-able. Probably devm_ioremap_nocache() might make more sense? I checked arm64/include/asm/io.h, looks like ioremap/ioremap_nocache/ioremap_wt are defined the same thing.
Quoted 4 lines
Quoted 2 lines
+
mutex_init(&fifo->lock);Isn't too late for initializing this one?
It won't cause problem here due to the 'is_ready' flag, but definitely better to move it ahead. Updated in v10.
Quoted 11 lines
drivers/platform/mellanox/mlxbf-tmfifo.c line 1334
Quoted 9 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +6
-0+/* Device remove function. */ +static int mlxbf_tmfifo_remove (struct platform_device *pdev) +{ +struct mlxbf_tmfifo *fifo =platform_get_drvdata (pdev); + +if (fifo)How is it possible to be not true?
Updated in v10. Removed.
Quoted 7 lines
drivers/platform/mellanox/mlxbf-tmfifo.c line 1337
Quoted 5 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +3
-0+mlxbf_tmfifo_cleanup (fifo); + +platform_set_drvdata (pdev,NULL );Redundant.
Updated in v10. Removed.
Quoted 8 lines
drivers/platform/mellanox/mlxbf-tmfifo.c line 1360
Quoted 6 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +4
-0+ +return 0 ; +} +MODULE_LICENSE ("GPL" );Is it correct?
Fixed in v10 and updated to MODULE_LICENSE("GPL v2");
Quoted 4 lines
--
With Best Regards,
Andy Shevchenko
PATCH v10 1/1 platform/mellanox: Add TmFifo driver for Mellanox BlueField Soc
In reply to Liming SunThis commit adds the TmFifo platform driver for Mellanox BlueField Soc. TmFifo is a shared FIFO which enables external host machine to exchange data with the SoC via USB or PCIe. The driver is based on virtio framework and has console and network access enabled.
---v9->v10:
Fixes for comments from Andy:
- Use devm_ioremap_resource() instead of devm_ioremap().
- Use kernel-doc comments.
- Keep Makefile contents sorted.
- Use same fixed format for offsets.
- Use SZ_1K/SZ_32K instead of 1024/23*1024.
- Remove unnecessary comments.
- Use one style for max numbers.
- More comments for mlxbf_tmfifo_vdev and mlxbf_tmfifo_data_64bit.
- Use globally defined MTU instead of new definition.
- Remove forward declaration of mlxbf_tmfifo_remove().
- Remove PAGE_ALIGN() for dma_alloc_coherent)().
- Remove the cast of "struct vring *".
- Check return result of test_and_set_bit().
- Add a macro mlxbt_vdev_to_tmfifo().
- Several other minor coding style comments.
Comment not applied:
- "Shouldn't be rather helper in EFI lib in kernel" Looks like efi.get_variable() is the way I found in the kernel tree.
- "this one is not protected anyhow? Potential race condition" In mlxbf_tmfifo_console_tx(), the spin-lock is used to protect the 'tx_buf' only, not the FIFO writes. So there is no race condition.
- "Is __packed needed in mlxbf_tmfifo_msg_hdr".
Yes, it is needed to make sure the structure is 8 bytes.
Fixes for comments from Vadim:
- Use tab in mlxbf-tmfifo-regs.h
- Use kernel-doc comments for struct mlxbf_tmfifo_msg_hdr and mlxbf_tmfifo_irq_info as well.
- Use _MAX instead of _CNT in the macro definition to be consistent.
- Fix the MODULE_LICENSE.
- Use BIT_ULL() instead of BIT().
- Remove argument of 'avail' for mlxbf_tmfifo_rxtx_header() and mlxbf_tmfifo_rxtx_word()
- Revise logic in mlxbf_tmfifo_rxtx_one_desc() to remove the WARN_ON().
- Change "union mlxbf_tmfifo_u64 u" to "union mlxbf_tmfifo_u64 buf" in mlxbf_tmfifo_rxtx_word().
- Change date type of vring_change from 'int' to 'bool'.
- Remove the blank lines after Signed-off.
- Don’t use declaration in the middle.
- Make the network header initialization in some more elegant way.
- Change label done to mlxbf_tmfifo_desc_done.
- Remove some unnecessary comments, and several other misc coding style comments.
- Simplify code logic in mlxbf_tmfifo_virtio_notify() New changes by Liming:
- Simplify the Rx/Tx function arguments to make it more readable.v8->v9:
Fixes for comments from Andy:
- Use modern devm_xxx() API instead.
Fixes for comments from Vadim:
- Split the Rx/Tx function into smaller funcitons.
- File name, copyright information.
- Function and variable name conversion.
- Local variable and indent coding styles.
- Remove unnecessary 'inline' declarations.
- Use devm_xxx() APIs.
- Move the efi_char16_t MAC address definition to global.
- Fix warnings reported by 'checkpatch --strict'.
- Fix warnings reported by 'make CF="-D__CHECK_ENDIAN__"'.
- Change select VIRTIO_xxx to depends on VIRTIO_ in Kconfig.
- Merge mlxbf_tmfifo_vdev_tx_buf_push() and mlxbf_tmfifo_vdev_tx_buf_pop().
- Add union to avoid casting between __le64 and u64.
- Several other misc coding style comments.
New changes by Liming:
- Removed the DT binding documentation since only ACPI is supported for now by UEFI on the SoC.
v8: Re-submit under drivers/platform/mellanox for the target-side
platform driver only.
v7: Added host side drivers into the same patch set.
v5~v6: Coding style fix.
v1~v4: Initial version for directory drivers/soc/mellanox.
--- drivers/platform/mellanox/Kconfig | 12 +- drivers/platform/mellanox/Makefile | 1 + drivers/platform/mellanox/mlxbf-tmfifo-regs.h | 63 ++ drivers/platform/mellanox/mlxbf-tmfifo.c | 1342 +++++++++++++++++++++++++ 4 files changed, 1417 insertions(+), 1 deletion(-) create mode 100644 drivers/platform/mellanox/mlxbf-tmfifo-regs.h create mode 100644 drivers/platform/mellanox/mlxbf-tmfifo.c
drivers/platform/mellanox/Kconfig +11 -1
@@ -5,7 +5,7 @@ menuconfig MELLANOX_PLATFORM bool "Platform support for Mellanox hardware" - depends on X86 || ARM || COMPILE_TEST + depends on X86 || ARM || ARM64 || COMPILE_TEST ---help--- Say Y here to get to see options for platform support for Mellanox systems. This option alone does not add any kernel code.
@@ -34,4 +34,14 @@ config MLXREG_IO to system resets operation, system reset causes monitoring and some kinds of mux selection. +config MLXBF_TMFIFO + tristate "Mellanox BlueField SoC TmFifo platform driver" + depends on ARM64 + depends on ACPI + depends on VIRTIO_CONSOLE && VIRTIO_NET + help + Say y here to enable TmFifo support. The TmFifo driver provides + platform driver support for the TmFifo which supports console + and networking based on the virtio framework. + endif # MELLANOX_PLATFORM
drivers/platform/mellanox/Makefile +1 -0
@@ -3,5 +3,6 @@ # Makefile for linux/drivers/platform/mellanox # Mellanox Platform-Specific Drivers # +obj-$(CONFIG_MLXBF_TMFIFO) += mlxbf-tmfifo.o obj-$(CONFIG_MLXREG_HOTPLUG) += mlxreg-hotplug.o obj-$(CONFIG_MLXREG_IO) += mlxreg-io.o
drivers/platform/mellanox/mlxbf-tmfifo-regs.h new file +63 -0
63 lines not on this page · raw message
drivers/platform/mellanox/mlxbf-tmfifo.c new file +1342 -0
1,342 lines not on this page · raw message
Signature · 1 line
1.8.3.1
Re: [PATCH v10] platform/mellanox: Add TmFifo driver for Mellanox BlueField Soc
Quoted 5 lines · Liming Sun
This commit adds the TmFifo platform driver for Mellanox BlueField Soc. TmFifo is a shared FIFO which enables external host machine to exchange data with the SoC via USB or PCIe. The driver is based on virtio framework and has console and network access enabled.
Thank you for an update.
Unfortunately more work is needed. My comments below.
Quoted 13 lines
drivers/platform/mellanox/mlxbf-tmfifo-regs.h new file +9
-0+#define MLXBF_TMFIFO_TX_STS__COUNT_RMASK GENMASK(8, 0) +#define MLXBF_TMFIFO_TX_STS__COUNT_MASK GENMASK(8, 0) +#define MLXBF_TMFIFO_TX_CTL__LWM_RMASK GENMASK(7, 0) +#define MLXBF_TMFIFO_TX_CTL__LWM_MASK GENMASK(7, 0) +#define MLXBF_TMFIFO_TX_CTL__HWM_RMASK GENMASK(7, 0) +#define MLXBF_TMFIFO_TX_CTL__HWM_MASK GENMASK(15, 8) +#define MLXBF_TMFIFO_TX_CTL__MAX_ENTRIES_RMASK GENMASK(8, 0) +#define MLXBF_TMFIFO_TX_CTL__MAX_ENTRIES_MASK GENMASK_ULL(40, 32) +#define MLXBF_TMFIFO_RX_STS__COUNT_RMASK GENMASK(8, 0)
drivers/platform/mellanox/mlxbf-tmfifo-regs.h line 61
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo-regs.h new file +7
-0+#define MLXBF_TMFIFO_RX_STS__COUNT_MASK GENMASK(8, 0) +#define MLXBF_TMFIFO_RX_CTL__LWM_RMASK GENMASK(7, 0) +#define MLXBF_TMFIFO_RX_CTL__LWM_MASK GENMASK(7, 0) +#define MLXBF_TMFIFO_RX_CTL__HWM_RMASK GENMASK(7, 0) +#define MLXBF_TMFIFO_RX_CTL__HWM_MASK GENMASK(15, 8) +#define MLXBF_TMFIFO_RX_CTL__MAX_ENTRIES_RMASK GENMASK(8, 0) +#define MLXBF_TMFIFO_RX_CTL__MAX_ENTRIES_MASK GENMASK_ULL(40, 32)
Since two of them have _ULL suffix I'm wondering if you have checked for side effects on the rest, i.e. if you operate with 64-bit variable and use something like ~MLXBF_TMFIFO_RX_CTL__MAX_ENTRIES_RMASK, it may give you interesting results.
drivers/platform/mellanox/mlxbf-tmfifo.c line 184
Quoted 11 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +10
-0+#define MLXBF_TMFIFO_TIMER_INTERVAL (HZ / 10) +/** +* mlxbf_tmfifo_u64 - Union of 64-bit data +* @data - 64-bit data in host byte order +* @data_le - 64-bit data in little-endian byte order +* +* It's expected to send 64-bit little-endian value (__le64) into the TmFifo. +* readq() and writeq() expect u64 instead. A union structure is used here +* to workaround the explicit casting usage like writeq(*(u64 *)&data_le). +*/
How do you know what readq()/writeq() does with the data? Is it on all architectures?
How the endianess conversion affects the actual data?
Quoted 5 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +4
-0+union mlxbf_tmfifo_u64 { +u64 data; +__le64 data_le; +};
drivers/platform/mellanox/mlxbf-tmfifo.c line 225
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +9
-0+/* +* Default MAC. +* This MAC address will be read from EFI persistent variable if configured. +* It can also be reconfigured with standard Linux tools. +*/ +static u8 mlxbf_tmfifo_net_default_mac[6 ] = { +0x00 ,0x1A ,0xCA ,0xFF ,0xFF ,0x01 }; +#define mlxbf_vdev_to_tmfifo (dev) \ + container_of(dev, struct mlxbf_tmfifo_vdev, vdev)
One line?
drivers/platform/mellanox/mlxbf-tmfifo.c line 241
Quoted 12 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +12
-0+/* Return the consumed Tx buffer space. */ +static int mlxbf_tmfifo_vdev_tx_buf_len (struct mlxbf_tmfifo_vdev *tm_vdev) +{ +int len; + +if (tm_vdev->tx_tail >= tm_vdev->tx_head) + len = tm_vdev->tx_tail - tm_vdev->tx_head; +else + len =MLXBF_TMFIFO_CONS_TX_BUF_SIZE - tm_vdev->tx_head + + tm_vdev->tx_tail; +return len; +}
Is this custom implementation of some kind of circ_buf?
Quoted 14 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +14
-0+/* Allocate vrings for the fifo. */ +static int mlxbf_tmfifo_alloc_vrings (struct mlxbf_tmfifo *fifo, +struct mlxbf_tmfifo_vdev *tm_vdev) +{ +struct mlxbf_tmfifo_vring *vring; +struct device *dev; +dma_addr_t dma; +int i, size; +void *va; + +for (i =0 ; i <ARRAY_SIZE (tm_vdev->vrings); i++) { + vring = &tm_vdev->vrings[i]; + vring->fifo = fifo; + vring->num =MLXBF_TMFIFO_VRING_SIZE ;
drivers/platform/mellanox/mlxbf-tmfifo.c line 284
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +9
-0+ vring->align =SMP_CACHE_BYTES ; + vring->index = i; + vring->vdev_id = tm_vdev->vdev.id.device; + dev = &tm_vdev->vdev.dev; + + size =vring_size (vring->num, vring->align); + va =dma_alloc_coherent (dev->parent, size, &dma,GFP_KERNEL ); +if (!va) { +dev_err (dev->parent,"dma_alloc_coherent failed\n" );
And how do you clean previously allocated items?
Quoted 9 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +9
-0+return -ENOMEM ; + } + + vring->va = va; + vring->dma = dma; + } + +return 0 ; +}
drivers/platform/mellanox/mlxbf-tmfifo.c line 324
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +8
-0+/* Disable interrupts of the fifo device. */ +static void mlxbf_tmfifo_disable_irqs (struct mlxbf_tmfifo *fifo) +{ +int i, irq; + +for (i =0 ; i <MLXBF_TM_MAX_IRQ ; i++) { + irq = fifo->irq_info[i].irq; +if (irq) {
I don't think this check is needed if you can guarantee that it has no staled records.
Quoted 12 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +11
-0+ fifo->irq_info[i].irq =0 ; +disable_irq (irq); + } + } +} +/* Get the number of available words in the TmFifo for sending. */ +static int mlxbf_tmfifo_get_tx_avail (struct mlxbf_tmfifo *fifo,int vdev_id) +{ +int tx_reserve; +u64 sts; +
drivers/platform/mellanox/mlxbf-tmfifo.c line 545
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +9
-0+/* Reserve some room in FIFO for console messages. */ +if (vdev_id ==VIRTIO_ID_NET ) + tx_reserve = fifo->tx_fifo_size /MLXBF_TMFIFO_RESERVE_RATIO ; +else + tx_reserve =1 ; + + sts =readq (fifo->tx_base +MLXBF_TMFIFO_TX_STS ); +return (fifo->tx_fifo_size - tx_reserve - +FIELD_GET (MLXBF_TMFIFO_TX_STS__COUNT_MASK , sts));
Redundant parens.
Moreover, consider
u32 count; // or whatever suits for FIELD_GET().
...
sts = readq(...);
count = FIELD_GET(...);
return ...;
Quoted 4 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +3
-0+} +while (size >0 ) { + addr = cons->tx_buf + cons->tx_head;
drivers/platform/mellanox/mlxbf-tmfifo.c line 595
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +9
-0+ +if (cons->tx_head +sizeof (u64) <= +MLXBF_TMFIFO_CONS_TX_BUF_SIZE ) { +memcpy (&data, addr,sizeof (u64)); + }else { + partial =MLXBF_TMFIFO_CONS_TX_BUF_SIZE - cons->tx_head; +memcpy (&data, addr, partial); +memcpy ((u8 *)&data + partial, cons->tx_buf, +sizeof (u64) - partial);
Unaligned access?!
drivers/platform/mellanox/mlxbf-tmfifo.c line 629
Quoted 4 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +3
-0+ } + buf.data =readq (fifo->rx_base +MLXBF_TMFIFO_RX_DATA ); + buf.data =le64_to_cpu (buf.data_le);
Are you sure this is correct?
How did you test this on BE architectures?
Quoted 1 line
+
tm_vdev=devm_kzalloc(dev, sizeof(*tm_vdev), GFP_KERNEL);
Is it appropriate use of devm_* ?
drivers/platform/mellanox/mlxbf-tmfifo.c line 1187
Quoted 13 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +11
-0+if (!tm_vdev) { + ret = -ENOMEM ; + goto fail; + } +/* Read the configured network MAC address from efi variable. */ +static void mlxbf_tmfifo_get_cfg_mac (u8 *mac) +{ +efi_guid_t guid =EFI_GLOBAL_VARIABLE_GUID ; +efi_status_t status; +unsigned long size; +u8 buf[6 ];
ETH_ALEN ?
drivers/platform/mellanox/mlxbf-tmfifo.c line 1189
Quoted 2 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +2
-0+ + size =sizeof (buf);
Ditto.
drivers/platform/mellanox/mlxbf-tmfifo.c line 1192
Quoted 4 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +3
-0+ status = efi.get_variable (mlxbf_tmfifo_efi_name, &guid,NULL , &size, + buf); +if (status ==EFI_SUCCESS && size ==sizeof (buf))
Ditto.
Quoted 1 line
+
memcpy(mac, buf, sizeof(buf));
ether_addr_copy().
drivers/platform/mellanox/mlxbf-tmfifo.c line 1295
Quoted 3 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +2
-0+} +memcpy (net_config.mac, mlxbf_tmfifo_net_default_mac,6 );
ether_addr_copy()...
Quoted 1 line
+
mlxbf_tmfifo_get_cfg_mac(net_config.mac);
... but actually above should be part of this function.
Signature · 2 lines
With Best Regards, Andy Shevchenko
RE: [PATCH v10] platform/mellanox: Add TmFifo driver for Mellanox BlueField Soc
Thanks Andy! Please see my response below. If no further comments, I'll try to post v11 after more testing.
Regards,
Liming
Quoted 41 lines
-----Original Message-----
From: Andy Shevchenko <[email protected]>
Sent: Tuesday, March 5, 2019 10:34 AM
To: Liming Sun <[email protected]>
Cc: David Woods <[email protected]>; Andy Shevchenko <[email protected]>; Darren Hart <[email protected]>; Vadim Pasternak <[email protected]>; Linux Kernel Mailing List <[email protected]>; Platform Driver <platform-driver- [email protected]>
Subject: Re: [PATCH v10] platform/mellanox: Add TmFifo driver for Mellanox BlueField SocQuoted 5 lines · Liming Sun
This commit adds the TmFifo platform driver for Mellanox BlueField Soc. TmFifo is a shared FIFO which enables external host machine to exchange data with the SoC via USB or PCIe. The driver is based on virtio framework and has console and network access enabled.
Thank you for an update.
Unfortunately more work is needed. My comments below.
Quoted 20 lines
drivers/platform/mellanox/mlxbf-tmfifo-regs.h new file +14
-0+#define MLXBF_TMFIFO_TX_STS__COUNT_RMASK GENMASK(8, 0) +#define MLXBF_TMFIFO_TX_STS__COUNT_MASK GENMASK(8, 0) +#define MLXBF_TMFIFO_TX_CTL__LWM_RMASK GENMASK(7, 0) +#define MLXBF_TMFIFO_TX_CTL__LWM_MASK GENMASK(7, 0) +#define MLXBF_TMFIFO_TX_CTL__HWM_RMASK GENMASK(7, 0) +#define MLXBF_TMFIFO_TX_CTL__HWM_MASK GENMASK(15, 8) +#define MLXBF_TMFIFO_TX_CTL__MAX_ENTRIES_RMASK GENMASK(8, 0) +#define MLXBF_TMFIFO_TX_CTL__MAX_ENTRIES_MASK GENMASK_ULL(40, 32) +#define MLXBF_TMFIFO_RX_STS__COUNT_RMASK GENMASK(8, 0) +#define MLXBF_TMFIFO_RX_STS__COUNT_MASK GENMASK(8, 0) +#define MLXBF_TMFIFO_RX_CTL__LWM_RMASK GENMASK(7, 0) +#define MLXBF_TMFIFO_RX_CTL__LWM_MASK GENMASK(7, 0) +#define MLXBF_TMFIFO_RX_CTL__HWM_RMASK GENMASK(7, 0) +#define MLXBF_TMFIFO_RX_CTL__HWM_MASK GENMASK(15, 8)
Quoted 7 lines
drivers/platform/mellanox/mlxbf-tmfifo-regs.h line 61
Quoted 2 lines
drivers/platform/mellanox/mlxbf-tmfifo-regs.h new file +2
-0+#define MLXBF_TMFIFO_RX_CTL__MAX_ENTRIES_RMASK GENMASK(8, 0) +#define MLXBF_TMFIFO_RX_CTL__MAX_ENTRIES_MASK GENMASK_ULL(40, 32)Since two of them have
_ULLsuffix I'm wondering if you have checked for side effects on the rest, i.e. if you operate with 64-bit variable and use something like ~MLXBF_TMFIFO_RX_CTL__MAX_ENTRIES_RMASK, it may give you interesting results.
The running system on the SoC is arm64 where BITS_PER_LONG and BITS_PER_LONG_LONG have the same value. In such case, the two macros appears to be the same. But you're right, I should use GENMASK_ULL() to be consistent and more correctly, just in case the "CONFIG_64BIT" is not defined somehow.
Will update it in v11.
Quoted 13 lines
drivers/platform/mellanox/mlxbf-tmfifo.c line 184
Quoted 12 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +10
-0+#define MLXBF_TMFIFO_TIMER_INTERVAL (HZ / 10) +/** +* mlxbf_tmfifo_u64 - Union of 64-bit data +* @data - 64-bit data in host byte order +* @data_le - 64-bit data in little-endian byte order +* +* It's expected to send 64-bit little-endian value (__le64) into the TmFifo. +* readq() and writeq() expect u64 instead. A union structure is used here +* to workaround the explicit casting usage like writeq(*(u64 *)&data_le). +*/
Quoted 3 lines
How do you know what readq()/writeq() does with the data? Is it on all architectures?
How the endianess conversion affects the actual data?
The SoC runs arm64 and supports little endian for now. The FIFO has two sides, one side is the SoC, the other side is extern host machine which could access the FIFO via USB or PCIe. The rule is that the 'byte stream' will keep the same when one side write 8 bytes and the other side reads the 8 bytes. So as long as both sides have agreement on the byte-order it should be fine.
After double check the arm64 readq()/writeq() implementation, it appears that these APIs already does cpu_to_le64() and le64_to_cpu() conversion. There's actually no need to make another conversion (and shouldn't do it). I'll remove these conversions in v11. The code will look much cleaner.
Quoted 14 lines
Quoted 13 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +11
-0+union mlxbf_tmfifo_u64 { +u64 data; +__le64 data_le; +}; +/* +* Default MAC. +* This MAC address will be read from EFI persistent variable if configured. +* It can also be reconfigured with standard Linux tools. +*/ +static u8 mlxbf_tmfifo_net_default_mac[6 ] = { +0x00 ,0x1A ,0xCA ,0xFF ,0xFF ,0x01 };
Quoted 4 lines
drivers/platform/mellanox/mlxbf-tmfifo.c line 225
Quoted 2 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +2
-0+#define mlxbf_vdev_to_tmfifo (dev) \ + container_of(dev, struct mlxbf_tmfifo_vdev, vdev)One line?
Couldn't fit it into one line within 80 characters.
(Please correct me if you meant single line even exceeding 80 chracters).
Quoted 15 lines
drivers/platform/mellanox/mlxbf-tmfifo.c line 241
Quoted 13 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +12
-0+/* Return the consumed Tx buffer space. */ +static int mlxbf_tmfifo_vdev_tx_buf_len (struct mlxbf_tmfifo_vdev *tm_vdev) +{ +int len; + +if (tm_vdev->tx_tail >= tm_vdev->tx_head) + len = tm_vdev->tx_tail - tm_vdev->tx_head; +else + len =MLXBF_TMFIFO_CONS_TX_BUF_SIZE - tm_vdev->tx_head + + tm_vdev->tx_tail; +return len; +}Is this custom implementation of some kind of
circ_buf?
Yes. I'll try if I could re-use the circ_buf structure and update it in v11.
Quoted 24 lines
Quoted 23 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +22
-0+/* Allocate vrings for the fifo. */ +static int mlxbf_tmfifo_alloc_vrings (struct mlxbf_tmfifo *fifo, +struct mlxbf_tmfifo_vdev *tm_vdev) +{ +struct mlxbf_tmfifo_vring *vring; +struct device *dev; +dma_addr_t dma; +int i, size; +void *va; + +for (i =0 ; i <ARRAY_SIZE (tm_vdev->vrings); i++) { + vring = &tm_vdev->vrings[i]; + vring->fifo = fifo; + vring->num =MLXBF_TMFIFO_VRING_SIZE ; + vring->align =SMP_CACHE_BYTES ; + vring->index = i; + vring->vdev_id = tm_vdev->vdev.id.device; + dev = &tm_vdev->vdev.dev; + + size =vring_size (vring->num, vring->align); + va =dma_alloc_coherent (dev->parent, size, &dma,GFP_KERNEL ); +if (!va) {
Quoted 3 lines
Quoted 1 line
+
dev_err(dev->parent, "dma_alloc_coherent failed\n");And how do you clean previously allocated items?
Fixed. Check the return value of mlxbf_tmfifo_alloc_vrings() and goto 'register_fail' (probably change to a better name) instead of 'fail'. In such case the mlxbf_tmfifo_free_vrings() will be called to clean up all allocated vrings.
Quoted 19 lines
Quoted 18 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +16
-0+return -ENOMEM ; + } + + vring->va = va; + vring->dma = dma; + } + +return 0 ; +} +/* Disable interrupts of the fifo device. */ +static void mlxbf_tmfifo_disable_irqs (struct mlxbf_tmfifo *fifo) +{ +int i, irq; + +for (i =0 ; i <MLXBF_TM_MAX_IRQ ; i++) { + irq = fifo->irq_info[i].irq;
Quoted 4 lines
Quoted 1 line
+ if (irq) {
I don't think this check is needed if you can guarantee that it has no staled records.
Yes, it's not needed any more according to the current code. Will remove it in v11.
Quoted 27 lines
Quoted 13 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +11
-0+ fifo->irq_info[i].irq =0 ; +disable_irq (irq); + } + } +} +/* Get the number of available words in the TmFifo for sending. */ +static int mlxbf_tmfifo_get_tx_avail (struct mlxbf_tmfifo *fifo,int vdev_id) +{ +int tx_reserve; +u64 sts; +drivers/platform/mellanox/mlxbf-tmfifo.c line 545
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +9
-0+/* Reserve some room in FIFO for console messages. */ +if (vdev_id ==VIRTIO_ID_NET ) + tx_reserve = fifo->tx_fifo_size /MLXBF_TMFIFO_RESERVE_RATIO ; +else + tx_reserve =1 ; + + sts =readq (fifo->tx_base +MLXBF_TMFIFO_TX_STS ); +return (fifo->tx_fifo_size - tx_reserve - +FIELD_GET (MLXBF_TMFIFO_TX_STS__COUNT_MASK , sts));Redundant parens.
Moreover, consider
Quoted 6 lines
u32 count; // or whatever suits for
FIELD_GET().
...sts = readq(...);
count =FIELD_GET(...);
return ...;
Will update in v11.
Quoted 13 lines
Quoted 12 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +10
-0+} +while (size >0 ) { + addr = cons->tx_buf + cons->tx_head; + +if (cons->tx_head +sizeof (u64) <= +MLXBF_TMFIFO_CONS_TX_BUF_SIZE ) { +memcpy (&data, addr,sizeof (u64)); + }else { + partial =MLXBF_TMFIFO_CONS_TX_BUF_SIZE - cons->tx_head; +memcpy (&data, addr, partial);
Quoted 4 lines
drivers/platform/mellanox/mlxbf-tmfifo.c line 595
Quoted 2 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +2
-0+memcpy ((u8 *)&data + partial, cons->tx_buf, +sizeof (u64) - partial);Unaligned access?!
The code here is to build and copy 8 bytes from the buffer into the 'data' variable. The source could be unaligned. For example, 3 bytes are at the end of the buffer and 5 bytes are at the beginning of the buffer. memcpy() is used to do byte-stream copy which seems ok. Please correct me if I misunderstand the comment.
Quoted 8 lines
drivers/platform/mellanox/mlxbf-tmfifo.c line 629
Quoted 5 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +3
-0+ } + buf.data =readq (fifo->rx_base +MLXBF_TMFIFO_RX_DATA ); + buf.data =le64_to_cpu (buf.data_le);Are you sure this is correct?
How did you test this on BE architectures?
Thanks for the comment! Same as above, the conversion is not really needed. I'll remove them in v11. As for testing, we only have arm64 little-endian Linux running on the SoC. This conversion doesn't make much difference for the SoC. As for BE architecture, we mainly verify the other side of the FIFO, which is the external host like using ppc64.
Quoted 4 lines
Quoted 2 lines
+
tm_vdev=devm_kzalloc(dev, sizeof(*tm_vdev), GFP_KERNEL);Is it appropriate use of devm_* ?
This is SoC, the device won't be closed or detached. The only case is when the driver is unloaded. So it appears ok to use devm_kzalloc() since it's allocated during probe() and released during module unload . Please correct me if I misunderstand it.
Quoted 13 lines
Quoted 12 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +10
-0+if (!tm_vdev) { + ret = -ENOMEM ; + goto fail; + } +/* Read the configured network MAC address from efi variable. */ +static void mlxbf_tmfifo_get_cfg_mac (u8 *mac) +{ +efi_guid_t guid =EFI_GLOBAL_VARIABLE_GUID ; +efi_status_t status; +unsigned long size;
Quoted 3 lines
Quoted 1 line
+ u8 buf[6];
ETH_ALEN?
Will update it in v11
Quoted 5 lines
drivers/platform/mellanox/mlxbf-tmfifo.c line 1189
Quoted 3 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +2
-0+ + size =sizeof (buf);Ditto.
Will update it in v11
Quoted 7 lines
drivers/platform/mellanox/mlxbf-tmfifo.c line 1192
Quoted 5 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +3
-0+ status = efi.get_variable (mlxbf_tmfifo_efi_name, &guid,NULL , &size, + buf); +if (status ==EFI_SUCCESS && size ==sizeof (buf))Ditto.
Will update it in v11
Quoted 4 lines
Quoted 2 lines
+
memcpy(mac, buf, sizeof(buf));
ether_addr_copy().
Will update it in v11
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c line 1295
Quoted 4 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +2
-0+} +memcpy (net_config.mac, mlxbf_tmfifo_net_default_mac,6 );
ether_addr_copy()...Quoted 1 line
+
mlxbf_tmfifo_get_cfg_mac(net_config.mac);... but actually above should be part of this function.
Will update it in v11
Quoted 4 lines
--
With Best Regards,
Andy Shevchenko
RE: [PATCH v10] platform/mellanox: Add TmFifo driver for Mellanox BlueField Soc
Andy,
The v11 has been posted.
Thanks!
Liming
Quoted 346 lines
-----Original Message-----
From: Liming Sun
Sent: Wednesday, March 6, 2019 3:01 PM
To: 'Andy Shevchenko' <[email protected]>
Cc: David Woods <[email protected]>; Andy Shevchenko <[email protected]>; Darren Hart <[email protected]>; Vadim Pasternak <[email protected]>; Linux Kernel Mailing List <[email protected]>; Platform Driver <platform-driver- [email protected]>
Subject: RE: [PATCH v10] platform/mellanox: Add TmFifo driver for Mellanox BlueField SocThanks Andy! Please see my response below. If no further comments, I'll try to post v11 after more testing.
Regards,
LimingQuoted 41 lines
-----Original Message-----
From: Andy Shevchenko <[email protected]>
Sent: Tuesday, March 5, 2019 10:34 AM
To: Liming Sun <[email protected]>
Cc: David Woods <[email protected]>; Andy Shevchenko <[email protected]>; Darren Hart <[email protected]>; Vadim Pasternak <[email protected]>; Linux Kernel Mailing List <[email protected]>; Platform Driver <platform-driver- [email protected]>
Subject: Re: [PATCH v10] platform/mellanox: Add TmFifo driver for Mellanox BlueField SocQuoted 5 lines · Liming Sun
This commit adds the TmFifo platform driver for Mellanox BlueField Soc. TmFifo is a shared FIFO which enables external host machine to exchange data with the SoC via USB or PCIe. The driver is based on virtio framework and has console and network access enabled.
Thank you for an update.
Unfortunately more work is needed. My comments below.
Quoted 20 lines
drivers/platform/mellanox/mlxbf-tmfifo-regs.h new file +14
-0+#define MLXBF_TMFIFO_TX_STS__COUNT_RMASK GENMASK(8, 0) +#define MLXBF_TMFIFO_TX_STS__COUNT_MASK GENMASK(8, 0) +#define MLXBF_TMFIFO_TX_CTL__LWM_RMASK GENMASK(7, 0) +#define MLXBF_TMFIFO_TX_CTL__LWM_MASK GENMASK(7, 0) +#define MLXBF_TMFIFO_TX_CTL__HWM_RMASK GENMASK(7, 0) +#define MLXBF_TMFIFO_TX_CTL__HWM_MASK GENMASK(15, 8) +#define MLXBF_TMFIFO_TX_CTL__MAX_ENTRIES_RMASK GENMASK(8, 0) +#define MLXBF_TMFIFO_TX_CTL__MAX_ENTRIES_MASK GENMASK_ULL(40, 32) +#define MLXBF_TMFIFO_RX_STS__COUNT_RMASK GENMASK(8, 0) +#define MLXBF_TMFIFO_RX_STS__COUNT_MASK GENMASK(8, 0) +#define MLXBF_TMFIFO_RX_CTL__LWM_RMASK GENMASK(7, 0) +#define MLXBF_TMFIFO_RX_CTL__LWM_MASK GENMASK(7, 0) +#define MLXBF_TMFIFO_RX_CTL__HWM_RMASK GENMASK(7, 0) +#define MLXBF_TMFIFO_RX_CTL__HWM_MASK GENMASK(15, 8)Quoted 7 lines
drivers/platform/mellanox/mlxbf-tmfifo-regs.h line 61
Quoted 2 lines
drivers/platform/mellanox/mlxbf-tmfifo-regs.h new file +2
-0+#define MLXBF_TMFIFO_RX_CTL__MAX_ENTRIES_RMASK GENMASK(8, 0) +#define MLXBF_TMFIFO_RX_CTL__MAX_ENTRIES_MASK GENMASK_ULL(40, 32)Since two of them have
_ULLsuffix I'm wondering if you have checked for side effects on the rest, i.e. if you operate with 64-bit variable and use something like ~MLXBF_TMFIFO_RX_CTL__MAX_ENTRIES_RMASK, it may give you interesting results.The running system on the SoC is arm64 where
BITS_PER_LONGandBITS_PER_LONG_LONGhave the same value. In such case, the two macros appears to be the same. But you're right, I should useGENMASK_ULL()to be consistent and more correctly, just in case the "CONFIG_64BIT" is not defined somehow.Will update it in v11.
Quoted 13 lines
drivers/platform/mellanox/mlxbf-tmfifo.c line 184
Quoted 12 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +10
-0+#define MLXBF_TMFIFO_TIMER_INTERVAL (HZ / 10) +/** +* mlxbf_tmfifo_u64 - Union of 64-bit data +* @data - 64-bit data in host byte order +* @data_le - 64-bit data in little-endian byte order +* +* It's expected to send 64-bit little-endian value (__le64) into the TmFifo. +* readq() and writeq() expect u64 instead. A union structure is used here +* to workaround the explicit casting usage like writeq(*(u64 *)&data_le). +*/ Quoted 3 lines
How do you know what readq()/writeq() does with the data? Is it on all architectures?
How the endianess conversion affects the actual data?The SoC runs arm64 and supports little endian for now. The FIFO has two sides, one side is the SoC, the other side is extern host machine which could access the FIFO via USB or PCIe. The rule is that the 'byte stream' will keep the same when one side write 8 bytes and the other side reads the 8 bytes. So as long as both sides have agreement on the byte-order it should be fine.
After double check the arm64 readq()/writeq() implementation, it appears that these APIs already does
cpu_to_le64()andle64_to_cpu()conversion. There's actually no need to make another conversion (and shouldn't do it). I'll remove these conversions in v11. The code will look much cleaner.Quoted 14 lines
Quoted 13 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +11
-0+union mlxbf_tmfifo_u64 { +u64 data; +__le64 data_le; +}; +/* +* Default MAC. +* This MAC address will be read from EFI persistent variable if configured. +* It can also be reconfigured with standard Linux tools. +*/ +static u8 mlxbf_tmfifo_net_default_mac[6 ] = { +0x00 ,0x1A ,0xCA ,0xFF ,0xFF ,0x01 };Quoted 4 lines
drivers/platform/mellanox/mlxbf-tmfifo.c line 225
Quoted 2 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +2
-0+#define mlxbf_vdev_to_tmfifo (dev) \ + container_of(dev, struct mlxbf_tmfifo_vdev, vdev)One line?
Couldn't fit it into one line within 80 characters.
(Please correct me if you meant single line even exceeding 80 chracters).Quoted 15 lines
drivers/platform/mellanox/mlxbf-tmfifo.c line 241
Quoted 13 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +12
-0+/* Return the consumed Tx buffer space. */ +static int mlxbf_tmfifo_vdev_tx_buf_len (struct mlxbf_tmfifo_vdev *tm_vdev) +{ +int len; + +if (tm_vdev->tx_tail >= tm_vdev->tx_head) + len = tm_vdev->tx_tail - tm_vdev->tx_head; +else + len =MLXBF_TMFIFO_CONS_TX_BUF_SIZE - tm_vdev->tx_head + + tm_vdev->tx_tail; +return len; +}Is this custom implementation of some kind of
circ_buf?Yes. I'll try if I could re-use the
circ_bufstructure and update it in v11.Quoted 24 lines
Quoted 23 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +22
-0+/* Allocate vrings for the fifo. */ +static int mlxbf_tmfifo_alloc_vrings (struct mlxbf_tmfifo *fifo, +struct mlxbf_tmfifo_vdev *tm_vdev) +{ +struct mlxbf_tmfifo_vring *vring; +struct device *dev; +dma_addr_t dma; +int i, size; +void *va; + +for (i =0 ; i <ARRAY_SIZE (tm_vdev->vrings); i++) { + vring = &tm_vdev->vrings[i]; + vring->fifo = fifo; + vring->num =MLXBF_TMFIFO_VRING_SIZE ; + vring->align =SMP_CACHE_BYTES ; + vring->index = i; + vring->vdev_id = tm_vdev->vdev.id.device; + dev = &tm_vdev->vdev.dev; + + size =vring_size (vring->num, vring->align); + va =dma_alloc_coherent (dev->parent, size, &dma,GFP_KERNEL ); +if (!va) {Quoted 3 lines
Quoted 1 line
+
dev_err(dev->parent, "dma_alloc_coherent failed\n");And how do you clean previously allocated items?
Fixed. Check the return value of
mlxbf_tmfifo_alloc_vrings()and goto 'register_fail' (probably change to a better name) instead of 'fail'. In such case themlxbf_tmfifo_free_vrings()will be called to clean up all allocated vrings.Quoted 19 lines
Quoted 18 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +16
-0+return -ENOMEM ; + } + + vring->va = va; + vring->dma = dma; + } + +return 0 ; +} +/* Disable interrupts of the fifo device. */ +static void mlxbf_tmfifo_disable_irqs (struct mlxbf_tmfifo *fifo) +{ +int i, irq; + +for (i =0 ; i <MLXBF_TM_MAX_IRQ ; i++) { + irq = fifo->irq_info[i].irq;Quoted 4 lines
Quoted 1 line
+ if (irq) {
I don't think this check is needed if you can guarantee that it has no staled records.
Yes, it's not needed any more according to the current code. Will remove it in v11.
Quoted 27 lines
Quoted 13 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +11
-0+ fifo->irq_info[i].irq =0 ; +disable_irq (irq); + } + } +} +/* Get the number of available words in the TmFifo for sending. */ +static int mlxbf_tmfifo_get_tx_avail (struct mlxbf_tmfifo *fifo,int vdev_id) +{ +int tx_reserve; +u64 sts; +drivers/platform/mellanox/mlxbf-tmfifo.c line 545
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +9
-0+/* Reserve some room in FIFO for console messages. */ +if (vdev_id ==VIRTIO_ID_NET ) + tx_reserve = fifo->tx_fifo_size /MLXBF_TMFIFO_RESERVE_RATIO ; +else + tx_reserve =1 ; + + sts =readq (fifo->tx_base +MLXBF_TMFIFO_TX_STS ); +return (fifo->tx_fifo_size - tx_reserve - +FIELD_GET (MLXBF_TMFIFO_TX_STS__COUNT_MASK , sts));Redundant parens.
Moreover, considerQuoted 6 lines
u32 count; // or whatever suits for
FIELD_GET().
...sts = readq(...);
count =FIELD_GET(...);
return ...;Will update in v11.
Quoted 13 lines
Quoted 12 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +10
-0+} +while (size >0 ) { + addr = cons->tx_buf + cons->tx_head; + +if (cons->tx_head +sizeof (u64) <= +MLXBF_TMFIFO_CONS_TX_BUF_SIZE ) { +memcpy (&data, addr,sizeof (u64)); + }else { + partial =MLXBF_TMFIFO_CONS_TX_BUF_SIZE - cons->tx_head; +memcpy (&data, addr, partial);Quoted 4 lines
drivers/platform/mellanox/mlxbf-tmfifo.c line 595
Quoted 2 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +2
-0+memcpy ((u8 *)&data + partial, cons->tx_buf, +sizeof (u64) - partial);Unaligned access?!
The code here is to build and copy 8 bytes from the buffer into the 'data' variable. The source could be unaligned. For example, 3 bytes are at the end of the buffer and 5 bytes are at the beginning of the buffer.
memcpy()is used to do byte-stream copy which seems ok. Please correct me if I misunderstand the comment.Quoted 8 lines
drivers/platform/mellanox/mlxbf-tmfifo.c line 629
Quoted 5 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +3
-0+ } + buf.data =readq (fifo->rx_base +MLXBF_TMFIFO_RX_DATA ); + buf.data =le64_to_cpu (buf.data_le);Are you sure this is correct?
How did you test this on BE architectures?Thanks for the comment! Same as above, the conversion is not really needed. I'll remove them in v11. As for testing, we only have arm64 little-endian Linux running on the SoC. This conversion doesn't make much difference for the SoC. As for BE architecture, we mainly verify the other side of the FIFO, which is the external host like using ppc64.
Quoted 4 lines
Quoted 2 lines
+
tm_vdev=devm_kzalloc(dev, sizeof(*tm_vdev), GFP_KERNEL);Is it appropriate use of devm_* ?
This is SoC, the device won't be closed or detached. The only case is when the driver is unloaded. So it appears ok to use
devm_kzalloc()since it's allocated duringprobe()and released during module unload . Please correct me if I misunderstand it.Quoted 13 lines
Quoted 12 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +10
-0+if (!tm_vdev) { + ret = -ENOMEM ; + goto fail; + } +/* Read the configured network MAC address from efi variable. */ +static void mlxbf_tmfifo_get_cfg_mac (u8 *mac) +{ +efi_guid_t guid =EFI_GLOBAL_VARIABLE_GUID ; +efi_status_t status; +unsigned long size;Quoted 3 lines
Quoted 1 line
+ u8 buf[6];
ETH_ALEN?Will update it in v11
Quoted 5 lines
drivers/platform/mellanox/mlxbf-tmfifo.c line 1189
Quoted 3 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +2
-0+ + size =sizeof (buf);Ditto.
Will update it in v11
Quoted 7 lines
drivers/platform/mellanox/mlxbf-tmfifo.c line 1192
Quoted 5 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +3
-0+ status = efi.get_variable (mlxbf_tmfifo_efi_name, &guid,NULL , &size, + buf); +if (status ==EFI_SUCCESS && size ==sizeof (buf))Ditto.
Will update it in v11
Quoted 4 lines
Quoted 2 lines
+
memcpy(mac, buf, sizeof(buf));
ether_addr_copy().Will update it in v11
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c line 1295
Quoted 4 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +2
-0+} +memcpy (net_config.mac, mlxbf_tmfifo_net_default_mac,6 );
ether_addr_copy()...Quoted 1 line
+
mlxbf_tmfifo_get_cfg_mac(net_config.mac);... but actually above should be part of this function.
Will update it in v11
Quoted 4 lines
--
With Best Regards,
Andy Shevchenko
PATCH v11 1/1 platform/mellanox: Add TmFifo driver for Mellanox BlueField Soc
In reply to Liming SunThis commit adds the TmFifo platform driver for Mellanox BlueField Soc. TmFifo is a shared FIFO which enables external host machine to exchange data with the SoC via USB or PCIe. The driver is based on virtio framework and has console and network access enabled.
---v10->v11:
Fixes for comments from Andy:
- Use GENMASK_ULL() instead of GENMASK() in mlxbf-tmfifo-regs.h
- Removed the cpu_to_le64()/le64_to_cpu() conversion since readq()/writeq() already takes care of it.
- Remove the "if (irq)" check in mlxbf_tmfifo_disable_irqs().
- Add "u32 count" temp variable in mlxbf_tmfifo_get_tx_avail().
- Clean up mlxbf_tmfifo_get_cfg_mac(), use ETH_ALEN instead of value 6.
- Change the tx_buf to use Linux existing 'struct circ_buf'. Comment not applied:
- "Change macro mlxbf_vdev_to_tmfifo() to one line" Couldn't fit in one line with 80 chracters
- "Is it appropriate use of devm_* for 'tm_vdev = devm_kzalloc'" This is SoC, the device won't be closed or detached. The only case is when the driver is unloaded. So it appears ok to use devm_kzalloc() since it's allocated during probe() and released during module unload.
Comments from Vadim: OKv9->v10:
Fixes for comments from Andy:
- Use devm_ioremap_resource() instead of devm_ioremap().
- Use kernel-doc comments.
- Keep Makefile contents sorted.
- Use same fixed format for offsets.
- Use SZ_1K/SZ_32K instead of 1024/23*1024.
- Remove unnecessary comments.
- Use one style for max numbers.
- More comments for mlxbf_tmfifo_vdev and mlxbf_tmfifo_data_64bit.
- Use globally defined MTU instead of new definition.
- Remove forward declaration of mlxbf_tmfifo_remove().
- Remove PAGE_ALIGN() for dma_alloc_coherent)().
- Remove the cast of "struct vring *".
- Check return result of test_and_set_bit().
- Add a macro mlxbt_vdev_to_tmfifo().
- Several other minor coding style comments.
Comment not applied:
- "Shouldn't be rather helper in EFI lib in kernel" Looks like efi.get_variable() is the way I found in the kernel tree.
- "this one is not protected anyhow? Potential race condition" In mlxbf_tmfifo_console_tx(), the spin-lock is used to protect the 'tx_buf' only, not the FIFO writes. So there is no race condition.
- "Is __packed needed in mlxbf_tmfifo_msg_hdr".
Yes, it is needed to make sure the structure is 8 bytes.
Fixes for comments from Vadim:
- Use tab in mlxbf-tmfifo-regs.h
- Use kernel-doc comments for struct mlxbf_tmfifo_msg_hdr and mlxbf_tmfifo_irq_info as well.
- Use _MAX instead of _CNT in the macro definition to be consistent.
- Fix the MODULE_LICENSE.
- Use BIT_ULL() instead of BIT().
- Remove argument of 'avail' for mlxbf_tmfifo_rxtx_header() and mlxbf_tmfifo_rxtx_word()
- Revise logic in mlxbf_tmfifo_rxtx_one_desc() to remove the WARN_ON().
- Change "union mlxbf_tmfifo_u64 u" to "union mlxbf_tmfifo_u64 buf" in mlxbf_tmfifo_rxtx_word().
- Change date type of vring_change from 'int' to 'bool'.
- Remove the blank lines after Signed-off.
- Don’t use declaration in the middle.
- Make the network header initialization in some more elegant way.
- Change label done to mlxbf_tmfifo_desc_done.
- Remove some unnecessary comments, and several other misc coding style comments.
- Simplify code logic in mlxbf_tmfifo_virtio_notify() New changes by Liming:
- Simplify the Rx/Tx function arguments to make it more readable.v8->v9:
Fixes for comments from Andy:
- Use modern devm_xxx() API instead.
Fixes for comments from Vadim:
- Split the Rx/Tx function into smaller funcitons.
- File name, copyright information.
- Function and variable name conversion.
- Local variable and indent coding styles.
- Remove unnecessary 'inline' declarations.
- Use devm_xxx() APIs.
- Move the efi_char16_t MAC address definition to global.
- Fix warnings reported by 'checkpatch --strict'.
- Fix warnings reported by 'make CF="-D__CHECK_ENDIAN__"'.
- Change select VIRTIO_xxx to depends on VIRTIO_ in Kconfig.
- Merge mlxbf_tmfifo_vdev_tx_buf_push() and mlxbf_tmfifo_vdev_tx_buf_pop().
- Add union to avoid casting between __le64 and u64.
- Several other misc coding style comments.
New changes by Liming:
- Removed the DT binding documentation since only ACPI is supported for now by UEFI on the SoC.
v8: Re-submit under drivers/platform/mellanox for the target-side
platform driver only.
v7: Added host side drivers into the same patch set.
v5~v6: Coding style fix.
v1~v4: Initial version for directory drivers/soc/mellanox.
--- drivers/platform/mellanox/Kconfig | 12 +- drivers/platform/mellanox/Makefile | 1 + drivers/platform/mellanox/mlxbf-tmfifo-regs.h | 63 ++ drivers/platform/mellanox/mlxbf-tmfifo.c | 1286 +++++++++++++++++++++++++ 4 files changed, 1361 insertions(+), 1 deletion(-) create mode 100644 drivers/platform/mellanox/mlxbf-tmfifo-regs.h create mode 100644 drivers/platform/mellanox/mlxbf-tmfifo.c
drivers/platform/mellanox/Kconfig +11 -1
@@ -5,7 +5,7 @@ menuconfig MELLANOX_PLATFORM bool "Platform support for Mellanox hardware" - depends on X86 || ARM || COMPILE_TEST + depends on X86 || ARM || ARM64 || COMPILE_TEST ---help--- Say Y here to get to see options for platform support for Mellanox systems. This option alone does not add any kernel code.
@@ -34,4 +34,14 @@ config MLXREG_IO to system resets operation, system reset causes monitoring and some kinds of mux selection. +config MLXBF_TMFIFO + tristate "Mellanox BlueField SoC TmFifo platform driver" + depends on ARM64 + depends on ACPI + depends on VIRTIO_CONSOLE && VIRTIO_NET + help + Say y here to enable TmFifo support. The TmFifo driver provides + platform driver support for the TmFifo which supports console + and networking based on the virtio framework. + endif # MELLANOX_PLATFORM
drivers/platform/mellanox/Makefile +1 -0
@@ -3,5 +3,6 @@ # Makefile for linux/drivers/platform/mellanox # Mellanox Platform-Specific Drivers # +obj-$(CONFIG_MLXBF_TMFIFO) += mlxbf-tmfifo.o obj-$(CONFIG_MLXREG_HOTPLUG) += mlxreg-hotplug.o obj-$(CONFIG_MLXREG_IO) += mlxreg-io.o
drivers/platform/mellanox/mlxbf-tmfifo-regs.h new file +63 -0
63 lines not on this page · raw message
drivers/platform/mellanox/mlxbf-tmfifo.c new file +1286 -0
1,286 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v11 1/1 platform/mellanox: Add TmFifo driver for Mellanox BlueField Soc
In reply to Liming SunThis commit adds the TmFifo platform driver for Mellanox BlueField Soc. TmFifo is a shared FIFO which enables external host machine to exchange data with the SoC via USB or PCIe. The driver is based on virtio framework and has console and network access enabled.
---v11->v11: rebase & resend, no new changesv10->v11:
Fixes for comments from Andy:
- Use GENMASK_ULL() instead of GENMASK() in mlxbf-tmfifo-regs.h
- Removed the cpu_to_le64()/le64_to_cpu() conversion since readq()/writeq() already takes care of it.
- Remove the "if (irq)" check in mlxbf_tmfifo_disable_irqs().
- Add "u32 count" temp variable in mlxbf_tmfifo_get_tx_avail().
- Clean up mlxbf_tmfifo_get_cfg_mac(), use ETH_ALEN instead of value 6.
- Change the tx_buf to use Linux existing 'struct circ_buf'. Comment not applied:
- "Change macro mlxbf_vdev_to_tmfifo() to one line" Couldn't fit in one line with 80 chracters
- "Is it appropriate use of devm_* for 'tm_vdev = devm_kzalloc'" This is SoC, the device won't be closed or detached. The only case is when the driver is unloaded. So it appears ok to use devm_kzalloc() since it's allocated during probe() and released during module unload.
Comments from Vadim: OKv9->v10:
Fixes for comments from Andy:
- Use devm_ioremap_resource() instead of devm_ioremap().
- Use kernel-doc comments.
- Keep Makefile contents sorted.
- Use same fixed format for offsets.
- Use SZ_1K/SZ_32K instead of 1024/23*1024.
- Remove unnecessary comments.
- Use one style for max numbers.
- More comments for mlxbf_tmfifo_vdev and mlxbf_tmfifo_data_64bit.
- Use globally defined MTU instead of new definition.
- Remove forward declaration of mlxbf_tmfifo_remove().
- Remove PAGE_ALIGN() for dma_alloc_coherent)().
- Remove the cast of "struct vring *".
- Check return result of test_and_set_bit().
- Add a macro mlxbt_vdev_to_tmfifo().
- Several other minor coding style comments.
Comment not applied:
- "Shouldn't be rather helper in EFI lib in kernel" Looks like efi.get_variable() is the way I found in the kernel tree.
- "this one is not protected anyhow? Potential race condition" In mlxbf_tmfifo_console_tx(), the spin-lock is used to protect the 'tx_buf' only, not the FIFO writes. So there is no race condition.
- "Is __packed needed in mlxbf_tmfifo_msg_hdr".
Yes, it is needed to make sure the structure is 8 bytes.
Fixes for comments from Vadim:
- Use tab in mlxbf-tmfifo-regs.h
- Use kernel-doc comments for struct mlxbf_tmfifo_msg_hdr and mlxbf_tmfifo_irq_info as well.
- Use _MAX instead of _CNT in the macro definition to be consistent.
- Fix the MODULE_LICENSE.
- Use BIT_ULL() instead of BIT().
- Remove argument of 'avail' for mlxbf_tmfifo_rxtx_header() and mlxbf_tmfifo_rxtx_word()
- Revise logic in mlxbf_tmfifo_rxtx_one_desc() to remove the WARN_ON().
- Change "union mlxbf_tmfifo_u64 u" to "union mlxbf_tmfifo_u64 buf" in mlxbf_tmfifo_rxtx_word().
- Change date type of vring_change from 'int' to 'bool'.
- Remove the blank lines after Signed-off.
- Don’t use declaration in the middle.
- Make the network header initialization in some more elegant way.
- Change label done to mlxbf_tmfifo_desc_done.
- Remove some unnecessary comments, and several other misc coding style comments.
- Simplify code logic in mlxbf_tmfifo_virtio_notify() New changes by Liming:
- Simplify the Rx/Tx function arguments to make it more readable.v8->v9:
Fixes for comments from Andy:
- Use modern devm_xxx() API instead.
Fixes for comments from Vadim:
- Split the Rx/Tx function into smaller funcitons.
- File name, copyright information.
- Function and variable name conversion.
- Local variable and indent coding styles.
- Remove unnecessary 'inline' declarations.
- Use devm_xxx() APIs.
- Move the efi_char16_t MAC address definition to global.
- Fix warnings reported by 'checkpatch --strict'.
- Fix warnings reported by 'make CF="-D__CHECK_ENDIAN__"'.
- Change select VIRTIO_xxx to depends on VIRTIO_ in Kconfig.
- Merge mlxbf_tmfifo_vdev_tx_buf_push() and mlxbf_tmfifo_vdev_tx_buf_pop().
- Add union to avoid casting between __le64 and u64.
- Several other misc coding style comments.
New changes by Liming:
- Removed the DT binding documentation since only ACPI is supported for now by UEFI on the SoC.
v8: Re-submit under drivers/platform/mellanox for the target-side
platform driver only.
v7: Added host side drivers into the same patch set.
v5~v6: Coding style fix.
v1~v4: Initial version for directory drivers/soc/mellanox.
--- drivers/platform/mellanox/Kconfig | 12 +- drivers/platform/mellanox/Makefile | 1 + drivers/platform/mellanox/mlxbf-tmfifo-regs.h | 63 ++ drivers/platform/mellanox/mlxbf-tmfifo.c | 1286 +++++++++++++++++++++++++ 4 files changed, 1361 insertions(+), 1 deletion(-) create mode 100644 drivers/platform/mellanox/mlxbf-tmfifo-regs.h create mode 100644 drivers/platform/mellanox/mlxbf-tmfifo.c
drivers/platform/mellanox/Kconfig +11 -1
@@ -5,7 +5,7 @@ menuconfig MELLANOX_PLATFORM bool "Platform support for Mellanox hardware" - depends on X86 || ARM || COMPILE_TEST + depends on X86 || ARM || ARM64 || COMPILE_TEST ---help--- Say Y here to get to see options for platform support for Mellanox systems. This option alone does not add any kernel code.
@@ -34,4 +34,14 @@ config MLXREG_IO to system resets operation, system reset causes monitoring and some kinds of mux selection. +config MLXBF_TMFIFO + tristate "Mellanox BlueField SoC TmFifo platform driver" + depends on ARM64 + depends on ACPI + depends on VIRTIO_CONSOLE && VIRTIO_NET + help + Say y here to enable TmFifo support. The TmFifo driver provides + platform driver support for the TmFifo which supports console + and networking based on the virtio framework. + endif # MELLANOX_PLATFORM
drivers/platform/mellanox/Makefile +1 -0
@@ -3,5 +3,6 @@ # Makefile for linux/drivers/platform/mellanox # Mellanox Platform-Specific Drivers # +obj-$(CONFIG_MLXBF_TMFIFO) += mlxbf-tmfifo.o obj-$(CONFIG_MLXREG_HOTPLUG) += mlxreg-hotplug.o obj-$(CONFIG_MLXREG_IO) += mlxreg-io.o
drivers/platform/mellanox/mlxbf-tmfifo-regs.h new file +63 -0
63 lines not on this page · raw message
drivers/platform/mellanox/mlxbf-tmfifo.c new file +1286 -0
1,286 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v12 1/1 platform/mellanox: Add TmFifo driver for Mellanox BlueField Soc
In reply to Liming SunThis commit adds the TmFifo platform driver for Mellanox BlueField Soc. TmFifo is a shared FIFO which enables external host machine to exchange data with the SoC via USB or PCIe. The driver is based on virtio framework and has console and network access enabled.
---v11->v12:
Fixed the two unsolved comments from v11.
- "Change macro mlxbf_vdev_to_tmfifo() to one line" Done. Seems not hard.
- "Is it appropriate use of devm_* for 'tm_vdev = devm_kzalloc'" Yes, understand the comment now. The tmfifo is fixed, but the vdev is dynamic. Use kzalloc() instead, and free the device in the release callback which is the right place for it.v10->v11:
Fixes for comments from Andy:
- Use GENMASK_ULL() instead of GENMASK() in mlxbf-tmfifo-regs.h
- Removed the cpu_to_le64()/le64_to_cpu() conversion since readq()/writeq() already takes care of it.
- Remove the "if (irq)" check in mlxbf_tmfifo_disable_irqs().
- Add "u32 count" temp variable in mlxbf_tmfifo_get_tx_avail().
- Clean up mlxbf_tmfifo_get_cfg_mac(), use ETH_ALEN instead of value 6.
- Change the tx_buf to use Linux existing 'struct circ_buf'. Comment not applied:
- "Change macro mlxbf_vdev_to_tmfifo() to one line" Couldn't fit in one line with 80 chracters
- "Is it appropriate use of devm_* for 'tm_vdev = devm_kzalloc'" This is SoC, the device won't be closed or detached. The only case is when the driver is unloaded. So it appears ok to use devm_kzalloc() since it's allocated during probe() and released during module unload.
Comments from Vadim: OKv9->v10:
Fixes for comments from Andy:
- Use devm_ioremap_resource() instead of devm_ioremap().
- Use kernel-doc comments.
- Keep Makefile contents sorted.
- Use same fixed format for offsets.
- Use SZ_1K/SZ_32K instead of 1024/23*1024.
- Remove unnecessary comments.
- Use one style for max numbers.
- More comments for mlxbf_tmfifo_vdev and mlxbf_tmfifo_data_64bit.
- Use globally defined MTU instead of new definition.
- Remove forward declaration of mlxbf_tmfifo_remove().
- Remove PAGE_ALIGN() for dma_alloc_coherent)().
- Remove the cast of "struct vring *".
- Check return result of test_and_set_bit().
- Add a macro mlxbt_vdev_to_tmfifo().
- Several other minor coding style comments.
Comment not applied:
- "Shouldn't be rather helper in EFI lib in kernel" Looks like efi.get_variable() is the way I found in the kernel tree.
- "this one is not protected anyhow? Potential race condition" In mlxbf_tmfifo_console_tx(), the spin-lock is used to protect the 'tx_buf' only, not the FIFO writes. So there is no race condition.
- "Is __packed needed in mlxbf_tmfifo_msg_hdr".
Yes, it is needed to make sure the structure is 8 bytes.
Fixes for comments from Vadim:
- Use tab in mlxbf-tmfifo-regs.h
- Use kernel-doc comments for struct mlxbf_tmfifo_msg_hdr and mlxbf_tmfifo_irq_info as well.
- Use _MAX instead of _CNT in the macro definition to be consistent.
- Fix the MODULE_LICENSE.
- Use BIT_ULL() instead of BIT().
- Remove argument of 'avail' for mlxbf_tmfifo_rxtx_header() and mlxbf_tmfifo_rxtx_word()
- Revise logic in mlxbf_tmfifo_rxtx_one_desc() to remove the WARN_ON().
- Change "union mlxbf_tmfifo_u64 u" to "union mlxbf_tmfifo_u64 buf" in mlxbf_tmfifo_rxtx_word().
- Change date type of vring_change from 'int' to 'bool'.
- Remove the blank lines after Signed-off.
- Don’t use declaration in the middle.
- Make the network header initialization in some more elegant way.
- Change label done to mlxbf_tmfifo_desc_done.
- Remove some unnecessary comments, and several other misc coding style comments.
- Simplify code logic in mlxbf_tmfifo_virtio_notify() New changes by Liming:
- Simplify the Rx/Tx function arguments to make it more readable.v8->v9:
Fixes for comments from Andy:
- Use modern devm_xxx() API instead.
Fixes for comments from Vadim:
- Split the Rx/Tx function into smaller funcitons.
- File name, copyright information.
- Function and variable name conversion.
- Local variable and indent coding styles.
- Remove unnecessary 'inline' declarations.
- Use devm_xxx() APIs.
- Move the efi_char16_t MAC address definition to global.
- Fix warnings reported by 'checkpatch --strict'.
- Fix warnings reported by 'make CF="-D__CHECK_ENDIAN__"'.
- Change select VIRTIO_xxx to depends on VIRTIO_ in Kconfig.
- Merge mlxbf_tmfifo_vdev_tx_buf_push() and mlxbf_tmfifo_vdev_tx_buf_pop().
- Add union to avoid casting between __le64 and u64.
- Several other misc coding style comments.
New changes by Liming:
- Removed the DT binding documentation since only ACPI is supported for now by UEFI on the SoC.
v8: Re-submit under drivers/platform/mellanox for the target-side
platform driver only.
v7: Added host side drivers into the same patch set.
v5~v6: Coding style fix.
v1~v4: Initial version for directory drivers/soc/mellanox.
--- drivers/platform/mellanox/Kconfig | 12 +- drivers/platform/mellanox/Makefile | 1 + drivers/platform/mellanox/mlxbf-tmfifo-regs.h | 63 ++ drivers/platform/mellanox/mlxbf-tmfifo.c | 1291 +++++++++++++++++++++++++ 4 files changed, 1366 insertions(+), 1 deletion(-) create mode 100644 drivers/platform/mellanox/mlxbf-tmfifo-regs.h create mode 100644 drivers/platform/mellanox/mlxbf-tmfifo.c
drivers/platform/mellanox/Kconfig +11 -1
@@ -5,7 +5,7 @@ menuconfig MELLANOX_PLATFORM bool "Platform support for Mellanox hardware" - depends on X86 || ARM || COMPILE_TEST + depends on X86 || ARM || ARM64 || COMPILE_TEST ---help--- Say Y here to get to see options for platform support for Mellanox systems. This option alone does not add any kernel code.
@@ -34,4 +34,14 @@ config MLXREG_IO to system resets operation, system reset causes monitoring and some kinds of mux selection. +config MLXBF_TMFIFO + tristate "Mellanox BlueField SoC TmFifo platform driver" + depends on ARM64 + depends on ACPI + depends on VIRTIO_CONSOLE && VIRTIO_NET + help + Say y here to enable TmFifo support. The TmFifo driver provides + platform driver support for the TmFifo which supports console + and networking based on the virtio framework. + endif # MELLANOX_PLATFORM
drivers/platform/mellanox/Makefile +1 -0
@@ -3,5 +3,6 @@ # Makefile for linux/drivers/platform/mellanox # Mellanox Platform-Specific Drivers # +obj-$(CONFIG_MLXBF_TMFIFO) += mlxbf-tmfifo.o obj-$(CONFIG_MLXREG_HOTPLUG) += mlxreg-hotplug.o obj-$(CONFIG_MLXREG_IO) += mlxreg-io.o
drivers/platform/mellanox/mlxbf-tmfifo-regs.h new file +63 -0
63 lines not on this page · raw message
drivers/platform/mellanox/mlxbf-tmfifo.c new file +1291 -0
1,291 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v13 1/1 platform/mellanox: Add TmFifo driver for Mellanox BlueField Soc
In reply to Liming SunThis commit adds the TmFifo platform driver for Mellanox BlueField Soc. TmFifo is a shared FIFO which enables external host machine to exchange data with the SoC via USB or PCIe. The driver is based on virtio framework and has console and network access enabled.
---v12->v13:
Rebase and resubmit (no new changes).v11->v12:
Fixed the two unsolved comments from v11.
- "Change macro mlxbf_vdev_to_tmfifo() to one line" Done. Seems not hard.
- "Is it appropriate use of devm_* for 'tm_vdev = devm_kzalloc'" Yes, understand the comment now. The tmfifo is fixed, but the vdev is dynamic. Use kzalloc() instead, and free the device in the release callback which is the right place for it.v10->v11:
Fixes for comments from Andy:
- Use GENMASK_ULL() instead of GENMASK() in mlxbf-tmfifo-regs.h
- Removed the cpu_to_le64()/le64_to_cpu() conversion since readq()/writeq() already takes care of it.
- Remove the "if (irq)" check in mlxbf_tmfifo_disable_irqs().
- Add "u32 count" temp variable in mlxbf_tmfifo_get_tx_avail().
- Clean up mlxbf_tmfifo_get_cfg_mac(), use ETH_ALEN instead of value 6.
- Change the tx_buf to use Linux existing 'struct circ_buf'. Comment not applied:
- "Change macro mlxbf_vdev_to_tmfifo() to one line" Couldn't fit in one line with 80 chracters
- "Is it appropriate use of devm_* for 'tm_vdev = devm_kzalloc'" This is SoC, the device won't be closed or detached. The only case is when the driver is unloaded. So it appears ok to use devm_kzalloc() since it's allocated during probe() and released during module unload.
Comments from Vadim: OKv9->v10:
Fixes for comments from Andy:
- Use devm_ioremap_resource() instead of devm_ioremap().
- Use kernel-doc comments.
- Keep Makefile contents sorted.
- Use same fixed format for offsets.
- Use SZ_1K/SZ_32K instead of 1024/23*1024.
- Remove unnecessary comments.
- Use one style for max numbers.
- More comments for mlxbf_tmfifo_vdev and mlxbf_tmfifo_data_64bit.
- Use globally defined MTU instead of new definition.
- Remove forward declaration of mlxbf_tmfifo_remove().
- Remove PAGE_ALIGN() for dma_alloc_coherent)().
- Remove the cast of "struct vring *".
- Check return result of test_and_set_bit().
- Add a macro mlxbt_vdev_to_tmfifo().
- Several other minor coding style comments.
Comment not applied:
- "Shouldn't be rather helper in EFI lib in kernel" Looks like efi.get_variable() is the way I found in the kernel tree.
- "this one is not protected anyhow? Potential race condition" In mlxbf_tmfifo_console_tx(), the spin-lock is used to protect the 'tx_buf' only, not the FIFO writes. So there is no race condition.
- "Is __packed needed in mlxbf_tmfifo_msg_hdr".
Yes, it is needed to make sure the structure is 8 bytes.
Fixes for comments from Vadim:
- Use tab in mlxbf-tmfifo-regs.h
- Use kernel-doc comments for struct mlxbf_tmfifo_msg_hdr and mlxbf_tmfifo_irq_info as well.
- Use _MAX instead of _CNT in the macro definition to be consistent.
- Fix the MODULE_LICENSE.
- Use BIT_ULL() instead of BIT().
- Remove argument of 'avail' for mlxbf_tmfifo_rxtx_header() and mlxbf_tmfifo_rxtx_word()
- Revise logic in mlxbf_tmfifo_rxtx_one_desc() to remove the WARN_ON().
- Change "union mlxbf_tmfifo_u64 u" to "union mlxbf_tmfifo_u64 buf" in mlxbf_tmfifo_rxtx_word().
- Change date type of vring_change from 'int' to 'bool'.
- Remove the blank lines after Signed-off.
- Don’t use declaration in the middle.
- Make the network header initialization in some more elegant way.
- Change label done to mlxbf_tmfifo_desc_done.
- Remove some unnecessary comments, and several other misc coding style comments.
- Simplify code logic in mlxbf_tmfifo_virtio_notify() New changes by Liming:
- Simplify the Rx/Tx function arguments to make it more readable.v8->v9:
Fixes for comments from Andy:
- Use modern devm_xxx() API instead.
Fixes for comments from Vadim:
- Split the Rx/Tx function into smaller funcitons.
- File name, copyright information.
- Function and variable name conversion.
- Local variable and indent coding styles.
- Remove unnecessary 'inline' declarations.
- Use devm_xxx() APIs.
- Move the efi_char16_t MAC address definition to global.
- Fix warnings reported by 'checkpatch --strict'.
- Fix warnings reported by 'make CF="-D__CHECK_ENDIAN__"'.
- Change select VIRTIO_xxx to depends on VIRTIO_ in Kconfig.
- Merge mlxbf_tmfifo_vdev_tx_buf_push() and mlxbf_tmfifo_vdev_tx_buf_pop().
- Add union to avoid casting between __le64 and u64.
- Several other misc coding style comments.
New changes by Liming:
- Removed the DT binding documentation since only ACPI is supported for now by UEFI on the SoC.
v8: Re-submit under drivers/platform/mellanox for the target-side
platform driver only.
v7: Added host side drivers into the same patch set.
v5~v6: Coding style fix.
v1~v4: Initial version for directory drivers/soc/mellanox.
--- drivers/platform/mellanox/Kconfig | 12 +- drivers/platform/mellanox/Makefile | 1 + drivers/platform/mellanox/mlxbf-tmfifo-regs.h | 63 ++ drivers/platform/mellanox/mlxbf-tmfifo.c | 1291 +++++++++++++++++++++++++ 4 files changed, 1366 insertions(+), 1 deletion(-) create mode 100644 drivers/platform/mellanox/mlxbf-tmfifo-regs.h create mode 100644 drivers/platform/mellanox/mlxbf-tmfifo.c
drivers/platform/mellanox/Kconfig +11 -1
@@ -5,7 +5,7 @@ menuconfig MELLANOX_PLATFORM bool "Platform support for Mellanox hardware" - depends on X86 || ARM || COMPILE_TEST + depends on X86 || ARM || ARM64 || COMPILE_TEST ---help--- Say Y here to get to see options for platform support for Mellanox systems. This option alone does not add any kernel code.
@@ -34,4 +34,14 @@ config MLXREG_IO to system resets operation, system reset causes monitoring and some kinds of mux selection. +config MLXBF_TMFIFO + tristate "Mellanox BlueField SoC TmFifo platform driver" + depends on ARM64 + depends on ACPI + depends on VIRTIO_CONSOLE && VIRTIO_NET + help + Say y here to enable TmFifo support. The TmFifo driver provides + platform driver support for the TmFifo which supports console + and networking based on the virtio framework. + endif # MELLANOX_PLATFORM
drivers/platform/mellanox/Makefile +1 -0
@@ -3,5 +3,6 @@ # Makefile for linux/drivers/platform/mellanox # Mellanox Platform-Specific Drivers # +obj-$(CONFIG_MLXBF_TMFIFO) += mlxbf-tmfifo.o obj-$(CONFIG_MLXREG_HOTPLUG) += mlxreg-hotplug.o obj-$(CONFIG_MLXREG_IO) += mlxreg-io.o
drivers/platform/mellanox/mlxbf-tmfifo-regs.h new file +63 -0
63 lines not on this page · raw message
drivers/platform/mellanox/mlxbf-tmfifo.c new file +1291 -0
1,291 lines not on this page · raw message
Signature · 1 line
1.8.3.1
Re: [PATCH v13] platform/mellanox: Add TmFifo driver for Mellanox BlueField Soc
Quoted 4 lines · Liming Sun
This commit adds the TmFifo platform driver for Mellanox BlueField Soc. TmFifo is a shared FIFO which enables external host machine to exchange data with the SoC via USB or PCIe. The driver is based on virtio framework and has console and network access enabled.
Thanks for an update. Almost good.
My comments below.
Meanwhile I pushed this to my review and testing queue, thanks!
drivers/platform/mellanox/mlxbf-tmfifo.c line 16
Quoted 9 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +9
-0+#include <linux/acpi.h> +#include <linux/bitfield.h> +#include <linux/circ_buf.h> +#include <linux/efi.h> +#include <linux/irq.h> +#include <linux/module.h> +#include <linux/mutex.h> +#include <linux/platform_device.h> +#include <linux/types.h>
Perhaps blank line here. Would be more clear that this is utilizing virtio framework.
Quoted 9 lines
(quoted diff) +8
-0+#include <linux/virtio_config.h> +#include <linux/virtio_console.h> +#include <linux/virtio_ids.h> +#include <linux/virtio_net.h> +#include <linux/virtio_ring.h> +/** + * mlxbf_tmfifo_msg_hdr - Structure of the TmFifo message header + * @type: message type
Review
Quoted 10 lines
(quoted diff) +10
-0+ * @len: payload length + * @u: 64-bit union data + */ +union mlxbf_tmfifo_msg_hdr { + struct { + u8 type; + __be16 len; + u8 unused[5]; + } __packed; + u64 data;
I'm not sure I understand how you can distinguish which field of union to use? Isn't here some type missed?
drivers/platform/mellanox/mlxbf-tmfifo.c line 193
Quoted 5 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +3
-0+}; +static u8 mlxbf_tmfifo_net_default_mac[ETH_ALEN ] = { +0x00 ,0x1A ,0xCA ,0xFF ,0xFF ,0x01 };
This should be two lines.
drivers/platform/mellanox/mlxbf-tmfifo.c line 204
Quoted 4 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +4
-0+/* Supported virtio-net features. */ +#define MLXBF_TMFIFO_NET_FEATURES (BIT_ULL(VIRTIO_NET_F_MTU) | \ + BIT_ULL(VIRTIO_NET_F_STATUS) | \ + BIT_ULL(VIRTIO_NET_F_MAC))
Better to write as
#define FOO \
(BIT(x) | BIT(y) ...)
I think I told this earlier?
Quoted 1 line
+/* Allocate vrings for the fifo. */
fifo -> FIFO (and check all occurrences)
Quoted 13 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +13
-0+static int mlxbf_tmfifo_alloc_vrings (struct mlxbf_tmfifo *fifo, +struct mlxbf_tmfifo_vdev *tm_vdev) +{ +struct mlxbf_tmfifo_vring *vring; +struct device *dev; +dma_addr_t dma; +int i, size; +void *va; + +for (i =0 ; i <ARRAY_SIZE (tm_vdev->vrings); i++) { + vring = &tm_vdev->vrings[i]; + vring->fifo = fifo; + vring->num =MLXBF_TMFIFO_VRING_SIZE ;
drivers/platform/mellanox/mlxbf-tmfifo.c line 230
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +9
-0+ vring->align =SMP_CACHE_BYTES ; + vring->index = i; + vring->vdev_id = tm_vdev->vdev.id.device; + dev = &tm_vdev->vdev.dev; + + size =vring_size (vring->num, vring->align); + va =dma_alloc_coherent (dev->parent, size, &dma,GFP_KERNEL ); +if (!va) { +dev_err (dev->parent,"dma_alloc_coherent failed\n" );
I don't see how this will free the allocated entries. I think I told about this either.
Quoted 6 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +6
-0+return -ENOMEM ; + } + + vring->va = va; + vring->dma = dma; + }
drivers/platform/mellanox/mlxbf-tmfifo.c
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +8
-0+ +return 0 ; +} +/* House-keeping timer. */ +static void mlxbf_tmfifo_timer (struct timer_list *arg) +{ + struct mlxbf_tmfifo *fifo = container_of(arg, struct mlxbf_tmfifo, + timer);
One line would be still good enough.
Quoted 8 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +8
-0+int more; + + more = !test_and_set_bit (MLXBF_TM_RX_HWM_IRQ , &fifo->pend_events) || + !test_and_set_bit (MLXBF_TM_TX_LWM_IRQ , &fifo->pend_events); + +if (more) +schedule_work (&fifo->work); +
drivers/platform/mellanox/mlxbf-tmfifo.c
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +8
-0+mod_timer (&fifo->timer, jiffies +MLXBF_TMFIFO_TIMER_INTERVAL ); +} + status = efi.get_variable (mlxbf_tmfifo_efi_name, &guid,NULL , &size, + buf); +if (status ==EFI_SUCCESS && size ==ETH_ALEN ) +ether_addr_copy (mac, buf); +else +memcpy (mac, mlxbf_tmfifo_net_default_mac,ETH_ALEN );
ether_addr_copy() as well.
drivers/platform/mellanox/mlxbf-tmfifo.c line 1214
Quoted 3 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +2
-0+} + fifo->pdev = pdev;
Do you really need to keep pdev there? Isn't struct device pointer enough?
drivers/platform/mellanox/mlxbf-tmfifo.c line 1237
Quoted 3 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +3
-0+/* Create the console vdev. */ + ret =mlxbf_tmfifo_create_vdev (&pdev->dev, fifo,VIRTIO_ID_CONSOLE ,0 , +NULL ,0 );
If you define temporary variable
struct device *dev = &pdev->dev;
these lines can be merged into one.
Quoted 2 lines
(quoted diff) +2
-0+ if (ret) + goto fail;
Signature · 2 lines
With Best Regards, Andy Shevchenko
RE: [PATCH v13] platform/mellanox: Add TmFifo driver for Mellanox BlueField Soc
Thanks Andy! I'll address the comments in v14.
Some question for the comment below:
Quoted 7 lines
Quoted 6 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +4
-0+ size =vring_size (vring->num, vring->align); + va =dma_alloc_coherent (dev->parent, size, &dma,GFP_KERNEL ); +if (!va) { +dev_err (dev->parent,"dma_alloc_coherent failed\n" );I don't see how this will free the allocated entries.
I think I told about this either.
When an error is returned, all the allocated entries will be released by the in the caller context by calling mlxbf_tmfifo_free_vrings(), like the logic below. Or do you prefer releasing the entries in mlxbf_tmfifo_alloc_vrings() instead?
1073 if (mlxbf_tmfifo_alloc_vrings(fifo, tm_vdev)) {
1074 dev_err(dev, "unable to allocate vring\n"); 1075 ret = -ENOMEM; 1076 goto vdev_fail;
1077 }
...
1097 vdev_fail:
1098 mlxbf_tmfifo_free_vrings(fifo, tm_vdev);
Regards,
Liming
Quoted 168 lines
-----Original Message-----
From: Andy Shevchenko <[email protected]>
Sent: Friday, April 5, 2019 11:44 AM
To: Liming Sun <[email protected]>
Cc: David Woods <[email protected]>; Andy Shevchenko <[email protected]>; Darren Hart <[email protected]>; Vadim Pasternak <[email protected]>; Linux Kernel Mailing List <[email protected]>; Platform Driver <platform-driver- [email protected]>
Subject: Re: [PATCH v13] platform/mellanox: Add TmFifo driver for Mellanox BlueField SocQuoted 4 lines · Liming Sun
This commit adds the TmFifo platform driver for Mellanox BlueField Soc. TmFifo is a shared FIFO which enables external host machine to exchange data with the SoC via USB or PCIe. The driver is based on virtio framework and has console and network access enabled.
Thanks for an update. Almost good.
My comments below.Meanwhile I pushed this to my review and testing queue, thanks!
drivers/platform/mellanox/mlxbf-tmfifo.c line 16
Quoted 9 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +9
-0+#include <linux/acpi.h> +#include <linux/bitfield.h> +#include <linux/circ_buf.h> +#include <linux/efi.h> +#include <linux/irq.h> +#include <linux/module.h> +#include <linux/mutex.h> +#include <linux/platform_device.h> +#include <linux/types.h> Perhaps blank line here. Would be more clear that this is utilizing virtio framework.
Quoted 9 lines
(quoted diff) +8
-0+#include <linux/virtio_config.h> +#include <linux/virtio_console.h> +#include <linux/virtio_ids.h> +#include <linux/virtio_net.h> +#include <linux/virtio_ring.h> +/** + * mlxbf_tmfifo_msg_hdr - Structure of the TmFifo message header + * @type: message typeReview
Quoted 10 lines
(quoted diff) +10
-0+ * @len: payload length + * @u: 64-bit union data + */ +union mlxbf_tmfifo_msg_hdr { + struct { + u8 type; + __be16 len; + u8 unused[5]; + } __packed; + u64 data;I'm not sure I understand how you can distinguish which field of union to use? Isn't here some type missed?
drivers/platform/mellanox/mlxbf-tmfifo.c line 193
Quoted 5 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +3
-0+}; +static u8 mlxbf_tmfifo_net_default_mac[ETH_ALEN ] = { +0x00 ,0x1A ,0xCA ,0xFF ,0xFF ,0x01 };This should be two lines.
drivers/platform/mellanox/mlxbf-tmfifo.c line 204
Quoted 4 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +4
-0+/* Supported virtio-net features. */ +#define MLXBF_TMFIFO_NET_FEATURES (BIT_ULL(VIRTIO_NET_F_MTU) | \ + BIT_ULL(VIRTIO_NET_F_STATUS) | \ + BIT_ULL(VIRTIO_NET_F_MAC))Better to write as
#define FOO \
(BIT(x) | BIT(y) ...)I think I told this earlier?
Quoted 1 line
+/* Allocate vrings for the fifo. */
fifo -> FIFO (and check all occurrences)
Quoted 13 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +13
-0+static int mlxbf_tmfifo_alloc_vrings (struct mlxbf_tmfifo *fifo, +struct mlxbf_tmfifo_vdev *tm_vdev) +{ +struct mlxbf_tmfifo_vring *vring; +struct device *dev; +dma_addr_t dma; +int i, size; +void *va; + +for (i =0 ; i <ARRAY_SIZE (tm_vdev->vrings); i++) { + vring = &tm_vdev->vrings[i]; + vring->fifo = fifo; + vring->num =MLXBF_TMFIFO_VRING_SIZE ;drivers/platform/mellanox/mlxbf-tmfifo.c line 230
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +9
-0+ vring->align =SMP_CACHE_BYTES ; + vring->index = i; + vring->vdev_id = tm_vdev->vdev.id.device; + dev = &tm_vdev->vdev.dev; + + size =vring_size (vring->num, vring->align); + va =dma_alloc_coherent (dev->parent, size, &dma,GFP_KERNEL ); +if (!va) { +dev_err (dev->parent,"dma_alloc_coherent failed\n" );I don't see how this will free the allocated entries. I think I told about this either.
Quoted 6 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +6
-0+return -ENOMEM ; + } + + vring->va = va; + vring->dma = dma; + }drivers/platform/mellanox/mlxbf-tmfifo.c
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +8
-0+ +return 0 ; +} +/* House-keeping timer. */ +static void mlxbf_tmfifo_timer (struct timer_list *arg) +{ + struct mlxbf_tmfifo *fifo = container_of(arg, struct mlxbf_tmfifo, + timer);One line would be still good enough.
Quoted 8 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +8
-0+int more; + + more = !test_and_set_bit (MLXBF_TM_RX_HWM_IRQ , &fifo->pend_events) || + !test_and_set_bit (MLXBF_TM_TX_LWM_IRQ , &fifo->pend_events); + +if (more) +schedule_work (&fifo->work); +drivers/platform/mellanox/mlxbf-tmfifo.c
Quoted 10 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +8
-0+mod_timer (&fifo->timer, jiffies +MLXBF_TMFIFO_TIMER_INTERVAL ); +} + status = efi.get_variable (mlxbf_tmfifo_efi_name, &guid,NULL , &size, + buf); +if (status ==EFI_SUCCESS && size ==ETH_ALEN ) +ether_addr_copy (mac, buf); +else +memcpy (mac, mlxbf_tmfifo_net_default_mac,ETH_ALEN );
ether_addr_copy()as well.drivers/platform/mellanox/mlxbf-tmfifo.c line 1214
Quoted 3 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +2
-0+} + fifo->pdev = pdev;Do you really need to keep pdev there? Isn't struct device pointer enough?
drivers/platform/mellanox/mlxbf-tmfifo.c line 1237
Quoted 3 lines
drivers/platform/mellanox/mlxbf-tmfifo.c new file +3
-0+/* Create the console vdev. */ + ret =mlxbf_tmfifo_create_vdev (&pdev->dev, fifo,VIRTIO_ID_CONSOLE ,0 , +NULL ,0 );If you define temporary variable
struct device *dev =&pdev->dev;
these lines can be merged into one.Review
Quoted 2 lines
(quoted diff) +2
-0+ if (ret) + goto fail;--
With Best Regards,
Andy Shevchenko