// SPDX-License-Identifier: GPL-2.0 /* Copyright (c) 2020, Intel Corporation. */ #include <linux/vmalloc.h> #include "ice.h" #include "ice_lib.h" #include "devlink.h" #include "devlink_port.h" #include "ice_eswitch.h" #include "ice_fw_update.h" #include "ice_dcb_lib.h" #include "ice_sf_eth.h" /* context for devlink info version reporting */ struct ice_info_ctx { … }; /* The following functions are used to format specific strings for various * devlink info versions. The ctx parameter is used to provide the storage * buffer, as well as any ancillary information calculated when the info * request was made. * * If a version does not exist, for example when attempting to get the * inactive version of flash when there is no pending update, the function * should leave the buffer in the ctx structure empty. */ static void ice_info_get_dsn(struct ice_pf *pf, struct ice_info_ctx *ctx) { … } static void ice_info_pba(struct ice_pf *pf, struct ice_info_ctx *ctx) { … } static void ice_info_fw_mgmt(struct ice_pf *pf, struct ice_info_ctx *ctx) { … } static void ice_info_fw_api(struct ice_pf *pf, struct ice_info_ctx *ctx) { … } static void ice_info_fw_build(struct ice_pf *pf, struct ice_info_ctx *ctx) { … } static void ice_info_orom_ver(struct ice_pf *pf, struct ice_info_ctx *ctx) { … } static void ice_info_pending_orom_ver(struct ice_pf __always_unused *pf, struct ice_info_ctx *ctx) { … } static void ice_info_nvm_ver(struct ice_pf *pf, struct ice_info_ctx *ctx) { … } static void ice_info_pending_nvm_ver(struct ice_pf __always_unused *pf, struct ice_info_ctx *ctx) { … } static void ice_info_eetrack(struct ice_pf *pf, struct ice_info_ctx *ctx) { … } static void ice_info_pending_eetrack(struct ice_pf *pf, struct ice_info_ctx *ctx) { … } static void ice_info_ddp_pkg_name(struct ice_pf *pf, struct ice_info_ctx *ctx) { … } static void ice_info_ddp_pkg_version(struct ice_pf *pf, struct ice_info_ctx *ctx) { … } static void ice_info_ddp_pkg_bundle_id(struct ice_pf *pf, struct ice_info_ctx *ctx) { … } static void ice_info_netlist_ver(struct ice_pf *pf, struct ice_info_ctx *ctx) { … } static void ice_info_netlist_build(struct ice_pf *pf, struct ice_info_ctx *ctx) { … } static void ice_info_pending_netlist_ver(struct ice_pf __always_unused *pf, struct ice_info_ctx *ctx) { … } static void ice_info_pending_netlist_build(struct ice_pf __always_unused *pf, struct ice_info_ctx *ctx) { … } static void ice_info_cgu_fw_build(struct ice_pf *pf, struct ice_info_ctx *ctx) { … } static void ice_info_cgu_id(struct ice_pf *pf, struct ice_info_ctx *ctx) { … } #define fixed(key, getter) … #define running(key, getter) … #define stored(key, getter, fallback) … /* The combined() macro inserts both the running entry as well as a stored * entry. The running entry will always report the version from the active * handler. The stored entry will first try the pending handler, and fallback * to the active handler if the pending function does not report a version. * The pending handler should check the status of a pending update for the * relevant flash component. It should only fill in the buffer in the case * where a valid pending version is available. This ensures that the related * stored and running versions remain in sync, and that stored versions are * correctly reported as expected. */ #define combined(key, active, pending) … enum ice_version_type { … }; static const struct ice_devlink_version { … } ice_devlink_versions[] = …; /** * ice_devlink_info_get - .info_get devlink handler * @devlink: devlink instance structure * @req: the devlink info request * @extack: extended netdev ack structure * * Callback for the devlink .info_get operation. Reports information about the * device. * * Return: zero on success or an error code on failure. */ static int ice_devlink_info_get(struct devlink *devlink, struct devlink_info_req *req, struct netlink_ext_ack *extack) { … } /** * ice_devlink_reload_empr_start - Start EMP reset to activate new firmware * @pf: pointer to the pf instance * @extack: netlink extended ACK structure * * Allow user to activate new Embedded Management Processor firmware by * issuing device specific EMP reset. Called in response to * a DEVLINK_CMD_RELOAD with the DEVLINK_RELOAD_ACTION_FW_ACTIVATE. * * Note that teardown and rebuild of the driver state happens automatically as * part of an interrupt and watchdog task. This is because all physical * functions on the device must be able to reset when an EMP reset occurs from * any source. */ static int ice_devlink_reload_empr_start(struct ice_pf *pf, struct netlink_ext_ack *extack) { … } /** * ice_devlink_reinit_down - unload given PF * @pf: pointer to the PF struct */ static void ice_devlink_reinit_down(struct ice_pf *pf) { … } /** * ice_devlink_reload_down - prepare for reload * @devlink: pointer to the devlink instance to reload * @netns_change: if true, the network namespace is changing * @action: the action to perform * @limit: limits on what reload should do, such as not resetting * @extack: netlink extended ACK structure */ static int ice_devlink_reload_down(struct devlink *devlink, bool netns_change, enum devlink_reload_action action, enum devlink_reload_limit limit, struct netlink_ext_ack *extack) { … } /** * ice_devlink_reload_empr_finish - Wait for EMP reset to finish * @pf: pointer to the pf instance * @extack: netlink extended ACK structure * * Wait for driver to finish rebuilding after EMP reset is completed. This * includes time to wait for both the actual device reset as well as the time * for the driver's rebuild to complete. */ static int ice_devlink_reload_empr_finish(struct ice_pf *pf, struct netlink_ext_ack *extack) { … } /** * ice_get_tx_topo_user_sel - Read user's choice from flash * @pf: pointer to pf structure * @layers: value read from flash will be saved here * * Reads user's preference for Tx Scheduler Topology Tree from PFA TLV. * * Return: zero when read was successful, negative values otherwise. */ static int ice_get_tx_topo_user_sel(struct ice_pf *pf, uint8_t *layers) { … } /** * ice_update_tx_topo_user_sel - Save user's preference in flash * @pf: pointer to pf structure * @layers: value to be saved in flash * * Variable "layers" defines user's preference about number of layers in Tx * Scheduler Topology Tree. This choice should be stored in PFA TLV field * and be picked up by driver, next time during init. * * Return: zero when save was successful, negative values otherwise. */ static int ice_update_tx_topo_user_sel(struct ice_pf *pf, int layers) { … } /** * ice_devlink_tx_sched_layers_get - Get tx_scheduling_layers parameter * @devlink: pointer to the devlink instance * @id: the parameter ID to set * @ctx: context to store the parameter value * * Return: zero on success and negative value on failure. */ static int ice_devlink_tx_sched_layers_get(struct devlink *devlink, u32 id, struct devlink_param_gset_ctx *ctx) { … } /** * ice_devlink_tx_sched_layers_set - Set tx_scheduling_layers parameter * @devlink: pointer to the devlink instance * @id: the parameter ID to set * @ctx: context to get the parameter value * @extack: netlink extended ACK structure * * Return: zero on success and negative value on failure. */ static int ice_devlink_tx_sched_layers_set(struct devlink *devlink, u32 id, struct devlink_param_gset_ctx *ctx, struct netlink_ext_ack *extack) { … } /** * ice_devlink_tx_sched_layers_validate - Validate passed tx_scheduling_layers * parameter value * @devlink: unused pointer to devlink instance * @id: the parameter ID to validate * @val: value to validate * @extack: netlink extended ACK structure * * Supported values are: * - 5 - five layers Tx Scheduler Topology Tree * - 9 - nine layers Tx Scheduler Topology Tree * * Return: zero when passed parameter value is supported. Negative value on * error. */ static int ice_devlink_tx_sched_layers_validate(struct devlink *devlink, u32 id, union devlink_param_value val, struct netlink_ext_ack *extack) { … } /** * ice_tear_down_devlink_rate_tree - removes devlink-rate exported tree * @pf: pf struct * * This function tears down tree exported during VF's creation. */ void ice_tear_down_devlink_rate_tree(struct ice_pf *pf) { … } /** * ice_enable_custom_tx - try to enable custom Tx feature * @pf: pf struct * * This function tries to enable custom Tx feature, * it's not possible to enable it, if DCB or ADQ is active. */ static bool ice_enable_custom_tx(struct ice_pf *pf) { … } /** * ice_traverse_tx_tree - traverse Tx scheduler tree * @devlink: devlink struct * @node: current node, used for recursion * @tc_node: tc_node struct, that is treated as a root * @pf: pf struct * * This function traverses Tx scheduler tree and exports * entire structure to the devlink-rate. */ static void ice_traverse_tx_tree(struct devlink *devlink, struct ice_sched_node *node, struct ice_sched_node *tc_node, struct ice_pf *pf) { … } /** * ice_devlink_rate_init_tx_topology - export Tx scheduler tree to devlink rate * @devlink: devlink struct * @vsi: main vsi struct * * This function finds a root node, then calls ice_traverse_tx tree, which * traverses the tree and exports it's contents to devlink rate. */ int ice_devlink_rate_init_tx_topology(struct devlink *devlink, struct ice_vsi *vsi) { … } static void ice_clear_rate_nodes(struct ice_sched_node *node) { … } /** * ice_devlink_rate_clear_tx_topology - clear node->rate_node * @vsi: main vsi struct * * Clear rate_node to cleanup creation of Tx topology. * */ void ice_devlink_rate_clear_tx_topology(struct ice_vsi *vsi) { … } /** * ice_set_object_tx_share - sets node scheduling parameter * @pi: devlink struct instance * @node: node struct instance * @bw: bandwidth in bytes per second * @extack: extended netdev ack structure * * This function sets ICE_MIN_BW scheduling BW limit. */ static int ice_set_object_tx_share(struct ice_port_info *pi, struct ice_sched_node *node, u64 bw, struct netlink_ext_ack *extack) { … } /** * ice_set_object_tx_max - sets node scheduling parameter * @pi: devlink struct instance * @node: node struct instance * @bw: bandwidth in bytes per second * @extack: extended netdev ack structure * * This function sets ICE_MAX_BW scheduling BW limit. */ static int ice_set_object_tx_max(struct ice_port_info *pi, struct ice_sched_node *node, u64 bw, struct netlink_ext_ack *extack) { … } /** * ice_set_object_tx_priority - sets node scheduling parameter * @pi: devlink struct instance * @node: node struct instance * @priority: value representing priority for strict priority arbitration * @extack: extended netdev ack structure * * This function sets priority of node among siblings. */ static int ice_set_object_tx_priority(struct ice_port_info *pi, struct ice_sched_node *node, u32 priority, struct netlink_ext_ack *extack) { … } /** * ice_set_object_tx_weight - sets node scheduling parameter * @pi: devlink struct instance * @node: node struct instance * @weight: value represeting relative weight for WFQ arbitration * @extack: extended netdev ack structure * * This function sets node weight for WFQ algorithm. */ static int ice_set_object_tx_weight(struct ice_port_info *pi, struct ice_sched_node *node, u32 weight, struct netlink_ext_ack *extack) { … } /** * ice_get_pi_from_dev_rate - get port info from devlink_rate * @rate_node: devlink struct instance * * This function returns corresponding port_info struct of devlink_rate */ static struct ice_port_info *ice_get_pi_from_dev_rate(struct devlink_rate *rate_node) { … } static int ice_devlink_rate_node_new(struct devlink_rate *rate_node, void **priv, struct netlink_ext_ack *extack) { … } static int ice_devlink_rate_node_del(struct devlink_rate *rate_node, void *priv, struct netlink_ext_ack *extack) { … } static int ice_devlink_rate_leaf_tx_max_set(struct devlink_rate *rate_leaf, void *priv, u64 tx_max, struct netlink_ext_ack *extack) { … } static int ice_devlink_rate_leaf_tx_share_set(struct devlink_rate *rate_leaf, void *priv, u64 tx_share, struct netlink_ext_ack *extack) { … } static int ice_devlink_rate_leaf_tx_priority_set(struct devlink_rate *rate_leaf, void *priv, u32 tx_priority, struct netlink_ext_ack *extack) { … } static int ice_devlink_rate_leaf_tx_weight_set(struct devlink_rate *rate_leaf, void *priv, u32 tx_weight, struct netlink_ext_ack *extack) { … } static int ice_devlink_rate_node_tx_max_set(struct devlink_rate *rate_node, void *priv, u64 tx_max, struct netlink_ext_ack *extack) { … } static int ice_devlink_rate_node_tx_share_set(struct devlink_rate *rate_node, void *priv, u64 tx_share, struct netlink_ext_ack *extack) { … } static int ice_devlink_rate_node_tx_priority_set(struct devlink_rate *rate_node, void *priv, u32 tx_priority, struct netlink_ext_ack *extack) { … } static int ice_devlink_rate_node_tx_weight_set(struct devlink_rate *rate_node, void *priv, u32 tx_weight, struct netlink_ext_ack *extack) { … } static int ice_devlink_set_parent(struct devlink_rate *devlink_rate, struct devlink_rate *parent, void *priv, void *parent_priv, struct netlink_ext_ack *extack) { … } /** * ice_devlink_reinit_up - do reinit of the given PF * @pf: pointer to the PF struct */ static int ice_devlink_reinit_up(struct ice_pf *pf) { … } /** * ice_devlink_reload_up - do reload up after reinit * @devlink: pointer to the devlink instance reloading * @action: the action requested * @limit: limits imposed by userspace, such as not resetting * @actions_performed: on return, indicate what actions actually performed * @extack: netlink extended ACK structure */ static int ice_devlink_reload_up(struct devlink *devlink, enum devlink_reload_action action, enum devlink_reload_limit limit, u32 *actions_performed, struct netlink_ext_ack *extack) { … } static const struct devlink_ops ice_devlink_ops = …; static const struct devlink_ops ice_sf_devlink_ops; static int ice_devlink_enable_roce_get(struct devlink *devlink, u32 id, struct devlink_param_gset_ctx *ctx) { … } static int ice_devlink_enable_roce_set(struct devlink *devlink, u32 id, struct devlink_param_gset_ctx *ctx, struct netlink_ext_ack *extack) { … } static int ice_devlink_enable_roce_validate(struct devlink *devlink, u32 id, union devlink_param_value val, struct netlink_ext_ack *extack) { … } static int ice_devlink_enable_iw_get(struct devlink *devlink, u32 id, struct devlink_param_gset_ctx *ctx) { … } static int ice_devlink_enable_iw_set(struct devlink *devlink, u32 id, struct devlink_param_gset_ctx *ctx, struct netlink_ext_ack *extack) { … } static int ice_devlink_enable_iw_validate(struct devlink *devlink, u32 id, union devlink_param_value val, struct netlink_ext_ack *extack) { … } #define DEVLINK_LOCAL_FWD_DISABLED_STR … #define DEVLINK_LOCAL_FWD_ENABLED_STR … #define DEVLINK_LOCAL_FWD_PRIORITIZED_STR … /** * ice_devlink_local_fwd_mode_to_str - Get string for local_fwd mode. * @mode: local forwarding for mode used in port_info struct. * * Return: Mode respective string or "Invalid". */ static const char * ice_devlink_local_fwd_mode_to_str(enum ice_local_fwd_mode mode) { … } /** * ice_devlink_local_fwd_str_to_mode - Get local_fwd mode from string name. * @mode_str: local forwarding mode string. * * Return: Mode value or negative number if invalid. */ static int ice_devlink_local_fwd_str_to_mode(const char *mode_str) { … } /** * ice_devlink_local_fwd_get - Get local_fwd parameter. * @devlink: Pointer to the devlink instance. * @id: The parameter ID to set. * @ctx: Context to store the parameter value. * * Return: Zero. */ static int ice_devlink_local_fwd_get(struct devlink *devlink, u32 id, struct devlink_param_gset_ctx *ctx) { … } /** * ice_devlink_local_fwd_set - Set local_fwd parameter. * @devlink: Pointer to the devlink instance. * @id: The parameter ID to set. * @ctx: Context to get the parameter value. * @extack: Netlink extended ACK structure. * * Return: Zero. */ static int ice_devlink_local_fwd_set(struct devlink *devlink, u32 id, struct devlink_param_gset_ctx *ctx, struct netlink_ext_ack *extack) { … } /** * ice_devlink_local_fwd_validate - Validate passed local_fwd parameter value. * @devlink: Unused pointer to devlink instance. * @id: The parameter ID to validate. * @val: Value to validate. * @extack: Netlink extended ACK structure. * * Supported values are: * "enabled" - local_fwd is enabled, "disabled" - local_fwd is disabled * "prioritized" - local_fwd traffic is prioritized in scheduling. * * Return: Zero when passed parameter value is supported. Negative value on * error. */ static int ice_devlink_local_fwd_validate(struct devlink *devlink, u32 id, union devlink_param_value val, struct netlink_ext_ack *extack) { … } enum ice_param_id { … }; static const struct devlink_param ice_dvl_rdma_params[] = …; static const struct devlink_param ice_dvl_sched_params[] = …; static void ice_devlink_free(void *devlink_ptr) { … } /** * ice_allocate_pf - Allocate devlink and return PF structure pointer * @dev: the device to allocate for * * Allocate a devlink instance for this device and return the private area as * the PF structure. The devlink memory is kept track of through devres by * adding an action to remove it when unwinding. */ struct ice_pf *ice_allocate_pf(struct device *dev) { … } /** * ice_allocate_sf - Allocate devlink and return SF structure pointer * @dev: the device to allocate for * @pf: pointer to the PF structure * * Allocate a devlink instance for SF. * * Return: ice_sf_priv pointer to allocated memory or ERR_PTR in case of error */ struct ice_sf_priv *ice_allocate_sf(struct device *dev, struct ice_pf *pf) { … } /** * ice_devlink_register - Register devlink interface for this PF * @pf: the PF to register the devlink for. * * Register the devlink instance associated with this physical function. * * Return: zero on success or an error code on failure. */ void ice_devlink_register(struct ice_pf *pf) { … } /** * ice_devlink_unregister - Unregister devlink resources for this PF. * @pf: the PF structure to cleanup * * Releases resources used by devlink and cleans up associated memory. */ void ice_devlink_unregister(struct ice_pf *pf) { … } int ice_devlink_register_params(struct ice_pf *pf) { … } void ice_devlink_unregister_params(struct ice_pf *pf) { … } #define ICE_DEVLINK_READ_BLK_SIZE … static const struct devlink_region_ops ice_nvm_region_ops; static const struct devlink_region_ops ice_sram_region_ops; /** * ice_devlink_nvm_snapshot - Capture a snapshot of the NVM flash contents * @devlink: the devlink instance * @ops: the devlink region to snapshot * @extack: extended ACK response structure * @data: on exit points to snapshot data buffer * * This function is called in response to a DEVLINK_CMD_REGION_NEW for either * the nvm-flash or shadow-ram region. * * It captures a snapshot of the NVM or Shadow RAM flash contents. This * snapshot can then later be viewed via the DEVLINK_CMD_REGION_READ netlink * interface. * * @returns zero on success, and updates the data pointer. Returns a non-zero * error code on failure. */ static int ice_devlink_nvm_snapshot(struct devlink *devlink, const struct devlink_region_ops *ops, struct netlink_ext_ack *extack, u8 **data) { … } /** * ice_devlink_nvm_read - Read a portion of NVM flash contents * @devlink: the devlink instance * @ops: the devlink region to snapshot * @extack: extended ACK response structure * @offset: the offset to start at * @size: the amount to read * @data: the data buffer to read into * * This function is called in response to DEVLINK_CMD_REGION_READ to directly * read a section of the NVM contents. * * It reads from either the nvm-flash or shadow-ram region contents. * * @returns zero on success, and updates the data pointer. Returns a non-zero * error code on failure. */ static int ice_devlink_nvm_read(struct devlink *devlink, const struct devlink_region_ops *ops, struct netlink_ext_ack *extack, u64 offset, u32 size, u8 *data) { … } /** * ice_devlink_devcaps_snapshot - Capture snapshot of device capabilities * @devlink: the devlink instance * @ops: the devlink region being snapshotted * @extack: extended ACK response structure * @data: on exit points to snapshot data buffer * * This function is called in response to the DEVLINK_CMD_REGION_TRIGGER for * the device-caps devlink region. It captures a snapshot of the device * capabilities reported by firmware. * * @returns zero on success, and updates the data pointer. Returns a non-zero * error code on failure. */ static int ice_devlink_devcaps_snapshot(struct devlink *devlink, const struct devlink_region_ops *ops, struct netlink_ext_ack *extack, u8 **data) { … } static const struct devlink_region_ops ice_nvm_region_ops = …; static const struct devlink_region_ops ice_sram_region_ops = …; static const struct devlink_region_ops ice_devcaps_region_ops = …; /** * ice_devlink_init_regions - Initialize devlink regions * @pf: the PF device structure * * Create devlink regions used to enable access to dump the contents of the * flash memory on the device. */ void ice_devlink_init_regions(struct ice_pf *pf) { … } /** * ice_devlink_destroy_regions - Destroy devlink regions * @pf: the PF device structure * * Remove previously created regions for this PF. */ void ice_devlink_destroy_regions(struct ice_pf *pf) { … }