Add Fieldbus subsystem + support HMS Profinet card
Subsystems (2)
v4 cover Add Fieldbus subsystem + support HMS Profinet card
This patch:
1. adds a Fieldbus subsystem
2. adds support for the HMS Industrial Networks AB Profinet card.
1. Fieldbus subsystem
---------------------
Fieldbus device (client) adapters allow data exchange with a PLC aka. "Fieldbus Controller" over a fieldbus (Profinet, FLNet, etc.) They are typically used when a Linux device wants to expose itself as an actuator, motor, console light, switch, etc. over the fieldbus. The framework is designed to provide a generic interface to Fieldbus Devices from both the Linux Kernel and the userspace.
2. Add support for HMS Profinet Card
------------------------------------
Profinet is an industry technical standard for data communication over Industrial Ethernet, designed for collecting data from, and controlling, equipment in industrial systems, with a particular strength in delivering data under tight time constraints (on the order of 1ms or less).
The profinet card itself is connected to the system via an industrial bus called 'anybus'.
I have followed the bus driver/client driver pattern, and created an anybus bus driver, plus a client driver for the profinet card.
In case this patch set gets (eventually) accepted, drivers for other anybus client cards may follow: flnet, cc-link, ...
The anybus slot on the host is located on an 'anybus bridge', which is custom h/w designed by arcx. Its driver is modeled as a misc device, which exposes a dual reset controller, plus a power readout unrelated to the anybus.
v4:
general
create fieldbus_dev subsystem, with standardized 'simple'
userspace interface (sysfs + cdev)
remove redundant __packed keywords
use __be16/32 types wherever values are explicitly big-endian
hms-profinet:
remove configuration code, and uapi headers: not supported (yet)
when registering as a fieldbus_dev.
anybuss-host:
use struct kref to reference-count tasks
replace busy loops with usleep_range() loop after 10 tries use threaded irq so time_before_eq(jiffies, timeout) will
continue to work
allow client devices to be assigned a devicetree node,
in the same way as pci/mmc/...
v3:
devicetree-bindings
adding the vendor prefix is now a separate commit
anybus-bridge:
moved misc driver to drivers/bus/ converted of_gpio_* to gpiod_* abstractions can power readout is now a fixed-voltage regulator
anybuss-host:
converted refcounts from atomic_t to refcount_t fixed potential use-after-free
hms-profinet:
applied minor kernel build robot suggestion
v2:
added architecture overview comments to host driver completely reworked anybus-bridge driver, it becomes a reset controller anybuss-host driver now needs devicetree entry, link to reset controller I will hold off on kernel-doc until the overall architecture gets
more validation / approval
fixed Kconfig, comment-style, document ioctl magic numbers removed redundant pwm dependency
renamed enable-gpios to reset-gpios
stop driving reset-gpio after unloading driver
use interrupt-parent / interrupts method to describe interrupts
in the devicetree
convert references 'i.MX WEIM parallel bus' to 'parallel bus' replace devicetree functions with more generic platform_get_resource()
platform_get_irq()
added device unique data to add_device_randomness()
v1:
first shot
Sven Van Asbroeck (7):
fieldbus_dev: add Fieldbus Device subsystem.
fieldbus: support the Arcx anybus bridge
dt-bindings: Add vendor prefix for arcx / Archronix
dt-bindings: anybus-bridge: document devicetree binding
fieldbus: support HMS Anybus-S bus
dt-bindings: anybuss-host: document devicetree binding
fieldbus_dev: support HMS Profinet IRT industrial controller
Documentation/ABI/testing/fieldbus-dev-cdev | 31 + .../ABI/testing/sysfs-class-fieldbus-dev | 63 + .../bindings/fieldbus/arcx,anybus-bridge.txt | 34 + .../bindings/fieldbus/arcx,anybuss-host.txt | 66 + .../devicetree/bindings/vendor-prefixes.txt | 1 + Documentation/fieldbus_dev/fieldbus_dev.txt | 66 + drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/fieldbus/Kconfig | 56 + drivers/fieldbus/Makefile | 12 + drivers/fieldbus/anybus-bridge.c | 321 ++++ drivers/fieldbus/anybuss-host.c | 1497 +++++++++++++++++ drivers/fieldbus/dev_core.c | 355 ++++ drivers/fieldbus/hms-profinet.c | 223 +++ include/linux/anybuss-client.h | 104 ++ include/linux/fieldbus_dev.h | 106 ++ 16 files changed, 2938 insertions(+) create mode 100644 Documentation/ABI/testing/fieldbus-dev-cdev create mode 100644 Documentation/ABI/testing/sysfs-class-fieldbus-dev create mode 100644 Documentation/devicetree/bindings/fieldbus/arcx,anybus-bridge.txt create mode 100644 Documentation/devicetree/bindings/fieldbus/arcx,anybuss-host.txt create mode 100644 Documentation/fieldbus_dev/fieldbus_dev.txt create mode 100644 drivers/fieldbus/Kconfig create mode 100644 drivers/fieldbus/Makefile create mode 100644 drivers/fieldbus/anybus-bridge.c create mode 100644 drivers/fieldbus/anybuss-host.c create mode 100644 drivers/fieldbus/dev_core.c create mode 100644 drivers/fieldbus/hms-profinet.c create mode 100644 include/linux/anybuss-client.h create mode 100644 include/linux/fieldbus_dev.h
Signature · 1 line
2.17.1
PATCH v4 1/7 fieldbus_dev: add Fieldbus Device subsystem.
Fieldbus device (client) adapters allow data exchange with a PLC aka. "Fieldbus Controller" over a fieldbus (Profinet, FLNet, etc.)
They are typically used when a Linux device wants to expose itself as an actuator, motor, console light, switch, etc. over the fieldbus.
This framework is designed to provide a generic interface to Fieldbus Devices from both the Linux Kernel and the userspace.
--- Documentation/ABI/testing/fieldbus-dev-cdev | 31 ++ .../ABI/testing/sysfs-class-fieldbus-dev | 63 ++++ Documentation/fieldbus_dev/fieldbus_dev.txt | 66 ++++ drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/fieldbus/Kconfig | 19 + drivers/fieldbus/Makefile | 9 + drivers/fieldbus/dev_core.c | 355 ++++++++++++++++++ include/linux/fieldbus_dev.h | 106 ++++++ 9 files changed, 652 insertions(+) create mode 100644 Documentation/ABI/testing/fieldbus-dev-cdev create mode 100644 Documentation/ABI/testing/sysfs-class-fieldbus-dev create mode 100644 Documentation/fieldbus_dev/fieldbus_dev.txt create mode 100644 drivers/fieldbus/Kconfig create mode 100644 drivers/fieldbus/Makefile create mode 100644 drivers/fieldbus/dev_core.c create mode 100644 include/linux/fieldbus_dev.h
Documentation/ABI/testing/fieldbus-dev-cdev new file +31 -0
@@ -0,0 +1,31 @@ +What: /dev/fieldbus_devX +Date: December 2018 +KernelVersion: 4.21 +Contact: Sven Van Asbroeck <[email protected]> +Description: + The cdev interface to drivers for Fieldbus Device Memory + (aka. Process Memory). + + The following file operations are supported: + + open(2) + Create an I/O context associated with the file descriptor. + + read(2) + Read from Process Memory's "read area". + Clears POLLERR | POLLPRI from the file descriptor. + + write(2) + Write to Process Memory's "write area". + + poll(2), select(2), epoll_wait(2) etc. + When a "Process Memory Read Area Changed" event occurs, + POLLERR | POLLPRI will be set on the file descriptor. + Note that POLLIN | POLLOUT events are always set, because the + process memory area is always readable and writable. + + close(2) + Free up the I/O context that was associated + with the file descriptor. + +Users: TBD
Documentation/ABI/testing/sysfs-class-fieldbus-dev new file +63 -0
63 lines not on this page · raw message
Documentation/fieldbus_dev/fieldbus_dev.txt new file +66 -0
66 lines not on this page · raw message
drivers/Kconfig +2 -0
@@ -219,6 +219,8 @@ source "drivers/visorbus/Kconfig" source "drivers/siox/Kconfig" +source "drivers/fieldbus/Kconfig" + source "drivers/slimbus/Kconfig" endmenu
drivers/Makefile +1 -0
@@ -187,4 +187,5 @@ obj-$(CONFIG_TEE) += tee/ obj-$(CONFIG_MULTIPLEXER) += mux/ obj-$(CONFIG_UNISYS_VISORBUS) += visorbus/ obj-$(CONFIG_SIOX) += siox/ +obj-$(CONFIG_FIELDBUS_DEV) += fieldbus/ obj-$(CONFIG_GNSS) += gnss/
drivers/fieldbus/Kconfig new file +19 -0
@@ -0,0 +1,19 @@ +menuconfig FIELDBUS_DEV + bool "Fieldbus Device Support" + help + Support for Fieldbus Device Adapters. + + Fieldbus device (client) adapters allow data exchange with a PLC aka. + "Fieldbus Controller" over a fieldbus (Profinet, FLNet, etc.) + + They are typically used when a Linux device wants to expose itself + as an actuator, motor, console light, switch, etc. over the fieldbus. + + This framework is designed to provide a generic interface to Fieldbus + Devices from both the Linux Kernel and the userspace. + + If unsure, say no. + +if FIELDBUS_DEV + +endif
drivers/fieldbus/Makefile new file +9 -0
@@ -0,0 +1,9 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Makefile for fieldbus_dev drivers. +# + +obj-$(CONFIG_FIELDBUS_DEV) += fieldbus_dev_core.o +fieldbus_dev_core-y := dev_core.o + +# Devices
drivers/fieldbus/dev_core.c new file +355 -0
355 lines not on this page · raw message
include/linux/fieldbus_dev.h new file +106 -0
106 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v4 2/7 fieldbus: support the Arcx anybus bridge
In reply to [email protected]Add a driver for the Arcx anybus bridge.
This chip embeds up to two Anybus-S application connectors (slots), and connects to the SoC via a parallel memory bus. There is also a CAN power readout, unrelated to the Anybus, modelled as a regulator.
--- drivers/fieldbus/Kconfig | 10 + drivers/fieldbus/Makefile | 1 + drivers/fieldbus/anybus-bridge.c | 321 +++++++++++++++++++++++++++++++ 3 files changed, 332 insertions(+) create mode 100644 drivers/fieldbus/anybus-bridge.c
drivers/fieldbus/Kconfig +10 -0
@@ -16,4 +16,14 @@ menuconfig FIELDBUS_DEV if FIELDBUS_DEV +config ARCX_ANYBUS_BRIDGE + tristate "Arcx Anybus-S Bridge" + depends on OF && GPIOLIB + help + Select this to get support for the Arcx Anybus bridge. + It connects to the SoC via a parallel memory bus, and + embeds up to two Anybus-S application connectors (slots). + There is also a CAN power readout, unrelated to the Anybus, + modelled as a regulator. + endif
drivers/fieldbus/Makefile +1 -0
@@ -7,3 +7,4 @@ obj-$(CONFIG_FIELDBUS_DEV) += fieldbus_dev_core.o fieldbus_dev_core-y := dev_core.o # Devices +obj-$(CONFIG_ARCX_ANYBUS_BRIDGE) += anybus-bridge.o
drivers/fieldbus/anybus-bridge.c new file +321 -0
321 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v4 3/7 dt-bindings: Add vendor prefix for arcx / Archronix
In reply to [email protected]arcx Inc. is an engineering company which provides advanced embedded systems and consulting services.
Archronix is a technology design and product engineering firm specializing in hardware control systems and enabling software. Clients include OEM's in the transportation, aerospace, medical and commercial sectors.
Websites:
http://www.arcx.com/ http://www.archronix.com/
--- Documentation/devicetree/bindings/vendor-prefixes.txt | 1 + 1 file changed, 1 insertion(+)
Documentation/devicetree/bindings/vendor-prefixes.txt +1 -0
@@ -35,6 +35,7 @@ aptina Aptina Imaging arasan Arasan Chip Systems archermind ArcherMind Technology (Nanjing) Co., Ltd. arctic Arctic Sand +arcx arcx Inc. / Archronix Inc. aries Aries Embedded GmbH arm ARM Ltd. armadeus ARMadeus Systems SARL
Signature · 1 line
2.17.1
PATCH v4 4/7 dt-bindings: anybus-bridge: document devicetree binding
In reply to [email protected]This patch adds devicetree binding documentation for the Arcx anybus bridge.
--- .../bindings/fieldbus/arcx,anybus-bridge.txt | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Documentation/devicetree/bindings/fieldbus/arcx,anybus-bridge.txt
Documentation/devicetree/bindings/fieldbus/arcx,anybus-bridge.txt new file +34 -0
@@ -0,0 +1,34 @@ +* Arcx anybus bridge + +This chip communicates with the SoC over a parallel bus. It is +expected that its Device Tree node is specified as the child of a node +corresponding to the parallel bus used for communication. + +Required properties: + + - compatible : The following chip-specific string: + "arcx,anybus-bridge" + + - reg : bus memory area where the cpld registers are located. + + - reset-gpios : the GPIO pin connected to the reset line of the bridge. + + - #reset-cells : Must be 1. + this bridge is a reset provider to its two embedded Anybus-S slots. + +Example of usage: + +This example places the bridge on top of the i.MX WEIM parallel bus, see: +Documentation/devicetree/bindings/bus/imx-weim.txt + +&weim { + anybus_bridge: bridge@0,0 { + compatible = "arcx,anybus-bridge"; + reg = <0 0 0x100>; + reset-gpios = <&gpio5 2 GPIO_ACTIVE_HIGH>; + #reset-cells = <1>; + /* fsl,weim-cs-timing is a i.MX WEIM bus specific property */ + fsl,weim-cs-timing = <0x024400b1 0x00001010 0x20081100 + 0x00000000 0xa0000240 0x00000000>; + }; +};
Signature · 1 line
2.17.1
PATCH v4 5/7 fieldbus: support HMS Anybus-S bus
In reply to [email protected]The Anybus-S/Anybus-M is a series of interchangeable fieldbus communication modules featuring on board memory and processing power. All software and hardware functionality required to communicate on the fieldbus is incorporated in the module itself, allowing the application to focus on other tasks.
Typical applications are frequency inverters, HMI and visualization devices, instruments, scales, robotics, PLC’s and intelligent measuring devices.
Official documentation:
https://www.anybus.com/docs/librariesprovider7/default-document-library/
manuals-design-guides/hms-hmsi-27-275.pdf
--- drivers/fieldbus/Kconfig | 10 + drivers/fieldbus/Makefile | 1 + drivers/fieldbus/anybuss-host.c | 1497 +++++++++++++++++++++++++++++++ include/linux/anybuss-client.h | 104 +++ 4 files changed, 1612 insertions(+) create mode 100644 drivers/fieldbus/anybuss-host.c create mode 100644 include/linux/anybuss-client.h
drivers/fieldbus/Kconfig +10 -0
@@ -26,4 +26,14 @@ config ARCX_ANYBUS_BRIDGE There is also a CAN power readout, unrelated to the Anybus, modelled as a regulator. +config HMS_ANYBUSS_HOST + tristate "HMS Anybus-S Host/Bus Driver" + select REGMAP + depends on OF + help + Driver for the HMS Industrial Networks Anybus-S bus. + You can attach Anybus-S compatible cards to it, which + typically provide fieldbus and industrial ethernet + functionality. + endif
drivers/fieldbus/Makefile +1 -0
@@ -8,3 +8,4 @@ fieldbus_dev_core-y := dev_core.o # Devices obj-$(CONFIG_ARCX_ANYBUS_BRIDGE) += anybus-bridge.o +obj-$(CONFIG_HMS_ANYBUSS_HOST) += anybuss-host.o
drivers/fieldbus/anybuss-host.c new file +1497 -0
1,497 lines not on this page · raw message
include/linux/anybuss-client.h new file +104 -0
104 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v4 6/7 dt-bindings: anybuss-host: document devicetree binding
In reply to [email protected]This patch adds devicetree binding documentation for the Arcx Anybus-S host.
--- .../bindings/fieldbus/arcx,anybuss-host.txt | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 Documentation/devicetree/bindings/fieldbus/arcx,anybuss-host.txt
Documentation/devicetree/bindings/fieldbus/arcx,anybuss-host.txt new file +66 -0
@@ -0,0 +1,66 @@ +* Arcx Anybus-S host + +This host communicates with the SoC over a parallel bus. It is +expected that its Device Tree node is specified as the child of a node +corresponding to the parallel bus used for communication. + +Required properties: +-------------------- + + - compatible : The following string: + "arcx,anybuss-host" + + - reg : bus memory area where the Anybus-S host dpram is located. + + - interrupts : interrupt connected to the Anybus-S host interrupt line. + Generic interrupt client node bindings are described in + interrupt-controller/interrupts.txt + + - resets : the reset line associated with the Anybus-S host. + +Optional: use of subnodes +------------------------- + +The card connected to a host may need additional properties. These can be +specified in subnodes to the host node. + +The subnodes are identified by the standard 'reg' property. Which information +exactly can be specified depends on the bindings for the function driver +for the subnode. + +Required host node properties when using subnodes: +- #address-cells: should be one. +- #size-cells: should be zero. + +Required subnode properties: +- reg: Must contain the fieldbus type of the card this subnode describes. + +Example of usage: +----------------- + +This example places the Anybus-S host on top of the i.MX WEIM parallel bus, see: +Documentation/devicetree/bindings/bus/imx-weim.txt + +&weim { + anybus-host@0 { + compatible = "arcx,anybuss-host"; + reg = <0 0x400000 0x800>; + interrupt-parent = <&gpio1>; + interrupts = <1 IRQ_TYPE_LEVEL_LOW>; + resets = <&anybus_bridge 0>; + /* fsl,weim-cs-timing is a i.MX WEIM bus specific property */ + fsl,weim-cs-timing = <0x024400b1 0x00001010 0x20081100 + 0x00000000 0xa0000240 0x00000000>; + /* + * optional subnode for a profinet card + * (fieldbus type = 0x0089) + */ + #address-cells = <1>; + #size-cells = <0>; + profinet@0 { + reg = <0x0089>; + /* profinet specific properties go here */ + }; + }; + +};
Signature · 1 line
2.17.1
PATCH v4 7/7 fieldbus_dev: support HMS Profinet IRT industrial controller
In reply to [email protected]The Anybus-S PROFINET IRT communication module provides instant integration to any Ethernet based LAN via SMTP, FTP, HTTP as well as PROFINET and Modbus-TCP. Additional protocols can be implemented on top of TCP/IP or UDP using the transparent socket interface.
Official documentation:
https://www.anybus.com/docs/librariesprovider7/default-document-library
/manuals-design-guides/hms-hmsi-168-52.pdf
This implementation is an Anybus-S client driver, designed to be instantiated by the Anybus-S bus driver when it discovers the Profinet card.
If loaded successfully, the driver registers itself as a fieldbus_dev, and userspace can access it through the fieldbus_dev interface.
--- drivers/fieldbus/Kconfig | 17 +++ drivers/fieldbus/Makefile | 1 + drivers/fieldbus/hms-profinet.c | 223 ++++++++++++++++++++++++++++++++ 3 files changed, 241 insertions(+) create mode 100644 drivers/fieldbus/hms-profinet.c
drivers/fieldbus/Kconfig +17 -0
@@ -36,4 +36,21 @@ config HMS_ANYBUSS_HOST typically provide fieldbus and industrial ethernet functionality. +config HMS_PROFINET + tristate "HMS Profinet IRT Controller (Anybus-S)" + depends on FIELDBUS_DEV + select HMS_ANYBUSS_HOST + help + If you say yes here you get support for the HMS Industrial + Networks Profinet IRT Controller. + + It will be registered with the kernel as a fieldbus_dev, + so userspace can interact with it via the fieldbus_dev userspace + interface(s). + + This driver can also be built as a module. If so, the module + will be called hms-profinet. + + If unsure, say N. + endif
drivers/fieldbus/Makefile +1 -0
@@ -9,3 +9,4 @@ fieldbus_dev_core-y := dev_core.o # Devices obj-$(CONFIG_ARCX_ANYBUS_BRIDGE) += anybus-bridge.o obj-$(CONFIG_HMS_ANYBUSS_HOST) += anybuss-host.o +obj-$(CONFIG_HMS_PROFINET) += hms-profinet.o
drivers/fieldbus/hms-profinet.c new file +223 -0
223 lines not on this page · raw message
Signature · 1 line
2.17.1
Rob Herring
maintainerRe: [PATCH anybus v4 6/7] dt-bindings: anybuss-host: document devicetree binding
In reply to [email protected]Quoted 55 lines · On Wed, Nov 21, 2018 at 10:07:08AM -0500, [email protected] wrote:
This patch adds devicetree binding documentation for the Arcx Anybus-S host.
Signed-off-by Sven Van Asbroeck <[email protected]>--- .../bindings/fieldbus/arcx,anybuss-host.txt | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 Documentation/devicetree/bindings/fieldbus/arcx,anybuss-host.txtDocumentation/devicetree/bindings/fieldbus/arcx,anybuss-host.txt new file +40
-0@@ -0,0 +1,66 @@ +* Arcx Anybus-S host + +This host communicates with the SoC over a parallel bus. It is +expected that its Device Tree node is specified as the child of a node +corresponding to the parallel bus used for communication. + +Required properties: +-------------------- + + - compatible : The following string: + "arcx,anybuss-host" + + - reg : bus memory area where the Anybus-S host dpram is located. + + - interrupts : interrupt connected to the Anybus-S host interrupt line. + Generic interrupt client node bindings are described in + interrupt-controller/interrupts.txt + + - resets : the reset line associated with the Anybus-S host. + +Optional: use of subnodes +------------------------- + +The card connected to a host may need additional properties. These can be +specified in subnodes to the host node. + +The subnodes are identified by the standard 'reg' property. Which information +exactly can be specified depends on the bindings for the function driver +for the subnode. + +Required host node properties when using subnodes: +- #address-cells: should be one. +- #size-cells: should be zero. + +Required subnode properties: +- reg: Must contain the fieldbus type of the card this subnode describes. + +Example of usage: +----------------- +
Documentation/devicetree/bindings/fieldbus/arcx,anybuss-host.txt line 50
Quoted 10 lines
Documentation/devicetree/bindings/fieldbus/arcx,anybuss-host.txt new file +10
-0+This example places the Anybus-S host on top of the i.MX WEIM parallel bus, see: +Documentation/devicetree/bindings/bus/imx-weim.txt + +&weim { + anybus-host@0 { + compatible = "arcx,anybuss-host"; + reg = <0 0x400000 0x800>; + interrupt-parent = <&gpio1>; + interrupts = <1 IRQ_TYPE_LEVEL_LOW>; + resets = <&anybus_bridge 0>;
I'm still not clear what a bridge vs. host is. Both examples are on WEIM bus CS0?
Documentation/devicetree/bindings/fieldbus/arcx,anybuss-host.txt line 60
Quoted 10 lines
Documentation/devicetree/bindings/fieldbus/arcx,anybuss-host.txt new file +10
-0+ /* fsl,weim-cs-timing is a i.MX WEIM bus specific property */ + fsl,weim-cs-timing = <0x024400b1 0x00001010 0x20081100 + 0x00000000 0xa0000240 0x00000000>; + /* + * optional subnode for a profinet card + * (fieldbus type = 0x0089) + */ + #address-cells = <1>; + #size-cells = <0>; + profinet@0 {
Unit-addresses are based on 'reg'. So this should either be '89' or based on a definition for the bus (e.g. PCI uses dev and func).
Documentation/devicetree/bindings/fieldbus/arcx,anybuss-host.txt line 61
Quoted 1 line
Documentation/devicetree/bindings/fieldbus/arcx,anybuss-host.txt new file +1
-0+ reg = <0x0089>;
Is fieldbus type how one addresses a device on the bus?
Quoted 8 lines
Documentation/devicetree/bindings/fieldbus/arcx,anybuss-host.txt new file +5
-0+ /* profinet specific properties go here */ + }; + }; + +};Signature · 1 line
2.17.1
Re: [PATCH anybus v4 1/7] fieldbus_dev: add Fieldbus Device subsystem.
In reply to [email protected]Quoted 10 lines · On Wed, Nov 21, 2018 at 10:07:03AM -0500, [email protected] wrote:
Fieldbus device (client) adapters allow data exchange with a PLC aka. "Fieldbus Controller" over a fieldbus (Profinet, FLNet, etc.)
They are typically used when a Linux device wants to expose itself as an actuator, motor, console light, switch, etc. over the fieldbus.
This framework is designed to provide a generic interface to Fieldbus Devices from both the Linux Kernel and the userspace.
Signed-off-by Sven Van Asbroeck <[email protected]>
License nit:
drivers/fieldbus/dev_core.c line 1
Quoted 4 lines
drivers/fieldbus/dev_core.c new file +1
-0@@ -0,0 +1,355 @@ +// SPDX-License-Identifier: GPL-2.0
That's great, but then you write:
drivers/fieldbus/dev_core.c line 355
Quoted 1 line
drivers/fieldbus/dev_core.c new file +1
-0+MODULE_LICENSE ("GPL" );
Which means "GPLv2+". So this MODULE_LICENSE() should be "GPL v2", right?
thanks,
greg k-h
Re: [PATCH anybus v4 1/7] fieldbus_dev: add Fieldbus Device subsystem.
In reply to [email protected]Quoted 10 lines · On Wed, Nov 21, 2018 at 10:07:03AM -0500, [email protected] wrote:
Fieldbus device (client) adapters allow data exchange with a PLC aka. "Fieldbus Controller" over a fieldbus (Profinet, FLNet, etc.)
They are typically used when a Linux device wants to expose itself as an actuator, motor, console light, switch, etc. over the fieldbus.
This framework is designed to provide a generic interface to Fieldbus Devices from both the Linux Kernel and the userspace.
Signed-off-by Sven Van Asbroeck <[email protected]>
Your "From:" line does not match this address or name at all, which means no one can apply this :(
Please fix for your next round of patches.
thanks,
greg k-h
Re: [PATCH anybus v4 1/7] fieldbus_dev: add Fieldbus Device subsystem.
In reply to [email protected]Quoted 24 lines · On Wed, Nov 21, 2018 at 10:07:03AM -0500, [email protected] wrote:
drivers/fieldbus/dev_core.c new file +24
-0+static struct attribute *fieldbus_attrs[] = { + &dev_attr_enabled.attr, + &dev_attr_card_name.attr, + &dev_attr_fieldbus_id.attr, + &dev_attr_read_area_size.attr, + &dev_attr_write_area_size.attr, + &dev_attr_online.attr, + &dev_attr_fieldbus_type.attr, +NULL , +}; + +static umode_t fieldbus_is_visible (struct kobject *kobj,struct attribute *attr, +int n) +{ + struct device *dev = container_of(kobj, struct device, kobj); +struct fieldbus_dev *fb =dev_get_drvdata (dev); +umode_t mode = attr->mode; + +if (attr == &dev_attr_enabled.attr) { + mode =0 ; +if (fb->enable_get) + mode |=0444 ; +if (fb->simple_enable_set) + mode |=0200 ;
drivers/fieldbus/dev_core.c line 158
Quoted 10 lines
drivers/fieldbus/dev_core.c new file +10
-0+ } + +return mode; +} + +static const struct attribute_group fieldbus_group = { + .attrs = fieldbus_attrs, + .is_visible = fieldbus_is_visible, +}; +__ATTRIBUTE_GROUPS (fieldbus);
Why not just use ATTRIBUTE_GROUPS()?
Quoted 11 lines
drivers/fieldbus/dev_core.c new file +11
-0+static int __fieldbus_dev_register (struct fieldbus_dev *fb) +{ +dev_t devno; +int err; + +if (!fb) +return -EINVAL ; +if (!fb->read_area || !fb->write_area || !fb->fieldbus_id_get) +return -EINVAL ; + fb->id =ida_simple_get (&fieldbus_ida,0 ,MAX_FIELDBUSES ,GFP_KERNEL ); +if (fb->id <0 )
drivers/fieldbus/dev_core.c line 290
Quoted 10 lines
drivers/fieldbus/dev_core.c new file +10
-0+return fb->id; + devno =MKDEV (MAJOR (fieldbus_devt), fb->id); +init_waitqueue_head (&fb->dc_wq); +cdev_init (&fb->cdev, &fieldbus_fops); + err =cdev_add (&fb->cdev, devno,1 ); +if (err) { +pr_err ("fieldbus_dev%d unable to add device %d:%d\n" , + fb->id,MAJOR (fieldbus_devt), fb->id); + goto err_cdev; + }
Why do you have a static cdev?
drivers/fieldbus/dev_core.c line 297
Quoted 7 lines
drivers/fieldbus/dev_core.c new file +7
-0+ fb->dev =device_create (&fieldbus_class, fb->parent, devno, fb, +"fieldbus_dev%d" , fb->id); +if (IS_ERR (fb->dev)) { + err =PTR_ERR (fb->dev); + goto err_dev_create; + } + fb->online_sd =sysfs_get_dirent (fb->dev->kobj.sd,"online" );
Ick, what? Why? Why are you messing around with a raw sysfs attribute?
Also, you are creating sysfs files and you are not documenting any of them in Documentation/ABI/ which is not allowed. Please add that to this patch for the next round.
thanks,
greg k-h
Re: [PATCH anybus v4 6/7] dt-bindings: anybuss-host: document devicetree binding
In reply to Rob HerringRob, thank you so much for the review !
Quoted 6 lines · Rob Herring
Unit-addresses are based on 'reg'. So this should either be '89' or based on a definition for the bus (e.g. PCI uses dev and func).
Quoted 1 line
+ reg = <
0x0089>;Is fieldbus type how one addresses a device on the bus?
I'm afraid not. Anybus cards don't have an address, because only a single card can be connected to an anybus at a time.
Fieldbus type defines the type/functionality of the connected card. Like pci device ids.
The current patchset allows devicetree nodes to be provided depending on the type of card connected to the bus. It identifies the card by type, not location.
Is this not desired / allowed ?
Quoted 2 lines
I'm still not clear what a bridge vs. host is. Both examples are on WEIM bus CS0?
I agree that the terminology is too confusing. I'm looking to change it.
Let's compare current anybus with a well-established bus architecture like pci:
pci anybus
--------------------------------------------------------------------------------
Common bus code (spec), pci/pci_driver.c fieldbus/anybuss-host.c
calls bus_register() must be parallel bus
subnode
no of compatible has of compatible
--------------------------------------------------------------------------------
Device on bus, calls
XXX_client_driver_register() hwmon/k8temp.c fieldbus/hms-profinet.c
--------------------------------------------------------------------------------
Controller, silicon driver pci/pcie-tango.c fieldbus/anybus-bridge.c
platform_driver calls platform_driver does not
pci_host_probe() register with anybusI should probably rework this so it conforms more closely to the way it's done on pci. Would the following look any better?
pci anybus
--------------------------------------------------------------------------------
Common bus code (spec), pci/pci_driver.c anybus/anybus_driver.c calls bus_register() no of compatible no of compatible
--------------------------------------------------------------------------------
Device on bus, calls
XXX_client_driver_register() hwmon/k8temp.c fieldbus/hms-profinet.c
--------------------------------------------------------------------------------
Controller, silicon driver pci/pcie-tango.c anybus/arcx-controller.c
platform_driver calls platform_driver calls
pci_host_probe() anybus_host_probe()Of course, the analogy is not perfect, as there can only be a single card (device) connected to an anybus at a time.
Re: [PATCH anybus v4 1/7] fieldbus_dev: add Fieldbus Device subsystem.
In reply to Greg KHWow Greg, thanks for the review, this is awesome !!
Quoted 9 lines · Greg KH
drivers/fieldbus/dev_core.c line 290
Quoted 7 lines
drivers/fieldbus/dev_core.c new file +7
-0+cdev_init (&fb->cdev, &fieldbus_fops); + err =cdev_add (&fb->cdev, devno,1 ); +if (err) { +pr_err ("fieldbus_dev%d unable to add device %d:%d\n" , + fb->id,MAJOR (fieldbus_devt), fb->id); + goto err_cdev; + }Why do you have a static cdev?
The proposed fieldbus API needs a single /dev/fieldbus_devX node for every device. I just looked around the drivers/ tree to see how others accomplish this.
Is there a better way?
Quoted 3 lines
Quoted 1 line
+
fb->online_sd=sysfs_get_dirent(fb->dev->kobj.sd, "online");Ick, what? Why? Why are you messing around with a raw sysfs attribute?
The proposed fieldbus API has a sysfs attribute that can be poll/select'ed on. Is this behaviour still allowed / ok?
If so, you're saying that I should not store the raw attribute, but just do:sysfs_notify(&fb->dev->kobj, NULL, "online") ?
Now that I (hopefully) have a few seconds of your attention...
I suppose the fieldbus API in this patch can't go anywhere, without buy-in from multiple people who also want to use fieldbus. Right now, there are none.
This might be a chicken-and-egg problem. Perhaps here are no fieldbus devices because
there's no good general API. There's no good general API because there are no fieldbus devices yet.
Is there a tried and tested way to break this deadlock?
Rob Herring
maintainerRe: [PATCH anybus v4 6/7] dt-bindings: anybuss-host: document devicetree binding
In reply to Sven Van AsbroeckQuoted 8 lines · Sven Van Asbroeck
Rob, thank you so much for the review !
Quoted 3 lines · Rob Herring
Unit-addresses are based on 'reg'. So this should either be '89' or based on a definition for the bus (e.g. PCI uses dev and func).
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
+ reg = <
0x0089>;Is fieldbus type how one addresses a device on the bus?
I'm afraid not. Anybus cards don't have an address, because only a single card can be connected to an anybus at a time.
Then you don't need reg as you should only have 1 child node.
Quoted 2 lines
Fieldbus type defines the type/functionality of the connected card. Like pci device ids.
Which for PCI can be overridden in DT, but is part of reg.
Quoted 5 lines
The current patchset allows devicetree nodes to be provided depending on the type of card connected to the bus. It identifies the card by type, not location.
Is this not desired / allowed ?
No, 'reg' is how you address a device. You could use 'type' in the compatible string if type implies some sort of standard class interface.
Quoted 17 lines
Quoted 2 lines
I'm still not clear what a bridge vs. host is. Both examples are on WEIM bus CS0?
I agree that the terminology is too confusing. I'm looking to change it.
Let's compare current anybus with a well-established bus architecture like pci:
pci anybus
--------------------------------------------------------------------------------
Common bus code (spec),pci/pci_driver.cfieldbus/anybuss-host.c
callsbus_register()must be parallel bus
subnode
no of compatible has of compatible
--------------------------------------------------------------------------------
Device on bus, calls
XXX_client_driver_register()hwmon/k8temp.cfieldbus/hms-profinet.c
--------------------------------------------------------------------------------
Quoted 6 lines
Controller, silicon driver pci/pcie-tango.c fieldbus/anybus-bridge.c platform_driver calls platform_driver does not pci_host_probe() register with anybusI should probably rework this so it conforms more closely to the way it's done on pci. Would the following look any better?
Yes, this looks better.
Quoted 3 lines
pci anybus
--------------------------------------------------------------------------------
Common bus code (spec),pci/pci_driver.canybus/anybus_driver.c
Maybe just anybus/core.c or anybus/bus.c. I'm guessing your implementation will be *much* more simple than PCI.
Quoted 11 lines
calls
bus_register()no of compatible no of compatible
--------------------------------------------------------------------------------
Device on bus, calls
XXX_client_driver_register()hwmon/k8temp.cfieldbus/hms-profinet.c
--------------------------------------------------------------------------------Controller, silicon driver pci/pcie-tango.c anybus/arcx-controller.c platform_driver calls platform_driver calls pci_host_probe() anybus_host_probe()Of course, the analogy is not perfect, as there can only be a single card (device) connected to an anybus at a time.
Right, that should simplify the bus code a lot.
Rob
Re: [PATCH anybus v4 1/7] fieldbus_dev: add Fieldbus Device subsystem.
In reply to Sven Van AsbroeckQuoted 12 lines · Sven Van Asbroeck
Wow Greg, thanks for the review, this is awesome !!
Quoted 8 lines · Greg KH
Quoted 7 lines
drivers/fieldbus/dev_core.c new file +7
-0+cdev_init (&fb->cdev, &fieldbus_fops); + err =cdev_add (&fb->cdev, devno,1 ); +if (err) { +pr_err ("fieldbus_dev%d unable to add device %d:%d\n" , + fb->id,MAJOR (fieldbus_devt), fb->id); + goto err_cdev; + }
Quoted 7 lines
Quoted 1 line
Why do you have a static cdev?
The proposed fieldbus API needs a single
/dev/fieldbus_devXnode for every device. I just looked around thedrivers/tree to see how others accomplish this.Is there a better way?
It depends on what you want to do with this device node. You can use a static one in your structure if you use it to "cast back" to your real structure in the open() call, do you do that? If not, just create one dynamically.
Or use a misc device? How many of these do you need?
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
+
fb->online_sd=sysfs_get_dirent(fb->dev->kobj.sd, "online");Ick, what? Why? Why are you messing around with a raw sysfs attribute?
The proposed fieldbus API has a sysfs attribute that can be poll/select'ed on. Is this behaviour still allowed / ok?
For an online/offline attribute, no need to poll on it, just do a 'kobject change' event for online/offline and all should be fine. This is not a high-frequency event, right?
Quoted 3 lines
Now that I (hopefully) have a few seconds of your attention...
I suppose the fieldbus API in this patch can't go anywhere, without buy-in from multiple people who also want to use fieldbus. Right now, there are none.
Hey, if no one wants to use it, either no need to write any code at all, or you get to decide everything. Either way, you're in charge! :)
But you do need to document the thing, in Documentation/ABI/ to get it correct and able to be reviewed.
thanks,
greg k-h
Re: [PATCH anybus v4 1/7] fieldbus_dev: add Fieldbus Device subsystem.
Quoted 3 lines · Greg KH
It depends on what you want to do with this device node. You can use a static one in your structure if you use it to "cast back" to your real structure in the
open()call, do you do that?
I do...
static int fieldbus_open(struct inode *inode, struct file *filp)
{
struct fieldbus_dev *fbdev = container_of(inode->i_cdev,
struct fieldbus_dev,
cdev);Quoted 1 line
Or use a misc device? How many of these do you need?
Just one per fieldbus device.
But my main concern is naming in sysfs. A misc device will always show up as /sys/class/misc/..., right? Given that this is a userspace fieldbus API, we'd prefer /sys/class/fieldbus_dev/..., and cdev is the only way?
Quoted 3 lines
For an online/offline attribute, no need to poll on it, just do a 'kobject change' event for online/offline and all should be fine. This is not a high-frequency event, right?
Grepping... you mean kobject_uevent(KOBJ_CHANGE) ? THAT mechanism seems to fit much better, thanks !!
Quoted 2 lines
Hey, if no one wants to use it, either no need to write any code at all, or you get to decide everything. Either way, you're in charge! :)
I did get the impression that people are reluctant to take my patch partly because of an unproven userspace API. Maybe they are (rightly) worried that, once in, we will have to support this userspace API for evermore.
I'd love to get others involved in Fieldbus on Linux, but I'm not sure how.
Quoted 2 lines
But you do need to document the thing, in
Documentation/ABI/to get it correct and able to be reviewed.
The documentation is already included in this patch? Should I indicate this in some standardized fashion?
create mode 100644 Documentation/ABI/testing/fieldbus-dev-cdev create mode 100644 Documentation/ABI/testing/sysfs-class-fieldbus-dev
Thanks :)
Sven
Re: [PATCH anybus v4 1/7] fieldbus_dev: add Fieldbus Device subsystem.
Quoted 6 lines · Sven Van Asbroeck
Quoted 3 lines · Greg KH
It depends on what you want to do with this device node. You can use a static one in your structure if you use it to "cast back" to your real structure in the
open()call, do you do that?
Quoted 7 lines
I do...
static int
fieldbus_open(struct inode *inode, struct file *filp){ struct fieldbus_dev *fbdev = container_of(inode->i_cdev, struct fieldbus_dev, cdev);
Ok, good, that's a nice way to use this, nevermind my objection.
Quoted 6 lines
Quoted 1 line
Or use a misc device? How many of these do you need?
Just one per fieldbus device.
But my main concern is naming in sysfs. A misc device will always show up as/sys/class/misc/..., right? Given that this is a userspace fieldbus API, we'd prefer/sys/class/fieldbus_dev/..., and cdev is the only way?
Ah, the common misunderstanding.
A cdev has NOTHING to do with the /sys/class/ entries. It is only there to register a char device with the kernel core and to handle the file operations that are caused by it. It does not do much, and not even the /dev/NODE stuff either. That is up to your class device code.
So you still need a char device, and you will have have a load of them, just use the misc device api. It's simple, clean, and is hard to get wrong. The cdev api is hard, complex, and trivial to get wrong in any number of different ways that it can be used :)
That being said, it looks like you used it correctly, so all should be fine here.
And your /sys/class/fieldbus_dev/ is "interesting", why name it that?
Quoted 6 lines
Quoted 3 lines
For an online/offline attribute, no need to poll on it, just do a 'kobject change' event for online/offline and all should be fine. This is not a high-frequency event, right?
Grepping... you mean
kobject_uevent(KOBJ_CHANGE)? THAT mechanism seems to fit much better, thanks !!
Yes, use that please.
Quoted 9 lines
Quoted 2 lines
Hey, if no one wants to use it, either no need to write any code at all, or you get to decide everything. Either way, you're in charge! :)
I did get the impression that people are reluctant to take my patch partly because of an unproven userspace API. Maybe they are (rightly) worried that, once in, we will have to support this userspace API for evermore.
I'd love to get others involved in Fieldbus on Linux, but I'm not sure how.
Adding a new driver subsystem is messy, it takes a lot of work and finding the right reviewers is hard. It's not just you, it happens all the time (look at how long the i3c code took to get merged as one example...)
So keep submitting, I'll try to review it the next time around, and all should be fine. But keep your user api as simple as possible for now, only doing what you need it to do, worry about future stuff then.
Quoted 8 lines
Quoted 2 lines
But you do need to document the thing, in
Documentation/ABI/to get it correct and able to be reviewed.The documentation is already included in this patch? Should I indicate this in some standardized fashion?
create mode 100644 Documentation/ABI/testing/fieldbus-dev-cdev create mode 100644 Documentation/ABI/testing/sysfs-class-fieldbus-dev
Ah, sorry, I didn't read it, my fault :(
Why not just /sys/class/fieldbus/ ? No need for "dev", right?
greg k-h
Re: [PATCH anybus v4 1/7] fieldbus_dev: add Fieldbus Device subsystem.
Quoted 4 lines · Greg KH
So you still need a char device, and you will have have a load of them, just use the misc device api. It's simple, clean, and is hard to get wrong. The cdev api is hard, complex, and trivial to get wrong in any number of different ways that it can be used :)
Awesome little nugget! These things you just can't tell by reading the kernel tree. In many cases, it's not immediately obvious to me which of the various methods are 'recommended', and which ones are historic leftovers.
Quoted 1 line
And your
/sys/class/fieldbus_dev/is "interesting", why name it that?
Not sure why it's interesting? I figured it would allow userspace to enumerate all fieldbus devices simply by going to /sys/class/fieldbus_dev/ and process every subdirectory.
Example with 3 fieldbus cards:/sys/class/fieldbus_dev/fieldbus_dev0/name etc/sys/class/fieldbus_dev/fieldbus_dev1/name etc/sys/class/fieldbus_dev/fieldbus_dev2/name etc
Is there a better way?
Quoted 3 lines
So keep submitting, I'll try to review it the next time around, and all should be fine. But keep your user api as simple as possible for now, only doing what you need it to do, worry about future stuff then.
Thanks, that's awesome !!
I figured that I should take baby steps. I simplified the userspace API to the absolute bare minimum. To the point that the profinet card isn't useable in our company's specific use case, because there's no configuration API yet.
Quoted 1 line
Why not just
/sys/class/fieldbus/? No need for "dev", right?
Good question... Two very different classes of devices sit on a fieldbus:
Fieldbus device is like a slave
Fieldbus controller is like a master
This subsystem is specific for fieldbus *devices*. I figured I'd encode this in the API name, in case someone wants to support fieldbus controllers later.
Re: [PATCH anybus v4 6/7] dt-bindings: anybuss-host: document devicetree binding
In reply to Rob HerringRob,
Eliminating the 'compatible' property for the anybus gives me an interesting devicetree problem.
The imx-weim code naively loops through all subnodes, applying timing settings to the CS in the first reg entry.
In the example below, WEIM CS0 is programmed with the settings in fsl,weim-cs-timing, because the CS part of reg is 0:
weim: weim@21b8000 {
compatible = "fsl,imx6q-weim";
reg = <0x021b8000 0x4000>;
clocks = <&clks 196>;
#address-cells = <2>;
#size-cells = <1>;
ranges = <0 0 0x08000000 0x08000000>;
fsl,weim-cs-gpr = <&gpr>;
nor@0,0 {
compatible = "cfi-flash";
reg = <0 0 0x02000000>;
#address-cells = <1>;
#size-cells = <1>;
bank-width = <2>;
fsl,weim-cs-timing = <0x00620081 0x00000001 0x1c022000
0x0000c000 0x1404a38e 0x00000000>;
};
};The problem is that my 'anybus controller' hardware spans chip selects. It requires access to various memory areas. In the example below, CS1 will not be programmed with timing settings:
weim {
controller@0 {
compatible = "arcx,anybus-controller";
reg = <0 0 0x100>, <0 0x400000 0x800>, <1 0x400000 0x800>;
fsl,weim-cs-timing = ...;
};
};I've coped with this in the past by creating a 'dummy' subnode, without a compatible property. But it's ugly:
weim {
controller@0 {
compatible = "arcx,anybus-controller";
reg = <0 0 0x100>, <0 0x400000 0x800>, <1 0x400000 0x800>;
fsl,weim-cs-timing = ...;
};
dummy@1 { /* this works ! */
reg = <1 0 0>;
fsl,weim-cs-timing = ...;
};
};Is there a better way? I've looked and looked, but can't find anything that's similar.
Or should I extend the imx-weim driver to cope?
Rob Herring
maintainerRe: [PATCH anybus v4 6/7] dt-bindings: anybuss-host: document devicetree binding
Quoted 59 lines · Sven Van Asbroeck
Rob,
Eliminating the 'compatible' property for the anybus gives me an interesting devicetree problem.
The imx-weim code naively loops through all subnodes, applying timing settings to the CS in the first reg entry.
In the example below, WEIM CS0 is programmed with the settings in fsl,weim-cs-timing, because the CS part of reg is 0:weim: weim@21b8000 { compatible = "fsl,imx6q-weim"; reg = <0x021b8000 0x4000>; clocks = <&clks 196>; #address-cells = <2>; #size-cells = <1>; ranges = <0 0 0x08000000 0x08000000>; fsl,weim-cs-gpr = <&gpr>; nor@0,0 { compatible = "cfi-flash"; reg = <0 0 0x02000000>; #address-cells = <1>; #size-cells = <1>; bank-width = <2>; fsl,weim-cs-timing = <0x00620081 0x00000001 0x1c022000 0x0000c000 0x1404a38e 0x00000000>; }; };The problem is that my 'anybus controller' hardware spans chip selects. It requires access to various memory areas. In the example below, CS1 will not be programmed with timing settings:
weim { controller@0 { compatible = "arcx,anybus-controller"; reg = <0 0 0x100>, <0 0x400000 0x800>, <1 0x400000 0x800>; fsl,weim-cs-timing = ...; }; };I've coped with this in the past by creating a 'dummy' subnode, without a compatible property. But it's ugly:
weim { controller@0 { compatible = "arcx,anybus-controller"; reg = <0 0 0x100>, <0 0x400000 0x800>, <1 0x400000 0x800>; fsl,weim-cs-timing = ...; }; dummy@1 { /* this works ! */ reg = <1 0 0>; fsl,weim-cs-timing = ...; }; };
Quoted 4 lines
Is there a better way? I've looked and looked, but can't find anything that's similar.
Or should I extend the imx-weim driver to cope?
Yes, I think it should iterate on child reg properties not just nodes. Hopefully, you don't need different timing for each CS though.
Rob