Skip to contentSkip to conversation

mei: revamp mei_amthif_irq_read_message

PATCH In review Tomas Winkler 2 participants 5 messages Apr 19, 2013

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

PATCH 1/3 mei: revamp mei_amthif_irq_read_message

Rename the function to mei_amthif_irq_read_msg
and change parameters order

---
 drivers/misc/mei/amthif.c    | 10 +++++-----
 drivers/misc/mei/interrupt.c |  2 +-
 drivers/misc/mei/mei_dev.h   |  9 +++++++++
 3 files changed, 15 insertions(+), 6 deletions(-)
drivers/misc/mei/amthif.c +5 -5
index 9a5e8c7..31a6212 100644
@@ -505,14 +505,15 @@ int mei_amthif_irq_write_complete(struct mei_device *dev, s32 *slots,
  * mei_amthif_irq_read_message - read routine after ISR to
  *			handle the read amthif message
  *
- * @complete_list: An instance of our list structure
  * @dev: the device structure
  * @mei_hdr: header of amthif message
+ * @complete_list: An instance of our list structure
  *
  * returns 0 on success, <0 on failure.
  */
-int mei_amthif_irq_read_message(struct mei_cl_cb *complete_list,
-		struct mei_device *dev, struct mei_msg_hdr *mei_hdr)
+int mei_amthif_irq_read_msg(struct mei_device *dev,
+			    struct mei_msg_hdr *mei_hdr,
+			    struct mei_cl_cb *complete_list)
 {
 	struct mei_cl_cb *cb;
 	unsigned char *buffer;
@@ -530,8 +531,7 @@ int mei_amthif_irq_read_message(struct mei_cl_cb *complete_list,
 	if (!mei_hdr->msg_complete)
 		return 0;
 
-	dev_dbg(&dev->pdev->dev,
-			"amthif_message_buffer_index =%d\n",
+	dev_dbg(&dev->pdev->dev, "amthif_message_buffer_index =%d\n",
 			mei_hdr->length);
 
 	dev_dbg(&dev->pdev->dev, "completed amthif read.\n ");
drivers/misc/mei/interrupt.c +1 -1
index 653fcfb..9bf64c0 100644
@@ -427,7 +427,7 @@ int mei_irq_read_handler(struct mei_device *dev,
 		dev_dbg(&dev->pdev->dev, "call mei_irq_thread_read_iamthif_message.\n");
 		dev_dbg(&dev->pdev->dev, MEI_HDR_FMT, MEI_HDR_PRM(mei_hdr));
 
-		ret = mei_amthif_irq_read_message(cmpl_list, dev, mei_hdr);
+		ret = mei_amthif_irq_read_msg(dev, mei_hdr, cmpl_list);
 		if (ret)
 			goto end;
 	} else {
drivers/misc/mei/mei_dev.h +9 -0
index 56dee56..c91c492 100644
@@ -502,6 +502,15 @@ struct mei_cl_cb *mei_amthif_find_read_list_entry(struct mei_device *dev,
 
 void mei_amthif_run_next_cmd(struct mei_device *dev);
 
+int mei_amthif_irq_write_complete(struct mei_device *dev, s32 *slots,
+			struct mei_cl_cb *cb, struct mei_cl_cb *cmpl_list);
+
+void mei_amthif_complete(struct mei_device *dev, struct mei_cl_cb *cb);
+int mei_amthif_irq_read_msg(struct mei_device *dev,
+			    struct mei_msg_hdr *mei_hdr,
+			    struct mei_cl_cb *complete_list);
+int mei_amthif_irq_read(struct mei_device *dev, s32 *slots);
+
 /*
  * NFC functions
  */
Signature · 1 line
1.8.1.2
#1 lore raw

PATCH v2 3/3 mei: reseting -> resetting

From: Bill Nottingham <[email protected]>

This enum leaks out to userspace via error messages, so fix the spelling.

---
V2: rebased

 drivers/misc/mei/hbm.c     | 8 ++++----
 drivers/misc/mei/hw-me.c   | 2 +-
 drivers/misc/mei/init.c    | 4 ++--
 drivers/misc/mei/mei_dev.h | 2 +-
 4 files changed, 8 insertions(+), 8 deletions(-)
drivers/misc/mei/hbm.c +4 -4
index 4de80d9..db605f5 100644
@@ -52,7 +52,7 @@ static void mei_hbm_me_cl_allocate(struct mei_device *dev)
 			sizeof(struct mei_me_client), GFP_KERNEL);
 	if (!clients) {
 		dev_err(&dev->pdev->dev, "memory allocation for ME clients failed.\n");
-		dev->dev_state = MEI_DEV_RESETING;
+		dev->dev_state = MEI_DEV_RESETTING;
 		mei_reset(dev, 1);
 		return;
 	}
@@ -167,7 +167,7 @@ int mei_hbm_start_req(struct mei_device *dev)
 	dev->hbm_state = MEI_HBM_IDLE;
 	if (mei_write_message(dev, mei_hdr, dev->wr_msg.data)) {
 		dev_err(&dev->pdev->dev, "version message writet failed\n");
-		dev->dev_state = MEI_DEV_RESETING;
+		dev->dev_state = MEI_DEV_RESETTING;
 		mei_reset(dev, 1);
 		return -ENODEV;
 	}
@@ -196,7 +196,7 @@ static void mei_hbm_enum_clients_req(struct mei_device *dev)
 	enum_req->hbm_cmd = HOST_ENUM_REQ_CMD;
 
 	if (mei_write_message(dev, mei_hdr, dev->wr_msg.data)) {
-		dev->dev_state = MEI_DEV_RESETING;
+		dev->dev_state = MEI_DEV_RESETTING;
 		dev_err(&dev->pdev->dev, "enumeration request write failed.\n");
 		mei_reset(dev, 1);
 	}
@@ -249,7 +249,7 @@ static int mei_hbm_prop_req(struct mei_device *dev)
 	prop_req->address = next_client_index;
 
 	if (mei_write_message(dev, mei_hdr, dev->wr_msg.data)) {
-		dev->dev_state = MEI_DEV_RESETING;
+		dev->dev_state = MEI_DEV_RESETTING;
 		dev_err(&dev->pdev->dev, "properties request write failed\n");
 		mei_reset(dev, 1);
 
drivers/misc/mei/hw-me.c +1 -1
index 3d6dfa3..fc03227 100644
@@ -481,7 +481,7 @@ irqreturn_t mei_me_irq_thread_handler(int irq, void *dev_id)
 
 	/* check if ME wants a reset */
 	if (!mei_hw_is_ready(dev) &&
-	    dev->dev_state != MEI_DEV_RESETING &&
+	    dev->dev_state != MEI_DEV_RESETTING &&
 	    dev->dev_state != MEI_DEV_INITIALIZING) {
 		dev_dbg(&dev->pdev->dev, "FW not ready.\n");
 		mei_reset(dev, 1);
drivers/misc/mei/init.c +2 -2
index 59159e0..713d89f 100644
@@ -33,7 +33,7 @@ const char *mei_dev_state_str(int state)
 	MEI_DEV_STATE(INITIALIZING);
 	MEI_DEV_STATE(INIT_CLIENTS);
 	MEI_DEV_STATE(ENABLED);
-	MEI_DEV_STATE(RESETING);
+	MEI_DEV_STATE(RESETTING);
 	MEI_DEV_STATE(DISABLED);
 	MEI_DEV_STATE(POWER_DOWN);
 	MEI_DEV_STATE(POWER_UP);
@@ -146,7 +146,7 @@ void mei_reset(struct mei_device *dev, int interrupts_enabled)
 	if (dev->dev_state != MEI_DEV_INITIALIZING) {
 		if (dev->dev_state != MEI_DEV_DISABLED &&
 		    dev->dev_state != MEI_DEV_POWER_DOWN)
-			dev->dev_state = MEI_DEV_RESETING;
+			dev->dev_state = MEI_DEV_RESETTING;
 
 		mei_cl_all_disconnect(dev);
 
drivers/misc/mei/mei_dev.h +1 -1
index c91c492..4de5140 100644
@@ -97,7 +97,7 @@ enum mei_dev_state {
 	MEI_DEV_INITIALIZING = 0,
 	MEI_DEV_INIT_CLIENTS,
 	MEI_DEV_ENABLED,
-	MEI_DEV_RESETING,
+	MEI_DEV_RESETTING,
 	MEI_DEV_DISABLED,
 	MEI_DEV_POWER_DOWN,
 	MEI_DEV_POWER_UP
Signature · 1 line
1.8.1.2
#2 lore raw

PATCH 2/3 mei: fix reading large reposnes

In reply to Tomas Winkler

While writting to device is limitted to max_msg_length advertized in client properites the read can be much longer delivered consequiting chunks.

We use krealloc to enlarge the buffer when needed.

---
 drivers/misc/mei/bus.c       |  8 ++++----
 drivers/misc/mei/client.c    |  7 ++++---
 drivers/misc/mei/client.h    |  2 +-
 drivers/misc/mei/interrupt.c | 18 +++++++++++++++---
 drivers/misc/mei/main.c      |  7 +++----
 5 files changed, 27 insertions(+), 15 deletions(-)
drivers/misc/mei/bus.c +4 -4
index 834ceeb..1e935ea 100644
@@ -286,7 +286,7 @@ int __mei_cl_recv(struct mei_cl *cl, u8 *buf, size_t length)
 	mutex_lock(&dev->device_lock);
 
 	if (!cl->read_cb) {
-		err = mei_cl_read_start(cl);
+		err = mei_cl_read_start(cl, length);
 		if (err < 0) {
 			mutex_unlock(&dev->device_lock);
 			return err;
@@ -378,7 +378,7 @@ static void mei_bus_event_work(struct work_struct *work)
 	device->events = 0;
 
 	/* Prepare for the next read */
-	mei_cl_read_start(device->cl);
+	mei_cl_read_start(device->cl, 0);
 }
 
 int mei_cl_register_event_cb(struct mei_cl_device *device,
@@ -392,7 +392,7 @@ int mei_cl_register_event_cb(struct mei_cl_device *device,
 	device->event_context = context;
 	INIT_WORK(&device->event_work, mei_bus_event_work);
 
-	mei_cl_read_start(device->cl);
+	mei_cl_read_start(device->cl, 0);
 
 	return 0;
 }
@@ -436,7 +436,7 @@ int mei_cl_enable_device(struct mei_cl_device *device)
 	mutex_unlock(&dev->device_lock);
 
 	if (device->event_cb && !cl->read_cb)
-		mei_cl_read_start(device->cl);
+		mei_cl_read_start(device->cl, 0);
 
 	if (!device->ops || !device->ops->enable)
 		return 0;
drivers/misc/mei/client.c +4 -3
index 9541aa9..7189274 100644
@@ -624,7 +624,7 @@ int mei_cl_flow_ctrl_reduce(struct mei_cl *cl)
  *
  * returns 0 on success, <0 on failure.
  */
-int mei_cl_read_start(struct mei_cl *cl)
+int mei_cl_read_start(struct mei_cl *cl, size_t length)
 {
 	struct mei_device *dev;
 	struct mei_cl_cb *cb;
@@ -657,8 +657,9 @@ int mei_cl_read_start(struct mei_cl *cl)
 	if (!cb)
 		return -ENOMEM;
 
-	rets = mei_io_cb_alloc_resp_buf(cb,
-			dev->me_clients[i].props.max_msg_length);
+	/* always allocate at least client max message */
+	length = max_t(size_t, length, dev->me_clients[i].props.max_msg_length);
+	rets = mei_io_cb_alloc_resp_buf(cb, length);
 	if (rets)
 		goto err;
 
drivers/misc/mei/client.h +1 -1
index e890c8b..cfdb144 100644
@@ -87,7 +87,7 @@ int mei_cl_flow_ctrl_reduce(struct mei_cl *cl);
 bool mei_cl_is_other_connecting(struct mei_cl *cl);
 int mei_cl_disconnect(struct mei_cl *cl);
 int mei_cl_connect(struct mei_cl *cl, struct file *file);
-int mei_cl_read_start(struct mei_cl *cl);
+int mei_cl_read_start(struct mei_cl *cl, size_t length);
 int mei_cl_write(struct mei_cl *cl, struct mei_cl_cb *cb, bool blocking);
 
 void mei_host_client_init(struct work_struct *work);
drivers/misc/mei/interrupt.c +15 -3
index 9bf64c0..7473071 100644
@@ -145,9 +145,21 @@ static int mei_cl_irq_read_msg(struct mei_device *dev,
 		}
 
 		if (cb->response_buffer.size < mei_hdr->length + cb->buf_idx) {
-			dev_warn(&dev->pdev->dev, "message overflow.\n");
-			list_del(&cb->list);
-			return -ENOMEM;
+			dev_dbg(&dev->pdev->dev, "message overflow. size %d len %d idx %ld\n",
+				cb->response_buffer.size,
+				mei_hdr->length, cb->buf_idx);
+			cb->response_buffer.data =
+					krealloc(cb->response_buffer.data,
+					mei_hdr->length + cb->buf_idx,
+					GFP_KERNEL);
+
+			if (!cb->response_buffer.data) {
+				dev_err(&dev->pdev->dev, "allocation failed.\n");
+				list_del(&cb->list);
+				return -ENOMEM;
+			}
+			cb->response_buffer.size =
+				mei_hdr->length + cb->buf_idx;
 		}
 
 		buffer = cb->response_buffer.data + cb->buf_idx;
drivers/misc/mei/main.c +3 -4
index 78b4da5..7c44c8d 100644
@@ -244,7 +244,7 @@ static ssize_t mei_read(struct file *file, char __user *ubuf,
 		goto out;
 	}
 
-	err = mei_cl_read_start(cl);
+	err = mei_cl_read_start(cl, length);
 	if (err && err != -EBUSY) {
 		dev_dbg(&dev->pdev->dev,
 			"mei start read failure with status = %d\n", err);
@@ -292,9 +292,8 @@ static ssize_t mei_read(struct file *file, char __user *ubuf,
 	}
 	/* now copy the data to user space */
 copy_buffer:
-	dev_dbg(&dev->pdev->dev, "cb->response_buffer size - %d\n",
-	    cb->response_buffer.size);
-	dev_dbg(&dev->pdev->dev, "cb->buf_idx - %lu\n", cb->buf_idx);
+	dev_dbg(&dev->pdev->dev, "buf.size = %d buf.idx= %ld\n",
+	    cb->response_buffer.size, cb->buf_idx);
 	if (length == 0 || ubuf == NULL || *offset > cb->buf_idx) {
 		rets = -EMSGSIZE;
 		goto free;
Signature · 1 line
1.8.1.2
maintainer
#3 lore raw

Re: [char-misc-next 2/3] mei: fix reading large reposnes

Quoted 6 lines · Tomas Winkler

While writting to device is limitted to max_msg_length advertized in client properites the read can be much longer delivered consequiting chunks.

We use krealloc to enlarge the buffer when needed.

Patch 1/3 had some fuzz in interrupt.c, so I fixed that up by hand, but this one just fails to apply at all:
checking file drivers/misc/mei/bus.c
checking file drivers/misc/mei/client.c
checking file drivers/misc/mei/client.h
checking file drivers/misc/mei/interrupt.c
Hunk #1 FAILED at 145.
1 out of 1 hunk FAILED
checking file drivers/misc/mei/main.c

So something is out of sync between us.

Care to refresh this patch based on my latest tree, and 3/3, and resend them?

thanks,

greg k-h

#4 lore raw

RE: [char-misc-next 2/3] mei: fix reading large reposnes

Quoted 20 lines · Tomas Winkler
Quoted 2 lines

While writting to device is limitted to max_msg_length advertized in client properites the read can be much longer delivered consequiting

chunks.

Quoted 4 lines

We use krealloc to enlarge the buffer when needed.

Patch 1/3 had some fuzz in interrupt.c, so I fixed that up by hand, but this one just fails to apply at all:
checking file drivers/misc/mei/bus.c
checking file drivers/misc/mei/client.c
checking file drivers/misc/mei/client.h
checking file drivers/misc/mei/interrupt.c
Hunk #1 FAILED at 145.
1 out of 1 hunk FAILED
checking file drivers/misc/mei/main.c

Quoted 4 lines

So something is out of sync between us.

Care to refresh this patch based on my latest tree, and 3/3, and resend them?

Grrr, I sent you one patch less, I've rebased this new spelling fix and missed to count it in. I'm resending the missing patches.

Tomas