Skip to content

Commit be91128

Browse files
jahay1anguy11
authored andcommitted
idpf: implement RDMA vport auxiliary dev create, init, and destroy
Implement the functions to create, initialize, and destroy an RDMA vport auxiliary device. The vport aux dev creation is dependent on the core aux device to call idpf_idc_vport_dev_ctrl to signal that it is ready for vport aux devices. Implement that core callback to either create and initialize the vport aux dev or deinitialize. RDMA vport aux dev creation is also dependent on the control plane to tell us the vport is RDMA enabled. Add a flag in the create vport message to signal individual vport RDMA capabilities. Reviewed-by: Madhu Chittim <[email protected]> Signed-off-by: Joshua Hay <[email protected]> Signed-off-by: Tatyana Nikolova <[email protected]> Signed-off-by: Tony Nguyen <[email protected]>
1 parent f4312e6 commit be91128

File tree

5 files changed

+207
-1
lines changed

5 files changed

+207
-1
lines changed

drivers/net/ethernet/intel/idpf/idpf.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ struct idpf_port_stats {
281281
* group will yield total number of RX queues.
282282
* @rxq_model: Splitq queue or single queue queuing model
283283
* @rx_ptype_lkup: Lookup table for ptypes on RX
284+
* @vdev_info: IDC vport device info pointer
284285
* @adapter: back pointer to associated adapter
285286
* @netdev: Associated net_device. Each vport should have one and only one
286287
* associated netdev.
@@ -326,6 +327,8 @@ struct idpf_vport {
326327
u32 rxq_model;
327328
struct libeth_rx_pt *rx_ptype_lkup;
328329

330+
struct iidc_rdma_vport_dev_info *vdev_info;
331+
329332
struct idpf_adapter *adapter;
330333
struct net_device *netdev;
331334
DECLARE_BITMAP(flags, IDPF_VPORT_FLAGS_NBITS);
@@ -889,5 +892,6 @@ int idpf_idc_init(struct idpf_adapter *adapter);
889892
int idpf_idc_init_aux_core_dev(struct idpf_adapter *adapter,
890893
enum iidc_function_type ftype);
891894
void idpf_idc_deinit_core_aux_device(struct iidc_rdma_core_dev_info *cdev_info);
895+
void idpf_idc_deinit_vport_aux_device(struct iidc_rdma_vport_dev_info *vdev_info);
892896

893897
#endif /* !_IDPF_H_ */

drivers/net/ethernet/intel/idpf/idpf_idc.c

Lines changed: 179 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,115 @@ int idpf_idc_init(struct idpf_adapter *adapter)
3232
return err;
3333
}
3434

35+
/**
36+
* idpf_vport_adev_release - function to be mapped to aux dev's release op
37+
* @dev: pointer to device to free
38+
*/
39+
static void idpf_vport_adev_release(struct device *dev)
40+
{
41+
struct iidc_rdma_vport_auxiliary_dev *iadev;
42+
43+
iadev = container_of(dev, struct iidc_rdma_vport_auxiliary_dev, adev.dev);
44+
kfree(iadev);
45+
iadev = NULL;
46+
}
47+
48+
/**
49+
* idpf_plug_vport_aux_dev - allocate and register a vport Auxiliary device
50+
* @cdev_info: IDC core device info pointer
51+
* @vdev_info: IDC vport device info pointer
52+
*
53+
* Return: 0 on success or error code on failure.
54+
*/
55+
static int idpf_plug_vport_aux_dev(struct iidc_rdma_core_dev_info *cdev_info,
56+
struct iidc_rdma_vport_dev_info *vdev_info)
57+
{
58+
struct iidc_rdma_vport_auxiliary_dev *iadev;
59+
char name[IDPF_IDC_MAX_ADEV_NAME_LEN];
60+
struct auxiliary_device *adev;
61+
int ret;
62+
63+
iadev = kzalloc(sizeof(*iadev), GFP_KERNEL);
64+
if (!iadev)
65+
return -ENOMEM;
66+
67+
adev = &iadev->adev;
68+
vdev_info->adev = &iadev->adev;
69+
iadev->vdev_info = vdev_info;
70+
71+
ret = ida_alloc(&idpf_idc_ida, GFP_KERNEL);
72+
if (ret < 0) {
73+
pr_err("failed to allocate unique device ID for Auxiliary driver\n");
74+
goto err_ida_alloc;
75+
}
76+
adev->id = ret;
77+
adev->dev.release = idpf_vport_adev_release;
78+
adev->dev.parent = &cdev_info->pdev->dev;
79+
sprintf(name, "%04x.rdma.vdev", cdev_info->pdev->vendor);
80+
adev->name = name;
81+
82+
ret = auxiliary_device_init(adev);
83+
if (ret)
84+
goto err_aux_dev_init;
85+
86+
ret = auxiliary_device_add(adev);
87+
if (ret)
88+
goto err_aux_dev_add;
89+
90+
return 0;
91+
92+
err_aux_dev_add:
93+
auxiliary_device_uninit(adev);
94+
err_aux_dev_init:
95+
ida_free(&idpf_idc_ida, adev->id);
96+
err_ida_alloc:
97+
vdev_info->adev = NULL;
98+
kfree(iadev);
99+
100+
return ret;
101+
}
102+
103+
/**
104+
* idpf_idc_init_aux_vport_dev - initialize vport Auxiliary Device(s)
105+
* @vport: virtual port data struct
106+
*
107+
* Return: 0 on success or error code on failure.
108+
*/
109+
static int idpf_idc_init_aux_vport_dev(struct idpf_vport *vport)
110+
{
111+
struct idpf_adapter *adapter = vport->adapter;
112+
struct iidc_rdma_vport_dev_info *vdev_info;
113+
struct iidc_rdma_core_dev_info *cdev_info;
114+
struct virtchnl2_create_vport *vport_msg;
115+
int err;
116+
117+
vport_msg = (struct virtchnl2_create_vport *)
118+
adapter->vport_params_recvd[vport->idx];
119+
120+
if (!(le16_to_cpu(vport_msg->vport_flags) & VIRTCHNL2_VPORT_ENABLE_RDMA))
121+
return 0;
122+
123+
vport->vdev_info = kzalloc(sizeof(*vdev_info), GFP_KERNEL);
124+
if (!vport->vdev_info)
125+
return -ENOMEM;
126+
127+
cdev_info = vport->adapter->cdev_info;
128+
129+
vdev_info = vport->vdev_info;
130+
vdev_info->vport_id = vport->vport_id;
131+
vdev_info->netdev = vport->netdev;
132+
vdev_info->core_adev = cdev_info->adev;
133+
134+
err = idpf_plug_vport_aux_dev(cdev_info, vdev_info);
135+
if (err) {
136+
vport->vdev_info = NULL;
137+
kfree(vdev_info);
138+
return err;
139+
}
140+
141+
return 0;
142+
}
143+
35144
/**
36145
* idpf_core_adev_release - function to be mapped to aux dev's release op
37146
* @dev: pointer to device to free
@@ -104,12 +213,60 @@ static int idpf_plug_core_aux_dev(struct iidc_rdma_core_dev_info *cdev_info)
104213
*/
105214
static void idpf_unplug_aux_dev(struct auxiliary_device *adev)
106215
{
216+
if (!adev)
217+
return;
218+
107219
auxiliary_device_delete(adev);
108220
auxiliary_device_uninit(adev);
109221

110222
ida_free(&idpf_idc_ida, adev->id);
111223
}
112224

225+
/**
226+
* idpf_idc_vport_dev_up - called when CORE is ready for vport aux devs
227+
* @adapter: private data struct
228+
*
229+
* Return: 0 on success or error code on failure.
230+
*/
231+
static int idpf_idc_vport_dev_up(struct idpf_adapter *adapter)
232+
{
233+
int i, err = 0;
234+
235+
for (i = 0; i < adapter->num_alloc_vports; i++) {
236+
struct idpf_vport *vport = adapter->vports[i];
237+
238+
if (!vport)
239+
continue;
240+
241+
if (!vport->vdev_info)
242+
err = idpf_idc_init_aux_vport_dev(vport);
243+
else
244+
err = idpf_plug_vport_aux_dev(vport->adapter->cdev_info,
245+
vport->vdev_info);
246+
}
247+
248+
return err;
249+
}
250+
251+
/**
252+
* idpf_idc_vport_dev_down - called CORE is leaving vport aux dev support state
253+
* @adapter: private data struct
254+
*/
255+
static void idpf_idc_vport_dev_down(struct idpf_adapter *adapter)
256+
{
257+
int i;
258+
259+
for (i = 0; i < adapter->num_alloc_vports; i++) {
260+
struct idpf_vport *vport = adapter->vports[i];
261+
262+
if (!vport)
263+
continue;
264+
265+
idpf_unplug_aux_dev(vport->vdev_info->adev);
266+
vport->vdev_info->adev = NULL;
267+
}
268+
}
269+
113270
/**
114271
* idpf_idc_vport_dev_ctrl - Called by an Auxiliary Driver
115272
* @cdev_info: IDC core device info pointer
@@ -123,7 +280,14 @@ static void idpf_unplug_aux_dev(struct auxiliary_device *adev)
123280
*/
124281
int idpf_idc_vport_dev_ctrl(struct iidc_rdma_core_dev_info *cdev_info, bool up)
125282
{
126-
return -EOPNOTSUPP;
283+
struct idpf_adapter *adapter = pci_get_drvdata(cdev_info->pdev);
284+
285+
if (up)
286+
return idpf_idc_vport_dev_up(adapter);
287+
288+
idpf_idc_vport_dev_down(adapter);
289+
290+
return 0;
127291
}
128292
EXPORT_SYMBOL_GPL(idpf_idc_vport_dev_ctrl);
129293

@@ -225,3 +389,17 @@ void idpf_idc_deinit_core_aux_device(struct iidc_rdma_core_dev_info *cdev_info)
225389
kfree(cdev_info->iidc_priv);
226390
kfree(cdev_info);
227391
}
392+
393+
/**
394+
* idpf_idc_deinit_vport_aux_device - de-initialize Auxiliary Device(s)
395+
* @vdev_info: IDC vport device info pointer
396+
*/
397+
void idpf_idc_deinit_vport_aux_device(struct iidc_rdma_vport_dev_info *vdev_info)
398+
{
399+
if (!vdev_info)
400+
return;
401+
402+
idpf_unplug_aux_dev(vdev_info->adev);
403+
404+
kfree(vdev_info);
405+
}

drivers/net/ethernet/intel/idpf/idpf_lib.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,8 @@ static void idpf_vport_dealloc(struct idpf_vport *vport)
10211021
struct idpf_adapter *adapter = vport->adapter;
10221022
unsigned int i = vport->idx;
10231023

1024+
idpf_idc_deinit_vport_aux_device(vport->vdev_info);
1025+
10241026
idpf_deinit_mac_addr(vport);
10251027
idpf_vport_stop(vport);
10261028

drivers/net/ethernet/intel/idpf/virtchnl2.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,9 +575,12 @@ VIRTCHNL2_CHECK_STRUCT_LEN(8, virtchnl2_queue_reg_chunks);
575575
/**
576576
* enum virtchnl2_vport_flags - Vport flags that indicate vport capabilities.
577577
* @VIRTCHNL2_VPORT_UPLINK_PORT: Representatives of underlying physical ports
578+
* @VIRTCHNL2_VPORT_ENABLE_RDMA: RDMA is enabled for this vport
578579
*/
579580
enum virtchnl2_vport_flags {
580581
VIRTCHNL2_VPORT_UPLINK_PORT = BIT(0),
582+
/* VIRTCHNL2_VPORT_* bits [1:3] rsvd */
583+
VIRTCHNL2_VPORT_ENABLE_RDMA = BIT(4),
581584
};
582585

583586
/**

include/linux/net/intel/iidc_rdma_idpf.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,25 @@
66

77
#include <linux/auxiliary_bus.h>
88

9+
/* struct to be populated by core LAN PCI driver */
10+
struct iidc_rdma_vport_dev_info {
11+
struct auxiliary_device *adev;
12+
struct auxiliary_device *core_adev;
13+
struct net_device *netdev;
14+
u16 vport_id;
15+
};
16+
17+
struct iidc_rdma_vport_auxiliary_dev {
18+
struct auxiliary_device adev;
19+
struct iidc_rdma_vport_dev_info *vdev_info;
20+
};
21+
22+
struct iidc_rdma_vport_auxiliary_drv {
23+
struct auxiliary_driver adrv;
24+
void (*event_handler)(struct iidc_rdma_vport_dev_info *vdev,
25+
struct iidc_rdma_event *event);
26+
};
27+
928
/* struct to be populated by core LAN PCI driver */
1029
enum iidc_function_type {
1130
IIDC_FUNCTION_TYPE_PF,

0 commit comments

Comments
 (0)