init.c (95d002e0a34cb0f238abb39987f9980f325d8332) init.c (43b8a7ed4739a86c1e8543489bf5524780f66284)
1// SPDX-License-Identifier: GPL-2.0
1/*
2/*
2 *
3 * Copyright (c) 2012-2018, Intel Corporation. All rights reserved.
3 * Intel Management Engine Interface (Intel MEI) Linux driver
4 * Intel Management Engine Interface (Intel MEI) Linux driver
4 * Copyright (c) 2003-2012, Intel Corporation.
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/export.h>
18#include <linux/sched.h>
19#include <linux/wait.h>
20#include <linux/delay.h>
21
22#include <linux/mei.h>

--- 105 unchanged lines hidden (view full) ---

128 * if the reset was called due the hbm protocol error
129 * we need to call it before hw start
130 * so the hbm watchdog won't kick in
131 */
132 mei_hbm_idle(dev);
133
134 /* enter reset flow */
135 interrupts_enabled = state != MEI_DEV_POWER_DOWN;
5 */
6
7#include <linux/export.h>
8#include <linux/sched.h>
9#include <linux/wait.h>
10#include <linux/delay.h>
11
12#include <linux/mei.h>

--- 105 unchanged lines hidden (view full) ---

118 * if the reset was called due the hbm protocol error
119 * we need to call it before hw start
120 * so the hbm watchdog won't kick in
121 */
122 mei_hbm_idle(dev);
123
124 /* enter reset flow */
125 interrupts_enabled = state != MEI_DEV_POWER_DOWN;
136 dev->dev_state = MEI_DEV_RESETTING;
126 mei_set_devstate(dev, MEI_DEV_RESETTING);
137
138 dev->reset_count++;
139 if (dev->reset_count > MEI_MAX_CONSEC_RESET) {
140 dev_err(dev->dev, "reset: reached maximal consecutive resets: disabling the device\n");
127
128 dev->reset_count++;
129 if (dev->reset_count > MEI_MAX_CONSEC_RESET) {
130 dev_err(dev->dev, "reset: reached maximal consecutive resets: disabling the device\n");
141 dev->dev_state = MEI_DEV_DISABLED;
131 mei_set_devstate(dev, MEI_DEV_DISABLED);
142 return -ENODEV;
143 }
144
145 ret = mei_hw_reset(dev, interrupts_enabled);
146 /* fall through and remove the sw state even if hw reset has failed */
147
148 /* no need to clean up software state in case of power up */
149 if (state != MEI_DEV_INITIALIZING && state != MEI_DEV_POWER_UP)

--- 5 unchanged lines hidden (view full) ---

155
156 if (ret) {
157 dev_err(dev->dev, "hw_reset failed ret = %d\n", ret);
158 return ret;
159 }
160
161 if (state == MEI_DEV_POWER_DOWN) {
162 dev_dbg(dev->dev, "powering down: end of reset\n");
132 return -ENODEV;
133 }
134
135 ret = mei_hw_reset(dev, interrupts_enabled);
136 /* fall through and remove the sw state even if hw reset has failed */
137
138 /* no need to clean up software state in case of power up */
139 if (state != MEI_DEV_INITIALIZING && state != MEI_DEV_POWER_UP)

--- 5 unchanged lines hidden (view full) ---

145
146 if (ret) {
147 dev_err(dev->dev, "hw_reset failed ret = %d\n", ret);
148 return ret;
149 }
150
151 if (state == MEI_DEV_POWER_DOWN) {
152 dev_dbg(dev->dev, "powering down: end of reset\n");
163 dev->dev_state = MEI_DEV_DISABLED;
153 mei_set_devstate(dev, MEI_DEV_DISABLED);
164 return 0;
165 }
166
167 ret = mei_hw_start(dev);
168 if (ret) {
169 dev_err(dev->dev, "hw_start failed ret = %d\n", ret);
170 return ret;
171 }
172
173 dev_dbg(dev->dev, "link is established start sending messages.\n");
174
154 return 0;
155 }
156
157 ret = mei_hw_start(dev);
158 if (ret) {
159 dev_err(dev->dev, "hw_start failed ret = %d\n", ret);
160 return ret;
161 }
162
163 dev_dbg(dev->dev, "link is established start sending messages.\n");
164
175 dev->dev_state = MEI_DEV_INIT_CLIENTS;
165 mei_set_devstate(dev, MEI_DEV_INIT_CLIENTS);
176 ret = mei_hbm_start_req(dev);
177 if (ret) {
178 dev_err(dev->dev, "hbm_start failed ret = %d\n", ret);
166 ret = mei_hbm_start_req(dev);
167 if (ret) {
168 dev_err(dev->dev, "hbm_start failed ret = %d\n", ret);
179 dev->dev_state = MEI_DEV_RESETTING;
169 mei_set_devstate(dev, MEI_DEV_RESETTING);
180 return ret;
181 }
182
183 return 0;
184}
185EXPORT_SYMBOL_GPL(mei_reset);
186
187/**

--- 13 unchanged lines hidden (view full) ---

201 mei_clear_interrupts(dev);
202
203 mei_hw_config(dev);
204
205 dev_dbg(dev->dev, "reset in start the mei device.\n");
206
207 dev->reset_count = 0;
208 do {
170 return ret;
171 }
172
173 return 0;
174}
175EXPORT_SYMBOL_GPL(mei_reset);
176
177/**

--- 13 unchanged lines hidden (view full) ---

191 mei_clear_interrupts(dev);
192
193 mei_hw_config(dev);
194
195 dev_dbg(dev->dev, "reset in start the mei device.\n");
196
197 dev->reset_count = 0;
198 do {
209 dev->dev_state = MEI_DEV_INITIALIZING;
199 mei_set_devstate(dev, MEI_DEV_INITIALIZING);
210 ret = mei_reset(dev);
211
212 if (ret == -ENODEV || dev->dev_state == MEI_DEV_DISABLED) {
213 dev_err(dev->dev, "reset failed ret = %d", ret);
214 goto err;
215 }
216 } while (ret);
217

--- 18 unchanged lines hidden (view full) ---

236 }
237
238 dev_dbg(dev->dev, "link layer has been established.\n");
239
240 mutex_unlock(&dev->device_lock);
241 return 0;
242err:
243 dev_err(dev->dev, "link layer initialization failed.\n");
200 ret = mei_reset(dev);
201
202 if (ret == -ENODEV || dev->dev_state == MEI_DEV_DISABLED) {
203 dev_err(dev->dev, "reset failed ret = %d", ret);
204 goto err;
205 }
206 } while (ret);
207

--- 18 unchanged lines hidden (view full) ---

226 }
227
228 dev_dbg(dev->dev, "link layer has been established.\n");
229
230 mutex_unlock(&dev->device_lock);
231 return 0;
232err:
233 dev_err(dev->dev, "link layer initialization failed.\n");
244 dev->dev_state = MEI_DEV_DISABLED;
234 mei_set_devstate(dev, MEI_DEV_DISABLED);
245 mutex_unlock(&dev->device_lock);
246 return -ENODEV;
247}
248EXPORT_SYMBOL_GPL(mei_start);
249
250/**
251 * mei_restart - restart device after suspend
252 *
253 * @dev: the device structure
254 *
255 * Return: 0 on success or -ENODEV if the restart hasn't succeeded
256 */
257int mei_restart(struct mei_device *dev)
258{
259 int err;
260
261 mutex_lock(&dev->device_lock);
262
235 mutex_unlock(&dev->device_lock);
236 return -ENODEV;
237}
238EXPORT_SYMBOL_GPL(mei_start);
239
240/**
241 * mei_restart - restart device after suspend
242 *
243 * @dev: the device structure
244 *
245 * Return: 0 on success or -ENODEV if the restart hasn't succeeded
246 */
247int mei_restart(struct mei_device *dev)
248{
249 int err;
250
251 mutex_lock(&dev->device_lock);
252
263 dev->dev_state = MEI_DEV_POWER_UP;
253 mei_set_devstate(dev, MEI_DEV_POWER_UP);
264 dev->reset_count = 0;
265
266 err = mei_reset(dev);
267
268 mutex_unlock(&dev->device_lock);
269
270 if (err == -ENODEV || dev->dev_state == MEI_DEV_DISABLED) {
271 dev_err(dev->dev, "device disabled = %d\n", err);

--- 34 unchanged lines hidden (view full) ---

306 schedule_work(&dev->reset_work);
307}
308
309void mei_stop(struct mei_device *dev)
310{
311 dev_dbg(dev->dev, "stopping the device.\n");
312
313 mutex_lock(&dev->device_lock);
254 dev->reset_count = 0;
255
256 err = mei_reset(dev);
257
258 mutex_unlock(&dev->device_lock);
259
260 if (err == -ENODEV || dev->dev_state == MEI_DEV_DISABLED) {
261 dev_err(dev->dev, "device disabled = %d\n", err);

--- 34 unchanged lines hidden (view full) ---

296 schedule_work(&dev->reset_work);
297}
298
299void mei_stop(struct mei_device *dev)
300{
301 dev_dbg(dev->dev, "stopping the device.\n");
302
303 mutex_lock(&dev->device_lock);
314 dev->dev_state = MEI_DEV_POWER_DOWN;
304 mei_set_devstate(dev, MEI_DEV_POWER_DOWN);
315 mutex_unlock(&dev->device_lock);
316 mei_cl_bus_remove_devices(dev);
317
318 mei_cancel_work(dev);
319
320 mei_clear_interrupts(dev);
321 mei_synchronize_irq(dev);
322
323 mutex_lock(&dev->device_lock);
324
325 mei_reset(dev);
326 /* move device to disabled state unconditionally */
305 mutex_unlock(&dev->device_lock);
306 mei_cl_bus_remove_devices(dev);
307
308 mei_cancel_work(dev);
309
310 mei_clear_interrupts(dev);
311 mei_synchronize_irq(dev);
312
313 mutex_lock(&dev->device_lock);
314
315 mei_reset(dev);
316 /* move device to disabled state unconditionally */
327 dev->dev_state = MEI_DEV_DISABLED;
317 mei_set_devstate(dev, MEI_DEV_DISABLED);
328
329 mutex_unlock(&dev->device_lock);
330}
331EXPORT_SYMBOL_GPL(mei_stop);
332
333/**
334 * mei_write_is_idle - check if the write queues are idle
335 *

--- 71 unchanged lines hidden ---
318
319 mutex_unlock(&dev->device_lock);
320}
321EXPORT_SYMBOL_GPL(mei_stop);
322
323/**
324 * mei_write_is_idle - check if the write queues are idle
325 *

--- 71 unchanged lines hidden ---