5
5
6
6
#include "core.h"
7
7
8
- struct pdsc_wait_context {
9
- struct pdsc_qcq * qcq ;
10
- struct completion wait_completion ;
11
- };
12
-
13
8
static int pdsc_process_notifyq (struct pdsc_qcq * qcq )
14
9
{
15
10
union pds_core_notifyq_comp * comp ;
@@ -109,10 +104,10 @@ void pdsc_process_adminq(struct pdsc_qcq *qcq)
109
104
q_info = & q -> info [q -> tail_idx ];
110
105
q -> tail_idx = (q -> tail_idx + 1 ) & (q -> num_descs - 1 );
111
106
112
- /* Copy out the completion data */
113
- memcpy (q_info -> dest , comp , sizeof (* comp ));
114
-
115
- complete_all ( & q_info -> wc -> wait_completion );
107
+ if (! completion_done ( & q_info -> completion )) {
108
+ memcpy (q_info -> dest , comp , sizeof (* comp ));
109
+ complete ( & q_info -> completion );
110
+ }
116
111
117
112
if (cq -> tail_idx == cq -> num_descs - 1 )
118
113
cq -> done_color = !cq -> done_color ;
@@ -162,8 +157,7 @@ irqreturn_t pdsc_adminq_isr(int irq, void *data)
162
157
static int __pdsc_adminq_post (struct pdsc * pdsc ,
163
158
struct pdsc_qcq * qcq ,
164
159
union pds_core_adminq_cmd * cmd ,
165
- union pds_core_adminq_comp * comp ,
166
- struct pdsc_wait_context * wc )
160
+ union pds_core_adminq_comp * comp )
167
161
{
168
162
struct pdsc_queue * q = & qcq -> q ;
169
163
struct pdsc_q_info * q_info ;
@@ -205,9 +199,9 @@ static int __pdsc_adminq_post(struct pdsc *pdsc,
205
199
/* Post the request */
206
200
index = q -> head_idx ;
207
201
q_info = & q -> info [index ];
208
- q_info -> wc = wc ;
209
202
q_info -> dest = comp ;
210
203
memcpy (q_info -> desc , cmd , sizeof (* cmd ));
204
+ reinit_completion (& q_info -> completion );
211
205
212
206
dev_dbg (pdsc -> dev , "head_idx %d tail_idx %d\n" ,
213
207
q -> head_idx , q -> tail_idx );
@@ -231,16 +225,13 @@ int pdsc_adminq_post(struct pdsc *pdsc,
231
225
union pds_core_adminq_comp * comp ,
232
226
bool fast_poll )
233
227
{
234
- struct pdsc_wait_context wc = {
235
- .wait_completion =
236
- COMPLETION_INITIALIZER_ONSTACK (wc .wait_completion ),
237
- };
238
228
unsigned long poll_interval = 1 ;
239
229
unsigned long poll_jiffies ;
240
230
unsigned long time_limit ;
241
231
unsigned long time_start ;
242
232
unsigned long time_done ;
243
233
unsigned long remaining ;
234
+ struct completion * wc ;
244
235
int err = 0 ;
245
236
int index ;
246
237
@@ -250,20 +241,19 @@ int pdsc_adminq_post(struct pdsc *pdsc,
250
241
return - ENXIO ;
251
242
}
252
243
253
- wc .qcq = & pdsc -> adminqcq ;
254
- index = __pdsc_adminq_post (pdsc , & pdsc -> adminqcq , cmd , comp , & wc );
244
+ index = __pdsc_adminq_post (pdsc , & pdsc -> adminqcq , cmd , comp );
255
245
if (index < 0 ) {
256
246
err = index ;
257
247
goto err_out ;
258
248
}
259
249
250
+ wc = & pdsc -> adminqcq .q .info [index ].completion ;
260
251
time_start = jiffies ;
261
252
time_limit = time_start + HZ * pdsc -> devcmd_timeout ;
262
253
do {
263
254
/* Timeslice the actual wait to catch IO errors etc early */
264
255
poll_jiffies = msecs_to_jiffies (poll_interval );
265
- remaining = wait_for_completion_timeout (& wc .wait_completion ,
266
- poll_jiffies );
256
+ remaining = wait_for_completion_timeout (wc , poll_jiffies );
267
257
if (remaining )
268
258
break ;
269
259
@@ -292,9 +282,11 @@ int pdsc_adminq_post(struct pdsc *pdsc,
292
282
dev_dbg (pdsc -> dev , "%s: elapsed %d msecs\n" ,
293
283
__func__ , jiffies_to_msecs (time_done - time_start ));
294
284
295
- /* Check the results */
296
- if (time_after_eq (time_done , time_limit ))
285
+ /* Check the results and clear an un-completed timeout */
286
+ if (time_after_eq (time_done , time_limit ) && ! completion_done ( wc )) {
297
287
err = - ETIMEDOUT ;
288
+ complete (wc );
289
+ }
298
290
299
291
dev_dbg (pdsc -> dev , "read admin queue completion idx %d:\n" , index );
300
292
dynamic_hex_dump ("comp " , DUMP_PREFIX_OFFSET , 16 , 1 ,
0 commit comments