|
1 | 1 | // SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause |
2 | 2 | /* |
3 | | - * Copyright 2018-2019 Amazon.com, Inc. or its affiliates. All rights reserved. |
| 3 | + * Copyright 2018-2020 Amazon.com, Inc. or its affiliates. All rights reserved. |
4 | 4 | */ |
5 | 5 |
|
6 | 6 | #include <linux/module.h> |
7 | 7 | #include <linux/pci.h> |
| 8 | +#include <linux/utsname.h> |
| 9 | +#include <linux/version.h> |
8 | 10 |
|
9 | 11 | #include <rdma/ib_user_verbs.h> |
10 | 12 |
|
@@ -187,6 +189,52 @@ static void efa_stats_init(struct efa_dev *dev) |
187 | 189 | atomic64_set(s, 0); |
188 | 190 | } |
189 | 191 |
|
| 192 | +static void efa_set_host_info(struct efa_dev *dev) |
| 193 | +{ |
| 194 | + struct efa_admin_set_feature_resp resp = {}; |
| 195 | + struct efa_admin_set_feature_cmd cmd = {}; |
| 196 | + struct efa_admin_host_info *hinf; |
| 197 | + u32 bufsz = sizeof(*hinf); |
| 198 | + dma_addr_t hinf_dma; |
| 199 | + |
| 200 | + if (!efa_com_check_supported_feature_id(&dev->edev, |
| 201 | + EFA_ADMIN_HOST_INFO)) |
| 202 | + return; |
| 203 | + |
| 204 | + /* Failures in host info set shall not disturb probe */ |
| 205 | + hinf = dma_alloc_coherent(&dev->pdev->dev, bufsz, &hinf_dma, |
| 206 | + GFP_KERNEL); |
| 207 | + if (!hinf) |
| 208 | + return; |
| 209 | + |
| 210 | + strlcpy(hinf->os_dist_str, utsname()->release, |
| 211 | + min(sizeof(hinf->os_dist_str), sizeof(utsname()->release))); |
| 212 | + hinf->os_type = EFA_ADMIN_OS_LINUX; |
| 213 | + strlcpy(hinf->kernel_ver_str, utsname()->version, |
| 214 | + min(sizeof(hinf->kernel_ver_str), sizeof(utsname()->version))); |
| 215 | + hinf->kernel_ver = LINUX_VERSION_CODE; |
| 216 | + EFA_SET(&hinf->driver_ver, EFA_ADMIN_HOST_INFO_DRIVER_MAJOR, 0); |
| 217 | + EFA_SET(&hinf->driver_ver, EFA_ADMIN_HOST_INFO_DRIVER_MINOR, 0); |
| 218 | + EFA_SET(&hinf->driver_ver, EFA_ADMIN_HOST_INFO_DRIVER_SUB_MINOR, 0); |
| 219 | + EFA_SET(&hinf->driver_ver, EFA_ADMIN_HOST_INFO_DRIVER_MODULE_TYPE, 0); |
| 220 | + EFA_SET(&hinf->bdf, EFA_ADMIN_HOST_INFO_BUS, dev->pdev->bus->number); |
| 221 | + EFA_SET(&hinf->bdf, EFA_ADMIN_HOST_INFO_DEVICE, |
| 222 | + PCI_SLOT(dev->pdev->devfn)); |
| 223 | + EFA_SET(&hinf->bdf, EFA_ADMIN_HOST_INFO_FUNCTION, |
| 224 | + PCI_FUNC(dev->pdev->devfn)); |
| 225 | + EFA_SET(&hinf->spec_ver, EFA_ADMIN_HOST_INFO_SPEC_MAJOR, |
| 226 | + EFA_COMMON_SPEC_VERSION_MAJOR); |
| 227 | + EFA_SET(&hinf->spec_ver, EFA_ADMIN_HOST_INFO_SPEC_MINOR, |
| 228 | + EFA_COMMON_SPEC_VERSION_MINOR); |
| 229 | + EFA_SET(&hinf->flags, EFA_ADMIN_HOST_INFO_INTREE, 1); |
| 230 | + EFA_SET(&hinf->flags, EFA_ADMIN_HOST_INFO_GDR, 0); |
| 231 | + |
| 232 | + efa_com_set_feature_ex(&dev->edev, &resp, &cmd, EFA_ADMIN_HOST_INFO, |
| 233 | + hinf_dma, bufsz); |
| 234 | + |
| 235 | + dma_free_coherent(&dev->pdev->dev, bufsz, hinf, hinf_dma); |
| 236 | +} |
| 237 | + |
190 | 238 | static const struct ib_device_ops efa_dev_ops = { |
191 | 239 | .owner = THIS_MODULE, |
192 | 240 | .driver_id = RDMA_DRIVER_EFA, |
@@ -251,6 +299,8 @@ static int efa_ib_device_add(struct efa_dev *dev) |
251 | 299 | if (err) |
252 | 300 | goto err_release_doorbell_bar; |
253 | 301 |
|
| 302 | + efa_set_host_info(dev); |
| 303 | + |
254 | 304 | dev->ibdev.node_type = RDMA_NODE_UNSPECIFIED; |
255 | 305 | dev->ibdev.phys_port_cnt = 1; |
256 | 306 | dev->ibdev.num_comp_vectors = 1; |
|
0 commit comments