1 // 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 6 MODULE_ALIAS("i40iw"); 7 MODULE_AUTHOR("Intel Corporation, <e1000-rdma@lists.sourceforge.net>"); 8 MODULE_DESCRIPTION("Intel(R) Ethernet Protocol Driver for RDMA"); 9 MODULE_LICENSE("Dual BSD/GPL"); 10 11 static struct notifier_block irdma_inetaddr_notifier = { 12 .notifier_call = irdma_inetaddr_event 13 }; 14 15 static struct notifier_block irdma_inetaddr6_notifier = { 16 .notifier_call = irdma_inet6addr_event 17 }; 18 19 static struct notifier_block irdma_net_notifier = { 20 .notifier_call = irdma_net_event 21 }; 22 23 static struct notifier_block irdma_netdevice_notifier = { 24 .notifier_call = irdma_netdevice_event 25 }; 26 27 static 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 35 static 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 43 static 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 55 static 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 63 static 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 84 static 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 */ 147 static 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 */ 160 static 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 */ 188 static 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 204 static 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; 210 struct irdma_device *iwdev = dev_get_drvdata(&aux_dev->dev); 211 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 218 static void irdma_fill_device_info(struct irdma_device *iwdev, struct ice_pf *pf, 219 struct ice_vsi *vsi) 220 { 221 struct irdma_pci_f *rf = iwdev->rf; 222 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; 231 rf->protocol_used = IRDMA_ROCE_PROTOCOL_ONLY; 232 rf->rdma_ver = IRDMA_GEN_2; 233 rf->rsrc_profile = IRDMA_HMC_PROFILE_DEFAULT; 234 rf->rst_to = IRDMA_RST_TIMEOUT_HZ; 235 rf->gen_ops.request_reset = irdma_request_reset; 236 rf->limits_sel = 7; 237 rf->iwdev = iwdev; 238 239 iwdev->netdev = vsi->netdev; 240 iwdev->vsi_num = vsi->vsi_num; 241 iwdev->init_state = INITIAL_STATE; 242 iwdev->roce_cwnd = IRDMA_ROCE_CWND_DEFAULT; 243 iwdev->roce_ackcreds = IRDMA_ROCE_ACKCREDS_DEFAULT; 244 iwdev->rcv_wnd = IRDMA_CM_DEFAULT_RCV_WND_SCALED; 245 iwdev->rcv_wscale = IRDMA_CM_DEFAULT_RCV_WND_SCALE; 246 if (rf->protocol_used == IRDMA_ROCE_PROTOCOL_ONLY) 247 iwdev->roce_mode = true; 248 } 249 250 static int irdma_probe(struct auxiliary_device *aux_dev, const struct auxiliary_device_id *id) 251 { 252 struct iidc_auxiliary_dev *iidc_adev = container_of(aux_dev, 253 struct iidc_auxiliary_dev, 254 adev); 255 struct ice_pf *pf = iidc_adev->pf; 256 struct ice_vsi *vsi = ice_get_main_vsi(pf); 257 struct iidc_qos_params qos_info = {}; 258 struct irdma_device *iwdev; 259 struct irdma_pci_f *rf; 260 struct irdma_l2params l2params = {}; 261 int err; 262 263 if (!vsi) 264 return -EIO; 265 iwdev = ib_alloc_device(irdma_device, ibdev); 266 if (!iwdev) 267 return -ENOMEM; 268 iwdev->rf = kzalloc(sizeof(*rf), GFP_KERNEL); 269 if (!iwdev->rf) { 270 ib_dealloc_device(&iwdev->ibdev); 271 return -ENOMEM; 272 } 273 274 irdma_fill_device_info(iwdev, pf, vsi); 275 rf = iwdev->rf; 276 277 if (irdma_ctrl_init_hw(rf)) { 278 err = -EIO; 279 goto err_ctrl_init; 280 } 281 282 l2params.mtu = iwdev->netdev->mtu; 283 ice_get_qos_params(pf, &qos_info); 284 irdma_fill_qos_info(&l2params, &qos_info); 285 if (irdma_rt_init_hw(iwdev, &l2params)) { 286 err = -EIO; 287 goto err_rt_init; 288 } 289 290 err = irdma_ib_register_device(iwdev); 291 if (err) 292 goto err_ibreg; 293 294 ice_rdma_update_vsi_filter(pf, iwdev->vsi_num, true); 295 296 ibdev_dbg(&iwdev->ibdev, "INIT: Gen2 PF[%d] device probe success\n", PCI_FUNC(rf->pcidev->devfn)); 297 dev_set_drvdata(&aux_dev->dev, iwdev); 298 299 return 0; 300 301 err_ibreg: 302 irdma_rt_deinit_hw(iwdev); 303 err_rt_init: 304 irdma_ctrl_deinit_hw(rf); 305 err_ctrl_init: 306 kfree(iwdev->rf); 307 ib_dealloc_device(&iwdev->ibdev); 308 309 return err; 310 } 311 312 static const struct auxiliary_device_id irdma_auxiliary_id_table[] = { 313 {.name = "ice.iwarp", }, 314 {.name = "ice.roce", }, 315 {}, 316 }; 317 318 MODULE_DEVICE_TABLE(auxiliary, irdma_auxiliary_id_table); 319 320 static struct iidc_auxiliary_drv irdma_auxiliary_drv = { 321 .adrv = { 322 .id_table = irdma_auxiliary_id_table, 323 .probe = irdma_probe, 324 .remove = irdma_remove, 325 }, 326 .event_handler = irdma_iidc_event_handler, 327 }; 328 329 static int __init irdma_init_module(void) 330 { 331 int ret; 332 333 ret = auxiliary_driver_register(&i40iw_auxiliary_drv); 334 if (ret) { 335 pr_err("Failed i40iw(gen_1) auxiliary_driver_register() ret=%d\n", 336 ret); 337 return ret; 338 } 339 340 ret = auxiliary_driver_register(&irdma_auxiliary_drv.adrv); 341 if (ret) { 342 auxiliary_driver_unregister(&i40iw_auxiliary_drv); 343 pr_err("Failed irdma auxiliary_driver_register() ret=%d\n", 344 ret); 345 return ret; 346 } 347 348 irdma_register_notifiers(); 349 350 return 0; 351 } 352 353 static void __exit irdma_exit_module(void) 354 { 355 irdma_unregister_notifiers(); 356 auxiliary_driver_unregister(&irdma_auxiliary_drv.adrv); 357 auxiliary_driver_unregister(&i40iw_auxiliary_drv); 358 } 359 360 module_init(irdma_init_module); 361 module_exit(irdma_exit_module); 362