Commit a4c60404 authored by Eric Farman's avatar Eric Farman Committed by Heiko Carstens

vfio/ccw: simplify CCW chain fetch routines

The act of processing a fetched CCW has two components:

 1) Process a Transfer-in-channel (TIC) CCW
 2) Process any other CCW

The former needs to look at whether the TIC jumps backwards into
the current channel program or forwards into a new segment,
while the latter just processes the CCW data address itself.

Rather than passing the chain segment and index within it to the
handlers for the above, and requiring each to calculate the
elements it needs, simply pass the needed pointers directly.

For the TIC, that means the CCW being processed and the location
of the entire channel program which holds all segments. For the
other CCWs, the page_array pointer is also needed to perform the
page pinning, etc.

While at it, rename ccwchain_fetch_direct to _ccw, to indicate
what it is. The name "_direct" is historical, when it used to
process a direct-addressed CCW, but IDAs are processed here too.
Signed-off-by: default avatarEric Farman <farman@linux.ibm.com>
Reviewed-by: default avatarMatthew Rosato <mjrosato@linux.ibm.com>
Signed-off-by: default avatarHeiko Carstens <hca@linux.ibm.com>
parent c5e8083f
...@@ -482,11 +482,9 @@ static int ccwchain_loop_tic(struct ccwchain *chain, struct channel_program *cp) ...@@ -482,11 +482,9 @@ static int ccwchain_loop_tic(struct ccwchain *chain, struct channel_program *cp)
return 0; return 0;
} }
static int ccwchain_fetch_tic(struct ccwchain *chain, static int ccwchain_fetch_tic(struct ccw1 *ccw,
int idx,
struct channel_program *cp) struct channel_program *cp)
{ {
struct ccw1 *ccw = chain->ch_ccw + idx;
struct ccwchain *iter; struct ccwchain *iter;
u32 ccw_head; u32 ccw_head;
...@@ -502,14 +500,12 @@ static int ccwchain_fetch_tic(struct ccwchain *chain, ...@@ -502,14 +500,12 @@ static int ccwchain_fetch_tic(struct ccwchain *chain,
return -EFAULT; return -EFAULT;
} }
static int ccwchain_fetch_direct(struct ccwchain *chain, static int ccwchain_fetch_ccw(struct ccw1 *ccw,
int idx, struct page_array *pa,
struct channel_program *cp) struct channel_program *cp)
{ {
struct vfio_device *vdev = struct vfio_device *vdev =
&container_of(cp, struct vfio_ccw_private, cp)->vdev; &container_of(cp, struct vfio_ccw_private, cp)->vdev;
struct ccw1 *ccw;
struct page_array *pa;
u64 iova; u64 iova;
unsigned long *idaws; unsigned long *idaws;
int ret; int ret;
...@@ -517,8 +513,6 @@ static int ccwchain_fetch_direct(struct ccwchain *chain, ...@@ -517,8 +513,6 @@ static int ccwchain_fetch_direct(struct ccwchain *chain,
int idaw_nr, idal_len; int idaw_nr, idal_len;
int i; int i;
ccw = chain->ch_ccw + idx;
if (ccw->count) if (ccw->count)
bytes = ccw->count; bytes = ccw->count;
...@@ -548,7 +542,6 @@ static int ccwchain_fetch_direct(struct ccwchain *chain, ...@@ -548,7 +542,6 @@ static int ccwchain_fetch_direct(struct ccwchain *chain,
* required for the data transfer, since we only only support * required for the data transfer, since we only only support
* 4K IDAWs today. * 4K IDAWs today.
*/ */
pa = chain->ch_pa + idx;
ret = page_array_alloc(pa, iova, bytes); ret = page_array_alloc(pa, iova, bytes);
if (ret < 0) if (ret < 0)
goto out_free_idaws; goto out_free_idaws;
...@@ -604,16 +597,15 @@ static int ccwchain_fetch_direct(struct ccwchain *chain, ...@@ -604,16 +597,15 @@ static int ccwchain_fetch_direct(struct ccwchain *chain,
* and to get rid of the cda 2G limitiaion of ccw1, we'll translate * and to get rid of the cda 2G limitiaion of ccw1, we'll translate
* direct ccws to idal ccws. * direct ccws to idal ccws.
*/ */
static int ccwchain_fetch_one(struct ccwchain *chain, static int ccwchain_fetch_one(struct ccw1 *ccw,
int idx, struct page_array *pa,
struct channel_program *cp) struct channel_program *cp)
{
struct ccw1 *ccw = chain->ch_ccw + idx;
{
if (ccw_is_tic(ccw)) if (ccw_is_tic(ccw))
return ccwchain_fetch_tic(chain, idx, cp); return ccwchain_fetch_tic(ccw, cp);
return ccwchain_fetch_direct(chain, idx, cp); return ccwchain_fetch_ccw(ccw, pa, cp);
} }
/** /**
...@@ -736,6 +728,8 @@ void cp_free(struct channel_program *cp) ...@@ -736,6 +728,8 @@ void cp_free(struct channel_program *cp)
int cp_prefetch(struct channel_program *cp) int cp_prefetch(struct channel_program *cp)
{ {
struct ccwchain *chain; struct ccwchain *chain;
struct ccw1 *ccw;
struct page_array *pa;
int len, idx, ret; int len, idx, ret;
/* this is an error in the caller */ /* this is an error in the caller */
...@@ -745,7 +739,10 @@ int cp_prefetch(struct channel_program *cp) ...@@ -745,7 +739,10 @@ int cp_prefetch(struct channel_program *cp)
list_for_each_entry(chain, &cp->ccwchain_list, next) { list_for_each_entry(chain, &cp->ccwchain_list, next) {
len = chain->ch_len; len = chain->ch_len;
for (idx = 0; idx < len; idx++) { for (idx = 0; idx < len; idx++) {
ret = ccwchain_fetch_one(chain, idx, cp); ccw = chain->ch_ccw + idx;
pa = chain->ch_pa + idx;
ret = ccwchain_fetch_one(ccw, pa, cp);
if (ret) if (ret)
goto out_err; goto out_err;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment