Oren Weil | 3ceb3e6 | 2011-05-15 13:43:47 +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 | 3ceb3e6 | 2011-05-15 13:43:47 +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 | #include <linux/kernel.h> |
| 17 | #include <linux/module.h> |
| 18 | #include <linux/moduleparam.h> |
| 19 | #include <linux/device.h> |
Oren Weil | 3ceb3e6 | 2011-05-15 13:43:47 +0300 | [diff] [blame] | 20 | #include <linux/sched.h> |
Oren Weil | 9ce178e | 2011-09-07 09:03:09 +0300 | [diff] [blame] | 21 | #include <linux/watchdog.h> |
Oren Weil | 3ceb3e6 | 2011-05-15 13:43:47 +0300 | [diff] [blame] | 22 | |
Tomas Winkler | 4f3afe1 | 2012-05-09 16:38:59 +0300 | [diff] [blame] | 23 | #include <linux/mei.h> |
Oren Weil | 3ceb3e6 | 2011-05-15 13:43:47 +0300 | [diff] [blame] | 24 | |
Tomas Winkler | 47a7380 | 2012-12-25 19:06:03 +0200 | [diff] [blame] | 25 | #include "mei_dev.h" |
Tomas Winkler | 0edb23f | 2013-01-08 23:07:12 +0200 | [diff] [blame] | 26 | #include "hbm.h" |
Tomas Winkler | 90e0b5f | 2013-01-08 23:07:14 +0200 | [diff] [blame] | 27 | #include "client.h" |
Tomas Winkler | 47a7380 | 2012-12-25 19:06:03 +0200 | [diff] [blame] | 28 | |
Oren Weil | 3ceb3e6 | 2011-05-15 13:43:47 +0300 | [diff] [blame] | 29 | static const u8 mei_start_wd_params[] = { 0x02, 0x12, 0x13, 0x10 }; |
| 30 | static const u8 mei_stop_wd_params[] = { 0x02, 0x02, 0x14, 0x10 }; |
| 31 | |
Tomas Winkler | 70cd533 | 2011-12-22 18:50:50 +0200 | [diff] [blame] | 32 | /* |
| 33 | * AMT Watchdog Device |
| 34 | */ |
| 35 | #define INTEL_AMT_WATCHDOG_ID "INTCAMT" |
| 36 | |
Oren Weil | 3ceb3e6 | 2011-05-15 13:43:47 +0300 | [diff] [blame] | 37 | /* UUIDs for AMT F/W clients */ |
| 38 | const uuid_le mei_wd_guid = UUID_LE(0x05B79A6F, 0x4628, 0x4D7F, 0x89, |
| 39 | 0x9D, 0xA9, 0x15, 0x14, 0xCB, |
| 40 | 0x32, 0xAB); |
| 41 | |
Tomas Winkler | 5192dda | 2012-03-19 17:58:43 +0200 | [diff] [blame] | 42 | static void mei_wd_set_start_timeout(struct mei_device *dev, u16 timeout) |
Oren Weil | 3ceb3e6 | 2011-05-15 13:43:47 +0300 | [diff] [blame] | 43 | { |
Tomas Winkler | 2bf94cab | 2014-09-29 16:31:42 +0300 | [diff] [blame] | 44 | dev_dbg(dev->dev, "wd: set timeout=%d.\n", timeout); |
Tomas Winkler | 248ffdf | 2012-08-16 19:39:42 +0300 | [diff] [blame] | 45 | memcpy(dev->wd_data, mei_start_wd_params, MEI_WD_HDR_SIZE); |
| 46 | memcpy(dev->wd_data + MEI_WD_HDR_SIZE, &timeout, sizeof(u16)); |
Oren Weil | 3ceb3e6 | 2011-05-15 13:43:47 +0300 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | /** |
Tomas Winkler | 7cb1ba9 | 2012-07-04 19:24:51 +0300 | [diff] [blame] | 50 | * mei_wd_host_init - connect to the watchdog client |
Oren Weil | 3ceb3e6 | 2011-05-15 13:43:47 +0300 | [diff] [blame] | 51 | * |
| 52 | * @dev: the device structure |
Masanari Iida | 393b148 | 2013-04-05 01:05:05 +0900 | [diff] [blame] | 53 | * |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 54 | * Return: -ENOTTY if wd client cannot be found |
Tomas Winkler | 9487eb0 | 2012-04-03 23:34:58 +0300 | [diff] [blame] | 55 | * -EIO if write has failed |
Tomas Winkler | 7cb1ba9 | 2012-07-04 19:24:51 +0300 | [diff] [blame] | 56 | * 0 on success |
Oren Weil | 3ceb3e6 | 2011-05-15 13:43:47 +0300 | [diff] [blame] | 57 | */ |
Tomas Winkler | 9487eb0 | 2012-04-03 23:34:58 +0300 | [diff] [blame] | 58 | int mei_wd_host_init(struct mei_device *dev) |
Oren Weil | 3ceb3e6 | 2011-05-15 13:43:47 +0300 | [diff] [blame] | 59 | { |
Tomas Winkler | 781d0d8 | 2013-01-08 23:07:22 +0200 | [diff] [blame] | 60 | struct mei_cl *cl = &dev->wd_cl; |
Tomas Winkler | d320832 | 2014-08-24 12:08:55 +0300 | [diff] [blame] | 61 | struct mei_me_client *me_cl; |
Tomas Winkler | 781d0d8 | 2013-01-08 23:07:22 +0200 | [diff] [blame] | 62 | int ret; |
Oren Weil | 3ceb3e6 | 2011-05-15 13:43:47 +0300 | [diff] [blame] | 63 | |
Tomas Winkler | 781d0d8 | 2013-01-08 23:07:22 +0200 | [diff] [blame] | 64 | mei_cl_init(cl, dev); |
| 65 | |
Tomas Winkler | 248ffdf | 2012-08-16 19:39:42 +0300 | [diff] [blame] | 66 | dev->wd_timeout = MEI_WD_DEFAULT_TIMEOUT; |
Tomas Winkler | c216fde | 2012-08-16 19:39:43 +0300 | [diff] [blame] | 67 | dev->wd_state = MEI_WD_IDLE; |
Oren Weil | 3ceb3e6 | 2011-05-15 13:43:47 +0300 | [diff] [blame] | 68 | |
Oren Weil | 3ceb3e6 | 2011-05-15 13:43:47 +0300 | [diff] [blame] | 69 | |
Tomas Winkler | 781d0d8 | 2013-01-08 23:07:22 +0200 | [diff] [blame] | 70 | /* check for valid client id */ |
Tomas Winkler | d320832 | 2014-08-24 12:08:55 +0300 | [diff] [blame] | 71 | me_cl = mei_me_cl_by_uuid(dev, &mei_wd_guid); |
| 72 | if (!me_cl) { |
Tomas Winkler | 2bf94cab | 2014-09-29 16:31:42 +0300 | [diff] [blame] | 73 | dev_info(dev->dev, "wd: failed to find the client\n"); |
Alexander Usyskin | 7ca96aa | 2014-02-19 17:35:49 +0200 | [diff] [blame] | 74 | return -ENOTTY; |
Oren Weil | 3ceb3e6 | 2011-05-15 13:43:47 +0300 | [diff] [blame] | 75 | } |
Oren Weil | 617aa39 | 2011-09-07 09:03:07 +0300 | [diff] [blame] | 76 | |
Tomas Winkler | d320832 | 2014-08-24 12:08:55 +0300 | [diff] [blame] | 77 | cl->me_client_id = me_cl->client_id; |
Tomas Winkler | d880f32 | 2014-08-21 14:29:15 +0300 | [diff] [blame] | 78 | cl->cl_uuid = me_cl->props.protocol_name; |
Tomas Winkler | 79563db | 2015-01-11 00:07:16 +0200 | [diff] [blame] | 79 | mei_me_cl_put(me_cl); |
Tomas Winkler | 781d0d8 | 2013-01-08 23:07:22 +0200 | [diff] [blame] | 80 | |
| 81 | ret = mei_cl_link(cl, MEI_WD_HOST_CLIENT_ID); |
| 82 | |
| 83 | if (ret < 0) { |
Tomas Winkler | 2bf94cab | 2014-09-29 16:31:42 +0300 | [diff] [blame] | 84 | dev_info(dev->dev, "wd: failed link client\n"); |
Tomas Winkler | 50f67a0 | 2013-10-21 22:05:39 +0300 | [diff] [blame] | 85 | return ret; |
Tomas Winkler | 781d0d8 | 2013-01-08 23:07:22 +0200 | [diff] [blame] | 86 | } |
| 87 | |
Tomas Winkler | 6409285 | 2014-02-17 15:13:21 +0200 | [diff] [blame] | 88 | ret = mei_cl_connect(cl, NULL); |
Tomas Winkler | 9487eb0 | 2012-04-03 23:34:58 +0300 | [diff] [blame] | 89 | |
Tomas Winkler | 6409285 | 2014-02-17 15:13:21 +0200 | [diff] [blame] | 90 | if (ret) { |
Tomas Winkler | 2bf94cab | 2014-09-29 16:31:42 +0300 | [diff] [blame] | 91 | dev_err(dev->dev, "wd: failed to connect = %d\n", ret); |
Tomas Winkler | 6409285 | 2014-02-17 15:13:21 +0200 | [diff] [blame] | 92 | mei_cl_unlink(cl); |
| 93 | return ret; |
| 94 | } |
| 95 | |
| 96 | ret = mei_watchdog_register(dev); |
| 97 | if (ret) { |
| 98 | mei_cl_disconnect(cl); |
| 99 | mei_cl_unlink(cl); |
| 100 | } |
| 101 | return ret; |
Oren Weil | 3ceb3e6 | 2011-05-15 13:43:47 +0300 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | /** |
| 105 | * mei_wd_send - sends watch dog message to fw. |
| 106 | * |
| 107 | * @dev: the device structure |
| 108 | * |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 109 | * Return: 0 if success, |
Oren Weil | 3ceb3e6 | 2011-05-15 13:43:47 +0300 | [diff] [blame] | 110 | * -EIO when message send fails |
| 111 | * -EINVAL when invalid message is to be sent |
Tomas Winkler | b6d81fd | 2014-02-19 17:35:50 +0200 | [diff] [blame] | 112 | * -ENODEV on flow control failure |
Oren Weil | 3ceb3e6 | 2011-05-15 13:43:47 +0300 | [diff] [blame] | 113 | */ |
| 114 | int mei_wd_send(struct mei_device *dev) |
| 115 | { |
Tomas Winkler | b6d81fd | 2014-02-19 17:35:50 +0200 | [diff] [blame] | 116 | struct mei_cl *cl = &dev->wd_cl; |
Tomas Winkler | e46f187 | 2012-12-25 19:06:10 +0200 | [diff] [blame] | 117 | struct mei_msg_hdr hdr; |
Tomas Winkler | b6d81fd | 2014-02-19 17:35:50 +0200 | [diff] [blame] | 118 | int ret; |
Oren Weil | 3ceb3e6 | 2011-05-15 13:43:47 +0300 | [diff] [blame] | 119 | |
Tomas Winkler | b6d81fd | 2014-02-19 17:35:50 +0200 | [diff] [blame] | 120 | hdr.host_addr = cl->host_client_id; |
| 121 | hdr.me_addr = cl->me_client_id; |
Tomas Winkler | e46f187 | 2012-12-25 19:06:10 +0200 | [diff] [blame] | 122 | hdr.msg_complete = 1; |
| 123 | hdr.reserved = 0; |
Tomas Winkler | 479327f | 2013-12-17 15:56:56 +0200 | [diff] [blame] | 124 | hdr.internal = 0; |
Oren Weil | 3ceb3e6 | 2011-05-15 13:43:47 +0300 | [diff] [blame] | 125 | |
Tomas Winkler | 248ffdf | 2012-08-16 19:39:42 +0300 | [diff] [blame] | 126 | if (!memcmp(dev->wd_data, mei_start_wd_params, MEI_WD_HDR_SIZE)) |
Tomas Winkler | e46f187 | 2012-12-25 19:06:10 +0200 | [diff] [blame] | 127 | hdr.length = MEI_WD_START_MSG_SIZE; |
Tomas Winkler | 248ffdf | 2012-08-16 19:39:42 +0300 | [diff] [blame] | 128 | else if (!memcmp(dev->wd_data, mei_stop_wd_params, MEI_WD_HDR_SIZE)) |
Tomas Winkler | e46f187 | 2012-12-25 19:06:10 +0200 | [diff] [blame] | 129 | hdr.length = MEI_WD_STOP_MSG_SIZE; |
Tomas Winkler | b6d81fd | 2014-02-19 17:35:50 +0200 | [diff] [blame] | 130 | else { |
Tomas Winkler | 2bf94cab | 2014-09-29 16:31:42 +0300 | [diff] [blame] | 131 | dev_err(dev->dev, "wd: invalid message is to be sent, aborting\n"); |
Oren Weil | 3ceb3e6 | 2011-05-15 13:43:47 +0300 | [diff] [blame] | 132 | return -EINVAL; |
Tomas Winkler | b6d81fd | 2014-02-19 17:35:50 +0200 | [diff] [blame] | 133 | } |
Oren Weil | 3ceb3e6 | 2011-05-15 13:43:47 +0300 | [diff] [blame] | 134 | |
Tomas Winkler | b6d81fd | 2014-02-19 17:35:50 +0200 | [diff] [blame] | 135 | ret = mei_write_message(dev, &hdr, dev->wd_data); |
| 136 | if (ret) { |
Tomas Winkler | 2bf94cab | 2014-09-29 16:31:42 +0300 | [diff] [blame] | 137 | dev_err(dev->dev, "wd: write message failed\n"); |
Tomas Winkler | b6d81fd | 2014-02-19 17:35:50 +0200 | [diff] [blame] | 138 | return ret; |
| 139 | } |
| 140 | |
| 141 | ret = mei_cl_flow_ctrl_reduce(cl); |
| 142 | if (ret) { |
Tomas Winkler | 2bf94cab | 2014-09-29 16:31:42 +0300 | [diff] [blame] | 143 | dev_err(dev->dev, "wd: flow_ctrl_reduce failed.\n"); |
Tomas Winkler | b6d81fd | 2014-02-19 17:35:50 +0200 | [diff] [blame] | 144 | return ret; |
| 145 | } |
| 146 | |
| 147 | return 0; |
Oren Weil | 3ceb3e6 | 2011-05-15 13:43:47 +0300 | [diff] [blame] | 148 | } |
| 149 | |
Oren Weil | d8deca3 | 2011-09-07 09:03:17 +0300 | [diff] [blame] | 150 | /** |
| 151 | * mei_wd_stop - sends watchdog stop message to fw. |
| 152 | * |
| 153 | * @dev: the device structure |
Oren Weil | d8deca3 | 2011-09-07 09:03:17 +0300 | [diff] [blame] | 154 | * |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 155 | * Return: 0 if success |
Tomas Winkler | 5877255 | 2014-02-19 17:35:51 +0200 | [diff] [blame] | 156 | * on error: |
| 157 | * -EIO when message send fails |
Oren Weil | d8deca3 | 2011-09-07 09:03:17 +0300 | [diff] [blame] | 158 | * -EINVAL when invalid message is to be sent |
Tomas Winkler | 5877255 | 2014-02-19 17:35:51 +0200 | [diff] [blame] | 159 | * -ETIME on message timeout |
Oren Weil | d8deca3 | 2011-09-07 09:03:17 +0300 | [diff] [blame] | 160 | */ |
Tomas Winkler | c216fde | 2012-08-16 19:39:43 +0300 | [diff] [blame] | 161 | int mei_wd_stop(struct mei_device *dev) |
Oren Weil | 3ceb3e6 | 2011-05-15 13:43:47 +0300 | [diff] [blame] | 162 | { |
Tomas Winkler | f3de9b6 | 2015-03-27 00:27:58 +0200 | [diff] [blame] | 163 | struct mei_cl *cl = &dev->wd_cl; |
Oren Weil | 3ceb3e6 | 2011-05-15 13:43:47 +0300 | [diff] [blame] | 164 | int ret; |
Oren Weil | 3ceb3e6 | 2011-05-15 13:43:47 +0300 | [diff] [blame] | 165 | |
Tomas Winkler | f3de9b6 | 2015-03-27 00:27:58 +0200 | [diff] [blame] | 166 | if (!mei_cl_is_connected(cl) || |
Tomas Winkler | c216fde | 2012-08-16 19:39:43 +0300 | [diff] [blame] | 167 | dev->wd_state != MEI_WD_RUNNING) |
Oren Weil | 3ceb3e6 | 2011-05-15 13:43:47 +0300 | [diff] [blame] | 168 | return 0; |
| 169 | |
Tomas Winkler | 248ffdf | 2012-08-16 19:39:42 +0300 | [diff] [blame] | 170 | memcpy(dev->wd_data, mei_stop_wd_params, MEI_WD_STOP_MSG_SIZE); |
Tomas Winkler | c216fde | 2012-08-16 19:39:43 +0300 | [diff] [blame] | 171 | |
| 172 | dev->wd_state = MEI_WD_STOPPING; |
Oren Weil | 3ceb3e6 | 2011-05-15 13:43:47 +0300 | [diff] [blame] | 173 | |
Tomas Winkler | f3de9b6 | 2015-03-27 00:27:58 +0200 | [diff] [blame] | 174 | ret = mei_cl_flow_ctrl_creds(cl); |
Oren Weil | 3ceb3e6 | 2011-05-15 13:43:47 +0300 | [diff] [blame] | 175 | if (ret < 0) |
Tomas Winkler | 5877255 | 2014-02-19 17:35:51 +0200 | [diff] [blame] | 176 | goto err; |
Oren Weil | 3ceb3e6 | 2011-05-15 13:43:47 +0300 | [diff] [blame] | 177 | |
Tomas Winkler | 6aae48f | 2014-02-19 17:35:47 +0200 | [diff] [blame] | 178 | if (ret && mei_hbuf_acquire(dev)) { |
Tomas Winkler | b6d81fd | 2014-02-19 17:35:50 +0200 | [diff] [blame] | 179 | ret = mei_wd_send(dev); |
| 180 | if (ret) |
Tomas Winkler | 5877255 | 2014-02-19 17:35:51 +0200 | [diff] [blame] | 181 | goto err; |
Tomas Winkler | eb9af0a | 2011-05-25 17:28:22 +0300 | [diff] [blame] | 182 | dev->wd_pending = false; |
Oren Weil | 3ceb3e6 | 2011-05-15 13:43:47 +0300 | [diff] [blame] | 183 | } else { |
Tomas Winkler | eb9af0a | 2011-05-25 17:28:22 +0300 | [diff] [blame] | 184 | dev->wd_pending = true; |
Oren Weil | 3ceb3e6 | 2011-05-15 13:43:47 +0300 | [diff] [blame] | 185 | } |
Tomas Winkler | c216fde | 2012-08-16 19:39:43 +0300 | [diff] [blame] | 186 | |
Oren Weil | 3ceb3e6 | 2011-05-15 13:43:47 +0300 | [diff] [blame] | 187 | mutex_unlock(&dev->device_lock); |
| 188 | |
Tomas Winkler | 5877255 | 2014-02-19 17:35:51 +0200 | [diff] [blame] | 189 | ret = wait_event_timeout(dev->wait_stop_wd, |
| 190 | dev->wd_state == MEI_WD_IDLE, |
| 191 | msecs_to_jiffies(MEI_WD_STOP_TIMEOUT)); |
Oren Weil | 3ceb3e6 | 2011-05-15 13:43:47 +0300 | [diff] [blame] | 192 | mutex_lock(&dev->device_lock); |
Tomas Winkler | 5877255 | 2014-02-19 17:35:51 +0200 | [diff] [blame] | 193 | if (dev->wd_state != MEI_WD_IDLE) { |
| 194 | /* timeout */ |
| 195 | ret = -ETIME; |
Tomas Winkler | 2bf94cab | 2014-09-29 16:31:42 +0300 | [diff] [blame] | 196 | dev_warn(dev->dev, "wd: stop failed to complete ret=%d\n", ret); |
Tomas Winkler | 5877255 | 2014-02-19 17:35:51 +0200 | [diff] [blame] | 197 | goto err; |
Tomas Winkler | a534bb6 | 2011-06-13 16:39:31 +0300 | [diff] [blame] | 198 | } |
Tomas Winkler | 2bf94cab | 2014-09-29 16:31:42 +0300 | [diff] [blame] | 199 | dev_dbg(dev->dev, "wd: stop completed after %u msec\n", |
Tomas Winkler | 5877255 | 2014-02-19 17:35:51 +0200 | [diff] [blame] | 200 | MEI_WD_STOP_TIMEOUT - jiffies_to_msecs(ret)); |
| 201 | return 0; |
| 202 | err: |
Oren Weil | 3ceb3e6 | 2011-05-15 13:43:47 +0300 | [diff] [blame] | 203 | return ret; |
| 204 | } |
| 205 | |
Alexander Usyskin | 3908be6 | 2015-02-10 10:39:35 +0200 | [diff] [blame] | 206 | /** |
Oren Weil | 4a3cafd | 2011-09-07 09:03:10 +0300 | [diff] [blame] | 207 | * mei_wd_ops_start - wd start command from the watchdog core. |
| 208 | * |
Alexander Usyskin | 3908be6 | 2015-02-10 10:39:35 +0200 | [diff] [blame] | 209 | * @wd_dev: watchdog device struct |
Oren Weil | 4a3cafd | 2011-09-07 09:03:10 +0300 | [diff] [blame] | 210 | * |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 211 | * Return: 0 if success, negative errno code for failure |
Oren Weil | 4a3cafd | 2011-09-07 09:03:10 +0300 | [diff] [blame] | 212 | */ |
| 213 | static int mei_wd_ops_start(struct watchdog_device *wd_dev) |
| 214 | { |
Oren Weil | 4a3cafd | 2011-09-07 09:03:10 +0300 | [diff] [blame] | 215 | struct mei_device *dev; |
Tomas Winkler | f3de9b6 | 2015-03-27 00:27:58 +0200 | [diff] [blame] | 216 | struct mei_cl *cl; |
| 217 | int err = -ENODEV; |
Oren Weil | 4a3cafd | 2011-09-07 09:03:10 +0300 | [diff] [blame] | 218 | |
Tomas Winkler | 09649a8 | 2012-08-16 19:39:44 +0300 | [diff] [blame] | 219 | dev = watchdog_get_drvdata(wd_dev); |
Oren Weil | 4a3cafd | 2011-09-07 09:03:10 +0300 | [diff] [blame] | 220 | if (!dev) |
| 221 | return -ENODEV; |
| 222 | |
Tomas Winkler | f3de9b6 | 2015-03-27 00:27:58 +0200 | [diff] [blame] | 223 | cl = &dev->wd_cl; |
| 224 | |
Oren Weil | 4a3cafd | 2011-09-07 09:03:10 +0300 | [diff] [blame] | 225 | mutex_lock(&dev->device_lock); |
| 226 | |
Tomas Winkler | b210d75 | 2012-08-07 00:03:56 +0300 | [diff] [blame] | 227 | if (dev->dev_state != MEI_DEV_ENABLED) { |
Tomas Winkler | 2bf94cab | 2014-09-29 16:31:42 +0300 | [diff] [blame] | 228 | dev_dbg(dev->dev, "wd: dev_state != MEI_DEV_ENABLED dev_state = %s\n", |
Tomas Winkler | b210d75 | 2012-08-07 00:03:56 +0300 | [diff] [blame] | 229 | mei_dev_state_str(dev->dev_state)); |
Oren Weil | 4a3cafd | 2011-09-07 09:03:10 +0300 | [diff] [blame] | 230 | goto end_unlock; |
| 231 | } |
| 232 | |
Tomas Winkler | f3de9b6 | 2015-03-27 00:27:58 +0200 | [diff] [blame] | 233 | if (!mei_cl_is_connected(cl)) { |
| 234 | cl_dbg(dev, cl, "MEI Driver is not connected to Watchdog Client\n"); |
Oren Weil | 4a3cafd | 2011-09-07 09:03:10 +0300 | [diff] [blame] | 235 | goto end_unlock; |
| 236 | } |
| 237 | |
Oren Weil | 55d3385 | 2011-09-07 09:03:12 +0300 | [diff] [blame] | 238 | mei_wd_set_start_timeout(dev, dev->wd_timeout); |
Oren Weil | 4a3cafd | 2011-09-07 09:03:10 +0300 | [diff] [blame] | 239 | |
| 240 | err = 0; |
| 241 | end_unlock: |
| 242 | mutex_unlock(&dev->device_lock); |
| 243 | return err; |
| 244 | } |
| 245 | |
Alexander Usyskin | 3908be6 | 2015-02-10 10:39:35 +0200 | [diff] [blame] | 246 | /** |
Oren Weil | 4a3cafd | 2011-09-07 09:03:10 +0300 | [diff] [blame] | 247 | * mei_wd_ops_stop - wd stop command from the watchdog core. |
| 248 | * |
Alexander Usyskin | 3908be6 | 2015-02-10 10:39:35 +0200 | [diff] [blame] | 249 | * @wd_dev: watchdog device struct |
Oren Weil | 4a3cafd | 2011-09-07 09:03:10 +0300 | [diff] [blame] | 250 | * |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 251 | * Return: 0 if success, negative errno code for failure |
Oren Weil | 4a3cafd | 2011-09-07 09:03:10 +0300 | [diff] [blame] | 252 | */ |
| 253 | static int mei_wd_ops_stop(struct watchdog_device *wd_dev) |
| 254 | { |
| 255 | struct mei_device *dev; |
Oren Weil | 4a3cafd | 2011-09-07 09:03:10 +0300 | [diff] [blame] | 256 | |
Tomas Winkler | 09649a8 | 2012-08-16 19:39:44 +0300 | [diff] [blame] | 257 | dev = watchdog_get_drvdata(wd_dev); |
Oren Weil | 4a3cafd | 2011-09-07 09:03:10 +0300 | [diff] [blame] | 258 | if (!dev) |
| 259 | return -ENODEV; |
| 260 | |
| 261 | mutex_lock(&dev->device_lock); |
Tomas Winkler | c216fde | 2012-08-16 19:39:43 +0300 | [diff] [blame] | 262 | mei_wd_stop(dev); |
Oren Weil | 4a3cafd | 2011-09-07 09:03:10 +0300 | [diff] [blame] | 263 | mutex_unlock(&dev->device_lock); |
| 264 | |
| 265 | return 0; |
| 266 | } |
| 267 | |
Alexander Usyskin | 3908be6 | 2015-02-10 10:39:35 +0200 | [diff] [blame] | 268 | /** |
Oren Weil | 8c4a59a | 2011-09-07 09:03:11 +0300 | [diff] [blame] | 269 | * mei_wd_ops_ping - wd ping command from the watchdog core. |
| 270 | * |
Alexander Usyskin | 3908be6 | 2015-02-10 10:39:35 +0200 | [diff] [blame] | 271 | * @wd_dev: watchdog device struct |
Oren Weil | 8c4a59a | 2011-09-07 09:03:11 +0300 | [diff] [blame] | 272 | * |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 273 | * Return: 0 if success, negative errno code for failure |
Oren Weil | 8c4a59a | 2011-09-07 09:03:11 +0300 | [diff] [blame] | 274 | */ |
| 275 | static int mei_wd_ops_ping(struct watchdog_device *wd_dev) |
| 276 | { |
Oren Weil | 8c4a59a | 2011-09-07 09:03:11 +0300 | [diff] [blame] | 277 | struct mei_device *dev; |
Tomas Winkler | 3d32cf0 | 2014-10-02 13:39:32 +0300 | [diff] [blame] | 278 | struct mei_cl *cl; |
Tomas Winkler | 6aae48f | 2014-02-19 17:35:47 +0200 | [diff] [blame] | 279 | int ret; |
Oren Weil | 8c4a59a | 2011-09-07 09:03:11 +0300 | [diff] [blame] | 280 | |
Tomas Winkler | 09649a8 | 2012-08-16 19:39:44 +0300 | [diff] [blame] | 281 | dev = watchdog_get_drvdata(wd_dev); |
Oren Weil | 8c4a59a | 2011-09-07 09:03:11 +0300 | [diff] [blame] | 282 | if (!dev) |
| 283 | return -ENODEV; |
| 284 | |
Tomas Winkler | 3d32cf0 | 2014-10-02 13:39:32 +0300 | [diff] [blame] | 285 | cl = &dev->wd_cl; |
| 286 | |
Oren Weil | 8c4a59a | 2011-09-07 09:03:11 +0300 | [diff] [blame] | 287 | mutex_lock(&dev->device_lock); |
| 288 | |
Tomas Winkler | f3de9b6 | 2015-03-27 00:27:58 +0200 | [diff] [blame] | 289 | if (!mei_cl_is_connected(cl)) { |
| 290 | cl_err(dev, cl, "wd: not connected.\n"); |
Oren Weil | 8c4a59a | 2011-09-07 09:03:11 +0300 | [diff] [blame] | 291 | ret = -ENODEV; |
| 292 | goto end; |
| 293 | } |
| 294 | |
Tomas Winkler | c216fde | 2012-08-16 19:39:43 +0300 | [diff] [blame] | 295 | dev->wd_state = MEI_WD_RUNNING; |
| 296 | |
Tomas Winkler | 3d32cf0 | 2014-10-02 13:39:32 +0300 | [diff] [blame] | 297 | ret = mei_cl_flow_ctrl_creds(cl); |
Tomas Winkler | 6aae48f | 2014-02-19 17:35:47 +0200 | [diff] [blame] | 298 | if (ret < 0) |
| 299 | goto end; |
Tomas Winkler | 3d32cf0 | 2014-10-02 13:39:32 +0300 | [diff] [blame] | 300 | |
Oren Weil | 8c4a59a | 2011-09-07 09:03:11 +0300 | [diff] [blame] | 301 | /* Check if we can send the ping to HW*/ |
Tomas Winkler | 6aae48f | 2014-02-19 17:35:47 +0200 | [diff] [blame] | 302 | if (ret && mei_hbuf_acquire(dev)) { |
Tomas Winkler | 2bf94cab | 2014-09-29 16:31:42 +0300 | [diff] [blame] | 303 | dev_dbg(dev->dev, "wd: sending ping\n"); |
Oren Weil | 8c4a59a | 2011-09-07 09:03:11 +0300 | [diff] [blame] | 304 | |
Tomas Winkler | b6d81fd | 2014-02-19 17:35:50 +0200 | [diff] [blame] | 305 | ret = mei_wd_send(dev); |
| 306 | if (ret) |
Oren Weil | 8c4a59a | 2011-09-07 09:03:11 +0300 | [diff] [blame] | 307 | goto end; |
Tomas Winkler | b6d81fd | 2014-02-19 17:35:50 +0200 | [diff] [blame] | 308 | dev->wd_pending = false; |
Oren Weil | 8c4a59a | 2011-09-07 09:03:11 +0300 | [diff] [blame] | 309 | } else { |
| 310 | dev->wd_pending = true; |
| 311 | } |
| 312 | |
| 313 | end: |
| 314 | mutex_unlock(&dev->device_lock); |
| 315 | return ret; |
| 316 | } |
| 317 | |
Alexander Usyskin | 3908be6 | 2015-02-10 10:39:35 +0200 | [diff] [blame] | 318 | /** |
Oren Weil | 55d3385 | 2011-09-07 09:03:12 +0300 | [diff] [blame] | 319 | * mei_wd_ops_set_timeout - wd set timeout command from the watchdog core. |
| 320 | * |
Alexander Usyskin | 3908be6 | 2015-02-10 10:39:35 +0200 | [diff] [blame] | 321 | * @wd_dev: watchdog device struct |
| 322 | * @timeout: timeout value to set |
Oren Weil | 55d3385 | 2011-09-07 09:03:12 +0300 | [diff] [blame] | 323 | * |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 324 | * Return: 0 if success, negative errno code for failure |
Oren Weil | 55d3385 | 2011-09-07 09:03:12 +0300 | [diff] [blame] | 325 | */ |
Tomas Winkler | 5f1e54e | 2013-04-13 23:41:25 +0300 | [diff] [blame] | 326 | static int mei_wd_ops_set_timeout(struct watchdog_device *wd_dev, |
| 327 | unsigned int timeout) |
Oren Weil | 55d3385 | 2011-09-07 09:03:12 +0300 | [diff] [blame] | 328 | { |
| 329 | struct mei_device *dev; |
Oren Weil | 55d3385 | 2011-09-07 09:03:12 +0300 | [diff] [blame] | 330 | |
Tomas Winkler | 09649a8 | 2012-08-16 19:39:44 +0300 | [diff] [blame] | 331 | dev = watchdog_get_drvdata(wd_dev); |
Oren Weil | 55d3385 | 2011-09-07 09:03:12 +0300 | [diff] [blame] | 332 | if (!dev) |
| 333 | return -ENODEV; |
| 334 | |
| 335 | /* Check Timeout value */ |
Tomas Winkler | 248ffdf | 2012-08-16 19:39:42 +0300 | [diff] [blame] | 336 | if (timeout < MEI_WD_MIN_TIMEOUT || timeout > MEI_WD_MAX_TIMEOUT) |
Oren Weil | 55d3385 | 2011-09-07 09:03:12 +0300 | [diff] [blame] | 337 | return -EINVAL; |
| 338 | |
| 339 | mutex_lock(&dev->device_lock); |
| 340 | |
| 341 | dev->wd_timeout = timeout; |
Wim Van Sebroeck | 0197c1c | 2012-02-29 20:20:58 +0100 | [diff] [blame] | 342 | wd_dev->timeout = timeout; |
Oren Weil | 55d3385 | 2011-09-07 09:03:12 +0300 | [diff] [blame] | 343 | mei_wd_set_start_timeout(dev, dev->wd_timeout); |
| 344 | |
| 345 | mutex_unlock(&dev->device_lock); |
| 346 | |
| 347 | return 0; |
| 348 | } |
| 349 | |
| 350 | /* |
Oren Weil | 4a3cafd | 2011-09-07 09:03:10 +0300 | [diff] [blame] | 351 | * Watchdog Device structs |
| 352 | */ |
Tomas Winkler | 575c1e4 | 2011-10-23 18:30:39 +0200 | [diff] [blame] | 353 | static const struct watchdog_ops wd_ops = { |
Oren Weil | 4a3cafd | 2011-09-07 09:03:10 +0300 | [diff] [blame] | 354 | .owner = THIS_MODULE, |
| 355 | .start = mei_wd_ops_start, |
| 356 | .stop = mei_wd_ops_stop, |
Oren Weil | 8c4a59a | 2011-09-07 09:03:11 +0300 | [diff] [blame] | 357 | .ping = mei_wd_ops_ping, |
Oren Weil | 55d3385 | 2011-09-07 09:03:12 +0300 | [diff] [blame] | 358 | .set_timeout = mei_wd_ops_set_timeout, |
Oren Weil | 4a3cafd | 2011-09-07 09:03:10 +0300 | [diff] [blame] | 359 | }; |
Tomas Winkler | 575c1e4 | 2011-10-23 18:30:39 +0200 | [diff] [blame] | 360 | static const struct watchdog_info wd_info = { |
Oren Weil | 4a3cafd | 2011-09-07 09:03:10 +0300 | [diff] [blame] | 361 | .identity = INTEL_AMT_WATCHDOG_ID, |
Tomas Winkler | c8df729 | 2012-08-16 19:39:41 +0300 | [diff] [blame] | 362 | .options = WDIOF_KEEPALIVEPING | |
| 363 | WDIOF_SETTIMEOUT | |
| 364 | WDIOF_ALARMONLY, |
Oren Weil | 4a3cafd | 2011-09-07 09:03:10 +0300 | [diff] [blame] | 365 | }; |
| 366 | |
Tomas Winkler | 68d923d | 2012-04-02 20:32:38 +0300 | [diff] [blame] | 367 | static struct watchdog_device amt_wd_dev = { |
Oren Weil | 4a3cafd | 2011-09-07 09:03:10 +0300 | [diff] [blame] | 368 | .info = &wd_info, |
| 369 | .ops = &wd_ops, |
Tomas Winkler | 248ffdf | 2012-08-16 19:39:42 +0300 | [diff] [blame] | 370 | .timeout = MEI_WD_DEFAULT_TIMEOUT, |
| 371 | .min_timeout = MEI_WD_MIN_TIMEOUT, |
| 372 | .max_timeout = MEI_WD_MAX_TIMEOUT, |
Oren Weil | 4a3cafd | 2011-09-07 09:03:10 +0300 | [diff] [blame] | 373 | }; |
| 374 | |
| 375 | |
Tomas Winkler | 6409285 | 2014-02-17 15:13:21 +0200 | [diff] [blame] | 376 | int mei_watchdog_register(struct mei_device *dev) |
Tomas Winkler | 70cd533 | 2011-12-22 18:50:50 +0200 | [diff] [blame] | 377 | { |
Tomas Winkler | 6409285 | 2014-02-17 15:13:21 +0200 | [diff] [blame] | 378 | |
| 379 | int ret; |
| 380 | |
| 381 | /* unlock to perserve correct locking order */ |
| 382 | mutex_unlock(&dev->device_lock); |
| 383 | ret = watchdog_register_device(&amt_wd_dev); |
| 384 | mutex_lock(&dev->device_lock); |
| 385 | if (ret) { |
Tomas Winkler | 2bf94cab | 2014-09-29 16:31:42 +0300 | [diff] [blame] | 386 | dev_err(dev->dev, "wd: unable to register watchdog device = %d.\n", |
Tomas Winkler | 6409285 | 2014-02-17 15:13:21 +0200 | [diff] [blame] | 387 | ret); |
| 388 | return ret; |
Tomas Winkler | 70cd533 | 2011-12-22 18:50:50 +0200 | [diff] [blame] | 389 | } |
Tomas Winkler | 09649a8 | 2012-08-16 19:39:44 +0300 | [diff] [blame] | 390 | |
Tomas Winkler | 2bf94cab | 2014-09-29 16:31:42 +0300 | [diff] [blame] | 391 | dev_dbg(dev->dev, "wd: successfully register watchdog interface.\n"); |
Tomas Winkler | 09649a8 | 2012-08-16 19:39:44 +0300 | [diff] [blame] | 392 | watchdog_set_drvdata(&amt_wd_dev, dev); |
Tomas Winkler | 6409285 | 2014-02-17 15:13:21 +0200 | [diff] [blame] | 393 | return 0; |
Tomas Winkler | 70cd533 | 2011-12-22 18:50:50 +0200 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | void mei_watchdog_unregister(struct mei_device *dev) |
| 397 | { |
Tomas Winkler | d692170 | 2012-12-16 13:23:17 +0200 | [diff] [blame] | 398 | if (watchdog_get_drvdata(&amt_wd_dev) == NULL) |
Tomas Winkler | 09649a8 | 2012-08-16 19:39:44 +0300 | [diff] [blame] | 399 | return; |
| 400 | |
| 401 | watchdog_set_drvdata(&amt_wd_dev, NULL); |
| 402 | watchdog_unregister_device(&amt_wd_dev); |
Tomas Winkler | 70cd533 | 2011-12-22 18:50:50 +0200 | [diff] [blame] | 403 | } |
| 404 | |