Skip to contentSkip to conversation

Add Fieldbus subsystem + support HMS Profinet card

PATCH Superseded Sven Van Asbroeck 6 participants 20 messages Dec 4, 2018 – Dec 7, 2018

Subsystems (2)

v5 of 11 Superseded Latest is v11 →

lore
Share & tools
lore
#0 lore raw

v5 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 controller', which is custom h/w designed by arcx. It exposes a dual anybus host implementation, plus a power readout unrelated to the anybus.

v5:
Greg KH:
fix licence nit
consistent use of e-mail address
replaced raw sysfs attribute with kobject_uevent() call keep __ATTRIBUTE_GROUPS because we need is_visible field
Rob Herring:
controller devicetree entry now requires multiple address
regions and interrupts
controller child node(s) now mapped to child devices by
slot/host position (using devicetree reg = <>)
architectural overhaul to align closely to existing pci arch:

pci anybus
--------------------------------------------------------------------------------
Common bus code (spec), pci/pci_driver.c anybus/dev_core.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-anybus.c
platform_driver calls platform_driver calls
pci_host_probe() anybus_host_common_probe()

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 (6):
fieldbus_dev: add Fieldbus Device subsystem.
anybus-s: support HMS Anybus-S bus
anybus-s: support the Arcx anybus controller
dt-bindings: anybus-controller: document devicetree binding
dt-bindings: Add vendor prefix for arcx / Archronix
fieldbus_dev: support HMS Profinet IRT industrial controller

 Documentation/ABI/testing/fieldbus-dev-cdev   |   31 +
 .../ABI/testing/sysfs-class-fieldbus-dev      |   63 +
 .../fieldbus/arcx,anybus-controller.txt       |   71 +
 .../devicetree/bindings/vendor-prefixes.txt   |    1 +
 Documentation/fieldbus_dev/fieldbus_dev.txt   |   66 +
 drivers/Kconfig                               |    2 +
 drivers/Makefile                              |    1 +
 drivers/fieldbus/Kconfig                      |   18 +
 drivers/fieldbus/Makefile                     |   10 +
 drivers/fieldbus/anybuss/Kconfig              |   39 +
 drivers/fieldbus/anybuss/Makefile             |   10 +
 drivers/fieldbus/anybuss/arcx-anybus.c        |  399 +++++
 drivers/fieldbus/anybuss/hms-profinet.c       |  223 +++
 drivers/fieldbus/anybuss/host.c               | 1459 +++++++++++++++++
 drivers/fieldbus/dev_core.c                   |  349 ++++
 include/linux/anybuss-client.h                |  104 ++
 include/linux/anybuss-controller.h            |   47 +
 include/linux/fieldbus_dev.h                  |  105 ++
 18 files changed, 2998 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-controller.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/anybuss/Kconfig
 create mode 100644 drivers/fieldbus/anybuss/Makefile
 create mode 100644 drivers/fieldbus/anybuss/arcx-anybus.c
 create mode 100644 drivers/fieldbus/anybuss/hms-profinet.c
 create mode 100644 drivers/fieldbus/anybuss/host.c
 create mode 100644 drivers/fieldbus/dev_core.c
 create mode 100644 include/linux/anybuss-client.h
 create mode 100644 include/linux/anybuss-controller.h
 create mode 100644 include/linux/fieldbus_dev.h
Signature · 1 line
2.17.1
#1 lore raw

PATCH v5 1/6 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                   | 349 ++++++++++++++++++
 include/linux/fieldbus_dev.h                  | 105 ++++++
 9 files changed, 645 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
new file mode 100644
index 000000000000..2c71f63ce0f9
@@ -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
index 155f25ad3a92..d6410846a4a8 100644
@@ -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
index 723698ad04f3..cb278f951c99 100644
@@ -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
new file mode 100644
index 000000000000..1d1929ba7e27
@@ -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
new file mode 100644
index 000000000000..768a116fc9c6
@@ -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 +349 -0

349 lines not on this page · raw message

include/linux/fieldbus_dev.h new file +105 -0

105 lines not on this page · raw message

Signature · 1 line
2.17.1
reviewer
#2 lore raw

Re: [PATCH v5 1/6] fieldbus_dev: add Fieldbus Device subsystem.

Quoted 15 lines · Sven Van Asbroeck
drivers/fieldbus/Kconfig new file +9 -0
new file mode 100644
index 000000000000..1d1929ba7e27
@@ -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

drivers/fieldbus/Kconfig line 19

Quoted 10 lines
drivers/fieldbus/Kconfig new file +10 -0
+	  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

Hi,
Please consistently use one tab + 2 spaces to indent Kconfig help text, as documented in Documentation/process/coding-style.rst.

Signature · 1 line
~Randy
reviewer
#3 lore raw

Re: [PATCH v5 1/6] fieldbus_dev: add Fieldbus Device subsystem.

In reply to Sven Van Asbroeck
Quoted 20 lines · Sven Van Asbroeck

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/fieldbus_dev/fieldbus_dev.txt new file +1 -0
new file mode 100644
index 000000000000..40ab4de0f019
@@ -0,0 +1,66 @@
+                       Fieldbus-Device Subsystem

Documentation/fieldbus_dev/fieldbus_dev.txt line 11

Quoted 10 lines
Documentation/fieldbus_dev/fieldbus_dev.txt new file +10 -0
+               ============================================
+
+Part 0 - What is a Fieldbus Device ?
+------------------------------------
+
+Fieldbus is the name of a family of industrial computer network protocols used
+for real-time distributed control, standardized as IEC 61158.
+
+A complex automated industrial system — such as manufacturing assembly line —
+usually needs a distributed control system—an organized hierarchy of controller

"system-an" looks like a hyphenated word, but it's not. It would be better to use either "--" or " - " (as in the line above it).

Documentation/fieldbus_dev/fieldbus_dev.txt line 12

Quoted 1 line
Documentation/fieldbus_dev/fieldbus_dev.txt new file +1 -0
+systems—to function. In this hierarchy, there is usually a

Same for "systems-to".

Documentation/fieldbus_dev/fieldbus_dev.txt line 23

Quoted 11 lines
Documentation/fieldbus_dev/fieldbus_dev.txt new file +11 -0
+Human Machine Interface (HMI) at the top, where an operator can monitor or
+operate the system. This is typically linked to a middle layer of programmable
+logic controllers (PLC) via a non-time-critical communications system
+(e.g. Ethernet). At the bottom of the control chain is the fieldbus that links
+the PLCs to the components that actually do the work, such as sensors,
+actuators, electric motors, console lights, switches, valves and contactors.
+
+(Source: Wikipedia)
+
+A "Fieldbus Device" is such an actuator, motor, console light, switch, ...
+controlled via the Fieldbus by a PLC aka. "Fieldbus Controller".

a.k.a. or just "aka", but not "aka."

Documentation/fieldbus_dev/fieldbus_dev.txt line 33

Quoted 10 lines
Documentation/fieldbus_dev/fieldbus_dev.txt new file +10 -0
+
+Communication between PLC and device typically happens via process data memory,
+separated into input and output areas. The Fieldbus then cyclically transfers
+the PLC's output area to the device's input area, and vice versa.
+
+Part I - Why do we need this subsystem?
+---------------------------------------
+
+Fieldbus device (client) adapters are commercially available. They allow data
+exchange with a PLC aka. "Fieldbus Controller" via process data memory.

aka

Quoted 33 lines
Documentation/fieldbus_dev/fieldbus_dev.txt new file +33 -0
+
+They are typically used when a Linux device wants to expose itself as an
+actuator, motor, console light, switch, etc. over the fieldbus.
+
+The purpose of this subsystem is:
+a) present a general, standardized, extensible API/ABI to userspace; and
+b) present a convenient interface to drivers.
+
+Part II - How can drivers use the subsystem?
+--------------------------------------------
+
+Any driver that wants to register as a Fieldbus Device should allocate and
+populate a 'struct fieldbus_dev' (from include/linux/fieldbus_dev.h).
+Registration then happens by calling fieldbus_dev_register().
+
+Part III - How can userspace use the subsystem?
+-----------------------------------------------
+
+Fieldbus protocols and adapters are diverse and varied. However, they share
+a limited few common behaviours and properties. This allows us to define
+a simple interface consisting of a character device and a set of sysfs files:
+
+See:
+Documentation/ABI/testing/sysfs-class-fieldbus-dev
+Documentation/ABI/testing/fieldbus-dev-cdev
+
+Note that this simple interface does not provide a way to modify adapter
+configuration settings. It is therefore useful only for adapters that get their
+configuration settings some other way, e.g. non-volatile memory on the adapter,
+through the network, ...
+
+At a later phase, this simple interface can easily co-exist with a future
+(netlink-based ?) configuration settings interface.
Signature · 1 line
~Randy
#4 lore raw

Re: [PATCH v5 1/6] fieldbus_dev: add Fieldbus Device subsystem.

In reply to Sven Van Asbroeck

Documentation/ABI/testing/sysfs-class-fieldbus-dev line 1

Quoted 4 lines · Sven Van Asbroeck
Documentation/ABI/testing/sysfs-class-fieldbus-dev new file +1 -0
@@ -0,0 +1,63 @@
+What:		/sys/class/fieldbus_dev/fieldbus_devX/card_name

Here's a good example of your naming being a bit too "verbose" :)

There is no need to name your devices with the same prefix as your class. Just make it:
/sys/class/fieldbus/XXX/card_name

And why is this a class and not just a "normal" device and bus? Devices live on busses, not generally as a class. Can your devices live on different types of busses (USB, PCI, etc.)?

But, if you really just want to leave this as a "class", then just call it "fieldbus" and make it simple. You are only exposing the "fieldbus-specific" type of attributes here, so that's probably good enough for now.

drivers/Makefile obj-$(CONFIG_TEE) += tee/ · line 191

Quoted 8 lines
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/

Why not after gnss?

drivers/fieldbus/Makefile line 6

Quoted 9 lines
drivers/fieldbus/Makefile new file +6 -0
@@ -0,0 +1,9 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Makefile for fieldbus_dev drivers.
+#
+
+obj-$(CONFIG_FIELDBUS_DEV)	+= fieldbus_dev_core.o

Why not just "fieldbus.o"?

drivers/fieldbus/Makefile

Quoted 6 lines
drivers/fieldbus/Makefile new file +6 -0
+static ssize_t online_show(struct device *dev, struct device_attribute *attr,
+				char *buf)
+{
+	struct fieldbus_dev *fb = dev_get_drvdata(dev);
+
+	return snprintf(buf, PAGE_SIZE, "%s\n",

Nit, sysfs attributes are always so small that you don't need to care about the size of the buffer because you "always" know that you will not overflow it.

So this can just be a simple:

	return sprintf(buf, "%s\n", ...);
Quoted 4 lines
drivers/fieldbus/Makefile new file +4 -0
+		fb->online ? "online" : "offline");
+}
+static DEVICE_ATTR_RO(online);
+

drivers/fieldbus/Makefile

Quoted 10 lines
drivers/fieldbus/Makefile new file +10 -0
+static ssize_t enabled_show(struct device *dev, struct device_attribute *attr,
+				char *buf)
+{
+	struct fieldbus_dev *fb = dev_get_drvdata(dev);
+
+	if (!fb->enable_get)
+		return -EINVAL;
+	return snprintf(buf, PAGE_SIZE, "%s\n",
+		fb->enable_get(fb) ? ctrl_enabled : ctrl_disabled);
+}

New line?

drivers/fieldbus/Makefile

Quoted 9 lines
drivers/fieldbus/Makefile new file +9 -0
+static ssize_t enabled_store(struct device *dev, struct device_attribute *attr,
+			     const char *buf, size_t n)
+{
+	struct fieldbus_dev *fb = dev_get_drvdata(dev);
+	int err;
+
+	if (!fb->simple_enable_set) {
+		n = -ENOTSUPP;
+	} else if (sysfs_streq(buf, ctrl_enabled)) {

Why not just have the normal "0/1" type of parsing? We have a function for it already, kstrtobool().

thanks,

greg k-h

#5 lore raw

Re: [PATCH v5 1/6] fieldbus_dev: add Fieldbus Device subsystem.

Hello Greg, thanks for the feedback!

Quoted 3 lines · Greg KH

And why is this a class and not just a "normal" device and bus? Devices live on busses, not generally as a class. Can your devices live on different types of busses (USB, PCI, etc.)?

This patchset can be a bit confusing, because it doesn't just add support for a single fieldbus device - it proposes a general fieldbus subsystem.

Fieldbus devices from different vendors can sit on the usb, i2c, pci, etc. buse, but they all register as a fieldbus device, via fieldbus_dev_register(), and show up as a fieldbus class member.

Userspace can then enumerate all fieldbus devices connected to the system by looking at the class. Without having to know which bus they happen to be connected to.

If there is an abstraction in Linux that's a better fit, I'm very open to making changes.

Sven

#6 lore raw

Re: [PATCH v5 1/6] fieldbus_dev: add Fieldbus Device subsystem.

Quoted 9 lines · Sven Van Asbroeck

Hello Greg, thanks for the feedback!

Quoted 3 lines · Greg KH

And why is this a class and not just a "normal" device and bus? Devices live on busses, not generally as a class. Can your devices live on different types of busses (USB, PCI, etc.)?

This patchset can be a bit confusing, because it doesn't just add support for a single fieldbus device - it proposes a general fieldbus subsystem.

Great, then call it a 'fieldbus' class, not "fieldbus_dev' class.

Devices can belong to a bus, or a class, so you are fine here.

Quoted 3 lines

Fieldbus devices from different vendors can sit on the usb, i2c, pci, etc. buse, but they all register as a fieldbus device, via fieldbus_dev_register(), and show up as a fieldbus class member.

ok, I'm just complaining about your name in sysfs, not your code :)

I think what you did here is correct from a logic point of view.

Quoted 3 lines

Userspace can then enumerate all fieldbus devices connected to the system by looking at the class. Without having to know which bus they happen to be connected to.

Sounds reasonable.

nice work,

greg k-h

#7 lore raw

Re: [PATCH v5 1/6] fieldbus_dev: add Fieldbus Device subsystem.

Thanks :)

Quoted 2 lines · Greg KH

Great, then call it a 'fieldbus' class, not "fieldbus_dev' class.

Small nit:

Hardware connected to a fieldbus comes in two distinct flavours:
- clients (e.g. thermometer, robotic arm) called "fieldbus devices"
- servers (e.g. a PLC) called "fieldbus controllers"

Their userspace APIs will probably differ quite a lot.

The userspace API created by the patch is only for clients a.k.a. "fieldbus devices". That's why I'm writing 'fieldbus_dev' all over the place.

For simplicity, we could change that to just 'fieldbus'. But would this get us in trouble when, at some point, we want to add a userspace API for servers a.k.a. "fieldbus controllers" ?

#8 lore raw

Re: [PATCH v5 1/6] fieldbus_dev: add Fieldbus Device subsystem.

Quoted 10 lines · Sven Van Asbroeck
Quoted 2 lines · Greg KH

Great, then call it a 'fieldbus' class, not "fieldbus_dev' class.

Small nit:

Hardware connected to a fieldbus comes in two distinct flavours:
- clients (e.g. thermometer, robotic arm) called "fieldbus devices"
- servers (e.g. a PLC) called "fieldbus controllers"

Quoted 8 lines

Their userspace APIs will probably differ quite a lot.

The userspace API created by the patch is only for clients a.k.a. "fieldbus devices". That's why I'm writing 'fieldbus_dev' all over the place.

For simplicity, we could change that to just 'fieldbus'. But would this get us in trouble when, at some point, we want to add a userspace API for servers a.k.a. "fieldbus controllers" ?

In the long run, would you expect to support more devices or more controllers that need a distinct driver? Whichever we have more of should probably get the shorter name.

Arnd

#9 lore raw

Re: [PATCH v5 1/6] fieldbus_dev: add Fieldbus Device subsystem.

In reply to Sven Van Asbroeck
Quoted 6 lines · Sven Van Asbroeck

Thanks :)

Quoted 2 lines · Greg KH

Great, then call it a 'fieldbus' class, not "fieldbus_dev' class.

Quoted 7 lines

Small nit:

Hardware connected to a fieldbus comes in two distinct flavours:
- clients (e.g. thermometer, robotic arm) called "fieldbus devices"
- servers (e.g. a PLC) called "fieldbus controllers"

Their userspace APIs will probably differ quite a lot.

But servers are going to be much more rare, and odds are userspace is not going to need to control anything with them, right?

Quoted 6 lines

The userspace API created by the patch is only for clients a.k.a. "fieldbus devices". That's why I'm writing 'fieldbus_dev' all over the place.

For simplicity, we could change that to just 'fieldbus'. But would this get us in trouble when, at some point, we want to add a userspace API for servers a.k.a. "fieldbus controllers" ?

Ick, yeah, I guess so, but planning for future events is not something we do well at all. Are you sure you will need fieldbus controllers as a class?

And as these are really devices, why not make them a "device" and a bus? What type of topology do you have on these busses? Are everything "flat" and connected directly to a PCI/USB/platform device? Or are there multiple devices attached to a single controller?

It really feels like you want to use 'struct device' and a bus_type and not a class here to me...

thanks,

greg k-h

#10 lore raw

Re: [PATCH v5 1/6] fieldbus_dev: add Fieldbus Device subsystem.

Hi Greg,

Quoted 9 lines · Greg KH

And as these are really devices, why not make them a "device" and a bus? What type of topology do you have on these busses? Are everything "flat" and connected directly to a PCI/USB/platform device? Or are there multiple devices attached to a single controller?

It really feels like you want to use 'struct device' and a bus_type and not a class here to me...

I don't believe that the bus/device abstraction is appropriate for fieldbus peripherals. But obviously I'm not a fieldbus or kernel expert, so I keep an open mind to any elegant solutions I may have missed.

The name FieldBUS is misleading - it's an industrial network, not a bus. The underlying network technology varies: Profinet runs over Ethernet, Profibus over RS485. The topology is typical for networks AFAIK.

The actual layout of the raw packets exchanged over the network is proprietary; fieldbus cards will typically implement this internally, and hide the details.

To the user, a fieldbus card typically exposes shared memory regions. For example, a robotic arm may store its arm angle at offset 27 of its memory region. The PC controlling the arm writes a new value to offset 27 in the memory of its own fieldbus card. The cards then communicate over the network, the memory in the arm's fieldbus card is updated, and the arm is notified of the data change by an interrupt.

Like I said, I'm by no means a fieldbus expert. But this 'feels' unlike a device/bus abstraction. And it also doesn't 'feel' right to make this part of the network stack. But I keep an open mind.

Sven

#11 lore raw

PATCH v5 2/6 anybus-s: support HMS Anybus-S bus

In reply to Sven Van Asbroeck

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           |    3 +-
 drivers/fieldbus/Makefile          |    4 +-
 drivers/fieldbus/anybuss/Kconfig   |    9 +
 drivers/fieldbus/anybuss/Makefile  |    7 +
 drivers/fieldbus/anybuss/host.c    | 1459 ++++++++++++++++++++++++++++
 include/linux/anybuss-client.h     |  104 ++
 include/linux/anybuss-controller.h |   47 +
 7 files changed, 1630 insertions(+), 3 deletions(-)
 create mode 100644 drivers/fieldbus/anybuss/Kconfig
 create mode 100644 drivers/fieldbus/anybuss/Makefile
 create mode 100644 drivers/fieldbus/anybuss/host.c
 create mode 100644 include/linux/anybuss-client.h
 create mode 100644 include/linux/anybuss-controller.h
drivers/fieldbus/Kconfig +1 -2
index 1d1929ba7e27..f2578218e5c3 100644
@@ -14,6 +14,5 @@ menuconfig FIELDBUS_DEV
 
           If unsure, say no.
 
-if FIELDBUS_DEV
+source "drivers/fieldbus/anybuss/Kconfig"
 
-endif
drivers/fieldbus/Makefile +3 -1
index 768a116fc9c6..b9eee708374a 100644
@@ -6,4 +6,6 @@
 obj-$(CONFIG_FIELDBUS_DEV)	+= fieldbus_dev_core.o
 fieldbus_dev_core-y		:= dev_core.o
 
-# Devices
+# Anybus-S core and devices
+obj-$(CONFIG_HMS_ANYBUSS_BUS)	+= anybuss/
+
drivers/fieldbus/anybuss/Kconfig new file +9 -0
new file mode 100644
index 000000000000..5b495f25c11e
@@ -0,0 +1,9 @@
+config HMS_ANYBUSS_BUS
+	tristate "HMS Anybus-S Bus Support"
+	select REGMAP
+	depends on OF && FIELDBUS_DEV
+	help
+	  Driver for the HMS Industrial Networks Anybus-S bus.
+	  You can attach a single Anybus-S compatible card to it, which
+	  typically provides fieldbus and industrial ethernet
+	  functionality.
drivers/fieldbus/anybuss/Makefile new file +7 -0
new file mode 100644
index 000000000000..b1c386cb4ed2
@@ -0,0 +1,7 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Makefile for anybuss drivers.
+#
+
+obj-y			+= anybuss_core.o
+anybuss_core-y		+= host.o
drivers/fieldbus/anybuss/host.c new file +1459 -0

1,459 lines not on this page · raw message

include/linux/anybuss-client.h new file +104 -0

104 lines not on this page · raw message

include/linux/anybuss-controller.h new file +47 -0

47 lines not on this page · raw message

Signature · 1 line
2.17.1
#12 lore raw

PATCH v5 3/6 anybus-s: support the Arcx anybus controller

In reply to Sven Van Asbroeck

Add a driver for the Arcx anybus controller.

This device implements two Anybus-S hosts (buses), 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/Makefile              |   1 -
 drivers/fieldbus/anybuss/Kconfig       |  14 +
 drivers/fieldbus/anybuss/Makefile      |   2 +
 drivers/fieldbus/anybuss/arcx-anybus.c | 399 +++++++++++++++++++++++++
 4 files changed, 415 insertions(+), 1 deletion(-)
 create mode 100644 drivers/fieldbus/anybuss/arcx-anybus.c
drivers/fieldbus/Makefile +0 -1
index b9eee708374a..982dc6cede82 100644
@@ -8,4 +8,3 @@ fieldbus_dev_core-y		:= dev_core.o
 
 # Anybus-S core and devices
 obj-$(CONFIG_HMS_ANYBUSS_BUS)	+= anybuss/
-
drivers/fieldbus/anybuss/Kconfig +14 -0
index 5b495f25c11e..7e563a78be13 100644
@@ -7,3 +7,17 @@ config HMS_ANYBUSS_BUS
 	  You can attach a single Anybus-S compatible card to it, which
 	  typically provides fieldbus and industrial ethernet
 	  functionality.
+
+if HMS_ANYBUSS_BUS
+
+config ARCX_ANYBUS_CONTROLLER
+	tristate "Arcx Anybus-S Controller"
+	depends on OF && GPIOLIB
+	help
+	  Select this to get support for the Arcx Anybus controller.
+	  It connects to the SoC via a parallel memory bus, and
+	  embeds up to two Anybus-S buses (slots).
+	  There is also a CAN power readout, unrelated to the Anybus,
+	  modelled as a regulator.
+
+endif
drivers/fieldbus/anybuss/Makefile +2 -0
index b1c386cb4ed2..815155f02700 100644
@@ -5,3 +5,5 @@
 
 obj-y			+= anybuss_core.o
 anybuss_core-y		+= host.o
+
+obj-$(CONFIG_ARCX_ANYBUS_CONTROLLER) += arcx-anybus.o
drivers/fieldbus/anybuss/arcx-anybus.c new file +399 -0

399 lines not on this page · raw message

Signature · 1 line
2.17.1
#13 lore raw

PATCH v5 4/6 dt-bindings: anybus-controller: document devicetree binding

In reply to Sven Van Asbroeck

From: Sven Van Asbroeck <[email protected]>

This patch adds devicetree binding documentation for the Arcx anybus controller.

---
 .../fieldbus/arcx,anybus-controller.txt       | 71 +++++++++++++++++++
 1 file changed, 71 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/fieldbus/arcx,anybus-controller.txt
Documentation/devicetree/bindings/fieldbus/arcx,anybus-controller.txt new file +71 -0
new file mode 100644
index 000000000000..b1f9474f36d5
@@ -0,0 +1,71 @@
+* Arcx Anybus-S controller
+
+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-controller"
+
+  - reg : three areas:
+	index 0: bus memory area where the cpld registers are located.
+	index 1: bus memory area of the first  host's dual-port ram.
+	index 2: bus memory area of the second host's dual-port ram.
+
+  - reset-gpios : the GPIO pin connected to the reset line of the controller.
+
+  - interrupts : two interrupts:
+		index 0: interrupt connected to the first  host
+		index 1: interrupt connected to the second host
+	Generic interrupt client node bindings are described in
+	interrupt-controller/interrupts.txt
+
+Optional: use of subnodes
+-------------------------
+
+The card connected to a host may need additional properties. These can be
+specified in subnodes to the controller 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 controller node properties when using subnodes:
+- #address-cells: should be one.
+- #size-cells: should be zero.
+
+Required subnode properties:
+- reg: Must contain the host index of the card this subnode describes:
+		<0>	for the first  host on the controller
+		<1>	for the second host on the controller
+	Note that only a single card can be plugged into a host, so the host
+	index uniquely describes the card location.
+
+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 {
+	controller@0,0 {
+		compatible = "arcx,anybus-controller";
+		reg = <0 0 0x100>, <0 0x400000 0x800>, <1 0x400000 0x800>;
+		reset-gpios = <&gpio5 2 GPIO_ACTIVE_HIGH>;
+		interrupt-parent = <&gpio1>;
+		interrupts = <1 IRQ_TYPE_LEVEL_LOW>, <5 IRQ_TYPE_LEVEL_LOW>;
+		/* 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 card plugged into the first host */
+		#address-cells = <1>;
+		#size-cells = <0>;
+		card@0 {
+			reg = <0>;
+			/* card specific properties go here */
+		};
+	};
+};
Signature · 1 line
2.17.1
maintainer
#14 lore raw

Re: [PATCH v5 4/6] dt-bindings: anybus-controller: document devicetree binding

Quoted 10 lines · Sven Van Asbroeck

From: Sven Van Asbroeck <[email protected]>

This patch adds devicetree binding documentation for the Arcx anybus controller.

---
 .../fieldbus/arcx,anybus-controller.txt       | 71 +++++++++++++++++++
 1 file changed, 71 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/fieldbus/arcx,anybus-controller.txt

This looks fine to me now, but still seems the rest of the series has some discussion. In theory, all that should have no impact on the bindings.

Rob

#15 lore raw

PATCH v5 5/6 dt-bindings: Add vendor prefix for arcx / Archronix

In reply to Sven Van Asbroeck

From: Sven Van Asbroeck <[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
index 2c3fc512e746..2ad1128c4470 100644
@@ -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
#16 lore raw

PATCH v5 6/6 fieldbus_dev: support HMS Profinet IRT industrial controller

In reply to Sven Van Asbroeck

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/anybuss/Kconfig        |  16 ++
 drivers/fieldbus/anybuss/Makefile       |   1 +
 drivers/fieldbus/anybuss/hms-profinet.c | 223 ++++++++++++++++++++++++
 3 files changed, 240 insertions(+)
 create mode 100644 drivers/fieldbus/anybuss/hms-profinet.c
drivers/fieldbus/anybuss/Kconfig +16 -0
index 7e563a78be13..1d0e7516b18e 100644
@@ -20,4 +20,20 @@ config ARCX_ANYBUS_CONTROLLER
 	  There is also a CAN power readout, unrelated to the Anybus,
 	  modelled as a regulator.
 
+config HMS_PROFINET
+	tristate "HMS Profinet IRT Controller (Anybus-S)"
+	depends on FIELDBUS_DEV && HMS_ANYBUSS_BUS
+	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/anybuss/Makefile +1 -0
index 815155f02700..322963a452dc 100644
@@ -7,3 +7,4 @@ obj-y			+= anybuss_core.o
 anybuss_core-y		+= host.o
 
 obj-$(CONFIG_ARCX_ANYBUS_CONTROLLER) += arcx-anybus.o
+obj-$(CONFIG_HMS_PROFINET)	+= hms-profinet.o
drivers/fieldbus/anybuss/hms-profinet.c new file +223 -0

223 lines not on this page · raw message

Signature · 1 line
2.17.1
reviewer
#17 lore raw

Re: [PATCH v5 6/6] fieldbus_dev: support HMS Profinet IRT industrial controller

Quoted 15 lines · Sven Van Asbroeck
drivers/fieldbus/anybuss/Kconfig +7 -0
index 7e563a78be13..1d0e7516b18e 100644
@@ -20,4 +20,20 @@ config ARCX_ANYBUS_CONTROLLER
 	  There is also a CAN power readout, unrelated to the Anybus,
 	  modelled as a regulator.
 
+config HMS_PROFINET
+	tristate "HMS Profinet IRT Controller (Anybus-S)"
+	depends on FIELDBUS_DEV && HMS_ANYBUSS_BUS
+	help
+	 If you say yes here you get support for the HMS Industrial
+	 Networks Profinet IRT Controller.
+

drivers/fieldbus/anybuss/Kconfig config ARCX_ANYBUS_CONTROLLER · line 39

Quoted 10 lines
drivers/fieldbus/anybuss/Kconfig +9 -0
+	 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

Indent with tab + 2 spaces.

Signature · 1 line
~Randy
#18 lore raw
In reply to Sven Van Asbroeck
Quoted 3 lines · Sven Van Asbroeck

This patch:
1. adds a Fieldbus subsystem
2. adds support for the HMS Industrial Networks AB Profinet card.

Does this actually need a new fieldbus subsystem or could it just be implemented as a new network protocol?

Quoted 10 lines

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.

Then this generic interface to a fieldbus device could just be a socket.

Quoted 22 lines

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 controller', which is custom h/w designed by arcx. It exposes a dual anybus host implementation, plus a power readout unrelated to the anybus.

#19 lore raw

Hi David, thank you for the feedback !

Quoted 6 lines · David Lechner

Does this actually need a new fieldbus subsystem or could it just be implemented as a new network protocol?

Then this generic interface to a fieldbus device could just be a socket.

This is a fundamental question, and I'm glad we are having this discussion.

Caveat: I am by no means a Fieldbus expert. HMS Industrial Networks are. They have recently become aware of this mainlining effort; but they are not Linux focused. I really hope they will participate.

Fieldbus is a collection of network protocols for industrial networks. The underlying network technology varies: e.g. Ethernet for Profinet, RS485 for Profibus, just to name a few.

The actual layout of the raw packets exchanged over the network is proprietary; fieldbus cards will typically implement this internally, and hide the details. Some fieldbus protocols have hard real-time requirements: the CPU inside a fieldbus card will typically run an RTOS to satisfy these.

Could Profinet be added as a new network protocol? Leaving aside proprietary and hard real-time concerns, the main issue is that cards implementing the standard won't provide access to the raw packets.

As a result, the Fieldbus userspace API can only consist of whatever these cards are willing to expose. This varies widely among implementations and fieldbus protocols, but there are a few commonalities. For example, every fieldbus card will expose 'process memory' which you can think of as shared memory between a device and its controller (master).

The fieldbus subsystem proposed in this patch exposes a minimal set of functionality that every fieldbus device is supposed to have. In many instances, this won't even be enough to get the card to work. For example, there is currently no way to provide initialization parameters. These vary from setting the card network id, to configuring a built-in HTTP server running inside the card (!!).

Linus Walleij suggested that the KVP nature of Netlink sockets might be a good match for fieldbus initialization parameters. It sounds promising. Yet when it comes to accessing shared memory, I cannot see how Netlink could be of use?

It would be ideal if actual fieldbus experts could help shape this interface, but I don't know of any that are willing to. One possible explanation is that the fieldbus corporate environment may be a strong believer in proprietary technologies.

Sven