mctp: Add MCTP-over-serial transport binding
Subsystems (4)
Jeremy Kerr
maintainerPATCH 1/1 mctp: Add MCTP-over-serial transport binding
This change adds a MCTP Serial transport binding, as per DMTF DSP0253. This is implemented as a new serial line discipline, and can be attached to arbitrary serial devices.
The 'mctp' utility provides the ldisc magic to set up the serial link:
# mctp link serial /dev/ttyS0 & # mctp link dev lo index 1 address 0x00:00:00:00:00:00 net 1 mtu 65536 up dev mctpserial0 index 5 address 0x(no-addr) net 1 mtu 68 down
--- drivers/net/mctp/Kconfig | 11 + drivers/net/mctp/Makefile | 1 + drivers/net/mctp/mctp-serial.c | 494 +++++++++++++++++++++++++++++++++ include/uapi/linux/tty.h | 1 + 4 files changed, 507 insertions(+) create mode 100644 drivers/net/mctp/mctp-serial.c
drivers/net/mctp/Kconfig +11 -0
@@ -3,6 +3,17 @@ if MCTP menu "MCTP Device Drivers" +config MCTP_SERIAL + tristate "MCTP serial transport" + depends on TTY + select CRC_CCITT + help + This driver provides an MCTP-over-serial interface, through a + serial line-discipline. By attaching the ldisc to a serial device, + we get a new net device to transport MCTP packets. + + Say y here if you need to connect to MCTP devices over serial. + endmenu endif
drivers/net/mctp/Makefile +1 -0
@@ -0,0 +1 @@ +obj-$(CONFIG_MCTP_SERIAL) += mctp-serial.o
drivers/net/mctp/mctp-serial.c new file +494 -0
494 lines not on this page · raw message
include/uapi/linux/tty.h +1 -0
@@ -38,5 +38,6 @@#define N_NCI 25/* NFC NCI UART */ #define N_SPEAKUP 26/* Speakup communication with synths */ #define N_NULL 27/* Null ldisc used for error handling */ +#define N_MCTP 28/* MCTP-over-serial */ #endif /* _UAPI_LINUX_TTY_H */
Signature · 1 line
2.30.2
Greg Kroah-Hartman
maintainerQuoted 1 line · Jeremy Kerr
This change adds a MCTP Serial transport binding, as per DMTF DSP0253.
What is "DMTF DSP0253"? Can you provide a link to this or more information that explains why this has to be a serial thing?
Quoted 2 lines
This is implemented as a new serial line discipline, and can be attached to arbitrary serial devices.
Why? Who is going to use this?
Quoted 6 lines
The 'mctp' utility provides the ldisc magic to set up the serial link:
# mctp link serial /dev/ttyS0 & # mctp link dev lo index 1 address 0x00:00:00:00:00:00 net 1 mtu 65536 up dev mctpserial0 index 5 address 0x(no-addr) net 1 mtu 68 down
Where is this magic mctp application? I can't find it in my distro packages anywhere.
Quoted 18 lines
Signed-off-by Jeremy Kerr <[email protected]>--- drivers/net/mctp/Kconfig | 11 + drivers/net/mctp/Makefile | 1 + drivers/net/mctp/mctp-serial.c | 494 +++++++++++++++++++++++++++++++++ include/uapi/linux/tty.h | 1 + 4 files changed, 507 insertions(+) create mode 100644 drivers/net/mctp/mctp-serial.cdrivers/net/mctp/Kconfig +0
-0@@ -3,6 +3,17 @@ if MCTP menu "MCTP Device Drivers"
drivers/net/mctp/Kconfig if MCTP · line 15
Quoted 10 lines
drivers/net/mctp/Kconfig +10
-0+config MCTP_SERIAL + tristate "MCTP serial transport" + depends on TTY + select CRC_CCITT + help + This driver provides an MCTP-over-serial interface, through a + serial line-discipline. By attaching the ldisc to a serial device, + we get a new net device to transport MCTP packets. + + Say y here if you need to connect to MCTP devices over serial.
Module name?
Quoted 30 lines
drivers/net/mctp/Kconfig +1
-0+ endmenu endifdrivers/net/mctp/Makefile +1
-0@@ -0,0 +1 @@ +obj-$(CONFIG_MCTP_SERIAL) += mctp-serial.odrivers/net/mctp/mctp-serial.c new file +14
-0@@ -0,0 +1,494 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Management Component Transport Protocol (MCTP) - serial transport +* binding. +* +* Copyright (c) 2021 Code Construct +*/ + +#include <linux/idr.h> +#include <linux/if_arp.h> +#include <linux/module.h> +#include <linux/skbuff.h> +#include <linux/tty.h> +#include <linux/workqueue.h>
drivers/net/mctp/mctp-serial.c line 24
Quoted 10 lines
drivers/net/mctp/mctp-serial.c new file +10
-0+#include <linux/crc-ccitt.h> + +#include <linux/mctp.h> +#include <net/mctp.h> +#include <net/pkt_sched.h> + +#define MCTP_SERIAL_MTU 68/* base mtu (64) + mctp header */ +#define MCTP_SERIAL_FRAME_MTU (MCTP_SERIAL_MTU + 6)/* + serial framing */ + +#define MCTP_SERIAL_VERSION 0x1
Where does this number come from?
drivers/net/mctp/mctp-serial.c line 31
Quoted 7 lines
drivers/net/mctp/mctp-serial.c new file +7
-0+ +#define BUFSIZE MCTP_SERIAL_FRAME_MTU + +#define BYTE_FRAME 0x7e +#define BYTE_ESC 0x7d + +static DEFINE_IDA (mctp_serial_ida);
I think you forgot to clean this up when the module is removed.
thanks,
greg k-h
Jeremy Kerr
maintainerHi Greg,
Thanks for the review, I'll get a v2 done. Some replies inline.
Quoted 5 lines
Quoted 2 lines
This change adds a MCTP Serial transport binding, as per DMTF DSP0253.
What is "DMTF DSP0253"? Can you provide a link to this or more information that explains why this has to be a serial thing?
Sure, can do!
[it doesn't *have* to be a serial thing - MCTP supports multiple physical layers as "transports" - current specs define transports for serial, i2c and PCIe. The choice of transport will be dictated by however you've connected your remote MCTP device(s). In this case though, it's also handy for emulation, where we can transport MCTP packets between virtual machines by connecting VMs' pty channels]
Quoted 10 lines
Quoted 7 lines
The 'mctp' utility provides the ldisc magic to set up the serial link:
# mctp link serial /dev/ttyS0 & # mctp link dev lo index 1 address 0x00:00:00:00:00:00 net 1 mtu 65536 up dev mctpserial0 index 5 address 0x(no-addr) net 1 mtu 68 downWhere is this magic mctp application? I can't find it in my distro packages anywhere.
The MCTP support is pretty new, and possibly a bit eclectic for general distro inclusion at this stage. I'll include a ref to the tools.
Quoted 3 lines
Quoted 1 line
+ Say y here if you need to connect to MCTP devices over serial.
Module name?
Ack.
Quoted 3 lines
Quoted 1 line
+#define MCTP_SERIAL_VERSION 0x1
Where does this number come from?
Defined by the current spec; I'll add a comment.
Quoted 3 lines
Quoted 1 line
+static
DEFINE_IDA(mctp_serial_ida);I think you forgot to clean this up when the module is removed.
Would it be possible to have the module exit called while we still have ida bitmaps still allocated? It looks like a ldisc being open will require a reference on the module; so a module remove will mean we have no ldiscs in use, and therefore an empty ida, so the ida_destroy() will always be a no-op.
Is there a path I'm missing here? Or is this more of a completeness thing?
Cheers,
Jeremy
Greg Kroah-Hartman
maintainerQuoted 9 lines · Jeremy Kerr
Quoted 3 lines
Quoted 1 line
+static
DEFINE_IDA(mctp_serial_ida);I think you forgot to clean this up when the module is removed.
Would it be possible to have the module exit called while we still have ida bitmaps still allocated? It looks like a ldisc being open will require a reference on the module; so a module remove will mean we have no ldiscs in use, and therefore an empty ida, so the
ida_destroy()will always be a no-op.
ida_destroy() will not be a no-op if you have allocated some things in the past. It should always be called when your module is removed.
Or at least that is how it used to be, if this has changed in the past year, then I am mistaken here.
thanks,
greg k-h
Jeremy Kerr
maintainerHi Greg,
Quoted 5 lines
ida_destroy()will not be a no-op if you have allocated some things in the past. It should always be called when your module is removed.Or at least that is how it used to be, if this has changed in the past year, then I am mistaken here.
I was going by this bit of the comment on ida_destroy:
* Calling this function frees all IDs and releases all resources used
* by an IDA. When this call returns, the IDA is empty and can be reused
* or freed. If the IDA is already empty, there is no need to call this
* function.
[From a documentation improvement in 50d97d50715]
Looking at ida_destroy, it's iterating the xarray and freeing all !value entries. ida_free will free a (allocated) value entry once all bits are clear, so the comment looks correct to me - there's nothing left to free if the ida is empty.
However, I'm definitely no ida/idr/xarray expert! Happy to be corrected here - and I'll send a patch to clarify that comment too, if so.
Cheers,
Jeremy
Quoted 7 lines · Jeremy Kerr
Hi Greg,
Quoted 5 lines
ida_destroy()will not be a no-op if you have allocated some things in the past. It should always be called when your module is removed.Or at least that is how it used to be, if this has changed in the past year, then I am mistaken here.
I think Greg is remembering how the IDA behaved before it was converted to use the radix tree back in 2016 (0a835c4f090a). About two-thirds of the users of the IDA and IDR forgot to call ida_destroy/idr_destroy, so rather than fix those places, I decided to make those data structures no longer require a destructor.
Quoted 22 lines
I was going by this bit of the comment on
ida_destroy:* Calling this function frees all IDs and releases all resources used
* by an IDA. When this call returns, the IDA is empty and can be reused
* or freed. If the IDA is already empty, there is no need to call this
* function.[From a documentation improvement in
50d97d50715]Looking at
ida_destroy, it's iterating the xarray and freeing all !value entries.ida_freewill free a (allocated) value entry once all bits are clear, so the comment looks correct to me - there's nothing left to free if the ida is empty.However, I'm definitely no ida/idr/xarray expert! Happy to be corrected here - and I'll send a patch to clarify that comment too, if so.
Cheers,
Jeremy
Greg Kroah-Hartman
maintainerQuoted 6 lines · Matthew Wilcox
Quoted 5 lines · Jeremy Kerr
Hi Greg,
Quoted 3 lines
ida_destroy()will not be a no-op if you have allocated some things in the past. It should always be called when your module is removed.
Quoted 8 lines
Quoted 2 lines
Quoted 2 lines
Or at least that is how it used to be, if this has changed in the past year, then I am mistaken here.
I think Greg is remembering how the IDA behaved before it was converted to use the radix tree back in 2016 (
0a835c4f090a). About two-thirds of the users of the IDA and IDR forgot to call ida_destroy/idr_destroy, so rather than fix those places, I decided to make those data structures no longer require a destructor.
Ah, yes. Glad to see that's no longer needed, sorry for the noise and thanks for correcting me.
greg k-h