Skip to content

Commit

Permalink
mei: don't query HCSR for host buffer depth
Browse files Browse the repository at this point in the history
1. We record host (write) buffer depth during reset
 so we don't need to query HCSR register later on.
 The host buffer depth doesn't change after the reset
2. Use mei_hbuf_max_data function to compute payload size in bytes

Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Tomas Winkler authored and Greg Kroah-Hartman committed Jun 26, 2012
1 parent 21c66d1 commit 24aadc8
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 21 deletions.
3 changes: 3 additions & 0 deletions drivers/misc/mei/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ int mei_hw_init(struct mei_device *dev)
if ((dev->host_hw_state & H_IS) == H_IS)
mei_reg_write(dev, H_CSR, dev->host_hw_state);

/* Doesn't change in runtime */
dev->hbuf_depth = (dev->host_hw_state & H_CBD) >> 24;

dev->recvd_msg = false;
dev_dbg(&dev->pdev->dev, "reset in start the mei device.\n");

Expand Down
7 changes: 3 additions & 4 deletions drivers/misc/mei/interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,14 @@ int mei_host_buffer_is_empty(struct mei_device *dev)
*/
int mei_count_empty_write_slots(struct mei_device *dev)
{
unsigned char buffer_depth, filled_slots, empty_slots;
unsigned char filled_slots, empty_slots;

dev->host_hw_state = mei_hcsr_read(dev);
buffer_depth = (unsigned char) ((dev->host_hw_state & H_CBD) >> 24);
filled_slots = _host_get_filled_slots(dev);
empty_slots = buffer_depth - filled_slots;
empty_slots = dev->hbuf_depth - filled_slots;

/* check for overflow */
if (filled_slots > buffer_depth)
if (filled_slots > dev->hbuf_depth)
return -EOVERFLOW;

return empty_slots;
Expand Down
6 changes: 6 additions & 0 deletions drivers/misc/mei/interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ int mei_count_empty_write_slots(struct mei_device *dev);

int mei_flow_ctrl_creds(struct mei_device *dev, struct mei_cl *cl);

static inline size_t mei_hbuf_max_data(const struct mei_device *dev)
{
return dev->hbuf_depth * sizeof(u32) - sizeof(struct mei_msg_hdr);
}


int mei_wd_send(struct mei_device *dev);
int mei_wd_stop(struct mei_device *dev, bool preserve);
int mei_wd_host_init(struct mei_device *dev);
Expand Down
6 changes: 3 additions & 3 deletions drivers/misc/mei/interrupt.c
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,7 @@ static int _mei_irq_thread_cmpl(struct mei_device *dev, s32 *slots,
list_move_tail(&cb_pos->cb_list,
&dev->write_waiting_list.mei_cb.cb_list);
}
} else if (*slots == ((dev->host_hw_state & H_CBD) >> 24)) {
} else if (*slots == dev->hbuf_depth) {
/* buffer is still empty */
mei_hdr = (struct mei_msg_hdr *) &dev->wr_msg_buf[0];
mei_hdr->host_addr = cl->host_client_id;
Expand Down Expand Up @@ -1046,8 +1046,8 @@ static int _mei_irq_thread_cmpl_iamthif(struct mei_device *dev, s32 *slots,
&dev->write_waiting_list.mei_cb.cb_list);

}
} else if (*slots == ((dev->host_hw_state & H_CBD) >> 24)) {
/* buffer is still empty */
} else if (*slots == dev->hbuf_depth) {
/* buffer is still empty */
mei_hdr = (struct mei_msg_hdr *) &dev->wr_msg_buf[0];
mei_hdr->host_addr = cl->host_client_id;
mei_hdr->me_addr = cl->me_client_id;
Expand Down
8 changes: 2 additions & 6 deletions drivers/misc/mei/iorw.c
Original file line number Diff line number Diff line change
Expand Up @@ -481,12 +481,8 @@ int amthi_write(struct mei_device *dev, struct mei_cl_cb *cb)
if (ret && dev->mei_host_buffer_is_empty) {
ret = 0;
dev->mei_host_buffer_is_empty = false;
if (cb->request_buffer.size >
(((dev->host_hw_state & H_CBD) >> 24) * sizeof(u32))
-sizeof(struct mei_msg_hdr)) {
mei_hdr.length =
(((dev->host_hw_state & H_CBD) >> 24) *
sizeof(u32)) - sizeof(struct mei_msg_hdr);
if (cb->request_buffer.size > mei_hbuf_max_data(dev)) {
mei_hdr.length = mei_hbuf_max_data(dev);
mei_hdr.msg_complete = 0;
} else {
mei_hdr.length = cb->request_buffer.size;
Expand Down
9 changes: 2 additions & 7 deletions drivers/misc/mei/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -714,13 +714,8 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf,
if (rets && dev->mei_host_buffer_is_empty) {
rets = 0;
dev->mei_host_buffer_is_empty = false;
if (length > ((((dev->host_hw_state & H_CBD) >> 24) *
sizeof(u32)) - sizeof(struct mei_msg_hdr))) {

mei_hdr.length =
(((dev->host_hw_state & H_CBD) >> 24) *
sizeof(u32)) -
sizeof(struct mei_msg_hdr);
if (length > mei_hbuf_max_data(dev)) {
mei_hdr.length = mei_hbuf_max_data(dev);
mei_hdr.msg_complete = 0;
} else {
mei_hdr.length = length;
Expand Down
6 changes: 5 additions & 1 deletion drivers/misc/mei/mei_dev.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,10 @@ struct mei_io_list {
struct mei_cl_cb mei_cb;
};

/* MEI private device struct */
/**
* struct mei_deive - MEI private device struct
* @hbuf_depth - depth of host(write) buffer
*/
struct mei_device {
struct pci_dev *pdev; /* pointer to pci device struct */
/*
Expand Down Expand Up @@ -205,6 +208,7 @@ struct mei_device {
*/
u32 host_hw_state;
u32 me_hw_state;
u8 hbuf_depth;
/*
* waiting queue for receive message from FW
*/
Expand Down

0 comments on commit 24aadc8

Please sign in to comment.