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