Samuel Ortiz | e535410 | 2013-03-27 17:29:53 +0200 | [diff] [blame] | 1 | /* |
| 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 Ortiz | 3e83329 | 2013-03-27 17:29:55 +0200 | [diff] [blame] | 19 | #include <linux/sched.h> |
Samuel Ortiz | e535410 | 2013-03-27 17:29:53 +0200 | [diff] [blame] | 20 | #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 Ortiz | e535410 | 2013-03-27 17:29:53 +0200 | [diff] [blame] | 25 | #include <linux/mei_cl_bus.h> |
| 26 | |
| 27 | #include "mei_dev.h" |
Samuel Ortiz | 3e83329 | 2013-03-27 17:29:55 +0200 | [diff] [blame] | 28 | #include "client.h" |
Samuel Ortiz | e535410 | 2013-03-27 17:29:53 +0200 | [diff] [blame] | 29 | |
| 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 Winkler | 6238299 | 2015-07-23 15:08:35 +0300 | [diff] [blame] | 33 | /** |
| 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 | */ |
| 43 | ssize_t __mei_cl_send(struct mei_cl *cl, u8 *buf, size_t length, |
| 44 | bool blocking) |
| 45 | { |
| 46 | struct mei_device *bus; |
Alexander Usyskin | 6cbb097 | 2016-02-10 23:57:26 +0200 | [diff] [blame] | 47 | struct mei_cl_cb *cb; |
Tomas Winkler | 6238299 | 2015-07-23 15:08:35 +0300 | [diff] [blame] | 48 | 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 Usyskin | 15c13df | 2016-02-07 23:35:32 +0200 | [diff] [blame] | 56 | if (bus->dev_state != MEI_DEV_ENABLED) { |
| 57 | rets = -ENODEV; |
| 58 | goto out; |
| 59 | } |
| 60 | |
Tomas Winkler | 6238299 | 2015-07-23 15:08:35 +0300 | [diff] [blame] | 61 | 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 | |
| 87 | out: |
| 88 | mutex_unlock(&bus->device_lock); |
Tomas Winkler | 6238299 | 2015-07-23 15:08:35 +0300 | [diff] [blame] | 89 | |
| 90 | return rets; |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * __mei_cl_recv - internal client receive (read) |
| 95 | * |
| 96 | * @cl: host client |
Tomas Winkler | df7f544 | 2015-10-13 15:02:40 +0300 | [diff] [blame] | 97 | * @buf: buffer to receive |
Tomas Winkler | 6238299 | 2015-07-23 15:08:35 +0300 | [diff] [blame] | 98 | * @length: buffer length |
| 99 | * |
| 100 | * Return: read size in bytes of < 0 on error |
| 101 | */ |
| 102 | ssize_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 Usyskin | 15c13df | 2016-02-07 23:35:32 +0200 | [diff] [blame] | 115 | if (bus->dev_state != MEI_DEV_ENABLED) { |
| 116 | rets = -ENODEV; |
| 117 | goto out; |
| 118 | } |
Tomas Winkler | 6238299 | 2015-07-23 15:08:35 +0300 | [diff] [blame] | 119 | |
| 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 */ |
Alexander Usyskin | 1eb5bd4 | 2016-06-16 17:58:54 +0300 | [diff] [blame] | 129 | /* synchronized under device mutex */ |
| 130 | if (!waitqueue_active(&cl->rx_wait)) { |
Tomas Winkler | 6238299 | 2015-07-23 15:08:35 +0300 | [diff] [blame] | 131 | |
| 132 | mutex_unlock(&bus->device_lock); |
| 133 | |
| 134 | if (wait_event_interruptible(cl->rx_wait, |
| 135 | (!list_empty(&cl->rd_completed)) || |
| 136 | (!mei_cl_is_connected(cl)))) { |
| 137 | |
| 138 | if (signal_pending(current)) |
| 139 | return -EINTR; |
| 140 | return -ERESTARTSYS; |
| 141 | } |
| 142 | |
| 143 | mutex_lock(&bus->device_lock); |
| 144 | |
| 145 | if (!mei_cl_is_connected(cl)) { |
Tomas Winkler | 2d4d548 | 2016-06-23 00:25:31 +0300 | [diff] [blame] | 146 | rets = -ENODEV; |
Tomas Winkler | 6238299 | 2015-07-23 15:08:35 +0300 | [diff] [blame] | 147 | goto out; |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | cb = mei_cl_read_cb(cl, NULL); |
| 152 | if (!cb) { |
| 153 | rets = 0; |
| 154 | goto out; |
| 155 | } |
| 156 | |
| 157 | copy: |
| 158 | if (cb->status) { |
| 159 | rets = cb->status; |
| 160 | goto free; |
| 161 | } |
| 162 | |
| 163 | r_length = min_t(size_t, length, cb->buf_idx); |
| 164 | memcpy(buf, cb->buf.data, r_length); |
| 165 | rets = r_length; |
| 166 | |
| 167 | free: |
| 168 | mei_io_cb_free(cb); |
| 169 | out: |
| 170 | mutex_unlock(&bus->device_lock); |
| 171 | |
| 172 | return rets; |
| 173 | } |
| 174 | |
| 175 | /** |
Tomas Winkler | d49dc5e | 2015-09-10 10:18:05 +0300 | [diff] [blame] | 176 | * mei_cldev_send - me device send (write) |
Tomas Winkler | 6238299 | 2015-07-23 15:08:35 +0300 | [diff] [blame] | 177 | * |
| 178 | * @cldev: me client device |
| 179 | * @buf: buffer to send |
| 180 | * @length: buffer length |
| 181 | * |
| 182 | * Return: written size in bytes or < 0 on error |
| 183 | */ |
Tomas Winkler | d49dc5e | 2015-09-10 10:18:05 +0300 | [diff] [blame] | 184 | ssize_t mei_cldev_send(struct mei_cl_device *cldev, u8 *buf, size_t length) |
Tomas Winkler | 6238299 | 2015-07-23 15:08:35 +0300 | [diff] [blame] | 185 | { |
| 186 | struct mei_cl *cl = cldev->cl; |
| 187 | |
| 188 | if (cl == NULL) |
| 189 | return -ENODEV; |
| 190 | |
| 191 | return __mei_cl_send(cl, buf, length, 1); |
| 192 | } |
Tomas Winkler | d49dc5e | 2015-09-10 10:18:05 +0300 | [diff] [blame] | 193 | EXPORT_SYMBOL_GPL(mei_cldev_send); |
Tomas Winkler | 6238299 | 2015-07-23 15:08:35 +0300 | [diff] [blame] | 194 | |
| 195 | /** |
Tomas Winkler | d49dc5e | 2015-09-10 10:18:05 +0300 | [diff] [blame] | 196 | * mei_cldev_recv - client receive (read) |
Tomas Winkler | 6238299 | 2015-07-23 15:08:35 +0300 | [diff] [blame] | 197 | * |
| 198 | * @cldev: me client device |
Tomas Winkler | df7f544 | 2015-10-13 15:02:40 +0300 | [diff] [blame] | 199 | * @buf: buffer to receive |
Tomas Winkler | 6238299 | 2015-07-23 15:08:35 +0300 | [diff] [blame] | 200 | * @length: buffer length |
| 201 | * |
| 202 | * Return: read size in bytes of < 0 on error |
| 203 | */ |
Tomas Winkler | d49dc5e | 2015-09-10 10:18:05 +0300 | [diff] [blame] | 204 | ssize_t mei_cldev_recv(struct mei_cl_device *cldev, u8 *buf, size_t length) |
Tomas Winkler | 6238299 | 2015-07-23 15:08:35 +0300 | [diff] [blame] | 205 | { |
| 206 | struct mei_cl *cl = cldev->cl; |
| 207 | |
| 208 | if (cl == NULL) |
| 209 | return -ENODEV; |
| 210 | |
| 211 | return __mei_cl_recv(cl, buf, length); |
| 212 | } |
Tomas Winkler | d49dc5e | 2015-09-10 10:18:05 +0300 | [diff] [blame] | 213 | EXPORT_SYMBOL_GPL(mei_cldev_recv); |
Tomas Winkler | 6238299 | 2015-07-23 15:08:35 +0300 | [diff] [blame] | 214 | |
| 215 | /** |
Tomas Winkler | d49dc5e | 2015-09-10 10:18:05 +0300 | [diff] [blame] | 216 | * mei_cl_bus_event_work - dispatch rx event for a bus device |
Tomas Winkler | 6238299 | 2015-07-23 15:08:35 +0300 | [diff] [blame] | 217 | * and schedule new work |
| 218 | * |
| 219 | * @work: work |
| 220 | */ |
Tomas Winkler | d49dc5e | 2015-09-10 10:18:05 +0300 | [diff] [blame] | 221 | static void mei_cl_bus_event_work(struct work_struct *work) |
Tomas Winkler | 6238299 | 2015-07-23 15:08:35 +0300 | [diff] [blame] | 222 | { |
| 223 | struct mei_cl_device *cldev; |
Alexander Usyskin | bc46b45 | 2016-05-03 18:54:21 -0400 | [diff] [blame] | 224 | struct mei_device *bus; |
Tomas Winkler | 6238299 | 2015-07-23 15:08:35 +0300 | [diff] [blame] | 225 | |
| 226 | cldev = container_of(work, struct mei_cl_device, event_work); |
| 227 | |
Alexander Usyskin | bc46b45 | 2016-05-03 18:54:21 -0400 | [diff] [blame] | 228 | bus = cldev->bus; |
| 229 | |
Tomas Winkler | 6238299 | 2015-07-23 15:08:35 +0300 | [diff] [blame] | 230 | if (cldev->event_cb) |
Tomas Winkler | 1e4edb3 | 2016-10-19 16:33:31 +0300 | [diff] [blame^] | 231 | cldev->event_cb(cldev, cldev->events); |
Tomas Winkler | 6238299 | 2015-07-23 15:08:35 +0300 | [diff] [blame] | 232 | |
| 233 | cldev->events = 0; |
| 234 | |
| 235 | /* Prepare for the next read */ |
Alexander Usyskin | bc46b45 | 2016-05-03 18:54:21 -0400 | [diff] [blame] | 236 | if (cldev->events_mask & BIT(MEI_CL_EVENT_RX)) { |
| 237 | mutex_lock(&bus->device_lock); |
Tomas Winkler | 3030dc0 | 2016-07-26 01:06:05 +0300 | [diff] [blame] | 238 | mei_cl_read_start(cldev->cl, mei_cl_mtu(cldev->cl), NULL); |
Alexander Usyskin | bc46b45 | 2016-05-03 18:54:21 -0400 | [diff] [blame] | 239 | mutex_unlock(&bus->device_lock); |
| 240 | } |
Alexander Usyskin | bb2ef9c | 2015-07-26 09:54:23 +0300 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | /** |
| 244 | * mei_cl_bus_notify_event - schedule notify cb on bus client |
| 245 | * |
| 246 | * @cl: host client |
Tomas Winkler | 850f894 | 2016-02-07 23:35:31 +0200 | [diff] [blame] | 247 | * |
| 248 | * Return: true if event was scheduled |
| 249 | * false if the client is not waiting for event |
Alexander Usyskin | bb2ef9c | 2015-07-26 09:54:23 +0300 | [diff] [blame] | 250 | */ |
Tomas Winkler | 850f894 | 2016-02-07 23:35:31 +0200 | [diff] [blame] | 251 | bool mei_cl_bus_notify_event(struct mei_cl *cl) |
Alexander Usyskin | bb2ef9c | 2015-07-26 09:54:23 +0300 | [diff] [blame] | 252 | { |
| 253 | struct mei_cl_device *cldev = cl->cldev; |
| 254 | |
| 255 | if (!cldev || !cldev->event_cb) |
Tomas Winkler | 850f894 | 2016-02-07 23:35:31 +0200 | [diff] [blame] | 256 | return false; |
Alexander Usyskin | bb2ef9c | 2015-07-26 09:54:23 +0300 | [diff] [blame] | 257 | |
| 258 | if (!(cldev->events_mask & BIT(MEI_CL_EVENT_NOTIF))) |
Tomas Winkler | 850f894 | 2016-02-07 23:35:31 +0200 | [diff] [blame] | 259 | return false; |
Alexander Usyskin | bb2ef9c | 2015-07-26 09:54:23 +0300 | [diff] [blame] | 260 | |
| 261 | if (!cl->notify_ev) |
Tomas Winkler | 850f894 | 2016-02-07 23:35:31 +0200 | [diff] [blame] | 262 | return false; |
Alexander Usyskin | bb2ef9c | 2015-07-26 09:54:23 +0300 | [diff] [blame] | 263 | |
| 264 | set_bit(MEI_CL_EVENT_NOTIF, &cldev->events); |
| 265 | |
| 266 | schedule_work(&cldev->event_work); |
| 267 | |
| 268 | cl->notify_ev = false; |
Tomas Winkler | 850f894 | 2016-02-07 23:35:31 +0200 | [diff] [blame] | 269 | |
| 270 | return true; |
Tomas Winkler | 6238299 | 2015-07-23 15:08:35 +0300 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | /** |
Tomas Winkler | a1f9ae2 | 2016-02-07 23:35:30 +0200 | [diff] [blame] | 274 | * mei_cl_bus_rx_event - schedule rx event |
Tomas Winkler | 6238299 | 2015-07-23 15:08:35 +0300 | [diff] [blame] | 275 | * |
| 276 | * @cl: host client |
Tomas Winkler | a1f9ae2 | 2016-02-07 23:35:30 +0200 | [diff] [blame] | 277 | * |
| 278 | * Return: true if event was scheduled |
| 279 | * false if the client is not waiting for event |
Tomas Winkler | 6238299 | 2015-07-23 15:08:35 +0300 | [diff] [blame] | 280 | */ |
Tomas Winkler | a1f9ae2 | 2016-02-07 23:35:30 +0200 | [diff] [blame] | 281 | bool mei_cl_bus_rx_event(struct mei_cl *cl) |
Tomas Winkler | 6238299 | 2015-07-23 15:08:35 +0300 | [diff] [blame] | 282 | { |
| 283 | struct mei_cl_device *cldev = cl->cldev; |
| 284 | |
| 285 | if (!cldev || !cldev->event_cb) |
Tomas Winkler | a1f9ae2 | 2016-02-07 23:35:30 +0200 | [diff] [blame] | 286 | return false; |
Tomas Winkler | 6238299 | 2015-07-23 15:08:35 +0300 | [diff] [blame] | 287 | |
Alexander Usyskin | bb2ef9c | 2015-07-26 09:54:23 +0300 | [diff] [blame] | 288 | if (!(cldev->events_mask & BIT(MEI_CL_EVENT_RX))) |
Tomas Winkler | a1f9ae2 | 2016-02-07 23:35:30 +0200 | [diff] [blame] | 289 | return false; |
Alexander Usyskin | bb2ef9c | 2015-07-26 09:54:23 +0300 | [diff] [blame] | 290 | |
Tomas Winkler | 6238299 | 2015-07-23 15:08:35 +0300 | [diff] [blame] | 291 | set_bit(MEI_CL_EVENT_RX, &cldev->events); |
| 292 | |
| 293 | schedule_work(&cldev->event_work); |
Tomas Winkler | a1f9ae2 | 2016-02-07 23:35:30 +0200 | [diff] [blame] | 294 | |
| 295 | return true; |
Tomas Winkler | 6238299 | 2015-07-23 15:08:35 +0300 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | /** |
Tomas Winkler | d49dc5e | 2015-09-10 10:18:05 +0300 | [diff] [blame] | 299 | * mei_cldev_register_event_cb - register event callback |
Tomas Winkler | 6238299 | 2015-07-23 15:08:35 +0300 | [diff] [blame] | 300 | * |
| 301 | * @cldev: me client devices |
| 302 | * @event_cb: callback function |
Alexander Usyskin | bb2ef9c | 2015-07-26 09:54:23 +0300 | [diff] [blame] | 303 | * @events_mask: requested events bitmask |
Tomas Winkler | 6238299 | 2015-07-23 15:08:35 +0300 | [diff] [blame] | 304 | * |
| 305 | * Return: 0 on success |
| 306 | * -EALREADY if an callback is already registered |
| 307 | * <0 on other errors |
| 308 | */ |
Tomas Winkler | d49dc5e | 2015-09-10 10:18:05 +0300 | [diff] [blame] | 309 | int mei_cldev_register_event_cb(struct mei_cl_device *cldev, |
| 310 | unsigned long events_mask, |
Tomas Winkler | 1e4edb3 | 2016-10-19 16:33:31 +0300 | [diff] [blame^] | 311 | mei_cldev_event_cb_t event_cb) |
Tomas Winkler | 6238299 | 2015-07-23 15:08:35 +0300 | [diff] [blame] | 312 | { |
Alexander Usyskin | bc46b45 | 2016-05-03 18:54:21 -0400 | [diff] [blame] | 313 | struct mei_device *bus = cldev->bus; |
Tomas Winkler | 48168f4 | 2015-07-23 15:08:38 +0300 | [diff] [blame] | 314 | int ret; |
| 315 | |
Tomas Winkler | 6238299 | 2015-07-23 15:08:35 +0300 | [diff] [blame] | 316 | if (cldev->event_cb) |
| 317 | return -EALREADY; |
| 318 | |
| 319 | cldev->events = 0; |
Alexander Usyskin | bb2ef9c | 2015-07-26 09:54:23 +0300 | [diff] [blame] | 320 | cldev->events_mask = events_mask; |
Tomas Winkler | 6238299 | 2015-07-23 15:08:35 +0300 | [diff] [blame] | 321 | cldev->event_cb = event_cb; |
Tomas Winkler | d49dc5e | 2015-09-10 10:18:05 +0300 | [diff] [blame] | 322 | INIT_WORK(&cldev->event_work, mei_cl_bus_event_work); |
Tomas Winkler | 6238299 | 2015-07-23 15:08:35 +0300 | [diff] [blame] | 323 | |
Alexander Usyskin | bb2ef9c | 2015-07-26 09:54:23 +0300 | [diff] [blame] | 324 | if (cldev->events_mask & BIT(MEI_CL_EVENT_RX)) { |
Alexander Usyskin | bc46b45 | 2016-05-03 18:54:21 -0400 | [diff] [blame] | 325 | mutex_lock(&bus->device_lock); |
Tomas Winkler | 3030dc0 | 2016-07-26 01:06:05 +0300 | [diff] [blame] | 326 | ret = mei_cl_read_start(cldev->cl, mei_cl_mtu(cldev->cl), NULL); |
Alexander Usyskin | bc46b45 | 2016-05-03 18:54:21 -0400 | [diff] [blame] | 327 | mutex_unlock(&bus->device_lock); |
Alexander Usyskin | bb2ef9c | 2015-07-26 09:54:23 +0300 | [diff] [blame] | 328 | if (ret && ret != -EBUSY) |
| 329 | return ret; |
| 330 | } |
| 331 | |
| 332 | if (cldev->events_mask & BIT(MEI_CL_EVENT_NOTIF)) { |
Alexander Usyskin | bc46b45 | 2016-05-03 18:54:21 -0400 | [diff] [blame] | 333 | mutex_lock(&bus->device_lock); |
Alexander Usyskin | bb2ef9c | 2015-07-26 09:54:23 +0300 | [diff] [blame] | 334 | ret = mei_cl_notify_request(cldev->cl, NULL, event_cb ? 1 : 0); |
Alexander Usyskin | bc46b45 | 2016-05-03 18:54:21 -0400 | [diff] [blame] | 335 | mutex_unlock(&bus->device_lock); |
Alexander Usyskin | bb2ef9c | 2015-07-26 09:54:23 +0300 | [diff] [blame] | 336 | if (ret) |
| 337 | return ret; |
| 338 | } |
Tomas Winkler | 6238299 | 2015-07-23 15:08:35 +0300 | [diff] [blame] | 339 | |
| 340 | return 0; |
| 341 | } |
Tomas Winkler | d49dc5e | 2015-09-10 10:18:05 +0300 | [diff] [blame] | 342 | EXPORT_SYMBOL_GPL(mei_cldev_register_event_cb); |
Tomas Winkler | 6238299 | 2015-07-23 15:08:35 +0300 | [diff] [blame] | 343 | |
| 344 | /** |
Tomas Winkler | d49dc5e | 2015-09-10 10:18:05 +0300 | [diff] [blame] | 345 | * mei_cldev_get_drvdata - driver data getter |
Tomas Winkler | 6238299 | 2015-07-23 15:08:35 +0300 | [diff] [blame] | 346 | * |
| 347 | * @cldev: mei client device |
| 348 | * |
| 349 | * Return: driver private data |
| 350 | */ |
Tomas Winkler | d49dc5e | 2015-09-10 10:18:05 +0300 | [diff] [blame] | 351 | void *mei_cldev_get_drvdata(const struct mei_cl_device *cldev) |
Tomas Winkler | 6238299 | 2015-07-23 15:08:35 +0300 | [diff] [blame] | 352 | { |
| 353 | return dev_get_drvdata(&cldev->dev); |
| 354 | } |
Tomas Winkler | d49dc5e | 2015-09-10 10:18:05 +0300 | [diff] [blame] | 355 | EXPORT_SYMBOL_GPL(mei_cldev_get_drvdata); |
Tomas Winkler | 6238299 | 2015-07-23 15:08:35 +0300 | [diff] [blame] | 356 | |
| 357 | /** |
Tomas Winkler | d49dc5e | 2015-09-10 10:18:05 +0300 | [diff] [blame] | 358 | * mei_cldev_set_drvdata - driver data setter |
Tomas Winkler | 6238299 | 2015-07-23 15:08:35 +0300 | [diff] [blame] | 359 | * |
| 360 | * @cldev: mei client device |
| 361 | * @data: data to store |
| 362 | */ |
Tomas Winkler | d49dc5e | 2015-09-10 10:18:05 +0300 | [diff] [blame] | 363 | void mei_cldev_set_drvdata(struct mei_cl_device *cldev, void *data) |
Tomas Winkler | 6238299 | 2015-07-23 15:08:35 +0300 | [diff] [blame] | 364 | { |
| 365 | dev_set_drvdata(&cldev->dev, data); |
| 366 | } |
Tomas Winkler | d49dc5e | 2015-09-10 10:18:05 +0300 | [diff] [blame] | 367 | EXPORT_SYMBOL_GPL(mei_cldev_set_drvdata); |
Tomas Winkler | 6238299 | 2015-07-23 15:08:35 +0300 | [diff] [blame] | 368 | |
| 369 | /** |
Tomas Winkler | baeacd0 | 2015-09-10 10:18:02 +0300 | [diff] [blame] | 370 | * mei_cldev_uuid - return uuid of the underlying me client |
| 371 | * |
| 372 | * @cldev: mei client device |
| 373 | * |
| 374 | * Return: me client uuid |
| 375 | */ |
| 376 | const uuid_le *mei_cldev_uuid(const struct mei_cl_device *cldev) |
| 377 | { |
| 378 | return mei_me_cl_uuid(cldev->me_cl); |
| 379 | } |
| 380 | EXPORT_SYMBOL_GPL(mei_cldev_uuid); |
| 381 | |
| 382 | /** |
| 383 | * mei_cldev_ver - return protocol version of the underlying me client |
| 384 | * |
| 385 | * @cldev: mei client device |
| 386 | * |
| 387 | * Return: me client protocol version |
| 388 | */ |
| 389 | u8 mei_cldev_ver(const struct mei_cl_device *cldev) |
| 390 | { |
| 391 | return mei_me_cl_ver(cldev->me_cl); |
| 392 | } |
| 393 | EXPORT_SYMBOL_GPL(mei_cldev_ver); |
| 394 | |
| 395 | /** |
Tomas Winkler | 01a14ed | 2015-09-10 10:18:03 +0300 | [diff] [blame] | 396 | * mei_cldev_enabled - check whether the device is enabled |
| 397 | * |
| 398 | * @cldev: mei client device |
| 399 | * |
| 400 | * Return: true if me client is initialized and connected |
| 401 | */ |
| 402 | bool mei_cldev_enabled(struct mei_cl_device *cldev) |
| 403 | { |
| 404 | return cldev->cl && mei_cl_is_connected(cldev->cl); |
| 405 | } |
| 406 | EXPORT_SYMBOL_GPL(mei_cldev_enabled); |
| 407 | |
| 408 | /** |
Tomas Winkler | d49dc5e | 2015-09-10 10:18:05 +0300 | [diff] [blame] | 409 | * mei_cldev_enable_device - enable me client device |
Tomas Winkler | 6238299 | 2015-07-23 15:08:35 +0300 | [diff] [blame] | 410 | * create connection with me client |
| 411 | * |
| 412 | * @cldev: me client device |
| 413 | * |
| 414 | * Return: 0 on success and < 0 on error |
| 415 | */ |
Tomas Winkler | d49dc5e | 2015-09-10 10:18:05 +0300 | [diff] [blame] | 416 | int mei_cldev_enable(struct mei_cl_device *cldev) |
Tomas Winkler | 6238299 | 2015-07-23 15:08:35 +0300 | [diff] [blame] | 417 | { |
Tomas Winkler | 6009595 | 2015-07-23 15:08:47 +0300 | [diff] [blame] | 418 | struct mei_device *bus = cldev->bus; |
| 419 | struct mei_cl *cl; |
| 420 | int ret; |
Tomas Winkler | 6238299 | 2015-07-23 15:08:35 +0300 | [diff] [blame] | 421 | |
Tomas Winkler | 6009595 | 2015-07-23 15:08:47 +0300 | [diff] [blame] | 422 | cl = cldev->cl; |
Tomas Winkler | 6238299 | 2015-07-23 15:08:35 +0300 | [diff] [blame] | 423 | |
Tomas Winkler | 6009595 | 2015-07-23 15:08:47 +0300 | [diff] [blame] | 424 | if (!cl) { |
| 425 | mutex_lock(&bus->device_lock); |
Alexander Usyskin | 7851e00 | 2016-02-07 23:35:40 +0200 | [diff] [blame] | 426 | cl = mei_cl_alloc_linked(bus); |
Tomas Winkler | 6009595 | 2015-07-23 15:08:47 +0300 | [diff] [blame] | 427 | mutex_unlock(&bus->device_lock); |
| 428 | if (IS_ERR(cl)) |
| 429 | return PTR_ERR(cl); |
| 430 | /* update pointers */ |
| 431 | cldev->cl = cl; |
| 432 | cl->cldev = cldev; |
| 433 | } |
Tomas Winkler | 6238299 | 2015-07-23 15:08:35 +0300 | [diff] [blame] | 434 | |
| 435 | mutex_lock(&bus->device_lock); |
Tomas Winkler | 6238299 | 2015-07-23 15:08:35 +0300 | [diff] [blame] | 436 | if (mei_cl_is_connected(cl)) { |
Tomas Winkler | 6009595 | 2015-07-23 15:08:47 +0300 | [diff] [blame] | 437 | ret = 0; |
| 438 | goto out; |
Tomas Winkler | 6238299 | 2015-07-23 15:08:35 +0300 | [diff] [blame] | 439 | } |
| 440 | |
Tomas Winkler | 6009595 | 2015-07-23 15:08:47 +0300 | [diff] [blame] | 441 | if (!mei_me_cl_is_active(cldev->me_cl)) { |
| 442 | dev_err(&cldev->dev, "me client is not active\n"); |
| 443 | ret = -ENOTTY; |
| 444 | goto out; |
Tomas Winkler | 6238299 | 2015-07-23 15:08:35 +0300 | [diff] [blame] | 445 | } |
| 446 | |
Tomas Winkler | 6009595 | 2015-07-23 15:08:47 +0300 | [diff] [blame] | 447 | ret = mei_cl_connect(cl, cldev->me_cl, NULL); |
| 448 | if (ret < 0) |
| 449 | dev_err(&cldev->dev, "cannot connect\n"); |
| 450 | |
| 451 | out: |
Tomas Winkler | 6238299 | 2015-07-23 15:08:35 +0300 | [diff] [blame] | 452 | mutex_unlock(&bus->device_lock); |
| 453 | |
Tomas Winkler | 6009595 | 2015-07-23 15:08:47 +0300 | [diff] [blame] | 454 | return ret; |
Tomas Winkler | 6238299 | 2015-07-23 15:08:35 +0300 | [diff] [blame] | 455 | } |
Tomas Winkler | d49dc5e | 2015-09-10 10:18:05 +0300 | [diff] [blame] | 456 | EXPORT_SYMBOL_GPL(mei_cldev_enable); |
Tomas Winkler | 6238299 | 2015-07-23 15:08:35 +0300 | [diff] [blame] | 457 | |
| 458 | /** |
Tomas Winkler | d49dc5e | 2015-09-10 10:18:05 +0300 | [diff] [blame] | 459 | * mei_cldev_disable - disable me client device |
Tomas Winkler | 6238299 | 2015-07-23 15:08:35 +0300 | [diff] [blame] | 460 | * disconnect form the me client |
| 461 | * |
| 462 | * @cldev: me client device |
| 463 | * |
| 464 | * Return: 0 on success and < 0 on error |
| 465 | */ |
Tomas Winkler | d49dc5e | 2015-09-10 10:18:05 +0300 | [diff] [blame] | 466 | int mei_cldev_disable(struct mei_cl_device *cldev) |
Tomas Winkler | 6238299 | 2015-07-23 15:08:35 +0300 | [diff] [blame] | 467 | { |
Tomas Winkler | 6238299 | 2015-07-23 15:08:35 +0300 | [diff] [blame] | 468 | struct mei_device *bus; |
Tomas Winkler | 6009595 | 2015-07-23 15:08:47 +0300 | [diff] [blame] | 469 | struct mei_cl *cl; |
| 470 | int err; |
Tomas Winkler | 6238299 | 2015-07-23 15:08:35 +0300 | [diff] [blame] | 471 | |
Tomas Winkler | 6009595 | 2015-07-23 15:08:47 +0300 | [diff] [blame] | 472 | if (!cldev || !cldev->cl) |
Tomas Winkler | 6238299 | 2015-07-23 15:08:35 +0300 | [diff] [blame] | 473 | return -ENODEV; |
| 474 | |
Tomas Winkler | 6009595 | 2015-07-23 15:08:47 +0300 | [diff] [blame] | 475 | cl = cldev->cl; |
| 476 | |
| 477 | bus = cldev->bus; |
Tomas Winkler | 6238299 | 2015-07-23 15:08:35 +0300 | [diff] [blame] | 478 | |
| 479 | cldev->event_cb = NULL; |
| 480 | |
| 481 | mutex_lock(&bus->device_lock); |
| 482 | |
| 483 | if (!mei_cl_is_connected(cl)) { |
| 484 | dev_err(bus->dev, "Already disconnected"); |
| 485 | err = 0; |
| 486 | goto out; |
| 487 | } |
| 488 | |
| 489 | err = mei_cl_disconnect(cl); |
Tomas Winkler | 6009595 | 2015-07-23 15:08:47 +0300 | [diff] [blame] | 490 | if (err < 0) |
Tomas Winkler | 6238299 | 2015-07-23 15:08:35 +0300 | [diff] [blame] | 491 | dev_err(bus->dev, "Could not disconnect from the ME client"); |
Tomas Winkler | 6238299 | 2015-07-23 15:08:35 +0300 | [diff] [blame] | 492 | |
| 493 | out: |
Tomas Winkler | 6009595 | 2015-07-23 15:08:47 +0300 | [diff] [blame] | 494 | /* Flush queues and remove any pending read */ |
| 495 | mei_cl_flush_queues(cl, NULL); |
| 496 | mei_cl_unlink(cl); |
| 497 | |
| 498 | kfree(cl); |
| 499 | cldev->cl = NULL; |
| 500 | |
Tomas Winkler | 6238299 | 2015-07-23 15:08:35 +0300 | [diff] [blame] | 501 | mutex_unlock(&bus->device_lock); |
| 502 | return err; |
Tomas Winkler | 6238299 | 2015-07-23 15:08:35 +0300 | [diff] [blame] | 503 | } |
Tomas Winkler | d49dc5e | 2015-09-10 10:18:05 +0300 | [diff] [blame] | 504 | EXPORT_SYMBOL_GPL(mei_cldev_disable); |
Tomas Winkler | 6238299 | 2015-07-23 15:08:35 +0300 | [diff] [blame] | 505 | |
Tomas Winkler | 688a9cc | 2015-07-23 15:08:39 +0300 | [diff] [blame] | 506 | /** |
| 507 | * mei_cl_device_find - find matching entry in the driver id table |
| 508 | * |
| 509 | * @cldev: me client device |
| 510 | * @cldrv: me client driver |
| 511 | * |
| 512 | * Return: id on success; NULL if no id is matching |
| 513 | */ |
| 514 | static const |
| 515 | struct mei_cl_device_id *mei_cl_device_find(struct mei_cl_device *cldev, |
| 516 | struct mei_cl_driver *cldrv) |
Samuel Ortiz | e535410 | 2013-03-27 17:29:53 +0200 | [diff] [blame] | 517 | { |
Samuel Ortiz | e535410 | 2013-03-27 17:29:53 +0200 | [diff] [blame] | 518 | const struct mei_cl_device_id *id; |
Tomas Winkler | c93b76b | 2015-05-07 15:54:02 +0300 | [diff] [blame] | 519 | const uuid_le *uuid; |
Tomas Winkler | b26864c | 2015-09-10 10:18:01 +0300 | [diff] [blame] | 520 | u8 version; |
| 521 | bool match; |
Samuel Ortiz | e535410 | 2013-03-27 17:29:53 +0200 | [diff] [blame] | 522 | |
Tomas Winkler | b37719c3 | 2015-07-23 15:08:33 +0300 | [diff] [blame] | 523 | uuid = mei_me_cl_uuid(cldev->me_cl); |
Tomas Winkler | b26864c | 2015-09-10 10:18:01 +0300 | [diff] [blame] | 524 | version = mei_me_cl_ver(cldev->me_cl); |
Samuel Ortiz | e535410 | 2013-03-27 17:29:53 +0200 | [diff] [blame] | 525 | |
Tomas Winkler | b37719c3 | 2015-07-23 15:08:33 +0300 | [diff] [blame] | 526 | id = cldrv->id_table; |
Greg Kroah-Hartman | b144ce2 | 2015-05-27 17:17:27 -0700 | [diff] [blame] | 527 | while (uuid_le_cmp(NULL_UUID_LE, id->uuid)) { |
Greg Kroah-Hartman | b144ce2 | 2015-05-27 17:17:27 -0700 | [diff] [blame] | 528 | if (!uuid_le_cmp(*uuid, id->uuid)) { |
Tomas Winkler | b26864c | 2015-09-10 10:18:01 +0300 | [diff] [blame] | 529 | match = true; |
Tomas Winkler | 688a9cc | 2015-07-23 15:08:39 +0300 | [diff] [blame] | 530 | |
Tomas Winkler | b26864c | 2015-09-10 10:18:01 +0300 | [diff] [blame] | 531 | if (cldev->name[0]) |
| 532 | if (strncmp(cldev->name, id->name, |
| 533 | sizeof(id->name))) |
| 534 | match = false; |
Tomas Winkler | 688a9cc | 2015-07-23 15:08:39 +0300 | [diff] [blame] | 535 | |
Tomas Winkler | b26864c | 2015-09-10 10:18:01 +0300 | [diff] [blame] | 536 | if (id->version != MEI_CL_VERSION_ANY) |
| 537 | if (id->version != version) |
| 538 | match = false; |
| 539 | if (match) |
Tomas Winkler | 688a9cc | 2015-07-23 15:08:39 +0300 | [diff] [blame] | 540 | return id; |
Tomas Winkler | c93b76b | 2015-05-07 15:54:02 +0300 | [diff] [blame] | 541 | } |
Samuel Ortiz | e535410 | 2013-03-27 17:29:53 +0200 | [diff] [blame] | 542 | |
| 543 | id++; |
| 544 | } |
| 545 | |
Tomas Winkler | 688a9cc | 2015-07-23 15:08:39 +0300 | [diff] [blame] | 546 | return NULL; |
| 547 | } |
| 548 | |
| 549 | /** |
| 550 | * mei_cl_device_match - device match function |
| 551 | * |
| 552 | * @dev: device |
| 553 | * @drv: driver |
| 554 | * |
| 555 | * Return: 1 if matching device was found 0 otherwise |
| 556 | */ |
| 557 | static int mei_cl_device_match(struct device *dev, struct device_driver *drv) |
| 558 | { |
| 559 | struct mei_cl_device *cldev = to_mei_cl_device(dev); |
| 560 | struct mei_cl_driver *cldrv = to_mei_cl_driver(drv); |
| 561 | const struct mei_cl_device_id *found_id; |
| 562 | |
| 563 | if (!cldev) |
| 564 | return 0; |
| 565 | |
Tomas Winkler | 71ce789 | 2015-07-23 15:08:43 +0300 | [diff] [blame] | 566 | if (!cldev->do_match) |
| 567 | return 0; |
| 568 | |
Tomas Winkler | 688a9cc | 2015-07-23 15:08:39 +0300 | [diff] [blame] | 569 | if (!cldrv || !cldrv->id_table) |
| 570 | return 0; |
| 571 | |
| 572 | found_id = mei_cl_device_find(cldev, cldrv); |
| 573 | if (found_id) |
| 574 | return 1; |
| 575 | |
Samuel Ortiz | e535410 | 2013-03-27 17:29:53 +0200 | [diff] [blame] | 576 | return 0; |
| 577 | } |
| 578 | |
Tomas Winkler | feb8cd0 | 2015-07-23 15:08:40 +0300 | [diff] [blame] | 579 | /** |
| 580 | * mei_cl_device_probe - bus probe function |
| 581 | * |
| 582 | * @dev: device |
| 583 | * |
| 584 | * Return: 0 on success; < 0 otherwise |
| 585 | */ |
Samuel Ortiz | e535410 | 2013-03-27 17:29:53 +0200 | [diff] [blame] | 586 | static int mei_cl_device_probe(struct device *dev) |
| 587 | { |
Tomas Winkler | feb8cd0 | 2015-07-23 15:08:40 +0300 | [diff] [blame] | 588 | struct mei_cl_device *cldev; |
Tomas Winkler | b37719c3 | 2015-07-23 15:08:33 +0300 | [diff] [blame] | 589 | struct mei_cl_driver *cldrv; |
Tomas Winkler | feb8cd0 | 2015-07-23 15:08:40 +0300 | [diff] [blame] | 590 | const struct mei_cl_device_id *id; |
Alexey Khoroshilov | b9c7954 | 2016-04-01 23:53:01 +0300 | [diff] [blame] | 591 | int ret; |
Tomas Winkler | feb8cd0 | 2015-07-23 15:08:40 +0300 | [diff] [blame] | 592 | |
| 593 | cldev = to_mei_cl_device(dev); |
| 594 | cldrv = to_mei_cl_driver(dev->driver); |
Samuel Ortiz | e535410 | 2013-03-27 17:29:53 +0200 | [diff] [blame] | 595 | |
Tomas Winkler | b37719c3 | 2015-07-23 15:08:33 +0300 | [diff] [blame] | 596 | if (!cldev) |
Samuel Ortiz | e535410 | 2013-03-27 17:29:53 +0200 | [diff] [blame] | 597 | return 0; |
| 598 | |
Tomas Winkler | b37719c3 | 2015-07-23 15:08:33 +0300 | [diff] [blame] | 599 | if (!cldrv || !cldrv->probe) |
Samuel Ortiz | e535410 | 2013-03-27 17:29:53 +0200 | [diff] [blame] | 600 | return -ENODEV; |
| 601 | |
Tomas Winkler | feb8cd0 | 2015-07-23 15:08:40 +0300 | [diff] [blame] | 602 | id = mei_cl_device_find(cldev, cldrv); |
| 603 | if (!id) |
| 604 | return -ENODEV; |
Samuel Ortiz | e535410 | 2013-03-27 17:29:53 +0200 | [diff] [blame] | 605 | |
Alexey Khoroshilov | b9c7954 | 2016-04-01 23:53:01 +0300 | [diff] [blame] | 606 | ret = cldrv->probe(cldev, id); |
| 607 | if (ret) |
| 608 | return ret; |
Samuel Ortiz | e535410 | 2013-03-27 17:29:53 +0200 | [diff] [blame] | 609 | |
Alexey Khoroshilov | b9c7954 | 2016-04-01 23:53:01 +0300 | [diff] [blame] | 610 | __module_get(THIS_MODULE); |
| 611 | return 0; |
Samuel Ortiz | e535410 | 2013-03-27 17:29:53 +0200 | [diff] [blame] | 612 | } |
| 613 | |
Tomas Winkler | feb8cd0 | 2015-07-23 15:08:40 +0300 | [diff] [blame] | 614 | /** |
| 615 | * mei_cl_device_remove - remove device from the bus |
| 616 | * |
| 617 | * @dev: device |
| 618 | * |
| 619 | * Return: 0 on success; < 0 otherwise |
| 620 | */ |
Samuel Ortiz | e535410 | 2013-03-27 17:29:53 +0200 | [diff] [blame] | 621 | static int mei_cl_device_remove(struct device *dev) |
| 622 | { |
Tomas Winkler | b37719c3 | 2015-07-23 15:08:33 +0300 | [diff] [blame] | 623 | struct mei_cl_device *cldev = to_mei_cl_device(dev); |
| 624 | struct mei_cl_driver *cldrv; |
Tomas Winkler | feb8cd0 | 2015-07-23 15:08:40 +0300 | [diff] [blame] | 625 | int ret = 0; |
Samuel Ortiz | e535410 | 2013-03-27 17:29:53 +0200 | [diff] [blame] | 626 | |
Tomas Winkler | b37719c3 | 2015-07-23 15:08:33 +0300 | [diff] [blame] | 627 | if (!cldev || !dev->driver) |
Samuel Ortiz | e535410 | 2013-03-27 17:29:53 +0200 | [diff] [blame] | 628 | return 0; |
| 629 | |
Tomas Winkler | b37719c3 | 2015-07-23 15:08:33 +0300 | [diff] [blame] | 630 | if (cldev->event_cb) { |
| 631 | cldev->event_cb = NULL; |
| 632 | cancel_work_sync(&cldev->event_work); |
Samuel Ortiz | 3e83329 | 2013-03-27 17:29:55 +0200 | [diff] [blame] | 633 | } |
| 634 | |
Tomas Winkler | b37719c3 | 2015-07-23 15:08:33 +0300 | [diff] [blame] | 635 | cldrv = to_mei_cl_driver(dev->driver); |
Tomas Winkler | feb8cd0 | 2015-07-23 15:08:40 +0300 | [diff] [blame] | 636 | if (cldrv->remove) |
| 637 | ret = cldrv->remove(cldev); |
Samuel Ortiz | e535410 | 2013-03-27 17:29:53 +0200 | [diff] [blame] | 638 | |
Tomas Winkler | feb8cd0 | 2015-07-23 15:08:40 +0300 | [diff] [blame] | 639 | module_put(THIS_MODULE); |
| 640 | dev->driver = NULL; |
| 641 | return ret; |
Samuel Ortiz | e535410 | 2013-03-27 17:29:53 +0200 | [diff] [blame] | 642 | |
Samuel Ortiz | e535410 | 2013-03-27 17:29:53 +0200 | [diff] [blame] | 643 | } |
| 644 | |
Tomas Winkler | 007d64e | 2015-05-07 15:54:03 +0300 | [diff] [blame] | 645 | static ssize_t name_show(struct device *dev, struct device_attribute *a, |
| 646 | char *buf) |
| 647 | { |
Tomas Winkler | b37719c3 | 2015-07-23 15:08:33 +0300 | [diff] [blame] | 648 | struct mei_cl_device *cldev = to_mei_cl_device(dev); |
Tomas Winkler | 007d64e | 2015-05-07 15:54:03 +0300 | [diff] [blame] | 649 | |
Rasmus Villemoes | 423de92 | 2016-03-24 10:38:04 +0200 | [diff] [blame] | 650 | return scnprintf(buf, PAGE_SIZE, "%s", cldev->name); |
Tomas Winkler | 007d64e | 2015-05-07 15:54:03 +0300 | [diff] [blame] | 651 | } |
| 652 | static DEVICE_ATTR_RO(name); |
| 653 | |
| 654 | static ssize_t uuid_show(struct device *dev, struct device_attribute *a, |
| 655 | char *buf) |
| 656 | { |
Tomas Winkler | b37719c3 | 2015-07-23 15:08:33 +0300 | [diff] [blame] | 657 | struct mei_cl_device *cldev = to_mei_cl_device(dev); |
| 658 | const uuid_le *uuid = mei_me_cl_uuid(cldev->me_cl); |
Tomas Winkler | 007d64e | 2015-05-07 15:54:03 +0300 | [diff] [blame] | 659 | |
Rasmus Villemoes | 423de92 | 2016-03-24 10:38:04 +0200 | [diff] [blame] | 660 | return scnprintf(buf, PAGE_SIZE, "%pUl", uuid); |
Tomas Winkler | 007d64e | 2015-05-07 15:54:03 +0300 | [diff] [blame] | 661 | } |
| 662 | static DEVICE_ATTR_RO(uuid); |
| 663 | |
Tomas Winkler | 40b7320 | 2015-09-10 10:18:00 +0300 | [diff] [blame] | 664 | static ssize_t version_show(struct device *dev, struct device_attribute *a, |
| 665 | char *buf) |
| 666 | { |
| 667 | struct mei_cl_device *cldev = to_mei_cl_device(dev); |
| 668 | u8 version = mei_me_cl_ver(cldev->me_cl); |
Tomas Winkler | 40b7320 | 2015-09-10 10:18:00 +0300 | [diff] [blame] | 669 | |
Rasmus Villemoes | 423de92 | 2016-03-24 10:38:04 +0200 | [diff] [blame] | 670 | return scnprintf(buf, PAGE_SIZE, "%02X", version); |
Tomas Winkler | 40b7320 | 2015-09-10 10:18:00 +0300 | [diff] [blame] | 671 | } |
| 672 | static DEVICE_ATTR_RO(version); |
| 673 | |
Samuel Ortiz | e535410 | 2013-03-27 17:29:53 +0200 | [diff] [blame] | 674 | static ssize_t modalias_show(struct device *dev, struct device_attribute *a, |
| 675 | char *buf) |
| 676 | { |
Tomas Winkler | b37719c3 | 2015-07-23 15:08:33 +0300 | [diff] [blame] | 677 | struct mei_cl_device *cldev = to_mei_cl_device(dev); |
| 678 | const uuid_le *uuid = mei_me_cl_uuid(cldev->me_cl); |
Samuel Ortiz | e535410 | 2013-03-27 17:29:53 +0200 | [diff] [blame] | 679 | |
Rasmus Villemoes | 423de92 | 2016-03-24 10:38:04 +0200 | [diff] [blame] | 680 | return scnprintf(buf, PAGE_SIZE, "mei:%s:%pUl:", cldev->name, uuid); |
Samuel Ortiz | e535410 | 2013-03-27 17:29:53 +0200 | [diff] [blame] | 681 | } |
Greg Kroah-Hartman | 32f389ec | 2013-08-23 14:24:39 -0700 | [diff] [blame] | 682 | static DEVICE_ATTR_RO(modalias); |
Samuel Ortiz | e535410 | 2013-03-27 17:29:53 +0200 | [diff] [blame] | 683 | |
Tomas Winkler | d49dc5e | 2015-09-10 10:18:05 +0300 | [diff] [blame] | 684 | static struct attribute *mei_cldev_attrs[] = { |
Tomas Winkler | 007d64e | 2015-05-07 15:54:03 +0300 | [diff] [blame] | 685 | &dev_attr_name.attr, |
| 686 | &dev_attr_uuid.attr, |
Tomas Winkler | 40b7320 | 2015-09-10 10:18:00 +0300 | [diff] [blame] | 687 | &dev_attr_version.attr, |
Greg Kroah-Hartman | 32f389ec | 2013-08-23 14:24:39 -0700 | [diff] [blame] | 688 | &dev_attr_modalias.attr, |
| 689 | NULL, |
Samuel Ortiz | e535410 | 2013-03-27 17:29:53 +0200 | [diff] [blame] | 690 | }; |
Tomas Winkler | d49dc5e | 2015-09-10 10:18:05 +0300 | [diff] [blame] | 691 | ATTRIBUTE_GROUPS(mei_cldev); |
Samuel Ortiz | e535410 | 2013-03-27 17:29:53 +0200 | [diff] [blame] | 692 | |
Tomas Winkler | 38d3c00 | 2015-07-23 15:08:36 +0300 | [diff] [blame] | 693 | /** |
| 694 | * mei_cl_device_uevent - me client bus uevent handler |
| 695 | * |
| 696 | * @dev: device |
| 697 | * @env: uevent kobject |
| 698 | * |
| 699 | * Return: 0 on success -ENOMEM on when add_uevent_var fails |
| 700 | */ |
| 701 | static int mei_cl_device_uevent(struct device *dev, struct kobj_uevent_env *env) |
Samuel Ortiz | e535410 | 2013-03-27 17:29:53 +0200 | [diff] [blame] | 702 | { |
Tomas Winkler | b37719c3 | 2015-07-23 15:08:33 +0300 | [diff] [blame] | 703 | struct mei_cl_device *cldev = to_mei_cl_device(dev); |
| 704 | const uuid_le *uuid = mei_me_cl_uuid(cldev->me_cl); |
Tomas Winkler | 40b7320 | 2015-09-10 10:18:00 +0300 | [diff] [blame] | 705 | u8 version = mei_me_cl_ver(cldev->me_cl); |
| 706 | |
| 707 | if (add_uevent_var(env, "MEI_CL_VERSION=%d", version)) |
| 708 | return -ENOMEM; |
Tomas Winkler | c93b76b | 2015-05-07 15:54:02 +0300 | [diff] [blame] | 709 | |
Tomas Winkler | 007d64e | 2015-05-07 15:54:03 +0300 | [diff] [blame] | 710 | if (add_uevent_var(env, "MEI_CL_UUID=%pUl", uuid)) |
| 711 | return -ENOMEM; |
| 712 | |
Tomas Winkler | b37719c3 | 2015-07-23 15:08:33 +0300 | [diff] [blame] | 713 | if (add_uevent_var(env, "MEI_CL_NAME=%s", cldev->name)) |
Tomas Winkler | 007d64e | 2015-05-07 15:54:03 +0300 | [diff] [blame] | 714 | return -ENOMEM; |
| 715 | |
Tomas Winkler | b26864c | 2015-09-10 10:18:01 +0300 | [diff] [blame] | 716 | if (add_uevent_var(env, "MODALIAS=mei:%s:%pUl:%02X:", |
| 717 | cldev->name, uuid, version)) |
Samuel Ortiz | e535410 | 2013-03-27 17:29:53 +0200 | [diff] [blame] | 718 | return -ENOMEM; |
| 719 | |
| 720 | return 0; |
| 721 | } |
| 722 | |
| 723 | static struct bus_type mei_cl_bus_type = { |
| 724 | .name = "mei", |
Tomas Winkler | d49dc5e | 2015-09-10 10:18:05 +0300 | [diff] [blame] | 725 | .dev_groups = mei_cldev_groups, |
Samuel Ortiz | e535410 | 2013-03-27 17:29:53 +0200 | [diff] [blame] | 726 | .match = mei_cl_device_match, |
| 727 | .probe = mei_cl_device_probe, |
| 728 | .remove = mei_cl_device_remove, |
Tomas Winkler | 38d3c00 | 2015-07-23 15:08:36 +0300 | [diff] [blame] | 729 | .uevent = mei_cl_device_uevent, |
Samuel Ortiz | e535410 | 2013-03-27 17:29:53 +0200 | [diff] [blame] | 730 | }; |
| 731 | |
Tomas Winkler | 512f64d | 2015-07-23 15:08:41 +0300 | [diff] [blame] | 732 | static struct mei_device *mei_dev_bus_get(struct mei_device *bus) |
| 733 | { |
| 734 | if (bus) |
| 735 | get_device(bus->dev); |
| 736 | |
| 737 | return bus; |
| 738 | } |
| 739 | |
| 740 | static void mei_dev_bus_put(struct mei_device *bus) |
| 741 | { |
| 742 | if (bus) |
| 743 | put_device(bus->dev); |
| 744 | } |
| 745 | |
Tomas Winkler | ae48d74 | 2015-09-10 10:18:06 +0300 | [diff] [blame] | 746 | static void mei_cl_bus_dev_release(struct device *dev) |
Samuel Ortiz | e535410 | 2013-03-27 17:29:53 +0200 | [diff] [blame] | 747 | { |
Tomas Winkler | b37719c3 | 2015-07-23 15:08:33 +0300 | [diff] [blame] | 748 | struct mei_cl_device *cldev = to_mei_cl_device(dev); |
Alexander Usyskin | d49ed64 | 2015-05-04 09:43:54 +0300 | [diff] [blame] | 749 | |
Tomas Winkler | b37719c3 | 2015-07-23 15:08:33 +0300 | [diff] [blame] | 750 | if (!cldev) |
Alexander Usyskin | d49ed64 | 2015-05-04 09:43:54 +0300 | [diff] [blame] | 751 | return; |
| 752 | |
Tomas Winkler | b37719c3 | 2015-07-23 15:08:33 +0300 | [diff] [blame] | 753 | mei_me_cl_put(cldev->me_cl); |
Tomas Winkler | 512f64d | 2015-07-23 15:08:41 +0300 | [diff] [blame] | 754 | mei_dev_bus_put(cldev->bus); |
Tomas Winkler | b37719c3 | 2015-07-23 15:08:33 +0300 | [diff] [blame] | 755 | kfree(cldev); |
Samuel Ortiz | e535410 | 2013-03-27 17:29:53 +0200 | [diff] [blame] | 756 | } |
| 757 | |
| 758 | static struct device_type mei_cl_device_type = { |
Tomas Winkler | ae48d74 | 2015-09-10 10:18:06 +0300 | [diff] [blame] | 759 | .release = mei_cl_bus_dev_release, |
Samuel Ortiz | e535410 | 2013-03-27 17:29:53 +0200 | [diff] [blame] | 760 | }; |
| 761 | |
Tomas Winkler | 71ce789 | 2015-07-23 15:08:43 +0300 | [diff] [blame] | 762 | /** |
Tomas Winkler | 213dd19 | 2015-10-28 14:34:35 +0200 | [diff] [blame] | 763 | * mei_cl_bus_set_name - set device name for me client device |
| 764 | * |
| 765 | * @cldev: me client device |
| 766 | */ |
| 767 | static inline void mei_cl_bus_set_name(struct mei_cl_device *cldev) |
| 768 | { |
| 769 | dev_set_name(&cldev->dev, "mei:%s:%pUl:%02X", |
| 770 | cldev->name, |
| 771 | mei_me_cl_uuid(cldev->me_cl), |
| 772 | mei_me_cl_ver(cldev->me_cl)); |
| 773 | } |
| 774 | |
| 775 | /** |
Tomas Winkler | ae48d74 | 2015-09-10 10:18:06 +0300 | [diff] [blame] | 776 | * mei_cl_bus_dev_alloc - initialize and allocate mei client device |
Tomas Winkler | 71ce789 | 2015-07-23 15:08:43 +0300 | [diff] [blame] | 777 | * |
| 778 | * @bus: mei device |
| 779 | * @me_cl: me client |
| 780 | * |
| 781 | * Return: allocated device structur or NULL on allocation failure |
| 782 | */ |
Tomas Winkler | ae48d74 | 2015-09-10 10:18:06 +0300 | [diff] [blame] | 783 | static struct mei_cl_device *mei_cl_bus_dev_alloc(struct mei_device *bus, |
| 784 | struct mei_me_client *me_cl) |
Tomas Winkler | 71ce789 | 2015-07-23 15:08:43 +0300 | [diff] [blame] | 785 | { |
| 786 | struct mei_cl_device *cldev; |
| 787 | |
| 788 | cldev = kzalloc(sizeof(struct mei_cl_device), GFP_KERNEL); |
| 789 | if (!cldev) |
| 790 | return NULL; |
| 791 | |
| 792 | device_initialize(&cldev->dev); |
| 793 | cldev->dev.parent = bus->dev; |
| 794 | cldev->dev.bus = &mei_cl_bus_type; |
| 795 | cldev->dev.type = &mei_cl_device_type; |
| 796 | cldev->bus = mei_dev_bus_get(bus); |
| 797 | cldev->me_cl = mei_me_cl_get(me_cl); |
Tomas Winkler | 213dd19 | 2015-10-28 14:34:35 +0200 | [diff] [blame] | 798 | mei_cl_bus_set_name(cldev); |
Tomas Winkler | 71ce789 | 2015-07-23 15:08:43 +0300 | [diff] [blame] | 799 | cldev->is_added = 0; |
| 800 | INIT_LIST_HEAD(&cldev->bus_list); |
| 801 | |
| 802 | return cldev; |
| 803 | } |
| 804 | |
| 805 | /** |
| 806 | * mei_cl_dev_setup - setup me client device |
| 807 | * run fix up routines and set the device name |
| 808 | * |
| 809 | * @bus: mei device |
| 810 | * @cldev: me client device |
| 811 | * |
| 812 | * Return: true if the device is eligible for enumeration |
| 813 | */ |
Tomas Winkler | ae48d74 | 2015-09-10 10:18:06 +0300 | [diff] [blame] | 814 | static bool mei_cl_bus_dev_setup(struct mei_device *bus, |
| 815 | struct mei_cl_device *cldev) |
Tomas Winkler | 71ce789 | 2015-07-23 15:08:43 +0300 | [diff] [blame] | 816 | { |
| 817 | cldev->do_match = 1; |
Tomas Winkler | ae48d74 | 2015-09-10 10:18:06 +0300 | [diff] [blame] | 818 | mei_cl_bus_dev_fixup(cldev); |
Tomas Winkler | 71ce789 | 2015-07-23 15:08:43 +0300 | [diff] [blame] | 819 | |
Tomas Winkler | 213dd19 | 2015-10-28 14:34:35 +0200 | [diff] [blame] | 820 | /* the device name can change during fix up */ |
Tomas Winkler | 71ce789 | 2015-07-23 15:08:43 +0300 | [diff] [blame] | 821 | if (cldev->do_match) |
Tomas Winkler | 213dd19 | 2015-10-28 14:34:35 +0200 | [diff] [blame] | 822 | mei_cl_bus_set_name(cldev); |
Tomas Winkler | 71ce789 | 2015-07-23 15:08:43 +0300 | [diff] [blame] | 823 | |
| 824 | return cldev->do_match == 1; |
| 825 | } |
| 826 | |
| 827 | /** |
| 828 | * mei_cl_bus_dev_add - add me client devices |
| 829 | * |
| 830 | * @cldev: me client device |
| 831 | * |
| 832 | * Return: 0 on success; < 0 on failre |
| 833 | */ |
| 834 | static int mei_cl_bus_dev_add(struct mei_cl_device *cldev) |
| 835 | { |
| 836 | int ret; |
| 837 | |
Tomas Winkler | b26864c | 2015-09-10 10:18:01 +0300 | [diff] [blame] | 838 | dev_dbg(cldev->bus->dev, "adding %pUL:%02X\n", |
| 839 | mei_me_cl_uuid(cldev->me_cl), |
| 840 | mei_me_cl_ver(cldev->me_cl)); |
Tomas Winkler | 71ce789 | 2015-07-23 15:08:43 +0300 | [diff] [blame] | 841 | ret = device_add(&cldev->dev); |
| 842 | if (!ret) |
| 843 | cldev->is_added = 1; |
| 844 | |
| 845 | return ret; |
| 846 | } |
| 847 | |
Tomas Winkler | 6009595 | 2015-07-23 15:08:47 +0300 | [diff] [blame] | 848 | /** |
| 849 | * mei_cl_bus_dev_stop - stop the driver |
| 850 | * |
| 851 | * @cldev: me client device |
| 852 | */ |
| 853 | static void mei_cl_bus_dev_stop(struct mei_cl_device *cldev) |
| 854 | { |
| 855 | if (cldev->is_added) |
| 856 | device_release_driver(&cldev->dev); |
| 857 | } |
| 858 | |
| 859 | /** |
| 860 | * mei_cl_bus_dev_destroy - destroy me client devices object |
| 861 | * |
| 862 | * @cldev: me client device |
Tomas Winkler | 2da55cf | 2015-10-28 14:34:34 +0200 | [diff] [blame] | 863 | * |
| 864 | * Locking: called under "dev->cl_bus_lock" lock |
Tomas Winkler | 6009595 | 2015-07-23 15:08:47 +0300 | [diff] [blame] | 865 | */ |
| 866 | static void mei_cl_bus_dev_destroy(struct mei_cl_device *cldev) |
| 867 | { |
Tomas Winkler | 2da55cf | 2015-10-28 14:34:34 +0200 | [diff] [blame] | 868 | |
| 869 | WARN_ON(!mutex_is_locked(&cldev->bus->cl_bus_lock)); |
| 870 | |
Tomas Winkler | 6009595 | 2015-07-23 15:08:47 +0300 | [diff] [blame] | 871 | if (!cldev->is_added) |
| 872 | return; |
| 873 | |
| 874 | device_del(&cldev->dev); |
| 875 | |
Tomas Winkler | 6009595 | 2015-07-23 15:08:47 +0300 | [diff] [blame] | 876 | list_del_init(&cldev->bus_list); |
Tomas Winkler | 6009595 | 2015-07-23 15:08:47 +0300 | [diff] [blame] | 877 | |
| 878 | cldev->is_added = 0; |
| 879 | put_device(&cldev->dev); |
| 880 | } |
| 881 | |
| 882 | /** |
| 883 | * mei_cl_bus_remove_device - remove a devices form the bus |
| 884 | * |
| 885 | * @cldev: me client device |
| 886 | */ |
| 887 | static void mei_cl_bus_remove_device(struct mei_cl_device *cldev) |
| 888 | { |
| 889 | mei_cl_bus_dev_stop(cldev); |
| 890 | mei_cl_bus_dev_destroy(cldev); |
| 891 | } |
| 892 | |
| 893 | /** |
| 894 | * mei_cl_bus_remove_devices - remove all devices form the bus |
| 895 | * |
| 896 | * @bus: mei device |
| 897 | */ |
| 898 | void mei_cl_bus_remove_devices(struct mei_device *bus) |
| 899 | { |
| 900 | struct mei_cl_device *cldev, *next; |
| 901 | |
Tomas Winkler | 2da55cf | 2015-10-28 14:34:34 +0200 | [diff] [blame] | 902 | mutex_lock(&bus->cl_bus_lock); |
Tomas Winkler | 6009595 | 2015-07-23 15:08:47 +0300 | [diff] [blame] | 903 | list_for_each_entry_safe(cldev, next, &bus->device_list, bus_list) |
| 904 | mei_cl_bus_remove_device(cldev); |
Tomas Winkler | 2da55cf | 2015-10-28 14:34:34 +0200 | [diff] [blame] | 905 | mutex_unlock(&bus->cl_bus_lock); |
Tomas Winkler | 6009595 | 2015-07-23 15:08:47 +0300 | [diff] [blame] | 906 | } |
| 907 | |
| 908 | |
| 909 | /** |
Tomas Winkler | ae48d74 | 2015-09-10 10:18:06 +0300 | [diff] [blame] | 910 | * mei_cl_bus_dev_init - allocate and initializes an mei client devices |
Tomas Winkler | 6009595 | 2015-07-23 15:08:47 +0300 | [diff] [blame] | 911 | * based on me client |
| 912 | * |
| 913 | * @bus: mei device |
| 914 | * @me_cl: me client |
Tomas Winkler | 2da55cf | 2015-10-28 14:34:34 +0200 | [diff] [blame] | 915 | * |
| 916 | * Locking: called under "dev->cl_bus_lock" lock |
Tomas Winkler | 6009595 | 2015-07-23 15:08:47 +0300 | [diff] [blame] | 917 | */ |
Tomas Winkler | ae48d74 | 2015-09-10 10:18:06 +0300 | [diff] [blame] | 918 | static void mei_cl_bus_dev_init(struct mei_device *bus, |
| 919 | struct mei_me_client *me_cl) |
Samuel Ortiz | e535410 | 2013-03-27 17:29:53 +0200 | [diff] [blame] | 920 | { |
Tomas Winkler | b37719c3 | 2015-07-23 15:08:33 +0300 | [diff] [blame] | 921 | struct mei_cl_device *cldev; |
Tomas Winkler | 6009595 | 2015-07-23 15:08:47 +0300 | [diff] [blame] | 922 | |
Tomas Winkler | 2da55cf | 2015-10-28 14:34:34 +0200 | [diff] [blame] | 923 | WARN_ON(!mutex_is_locked(&bus->cl_bus_lock)); |
| 924 | |
Tomas Winkler | 6009595 | 2015-07-23 15:08:47 +0300 | [diff] [blame] | 925 | dev_dbg(bus->dev, "initializing %pUl", mei_me_cl_uuid(me_cl)); |
| 926 | |
| 927 | if (me_cl->bus_added) |
| 928 | return; |
Samuel Ortiz | e535410 | 2013-03-27 17:29:53 +0200 | [diff] [blame] | 929 | |
Tomas Winkler | ae48d74 | 2015-09-10 10:18:06 +0300 | [diff] [blame] | 930 | cldev = mei_cl_bus_dev_alloc(bus, me_cl); |
Tomas Winkler | b37719c3 | 2015-07-23 15:08:33 +0300 | [diff] [blame] | 931 | if (!cldev) |
Tomas Winkler | 6009595 | 2015-07-23 15:08:47 +0300 | [diff] [blame] | 932 | return; |
Samuel Ortiz | e535410 | 2013-03-27 17:29:53 +0200 | [diff] [blame] | 933 | |
Tomas Winkler | 6009595 | 2015-07-23 15:08:47 +0300 | [diff] [blame] | 934 | me_cl->bus_added = true; |
| 935 | list_add_tail(&cldev->bus_list, &bus->device_list); |
Tomas Winkler | c93b76b | 2015-05-07 15:54:02 +0300 | [diff] [blame] | 936 | |
Samuel Ortiz | e535410 | 2013-03-27 17:29:53 +0200 | [diff] [blame] | 937 | } |
Samuel Ortiz | e535410 | 2013-03-27 17:29:53 +0200 | [diff] [blame] | 938 | |
Tomas Winkler | 6009595 | 2015-07-23 15:08:47 +0300 | [diff] [blame] | 939 | /** |
| 940 | * mei_cl_bus_rescan - scan me clients list and add create |
| 941 | * devices for eligible clients |
| 942 | * |
| 943 | * @bus: mei device |
| 944 | */ |
| 945 | void mei_cl_bus_rescan(struct mei_device *bus) |
Samuel Ortiz | e535410 | 2013-03-27 17:29:53 +0200 | [diff] [blame] | 946 | { |
Tomas Winkler | 6009595 | 2015-07-23 15:08:47 +0300 | [diff] [blame] | 947 | struct mei_cl_device *cldev, *n; |
| 948 | struct mei_me_client *me_cl; |
| 949 | |
Tomas Winkler | 2da55cf | 2015-10-28 14:34:34 +0200 | [diff] [blame] | 950 | mutex_lock(&bus->cl_bus_lock); |
| 951 | |
Tomas Winkler | 6009595 | 2015-07-23 15:08:47 +0300 | [diff] [blame] | 952 | down_read(&bus->me_clients_rwsem); |
| 953 | list_for_each_entry(me_cl, &bus->me_clients, list) |
Tomas Winkler | ae48d74 | 2015-09-10 10:18:06 +0300 | [diff] [blame] | 954 | mei_cl_bus_dev_init(bus, me_cl); |
Tomas Winkler | 6009595 | 2015-07-23 15:08:47 +0300 | [diff] [blame] | 955 | up_read(&bus->me_clients_rwsem); |
| 956 | |
Tomas Winkler | 6009595 | 2015-07-23 15:08:47 +0300 | [diff] [blame] | 957 | list_for_each_entry_safe(cldev, n, &bus->device_list, bus_list) { |
| 958 | |
| 959 | if (!mei_me_cl_is_active(cldev->me_cl)) { |
| 960 | mei_cl_bus_remove_device(cldev); |
| 961 | continue; |
| 962 | } |
| 963 | |
| 964 | if (cldev->is_added) |
| 965 | continue; |
| 966 | |
Tomas Winkler | ae48d74 | 2015-09-10 10:18:06 +0300 | [diff] [blame] | 967 | if (mei_cl_bus_dev_setup(bus, cldev)) |
Tomas Winkler | 6009595 | 2015-07-23 15:08:47 +0300 | [diff] [blame] | 968 | mei_cl_bus_dev_add(cldev); |
| 969 | else { |
| 970 | list_del_init(&cldev->bus_list); |
| 971 | put_device(&cldev->dev); |
| 972 | } |
| 973 | } |
| 974 | mutex_unlock(&bus->cl_bus_lock); |
| 975 | |
| 976 | dev_dbg(bus->dev, "rescan end"); |
Samuel Ortiz | e535410 | 2013-03-27 17:29:53 +0200 | [diff] [blame] | 977 | } |
Samuel Ortiz | 333e4ee | 2013-03-27 17:29:54 +0200 | [diff] [blame] | 978 | |
Alexander Usyskin | a816a00 | 2016-02-07 23:35:41 +0200 | [diff] [blame] | 979 | void mei_cl_bus_rescan_work(struct work_struct *work) |
| 980 | { |
| 981 | struct mei_device *bus = |
| 982 | container_of(work, struct mei_device, bus_rescan_work); |
Alexander Usyskin | 025fb79 | 2016-02-07 23:35:43 +0200 | [diff] [blame] | 983 | struct mei_me_client *me_cl; |
| 984 | |
Alexander Usyskin | 025fb79 | 2016-02-07 23:35:43 +0200 | [diff] [blame] | 985 | me_cl = mei_me_cl_by_uuid(bus, &mei_amthif_guid); |
| 986 | if (me_cl) |
| 987 | mei_amthif_host_init(bus, me_cl); |
| 988 | mei_me_cl_put(me_cl); |
Alexander Usyskin | a816a00 | 2016-02-07 23:35:41 +0200 | [diff] [blame] | 989 | |
| 990 | mei_cl_bus_rescan(bus); |
| 991 | } |
| 992 | |
Tomas Winkler | d49dc5e | 2015-09-10 10:18:05 +0300 | [diff] [blame] | 993 | int __mei_cldev_driver_register(struct mei_cl_driver *cldrv, |
| 994 | struct module *owner) |
Samuel Ortiz | 333e4ee | 2013-03-27 17:29:54 +0200 | [diff] [blame] | 995 | { |
| 996 | int err; |
| 997 | |
Tomas Winkler | b37719c3 | 2015-07-23 15:08:33 +0300 | [diff] [blame] | 998 | cldrv->driver.name = cldrv->name; |
| 999 | cldrv->driver.owner = owner; |
| 1000 | cldrv->driver.bus = &mei_cl_bus_type; |
Samuel Ortiz | 333e4ee | 2013-03-27 17:29:54 +0200 | [diff] [blame] | 1001 | |
Tomas Winkler | b37719c3 | 2015-07-23 15:08:33 +0300 | [diff] [blame] | 1002 | err = driver_register(&cldrv->driver); |
Samuel Ortiz | 333e4ee | 2013-03-27 17:29:54 +0200 | [diff] [blame] | 1003 | if (err) |
| 1004 | return err; |
| 1005 | |
Tomas Winkler | b37719c3 | 2015-07-23 15:08:33 +0300 | [diff] [blame] | 1006 | pr_debug("mei: driver [%s] registered\n", cldrv->driver.name); |
Samuel Ortiz | 333e4ee | 2013-03-27 17:29:54 +0200 | [diff] [blame] | 1007 | |
| 1008 | return 0; |
| 1009 | } |
Tomas Winkler | d49dc5e | 2015-09-10 10:18:05 +0300 | [diff] [blame] | 1010 | EXPORT_SYMBOL_GPL(__mei_cldev_driver_register); |
Samuel Ortiz | 333e4ee | 2013-03-27 17:29:54 +0200 | [diff] [blame] | 1011 | |
Tomas Winkler | d49dc5e | 2015-09-10 10:18:05 +0300 | [diff] [blame] | 1012 | void mei_cldev_driver_unregister(struct mei_cl_driver *cldrv) |
Samuel Ortiz | 333e4ee | 2013-03-27 17:29:54 +0200 | [diff] [blame] | 1013 | { |
Tomas Winkler | b37719c3 | 2015-07-23 15:08:33 +0300 | [diff] [blame] | 1014 | driver_unregister(&cldrv->driver); |
Samuel Ortiz | 333e4ee | 2013-03-27 17:29:54 +0200 | [diff] [blame] | 1015 | |
Tomas Winkler | b37719c3 | 2015-07-23 15:08:33 +0300 | [diff] [blame] | 1016 | pr_debug("mei: driver [%s] unregistered\n", cldrv->driver.name); |
Samuel Ortiz | 333e4ee | 2013-03-27 17:29:54 +0200 | [diff] [blame] | 1017 | } |
Tomas Winkler | d49dc5e | 2015-09-10 10:18:05 +0300 | [diff] [blame] | 1018 | EXPORT_SYMBOL_GPL(mei_cldev_driver_unregister); |
Samuel Ortiz | 3e83329 | 2013-03-27 17:29:55 +0200 | [diff] [blame] | 1019 | |
Tomas Winkler | 6009595 | 2015-07-23 15:08:47 +0300 | [diff] [blame] | 1020 | |
Samuel Ortiz | cf3baef | 2013-03-27 17:29:57 +0200 | [diff] [blame] | 1021 | int __init mei_cl_bus_init(void) |
| 1022 | { |
| 1023 | return bus_register(&mei_cl_bus_type); |
| 1024 | } |
| 1025 | |
| 1026 | void __exit mei_cl_bus_exit(void) |
| 1027 | { |
| 1028 | bus_unregister(&mei_cl_bus_type); |
| 1029 | } |