@@ -302,8 +302,9 @@ static irqreturn_t iavf_msix_aq(int irq, void *data)
302
302
rd32 (hw , IAVF_VFINT_ICR01 );
303
303
rd32 (hw , IAVF_VFINT_ICR0_ENA1 );
304
304
305
- /* schedule work on the private workqueue */
306
- queue_work (iavf_wq , & adapter -> adminq_task );
305
+ if (adapter -> state != __IAVF_REMOVE )
306
+ /* schedule work on the private workqueue */
307
+ queue_work (iavf_wq , & adapter -> adminq_task );
307
308
308
309
return IRQ_HANDLED ;
309
310
}
@@ -1136,8 +1137,7 @@ void iavf_down(struct iavf_adapter *adapter)
1136
1137
rss -> state = IAVF_ADV_RSS_DEL_REQUEST ;
1137
1138
spin_unlock_bh (& adapter -> adv_rss_lock );
1138
1139
1139
- if (!(adapter -> flags & IAVF_FLAG_PF_COMMS_FAILED ) &&
1140
- adapter -> state != __IAVF_RESETTING ) {
1140
+ if (!(adapter -> flags & IAVF_FLAG_PF_COMMS_FAILED )) {
1141
1141
/* cancel any current operation */
1142
1142
adapter -> current_op = VIRTCHNL_OP_UNKNOWN ;
1143
1143
/* Schedule operations to close down the HW. Don't wait
@@ -2374,17 +2374,22 @@ static void iavf_watchdog_task(struct work_struct *work)
2374
2374
struct iavf_hw * hw = & adapter -> hw ;
2375
2375
u32 reg_val ;
2376
2376
2377
- if (!mutex_trylock (& adapter -> crit_lock ))
2377
+ if (!mutex_trylock (& adapter -> crit_lock )) {
2378
+ if (adapter -> state == __IAVF_REMOVE )
2379
+ return ;
2380
+
2378
2381
goto restart_watchdog ;
2382
+ }
2379
2383
2380
2384
if (adapter -> flags & IAVF_FLAG_PF_COMMS_FAILED )
2381
2385
iavf_change_state (adapter , __IAVF_COMM_FAILED );
2382
2386
2383
- if (adapter -> flags & IAVF_FLAG_RESET_NEEDED &&
2384
- adapter -> state != __IAVF_RESETTING ) {
2385
- iavf_change_state (adapter , __IAVF_RESETTING );
2387
+ if (adapter -> flags & IAVF_FLAG_RESET_NEEDED ) {
2386
2388
adapter -> aq_required = 0 ;
2387
2389
adapter -> current_op = VIRTCHNL_OP_UNKNOWN ;
2390
+ mutex_unlock (& adapter -> crit_lock );
2391
+ queue_work (iavf_wq , & adapter -> reset_task );
2392
+ return ;
2388
2393
}
2389
2394
2390
2395
switch (adapter -> state ) {
@@ -2419,6 +2424,15 @@ static void iavf_watchdog_task(struct work_struct *work)
2419
2424
msecs_to_jiffies (1 ));
2420
2425
return ;
2421
2426
case __IAVF_INIT_FAILED :
2427
+ if (test_bit (__IAVF_IN_REMOVE_TASK ,
2428
+ & adapter -> crit_section )) {
2429
+ /* Do not update the state and do not reschedule
2430
+ * watchdog task, iavf_remove should handle this state
2431
+ * as it can loop forever
2432
+ */
2433
+ mutex_unlock (& adapter -> crit_lock );
2434
+ return ;
2435
+ }
2422
2436
if (++ adapter -> aq_wait_count > IAVF_AQ_MAX_ERR ) {
2423
2437
dev_err (& adapter -> pdev -> dev ,
2424
2438
"Failed to communicate with PF; waiting before retry\n" );
@@ -2435,6 +2449,17 @@ static void iavf_watchdog_task(struct work_struct *work)
2435
2449
queue_delayed_work (iavf_wq , & adapter -> watchdog_task , HZ );
2436
2450
return ;
2437
2451
case __IAVF_COMM_FAILED :
2452
+ if (test_bit (__IAVF_IN_REMOVE_TASK ,
2453
+ & adapter -> crit_section )) {
2454
+ /* Set state to __IAVF_INIT_FAILED and perform remove
2455
+ * steps. Remove IAVF_FLAG_PF_COMMS_FAILED so the task
2456
+ * doesn't bring the state back to __IAVF_COMM_FAILED.
2457
+ */
2458
+ iavf_change_state (adapter , __IAVF_INIT_FAILED );
2459
+ adapter -> flags &= ~IAVF_FLAG_PF_COMMS_FAILED ;
2460
+ mutex_unlock (& adapter -> crit_lock );
2461
+ return ;
2462
+ }
2438
2463
reg_val = rd32 (hw , IAVF_VFGEN_RSTAT ) &
2439
2464
IAVF_VFGEN_RSTAT_VFR_STATE_MASK ;
2440
2465
if (reg_val == VIRTCHNL_VFR_VFACTIVE ||
@@ -2507,7 +2532,8 @@ static void iavf_watchdog_task(struct work_struct *work)
2507
2532
schedule_delayed_work (& adapter -> client_task , msecs_to_jiffies (5 ));
2508
2533
mutex_unlock (& adapter -> crit_lock );
2509
2534
restart_watchdog :
2510
- queue_work (iavf_wq , & adapter -> adminq_task );
2535
+ if (adapter -> state >= __IAVF_DOWN )
2536
+ queue_work (iavf_wq , & adapter -> adminq_task );
2511
2537
if (adapter -> aq_required )
2512
2538
queue_delayed_work (iavf_wq , & adapter -> watchdog_task ,
2513
2539
msecs_to_jiffies (20 ));
@@ -2601,13 +2627,13 @@ static void iavf_reset_task(struct work_struct *work)
2601
2627
/* When device is being removed it doesn't make sense to run the reset
2602
2628
* task, just return in such a case.
2603
2629
*/
2604
- if (mutex_is_locked (& adapter -> remove_lock ))
2605
- return ;
2630
+ if (!mutex_trylock (& adapter -> crit_lock )) {
2631
+ if (adapter -> state != __IAVF_REMOVE )
2632
+ queue_work (iavf_wq , & adapter -> reset_task );
2606
2633
2607
- if (iavf_lock_timeout (& adapter -> crit_lock , 200 )) {
2608
- schedule_work (& adapter -> reset_task );
2609
2634
return ;
2610
2635
}
2636
+
2611
2637
while (!mutex_trylock (& adapter -> client_lock ))
2612
2638
usleep_range (500 , 1000 );
2613
2639
if (CLIENT_ENABLED (adapter )) {
@@ -2662,6 +2688,7 @@ static void iavf_reset_task(struct work_struct *work)
2662
2688
reg_val );
2663
2689
iavf_disable_vf (adapter );
2664
2690
mutex_unlock (& adapter -> client_lock );
2691
+ mutex_unlock (& adapter -> crit_lock );
2665
2692
return ; /* Do not attempt to reinit. It's dead, Jim. */
2666
2693
}
2667
2694
@@ -2670,8 +2697,7 @@ static void iavf_reset_task(struct work_struct *work)
2670
2697
* ndo_open() returning, so we can't assume it means all our open
2671
2698
* tasks have finished, since we're not holding the rtnl_lock here.
2672
2699
*/
2673
- running = ((adapter -> state == __IAVF_RUNNING ) ||
2674
- (adapter -> state == __IAVF_RESETTING ));
2700
+ running = adapter -> state == __IAVF_RUNNING ;
2675
2701
2676
2702
if (running ) {
2677
2703
netdev -> flags &= ~IFF_UP ;
@@ -2826,13 +2852,19 @@ static void iavf_adminq_task(struct work_struct *work)
2826
2852
if (adapter -> flags & IAVF_FLAG_PF_COMMS_FAILED )
2827
2853
goto out ;
2828
2854
2855
+ if (!mutex_trylock (& adapter -> crit_lock )) {
2856
+ if (adapter -> state == __IAVF_REMOVE )
2857
+ return ;
2858
+
2859
+ queue_work (iavf_wq , & adapter -> adminq_task );
2860
+ goto out ;
2861
+ }
2862
+
2829
2863
event .buf_len = IAVF_MAX_AQ_BUF_SIZE ;
2830
2864
event .msg_buf = kzalloc (event .buf_len , GFP_KERNEL );
2831
2865
if (!event .msg_buf )
2832
2866
goto out ;
2833
2867
2834
- if (iavf_lock_timeout (& adapter -> crit_lock , 200 ))
2835
- goto freedom ;
2836
2868
do {
2837
2869
ret = iavf_clean_arq_element (hw , & event , & pending );
2838
2870
v_op = (enum virtchnl_ops )le32_to_cpu (event .desc .cookie_high );
@@ -2848,6 +2880,24 @@ static void iavf_adminq_task(struct work_struct *work)
2848
2880
} while (pending );
2849
2881
mutex_unlock (& adapter -> crit_lock );
2850
2882
2883
+ if ((adapter -> flags & IAVF_FLAG_SETUP_NETDEV_FEATURES )) {
2884
+ if (adapter -> netdev_registered ||
2885
+ !test_bit (__IAVF_IN_REMOVE_TASK , & adapter -> crit_section )) {
2886
+ struct net_device * netdev = adapter -> netdev ;
2887
+
2888
+ rtnl_lock ();
2889
+ netdev_update_features (netdev );
2890
+ rtnl_unlock ();
2891
+ /* Request VLAN offload settings */
2892
+ if (VLAN_V2_ALLOWED (adapter ))
2893
+ iavf_set_vlan_offload_features
2894
+ (adapter , 0 , netdev -> features );
2895
+
2896
+ iavf_set_queue_vlan_tag_loc (adapter );
2897
+ }
2898
+
2899
+ adapter -> flags &= ~IAVF_FLAG_SETUP_NETDEV_FEATURES ;
2900
+ }
2851
2901
if ((adapter -> flags &
2852
2902
(IAVF_FLAG_RESET_PENDING | IAVF_FLAG_RESET_NEEDED )) ||
2853
2903
adapter -> state == __IAVF_RESETTING )
@@ -3800,11 +3850,12 @@ static int iavf_close(struct net_device *netdev)
3800
3850
struct iavf_adapter * adapter = netdev_priv (netdev );
3801
3851
int status ;
3802
3852
3803
- if (adapter -> state <= __IAVF_DOWN_PENDING )
3804
- return 0 ;
3853
+ mutex_lock (& adapter -> crit_lock );
3805
3854
3806
- while (!mutex_trylock (& adapter -> crit_lock ))
3807
- usleep_range (500 , 1000 );
3855
+ if (adapter -> state <= __IAVF_DOWN_PENDING ) {
3856
+ mutex_unlock (& adapter -> crit_lock );
3857
+ return 0 ;
3858
+ }
3808
3859
3809
3860
set_bit (__IAVF_VSI_DOWN , adapter -> vsi .state );
3810
3861
if (CLIENT_ENABLED (adapter ))
@@ -3853,8 +3904,11 @@ static int iavf_change_mtu(struct net_device *netdev, int new_mtu)
3853
3904
iavf_notify_client_l2_params (& adapter -> vsi );
3854
3905
adapter -> flags |= IAVF_FLAG_SERVICE_CLIENT_REQUESTED ;
3855
3906
}
3856
- adapter -> flags |= IAVF_FLAG_RESET_NEEDED ;
3857
- queue_work (iavf_wq , & adapter -> reset_task );
3907
+
3908
+ if (netif_running (netdev )) {
3909
+ adapter -> flags |= IAVF_FLAG_RESET_NEEDED ;
3910
+ queue_work (iavf_wq , & adapter -> reset_task );
3911
+ }
3858
3912
3859
3913
return 0 ;
3860
3914
}
@@ -4431,7 +4485,6 @@ static int iavf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
4431
4485
*/
4432
4486
mutex_init (& adapter -> crit_lock );
4433
4487
mutex_init (& adapter -> client_lock );
4434
- mutex_init (& adapter -> remove_lock );
4435
4488
mutex_init (& hw -> aq .asq_mutex );
4436
4489
mutex_init (& hw -> aq .arq_mutex );
4437
4490
@@ -4547,7 +4600,6 @@ static int __maybe_unused iavf_resume(struct device *dev_d)
4547
4600
static void iavf_remove (struct pci_dev * pdev )
4548
4601
{
4549
4602
struct iavf_adapter * adapter = iavf_pdev_to_adapter (pdev );
4550
- enum iavf_state_t prev_state = adapter -> last_state ;
4551
4603
struct net_device * netdev = adapter -> netdev ;
4552
4604
struct iavf_fdir_fltr * fdir , * fdirtmp ;
4553
4605
struct iavf_vlan_filter * vlf , * vlftmp ;
@@ -4556,14 +4608,30 @@ static void iavf_remove(struct pci_dev *pdev)
4556
4608
struct iavf_cloud_filter * cf , * cftmp ;
4557
4609
struct iavf_hw * hw = & adapter -> hw ;
4558
4610
int err ;
4559
- /* Indicate we are in remove and not to run reset_task */
4560
- mutex_lock (& adapter -> remove_lock );
4561
- cancel_work_sync (& adapter -> reset_task );
4611
+
4612
+ set_bit (__IAVF_IN_REMOVE_TASK , & adapter -> crit_section );
4613
+ /* Wait until port initialization is complete.
4614
+ * There are flows where register/unregister netdev may race.
4615
+ */
4616
+ while (1 ) {
4617
+ mutex_lock (& adapter -> crit_lock );
4618
+ if (adapter -> state == __IAVF_RUNNING ||
4619
+ adapter -> state == __IAVF_DOWN ||
4620
+ adapter -> state == __IAVF_INIT_FAILED ) {
4621
+ mutex_unlock (& adapter -> crit_lock );
4622
+ break ;
4623
+ }
4624
+
4625
+ mutex_unlock (& adapter -> crit_lock );
4626
+ usleep_range (500 , 1000 );
4627
+ }
4562
4628
cancel_delayed_work_sync (& adapter -> watchdog_task );
4563
- cancel_delayed_work_sync ( & adapter -> client_task );
4629
+
4564
4630
if (adapter -> netdev_registered ) {
4565
- unregister_netdev (netdev );
4631
+ rtnl_lock ();
4632
+ unregister_netdevice (netdev );
4566
4633
adapter -> netdev_registered = false;
4634
+ rtnl_unlock ();
4567
4635
}
4568
4636
if (CLIENT_ALLOWED (adapter )) {
4569
4637
err = iavf_lan_del_device (adapter );
@@ -4572,44 +4640,35 @@ static void iavf_remove(struct pci_dev *pdev)
4572
4640
err );
4573
4641
}
4574
4642
4643
+ mutex_lock (& adapter -> crit_lock );
4644
+ dev_info (& adapter -> pdev -> dev , "Remove device\n" );
4645
+ iavf_change_state (adapter , __IAVF_REMOVE );
4646
+
4575
4647
iavf_request_reset (adapter );
4576
4648
msleep (50 );
4577
4649
/* If the FW isn't responding, kick it once, but only once. */
4578
4650
if (!iavf_asq_done (hw )) {
4579
4651
iavf_request_reset (adapter );
4580
4652
msleep (50 );
4581
4653
}
4582
- if (iavf_lock_timeout (& adapter -> crit_lock , 5000 ))
4583
- dev_warn (& adapter -> pdev -> dev , "failed to acquire crit_lock in %s\n" , __FUNCTION__ );
4584
4654
4585
- dev_info ( & adapter -> pdev -> dev , "Removing device\n" );
4655
+ iavf_misc_irq_disable ( adapter );
4586
4656
/* Shut down all the garbage mashers on the detention level */
4587
- iavf_change_state (adapter , __IAVF_REMOVE );
4657
+ cancel_work_sync (& adapter -> reset_task );
4658
+ cancel_delayed_work_sync (& adapter -> watchdog_task );
4659
+ cancel_work_sync (& adapter -> adminq_task );
4660
+ cancel_delayed_work_sync (& adapter -> client_task );
4661
+
4588
4662
adapter -> aq_required = 0 ;
4589
4663
adapter -> flags &= ~IAVF_FLAG_REINIT_ITR_NEEDED ;
4590
4664
4591
4665
iavf_free_all_tx_resources (adapter );
4592
4666
iavf_free_all_rx_resources (adapter );
4593
- iavf_misc_irq_disable (adapter );
4594
4667
iavf_free_misc_irq (adapter );
4595
4668
4596
- /* In case we enter iavf_remove from erroneous state, free traffic irqs
4597
- * here, so as to not cause a kernel crash, when calling
4598
- * iavf_reset_interrupt_capability.
4599
- */
4600
- if ((adapter -> last_state == __IAVF_RESETTING &&
4601
- prev_state != __IAVF_DOWN ) ||
4602
- (adapter -> last_state == __IAVF_RUNNING &&
4603
- !(netdev -> flags & IFF_UP )))
4604
- iavf_free_traffic_irqs (adapter );
4605
-
4606
4669
iavf_reset_interrupt_capability (adapter );
4607
4670
iavf_free_q_vectors (adapter );
4608
4671
4609
- cancel_delayed_work_sync (& adapter -> watchdog_task );
4610
-
4611
- cancel_work_sync (& adapter -> adminq_task );
4612
-
4613
4672
iavf_free_rss (adapter );
4614
4673
4615
4674
if (hw -> aq .asq .count )
@@ -4621,8 +4680,6 @@ static void iavf_remove(struct pci_dev *pdev)
4621
4680
mutex_destroy (& adapter -> client_lock );
4622
4681
mutex_unlock (& adapter -> crit_lock );
4623
4682
mutex_destroy (& adapter -> crit_lock );
4624
- mutex_unlock (& adapter -> remove_lock );
4625
- mutex_destroy (& adapter -> remove_lock );
4626
4683
4627
4684
iounmap (hw -> hw_addr );
4628
4685
pci_release_regions (pdev );
0 commit comments