interrupt.c 17 KB

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