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