diff mbox series

[v3,for-next,2/5] RDMA/hns: Encapsulate and simplify qp state transition

Message ID 1544265611-50379-3-git-send-email-oulijun@huawei.com (mailing list archive)
State Accepted
Commit 233673e422de70d6ba32e7b41dd75e47f036d03b
Delegated to: Jason Gunthorpe
Headers show
Series [v3,for-next,1/5] RDMA/hns: Init qp context when modify qp from reset to init | expand

Commit Message

Lijun Ou Dec. 8, 2018, 10:40 a.m. UTC
This patch move the codes of qp state transition into the
new function as well as simplify the logic for other
qp states transition.

Signed-off-by: Lijun Ou <oulijun@huawei.com>
---
V1->V2:
1. Use inline function instead of macro definition
2. Simplify the qp state transition logic
---
 drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 31 +++++++++++++++---------------
 1 file changed, 16 insertions(+), 15 deletions(-)

Comments

Yuval Shaia Dec. 9, 2018, 1:18 p.m. UTC | #1
On Sat, Dec 08, 2018 at 06:40:08PM +0800, Lijun Ou wrote:
> This patch move the codes of qp state transition into the
> new function as well as simplify the logic for other
> qp states transition.
> 
> Signed-off-by: Lijun Ou <oulijun@huawei.com>
> ---
> V1->V2:
> 1. Use inline function instead of macro definition
> 2. Simplify the qp state transition logic
> ---
>  drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 31 +++++++++++++++---------------
>  1 file changed, 16 insertions(+), 15 deletions(-)
> 
> diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c
> index 1cffe74..ca71e10 100644
> --- a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c
> +++ b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c
> @@ -3670,6 +3670,21 @@ static int modify_qp_rtr_to_rts(struct ib_qp *ibqp,
>  	return 0;
>  }
>  
> +static inline bool hns_roce_v2_check_qp_stat(enum ib_qp_state cur_state,
> +					     enum ib_qp_state new_state)
> +{
> +
> +	if ((cur_state != IB_QPS_RESET &&
> +	    (new_state == IB_QPS_ERR || new_state == IB_QPS_RESET)) ||
> +	    ((cur_state == IB_QPS_RTS || cur_state == IB_QPS_SQD) &&
> +	    (new_state == IB_QPS_RTS || new_state == IB_QPS_SQD)) ||
> +	    (cur_state == IB_QPS_SQE && new_state == IB_QPS_RTS))
> +		return true;
> +
> +	return false;
> +
> +}
> +
>  static int hns_roce_v2_modify_qp(struct ib_qp *ibqp,
>  				 const struct ib_qp_attr *attr,
>  				 int attr_mask, enum ib_qp_state cur_state,
> @@ -3711,21 +3726,7 @@ static int hns_roce_v2_modify_qp(struct ib_qp *ibqp,
>  					   qpc_mask);
>  		if (ret)
>  			goto out;
> -	} else if ((cur_state == IB_QPS_RTS && new_state == IB_QPS_RTS) ||
> -		   (cur_state == IB_QPS_SQE && new_state == IB_QPS_RTS) ||
> -		   (cur_state == IB_QPS_RTS && new_state == IB_QPS_SQD) ||
> -		   (cur_state == IB_QPS_SQD && new_state == IB_QPS_SQD) ||
> -		   (cur_state == IB_QPS_SQD && new_state == IB_QPS_RTS) ||
> -		   (cur_state == IB_QPS_INIT && new_state == IB_QPS_RESET) ||
> -		   (cur_state == IB_QPS_RTR && new_state == IB_QPS_RESET) ||
> -		   (cur_state == IB_QPS_RTS && new_state == IB_QPS_RESET) ||
> -		   (cur_state == IB_QPS_ERR && new_state == IB_QPS_RESET) ||
> -		   (cur_state == IB_QPS_INIT && new_state == IB_QPS_ERR) ||
> -		   (cur_state == IB_QPS_RTR && new_state == IB_QPS_ERR) ||
> -		   (cur_state == IB_QPS_RTS && new_state == IB_QPS_ERR) ||
> -		   (cur_state == IB_QPS_SQD && new_state == IB_QPS_ERR) ||
> -		   (cur_state == IB_QPS_SQE && new_state == IB_QPS_ERR) ||
> -		   (cur_state == IB_QPS_ERR && new_state == IB_QPS_ERR)) {
> +	} else if (hns_roce_v2_check_qp_stat(cur_state, new_state)) {
>  		/* Nothing */

If doing nothing then suggesting to make hns_roce_v2_check_qp_stat return
void.

>  		;
>  	} else {
> -- 
> 1.9.1
>
Yuval Shaia Dec. 9, 2018, 1:28 p.m. UTC | #2
Sorry, please ignore my last comment but pls chk question and comment here.

On Sun, Dec 09, 2018 at 03:18:27PM +0200, Yuval Shaia wrote:
> On Sat, Dec 08, 2018 at 06:40:08PM +0800, Lijun Ou wrote:
> > This patch move the codes of qp state transition into the
> > new function as well as simplify the logic for other
> > qp states transition.

I don't see code that do "state transition" in this patch.

> > 
> > Signed-off-by: Lijun Ou <oulijun@huawei.com>
> > ---
> > V1->V2:
> > 1. Use inline function instead of macro definition
> > 2. Simplify the qp state transition logic
> > ---
> >  drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 31 +++++++++++++++---------------
> >  1 file changed, 16 insertions(+), 15 deletions(-)
> > 
> > diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c
> > index 1cffe74..ca71e10 100644
> > --- a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c
> > +++ b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c
> > @@ -3670,6 +3670,21 @@ static int modify_qp_rtr_to_rts(struct ib_qp *ibqp,
> >  	return 0;
> >  }
> >  
> > +static inline bool hns_roce_v2_check_qp_stat(enum ib_qp_state cur_state,
> > +					     enum ib_qp_state new_state)
> > +{
> > +
> > +	if ((cur_state != IB_QPS_RESET &&
> > +	    (new_state == IB_QPS_ERR || new_state == IB_QPS_RESET)) ||
> > +	    ((cur_state == IB_QPS_RTS || cur_state == IB_QPS_SQD) &&
> > +	    (new_state == IB_QPS_RTS || new_state == IB_QPS_SQD)) ||
> > +	    (cur_state == IB_QPS_SQE && new_state == IB_QPS_RTS))
> > +		return true;
> > +
> > +	return false;
> > +
> > +}
> > +
> >  static int hns_roce_v2_modify_qp(struct ib_qp *ibqp,
> >  				 const struct ib_qp_attr *attr,
> >  				 int attr_mask, enum ib_qp_state cur_state,
> > @@ -3711,21 +3726,7 @@ static int hns_roce_v2_modify_qp(struct ib_qp *ibqp,
> >  					   qpc_mask);
> >  		if (ret)
> >  			goto out;
> > -	} else if ((cur_state == IB_QPS_RTS && new_state == IB_QPS_RTS) ||
> > -		   (cur_state == IB_QPS_SQE && new_state == IB_QPS_RTS) ||
> > -		   (cur_state == IB_QPS_RTS && new_state == IB_QPS_SQD) ||
> > -		   (cur_state == IB_QPS_SQD && new_state == IB_QPS_SQD) ||
> > -		   (cur_state == IB_QPS_SQD && new_state == IB_QPS_RTS) ||
> > -		   (cur_state == IB_QPS_INIT && new_state == IB_QPS_RESET) ||
> > -		   (cur_state == IB_QPS_RTR && new_state == IB_QPS_RESET) ||
> > -		   (cur_state == IB_QPS_RTS && new_state == IB_QPS_RESET) ||
> > -		   (cur_state == IB_QPS_ERR && new_state == IB_QPS_RESET) ||
> > -		   (cur_state == IB_QPS_INIT && new_state == IB_QPS_ERR) ||
> > -		   (cur_state == IB_QPS_RTR && new_state == IB_QPS_ERR) ||
> > -		   (cur_state == IB_QPS_RTS && new_state == IB_QPS_ERR) ||
> > -		   (cur_state == IB_QPS_SQD && new_state == IB_QPS_ERR) ||
> > -		   (cur_state == IB_QPS_SQE && new_state == IB_QPS_ERR) ||
> > -		   (cur_state == IB_QPS_ERR && new_state == IB_QPS_ERR)) {
> > +	} else if (hns_roce_v2_check_qp_stat(cur_state, new_state)) {
> >  		/* Nothing */
> 
> If doing nothing then suggesting to make hns_roce_v2_check_qp_stat return
> void.

Ignore the above but, since the return value from hns_roce_v2_check_qp_stat
is ignored then suggesting to remove the 'if'.

> 
> >  		;
> >  	} else {
> > -- 
> > 1.9.1
> >
Lijun Ou Dec. 10, 2018, 7 a.m. UTC | #3
在 2018/12/9 21:28, Yuval Shaia 写道:
> Sorry, please ignore my last comment but pls chk question and comment here.
>
> On Sun, Dec 09, 2018 at 03:18:27PM +0200, Yuval Shaia wrote:
>> On Sat, Dec 08, 2018 at 06:40:08PM +0800, Lijun Ou wrote:
>>> This patch move the codes of qp state transition into the
>>> new function as well as simplify the logic for other
>>> qp states transition.
> I don't see code that do "state transition" in this patch.
The legal qp state jump. for example, the transition from a state of qp  to either state.
>>> Signed-off-by: Lijun Ou <oulijun@huawei.com>
>>> ---
>>> V1->V2:
>>> 1. Use inline function instead of macro definition
>>> 2. Simplify the qp state transition logic
>>> ---
>>>  drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 31 +++++++++++++++---------------
>>>  1 file changed, 16 insertions(+), 15 deletions(-)
>>>
>>> diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c
>>> index 1cffe74..ca71e10 100644
>>> --- a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c
>>> +++ b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c
>>> @@ -3670,6 +3670,21 @@ static int modify_qp_rtr_to_rts(struct ib_qp *ibqp,
>>>  	return 0;
>>>  }
>>>  
>>> +static inline bool hns_roce_v2_check_qp_stat(enum ib_qp_state cur_state,
>>> +					     enum ib_qp_state new_state)
>>> +{
>>> +
>>> +	if ((cur_state != IB_QPS_RESET &&
>>> +	    (new_state == IB_QPS_ERR || new_state == IB_QPS_RESET)) ||
>>> +	    ((cur_state == IB_QPS_RTS || cur_state == IB_QPS_SQD) &&
>>> +	    (new_state == IB_QPS_RTS || new_state == IB_QPS_SQD)) ||
>>> +	    (cur_state == IB_QPS_SQE && new_state == IB_QPS_RTS))
>>> +		return true;
>>> +
>>> +	return false;
>>> +
>>> +}
>>> +
>>>  static int hns_roce_v2_modify_qp(struct ib_qp *ibqp,
>>>  				 const struct ib_qp_attr *attr,
>>>  				 int attr_mask, enum ib_qp_state cur_state,
>>> @@ -3711,21 +3726,7 @@ static int hns_roce_v2_modify_qp(struct ib_qp *ibqp,
>>>  					   qpc_mask);
>>>  		if (ret)
>>>  			goto out;
>>> -	} else if ((cur_state == IB_QPS_RTS && new_state == IB_QPS_RTS) ||
>>> -		   (cur_state == IB_QPS_SQE && new_state == IB_QPS_RTS) ||
>>> -		   (cur_state == IB_QPS_RTS && new_state == IB_QPS_SQD) ||
>>> -		   (cur_state == IB_QPS_SQD && new_state == IB_QPS_SQD) ||
>>> -		   (cur_state == IB_QPS_SQD && new_state == IB_QPS_RTS) ||
>>> -		   (cur_state == IB_QPS_INIT && new_state == IB_QPS_RESET) ||
>>> -		   (cur_state == IB_QPS_RTR && new_state == IB_QPS_RESET) ||
>>> -		   (cur_state == IB_QPS_RTS && new_state == IB_QPS_RESET) ||
>>> -		   (cur_state == IB_QPS_ERR && new_state == IB_QPS_RESET) ||
>>> -		   (cur_state == IB_QPS_INIT && new_state == IB_QPS_ERR) ||
>>> -		   (cur_state == IB_QPS_RTR && new_state == IB_QPS_ERR) ||
>>> -		   (cur_state == IB_QPS_RTS && new_state == IB_QPS_ERR) ||
>>> -		   (cur_state == IB_QPS_SQD && new_state == IB_QPS_ERR) ||
>>> -		   (cur_state == IB_QPS_SQE && new_state == IB_QPS_ERR) ||
>>> -		   (cur_state == IB_QPS_ERR && new_state == IB_QPS_ERR)) {
>>> +	} else if (hns_roce_v2_check_qp_stat(cur_state, new_state)) {
>>>  		/* Nothing */
>> If doing nothing then suggesting to make hns_roce_v2_check_qp_stat return
>> void.
> Ignore the above but, since the return value from hns_roce_v2_check_qp_stat
> is ignored then suggesting to remove the 'if'.
>
>>>  		;
>>>  	} else {
>>> -- 
>>> 1.9.1
>>>
> .
>
diff mbox series

Patch

diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c
index 1cffe74..ca71e10 100644
--- a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c
+++ b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c
@@ -3670,6 +3670,21 @@  static int modify_qp_rtr_to_rts(struct ib_qp *ibqp,
 	return 0;
 }
 
+static inline bool hns_roce_v2_check_qp_stat(enum ib_qp_state cur_state,
+					     enum ib_qp_state new_state)
+{
+
+	if ((cur_state != IB_QPS_RESET &&
+	    (new_state == IB_QPS_ERR || new_state == IB_QPS_RESET)) ||
+	    ((cur_state == IB_QPS_RTS || cur_state == IB_QPS_SQD) &&
+	    (new_state == IB_QPS_RTS || new_state == IB_QPS_SQD)) ||
+	    (cur_state == IB_QPS_SQE && new_state == IB_QPS_RTS))
+		return true;
+
+	return false;
+
+}
+
 static int hns_roce_v2_modify_qp(struct ib_qp *ibqp,
 				 const struct ib_qp_attr *attr,
 				 int attr_mask, enum ib_qp_state cur_state,
@@ -3711,21 +3726,7 @@  static int hns_roce_v2_modify_qp(struct ib_qp *ibqp,
 					   qpc_mask);
 		if (ret)
 			goto out;
-	} else if ((cur_state == IB_QPS_RTS && new_state == IB_QPS_RTS) ||
-		   (cur_state == IB_QPS_SQE && new_state == IB_QPS_RTS) ||
-		   (cur_state == IB_QPS_RTS && new_state == IB_QPS_SQD) ||
-		   (cur_state == IB_QPS_SQD && new_state == IB_QPS_SQD) ||
-		   (cur_state == IB_QPS_SQD && new_state == IB_QPS_RTS) ||
-		   (cur_state == IB_QPS_INIT && new_state == IB_QPS_RESET) ||
-		   (cur_state == IB_QPS_RTR && new_state == IB_QPS_RESET) ||
-		   (cur_state == IB_QPS_RTS && new_state == IB_QPS_RESET) ||
-		   (cur_state == IB_QPS_ERR && new_state == IB_QPS_RESET) ||
-		   (cur_state == IB_QPS_INIT && new_state == IB_QPS_ERR) ||
-		   (cur_state == IB_QPS_RTR && new_state == IB_QPS_ERR) ||
-		   (cur_state == IB_QPS_RTS && new_state == IB_QPS_ERR) ||
-		   (cur_state == IB_QPS_SQD && new_state == IB_QPS_ERR) ||
-		   (cur_state == IB_QPS_SQE && new_state == IB_QPS_ERR) ||
-		   (cur_state == IB_QPS_ERR && new_state == IB_QPS_ERR)) {
+	} else if (hns_roce_v2_check_qp_stat(cur_state, new_state)) {
 		/* Nothing */
 		;
 	} else {