mei: use structured buffer for extra write buffer
authorTomas Winkler <tomas.winkler@intel.com>
Sun, 18 Nov 2012 13:13:15 +0000 (15:13 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 21 Nov 2012 20:43:57 +0000 (12:43 -0800)
The structure of the message is static so we don't have
to use and cast the buffer. We can also drop extra_write_index
variable as this information can be extracted directly
from the message header

Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/misc/mei/init.c
drivers/misc/mei/interrupt.c
drivers/misc/mei/mei_dev.h

index 02784af..49600d6 100644 (file)
@@ -288,7 +288,7 @@ void mei_reset(struct mei_device *dev, int interrupts_enabled)
                mei_me_cl_unlink(dev, &dev->iamthif_cl);
 
                mei_amthif_reset_params(dev);
-               dev->extra_write_index = 0;
+               memset(&dev->wr_ext_msg, 0, sizeof(dev->wr_ext_msg));
        }
 
        dev->me_clients_num = 0;
index 14becc0..9224646 100644 (file)
@@ -446,15 +446,14 @@ static void mei_client_disconnect_request(struct mei_device *dev,
                                dev->iamthif_timer = 0;
 
                        /* prepare disconnect response */
-                       (void)mei_hbm_hdr(&dev->ext_msg_buf[0], len);
+                       (void)mei_hbm_hdr((u32 *)&dev->wr_ext_msg.hdr, len);
                        disconnect_res =
                                (struct hbm_client_connect_response *)
-                               &dev->ext_msg_buf[1];
+                               &dev->wr_ext_msg.data;
                        disconnect_res->hbm_cmd = CLIENT_DISCONNECT_RES_CMD;
                        disconnect_res->host_addr = pos->host_client_id;
                        disconnect_res->me_addr = pos->me_client_id;
                        disconnect_res->status = 0;
-                       dev->extra_write_index = 2;
                        break;
                }
        }
@@ -643,16 +642,13 @@ static void mei_irq_thread_read_bus_message(struct mei_device *dev,
        {
                /* prepare stop request: sent in next interrupt event */
 
-               u32 *buf = dev->ext_msg_buf;
                const size_t len = sizeof(struct hbm_host_stop_request);
 
-               mei_hdr = mei_hbm_hdr(&buf[0], len);
-               stop_req = (struct hbm_host_stop_request *)&buf[1];
+               mei_hdr = mei_hbm_hdr((u32 *)&dev->wr_ext_msg.hdr, len);
+               stop_req = (struct hbm_host_stop_request *)&dev->wr_ext_msg.data;
                memset(stop_req, 0, len);
                stop_req->hbm_cmd = HOST_STOP_REQ_CMD;
                stop_req->reason = DRIVER_STOP_REQUEST;
-
-               dev->extra_write_index = 2;
                break;
        }
        default:
@@ -988,15 +984,11 @@ static int mei_irq_thread_write_handler(struct mei_cl_cb *cmpl_list,
                wake_up_interruptible(&dev->wait_stop_wd);
        }
 
-       if (dev->extra_write_index) {
-               dev_dbg(&dev->pdev->dev, "extra_write_index =%d.\n",
-                               dev->extra_write_index);
-               mei_write_message(dev,
-                               (struct mei_msg_hdr *) &dev->ext_msg_buf[0],
-                               (unsigned char *) &dev->ext_msg_buf[1],
-                               (dev->extra_write_index - 1) * sizeof(u32));
-               *slots -= dev->extra_write_index;
-               dev->extra_write_index = 0;
+       if (dev->wr_ext_msg.hdr.length) {
+               mei_write_message(dev, &dev->wr_ext_msg.hdr,
+                       dev->wr_ext_msg.data, dev->wr_ext_msg.hdr.length);
+               *slots -= mei_data2slots(dev->wr_ext_msg.hdr.length);
+               dev->wr_ext_msg.hdr.length = 0;
        }
        if (dev->dev_state == MEI_DEV_ENABLED) {
                if (dev->wd_pending &&
@@ -1263,11 +1255,11 @@ irqreturn_t mei_interrupt_thread_handler(int irq, void *dev_id)
        }
        /* check slots available for reading */
        slots = mei_count_full_read_slots(dev);
-       dev_dbg(&dev->pdev->dev, "slots =%08x  extra_write_index =%08x.\n",
-               slots, dev->extra_write_index);
-       while (slots > 0 && !dev->extra_write_index) {
-               dev_dbg(&dev->pdev->dev, "slots =%08x  extra_write_index =%08x.\n",
-                               slots, dev->extra_write_index);
+       while (slots > 0) {
+               /* we have urgent data to send so break the read */
+               if (dev->wr_ext_msg.hdr.length)
+                       break;
+               dev_dbg(&dev->pdev->dev, "slots =%08x\n", slots);
                dev_dbg(&dev->pdev->dev, "call mei_irq_thread_read_handler.\n");
                rets = mei_irq_thread_read_handler(&complete_list, dev, &slots);
                if (rets)
index e511b84..2a38e95 100644 (file)
@@ -192,8 +192,9 @@ struct mei_cl {
 };
 
 /**
- * struct mei_deive -  MEI private device struct
+ * struct mei_device -  MEI private device struct
  * @hbuf_depth - depth of host(write) buffer
+ * @wr_ext_msg - buffer for hbm control responses (set in read cycle)
  */
 struct mei_device {
        struct pci_dev *pdev;   /* pointer to pci device struct */
@@ -244,11 +245,13 @@ struct mei_device {
        u16 init_clients_timer;
        bool need_reset;
 
-       u32 extra_write_index;
        unsigned char rd_msg_buf[MEI_RD_MSG_BUF_SIZE];  /* control messages */
-       u32 wr_msg_buf[128];    /* used for control messages */
-       u32 ext_msg_buf[8];     /* for control responses */
        u32 rd_msg_hdr;
+       u32 wr_msg_buf[128];    /* used for control messages */
+       struct {
+               struct mei_msg_hdr hdr;
+               unsigned char data[4];  /* All HBM messages are 4 bytes */
+       } wr_ext_msg;           /* for control responses */
 
        struct hbm_version version;