Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Intel Management Engine Interface (Intel MEI) Linux driver |
| 4 | * Copyright (c) 2003-2012, Intel Corporation. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify it |
| 7 | * under the terms and conditions of the GNU General Public License, |
| 8 | * version 2, as published by the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 13 | * more details. |
| 14 | * |
| 15 | */ |
| 16 | |
Tomas Winkler | 4fcbc99 | 2014-03-18 22:51:55 +0200 | [diff] [blame] | 17 | #include <linux/export.h> |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 18 | #include <linux/pci.h> |
| 19 | #include <linux/sched.h> |
| 20 | #include <linux/wait.h> |
| 21 | #include <linux/mei.h> |
Tomas Winkler | 180ea05 | 2014-03-18 22:52:02 +0200 | [diff] [blame] | 22 | #include <linux/pm_runtime.h> |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 23 | |
| 24 | #include "mei_dev.h" |
Tomas Winkler | 0edb23f | 2013-01-08 23:07:12 +0200 | [diff] [blame] | 25 | #include "hbm.h" |
Alexander Usyskin | 12d0066 | 2014-02-17 15:13:23 +0200 | [diff] [blame] | 26 | #include "client.h" |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 27 | |
Tomas Winkler | 89778d6 | 2014-08-21 14:29:16 +0300 | [diff] [blame] | 28 | static const char *mei_hbm_status_str(enum mei_hbm_status status) |
| 29 | { |
| 30 | #define MEI_HBM_STATUS(status) case MEI_HBMS_##status: return #status |
| 31 | switch (status) { |
| 32 | MEI_HBM_STATUS(SUCCESS); |
| 33 | MEI_HBM_STATUS(CLIENT_NOT_FOUND); |
| 34 | MEI_HBM_STATUS(ALREADY_EXISTS); |
| 35 | MEI_HBM_STATUS(REJECTED); |
| 36 | MEI_HBM_STATUS(INVALID_PARAMETER); |
| 37 | MEI_HBM_STATUS(NOT_ALLOWED); |
| 38 | MEI_HBM_STATUS(ALREADY_STARTED); |
| 39 | MEI_HBM_STATUS(NOT_STARTED); |
| 40 | default: return "unknown"; |
| 41 | } |
| 42 | #undef MEI_HBM_STATUS |
| 43 | }; |
| 44 | |
Alexander Usyskin | 285e299 | 2014-02-17 15:13:20 +0200 | [diff] [blame] | 45 | static const char *mei_cl_conn_status_str(enum mei_cl_connect_status status) |
| 46 | { |
| 47 | #define MEI_CL_CS(status) case MEI_CL_CONN_##status: return #status |
| 48 | switch (status) { |
| 49 | MEI_CL_CS(SUCCESS); |
| 50 | MEI_CL_CS(NOT_FOUND); |
| 51 | MEI_CL_CS(ALREADY_STARTED); |
| 52 | MEI_CL_CS(OUT_OF_RESOURCES); |
| 53 | MEI_CL_CS(MESSAGE_SMALL); |
| 54 | default: return "unknown"; |
| 55 | } |
| 56 | #undef MEI_CL_CCS |
| 57 | } |
| 58 | |
Alexander Usyskin | 1beeb4b | 2014-09-29 16:31:33 +0300 | [diff] [blame] | 59 | const char *mei_hbm_state_str(enum mei_hbm_state state) |
| 60 | { |
| 61 | #define MEI_HBM_STATE(state) case MEI_HBM_##state: return #state |
| 62 | switch (state) { |
| 63 | MEI_HBM_STATE(IDLE); |
| 64 | MEI_HBM_STATE(STARTING); |
| 65 | MEI_HBM_STATE(STARTED); |
| 66 | MEI_HBM_STATE(ENUM_CLIENTS); |
| 67 | MEI_HBM_STATE(CLIENT_PROPERTIES); |
| 68 | MEI_HBM_STATE(STOPPED); |
| 69 | default: |
| 70 | return "unknown"; |
| 71 | } |
| 72 | #undef MEI_HBM_STATE |
| 73 | } |
| 74 | |
Alexander Usyskin | 285e299 | 2014-02-17 15:13:20 +0200 | [diff] [blame] | 75 | /** |
| 76 | * mei_cl_conn_status_to_errno - convert client connect response |
| 77 | * status to error code |
| 78 | * |
| 79 | * @status: client connect response status |
| 80 | * |
| 81 | * returns corresponding error code |
| 82 | */ |
| 83 | static int mei_cl_conn_status_to_errno(enum mei_cl_connect_status status) |
| 84 | { |
| 85 | switch (status) { |
| 86 | case MEI_CL_CONN_SUCCESS: return 0; |
| 87 | case MEI_CL_CONN_NOT_FOUND: return -ENOTTY; |
| 88 | case MEI_CL_CONN_ALREADY_STARTED: return -EBUSY; |
| 89 | case MEI_CL_CONN_OUT_OF_RESOURCES: return -EBUSY; |
| 90 | case MEI_CL_CONN_MESSAGE_SMALL: return -EINVAL; |
| 91 | default: return -EINVAL; |
| 92 | } |
| 93 | } |
| 94 | |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 95 | /** |
Tomas Winkler | 84b3294 | 2014-05-07 16:51:28 +0300 | [diff] [blame] | 96 | * mei_hbm_idle - set hbm to idle state |
| 97 | * |
| 98 | * @dev: the device structure |
| 99 | */ |
| 100 | void mei_hbm_idle(struct mei_device *dev) |
| 101 | { |
| 102 | dev->init_clients_timer = 0; |
| 103 | dev->hbm_state = MEI_HBM_IDLE; |
| 104 | } |
| 105 | |
| 106 | /** |
Tomas Winkler | 25ca647 | 2014-08-21 14:29:14 +0300 | [diff] [blame] | 107 | * mei_me_cl_remove_all - remove all me clients |
| 108 | * |
| 109 | * @dev: the device structure |
| 110 | */ |
| 111 | static void mei_me_cl_remove_all(struct mei_device *dev) |
| 112 | { |
| 113 | struct mei_me_client *me_cl, *next; |
Tomas Winkler | 92db155 | 2014-09-29 16:31:37 +0300 | [diff] [blame] | 114 | |
Tomas Winkler | 25ca647 | 2014-08-21 14:29:14 +0300 | [diff] [blame] | 115 | list_for_each_entry_safe(me_cl, next, &dev->me_clients, list) { |
| 116 | list_del(&me_cl->list); |
| 117 | kfree(me_cl); |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | /** |
Tomas Winkler | 84b3294 | 2014-05-07 16:51:28 +0300 | [diff] [blame] | 122 | * mei_hbm_reset - reset hbm counters and book keeping data structurs |
| 123 | * |
| 124 | * @dev: the device structure |
| 125 | */ |
| 126 | void mei_hbm_reset(struct mei_device *dev) |
| 127 | { |
Tomas Winkler | 84b3294 | 2014-05-07 16:51:28 +0300 | [diff] [blame] | 128 | dev->me_client_presentation_num = 0; |
| 129 | dev->me_client_index = 0; |
| 130 | |
Tomas Winkler | 25ca647 | 2014-08-21 14:29:14 +0300 | [diff] [blame] | 131 | mei_me_cl_remove_all(dev); |
Tomas Winkler | 84b3294 | 2014-05-07 16:51:28 +0300 | [diff] [blame] | 132 | |
| 133 | mei_hbm_idle(dev); |
| 134 | } |
| 135 | |
| 136 | /** |
Tomas Winkler | 2190fe2 | 2014-09-29 16:31:40 +0300 | [diff] [blame] | 137 | * mei_hbm_hdr - construct hbm header |
| 138 | * |
| 139 | * @hdr: hbm header |
| 140 | * @length: payload length |
| 141 | */ |
| 142 | |
| 143 | static inline void mei_hbm_hdr(struct mei_msg_hdr *hdr, size_t length) |
| 144 | { |
| 145 | hdr->host_addr = 0; |
| 146 | hdr->me_addr = 0; |
| 147 | hdr->length = length; |
| 148 | hdr->msg_complete = 1; |
| 149 | hdr->reserved = 0; |
| 150 | } |
| 151 | |
| 152 | /** |
Tomas Winkler | cd51ed6 | 2012-12-25 19:06:09 +0200 | [diff] [blame] | 153 | * mei_hbm_cl_hdr - construct client hbm header |
Masanari Iida | 393b148 | 2013-04-05 01:05:05 +0900 | [diff] [blame] | 154 | * |
Tomas Winkler | 68d1aa6 | 2014-08-21 14:29:11 +0300 | [diff] [blame] | 155 | * @cl: client |
Tomas Winkler | cd51ed6 | 2012-12-25 19:06:09 +0200 | [diff] [blame] | 156 | * @hbm_cmd: host bus message command |
| 157 | * @buf: buffer for cl header |
| 158 | * @len: buffer length |
| 159 | */ |
| 160 | static inline |
| 161 | void mei_hbm_cl_hdr(struct mei_cl *cl, u8 hbm_cmd, void *buf, size_t len) |
| 162 | { |
| 163 | struct mei_hbm_cl_cmd *cmd = buf; |
| 164 | |
| 165 | memset(cmd, 0, len); |
| 166 | |
| 167 | cmd->hbm_cmd = hbm_cmd; |
| 168 | cmd->host_addr = cl->host_client_id; |
| 169 | cmd->me_addr = cl->me_client_id; |
| 170 | } |
| 171 | |
| 172 | /** |
Tomas Winkler | 68d1aa6 | 2014-08-21 14:29:11 +0300 | [diff] [blame] | 173 | * mei_hbm_cl_write - write simple hbm client message |
| 174 | * |
| 175 | * @dev: the device structure |
| 176 | * @cl: client |
| 177 | * @hbm_cmd: host bus message command |
| 178 | * @len: buffer length |
| 179 | */ |
| 180 | static inline |
| 181 | int mei_hbm_cl_write(struct mei_device *dev, |
| 182 | struct mei_cl *cl, u8 hbm_cmd, size_t len) |
| 183 | { |
| 184 | struct mei_msg_hdr *mei_hdr = &dev->wr_msg.hdr; |
| 185 | |
| 186 | mei_hbm_hdr(mei_hdr, len); |
| 187 | mei_hbm_cl_hdr(cl, hbm_cmd, dev->wr_msg.data, len); |
| 188 | |
| 189 | return mei_write_message(dev, mei_hdr, dev->wr_msg.data); |
| 190 | } |
| 191 | |
| 192 | /** |
Tomas Winkler | 2af89db | 2014-08-21 14:29:20 +0300 | [diff] [blame] | 193 | * mei_hbm_cl_addr_equal - check if the client's and |
| 194 | * the message address match |
Tomas Winkler | cd51ed6 | 2012-12-25 19:06:09 +0200 | [diff] [blame] | 195 | * |
Tomas Winkler | 2af89db | 2014-08-21 14:29:20 +0300 | [diff] [blame] | 196 | * @cl: client |
| 197 | * @cmd: hbm client message |
Tomas Winkler | cd51ed6 | 2012-12-25 19:06:09 +0200 | [diff] [blame] | 198 | * |
Alexander Usyskin | 83ce074 | 2014-01-08 22:31:46 +0200 | [diff] [blame] | 199 | * returns true if addresses are the same |
Tomas Winkler | cd51ed6 | 2012-12-25 19:06:09 +0200 | [diff] [blame] | 200 | */ |
| 201 | static inline |
Tomas Winkler | 2af89db | 2014-08-21 14:29:20 +0300 | [diff] [blame] | 202 | bool mei_hbm_cl_addr_equal(struct mei_cl *cl, struct mei_hbm_cl_cmd *cmd) |
Tomas Winkler | cd51ed6 | 2012-12-25 19:06:09 +0200 | [diff] [blame] | 203 | { |
Tomas Winkler | cd51ed6 | 2012-12-25 19:06:09 +0200 | [diff] [blame] | 204 | return cl->host_client_id == cmd->host_addr && |
| 205 | cl->me_client_id == cmd->me_addr; |
| 206 | } |
| 207 | |
Alexander Usyskin | cb02efc | 2014-08-21 14:29:19 +0300 | [diff] [blame] | 208 | /** |
Tomas Winkler | 2af89db | 2014-08-21 14:29:20 +0300 | [diff] [blame] | 209 | * mei_hbm_cl_find_by_cmd - find recipient client |
| 210 | * |
| 211 | * @dev: the device structure |
| 212 | * @buf: a buffer with hbm cl command |
| 213 | * |
| 214 | * returns the recipient client or NULL if not found |
| 215 | */ |
| 216 | static inline |
| 217 | struct mei_cl *mei_hbm_cl_find_by_cmd(struct mei_device *dev, void *buf) |
| 218 | { |
| 219 | struct mei_hbm_cl_cmd *cmd = (struct mei_hbm_cl_cmd *)buf; |
| 220 | struct mei_cl *cl; |
| 221 | |
| 222 | list_for_each_entry(cl, &dev->file_list, link) |
| 223 | if (mei_hbm_cl_addr_equal(cl, cmd)) |
| 224 | return cl; |
| 225 | return NULL; |
| 226 | } |
| 227 | |
| 228 | |
| 229 | /** |
Alexander Usyskin | cb02efc | 2014-08-21 14:29:19 +0300 | [diff] [blame] | 230 | * mei_hbm_start_wait - wait for start response message. |
| 231 | * |
| 232 | * @dev: the device structure |
| 233 | * |
| 234 | * returns 0 on success and < 0 on failure |
| 235 | */ |
Tomas Winkler | 9b0d5ef | 2013-04-18 23:03:48 +0300 | [diff] [blame] | 236 | int mei_hbm_start_wait(struct mei_device *dev) |
| 237 | { |
| 238 | int ret; |
Alexander Usyskin | cb02efc | 2014-08-21 14:29:19 +0300 | [diff] [blame] | 239 | |
| 240 | if (dev->hbm_state > MEI_HBM_STARTING) |
Tomas Winkler | 9b0d5ef | 2013-04-18 23:03:48 +0300 | [diff] [blame] | 241 | return 0; |
| 242 | |
| 243 | mutex_unlock(&dev->device_lock); |
Alexander Usyskin | cb02efc | 2014-08-21 14:29:19 +0300 | [diff] [blame] | 244 | ret = wait_event_timeout(dev->wait_hbm_start, |
| 245 | dev->hbm_state != MEI_HBM_STARTING, |
Tomas Winkler | 7d93e58 | 2014-01-14 23:10:10 +0200 | [diff] [blame] | 246 | mei_secs_to_jiffies(MEI_HBM_TIMEOUT)); |
Tomas Winkler | 9b0d5ef | 2013-04-18 23:03:48 +0300 | [diff] [blame] | 247 | mutex_lock(&dev->device_lock); |
| 248 | |
Alexander Usyskin | cb02efc | 2014-08-21 14:29:19 +0300 | [diff] [blame] | 249 | if (ret == 0 && (dev->hbm_state <= MEI_HBM_STARTING)) { |
Tomas Winkler | 9b0d5ef | 2013-04-18 23:03:48 +0300 | [diff] [blame] | 250 | dev->hbm_state = MEI_HBM_IDLE; |
Masanari Iida | 8b513d0 | 2013-05-21 23:13:12 +0900 | [diff] [blame] | 251 | dev_err(&dev->pdev->dev, "waiting for mei start failed\n"); |
Alexander Usyskin | 7ca96aa | 2014-02-19 17:35:49 +0200 | [diff] [blame] | 252 | return -ETIME; |
Tomas Winkler | 9b0d5ef | 2013-04-18 23:03:48 +0300 | [diff] [blame] | 253 | } |
| 254 | return 0; |
| 255 | } |
| 256 | |
Tomas Winkler | 6bbda15 | 2012-12-25 19:06:12 +0200 | [diff] [blame] | 257 | /** |
Tomas Winkler | 8120e72 | 2012-12-25 19:06:11 +0200 | [diff] [blame] | 258 | * mei_hbm_start_req - sends start request message. |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 259 | * |
| 260 | * @dev: the device structure |
Tomas Winkler | 544f946 | 2014-01-08 20:19:21 +0200 | [diff] [blame] | 261 | * |
| 262 | * returns 0 on success and < 0 on failure |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 263 | */ |
Tomas Winkler | 9b0d5ef | 2013-04-18 23:03:48 +0300 | [diff] [blame] | 264 | int mei_hbm_start_req(struct mei_device *dev) |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 265 | { |
Tomas Winkler | e46f187 | 2012-12-25 19:06:10 +0200 | [diff] [blame] | 266 | struct mei_msg_hdr *mei_hdr = &dev->wr_msg.hdr; |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 267 | struct hbm_host_version_request *start_req; |
| 268 | const size_t len = sizeof(struct hbm_host_version_request); |
Tomas Winkler | 544f946 | 2014-01-08 20:19:21 +0200 | [diff] [blame] | 269 | int ret; |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 270 | |
Tomas Winkler | 5ca2d38 | 2014-08-21 14:29:13 +0300 | [diff] [blame] | 271 | mei_hbm_reset(dev); |
| 272 | |
Tomas Winkler | e46f187 | 2012-12-25 19:06:10 +0200 | [diff] [blame] | 273 | mei_hbm_hdr(mei_hdr, len); |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 274 | |
| 275 | /* host start message */ |
Tomas Winkler | e46f187 | 2012-12-25 19:06:10 +0200 | [diff] [blame] | 276 | start_req = (struct hbm_host_version_request *)dev->wr_msg.data; |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 277 | memset(start_req, 0, len); |
| 278 | start_req->hbm_cmd = HOST_START_REQ_CMD; |
| 279 | start_req->host_version.major_version = HBM_MAJOR_VERSION; |
| 280 | start_req->host_version.minor_version = HBM_MINOR_VERSION; |
| 281 | |
Tomas Winkler | 9b0d5ef | 2013-04-18 23:03:48 +0300 | [diff] [blame] | 282 | dev->hbm_state = MEI_HBM_IDLE; |
Tomas Winkler | 544f946 | 2014-01-08 20:19:21 +0200 | [diff] [blame] | 283 | ret = mei_write_message(dev, mei_hdr, dev->wr_msg.data); |
| 284 | if (ret) { |
| 285 | dev_err(&dev->pdev->dev, "version message write failed: ret = %d\n", |
| 286 | ret); |
| 287 | return ret; |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 288 | } |
Tomas Winkler | 544f946 | 2014-01-08 20:19:21 +0200 | [diff] [blame] | 289 | |
Alexander Usyskin | cb02efc | 2014-08-21 14:29:19 +0300 | [diff] [blame] | 290 | dev->hbm_state = MEI_HBM_STARTING; |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 291 | dev->init_clients_timer = MEI_CLIENTS_INIT_TIMEOUT; |
Tomas Winkler | 9b0d5ef | 2013-04-18 23:03:48 +0300 | [diff] [blame] | 292 | return 0; |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 293 | } |
| 294 | |
Tomas Winkler | 9b0d5ef | 2013-04-18 23:03:48 +0300 | [diff] [blame] | 295 | /* |
Tomas Winkler | 8120e72 | 2012-12-25 19:06:11 +0200 | [diff] [blame] | 296 | * mei_hbm_enum_clients_req - sends enumeration client request message. |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 297 | * |
| 298 | * @dev: the device structure |
| 299 | * |
Tomas Winkler | 544f946 | 2014-01-08 20:19:21 +0200 | [diff] [blame] | 300 | * returns 0 on success and < 0 on failure |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 301 | */ |
Tomas Winkler | 544f946 | 2014-01-08 20:19:21 +0200 | [diff] [blame] | 302 | static int mei_hbm_enum_clients_req(struct mei_device *dev) |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 303 | { |
Tomas Winkler | e46f187 | 2012-12-25 19:06:10 +0200 | [diff] [blame] | 304 | struct mei_msg_hdr *mei_hdr = &dev->wr_msg.hdr; |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 305 | struct hbm_host_enum_request *enum_req; |
| 306 | const size_t len = sizeof(struct hbm_host_enum_request); |
Tomas Winkler | 544f946 | 2014-01-08 20:19:21 +0200 | [diff] [blame] | 307 | int ret; |
| 308 | |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 309 | /* enumerate clients */ |
Tomas Winkler | e46f187 | 2012-12-25 19:06:10 +0200 | [diff] [blame] | 310 | mei_hbm_hdr(mei_hdr, len); |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 311 | |
Tomas Winkler | e46f187 | 2012-12-25 19:06:10 +0200 | [diff] [blame] | 312 | enum_req = (struct hbm_host_enum_request *)dev->wr_msg.data; |
| 313 | memset(enum_req, 0, len); |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 314 | enum_req->hbm_cmd = HOST_ENUM_REQ_CMD; |
| 315 | |
Tomas Winkler | 544f946 | 2014-01-08 20:19:21 +0200 | [diff] [blame] | 316 | ret = mei_write_message(dev, mei_hdr, dev->wr_msg.data); |
| 317 | if (ret) { |
| 318 | dev_err(&dev->pdev->dev, "enumeration request write failed: ret = %d.\n", |
| 319 | ret); |
| 320 | return ret; |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 321 | } |
Tomas Winkler | 9b0d5ef | 2013-04-18 23:03:48 +0300 | [diff] [blame] | 322 | dev->hbm_state = MEI_HBM_ENUM_CLIENTS; |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 323 | dev->init_clients_timer = MEI_CLIENTS_INIT_TIMEOUT; |
Tomas Winkler | 544f946 | 2014-01-08 20:19:21 +0200 | [diff] [blame] | 324 | return 0; |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 325 | } |
| 326 | |
Tomas Winkler | 5ca2d38 | 2014-08-21 14:29:13 +0300 | [diff] [blame] | 327 | /* |
| 328 | * mei_hbm_me_cl_add - add new me client to the list |
| 329 | * |
| 330 | * @dev: the device structure |
| 331 | * @res: hbm property response |
| 332 | * |
| 333 | * returns 0 on success and -ENOMEM on allocation failure |
| 334 | */ |
| 335 | |
| 336 | static int mei_hbm_me_cl_add(struct mei_device *dev, |
| 337 | struct hbm_props_response *res) |
| 338 | { |
| 339 | struct mei_me_client *me_cl; |
| 340 | |
| 341 | me_cl = kzalloc(sizeof(struct mei_me_client), GFP_KERNEL); |
| 342 | if (!me_cl) |
| 343 | return -ENOMEM; |
| 344 | |
| 345 | me_cl->props = res->client_properties; |
| 346 | me_cl->client_id = res->me_addr; |
| 347 | me_cl->mei_flow_ctrl_creds = 0; |
| 348 | |
| 349 | list_add(&me_cl->list, &dev->me_clients); |
| 350 | return 0; |
| 351 | } |
| 352 | |
Tomas Winkler | 8120e72 | 2012-12-25 19:06:11 +0200 | [diff] [blame] | 353 | /** |
Masanari Iida | 393b148 | 2013-04-05 01:05:05 +0900 | [diff] [blame] | 354 | * mei_hbm_prop_req - request property for a single client |
Tomas Winkler | 8120e72 | 2012-12-25 19:06:11 +0200 | [diff] [blame] | 355 | * |
| 356 | * @dev: the device structure |
| 357 | * |
Tomas Winkler | 544f946 | 2014-01-08 20:19:21 +0200 | [diff] [blame] | 358 | * returns 0 on success and < 0 on failure |
Tomas Winkler | 8120e72 | 2012-12-25 19:06:11 +0200 | [diff] [blame] | 359 | */ |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 360 | |
Tomas Winkler | 8120e72 | 2012-12-25 19:06:11 +0200 | [diff] [blame] | 361 | static int mei_hbm_prop_req(struct mei_device *dev) |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 362 | { |
| 363 | |
Tomas Winkler | e46f187 | 2012-12-25 19:06:10 +0200 | [diff] [blame] | 364 | struct mei_msg_hdr *mei_hdr = &dev->wr_msg.hdr; |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 365 | struct hbm_props_request *prop_req; |
| 366 | const size_t len = sizeof(struct hbm_props_request); |
| 367 | unsigned long next_client_index; |
Tomas Winkler | 544f946 | 2014-01-08 20:19:21 +0200 | [diff] [blame] | 368 | int ret; |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 369 | |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 370 | next_client_index = find_next_bit(dev->me_clients_map, MEI_CLIENTS_MAX, |
| 371 | dev->me_client_index); |
| 372 | |
| 373 | /* We got all client properties */ |
| 374 | if (next_client_index == MEI_CLIENTS_MAX) { |
Tomas Winkler | 9b0d5ef | 2013-04-18 23:03:48 +0300 | [diff] [blame] | 375 | dev->hbm_state = MEI_HBM_STARTED; |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 376 | schedule_work(&dev->init_work); |
| 377 | |
| 378 | return 0; |
| 379 | } |
| 380 | |
Tomas Winkler | e46f187 | 2012-12-25 19:06:10 +0200 | [diff] [blame] | 381 | mei_hbm_hdr(mei_hdr, len); |
| 382 | prop_req = (struct hbm_props_request *)dev->wr_msg.data; |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 383 | |
| 384 | memset(prop_req, 0, sizeof(struct hbm_props_request)); |
| 385 | |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 386 | prop_req->hbm_cmd = HOST_CLIENT_PROPERTIES_REQ_CMD; |
Tomas Winkler | 3438c1f | 2014-08-21 14:29:10 +0300 | [diff] [blame] | 387 | prop_req->me_addr = next_client_index; |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 388 | |
Tomas Winkler | 544f946 | 2014-01-08 20:19:21 +0200 | [diff] [blame] | 389 | ret = mei_write_message(dev, mei_hdr, dev->wr_msg.data); |
| 390 | if (ret) { |
| 391 | dev_err(&dev->pdev->dev, "properties request write failed: ret = %d\n", |
| 392 | ret); |
| 393 | return ret; |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | dev->init_clients_timer = MEI_CLIENTS_INIT_TIMEOUT; |
| 397 | dev->me_client_index = next_client_index; |
| 398 | |
| 399 | return 0; |
| 400 | } |
| 401 | |
Tomas Winkler | 4fcbc99 | 2014-03-18 22:51:55 +0200 | [diff] [blame] | 402 | /* |
| 403 | * mei_hbm_pg - sends pg command |
| 404 | * |
| 405 | * @dev: the device structure |
| 406 | * @pg_cmd: the pg command code |
| 407 | * |
Tomas Winkler | bae1cc7 | 2014-08-21 14:29:21 +0300 | [diff] [blame] | 408 | * returns -EIO on write failure |
| 409 | * -EOPNOTSUPP if the operation is not supported by the protocol |
Tomas Winkler | 4fcbc99 | 2014-03-18 22:51:55 +0200 | [diff] [blame] | 410 | */ |
| 411 | int mei_hbm_pg(struct mei_device *dev, u8 pg_cmd) |
| 412 | { |
| 413 | struct mei_msg_hdr *mei_hdr = &dev->wr_msg.hdr; |
| 414 | struct hbm_power_gate *req; |
| 415 | const size_t len = sizeof(struct hbm_power_gate); |
| 416 | int ret; |
| 417 | |
Tomas Winkler | bae1cc7 | 2014-08-21 14:29:21 +0300 | [diff] [blame] | 418 | if (!dev->hbm_f_pg_supported) |
| 419 | return -EOPNOTSUPP; |
| 420 | |
Tomas Winkler | 4fcbc99 | 2014-03-18 22:51:55 +0200 | [diff] [blame] | 421 | mei_hbm_hdr(mei_hdr, len); |
| 422 | |
| 423 | req = (struct hbm_power_gate *)dev->wr_msg.data; |
| 424 | memset(req, 0, len); |
| 425 | req->hbm_cmd = pg_cmd; |
| 426 | |
| 427 | ret = mei_write_message(dev, mei_hdr, dev->wr_msg.data); |
| 428 | if (ret) |
| 429 | dev_err(&dev->pdev->dev, "power gate command write failed.\n"); |
| 430 | return ret; |
| 431 | } |
| 432 | EXPORT_SYMBOL_GPL(mei_hbm_pg); |
| 433 | |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 434 | /** |
Tomas Winkler | 6bb948c | 2014-02-12 21:41:52 +0200 | [diff] [blame] | 435 | * mei_hbm_stop_req - send stop request message |
Tomas Winkler | e46f187 | 2012-12-25 19:06:10 +0200 | [diff] [blame] | 436 | * |
| 437 | * @dev - mei device |
Tomas Winkler | 6bb948c | 2014-02-12 21:41:52 +0200 | [diff] [blame] | 438 | * @cl: client info |
| 439 | * |
| 440 | * This function returns -EIO on write failure |
Tomas Winkler | e46f187 | 2012-12-25 19:06:10 +0200 | [diff] [blame] | 441 | */ |
Tomas Winkler | 6bb948c | 2014-02-12 21:41:52 +0200 | [diff] [blame] | 442 | static int mei_hbm_stop_req(struct mei_device *dev) |
Tomas Winkler | e46f187 | 2012-12-25 19:06:10 +0200 | [diff] [blame] | 443 | { |
Tomas Winkler | 6bb948c | 2014-02-12 21:41:52 +0200 | [diff] [blame] | 444 | struct mei_msg_hdr *mei_hdr = &dev->wr_msg.hdr; |
Tomas Winkler | e46f187 | 2012-12-25 19:06:10 +0200 | [diff] [blame] | 445 | struct hbm_host_stop_request *req = |
Tomas Winkler | 6bb948c | 2014-02-12 21:41:52 +0200 | [diff] [blame] | 446 | (struct hbm_host_stop_request *)dev->wr_msg.data; |
Tomas Winkler | e46f187 | 2012-12-25 19:06:10 +0200 | [diff] [blame] | 447 | const size_t len = sizeof(struct hbm_host_stop_request); |
| 448 | |
| 449 | mei_hbm_hdr(mei_hdr, len); |
| 450 | |
| 451 | memset(req, 0, len); |
| 452 | req->hbm_cmd = HOST_STOP_REQ_CMD; |
| 453 | req->reason = DRIVER_STOP_REQUEST; |
Tomas Winkler | 6bb948c | 2014-02-12 21:41:52 +0200 | [diff] [blame] | 454 | |
| 455 | return mei_write_message(dev, mei_hdr, dev->wr_msg.data); |
Tomas Winkler | e46f187 | 2012-12-25 19:06:10 +0200 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | /** |
Alexander Usyskin | 83ce074 | 2014-01-08 22:31:46 +0200 | [diff] [blame] | 459 | * mei_hbm_cl_flow_control_req - sends flow control request. |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 460 | * |
| 461 | * @dev: the device structure |
Tomas Winkler | 8120e72 | 2012-12-25 19:06:11 +0200 | [diff] [blame] | 462 | * @cl: client info |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 463 | * |
| 464 | * This function returns -EIO on write failure |
| 465 | */ |
Tomas Winkler | 8120e72 | 2012-12-25 19:06:11 +0200 | [diff] [blame] | 466 | int mei_hbm_cl_flow_control_req(struct mei_device *dev, struct mei_cl *cl) |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 467 | { |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 468 | const size_t len = sizeof(struct hbm_flow_control); |
Tomas Winkler | 92db155 | 2014-09-29 16:31:37 +0300 | [diff] [blame] | 469 | |
Tomas Winkler | 4692218 | 2014-03-16 14:35:55 +0200 | [diff] [blame] | 470 | cl_dbg(dev, cl, "sending flow control\n"); |
Tomas Winkler | 68d1aa6 | 2014-08-21 14:29:11 +0300 | [diff] [blame] | 471 | return mei_hbm_cl_write(dev, cl, MEI_FLOW_CONTROL_CMD, len); |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | /** |
Masanari Iida | 393b148 | 2013-04-05 01:05:05 +0900 | [diff] [blame] | 475 | * mei_hbm_add_single_flow_creds - adds single buffer credentials. |
Tomas Winkler | 6bbda15 | 2012-12-25 19:06:12 +0200 | [diff] [blame] | 476 | * |
Masanari Iida | 393b148 | 2013-04-05 01:05:05 +0900 | [diff] [blame] | 477 | * @dev: the device structure |
Tomas Winkler | 6bbda15 | 2012-12-25 19:06:12 +0200 | [diff] [blame] | 478 | * @flow: flow control. |
Alexander Usyskin | 12d0066 | 2014-02-17 15:13:23 +0200 | [diff] [blame] | 479 | * |
| 480 | * return 0 on success, < 0 otherwise |
Tomas Winkler | 6bbda15 | 2012-12-25 19:06:12 +0200 | [diff] [blame] | 481 | */ |
Alexander Usyskin | 12d0066 | 2014-02-17 15:13:23 +0200 | [diff] [blame] | 482 | static int mei_hbm_add_single_flow_creds(struct mei_device *dev, |
Tomas Winkler | 6bbda15 | 2012-12-25 19:06:12 +0200 | [diff] [blame] | 483 | struct hbm_flow_control *flow) |
| 484 | { |
Alexander Usyskin | 12d0066 | 2014-02-17 15:13:23 +0200 | [diff] [blame] | 485 | struct mei_me_client *me_cl; |
Tomas Winkler | 6bbda15 | 2012-12-25 19:06:12 +0200 | [diff] [blame] | 486 | |
Tomas Winkler | d320832 | 2014-08-24 12:08:55 +0300 | [diff] [blame] | 487 | me_cl = mei_me_cl_by_id(dev, flow->me_addr); |
| 488 | if (!me_cl) { |
Alexander Usyskin | 12d0066 | 2014-02-17 15:13:23 +0200 | [diff] [blame] | 489 | dev_err(&dev->pdev->dev, "no such me client %d\n", |
| 490 | flow->me_addr); |
Tomas Winkler | d320832 | 2014-08-24 12:08:55 +0300 | [diff] [blame] | 491 | return -ENOENT; |
Tomas Winkler | 6bbda15 | 2012-12-25 19:06:12 +0200 | [diff] [blame] | 492 | } |
Alexander Usyskin | 12d0066 | 2014-02-17 15:13:23 +0200 | [diff] [blame] | 493 | |
Tomas Winkler | d320832 | 2014-08-24 12:08:55 +0300 | [diff] [blame] | 494 | if (WARN_ON(me_cl->props.single_recv_buf == 0)) |
| 495 | return -EINVAL; |
| 496 | |
| 497 | me_cl->mei_flow_ctrl_creds++; |
| 498 | dev_dbg(&dev->pdev->dev, "recv flow ctrl msg ME %d (single) creds = %d.\n", |
| 499 | flow->me_addr, me_cl->mei_flow_ctrl_creds); |
Alexander Usyskin | 12d0066 | 2014-02-17 15:13:23 +0200 | [diff] [blame] | 500 | |
| 501 | return 0; |
Tomas Winkler | 6bbda15 | 2012-12-25 19:06:12 +0200 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | /** |
| 505 | * mei_hbm_cl_flow_control_res - flow control response from me |
| 506 | * |
| 507 | * @dev: the device structure |
| 508 | * @flow_control: flow control response bus message |
| 509 | */ |
| 510 | static void mei_hbm_cl_flow_control_res(struct mei_device *dev, |
Tomas Winkler | 2af89db | 2014-08-21 14:29:20 +0300 | [diff] [blame] | 511 | struct hbm_flow_control *flow_control) |
Tomas Winkler | 6bbda15 | 2012-12-25 19:06:12 +0200 | [diff] [blame] | 512 | { |
Tomas Winkler | 31f88f5 | 2014-02-17 15:13:25 +0200 | [diff] [blame] | 513 | struct mei_cl *cl; |
Tomas Winkler | 6bbda15 | 2012-12-25 19:06:12 +0200 | [diff] [blame] | 514 | |
| 515 | if (!flow_control->host_addr) { |
| 516 | /* single receive buffer */ |
| 517 | mei_hbm_add_single_flow_creds(dev, flow_control); |
| 518 | return; |
| 519 | } |
| 520 | |
Tomas Winkler | 2af89db | 2014-08-21 14:29:20 +0300 | [diff] [blame] | 521 | cl = mei_hbm_cl_find_by_cmd(dev, flow_control); |
| 522 | if (cl) { |
| 523 | cl->mei_flow_ctrl_creds++; |
| 524 | cl_dbg(dev, cl, "flow control creds = %d.\n", |
Tomas Winkler | 5ca2d38 | 2014-08-21 14:29:13 +0300 | [diff] [blame] | 525 | cl->mei_flow_ctrl_creds); |
Tomas Winkler | 6bbda15 | 2012-12-25 19:06:12 +0200 | [diff] [blame] | 526 | } |
| 527 | } |
| 528 | |
| 529 | |
| 530 | /** |
Tomas Winkler | 8120e72 | 2012-12-25 19:06:11 +0200 | [diff] [blame] | 531 | * mei_hbm_cl_disconnect_req - sends disconnect message to fw. |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 532 | * |
| 533 | * @dev: the device structure |
Tomas Winkler | 8120e72 | 2012-12-25 19:06:11 +0200 | [diff] [blame] | 534 | * @cl: a client to disconnect from |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 535 | * |
| 536 | * This function returns -EIO on write failure |
| 537 | */ |
Tomas Winkler | 8120e72 | 2012-12-25 19:06:11 +0200 | [diff] [blame] | 538 | int mei_hbm_cl_disconnect_req(struct mei_device *dev, struct mei_cl *cl) |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 539 | { |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 540 | const size_t len = sizeof(struct hbm_client_connect_request); |
Tomas Winkler | 92db155 | 2014-09-29 16:31:37 +0300 | [diff] [blame] | 541 | |
Tomas Winkler | 68d1aa6 | 2014-08-21 14:29:11 +0300 | [diff] [blame] | 542 | return mei_hbm_cl_write(dev, cl, CLIENT_DISCONNECT_REQ_CMD, len); |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | /** |
Tomas Winkler | 6bb948c | 2014-02-12 21:41:52 +0200 | [diff] [blame] | 546 | * mei_hbm_cl_disconnect_rsp - sends disconnect respose to the FW |
| 547 | * |
| 548 | * @dev: the device structure |
| 549 | * @cl: a client to disconnect from |
| 550 | * |
| 551 | * This function returns -EIO on write failure |
| 552 | */ |
| 553 | int mei_hbm_cl_disconnect_rsp(struct mei_device *dev, struct mei_cl *cl) |
| 554 | { |
Tomas Winkler | 6bb948c | 2014-02-12 21:41:52 +0200 | [diff] [blame] | 555 | const size_t len = sizeof(struct hbm_client_connect_response); |
Tomas Winkler | 92db155 | 2014-09-29 16:31:37 +0300 | [diff] [blame] | 556 | |
Tomas Winkler | 68d1aa6 | 2014-08-21 14:29:11 +0300 | [diff] [blame] | 557 | return mei_hbm_cl_write(dev, cl, CLIENT_DISCONNECT_RES_CMD, len); |
Tomas Winkler | 6bb948c | 2014-02-12 21:41:52 +0200 | [diff] [blame] | 558 | } |
| 559 | |
| 560 | /** |
Tomas Winkler | 12f45ed | 2014-08-21 14:29:18 +0300 | [diff] [blame] | 561 | * mei_hbm_cl_disconnect_res - update the client state according |
| 562 | * disconnect response |
Tomas Winkler | 6bbda15 | 2012-12-25 19:06:12 +0200 | [diff] [blame] | 563 | * |
Tomas Winkler | 12f45ed | 2014-08-21 14:29:18 +0300 | [diff] [blame] | 564 | * @cl: mei host client |
| 565 | * @cmd: disconnect client response host bus message |
Tomas Winkler | 6bbda15 | 2012-12-25 19:06:12 +0200 | [diff] [blame] | 566 | */ |
Tomas Winkler | 12f45ed | 2014-08-21 14:29:18 +0300 | [diff] [blame] | 567 | static void mei_hbm_cl_disconnect_res(struct mei_cl *cl, |
| 568 | struct mei_hbm_cl_cmd *cmd) |
Tomas Winkler | 6bbda15 | 2012-12-25 19:06:12 +0200 | [diff] [blame] | 569 | { |
Tomas Winkler | 12f45ed | 2014-08-21 14:29:18 +0300 | [diff] [blame] | 570 | struct hbm_client_connect_response *rs = |
| 571 | (struct hbm_client_connect_response *)cmd; |
Tomas Winkler | 6bbda15 | 2012-12-25 19:06:12 +0200 | [diff] [blame] | 572 | |
Tomas Winkler | 12f45ed | 2014-08-21 14:29:18 +0300 | [diff] [blame] | 573 | dev_dbg(&cl->dev->pdev->dev, "hbm: disconnect response cl:host=%02d me=%02d status=%d\n", |
Alexander Usyskin | 285e299 | 2014-02-17 15:13:20 +0200 | [diff] [blame] | 574 | rs->me_addr, rs->host_addr, rs->status); |
Tomas Winkler | 6bbda15 | 2012-12-25 19:06:12 +0200 | [diff] [blame] | 575 | |
Tomas Winkler | 12f45ed | 2014-08-21 14:29:18 +0300 | [diff] [blame] | 576 | if (rs->status == MEI_CL_DISCONN_SUCCESS) |
| 577 | cl->state = MEI_FILE_DISCONNECTED; |
| 578 | cl->status = 0; |
Tomas Winkler | 6bbda15 | 2012-12-25 19:06:12 +0200 | [diff] [blame] | 579 | } |
| 580 | |
| 581 | /** |
Tomas Winkler | 8120e72 | 2012-12-25 19:06:11 +0200 | [diff] [blame] | 582 | * mei_hbm_cl_connect_req - send connection request to specific me client |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 583 | * |
| 584 | * @dev: the device structure |
Tomas Winkler | 8120e72 | 2012-12-25 19:06:11 +0200 | [diff] [blame] | 585 | * @cl: a client to connect to |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 586 | * |
Tomas Winkler | 8120e72 | 2012-12-25 19:06:11 +0200 | [diff] [blame] | 587 | * returns -EIO on write failure |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 588 | */ |
Tomas Winkler | 8120e72 | 2012-12-25 19:06:11 +0200 | [diff] [blame] | 589 | int mei_hbm_cl_connect_req(struct mei_device *dev, struct mei_cl *cl) |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 590 | { |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 591 | const size_t len = sizeof(struct hbm_client_connect_request); |
Tomas Winkler | 92db155 | 2014-09-29 16:31:37 +0300 | [diff] [blame] | 592 | |
Tomas Winkler | 68d1aa6 | 2014-08-21 14:29:11 +0300 | [diff] [blame] | 593 | return mei_hbm_cl_write(dev, cl, CLIENT_CONNECT_REQ_CMD, len); |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 594 | } |
| 595 | |
| 596 | /** |
Tomas Winkler | 12f45ed | 2014-08-21 14:29:18 +0300 | [diff] [blame] | 597 | * mei_hbm_cl_connect_res - update the client state according |
| 598 | * connection response |
Tomas Winkler | 6bbda15 | 2012-12-25 19:06:12 +0200 | [diff] [blame] | 599 | * |
Tomas Winkler | 12f45ed | 2014-08-21 14:29:18 +0300 | [diff] [blame] | 600 | * @cl: mei host client |
| 601 | * @cmd: connect client response host bus message |
Tomas Winkler | 6bbda15 | 2012-12-25 19:06:12 +0200 | [diff] [blame] | 602 | */ |
Tomas Winkler | 12f45ed | 2014-08-21 14:29:18 +0300 | [diff] [blame] | 603 | static void mei_hbm_cl_connect_res(struct mei_cl *cl, |
| 604 | struct mei_hbm_cl_cmd *cmd) |
Tomas Winkler | 6bbda15 | 2012-12-25 19:06:12 +0200 | [diff] [blame] | 605 | { |
Tomas Winkler | 12f45ed | 2014-08-21 14:29:18 +0300 | [diff] [blame] | 606 | struct hbm_client_connect_response *rs = |
| 607 | (struct hbm_client_connect_response *)cmd; |
Tomas Winkler | 6bbda15 | 2012-12-25 19:06:12 +0200 | [diff] [blame] | 608 | |
Tomas Winkler | 12f45ed | 2014-08-21 14:29:18 +0300 | [diff] [blame] | 609 | dev_dbg(&cl->dev->pdev->dev, "hbm: connect response cl:host=%02d me=%02d status=%s\n", |
Alexander Usyskin | 285e299 | 2014-02-17 15:13:20 +0200 | [diff] [blame] | 610 | rs->me_addr, rs->host_addr, |
| 611 | mei_cl_conn_status_str(rs->status)); |
Tomas Winkler | 6bbda15 | 2012-12-25 19:06:12 +0200 | [diff] [blame] | 612 | |
Tomas Winkler | 12f45ed | 2014-08-21 14:29:18 +0300 | [diff] [blame] | 613 | if (rs->status == MEI_CL_CONN_SUCCESS) |
| 614 | cl->state = MEI_FILE_CONNECTED; |
| 615 | else |
| 616 | cl->state = MEI_FILE_DISCONNECTED; |
| 617 | cl->status = mei_cl_conn_status_to_errno(rs->status); |
| 618 | } |
Tomas Winkler | 6bbda15 | 2012-12-25 19:06:12 +0200 | [diff] [blame] | 619 | |
Tomas Winkler | 12f45ed | 2014-08-21 14:29:18 +0300 | [diff] [blame] | 620 | /** |
| 621 | * mei_hbm_cl_res - process hbm response received on behalf |
| 622 | * an client |
| 623 | * |
| 624 | * @dev: the device structure |
| 625 | * @rs: hbm client message |
| 626 | * @fop_type: file operation type |
| 627 | */ |
| 628 | static void mei_hbm_cl_res(struct mei_device *dev, |
| 629 | struct mei_hbm_cl_cmd *rs, |
| 630 | enum mei_cb_file_ops fop_type) |
| 631 | { |
| 632 | struct mei_cl *cl; |
| 633 | struct mei_cl_cb *cb, *next; |
| 634 | |
| 635 | cl = NULL; |
Tomas Winkler | 6409285 | 2014-02-17 15:13:21 +0200 | [diff] [blame] | 636 | list_for_each_entry_safe(cb, next, &dev->ctrl_rd_list.list, list) { |
Tomas Winkler | 6bbda15 | 2012-12-25 19:06:12 +0200 | [diff] [blame] | 637 | |
Tomas Winkler | 6409285 | 2014-02-17 15:13:21 +0200 | [diff] [blame] | 638 | cl = cb->cl; |
| 639 | /* this should not happen */ |
| 640 | if (WARN_ON(!cl)) { |
| 641 | list_del_init(&cb->list); |
| 642 | continue; |
Tomas Winkler | 6bbda15 | 2012-12-25 19:06:12 +0200 | [diff] [blame] | 643 | } |
Tomas Winkler | 6409285 | 2014-02-17 15:13:21 +0200 | [diff] [blame] | 644 | |
Tomas Winkler | 12f45ed | 2014-08-21 14:29:18 +0300 | [diff] [blame] | 645 | if (cb->fop_type != fop_type) |
Tomas Winkler | 6409285 | 2014-02-17 15:13:21 +0200 | [diff] [blame] | 646 | continue; |
| 647 | |
| 648 | if (mei_hbm_cl_addr_equal(cl, rs)) { |
| 649 | list_del(&cb->list); |
| 650 | break; |
Tomas Winkler | 6bbda15 | 2012-12-25 19:06:12 +0200 | [diff] [blame] | 651 | } |
| 652 | } |
Tomas Winkler | 6409285 | 2014-02-17 15:13:21 +0200 | [diff] [blame] | 653 | |
| 654 | if (!cl) |
| 655 | return; |
| 656 | |
Tomas Winkler | 12f45ed | 2014-08-21 14:29:18 +0300 | [diff] [blame] | 657 | switch (fop_type) { |
| 658 | case MEI_FOP_CONNECT: |
| 659 | mei_hbm_cl_connect_res(cl, rs); |
| 660 | break; |
| 661 | case MEI_FOP_DISCONNECT: |
| 662 | mei_hbm_cl_disconnect_res(cl, rs); |
| 663 | break; |
| 664 | default: |
| 665 | return; |
| 666 | } |
| 667 | |
Tomas Winkler | 6409285 | 2014-02-17 15:13:21 +0200 | [diff] [blame] | 668 | cl->timer_count = 0; |
Tomas Winkler | 12f45ed | 2014-08-21 14:29:18 +0300 | [diff] [blame] | 669 | wake_up(&cl->wait); |
Tomas Winkler | 6bbda15 | 2012-12-25 19:06:12 +0200 | [diff] [blame] | 670 | } |
| 671 | |
| 672 | |
| 673 | /** |
Alexander Usyskin | 83ce074 | 2014-01-08 22:31:46 +0200 | [diff] [blame] | 674 | * mei_hbm_fw_disconnect_req - disconnect request initiated by ME firmware |
| 675 | * host sends disconnect response |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 676 | * |
| 677 | * @dev: the device structure. |
Tomas Winkler | 8120e72 | 2012-12-25 19:06:11 +0200 | [diff] [blame] | 678 | * @disconnect_req: disconnect request bus message from the me |
Tomas Winkler | 6bb948c | 2014-02-12 21:41:52 +0200 | [diff] [blame] | 679 | * |
| 680 | * returns -ENOMEM on allocation failure |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 681 | */ |
Tomas Winkler | 6bb948c | 2014-02-12 21:41:52 +0200 | [diff] [blame] | 682 | static int mei_hbm_fw_disconnect_req(struct mei_device *dev, |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 683 | struct hbm_client_connect_request *disconnect_req) |
| 684 | { |
Tomas Winkler | 31f88f5 | 2014-02-17 15:13:25 +0200 | [diff] [blame] | 685 | struct mei_cl *cl; |
Tomas Winkler | 6bb948c | 2014-02-12 21:41:52 +0200 | [diff] [blame] | 686 | struct mei_cl_cb *cb; |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 687 | |
Tomas Winkler | 2af89db | 2014-08-21 14:29:20 +0300 | [diff] [blame] | 688 | cl = mei_hbm_cl_find_by_cmd(dev, disconnect_req); |
| 689 | if (cl) { |
| 690 | cl_dbg(dev, cl, "disconnect request received\n"); |
| 691 | cl->state = MEI_FILE_DISCONNECTED; |
| 692 | cl->timer_count = 0; |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 693 | |
Tomas Winkler | 2af89db | 2014-08-21 14:29:20 +0300 | [diff] [blame] | 694 | cb = mei_io_cb_init(cl, NULL); |
| 695 | if (!cb) |
| 696 | return -ENOMEM; |
| 697 | cb->fop_type = MEI_FOP_DISCONNECT_RSP; |
| 698 | cl_dbg(dev, cl, "add disconnect response as first\n"); |
| 699 | list_add(&cb->list, &dev->ctrl_wr_list.list); |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 700 | } |
Tomas Winkler | 6bb948c | 2014-02-12 21:41:52 +0200 | [diff] [blame] | 701 | return 0; |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 702 | } |
| 703 | |
Tomas Winkler | bae1cc7 | 2014-08-21 14:29:21 +0300 | [diff] [blame] | 704 | /** |
| 705 | * mei_hbm_config_features: check what hbm features and commands |
| 706 | * are supported by the fw |
| 707 | * |
| 708 | * @dev: the device structure |
| 709 | */ |
| 710 | static void mei_hbm_config_features(struct mei_device *dev) |
| 711 | { |
| 712 | /* Power Gating Isolation Support */ |
| 713 | dev->hbm_f_pg_supported = 0; |
| 714 | if (dev->version.major_version > HBM_MAJOR_VERSION_PGI) |
| 715 | dev->hbm_f_pg_supported = 1; |
| 716 | |
| 717 | if (dev->version.major_version == HBM_MAJOR_VERSION_PGI && |
| 718 | dev->version.minor_version >= HBM_MINOR_VERSION_PGI) |
| 719 | dev->hbm_f_pg_supported = 1; |
| 720 | } |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 721 | |
| 722 | /** |
Tomas Winkler | 2c9b48a | 2013-06-16 09:16:31 +0300 | [diff] [blame] | 723 | * mei_hbm_version_is_supported - checks whether the driver can |
| 724 | * support the hbm version of the device |
| 725 | * |
| 726 | * @dev: the device structure |
| 727 | * returns true if driver can support hbm version of the device |
| 728 | */ |
| 729 | bool mei_hbm_version_is_supported(struct mei_device *dev) |
| 730 | { |
| 731 | return (dev->version.major_version < HBM_MAJOR_VERSION) || |
| 732 | (dev->version.major_version == HBM_MAJOR_VERSION && |
| 733 | dev->version.minor_version <= HBM_MINOR_VERSION); |
| 734 | } |
| 735 | |
| 736 | /** |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 737 | * mei_hbm_dispatch - bottom half read routine after ISR to |
| 738 | * handle the read bus message cmd processing. |
| 739 | * |
| 740 | * @dev: the device structure |
| 741 | * @mei_hdr: header of bus message |
Tomas Winkler | 544f946 | 2014-01-08 20:19:21 +0200 | [diff] [blame] | 742 | * |
| 743 | * returns 0 on success and < 0 on failure |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 744 | */ |
Tomas Winkler | 544f946 | 2014-01-08 20:19:21 +0200 | [diff] [blame] | 745 | int mei_hbm_dispatch(struct mei_device *dev, struct mei_msg_hdr *hdr) |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 746 | { |
| 747 | struct mei_bus_message *mei_msg; |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 748 | struct hbm_host_version_response *version_res; |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 749 | struct hbm_props_response *props_res; |
| 750 | struct hbm_host_enum_response *enum_res; |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 751 | |
Tomas Winkler | 12f45ed | 2014-08-21 14:29:18 +0300 | [diff] [blame] | 752 | struct mei_hbm_cl_cmd *cl_cmd; |
| 753 | struct hbm_client_connect_request *disconnect_req; |
| 754 | struct hbm_flow_control *flow_control; |
| 755 | |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 756 | /* read the message to our buffer */ |
| 757 | BUG_ON(hdr->length >= sizeof(dev->rd_msg_buf)); |
| 758 | mei_read_slots(dev, dev->rd_msg_buf, hdr->length); |
| 759 | mei_msg = (struct mei_bus_message *)dev->rd_msg_buf; |
Tomas Winkler | 12f45ed | 2014-08-21 14:29:18 +0300 | [diff] [blame] | 760 | cl_cmd = (struct mei_hbm_cl_cmd *)mei_msg; |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 761 | |
Tomas Winkler | 66ae460 | 2014-01-08 20:19:22 +0200 | [diff] [blame] | 762 | /* ignore spurious message and prevent reset nesting |
| 763 | * hbm is put to idle during system reset |
| 764 | */ |
| 765 | if (dev->hbm_state == MEI_HBM_IDLE) { |
| 766 | dev_dbg(&dev->pdev->dev, "hbm: state is idle ignore spurious messages\n"); |
| 767 | return 0; |
| 768 | } |
| 769 | |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 770 | switch (mei_msg->hbm_cmd) { |
| 771 | case HOST_START_RES_CMD: |
Tomas Winkler | 544f946 | 2014-01-08 20:19:21 +0200 | [diff] [blame] | 772 | dev_dbg(&dev->pdev->dev, "hbm: start: response message received.\n"); |
| 773 | |
| 774 | dev->init_clients_timer = 0; |
| 775 | |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 776 | version_res = (struct hbm_host_version_response *)mei_msg; |
Tomas Winkler | 2c9b48a | 2013-06-16 09:16:31 +0300 | [diff] [blame] | 777 | |
| 778 | dev_dbg(&dev->pdev->dev, "HBM VERSION: DRIVER=%02d:%02d DEVICE=%02d:%02d\n", |
| 779 | HBM_MAJOR_VERSION, HBM_MINOR_VERSION, |
| 780 | version_res->me_max_version.major_version, |
| 781 | version_res->me_max_version.minor_version); |
| 782 | |
| 783 | if (version_res->host_version_supported) { |
| 784 | dev->version.major_version = HBM_MAJOR_VERSION; |
| 785 | dev->version.minor_version = HBM_MINOR_VERSION; |
| 786 | } else { |
| 787 | dev->version.major_version = |
| 788 | version_res->me_max_version.major_version; |
| 789 | dev->version.minor_version = |
| 790 | version_res->me_max_version.minor_version; |
| 791 | } |
| 792 | |
| 793 | if (!mei_hbm_version_is_supported(dev)) { |
Tomas Winkler | 544f946 | 2014-01-08 20:19:21 +0200 | [diff] [blame] | 794 | dev_warn(&dev->pdev->dev, "hbm: start: version mismatch - stopping the driver.\n"); |
Tomas Winkler | e46f187 | 2012-12-25 19:06:10 +0200 | [diff] [blame] | 795 | |
Tomas Winkler | 544f946 | 2014-01-08 20:19:21 +0200 | [diff] [blame] | 796 | dev->hbm_state = MEI_HBM_STOPPED; |
Tomas Winkler | 6bb948c | 2014-02-12 21:41:52 +0200 | [diff] [blame] | 797 | if (mei_hbm_stop_req(dev)) { |
Tomas Winkler | 544f946 | 2014-01-08 20:19:21 +0200 | [diff] [blame] | 798 | dev_err(&dev->pdev->dev, "hbm: start: failed to send stop request\n"); |
| 799 | return -EIO; |
| 800 | } |
| 801 | break; |
Tomas Winkler | e46f187 | 2012-12-25 19:06:10 +0200 | [diff] [blame] | 802 | } |
| 803 | |
Tomas Winkler | bae1cc7 | 2014-08-21 14:29:21 +0300 | [diff] [blame] | 804 | mei_hbm_config_features(dev); |
| 805 | |
Tomas Winkler | 544f946 | 2014-01-08 20:19:21 +0200 | [diff] [blame] | 806 | if (dev->dev_state != MEI_DEV_INIT_CLIENTS || |
Alexander Usyskin | cb02efc | 2014-08-21 14:29:19 +0300 | [diff] [blame] | 807 | dev->hbm_state != MEI_HBM_STARTING) { |
Tomas Winkler | 544f946 | 2014-01-08 20:19:21 +0200 | [diff] [blame] | 808 | dev_err(&dev->pdev->dev, "hbm: start: state mismatch, [%d, %d]\n", |
| 809 | dev->dev_state, dev->hbm_state); |
| 810 | return -EPROTO; |
| 811 | } |
| 812 | |
| 813 | dev->hbm_state = MEI_HBM_STARTED; |
| 814 | |
| 815 | if (mei_hbm_enum_clients_req(dev)) { |
| 816 | dev_err(&dev->pdev->dev, "hbm: start: failed to send enumeration request\n"); |
| 817 | return -EIO; |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 818 | } |
| 819 | |
Alexander Usyskin | cb02efc | 2014-08-21 14:29:19 +0300 | [diff] [blame] | 820 | wake_up(&dev->wait_hbm_start); |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 821 | break; |
| 822 | |
| 823 | case CLIENT_CONNECT_RES_CMD: |
Tomas Winkler | 544f946 | 2014-01-08 20:19:21 +0200 | [diff] [blame] | 824 | dev_dbg(&dev->pdev->dev, "hbm: client connect response: message received.\n"); |
Tomas Winkler | 12f45ed | 2014-08-21 14:29:18 +0300 | [diff] [blame] | 825 | mei_hbm_cl_res(dev, cl_cmd, MEI_FOP_CONNECT); |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 826 | break; |
| 827 | |
| 828 | case CLIENT_DISCONNECT_RES_CMD: |
Tomas Winkler | 544f946 | 2014-01-08 20:19:21 +0200 | [diff] [blame] | 829 | dev_dbg(&dev->pdev->dev, "hbm: client disconnect response: message received.\n"); |
Tomas Winkler | 12f45ed | 2014-08-21 14:29:18 +0300 | [diff] [blame] | 830 | mei_hbm_cl_res(dev, cl_cmd, MEI_FOP_DISCONNECT); |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 831 | break; |
| 832 | |
| 833 | case MEI_FLOW_CONTROL_CMD: |
Tomas Winkler | 544f946 | 2014-01-08 20:19:21 +0200 | [diff] [blame] | 834 | dev_dbg(&dev->pdev->dev, "hbm: client flow control response: message received.\n"); |
| 835 | |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 836 | flow_control = (struct hbm_flow_control *) mei_msg; |
Tomas Winkler | 6bbda15 | 2012-12-25 19:06:12 +0200 | [diff] [blame] | 837 | mei_hbm_cl_flow_control_res(dev, flow_control); |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 838 | break; |
| 839 | |
Tomas Winkler | 4fcbc99 | 2014-03-18 22:51:55 +0200 | [diff] [blame] | 840 | case MEI_PG_ISOLATION_ENTRY_RES_CMD: |
| 841 | dev_dbg(&dev->pdev->dev, "power gate isolation entry response received\n"); |
Tomas Winkler | ba9cdd0 | 2014-03-18 22:52:00 +0200 | [diff] [blame] | 842 | dev->pg_event = MEI_PG_EVENT_RECEIVED; |
Tomas Winkler | 4fcbc99 | 2014-03-18 22:51:55 +0200 | [diff] [blame] | 843 | if (waitqueue_active(&dev->wait_pg)) |
| 844 | wake_up(&dev->wait_pg); |
| 845 | break; |
| 846 | |
| 847 | case MEI_PG_ISOLATION_EXIT_REQ_CMD: |
| 848 | dev_dbg(&dev->pdev->dev, "power gate isolation exit request received\n"); |
Tomas Winkler | ba9cdd0 | 2014-03-18 22:52:00 +0200 | [diff] [blame] | 849 | dev->pg_event = MEI_PG_EVENT_RECEIVED; |
Tomas Winkler | 4fcbc99 | 2014-03-18 22:51:55 +0200 | [diff] [blame] | 850 | if (waitqueue_active(&dev->wait_pg)) |
| 851 | wake_up(&dev->wait_pg); |
Tomas Winkler | 180ea05 | 2014-03-18 22:52:02 +0200 | [diff] [blame] | 852 | else |
| 853 | /* |
| 854 | * If the driver is not waiting on this then |
| 855 | * this is HW initiated exit from PG. |
| 856 | * Start runtime pm resume sequence to exit from PG. |
| 857 | */ |
| 858 | pm_request_resume(&dev->pdev->dev); |
Tomas Winkler | 4fcbc99 | 2014-03-18 22:51:55 +0200 | [diff] [blame] | 859 | break; |
| 860 | |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 861 | case HOST_CLIENT_PROPERTIES_RES_CMD: |
Tomas Winkler | 544f946 | 2014-01-08 20:19:21 +0200 | [diff] [blame] | 862 | dev_dbg(&dev->pdev->dev, "hbm: properties response: message received.\n"); |
| 863 | |
| 864 | dev->init_clients_timer = 0; |
| 865 | |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 866 | if (dev->dev_state != MEI_DEV_INIT_CLIENTS || |
Tomas Winkler | 9b0d5ef | 2013-04-18 23:03:48 +0300 | [diff] [blame] | 867 | dev->hbm_state != MEI_HBM_CLIENT_PROPERTIES) { |
Tomas Winkler | 544f946 | 2014-01-08 20:19:21 +0200 | [diff] [blame] | 868 | dev_err(&dev->pdev->dev, "hbm: properties response: state mismatch, [%d, %d]\n", |
| 869 | dev->dev_state, dev->hbm_state); |
| 870 | return -EPROTO; |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 871 | } |
| 872 | |
Tomas Winkler | 5ca2d38 | 2014-08-21 14:29:13 +0300 | [diff] [blame] | 873 | props_res = (struct hbm_props_response *)mei_msg; |
| 874 | |
| 875 | if (props_res->status) { |
Tomas Winkler | 89778d6 | 2014-08-21 14:29:16 +0300 | [diff] [blame] | 876 | dev_err(&dev->pdev->dev, "hbm: properties response: wrong status = %d %s\n", |
| 877 | props_res->status, |
| 878 | mei_hbm_status_str(props_res->status)); |
Tomas Winkler | 5ca2d38 | 2014-08-21 14:29:13 +0300 | [diff] [blame] | 879 | return -EPROTO; |
| 880 | } |
| 881 | |
| 882 | mei_hbm_me_cl_add(dev, props_res); |
| 883 | |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 884 | dev->me_client_index++; |
| 885 | dev->me_client_presentation_num++; |
| 886 | |
Tomas Winkler | 8120e72 | 2012-12-25 19:06:11 +0200 | [diff] [blame] | 887 | /* request property for the next client */ |
Tomas Winkler | 544f946 | 2014-01-08 20:19:21 +0200 | [diff] [blame] | 888 | if (mei_hbm_prop_req(dev)) |
| 889 | return -EIO; |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 890 | |
| 891 | break; |
| 892 | |
| 893 | case HOST_ENUM_RES_CMD: |
Tomas Winkler | 544f946 | 2014-01-08 20:19:21 +0200 | [diff] [blame] | 894 | dev_dbg(&dev->pdev->dev, "hbm: enumeration response: message received\n"); |
| 895 | |
| 896 | dev->init_clients_timer = 0; |
| 897 | |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 898 | enum_res = (struct hbm_host_enum_response *) mei_msg; |
Tomas Winkler | 23f5a32 | 2013-09-02 03:11:01 +0300 | [diff] [blame] | 899 | BUILD_BUG_ON(sizeof(dev->me_clients_map) |
| 900 | < sizeof(enum_res->valid_addresses)); |
| 901 | memcpy(dev->me_clients_map, enum_res->valid_addresses, |
Tomas Winkler | 5ca2d38 | 2014-08-21 14:29:13 +0300 | [diff] [blame] | 902 | sizeof(enum_res->valid_addresses)); |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 903 | |
Tomas Winkler | 544f946 | 2014-01-08 20:19:21 +0200 | [diff] [blame] | 904 | if (dev->dev_state != MEI_DEV_INIT_CLIENTS || |
| 905 | dev->hbm_state != MEI_HBM_ENUM_CLIENTS) { |
| 906 | dev_err(&dev->pdev->dev, "hbm: enumeration response: state mismatch, [%d, %d]\n", |
| 907 | dev->dev_state, dev->hbm_state); |
| 908 | return -EPROTO; |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 909 | } |
Tomas Winkler | 544f946 | 2014-01-08 20:19:21 +0200 | [diff] [blame] | 910 | |
Tomas Winkler | 544f946 | 2014-01-08 20:19:21 +0200 | [diff] [blame] | 911 | dev->hbm_state = MEI_HBM_CLIENT_PROPERTIES; |
| 912 | |
| 913 | /* first property request */ |
| 914 | if (mei_hbm_prop_req(dev)) |
| 915 | return -EIO; |
| 916 | |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 917 | break; |
| 918 | |
| 919 | case HOST_STOP_RES_CMD: |
Tomas Winkler | 544f946 | 2014-01-08 20:19:21 +0200 | [diff] [blame] | 920 | dev_dbg(&dev->pdev->dev, "hbm: stop response: message received\n"); |
Tomas Winkler | 9b0d5ef | 2013-04-18 23:03:48 +0300 | [diff] [blame] | 921 | |
Tomas Winkler | 544f946 | 2014-01-08 20:19:21 +0200 | [diff] [blame] | 922 | dev->init_clients_timer = 0; |
| 923 | |
| 924 | if (dev->hbm_state != MEI_HBM_STOPPED) { |
| 925 | dev_err(&dev->pdev->dev, "hbm: stop response: state mismatch, [%d, %d]\n", |
| 926 | dev->dev_state, dev->hbm_state); |
| 927 | return -EPROTO; |
| 928 | } |
| 929 | |
Tomas Winkler | 33ec082 | 2014-01-12 00:36:09 +0200 | [diff] [blame] | 930 | dev->dev_state = MEI_DEV_POWER_DOWN; |
Tomas Winkler | 544f946 | 2014-01-08 20:19:21 +0200 | [diff] [blame] | 931 | dev_info(&dev->pdev->dev, "hbm: stop response: resetting.\n"); |
| 932 | /* force the reset */ |
| 933 | return -EPROTO; |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 934 | break; |
| 935 | |
| 936 | case CLIENT_DISCONNECT_REQ_CMD: |
Tomas Winkler | 544f946 | 2014-01-08 20:19:21 +0200 | [diff] [blame] | 937 | dev_dbg(&dev->pdev->dev, "hbm: disconnect request: message received\n"); |
| 938 | |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 939 | disconnect_req = (struct hbm_client_connect_request *)mei_msg; |
Tomas Winkler | 8120e72 | 2012-12-25 19:06:11 +0200 | [diff] [blame] | 940 | mei_hbm_fw_disconnect_req(dev, disconnect_req); |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 941 | break; |
| 942 | |
| 943 | case ME_STOP_REQ_CMD: |
Tomas Winkler | 544f946 | 2014-01-08 20:19:21 +0200 | [diff] [blame] | 944 | dev_dbg(&dev->pdev->dev, "hbm: stop request: message received\n"); |
Tomas Winkler | 544f946 | 2014-01-08 20:19:21 +0200 | [diff] [blame] | 945 | dev->hbm_state = MEI_HBM_STOPPED; |
Tomas Winkler | 6bb948c | 2014-02-12 21:41:52 +0200 | [diff] [blame] | 946 | if (mei_hbm_stop_req(dev)) { |
Alexander Usyskin | cb02efc | 2014-08-21 14:29:19 +0300 | [diff] [blame] | 947 | dev_err(&dev->pdev->dev, "hbm: stop request: failed to send stop request\n"); |
Tomas Winkler | 6bb948c | 2014-02-12 21:41:52 +0200 | [diff] [blame] | 948 | return -EIO; |
| 949 | } |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 950 | break; |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 951 | default: |
| 952 | BUG(); |
| 953 | break; |
| 954 | |
| 955 | } |
Tomas Winkler | 544f946 | 2014-01-08 20:19:21 +0200 | [diff] [blame] | 956 | return 0; |
Tomas Winkler | bb1b013 | 2012-12-25 19:06:07 +0200 | [diff] [blame] | 957 | } |
| 958 | |