11// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
22/*
3- * Copyright 2015-2021 Amazon.com, Inc. or its affiliates. All rights reserved.
3+ * Copyright 2015-2023 Amazon.com, Inc. or its affiliates. All rights reserved.
44 */
55
66#include "linux/pci.h"
77
88#include "ena_devlink.h"
99#ifdef ENA_DEVLINK_SUPPORT
10+ #ifdef ENA_PHC_SUPPORT
11+ #include "ena_phc.h"
12+
13+ static int ena_devlink_phc_enable_validate (struct devlink * devlink , u32 id ,
14+ union devlink_param_value val ,
15+ struct netlink_ext_ack * extack );
16+ #endif /* ENA_PHC_SUPPORT */
1017
1118static int ena_devlink_llq_header_validate (struct devlink * devlink , u32 id ,
1219 union devlink_param_value val ,
@@ -15,13 +22,22 @@ static int ena_devlink_llq_header_validate(struct devlink *devlink, u32 id,
1522enum ena_devlink_param_id {
1623 ENA_DEVLINK_PARAM_ID_BASE = DEVLINK_PARAM_GENERIC_ID_MAX ,
1724 ENA_DEVLINK_PARAM_ID_LLQ_HEADER_SIZE ,
25+ #ifdef ENA_PHC_SUPPORT
26+ ENA_DEVLINK_PARAM_ID_PHC_ENABLE ,
27+ #endif /* ENA_PHC_SUPPORT */
1828};
1929
2030static const struct devlink_param ena_devlink_params [] = {
2131 DEVLINK_PARAM_DRIVER (ENA_DEVLINK_PARAM_ID_LLQ_HEADER_SIZE ,
2232 "large_llq_header" , DEVLINK_PARAM_TYPE_BOOL ,
2333 BIT (DEVLINK_PARAM_CMODE_DRIVERINIT ),
2434 NULL , NULL , ena_devlink_llq_header_validate ),
35+ #ifdef ENA_PHC_SUPPORT
36+ DEVLINK_PARAM_DRIVER (ENA_DEVLINK_PARAM_ID_PHC_ENABLE ,
37+ "phc_enable" , DEVLINK_PARAM_TYPE_BOOL ,
38+ BIT (DEVLINK_PARAM_CMODE_DRIVERINIT ),
39+ NULL , NULL , ena_devlink_phc_enable_validate ),
40+ #endif /* ENA_PHC_SUPPORT */
2541};
2642
2743static int ena_devlink_llq_header_validate (struct devlink * devlink , u32 id ,
@@ -47,6 +63,25 @@ static int ena_devlink_llq_header_validate(struct devlink *devlink, u32 id,
4763 return 0 ;
4864}
4965
66+ #ifdef ENA_PHC_SUPPORT
67+ static int ena_devlink_phc_enable_validate (struct devlink * devlink , u32 id ,
68+ union devlink_param_value val ,
69+ struct netlink_ext_ack * extack )
70+ {
71+ struct ena_adapter * adapter = ENA_DEVLINK_PRIV (devlink );
72+
73+ if (!val .vbool )
74+ return 0 ;
75+
76+ if (!ena_com_phc_supported (adapter -> ena_dev )) {
77+ NL_SET_ERR_MSG_MOD (extack , "Device doesn't support PHC" );
78+ return - EOPNOTSUPP ;
79+ }
80+
81+ return 0 ;
82+ }
83+
84+ #endif /* ENA_PHC_SUPPORT */
5085#ifdef ENA_DEVLINK_CONFIGURE_AFTER_REGISTER
5186/* Determines if ena_devlink_register has been called.
5287 * Prefer to check if the driver enabled reloading capabilities, but fallback
@@ -82,6 +117,16 @@ void ena_devlink_params_get(struct devlink *devlink)
82117 }
83118
84119 adapter -> large_llq_header_enabled = val .vbool ;
120+ #ifdef ENA_PHC_SUPPORT
121+
122+ err = devlink_param_driverinit_value_get (devlink , ENA_DEVLINK_PARAM_ID_PHC_ENABLE , & val );
123+ if (err ) {
124+ netdev_err (adapter -> netdev , "Failed to query PHC param\n" );
125+ return ;
126+ }
127+
128+ ena_phc_enable (adapter , val .vbool );
129+ #endif /* ENA_PHC_SUPPORT */
85130}
86131
87132void ena_devlink_disable_large_llq_header_param (struct devlink * devlink )
@@ -100,6 +145,22 @@ void ena_devlink_disable_large_llq_header_param(struct devlink *devlink)
100145 value );
101146}
102147
148+ #ifdef ENA_PHC_SUPPORT
149+ void ena_devlink_disable_phc_param (struct devlink * devlink )
150+ {
151+ union devlink_param_value value ;
152+
153+ #ifdef ENA_DEVLINK_CONFIGURE_AFTER_REGISTER
154+ /* If devlink params aren't registered, don't access them */
155+ if (!ena_is_devlink_params_registered (devlink ))
156+ return ;
157+
158+ #endif
159+ value .vbool = false;
160+ devlink_param_driverinit_value_set (devlink , ENA_DEVLINK_PARAM_ID_PHC_ENABLE , value );
161+ }
162+
163+ #endif /* ENA_PHC_SUPPORT */
103164static int ena_devlink_reload_down (struct devlink * devlink ,
104165#ifdef ENA_DEVLINK_RELOAD_NS_CHANGE_SUPPORT
105166 bool netns_change ,
@@ -164,11 +225,11 @@ static int ena_devlink_reload_up(struct devlink *devlink,
164225 rtnl_lock ();
165226 /* Check that no other routine initialized the device (e.g.
166227 * ena_fw_reset_device()). Also we're under devlink_mutex here,
167- * so devink (and ena_adapter with it) isn't freed under our
168- * feet.
228+ * so devlink isn't freed under our feet.
169229 */
170230 if (!test_bit (ENA_FLAG_DEVICE_RUNNING , & adapter -> flags ))
171231 err = ena_restore_device (adapter );
232+
172233 rtnl_unlock ();
173234
174235#ifdef ENA_DEVLINK_RELOAD_LIMIT_AND_ACTION_SUPPORT
@@ -220,9 +281,18 @@ static int ena_devlink_configure_params(struct devlink *devlink)
220281 ENA_DEVLINK_PARAM_ID_LLQ_HEADER_SIZE ,
221282 value );
222283
284+ #ifdef ENA_PHC_SUPPORT
285+ value .vbool = ena_phc_is_enabled (adapter );
286+ devlink_param_driverinit_value_set (devlink , ENA_DEVLINK_PARAM_ID_PHC_ENABLE , value );
287+
288+ #endif /* ENA_PHC_SUPPORT */
223289#ifdef ENA_DEVLINK_RELOAD_SUPPORT_ADVERTISEMENT_NEEDED
224290 devlink_set_features (devlink , DEVLINK_F_RELOAD );
225291
292+ #endif
293+ #ifdef ENA_DEVLINK_PUBLISH_REQUIRED
294+ devlink_params_publish (devlink );
295+
226296#endif
227297#ifdef ENA_DEVLINK_RELOAD_ENABLING_REQUIRED
228298 devlink_reload_enable (devlink );
@@ -270,6 +340,10 @@ static void ena_devlink_configure_params_clean(struct devlink *devlink)
270340#ifdef ENA_DEVLINK_RELOAD_ENABLING_REQUIRED
271341 devlink_reload_disable (devlink );
272342
343+ #endif
344+ #ifdef ENA_DEVLINK_PUBLISH_REQUIRED
345+ devlink_params_unpublish (devlink );
346+
273347#endif
274348 devlink_params_unregister (devlink , ena_devlink_params ,
275349 ARRAY_SIZE (ena_devlink_params ));
0 commit comments