diff options
author | Tomas Winkler <tomas.winkler@intel.com> | 2012-07-04 12:24:52 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2012-07-10 17:58:35 -0400 |
commit | 7bdf72d3d8059a50214069ea4b87c2174645f40f (patch) | |
tree | b54edc0497ab402791422a50905e59fc49f71f51 /drivers/misc | |
parent | 7cb1ba9b679afe5fc335205fd6fb25fd3e51e33a (diff) |
mei: introduce mei_data2slots wrapper
Introduce mei_data2slots wrapper for sake of
readability. This wrapper close up the open code
for computing slots from a message length:
rond up dwords count from payload and header byte size
Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/misc')
-rw-r--r-- | drivers/misc/mei/interface.c | 2 | ||||
-rw-r--r-- | drivers/misc/mei/interface.h | 6 | ||||
-rw-r--r-- | drivers/misc/mei/interrupt.c | 33 |
3 files changed, 18 insertions, 23 deletions
diff --git a/drivers/misc/mei/interface.c b/drivers/misc/mei/interface.c index 88ada64c0b54..509c3957ff45 100644 --- a/drivers/misc/mei/interface.c +++ b/drivers/misc/mei/interface.c | |||
@@ -135,7 +135,7 @@ int mei_write_message(struct mei_device *dev, struct mei_msg_hdr *header, | |||
135 | empty_slots = mei_hbuf_empty_slots(dev); | 135 | empty_slots = mei_hbuf_empty_slots(dev); |
136 | dev_dbg(&dev->pdev->dev, "empty slots = %hu.\n", empty_slots); | 136 | dev_dbg(&dev->pdev->dev, "empty slots = %hu.\n", empty_slots); |
137 | 137 | ||
138 | dw_cnt = (length + sizeof(*header) + 3) / 4; | 138 | dw_cnt = mei_data2slots(length); |
139 | if (empty_slots < 0 || dw_cnt > empty_slots) | 139 | if (empty_slots < 0 || dw_cnt > empty_slots) |
140 | return -EIO; | 140 | return -EIO; |
141 | 141 | ||
diff --git a/drivers/misc/mei/interface.h b/drivers/misc/mei/interface.h index cd9b778e8dc5..fb5c7db4723b 100644 --- a/drivers/misc/mei/interface.h +++ b/drivers/misc/mei/interface.h | |||
@@ -50,6 +50,12 @@ static inline size_t mei_hbuf_max_data(const struct mei_device *dev) | |||
50 | return dev->hbuf_depth * sizeof(u32) - sizeof(struct mei_msg_hdr); | 50 | return dev->hbuf_depth * sizeof(u32) - sizeof(struct mei_msg_hdr); |
51 | } | 51 | } |
52 | 52 | ||
53 | /* get slots (dwords) from a message length + header (bytes) */ | ||
54 | static inline unsigned char mei_data2slots(size_t length) | ||
55 | { | ||
56 | return DIV_ROUND_UP(sizeof(struct mei_msg_hdr) + length, 4); | ||
57 | } | ||
58 | |||
53 | int mei_count_full_read_slots(struct mei_device *dev); | 59 | int mei_count_full_read_slots(struct mei_device *dev); |
54 | 60 | ||
55 | 61 | ||
diff --git a/drivers/misc/mei/interrupt.c b/drivers/misc/mei/interrupt.c index 4c1afcf6f4e9..92d762100268 100644 --- a/drivers/misc/mei/interrupt.c +++ b/drivers/misc/mei/interrupt.c | |||
@@ -267,8 +267,7 @@ static int _mei_irq_thread_iamthif_read(struct mei_device *dev, s32 *slots) | |||
267 | + sizeof(struct hbm_flow_control))) { | 267 | + sizeof(struct hbm_flow_control))) { |
268 | return -EMSGSIZE; | 268 | return -EMSGSIZE; |
269 | } | 269 | } |
270 | *slots -= (sizeof(struct mei_msg_hdr) + | 270 | *slots -= mei_data2slots(sizeof(struct hbm_flow_control)); |
271 | sizeof(struct hbm_flow_control) + 3) / 4; | ||
272 | if (mei_send_flow_control(dev, &dev->iamthif_cl)) { | 271 | if (mei_send_flow_control(dev, &dev->iamthif_cl)) { |
273 | dev_dbg(&dev->pdev->dev, "iamthif flow control failed\n"); | 272 | dev_dbg(&dev->pdev->dev, "iamthif flow control failed\n"); |
274 | return -EIO; | 273 | return -EIO; |
@@ -302,8 +301,7 @@ static int _mei_irq_thread_close(struct mei_device *dev, s32 *slots, | |||
302 | { | 301 | { |
303 | if ((*slots * sizeof(u32)) >= (sizeof(struct mei_msg_hdr) + | 302 | if ((*slots * sizeof(u32)) >= (sizeof(struct mei_msg_hdr) + |
304 | sizeof(struct hbm_client_disconnect_request))) { | 303 | sizeof(struct hbm_client_disconnect_request))) { |
305 | *slots -= (sizeof(struct mei_msg_hdr) + | 304 | *slots -= mei_data2slots(sizeof(struct hbm_client_disconnect_request)); |
306 | sizeof(struct hbm_client_disconnect_request) + 3) / 4; | ||
307 | 305 | ||
308 | if (mei_disconnect(dev, cl)) { | 306 | if (mei_disconnect(dev, cl)) { |
309 | cl->status = 0; | 307 | cl->status = 0; |
@@ -841,8 +839,8 @@ static int _mei_irq_thread_read(struct mei_device *dev, s32 *slots, | |||
841 | return -EBADMSG; | 839 | return -EBADMSG; |
842 | } | 840 | } |
843 | 841 | ||
844 | *slots -= (sizeof(struct mei_msg_hdr) + | 842 | *slots -= mei_data2slots(sizeof(struct hbm_flow_control)); |
845 | sizeof(struct hbm_flow_control) + 3) / 4; | 843 | |
846 | if (mei_send_flow_control(dev, cl)) { | 844 | if (mei_send_flow_control(dev, cl)) { |
847 | cl->status = -ENODEV; | 845 | cl->status = -ENODEV; |
848 | cb_pos->information = 0; | 846 | cb_pos->information = 0; |
@@ -874,8 +872,7 @@ static int _mei_irq_thread_ioctl(struct mei_device *dev, s32 *slots, | |||
874 | if ((*slots * sizeof(u32)) >= (sizeof(struct mei_msg_hdr) + | 872 | if ((*slots * sizeof(u32)) >= (sizeof(struct mei_msg_hdr) + |
875 | sizeof(struct hbm_client_connect_request))) { | 873 | sizeof(struct hbm_client_connect_request))) { |
876 | cl->state = MEI_FILE_CONNECTING; | 874 | cl->state = MEI_FILE_CONNECTING; |
877 | *slots -= (sizeof(struct mei_msg_hdr) + | 875 | *slots -= mei_data2slots(sizeof(struct hbm_client_connect_request)); |
878 | sizeof(struct hbm_client_connect_request) + 3) / 4; | ||
879 | if (mei_connect(dev, cl)) { | 876 | if (mei_connect(dev, cl)) { |
880 | cl->status = -ENODEV; | 877 | cl->status = -ENODEV; |
881 | cb_pos->information = 0; | 878 | cb_pos->information = 0; |
@@ -931,8 +928,7 @@ static int _mei_irq_thread_cmpl(struct mei_device *dev, s32 *slots, | |||
931 | cb_pos->information); | 928 | cb_pos->information); |
932 | dev_dbg(&dev->pdev->dev, "mei_hdr->length =%d\n", | 929 | dev_dbg(&dev->pdev->dev, "mei_hdr->length =%d\n", |
933 | mei_hdr->length); | 930 | mei_hdr->length); |
934 | *slots -= (sizeof(struct mei_msg_hdr) + | 931 | *slots -= mei_data2slots(mei_hdr->length); |
935 | mei_hdr->length + 3) / 4; | ||
936 | if (mei_write_message(dev, mei_hdr, | 932 | if (mei_write_message(dev, mei_hdr, |
937 | (unsigned char *) | 933 | (unsigned char *) |
938 | (cb_pos->request_buffer.data + | 934 | (cb_pos->request_buffer.data + |
@@ -959,9 +955,7 @@ static int _mei_irq_thread_cmpl(struct mei_device *dev, s32 *slots, | |||
959 | (*slots * sizeof(u32)) - sizeof(struct mei_msg_hdr); | 955 | (*slots * sizeof(u32)) - sizeof(struct mei_msg_hdr); |
960 | mei_hdr->msg_complete = 0; | 956 | mei_hdr->msg_complete = 0; |
961 | mei_hdr->reserved = 0; | 957 | mei_hdr->reserved = 0; |
962 | 958 | *slots -= mei_data2slots(mei_hdr->length); | |
963 | (*slots) -= (sizeof(struct mei_msg_hdr) + | ||
964 | mei_hdr->length + 3) / 4; | ||
965 | if (mei_write_message(dev, mei_hdr, | 959 | if (mei_write_message(dev, mei_hdr, |
966 | (unsigned char *) | 960 | (unsigned char *) |
967 | (cb_pos->request_buffer.data + | 961 | (cb_pos->request_buffer.data + |
@@ -1020,8 +1014,7 @@ static int _mei_irq_thread_cmpl_iamthif(struct mei_device *dev, s32 *slots, | |||
1020 | mei_hdr->msg_complete = 1; | 1014 | mei_hdr->msg_complete = 1; |
1021 | mei_hdr->reserved = 0; | 1015 | mei_hdr->reserved = 0; |
1022 | 1016 | ||
1023 | *slots -= (sizeof(struct mei_msg_hdr) + | 1017 | *slots -= mei_data2slots(mei_hdr->length); |
1024 | mei_hdr->length + 3) / 4; | ||
1025 | 1018 | ||
1026 | if (mei_write_message(dev, mei_hdr, | 1019 | if (mei_write_message(dev, mei_hdr, |
1027 | (dev->iamthif_msg_buf + | 1020 | (dev->iamthif_msg_buf + |
@@ -1055,8 +1048,7 @@ static int _mei_irq_thread_cmpl_iamthif(struct mei_device *dev, s32 *slots, | |||
1055 | mei_hdr->msg_complete = 0; | 1048 | mei_hdr->msg_complete = 0; |
1056 | mei_hdr->reserved = 0; | 1049 | mei_hdr->reserved = 0; |
1057 | 1050 | ||
1058 | *slots -= (sizeof(struct mei_msg_hdr) + | 1051 | *slots -= mei_data2slots(mei_hdr->length); |
1059 | mei_hdr->length + 3) / 4; | ||
1060 | 1052 | ||
1061 | if (mei_write_message(dev, mei_hdr, | 1053 | if (mei_write_message(dev, mei_hdr, |
1062 | (dev->iamthif_msg_buf + | 1054 | (dev->iamthif_msg_buf + |
@@ -1266,12 +1258,9 @@ static int mei_irq_thread_write_handler(struct mei_io_list *cmpl_list, | |||
1266 | dev->wd_pending = false; | 1258 | dev->wd_pending = false; |
1267 | 1259 | ||
1268 | if (dev->wd_timeout) | 1260 | if (dev->wd_timeout) |
1269 | *slots -= (sizeof(struct mei_msg_hdr) + | 1261 | *slots -= mei_data2slots(MEI_START_WD_DATA_SIZE); |
1270 | MEI_START_WD_DATA_SIZE + 3) / 4; | ||
1271 | else | 1262 | else |
1272 | *slots -= (sizeof(struct mei_msg_hdr) + | 1263 | *slots -= mei_data2slots(MEI_START_WD_DATA_SIZE); |
1273 | MEI_WD_PARAMS_SIZE + 3) / 4; | ||
1274 | |||
1275 | } | 1264 | } |
1276 | } | 1265 | } |
1277 | if (dev->stop) | 1266 | if (dev->stop) |