Tomas Winkler | 9fff042 | 2019-03-12 00:10:41 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Samuel Ortiz | 59fcd7c | 2013-04-11 03:03:29 +0200 | [diff] [blame] | 2 | /* |
Tomas Winkler | 1e55b60 | 2019-03-12 00:10:44 +0200 | [diff] [blame] | 3 | * Copyright (c) 2013-2019, Intel Corporation. All rights reserved. |
Samuel Ortiz | 59fcd7c | 2013-04-11 03:03:29 +0200 | [diff] [blame] | 4 | * Intel Management Engine Interface (Intel MEI) Linux driver |
Samuel Ortiz | 59fcd7c | 2013-04-11 03:03:29 +0200 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <linux/kernel.h> |
Samuel Ortiz | 36eda94 | 2013-04-11 03:03:31 +0200 | [diff] [blame] | 8 | #include <linux/sched.h> |
Samuel Ortiz | 59fcd7c | 2013-04-11 03:03:29 +0200 | [diff] [blame] | 9 | #include <linux/module.h> |
Samuel Ortiz | 59fcd7c | 2013-04-11 03:03:29 +0200 | [diff] [blame] | 10 | #include <linux/device.h> |
Tomas Winkler | 1f18035 | 2014-09-29 16:31:46 +0300 | [diff] [blame] | 11 | #include <linux/slab.h> |
Tomas Winkler | 71ce789 | 2015-07-23 15:08:43 +0300 | [diff] [blame] | 12 | #include <linux/uuid.h> |
Tomas Winkler | 1f18035 | 2014-09-29 16:31:46 +0300 | [diff] [blame] | 13 | |
Samuel Ortiz | 59fcd7c | 2013-04-11 03:03:29 +0200 | [diff] [blame] | 14 | #include <linux/mei_cl_bus.h> |
| 15 | |
| 16 | #include "mei_dev.h" |
| 17 | #include "client.h" |
| 18 | |
Tomas Winkler | 5b6dca2 | 2015-07-23 15:08:44 +0300 | [diff] [blame] | 19 | #define MEI_UUID_NFC_INFO UUID_LE(0xd2de1625, 0x382d, 0x417d, \ |
| 20 | 0x48, 0xa4, 0xef, 0xab, 0xba, 0x8a, 0x12, 0x06) |
| 21 | |
Tomas Winkler | 6009595 | 2015-07-23 15:08:47 +0300 | [diff] [blame] | 22 | static const uuid_le mei_nfc_info_guid = MEI_UUID_NFC_INFO; |
| 23 | |
| 24 | #define MEI_UUID_NFC_HCI UUID_LE(0x0bb17a78, 0x2a8e, 0x4c50, \ |
| 25 | 0x94, 0xd4, 0x50, 0x26, 0x67, 0x23, 0x77, 0x5c) |
| 26 | |
Tomas Winkler | e97cdb3 | 2016-01-08 00:49:24 +0200 | [diff] [blame] | 27 | #define MEI_UUID_WD UUID_LE(0x05B79A6F, 0x4628, 0x4D7F, \ |
| 28 | 0x89, 0x9D, 0xA9, 0x15, 0x14, 0xCB, 0x32, 0xAB) |
| 29 | |
Alexander Usyskin | 7279b23 | 2016-11-10 18:38:57 +0200 | [diff] [blame] | 30 | #define MEI_UUID_MKHIF_FIX UUID_LE(0x55213584, 0x9a29, 0x4916, \ |
| 31 | 0xba, 0xdf, 0xf, 0xb7, 0xed, 0x68, 0x2a, 0xeb) |
| 32 | |
Tomas Winkler | d1e204e | 2019-02-21 23:41:55 +0530 | [diff] [blame] | 33 | #define MEI_UUID_HDCP UUID_LE(0xB638AB7E, 0x94E2, 0x4EA2, \ |
| 34 | 0xA5, 0x52, 0xD1, 0xC5, 0x4B, 0x62, 0x7F, 0x04) |
| 35 | |
Tomas Winkler | 71ce789 | 2015-07-23 15:08:43 +0300 | [diff] [blame] | 36 | #define MEI_UUID_ANY NULL_UUID_LE |
| 37 | |
Tomas Winkler | 5b6dca2 | 2015-07-23 15:08:44 +0300 | [diff] [blame] | 38 | /** |
Tomas Winkler | dd070a1 | 2015-07-23 15:08:45 +0300 | [diff] [blame] | 39 | * number_of_connections - determine whether an client be on the bus |
| 40 | * according number of connections |
| 41 | * We support only clients: |
| 42 | * 1. with single connection |
| 43 | * 2. and fixed clients (max_number_of_connections == 0) |
| 44 | * |
| 45 | * @cldev: me clients device |
| 46 | */ |
| 47 | static void number_of_connections(struct mei_cl_device *cldev) |
| 48 | { |
Tomas Winkler | 2bcfdc2 | 2016-01-07 14:46:34 +0200 | [diff] [blame] | 49 | dev_dbg(&cldev->dev, "running hook %s\n", __func__); |
Tomas Winkler | dd070a1 | 2015-07-23 15:08:45 +0300 | [diff] [blame] | 50 | |
| 51 | if (cldev->me_cl->props.max_number_of_connections > 1) |
| 52 | cldev->do_match = 0; |
| 53 | } |
| 54 | |
| 55 | /** |
Tomas Winkler | 5b6dca2 | 2015-07-23 15:08:44 +0300 | [diff] [blame] | 56 | * blacklist - blacklist a client from the bus |
| 57 | * |
| 58 | * @cldev: me clients device |
| 59 | */ |
| 60 | static void blacklist(struct mei_cl_device *cldev) |
| 61 | { |
Tomas Winkler | 2bcfdc2 | 2016-01-07 14:46:34 +0200 | [diff] [blame] | 62 | dev_dbg(&cldev->dev, "running hook %s\n", __func__); |
| 63 | |
Tomas Winkler | 5b6dca2 | 2015-07-23 15:08:44 +0300 | [diff] [blame] | 64 | cldev->do_match = 0; |
| 65 | } |
| 66 | |
Tomas Winkler | d1e204e | 2019-02-21 23:41:55 +0530 | [diff] [blame] | 67 | /** |
| 68 | * whitelist - forcefully whitelist client |
| 69 | * |
| 70 | * @cldev: me clients device |
| 71 | */ |
| 72 | static void whitelist(struct mei_cl_device *cldev) |
| 73 | { |
| 74 | dev_dbg(&cldev->dev, "running hook %s\n", __func__); |
| 75 | |
| 76 | cldev->do_match = 1; |
| 77 | } |
| 78 | |
Alexander Usyskin | 7279b23 | 2016-11-10 18:38:57 +0200 | [diff] [blame] | 79 | #define OSTYPE_LINUX 2 |
| 80 | struct mei_os_ver { |
| 81 | __le16 build; |
| 82 | __le16 reserved1; |
| 83 | u8 os_type; |
| 84 | u8 major; |
| 85 | u8 minor; |
| 86 | u8 reserved2; |
| 87 | } __packed; |
| 88 | |
| 89 | #define MKHI_FEATURE_PTT 0x10 |
| 90 | |
| 91 | struct mkhi_rule_id { |
| 92 | __le16 rule_type; |
| 93 | u8 feature_id; |
| 94 | u8 reserved; |
| 95 | } __packed; |
| 96 | |
| 97 | struct mkhi_fwcaps { |
| 98 | struct mkhi_rule_id id; |
| 99 | u8 len; |
| 100 | u8 data[0]; |
| 101 | } __packed; |
| 102 | |
Alexander Usyskin | 3cfaeb3 | 2018-06-25 00:11:41 +0300 | [diff] [blame] | 103 | struct mkhi_fw_ver_block { |
| 104 | u16 minor; |
| 105 | u8 major; |
| 106 | u8 platform; |
| 107 | u16 buildno; |
| 108 | u16 hotfix; |
| 109 | } __packed; |
| 110 | |
| 111 | struct mkhi_fw_ver { |
| 112 | struct mkhi_fw_ver_block ver[MEI_MAX_FW_VER_BLOCKS]; |
| 113 | } __packed; |
| 114 | |
Alexander Usyskin | 7279b23 | 2016-11-10 18:38:57 +0200 | [diff] [blame] | 115 | #define MKHI_FWCAPS_GROUP_ID 0x3 |
| 116 | #define MKHI_FWCAPS_SET_OS_VER_APP_RULE_CMD 6 |
Alexander Usyskin | 3cfaeb3 | 2018-06-25 00:11:41 +0300 | [diff] [blame] | 117 | #define MKHI_GEN_GROUP_ID 0xFF |
| 118 | #define MKHI_GEN_GET_FW_VERSION_CMD 0x2 |
Alexander Usyskin | 7279b23 | 2016-11-10 18:38:57 +0200 | [diff] [blame] | 119 | struct mkhi_msg_hdr { |
| 120 | u8 group_id; |
| 121 | u8 command; |
| 122 | u8 reserved; |
| 123 | u8 result; |
| 124 | } __packed; |
| 125 | |
| 126 | struct mkhi_msg { |
| 127 | struct mkhi_msg_hdr hdr; |
| 128 | u8 data[0]; |
| 129 | } __packed; |
| 130 | |
Tomas Winkler | dd04eecc | 2017-03-20 15:04:05 +0200 | [diff] [blame] | 131 | #define MKHI_OSVER_BUF_LEN (sizeof(struct mkhi_msg_hdr) + \ |
| 132 | sizeof(struct mkhi_fwcaps) + \ |
| 133 | sizeof(struct mei_os_ver)) |
Alexander Usyskin | 7279b23 | 2016-11-10 18:38:57 +0200 | [diff] [blame] | 134 | static int mei_osver(struct mei_cl_device *cldev) |
| 135 | { |
Tomas Winkler | dd04eecc | 2017-03-20 15:04:05 +0200 | [diff] [blame] | 136 | const size_t size = MKHI_OSVER_BUF_LEN; |
| 137 | char buf[MKHI_OSVER_BUF_LEN]; |
Alexander Usyskin | 7279b23 | 2016-11-10 18:38:57 +0200 | [diff] [blame] | 138 | struct mkhi_msg *req; |
| 139 | struct mkhi_fwcaps *fwcaps; |
| 140 | struct mei_os_ver *os_ver; |
| 141 | unsigned int mode = MEI_CL_IO_TX_BLOCKING | MEI_CL_IO_TX_INTERNAL; |
| 142 | |
| 143 | memset(buf, 0, size); |
| 144 | |
| 145 | req = (struct mkhi_msg *)buf; |
| 146 | req->hdr.group_id = MKHI_FWCAPS_GROUP_ID; |
| 147 | req->hdr.command = MKHI_FWCAPS_SET_OS_VER_APP_RULE_CMD; |
| 148 | |
| 149 | fwcaps = (struct mkhi_fwcaps *)req->data; |
| 150 | |
| 151 | fwcaps->id.rule_type = 0x0; |
| 152 | fwcaps->id.feature_id = MKHI_FEATURE_PTT; |
| 153 | fwcaps->len = sizeof(*os_ver); |
| 154 | os_ver = (struct mei_os_ver *)fwcaps->data; |
| 155 | os_ver->os_type = OSTYPE_LINUX; |
| 156 | |
Alexander Usyskin | c6240ca | 2017-03-05 21:40:42 +0200 | [diff] [blame] | 157 | return __mei_cl_send(cldev->cl, buf, size, mode); |
Alexander Usyskin | 7279b23 | 2016-11-10 18:38:57 +0200 | [diff] [blame] | 158 | } |
| 159 | |
Alexander Usyskin | 3cfaeb3 | 2018-06-25 00:11:41 +0300 | [diff] [blame] | 160 | #define MKHI_FWVER_BUF_LEN (sizeof(struct mkhi_msg_hdr) + \ |
| 161 | sizeof(struct mkhi_fw_ver)) |
| 162 | #define MKHI_FWVER_LEN(__num) (sizeof(struct mkhi_msg_hdr) + \ |
| 163 | sizeof(struct mkhi_fw_ver_block) * (__num)) |
| 164 | #define MKHI_RCV_TIMEOUT 500 /* receive timeout in msec */ |
| 165 | static int mei_fwver(struct mei_cl_device *cldev) |
| 166 | { |
| 167 | char buf[MKHI_FWVER_BUF_LEN]; |
| 168 | struct mkhi_msg *req; |
| 169 | struct mkhi_fw_ver *fwver; |
| 170 | int bytes_recv, ret, i; |
| 171 | |
| 172 | memset(buf, 0, sizeof(buf)); |
| 173 | |
| 174 | req = (struct mkhi_msg *)buf; |
| 175 | req->hdr.group_id = MKHI_GEN_GROUP_ID; |
| 176 | req->hdr.command = MKHI_GEN_GET_FW_VERSION_CMD; |
| 177 | |
| 178 | ret = __mei_cl_send(cldev->cl, buf, sizeof(struct mkhi_msg_hdr), |
| 179 | MEI_CL_IO_TX_BLOCKING); |
| 180 | if (ret < 0) { |
| 181 | dev_err(&cldev->dev, "Could not send ReqFWVersion cmd\n"); |
| 182 | return ret; |
| 183 | } |
| 184 | |
| 185 | ret = 0; |
| 186 | bytes_recv = __mei_cl_recv(cldev->cl, buf, sizeof(buf), 0, |
| 187 | MKHI_RCV_TIMEOUT); |
Tomas Winkler | 7f3838f | 2018-07-15 14:41:18 +0300 | [diff] [blame] | 188 | if (bytes_recv < 0 || (size_t)bytes_recv < MKHI_FWVER_LEN(1)) { |
Alexander Usyskin | 3cfaeb3 | 2018-06-25 00:11:41 +0300 | [diff] [blame] | 189 | /* |
| 190 | * Should be at least one version block, |
| 191 | * error out if nothing found |
| 192 | */ |
| 193 | dev_err(&cldev->dev, "Could not read FW version\n"); |
| 194 | return -EIO; |
| 195 | } |
| 196 | |
| 197 | fwver = (struct mkhi_fw_ver *)req->data; |
| 198 | memset(cldev->bus->fw_ver, 0, sizeof(cldev->bus->fw_ver)); |
| 199 | for (i = 0; i < MEI_MAX_FW_VER_BLOCKS; i++) { |
Tomas Winkler | 7f3838f | 2018-07-15 14:41:18 +0300 | [diff] [blame] | 200 | if ((size_t)bytes_recv < MKHI_FWVER_LEN(i + 1)) |
Alexander Usyskin | 3cfaeb3 | 2018-06-25 00:11:41 +0300 | [diff] [blame] | 201 | break; |
| 202 | dev_dbg(&cldev->dev, "FW version%d %d:%d.%d.%d.%d\n", |
| 203 | i, fwver->ver[i].platform, |
| 204 | fwver->ver[i].major, fwver->ver[i].minor, |
| 205 | fwver->ver[i].hotfix, fwver->ver[i].buildno); |
| 206 | |
| 207 | cldev->bus->fw_ver[i].platform = fwver->ver[i].platform; |
| 208 | cldev->bus->fw_ver[i].major = fwver->ver[i].major; |
| 209 | cldev->bus->fw_ver[i].minor = fwver->ver[i].minor; |
| 210 | cldev->bus->fw_ver[i].hotfix = fwver->ver[i].hotfix; |
| 211 | cldev->bus->fw_ver[i].buildno = fwver->ver[i].buildno; |
| 212 | } |
| 213 | |
| 214 | return ret; |
| 215 | } |
| 216 | |
Alexander Usyskin | 7279b23 | 2016-11-10 18:38:57 +0200 | [diff] [blame] | 217 | static void mei_mkhi_fix(struct mei_cl_device *cldev) |
| 218 | { |
| 219 | int ret; |
| 220 | |
Alexander Usyskin | f8204f0 | 2019-10-04 21:17:22 +0300 | [diff] [blame] | 221 | /* No need to enable the client if nothing is needed from it */ |
| 222 | if (!cldev->bus->fw_f_fw_ver_supported && |
| 223 | !cldev->bus->hbm_f_os_supported) |
| 224 | return; |
| 225 | |
Alexander Usyskin | 7279b23 | 2016-11-10 18:38:57 +0200 | [diff] [blame] | 226 | ret = mei_cldev_enable(cldev); |
| 227 | if (ret) |
| 228 | return; |
| 229 | |
Alexander Usyskin | f8204f0 | 2019-10-04 21:17:22 +0300 | [diff] [blame] | 230 | if (cldev->bus->fw_f_fw_ver_supported) { |
| 231 | ret = mei_fwver(cldev); |
| 232 | if (ret < 0) |
| 233 | dev_err(&cldev->dev, "FW version command failed %d\n", |
| 234 | ret); |
| 235 | } |
Alexander Usyskin | 7279b23 | 2016-11-10 18:38:57 +0200 | [diff] [blame] | 236 | |
Alexander Usyskin | 3cfaeb3 | 2018-06-25 00:11:41 +0300 | [diff] [blame] | 237 | if (cldev->bus->hbm_f_os_supported) { |
| 238 | ret = mei_osver(cldev); |
| 239 | if (ret < 0) |
| 240 | dev_err(&cldev->dev, "OS version command failed %d\n", |
| 241 | ret); |
| 242 | } |
Alexander Usyskin | 7279b23 | 2016-11-10 18:38:57 +0200 | [diff] [blame] | 243 | mei_cldev_disable(cldev); |
| 244 | } |
| 245 | |
Tomas Winkler | e97cdb3 | 2016-01-08 00:49:24 +0200 | [diff] [blame] | 246 | /** |
| 247 | * mei_wd - wd client on the bus, change protocol version |
| 248 | * as the API has changed. |
| 249 | * |
| 250 | * @cldev: me clients device |
| 251 | */ |
| 252 | #if IS_ENABLED(CONFIG_INTEL_MEI_ME) |
| 253 | #include <linux/pci.h> |
| 254 | #include "hw-me-regs.h" |
| 255 | static void mei_wd(struct mei_cl_device *cldev) |
| 256 | { |
| 257 | struct pci_dev *pdev = to_pci_dev(cldev->dev.parent); |
| 258 | |
| 259 | dev_dbg(&cldev->dev, "running hook %s\n", __func__); |
| 260 | if (pdev->device == MEI_DEV_ID_WPT_LP || |
| 261 | pdev->device == MEI_DEV_ID_SPT || |
| 262 | pdev->device == MEI_DEV_ID_SPT_H) |
| 263 | cldev->me_cl->props.protocol_version = 0x2; |
| 264 | |
| 265 | cldev->do_match = 1; |
| 266 | } |
| 267 | #else |
| 268 | static inline void mei_wd(struct mei_cl_device *cldev) {} |
| 269 | #endif /* CONFIG_INTEL_MEI_ME */ |
| 270 | |
Samuel Ortiz | 59fcd7c | 2013-04-11 03:03:29 +0200 | [diff] [blame] | 271 | struct mei_nfc_cmd { |
| 272 | u8 command; |
| 273 | u8 status; |
| 274 | u16 req_id; |
| 275 | u32 reserved; |
| 276 | u16 data_size; |
| 277 | u8 sub_command; |
| 278 | u8 data[]; |
| 279 | } __packed; |
| 280 | |
| 281 | struct mei_nfc_reply { |
| 282 | u8 command; |
| 283 | u8 status; |
| 284 | u16 req_id; |
| 285 | u32 reserved; |
| 286 | u16 data_size; |
| 287 | u8 sub_command; |
| 288 | u8 reply_status; |
| 289 | u8 data[]; |
| 290 | } __packed; |
| 291 | |
| 292 | struct mei_nfc_if_version { |
| 293 | u8 radio_version_sw[3]; |
| 294 | u8 reserved[3]; |
| 295 | u8 radio_version_hw[3]; |
| 296 | u8 i2c_addr; |
| 297 | u8 fw_ivn; |
| 298 | u8 vendor_id; |
| 299 | u8 radio_type; |
| 300 | } __packed; |
| 301 | |
Samuel Ortiz | 59fcd7c | 2013-04-11 03:03:29 +0200 | [diff] [blame] | 302 | |
| 303 | #define MEI_NFC_CMD_MAINTENANCE 0x00 |
Samuel Ortiz | 59fcd7c | 2013-04-11 03:03:29 +0200 | [diff] [blame] | 304 | #define MEI_NFC_SUBCMD_IF_VERSION 0x01 |
| 305 | |
Samuel Ortiz | 91a6b95 | 2013-04-11 03:03:30 +0200 | [diff] [blame] | 306 | /* Vendors */ |
| 307 | #define MEI_NFC_VENDOR_INSIDE 0x00 |
| 308 | #define MEI_NFC_VENDOR_NXP 0x01 |
| 309 | |
| 310 | /* Radio types */ |
| 311 | #define MEI_NFC_VENDOR_INSIDE_UREAD 0x00 |
| 312 | #define MEI_NFC_VENDOR_NXP_PN544 0x01 |
| 313 | |
Tomas Winkler | b39910c | 2015-07-23 15:08:46 +0300 | [diff] [blame] | 314 | /** |
| 315 | * mei_nfc_if_version - get NFC interface version |
| 316 | * |
| 317 | * @cl: host client (nfc info) |
| 318 | * @ver: NFC interface version to be filled in |
| 319 | * |
| 320 | * Return: 0 on success; < 0 otherwise |
| 321 | */ |
| 322 | static int mei_nfc_if_version(struct mei_cl *cl, |
| 323 | struct mei_nfc_if_version *ver) |
Samuel Ortiz | 91a6b95 | 2013-04-11 03:03:30 +0200 | [diff] [blame] | 324 | { |
Tomas Winkler | b37719c3 | 2015-07-23 15:08:33 +0300 | [diff] [blame] | 325 | struct mei_device *bus; |
Tomas Winkler | b39910c | 2015-07-23 15:08:46 +0300 | [diff] [blame] | 326 | struct mei_nfc_cmd cmd = { |
| 327 | .command = MEI_NFC_CMD_MAINTENANCE, |
| 328 | .data_size = 1, |
| 329 | .sub_command = MEI_NFC_SUBCMD_IF_VERSION, |
| 330 | }; |
Samuel Ortiz | 59fcd7c | 2013-04-11 03:03:29 +0200 | [diff] [blame] | 331 | struct mei_nfc_reply *reply = NULL; |
Samuel Ortiz | 59fcd7c | 2013-04-11 03:03:29 +0200 | [diff] [blame] | 332 | size_t if_version_length; |
| 333 | int bytes_recv, ret; |
| 334 | |
Tomas Winkler | b37719c3 | 2015-07-23 15:08:33 +0300 | [diff] [blame] | 335 | bus = cl->dev; |
Samuel Ortiz | 59fcd7c | 2013-04-11 03:03:29 +0200 | [diff] [blame] | 336 | |
Tomas Winkler | b39910c | 2015-07-23 15:08:46 +0300 | [diff] [blame] | 337 | WARN_ON(mutex_is_locked(&bus->device_lock)); |
Samuel Ortiz | 59fcd7c | 2013-04-11 03:03:29 +0200 | [diff] [blame] | 338 | |
Alexander Usyskin | e0cb6b2 | 2016-11-08 18:26:08 +0200 | [diff] [blame] | 339 | ret = __mei_cl_send(cl, (u8 *)&cmd, sizeof(struct mei_nfc_cmd), |
| 340 | MEI_CL_IO_TX_BLOCKING); |
Samuel Ortiz | 59fcd7c | 2013-04-11 03:03:29 +0200 | [diff] [blame] | 341 | if (ret < 0) { |
Tomas Winkler | b37719c3 | 2015-07-23 15:08:33 +0300 | [diff] [blame] | 342 | dev_err(bus->dev, "Could not send IF version cmd\n"); |
Samuel Ortiz | 59fcd7c | 2013-04-11 03:03:29 +0200 | [diff] [blame] | 343 | return ret; |
| 344 | } |
| 345 | |
| 346 | /* to be sure on the stack we alloc memory */ |
| 347 | if_version_length = sizeof(struct mei_nfc_reply) + |
| 348 | sizeof(struct mei_nfc_if_version); |
| 349 | |
| 350 | reply = kzalloc(if_version_length, GFP_KERNEL); |
| 351 | if (!reply) |
| 352 | return -ENOMEM; |
| 353 | |
Tomas Winkler | b39910c | 2015-07-23 15:08:46 +0300 | [diff] [blame] | 354 | ret = 0; |
Alexander Usyskin | 9a7c0b6 | 2018-06-25 00:11:40 +0300 | [diff] [blame] | 355 | bytes_recv = __mei_cl_recv(cl, (u8 *)reply, if_version_length, 0, 0); |
Tomas Winkler | 7f3838f | 2018-07-15 14:41:18 +0300 | [diff] [blame] | 356 | if (bytes_recv < 0 || (size_t)bytes_recv < if_version_length) { |
Tomas Winkler | b37719c3 | 2015-07-23 15:08:33 +0300 | [diff] [blame] | 357 | dev_err(bus->dev, "Could not read IF version\n"); |
Samuel Ortiz | 59fcd7c | 2013-04-11 03:03:29 +0200 | [diff] [blame] | 358 | ret = -EIO; |
| 359 | goto err; |
| 360 | } |
| 361 | |
Tomas Winkler | b39910c | 2015-07-23 15:08:46 +0300 | [diff] [blame] | 362 | memcpy(ver, reply->data, sizeof(struct mei_nfc_if_version)); |
Samuel Ortiz | 59fcd7c | 2013-04-11 03:03:29 +0200 | [diff] [blame] | 363 | |
Tomas Winkler | b39910c | 2015-07-23 15:08:46 +0300 | [diff] [blame] | 364 | dev_info(bus->dev, "NFC MEI VERSION: IVN 0x%x Vendor ID 0x%x Type 0x%x\n", |
| 365 | ver->fw_ivn, ver->vendor_id, ver->radio_type); |
Samuel Ortiz | 59fcd7c | 2013-04-11 03:03:29 +0200 | [diff] [blame] | 366 | |
| 367 | err: |
| 368 | kfree(reply); |
| 369 | return ret; |
| 370 | } |
| 371 | |
Tomas Winkler | b39910c | 2015-07-23 15:08:46 +0300 | [diff] [blame] | 372 | /** |
| 373 | * mei_nfc_radio_name - derive nfc radio name from the interface version |
| 374 | * |
| 375 | * @ver: NFC radio version |
| 376 | * |
| 377 | * Return: radio name string |
| 378 | */ |
| 379 | static const char *mei_nfc_radio_name(struct mei_nfc_if_version *ver) |
| 380 | { |
| 381 | |
| 382 | if (ver->vendor_id == MEI_NFC_VENDOR_INSIDE) { |
| 383 | if (ver->radio_type == MEI_NFC_VENDOR_INSIDE_UREAD) |
| 384 | return "microread"; |
| 385 | } |
| 386 | |
| 387 | if (ver->vendor_id == MEI_NFC_VENDOR_NXP) { |
| 388 | if (ver->radio_type == MEI_NFC_VENDOR_NXP_PN544) |
| 389 | return "pn544"; |
| 390 | } |
| 391 | |
| 392 | return NULL; |
| 393 | } |
| 394 | |
Tomas Winkler | 6009595 | 2015-07-23 15:08:47 +0300 | [diff] [blame] | 395 | /** |
| 396 | * mei_nfc - The nfc fixup function. The function retrieves nfc radio |
| 397 | * name and set is as device attribute so we can load |
| 398 | * the proper device driver for it |
| 399 | * |
| 400 | * @cldev: me client device (nfc) |
| 401 | */ |
| 402 | static void mei_nfc(struct mei_cl_device *cldev) |
Samuel Ortiz | 59fcd7c | 2013-04-11 03:03:29 +0200 | [diff] [blame] | 403 | { |
Tomas Winkler | b37719c3 | 2015-07-23 15:08:33 +0300 | [diff] [blame] | 404 | struct mei_device *bus; |
Tomas Winkler | 6009595 | 2015-07-23 15:08:47 +0300 | [diff] [blame] | 405 | struct mei_cl *cl; |
| 406 | struct mei_me_client *me_cl = NULL; |
| 407 | struct mei_nfc_if_version ver; |
| 408 | const char *radio_name = NULL; |
Tomas Winkler | d320832 | 2014-08-24 12:08:55 +0300 | [diff] [blame] | 409 | int ret; |
Samuel Ortiz | 59fcd7c | 2013-04-11 03:03:29 +0200 | [diff] [blame] | 410 | |
Tomas Winkler | 6009595 | 2015-07-23 15:08:47 +0300 | [diff] [blame] | 411 | bus = cldev->bus; |
Tomas Winkler | a176c24 | 2014-11-05 18:18:52 +0200 | [diff] [blame] | 412 | |
Tomas Winkler | 2bcfdc2 | 2016-01-07 14:46:34 +0200 | [diff] [blame] | 413 | dev_dbg(&cldev->dev, "running hook %s\n", __func__); |
Samuel Ortiz | 59fcd7c | 2013-04-11 03:03:29 +0200 | [diff] [blame] | 414 | |
Tomas Winkler | 6009595 | 2015-07-23 15:08:47 +0300 | [diff] [blame] | 415 | mutex_lock(&bus->device_lock); |
| 416 | /* we need to connect to INFO GUID */ |
Alexander Usyskin | 7851e00 | 2016-02-07 23:35:40 +0200 | [diff] [blame] | 417 | cl = mei_cl_alloc_linked(bus); |
Tomas Winkler | 03b8d34 | 2015-02-10 10:39:44 +0200 | [diff] [blame] | 418 | if (IS_ERR(cl)) { |
| 419 | ret = PTR_ERR(cl); |
Tomas Winkler | 6009595 | 2015-07-23 15:08:47 +0300 | [diff] [blame] | 420 | cl = NULL; |
| 421 | dev_err(bus->dev, "nfc hook alloc failed %d\n", ret); |
| 422 | goto out; |
Tomas Winkler | 03b8d34 | 2015-02-10 10:39:44 +0200 | [diff] [blame] | 423 | } |
| 424 | |
Tomas Winkler | 6009595 | 2015-07-23 15:08:47 +0300 | [diff] [blame] | 425 | me_cl = mei_me_cl_by_uuid(bus, &mei_nfc_info_guid); |
| 426 | if (!me_cl) { |
| 427 | ret = -ENOTTY; |
| 428 | dev_err(bus->dev, "Cannot find nfc info %d\n", ret); |
| 429 | goto out; |
| 430 | } |
Samuel Ortiz | 59fcd7c | 2013-04-11 03:03:29 +0200 | [diff] [blame] | 431 | |
Tomas Winkler | 6009595 | 2015-07-23 15:08:47 +0300 | [diff] [blame] | 432 | ret = mei_cl_connect(cl, me_cl, NULL); |
| 433 | if (ret < 0) { |
| 434 | dev_err(&cldev->dev, "Can't connect to the NFC INFO ME ret = %d\n", |
| 435 | ret); |
| 436 | goto out; |
| 437 | } |
Tomas Winkler | 03b8d34 | 2015-02-10 10:39:44 +0200 | [diff] [blame] | 438 | |
Tomas Winkler | b37719c3 | 2015-07-23 15:08:33 +0300 | [diff] [blame] | 439 | mutex_unlock(&bus->device_lock); |
Tomas Winkler | 6009595 | 2015-07-23 15:08:47 +0300 | [diff] [blame] | 440 | |
| 441 | ret = mei_nfc_if_version(cl, &ver); |
| 442 | if (ret) |
| 443 | goto disconnect; |
| 444 | |
| 445 | radio_name = mei_nfc_radio_name(&ver); |
| 446 | |
| 447 | if (!radio_name) { |
| 448 | ret = -ENOENT; |
| 449 | dev_err(&cldev->dev, "Can't get the NFC interface version ret = %d\n", |
| 450 | ret); |
| 451 | goto disconnect; |
| 452 | } |
| 453 | |
| 454 | dev_dbg(bus->dev, "nfc radio %s\n", radio_name); |
| 455 | strlcpy(cldev->name, radio_name, sizeof(cldev->name)); |
| 456 | |
| 457 | disconnect: |
| 458 | mutex_lock(&bus->device_lock); |
| 459 | if (mei_cl_disconnect(cl) < 0) |
| 460 | dev_err(bus->dev, "Can't disconnect the NFC INFO ME\n"); |
| 461 | |
| 462 | mei_cl_flush_queues(cl, NULL); |
| 463 | |
| 464 | out: |
| 465 | mei_cl_unlink(cl); |
| 466 | mutex_unlock(&bus->device_lock); |
| 467 | mei_me_cl_put(me_cl); |
| 468 | kfree(cl); |
| 469 | |
| 470 | if (ret) |
| 471 | cldev->do_match = 0; |
| 472 | |
| 473 | dev_dbg(bus->dev, "end of fixup match = %d\n", cldev->do_match); |
Samuel Ortiz | 59fcd7c | 2013-04-11 03:03:29 +0200 | [diff] [blame] | 474 | } |
Tomas Winkler | 4870569 | 2014-02-17 15:13:19 +0200 | [diff] [blame] | 475 | |
Tomas Winkler | 71ce789 | 2015-07-23 15:08:43 +0300 | [diff] [blame] | 476 | #define MEI_FIXUP(_uuid, _hook) { _uuid, _hook } |
| 477 | |
| 478 | static struct mei_fixup { |
| 479 | |
| 480 | const uuid_le uuid; |
| 481 | void (*hook)(struct mei_cl_device *cldev); |
Tomas Winkler | 5b6dca2 | 2015-07-23 15:08:44 +0300 | [diff] [blame] | 482 | } mei_fixups[] = { |
Tomas Winkler | dd070a1 | 2015-07-23 15:08:45 +0300 | [diff] [blame] | 483 | MEI_FIXUP(MEI_UUID_ANY, number_of_connections), |
Tomas Winkler | 5b6dca2 | 2015-07-23 15:08:44 +0300 | [diff] [blame] | 484 | MEI_FIXUP(MEI_UUID_NFC_INFO, blacklist), |
Tomas Winkler | 6009595 | 2015-07-23 15:08:47 +0300 | [diff] [blame] | 485 | MEI_FIXUP(MEI_UUID_NFC_HCI, mei_nfc), |
Tomas Winkler | e97cdb3 | 2016-01-08 00:49:24 +0200 | [diff] [blame] | 486 | MEI_FIXUP(MEI_UUID_WD, mei_wd), |
Alexander Usyskin | 7279b23 | 2016-11-10 18:38:57 +0200 | [diff] [blame] | 487 | MEI_FIXUP(MEI_UUID_MKHIF_FIX, mei_mkhi_fix), |
Tomas Winkler | d1e204e | 2019-02-21 23:41:55 +0530 | [diff] [blame] | 488 | MEI_FIXUP(MEI_UUID_HDCP, whitelist), |
Tomas Winkler | 5b6dca2 | 2015-07-23 15:08:44 +0300 | [diff] [blame] | 489 | }; |
Tomas Winkler | 71ce789 | 2015-07-23 15:08:43 +0300 | [diff] [blame] | 490 | |
| 491 | /** |
Tomas Winkler | ae48d74 | 2015-09-10 10:18:06 +0300 | [diff] [blame] | 492 | * mei_cldev_fixup - run fixup handlers |
Tomas Winkler | 71ce789 | 2015-07-23 15:08:43 +0300 | [diff] [blame] | 493 | * |
| 494 | * @cldev: me client device |
| 495 | */ |
Tomas Winkler | ae48d74 | 2015-09-10 10:18:06 +0300 | [diff] [blame] | 496 | void mei_cl_bus_dev_fixup(struct mei_cl_device *cldev) |
Tomas Winkler | 71ce789 | 2015-07-23 15:08:43 +0300 | [diff] [blame] | 497 | { |
| 498 | struct mei_fixup *f; |
| 499 | const uuid_le *uuid = mei_me_cl_uuid(cldev->me_cl); |
Tomas Winkler | 44c98df | 2018-07-12 17:10:09 +0300 | [diff] [blame] | 500 | size_t i; |
Tomas Winkler | 71ce789 | 2015-07-23 15:08:43 +0300 | [diff] [blame] | 501 | |
| 502 | for (i = 0; i < ARRAY_SIZE(mei_fixups); i++) { |
| 503 | |
| 504 | f = &mei_fixups[i]; |
| 505 | if (uuid_le_cmp(f->uuid, MEI_UUID_ANY) == 0 || |
| 506 | uuid_le_cmp(f->uuid, *uuid) == 0) |
| 507 | f->hook(cldev); |
| 508 | } |
| 509 | } |
Tomas Winkler | 4870569 | 2014-02-17 15:13:19 +0200 | [diff] [blame] | 510 | |