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. */ |
| 50 | dev->iamthif_current_cb = NULL; |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 51 | dev->iamthif_canceled = false; |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 52 | dev->iamthif_state = MEI_IAMTHIF_IDLE; |
| 53 | dev->iamthif_timer = 0; |
Alexander Usyskin | 4a70457 | 2013-09-02 13:29:47 +0300 | [diff] [blame] | 54 | dev->iamthif_stall_timer = 0; |
Tomas Winkler | 22f96a0 | 2013-09-16 23:44:47 +0300 | [diff] [blame] | 55 | dev->iamthif_open_count = 0; |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | /** |
Masanari Iida | 393b148 | 2013-04-05 01:05:05 +0900 | [diff] [blame] | 59 | * mei_amthif_host_init - mei initialization amthif client. |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 60 | * |
| 61 | * @dev: the device structure |
Alexander Usyskin | d49ed64 | 2015-05-04 09:43:54 +0300 | [diff] [blame] | 62 | * @me_cl: me client |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 63 | * |
Alexander Usyskin | ce23139 | 2014-09-29 16:31:50 +0300 | [diff] [blame] | 64 | * Return: 0 on success, <0 on failure. |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 65 | */ |
Alexander Usyskin | d49ed64 | 2015-05-04 09:43:54 +0300 | [diff] [blame] | 66 | 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] | 67 | { |
Tomas Winkler | 781d0d8 | 2013-01-08 23:07:22 +0200 | [diff] [blame] | 68 | struct mei_cl *cl = &dev->iamthif_cl; |
Tomas Winkler | d320832 | 2014-08-24 12:08:55 +0300 | [diff] [blame] | 69 | int ret; |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 70 | |
Tomas Winkler | 6222f7b | 2013-01-08 23:07:23 +0200 | [diff] [blame] | 71 | dev->iamthif_state = MEI_IAMTHIF_IDLE; |
| 72 | |
Tomas Winkler | 781d0d8 | 2013-01-08 23:07:22 +0200 | [diff] [blame] | 73 | mei_cl_init(cl, dev); |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 74 | |
Tomas Winkler | 781d0d8 | 2013-01-08 23:07:22 +0200 | [diff] [blame] | 75 | ret = mei_cl_link(cl, MEI_IAMTHIF_HOST_CLIENT_ID); |
Tomas Winkler | 781d0d8 | 2013-01-08 23:07:22 +0200 | [diff] [blame] | 76 | if (ret < 0) { |
Tomas Winkler | 79563db | 2015-01-11 00:07:16 +0200 | [diff] [blame] | 77 | dev_err(dev->dev, "amthif: failed cl_link %d\n", ret); |
Alexander Usyskin | d49ed64 | 2015-05-04 09:43:54 +0300 | [diff] [blame] | 78 | return ret; |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 79 | } |
Tomas Winkler | 781d0d8 | 2013-01-08 23:07:22 +0200 | [diff] [blame] | 80 | |
Alexander Usyskin | d49ed64 | 2015-05-04 09:43:54 +0300 | [diff] [blame] | 81 | ret = mei_cl_connect(cl, me_cl, NULL); |
Tomas Winkler | 6409285 | 2014-02-17 15:13:21 +0200 | [diff] [blame] | 82 | |
| 83 | dev->iamthif_state = MEI_IAMTHIF_IDLE; |
| 84 | |
| 85 | return ret; |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | /** |
| 89 | * mei_amthif_find_read_list_entry - finds a amthilist entry for current file |
| 90 | * |
| 91 | * @dev: the device structure |
| 92 | * @file: pointer to file object |
| 93 | * |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 94 | * Return: returned a list entry on success, NULL on failure. |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 95 | */ |
| 96 | struct mei_cl_cb *mei_amthif_find_read_list_entry(struct mei_device *dev, |
| 97 | struct file *file) |
| 98 | { |
Tomas Winkler | 31f88f5 | 2014-02-17 15:13:25 +0200 | [diff] [blame] | 99 | struct mei_cl_cb *cb; |
Tomas Winkler | 92db155 | 2014-09-29 16:31:37 +0300 | [diff] [blame] | 100 | |
Alexander Usyskin | 05e314e | 2014-08-14 17:22:21 +0300 | [diff] [blame] | 101 | list_for_each_entry(cb, &dev->amthif_rd_complete_list.list, list) |
| 102 | if (cb->file_object == file) |
Tomas Winkler | 31f88f5 | 2014-02-17 15:13:25 +0200 | [diff] [blame] | 103 | return cb; |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 104 | return NULL; |
| 105 | } |
| 106 | |
| 107 | |
| 108 | /** |
| 109 | * mei_amthif_read - read data from AMTHIF client |
| 110 | * |
| 111 | * @dev: the device structure |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 112 | * @file: pointer to file object |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 113 | * @ubuf: pointer to user data in user space |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 114 | * @length: data length to read |
| 115 | * @offset: data read offset |
| 116 | * |
| 117 | * Locking: called under "dev->device_lock" lock |
| 118 | * |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 119 | * Return: |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 120 | * returned data length on success, |
| 121 | * zero if no data to read, |
| 122 | * negative on failure. |
| 123 | */ |
| 124 | int mei_amthif_read(struct mei_device *dev, struct file *file, |
| 125 | char __user *ubuf, size_t length, loff_t *offset) |
| 126 | { |
Tomas Winkler | d320832 | 2014-08-24 12:08:55 +0300 | [diff] [blame] | 127 | struct mei_cl *cl = file->private_data; |
| 128 | struct mei_cl_cb *cb; |
| 129 | unsigned long timeout; |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 130 | int rets; |
| 131 | int wait_ret; |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 132 | |
Alexander Usyskin | 83ce074 | 2014-01-08 22:31:46 +0200 | [diff] [blame] | 133 | /* Only possible if we are in timeout */ |
Alexander Usyskin | 05e314e | 2014-08-14 17:22:21 +0300 | [diff] [blame] | 134 | if (!cl) { |
Tomas Winkler | 2bf94cab | 2014-09-29 16:31:42 +0300 | [diff] [blame] | 135 | dev_err(dev->dev, "bad file ext.\n"); |
Alexander Usyskin | 7ca96aa | 2014-02-19 17:35:49 +0200 | [diff] [blame] | 136 | return -ETIME; |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 137 | } |
| 138 | |
Tomas Winkler | 2bf94cab | 2014-09-29 16:31:42 +0300 | [diff] [blame] | 139 | dev_dbg(dev->dev, "checking amthif data\n"); |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 140 | cb = mei_amthif_find_read_list_entry(dev, file); |
| 141 | |
| 142 | /* Check for if we can block or not*/ |
| 143 | if (cb == NULL && file->f_flags & O_NONBLOCK) |
| 144 | return -EAGAIN; |
| 145 | |
| 146 | |
Tomas Winkler | 2bf94cab | 2014-09-29 16:31:42 +0300 | [diff] [blame] | 147 | dev_dbg(dev->dev, "waiting for amthif data\n"); |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 148 | while (cb == NULL) { |
| 149 | /* unlock the Mutex */ |
| 150 | mutex_unlock(&dev->device_lock); |
| 151 | |
| 152 | wait_ret = wait_event_interruptible(dev->iamthif_cl.wait, |
| 153 | (cb = mei_amthif_find_read_list_entry(dev, file))); |
| 154 | |
Alexey Khoroshilov | e6028db | 2012-12-22 01:44:16 +0400 | [diff] [blame] | 155 | /* Locking again the Mutex */ |
| 156 | mutex_lock(&dev->device_lock); |
| 157 | |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 158 | if (wait_ret) |
| 159 | return -ERESTARTSYS; |
| 160 | |
Tomas Winkler | 2bf94cab | 2014-09-29 16:31:42 +0300 | [diff] [blame] | 161 | dev_dbg(dev->dev, "woke up from sleep\n"); |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 162 | } |
| 163 | |
Tomas Winkler | db4756f | 2015-02-10 10:39:37 +0200 | [diff] [blame] | 164 | if (cb->status) { |
| 165 | rets = cb->status; |
| 166 | dev_dbg(dev->dev, "read operation failed %d\n", rets); |
| 167 | goto free; |
| 168 | } |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 169 | |
Tomas Winkler | 2bf94cab | 2014-09-29 16:31:42 +0300 | [diff] [blame] | 170 | dev_dbg(dev->dev, "Got amthif data\n"); |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 171 | dev->iamthif_timer = 0; |
| 172 | |
Tomas Winkler | db4756f | 2015-02-10 10:39:37 +0200 | [diff] [blame] | 173 | timeout = cb->read_time + |
| 174 | mei_secs_to_jiffies(MEI_IAMTHIF_READ_TIMER); |
| 175 | dev_dbg(dev->dev, "amthif timeout = %lud\n", |
| 176 | timeout); |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 177 | |
Tomas Winkler | db4756f | 2015-02-10 10:39:37 +0200 | [diff] [blame] | 178 | if (time_after(jiffies, timeout)) { |
| 179 | dev_dbg(dev->dev, "amthif Time out\n"); |
| 180 | /* 15 sec for the message has expired */ |
Tomas Winkler | 928fa66 | 2015-02-10 10:39:45 +0200 | [diff] [blame] | 181 | list_del_init(&cb->list); |
Tomas Winkler | db4756f | 2015-02-10 10:39:37 +0200 | [diff] [blame] | 182 | rets = -ETIME; |
| 183 | goto free; |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 184 | } |
| 185 | /* if the whole message will fit remove it from the list */ |
| 186 | if (cb->buf_idx >= *offset && length >= (cb->buf_idx - *offset)) |
Tomas Winkler | 928fa66 | 2015-02-10 10:39:45 +0200 | [diff] [blame] | 187 | list_del_init(&cb->list); |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 188 | else if (cb->buf_idx > 0 && cb->buf_idx <= *offset) { |
| 189 | /* end of the message has been reached */ |
Tomas Winkler | 928fa66 | 2015-02-10 10:39:45 +0200 | [diff] [blame] | 190 | list_del_init(&cb->list); |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 191 | rets = 0; |
| 192 | goto free; |
| 193 | } |
| 194 | /* else means that not full buffer will be read and do not |
| 195 | * remove message from deletion list |
| 196 | */ |
| 197 | |
Tomas Winkler | 5db7514 | 2015-02-10 10:39:42 +0200 | [diff] [blame] | 198 | dev_dbg(dev->dev, "amthif cb->buf size - %d\n", |
| 199 | cb->buf.size); |
Tomas Winkler | 2bf94cab | 2014-09-29 16:31:42 +0300 | [diff] [blame] | 200 | dev_dbg(dev->dev, "amthif cb->buf_idx - %lu\n", cb->buf_idx); |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 201 | |
Alexander Usyskin | 83ce074 | 2014-01-08 22:31:46 +0200 | [diff] [blame] | 202 | /* length is being truncated to PAGE_SIZE, however, |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 203 | * the buf_idx may point beyond */ |
| 204 | length = min_t(size_t, length, (cb->buf_idx - *offset)); |
| 205 | |
Tomas Winkler | 5db7514 | 2015-02-10 10:39:42 +0200 | [diff] [blame] | 206 | if (copy_to_user(ubuf, cb->buf.data + *offset, length)) { |
Tomas Winkler | 2bf94cab | 2014-09-29 16:31:42 +0300 | [diff] [blame] | 207 | dev_dbg(dev->dev, "failed to copy data to userland\n"); |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 208 | rets = -EFAULT; |
Tomas Winkler | 34e267d | 2014-03-16 14:35:57 +0200 | [diff] [blame] | 209 | } else { |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 210 | rets = length; |
| 211 | if ((*offset + length) < cb->buf_idx) { |
| 212 | *offset += length; |
| 213 | goto out; |
| 214 | } |
| 215 | } |
| 216 | free: |
Tomas Winkler | 2bf94cab | 2014-09-29 16:31:42 +0300 | [diff] [blame] | 217 | dev_dbg(dev->dev, "free amthif cb memory.\n"); |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 218 | *offset = 0; |
| 219 | mei_io_cb_free(cb); |
| 220 | out: |
| 221 | return rets; |
| 222 | } |
| 223 | |
| 224 | /** |
Tomas Winkler | c54bf3a | 2015-02-10 10:39:39 +0200 | [diff] [blame] | 225 | * mei_amthif_read_start - queue message for sending read credential |
| 226 | * |
| 227 | * @cl: host client |
| 228 | * @file: file pointer of message recipient |
| 229 | * |
| 230 | * Return: 0 on success, <0 on failure. |
| 231 | */ |
| 232 | static int mei_amthif_read_start(struct mei_cl *cl, struct file *file) |
| 233 | { |
| 234 | struct mei_device *dev = cl->dev; |
| 235 | struct mei_cl_cb *cb; |
Tomas Winkler | c54bf3a | 2015-02-10 10:39:39 +0200 | [diff] [blame] | 236 | int rets; |
| 237 | |
Tomas Winkler | bca67d6 | 2015-02-10 10:39:43 +0200 | [diff] [blame] | 238 | cb = mei_io_cb_init(cl, MEI_FOP_READ, file); |
Tomas Winkler | c54bf3a | 2015-02-10 10:39:39 +0200 | [diff] [blame] | 239 | if (!cb) { |
| 240 | rets = -ENOMEM; |
| 241 | goto err; |
| 242 | } |
| 243 | |
Alexander Usyskin | 9e23936 | 2015-05-04 09:43:58 +0300 | [diff] [blame] | 244 | rets = mei_io_cb_alloc_buf(cb, mei_cl_mtu(cl)); |
Tomas Winkler | c54bf3a | 2015-02-10 10:39:39 +0200 | [diff] [blame] | 245 | if (rets) |
| 246 | goto err; |
| 247 | |
Tomas Winkler | c54bf3a | 2015-02-10 10:39:39 +0200 | [diff] [blame] | 248 | list_add_tail(&cb->list, &dev->ctrl_wr_list.list); |
| 249 | |
Tomas Winkler | c54bf3a | 2015-02-10 10:39:39 +0200 | [diff] [blame] | 250 | dev->iamthif_state = MEI_IAMTHIF_READING; |
| 251 | dev->iamthif_file_object = cb->file_object; |
| 252 | dev->iamthif_current_cb = cb; |
| 253 | |
| 254 | return 0; |
| 255 | err: |
| 256 | mei_io_cb_free(cb); |
| 257 | return rets; |
| 258 | } |
| 259 | |
| 260 | /** |
Tomas Winkler | ab5c4a5 | 2012-11-01 21:17:18 +0200 | [diff] [blame] | 261 | * mei_amthif_send_cmd - send amthif command to the ME |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 262 | * |
Tomas Winkler | 8660172 | 2015-02-10 10:39:40 +0200 | [diff] [blame] | 263 | * @cl: the host client |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 264 | * @cb: mei call back struct |
| 265 | * |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 266 | * Return: 0 on success, <0 on failure. |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 267 | */ |
Tomas Winkler | 8660172 | 2015-02-10 10:39:40 +0200 | [diff] [blame] | 268 | static int mei_amthif_send_cmd(struct mei_cl *cl, struct mei_cl_cb *cb) |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 269 | { |
Tomas Winkler | 8660172 | 2015-02-10 10:39:40 +0200 | [diff] [blame] | 270 | struct mei_device *dev; |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 271 | int ret; |
| 272 | |
Tomas Winkler | 8660172 | 2015-02-10 10:39:40 +0200 | [diff] [blame] | 273 | if (!cl->dev || !cb) |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 274 | return -ENODEV; |
| 275 | |
Tomas Winkler | 8660172 | 2015-02-10 10:39:40 +0200 | [diff] [blame] | 276 | dev = cl->dev; |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 277 | |
| 278 | dev->iamthif_state = MEI_IAMTHIF_WRITING; |
| 279 | dev->iamthif_current_cb = cb; |
| 280 | dev->iamthif_file_object = cb->file_object; |
| 281 | dev->iamthif_canceled = false; |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 282 | |
Tomas Winkler | 8660172 | 2015-02-10 10:39:40 +0200 | [diff] [blame] | 283 | ret = mei_cl_write(cl, cb, false); |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 284 | if (ret < 0) |
| 285 | return ret; |
| 286 | |
Tomas Winkler | 8660172 | 2015-02-10 10:39:40 +0200 | [diff] [blame] | 287 | if (cb->completed) |
| 288 | cb->status = mei_amthif_read_start(cl, cb->file_object); |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 289 | |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 290 | return 0; |
| 291 | } |
| 292 | |
| 293 | /** |
Alexander Usyskin | ce23139 | 2014-09-29 16:31:50 +0300 | [diff] [blame] | 294 | * mei_amthif_run_next_cmd - send next amt command from queue |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 295 | * |
| 296 | * @dev: the device structure |
Tomas Winkler | 8660172 | 2015-02-10 10:39:40 +0200 | [diff] [blame] | 297 | * |
| 298 | * Return: 0 on success, <0 on failure. |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 299 | */ |
Tomas Winkler | 8660172 | 2015-02-10 10:39:40 +0200 | [diff] [blame] | 300 | int mei_amthif_run_next_cmd(struct mei_device *dev) |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 301 | { |
Tomas Winkler | 8660172 | 2015-02-10 10:39:40 +0200 | [diff] [blame] | 302 | struct mei_cl *cl = &dev->iamthif_cl; |
Alexander Usyskin | 05e314e | 2014-08-14 17:22:21 +0300 | [diff] [blame] | 303 | struct mei_cl_cb *cb; |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 304 | |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 305 | dev->iamthif_canceled = false; |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 306 | dev->iamthif_state = MEI_IAMTHIF_IDLE; |
| 307 | dev->iamthif_timer = 0; |
| 308 | dev->iamthif_file_object = NULL; |
| 309 | |
Tomas Winkler | 2bf94cab | 2014-09-29 16:31:42 +0300 | [diff] [blame] | 310 | dev_dbg(dev->dev, "complete amthif cmd_list cb.\n"); |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 311 | |
Alexander Usyskin | 140c755 | 2014-10-02 13:39:31 +0300 | [diff] [blame] | 312 | cb = list_first_entry_or_null(&dev->amthif_cmd_list.list, |
| 313 | typeof(*cb), list); |
| 314 | if (!cb) |
Tomas Winkler | 8660172 | 2015-02-10 10:39:40 +0200 | [diff] [blame] | 315 | return 0; |
| 316 | |
Tomas Winkler | c54bf3a | 2015-02-10 10:39:39 +0200 | [diff] [blame] | 317 | list_del_init(&cb->list); |
Tomas Winkler | 8660172 | 2015-02-10 10:39:40 +0200 | [diff] [blame] | 318 | return mei_amthif_send_cmd(cl, cb); |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 319 | } |
| 320 | |
Tomas Winkler | 8660172 | 2015-02-10 10:39:40 +0200 | [diff] [blame] | 321 | /** |
| 322 | * mei_amthif_write - write amthif data to amthif client |
| 323 | * |
| 324 | * @cl: host client |
| 325 | * @cb: mei call back struct |
| 326 | * |
| 327 | * Return: 0 on success, <0 on failure. |
| 328 | */ |
| 329 | int mei_amthif_write(struct mei_cl *cl, struct mei_cl_cb *cb) |
| 330 | { |
| 331 | |
| 332 | struct mei_device *dev; |
| 333 | |
| 334 | if (WARN_ON(!cl || !cl->dev)) |
| 335 | return -ENODEV; |
| 336 | |
| 337 | if (WARN_ON(!cb)) |
| 338 | return -EINVAL; |
| 339 | |
| 340 | dev = cl->dev; |
| 341 | |
Tomas Winkler | 8660172 | 2015-02-10 10:39:40 +0200 | [diff] [blame] | 342 | list_add_tail(&cb->list, &dev->amthif_cmd_list.list); |
| 343 | return mei_amthif_run_next_cmd(dev); |
| 344 | } |
Tomas Winkler | 744f0f2 | 2012-11-11 17:38:02 +0200 | [diff] [blame] | 345 | |
Tomas Winkler | 1d9013f | 2015-03-27 00:27:57 +0200 | [diff] [blame] | 346 | /** |
| 347 | * mei_amthif_poll - the amthif poll function |
| 348 | * |
| 349 | * @dev: the device structure |
| 350 | * @file: pointer to file structure |
| 351 | * @wait: pointer to poll_table structure |
| 352 | * |
| 353 | * Return: poll mask |
| 354 | * |
| 355 | * Locking: called under "dev->device_lock" lock |
| 356 | */ |
Tomas Winkler | 744f0f2 | 2012-11-11 17:38:02 +0200 | [diff] [blame] | 357 | |
| 358 | unsigned int mei_amthif_poll(struct mei_device *dev, |
| 359 | struct file *file, poll_table *wait) |
| 360 | { |
| 361 | unsigned int mask = 0; |
Tomas Winkler | b950ac1 | 2013-07-25 20:15:53 +0300 | [diff] [blame] | 362 | |
Tomas Winkler | 744f0f2 | 2012-11-11 17:38:02 +0200 | [diff] [blame] | 363 | poll_wait(file, &dev->iamthif_cl.wait, wait); |
Tomas Winkler | b950ac1 | 2013-07-25 20:15:53 +0300 | [diff] [blame] | 364 | |
Tomas Winkler | 1d9013f | 2015-03-27 00:27:57 +0200 | [diff] [blame] | 365 | if (dev->iamthif_state == MEI_IAMTHIF_READ_COMPLETE && |
| 366 | dev->iamthif_file_object == file) { |
Tomas Winkler | b950ac1 | 2013-07-25 20:15:53 +0300 | [diff] [blame] | 367 | |
Tomas Winkler | 1d9013f | 2015-03-27 00:27:57 +0200 | [diff] [blame] | 368 | mask |= POLLIN | POLLRDNORM; |
Tomas Winkler | 744f0f2 | 2012-11-11 17:38:02 +0200 | [diff] [blame] | 369 | mei_amthif_run_next_cmd(dev); |
| 370 | } |
Tomas Winkler | b950ac1 | 2013-07-25 20:15:53 +0300 | [diff] [blame] | 371 | |
Tomas Winkler | 744f0f2 | 2012-11-11 17:38:02 +0200 | [diff] [blame] | 372 | return mask; |
| 373 | } |
| 374 | |
| 375 | |
| 376 | |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 377 | /** |
Tomas Winkler | 9d09819 | 2014-02-19 17:35:48 +0200 | [diff] [blame] | 378 | * mei_amthif_irq_write - write iamthif command in irq thread context. |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 379 | * |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 380 | * @cl: private data of the file object. |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 381 | * @cb: callback block. |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 382 | * @cmpl_list: complete list. |
| 383 | * |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 384 | * Return: 0, OK; otherwise, error. |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 385 | */ |
Tomas Winkler | 9d09819 | 2014-02-19 17:35:48 +0200 | [diff] [blame] | 386 | int mei_amthif_irq_write(struct mei_cl *cl, struct mei_cl_cb *cb, |
| 387 | struct mei_cl_cb *cmpl_list) |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 388 | { |
Tomas Winkler | 8660172 | 2015-02-10 10:39:40 +0200 | [diff] [blame] | 389 | int ret; |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 390 | |
Tomas Winkler | 8660172 | 2015-02-10 10:39:40 +0200 | [diff] [blame] | 391 | ret = mei_cl_irq_write(cl, cb, cmpl_list); |
| 392 | if (ret) |
| 393 | return ret; |
Tomas Winkler | 136698e | 2013-09-16 23:44:44 +0300 | [diff] [blame] | 394 | |
Tomas Winkler | 8660172 | 2015-02-10 10:39:40 +0200 | [diff] [blame] | 395 | if (cb->completed) |
Tomas Winkler | c54bf3a | 2015-02-10 10:39:39 +0200 | [diff] [blame] | 396 | cb->status = mei_amthif_read_start(cl, cb->file_object); |
Tomas Winkler | 24c656e | 2012-11-18 15:13:17 +0200 | [diff] [blame] | 397 | |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 398 | return 0; |
| 399 | } |
| 400 | |
| 401 | /** |
Alexander Usyskin | ce23139 | 2014-09-29 16:31:50 +0300 | [diff] [blame] | 402 | * mei_amthif_irq_read_msg - read routine after ISR to |
Tomas Winkler | 1a1aca4 | 2013-01-08 23:07:21 +0200 | [diff] [blame] | 403 | * handle the read amthif message |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 404 | * |
Tomas Winkler | db4756f | 2015-02-10 10:39:37 +0200 | [diff] [blame] | 405 | * @cl: mei client |
Tomas Winkler | 1a1aca4 | 2013-01-08 23:07:21 +0200 | [diff] [blame] | 406 | * @mei_hdr: header of amthif message |
Tomas Winkler | 331e418 | 2015-02-10 10:39:41 +0200 | [diff] [blame] | 407 | * @cmpl_list: completed callbacks list |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 408 | * |
Tomas Winkler | 331e418 | 2015-02-10 10:39:41 +0200 | [diff] [blame] | 409 | * 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] | 410 | */ |
Tomas Winkler | db4756f | 2015-02-10 10:39:37 +0200 | [diff] [blame] | 411 | int mei_amthif_irq_read_msg(struct mei_cl *cl, |
Tomas Winkler | 5ceb46e | 2013-04-19 21:16:53 +0300 | [diff] [blame] | 412 | struct mei_msg_hdr *mei_hdr, |
Tomas Winkler | 331e418 | 2015-02-10 10:39:41 +0200 | [diff] [blame] | 413 | struct mei_cl_cb *cmpl_list) |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 414 | { |
Tomas Winkler | db4756f | 2015-02-10 10:39:37 +0200 | [diff] [blame] | 415 | struct mei_device *dev; |
Tomas Winkler | 331e418 | 2015-02-10 10:39:41 +0200 | [diff] [blame] | 416 | int ret; |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 417 | |
Tomas Winkler | db4756f | 2015-02-10 10:39:37 +0200 | [diff] [blame] | 418 | dev = cl->dev; |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 419 | |
Tomas Winkler | db4756f | 2015-02-10 10:39:37 +0200 | [diff] [blame] | 420 | if (dev->iamthif_state != MEI_IAMTHIF_READING) |
Tomas Winkler | 331e418 | 2015-02-10 10:39:41 +0200 | [diff] [blame] | 421 | return 0; |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 422 | |
Tomas Winkler | 331e418 | 2015-02-10 10:39:41 +0200 | [diff] [blame] | 423 | ret = mei_cl_irq_read_msg(cl, mei_hdr, cmpl_list); |
| 424 | if (ret) |
| 425 | return ret; |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 426 | |
| 427 | if (!mei_hdr->msg_complete) |
| 428 | return 0; |
| 429 | |
Tomas Winkler | 2bf94cab | 2014-09-29 16:31:42 +0300 | [diff] [blame] | 430 | dev_dbg(dev->dev, "completed amthif read.\n "); |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 431 | dev->iamthif_current_cb = NULL; |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 432 | dev->iamthif_stall_timer = 0; |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 433 | |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 434 | return 0; |
| 435 | } |
| 436 | |
| 437 | /** |
| 438 | * mei_amthif_complete - complete amthif callback. |
| 439 | * |
| 440 | * @dev: the device structure. |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 441 | * @cb: callback block. |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 442 | */ |
| 443 | void mei_amthif_complete(struct mei_device *dev, struct mei_cl_cb *cb) |
| 444 | { |
Tomas Winkler | c54bf3a | 2015-02-10 10:39:39 +0200 | [diff] [blame] | 445 | |
| 446 | if (cb->fop_type == MEI_FOP_WRITE) { |
| 447 | if (!cb->status) { |
| 448 | dev->iamthif_stall_timer = MEI_IAMTHIF_STALL_TIMER; |
| 449 | mei_io_cb_free(cb); |
| 450 | return; |
| 451 | } |
| 452 | /* |
| 453 | * in case of error enqueue the write cb to complete read list |
| 454 | * so it can be propagated to the reader |
| 455 | */ |
| 456 | list_add_tail(&cb->list, &dev->amthif_rd_complete_list.list); |
| 457 | wake_up_interruptible(&dev->iamthif_cl.wait); |
| 458 | return; |
| 459 | } |
| 460 | |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 461 | if (dev->iamthif_canceled != 1) { |
| 462 | dev->iamthif_state = MEI_IAMTHIF_READ_COMPLETE; |
| 463 | dev->iamthif_stall_timer = 0; |
Tomas Winkler | e773efc | 2012-11-11 17:37:58 +0200 | [diff] [blame] | 464 | list_add_tail(&cb->list, &dev->amthif_rd_complete_list.list); |
Tomas Winkler | 2bf94cab | 2014-09-29 16:31:42 +0300 | [diff] [blame] | 465 | dev_dbg(dev->dev, "amthif read completed\n"); |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 466 | dev->iamthif_timer = jiffies; |
Tomas Winkler | 2bf94cab | 2014-09-29 16:31:42 +0300 | [diff] [blame] | 467 | dev_dbg(dev->dev, "dev->iamthif_timer = %ld\n", |
Tomas Winkler | c54bf3a | 2015-02-10 10:39:39 +0200 | [diff] [blame] | 468 | dev->iamthif_timer); |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 469 | } else { |
| 470 | mei_amthif_run_next_cmd(dev); |
| 471 | } |
| 472 | |
Tomas Winkler | 2bf94cab | 2014-09-29 16:31:42 +0300 | [diff] [blame] | 473 | dev_dbg(dev->dev, "completing amthif call back.\n"); |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 474 | wake_up_interruptible(&dev->iamthif_cl.wait); |
| 475 | } |
| 476 | |
Tomas Winkler | a562d5c | 2012-11-11 17:38:01 +0200 | [diff] [blame] | 477 | /** |
| 478 | * mei_clear_list - removes all callbacks associated with file |
| 479 | * from mei_cb_list |
| 480 | * |
| 481 | * @dev: device structure. |
| 482 | * @file: file structure |
| 483 | * @mei_cb_list: callbacks list |
| 484 | * |
| 485 | * mei_clear_list is called to clear resources associated with file |
| 486 | * when application calls close function or Ctrl-C was pressed |
| 487 | * |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 488 | * Return: true if callback removed from the list, false otherwise |
Tomas Winkler | a562d5c | 2012-11-11 17:38:01 +0200 | [diff] [blame] | 489 | */ |
| 490 | static bool mei_clear_list(struct mei_device *dev, |
| 491 | const struct file *file, struct list_head *mei_cb_list) |
| 492 | { |
Tomas Winkler | 928fa66 | 2015-02-10 10:39:45 +0200 | [diff] [blame] | 493 | struct mei_cl *cl = &dev->iamthif_cl; |
| 494 | struct mei_cl_cb *cb, *next; |
Tomas Winkler | a562d5c | 2012-11-11 17:38:01 +0200 | [diff] [blame] | 495 | bool removed = false; |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 496 | |
Tomas Winkler | a562d5c | 2012-11-11 17:38:01 +0200 | [diff] [blame] | 497 | /* list all list member */ |
Tomas Winkler | 928fa66 | 2015-02-10 10:39:45 +0200 | [diff] [blame] | 498 | list_for_each_entry_safe(cb, next, mei_cb_list, list) { |
Tomas Winkler | a562d5c | 2012-11-11 17:38:01 +0200 | [diff] [blame] | 499 | /* check if list member associated with a file */ |
Tomas Winkler | 928fa66 | 2015-02-10 10:39:45 +0200 | [diff] [blame] | 500 | if (file == cb->file_object) { |
Tomas Winkler | a562d5c | 2012-11-11 17:38:01 +0200 | [diff] [blame] | 501 | /* check if cb equal to current iamthif cb */ |
Tomas Winkler | 928fa66 | 2015-02-10 10:39:45 +0200 | [diff] [blame] | 502 | if (dev->iamthif_current_cb == cb) { |
Tomas Winkler | a562d5c | 2012-11-11 17:38:01 +0200 | [diff] [blame] | 503 | dev->iamthif_current_cb = NULL; |
| 504 | /* send flow control to iamthif client */ |
Tomas Winkler | 928fa66 | 2015-02-10 10:39:45 +0200 | [diff] [blame] | 505 | mei_hbm_cl_flow_control_req(dev, cl); |
Tomas Winkler | a562d5c | 2012-11-11 17:38:01 +0200 | [diff] [blame] | 506 | } |
| 507 | /* free all allocated buffers */ |
Tomas Winkler | 928fa66 | 2015-02-10 10:39:45 +0200 | [diff] [blame] | 508 | mei_io_cb_free(cb); |
Tomas Winkler | a562d5c | 2012-11-11 17:38:01 +0200 | [diff] [blame] | 509 | removed = true; |
| 510 | } |
| 511 | } |
| 512 | return removed; |
| 513 | } |
| 514 | |
| 515 | /** |
| 516 | * mei_clear_lists - removes all callbacks associated with file |
| 517 | * |
| 518 | * @dev: device structure |
| 519 | * @file: file structure |
| 520 | * |
| 521 | * mei_clear_lists is called to clear resources associated with file |
| 522 | * when application calls close function or Ctrl-C was pressed |
| 523 | * |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 524 | * Return: true if callback removed from the list, false otherwise |
Tomas Winkler | a562d5c | 2012-11-11 17:38:01 +0200 | [diff] [blame] | 525 | */ |
| 526 | static bool mei_clear_lists(struct mei_device *dev, struct file *file) |
| 527 | { |
| 528 | bool removed = false; |
| 529 | |
| 530 | /* remove callbacks associated with a file */ |
| 531 | mei_clear_list(dev, file, &dev->amthif_cmd_list.list); |
| 532 | if (mei_clear_list(dev, file, &dev->amthif_rd_complete_list.list)) |
| 533 | removed = true; |
| 534 | |
| 535 | mei_clear_list(dev, file, &dev->ctrl_rd_list.list); |
| 536 | |
| 537 | if (mei_clear_list(dev, file, &dev->ctrl_wr_list.list)) |
| 538 | removed = true; |
| 539 | |
| 540 | if (mei_clear_list(dev, file, &dev->write_waiting_list.list)) |
| 541 | removed = true; |
| 542 | |
| 543 | if (mei_clear_list(dev, file, &dev->write_list.list)) |
| 544 | removed = true; |
| 545 | |
| 546 | /* check if iamthif_current_cb not NULL */ |
| 547 | if (dev->iamthif_current_cb && !removed) { |
| 548 | /* check file and iamthif current cb association */ |
| 549 | if (dev->iamthif_current_cb->file_object == file) { |
| 550 | /* remove cb */ |
| 551 | mei_io_cb_free(dev->iamthif_current_cb); |
| 552 | dev->iamthif_current_cb = NULL; |
| 553 | removed = true; |
| 554 | } |
| 555 | } |
| 556 | return removed; |
| 557 | } |
| 558 | |
| 559 | /** |
| 560 | * mei_amthif_release - the release function |
| 561 | * |
Masanari Iida | 393b148 | 2013-04-05 01:05:05 +0900 | [diff] [blame] | 562 | * @dev: device structure |
Tomas Winkler | a562d5c | 2012-11-11 17:38:01 +0200 | [diff] [blame] | 563 | * @file: pointer to file structure |
| 564 | * |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 565 | * Return: 0 on success, <0 on error |
Tomas Winkler | a562d5c | 2012-11-11 17:38:01 +0200 | [diff] [blame] | 566 | */ |
| 567 | int mei_amthif_release(struct mei_device *dev, struct file *file) |
| 568 | { |
Tomas Winkler | 22f96a0 | 2013-09-16 23:44:47 +0300 | [diff] [blame] | 569 | if (dev->iamthif_open_count > 0) |
| 570 | dev->iamthif_open_count--; |
Tomas Winkler | a562d5c | 2012-11-11 17:38:01 +0200 | [diff] [blame] | 571 | |
| 572 | if (dev->iamthif_file_object == file && |
| 573 | dev->iamthif_state != MEI_IAMTHIF_IDLE) { |
| 574 | |
Tomas Winkler | 2bf94cab | 2014-09-29 16:31:42 +0300 | [diff] [blame] | 575 | dev_dbg(dev->dev, "amthif canceled iamthif state %d\n", |
Tomas Winkler | a562d5c | 2012-11-11 17:38:01 +0200 | [diff] [blame] | 576 | dev->iamthif_state); |
| 577 | dev->iamthif_canceled = true; |
| 578 | if (dev->iamthif_state == MEI_IAMTHIF_READ_COMPLETE) { |
Tomas Winkler | 2bf94cab | 2014-09-29 16:31:42 +0300 | [diff] [blame] | 579 | dev_dbg(dev->dev, "run next amthif iamthif cb\n"); |
Tomas Winkler | a562d5c | 2012-11-11 17:38:01 +0200 | [diff] [blame] | 580 | mei_amthif_run_next_cmd(dev); |
| 581 | } |
| 582 | } |
| 583 | |
| 584 | if (mei_clear_lists(dev, file)) |
| 585 | dev->iamthif_state = MEI_IAMTHIF_IDLE; |
| 586 | |
| 587 | return 0; |
| 588 | } |