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