3 * Intel Management Engine Interface (Intel MEI) Linux driver
4 * Copyright (c) 2003-2013, Intel Corporation.
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.
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
17 #include <linux/kernel.h>
18 #include <linux/sched.h>
19 #include <linux/module.h>
20 #include <linux/moduleparam.h>
21 #include <linux/device.h>
22 #include <linux/slab.h>
23 #include <linux/uuid.h>
25 #include <linux/mei_cl_bus.h>
30 #define MEI_UUID_NFC_INFO UUID_LE(0xd2de1625, 0x382d, 0x417d, \
31 0x48, 0xa4, 0xef, 0xab, 0xba, 0x8a, 0x12, 0x06)
33 static const uuid_le mei_nfc_info_guid
= MEI_UUID_NFC_INFO
;
35 #define MEI_UUID_NFC_HCI UUID_LE(0x0bb17a78, 0x2a8e, 0x4c50, \
36 0x94, 0xd4, 0x50, 0x26, 0x67, 0x23, 0x77, 0x5c)
38 #define MEI_UUID_WD UUID_LE(0x05B79A6F, 0x4628, 0x4D7F, \
39 0x89, 0x9D, 0xA9, 0x15, 0x14, 0xCB, 0x32, 0xAB)
41 #define MEI_UUID_MKHIF_FIX UUID_LE(0x55213584, 0x9a29, 0x4916, \
42 0xba, 0xdf, 0xf, 0xb7, 0xed, 0x68, 0x2a, 0xeb)
44 #define MEI_UUID_ANY NULL_UUID_LE
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)
53 * @cldev: me clients device
55 static void number_of_connections(struct mei_cl_device
*cldev
)
57 dev_dbg(&cldev
->dev
, "running hook %s\n", __func__
);
59 if (cldev
->me_cl
->props
.max_number_of_connections
> 1)
64 * blacklist - blacklist a client from the bus
66 * @cldev: me clients device
68 static void blacklist(struct mei_cl_device
*cldev
)
70 dev_dbg(&cldev
->dev
, "running hook %s\n", __func__
);
75 #define OSTYPE_LINUX 2
85 #define MKHI_FEATURE_PTT 0x10
94 struct mkhi_rule_id id
;
99 #define MKHI_FWCAPS_GROUP_ID 0x3
100 #define MKHI_FWCAPS_SET_OS_VER_APP_RULE_CMD 6
101 struct mkhi_msg_hdr
{
109 struct mkhi_msg_hdr hdr
;
113 #define MKHI_OSVER_BUF_LEN (sizeof(struct mkhi_msg_hdr) + \
114 sizeof(struct mkhi_fwcaps) + \
115 sizeof(struct mei_os_ver))
116 static int mei_osver(struct mei_cl_device
*cldev
)
118 const size_t size
= MKHI_OSVER_BUF_LEN
;
119 char buf
[MKHI_OSVER_BUF_LEN
];
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
;
125 memset(buf
, 0, size
);
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
;
131 fwcaps
= (struct mkhi_fwcaps
*)req
->data
;
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
;
139 return __mei_cl_send(cldev
->cl
, buf
, size
, mode
);
142 static void mei_mkhi_fix(struct mei_cl_device
*cldev
)
146 if (!cldev
->bus
->hbm_f_os_supported
)
149 ret
= mei_cldev_enable(cldev
);
153 ret
= mei_osver(cldev
);
155 dev_err(&cldev
->dev
, "OS version command failed %d\n", ret
);
157 mei_cldev_disable(cldev
);
161 * mei_wd - wd client on the bus, change protocol version
162 * as the API has changed.
164 * @cldev: me clients device
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
)
171 struct pci_dev
*pdev
= to_pci_dev(cldev
->dev
.parent
);
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;
182 static inline void mei_wd(struct mei_cl_device
*cldev
) {}
183 #endif /* CONFIG_INTEL_MEI_ME */
195 struct mei_nfc_reply
{
206 struct mei_nfc_if_version
{
207 u8 radio_version_sw
[3];
209 u8 radio_version_hw
[3];
217 #define MEI_NFC_CMD_MAINTENANCE 0x00
218 #define MEI_NFC_SUBCMD_IF_VERSION 0x01
221 #define MEI_NFC_VENDOR_INSIDE 0x00
222 #define MEI_NFC_VENDOR_NXP 0x01
225 #define MEI_NFC_VENDOR_INSIDE_UREAD 0x00
226 #define MEI_NFC_VENDOR_NXP_PN544 0x01
229 * mei_nfc_if_version - get NFC interface version
231 * @cl: host client (nfc info)
232 * @ver: NFC interface version to be filled in
234 * Return: 0 on success; < 0 otherwise
236 static int mei_nfc_if_version(struct mei_cl
*cl
,
237 struct mei_nfc_if_version
*ver
)
239 struct mei_device
*bus
;
240 struct mei_nfc_cmd cmd
= {
241 .command
= MEI_NFC_CMD_MAINTENANCE
,
243 .sub_command
= MEI_NFC_SUBCMD_IF_VERSION
,
245 struct mei_nfc_reply
*reply
= NULL
;
246 size_t if_version_length
;
251 WARN_ON(mutex_is_locked(&bus
->device_lock
));
253 ret
= __mei_cl_send(cl
, (u8
*)&cmd
, sizeof(struct mei_nfc_cmd
),
254 MEI_CL_IO_TX_BLOCKING
);
256 dev_err(bus
->dev
, "Could not send IF version cmd\n");
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
);
264 reply
= kzalloc(if_version_length
, GFP_KERNEL
);
269 bytes_recv
= __mei_cl_recv(cl
, (u8
*)reply
, if_version_length
, 0);
270 if (bytes_recv
< if_version_length
) {
271 dev_err(bus
->dev
, "Could not read IF version\n");
276 memcpy(ver
, reply
->data
, sizeof(struct mei_nfc_if_version
));
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
);
287 * mei_nfc_radio_name - derive nfc radio name from the interface version
289 * @ver: NFC radio version
291 * Return: radio name string
293 static const char *mei_nfc_radio_name(struct mei_nfc_if_version
*ver
)
296 if (ver
->vendor_id
== MEI_NFC_VENDOR_INSIDE
) {
297 if (ver
->radio_type
== MEI_NFC_VENDOR_INSIDE_UREAD
)
301 if (ver
->vendor_id
== MEI_NFC_VENDOR_NXP
) {
302 if (ver
->radio_type
== MEI_NFC_VENDOR_NXP_PN544
)
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
314 * @cldev: me client device (nfc)
316 static void mei_nfc(struct mei_cl_device
*cldev
)
318 struct mei_device
*bus
;
320 struct mei_me_client
*me_cl
= NULL
;
321 struct mei_nfc_if_version ver
;
322 const char *radio_name
= NULL
;
327 dev_dbg(&cldev
->dev
, "running hook %s\n", __func__
);
329 mutex_lock(&bus
->device_lock
);
330 /* we need to connect to INFO GUID */
331 cl
= mei_cl_alloc_linked(bus
);
335 dev_err(bus
->dev
, "nfc hook alloc failed %d\n", ret
);
339 me_cl
= mei_me_cl_by_uuid(bus
, &mei_nfc_info_guid
);
342 dev_err(bus
->dev
, "Cannot find nfc info %d\n", ret
);
346 ret
= mei_cl_connect(cl
, me_cl
, NULL
);
348 dev_err(&cldev
->dev
, "Can't connect to the NFC INFO ME ret = %d\n",
353 mutex_unlock(&bus
->device_lock
);
355 ret
= mei_nfc_if_version(cl
, &ver
);
359 radio_name
= mei_nfc_radio_name(&ver
);
363 dev_err(&cldev
->dev
, "Can't get the NFC interface version ret = %d\n",
368 dev_dbg(bus
->dev
, "nfc radio %s\n", radio_name
);
369 strlcpy(cldev
->name
, radio_name
, sizeof(cldev
->name
));
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");
376 mei_cl_flush_queues(cl
, NULL
);
380 mutex_unlock(&bus
->device_lock
);
381 mei_me_cl_put(me_cl
);
387 dev_dbg(bus
->dev
, "end of fixup match = %d\n", cldev
->do_match
);
390 #define MEI_FIXUP(_uuid, _hook) { _uuid, _hook }
392 static struct mei_fixup
{
395 void (*hook
)(struct mei_cl_device
*cldev
);
397 MEI_FIXUP(MEI_UUID_ANY
, number_of_connections
),
398 MEI_FIXUP(MEI_UUID_NFC_INFO
, blacklist
),
399 MEI_FIXUP(MEI_UUID_NFC_HCI
, mei_nfc
),
400 MEI_FIXUP(MEI_UUID_WD
, mei_wd
),
401 MEI_FIXUP(MEI_UUID_MKHIF_FIX
, mei_mkhi_fix
),
405 * mei_cldev_fixup - run fixup handlers
407 * @cldev: me client device
409 void mei_cl_bus_dev_fixup(struct mei_cl_device
*cldev
)
412 const uuid_le
*uuid
= mei_me_cl_uuid(cldev
->me_cl
);
415 for (i
= 0; i
< ARRAY_SIZE(mei_fixups
); i
++) {
418 if (uuid_le_cmp(f
->uuid
, MEI_UUID_ANY
) == 0 ||
419 uuid_le_cmp(f
->uuid
, *uuid
) == 0)