|
| 1 | +// SPDX-License-Identifier: GPL-2.0 |
| 2 | +/* |
| 3 | + * Copyright (c) 2021 - 2022, Shanghai Yunsilicon Technology Co., Ltd. |
| 4 | + * All rights reserved. |
| 5 | + */ |
| 6 | + |
| 7 | +#include <config.h> |
| 8 | + |
| 9 | +#include <stdlib.h> |
| 10 | +#include <stdio.h> |
| 11 | +#include <stdatomic.h> |
| 12 | +#include <string.h> |
| 13 | +#include <pthread.h> |
| 14 | +#include <errno.h> |
| 15 | +#include <limits.h> |
| 16 | +#include <sys/types.h> |
| 17 | +#include <sys/stat.h> |
| 18 | +#include <fcntl.h> |
| 19 | +#include <unistd.h> |
| 20 | +#include <sys/mman.h> |
| 21 | +#include <ccan/array_size.h> |
| 22 | + |
| 23 | +#include <util/compiler.h> |
| 24 | +#include <util/mmio.h> |
| 25 | +#include <rdma/ib_user_ioctl_cmds.h> |
| 26 | +#include <infiniband/cmd_write.h> |
| 27 | + |
| 28 | +#include "xscale.h" |
| 29 | +#include "xsc-abi.h" |
| 30 | + |
| 31 | +int xsc_query_port(struct ibv_context *context, u8 port, |
| 32 | + struct ibv_port_attr *attr) |
| 33 | +{ |
| 34 | + struct ibv_query_port cmd; |
| 35 | + |
| 36 | + return ibv_cmd_query_port(context, port, attr, &cmd, sizeof(cmd)); |
| 37 | +} |
| 38 | + |
| 39 | +static void xsc_set_fw_version(struct ibv_device_attr *attr, |
| 40 | + union xsc_ib_fw_ver *fw_ver) |
| 41 | +{ |
| 42 | + u8 ver_major = fw_ver->s.ver_major; |
| 43 | + u8 ver_minor = fw_ver->s.ver_minor; |
| 44 | + u16 ver_patch = fw_ver->s.ver_patch; |
| 45 | + u32 ver_tweak = fw_ver->s.ver_tweak; |
| 46 | + |
| 47 | + if (ver_tweak == 0) { |
| 48 | + snprintf(attr->fw_ver, sizeof(attr->fw_ver), "v%u.%u.%u", |
| 49 | + ver_major, ver_minor, ver_patch); |
| 50 | + } else { |
| 51 | + snprintf(attr->fw_ver, sizeof(attr->fw_ver), "v%u.%u.%u+%u", |
| 52 | + ver_major, ver_minor, ver_patch, ver_tweak); |
| 53 | + } |
| 54 | +} |
| 55 | + |
| 56 | +int xsc_query_device_ex(struct ibv_context *context, |
| 57 | + const struct ibv_query_device_ex_input *input, |
| 58 | + struct ibv_device_attr_ex *attr, size_t attr_size) |
| 59 | +{ |
| 60 | + struct ib_uverbs_ex_query_device_resp resp; |
| 61 | + size_t resp_size = sizeof(resp); |
| 62 | + union xsc_ib_fw_ver raw_fw_ver; |
| 63 | + int err; |
| 64 | + |
| 65 | + raw_fw_ver.data = 0; |
| 66 | + err = ibv_cmd_query_device_any(context, input, attr, attr_size, |
| 67 | + &resp, &resp_size); |
| 68 | + if (err) |
| 69 | + return err; |
| 70 | + |
| 71 | + raw_fw_ver.data = resp.base.fw_ver; |
| 72 | + xsc_set_fw_version(&attr->orig_attr, &raw_fw_ver); |
| 73 | + |
| 74 | + return 0; |
| 75 | +} |
0 commit comments