Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Intel Management Engine Interface (Intel MEI) Linux driver |
| 4 | * Copyright (c) 2003-2012, Intel Corporation. |
| 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/kernel.h> |
| 18 | #include <linux/fs.h> |
| 19 | #include <linux/errno.h> |
| 20 | #include <linux/types.h> |
| 21 | #include <linux/fcntl.h> |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 22 | #include <linux/ioctl.h> |
| 23 | #include <linux/cdev.h> |
| 24 | #include <linux/list.h> |
| 25 | #include <linux/delay.h> |
| 26 | #include <linux/sched.h> |
| 27 | #include <linux/uuid.h> |
| 28 | #include <linux/jiffies.h> |
| 29 | #include <linux/uaccess.h> |
Tomas Winkler | 1f18035 | 2014-09-29 16:31:46 +0300 | [diff] [blame] | 30 | #include <linux/slab.h> |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 31 | |
Tomas Winkler | 47a7380 | 2012-12-25 19:06:03 +0200 | [diff] [blame] | 32 | #include <linux/mei.h> |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 33 | |
| 34 | #include "mei_dev.h" |
Tomas Winkler | 0edb23f | 2013-01-08 23:07:12 +0200 | [diff] [blame] | 35 | #include "hbm.h" |
Tomas Winkler | 90e0b5f | 2013-01-08 23:07:14 +0200 | [diff] [blame] | 36 | #include "client.h" |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 37 | |
Tomas Winkler | 1a1aca4 | 2013-01-08 23:07:21 +0200 | [diff] [blame] | 38 | const uuid_le mei_amthif_guid = UUID_LE(0x12f80028, 0xb4b7, 0x4b2d, |
| 39 | 0xac, 0xa8, 0x46, 0xe0, |
| 40 | 0xff, 0x65, 0x81, 0x4c); |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 41 | |
| 42 | /** |
| 43 | * mei_amthif_reset_params - initializes mei device iamthif |
| 44 | * |
| 45 | * @dev: the device structure |
| 46 | */ |
| 47 | void mei_amthif_reset_params(struct mei_device *dev) |
| 48 | { |
| 49 | /* reset iamthif parameters. */ |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 50 | dev->iamthif_canceled = false; |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 51 | dev->iamthif_state = MEI_IAMTHIF_IDLE; |
Alexander Usyskin | 4a70457 | 2013-09-02 13:29:47 +0300 | [diff] [blame] | 52 | dev->iamthif_stall_timer = 0; |
Tomas Winkler | 22f96a0 | 2013-09-16 23:44:47 +0300 | [diff] [blame] | 53 | dev->iamthif_open_count = 0; |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | /** |
Masanari Iida | 393b148 | 2013-04-05 01:05:05 +0900 | [diff] [blame] | 57 | * mei_amthif_host_init - mei initialization amthif client. |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 58 | * |
| 59 | * @dev: the device structure |
Alexander Usyskin | d49ed64 | 2015-05-04 09:43:54 +0300 | [diff] [blame] | 60 | * @me_cl: me client |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 61 | * |
Alexander Usyskin | ce23139 | 2014-09-29 16:31:50 +0300 | [diff] [blame] | 62 | * Return: 0 on success, <0 on failure. |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 63 | */ |
Alexander Usyskin | d49ed64 | 2015-05-04 09:43:54 +0300 | [diff] [blame] | 64 | int mei_amthif_host_init(struct mei_device *dev, struct mei_me_client *me_cl) |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 65 | { |
Tomas Winkler | 781d0d8 | 2013-01-08 23:07:22 +0200 | [diff] [blame] | 66 | struct mei_cl *cl = &dev->iamthif_cl; |
Tomas Winkler | d320832 | 2014-08-24 12:08:55 +0300 | [diff] [blame] | 67 | int ret; |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 68 | |
Alexander Usyskin | e728ae2 | 2016-07-26 01:06:09 +0300 | [diff] [blame] | 69 | mutex_lock(&dev->device_lock); |
| 70 | |
| 71 | if (mei_cl_is_connected(cl)) { |
| 72 | ret = 0; |
| 73 | goto out; |
| 74 | } |
Alexander Usyskin | 025fb79 | 2016-02-07 23:35:43 +0200 | [diff] [blame] | 75 | |
Tomas Winkler | 6222f7b | 2013-01-08 23:07:23 +0200 | [diff] [blame] | 76 | dev->iamthif_state = MEI_IAMTHIF_IDLE; |
| 77 | |
Tomas Winkler | 781d0d8 | 2013-01-08 23:07:22 +0200 | [diff] [blame] | 78 | mei_cl_init(cl, dev); |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 79 | |
Alexander Usyskin | 7851e00 | 2016-02-07 23:35:40 +0200 | [diff] [blame] | 80 | ret = mei_cl_link(cl); |
Tomas Winkler | 781d0d8 | 2013-01-08 23:07:22 +0200 | [diff] [blame] | 81 | if (ret < 0) { |
Tomas Winkler | 79563db | 2015-01-11 00:07:16 +0200 | [diff] [blame] | 82 | dev_err(dev->dev, "amthif: failed cl_link %d\n", ret); |
Alexander Usyskin | e728ae2 | 2016-07-26 01:06:09 +0300 | [diff] [blame] | 83 | goto out; |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 84 | } |
Tomas Winkler | 781d0d8 | 2013-01-08 23:07:22 +0200 | [diff] [blame] | 85 | |
Alexander Usyskin | d49ed64 | 2015-05-04 09:43:54 +0300 | [diff] [blame] | 86 | ret = mei_cl_connect(cl, me_cl, NULL); |
Tomas Winkler | 6409285 | 2014-02-17 15:13:21 +0200 | [diff] [blame] | 87 | |
Alexander Usyskin | e728ae2 | 2016-07-26 01:06:09 +0300 | [diff] [blame] | 88 | out: |
| 89 | mutex_unlock(&dev->device_lock); |
Tomas Winkler | 6409285 | 2014-02-17 15:13:21 +0200 | [diff] [blame] | 90 | return ret; |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | /** |
Tomas Winkler | c54bf3a | 2015-02-10 10:39:39 +0200 | [diff] [blame] | 94 | * mei_amthif_read_start - queue message for sending read credential |
| 95 | * |
| 96 | * @cl: host client |
Tomas Winkler | 3030dc0 | 2016-07-26 01:06:05 +0300 | [diff] [blame] | 97 | * @fp: file pointer of message recipient |
Tomas Winkler | c54bf3a | 2015-02-10 10:39:39 +0200 | [diff] [blame] | 98 | * |
| 99 | * Return: 0 on success, <0 on failure. |
| 100 | */ |
Tomas Winkler | 3030dc0 | 2016-07-26 01:06:05 +0300 | [diff] [blame] | 101 | static int mei_amthif_read_start(struct mei_cl *cl, const struct file *fp) |
Tomas Winkler | c54bf3a | 2015-02-10 10:39:39 +0200 | [diff] [blame] | 102 | { |
| 103 | struct mei_device *dev = cl->dev; |
| 104 | struct mei_cl_cb *cb; |
Tomas Winkler | c54bf3a | 2015-02-10 10:39:39 +0200 | [diff] [blame] | 105 | |
Tomas Winkler | 3030dc0 | 2016-07-26 01:06:05 +0300 | [diff] [blame] | 106 | cb = mei_cl_enqueue_ctrl_wr_cb(cl, mei_cl_mtu(cl), MEI_FOP_READ, fp); |
Alexander Usyskin | 35eda92 | 2016-05-24 16:03:40 -0400 | [diff] [blame] | 107 | if (!cb) |
| 108 | return -ENOMEM; |
Tomas Winkler | c54bf3a | 2015-02-10 10:39:39 +0200 | [diff] [blame] | 109 | |
Alexander Usyskin | 46978ad | 2016-07-26 01:06:03 +0300 | [diff] [blame] | 110 | cl->rx_flow_ctrl_creds++; |
Tomas Winkler | c54bf3a | 2015-02-10 10:39:39 +0200 | [diff] [blame] | 111 | |
Tomas Winkler | c54bf3a | 2015-02-10 10:39:39 +0200 | [diff] [blame] | 112 | dev->iamthif_state = MEI_IAMTHIF_READING; |
Alexander Usyskin | 97d549b | 2016-06-16 17:58:57 +0300 | [diff] [blame] | 113 | cl->fp = cb->fp; |
Tomas Winkler | c54bf3a | 2015-02-10 10:39:39 +0200 | [diff] [blame] | 114 | |
| 115 | return 0; |
Tomas Winkler | c54bf3a | 2015-02-10 10:39:39 +0200 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | /** |
Alexander Usyskin | ce23139 | 2014-09-29 16:31:50 +0300 | [diff] [blame] | 119 | * mei_amthif_run_next_cmd - send next amt command from queue |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 120 | * |
| 121 | * @dev: the device structure |
Tomas Winkler | 8660172 | 2015-02-10 10:39:40 +0200 | [diff] [blame] | 122 | * |
| 123 | * Return: 0 on success, <0 on failure. |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 124 | */ |
Tomas Winkler | 8660172 | 2015-02-10 10:39:40 +0200 | [diff] [blame] | 125 | int mei_amthif_run_next_cmd(struct mei_device *dev) |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 126 | { |
Tomas Winkler | 8660172 | 2015-02-10 10:39:40 +0200 | [diff] [blame] | 127 | struct mei_cl *cl = &dev->iamthif_cl; |
Alexander Usyskin | 05e314e | 2014-08-14 17:22:21 +0300 | [diff] [blame] | 128 | struct mei_cl_cb *cb; |
Alexander Usyskin | 2239338 | 2016-05-24 16:03:39 -0400 | [diff] [blame] | 129 | int ret; |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 130 | |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 131 | dev->iamthif_canceled = false; |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 132 | |
Tomas Winkler | 2bf94cab | 2014-09-29 16:31:42 +0300 | [diff] [blame] | 133 | dev_dbg(dev->dev, "complete amthif cmd_list cb.\n"); |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 134 | |
Alexander Usyskin | 140c755 | 2014-10-02 13:39:31 +0300 | [diff] [blame] | 135 | cb = list_first_entry_or_null(&dev->amthif_cmd_list.list, |
| 136 | typeof(*cb), list); |
Alexander Usyskin | 2239338 | 2016-05-24 16:03:39 -0400 | [diff] [blame] | 137 | if (!cb) { |
| 138 | dev->iamthif_state = MEI_IAMTHIF_IDLE; |
Alexander Usyskin | 97d549b | 2016-06-16 17:58:57 +0300 | [diff] [blame] | 139 | cl->fp = NULL; |
Tomas Winkler | 8660172 | 2015-02-10 10:39:40 +0200 | [diff] [blame] | 140 | return 0; |
Alexander Usyskin | 2239338 | 2016-05-24 16:03:39 -0400 | [diff] [blame] | 141 | } |
Tomas Winkler | 8660172 | 2015-02-10 10:39:40 +0200 | [diff] [blame] | 142 | |
Tomas Winkler | c54bf3a | 2015-02-10 10:39:39 +0200 | [diff] [blame] | 143 | list_del_init(&cb->list); |
Alexander Usyskin | 2239338 | 2016-05-24 16:03:39 -0400 | [diff] [blame] | 144 | dev->iamthif_state = MEI_IAMTHIF_WRITING; |
Alexander Usyskin | 97d549b | 2016-06-16 17:58:57 +0300 | [diff] [blame] | 145 | cl->fp = cb->fp; |
Alexander Usyskin | 2239338 | 2016-05-24 16:03:39 -0400 | [diff] [blame] | 146 | |
| 147 | ret = mei_cl_write(cl, cb, false); |
| 148 | if (ret < 0) |
| 149 | return ret; |
| 150 | |
| 151 | if (cb->completed) |
| 152 | cb->status = mei_amthif_read_start(cl, cb->fp); |
| 153 | |
| 154 | return 0; |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 155 | } |
| 156 | |
Tomas Winkler | 8660172 | 2015-02-10 10:39:40 +0200 | [diff] [blame] | 157 | /** |
| 158 | * mei_amthif_write - write amthif data to amthif client |
| 159 | * |
| 160 | * @cl: host client |
| 161 | * @cb: mei call back struct |
| 162 | * |
| 163 | * Return: 0 on success, <0 on failure. |
| 164 | */ |
| 165 | int mei_amthif_write(struct mei_cl *cl, struct mei_cl_cb *cb) |
| 166 | { |
| 167 | |
Tomas Winkler | 77b007b | 2016-02-07 23:35:27 +0200 | [diff] [blame] | 168 | struct mei_device *dev = cl->dev; |
Tomas Winkler | 8660172 | 2015-02-10 10:39:40 +0200 | [diff] [blame] | 169 | |
Tomas Winkler | 8660172 | 2015-02-10 10:39:40 +0200 | [diff] [blame] | 170 | list_add_tail(&cb->list, &dev->amthif_cmd_list.list); |
Alexander Usyskin | 5cf8b2a | 2016-02-07 23:35:25 +0200 | [diff] [blame] | 171 | |
| 172 | /* |
| 173 | * The previous request is still in processing, queue this one. |
| 174 | */ |
Alexander Usyskin | ca455fa | 2016-05-24 16:03:35 -0400 | [diff] [blame] | 175 | if (dev->iamthif_state != MEI_IAMTHIF_IDLE) |
Alexander Usyskin | 5cf8b2a | 2016-02-07 23:35:25 +0200 | [diff] [blame] | 176 | return 0; |
| 177 | |
Tomas Winkler | 8660172 | 2015-02-10 10:39:40 +0200 | [diff] [blame] | 178 | return mei_amthif_run_next_cmd(dev); |
| 179 | } |
Tomas Winkler | 744f0f2 | 2012-11-11 17:38:02 +0200 | [diff] [blame] | 180 | |
Tomas Winkler | 1d9013f | 2015-03-27 00:27:57 +0200 | [diff] [blame] | 181 | /** |
| 182 | * mei_amthif_poll - the amthif poll function |
| 183 | * |
Tomas Winkler | 1d9013f | 2015-03-27 00:27:57 +0200 | [diff] [blame] | 184 | * @file: pointer to file structure |
| 185 | * @wait: pointer to poll_table structure |
| 186 | * |
| 187 | * Return: poll mask |
| 188 | * |
| 189 | * Locking: called under "dev->device_lock" lock |
| 190 | */ |
Alexander Usyskin | ca455fa | 2016-05-24 16:03:35 -0400 | [diff] [blame] | 191 | unsigned int mei_amthif_poll(struct file *file, poll_table *wait) |
Tomas Winkler | 744f0f2 | 2012-11-11 17:38:02 +0200 | [diff] [blame] | 192 | { |
Alexander Usyskin | ca455fa | 2016-05-24 16:03:35 -0400 | [diff] [blame] | 193 | struct mei_cl *cl = file->private_data; |
| 194 | struct mei_cl_cb *cb = mei_cl_read_cb(cl, file); |
Tomas Winkler | 744f0f2 | 2012-11-11 17:38:02 +0200 | [diff] [blame] | 195 | unsigned int mask = 0; |
Tomas Winkler | b950ac1 | 2013-07-25 20:15:53 +0300 | [diff] [blame] | 196 | |
Alexander Usyskin | ca455fa | 2016-05-24 16:03:35 -0400 | [diff] [blame] | 197 | poll_wait(file, &cl->rx_wait, wait); |
| 198 | if (cb) |
Tomas Winkler | 1d9013f | 2015-03-27 00:27:57 +0200 | [diff] [blame] | 199 | mask |= POLLIN | POLLRDNORM; |
Tomas Winkler | b950ac1 | 2013-07-25 20:15:53 +0300 | [diff] [blame] | 200 | |
Tomas Winkler | 744f0f2 | 2012-11-11 17:38:02 +0200 | [diff] [blame] | 201 | return mask; |
| 202 | } |
| 203 | |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 204 | /** |
Tomas Winkler | 9d09819 | 2014-02-19 17:35:48 +0200 | [diff] [blame] | 205 | * mei_amthif_irq_write - write iamthif command in irq thread context. |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 206 | * |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 207 | * @cl: private data of the file object. |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 208 | * @cb: callback block. |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 209 | * @cmpl_list: complete list. |
| 210 | * |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 211 | * Return: 0, OK; otherwise, error. |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 212 | */ |
Tomas Winkler | 9d09819 | 2014-02-19 17:35:48 +0200 | [diff] [blame] | 213 | int mei_amthif_irq_write(struct mei_cl *cl, struct mei_cl_cb *cb, |
| 214 | struct mei_cl_cb *cmpl_list) |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 215 | { |
Tomas Winkler | 8660172 | 2015-02-10 10:39:40 +0200 | [diff] [blame] | 216 | int ret; |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 217 | |
Tomas Winkler | 8660172 | 2015-02-10 10:39:40 +0200 | [diff] [blame] | 218 | ret = mei_cl_irq_write(cl, cb, cmpl_list); |
| 219 | if (ret) |
| 220 | return ret; |
Tomas Winkler | 136698e | 2013-09-16 23:44:44 +0300 | [diff] [blame] | 221 | |
Tomas Winkler | 8660172 | 2015-02-10 10:39:40 +0200 | [diff] [blame] | 222 | if (cb->completed) |
Tomas Winkler | 62e8e6a | 2016-02-07 23:35:24 +0200 | [diff] [blame] | 223 | cb->status = mei_amthif_read_start(cl, cb->fp); |
Tomas Winkler | 24c656e | 2012-11-18 15:13:17 +0200 | [diff] [blame] | 224 | |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 225 | return 0; |
| 226 | } |
| 227 | |
| 228 | /** |
Alexander Usyskin | ce23139 | 2014-09-29 16:31:50 +0300 | [diff] [blame] | 229 | * mei_amthif_irq_read_msg - read routine after ISR to |
Tomas Winkler | 1a1aca4 | 2013-01-08 23:07:21 +0200 | [diff] [blame] | 230 | * handle the read amthif message |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 231 | * |
Tomas Winkler | db4756f | 2015-02-10 10:39:37 +0200 | [diff] [blame] | 232 | * @cl: mei client |
Tomas Winkler | 1a1aca4 | 2013-01-08 23:07:21 +0200 | [diff] [blame] | 233 | * @mei_hdr: header of amthif message |
Tomas Winkler | 331e418 | 2015-02-10 10:39:41 +0200 | [diff] [blame] | 234 | * @cmpl_list: completed callbacks list |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 235 | * |
Tomas Winkler | 331e418 | 2015-02-10 10:39:41 +0200 | [diff] [blame] | 236 | * Return: -ENODEV if cb is NULL 0 otherwise; error message is in cb->status |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 237 | */ |
Tomas Winkler | db4756f | 2015-02-10 10:39:37 +0200 | [diff] [blame] | 238 | int mei_amthif_irq_read_msg(struct mei_cl *cl, |
Tomas Winkler | 5ceb46e | 2013-04-19 21:16:53 +0300 | [diff] [blame] | 239 | struct mei_msg_hdr *mei_hdr, |
Tomas Winkler | 331e418 | 2015-02-10 10:39:41 +0200 | [diff] [blame] | 240 | struct mei_cl_cb *cmpl_list) |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 241 | { |
Tomas Winkler | db4756f | 2015-02-10 10:39:37 +0200 | [diff] [blame] | 242 | struct mei_device *dev; |
Tomas Winkler | 331e418 | 2015-02-10 10:39:41 +0200 | [diff] [blame] | 243 | int ret; |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 244 | |
Tomas Winkler | db4756f | 2015-02-10 10:39:37 +0200 | [diff] [blame] | 245 | dev = cl->dev; |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 246 | |
Alexander Usyskin | 9d04ee1 | 2016-04-17 12:16:04 -0400 | [diff] [blame] | 247 | if (dev->iamthif_state != MEI_IAMTHIF_READING) { |
| 248 | mei_irq_discard_msg(dev, mei_hdr); |
Tomas Winkler | 331e418 | 2015-02-10 10:39:41 +0200 | [diff] [blame] | 249 | return 0; |
Alexander Usyskin | 9d04ee1 | 2016-04-17 12:16:04 -0400 | [diff] [blame] | 250 | } |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 251 | |
Tomas Winkler | 331e418 | 2015-02-10 10:39:41 +0200 | [diff] [blame] | 252 | ret = mei_cl_irq_read_msg(cl, mei_hdr, cmpl_list); |
| 253 | if (ret) |
| 254 | return ret; |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 255 | |
| 256 | if (!mei_hdr->msg_complete) |
| 257 | return 0; |
| 258 | |
Tomas Winkler | 2bf94cab | 2014-09-29 16:31:42 +0300 | [diff] [blame] | 259 | dev_dbg(dev->dev, "completed amthif read.\n "); |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 260 | dev->iamthif_stall_timer = 0; |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 261 | |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 262 | return 0; |
| 263 | } |
| 264 | |
| 265 | /** |
| 266 | * mei_amthif_complete - complete amthif callback. |
| 267 | * |
Tomas Winkler | 9abd8b3 | 2016-02-07 23:35:26 +0200 | [diff] [blame] | 268 | * @cl: host client |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 269 | * @cb: callback block. |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 270 | */ |
Tomas Winkler | 9abd8b3 | 2016-02-07 23:35:26 +0200 | [diff] [blame] | 271 | void mei_amthif_complete(struct mei_cl *cl, struct mei_cl_cb *cb) |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 272 | { |
Tomas Winkler | 9abd8b3 | 2016-02-07 23:35:26 +0200 | [diff] [blame] | 273 | struct mei_device *dev = cl->dev; |
Tomas Winkler | c54bf3a | 2015-02-10 10:39:39 +0200 | [diff] [blame] | 274 | |
Alexander Usyskin | 32a1dc1 | 2016-05-24 16:03:36 -0400 | [diff] [blame] | 275 | dev_dbg(dev->dev, "completing amthif call back.\n"); |
| 276 | switch (cb->fop_type) { |
| 277 | case MEI_FOP_WRITE: |
Tomas Winkler | c54bf3a | 2015-02-10 10:39:39 +0200 | [diff] [blame] | 278 | if (!cb->status) { |
| 279 | dev->iamthif_stall_timer = MEI_IAMTHIF_STALL_TIMER; |
Alexander Usyskin | 1892fc2 | 2016-09-25 13:25:31 +0300 | [diff] [blame] | 280 | mei_schedule_stall_timer(dev); |
Tomas Winkler | c54bf3a | 2015-02-10 10:39:39 +0200 | [diff] [blame] | 281 | mei_io_cb_free(cb); |
| 282 | return; |
| 283 | } |
Alexander Usyskin | 32a1dc1 | 2016-05-24 16:03:36 -0400 | [diff] [blame] | 284 | dev->iamthif_state = MEI_IAMTHIF_IDLE; |
Alexander Usyskin | 97d549b | 2016-06-16 17:58:57 +0300 | [diff] [blame] | 285 | cl->fp = NULL; |
Alexander Usyskin | 32a1dc1 | 2016-05-24 16:03:36 -0400 | [diff] [blame] | 286 | if (!dev->iamthif_canceled) { |
| 287 | /* |
| 288 | * in case of error enqueue the write cb to complete |
| 289 | * read list so it can be propagated to the reader |
| 290 | */ |
| 291 | list_add_tail(&cb->list, &cl->rd_completed); |
| 292 | wake_up_interruptible(&cl->rx_wait); |
| 293 | } else { |
| 294 | mei_io_cb_free(cb); |
| 295 | } |
| 296 | break; |
| 297 | case MEI_FOP_READ: |
| 298 | if (!dev->iamthif_canceled) { |
| 299 | list_add_tail(&cb->list, &cl->rd_completed); |
| 300 | dev_dbg(dev->dev, "amthif read completed\n"); |
| 301 | wake_up_interruptible(&cl->rx_wait); |
| 302 | } else { |
| 303 | mei_io_cb_free(cb); |
| 304 | } |
| 305 | |
Alexander Usyskin | 32a1dc1 | 2016-05-24 16:03:36 -0400 | [diff] [blame] | 306 | dev->iamthif_stall_timer = 0; |
| 307 | mei_amthif_run_next_cmd(dev); |
| 308 | break; |
| 309 | default: |
| 310 | WARN_ON(1); |
Tomas Winkler | c54bf3a | 2015-02-10 10:39:39 +0200 | [diff] [blame] | 311 | } |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 312 | } |
| 313 | |
Tomas Winkler | a562d5c | 2012-11-11 17:38:01 +0200 | [diff] [blame] | 314 | /** |
| 315 | * mei_clear_list - removes all callbacks associated with file |
| 316 | * from mei_cb_list |
| 317 | * |
Tomas Winkler | a562d5c | 2012-11-11 17:38:01 +0200 | [diff] [blame] | 318 | * @file: file structure |
| 319 | * @mei_cb_list: callbacks list |
| 320 | * |
| 321 | * mei_clear_list is called to clear resources associated with file |
| 322 | * when application calls close function or Ctrl-C was pressed |
Tomas Winkler | a562d5c | 2012-11-11 17:38:01 +0200 | [diff] [blame] | 323 | */ |
Alexander Usyskin | c85dba9 | 2016-06-16 17:58:59 +0300 | [diff] [blame] | 324 | static void mei_clear_list(const struct file *file, |
| 325 | struct list_head *mei_cb_list) |
Tomas Winkler | a562d5c | 2012-11-11 17:38:01 +0200 | [diff] [blame] | 326 | { |
Tomas Winkler | 928fa66 | 2015-02-10 10:39:45 +0200 | [diff] [blame] | 327 | struct mei_cl_cb *cb, *next; |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 328 | |
Alexander Usyskin | 32a1dc1 | 2016-05-24 16:03:36 -0400 | [diff] [blame] | 329 | list_for_each_entry_safe(cb, next, mei_cb_list, list) |
| 330 | if (file == cb->fp) |
Tomas Winkler | 928fa66 | 2015-02-10 10:39:45 +0200 | [diff] [blame] | 331 | mei_io_cb_free(cb); |
Tomas Winkler | a562d5c | 2012-11-11 17:38:01 +0200 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | /** |
Tomas Winkler | a562d5c | 2012-11-11 17:38:01 +0200 | [diff] [blame] | 335 | * mei_amthif_release - the release function |
| 336 | * |
Masanari Iida | 393b148 | 2013-04-05 01:05:05 +0900 | [diff] [blame] | 337 | * @dev: device structure |
Tomas Winkler | a562d5c | 2012-11-11 17:38:01 +0200 | [diff] [blame] | 338 | * @file: pointer to file structure |
| 339 | * |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 340 | * Return: 0 on success, <0 on error |
Tomas Winkler | a562d5c | 2012-11-11 17:38:01 +0200 | [diff] [blame] | 341 | */ |
| 342 | int mei_amthif_release(struct mei_device *dev, struct file *file) |
| 343 | { |
Alexander Usyskin | 97d549b | 2016-06-16 17:58:57 +0300 | [diff] [blame] | 344 | struct mei_cl *cl = file->private_data; |
| 345 | |
Tomas Winkler | 22f96a0 | 2013-09-16 23:44:47 +0300 | [diff] [blame] | 346 | if (dev->iamthif_open_count > 0) |
| 347 | dev->iamthif_open_count--; |
Tomas Winkler | a562d5c | 2012-11-11 17:38:01 +0200 | [diff] [blame] | 348 | |
Alexander Usyskin | 97d549b | 2016-06-16 17:58:57 +0300 | [diff] [blame] | 349 | if (cl->fp == file && dev->iamthif_state != MEI_IAMTHIF_IDLE) { |
Tomas Winkler | a562d5c | 2012-11-11 17:38:01 +0200 | [diff] [blame] | 350 | |
Tomas Winkler | 2bf94cab | 2014-09-29 16:31:42 +0300 | [diff] [blame] | 351 | dev_dbg(dev->dev, "amthif canceled iamthif state %d\n", |
Tomas Winkler | a562d5c | 2012-11-11 17:38:01 +0200 | [diff] [blame] | 352 | dev->iamthif_state); |
| 353 | dev->iamthif_canceled = true; |
Tomas Winkler | a562d5c | 2012-11-11 17:38:01 +0200 | [diff] [blame] | 354 | } |
| 355 | |
Alexander Usyskin | c85dba9 | 2016-06-16 17:58:59 +0300 | [diff] [blame] | 356 | mei_clear_list(file, &dev->amthif_cmd_list.list); |
| 357 | mei_clear_list(file, &cl->rd_completed); |
| 358 | mei_clear_list(file, &dev->ctrl_rd_list.list); |
Tomas Winkler | a562d5c | 2012-11-11 17:38:01 +0200 | [diff] [blame] | 359 | |
| 360 | return 0; |
| 361 | } |