On 17/04/2024 17:20, Michal Swiatkowski wrote:
+/**
+ * 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)
+{
+       struct ice_dynamic_port *dyn_port;
+
+       dyn_port = ice_devlink_port_to_dyn(port);
+
+       if (dyn_port->active) {
+               *state = DEVLINK_PORT_FN_STATE_ACTIVE;
+               *opstate = DEVLINK_PORT_FN_OPSTATE_ATTACHED;


DEVLINK_PORT_FN_OPSTATE_ATTACHED means the SF is up/bind[1].
ice is using auxiliary bus for SFs, which means user can unbind it
via the auxiliary sysfs (/sys/bus/auxiliary/drivers/ice_sf/unbind).
In this case[2], you need to return:
*state = DEVLINK_PORT_FN_STATE_ACTIVE;
*opstate = DEVLINK_PORT_FN_OPSTATE_DETACHED;


[1]
Documentation from include/uapi/linux/devlink.h:

* @DEVLINK_PORT_FN_OPSTATE_ATTACHED: Driver is attached to the function. <...>
* @DEVLINK_PORT_FN_OPSTATE_DETACHED: Driver is detached from the function.

+       } else {
+               *state = DEVLINK_PORT_FN_STATE_INACTIVE;
+               *opstate = DEVLINK_PORT_FN_OPSTATE_DETACHED;
+       }
+
+       return 0;
+}
+

Reply via email to