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