interrupt.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  1. /*
  2. *
  3. * 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. #include <linux/export.h>
  17. #include <linux/pci.h>
  18. #include <linux/kthread.h>
  19. #include <linux/interrupt.h>
  20. #include <linux/fs.h>
  21. #include <linux/jiffies.h>
  22. #include <linux/mei.h>
  23. #include "mei_dev.h"
  24. #include "hbm.h"
  25. #include "hw-me.h"
  26. #include "client.h"
  27. /**
  28. * mei_cl_complete_handler - processes completed operation for a client
  29. *
  30. * @cl: private data of the file object.
  31. * @cb: callback block.
  32. */
  33. static void mei_cl_complete_handler(struct mei_cl *cl, struct mei_cl_cb *cb)
  34. {
  35. if (cb->fop_type == MEI_FOP_WRITE) {
  36. mei_io_cb_free(cb);
  37. cb = NULL;
  38. cl->writing_state = MEI_WRITE_COMPLETE;
  39. if (waitqueue_active(&cl->tx_wait))
  40. wake_up_interruptible(&cl->tx_wait);
  41. } else if (cb->fop_type == MEI_FOP_READ &&
  42. MEI_READING == cl->reading_state) {
  43. cl->reading_state = MEI_READ_COMPLETE;
  44. if (waitqueue_active(&cl->rx_wait))
  45. wake_up_interruptible(&cl->rx_wait);
  46. else
  47. mei_cl_bus_rx_event(cl);
  48. }
  49. }
  50. /**
  51. * mei_irq_compl_handler - dispatch complete handelers
  52. * for the completed callbacks
  53. *
  54. * @dev - mei device
  55. * @compl_list - list of completed cbs
  56. */
  57. void mei_irq_compl_handler(struct mei_device *dev, struct mei_cl_cb *compl_list)
  58. {
  59. struct mei_cl_cb *cb, *next;
  60. struct mei_cl *cl;
  61. list_for_each_entry_safe(cb, next, &compl_list->list, list) {
  62. cl = cb->cl;
  63. list_del(&cb->list);
  64. if (!cl)
  65. continue;
  66. dev_dbg(&dev->pdev->dev, "completing call back.\n");
  67. if (cl == &dev->iamthif_cl)
  68. mei_amthif_complete(dev, cb);
  69. else
  70. mei_cl_complete_handler(cl, cb);
  71. }
  72. }
  73. EXPORT_SYMBOL_GPL(mei_irq_compl_handler);
  74. /**
  75. * mei_cl_hbm_equal - check if hbm is addressed to the client
  76. *
  77. * @cl: host client
  78. * @mei_hdr: header of mei client message
  79. *
  80. * returns true if matches, false otherwise
  81. */
  82. static inline int mei_cl_hbm_equal(struct mei_cl *cl,
  83. struct mei_msg_hdr *mei_hdr)
  84. {
  85. return cl->host_client_id == mei_hdr->host_addr &&
  86. cl->me_client_id == mei_hdr->me_addr;
  87. }
  88. /**
  89. * mei_cl_is_reading - checks if the client
  90. is the one to read this message
  91. *
  92. * @cl: mei client
  93. * @mei_hdr: header of mei message
  94. *
  95. * returns true on match and false otherwise
  96. */
  97. static bool mei_cl_is_reading(struct mei_cl *cl, struct mei_msg_hdr *mei_hdr)
  98. {
  99. return mei_cl_hbm_equal(cl, mei_hdr) &&
  100. cl->state == MEI_FILE_CONNECTED &&
  101. cl->reading_state != MEI_READ_COMPLETE;
  102. }
  103. /**
  104. * mei_irq_read_client_message - process client message
  105. *
  106. * @dev: the device structure
  107. * @mei_hdr: header of mei client message
  108. * @complete_list: An instance of our list structure
  109. *
  110. * returns 0 on success, <0 on failure.
  111. */
  112. static int mei_cl_irq_read_msg(struct mei_device *dev,
  113. struct mei_msg_hdr *mei_hdr,
  114. struct mei_cl_cb *complete_list)
  115. {
  116. struct mei_cl *cl;
  117. struct mei_cl_cb *cb, *next;
  118. unsigned char *buffer = NULL;
  119. list_for_each_entry_safe(cb, next, &dev->read_list.list, list) {
  120. cl = cb->cl;
  121. if (!cl || !mei_cl_is_reading(cl, mei_hdr))
  122. continue;
  123. cl->reading_state = MEI_READING;
  124. if (cb->response_buffer.size == 0 ||
  125. cb->response_buffer.data == NULL) {
  126. dev_err(&dev->pdev->dev, "response buffer is not allocated.\n");
  127. list_del(&cb->list);
  128. return -ENOMEM;
  129. }
  130. if (cb->response_buffer.size < mei_hdr->length + cb->buf_idx) {
  131. dev_warn(&dev->pdev->dev, "message overflow.\n");
  132. list_del(&cb->list);
  133. return -ENOMEM;
  134. }
  135. buffer = cb->response_buffer.data + cb->buf_idx;
  136. mei_read_slots(dev, buffer, mei_hdr->length);
  137. cb->buf_idx += mei_hdr->length;
  138. if (mei_hdr->msg_complete) {
  139. cl->status = 0;
  140. list_del(&cb->list);
  141. dev_dbg(&dev->pdev->dev, "completed read H cl = %d, ME cl = %d, length = %lu\n",
  142. cl->host_client_id,
  143. cl->me_client_id,
  144. cb->buf_idx);
  145. list_add_tail(&cb->list, &complete_list->list);
  146. }
  147. break;
  148. }
  149. dev_dbg(&dev->pdev->dev, "message read\n");
  150. if (!buffer) {
  151. mei_read_slots(dev, dev->rd_msg_buf, mei_hdr->length);
  152. dev_dbg(&dev->pdev->dev, "discarding message " MEI_HDR_FMT "\n",
  153. MEI_HDR_PRM(mei_hdr));
  154. }
  155. return 0;
  156. }
  157. /**
  158. * _mei_irq_thread_close - processes close related operation.
  159. *
  160. * @dev: the device structure.
  161. * @slots: free slots.
  162. * @cb_pos: callback block.
  163. * @cl: private data of the file object.
  164. * @cmpl_list: complete list.
  165. *
  166. * returns 0, OK; otherwise, error.
  167. */
  168. static int _mei_irq_thread_close(struct mei_device *dev, s32 *slots,
  169. struct mei_cl_cb *cb_pos,
  170. struct mei_cl *cl,
  171. struct mei_cl_cb *cmpl_list)
  172. {
  173. u32 msg_slots =
  174. mei_data2slots(sizeof(struct hbm_client_connect_request));
  175. if (*slots < msg_slots)
  176. return -EMSGSIZE;
  177. *slots -= msg_slots;
  178. if (mei_hbm_cl_disconnect_req(dev, cl)) {
  179. cl->status = 0;
  180. cb_pos->buf_idx = 0;
  181. list_move_tail(&cb_pos->list, &cmpl_list->list);
  182. return -EIO;
  183. }
  184. cl->state = MEI_FILE_DISCONNECTING;
  185. cl->status = 0;
  186. cb_pos->buf_idx = 0;
  187. list_move_tail(&cb_pos->list, &dev->ctrl_rd_list.list);
  188. cl->timer_count = MEI_CONNECT_TIMEOUT;
  189. return 0;
  190. }
  191. /**
  192. * _mei_hb_read - processes read related operation.
  193. *
  194. * @dev: the device structure.
  195. * @slots: free slots.
  196. * @cb_pos: callback block.
  197. * @cl: private data of the file object.
  198. * @cmpl_list: complete list.
  199. *
  200. * returns 0, OK; otherwise, error.
  201. */
  202. static int _mei_irq_thread_read(struct mei_device *dev, s32 *slots,
  203. struct mei_cl_cb *cb_pos,
  204. struct mei_cl *cl,
  205. struct mei_cl_cb *cmpl_list)
  206. {
  207. u32 msg_slots = mei_data2slots(sizeof(struct hbm_flow_control));
  208. if (*slots < msg_slots) {
  209. /* return the cancel routine */
  210. list_del(&cb_pos->list);
  211. return -EMSGSIZE;
  212. }
  213. *slots -= msg_slots;
  214. if (mei_hbm_cl_flow_control_req(dev, cl)) {
  215. cl->status = -ENODEV;
  216. cb_pos->buf_idx = 0;
  217. list_move_tail(&cb_pos->list, &cmpl_list->list);
  218. return -ENODEV;
  219. }
  220. list_move_tail(&cb_pos->list, &dev->read_list.list);
  221. return 0;
  222. }
  223. /**
  224. * _mei_irq_thread_ioctl - processes ioctl related operation.
  225. *
  226. * @dev: the device structure.
  227. * @slots: free slots.
  228. * @cb_pos: callback block.
  229. * @cl: private data of the file object.
  230. * @cmpl_list: complete list.
  231. *
  232. * returns 0, OK; otherwise, error.
  233. */
  234. static int _mei_irq_thread_ioctl(struct mei_device *dev, s32 *slots,
  235. struct mei_cl_cb *cb_pos,
  236. struct mei_cl *cl,
  237. struct mei_cl_cb *cmpl_list)
  238. {
  239. u32 msg_slots =
  240. mei_data2slots(sizeof(struct hbm_client_connect_request));
  241. if (*slots < msg_slots) {
  242. /* return the cancel routine */
  243. list_del(&cb_pos->list);
  244. return -EMSGSIZE;
  245. }
  246. *slots -= msg_slots;
  247. cl->state = MEI_FILE_CONNECTING;
  248. if (mei_hbm_cl_connect_req(dev, cl)) {
  249. cl->status = -ENODEV;
  250. cb_pos->buf_idx = 0;
  251. list_del(&cb_pos->list);
  252. return -ENODEV;
  253. } else {
  254. list_move_tail(&cb_pos->list, &dev->ctrl_rd_list.list);
  255. cl->timer_count = MEI_CONNECT_TIMEOUT;
  256. }
  257. return 0;
  258. }
  259. /**
  260. * mei_irq_thread_write_complete - write messages to device.
  261. *
  262. * @dev: the device structure.
  263. * @slots: free slots.
  264. * @cb: callback block.
  265. * @cmpl_list: complete list.
  266. *
  267. * returns 0, OK; otherwise, error.
  268. */
  269. static int mei_irq_thread_write_complete(struct mei_device *dev, s32 *slots,
  270. struct mei_cl_cb *cb, struct mei_cl_cb *cmpl_list)
  271. {
  272. struct mei_msg_hdr mei_hdr;
  273. struct mei_cl *cl = cb->cl;
  274. size_t len = cb->request_buffer.size - cb->buf_idx;
  275. u32 msg_slots = mei_data2slots(len);
  276. mei_hdr.host_addr = cl->host_client_id;
  277. mei_hdr.me_addr = cl->me_client_id;
  278. mei_hdr.reserved = 0;
  279. if (*slots >= msg_slots) {
  280. mei_hdr.length = len;
  281. mei_hdr.msg_complete = 1;
  282. /* Split the message only if we can write the whole host buffer */
  283. } else if (*slots == dev->hbuf_depth) {
  284. msg_slots = *slots;
  285. len = (*slots * sizeof(u32)) - sizeof(struct mei_msg_hdr);
  286. mei_hdr.length = len;
  287. mei_hdr.msg_complete = 0;
  288. } else {
  289. /* wait for next time the host buffer is empty */
  290. return 0;
  291. }
  292. dev_dbg(&dev->pdev->dev, "buf: size = %d idx = %lu\n",
  293. cb->request_buffer.size, cb->buf_idx);
  294. dev_dbg(&dev->pdev->dev, MEI_HDR_FMT, MEI_HDR_PRM(&mei_hdr));
  295. *slots -= msg_slots;
  296. if (mei_write_message(dev, &mei_hdr,
  297. cb->request_buffer.data + cb->buf_idx)) {
  298. cl->status = -ENODEV;
  299. list_move_tail(&cb->list, &cmpl_list->list);
  300. return -ENODEV;
  301. }
  302. if (mei_cl_flow_ctrl_reduce(cl))
  303. return -ENODEV;
  304. cl->status = 0;
  305. cb->buf_idx += mei_hdr.length;
  306. if (mei_hdr.msg_complete)
  307. list_move_tail(&cb->list, &dev->write_waiting_list.list);
  308. return 0;
  309. }
  310. /**
  311. * mei_irq_thread_read_handler - bottom half read routine after ISR to
  312. * handle the read processing.
  313. *
  314. * @dev: the device structure
  315. * @cmpl_list: An instance of our list structure
  316. * @slots: slots to read.
  317. *
  318. * returns 0 on success, <0 on failure.
  319. */
  320. int mei_irq_read_handler(struct mei_device *dev,
  321. struct mei_cl_cb *cmpl_list, s32 *slots)
  322. {
  323. struct mei_msg_hdr *mei_hdr;
  324. struct mei_cl *cl_pos = NULL;
  325. struct mei_cl *cl_next = NULL;
  326. int ret = 0;
  327. if (!dev->rd_msg_hdr) {
  328. dev->rd_msg_hdr = mei_read_hdr(dev);
  329. dev_dbg(&dev->pdev->dev, "slots =%08x.\n", *slots);
  330. (*slots)--;
  331. dev_dbg(&dev->pdev->dev, "slots =%08x.\n", *slots);
  332. }
  333. mei_hdr = (struct mei_msg_hdr *) &dev->rd_msg_hdr;
  334. dev_dbg(&dev->pdev->dev, MEI_HDR_FMT, MEI_HDR_PRM(mei_hdr));
  335. if (mei_hdr->reserved || !dev->rd_msg_hdr) {
  336. dev_dbg(&dev->pdev->dev, "corrupted message header.\n");
  337. ret = -EBADMSG;
  338. goto end;
  339. }
  340. if (mei_hdr->host_addr || mei_hdr->me_addr) {
  341. list_for_each_entry_safe(cl_pos, cl_next,
  342. &dev->file_list, link) {
  343. dev_dbg(&dev->pdev->dev,
  344. "list_for_each_entry_safe read host"
  345. " client = %d, ME client = %d\n",
  346. cl_pos->host_client_id,
  347. cl_pos->me_client_id);
  348. if (mei_cl_hbm_equal(cl_pos, mei_hdr))
  349. break;
  350. }
  351. if (&cl_pos->link == &dev->file_list) {
  352. dev_dbg(&dev->pdev->dev, "corrupted message header\n");
  353. ret = -EBADMSG;
  354. goto end;
  355. }
  356. }
  357. if (((*slots) * sizeof(u32)) < mei_hdr->length) {
  358. dev_err(&dev->pdev->dev,
  359. "we can't read the message slots =%08x.\n",
  360. *slots);
  361. /* we can't read the message */
  362. ret = -ERANGE;
  363. goto end;
  364. }
  365. /* decide where to read the message too */
  366. if (!mei_hdr->host_addr) {
  367. dev_dbg(&dev->pdev->dev, "call mei_irq_thread_read_bus_message.\n");
  368. mei_hbm_dispatch(dev, mei_hdr);
  369. dev_dbg(&dev->pdev->dev, "end mei_irq_thread_read_bus_message.\n");
  370. } else if (mei_hdr->host_addr == dev->iamthif_cl.host_client_id &&
  371. (MEI_FILE_CONNECTED == dev->iamthif_cl.state) &&
  372. (dev->iamthif_state == MEI_IAMTHIF_READING)) {
  373. dev_dbg(&dev->pdev->dev, "call mei_irq_thread_read_iamthif_message.\n");
  374. dev_dbg(&dev->pdev->dev, MEI_HDR_FMT, MEI_HDR_PRM(mei_hdr));
  375. ret = mei_amthif_irq_read_msg(dev, mei_hdr, cmpl_list);
  376. if (ret)
  377. goto end;
  378. } else {
  379. dev_dbg(&dev->pdev->dev, "call mei_cl_irq_read_msg.\n");
  380. dev_dbg(&dev->pdev->dev, MEI_HDR_FMT, MEI_HDR_PRM(mei_hdr));
  381. ret = mei_cl_irq_read_msg(dev, mei_hdr, cmpl_list);
  382. if (ret)
  383. goto end;
  384. }
  385. /* reset the number of slots and header */
  386. *slots = mei_count_full_read_slots(dev);
  387. dev->rd_msg_hdr = 0;
  388. if (*slots == -EOVERFLOW) {
  389. /* overflow - reset */
  390. dev_err(&dev->pdev->dev, "resetting due to slots overflow.\n");
  391. /* set the event since message has been read */
  392. ret = -ERANGE;
  393. goto end;
  394. }
  395. end:
  396. return ret;
  397. }
  398. EXPORT_SYMBOL_GPL(mei_irq_read_handler);
  399. /**
  400. * mei_irq_write_handler - dispatch write requests
  401. * after irq received
  402. *
  403. * @dev: the device structure
  404. * @cmpl_list: An instance of our list structure
  405. *
  406. * returns 0 on success, <0 on failure.
  407. */
  408. int mei_irq_write_handler(struct mei_device *dev, struct mei_cl_cb *cmpl_list)
  409. {
  410. struct mei_cl *cl;
  411. struct mei_cl_cb *pos = NULL, *next = NULL;
  412. struct mei_cl_cb *list;
  413. s32 slots;
  414. int ret;
  415. if (!mei_hbuf_is_ready(dev)) {
  416. dev_dbg(&dev->pdev->dev, "host buffer is not empty.\n");
  417. return 0;
  418. }
  419. slots = mei_hbuf_empty_slots(dev);
  420. if (slots <= 0)
  421. return -EMSGSIZE;
  422. /* complete all waiting for write CB */
  423. dev_dbg(&dev->pdev->dev, "complete all waiting for write cb.\n");
  424. list = &dev->write_waiting_list;
  425. list_for_each_entry_safe(pos, next, &list->list, list) {
  426. cl = pos->cl;
  427. if (cl == NULL)
  428. continue;
  429. cl->status = 0;
  430. list_del(&pos->list);
  431. if (MEI_WRITING == cl->writing_state &&
  432. pos->fop_type == MEI_FOP_WRITE &&
  433. cl != &dev->iamthif_cl) {
  434. dev_dbg(&dev->pdev->dev, "MEI WRITE COMPLETE\n");
  435. cl->writing_state = MEI_WRITE_COMPLETE;
  436. list_add_tail(&pos->list, &cmpl_list->list);
  437. }
  438. if (cl == &dev->iamthif_cl) {
  439. dev_dbg(&dev->pdev->dev, "check iamthif flow control.\n");
  440. if (dev->iamthif_flow_control_pending) {
  441. ret = mei_amthif_irq_read(dev, &slots);
  442. if (ret)
  443. return ret;
  444. }
  445. }
  446. }
  447. if (dev->wd_state == MEI_WD_STOPPING) {
  448. dev->wd_state = MEI_WD_IDLE;
  449. wake_up_interruptible(&dev->wait_stop_wd);
  450. }
  451. if (dev->wr_ext_msg.hdr.length) {
  452. mei_write_message(dev, &dev->wr_ext_msg.hdr,
  453. dev->wr_ext_msg.data);
  454. slots -= mei_data2slots(dev->wr_ext_msg.hdr.length);
  455. dev->wr_ext_msg.hdr.length = 0;
  456. }
  457. if (dev->dev_state == MEI_DEV_ENABLED) {
  458. if (dev->wd_pending &&
  459. mei_cl_flow_ctrl_creds(&dev->wd_cl) > 0) {
  460. if (mei_wd_send(dev))
  461. dev_dbg(&dev->pdev->dev, "wd send failed.\n");
  462. else if (mei_cl_flow_ctrl_reduce(&dev->wd_cl))
  463. return -ENODEV;
  464. dev->wd_pending = false;
  465. if (dev->wd_state == MEI_WD_RUNNING)
  466. slots -= mei_data2slots(MEI_WD_START_MSG_SIZE);
  467. else
  468. slots -= mei_data2slots(MEI_WD_STOP_MSG_SIZE);
  469. }
  470. }
  471. /* complete control write list CB */
  472. dev_dbg(&dev->pdev->dev, "complete control write list cb.\n");
  473. list_for_each_entry_safe(pos, next, &dev->ctrl_wr_list.list, list) {
  474. cl = pos->cl;
  475. if (!cl) {
  476. list_del(&pos->list);
  477. return -ENODEV;
  478. }
  479. switch (pos->fop_type) {
  480. case MEI_FOP_CLOSE:
  481. /* send disconnect message */
  482. ret = _mei_irq_thread_close(dev, &slots, pos,
  483. cl, cmpl_list);
  484. if (ret)
  485. return ret;
  486. break;
  487. case MEI_FOP_READ:
  488. /* send flow control message */
  489. ret = _mei_irq_thread_read(dev, &slots, pos,
  490. cl, cmpl_list);
  491. if (ret)
  492. return ret;
  493. break;
  494. case MEI_FOP_IOCTL:
  495. /* connect message */
  496. if (mei_cl_is_other_connecting(cl))
  497. continue;
  498. ret = _mei_irq_thread_ioctl(dev, &slots, pos,
  499. cl, cmpl_list);
  500. if (ret)
  501. return ret;
  502. break;
  503. default:
  504. BUG();
  505. }
  506. }
  507. /* complete write list CB */
  508. dev_dbg(&dev->pdev->dev, "complete write list cb.\n");
  509. list_for_each_entry_safe(pos, next, &dev->write_list.list, list) {
  510. cl = pos->cl;
  511. if (cl == NULL)
  512. continue;
  513. if (mei_cl_flow_ctrl_creds(cl) <= 0) {
  514. dev_dbg(&dev->pdev->dev,
  515. "No flow control credentials for client %d, not sending.\n",
  516. cl->host_client_id);
  517. continue;
  518. }
  519. if (cl == &dev->iamthif_cl)
  520. ret = mei_amthif_irq_write_complete(dev, &slots,
  521. pos, cmpl_list);
  522. else
  523. ret = mei_irq_thread_write_complete(dev, &slots, pos,
  524. cmpl_list);
  525. if (ret)
  526. return ret;
  527. }
  528. return 0;
  529. }
  530. EXPORT_SYMBOL_GPL(mei_irq_write_handler);
  531. /**
  532. * mei_timer - timer function.
  533. *
  534. * @work: pointer to the work_struct structure
  535. *
  536. * NOTE: This function is called by timer interrupt work
  537. */
  538. void mei_timer(struct work_struct *work)
  539. {
  540. unsigned long timeout;
  541. struct mei_cl *cl_pos = NULL;
  542. struct mei_cl *cl_next = NULL;
  543. struct mei_cl_cb *cb_pos = NULL;
  544. struct mei_cl_cb *cb_next = NULL;
  545. struct mei_device *dev = container_of(work,
  546. struct mei_device, timer_work.work);
  547. mutex_lock(&dev->device_lock);
  548. if (dev->dev_state != MEI_DEV_ENABLED) {
  549. if (dev->dev_state == MEI_DEV_INIT_CLIENTS) {
  550. if (dev->init_clients_timer) {
  551. if (--dev->init_clients_timer == 0) {
  552. dev_err(&dev->pdev->dev, "reset: init clients timeout hbm_state = %d.\n",
  553. dev->hbm_state);
  554. mei_reset(dev, 1);
  555. }
  556. }
  557. }
  558. goto out;
  559. }
  560. /*** connect/disconnect timeouts ***/
  561. list_for_each_entry_safe(cl_pos, cl_next, &dev->file_list, link) {
  562. if (cl_pos->timer_count) {
  563. if (--cl_pos->timer_count == 0) {
  564. dev_err(&dev->pdev->dev, "reset: connect/disconnect timeout.\n");
  565. mei_reset(dev, 1);
  566. goto out;
  567. }
  568. }
  569. }
  570. if (dev->iamthif_stall_timer) {
  571. if (--dev->iamthif_stall_timer == 0) {
  572. dev_err(&dev->pdev->dev, "reset: amthif hanged.\n");
  573. mei_reset(dev, 1);
  574. dev->iamthif_msg_buf_size = 0;
  575. dev->iamthif_msg_buf_index = 0;
  576. dev->iamthif_canceled = false;
  577. dev->iamthif_ioctl = true;
  578. dev->iamthif_state = MEI_IAMTHIF_IDLE;
  579. dev->iamthif_timer = 0;
  580. mei_io_cb_free(dev->iamthif_current_cb);
  581. dev->iamthif_current_cb = NULL;
  582. dev->iamthif_file_object = NULL;
  583. mei_amthif_run_next_cmd(dev);
  584. }
  585. }
  586. if (dev->iamthif_timer) {
  587. timeout = dev->iamthif_timer +
  588. mei_secs_to_jiffies(MEI_IAMTHIF_READ_TIMER);
  589. dev_dbg(&dev->pdev->dev, "dev->iamthif_timer = %ld\n",
  590. dev->iamthif_timer);
  591. dev_dbg(&dev->pdev->dev, "timeout = %ld\n", timeout);
  592. dev_dbg(&dev->pdev->dev, "jiffies = %ld\n", jiffies);
  593. if (time_after(jiffies, timeout)) {
  594. /*
  595. * User didn't read the AMTHI data on time (15sec)
  596. * freeing AMTHI for other requests
  597. */
  598. dev_dbg(&dev->pdev->dev, "freeing AMTHI for other requests\n");
  599. list_for_each_entry_safe(cb_pos, cb_next,
  600. &dev->amthif_rd_complete_list.list, list) {
  601. cl_pos = cb_pos->file_object->private_data;
  602. /* Finding the AMTHI entry. */
  603. if (cl_pos == &dev->iamthif_cl)
  604. list_del(&cb_pos->list);
  605. }
  606. mei_io_cb_free(dev->iamthif_current_cb);
  607. dev->iamthif_current_cb = NULL;
  608. dev->iamthif_file_object->private_data = NULL;
  609. dev->iamthif_file_object = NULL;
  610. dev->iamthif_timer = 0;
  611. mei_amthif_run_next_cmd(dev);
  612. }
  613. }
  614. out:
  615. schedule_delayed_work(&dev->timer_work, 2 * HZ);
  616. mutex_unlock(&dev->device_lock);
  617. }