Skip to content

Commit 177ef7f

Browse files
praczynsanguy11
authored andcommitted
ice: base subfunction aux driver
Implement subfunction driver. It is probe when subfunction port is activated. VSI is already created. During the probe VSI is being configured. MAC unicast and broadcast filter is added to allow traffic to pass. Store subfunction pointer in VSI struct. The same is done for VF pointer. Make union of subfunction and VF pointer as only one of them can be set with one VSI. Reviewed-by: Simon Horman <[email protected]> Reviewed-by: Jiri Pirko <[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 f43e3be commit 177ef7f

File tree

7 files changed

+215
-1
lines changed

7 files changed

+215
-1
lines changed

drivers/net/ethernet/intel/ice/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ ice-y := ice_main.o \
3333
ice_idc.o \
3434
devlink/devlink.o \
3535
devlink/devlink_port.o \
36+
ice_sf_eth.o \
3637
ice_ddp.o \
3738
ice_fw_update.o \
3839
ice_lag.o \

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,47 @@ void ice_devlink_destroy_vf_port(struct ice_vf *vf)
489489
devl_port_unregister(&vf->devlink_port);
490490
}
491491

492+
/**
493+
* ice_devlink_create_sf_dev_port - Register virtual port for a subfunction
494+
* @sf_dev: the subfunction device to create a devlink port for
495+
*
496+
* Register virtual flavour devlink port for the subfunction auxiliary device
497+
* created after activating a dynamically added devlink port.
498+
*
499+
* Return: zero on success or an error code on failure.
500+
*/
501+
int ice_devlink_create_sf_dev_port(struct ice_sf_dev *sf_dev)
502+
{
503+
struct devlink_port_attrs attrs = {};
504+
struct ice_dynamic_port *dyn_port;
505+
struct devlink_port *devlink_port;
506+
struct devlink *devlink;
507+
struct ice_vsi *vsi;
508+
509+
dyn_port = sf_dev->dyn_port;
510+
vsi = dyn_port->vsi;
511+
512+
devlink_port = &sf_dev->priv->devlink_port;
513+
514+
attrs.flavour = DEVLINK_PORT_FLAVOUR_VIRTUAL;
515+
516+
devlink_port_attrs_set(devlink_port, &attrs);
517+
devlink = priv_to_devlink(sf_dev->priv);
518+
519+
return devl_port_register(devlink, devlink_port, vsi->idx);
520+
}
521+
522+
/**
523+
* ice_devlink_destroy_sf_dev_port - Destroy virtual port for a subfunction
524+
* @sf_dev: the subfunction device to create a devlink port for
525+
*
526+
* Unregisters the virtual port associated with this subfunction.
527+
*/
528+
void ice_devlink_destroy_sf_dev_port(struct ice_sf_dev *sf_dev)
529+
{
530+
devl_port_unregister(&sf_dev->priv->devlink_port);
531+
}
532+
492533
/**
493534
* ice_dealloc_dynamic_port - Deallocate and remove a dynamic port
494535
* @dyn_port: dynamic port instance to deallocate

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#define _DEVLINK_PORT_H_
66

77
#include "../ice.h"
8+
#include "../ice_sf_eth.h"
89

910
/**
1011
* struct ice_dynamic_port - Track dynamically added devlink port instance
@@ -34,6 +35,8 @@ int ice_devlink_create_vf_port(struct ice_vf *vf);
3435
void ice_devlink_destroy_vf_port(struct ice_vf *vf);
3536
int ice_devlink_create_sf_port(struct ice_dynamic_port *dyn_port);
3637
void ice_devlink_destroy_sf_port(struct ice_dynamic_port *dyn_port);
38+
int ice_devlink_create_sf_dev_port(struct ice_sf_dev *sf_dev);
39+
void ice_devlink_destroy_sf_dev_port(struct ice_sf_dev *sf_dev);
3740

3841
#define ice_devlink_port_to_dyn(port) \
3942
container_of(port, struct ice_dynamic_port, devlink_port)

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,12 @@ struct ice_vsi {
451451
struct_group_tagged(ice_vsi_cfg_params, params,
452452
struct ice_port_info *port_info; /* back pointer to port_info */
453453
struct ice_channel *ch; /* VSI's channel structure, may be NULL */
454-
struct ice_vf *vf; /* VF associated with this VSI, may be NULL */
454+
union {
455+
/* VF associated with this VSI, may be NULL */
456+
struct ice_vf *vf;
457+
/* SF associated with this VSI, may be NULL */
458+
struct ice_dynamic_port *sf;
459+
};
455460
u32 flags; /* VSI flags used for rebuild and configuration */
456461
enum ice_vsi_type type; /* the type of the VSI */
457462
);

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "ice_dcb_nl.h"
1616
#include "devlink/devlink.h"
1717
#include "devlink/devlink_port.h"
18+
#include "ice_sf_eth.h"
1819
#include "ice_hwmon.h"
1920
/* Including ice_trace.h with CREATE_TRACE_POINTS defined will generate the
2021
* ice tracepoint functions. This must be done exactly once across the
@@ -5934,8 +5935,16 @@ static int __init ice_module_init(void)
59345935
goto err_dest_lag_wq;
59355936
}
59365937

5938+
status = ice_sf_driver_register();
5939+
if (status) {
5940+
pr_err("Failed to register SF driver, err %d\n", status);
5941+
goto err_sf_driver;
5942+
}
5943+
59375944
return 0;
59385945

5946+
err_sf_driver:
5947+
pci_unregister_driver(&ice_driver);
59395948
err_dest_lag_wq:
59405949
destroy_workqueue(ice_lag_wq);
59415950
ice_debugfs_exit();
@@ -5953,6 +5962,7 @@ module_init(ice_module_init);
59535962
*/
59545963
static void __exit ice_module_exit(void)
59555964
{
5965+
ice_sf_driver_unregister();
59565966
pci_unregister_driver(&ice_driver);
59575967
ice_debugfs_exit();
59585968
destroy_workqueue(ice_wq);
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/* Copyright (c) 2024, Intel Corporation. */
3+
#include "ice.h"
4+
#include "ice_lib.h"
5+
#include "ice_fltr.h"
6+
#include "ice_sf_eth.h"
7+
#include "devlink/devlink_port.h"
8+
#include "devlink/devlink.h"
9+
10+
/**
11+
* ice_sf_dev_probe - subfunction driver probe function
12+
* @adev: pointer to the auxiliary device
13+
* @id: pointer to the auxiliary_device id
14+
*
15+
* Configure VSI and netdev resources for the subfunction device.
16+
*
17+
* Return: zero on success or an error code on failure.
18+
*/
19+
static int ice_sf_dev_probe(struct auxiliary_device *adev,
20+
const struct auxiliary_device_id *id)
21+
{
22+
struct ice_sf_dev *sf_dev = ice_adev_to_sf_dev(adev);
23+
struct ice_dynamic_port *dyn_port = sf_dev->dyn_port;
24+
struct ice_vsi *vsi = dyn_port->vsi;
25+
struct ice_pf *pf = dyn_port->pf;
26+
struct device *dev = &adev->dev;
27+
struct ice_sf_priv *priv;
28+
struct devlink *devlink;
29+
int err;
30+
31+
vsi->type = ICE_VSI_SF;
32+
vsi->port_info = pf->hw.port_info;
33+
vsi->flags = ICE_VSI_FLAG_INIT;
34+
35+
priv = ice_allocate_sf(&adev->dev, pf);
36+
if (!priv) {
37+
dev_err(dev, "Subfunction devlink alloc failed");
38+
return -ENOMEM;
39+
}
40+
41+
priv->dev = sf_dev;
42+
sf_dev->priv = priv;
43+
devlink = priv_to_devlink(priv);
44+
45+
devl_lock(devlink);
46+
47+
err = ice_vsi_cfg(vsi);
48+
if (err) {
49+
dev_err(dev, "Subfunction vsi config failed");
50+
goto err_free_devlink;
51+
}
52+
vsi->sf = dyn_port;
53+
54+
err = ice_devlink_create_sf_dev_port(sf_dev);
55+
if (err) {
56+
dev_err(dev, "Cannot add ice virtual devlink port for subfunction");
57+
goto err_vsi_decfg;
58+
}
59+
60+
err = devl_port_fn_devlink_set(&dyn_port->devlink_port, devlink);
61+
if (err) {
62+
dev_err(dev, "Can't link devlink instance to SF devlink port");
63+
goto err_devlink_destroy;
64+
}
65+
66+
ice_napi_add(vsi);
67+
68+
devl_register(devlink);
69+
devl_unlock(devlink);
70+
71+
return 0;
72+
73+
err_devlink_destroy:
74+
ice_devlink_destroy_sf_dev_port(sf_dev);
75+
err_vsi_decfg:
76+
ice_vsi_decfg(vsi);
77+
err_free_devlink:
78+
devl_unlock(devlink);
79+
devlink_free(devlink);
80+
return err;
81+
}
82+
83+
/**
84+
* ice_sf_dev_remove - subfunction driver remove function
85+
* @adev: pointer to the auxiliary device
86+
*
87+
* Deinitalize VSI and netdev resources for the subfunction device.
88+
*/
89+
static void ice_sf_dev_remove(struct auxiliary_device *adev)
90+
{
91+
struct ice_sf_dev *sf_dev = ice_adev_to_sf_dev(adev);
92+
struct ice_dynamic_port *dyn_port = sf_dev->dyn_port;
93+
struct ice_vsi *vsi = dyn_port->vsi;
94+
struct devlink *devlink;
95+
96+
devlink = priv_to_devlink(sf_dev->priv);
97+
devl_lock(devlink);
98+
99+
ice_vsi_close(vsi);
100+
101+
ice_devlink_destroy_sf_dev_port(sf_dev);
102+
devl_unregister(devlink);
103+
devl_unlock(devlink);
104+
devlink_free(devlink);
105+
ice_vsi_decfg(vsi);
106+
}
107+
108+
static const struct auxiliary_device_id ice_sf_dev_id_table[] = {
109+
{ .name = "ice.sf", },
110+
{ },
111+
};
112+
113+
MODULE_DEVICE_TABLE(auxiliary, ice_sf_dev_id_table);
114+
115+
static struct auxiliary_driver ice_sf_driver = {
116+
.name = "sf",
117+
.probe = ice_sf_dev_probe,
118+
.remove = ice_sf_dev_remove,
119+
.id_table = ice_sf_dev_id_table
120+
};
121+
122+
/**
123+
* ice_sf_driver_register - Register new auxiliary subfunction driver
124+
*
125+
* Return: zero on success or an error code on failure.
126+
*/
127+
int ice_sf_driver_register(void)
128+
{
129+
return auxiliary_driver_register(&ice_sf_driver);
130+
}
131+
132+
/**
133+
* ice_sf_driver_unregister - Unregister new auxiliary subfunction driver
134+
*
135+
*/
136+
void ice_sf_driver_unregister(void)
137+
{
138+
auxiliary_driver_unregister(&ice_sf_driver);
139+
}

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,24 @@
77
#include <linux/auxiliary_bus.h>
88
#include "ice.h"
99

10+
struct ice_sf_dev {
11+
struct auxiliary_device adev;
12+
struct ice_dynamic_port *dyn_port;
13+
struct ice_sf_priv *priv;
14+
};
15+
1016
struct ice_sf_priv {
1117
struct ice_sf_dev *dev;
1218
struct devlink_port devlink_port;
1319
};
1420

21+
static inline struct
22+
ice_sf_dev *ice_adev_to_sf_dev(struct auxiliary_device *adev)
23+
{
24+
return container_of(adev, struct ice_sf_dev, adev);
25+
}
26+
27+
int ice_sf_driver_register(void);
28+
void ice_sf_driver_unregister(void);
29+
1530
#endif /* _ICE_SF_ETH_H_ */

0 commit comments

Comments
 (0)