blob: 25b1997a62cbc38626ffb3b0166efe649aed9e08 [file] [log] [blame]
Oren Weil3ce72722011-05-15 13:43:43 +03001/*
2 *
3 * Intel Management Engine Interface (Intel MEI) Linux driver
Tomas Winkler733ba912012-02-09 19:25:53 +02004 * Copyright (c) 2003-2012, Intel Corporation.
Oren Weil3ce72722011-05-15 13:43:43 +03005 *
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 Winkler06ecd642013-02-06 14:06:42 +020018
19#include <linux/kthread.h>
20#include <linux/interrupt.h>
Tomas Winkler47a73802012-12-25 19:06:03 +020021
22#include "mei_dev.h"
Tomas Winkler06ecd642013-02-06 14:06:42 +020023#include "hbm.h"
24
Tomas Winkler6e4cd272014-03-11 14:49:23 +020025#include "hw-me.h"
26#include "hw-me-regs.h"
Tomas Winkler06ecd642013-02-06 14:06:42 +020027
Tomas Winklera0a927d2015-02-10 10:39:33 +020028#include "mei-trace.h"
29
Tomas Winkler3a65dd42012-12-25 19:06:06 +020030/**
Tomas Winklerb68301e2013-03-27 16:58:29 +020031 * mei_me_reg_read - Reads 32bit data from the mei device
Tomas Winkler3a65dd42012-12-25 19:06:06 +020032 *
Alexander Usyskina8605ea2014-09-29 16:31:49 +030033 * @hw: the me hardware structure
Tomas Winkler3a65dd42012-12-25 19:06:06 +020034 * @offset: offset from which to read the data
35 *
Alexander Usyskina8605ea2014-09-29 16:31:49 +030036 * Return: register value (u32)
Tomas Winkler3a65dd42012-12-25 19:06:06 +020037 */
Tomas Winklerb68301e2013-03-27 16:58:29 +020038static inline u32 mei_me_reg_read(const struct mei_me_hw *hw,
Tomas Winkler3a65dd42012-12-25 19:06:06 +020039 unsigned long offset)
40{
Tomas Winkler52c34562013-02-06 14:06:40 +020041 return ioread32(hw->mem_addr + offset);
Tomas Winkler3a65dd42012-12-25 19:06:06 +020042}
Oren Weil3ce72722011-05-15 13:43:43 +030043
44
45/**
Tomas Winklerb68301e2013-03-27 16:58:29 +020046 * mei_me_reg_write - Writes 32bit data to the mei device
Tomas Winkler3a65dd42012-12-25 19:06:06 +020047 *
Alexander Usyskina8605ea2014-09-29 16:31:49 +030048 * @hw: the me hardware structure
Tomas Winkler3a65dd42012-12-25 19:06:06 +020049 * @offset: offset from which to write the data
50 * @value: register value to write (u32)
51 */
Tomas Winklerb68301e2013-03-27 16:58:29 +020052static inline void mei_me_reg_write(const struct mei_me_hw *hw,
Tomas Winkler3a65dd42012-12-25 19:06:06 +020053 unsigned long offset, u32 value)
54{
Tomas Winkler52c34562013-02-06 14:06:40 +020055 iowrite32(value, hw->mem_addr + offset);
Tomas Winkler3a65dd42012-12-25 19:06:06 +020056}
57
58/**
Tomas Winklerb68301e2013-03-27 16:58:29 +020059 * mei_me_mecbrw_read - Reads 32bit data from ME circular buffer
Tomas Winklerd0252842013-01-08 23:07:24 +020060 * read window register
Tomas Winkler3a65dd42012-12-25 19:06:06 +020061 *
62 * @dev: the device structure
63 *
Alexander Usyskina8605ea2014-09-29 16:31:49 +030064 * Return: ME_CB_RW register value (u32)
Tomas Winkler3a65dd42012-12-25 19:06:06 +020065 */
Tomas Winkler381a58c2015-02-10 10:39:32 +020066static inline u32 mei_me_mecbrw_read(const struct mei_device *dev)
Tomas Winkler3a65dd42012-12-25 19:06:06 +020067{
Tomas Winklerb68301e2013-03-27 16:58:29 +020068 return mei_me_reg_read(to_me_hw(dev), ME_CB_RW);
Tomas Winkler3a65dd42012-12-25 19:06:06 +020069}
Tomas Winkler381a58c2015-02-10 10:39:32 +020070
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 */
77static 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 Winkler3a65dd42012-12-25 19:06:06 +020082/**
Tomas Winklerb68301e2013-03-27 16:58:29 +020083 * mei_me_mecsr_read - Reads 32bit data from the ME CSR
Tomas Winkler3a65dd42012-12-25 19:06:06 +020084 *
Tomas Winkler381a58c2015-02-10 10:39:32 +020085 * @dev: the device structure
Tomas Winkler3a65dd42012-12-25 19:06:06 +020086 *
Alexander Usyskina8605ea2014-09-29 16:31:49 +030087 * Return: ME_CSR_HA register value (u32)
Tomas Winkler3a65dd42012-12-25 19:06:06 +020088 */
Tomas Winkler381a58c2015-02-10 10:39:32 +020089static inline u32 mei_me_mecsr_read(const struct mei_device *dev)
Tomas Winkler3a65dd42012-12-25 19:06:06 +020090{
Tomas Winklera0a927d2015-02-10 10:39:33 +020091 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 Winkler3a65dd42012-12-25 19:06:06 +020097}
98
99/**
Tomas Winklerd0252842013-01-08 23:07:24 +0200100 * mei_hcsr_read - Reads 32bit data from the host CSR
101 *
Tomas Winkler381a58c2015-02-10 10:39:32 +0200102 * @dev: the device structure
Tomas Winklerd0252842013-01-08 23:07:24 +0200103 *
Alexander Usyskina8605ea2014-09-29 16:31:49 +0300104 * Return: H_CSR register value (u32)
Tomas Winklerd0252842013-01-08 23:07:24 +0200105 */
Tomas Winkler381a58c2015-02-10 10:39:32 +0200106static inline u32 mei_hcsr_read(const struct mei_device *dev)
Tomas Winklerd0252842013-01-08 23:07:24 +0200107{
Tomas Winklera0a927d2015-02-10 10:39:33 +0200108 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 Winkler381a58c2015-02-10 10:39:32 +0200114}
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 */
122static inline void mei_hcsr_write(struct mei_device *dev, u32 reg)
123{
Tomas Winklera0a927d2015-02-10 10:39:33 +0200124 trace_mei_reg_write(dev->dev, "H_CSR", H_CSR, reg);
Tomas Winkler381a58c2015-02-10 10:39:32 +0200125 mei_me_reg_write(to_me_hw(dev), H_CSR, reg);
Tomas Winklerd0252842013-01-08 23:07:24 +0200126}
127
128/**
129 * mei_hcsr_set - writes H_CSR register to the mei device,
Oren Weil3ce72722011-05-15 13:43:43 +0300130 * and ignores the H_IS bit for it is write-one-to-zero.
131 *
Tomas Winkler381a58c2015-02-10 10:39:32 +0200132 * @dev: the device structure
133 * @reg: new register value
Oren Weil3ce72722011-05-15 13:43:43 +0300134 */
Tomas Winkler381a58c2015-02-10 10:39:32 +0200135static inline void mei_hcsr_set(struct mei_device *dev, u32 reg)
Oren Weil3ce72722011-05-15 13:43:43 +0300136{
Alexander Usyskin1fa55b42015-08-02 22:20:52 +0300137 reg &= ~H_CSR_IS_MASK;
Tomas Winkler381a58c2015-02-10 10:39:32 +0200138 mei_hcsr_write(dev, reg);
Oren Weil3ce72722011-05-15 13:43:43 +0300139}
140
Tomas Winkler1bd30b62014-09-29 16:31:43 +0300141/**
Alexander Usyskin859ef2f2015-08-02 22:20:54 +0300142 * 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 */
148static 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 Usyskincf094eb2015-09-18 00:11:52 +0300153 trace_mei_reg_read(dev->dev, "H_D0I3C", H_D0I3C, reg);
Alexander Usyskin859ef2f2015-08-02 22:20:54 +0300154
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 */
164static inline void mei_me_d0i3c_write(struct mei_device *dev, u32 reg)
165{
Alexander Usyskincf094eb2015-09-18 00:11:52 +0300166 trace_mei_reg_write(dev->dev, "H_D0I3C", H_D0I3C, reg);
Alexander Usyskin859ef2f2015-08-02 22:20:54 +0300167 mei_me_reg_write(to_me_hw(dev), H_D0I3C, reg);
168}
169
170/**
Tomas Winkler1bd30b62014-09-29 16:31:43 +0300171 * 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 Usyskince231392014-09-29 16:31:50 +0300175 *
176 * Return: 0 on success, error otherwise
Tomas Winkler1bd30b62014-09-29 16:31:43 +0300177 */
178static int mei_me_fw_status(struct mei_device *dev,
179 struct mei_fw_status *fw_status)
180{
Tomas Winkler1bd30b62014-09-29 16:31:43 +0300181 struct pci_dev *pdev = to_pci_dev(dev->dev);
Tomas Winkler4ad96db2014-09-29 16:31:45 +0300182 struct mei_me_hw *hw = to_me_hw(dev);
183 const struct mei_fw_status *fw_src = &hw->cfg->fw_status;
Tomas Winkler1bd30b62014-09-29 16:31:43 +0300184 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++) {
192 ret = pci_read_config_dword(pdev,
193 fw_src->status[i], &fw_status->status[i]);
194 if (ret)
195 return ret;
196 }
197
198 return 0;
199}
Tomas Winklere7e0c232013-01-08 23:07:31 +0200200
201/**
Masanari Iida393b1482013-04-05 01:05:05 +0900202 * mei_me_hw_config - configure hw dependent settings
Tomas Winklere7e0c232013-01-08 23:07:31 +0200203 *
204 * @dev: mei device
205 */
Tomas Winkler827eef52013-02-06 14:06:41 +0200206static void mei_me_hw_config(struct mei_device *dev)
Tomas Winklere7e0c232013-01-08 23:07:31 +0200207{
Alexander Usyskinbb9f4d22015-08-02 22:20:51 +0300208 struct pci_dev *pdev = to_pci_dev(dev->dev);
Tomas Winklerba9cdd02014-03-18 22:52:00 +0200209 struct mei_me_hw *hw = to_me_hw(dev);
Alexander Usyskinbb9f4d22015-08-02 22:20:51 +0300210 u32 hcsr, reg;
211
Tomas Winklere7e0c232013-01-08 23:07:31 +0200212 /* Doesn't change in runtime */
Alexander Usyskinbb9f4d22015-08-02 22:20:51 +0300213 hcsr = mei_hcsr_read(dev);
Tomas Winklere7e0c232013-01-08 23:07:31 +0200214 dev->hbuf_depth = (hcsr & H_CBD) >> 24;
Tomas Winklerba9cdd02014-03-18 22:52:00 +0200215
Alexander Usyskinbb9f4d22015-08-02 22:20:51 +0300216 reg = 0;
217 pci_read_config_dword(pdev, PCI_CFG_HFS_1, &reg);
218 hw->d0i3_supported =
219 ((reg & PCI_CFG_HFS_1_D0I3_MSK) == PCI_CFG_HFS_1_D0I3_MSK);
Alexander Usyskinb9a1fc92015-08-02 22:20:56 +0300220
221 hw->pg_state = MEI_PG_OFF;
222 if (hw->d0i3_supported) {
223 reg = mei_me_d0i3c_read(dev);
224 if (reg & H_D0I3C_I3)
225 hw->pg_state = MEI_PG_ON;
226 }
Tomas Winklere7e0c232013-01-08 23:07:31 +0200227}
Tomas Winkler964a2332014-03-18 22:51:59 +0200228
229/**
230 * mei_me_pg_state - translate internal pg state
231 * to the mei power gating state
232 *
Alexander Usyskince231392014-09-29 16:31:50 +0300233 * @dev: mei device
234 *
235 * Return: MEI_PG_OFF if aliveness is on and MEI_PG_ON otherwise
Tomas Winkler964a2332014-03-18 22:51:59 +0200236 */
237static inline enum mei_pg_state mei_me_pg_state(struct mei_device *dev)
238{
Tomas Winklerba9cdd02014-03-18 22:52:00 +0200239 struct mei_me_hw *hw = to_me_hw(dev);
Tomas Winkler92db1552014-09-29 16:31:37 +0300240
Tomas Winklerba9cdd02014-03-18 22:52:00 +0200241 return hw->pg_state;
Tomas Winkler964a2332014-03-18 22:51:59 +0200242}
243
Oren Weil3ce72722011-05-15 13:43:43 +0300244/**
Alexander Usyskince231392014-09-29 16:31:50 +0300245 * mei_me_intr_clear - clear and stop interrupts
Tomas Winkler3a65dd42012-12-25 19:06:06 +0200246 *
247 * @dev: the device structure
248 */
Tomas Winkler827eef52013-02-06 14:06:41 +0200249static void mei_me_intr_clear(struct mei_device *dev)
Tomas Winkler3a65dd42012-12-25 19:06:06 +0200250{
Tomas Winkler381a58c2015-02-10 10:39:32 +0200251 u32 hcsr = mei_hcsr_read(dev);
Tomas Winkler92db1552014-09-29 16:31:37 +0300252
Alexander Usyskin1fa55b42015-08-02 22:20:52 +0300253 if (hcsr & H_CSR_IS_MASK)
Tomas Winkler381a58c2015-02-10 10:39:32 +0200254 mei_hcsr_write(dev, hcsr);
Tomas Winkler3a65dd42012-12-25 19:06:06 +0200255}
Tomas Winkler3a65dd42012-12-25 19:06:06 +0200256/**
Tomas Winkler827eef52013-02-06 14:06:41 +0200257 * mei_me_intr_enable - enables mei device interrupts
Oren Weil3ce72722011-05-15 13:43:43 +0300258 *
259 * @dev: the device structure
260 */
Tomas Winkler827eef52013-02-06 14:06:41 +0200261static void mei_me_intr_enable(struct mei_device *dev)
Oren Weil3ce72722011-05-15 13:43:43 +0300262{
Tomas Winkler381a58c2015-02-10 10:39:32 +0200263 u32 hcsr = mei_hcsr_read(dev);
Tomas Winkler92db1552014-09-29 16:31:37 +0300264
Alexander Usyskin1fa55b42015-08-02 22:20:52 +0300265 hcsr |= H_CSR_IE_MASK;
Tomas Winkler381a58c2015-02-10 10:39:32 +0200266 mei_hcsr_set(dev, hcsr);
Oren Weil3ce72722011-05-15 13:43:43 +0300267}
268
269/**
Alexander Usyskince231392014-09-29 16:31:50 +0300270 * mei_me_intr_disable - disables mei device interrupts
Oren Weil3ce72722011-05-15 13:43:43 +0300271 *
272 * @dev: the device structure
273 */
Tomas Winkler827eef52013-02-06 14:06:41 +0200274static void mei_me_intr_disable(struct mei_device *dev)
Oren Weil3ce72722011-05-15 13:43:43 +0300275{
Tomas Winkler381a58c2015-02-10 10:39:32 +0200276 u32 hcsr = mei_hcsr_read(dev);
Tomas Winkler92db1552014-09-29 16:31:37 +0300277
Alexander Usyskin1fa55b42015-08-02 22:20:52 +0300278 hcsr &= ~H_CSR_IE_MASK;
Tomas Winkler381a58c2015-02-10 10:39:32 +0200279 mei_hcsr_set(dev, hcsr);
Oren Weil3ce72722011-05-15 13:43:43 +0300280}
281
Tomas Winkleradfba322013-01-08 23:07:27 +0200282/**
Tomas Winkler68f8ea12013-03-10 13:56:07 +0200283 * mei_me_hw_reset_release - release device from the reset
284 *
285 * @dev: the device structure
286 */
287static void mei_me_hw_reset_release(struct mei_device *dev)
288{
Tomas Winkler381a58c2015-02-10 10:39:32 +0200289 u32 hcsr = mei_hcsr_read(dev);
Tomas Winkler68f8ea12013-03-10 13:56:07 +0200290
291 hcsr |= H_IG;
292 hcsr &= ~H_RST;
Tomas Winkler381a58c2015-02-10 10:39:32 +0200293 mei_hcsr_set(dev, hcsr);
Tomas Winklerb04ada92014-05-12 12:19:39 +0300294
295 /* complete this write before we set host ready on another CPU */
296 mmiowb();
Tomas Winkler68f8ea12013-03-10 13:56:07 +0200297}
Tomas Winkleradfba322013-01-08 23:07:27 +0200298
Tomas Winkler115ba282013-01-08 23:07:29 +0200299/**
Tomas Winkler827eef52013-02-06 14:06:41 +0200300 * mei_me_host_set_ready - enable device
Tomas Winkler115ba282013-01-08 23:07:29 +0200301 *
Alexander Usyskince231392014-09-29 16:31:50 +0300302 * @dev: mei device
Tomas Winkler115ba282013-01-08 23:07:29 +0200303 */
Tomas Winkler827eef52013-02-06 14:06:41 +0200304static void mei_me_host_set_ready(struct mei_device *dev)
Tomas Winkler115ba282013-01-08 23:07:29 +0200305{
Tomas Winkler381a58c2015-02-10 10:39:32 +0200306 u32 hcsr = mei_hcsr_read(dev);
Tomas Winkler92db1552014-09-29 16:31:37 +0300307
Alexander Usyskin1fa55b42015-08-02 22:20:52 +0300308 hcsr |= H_CSR_IE_MASK | H_IG | H_RDY;
Tomas Winkler381a58c2015-02-10 10:39:32 +0200309 mei_hcsr_set(dev, hcsr);
Tomas Winkler115ba282013-01-08 23:07:29 +0200310}
Alexander Usyskince231392014-09-29 16:31:50 +0300311
Tomas Winkler115ba282013-01-08 23:07:29 +0200312/**
Tomas Winkler827eef52013-02-06 14:06:41 +0200313 * mei_me_host_is_ready - check whether the host has turned ready
Tomas Winkler115ba282013-01-08 23:07:29 +0200314 *
Alexander Usyskina8605ea2014-09-29 16:31:49 +0300315 * @dev: mei device
316 * Return: bool
Tomas Winkler115ba282013-01-08 23:07:29 +0200317 */
Tomas Winkler827eef52013-02-06 14:06:41 +0200318static bool mei_me_host_is_ready(struct mei_device *dev)
Tomas Winkler115ba282013-01-08 23:07:29 +0200319{
Tomas Winkler381a58c2015-02-10 10:39:32 +0200320 u32 hcsr = mei_hcsr_read(dev);
Tomas Winkler92db1552014-09-29 16:31:37 +0300321
Tomas Winkler18caeb72014-11-12 23:42:14 +0200322 return (hcsr & H_RDY) == H_RDY;
Tomas Winkler115ba282013-01-08 23:07:29 +0200323}
324
325/**
Tomas Winkler827eef52013-02-06 14:06:41 +0200326 * mei_me_hw_is_ready - check whether the me(hw) has turned ready
Tomas Winkler115ba282013-01-08 23:07:29 +0200327 *
Alexander Usyskina8605ea2014-09-29 16:31:49 +0300328 * @dev: mei device
329 * Return: bool
Tomas Winkler115ba282013-01-08 23:07:29 +0200330 */
Tomas Winkler827eef52013-02-06 14:06:41 +0200331static bool mei_me_hw_is_ready(struct mei_device *dev)
Tomas Winkler115ba282013-01-08 23:07:29 +0200332{
Tomas Winkler381a58c2015-02-10 10:39:32 +0200333 u32 mecsr = mei_me_mecsr_read(dev);
Tomas Winkler92db1552014-09-29 16:31:37 +0300334
Tomas Winkler18caeb72014-11-12 23:42:14 +0200335 return (mecsr & ME_RDY_HRA) == ME_RDY_HRA;
Tomas Winkler115ba282013-01-08 23:07:29 +0200336}
Tomas Winkler3a65dd42012-12-25 19:06:06 +0200337
Alexander Usyskince231392014-09-29 16:31:50 +0300338/**
339 * mei_me_hw_ready_wait - wait until the me(hw) has turned ready
340 * or timeout is reached
341 *
342 * @dev: mei device
343 * Return: 0 on success, error otherwise
344 */
Tomas Winkleraafae7e2013-03-11 18:27:03 +0200345static int mei_me_hw_ready_wait(struct mei_device *dev)
346{
Tomas Winkleraafae7e2013-03-11 18:27:03 +0200347 mutex_unlock(&dev->device_lock);
Alexander Usyskin2c2b93e2014-08-12 20:16:03 +0300348 wait_event_timeout(dev->wait_hw_ready,
Tomas Winklerdab9bf42013-07-17 15:13:17 +0300349 dev->recvd_hw_ready,
Tomas Winkler7d93e582014-01-14 23:10:10 +0200350 mei_secs_to_jiffies(MEI_HW_READY_TIMEOUT));
Tomas Winkleraafae7e2013-03-11 18:27:03 +0200351 mutex_lock(&dev->device_lock);
Alexander Usyskin2c2b93e2014-08-12 20:16:03 +0300352 if (!dev->recvd_hw_ready) {
Tomas Winkler2bf94cab2014-09-29 16:31:42 +0300353 dev_err(dev->dev, "wait hw ready failed\n");
Alexander Usyskin2c2b93e2014-08-12 20:16:03 +0300354 return -ETIME;
Tomas Winkleraafae7e2013-03-11 18:27:03 +0200355 }
356
Alexander Usyskin663b7ee2015-01-25 23:45:28 +0200357 mei_me_hw_reset_release(dev);
Tomas Winkleraafae7e2013-03-11 18:27:03 +0200358 dev->recvd_hw_ready = false;
359 return 0;
360}
361
Alexander Usyskince231392014-09-29 16:31:50 +0300362/**
363 * mei_me_hw_start - hw start routine
364 *
365 * @dev: mei device
366 * Return: 0 on success, error otherwise
367 */
Tomas Winkleraafae7e2013-03-11 18:27:03 +0200368static int mei_me_hw_start(struct mei_device *dev)
369{
370 int ret = mei_me_hw_ready_wait(dev);
Tomas Winkler92db1552014-09-29 16:31:37 +0300371
Tomas Winkleraafae7e2013-03-11 18:27:03 +0200372 if (ret)
373 return ret;
Tomas Winkler2bf94cab2014-09-29 16:31:42 +0300374 dev_dbg(dev->dev, "hw is ready\n");
Tomas Winkleraafae7e2013-03-11 18:27:03 +0200375
376 mei_me_host_set_ready(dev);
377 return ret;
378}
379
380
Tomas Winkler3a65dd42012-12-25 19:06:06 +0200381/**
Tomas Winkler726917f2012-06-25 23:46:28 +0300382 * mei_hbuf_filled_slots - gets number of device filled buffer slots
Oren Weil3ce72722011-05-15 13:43:43 +0300383 *
Sedat Dilek7353f852013-01-17 19:54:15 +0100384 * @dev: the device structure
Oren Weil3ce72722011-05-15 13:43:43 +0300385 *
Alexander Usyskina8605ea2014-09-29 16:31:49 +0300386 * Return: number of filled slots
Oren Weil3ce72722011-05-15 13:43:43 +0300387 */
Tomas Winkler726917f2012-06-25 23:46:28 +0300388static unsigned char mei_hbuf_filled_slots(struct mei_device *dev)
Oren Weil3ce72722011-05-15 13:43:43 +0300389{
Tomas Winkler18caeb72014-11-12 23:42:14 +0200390 u32 hcsr;
Oren Weil3ce72722011-05-15 13:43:43 +0300391 char read_ptr, write_ptr;
392
Tomas Winkler381a58c2015-02-10 10:39:32 +0200393 hcsr = mei_hcsr_read(dev);
Tomas Winkler726917f2012-06-25 23:46:28 +0300394
Tomas Winkler18caeb72014-11-12 23:42:14 +0200395 read_ptr = (char) ((hcsr & H_CBRP) >> 8);
396 write_ptr = (char) ((hcsr & H_CBWP) >> 16);
Oren Weil3ce72722011-05-15 13:43:43 +0300397
398 return (unsigned char) (write_ptr - read_ptr);
399}
400
401/**
Masanari Iida393b1482013-04-05 01:05:05 +0900402 * mei_me_hbuf_is_empty - checks if host buffer is empty.
Oren Weil3ce72722011-05-15 13:43:43 +0300403 *
404 * @dev: the device structure
405 *
Alexander Usyskina8605ea2014-09-29 16:31:49 +0300406 * Return: true if empty, false - otherwise.
Oren Weil3ce72722011-05-15 13:43:43 +0300407 */
Tomas Winkler827eef52013-02-06 14:06:41 +0200408static bool mei_me_hbuf_is_empty(struct mei_device *dev)
Oren Weil3ce72722011-05-15 13:43:43 +0300409{
Tomas Winkler726917f2012-06-25 23:46:28 +0300410 return mei_hbuf_filled_slots(dev) == 0;
Oren Weil3ce72722011-05-15 13:43:43 +0300411}
412
413/**
Tomas Winkler827eef52013-02-06 14:06:41 +0200414 * mei_me_hbuf_empty_slots - counts write empty slots.
Oren Weil3ce72722011-05-15 13:43:43 +0300415 *
416 * @dev: the device structure
417 *
Alexander Usyskina8605ea2014-09-29 16:31:49 +0300418 * Return: -EOVERFLOW if overflow, otherwise empty slots count
Oren Weil3ce72722011-05-15 13:43:43 +0300419 */
Tomas Winkler827eef52013-02-06 14:06:41 +0200420static int mei_me_hbuf_empty_slots(struct mei_device *dev)
Oren Weil3ce72722011-05-15 13:43:43 +0300421{
Tomas Winkler24aadc82012-06-25 23:46:27 +0300422 unsigned char filled_slots, empty_slots;
Oren Weil3ce72722011-05-15 13:43:43 +0300423
Tomas Winkler726917f2012-06-25 23:46:28 +0300424 filled_slots = mei_hbuf_filled_slots(dev);
Tomas Winkler24aadc82012-06-25 23:46:27 +0300425 empty_slots = dev->hbuf_depth - filled_slots;
Oren Weil3ce72722011-05-15 13:43:43 +0300426
427 /* check for overflow */
Tomas Winkler24aadc82012-06-25 23:46:27 +0300428 if (filled_slots > dev->hbuf_depth)
Oren Weil3ce72722011-05-15 13:43:43 +0300429 return -EOVERFLOW;
430
431 return empty_slots;
432}
433
Alexander Usyskince231392014-09-29 16:31:50 +0300434/**
435 * mei_me_hbuf_max_len - returns size of hw buffer.
436 *
437 * @dev: the device structure
438 *
439 * Return: size of hw buffer in bytes
440 */
Tomas Winkler827eef52013-02-06 14:06:41 +0200441static size_t mei_me_hbuf_max_len(const struct mei_device *dev)
442{
443 return dev->hbuf_depth * sizeof(u32) - sizeof(struct mei_msg_hdr);
444}
445
446
Oren Weil3ce72722011-05-15 13:43:43 +0300447/**
Alexander Usyskin7ca96aa2014-02-19 17:35:49 +0200448 * mei_me_write_message - writes a message to mei device.
Oren Weil3ce72722011-05-15 13:43:43 +0300449 *
450 * @dev: the device structure
Sedat Dilek7353f852013-01-17 19:54:15 +0100451 * @header: mei HECI header of message
Tomas Winkler438763f2012-12-25 19:05:59 +0200452 * @buf: message payload will be written
Oren Weil3ce72722011-05-15 13:43:43 +0300453 *
Alexander Usyskina8605ea2014-09-29 16:31:49 +0300454 * Return: -EIO if write has failed
Oren Weil3ce72722011-05-15 13:43:43 +0300455 */
Tomas Winkler827eef52013-02-06 14:06:41 +0200456static int mei_me_write_message(struct mei_device *dev,
457 struct mei_msg_hdr *header,
458 unsigned char *buf)
Oren Weil3ce72722011-05-15 13:43:43 +0300459{
Tomas Winklerc8c8d082013-03-11 18:27:02 +0200460 unsigned long rem;
Tomas Winkler438763f2012-12-25 19:05:59 +0200461 unsigned long length = header->length;
Tomas Winkler169d1332012-06-19 09:13:35 +0300462 u32 *reg_buf = (u32 *)buf;
Tomas Winkler88eb99f2013-01-08 23:07:30 +0200463 u32 hcsr;
Tomas Winklerc8c8d082013-03-11 18:27:02 +0200464 u32 dw_cnt;
Tomas Winkler169d1332012-06-19 09:13:35 +0300465 int i;
466 int empty_slots;
Oren Weil3ce72722011-05-15 13:43:43 +0300467
Tomas Winkler2bf94cab2014-09-29 16:31:42 +0300468 dev_dbg(dev->dev, MEI_HDR_FMT, MEI_HDR_PRM(header));
Oren Weil3ce72722011-05-15 13:43:43 +0300469
Tomas Winkler726917f2012-06-25 23:46:28 +0300470 empty_slots = mei_hbuf_empty_slots(dev);
Tomas Winkler2bf94cab2014-09-29 16:31:42 +0300471 dev_dbg(dev->dev, "empty slots = %hu.\n", empty_slots);
Oren Weil3ce72722011-05-15 13:43:43 +0300472
Tomas Winkler7bdf72d2012-07-04 19:24:52 +0300473 dw_cnt = mei_data2slots(length);
Tomas Winkler169d1332012-06-19 09:13:35 +0300474 if (empty_slots < 0 || dw_cnt > empty_slots)
Tomas Winkler9d098192014-02-19 17:35:48 +0200475 return -EMSGSIZE;
Oren Weil3ce72722011-05-15 13:43:43 +0300476
Tomas Winkler381a58c2015-02-10 10:39:32 +0200477 mei_me_hcbww_write(dev, *((u32 *) header));
Oren Weil3ce72722011-05-15 13:43:43 +0300478
Tomas Winkler169d1332012-06-19 09:13:35 +0300479 for (i = 0; i < length / 4; i++)
Tomas Winkler381a58c2015-02-10 10:39:32 +0200480 mei_me_hcbww_write(dev, reg_buf[i]);
Tomas Winkler169d1332012-06-19 09:13:35 +0300481
482 rem = length & 0x3;
483 if (rem > 0) {
484 u32 reg = 0;
Tomas Winkler92db1552014-09-29 16:31:37 +0300485
Tomas Winkler169d1332012-06-19 09:13:35 +0300486 memcpy(&reg, &buf[length - rem], rem);
Tomas Winkler381a58c2015-02-10 10:39:32 +0200487 mei_me_hcbww_write(dev, reg);
Oren Weil3ce72722011-05-15 13:43:43 +0300488 }
489
Tomas Winkler381a58c2015-02-10 10:39:32 +0200490 hcsr = mei_hcsr_read(dev) | H_IG;
491 mei_hcsr_set(dev, hcsr);
Tomas Winkler827eef52013-02-06 14:06:41 +0200492 if (!mei_me_hw_is_ready(dev))
Tomas Winkler1ccb7b62012-03-14 14:39:42 +0200493 return -EIO;
Oren Weil3ce72722011-05-15 13:43:43 +0300494
Tomas Winkler1ccb7b62012-03-14 14:39:42 +0200495 return 0;
Oren Weil3ce72722011-05-15 13:43:43 +0300496}
497
498/**
Tomas Winkler827eef52013-02-06 14:06:41 +0200499 * mei_me_count_full_read_slots - counts read full slots.
Oren Weil3ce72722011-05-15 13:43:43 +0300500 *
501 * @dev: the device structure
502 *
Alexander Usyskina8605ea2014-09-29 16:31:49 +0300503 * Return: -EOVERFLOW if overflow, otherwise filled slots count
Oren Weil3ce72722011-05-15 13:43:43 +0300504 */
Tomas Winkler827eef52013-02-06 14:06:41 +0200505static int mei_me_count_full_read_slots(struct mei_device *dev)
Oren Weil3ce72722011-05-15 13:43:43 +0300506{
Tomas Winkler18caeb72014-11-12 23:42:14 +0200507 u32 me_csr;
Oren Weil3ce72722011-05-15 13:43:43 +0300508 char read_ptr, write_ptr;
509 unsigned char buffer_depth, filled_slots;
510
Tomas Winkler381a58c2015-02-10 10:39:32 +0200511 me_csr = mei_me_mecsr_read(dev);
Tomas Winkler18caeb72014-11-12 23:42:14 +0200512 buffer_depth = (unsigned char)((me_csr & ME_CBD_HRA) >> 24);
513 read_ptr = (char) ((me_csr & ME_CBRP_HRA) >> 8);
514 write_ptr = (char) ((me_csr & ME_CBWP_HRA) >> 16);
Oren Weil3ce72722011-05-15 13:43:43 +0300515 filled_slots = (unsigned char) (write_ptr - read_ptr);
516
517 /* check for overflow */
518 if (filled_slots > buffer_depth)
519 return -EOVERFLOW;
520
Tomas Winkler2bf94cab2014-09-29 16:31:42 +0300521 dev_dbg(dev->dev, "filled_slots =%08x\n", filled_slots);
Oren Weil3ce72722011-05-15 13:43:43 +0300522 return (int)filled_slots;
523}
524
525/**
Tomas Winkler827eef52013-02-06 14:06:41 +0200526 * mei_me_read_slots - reads a message from mei device.
Oren Weil3ce72722011-05-15 13:43:43 +0300527 *
528 * @dev: the device structure
529 * @buffer: message buffer will be written
530 * @buffer_length: message size will be read
Alexander Usyskince231392014-09-29 16:31:50 +0300531 *
532 * Return: always 0
Oren Weil3ce72722011-05-15 13:43:43 +0300533 */
Tomas Winkler827eef52013-02-06 14:06:41 +0200534static int mei_me_read_slots(struct mei_device *dev, unsigned char *buffer,
Tomas Winkleredf1eed2012-02-09 19:25:54 +0200535 unsigned long buffer_length)
Oren Weil3ce72722011-05-15 13:43:43 +0300536{
Tomas Winkleredf1eed2012-02-09 19:25:54 +0200537 u32 *reg_buf = (u32 *)buffer;
Tomas Winkler88eb99f2013-01-08 23:07:30 +0200538 u32 hcsr;
Oren Weil3ce72722011-05-15 13:43:43 +0300539
Tomas Winkleredf1eed2012-02-09 19:25:54 +0200540 for (; buffer_length >= sizeof(u32); buffer_length -= sizeof(u32))
Tomas Winkler827eef52013-02-06 14:06:41 +0200541 *reg_buf++ = mei_me_mecbrw_read(dev);
Oren Weil3ce72722011-05-15 13:43:43 +0300542
543 if (buffer_length > 0) {
Tomas Winkler827eef52013-02-06 14:06:41 +0200544 u32 reg = mei_me_mecbrw_read(dev);
Tomas Winkler92db1552014-09-29 16:31:37 +0300545
Tomas Winkleredf1eed2012-02-09 19:25:54 +0200546 memcpy(reg_buf, &reg, buffer_length);
Oren Weil3ce72722011-05-15 13:43:43 +0300547 }
548
Tomas Winkler381a58c2015-02-10 10:39:32 +0200549 hcsr = mei_hcsr_read(dev) | H_IG;
550 mei_hcsr_set(dev, hcsr);
Tomas Winkler827eef52013-02-06 14:06:41 +0200551 return 0;
Oren Weil3ce72722011-05-15 13:43:43 +0300552}
553
Tomas Winkler06ecd642013-02-06 14:06:42 +0200554/**
Alexander Usyskin2d1995f2015-02-10 10:39:34 +0200555 * mei_me_pg_set - write pg enter register
Tomas Winklerb16c3572014-03-18 22:51:57 +0200556 *
557 * @dev: the device structure
558 */
Alexander Usyskin2d1995f2015-02-10 10:39:34 +0200559static void mei_me_pg_set(struct mei_device *dev)
Tomas Winklerb16c3572014-03-18 22:51:57 +0200560{
561 struct mei_me_hw *hw = to_me_hw(dev);
Tomas Winklera0a927d2015-02-10 10:39:33 +0200562 u32 reg;
563
564 reg = mei_me_reg_read(hw, H_HPG_CSR);
565 trace_mei_reg_read(dev->dev, "H_HPG_CSR", H_HPG_CSR, reg);
Tomas Winkler92db1552014-09-29 16:31:37 +0300566
Tomas Winklerb16c3572014-03-18 22:51:57 +0200567 reg |= H_HPG_CSR_PGI;
Tomas Winklera0a927d2015-02-10 10:39:33 +0200568
569 trace_mei_reg_write(dev->dev, "H_HPG_CSR", H_HPG_CSR, reg);
Tomas Winklerb16c3572014-03-18 22:51:57 +0200570 mei_me_reg_write(hw, H_HPG_CSR, reg);
571}
572
573/**
Alexander Usyskin2d1995f2015-02-10 10:39:34 +0200574 * mei_me_pg_unset - write pg exit register
Tomas Winklerb16c3572014-03-18 22:51:57 +0200575 *
576 * @dev: the device structure
577 */
Alexander Usyskin2d1995f2015-02-10 10:39:34 +0200578static void mei_me_pg_unset(struct mei_device *dev)
Tomas Winklerb16c3572014-03-18 22:51:57 +0200579{
580 struct mei_me_hw *hw = to_me_hw(dev);
Tomas Winklera0a927d2015-02-10 10:39:33 +0200581 u32 reg;
582
583 reg = mei_me_reg_read(hw, H_HPG_CSR);
584 trace_mei_reg_read(dev->dev, "H_HPG_CSR", H_HPG_CSR, reg);
Tomas Winklerb16c3572014-03-18 22:51:57 +0200585
586 WARN(!(reg & H_HPG_CSR_PGI), "PGI is not set\n");
587
588 reg |= H_HPG_CSR_PGIHEXR;
Tomas Winklera0a927d2015-02-10 10:39:33 +0200589
590 trace_mei_reg_write(dev->dev, "H_HPG_CSR", H_HPG_CSR, reg);
Tomas Winklerb16c3572014-03-18 22:51:57 +0200591 mei_me_reg_write(hw, H_HPG_CSR, reg);
592}
593
594/**
Alexander Usyskin859ef2f2015-08-02 22:20:54 +0300595 * mei_me_pg_legacy_enter_sync - perform legacy pg entry procedure
Tomas Winklerba9cdd02014-03-18 22:52:00 +0200596 *
597 * @dev: the device structure
598 *
Alexander Usyskina8605ea2014-09-29 16:31:49 +0300599 * Return: 0 on success an error code otherwise
Tomas Winklerba9cdd02014-03-18 22:52:00 +0200600 */
Alexander Usyskin859ef2f2015-08-02 22:20:54 +0300601static int mei_me_pg_legacy_enter_sync(struct mei_device *dev)
Tomas Winklerba9cdd02014-03-18 22:52:00 +0200602{
603 struct mei_me_hw *hw = to_me_hw(dev);
604 unsigned long timeout = mei_secs_to_jiffies(MEI_PGI_TIMEOUT);
605 int ret;
606
607 dev->pg_event = MEI_PG_EVENT_WAIT;
608
609 ret = mei_hbm_pg(dev, MEI_PG_ISOLATION_ENTRY_REQ_CMD);
610 if (ret)
611 return ret;
612
613 mutex_unlock(&dev->device_lock);
614 wait_event_timeout(dev->wait_pg,
615 dev->pg_event == MEI_PG_EVENT_RECEIVED, timeout);
616 mutex_lock(&dev->device_lock);
617
618 if (dev->pg_event == MEI_PG_EVENT_RECEIVED) {
Alexander Usyskin2d1995f2015-02-10 10:39:34 +0200619 mei_me_pg_set(dev);
Tomas Winklerba9cdd02014-03-18 22:52:00 +0200620 ret = 0;
621 } else {
622 ret = -ETIME;
623 }
624
625 dev->pg_event = MEI_PG_EVENT_IDLE;
626 hw->pg_state = MEI_PG_ON;
627
628 return ret;
629}
630
631/**
Alexander Usyskin859ef2f2015-08-02 22:20:54 +0300632 * mei_me_pg_legacy_exit_sync - perform legacy pg exit procedure
Tomas Winklerba9cdd02014-03-18 22:52:00 +0200633 *
634 * @dev: the device structure
635 *
Alexander Usyskina8605ea2014-09-29 16:31:49 +0300636 * Return: 0 on success an error code otherwise
Tomas Winklerba9cdd02014-03-18 22:52:00 +0200637 */
Alexander Usyskin859ef2f2015-08-02 22:20:54 +0300638static int mei_me_pg_legacy_exit_sync(struct mei_device *dev)
Tomas Winklerba9cdd02014-03-18 22:52:00 +0200639{
640 struct mei_me_hw *hw = to_me_hw(dev);
641 unsigned long timeout = mei_secs_to_jiffies(MEI_PGI_TIMEOUT);
642 int ret;
643
644 if (dev->pg_event == MEI_PG_EVENT_RECEIVED)
645 goto reply;
646
647 dev->pg_event = MEI_PG_EVENT_WAIT;
648
Alexander Usyskin2d1995f2015-02-10 10:39:34 +0200649 mei_me_pg_unset(dev);
Tomas Winklerba9cdd02014-03-18 22:52:00 +0200650
651 mutex_unlock(&dev->device_lock);
652 wait_event_timeout(dev->wait_pg,
653 dev->pg_event == MEI_PG_EVENT_RECEIVED, timeout);
654 mutex_lock(&dev->device_lock);
655
656reply:
Alexander Usyskin3dc196e2015-06-13 08:51:17 +0300657 if (dev->pg_event != MEI_PG_EVENT_RECEIVED) {
658 ret = -ETIME;
659 goto out;
660 }
661
662 dev->pg_event = MEI_PG_EVENT_INTR_WAIT;
663 ret = mei_hbm_pg(dev, MEI_PG_ISOLATION_EXIT_RES_CMD);
664 if (ret)
665 return ret;
666
667 mutex_unlock(&dev->device_lock);
668 wait_event_timeout(dev->wait_pg,
669 dev->pg_event == MEI_PG_EVENT_INTR_RECEIVED, timeout);
670 mutex_lock(&dev->device_lock);
671
672 if (dev->pg_event == MEI_PG_EVENT_INTR_RECEIVED)
673 ret = 0;
Tomas Winklerba9cdd02014-03-18 22:52:00 +0200674 else
675 ret = -ETIME;
676
Alexander Usyskin3dc196e2015-06-13 08:51:17 +0300677out:
Tomas Winklerba9cdd02014-03-18 22:52:00 +0200678 dev->pg_event = MEI_PG_EVENT_IDLE;
679 hw->pg_state = MEI_PG_OFF;
680
681 return ret;
682}
683
684/**
Alexander Usyskin3dc196e2015-06-13 08:51:17 +0300685 * mei_me_pg_in_transition - is device now in pg transition
686 *
687 * @dev: the device structure
688 *
689 * Return: true if in pg transition, false otherwise
690 */
691static bool mei_me_pg_in_transition(struct mei_device *dev)
692{
693 return dev->pg_event >= MEI_PG_EVENT_WAIT &&
694 dev->pg_event <= MEI_PG_EVENT_INTR_WAIT;
695}
696
697/**
Tomas Winkleree7e5af2014-03-18 22:51:58 +0200698 * mei_me_pg_is_enabled - detect if PG is supported by HW
699 *
700 * @dev: the device structure
701 *
Alexander Usyskina8605ea2014-09-29 16:31:49 +0300702 * Return: true is pg supported, false otherwise
Tomas Winkleree7e5af2014-03-18 22:51:58 +0200703 */
704static bool mei_me_pg_is_enabled(struct mei_device *dev)
705{
Alexander Usyskin859ef2f2015-08-02 22:20:54 +0300706 struct mei_me_hw *hw = to_me_hw(dev);
Tomas Winkler381a58c2015-02-10 10:39:32 +0200707 u32 reg = mei_me_mecsr_read(dev);
Tomas Winkleree7e5af2014-03-18 22:51:58 +0200708
Alexander Usyskin859ef2f2015-08-02 22:20:54 +0300709 if (hw->d0i3_supported)
710 return true;
711
Tomas Winkleree7e5af2014-03-18 22:51:58 +0200712 if ((reg & ME_PGIC_HRA) == 0)
713 goto notsupported;
714
Tomas Winklerbae1cc72014-08-21 14:29:21 +0300715 if (!dev->hbm_f_pg_supported)
Tomas Winkleree7e5af2014-03-18 22:51:58 +0200716 goto notsupported;
717
718 return true;
719
720notsupported:
Alexander Usyskin859ef2f2015-08-02 22:20:54 +0300721 dev_dbg(dev->dev, "pg: not supported: d0i3 = %d HGP = %d hbm version %d.%d ?= %d.%d\n",
722 hw->d0i3_supported,
Tomas Winkleree7e5af2014-03-18 22:51:58 +0200723 !!(reg & ME_PGIC_HRA),
724 dev->version.major_version,
725 dev->version.minor_version,
726 HBM_MAJOR_VERSION_PGI,
727 HBM_MINOR_VERSION_PGI);
728
729 return false;
730}
731
732/**
Alexander Usyskin859ef2f2015-08-02 22:20:54 +0300733 * mei_me_d0i3_set - write d0i3 register bit on mei device.
734 *
735 * @dev: the device structure
736 * @intr: ask for interrupt
737 *
738 * Return: D0I3C register value
739 */
740static u32 mei_me_d0i3_set(struct mei_device *dev, bool intr)
741{
742 u32 reg = mei_me_d0i3c_read(dev);
743
744 reg |= H_D0I3C_I3;
745 if (intr)
746 reg |= H_D0I3C_IR;
747 else
748 reg &= ~H_D0I3C_IR;
749 mei_me_d0i3c_write(dev, reg);
750 /* read it to ensure HW consistency */
751 reg = mei_me_d0i3c_read(dev);
752 return reg;
753}
754
755/**
756 * mei_me_d0i3_unset - clean d0i3 register bit on mei device.
757 *
758 * @dev: the device structure
759 *
760 * Return: D0I3C register value
761 */
762static u32 mei_me_d0i3_unset(struct mei_device *dev)
763{
764 u32 reg = mei_me_d0i3c_read(dev);
765
766 reg &= ~H_D0I3C_I3;
767 reg |= H_D0I3C_IR;
768 mei_me_d0i3c_write(dev, reg);
769 /* read it to ensure HW consistency */
770 reg = mei_me_d0i3c_read(dev);
771 return reg;
772}
773
774/**
775 * mei_me_d0i3_enter_sync - perform d0i3 entry procedure
776 *
777 * @dev: the device structure
778 *
779 * Return: 0 on success an error code otherwise
780 */
781static int mei_me_d0i3_enter_sync(struct mei_device *dev)
782{
783 struct mei_me_hw *hw = to_me_hw(dev);
784 unsigned long d0i3_timeout = mei_secs_to_jiffies(MEI_D0I3_TIMEOUT);
785 unsigned long pgi_timeout = mei_secs_to_jiffies(MEI_PGI_TIMEOUT);
786 int ret;
787 u32 reg;
788
789 reg = mei_me_d0i3c_read(dev);
790 if (reg & H_D0I3C_I3) {
791 /* we are in d0i3, nothing to do */
792 dev_dbg(dev->dev, "d0i3 set not needed\n");
793 ret = 0;
794 goto on;
795 }
796
797 /* PGI entry procedure */
798 dev->pg_event = MEI_PG_EVENT_WAIT;
799
800 ret = mei_hbm_pg(dev, MEI_PG_ISOLATION_ENTRY_REQ_CMD);
801 if (ret)
802 /* FIXME: should we reset here? */
803 goto out;
804
805 mutex_unlock(&dev->device_lock);
806 wait_event_timeout(dev->wait_pg,
807 dev->pg_event == MEI_PG_EVENT_RECEIVED, pgi_timeout);
808 mutex_lock(&dev->device_lock);
809
810 if (dev->pg_event != MEI_PG_EVENT_RECEIVED) {
811 ret = -ETIME;
812 goto out;
813 }
814 /* end PGI entry procedure */
815
816 dev->pg_event = MEI_PG_EVENT_INTR_WAIT;
817
818 reg = mei_me_d0i3_set(dev, true);
819 if (!(reg & H_D0I3C_CIP)) {
820 dev_dbg(dev->dev, "d0i3 enter wait not needed\n");
821 ret = 0;
822 goto on;
823 }
824
825 mutex_unlock(&dev->device_lock);
826 wait_event_timeout(dev->wait_pg,
827 dev->pg_event == MEI_PG_EVENT_INTR_RECEIVED, d0i3_timeout);
828 mutex_lock(&dev->device_lock);
829
830 if (dev->pg_event != MEI_PG_EVENT_INTR_RECEIVED) {
831 reg = mei_me_d0i3c_read(dev);
832 if (!(reg & H_D0I3C_I3)) {
833 ret = -ETIME;
834 goto out;
835 }
836 }
837
838 ret = 0;
839on:
840 hw->pg_state = MEI_PG_ON;
841out:
842 dev->pg_event = MEI_PG_EVENT_IDLE;
843 dev_dbg(dev->dev, "d0i3 enter ret = %d\n", ret);
844 return ret;
845}
846
847/**
848 * mei_me_d0i3_enter - perform d0i3 entry procedure
849 * no hbm PG handshake
850 * no waiting for confirmation; runs with interrupts
851 * disabled
852 *
853 * @dev: the device structure
854 *
855 * Return: 0 on success an error code otherwise
856 */
857static int mei_me_d0i3_enter(struct mei_device *dev)
858{
859 struct mei_me_hw *hw = to_me_hw(dev);
860 u32 reg;
861
862 reg = mei_me_d0i3c_read(dev);
863 if (reg & H_D0I3C_I3) {
864 /* we are in d0i3, nothing to do */
865 dev_dbg(dev->dev, "already d0i3 : set not needed\n");
866 goto on;
867 }
868
869 mei_me_d0i3_set(dev, false);
870on:
871 hw->pg_state = MEI_PG_ON;
872 dev->pg_event = MEI_PG_EVENT_IDLE;
873 dev_dbg(dev->dev, "d0i3 enter\n");
874 return 0;
875}
876
877/**
878 * mei_me_d0i3_exit_sync - perform d0i3 exit procedure
879 *
880 * @dev: the device structure
881 *
882 * Return: 0 on success an error code otherwise
883 */
884static int mei_me_d0i3_exit_sync(struct mei_device *dev)
885{
886 struct mei_me_hw *hw = to_me_hw(dev);
887 unsigned long timeout = mei_secs_to_jiffies(MEI_D0I3_TIMEOUT);
888 int ret;
889 u32 reg;
890
891 dev->pg_event = MEI_PG_EVENT_INTR_WAIT;
892
893 reg = mei_me_d0i3c_read(dev);
894 if (!(reg & H_D0I3C_I3)) {
895 /* we are not in d0i3, nothing to do */
896 dev_dbg(dev->dev, "d0i3 exit not needed\n");
897 ret = 0;
898 goto off;
899 }
900
901 reg = mei_me_d0i3_unset(dev);
902 if (!(reg & H_D0I3C_CIP)) {
903 dev_dbg(dev->dev, "d0i3 exit wait not needed\n");
904 ret = 0;
905 goto off;
906 }
907
908 mutex_unlock(&dev->device_lock);
909 wait_event_timeout(dev->wait_pg,
910 dev->pg_event == MEI_PG_EVENT_INTR_RECEIVED, timeout);
911 mutex_lock(&dev->device_lock);
912
913 if (dev->pg_event != MEI_PG_EVENT_INTR_RECEIVED) {
914 reg = mei_me_d0i3c_read(dev);
915 if (reg & H_D0I3C_I3) {
916 ret = -ETIME;
917 goto out;
918 }
919 }
920
921 ret = 0;
922off:
923 hw->pg_state = MEI_PG_OFF;
924out:
925 dev->pg_event = MEI_PG_EVENT_IDLE;
926
927 dev_dbg(dev->dev, "d0i3 exit ret = %d\n", ret);
928 return ret;
929}
930
931/**
932 * mei_me_pg_legacy_intr - perform legacy pg processing
933 * in interrupt thread handler
934 *
935 * @dev: the device structure
936 */
937static void mei_me_pg_legacy_intr(struct mei_device *dev)
938{
939 struct mei_me_hw *hw = to_me_hw(dev);
940
941 if (dev->pg_event != MEI_PG_EVENT_INTR_WAIT)
942 return;
943
944 dev->pg_event = MEI_PG_EVENT_INTR_RECEIVED;
945 hw->pg_state = MEI_PG_OFF;
946 if (waitqueue_active(&dev->wait_pg))
947 wake_up(&dev->wait_pg);
948}
949
950/**
951 * mei_me_d0i3_intr - perform d0i3 processing in interrupt thread handler
952 *
953 * @dev: the device structure
954 */
955static void mei_me_d0i3_intr(struct mei_device *dev)
956{
957 struct mei_me_hw *hw = to_me_hw(dev);
958
959 if (dev->pg_event == MEI_PG_EVENT_INTR_WAIT &&
960 (hw->intr_source & H_D0I3C_IS)) {
961 dev->pg_event = MEI_PG_EVENT_INTR_RECEIVED;
962 if (hw->pg_state == MEI_PG_ON) {
963 hw->pg_state = MEI_PG_OFF;
964 if (dev->hbm_state != MEI_HBM_IDLE) {
965 /*
966 * force H_RDY because it could be
967 * wiped off during PG
968 */
969 dev_dbg(dev->dev, "d0i3 set host ready\n");
970 mei_me_host_set_ready(dev);
971 }
972 } else {
973 hw->pg_state = MEI_PG_ON;
974 }
975
976 wake_up(&dev->wait_pg);
977 }
978
979 if (hw->pg_state == MEI_PG_ON && (hw->intr_source & H_IS)) {
980 /*
981 * HW sent some data and we are in D0i3, so
982 * we got here because of HW initiated exit from D0i3.
983 * Start runtime pm resume sequence to exit low power state.
984 */
985 dev_dbg(dev->dev, "d0i3 want resume\n");
986 mei_hbm_pg_resume(dev);
987 }
988}
989
990/**
Alexander Usyskin3dc196e2015-06-13 08:51:17 +0300991 * mei_me_pg_intr - perform pg processing in interrupt thread handler
992 *
993 * @dev: the device structure
994 */
995static void mei_me_pg_intr(struct mei_device *dev)
996{
997 struct mei_me_hw *hw = to_me_hw(dev);
998
Alexander Usyskin859ef2f2015-08-02 22:20:54 +0300999 if (hw->d0i3_supported)
1000 mei_me_d0i3_intr(dev);
1001 else
1002 mei_me_pg_legacy_intr(dev);
1003}
Alexander Usyskin3dc196e2015-06-13 08:51:17 +03001004
Alexander Usyskin859ef2f2015-08-02 22:20:54 +03001005/**
1006 * mei_me_pg_enter_sync - perform runtime pm entry procedure
1007 *
1008 * @dev: the device structure
1009 *
1010 * Return: 0 on success an error code otherwise
1011 */
1012int mei_me_pg_enter_sync(struct mei_device *dev)
1013{
1014 struct mei_me_hw *hw = to_me_hw(dev);
1015
1016 if (hw->d0i3_supported)
1017 return mei_me_d0i3_enter_sync(dev);
1018 else
1019 return mei_me_pg_legacy_enter_sync(dev);
1020}
1021
1022/**
1023 * mei_me_pg_exit_sync - perform runtime pm exit procedure
1024 *
1025 * @dev: the device structure
1026 *
1027 * Return: 0 on success an error code otherwise
1028 */
1029int mei_me_pg_exit_sync(struct mei_device *dev)
1030{
1031 struct mei_me_hw *hw = to_me_hw(dev);
1032
1033 if (hw->d0i3_supported)
1034 return mei_me_d0i3_exit_sync(dev);
1035 else
1036 return mei_me_pg_legacy_exit_sync(dev);
Alexander Usyskin3dc196e2015-06-13 08:51:17 +03001037}
1038
1039/**
Alexander Usyskinebad6b92015-08-02 22:20:55 +03001040 * mei_me_hw_reset - resets fw via mei csr register.
1041 *
1042 * @dev: the device structure
1043 * @intr_enable: if interrupt should be enabled after reset.
1044 *
Alexander Usyskinb9a1fc92015-08-02 22:20:56 +03001045 * Return: 0 on success an error code otherwise
Alexander Usyskinebad6b92015-08-02 22:20:55 +03001046 */
1047static int mei_me_hw_reset(struct mei_device *dev, bool intr_enable)
1048{
Alexander Usyskinb9a1fc92015-08-02 22:20:56 +03001049 struct mei_me_hw *hw = to_me_hw(dev);
1050 int ret;
1051 u32 hcsr;
Alexander Usyskinebad6b92015-08-02 22:20:55 +03001052
Alexander Usyskinb9a1fc92015-08-02 22:20:56 +03001053 if (intr_enable) {
1054 mei_me_intr_enable(dev);
1055 if (hw->d0i3_supported) {
1056 ret = mei_me_d0i3_exit_sync(dev);
1057 if (ret)
1058 return ret;
1059 }
1060 }
1061
1062 hcsr = mei_hcsr_read(dev);
Alexander Usyskinebad6b92015-08-02 22:20:55 +03001063 /* H_RST may be found lit before reset is started,
1064 * for example if preceding reset flow hasn't completed.
1065 * In that case asserting H_RST will be ignored, therefore
1066 * we need to clean H_RST bit to start a successful reset sequence.
1067 */
1068 if ((hcsr & H_RST) == H_RST) {
1069 dev_warn(dev->dev, "H_RST is set = 0x%08X", hcsr);
1070 hcsr &= ~H_RST;
1071 mei_hcsr_set(dev, hcsr);
1072 hcsr = mei_hcsr_read(dev);
1073 }
1074
1075 hcsr |= H_RST | H_IG | H_CSR_IS_MASK;
1076
Alexander Usyskinb9a1fc92015-08-02 22:20:56 +03001077 if (!intr_enable)
Alexander Usyskinebad6b92015-08-02 22:20:55 +03001078 hcsr &= ~H_CSR_IE_MASK;
1079
1080 dev->recvd_hw_ready = false;
1081 mei_hcsr_write(dev, hcsr);
1082
1083 /*
1084 * Host reads the H_CSR once to ensure that the
1085 * posted write to H_CSR completes.
1086 */
1087 hcsr = mei_hcsr_read(dev);
1088
1089 if ((hcsr & H_RST) == 0)
1090 dev_warn(dev->dev, "H_RST is not set = 0x%08X", hcsr);
1091
1092 if ((hcsr & H_RDY) == H_RDY)
1093 dev_warn(dev->dev, "H_RDY is not cleared 0x%08X", hcsr);
1094
Alexander Usyskinb9a1fc92015-08-02 22:20:56 +03001095 if (!intr_enable) {
Alexander Usyskinebad6b92015-08-02 22:20:55 +03001096 mei_me_hw_reset_release(dev);
Alexander Usyskinb9a1fc92015-08-02 22:20:56 +03001097 if (hw->d0i3_supported) {
1098 ret = mei_me_d0i3_enter(dev);
1099 if (ret)
1100 return ret;
1101 }
1102 }
Alexander Usyskinebad6b92015-08-02 22:20:55 +03001103 return 0;
1104}
1105
1106/**
Tomas Winkler06ecd642013-02-06 14:06:42 +02001107 * mei_me_irq_quick_handler - The ISR of the MEI device
1108 *
1109 * @irq: The irq number
1110 * @dev_id: pointer to the device structure
1111 *
Alexander Usyskina8605ea2014-09-29 16:31:49 +03001112 * Return: irqreturn_t
Tomas Winkler06ecd642013-02-06 14:06:42 +02001113 */
Tomas Winkler06ecd642013-02-06 14:06:42 +02001114irqreturn_t mei_me_irq_quick_handler(int irq, void *dev_id)
1115{
Alexander Usyskin1fa55b42015-08-02 22:20:52 +03001116 struct mei_device *dev = (struct mei_device *)dev_id;
1117 struct mei_me_hw *hw = to_me_hw(dev);
1118 u32 hcsr;
Tomas Winkler06ecd642013-02-06 14:06:42 +02001119
Alexander Usyskin1fa55b42015-08-02 22:20:52 +03001120 hcsr = mei_hcsr_read(dev);
1121 if (!(hcsr & H_CSR_IS_MASK))
Tomas Winkler06ecd642013-02-06 14:06:42 +02001122 return IRQ_NONE;
1123
Alexander Usyskin1fa55b42015-08-02 22:20:52 +03001124 hw->intr_source = hcsr & H_CSR_IS_MASK;
1125 dev_dbg(dev->dev, "interrupt source 0x%08X.\n", hw->intr_source);
1126
1127 /* clear H_IS and H_D0I3C_IS bits in H_CSR to clear the interrupts */
Tomas Winkler381a58c2015-02-10 10:39:32 +02001128 mei_hcsr_write(dev, hcsr);
Tomas Winkler06ecd642013-02-06 14:06:42 +02001129
1130 return IRQ_WAKE_THREAD;
1131}
1132
1133/**
1134 * mei_me_irq_thread_handler - function called after ISR to handle the interrupt
1135 * processing.
1136 *
1137 * @irq: The irq number
1138 * @dev_id: pointer to the device structure
1139 *
Alexander Usyskina8605ea2014-09-29 16:31:49 +03001140 * Return: irqreturn_t
Tomas Winkler06ecd642013-02-06 14:06:42 +02001141 *
1142 */
1143irqreturn_t mei_me_irq_thread_handler(int irq, void *dev_id)
1144{
1145 struct mei_device *dev = (struct mei_device *) dev_id;
1146 struct mei_cl_cb complete_list;
Tomas Winkler06ecd642013-02-06 14:06:42 +02001147 s32 slots;
Tomas Winkler544f9462014-01-08 20:19:21 +02001148 int rets = 0;
Tomas Winkler06ecd642013-02-06 14:06:42 +02001149
Tomas Winkler2bf94cab2014-09-29 16:31:42 +03001150 dev_dbg(dev->dev, "function called after ISR to handle the interrupt processing.\n");
Tomas Winkler06ecd642013-02-06 14:06:42 +02001151 /* initialize our complete list */
1152 mutex_lock(&dev->device_lock);
1153 mei_io_list_init(&complete_list);
1154
Tomas Winkler06ecd642013-02-06 14:06:42 +02001155 /* check if ME wants a reset */
Tomas Winkler33ec0822014-01-12 00:36:09 +02001156 if (!mei_hw_is_ready(dev) && dev->dev_state != MEI_DEV_RESETTING) {
Tomas Winkler2bf94cab2014-09-29 16:31:42 +03001157 dev_warn(dev->dev, "FW not ready: resetting.\n");
Tomas Winkler544f9462014-01-08 20:19:21 +02001158 schedule_work(&dev->reset_work);
1159 goto end;
Tomas Winkler06ecd642013-02-06 14:06:42 +02001160 }
1161
Alexander Usyskin3dc196e2015-06-13 08:51:17 +03001162 mei_me_pg_intr(dev);
1163
Tomas Winkler06ecd642013-02-06 14:06:42 +02001164 /* check if we need to start the dev */
1165 if (!mei_host_is_ready(dev)) {
1166 if (mei_hw_is_ready(dev)) {
Tomas Winkler2bf94cab2014-09-29 16:31:42 +03001167 dev_dbg(dev->dev, "we need to start the dev.\n");
Tomas Winkleraafae7e2013-03-11 18:27:03 +02001168 dev->recvd_hw_ready = true;
Alexander Usyskin2c2b93e2014-08-12 20:16:03 +03001169 wake_up(&dev->wait_hw_ready);
Tomas Winkler06ecd642013-02-06 14:06:42 +02001170 } else {
Tomas Winkler2bf94cab2014-09-29 16:31:42 +03001171 dev_dbg(dev->dev, "Spurious Interrupt\n");
Tomas Winkler06ecd642013-02-06 14:06:42 +02001172 }
Tomas Winkler544f9462014-01-08 20:19:21 +02001173 goto end;
Tomas Winkler06ecd642013-02-06 14:06:42 +02001174 }
1175 /* check slots available for reading */
1176 slots = mei_count_full_read_slots(dev);
1177 while (slots > 0) {
Tomas Winkler2bf94cab2014-09-29 16:31:42 +03001178 dev_dbg(dev->dev, "slots to read = %08x\n", slots);
Tomas Winkler06ecd642013-02-06 14:06:42 +02001179 rets = mei_irq_read_handler(dev, &complete_list, &slots);
Tomas Winklerb1b94b52014-03-03 00:21:28 +02001180 /* There is a race between ME write and interrupt delivery:
1181 * Not all data is always available immediately after the
1182 * interrupt, so try to read again on the next interrupt.
1183 */
1184 if (rets == -ENODATA)
1185 break;
1186
Tomas Winkler33ec0822014-01-12 00:36:09 +02001187 if (rets && dev->dev_state != MEI_DEV_RESETTING) {
Tomas Winkler2bf94cab2014-09-29 16:31:42 +03001188 dev_err(dev->dev, "mei_irq_read_handler ret = %d.\n",
Tomas Winklerb1b94b52014-03-03 00:21:28 +02001189 rets);
Tomas Winkler544f9462014-01-08 20:19:21 +02001190 schedule_work(&dev->reset_work);
Tomas Winkler06ecd642013-02-06 14:06:42 +02001191 goto end;
Tomas Winkler544f9462014-01-08 20:19:21 +02001192 }
Tomas Winkler06ecd642013-02-06 14:06:42 +02001193 }
Tomas Winkler06ecd642013-02-06 14:06:42 +02001194
Tomas Winkler6aae48f2014-02-19 17:35:47 +02001195 dev->hbuf_is_ready = mei_hbuf_is_ready(dev);
1196
Tomas Winklerba9cdd02014-03-18 22:52:00 +02001197 /*
1198 * During PG handshake only allowed write is the replay to the
1199 * PG exit message, so block calling write function
Alexander Usyskin3dc196e2015-06-13 08:51:17 +03001200 * if the pg event is in PG handshake
Tomas Winklerba9cdd02014-03-18 22:52:00 +02001201 */
Alexander Usyskin3dc196e2015-06-13 08:51:17 +03001202 if (dev->pg_event != MEI_PG_EVENT_WAIT &&
1203 dev->pg_event != MEI_PG_EVENT_RECEIVED) {
Tomas Winklerba9cdd02014-03-18 22:52:00 +02001204 rets = mei_irq_write_handler(dev, &complete_list);
1205 dev->hbuf_is_ready = mei_hbuf_is_ready(dev);
1206 }
Tomas Winkler06ecd642013-02-06 14:06:42 +02001207
Tomas Winkler4c6e22b2013-03-17 11:41:20 +02001208 mei_irq_compl_handler(dev, &complete_list);
Tomas Winkler06ecd642013-02-06 14:06:42 +02001209
Tomas Winkler544f9462014-01-08 20:19:21 +02001210end:
Tomas Winkler2bf94cab2014-09-29 16:31:42 +03001211 dev_dbg(dev->dev, "interrupt thread end ret = %d\n", rets);
Tomas Winkler544f9462014-01-08 20:19:21 +02001212 mutex_unlock(&dev->device_lock);
Tomas Winkler06ecd642013-02-06 14:06:42 +02001213 return IRQ_HANDLED;
1214}
Alexander Usyskin04dd3662014-03-31 17:59:23 +03001215
Tomas Winkler827eef52013-02-06 14:06:41 +02001216static const struct mei_hw_ops mei_me_hw_ops = {
1217
Tomas Winkler1bd30b62014-09-29 16:31:43 +03001218 .fw_status = mei_me_fw_status,
Tomas Winkler964a2332014-03-18 22:51:59 +02001219 .pg_state = mei_me_pg_state,
1220
Tomas Winkler827eef52013-02-06 14:06:41 +02001221 .host_is_ready = mei_me_host_is_ready,
1222
1223 .hw_is_ready = mei_me_hw_is_ready,
1224 .hw_reset = mei_me_hw_reset,
Tomas Winkleraafae7e2013-03-11 18:27:03 +02001225 .hw_config = mei_me_hw_config,
1226 .hw_start = mei_me_hw_start,
Tomas Winkler827eef52013-02-06 14:06:41 +02001227
Alexander Usyskin3dc196e2015-06-13 08:51:17 +03001228 .pg_in_transition = mei_me_pg_in_transition,
Tomas Winkleree7e5af2014-03-18 22:51:58 +02001229 .pg_is_enabled = mei_me_pg_is_enabled,
1230
Tomas Winkler827eef52013-02-06 14:06:41 +02001231 .intr_clear = mei_me_intr_clear,
1232 .intr_enable = mei_me_intr_enable,
1233 .intr_disable = mei_me_intr_disable,
1234
1235 .hbuf_free_slots = mei_me_hbuf_empty_slots,
1236 .hbuf_is_ready = mei_me_hbuf_is_empty,
1237 .hbuf_max_len = mei_me_hbuf_max_len,
1238
1239 .write = mei_me_write_message,
1240
1241 .rdbuf_full_slots = mei_me_count_full_read_slots,
1242 .read_hdr = mei_me_mecbrw_read,
1243 .read = mei_me_read_slots
1244};
1245
Tomas Winklerc9199512014-05-13 01:30:54 +03001246static bool mei_me_fw_type_nm(struct pci_dev *pdev)
1247{
1248 u32 reg;
Tomas Winkler92db1552014-09-29 16:31:37 +03001249
Tomas Winklerc9199512014-05-13 01:30:54 +03001250 pci_read_config_dword(pdev, PCI_CFG_HFS_2, &reg);
1251 /* make sure that bit 9 (NM) is up and bit 10 (DM) is down */
1252 return (reg & 0x600) == 0x200;
1253}
1254
1255#define MEI_CFG_FW_NM \
1256 .quirk_probe = mei_me_fw_type_nm
1257
1258static bool mei_me_fw_type_sps(struct pci_dev *pdev)
1259{
1260 u32 reg;
1261 /* Read ME FW Status check for SPS Firmware */
1262 pci_read_config_dword(pdev, PCI_CFG_HFS_1, &reg);
1263 /* if bits [19:16] = 15, running SPS Firmware */
1264 return (reg & 0xf0000) == 0xf0000;
1265}
1266
1267#define MEI_CFG_FW_SPS \
1268 .quirk_probe = mei_me_fw_type_sps
1269
1270
Alexander Usyskin8d929d42014-05-13 01:30:53 +03001271#define MEI_CFG_LEGACY_HFS \
1272 .fw_status.count = 0
1273
1274#define MEI_CFG_ICH_HFS \
1275 .fw_status.count = 1, \
1276 .fw_status.status[0] = PCI_CFG_HFS_1
1277
1278#define MEI_CFG_PCH_HFS \
1279 .fw_status.count = 2, \
1280 .fw_status.status[0] = PCI_CFG_HFS_1, \
1281 .fw_status.status[1] = PCI_CFG_HFS_2
1282
Alexander Usyskinedca5ea2014-11-19 17:01:38 +02001283#define MEI_CFG_PCH8_HFS \
1284 .fw_status.count = 6, \
1285 .fw_status.status[0] = PCI_CFG_HFS_1, \
1286 .fw_status.status[1] = PCI_CFG_HFS_2, \
1287 .fw_status.status[2] = PCI_CFG_HFS_3, \
1288 .fw_status.status[3] = PCI_CFG_HFS_4, \
1289 .fw_status.status[4] = PCI_CFG_HFS_5, \
1290 .fw_status.status[5] = PCI_CFG_HFS_6
Alexander Usyskin8d929d42014-05-13 01:30:53 +03001291
1292/* ICH Legacy devices */
1293const struct mei_cfg mei_me_legacy_cfg = {
1294 MEI_CFG_LEGACY_HFS,
1295};
1296
1297/* ICH devices */
1298const struct mei_cfg mei_me_ich_cfg = {
1299 MEI_CFG_ICH_HFS,
1300};
1301
1302/* PCH devices */
1303const struct mei_cfg mei_me_pch_cfg = {
1304 MEI_CFG_PCH_HFS,
1305};
1306
Tomas Winklerc9199512014-05-13 01:30:54 +03001307
1308/* PCH Cougar Point and Patsburg with quirk for Node Manager exclusion */
1309const struct mei_cfg mei_me_pch_cpt_pbg_cfg = {
1310 MEI_CFG_PCH_HFS,
1311 MEI_CFG_FW_NM,
1312};
1313
Alexander Usyskinedca5ea2014-11-19 17:01:38 +02001314/* PCH8 Lynx Point and newer devices */
1315const struct mei_cfg mei_me_pch8_cfg = {
1316 MEI_CFG_PCH8_HFS,
1317};
1318
1319/* PCH8 Lynx Point with quirk for SPS Firmware exclusion */
1320const struct mei_cfg mei_me_pch8_sps_cfg = {
1321 MEI_CFG_PCH8_HFS,
Tomas Winklerc9199512014-05-13 01:30:54 +03001322 MEI_CFG_FW_SPS,
1323};
1324
Tomas Winkler52c34562013-02-06 14:06:40 +02001325/**
Masanari Iida393b1482013-04-05 01:05:05 +09001326 * mei_me_dev_init - allocates and initializes the mei device structure
Tomas Winkler52c34562013-02-06 14:06:40 +02001327 *
1328 * @pdev: The pci device structure
Alexander Usyskin8d929d42014-05-13 01:30:53 +03001329 * @cfg: per device generation config
Tomas Winkler52c34562013-02-06 14:06:40 +02001330 *
Alexander Usyskina8605ea2014-09-29 16:31:49 +03001331 * Return: The mei_device_device pointer on success, NULL on failure.
Tomas Winkler52c34562013-02-06 14:06:40 +02001332 */
Alexander Usyskin8d929d42014-05-13 01:30:53 +03001333struct mei_device *mei_me_dev_init(struct pci_dev *pdev,
1334 const struct mei_cfg *cfg)
Tomas Winkler52c34562013-02-06 14:06:40 +02001335{
1336 struct mei_device *dev;
Tomas Winkler4ad96db2014-09-29 16:31:45 +03001337 struct mei_me_hw *hw;
Tomas Winkler52c34562013-02-06 14:06:40 +02001338
1339 dev = kzalloc(sizeof(struct mei_device) +
1340 sizeof(struct mei_me_hw), GFP_KERNEL);
1341 if (!dev)
1342 return NULL;
Tomas Winkler4ad96db2014-09-29 16:31:45 +03001343 hw = to_me_hw(dev);
Tomas Winkler52c34562013-02-06 14:06:40 +02001344
Tomas Winkler3a7e9b62014-09-29 16:31:41 +03001345 mei_device_init(dev, &pdev->dev, &mei_me_hw_ops);
Tomas Winkler4ad96db2014-09-29 16:31:45 +03001346 hw->cfg = cfg;
Tomas Winkler52c34562013-02-06 14:06:40 +02001347 return dev;
1348}
Tomas Winkler06ecd642013-02-06 14:06:42 +02001349