@@ -1881,6 +1881,56 @@ int ena_com_get_link_params(struct ena_com_dev *ena_dev,
1881
1881
return ena_com_get_feature (ena_dev , resp , ENA_ADMIN_LINK_CONFIG , 0 );
1882
1882
}
1883
1883
1884
+ static int ena_get_dev_stats (struct ena_com_dev * ena_dev ,
1885
+ struct ena_com_stats_ctx * ctx ,
1886
+ enum ena_admin_get_stats_type type )
1887
+ {
1888
+ struct ena_admin_acq_get_stats_resp * get_resp = & ctx -> get_resp ;
1889
+ struct ena_admin_aq_get_stats_cmd * get_cmd = & ctx -> get_cmd ;
1890
+ struct ena_com_admin_queue * admin_queue ;
1891
+ int ret ;
1892
+
1893
+ admin_queue = & ena_dev -> admin_queue ;
1894
+
1895
+ get_cmd -> aq_common_descriptor .opcode = ENA_ADMIN_GET_STATS ;
1896
+ get_cmd -> aq_common_descriptor .flags = 0 ;
1897
+ get_cmd -> type = type ;
1898
+
1899
+ ret = ena_com_execute_admin_command (admin_queue ,
1900
+ (struct ena_admin_aq_entry * )get_cmd ,
1901
+ sizeof (* get_cmd ),
1902
+ (struct ena_admin_acq_entry * )get_resp ,
1903
+ sizeof (* get_resp ));
1904
+
1905
+ if (unlikely (ret ))
1906
+ netdev_err (ena_dev -> net_device , "Failed to get stats. error: %d\n" , ret );
1907
+
1908
+ return ret ;
1909
+ }
1910
+
1911
+ static void ena_com_set_supported_customer_metrics (struct ena_com_dev * ena_dev )
1912
+ {
1913
+ struct ena_customer_metrics * customer_metrics ;
1914
+ struct ena_com_stats_ctx ctx ;
1915
+ int ret ;
1916
+
1917
+ customer_metrics = & ena_dev -> customer_metrics ;
1918
+ if (!ena_com_get_cap (ena_dev , ENA_ADMIN_CUSTOMER_METRICS )) {
1919
+ customer_metrics -> supported_metrics = ENA_ADMIN_CUSTOMER_METRICS_MIN_SUPPORT_MASK ;
1920
+ return ;
1921
+ }
1922
+
1923
+ memset (& ctx , 0x0 , sizeof (ctx ));
1924
+ ctx .get_cmd .requested_metrics = ENA_ADMIN_CUSTOMER_METRICS_SUPPORT_MASK ;
1925
+ ret = ena_get_dev_stats (ena_dev , & ctx , ENA_ADMIN_GET_STATS_TYPE_CUSTOMER_METRICS );
1926
+ if (likely (ret == 0 ))
1927
+ customer_metrics -> supported_metrics =
1928
+ ctx .get_resp .u .customer_metrics .reported_metrics ;
1929
+ else
1930
+ netdev_err (ena_dev -> net_device ,
1931
+ "Failed to query customer metrics support. error: %d\n" , ret );
1932
+ }
1933
+
1884
1934
int ena_com_get_dev_attr_feat (struct ena_com_dev * ena_dev ,
1885
1935
struct ena_com_dev_get_features_ctx * get_feat_ctx )
1886
1936
{
@@ -1960,6 +2010,8 @@ int ena_com_get_dev_attr_feat(struct ena_com_dev *ena_dev,
1960
2010
else
1961
2011
return rc ;
1962
2012
2013
+ ena_com_set_supported_customer_metrics (ena_dev );
2014
+
1963
2015
return 0 ;
1964
2016
}
1965
2017
@@ -2104,33 +2156,6 @@ int ena_com_dev_reset(struct ena_com_dev *ena_dev,
2104
2156
return 0 ;
2105
2157
}
2106
2158
2107
- static int ena_get_dev_stats (struct ena_com_dev * ena_dev ,
2108
- struct ena_com_stats_ctx * ctx ,
2109
- enum ena_admin_get_stats_type type )
2110
- {
2111
- struct ena_admin_aq_get_stats_cmd * get_cmd = & ctx -> get_cmd ;
2112
- struct ena_admin_acq_get_stats_resp * get_resp = & ctx -> get_resp ;
2113
- struct ena_com_admin_queue * admin_queue ;
2114
- int ret ;
2115
-
2116
- admin_queue = & ena_dev -> admin_queue ;
2117
-
2118
- get_cmd -> aq_common_descriptor .opcode = ENA_ADMIN_GET_STATS ;
2119
- get_cmd -> aq_common_descriptor .flags = 0 ;
2120
- get_cmd -> type = type ;
2121
-
2122
- ret = ena_com_execute_admin_command (admin_queue ,
2123
- (struct ena_admin_aq_entry * )get_cmd ,
2124
- sizeof (* get_cmd ),
2125
- (struct ena_admin_acq_entry * )get_resp ,
2126
- sizeof (* get_resp ));
2127
-
2128
- if (unlikely (ret ))
2129
- netdev_err (ena_dev -> net_device , "Failed to get stats. error: %d\n" , ret );
2130
-
2131
- return ret ;
2132
- }
2133
-
2134
2159
int ena_com_get_eni_stats (struct ena_com_dev * ena_dev ,
2135
2160
struct ena_admin_eni_stats * stats )
2136
2161
{
@@ -2188,6 +2213,50 @@ int ena_com_get_dev_basic_stats(struct ena_com_dev *ena_dev,
2188
2213
return ret ;
2189
2214
}
2190
2215
2216
+ int ena_com_get_customer_metrics (struct ena_com_dev * ena_dev , char * buffer , u32 len )
2217
+ {
2218
+ struct ena_admin_aq_get_stats_cmd * get_cmd ;
2219
+ struct ena_com_stats_ctx ctx ;
2220
+ int ret ;
2221
+
2222
+ if (unlikely (len > ena_dev -> customer_metrics .buffer_len )) {
2223
+ netdev_err (ena_dev -> net_device ,
2224
+ "Invalid buffer size %u. The given buffer is too big.\n" , len );
2225
+ return - EINVAL ;
2226
+ }
2227
+
2228
+ if (!ena_com_get_cap (ena_dev , ENA_ADMIN_CUSTOMER_METRICS )) {
2229
+ netdev_err (ena_dev -> net_device , "Capability %d not supported.\n" ,
2230
+ ENA_ADMIN_CUSTOMER_METRICS );
2231
+ return - EOPNOTSUPP ;
2232
+ }
2233
+
2234
+ if (!ena_dev -> customer_metrics .supported_metrics ) {
2235
+ netdev_err (ena_dev -> net_device , "No supported customer metrics.\n" );
2236
+ return - EOPNOTSUPP ;
2237
+ }
2238
+
2239
+ get_cmd = & ctx .get_cmd ;
2240
+ memset (& ctx , 0x0 , sizeof (ctx ));
2241
+ ret = ena_com_mem_addr_set (ena_dev ,
2242
+ & get_cmd -> u .control_buffer .address ,
2243
+ ena_dev -> customer_metrics .buffer_dma_addr );
2244
+ if (unlikely (ret )) {
2245
+ netdev_err (ena_dev -> net_device , "Memory address set failed.\n" );
2246
+ return ret ;
2247
+ }
2248
+
2249
+ get_cmd -> u .control_buffer .length = ena_dev -> customer_metrics .buffer_len ;
2250
+ get_cmd -> requested_metrics = ena_dev -> customer_metrics .supported_metrics ;
2251
+ ret = ena_get_dev_stats (ena_dev , & ctx , ENA_ADMIN_GET_STATS_TYPE_CUSTOMER_METRICS );
2252
+ if (likely (ret == 0 ))
2253
+ memcpy (buffer , ena_dev -> customer_metrics .buffer_virt_addr , len );
2254
+ else
2255
+ netdev_err (ena_dev -> net_device , "Failed to get customer metrics. error: %d\n" , ret );
2256
+
2257
+ return ret ;
2258
+ }
2259
+
2191
2260
int ena_com_set_dev_mtu (struct ena_com_dev * ena_dev , u32 mtu )
2192
2261
{
2193
2262
struct ena_com_admin_queue * admin_queue ;
@@ -2727,6 +2796,24 @@ int ena_com_allocate_debug_area(struct ena_com_dev *ena_dev,
2727
2796
return 0 ;
2728
2797
}
2729
2798
2799
+ int ena_com_allocate_customer_metrics_buffer (struct ena_com_dev * ena_dev )
2800
+ {
2801
+ struct ena_customer_metrics * customer_metrics = & ena_dev -> customer_metrics ;
2802
+
2803
+ customer_metrics -> buffer_len = ENA_CUSTOMER_METRICS_BUFFER_SIZE ;
2804
+ customer_metrics -> buffer_virt_addr = NULL ;
2805
+
2806
+ customer_metrics -> buffer_virt_addr =
2807
+ dma_alloc_coherent (ena_dev -> dmadev , customer_metrics -> buffer_len ,
2808
+ & customer_metrics -> buffer_dma_addr , GFP_KERNEL );
2809
+ if (!customer_metrics -> buffer_virt_addr ) {
2810
+ customer_metrics -> buffer_len = 0 ;
2811
+ return - ENOMEM ;
2812
+ }
2813
+
2814
+ return 0 ;
2815
+ }
2816
+
2730
2817
void ena_com_delete_host_info (struct ena_com_dev * ena_dev )
2731
2818
{
2732
2819
struct ena_host_attribute * host_attr = & ena_dev -> host_attr ;
@@ -2749,6 +2836,19 @@ void ena_com_delete_debug_area(struct ena_com_dev *ena_dev)
2749
2836
}
2750
2837
}
2751
2838
2839
+ void ena_com_delete_customer_metrics_buffer (struct ena_com_dev * ena_dev )
2840
+ {
2841
+ struct ena_customer_metrics * customer_metrics = & ena_dev -> customer_metrics ;
2842
+
2843
+ if (customer_metrics -> buffer_virt_addr ) {
2844
+ dma_free_coherent (ena_dev -> dmadev , customer_metrics -> buffer_len ,
2845
+ customer_metrics -> buffer_virt_addr ,
2846
+ customer_metrics -> buffer_dma_addr );
2847
+ customer_metrics -> buffer_virt_addr = NULL ;
2848
+ customer_metrics -> buffer_len = 0 ;
2849
+ }
2850
+ }
2851
+
2752
2852
int ena_com_set_host_attributes (struct ena_com_dev * ena_dev )
2753
2853
{
2754
2854
struct ena_host_attribute * host_attr = & ena_dev -> host_attr ;
0 commit comments