interrupt.c 17 KB

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