interrupt.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266
  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 "mei_dev.h"
  22. #include <linux/mei.h>
  23. #include "hw.h"
  24. #include "interface.h"
  25. /**
  26. * mei_interrupt_quick_handler - The ISR of the MEI device
  27. *
  28. * @irq: The irq number
  29. * @dev_id: pointer to the device structure
  30. *
  31. * returns irqreturn_t
  32. */
  33. irqreturn_t mei_interrupt_quick_handler(int irq, void *dev_id)
  34. {
  35. struct mei_device *dev = (struct mei_device *) dev_id;
  36. u32 csr_reg = mei_hcsr_read(dev);
  37. if ((csr_reg & H_IS) != H_IS)
  38. return IRQ_NONE;
  39. /* clear H_IS bit in H_CSR */
  40. mei_reg_write(dev, H_CSR, csr_reg);
  41. return IRQ_WAKE_THREAD;
  42. }
  43. /**
  44. * _mei_cmpl - processes completed operation.
  45. *
  46. * @cl: private data of the file object.
  47. * @cb_pos: callback block.
  48. */
  49. static void _mei_cmpl(struct mei_cl *cl, struct mei_cl_cb *cb_pos)
  50. {
  51. if (cb_pos->fop_type == MEI_FOP_WRITE) {
  52. mei_io_cb_free(cb_pos);
  53. cb_pos = NULL;
  54. cl->writing_state = MEI_WRITE_COMPLETE;
  55. if (waitqueue_active(&cl->tx_wait))
  56. wake_up_interruptible(&cl->tx_wait);
  57. } else if (cb_pos->fop_type == MEI_FOP_READ &&
  58. MEI_READING == cl->reading_state) {
  59. cl->reading_state = MEI_READ_COMPLETE;
  60. if (waitqueue_active(&cl->rx_wait))
  61. wake_up_interruptible(&cl->rx_wait);
  62. }
  63. }
  64. /**
  65. * _mei_irq_thread_state_ok - checks if mei header matches file private data
  66. *
  67. * @cl: private data of the file object
  68. * @mei_hdr: header of mei client message
  69. *
  70. * returns !=0 if matches, 0 if no match.
  71. */
  72. static int _mei_irq_thread_state_ok(struct mei_cl *cl,
  73. struct mei_msg_hdr *mei_hdr)
  74. {
  75. return (cl->host_client_id == mei_hdr->host_addr &&
  76. cl->me_client_id == mei_hdr->me_addr &&
  77. cl->state == MEI_FILE_CONNECTED &&
  78. MEI_READ_COMPLETE != cl->reading_state);
  79. }
  80. /**
  81. * mei_irq_thread_read_client_message - bottom half read routine after ISR to
  82. * handle the read mei client message data processing.
  83. *
  84. * @complete_list: An instance of our list structure
  85. * @dev: the device structure
  86. * @mei_hdr: header of mei client message
  87. *
  88. * returns 0 on success, <0 on failure.
  89. */
  90. static int mei_irq_thread_read_client_message(struct mei_cl_cb *complete_list,
  91. struct mei_device *dev,
  92. struct mei_msg_hdr *mei_hdr)
  93. {
  94. struct mei_cl *cl;
  95. struct mei_cl_cb *cb_pos = NULL, *cb_next = NULL;
  96. unsigned char *buffer = NULL;
  97. dev_dbg(&dev->pdev->dev, "start client msg\n");
  98. if (list_empty(&dev->read_list.list))
  99. goto quit;
  100. list_for_each_entry_safe(cb_pos, cb_next, &dev->read_list.list, list) {
  101. cl = cb_pos->cl;
  102. if (cl && _mei_irq_thread_state_ok(cl, mei_hdr)) {
  103. cl->reading_state = MEI_READING;
  104. buffer = cb_pos->response_buffer.data + cb_pos->buf_idx;
  105. if (cb_pos->response_buffer.size <
  106. mei_hdr->length + cb_pos->buf_idx) {
  107. dev_dbg(&dev->pdev->dev, "message overflow.\n");
  108. list_del(&cb_pos->list);
  109. return -ENOMEM;
  110. }
  111. if (buffer)
  112. mei_read_slots(dev, buffer, mei_hdr->length);
  113. cb_pos->buf_idx += mei_hdr->length;
  114. if (mei_hdr->msg_complete) {
  115. cl->status = 0;
  116. list_del(&cb_pos->list);
  117. dev_dbg(&dev->pdev->dev,
  118. "completed read H cl = %d, ME cl = %d, length = %lu\n",
  119. cl->host_client_id,
  120. cl->me_client_id,
  121. cb_pos->buf_idx);
  122. list_add_tail(&cb_pos->list,
  123. &complete_list->list);
  124. }
  125. break;
  126. }
  127. }
  128. quit:
  129. dev_dbg(&dev->pdev->dev, "message read\n");
  130. if (!buffer) {
  131. mei_read_slots(dev, dev->rd_msg_buf, mei_hdr->length);
  132. dev_dbg(&dev->pdev->dev, "discarding message, header =%08x.\n",
  133. *(u32 *) dev->rd_msg_buf);
  134. }
  135. return 0;
  136. }
  137. /**
  138. * _mei_irq_thread_close - processes close related operation.
  139. *
  140. * @dev: the device structure.
  141. * @slots: free slots.
  142. * @cb_pos: callback block.
  143. * @cl: private data of the file object.
  144. * @cmpl_list: complete list.
  145. *
  146. * returns 0, OK; otherwise, error.
  147. */
  148. static int _mei_irq_thread_close(struct mei_device *dev, s32 *slots,
  149. struct mei_cl_cb *cb_pos,
  150. struct mei_cl *cl,
  151. struct mei_cl_cb *cmpl_list)
  152. {
  153. if ((*slots * sizeof(u32)) < (sizeof(struct mei_msg_hdr) +
  154. sizeof(struct hbm_client_connect_request)))
  155. return -EBADMSG;
  156. *slots -= mei_data2slots(sizeof(struct hbm_client_connect_request));
  157. if (mei_disconnect(dev, cl)) {
  158. cl->status = 0;
  159. cb_pos->buf_idx = 0;
  160. list_move_tail(&cb_pos->list, &cmpl_list->list);
  161. return -EMSGSIZE;
  162. } else {
  163. cl->state = MEI_FILE_DISCONNECTING;
  164. cl->status = 0;
  165. cb_pos->buf_idx = 0;
  166. list_move_tail(&cb_pos->list, &dev->ctrl_rd_list.list);
  167. cl->timer_count = MEI_CONNECT_TIMEOUT;
  168. }
  169. return 0;
  170. }
  171. /**
  172. * is_treat_specially_client - checks if the message belongs
  173. * to the file private data.
  174. *
  175. * @cl: private data of the file object
  176. * @rs: connect response bus message
  177. *
  178. */
  179. static bool is_treat_specially_client(struct mei_cl *cl,
  180. struct hbm_client_connect_response *rs)
  181. {
  182. if (cl->host_client_id == rs->host_addr &&
  183. cl->me_client_id == rs->me_addr) {
  184. if (!rs->status) {
  185. cl->state = MEI_FILE_CONNECTED;
  186. cl->status = 0;
  187. } else {
  188. cl->state = MEI_FILE_DISCONNECTED;
  189. cl->status = -ENODEV;
  190. }
  191. cl->timer_count = 0;
  192. return true;
  193. }
  194. return false;
  195. }
  196. /**
  197. * mei_client_connect_response - connects to response irq routine
  198. *
  199. * @dev: the device structure
  200. * @rs: connect response bus message
  201. */
  202. static void mei_client_connect_response(struct mei_device *dev,
  203. struct hbm_client_connect_response *rs)
  204. {
  205. struct mei_cl *cl;
  206. struct mei_cl_cb *pos = NULL, *next = NULL;
  207. dev_dbg(&dev->pdev->dev,
  208. "connect_response:\n"
  209. "ME Client = %d\n"
  210. "Host Client = %d\n"
  211. "Status = %d\n",
  212. rs->me_addr,
  213. rs->host_addr,
  214. rs->status);
  215. /* if WD or iamthif client treat specially */
  216. if (is_treat_specially_client(&(dev->wd_cl), rs)) {
  217. dev_dbg(&dev->pdev->dev, "successfully connected to WD client.\n");
  218. mei_watchdog_register(dev);
  219. /* next step in the state maching */
  220. mei_amthif_host_init(dev);
  221. return;
  222. }
  223. if (is_treat_specially_client(&(dev->iamthif_cl), rs)) {
  224. dev->iamthif_state = MEI_IAMTHIF_IDLE;
  225. return;
  226. }
  227. list_for_each_entry_safe(pos, next, &dev->ctrl_rd_list.list, list) {
  228. cl = pos->cl;
  229. if (!cl) {
  230. list_del(&pos->list);
  231. return;
  232. }
  233. if (pos->fop_type == MEI_FOP_IOCTL) {
  234. if (is_treat_specially_client(cl, rs)) {
  235. list_del(&pos->list);
  236. cl->status = 0;
  237. cl->timer_count = 0;
  238. break;
  239. }
  240. }
  241. }
  242. }
  243. /**
  244. * mei_client_disconnect_response - disconnects from response irq routine
  245. *
  246. * @dev: the device structure
  247. * @rs: disconnect response bus message
  248. */
  249. static void mei_client_disconnect_response(struct mei_device *dev,
  250. struct hbm_client_connect_response *rs)
  251. {
  252. struct mei_cl *cl;
  253. struct mei_cl_cb *pos = NULL, *next = NULL;
  254. dev_dbg(&dev->pdev->dev,
  255. "disconnect_response:\n"
  256. "ME Client = %d\n"
  257. "Host Client = %d\n"
  258. "Status = %d\n",
  259. rs->me_addr,
  260. rs->host_addr,
  261. rs->status);
  262. list_for_each_entry_safe(pos, next, &dev->ctrl_rd_list.list, list) {
  263. cl = pos->cl;
  264. if (!cl) {
  265. list_del(&pos->list);
  266. return;
  267. }
  268. dev_dbg(&dev->pdev->dev, "list_for_each_entry_safe in ctrl_rd_list.\n");
  269. if (cl->host_client_id == rs->host_addr &&
  270. cl->me_client_id == rs->me_addr) {
  271. list_del(&pos->list);
  272. if (!rs->status)
  273. cl->state = MEI_FILE_DISCONNECTED;
  274. cl->status = 0;
  275. cl->timer_count = 0;
  276. break;
  277. }
  278. }
  279. }
  280. /**
  281. * same_flow_addr - tells if they have the same address.
  282. *
  283. * @file: private data of the file object.
  284. * @flow: flow control.
  285. *
  286. * returns !=0, same; 0,not.
  287. */
  288. static int same_flow_addr(struct mei_cl *cl, struct hbm_flow_control *flow)
  289. {
  290. return (cl->host_client_id == flow->host_addr &&
  291. cl->me_client_id == flow->me_addr);
  292. }
  293. /**
  294. * add_single_flow_creds - adds single buffer credentials.
  295. *
  296. * @file: private data ot the file object.
  297. * @flow: flow control.
  298. */
  299. static void add_single_flow_creds(struct mei_device *dev,
  300. struct hbm_flow_control *flow)
  301. {
  302. struct mei_me_client *client;
  303. int i;
  304. for (i = 0; i < dev->me_clients_num; i++) {
  305. client = &dev->me_clients[i];
  306. if (client && flow->me_addr == client->client_id) {
  307. if (client->props.single_recv_buf) {
  308. client->mei_flow_ctrl_creds++;
  309. dev_dbg(&dev->pdev->dev, "recv flow ctrl msg ME %d (single).\n",
  310. flow->me_addr);
  311. dev_dbg(&dev->pdev->dev, "flow control credentials =%d.\n",
  312. client->mei_flow_ctrl_creds);
  313. } else {
  314. BUG(); /* error in flow control */
  315. }
  316. }
  317. }
  318. }
  319. /**
  320. * mei_client_flow_control_response - flow control response irq routine
  321. *
  322. * @dev: the device structure
  323. * @flow_control: flow control response bus message
  324. */
  325. static void mei_client_flow_control_response(struct mei_device *dev,
  326. struct hbm_flow_control *flow_control)
  327. {
  328. struct mei_cl *cl_pos = NULL;
  329. struct mei_cl *cl_next = NULL;
  330. if (!flow_control->host_addr) {
  331. /* single receive buffer */
  332. add_single_flow_creds(dev, flow_control);
  333. } else {
  334. /* normal connection */
  335. list_for_each_entry_safe(cl_pos, cl_next,
  336. &dev->file_list, link) {
  337. dev_dbg(&dev->pdev->dev, "list_for_each_entry_safe in file_list\n");
  338. dev_dbg(&dev->pdev->dev, "cl of host client %d ME client %d.\n",
  339. cl_pos->host_client_id,
  340. cl_pos->me_client_id);
  341. dev_dbg(&dev->pdev->dev, "flow ctrl msg for host %d ME %d.\n",
  342. flow_control->host_addr,
  343. flow_control->me_addr);
  344. if (same_flow_addr(cl_pos, flow_control)) {
  345. dev_dbg(&dev->pdev->dev, "recv ctrl msg for host %d ME %d.\n",
  346. flow_control->host_addr,
  347. flow_control->me_addr);
  348. cl_pos->mei_flow_ctrl_creds++;
  349. dev_dbg(&dev->pdev->dev, "flow control credentials = %d.\n",
  350. cl_pos->mei_flow_ctrl_creds);
  351. break;
  352. }
  353. }
  354. }
  355. }
  356. /**
  357. * same_disconn_addr - tells if they have the same address
  358. *
  359. * @file: private data of the file object.
  360. * @disconn: disconnection request.
  361. *
  362. * returns !=0, same; 0,not.
  363. */
  364. static int same_disconn_addr(struct mei_cl *cl,
  365. struct hbm_client_connect_request *req)
  366. {
  367. return (cl->host_client_id == req->host_addr &&
  368. cl->me_client_id == req->me_addr);
  369. }
  370. /**
  371. * mei_client_disconnect_request - disconnects from request irq routine
  372. *
  373. * @dev: the device structure.
  374. * @disconnect_req: disconnect request bus message.
  375. */
  376. static void mei_client_disconnect_request(struct mei_device *dev,
  377. struct hbm_client_connect_request *disconnect_req)
  378. {
  379. struct hbm_client_connect_response *disconnect_res;
  380. struct mei_cl *pos, *next;
  381. const size_t len = sizeof(struct hbm_client_connect_response);
  382. list_for_each_entry_safe(pos, next, &dev->file_list, link) {
  383. if (same_disconn_addr(pos, disconnect_req)) {
  384. dev_dbg(&dev->pdev->dev, "disconnect request host client %d ME client %d.\n",
  385. disconnect_req->host_addr,
  386. disconnect_req->me_addr);
  387. pos->state = MEI_FILE_DISCONNECTED;
  388. pos->timer_count = 0;
  389. if (pos == &dev->wd_cl)
  390. dev->wd_pending = false;
  391. else if (pos == &dev->iamthif_cl)
  392. dev->iamthif_timer = 0;
  393. /* prepare disconnect response */
  394. (void)mei_hbm_hdr((u32 *)&dev->wr_ext_msg.hdr, len);
  395. disconnect_res =
  396. (struct hbm_client_connect_response *)
  397. &dev->wr_ext_msg.data;
  398. disconnect_res->hbm_cmd = CLIENT_DISCONNECT_RES_CMD;
  399. disconnect_res->host_addr = pos->host_client_id;
  400. disconnect_res->me_addr = pos->me_client_id;
  401. disconnect_res->status = 0;
  402. break;
  403. }
  404. }
  405. }
  406. /**
  407. * mei_irq_thread_read_bus_message - bottom half read routine after ISR to
  408. * handle the read bus message cmd processing.
  409. *
  410. * @dev: the device structure
  411. * @mei_hdr: header of bus message
  412. */
  413. static void mei_irq_thread_read_bus_message(struct mei_device *dev,
  414. struct mei_msg_hdr *mei_hdr)
  415. {
  416. struct mei_bus_message *mei_msg;
  417. struct hbm_host_version_response *version_res;
  418. struct hbm_client_connect_response *connect_res;
  419. struct hbm_client_connect_response *disconnect_res;
  420. struct hbm_client_connect_request *disconnect_req;
  421. struct hbm_flow_control *flow_control;
  422. struct hbm_props_response *props_res;
  423. struct hbm_host_enum_response *enum_res;
  424. struct hbm_host_stop_request *stop_req;
  425. int res;
  426. /* read the message to our buffer */
  427. BUG_ON(mei_hdr->length >= sizeof(dev->rd_msg_buf));
  428. mei_read_slots(dev, dev->rd_msg_buf, mei_hdr->length);
  429. mei_msg = (struct mei_bus_message *)dev->rd_msg_buf;
  430. switch (mei_msg->hbm_cmd) {
  431. case HOST_START_RES_CMD:
  432. version_res = (struct hbm_host_version_response *) mei_msg;
  433. if (version_res->host_version_supported) {
  434. dev->version.major_version = HBM_MAJOR_VERSION;
  435. dev->version.minor_version = HBM_MINOR_VERSION;
  436. if (dev->dev_state == MEI_DEV_INIT_CLIENTS &&
  437. dev->init_clients_state == MEI_START_MESSAGE) {
  438. dev->init_clients_timer = 0;
  439. mei_host_enum_clients_message(dev);
  440. } else {
  441. dev->recvd_msg = false;
  442. dev_dbg(&dev->pdev->dev, "IMEI reset due to received host start response bus message.\n");
  443. mei_reset(dev, 1);
  444. return;
  445. }
  446. } else {
  447. u32 *buf = dev->wr_msg_buf;
  448. const size_t len = sizeof(struct hbm_host_stop_request);
  449. dev->version = version_res->me_max_version;
  450. /* send stop message */
  451. mei_hdr = mei_hbm_hdr(&buf[0], len);
  452. stop_req = (struct hbm_host_stop_request *)&buf[1];
  453. memset(stop_req, 0, len);
  454. stop_req->hbm_cmd = HOST_STOP_REQ_CMD;
  455. stop_req->reason = DRIVER_STOP_REQUEST;
  456. mei_write_message(dev, mei_hdr,
  457. (unsigned char *)stop_req, len);
  458. dev_dbg(&dev->pdev->dev, "version mismatch.\n");
  459. return;
  460. }
  461. dev->recvd_msg = true;
  462. dev_dbg(&dev->pdev->dev, "host start response message received.\n");
  463. break;
  464. case CLIENT_CONNECT_RES_CMD:
  465. connect_res = (struct hbm_client_connect_response *) mei_msg;
  466. mei_client_connect_response(dev, connect_res);
  467. dev_dbg(&dev->pdev->dev, "client connect response message received.\n");
  468. wake_up(&dev->wait_recvd_msg);
  469. break;
  470. case CLIENT_DISCONNECT_RES_CMD:
  471. disconnect_res = (struct hbm_client_connect_response *) mei_msg;
  472. mei_client_disconnect_response(dev, disconnect_res);
  473. dev_dbg(&dev->pdev->dev, "client disconnect response message received.\n");
  474. wake_up(&dev->wait_recvd_msg);
  475. break;
  476. case MEI_FLOW_CONTROL_CMD:
  477. flow_control = (struct hbm_flow_control *) mei_msg;
  478. mei_client_flow_control_response(dev, flow_control);
  479. dev_dbg(&dev->pdev->dev, "client flow control response message received.\n");
  480. break;
  481. case HOST_CLIENT_PROPERTIES_RES_CMD:
  482. props_res = (struct hbm_props_response *)mei_msg;
  483. if (props_res->status || !dev->me_clients) {
  484. dev_dbg(&dev->pdev->dev, "reset due to received host client properties response bus message wrong status.\n");
  485. mei_reset(dev, 1);
  486. return;
  487. }
  488. if (dev->me_clients[dev->me_client_presentation_num]
  489. .client_id == props_res->address) {
  490. dev->me_clients[dev->me_client_presentation_num].props
  491. = props_res->client_properties;
  492. if (dev->dev_state == MEI_DEV_INIT_CLIENTS &&
  493. dev->init_clients_state ==
  494. MEI_CLIENT_PROPERTIES_MESSAGE) {
  495. dev->me_client_index++;
  496. dev->me_client_presentation_num++;
  497. /** Send Client Properties request **/
  498. res = mei_host_client_properties(dev);
  499. if (res < 0) {
  500. dev_dbg(&dev->pdev->dev, "mei_host_client_properties() failed");
  501. return;
  502. } else if (!res) {
  503. /*
  504. * No more clients to send to.
  505. * Clear Map for indicating now ME clients
  506. * with associated host client
  507. */
  508. bitmap_zero(dev->host_clients_map, MEI_CLIENTS_MAX);
  509. dev->open_handle_count = 0;
  510. /*
  511. * Reserving the first three client IDs
  512. * Client Id 0 - Reserved for MEI Bus Message communications
  513. * Client Id 1 - Reserved for Watchdog
  514. * Client ID 2 - Reserved for AMTHI
  515. */
  516. bitmap_set(dev->host_clients_map, 0, 3);
  517. dev->dev_state = MEI_DEV_ENABLED;
  518. /* if wd initialization fails, initialization the AMTHI client,
  519. * otherwise the AMTHI client will be initialized after the WD client connect response
  520. * will be received
  521. */
  522. if (mei_wd_host_init(dev))
  523. mei_amthif_host_init(dev);
  524. }
  525. } else {
  526. dev_dbg(&dev->pdev->dev, "reset due to received host client properties response bus message");
  527. mei_reset(dev, 1);
  528. return;
  529. }
  530. } else {
  531. dev_dbg(&dev->pdev->dev, "reset due to received host client properties response bus message for wrong client ID\n");
  532. mei_reset(dev, 1);
  533. return;
  534. }
  535. break;
  536. case HOST_ENUM_RES_CMD:
  537. enum_res = (struct hbm_host_enum_response *) mei_msg;
  538. memcpy(dev->me_clients_map, enum_res->valid_addresses, 32);
  539. if (dev->dev_state == MEI_DEV_INIT_CLIENTS &&
  540. dev->init_clients_state == MEI_ENUM_CLIENTS_MESSAGE) {
  541. dev->init_clients_timer = 0;
  542. dev->me_client_presentation_num = 0;
  543. dev->me_client_index = 0;
  544. mei_allocate_me_clients_storage(dev);
  545. dev->init_clients_state =
  546. MEI_CLIENT_PROPERTIES_MESSAGE;
  547. mei_host_client_properties(dev);
  548. } else {
  549. dev_dbg(&dev->pdev->dev, "reset due to received host enumeration clients response bus message.\n");
  550. mei_reset(dev, 1);
  551. return;
  552. }
  553. break;
  554. case HOST_STOP_RES_CMD:
  555. dev->dev_state = MEI_DEV_DISABLED;
  556. dev_dbg(&dev->pdev->dev, "resetting because of FW stop response.\n");
  557. mei_reset(dev, 1);
  558. break;
  559. case CLIENT_DISCONNECT_REQ_CMD:
  560. /* search for client */
  561. disconnect_req = (struct hbm_client_connect_request *)mei_msg;
  562. mei_client_disconnect_request(dev, disconnect_req);
  563. break;
  564. case ME_STOP_REQ_CMD:
  565. {
  566. /* prepare stop request: sent in next interrupt event */
  567. const size_t len = sizeof(struct hbm_host_stop_request);
  568. mei_hdr = mei_hbm_hdr((u32 *)&dev->wr_ext_msg.hdr, len);
  569. stop_req = (struct hbm_host_stop_request *)&dev->wr_ext_msg.data;
  570. memset(stop_req, 0, len);
  571. stop_req->hbm_cmd = HOST_STOP_REQ_CMD;
  572. stop_req->reason = DRIVER_STOP_REQUEST;
  573. break;
  574. }
  575. default:
  576. BUG();
  577. break;
  578. }
  579. }
  580. /**
  581. * _mei_hb_read - processes read related operation.
  582. *
  583. * @dev: the device structure.
  584. * @slots: free slots.
  585. * @cb_pos: callback block.
  586. * @cl: private data of the file object.
  587. * @cmpl_list: complete list.
  588. *
  589. * returns 0, OK; otherwise, error.
  590. */
  591. static int _mei_irq_thread_read(struct mei_device *dev, s32 *slots,
  592. struct mei_cl_cb *cb_pos,
  593. struct mei_cl *cl,
  594. struct mei_cl_cb *cmpl_list)
  595. {
  596. if ((*slots * sizeof(u32)) < (sizeof(struct mei_msg_hdr) +
  597. sizeof(struct hbm_flow_control))) {
  598. /* return the cancel routine */
  599. list_del(&cb_pos->list);
  600. return -EBADMSG;
  601. }
  602. *slots -= mei_data2slots(sizeof(struct hbm_flow_control));
  603. if (mei_send_flow_control(dev, cl)) {
  604. cl->status = -ENODEV;
  605. cb_pos->buf_idx = 0;
  606. list_move_tail(&cb_pos->list, &cmpl_list->list);
  607. return -ENODEV;
  608. }
  609. list_move_tail(&cb_pos->list, &dev->read_list.list);
  610. return 0;
  611. }
  612. /**
  613. * _mei_irq_thread_ioctl - processes ioctl related operation.
  614. *
  615. * @dev: the device structure.
  616. * @slots: free slots.
  617. * @cb_pos: callback block.
  618. * @cl: private data of the file object.
  619. * @cmpl_list: complete list.
  620. *
  621. * returns 0, OK; otherwise, error.
  622. */
  623. static int _mei_irq_thread_ioctl(struct mei_device *dev, s32 *slots,
  624. struct mei_cl_cb *cb_pos,
  625. struct mei_cl *cl,
  626. struct mei_cl_cb *cmpl_list)
  627. {
  628. if ((*slots * sizeof(u32)) < (sizeof(struct mei_msg_hdr) +
  629. sizeof(struct hbm_client_connect_request))) {
  630. /* return the cancel routine */
  631. list_del(&cb_pos->list);
  632. return -EBADMSG;
  633. }
  634. cl->state = MEI_FILE_CONNECTING;
  635. *slots -= mei_data2slots(sizeof(struct hbm_client_connect_request));
  636. if (mei_connect(dev, cl)) {
  637. cl->status = -ENODEV;
  638. cb_pos->buf_idx = 0;
  639. list_del(&cb_pos->list);
  640. return -ENODEV;
  641. } else {
  642. list_move_tail(&cb_pos->list, &dev->ctrl_rd_list.list);
  643. cl->timer_count = MEI_CONNECT_TIMEOUT;
  644. }
  645. return 0;
  646. }
  647. /**
  648. * mei_irq_thread_write_complete - write messages to device.
  649. *
  650. * @dev: the device structure.
  651. * @slots: free slots.
  652. * @cb: callback block.
  653. * @cmpl_list: complete list.
  654. *
  655. * returns 0, OK; otherwise, error.
  656. */
  657. static int mei_irq_thread_write_complete(struct mei_device *dev, s32 *slots,
  658. struct mei_cl_cb *cb, struct mei_cl_cb *cmpl_list)
  659. {
  660. struct mei_msg_hdr *mei_hdr;
  661. struct mei_cl *cl = cb->cl;
  662. size_t len = cb->request_buffer.size - cb->buf_idx;
  663. size_t msg_slots = mei_data2slots(len);
  664. mei_hdr = (struct mei_msg_hdr *)&dev->wr_msg_buf[0];
  665. mei_hdr->host_addr = cl->host_client_id;
  666. mei_hdr->me_addr = cl->me_client_id;
  667. mei_hdr->reserved = 0;
  668. if (*slots >= msg_slots) {
  669. mei_hdr->length = len;
  670. mei_hdr->msg_complete = 1;
  671. /* Split the message only if we can write the whole host buffer */
  672. } else if (*slots == dev->hbuf_depth) {
  673. msg_slots = *slots;
  674. len = (*slots * sizeof(u32)) - sizeof(struct mei_msg_hdr);
  675. mei_hdr->length = len;
  676. mei_hdr->msg_complete = 0;
  677. } else {
  678. /* wait for next time the host buffer is empty */
  679. return 0;
  680. }
  681. dev_dbg(&dev->pdev->dev, "buf: size = %d idx = %lu\n",
  682. cb->request_buffer.size, cb->buf_idx);
  683. dev_dbg(&dev->pdev->dev, "msg: len = %d complete = %d\n",
  684. mei_hdr->length, mei_hdr->msg_complete);
  685. *slots -= msg_slots;
  686. if (mei_write_message(dev, mei_hdr,
  687. cb->request_buffer.data + cb->buf_idx, len)) {
  688. cl->status = -ENODEV;
  689. list_move_tail(&cb->list, &cmpl_list->list);
  690. return -ENODEV;
  691. }
  692. if (mei_flow_ctrl_reduce(dev, cl))
  693. return -ENODEV;
  694. cl->status = 0;
  695. cb->buf_idx += mei_hdr->length;
  696. if (mei_hdr->msg_complete)
  697. list_move_tail(&cb->list, &dev->write_waiting_list.list);
  698. return 0;
  699. }
  700. /**
  701. * mei_irq_thread_read_handler - bottom half read routine after ISR to
  702. * handle the read processing.
  703. *
  704. * @cmpl_list: An instance of our list structure
  705. * @dev: the device structure
  706. * @slots: slots to read.
  707. *
  708. * returns 0 on success, <0 on failure.
  709. */
  710. static int mei_irq_thread_read_handler(struct mei_cl_cb *cmpl_list,
  711. struct mei_device *dev,
  712. s32 *slots)
  713. {
  714. struct mei_msg_hdr *mei_hdr;
  715. struct mei_cl *cl_pos = NULL;
  716. struct mei_cl *cl_next = NULL;
  717. int ret = 0;
  718. if (!dev->rd_msg_hdr) {
  719. dev->rd_msg_hdr = mei_mecbrw_read(dev);
  720. dev_dbg(&dev->pdev->dev, "slots =%08x.\n", *slots);
  721. (*slots)--;
  722. dev_dbg(&dev->pdev->dev, "slots =%08x.\n", *slots);
  723. }
  724. mei_hdr = (struct mei_msg_hdr *) &dev->rd_msg_hdr;
  725. dev_dbg(&dev->pdev->dev, "mei_hdr->length =%d\n", mei_hdr->length);
  726. if (mei_hdr->reserved || !dev->rd_msg_hdr) {
  727. dev_dbg(&dev->pdev->dev, "corrupted message header.\n");
  728. ret = -EBADMSG;
  729. goto end;
  730. }
  731. if (mei_hdr->host_addr || mei_hdr->me_addr) {
  732. list_for_each_entry_safe(cl_pos, cl_next,
  733. &dev->file_list, link) {
  734. dev_dbg(&dev->pdev->dev,
  735. "list_for_each_entry_safe read host"
  736. " client = %d, ME client = %d\n",
  737. cl_pos->host_client_id,
  738. cl_pos->me_client_id);
  739. if (cl_pos->host_client_id == mei_hdr->host_addr &&
  740. cl_pos->me_client_id == mei_hdr->me_addr)
  741. break;
  742. }
  743. if (&cl_pos->link == &dev->file_list) {
  744. dev_dbg(&dev->pdev->dev, "corrupted message header\n");
  745. ret = -EBADMSG;
  746. goto end;
  747. }
  748. }
  749. if (((*slots) * sizeof(u32)) < mei_hdr->length) {
  750. dev_dbg(&dev->pdev->dev,
  751. "we can't read the message slots =%08x.\n",
  752. *slots);
  753. /* we can't read the message */
  754. ret = -ERANGE;
  755. goto end;
  756. }
  757. /* decide where to read the message too */
  758. if (!mei_hdr->host_addr) {
  759. dev_dbg(&dev->pdev->dev, "call mei_irq_thread_read_bus_message.\n");
  760. mei_irq_thread_read_bus_message(dev, mei_hdr);
  761. dev_dbg(&dev->pdev->dev, "end mei_irq_thread_read_bus_message.\n");
  762. } else if (mei_hdr->host_addr == dev->iamthif_cl.host_client_id &&
  763. (MEI_FILE_CONNECTED == dev->iamthif_cl.state) &&
  764. (dev->iamthif_state == MEI_IAMTHIF_READING)) {
  765. dev_dbg(&dev->pdev->dev, "call mei_irq_thread_read_iamthif_message.\n");
  766. dev_dbg(&dev->pdev->dev, "mei_hdr->length =%d\n",
  767. mei_hdr->length);
  768. ret = mei_amthif_irq_read_message(cmpl_list, dev, mei_hdr);
  769. if (ret)
  770. goto end;
  771. } else {
  772. dev_dbg(&dev->pdev->dev, "call mei_irq_thread_read_client_message.\n");
  773. ret = mei_irq_thread_read_client_message(cmpl_list,
  774. dev, mei_hdr);
  775. if (ret)
  776. goto end;
  777. }
  778. /* reset the number of slots and header */
  779. *slots = mei_count_full_read_slots(dev);
  780. dev->rd_msg_hdr = 0;
  781. if (*slots == -EOVERFLOW) {
  782. /* overflow - reset */
  783. dev_dbg(&dev->pdev->dev, "resetting due to slots overflow.\n");
  784. /* set the event since message has been read */
  785. ret = -ERANGE;
  786. goto end;
  787. }
  788. end:
  789. return ret;
  790. }
  791. /**
  792. * mei_irq_thread_write_handler - bottom half write routine after
  793. * ISR to handle the write processing.
  794. *
  795. * @dev: the device structure
  796. * @cmpl_list: An instance of our list structure
  797. *
  798. * returns 0 on success, <0 on failure.
  799. */
  800. static int mei_irq_thread_write_handler(struct mei_device *dev,
  801. struct mei_cl_cb *cmpl_list)
  802. {
  803. struct mei_cl *cl;
  804. struct mei_cl_cb *pos = NULL, *next = NULL;
  805. struct mei_cl_cb *list;
  806. s32 slots;
  807. int ret;
  808. if (!mei_hbuf_is_empty(dev)) {
  809. dev_dbg(&dev->pdev->dev, "host buffer is not empty.\n");
  810. return 0;
  811. }
  812. slots = mei_hbuf_empty_slots(dev);
  813. if (slots <= 0)
  814. return -EMSGSIZE;
  815. /* complete all waiting for write CB */
  816. dev_dbg(&dev->pdev->dev, "complete all waiting for write cb.\n");
  817. list = &dev->write_waiting_list;
  818. list_for_each_entry_safe(pos, next, &list->list, list) {
  819. cl = pos->cl;
  820. if (cl == NULL)
  821. continue;
  822. cl->status = 0;
  823. list_del(&pos->list);
  824. if (MEI_WRITING == cl->writing_state &&
  825. pos->fop_type == MEI_FOP_WRITE &&
  826. cl != &dev->iamthif_cl) {
  827. dev_dbg(&dev->pdev->dev, "MEI WRITE COMPLETE\n");
  828. cl->writing_state = MEI_WRITE_COMPLETE;
  829. list_add_tail(&pos->list, &cmpl_list->list);
  830. }
  831. if (cl == &dev->iamthif_cl) {
  832. dev_dbg(&dev->pdev->dev, "check iamthif flow control.\n");
  833. if (dev->iamthif_flow_control_pending) {
  834. ret = mei_amthif_irq_read(dev, &slots);
  835. if (ret)
  836. return ret;
  837. }
  838. }
  839. }
  840. if (dev->wd_state == MEI_WD_STOPPING) {
  841. dev->wd_state = MEI_WD_IDLE;
  842. wake_up_interruptible(&dev->wait_stop_wd);
  843. }
  844. if (dev->wr_ext_msg.hdr.length) {
  845. mei_write_message(dev, &dev->wr_ext_msg.hdr,
  846. dev->wr_ext_msg.data, dev->wr_ext_msg.hdr.length);
  847. slots -= mei_data2slots(dev->wr_ext_msg.hdr.length);
  848. dev->wr_ext_msg.hdr.length = 0;
  849. }
  850. if (dev->dev_state == MEI_DEV_ENABLED) {
  851. if (dev->wd_pending &&
  852. mei_flow_ctrl_creds(dev, &dev->wd_cl) > 0) {
  853. if (mei_wd_send(dev))
  854. dev_dbg(&dev->pdev->dev, "wd send failed.\n");
  855. else if (mei_flow_ctrl_reduce(dev, &dev->wd_cl))
  856. return -ENODEV;
  857. dev->wd_pending = false;
  858. if (dev->wd_state == MEI_WD_RUNNING)
  859. slots -= mei_data2slots(MEI_WD_START_MSG_SIZE);
  860. else
  861. slots -= mei_data2slots(MEI_WD_STOP_MSG_SIZE);
  862. }
  863. }
  864. /* complete control write list CB */
  865. dev_dbg(&dev->pdev->dev, "complete control write list cb.\n");
  866. list_for_each_entry_safe(pos, next, &dev->ctrl_wr_list.list, list) {
  867. cl = pos->cl;
  868. if (!cl) {
  869. list_del(&pos->list);
  870. return -ENODEV;
  871. }
  872. switch (pos->fop_type) {
  873. case MEI_FOP_CLOSE:
  874. /* send disconnect message */
  875. ret = _mei_irq_thread_close(dev, &slots, pos,
  876. cl, cmpl_list);
  877. if (ret)
  878. return ret;
  879. break;
  880. case MEI_FOP_READ:
  881. /* send flow control message */
  882. ret = _mei_irq_thread_read(dev, &slots, pos,
  883. cl, cmpl_list);
  884. if (ret)
  885. return ret;
  886. break;
  887. case MEI_FOP_IOCTL:
  888. /* connect message */
  889. if (mei_other_client_is_connecting(dev, cl))
  890. continue;
  891. ret = _mei_irq_thread_ioctl(dev, &slots, pos,
  892. cl, cmpl_list);
  893. if (ret)
  894. return ret;
  895. break;
  896. default:
  897. BUG();
  898. }
  899. }
  900. /* complete write list CB */
  901. dev_dbg(&dev->pdev->dev, "complete write list cb.\n");
  902. list_for_each_entry_safe(pos, next, &dev->write_list.list, list) {
  903. cl = pos->cl;
  904. if (cl == NULL)
  905. continue;
  906. if (mei_flow_ctrl_creds(dev, cl) <= 0) {
  907. dev_dbg(&dev->pdev->dev,
  908. "No flow control credentials for client %d, not sending.\n",
  909. cl->host_client_id);
  910. continue;
  911. }
  912. if (cl == &dev->iamthif_cl)
  913. ret = mei_amthif_irq_write_complete(dev, &slots,
  914. pos, cmpl_list);
  915. else
  916. ret = mei_irq_thread_write_complete(dev, &slots, pos,
  917. cmpl_list);
  918. if (ret)
  919. return ret;
  920. }
  921. return 0;
  922. }
  923. /**
  924. * mei_timer - timer function.
  925. *
  926. * @work: pointer to the work_struct structure
  927. *
  928. * NOTE: This function is called by timer interrupt work
  929. */
  930. void mei_timer(struct work_struct *work)
  931. {
  932. unsigned long timeout;
  933. struct mei_cl *cl_pos = NULL;
  934. struct mei_cl *cl_next = NULL;
  935. struct mei_cl_cb *cb_pos = NULL;
  936. struct mei_cl_cb *cb_next = NULL;
  937. struct mei_device *dev = container_of(work,
  938. struct mei_device, timer_work.work);
  939. mutex_lock(&dev->device_lock);
  940. if (dev->dev_state != MEI_DEV_ENABLED) {
  941. if (dev->dev_state == MEI_DEV_INIT_CLIENTS) {
  942. if (dev->init_clients_timer) {
  943. if (--dev->init_clients_timer == 0) {
  944. dev_dbg(&dev->pdev->dev, "IMEI reset due to init clients timeout ,init clients state = %d.\n",
  945. dev->init_clients_state);
  946. mei_reset(dev, 1);
  947. }
  948. }
  949. }
  950. goto out;
  951. }
  952. /*** connect/disconnect timeouts ***/
  953. list_for_each_entry_safe(cl_pos, cl_next, &dev->file_list, link) {
  954. if (cl_pos->timer_count) {
  955. if (--cl_pos->timer_count == 0) {
  956. dev_dbg(&dev->pdev->dev, "HECI reset due to connect/disconnect timeout.\n");
  957. mei_reset(dev, 1);
  958. goto out;
  959. }
  960. }
  961. }
  962. if (dev->iamthif_stall_timer) {
  963. if (--dev->iamthif_stall_timer == 0) {
  964. dev_dbg(&dev->pdev->dev, "resetting because of hang to amthi.\n");
  965. mei_reset(dev, 1);
  966. dev->iamthif_msg_buf_size = 0;
  967. dev->iamthif_msg_buf_index = 0;
  968. dev->iamthif_canceled = false;
  969. dev->iamthif_ioctl = true;
  970. dev->iamthif_state = MEI_IAMTHIF_IDLE;
  971. dev->iamthif_timer = 0;
  972. mei_io_cb_free(dev->iamthif_current_cb);
  973. dev->iamthif_current_cb = NULL;
  974. dev->iamthif_file_object = NULL;
  975. mei_amthif_run_next_cmd(dev);
  976. }
  977. }
  978. if (dev->iamthif_timer) {
  979. timeout = dev->iamthif_timer +
  980. mei_secs_to_jiffies(MEI_IAMTHIF_READ_TIMER);
  981. dev_dbg(&dev->pdev->dev, "dev->iamthif_timer = %ld\n",
  982. dev->iamthif_timer);
  983. dev_dbg(&dev->pdev->dev, "timeout = %ld\n", timeout);
  984. dev_dbg(&dev->pdev->dev, "jiffies = %ld\n", jiffies);
  985. if (time_after(jiffies, timeout)) {
  986. /*
  987. * User didn't read the AMTHI data on time (15sec)
  988. * freeing AMTHI for other requests
  989. */
  990. dev_dbg(&dev->pdev->dev, "freeing AMTHI for other requests\n");
  991. list_for_each_entry_safe(cb_pos, cb_next,
  992. &dev->amthif_rd_complete_list.list, list) {
  993. cl_pos = cb_pos->file_object->private_data;
  994. /* Finding the AMTHI entry. */
  995. if (cl_pos == &dev->iamthif_cl)
  996. list_del(&cb_pos->list);
  997. }
  998. mei_io_cb_free(dev->iamthif_current_cb);
  999. dev->iamthif_current_cb = NULL;
  1000. dev->iamthif_file_object->private_data = NULL;
  1001. dev->iamthif_file_object = NULL;
  1002. dev->iamthif_timer = 0;
  1003. mei_amthif_run_next_cmd(dev);
  1004. }
  1005. }
  1006. out:
  1007. schedule_delayed_work(&dev->timer_work, 2 * HZ);
  1008. mutex_unlock(&dev->device_lock);
  1009. }
  1010. /**
  1011. * mei_interrupt_thread_handler - function called after ISR to handle the interrupt
  1012. * processing.
  1013. *
  1014. * @irq: The irq number
  1015. * @dev_id: pointer to the device structure
  1016. *
  1017. * returns irqreturn_t
  1018. *
  1019. */
  1020. irqreturn_t mei_interrupt_thread_handler(int irq, void *dev_id)
  1021. {
  1022. struct mei_device *dev = (struct mei_device *) dev_id;
  1023. struct mei_cl_cb complete_list;
  1024. struct mei_cl_cb *cb_pos = NULL, *cb_next = NULL;
  1025. struct mei_cl *cl;
  1026. s32 slots;
  1027. int rets;
  1028. bool bus_message_received;
  1029. dev_dbg(&dev->pdev->dev, "function called after ISR to handle the interrupt processing.\n");
  1030. /* initialize our complete list */
  1031. mutex_lock(&dev->device_lock);
  1032. mei_io_list_init(&complete_list);
  1033. dev->host_hw_state = mei_hcsr_read(dev);
  1034. /* Ack the interrupt here
  1035. * In case of MSI we don't go through the quick handler */
  1036. if (pci_dev_msi_enabled(dev->pdev))
  1037. mei_reg_write(dev, H_CSR, dev->host_hw_state);
  1038. dev->me_hw_state = mei_mecsr_read(dev);
  1039. /* check if ME wants a reset */
  1040. if ((dev->me_hw_state & ME_RDY_HRA) == 0 &&
  1041. dev->dev_state != MEI_DEV_RESETING &&
  1042. dev->dev_state != MEI_DEV_INITIALIZING) {
  1043. dev_dbg(&dev->pdev->dev, "FW not ready.\n");
  1044. mei_reset(dev, 1);
  1045. mutex_unlock(&dev->device_lock);
  1046. return IRQ_HANDLED;
  1047. }
  1048. /* check if we need to start the dev */
  1049. if ((dev->host_hw_state & H_RDY) == 0) {
  1050. if ((dev->me_hw_state & ME_RDY_HRA) == ME_RDY_HRA) {
  1051. dev_dbg(&dev->pdev->dev, "we need to start the dev.\n");
  1052. dev->host_hw_state |= (H_IE | H_IG | H_RDY);
  1053. mei_hcsr_set(dev);
  1054. dev->dev_state = MEI_DEV_INIT_CLIENTS;
  1055. dev_dbg(&dev->pdev->dev, "link is established start sending messages.\n");
  1056. /* link is established
  1057. * start sending messages.
  1058. */
  1059. mei_host_start_message(dev);
  1060. mutex_unlock(&dev->device_lock);
  1061. return IRQ_HANDLED;
  1062. } else {
  1063. dev_dbg(&dev->pdev->dev, "FW not ready.\n");
  1064. mutex_unlock(&dev->device_lock);
  1065. return IRQ_HANDLED;
  1066. }
  1067. }
  1068. /* check slots available for reading */
  1069. slots = mei_count_full_read_slots(dev);
  1070. while (slots > 0) {
  1071. /* we have urgent data to send so break the read */
  1072. if (dev->wr_ext_msg.hdr.length)
  1073. break;
  1074. dev_dbg(&dev->pdev->dev, "slots =%08x\n", slots);
  1075. dev_dbg(&dev->pdev->dev, "call mei_irq_thread_read_handler.\n");
  1076. rets = mei_irq_thread_read_handler(&complete_list, dev, &slots);
  1077. if (rets)
  1078. goto end;
  1079. }
  1080. rets = mei_irq_thread_write_handler(dev, &complete_list);
  1081. end:
  1082. dev_dbg(&dev->pdev->dev, "end of bottom half function.\n");
  1083. dev->host_hw_state = mei_hcsr_read(dev);
  1084. dev->mei_host_buffer_is_empty = mei_hbuf_is_empty(dev);
  1085. bus_message_received = false;
  1086. if (dev->recvd_msg && waitqueue_active(&dev->wait_recvd_msg)) {
  1087. dev_dbg(&dev->pdev->dev, "received waiting bus message\n");
  1088. bus_message_received = true;
  1089. }
  1090. mutex_unlock(&dev->device_lock);
  1091. if (bus_message_received) {
  1092. dev_dbg(&dev->pdev->dev, "wake up dev->wait_recvd_msg\n");
  1093. wake_up_interruptible(&dev->wait_recvd_msg);
  1094. bus_message_received = false;
  1095. }
  1096. if (list_empty(&complete_list.list))
  1097. return IRQ_HANDLED;
  1098. list_for_each_entry_safe(cb_pos, cb_next, &complete_list.list, list) {
  1099. cl = cb_pos->cl;
  1100. list_del(&cb_pos->list);
  1101. if (cl) {
  1102. if (cl != &dev->iamthif_cl) {
  1103. dev_dbg(&dev->pdev->dev, "completing call back.\n");
  1104. _mei_cmpl(cl, cb_pos);
  1105. cb_pos = NULL;
  1106. } else if (cl == &dev->iamthif_cl) {
  1107. mei_amthif_complete(dev, cb_pos);
  1108. }
  1109. }
  1110. }
  1111. return IRQ_HANDLED;
  1112. }