blob: 9fab29039f1c07ab79261c46a70fc7503e4b5fe6 [file] [log] [blame]
Mustafa Ismail8498a302021-06-02 15:51:23 -05001// SPDX-License-Identifier: GPL-2.0 or Linux-OpenIB
2/* Copyright (c) 2015 - 2021 Intel Corporation */
3#include "main.h"
4#include "../../../net/ethernet/intel/ice/ice.h"
5
6MODULE_ALIAS("i40iw");
7MODULE_AUTHOR("Intel Corporation, <e1000-rdma@lists.sourceforge.net>");
8MODULE_DESCRIPTION("Intel(R) Ethernet Protocol Driver for RDMA");
9MODULE_LICENSE("Dual BSD/GPL");
10
11static struct notifier_block irdma_inetaddr_notifier = {
12 .notifier_call = irdma_inetaddr_event
13};
14
15static struct notifier_block irdma_inetaddr6_notifier = {
16 .notifier_call = irdma_inet6addr_event
17};
18
19static struct notifier_block irdma_net_notifier = {
20 .notifier_call = irdma_net_event
21};
22
23static struct notifier_block irdma_netdevice_notifier = {
24 .notifier_call = irdma_netdevice_event
25};
26
27static void irdma_register_notifiers(void)
28{
29 register_inetaddr_notifier(&irdma_inetaddr_notifier);
30 register_inet6addr_notifier(&irdma_inetaddr6_notifier);
31 register_netevent_notifier(&irdma_net_notifier);
32 register_netdevice_notifier(&irdma_netdevice_notifier);
33}
34
35static void irdma_unregister_notifiers(void)
36{
37 unregister_netevent_notifier(&irdma_net_notifier);
38 unregister_inetaddr_notifier(&irdma_inetaddr_notifier);
39 unregister_inet6addr_notifier(&irdma_inetaddr6_notifier);
40 unregister_netdevice_notifier(&irdma_netdevice_notifier);
41}
42
43static void irdma_prep_tc_change(struct irdma_device *iwdev)
44{
45 iwdev->vsi.tc_change_pending = true;
46 irdma_sc_suspend_resume_qps(&iwdev->vsi, IRDMA_OP_SUSPEND);
47
48 /* Wait for all qp's to suspend */
49 wait_event_timeout(iwdev->suspend_wq,
50 !atomic_read(&iwdev->vsi.qp_suspend_reqs),
51 IRDMA_EVENT_TIMEOUT);
52 irdma_ws_reset(&iwdev->vsi);
53}
54
55static void irdma_log_invalid_mtu(u16 mtu, struct irdma_sc_dev *dev)
56{
57 if (mtu < IRDMA_MIN_MTU_IPV4)
58 ibdev_warn(to_ibdev(dev), "MTU setting [%d] too low for RDMA traffic. Minimum MTU is 576 for IPv4\n", mtu);
59 else if (mtu < IRDMA_MIN_MTU_IPV6)
60 ibdev_warn(to_ibdev(dev), "MTU setting [%d] too low for RDMA traffic. Minimum MTU is 1280 for IPv6\\n", mtu);
61}
62
63static void irdma_fill_qos_info(struct irdma_l2params *l2params,
64 struct iidc_qos_params *qos_info)
65{
66 int i;
67
68 l2params->num_tc = qos_info->num_tc;
69 l2params->vsi_prio_type = qos_info->vport_priority_type;
70 l2params->vsi_rel_bw = qos_info->vport_relative_bw;
71 for (i = 0; i < l2params->num_tc; i++) {
72 l2params->tc_info[i].egress_virt_up =
73 qos_info->tc_info[i].egress_virt_up;
74 l2params->tc_info[i].ingress_virt_up =
75 qos_info->tc_info[i].ingress_virt_up;
76 l2params->tc_info[i].prio_type = qos_info->tc_info[i].prio_type;
77 l2params->tc_info[i].rel_bw = qos_info->tc_info[i].rel_bw;
78 l2params->tc_info[i].tc_ctx = qos_info->tc_info[i].tc_ctx;
79 }
80 for (i = 0; i < IIDC_MAX_USER_PRIORITY; i++)
81 l2params->up2tc[i] = qos_info->up2tc[i];
82}
83
84static void irdma_iidc_event_handler(struct ice_pf *pf, struct iidc_event *event)
85{
86 struct irdma_device *iwdev = dev_get_drvdata(&pf->adev->dev);
87 struct irdma_l2params l2params = {};
88
89 if (*event->type & BIT(IIDC_EVENT_AFTER_MTU_CHANGE)) {
90 ibdev_dbg(&iwdev->ibdev, "CLNT: new MTU = %d\n", iwdev->netdev->mtu);
91 if (iwdev->vsi.mtu != iwdev->netdev->mtu) {
92 l2params.mtu = iwdev->netdev->mtu;
93 l2params.mtu_changed = true;
94 irdma_log_invalid_mtu(l2params.mtu, &iwdev->rf->sc_dev);
95 irdma_change_l2params(&iwdev->vsi, &l2params);
96 }
97 } else if (*event->type & BIT(IIDC_EVENT_BEFORE_TC_CHANGE)) {
98 if (iwdev->vsi.tc_change_pending)
99 return;
100
101 irdma_prep_tc_change(iwdev);
102 } else if (*event->type & BIT(IIDC_EVENT_AFTER_TC_CHANGE)) {
103 struct iidc_qos_params qos_info = {};
104
105 if (!iwdev->vsi.tc_change_pending)
106 return;
107
108 l2params.tc_changed = true;
109 ibdev_dbg(&iwdev->ibdev, "CLNT: TC Change\n");
110 ice_get_qos_params(pf, &qos_info);
111 iwdev->dcb = qos_info.num_tc > 1;
112 irdma_fill_qos_info(&l2params, &qos_info);
113 irdma_change_l2params(&iwdev->vsi, &l2params);
114 } else if (*event->type & BIT(IIDC_EVENT_CRIT_ERR)) {
115 ibdev_warn(&iwdev->ibdev, "ICE OICR event notification: oicr = 0x%08x\n",
116 event->reg);
117 if (event->reg & IRDMAPFINT_OICR_PE_CRITERR_M) {
118 u32 pe_criterr;
119
120 pe_criterr = readl(iwdev->rf->sc_dev.hw_regs[IRDMA_GLPE_CRITERR]);
121#define IRDMA_Q1_RESOURCE_ERR 0x0001024d
122 if (pe_criterr != IRDMA_Q1_RESOURCE_ERR) {
123 ibdev_err(&iwdev->ibdev, "critical PE Error, GLPE_CRITERR=0x%08x\n",
124 pe_criterr);
125 iwdev->rf->reset = true;
126 } else {
127 ibdev_warn(&iwdev->ibdev, "Q1 Resource Check\n");
128 }
129 }
130 if (event->reg & IRDMAPFINT_OICR_HMC_ERR_M) {
131 ibdev_err(&iwdev->ibdev, "HMC Error\n");
132 iwdev->rf->reset = true;
133 }
134 if (event->reg & IRDMAPFINT_OICR_PE_PUSH_M) {
135 ibdev_err(&iwdev->ibdev, "PE Push Error\n");
136 iwdev->rf->reset = true;
137 }
138 if (iwdev->rf->reset)
139 iwdev->rf->gen_ops.request_reset(iwdev->rf);
140 }
141}
142
143/**
144 * irdma_request_reset - Request a reset
145 * @rf: RDMA PCI function
146 */
147static void irdma_request_reset(struct irdma_pci_f *rf)
148{
149 struct ice_pf *pf = rf->cdev;
150
151 ibdev_warn(&rf->iwdev->ibdev, "Requesting a reset\n");
152 ice_rdma_request_reset(pf, IIDC_PFR);
153}
154
155/**
156 * irdma_lan_register_qset - Register qset with LAN driver
157 * @vsi: vsi structure
158 * @tc_node: Traffic class node
159 */
160static enum irdma_status_code irdma_lan_register_qset(struct irdma_sc_vsi *vsi,
161 struct irdma_ws_node *tc_node)
162{
163 struct irdma_device *iwdev = vsi->back_vsi;
164 struct ice_pf *pf = iwdev->rf->cdev;
165 struct iidc_rdma_qset_params qset = {};
166 int ret;
167
168 qset.qs_handle = tc_node->qs_handle;
169 qset.tc = tc_node->traffic_class;
170 qset.vport_id = vsi->vsi_idx;
171 ret = ice_add_rdma_qset(pf, &qset);
172 if (ret) {
173 ibdev_dbg(&iwdev->ibdev, "WS: LAN alloc_res for rdma qset failed.\n");
174 return IRDMA_ERR_REG_QSET;
175 }
176
177 tc_node->l2_sched_node_id = qset.teid;
178 vsi->qos[tc_node->user_pri].l2_sched_node_id = qset.teid;
179
180 return 0;
181}
182
183/**
184 * irdma_lan_unregister_qset - Unregister qset with LAN driver
185 * @vsi: vsi structure
186 * @tc_node: Traffic class node
187 */
188static void irdma_lan_unregister_qset(struct irdma_sc_vsi *vsi,
189 struct irdma_ws_node *tc_node)
190{
191 struct irdma_device *iwdev = vsi->back_vsi;
192 struct ice_pf *pf = iwdev->rf->cdev;
193 struct iidc_rdma_qset_params qset = {};
194
195 qset.qs_handle = tc_node->qs_handle;
196 qset.tc = tc_node->traffic_class;
197 qset.vport_id = vsi->vsi_idx;
198 qset.teid = tc_node->l2_sched_node_id;
199
200 if (ice_del_rdma_qset(pf, &qset))
201 ibdev_dbg(&iwdev->ibdev, "WS: LAN free_res for rdma qset failed.\n");
202}
203
204static void irdma_remove(struct auxiliary_device *aux_dev)
205{
206 struct iidc_auxiliary_dev *iidc_adev = container_of(aux_dev,
207 struct iidc_auxiliary_dev,
208 adev);
209 struct ice_pf *pf = iidc_adev->pf;
David E. Box27963d32021-12-21 15:58:49 -0800210 struct irdma_device *iwdev = auxiliary_get_drvdata(aux_dev);
Mustafa Ismail8498a302021-06-02 15:51:23 -0500211
212 irdma_ib_unregister_device(iwdev);
213 ice_rdma_update_vsi_filter(pf, iwdev->vsi_num, false);
214
215 pr_debug("INIT: Gen2 PF[%d] device remove success\n", PCI_FUNC(pf->pdev->devfn));
216}
217
Tatyana Nikolova0dc2d6f2021-07-08 14:35:21 -0700218static void irdma_fill_device_info(struct irdma_device *iwdev, struct ice_pf *pf,
219 struct ice_vsi *vsi)
Mustafa Ismail8498a302021-06-02 15:51:23 -0500220{
221 struct irdma_pci_f *rf = iwdev->rf;
Mustafa Ismail8498a302021-06-02 15:51:23 -0500222
223 rf->cdev = pf;
224 rf->gen_ops.register_qset = irdma_lan_register_qset;
225 rf->gen_ops.unregister_qset = irdma_lan_unregister_qset;
226 rf->hw.hw_addr = pf->hw.hw_addr;
227 rf->pcidev = pf->pdev;
228 rf->msix_count = pf->num_rdma_msix;
229 rf->msix_entries = &pf->msix_entries[pf->rdma_base_vector];
230 rf->default_vsi.vsi_idx = vsi->vsi_num;
Shiraz Saleem774a90c2021-10-18 18:16:03 -0500231 rf->protocol_used = pf->rdma_mode & IIDC_RDMA_PROTOCOL_ROCEV2 ?
232 IRDMA_ROCE_PROTOCOL_ONLY : IRDMA_IWARP_PROTOCOL_ONLY;
Mustafa Ismail8498a302021-06-02 15:51:23 -0500233 rf->rdma_ver = IRDMA_GEN_2;
234 rf->rsrc_profile = IRDMA_HMC_PROFILE_DEFAULT;
235 rf->rst_to = IRDMA_RST_TIMEOUT_HZ;
236 rf->gen_ops.request_reset = irdma_request_reset;
237 rf->limits_sel = 7;
238 rf->iwdev = iwdev;
239
240 iwdev->netdev = vsi->netdev;
241 iwdev->vsi_num = vsi->vsi_num;
242 iwdev->init_state = INITIAL_STATE;
243 iwdev->roce_cwnd = IRDMA_ROCE_CWND_DEFAULT;
244 iwdev->roce_ackcreds = IRDMA_ROCE_ACKCREDS_DEFAULT;
245 iwdev->rcv_wnd = IRDMA_CM_DEFAULT_RCV_WND_SCALED;
246 iwdev->rcv_wscale = IRDMA_CM_DEFAULT_RCV_WND_SCALE;
247 if (rf->protocol_used == IRDMA_ROCE_PROTOCOL_ONLY)
248 iwdev->roce_mode = true;
249}
250
251static int irdma_probe(struct auxiliary_device *aux_dev, const struct auxiliary_device_id *id)
252{
253 struct iidc_auxiliary_dev *iidc_adev = container_of(aux_dev,
254 struct iidc_auxiliary_dev,
255 adev);
256 struct ice_pf *pf = iidc_adev->pf;
Tatyana Nikolova0dc2d6f2021-07-08 14:35:21 -0700257 struct ice_vsi *vsi = ice_get_main_vsi(pf);
Mustafa Ismail8498a302021-06-02 15:51:23 -0500258 struct iidc_qos_params qos_info = {};
259 struct irdma_device *iwdev;
260 struct irdma_pci_f *rf;
261 struct irdma_l2params l2params = {};
262 int err;
263
Tatyana Nikolova0dc2d6f2021-07-08 14:35:21 -0700264 if (!vsi)
265 return -EIO;
Mustafa Ismail8498a302021-06-02 15:51:23 -0500266 iwdev = ib_alloc_device(irdma_device, ibdev);
267 if (!iwdev)
268 return -ENOMEM;
269 iwdev->rf = kzalloc(sizeof(*rf), GFP_KERNEL);
270 if (!iwdev->rf) {
271 ib_dealloc_device(&iwdev->ibdev);
272 return -ENOMEM;
273 }
274
Tatyana Nikolova0dc2d6f2021-07-08 14:35:21 -0700275 irdma_fill_device_info(iwdev, pf, vsi);
Mustafa Ismail8498a302021-06-02 15:51:23 -0500276 rf = iwdev->rf;
277
278 if (irdma_ctrl_init_hw(rf)) {
279 err = -EIO;
280 goto err_ctrl_init;
281 }
282
283 l2params.mtu = iwdev->netdev->mtu;
284 ice_get_qos_params(pf, &qos_info);
285 irdma_fill_qos_info(&l2params, &qos_info);
286 if (irdma_rt_init_hw(iwdev, &l2params)) {
287 err = -EIO;
288 goto err_rt_init;
289 }
290
291 err = irdma_ib_register_device(iwdev);
292 if (err)
293 goto err_ibreg;
294
295 ice_rdma_update_vsi_filter(pf, iwdev->vsi_num, true);
296
297 ibdev_dbg(&iwdev->ibdev, "INIT: Gen2 PF[%d] device probe success\n", PCI_FUNC(rf->pcidev->devfn));
David E. Box27963d32021-12-21 15:58:49 -0800298 auxiliary_set_drvdata(aux_dev, iwdev);
Mustafa Ismail8498a302021-06-02 15:51:23 -0500299
300 return 0;
301
302err_ibreg:
303 irdma_rt_deinit_hw(iwdev);
304err_rt_init:
305 irdma_ctrl_deinit_hw(rf);
306err_ctrl_init:
307 kfree(iwdev->rf);
308 ib_dealloc_device(&iwdev->ibdev);
309
310 return err;
311}
312
313static const struct auxiliary_device_id irdma_auxiliary_id_table[] = {
314 {.name = "ice.iwarp", },
315 {.name = "ice.roce", },
316 {},
317};
318
319MODULE_DEVICE_TABLE(auxiliary, irdma_auxiliary_id_table);
320
321static struct iidc_auxiliary_drv irdma_auxiliary_drv = {
322 .adrv = {
323 .id_table = irdma_auxiliary_id_table,
324 .probe = irdma_probe,
325 .remove = irdma_remove,
326 },
327 .event_handler = irdma_iidc_event_handler,
328};
329
330static int __init irdma_init_module(void)
331{
332 int ret;
333
334 ret = auxiliary_driver_register(&i40iw_auxiliary_drv);
335 if (ret) {
336 pr_err("Failed i40iw(gen_1) auxiliary_driver_register() ret=%d\n",
337 ret);
338 return ret;
339 }
340
341 ret = auxiliary_driver_register(&irdma_auxiliary_drv.adrv);
342 if (ret) {
343 auxiliary_driver_unregister(&i40iw_auxiliary_drv);
344 pr_err("Failed irdma auxiliary_driver_register() ret=%d\n",
345 ret);
346 return ret;
347 }
348
349 irdma_register_notifiers();
350
351 return 0;
352}
353
354static void __exit irdma_exit_module(void)
355{
356 irdma_unregister_notifiers();
357 auxiliary_driver_unregister(&irdma_auxiliary_drv.adrv);
358 auxiliary_driver_unregister(&i40iw_auxiliary_drv);
359}
360
361module_init(irdma_init_module);
362module_exit(irdma_exit_module);