@@ -1968,6 +1968,7 @@ static int iavf_reinit_interrupt_scheme(struct iavf_adapter *adapter, bool runni
19681968static void iavf_finish_config (struct work_struct * work )
19691969{
19701970 struct iavf_adapter * adapter ;
1971+ bool netdev_released = false;
19711972 int pairs , err ;
19721973
19731974 adapter = container_of (work , struct iavf_adapter , finish_config );
@@ -1988,7 +1989,16 @@ static void iavf_finish_config(struct work_struct *work)
19881989
19891990 switch (adapter -> state ) {
19901991 case __IAVF_DOWN :
1992+ /* Set the real number of queues when reset occurs while
1993+ * state == __IAVF_DOWN
1994+ */
1995+ pairs = adapter -> num_active_queues ;
1996+ netif_set_real_num_rx_queues (adapter -> netdev , pairs );
1997+ netif_set_real_num_tx_queues (adapter -> netdev , pairs );
1998+
19911999 if (adapter -> netdev -> reg_state != NETREG_REGISTERED ) {
2000+ mutex_unlock (& adapter -> netdev -> lock );
2001+ netdev_released = true;
19922002 err = register_netdevice (adapter -> netdev );
19932003 if (err ) {
19942004 dev_err (& adapter -> pdev -> dev , "Unable to register netdev (%d)\n" ,
@@ -2003,11 +2013,7 @@ static void iavf_finish_config(struct work_struct *work)
20032013 goto out ;
20042014 }
20052015 }
2006-
2007- /* Set the real number of queues when reset occurs while
2008- * state == __IAVF_DOWN
2009- */
2010- fallthrough ;
2016+ break ;
20112017 case __IAVF_RUNNING :
20122018 pairs = adapter -> num_active_queues ;
20132019 netif_set_real_num_rx_queues (adapter -> netdev , pairs );
@@ -2020,7 +2026,8 @@ static void iavf_finish_config(struct work_struct *work)
20202026
20212027out :
20222028 mutex_unlock (& adapter -> crit_lock );
2023- mutex_unlock (& adapter -> netdev -> lock );
2029+ if (!netdev_released )
2030+ mutex_unlock (& adapter -> netdev -> lock );
20242031 rtnl_unlock ();
20252032}
20262033
@@ -2713,12 +2720,16 @@ static void iavf_watchdog_task(struct work_struct *work)
27132720 struct iavf_adapter * adapter = container_of (work ,
27142721 struct iavf_adapter ,
27152722 watchdog_task .work );
2723+ struct net_device * netdev = adapter -> netdev ;
27162724 struct iavf_hw * hw = & adapter -> hw ;
27172725 u32 reg_val ;
27182726
2727+ mutex_lock (& netdev -> lock );
27192728 if (!mutex_trylock (& adapter -> crit_lock )) {
2720- if (adapter -> state == __IAVF_REMOVE )
2729+ if (adapter -> state == __IAVF_REMOVE ) {
2730+ mutex_unlock (& netdev -> lock );
27212731 return ;
2732+ }
27222733
27232734 goto restart_watchdog ;
27242735 }
@@ -2730,30 +2741,35 @@ static void iavf_watchdog_task(struct work_struct *work)
27302741 case __IAVF_STARTUP :
27312742 iavf_startup (adapter );
27322743 mutex_unlock (& adapter -> crit_lock );
2744+ mutex_unlock (& netdev -> lock );
27332745 queue_delayed_work (adapter -> wq , & adapter -> watchdog_task ,
27342746 msecs_to_jiffies (30 ));
27352747 return ;
27362748 case __IAVF_INIT_VERSION_CHECK :
27372749 iavf_init_version_check (adapter );
27382750 mutex_unlock (& adapter -> crit_lock );
2751+ mutex_unlock (& netdev -> lock );
27392752 queue_delayed_work (adapter -> wq , & adapter -> watchdog_task ,
27402753 msecs_to_jiffies (30 ));
27412754 return ;
27422755 case __IAVF_INIT_GET_RESOURCES :
27432756 iavf_init_get_resources (adapter );
27442757 mutex_unlock (& adapter -> crit_lock );
2758+ mutex_unlock (& netdev -> lock );
27452759 queue_delayed_work (adapter -> wq , & adapter -> watchdog_task ,
27462760 msecs_to_jiffies (1 ));
27472761 return ;
27482762 case __IAVF_INIT_EXTENDED_CAPS :
27492763 iavf_init_process_extended_caps (adapter );
27502764 mutex_unlock (& adapter -> crit_lock );
2765+ mutex_unlock (& netdev -> lock );
27512766 queue_delayed_work (adapter -> wq , & adapter -> watchdog_task ,
27522767 msecs_to_jiffies (1 ));
27532768 return ;
27542769 case __IAVF_INIT_CONFIG_ADAPTER :
27552770 iavf_init_config_adapter (adapter );
27562771 mutex_unlock (& adapter -> crit_lock );
2772+ mutex_unlock (& netdev -> lock );
27572773 queue_delayed_work (adapter -> wq , & adapter -> watchdog_task ,
27582774 msecs_to_jiffies (1 ));
27592775 return ;
@@ -2765,6 +2781,7 @@ static void iavf_watchdog_task(struct work_struct *work)
27652781 * as it can loop forever
27662782 */
27672783 mutex_unlock (& adapter -> crit_lock );
2784+ mutex_unlock (& netdev -> lock );
27682785 return ;
27692786 }
27702787 if (++ adapter -> aq_wait_count > IAVF_AQ_MAX_ERR ) {
@@ -2773,13 +2790,15 @@ static void iavf_watchdog_task(struct work_struct *work)
27732790 adapter -> flags |= IAVF_FLAG_PF_COMMS_FAILED ;
27742791 iavf_shutdown_adminq (hw );
27752792 mutex_unlock (& adapter -> crit_lock );
2793+ mutex_unlock (& netdev -> lock );
27762794 queue_delayed_work (adapter -> wq ,
27772795 & adapter -> watchdog_task , (5 * HZ ));
27782796 return ;
27792797 }
27802798 /* Try again from failed step*/
27812799 iavf_change_state (adapter , adapter -> last_state );
27822800 mutex_unlock (& adapter -> crit_lock );
2801+ mutex_unlock (& netdev -> lock );
27832802 queue_delayed_work (adapter -> wq , & adapter -> watchdog_task , HZ );
27842803 return ;
27852804 case __IAVF_COMM_FAILED :
@@ -2792,6 +2811,7 @@ static void iavf_watchdog_task(struct work_struct *work)
27922811 iavf_change_state (adapter , __IAVF_INIT_FAILED );
27932812 adapter -> flags &= ~IAVF_FLAG_PF_COMMS_FAILED ;
27942813 mutex_unlock (& adapter -> crit_lock );
2814+ mutex_unlock (& netdev -> lock );
27952815 return ;
27962816 }
27972817 reg_val = rd32 (hw , IAVF_VFGEN_RSTAT ) &
@@ -2811,12 +2831,14 @@ static void iavf_watchdog_task(struct work_struct *work)
28112831 adapter -> aq_required = 0 ;
28122832 adapter -> current_op = VIRTCHNL_OP_UNKNOWN ;
28132833 mutex_unlock (& adapter -> crit_lock );
2834+ mutex_unlock (& netdev -> lock );
28142835 queue_delayed_work (adapter -> wq ,
28152836 & adapter -> watchdog_task ,
28162837 msecs_to_jiffies (10 ));
28172838 return ;
28182839 case __IAVF_RESETTING :
28192840 mutex_unlock (& adapter -> crit_lock );
2841+ mutex_unlock (& netdev -> lock );
28202842 queue_delayed_work (adapter -> wq , & adapter -> watchdog_task ,
28212843 HZ * 2 );
28222844 return ;
@@ -2847,6 +2869,7 @@ static void iavf_watchdog_task(struct work_struct *work)
28472869 case __IAVF_REMOVE :
28482870 default :
28492871 mutex_unlock (& adapter -> crit_lock );
2872+ mutex_unlock (& netdev -> lock );
28502873 return ;
28512874 }
28522875
@@ -2858,12 +2881,14 @@ static void iavf_watchdog_task(struct work_struct *work)
28582881 dev_err (& adapter -> pdev -> dev , "Hardware reset detected\n" );
28592882 iavf_schedule_reset (adapter , IAVF_FLAG_RESET_PENDING );
28602883 mutex_unlock (& adapter -> crit_lock );
2884+ mutex_unlock (& netdev -> lock );
28612885 queue_delayed_work (adapter -> wq ,
28622886 & adapter -> watchdog_task , HZ * 2 );
28632887 return ;
28642888 }
28652889
28662890 mutex_unlock (& adapter -> crit_lock );
2891+ mutex_unlock (& netdev -> lock );
28672892restart_watchdog :
28682893 if (adapter -> state >= __IAVF_DOWN )
28692894 queue_work (adapter -> wq , & adapter -> adminq_task );
@@ -4340,14 +4365,17 @@ static int iavf_open(struct net_device *netdev)
43404365 return - EIO ;
43414366 }
43424367
4368+ mutex_lock (& netdev -> lock );
43434369 while (!mutex_trylock (& adapter -> crit_lock )) {
43444370 /* If we are in __IAVF_INIT_CONFIG_ADAPTER state the crit_lock
43454371 * is already taken and iavf_open is called from an upper
43464372 * device's notifier reacting on NETDEV_REGISTER event.
43474373 * We have to leave here to avoid dead lock.
43484374 */
4349- if (adapter -> state == __IAVF_INIT_CONFIG_ADAPTER )
4375+ if (adapter -> state == __IAVF_INIT_CONFIG_ADAPTER ) {
4376+ mutex_unlock (& netdev -> lock );
43504377 return - EBUSY ;
4378+ }
43514379
43524380 usleep_range (500 , 1000 );
43534381 }
@@ -4396,6 +4424,7 @@ static int iavf_open(struct net_device *netdev)
43964424 iavf_irq_enable (adapter , true);
43974425
43984426 mutex_unlock (& adapter -> crit_lock );
4427+ mutex_unlock (& netdev -> lock );
43994428
44004429 return 0 ;
44014430
@@ -4408,6 +4437,7 @@ static int iavf_open(struct net_device *netdev)
44084437 iavf_free_all_tx_resources (adapter );
44094438err_unlock :
44104439 mutex_unlock (& adapter -> crit_lock );
4440+ mutex_unlock (& netdev -> lock );
44114441
44124442 return err ;
44134443}
@@ -4429,10 +4459,12 @@ static int iavf_close(struct net_device *netdev)
44294459 u64 aq_to_restore ;
44304460 int status ;
44314461
4462+ mutex_lock (& netdev -> lock );
44324463 mutex_lock (& adapter -> crit_lock );
44334464
44344465 if (adapter -> state <= __IAVF_DOWN_PENDING ) {
44354466 mutex_unlock (& adapter -> crit_lock );
4467+ mutex_unlock (& netdev -> lock );
44364468 return 0 ;
44374469 }
44384470
@@ -4466,6 +4498,7 @@ static int iavf_close(struct net_device *netdev)
44664498 iavf_free_traffic_irqs (adapter );
44674499
44684500 mutex_unlock (& adapter -> crit_lock );
4501+ mutex_unlock (& netdev -> lock );
44694502
44704503 /* We explicitly don't free resources here because the hardware is
44714504 * still active and can DMA into memory. Resources are cleared in
@@ -5342,6 +5375,7 @@ static int iavf_suspend(struct device *dev_d)
53425375
53435376 netif_device_detach (netdev );
53445377
5378+ mutex_lock (& netdev -> lock );
53455379 mutex_lock (& adapter -> crit_lock );
53465380
53475381 if (netif_running (netdev )) {
@@ -5353,6 +5387,7 @@ static int iavf_suspend(struct device *dev_d)
53535387 iavf_reset_interrupt_capability (adapter );
53545388
53555389 mutex_unlock (& adapter -> crit_lock );
5390+ mutex_unlock (& netdev -> lock );
53565391
53575392 return 0 ;
53585393}
@@ -5451,6 +5486,7 @@ static void iavf_remove(struct pci_dev *pdev)
54515486 if (netdev -> reg_state == NETREG_REGISTERED )
54525487 unregister_netdev (netdev );
54535488
5489+ mutex_lock (& netdev -> lock );
54545490 mutex_lock (& adapter -> crit_lock );
54555491 dev_info (& adapter -> pdev -> dev , "Removing device\n" );
54565492 iavf_change_state (adapter , __IAVF_REMOVE );
@@ -5487,6 +5523,7 @@ static void iavf_remove(struct pci_dev *pdev)
54875523 mutex_destroy (& hw -> aq .asq_mutex );
54885524 mutex_unlock (& adapter -> crit_lock );
54895525 mutex_destroy (& adapter -> crit_lock );
5526+ mutex_unlock (& netdev -> lock );
54905527
54915528 iounmap (hw -> hw_addr );
54925529 pci_release_regions (pdev );
0 commit comments