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>
This commit is contained in:
parent
7cb1ba9b67
commit
7bdf72d3d8
@ -135,7 +135,7 @@ int mei_write_message(struct mei_device *dev, struct mei_msg_hdr *header,
|
|||||||
empty_slots = mei_hbuf_empty_slots(dev);
|
empty_slots = mei_hbuf_empty_slots(dev);
|
||||||
dev_dbg(&dev->pdev->dev, "empty slots = %hu.\n", empty_slots);
|
dev_dbg(&dev->pdev->dev, "empty slots = %hu.\n", empty_slots);
|
||||||
|
|
||||||
dw_cnt = (length + sizeof(*header) + 3) / 4;
|
dw_cnt = mei_data2slots(length);
|
||||||
if (empty_slots < 0 || dw_cnt > empty_slots)
|
if (empty_slots < 0 || dw_cnt > empty_slots)
|
||||||
return -EIO;
|
return -EIO;
|
||||||
|
|
||||||
|
@ -50,6 +50,12 @@ static inline size_t mei_hbuf_max_data(const struct mei_device *dev)
|
|||||||
return dev->hbuf_depth * sizeof(u32) - sizeof(struct mei_msg_hdr);
|
return dev->hbuf_depth * sizeof(u32) - sizeof(struct mei_msg_hdr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* get slots (dwords) from a message length + header (bytes) */
|
||||||
|
static inline unsigned char mei_data2slots(size_t length)
|
||||||
|
{
|
||||||
|
return DIV_ROUND_UP(sizeof(struct mei_msg_hdr) + length, 4);
|
||||||
|
}
|
||||||
|
|
||||||
int mei_count_full_read_slots(struct mei_device *dev);
|
int mei_count_full_read_slots(struct mei_device *dev);
|
||||||
|
|
||||||
|
|
||||||
|
@ -267,8 +267,7 @@ static int _mei_irq_thread_iamthif_read(struct mei_device *dev, s32 *slots)
|
|||||||
+ sizeof(struct hbm_flow_control))) {
|
+ sizeof(struct hbm_flow_control))) {
|
||||||
return -EMSGSIZE;
|
return -EMSGSIZE;
|
||||||
}
|
}
|
||||||
*slots -= (sizeof(struct mei_msg_hdr) +
|
*slots -= mei_data2slots(sizeof(struct hbm_flow_control));
|
||||||
sizeof(struct hbm_flow_control) + 3) / 4;
|
|
||||||
if (mei_send_flow_control(dev, &dev->iamthif_cl)) {
|
if (mei_send_flow_control(dev, &dev->iamthif_cl)) {
|
||||||
dev_dbg(&dev->pdev->dev, "iamthif flow control failed\n");
|
dev_dbg(&dev->pdev->dev, "iamthif flow control failed\n");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
@ -302,8 +301,7 @@ static int _mei_irq_thread_close(struct mei_device *dev, s32 *slots,
|
|||||||
{
|
{
|
||||||
if ((*slots * sizeof(u32)) >= (sizeof(struct mei_msg_hdr) +
|
if ((*slots * sizeof(u32)) >= (sizeof(struct mei_msg_hdr) +
|
||||||
sizeof(struct hbm_client_disconnect_request))) {
|
sizeof(struct hbm_client_disconnect_request))) {
|
||||||
*slots -= (sizeof(struct mei_msg_hdr) +
|
*slots -= mei_data2slots(sizeof(struct hbm_client_disconnect_request));
|
||||||
sizeof(struct hbm_client_disconnect_request) + 3) / 4;
|
|
||||||
|
|
||||||
if (mei_disconnect(dev, cl)) {
|
if (mei_disconnect(dev, cl)) {
|
||||||
cl->status = 0;
|
cl->status = 0;
|
||||||
@ -841,8 +839,8 @@ static int _mei_irq_thread_read(struct mei_device *dev, s32 *slots,
|
|||||||
return -EBADMSG;
|
return -EBADMSG;
|
||||||
}
|
}
|
||||||
|
|
||||||
*slots -= (sizeof(struct mei_msg_hdr) +
|
*slots -= mei_data2slots(sizeof(struct hbm_flow_control));
|
||||||
sizeof(struct hbm_flow_control) + 3) / 4;
|
|
||||||
if (mei_send_flow_control(dev, cl)) {
|
if (mei_send_flow_control(dev, cl)) {
|
||||||
cl->status = -ENODEV;
|
cl->status = -ENODEV;
|
||||||
cb_pos->information = 0;
|
cb_pos->information = 0;
|
||||||
@ -874,8 +872,7 @@ static int _mei_irq_thread_ioctl(struct mei_device *dev, s32 *slots,
|
|||||||
if ((*slots * sizeof(u32)) >= (sizeof(struct mei_msg_hdr) +
|
if ((*slots * sizeof(u32)) >= (sizeof(struct mei_msg_hdr) +
|
||||||
sizeof(struct hbm_client_connect_request))) {
|
sizeof(struct hbm_client_connect_request))) {
|
||||||
cl->state = MEI_FILE_CONNECTING;
|
cl->state = MEI_FILE_CONNECTING;
|
||||||
*slots -= (sizeof(struct mei_msg_hdr) +
|
*slots -= mei_data2slots(sizeof(struct hbm_client_connect_request));
|
||||||
sizeof(struct hbm_client_connect_request) + 3) / 4;
|
|
||||||
if (mei_connect(dev, cl)) {
|
if (mei_connect(dev, cl)) {
|
||||||
cl->status = -ENODEV;
|
cl->status = -ENODEV;
|
||||||
cb_pos->information = 0;
|
cb_pos->information = 0;
|
||||||
@ -931,8 +928,7 @@ static int _mei_irq_thread_cmpl(struct mei_device *dev, s32 *slots,
|
|||||||
cb_pos->information);
|
cb_pos->information);
|
||||||
dev_dbg(&dev->pdev->dev, "mei_hdr->length =%d\n",
|
dev_dbg(&dev->pdev->dev, "mei_hdr->length =%d\n",
|
||||||
mei_hdr->length);
|
mei_hdr->length);
|
||||||
*slots -= (sizeof(struct mei_msg_hdr) +
|
*slots -= mei_data2slots(mei_hdr->length);
|
||||||
mei_hdr->length + 3) / 4;
|
|
||||||
if (mei_write_message(dev, mei_hdr,
|
if (mei_write_message(dev, mei_hdr,
|
||||||
(unsigned char *)
|
(unsigned char *)
|
||||||
(cb_pos->request_buffer.data +
|
(cb_pos->request_buffer.data +
|
||||||
@ -959,9 +955,7 @@ static int _mei_irq_thread_cmpl(struct mei_device *dev, s32 *slots,
|
|||||||
(*slots * sizeof(u32)) - sizeof(struct mei_msg_hdr);
|
(*slots * sizeof(u32)) - sizeof(struct mei_msg_hdr);
|
||||||
mei_hdr->msg_complete = 0;
|
mei_hdr->msg_complete = 0;
|
||||||
mei_hdr->reserved = 0;
|
mei_hdr->reserved = 0;
|
||||||
|
*slots -= mei_data2slots(mei_hdr->length);
|
||||||
(*slots) -= (sizeof(struct mei_msg_hdr) +
|
|
||||||
mei_hdr->length + 3) / 4;
|
|
||||||
if (mei_write_message(dev, mei_hdr,
|
if (mei_write_message(dev, mei_hdr,
|
||||||
(unsigned char *)
|
(unsigned char *)
|
||||||
(cb_pos->request_buffer.data +
|
(cb_pos->request_buffer.data +
|
||||||
@ -1020,8 +1014,7 @@ static int _mei_irq_thread_cmpl_iamthif(struct mei_device *dev, s32 *slots,
|
|||||||
mei_hdr->msg_complete = 1;
|
mei_hdr->msg_complete = 1;
|
||||||
mei_hdr->reserved = 0;
|
mei_hdr->reserved = 0;
|
||||||
|
|
||||||
*slots -= (sizeof(struct mei_msg_hdr) +
|
*slots -= mei_data2slots(mei_hdr->length);
|
||||||
mei_hdr->length + 3) / 4;
|
|
||||||
|
|
||||||
if (mei_write_message(dev, mei_hdr,
|
if (mei_write_message(dev, mei_hdr,
|
||||||
(dev->iamthif_msg_buf +
|
(dev->iamthif_msg_buf +
|
||||||
@ -1055,8 +1048,7 @@ static int _mei_irq_thread_cmpl_iamthif(struct mei_device *dev, s32 *slots,
|
|||||||
mei_hdr->msg_complete = 0;
|
mei_hdr->msg_complete = 0;
|
||||||
mei_hdr->reserved = 0;
|
mei_hdr->reserved = 0;
|
||||||
|
|
||||||
*slots -= (sizeof(struct mei_msg_hdr) +
|
*slots -= mei_data2slots(mei_hdr->length);
|
||||||
mei_hdr->length + 3) / 4;
|
|
||||||
|
|
||||||
if (mei_write_message(dev, mei_hdr,
|
if (mei_write_message(dev, mei_hdr,
|
||||||
(dev->iamthif_msg_buf +
|
(dev->iamthif_msg_buf +
|
||||||
@ -1266,12 +1258,9 @@ static int mei_irq_thread_write_handler(struct mei_io_list *cmpl_list,
|
|||||||
dev->wd_pending = false;
|
dev->wd_pending = false;
|
||||||
|
|
||||||
if (dev->wd_timeout)
|
if (dev->wd_timeout)
|
||||||
*slots -= (sizeof(struct mei_msg_hdr) +
|
*slots -= mei_data2slots(MEI_START_WD_DATA_SIZE);
|
||||||
MEI_START_WD_DATA_SIZE + 3) / 4;
|
|
||||||
else
|
else
|
||||||
*slots -= (sizeof(struct mei_msg_hdr) +
|
*slots -= mei_data2slots(MEI_START_WD_DATA_SIZE);
|
||||||
MEI_WD_PARAMS_SIZE + 3) / 4;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (dev->stop)
|
if (dev->stop)
|
||||||
|
Loading…
Reference in New Issue
Block a user