blob: 04dc051508981d0bd469eddbd0203fec06f2b7b1 [file] [log] [blame]
Samuel Ortize5354102013-03-27 17:29:53 +02001/*
2 * Intel Management Engine Interface (Intel MEI) Linux driver
3 * Copyright (c) 2012-2013, Intel Corporation.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 */
15
16#include <linux/module.h>
17#include <linux/device.h>
18#include <linux/kernel.h>
Samuel Ortiz3e833292013-03-27 17:29:55 +020019#include <linux/sched.h>
Samuel Ortize5354102013-03-27 17:29:53 +020020#include <linux/init.h>
21#include <linux/errno.h>
22#include <linux/slab.h>
23#include <linux/mutex.h>
24#include <linux/interrupt.h>
Samuel Ortize5354102013-03-27 17:29:53 +020025#include <linux/mei_cl_bus.h>
26
27#include "mei_dev.h"
Samuel Ortiz3e833292013-03-27 17:29:55 +020028#include "client.h"
Samuel Ortize5354102013-03-27 17:29:53 +020029
30#define to_mei_cl_driver(d) container_of(d, struct mei_cl_driver, driver)
31#define to_mei_cl_device(d) container_of(d, struct mei_cl_device, dev)
32
Tomas Winkler62382992015-07-23 15:08:35 +030033/**
34 * __mei_cl_send - internal client send (write)
35 *
36 * @cl: host client
37 * @buf: buffer to send
38 * @length: buffer length
39 * @blocking: wait for write completion
40 *
41 * Return: written size bytes or < 0 on error
42 */
43ssize_t __mei_cl_send(struct mei_cl *cl, u8 *buf, size_t length,
44 bool blocking)
45{
46 struct mei_device *bus;
Alexander Usyskin6cbb0972016-02-10 23:57:26 +020047 struct mei_cl_cb *cb;
Tomas Winkler62382992015-07-23 15:08:35 +030048 ssize_t rets;
49
50 if (WARN_ON(!cl || !cl->dev))
51 return -ENODEV;
52
53 bus = cl->dev;
54
55 mutex_lock(&bus->device_lock);
Alexander Usyskin15c13df2016-02-07 23:35:32 +020056 if (bus->dev_state != MEI_DEV_ENABLED) {
57 rets = -ENODEV;
58 goto out;
59 }
60
Tomas Winkler62382992015-07-23 15:08:35 +030061 if (!mei_cl_is_connected(cl)) {
62 rets = -ENODEV;
63 goto out;
64 }
65
66 /* Check if we have an ME client device */
67 if (!mei_me_cl_is_active(cl->me_cl)) {
68 rets = -ENOTTY;
69 goto out;
70 }
71
72 if (length > mei_cl_mtu(cl)) {
73 rets = -EFBIG;
74 goto out;
75 }
76
77 cb = mei_cl_alloc_cb(cl, length, MEI_FOP_WRITE, NULL);
78 if (!cb) {
79 rets = -ENOMEM;
80 goto out;
81 }
82
83 memcpy(cb->buf.data, buf, length);
84
85 rets = mei_cl_write(cl, cb, blocking);
86
87out:
88 mutex_unlock(&bus->device_lock);
Tomas Winkler62382992015-07-23 15:08:35 +030089
90 return rets;
91}
92
93/**
94 * __mei_cl_recv - internal client receive (read)
95 *
96 * @cl: host client
Tomas Winklerdf7f5442015-10-13 15:02:40 +030097 * @buf: buffer to receive
Tomas Winkler62382992015-07-23 15:08:35 +030098 * @length: buffer length
99 *
100 * Return: read size in bytes of < 0 on error
101 */
102ssize_t __mei_cl_recv(struct mei_cl *cl, u8 *buf, size_t length)
103{
104 struct mei_device *bus;
105 struct mei_cl_cb *cb;
106 size_t r_length;
107 ssize_t rets;
108
109 if (WARN_ON(!cl || !cl->dev))
110 return -ENODEV;
111
112 bus = cl->dev;
113
114 mutex_lock(&bus->device_lock);
Alexander Usyskin15c13df2016-02-07 23:35:32 +0200115 if (bus->dev_state != MEI_DEV_ENABLED) {
116 rets = -ENODEV;
117 goto out;
118 }
Tomas Winkler62382992015-07-23 15:08:35 +0300119
120 cb = mei_cl_read_cb(cl, NULL);
121 if (cb)
122 goto copy;
123
124 rets = mei_cl_read_start(cl, length, NULL);
125 if (rets && rets != -EBUSY)
126 goto out;
127
128 /* wait on event only if there is no other waiter */
129 if (list_empty(&cl->rd_completed) && !waitqueue_active(&cl->rx_wait)) {
130
131 mutex_unlock(&bus->device_lock);
132
133 if (wait_event_interruptible(cl->rx_wait,
134 (!list_empty(&cl->rd_completed)) ||
135 (!mei_cl_is_connected(cl)))) {
136
137 if (signal_pending(current))
138 return -EINTR;
139 return -ERESTARTSYS;
140 }
141
142 mutex_lock(&bus->device_lock);
143
144 if (!mei_cl_is_connected(cl)) {
145 rets = -EBUSY;
146 goto out;
147 }
148 }
149
150 cb = mei_cl_read_cb(cl, NULL);
151 if (!cb) {
152 rets = 0;
153 goto out;
154 }
155
156copy:
157 if (cb->status) {
158 rets = cb->status;
159 goto free;
160 }
161
162 r_length = min_t(size_t, length, cb->buf_idx);
163 memcpy(buf, cb->buf.data, r_length);
164 rets = r_length;
165
166free:
167 mei_io_cb_free(cb);
168out:
169 mutex_unlock(&bus->device_lock);
170
171 return rets;
172}
173
174/**
Tomas Winklerd49dc5e2015-09-10 10:18:05 +0300175 * mei_cldev_send - me device send (write)
Tomas Winkler62382992015-07-23 15:08:35 +0300176 *
177 * @cldev: me client device
178 * @buf: buffer to send
179 * @length: buffer length
180 *
181 * Return: written size in bytes or < 0 on error
182 */
Tomas Winklerd49dc5e2015-09-10 10:18:05 +0300183ssize_t mei_cldev_send(struct mei_cl_device *cldev, u8 *buf, size_t length)
Tomas Winkler62382992015-07-23 15:08:35 +0300184{
185 struct mei_cl *cl = cldev->cl;
186
187 if (cl == NULL)
188 return -ENODEV;
189
190 return __mei_cl_send(cl, buf, length, 1);
191}
Tomas Winklerd49dc5e2015-09-10 10:18:05 +0300192EXPORT_SYMBOL_GPL(mei_cldev_send);
Tomas Winkler62382992015-07-23 15:08:35 +0300193
194/**
Tomas Winklerd49dc5e2015-09-10 10:18:05 +0300195 * mei_cldev_recv - client receive (read)
Tomas Winkler62382992015-07-23 15:08:35 +0300196 *
197 * @cldev: me client device
Tomas Winklerdf7f5442015-10-13 15:02:40 +0300198 * @buf: buffer to receive
Tomas Winkler62382992015-07-23 15:08:35 +0300199 * @length: buffer length
200 *
201 * Return: read size in bytes of < 0 on error
202 */
Tomas Winklerd49dc5e2015-09-10 10:18:05 +0300203ssize_t mei_cldev_recv(struct mei_cl_device *cldev, u8 *buf, size_t length)
Tomas Winkler62382992015-07-23 15:08:35 +0300204{
205 struct mei_cl *cl = cldev->cl;
206
207 if (cl == NULL)
208 return -ENODEV;
209
210 return __mei_cl_recv(cl, buf, length);
211}
Tomas Winklerd49dc5e2015-09-10 10:18:05 +0300212EXPORT_SYMBOL_GPL(mei_cldev_recv);
Tomas Winkler62382992015-07-23 15:08:35 +0300213
214/**
Tomas Winklerd49dc5e2015-09-10 10:18:05 +0300215 * mei_cl_bus_event_work - dispatch rx event for a bus device
Tomas Winkler62382992015-07-23 15:08:35 +0300216 * and schedule new work
217 *
218 * @work: work
219 */
Tomas Winklerd49dc5e2015-09-10 10:18:05 +0300220static void mei_cl_bus_event_work(struct work_struct *work)
Tomas Winkler62382992015-07-23 15:08:35 +0300221{
222 struct mei_cl_device *cldev;
223
224 cldev = container_of(work, struct mei_cl_device, event_work);
225
226 if (cldev->event_cb)
227 cldev->event_cb(cldev, cldev->events, cldev->event_context);
228
229 cldev->events = 0;
230
231 /* Prepare for the next read */
Alexander Usyskinbb2ef9c2015-07-26 09:54:23 +0300232 if (cldev->events_mask & BIT(MEI_CL_EVENT_RX))
233 mei_cl_read_start(cldev->cl, 0, NULL);
234}
235
236/**
237 * mei_cl_bus_notify_event - schedule notify cb on bus client
238 *
239 * @cl: host client
Tomas Winkler850f8942016-02-07 23:35:31 +0200240 *
241 * Return: true if event was scheduled
242 * false if the client is not waiting for event
Alexander Usyskinbb2ef9c2015-07-26 09:54:23 +0300243 */
Tomas Winkler850f8942016-02-07 23:35:31 +0200244bool mei_cl_bus_notify_event(struct mei_cl *cl)
Alexander Usyskinbb2ef9c2015-07-26 09:54:23 +0300245{
246 struct mei_cl_device *cldev = cl->cldev;
247
248 if (!cldev || !cldev->event_cb)
Tomas Winkler850f8942016-02-07 23:35:31 +0200249 return false;
Alexander Usyskinbb2ef9c2015-07-26 09:54:23 +0300250
251 if (!(cldev->events_mask & BIT(MEI_CL_EVENT_NOTIF)))
Tomas Winkler850f8942016-02-07 23:35:31 +0200252 return false;
Alexander Usyskinbb2ef9c2015-07-26 09:54:23 +0300253
254 if (!cl->notify_ev)
Tomas Winkler850f8942016-02-07 23:35:31 +0200255 return false;
Alexander Usyskinbb2ef9c2015-07-26 09:54:23 +0300256
257 set_bit(MEI_CL_EVENT_NOTIF, &cldev->events);
258
259 schedule_work(&cldev->event_work);
260
261 cl->notify_ev = false;
Tomas Winkler850f8942016-02-07 23:35:31 +0200262
263 return true;
Tomas Winkler62382992015-07-23 15:08:35 +0300264}
265
266/**
Tomas Winklera1f9ae22016-02-07 23:35:30 +0200267 * mei_cl_bus_rx_event - schedule rx event
Tomas Winkler62382992015-07-23 15:08:35 +0300268 *
269 * @cl: host client
Tomas Winklera1f9ae22016-02-07 23:35:30 +0200270 *
271 * Return: true if event was scheduled
272 * false if the client is not waiting for event
Tomas Winkler62382992015-07-23 15:08:35 +0300273 */
Tomas Winklera1f9ae22016-02-07 23:35:30 +0200274bool mei_cl_bus_rx_event(struct mei_cl *cl)
Tomas Winkler62382992015-07-23 15:08:35 +0300275{
276 struct mei_cl_device *cldev = cl->cldev;
277
278 if (!cldev || !cldev->event_cb)
Tomas Winklera1f9ae22016-02-07 23:35:30 +0200279 return false;
Tomas Winkler62382992015-07-23 15:08:35 +0300280
Alexander Usyskinbb2ef9c2015-07-26 09:54:23 +0300281 if (!(cldev->events_mask & BIT(MEI_CL_EVENT_RX)))
Tomas Winklera1f9ae22016-02-07 23:35:30 +0200282 return false;
Alexander Usyskinbb2ef9c2015-07-26 09:54:23 +0300283
Tomas Winkler62382992015-07-23 15:08:35 +0300284 set_bit(MEI_CL_EVENT_RX, &cldev->events);
285
286 schedule_work(&cldev->event_work);
Tomas Winklera1f9ae22016-02-07 23:35:30 +0200287
288 return true;
Tomas Winkler62382992015-07-23 15:08:35 +0300289}
290
291/**
Tomas Winklerd49dc5e2015-09-10 10:18:05 +0300292 * mei_cldev_register_event_cb - register event callback
Tomas Winkler62382992015-07-23 15:08:35 +0300293 *
294 * @cldev: me client devices
295 * @event_cb: callback function
Alexander Usyskinbb2ef9c2015-07-26 09:54:23 +0300296 * @events_mask: requested events bitmask
Tomas Winkler62382992015-07-23 15:08:35 +0300297 * @context: driver context data
298 *
299 * Return: 0 on success
300 * -EALREADY if an callback is already registered
301 * <0 on other errors
302 */
Tomas Winklerd49dc5e2015-09-10 10:18:05 +0300303int mei_cldev_register_event_cb(struct mei_cl_device *cldev,
304 unsigned long events_mask,
305 mei_cldev_event_cb_t event_cb, void *context)
Tomas Winkler62382992015-07-23 15:08:35 +0300306{
Tomas Winkler48168f42015-07-23 15:08:38 +0300307 int ret;
308
Tomas Winkler62382992015-07-23 15:08:35 +0300309 if (cldev->event_cb)
310 return -EALREADY;
311
312 cldev->events = 0;
Alexander Usyskinbb2ef9c2015-07-26 09:54:23 +0300313 cldev->events_mask = events_mask;
Tomas Winkler62382992015-07-23 15:08:35 +0300314 cldev->event_cb = event_cb;
315 cldev->event_context = context;
Tomas Winklerd49dc5e2015-09-10 10:18:05 +0300316 INIT_WORK(&cldev->event_work, mei_cl_bus_event_work);
Tomas Winkler62382992015-07-23 15:08:35 +0300317
Alexander Usyskinbb2ef9c2015-07-26 09:54:23 +0300318 if (cldev->events_mask & BIT(MEI_CL_EVENT_RX)) {
319 ret = mei_cl_read_start(cldev->cl, 0, NULL);
320 if (ret && ret != -EBUSY)
321 return ret;
322 }
323
324 if (cldev->events_mask & BIT(MEI_CL_EVENT_NOTIF)) {
325 mutex_lock(&cldev->cl->dev->device_lock);
326 ret = mei_cl_notify_request(cldev->cl, NULL, event_cb ? 1 : 0);
327 mutex_unlock(&cldev->cl->dev->device_lock);
328 if (ret)
329 return ret;
330 }
Tomas Winkler62382992015-07-23 15:08:35 +0300331
332 return 0;
333}
Tomas Winklerd49dc5e2015-09-10 10:18:05 +0300334EXPORT_SYMBOL_GPL(mei_cldev_register_event_cb);
Tomas Winkler62382992015-07-23 15:08:35 +0300335
336/**
Tomas Winklerd49dc5e2015-09-10 10:18:05 +0300337 * mei_cldev_get_drvdata - driver data getter
Tomas Winkler62382992015-07-23 15:08:35 +0300338 *
339 * @cldev: mei client device
340 *
341 * Return: driver private data
342 */
Tomas Winklerd49dc5e2015-09-10 10:18:05 +0300343void *mei_cldev_get_drvdata(const struct mei_cl_device *cldev)
Tomas Winkler62382992015-07-23 15:08:35 +0300344{
345 return dev_get_drvdata(&cldev->dev);
346}
Tomas Winklerd49dc5e2015-09-10 10:18:05 +0300347EXPORT_SYMBOL_GPL(mei_cldev_get_drvdata);
Tomas Winkler62382992015-07-23 15:08:35 +0300348
349/**
Tomas Winklerd49dc5e2015-09-10 10:18:05 +0300350 * mei_cldev_set_drvdata - driver data setter
Tomas Winkler62382992015-07-23 15:08:35 +0300351 *
352 * @cldev: mei client device
353 * @data: data to store
354 */
Tomas Winklerd49dc5e2015-09-10 10:18:05 +0300355void mei_cldev_set_drvdata(struct mei_cl_device *cldev, void *data)
Tomas Winkler62382992015-07-23 15:08:35 +0300356{
357 dev_set_drvdata(&cldev->dev, data);
358}
Tomas Winklerd49dc5e2015-09-10 10:18:05 +0300359EXPORT_SYMBOL_GPL(mei_cldev_set_drvdata);
Tomas Winkler62382992015-07-23 15:08:35 +0300360
361/**
Tomas Winklerbaeacd02015-09-10 10:18:02 +0300362 * mei_cldev_uuid - return uuid of the underlying me client
363 *
364 * @cldev: mei client device
365 *
366 * Return: me client uuid
367 */
368const uuid_le *mei_cldev_uuid(const struct mei_cl_device *cldev)
369{
370 return mei_me_cl_uuid(cldev->me_cl);
371}
372EXPORT_SYMBOL_GPL(mei_cldev_uuid);
373
374/**
375 * mei_cldev_ver - return protocol version of the underlying me client
376 *
377 * @cldev: mei client device
378 *
379 * Return: me client protocol version
380 */
381u8 mei_cldev_ver(const struct mei_cl_device *cldev)
382{
383 return mei_me_cl_ver(cldev->me_cl);
384}
385EXPORT_SYMBOL_GPL(mei_cldev_ver);
386
387/**
Tomas Winkler01a14ed2015-09-10 10:18:03 +0300388 * mei_cldev_enabled - check whether the device is enabled
389 *
390 * @cldev: mei client device
391 *
392 * Return: true if me client is initialized and connected
393 */
394bool mei_cldev_enabled(struct mei_cl_device *cldev)
395{
396 return cldev->cl && mei_cl_is_connected(cldev->cl);
397}
398EXPORT_SYMBOL_GPL(mei_cldev_enabled);
399
400/**
Tomas Winklerd49dc5e2015-09-10 10:18:05 +0300401 * mei_cldev_enable_device - enable me client device
Tomas Winkler62382992015-07-23 15:08:35 +0300402 * create connection with me client
403 *
404 * @cldev: me client device
405 *
406 * Return: 0 on success and < 0 on error
407 */
Tomas Winklerd49dc5e2015-09-10 10:18:05 +0300408int mei_cldev_enable(struct mei_cl_device *cldev)
Tomas Winkler62382992015-07-23 15:08:35 +0300409{
Tomas Winkler60095952015-07-23 15:08:47 +0300410 struct mei_device *bus = cldev->bus;
411 struct mei_cl *cl;
412 int ret;
Tomas Winkler62382992015-07-23 15:08:35 +0300413
Tomas Winkler60095952015-07-23 15:08:47 +0300414 cl = cldev->cl;
Tomas Winkler62382992015-07-23 15:08:35 +0300415
Tomas Winkler60095952015-07-23 15:08:47 +0300416 if (!cl) {
417 mutex_lock(&bus->device_lock);
Alexander Usyskin7851e002016-02-07 23:35:40 +0200418 cl = mei_cl_alloc_linked(bus);
Tomas Winkler60095952015-07-23 15:08:47 +0300419 mutex_unlock(&bus->device_lock);
420 if (IS_ERR(cl))
421 return PTR_ERR(cl);
422 /* update pointers */
423 cldev->cl = cl;
424 cl->cldev = cldev;
425 }
Tomas Winkler62382992015-07-23 15:08:35 +0300426
427 mutex_lock(&bus->device_lock);
Tomas Winkler62382992015-07-23 15:08:35 +0300428 if (mei_cl_is_connected(cl)) {
Tomas Winkler60095952015-07-23 15:08:47 +0300429 ret = 0;
430 goto out;
Tomas Winkler62382992015-07-23 15:08:35 +0300431 }
432
Tomas Winkler60095952015-07-23 15:08:47 +0300433 if (!mei_me_cl_is_active(cldev->me_cl)) {
434 dev_err(&cldev->dev, "me client is not active\n");
435 ret = -ENOTTY;
436 goto out;
Tomas Winkler62382992015-07-23 15:08:35 +0300437 }
438
Tomas Winkler60095952015-07-23 15:08:47 +0300439 ret = mei_cl_connect(cl, cldev->me_cl, NULL);
440 if (ret < 0)
441 dev_err(&cldev->dev, "cannot connect\n");
442
443out:
Tomas Winkler62382992015-07-23 15:08:35 +0300444 mutex_unlock(&bus->device_lock);
445
Tomas Winkler60095952015-07-23 15:08:47 +0300446 return ret;
Tomas Winkler62382992015-07-23 15:08:35 +0300447}
Tomas Winklerd49dc5e2015-09-10 10:18:05 +0300448EXPORT_SYMBOL_GPL(mei_cldev_enable);
Tomas Winkler62382992015-07-23 15:08:35 +0300449
450/**
Tomas Winklerd49dc5e2015-09-10 10:18:05 +0300451 * mei_cldev_disable - disable me client device
Tomas Winkler62382992015-07-23 15:08:35 +0300452 * disconnect form the me client
453 *
454 * @cldev: me client device
455 *
456 * Return: 0 on success and < 0 on error
457 */
Tomas Winklerd49dc5e2015-09-10 10:18:05 +0300458int mei_cldev_disable(struct mei_cl_device *cldev)
Tomas Winkler62382992015-07-23 15:08:35 +0300459{
Tomas Winkler62382992015-07-23 15:08:35 +0300460 struct mei_device *bus;
Tomas Winkler60095952015-07-23 15:08:47 +0300461 struct mei_cl *cl;
462 int err;
Tomas Winkler62382992015-07-23 15:08:35 +0300463
Tomas Winkler60095952015-07-23 15:08:47 +0300464 if (!cldev || !cldev->cl)
Tomas Winkler62382992015-07-23 15:08:35 +0300465 return -ENODEV;
466
Tomas Winkler60095952015-07-23 15:08:47 +0300467 cl = cldev->cl;
468
469 bus = cldev->bus;
Tomas Winkler62382992015-07-23 15:08:35 +0300470
471 cldev->event_cb = NULL;
472
473 mutex_lock(&bus->device_lock);
474
475 if (!mei_cl_is_connected(cl)) {
476 dev_err(bus->dev, "Already disconnected");
477 err = 0;
478 goto out;
479 }
480
481 err = mei_cl_disconnect(cl);
Tomas Winkler60095952015-07-23 15:08:47 +0300482 if (err < 0)
Tomas Winkler62382992015-07-23 15:08:35 +0300483 dev_err(bus->dev, "Could not disconnect from the ME client");
Tomas Winkler62382992015-07-23 15:08:35 +0300484
485out:
Tomas Winkler60095952015-07-23 15:08:47 +0300486 /* Flush queues and remove any pending read */
487 mei_cl_flush_queues(cl, NULL);
488 mei_cl_unlink(cl);
489
490 kfree(cl);
491 cldev->cl = NULL;
492
Tomas Winkler62382992015-07-23 15:08:35 +0300493 mutex_unlock(&bus->device_lock);
494 return err;
Tomas Winkler62382992015-07-23 15:08:35 +0300495}
Tomas Winklerd49dc5e2015-09-10 10:18:05 +0300496EXPORT_SYMBOL_GPL(mei_cldev_disable);
Tomas Winkler62382992015-07-23 15:08:35 +0300497
Tomas Winkler688a9cc2015-07-23 15:08:39 +0300498/**
499 * mei_cl_device_find - find matching entry in the driver id table
500 *
501 * @cldev: me client device
502 * @cldrv: me client driver
503 *
504 * Return: id on success; NULL if no id is matching
505 */
506static const
507struct mei_cl_device_id *mei_cl_device_find(struct mei_cl_device *cldev,
508 struct mei_cl_driver *cldrv)
Samuel Ortize5354102013-03-27 17:29:53 +0200509{
Samuel Ortize5354102013-03-27 17:29:53 +0200510 const struct mei_cl_device_id *id;
Tomas Winklerc93b76b2015-05-07 15:54:02 +0300511 const uuid_le *uuid;
Tomas Winklerb26864c2015-09-10 10:18:01 +0300512 u8 version;
513 bool match;
Samuel Ortize5354102013-03-27 17:29:53 +0200514
Tomas Winklerb37719c32015-07-23 15:08:33 +0300515 uuid = mei_me_cl_uuid(cldev->me_cl);
Tomas Winklerb26864c2015-09-10 10:18:01 +0300516 version = mei_me_cl_ver(cldev->me_cl);
Samuel Ortize5354102013-03-27 17:29:53 +0200517
Tomas Winklerb37719c32015-07-23 15:08:33 +0300518 id = cldrv->id_table;
Greg Kroah-Hartmanb144ce22015-05-27 17:17:27 -0700519 while (uuid_le_cmp(NULL_UUID_LE, id->uuid)) {
Greg Kroah-Hartmanb144ce22015-05-27 17:17:27 -0700520 if (!uuid_le_cmp(*uuid, id->uuid)) {
Tomas Winklerb26864c2015-09-10 10:18:01 +0300521 match = true;
Tomas Winkler688a9cc2015-07-23 15:08:39 +0300522
Tomas Winklerb26864c2015-09-10 10:18:01 +0300523 if (cldev->name[0])
524 if (strncmp(cldev->name, id->name,
525 sizeof(id->name)))
526 match = false;
Tomas Winkler688a9cc2015-07-23 15:08:39 +0300527
Tomas Winklerb26864c2015-09-10 10:18:01 +0300528 if (id->version != MEI_CL_VERSION_ANY)
529 if (id->version != version)
530 match = false;
531 if (match)
Tomas Winkler688a9cc2015-07-23 15:08:39 +0300532 return id;
Tomas Winklerc93b76b2015-05-07 15:54:02 +0300533 }
Samuel Ortize5354102013-03-27 17:29:53 +0200534
535 id++;
536 }
537
Tomas Winkler688a9cc2015-07-23 15:08:39 +0300538 return NULL;
539}
540
541/**
542 * mei_cl_device_match - device match function
543 *
544 * @dev: device
545 * @drv: driver
546 *
547 * Return: 1 if matching device was found 0 otherwise
548 */
549static int mei_cl_device_match(struct device *dev, struct device_driver *drv)
550{
551 struct mei_cl_device *cldev = to_mei_cl_device(dev);
552 struct mei_cl_driver *cldrv = to_mei_cl_driver(drv);
553 const struct mei_cl_device_id *found_id;
554
555 if (!cldev)
556 return 0;
557
Tomas Winkler71ce7892015-07-23 15:08:43 +0300558 if (!cldev->do_match)
559 return 0;
560
Tomas Winkler688a9cc2015-07-23 15:08:39 +0300561 if (!cldrv || !cldrv->id_table)
562 return 0;
563
564 found_id = mei_cl_device_find(cldev, cldrv);
565 if (found_id)
566 return 1;
567
Samuel Ortize5354102013-03-27 17:29:53 +0200568 return 0;
569}
570
Tomas Winklerfeb8cd02015-07-23 15:08:40 +0300571/**
572 * mei_cl_device_probe - bus probe function
573 *
574 * @dev: device
575 *
576 * Return: 0 on success; < 0 otherwise
577 */
Samuel Ortize5354102013-03-27 17:29:53 +0200578static int mei_cl_device_probe(struct device *dev)
579{
Tomas Winklerfeb8cd02015-07-23 15:08:40 +0300580 struct mei_cl_device *cldev;
Tomas Winklerb37719c32015-07-23 15:08:33 +0300581 struct mei_cl_driver *cldrv;
Tomas Winklerfeb8cd02015-07-23 15:08:40 +0300582 const struct mei_cl_device_id *id;
583
584 cldev = to_mei_cl_device(dev);
585 cldrv = to_mei_cl_driver(dev->driver);
Samuel Ortize5354102013-03-27 17:29:53 +0200586
Tomas Winklerb37719c32015-07-23 15:08:33 +0300587 if (!cldev)
Samuel Ortize5354102013-03-27 17:29:53 +0200588 return 0;
589
Tomas Winklerb37719c32015-07-23 15:08:33 +0300590 if (!cldrv || !cldrv->probe)
Samuel Ortize5354102013-03-27 17:29:53 +0200591 return -ENODEV;
592
Tomas Winklerfeb8cd02015-07-23 15:08:40 +0300593 id = mei_cl_device_find(cldev, cldrv);
594 if (!id)
595 return -ENODEV;
Samuel Ortize5354102013-03-27 17:29:53 +0200596
Tomas Winklerfeb8cd02015-07-23 15:08:40 +0300597 __module_get(THIS_MODULE);
Samuel Ortize5354102013-03-27 17:29:53 +0200598
Tomas Winklerfeb8cd02015-07-23 15:08:40 +0300599 return cldrv->probe(cldev, id);
Samuel Ortize5354102013-03-27 17:29:53 +0200600}
601
Tomas Winklerfeb8cd02015-07-23 15:08:40 +0300602/**
603 * mei_cl_device_remove - remove device from the bus
604 *
605 * @dev: device
606 *
607 * Return: 0 on success; < 0 otherwise
608 */
Samuel Ortize5354102013-03-27 17:29:53 +0200609static int mei_cl_device_remove(struct device *dev)
610{
Tomas Winklerb37719c32015-07-23 15:08:33 +0300611 struct mei_cl_device *cldev = to_mei_cl_device(dev);
612 struct mei_cl_driver *cldrv;
Tomas Winklerfeb8cd02015-07-23 15:08:40 +0300613 int ret = 0;
Samuel Ortize5354102013-03-27 17:29:53 +0200614
Tomas Winklerb37719c32015-07-23 15:08:33 +0300615 if (!cldev || !dev->driver)
Samuel Ortize5354102013-03-27 17:29:53 +0200616 return 0;
617
Tomas Winklerb37719c32015-07-23 15:08:33 +0300618 if (cldev->event_cb) {
619 cldev->event_cb = NULL;
620 cancel_work_sync(&cldev->event_work);
Samuel Ortiz3e833292013-03-27 17:29:55 +0200621 }
622
Tomas Winklerb37719c32015-07-23 15:08:33 +0300623 cldrv = to_mei_cl_driver(dev->driver);
Tomas Winklerfeb8cd02015-07-23 15:08:40 +0300624 if (cldrv->remove)
625 ret = cldrv->remove(cldev);
Samuel Ortize5354102013-03-27 17:29:53 +0200626
Tomas Winklerfeb8cd02015-07-23 15:08:40 +0300627 module_put(THIS_MODULE);
628 dev->driver = NULL;
629 return ret;
Samuel Ortize5354102013-03-27 17:29:53 +0200630
Samuel Ortize5354102013-03-27 17:29:53 +0200631}
632
Tomas Winkler007d64e2015-05-07 15:54:03 +0300633static ssize_t name_show(struct device *dev, struct device_attribute *a,
634 char *buf)
635{
Tomas Winklerb37719c32015-07-23 15:08:33 +0300636 struct mei_cl_device *cldev = to_mei_cl_device(dev);
Tomas Winkler007d64e2015-05-07 15:54:03 +0300637
Rasmus Villemoes423de922016-03-24 10:38:04 +0200638 return scnprintf(buf, PAGE_SIZE, "%s", cldev->name);
Tomas Winkler007d64e2015-05-07 15:54:03 +0300639}
640static DEVICE_ATTR_RO(name);
641
642static ssize_t uuid_show(struct device *dev, struct device_attribute *a,
643 char *buf)
644{
Tomas Winklerb37719c32015-07-23 15:08:33 +0300645 struct mei_cl_device *cldev = to_mei_cl_device(dev);
646 const uuid_le *uuid = mei_me_cl_uuid(cldev->me_cl);
Tomas Winkler007d64e2015-05-07 15:54:03 +0300647
Rasmus Villemoes423de922016-03-24 10:38:04 +0200648 return scnprintf(buf, PAGE_SIZE, "%pUl", uuid);
Tomas Winkler007d64e2015-05-07 15:54:03 +0300649}
650static DEVICE_ATTR_RO(uuid);
651
Tomas Winkler40b73202015-09-10 10:18:00 +0300652static ssize_t version_show(struct device *dev, struct device_attribute *a,
653 char *buf)
654{
655 struct mei_cl_device *cldev = to_mei_cl_device(dev);
656 u8 version = mei_me_cl_ver(cldev->me_cl);
Tomas Winkler40b73202015-09-10 10:18:00 +0300657
Rasmus Villemoes423de922016-03-24 10:38:04 +0200658 return scnprintf(buf, PAGE_SIZE, "%02X", version);
Tomas Winkler40b73202015-09-10 10:18:00 +0300659}
660static DEVICE_ATTR_RO(version);
661
Samuel Ortize5354102013-03-27 17:29:53 +0200662static ssize_t modalias_show(struct device *dev, struct device_attribute *a,
663 char *buf)
664{
Tomas Winklerb37719c32015-07-23 15:08:33 +0300665 struct mei_cl_device *cldev = to_mei_cl_device(dev);
666 const uuid_le *uuid = mei_me_cl_uuid(cldev->me_cl);
Samuel Ortize5354102013-03-27 17:29:53 +0200667
Rasmus Villemoes423de922016-03-24 10:38:04 +0200668 return scnprintf(buf, PAGE_SIZE, "mei:%s:%pUl:", cldev->name, uuid);
Samuel Ortize5354102013-03-27 17:29:53 +0200669}
Greg Kroah-Hartman32f389ec2013-08-23 14:24:39 -0700670static DEVICE_ATTR_RO(modalias);
Samuel Ortize5354102013-03-27 17:29:53 +0200671
Tomas Winklerd49dc5e2015-09-10 10:18:05 +0300672static struct attribute *mei_cldev_attrs[] = {
Tomas Winkler007d64e2015-05-07 15:54:03 +0300673 &dev_attr_name.attr,
674 &dev_attr_uuid.attr,
Tomas Winkler40b73202015-09-10 10:18:00 +0300675 &dev_attr_version.attr,
Greg Kroah-Hartman32f389ec2013-08-23 14:24:39 -0700676 &dev_attr_modalias.attr,
677 NULL,
Samuel Ortize5354102013-03-27 17:29:53 +0200678};
Tomas Winklerd49dc5e2015-09-10 10:18:05 +0300679ATTRIBUTE_GROUPS(mei_cldev);
Samuel Ortize5354102013-03-27 17:29:53 +0200680
Tomas Winkler38d3c002015-07-23 15:08:36 +0300681/**
682 * mei_cl_device_uevent - me client bus uevent handler
683 *
684 * @dev: device
685 * @env: uevent kobject
686 *
687 * Return: 0 on success -ENOMEM on when add_uevent_var fails
688 */
689static int mei_cl_device_uevent(struct device *dev, struct kobj_uevent_env *env)
Samuel Ortize5354102013-03-27 17:29:53 +0200690{
Tomas Winklerb37719c32015-07-23 15:08:33 +0300691 struct mei_cl_device *cldev = to_mei_cl_device(dev);
692 const uuid_le *uuid = mei_me_cl_uuid(cldev->me_cl);
Tomas Winkler40b73202015-09-10 10:18:00 +0300693 u8 version = mei_me_cl_ver(cldev->me_cl);
694
695 if (add_uevent_var(env, "MEI_CL_VERSION=%d", version))
696 return -ENOMEM;
Tomas Winklerc93b76b2015-05-07 15:54:02 +0300697
Tomas Winkler007d64e2015-05-07 15:54:03 +0300698 if (add_uevent_var(env, "MEI_CL_UUID=%pUl", uuid))
699 return -ENOMEM;
700
Tomas Winklerb37719c32015-07-23 15:08:33 +0300701 if (add_uevent_var(env, "MEI_CL_NAME=%s", cldev->name))
Tomas Winkler007d64e2015-05-07 15:54:03 +0300702 return -ENOMEM;
703
Tomas Winklerb26864c2015-09-10 10:18:01 +0300704 if (add_uevent_var(env, "MODALIAS=mei:%s:%pUl:%02X:",
705 cldev->name, uuid, version))
Samuel Ortize5354102013-03-27 17:29:53 +0200706 return -ENOMEM;
707
708 return 0;
709}
710
711static struct bus_type mei_cl_bus_type = {
712 .name = "mei",
Tomas Winklerd49dc5e2015-09-10 10:18:05 +0300713 .dev_groups = mei_cldev_groups,
Samuel Ortize5354102013-03-27 17:29:53 +0200714 .match = mei_cl_device_match,
715 .probe = mei_cl_device_probe,
716 .remove = mei_cl_device_remove,
Tomas Winkler38d3c002015-07-23 15:08:36 +0300717 .uevent = mei_cl_device_uevent,
Samuel Ortize5354102013-03-27 17:29:53 +0200718};
719
Tomas Winkler512f64d2015-07-23 15:08:41 +0300720static struct mei_device *mei_dev_bus_get(struct mei_device *bus)
721{
722 if (bus)
723 get_device(bus->dev);
724
725 return bus;
726}
727
728static void mei_dev_bus_put(struct mei_device *bus)
729{
730 if (bus)
731 put_device(bus->dev);
732}
733
Tomas Winklerae48d742015-09-10 10:18:06 +0300734static void mei_cl_bus_dev_release(struct device *dev)
Samuel Ortize5354102013-03-27 17:29:53 +0200735{
Tomas Winklerb37719c32015-07-23 15:08:33 +0300736 struct mei_cl_device *cldev = to_mei_cl_device(dev);
Alexander Usyskind49ed642015-05-04 09:43:54 +0300737
Tomas Winklerb37719c32015-07-23 15:08:33 +0300738 if (!cldev)
Alexander Usyskind49ed642015-05-04 09:43:54 +0300739 return;
740
Tomas Winklerb37719c32015-07-23 15:08:33 +0300741 mei_me_cl_put(cldev->me_cl);
Tomas Winkler512f64d2015-07-23 15:08:41 +0300742 mei_dev_bus_put(cldev->bus);
Tomas Winklerb37719c32015-07-23 15:08:33 +0300743 kfree(cldev);
Samuel Ortize5354102013-03-27 17:29:53 +0200744}
745
746static struct device_type mei_cl_device_type = {
Tomas Winklerae48d742015-09-10 10:18:06 +0300747 .release = mei_cl_bus_dev_release,
Samuel Ortize5354102013-03-27 17:29:53 +0200748};
749
Tomas Winkler71ce7892015-07-23 15:08:43 +0300750/**
Tomas Winkler213dd192015-10-28 14:34:35 +0200751 * mei_cl_bus_set_name - set device name for me client device
752 *
753 * @cldev: me client device
754 */
755static inline void mei_cl_bus_set_name(struct mei_cl_device *cldev)
756{
757 dev_set_name(&cldev->dev, "mei:%s:%pUl:%02X",
758 cldev->name,
759 mei_me_cl_uuid(cldev->me_cl),
760 mei_me_cl_ver(cldev->me_cl));
761}
762
763/**
Tomas Winklerae48d742015-09-10 10:18:06 +0300764 * mei_cl_bus_dev_alloc - initialize and allocate mei client device
Tomas Winkler71ce7892015-07-23 15:08:43 +0300765 *
766 * @bus: mei device
767 * @me_cl: me client
768 *
769 * Return: allocated device structur or NULL on allocation failure
770 */
Tomas Winklerae48d742015-09-10 10:18:06 +0300771static struct mei_cl_device *mei_cl_bus_dev_alloc(struct mei_device *bus,
772 struct mei_me_client *me_cl)
Tomas Winkler71ce7892015-07-23 15:08:43 +0300773{
774 struct mei_cl_device *cldev;
775
776 cldev = kzalloc(sizeof(struct mei_cl_device), GFP_KERNEL);
777 if (!cldev)
778 return NULL;
779
780 device_initialize(&cldev->dev);
781 cldev->dev.parent = bus->dev;
782 cldev->dev.bus = &mei_cl_bus_type;
783 cldev->dev.type = &mei_cl_device_type;
784 cldev->bus = mei_dev_bus_get(bus);
785 cldev->me_cl = mei_me_cl_get(me_cl);
Tomas Winkler213dd192015-10-28 14:34:35 +0200786 mei_cl_bus_set_name(cldev);
Tomas Winkler71ce7892015-07-23 15:08:43 +0300787 cldev->is_added = 0;
788 INIT_LIST_HEAD(&cldev->bus_list);
789
790 return cldev;
791}
792
793/**
794 * mei_cl_dev_setup - setup me client device
795 * run fix up routines and set the device name
796 *
797 * @bus: mei device
798 * @cldev: me client device
799 *
800 * Return: true if the device is eligible for enumeration
801 */
Tomas Winklerae48d742015-09-10 10:18:06 +0300802static bool mei_cl_bus_dev_setup(struct mei_device *bus,
803 struct mei_cl_device *cldev)
Tomas Winkler71ce7892015-07-23 15:08:43 +0300804{
805 cldev->do_match = 1;
Tomas Winklerae48d742015-09-10 10:18:06 +0300806 mei_cl_bus_dev_fixup(cldev);
Tomas Winkler71ce7892015-07-23 15:08:43 +0300807
Tomas Winkler213dd192015-10-28 14:34:35 +0200808 /* the device name can change during fix up */
Tomas Winkler71ce7892015-07-23 15:08:43 +0300809 if (cldev->do_match)
Tomas Winkler213dd192015-10-28 14:34:35 +0200810 mei_cl_bus_set_name(cldev);
Tomas Winkler71ce7892015-07-23 15:08:43 +0300811
812 return cldev->do_match == 1;
813}
814
815/**
816 * mei_cl_bus_dev_add - add me client devices
817 *
818 * @cldev: me client device
819 *
820 * Return: 0 on success; < 0 on failre
821 */
822static int mei_cl_bus_dev_add(struct mei_cl_device *cldev)
823{
824 int ret;
825
Tomas Winklerb26864c2015-09-10 10:18:01 +0300826 dev_dbg(cldev->bus->dev, "adding %pUL:%02X\n",
827 mei_me_cl_uuid(cldev->me_cl),
828 mei_me_cl_ver(cldev->me_cl));
Tomas Winkler71ce7892015-07-23 15:08:43 +0300829 ret = device_add(&cldev->dev);
830 if (!ret)
831 cldev->is_added = 1;
832
833 return ret;
834}
835
Tomas Winkler60095952015-07-23 15:08:47 +0300836/**
837 * mei_cl_bus_dev_stop - stop the driver
838 *
839 * @cldev: me client device
840 */
841static void mei_cl_bus_dev_stop(struct mei_cl_device *cldev)
842{
843 if (cldev->is_added)
844 device_release_driver(&cldev->dev);
845}
846
847/**
848 * mei_cl_bus_dev_destroy - destroy me client devices object
849 *
850 * @cldev: me client device
Tomas Winkler2da55cf2015-10-28 14:34:34 +0200851 *
852 * Locking: called under "dev->cl_bus_lock" lock
Tomas Winkler60095952015-07-23 15:08:47 +0300853 */
854static void mei_cl_bus_dev_destroy(struct mei_cl_device *cldev)
855{
Tomas Winkler2da55cf2015-10-28 14:34:34 +0200856
857 WARN_ON(!mutex_is_locked(&cldev->bus->cl_bus_lock));
858
Tomas Winkler60095952015-07-23 15:08:47 +0300859 if (!cldev->is_added)
860 return;
861
862 device_del(&cldev->dev);
863
Tomas Winkler60095952015-07-23 15:08:47 +0300864 list_del_init(&cldev->bus_list);
Tomas Winkler60095952015-07-23 15:08:47 +0300865
866 cldev->is_added = 0;
867 put_device(&cldev->dev);
868}
869
870/**
871 * mei_cl_bus_remove_device - remove a devices form the bus
872 *
873 * @cldev: me client device
874 */
875static void mei_cl_bus_remove_device(struct mei_cl_device *cldev)
876{
877 mei_cl_bus_dev_stop(cldev);
878 mei_cl_bus_dev_destroy(cldev);
879}
880
881/**
882 * mei_cl_bus_remove_devices - remove all devices form the bus
883 *
884 * @bus: mei device
885 */
886void mei_cl_bus_remove_devices(struct mei_device *bus)
887{
888 struct mei_cl_device *cldev, *next;
889
Tomas Winkler2da55cf2015-10-28 14:34:34 +0200890 mutex_lock(&bus->cl_bus_lock);
Tomas Winkler60095952015-07-23 15:08:47 +0300891 list_for_each_entry_safe(cldev, next, &bus->device_list, bus_list)
892 mei_cl_bus_remove_device(cldev);
Tomas Winkler2da55cf2015-10-28 14:34:34 +0200893 mutex_unlock(&bus->cl_bus_lock);
Tomas Winkler60095952015-07-23 15:08:47 +0300894}
895
896
897/**
Tomas Winklerae48d742015-09-10 10:18:06 +0300898 * mei_cl_bus_dev_init - allocate and initializes an mei client devices
Tomas Winkler60095952015-07-23 15:08:47 +0300899 * based on me client
900 *
901 * @bus: mei device
902 * @me_cl: me client
Tomas Winkler2da55cf2015-10-28 14:34:34 +0200903 *
904 * Locking: called under "dev->cl_bus_lock" lock
Tomas Winkler60095952015-07-23 15:08:47 +0300905 */
Tomas Winklerae48d742015-09-10 10:18:06 +0300906static void mei_cl_bus_dev_init(struct mei_device *bus,
907 struct mei_me_client *me_cl)
Samuel Ortize5354102013-03-27 17:29:53 +0200908{
Tomas Winklerb37719c32015-07-23 15:08:33 +0300909 struct mei_cl_device *cldev;
Tomas Winkler60095952015-07-23 15:08:47 +0300910
Tomas Winkler2da55cf2015-10-28 14:34:34 +0200911 WARN_ON(!mutex_is_locked(&bus->cl_bus_lock));
912
Tomas Winkler60095952015-07-23 15:08:47 +0300913 dev_dbg(bus->dev, "initializing %pUl", mei_me_cl_uuid(me_cl));
914
915 if (me_cl->bus_added)
916 return;
Samuel Ortize5354102013-03-27 17:29:53 +0200917
Tomas Winklerae48d742015-09-10 10:18:06 +0300918 cldev = mei_cl_bus_dev_alloc(bus, me_cl);
Tomas Winklerb37719c32015-07-23 15:08:33 +0300919 if (!cldev)
Tomas Winkler60095952015-07-23 15:08:47 +0300920 return;
Samuel Ortize5354102013-03-27 17:29:53 +0200921
Tomas Winkler60095952015-07-23 15:08:47 +0300922 me_cl->bus_added = true;
923 list_add_tail(&cldev->bus_list, &bus->device_list);
Tomas Winklerc93b76b2015-05-07 15:54:02 +0300924
Samuel Ortize5354102013-03-27 17:29:53 +0200925}
Samuel Ortize5354102013-03-27 17:29:53 +0200926
Tomas Winkler60095952015-07-23 15:08:47 +0300927/**
928 * mei_cl_bus_rescan - scan me clients list and add create
929 * devices for eligible clients
930 *
931 * @bus: mei device
932 */
933void mei_cl_bus_rescan(struct mei_device *bus)
Samuel Ortize5354102013-03-27 17:29:53 +0200934{
Tomas Winkler60095952015-07-23 15:08:47 +0300935 struct mei_cl_device *cldev, *n;
936 struct mei_me_client *me_cl;
937
Tomas Winkler2da55cf2015-10-28 14:34:34 +0200938 mutex_lock(&bus->cl_bus_lock);
939
Tomas Winkler60095952015-07-23 15:08:47 +0300940 down_read(&bus->me_clients_rwsem);
941 list_for_each_entry(me_cl, &bus->me_clients, list)
Tomas Winklerae48d742015-09-10 10:18:06 +0300942 mei_cl_bus_dev_init(bus, me_cl);
Tomas Winkler60095952015-07-23 15:08:47 +0300943 up_read(&bus->me_clients_rwsem);
944
Tomas Winkler60095952015-07-23 15:08:47 +0300945 list_for_each_entry_safe(cldev, n, &bus->device_list, bus_list) {
946
947 if (!mei_me_cl_is_active(cldev->me_cl)) {
948 mei_cl_bus_remove_device(cldev);
949 continue;
950 }
951
952 if (cldev->is_added)
953 continue;
954
Tomas Winklerae48d742015-09-10 10:18:06 +0300955 if (mei_cl_bus_dev_setup(bus, cldev))
Tomas Winkler60095952015-07-23 15:08:47 +0300956 mei_cl_bus_dev_add(cldev);
957 else {
958 list_del_init(&cldev->bus_list);
959 put_device(&cldev->dev);
960 }
961 }
962 mutex_unlock(&bus->cl_bus_lock);
963
964 dev_dbg(bus->dev, "rescan end");
Samuel Ortize5354102013-03-27 17:29:53 +0200965}
Samuel Ortiz333e4ee2013-03-27 17:29:54 +0200966
Alexander Usyskina816a002016-02-07 23:35:41 +0200967void mei_cl_bus_rescan_work(struct work_struct *work)
968{
969 struct mei_device *bus =
970 container_of(work, struct mei_device, bus_rescan_work);
Alexander Usyskin025fb792016-02-07 23:35:43 +0200971 struct mei_me_client *me_cl;
972
973 mutex_lock(&bus->device_lock);
974 me_cl = mei_me_cl_by_uuid(bus, &mei_amthif_guid);
975 if (me_cl)
976 mei_amthif_host_init(bus, me_cl);
977 mei_me_cl_put(me_cl);
978 mutex_unlock(&bus->device_lock);
Alexander Usyskina816a002016-02-07 23:35:41 +0200979
980 mei_cl_bus_rescan(bus);
981}
982
Tomas Winklerd49dc5e2015-09-10 10:18:05 +0300983int __mei_cldev_driver_register(struct mei_cl_driver *cldrv,
984 struct module *owner)
Samuel Ortiz333e4ee2013-03-27 17:29:54 +0200985{
986 int err;
987
Tomas Winklerb37719c32015-07-23 15:08:33 +0300988 cldrv->driver.name = cldrv->name;
989 cldrv->driver.owner = owner;
990 cldrv->driver.bus = &mei_cl_bus_type;
Samuel Ortiz333e4ee2013-03-27 17:29:54 +0200991
Tomas Winklerb37719c32015-07-23 15:08:33 +0300992 err = driver_register(&cldrv->driver);
Samuel Ortiz333e4ee2013-03-27 17:29:54 +0200993 if (err)
994 return err;
995
Tomas Winklerb37719c32015-07-23 15:08:33 +0300996 pr_debug("mei: driver [%s] registered\n", cldrv->driver.name);
Samuel Ortiz333e4ee2013-03-27 17:29:54 +0200997
998 return 0;
999}
Tomas Winklerd49dc5e2015-09-10 10:18:05 +03001000EXPORT_SYMBOL_GPL(__mei_cldev_driver_register);
Samuel Ortiz333e4ee2013-03-27 17:29:54 +02001001
Tomas Winklerd49dc5e2015-09-10 10:18:05 +03001002void mei_cldev_driver_unregister(struct mei_cl_driver *cldrv)
Samuel Ortiz333e4ee2013-03-27 17:29:54 +02001003{
Tomas Winklerb37719c32015-07-23 15:08:33 +03001004 driver_unregister(&cldrv->driver);
Samuel Ortiz333e4ee2013-03-27 17:29:54 +02001005
Tomas Winklerb37719c32015-07-23 15:08:33 +03001006 pr_debug("mei: driver [%s] unregistered\n", cldrv->driver.name);
Samuel Ortiz333e4ee2013-03-27 17:29:54 +02001007}
Tomas Winklerd49dc5e2015-09-10 10:18:05 +03001008EXPORT_SYMBOL_GPL(mei_cldev_driver_unregister);
Samuel Ortiz3e833292013-03-27 17:29:55 +02001009
Tomas Winkler60095952015-07-23 15:08:47 +03001010
Samuel Ortizcf3baef2013-03-27 17:29:57 +02001011int __init mei_cl_bus_init(void)
1012{
1013 return bus_register(&mei_cl_bus_type);
1014}
1015
1016void __exit mei_cl_bus_exit(void)
1017{
1018 bus_unregister(&mei_cl_bus_type);
1019}