Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +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 | 91f01c6 | 2011-05-15 13:43:44 +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 | |
Tomas Winkler | 40e0b67 | 2013-03-27 16:58:30 +0200 | [diff] [blame] | 17 | #include <linux/export.h> |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 18 | #include <linux/pci.h> |
| 19 | #include <linux/sched.h> |
| 20 | #include <linux/wait.h> |
| 21 | #include <linux/delay.h> |
| 22 | |
Tomas Winkler | 4f3afe1 | 2012-05-09 16:38:59 +0300 | [diff] [blame] | 23 | #include <linux/mei.h> |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 24 | |
Tomas Winkler | 47a7380 | 2012-12-25 19:06:03 +0200 | [diff] [blame] | 25 | #include "mei_dev.h" |
Tomas Winkler | aafae7e | 2013-03-11 18:27:03 +0200 | [diff] [blame] | 26 | #include "hbm.h" |
Tomas Winkler | 90e0b5f | 2013-01-08 23:07:14 +0200 | [diff] [blame] | 27 | #include "client.h" |
Tomas Winkler | 47a7380 | 2012-12-25 19:06:03 +0200 | [diff] [blame] | 28 | |
Tomas Winkler | b210d75 | 2012-08-07 00:03:56 +0300 | [diff] [blame] | 29 | const char *mei_dev_state_str(int state) |
| 30 | { |
| 31 | #define MEI_DEV_STATE(state) case MEI_DEV_##state: return #state |
| 32 | switch (state) { |
| 33 | MEI_DEV_STATE(INITIALIZING); |
| 34 | MEI_DEV_STATE(INIT_CLIENTS); |
| 35 | MEI_DEV_STATE(ENABLED); |
Bill Nottingham | 0cfee51 | 2013-04-19 22:01:36 +0300 | [diff] [blame] | 36 | MEI_DEV_STATE(RESETTING); |
Tomas Winkler | b210d75 | 2012-08-07 00:03:56 +0300 | [diff] [blame] | 37 | MEI_DEV_STATE(DISABLED); |
Tomas Winkler | b210d75 | 2012-08-07 00:03:56 +0300 | [diff] [blame] | 38 | MEI_DEV_STATE(POWER_DOWN); |
| 39 | MEI_DEV_STATE(POWER_UP); |
| 40 | default: |
Masanari Iida | 8b513d0 | 2013-05-21 23:13:12 +0900 | [diff] [blame] | 41 | return "unknown"; |
Tomas Winkler | b210d75 | 2012-08-07 00:03:56 +0300 | [diff] [blame] | 42 | } |
| 43 | #undef MEI_DEV_STATE |
| 44 | } |
| 45 | |
Tomas Winkler | 33ec082 | 2014-01-12 00:36:09 +0200 | [diff] [blame] | 46 | |
| 47 | /** |
| 48 | * mei_cancel_work. Cancel mei background jobs |
| 49 | * |
| 50 | * @dev: the device structure |
| 51 | * |
| 52 | * returns 0 on success or < 0 if the reset hasn't succeeded |
| 53 | */ |
| 54 | void mei_cancel_work(struct mei_device *dev) |
| 55 | { |
| 56 | cancel_work_sync(&dev->init_work); |
| 57 | cancel_work_sync(&dev->reset_work); |
| 58 | |
| 59 | cancel_delayed_work(&dev->timer_work); |
| 60 | } |
| 61 | EXPORT_SYMBOL_GPL(mei_cancel_work); |
| 62 | |
| 63 | /** |
| 64 | * mei_reset - resets host and fw. |
| 65 | * |
| 66 | * @dev: the device structure |
| 67 | */ |
| 68 | int mei_reset(struct mei_device *dev) |
| 69 | { |
| 70 | enum mei_dev_state state = dev->dev_state; |
| 71 | bool interrupts_enabled; |
| 72 | int ret; |
| 73 | |
| 74 | if (state != MEI_DEV_INITIALIZING && |
| 75 | state != MEI_DEV_DISABLED && |
| 76 | state != MEI_DEV_POWER_DOWN && |
Alexander Usyskin | 04dd366 | 2014-03-31 17:59:23 +0300 | [diff] [blame] | 77 | state != MEI_DEV_POWER_UP) { |
| 78 | struct mei_fw_status fw_status; |
| 79 | mei_fw_status(dev, &fw_status); |
| 80 | dev_warn(&dev->pdev->dev, |
| 81 | "unexpected reset: dev_state = %s " FW_STS_FMT "\n", |
| 82 | mei_dev_state_str(state), FW_STS_PRM(fw_status)); |
| 83 | } |
Tomas Winkler | 33ec082 | 2014-01-12 00:36:09 +0200 | [diff] [blame] | 84 | |
| 85 | /* we're already in reset, cancel the init timer |
| 86 | * if the reset was called due the hbm protocol error |
| 87 | * we need to call it before hw start |
| 88 | * so the hbm watchdog won't kick in |
| 89 | */ |
| 90 | mei_hbm_idle(dev); |
| 91 | |
| 92 | /* enter reset flow */ |
| 93 | interrupts_enabled = state != MEI_DEV_POWER_DOWN; |
| 94 | dev->dev_state = MEI_DEV_RESETTING; |
| 95 | |
Tomas Winkler | 6adb8ef | 2014-01-12 00:36:10 +0200 | [diff] [blame] | 96 | dev->reset_count++; |
| 97 | if (dev->reset_count > MEI_MAX_CONSEC_RESET) { |
| 98 | dev_err(&dev->pdev->dev, "reset: reached maximal consecutive resets: disabling the device\n"); |
| 99 | dev->dev_state = MEI_DEV_DISABLED; |
| 100 | return -ENODEV; |
| 101 | } |
| 102 | |
Tomas Winkler | 33ec082 | 2014-01-12 00:36:09 +0200 | [diff] [blame] | 103 | ret = mei_hw_reset(dev, interrupts_enabled); |
| 104 | /* fall through and remove the sw state even if hw reset has failed */ |
| 105 | |
| 106 | /* no need to clean up software state in case of power up */ |
| 107 | if (state != MEI_DEV_INITIALIZING && |
| 108 | state != MEI_DEV_POWER_UP) { |
| 109 | |
| 110 | /* remove all waiting requests */ |
| 111 | mei_cl_all_write_clear(dev); |
| 112 | |
| 113 | mei_cl_all_disconnect(dev); |
| 114 | |
| 115 | /* wake up all readers and writers so they can be interrupted */ |
| 116 | mei_cl_all_wakeup(dev); |
| 117 | |
| 118 | /* remove entry if already in list */ |
| 119 | dev_dbg(&dev->pdev->dev, "remove iamthif and wd from the file list.\n"); |
| 120 | mei_cl_unlink(&dev->wd_cl); |
| 121 | mei_cl_unlink(&dev->iamthif_cl); |
| 122 | mei_amthif_reset_params(dev); |
Tomas Winkler | 33ec082 | 2014-01-12 00:36:09 +0200 | [diff] [blame] | 123 | } |
| 124 | |
Tomas Winkler | 84b3294 | 2014-05-07 16:51:28 +0300 | [diff] [blame] | 125 | mei_hbm_reset(dev); |
Tomas Winkler | 33ec082 | 2014-01-12 00:36:09 +0200 | [diff] [blame] | 126 | |
Tomas Winkler | 33ec082 | 2014-01-12 00:36:09 +0200 | [diff] [blame] | 127 | dev->rd_msg_hdr = 0; |
| 128 | dev->wd_pending = false; |
| 129 | |
| 130 | if (ret) { |
| 131 | dev_err(&dev->pdev->dev, "hw_reset failed ret = %d\n", ret); |
Tomas Winkler | 33ec082 | 2014-01-12 00:36:09 +0200 | [diff] [blame] | 132 | return ret; |
| 133 | } |
| 134 | |
| 135 | if (state == MEI_DEV_POWER_DOWN) { |
| 136 | dev_dbg(&dev->pdev->dev, "powering down: end of reset\n"); |
| 137 | dev->dev_state = MEI_DEV_DISABLED; |
| 138 | return 0; |
| 139 | } |
| 140 | |
| 141 | ret = mei_hw_start(dev); |
| 142 | if (ret) { |
| 143 | dev_err(&dev->pdev->dev, "hw_start failed ret = %d\n", ret); |
Tomas Winkler | 33ec082 | 2014-01-12 00:36:09 +0200 | [diff] [blame] | 144 | return ret; |
| 145 | } |
| 146 | |
| 147 | dev_dbg(&dev->pdev->dev, "link is established start sending messages.\n"); |
| 148 | |
| 149 | dev->dev_state = MEI_DEV_INIT_CLIENTS; |
| 150 | ret = mei_hbm_start_req(dev); |
| 151 | if (ret) { |
| 152 | dev_err(&dev->pdev->dev, "hbm_start failed ret = %d\n", ret); |
Tomas Winkler | 7d93e58 | 2014-01-14 23:10:10 +0200 | [diff] [blame] | 153 | dev->dev_state = MEI_DEV_RESETTING; |
Tomas Winkler | 33ec082 | 2014-01-12 00:36:09 +0200 | [diff] [blame] | 154 | return ret; |
| 155 | } |
| 156 | |
| 157 | return 0; |
| 158 | } |
| 159 | EXPORT_SYMBOL_GPL(mei_reset); |
| 160 | |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 161 | /** |
Tomas Winkler | c4d589b | 2013-03-27 16:58:28 +0200 | [diff] [blame] | 162 | * mei_start - initializes host and fw to start work. |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 163 | * |
| 164 | * @dev: the device structure |
| 165 | * |
| 166 | * returns 0 on success, <0 on failure. |
| 167 | */ |
Tomas Winkler | c4d589b | 2013-03-27 16:58:28 +0200 | [diff] [blame] | 168 | int mei_start(struct mei_device *dev) |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 169 | { |
Tomas Winkler | 7d93e58 | 2014-01-14 23:10:10 +0200 | [diff] [blame] | 170 | int ret; |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 171 | mutex_lock(&dev->device_lock); |
| 172 | |
Tomas Winkler | 33ec082 | 2014-01-12 00:36:09 +0200 | [diff] [blame] | 173 | /* acknowledge interrupt and stop interrupts */ |
Tomas Winkler | 3a65dd4 | 2012-12-25 19:06:06 +0200 | [diff] [blame] | 174 | mei_clear_interrupts(dev); |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 175 | |
Tomas Winkler | e7e0c23 | 2013-01-08 23:07:31 +0200 | [diff] [blame] | 176 | mei_hw_config(dev); |
Tomas Winkler | 24aadc8 | 2012-06-25 23:46:27 +0300 | [diff] [blame] | 177 | |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 178 | dev_dbg(&dev->pdev->dev, "reset in start the mei device.\n"); |
| 179 | |
Tomas Winkler | 6adb8ef | 2014-01-12 00:36:10 +0200 | [diff] [blame] | 180 | dev->reset_count = 0; |
Tomas Winkler | 7d93e58 | 2014-01-14 23:10:10 +0200 | [diff] [blame] | 181 | do { |
| 182 | dev->dev_state = MEI_DEV_INITIALIZING; |
| 183 | ret = mei_reset(dev); |
Tomas Winkler | 33ec082 | 2014-01-12 00:36:09 +0200 | [diff] [blame] | 184 | |
Tomas Winkler | 7d93e58 | 2014-01-14 23:10:10 +0200 | [diff] [blame] | 185 | if (ret == -ENODEV || dev->dev_state == MEI_DEV_DISABLED) { |
| 186 | dev_err(&dev->pdev->dev, "reset failed ret = %d", ret); |
| 187 | goto err; |
| 188 | } |
| 189 | } while (ret); |
| 190 | |
| 191 | /* we cannot start the device w/o hbm start message completed */ |
Tomas Winkler | 33ec082 | 2014-01-12 00:36:09 +0200 | [diff] [blame] | 192 | if (dev->dev_state == MEI_DEV_DISABLED) { |
| 193 | dev_err(&dev->pdev->dev, "reset failed"); |
| 194 | goto err; |
| 195 | } |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 196 | |
Tomas Winkler | 9b0d5ef | 2013-04-18 23:03:48 +0300 | [diff] [blame] | 197 | if (mei_hbm_start_wait(dev)) { |
| 198 | dev_err(&dev->pdev->dev, "HBM haven't started"); |
Tomas Winkler | e7e0c23 | 2013-01-08 23:07:31 +0200 | [diff] [blame] | 199 | goto err; |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 200 | } |
| 201 | |
Tomas Winkler | e7e0c23 | 2013-01-08 23:07:31 +0200 | [diff] [blame] | 202 | if (!mei_host_is_ready(dev)) { |
| 203 | dev_err(&dev->pdev->dev, "host is not ready.\n"); |
| 204 | goto err; |
| 205 | } |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 206 | |
Tomas Winkler | 827eef5 | 2013-02-06 14:06:41 +0200 | [diff] [blame] | 207 | if (!mei_hw_is_ready(dev)) { |
Tomas Winkler | e7e0c23 | 2013-01-08 23:07:31 +0200 | [diff] [blame] | 208 | dev_err(&dev->pdev->dev, "ME is not ready.\n"); |
| 209 | goto err; |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 210 | } |
| 211 | |
Tomas Winkler | 2c9b48a | 2013-06-16 09:16:31 +0300 | [diff] [blame] | 212 | if (!mei_hbm_version_is_supported(dev)) { |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 213 | dev_dbg(&dev->pdev->dev, "MEI start failed.\n"); |
Tomas Winkler | e7e0c23 | 2013-01-08 23:07:31 +0200 | [diff] [blame] | 214 | goto err; |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 215 | } |
| 216 | |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 217 | dev_dbg(&dev->pdev->dev, "link layer has been established.\n"); |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 218 | |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 219 | mutex_unlock(&dev->device_lock); |
Tomas Winkler | e7e0c23 | 2013-01-08 23:07:31 +0200 | [diff] [blame] | 220 | return 0; |
| 221 | err: |
| 222 | dev_err(&dev->pdev->dev, "link layer initialization failed.\n"); |
| 223 | dev->dev_state = MEI_DEV_DISABLED; |
| 224 | mutex_unlock(&dev->device_lock); |
| 225 | return -ENODEV; |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 226 | } |
Tomas Winkler | 40e0b67 | 2013-03-27 16:58:30 +0200 | [diff] [blame] | 227 | EXPORT_SYMBOL_GPL(mei_start); |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 228 | |
Tomas Winkler | 544f946 | 2014-01-08 20:19:21 +0200 | [diff] [blame] | 229 | /** |
Tomas Winkler | 33ec082 | 2014-01-12 00:36:09 +0200 | [diff] [blame] | 230 | * mei_restart - restart device after suspend |
Tomas Winkler | 544f946 | 2014-01-08 20:19:21 +0200 | [diff] [blame] | 231 | * |
| 232 | * @dev: the device structure |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 233 | * |
Tomas Winkler | 33ec082 | 2014-01-12 00:36:09 +0200 | [diff] [blame] | 234 | * returns 0 on success or -ENODEV if the restart hasn't succeeded |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 235 | */ |
Tomas Winkler | 33ec082 | 2014-01-12 00:36:09 +0200 | [diff] [blame] | 236 | int mei_restart(struct mei_device *dev) |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 237 | { |
Tomas Winkler | 33ec082 | 2014-01-12 00:36:09 +0200 | [diff] [blame] | 238 | int err; |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 239 | |
Tomas Winkler | 33ec082 | 2014-01-12 00:36:09 +0200 | [diff] [blame] | 240 | mutex_lock(&dev->device_lock); |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 241 | |
Tomas Winkler | 33ec082 | 2014-01-12 00:36:09 +0200 | [diff] [blame] | 242 | mei_clear_interrupts(dev); |
Alexander Usyskin | f931f4f | 2013-10-21 22:05:43 +0300 | [diff] [blame] | 243 | |
Tomas Winkler | 33ec082 | 2014-01-12 00:36:09 +0200 | [diff] [blame] | 244 | dev->dev_state = MEI_DEV_POWER_UP; |
Tomas Winkler | 6adb8ef | 2014-01-12 00:36:10 +0200 | [diff] [blame] | 245 | dev->reset_count = 0; |
Tomas Winkler | 66ae460 | 2014-01-08 20:19:22 +0200 | [diff] [blame] | 246 | |
Tomas Winkler | 33ec082 | 2014-01-12 00:36:09 +0200 | [diff] [blame] | 247 | err = mei_reset(dev); |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 248 | |
Tomas Winkler | 33ec082 | 2014-01-12 00:36:09 +0200 | [diff] [blame] | 249 | mutex_unlock(&dev->device_lock); |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 250 | |
Tomas Winkler | 7d93e58 | 2014-01-14 23:10:10 +0200 | [diff] [blame] | 251 | if (err == -ENODEV || dev->dev_state == MEI_DEV_DISABLED) { |
| 252 | dev_err(&dev->pdev->dev, "device disabled = %d\n", err); |
Tomas Winkler | 33ec082 | 2014-01-12 00:36:09 +0200 | [diff] [blame] | 253 | return -ENODEV; |
Tomas Winkler | 7d93e58 | 2014-01-14 23:10:10 +0200 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | /* try to start again */ |
| 257 | if (err) |
| 258 | schedule_work(&dev->reset_work); |
| 259 | |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 260 | |
Tomas Winkler | 33ec082 | 2014-01-12 00:36:09 +0200 | [diff] [blame] | 261 | return 0; |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 262 | } |
Tomas Winkler | 33ec082 | 2014-01-12 00:36:09 +0200 | [diff] [blame] | 263 | EXPORT_SYMBOL_GPL(mei_restart); |
| 264 | |
Tomas Winkler | 544f946 | 2014-01-08 20:19:21 +0200 | [diff] [blame] | 265 | static void mei_reset_work(struct work_struct *work) |
| 266 | { |
| 267 | struct mei_device *dev = |
| 268 | container_of(work, struct mei_device, reset_work); |
Tomas Winkler | 7d93e58 | 2014-01-14 23:10:10 +0200 | [diff] [blame] | 269 | int ret; |
Tomas Winkler | 544f946 | 2014-01-08 20:19:21 +0200 | [diff] [blame] | 270 | |
| 271 | mutex_lock(&dev->device_lock); |
| 272 | |
Tomas Winkler | 7d93e58 | 2014-01-14 23:10:10 +0200 | [diff] [blame] | 273 | ret = mei_reset(dev); |
Tomas Winkler | 544f946 | 2014-01-08 20:19:21 +0200 | [diff] [blame] | 274 | |
| 275 | mutex_unlock(&dev->device_lock); |
Tomas Winkler | 33ec082 | 2014-01-12 00:36:09 +0200 | [diff] [blame] | 276 | |
Tomas Winkler | 7d93e58 | 2014-01-14 23:10:10 +0200 | [diff] [blame] | 277 | if (dev->dev_state == MEI_DEV_DISABLED) { |
| 278 | dev_err(&dev->pdev->dev, "device disabled = %d\n", ret); |
| 279 | return; |
| 280 | } |
| 281 | |
| 282 | /* retry reset in case of failure */ |
| 283 | if (ret) |
| 284 | schedule_work(&dev->reset_work); |
Tomas Winkler | 544f946 | 2014-01-08 20:19:21 +0200 | [diff] [blame] | 285 | } |
| 286 | |
Tomas Winkler | 7cb035d | 2013-03-10 13:56:08 +0200 | [diff] [blame] | 287 | void mei_stop(struct mei_device *dev) |
| 288 | { |
| 289 | dev_dbg(&dev->pdev->dev, "stopping the device.\n"); |
| 290 | |
Tomas Winkler | dc844b0 | 2013-11-11 13:26:06 +0200 | [diff] [blame] | 291 | mei_cancel_work(dev); |
| 292 | |
| 293 | mei_nfc_host_exit(dev); |
Samuel Ortiz | 5e85b36 | 2013-06-10 10:10:25 +0300 | [diff] [blame] | 294 | |
Tomas Winkler | 4870569 | 2014-02-17 15:13:19 +0200 | [diff] [blame] | 295 | mei_cl_bus_remove_devices(dev); |
| 296 | |
Tomas Winkler | 7cb035d | 2013-03-10 13:56:08 +0200 | [diff] [blame] | 297 | mutex_lock(&dev->device_lock); |
| 298 | |
Tomas Winkler | 7cb035d | 2013-03-10 13:56:08 +0200 | [diff] [blame] | 299 | mei_wd_stop(dev); |
| 300 | |
| 301 | dev->dev_state = MEI_DEV_POWER_DOWN; |
Tomas Winkler | 33ec082 | 2014-01-12 00:36:09 +0200 | [diff] [blame] | 302 | mei_reset(dev); |
Tomas Winkler | 7cb035d | 2013-03-10 13:56:08 +0200 | [diff] [blame] | 303 | |
| 304 | mutex_unlock(&dev->device_lock); |
| 305 | |
Tomas Winkler | 2e64712 | 2013-03-27 16:58:26 +0200 | [diff] [blame] | 306 | mei_watchdog_unregister(dev); |
Tomas Winkler | 7cb035d | 2013-03-10 13:56:08 +0200 | [diff] [blame] | 307 | } |
Tomas Winkler | 40e0b67 | 2013-03-27 16:58:30 +0200 | [diff] [blame] | 308 | EXPORT_SYMBOL_GPL(mei_stop); |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 309 | |
Tomas Winkler | a532bbe | 2014-03-18 22:52:01 +0200 | [diff] [blame] | 310 | /** |
| 311 | * mei_write_is_idle - check if the write queues are idle |
| 312 | * |
| 313 | * @dev: the device structure |
| 314 | * |
| 315 | * returns true of there is no pending write |
| 316 | */ |
| 317 | bool mei_write_is_idle(struct mei_device *dev) |
| 318 | { |
| 319 | bool idle = (dev->dev_state == MEI_DEV_ENABLED && |
| 320 | list_empty(&dev->ctrl_wr_list.list) && |
| 321 | list_empty(&dev->write_list.list)); |
Samuel Ortiz | c1174c0 | 2012-11-18 15:13:20 +0200 | [diff] [blame] | 322 | |
Tomas Winkler | a532bbe | 2014-03-18 22:52:01 +0200 | [diff] [blame] | 323 | dev_dbg(&dev->pdev->dev, "write pg: is idle[%d] state=%s ctrl=%d write=%d\n", |
| 324 | idle, |
| 325 | mei_dev_state_str(dev->dev_state), |
| 326 | list_empty(&dev->ctrl_wr_list.list), |
| 327 | list_empty(&dev->write_list.list)); |
| 328 | |
| 329 | return idle; |
| 330 | } |
| 331 | EXPORT_SYMBOL_GPL(mei_write_is_idle); |
Oren Weil | 91f01c6 | 2011-05-15 13:43:44 +0300 | [diff] [blame] | 332 | |
Alexander Usyskin | 8d929d4 | 2014-05-13 01:30:53 +0300 | [diff] [blame] | 333 | int mei_fw_status(struct mei_device *dev, struct mei_fw_status *fw_status) |
| 334 | { |
| 335 | int i; |
| 336 | const struct mei_fw_status *fw_src = &dev->cfg->fw_status; |
| 337 | |
| 338 | if (!fw_status) |
| 339 | return -EINVAL; |
| 340 | |
| 341 | fw_status->count = fw_src->count; |
| 342 | for (i = 0; i < fw_src->count && i < MEI_FW_STATUS_MAX; i++) { |
| 343 | int ret; |
| 344 | ret = pci_read_config_dword(dev->pdev, |
| 345 | fw_src->status[i], &fw_status->status[i]); |
| 346 | if (ret) |
| 347 | return ret; |
| 348 | } |
| 349 | |
| 350 | return 0; |
| 351 | } |
| 352 | EXPORT_SYMBOL_GPL(mei_fw_status); |
| 353 | |
| 354 | void mei_device_init(struct mei_device *dev, const struct mei_cfg *cfg) |
Tomas Winkler | 544f946 | 2014-01-08 20:19:21 +0200 | [diff] [blame] | 355 | { |
| 356 | /* setup our list array */ |
| 357 | INIT_LIST_HEAD(&dev->file_list); |
| 358 | INIT_LIST_HEAD(&dev->device_list); |
| 359 | mutex_init(&dev->device_lock); |
| 360 | init_waitqueue_head(&dev->wait_hw_ready); |
Tomas Winkler | 4fcbc99 | 2014-03-18 22:51:55 +0200 | [diff] [blame] | 361 | init_waitqueue_head(&dev->wait_pg); |
Tomas Winkler | 544f946 | 2014-01-08 20:19:21 +0200 | [diff] [blame] | 362 | init_waitqueue_head(&dev->wait_recvd_msg); |
| 363 | init_waitqueue_head(&dev->wait_stop_wd); |
| 364 | dev->dev_state = MEI_DEV_INITIALIZING; |
Tomas Winkler | 6adb8ef | 2014-01-12 00:36:10 +0200 | [diff] [blame] | 365 | dev->reset_count = 0; |
Tomas Winkler | 544f946 | 2014-01-08 20:19:21 +0200 | [diff] [blame] | 366 | |
| 367 | mei_io_list_init(&dev->read_list); |
| 368 | mei_io_list_init(&dev->write_list); |
| 369 | mei_io_list_init(&dev->write_waiting_list); |
| 370 | mei_io_list_init(&dev->ctrl_wr_list); |
| 371 | mei_io_list_init(&dev->ctrl_rd_list); |
| 372 | |
| 373 | INIT_DELAYED_WORK(&dev->timer_work, mei_timer); |
| 374 | INIT_WORK(&dev->init_work, mei_host_client_init); |
| 375 | INIT_WORK(&dev->reset_work, mei_reset_work); |
| 376 | |
| 377 | INIT_LIST_HEAD(&dev->wd_cl.link); |
| 378 | INIT_LIST_HEAD(&dev->iamthif_cl.link); |
| 379 | mei_io_list_init(&dev->amthif_cmd_list); |
| 380 | mei_io_list_init(&dev->amthif_rd_complete_list); |
| 381 | |
| 382 | bitmap_zero(dev->host_clients_map, MEI_CLIENTS_MAX); |
| 383 | dev->open_handle_count = 0; |
| 384 | |
| 385 | /* |
| 386 | * Reserving the first client ID |
| 387 | * 0: Reserved for MEI Bus Message communications |
| 388 | */ |
| 389 | bitmap_set(dev->host_clients_map, 0, 1); |
Tomas Winkler | 964a233 | 2014-03-18 22:51:59 +0200 | [diff] [blame] | 390 | |
| 391 | dev->pg_event = MEI_PG_EVENT_IDLE; |
Alexander Usyskin | 8d929d4 | 2014-05-13 01:30:53 +0300 | [diff] [blame] | 392 | dev->cfg = cfg; |
Tomas Winkler | 544f946 | 2014-01-08 20:19:21 +0200 | [diff] [blame] | 393 | } |
| 394 | EXPORT_SYMBOL_GPL(mei_device_init); |
| 395 | |