Skip to contentSkip to conversation

misc: Add Renesas Synchronization Management Unit (SMU) support

PATCH In review [email protected] 2 participants 14 messages Feb 12, 2021 – Feb 17, 2021 Char and misc drivers

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 misc: Add Renesas Synchronization Management Unit (SMU) support

From: Min Li <[email protected]>

This driver supports 1588 related functions of ClockMatrix(TM) and 82P33xxx families of timing and synchronization devices.

The driver is developed to be only used by Renesas PTP Clock Manager for Linux (pcm4l) software. It supports 1588/PTP releated functionalities that specific to Renesas devices but are not supported by general PHC framework. So pcm4l will use both the existing PHC driver and this module to complete 1588/PTP support. The supported functons are:

-set combomode
-get dpll's state
-get dpll's ffo

This driver must work with Renesas MFD driver to access SMU through I2C/SPI.

Changes since v1:
-Provide more background for purpose of the change. -Provide compat_ioctl support
-Fix ioctl cmd definition

---
 drivers/misc/Kconfig      |  13 ++
 drivers/misc/Makefile     |   3 +
 drivers/misc/rsmu_cdev.c  | 449 ++++++++++++++++++++++++++++++++++++++++++++++
 drivers/misc/rsmu_cdev.h  |  75 ++++++++
 drivers/misc/rsmu_cm.c    | 214 ++++++++++++++++++++++
 drivers/misc/rsmu_sabre.c | 153 ++++++++++++++++
 include/uapi/linux/rsmu.h |  61 +++++++
 7 files changed, 968 insertions(+)
 create mode 100644 drivers/misc/rsmu_cdev.c
 create mode 100644 drivers/misc/rsmu_cdev.h
 create mode 100644 drivers/misc/rsmu_cm.c
 create mode 100644 drivers/misc/rsmu_sabre.c
 create mode 100644 include/uapi/linux/rsmu.h
drivers/misc/Kconfig +13 -0
index fafa8b0..70144f3 100644
@@ -466,6 +466,19 @@ config HISI_HIKEY_USB
 	  switching between the dual-role USB-C port and the USB-A host ports
 	  using only one USB controller.
 
+config RSMU
+	tristate "Renesas Synchronization Management Unit (SMU)"
+	depends on MFD_RSMU_I2C || MFD_RSMU_SPI
+	help
+	  This option enables support for Renesas SMU, such as Clockmatrix and
+	  82P33XXX series. The driver is developed to be only used by Renesas
+	  PTP Clock Manager for Linux (pcm4l) software. It supports 1588/PTP
+	  releated functionalities that specific to Renesas devices but are not
+	  supported by general PHC framework. So pcm4l will use both the
+	  existing PHC driver and this module to complete 1588/PTP support.
+	  This driver must work with Renesas MFD driver to access SMU
+	  through I2C/SPI.
+
 source "drivers/misc/c2port/Kconfig"
 source "drivers/misc/eeprom/Kconfig"
 source "drivers/misc/cb710/Kconfig"
drivers/misc/Makefile +3 -0
index d23231e..3054c0d 100644
@@ -57,3 +57,6 @@ obj-$(CONFIG_HABANA_AI)		+= habanalabs/
 obj-$(CONFIG_UACCE)		+= uacce/
 obj-$(CONFIG_XILINX_SDFEC)	+= xilinx_sdfec.o
 obj-$(CONFIG_HISI_HIKEY_USB)	+= hisi_hikey_usb.o
+
+rsmu-objs			:= rsmu_cdev.o rsmu_cm.o rsmu_sabre.o
+obj-$(CONFIG_RSMU)		+= rsmu.o
drivers/misc/rsmu_cdev.c new file +449 -0

449 lines not on this page · raw message

drivers/misc/rsmu_cdev.h new file +75 -0

75 lines not on this page · raw message

drivers/misc/rsmu_cm.c new file +214 -0

214 lines not on this page · raw message

drivers/misc/rsmu_sabre.c new file +153 -0

153 lines not on this page · raw message

include/uapi/linux/rsmu.h new file +61 -0

61 lines not on this page · raw message

Signature · 1 line
2.7.4
maintainer
#1 lore raw
Quoted 20 lines · On Thu, Feb 11, 2021 at 08:16:15PM -0500, [email protected] wrote:

From: Min Li <[email protected]>

This driver supports 1588 related functions of ClockMatrix(TM) and 82P33xxx families of timing and synchronization devices.

The driver is developed to be only used by Renesas PTP Clock Manager for Linux (pcm4l) software. It supports 1588/PTP releated functionalities that specific to Renesas devices but are not supported by general PHC framework. So pcm4l will use both the existing PHC driver and this module to complete 1588/PTP support. The supported functons are:

(quoted diff) +0 -3
-set combomode
-get dpll's state
-get dpll's ffo

This driver must work with Renesas MFD driver to access SMU through I2C/SPI.

Changes since v1:

Review

Quoted 3 lines
(quoted diff) +0 -3
-Provide more background for purpose of the change.
-Provide compat_ioctl support
-Fix ioctl cmd definition

This "changes" list goes below the --- line.

And you seem to have ignored my review, especially about documenting the sysfs files here, please do that as I can not accept this patch as-is.

greg k-h

author
#2 lore raw
Quoted 8 lines
Quoted 8 lines
(quoted diff) +0 -3
-set combomode
-get dpll's state
-get dpll's ffo

This driver must work with Renesas MFD driver to access SMU through I2C/SPI.

Quoted 7 lines

Review

Quoted 4 lines

Changes since v1:

(quoted diff) +0 -3
-Provide more background for purpose of the change.
-Provide compat_ioctl support
-Fix ioctl cmd definition

This "changes" list goes below the --- line.

Sorry, is this a problem that you are requesting me to address? I am bit confused...

Quoted 3 lines

And you seem to have ignored my review, especially about documenting the sysfs files here, please do that as I can not accept this patch as-is.

If I come up with an rsmu.rst under Documentation/driver-api, is that something you are looking for?

maintainer
#3 lore raw
Quoted 16 lines · Min Li
Quoted 8 lines
Quoted 8 lines
(quoted diff) +0 -3
-set combomode
-get dpll's state
-get dpll's ffo

This driver must work with Renesas MFD driver to access SMU through I2C/SPI.

Quoted 7 lines

Review

Quoted 4 lines

Changes since v1:

(quoted diff) +0 -3
-Provide more background for purpose of the change.
-Provide compat_ioctl support
-Fix ioctl cmd definition

This "changes" list goes below the --- line.

Quoted 1 line

Sorry, is this a problem that you are requesting me to address? I am bit confused...

Yes, please place that list of changes below the --- line in your patch. The documentation says to do this, right?

Quoted 5 lines
Quoted 3 lines

And you seem to have ignored my review, especially about documenting the sysfs files here, please do that as I can not accept this patch as-is.

If I come up with an rsmu.rst under Documentation/driver-api, is that something you are looking for?

No, all sysfs files need to be documented in Documentation/ABI/

thanks,

greg k-h

author
#4 lore raw
Quoted 9 lines
Quoted 2 lines

If I come up with an rsmu.rst under Documentation/driver-api, is that

something you are looking for?

No, all sysfs files need to be documented in Documentation/ABI/

thanks,

greg k-h

Hi Greg

I decided to follow Arnd's suggestion and drop the extra sysfs attributes declaration here.

Any other documents that you are looking for here?

author
#5 lore raw
In reply to Greg KH
Quoted 18 lines · Min Li
Quoted 16 lines
Quoted 15 lines

Review

Quoted 12 lines
(quoted diff) +0 -3
-set combomode
-get dpll's state
-get dpll's ffo

This driver must work with Renesas MFD driver to access SMU through I2C/SPI.

Changes since v1:

(quoted diff) +0 -3
-Provide more background for purpose of the change.
-Provide compat_ioctl support
-Fix ioctl cmd definition

This "changes" list goes below the --- line.

Quoted 6 lines
Quoted 1 line

Sorry, is this a problem that you are requesting me to address? I am bit

confused...

Yes, please place that list of changes below the --- line in your patch. The documentation says to do this, right?

Hi Greg

Do you mean this "---" like below? How can I do that? Sorry I was never asked to do that from other reviewer.

---
 drivers/misc/Kconfig      |  13 ++
 drivers/misc/Makefile     |   3 +
 drivers/misc/rsmu_cdev.c  | 449 ++++++++++++++++++++++++++++++++++++++++++++++
 drivers/misc/rsmu_cdev.h  |  75 ++++++++
 drivers/misc/rsmu_cm.c    | 214 ++++++++++++++++++++++
 drivers/misc/rsmu_sabre.c | 153 ++++++++++++++++
 include/uapi/linux/rsmu.h |  61 +++++++
 7 files changed, 968 insertions(+)
 create mode 100644 drivers/misc/rsmu_cdev.c
 create mode 100644 drivers/misc/rsmu_cdev.h
 create mode 100644 drivers/misc/rsmu_cm.c
 create mode 100644 drivers/misc/rsmu_sabre.c
 create mode 100644 include/uapi/linux/rsmu.h
maintainer
#6 lore raw
Quoted 19 lines · Min Li
Quoted 19 lines · Min Li
Quoted 17 lines
Quoted 8 lines
Quoted 8 lines
(quoted diff) +0 -3
-set combomode
-get dpll's state
-get dpll's ffo

This driver must work with Renesas MFD driver to access SMU through I2C/SPI.

Quoted 7 lines

Review

Quoted 4 lines

Changes since v1:

(quoted diff) +0 -3
-Provide more background for purpose of the change.
-Provide compat_ioctl support
-Fix ioctl cmd definition

This "changes" list goes below the --- line.

Sorry, is this a problem that you are requesting me to address? I am bit

Quoted 8 lines
Quoted 5 lines

confused...

Yes, please place that list of changes below the --- line in your patch. The documentation says to do this, right?

Hi Greg

Do you mean this "---" like below? How can I do that? Sorry I was never asked to do that from other reviewer.

Yes, that line.

The documentation should tell you how to do that, as per my patch bot:

- This looks like a new version of a previously submitted patch, but you did not list below the --- line any changes from the previous version. Please read the section entitled "The canonical patch format" in the kernel file, Documentation/SubmittingPatches for what needs to be done here to properly describe this.

thanks,

greg k-h

author
#7 lore raw
Quoted 11 lines

Yes, that line.

The documentation should tell you how to do that, as per my patch bot:

- This looks like a new version of a previously submitted patch, but you did not list below the --- line any changes from the previous version. Please read the section entitled "The canonical patch format" in the kernel file, Documentation/SubmittingPatches for what needs to be done here to properly describe this.

Quoted 3 lines

thanks,

greg k-h

Hi Greg

I read documentation. Am I supposed to add the "---" marker line manually by myself when doing "git commit --amend"? git commit will always add a "---" marker line before the actual change like below

---
Changes since v1:
-Provide more background for purpose of the change. -Provide compat_ioctl support
-Fix ioctl cmd definition

---
 drivers/misc/Kconfig      |  13 ++
 drivers/misc/Makefile     |   3 +
maintainer
#8 lore raw
Quoted 23 lines · Min Li
Quoted 11 lines

Yes, that line.

The documentation should tell you how to do that, as per my patch bot:

- This looks like a new version of a previously submitted patch, but you did not list below the --- line any changes from the previous version. Please read the section entitled "The canonical patch format" in the kernel file, Documentation/SubmittingPatches for what needs to be done here to properly describe this.

Quoted 3 lines

thanks,

greg k-h

Hi Greg

I read documentation. Am I supposed to add the "---" marker line manually by myself when doing "git commit --amend"? git commit will always add a "---" marker line before the actual change like below

---
Changes since v1:

Review

Quoted 6 lines
(quoted diff) +0 -4
-Provide more background for purpose of the change.
-Provide compat_ioctl support
-Fix ioctl cmd definition
---
 drivers/misc/Kconfig      |  13 ++
 drivers/misc/Makefile     |   3 +

You add the text after you have created the patch with 'git format-patch' by editing the text file before sending it off to us. You don't add it to the changelog comment itself.

hope this helps,

greg k-h

maintainer
#9 lore raw
In reply to [email protected]

drivers/misc/rsmu_cdev.c line 228

Quoted 13 lines · On Thu, Feb 11, 2021 at 08:16:15PM -0500, [email protected] wrote:
drivers/misc/rsmu_cdev.c new file +13 -0
+static int
+rsmu_open(struct inode *iptr, struct file *fptr)
+{
+	struct rsmu_cdev *rsmu;
+
+	rsmu = container_of(iptr->i_cdev, struct rsmu_cdev, rsmu_cdev);
+	if (!rsmu)
+		return -EAGAIN;
+
+	/* Only one open per device at a time */
+	if (!atomic_dec_and_test(&rsmu->open_count)) {
+		atomic_inc(&rsmu->open_count);
+		return -EBUSY;

This does not do what you think it does, and does not prevent multiple applications from talking to your device at the same time.

There is no need for this at all, as it does not work, sorry. If multiple apps talk to your device, it's their fault, not the kernel's fault, that things go wrong.

And I thought that Arnd already told you to fix this?

thanks,

greg k-h

author
#10 lore raw
Quoted 9 lines

drivers/misc/rsmu_cdev.c line 228

Quoted 5 lines
drivers/misc/rsmu_cdev.c new file +5 -0
+
+	/* Only one open per device at a time */
+	if (!atomic_dec_and_test(&rsmu->open_count)) {
+		atomic_inc(&rsmu->open_count);
+		return -EBUSY;

This does not do what you think it does, and does not prevent multiple applications from talking to your device at the same time.

Quoted 6 lines

There is no need for this at all, as it does not work, sorry. If multiple apps talk to your device, it's their fault, not the kernel's fault, that things go wrong.

And I thought that Arnd already told you to fix this?

Hi Greg

Sorry for not replying to the list, I am new so not very familiar with the process.

Can you elaborate why it doesn't work? I kind of borrow the idea from xilinx_sdfec.c and I don't see why it doesn't work.

I mean if an application failed at opening the device, how can it proceed to talk the device without a file descriptor?

Thanks

Min

maintainer
#11 lore raw
Quoted 16 lines · Min Li
Quoted 9 lines

drivers/misc/rsmu_cdev.c line 228

Quoted 5 lines
drivers/misc/rsmu_cdev.c new file +5 -0
+
+	/* Only one open per device at a time */
+	if (!atomic_dec_and_test(&rsmu->open_count)) {
+		atomic_inc(&rsmu->open_count);
+		return -EBUSY;

This does not do what you think it does, and does not prevent multiple applications from talking to your device at the same time.

Quoted 6 lines

There is no need for this at all, as it does not work, sorry. If multiple apps talk to your device, it's their fault, not the kernel's fault, that things go wrong.

And I thought that Arnd already told you to fix this?

Quoted 6 lines

Hi Greg

Sorry for not replying to the list, I am new so not very familiar with the process.

Can you elaborate why it doesn't work? I kind of borrow the idea from xilinx_sdfec.c and I don't see why it doesn't work.

xilinx_sdfec.c has:

	static int xsdfec_dev_open(struct inode *iptr, struct file *fptr)
	{
	        return 0;
	}

Which isn't even needed at all, but it is NOT trying to keep people from calling open multiple times.

As for why the above logic does not work in your driver, think of what happens if someone opens the character device node, and then calls dup(2) on it and passes that file descriptor off to another program. Or just calls it multiple times from different threads in the same program. The kernel does not know what is happening here, and so, "do not allow to be opened multiple times" does not do anything to keep userspace from actually writing to the device node from multiple processes or threads.

So don't even try, it's not worth it.

Quoted 2 lines

I mean if an application failed at opening the device, how can it proceed to talk the device without a file descriptor?

See above for how to do this.

thanks,

greg k-h

author
#12 lore raw
Quoted 21 lines

xilinx_sdfec.c has:

	static int xsdfec_dev_open(struct inode *iptr, struct file *fptr)
	{
	        return 0;
	}

Which isn't even needed at all, but it is NOT trying to keep people from calling open multiple times.

As for why the above logic does not work in your driver, think of what happens if someone opens the character device node, and then calls dup(2) on it and passes that file descriptor off to another program. Or just calls it multiple times from different threads in the same program. The kernel does not know what is happening here, and so, "do not allow to be opened multiple times" does not do anything to keep userspace from actually writing to the device node from multiple processes or threads.

So don't even try, it's not worth it.

Quoted 8 lines
Quoted 2 lines

I mean if an application failed at opening the device, how can it proceed to talk the device without a file descriptor?

See above for how to do this.

thanks,

greg k-h

Hi Greg

Thanks for your insight for this. Now I can see this change doesn't prevent deliberate hacker from opening the driver multiple times.

What I had in mind is that it does prevent some unintentional mistake like some one accidentally opens the application twice. The second one would fail due to the change here.

maintainer
#13 lore raw
Quoted 28 lines · Min Li
Quoted 28 lines

xilinx_sdfec.c has:

	static int xsdfec_dev_open(struct inode *iptr, struct file *fptr)
	{
	        return 0;
	}

Which isn't even needed at all, but it is NOT trying to keep people from calling open multiple times.

As for why the above logic does not work in your driver, think of what happens if someone opens the character device node, and then calls dup(2) on it and passes that file descriptor off to another program. Or just calls it multiple times from different threads in the same program. The kernel does not know what is happening here, and so, "do not allow to be opened multiple times" does not do anything to keep userspace from actually writing to the device node from multiple processes or threads.

So don't even try, it's not worth it.

Quoted 2 lines

I mean if an application failed at opening the device, how can it proceed to talk the device without a file descriptor?

See above for how to do this.

thanks,

Quoted 8 lines
Quoted 1 line

greg k-h

Hi Greg

Thanks for your insight for this. Now I can see this change doesn't prevent deliberate hacker from opening the driver multiple times.

What I had in mind is that it does prevent some unintentional mistake like some one accidentally opens the application twice. The second one would fail due to the change here.

Do not add kernel code that does not work for it's intended purpose :)

thanks,

greg k-h