Oren Weil | ab84116 | 2011-05-15 13:43:41 +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 | ab84116 | 2011-05-15 13:43:41 +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 | #ifndef _MEI_DEV_H_ |
| 18 | #define _MEI_DEV_H_ |
| 19 | |
| 20 | #include <linux/types.h> |
Alexander Usyskin | fdd9b86 | 2016-01-08 00:49:21 +0200 | [diff] [blame] | 21 | #include <linux/cdev.h> |
Tomas Winkler | 744f0f2 | 2012-11-11 17:38:02 +0200 | [diff] [blame] | 22 | #include <linux/poll.h> |
Tomas Winkler | 4f3afe1 | 2012-05-09 16:38:59 +0300 | [diff] [blame] | 23 | #include <linux/mei.h> |
Samuel Ortiz | e535410 | 2013-03-27 17:29:53 +0200 | [diff] [blame] | 24 | #include <linux/mei_cl_bus.h> |
Tomas Winkler | 66ef5ea | 2012-12-25 19:06:02 +0200 | [diff] [blame] | 25 | |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 26 | #include "hw.h" |
Tomas Winkler | 9b0d5ef | 2013-04-18 23:03:48 +0300 | [diff] [blame] | 27 | #include "hbm.h" |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 28 | |
Oren Weil | 9ce178e | 2011-09-07 09:03:09 +0300 | [diff] [blame] | 29 | |
| 30 | /* |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 31 | * AMTHI Client UUID |
| 32 | */ |
Tomas Winkler | 1a1aca4 | 2013-01-08 23:07:21 +0200 | [diff] [blame] | 33 | extern const uuid_le mei_amthif_guid; |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 34 | |
Alexander Usyskin | fdd9b86 | 2016-01-08 00:49:21 +0200 | [diff] [blame] | 35 | #define MEI_RD_MSG_BUF_SIZE (128 * sizeof(u32)) |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 36 | |
| 37 | /* |
Tomas Winkler | 1e2776c | 2012-08-24 00:35:58 +0300 | [diff] [blame] | 38 | * Number of Maximum MEI Clients |
| 39 | */ |
| 40 | #define MEI_CLIENTS_MAX 256 |
| 41 | |
| 42 | /* |
Tomas Winkler | 6adb8ef | 2014-01-12 00:36:10 +0200 | [diff] [blame] | 43 | * maximum number of consecutive resets |
| 44 | */ |
| 45 | #define MEI_MAX_CONSEC_RESET 3 |
| 46 | |
| 47 | /* |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 48 | * Number of File descriptors/handles |
| 49 | * that can be opened to the driver. |
| 50 | * |
Tomas Winkler | 781d0d8 | 2013-01-08 23:07:22 +0200 | [diff] [blame] | 51 | * Limit to 255: 256 Total Clients |
Alexander Usyskin | 83ce074 | 2014-01-08 22:31:46 +0200 | [diff] [blame] | 52 | * minus internal client for MEI Bus Messages |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 53 | */ |
Tomas Winkler | 781d0d8 | 2013-01-08 23:07:22 +0200 | [diff] [blame] | 54 | #define MEI_MAX_OPEN_HANDLE_COUNT (MEI_CLIENTS_MAX - 1) |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 55 | |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 56 | /* File state */ |
| 57 | enum file_state { |
| 58 | MEI_FILE_INITIALIZING = 0, |
| 59 | MEI_FILE_CONNECTING, |
| 60 | MEI_FILE_CONNECTED, |
| 61 | MEI_FILE_DISCONNECTING, |
Tomas Winkler | 3c66618 | 2015-05-04 09:43:52 +0300 | [diff] [blame] | 62 | MEI_FILE_DISCONNECT_REPLY, |
Alexander Usyskin | 18901357 | 2015-07-23 21:37:13 +0300 | [diff] [blame] | 63 | MEI_FILE_DISCONNECT_REQUIRED, |
Tomas Winkler | 3c66618 | 2015-05-04 09:43:52 +0300 | [diff] [blame] | 64 | MEI_FILE_DISCONNECTED, |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | /* MEI device states */ |
Tomas Winkler | b210d75 | 2012-08-07 00:03:56 +0300 | [diff] [blame] | 68 | enum mei_dev_state { |
| 69 | MEI_DEV_INITIALIZING = 0, |
| 70 | MEI_DEV_INIT_CLIENTS, |
| 71 | MEI_DEV_ENABLED, |
Bill Nottingham | 0cfee51 | 2013-04-19 22:01:36 +0300 | [diff] [blame] | 72 | MEI_DEV_RESETTING, |
Tomas Winkler | b210d75 | 2012-08-07 00:03:56 +0300 | [diff] [blame] | 73 | MEI_DEV_DISABLED, |
Tomas Winkler | b210d75 | 2012-08-07 00:03:56 +0300 | [diff] [blame] | 74 | MEI_DEV_POWER_DOWN, |
| 75 | MEI_DEV_POWER_UP |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 76 | }; |
| 77 | |
Tomas Winkler | b210d75 | 2012-08-07 00:03:56 +0300 | [diff] [blame] | 78 | const char *mei_dev_state_str(int state); |
| 79 | |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 80 | enum iamthif_states { |
| 81 | MEI_IAMTHIF_IDLE, |
| 82 | MEI_IAMTHIF_WRITING, |
| 83 | MEI_IAMTHIF_FLOW_CONTROL, |
| 84 | MEI_IAMTHIF_READING, |
| 85 | MEI_IAMTHIF_READ_COMPLETE |
| 86 | }; |
| 87 | |
| 88 | enum mei_file_transaction_states { |
| 89 | MEI_IDLE, |
| 90 | MEI_WRITING, |
| 91 | MEI_WRITE_COMPLETE, |
| 92 | MEI_FLOW_CONTROL, |
| 93 | MEI_READING, |
| 94 | MEI_READ_COMPLETE |
| 95 | }; |
| 96 | |
Tomas Winkler | 4b8960b | 2012-11-11 17:38:00 +0200 | [diff] [blame] | 97 | /** |
| 98 | * enum mei_cb_file_ops - file operation associated with the callback |
Alexander Usyskin | ce23139 | 2014-09-29 16:31:50 +0300 | [diff] [blame] | 99 | * @MEI_FOP_READ: read |
| 100 | * @MEI_FOP_WRITE: write |
| 101 | * @MEI_FOP_CONNECT: connect |
| 102 | * @MEI_FOP_DISCONNECT: disconnect |
| 103 | * @MEI_FOP_DISCONNECT_RSP: disconnect response |
Tomas Winkler | 965ae37 | 2015-07-26 09:54:16 +0300 | [diff] [blame] | 104 | * @MEI_FOP_NOTIFY_START: start notification |
| 105 | * @MEI_FOP_NOTIFY_STOP: stop notification |
Tomas Winkler | 4b8960b | 2012-11-11 17:38:00 +0200 | [diff] [blame] | 106 | */ |
| 107 | enum mei_cb_file_ops { |
| 108 | MEI_FOP_READ = 0, |
| 109 | MEI_FOP_WRITE, |
Tomas Winkler | 02a7eec | 2014-02-12 21:41:51 +0200 | [diff] [blame] | 110 | MEI_FOP_CONNECT, |
Tomas Winkler | 5a8373f | 2014-08-21 14:29:17 +0300 | [diff] [blame] | 111 | MEI_FOP_DISCONNECT, |
Tomas Winkler | 6bb948c | 2014-02-12 21:41:52 +0200 | [diff] [blame] | 112 | MEI_FOP_DISCONNECT_RSP, |
Tomas Winkler | 965ae37 | 2015-07-26 09:54:16 +0300 | [diff] [blame] | 113 | MEI_FOP_NOTIFY_START, |
| 114 | MEI_FOP_NOTIFY_STOP, |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 115 | }; |
| 116 | |
| 117 | /* |
| 118 | * Intel MEI message data struct |
| 119 | */ |
Tomas Winkler | 4234a6d | 2013-04-08 21:56:37 +0300 | [diff] [blame] | 120 | struct mei_msg_data { |
Tomas Winkler | f862b6b | 2016-02-07 23:35:19 +0200 | [diff] [blame] | 121 | size_t size; |
Tomas Winkler | edf1eed | 2012-02-09 19:25:54 +0200 | [diff] [blame] | 122 | unsigned char *data; |
Tomas Winkler | f060939 | 2012-09-11 00:43:21 +0300 | [diff] [blame] | 123 | }; |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 124 | |
Alexander Usyskin | 04dd366 | 2014-03-31 17:59:23 +0300 | [diff] [blame] | 125 | /* Maximum number of processed FW status registers */ |
Alexander Usyskin | edca5ea | 2014-11-19 17:01:38 +0200 | [diff] [blame] | 126 | #define MEI_FW_STATUS_MAX 6 |
| 127 | /* Minimal buffer for FW status string (8 bytes in dw + space or '\0') */ |
| 128 | #define MEI_FW_STATUS_STR_SZ (MEI_FW_STATUS_MAX * (8 + 1)) |
| 129 | |
Alexander Usyskin | 04dd366 | 2014-03-31 17:59:23 +0300 | [diff] [blame] | 130 | |
| 131 | /* |
| 132 | * struct mei_fw_status - storage of FW status data |
| 133 | * |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 134 | * @count: number of actually available elements in array |
| 135 | * @status: FW status registers |
Alexander Usyskin | 04dd366 | 2014-03-31 17:59:23 +0300 | [diff] [blame] | 136 | */ |
| 137 | struct mei_fw_status { |
| 138 | int count; |
| 139 | u32 status[MEI_FW_STATUS_MAX]; |
| 140 | }; |
| 141 | |
Tomas Winkler | db7da79 | 2012-12-25 19:06:05 +0200 | [diff] [blame] | 142 | /** |
| 143 | * struct mei_me_client - representation of me (fw) client |
| 144 | * |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 145 | * @list: link in me client list |
Tomas Winkler | 79563db | 2015-01-11 00:07:16 +0200 | [diff] [blame] | 146 | * @refcnt: struct reference count |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 147 | * @props: client properties |
| 148 | * @client_id: me client id |
| 149 | * @mei_flow_ctrl_creds: flow control credits |
Alexander Usyskin | a03d77f | 2015-05-04 09:43:55 +0300 | [diff] [blame] | 150 | * @connect_count: number connections to this client |
Tomas Winkler | 0ff0a8d | 2015-07-23 15:08:42 +0300 | [diff] [blame] | 151 | * @bus_added: added to bus |
Tomas Winkler | db7da79 | 2012-12-25 19:06:05 +0200 | [diff] [blame] | 152 | */ |
| 153 | struct mei_me_client { |
Tomas Winkler | 5ca2d38 | 2014-08-21 14:29:13 +0300 | [diff] [blame] | 154 | struct list_head list; |
Tomas Winkler | 79563db | 2015-01-11 00:07:16 +0200 | [diff] [blame] | 155 | struct kref refcnt; |
Tomas Winkler | db7da79 | 2012-12-25 19:06:05 +0200 | [diff] [blame] | 156 | struct mei_client_properties props; |
| 157 | u8 client_id; |
| 158 | u8 mei_flow_ctrl_creds; |
Alexander Usyskin | a03d77f | 2015-05-04 09:43:55 +0300 | [diff] [blame] | 159 | u8 connect_count; |
Tomas Winkler | 0ff0a8d | 2015-07-23 15:08:42 +0300 | [diff] [blame] | 160 | u8 bus_added; |
Tomas Winkler | db7da79 | 2012-12-25 19:06:05 +0200 | [diff] [blame] | 161 | }; |
| 162 | |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 163 | |
Tomas Winkler | db3ed43 | 2012-11-11 17:37:59 +0200 | [diff] [blame] | 164 | struct mei_cl; |
| 165 | |
Tomas Winkler | 4b8960b | 2012-11-11 17:38:00 +0200 | [diff] [blame] | 166 | /** |
Tomas Winkler | db3ed43 | 2012-11-11 17:37:59 +0200 | [diff] [blame] | 167 | * struct mei_cl_cb - file operation callback structure |
| 168 | * |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 169 | * @list: link in callback queue |
| 170 | * @cl: file client who is running this operation |
| 171 | * @fop_type: file operation type |
Tomas Winkler | 5db7514 | 2015-02-10 10:39:42 +0200 | [diff] [blame] | 172 | * @buf: buffer for data associated with the callback |
Alexander Usyskin | ce23139 | 2014-09-29 16:31:50 +0300 | [diff] [blame] | 173 | * @buf_idx: last read index |
Tomas Winkler | 62e8e6a | 2016-02-07 23:35:24 +0200 | [diff] [blame] | 174 | * @fp: pointer to file structure |
Tomas Winkler | 3d33ff2 | 2015-02-10 10:39:36 +0200 | [diff] [blame] | 175 | * @status: io status of the cb |
Alexander Usyskin | ce23139 | 2014-09-29 16:31:50 +0300 | [diff] [blame] | 176 | * @internal: communication between driver and FW flag |
Tomas Winkler | 8660172 | 2015-02-10 10:39:40 +0200 | [diff] [blame] | 177 | * @completed: the transfer or reception has completed |
Tomas Winkler | db3ed43 | 2012-11-11 17:37:59 +0200 | [diff] [blame] | 178 | */ |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 179 | struct mei_cl_cb { |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 180 | struct list_head list; |
Tomas Winkler | db3ed43 | 2012-11-11 17:37:59 +0200 | [diff] [blame] | 181 | struct mei_cl *cl; |
Tomas Winkler | 4b8960b | 2012-11-11 17:38:00 +0200 | [diff] [blame] | 182 | enum mei_cb_file_ops fop_type; |
Tomas Winkler | 5db7514 | 2015-02-10 10:39:42 +0200 | [diff] [blame] | 183 | struct mei_msg_data buf; |
Tomas Winkler | f862b6b | 2016-02-07 23:35:19 +0200 | [diff] [blame] | 184 | size_t buf_idx; |
Tomas Winkler | 62e8e6a | 2016-02-07 23:35:24 +0200 | [diff] [blame] | 185 | const struct file *fp; |
Tomas Winkler | 3d33ff2 | 2015-02-10 10:39:36 +0200 | [diff] [blame] | 186 | int status; |
Tomas Winkler | 479327f | 2013-12-17 15:56:56 +0200 | [diff] [blame] | 187 | u32 internal:1; |
Tomas Winkler | 8660172 | 2015-02-10 10:39:40 +0200 | [diff] [blame] | 188 | u32 completed:1; |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 189 | }; |
| 190 | |
Alexander Usyskin | ce23139 | 2014-09-29 16:31:50 +0300 | [diff] [blame] | 191 | /** |
| 192 | * struct mei_cl - me client host representation |
| 193 | * carried in file->private_data |
| 194 | * |
| 195 | * @link: link in the clients list |
| 196 | * @dev: mei parent device |
| 197 | * @state: file operation state |
| 198 | * @tx_wait: wait queue for tx completion |
| 199 | * @rx_wait: wait queue for rx completion |
| 200 | * @wait: wait queue for management operation |
Tomas Winkler | b38a362 | 2015-07-26 09:54:19 +0300 | [diff] [blame] | 201 | * @ev_wait: notification wait queue |
Tomas Winkler | 237092b | 2015-07-26 09:54:22 +0300 | [diff] [blame] | 202 | * @ev_async: event async notification |
Alexander Usyskin | ce23139 | 2014-09-29 16:31:50 +0300 | [diff] [blame] | 203 | * @status: connection status |
Alexander Usyskin | d49ed64 | 2015-05-04 09:43:54 +0300 | [diff] [blame] | 204 | * @me_cl: fw client connected |
Alexander Usyskin | ce23139 | 2014-09-29 16:31:50 +0300 | [diff] [blame] | 205 | * @host_client_id: host id |
Alexander Usyskin | ce23139 | 2014-09-29 16:31:50 +0300 | [diff] [blame] | 206 | * @mei_flow_ctrl_creds: transmit flow credentials |
| 207 | * @timer_count: watchdog timer for operation completion |
Alexander Usyskin | d49ed64 | 2015-05-04 09:43:54 +0300 | [diff] [blame] | 208 | * @reserved: reserved for alignment |
Tomas Winkler | 965ae37 | 2015-07-26 09:54:16 +0300 | [diff] [blame] | 209 | * @notify_en: notification - enabled/disabled |
| 210 | * @notify_ev: pending notification event |
Alexander Usyskin | ce23139 | 2014-09-29 16:31:50 +0300 | [diff] [blame] | 211 | * @writing_state: state of the tx |
Tomas Winkler | a9bed61 | 2015-02-10 10:39:46 +0200 | [diff] [blame] | 212 | * @rd_pending: pending read credits |
| 213 | * @rd_completed: completed read |
Alexander Usyskin | ce23139 | 2014-09-29 16:31:50 +0300 | [diff] [blame] | 214 | * |
Tomas Winkler | b37719c3 | 2015-07-23 15:08:33 +0300 | [diff] [blame] | 215 | * @cldev: device on the mei client bus |
Alexander Usyskin | ce23139 | 2014-09-29 16:31:50 +0300 | [diff] [blame] | 216 | */ |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 217 | struct mei_cl { |
| 218 | struct list_head link; |
| 219 | struct mei_device *dev; |
| 220 | enum file_state state; |
| 221 | wait_queue_head_t tx_wait; |
| 222 | wait_queue_head_t rx_wait; |
| 223 | wait_queue_head_t wait; |
Tomas Winkler | b38a362 | 2015-07-26 09:54:19 +0300 | [diff] [blame] | 224 | wait_queue_head_t ev_wait; |
Tomas Winkler | 237092b | 2015-07-26 09:54:22 +0300 | [diff] [blame] | 225 | struct fasync_struct *ev_async; |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 226 | int status; |
Alexander Usyskin | d49ed64 | 2015-05-04 09:43:54 +0300 | [diff] [blame] | 227 | struct mei_me_client *me_cl; |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 228 | u8 host_client_id; |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 229 | u8 mei_flow_ctrl_creds; |
| 230 | u8 timer_count; |
Alexander Usyskin | d49ed64 | 2015-05-04 09:43:54 +0300 | [diff] [blame] | 231 | u8 reserved; |
Tomas Winkler | 965ae37 | 2015-07-26 09:54:16 +0300 | [diff] [blame] | 232 | u8 notify_en; |
| 233 | u8 notify_ev; |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 234 | enum mei_file_transaction_states writing_state; |
Tomas Winkler | a9bed61 | 2015-02-10 10:39:46 +0200 | [diff] [blame] | 235 | struct list_head rd_pending; |
| 236 | struct list_head rd_completed; |
Samuel Ortiz | a7b71bc | 2013-03-27 17:29:56 +0200 | [diff] [blame] | 237 | |
Tomas Winkler | b37719c3 | 2015-07-23 15:08:33 +0300 | [diff] [blame] | 238 | struct mei_cl_device *cldev; |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 239 | }; |
| 240 | |
Alexander Usyskin | 99c2658 | 2015-10-13 15:02:39 +0300 | [diff] [blame] | 241 | /** |
| 242 | * struct mei_hw_ops - hw specific ops |
Tomas Winkler | 827eef5 | 2013-02-06 14:06:41 +0200 | [diff] [blame] | 243 | * |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 244 | * @host_is_ready : query for host readiness |
Alexander Usyskin | 99c2658 | 2015-10-13 15:02:39 +0300 | [diff] [blame] | 245 | * |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 246 | * @hw_is_ready : query if hw is ready |
| 247 | * @hw_reset : reset hw |
| 248 | * @hw_start : start hw after reset |
| 249 | * @hw_config : configure hw |
Alexander Usyskin | 99c2658 | 2015-10-13 15:02:39 +0300 | [diff] [blame] | 250 | * |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 251 | * @fw_status : get fw status registers |
| 252 | * @pg_state : power gating state of the device |
Alexander Usyskin | 3dc196e | 2015-06-13 08:51:17 +0300 | [diff] [blame] | 253 | * @pg_in_transition : is device now in pg transition |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 254 | * @pg_is_enabled : is power gating enabled |
Alexander Usyskin | 99c2658 | 2015-10-13 15:02:39 +0300 | [diff] [blame] | 255 | * |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 256 | * @intr_clear : clear pending interrupts |
| 257 | * @intr_enable : enable interrupts |
| 258 | * @intr_disable : disable interrupts |
Alexander Usyskin | 99c2658 | 2015-10-13 15:02:39 +0300 | [diff] [blame] | 259 | * |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 260 | * @hbuf_free_slots : query for write buffer empty slots |
| 261 | * @hbuf_is_ready : query if write buffer is empty |
| 262 | * @hbuf_max_len : query for write buffer max len |
Alexander Usyskin | 99c2658 | 2015-10-13 15:02:39 +0300 | [diff] [blame] | 263 | * |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 264 | * @write : write a message to FW |
Alexander Usyskin | 99c2658 | 2015-10-13 15:02:39 +0300 | [diff] [blame] | 265 | * |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 266 | * @rdbuf_full_slots : query how many slots are filled |
Alexander Usyskin | 99c2658 | 2015-10-13 15:02:39 +0300 | [diff] [blame] | 267 | * |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 268 | * @read_hdr : get first 4 bytes (header) |
| 269 | * @read : read a buffer from the FW |
Tomas Winkler | 827eef5 | 2013-02-06 14:06:41 +0200 | [diff] [blame] | 270 | */ |
| 271 | struct mei_hw_ops { |
| 272 | |
Tomas Winkler | d63b309 | 2014-03-16 14:35:54 +0200 | [diff] [blame] | 273 | bool (*host_is_ready)(struct mei_device *dev); |
Tomas Winkler | 827eef5 | 2013-02-06 14:06:41 +0200 | [diff] [blame] | 274 | |
Tomas Winkler | d63b309 | 2014-03-16 14:35:54 +0200 | [diff] [blame] | 275 | bool (*hw_is_ready)(struct mei_device *dev); |
| 276 | int (*hw_reset)(struct mei_device *dev, bool enable); |
| 277 | int (*hw_start)(struct mei_device *dev); |
| 278 | void (*hw_config)(struct mei_device *dev); |
Tomas Winkler | 827eef5 | 2013-02-06 14:06:41 +0200 | [diff] [blame] | 279 | |
Tomas Winkler | 1bd30b6 | 2014-09-29 16:31:43 +0300 | [diff] [blame] | 280 | |
| 281 | int (*fw_status)(struct mei_device *dev, struct mei_fw_status *fw_sts); |
Tomas Winkler | 964a233 | 2014-03-18 22:51:59 +0200 | [diff] [blame] | 282 | enum mei_pg_state (*pg_state)(struct mei_device *dev); |
Alexander Usyskin | 3dc196e | 2015-06-13 08:51:17 +0300 | [diff] [blame] | 283 | bool (*pg_in_transition)(struct mei_device *dev); |
Tomas Winkler | ee7e5af | 2014-03-18 22:51:58 +0200 | [diff] [blame] | 284 | bool (*pg_is_enabled)(struct mei_device *dev); |
| 285 | |
Tomas Winkler | d63b309 | 2014-03-16 14:35:54 +0200 | [diff] [blame] | 286 | void (*intr_clear)(struct mei_device *dev); |
| 287 | void (*intr_enable)(struct mei_device *dev); |
| 288 | void (*intr_disable)(struct mei_device *dev); |
Tomas Winkler | 827eef5 | 2013-02-06 14:06:41 +0200 | [diff] [blame] | 289 | |
Tomas Winkler | d63b309 | 2014-03-16 14:35:54 +0200 | [diff] [blame] | 290 | int (*hbuf_free_slots)(struct mei_device *dev); |
| 291 | bool (*hbuf_is_ready)(struct mei_device *dev); |
| 292 | size_t (*hbuf_max_len)(const struct mei_device *dev); |
Tomas Winkler | 827eef5 | 2013-02-06 14:06:41 +0200 | [diff] [blame] | 293 | |
| 294 | int (*write)(struct mei_device *dev, |
| 295 | struct mei_msg_hdr *hdr, |
| 296 | unsigned char *buf); |
| 297 | |
| 298 | int (*rdbuf_full_slots)(struct mei_device *dev); |
| 299 | |
| 300 | u32 (*read_hdr)(const struct mei_device *dev); |
Tomas Winkler | d63b309 | 2014-03-16 14:35:54 +0200 | [diff] [blame] | 301 | int (*read)(struct mei_device *dev, |
Tomas Winkler | 827eef5 | 2013-02-06 14:06:41 +0200 | [diff] [blame] | 302 | unsigned char *buf, unsigned long len); |
| 303 | }; |
| 304 | |
Samuel Ortiz | e535410 | 2013-03-27 17:29:53 +0200 | [diff] [blame] | 305 | /* MEI bus API*/ |
Tomas Winkler | 6009595 | 2015-07-23 15:08:47 +0300 | [diff] [blame] | 306 | void mei_cl_bus_rescan(struct mei_device *bus); |
Alexander Usyskin | a816a00 | 2016-02-07 23:35:41 +0200 | [diff] [blame] | 307 | void mei_cl_bus_rescan_work(struct work_struct *work); |
Tomas Winkler | ae48d74 | 2015-09-10 10:18:06 +0300 | [diff] [blame] | 308 | void mei_cl_bus_dev_fixup(struct mei_cl_device *dev); |
Tomas Winkler | be9b720 | 2015-05-07 15:54:04 +0300 | [diff] [blame] | 309 | ssize_t __mei_cl_send(struct mei_cl *cl, u8 *buf, size_t length, |
| 310 | bool blocking); |
Tomas Winkler | 39db74c | 2014-11-27 14:07:28 +0200 | [diff] [blame] | 311 | ssize_t __mei_cl_recv(struct mei_cl *cl, u8 *buf, size_t length); |
Tomas Winkler | a1f9ae2 | 2016-02-07 23:35:30 +0200 | [diff] [blame] | 312 | bool mei_cl_bus_rx_event(struct mei_cl *cl); |
Tomas Winkler | 850f894 | 2016-02-07 23:35:31 +0200 | [diff] [blame] | 313 | bool mei_cl_bus_notify_event(struct mei_cl *cl); |
Tomas Winkler | b37719c3 | 2015-07-23 15:08:33 +0300 | [diff] [blame] | 314 | void mei_cl_bus_remove_devices(struct mei_device *bus); |
Samuel Ortiz | cf3baef | 2013-03-27 17:29:57 +0200 | [diff] [blame] | 315 | int mei_cl_bus_init(void); |
| 316 | void mei_cl_bus_exit(void); |
| 317 | |
Alexander Usyskin | ce23139 | 2014-09-29 16:31:50 +0300 | [diff] [blame] | 318 | /** |
Tomas Winkler | 964a233 | 2014-03-18 22:51:59 +0200 | [diff] [blame] | 319 | * enum mei_pg_event - power gating transition events |
| 320 | * |
| 321 | * @MEI_PG_EVENT_IDLE: the driver is not in power gating transition |
| 322 | * @MEI_PG_EVENT_WAIT: the driver is waiting for a pg event to complete |
| 323 | * @MEI_PG_EVENT_RECEIVED: the driver received pg event |
Alexander Usyskin | 3dc196e | 2015-06-13 08:51:17 +0300 | [diff] [blame] | 324 | * @MEI_PG_EVENT_INTR_WAIT: the driver is waiting for a pg event interrupt |
| 325 | * @MEI_PG_EVENT_INTR_RECEIVED: the driver received pg event interrupt |
Tomas Winkler | 964a233 | 2014-03-18 22:51:59 +0200 | [diff] [blame] | 326 | */ |
| 327 | enum mei_pg_event { |
| 328 | MEI_PG_EVENT_IDLE, |
| 329 | MEI_PG_EVENT_WAIT, |
| 330 | MEI_PG_EVENT_RECEIVED, |
Alexander Usyskin | 3dc196e | 2015-06-13 08:51:17 +0300 | [diff] [blame] | 331 | MEI_PG_EVENT_INTR_WAIT, |
| 332 | MEI_PG_EVENT_INTR_RECEIVED, |
Tomas Winkler | 964a233 | 2014-03-18 22:51:59 +0200 | [diff] [blame] | 333 | }; |
| 334 | |
| 335 | /** |
| 336 | * enum mei_pg_state - device internal power gating state |
| 337 | * |
| 338 | * @MEI_PG_OFF: device is not power gated - it is active |
| 339 | * @MEI_PG_ON: device is power gated - it is in lower power state |
| 340 | */ |
| 341 | enum mei_pg_state { |
| 342 | MEI_PG_OFF = 0, |
| 343 | MEI_PG_ON = 1, |
| 344 | }; |
| 345 | |
Alexander Usyskin | 1beeb4b | 2014-09-29 16:31:33 +0300 | [diff] [blame] | 346 | const char *mei_pg_state_str(enum mei_pg_state state); |
| 347 | |
Tomas Winkler | 24aadc8 | 2012-06-25 23:46:27 +0300 | [diff] [blame] | 348 | /** |
Tomas Winkler | 5fb54fb | 2012-11-18 15:13:15 +0200 | [diff] [blame] | 349 | * struct mei_device - MEI private device struct |
Alexander Usyskin | ce23139 | 2014-09-29 16:31:50 +0300 | [diff] [blame] | 350 | * |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 351 | * @dev : device on a bus |
| 352 | * @cdev : character device |
| 353 | * @minor : minor number allocated for device |
Alexander Usyskin | f3d8e87 | 2014-06-23 15:10:35 +0300 | [diff] [blame] | 354 | * |
Alexander Usyskin | ce23139 | 2014-09-29 16:31:50 +0300 | [diff] [blame] | 355 | * @write_list : write pending list |
| 356 | * @write_waiting_list : write completion list |
| 357 | * @ctrl_wr_list : pending control write list |
| 358 | * @ctrl_rd_list : pending control read list |
Tomas Winkler | bae1cc7 | 2014-08-21 14:29:21 +0300 | [diff] [blame] | 359 | * |
Alexander Usyskin | ce23139 | 2014-09-29 16:31:50 +0300 | [diff] [blame] | 360 | * @file_list : list of opened handles |
| 361 | * @open_handle_count: number of opened handles |
| 362 | * |
| 363 | * @device_lock : big device lock |
| 364 | * @timer_work : MEI timer delayed work (timeouts) |
| 365 | * |
| 366 | * @recvd_hw_ready : hw ready message received flag |
| 367 | * |
| 368 | * @wait_hw_ready : wait queue for receive HW ready message form FW |
| 369 | * @wait_pg : wait queue for receive PG message from FW |
| 370 | * @wait_hbm_start : wait queue for receive HBM start message from FW |
Alexander Usyskin | ce23139 | 2014-09-29 16:31:50 +0300 | [diff] [blame] | 371 | * |
| 372 | * @reset_count : number of consecutive resets |
| 373 | * @dev_state : device state |
| 374 | * @hbm_state : state of host bus message protocol |
| 375 | * @init_clients_timer : HBM init handshake timeout |
Tomas Winkler | bae1cc7 | 2014-08-21 14:29:21 +0300 | [diff] [blame] | 376 | * |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 377 | * @pg_event : power gating event |
Alexander Usyskin | ce23139 | 2014-09-29 16:31:50 +0300 | [diff] [blame] | 378 | * @pg_domain : runtime PM domain |
| 379 | * |
| 380 | * @rd_msg_buf : control messages buffer |
| 381 | * @rd_msg_hdr : read message header storage |
| 382 | * |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 383 | * @hbuf_depth : depth of hardware host/write buffer is slots |
| 384 | * @hbuf_is_ready : query if the host host/write buffer is ready |
Alexander Usyskin | ce23139 | 2014-09-29 16:31:50 +0300 | [diff] [blame] | 385 | * |
| 386 | * @version : HBM protocol version in use |
Alexander Usyskin | 18901357 | 2015-07-23 21:37:13 +0300 | [diff] [blame] | 387 | * @hbm_f_pg_supported : hbm feature pgi protocol |
| 388 | * @hbm_f_dc_supported : hbm feature dynamic clients |
| 389 | * @hbm_f_dot_supported : hbm feature disconnect on timeout |
Tomas Winkler | 4d99877 | 2015-07-26 09:54:17 +0300 | [diff] [blame] | 390 | * @hbm_f_ev_supported : hbm feature event notification |
Alexander Usyskin | f4e0624 | 2016-02-07 23:35:38 +0200 | [diff] [blame] | 391 | * @hbm_f_fa_supported : hbm feature fixed address client |
Alexander Usyskin | 27f476e | 2016-02-07 23:35:42 +0200 | [diff] [blame] | 392 | * @hbm_f_ie_supported : hbm feature immediate reply to enum request |
Alexander Usyskin | ce23139 | 2014-09-29 16:31:50 +0300 | [diff] [blame] | 393 | * |
Tomas Winkler | b7d8851 | 2015-02-10 10:39:31 +0200 | [diff] [blame] | 394 | * @me_clients_rwsem: rw lock over me_clients list |
Alexander Usyskin | ce23139 | 2014-09-29 16:31:50 +0300 | [diff] [blame] | 395 | * @me_clients : list of FW clients |
| 396 | * @me_clients_map : FW clients bit map |
| 397 | * @host_clients_map : host clients id pool |
Alexander Usyskin | ce23139 | 2014-09-29 16:31:50 +0300 | [diff] [blame] | 398 | * |
Alexander Usyskin | eeabfcf | 2015-05-04 09:43:57 +0300 | [diff] [blame] | 399 | * @allow_fixed_address: allow user space to connect a fixed client |
Alexander Usyskin | f4e0624 | 2016-02-07 23:35:38 +0200 | [diff] [blame] | 400 | * @override_fixed_address: force allow fixed address behavior |
Alexander Usyskin | eeabfcf | 2015-05-04 09:43:57 +0300 | [diff] [blame] | 401 | * |
Alexander Usyskin | ce23139 | 2014-09-29 16:31:50 +0300 | [diff] [blame] | 402 | * @amthif_cmd_list : amthif list for cmd waiting |
Tomas Winkler | 62e8e6a | 2016-02-07 23:35:24 +0200 | [diff] [blame] | 403 | * @iamthif_fp : file for current amthif operation |
Alexander Usyskin | ce23139 | 2014-09-29 16:31:50 +0300 | [diff] [blame] | 404 | * @iamthif_cl : amthif host client |
| 405 | * @iamthif_current_cb : amthif current operation callback |
| 406 | * @iamthif_open_count : number of opened amthif connections |
Alexander Usyskin | ce23139 | 2014-09-29 16:31:50 +0300 | [diff] [blame] | 407 | * @iamthif_stall_timer : timer to detect amthif hang |
Alexander Usyskin | ce23139 | 2014-09-29 16:31:50 +0300 | [diff] [blame] | 408 | * @iamthif_state : amthif processor state |
Alexander Usyskin | ce23139 | 2014-09-29 16:31:50 +0300 | [diff] [blame] | 409 | * @iamthif_canceled : current amthif command is canceled |
| 410 | * |
Alexander Usyskin | ce23139 | 2014-09-29 16:31:50 +0300 | [diff] [blame] | 411 | * @reset_work : work item for the device reset |
Alexander Usyskin | a816a00 | 2016-02-07 23:35:41 +0200 | [diff] [blame] | 412 | * @bus_rescan_work : work item for the bus rescan |
Alexander Usyskin | ce23139 | 2014-09-29 16:31:50 +0300 | [diff] [blame] | 413 | * |
| 414 | * @device_list : mei client bus list |
Tomas Winkler | 0ff0a8d | 2015-07-23 15:08:42 +0300 | [diff] [blame] | 415 | * @cl_bus_lock : client bus list lock |
Alexander Usyskin | ce23139 | 2014-09-29 16:31:50 +0300 | [diff] [blame] | 416 | * |
| 417 | * @dbgfs_dir : debugfs mei root directory |
| 418 | * |
| 419 | * @ops: : hw specific operations |
| 420 | * @hw : hw specific data |
Tomas Winkler | 24aadc8 | 2012-06-25 23:46:27 +0300 | [diff] [blame] | 421 | */ |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 422 | struct mei_device { |
Tomas Winkler | 3a7e9b6 | 2014-09-29 16:31:41 +0300 | [diff] [blame] | 423 | struct device *dev; |
Alexander Usyskin | f3d8e87 | 2014-06-23 15:10:35 +0300 | [diff] [blame] | 424 | struct cdev cdev; |
| 425 | int minor; |
| 426 | |
Alexander Usyskin | ce23139 | 2014-09-29 16:31:50 +0300 | [diff] [blame] | 427 | struct mei_cl_cb write_list; |
| 428 | struct mei_cl_cb write_waiting_list; |
| 429 | struct mei_cl_cb ctrl_wr_list; |
| 430 | struct mei_cl_cb ctrl_rd_list; |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 431 | |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 432 | struct list_head file_list; |
Tomas Winkler | eb9af0a | 2011-05-25 17:28:22 +0300 | [diff] [blame] | 433 | long open_handle_count; |
Tomas Winkler | fecb0d5 | 2012-12-25 19:06:04 +0200 | [diff] [blame] | 434 | |
Alexander Usyskin | ce23139 | 2014-09-29 16:31:50 +0300 | [diff] [blame] | 435 | struct mutex device_lock; |
| 436 | struct delayed_work timer_work; |
Tomas Winkler | aafae7e | 2013-03-11 18:27:03 +0200 | [diff] [blame] | 437 | |
| 438 | bool recvd_hw_ready; |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 439 | /* |
| 440 | * waiting queue for receive message from FW |
| 441 | */ |
Tomas Winkler | aafae7e | 2013-03-11 18:27:03 +0200 | [diff] [blame] | 442 | wait_queue_head_t wait_hw_ready; |
Tomas Winkler | 4fcbc99 | 2014-03-18 22:51:55 +0200 | [diff] [blame] | 443 | wait_queue_head_t wait_pg; |
Alexander Usyskin | cb02efc | 2014-08-21 14:29:19 +0300 | [diff] [blame] | 444 | wait_queue_head_t wait_hbm_start; |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 445 | |
| 446 | /* |
| 447 | * mei device states |
| 448 | */ |
Tomas Winkler | 6adb8ef | 2014-01-12 00:36:10 +0200 | [diff] [blame] | 449 | unsigned long reset_count; |
Tomas Winkler | b210d75 | 2012-08-07 00:03:56 +0300 | [diff] [blame] | 450 | enum mei_dev_state dev_state; |
Tomas Winkler | 9b0d5ef | 2013-04-18 23:03:48 +0300 | [diff] [blame] | 451 | enum mei_hbm_state hbm_state; |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 452 | u16 init_clients_timer; |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 453 | |
Tomas Winkler | 964a233 | 2014-03-18 22:51:59 +0200 | [diff] [blame] | 454 | /* |
| 455 | * Power Gating support |
| 456 | */ |
| 457 | enum mei_pg_event pg_event; |
Rafael J. Wysocki | bbd6d05 | 2014-12-04 22:43:07 +0100 | [diff] [blame] | 458 | #ifdef CONFIG_PM |
Tomas Winkler | e13fa90 | 2014-03-18 22:52:05 +0200 | [diff] [blame] | 459 | struct dev_pm_domain pg_domain; |
Rafael J. Wysocki | bbd6d05 | 2014-12-04 22:43:07 +0100 | [diff] [blame] | 460 | #endif /* CONFIG_PM */ |
Tomas Winkler | 964a233 | 2014-03-18 22:51:59 +0200 | [diff] [blame] | 461 | |
Alexander Usyskin | ce23139 | 2014-09-29 16:31:50 +0300 | [diff] [blame] | 462 | unsigned char rd_msg_buf[MEI_RD_MSG_BUF_SIZE]; |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 463 | u32 rd_msg_hdr; |
Tomas Winkler | e46f187 | 2012-12-25 19:06:10 +0200 | [diff] [blame] | 464 | |
Tomas Winkler | 330dd7d | 2013-02-06 14:06:43 +0200 | [diff] [blame] | 465 | /* write buffer */ |
| 466 | u8 hbuf_depth; |
| 467 | bool hbuf_is_ready; |
| 468 | |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 469 | struct hbm_version version; |
Tomas Winkler | bae1cc7 | 2014-08-21 14:29:21 +0300 | [diff] [blame] | 470 | unsigned int hbm_f_pg_supported:1; |
Tomas Winkler | 70ef835 | 2015-07-23 21:37:12 +0300 | [diff] [blame] | 471 | unsigned int hbm_f_dc_supported:1; |
Alexander Usyskin | 18901357 | 2015-07-23 21:37:13 +0300 | [diff] [blame] | 472 | unsigned int hbm_f_dot_supported:1; |
Tomas Winkler | 4d99877 | 2015-07-26 09:54:17 +0300 | [diff] [blame] | 473 | unsigned int hbm_f_ev_supported:1; |
Alexander Usyskin | f4e0624 | 2016-02-07 23:35:38 +0200 | [diff] [blame] | 474 | unsigned int hbm_f_fa_supported:1; |
Alexander Usyskin | 27f476e | 2016-02-07 23:35:42 +0200 | [diff] [blame] | 475 | unsigned int hbm_f_ie_supported:1; |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 476 | |
Tomas Winkler | b7d8851 | 2015-02-10 10:39:31 +0200 | [diff] [blame] | 477 | struct rw_semaphore me_clients_rwsem; |
Tomas Winkler | 5ca2d38 | 2014-08-21 14:29:13 +0300 | [diff] [blame] | 478 | struct list_head me_clients; |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 479 | DECLARE_BITMAP(me_clients_map, MEI_CLIENTS_MAX); |
| 480 | DECLARE_BITMAP(host_clients_map, MEI_CLIENTS_MAX); |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 481 | |
Viresh Kumar | 621a5f7 | 2015-09-26 15:04:07 -0700 | [diff] [blame] | 482 | bool allow_fixed_address; |
Alexander Usyskin | f4e0624 | 2016-02-07 23:35:38 +0200 | [diff] [blame] | 483 | bool override_fixed_address; |
Alexander Usyskin | eeabfcf | 2015-05-04 09:43:57 +0300 | [diff] [blame] | 484 | |
Tomas Winkler | e773efc | 2012-11-11 17:37:58 +0200 | [diff] [blame] | 485 | /* amthif list for cmd waiting */ |
| 486 | struct mei_cl_cb amthif_cmd_list; |
| 487 | /* driver managed amthif list for reading completed amthif cmd data */ |
Tomas Winkler | 62e8e6a | 2016-02-07 23:35:24 +0200 | [diff] [blame] | 488 | const struct file *iamthif_fp; |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 489 | struct mei_cl iamthif_cl; |
Tomas Winkler | eb9af0a | 2011-05-25 17:28:22 +0300 | [diff] [blame] | 490 | struct mei_cl_cb *iamthif_current_cb; |
Tomas Winkler | 22f96a0 | 2013-09-16 23:44:47 +0300 | [diff] [blame] | 491 | long iamthif_open_count; |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 492 | u32 iamthif_stall_timer; |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 493 | enum iamthif_states iamthif_state; |
Tomas Winkler | eb9af0a | 2011-05-25 17:28:22 +0300 | [diff] [blame] | 494 | bool iamthif_canceled; |
Samuel Ortiz | c1174c0 | 2012-11-18 15:13:20 +0200 | [diff] [blame] | 495 | |
Tomas Winkler | 544f946 | 2014-01-08 20:19:21 +0200 | [diff] [blame] | 496 | struct work_struct reset_work; |
Alexander Usyskin | a816a00 | 2016-02-07 23:35:41 +0200 | [diff] [blame] | 497 | struct work_struct bus_rescan_work; |
Tomas Winkler | 827eef5 | 2013-02-06 14:06:41 +0200 | [diff] [blame] | 498 | |
Samuel Ortiz | a7b71bc | 2013-03-27 17:29:56 +0200 | [diff] [blame] | 499 | /* List of bus devices */ |
| 500 | struct list_head device_list; |
Tomas Winkler | 0ff0a8d | 2015-07-23 15:08:42 +0300 | [diff] [blame] | 501 | struct mutex cl_bus_lock; |
Samuel Ortiz | a7b71bc | 2013-03-27 17:29:56 +0200 | [diff] [blame] | 502 | |
Tomas Winkler | 30e53bb | 2013-04-05 22:10:34 +0300 | [diff] [blame] | 503 | #if IS_ENABLED(CONFIG_DEBUG_FS) |
| 504 | struct dentry *dbgfs_dir; |
| 505 | #endif /* CONFIG_DEBUG_FS */ |
| 506 | |
| 507 | |
Tomas Winkler | 827eef5 | 2013-02-06 14:06:41 +0200 | [diff] [blame] | 508 | const struct mei_hw_ops *ops; |
Tomas Winkler | 52c3456 | 2013-02-06 14:06:40 +0200 | [diff] [blame] | 509 | char hw[0] __aligned(sizeof(void *)); |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 510 | }; |
| 511 | |
Tomas Winkler | 3870c32 | 2012-11-01 21:17:14 +0200 | [diff] [blame] | 512 | static inline unsigned long mei_secs_to_jiffies(unsigned long sec) |
| 513 | { |
| 514 | return msecs_to_jiffies(sec * MSEC_PER_SEC); |
| 515 | } |
| 516 | |
Tomas Winkler | c8c8d08 | 2013-03-11 18:27:02 +0200 | [diff] [blame] | 517 | /** |
| 518 | * mei_data2slots - get slots - number of (dwords) from a message length |
| 519 | * + size of the mei header |
Alexander Usyskin | ce23139 | 2014-09-29 16:31:50 +0300 | [diff] [blame] | 520 | * |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 521 | * @length: size of the messages in bytes |
| 522 | * |
| 523 | * Return: number of slots |
Tomas Winkler | c8c8d08 | 2013-03-11 18:27:02 +0200 | [diff] [blame] | 524 | */ |
| 525 | static inline u32 mei_data2slots(size_t length) |
| 526 | { |
| 527 | return DIV_ROUND_UP(sizeof(struct mei_msg_hdr) + length, 4); |
| 528 | } |
| 529 | |
Tomas Winkler | 10ee907 | 2013-11-11 13:26:08 +0200 | [diff] [blame] | 530 | /** |
Alexander Usyskin | ce23139 | 2014-09-29 16:31:50 +0300 | [diff] [blame] | 531 | * mei_slots2data - get data in slots - bytes from slots |
| 532 | * |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 533 | * @slots: number of available slots |
Alexander Usyskin | ce23139 | 2014-09-29 16:31:50 +0300 | [diff] [blame] | 534 | * |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 535 | * Return: number of bytes in slots |
Tomas Winkler | 10ee907 | 2013-11-11 13:26:08 +0200 | [diff] [blame] | 536 | */ |
| 537 | static inline u32 mei_slots2data(int slots) |
| 538 | { |
| 539 | return slots * 4; |
| 540 | } |
| 541 | |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 542 | /* |
| 543 | * mei init function prototypes |
| 544 | */ |
Tomas Winkler | 3a7e9b6 | 2014-09-29 16:31:41 +0300 | [diff] [blame] | 545 | void mei_device_init(struct mei_device *dev, |
| 546 | struct device *device, |
| 547 | const struct mei_hw_ops *hw_ops); |
Tomas Winkler | 33ec082 | 2014-01-12 00:36:09 +0200 | [diff] [blame] | 548 | int mei_reset(struct mei_device *dev); |
Tomas Winkler | c4d589b | 2013-03-27 16:58:28 +0200 | [diff] [blame] | 549 | int mei_start(struct mei_device *dev); |
Tomas Winkler | 33ec082 | 2014-01-12 00:36:09 +0200 | [diff] [blame] | 550 | int mei_restart(struct mei_device *dev); |
Tomas Winkler | 7cb035d | 2013-03-10 13:56:08 +0200 | [diff] [blame] | 551 | void mei_stop(struct mei_device *dev); |
Tomas Winkler | dc844b0 | 2013-11-11 13:26:06 +0200 | [diff] [blame] | 552 | void mei_cancel_work(struct mei_device *dev); |
Tomas Winkler | c95efb7 | 2011-05-25 17:28:21 +0300 | [diff] [blame] | 553 | |
Tomas Winkler | c95efb7 | 2011-05-25 17:28:21 +0300 | [diff] [blame] | 554 | /* |
| 555 | * MEI interrupt functions prototype |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 556 | */ |
Tomas Winkler | 06ecd64 | 2013-02-06 14:06:42 +0200 | [diff] [blame] | 557 | |
Oren Weil | a61c653 | 2011-09-07 09:03:13 +0300 | [diff] [blame] | 558 | void mei_timer(struct work_struct *work); |
Tomas Winkler | 06ecd64 | 2013-02-06 14:06:42 +0200 | [diff] [blame] | 559 | int mei_irq_read_handler(struct mei_device *dev, |
| 560 | struct mei_cl_cb *cmpl_list, s32 *slots); |
| 561 | |
| 562 | int mei_irq_write_handler(struct mei_device *dev, struct mei_cl_cb *cmpl_list); |
Tomas Winkler | 4c6e22b | 2013-03-17 11:41:20 +0200 | [diff] [blame] | 563 | void mei_irq_compl_handler(struct mei_device *dev, struct mei_cl_cb *cmpl_list); |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 564 | |
| 565 | /* |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 566 | * AMTHIF - AMT Host Interface Functions |
| 567 | */ |
| 568 | void mei_amthif_reset_params(struct mei_device *dev); |
| 569 | |
Alexander Usyskin | d49ed64 | 2015-05-04 09:43:54 +0300 | [diff] [blame] | 570 | 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] | 571 | |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 572 | int mei_amthif_read(struct mei_device *dev, struct file *file, |
Tomas Winkler | 744f0f2 | 2012-11-11 17:38:02 +0200 | [diff] [blame] | 573 | char __user *ubuf, size_t length, loff_t *offset); |
| 574 | |
| 575 | unsigned int mei_amthif_poll(struct mei_device *dev, |
| 576 | struct file *file, poll_table *wait); |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 577 | |
Tomas Winkler | a562d5c | 2012-11-11 17:38:01 +0200 | [diff] [blame] | 578 | int mei_amthif_release(struct mei_device *dev, struct file *file); |
| 579 | |
Tomas Winkler | 8660172 | 2015-02-10 10:39:40 +0200 | [diff] [blame] | 580 | int mei_amthif_write(struct mei_cl *cl, struct mei_cl_cb *cb); |
| 581 | int mei_amthif_run_next_cmd(struct mei_device *dev); |
Tomas Winkler | 9d09819 | 2014-02-19 17:35:48 +0200 | [diff] [blame] | 582 | int mei_amthif_irq_write(struct mei_cl *cl, struct mei_cl_cb *cb, |
| 583 | struct mei_cl_cb *cmpl_list); |
Tomas Winkler | 5ceb46e | 2013-04-19 21:16:53 +0300 | [diff] [blame] | 584 | |
Tomas Winkler | 9abd8b3 | 2016-02-07 23:35:26 +0200 | [diff] [blame] | 585 | void mei_amthif_complete(struct mei_cl *cl, struct mei_cl_cb *cb); |
Tomas Winkler | db4756f | 2015-02-10 10:39:37 +0200 | [diff] [blame] | 586 | int mei_amthif_irq_read_msg(struct mei_cl *cl, |
Tomas Winkler | 5ceb46e | 2013-04-19 21:16:53 +0300 | [diff] [blame] | 587 | struct mei_msg_hdr *mei_hdr, |
| 588 | struct mei_cl_cb *complete_list); |
| 589 | int mei_amthif_irq_read(struct mei_device *dev, s32 *slots); |
| 590 | |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 591 | /* |
| 592 | * Register Access Function |
| 593 | */ |
| 594 | |
Alexander Usyskin | 8d929d4 | 2014-05-13 01:30:53 +0300 | [diff] [blame] | 595 | |
Tomas Winkler | 827eef5 | 2013-02-06 14:06:41 +0200 | [diff] [blame] | 596 | static inline void mei_hw_config(struct mei_device *dev) |
| 597 | { |
| 598 | dev->ops->hw_config(dev); |
| 599 | } |
Tomas Winkler | ee7e5af | 2014-03-18 22:51:58 +0200 | [diff] [blame] | 600 | |
Tomas Winkler | 964a233 | 2014-03-18 22:51:59 +0200 | [diff] [blame] | 601 | static inline enum mei_pg_state mei_pg_state(struct mei_device *dev) |
| 602 | { |
| 603 | return dev->ops->pg_state(dev); |
| 604 | } |
| 605 | |
Alexander Usyskin | 3dc196e | 2015-06-13 08:51:17 +0300 | [diff] [blame] | 606 | static inline bool mei_pg_in_transition(struct mei_device *dev) |
| 607 | { |
| 608 | return dev->ops->pg_in_transition(dev); |
| 609 | } |
| 610 | |
Tomas Winkler | ee7e5af | 2014-03-18 22:51:58 +0200 | [diff] [blame] | 611 | static inline bool mei_pg_is_enabled(struct mei_device *dev) |
| 612 | { |
| 613 | return dev->ops->pg_is_enabled(dev); |
| 614 | } |
| 615 | |
Tomas Winkler | c20c68d | 2013-06-23 10:42:49 +0300 | [diff] [blame] | 616 | static inline int mei_hw_reset(struct mei_device *dev, bool enable) |
Tomas Winkler | 827eef5 | 2013-02-06 14:06:41 +0200 | [diff] [blame] | 617 | { |
Tomas Winkler | c20c68d | 2013-06-23 10:42:49 +0300 | [diff] [blame] | 618 | return dev->ops->hw_reset(dev, enable); |
Tomas Winkler | 827eef5 | 2013-02-06 14:06:41 +0200 | [diff] [blame] | 619 | } |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 620 | |
Tomas Winkler | 9049f79 | 2013-06-23 22:49:04 +0300 | [diff] [blame] | 621 | static inline int mei_hw_start(struct mei_device *dev) |
Tomas Winkler | aafae7e | 2013-03-11 18:27:03 +0200 | [diff] [blame] | 622 | { |
Tomas Winkler | 9049f79 | 2013-06-23 22:49:04 +0300 | [diff] [blame] | 623 | return dev->ops->hw_start(dev); |
Tomas Winkler | aafae7e | 2013-03-11 18:27:03 +0200 | [diff] [blame] | 624 | } |
| 625 | |
Tomas Winkler | 827eef5 | 2013-02-06 14:06:41 +0200 | [diff] [blame] | 626 | static inline void mei_clear_interrupts(struct mei_device *dev) |
| 627 | { |
| 628 | dev->ops->intr_clear(dev); |
| 629 | } |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 630 | |
Tomas Winkler | 827eef5 | 2013-02-06 14:06:41 +0200 | [diff] [blame] | 631 | static inline void mei_enable_interrupts(struct mei_device *dev) |
| 632 | { |
| 633 | dev->ops->intr_enable(dev); |
| 634 | } |
Tomas Winkler | e7e0c23 | 2013-01-08 23:07:31 +0200 | [diff] [blame] | 635 | |
Tomas Winkler | 827eef5 | 2013-02-06 14:06:41 +0200 | [diff] [blame] | 636 | static inline void mei_disable_interrupts(struct mei_device *dev) |
| 637 | { |
| 638 | dev->ops->intr_disable(dev); |
| 639 | } |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 640 | |
Tomas Winkler | 827eef5 | 2013-02-06 14:06:41 +0200 | [diff] [blame] | 641 | static inline bool mei_host_is_ready(struct mei_device *dev) |
| 642 | { |
| 643 | return dev->ops->host_is_ready(dev); |
| 644 | } |
| 645 | static inline bool mei_hw_is_ready(struct mei_device *dev) |
| 646 | { |
| 647 | return dev->ops->hw_is_ready(dev); |
| 648 | } |
Tomas Winkler | 115ba28 | 2013-01-08 23:07:29 +0200 | [diff] [blame] | 649 | |
Tomas Winkler | 827eef5 | 2013-02-06 14:06:41 +0200 | [diff] [blame] | 650 | static inline bool mei_hbuf_is_ready(struct mei_device *dev) |
| 651 | { |
| 652 | return dev->ops->hbuf_is_ready(dev); |
| 653 | } |
Tomas Winkler | 3a65dd4 | 2012-12-25 19:06:06 +0200 | [diff] [blame] | 654 | |
Tomas Winkler | 827eef5 | 2013-02-06 14:06:41 +0200 | [diff] [blame] | 655 | static inline int mei_hbuf_empty_slots(struct mei_device *dev) |
| 656 | { |
| 657 | return dev->ops->hbuf_free_slots(dev); |
| 658 | } |
| 659 | |
| 660 | static inline size_t mei_hbuf_max_len(const struct mei_device *dev) |
| 661 | { |
| 662 | return dev->ops->hbuf_max_len(dev); |
| 663 | } |
| 664 | |
| 665 | static inline int mei_write_message(struct mei_device *dev, |
Alexander Usyskin | c0ff901 | 2016-05-09 00:07:47 -0400 | [diff] [blame] | 666 | struct mei_msg_hdr *hdr, void *buf) |
Tomas Winkler | 827eef5 | 2013-02-06 14:06:41 +0200 | [diff] [blame] | 667 | { |
| 668 | return dev->ops->write(dev, hdr, buf); |
| 669 | } |
| 670 | |
| 671 | static inline u32 mei_read_hdr(const struct mei_device *dev) |
| 672 | { |
| 673 | return dev->ops->read_hdr(dev); |
| 674 | } |
| 675 | |
| 676 | static inline void mei_read_slots(struct mei_device *dev, |
| 677 | unsigned char *buf, unsigned long len) |
| 678 | { |
| 679 | dev->ops->read(dev, buf, len); |
| 680 | } |
| 681 | |
| 682 | static inline int mei_count_full_read_slots(struct mei_device *dev) |
| 683 | { |
| 684 | return dev->ops->rdbuf_full_slots(dev); |
| 685 | } |
Tomas Winkler | 5bd6471 | 2012-11-18 15:13:14 +0200 | [diff] [blame] | 686 | |
Tomas Winkler | 1bd30b6 | 2014-09-29 16:31:43 +0300 | [diff] [blame] | 687 | static inline int mei_fw_status(struct mei_device *dev, |
| 688 | struct mei_fw_status *fw_status) |
| 689 | { |
| 690 | return dev->ops->fw_status(dev, fw_status); |
| 691 | } |
Alexander Usyskin | 04dd366 | 2014-03-31 17:59:23 +0300 | [diff] [blame] | 692 | |
Tomas Winkler | 6aae48f | 2014-02-19 17:35:47 +0200 | [diff] [blame] | 693 | bool mei_hbuf_acquire(struct mei_device *dev); |
| 694 | |
Tomas Winkler | a532bbe | 2014-03-18 22:52:01 +0200 | [diff] [blame] | 695 | bool mei_write_is_idle(struct mei_device *dev); |
| 696 | |
Alexander Usyskin | 9d04ee1 | 2016-04-17 12:16:04 -0400 | [diff] [blame] | 697 | void mei_irq_discard_msg(struct mei_device *dev, struct mei_msg_hdr *hdr); |
| 698 | |
Tomas Winkler | 30e53bb | 2013-04-05 22:10:34 +0300 | [diff] [blame] | 699 | #if IS_ENABLED(CONFIG_DEBUG_FS) |
| 700 | int mei_dbgfs_register(struct mei_device *dev, const char *name); |
| 701 | void mei_dbgfs_deregister(struct mei_device *dev); |
| 702 | #else |
| 703 | static inline int mei_dbgfs_register(struct mei_device *dev, const char *name) |
| 704 | { |
| 705 | return 0; |
| 706 | } |
| 707 | static inline void mei_dbgfs_deregister(struct mei_device *dev) {} |
| 708 | #endif /* CONFIG_DEBUG_FS */ |
| 709 | |
Alexander Usyskin | f3d8e87 | 2014-06-23 15:10:35 +0300 | [diff] [blame] | 710 | int mei_register(struct mei_device *dev, struct device *parent); |
Tomas Winkler | 30e53bb | 2013-04-05 22:10:34 +0300 | [diff] [blame] | 711 | void mei_deregister(struct mei_device *dev); |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 712 | |
Tomas Winkler | 479327f | 2013-12-17 15:56:56 +0200 | [diff] [blame] | 713 | #define MEI_HDR_FMT "hdr:host=%02d me=%02d len=%d internal=%1d comp=%1d" |
Tomas Winkler | 15d4acc | 2012-12-25 19:06:00 +0200 | [diff] [blame] | 714 | #define MEI_HDR_PRM(hdr) \ |
| 715 | (hdr)->host_addr, (hdr)->me_addr, \ |
Tomas Winkler | 479327f | 2013-12-17 15:56:56 +0200 | [diff] [blame] | 716 | (hdr)->length, (hdr)->internal, (hdr)->msg_complete |
Tomas Winkler | 15d4acc | 2012-12-25 19:06:00 +0200 | [diff] [blame] | 717 | |
Alexander Usyskin | edca5ea | 2014-11-19 17:01:38 +0200 | [diff] [blame] | 718 | ssize_t mei_fw_status2str(struct mei_fw_status *fw_sts, char *buf, size_t len); |
| 719 | /** |
| 720 | * mei_fw_status_str - fetch and convert fw status registers to printable string |
| 721 | * |
| 722 | * @dev: the device structure |
| 723 | * @buf: string buffer at minimal size MEI_FW_STATUS_STR_SZ |
| 724 | * @len: buffer len must be >= MEI_FW_STATUS_STR_SZ |
| 725 | * |
| 726 | * Return: number of bytes written or < 0 on failure |
| 727 | */ |
| 728 | static inline ssize_t mei_fw_status_str(struct mei_device *dev, |
| 729 | char *buf, size_t len) |
| 730 | { |
| 731 | struct mei_fw_status fw_status; |
| 732 | int ret; |
| 733 | |
| 734 | buf[0] = '\0'; |
| 735 | |
| 736 | ret = mei_fw_status(dev, &fw_status); |
| 737 | if (ret) |
| 738 | return ret; |
| 739 | |
| 740 | ret = mei_fw_status2str(&fw_status, buf, MEI_FW_STATUS_STR_SZ); |
| 741 | |
| 742 | return ret; |
| 743 | } |
| 744 | |
| 745 | |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 746 | #endif |