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