1212
1313static int __counter_set_mode (struct rdma_port_counter * port_counter ,
1414 enum rdma_nl_counter_mode new_mode ,
15- enum rdma_nl_counter_mask new_mask )
15+ enum rdma_nl_counter_mask new_mask ,
16+ bool bind_opcnt )
1617{
1718 if (new_mode == RDMA_COUNTER_MODE_AUTO ) {
1819 if (new_mask & (~ALL_AUTO_MODE_MASKS ))
@@ -23,6 +24,7 @@ static int __counter_set_mode(struct rdma_port_counter *port_counter,
2324
2425 port_counter -> mode .mode = new_mode ;
2526 port_counter -> mode .mask = new_mask ;
27+ port_counter -> mode .bind_opcnt = bind_opcnt ;
2628 return 0 ;
2729}
2830
@@ -41,6 +43,7 @@ static int __counter_set_mode(struct rdma_port_counter *port_counter,
4143 */
4244int rdma_counter_set_auto_mode (struct ib_device * dev , u32 port ,
4345 enum rdma_nl_counter_mask mask ,
46+ bool bind_opcnt ,
4447 struct netlink_ext_ack * extack )
4548{
4649 struct rdma_port_counter * port_counter ;
@@ -59,12 +62,13 @@ int rdma_counter_set_auto_mode(struct ib_device *dev, u32 port,
5962 RDMA_COUNTER_MODE_NONE ;
6063
6164 if (port_counter -> mode .mode == mode &&
62- port_counter -> mode .mask == mask ) {
65+ port_counter -> mode .mask == mask &&
66+ port_counter -> mode .bind_opcnt == bind_opcnt ) {
6367 ret = 0 ;
6468 goto out ;
6569 }
6670
67- ret = __counter_set_mode (port_counter , mode , mask );
71+ ret = __counter_set_mode (port_counter , mode , mask , bind_opcnt );
6872
6973out :
7074 mutex_unlock (& port_counter -> lock );
@@ -89,7 +93,7 @@ static void auto_mode_init_counter(struct rdma_counter *counter,
8993}
9094
9195static int __rdma_counter_bind_qp (struct rdma_counter * counter ,
92- struct ib_qp * qp )
96+ struct ib_qp * qp , u32 port )
9397{
9498 int ret ;
9599
@@ -100,7 +104,7 @@ static int __rdma_counter_bind_qp(struct rdma_counter *counter,
100104 return - EOPNOTSUPP ;
101105
102106 mutex_lock (& counter -> lock );
103- ret = qp -> device -> ops .counter_bind_qp (counter , qp );
107+ ret = qp -> device -> ops .counter_bind_qp (counter , qp , port );
104108 mutex_unlock (& counter -> lock );
105109
106110 return ret ;
@@ -140,7 +144,8 @@ int rdma_counter_modify(struct ib_device *dev, u32 port,
140144
141145static struct rdma_counter * alloc_and_bind (struct ib_device * dev , u32 port ,
142146 struct ib_qp * qp ,
143- enum rdma_nl_counter_mode mode )
147+ enum rdma_nl_counter_mode mode ,
148+ bool bind_opcnt )
144149{
145150 struct rdma_port_counter * port_counter ;
146151 struct rdma_counter * counter ;
@@ -149,13 +154,15 @@ static struct rdma_counter *alloc_and_bind(struct ib_device *dev, u32 port,
149154 if (!dev -> ops .counter_dealloc || !dev -> ops .counter_alloc_stats )
150155 return NULL ;
151156
152- counter = kzalloc ( sizeof ( * counter ), GFP_KERNEL );
157+ counter = rdma_zalloc_drv_obj ( dev , rdma_counter );
153158 if (!counter )
154159 return NULL ;
155160
156161 counter -> device = dev ;
157162 counter -> port = port ;
158163
164+ dev -> ops .counter_init (counter );
165+
159166 rdma_restrack_new (& counter -> res , RDMA_RESTRACK_COUNTER );
160167 counter -> stats = dev -> ops .counter_alloc_stats (counter );
161168 if (!counter -> stats )
@@ -166,7 +173,7 @@ static struct rdma_counter *alloc_and_bind(struct ib_device *dev, u32 port,
166173 switch (mode ) {
167174 case RDMA_COUNTER_MODE_MANUAL :
168175 ret = __counter_set_mode (port_counter , RDMA_COUNTER_MODE_MANUAL ,
169- 0 );
176+ 0 , bind_opcnt );
170177 if (ret ) {
171178 mutex_unlock (& port_counter -> lock );
172179 goto err_mode ;
@@ -185,10 +192,11 @@ static struct rdma_counter *alloc_and_bind(struct ib_device *dev, u32 port,
185192 mutex_unlock (& port_counter -> lock );
186193
187194 counter -> mode .mode = mode ;
195+ counter -> mode .bind_opcnt = bind_opcnt ;
188196 kref_init (& counter -> kref );
189197 mutex_init (& counter -> lock );
190198
191- ret = __rdma_counter_bind_qp (counter , qp );
199+ ret = __rdma_counter_bind_qp (counter , qp , port );
192200 if (ret )
193201 goto err_mode ;
194202
@@ -213,7 +221,8 @@ static void rdma_counter_free(struct rdma_counter *counter)
213221 port_counter -> num_counters -- ;
214222 if (!port_counter -> num_counters &&
215223 (port_counter -> mode .mode == RDMA_COUNTER_MODE_MANUAL ))
216- __counter_set_mode (port_counter , RDMA_COUNTER_MODE_NONE , 0 );
224+ __counter_set_mode (port_counter , RDMA_COUNTER_MODE_NONE , 0 ,
225+ false);
217226
218227 mutex_unlock (& port_counter -> lock );
219228
@@ -238,7 +247,7 @@ static bool auto_mode_match(struct ib_qp *qp, struct rdma_counter *counter,
238247 return match ;
239248}
240249
241- static int __rdma_counter_unbind_qp (struct ib_qp * qp )
250+ static int __rdma_counter_unbind_qp (struct ib_qp * qp , u32 port )
242251{
243252 struct rdma_counter * counter = qp -> counter ;
244253 int ret ;
@@ -247,7 +256,7 @@ static int __rdma_counter_unbind_qp(struct ib_qp *qp)
247256 return - EOPNOTSUPP ;
248257
249258 mutex_lock (& counter -> lock );
250- ret = qp -> device -> ops .counter_unbind_qp (qp );
259+ ret = qp -> device -> ops .counter_unbind_qp (qp , port );
251260 mutex_unlock (& counter -> lock );
252261
253262 return ret ;
@@ -339,13 +348,14 @@ int rdma_counter_bind_qp_auto(struct ib_qp *qp, u32 port)
339348
340349 counter = rdma_get_counter_auto_mode (qp , port );
341350 if (counter ) {
342- ret = __rdma_counter_bind_qp (counter , qp );
351+ ret = __rdma_counter_bind_qp (counter , qp , port );
343352 if (ret ) {
344353 kref_put (& counter -> kref , counter_release );
345354 return ret ;
346355 }
347356 } else {
348- counter = alloc_and_bind (dev , port , qp , RDMA_COUNTER_MODE_AUTO );
357+ counter = alloc_and_bind (dev , port , qp , RDMA_COUNTER_MODE_AUTO ,
358+ port_counter -> mode .bind_opcnt );
349359 if (!counter )
350360 return - ENOMEM ;
351361 }
@@ -358,15 +368,15 @@ int rdma_counter_bind_qp_auto(struct ib_qp *qp, u32 port)
358368 * @force:
359369 * true - Decrease the counter ref-count anyway (e.g., qp destroy)
360370 */
361- int rdma_counter_unbind_qp (struct ib_qp * qp , bool force )
371+ int rdma_counter_unbind_qp (struct ib_qp * qp , u32 port , bool force )
362372{
363373 struct rdma_counter * counter = qp -> counter ;
364374 int ret ;
365375
366376 if (!counter )
367377 return - EINVAL ;
368378
369- ret = __rdma_counter_unbind_qp (qp );
379+ ret = __rdma_counter_unbind_qp (qp , port );
370380 if (ret && !force )
371381 return ret ;
372382
@@ -513,7 +523,7 @@ int rdma_counter_bind_qpn(struct ib_device *dev, u32 port,
513523 goto err_task ;
514524 }
515525
516- ret = __rdma_counter_bind_qp (counter , qp );
526+ ret = __rdma_counter_bind_qp (counter , qp , port );
517527 if (ret )
518528 goto err_task ;
519529
@@ -558,7 +568,7 @@ int rdma_counter_bind_qpn_alloc(struct ib_device *dev, u32 port,
558568 goto err ;
559569 }
560570
561- counter = alloc_and_bind (dev , port , qp , RDMA_COUNTER_MODE_MANUAL );
571+ counter = alloc_and_bind (dev , port , qp , RDMA_COUNTER_MODE_MANUAL , true );
562572 if (!counter ) {
563573 ret = - ENOMEM ;
564574 goto err ;
@@ -604,7 +614,7 @@ int rdma_counter_unbind_qpn(struct ib_device *dev, u32 port,
604614 goto out ;
605615 }
606616
607- ret = rdma_counter_unbind_qp (qp , false);
617+ ret = rdma_counter_unbind_qp (qp , port , false);
608618
609619out :
610620 rdma_restrack_put (& qp -> res );
@@ -613,13 +623,15 @@ int rdma_counter_unbind_qpn(struct ib_device *dev, u32 port,
613623
614624int rdma_counter_get_mode (struct ib_device * dev , u32 port ,
615625 enum rdma_nl_counter_mode * mode ,
616- enum rdma_nl_counter_mask * mask )
626+ enum rdma_nl_counter_mask * mask ,
627+ bool * opcnt )
617628{
618629 struct rdma_port_counter * port_counter ;
619630
620631 port_counter = & dev -> port_data [port ].port_counter ;
621632 * mode = port_counter -> mode .mode ;
622633 * mask = port_counter -> mode .mask ;
634+ * opcnt = port_counter -> mode .bind_opcnt ;
623635
624636 return 0 ;
625637}
0 commit comments