1 // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
2 /* Copyright (c) 2020, Mellanox Technologies inc. All rights reserved. */
3
4 #include "fw_reset.h"
5 #include "diag/fw_tracer.h"
6 #include "lib/tout.h"
7
8 enum {
9 MLX5_FW_RESET_FLAGS_RESET_REQUESTED,
10 MLX5_FW_RESET_FLAGS_NACK_RESET_REQUEST,
11 MLX5_FW_RESET_FLAGS_PENDING_COMP,
12 MLX5_FW_RESET_FLAGS_DROP_NEW_REQUESTS,
13 MLX5_FW_RESET_FLAGS_RELOAD_REQUIRED
14 };
15
16 struct mlx5_fw_reset {
17 struct mlx5_core_dev *dev;
18 struct mlx5_nb nb;
19 struct workqueue_struct *wq;
20 struct work_struct fw_live_patch_work;
21 struct work_struct reset_request_work;
22 struct work_struct reset_reload_work;
23 struct work_struct reset_now_work;
24 struct work_struct reset_abort_work;
25 unsigned long reset_flags;
26 struct timer_list timer;
27 struct completion done;
28 int ret;
29 };
30
mlx5_fw_reset_enable_remote_dev_reset_set(struct mlx5_core_dev * dev,bool enable)31 void mlx5_fw_reset_enable_remote_dev_reset_set(struct mlx5_core_dev *dev, bool enable)
32 {
33 struct mlx5_fw_reset *fw_reset = dev->priv.fw_reset;
34
35 if (enable)
36 clear_bit(MLX5_FW_RESET_FLAGS_NACK_RESET_REQUEST, &fw_reset->reset_flags);
37 else
38 set_bit(MLX5_FW_RESET_FLAGS_NACK_RESET_REQUEST, &fw_reset->reset_flags);
39 }
40
mlx5_fw_reset_enable_remote_dev_reset_get(struct mlx5_core_dev * dev)41 bool mlx5_fw_reset_enable_remote_dev_reset_get(struct mlx5_core_dev *dev)
42 {
43 struct mlx5_fw_reset *fw_reset = dev->priv.fw_reset;
44
45 return !test_bit(MLX5_FW_RESET_FLAGS_NACK_RESET_REQUEST, &fw_reset->reset_flags);
46 }
47
mlx5_reg_mfrl_set(struct mlx5_core_dev * dev,u8 reset_level,u8 reset_type_sel,u8 sync_resp,bool sync_start)48 static int mlx5_reg_mfrl_set(struct mlx5_core_dev *dev, u8 reset_level,
49 u8 reset_type_sel, u8 sync_resp, bool sync_start)
50 {
51 u32 out[MLX5_ST_SZ_DW(mfrl_reg)] = {};
52 u32 in[MLX5_ST_SZ_DW(mfrl_reg)] = {};
53
54 MLX5_SET(mfrl_reg, in, reset_level, reset_level);
55 MLX5_SET(mfrl_reg, in, rst_type_sel, reset_type_sel);
56 MLX5_SET(mfrl_reg, in, pci_sync_for_fw_update_resp, sync_resp);
57 MLX5_SET(mfrl_reg, in, pci_sync_for_fw_update_start, sync_start);
58
59 return mlx5_core_access_reg(dev, in, sizeof(in), out, sizeof(out), MLX5_REG_MFRL, 0, 1);
60 }
61
mlx5_reg_mfrl_query(struct mlx5_core_dev * dev,u8 * reset_level,u8 * reset_type,u8 * reset_state)62 static int mlx5_reg_mfrl_query(struct mlx5_core_dev *dev, u8 *reset_level,
63 u8 *reset_type, u8 *reset_state)
64 {
65 u32 out[MLX5_ST_SZ_DW(mfrl_reg)] = {};
66 u32 in[MLX5_ST_SZ_DW(mfrl_reg)] = {};
67 int err;
68
69 err = mlx5_core_access_reg(dev, in, sizeof(in), out, sizeof(out), MLX5_REG_MFRL, 0, 0);
70 if (err)
71 return err;
72
73 if (reset_level)
74 *reset_level = MLX5_GET(mfrl_reg, out, reset_level);
75 if (reset_type)
76 *reset_type = MLX5_GET(mfrl_reg, out, reset_type);
77 if (reset_state)
78 *reset_state = MLX5_GET(mfrl_reg, out, reset_state);
79
80 return 0;
81 }
82
mlx5_fw_reset_query(struct mlx5_core_dev * dev,u8 * reset_level,u8 * reset_type)83 int mlx5_fw_reset_query(struct mlx5_core_dev *dev, u8 *reset_level, u8 *reset_type)
84 {
85 return mlx5_reg_mfrl_query(dev, reset_level, reset_type, NULL);
86 }
87
mlx5_fw_reset_get_reset_state_err(struct mlx5_core_dev * dev,struct netlink_ext_ack * extack)88 static int mlx5_fw_reset_get_reset_state_err(struct mlx5_core_dev *dev,
89 struct netlink_ext_ack *extack)
90 {
91 u8 reset_state;
92
93 if (mlx5_reg_mfrl_query(dev, NULL, NULL, &reset_state))
94 goto out;
95
96 switch (reset_state) {
97 case MLX5_MFRL_REG_RESET_STATE_IN_NEGOTIATION:
98 case MLX5_MFRL_REG_RESET_STATE_RESET_IN_PROGRESS:
99 NL_SET_ERR_MSG_MOD(extack, "Sync reset was already triggered");
100 return -EBUSY;
101 case MLX5_MFRL_REG_RESET_STATE_TIMEOUT:
102 NL_SET_ERR_MSG_MOD(extack, "Sync reset got timeout");
103 return -ETIMEDOUT;
104 case MLX5_MFRL_REG_RESET_STATE_NACK:
105 NL_SET_ERR_MSG_MOD(extack, "One of the hosts disabled reset");
106 return -EPERM;
107 }
108
109 out:
110 NL_SET_ERR_MSG_MOD(extack, "Sync reset failed");
111 return -EIO;
112 }
113
mlx5_fw_reset_set_reset_sync(struct mlx5_core_dev * dev,u8 reset_type_sel,struct netlink_ext_ack * extack)114 int mlx5_fw_reset_set_reset_sync(struct mlx5_core_dev *dev, u8 reset_type_sel,
115 struct netlink_ext_ack *extack)
116 {
117 struct mlx5_fw_reset *fw_reset = dev->priv.fw_reset;
118 u32 out[MLX5_ST_SZ_DW(mfrl_reg)] = {};
119 u32 in[MLX5_ST_SZ_DW(mfrl_reg)] = {};
120 int err;
121
122 set_bit(MLX5_FW_RESET_FLAGS_PENDING_COMP, &fw_reset->reset_flags);
123
124 MLX5_SET(mfrl_reg, in, reset_level, MLX5_MFRL_REG_RESET_LEVEL3);
125 MLX5_SET(mfrl_reg, in, rst_type_sel, reset_type_sel);
126 MLX5_SET(mfrl_reg, in, pci_sync_for_fw_update_start, 1);
127 err = mlx5_access_reg(dev, in, sizeof(in), out, sizeof(out),
128 MLX5_REG_MFRL, 0, 1, false);
129 if (!err)
130 return 0;
131
132 clear_bit(MLX5_FW_RESET_FLAGS_PENDING_COMP, &fw_reset->reset_flags);
133 if (err == -EREMOTEIO && MLX5_CAP_MCAM_FEATURE(dev, reset_state))
134 return mlx5_fw_reset_get_reset_state_err(dev, extack);
135
136 NL_SET_ERR_MSG_MOD(extack, "Sync reset command failed");
137 return mlx5_cmd_check(dev, err, in, out);
138 }
139
mlx5_fw_reset_set_live_patch(struct mlx5_core_dev * dev)140 int mlx5_fw_reset_set_live_patch(struct mlx5_core_dev *dev)
141 {
142 return mlx5_reg_mfrl_set(dev, MLX5_MFRL_REG_RESET_LEVEL0, 0, 0, false);
143 }
144
mlx5_fw_reset_complete_reload(struct mlx5_core_dev * dev)145 static void mlx5_fw_reset_complete_reload(struct mlx5_core_dev *dev)
146 {
147 struct mlx5_fw_reset *fw_reset = dev->priv.fw_reset;
148
149 /* if this is the driver that initiated the fw reset, devlink completed the reload */
150 if (test_bit(MLX5_FW_RESET_FLAGS_PENDING_COMP, &fw_reset->reset_flags)) {
151 complete(&fw_reset->done);
152 } else {
153 mlx5_unload_one(dev, false);
154 if (mlx5_health_wait_pci_up(dev))
155 mlx5_core_err(dev, "reset reload flow aborted, PCI reads still not working\n");
156 else
157 mlx5_load_one(dev, true);
158 devlink_remote_reload_actions_performed(priv_to_devlink(dev), 0,
159 BIT(DEVLINK_RELOAD_ACTION_DRIVER_REINIT) |
160 BIT(DEVLINK_RELOAD_ACTION_FW_ACTIVATE));
161 }
162 }
163
mlx5_stop_sync_reset_poll(struct mlx5_core_dev * dev)164 static void mlx5_stop_sync_reset_poll(struct mlx5_core_dev *dev)
165 {
166 struct mlx5_fw_reset *fw_reset = dev->priv.fw_reset;
167
168 del_timer_sync(&fw_reset->timer);
169 }
170
mlx5_sync_reset_clear_reset_requested(struct mlx5_core_dev * dev,bool poll_health)171 static int mlx5_sync_reset_clear_reset_requested(struct mlx5_core_dev *dev, bool poll_health)
172 {
173 struct mlx5_fw_reset *fw_reset = dev->priv.fw_reset;
174
175 if (!test_and_clear_bit(MLX5_FW_RESET_FLAGS_RESET_REQUESTED, &fw_reset->reset_flags)) {
176 mlx5_core_warn(dev, "Reset request was already cleared\n");
177 return -EALREADY;
178 }
179
180 mlx5_stop_sync_reset_poll(dev);
181 if (poll_health)
182 mlx5_start_health_poll(dev);
183 return 0;
184 }
185
mlx5_sync_reset_reload_work(struct work_struct * work)186 static void mlx5_sync_reset_reload_work(struct work_struct *work)
187 {
188 struct mlx5_fw_reset *fw_reset = container_of(work, struct mlx5_fw_reset,
189 reset_reload_work);
190 struct mlx5_core_dev *dev = fw_reset->dev;
191
192 mlx5_sync_reset_clear_reset_requested(dev, false);
193 mlx5_enter_error_state(dev, true);
194 mlx5_fw_reset_complete_reload(dev);
195 }
196
197 #define MLX5_RESET_POLL_INTERVAL (HZ / 10)
poll_sync_reset(struct timer_list * t)198 static void poll_sync_reset(struct timer_list *t)
199 {
200 struct mlx5_fw_reset *fw_reset = from_timer(fw_reset, t, timer);
201 struct mlx5_core_dev *dev = fw_reset->dev;
202 u32 fatal_error;
203
204 if (!test_bit(MLX5_FW_RESET_FLAGS_RESET_REQUESTED, &fw_reset->reset_flags))
205 return;
206
207 fatal_error = mlx5_health_check_fatal_sensors(dev);
208
209 if (fatal_error) {
210 mlx5_core_warn(dev, "Got Device Reset\n");
211 if (!test_bit(MLX5_FW_RESET_FLAGS_DROP_NEW_REQUESTS, &fw_reset->reset_flags))
212 queue_work(fw_reset->wq, &fw_reset->reset_reload_work);
213 else
214 mlx5_core_err(dev, "Device is being removed, Drop new reset work\n");
215 return;
216 }
217
218 mod_timer(&fw_reset->timer, round_jiffies(jiffies + MLX5_RESET_POLL_INTERVAL));
219 }
220
mlx5_start_sync_reset_poll(struct mlx5_core_dev * dev)221 static void mlx5_start_sync_reset_poll(struct mlx5_core_dev *dev)
222 {
223 struct mlx5_fw_reset *fw_reset = dev->priv.fw_reset;
224
225 timer_setup(&fw_reset->timer, poll_sync_reset, 0);
226 fw_reset->timer.expires = round_jiffies(jiffies + MLX5_RESET_POLL_INTERVAL);
227 add_timer(&fw_reset->timer);
228 }
229
mlx5_fw_reset_set_reset_sync_ack(struct mlx5_core_dev * dev)230 static int mlx5_fw_reset_set_reset_sync_ack(struct mlx5_core_dev *dev)
231 {
232 return mlx5_reg_mfrl_set(dev, MLX5_MFRL_REG_RESET_LEVEL3, 0, 1, false);
233 }
234
mlx5_fw_reset_set_reset_sync_nack(struct mlx5_core_dev * dev)235 static int mlx5_fw_reset_set_reset_sync_nack(struct mlx5_core_dev *dev)
236 {
237 return mlx5_reg_mfrl_set(dev, MLX5_MFRL_REG_RESET_LEVEL3, 0, 2, false);
238 }
239
mlx5_sync_reset_set_reset_requested(struct mlx5_core_dev * dev)240 static int mlx5_sync_reset_set_reset_requested(struct mlx5_core_dev *dev)
241 {
242 struct mlx5_fw_reset *fw_reset = dev->priv.fw_reset;
243
244 if (test_and_set_bit(MLX5_FW_RESET_FLAGS_RESET_REQUESTED, &fw_reset->reset_flags)) {
245 mlx5_core_warn(dev, "Reset request was already set\n");
246 return -EALREADY;
247 }
248 mlx5_stop_health_poll(dev, true);
249 mlx5_start_sync_reset_poll(dev);
250 return 0;
251 }
252
mlx5_fw_live_patch_event(struct work_struct * work)253 static void mlx5_fw_live_patch_event(struct work_struct *work)
254 {
255 struct mlx5_fw_reset *fw_reset = container_of(work, struct mlx5_fw_reset,
256 fw_live_patch_work);
257 struct mlx5_core_dev *dev = fw_reset->dev;
258
259 mlx5_core_info(dev, "Live patch updated firmware version: %d.%d.%d\n", fw_rev_maj(dev),
260 fw_rev_min(dev), fw_rev_sub(dev));
261
262 if (mlx5_fw_tracer_reload(dev->tracer))
263 mlx5_core_err(dev, "Failed to reload FW tracer\n");
264 }
265
mlx5_sync_reset_request_event(struct work_struct * work)266 static void mlx5_sync_reset_request_event(struct work_struct *work)
267 {
268 struct mlx5_fw_reset *fw_reset = container_of(work, struct mlx5_fw_reset,
269 reset_request_work);
270 struct mlx5_core_dev *dev = fw_reset->dev;
271 int err;
272
273 if (test_bit(MLX5_FW_RESET_FLAGS_NACK_RESET_REQUEST, &fw_reset->reset_flags)) {
274 err = mlx5_fw_reset_set_reset_sync_nack(dev);
275 mlx5_core_warn(dev, "PCI Sync FW Update Reset Nack %s",
276 err ? "Failed" : "Sent");
277 return;
278 }
279 if (mlx5_sync_reset_set_reset_requested(dev))
280 return;
281
282 err = mlx5_fw_reset_set_reset_sync_ack(dev);
283 if (err)
284 mlx5_core_warn(dev, "PCI Sync FW Update Reset Ack Failed. Error code: %d\n", err);
285 else
286 mlx5_core_warn(dev, "PCI Sync FW Update Reset Ack. Device reset is expected.\n");
287 }
288
mlx5_pci_link_toggle(struct mlx5_core_dev * dev)289 static int mlx5_pci_link_toggle(struct mlx5_core_dev *dev)
290 {
291 struct pci_bus *bridge_bus = dev->pdev->bus;
292 struct pci_dev *bridge = bridge_bus->self;
293 u16 reg16, dev_id, sdev_id;
294 unsigned long timeout;
295 struct pci_dev *sdev;
296 int cap, err;
297 u32 reg32;
298
299 /* Check that all functions under the pci bridge are PFs of
300 * this device otherwise fail this function.
301 */
302 err = pci_read_config_word(dev->pdev, PCI_DEVICE_ID, &dev_id);
303 if (err)
304 return err;
305 list_for_each_entry(sdev, &bridge_bus->devices, bus_list) {
306 err = pci_read_config_word(sdev, PCI_DEVICE_ID, &sdev_id);
307 if (err)
308 return err;
309 if (sdev_id != dev_id)
310 return -EPERM;
311 }
312
313 cap = pci_find_capability(bridge, PCI_CAP_ID_EXP);
314 if (!cap)
315 return -EOPNOTSUPP;
316
317 list_for_each_entry(sdev, &bridge_bus->devices, bus_list) {
318 pci_save_state(sdev);
319 pci_cfg_access_lock(sdev);
320 }
321 /* PCI link toggle */
322 err = pcie_capability_set_word(bridge, PCI_EXP_LNKCTL, PCI_EXP_LNKCTL_LD);
323 if (err)
324 return err;
325 msleep(500);
326 err = pcie_capability_clear_word(bridge, PCI_EXP_LNKCTL, PCI_EXP_LNKCTL_LD);
327 if (err)
328 return err;
329
330 /* Check link */
331 err = pci_read_config_dword(bridge, cap + PCI_EXP_LNKCAP, ®32);
332 if (err)
333 return err;
334 if (!(reg32 & PCI_EXP_LNKCAP_DLLLARC)) {
335 mlx5_core_warn(dev, "No PCI link reporting capability (0x%08x)\n", reg32);
336 msleep(1000);
337 goto restore;
338 }
339
340 timeout = jiffies + msecs_to_jiffies(mlx5_tout_ms(dev, PCI_TOGGLE));
341 do {
342 err = pci_read_config_word(bridge, cap + PCI_EXP_LNKSTA, ®16);
343 if (err)
344 return err;
345 if (reg16 & PCI_EXP_LNKSTA_DLLLA)
346 break;
347 msleep(20);
348 } while (!time_after(jiffies, timeout));
349
350 if (reg16 & PCI_EXP_LNKSTA_DLLLA) {
351 mlx5_core_info(dev, "PCI Link up\n");
352 } else {
353 mlx5_core_err(dev, "PCI link not ready (0x%04x) after %llu ms\n",
354 reg16, mlx5_tout_ms(dev, PCI_TOGGLE));
355 err = -ETIMEDOUT;
356 }
357
358 do {
359 err = pci_read_config_word(dev->pdev, PCI_DEVICE_ID, ®16);
360 if (err)
361 return err;
362 if (reg16 == dev_id)
363 break;
364 msleep(20);
365 } while (!time_after(jiffies, timeout));
366
367 if (reg16 == dev_id) {
368 mlx5_core_info(dev, "Firmware responds to PCI config cycles again\n");
369 } else {
370 mlx5_core_err(dev, "Firmware is not responsive (0x%04x) after %llu ms\n",
371 reg16, mlx5_tout_ms(dev, PCI_TOGGLE));
372 err = -ETIMEDOUT;
373 }
374
375 restore:
376 list_for_each_entry(sdev, &bridge_bus->devices, bus_list) {
377 pci_cfg_access_unlock(sdev);
378 pci_restore_state(sdev);
379 }
380
381 return err;
382 }
383
mlx5_sync_reset_now_event(struct work_struct * work)384 static void mlx5_sync_reset_now_event(struct work_struct *work)
385 {
386 struct mlx5_fw_reset *fw_reset = container_of(work, struct mlx5_fw_reset,
387 reset_now_work);
388 struct mlx5_core_dev *dev = fw_reset->dev;
389 int err;
390
391 if (mlx5_sync_reset_clear_reset_requested(dev, false))
392 return;
393
394 mlx5_core_warn(dev, "Sync Reset now. Device is going to reset.\n");
395
396 err = mlx5_cmd_fast_teardown_hca(dev);
397 if (err) {
398 mlx5_core_warn(dev, "Fast teardown failed, no reset done, err %d\n", err);
399 goto done;
400 }
401
402 err = mlx5_pci_link_toggle(dev);
403 if (err) {
404 mlx5_core_warn(dev, "mlx5_pci_link_toggle failed, no reset done, err %d\n", err);
405 set_bit(MLX5_FW_RESET_FLAGS_RELOAD_REQUIRED, &fw_reset->reset_flags);
406 }
407
408 mlx5_enter_error_state(dev, true);
409 done:
410 fw_reset->ret = err;
411 mlx5_fw_reset_complete_reload(dev);
412 }
413
mlx5_sync_reset_abort_event(struct work_struct * work)414 static void mlx5_sync_reset_abort_event(struct work_struct *work)
415 {
416 struct mlx5_fw_reset *fw_reset = container_of(work, struct mlx5_fw_reset,
417 reset_abort_work);
418 struct mlx5_core_dev *dev = fw_reset->dev;
419
420 if (mlx5_sync_reset_clear_reset_requested(dev, true))
421 return;
422 mlx5_core_warn(dev, "PCI Sync FW Update Reset Aborted.\n");
423 }
424
mlx5_sync_reset_events_handle(struct mlx5_fw_reset * fw_reset,struct mlx5_eqe * eqe)425 static void mlx5_sync_reset_events_handle(struct mlx5_fw_reset *fw_reset, struct mlx5_eqe *eqe)
426 {
427 struct mlx5_eqe_sync_fw_update *sync_fw_update_eqe;
428 u8 sync_event_rst_type;
429
430 sync_fw_update_eqe = &eqe->data.sync_fw_update;
431 sync_event_rst_type = sync_fw_update_eqe->sync_rst_state & SYNC_RST_STATE_MASK;
432 switch (sync_event_rst_type) {
433 case MLX5_SYNC_RST_STATE_RESET_REQUEST:
434 queue_work(fw_reset->wq, &fw_reset->reset_request_work);
435 break;
436 case MLX5_SYNC_RST_STATE_RESET_NOW:
437 queue_work(fw_reset->wq, &fw_reset->reset_now_work);
438 break;
439 case MLX5_SYNC_RST_STATE_RESET_ABORT:
440 queue_work(fw_reset->wq, &fw_reset->reset_abort_work);
441 break;
442 }
443 }
444
fw_reset_event_notifier(struct notifier_block * nb,unsigned long action,void * data)445 static int fw_reset_event_notifier(struct notifier_block *nb, unsigned long action, void *data)
446 {
447 struct mlx5_fw_reset *fw_reset = mlx5_nb_cof(nb, struct mlx5_fw_reset, nb);
448 struct mlx5_eqe *eqe = data;
449
450 if (test_bit(MLX5_FW_RESET_FLAGS_DROP_NEW_REQUESTS, &fw_reset->reset_flags))
451 return NOTIFY_DONE;
452
453 switch (eqe->sub_type) {
454 case MLX5_GENERAL_SUBTYPE_FW_LIVE_PATCH_EVENT:
455 queue_work(fw_reset->wq, &fw_reset->fw_live_patch_work);
456 break;
457 case MLX5_GENERAL_SUBTYPE_PCI_SYNC_FOR_FW_UPDATE_EVENT:
458 mlx5_sync_reset_events_handle(fw_reset, eqe);
459 break;
460 default:
461 return NOTIFY_DONE;
462 }
463
464 return NOTIFY_OK;
465 }
466
mlx5_fw_reset_wait_reset_done(struct mlx5_core_dev * dev)467 int mlx5_fw_reset_wait_reset_done(struct mlx5_core_dev *dev)
468 {
469 unsigned long pci_sync_update_timeout = mlx5_tout_ms(dev, PCI_SYNC_UPDATE);
470 unsigned long timeout = msecs_to_jiffies(pci_sync_update_timeout);
471 struct mlx5_fw_reset *fw_reset = dev->priv.fw_reset;
472 int err;
473
474 if (!wait_for_completion_timeout(&fw_reset->done, timeout)) {
475 mlx5_core_warn(dev, "FW sync reset timeout after %lu seconds\n",
476 pci_sync_update_timeout / 1000);
477 err = -ETIMEDOUT;
478 goto out;
479 }
480 err = fw_reset->ret;
481 if (test_and_clear_bit(MLX5_FW_RESET_FLAGS_RELOAD_REQUIRED, &fw_reset->reset_flags)) {
482 mlx5_unload_one_devl_locked(dev, false);
483 mlx5_load_one_devl_locked(dev, true);
484 }
485 out:
486 clear_bit(MLX5_FW_RESET_FLAGS_PENDING_COMP, &fw_reset->reset_flags);
487 return err;
488 }
489
mlx5_fw_reset_events_start(struct mlx5_core_dev * dev)490 void mlx5_fw_reset_events_start(struct mlx5_core_dev *dev)
491 {
492 struct mlx5_fw_reset *fw_reset = dev->priv.fw_reset;
493
494 MLX5_NB_INIT(&fw_reset->nb, fw_reset_event_notifier, GENERAL_EVENT);
495 mlx5_eq_notifier_register(dev, &fw_reset->nb);
496 }
497
mlx5_fw_reset_events_stop(struct mlx5_core_dev * dev)498 void mlx5_fw_reset_events_stop(struct mlx5_core_dev *dev)
499 {
500 mlx5_eq_notifier_unregister(dev, &dev->priv.fw_reset->nb);
501 }
502
mlx5_drain_fw_reset(struct mlx5_core_dev * dev)503 void mlx5_drain_fw_reset(struct mlx5_core_dev *dev)
504 {
505 struct mlx5_fw_reset *fw_reset = dev->priv.fw_reset;
506
507 set_bit(MLX5_FW_RESET_FLAGS_DROP_NEW_REQUESTS, &fw_reset->reset_flags);
508 cancel_work_sync(&fw_reset->fw_live_patch_work);
509 cancel_work_sync(&fw_reset->reset_request_work);
510 cancel_work_sync(&fw_reset->reset_reload_work);
511 cancel_work_sync(&fw_reset->reset_now_work);
512 cancel_work_sync(&fw_reset->reset_abort_work);
513 }
514
mlx5_fw_reset_init(struct mlx5_core_dev * dev)515 int mlx5_fw_reset_init(struct mlx5_core_dev *dev)
516 {
517 struct mlx5_fw_reset *fw_reset = kzalloc(sizeof(*fw_reset), GFP_KERNEL);
518
519 if (!fw_reset)
520 return -ENOMEM;
521 fw_reset->wq = create_singlethread_workqueue("mlx5_fw_reset_events");
522 if (!fw_reset->wq) {
523 kfree(fw_reset);
524 return -ENOMEM;
525 }
526
527 fw_reset->dev = dev;
528 dev->priv.fw_reset = fw_reset;
529
530 INIT_WORK(&fw_reset->fw_live_patch_work, mlx5_fw_live_patch_event);
531 INIT_WORK(&fw_reset->reset_request_work, mlx5_sync_reset_request_event);
532 INIT_WORK(&fw_reset->reset_reload_work, mlx5_sync_reset_reload_work);
533 INIT_WORK(&fw_reset->reset_now_work, mlx5_sync_reset_now_event);
534 INIT_WORK(&fw_reset->reset_abort_work, mlx5_sync_reset_abort_event);
535
536 init_completion(&fw_reset->done);
537 return 0;
538 }
539
mlx5_fw_reset_cleanup(struct mlx5_core_dev * dev)540 void mlx5_fw_reset_cleanup(struct mlx5_core_dev *dev)
541 {
542 struct mlx5_fw_reset *fw_reset = dev->priv.fw_reset;
543
544 destroy_workqueue(fw_reset->wq);
545 kfree(dev->priv.fw_reset);
546 }
547