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