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" |
Tomas Winkler | 9dc64d6 | 2013-01-08 23:07:17 +0200 | [diff] [blame] | 21 | #include "hw-me.h" |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 22 | |
Tomas Winkler | 3a65dd4 | 2012-12-25 19:06:06 +0200 | [diff] [blame] | 23 | /** |
| 24 | * mei_reg_read - Reads 32bit data from the mei device |
| 25 | * |
| 26 | * @dev: the device structure |
| 27 | * @offset: offset from which to read the data |
| 28 | * |
| 29 | * returns register value (u32) |
| 30 | */ |
| 31 | static inline u32 mei_reg_read(const struct mei_device *dev, |
| 32 | unsigned long offset) |
| 33 | { |
| 34 | return ioread32(dev->mem_addr + offset); |
| 35 | } |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 36 | |
| 37 | |
| 38 | /** |
Tomas Winkler | 3a65dd4 | 2012-12-25 19:06:06 +0200 | [diff] [blame] | 39 | * mei_reg_write - Writes 32bit data to the mei device |
| 40 | * |
| 41 | * @dev: the device structure |
| 42 | * @offset: offset from which to write the data |
| 43 | * @value: register value to write (u32) |
| 44 | */ |
| 45 | static inline void mei_reg_write(const struct mei_device *dev, |
| 46 | unsigned long offset, u32 value) |
| 47 | { |
| 48 | iowrite32(value, dev->mem_addr + offset); |
| 49 | } |
| 50 | |
| 51 | /** |
Tomas Winkler | d025284 | 2013-01-08 23:07:24 +0200 | [diff] [blame] | 52 | * mei_mecbrw_read - Reads 32bit data from ME circular buffer |
| 53 | * read window register |
Tomas Winkler | 3a65dd4 | 2012-12-25 19:06:06 +0200 | [diff] [blame] | 54 | * |
| 55 | * @dev: the device structure |
| 56 | * |
Tomas Winkler | d025284 | 2013-01-08 23:07:24 +0200 | [diff] [blame] | 57 | * returns ME_CB_RW register value (u32) |
Tomas Winkler | 3a65dd4 | 2012-12-25 19:06:06 +0200 | [diff] [blame] | 58 | */ |
Tomas Winkler | 3a65dd4 | 2012-12-25 19:06:06 +0200 | [diff] [blame] | 59 | u32 mei_mecbrw_read(const struct mei_device *dev) |
| 60 | { |
| 61 | return mei_reg_read(dev, ME_CB_RW); |
| 62 | } |
| 63 | /** |
| 64 | * mei_mecsr_read - Reads 32bit data from the ME CSR |
| 65 | * |
| 66 | * @dev: the device structure |
| 67 | * |
| 68 | * returns ME_CSR_HA register value (u32) |
| 69 | */ |
Tomas Winkler | e7e0c23 | 2013-01-08 23:07:31 +0200 | [diff] [blame] | 70 | static inline u32 mei_mecsr_read(const struct mei_device *dev) |
Tomas Winkler | 3a65dd4 | 2012-12-25 19:06:06 +0200 | [diff] [blame] | 71 | { |
| 72 | return mei_reg_read(dev, ME_CSR_HA); |
| 73 | } |
| 74 | |
| 75 | /** |
Tomas Winkler | d025284 | 2013-01-08 23:07:24 +0200 | [diff] [blame] | 76 | * mei_hcsr_read - Reads 32bit data from the host CSR |
| 77 | * |
| 78 | * @dev: the device structure |
| 79 | * |
| 80 | * returns H_CSR register value (u32) |
| 81 | */ |
Tomas Winkler | e7e0c23 | 2013-01-08 23:07:31 +0200 | [diff] [blame] | 82 | static inline u32 mei_hcsr_read(const struct mei_device *dev) |
Tomas Winkler | d025284 | 2013-01-08 23:07:24 +0200 | [diff] [blame] | 83 | { |
| 84 | return mei_reg_read(dev, H_CSR); |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * mei_hcsr_set - writes H_CSR register to the mei device, |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 89 | * and ignores the H_IS bit for it is write-one-to-zero. |
| 90 | * |
| 91 | * @dev: the device structure |
| 92 | */ |
Tomas Winkler | 88eb99f | 2013-01-08 23:07:30 +0200 | [diff] [blame] | 93 | static inline void mei_hcsr_set(struct mei_device *dev, u32 hcsr) |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 94 | { |
Tomas Winkler | 88eb99f | 2013-01-08 23:07:30 +0200 | [diff] [blame] | 95 | hcsr &= ~H_IS; |
| 96 | mei_reg_write(dev, H_CSR, hcsr); |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 97 | } |
| 98 | |
Tomas Winkler | e7e0c23 | 2013-01-08 23:07:31 +0200 | [diff] [blame] | 99 | |
| 100 | /** |
| 101 | * me_hw_config - configure hw dependent settings |
| 102 | * |
| 103 | * @dev: mei device |
| 104 | */ |
| 105 | void mei_hw_config(struct mei_device *dev) |
| 106 | { |
| 107 | u32 hcsr = mei_hcsr_read(dev); |
| 108 | /* Doesn't change in runtime */ |
| 109 | dev->hbuf_depth = (hcsr & H_CBD) >> 24; |
| 110 | } |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 111 | /** |
Tomas Winkler | d025284 | 2013-01-08 23:07:24 +0200 | [diff] [blame] | 112 | * mei_clear_interrupts - clear and stop interrupts |
Tomas Winkler | 3a65dd4 | 2012-12-25 19:06:06 +0200 | [diff] [blame] | 113 | * |
| 114 | * @dev: the device structure |
| 115 | */ |
| 116 | void mei_clear_interrupts(struct mei_device *dev) |
| 117 | { |
Tomas Winkler | 9ea73dd | 2013-01-08 23:07:28 +0200 | [diff] [blame] | 118 | u32 hcsr = mei_hcsr_read(dev); |
| 119 | if ((hcsr & H_IS) == H_IS) |
| 120 | mei_reg_write(dev, H_CSR, hcsr); |
Tomas Winkler | 3a65dd4 | 2012-12-25 19:06:06 +0200 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | /** |
| 124 | * mei_enable_interrupts - enables mei device interrupts |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 125 | * |
| 126 | * @dev: the device structure |
| 127 | */ |
| 128 | void mei_enable_interrupts(struct mei_device *dev) |
| 129 | { |
Tomas Winkler | 9ea73dd | 2013-01-08 23:07:28 +0200 | [diff] [blame] | 130 | u32 hcsr = mei_hcsr_read(dev); |
| 131 | hcsr |= H_IE; |
Tomas Winkler | 88eb99f | 2013-01-08 23:07:30 +0200 | [diff] [blame] | 132 | mei_hcsr_set(dev, hcsr); |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | /** |
Tomas Winkler | 3a65dd4 | 2012-12-25 19:06:06 +0200 | [diff] [blame] | 136 | * mei_disable_interrupts - disables mei device interrupts |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 137 | * |
| 138 | * @dev: the device structure |
| 139 | */ |
| 140 | void mei_disable_interrupts(struct mei_device *dev) |
| 141 | { |
Tomas Winkler | 9ea73dd | 2013-01-08 23:07:28 +0200 | [diff] [blame] | 142 | u32 hcsr = mei_hcsr_read(dev); |
| 143 | hcsr &= ~H_IE; |
Tomas Winkler | 88eb99f | 2013-01-08 23:07:30 +0200 | [diff] [blame] | 144 | mei_hcsr_set(dev, hcsr); |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 145 | } |
| 146 | |
Tomas Winkler | adfba32 | 2013-01-08 23:07:27 +0200 | [diff] [blame] | 147 | /** |
| 148 | * mei_hw_reset - resets fw via mei csr register. |
| 149 | * |
| 150 | * @dev: the device structure |
| 151 | * @interrupts_enabled: if interrupt should be enabled after reset. |
| 152 | */ |
| 153 | void mei_hw_reset(struct mei_device *dev, bool intr_enable) |
| 154 | { |
| 155 | u32 hcsr = mei_hcsr_read(dev); |
| 156 | |
| 157 | dev_dbg(&dev->pdev->dev, "before reset HCSR = 0x%08x.\n", hcsr); |
| 158 | |
| 159 | hcsr |= (H_RST | H_IG); |
| 160 | |
| 161 | if (intr_enable) |
| 162 | hcsr |= H_IE; |
| 163 | else |
| 164 | hcsr &= ~H_IE; |
| 165 | |
Tomas Winkler | 88eb99f | 2013-01-08 23:07:30 +0200 | [diff] [blame] | 166 | mei_hcsr_set(dev, hcsr); |
Tomas Winkler | adfba32 | 2013-01-08 23:07:27 +0200 | [diff] [blame] | 167 | |
Tomas Winkler | 88eb99f | 2013-01-08 23:07:30 +0200 | [diff] [blame] | 168 | hcsr = mei_hcsr_read(dev) | H_IG; |
Tomas Winkler | adfba32 | 2013-01-08 23:07:27 +0200 | [diff] [blame] | 169 | hcsr &= ~H_RST; |
Tomas Winkler | adfba32 | 2013-01-08 23:07:27 +0200 | [diff] [blame] | 170 | |
Tomas Winkler | 88eb99f | 2013-01-08 23:07:30 +0200 | [diff] [blame] | 171 | mei_hcsr_set(dev, hcsr); |
Tomas Winkler | adfba32 | 2013-01-08 23:07:27 +0200 | [diff] [blame] | 172 | |
| 173 | hcsr = mei_hcsr_read(dev); |
| 174 | |
| 175 | dev_dbg(&dev->pdev->dev, "current HCSR = 0x%08x.\n", hcsr); |
| 176 | } |
| 177 | |
Tomas Winkler | 115ba28 | 2013-01-08 23:07:29 +0200 | [diff] [blame] | 178 | /** |
| 179 | * mei_host_set_ready - enable device |
| 180 | * |
| 181 | * @dev - mei device |
| 182 | * returns bool |
| 183 | */ |
| 184 | |
| 185 | void mei_host_set_ready(struct mei_device *dev) |
| 186 | { |
| 187 | dev->host_hw_state |= H_IE | H_IG | H_RDY; |
Tomas Winkler | 88eb99f | 2013-01-08 23:07:30 +0200 | [diff] [blame] | 188 | mei_hcsr_set(dev, dev->host_hw_state); |
Tomas Winkler | 115ba28 | 2013-01-08 23:07:29 +0200 | [diff] [blame] | 189 | } |
| 190 | /** |
| 191 | * mei_host_is_ready - check whether the host has turned ready |
| 192 | * |
| 193 | * @dev - mei device |
| 194 | * returns bool |
| 195 | */ |
| 196 | bool mei_host_is_ready(struct mei_device *dev) |
| 197 | { |
Tomas Winkler | e7e0c23 | 2013-01-08 23:07:31 +0200 | [diff] [blame] | 198 | dev->host_hw_state = mei_hcsr_read(dev); |
Tomas Winkler | 115ba28 | 2013-01-08 23:07:29 +0200 | [diff] [blame] | 199 | return (dev->host_hw_state & H_RDY) == H_RDY; |
| 200 | } |
| 201 | |
| 202 | /** |
| 203 | * mei_me_is_ready - check whether the me has turned ready |
| 204 | * |
| 205 | * @dev - mei device |
| 206 | * returns bool |
| 207 | */ |
| 208 | bool mei_me_is_ready(struct mei_device *dev) |
| 209 | { |
Tomas Winkler | e7e0c23 | 2013-01-08 23:07:31 +0200 | [diff] [blame] | 210 | dev->me_hw_state = mei_mecsr_read(dev); |
Tomas Winkler | 115ba28 | 2013-01-08 23:07:29 +0200 | [diff] [blame] | 211 | return (dev->me_hw_state & ME_RDY_HRA) == ME_RDY_HRA; |
| 212 | } |
Tomas Winkler | 3a65dd4 | 2012-12-25 19:06:06 +0200 | [diff] [blame] | 213 | |
| 214 | /** |
| 215 | * mei_interrupt_quick_handler - The ISR of the MEI device |
| 216 | * |
| 217 | * @irq: The irq number |
| 218 | * @dev_id: pointer to the device structure |
| 219 | * |
| 220 | * returns irqreturn_t |
| 221 | */ |
| 222 | irqreturn_t mei_interrupt_quick_handler(int irq, void *dev_id) |
| 223 | { |
| 224 | struct mei_device *dev = (struct mei_device *) dev_id; |
| 225 | u32 csr_reg = mei_hcsr_read(dev); |
| 226 | |
| 227 | if ((csr_reg & H_IS) != H_IS) |
| 228 | return IRQ_NONE; |
| 229 | |
| 230 | /* clear H_IS bit in H_CSR */ |
| 231 | mei_reg_write(dev, H_CSR, csr_reg); |
| 232 | |
| 233 | return IRQ_WAKE_THREAD; |
| 234 | } |
| 235 | |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 236 | /** |
Tomas Winkler | 726917f | 2012-06-25 23:46:28 +0300 | [diff] [blame] | 237 | * mei_hbuf_filled_slots - gets number of device filled buffer slots |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 238 | * |
Sedat Dilek | 7353f85 | 2013-01-17 19:54:15 +0100 | [diff] [blame] | 239 | * @dev: the device structure |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 240 | * |
| 241 | * returns number of filled slots |
| 242 | */ |
Tomas Winkler | 726917f | 2012-06-25 23:46:28 +0300 | [diff] [blame] | 243 | static unsigned char mei_hbuf_filled_slots(struct mei_device *dev) |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 244 | { |
| 245 | char read_ptr, write_ptr; |
| 246 | |
Tomas Winkler | 726917f | 2012-06-25 23:46:28 +0300 | [diff] [blame] | 247 | dev->host_hw_state = mei_hcsr_read(dev); |
| 248 | |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 249 | read_ptr = (char) ((dev->host_hw_state & H_CBRP) >> 8); |
| 250 | write_ptr = (char) ((dev->host_hw_state & H_CBWP) >> 16); |
| 251 | |
| 252 | return (unsigned char) (write_ptr - read_ptr); |
| 253 | } |
| 254 | |
| 255 | /** |
Tomas Winkler | 726917f | 2012-06-25 23:46:28 +0300 | [diff] [blame] | 256 | * mei_hbuf_is_empty - checks if host buffer is empty. |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 257 | * |
| 258 | * @dev: the device structure |
| 259 | * |
Tomas Winkler | 726917f | 2012-06-25 23:46:28 +0300 | [diff] [blame] | 260 | * returns true if empty, false - otherwise. |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 261 | */ |
Tomas Winkler | 726917f | 2012-06-25 23:46:28 +0300 | [diff] [blame] | 262 | bool mei_hbuf_is_empty(struct mei_device *dev) |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 263 | { |
Tomas Winkler | 726917f | 2012-06-25 23:46:28 +0300 | [diff] [blame] | 264 | return mei_hbuf_filled_slots(dev) == 0; |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | /** |
Tomas Winkler | 726917f | 2012-06-25 23:46:28 +0300 | [diff] [blame] | 268 | * mei_hbuf_empty_slots - counts write empty slots. |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 269 | * |
| 270 | * @dev: the device structure |
| 271 | * |
| 272 | * returns -1(ESLOTS_OVERFLOW) if overflow, otherwise empty slots count |
| 273 | */ |
Tomas Winkler | 726917f | 2012-06-25 23:46:28 +0300 | [diff] [blame] | 274 | int mei_hbuf_empty_slots(struct mei_device *dev) |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 275 | { |
Tomas Winkler | 24aadc8 | 2012-06-25 23:46:27 +0300 | [diff] [blame] | 276 | unsigned char filled_slots, empty_slots; |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 277 | |
Tomas Winkler | 726917f | 2012-06-25 23:46:28 +0300 | [diff] [blame] | 278 | filled_slots = mei_hbuf_filled_slots(dev); |
Tomas Winkler | 24aadc8 | 2012-06-25 23:46:27 +0300 | [diff] [blame] | 279 | empty_slots = dev->hbuf_depth - filled_slots; |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 280 | |
| 281 | /* check for overflow */ |
Tomas Winkler | 24aadc8 | 2012-06-25 23:46:27 +0300 | [diff] [blame] | 282 | if (filled_slots > dev->hbuf_depth) |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 283 | return -EOVERFLOW; |
| 284 | |
| 285 | return empty_slots; |
| 286 | } |
| 287 | |
| 288 | /** |
| 289 | * mei_write_message - writes a message to mei device. |
| 290 | * |
| 291 | * @dev: the device structure |
Sedat Dilek | 7353f85 | 2013-01-17 19:54:15 +0100 | [diff] [blame] | 292 | * @header: mei HECI header of message |
Tomas Winkler | 438763f | 2012-12-25 19:05:59 +0200 | [diff] [blame] | 293 | * @buf: message payload will be written |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 294 | * |
Tomas Winkler | 1ccb7b6 | 2012-03-14 14:39:42 +0200 | [diff] [blame] | 295 | * This function returns -EIO if write has failed |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 296 | */ |
Tomas Winkler | 169d133 | 2012-06-19 09:13:35 +0300 | [diff] [blame] | 297 | 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] | 298 | unsigned char *buf) |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 299 | { |
Tomas Winkler | 169d133 | 2012-06-19 09:13:35 +0300 | [diff] [blame] | 300 | unsigned long rem, dw_cnt; |
Tomas Winkler | 438763f | 2012-12-25 19:05:59 +0200 | [diff] [blame] | 301 | unsigned long length = header->length; |
Tomas Winkler | 169d133 | 2012-06-19 09:13:35 +0300 | [diff] [blame] | 302 | u32 *reg_buf = (u32 *)buf; |
Tomas Winkler | 88eb99f | 2013-01-08 23:07:30 +0200 | [diff] [blame] | 303 | u32 hcsr; |
Tomas Winkler | 169d133 | 2012-06-19 09:13:35 +0300 | [diff] [blame] | 304 | int i; |
| 305 | int empty_slots; |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 306 | |
Tomas Winkler | 15d4acc | 2012-12-25 19:06:00 +0200 | [diff] [blame] | 307 | dev_dbg(&dev->pdev->dev, MEI_HDR_FMT, MEI_HDR_PRM(header)); |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 308 | |
Tomas Winkler | 726917f | 2012-06-25 23:46:28 +0300 | [diff] [blame] | 309 | empty_slots = mei_hbuf_empty_slots(dev); |
Tomas Winkler | 169d133 | 2012-06-19 09:13:35 +0300 | [diff] [blame] | 310 | dev_dbg(&dev->pdev->dev, "empty slots = %hu.\n", empty_slots); |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 311 | |
Tomas Winkler | 7bdf72d | 2012-07-04 19:24:52 +0300 | [diff] [blame] | 312 | dw_cnt = mei_data2slots(length); |
Tomas Winkler | 169d133 | 2012-06-19 09:13:35 +0300 | [diff] [blame] | 313 | if (empty_slots < 0 || dw_cnt > empty_slots) |
Tomas Winkler | 1ccb7b6 | 2012-03-14 14:39:42 +0200 | [diff] [blame] | 314 | return -EIO; |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 315 | |
| 316 | mei_reg_write(dev, H_CB_WW, *((u32 *) header)); |
| 317 | |
Tomas Winkler | 169d133 | 2012-06-19 09:13:35 +0300 | [diff] [blame] | 318 | for (i = 0; i < length / 4; i++) |
| 319 | mei_reg_write(dev, H_CB_WW, reg_buf[i]); |
| 320 | |
| 321 | rem = length & 0x3; |
| 322 | if (rem > 0) { |
| 323 | u32 reg = 0; |
| 324 | memcpy(®, &buf[length - rem], rem); |
| 325 | mei_reg_write(dev, H_CB_WW, reg); |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 326 | } |
| 327 | |
Tomas Winkler | 88eb99f | 2013-01-08 23:07:30 +0200 | [diff] [blame] | 328 | hcsr = mei_hcsr_read(dev) | H_IG; |
| 329 | mei_hcsr_set(dev, hcsr); |
Tomas Winkler | 115ba28 | 2013-01-08 23:07:29 +0200 | [diff] [blame] | 330 | if (!mei_me_is_ready(dev)) |
Tomas Winkler | 1ccb7b6 | 2012-03-14 14:39:42 +0200 | [diff] [blame] | 331 | return -EIO; |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 332 | |
Tomas Winkler | 1ccb7b6 | 2012-03-14 14:39:42 +0200 | [diff] [blame] | 333 | return 0; |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | /** |
| 337 | * mei_count_full_read_slots - counts read full slots. |
| 338 | * |
| 339 | * @dev: the device structure |
| 340 | * |
| 341 | * returns -1(ESLOTS_OVERFLOW) if overflow, otherwise filled slots count |
| 342 | */ |
| 343 | int mei_count_full_read_slots(struct mei_device *dev) |
| 344 | { |
| 345 | char read_ptr, write_ptr; |
| 346 | unsigned char buffer_depth, filled_slots; |
| 347 | |
| 348 | dev->me_hw_state = mei_mecsr_read(dev); |
| 349 | buffer_depth = (unsigned char)((dev->me_hw_state & ME_CBD_HRA) >> 24); |
| 350 | read_ptr = (char) ((dev->me_hw_state & ME_CBRP_HRA) >> 8); |
| 351 | write_ptr = (char) ((dev->me_hw_state & ME_CBWP_HRA) >> 16); |
| 352 | filled_slots = (unsigned char) (write_ptr - read_ptr); |
| 353 | |
| 354 | /* check for overflow */ |
| 355 | if (filled_slots > buffer_depth) |
| 356 | return -EOVERFLOW; |
| 357 | |
| 358 | dev_dbg(&dev->pdev->dev, "filled_slots =%08x\n", filled_slots); |
| 359 | return (int)filled_slots; |
| 360 | } |
| 361 | |
| 362 | /** |
| 363 | * mei_read_slots - reads a message from mei device. |
| 364 | * |
| 365 | * @dev: the device structure |
| 366 | * @buffer: message buffer will be written |
| 367 | * @buffer_length: message size will be read |
| 368 | */ |
Tomas Winkler | edf1eed | 2012-02-09 19:25:54 +0200 | [diff] [blame] | 369 | void mei_read_slots(struct mei_device *dev, unsigned char *buffer, |
| 370 | unsigned long buffer_length) |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 371 | { |
Tomas Winkler | edf1eed | 2012-02-09 19:25:54 +0200 | [diff] [blame] | 372 | u32 *reg_buf = (u32 *)buffer; |
Tomas Winkler | 88eb99f | 2013-01-08 23:07:30 +0200 | [diff] [blame] | 373 | u32 hcsr; |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 374 | |
Tomas Winkler | edf1eed | 2012-02-09 19:25:54 +0200 | [diff] [blame] | 375 | for (; buffer_length >= sizeof(u32); buffer_length -= sizeof(u32)) |
| 376 | *reg_buf++ = mei_mecbrw_read(dev); |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 377 | |
| 378 | if (buffer_length > 0) { |
Tomas Winkler | edf1eed | 2012-02-09 19:25:54 +0200 | [diff] [blame] | 379 | u32 reg = mei_mecbrw_read(dev); |
| 380 | memcpy(reg_buf, ®, buffer_length); |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 381 | } |
| 382 | |
Tomas Winkler | 88eb99f | 2013-01-08 23:07:30 +0200 | [diff] [blame] | 383 | hcsr = mei_hcsr_read(dev) | H_IG; |
| 384 | mei_hcsr_set(dev, hcsr); |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 385 | } |
| 386 | |