interrupt.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2003-2018, Intel Corporation. All rights reserved.
  4. * Intel Management Engine Interface (Intel MEI) Linux driver
  5. */
  6. #include <linux/export.h>
  7. #include <linux/kthread.h>
  8. #include <linux/interrupt.h>
  9. #include <linux/fs.h>
  10. #include <linux/jiffies.h>
  11. #include <linux/slab.h>
  12. #include <linux/pm_runtime.h>
  13. #include <linux/mei.h>
  14. #include "mei_dev.h"
  15. #include "hbm.h"
  16. #include "client.h"
  17. /**
  18. * mei_irq_compl_handler - dispatch complete handlers
  19. * for the completed callbacks
  20. *
  21. * @dev: mei device
  22. * @cmpl_list: list of completed cbs
  23. */
  24. void mei_irq_compl_handler(struct mei_device *dev, struct list_head *cmpl_list)
  25. {
  26. struct mei_cl_cb *cb, *next;
  27. struct mei_cl *cl;
  28. list_for_each_entry_safe(cb, next, cmpl_list, list) {
  29. cl = cb->cl;
  30. list_del_init(&cb->list);
  31. cl_dbg(dev, cl, "completing call back.\n");
  32. mei_cl_complete(cl, cb);
  33. }
  34. }
  35. EXPORT_SYMBOL_GPL(mei_irq_compl_handler);
  36. /**
  37. * mei_cl_hbm_equal - check if hbm is addressed to the client
  38. *
  39. * @cl: host client
  40. * @mei_hdr: header of mei client message
  41. *
  42. * Return: true if matches, false otherwise
  43. */
  44. static inline int mei_cl_hbm_equal(struct mei_cl *cl,
  45. struct mei_msg_hdr *mei_hdr)
  46. {
  47. return mei_cl_host_addr(cl) == mei_hdr->host_addr &&
  48. mei_cl_me_id(cl) == mei_hdr->me_addr;
  49. }
  50. /**
  51. * mei_irq_discard_msg - discard received message
  52. *
  53. * @dev: mei device
  54. * @hdr: message header
  55. * @discard_len: the length of the message to discard (excluding header)
  56. */
  57. static void mei_irq_discard_msg(struct mei_device *dev, struct mei_msg_hdr *hdr,
  58. size_t discard_len)
  59. {
  60. if (hdr->dma_ring) {
  61. mei_dma_ring_read(dev, NULL,
  62. hdr->extension[dev->rd_msg_hdr_count - 2]);
  63. discard_len = 0;
  64. }
  65. /*
  66. * no need to check for size as it is guaranteed
  67. * that length fits into rd_msg_buf
  68. */
  69. mei_read_slots(dev, dev->rd_msg_buf, discard_len);
  70. dev_dbg(&dev->dev, "discarding message " MEI_HDR_FMT "\n",
  71. MEI_HDR_PRM(hdr));
  72. }
  73. /**
  74. * mei_cl_irq_read_msg - process client message
  75. *
  76. * @cl: reading client
  77. * @mei_hdr: header of mei client message
  78. * @meta: extend meta header
  79. * @cmpl_list: completion list
  80. *
  81. * Return: always 0
  82. */
  83. static int mei_cl_irq_read_msg(struct mei_cl *cl,
  84. struct mei_msg_hdr *mei_hdr,
  85. struct mei_ext_meta_hdr *meta,
  86. struct list_head *cmpl_list)
  87. {
  88. struct mei_device *dev = cl->dev;
  89. struct mei_cl_cb *cb;
  90. struct mei_ext_hdr_vtag *vtag_hdr = NULL;
  91. struct mei_ext_hdr_gsc_f2h *gsc_f2h = NULL;
  92. size_t buf_sz;
  93. u32 length;
  94. u32 ext_len;
  95. length = mei_hdr->length;
  96. ext_len = 0;
  97. if (mei_hdr->extended) {
  98. ext_len = sizeof(*meta) + mei_slots2data(meta->size);
  99. length -= ext_len;
  100. }
  101. cb = list_first_entry_or_null(&cl->rd_pending, struct mei_cl_cb, list);
  102. if (!cb) {
  103. if (!mei_cl_is_fixed_address(cl)) {
  104. cl_err(dev, cl, "pending read cb not found\n");
  105. goto discard;
  106. }
  107. cb = mei_cl_alloc_cb(cl, mei_cl_mtu(cl), MEI_FOP_READ, cl->fp);
  108. if (!cb)
  109. goto discard;
  110. list_add_tail(&cb->list, &cl->rd_pending);
  111. }
  112. if (mei_hdr->extended) {
  113. struct mei_ext_hdr *ext = mei_ext_begin(meta);
  114. do {
  115. switch (ext->type) {
  116. case MEI_EXT_HDR_VTAG:
  117. vtag_hdr = (struct mei_ext_hdr_vtag *)ext;
  118. break;
  119. case MEI_EXT_HDR_GSC:
  120. gsc_f2h = (struct mei_ext_hdr_gsc_f2h *)ext;
  121. cb->ext_hdr = (struct mei_ext_hdr *) kzalloc_obj(*gsc_f2h);
  122. if (!cb->ext_hdr) {
  123. cb->status = -ENOMEM;
  124. goto discard;
  125. }
  126. break;
  127. case MEI_EXT_HDR_NONE:
  128. fallthrough;
  129. default:
  130. cl_err(dev, cl, "unknown extended header\n");
  131. cb->status = -EPROTO;
  132. break;
  133. }
  134. ext = mei_ext_next(ext);
  135. } while (!mei_ext_last(meta, ext));
  136. if (!vtag_hdr && !gsc_f2h) {
  137. cl_dbg(dev, cl, "no vtag or gsc found in extended header.\n");
  138. cb->status = -EPROTO;
  139. goto discard;
  140. }
  141. }
  142. if (vtag_hdr) {
  143. cl_dbg(dev, cl, "vtag: %d\n", vtag_hdr->vtag);
  144. if (cb->vtag && cb->vtag != vtag_hdr->vtag) {
  145. cl_err(dev, cl, "mismatched tag: %d != %d\n",
  146. cb->vtag, vtag_hdr->vtag);
  147. cb->status = -EPROTO;
  148. goto discard;
  149. }
  150. cb->vtag = vtag_hdr->vtag;
  151. }
  152. if (gsc_f2h) {
  153. u32 ext_hdr_len = mei_ext_hdr_len(&gsc_f2h->hdr);
  154. if (!dev->hbm_f_gsc_supported) {
  155. cl_err(dev, cl, "gsc extended header is not supported\n");
  156. cb->status = -EPROTO;
  157. goto discard;
  158. }
  159. if (length) {
  160. cl_err(dev, cl, "no data allowed in cb with gsc\n");
  161. cb->status = -EPROTO;
  162. goto discard;
  163. }
  164. if (ext_hdr_len > sizeof(*gsc_f2h)) {
  165. cl_err(dev, cl, "gsc extended header is too big %u\n", ext_hdr_len);
  166. cb->status = -EPROTO;
  167. goto discard;
  168. }
  169. memcpy(cb->ext_hdr, gsc_f2h, ext_hdr_len);
  170. }
  171. if (!mei_cl_is_connected(cl)) {
  172. cl_dbg(dev, cl, "not connected\n");
  173. cb->status = -ENODEV;
  174. goto discard;
  175. }
  176. if (mei_hdr->dma_ring)
  177. length = mei_hdr->extension[mei_data2slots(ext_len)];
  178. buf_sz = length + cb->buf_idx;
  179. /* catch for integer overflow */
  180. if (buf_sz < cb->buf_idx) {
  181. cl_err(dev, cl, "message is too big len %d idx %zu\n",
  182. length, cb->buf_idx);
  183. cb->status = -EMSGSIZE;
  184. goto discard;
  185. }
  186. if (cb->buf.size < buf_sz) {
  187. cl_dbg(dev, cl, "message overflow. size %zu len %d idx %zu\n",
  188. cb->buf.size, length, cb->buf_idx);
  189. cb->status = -EMSGSIZE;
  190. goto discard;
  191. }
  192. if (mei_hdr->dma_ring) {
  193. mei_dma_ring_read(dev, cb->buf.data + cb->buf_idx, length);
  194. /* for DMA read 0 length to generate interrupt to the device */
  195. mei_read_slots(dev, cb->buf.data + cb->buf_idx, 0);
  196. } else {
  197. mei_read_slots(dev, cb->buf.data + cb->buf_idx, length);
  198. }
  199. cb->buf_idx += length;
  200. if (mei_hdr->msg_complete) {
  201. cl_dbg(dev, cl, "completed read length = %zu\n", cb->buf_idx);
  202. list_move_tail(&cb->list, cmpl_list);
  203. } else {
  204. pm_request_autosuspend(dev->parent);
  205. }
  206. return 0;
  207. discard:
  208. if (cb)
  209. list_move_tail(&cb->list, cmpl_list);
  210. mei_irq_discard_msg(dev, mei_hdr, length);
  211. return 0;
  212. }
  213. /**
  214. * mei_cl_irq_disconnect_rsp - send disconnection response message
  215. *
  216. * @cl: client
  217. * @cb: callback block.
  218. * @cmpl_list: complete list.
  219. *
  220. * Return: 0, OK; otherwise, error.
  221. */
  222. static int mei_cl_irq_disconnect_rsp(struct mei_cl *cl, struct mei_cl_cb *cb,
  223. struct list_head *cmpl_list)
  224. {
  225. struct mei_device *dev = cl->dev;
  226. u32 msg_slots;
  227. int slots;
  228. int ret;
  229. msg_slots = mei_hbm2slots(sizeof(struct hbm_client_connect_response));
  230. slots = mei_hbuf_empty_slots(dev);
  231. if (slots < 0)
  232. return -EOVERFLOW;
  233. if ((u32)slots < msg_slots)
  234. return -EMSGSIZE;
  235. ret = mei_hbm_cl_disconnect_rsp(dev, cl);
  236. list_move_tail(&cb->list, cmpl_list);
  237. return ret;
  238. }
  239. /**
  240. * mei_cl_irq_read - processes client read related operation from the
  241. * interrupt thread context - request for flow control credits
  242. *
  243. * @cl: client
  244. * @cb: callback block.
  245. * @cmpl_list: complete list.
  246. *
  247. * Return: 0, OK; otherwise, error.
  248. */
  249. static int mei_cl_irq_read(struct mei_cl *cl, struct mei_cl_cb *cb,
  250. struct list_head *cmpl_list)
  251. {
  252. struct mei_device *dev = cl->dev;
  253. u32 msg_slots;
  254. int slots;
  255. int ret;
  256. if (!list_empty(&cl->rd_pending))
  257. return 0;
  258. msg_slots = mei_hbm2slots(sizeof(struct hbm_flow_control));
  259. slots = mei_hbuf_empty_slots(dev);
  260. if (slots < 0)
  261. return -EOVERFLOW;
  262. if ((u32)slots < msg_slots)
  263. return -EMSGSIZE;
  264. ret = mei_hbm_cl_flow_control_req(dev, cl);
  265. if (ret) {
  266. cl->status = ret;
  267. cb->buf_idx = 0;
  268. list_move_tail(&cb->list, cmpl_list);
  269. return ret;
  270. }
  271. pm_request_autosuspend(dev->parent);
  272. list_move_tail(&cb->list, &cl->rd_pending);
  273. return 0;
  274. }
  275. static inline bool hdr_is_hbm(struct mei_msg_hdr *mei_hdr)
  276. {
  277. return mei_hdr->host_addr == 0 && mei_hdr->me_addr == 0;
  278. }
  279. static inline bool hdr_is_fixed(struct mei_msg_hdr *mei_hdr)
  280. {
  281. return mei_hdr->host_addr == 0 && mei_hdr->me_addr != 0;
  282. }
  283. static inline int hdr_is_valid(u32 msg_hdr)
  284. {
  285. struct mei_msg_hdr *mei_hdr;
  286. u32 expected_len = 0;
  287. mei_hdr = (struct mei_msg_hdr *)&msg_hdr;
  288. if (!msg_hdr || mei_hdr->reserved)
  289. return -EBADMSG;
  290. if (mei_hdr->dma_ring)
  291. expected_len += MEI_SLOT_SIZE;
  292. if (mei_hdr->extended)
  293. expected_len += MEI_SLOT_SIZE;
  294. if (mei_hdr->length < expected_len)
  295. return -EBADMSG;
  296. return 0;
  297. }
  298. /**
  299. * mei_irq_read_handler - bottom half read routine after ISR to
  300. * handle the read processing.
  301. *
  302. * @dev: the device structure
  303. * @cmpl_list: An instance of our list structure
  304. * @slots: slots to read.
  305. *
  306. * Return: 0 on success, <0 on failure.
  307. */
  308. int mei_irq_read_handler(struct mei_device *dev,
  309. struct list_head *cmpl_list, s32 *slots)
  310. {
  311. struct mei_msg_hdr *mei_hdr;
  312. struct mei_ext_meta_hdr *meta_hdr = NULL;
  313. struct mei_cl *cl;
  314. int ret;
  315. u32 hdr_size_left;
  316. u32 hdr_size_ext;
  317. int i;
  318. int ext_hdr_end;
  319. if (!dev->rd_msg_hdr[0]) {
  320. dev->rd_msg_hdr[0] = mei_read_hdr(dev);
  321. dev->rd_msg_hdr_count = 1;
  322. (*slots)--;
  323. dev_dbg(&dev->dev, "slots =%08x.\n", *slots);
  324. ret = hdr_is_valid(dev->rd_msg_hdr[0]);
  325. if (ret) {
  326. dev_err(&dev->dev, "corrupted message header 0x%08X\n",
  327. dev->rd_msg_hdr[0]);
  328. goto end;
  329. }
  330. }
  331. mei_hdr = (struct mei_msg_hdr *)dev->rd_msg_hdr;
  332. dev_dbg(&dev->dev, MEI_HDR_FMT, MEI_HDR_PRM(mei_hdr));
  333. if (mei_slots2data(*slots) < mei_hdr->length) {
  334. dev_err(&dev->dev, "less data available than length=%08x.\n",
  335. *slots);
  336. /* we can't read the message */
  337. ret = -ENODATA;
  338. goto end;
  339. }
  340. ext_hdr_end = 1;
  341. hdr_size_left = mei_hdr->length;
  342. if (mei_hdr->extended) {
  343. if (!dev->rd_msg_hdr[1]) {
  344. dev->rd_msg_hdr[1] = mei_read_hdr(dev);
  345. dev->rd_msg_hdr_count++;
  346. (*slots)--;
  347. dev_dbg(&dev->dev, "extended header is %08x\n", dev->rd_msg_hdr[1]);
  348. }
  349. meta_hdr = ((struct mei_ext_meta_hdr *)&dev->rd_msg_hdr[1]);
  350. if (check_add_overflow((u32)sizeof(*meta_hdr),
  351. mei_slots2data(meta_hdr->size),
  352. &hdr_size_ext)) {
  353. dev_err(&dev->dev, "extended message size too big %d\n",
  354. meta_hdr->size);
  355. return -EBADMSG;
  356. }
  357. if (hdr_size_left < hdr_size_ext) {
  358. dev_err(&dev->dev, "corrupted message header len %d\n",
  359. mei_hdr->length);
  360. return -EBADMSG;
  361. }
  362. hdr_size_left -= hdr_size_ext;
  363. ext_hdr_end = meta_hdr->size + 2;
  364. for (i = dev->rd_msg_hdr_count; i < ext_hdr_end; i++) {
  365. dev->rd_msg_hdr[i] = mei_read_hdr(dev);
  366. dev_dbg(&dev->dev, "extended header %d is %08x\n", i,
  367. dev->rd_msg_hdr[i]);
  368. dev->rd_msg_hdr_count++;
  369. (*slots)--;
  370. }
  371. }
  372. if (mei_hdr->dma_ring) {
  373. if (hdr_size_left != sizeof(dev->rd_msg_hdr[ext_hdr_end])) {
  374. dev_err(&dev->dev, "corrupted message header len %d\n",
  375. mei_hdr->length);
  376. return -EBADMSG;
  377. }
  378. dev->rd_msg_hdr[ext_hdr_end] = mei_read_hdr(dev);
  379. dev->rd_msg_hdr_count++;
  380. (*slots)--;
  381. mei_hdr->length -= sizeof(dev->rd_msg_hdr[ext_hdr_end]);
  382. }
  383. /* HBM message */
  384. if (hdr_is_hbm(mei_hdr)) {
  385. ret = mei_hbm_dispatch(dev, mei_hdr);
  386. if (ret) {
  387. dev_dbg(&dev->dev, "mei_hbm_dispatch failed ret = %d\n", ret);
  388. goto end;
  389. }
  390. goto reset_slots;
  391. }
  392. /* find recipient cl */
  393. list_for_each_entry(cl, &dev->file_list, link) {
  394. if (mei_cl_hbm_equal(cl, mei_hdr)) {
  395. cl_dbg(dev, cl, "got a message\n");
  396. ret = mei_cl_irq_read_msg(cl, mei_hdr, meta_hdr, cmpl_list);
  397. goto reset_slots;
  398. }
  399. }
  400. /* if no recipient cl was found we assume corrupted header */
  401. /* A message for not connected fixed address clients
  402. * should be silently discarded
  403. * On power down client may be force cleaned,
  404. * silently discard such messages
  405. */
  406. if (hdr_is_fixed(mei_hdr) ||
  407. dev->dev_state == MEI_DEV_POWER_DOWN) {
  408. mei_irq_discard_msg(dev, mei_hdr, mei_hdr->length);
  409. ret = 0;
  410. goto reset_slots;
  411. }
  412. dev_err(&dev->dev, "no destination client found 0x%08X\n", dev->rd_msg_hdr[0]);
  413. ret = -EBADMSG;
  414. goto end;
  415. reset_slots:
  416. /* reset the number of slots and header */
  417. memset(dev->rd_msg_hdr, 0, sizeof(dev->rd_msg_hdr));
  418. dev->rd_msg_hdr_count = 0;
  419. *slots = mei_count_full_read_slots(dev);
  420. if (*slots == -EOVERFLOW) {
  421. /* overflow - reset */
  422. dev_err(&dev->dev, "resetting due to slots overflow.\n");
  423. /* set the event since message has been read */
  424. ret = -ERANGE;
  425. goto end;
  426. }
  427. end:
  428. return ret;
  429. }
  430. EXPORT_SYMBOL_GPL(mei_irq_read_handler);
  431. /**
  432. * mei_irq_write_handler - dispatch write requests
  433. * after irq received
  434. *
  435. * @dev: the device structure
  436. * @cmpl_list: An instance of our list structure
  437. *
  438. * Return: 0 on success, <0 on failure.
  439. */
  440. int mei_irq_write_handler(struct mei_device *dev, struct list_head *cmpl_list)
  441. {
  442. struct mei_cl *cl;
  443. struct mei_cl_cb *cb, *next;
  444. s32 slots;
  445. int ret;
  446. if (!mei_hbuf_acquire(dev))
  447. return 0;
  448. slots = mei_hbuf_empty_slots(dev);
  449. if (slots < 0)
  450. return -EOVERFLOW;
  451. if (slots == 0)
  452. return -EMSGSIZE;
  453. /* complete all waiting for write CB */
  454. dev_dbg(&dev->dev, "complete all waiting for write cb.\n");
  455. list_for_each_entry_safe(cb, next, &dev->write_waiting_list, list) {
  456. cl = cb->cl;
  457. cl->status = 0;
  458. cl_dbg(dev, cl, "MEI WRITE COMPLETE\n");
  459. cl->writing_state = MEI_WRITE_COMPLETE;
  460. list_move_tail(&cb->list, cmpl_list);
  461. }
  462. /* complete control write list CB */
  463. dev_dbg(&dev->dev, "complete control write list cb.\n");
  464. list_for_each_entry_safe(cb, next, &dev->ctrl_wr_list, list) {
  465. cl = cb->cl;
  466. switch (cb->fop_type) {
  467. case MEI_FOP_DISCONNECT:
  468. /* send disconnect message */
  469. ret = mei_cl_irq_disconnect(cl, cb, cmpl_list);
  470. if (ret)
  471. return ret;
  472. break;
  473. case MEI_FOP_READ:
  474. /* send flow control message */
  475. ret = mei_cl_irq_read(cl, cb, cmpl_list);
  476. if (ret)
  477. return ret;
  478. break;
  479. case MEI_FOP_CONNECT:
  480. /* connect message */
  481. ret = mei_cl_irq_connect(cl, cb, cmpl_list);
  482. if (ret)
  483. return ret;
  484. break;
  485. case MEI_FOP_DISCONNECT_RSP:
  486. /* send disconnect resp */
  487. ret = mei_cl_irq_disconnect_rsp(cl, cb, cmpl_list);
  488. if (ret)
  489. return ret;
  490. break;
  491. case MEI_FOP_NOTIFY_START:
  492. case MEI_FOP_NOTIFY_STOP:
  493. ret = mei_cl_irq_notify(cl, cb, cmpl_list);
  494. if (ret)
  495. return ret;
  496. break;
  497. case MEI_FOP_DMA_MAP:
  498. ret = mei_cl_irq_dma_map(cl, cb, cmpl_list);
  499. if (ret)
  500. return ret;
  501. break;
  502. case MEI_FOP_DMA_UNMAP:
  503. ret = mei_cl_irq_dma_unmap(cl, cb, cmpl_list);
  504. if (ret)
  505. return ret;
  506. break;
  507. default:
  508. BUG();
  509. }
  510. }
  511. /* complete write list CB */
  512. dev_dbg(&dev->dev, "complete write list cb.\n");
  513. list_for_each_entry_safe(cb, next, &dev->write_list, list) {
  514. cl = cb->cl;
  515. ret = mei_cl_irq_write(cl, cb, cmpl_list);
  516. if (ret)
  517. return ret;
  518. }
  519. return 0;
  520. }
  521. EXPORT_SYMBOL_GPL(mei_irq_write_handler);
  522. /**
  523. * mei_connect_timeout - connect/disconnect timeouts
  524. *
  525. * @cl: host client
  526. */
  527. static void mei_connect_timeout(struct mei_cl *cl)
  528. {
  529. struct mei_device *dev = cl->dev;
  530. if (cl->state == MEI_FILE_CONNECTING) {
  531. if (dev->hbm_f_dot_supported) {
  532. cl->state = MEI_FILE_DISCONNECT_REQUIRED;
  533. wake_up(&cl->wait);
  534. return;
  535. }
  536. }
  537. mei_reset(dev);
  538. }
  539. #define MEI_STALL_TIMER_FREQ (2 * HZ)
  540. /**
  541. * mei_schedule_stall_timer - re-arm stall_timer work
  542. *
  543. * @dev: the device structure
  544. *
  545. * Schedule stall timer
  546. */
  547. void mei_schedule_stall_timer(struct mei_device *dev)
  548. {
  549. schedule_delayed_work(&dev->timer_work, MEI_STALL_TIMER_FREQ);
  550. }
  551. /**
  552. * mei_timer - timer function.
  553. *
  554. * @work: pointer to the work_struct structure
  555. *
  556. */
  557. void mei_timer(struct work_struct *work)
  558. {
  559. struct mei_cl *cl;
  560. struct mei_device *dev = container_of(work,
  561. struct mei_device, timer_work.work);
  562. bool reschedule_timer = false;
  563. mutex_lock(&dev->device_lock);
  564. /* Catch interrupt stalls during HBM init handshake */
  565. if (dev->dev_state == MEI_DEV_INIT_CLIENTS &&
  566. dev->hbm_state != MEI_HBM_IDLE) {
  567. if (dev->init_clients_timer) {
  568. if (--dev->init_clients_timer == 0) {
  569. dev_err(&dev->dev, "timer: init clients timeout hbm_state = %d.\n",
  570. dev->hbm_state);
  571. mei_reset(dev);
  572. goto out;
  573. }
  574. reschedule_timer = true;
  575. }
  576. }
  577. if (dev->dev_state != MEI_DEV_ENABLED)
  578. goto out;
  579. /*** connect/disconnect timeouts ***/
  580. list_for_each_entry(cl, &dev->file_list, link) {
  581. if (cl->timer_count) {
  582. if (--cl->timer_count == 0) {
  583. dev_err(&dev->dev, "timer: connect/disconnect timeout.\n");
  584. mei_connect_timeout(cl);
  585. goto out;
  586. }
  587. reschedule_timer = true;
  588. }
  589. }
  590. out:
  591. if (dev->dev_state != MEI_DEV_DISABLED && reschedule_timer)
  592. mei_schedule_stall_timer(dev);
  593. mutex_unlock(&dev->device_lock);
  594. }