|
2 | 2 | /* Copyright (c) 2020, Intel Corporation. */
|
3 | 3 |
|
4 | 4 | #include "ice.h"
|
| 5 | +#include "ice_lib.h" |
5 | 6 | #include "ice_devlink.h"
|
6 | 7 |
|
| 8 | +static int ice_info_get_dsn(struct ice_pf *pf, char *buf, size_t len) |
| 9 | +{ |
| 10 | + u8 dsn[8]; |
| 11 | + |
| 12 | + /* Copy the DSN into an array in Big Endian format */ |
| 13 | + put_unaligned_be64(pci_get_dsn(pf->pdev), dsn); |
| 14 | + |
| 15 | + snprintf(buf, len, "%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x", |
| 16 | + dsn[0], dsn[1], dsn[2], dsn[3], |
| 17 | + dsn[4], dsn[5], dsn[6], dsn[7]); |
| 18 | + |
| 19 | + return 0; |
| 20 | +} |
| 21 | + |
| 22 | +static int ice_info_fw_mgmt(struct ice_pf *pf, char *buf, size_t len) |
| 23 | +{ |
| 24 | + struct ice_hw *hw = &pf->hw; |
| 25 | + |
| 26 | + snprintf(buf, len, "%u.%u.%u", hw->fw_maj_ver, hw->fw_min_ver, |
| 27 | + hw->fw_patch); |
| 28 | + |
| 29 | + return 0; |
| 30 | +} |
| 31 | + |
| 32 | +static int ice_info_fw_api(struct ice_pf *pf, char *buf, size_t len) |
| 33 | +{ |
| 34 | + struct ice_hw *hw = &pf->hw; |
| 35 | + |
| 36 | + snprintf(buf, len, "%u.%u", hw->api_maj_ver, hw->api_min_ver); |
| 37 | + |
| 38 | + return 0; |
| 39 | +} |
| 40 | + |
| 41 | +static int ice_info_fw_build(struct ice_pf *pf, char *buf, size_t len) |
| 42 | +{ |
| 43 | + struct ice_hw *hw = &pf->hw; |
| 44 | + |
| 45 | + snprintf(buf, len, "0x%08x", hw->fw_build); |
| 46 | + |
| 47 | + return 0; |
| 48 | +} |
| 49 | + |
| 50 | +static int ice_info_orom_ver(struct ice_pf *pf, char *buf, size_t len) |
| 51 | +{ |
| 52 | + struct ice_orom_info *orom = &pf->hw.nvm.orom; |
| 53 | + |
| 54 | + snprintf(buf, len, "%u.%u.%u", orom->major, orom->build, orom->patch); |
| 55 | + |
| 56 | + return 0; |
| 57 | +} |
| 58 | + |
| 59 | +static int ice_info_nvm_ver(struct ice_pf *pf, char *buf, size_t len) |
| 60 | +{ |
| 61 | + struct ice_nvm_info *nvm = &pf->hw.nvm; |
| 62 | + |
| 63 | + snprintf(buf, len, "%x.%02x", nvm->major_ver, nvm->minor_ver); |
| 64 | + |
| 65 | + return 0; |
| 66 | +} |
| 67 | + |
| 68 | +static int ice_info_eetrack(struct ice_pf *pf, char *buf, size_t len) |
| 69 | +{ |
| 70 | + struct ice_nvm_info *nvm = &pf->hw.nvm; |
| 71 | + |
| 72 | + snprintf(buf, len, "0x%08x", nvm->eetrack); |
| 73 | + |
| 74 | + return 0; |
| 75 | +} |
| 76 | + |
| 77 | +static int ice_info_ddp_pkg_name(struct ice_pf *pf, char *buf, size_t len) |
| 78 | +{ |
| 79 | + struct ice_hw *hw = &pf->hw; |
| 80 | + |
| 81 | + snprintf(buf, len, "%s", hw->active_pkg_name); |
| 82 | + |
| 83 | + return 0; |
| 84 | +} |
| 85 | + |
| 86 | +static int ice_info_ddp_pkg_version(struct ice_pf *pf, char *buf, size_t len) |
| 87 | +{ |
| 88 | + struct ice_pkg_ver *pkg = &pf->hw.active_pkg_ver; |
| 89 | + |
| 90 | + snprintf(buf, len, "%u.%u.%u.%u", pkg->major, pkg->minor, pkg->update, |
| 91 | + pkg->draft); |
| 92 | + |
| 93 | + return 0; |
| 94 | +} |
| 95 | + |
| 96 | +#define running(key, getter) { ICE_VERSION_RUNNING, key, getter } |
| 97 | + |
| 98 | +enum ice_version_type { |
| 99 | + ICE_VERSION_FIXED, |
| 100 | + ICE_VERSION_RUNNING, |
| 101 | + ICE_VERSION_STORED, |
| 102 | +}; |
| 103 | + |
| 104 | +static const struct ice_devlink_version { |
| 105 | + enum ice_version_type type; |
| 106 | + const char *key; |
| 107 | + int (*getter)(struct ice_pf *pf, char *buf, size_t len); |
| 108 | +} ice_devlink_versions[] = { |
| 109 | + running(DEVLINK_INFO_VERSION_GENERIC_FW_MGMT, ice_info_fw_mgmt), |
| 110 | + running("fw.mgmt.api", ice_info_fw_api), |
| 111 | + running("fw.mgmt.build", ice_info_fw_build), |
| 112 | + running(DEVLINK_INFO_VERSION_GENERIC_FW_UNDI, ice_info_orom_ver), |
| 113 | + running("fw.psid.api", ice_info_nvm_ver), |
| 114 | + running(DEVLINK_INFO_VERSION_GENERIC_FW_BUNDLE_ID, ice_info_eetrack), |
| 115 | + running("fw.app.name", ice_info_ddp_pkg_name), |
| 116 | + running(DEVLINK_INFO_VERSION_GENERIC_FW_APP, ice_info_ddp_pkg_version), |
| 117 | +}; |
| 118 | + |
| 119 | +/** |
| 120 | + * ice_devlink_info_get - .info_get devlink handler |
| 121 | + * @devlink: devlink instance structure |
| 122 | + * @req: the devlink info request |
| 123 | + * @extack: extended netdev ack structure |
| 124 | + * |
| 125 | + * Callback for the devlink .info_get operation. Reports information about the |
| 126 | + * device. |
| 127 | + * |
| 128 | + * @returns zero on success or an error code on failure. |
| 129 | + */ |
| 130 | +static int ice_devlink_info_get(struct devlink *devlink, |
| 131 | + struct devlink_info_req *req, |
| 132 | + struct netlink_ext_ack *extack) |
| 133 | +{ |
| 134 | + struct ice_pf *pf = devlink_priv(devlink); |
| 135 | + char buf[100]; |
| 136 | + size_t i; |
| 137 | + int err; |
| 138 | + |
| 139 | + err = devlink_info_driver_name_put(req, KBUILD_MODNAME); |
| 140 | + if (err) { |
| 141 | + NL_SET_ERR_MSG_MOD(extack, "Unable to set driver name"); |
| 142 | + return err; |
| 143 | + } |
| 144 | + |
| 145 | + err = ice_info_get_dsn(pf, buf, sizeof(buf)); |
| 146 | + if (err) { |
| 147 | + NL_SET_ERR_MSG_MOD(extack, "Unable to obtain serial number"); |
| 148 | + return err; |
| 149 | + } |
| 150 | + |
| 151 | + err = devlink_info_serial_number_put(req, buf); |
| 152 | + if (err) { |
| 153 | + NL_SET_ERR_MSG_MOD(extack, "Unable to set serial number"); |
| 154 | + return err; |
| 155 | + } |
| 156 | + |
| 157 | + for (i = 0; i < ARRAY_SIZE(ice_devlink_versions); i++) { |
| 158 | + enum ice_version_type type = ice_devlink_versions[i].type; |
| 159 | + const char *key = ice_devlink_versions[i].key; |
| 160 | + |
| 161 | + err = ice_devlink_versions[i].getter(pf, buf, sizeof(buf)); |
| 162 | + if (err) { |
| 163 | + NL_SET_ERR_MSG_MOD(extack, "Unable to obtain version info"); |
| 164 | + return err; |
| 165 | + } |
| 166 | + |
| 167 | + switch (type) { |
| 168 | + case ICE_VERSION_FIXED: |
| 169 | + err = devlink_info_version_fixed_put(req, key, buf); |
| 170 | + if (err) { |
| 171 | + NL_SET_ERR_MSG_MOD(extack, "Unable to set fixed version"); |
| 172 | + return err; |
| 173 | + } |
| 174 | + break; |
| 175 | + case ICE_VERSION_RUNNING: |
| 176 | + err = devlink_info_version_running_put(req, key, buf); |
| 177 | + if (err) { |
| 178 | + NL_SET_ERR_MSG_MOD(extack, "Unable to set running version"); |
| 179 | + return err; |
| 180 | + } |
| 181 | + break; |
| 182 | + case ICE_VERSION_STORED: |
| 183 | + err = devlink_info_version_stored_put(req, key, buf); |
| 184 | + if (err) { |
| 185 | + NL_SET_ERR_MSG_MOD(extack, "Unable to set stored version"); |
| 186 | + return err; |
| 187 | + } |
| 188 | + break; |
| 189 | + } |
| 190 | + } |
| 191 | + |
| 192 | + return 0; |
| 193 | +} |
| 194 | + |
7 | 195 | static const struct devlink_ops ice_devlink_ops = {
|
| 196 | + .info_get = ice_devlink_info_get, |
8 | 197 | };
|
9 | 198 |
|
10 | 199 | static void ice_devlink_free(void *devlink_ptr)
|
|
0 commit comments