mei: amthif fixes and cleanups
Subsystems (2)
cover mei: amthif fixes and cleanups
Amthif client has special treatment in the driver, this series provides more reuse of the mei generic consturcts and reducing amount of the special code.
Alexander Usyskin (7):
mei: amthif: drop READ_COMPLETE state
mei: amthif: fix request cancel
mei: amthif: drop iamthif_current_cb
mei: amthif: enable poll for async events
mei: amthif: drop mei_amthif_send_cmd
mei: amthif: use mei_cl_alloc_cb for allocating cbs
mei: drop mei_io_cb_alloc_buf
drivers/misc/mei/amthif.c | 200 +++++++++++++------------------------------ drivers/misc/mei/client.c | 32 ++----- drivers/misc/mei/client.h | 2 - drivers/misc/mei/interrupt.c | 5 -- drivers/misc/mei/main.c | 10 +-- drivers/misc/mei/mei_dev.h | 7 +- 6 files changed, 71 insertions(+), 185 deletions(-)
Signature · 1 line
2.5.5
PATCH 1/7 mei: amthif: drop READ_COMPLETE state
From: Alexander Usyskin <[email protected]>
AMTHIF code now uses read completed queue to store replies from the FW. It is possible to send the next request as soon as a read from the FW is completed. With these changes we don't need the READ_COMPLETE state.
--- drivers/misc/mei/amthif.c | 34 +++++++++++----------------------- drivers/misc/mei/main.c | 2 +- drivers/misc/mei/mei_dev.h | 5 +---- 3 files changed, 13 insertions(+), 28 deletions(-)
drivers/misc/mei/amthif.c +11 -23
@@ -299,8 +299,7 @@ int mei_amthif_write(struct mei_cl *cl, struct mei_cl_cb *cb)/* * The previous request is still in processing, queue this one. */ -if (dev->iamthif_state >MEI_IAMTHIF_IDLE && - dev->iamthif_state <MEI_IAMTHIF_READ_COMPLETE ) +if (dev->iamthif_state !=MEI_IAMTHIF_IDLE )return 0 ;return mei_amthif_run_next_cmd (dev);
@@ -309,7 +308,6 @@ int mei_amthif_write(struct mei_cl *cl, struct mei_cl_cb *cb)/** * mei_amthif_poll - the amthif poll function * -* @dev: the device structure * @file: pointer to file structure * @wait: pointer to poll_table structure *
@@ -317,26 +315,19 @@ int mei_amthif_write(struct mei_cl *cl, struct mei_cl_cb *cb)* * Locking: called under "dev->device_lock" lock */ - -unsigned int mei_amthif_poll (struct mei_device *dev, -struct file *file,poll_table *wait) +unsigned int mei_amthif_poll (struct file *file,poll_table *wait) { +struct mei_cl *cl = file->private_data; +struct mei_cl_cb *cb =mei_cl_read_cb (cl, file);unsigned int mask =0 ; -poll_wait (file, &dev->iamthif_cl.rx_wait, wait); - -if (dev->iamthif_state ==MEI_IAMTHIF_READ_COMPLETE && - dev->iamthif_fp == file) { - +poll_wait (file, &cl->rx_wait, wait); +if (cb) mask |=POLLIN |POLLRDNORM ; -mei_amthif_run_next_cmd (dev); - }return mask; } - -/** * mei_amthif_irq_write - write iamthif command in irq thread context. *
@@ -393,7 +384,6 @@ int mei_amthif_irq_read_msg(struct mei_cl *cl,return 0 ;dev_dbg (dev->dev,"completed amthif read.\n " ); - dev->iamthif_current_cb =NULL ; dev->iamthif_stall_timer =0 ;return 0 ;
@@ -425,14 +415,16 @@ void mei_amthif_complete(struct mei_cl *cl, struct mei_cl_cb *cb) }if (!dev->iamthif_canceled) { - dev->iamthif_state =MEI_IAMTHIF_READ_COMPLETE ; - dev->iamthif_stall_timer =0 ;list_add_tail (&cb->list, &cl->rd_completed);dev_dbg (dev->dev,"amthif read completed\n" ); }else { -mei_amthif_run_next_cmd (dev); +mei_io_cb_free (cb); } + dev->iamthif_current_cb =NULL ; + dev->iamthif_stall_timer =0 ; +mei_amthif_run_next_cmd (dev); +dev_dbg (dev->dev,"completing amthif call back.\n" );wake_up_interruptible (&cl->rx_wait); }
@@ -539,10 +531,6 @@ int mei_amthif_release(struct mei_device *dev, struct file *file)dev_dbg (dev->dev,"amthif canceled iamthif state %d\n" , dev->iamthif_state); dev->iamthif_canceled = true; -if (dev->iamthif_state ==MEI_IAMTHIF_READ_COMPLETE ) { -dev_dbg (dev->dev,"run next amthif iamthif cb\n" ); -mei_amthif_run_next_cmd (dev); - } }if (mei_clear_lists (dev, file))
drivers/misc/mei/main.c +1 -1
@@ -610,7 +610,7 @@ static unsigned int mei_poll(struct file *file, poll_table *wait) }if (cl == &dev->iamthif_cl) { - mask =mei_amthif_poll (dev, file, wait); + mask =mei_amthif_poll (file, wait); goto out; }
drivers/misc/mei/mei_dev.h +1 -4
@@ -80,9 +80,7 @@ const char *mei_dev_state_str(int state);enum iamthif_states {MEI_IAMTHIF_IDLE ,MEI_IAMTHIF_WRITING , -MEI_IAMTHIF_FLOW_CONTROL ,MEI_IAMTHIF_READING , -MEI_IAMTHIF_READ_COMPLETE };enum mei_file_transaction_states {
@@ -572,8 +570,7 @@ int mei_amthif_host_init(struct mei_device *dev, struct mei_me_client *me_cl);int mei_amthif_read (struct mei_device *dev,struct file *file,char __user *ubuf,size_t length,loff_t *offset); -unsigned int mei_amthif_poll (struct mei_device *dev, -struct file *file,poll_table *wait); +unsigned int mei_amthif_poll (struct file *file,poll_table *wait);int mei_amthif_release (struct mei_device *dev,struct file *file);
Signature · 1 line
2.5.5
PATCH 2/7 mei: amthif: fix request cancel
In reply to Tomas WinklerFrom: Alexander Usyskin <[email protected]>
Currently, all requests cancelled by the user are immediately removed from the queues. Such removal can cause unexpected behavior in the case when a request is partially written or a reply is received after the request is cancelled. To resolve this a request is always fully processed and the result is discarded in case the request was canceled. This completes the partial fix in commit:
9d04ee1 ("mei: amthif: discard not read messages")
--- drivers/misc/mei/amthif.c | 111 +++++++++++++++---------------------------- drivers/misc/mei/interrupt.c | 2 - 2 files changed, 38 insertions(+), 75 deletions(-)
drivers/misc/mei/amthif.c +38 -73
@@ -399,34 +399,44 @@ void mei_amthif_complete(struct mei_cl *cl, struct mei_cl_cb *cb) {struct mei_device *dev = cl->dev; -if (cb->fop_type ==MEI_FOP_WRITE ) { +dev_dbg (dev->dev,"completing amthif call back.\n" ); +switch (cb->fop_type) { +case MEI_FOP_WRITE :if (!cb->status) { dev->iamthif_stall_timer =MEI_IAMTHIF_STALL_TIMER ;mei_io_cb_free (cb);return ; } -/* -* in case of error enqueue the write cb to complete read list -* so it can be propagated to the reader -*/ -list_add_tail (&cb->list, &cl->rd_completed); -wake_up_interruptible (&cl->rx_wait); -return ; - } + dev->iamthif_current_cb =NULL ; + dev->iamthif_state =MEI_IAMTHIF_IDLE ; + dev->iamthif_fp =NULL ; +if (!dev->iamthif_canceled) { +/* +* in case of error enqueue the write cb to complete +* read list so it can be propagated to the reader +*/ +list_add_tail (&cb->list, &cl->rd_completed); +wake_up_interruptible (&cl->rx_wait); + }else { +mei_io_cb_free (cb); + } +break ; +case MEI_FOP_READ : +if (!dev->iamthif_canceled) { +list_add_tail (&cb->list, &cl->rd_completed); +dev_dbg (dev->dev,"amthif read completed\n" ); +wake_up_interruptible (&cl->rx_wait); + }else { +mei_io_cb_free (cb); + } -if (!dev->iamthif_canceled) { -list_add_tail (&cb->list, &cl->rd_completed); -dev_dbg (dev->dev,"amthif read completed\n" ); - }else { -mei_io_cb_free (cb); + dev->iamthif_current_cb =NULL ; + dev->iamthif_stall_timer =0 ; +mei_amthif_run_next_cmd (dev); +break ; +default : +WARN_ON (1 ); } - - dev->iamthif_current_cb =NULL ; - dev->iamthif_stall_timer =0 ; -mei_amthif_run_next_cmd (dev); - -dev_dbg (dev->dev,"completing amthif call back.\n" ); -wake_up_interruptible (&cl->rx_wait); }/**
@@ -439,32 +449,15 @@ void mei_amthif_complete(struct mei_cl *cl, struct mei_cl_cb *cb)* * mei_clear_list is called to clear resources associated with file * when application calls close function or Ctrl-C was pressed -* -* Return: true if callback removed from the list, false otherwise */ -static bool mei_clear_list (struct mei_device *dev, +static void mei_clear_list (struct mei_device *dev,const struct file *file,struct list_head *mei_cb_list) { -struct mei_cl *cl = &dev->iamthif_cl;struct mei_cl_cb *cb, *next; -bool removed = false; - -/* list all list member */ -list_for_each_entry_safe (cb, next, mei_cb_list, list) { -/* check if list member associated with a file */ -if (file == cb->fp) { -/* check if cb equal to current iamthif cb */ -if (dev->iamthif_current_cb == cb) { - dev->iamthif_current_cb =NULL ; -/* send flow control to iamthif client */ -mei_hbm_cl_flow_control_req (dev, cl); - } -/* free all allocated buffers */ + +list_for_each_entry_safe (cb, next, mei_cb_list, list) +if (file == cb->fp)mei_io_cb_free (cb); - removed = true; - } - } -return removed; }/**
@@ -475,41 +468,14 @@ static bool mei_clear_list(struct mei_device *dev,* * mei_clear_lists is called to clear resources associated with file * when application calls close function or Ctrl-C was pressed -* -* Return: true if callback removed from the list, false otherwise */ -static bool mei_clear_lists (struct mei_device *dev,const struct file *file) +static void mei_clear_lists (struct mei_device *dev,const struct file *file) { -bool removed = false;struct mei_cl *cl = &dev->iamthif_cl; -/* remove callbacks associated with a file */ mei_clear_list (dev, file, &dev->amthif_cmd_list.list); -if (mei_clear_list (dev, file, &cl->rd_completed)) - removed = true; - +mei_clear_list (dev, file, &cl->rd_completed);mei_clear_list (dev, file, &dev->ctrl_rd_list.list); - -if (mei_clear_list (dev, file, &dev->ctrl_wr_list.list)) - removed = true; - -if (mei_clear_list (dev, file, &dev->write_waiting_list.list)) - removed = true; - -if (mei_clear_list (dev, file, &dev->write_list.list)) - removed = true; - -/* check if iamthif_current_cb not NULL */ -if (dev->iamthif_current_cb && !removed) { -/* check file and iamthif current cb association */ -if (dev->iamthif_current_cb->fp == file) { -/* remove cb */ -mei_io_cb_free (dev->iamthif_current_cb); - dev->iamthif_current_cb =NULL ; - removed = true; - } - } -return removed; }/**
@@ -533,8 +499,7 @@ int mei_amthif_release(struct mei_device *dev, struct file *file) dev->iamthif_canceled = true; } -if (mei_clear_lists (dev, file)) - dev->iamthif_state =MEI_IAMTHIF_IDLE ; +mei_clear_lists (dev, file);return 0 ; }
drivers/misc/mei/interrupt.c +0 -2
@@ -514,8 +514,6 @@ void mei_timer(struct work_struct *work)if (--dev->iamthif_stall_timer ==0 ) {dev_err (dev->dev,"timer: amthif hanged.\n" );mei_reset (dev); - dev->iamthif_canceled = false; - dev->iamthif_state =MEI_IAMTHIF_IDLE ;mei_io_cb_free (dev->iamthif_current_cb); dev->iamthif_current_cb =NULL ;
Signature · 1 line
2.5.5
PATCH 3/7 mei: amthif: drop iamthif_current_cb
In reply to Tomas WinklerFrom: Alexander Usyskin <[email protected]>
iamthif_current_cb was used in request cancel in amthif code. Now a canceled request is discarded only at the end of the processing and the variable lost its purpose and can be safely removed.
--- drivers/misc/mei/amthif.c | 5 ----- drivers/misc/mei/interrupt.c | 3 --- drivers/misc/mei/mei_dev.h | 2 -- 3 files changed, 10 deletions(-)
drivers/misc/mei/amthif.c +0 -5
@@ -47,7 +47,6 @@ const uuid_le mei_amthif_guid = UUID_LE(0x12f80028, 0xb4b7, 0x4b2d,void mei_amthif_reset_params (struct mei_device *dev) {/* reset iamthif parameters. */ - dev->iamthif_current_cb =NULL ; dev->iamthif_canceled = false; dev->iamthif_state =MEI_IAMTHIF_IDLE ; dev->iamthif_stall_timer =0 ;
@@ -213,7 +212,6 @@ static int mei_amthif_read_start(struct mei_cl *cl, const struct file *file) dev->iamthif_state =MEI_IAMTHIF_READING ; dev->iamthif_fp = cb->fp; - dev->iamthif_current_cb = cb;return 0 ; err:
@@ -240,7 +238,6 @@ static int mei_amthif_send_cmd(struct mei_cl *cl, struct mei_cl_cb *cb) dev = cl->dev; dev->iamthif_state =MEI_IAMTHIF_WRITING ; - dev->iamthif_current_cb = cb; dev->iamthif_fp = cb->fp; dev->iamthif_canceled = false;
@@ -407,7 +404,6 @@ void mei_amthif_complete(struct mei_cl *cl, struct mei_cl_cb *cb)mei_io_cb_free (cb);return ; } - dev->iamthif_current_cb =NULL ; dev->iamthif_state =MEI_IAMTHIF_IDLE ; dev->iamthif_fp =NULL ;if (!dev->iamthif_canceled) {
@@ -430,7 +426,6 @@ void mei_amthif_complete(struct mei_cl *cl, struct mei_cl_cb *cb)mei_io_cb_free (cb); } - dev->iamthif_current_cb =NULL ; dev->iamthif_stall_timer =0 ;mei_amthif_run_next_cmd (dev);break ;
drivers/misc/mei/interrupt.c +0 -3
@@ -515,9 +515,6 @@ void mei_timer(struct work_struct *work)dev_err (dev->dev,"timer: amthif hanged.\n" );mei_reset (dev); -mei_io_cb_free (dev->iamthif_current_cb); - dev->iamthif_current_cb =NULL ; - dev->iamthif_fp =NULL ;mei_amthif_run_next_cmd (dev); }
drivers/misc/mei/mei_dev.h +0 -2
@@ -400,7 +400,6 @@ const char *mei_pg_state_str(enum mei_pg_state state);* @amthif_cmd_list : amthif list for cmd waiting * @iamthif_fp : file for current amthif operation * @iamthif_cl : amthif host client -* @iamthif_current_cb : amthif current operation callback * @iamthif_open_count : number of opened amthif connections * @iamthif_stall_timer : timer to detect amthif hang * @iamthif_state : amthif processor state
@@ -485,7 +484,6 @@ struct mei_device {/* driver managed amthif list for reading completed amthif cmd data */ const struct file *iamthif_fp;struct mei_cl iamthif_cl; -struct mei_cl_cb *iamthif_current_cb;long iamthif_open_count;u32 iamthif_stall_timer;enum iamthif_states iamthif_state;
Signature · 1 line
2.5.5
PATCH 4/7 mei: amthif: enable poll for async events
In reply to Tomas WinklerFrom: Alexander Usyskin <[email protected]>
Currently the poll function is bailing early for amthif client and ignores requests for async events notifications.
Move async event processing before amthif to enable async events notifications on amthif client.
--- drivers/misc/mei/main.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/misc/mei/main.c +5 -5
@@ -609,17 +609,17 @@ static unsigned int mei_poll(struct file *file, poll_table *wait) goto out; } -if (cl == &dev->iamthif_cl) { - mask =mei_amthif_poll (file, wait); - goto out; - } -if (notify_en) {poll_wait (file, &cl->ev_wait, wait);if (cl->notify_ev) mask |=POLLPRI ; } +if (cl == &dev->iamthif_cl) { + mask |=mei_amthif_poll (file, wait); + goto out; + } +if (req_events & (POLLIN |POLLRDNORM )) {poll_wait (file, &cl->rx_wait, wait);
Signature · 1 line
2.5.5
PATCH 5/7 mei: amthif: drop mei_amthif_send_cmd
In reply to Tomas WinklerFrom: Alexander Usyskin <[email protected]>
Incorporate the mei_amthif_send_cmd code into its only caller:mei_amthif_run_next_cmd
--- drivers/misc/mei/amthif.c | 52 +++++++++++++++-------------------------------- 1 file changed, 16 insertions(+), 36 deletions(-)
drivers/misc/mei/amthif.c +16 -36
@@ -220,38 +220,6 @@ err: }/** -* mei_amthif_send_cmd - send amthif command to the ME -* -* @cl: the host client -* @cb: mei call back struct -* -* Return: 0 on success, <0 on failure. -*/ -static int mei_amthif_send_cmd (struct mei_cl *cl,struct mei_cl_cb *cb) -{ -struct mei_device *dev; -int ret; - -if (!cl->dev || !cb) -return -ENODEV ; - - dev = cl->dev; - - dev->iamthif_state =MEI_IAMTHIF_WRITING ; - dev->iamthif_fp = cb->fp; - dev->iamthif_canceled = false; - - ret =mei_cl_write (cl, cb, false); -if (ret <0 ) -return ret; - -if (cb->completed) - cb->status =mei_amthif_read_start (cl, cb->fp); - -return 0 ; -} - -/** * mei_amthif_run_next_cmd - send next amt command from queue * * @dev: the device structure
@@ -262,20 +230,32 @@ int mei_amthif_run_next_cmd(struct mei_device *dev) {struct mei_cl *cl = &dev->iamthif_cl;struct mei_cl_cb *cb; +int ret; dev->iamthif_canceled = false; - dev->iamthif_state =MEI_IAMTHIF_IDLE ; - dev->iamthif_fp =NULL ;dev_dbg (dev->dev,"complete amthif cmd_list cb.\n" ); cb =list_first_entry_or_null (&dev->amthif_cmd_list.list,typeof (*cb), list); -if (!cb) +if (!cb) { + dev->iamthif_state =MEI_IAMTHIF_IDLE ; + dev->iamthif_fp =NULL ;return 0 ; + }list_del_init (&cb->list); -return mei_amthif_send_cmd (cl, cb); + dev->iamthif_state =MEI_IAMTHIF_WRITING ; + dev->iamthif_fp = cb->fp; + + ret =mei_cl_write (cl, cb, false); +if (ret <0 ) +return ret; + +if (cb->completed) + cb->status =mei_amthif_read_start (cl, cb->fp); + +return 0 ; }/**
Signature · 1 line
2.5.5
PATCH 6/7 mei: amthif: use mei_cl_alloc_cb for allocating cbs
In reply to Tomas WinklerFrom: Alexander Usyskin <[email protected]>
Use mei_cl_alloc_cb wrapper instead of open code steps
--- drivers/misc/mei/amthif.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-)
drivers/misc/mei/amthif.c +3 -13
@@ -196,17 +196,10 @@ static int mei_amthif_read_start(struct mei_cl *cl, const struct file *file) {struct mei_device *dev = cl->dev;struct mei_cl_cb *cb; -int rets; - - cb =mei_io_cb_init (cl,MEI_FOP_READ , file); -if (!cb) { - rets = -ENOMEM ; - goto err; - } - rets =mei_io_cb_alloc_buf (cb,mei_cl_mtu (cl)); -if (rets) - goto err; + cb =mei_cl_alloc_cb (cl,mei_cl_mtu (cl),MEI_FOP_READ , file); +if (!cb) +return -ENOMEM ;list_add_tail (&cb->list, &dev->ctrl_wr_list.list);
@@ -214,9 +207,6 @@ static int mei_amthif_read_start(struct mei_cl *cl, const struct file *file) dev->iamthif_fp = cb->fp;return 0 ; -err: -mei_io_cb_free (cb); -return rets; }/**
Signature · 1 line
2.5.5
PATCH 7/7 mei: drop mei_io_cb_alloc_buf
In reply to Tomas WinklerFrom: Alexander Usyskin <[email protected]>
mei_io_cb_alloc_buf have a single caller :mei_cl_alloc_cb. After amthif stopped using it, the code can be integrated into the caller and the function can be dropped.
--- drivers/misc/mei/client.c | 32 ++++++-------------------------- drivers/misc/mei/client.h | 2 -- 2 files changed, 6 insertions(+), 28 deletions(-)
drivers/misc/mei/client.c +6 -26
@@ -420,31 +420,6 @@ static inline void mei_io_list_free(struct mei_cl_cb *list, struct mei_cl *cl) }/** -* mei_io_cb_alloc_buf - allocate callback buffer -* -* @cb: io callback structure -* @length: size of the buffer -* -* Return: 0 on success -* -EINVAL if cb is NULL -* -ENOMEM if allocation failed -*/ -int mei_io_cb_alloc_buf (struct mei_cl_cb *cb,size_t length) -{ -if (!cb) -return -EINVAL ; - -if (length ==0 ) -return 0 ; - - cb->buf.data =kmalloc (length,GFP_KERNEL ); -if (!cb->buf.data) -return -ENOMEM ; - cb->buf.size = length; -return 0 ; -} - -/** * mei_cl_alloc_cb - a convenient wrapper for allocating read cb * * @cl: host client
@@ -464,10 +439,15 @@ struct mei_cl_cb *mei_cl_alloc_cb(struct mei_cl *cl, size_t length,if (!cb)return NULL ; -if (mei_io_cb_alloc_buf (cb, length)) { +if (length ==0 ) +return cb; + + cb->buf.data =kmalloc (length,GFP_KERNEL ); +if (!cb->buf.data) {mei_io_cb_free (cb);return NULL ; } + cb->buf.size = length;return cb; }
drivers/misc/mei/client.h +0 -2
@@ -85,8 +85,6 @@ static inline u8 mei_me_cl_ver(const struct mei_me_client *me_cl)struct mei_cl_cb *mei_io_cb_init (struct mei_cl *cl,enum mei_cb_file_ops type,const struct file *fp);void mei_io_cb_free (struct mei_cl_cb *priv_cb); -int mei_io_cb_alloc_buf (struct mei_cl_cb *cb,size_t length); -/** * mei_io_list_init - Sets up a queue list.
Signature · 1 line
2.5.5