Skip to contentSkip to conversation

hid: intel-ish-hid: ishtp: add helper function for driver data get/set

PATCH In review Even Xu 4 participants 19 messages Dec 23, 2016 – Jan 5, 2017

Subsystems (3)
lore
Share & tools
lore

Even Xu

author
#0 lore raw

PATCH 1/7 hid: intel-ish-hid: ishtp: add helper function for driver data get/set

Add helper function ishtp_set_drvdata() and ishtp_get_drvdata() for different ISH client drivers to set/get private driver data.

---
 drivers/hid/intel-ish-hid/ishtp/bus.c | 27 +++++++++++++++++++++++++++
 drivers/hid/intel-ish-hid/ishtp/bus.h |  3 +++
 2 files changed, 30 insertions(+)
drivers/hid/intel-ish-hid/ishtp/bus.c +27 -0
index 2565215..40e13f1 100644
@@ -562,6 +562,33 @@ void ishtp_put_device(struct ishtp_cl_device *cl_device)
 EXPORT_SYMBOL(ishtp_put_device);
 
 /**
+ * ishtp_set_drvdata() - set client driver data
+ * @cl_device:	client device instance
+ * @data:	driver data need to be set
+ *
+ * Set client driver data to cl_device->driver_data.
+ */
+void ishtp_set_drvdata(struct ishtp_cl_device *cl_device, void *data)
+{
+	cl_device->driver_data = data;
+}
+EXPORT_SYMBOL(ishtp_set_drvdata);
+
+/**
+ * ishtp_get_drvdata() - get client driver data
+ * @cl_device:	client device instance
+ *
+ * Get client driver data from cl_device->driver_data.
+ *
+ * Return: pointer of driver data
+ */
+void *ishtp_get_drvdata(struct ishtp_cl_device *cl_device)
+{
+	return cl_device->driver_data;
+}
+EXPORT_SYMBOL(ishtp_get_drvdata);
+
+/**
  * ishtp_bus_new_client() - Create a new client
  * @dev:	ISHTP device instance
  *
drivers/hid/intel-ish-hid/ishtp/bus.h +3 -0
index a1ffae7..8888331 100644
@@ -101,6 +101,9 @@ void	ishtp_reset_compl_handler(struct ishtp_device *dev);
 void	ishtp_put_device(struct ishtp_cl_device *);
 void	ishtp_get_device(struct ishtp_cl_device *);
 
+void	ishtp_set_drvdata(struct ishtp_cl_device *cl_device, void *data);
+void	*ishtp_get_drvdata(struct ishtp_cl_device *cl_device);
+
 int	__ishtp_cl_driver_register(struct ishtp_cl_driver *driver,
 				   struct module *owner);
 #define ishtp_cl_driver_register(driver)		\
Signature · 1 line
2.7.4
author
#1 lore raw

PATCH 2/7 hid: intel-ish-hid: use helper function for private driver data set/get

Use helper set/get function to set/get driver data in ishtp-hid-client driver instead of directly accessing cl_device driver_data member.

---
 drivers/hid/intel-ish-hid/ishtp-hid-client.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/hid/intel-ish-hid/ishtp-hid-client.c +7 -7
index 5c643d7a..3a3203d 100644
@@ -321,7 +321,7 @@ static void process_recv(struct ishtp_cl *hid_ishtp_cl, void *recv_buf,
  */
 static void ish_cl_event_cb(struct ishtp_cl_device *device)
 {
-	struct ishtp_cl	*hid_ishtp_cl = device->driver_data;
+	struct ishtp_cl	*hid_ishtp_cl = ishtp_get_drvdata(device);
 	struct ishtp_cl_rb *rb_in_proc;
 	size_t r_length;
 	unsigned long flags;
@@ -770,7 +770,7 @@ static void hid_ishtp_cl_reset_handler(struct work_struct *work)
 	if (!hid_ishtp_cl)
 		return;
 
-	cl_device->driver_data = hid_ishtp_cl;
+	ishtp_set_drvdata(cl_device, hid_ishtp_cl);
 	hid_ishtp_cl->client_data = client_data;
 	client_data->hid_ishtp_cl = hid_ishtp_cl;
 
@@ -819,7 +819,7 @@ static int hid_ishtp_cl_probe(struct ishtp_cl_device *cl_device)
 	if (!hid_ishtp_cl)
 		return -ENOMEM;
 
-	cl_device->driver_data = hid_ishtp_cl;
+	ishtp_set_drvdata(cl_device, hid_ishtp_cl);
 	hid_ishtp_cl->client_data = client_data;
 	client_data->hid_ishtp_cl = hid_ishtp_cl;
 	client_data->cl_device = cl_device;
@@ -849,7 +849,7 @@ static int hid_ishtp_cl_probe(struct ishtp_cl_device *cl_device)
  */
 static int hid_ishtp_cl_remove(struct ishtp_cl_device *cl_device)
 {
-	struct ishtp_cl *hid_ishtp_cl = cl_device->driver_data;
+	struct ishtp_cl *hid_ishtp_cl = ishtp_get_drvdata(cl_device);
 	struct ishtp_cl_data *client_data = hid_ishtp_cl->client_data;
 
 	hid_ishtp_trace(client_data, "%s hid_ishtp_cl %p\n", __func__,
@@ -879,7 +879,7 @@ static int hid_ishtp_cl_remove(struct ishtp_cl_device *cl_device)
  */
 static int hid_ishtp_cl_reset(struct ishtp_cl_device *cl_device)
 {
-	struct ishtp_cl *hid_ishtp_cl = cl_device->driver_data;
+	struct ishtp_cl *hid_ishtp_cl = ishtp_get_drvdata(cl_device);
 	struct ishtp_cl_data *client_data = hid_ishtp_cl->client_data;
 
 	hid_ishtp_trace(client_data, "%s hid_ishtp_cl %p\n", __func__,
@@ -903,7 +903,7 @@ static int hid_ishtp_cl_reset(struct ishtp_cl_device *cl_device)
 static int hid_ishtp_cl_suspend(struct device *device)
 {
 	struct ishtp_cl_device *cl_device = to_ishtp_cl_device(device);
-	struct ishtp_cl *hid_ishtp_cl = cl_device->driver_data;
+	struct ishtp_cl *hid_ishtp_cl = ishtp_get_drvdata(cl_device);
 	struct ishtp_cl_data *client_data = hid_ishtp_cl->client_data;
 
 	hid_ishtp_trace(client_data, "%s hid_ishtp_cl %p\n", __func__,
@@ -924,7 +924,7 @@ static int hid_ishtp_cl_suspend(struct device *device)
 static int hid_ishtp_cl_resume(struct device *device)
 {
 	struct ishtp_cl_device *cl_device = to_ishtp_cl_device(device);
-	struct ishtp_cl *hid_ishtp_cl = cl_device->driver_data;
+	struct ishtp_cl *hid_ishtp_cl = ishtp_get_drvdata(cl_device);
 	struct ishtp_cl_data *client_data = hid_ishtp_cl->client_data;
 
 	hid_ishtp_trace(client_data, "%s hid_ishtp_cl %p\n", __func__,
Signature · 1 line
2.7.4
author
#2 lore raw

PATCH 3/7 hid: intel-ish-hid: ishtp: add helper functions for client buffer operation

In reply to Even Xu

Add helper ishtp_cl_tx_empty() and ishtp_cl_rx_get_rb() to hide internal details from callers, who needs this functionality.

---
 drivers/hid/intel-ish-hid/ishtp/client-buffers.c | 45 ++++++++++++++++++++++++
 drivers/hid/intel-ish-hid/ishtp/client.h         |  2 ++
 2 files changed, 47 insertions(+)
drivers/hid/intel-ish-hid/ishtp/client-buffers.c +45 -0
index b9b917d..12d6130 100644
@@ -255,3 +255,48 @@ int ishtp_cl_io_rb_recycle(struct ishtp_cl_rb *rb)
 	return	rets;
 }
 EXPORT_SYMBOL(ishtp_cl_io_rb_recycle);
+
+/**
+ * ishtp_cl_tx_empty() -test whether client device tx buffer is empty
+ * @cl: Pointer to client device instance
+ *
+ * Look client device tx buffer list, and check whether this list is empty
+ *
+ * Return: true if client tx buffer list is empty else false
+ */
+bool ishtp_cl_tx_empty(struct ishtp_cl *cl)
+{
+	int tx_list_empty;
+	unsigned long tx_flags;
+
+	spin_lock_irqsave(&cl->tx_list_spinlock, tx_flags);
+	tx_list_empty = list_empty(&cl->tx_list.list);
+	spin_unlock_irqrestore(&cl->tx_list_spinlock, tx_flags);
+
+	return !!tx_list_empty;
+}
+EXPORT_SYMBOL(ishtp_cl_tx_empty);
+
+/**
+ * ishtp_cl_rx_get_rb() -Get a rb from client device rx buffer list
+ * @cl: Pointer to client device instance
+ *
+ * Check client device in-processing buffer list and get a rb from it.
+ *
+ * Return: rb pointer if buffer list isn't empty else NULL
+ */
+struct ishtp_cl_rb *ishtp_cl_rx_get_rb(struct ishtp_cl *cl)
+{
+	unsigned long rx_flags;
+	struct ishtp_cl_rb *rb;
+
+	spin_lock_irqsave(&cl->in_process_spinlock, rx_flags);
+	rb = list_first_entry_or_null(&cl->in_process_list.list,
+				struct ishtp_cl_rb, list);
+	if (rb)
+		list_del_init(&rb->list);
+	spin_unlock_irqrestore(&cl->in_process_spinlock, rx_flags);
+
+	return rb;
+}
+EXPORT_SYMBOL(ishtp_cl_rx_get_rb);
drivers/hid/intel-ish-hid/ishtp/client.h +2 -0
index 444d069..8ab2833 100644
@@ -178,5 +178,7 @@ int ishtp_cl_flush_queues(struct ishtp_cl *cl);
 
 /* exported functions from ISHTP client buffer management scope */
 int ishtp_cl_io_rb_recycle(struct ishtp_cl_rb *rb);
+bool ishtp_cl_tx_empty(struct ishtp_cl *cl);
+struct ishtp_cl_rb *ishtp_cl_rx_get_rb(struct ishtp_cl *cl);
 
 #endif /* _ISHTP_CLIENT_H_ */
Signature · 1 line
2.7.4
author
#3 lore raw

PATCH 4/7 hid: intel-ish-hid: use helper function to access client buffer

In reply to Even Xu

ishtp bus driver exposed helper functions for client buffer accessing, so change to use these functions in ishtp-hid-client driver to avoid access client buffer directly.

---
 drivers/hid/intel-ish-hid/ishtp-hid-client.c | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)
drivers/hid/intel-ish-hid/ishtp-hid-client.c +1 -12
index 3a3203d..0a7270c 100644
@@ -324,20 +324,11 @@ static void ish_cl_event_cb(struct ishtp_cl_device *device)
 	struct ishtp_cl	*hid_ishtp_cl = ishtp_get_drvdata(device);
 	struct ishtp_cl_rb *rb_in_proc;
 	size_t r_length;
-	unsigned long flags;
 
 	if (!hid_ishtp_cl)
 		return;
 
-	spin_lock_irqsave(&hid_ishtp_cl->in_process_spinlock, flags);
-	while (!list_empty(&hid_ishtp_cl->in_process_list.list)) {
-		rb_in_proc = list_entry(
-			hid_ishtp_cl->in_process_list.list.next,
-			struct ishtp_cl_rb, list);
-		list_del_init(&rb_in_proc->list);
-		spin_unlock_irqrestore(&hid_ishtp_cl->in_process_spinlock,
-			flags);
-
+	while ((rb_in_proc = ishtp_cl_rx_get_rb(hid_ishtp_cl)) != NULL) {
 		if (!rb_in_proc->buffer.data)
 			return;
 
@@ -347,9 +338,7 @@ static void ish_cl_event_cb(struct ishtp_cl_device *device)
 		process_recv(hid_ishtp_cl, rb_in_proc->buffer.data, r_length);
 
 		ishtp_cl_io_rb_recycle(rb_in_proc);
-		spin_lock_irqsave(&hid_ishtp_cl->in_process_spinlock, flags);
 	}
-	spin_unlock_irqrestore(&hid_ishtp_cl->in_process_spinlock, flags);
 }
 
 /**
Signature · 1 line
2.7.4
author
#4 lore raw

PATCH 5/7 hid: intel-ish-hid: ishtp: add helper function for client search

In reply to Even Xu

Add helper function ishtp_fw_cl_get_client() for client driver searching client information to hide internal details from callers.

---
 drivers/hid/intel-ish-hid/ishtp/bus.c | 25 +++++++++++++++++++++++++
 drivers/hid/intel-ish-hid/ishtp/bus.h |  2 ++
 2 files changed, 27 insertions(+)
drivers/hid/intel-ish-hid/ishtp/bus.c +25 -0
index 40e13f1..f07af7a 100644
@@ -149,6 +149,31 @@ int ishtp_fw_cl_by_uuid(struct ishtp_device *dev, const uuid_le *uuid)
 EXPORT_SYMBOL(ishtp_fw_cl_by_uuid);
 
 /**
+ * ishtp_fw_cl_get_client() - return client information to client
+ * @dev: the ishtp device structure
+ * @uuid: uuid of the client to search
+ *
+ * Search firmware client using UUID and reture related client information.
+ *
+ * Return: pointer of client information on success, NULL on failure.
+ */
+struct ishtp_fw_client *ishtp_fw_cl_get_client(struct ishtp_device *dev,
+						const uuid_le *uuid)
+{
+	int i;
+	unsigned long flags;
+
+	spin_lock_irqsave(&dev->fw_clients_lock, flags);
+	i = ishtp_fw_cl_by_uuid(dev, uuid);
+	spin_unlock_irqrestore(&dev->fw_clients_lock, flags);
+	if (i < 0 || dev->fw_clients[i].props.fixed_address)
+		return NULL;
+
+	return &dev->fw_clients[i];
+}
+EXPORT_SYMBOL(ishtp_fw_cl_get_client);
+
+/**
  * ishtp_fw_cl_by_id() - return index to fw_clients for client_id
  * @dev: the ishtp device structure
  * @client_id: fw client id to search
drivers/hid/intel-ish-hid/ishtp/bus.h +2 -0
index 8888331..b8a5bcc 100644
@@ -113,5 +113,7 @@ void	ishtp_cl_driver_unregister(struct ishtp_cl_driver *driver);
 int	ishtp_register_event_cb(struct ishtp_cl_device *device,
 				void (*read_cb)(struct ishtp_cl_device *));
 int	ishtp_fw_cl_by_uuid(struct ishtp_device *dev, const uuid_le *cuuid);
+struct	ishtp_fw_client *ishtp_fw_cl_get_client(struct ishtp_device *dev,
+						const uuid_le *uuid);
 
 #endif /* _LINUX_ISHTP_CL_BUS_H */
Signature · 1 line
2.7.4
author
#5 lore raw

PATCH 6/7 hid: intel-ish-hid: use helper function to search client id

In reply to Even Xu

ishtp exposed helper ishtp_fw_cl_get_client() function for client information searching, so switch to use it.

---
 drivers/hid/intel-ish-hid/ishtp-hid-client.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
drivers/hid/intel-ish-hid/ishtp-hid-client.c +6 -8
index 0a7270c..34847ed 100644
@@ -631,8 +631,8 @@ static int ishtp_get_report_descriptor(struct ishtp_cl *hid_ishtp_cl,
 static int hid_ishtp_cl_init(struct ishtp_cl *hid_ishtp_cl, int reset)
 {
 	struct ishtp_device *dev;
-	unsigned long flags;
 	struct ishtp_cl_data *client_data = hid_ishtp_cl->client_data;
+	struct ishtp_fw_client *fw_client;
 	int i;
 	int rv;
 
@@ -654,16 +654,14 @@ static int hid_ishtp_cl_init(struct ishtp_cl *hid_ishtp_cl, int reset)
 	hid_ishtp_cl->rx_ring_size = HID_CL_RX_RING_SIZE;
 	hid_ishtp_cl->tx_ring_size = HID_CL_TX_RING_SIZE;
 
-	spin_lock_irqsave(&dev->fw_clients_lock, flags);
-	i = ishtp_fw_cl_by_uuid(dev, &hid_ishtp_guid);
-	if (i < 0) {
-		spin_unlock_irqrestore(&dev->fw_clients_lock, flags);
+	fw_client = ishtp_fw_cl_get_client(dev, &hid_ishtp_guid);
+	if (!fw_client) {
 		dev_err(&client_data->cl_device->dev,
 			"ish client uuid not found\n");
-		return i;
+		return -ENOENT;
 	}
-	hid_ishtp_cl->fw_client_id = dev->fw_clients[i].client_id;
-	spin_unlock_irqrestore(&dev->fw_clients_lock, flags);
+
+	hid_ishtp_cl->fw_client_id = fw_client->client_id;
 	hid_ishtp_cl->state = ISHTP_CL_CONNECTING;
 
 	rv = ishtp_cl_connect(hid_ishtp_cl);
Signature · 1 line
2.7.4
author
#6 lore raw

PATCH 7/7 misc: intel-ish-client: add intel ishtp clients driver

In reply to Even Xu

Intel ISHFW supports many different clients, in hid/intel-ish-hid/ishtp bus driver, it creates following client devices:
HID client:
interface of sensor configure and sensor event report.
SMHI client:
interface of sensor calibration, ISHFW debug, ISHFW performance analysis and manufacture support.
Trace client:
interface of ISHFW debug log output.
Trace configure client:
interface of ISHFW debug log configuration, such as output port, log level, filter.
ISHFW loader client:
interface of customized ISHFW loader.
HID client has been handle by hid/intel-ish-hid/intel-ishtp-hid client driver, and rest of the clients export interface using miscellaneous drivers. This interface is used by user space tools for debugging and calibration of sensors.

---
 drivers/misc/Kconfig                               |   1 +
 drivers/misc/Makefile                              |   1 +
 drivers/misc/intel-ish-client/Kconfig              |  15 +
 drivers/misc/intel-ish-client/Makefile             |   8 +
 .../misc/intel-ish-client/intel-ishtp-clients.c    | 884 +++++++++++++++++++++
 include/uapi/linux/intel-ishtp-clients.h           |  73 ++
 6 files changed, 982 insertions(+)
 create mode 100644 drivers/misc/intel-ish-client/Kconfig
 create mode 100644 drivers/misc/intel-ish-client/Makefile
 create mode 100644 drivers/misc/intel-ish-client/intel-ishtp-clients.c
 create mode 100644 include/uapi/linux/intel-ishtp-clients.h
drivers/misc/Kconfig +1 -0
index 64971ba..a89849f 100644
@@ -778,4 +778,5 @@ source "drivers/misc/mic/Kconfig"
 source "drivers/misc/genwqe/Kconfig"
 source "drivers/misc/echo/Kconfig"
 source "drivers/misc/cxl/Kconfig"
+source "drivers/misc/intel-ish-client/Kconfig"
 endmenu
drivers/misc/Makefile +1 -0
index 3198336..c54015d 100644
@@ -53,6 +53,7 @@ obj-$(CONFIG_ECHO)		+= echo/
 obj-$(CONFIG_VEXPRESS_SYSCFG)	+= vexpress-syscfg.o
 obj-$(CONFIG_CXL_BASE)		+= cxl/
 obj-$(CONFIG_PANEL)             += panel.o
+obj-$(CONFIG_INTEL_ISH_CLIENT)	+= intel-ish-client/
 
 lkdtm-$(CONFIG_LKDTM)		+= lkdtm_core.o
 lkdtm-$(CONFIG_LKDTM)		+= lkdtm_bugs.o
drivers/misc/intel-ish-client/Kconfig new file +15 -0
new file mode 100644
index 0000000..6fa9cc0
@@ -0,0 +1,15 @@
+menu "Intel ISH Client support"
+	depends on INTEL_ISH_HID
+
+config INTEL_ISH_CLIENT
+	tristate "Intel Integrated Sensor Hub Client"
+	help
+	  The Integrated Sensor Hub (ISH) supports many clients, Intel ISH client
+	  driver supports following clients:
+	  SMHI client: calibration & perfermance & menufacture tool interface
+	  trace configure client: ISHFW trace parameter configure interface
+	  trace tool client: ISHFW trace log output interface
+	  loader client: loading customized ISHFW interface
+
+	  Say Y here if you want to support Intel ISH clients. If unsure, say N.
+endmenu
drivers/misc/intel-ish-client/Makefile new file +8 -0
new file mode 100644
index 0000000..29a5461
@@ -0,0 +1,8 @@
+#
+# Makefile - Intel ISH client driver
+# Copyright (c) 2014-2016, Intel Corporation.
+#
+#
+obj-$(CONFIG_INTEL_ISH_CLIENT) += intel-ishtp-clients.o
+
+ccflags-y += -I$(srctree)/drivers/hid/intel-ish-hid/ishtp
drivers/misc/intel-ish-client/intel-ishtp-clients.c new file +884 -0

884 lines not on this page · raw message

include/uapi/linux/intel-ishtp-clients.h new file +73 -0

73 lines not on this page · raw message

Signature · 1 line
2.7.4
maintainer
#7 lore raw

Re: [PATCH 7/7] misc: intel-ish-client: add intel ishtp clients driver

On Fri, 23 Dec 2016, Even Xu wrote:

[ ... snip ... ]

drivers/misc/intel-ish-client/intel-ishtp-clients.c line 330

Quoted 13 lines
drivers/misc/intel-ish-client/intel-ishtp-clients.c new file +13 -0
+static ssize_t ishtp_cl_write(struct file *file, const char __user *ubuf,
+	size_t length, loff_t *offset)
+{
+	struct ishtp_cl_miscdev *ishtp_cl_misc = file->private_data;
+	struct ishtp_cl *cl;
+	void *write_buf;
+	struct ishtp_device *dev;
+	int ret;
+
+	/* Non-blocking semantics are not supported */
+	if (file->f_flags & O_NONBLOCK) {
+		ret = -EINVAL;
+		goto out_unlock;

When taking the error path here you'd try to unlock ishtp_cl_misc->cl_mutex before actually acquiring it.

Signature · 2 lines
Jiri Kosina
SUSE Labs
author Reviewed-by Andriy Shevchenko Reviewed-by Srinivas Pandruvada
#8 lore raw

Re: [PATCH 7/7] misc: intel-ish-client: add intel ishtp clients driver

Quoted 10 lines · Jiri Kosina

On Fri, 23 Dec 2016, Even Xu wrote:

[ ... snip ... ]

Quoted 7 lines

+static ssize_t ishtp_cl_write(struct file *file, const char __user *ubuf,

(quoted diff) +3 -0
+	size_t length, loff_t *offset)
+{
+	struct ishtp_cl_miscdev *ishtp_cl_misc = file-
Quoted 1 line

private_data;

Quoted 12 lines

Review

Quoted 9 lines
(quoted diff) +9 -0
+	struct ishtp_cl *cl;
+	void *write_buf;
+	struct ishtp_device *dev;
+	int ret;
+
+	/* Non-blocking semantics are not supported */
+	if (file->f_flags & O_NONBLOCK) {
+		ret = -EINVAL;
+		goto out_unlock;

When taking the error path here you'd try to unlock ishtp_cl_misc->cl_mutex before actually acquiring it.

Thanks for your comments, Jiri, I update my patch below:
===============================================================

Intel ISHFW supports many different clients, in hid/intel-ish-hid/ishtp bus driver, it creates following client devices:
HID client:
interface of sensor configure and sensor event report.
SMHI client:
interface of sensor calibration, ISHFW debug, ISHFW performance analysis and manufacture support.
Trace client:
interface of ISHFW debug log output.
Trace configure client:
interface of ISHFW debug log configuration, such as output port, log level, filter.
ISHFW loader client:
interface of customized ISHFW loader.
HID client has been handle by hid/intel-ish-hid/intel-ishtp-hid client driver, and rest of the clients export interface using miscellaneous drivers. This interface is used by user space tools for debugging and calibration of sensors.

---
 drivers/misc/Kconfig                               |   1 + drivers/misc/Makefile                              |   1 + drivers/misc/intel-ish-client/Kconfig              |  15 + drivers/misc/intel-ish-client/Makefile             |   8 + .../misc/intel-ish-client/intel-ishtp-clients.c    | 882 +++++++++++++++++++++ include/uapi/linux/intel-ishtp-clients.h           |  73 ++

 6 files changed, 980 insertions(+)

 create mode 100644 drivers/misc/intel-ish-client/Kconfig create mode 100644 drivers/misc/intel-ish-client/Makefile create mode 100644 drivers/misc/intel-ish-client/intel-ishtp-clients.c create mode 100644 include/uapi/linux/intel-ishtp-clients.h

drivers/misc/Kconfig +0 -0
index 64971ba..a89849f 100644
@@ -778,4 +778,5 @@ source "drivers/misc/mic/Kconfig"

 source "drivers/misc/genwqe/Kconfig"
 source "drivers/misc/echo/Kconfig"
 source "drivers/misc/cxl/Kconfig"
+source "drivers/misc/intel-ish-client/Kconfig"
 endmenu

drivers/misc/Makefile +0 -0
index 3198336..c54015d 100644

--- a/drivers/misc/Makefile

+++ b/drivers/misc/Makefile
@@ -53,6 +53,7 @@ obj-$(CONFIG_ECHO) += echo/
 obj-$(CONFIG_VEXPRESS_SYSCFG) += vexpress-syscfg.o
 obj-$(CONFIG_CXL_BASE) += cxl/
 obj-$(CONFIG_PANEL)             += panel.o
+obj-$(CONFIG_INTEL_ISH_CLIENT) += intel-ish-client/

 lkdtm-$(CONFIG_LKDTM) += lkdtm_core.o
 lkdtm-$(CONFIG_LKDTM) += lkdtm_bugs.o

drivers/misc/intel-ish-client/Kconfig new file +15 -0
new file mode 100644
index 0000000..6fa9cc0
@@ -0,0 +1,15 @@
+menu "Intel ISH Client support"
+	depends on INTEL_ISH_HID
+
+config INTEL_ISH_CLIENT
+	tristate "Intel Integrated Sensor Hub Client"
+	help
+	  The Integrated Sensor Hub (ISH) supports many clients, Intel ISH client
+	  driver supports following clients:
+	  SMHI client: calibration & perfermance & menufacture tool interface
+	  trace configure client: ISHFW trace parameter configure interface
+	  trace tool client: ISHFW trace log output interface
+	  loader client: loading customized ISHFW interface
+
+	  Say Y here if you want to support Intel ISH clients. If unsure, say N.
+endmenu
drivers/misc/intel-ish-client/Makefile new file +8 -0
new file mode 100644
index 0000000..29a5461
@@ -0,0 +1,8 @@
+#
+# Makefile - Intel ISH client driver
+# Copyright (c) 2014-2016, Intel Corporation.
+#
+#
+obj-$(CONFIG_INTEL_ISH_CLIENT) += intel-ishtp-clients.o
+
+ccflags-y += -I$(srctree)/drivers/hid/intel-ish-hid/ishtp
drivers/misc/intel-ish-client/intel-ishtp-clients.c new file +882 -0

882 lines not on this page · raw message

include/uapi/linux/intel-ishtp-clients.h new file +73 -0

73 lines not on this page · raw message

--
2.7.4

maintainer
#9 lore raw

Re: [PATCH 7/7] misc: intel-ish-client: add intel ishtp clients driver

Quoted 21 lines · Even
Quoted 8 lines

[ ... snip ... ]

Quoted 7 lines

+static ssize_t ishtp_cl_write(struct file *file, const char __user *ubuf,

drivers/misc/intel-ish-client/intel-ishtp-clients.c new file +3 -0
+	size_t length, loff_t *offset)
+{
+	struct ishtp_cl_miscdev *ishtp_cl_misc = file-
Quoted 1 line

private_data;

Quoted 12 lines

drivers/misc/intel-ish-client/intel-ishtp-clients.c line 341

Quoted 9 lines
drivers/misc/intel-ish-client/intel-ishtp-clients.c new file +9 -0
+	struct ishtp_cl *cl;
+	void *write_buf;
+	struct ishtp_device *dev;
+	int ret;
+
+	/* Non-blocking semantics are not supported */
+	if (file->f_flags & O_NONBLOCK) {
+		ret = -EINVAL;
+		goto out_unlock;

When taking the error path here you'd try to unlock ishtp_cl_misc->cl_mutex before actually acquiring it.

Quoted 1 line

Thanks for your comments, Jiri, I update my patch below:

Greg, how would you like to handle this (after you're done with reviewing it of course), given that this driver depends on the preceeding 6 patches to intel-ish-hid driver?

Thanks,

Signature · 2 lines
Jiri Kosina
SUSE Labs
#10 lore raw

Re: [PATCH 7/7] misc: intel-ish-client: add intel ishtp clients driver

Quoted 23 lines · Jiri Kosina
Quoted 21 lines · Even
Quoted 20 lines

[ ... snip ... ]

Quoted 7 lines

+static ssize_t ishtp_cl_write(struct file *file, const char __user *ubuf,

drivers/misc/intel-ish-client/intel-ishtp-clients.c new file +3 -0
+	size_t length, loff_t *offset)
+{
+	struct ishtp_cl_miscdev *ishtp_cl_misc = file-
Quoted 1 line

private_data;

drivers/misc/intel-ish-client/intel-ishtp-clients.c line 341

Quoted 9 lines
drivers/misc/intel-ish-client/intel-ishtp-clients.c new file +9 -0
+	struct ishtp_cl *cl;
+	void *write_buf;
+	struct ishtp_device *dev;
+	int ret;
+
+	/* Non-blocking semantics are not supported */
+	if (file->f_flags & O_NONBLOCK) {
+		ret = -EINVAL;
+		goto out_unlock;

When taking the error path here you'd try to unlock ishtp_cl_misc->cl_mutex before actually acquiring it.

Quoted 5 lines
Quoted 1 line

Thanks for your comments, Jiri, I update my patch below:

Greg, how would you like to handle this (after you're done with reviewing it of course), given that this driver depends on the preceeding 6 patches to intel-ish-hid driver?

Let me go review it now, but if it's ok, I have no problem taking it in my tree, or if you want to take it through yours, that's fine with me, which ever is easiest for you.

thanks,

greg k-h

maintainer
#11 lore raw

Re: [PATCH 7/7] misc: intel-ish-client: add intel ishtp clients driver

In reply to Even Xu
Quoted 22 lines · Even Xu

Intel ISHFW supports many different clients, in hid/intel-ish-hid/ishtp bus driver, it creates following client devices:
HID client:
interface of sensor configure and sensor event report.
SMHI client:
interface of sensor calibration, ISHFW debug, ISHFW performance analysis and manufacture support.
Trace client:
interface of ISHFW debug log output.
Trace configure client:
interface of ISHFW debug log configuration, such as output port, log level, filter.
ISHFW loader client:
interface of customized ISHFW loader.
HID client has been handle by hid/intel-ish-hid/intel-ishtp-hid client driver, and rest of the clients export interface using miscellaneous drivers. This interface is used by user space tools for debugging and calibration of sensors.

Quoted 7 lines
---
 drivers/misc/Kconfig                               |   1 +
 drivers/misc/Makefile                              |   1 +
 drivers/misc/intel-ish-client/Kconfig              |  15 +
 drivers/misc/intel-ish-client/Makefile             |   8 +
 .../misc/intel-ish-client/intel-ishtp-clients.c    | 884 +++++++++++++++++++++
 include/uapi/linux/intel-ishtp-clients.h           |  73 ++

Why create a whole new subdirectory for just one .c file? Is that really needed?

And I'm not quite sure why you need a misc driver, what exactly is this code doing?

Let me look at your uapi header file:

Quoted 25 lines
include/uapi/linux/intel-ishtp-clients.h new file +22 -0
@@ -0,0 +1,73 @@
+/*
+ * Intel ISHTP Clients Interface Header
+ *
+ * Copyright (c) 2016, Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ */
+
+#ifndef _INTEL_ISHTP_CLIENTS_H
+#define _INTEL_ISHTP_CLIENTS_H
+
+#include <linux/ioctl.h>
+#include <linux/miscdevice.h>
+#include <linux/mutex.h>

include/uapi/linux/intel-ishtp-clients.h line 32

Quoted 10 lines
include/uapi/linux/intel-ishtp-clients.h new file +10 -0
+#include <linux/types.h>
+#include <linux/uuid.h>
+
+/*
+ * This IOCTL is used to associate the current file descriptor with a
+ * FW Client (given by UUID). This opens a communication channel
+ * between a host client and a FW client. From this point every read and write
+ * will communicate with the associated FW client.
+ * Only in close() (file_operation release()) the communication between
+ * the clients is disconnected

Why do you want to do this? What will read/write do with this device now?

include/uapi/linux/intel-ishtp-clients.h line 35

Quoted 3 lines
include/uapi/linux/intel-ishtp-clients.h new file +3 -0
+ *
+ * The IOCTL argument is a struct with a union that contains
+ * the input parameter and the output parameter for this IOCTL.

Is that sentance really needed?

include/uapi/linux/intel-ishtp-clients.h line 47

Quoted 12 lines
include/uapi/linux/intel-ishtp-clients.h new file +12 -0
+ *
+ * The input parameter is UUID of the FW Client.
+ * The output parameter is the properties of the FW client
+ * (FW protocol version and max message size).
+ *
+ */
+#define IOCTL_ISHTP_CONNECT_CLIENT	_IOWR('H', 0x81,	\
+				struct ishtp_connect_client_data)
+
+/* Configuration: set number of Rx/Tx buffers. Must be used before connection */
+#define IOCTL_ISHTP_SET_RX_FIFO_SIZE	_IOWR('H', 0x82, long)
+#define IOCTL_ISHTP_SET_TX_FIFO_SIZE	_IOWR('H', 0x83, long)

Before connection to what?

include/uapi/linux/intel-ishtp-clients.h line 50

Quoted 3 lines
include/uapi/linux/intel-ishtp-clients.h new file +3 -0
+
+/* Get FW status */
+#define IOCTL_ISH_GET_FW_STATUS	_IO('H', 0x84)

What is this?

include/uapi/linux/intel-ishtp-clients.h line 52

Quoted 2 lines
include/uapi/linux/intel-ishtp-clients.h new file +2 -0
+
+#define IOCTL_ISH_HW_RESET	_IO('H', 0x85)

No documentation?

include/uapi/linux/intel-ishtp-clients.h line 62

Quoted 10 lines
include/uapi/linux/intel-ishtp-clients.h new file +10 -0
+
+/*
+ * Intel ISHTP client information struct
+ */
+struct ishtp_client {
+	__u32 max_msg_length;
+	__u8 protocol_version;
+	__u8 reserved[3];
+};
+

Nice job using the correct types.

I still don't know what this api does, let me go look at the .c code now...

thanks,

greg k-h

#12 lore raw

Re: [PATCH 7/7] misc: intel-ish-client: add intel ishtp clients driver

Quoted 40 lines · Greg KH
Quoted 28 lines · Even Xu

Intel ISHFW supports many different clients, in hid/intel-ish-hid/ishtp bus driver, it creates following client devices:
HID client:
interface of sensor configure and sensor event report.
SMHI client:
interface of sensor calibration, ISHFW debug, ISHFW performance analysis and manufacture support.
Trace client:
interface of ISHFW debug log output.
Trace configure client:
interface of ISHFW debug log configuration, such as output
port,
log level, filter.
ISHFW loader client:
interface of customized ISHFW loader.
HID client has been handle by hid/intel-ish-hid/intel-ishtp-hid client
driver, and rest of the clients export interface using miscellaneous
drivers. This interface is used by user space tools for debugging and
calibration of sensors.

Quoted 9 lines

om>
---
 drivers/misc/Kconfig                               |   1 + drivers/misc/Makefile                              |   1 + drivers/misc/intel-ish-client/Kconfig              |  15 + drivers/misc/intel-ish-client/Makefile             |   8 + .../misc/intel-ish-client/intel-ishtp-clients.c    | 884
+++++++++++++++++++++
 include/uapi/linux/intel-ishtp-clients.h           |  73 ++

Quoted 2 lines

Why create a whole new subdirectory for just one .c file?  Is that really needed?

The other option is to move this .c file to drivers/hid/intel-ish-hid/. I think the folders inside drivers/hid/ is mostly for just implementing transport layer for hid devices.

Quoted 4 lines

And I'm not quite sure why you need a misc driver, what exactly is this
code doing?

As described in the description, this driver is a companion driver for ISH user space tools for calibration, production and debug.

Basically the ISH provided a standalone low power processor to developers and manufacturers  to do download some custom algorithms for sensors, which may not be compliant to USB HID sensor specifications (mostly for IOT space). In that case the user space for those can communicate using misc driver interface, without adding new kernel drivers.

Thanks,
Srinivas

maintainer
#13 lore raw

Re: [PATCH 7/7] misc: intel-ish-client: add intel ishtp clients driver

Quoted 49 lines · Srinivas Pandruvada
Quoted 40 lines · Greg KH
Quoted 28 lines · Even Xu

Intel ISHFW supports many different clients, in hid/intel-ish-hid/ishtp bus driver, it creates following client devices:
HID client:
interface of sensor configure and sensor event report.
SMHI client:
interface of sensor calibration, ISHFW debug, ISHFW performance analysis and manufacture support.
Trace client:
interface of ISHFW debug log output.
Trace configure client:
interface of ISHFW debug log configuration, such as output
port,
log level, filter.
ISHFW loader client:
interface of customized ISHFW loader.
HID client has been handle by hid/intel-ish-hid/intel-ishtp-hid client
driver, and rest of the clients export interface using miscellaneous
drivers. This interface is used by user space tools for debugging and
calibration of sensors.

Quoted 9 lines

om>
---
 drivers/misc/Kconfig                               |   1 + drivers/misc/Makefile                              |   1 + drivers/misc/intel-ish-client/Kconfig              |  15 + drivers/misc/intel-ish-client/Makefile             |   8 + .../misc/intel-ish-client/intel-ishtp-clients.c    | 884
+++++++++++++++++++++
 include/uapi/linux/intel-ishtp-clients.h           |  73 ++

Quoted 2 lines

Why create a whole new subdirectory for just one .c file?  Is that really needed?

The other option is to move this .c file to drivers/hid/intel-ish-hid/. I think the folders inside drivers/hid/ is mostly for just implementing transport layer for hid devices.

Quoted 1 line
Quoted 5 lines
Quoted 3 lines

And I'm not quite sure why you need a misc driver, what exactly is this
code doing?

As described in the description, this driver is a companion driver for ISH user space tools for calibration, production and debug.

debug should not require a char device node, use debugfs, that is what it is there for.

For "calibration", why not use configfs or even sysfs?

Quoted 6 lines

Basically the ISH provided a standalone low power processor to developers and manufacturers  to do download some custom algorithms for sensors, which may not be compliant to USB HID sensor specifications (mostly for IOT space). In that case the user space for those can communicate using misc driver interface, without adding new kernel drivers.

So you hide it behind a char device node? That's not very descriptive or easy to understand :)

Again, use the interfaces that the kernel gives you for this type of stuff, and don't create new one-off ones if at all possible.

thanks,

greg k-h

#14 lore raw

Re: [PATCH 7/7] misc: intel-ish-client: add intel ishtp clients driver

Quoted 6 lines · Greg KH
Quoted 5 lines · Srinivas Pandruvada
Quoted 3 lines · Greg KH

On Fri, Dec 23, 2016 at 09:22:29AM +0800, Even Xu wrote

Quoted 1 line

[...]

Quoted 5 lines

debug should not require a char device node, use debugfs, that is what
it is there for.

For "calibration", why not use configfs or even sysfs?

We will check on this. There is some legacy with the deployed user space tools.

Quoted 10 lines
Quoted 9 lines

Basically the ISH provided a standalone low power processor to developers and manufacturers  to do download some custom algorithms for
sensors, which may not be compliant to USB HID sensor specifications
(mostly for IOT space). In that case the user space for those can communicate using misc driver interface, without adding new kernel drivers.

Quoted 3 lines

So you hide it behind a char device node?  That's not very descriptive
or easy to understand :)

We added several new sensors to IIO and in process of adding new sensors to standardize ABI for sensors defined in HID sensor spec.

Customers can develop and download some algorithm which uses output of several sensors and come up with some fusion sensor to detect some activity. Either some kernel driver needs to read this and pass this event to user space or directly let the user space communicate with the firmware using character device.
Is there any better way to handle this?

We want customers to use upstream kernel without out of tree kernel drivers.

Thanks,
Srinivas

maintainer
#15 lore raw

Re: [PATCH 7/7] misc: intel-ish-client: add intel ishtp clients driver

Quoted 9 lines · Srinivas Pandruvada
Quoted 6 lines · Greg KH
Quoted 5 lines · Srinivas Pandruvada
Quoted 3 lines · Greg KH

On Fri, Dec 23, 2016 at 09:22:29AM +0800, Even Xu wrote

Quoted 1 line

[...]

Quoted 8 lines
Quoted 5 lines

debug should not require a char device node, use debugfs, that is what
it is there for.

For "calibration", why not use configfs or even sysfs?

We will check on this. There is some legacy with the deployed user space tools.

Um, you do know that's not a good reason/excuse at all to take incorrect kernel code, right? Please don't use that as any kind of excuse.

Quoted 22 lines
Quoted 9 lines
Quoted 8 lines

Basically the ISH provided a standalone low power processor to developers and manufacturers  to do download some custom algorithms for
sensors, which may not be compliant to USB HID sensor specifications
(mostly for IOT space). In that case the user space for those can communicate using misc driver interface, without adding new kernel drivers.

Quoted 3 lines

So you hide it behind a char device node?  That's not very descriptive
or easy to understand :)

We added several new sensors to IIO and in process of adding new sensors to standardize ABI for sensors defined in HID sensor spec.

Customers can develop and download some algorithm which uses output of several sensors and come up with some fusion sensor to detect some activity. Either some kernel driver needs to read this and pass this event to user space or directly let the user space communicate with the firmware using character device.
Is there any better way to handle this?

Quoted 2 lines

We want customers to use upstream kernel without out of tree kernel drivers.

Why are you somehow claiming this is an either/or kind of situation? What out-of-tree kernel modules are there? Why can't they just be merged if they are somewhere?

Having an interface to add new types of "functionality" is great, and fine, but why you think a char device node is that type of api is confusing to me when I already pointed out an number of other potential solutions. Have you tried them out and found they do not work? If so, great, please explain what is lacking and we can go from there.

If not, please do some basic research first before trying to claim that a char device is the only possible solution.

You have run this code through the internal Intel kernel developer review process on their mailing list, correct? What did they say about your current design? If not, why have you not taken advantage of this resource?

thanks,

greg k-h

author
#16 lore raw

RE: [PATCH 7/7] misc: intel-ish-client: add intel ishtp clients driver

Hi, Greg,

Thanks for your review and suggestion, I will rework my patch based on your suggestion and then submit again.

Best Regards,
Even Xu

-----Original Message-----
From: Greg KH [mailto:[email protected]]
Sent: Thursday, January 5, 2017 3:41 AM
To: Srinivas Pandruvada <[email protected]>
Cc: Xu, Even <[email protected]>; [email protected]; [email protected]; [email protected]; Shevchenko, Andriy <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH 7/7] misc: intel-ish-client: add intel ishtp clients driver

Quoted 9 lines · Srinivas Pandruvada
Quoted 6 lines · Greg KH
Quoted 5 lines · Srinivas Pandruvada
Quoted 3 lines · Greg KH

On Fri, Dec 23, 2016 at 09:22:29AM +0800, Even Xu wrote

Quoted 1 line

[...]

Quoted 7 lines
Quoted 4 lines

debug should not require a char device node, use debugfs, that is what it is there for.

For "calibration", why not use configfs or even sysfs?

We will check on this. There is some legacy with the deployed user space tools.

Um, you do know that's not a good reason/excuse at all to take incorrect kernel code, right? Please don't use that as any kind of excuse.

Quoted 19 lines
Quoted 9 lines
Quoted 6 lines

Basically the ISH provided a standalone low power processor to developers and manufacturers  to do download some custom algorithms for sensors, which may not be compliant to USB HID sensor specifications (mostly for IOT space). In that case the user space for those can communicate using misc driver interface, without adding new kernel drivers.

So you hide it behind a char device node?  That's not very descriptive or easy to understand :)

We added several new sensors to IIO and in process of adding new sensors to standardize ABI for sensors defined in HID sensor spec.

Customers can develop and download some algorithm which uses output of several sensors and come up with some fusion sensor to detect some activity. Either some kernel driver needs to read this and pass this event to user space or directly let the user space communicate with the firmware using character device.
Is there any better way to handle this?

Quoted 2 lines

We want customers to use upstream kernel without out of tree kernel drivers.

Why are you somehow claiming this is an either/or kind of situation?
What out-of-tree kernel modules are there? Why can't they just be merged if they are somewhere?

Having an interface to add new types of "functionality" is great, and fine, but why you think a char device node is that type of api is confusing to me when I already pointed out an number of other potential solutions. Have you tried them out and found they do not work? If so, great, please explain what is lacking and we can go from there.

If not, please do some basic research first before trying to claim that a char device is the only possible solution.

You have run this code through the internal Intel kernel developer review process on their mailing list, correct? What did they say about your current design? If not, why have you not taken advantage of this resource?

thanks,

greg k-h

maintainer
#17 lore raw

Re: [PATCH 7/7] misc: intel-ish-client: add intel ishtp clients driver

In reply to Even Xu
Quoted 38 lines · Even Xu
drivers/misc/intel-ish-client/intel-ishtp-clients.c new file +38 -0
+/**
+ * ishtp_cl_probe() - ISHTP client driver probe
+ * @cl_device:		ISHTP client device instance
+ *
+ * This function gets called on device create on ISHTP bus
+ *
+ * Return: 0 on success, non zero on error
+ */
+static int ishtp_cl_probe(struct ishtp_cl_device *cl_device)
+{
+	struct ishtp_cl_miscdev *ishtp_cl_misc;
+	int ret;
+
+	if (!cl_device)
+		return -ENODEV;
+
+	ishtp_cl_misc = kzalloc(sizeof(struct ishtp_cl_miscdev),
+				GFP_KERNEL);
+	if (!ishtp_cl_misc)
+		return -ENOMEM;
+
+	if (uuid_le_cmp(ishtp_smhi_guid,
+			cl_device->fw_client->props.protocol_name) == 0) {
+		ishtp_cl_misc->cl_miscdev.name = "ish-smhi";
+	} else if (uuid_le_cmp(ishtp_trace_guid,
+			cl_device->fw_client->props.protocol_name) == 0) {
+		ishtp_cl_misc->cl_miscdev.name = "ish-trace";
+	} else if (uuid_le_cmp(ishtp_traceconfig_guid,
+			cl_device->fw_client->props.protocol_name) == 0) {
+		ishtp_cl_misc->cl_miscdev.name = "ish-tracec";
+	} else if (uuid_le_cmp(ishtp_loader_guid,
+			cl_device->fw_client->props.protocol_name) == 0) {
+		ishtp_cl_misc->cl_miscdev.name = "ish-loader";
+	} else {
+		dev_err(&cl_device->dev, "Not supported client\n");
+		ret = -ENODEV;
+		goto release_mem;
+	}

drivers/misc/intel-ish-client/intel-ishtp-clients.c line 761

Quoted 10 lines
drivers/misc/intel-ish-client/intel-ishtp-clients.c new file +10 -0
+
+	ishtp_cl_misc->cl_miscdev.parent = &cl_device->dev;
+	ishtp_cl_misc->cl_miscdev.fops = &ishtp_cl_fops;
+	ishtp_cl_misc->cl_miscdev.minor = MISC_DYNAMIC_MINOR,
+
+	ret = misc_register(&ishtp_cl_misc->cl_miscdev);
+	if (ret) {
+		dev_err(&cl_device->dev, "misc device register failed\n");
+		goto release_mem;
+	}

Now your userspace device node is created and can be opened up and accessed. But:

Quoted 5 lines
drivers/misc/intel-ish-client/intel-ishtp-clients.c new file +5 -0
+
+	ishtp_cl_misc->cl_device = cl_device;
+
+	init_waitqueue_head(&ishtp_cl_misc->read_wait);
+

drivers/misc/intel-ish-client/intel-ishtp-clients.c line 776

Quoted 10 lines
drivers/misc/intel-ish-client/intel-ishtp-clients.c new file +10 -0
+	ishtp_set_drvdata(cl_device, ishtp_cl_misc);
+
+	ishtp_get_device(cl_device);
+
+	mutex_init(&ishtp_cl_misc->cl_mutex);
+
+	INIT_WORK(&ishtp_cl_misc->reset_work, ishtp_cl_reset_handler);
+
+	/* Register event callback */
+	ishtp_register_event_cb(cl_device, ishtp_cl_event_cb);

You were not done setting up the device. What nasty races just happened?

And the above functions can never fail? Why are you grabbing a refernce to the cl_device yet doing nothing with it? That feels really broken and wrong.

thanks,

greg k-h

maintainer
#18 lore raw

Re: [PATCH 7/7] misc: intel-ish-client: add intel ishtp clients driver

In reply to Even Xu
Quoted 6 lines · Even Xu
drivers/misc/intel-ish-client/intel-ishtp-clients.c new file +6 -0
+static int ishtp_cl_open(struct inode *inode, struct file *file)
+{
+	struct miscdevice *misc = file->private_data;
+	struct ishtp_cl *cl;
+	struct ishtp_device *dev;
+	struct ishtp_cl_miscdev *ishtp_cl_misc;

drivers/misc/intel-ish-client/intel-ishtp-clients.c line 94

Quoted 10 lines
drivers/misc/intel-ish-client/intel-ishtp-clients.c new file +10 -0
+	int ret;
+
+	/* Non-blocking semantics are not supported */
+	if (file->f_flags & O_NONBLOCK)
+		return -EINVAL;
+
+	ishtp_cl_misc = container_of(misc,
+				struct ishtp_cl_miscdev, cl_miscdev);
+	if (!ishtp_cl_misc || !ishtp_cl_misc->cl_device)
+		return -ENODEV;

How can ishtp_cl_misc ever be NULL? Are you sure you know what container_of() really does here? :)

drivers/misc/intel-ish-client/intel-ishtp-clients.c line 98

Quoted 3 lines
drivers/misc/intel-ish-client/intel-ishtp-clients.c new file +3 -0
+	dev = ishtp_cl_misc->cl_device->ishtp_dev;
+	if (!dev)
+		return -ENODEV;

How can dev be NULL?

Quoted 67 lines
drivers/misc/intel-ish-client/intel-ishtp-clients.c new file +67 -0
+
+	mutex_lock(&ishtp_cl_misc->cl_mutex);
+
+	/*
+	 * Every client only supports one opened instance
+	 * at the sametime.
+	 */
+	if (ishtp_cl_misc->cl) {
+		ret = -EBUSY;
+		goto out_unlock;
+	}
+
+	cl = ishtp_cl_allocate(dev);
+	if (!cl) {
+		ret = -ENOMEM;
+		goto out_free;
+	}
+
+	if (dev->dev_state != ISHTP_DEV_ENABLED) {
+		ret = -ENODEV;
+		goto out_free;
+	}
+
+	ret = ishtp_cl_link(cl, ISHTP_HOST_CLIENT_ID_ANY);
+	if (ret)
+		goto out_free;
+
+	ishtp_cl_misc->cl = cl;
+
+	file->private_data = ishtp_cl_misc;
+
+	mutex_unlock(&ishtp_cl_misc->cl_mutex);
+
+	return nonseekable_open(inode, file);
+
+out_free:
+	kfree(cl);
+out_unlock:
+	mutex_unlock(&ishtp_cl_misc->cl_mutex);
+	return ret;
+}
+
+#define WAIT_FOR_SEND_SLICE_MS		100
+#define WAIT_FOR_SEND_COUNT		10
+
+static int ishtp_cl_release(struct inode *inode, struct file *file)
+{
+	struct ishtp_cl_miscdev *ishtp_cl_misc = file->private_data;
+	struct ishtp_cl *cl;
+	struct ishtp_cl_rb *rb;
+	struct ishtp_device *dev;
+	int try = WAIT_FOR_SEND_COUNT;
+	int ret;
+
+	mutex_lock(&ishtp_cl_misc->cl_mutex);
+
+	/* Wake up from waiting if anyone wait on it */
+	wake_up_interruptible(&ishtp_cl_misc->read_wait);
+
+	cl = ishtp_cl_misc->cl;
+	dev = cl->dev;
+
+	/*
+	 * May happen if device sent FW reset or was intentionally
+	 * halted by host SW. The client is then invalid.
+	 */
+	if ((dev->dev_state == ISHTP_DEV_ENABLED) &&

drivers/misc/intel-ish-client/intel-ishtp-clients.c line 175

Quoted 10 lines
drivers/misc/intel-ish-client/intel-ishtp-clients.c new file +10 -0
+			(cl->state == ISHTP_CL_CONNECTED)) {
+		/*
+		 * Check and wait 1s for message in tx_list to be sent.
+		 */
+		do {
+			if (!ishtp_cl_tx_empty(cl))
+				msleep_interruptible(WAIT_FOR_SEND_SLICE_MS);
+			else
+				break;
+		} while (--try);

So just try it a bunch and hope it all works out? No error message if something went wrong? Why not try forever? Why that specific number of trys? This feels hacky.

Quoted 40 lines
drivers/misc/intel-ish-client/intel-ishtp-clients.c new file +40 -0
+
+		cl->state = ISHTP_CL_DISCONNECTING;
+		ret = ishtp_cl_disconnect(cl);
+	}
+
+	ishtp_cl_unlink(cl);
+	ishtp_cl_flush_queues(cl);
+	/* Disband and free all Tx and Rx client-level rings */
+	ishtp_cl_free(cl);
+
+	ishtp_cl_misc->cl = NULL;
+
+	rb = ishtp_cl_misc->read_rb;
+	if (rb) {
+		ishtp_cl_io_rb_recycle(rb);
+		ishtp_cl_misc->read_rb = NULL;
+	}
+
+	file->private_data = NULL;
+
+	mutex_unlock(&ishtp_cl_misc->cl_mutex);
+
+	return ret;
+}
+
+static ssize_t ishtp_cl_read(struct file *file, char __user *ubuf,
+			size_t length, loff_t *offset)
+{
+	struct ishtp_cl_miscdev *ishtp_cl_misc = file->private_data;
+	struct ishtp_cl *cl;
+	struct ishtp_cl_rb *rb;
+	struct ishtp_device *dev;
+	int ret = 0;
+
+	/* Non-blocking semantics are not supported */
+	if (file->f_flags & O_NONBLOCK)
+		return -EINVAL;
+
+	mutex_lock(&ishtp_cl_misc->cl_mutex);
+

drivers/misc/intel-ish-client/intel-ishtp-clients.c line 225

Quoted 10 lines
drivers/misc/intel-ish-client/intel-ishtp-clients.c new file +10 -0
+	cl = ishtp_cl_misc->cl;
+
+	/*
+	 * ISHFW reset will cause cl be freed and re-allocated.
+	 * So must make sure cl is re-allocated successfully.
+	 */
+	if (!cl || !cl->dev) {
+		ret = -ENODEV;
+		goto out_unlock;
+	}

How can these ever be true?

Quoted 17 lines
drivers/misc/intel-ish-client/intel-ishtp-clients.c new file +17 -0
+
+	dev = cl->dev;
+	if (dev->dev_state != ISHTP_DEV_ENABLED) {
+		ret = -ENODEV;
+		goto out_unlock;
+	}
+
+	if (ishtp_cl_misc->read_rb)
+		goto get_rb;
+
+	rb = ishtp_cl_rx_get_rb(cl);
+	if (rb)
+		goto copy_buffer;
+
+	/*
+	 * Release mutex for other operation can be processed parallelly
+	 * during waiting.

drivers/misc/intel-ish-client/intel-ishtp-clients.c line 252

Quoted 10 lines
drivers/misc/intel-ish-client/intel-ishtp-clients.c new file +10 -0
+	 */
+	mutex_unlock(&ishtp_cl_misc->cl_mutex);
+
+	if (wait_event_interruptible(ishtp_cl_misc->read_wait,
+			ishtp_cl_misc->read_rb != NULL)) {
+		dev_err(&ishtp_cl_misc->cl_device->dev,
+			"Wake up not successful;"
+			"signal pending = %d signal = %08lX\n",
+			signal_pending(current),
+			current->pending.signal.sig[0]);

Why spam the error log for this?

Quoted 54 lines
drivers/misc/intel-ish-client/intel-ishtp-clients.c new file +54 -0
+		return -ERESTARTSYS;
+	}
+
+	mutex_lock(&ishtp_cl_misc->cl_mutex);
+
+	/*
+	 * waitqueue can be woken up in many cases, so must check
+	 * if dev and cl is still available.
+	 */
+	if (dev->dev_state != ISHTP_DEV_ENABLED) {
+		ret = -ENODEV;
+		goto out_unlock;
+	}
+
+	cl = ishtp_cl_misc->cl;
+	if (!cl) {
+		ret = -ENODEV;
+		goto out_unlock;
+	}
+
+	if (cl->state == ISHTP_CL_INITIALIZING ||
+		cl->state == ISHTP_CL_DISCONNECTED ||
+		cl->state == ISHTP_CL_DISCONNECTING) {
+		ret = -EBUSY;
+		goto out_unlock;
+	}
+
+get_rb:
+	rb = ishtp_cl_misc->read_rb;
+	if (!rb) {
+		ret = -ENODEV;
+		goto out_unlock;
+	}
+
+copy_buffer:
+	/* Now copy the data to user space */
+	if (!length || !ubuf || *offset > rb->buf_idx) {
+		ret = -EMSGSIZE;
+		goto out_unlock;
+	}
+
+	/*
+	 * length is being truncated, however buf_idx may
+	 * point beyond that.
+	 */
+	length = min_t(size_t, length, rb->buf_idx - *offset);
+
+	if (copy_to_user(ubuf, rb->buffer.data + *offset, length)) {
+		ret = -EFAULT;
+		goto out_unlock;
+	}
+
+	*offset += length;
+	if ((unsigned long)*offset < rb->buf_idx)

drivers/misc/intel-ish-client/intel-ishtp-clients.c line 316

Quoted 10 lines
drivers/misc/intel-ish-client/intel-ishtp-clients.c new file +10 -0
+		goto out_unlock;
+
+	ishtp_cl_io_rb_recycle(rb);
+	ishtp_cl_misc->read_rb = NULL;
+	*offset = 0;
+
+out_unlock:
+	mutex_unlock(&ishtp_cl_misc->cl_mutex);
+	return ret < 0 ? ret : length;
+}

I still don't understand what is being read/written through this character device node. What is it used for?

thanks,

greg k-h