aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorTomas Winkler <tomas.winkler@intel.com>2012-11-18 08:13:16 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-11-21 15:43:58 -0500
commitea3b5fb710c6d0b61f4bfbbc48b34b99b9c89bae (patch)
tree3feb8b2e9907b1ddc9cf4c587c2ec6f223988781 /drivers
parent5fb54fb456f77128f817ab3491d6b131bec480b5 (diff)
mei: streamline write complete flow function
Rename the function _mei_irq_thread_cmpl to mei_irq_thread_write_complete to make clear it deals with writing. Remove cl from the parameter list as it can be extracted from cb block. Extract the common flow from if statements and document the logic properly Signed-off-by: Tomas Winkler <tomas.winkler@intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/misc/mei/interrupt.c113
1 files changed, 43 insertions, 70 deletions
diff --git a/drivers/misc/mei/interrupt.c b/drivers/misc/mei/interrupt.c
index 92246465ea11..85e272258ff1 100644
--- a/drivers/misc/mei/interrupt.c
+++ b/drivers/misc/mei/interrupt.c
@@ -734,90 +734,63 @@ static int _mei_irq_thread_ioctl(struct mei_device *dev, s32 *slots,
734} 734}
735 735
736/** 736/**
737 * _mei_irq_thread_cmpl - processes completed and no-iamthif operation. 737 * mei_irq_thread_write_complete - write messages to device.
738 * 738 *
739 * @dev: the device structure. 739 * @dev: the device structure.
740 * @slots: free slots. 740 * @slots: free slots.
741 * @cb_pos: callback block. 741 * @cb: callback block.
742 * @cl: private data of the file object.
743 * @cmpl_list: complete list. 742 * @cmpl_list: complete list.
744 * 743 *
745 * returns 0, OK; otherwise, error. 744 * returns 0, OK; otherwise, error.
746 */ 745 */
747static int _mei_irq_thread_cmpl(struct mei_device *dev, s32 *slots, 746static int mei_irq_thread_write_complete(struct mei_device *dev, s32 *slots,
748 struct mei_cl_cb *cb_pos, 747 struct mei_cl_cb *cb, struct mei_cl_cb *cmpl_list)
749 struct mei_cl *cl,
750 struct mei_cl_cb *cmpl_list)
751{ 748{
752 struct mei_msg_hdr *mei_hdr; 749 struct mei_msg_hdr *mei_hdr;
750 struct mei_cl *cl = cb->cl;
751 size_t len = cb->request_buffer.size - cb->buf_idx;
752 size_t msg_slots = mei_data2slots(len);
753
754 mei_hdr = (struct mei_msg_hdr *)&dev->wr_msg_buf[0];
755 mei_hdr->host_addr = cl->host_client_id;
756 mei_hdr->me_addr = cl->me_client_id;
757 mei_hdr->reserved = 0;
753 758
754 if ((*slots * sizeof(u32)) >= (sizeof(struct mei_msg_hdr) + 759 if (*slots >= msg_slots) {
755 (cb_pos->request_buffer.size - cb_pos->buf_idx))) { 760 mei_hdr->length = len;
756 mei_hdr = (struct mei_msg_hdr *) &dev->wr_msg_buf[0];
757 mei_hdr->host_addr = cl->host_client_id;
758 mei_hdr->me_addr = cl->me_client_id;
759 mei_hdr->length = cb_pos->request_buffer.size - cb_pos->buf_idx;
760 mei_hdr->msg_complete = 1; 761 mei_hdr->msg_complete = 1;
761 mei_hdr->reserved = 0; 762 /* Split the message only if we can write the whole host buffer */
762 dev_dbg(&dev->pdev->dev, "cb_pos->request_buffer.size =%d"
763 "mei_hdr->msg_complete = %d\n",
764 cb_pos->request_buffer.size,
765 mei_hdr->msg_complete);
766 dev_dbg(&dev->pdev->dev, "cb_pos->buf_idx =%lu\n",
767 cb_pos->buf_idx);
768 dev_dbg(&dev->pdev->dev, "mei_hdr->length =%d\n",
769 mei_hdr->length);
770 *slots -= mei_data2slots(mei_hdr->length);
771 if (mei_write_message(dev, mei_hdr,
772 (unsigned char *)
773 (cb_pos->request_buffer.data +
774 cb_pos->buf_idx),
775 mei_hdr->length)) {
776 cl->status = -ENODEV;
777 list_move_tail(&cb_pos->list, &cmpl_list->list);
778 return -ENODEV;
779 } else {
780 if (mei_flow_ctrl_reduce(dev, cl))
781 return -ENODEV;
782 cl->status = 0;
783 cb_pos->buf_idx += mei_hdr->length;
784 list_move_tail(&cb_pos->list, &dev->write_waiting_list.list);
785 }
786 } else if (*slots == dev->hbuf_depth) { 763 } else if (*slots == dev->hbuf_depth) {
787 /* buffer is still empty */ 764 msg_slots = *slots;
788 mei_hdr = (struct mei_msg_hdr *) &dev->wr_msg_buf[0]; 765 len = (*slots * sizeof(u32)) - sizeof(struct mei_msg_hdr);
789 mei_hdr->host_addr = cl->host_client_id; 766 mei_hdr->length = len;
790 mei_hdr->me_addr = cl->me_client_id;
791 mei_hdr->length =
792 (*slots * sizeof(u32)) - sizeof(struct mei_msg_hdr);
793 mei_hdr->msg_complete = 0; 767 mei_hdr->msg_complete = 0;
794 mei_hdr->reserved = 0;
795 *slots -= mei_data2slots(mei_hdr->length);
796 if (mei_write_message(dev, mei_hdr,
797 (unsigned char *)
798 (cb_pos->request_buffer.data +
799 cb_pos->buf_idx),
800 mei_hdr->length)) {
801 cl->status = -ENODEV;
802 list_move_tail(&cb_pos->list, &cmpl_list->list);
803 return -ENODEV;
804 } else {
805 cb_pos->buf_idx += mei_hdr->length;
806 dev_dbg(&dev->pdev->dev,
807 "cb_pos->request_buffer.size =%d"
808 " mei_hdr->msg_complete = %d\n",
809 cb_pos->request_buffer.size,
810 mei_hdr->msg_complete);
811 dev_dbg(&dev->pdev->dev, "cb_pos->buf_idx =%lu\n",
812 cb_pos->buf_idx);
813 dev_dbg(&dev->pdev->dev, "mei_hdr->length =%d\n",
814 mei_hdr->length);
815 }
816 return -EMSGSIZE;
817 } else { 768 } else {
818 return -EBADMSG; 769 /* wait for next time the host buffer is empty */
770 return 0;
819 } 771 }
820 772
773 dev_dbg(&dev->pdev->dev, "buf: size = %d idx = %lu\n",
774 cb->request_buffer.size, cb->buf_idx);
775 dev_dbg(&dev->pdev->dev, "msg: len = %d complete = %d\n",
776 mei_hdr->length, mei_hdr->msg_complete);
777
778 *slots -= msg_slots;
779 if (mei_write_message(dev, mei_hdr,
780 cb->request_buffer.data + cb->buf_idx, len)) {
781 cl->status = -ENODEV;
782 list_move_tail(&cb->list, &cmpl_list->list);
783 return -ENODEV;
784 }
785
786 if (mei_flow_ctrl_reduce(dev, cl))
787 return -ENODEV;
788
789 cl->status = 0;
790 cb->buf_idx += mei_hdr->length;
791 if (mei_hdr->msg_complete)
792 list_move_tail(&cb->list, &dev->write_waiting_list.list);
793
821 return 0; 794 return 0;
822} 795}
823 796
@@ -1059,8 +1032,8 @@ static int mei_irq_thread_write_handler(struct mei_cl_cb *cmpl_list,
1059 cl->host_client_id); 1032 cl->host_client_id);
1060 continue; 1033 continue;
1061 } 1034 }
1062 ret = _mei_irq_thread_cmpl(dev, slots, pos, 1035 ret = mei_irq_thread_write_complete(dev, slots, pos,
1063 cl, cmpl_list); 1036 cmpl_list);
1064 if (ret) 1037 if (ret)
1065 return ret; 1038 return ret;
1066 1039