@@ -440,6 +440,9 @@ void hclgevf_update_link_status(struct hclgevf_dev *hdev, int link_state)
440
440
struct hnae3_client * rclient ;
441
441
struct hnae3_client * client ;
442
442
443
+ if (test_and_set_bit (HCLGEVF_STATE_LINK_UPDATING , & hdev -> state ))
444
+ return ;
445
+
443
446
client = handle -> client ;
444
447
rclient = hdev -> roce_client ;
445
448
@@ -452,6 +455,8 @@ void hclgevf_update_link_status(struct hclgevf_dev *hdev, int link_state)
452
455
rclient -> ops -> link_status_change (rhandle , !!link_state );
453
456
hdev -> hw .mac .link = link_state ;
454
457
}
458
+
459
+ clear_bit (HCLGEVF_STATE_LINK_UPDATING , & hdev -> state );
455
460
}
456
461
457
462
static void hclgevf_update_link_mode (struct hclgevf_dev * hdev )
@@ -1767,54 +1772,38 @@ static void hclgevf_get_misc_vector(struct hclgevf_dev *hdev)
1767
1772
1768
1773
void hclgevf_reset_task_schedule (struct hclgevf_dev * hdev )
1769
1774
{
1770
- if (!test_bit (HCLGEVF_STATE_RST_SERVICE_SCHED , & hdev -> state ) &&
1771
- !test_bit (HCLGEVF_STATE_REMOVING , & hdev -> state )) {
1772
- set_bit (HCLGEVF_STATE_RST_SERVICE_SCHED , & hdev -> state );
1773
- schedule_work (& hdev -> rst_service_task );
1774
- }
1775
+ if (!test_bit (HCLGEVF_STATE_REMOVING , & hdev -> state ) &&
1776
+ !test_and_set_bit (HCLGEVF_STATE_RST_SERVICE_SCHED ,
1777
+ & hdev -> state ))
1778
+ mod_delayed_work (system_wq , & hdev -> service_task , 0 );
1775
1779
}
1776
1780
1777
1781
void hclgevf_mbx_task_schedule (struct hclgevf_dev * hdev )
1778
1782
{
1779
- if (!test_bit (HCLGEVF_STATE_MBX_SERVICE_SCHED , & hdev -> state ) &&
1780
- !test_bit (HCLGEVF_STATE_MBX_HANDLING , & hdev -> state )) {
1781
- set_bit (HCLGEVF_STATE_MBX_SERVICE_SCHED , & hdev -> state );
1782
- schedule_work (& hdev -> mbx_service_task );
1783
- }
1783
+ if (!test_bit (HCLGEVF_STATE_REMOVING , & hdev -> state ) &&
1784
+ !test_and_set_bit (HCLGEVF_STATE_MBX_SERVICE_SCHED ,
1785
+ & hdev -> state ))
1786
+ mod_delayed_work (system_wq , & hdev -> service_task , 0 );
1784
1787
}
1785
1788
1786
- static void hclgevf_task_schedule (struct hclgevf_dev * hdev )
1789
+ static void hclgevf_task_schedule (struct hclgevf_dev * hdev ,
1790
+ unsigned long delay )
1787
1791
{
1788
- if (!test_bit (HCLGEVF_STATE_DOWN , & hdev -> state ) &&
1789
- !test_and_set_bit (HCLGEVF_STATE_SERVICE_SCHED , & hdev -> state )) {
1790
- mod_delayed_work (system_wq , & hdev -> service_task ,
1791
- round_jiffies_relative (HZ ));
1792
- hdev -> stats_timer ++ ;
1793
- }
1792
+ if (!test_bit (HCLGEVF_STATE_REMOVING , & hdev -> state ))
1793
+ mod_delayed_work (system_wq , & hdev -> service_task , delay );
1794
1794
}
1795
1795
1796
- static void hclgevf_deferred_task_schedule (struct hclgevf_dev * hdev )
1797
- {
1798
- /* if we have any pending mailbox event then schedule the mbx task */
1799
- if (hdev -> mbx_event_pending )
1800
- hclgevf_mbx_task_schedule (hdev );
1801
-
1802
- if (test_bit (HCLGEVF_RESET_PENDING , & hdev -> reset_state ))
1803
- hclgevf_reset_task_schedule (hdev );
1804
- }
1805
-
1806
- static void hclgevf_reset_service_task (struct work_struct * work )
1796
+ static void hclgevf_reset_service_task (struct hclgevf_dev * hdev )
1807
1797
{
1808
1798
#define HCLGEVF_MAX_RESET_ATTEMPTS_CNT 3
1809
1799
1810
- struct hclgevf_dev * hdev =
1811
- container_of (work , struct hclgevf_dev , rst_service_task );
1812
1800
int ret ;
1813
1801
1814
- if (test_and_set_bit ( HCLGEVF_STATE_RST_HANDLING , & hdev -> state ))
1802
+ if (! test_and_clear_bit ( HCLGEVF_STATE_RST_SERVICE_SCHED , & hdev -> state ))
1815
1803
return ;
1816
1804
1817
- clear_bit (HCLGEVF_STATE_RST_SERVICE_SCHED , & hdev -> state );
1805
+ if (test_and_set_bit (HCLGEVF_STATE_RST_HANDLING , & hdev -> state ))
1806
+ return ;
1818
1807
1819
1808
if (test_and_clear_bit (HCLGEVF_RESET_PENDING ,
1820
1809
& hdev -> reset_state )) {
@@ -1877,39 +1866,24 @@ static void hclgevf_reset_service_task(struct work_struct *work)
1877
1866
clear_bit (HCLGEVF_STATE_RST_HANDLING , & hdev -> state );
1878
1867
}
1879
1868
1880
- static void hclgevf_mailbox_service_task (struct work_struct * work )
1869
+ static void hclgevf_mailbox_service_task (struct hclgevf_dev * hdev )
1881
1870
{
1882
- struct hclgevf_dev * hdev ;
1883
-
1884
- hdev = container_of (work , struct hclgevf_dev , mbx_service_task );
1871
+ if (!test_and_clear_bit (HCLGEVF_STATE_MBX_SERVICE_SCHED , & hdev -> state ))
1872
+ return ;
1885
1873
1886
1874
if (test_and_set_bit (HCLGEVF_STATE_MBX_HANDLING , & hdev -> state ))
1887
1875
return ;
1888
1876
1889
- clear_bit (HCLGEVF_STATE_MBX_SERVICE_SCHED , & hdev -> state );
1890
-
1891
1877
hclgevf_mbx_async_handler (hdev );
1892
1878
1893
1879
clear_bit (HCLGEVF_STATE_MBX_HANDLING , & hdev -> state );
1894
1880
}
1895
1881
1896
- static void hclgevf_keep_alive_timer (struct timer_list * t )
1897
- {
1898
- struct hclgevf_dev * hdev = from_timer (hdev , t , keep_alive_timer );
1899
-
1900
- schedule_work (& hdev -> keep_alive_task );
1901
- mod_timer (& hdev -> keep_alive_timer , jiffies +
1902
- HCLGEVF_KEEP_ALIVE_TASK_INTERVAL * HZ );
1903
- }
1904
-
1905
- static void hclgevf_keep_alive_task (struct work_struct * work )
1882
+ static void hclgevf_keep_alive (struct hclgevf_dev * hdev )
1906
1883
{
1907
- struct hclgevf_dev * hdev ;
1908
1884
u8 respmsg ;
1909
1885
int ret ;
1910
1886
1911
- hdev = container_of (work , struct hclgevf_dev , keep_alive_task );
1912
-
1913
1887
if (test_bit (HCLGEVF_STATE_CMD_DISABLE , & hdev -> state ))
1914
1888
return ;
1915
1889
@@ -1920,19 +1894,32 @@ static void hclgevf_keep_alive_task(struct work_struct *work)
1920
1894
"VF sends keep alive cmd failed(=%d)\n" , ret );
1921
1895
}
1922
1896
1923
- static void hclgevf_service_task (struct work_struct * work )
1897
+ static void hclgevf_periodic_service_task (struct hclgevf_dev * hdev )
1924
1898
{
1925
- struct hnae3_handle * handle ;
1926
- struct hclgevf_dev * hdev ;
1899
+ unsigned long delta = round_jiffies_relative ( HZ ) ;
1900
+ struct hnae3_handle * handle = & hdev -> nic ;
1927
1901
1928
- hdev = container_of ( work , struct hclgevf_dev , service_task . work );
1929
- handle = & hdev -> nic ;
1902
+ if ( time_is_after_jiffies ( hdev -> last_serv_processed + HZ )) {
1903
+ delta = jiffies - hdev -> last_serv_processed ;
1930
1904
1931
- if (hdev -> stats_timer >= HCLGEVF_STATS_TIMER_INTERVAL ) {
1932
- hclgevf_tqps_update_stats (handle );
1933
- hdev -> stats_timer = 0 ;
1905
+ if (delta < round_jiffies_relative (HZ )) {
1906
+ delta = round_jiffies_relative (HZ ) - delta ;
1907
+ goto out ;
1908
+ }
1909
+ }
1910
+
1911
+ hdev -> serv_processed_cnt ++ ;
1912
+ if (!(hdev -> serv_processed_cnt % HCLGEVF_KEEP_ALIVE_TASK_INTERVAL ))
1913
+ hclgevf_keep_alive (hdev );
1914
+
1915
+ if (test_bit (HCLGEVF_STATE_DOWN , & hdev -> state )) {
1916
+ hdev -> last_serv_processed = jiffies ;
1917
+ goto out ;
1934
1918
}
1935
1919
1920
+ if (!(hdev -> serv_processed_cnt % HCLGEVF_STATS_TIMER_INTERVAL ))
1921
+ hclgevf_tqps_update_stats (handle );
1922
+
1936
1923
/* request the link status from the PF. PF would be able to tell VF
1937
1924
* about such updates in future so we might remove this later
1938
1925
*/
@@ -1942,11 +1929,27 @@ static void hclgevf_service_task(struct work_struct *work)
1942
1929
1943
1930
hclgevf_sync_vlan_filter (hdev );
1944
1931
1945
- hclgevf_deferred_task_schedule ( hdev ) ;
1932
+ hdev -> last_serv_processed = jiffies ;
1946
1933
1947
- clear_bit (HCLGEVF_STATE_SERVICE_SCHED , & hdev -> state );
1934
+ out :
1935
+ hclgevf_task_schedule (hdev , delta );
1936
+ }
1937
+
1938
+ static void hclgevf_service_task (struct work_struct * work )
1939
+ {
1940
+ struct hclgevf_dev * hdev = container_of (work , struct hclgevf_dev ,
1941
+ service_task .work );
1948
1942
1949
- hclgevf_task_schedule (hdev );
1943
+ hclgevf_reset_service_task (hdev );
1944
+ hclgevf_mailbox_service_task (hdev );
1945
+ hclgevf_periodic_service_task (hdev );
1946
+
1947
+ /* Handle reset and mbx again in case periodical task delays the
1948
+ * handling by calling hclgevf_task_schedule() in
1949
+ * hclgevf_periodic_service_task()
1950
+ */
1951
+ hclgevf_reset_service_task (hdev );
1952
+ hclgevf_mailbox_service_task (hdev );
1950
1953
}
1951
1954
1952
1955
static void hclgevf_clear_event_cause (struct hclgevf_dev * hdev , u32 regclr )
@@ -2183,16 +2186,31 @@ static int hclgevf_init_vlan_config(struct hclgevf_dev *hdev)
2183
2186
false);
2184
2187
}
2185
2188
2189
+ static void hclgevf_flush_link_update (struct hclgevf_dev * hdev )
2190
+ {
2191
+ #define HCLGEVF_FLUSH_LINK_TIMEOUT 100000
2192
+
2193
+ unsigned long last = hdev -> serv_processed_cnt ;
2194
+ int i = 0 ;
2195
+
2196
+ while (test_bit (HCLGEVF_STATE_LINK_UPDATING , & hdev -> state ) &&
2197
+ i ++ < HCLGEVF_FLUSH_LINK_TIMEOUT &&
2198
+ last == hdev -> serv_processed_cnt )
2199
+ usleep_range (1 , 1 );
2200
+ }
2201
+
2186
2202
static void hclgevf_set_timer_task (struct hnae3_handle * handle , bool enable )
2187
2203
{
2188
2204
struct hclgevf_dev * hdev = hclgevf_ae_get_hdev (handle );
2189
2205
2190
2206
if (enable ) {
2191
- hclgevf_task_schedule (hdev );
2207
+ hclgevf_task_schedule (hdev , 0 );
2192
2208
} else {
2193
2209
set_bit (HCLGEVF_STATE_DOWN , & hdev -> state );
2194
- cancel_delayed_work_sync (& hdev -> service_task );
2195
- clear_bit (HCLGEVF_STATE_SERVICE_SCHED , & hdev -> state );
2210
+
2211
+ /* flush memory to make sure DOWN is seen by service task */
2212
+ smp_mb__before_atomic ();
2213
+ hclgevf_flush_link_update (hdev );
2196
2214
}
2197
2215
}
2198
2216
@@ -2239,16 +2257,12 @@ static int hclgevf_set_alive(struct hnae3_handle *handle, bool alive)
2239
2257
2240
2258
static int hclgevf_client_start (struct hnae3_handle * handle )
2241
2259
{
2242
- struct hclgevf_dev * hdev = hclgevf_ae_get_hdev (handle );
2243
2260
int ret ;
2244
2261
2245
2262
ret = hclgevf_set_alive (handle , true);
2246
2263
if (ret )
2247
2264
return ret ;
2248
2265
2249
- mod_timer (& hdev -> keep_alive_timer , jiffies +
2250
- HCLGEVF_KEEP_ALIVE_TASK_INTERVAL * HZ );
2251
-
2252
2266
return 0 ;
2253
2267
}
2254
2268
@@ -2261,22 +2275,14 @@ static void hclgevf_client_stop(struct hnae3_handle *handle)
2261
2275
if (ret )
2262
2276
dev_warn (& hdev -> pdev -> dev ,
2263
2277
"%s failed %d\n" , __func__ , ret );
2264
-
2265
- del_timer_sync (& hdev -> keep_alive_timer );
2266
- cancel_work_sync (& hdev -> keep_alive_task );
2267
2278
}
2268
2279
2269
2280
static void hclgevf_state_init (struct hclgevf_dev * hdev )
2270
2281
{
2271
- /* setup tasks for the MBX */
2272
- INIT_WORK (& hdev -> mbx_service_task , hclgevf_mailbox_service_task );
2273
2282
clear_bit (HCLGEVF_STATE_MBX_SERVICE_SCHED , & hdev -> state );
2274
2283
clear_bit (HCLGEVF_STATE_MBX_HANDLING , & hdev -> state );
2275
2284
2276
2285
INIT_DELAYED_WORK (& hdev -> service_task , hclgevf_service_task );
2277
- clear_bit (HCLGEVF_STATE_SERVICE_SCHED , & hdev -> state );
2278
-
2279
- INIT_WORK (& hdev -> rst_service_task , hclgevf_reset_service_task );
2280
2286
2281
2287
mutex_init (& hdev -> mbx_resp .mbx_mutex );
2282
2288
@@ -2289,16 +2295,8 @@ static void hclgevf_state_uninit(struct hclgevf_dev *hdev)
2289
2295
set_bit (HCLGEVF_STATE_DOWN , & hdev -> state );
2290
2296
set_bit (HCLGEVF_STATE_REMOVING , & hdev -> state );
2291
2297
2292
- if (hdev -> keep_alive_timer .function )
2293
- del_timer_sync (& hdev -> keep_alive_timer );
2294
- if (hdev -> keep_alive_task .func )
2295
- cancel_work_sync (& hdev -> keep_alive_task );
2296
2298
if (hdev -> service_task .work .func )
2297
2299
cancel_delayed_work_sync (& hdev -> service_task );
2298
- if (hdev -> mbx_service_task .func )
2299
- cancel_work_sync (& hdev -> mbx_service_task );
2300
- if (hdev -> rst_service_task .func )
2301
- cancel_work_sync (& hdev -> rst_service_task );
2302
2300
2303
2301
mutex_destroy (& hdev -> mbx_resp .mbx_mutex );
2304
2302
}
@@ -2796,6 +2794,8 @@ static int hclgevf_init_hdev(struct hclgevf_dev *hdev)
2796
2794
dev_info (& hdev -> pdev -> dev , "finished initializing %s driver\n" ,
2797
2795
HCLGEVF_DRIVER_NAME );
2798
2796
2797
+ hclgevf_task_schedule (hdev , round_jiffies_relative (HZ ));
2798
+
2799
2799
return 0 ;
2800
2800
2801
2801
err_config :
@@ -2827,7 +2827,6 @@ static void hclgevf_uninit_hdev(struct hclgevf_dev *hdev)
2827
2827
static int hclgevf_init_ae_dev (struct hnae3_ae_dev * ae_dev )
2828
2828
{
2829
2829
struct pci_dev * pdev = ae_dev -> pdev ;
2830
- struct hclgevf_dev * hdev ;
2831
2830
int ret ;
2832
2831
2833
2832
ret = hclgevf_alloc_hdev (ae_dev );
@@ -2842,10 +2841,6 @@ static int hclgevf_init_ae_dev(struct hnae3_ae_dev *ae_dev)
2842
2841
return ret ;
2843
2842
}
2844
2843
2845
- hdev = ae_dev -> priv ;
2846
- timer_setup (& hdev -> keep_alive_timer , hclgevf_keep_alive_timer , 0 );
2847
- INIT_WORK (& hdev -> keep_alive_task , hclgevf_keep_alive_task );
2848
-
2849
2844
return 0 ;
2850
2845
}
2851
2846
0 commit comments