Skip to contentSkip to conversation

Support HMS Profinet Card over Anybus

PATCH In review [email protected] 5 participants 35 messages Nov 4, 2018 – Nov 12, 2018

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v3 cover Support HMS Profinet Card over Anybus

From: Sven Van Asbroeck <[email protected]>

This patch set adds support for the HMS Industrial Networks AB 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.

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):
misc: support the Arcx anybus bridge
dt-bindings: Add vendor prefix for arcx / Archronix
dt-bindings: anybus-bridge: document devicetree binding
bus: support HMS Anybus-S bus
dt-bindings: anybuss-host: document devicetree binding
misc: support HMS Profinet IRT industrial controller

 .../bindings/bus/arcx,anybuss-host.txt        |   36 +
 .../bindings/misc/arcx,anybus-bridge.txt      |   34 +
 .../devicetree/bindings/vendor-prefixes.txt   |    1 +
 Documentation/ioctl/ioctl-number.txt          |    1 +
 drivers/bus/Kconfig                           |   20 +
 drivers/bus/Makefile                          |    2 +
 drivers/bus/anybus-bridge.c                   |  321 ++++
 drivers/bus/anybuss-host.c                    | 1503 +++++++++++++++++
 drivers/misc/Kconfig                          |   10 +
 drivers/misc/Makefile                         |    1 +
 drivers/misc/hms-profinet.c                   |  753 +++++++++
 include/linux/anybuss-client.h                |  100 ++
 include/uapi/linux/hms-common.h               |   14 +
 include/uapi/linux/hms-profinet.h             |  102 ++
 14 files changed, 2898 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/bus/arcx,anybuss-host.txt
 create mode 100644 Documentation/devicetree/bindings/misc/arcx,anybus-bridge.txt
 create mode 100644 drivers/bus/anybus-bridge.c
 create mode 100644 drivers/bus/anybuss-host.c
 create mode 100644 drivers/misc/hms-profinet.c
 create mode 100644 include/linux/anybuss-client.h
 create mode 100644 include/uapi/linux/hms-common.h
 create mode 100644 include/uapi/linux/hms-profinet.h
Signature · 1 line
2.17.1
#1 lore raw

PATCH v3 1/6 misc: support the Arcx anybus bridge

From: Sven Van Asbroeck <[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/bus/Kconfig         |  10 ++
 drivers/bus/Makefile        |   1 +
 drivers/bus/anybus-bridge.c | 321 ++++++++++++++++++++++++++++++++++++
 3 files changed, 332 insertions(+)
 create mode 100644 drivers/bus/anybus-bridge.c
drivers/bus/Kconfig +10 -0
index 1851112ccc29..f29131529ddb 100644
@@ -173,6 +173,16 @@ config VEXPRESS_CONFIG
 	  Platform configuration infrastructure for the ARM Ltd.
 	  Versatile Express.
 
+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.
+
 config DA8XX_MSTPRI
 	bool "TI da8xx master peripheral priority driver"
 	depends on ARCH_DAVINCI_DA8XX
drivers/bus/Makefile +1 -0
index ca300b1914ce..24fa2cde0692 100644
@@ -30,5 +30,6 @@ obj-$(CONFIG_TI_SYSC)		+= ti-sysc.o
 obj-$(CONFIG_TS_NBUS)		+= ts-nbus.o
 obj-$(CONFIG_UNIPHIER_SYSTEM_BUS)	+= uniphier-system-bus.o
 obj-$(CONFIG_VEXPRESS_CONFIG)	+= vexpress-config.o
+obj-$(CONFIG_ARCX_ANYBUS_BRIDGE)	+= anybus-bridge.o
 
 obj-$(CONFIG_DA8XX_MSTPRI)	+= da8xx-mstpri.o
drivers/bus/anybus-bridge.c new file +321 -0

321 lines not on this page · raw message

Signature · 1 line
2.17.1
#9 lore raw

PATCH v3 2/6 dt-bindings: Add vendor prefix for arcx / Archronix

In reply to [email protected]

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
#12 lore raw

PATCH v3 3/6 dt-bindings: anybus-bridge: document devicetree binding

In reply to [email protected]

From: Sven Van Asbroeck <[email protected]>

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

---
 .../bindings/misc/arcx,anybus-bridge.txt      | 34 +++++++++++++++++++
 1 file changed, 34 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/misc/arcx,anybus-bridge.txt
Documentation/devicetree/bindings/misc/arcx,anybus-bridge.txt new file +34 -0
new file mode 100644
index 000000000000..cb801b7568b0
@@ -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
#14 lore raw

PATCH v3 4/6 bus: support HMS Anybus-S bus

In reply to [email protected]

From: Sven Van Asbroeck <[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/bus/Kconfig            |   10 +
 drivers/bus/Makefile           |    1 +
 drivers/bus/anybuss-host.c     | 1503 ++++++++++++++++++++++++++++++++
 include/linux/anybuss-client.h |  100 +++
 4 files changed, 1614 insertions(+)
 create mode 100644 drivers/bus/anybuss-host.c
 create mode 100644 include/linux/anybuss-client.h
drivers/bus/Kconfig +10 -0
index f29131529ddb..a11980889711 100644
@@ -45,6 +45,16 @@ config IMX_WEIM
 	  The WEIM(Wireless External Interface Module) works like a bus.
 	  You can attach many different devices on it, such as NOR, onenand.
 
+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.
+
 config MIPS_CDMM
 	bool "MIPS Common Device Memory Map (CDMM) Driver"
 	depends on CPU_MIPSR2
drivers/bus/Makefile +1 -0
index 24fa2cde0692..d2ab4716b509 100644
@@ -13,6 +13,7 @@ obj-$(CONFIG_BRCMSTB_GISB_ARB)	+= brcmstb_gisb.o
 obj-$(CONFIG_FSL_MC_BUS)	+= fsl-mc/
 
 obj-$(CONFIG_IMX_WEIM)		+= imx-weim.o
+obj-$(CONFIG_HMS_ANYBUSS_HOST)	+= anybuss-host.o
 obj-$(CONFIG_MIPS_CDMM)		+= mips_cdmm.o
 obj-$(CONFIG_MVEBU_MBUS) 	+= mvebu-mbus.o
 
drivers/bus/anybuss-host.c new file +1503 -0

1,503 lines not on this page · raw message

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

100 lines not on this page · raw message

Signature · 1 line
2.17.1
#22 lore raw

PATCH v3 5/6 dt-bindings: anybuss-host: document devicetree binding

In reply to [email protected]

From: Sven Van Asbroeck <[email protected]>

This patch adds devicetree binding documentation for the Arcx Anybus-S host.

---
 .../bindings/bus/arcx,anybuss-host.txt        | 36 +++++++++++++++++++
 1 file changed, 36 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/bus/arcx,anybuss-host.txt
Documentation/devicetree/bindings/bus/arcx,anybuss-host.txt new file +36 -0
new file mode 100644
index 000000000000..5c28e4e09bb2
@@ -0,0 +1,36 @@
+* 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.
+
+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>;
+	};
+};
Signature · 1 line
2.17.1
#27 lore raw

PATCH v3 6/6 misc: support HMS Profinet IRT industrial controller

In reply to [email protected]

From: Sven Van Asbroeck <[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 creates a /dev/profinet%d devnode, and a /sys/class/misc/profinet%d sysfs subdir:
- the card can be configured with a single, atomic ioctl on the devnode;
- the card's internal dpram is accessed by calling read/write/seek on the devnode.
- the card's "fieldbus specific area" properties can be accessed via the sysfs dir.

---
 Documentation/ioctl/ioctl-number.txt |   1 +
 drivers/misc/Kconfig                 |  10 +
 drivers/misc/Makefile                |   1 +
 drivers/misc/hms-profinet.c          | 753 +++++++++++++++++++++++++++
 include/uapi/linux/hms-common.h      |  14 +
 include/uapi/linux/hms-profinet.h    | 102 ++++
 6 files changed, 881 insertions(+)
 create mode 100644 drivers/misc/hms-profinet.c
 create mode 100644 include/uapi/linux/hms-common.h
 create mode 100644 include/uapi/linux/hms-profinet.h
Documentation/ioctl/ioctl-number.txt +1 -0
index 13a7c999c04a..a389a4ec1429 100644
@@ -241,6 +241,7 @@ Code  Seq#(hex)	Include File		Comments
 					<http://web.archive.org/web/*/http://mikonos.dia.unisa.it/tcfs>
 'l'	40-7F	linux/udf_fs_i.h	in development:
 					<http://sourceforge.net/projects/linux-udf/>
+'l'	80-9F	linux/hms-profinet.h	Anybus-S
 'm'	00-09	linux/mmtimer.h		conflict!
 'm'	all	linux/mtio.h		conflict!
 'm'	all	linux/soundcard.h	conflict!
drivers/misc/Kconfig +10 -0
index 3726eacdf65d..cf1ac5784048 100644
@@ -406,6 +406,16 @@ config SPEAR13XX_PCIE_GADGET
 	 entry will be created for that controller. User can use these
 	 sysfs node to configure PCIe EP as per his requirements.
 
+config HMS_PROFINET
+	tristate "HMS Profinet IRT Controller (Anybus-S)"
+	select HMS_ANYBUSS_HOST
+	help
+	 If you say yes here you get support for the HMS Industrial
+	 Networks Profinet IRT Controller.
+	 This driver can also be built as a module. If so, the module
+	 will be called hms-profinet.
+	 If unsure, say N.
+
 config VMWARE_BALLOON
 	tristate "VMware Balloon Driver"
 	depends on VMWARE_VMCI && X86 && HYPERVISOR_GUEST
drivers/misc/Makefile +1 -0
index af22bbc3d00c..dcf0468187b6 100644
@@ -34,6 +34,7 @@ obj-$(CONFIG_SENSORS_TSL2550)	+= tsl2550.o
 obj-$(CONFIG_DS1682)		+= ds1682.o
 obj-$(CONFIG_C2PORT)		+= c2port/
 obj-$(CONFIG_HMC6352)		+= hmc6352.o
+obj-$(CONFIG_HMS_PROFINET)	+= hms-profinet.o
 obj-y				+= eeprom/
 obj-y				+= cb710/
 obj-$(CONFIG_SPEAR13XX_PCIE_GADGET)	+= spear13xx_pcie_gadget.o
drivers/misc/hms-profinet.c new file +753 -0

753 lines not on this page · raw message

include/uapi/linux/hms-common.h new file +14 -0
new file mode 100644
index 000000000000..4b69963a3863
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright 2018 Archronix Corp. All Rights Reserved.
+ *
+ */
+
+#ifndef _UAPILINUX_HMSCOMMON_H_
+#define _UAPILINUX_HMSCOMMON_H_
+
+#define HMS_SMA_CLEAR		0
+#define HMS_SMA_FREEZE		1
+#define HMS_SMA_SET		2
+
+#endif /* _UAPILINUX_HMSCOMMON_H_ */
include/uapi/linux/hms-profinet.h new file +102 -0

102 lines not on this page · raw message

Signature · 1 line
2.17.1
Reviewed-by on v3 2/6
#10 lore raw

Re: [PATCH anybus v3 2/6] dt-bindings: Add vendor prefix for arcx / Archronix

In reply to [email protected]

Am 04.11.18 um 16:54 schrieb [email protected]:

Quoted 10 lines

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.

Quoted 5 lines

Websites:

	http://www.arcx.com/
	http://www.archronix.com/

Thanks,
Andreas

Signature · 3 lines
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
maintainer Reviewed-by on v3 2/6
#11 lore raw

Re: [PATCH anybus v3 2/6] dt-bindings: Add vendor prefix for arcx / Archronix

In reply to [email protected]
Quoted 10 lines · On Sun, 4 Nov 2018 10:54:57 -0500, [email protected] wrote:

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.

Quoted 9 lines

Websites:

	http://www.arcx.com/
	http://www.archronix.com/
---
 Documentation/devicetree/bindings/vendor-prefixes.txt | 1 +
 1 file changed, 1 insertion(+)
maintainer Reviewed-by on v3 3/6
#13 lore raw

Re: [PATCH anybus v3 3/6] dt-bindings: anybus-bridge: document devicetree binding

In reply to [email protected]
Quoted 11 lines · On Sun, 4 Nov 2018 10:54:58 -0500, [email protected] wrote:

From: Sven Van Asbroeck <[email protected]>

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

---
 .../bindings/misc/arcx,anybus-bridge.txt      | 34 +++++++++++++++++++
 1 file changed, 34 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/misc/arcx,anybus-bridge.txt
maintainer
#2 lore raw

Re: [PATCH anybus v3 1/6] misc: support the Arcx anybus bridge

In reply to [email protected]
Quoted 8 lines · On Sun, Nov 04, 2018 at 10:54:56AM -0500, [email protected] wrote:

From: Sven Van Asbroeck <[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.

bridge vs. host are confusing me as those are often the same thing. But here bridge is just some auxilliary controls for the bus and the host is the actual bus with devices? I'm not sure why you split this into 2 DT nodes? How many devices are connected to the host processor (i.MX) bus?

Rob

#3 lore raw

Re: [PATCH anybus v3 1/6] misc: support the Arcx anybus bridge

Quoted 6 lines · Rob Herring

bridge vs. host are confusing me as those are often the same thing. But here bridge is just some auxilliary controls for the bus and the host is the actual bus with devices? I'm not sure why you split this into 2 DT nodes? How many devices are connected to the host processor (i.MX) bus?

The anybus can only have a single client card (device) on the bus. I know, we can criticise the name, but that's how HMS Industrial Networks designed it.

The anybus-bridge is how we (at arcx / Archronix) physically connect anybus slots to the iMX. It is a CPLD chip connected to the i.MX WEIM bus on the SoC side. On the other side of the CPLD, there are two anybus slots. Each slot may hold an anybus card (profinet, flnet, cc-link, ...)

The anybuss-host implements the anybus specification in a platform-independent way. Some other company could attach anybus slots to their CPU through a completely different bus, or spi, and they could still attach the anybuss-host driver onto it. All the driver needs is a regmap providing access to the anybus slot memory, an interrupt, and a reset controller.

Sven

maintainer
#4 lore raw

Re: [PATCH anybus v3 1/6] misc: support the Arcx anybus bridge

Quoted 19 lines · Sven Van Asbroeck
Quoted 6 lines · Rob Herring

bridge vs. host are confusing me as those are often the same thing. But here bridge is just some auxilliary controls for the bus and the host is the actual bus with devices? I'm not sure why you split this into 2 DT nodes? How many devices are connected to the host processor (i.MX) bus?

The anybus can only have a single client card (device) on the bus. I know, we can criticise the name, but that's how HMS Industrial Networks designed it.

The anybus-bridge is how we (at arcx / Archronix) physically connect anybus slots to the iMX. It is a CPLD chip connected to the i.MX WEIM bus on the SoC side. On the other side of the CPLD, there are two anybus slots. Each slot may hold an anybus card (profinet, flnet, cc-link, ...)

Quoted 6 lines

The anybuss-host implements the anybus specification in a platform-independent way. Some other company could attach anybus slots to their CPU through a completely different bus, or spi, and they could still attach the anybuss-host driver onto it. All the driver needs is a regmap providing access to the anybus slot memory, an interrupt, and a reset controller.

It doesn't really sound like the host should be in DT. The bridge should register itself as an anybus provider and that should in turn enable the anybus host protocol.

Rob

#5 lore raw

Re: [PATCH anybus v3 1/6] misc: support the Arcx anybus bridge

Quoted 3 lines · Rob Herring

It doesn't really sound like the host should be in DT. The bridge should register itself as an anybus provider and that should in turn enable the anybus host protocol.

Very good point. Just to make sure we're on the same page, could you point me to a relevant example where something registers as a provider?

v1 of this patch did not have the host in DT. The host just required platform data with a regmap and a reset (the interrupt was passed via resources):

struct anybuss_host_pdata {
    struct regmap *regmap;
    void (*reset)(struct device *dev, bool reset);
};

But there were problems with this approach.

The review feedback told me that my self-rolled reset callback should really be a reset controller. I looked for ways to pass a handle to a reset controller via platform data. This has recently been introduced via:

reset_controller_add_lookup()

This binds a client device to a reset controller, without using the devicetree, so the device can grab its controller via (devm_)reset_control_get*. Great! But... to make the binding, you have to specify the full device names of the controllers and client devices. See this example from psc-da850.c:

static struct reset_control_lookup da850_psc0_reset_lookup_table[] = {
    RESET_LOOKUP("da850-psc0", 15, "davinci-rproc.0", NULL),
};

I very quickly found myself in ida_simple_get() hell, trying to second-guess what the devices I was creating, would be called !

So instead I put the host in DT, then I could easily connect the reset controller. This also greatly simplified the bridge driver, a lot of boilerplate would simply disappear.

Suggestions are very welcome :)

Sven

maintainer
#6 lore raw

Re: [PATCH anybus v3 1/6] misc: support the Arcx anybus bridge

Quoted 9 lines · Sven Van Asbroeck
Quoted 3 lines · Rob Herring

It doesn't really sound like the host should be in DT. The bridge should register itself as an anybus provider and that should in turn enable the anybus host protocol.

Very good point. Just to make sure we're on the same page, could you point me to a relevant example where something registers as a provider?

Not sure exactly. Perhaps I2C SMBus functions that implement the register access protocol on top of I2C bus.

Quoted 9 lines

v1 of this patch did not have the host in DT. The host just required platform data with a regmap and a reset (the interrupt was passed via resources):

struct anybuss_host_pdata {
    struct regmap *regmap;
    void (*reset)(struct device *dev, bool reset);
};

But there were problems with this approach.

A block diagram would help. Something that shows the host SoC, your CPLD, reset, irq, etc.

Quoted 3 lines

The review feedback told me that my self-rolled reset callback should really be a reset controller. I looked for ways to pass a handle to a reset controller via platform data. This has recently been introduced via:

Maybe an overkill for 1 reset.

Quoted 12 lines

reset_controller_add_lookup()

This binds a client device to a reset controller, without using the devicetree, so the device can grab its controller via (devm_)reset_control_get*. Great! But... to make the binding, you have to specify the full device names of the controllers and client devices. See this example from psc-da850.c:

static struct reset_control_lookup da850_psc0_reset_lookup_table[] = {
    RESET_LOOKUP("da850-psc0", 15, "davinci-rproc.0", NULL),
};
Quoted 6 lines

I very quickly found myself in ida_simple_get() hell, trying to second-guess what the devices I was creating, would be called !

So instead I put the host in DT, then I could easily connect the reset controller. This also greatly simplified the bridge driver, a lot of boilerplate would simply disappear.

If the host is not a h/w component, but just a s/w protocol then it doesn't belong in DT. Perhaps it could be a library which the bridge driver can call into.

What are the resets connected to? The slots? Maybe you should model the slots in DT.

Rob

#7 lore raw

Re: [PATCH anybus v3 1/6] misc: support the Arcx anybus bridge

Quoted 3 lines · Rob Herring

If the host is not a h/w component, but just a s/w protocol then it doesn't belong in DT. Perhaps it could be a library which the bridge driver can call into.

Anybus cards have an id register, which identifies what they are, so that the appropriate client driver may be instantiated. In that sense anybus is very suited to the bus/client abstraction of pci/usb/etc.

Quoted 3 lines

What are the resets connected to? The slots? Maybe you should model the slots in DT.

Yes, the resets are ultimately connected to the slots.
I'm happy to model the slots in DT. It makes sense, they are physical, hardware components.

Quoted 4 lines

A block diagram would help. Something that shows the host SoC, your CPLD, reset, irq, etc.

  +------------------------------------------------------------------------+
  |                                  SOC (i.MX6)                           |
  |------------------------------------------------------------------------|
  |     i.MX WEIM bus                                   | i.MX GPIO        |
  +------------------------------------------------------------------------+
                ^                                              ^ ^
                | parallel bus                                 | | irq x2
                v                                              | |
  +------------------------------------------------------------------------+
  |                                     CPLD                               |
  |------------------------------------------------------------------------|
  |             anybus slot 1             ||            anybus slot 2      |
  |------------------------------------------------------------------------|
  | memory bus               | irq| reset || memory bus       | irq| reset |
  +------------------------------------------------------------------------+
                ^                                               ^
                |                                               |
                v                                               v
  +--------------------------------------+ +-------------------------------+
  |          anybus card                 | |           anybus card         |
  +--------------------------------------+ +-------------------------------+
maintainer
#8 lore raw

Re: [PATCH anybus v3 1/6] misc: support the Arcx anybus bridge

Quoted 11 lines · Sven Van Asbroeck
Quoted 3 lines · Rob Herring

If the host is not a h/w component, but just a s/w protocol then it doesn't belong in DT. Perhaps it could be a library which the bridge driver can call into.

Anybus cards have an id register, which identifies what they are, so that the appropriate client driver may be instantiated. In that sense anybus is very suited to the bus/client abstraction of pci/usb/etc.

Quoted 7 lines
Quoted 3 lines

What are the resets connected to? The slots? Maybe you should model the slots in DT.

Yes, the resets are ultimately connected to the slots.
I'm happy to model the slots in DT. It makes sense, they are physical, hardware components.

It may also be necessary to have a way to add more DT properties to a device in the slot that can not be probed by looking at the ID register. Ideally it should not be needed, but we have added this to most buses anyway: USB, PCI, MMC and others can all be probed automatically for many devices, but there are some devices that need a place where extra information can be stored, e.g. an ethernet MAC address (in the absence of a PROM), an external clock or reset line that is not part of the normal protocol, or a more specific identification when two devices accidentally have the same ID.

Arnd

maintainer
#15 lore raw

Re: [PATCH anybus v3 4/6] bus: support HMS Anybus-S bus

In reply to [email protected]

drivers/bus/anybuss-host.c line 236

Quoted 13 lines · On Sun, Nov 4, 2018 at 4:55 PM <[email protected]> wrote:

From: Sven Van Asbroeck <[email protected]>

drivers/bus/anybuss-host.c new file +11 -0
+struct anybus_mbox_hdr {
+       u16 id;
+       u16 info;
+       u16 cmd_num;
+       u16 data_size;
+       u16 frame_count;
+       u16 frame_num;
+       u16 offset_high;
+       u16 offset_low;
+       u16 extended[8];
+} __packed;

I don't think you want this to be __packed, it won't change the layout but instead force byte accesses on architectures that don't have fast unaligned load/store instructions.

Instead of the __packed, it's almost always better to ensure that the structure itself is aligned to a 16-bit address.

Quoted 6 lines
drivers/bus/anybuss-host.c new file +6 -0
+static struct ab_task *ab_task_create_get(struct kmem_cache *cache,
+                       ab_task_fn_t task_fn)
+{
+       struct ab_task *t;
+
+       t = kmem_cache_alloc(cache, GFP_KERNEL);

drivers/bus/anybuss-host.c line 274

Quoted 10 lines
drivers/bus/anybuss-host.c new file +10 -0
+       if (!t)
+               return NULL;
+       t->cache = cache;
+       refcount_set(&t->refcnt, 1);
+       t->task_fn = task_fn;
+       t->done_fn = NULL;
+       t->result = 0;
+       init_completion(&t->done);
+       return t;
+}

It looks like you build your own object management here. Maybe use kobject, or at least kref instead of the refcount_t based low-level implementation?

Quoted 13 lines
drivers/bus/anybuss-host.c new file +13 -0
+struct anybuss_host {
+       struct device *dev;
+       struct anybuss_client *client;
+       struct reset_control *reset;
+       struct regmap *regmap;
+       int irq;
+       struct task_struct *qthread;
+       wait_queue_head_t wq;
+       struct completion card_boot;
+       atomic_t ind_ab;
+       spinlock_t qlock;
+       struct kmem_cache *qcache;
+       struct kfifo qs[3];

drivers/bus/anybuss-host.c line 365

Quoted 10 lines
drivers/bus/anybuss-host.c new file +10 -0
+       struct kfifo *powerq;
+       struct kfifo *mboxq;
+       struct kfifo *areaq;
+       bool power_on;
+       bool softint_pending;
+       atomic_t dc_event;
+       wait_queue_head_t dc_wq;
+       atomic_t fieldbus_online;
+       struct kernfs_node *fieldbus_online_sd;
+};

Similarly, should that anybuss_host sturcture maybe be based on a 'struct device' itself? What is the hierarchy of devices in sysfs?

Quoted 6 lines
drivers/bus/anybuss-host.c new file +6 -0
+
+static int read_ind_ab(struct regmap *regmap)
+{
+       unsigned long timeout = jiffies + HZ/2;
+       unsigned int a, b;
+

drivers/bus/anybuss-host.c line 396

Quoted 10 lines
drivers/bus/anybuss-host.c new file +10 -0
+       while (time_before_eq(jiffies, timeout)) {
+               regmap_read(regmap, REG_IND_AB, &a);
+               regmap_read(regmap, REG_IND_AB, &b);
+               if (likely(a == b))
+                       return (int)a;
+               cpu_relax();
+       }
+       WARN(1, "IND_AB register not stable");
+       return -ETIMEDOUT;
+}

500ms is an awfully long time for a busy loop. Can you change the cpu_relax() into a msleep() or usleep_range() to let other processes get some time?

I see this is called from the interrupt handler at the moment, which means you cannot call sleeping functions, but it also means that the timeout may never happen because the timer tick IRQ cannot get through. That means you may have to change the irq handler logic, e.g. to try this a few times but then defer to a bottom half if it fails for a long time.

drivers/bus/anybuss-host.c line 661

Quoted 13 lines
drivers/bus/anybuss-host.c new file +13 -0
+/* -------------------------- mailbox tasks ----------------------- */
+
+struct msgAnybusInit {
+       u16 input_io_len;
+       u16 input_dpram_len;
+       u16 input_total_len;
+       u16 output_io_len;
+       u16 output_dpram_len;
+       u16 output_total_len;
+       u16 op_mode;
+       u16 notif_config;
+       u16 wd_val;
+} __packed;

Again, probably not __packed here.

Quoted 4 lines
drivers/bus/anybuss-host.c new file +4 -0
+static int task_fn_mbox_2(struct anybuss_host *cd, struct ab_task *t)
+{
+       struct mbox_priv *pd = &t->mbox_pd;
+       unsigned int ind_ap;

drivers/bus/anybuss-host.c line 676

Quoted 10 lines
drivers/bus/anybuss-host.c new file +10 -0
+
+       if (!cd->power_on)
+               return -EIO;
+       regmap_read(cd->regmap, REG_IND_AP, &ind_ap);
+       if (((atomic_read(&cd->ind_ab) ^ ind_ap) & IND_AX_MOUT) == 0) {
+               /* output message not here */
+               if (time_after(jiffies, t->start_jiffies + TIMEOUT))
+                       return -ETIMEDOUT;
+               return -EINPROGRESS;
+       }

Again, avoid busy loops with long timeouts like this.

Arnd

maintainer
#23 lore raw

Re: [PATCH anybus v3 5/6] dt-bindings: anybuss-host: document devicetree binding

In reply to [email protected]
Quoted 24 lines · On Sun, Nov 4, 2018 at 4:55 PM <[email protected]> wrote:
---
 .../bindings/bus/arcx,anybuss-host.txt        | 36 +++++++++++++++++++
 1 file changed, 36 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/bus/arcx,anybuss-host.txt
Documentation/devicetree/bindings/bus/arcx,anybuss-host.txt new file +13 -0
new file mode 100644
index 000000000000..5c28e4e09bb2
@@ -0,0 +1,36 @@
+* 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.
+

Documentation/devicetree/bindings/bus/arcx,anybuss-host.txt line 23

Quoted 10 lines
Documentation/devicetree/bindings/bus/arcx,anybuss-host.txt new file +10 -0
+  - 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.
+
+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

To allow describing connected devices, I think we need a #address-cells and #size-cells property here, with fixed values. If a device is attached by a single 32-bit integer, then

#address-cells = <1>;
#size-cells = <0>;

should be enough, otherwise you might need additional address cells. Actually listing the device(s) can be optional, but we do need the adress in order
to let the bus code associate a device_node pointer with the child device structure to let a driver read the properties.

Arnd

maintainer
#28 lore raw

Re: [PATCH anybus v3 6/6] misc: support HMS Profinet IRT industrial controller

In reply to [email protected]

drivers/misc/hms-profinet.c line 33

Quoted 4 lines · On Sun, Nov 4, 2018 at 4:55 PM <[email protected]> wrote:
drivers/misc/hms-profinet.c new file +4 -0
+
+struct msgEthConfig {
+       u32 ip_addr, subnet_msk, gateway_addr;
+} __packed;

The __packed attribute makes it slower to access but doesn't change the layout, so better drop it.

Quoted 5 lines
drivers/misc/hms-profinet.c new file +5 -0
+struct msgMacAddr {
+       u8 addr[6];
+} __packed;
+
+struct msgStr {

drivers/misc/hms-profinet.c line 49

Quoted 10 lines
drivers/misc/hms-profinet.c new file +10 -0
+       char    s[128];
+} __packed;
+
+struct msgShortStr {
+       char    s[64];
+} __packed;
+
+struct msgHicp {
+       char    enable;
+} __packed;

The __packed on these ones has no effect, and can just be dropped for readability.

Quoted 14 lines
drivers/misc/hms-profinet.c new file +14 -0
+static ssize_t mac_addr_show(struct device *dev,
+                               struct device_attribute *attr,
+                               char *buf)
+{
+       struct profi_priv *priv = dev_get_drvdata(dev);
+       struct msgMacAddr response;
+       int ret;
+
+       ret = anybuss_recv_msg(priv->client, 0x0010, &response,
+                                               sizeof(response));
+       if (ret)
+               return ret;
+       return snprintf(buf, PAGE_SIZE, "%02X:%02X:%02X:%02X:%02X:%02X\n",
+               response.addr[0], response.addr[1],

drivers/misc/hms-profinet.c line 346

Quoted 10 lines
drivers/misc/hms-profinet.c new file +9 -0
+               response.addr[2], response.addr[3],
+               response.addr[4], response.addr[5]);
+}
+
+static DEVICE_ATTR_RO(mac_addr);
 
+static ssize_t ip_addr_show(struct device *dev,
+                               struct device_attribute *attr,
+                               char *buf)
+{

I don't understand much about field bus, but I have a general feeling that if you configure a mac address and IP address, this should be connect ed to the network layer in some form, possibly being exposed as a network device and manipulated using netlink instead of sysfs or ioctl.

Can you explain how this fits together and why you got the the sysfs interface?

Quoted 1 line

+struct ProfinetConfig {

The CamelCase naming seems odd here.

include/uapi/linux/hms-profinet.h line 22

Quoted 7 lines
include/uapi/linux/hms-profinet.h new file +7 -0
+       struct {
+               /* addresses IN NETWORK ORDER! */
+               __u32 ip_addr;
+               __u32 subnet_msk;
+               __u32 gateway_addr;
+               __u8  is_valid:1;
+       } eth;

This is where packing might make sense, since you have padding fields in a user space structure ;-) . It would be better to just avoid the implicit padding though and name all fields.

Overall, this structure feels too complex for an ioctl interface, with the nested structures. If we end up keeping that ioctl, maybe at least make it a flat structure without padding, or alternatively make it a set of separate ioctls.

Arnd

#24 lore raw

Re: [PATCH anybus v3 5/6] dt-bindings: anybuss-host: document devicetree binding

In reply to Arnd Bergmann

Hi Arnd, thank you for the review and the feedback !

Quoted 3 lines

To allow describing connected devices, I think we need a #address-cells and #size-cells property here, with fixed values.

I'm not sure I understand. Connected devices aren't described in the devicetree. The anybus specification defines an id register, which is then used to load the client driver automatically, in the manner of pci/usb.

In case I have misinterpreted your feedback, could you clarify a bit? Thanks,
Sven

E.g. here's the definition of an anybus client driver, a profinet card:

static struct anybuss_client_driver profinet_driver = {
.probe = profinet_probe,
.remove = profinet_remove,
.driver = {
.name = "hms-profinet",
.owner = THIS_MODULE,
},
.fieldbus_type = 0x0089,
};

static int __init profinet_init(void)

{
    return anybuss_client_driver_register(&profinet_driver);
}

module_init(profinet_init);

maintainer
#25 lore raw

Re: [PATCH anybus v3 5/6] dt-bindings: anybuss-host: document devicetree binding

Quoted 7 lines · Sven Van Asbroeck

Hi Arnd, thank you for the review and the feedback !

Quoted 3 lines

To allow describing connected devices, I think we need a #address-cells and #size-cells property here, with fixed values.

Quoted 6 lines

I'm not sure I understand. Connected devices aren't described in the devicetree. The anybus specification defines an id register, which is then used to load the client driver automatically, in the manner of pci/usb.

In case I have misinterpreted your feedback, could you clarify a bit?

This is related to my reply on another patch of this series. I think it's likely that you need to be able to describe anybus devices in DT for additional properties in some cases, even if the common case doesn't need it.

We do the same thing on PCI and USB, where normally everything is probed through hardware access, but a device driver can look at dev->of_node to see if that contains any further properties.

Arnd

#29 lore raw

Re: [PATCH anybus v3 6/6] misc: support HMS Profinet IRT industrial controller

In reply to Arnd Bergmann

Hi Arnd,

These are great questions, I had been wondering when they would be brought up :)

Quoted 9 lines · Arnd Bergmann

I don't understand much about field bus, but I have a general feeling that if you configure a mac address and IP address, this should be connect ed to the network layer in some form, possibly being exposed as a network device and manipulated using netlink instead of sysfs or ioctl.

Can you explain how this fits together and why you got the the sysfs interface?

I started typing here how a fieldbus differs from a networking device, and how it does not fit in the kernel abstraction for networking devices.

Then I started explaining the "roll my own" userspace API I created for fieldbus devices... and it hit me. There is already a fieldbus API !

include/linux/uio_driver.h

Let me go and check how well it fits with what my device needs.

Quoted 8 lines

include/uapi/linux/hms-profinet.h line 22

Quoted 7 lines
include/uapi/linux/hms-profinet.h new file +7 -0
+       struct {
+               /* addresses IN NETWORK ORDER! */
+               __u32 ip_addr;
+               __u32 subnet_msk;
+               __u32 gateway_addr;
+               __u8  is_valid:1;
+       } eth;
Quoted 5 lines

Overall, this structure feels too complex for an ioctl interface, with the nested structures. If we end up keeping that ioctl, maybe at least make it a flat structure without padding, or alternatively make it a set of separate ioctls.

I agree that it feels complex, but it's the best I could come up with. There are a few hidden constraints:

1. The profinet card configuration settings must be applied atomically. And they can only be applied right after device reset.

So if we use smaller, separate ioctls, we will end up resetting the device each time we send an ioctl. And to assemble a real configuration, we need 5 or 6 ioctls, so the card gets reset 5 or 6 times, which takes ages. It cannot work this way.

2. Configuration settings are optional. That's why why each little struct has an is_valid member. If we use a flatter structure, we need a bool for every config setting in the struct, to indicate if it should be applied. Which feels clunky.

One way to overcome this is by letting the ioctls change data in the driver, but not on the card. Then a separate "apply" ioctl could apply the whole configuration atomically.

Example:
ioctl(clear all settings?);
ioctl(set ip address);
ioctl(set stop mode action);
ioctl(enable internal webserver);
ioctl(apply);

But of course, what happens if two processes try to configure the driver at the same time?
The ioctl calls would be interleaved, and the result would be very messy...

There must be a better way?

#16 lore raw

Re: [PATCH anybus v3 4/6] bus: support HMS Anybus-S bus

In reply to Arnd Bergmann
Quoted 4 lines · Arnd Bergmann

It looks like you build your own object management here. Maybe use kobject, or at least kref instead of the refcount_t based low-level implementation?

Excellent point. I'll replace with krefs.

Quoted 8 lines

I see this is called from the interrupt handler at the moment, which means you cannot call sleeping functions, but it also means that the timeout may never happen because the timer tick IRQ cannot get through. That means you may have to change the irq handler logic, e.g. to try this a few times but then defer to a bottom half if it fails for a long time.

Touche ! Yes, this is very likely a big problem.

What if I converted the interrupt handler into a threaded interrupt handler? That would allow the timer tick to get through, correct?

Point taken about cpu_relax(), I will fix.

maintainer
#30 lore raw

Re: [PATCH anybus v3 6/6] misc: support HMS Profinet IRT industrial controller

In reply to Sven Van Asbroeck
Quoted 26 lines · Sven Van Asbroeck
Quoted 8 lines · Arnd Bergmann

+ struct {

include/uapi/linux/hms-profinet.h line 22

Quoted 6 lines
include/uapi/linux/hms-profinet.h new file +6 -0
+               /* addresses IN NETWORK ORDER! */
+               __u32 ip_addr;
+               __u32 subnet_msk;
+               __u32 gateway_addr;
+               __u8  is_valid:1;
+       } eth;
Quoted 5 lines

Overall, this structure feels too complex for an ioctl interface, with the nested structures. If we end up keeping that ioctl, maybe at least make it a flat structure without padding, or alternatively make it a set of separate ioctls.

I agree that it feels complex, but it's the best I could come up with. There are a few hidden constraints:

1. The profinet card configuration settings must be applied atomically. And they can only be applied right after device reset.

So if we use smaller, separate ioctls, we will end up resetting the device each time we send an ioctl. And to assemble a real configuration, we need 5 or 6 ioctls, so the card gets reset 5 or 6 times, which takes ages. It cannot work this way.

Quoted 4 lines

2. Configuration settings are optional. That's why why each little struct has an is_valid member. If we use a flatter structure, we need a bool for every config setting in the struct, to indicate if it should be applied. Which feels clunky.

I think a more common way to do this would be to use a __u64 member containing a bitmask of which fields are valid.

Quoted 11 lines

One way to overcome this is by letting the ioctls change data in the driver, but not on the card. Then a separate "apply" ioctl could apply the whole configuration atomically.

Example:
ioctl(clear all settings?);
ioctl(set ip address);
ioctl(set stop mode action);
ioctl(enable internal webserver);
ioctl(apply);

Quoted 5 lines

But of course, what happens if two processes try to configure the driver at the same time?
The ioctl calls would be interleaved, and the result would be very messy...

There must be a better way?

In particular the bits about optional fields would fit much better into netlink, which is a kind of TLV interface, and you can send a number of configuration steps in one 'sendmsg' syscall, but leave out the ones that you are not interested in.

This would also allow you to specify standard parameters that could apply to multiple vendors or fieldbus protocols, and have a common configuration tool for all of them.

Arnd

maintainer
#17 lore raw

Re: [PATCH anybus v3 4/6] bus: support HMS Anybus-S bus

In reply to Sven Van Asbroeck
Quoted 8 lines · Sven Van Asbroeck
Quoted 6 lines · Arnd Bergmann

I see this is called from the interrupt handler at the moment, which means you cannot call sleeping functions, but it also means that the timeout may never happen because the timer tick IRQ cannot get through. That means you may have to change the irq handler logic, e.g. to try this a few times but then defer to a bottom half if it fails for a long time.

Quoted 4 lines

Touche ! Yes, this is very likely a big problem.

What if I converted the interrupt handler into a threaded interrupt handler? That would allow the timer tick to get through, correct?

Yes, with a threaded IRQ handler, the tick comes through, and you can use a sleeping function to back off between the retries.

Arnd

#31 lore raw
In reply to [email protected]

Arnd, Rob, Linus,

Many thanks for your constructive feedback so far !

Is there anything in general about this set that would prevent it from being mainlined? Perhaps I am trying to do too much at once, dropping a patchset that is too complex to be properly reviewed?

I've been thinking about reworking the host to its simplest, yet feature- complete form. Just serialize all card accesses with a single lock. Then the kernel thread, kqueue, kcache, kref etc would all disappear. The price we pay is a reduction in performance/parallelism. We could then increase parallelism at a later stage.
Would that be of any help?

Comments on v3 will go into v4 shortly.
(Rob, I'm not sure how to address your feedback, other than to s/host/slot/g ?)

Yours,
Sven

#18 lore raw

Re: [PATCH anybus v3 4/6] bus: support HMS Anybus-S bus

In reply to Arnd Bergmann
Quoted 17 lines · Arnd Bergmann

drivers/bus/anybuss-host.c line 236

Quoted 12 lines
drivers/bus/anybuss-host.c new file +11 -0
+struct anybus_mbox_hdr {
+       u16 id;
+       u16 info;
+       u16 cmd_num;
+       u16 data_size;
+       u16 frame_count;
+       u16 frame_num;
+       u16 offset_high;
+       u16 offset_low;
+       u16 extended[8];
+} __packed;

I don't think you want this to be __packed, it won't change the layout but instead force byte accesses on architectures that don't have fast unaligned load/store instructions.

Quoted 3 lines

Instead of the __packed, it's almost always better to ensure that the structure itself is aligned to a 16-bit address.

A general question about __packed.

My current understanding is this:
(please tell me if it's incorrect or incomplete)

+ without __packed, the compiler is free to pad the struct in whatever way it feels is best.
+ with __packed, the fields have to be laid out EXACTLY as specified.

Is it possible that someone will compile this on an architecture that 'likes' 16-bit ints to be 32-bit aligned? If such an architecture does not currently exist, could it appear in the future?

If the compiler changes the padding in the struct, the driver will break, as the struct layout is tightly defined by the anybus spec.

Would it be better to stay safe, and keep __packed in case of such tightly defined structures?

maintainer
#19 lore raw

Re: [PATCH anybus v3 4/6] bus: support HMS Anybus-S bus

Quoted 23 lines · Sven Van Asbroeck
Quoted 17 lines · Arnd Bergmann

drivers/bus/anybuss-host.c line 236

Quoted 12 lines
drivers/bus/anybuss-host.c new file +11 -0
+struct anybus_mbox_hdr {
+       u16 id;
+       u16 info;
+       u16 cmd_num;
+       u16 data_size;
+       u16 frame_count;
+       u16 frame_num;
+       u16 offset_high;
+       u16 offset_low;
+       u16 extended[8];
+} __packed;

I don't think you want this to be __packed, it won't change the layout but instead force byte accesses on architectures that don't have fast unaligned load/store instructions.

Quoted 3 lines

Instead of the __packed, it's almost always better to ensure that the structure itself is aligned to a 16-bit address.

Quoted 8 lines

A general question about __packed.

My current understanding is this:
(please tell me if it's incorrect or incomplete)

+ without __packed, the compiler is free to pad the struct in whatever way it feels is best.
+ with __packed, the fields have to be laid out EXACTLY as specified.

It's not up to the compiler but the ELF ABI. The rules are largely consisten among the architectures we support, but there are a couple of notable exceptions:

- ARM OABI requires 32-bit alignment for structures
- x86-32 aligns 64-bit members to 32-bit rather than 64-bit
- m68k has some oddities, I think they can pack certain members (don't remember the details)

Quoted 3 lines

Is it possible that someone will compile this on an architecture that 'likes' 16-bit ints to be 32-bit aligned? If such an architecture does not currently exist, could it appear in the future?

I'm fairly sure Linux would not be portable to an architecture like this without a major development effort.

Quoted 5 lines

If the compiler changes the padding in the struct, the driver will break, as the struct layout is tightly defined by the anybus spec.

Would it be better to stay safe, and keep __packed in case of such tightly defined structures?

Generally I think it does more harm than good. If you require __packed attributes for correct structure layout, then only apply it to those members that are not naturally aligned, and mark the structure itself as __aligned(n) with the alignment you expect if that makes a difference.

Arnd

maintainer
#32 lore raw
In reply to Sven Van Asbroeck
Quoted 8 lines · Sven Van Asbroeck

Arnd, Rob, Linus,

Many thanks for your constructive feedback so far !

Is there anything in general about this set that would prevent it from being mainlined? Perhaps I am trying to do too much at once, dropping a patchset that is too complex to be properly reviewed?

As usual, it comes down to the user space interfaces I think. Designing a user interface is hard, most importantly because you cannot change it once anyone starts relying on it, as opposed to implementation details that you are free to change at any point.

It's also hard to find reviewers for it, the best you can hope for is that you find people that have both knowledge about the type of hardware you work with and Linux user interface design, and get them to review the code.

Quoted 6 lines

I've been thinking about reworking the host to its simplest, yet feature- complete form. Just serialize all card accesses with a single lock. Then the kernel thread, kqueue, kcache, kref etc would all disappear. The price we pay is a reduction in performance/parallelism. We could then increase parallelism at a later stage.
Would that be of any help?

I don't think that's a major issue. If you are happy with the implementation there, and you use the interfaces correctly, that won't stop the driver from getting merged, even if you could rework it to use something else later.

Arnd

#33 lore raw
Quoted 6 lines · Arnd Bergmann

As usual, it comes down to the user space interfaces I think. Designing a user interface is hard, most importantly because you cannot change it once anyone starts relying on it, as opposed to implementation details that you are free to change at any point.

Thanks for the feedback !
I will rework v4 so it uses a userspace interface shared with other fieldbus drivers - uio.
Let's see how it goes.

maintainer
#34 lore raw
Quoted 4 lines · Sven Van Asbroeck
Quoted 2 lines · Arnd Bergmann
Quoted 8 lines
Quoted 4 lines

As usual, it comes down to the user space interfaces I think. Designing a user interface is hard, most importantly because you cannot change it once anyone starts relying on it, as opposed to implementation details that you are free to change at any point.

Thanks for the feedback !
I will rework v4 so it uses a userspace interface shared with other fieldbus drivers - uio.

You mentioned this before, but I don't see how this would actually work. Isn't uio just a slim wrapper for allowing user space access to hardware registers while avoiding a kernel driver?

Arnd

#20 lore raw

Re: [PATCH anybus v3 4/6] bus: support HMS Anybus-S bus

In reply to Arnd Bergmann
Quoted 31 lines · Arnd Bergmann
Quoted 21 lines · Sven Van Asbroeck
Quoted 16 lines · Arnd Bergmann

drivers/bus/anybuss-host.c line 236

Quoted 11 lines
drivers/bus/anybuss-host.c new file +11 -0
+struct anybus_mbox_hdr {
+       u16 id;
+       u16 info;
+       u16 cmd_num;
+       u16 data_size;
+       u16 frame_count;
+       u16 frame_num;
+       u16 offset_high;
+       u16 offset_low;
+       u16 extended[8];
+} __packed;

I don't think you want this to be __packed, it won't change the layout but instead force byte accesses on architectures that don't have fast unaligned load/store instructions.

Quoted 3 lines

Instead of the __packed, it's almost always better to ensure that the structure itself is aligned to a 16-bit address.

Quoted 8 lines

A general question about __packed.

My current understanding is this:
(please tell me if it's incorrect or incomplete)

+ without __packed, the compiler is free to pad the struct in whatever way it feels is best.
+ with __packed, the fields have to be laid out EXACTLY as specified.

Quoted 8 lines

It's not up to the compiler but the ELF ABI. The rules are largely consisten among the architectures we support, but there are a couple of notable exceptions:

- ARM OABI requires 32-bit alignment for structures
- x86-32 aligns 64-bit members to 32-bit rather than 64-bit
- m68k has some oddities, I think they can pack certain members (don't remember the details)

M68k aligns 16-bit and larger members to 16-bit.

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
#21 lore raw

Re: [PATCH anybus v3 4/6] bus: support HMS Anybus-S bus

In reply to Arnd Bergmann
Quoted 20 lines · Arnd Bergmann
Quoted 20 lines
drivers/bus/anybuss-host.c new file +18 -0
+struct anybuss_host {
+       struct device *dev;
+       struct anybuss_client *client;
+       struct reset_control *reset;
+       struct regmap *regmap;
+       int irq;
+       struct task_struct *qthread;
+       wait_queue_head_t wq;
+       struct completion card_boot;
+       atomic_t ind_ab;
+       spinlock_t qlock;
+       struct kmem_cache *qcache;
+       struct kfifo qs[3];
+       struct kfifo *powerq;
+       struct kfifo *mboxq;
+       struct kfifo *areaq;
+       bool power_on;
+       bool softint_pending;
Quoted 9 lines

drivers/bus/anybuss-host.c line 365

Quoted 5 lines
drivers/bus/anybuss-host.c new file +5 -0
+       atomic_t dc_event;
+       wait_queue_head_t dc_wq;
+       atomic_t fieldbus_online;
+       struct kernfs_node *fieldbus_online_sd;
+};

Similarly, should that anybuss_host sturcture maybe be based on a 'struct device' itself? What is the hierarchy of devices in sysfs?

The anybus host 'is-a' platform device. The dev member in struct anybuss_host is actually &pdev->dev.

The host's platform device shows up in sysfs under /sys/bus/platform/devices/anybuss-host.0.auto
where .0 is the first anybus slot on the bridge, .1 the second slot. If there is more than one bridge, we'll see .2, .3 etc.

Here are the virtual files in that dir:

drwxr-xr-x 3 root root 0 Nov 12 11:02
anybuss-host.0.auto.card0
lrwxrwxrwx 1 root root 0 Nov 12 11:11 driver ->
../../../../../../../bus/platform/drivers/anybuss-host

-rw-r--r--    1 root     root          4096 Nov 12 11:11 driver_override
drwxr-xr-x    3 root     root             0 Nov 12 11:02 misc
-r--r--r--    1 root     root          4096 Nov 12 11:11 modalias
drwxr-xr-x    2 root     root             0 Nov 12 11:11 power
-r--r--r--    1 root     root          4096 Nov 12 11:11 state
lrwxrwxrwx    1 root     root             0 Nov 12 11:11 subsystem ->

../../../../../../../bus/platform
-rw-r--r-- 1 root root 4096 Nov 12 11:02 uevent

Where
anybuss-host.0.auto.card0 just points to the detected anybus card, if any. Nothing to see there, it's just an artefact of the bus/device abstraction. misc points to the detected anybus card driver (which is implemented as a misc class device).

This sysfs hierarchy makes sense to me. Is there something I should be doing (or not doing) ?

#26 lore raw

Re: [PATCH anybus v3 5/6] dt-bindings: anybuss-host: document devicetree binding

In reply to Arnd Bergmann
Quoted 5 lines · Arnd Bergmann

We do the same thing on PCI and USB, where normally everything is probed through hardware access, but a device driver can look at dev->of_node to see if that contains any further properties.

This is very interesting. Spent some time trying to find an example of this for pci/usb, but drew a blank. Could you point me to an example?

One of our products has pcie ethernet, but we have to patch it so it can grab its mac address from the bootloader. You are saying that there is a standard way to accomplish this?