interrupt.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  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. dev_dbg(dev->dev, "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 = kzalloc(sizeof(*gsc_f2h), GFP_KERNEL);
  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_runtime_mark_last_busy(dev->dev);
  205. pm_request_autosuspend(dev->dev);
  206. }
  207. return 0;
  208. discard:
  209. if (cb)
  210. list_move_tail(&cb->list, cmpl_list);
  211. mei_irq_discard_msg(dev, mei_hdr, length);
  212. return 0;
  213. }
  214. /**
  215. * mei_cl_irq_disconnect_rsp - send disconnection response message
  216. *
  217. * @cl: client
  218. * @cb: callback block.
  219. * @cmpl_list: complete list.
  220. *
  221. * Return: 0, OK; otherwise, error.
  222. */
  223. static int mei_cl_irq_disconnect_rsp(struct mei_cl *cl, struct mei_cl_cb *cb,
  224. struct list_head *cmpl_list)
  225. {
  226. struct mei_device *dev = cl->dev;
  227. u32 msg_slots;
  228. int slots;
  229. int ret;
  230. msg_slots = mei_hbm2slots(sizeof(struct hbm_client_connect_response));
  231. slots = mei_hbuf_empty_slots(dev);
  232. if (slots < 0)
  233. return -EOVERFLOW;
  234. if ((u32)slots < msg_slots)
  235. return -EMSGSIZE;
  236. ret = mei_hbm_cl_disconnect_rsp(dev, cl);
  237. list_move_tail(&cb->list, cmpl_list);
  238. return ret;
  239. }
  240. /**
  241. * mei_cl_irq_read - processes client read related operation from the
  242. * interrupt thread context - request for flow control credits
  243. *
  244. * @cl: client
  245. * @cb: callback block.
  246. * @cmpl_list: complete list.
  247. *
  248. * Return: 0, OK; otherwise, error.
  249. */
  250. static int mei_cl_irq_read(struct mei_cl *cl, struct mei_cl_cb *cb,
  251. struct list_head *cmpl_list)
  252. {
  253. struct mei_device *dev = cl->dev;
  254. u32 msg_slots;
  255. int slots;
  256. int ret;
  257. if (!list_empty(&cl->rd_pending))
  258. return 0;
  259. msg_slots = mei_hbm2slots(sizeof(struct hbm_flow_control));
  260. slots = mei_hbuf_empty_slots(dev);
  261. if (slots < 0)
  262. return -EOVERFLOW;
  263. if ((u32)slots < msg_slots)
  264. return -EMSGSIZE;
  265. ret = mei_hbm_cl_flow_control_req(dev, cl);
  266. if (ret) {
  267. cl->status = ret;
  268. cb->buf_idx = 0;
  269. list_move_tail(&cb->list, cmpl_list);
  270. return ret;
  271. }
  272. pm_runtime_mark_last_busy(dev->dev);
  273. pm_request_autosuspend(dev->dev);
  274. list_move_tail(&cb->list, &cl->rd_pending);
  275. return 0;
  276. }
  277. static inline bool hdr_is_hbm(struct mei_msg_hdr *mei_hdr)
  278. {
  279. return mei_hdr->host_addr == 0 && mei_hdr->me_addr == 0;
  280. }
  281. static inline bool hdr_is_fixed(struct mei_msg_hdr *mei_hdr)
  282. {
  283. return mei_hdr->host_addr == 0 && mei_hdr->me_addr != 0;
  284. }
  285. static inline int hdr_is_valid(u32 msg_hdr)
  286. {
  287. struct mei_msg_hdr *mei_hdr;
  288. u32 expected_len = 0;
  289. mei_hdr = (struct mei_msg_hdr *)&msg_hdr;
  290. if (!msg_hdr || mei_hdr->reserved)
  291. return -EBADMSG;
  292. if (mei_hdr->dma_ring)
  293. expected_len += MEI_SLOT_SIZE;
  294. if (mei_hdr->extended)
  295. expected_len += MEI_SLOT_SIZE;
  296. if (mei_hdr->length < expected_len)
  297. return -EBADMSG;
  298. return 0;
  299. }
  300. /**
  301. * mei_irq_read_handler - bottom half read routine after ISR to
  302. * handle the read processing.
  303. *
  304. * @dev: the device structure
  305. * @cmpl_list: An instance of our list structure
  306. * @slots: slots to read.
  307. *
  308. * Return: 0 on success, <0 on failure.
  309. */
  310. int mei_irq_read_handler(struct mei_device *dev,
  311. struct list_head *cmpl_list, s32 *slots)
  312. {
  313. struct mei_msg_hdr *mei_hdr;
  314. struct mei_ext_meta_hdr *meta_hdr = NULL;
  315. struct mei_cl *cl;
  316. int ret;
  317. u32 hdr_size_left;
  318. u32 hdr_size_ext;
  319. int i;
  320. int ext_hdr_end;
  321. if (!dev->rd_msg_hdr[0]) {
  322. dev->rd_msg_hdr[0] = mei_read_hdr(dev);
  323. dev->rd_msg_hdr_count = 1;
  324. (*slots)--;
  325. dev_dbg(dev->dev, "slots =%08x.\n", *slots);
  326. ret = hdr_is_valid(dev->rd_msg_hdr[0]);
  327. if (ret) {
  328. dev_err(dev->dev, "corrupted message header 0x%08X\n",
  329. dev->rd_msg_hdr[0]);
  330. goto end;
  331. }
  332. }
  333. mei_hdr = (struct mei_msg_hdr *)dev->rd_msg_hdr;
  334. dev_dbg(dev->dev, MEI_HDR_FMT, MEI_HDR_PRM(mei_hdr));
  335. if (mei_slots2data(*slots) < mei_hdr->length) {
  336. dev_err(dev->dev, "less data available than length=%08x.\n",
  337. *slots);
  338. /* we can't read the message */
  339. ret = -ENODATA;
  340. goto end;
  341. }
  342. ext_hdr_end = 1;
  343. hdr_size_left = mei_hdr->length;
  344. if (mei_hdr->extended) {
  345. if (!dev->rd_msg_hdr[1]) {
  346. dev->rd_msg_hdr[1] = mei_read_hdr(dev);
  347. dev->rd_msg_hdr_count++;
  348. (*slots)--;
  349. dev_dbg(dev->dev, "extended header is %08x\n", dev->rd_msg_hdr[1]);
  350. }
  351. meta_hdr = ((struct mei_ext_meta_hdr *)&dev->rd_msg_hdr[1]);
  352. if (check_add_overflow((u32)sizeof(*meta_hdr),
  353. mei_slots2data(meta_hdr->size),
  354. &hdr_size_ext)) {
  355. dev_err(dev->dev, "extended message size too big %d\n",
  356. meta_hdr->size);
  357. return -EBADMSG;
  358. }
  359. if (hdr_size_left < hdr_size_ext) {
  360. dev_err(dev->dev, "corrupted message header len %d\n",
  361. mei_hdr->length);
  362. return -EBADMSG;
  363. }
  364. hdr_size_left -= hdr_size_ext;
  365. ext_hdr_end = meta_hdr->size + 2;
  366. for (i = dev->rd_msg_hdr_count; i < ext_hdr_end; i++) {
  367. dev->rd_msg_hdr[i] = mei_read_hdr(dev);
  368. dev_dbg(dev->dev, "extended header %d is %08x\n", i,
  369. dev->rd_msg_hdr[i]);
  370. dev->rd_msg_hdr_count++;
  371. (*slots)--;
  372. }
  373. }
  374. if (mei_hdr->dma_ring) {
  375. if (hdr_size_left != sizeof(dev->rd_msg_hdr[ext_hdr_end])) {
  376. dev_err(dev->dev, "corrupted message header len %d\n",
  377. mei_hdr->length);
  378. return -EBADMSG;
  379. }
  380. dev->rd_msg_hdr[ext_hdr_end] = mei_read_hdr(dev);
  381. dev->rd_msg_hdr_count++;
  382. (*slots)--;
  383. mei_hdr->length -= sizeof(dev->rd_msg_hdr[ext_hdr_end]);
  384. }
  385. /* HBM message */
  386. if (hdr_is_hbm(mei_hdr)) {
  387. ret = mei_hbm_dispatch(dev, mei_hdr);
  388. if (ret) {
  389. dev_dbg(dev->dev, "mei_hbm_dispatch failed ret = %d\n",
  390. ret);
  391. goto end;
  392. }
  393. goto reset_slots;
  394. }
  395. /* find recipient cl */
  396. list_for_each_entry(cl, &dev->file_list, link) {
  397. if (mei_cl_hbm_equal(cl, mei_hdr)) {
  398. cl_dbg(dev, cl, "got a message\n");
  399. ret = mei_cl_irq_read_msg(cl, mei_hdr, meta_hdr, cmpl_list);
  400. goto reset_slots;
  401. }
  402. }
  403. /* if no recipient cl was found we assume corrupted header */
  404. /* A message for not connected fixed address clients
  405. * should be silently discarded
  406. * On power down client may be force cleaned,
  407. * silently discard such messages
  408. */
  409. if (hdr_is_fixed(mei_hdr) ||
  410. dev->dev_state == MEI_DEV_POWER_DOWN) {
  411. mei_irq_discard_msg(dev, mei_hdr, mei_hdr->length);
  412. ret = 0;
  413. goto reset_slots;
  414. }
  415. dev_err(dev->dev, "no destination client found 0x%08X\n", dev->rd_msg_hdr[0]);
  416. ret = -EBADMSG;
  417. goto end;
  418. reset_slots:
  419. /* reset the number of slots and header */
  420. memset(dev->rd_msg_hdr, 0, sizeof(dev->rd_msg_hdr));
  421. dev->rd_msg_hdr_count = 0;
  422. *slots = mei_count_full_read_slots(dev);
  423. if (*slots == -EOVERFLOW) {
  424. /* overflow - reset */
  425. dev_err(dev->dev, "resetting due to slots overflow.\n");
  426. /* set the event since message has been read */
  427. ret = -ERANGE;
  428. goto end;
  429. }
  430. end:
  431. return ret;
  432. }
  433. EXPORT_SYMBOL_GPL(mei_irq_read_handler);
  434. /**
  435. * mei_irq_write_handler - dispatch write requests
  436. * after irq received
  437. *
  438. * @dev: the device structure
  439. * @cmpl_list: An instance of our list structure
  440. *
  441. * Return: 0 on success, <0 on failure.
  442. */
  443. int mei_irq_write_handler(struct mei_device *dev, struct list_head *cmpl_list)
  444. {
  445. struct mei_cl *cl;
  446. struct mei_cl_cb *cb, *next;
  447. s32 slots;
  448. int ret;
  449. if (!mei_hbuf_acquire(dev))
  450. return 0;
  451. slots = mei_hbuf_empty_slots(dev);
  452. if (slots < 0)
  453. return -EOVERFLOW;
  454. if (slots == 0)
  455. return -EMSGSIZE;
  456. /* complete all waiting for write CB */
  457. dev_dbg(dev->dev, "complete all waiting for write cb.\n");
  458. list_for_each_entry_safe(cb, next, &dev->write_waiting_list, list) {
  459. cl = cb->cl;
  460. cl->status = 0;
  461. cl_dbg(dev, cl, "MEI WRITE COMPLETE\n");
  462. cl->writing_state = MEI_WRITE_COMPLETE;
  463. list_move_tail(&cb->list, cmpl_list);
  464. }
  465. /* complete control write list CB */
  466. dev_dbg(dev->dev, "complete control write list cb.\n");
  467. list_for_each_entry_safe(cb, next, &dev->ctrl_wr_list, list) {
  468. cl = cb->cl;
  469. switch (cb->fop_type) {
  470. case MEI_FOP_DISCONNECT:
  471. /* send disconnect message */
  472. ret = mei_cl_irq_disconnect(cl, cb, cmpl_list);
  473. if (ret)
  474. return ret;
  475. break;
  476. case MEI_FOP_READ:
  477. /* send flow control message */
  478. ret = mei_cl_irq_read(cl, cb, cmpl_list);
  479. if (ret)
  480. return ret;
  481. break;
  482. case MEI_FOP_CONNECT:
  483. /* connect message */
  484. ret = mei_cl_irq_connect(cl, cb, cmpl_list);
  485. if (ret)
  486. return ret;
  487. break;
  488. case MEI_FOP_DISCONNECT_RSP:
  489. /* send disconnect resp */
  490. ret = mei_cl_irq_disconnect_rsp(cl, cb, cmpl_list);
  491. if (ret)
  492. return ret;
  493. break;
  494. case MEI_FOP_NOTIFY_START:
  495. case MEI_FOP_NOTIFY_STOP:
  496. ret = mei_cl_irq_notify(cl, cb, cmpl_list);
  497. if (ret)
  498. return ret;
  499. break;
  500. case MEI_FOP_DMA_MAP:
  501. ret = mei_cl_irq_dma_map(cl, cb, cmpl_list);
  502. if (ret)
  503. return ret;
  504. break;
  505. case MEI_FOP_DMA_UNMAP:
  506. ret = mei_cl_irq_dma_unmap(cl, cb, cmpl_list);
  507. if (ret)
  508. return ret;
  509. break;
  510. default:
  511. BUG();
  512. }
  513. }
  514. /* complete write list CB */
  515. dev_dbg(dev->dev, "complete write list cb.\n");
  516. list_for_each_entry_safe(cb, next, &dev->write_list, list) {
  517. cl = cb->cl;
  518. ret = mei_cl_irq_write(cl, cb, cmpl_list);
  519. if (ret)
  520. return ret;
  521. }
  522. return 0;
  523. }
  524. EXPORT_SYMBOL_GPL(mei_irq_write_handler);
  525. /**
  526. * mei_connect_timeout - connect/disconnect timeouts
  527. *
  528. * @cl: host client
  529. */
  530. static void mei_connect_timeout(struct mei_cl *cl)
  531. {
  532. struct mei_device *dev = cl->dev;
  533. if (cl->state == MEI_FILE_CONNECTING) {
  534. if (dev->hbm_f_dot_supported) {
  535. cl->state = MEI_FILE_DISCONNECT_REQUIRED;
  536. wake_up(&cl->wait);
  537. return;
  538. }
  539. }
  540. mei_reset(dev);
  541. }
  542. #define MEI_STALL_TIMER_FREQ (2 * HZ)
  543. /**
  544. * mei_schedule_stall_timer - re-arm stall_timer work
  545. *
  546. * @dev: the device structure
  547. *
  548. * Schedule stall timer
  549. */
  550. void mei_schedule_stall_timer(struct mei_device *dev)
  551. {
  552. schedule_delayed_work(&dev->timer_work, MEI_STALL_TIMER_FREQ);
  553. }
  554. /**
  555. * mei_timer - timer function.
  556. *
  557. * @work: pointer to the work_struct structure
  558. *
  559. */
  560. void mei_timer(struct work_struct *work)
  561. {
  562. struct mei_cl *cl;
  563. struct mei_device *dev = container_of(work,
  564. struct mei_device, timer_work.work);
  565. bool reschedule_timer = false;
  566. mutex_lock(&dev->device_lock);
  567. /* Catch interrupt stalls during HBM init handshake */
  568. if (dev->dev_state == MEI_DEV_INIT_CLIENTS &&
  569. dev->hbm_state != MEI_HBM_IDLE) {
  570. if (dev->init_clients_timer) {
  571. if (--dev->init_clients_timer == 0) {
  572. dev_err(dev->dev, "timer: init clients timeout hbm_state = %d.\n",
  573. dev->hbm_state);
  574. mei_reset(dev);
  575. goto out;
  576. }
  577. reschedule_timer = true;
  578. }
  579. }
  580. if (dev->dev_state != MEI_DEV_ENABLED)
  581. goto out;
  582. /*** connect/disconnect timeouts ***/
  583. list_for_each_entry(cl, &dev->file_list, link) {
  584. if (cl->timer_count) {
  585. if (--cl->timer_count == 0) {
  586. dev_err(dev->dev, "timer: connect/disconnect timeout.\n");
  587. mei_connect_timeout(cl);
  588. goto out;
  589. }
  590. reschedule_timer = true;
  591. }
  592. }
  593. out:
  594. if (dev->dev_state != MEI_DEV_DISABLED && reschedule_timer)
  595. mei_schedule_stall_timer(dev);
  596. mutex_unlock(&dev->device_lock);
  597. }