]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - drivers/misc/mei/amthif.c
mei: revamp writing slot counting
[karo-tx-linux.git] / drivers / misc / mei / amthif.c
index 2fad8443282913f65601c408bc37a2e9f990efdf..bff9a07f1af57e3b75992e52b06f13185932492f 100644 (file)
@@ -21,7 +21,6 @@
 #include <linux/fcntl.h>
 #include <linux/aio.h>
 #include <linux/pci.h>
-#include <linux/init.h>
 #include <linux/ioctl.h>
 #include <linux/cdev.h>
 #include <linux/list.h>
@@ -116,14 +115,11 @@ int mei_amthif_host_init(struct mei_device *dev)
 
        cl->state = MEI_FILE_CONNECTING;
 
-       if (mei_hbm_cl_connect_req(dev, cl)) {
-               dev_dbg(&dev->pdev->dev, "amthif: Failed to connect to ME client\n");
-               cl->state = MEI_FILE_DISCONNECTED;
-               cl->host_client_id = 0;
-       } else {
-               cl->timer_count = MEI_CONNECT_TIMEOUT;
-       }
-       return 0;
+       ret = mei_cl_connect(cl, NULL);
+
+       dev->iamthif_state = MEI_IAMTHIF_IDLE;
+
+       return ret;
 }
 
 /**
@@ -137,14 +133,12 @@ int mei_amthif_host_init(struct mei_device *dev)
 struct mei_cl_cb *mei_amthif_find_read_list_entry(struct mei_device *dev,
                                                struct file *file)
 {
-       struct mei_cl_cb *pos = NULL;
-       struct mei_cl_cb *next = NULL;
+       struct mei_cl_cb *cb;
 
-       list_for_each_entry_safe(pos, next,
-                               &dev->amthif_rd_complete_list.list, list) {
-               if (pos->cl && pos->cl == &dev->iamthif_cl &&
-                       pos->file_object == file)
-                       return pos;
+       list_for_each_entry(cb, &dev->amthif_rd_complete_list.list, list) {
+               if (cb->cl && cb->cl == &dev->iamthif_cl &&
+                       cb->file_object == file)
+                       return cb;
        }
        return NULL;
 }
@@ -302,9 +296,8 @@ static int mei_amthif_send_cmd(struct mei_device *dev, struct mei_cl_cb *cb)
        if (ret < 0)
                return ret;
 
-       if (ret && dev->hbuf_is_ready) {
+       if (ret && mei_hbuf_acquire(dev)) {
                ret = 0;
-               dev->hbuf_is_ready = false;
                if (cb->request_buffer.size > mei_hbuf_max_len(dev)) {
                        mei_hdr.length = mei_hbuf_max_len(dev);
                        mei_hdr.msg_complete = 0;
@@ -336,10 +329,6 @@ static int mei_amthif_send_cmd(struct mei_device *dev, struct mei_cl_cb *cb)
                        list_add_tail(&cb->list, &dev->write_list.list);
                }
        } else {
-               if (!dev->hbuf_is_ready)
-                       dev_dbg(&dev->pdev->dev, "host buffer is not empty");
-
-               dev_dbg(&dev->pdev->dev, "No flow control credentials, so add iamthif cb to write list.\n");
                list_add_tail(&cb->list, &dev->write_list.list);
        }
        return 0;
@@ -365,7 +354,7 @@ int mei_amthif_write(struct mei_device *dev, struct mei_cl_cb *cb)
        if (ret)
                return ret;
 
-       cb->fop_type = MEI_FOP_IOCTL;
+       cb->fop_type = MEI_FOP_WRITE;
 
        if (!list_empty(&dev->amthif_cmd_list.list) ||
            dev->iamthif_state != MEI_IAMTHIF_IDLE) {
@@ -447,23 +436,23 @@ unsigned int mei_amthif_poll(struct mei_device *dev,
 
 
 /**
- * mei_amthif_irq_write_completed - processes completed iamthif operation.
+ * mei_amthif_irq_write - write iamthif command in irq thread context.
  *
  * @dev: the device structure.
- * @slots: free slots.
  * @cb_pos: callback block.
  * @cl: private data of the file object.
  * @cmpl_list: complete list.
  *
  * returns 0, OK; otherwise, error.
  */
-int mei_amthif_irq_write_complete(struct mei_cl *cl, struct mei_cl_cb *cb,
-                                 s32 *slots, struct mei_cl_cb *cmpl_list)
+int mei_amthif_irq_write(struct mei_cl *cl, struct mei_cl_cb *cb,
+                        struct mei_cl_cb *cmpl_list)
 {
        struct mei_device *dev = cl->dev;
        struct mei_msg_hdr mei_hdr;
        size_t len = dev->iamthif_msg_buf_size - dev->iamthif_msg_buf_index;
        u32 msg_slots = mei_data2slots(len);
+       int slots;
        int rets;
 
        rets = mei_cl_flow_ctrl_creds(cl);
@@ -480,13 +469,15 @@ int mei_amthif_irq_write_complete(struct mei_cl *cl, struct mei_cl_cb *cb,
        mei_hdr.reserved = 0;
        mei_hdr.internal = 0;
 
-       if (*slots >= msg_slots) {
+       slots = mei_hbuf_empty_slots(dev);
+
+       if (slots >= msg_slots) {
                mei_hdr.length = len;
                mei_hdr.msg_complete = 1;
        /* Split the message only if we can write the whole host buffer */
-       } else if (*slots == dev->hbuf_depth) {
-               msg_slots = *slots;
-               len = (*slots * sizeof(u32)) - sizeof(struct mei_msg_hdr);
+       } else if (slots == dev->hbuf_depth) {
+               msg_slots = slots;
+               len = (slots * sizeof(u32)) - sizeof(struct mei_msg_hdr);
                mei_hdr.length = len;
                mei_hdr.msg_complete = 0;
        } else {
@@ -496,7 +487,6 @@ int mei_amthif_irq_write_complete(struct mei_cl *cl, struct mei_cl_cb *cb,
 
        dev_dbg(&dev->pdev->dev, MEI_HDR_FMT,  MEI_HDR_PRM(&mei_hdr));
 
-       *slots -=  msg_slots;
        rets = mei_write_message(dev, &mei_hdr,
                        dev->iamthif_msg_buf + dev->iamthif_msg_buf_index);
        if (rets) {