1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (C) 2021, Intel Corporation. */
4 /* Inter-Driver Communication */
7 #include "ice_dcb_lib.h"
10 * ice_get_auxiliary_drv - retrieve iidc_auxiliary_drv struct
11 * @pf: pointer to PF struct
13 * This function has to be called with a device_lock on the
14 * pf->adev.dev to avoid race conditions.
16 static struct iidc_auxiliary_drv *ice_get_auxiliary_drv(struct ice_pf *pf)
18 struct auxiliary_device *adev;
21 if (!adev || !adev->dev.driver)
24 return container_of(adev->dev.driver, struct iidc_auxiliary_drv,
29 * ice_send_event_to_aux - send event to RDMA AUX driver
30 * @pf: pointer to PF struct
31 * @event: event struct
33 void ice_send_event_to_aux(struct ice_pf *pf, struct iidc_event *event)
35 struct iidc_auxiliary_drv *iadrv;
37 if (WARN_ON_ONCE(!in_task()))
40 mutex_lock(&pf->adev_mutex);
44 device_lock(&pf->adev->dev);
45 iadrv = ice_get_auxiliary_drv(pf);
46 if (iadrv && iadrv->event_handler)
47 iadrv->event_handler(pf, event);
48 device_unlock(&pf->adev->dev);
50 mutex_unlock(&pf->adev_mutex);
54 * ice_find_vsi - Find the VSI from VSI ID
55 * @pf: The PF pointer to search in
56 * @vsi_num: The VSI ID to search for
58 static struct ice_vsi *ice_find_vsi(struct ice_pf *pf, u16 vsi_num)
62 ice_for_each_vsi(pf, i)
63 if (pf->vsi[i] && pf->vsi[i]->vsi_num == vsi_num)
69 * ice_add_rdma_qset - Add Leaf Node for RDMA Qset
71 * @qset: Resource to be allocated
73 int ice_add_rdma_qset(struct ice_pf *pf, struct iidc_rdma_qset_params *qset)
75 u16 max_rdmaqs[ICE_MAX_TRAFFIC_CLASS];
83 if (WARN_ON(!pf || !qset))
86 dev = ice_pf_to_dev(pf);
88 if (!ice_is_rdma_ena(pf))
91 vsi = ice_get_main_vsi(pf);
93 dev_err(dev, "RDMA QSet invalid VSI\n");
97 ice_for_each_traffic_class(i)
100 max_rdmaqs[qset->tc]++;
101 qs_handle = qset->qs_handle;
103 status = ice_cfg_vsi_rdma(vsi->port_info, vsi->idx, vsi->tc_cfg.ena_tc,
106 dev_err(dev, "Failed VSI RDMA Qset config\n");
110 status = ice_ena_vsi_rdma_qset(vsi->port_info, vsi->idx, qset->tc,
111 &qs_handle, 1, &qset_teid);
113 dev_err(dev, "Failed VSI RDMA Qset enable\n");
116 vsi->qset_handle[qset->tc] = qset->qs_handle;
117 qset->teid = qset_teid;
121 EXPORT_SYMBOL_GPL(ice_add_rdma_qset);
124 * ice_del_rdma_qset - Delete leaf node for RDMA Qset
126 * @qset: Resource to be freed
128 int ice_del_rdma_qset(struct ice_pf *pf, struct iidc_rdma_qset_params *qset)
134 if (WARN_ON(!pf || !qset))
137 vsi = ice_find_vsi(pf, qset->vport_id);
139 dev_err(ice_pf_to_dev(pf), "RDMA Invalid VSI\n");
143 q_id = qset->qs_handle;
146 vsi->qset_handle[qset->tc] = 0;
148 return ice_dis_vsi_rdma_qset(vsi->port_info, 1, &teid, &q_id);
150 EXPORT_SYMBOL_GPL(ice_del_rdma_qset);
153 * ice_rdma_request_reset - accept request from RDMA to perform a reset
155 * @reset_type: type of reset
157 int ice_rdma_request_reset(struct ice_pf *pf, enum iidc_reset_type reset_type)
159 enum ice_reset_req reset;
164 switch (reset_type) {
166 reset = ICE_RESET_PFR;
169 reset = ICE_RESET_CORER;
172 reset = ICE_RESET_GLOBR;
175 dev_err(ice_pf_to_dev(pf), "incorrect reset request\n");
179 return ice_schedule_reset(pf, reset);
181 EXPORT_SYMBOL_GPL(ice_rdma_request_reset);
184 * ice_rdma_update_vsi_filter - update main VSI filters for RDMA
185 * @pf: pointer to struct for PF
186 * @vsi_id: VSI HW idx to update filter on
187 * @enable: bool whether to enable or disable filters
189 int ice_rdma_update_vsi_filter(struct ice_pf *pf, u16 vsi_id, bool enable)
197 vsi = ice_find_vsi(pf, vsi_id);
201 status = ice_cfg_rdma_fltr(&pf->hw, vsi->idx, enable);
203 dev_err(ice_pf_to_dev(pf), "Failed to %sable RDMA filtering\n",
204 enable ? "en" : "dis");
207 vsi->info.q_opt_flags |= ICE_AQ_VSI_Q_OPT_PE_FLTR_EN;
209 vsi->info.q_opt_flags &= ~ICE_AQ_VSI_Q_OPT_PE_FLTR_EN;
214 EXPORT_SYMBOL_GPL(ice_rdma_update_vsi_filter);
217 * ice_get_qos_params - parse QoS params for RDMA consumption
218 * @pf: pointer to PF struct
219 * @qos: set of QoS values
221 void ice_get_qos_params(struct ice_pf *pf, struct iidc_qos_params *qos)
223 struct ice_dcbx_cfg *dcbx_cfg;
227 dcbx_cfg = &pf->hw.port_info->qos_cfg.local_dcbx_cfg;
228 up2tc = rd32(&pf->hw, PRTDCB_TUP2TC);
230 qos->num_tc = ice_dcb_get_num_tc(dcbx_cfg);
231 for (i = 0; i < IIDC_MAX_USER_PRIORITY; i++)
232 qos->up2tc[i] = (up2tc >> (i * 3)) & 0x7;
234 for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++)
235 qos->tc_info[i].rel_bw = dcbx_cfg->etscfg.tcbwtable[i];
237 qos->pfc_mode = dcbx_cfg->pfc_mode;
238 if (qos->pfc_mode == IIDC_DSCP_PFC_MODE)
239 for (i = 0; i < IIDC_MAX_DSCP_MAPPING; i++)
240 qos->dscp_map[i] = dcbx_cfg->dscp_map[i];
242 EXPORT_SYMBOL_GPL(ice_get_qos_params);
245 * ice_reserve_rdma_qvector - Reserve vector resources for RDMA driver
246 * @pf: board private structure to initialize
248 static int ice_reserve_rdma_qvector(struct ice_pf *pf)
250 if (ice_is_rdma_ena(pf)) {
253 index = ice_get_res(pf, pf->irq_tracker, pf->num_rdma_msix,
254 ICE_RES_RDMA_VEC_ID);
257 pf->num_avail_sw_msix -= pf->num_rdma_msix;
258 pf->rdma_base_vector = (u16)index;
264 * ice_adev_release - function to be mapped to AUX dev's release op
265 * @dev: pointer to device to free
267 static void ice_adev_release(struct device *dev)
269 struct iidc_auxiliary_dev *iadev;
271 iadev = container_of(dev, struct iidc_auxiliary_dev, adev.dev);
276 * ice_plug_aux_dev - allocate and register AUX device
277 * @pf: pointer to pf struct
279 int ice_plug_aux_dev(struct ice_pf *pf)
281 struct iidc_auxiliary_dev *iadev;
282 struct auxiliary_device *adev;
285 /* if this PF doesn't support a technology that requires auxiliary
286 * devices, then gracefully exit
288 if (!ice_is_rdma_ena(pf))
291 iadev = kzalloc(sizeof(*iadev), GFP_KERNEL);
298 adev->id = pf->aux_idx;
299 adev->dev.release = ice_adev_release;
300 adev->dev.parent = &pf->pdev->dev;
301 adev->name = pf->rdma_mode & IIDC_RDMA_PROTOCOL_ROCEV2 ? "roce" : "iwarp";
303 ret = auxiliary_device_init(adev);
309 ret = auxiliary_device_add(adev);
311 auxiliary_device_uninit(adev);
315 mutex_lock(&pf->adev_mutex);
317 mutex_unlock(&pf->adev_mutex);
322 /* ice_unplug_aux_dev - unregister and free AUX device
323 * @pf: pointer to pf struct
325 void ice_unplug_aux_dev(struct ice_pf *pf)
327 struct auxiliary_device *adev;
329 mutex_lock(&pf->adev_mutex);
332 mutex_unlock(&pf->adev_mutex);
335 auxiliary_device_delete(adev);
336 auxiliary_device_uninit(adev);
341 * ice_init_rdma - initializes PF for RDMA use
344 int ice_init_rdma(struct ice_pf *pf)
346 struct device *dev = &pf->pdev->dev;
349 /* Reserve vector resources */
350 ret = ice_reserve_rdma_qvector(pf);
352 dev_err(dev, "failed to reserve vectors for RDMA\n");
355 pf->rdma_mode |= IIDC_RDMA_PROTOCOL_ROCEV2;
356 return ice_plug_aux_dev(pf);