Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Intel Management Engine Interface (Intel MEI) Linux driver |
Tomas Winkler | 733ba91 | 2012-02-09 19:25:53 +0200 | [diff] [blame] | 4 | * Copyright (c) 2003-2012, Intel Corporation. |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 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 | |
| 17 | #include <linux/pci.h> |
| 18 | #include "mei_dev.h" |
Tomas Winkler | 4f3afe1 | 2012-05-09 16:38:59 +0300 | [diff] [blame] | 19 | #include <linux/mei.h> |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 20 | #include "interface.h" |
| 21 | |
| 22 | |
| 23 | |
| 24 | /** |
| 25 | * mei_set_csr_register - writes H_CSR register to the mei device, |
| 26 | * and ignores the H_IS bit for it is write-one-to-zero. |
| 27 | * |
| 28 | * @dev: the device structure |
| 29 | */ |
| 30 | void mei_hcsr_set(struct mei_device *dev) |
| 31 | { |
| 32 | if ((dev->host_hw_state & H_IS) == H_IS) |
| 33 | dev->host_hw_state &= ~H_IS; |
| 34 | mei_reg_write(dev, H_CSR, dev->host_hw_state); |
| 35 | dev->host_hw_state = mei_hcsr_read(dev); |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * mei_csr_enable_interrupts - enables mei device interrupts |
| 40 | * |
| 41 | * @dev: the device structure |
| 42 | */ |
| 43 | void mei_enable_interrupts(struct mei_device *dev) |
| 44 | { |
| 45 | dev->host_hw_state |= H_IE; |
| 46 | mei_hcsr_set(dev); |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * mei_csr_disable_interrupts - disables mei device interrupts |
| 51 | * |
| 52 | * @dev: the device structure |
| 53 | */ |
| 54 | void mei_disable_interrupts(struct mei_device *dev) |
| 55 | { |
| 56 | dev->host_hw_state &= ~H_IE; |
| 57 | mei_hcsr_set(dev); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * _host_get_filled_slots - gets number of device filled buffer slots |
| 62 | * |
| 63 | * @device: the device structure |
| 64 | * |
| 65 | * returns number of filled slots |
| 66 | */ |
| 67 | static unsigned char _host_get_filled_slots(const struct mei_device *dev) |
| 68 | { |
| 69 | char read_ptr, write_ptr; |
| 70 | |
| 71 | read_ptr = (char) ((dev->host_hw_state & H_CBRP) >> 8); |
| 72 | write_ptr = (char) ((dev->host_hw_state & H_CBWP) >> 16); |
| 73 | |
| 74 | return (unsigned char) (write_ptr - read_ptr); |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * mei_host_buffer_is_empty - checks if host buffer is empty. |
| 79 | * |
| 80 | * @dev: the device structure |
| 81 | * |
| 82 | * returns 1 if empty, 0 - otherwise. |
| 83 | */ |
| 84 | int mei_host_buffer_is_empty(struct mei_device *dev) |
| 85 | { |
| 86 | unsigned char filled_slots; |
| 87 | |
| 88 | dev->host_hw_state = mei_hcsr_read(dev); |
| 89 | filled_slots = _host_get_filled_slots(dev); |
| 90 | |
| 91 | if (filled_slots == 0) |
| 92 | return 1; |
| 93 | |
| 94 | return 0; |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * mei_count_empty_write_slots - counts write empty slots. |
| 99 | * |
| 100 | * @dev: the device structure |
| 101 | * |
| 102 | * returns -1(ESLOTS_OVERFLOW) if overflow, otherwise empty slots count |
| 103 | */ |
| 104 | int mei_count_empty_write_slots(struct mei_device *dev) |
| 105 | { |
Tomas Winkler | 24aadc8 | 2012-06-25 23:46:27 +0300 | [diff] [blame^] | 106 | unsigned char filled_slots, empty_slots; |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 107 | |
| 108 | dev->host_hw_state = mei_hcsr_read(dev); |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 109 | filled_slots = _host_get_filled_slots(dev); |
Tomas Winkler | 24aadc8 | 2012-06-25 23:46:27 +0300 | [diff] [blame^] | 110 | empty_slots = dev->hbuf_depth - filled_slots; |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 111 | |
| 112 | /* check for overflow */ |
Tomas Winkler | 24aadc8 | 2012-06-25 23:46:27 +0300 | [diff] [blame^] | 113 | if (filled_slots > dev->hbuf_depth) |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 114 | return -EOVERFLOW; |
| 115 | |
| 116 | return empty_slots; |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * mei_write_message - writes a message to mei device. |
| 121 | * |
| 122 | * @dev: the device structure |
| 123 | * @header: header of message |
| 124 | * @write_buffer: message buffer will be written |
| 125 | * @write_length: message size will be written |
| 126 | * |
Tomas Winkler | 1ccb7b6 | 2012-03-14 14:39:42 +0200 | [diff] [blame] | 127 | * This function returns -EIO if write has failed |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 128 | */ |
Tomas Winkler | 169d133 | 2012-06-19 09:13:35 +0300 | [diff] [blame] | 129 | int mei_write_message(struct mei_device *dev, struct mei_msg_hdr *header, |
| 130 | unsigned char *buf, unsigned long length) |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 131 | { |
Tomas Winkler | 169d133 | 2012-06-19 09:13:35 +0300 | [diff] [blame] | 132 | unsigned long rem, dw_cnt; |
| 133 | u32 *reg_buf = (u32 *)buf; |
| 134 | int i; |
| 135 | int empty_slots; |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 136 | |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 137 | |
| 138 | dev_dbg(&dev->pdev->dev, |
| 139 | "mei_write_message header=%08x.\n", |
| 140 | *((u32 *) header)); |
| 141 | |
Tomas Winkler | 169d133 | 2012-06-19 09:13:35 +0300 | [diff] [blame] | 142 | empty_slots = mei_count_empty_write_slots(dev); |
| 143 | dev_dbg(&dev->pdev->dev, "empty slots = %hu.\n", empty_slots); |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 144 | |
Tomas Winkler | 169d133 | 2012-06-19 09:13:35 +0300 | [diff] [blame] | 145 | dw_cnt = (length + sizeof(*header) + 3) / 4; |
| 146 | if (empty_slots < 0 || dw_cnt > empty_slots) |
Tomas Winkler | 1ccb7b6 | 2012-03-14 14:39:42 +0200 | [diff] [blame] | 147 | return -EIO; |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 148 | |
| 149 | mei_reg_write(dev, H_CB_WW, *((u32 *) header)); |
| 150 | |
Tomas Winkler | 169d133 | 2012-06-19 09:13:35 +0300 | [diff] [blame] | 151 | for (i = 0; i < length / 4; i++) |
| 152 | mei_reg_write(dev, H_CB_WW, reg_buf[i]); |
| 153 | |
| 154 | rem = length & 0x3; |
| 155 | if (rem > 0) { |
| 156 | u32 reg = 0; |
| 157 | memcpy(®, &buf[length - rem], rem); |
| 158 | mei_reg_write(dev, H_CB_WW, reg); |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 159 | } |
| 160 | |
Tomas Winkler | 169d133 | 2012-06-19 09:13:35 +0300 | [diff] [blame] | 161 | dev->host_hw_state = mei_hcsr_read(dev); |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 162 | dev->host_hw_state |= H_IG; |
| 163 | mei_hcsr_set(dev); |
| 164 | dev->me_hw_state = mei_mecsr_read(dev); |
| 165 | if ((dev->me_hw_state & ME_RDY_HRA) != ME_RDY_HRA) |
Tomas Winkler | 1ccb7b6 | 2012-03-14 14:39:42 +0200 | [diff] [blame] | 166 | return -EIO; |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 167 | |
Tomas Winkler | 1ccb7b6 | 2012-03-14 14:39:42 +0200 | [diff] [blame] | 168 | return 0; |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | /** |
| 172 | * mei_count_full_read_slots - counts read full slots. |
| 173 | * |
| 174 | * @dev: the device structure |
| 175 | * |
| 176 | * returns -1(ESLOTS_OVERFLOW) if overflow, otherwise filled slots count |
| 177 | */ |
| 178 | int mei_count_full_read_slots(struct mei_device *dev) |
| 179 | { |
| 180 | char read_ptr, write_ptr; |
| 181 | unsigned char buffer_depth, filled_slots; |
| 182 | |
| 183 | dev->me_hw_state = mei_mecsr_read(dev); |
| 184 | buffer_depth = (unsigned char)((dev->me_hw_state & ME_CBD_HRA) >> 24); |
| 185 | read_ptr = (char) ((dev->me_hw_state & ME_CBRP_HRA) >> 8); |
| 186 | write_ptr = (char) ((dev->me_hw_state & ME_CBWP_HRA) >> 16); |
| 187 | filled_slots = (unsigned char) (write_ptr - read_ptr); |
| 188 | |
| 189 | /* check for overflow */ |
| 190 | if (filled_slots > buffer_depth) |
| 191 | return -EOVERFLOW; |
| 192 | |
| 193 | dev_dbg(&dev->pdev->dev, "filled_slots =%08x\n", filled_slots); |
| 194 | return (int)filled_slots; |
| 195 | } |
| 196 | |
| 197 | /** |
| 198 | * mei_read_slots - reads a message from mei device. |
| 199 | * |
| 200 | * @dev: the device structure |
| 201 | * @buffer: message buffer will be written |
| 202 | * @buffer_length: message size will be read |
| 203 | */ |
Tomas Winkler | edf1eed | 2012-02-09 19:25:54 +0200 | [diff] [blame] | 204 | void mei_read_slots(struct mei_device *dev, unsigned char *buffer, |
| 205 | unsigned long buffer_length) |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 206 | { |
Tomas Winkler | edf1eed | 2012-02-09 19:25:54 +0200 | [diff] [blame] | 207 | u32 *reg_buf = (u32 *)buffer; |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 208 | |
Tomas Winkler | edf1eed | 2012-02-09 19:25:54 +0200 | [diff] [blame] | 209 | for (; buffer_length >= sizeof(u32); buffer_length -= sizeof(u32)) |
| 210 | *reg_buf++ = mei_mecbrw_read(dev); |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 211 | |
| 212 | if (buffer_length > 0) { |
Tomas Winkler | edf1eed | 2012-02-09 19:25:54 +0200 | [diff] [blame] | 213 | u32 reg = mei_mecbrw_read(dev); |
| 214 | memcpy(reg_buf, ®, buffer_length); |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | dev->host_hw_state |= H_IG; |
| 218 | mei_hcsr_set(dev); |
| 219 | } |
| 220 | |
| 221 | /** |
| 222 | * mei_flow_ctrl_creds - checks flow_control credentials. |
| 223 | * |
| 224 | * @dev: the device structure |
| 225 | * @cl: private data of the file object |
| 226 | * |
| 227 | * returns 1 if mei_flow_ctrl_creds >0, 0 - otherwise. |
| 228 | * -ENOENT if mei_cl is not present |
| 229 | * -EINVAL if single_recv_buf == 0 |
| 230 | */ |
| 231 | int mei_flow_ctrl_creds(struct mei_device *dev, struct mei_cl *cl) |
| 232 | { |
| 233 | int i; |
| 234 | |
Tomas Winkler | cf9673d | 2011-06-06 10:44:33 +0300 | [diff] [blame] | 235 | if (!dev->me_clients_num) |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 236 | return 0; |
| 237 | |
| 238 | if (cl->mei_flow_ctrl_creds > 0) |
| 239 | return 1; |
| 240 | |
Tomas Winkler | cf9673d | 2011-06-06 10:44:33 +0300 | [diff] [blame] | 241 | for (i = 0; i < dev->me_clients_num; i++) { |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 242 | struct mei_me_client *me_cl = &dev->me_clients[i]; |
| 243 | if (me_cl->client_id == cl->me_client_id) { |
| 244 | if (me_cl->mei_flow_ctrl_creds) { |
| 245 | if (WARN_ON(me_cl->props.single_recv_buf == 0)) |
| 246 | return -EINVAL; |
| 247 | return 1; |
| 248 | } else { |
| 249 | return 0; |
| 250 | } |
| 251 | } |
| 252 | } |
| 253 | return -ENOENT; |
| 254 | } |
| 255 | |
| 256 | /** |
| 257 | * mei_flow_ctrl_reduce - reduces flow_control. |
| 258 | * |
| 259 | * @dev: the device structure |
| 260 | * @cl: private data of the file object |
| 261 | * @returns |
| 262 | * 0 on success |
| 263 | * -ENOENT when me client is not found |
Justin P. Mattock | 5f9092f3 | 2012-03-12 07:18:09 -0700 | [diff] [blame] | 264 | * -EINVAL when ctrl credits are <= 0 |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 265 | */ |
| 266 | int mei_flow_ctrl_reduce(struct mei_device *dev, struct mei_cl *cl) |
| 267 | { |
| 268 | int i; |
| 269 | |
Tomas Winkler | cf9673d | 2011-06-06 10:44:33 +0300 | [diff] [blame] | 270 | if (!dev->me_clients_num) |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 271 | return -ENOENT; |
| 272 | |
Tomas Winkler | cf9673d | 2011-06-06 10:44:33 +0300 | [diff] [blame] | 273 | for (i = 0; i < dev->me_clients_num; i++) { |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 274 | struct mei_me_client *me_cl = &dev->me_clients[i]; |
| 275 | if (me_cl->client_id == cl->me_client_id) { |
| 276 | if (me_cl->props.single_recv_buf != 0) { |
| 277 | if (WARN_ON(me_cl->mei_flow_ctrl_creds <= 0)) |
| 278 | return -EINVAL; |
| 279 | dev->me_clients[i].mei_flow_ctrl_creds--; |
| 280 | } else { |
| 281 | if (WARN_ON(cl->mei_flow_ctrl_creds <= 0)) |
| 282 | return -EINVAL; |
| 283 | cl->mei_flow_ctrl_creds--; |
| 284 | } |
| 285 | return 0; |
| 286 | } |
| 287 | } |
| 288 | return -ENOENT; |
| 289 | } |
| 290 | |
| 291 | /** |
| 292 | * mei_send_flow_control - sends flow control to fw. |
| 293 | * |
| 294 | * @dev: the device structure |
| 295 | * @cl: private data of the file object |
| 296 | * |
Tomas Winkler | 1ccb7b6 | 2012-03-14 14:39:42 +0200 | [diff] [blame] | 297 | * This function returns -EIO on write failure |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 298 | */ |
| 299 | int mei_send_flow_control(struct mei_device *dev, struct mei_cl *cl) |
| 300 | { |
| 301 | struct mei_msg_hdr *mei_hdr; |
| 302 | struct hbm_flow_control *mei_flow_control; |
| 303 | |
| 304 | mei_hdr = (struct mei_msg_hdr *) &dev->wr_msg_buf[0]; |
| 305 | mei_hdr->host_addr = 0; |
| 306 | mei_hdr->me_addr = 0; |
| 307 | mei_hdr->length = sizeof(struct hbm_flow_control); |
| 308 | mei_hdr->msg_complete = 1; |
| 309 | mei_hdr->reserved = 0; |
| 310 | |
| 311 | mei_flow_control = (struct hbm_flow_control *) &dev->wr_msg_buf[1]; |
Julia Lawall | c056998 | 2011-09-16 08:57:33 +0200 | [diff] [blame] | 312 | memset(mei_flow_control, 0, sizeof(*mei_flow_control)); |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 313 | mei_flow_control->host_addr = cl->host_client_id; |
| 314 | mei_flow_control->me_addr = cl->me_client_id; |
Tomas Winkler | 1ca7e78 | 2012-02-26 23:18:57 +0200 | [diff] [blame] | 315 | mei_flow_control->hbm_cmd = MEI_FLOW_CONTROL_CMD; |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 316 | memset(mei_flow_control->reserved, 0, |
| 317 | sizeof(mei_flow_control->reserved)); |
| 318 | dev_dbg(&dev->pdev->dev, "sending flow control host client = %d, ME client = %d\n", |
Tomas Winkler | 1ccb7b6 | 2012-03-14 14:39:42 +0200 | [diff] [blame] | 319 | cl->host_client_id, cl->me_client_id); |
| 320 | |
| 321 | return mei_write_message(dev, mei_hdr, |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 322 | (unsigned char *) mei_flow_control, |
Tomas Winkler | 1ccb7b6 | 2012-03-14 14:39:42 +0200 | [diff] [blame] | 323 | sizeof(struct hbm_flow_control)); |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | /** |
| 327 | * mei_other_client_is_connecting - checks if other |
| 328 | * client with the same client id is connected. |
| 329 | * |
| 330 | * @dev: the device structure |
| 331 | * @cl: private data of the file object |
| 332 | * |
| 333 | * returns 1 if other client is connected, 0 - otherwise. |
| 334 | */ |
| 335 | int mei_other_client_is_connecting(struct mei_device *dev, |
| 336 | struct mei_cl *cl) |
| 337 | { |
| 338 | struct mei_cl *cl_pos = NULL; |
| 339 | struct mei_cl *cl_next = NULL; |
| 340 | |
| 341 | list_for_each_entry_safe(cl_pos, cl_next, &dev->file_list, link) { |
| 342 | if ((cl_pos->state == MEI_FILE_CONNECTING) && |
| 343 | (cl_pos != cl) && |
| 344 | cl->me_client_id == cl_pos->me_client_id) |
| 345 | return 1; |
| 346 | |
| 347 | } |
| 348 | return 0; |
| 349 | } |
| 350 | |
| 351 | /** |
| 352 | * mei_disconnect - sends disconnect message to fw. |
| 353 | * |
| 354 | * @dev: the device structure |
| 355 | * @cl: private data of the file object |
| 356 | * |
Tomas Winkler | 1ccb7b6 | 2012-03-14 14:39:42 +0200 | [diff] [blame] | 357 | * This function returns -EIO on write failure |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 358 | */ |
| 359 | int mei_disconnect(struct mei_device *dev, struct mei_cl *cl) |
| 360 | { |
| 361 | struct mei_msg_hdr *mei_hdr; |
| 362 | struct hbm_client_disconnect_request *mei_cli_disconnect; |
| 363 | |
| 364 | mei_hdr = (struct mei_msg_hdr *) &dev->wr_msg_buf[0]; |
| 365 | mei_hdr->host_addr = 0; |
| 366 | mei_hdr->me_addr = 0; |
| 367 | mei_hdr->length = sizeof(struct hbm_client_disconnect_request); |
| 368 | mei_hdr->msg_complete = 1; |
| 369 | mei_hdr->reserved = 0; |
| 370 | |
| 371 | mei_cli_disconnect = |
| 372 | (struct hbm_client_disconnect_request *) &dev->wr_msg_buf[1]; |
Julia Lawall | c056998 | 2011-09-16 08:57:33 +0200 | [diff] [blame] | 373 | memset(mei_cli_disconnect, 0, sizeof(*mei_cli_disconnect)); |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 374 | mei_cli_disconnect->host_addr = cl->host_client_id; |
| 375 | mei_cli_disconnect->me_addr = cl->me_client_id; |
Tomas Winkler | 1ca7e78 | 2012-02-26 23:18:57 +0200 | [diff] [blame] | 376 | mei_cli_disconnect->hbm_cmd = CLIENT_DISCONNECT_REQ_CMD; |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 377 | mei_cli_disconnect->reserved[0] = 0; |
| 378 | |
Tomas Winkler | 1ccb7b6 | 2012-03-14 14:39:42 +0200 | [diff] [blame] | 379 | return mei_write_message(dev, mei_hdr, |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 380 | (unsigned char *) mei_cli_disconnect, |
Tomas Winkler | 1ccb7b6 | 2012-03-14 14:39:42 +0200 | [diff] [blame] | 381 | sizeof(struct hbm_client_disconnect_request)); |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | /** |
| 385 | * mei_connect - sends connect message to fw. |
| 386 | * |
| 387 | * @dev: the device structure |
| 388 | * @cl: private data of the file object |
| 389 | * |
Tomas Winkler | 1ccb7b6 | 2012-03-14 14:39:42 +0200 | [diff] [blame] | 390 | * This function returns -EIO on write failure |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 391 | */ |
| 392 | int mei_connect(struct mei_device *dev, struct mei_cl *cl) |
| 393 | { |
| 394 | struct mei_msg_hdr *mei_hdr; |
| 395 | struct hbm_client_connect_request *mei_cli_connect; |
| 396 | |
| 397 | mei_hdr = (struct mei_msg_hdr *) &dev->wr_msg_buf[0]; |
| 398 | mei_hdr->host_addr = 0; |
| 399 | mei_hdr->me_addr = 0; |
| 400 | mei_hdr->length = sizeof(struct hbm_client_connect_request); |
| 401 | mei_hdr->msg_complete = 1; |
| 402 | mei_hdr->reserved = 0; |
| 403 | |
| 404 | mei_cli_connect = |
| 405 | (struct hbm_client_connect_request *) &dev->wr_msg_buf[1]; |
| 406 | mei_cli_connect->host_addr = cl->host_client_id; |
| 407 | mei_cli_connect->me_addr = cl->me_client_id; |
Tomas Winkler | 1ca7e78 | 2012-02-26 23:18:57 +0200 | [diff] [blame] | 408 | mei_cli_connect->hbm_cmd = CLIENT_CONNECT_REQ_CMD; |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 409 | mei_cli_connect->reserved = 0; |
| 410 | |
Tomas Winkler | 1ccb7b6 | 2012-03-14 14:39:42 +0200 | [diff] [blame] | 411 | return mei_write_message(dev, mei_hdr, |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 412 | (unsigned char *) mei_cli_connect, |
Tomas Winkler | 1ccb7b6 | 2012-03-14 14:39:42 +0200 | [diff] [blame] | 413 | sizeof(struct hbm_client_connect_request)); |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 414 | } |