linux/drivers/net/ethernet/intel/ice/devlink/devlink_port.c

// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2024, Intel Corporation. */

#include <linux/vmalloc.h>

#include "ice.h"
#include "devlink.h"
#include "devlink_port.h"
#include "ice_lib.h"
#include "ice_fltr.h"

static int ice_active_port_option =;

/**
 * ice_devlink_port_opt_speed_str - convert speed to a string
 * @speed: speed value
 */
static const char *ice_devlink_port_opt_speed_str(u8 speed)
{}

#define ICE_PORT_OPT_DESC_LEN
/**
 * ice_devlink_port_options_print - Print available port split options
 * @pf: the PF to print split port options
 *
 * Prints a table with available port split options and max port speeds
 */
static void ice_devlink_port_options_print(struct ice_pf *pf)
{}

/**
 * ice_devlink_aq_set_port_option - Send set port option admin queue command
 * @pf: the PF to print split port options
 * @option_idx: selected port option
 * @extack: extended netdev ack structure
 *
 * Sends set port option admin queue command with selected port option and
 * calls NVM write activate.
 */
static int
ice_devlink_aq_set_port_option(struct ice_pf *pf, u8 option_idx,
			       struct netlink_ext_ack *extack)
{}

/**
 * ice_devlink_port_split - .port_split devlink handler
 * @devlink: devlink instance structure
 * @port: devlink port structure
 * @count: number of ports to split to
 * @extack: extended netdev ack structure
 *
 * Callback for the devlink .port_split operation.
 *
 * Unfortunately, the devlink expression of available options is limited
 * to just a number, so search for an FW port option which supports
 * the specified number. As there could be multiple FW port options with
 * the same port split count, allow switching between them. When the same
 * port split count request is issued again, switch to the next FW port
 * option with the same port split count.
 *
 * Return: zero on success or an error code on failure.
 */
static int
ice_devlink_port_split(struct devlink *devlink, struct devlink_port *port,
		       unsigned int count, struct netlink_ext_ack *extack)
{}

/**
 * ice_devlink_port_unsplit - .port_unsplit devlink handler
 * @devlink: devlink instance structure
 * @port: devlink port structure
 * @extack: extended netdev ack structure
 *
 * Callback for the devlink .port_unsplit operation.
 * Calls ice_devlink_port_split with split count set to 1.
 * There could be no FW option available with split count 1.
 *
 * Return: zero on success or an error code on failure.
 */
static int
ice_devlink_port_unsplit(struct devlink *devlink, struct devlink_port *port,
			 struct netlink_ext_ack *extack)
{}

/**
 * ice_devlink_set_port_split_options - Set port split options
 * @pf: the PF to set port split options
 * @attrs: devlink attributes
 *
 * Sets devlink port split options based on available FW port options
 */
static void
ice_devlink_set_port_split_options(struct ice_pf *pf,
				   struct devlink_port_attrs *attrs)
{}

static const struct devlink_port_ops ice_devlink_port_ops =;

/**
 * ice_devlink_set_switch_id - Set unique switch id based on pci dsn
 * @pf: the PF to create a devlink port for
 * @ppid: struct with switch id information
 */
static void
ice_devlink_set_switch_id(struct ice_pf *pf, struct netdev_phys_item_id *ppid)
{}

/**
 * ice_devlink_create_pf_port - Create a devlink port for this PF
 * @pf: the PF to create a devlink port for
 *
 * Create and register a devlink_port for this PF.
 * This function has to be called under devl_lock.
 *
 * Return: zero on success or an error code on failure.
 */
int ice_devlink_create_pf_port(struct ice_pf *pf)
{}

/**
 * ice_devlink_destroy_pf_port - Destroy the devlink_port for this PF
 * @pf: the PF to cleanup
 *
 * Unregisters the devlink_port structure associated with this PF.
 * This function has to be called under devl_lock.
 */
void ice_devlink_destroy_pf_port(struct ice_pf *pf)
{}

/**
 * ice_devlink_port_get_vf_fn_mac - .port_fn_hw_addr_get devlink handler
 * @port: devlink port structure
 * @hw_addr: MAC address of the port
 * @hw_addr_len: length of MAC address
 * @extack: extended netdev ack structure
 *
 * Callback for the devlink .port_fn_hw_addr_get operation
 * Return: zero on success or an error code on failure.
 */
static int ice_devlink_port_get_vf_fn_mac(struct devlink_port *port,
					  u8 *hw_addr, int *hw_addr_len,
					  struct netlink_ext_ack *extack)
{}

/**
 * ice_devlink_port_set_vf_fn_mac - .port_fn_hw_addr_set devlink handler
 * @port: devlink port structure
 * @hw_addr: MAC address of the port
 * @hw_addr_len: length of MAC address
 * @extack: extended netdev ack structure
 *
 * Callback for the devlink .port_fn_hw_addr_set operation
 * Return: zero on success or an error code on failure.
 */
static int ice_devlink_port_set_vf_fn_mac(struct devlink_port *port,
					  const u8 *hw_addr,
					  int hw_addr_len,
					  struct netlink_ext_ack *extack)

{}

static const struct devlink_port_ops ice_devlink_vf_port_ops =;

/**
 * ice_devlink_create_vf_port - Create a devlink port for this VF
 * @vf: the VF to create a port for
 *
 * Create and register a devlink_port for this VF.
 *
 * Return: zero on success or an error code on failure.
 */
int ice_devlink_create_vf_port(struct ice_vf *vf)
{}

/**
 * ice_devlink_destroy_vf_port - Destroy the devlink_port for this VF
 * @vf: the VF to cleanup
 *
 * Unregisters the devlink_port structure associated with this VF.
 */
void ice_devlink_destroy_vf_port(struct ice_vf *vf)
{}

/**
 * ice_devlink_create_sf_dev_port - Register virtual port for a subfunction
 * @sf_dev: the subfunction device to create a devlink port for
 *
 * Register virtual flavour devlink port for the subfunction auxiliary device
 * created after activating a dynamically added devlink port.
 *
 * Return: zero on success or an error code on failure.
 */
int ice_devlink_create_sf_dev_port(struct ice_sf_dev *sf_dev)
{}

/**
 * ice_devlink_destroy_sf_dev_port - Destroy virtual port for a subfunction
 * @sf_dev: the subfunction device to create a devlink port for
 *
 * Unregisters the virtual port associated with this subfunction.
 */
void ice_devlink_destroy_sf_dev_port(struct ice_sf_dev *sf_dev)
{}

/**
 * ice_activate_dynamic_port - Activate a dynamic port
 * @dyn_port: dynamic port instance to activate
 * @extack: extack for reporting error messages
 *
 * Activate the dynamic port based on its flavour.
 *
 * Return: zero on success or an error code on failure.
 */
static int
ice_activate_dynamic_port(struct ice_dynamic_port *dyn_port,
			  struct netlink_ext_ack *extack)
{}

/**
 * ice_deactivate_dynamic_port - Deactivate a dynamic port
 * @dyn_port: dynamic port instance to deactivate
 *
 * Undo activation of a dynamic port.
 */
static void ice_deactivate_dynamic_port(struct ice_dynamic_port *dyn_port)
{}

/**
 * ice_dealloc_dynamic_port - Deallocate and remove a dynamic port
 * @dyn_port: dynamic port instance to deallocate
 *
 * Free resources associated with a dynamically added devlink port. Will
 * deactivate the port if its currently active.
 */
static void ice_dealloc_dynamic_port(struct ice_dynamic_port *dyn_port)
{}

/**
 * ice_dealloc_all_dynamic_ports - Deallocate all dynamic devlink ports
 * @pf: pointer to the pf structure
 */
void ice_dealloc_all_dynamic_ports(struct ice_pf *pf)
{}

/**
 * ice_devlink_port_new_check_attr - Check that new port attributes are valid
 * @pf: pointer to the PF structure
 * @new_attr: the attributes for the new port
 * @extack: extack for reporting error messages
 *
 * Check that the attributes for the new port are valid before continuing to
 * allocate the devlink port.
 *
 * Return: zero on success or an error code on failure.
 */
static int
ice_devlink_port_new_check_attr(struct ice_pf *pf,
				const struct devlink_port_new_attrs *new_attr,
				struct netlink_ext_ack *extack)
{}

/**
 * ice_devlink_port_del - devlink handler for port delete
 * @devlink: pointer to devlink
 * @port: devlink port to be deleted
 * @extack: pointer to extack
 *
 * Deletes devlink port and deallocates all resources associated with
 * created subfunction.
 *
 * Return: zero on success or an error code on failure.
 */
static int
ice_devlink_port_del(struct devlink *devlink, struct devlink_port *port,
		     struct netlink_ext_ack *extack)
{}

/**
 * ice_devlink_port_fn_hw_addr_set - devlink handler for mac address set
 * @port: pointer to devlink port
 * @hw_addr: hw address to set
 * @hw_addr_len: hw address length
 * @extack: extack for reporting error messages
 *
 * Sets mac address for the port, verifies arguments and copies address
 * to the subfunction structure.
 *
 * Return: zero on success or an error code on failure.
 */
static int
ice_devlink_port_fn_hw_addr_set(struct devlink_port *port, const u8 *hw_addr,
				int hw_addr_len,
				struct netlink_ext_ack *extack)
{}

/**
 * ice_devlink_port_fn_hw_addr_get - devlink handler for mac address get
 * @port: pointer to devlink port
 * @hw_addr: hw address to set
 * @hw_addr_len: hw address length
 * @extack: extack for reporting error messages
 *
 * Returns mac address for the port.
 *
 * Return: zero on success or an error code on failure.
 */
static int
ice_devlink_port_fn_hw_addr_get(struct devlink_port *port, u8 *hw_addr,
				int *hw_addr_len,
				struct netlink_ext_ack *extack)
{}

/**
 * ice_devlink_port_fn_state_set - devlink handler for port state set
 * @port: pointer to devlink port
 * @state: state to set
 * @extack: extack for reporting error messages
 *
 * Activates or deactivates the port.
 *
 * Return: zero on success or an error code on failure.
 */
static int
ice_devlink_port_fn_state_set(struct devlink_port *port,
			      enum devlink_port_fn_state state,
			      struct netlink_ext_ack *extack)
{}

/**
 * ice_devlink_port_fn_state_get - devlink handler for port state get
 * @port: pointer to devlink port
 * @state: admin configured state of the port
 * @opstate: current port operational state
 * @extack: extack for reporting error messages
 *
 * Gets port state.
 *
 * Return: zero on success or an error code on failure.
 */
static int
ice_devlink_port_fn_state_get(struct devlink_port *port,
			      enum devlink_port_fn_state *state,
			      enum devlink_port_fn_opstate *opstate,
			      struct netlink_ext_ack *extack)
{}

static const struct devlink_port_ops ice_devlink_port_sf_ops =;

/**
 * ice_reserve_sf_num - Reserve a subfunction number for this port
 * @pf: pointer to the pf structure
 * @new_attr: devlink port attributes requested
 * @extack: extack for reporting error messages
 * @sfnum: on success, the sf number reserved
 *
 * Reserve a subfunction number for this port. Only called for
 * DEVLINK_PORT_FLAVOUR_PCI_SF ports.
 *
 * Return: zero on success or an error code on failure.
 */
static int
ice_reserve_sf_num(struct ice_pf *pf,
		   const struct devlink_port_new_attrs *new_attr,
		   struct netlink_ext_ack *extack, u32 *sfnum)
{}

/**
 * ice_devlink_create_sf_port - Register PCI subfunction devlink port
 * @dyn_port: the dynamic port instance structure for this subfunction
 *
 * Register PCI subfunction flavour devlink port for a dynamically added
 * subfunction port.
 *
 * Return: zero on success or an error code on failure.
 */
int ice_devlink_create_sf_port(struct ice_dynamic_port *dyn_port)
{}

/**
 * ice_devlink_destroy_sf_port - Destroy the devlink_port for this SF
 * @dyn_port: the dynamic port instance structure for this subfunction
 *
 * Unregisters the devlink_port structure associated with this SF.
 */
void ice_devlink_destroy_sf_port(struct ice_dynamic_port *dyn_port)
{}

/**
 * ice_alloc_dynamic_port - Allocate new dynamic port
 * @pf: pointer to the pf structure
 * @new_attr: devlink port attributes requested
 * @extack: extack for reporting error messages
 * @devlink_port: index of newly created devlink port
 *
 * Allocate a new dynamic port instance and prepare it for configuration
 * with devlink.
 *
 * Return: zero on success or an error code on failure.
 */
static int
ice_alloc_dynamic_port(struct ice_pf *pf,
		       const struct devlink_port_new_attrs *new_attr,
		       struct netlink_ext_ack *extack,
		       struct devlink_port **devlink_port)
{}

/**
 * ice_devlink_port_new - devlink handler for the new port
 * @devlink: pointer to devlink
 * @new_attr: pointer to the port new attributes
 * @extack: extack for reporting error messages
 * @devlink_port: pointer to a new port
 *
 * Creates new devlink port, checks new port attributes and reject
 * any unsupported parameters, allocates new subfunction for that port.
 *
 * Return: zero on success or an error code on failure.
 */
int
ice_devlink_port_new(struct devlink *devlink,
		     const struct devlink_port_new_attrs *new_attr,
		     struct netlink_ext_ack *extack,
		     struct devlink_port **devlink_port)
{}