Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Intel Management Engine Interface (Intel MEI) Linux driver |
Tomas Winkler | 733ba91c | 2012-02-09 19:25:53 +0200 | [diff] [blame] | 4 | * Copyright (c) 2003-2012, Intel Corporation. |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +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 | |
Tomas Winkler | 40e0b67 | 2013-03-27 16:58:30 +0200 | [diff] [blame] | 18 | #include <linux/export.h> |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 19 | #include <linux/kthread.h> |
| 20 | #include <linux/interrupt.h> |
| 21 | #include <linux/fs.h> |
| 22 | #include <linux/jiffies.h> |
Tomas Winkler | 1f18035 | 2014-09-29 16:31:46 +0300 | [diff] [blame] | 23 | #include <linux/slab.h> |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 24 | |
Tomas Winkler | 4f3afe1 | 2012-05-09 16:38:59 +0300 | [diff] [blame] | 25 | #include <linux/mei.h> |
Tomas Winkler | 47a7380 | 2012-12-25 19:06:03 +0200 | [diff] [blame] | 26 | |
| 27 | #include "mei_dev.h" |
Tomas Winkler | 0edb23f | 2013-01-08 23:07:12 +0200 | [diff] [blame] | 28 | #include "hbm.h" |
Tomas Winkler | 90e0b5f | 2013-01-08 23:07:14 +0200 | [diff] [blame] | 29 | #include "client.h" |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 30 | |
| 31 | |
| 32 | /** |
Alexander Usyskin | 83ce074 | 2014-01-08 22:31:46 +0200 | [diff] [blame] | 33 | * mei_irq_compl_handler - dispatch complete handlers |
Tomas Winkler | 4c6e22b | 2013-03-17 11:41:20 +0200 | [diff] [blame] | 34 | * for the completed callbacks |
| 35 | * |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 36 | * @dev: mei device |
| 37 | * @compl_list: list of completed cbs |
Tomas Winkler | 4c6e22b | 2013-03-17 11:41:20 +0200 | [diff] [blame] | 38 | */ |
| 39 | void mei_irq_compl_handler(struct mei_device *dev, struct mei_cl_cb *compl_list) |
| 40 | { |
| 41 | struct mei_cl_cb *cb, *next; |
| 42 | struct mei_cl *cl; |
| 43 | |
| 44 | list_for_each_entry_safe(cb, next, &compl_list->list, list) { |
| 45 | cl = cb->cl; |
Tomas Winkler | c54bf3a | 2015-02-10 10:39:39 +0200 | [diff] [blame] | 46 | list_del_init(&cb->list); |
Tomas Winkler | 4c6e22b | 2013-03-17 11:41:20 +0200 | [diff] [blame] | 47 | |
Tomas Winkler | 2bf94cab | 2014-09-29 16:31:42 +0300 | [diff] [blame] | 48 | dev_dbg(dev->dev, "completing call back.\n"); |
Tomas Winkler | 4c6e22b | 2013-03-17 11:41:20 +0200 | [diff] [blame] | 49 | if (cl == &dev->iamthif_cl) |
| 50 | mei_amthif_complete(dev, cb); |
| 51 | else |
Tomas Winkler | db086fa | 2013-05-12 15:34:45 +0300 | [diff] [blame] | 52 | mei_cl_complete(cl, cb); |
Tomas Winkler | 4c6e22b | 2013-03-17 11:41:20 +0200 | [diff] [blame] | 53 | } |
| 54 | } |
Tomas Winkler | 40e0b67 | 2013-03-27 16:58:30 +0200 | [diff] [blame] | 55 | EXPORT_SYMBOL_GPL(mei_irq_compl_handler); |
Tomas Winkler | 6e0f180 | 2013-04-19 22:01:34 +0300 | [diff] [blame] | 56 | |
Tomas Winkler | 4c6e22b | 2013-03-17 11:41:20 +0200 | [diff] [blame] | 57 | /** |
Tomas Winkler | 6e0f180 | 2013-04-19 22:01:34 +0300 | [diff] [blame] | 58 | * mei_cl_hbm_equal - check if hbm is addressed to the client |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 59 | * |
Tomas Winkler | 6e0f180 | 2013-04-19 22:01:34 +0300 | [diff] [blame] | 60 | * @cl: host client |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 61 | * @mei_hdr: header of mei client message |
| 62 | * |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 63 | * Return: true if matches, false otherwise |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 64 | */ |
Tomas Winkler | 6e0f180 | 2013-04-19 22:01:34 +0300 | [diff] [blame] | 65 | static inline int mei_cl_hbm_equal(struct mei_cl *cl, |
| 66 | struct mei_msg_hdr *mei_hdr) |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 67 | { |
Tomas Winkler | 6e0f180 | 2013-04-19 22:01:34 +0300 | [diff] [blame] | 68 | return cl->host_client_id == mei_hdr->host_addr && |
| 69 | cl->me_client_id == mei_hdr->me_addr; |
| 70 | } |
| 71 | /** |
Tomas Winkler | 3d33ff2 | 2015-02-10 10:39:36 +0200 | [diff] [blame] | 72 | * mei_cl_is_reading - checks if the client is in reading state |
Tomas Winkler | 6e0f180 | 2013-04-19 22:01:34 +0300 | [diff] [blame] | 73 | * |
| 74 | * @cl: mei client |
Tomas Winkler | 6e0f180 | 2013-04-19 22:01:34 +0300 | [diff] [blame] | 75 | * |
Tomas Winkler | 3d33ff2 | 2015-02-10 10:39:36 +0200 | [diff] [blame] | 76 | * Return: true if the client is reading |
Tomas Winkler | 6e0f180 | 2013-04-19 22:01:34 +0300 | [diff] [blame] | 77 | */ |
Tomas Winkler | 3d33ff2 | 2015-02-10 10:39:36 +0200 | [diff] [blame] | 78 | static bool mei_cl_is_reading(struct mei_cl *cl) |
Tomas Winkler | 6e0f180 | 2013-04-19 22:01:34 +0300 | [diff] [blame] | 79 | { |
Tomas Winkler | 3d33ff2 | 2015-02-10 10:39:36 +0200 | [diff] [blame] | 80 | return cl->state == MEI_FILE_CONNECTED && |
Tomas Winkler | 6e0f180 | 2013-04-19 22:01:34 +0300 | [diff] [blame] | 81 | cl->reading_state != MEI_READ_COMPLETE; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | /** |
Tomas Winkler | 331e418 | 2015-02-10 10:39:41 +0200 | [diff] [blame] | 85 | * mei_irq_discard_msg - discard received message |
| 86 | * |
| 87 | * @dev: mei device |
| 88 | * @hdr: message header |
| 89 | */ |
| 90 | static inline |
| 91 | void mei_irq_discard_msg(struct mei_device *dev, struct mei_msg_hdr *hdr) |
| 92 | { |
| 93 | /* |
| 94 | * no need to check for size as it is guarantied |
| 95 | * that length fits into rd_msg_buf |
| 96 | */ |
| 97 | mei_read_slots(dev, dev->rd_msg_buf, hdr->length); |
| 98 | dev_dbg(dev->dev, "discarding message " MEI_HDR_FMT "\n", |
| 99 | MEI_HDR_PRM(hdr)); |
| 100 | } |
| 101 | |
| 102 | /** |
Alexander Usyskin | ce23139 | 2014-09-29 16:31:50 +0300 | [diff] [blame] | 103 | * mei_cl_irq_read_msg - process client message |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 104 | * |
Tomas Winkler | 3d33ff2 | 2015-02-10 10:39:36 +0200 | [diff] [blame] | 105 | * @cl: reading client |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 106 | * @mei_hdr: header of mei client message |
Tomas Winkler | 3d33ff2 | 2015-02-10 10:39:36 +0200 | [diff] [blame] | 107 | * @complete_list: completion list |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 108 | * |
Tomas Winkler | 3d33ff2 | 2015-02-10 10:39:36 +0200 | [diff] [blame] | 109 | * Return: always 0 |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 110 | */ |
Tomas Winkler | 331e418 | 2015-02-10 10:39:41 +0200 | [diff] [blame] | 111 | int mei_cl_irq_read_msg(struct mei_cl *cl, |
| 112 | struct mei_msg_hdr *mei_hdr, |
| 113 | struct mei_cl_cb *complete_list) |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 114 | { |
Tomas Winkler | 3d33ff2 | 2015-02-10 10:39:36 +0200 | [diff] [blame] | 115 | struct mei_device *dev = cl->dev; |
| 116 | struct mei_cl_cb *cb; |
Tomas Winkler | 479bc59 | 2011-06-16 00:46:03 +0300 | [diff] [blame] | 117 | unsigned char *buffer = NULL; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 118 | |
Tomas Winkler | 3d33ff2 | 2015-02-10 10:39:36 +0200 | [diff] [blame] | 119 | list_for_each_entry(cb, &dev->read_list.list, list) { |
| 120 | if (cl == cb->cl) |
| 121 | break; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 122 | } |
| 123 | |
Tomas Winkler | 3d33ff2 | 2015-02-10 10:39:36 +0200 | [diff] [blame] | 124 | if (&cb->list == &dev->read_list.list) { |
| 125 | dev_err(dev->dev, "no reader found\n"); |
| 126 | goto out; |
| 127 | } |
| 128 | |
| 129 | if (!mei_cl_is_reading(cl)) { |
| 130 | cl_err(dev, cl, "cl is not reading state=%d reading state=%d\n", |
| 131 | cl->state, cl->reading_state); |
| 132 | goto out; |
| 133 | } |
| 134 | |
| 135 | cl->reading_state = MEI_READING; |
| 136 | |
Tomas Winkler | 5db7514 | 2015-02-10 10:39:42 +0200 | [diff] [blame^] | 137 | if (cb->buf.size == 0 || cb->buf.data == NULL) { |
Tomas Winkler | 3d33ff2 | 2015-02-10 10:39:36 +0200 | [diff] [blame] | 138 | cl_err(dev, cl, "response buffer is not allocated.\n"); |
| 139 | list_move_tail(&cb->list, &complete_list->list); |
| 140 | cb->status = -ENOMEM; |
| 141 | goto out; |
| 142 | } |
| 143 | |
Tomas Winkler | 5db7514 | 2015-02-10 10:39:42 +0200 | [diff] [blame^] | 144 | if (cb->buf.size < mei_hdr->length + cb->buf_idx) { |
Tomas Winkler | 3d33ff2 | 2015-02-10 10:39:36 +0200 | [diff] [blame] | 145 | cl_dbg(dev, cl, "message overflow. size %d len %d idx %ld\n", |
Tomas Winkler | 5db7514 | 2015-02-10 10:39:42 +0200 | [diff] [blame^] | 146 | cb->buf.size, mei_hdr->length, cb->buf_idx); |
| 147 | buffer = krealloc(cb->buf.data, mei_hdr->length + cb->buf_idx, |
Tomas Winkler | 3d33ff2 | 2015-02-10 10:39:36 +0200 | [diff] [blame] | 148 | GFP_KERNEL); |
| 149 | |
| 150 | if (!buffer) { |
| 151 | cb->status = -ENOMEM; |
| 152 | list_move_tail(&cb->list, &complete_list->list); |
| 153 | goto out; |
| 154 | } |
Tomas Winkler | 5db7514 | 2015-02-10 10:39:42 +0200 | [diff] [blame^] | 155 | cb->buf.data = buffer; |
| 156 | cb->buf.size = mei_hdr->length + cb->buf_idx; |
Tomas Winkler | 3d33ff2 | 2015-02-10 10:39:36 +0200 | [diff] [blame] | 157 | } |
| 158 | |
Tomas Winkler | 5db7514 | 2015-02-10 10:39:42 +0200 | [diff] [blame^] | 159 | buffer = cb->buf.data + cb->buf_idx; |
Tomas Winkler | 3d33ff2 | 2015-02-10 10:39:36 +0200 | [diff] [blame] | 160 | mei_read_slots(dev, buffer, mei_hdr->length); |
| 161 | |
| 162 | cb->buf_idx += mei_hdr->length; |
Tomas Winkler | 331e418 | 2015-02-10 10:39:41 +0200 | [diff] [blame] | 163 | |
Tomas Winkler | 3d33ff2 | 2015-02-10 10:39:36 +0200 | [diff] [blame] | 164 | if (mei_hdr->msg_complete) { |
Tomas Winkler | 331e418 | 2015-02-10 10:39:41 +0200 | [diff] [blame] | 165 | cb->read_time = jiffies; |
Tomas Winkler | 3d33ff2 | 2015-02-10 10:39:36 +0200 | [diff] [blame] | 166 | cl_dbg(dev, cl, "completed read length = %lu\n", |
| 167 | cb->buf_idx); |
| 168 | list_move_tail(&cb->list, &complete_list->list); |
| 169 | } |
| 170 | |
| 171 | out: |
Tomas Winkler | 331e418 | 2015-02-10 10:39:41 +0200 | [diff] [blame] | 172 | if (!buffer) |
| 173 | mei_irq_discard_msg(dev, mei_hdr); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 174 | |
| 175 | return 0; |
| 176 | } |
| 177 | |
| 178 | /** |
Tomas Winkler | 6bb948c | 2014-02-12 21:41:52 +0200 | [diff] [blame] | 179 | * mei_cl_irq_disconnect_rsp - send disconnection response message |
| 180 | * |
| 181 | * @cl: client |
| 182 | * @cb: callback block. |
Tomas Winkler | 6bb948c | 2014-02-12 21:41:52 +0200 | [diff] [blame] | 183 | * @cmpl_list: complete list. |
| 184 | * |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 185 | * Return: 0, OK; otherwise, error. |
Tomas Winkler | 6bb948c | 2014-02-12 21:41:52 +0200 | [diff] [blame] | 186 | */ |
| 187 | static int mei_cl_irq_disconnect_rsp(struct mei_cl *cl, struct mei_cl_cb *cb, |
Tomas Winkler | 9d09819 | 2014-02-19 17:35:48 +0200 | [diff] [blame] | 188 | struct mei_cl_cb *cmpl_list) |
Tomas Winkler | 6bb948c | 2014-02-12 21:41:52 +0200 | [diff] [blame] | 189 | { |
| 190 | struct mei_device *dev = cl->dev; |
Tomas Winkler | 9d09819 | 2014-02-19 17:35:48 +0200 | [diff] [blame] | 191 | u32 msg_slots; |
| 192 | int slots; |
Tomas Winkler | 6bb948c | 2014-02-12 21:41:52 +0200 | [diff] [blame] | 193 | int ret; |
| 194 | |
Tomas Winkler | 9d09819 | 2014-02-19 17:35:48 +0200 | [diff] [blame] | 195 | slots = mei_hbuf_empty_slots(dev); |
| 196 | msg_slots = mei_data2slots(sizeof(struct hbm_client_connect_response)); |
Tomas Winkler | 6bb948c | 2014-02-12 21:41:52 +0200 | [diff] [blame] | 197 | |
Tomas Winkler | 9d09819 | 2014-02-19 17:35:48 +0200 | [diff] [blame] | 198 | if (slots < msg_slots) |
Tomas Winkler | 6bb948c | 2014-02-12 21:41:52 +0200 | [diff] [blame] | 199 | return -EMSGSIZE; |
| 200 | |
Tomas Winkler | 6bb948c | 2014-02-12 21:41:52 +0200 | [diff] [blame] | 201 | ret = mei_hbm_cl_disconnect_rsp(dev, cl); |
| 202 | |
| 203 | cl->state = MEI_FILE_DISCONNECTED; |
| 204 | cl->status = 0; |
Alexander Usyskin | 31a5ef2 | 2014-03-06 23:53:53 +0200 | [diff] [blame] | 205 | list_del(&cb->list); |
Tomas Winkler | 6bb948c | 2014-02-12 21:41:52 +0200 | [diff] [blame] | 206 | mei_io_cb_free(cb); |
| 207 | |
| 208 | return ret; |
| 209 | } |
| 210 | |
| 211 | |
| 212 | |
| 213 | /** |
Tomas Winkler | 5a8373f | 2014-08-21 14:29:17 +0300 | [diff] [blame] | 214 | * mei_cl_irq_disconnect - processes close related operation from |
Tomas Winkler | 6220d6a | 2013-05-12 15:34:46 +0300 | [diff] [blame] | 215 | * interrupt thread context - send disconnect request |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 216 | * |
Tomas Winkler | 6220d6a | 2013-05-12 15:34:46 +0300 | [diff] [blame] | 217 | * @cl: client |
| 218 | * @cb: callback block. |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 219 | * @cmpl_list: complete list. |
| 220 | * |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 221 | * Return: 0, OK; otherwise, error. |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 222 | */ |
Tomas Winkler | 5a8373f | 2014-08-21 14:29:17 +0300 | [diff] [blame] | 223 | static int mei_cl_irq_disconnect(struct mei_cl *cl, struct mei_cl_cb *cb, |
Tomas Winkler | 9d09819 | 2014-02-19 17:35:48 +0200 | [diff] [blame] | 224 | struct mei_cl_cb *cmpl_list) |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 225 | { |
Tomas Winkler | 6220d6a | 2013-05-12 15:34:46 +0300 | [diff] [blame] | 226 | struct mei_device *dev = cl->dev; |
Tomas Winkler | 9d09819 | 2014-02-19 17:35:48 +0200 | [diff] [blame] | 227 | u32 msg_slots; |
| 228 | int slots; |
Tomas Winkler | 6220d6a | 2013-05-12 15:34:46 +0300 | [diff] [blame] | 229 | |
Tomas Winkler | 9d09819 | 2014-02-19 17:35:48 +0200 | [diff] [blame] | 230 | msg_slots = mei_data2slots(sizeof(struct hbm_client_connect_request)); |
| 231 | slots = mei_hbuf_empty_slots(dev); |
Tomas Winkler | b45f3cc | 2012-07-04 19:24:53 +0300 | [diff] [blame] | 232 | |
Tomas Winkler | 9d09819 | 2014-02-19 17:35:48 +0200 | [diff] [blame] | 233 | if (slots < msg_slots) |
Tomas Winkler | c8c8d08 | 2013-03-11 18:27:02 +0200 | [diff] [blame] | 234 | return -EMSGSIZE; |
| 235 | |
Tomas Winkler | 8120e72 | 2012-12-25 19:06:11 +0200 | [diff] [blame] | 236 | if (mei_hbm_cl_disconnect_req(dev, cl)) { |
Tomas Winkler | b45f3cc | 2012-07-04 19:24:53 +0300 | [diff] [blame] | 237 | cl->status = 0; |
Tomas Winkler | 6220d6a | 2013-05-12 15:34:46 +0300 | [diff] [blame] | 238 | cb->buf_idx = 0; |
| 239 | list_move_tail(&cb->list, &cmpl_list->list); |
Tomas Winkler | c8c8d08 | 2013-03-11 18:27:02 +0200 | [diff] [blame] | 240 | return -EIO; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 241 | } |
| 242 | |
Tomas Winkler | c8c8d08 | 2013-03-11 18:27:02 +0200 | [diff] [blame] | 243 | cl->state = MEI_FILE_DISCONNECTING; |
| 244 | cl->status = 0; |
Tomas Winkler | 6220d6a | 2013-05-12 15:34:46 +0300 | [diff] [blame] | 245 | cb->buf_idx = 0; |
| 246 | list_move_tail(&cb->list, &dev->ctrl_rd_list.list); |
Tomas Winkler | c8c8d08 | 2013-03-11 18:27:02 +0200 | [diff] [blame] | 247 | cl->timer_count = MEI_CONNECT_TIMEOUT; |
| 248 | |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 249 | return 0; |
| 250 | } |
| 251 | |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 252 | |
| 253 | /** |
Alexander Usyskin | ce23139 | 2014-09-29 16:31:50 +0300 | [diff] [blame] | 254 | * mei_cl_irq_read - processes client read related operation from the |
Tomas Winkler | 6220d6a | 2013-05-12 15:34:46 +0300 | [diff] [blame] | 255 | * interrupt thread context - request for flow control credits |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 256 | * |
Tomas Winkler | 6220d6a | 2013-05-12 15:34:46 +0300 | [diff] [blame] | 257 | * @cl: client |
| 258 | * @cb: callback block. |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 259 | * @cmpl_list: complete list. |
| 260 | * |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 261 | * Return: 0, OK; otherwise, error. |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 262 | */ |
Tomas Winkler | 6220d6a | 2013-05-12 15:34:46 +0300 | [diff] [blame] | 263 | static int mei_cl_irq_read(struct mei_cl *cl, struct mei_cl_cb *cb, |
Tomas Winkler | 9d09819 | 2014-02-19 17:35:48 +0200 | [diff] [blame] | 264 | struct mei_cl_cb *cmpl_list) |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 265 | { |
Tomas Winkler | 6220d6a | 2013-05-12 15:34:46 +0300 | [diff] [blame] | 266 | struct mei_device *dev = cl->dev; |
Tomas Winkler | 9d09819 | 2014-02-19 17:35:48 +0200 | [diff] [blame] | 267 | u32 msg_slots; |
| 268 | int slots; |
Tomas Winkler | 2ebf8c9 | 2013-09-16 23:44:43 +0300 | [diff] [blame] | 269 | int ret; |
| 270 | |
Tomas Winkler | 9d09819 | 2014-02-19 17:35:48 +0200 | [diff] [blame] | 271 | msg_slots = mei_data2slots(sizeof(struct hbm_flow_control)); |
| 272 | slots = mei_hbuf_empty_slots(dev); |
Tomas Winkler | 2ebf8c9 | 2013-09-16 23:44:43 +0300 | [diff] [blame] | 273 | |
Tomas Winkler | 9d09819 | 2014-02-19 17:35:48 +0200 | [diff] [blame] | 274 | if (slots < msg_slots) |
Tomas Winkler | c8c8d08 | 2013-03-11 18:27:02 +0200 | [diff] [blame] | 275 | return -EMSGSIZE; |
Tomas Winkler | 7bdf72d | 2012-07-04 19:24:52 +0300 | [diff] [blame] | 276 | |
Tomas Winkler | 2ebf8c9 | 2013-09-16 23:44:43 +0300 | [diff] [blame] | 277 | ret = mei_hbm_cl_flow_control_req(dev, cl); |
| 278 | if (ret) { |
| 279 | cl->status = ret; |
Tomas Winkler | 6220d6a | 2013-05-12 15:34:46 +0300 | [diff] [blame] | 280 | cb->buf_idx = 0; |
| 281 | list_move_tail(&cb->list, &cmpl_list->list); |
Tomas Winkler | 2ebf8c9 | 2013-09-16 23:44:43 +0300 | [diff] [blame] | 282 | return ret; |
Tomas Winkler | 1ccb7b6 | 2012-03-14 14:39:42 +0200 | [diff] [blame] | 283 | } |
Tomas Winkler | 2ebf8c9 | 2013-09-16 23:44:43 +0300 | [diff] [blame] | 284 | |
Tomas Winkler | 6220d6a | 2013-05-12 15:34:46 +0300 | [diff] [blame] | 285 | list_move_tail(&cb->list, &dev->read_list.list); |
Tomas Winkler | 1ccb7b6 | 2012-03-14 14:39:42 +0200 | [diff] [blame] | 286 | |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 287 | return 0; |
| 288 | } |
| 289 | |
| 290 | |
| 291 | /** |
Tomas Winkler | 02a7eec | 2014-02-12 21:41:51 +0200 | [diff] [blame] | 292 | * mei_cl_irq_connect - send connect request in irq_thread context |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 293 | * |
Tomas Winkler | 6220d6a | 2013-05-12 15:34:46 +0300 | [diff] [blame] | 294 | * @cl: client |
| 295 | * @cb: callback block. |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 296 | * @cmpl_list: complete list. |
| 297 | * |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 298 | * Return: 0, OK; otherwise, error. |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 299 | */ |
Tomas Winkler | 02a7eec | 2014-02-12 21:41:51 +0200 | [diff] [blame] | 300 | static int mei_cl_irq_connect(struct mei_cl *cl, struct mei_cl_cb *cb, |
Tomas Winkler | 9d09819 | 2014-02-19 17:35:48 +0200 | [diff] [blame] | 301 | struct mei_cl_cb *cmpl_list) |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 302 | { |
Tomas Winkler | 6220d6a | 2013-05-12 15:34:46 +0300 | [diff] [blame] | 303 | struct mei_device *dev = cl->dev; |
Tomas Winkler | 9d09819 | 2014-02-19 17:35:48 +0200 | [diff] [blame] | 304 | u32 msg_slots; |
| 305 | int slots; |
Tomas Winkler | 2ebf8c9 | 2013-09-16 23:44:43 +0300 | [diff] [blame] | 306 | int ret; |
Tomas Winkler | 6220d6a | 2013-05-12 15:34:46 +0300 | [diff] [blame] | 307 | |
Tomas Winkler | 9d09819 | 2014-02-19 17:35:48 +0200 | [diff] [blame] | 308 | msg_slots = mei_data2slots(sizeof(struct hbm_client_connect_request)); |
| 309 | slots = mei_hbuf_empty_slots(dev); |
Tomas Winkler | c8c8d08 | 2013-03-11 18:27:02 +0200 | [diff] [blame] | 310 | |
Tomas Winkler | 02a7eec | 2014-02-12 21:41:51 +0200 | [diff] [blame] | 311 | if (mei_cl_is_other_connecting(cl)) |
| 312 | return 0; |
| 313 | |
Tomas Winkler | 9d09819 | 2014-02-19 17:35:48 +0200 | [diff] [blame] | 314 | if (slots < msg_slots) |
Tomas Winkler | c8c8d08 | 2013-03-11 18:27:02 +0200 | [diff] [blame] | 315 | return -EMSGSIZE; |
Tomas Winkler | c8c8d08 | 2013-03-11 18:27:02 +0200 | [diff] [blame] | 316 | |
Tomas Winkler | b45f3cc | 2012-07-04 19:24:53 +0300 | [diff] [blame] | 317 | cl->state = MEI_FILE_CONNECTING; |
Tomas Winkler | c8c8d08 | 2013-03-11 18:27:02 +0200 | [diff] [blame] | 318 | |
Tomas Winkler | 2ebf8c9 | 2013-09-16 23:44:43 +0300 | [diff] [blame] | 319 | ret = mei_hbm_cl_connect_req(dev, cl); |
| 320 | if (ret) { |
| 321 | cl->status = ret; |
Tomas Winkler | 6220d6a | 2013-05-12 15:34:46 +0300 | [diff] [blame] | 322 | cb->buf_idx = 0; |
| 323 | list_del(&cb->list); |
Tomas Winkler | 2ebf8c9 | 2013-09-16 23:44:43 +0300 | [diff] [blame] | 324 | return ret; |
Tomas Winkler | b45f3cc | 2012-07-04 19:24:53 +0300 | [diff] [blame] | 325 | } |
Tomas Winkler | 6220d6a | 2013-05-12 15:34:46 +0300 | [diff] [blame] | 326 | |
| 327 | list_move_tail(&cb->list, &dev->ctrl_rd_list.list); |
| 328 | cl->timer_count = MEI_CONNECT_TIMEOUT; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 329 | return 0; |
| 330 | } |
| 331 | |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 332 | |
| 333 | /** |
Masanari Iida | 393b148 | 2013-04-05 01:05:05 +0900 | [diff] [blame] | 334 | * mei_irq_read_handler - bottom half read routine after ISR to |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 335 | * handle the read processing. |
| 336 | * |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 337 | * @dev: the device structure |
Tomas Winkler | 06ecd64 | 2013-02-06 14:06:42 +0200 | [diff] [blame] | 338 | * @cmpl_list: An instance of our list structure |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 339 | * @slots: slots to read. |
| 340 | * |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 341 | * Return: 0 on success, <0 on failure. |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 342 | */ |
Tomas Winkler | 06ecd64 | 2013-02-06 14:06:42 +0200 | [diff] [blame] | 343 | int mei_irq_read_handler(struct mei_device *dev, |
| 344 | struct mei_cl_cb *cmpl_list, s32 *slots) |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 345 | { |
| 346 | struct mei_msg_hdr *mei_hdr; |
Tomas Winkler | 10ee907 | 2013-11-11 13:26:08 +0200 | [diff] [blame] | 347 | struct mei_cl *cl; |
| 348 | int ret; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 349 | |
| 350 | if (!dev->rd_msg_hdr) { |
Tomas Winkler | 827eef5 | 2013-02-06 14:06:41 +0200 | [diff] [blame] | 351 | dev->rd_msg_hdr = mei_read_hdr(dev); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 352 | (*slots)--; |
Tomas Winkler | 2bf94cab | 2014-09-29 16:31:42 +0300 | [diff] [blame] | 353 | dev_dbg(dev->dev, "slots =%08x.\n", *slots); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 354 | } |
| 355 | mei_hdr = (struct mei_msg_hdr *) &dev->rd_msg_hdr; |
Tomas Winkler | 2bf94cab | 2014-09-29 16:31:42 +0300 | [diff] [blame] | 356 | dev_dbg(dev->dev, MEI_HDR_FMT, MEI_HDR_PRM(mei_hdr)); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 357 | |
| 358 | if (mei_hdr->reserved || !dev->rd_msg_hdr) { |
Tomas Winkler | 2bf94cab | 2014-09-29 16:31:42 +0300 | [diff] [blame] | 359 | dev_err(dev->dev, "corrupted message header 0x%08X\n", |
Tomas Winkler | 10ee907 | 2013-11-11 13:26:08 +0200 | [diff] [blame] | 360 | dev->rd_msg_hdr); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 361 | ret = -EBADMSG; |
| 362 | goto end; |
| 363 | } |
| 364 | |
Tomas Winkler | 10ee907 | 2013-11-11 13:26:08 +0200 | [diff] [blame] | 365 | if (mei_slots2data(*slots) < mei_hdr->length) { |
Tomas Winkler | 2bf94cab | 2014-09-29 16:31:42 +0300 | [diff] [blame] | 366 | dev_err(dev->dev, "less data available than length=%08x.\n", |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 367 | *slots); |
| 368 | /* we can't read the message */ |
Tomas Winkler | b1b94b5 | 2014-03-03 00:21:28 +0200 | [diff] [blame] | 369 | ret = -ENODATA; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 370 | goto end; |
| 371 | } |
| 372 | |
Tomas Winkler | 10ee907 | 2013-11-11 13:26:08 +0200 | [diff] [blame] | 373 | /* HBM message */ |
| 374 | if (mei_hdr->host_addr == 0 && mei_hdr->me_addr == 0) { |
Tomas Winkler | 544f946 | 2014-01-08 20:19:21 +0200 | [diff] [blame] | 375 | ret = mei_hbm_dispatch(dev, mei_hdr); |
| 376 | if (ret) { |
Tomas Winkler | 2bf94cab | 2014-09-29 16:31:42 +0300 | [diff] [blame] | 377 | dev_dbg(dev->dev, "mei_hbm_dispatch failed ret = %d\n", |
Tomas Winkler | 544f946 | 2014-01-08 20:19:21 +0200 | [diff] [blame] | 378 | ret); |
| 379 | goto end; |
| 380 | } |
Tomas Winkler | 10ee907 | 2013-11-11 13:26:08 +0200 | [diff] [blame] | 381 | goto reset_slots; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 382 | } |
| 383 | |
Alexander Usyskin | 83ce074 | 2014-01-08 22:31:46 +0200 | [diff] [blame] | 384 | /* find recipient cl */ |
Tomas Winkler | 10ee907 | 2013-11-11 13:26:08 +0200 | [diff] [blame] | 385 | list_for_each_entry(cl, &dev->file_list, link) { |
| 386 | if (mei_cl_hbm_equal(cl, mei_hdr)) { |
| 387 | cl_dbg(dev, cl, "got a message\n"); |
| 388 | break; |
| 389 | } |
| 390 | } |
| 391 | |
Alexander Usyskin | 83ce074 | 2014-01-08 22:31:46 +0200 | [diff] [blame] | 392 | /* if no recipient cl was found we assume corrupted header */ |
Tomas Winkler | 10ee907 | 2013-11-11 13:26:08 +0200 | [diff] [blame] | 393 | if (&cl->link == &dev->file_list) { |
Tomas Winkler | 2bf94cab | 2014-09-29 16:31:42 +0300 | [diff] [blame] | 394 | dev_err(dev->dev, "no destination client found 0x%08X\n", |
Tomas Winkler | 10ee907 | 2013-11-11 13:26:08 +0200 | [diff] [blame] | 395 | dev->rd_msg_hdr); |
| 396 | ret = -EBADMSG; |
| 397 | goto end; |
| 398 | } |
| 399 | |
Tomas Winkler | db4756f | 2015-02-10 10:39:37 +0200 | [diff] [blame] | 400 | if (cl == &dev->iamthif_cl) { |
| 401 | ret = mei_amthif_irq_read_msg(cl, mei_hdr, cmpl_list); |
Tomas Winkler | 10ee907 | 2013-11-11 13:26:08 +0200 | [diff] [blame] | 402 | } else { |
Tomas Winkler | 3d33ff2 | 2015-02-10 10:39:36 +0200 | [diff] [blame] | 403 | ret = mei_cl_irq_read_msg(cl, mei_hdr, cmpl_list); |
Tomas Winkler | 10ee907 | 2013-11-11 13:26:08 +0200 | [diff] [blame] | 404 | } |
| 405 | |
Tomas Winkler | 3d33ff2 | 2015-02-10 10:39:36 +0200 | [diff] [blame] | 406 | |
Tomas Winkler | 10ee907 | 2013-11-11 13:26:08 +0200 | [diff] [blame] | 407 | reset_slots: |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 408 | /* reset the number of slots and header */ |
| 409 | *slots = mei_count_full_read_slots(dev); |
| 410 | dev->rd_msg_hdr = 0; |
| 411 | |
| 412 | if (*slots == -EOVERFLOW) { |
| 413 | /* overflow - reset */ |
Tomas Winkler | 2bf94cab | 2014-09-29 16:31:42 +0300 | [diff] [blame] | 414 | dev_err(dev->dev, "resetting due to slots overflow.\n"); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 415 | /* set the event since message has been read */ |
| 416 | ret = -ERANGE; |
| 417 | goto end; |
| 418 | } |
| 419 | end: |
| 420 | return ret; |
| 421 | } |
Tomas Winkler | 40e0b67 | 2013-03-27 16:58:30 +0200 | [diff] [blame] | 422 | EXPORT_SYMBOL_GPL(mei_irq_read_handler); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 423 | |
| 424 | |
| 425 | /** |
Tomas Winkler | 06ecd64 | 2013-02-06 14:06:42 +0200 | [diff] [blame] | 426 | * mei_irq_write_handler - dispatch write requests |
| 427 | * after irq received |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 428 | * |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 429 | * @dev: the device structure |
Tomas Winkler | 9a84d61 | 2012-11-18 15:13:18 +0200 | [diff] [blame] | 430 | * @cmpl_list: An instance of our list structure |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 431 | * |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 432 | * Return: 0 on success, <0 on failure. |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 433 | */ |
Tomas Winkler | c8c8d08 | 2013-03-11 18:27:02 +0200 | [diff] [blame] | 434 | int mei_irq_write_handler(struct mei_device *dev, struct mei_cl_cb *cmpl_list) |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 435 | { |
| 436 | |
| 437 | struct mei_cl *cl; |
Tomas Winkler | 6220d6a | 2013-05-12 15:34:46 +0300 | [diff] [blame] | 438 | struct mei_cl_cb *cb, *next; |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 439 | struct mei_cl_cb *list; |
Tomas Winkler | 9a84d61 | 2012-11-18 15:13:18 +0200 | [diff] [blame] | 440 | s32 slots; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 441 | int ret; |
| 442 | |
Tomas Winkler | 6aae48f | 2014-02-19 17:35:47 +0200 | [diff] [blame] | 443 | |
| 444 | if (!mei_hbuf_acquire(dev)) |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 445 | return 0; |
Tomas Winkler | 6aae48f | 2014-02-19 17:35:47 +0200 | [diff] [blame] | 446 | |
Tomas Winkler | 9a84d61 | 2012-11-18 15:13:18 +0200 | [diff] [blame] | 447 | slots = mei_hbuf_empty_slots(dev); |
| 448 | if (slots <= 0) |
Tomas Winkler | 7d5e0e5 | 2012-06-19 09:13:36 +0300 | [diff] [blame] | 449 | return -EMSGSIZE; |
| 450 | |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 451 | /* complete all waiting for write CB */ |
Tomas Winkler | 2bf94cab | 2014-09-29 16:31:42 +0300 | [diff] [blame] | 452 | dev_dbg(dev->dev, "complete all waiting for write cb.\n"); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 453 | |
| 454 | list = &dev->write_waiting_list; |
Tomas Winkler | 6220d6a | 2013-05-12 15:34:46 +0300 | [diff] [blame] | 455 | list_for_each_entry_safe(cb, next, &list->list, list) { |
| 456 | cl = cb->cl; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 457 | |
Tomas Winkler | b7cd2d9 | 2011-11-27 21:43:34 +0200 | [diff] [blame] | 458 | cl->status = 0; |
Tomas Winkler | c54bf3a | 2015-02-10 10:39:39 +0200 | [diff] [blame] | 459 | cl_dbg(dev, cl, "MEI WRITE COMPLETE\n"); |
| 460 | cl->writing_state = MEI_WRITE_COMPLETE; |
| 461 | list_move_tail(&cb->list, &cmpl_list->list); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 462 | } |
| 463 | |
Tomas Winkler | c216fde | 2012-08-16 19:39:43 +0300 | [diff] [blame] | 464 | if (dev->wd_state == MEI_WD_STOPPING) { |
| 465 | dev->wd_state = MEI_WD_IDLE; |
Tomas Winkler | 5877255 | 2014-02-19 17:35:51 +0200 | [diff] [blame] | 466 | wake_up(&dev->wait_stop_wd); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 467 | } |
| 468 | |
Tomas Winkler | 6409285 | 2014-02-17 15:13:21 +0200 | [diff] [blame] | 469 | if (mei_cl_is_connected(&dev->wd_cl)) { |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 470 | if (dev->wd_pending && |
Tomas Winkler | 90e0b5f | 2013-01-08 23:07:14 +0200 | [diff] [blame] | 471 | mei_cl_flow_ctrl_creds(&dev->wd_cl) > 0) { |
Tomas Winkler | b6d81fd | 2014-02-19 17:35:50 +0200 | [diff] [blame] | 472 | ret = mei_wd_send(dev); |
| 473 | if (ret) |
| 474 | return ret; |
Tomas Winkler | eb9af0a | 2011-05-25 17:28:22 +0300 | [diff] [blame] | 475 | dev->wd_pending = false; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 476 | } |
| 477 | } |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 478 | |
| 479 | /* complete control write list CB */ |
Tomas Winkler | 2bf94cab | 2014-09-29 16:31:42 +0300 | [diff] [blame] | 480 | dev_dbg(dev->dev, "complete control write list cb.\n"); |
Tomas Winkler | 6220d6a | 2013-05-12 15:34:46 +0300 | [diff] [blame] | 481 | list_for_each_entry_safe(cb, next, &dev->ctrl_wr_list.list, list) { |
| 482 | cl = cb->cl; |
Tomas Winkler | 6220d6a | 2013-05-12 15:34:46 +0300 | [diff] [blame] | 483 | switch (cb->fop_type) { |
Tomas Winkler | 5a8373f | 2014-08-21 14:29:17 +0300 | [diff] [blame] | 484 | case MEI_FOP_DISCONNECT: |
Tomas Winkler | c837209 | 2011-11-27 21:43:33 +0200 | [diff] [blame] | 485 | /* send disconnect message */ |
Tomas Winkler | 5a8373f | 2014-08-21 14:29:17 +0300 | [diff] [blame] | 486 | ret = mei_cl_irq_disconnect(cl, cb, cmpl_list); |
Tomas Winkler | c837209 | 2011-11-27 21:43:33 +0200 | [diff] [blame] | 487 | if (ret) |
| 488 | return ret; |
| 489 | |
| 490 | break; |
Tomas Winkler | 4b8960b | 2012-11-11 17:38:00 +0200 | [diff] [blame] | 491 | case MEI_FOP_READ: |
Tomas Winkler | c837209 | 2011-11-27 21:43:33 +0200 | [diff] [blame] | 492 | /* send flow control message */ |
Tomas Winkler | 9d09819 | 2014-02-19 17:35:48 +0200 | [diff] [blame] | 493 | ret = mei_cl_irq_read(cl, cb, cmpl_list); |
Tomas Winkler | c837209 | 2011-11-27 21:43:33 +0200 | [diff] [blame] | 494 | if (ret) |
| 495 | return ret; |
| 496 | |
| 497 | break; |
Tomas Winkler | 02a7eec | 2014-02-12 21:41:51 +0200 | [diff] [blame] | 498 | case MEI_FOP_CONNECT: |
Tomas Winkler | c837209 | 2011-11-27 21:43:33 +0200 | [diff] [blame] | 499 | /* connect message */ |
Tomas Winkler | 9d09819 | 2014-02-19 17:35:48 +0200 | [diff] [blame] | 500 | ret = mei_cl_irq_connect(cl, cb, cmpl_list); |
Tomas Winkler | c837209 | 2011-11-27 21:43:33 +0200 | [diff] [blame] | 501 | if (ret) |
| 502 | return ret; |
| 503 | |
| 504 | break; |
Tomas Winkler | 6bb948c | 2014-02-12 21:41:52 +0200 | [diff] [blame] | 505 | case MEI_FOP_DISCONNECT_RSP: |
| 506 | /* send disconnect resp */ |
Tomas Winkler | 9d09819 | 2014-02-19 17:35:48 +0200 | [diff] [blame] | 507 | ret = mei_cl_irq_disconnect_rsp(cl, cb, cmpl_list); |
Tomas Winkler | 6bb948c | 2014-02-12 21:41:52 +0200 | [diff] [blame] | 508 | if (ret) |
| 509 | return ret; |
Alexander Usyskin | 31a5ef2 | 2014-03-06 23:53:53 +0200 | [diff] [blame] | 510 | break; |
Tomas Winkler | c837209 | 2011-11-27 21:43:33 +0200 | [diff] [blame] | 511 | default: |
| 512 | BUG(); |
| 513 | } |
| 514 | |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 515 | } |
| 516 | /* complete write list CB */ |
Tomas Winkler | 2bf94cab | 2014-09-29 16:31:42 +0300 | [diff] [blame] | 517 | dev_dbg(dev->dev, "complete write list cb.\n"); |
Tomas Winkler | 6220d6a | 2013-05-12 15:34:46 +0300 | [diff] [blame] | 518 | list_for_each_entry_safe(cb, next, &dev->write_list.list, list) { |
| 519 | cl = cb->cl; |
Tomas Winkler | be9d87a | 2012-11-18 15:13:19 +0200 | [diff] [blame] | 520 | if (cl == &dev->iamthif_cl) |
Tomas Winkler | 9d09819 | 2014-02-19 17:35:48 +0200 | [diff] [blame] | 521 | ret = mei_amthif_irq_write(cl, cb, cmpl_list); |
Tomas Winkler | be9d87a | 2012-11-18 15:13:19 +0200 | [diff] [blame] | 522 | else |
Tomas Winkler | 9d09819 | 2014-02-19 17:35:48 +0200 | [diff] [blame] | 523 | ret = mei_cl_irq_write(cl, cb, cmpl_list); |
Tomas Winkler | be9d87a | 2012-11-18 15:13:19 +0200 | [diff] [blame] | 524 | if (ret) |
| 525 | return ret; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 526 | } |
| 527 | return 0; |
| 528 | } |
Tomas Winkler | 40e0b67 | 2013-03-27 16:58:30 +0200 | [diff] [blame] | 529 | EXPORT_SYMBOL_GPL(mei_irq_write_handler); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 530 | |
| 531 | |
| 532 | |
| 533 | /** |
| 534 | * mei_timer - timer function. |
| 535 | * |
| 536 | * @work: pointer to the work_struct structure |
| 537 | * |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 538 | */ |
Oren Weil | a61c653 | 2011-09-07 09:03:13 +0300 | [diff] [blame] | 539 | void mei_timer(struct work_struct *work) |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 540 | { |
| 541 | unsigned long timeout; |
Tomas Winkler | 31f88f5 | 2014-02-17 15:13:25 +0200 | [diff] [blame] | 542 | struct mei_cl *cl; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 543 | |
| 544 | struct mei_device *dev = container_of(work, |
Oren Weil | a61c653 | 2011-09-07 09:03:13 +0300 | [diff] [blame] | 545 | struct mei_device, timer_work.work); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 546 | |
| 547 | |
| 548 | mutex_lock(&dev->device_lock); |
Tomas Winkler | 66ae460 | 2014-01-08 20:19:22 +0200 | [diff] [blame] | 549 | |
| 550 | /* Catch interrupt stalls during HBM init handshake */ |
| 551 | if (dev->dev_state == MEI_DEV_INIT_CLIENTS && |
| 552 | dev->hbm_state != MEI_HBM_IDLE) { |
| 553 | |
| 554 | if (dev->init_clients_timer) { |
| 555 | if (--dev->init_clients_timer == 0) { |
Tomas Winkler | 2bf94cab | 2014-09-29 16:31:42 +0300 | [diff] [blame] | 556 | dev_err(dev->dev, "timer: init clients timeout hbm_state = %d.\n", |
Tomas Winkler | 66ae460 | 2014-01-08 20:19:22 +0200 | [diff] [blame] | 557 | dev->hbm_state); |
Tomas Winkler | 33ec082 | 2014-01-12 00:36:09 +0200 | [diff] [blame] | 558 | mei_reset(dev); |
Tomas Winkler | 66ae460 | 2014-01-08 20:19:22 +0200 | [diff] [blame] | 559 | goto out; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 560 | } |
| 561 | } |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 562 | } |
Tomas Winkler | 66ae460 | 2014-01-08 20:19:22 +0200 | [diff] [blame] | 563 | |
| 564 | if (dev->dev_state != MEI_DEV_ENABLED) |
| 565 | goto out; |
| 566 | |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 567 | /*** connect/disconnect timeouts ***/ |
Tomas Winkler | 31f88f5 | 2014-02-17 15:13:25 +0200 | [diff] [blame] | 568 | list_for_each_entry(cl, &dev->file_list, link) { |
| 569 | if (cl->timer_count) { |
| 570 | if (--cl->timer_count == 0) { |
Tomas Winkler | 2bf94cab | 2014-09-29 16:31:42 +0300 | [diff] [blame] | 571 | dev_err(dev->dev, "timer: connect/disconnect timeout.\n"); |
Tomas Winkler | 33ec082 | 2014-01-12 00:36:09 +0200 | [diff] [blame] | 572 | mei_reset(dev); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 573 | goto out; |
| 574 | } |
| 575 | } |
| 576 | } |
| 577 | |
Tomas Winkler | 6409285 | 2014-02-17 15:13:21 +0200 | [diff] [blame] | 578 | if (!mei_cl_is_connected(&dev->iamthif_cl)) |
| 579 | goto out; |
| 580 | |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 581 | if (dev->iamthif_stall_timer) { |
| 582 | if (--dev->iamthif_stall_timer == 0) { |
Tomas Winkler | 2bf94cab | 2014-09-29 16:31:42 +0300 | [diff] [blame] | 583 | dev_err(dev->dev, "timer: amthif hanged.\n"); |
Tomas Winkler | 33ec082 | 2014-01-12 00:36:09 +0200 | [diff] [blame] | 584 | mei_reset(dev); |
Tomas Winkler | eb9af0a | 2011-05-25 17:28:22 +0300 | [diff] [blame] | 585 | dev->iamthif_canceled = false; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 586 | dev->iamthif_state = MEI_IAMTHIF_IDLE; |
| 587 | dev->iamthif_timer = 0; |
| 588 | |
Tomas Winkler | 601a1ef | 2012-10-09 16:50:20 +0200 | [diff] [blame] | 589 | mei_io_cb_free(dev->iamthif_current_cb); |
| 590 | dev->iamthif_current_cb = NULL; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 591 | |
| 592 | dev->iamthif_file_object = NULL; |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 593 | mei_amthif_run_next_cmd(dev); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 594 | } |
| 595 | } |
| 596 | |
| 597 | if (dev->iamthif_timer) { |
| 598 | |
| 599 | timeout = dev->iamthif_timer + |
Tomas Winkler | 3870c32 | 2012-11-01 21:17:14 +0200 | [diff] [blame] | 600 | mei_secs_to_jiffies(MEI_IAMTHIF_READ_TIMER); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 601 | |
Tomas Winkler | 2bf94cab | 2014-09-29 16:31:42 +0300 | [diff] [blame] | 602 | dev_dbg(dev->dev, "dev->iamthif_timer = %ld\n", |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 603 | dev->iamthif_timer); |
Tomas Winkler | 2bf94cab | 2014-09-29 16:31:42 +0300 | [diff] [blame] | 604 | dev_dbg(dev->dev, "timeout = %ld\n", timeout); |
| 605 | dev_dbg(dev->dev, "jiffies = %ld\n", jiffies); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 606 | if (time_after(jiffies, timeout)) { |
| 607 | /* |
| 608 | * User didn't read the AMTHI data on time (15sec) |
| 609 | * freeing AMTHI for other requests |
| 610 | */ |
| 611 | |
Tomas Winkler | 2bf94cab | 2014-09-29 16:31:42 +0300 | [diff] [blame] | 612 | dev_dbg(dev->dev, "freeing AMTHI for other requests\n"); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 613 | |
Alexander Usyskin | 5456796 | 2014-08-14 17:22:20 +0300 | [diff] [blame] | 614 | mei_io_list_flush(&dev->amthif_rd_complete_list, |
| 615 | &dev->iamthif_cl); |
Tomas Winkler | 601a1ef | 2012-10-09 16:50:20 +0200 | [diff] [blame] | 616 | mei_io_cb_free(dev->iamthif_current_cb); |
| 617 | dev->iamthif_current_cb = NULL; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 618 | |
| 619 | dev->iamthif_file_object->private_data = NULL; |
| 620 | dev->iamthif_file_object = NULL; |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 621 | dev->iamthif_timer = 0; |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 622 | mei_amthif_run_next_cmd(dev); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 623 | |
| 624 | } |
| 625 | } |
| 626 | out: |
Tomas Winkler | 33ec082 | 2014-01-12 00:36:09 +0200 | [diff] [blame] | 627 | if (dev->dev_state != MEI_DEV_DISABLED) |
| 628 | schedule_delayed_work(&dev->timer_work, 2 * HZ); |
Tomas Winkler | 441ab50 | 2011-12-13 23:39:34 +0200 | [diff] [blame] | 629 | mutex_unlock(&dev->device_lock); |
Oren Weil | fb7d879 | 2011-05-15 13:43:42 +0300 | [diff] [blame] | 630 | } |