@@ -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,50 +2156,44 @@ 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 )
2159
+ int ena_com_get_eni_stats (struct ena_com_dev * ena_dev ,
2160
+ struct ena_admin_eni_stats * stats )
2110
2161
{
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 ;
2162
+ struct ena_com_stats_ctx ctx ;
2114
2163
int ret ;
2115
2164
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 ));
2165
+ if (!ena_com_get_cap (ena_dev , ENA_ADMIN_ENI_STATS )) {
2166
+ netdev_err (ena_dev -> net_device , "Capability %d isn't supported\n" ,
2167
+ ENA_ADMIN_ENI_STATS );
2168
+ return - EOPNOTSUPP ;
2169
+ }
2127
2170
2128
- if (unlikely (ret ))
2129
- netdev_err (ena_dev -> net_device , "Failed to get stats. error: %d\n" , ret );
2171
+ memset (& ctx , 0x0 , sizeof (ctx ));
2172
+ ret = ena_get_dev_stats (ena_dev , & ctx , ENA_ADMIN_GET_STATS_TYPE_ENI );
2173
+ if (likely (ret == 0 ))
2174
+ memcpy (stats , & ctx .get_resp .u .eni_stats ,
2175
+ sizeof (ctx .get_resp .u .eni_stats ));
2130
2176
2131
2177
return ret ;
2132
2178
}
2133
2179
2134
- int ena_com_get_eni_stats (struct ena_com_dev * ena_dev ,
2135
- struct ena_admin_eni_stats * stats )
2180
+ int ena_com_get_ena_srd_info (struct ena_com_dev * ena_dev ,
2181
+ struct ena_admin_ena_srd_info * info )
2136
2182
{
2137
2183
struct ena_com_stats_ctx ctx ;
2138
2184
int ret ;
2139
2185
2140
- if (!ena_com_get_cap (ena_dev , ENA_ADMIN_ENI_STATS )) {
2186
+ if (!ena_com_get_cap (ena_dev , ENA_ADMIN_ENA_SRD_INFO )) {
2141
2187
netdev_err (ena_dev -> net_device , "Capability %d isn't supported\n" ,
2142
- ENA_ADMIN_ENI_STATS );
2188
+ ENA_ADMIN_ENA_SRD_INFO );
2143
2189
return - EOPNOTSUPP ;
2144
2190
}
2145
2191
2146
2192
memset (& ctx , 0x0 , sizeof (ctx ));
2147
- ret = ena_get_dev_stats (ena_dev , & ctx , ENA_ADMIN_GET_STATS_TYPE_ENI );
2193
+ ret = ena_get_dev_stats (ena_dev , & ctx , ENA_ADMIN_GET_STATS_TYPE_ENA_SRD );
2148
2194
if (likely (ret == 0 ))
2149
- memcpy (stats , & ctx .get_resp .u .eni_stats ,
2150
- sizeof (ctx .get_resp .u .eni_stats ));
2195
+ memcpy (info , & ctx .get_resp .u .ena_srd_info ,
2196
+ sizeof (ctx .get_resp .u .ena_srd_info ));
2151
2197
2152
2198
return ret ;
2153
2199
}
@@ -2167,6 +2213,50 @@ int ena_com_get_dev_basic_stats(struct ena_com_dev *ena_dev,
2167
2213
return ret ;
2168
2214
}
2169
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
+
2170
2260
int ena_com_set_dev_mtu (struct ena_com_dev * ena_dev , u32 mtu )
2171
2261
{
2172
2262
struct ena_com_admin_queue * admin_queue ;
@@ -2706,6 +2796,24 @@ int ena_com_allocate_debug_area(struct ena_com_dev *ena_dev,
2706
2796
return 0 ;
2707
2797
}
2708
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
+
2709
2817
void ena_com_delete_host_info (struct ena_com_dev * ena_dev )
2710
2818
{
2711
2819
struct ena_host_attribute * host_attr = & ena_dev -> host_attr ;
@@ -2728,6 +2836,19 @@ void ena_com_delete_debug_area(struct ena_com_dev *ena_dev)
2728
2836
}
2729
2837
}
2730
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
+
2731
2852
int ena_com_set_host_attributes (struct ena_com_dev * ena_dev )
2732
2853
{
2733
2854
struct ena_host_attribute * host_attr = & ena_dev -> host_attr ;
0 commit comments