@@ -213,29 +213,18 @@ static int ionic_sriov_configure(struct pci_dev *pdev, int num_vfs)
213
213
return ret ;
214
214
}
215
215
216
- static int ionic_probe (struct pci_dev * pdev , const struct pci_device_id * ent )
216
+ static void ionic_clear_pci (struct ionic * ionic )
217
217
{
218
- struct device * dev = & pdev -> dev ;
219
- struct ionic * ionic ;
220
- int num_vfs ;
221
- int err ;
222
-
223
- ionic = ionic_devlink_alloc (dev );
224
- if (!ionic )
225
- return - ENOMEM ;
226
-
227
- ionic -> pdev = pdev ;
228
- ionic -> dev = dev ;
229
- pci_set_drvdata (pdev , ionic );
230
- mutex_init (& ionic -> dev_cmd_lock );
218
+ ionic_unmap_bars (ionic );
219
+ pci_release_regions (ionic -> pdev );
220
+ pci_disable_device (ionic -> pdev );
221
+ }
231
222
232
- /* Query system for DMA addressing limitation for the device. */
233
- err = dma_set_mask_and_coherent (dev , DMA_BIT_MASK (IONIC_ADDR_LEN ));
234
- if (err ) {
235
- dev_err (dev , "Unable to obtain 64-bit DMA for consistent allocations, aborting. err=%d\n" ,
236
- err );
237
- goto err_out_clear_drvdata ;
238
- }
223
+ static int ionic_setup_one (struct ionic * ionic )
224
+ {
225
+ struct pci_dev * pdev = ionic -> pdev ;
226
+ struct device * dev = ionic -> dev ;
227
+ int err ;
239
228
240
229
ionic_debugfs_add_dev (ionic );
241
230
@@ -249,20 +238,19 @@ static int ionic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
249
238
err = pci_request_regions (pdev , IONIC_DRV_NAME );
250
239
if (err ) {
251
240
dev_err (dev , "Cannot request PCI regions: %d, aborting\n" , err );
252
- goto err_out_pci_disable_device ;
241
+ goto err_out_clear_pci ;
253
242
}
254
-
255
243
pcie_print_link_status (pdev );
256
244
257
245
err = ionic_map_bars (ionic );
258
246
if (err )
259
- goto err_out_pci_release_regions ;
247
+ goto err_out_clear_pci ;
260
248
261
249
/* Configure the device */
262
250
err = ionic_setup (ionic );
263
251
if (err ) {
264
252
dev_err (dev , "Cannot setup device: %d, aborting\n" , err );
265
- goto err_out_unmap_bars ;
253
+ goto err_out_clear_pci ;
266
254
}
267
255
pci_set_master (pdev );
268
256
@@ -279,24 +267,64 @@ static int ionic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
279
267
goto err_out_teardown ;
280
268
}
281
269
282
- /* Configure the ports */
270
+ /* Configure the port */
283
271
err = ionic_port_identify (ionic );
284
272
if (err ) {
285
273
dev_err (dev , "Cannot identify port: %d, aborting\n" , err );
286
- goto err_out_reset ;
274
+ goto err_out_teardown ;
287
275
}
288
276
289
277
err = ionic_port_init (ionic );
290
278
if (err ) {
291
279
dev_err (dev , "Cannot init port: %d, aborting\n" , err );
292
- goto err_out_reset ;
280
+ goto err_out_teardown ;
281
+ }
282
+
283
+ return 0 ;
284
+
285
+ err_out_teardown :
286
+ ionic_dev_teardown (ionic );
287
+ err_out_clear_pci :
288
+ ionic_clear_pci (ionic );
289
+ err_out_debugfs_del_dev :
290
+ ionic_debugfs_del_dev (ionic );
291
+
292
+ return err ;
293
+ }
294
+
295
+ static int ionic_probe (struct pci_dev * pdev , const struct pci_device_id * ent )
296
+ {
297
+ struct device * dev = & pdev -> dev ;
298
+ struct ionic * ionic ;
299
+ int num_vfs ;
300
+ int err ;
301
+
302
+ ionic = ionic_devlink_alloc (dev );
303
+ if (!ionic )
304
+ return - ENOMEM ;
305
+
306
+ ionic -> pdev = pdev ;
307
+ ionic -> dev = dev ;
308
+ pci_set_drvdata (pdev , ionic );
309
+ mutex_init (& ionic -> dev_cmd_lock );
310
+
311
+ /* Query system for DMA addressing limitation for the device. */
312
+ err = dma_set_mask_and_coherent (dev , DMA_BIT_MASK (IONIC_ADDR_LEN ));
313
+ if (err ) {
314
+ dev_err (dev , "Unable to obtain 64-bit DMA for consistent allocations, aborting. err=%d\n" ,
315
+ err );
316
+ goto err_out ;
293
317
}
294
318
319
+ err = ionic_setup_one (ionic );
320
+ if (err )
321
+ goto err_out ;
322
+
295
323
/* Allocate and init the LIF */
296
324
err = ionic_lif_size (ionic );
297
325
if (err ) {
298
326
dev_err (dev , "Cannot size LIF: %d, aborting\n" , err );
299
- goto err_out_port_reset ;
327
+ goto err_out_pci ;
300
328
}
301
329
302
330
err = ionic_lif_alloc (ionic );
@@ -347,21 +375,10 @@ static int ionic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
347
375
ionic -> lif = NULL ;
348
376
err_out_free_irqs :
349
377
ionic_bus_free_irq_vectors (ionic );
350
- err_out_port_reset :
351
- ionic_port_reset (ionic );
352
- err_out_reset :
353
- ionic_reset (ionic );
354
- err_out_teardown :
378
+ err_out_pci :
355
379
ionic_dev_teardown (ionic );
356
- err_out_unmap_bars :
357
- ionic_unmap_bars (ionic );
358
- err_out_pci_release_regions :
359
- pci_release_regions (pdev );
360
- err_out_pci_disable_device :
361
- pci_disable_device (pdev );
362
- err_out_debugfs_del_dev :
363
- ionic_debugfs_del_dev (ionic );
364
- err_out_clear_drvdata :
380
+ ionic_clear_pci (ionic );
381
+ err_out :
365
382
mutex_destroy (& ionic -> dev_cmd_lock );
366
383
ionic_devlink_free (ionic );
367
384
@@ -386,20 +403,71 @@ static void ionic_remove(struct pci_dev *pdev)
386
403
ionic_port_reset (ionic );
387
404
ionic_reset (ionic );
388
405
ionic_dev_teardown (ionic );
389
- ionic_unmap_bars (ionic );
390
- pci_release_regions (pdev );
391
- pci_disable_device (pdev );
406
+ ionic_clear_pci (ionic );
392
407
ionic_debugfs_del_dev (ionic );
393
408
mutex_destroy (& ionic -> dev_cmd_lock );
394
409
ionic_devlink_free (ionic );
395
410
}
396
411
412
+ static void ionic_reset_prepare (struct pci_dev * pdev )
413
+ {
414
+ struct ionic * ionic = pci_get_drvdata (pdev );
415
+ struct ionic_lif * lif = ionic -> lif ;
416
+
417
+ dev_dbg (ionic -> dev , "%s: device stopping\n" , __func__ );
418
+
419
+ del_timer_sync (& ionic -> watchdog_timer );
420
+ cancel_work_sync (& lif -> deferred .work );
421
+
422
+ mutex_lock (& lif -> queue_lock );
423
+ ionic_stop_queues_reconfig (lif );
424
+ ionic_txrx_free (lif );
425
+ ionic_lif_deinit (lif );
426
+ ionic_qcqs_free (lif );
427
+ mutex_unlock (& lif -> queue_lock );
428
+
429
+ ionic_dev_teardown (ionic );
430
+ ionic_clear_pci (ionic );
431
+ ionic_debugfs_del_dev (ionic );
432
+ }
433
+
434
+ static void ionic_reset_done (struct pci_dev * pdev )
435
+ {
436
+ struct ionic * ionic = pci_get_drvdata (pdev );
437
+ struct ionic_lif * lif = ionic -> lif ;
438
+ int err ;
439
+
440
+ err = ionic_setup_one (ionic );
441
+ if (err )
442
+ goto err_out ;
443
+
444
+ ionic_debugfs_add_sizes (ionic );
445
+ ionic_debugfs_add_lif (ionic -> lif );
446
+
447
+ err = ionic_restart_lif (lif );
448
+ if (err )
449
+ goto err_out ;
450
+
451
+ mod_timer (& ionic -> watchdog_timer , jiffies + 1 );
452
+
453
+ err_out :
454
+ dev_dbg (ionic -> dev , "%s: device recovery %s\n" ,
455
+ __func__ , err ? "failed" : "done" );
456
+ }
457
+
458
+ static const struct pci_error_handlers ionic_err_handler = {
459
+ /* FLR handling */
460
+ .reset_prepare = ionic_reset_prepare ,
461
+ .reset_done = ionic_reset_done ,
462
+ };
463
+
397
464
static struct pci_driver ionic_driver = {
398
465
.name = IONIC_DRV_NAME ,
399
466
.id_table = ionic_id_table ,
400
467
.probe = ionic_probe ,
401
468
.remove = ionic_remove ,
402
469
.sriov_configure = ionic_sriov_configure ,
470
+ .err_handler = & ionic_err_handler
403
471
};
404
472
405
473
int ionic_bus_register_driver (void )
0 commit comments