Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +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 | 3ce7272 | 2011-05-15 13:43:43 +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 | #include <linux/pci.h> |
Tomas Winkler | 06ecd64 | 2013-02-06 14:06:42 +0200 | [diff] [blame] | 18 | |
| 19 | #include <linux/kthread.h> |
| 20 | #include <linux/interrupt.h> |
Tomas Winkler | 47a7380 | 2012-12-25 19:06:03 +0200 | [diff] [blame] | 21 | |
| 22 | #include "mei_dev.h" |
Tomas Winkler | 06ecd64 | 2013-02-06 14:06:42 +0200 | [diff] [blame] | 23 | #include "hbm.h" |
| 24 | |
Tomas Winkler | 6e4cd27 | 2014-03-11 14:49:23 +0200 | [diff] [blame] | 25 | #include "hw-me.h" |
| 26 | #include "hw-me-regs.h" |
Tomas Winkler | 06ecd64 | 2013-02-06 14:06:42 +0200 | [diff] [blame] | 27 | |
Tomas Winkler | a0a927d | 2015-02-10 10:39:33 +0200 | [diff] [blame] | 28 | #include "mei-trace.h" |
| 29 | |
Tomas Winkler | 3a65dd4 | 2012-12-25 19:06:06 +0200 | [diff] [blame] | 30 | /** |
Tomas Winkler | b68301e | 2013-03-27 16:58:29 +0200 | [diff] [blame] | 31 | * mei_me_reg_read - Reads 32bit data from the mei device |
Tomas Winkler | 3a65dd4 | 2012-12-25 19:06:06 +0200 | [diff] [blame] | 32 | * |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 33 | * @hw: the me hardware structure |
Tomas Winkler | 3a65dd4 | 2012-12-25 19:06:06 +0200 | [diff] [blame] | 34 | * @offset: offset from which to read the data |
| 35 | * |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 36 | * Return: register value (u32) |
Tomas Winkler | 3a65dd4 | 2012-12-25 19:06:06 +0200 | [diff] [blame] | 37 | */ |
Tomas Winkler | b68301e | 2013-03-27 16:58:29 +0200 | [diff] [blame] | 38 | static inline u32 mei_me_reg_read(const struct mei_me_hw *hw, |
Tomas Winkler | 3a65dd4 | 2012-12-25 19:06:06 +0200 | [diff] [blame] | 39 | unsigned long offset) |
| 40 | { |
Tomas Winkler | 52c3456 | 2013-02-06 14:06:40 +0200 | [diff] [blame] | 41 | return ioread32(hw->mem_addr + offset); |
Tomas Winkler | 3a65dd4 | 2012-12-25 19:06:06 +0200 | [diff] [blame] | 42 | } |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 43 | |
| 44 | |
| 45 | /** |
Tomas Winkler | b68301e | 2013-03-27 16:58:29 +0200 | [diff] [blame] | 46 | * mei_me_reg_write - Writes 32bit data to the mei device |
Tomas Winkler | 3a65dd4 | 2012-12-25 19:06:06 +0200 | [diff] [blame] | 47 | * |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 48 | * @hw: the me hardware structure |
Tomas Winkler | 3a65dd4 | 2012-12-25 19:06:06 +0200 | [diff] [blame] | 49 | * @offset: offset from which to write the data |
| 50 | * @value: register value to write (u32) |
| 51 | */ |
Tomas Winkler | b68301e | 2013-03-27 16:58:29 +0200 | [diff] [blame] | 52 | static inline void mei_me_reg_write(const struct mei_me_hw *hw, |
Tomas Winkler | 3a65dd4 | 2012-12-25 19:06:06 +0200 | [diff] [blame] | 53 | unsigned long offset, u32 value) |
| 54 | { |
Tomas Winkler | 52c3456 | 2013-02-06 14:06:40 +0200 | [diff] [blame] | 55 | iowrite32(value, hw->mem_addr + offset); |
Tomas Winkler | 3a65dd4 | 2012-12-25 19:06:06 +0200 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | /** |
Tomas Winkler | b68301e | 2013-03-27 16:58:29 +0200 | [diff] [blame] | 59 | * mei_me_mecbrw_read - Reads 32bit data from ME circular buffer |
Tomas Winkler | d025284 | 2013-01-08 23:07:24 +0200 | [diff] [blame] | 60 | * read window register |
Tomas Winkler | 3a65dd4 | 2012-12-25 19:06:06 +0200 | [diff] [blame] | 61 | * |
| 62 | * @dev: the device structure |
| 63 | * |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 64 | * Return: ME_CB_RW register value (u32) |
Tomas Winkler | 3a65dd4 | 2012-12-25 19:06:06 +0200 | [diff] [blame] | 65 | */ |
Tomas Winkler | 381a58c | 2015-02-10 10:39:32 +0200 | [diff] [blame] | 66 | static inline u32 mei_me_mecbrw_read(const struct mei_device *dev) |
Tomas Winkler | 3a65dd4 | 2012-12-25 19:06:06 +0200 | [diff] [blame] | 67 | { |
Tomas Winkler | b68301e | 2013-03-27 16:58:29 +0200 | [diff] [blame] | 68 | return mei_me_reg_read(to_me_hw(dev), ME_CB_RW); |
Tomas Winkler | 3a65dd4 | 2012-12-25 19:06:06 +0200 | [diff] [blame] | 69 | } |
Tomas Winkler | 381a58c | 2015-02-10 10:39:32 +0200 | [diff] [blame] | 70 | |
| 71 | /** |
| 72 | * mei_me_hcbww_write - write 32bit data to the host circular buffer |
| 73 | * |
| 74 | * @dev: the device structure |
| 75 | * @data: 32bit data to be written to the host circular buffer |
| 76 | */ |
| 77 | static inline void mei_me_hcbww_write(struct mei_device *dev, u32 data) |
| 78 | { |
| 79 | mei_me_reg_write(to_me_hw(dev), H_CB_WW, data); |
| 80 | } |
| 81 | |
Tomas Winkler | 3a65dd4 | 2012-12-25 19:06:06 +0200 | [diff] [blame] | 82 | /** |
Tomas Winkler | b68301e | 2013-03-27 16:58:29 +0200 | [diff] [blame] | 83 | * mei_me_mecsr_read - Reads 32bit data from the ME CSR |
Tomas Winkler | 3a65dd4 | 2012-12-25 19:06:06 +0200 | [diff] [blame] | 84 | * |
Tomas Winkler | 381a58c | 2015-02-10 10:39:32 +0200 | [diff] [blame] | 85 | * @dev: the device structure |
Tomas Winkler | 3a65dd4 | 2012-12-25 19:06:06 +0200 | [diff] [blame] | 86 | * |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 87 | * Return: ME_CSR_HA register value (u32) |
Tomas Winkler | 3a65dd4 | 2012-12-25 19:06:06 +0200 | [diff] [blame] | 88 | */ |
Tomas Winkler | 381a58c | 2015-02-10 10:39:32 +0200 | [diff] [blame] | 89 | static inline u32 mei_me_mecsr_read(const struct mei_device *dev) |
Tomas Winkler | 3a65dd4 | 2012-12-25 19:06:06 +0200 | [diff] [blame] | 90 | { |
Tomas Winkler | a0a927d | 2015-02-10 10:39:33 +0200 | [diff] [blame] | 91 | u32 reg; |
| 92 | |
| 93 | reg = mei_me_reg_read(to_me_hw(dev), ME_CSR_HA); |
| 94 | trace_mei_reg_read(dev->dev, "ME_CSR_HA", ME_CSR_HA, reg); |
| 95 | |
| 96 | return reg; |
Tomas Winkler | 3a65dd4 | 2012-12-25 19:06:06 +0200 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | /** |
Tomas Winkler | d025284 | 2013-01-08 23:07:24 +0200 | [diff] [blame] | 100 | * mei_hcsr_read - Reads 32bit data from the host CSR |
| 101 | * |
Tomas Winkler | 381a58c | 2015-02-10 10:39:32 +0200 | [diff] [blame] | 102 | * @dev: the device structure |
Tomas Winkler | d025284 | 2013-01-08 23:07:24 +0200 | [diff] [blame] | 103 | * |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 104 | * Return: H_CSR register value (u32) |
Tomas Winkler | d025284 | 2013-01-08 23:07:24 +0200 | [diff] [blame] | 105 | */ |
Tomas Winkler | 381a58c | 2015-02-10 10:39:32 +0200 | [diff] [blame] | 106 | static inline u32 mei_hcsr_read(const struct mei_device *dev) |
Tomas Winkler | d025284 | 2013-01-08 23:07:24 +0200 | [diff] [blame] | 107 | { |
Tomas Winkler | a0a927d | 2015-02-10 10:39:33 +0200 | [diff] [blame] | 108 | u32 reg; |
| 109 | |
| 110 | reg = mei_me_reg_read(to_me_hw(dev), H_CSR); |
| 111 | trace_mei_reg_read(dev->dev, "H_CSR", H_CSR, reg); |
| 112 | |
| 113 | return reg; |
Tomas Winkler | 381a58c | 2015-02-10 10:39:32 +0200 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | /** |
| 117 | * mei_hcsr_write - writes H_CSR register to the mei device |
| 118 | * |
| 119 | * @dev: the device structure |
| 120 | * @reg: new register value |
| 121 | */ |
| 122 | static inline void mei_hcsr_write(struct mei_device *dev, u32 reg) |
| 123 | { |
Tomas Winkler | a0a927d | 2015-02-10 10:39:33 +0200 | [diff] [blame] | 124 | trace_mei_reg_write(dev->dev, "H_CSR", H_CSR, reg); |
Tomas Winkler | 381a58c | 2015-02-10 10:39:32 +0200 | [diff] [blame] | 125 | mei_me_reg_write(to_me_hw(dev), H_CSR, reg); |
Tomas Winkler | d025284 | 2013-01-08 23:07:24 +0200 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | /** |
| 129 | * mei_hcsr_set - writes H_CSR register to the mei device, |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 130 | * and ignores the H_IS bit for it is write-one-to-zero. |
| 131 | * |
Tomas Winkler | 381a58c | 2015-02-10 10:39:32 +0200 | [diff] [blame] | 132 | * @dev: the device structure |
| 133 | * @reg: new register value |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 134 | */ |
Tomas Winkler | 381a58c | 2015-02-10 10:39:32 +0200 | [diff] [blame] | 135 | static inline void mei_hcsr_set(struct mei_device *dev, u32 reg) |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 136 | { |
Alexander Usyskin | 1fa55b4 | 2015-08-02 22:20:52 +0300 | [diff] [blame] | 137 | reg &= ~H_CSR_IS_MASK; |
Tomas Winkler | 381a58c | 2015-02-10 10:39:32 +0200 | [diff] [blame] | 138 | mei_hcsr_write(dev, reg); |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 139 | } |
| 140 | |
Tomas Winkler | 1bd30b6 | 2014-09-29 16:31:43 +0300 | [diff] [blame] | 141 | /** |
Alexander Usyskin | 859ef2f | 2015-08-02 22:20:54 +0300 | [diff] [blame] | 142 | * mei_me_d0i3c_read - Reads 32bit data from the D0I3C register |
| 143 | * |
| 144 | * @dev: the device structure |
| 145 | * |
| 146 | * Return: H_D0I3C register value (u32) |
| 147 | */ |
| 148 | static inline u32 mei_me_d0i3c_read(const struct mei_device *dev) |
| 149 | { |
| 150 | u32 reg; |
| 151 | |
| 152 | reg = mei_me_reg_read(to_me_hw(dev), H_D0I3C); |
Alexander Usyskin | cf094eb | 2015-09-18 00:11:52 +0300 | [diff] [blame] | 153 | trace_mei_reg_read(dev->dev, "H_D0I3C", H_D0I3C, reg); |
Alexander Usyskin | 859ef2f | 2015-08-02 22:20:54 +0300 | [diff] [blame] | 154 | |
| 155 | return reg; |
| 156 | } |
| 157 | |
| 158 | /** |
| 159 | * mei_me_d0i3c_write - writes H_D0I3C register to device |
| 160 | * |
| 161 | * @dev: the device structure |
| 162 | * @reg: new register value |
| 163 | */ |
| 164 | static inline void mei_me_d0i3c_write(struct mei_device *dev, u32 reg) |
| 165 | { |
Alexander Usyskin | cf094eb | 2015-09-18 00:11:52 +0300 | [diff] [blame] | 166 | trace_mei_reg_write(dev->dev, "H_D0I3C", H_D0I3C, reg); |
Alexander Usyskin | 859ef2f | 2015-08-02 22:20:54 +0300 | [diff] [blame] | 167 | mei_me_reg_write(to_me_hw(dev), H_D0I3C, reg); |
| 168 | } |
| 169 | |
| 170 | /** |
Tomas Winkler | 1bd30b6 | 2014-09-29 16:31:43 +0300 | [diff] [blame] | 171 | * mei_me_fw_status - read fw status register from pci config space |
| 172 | * |
| 173 | * @dev: mei device |
| 174 | * @fw_status: fw status register values |
Alexander Usyskin | ce23139 | 2014-09-29 16:31:50 +0300 | [diff] [blame] | 175 | * |
| 176 | * Return: 0 on success, error otherwise |
Tomas Winkler | 1bd30b6 | 2014-09-29 16:31:43 +0300 | [diff] [blame] | 177 | */ |
| 178 | static int mei_me_fw_status(struct mei_device *dev, |
| 179 | struct mei_fw_status *fw_status) |
| 180 | { |
Tomas Winkler | 1bd30b6 | 2014-09-29 16:31:43 +0300 | [diff] [blame] | 181 | struct pci_dev *pdev = to_pci_dev(dev->dev); |
Tomas Winkler | 4ad96db | 2014-09-29 16:31:45 +0300 | [diff] [blame] | 182 | struct mei_me_hw *hw = to_me_hw(dev); |
| 183 | const struct mei_fw_status *fw_src = &hw->cfg->fw_status; |
Tomas Winkler | 1bd30b6 | 2014-09-29 16:31:43 +0300 | [diff] [blame] | 184 | int ret; |
| 185 | int i; |
| 186 | |
| 187 | if (!fw_status) |
| 188 | return -EINVAL; |
| 189 | |
| 190 | fw_status->count = fw_src->count; |
| 191 | for (i = 0; i < fw_src->count && i < MEI_FW_STATUS_MAX; i++) { |
Tomas Winkler | a96c548 | 2016-02-07 22:46:51 +0200 | [diff] [blame] | 192 | ret = pci_read_config_dword(pdev, fw_src->status[i], |
| 193 | &fw_status->status[i]); |
| 194 | trace_mei_pci_cfg_read(dev->dev, "PCI_CFG_HSF_X", |
| 195 | fw_src->status[i], |
| 196 | fw_status->status[i]); |
Tomas Winkler | 1bd30b6 | 2014-09-29 16:31:43 +0300 | [diff] [blame] | 197 | if (ret) |
| 198 | return ret; |
| 199 | } |
| 200 | |
| 201 | return 0; |
| 202 | } |
Tomas Winkler | e7e0c23 | 2013-01-08 23:07:31 +0200 | [diff] [blame] | 203 | |
| 204 | /** |
Masanari Iida | 393b148 | 2013-04-05 01:05:05 +0900 | [diff] [blame] | 205 | * mei_me_hw_config - configure hw dependent settings |
Tomas Winkler | e7e0c23 | 2013-01-08 23:07:31 +0200 | [diff] [blame] | 206 | * |
| 207 | * @dev: mei device |
| 208 | */ |
Tomas Winkler | 827eef5 | 2013-02-06 14:06:41 +0200 | [diff] [blame] | 209 | static void mei_me_hw_config(struct mei_device *dev) |
Tomas Winkler | e7e0c23 | 2013-01-08 23:07:31 +0200 | [diff] [blame] | 210 | { |
Alexander Usyskin | bb9f4d2 | 2015-08-02 22:20:51 +0300 | [diff] [blame] | 211 | struct pci_dev *pdev = to_pci_dev(dev->dev); |
Tomas Winkler | ba9cdd0 | 2014-03-18 22:52:00 +0200 | [diff] [blame] | 212 | struct mei_me_hw *hw = to_me_hw(dev); |
Alexander Usyskin | bb9f4d2 | 2015-08-02 22:20:51 +0300 | [diff] [blame] | 213 | u32 hcsr, reg; |
| 214 | |
Tomas Winkler | e7e0c23 | 2013-01-08 23:07:31 +0200 | [diff] [blame] | 215 | /* Doesn't change in runtime */ |
Alexander Usyskin | bb9f4d2 | 2015-08-02 22:20:51 +0300 | [diff] [blame] | 216 | hcsr = mei_hcsr_read(dev); |
Tomas Winkler | e7e0c23 | 2013-01-08 23:07:31 +0200 | [diff] [blame] | 217 | dev->hbuf_depth = (hcsr & H_CBD) >> 24; |
Tomas Winkler | ba9cdd0 | 2014-03-18 22:52:00 +0200 | [diff] [blame] | 218 | |
Alexander Usyskin | bb9f4d2 | 2015-08-02 22:20:51 +0300 | [diff] [blame] | 219 | reg = 0; |
| 220 | pci_read_config_dword(pdev, PCI_CFG_HFS_1, ®); |
Tomas Winkler | a96c548 | 2016-02-07 22:46:51 +0200 | [diff] [blame] | 221 | trace_mei_pci_cfg_read(dev->dev, "PCI_CFG_HFS_1", PCI_CFG_HFS_1, reg); |
Alexander Usyskin | bb9f4d2 | 2015-08-02 22:20:51 +0300 | [diff] [blame] | 222 | hw->d0i3_supported = |
| 223 | ((reg & PCI_CFG_HFS_1_D0I3_MSK) == PCI_CFG_HFS_1_D0I3_MSK); |
Alexander Usyskin | b9a1fc9 | 2015-08-02 22:20:56 +0300 | [diff] [blame] | 224 | |
| 225 | hw->pg_state = MEI_PG_OFF; |
| 226 | if (hw->d0i3_supported) { |
| 227 | reg = mei_me_d0i3c_read(dev); |
| 228 | if (reg & H_D0I3C_I3) |
| 229 | hw->pg_state = MEI_PG_ON; |
| 230 | } |
Tomas Winkler | e7e0c23 | 2013-01-08 23:07:31 +0200 | [diff] [blame] | 231 | } |
Tomas Winkler | 964a233 | 2014-03-18 22:51:59 +0200 | [diff] [blame] | 232 | |
| 233 | /** |
| 234 | * mei_me_pg_state - translate internal pg state |
| 235 | * to the mei power gating state |
| 236 | * |
Alexander Usyskin | ce23139 | 2014-09-29 16:31:50 +0300 | [diff] [blame] | 237 | * @dev: mei device |
| 238 | * |
| 239 | * Return: MEI_PG_OFF if aliveness is on and MEI_PG_ON otherwise |
Tomas Winkler | 964a233 | 2014-03-18 22:51:59 +0200 | [diff] [blame] | 240 | */ |
| 241 | static inline enum mei_pg_state mei_me_pg_state(struct mei_device *dev) |
| 242 | { |
Tomas Winkler | ba9cdd0 | 2014-03-18 22:52:00 +0200 | [diff] [blame] | 243 | struct mei_me_hw *hw = to_me_hw(dev); |
Tomas Winkler | 92db155 | 2014-09-29 16:31:37 +0300 | [diff] [blame] | 244 | |
Tomas Winkler | ba9cdd0 | 2014-03-18 22:52:00 +0200 | [diff] [blame] | 245 | return hw->pg_state; |
Tomas Winkler | 964a233 | 2014-03-18 22:51:59 +0200 | [diff] [blame] | 246 | } |
| 247 | |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 248 | /** |
Alexander Usyskin | ce23139 | 2014-09-29 16:31:50 +0300 | [diff] [blame] | 249 | * mei_me_intr_clear - clear and stop interrupts |
Tomas Winkler | 3a65dd4 | 2012-12-25 19:06:06 +0200 | [diff] [blame] | 250 | * |
| 251 | * @dev: the device structure |
| 252 | */ |
Tomas Winkler | 827eef5 | 2013-02-06 14:06:41 +0200 | [diff] [blame] | 253 | static void mei_me_intr_clear(struct mei_device *dev) |
Tomas Winkler | 3a65dd4 | 2012-12-25 19:06:06 +0200 | [diff] [blame] | 254 | { |
Tomas Winkler | 381a58c | 2015-02-10 10:39:32 +0200 | [diff] [blame] | 255 | u32 hcsr = mei_hcsr_read(dev); |
Tomas Winkler | 92db155 | 2014-09-29 16:31:37 +0300 | [diff] [blame] | 256 | |
Alexander Usyskin | 1fa55b4 | 2015-08-02 22:20:52 +0300 | [diff] [blame] | 257 | if (hcsr & H_CSR_IS_MASK) |
Tomas Winkler | 381a58c | 2015-02-10 10:39:32 +0200 | [diff] [blame] | 258 | mei_hcsr_write(dev, hcsr); |
Tomas Winkler | 3a65dd4 | 2012-12-25 19:06:06 +0200 | [diff] [blame] | 259 | } |
Tomas Winkler | 3a65dd4 | 2012-12-25 19:06:06 +0200 | [diff] [blame] | 260 | /** |
Tomas Winkler | 827eef5 | 2013-02-06 14:06:41 +0200 | [diff] [blame] | 261 | * mei_me_intr_enable - enables mei device interrupts |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 262 | * |
| 263 | * @dev: the device structure |
| 264 | */ |
Tomas Winkler | 827eef5 | 2013-02-06 14:06:41 +0200 | [diff] [blame] | 265 | static void mei_me_intr_enable(struct mei_device *dev) |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 266 | { |
Tomas Winkler | 381a58c | 2015-02-10 10:39:32 +0200 | [diff] [blame] | 267 | u32 hcsr = mei_hcsr_read(dev); |
Tomas Winkler | 92db155 | 2014-09-29 16:31:37 +0300 | [diff] [blame] | 268 | |
Alexander Usyskin | 1fa55b4 | 2015-08-02 22:20:52 +0300 | [diff] [blame] | 269 | hcsr |= H_CSR_IE_MASK; |
Tomas Winkler | 381a58c | 2015-02-10 10:39:32 +0200 | [diff] [blame] | 270 | mei_hcsr_set(dev, hcsr); |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | /** |
Alexander Usyskin | ce23139 | 2014-09-29 16:31:50 +0300 | [diff] [blame] | 274 | * mei_me_intr_disable - disables mei device interrupts |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 275 | * |
| 276 | * @dev: the device structure |
| 277 | */ |
Tomas Winkler | 827eef5 | 2013-02-06 14:06:41 +0200 | [diff] [blame] | 278 | static void mei_me_intr_disable(struct mei_device *dev) |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 279 | { |
Tomas Winkler | 381a58c | 2015-02-10 10:39:32 +0200 | [diff] [blame] | 280 | u32 hcsr = mei_hcsr_read(dev); |
Tomas Winkler | 92db155 | 2014-09-29 16:31:37 +0300 | [diff] [blame] | 281 | |
Alexander Usyskin | 1fa55b4 | 2015-08-02 22:20:52 +0300 | [diff] [blame] | 282 | hcsr &= ~H_CSR_IE_MASK; |
Tomas Winkler | 381a58c | 2015-02-10 10:39:32 +0200 | [diff] [blame] | 283 | mei_hcsr_set(dev, hcsr); |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 284 | } |
| 285 | |
Tomas Winkler | adfba32 | 2013-01-08 23:07:27 +0200 | [diff] [blame] | 286 | /** |
Tomas Winkler | 68f8ea1 | 2013-03-10 13:56:07 +0200 | [diff] [blame] | 287 | * mei_me_hw_reset_release - release device from the reset |
| 288 | * |
| 289 | * @dev: the device structure |
| 290 | */ |
| 291 | static void mei_me_hw_reset_release(struct mei_device *dev) |
| 292 | { |
Tomas Winkler | 381a58c | 2015-02-10 10:39:32 +0200 | [diff] [blame] | 293 | u32 hcsr = mei_hcsr_read(dev); |
Tomas Winkler | 68f8ea1 | 2013-03-10 13:56:07 +0200 | [diff] [blame] | 294 | |
| 295 | hcsr |= H_IG; |
| 296 | hcsr &= ~H_RST; |
Tomas Winkler | 381a58c | 2015-02-10 10:39:32 +0200 | [diff] [blame] | 297 | mei_hcsr_set(dev, hcsr); |
Tomas Winkler | b04ada9 | 2014-05-12 12:19:39 +0300 | [diff] [blame] | 298 | |
| 299 | /* complete this write before we set host ready on another CPU */ |
| 300 | mmiowb(); |
Tomas Winkler | 68f8ea1 | 2013-03-10 13:56:07 +0200 | [diff] [blame] | 301 | } |
Tomas Winkler | adfba32 | 2013-01-08 23:07:27 +0200 | [diff] [blame] | 302 | |
Tomas Winkler | 115ba28 | 2013-01-08 23:07:29 +0200 | [diff] [blame] | 303 | /** |
Tomas Winkler | 827eef5 | 2013-02-06 14:06:41 +0200 | [diff] [blame] | 304 | * mei_me_host_set_ready - enable device |
Tomas Winkler | 115ba28 | 2013-01-08 23:07:29 +0200 | [diff] [blame] | 305 | * |
Alexander Usyskin | ce23139 | 2014-09-29 16:31:50 +0300 | [diff] [blame] | 306 | * @dev: mei device |
Tomas Winkler | 115ba28 | 2013-01-08 23:07:29 +0200 | [diff] [blame] | 307 | */ |
Tomas Winkler | 827eef5 | 2013-02-06 14:06:41 +0200 | [diff] [blame] | 308 | static void mei_me_host_set_ready(struct mei_device *dev) |
Tomas Winkler | 115ba28 | 2013-01-08 23:07:29 +0200 | [diff] [blame] | 309 | { |
Tomas Winkler | 381a58c | 2015-02-10 10:39:32 +0200 | [diff] [blame] | 310 | u32 hcsr = mei_hcsr_read(dev); |
Tomas Winkler | 92db155 | 2014-09-29 16:31:37 +0300 | [diff] [blame] | 311 | |
Alexander Usyskin | 1fa55b4 | 2015-08-02 22:20:52 +0300 | [diff] [blame] | 312 | hcsr |= H_CSR_IE_MASK | H_IG | H_RDY; |
Tomas Winkler | 381a58c | 2015-02-10 10:39:32 +0200 | [diff] [blame] | 313 | mei_hcsr_set(dev, hcsr); |
Tomas Winkler | 115ba28 | 2013-01-08 23:07:29 +0200 | [diff] [blame] | 314 | } |
Alexander Usyskin | ce23139 | 2014-09-29 16:31:50 +0300 | [diff] [blame] | 315 | |
Tomas Winkler | 115ba28 | 2013-01-08 23:07:29 +0200 | [diff] [blame] | 316 | /** |
Tomas Winkler | 827eef5 | 2013-02-06 14:06:41 +0200 | [diff] [blame] | 317 | * mei_me_host_is_ready - check whether the host has turned ready |
Tomas Winkler | 115ba28 | 2013-01-08 23:07:29 +0200 | [diff] [blame] | 318 | * |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 319 | * @dev: mei device |
| 320 | * Return: bool |
Tomas Winkler | 115ba28 | 2013-01-08 23:07:29 +0200 | [diff] [blame] | 321 | */ |
Tomas Winkler | 827eef5 | 2013-02-06 14:06:41 +0200 | [diff] [blame] | 322 | static bool mei_me_host_is_ready(struct mei_device *dev) |
Tomas Winkler | 115ba28 | 2013-01-08 23:07:29 +0200 | [diff] [blame] | 323 | { |
Tomas Winkler | 381a58c | 2015-02-10 10:39:32 +0200 | [diff] [blame] | 324 | u32 hcsr = mei_hcsr_read(dev); |
Tomas Winkler | 92db155 | 2014-09-29 16:31:37 +0300 | [diff] [blame] | 325 | |
Tomas Winkler | 18caeb7 | 2014-11-12 23:42:14 +0200 | [diff] [blame] | 326 | return (hcsr & H_RDY) == H_RDY; |
Tomas Winkler | 115ba28 | 2013-01-08 23:07:29 +0200 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | /** |
Tomas Winkler | 827eef5 | 2013-02-06 14:06:41 +0200 | [diff] [blame] | 330 | * mei_me_hw_is_ready - check whether the me(hw) has turned ready |
Tomas Winkler | 115ba28 | 2013-01-08 23:07:29 +0200 | [diff] [blame] | 331 | * |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 332 | * @dev: mei device |
| 333 | * Return: bool |
Tomas Winkler | 115ba28 | 2013-01-08 23:07:29 +0200 | [diff] [blame] | 334 | */ |
Tomas Winkler | 827eef5 | 2013-02-06 14:06:41 +0200 | [diff] [blame] | 335 | static bool mei_me_hw_is_ready(struct mei_device *dev) |
Tomas Winkler | 115ba28 | 2013-01-08 23:07:29 +0200 | [diff] [blame] | 336 | { |
Tomas Winkler | 381a58c | 2015-02-10 10:39:32 +0200 | [diff] [blame] | 337 | u32 mecsr = mei_me_mecsr_read(dev); |
Tomas Winkler | 92db155 | 2014-09-29 16:31:37 +0300 | [diff] [blame] | 338 | |
Tomas Winkler | 18caeb7 | 2014-11-12 23:42:14 +0200 | [diff] [blame] | 339 | return (mecsr & ME_RDY_HRA) == ME_RDY_HRA; |
Tomas Winkler | 115ba28 | 2013-01-08 23:07:29 +0200 | [diff] [blame] | 340 | } |
Tomas Winkler | 3a65dd4 | 2012-12-25 19:06:06 +0200 | [diff] [blame] | 341 | |
Alexander Usyskin | ce23139 | 2014-09-29 16:31:50 +0300 | [diff] [blame] | 342 | /** |
| 343 | * mei_me_hw_ready_wait - wait until the me(hw) has turned ready |
| 344 | * or timeout is reached |
| 345 | * |
| 346 | * @dev: mei device |
| 347 | * Return: 0 on success, error otherwise |
| 348 | */ |
Tomas Winkler | aafae7e | 2013-03-11 18:27:03 +0200 | [diff] [blame] | 349 | static int mei_me_hw_ready_wait(struct mei_device *dev) |
| 350 | { |
Tomas Winkler | aafae7e | 2013-03-11 18:27:03 +0200 | [diff] [blame] | 351 | mutex_unlock(&dev->device_lock); |
Alexander Usyskin | 2c2b93e | 2014-08-12 20:16:03 +0300 | [diff] [blame] | 352 | wait_event_timeout(dev->wait_hw_ready, |
Tomas Winkler | dab9bf4 | 2013-07-17 15:13:17 +0300 | [diff] [blame] | 353 | dev->recvd_hw_ready, |
Tomas Winkler | 7d93e58 | 2014-01-14 23:10:10 +0200 | [diff] [blame] | 354 | mei_secs_to_jiffies(MEI_HW_READY_TIMEOUT)); |
Tomas Winkler | aafae7e | 2013-03-11 18:27:03 +0200 | [diff] [blame] | 355 | mutex_lock(&dev->device_lock); |
Alexander Usyskin | 2c2b93e | 2014-08-12 20:16:03 +0300 | [diff] [blame] | 356 | if (!dev->recvd_hw_ready) { |
Tomas Winkler | 2bf94cab | 2014-09-29 16:31:42 +0300 | [diff] [blame] | 357 | dev_err(dev->dev, "wait hw ready failed\n"); |
Alexander Usyskin | 2c2b93e | 2014-08-12 20:16:03 +0300 | [diff] [blame] | 358 | return -ETIME; |
Tomas Winkler | aafae7e | 2013-03-11 18:27:03 +0200 | [diff] [blame] | 359 | } |
| 360 | |
Alexander Usyskin | 663b7ee | 2015-01-25 23:45:28 +0200 | [diff] [blame] | 361 | mei_me_hw_reset_release(dev); |
Tomas Winkler | aafae7e | 2013-03-11 18:27:03 +0200 | [diff] [blame] | 362 | dev->recvd_hw_ready = false; |
| 363 | return 0; |
| 364 | } |
| 365 | |
Alexander Usyskin | ce23139 | 2014-09-29 16:31:50 +0300 | [diff] [blame] | 366 | /** |
| 367 | * mei_me_hw_start - hw start routine |
| 368 | * |
| 369 | * @dev: mei device |
| 370 | * Return: 0 on success, error otherwise |
| 371 | */ |
Tomas Winkler | aafae7e | 2013-03-11 18:27:03 +0200 | [diff] [blame] | 372 | static int mei_me_hw_start(struct mei_device *dev) |
| 373 | { |
| 374 | int ret = mei_me_hw_ready_wait(dev); |
Tomas Winkler | 92db155 | 2014-09-29 16:31:37 +0300 | [diff] [blame] | 375 | |
Tomas Winkler | aafae7e | 2013-03-11 18:27:03 +0200 | [diff] [blame] | 376 | if (ret) |
| 377 | return ret; |
Tomas Winkler | 2bf94cab | 2014-09-29 16:31:42 +0300 | [diff] [blame] | 378 | dev_dbg(dev->dev, "hw is ready\n"); |
Tomas Winkler | aafae7e | 2013-03-11 18:27:03 +0200 | [diff] [blame] | 379 | |
| 380 | mei_me_host_set_ready(dev); |
| 381 | return ret; |
| 382 | } |
| 383 | |
| 384 | |
Tomas Winkler | 3a65dd4 | 2012-12-25 19:06:06 +0200 | [diff] [blame] | 385 | /** |
Tomas Winkler | 726917f | 2012-06-25 23:46:28 +0300 | [diff] [blame] | 386 | * mei_hbuf_filled_slots - gets number of device filled buffer slots |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 387 | * |
Sedat Dilek | 7353f85 | 2013-01-17 19:54:15 +0100 | [diff] [blame] | 388 | * @dev: the device structure |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 389 | * |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 390 | * Return: number of filled slots |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 391 | */ |
Tomas Winkler | 726917f | 2012-06-25 23:46:28 +0300 | [diff] [blame] | 392 | static unsigned char mei_hbuf_filled_slots(struct mei_device *dev) |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 393 | { |
Tomas Winkler | 18caeb7 | 2014-11-12 23:42:14 +0200 | [diff] [blame] | 394 | u32 hcsr; |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 395 | char read_ptr, write_ptr; |
| 396 | |
Tomas Winkler | 381a58c | 2015-02-10 10:39:32 +0200 | [diff] [blame] | 397 | hcsr = mei_hcsr_read(dev); |
Tomas Winkler | 726917f | 2012-06-25 23:46:28 +0300 | [diff] [blame] | 398 | |
Tomas Winkler | 18caeb7 | 2014-11-12 23:42:14 +0200 | [diff] [blame] | 399 | read_ptr = (char) ((hcsr & H_CBRP) >> 8); |
| 400 | write_ptr = (char) ((hcsr & H_CBWP) >> 16); |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 401 | |
| 402 | return (unsigned char) (write_ptr - read_ptr); |
| 403 | } |
| 404 | |
| 405 | /** |
Masanari Iida | 393b148 | 2013-04-05 01:05:05 +0900 | [diff] [blame] | 406 | * mei_me_hbuf_is_empty - checks if host buffer is empty. |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 407 | * |
| 408 | * @dev: the device structure |
| 409 | * |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 410 | * Return: true if empty, false - otherwise. |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 411 | */ |
Tomas Winkler | 827eef5 | 2013-02-06 14:06:41 +0200 | [diff] [blame] | 412 | static bool mei_me_hbuf_is_empty(struct mei_device *dev) |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 413 | { |
Tomas Winkler | 726917f | 2012-06-25 23:46:28 +0300 | [diff] [blame] | 414 | return mei_hbuf_filled_slots(dev) == 0; |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | /** |
Tomas Winkler | 827eef5 | 2013-02-06 14:06:41 +0200 | [diff] [blame] | 418 | * mei_me_hbuf_empty_slots - counts write empty slots. |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 419 | * |
| 420 | * @dev: the device structure |
| 421 | * |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 422 | * Return: -EOVERFLOW if overflow, otherwise empty slots count |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 423 | */ |
Tomas Winkler | 827eef5 | 2013-02-06 14:06:41 +0200 | [diff] [blame] | 424 | static int mei_me_hbuf_empty_slots(struct mei_device *dev) |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 425 | { |
Tomas Winkler | 24aadc8 | 2012-06-25 23:46:27 +0300 | [diff] [blame] | 426 | unsigned char filled_slots, empty_slots; |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 427 | |
Tomas Winkler | 726917f | 2012-06-25 23:46:28 +0300 | [diff] [blame] | 428 | filled_slots = mei_hbuf_filled_slots(dev); |
Tomas Winkler | 24aadc8 | 2012-06-25 23:46:27 +0300 | [diff] [blame] | 429 | empty_slots = dev->hbuf_depth - filled_slots; |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 430 | |
| 431 | /* check for overflow */ |
Tomas Winkler | 24aadc8 | 2012-06-25 23:46:27 +0300 | [diff] [blame] | 432 | if (filled_slots > dev->hbuf_depth) |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 433 | return -EOVERFLOW; |
| 434 | |
| 435 | return empty_slots; |
| 436 | } |
| 437 | |
Alexander Usyskin | ce23139 | 2014-09-29 16:31:50 +0300 | [diff] [blame] | 438 | /** |
| 439 | * mei_me_hbuf_max_len - returns size of hw buffer. |
| 440 | * |
| 441 | * @dev: the device structure |
| 442 | * |
| 443 | * Return: size of hw buffer in bytes |
| 444 | */ |
Tomas Winkler | 827eef5 | 2013-02-06 14:06:41 +0200 | [diff] [blame] | 445 | static size_t mei_me_hbuf_max_len(const struct mei_device *dev) |
| 446 | { |
| 447 | return dev->hbuf_depth * sizeof(u32) - sizeof(struct mei_msg_hdr); |
| 448 | } |
| 449 | |
| 450 | |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 451 | /** |
Alexander Usyskin | 7ca96aa | 2014-02-19 17:35:49 +0200 | [diff] [blame] | 452 | * mei_me_write_message - writes a message to mei device. |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 453 | * |
| 454 | * @dev: the device structure |
Sedat Dilek | 7353f85 | 2013-01-17 19:54:15 +0100 | [diff] [blame] | 455 | * @header: mei HECI header of message |
Tomas Winkler | 438763f | 2012-12-25 19:05:59 +0200 | [diff] [blame] | 456 | * @buf: message payload will be written |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 457 | * |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 458 | * Return: -EIO if write has failed |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 459 | */ |
Tomas Winkler | 827eef5 | 2013-02-06 14:06:41 +0200 | [diff] [blame] | 460 | static int mei_me_write_message(struct mei_device *dev, |
| 461 | struct mei_msg_hdr *header, |
| 462 | unsigned char *buf) |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 463 | { |
Tomas Winkler | c8c8d08 | 2013-03-11 18:27:02 +0200 | [diff] [blame] | 464 | unsigned long rem; |
Tomas Winkler | 438763f | 2012-12-25 19:05:59 +0200 | [diff] [blame] | 465 | unsigned long length = header->length; |
Tomas Winkler | 169d133 | 2012-06-19 09:13:35 +0300 | [diff] [blame] | 466 | u32 *reg_buf = (u32 *)buf; |
Tomas Winkler | 88eb99f | 2013-01-08 23:07:30 +0200 | [diff] [blame] | 467 | u32 hcsr; |
Tomas Winkler | c8c8d08 | 2013-03-11 18:27:02 +0200 | [diff] [blame] | 468 | u32 dw_cnt; |
Tomas Winkler | 169d133 | 2012-06-19 09:13:35 +0300 | [diff] [blame] | 469 | int i; |
| 470 | int empty_slots; |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 471 | |
Tomas Winkler | 2bf94cab | 2014-09-29 16:31:42 +0300 | [diff] [blame] | 472 | dev_dbg(dev->dev, MEI_HDR_FMT, MEI_HDR_PRM(header)); |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 473 | |
Tomas Winkler | 726917f | 2012-06-25 23:46:28 +0300 | [diff] [blame] | 474 | empty_slots = mei_hbuf_empty_slots(dev); |
Tomas Winkler | 2bf94cab | 2014-09-29 16:31:42 +0300 | [diff] [blame] | 475 | dev_dbg(dev->dev, "empty slots = %hu.\n", empty_slots); |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 476 | |
Tomas Winkler | 7bdf72d | 2012-07-04 19:24:52 +0300 | [diff] [blame] | 477 | dw_cnt = mei_data2slots(length); |
Tomas Winkler | 169d133 | 2012-06-19 09:13:35 +0300 | [diff] [blame] | 478 | if (empty_slots < 0 || dw_cnt > empty_slots) |
Tomas Winkler | 9d09819 | 2014-02-19 17:35:48 +0200 | [diff] [blame] | 479 | return -EMSGSIZE; |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 480 | |
Tomas Winkler | 381a58c | 2015-02-10 10:39:32 +0200 | [diff] [blame] | 481 | mei_me_hcbww_write(dev, *((u32 *) header)); |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 482 | |
Tomas Winkler | 169d133 | 2012-06-19 09:13:35 +0300 | [diff] [blame] | 483 | for (i = 0; i < length / 4; i++) |
Tomas Winkler | 381a58c | 2015-02-10 10:39:32 +0200 | [diff] [blame] | 484 | mei_me_hcbww_write(dev, reg_buf[i]); |
Tomas Winkler | 169d133 | 2012-06-19 09:13:35 +0300 | [diff] [blame] | 485 | |
| 486 | rem = length & 0x3; |
| 487 | if (rem > 0) { |
| 488 | u32 reg = 0; |
Tomas Winkler | 92db155 | 2014-09-29 16:31:37 +0300 | [diff] [blame] | 489 | |
Tomas Winkler | 169d133 | 2012-06-19 09:13:35 +0300 | [diff] [blame] | 490 | memcpy(®, &buf[length - rem], rem); |
Tomas Winkler | 381a58c | 2015-02-10 10:39:32 +0200 | [diff] [blame] | 491 | mei_me_hcbww_write(dev, reg); |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 492 | } |
| 493 | |
Tomas Winkler | 381a58c | 2015-02-10 10:39:32 +0200 | [diff] [blame] | 494 | hcsr = mei_hcsr_read(dev) | H_IG; |
| 495 | mei_hcsr_set(dev, hcsr); |
Tomas Winkler | 827eef5 | 2013-02-06 14:06:41 +0200 | [diff] [blame] | 496 | if (!mei_me_hw_is_ready(dev)) |
Tomas Winkler | 1ccb7b6 | 2012-03-14 14:39:42 +0200 | [diff] [blame] | 497 | return -EIO; |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 498 | |
Tomas Winkler | 1ccb7b6 | 2012-03-14 14:39:42 +0200 | [diff] [blame] | 499 | return 0; |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | /** |
Tomas Winkler | 827eef5 | 2013-02-06 14:06:41 +0200 | [diff] [blame] | 503 | * mei_me_count_full_read_slots - counts read full slots. |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 504 | * |
| 505 | * @dev: the device structure |
| 506 | * |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 507 | * Return: -EOVERFLOW if overflow, otherwise filled slots count |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 508 | */ |
Tomas Winkler | 827eef5 | 2013-02-06 14:06:41 +0200 | [diff] [blame] | 509 | static int mei_me_count_full_read_slots(struct mei_device *dev) |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 510 | { |
Tomas Winkler | 18caeb7 | 2014-11-12 23:42:14 +0200 | [diff] [blame] | 511 | u32 me_csr; |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 512 | char read_ptr, write_ptr; |
| 513 | unsigned char buffer_depth, filled_slots; |
| 514 | |
Tomas Winkler | 381a58c | 2015-02-10 10:39:32 +0200 | [diff] [blame] | 515 | me_csr = mei_me_mecsr_read(dev); |
Tomas Winkler | 18caeb7 | 2014-11-12 23:42:14 +0200 | [diff] [blame] | 516 | buffer_depth = (unsigned char)((me_csr & ME_CBD_HRA) >> 24); |
| 517 | read_ptr = (char) ((me_csr & ME_CBRP_HRA) >> 8); |
| 518 | write_ptr = (char) ((me_csr & ME_CBWP_HRA) >> 16); |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 519 | filled_slots = (unsigned char) (write_ptr - read_ptr); |
| 520 | |
| 521 | /* check for overflow */ |
| 522 | if (filled_slots > buffer_depth) |
| 523 | return -EOVERFLOW; |
| 524 | |
Tomas Winkler | 2bf94cab | 2014-09-29 16:31:42 +0300 | [diff] [blame] | 525 | dev_dbg(dev->dev, "filled_slots =%08x\n", filled_slots); |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 526 | return (int)filled_slots; |
| 527 | } |
| 528 | |
| 529 | /** |
Tomas Winkler | 827eef5 | 2013-02-06 14:06:41 +0200 | [diff] [blame] | 530 | * mei_me_read_slots - reads a message from mei device. |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 531 | * |
| 532 | * @dev: the device structure |
| 533 | * @buffer: message buffer will be written |
| 534 | * @buffer_length: message size will be read |
Alexander Usyskin | ce23139 | 2014-09-29 16:31:50 +0300 | [diff] [blame] | 535 | * |
| 536 | * Return: always 0 |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 537 | */ |
Tomas Winkler | 827eef5 | 2013-02-06 14:06:41 +0200 | [diff] [blame] | 538 | static int mei_me_read_slots(struct mei_device *dev, unsigned char *buffer, |
Tomas Winkler | edf1eed | 2012-02-09 19:25:54 +0200 | [diff] [blame] | 539 | unsigned long buffer_length) |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 540 | { |
Tomas Winkler | edf1eed | 2012-02-09 19:25:54 +0200 | [diff] [blame] | 541 | u32 *reg_buf = (u32 *)buffer; |
Tomas Winkler | 88eb99f | 2013-01-08 23:07:30 +0200 | [diff] [blame] | 542 | u32 hcsr; |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 543 | |
Tomas Winkler | edf1eed | 2012-02-09 19:25:54 +0200 | [diff] [blame] | 544 | for (; buffer_length >= sizeof(u32); buffer_length -= sizeof(u32)) |
Tomas Winkler | 827eef5 | 2013-02-06 14:06:41 +0200 | [diff] [blame] | 545 | *reg_buf++ = mei_me_mecbrw_read(dev); |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 546 | |
| 547 | if (buffer_length > 0) { |
Tomas Winkler | 827eef5 | 2013-02-06 14:06:41 +0200 | [diff] [blame] | 548 | u32 reg = mei_me_mecbrw_read(dev); |
Tomas Winkler | 92db155 | 2014-09-29 16:31:37 +0300 | [diff] [blame] | 549 | |
Tomas Winkler | edf1eed | 2012-02-09 19:25:54 +0200 | [diff] [blame] | 550 | memcpy(reg_buf, ®, buffer_length); |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 551 | } |
| 552 | |
Tomas Winkler | 381a58c | 2015-02-10 10:39:32 +0200 | [diff] [blame] | 553 | hcsr = mei_hcsr_read(dev) | H_IG; |
| 554 | mei_hcsr_set(dev, hcsr); |
Tomas Winkler | 827eef5 | 2013-02-06 14:06:41 +0200 | [diff] [blame] | 555 | return 0; |
Oren Weil | 3ce7272 | 2011-05-15 13:43:43 +0300 | [diff] [blame] | 556 | } |
| 557 | |
Tomas Winkler | 06ecd64 | 2013-02-06 14:06:42 +0200 | [diff] [blame] | 558 | /** |
Alexander Usyskin | 2d1995f | 2015-02-10 10:39:34 +0200 | [diff] [blame] | 559 | * mei_me_pg_set - write pg enter register |
Tomas Winkler | b16c357 | 2014-03-18 22:51:57 +0200 | [diff] [blame] | 560 | * |
| 561 | * @dev: the device structure |
| 562 | */ |
Alexander Usyskin | 2d1995f | 2015-02-10 10:39:34 +0200 | [diff] [blame] | 563 | static void mei_me_pg_set(struct mei_device *dev) |
Tomas Winkler | b16c357 | 2014-03-18 22:51:57 +0200 | [diff] [blame] | 564 | { |
| 565 | struct mei_me_hw *hw = to_me_hw(dev); |
Tomas Winkler | a0a927d | 2015-02-10 10:39:33 +0200 | [diff] [blame] | 566 | u32 reg; |
| 567 | |
| 568 | reg = mei_me_reg_read(hw, H_HPG_CSR); |
| 569 | trace_mei_reg_read(dev->dev, "H_HPG_CSR", H_HPG_CSR, reg); |
Tomas Winkler | 92db155 | 2014-09-29 16:31:37 +0300 | [diff] [blame] | 570 | |
Tomas Winkler | b16c357 | 2014-03-18 22:51:57 +0200 | [diff] [blame] | 571 | reg |= H_HPG_CSR_PGI; |
Tomas Winkler | a0a927d | 2015-02-10 10:39:33 +0200 | [diff] [blame] | 572 | |
| 573 | trace_mei_reg_write(dev->dev, "H_HPG_CSR", H_HPG_CSR, reg); |
Tomas Winkler | b16c357 | 2014-03-18 22:51:57 +0200 | [diff] [blame] | 574 | mei_me_reg_write(hw, H_HPG_CSR, reg); |
| 575 | } |
| 576 | |
| 577 | /** |
Alexander Usyskin | 2d1995f | 2015-02-10 10:39:34 +0200 | [diff] [blame] | 578 | * mei_me_pg_unset - write pg exit register |
Tomas Winkler | b16c357 | 2014-03-18 22:51:57 +0200 | [diff] [blame] | 579 | * |
| 580 | * @dev: the device structure |
| 581 | */ |
Alexander Usyskin | 2d1995f | 2015-02-10 10:39:34 +0200 | [diff] [blame] | 582 | static void mei_me_pg_unset(struct mei_device *dev) |
Tomas Winkler | b16c357 | 2014-03-18 22:51:57 +0200 | [diff] [blame] | 583 | { |
| 584 | struct mei_me_hw *hw = to_me_hw(dev); |
Tomas Winkler | a0a927d | 2015-02-10 10:39:33 +0200 | [diff] [blame] | 585 | u32 reg; |
| 586 | |
| 587 | reg = mei_me_reg_read(hw, H_HPG_CSR); |
| 588 | trace_mei_reg_read(dev->dev, "H_HPG_CSR", H_HPG_CSR, reg); |
Tomas Winkler | b16c357 | 2014-03-18 22:51:57 +0200 | [diff] [blame] | 589 | |
| 590 | WARN(!(reg & H_HPG_CSR_PGI), "PGI is not set\n"); |
| 591 | |
| 592 | reg |= H_HPG_CSR_PGIHEXR; |
Tomas Winkler | a0a927d | 2015-02-10 10:39:33 +0200 | [diff] [blame] | 593 | |
| 594 | trace_mei_reg_write(dev->dev, "H_HPG_CSR", H_HPG_CSR, reg); |
Tomas Winkler | b16c357 | 2014-03-18 22:51:57 +0200 | [diff] [blame] | 595 | mei_me_reg_write(hw, H_HPG_CSR, reg); |
| 596 | } |
| 597 | |
| 598 | /** |
Alexander Usyskin | 859ef2f | 2015-08-02 22:20:54 +0300 | [diff] [blame] | 599 | * mei_me_pg_legacy_enter_sync - perform legacy pg entry procedure |
Tomas Winkler | ba9cdd0 | 2014-03-18 22:52:00 +0200 | [diff] [blame] | 600 | * |
| 601 | * @dev: the device structure |
| 602 | * |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 603 | * Return: 0 on success an error code otherwise |
Tomas Winkler | ba9cdd0 | 2014-03-18 22:52:00 +0200 | [diff] [blame] | 604 | */ |
Alexander Usyskin | 859ef2f | 2015-08-02 22:20:54 +0300 | [diff] [blame] | 605 | static int mei_me_pg_legacy_enter_sync(struct mei_device *dev) |
Tomas Winkler | ba9cdd0 | 2014-03-18 22:52:00 +0200 | [diff] [blame] | 606 | { |
| 607 | struct mei_me_hw *hw = to_me_hw(dev); |
| 608 | unsigned long timeout = mei_secs_to_jiffies(MEI_PGI_TIMEOUT); |
| 609 | int ret; |
| 610 | |
| 611 | dev->pg_event = MEI_PG_EVENT_WAIT; |
| 612 | |
| 613 | ret = mei_hbm_pg(dev, MEI_PG_ISOLATION_ENTRY_REQ_CMD); |
| 614 | if (ret) |
| 615 | return ret; |
| 616 | |
| 617 | mutex_unlock(&dev->device_lock); |
| 618 | wait_event_timeout(dev->wait_pg, |
| 619 | dev->pg_event == MEI_PG_EVENT_RECEIVED, timeout); |
| 620 | mutex_lock(&dev->device_lock); |
| 621 | |
| 622 | if (dev->pg_event == MEI_PG_EVENT_RECEIVED) { |
Alexander Usyskin | 2d1995f | 2015-02-10 10:39:34 +0200 | [diff] [blame] | 623 | mei_me_pg_set(dev); |
Tomas Winkler | ba9cdd0 | 2014-03-18 22:52:00 +0200 | [diff] [blame] | 624 | ret = 0; |
| 625 | } else { |
| 626 | ret = -ETIME; |
| 627 | } |
| 628 | |
| 629 | dev->pg_event = MEI_PG_EVENT_IDLE; |
| 630 | hw->pg_state = MEI_PG_ON; |
| 631 | |
| 632 | return ret; |
| 633 | } |
| 634 | |
| 635 | /** |
Alexander Usyskin | 859ef2f | 2015-08-02 22:20:54 +0300 | [diff] [blame] | 636 | * mei_me_pg_legacy_exit_sync - perform legacy pg exit procedure |
Tomas Winkler | ba9cdd0 | 2014-03-18 22:52:00 +0200 | [diff] [blame] | 637 | * |
| 638 | * @dev: the device structure |
| 639 | * |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 640 | * Return: 0 on success an error code otherwise |
Tomas Winkler | ba9cdd0 | 2014-03-18 22:52:00 +0200 | [diff] [blame] | 641 | */ |
Alexander Usyskin | 859ef2f | 2015-08-02 22:20:54 +0300 | [diff] [blame] | 642 | static int mei_me_pg_legacy_exit_sync(struct mei_device *dev) |
Tomas Winkler | ba9cdd0 | 2014-03-18 22:52:00 +0200 | [diff] [blame] | 643 | { |
| 644 | struct mei_me_hw *hw = to_me_hw(dev); |
| 645 | unsigned long timeout = mei_secs_to_jiffies(MEI_PGI_TIMEOUT); |
| 646 | int ret; |
| 647 | |
| 648 | if (dev->pg_event == MEI_PG_EVENT_RECEIVED) |
| 649 | goto reply; |
| 650 | |
| 651 | dev->pg_event = MEI_PG_EVENT_WAIT; |
| 652 | |
Alexander Usyskin | 2d1995f | 2015-02-10 10:39:34 +0200 | [diff] [blame] | 653 | mei_me_pg_unset(dev); |
Tomas Winkler | ba9cdd0 | 2014-03-18 22:52:00 +0200 | [diff] [blame] | 654 | |
| 655 | mutex_unlock(&dev->device_lock); |
| 656 | wait_event_timeout(dev->wait_pg, |
| 657 | dev->pg_event == MEI_PG_EVENT_RECEIVED, timeout); |
| 658 | mutex_lock(&dev->device_lock); |
| 659 | |
| 660 | reply: |
Alexander Usyskin | 3dc196e | 2015-06-13 08:51:17 +0300 | [diff] [blame] | 661 | if (dev->pg_event != MEI_PG_EVENT_RECEIVED) { |
| 662 | ret = -ETIME; |
| 663 | goto out; |
| 664 | } |
| 665 | |
| 666 | dev->pg_event = MEI_PG_EVENT_INTR_WAIT; |
| 667 | ret = mei_hbm_pg(dev, MEI_PG_ISOLATION_EXIT_RES_CMD); |
| 668 | if (ret) |
| 669 | return ret; |
| 670 | |
| 671 | mutex_unlock(&dev->device_lock); |
| 672 | wait_event_timeout(dev->wait_pg, |
| 673 | dev->pg_event == MEI_PG_EVENT_INTR_RECEIVED, timeout); |
| 674 | mutex_lock(&dev->device_lock); |
| 675 | |
| 676 | if (dev->pg_event == MEI_PG_EVENT_INTR_RECEIVED) |
| 677 | ret = 0; |
Tomas Winkler | ba9cdd0 | 2014-03-18 22:52:00 +0200 | [diff] [blame] | 678 | else |
| 679 | ret = -ETIME; |
| 680 | |
Alexander Usyskin | 3dc196e | 2015-06-13 08:51:17 +0300 | [diff] [blame] | 681 | out: |
Tomas Winkler | ba9cdd0 | 2014-03-18 22:52:00 +0200 | [diff] [blame] | 682 | dev->pg_event = MEI_PG_EVENT_IDLE; |
| 683 | hw->pg_state = MEI_PG_OFF; |
| 684 | |
| 685 | return ret; |
| 686 | } |
| 687 | |
| 688 | /** |
Alexander Usyskin | 3dc196e | 2015-06-13 08:51:17 +0300 | [diff] [blame] | 689 | * mei_me_pg_in_transition - is device now in pg transition |
| 690 | * |
| 691 | * @dev: the device structure |
| 692 | * |
| 693 | * Return: true if in pg transition, false otherwise |
| 694 | */ |
| 695 | static bool mei_me_pg_in_transition(struct mei_device *dev) |
| 696 | { |
| 697 | return dev->pg_event >= MEI_PG_EVENT_WAIT && |
| 698 | dev->pg_event <= MEI_PG_EVENT_INTR_WAIT; |
| 699 | } |
| 700 | |
| 701 | /** |
Tomas Winkler | ee7e5af | 2014-03-18 22:51:58 +0200 | [diff] [blame] | 702 | * mei_me_pg_is_enabled - detect if PG is supported by HW |
| 703 | * |
| 704 | * @dev: the device structure |
| 705 | * |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 706 | * Return: true is pg supported, false otherwise |
Tomas Winkler | ee7e5af | 2014-03-18 22:51:58 +0200 | [diff] [blame] | 707 | */ |
| 708 | static bool mei_me_pg_is_enabled(struct mei_device *dev) |
| 709 | { |
Alexander Usyskin | 859ef2f | 2015-08-02 22:20:54 +0300 | [diff] [blame] | 710 | struct mei_me_hw *hw = to_me_hw(dev); |
Tomas Winkler | 381a58c | 2015-02-10 10:39:32 +0200 | [diff] [blame] | 711 | u32 reg = mei_me_mecsr_read(dev); |
Tomas Winkler | ee7e5af | 2014-03-18 22:51:58 +0200 | [diff] [blame] | 712 | |
Alexander Usyskin | 859ef2f | 2015-08-02 22:20:54 +0300 | [diff] [blame] | 713 | if (hw->d0i3_supported) |
| 714 | return true; |
| 715 | |
Tomas Winkler | ee7e5af | 2014-03-18 22:51:58 +0200 | [diff] [blame] | 716 | if ((reg & ME_PGIC_HRA) == 0) |
| 717 | goto notsupported; |
| 718 | |
Tomas Winkler | bae1cc7 | 2014-08-21 14:29:21 +0300 | [diff] [blame] | 719 | if (!dev->hbm_f_pg_supported) |
Tomas Winkler | ee7e5af | 2014-03-18 22:51:58 +0200 | [diff] [blame] | 720 | goto notsupported; |
| 721 | |
| 722 | return true; |
| 723 | |
| 724 | notsupported: |
Alexander Usyskin | 859ef2f | 2015-08-02 22:20:54 +0300 | [diff] [blame] | 725 | dev_dbg(dev->dev, "pg: not supported: d0i3 = %d HGP = %d hbm version %d.%d ?= %d.%d\n", |
| 726 | hw->d0i3_supported, |
Tomas Winkler | ee7e5af | 2014-03-18 22:51:58 +0200 | [diff] [blame] | 727 | !!(reg & ME_PGIC_HRA), |
| 728 | dev->version.major_version, |
| 729 | dev->version.minor_version, |
| 730 | HBM_MAJOR_VERSION_PGI, |
| 731 | HBM_MINOR_VERSION_PGI); |
| 732 | |
| 733 | return false; |
| 734 | } |
| 735 | |
| 736 | /** |
Alexander Usyskin | 859ef2f | 2015-08-02 22:20:54 +0300 | [diff] [blame] | 737 | * mei_me_d0i3_set - write d0i3 register bit on mei device. |
| 738 | * |
| 739 | * @dev: the device structure |
| 740 | * @intr: ask for interrupt |
| 741 | * |
| 742 | * Return: D0I3C register value |
| 743 | */ |
| 744 | static u32 mei_me_d0i3_set(struct mei_device *dev, bool intr) |
| 745 | { |
| 746 | u32 reg = mei_me_d0i3c_read(dev); |
| 747 | |
| 748 | reg |= H_D0I3C_I3; |
| 749 | if (intr) |
| 750 | reg |= H_D0I3C_IR; |
| 751 | else |
| 752 | reg &= ~H_D0I3C_IR; |
| 753 | mei_me_d0i3c_write(dev, reg); |
| 754 | /* read it to ensure HW consistency */ |
| 755 | reg = mei_me_d0i3c_read(dev); |
| 756 | return reg; |
| 757 | } |
| 758 | |
| 759 | /** |
| 760 | * mei_me_d0i3_unset - clean d0i3 register bit on mei device. |
| 761 | * |
| 762 | * @dev: the device structure |
| 763 | * |
| 764 | * Return: D0I3C register value |
| 765 | */ |
| 766 | static u32 mei_me_d0i3_unset(struct mei_device *dev) |
| 767 | { |
| 768 | u32 reg = mei_me_d0i3c_read(dev); |
| 769 | |
| 770 | reg &= ~H_D0I3C_I3; |
| 771 | reg |= H_D0I3C_IR; |
| 772 | mei_me_d0i3c_write(dev, reg); |
| 773 | /* read it to ensure HW consistency */ |
| 774 | reg = mei_me_d0i3c_read(dev); |
| 775 | return reg; |
| 776 | } |
| 777 | |
| 778 | /** |
| 779 | * mei_me_d0i3_enter_sync - perform d0i3 entry procedure |
| 780 | * |
| 781 | * @dev: the device structure |
| 782 | * |
| 783 | * Return: 0 on success an error code otherwise |
| 784 | */ |
| 785 | static int mei_me_d0i3_enter_sync(struct mei_device *dev) |
| 786 | { |
| 787 | struct mei_me_hw *hw = to_me_hw(dev); |
| 788 | unsigned long d0i3_timeout = mei_secs_to_jiffies(MEI_D0I3_TIMEOUT); |
| 789 | unsigned long pgi_timeout = mei_secs_to_jiffies(MEI_PGI_TIMEOUT); |
| 790 | int ret; |
| 791 | u32 reg; |
| 792 | |
| 793 | reg = mei_me_d0i3c_read(dev); |
| 794 | if (reg & H_D0I3C_I3) { |
| 795 | /* we are in d0i3, nothing to do */ |
| 796 | dev_dbg(dev->dev, "d0i3 set not needed\n"); |
| 797 | ret = 0; |
| 798 | goto on; |
| 799 | } |
| 800 | |
| 801 | /* PGI entry procedure */ |
| 802 | dev->pg_event = MEI_PG_EVENT_WAIT; |
| 803 | |
| 804 | ret = mei_hbm_pg(dev, MEI_PG_ISOLATION_ENTRY_REQ_CMD); |
| 805 | if (ret) |
| 806 | /* FIXME: should we reset here? */ |
| 807 | goto out; |
| 808 | |
| 809 | mutex_unlock(&dev->device_lock); |
| 810 | wait_event_timeout(dev->wait_pg, |
| 811 | dev->pg_event == MEI_PG_EVENT_RECEIVED, pgi_timeout); |
| 812 | mutex_lock(&dev->device_lock); |
| 813 | |
| 814 | if (dev->pg_event != MEI_PG_EVENT_RECEIVED) { |
| 815 | ret = -ETIME; |
| 816 | goto out; |
| 817 | } |
| 818 | /* end PGI entry procedure */ |
| 819 | |
| 820 | dev->pg_event = MEI_PG_EVENT_INTR_WAIT; |
| 821 | |
| 822 | reg = mei_me_d0i3_set(dev, true); |
| 823 | if (!(reg & H_D0I3C_CIP)) { |
| 824 | dev_dbg(dev->dev, "d0i3 enter wait not needed\n"); |
| 825 | ret = 0; |
| 826 | goto on; |
| 827 | } |
| 828 | |
| 829 | mutex_unlock(&dev->device_lock); |
| 830 | wait_event_timeout(dev->wait_pg, |
| 831 | dev->pg_event == MEI_PG_EVENT_INTR_RECEIVED, d0i3_timeout); |
| 832 | mutex_lock(&dev->device_lock); |
| 833 | |
| 834 | if (dev->pg_event != MEI_PG_EVENT_INTR_RECEIVED) { |
| 835 | reg = mei_me_d0i3c_read(dev); |
| 836 | if (!(reg & H_D0I3C_I3)) { |
| 837 | ret = -ETIME; |
| 838 | goto out; |
| 839 | } |
| 840 | } |
| 841 | |
| 842 | ret = 0; |
| 843 | on: |
| 844 | hw->pg_state = MEI_PG_ON; |
| 845 | out: |
| 846 | dev->pg_event = MEI_PG_EVENT_IDLE; |
| 847 | dev_dbg(dev->dev, "d0i3 enter ret = %d\n", ret); |
| 848 | return ret; |
| 849 | } |
| 850 | |
| 851 | /** |
| 852 | * mei_me_d0i3_enter - perform d0i3 entry procedure |
| 853 | * no hbm PG handshake |
| 854 | * no waiting for confirmation; runs with interrupts |
| 855 | * disabled |
| 856 | * |
| 857 | * @dev: the device structure |
| 858 | * |
| 859 | * Return: 0 on success an error code otherwise |
| 860 | */ |
| 861 | static int mei_me_d0i3_enter(struct mei_device *dev) |
| 862 | { |
| 863 | struct mei_me_hw *hw = to_me_hw(dev); |
| 864 | u32 reg; |
| 865 | |
| 866 | reg = mei_me_d0i3c_read(dev); |
| 867 | if (reg & H_D0I3C_I3) { |
| 868 | /* we are in d0i3, nothing to do */ |
| 869 | dev_dbg(dev->dev, "already d0i3 : set not needed\n"); |
| 870 | goto on; |
| 871 | } |
| 872 | |
| 873 | mei_me_d0i3_set(dev, false); |
| 874 | on: |
| 875 | hw->pg_state = MEI_PG_ON; |
| 876 | dev->pg_event = MEI_PG_EVENT_IDLE; |
| 877 | dev_dbg(dev->dev, "d0i3 enter\n"); |
| 878 | return 0; |
| 879 | } |
| 880 | |
| 881 | /** |
| 882 | * mei_me_d0i3_exit_sync - perform d0i3 exit procedure |
| 883 | * |
| 884 | * @dev: the device structure |
| 885 | * |
| 886 | * Return: 0 on success an error code otherwise |
| 887 | */ |
| 888 | static int mei_me_d0i3_exit_sync(struct mei_device *dev) |
| 889 | { |
| 890 | struct mei_me_hw *hw = to_me_hw(dev); |
| 891 | unsigned long timeout = mei_secs_to_jiffies(MEI_D0I3_TIMEOUT); |
| 892 | int ret; |
| 893 | u32 reg; |
| 894 | |
| 895 | dev->pg_event = MEI_PG_EVENT_INTR_WAIT; |
| 896 | |
| 897 | reg = mei_me_d0i3c_read(dev); |
| 898 | if (!(reg & H_D0I3C_I3)) { |
| 899 | /* we are not in d0i3, nothing to do */ |
| 900 | dev_dbg(dev->dev, "d0i3 exit not needed\n"); |
| 901 | ret = 0; |
| 902 | goto off; |
| 903 | } |
| 904 | |
| 905 | reg = mei_me_d0i3_unset(dev); |
| 906 | if (!(reg & H_D0I3C_CIP)) { |
| 907 | dev_dbg(dev->dev, "d0i3 exit wait not needed\n"); |
| 908 | ret = 0; |
| 909 | goto off; |
| 910 | } |
| 911 | |
| 912 | mutex_unlock(&dev->device_lock); |
| 913 | wait_event_timeout(dev->wait_pg, |
| 914 | dev->pg_event == MEI_PG_EVENT_INTR_RECEIVED, timeout); |
| 915 | mutex_lock(&dev->device_lock); |
| 916 | |
| 917 | if (dev->pg_event != MEI_PG_EVENT_INTR_RECEIVED) { |
| 918 | reg = mei_me_d0i3c_read(dev); |
| 919 | if (reg & H_D0I3C_I3) { |
| 920 | ret = -ETIME; |
| 921 | goto out; |
| 922 | } |
| 923 | } |
| 924 | |
| 925 | ret = 0; |
| 926 | off: |
| 927 | hw->pg_state = MEI_PG_OFF; |
| 928 | out: |
| 929 | dev->pg_event = MEI_PG_EVENT_IDLE; |
| 930 | |
| 931 | dev_dbg(dev->dev, "d0i3 exit ret = %d\n", ret); |
| 932 | return ret; |
| 933 | } |
| 934 | |
| 935 | /** |
| 936 | * mei_me_pg_legacy_intr - perform legacy pg processing |
| 937 | * in interrupt thread handler |
| 938 | * |
| 939 | * @dev: the device structure |
| 940 | */ |
| 941 | static void mei_me_pg_legacy_intr(struct mei_device *dev) |
| 942 | { |
| 943 | struct mei_me_hw *hw = to_me_hw(dev); |
| 944 | |
| 945 | if (dev->pg_event != MEI_PG_EVENT_INTR_WAIT) |
| 946 | return; |
| 947 | |
| 948 | dev->pg_event = MEI_PG_EVENT_INTR_RECEIVED; |
| 949 | hw->pg_state = MEI_PG_OFF; |
| 950 | if (waitqueue_active(&dev->wait_pg)) |
| 951 | wake_up(&dev->wait_pg); |
| 952 | } |
| 953 | |
| 954 | /** |
| 955 | * mei_me_d0i3_intr - perform d0i3 processing in interrupt thread handler |
| 956 | * |
| 957 | * @dev: the device structure |
| 958 | */ |
| 959 | static void mei_me_d0i3_intr(struct mei_device *dev) |
| 960 | { |
| 961 | struct mei_me_hw *hw = to_me_hw(dev); |
| 962 | |
| 963 | if (dev->pg_event == MEI_PG_EVENT_INTR_WAIT && |
| 964 | (hw->intr_source & H_D0I3C_IS)) { |
| 965 | dev->pg_event = MEI_PG_EVENT_INTR_RECEIVED; |
| 966 | if (hw->pg_state == MEI_PG_ON) { |
| 967 | hw->pg_state = MEI_PG_OFF; |
| 968 | if (dev->hbm_state != MEI_HBM_IDLE) { |
| 969 | /* |
| 970 | * force H_RDY because it could be |
| 971 | * wiped off during PG |
| 972 | */ |
| 973 | dev_dbg(dev->dev, "d0i3 set host ready\n"); |
| 974 | mei_me_host_set_ready(dev); |
| 975 | } |
| 976 | } else { |
| 977 | hw->pg_state = MEI_PG_ON; |
| 978 | } |
| 979 | |
| 980 | wake_up(&dev->wait_pg); |
| 981 | } |
| 982 | |
| 983 | if (hw->pg_state == MEI_PG_ON && (hw->intr_source & H_IS)) { |
| 984 | /* |
| 985 | * HW sent some data and we are in D0i3, so |
| 986 | * we got here because of HW initiated exit from D0i3. |
| 987 | * Start runtime pm resume sequence to exit low power state. |
| 988 | */ |
| 989 | dev_dbg(dev->dev, "d0i3 want resume\n"); |
| 990 | mei_hbm_pg_resume(dev); |
| 991 | } |
| 992 | } |
| 993 | |
| 994 | /** |
Alexander Usyskin | 3dc196e | 2015-06-13 08:51:17 +0300 | [diff] [blame] | 995 | * mei_me_pg_intr - perform pg processing in interrupt thread handler |
| 996 | * |
| 997 | * @dev: the device structure |
| 998 | */ |
| 999 | static void mei_me_pg_intr(struct mei_device *dev) |
| 1000 | { |
| 1001 | struct mei_me_hw *hw = to_me_hw(dev); |
| 1002 | |
Alexander Usyskin | 859ef2f | 2015-08-02 22:20:54 +0300 | [diff] [blame] | 1003 | if (hw->d0i3_supported) |
| 1004 | mei_me_d0i3_intr(dev); |
| 1005 | else |
| 1006 | mei_me_pg_legacy_intr(dev); |
| 1007 | } |
Alexander Usyskin | 3dc196e | 2015-06-13 08:51:17 +0300 | [diff] [blame] | 1008 | |
Alexander Usyskin | 859ef2f | 2015-08-02 22:20:54 +0300 | [diff] [blame] | 1009 | /** |
| 1010 | * mei_me_pg_enter_sync - perform runtime pm entry procedure |
| 1011 | * |
| 1012 | * @dev: the device structure |
| 1013 | * |
| 1014 | * Return: 0 on success an error code otherwise |
| 1015 | */ |
| 1016 | int mei_me_pg_enter_sync(struct mei_device *dev) |
| 1017 | { |
| 1018 | struct mei_me_hw *hw = to_me_hw(dev); |
| 1019 | |
| 1020 | if (hw->d0i3_supported) |
| 1021 | return mei_me_d0i3_enter_sync(dev); |
| 1022 | else |
| 1023 | return mei_me_pg_legacy_enter_sync(dev); |
| 1024 | } |
| 1025 | |
| 1026 | /** |
| 1027 | * mei_me_pg_exit_sync - perform runtime pm exit procedure |
| 1028 | * |
| 1029 | * @dev: the device structure |
| 1030 | * |
| 1031 | * Return: 0 on success an error code otherwise |
| 1032 | */ |
| 1033 | int mei_me_pg_exit_sync(struct mei_device *dev) |
| 1034 | { |
| 1035 | struct mei_me_hw *hw = to_me_hw(dev); |
| 1036 | |
| 1037 | if (hw->d0i3_supported) |
| 1038 | return mei_me_d0i3_exit_sync(dev); |
| 1039 | else |
| 1040 | return mei_me_pg_legacy_exit_sync(dev); |
Alexander Usyskin | 3dc196e | 2015-06-13 08:51:17 +0300 | [diff] [blame] | 1041 | } |
| 1042 | |
| 1043 | /** |
Alexander Usyskin | ebad6b9 | 2015-08-02 22:20:55 +0300 | [diff] [blame] | 1044 | * mei_me_hw_reset - resets fw via mei csr register. |
| 1045 | * |
| 1046 | * @dev: the device structure |
| 1047 | * @intr_enable: if interrupt should be enabled after reset. |
| 1048 | * |
Alexander Usyskin | b9a1fc9 | 2015-08-02 22:20:56 +0300 | [diff] [blame] | 1049 | * Return: 0 on success an error code otherwise |
Alexander Usyskin | ebad6b9 | 2015-08-02 22:20:55 +0300 | [diff] [blame] | 1050 | */ |
| 1051 | static int mei_me_hw_reset(struct mei_device *dev, bool intr_enable) |
| 1052 | { |
Alexander Usyskin | b9a1fc9 | 2015-08-02 22:20:56 +0300 | [diff] [blame] | 1053 | struct mei_me_hw *hw = to_me_hw(dev); |
| 1054 | int ret; |
| 1055 | u32 hcsr; |
Alexander Usyskin | ebad6b9 | 2015-08-02 22:20:55 +0300 | [diff] [blame] | 1056 | |
Alexander Usyskin | b9a1fc9 | 2015-08-02 22:20:56 +0300 | [diff] [blame] | 1057 | if (intr_enable) { |
| 1058 | mei_me_intr_enable(dev); |
| 1059 | if (hw->d0i3_supported) { |
| 1060 | ret = mei_me_d0i3_exit_sync(dev); |
| 1061 | if (ret) |
| 1062 | return ret; |
| 1063 | } |
| 1064 | } |
| 1065 | |
| 1066 | hcsr = mei_hcsr_read(dev); |
Alexander Usyskin | ebad6b9 | 2015-08-02 22:20:55 +0300 | [diff] [blame] | 1067 | /* H_RST may be found lit before reset is started, |
| 1068 | * for example if preceding reset flow hasn't completed. |
| 1069 | * In that case asserting H_RST will be ignored, therefore |
| 1070 | * we need to clean H_RST bit to start a successful reset sequence. |
| 1071 | */ |
| 1072 | if ((hcsr & H_RST) == H_RST) { |
| 1073 | dev_warn(dev->dev, "H_RST is set = 0x%08X", hcsr); |
| 1074 | hcsr &= ~H_RST; |
| 1075 | mei_hcsr_set(dev, hcsr); |
| 1076 | hcsr = mei_hcsr_read(dev); |
| 1077 | } |
| 1078 | |
| 1079 | hcsr |= H_RST | H_IG | H_CSR_IS_MASK; |
| 1080 | |
Alexander Usyskin | b9a1fc9 | 2015-08-02 22:20:56 +0300 | [diff] [blame] | 1081 | if (!intr_enable) |
Alexander Usyskin | ebad6b9 | 2015-08-02 22:20:55 +0300 | [diff] [blame] | 1082 | hcsr &= ~H_CSR_IE_MASK; |
| 1083 | |
| 1084 | dev->recvd_hw_ready = false; |
| 1085 | mei_hcsr_write(dev, hcsr); |
| 1086 | |
| 1087 | /* |
| 1088 | * Host reads the H_CSR once to ensure that the |
| 1089 | * posted write to H_CSR completes. |
| 1090 | */ |
| 1091 | hcsr = mei_hcsr_read(dev); |
| 1092 | |
| 1093 | if ((hcsr & H_RST) == 0) |
| 1094 | dev_warn(dev->dev, "H_RST is not set = 0x%08X", hcsr); |
| 1095 | |
| 1096 | if ((hcsr & H_RDY) == H_RDY) |
| 1097 | dev_warn(dev->dev, "H_RDY is not cleared 0x%08X", hcsr); |
| 1098 | |
Alexander Usyskin | b9a1fc9 | 2015-08-02 22:20:56 +0300 | [diff] [blame] | 1099 | if (!intr_enable) { |
Alexander Usyskin | ebad6b9 | 2015-08-02 22:20:55 +0300 | [diff] [blame] | 1100 | mei_me_hw_reset_release(dev); |
Alexander Usyskin | b9a1fc9 | 2015-08-02 22:20:56 +0300 | [diff] [blame] | 1101 | if (hw->d0i3_supported) { |
| 1102 | ret = mei_me_d0i3_enter(dev); |
| 1103 | if (ret) |
| 1104 | return ret; |
| 1105 | } |
| 1106 | } |
Alexander Usyskin | ebad6b9 | 2015-08-02 22:20:55 +0300 | [diff] [blame] | 1107 | return 0; |
| 1108 | } |
| 1109 | |
| 1110 | /** |
Tomas Winkler | 06ecd64 | 2013-02-06 14:06:42 +0200 | [diff] [blame] | 1111 | * mei_me_irq_quick_handler - The ISR of the MEI device |
| 1112 | * |
| 1113 | * @irq: The irq number |
| 1114 | * @dev_id: pointer to the device structure |
| 1115 | * |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 1116 | * Return: irqreturn_t |
Tomas Winkler | 06ecd64 | 2013-02-06 14:06:42 +0200 | [diff] [blame] | 1117 | */ |
Tomas Winkler | 06ecd64 | 2013-02-06 14:06:42 +0200 | [diff] [blame] | 1118 | irqreturn_t mei_me_irq_quick_handler(int irq, void *dev_id) |
| 1119 | { |
Alexander Usyskin | 1fa55b4 | 2015-08-02 22:20:52 +0300 | [diff] [blame] | 1120 | struct mei_device *dev = (struct mei_device *)dev_id; |
| 1121 | struct mei_me_hw *hw = to_me_hw(dev); |
| 1122 | u32 hcsr; |
Tomas Winkler | 06ecd64 | 2013-02-06 14:06:42 +0200 | [diff] [blame] | 1123 | |
Alexander Usyskin | 1fa55b4 | 2015-08-02 22:20:52 +0300 | [diff] [blame] | 1124 | hcsr = mei_hcsr_read(dev); |
| 1125 | if (!(hcsr & H_CSR_IS_MASK)) |
Tomas Winkler | 06ecd64 | 2013-02-06 14:06:42 +0200 | [diff] [blame] | 1126 | return IRQ_NONE; |
| 1127 | |
Alexander Usyskin | 1fa55b4 | 2015-08-02 22:20:52 +0300 | [diff] [blame] | 1128 | hw->intr_source = hcsr & H_CSR_IS_MASK; |
| 1129 | dev_dbg(dev->dev, "interrupt source 0x%08X.\n", hw->intr_source); |
| 1130 | |
| 1131 | /* clear H_IS and H_D0I3C_IS bits in H_CSR to clear the interrupts */ |
Tomas Winkler | 381a58c | 2015-02-10 10:39:32 +0200 | [diff] [blame] | 1132 | mei_hcsr_write(dev, hcsr); |
Tomas Winkler | 06ecd64 | 2013-02-06 14:06:42 +0200 | [diff] [blame] | 1133 | |
| 1134 | return IRQ_WAKE_THREAD; |
| 1135 | } |
| 1136 | |
| 1137 | /** |
| 1138 | * mei_me_irq_thread_handler - function called after ISR to handle the interrupt |
| 1139 | * processing. |
| 1140 | * |
| 1141 | * @irq: The irq number |
| 1142 | * @dev_id: pointer to the device structure |
| 1143 | * |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 1144 | * Return: irqreturn_t |
Tomas Winkler | 06ecd64 | 2013-02-06 14:06:42 +0200 | [diff] [blame] | 1145 | * |
| 1146 | */ |
| 1147 | irqreturn_t mei_me_irq_thread_handler(int irq, void *dev_id) |
| 1148 | { |
| 1149 | struct mei_device *dev = (struct mei_device *) dev_id; |
| 1150 | struct mei_cl_cb complete_list; |
Tomas Winkler | 06ecd64 | 2013-02-06 14:06:42 +0200 | [diff] [blame] | 1151 | s32 slots; |
Tomas Winkler | 544f946 | 2014-01-08 20:19:21 +0200 | [diff] [blame] | 1152 | int rets = 0; |
Tomas Winkler | 06ecd64 | 2013-02-06 14:06:42 +0200 | [diff] [blame] | 1153 | |
Tomas Winkler | 2bf94cab | 2014-09-29 16:31:42 +0300 | [diff] [blame] | 1154 | dev_dbg(dev->dev, "function called after ISR to handle the interrupt processing.\n"); |
Tomas Winkler | 06ecd64 | 2013-02-06 14:06:42 +0200 | [diff] [blame] | 1155 | /* initialize our complete list */ |
| 1156 | mutex_lock(&dev->device_lock); |
| 1157 | mei_io_list_init(&complete_list); |
| 1158 | |
Tomas Winkler | 06ecd64 | 2013-02-06 14:06:42 +0200 | [diff] [blame] | 1159 | /* check if ME wants a reset */ |
Tomas Winkler | 33ec082 | 2014-01-12 00:36:09 +0200 | [diff] [blame] | 1160 | if (!mei_hw_is_ready(dev) && dev->dev_state != MEI_DEV_RESETTING) { |
Tomas Winkler | 2bf94cab | 2014-09-29 16:31:42 +0300 | [diff] [blame] | 1161 | dev_warn(dev->dev, "FW not ready: resetting.\n"); |
Tomas Winkler | 544f946 | 2014-01-08 20:19:21 +0200 | [diff] [blame] | 1162 | schedule_work(&dev->reset_work); |
| 1163 | goto end; |
Tomas Winkler | 06ecd64 | 2013-02-06 14:06:42 +0200 | [diff] [blame] | 1164 | } |
| 1165 | |
Alexander Usyskin | 3dc196e | 2015-06-13 08:51:17 +0300 | [diff] [blame] | 1166 | mei_me_pg_intr(dev); |
| 1167 | |
Tomas Winkler | 06ecd64 | 2013-02-06 14:06:42 +0200 | [diff] [blame] | 1168 | /* check if we need to start the dev */ |
| 1169 | if (!mei_host_is_ready(dev)) { |
| 1170 | if (mei_hw_is_ready(dev)) { |
Tomas Winkler | 2bf94cab | 2014-09-29 16:31:42 +0300 | [diff] [blame] | 1171 | dev_dbg(dev->dev, "we need to start the dev.\n"); |
Tomas Winkler | aafae7e | 2013-03-11 18:27:03 +0200 | [diff] [blame] | 1172 | dev->recvd_hw_ready = true; |
Alexander Usyskin | 2c2b93e | 2014-08-12 20:16:03 +0300 | [diff] [blame] | 1173 | wake_up(&dev->wait_hw_ready); |
Tomas Winkler | 06ecd64 | 2013-02-06 14:06:42 +0200 | [diff] [blame] | 1174 | } else { |
Tomas Winkler | 2bf94cab | 2014-09-29 16:31:42 +0300 | [diff] [blame] | 1175 | dev_dbg(dev->dev, "Spurious Interrupt\n"); |
Tomas Winkler | 06ecd64 | 2013-02-06 14:06:42 +0200 | [diff] [blame] | 1176 | } |
Tomas Winkler | 544f946 | 2014-01-08 20:19:21 +0200 | [diff] [blame] | 1177 | goto end; |
Tomas Winkler | 06ecd64 | 2013-02-06 14:06:42 +0200 | [diff] [blame] | 1178 | } |
| 1179 | /* check slots available for reading */ |
| 1180 | slots = mei_count_full_read_slots(dev); |
| 1181 | while (slots > 0) { |
Tomas Winkler | 2bf94cab | 2014-09-29 16:31:42 +0300 | [diff] [blame] | 1182 | dev_dbg(dev->dev, "slots to read = %08x\n", slots); |
Tomas Winkler | 06ecd64 | 2013-02-06 14:06:42 +0200 | [diff] [blame] | 1183 | rets = mei_irq_read_handler(dev, &complete_list, &slots); |
Tomas Winkler | b1b94b5 | 2014-03-03 00:21:28 +0200 | [diff] [blame] | 1184 | /* There is a race between ME write and interrupt delivery: |
| 1185 | * Not all data is always available immediately after the |
| 1186 | * interrupt, so try to read again on the next interrupt. |
| 1187 | */ |
| 1188 | if (rets == -ENODATA) |
| 1189 | break; |
| 1190 | |
Tomas Winkler | 33ec082 | 2014-01-12 00:36:09 +0200 | [diff] [blame] | 1191 | if (rets && dev->dev_state != MEI_DEV_RESETTING) { |
Tomas Winkler | 2bf94cab | 2014-09-29 16:31:42 +0300 | [diff] [blame] | 1192 | dev_err(dev->dev, "mei_irq_read_handler ret = %d.\n", |
Tomas Winkler | b1b94b5 | 2014-03-03 00:21:28 +0200 | [diff] [blame] | 1193 | rets); |
Tomas Winkler | 544f946 | 2014-01-08 20:19:21 +0200 | [diff] [blame] | 1194 | schedule_work(&dev->reset_work); |
Tomas Winkler | 06ecd64 | 2013-02-06 14:06:42 +0200 | [diff] [blame] | 1195 | goto end; |
Tomas Winkler | 544f946 | 2014-01-08 20:19:21 +0200 | [diff] [blame] | 1196 | } |
Tomas Winkler | 06ecd64 | 2013-02-06 14:06:42 +0200 | [diff] [blame] | 1197 | } |
Tomas Winkler | 06ecd64 | 2013-02-06 14:06:42 +0200 | [diff] [blame] | 1198 | |
Tomas Winkler | 6aae48f | 2014-02-19 17:35:47 +0200 | [diff] [blame] | 1199 | dev->hbuf_is_ready = mei_hbuf_is_ready(dev); |
| 1200 | |
Tomas Winkler | ba9cdd0 | 2014-03-18 22:52:00 +0200 | [diff] [blame] | 1201 | /* |
| 1202 | * During PG handshake only allowed write is the replay to the |
| 1203 | * PG exit message, so block calling write function |
Alexander Usyskin | 3dc196e | 2015-06-13 08:51:17 +0300 | [diff] [blame] | 1204 | * if the pg event is in PG handshake |
Tomas Winkler | ba9cdd0 | 2014-03-18 22:52:00 +0200 | [diff] [blame] | 1205 | */ |
Alexander Usyskin | 3dc196e | 2015-06-13 08:51:17 +0300 | [diff] [blame] | 1206 | if (dev->pg_event != MEI_PG_EVENT_WAIT && |
| 1207 | dev->pg_event != MEI_PG_EVENT_RECEIVED) { |
Tomas Winkler | ba9cdd0 | 2014-03-18 22:52:00 +0200 | [diff] [blame] | 1208 | rets = mei_irq_write_handler(dev, &complete_list); |
| 1209 | dev->hbuf_is_ready = mei_hbuf_is_ready(dev); |
| 1210 | } |
Tomas Winkler | 06ecd64 | 2013-02-06 14:06:42 +0200 | [diff] [blame] | 1211 | |
Tomas Winkler | 4c6e22b | 2013-03-17 11:41:20 +0200 | [diff] [blame] | 1212 | mei_irq_compl_handler(dev, &complete_list); |
Tomas Winkler | 06ecd64 | 2013-02-06 14:06:42 +0200 | [diff] [blame] | 1213 | |
Tomas Winkler | 544f946 | 2014-01-08 20:19:21 +0200 | [diff] [blame] | 1214 | end: |
Tomas Winkler | 2bf94cab | 2014-09-29 16:31:42 +0300 | [diff] [blame] | 1215 | dev_dbg(dev->dev, "interrupt thread end ret = %d\n", rets); |
Tomas Winkler | 544f946 | 2014-01-08 20:19:21 +0200 | [diff] [blame] | 1216 | mutex_unlock(&dev->device_lock); |
Tomas Winkler | 06ecd64 | 2013-02-06 14:06:42 +0200 | [diff] [blame] | 1217 | return IRQ_HANDLED; |
| 1218 | } |
Alexander Usyskin | 04dd366 | 2014-03-31 17:59:23 +0300 | [diff] [blame] | 1219 | |
Tomas Winkler | 827eef5 | 2013-02-06 14:06:41 +0200 | [diff] [blame] | 1220 | static const struct mei_hw_ops mei_me_hw_ops = { |
| 1221 | |
Tomas Winkler | 1bd30b6 | 2014-09-29 16:31:43 +0300 | [diff] [blame] | 1222 | .fw_status = mei_me_fw_status, |
Tomas Winkler | 964a233 | 2014-03-18 22:51:59 +0200 | [diff] [blame] | 1223 | .pg_state = mei_me_pg_state, |
| 1224 | |
Tomas Winkler | 827eef5 | 2013-02-06 14:06:41 +0200 | [diff] [blame] | 1225 | .host_is_ready = mei_me_host_is_ready, |
| 1226 | |
| 1227 | .hw_is_ready = mei_me_hw_is_ready, |
| 1228 | .hw_reset = mei_me_hw_reset, |
Tomas Winkler | aafae7e | 2013-03-11 18:27:03 +0200 | [diff] [blame] | 1229 | .hw_config = mei_me_hw_config, |
| 1230 | .hw_start = mei_me_hw_start, |
Tomas Winkler | 827eef5 | 2013-02-06 14:06:41 +0200 | [diff] [blame] | 1231 | |
Alexander Usyskin | 3dc196e | 2015-06-13 08:51:17 +0300 | [diff] [blame] | 1232 | .pg_in_transition = mei_me_pg_in_transition, |
Tomas Winkler | ee7e5af | 2014-03-18 22:51:58 +0200 | [diff] [blame] | 1233 | .pg_is_enabled = mei_me_pg_is_enabled, |
| 1234 | |
Tomas Winkler | 827eef5 | 2013-02-06 14:06:41 +0200 | [diff] [blame] | 1235 | .intr_clear = mei_me_intr_clear, |
| 1236 | .intr_enable = mei_me_intr_enable, |
| 1237 | .intr_disable = mei_me_intr_disable, |
| 1238 | |
| 1239 | .hbuf_free_slots = mei_me_hbuf_empty_slots, |
| 1240 | .hbuf_is_ready = mei_me_hbuf_is_empty, |
| 1241 | .hbuf_max_len = mei_me_hbuf_max_len, |
| 1242 | |
| 1243 | .write = mei_me_write_message, |
| 1244 | |
| 1245 | .rdbuf_full_slots = mei_me_count_full_read_slots, |
| 1246 | .read_hdr = mei_me_mecbrw_read, |
| 1247 | .read = mei_me_read_slots |
| 1248 | }; |
| 1249 | |
Tomas Winkler | c919951 | 2014-05-13 01:30:54 +0300 | [diff] [blame] | 1250 | static bool mei_me_fw_type_nm(struct pci_dev *pdev) |
| 1251 | { |
| 1252 | u32 reg; |
Tomas Winkler | 92db155 | 2014-09-29 16:31:37 +0300 | [diff] [blame] | 1253 | |
Tomas Winkler | c919951 | 2014-05-13 01:30:54 +0300 | [diff] [blame] | 1254 | pci_read_config_dword(pdev, PCI_CFG_HFS_2, ®); |
Tomas Winkler | a96c548 | 2016-02-07 22:46:51 +0200 | [diff] [blame] | 1255 | trace_mei_pci_cfg_read(&pdev->dev, "PCI_CFG_HFS_2", PCI_CFG_HFS_2, reg); |
Tomas Winkler | c919951 | 2014-05-13 01:30:54 +0300 | [diff] [blame] | 1256 | /* make sure that bit 9 (NM) is up and bit 10 (DM) is down */ |
| 1257 | return (reg & 0x600) == 0x200; |
| 1258 | } |
| 1259 | |
| 1260 | #define MEI_CFG_FW_NM \ |
| 1261 | .quirk_probe = mei_me_fw_type_nm |
| 1262 | |
| 1263 | static bool mei_me_fw_type_sps(struct pci_dev *pdev) |
| 1264 | { |
| 1265 | u32 reg; |
| 1266 | /* Read ME FW Status check for SPS Firmware */ |
| 1267 | pci_read_config_dword(pdev, PCI_CFG_HFS_1, ®); |
Tomas Winkler | a96c548 | 2016-02-07 22:46:51 +0200 | [diff] [blame] | 1268 | trace_mei_pci_cfg_read(&pdev->dev, "PCI_CFG_HFS_1", PCI_CFG_HFS_1, reg); |
Tomas Winkler | c919951 | 2014-05-13 01:30:54 +0300 | [diff] [blame] | 1269 | /* if bits [19:16] = 15, running SPS Firmware */ |
| 1270 | return (reg & 0xf0000) == 0xf0000; |
| 1271 | } |
| 1272 | |
| 1273 | #define MEI_CFG_FW_SPS \ |
| 1274 | .quirk_probe = mei_me_fw_type_sps |
| 1275 | |
| 1276 | |
Alexander Usyskin | 8d929d4 | 2014-05-13 01:30:53 +0300 | [diff] [blame] | 1277 | #define MEI_CFG_LEGACY_HFS \ |
| 1278 | .fw_status.count = 0 |
| 1279 | |
| 1280 | #define MEI_CFG_ICH_HFS \ |
| 1281 | .fw_status.count = 1, \ |
| 1282 | .fw_status.status[0] = PCI_CFG_HFS_1 |
| 1283 | |
| 1284 | #define MEI_CFG_PCH_HFS \ |
| 1285 | .fw_status.count = 2, \ |
| 1286 | .fw_status.status[0] = PCI_CFG_HFS_1, \ |
| 1287 | .fw_status.status[1] = PCI_CFG_HFS_2 |
| 1288 | |
Alexander Usyskin | edca5ea | 2014-11-19 17:01:38 +0200 | [diff] [blame] | 1289 | #define MEI_CFG_PCH8_HFS \ |
| 1290 | .fw_status.count = 6, \ |
| 1291 | .fw_status.status[0] = PCI_CFG_HFS_1, \ |
| 1292 | .fw_status.status[1] = PCI_CFG_HFS_2, \ |
| 1293 | .fw_status.status[2] = PCI_CFG_HFS_3, \ |
| 1294 | .fw_status.status[3] = PCI_CFG_HFS_4, \ |
| 1295 | .fw_status.status[4] = PCI_CFG_HFS_5, \ |
| 1296 | .fw_status.status[5] = PCI_CFG_HFS_6 |
Alexander Usyskin | 8d929d4 | 2014-05-13 01:30:53 +0300 | [diff] [blame] | 1297 | |
| 1298 | /* ICH Legacy devices */ |
| 1299 | const struct mei_cfg mei_me_legacy_cfg = { |
| 1300 | MEI_CFG_LEGACY_HFS, |
| 1301 | }; |
| 1302 | |
| 1303 | /* ICH devices */ |
| 1304 | const struct mei_cfg mei_me_ich_cfg = { |
| 1305 | MEI_CFG_ICH_HFS, |
| 1306 | }; |
| 1307 | |
| 1308 | /* PCH devices */ |
| 1309 | const struct mei_cfg mei_me_pch_cfg = { |
| 1310 | MEI_CFG_PCH_HFS, |
| 1311 | }; |
| 1312 | |
Tomas Winkler | c919951 | 2014-05-13 01:30:54 +0300 | [diff] [blame] | 1313 | |
| 1314 | /* PCH Cougar Point and Patsburg with quirk for Node Manager exclusion */ |
| 1315 | const struct mei_cfg mei_me_pch_cpt_pbg_cfg = { |
| 1316 | MEI_CFG_PCH_HFS, |
| 1317 | MEI_CFG_FW_NM, |
| 1318 | }; |
| 1319 | |
Alexander Usyskin | edca5ea | 2014-11-19 17:01:38 +0200 | [diff] [blame] | 1320 | /* PCH8 Lynx Point and newer devices */ |
| 1321 | const struct mei_cfg mei_me_pch8_cfg = { |
| 1322 | MEI_CFG_PCH8_HFS, |
| 1323 | }; |
| 1324 | |
| 1325 | /* PCH8 Lynx Point with quirk for SPS Firmware exclusion */ |
| 1326 | const struct mei_cfg mei_me_pch8_sps_cfg = { |
| 1327 | MEI_CFG_PCH8_HFS, |
Tomas Winkler | c919951 | 2014-05-13 01:30:54 +0300 | [diff] [blame] | 1328 | MEI_CFG_FW_SPS, |
| 1329 | }; |
| 1330 | |
Tomas Winkler | 52c3456 | 2013-02-06 14:06:40 +0200 | [diff] [blame] | 1331 | /** |
Masanari Iida | 393b148 | 2013-04-05 01:05:05 +0900 | [diff] [blame] | 1332 | * mei_me_dev_init - allocates and initializes the mei device structure |
Tomas Winkler | 52c3456 | 2013-02-06 14:06:40 +0200 | [diff] [blame] | 1333 | * |
| 1334 | * @pdev: The pci device structure |
Alexander Usyskin | 8d929d4 | 2014-05-13 01:30:53 +0300 | [diff] [blame] | 1335 | * @cfg: per device generation config |
Tomas Winkler | 52c3456 | 2013-02-06 14:06:40 +0200 | [diff] [blame] | 1336 | * |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 1337 | * Return: The mei_device_device pointer on success, NULL on failure. |
Tomas Winkler | 52c3456 | 2013-02-06 14:06:40 +0200 | [diff] [blame] | 1338 | */ |
Alexander Usyskin | 8d929d4 | 2014-05-13 01:30:53 +0300 | [diff] [blame] | 1339 | struct mei_device *mei_me_dev_init(struct pci_dev *pdev, |
| 1340 | const struct mei_cfg *cfg) |
Tomas Winkler | 52c3456 | 2013-02-06 14:06:40 +0200 | [diff] [blame] | 1341 | { |
| 1342 | struct mei_device *dev; |
Tomas Winkler | 4ad96db | 2014-09-29 16:31:45 +0300 | [diff] [blame] | 1343 | struct mei_me_hw *hw; |
Tomas Winkler | 52c3456 | 2013-02-06 14:06:40 +0200 | [diff] [blame] | 1344 | |
| 1345 | dev = kzalloc(sizeof(struct mei_device) + |
| 1346 | sizeof(struct mei_me_hw), GFP_KERNEL); |
| 1347 | if (!dev) |
| 1348 | return NULL; |
Tomas Winkler | 4ad96db | 2014-09-29 16:31:45 +0300 | [diff] [blame] | 1349 | hw = to_me_hw(dev); |
Tomas Winkler | 52c3456 | 2013-02-06 14:06:40 +0200 | [diff] [blame] | 1350 | |
Tomas Winkler | 3a7e9b6 | 2014-09-29 16:31:41 +0300 | [diff] [blame] | 1351 | mei_device_init(dev, &pdev->dev, &mei_me_hw_ops); |
Tomas Winkler | 4ad96db | 2014-09-29 16:31:45 +0300 | [diff] [blame] | 1352 | hw->cfg = cfg; |
Tomas Winkler | 52c3456 | 2013-02-06 14:06:40 +0200 | [diff] [blame] | 1353 | return dev; |
| 1354 | } |
Tomas Winkler | 06ecd64 | 2013-02-06 14:06:42 +0200 | [diff] [blame] | 1355 | |