@@ -1251,43 +1251,62 @@ ice_handle_link_event(struct ice_pf *pf, struct ice_rq_event_info *event)
1251
1251
}
1252
1252
1253
1253
/**
1254
- * ice_aq_wait_for_event - Wait for an AdminQ event from firmware
1254
+ * ice_aq_prep_for_event - Prepare to wait for an AdminQ event from firmware
1255
1255
* @pf: pointer to the PF private structure
1256
- * @task: ptr to task structure
1256
+ * @task: intermediate helper storage and identifier for waiting
1257
1257
* @opcode: the opcode to wait for
1258
- * @timeout: how long to wait, in jiffies
1259
1258
*
1260
- * Waits for a specific AdminQ completion event on the ARQ for a given PF. The
1261
- * current thread will be put to sleep until the specified event occurs or
1262
- * until the given timeout is reached.
1259
+ * Prepares to wait for a specific AdminQ completion event on the ARQ for
1260
+ * a given PF. Actual wait would be done by a call to ice_aq_wait_for_event().
1263
1261
*
1264
- * To obtain only the descriptor contents, pass an event without an allocated
1265
- * msg_buf. If the complete data buffer is desired, allocate the
1266
- * event->msg_buf with enough space ahead of time.
1262
+ * Calls are separated to allow caller registering for event before sending
1263
+ * the command, which mitigates a race between registering and FW responding.
1267
1264
*
1268
- * Returns: zero on success, or a negative error code on failure.
1265
+ * To obtain only the descriptor contents, pass an task->event with null
1266
+ * msg_buf. If the complete data buffer is desired, allocate the
1267
+ * task->event.msg_buf with enough space ahead of time.
1269
1268
*/
1270
- int ice_aq_wait_for_event (struct ice_pf * pf , struct ice_aq_task * task ,
1271
- u16 opcode , unsigned long timeout )
1269
+ void ice_aq_prep_for_event (struct ice_pf * pf , struct ice_aq_task * task ,
1270
+ u16 opcode )
1272
1271
{
1273
- struct device * dev = ice_pf_to_dev (pf );
1274
- unsigned long start ;
1275
- long ret ;
1276
- int err ;
1277
-
1278
1272
INIT_HLIST_NODE (& task -> entry );
1279
1273
task -> opcode = opcode ;
1280
1274
task -> state = ICE_AQ_TASK_WAITING ;
1281
1275
1282
1276
spin_lock_bh (& pf -> aq_wait_lock );
1283
1277
hlist_add_head (& task -> entry , & pf -> aq_wait_list );
1284
1278
spin_unlock_bh (& pf -> aq_wait_lock );
1279
+ }
1285
1280
1286
- start = jiffies ;
1281
+ /**
1282
+ * ice_aq_wait_for_event - Wait for an AdminQ event from firmware
1283
+ * @pf: pointer to the PF private structure
1284
+ * @task: ptr prepared by ice_aq_prep_for_event()
1285
+ * @timeout: how long to wait, in jiffies
1286
+ *
1287
+ * Waits for a specific AdminQ completion event on the ARQ for a given PF. The
1288
+ * current thread will be put to sleep until the specified event occurs or
1289
+ * until the given timeout is reached.
1290
+ *
1291
+ * Returns: zero on success, or a negative error code on failure.
1292
+ */
1293
+ int ice_aq_wait_for_event (struct ice_pf * pf , struct ice_aq_task * task ,
1294
+ unsigned long timeout )
1295
+ {
1296
+ enum ice_aq_task_state * state = & task -> state ;
1297
+ struct device * dev = ice_pf_to_dev (pf );
1298
+ unsigned long start = jiffies ;
1299
+ long ret ;
1300
+ int err ;
1287
1301
1288
- ret = wait_event_interruptible_timeout (pf -> aq_wait_queue , task -> state ,
1302
+ ret = wait_event_interruptible_timeout (pf -> aq_wait_queue ,
1303
+ * state != ICE_AQ_TASK_WAITING ,
1289
1304
timeout );
1290
- switch (task -> state ) {
1305
+ switch (* state ) {
1306
+ case ICE_AQ_TASK_NOT_PREPARED :
1307
+ WARN (1 , "call to %s without ice_aq_prep_for_event()" , __func__ );
1308
+ err = - EINVAL ;
1309
+ break ;
1291
1310
case ICE_AQ_TASK_WAITING :
1292
1311
err = ret < 0 ? ret : - ETIMEDOUT ;
1293
1312
break ;
@@ -1298,15 +1317,15 @@ int ice_aq_wait_for_event(struct ice_pf *pf, struct ice_aq_task *task,
1298
1317
err = ret < 0 ? ret : 0 ;
1299
1318
break ;
1300
1319
default :
1301
- WARN (1 , "Unexpected AdminQ wait task state %u" , task -> state );
1320
+ WARN (1 , "Unexpected AdminQ wait task state %u" , * state );
1302
1321
err = - EINVAL ;
1303
1322
break ;
1304
1323
}
1305
1324
1306
1325
dev_dbg (dev , "Waited %u msecs (max %u msecs) for firmware response to op 0x%04x\n" ,
1307
1326
jiffies_to_msecs (jiffies - start ),
1308
1327
jiffies_to_msecs (timeout ),
1309
- opcode );
1328
+ task -> opcode );
1310
1329
1311
1330
spin_lock_bh (& pf -> aq_wait_lock );
1312
1331
hlist_del (& task -> entry );
@@ -1342,7 +1361,9 @@ static void ice_aq_check_events(struct ice_pf *pf, u16 opcode,
1342
1361
1343
1362
spin_lock_bh (& pf -> aq_wait_lock );
1344
1363
hlist_for_each_entry (task , & pf -> aq_wait_list , entry ) {
1345
- if (task -> state || task -> opcode != opcode )
1364
+ if (task -> state != ICE_AQ_TASK_WAITING )
1365
+ continue ;
1366
+ if (task -> opcode != opcode )
1346
1367
continue ;
1347
1368
1348
1369
task_ev = & task -> event ;
0 commit comments