Skip to content

Commit 13acc5c

Browse files
praczynsanguy11
authored andcommitted
ice: subfunction activation and base devlink ops
Use previously implemented SF aux driver. It is probe during SF activation and remove after deactivation. Implement set/get hw_address and set/get state as basic devlink ops for subfunction. Reviewed-by: Simon Horman <[email protected]> Signed-off-by: Piotr Raczynski <[email protected]> Signed-off-by: Michal Swiatkowski <[email protected]> Tested-by: Rafal Romanowski <[email protected]> Signed-off-by: Tony Nguyen <[email protected]>
1 parent 0c6a3cb commit 13acc5c

File tree

4 files changed

+290
-0
lines changed

4 files changed

+290
-0
lines changed

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

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,48 @@ void ice_devlink_destroy_sf_dev_port(struct ice_sf_dev *sf_dev)
530530
devl_port_unregister(&sf_dev->priv->devlink_port);
531531
}
532532

533+
/**
534+
* ice_activate_dynamic_port - Activate a dynamic port
535+
* @dyn_port: dynamic port instance to activate
536+
* @extack: extack for reporting error messages
537+
*
538+
* Activate the dynamic port based on its flavour.
539+
*
540+
* Return: zero on success or an error code on failure.
541+
*/
542+
static int
543+
ice_activate_dynamic_port(struct ice_dynamic_port *dyn_port,
544+
struct netlink_ext_ack *extack)
545+
{
546+
int err;
547+
548+
if (dyn_port->active)
549+
return 0;
550+
551+
err = ice_sf_eth_activate(dyn_port, extack);
552+
if (err)
553+
return err;
554+
555+
dyn_port->active = true;
556+
557+
return 0;
558+
}
559+
560+
/**
561+
* ice_deactivate_dynamic_port - Deactivate a dynamic port
562+
* @dyn_port: dynamic port instance to deactivate
563+
*
564+
* Undo activation of a dynamic port.
565+
*/
566+
static void ice_deactivate_dynamic_port(struct ice_dynamic_port *dyn_port)
567+
{
568+
if (!dyn_port->active)
569+
return;
570+
571+
ice_sf_eth_deactivate(dyn_port);
572+
dyn_port->active = false;
573+
}
574+
533575
/**
534576
* ice_dealloc_dynamic_port - Deallocate and remove a dynamic port
535577
* @dyn_port: dynamic port instance to deallocate
@@ -542,6 +584,8 @@ static void ice_dealloc_dynamic_port(struct ice_dynamic_port *dyn_port)
542584
struct devlink_port *devlink_port = &dyn_port->devlink_port;
543585
struct ice_pf *pf = dyn_port->pf;
544586

587+
ice_deactivate_dynamic_port(dyn_port);
588+
545589
xa_erase(&pf->sf_nums, devlink_port->attrs.pci_sf.sf);
546590
ice_eswitch_detach_sf(pf, dyn_port);
547591
ice_vsi_free(dyn_port->vsi);
@@ -629,8 +673,140 @@ ice_devlink_port_del(struct devlink *devlink, struct devlink_port *port,
629673
return 0;
630674
}
631675

676+
/**
677+
* ice_devlink_port_fn_hw_addr_set - devlink handler for mac address set
678+
* @port: pointer to devlink port
679+
* @hw_addr: hw address to set
680+
* @hw_addr_len: hw address length
681+
* @extack: extack for reporting error messages
682+
*
683+
* Sets mac address for the port, verifies arguments and copies address
684+
* to the subfunction structure.
685+
*
686+
* Return: zero on success or an error code on failure.
687+
*/
688+
static int
689+
ice_devlink_port_fn_hw_addr_set(struct devlink_port *port, const u8 *hw_addr,
690+
int hw_addr_len,
691+
struct netlink_ext_ack *extack)
692+
{
693+
struct ice_dynamic_port *dyn_port;
694+
695+
dyn_port = ice_devlink_port_to_dyn(port);
696+
697+
if (dyn_port->attached) {
698+
NL_SET_ERR_MSG_MOD(extack,
699+
"Ethernet address can be change only in detached state");
700+
return -EBUSY;
701+
}
702+
703+
if (hw_addr_len != ETH_ALEN || !is_valid_ether_addr(hw_addr)) {
704+
NL_SET_ERR_MSG_MOD(extack, "Invalid ethernet address");
705+
return -EADDRNOTAVAIL;
706+
}
707+
708+
ether_addr_copy(dyn_port->hw_addr, hw_addr);
709+
710+
return 0;
711+
}
712+
713+
/**
714+
* ice_devlink_port_fn_hw_addr_get - devlink handler for mac address get
715+
* @port: pointer to devlink port
716+
* @hw_addr: hw address to set
717+
* @hw_addr_len: hw address length
718+
* @extack: extack for reporting error messages
719+
*
720+
* Returns mac address for the port.
721+
*
722+
* Return: zero on success or an error code on failure.
723+
*/
724+
static int
725+
ice_devlink_port_fn_hw_addr_get(struct devlink_port *port, u8 *hw_addr,
726+
int *hw_addr_len,
727+
struct netlink_ext_ack *extack)
728+
{
729+
struct ice_dynamic_port *dyn_port;
730+
731+
dyn_port = ice_devlink_port_to_dyn(port);
732+
733+
ether_addr_copy(hw_addr, dyn_port->hw_addr);
734+
*hw_addr_len = ETH_ALEN;
735+
736+
return 0;
737+
}
738+
739+
/**
740+
* ice_devlink_port_fn_state_set - devlink handler for port state set
741+
* @port: pointer to devlink port
742+
* @state: state to set
743+
* @extack: extack for reporting error messages
744+
*
745+
* Activates or deactivates the port.
746+
*
747+
* Return: zero on success or an error code on failure.
748+
*/
749+
static int
750+
ice_devlink_port_fn_state_set(struct devlink_port *port,
751+
enum devlink_port_fn_state state,
752+
struct netlink_ext_ack *extack)
753+
{
754+
struct ice_dynamic_port *dyn_port;
755+
756+
dyn_port = ice_devlink_port_to_dyn(port);
757+
758+
switch (state) {
759+
case DEVLINK_PORT_FN_STATE_ACTIVE:
760+
return ice_activate_dynamic_port(dyn_port, extack);
761+
762+
case DEVLINK_PORT_FN_STATE_INACTIVE:
763+
ice_deactivate_dynamic_port(dyn_port);
764+
break;
765+
}
766+
767+
return 0;
768+
}
769+
770+
/**
771+
* ice_devlink_port_fn_state_get - devlink handler for port state get
772+
* @port: pointer to devlink port
773+
* @state: admin configured state of the port
774+
* @opstate: current port operational state
775+
* @extack: extack for reporting error messages
776+
*
777+
* Gets port state.
778+
*
779+
* Return: zero on success or an error code on failure.
780+
*/
781+
static int
782+
ice_devlink_port_fn_state_get(struct devlink_port *port,
783+
enum devlink_port_fn_state *state,
784+
enum devlink_port_fn_opstate *opstate,
785+
struct netlink_ext_ack *extack)
786+
{
787+
struct ice_dynamic_port *dyn_port;
788+
789+
dyn_port = ice_devlink_port_to_dyn(port);
790+
791+
if (dyn_port->active)
792+
*state = DEVLINK_PORT_FN_STATE_ACTIVE;
793+
else
794+
*state = DEVLINK_PORT_FN_STATE_INACTIVE;
795+
796+
if (dyn_port->attached)
797+
*opstate = DEVLINK_PORT_FN_OPSTATE_ATTACHED;
798+
else
799+
*opstate = DEVLINK_PORT_FN_OPSTATE_DETACHED;
800+
801+
return 0;
802+
}
803+
632804
static const struct devlink_port_ops ice_devlink_port_sf_ops = {
633805
.port_del = ice_devlink_port_del,
806+
.port_fn_hw_addr_get = ice_devlink_port_fn_hw_addr_get,
807+
.port_fn_hw_addr_set = ice_devlink_port_fn_hw_addr_set,
808+
.port_fn_state_get = ice_devlink_port_fn_state_get,
809+
.port_fn_state_set = ice_devlink_port_fn_state_set,
634810
};
635811

636812
/**

drivers/net/ethernet/intel/ice/devlink/devlink_port.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,29 @@
1111
* struct ice_dynamic_port - Track dynamically added devlink port instance
1212
* @hw_addr: the HW address for this port
1313
* @active: true if the port has been activated
14+
* @attached: true it the prot is attached
1415
* @devlink_port: the associated devlink port structure
1516
* @pf: pointer to the PF private structure
1617
* @vsi: the VSI associated with this port
1718
* @repr_id: the representor ID
1819
* @sfnum: the subfunction ID
20+
* @sf_dev: pointer to the subfunction device
1921
*
2022
* An instance of a dynamically added devlink port. Each port flavour
2123
*/
2224
struct ice_dynamic_port {
2325
u8 hw_addr[ETH_ALEN];
2426
u8 active: 1;
27+
u8 attached: 1;
2528
struct devlink_port devlink_port;
2629
struct ice_pf *pf;
2730
struct ice_vsi *vsi;
2831
unsigned long repr_id;
2932
u32 sfnum;
33+
/* Flavour-specific implementation data */
34+
union {
35+
struct ice_sf_dev *sf_dev;
36+
};
3037
};
3138

3239
void ice_dealloc_all_dynamic_ports(struct ice_pf *pf);

drivers/net/ethernet/intel/ice/ice_sf_eth.c

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ static int ice_sf_dev_probe(struct auxiliary_device *adev,
151151
devl_register(devlink);
152152
devl_unlock(devlink);
153153

154+
dyn_port->attached = true;
155+
154156
return 0;
155157

156158
err_netdev_decfg:
@@ -189,6 +191,8 @@ static void ice_sf_dev_remove(struct auxiliary_device *adev)
189191
devl_unlock(devlink);
190192
devlink_free(devlink);
191193
ice_vsi_decfg(vsi);
194+
195+
dyn_port->attached = false;
192196
}
193197

194198
static const struct auxiliary_device_id ice_sf_dev_id_table[] = {
@@ -205,6 +209,8 @@ static struct auxiliary_driver ice_sf_driver = {
205209
.id_table = ice_sf_dev_id_table
206210
};
207211

212+
static DEFINE_XARRAY_ALLOC1(ice_sf_aux_id);
213+
208214
/**
209215
* ice_sf_driver_register - Register new auxiliary subfunction driver
210216
*
@@ -223,3 +229,101 @@ void ice_sf_driver_unregister(void)
223229
{
224230
auxiliary_driver_unregister(&ice_sf_driver);
225231
}
232+
233+
/**
234+
* ice_sf_dev_release - Release device associated with auxiliary device
235+
* @device: pointer to the device
236+
*
237+
* Since most of the code for subfunction deactivation is handled in
238+
* the remove handler, here just free tracking resources.
239+
*/
240+
static void ice_sf_dev_release(struct device *device)
241+
{
242+
struct auxiliary_device *adev = to_auxiliary_dev(device);
243+
struct ice_sf_dev *sf_dev = ice_adev_to_sf_dev(adev);
244+
245+
xa_erase(&ice_sf_aux_id, adev->id);
246+
kfree(sf_dev);
247+
}
248+
249+
/**
250+
* ice_sf_eth_activate - Activate Ethernet subfunction port
251+
* @dyn_port: the dynamic port instance for this subfunction
252+
* @extack: extack for reporting error messages
253+
*
254+
* Activate the dynamic port as an Ethernet subfunction. Setup the netdev
255+
* resources associated and initialize the auxiliary device.
256+
*
257+
* Return: zero on success or an error code on failure.
258+
*/
259+
int
260+
ice_sf_eth_activate(struct ice_dynamic_port *dyn_port,
261+
struct netlink_ext_ack *extack)
262+
{
263+
struct ice_pf *pf = dyn_port->pf;
264+
struct ice_sf_dev *sf_dev;
265+
struct pci_dev *pdev;
266+
int err;
267+
u32 id;
268+
269+
err = xa_alloc(&ice_sf_aux_id, &id, NULL, xa_limit_32b,
270+
GFP_KERNEL);
271+
if (err) {
272+
NL_SET_ERR_MSG_MOD(extack, "Could not allocate SF ID");
273+
return err;
274+
}
275+
276+
sf_dev = kzalloc(sizeof(*sf_dev), GFP_KERNEL);
277+
if (!sf_dev) {
278+
err = -ENOMEM;
279+
NL_SET_ERR_MSG_MOD(extack, "Could not allocate SF memory");
280+
goto xa_erase;
281+
}
282+
pdev = pf->pdev;
283+
284+
sf_dev->dyn_port = dyn_port;
285+
sf_dev->adev.id = id;
286+
sf_dev->adev.name = "sf";
287+
sf_dev->adev.dev.release = ice_sf_dev_release;
288+
sf_dev->adev.dev.parent = &pdev->dev;
289+
290+
err = auxiliary_device_init(&sf_dev->adev);
291+
if (err) {
292+
NL_SET_ERR_MSG_MOD(extack, "Failed to initialize SF device");
293+
goto sf_dev_free;
294+
}
295+
296+
err = auxiliary_device_add(&sf_dev->adev);
297+
if (err) {
298+
NL_SET_ERR_MSG_MOD(extack, "Failed to add SF device");
299+
goto aux_dev_uninit;
300+
}
301+
302+
dyn_port->sf_dev = sf_dev;
303+
304+
return 0;
305+
306+
aux_dev_uninit:
307+
auxiliary_device_uninit(&sf_dev->adev);
308+
sf_dev_free:
309+
kfree(sf_dev);
310+
xa_erase:
311+
xa_erase(&ice_sf_aux_id, id);
312+
313+
return err;
314+
}
315+
316+
/**
317+
* ice_sf_eth_deactivate - Deactivate Ethernet subfunction port
318+
* @dyn_port: the dynamic port instance for this subfunction
319+
*
320+
* Deactivate the Ethernet subfunction, removing its auxiliary device and the
321+
* associated resources.
322+
*/
323+
void ice_sf_eth_deactivate(struct ice_dynamic_port *dyn_port)
324+
{
325+
struct ice_sf_dev *sf_dev = dyn_port->sf_dev;
326+
327+
auxiliary_device_delete(&sf_dev->adev);
328+
auxiliary_device_uninit(&sf_dev->adev);
329+
}

drivers/net/ethernet/intel/ice/ice_sf_eth.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,7 @@ ice_sf_dev *ice_adev_to_sf_dev(struct auxiliary_device *adev)
2727
int ice_sf_driver_register(void);
2828
void ice_sf_driver_unregister(void);
2929

30+
int ice_sf_eth_activate(struct ice_dynamic_port *dyn_port,
31+
struct netlink_ext_ack *extack);
32+
void ice_sf_eth_deactivate(struct ice_dynamic_port *dyn_port);
3033
#endif /* _ICE_SF_ETH_H_ */

0 commit comments

Comments
 (0)