| 1 |
// SPDX-License-Identifier: GPL-2.0 or Linux-OpenIB |
| 2 |
/* Copyright (c) 2023 - 2024 Intel Corporation */ |
| 3 |
|
| 4 |
#include "main.h" |
| 5 |
#include <linux/net/intel/iidc_rdma_idpf.h> |
| 6 |
#include "ig3rdma_hw.h" |
| 7 |
|
| 8 |
static void ig3rdma_idc_core_event_handler(struct iidc_rdma_core_dev_info *cdev_info, |
| 9 |
struct iidc_rdma_event *event) |
| 10 |
{ |
| 11 |
struct irdma_pci_f *rf = auxiliary_get_drvdata(cdev_info->adev); |
| 12 |
|
| 13 |
if (*event->type & BIT(IIDC_RDMA_EVENT_WARN_RESET)) { |
| 14 |
rf->reset = true; |
| 15 |
rf->sc_dev.vchnl_up = false; |
| 16 |
} |
| 17 |
} |
| 18 |
|
| 19 |
int ig3rdma_vchnl_send_sync(struct irdma_sc_dev *dev, u8 *msg, u16 len, |
| 20 |
u8 *recv_msg, u16 *recv_len) |
| 21 |
{ |
| 22 |
struct iidc_rdma_core_dev_info *cdev_info = dev_to_rf(dev)->cdev; |
| 23 |
int ret; |
| 24 |
|
| 25 |
ret = idpf_idc_rdma_vc_send_sync(cdev_info, msg, len, recv_msg, |
| 26 |
recv_len); |
| 27 |
if (ret == -ETIMEDOUT) { |
| 28 |
ibdev_err(&(dev_to_rf(dev)->iwdev->ibdev), |
| 29 |
"Virtual channel Req <-> Resp completion timeout\n"); |
| 30 |
dev->vchnl_up = false; |
| 31 |
} |
| 32 |
|
| 33 |
return ret; |
| 34 |
} |
| 35 |
|
| 36 |
static int ig3rdma_vchnl_init(struct irdma_pci_f *rf, |
| 37 |
struct iidc_rdma_core_dev_info *cdev_info, |
| 38 |
u8 *rdma_ver) |
| 39 |
{ |
| 40 |
struct iidc_rdma_priv_dev_info *idc_priv = cdev_info->iidc_priv; |
| 41 |
struct irdma_vchnl_init_info virt_info; |
| 42 |
u8 gen = rf->rdma_ver; |
| 43 |
int ret; |
| 44 |
|
| 45 |
rf->vchnl_wq = alloc_ordered_workqueue("irdma-virtchnl-wq", 0); |
| 46 |
if (!rf->vchnl_wq) |
| 47 |
return -ENOMEM; |
| 48 |
|
| 49 |
mutex_init(&rf->sc_dev.vchnl_mutex); |
| 50 |
|
| 51 |
virt_info.is_pf = !idc_priv->ftype; |
| 52 |
virt_info.hw_rev = gen; |
| 53 |
virt_info.privileged = gen == IRDMA_GEN_2; |
| 54 |
virt_info.vchnl_wq = rf->vchnl_wq; |
| 55 |
ret = irdma_sc_vchnl_init(&rf->sc_dev, &virt_info); |
| 56 |
if (ret) { |
| 57 |
destroy_workqueue(rf->vchnl_wq); |
| 58 |
mutex_destroy(&rf->sc_dev.vchnl_mutex); |
| 59 |
return ret; |
| 60 |
} |
| 61 |
|
| 62 |
*rdma_ver = rf->sc_dev.hw_attrs.uk_attrs.hw_rev; |
| 63 |
|
| 64 |
return 0; |
| 65 |
} |
| 66 |
|
| 67 |
/** |
| 68 |
* ig3rdma_request_reset - Request a reset |
| 69 |
* @rf: RDMA PCI function |
| 70 |
*/ |
| 71 |
static void ig3rdma_request_reset(struct irdma_pci_f *rf) |
| 72 |
{ |
| 73 |
ibdev_warn(&rf->iwdev->ibdev, "Requesting a reset\n"); |
| 74 |
idpf_idc_request_reset(rf->cdev, IIDC_FUNC_RESET); |
| 75 |
} |
| 76 |
|
| 77 |
static int ig3rdma_cfg_regions(struct irdma_hw *hw, |
| 78 |
struct iidc_rdma_core_dev_info *cdev_info) |
| 79 |
{ |
| 80 |
struct iidc_rdma_priv_dev_info *idc_priv = cdev_info->iidc_priv; |
| 81 |
struct pci_dev *pdev = cdev_info->pdev; |
| 82 |
int i; |
| 83 |
|
| 84 |
switch (idc_priv->ftype) { |
| 85 |
case IIDC_FUNCTION_TYPE_PF: |
| 86 |
hw->rdma_reg.len = IG3_PF_RDMA_REGION_LEN; |
| 87 |
hw->rdma_reg.offset = IG3_PF_RDMA_REGION_OFFSET; |
| 88 |
break; |
| 89 |
case IIDC_FUNCTION_TYPE_VF: |
| 90 |
hw->rdma_reg.len = IG3_VF_RDMA_REGION_LEN; |
| 91 |
hw->rdma_reg.offset = IG3_VF_RDMA_REGION_OFFSET; |
| 92 |
break; |
| 93 |
default: |
| 94 |
return -ENODEV; |
| 95 |
} |
| 96 |
|
| 97 |
hw->rdma_reg.addr = ioremap(pci_resource_start(pdev, 0) + hw->rdma_reg.offset, |
| 98 |
hw->rdma_reg.len); |
| 99 |
|
| 100 |
if (!hw->rdma_reg.addr) |
| 101 |
return -ENOMEM; |
| 102 |
|
| 103 |
hw->num_io_regions = le16_to_cpu(idc_priv->num_memory_regions); |
| 104 |
hw->io_regs = kzalloc_objs(struct irdma_mmio_region, hw->num_io_regions); |
| 105 |
|
| 106 |
if (!hw->io_regs) { |
| 107 |
iounmap(hw->rdma_reg.addr); |
| 108 |
return -ENOMEM; |
| 109 |
} |
| 110 |
|
| 111 |
for (i = 0; i < hw->num_io_regions; i++) { |
| 112 |
hw->io_regs[i].addr = |
| 113 |
idc_priv->mapped_mem_regions[i].region_addr; |
| 114 |
hw->io_regs[i].len = |
| 115 |
le64_to_cpu(idc_priv->mapped_mem_regions[i].size); |
| 116 |
hw->io_regs[i].offset = |
| 117 |
le64_to_cpu(idc_priv->mapped_mem_regions[i].start_offset); |
| 118 |
} |
| 119 |
|
| 120 |
return 0; |
| 121 |
} |
| 122 |
|
| 123 |
static void ig3rdma_decfg_rf(struct irdma_pci_f *rf) |
| 124 |
{ |
| 125 |
struct irdma_hw *hw = &rf->hw; |
| 126 |
|
| 127 |
mutex_destroy(&rf->ah_tbl_lock); |
| 128 |
destroy_workqueue(rf->vchnl_wq); |
| 129 |
mutex_destroy(&rf->sc_dev.vchnl_mutex); |
| 130 |
kfree(hw->io_regs); |
| 131 |
iounmap(hw->rdma_reg.addr); |
| 132 |
} |
| 133 |
|
| 134 |
static int ig3rdma_cfg_rf(struct irdma_pci_f *rf, |
| 135 |
struct iidc_rdma_core_dev_info *cdev_info) |
| 136 |
{ |
| 137 |
struct iidc_rdma_priv_dev_info *idc_priv = cdev_info->iidc_priv; |
| 138 |
int err; |
| 139 |
|
| 140 |
rf->sc_dev.hw = &rf->hw; |
| 141 |
rf->cdev = cdev_info; |
| 142 |
rf->pcidev = cdev_info->pdev; |
| 143 |
rf->hw.device = &rf->pcidev->dev; |
| 144 |
rf->msix_count = idc_priv->msix_count; |
| 145 |
rf->msix_entries = idc_priv->msix_entries; |
| 146 |
|
| 147 |
err = ig3rdma_vchnl_init(rf, cdev_info, &rf->rdma_ver); |
| 148 |
if (err) |
| 149 |
return err; |
| 150 |
|
| 151 |
err = ig3rdma_cfg_regions(&rf->hw, cdev_info); |
| 152 |
if (err) { |
| 153 |
destroy_workqueue(rf->vchnl_wq); |
| 154 |
mutex_destroy(&rf->sc_dev.vchnl_mutex); |
| 155 |
return err; |
| 156 |
} |
| 157 |
|
| 158 |
rf->protocol_used = IRDMA_ROCE_PROTOCOL_ONLY; |
| 159 |
rf->rsrc_profile = IRDMA_HMC_PROFILE_DEFAULT; |
| 160 |
rf->rst_to = IRDMA_RST_TIMEOUT_HZ; |
| 161 |
rf->gen_ops.request_reset = ig3rdma_request_reset; |
| 162 |
rf->limits_sel = 7; |
| 163 |
mutex_init(&rf->ah_tbl_lock); |
| 164 |
|
| 165 |
return 0; |
| 166 |
} |
| 167 |
|
| 168 |
static int ig3rdma_core_probe(struct auxiliary_device *aux_dev, |
| 169 |
const struct auxiliary_device_id *id) |
| 170 |
{ |
| 171 |
struct iidc_rdma_core_auxiliary_dev *idc_adev = |
| 172 |
container_of(aux_dev, struct iidc_rdma_core_auxiliary_dev, adev); |
| 173 |
struct iidc_rdma_core_dev_info *cdev_info = idc_adev->cdev_info; |
| 174 |
struct irdma_pci_f *rf; |
| 175 |
int err; |
| 176 |
|
| 177 |
rf = kzalloc_obj(*rf); |
| 178 |
if (!rf) |
| 179 |
return -ENOMEM; |
| 180 |
|
| 181 |
err = ig3rdma_cfg_rf(rf, cdev_info); |
| 182 |
if (err) |
| 183 |
goto err_cfg_rf; |
| 184 |
|
| 185 |
err = irdma_ctrl_init_hw(rf); |
| 186 |
if (err) |
| 187 |
goto err_ctrl_init; |
| 188 |
|
| 189 |
auxiliary_set_drvdata(aux_dev, rf); |
| 190 |
|
| 191 |
err = idpf_idc_vport_dev_ctrl(cdev_info, true); |
| 192 |
if (err) |
| 193 |
goto err_vport_ctrl; |
| 194 |
|
| 195 |
return 0; |
| 196 |
|
| 197 |
err_vport_ctrl: |
| 198 |
irdma_ctrl_deinit_hw(rf); |
| 199 |
err_ctrl_init: |
| 200 |
ig3rdma_decfg_rf(rf); |
| 201 |
err_cfg_rf: |
| 202 |
kfree(rf); |
| 203 |
|
| 204 |
return err; |
| 205 |
} |
| 206 |
|
| 207 |
static void ig3rdma_core_remove(struct auxiliary_device *aux_dev) |
| 208 |
{ |
| 209 |
struct iidc_rdma_core_auxiliary_dev *idc_adev = |
| 210 |
container_of(aux_dev, struct iidc_rdma_core_auxiliary_dev, adev); |
| 211 |
struct iidc_rdma_core_dev_info *cdev_info = idc_adev->cdev_info; |
| 212 |
struct irdma_pci_f *rf = auxiliary_get_drvdata(aux_dev); |
| 213 |
|
| 214 |
idpf_idc_vport_dev_ctrl(cdev_info, false); |
| 215 |
irdma_ctrl_deinit_hw(rf); |
| 216 |
ig3rdma_decfg_rf(rf); |
| 217 |
kfree(rf); |
| 218 |
} |
| 219 |
|
| 220 |
static const struct auxiliary_device_id ig3rdma_core_auxiliary_id_table[] = { |
| 221 |
{.name = "idpf.8086.rdma.core", }, |
| 222 |
{}, |
| 223 |
}; |
| 224 |
|
| 225 |
MODULE_DEVICE_TABLE(auxiliary, ig3rdma_core_auxiliary_id_table); |
| 226 |
|
| 227 |
struct iidc_rdma_core_auxiliary_drv ig3rdma_core_auxiliary_drv = { |
| 228 |
.adrv = { |
| 229 |
.name = "core", |
| 230 |
.id_table = ig3rdma_core_auxiliary_id_table, |
| 231 |
.probe = ig3rdma_core_probe, |
| 232 |
.remove = ig3rdma_core_remove, |
| 233 |
}, |
| 234 |
.event_handler = ig3rdma_idc_core_event_handler, |
| 235 |
}; |