interrupt.c 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334
  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->major_file_operations == MEI_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->major_file_operations == MEI_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 = (struct mei_cl *)cb_pos->file_private;
  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_disconnect_request)))
  155. return -EBADMSG;
  156. *slots -= mei_data2slots(sizeof(struct hbm_client_disconnect_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 = (struct mei_cl *)pos->file_private;
  229. if (!cl) {
  230. list_del(&pos->list);
  231. return;
  232. }
  233. if (MEI_IOCTL == pos->major_file_operations) {
  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 = (struct mei_cl *)pos->file_private;
  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_disconnect_request *disconn)
  366. {
  367. return (cl->host_client_id == disconn->host_addr &&
  368. cl->me_client_id == disconn->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_disconnect_request *disconnect_req)
  378. {
  379. struct mei_msg_hdr *mei_hdr;
  380. struct hbm_client_connect_response *disconnect_res;
  381. struct mei_cl *cl_pos = NULL;
  382. struct mei_cl *cl_next = NULL;
  383. list_for_each_entry_safe(cl_pos, cl_next, &dev->file_list, link) {
  384. if (same_disconn_addr(cl_pos, disconnect_req)) {
  385. dev_dbg(&dev->pdev->dev, "disconnect request host client %d ME client %d.\n",
  386. disconnect_req->host_addr,
  387. disconnect_req->me_addr);
  388. cl_pos->state = MEI_FILE_DISCONNECTED;
  389. cl_pos->timer_count = 0;
  390. if (cl_pos == &dev->wd_cl)
  391. dev->wd_pending = false;
  392. else if (cl_pos == &dev->iamthif_cl)
  393. dev->iamthif_timer = 0;
  394. /* prepare disconnect response */
  395. mei_hdr =
  396. (struct mei_msg_hdr *) &dev->ext_msg_buf[0];
  397. mei_hdr->host_addr = 0;
  398. mei_hdr->me_addr = 0;
  399. mei_hdr->length =
  400. sizeof(struct hbm_client_connect_response);
  401. mei_hdr->msg_complete = 1;
  402. mei_hdr->reserved = 0;
  403. disconnect_res =
  404. (struct hbm_client_connect_response *)
  405. &dev->ext_msg_buf[1];
  406. disconnect_res->host_addr = cl_pos->host_client_id;
  407. disconnect_res->me_addr = cl_pos->me_client_id;
  408. disconnect_res->hbm_cmd = CLIENT_DISCONNECT_RES_CMD;
  409. disconnect_res->status = 0;
  410. dev->extra_write_index = 2;
  411. break;
  412. }
  413. }
  414. }
  415. /**
  416. * mei_irq_thread_read_bus_message - bottom half read routine after ISR to
  417. * handle the read bus message cmd processing.
  418. *
  419. * @dev: the device structure
  420. * @mei_hdr: header of bus message
  421. */
  422. static void mei_irq_thread_read_bus_message(struct mei_device *dev,
  423. struct mei_msg_hdr *mei_hdr)
  424. {
  425. struct mei_bus_message *mei_msg;
  426. struct hbm_host_version_response *version_res;
  427. struct hbm_client_connect_response *connect_res;
  428. struct hbm_client_connect_response *disconnect_res;
  429. struct hbm_flow_control *flow_control;
  430. struct hbm_props_response *props_res;
  431. struct hbm_host_enum_response *enum_res;
  432. struct hbm_client_disconnect_request *disconnect_req;
  433. struct hbm_host_stop_request *host_stop_req;
  434. int res;
  435. /* read the message to our buffer */
  436. BUG_ON(mei_hdr->length >= sizeof(dev->rd_msg_buf));
  437. mei_read_slots(dev, dev->rd_msg_buf, mei_hdr->length);
  438. mei_msg = (struct mei_bus_message *)dev->rd_msg_buf;
  439. switch (mei_msg->hbm_cmd) {
  440. case HOST_START_RES_CMD:
  441. version_res = (struct hbm_host_version_response *) mei_msg;
  442. if (version_res->host_version_supported) {
  443. dev->version.major_version = HBM_MAJOR_VERSION;
  444. dev->version.minor_version = HBM_MINOR_VERSION;
  445. if (dev->dev_state == MEI_DEV_INIT_CLIENTS &&
  446. dev->init_clients_state == MEI_START_MESSAGE) {
  447. dev->init_clients_timer = 0;
  448. mei_host_enum_clients_message(dev);
  449. } else {
  450. dev->recvd_msg = false;
  451. dev_dbg(&dev->pdev->dev, "IMEI reset due to received host start response bus message.\n");
  452. mei_reset(dev, 1);
  453. return;
  454. }
  455. } else {
  456. dev->version = version_res->me_max_version;
  457. /* send stop message */
  458. mei_hdr = (struct mei_msg_hdr *)&dev->wr_msg_buf[0];
  459. mei_hdr->host_addr = 0;
  460. mei_hdr->me_addr = 0;
  461. mei_hdr->length = sizeof(struct hbm_host_stop_request);
  462. mei_hdr->msg_complete = 1;
  463. mei_hdr->reserved = 0;
  464. host_stop_req = (struct hbm_host_stop_request *)
  465. &dev->wr_msg_buf[1];
  466. memset(host_stop_req,
  467. 0,
  468. sizeof(struct hbm_host_stop_request));
  469. host_stop_req->hbm_cmd = HOST_STOP_REQ_CMD;
  470. host_stop_req->reason = DRIVER_STOP_REQUEST;
  471. mei_write_message(dev, mei_hdr,
  472. (unsigned char *) (host_stop_req),
  473. mei_hdr->length);
  474. dev_dbg(&dev->pdev->dev, "version mismatch.\n");
  475. return;
  476. }
  477. dev->recvd_msg = true;
  478. dev_dbg(&dev->pdev->dev, "host start response message received.\n");
  479. break;
  480. case CLIENT_CONNECT_RES_CMD:
  481. connect_res =
  482. (struct hbm_client_connect_response *) mei_msg;
  483. mei_client_connect_response(dev, connect_res);
  484. dev_dbg(&dev->pdev->dev, "client connect response message received.\n");
  485. wake_up(&dev->wait_recvd_msg);
  486. break;
  487. case CLIENT_DISCONNECT_RES_CMD:
  488. disconnect_res =
  489. (struct hbm_client_connect_response *) mei_msg;
  490. mei_client_disconnect_response(dev, disconnect_res);
  491. dev_dbg(&dev->pdev->dev, "client disconnect response message received.\n");
  492. wake_up(&dev->wait_recvd_msg);
  493. break;
  494. case MEI_FLOW_CONTROL_CMD:
  495. flow_control = (struct hbm_flow_control *) mei_msg;
  496. mei_client_flow_control_response(dev, flow_control);
  497. dev_dbg(&dev->pdev->dev, "client flow control response message received.\n");
  498. break;
  499. case HOST_CLIENT_PROPERTIES_RES_CMD:
  500. props_res = (struct hbm_props_response *)mei_msg;
  501. if (props_res->status || !dev->me_clients) {
  502. dev_dbg(&dev->pdev->dev, "reset due to received host client properties response bus message wrong status.\n");
  503. mei_reset(dev, 1);
  504. return;
  505. }
  506. if (dev->me_clients[dev->me_client_presentation_num]
  507. .client_id == props_res->address) {
  508. dev->me_clients[dev->me_client_presentation_num].props
  509. = props_res->client_properties;
  510. if (dev->dev_state == MEI_DEV_INIT_CLIENTS &&
  511. dev->init_clients_state ==
  512. MEI_CLIENT_PROPERTIES_MESSAGE) {
  513. dev->me_client_index++;
  514. dev->me_client_presentation_num++;
  515. /** Send Client Properties request **/
  516. res = mei_host_client_properties(dev);
  517. if (res < 0) {
  518. dev_dbg(&dev->pdev->dev, "mei_host_client_properties() failed");
  519. return;
  520. } else if (!res) {
  521. /*
  522. * No more clients to send to.
  523. * Clear Map for indicating now ME clients
  524. * with associated host client
  525. */
  526. bitmap_zero(dev->host_clients_map, MEI_CLIENTS_MAX);
  527. dev->open_handle_count = 0;
  528. /*
  529. * Reserving the first three client IDs
  530. * Client Id 0 - Reserved for MEI Bus Message communications
  531. * Client Id 1 - Reserved for Watchdog
  532. * Client ID 2 - Reserved for AMTHI
  533. */
  534. bitmap_set(dev->host_clients_map, 0, 3);
  535. dev->dev_state = MEI_DEV_ENABLED;
  536. /* if wd initialization fails, initialization the AMTHI client,
  537. * otherwise the AMTHI client will be initialized after the WD client connect response
  538. * will be received
  539. */
  540. if (mei_wd_host_init(dev))
  541. mei_amthif_host_init(dev);
  542. }
  543. } else {
  544. dev_dbg(&dev->pdev->dev, "reset due to received host client properties response bus message");
  545. mei_reset(dev, 1);
  546. return;
  547. }
  548. } else {
  549. dev_dbg(&dev->pdev->dev, "reset due to received host client properties response bus message for wrong client ID\n");
  550. mei_reset(dev, 1);
  551. return;
  552. }
  553. break;
  554. case HOST_ENUM_RES_CMD:
  555. enum_res = (struct hbm_host_enum_response *) mei_msg;
  556. memcpy(dev->me_clients_map, enum_res->valid_addresses, 32);
  557. if (dev->dev_state == MEI_DEV_INIT_CLIENTS &&
  558. dev->init_clients_state == MEI_ENUM_CLIENTS_MESSAGE) {
  559. dev->init_clients_timer = 0;
  560. dev->me_client_presentation_num = 0;
  561. dev->me_client_index = 0;
  562. mei_allocate_me_clients_storage(dev);
  563. dev->init_clients_state =
  564. MEI_CLIENT_PROPERTIES_MESSAGE;
  565. mei_host_client_properties(dev);
  566. } else {
  567. dev_dbg(&dev->pdev->dev, "reset due to received host enumeration clients response bus message.\n");
  568. mei_reset(dev, 1);
  569. return;
  570. }
  571. break;
  572. case HOST_STOP_RES_CMD:
  573. dev->dev_state = MEI_DEV_DISABLED;
  574. dev_dbg(&dev->pdev->dev, "resetting because of FW stop response.\n");
  575. mei_reset(dev, 1);
  576. break;
  577. case CLIENT_DISCONNECT_REQ_CMD:
  578. /* search for client */
  579. disconnect_req =
  580. (struct hbm_client_disconnect_request *) mei_msg;
  581. mei_client_disconnect_request(dev, disconnect_req);
  582. break;
  583. case ME_STOP_REQ_CMD:
  584. /* prepare stop request */
  585. mei_hdr = (struct mei_msg_hdr *) &dev->ext_msg_buf[0];
  586. mei_hdr->host_addr = 0;
  587. mei_hdr->me_addr = 0;
  588. mei_hdr->length = sizeof(struct hbm_host_stop_request);
  589. mei_hdr->msg_complete = 1;
  590. mei_hdr->reserved = 0;
  591. host_stop_req =
  592. (struct hbm_host_stop_request *) &dev->ext_msg_buf[1];
  593. memset(host_stop_req, 0, sizeof(struct hbm_host_stop_request));
  594. host_stop_req->hbm_cmd = HOST_STOP_REQ_CMD;
  595. host_stop_req->reason = DRIVER_STOP_REQUEST;
  596. host_stop_req->reserved[0] = 0;
  597. host_stop_req->reserved[1] = 0;
  598. dev->extra_write_index = 2;
  599. break;
  600. default:
  601. BUG();
  602. break;
  603. }
  604. }
  605. /**
  606. * _mei_hb_read - processes read related operation.
  607. *
  608. * @dev: the device structure.
  609. * @slots: free slots.
  610. * @cb_pos: callback block.
  611. * @cl: private data of the file object.
  612. * @cmpl_list: complete list.
  613. *
  614. * returns 0, OK; otherwise, error.
  615. */
  616. static int _mei_irq_thread_read(struct mei_device *dev, s32 *slots,
  617. struct mei_cl_cb *cb_pos,
  618. struct mei_cl *cl,
  619. struct mei_cl_cb *cmpl_list)
  620. {
  621. if ((*slots * sizeof(u32)) < (sizeof(struct mei_msg_hdr) +
  622. sizeof(struct hbm_flow_control))) {
  623. /* return the cancel routine */
  624. list_del(&cb_pos->list);
  625. return -EBADMSG;
  626. }
  627. *slots -= mei_data2slots(sizeof(struct hbm_flow_control));
  628. if (mei_send_flow_control(dev, cl)) {
  629. cl->status = -ENODEV;
  630. cb_pos->buf_idx = 0;
  631. list_move_tail(&cb_pos->list, &cmpl_list->list);
  632. return -ENODEV;
  633. }
  634. list_move_tail(&cb_pos->list, &dev->read_list.list);
  635. return 0;
  636. }
  637. /**
  638. * _mei_irq_thread_ioctl - processes ioctl related operation.
  639. *
  640. * @dev: the device structure.
  641. * @slots: free slots.
  642. * @cb_pos: callback block.
  643. * @cl: private data of the file object.
  644. * @cmpl_list: complete list.
  645. *
  646. * returns 0, OK; otherwise, error.
  647. */
  648. static int _mei_irq_thread_ioctl(struct mei_device *dev, s32 *slots,
  649. struct mei_cl_cb *cb_pos,
  650. struct mei_cl *cl,
  651. struct mei_cl_cb *cmpl_list)
  652. {
  653. if ((*slots * sizeof(u32)) < (sizeof(struct mei_msg_hdr) +
  654. sizeof(struct hbm_client_connect_request))) {
  655. /* return the cancel routine */
  656. list_del(&cb_pos->list);
  657. return -EBADMSG;
  658. }
  659. cl->state = MEI_FILE_CONNECTING;
  660. *slots -= mei_data2slots(sizeof(struct hbm_client_connect_request));
  661. if (mei_connect(dev, cl)) {
  662. cl->status = -ENODEV;
  663. cb_pos->buf_idx = 0;
  664. list_del(&cb_pos->list);
  665. return -ENODEV;
  666. } else {
  667. list_move_tail(&cb_pos->list, &dev->ctrl_rd_list.list);
  668. cl->timer_count = MEI_CONNECT_TIMEOUT;
  669. }
  670. return 0;
  671. }
  672. /**
  673. * _mei_irq_thread_cmpl - processes completed and no-iamthif operation.
  674. *
  675. * @dev: the device structure.
  676. * @slots: free slots.
  677. * @cb_pos: callback block.
  678. * @cl: private data of the file object.
  679. * @cmpl_list: complete list.
  680. *
  681. * returns 0, OK; otherwise, error.
  682. */
  683. static int _mei_irq_thread_cmpl(struct mei_device *dev, s32 *slots,
  684. struct mei_cl_cb *cb_pos,
  685. struct mei_cl *cl,
  686. struct mei_cl_cb *cmpl_list)
  687. {
  688. struct mei_msg_hdr *mei_hdr;
  689. if ((*slots * sizeof(u32)) >= (sizeof(struct mei_msg_hdr) +
  690. (cb_pos->request_buffer.size - cb_pos->buf_idx))) {
  691. mei_hdr = (struct mei_msg_hdr *) &dev->wr_msg_buf[0];
  692. mei_hdr->host_addr = cl->host_client_id;
  693. mei_hdr->me_addr = cl->me_client_id;
  694. mei_hdr->length = cb_pos->request_buffer.size - cb_pos->buf_idx;
  695. mei_hdr->msg_complete = 1;
  696. mei_hdr->reserved = 0;
  697. dev_dbg(&dev->pdev->dev, "cb_pos->request_buffer.size =%d"
  698. "mei_hdr->msg_complete = %d\n",
  699. cb_pos->request_buffer.size,
  700. mei_hdr->msg_complete);
  701. dev_dbg(&dev->pdev->dev, "cb_pos->buf_idx =%lu\n",
  702. cb_pos->buf_idx);
  703. dev_dbg(&dev->pdev->dev, "mei_hdr->length =%d\n",
  704. mei_hdr->length);
  705. *slots -= mei_data2slots(mei_hdr->length);
  706. if (mei_write_message(dev, mei_hdr,
  707. (unsigned char *)
  708. (cb_pos->request_buffer.data +
  709. cb_pos->buf_idx),
  710. mei_hdr->length)) {
  711. cl->status = -ENODEV;
  712. list_move_tail(&cb_pos->list, &cmpl_list->list);
  713. return -ENODEV;
  714. } else {
  715. if (mei_flow_ctrl_reduce(dev, cl))
  716. return -ENODEV;
  717. cl->status = 0;
  718. cb_pos->buf_idx += mei_hdr->length;
  719. list_move_tail(&cb_pos->list, &dev->write_waiting_list.list);
  720. }
  721. } else if (*slots == dev->hbuf_depth) {
  722. /* buffer is still empty */
  723. mei_hdr = (struct mei_msg_hdr *) &dev->wr_msg_buf[0];
  724. mei_hdr->host_addr = cl->host_client_id;
  725. mei_hdr->me_addr = cl->me_client_id;
  726. mei_hdr->length =
  727. (*slots * sizeof(u32)) - sizeof(struct mei_msg_hdr);
  728. mei_hdr->msg_complete = 0;
  729. mei_hdr->reserved = 0;
  730. *slots -= mei_data2slots(mei_hdr->length);
  731. if (mei_write_message(dev, mei_hdr,
  732. (unsigned char *)
  733. (cb_pos->request_buffer.data +
  734. cb_pos->buf_idx),
  735. mei_hdr->length)) {
  736. cl->status = -ENODEV;
  737. list_move_tail(&cb_pos->list, &cmpl_list->list);
  738. return -ENODEV;
  739. } else {
  740. cb_pos->buf_idx += mei_hdr->length;
  741. dev_dbg(&dev->pdev->dev,
  742. "cb_pos->request_buffer.size =%d"
  743. " mei_hdr->msg_complete = %d\n",
  744. cb_pos->request_buffer.size,
  745. mei_hdr->msg_complete);
  746. dev_dbg(&dev->pdev->dev, "cb_pos->buf_idx =%lu\n",
  747. cb_pos->buf_idx);
  748. dev_dbg(&dev->pdev->dev, "mei_hdr->length =%d\n",
  749. mei_hdr->length);
  750. }
  751. return -EMSGSIZE;
  752. } else {
  753. return -EBADMSG;
  754. }
  755. return 0;
  756. }
  757. /**
  758. * mei_irq_thread_read_handler - bottom half read routine after ISR to
  759. * handle the read processing.
  760. *
  761. * @cmpl_list: An instance of our list structure
  762. * @dev: the device structure
  763. * @slots: slots to read.
  764. *
  765. * returns 0 on success, <0 on failure.
  766. */
  767. static int mei_irq_thread_read_handler(struct mei_cl_cb *cmpl_list,
  768. struct mei_device *dev,
  769. s32 *slots)
  770. {
  771. struct mei_msg_hdr *mei_hdr;
  772. struct mei_cl *cl_pos = NULL;
  773. struct mei_cl *cl_next = NULL;
  774. int ret = 0;
  775. if (!dev->rd_msg_hdr) {
  776. dev->rd_msg_hdr = mei_mecbrw_read(dev);
  777. dev_dbg(&dev->pdev->dev, "slots =%08x.\n", *slots);
  778. (*slots)--;
  779. dev_dbg(&dev->pdev->dev, "slots =%08x.\n", *slots);
  780. }
  781. mei_hdr = (struct mei_msg_hdr *) &dev->rd_msg_hdr;
  782. dev_dbg(&dev->pdev->dev, "mei_hdr->length =%d\n", mei_hdr->length);
  783. if (mei_hdr->reserved || !dev->rd_msg_hdr) {
  784. dev_dbg(&dev->pdev->dev, "corrupted message header.\n");
  785. ret = -EBADMSG;
  786. goto end;
  787. }
  788. if (mei_hdr->host_addr || mei_hdr->me_addr) {
  789. list_for_each_entry_safe(cl_pos, cl_next,
  790. &dev->file_list, link) {
  791. dev_dbg(&dev->pdev->dev,
  792. "list_for_each_entry_safe read host"
  793. " client = %d, ME client = %d\n",
  794. cl_pos->host_client_id,
  795. cl_pos->me_client_id);
  796. if (cl_pos->host_client_id == mei_hdr->host_addr &&
  797. cl_pos->me_client_id == mei_hdr->me_addr)
  798. break;
  799. }
  800. if (&cl_pos->link == &dev->file_list) {
  801. dev_dbg(&dev->pdev->dev, "corrupted message header\n");
  802. ret = -EBADMSG;
  803. goto end;
  804. }
  805. }
  806. if (((*slots) * sizeof(u32)) < mei_hdr->length) {
  807. dev_dbg(&dev->pdev->dev,
  808. "we can't read the message slots =%08x.\n",
  809. *slots);
  810. /* we can't read the message */
  811. ret = -ERANGE;
  812. goto end;
  813. }
  814. /* decide where to read the message too */
  815. if (!mei_hdr->host_addr) {
  816. dev_dbg(&dev->pdev->dev, "call mei_irq_thread_read_bus_message.\n");
  817. mei_irq_thread_read_bus_message(dev, mei_hdr);
  818. dev_dbg(&dev->pdev->dev, "end mei_irq_thread_read_bus_message.\n");
  819. } else if (mei_hdr->host_addr == dev->iamthif_cl.host_client_id &&
  820. (MEI_FILE_CONNECTED == dev->iamthif_cl.state) &&
  821. (dev->iamthif_state == MEI_IAMTHIF_READING)) {
  822. dev_dbg(&dev->pdev->dev, "call mei_irq_thread_read_iamthif_message.\n");
  823. dev_dbg(&dev->pdev->dev, "mei_hdr->length =%d\n",
  824. mei_hdr->length);
  825. ret = mei_amthif_irq_read_message(cmpl_list, dev, mei_hdr);
  826. if (ret)
  827. goto end;
  828. } else {
  829. dev_dbg(&dev->pdev->dev, "call mei_irq_thread_read_client_message.\n");
  830. ret = mei_irq_thread_read_client_message(cmpl_list,
  831. dev, mei_hdr);
  832. if (ret)
  833. goto end;
  834. }
  835. /* reset the number of slots and header */
  836. *slots = mei_count_full_read_slots(dev);
  837. dev->rd_msg_hdr = 0;
  838. if (*slots == -EOVERFLOW) {
  839. /* overflow - reset */
  840. dev_dbg(&dev->pdev->dev, "resetting due to slots overflow.\n");
  841. /* set the event since message has been read */
  842. ret = -ERANGE;
  843. goto end;
  844. }
  845. end:
  846. return ret;
  847. }
  848. /**
  849. * mei_irq_thread_write_handler - bottom half write routine after
  850. * ISR to handle the write processing.
  851. *
  852. * @cmpl_list: An instance of our list structure
  853. * @dev: the device structure
  854. * @slots: slots to write.
  855. *
  856. * returns 0 on success, <0 on failure.
  857. */
  858. static int mei_irq_thread_write_handler(struct mei_cl_cb *cmpl_list,
  859. struct mei_device *dev, s32 *slots)
  860. {
  861. struct mei_cl *cl;
  862. struct mei_cl_cb *pos = NULL, *next = NULL;
  863. struct mei_cl_cb *list;
  864. int ret;
  865. if (!mei_hbuf_is_empty(dev)) {
  866. dev_dbg(&dev->pdev->dev, "host buffer is not empty.\n");
  867. return 0;
  868. }
  869. *slots = mei_hbuf_empty_slots(dev);
  870. if (*slots <= 0)
  871. return -EMSGSIZE;
  872. /* complete all waiting for write CB */
  873. dev_dbg(&dev->pdev->dev, "complete all waiting for write cb.\n");
  874. list = &dev->write_waiting_list;
  875. list_for_each_entry_safe(pos, next, &list->list, list) {
  876. cl = (struct mei_cl *)pos->file_private;
  877. if (cl == NULL)
  878. continue;
  879. cl->status = 0;
  880. list_del(&pos->list);
  881. if (MEI_WRITING == cl->writing_state &&
  882. (pos->major_file_operations == MEI_WRITE) &&
  883. (cl != &dev->iamthif_cl)) {
  884. dev_dbg(&dev->pdev->dev, "MEI WRITE COMPLETE\n");
  885. cl->writing_state = MEI_WRITE_COMPLETE;
  886. list_add_tail(&pos->list, &cmpl_list->list);
  887. }
  888. if (cl == &dev->iamthif_cl) {
  889. dev_dbg(&dev->pdev->dev, "check iamthif flow control.\n");
  890. if (dev->iamthif_flow_control_pending) {
  891. ret = mei_amthif_irq_read(dev, slots);
  892. if (ret)
  893. return ret;
  894. }
  895. }
  896. }
  897. if (dev->wd_state == MEI_WD_STOPPING) {
  898. dev->wd_state = MEI_WD_IDLE;
  899. wake_up_interruptible(&dev->wait_stop_wd);
  900. }
  901. if (dev->extra_write_index) {
  902. dev_dbg(&dev->pdev->dev, "extra_write_index =%d.\n",
  903. dev->extra_write_index);
  904. mei_write_message(dev,
  905. (struct mei_msg_hdr *) &dev->ext_msg_buf[0],
  906. (unsigned char *) &dev->ext_msg_buf[1],
  907. (dev->extra_write_index - 1) * sizeof(u32));
  908. *slots -= dev->extra_write_index;
  909. dev->extra_write_index = 0;
  910. }
  911. if (dev->dev_state == MEI_DEV_ENABLED) {
  912. if (dev->wd_pending &&
  913. mei_flow_ctrl_creds(dev, &dev->wd_cl) > 0) {
  914. if (mei_wd_send(dev))
  915. dev_dbg(&dev->pdev->dev, "wd send failed.\n");
  916. else if (mei_flow_ctrl_reduce(dev, &dev->wd_cl))
  917. return -ENODEV;
  918. dev->wd_pending = false;
  919. if (dev->wd_state == MEI_WD_RUNNING)
  920. *slots -= mei_data2slots(MEI_WD_START_MSG_SIZE);
  921. else
  922. *slots -= mei_data2slots(MEI_WD_STOP_MSG_SIZE);
  923. }
  924. }
  925. /* complete control write list CB */
  926. dev_dbg(&dev->pdev->dev, "complete control write list cb.\n");
  927. list_for_each_entry_safe(pos, next, &dev->ctrl_wr_list.list, list) {
  928. cl = (struct mei_cl *) pos->file_private;
  929. if (!cl) {
  930. list_del(&pos->list);
  931. return -ENODEV;
  932. }
  933. switch (pos->major_file_operations) {
  934. case MEI_CLOSE:
  935. /* send disconnect message */
  936. ret = _mei_irq_thread_close(dev, slots, pos, cl, cmpl_list);
  937. if (ret)
  938. return ret;
  939. break;
  940. case MEI_READ:
  941. /* send flow control message */
  942. ret = _mei_irq_thread_read(dev, slots, pos, cl, cmpl_list);
  943. if (ret)
  944. return ret;
  945. break;
  946. case MEI_IOCTL:
  947. /* connect message */
  948. if (mei_other_client_is_connecting(dev, cl))
  949. continue;
  950. ret = _mei_irq_thread_ioctl(dev, slots, pos, cl, cmpl_list);
  951. if (ret)
  952. return ret;
  953. break;
  954. default:
  955. BUG();
  956. }
  957. }
  958. /* complete write list CB */
  959. dev_dbg(&dev->pdev->dev, "complete write list cb.\n");
  960. list_for_each_entry_safe(pos, next, &dev->write_list.list, list) {
  961. cl = (struct mei_cl *)pos->file_private;
  962. if (cl == NULL)
  963. continue;
  964. if (cl != &dev->iamthif_cl) {
  965. if (mei_flow_ctrl_creds(dev, cl) <= 0) {
  966. dev_dbg(&dev->pdev->dev,
  967. "No flow control credentials for client %d, not sending.\n",
  968. cl->host_client_id);
  969. continue;
  970. }
  971. ret = _mei_irq_thread_cmpl(dev, slots, pos,
  972. cl, cmpl_list);
  973. if (ret)
  974. return ret;
  975. } else if (cl == &dev->iamthif_cl) {
  976. /* IAMTHIF IOCTL */
  977. dev_dbg(&dev->pdev->dev, "complete amthi write cb.\n");
  978. if (mei_flow_ctrl_creds(dev, cl) <= 0) {
  979. dev_dbg(&dev->pdev->dev,
  980. "No flow control credentials for amthi client %d.\n",
  981. cl->host_client_id);
  982. continue;
  983. }
  984. ret = mei_amthif_irq_process_completed(dev, slots, pos,
  985. cl, cmpl_list);
  986. if (ret)
  987. return ret;
  988. }
  989. }
  990. return 0;
  991. }
  992. /**
  993. * mei_timer - timer function.
  994. *
  995. * @work: pointer to the work_struct structure
  996. *
  997. * NOTE: This function is called by timer interrupt work
  998. */
  999. void mei_timer(struct work_struct *work)
  1000. {
  1001. unsigned long timeout;
  1002. struct mei_cl *cl_pos = NULL;
  1003. struct mei_cl *cl_next = NULL;
  1004. struct list_head *amthi_complete_list = NULL;
  1005. struct mei_cl_cb *cb_pos = NULL;
  1006. struct mei_cl_cb *cb_next = NULL;
  1007. struct mei_device *dev = container_of(work,
  1008. struct mei_device, timer_work.work);
  1009. mutex_lock(&dev->device_lock);
  1010. if (dev->dev_state != MEI_DEV_ENABLED) {
  1011. if (dev->dev_state == MEI_DEV_INIT_CLIENTS) {
  1012. if (dev->init_clients_timer) {
  1013. if (--dev->init_clients_timer == 0) {
  1014. dev_dbg(&dev->pdev->dev, "IMEI reset due to init clients timeout ,init clients state = %d.\n",
  1015. dev->init_clients_state);
  1016. mei_reset(dev, 1);
  1017. }
  1018. }
  1019. }
  1020. goto out;
  1021. }
  1022. /*** connect/disconnect timeouts ***/
  1023. list_for_each_entry_safe(cl_pos, cl_next, &dev->file_list, link) {
  1024. if (cl_pos->timer_count) {
  1025. if (--cl_pos->timer_count == 0) {
  1026. dev_dbg(&dev->pdev->dev, "HECI reset due to connect/disconnect timeout.\n");
  1027. mei_reset(dev, 1);
  1028. goto out;
  1029. }
  1030. }
  1031. }
  1032. if (dev->iamthif_stall_timer) {
  1033. if (--dev->iamthif_stall_timer == 0) {
  1034. dev_dbg(&dev->pdev->dev, "resetting because of hang to amthi.\n");
  1035. mei_reset(dev, 1);
  1036. dev->iamthif_msg_buf_size = 0;
  1037. dev->iamthif_msg_buf_index = 0;
  1038. dev->iamthif_canceled = false;
  1039. dev->iamthif_ioctl = true;
  1040. dev->iamthif_state = MEI_IAMTHIF_IDLE;
  1041. dev->iamthif_timer = 0;
  1042. mei_io_cb_free(dev->iamthif_current_cb);
  1043. dev->iamthif_current_cb = NULL;
  1044. dev->iamthif_file_object = NULL;
  1045. mei_amthif_run_next_cmd(dev);
  1046. }
  1047. }
  1048. if (dev->iamthif_timer) {
  1049. timeout = dev->iamthif_timer +
  1050. mei_secs_to_jiffies(MEI_IAMTHIF_READ_TIMER);
  1051. dev_dbg(&dev->pdev->dev, "dev->iamthif_timer = %ld\n",
  1052. dev->iamthif_timer);
  1053. dev_dbg(&dev->pdev->dev, "timeout = %ld\n", timeout);
  1054. dev_dbg(&dev->pdev->dev, "jiffies = %ld\n", jiffies);
  1055. if (time_after(jiffies, timeout)) {
  1056. /*
  1057. * User didn't read the AMTHI data on time (15sec)
  1058. * freeing AMTHI for other requests
  1059. */
  1060. dev_dbg(&dev->pdev->dev, "freeing AMTHI for other requests\n");
  1061. amthi_complete_list = &dev->amthi_read_complete_list.list;
  1062. list_for_each_entry_safe(cb_pos, cb_next, amthi_complete_list, list) {
  1063. cl_pos = cb_pos->file_object->private_data;
  1064. /* Finding the AMTHI entry. */
  1065. if (cl_pos == &dev->iamthif_cl)
  1066. list_del(&cb_pos->list);
  1067. }
  1068. mei_io_cb_free(dev->iamthif_current_cb);
  1069. dev->iamthif_current_cb = NULL;
  1070. dev->iamthif_file_object->private_data = NULL;
  1071. dev->iamthif_file_object = NULL;
  1072. dev->iamthif_timer = 0;
  1073. mei_amthif_run_next_cmd(dev);
  1074. }
  1075. }
  1076. out:
  1077. schedule_delayed_work(&dev->timer_work, 2 * HZ);
  1078. mutex_unlock(&dev->device_lock);
  1079. }
  1080. /**
  1081. * mei_interrupt_thread_handler - function called after ISR to handle the interrupt
  1082. * processing.
  1083. *
  1084. * @irq: The irq number
  1085. * @dev_id: pointer to the device structure
  1086. *
  1087. * returns irqreturn_t
  1088. *
  1089. */
  1090. irqreturn_t mei_interrupt_thread_handler(int irq, void *dev_id)
  1091. {
  1092. struct mei_device *dev = (struct mei_device *) dev_id;
  1093. struct mei_cl_cb complete_list;
  1094. struct mei_cl_cb *cb_pos = NULL, *cb_next = NULL;
  1095. struct mei_cl *cl;
  1096. s32 slots;
  1097. int rets;
  1098. bool bus_message_received;
  1099. dev_dbg(&dev->pdev->dev, "function called after ISR to handle the interrupt processing.\n");
  1100. /* initialize our complete list */
  1101. mutex_lock(&dev->device_lock);
  1102. mei_io_list_init(&complete_list);
  1103. dev->host_hw_state = mei_hcsr_read(dev);
  1104. /* Ack the interrupt here
  1105. * In case of MSI we don't go through the quick handler */
  1106. if (pci_dev_msi_enabled(dev->pdev))
  1107. mei_reg_write(dev, H_CSR, dev->host_hw_state);
  1108. dev->me_hw_state = mei_mecsr_read(dev);
  1109. /* check if ME wants a reset */
  1110. if ((dev->me_hw_state & ME_RDY_HRA) == 0 &&
  1111. dev->dev_state != MEI_DEV_RESETING &&
  1112. dev->dev_state != MEI_DEV_INITIALIZING) {
  1113. dev_dbg(&dev->pdev->dev, "FW not ready.\n");
  1114. mei_reset(dev, 1);
  1115. mutex_unlock(&dev->device_lock);
  1116. return IRQ_HANDLED;
  1117. }
  1118. /* check if we need to start the dev */
  1119. if ((dev->host_hw_state & H_RDY) == 0) {
  1120. if ((dev->me_hw_state & ME_RDY_HRA) == ME_RDY_HRA) {
  1121. dev_dbg(&dev->pdev->dev, "we need to start the dev.\n");
  1122. dev->host_hw_state |= (H_IE | H_IG | H_RDY);
  1123. mei_hcsr_set(dev);
  1124. dev->dev_state = MEI_DEV_INIT_CLIENTS;
  1125. dev_dbg(&dev->pdev->dev, "link is established start sending messages.\n");
  1126. /* link is established
  1127. * start sending messages.
  1128. */
  1129. mei_host_start_message(dev);
  1130. mutex_unlock(&dev->device_lock);
  1131. return IRQ_HANDLED;
  1132. } else {
  1133. dev_dbg(&dev->pdev->dev, "FW not ready.\n");
  1134. mutex_unlock(&dev->device_lock);
  1135. return IRQ_HANDLED;
  1136. }
  1137. }
  1138. /* check slots available for reading */
  1139. slots = mei_count_full_read_slots(dev);
  1140. dev_dbg(&dev->pdev->dev, "slots =%08x extra_write_index =%08x.\n",
  1141. slots, dev->extra_write_index);
  1142. while (slots > 0 && !dev->extra_write_index) {
  1143. dev_dbg(&dev->pdev->dev, "slots =%08x extra_write_index =%08x.\n",
  1144. slots, dev->extra_write_index);
  1145. dev_dbg(&dev->pdev->dev, "call mei_irq_thread_read_handler.\n");
  1146. rets = mei_irq_thread_read_handler(&complete_list, dev, &slots);
  1147. if (rets)
  1148. goto end;
  1149. }
  1150. rets = mei_irq_thread_write_handler(&complete_list, dev, &slots);
  1151. end:
  1152. dev_dbg(&dev->pdev->dev, "end of bottom half function.\n");
  1153. dev->host_hw_state = mei_hcsr_read(dev);
  1154. dev->mei_host_buffer_is_empty = mei_hbuf_is_empty(dev);
  1155. bus_message_received = false;
  1156. if (dev->recvd_msg && waitqueue_active(&dev->wait_recvd_msg)) {
  1157. dev_dbg(&dev->pdev->dev, "received waiting bus message\n");
  1158. bus_message_received = true;
  1159. }
  1160. mutex_unlock(&dev->device_lock);
  1161. if (bus_message_received) {
  1162. dev_dbg(&dev->pdev->dev, "wake up dev->wait_recvd_msg\n");
  1163. wake_up_interruptible(&dev->wait_recvd_msg);
  1164. bus_message_received = false;
  1165. }
  1166. if (list_empty(&complete_list.list))
  1167. return IRQ_HANDLED;
  1168. list_for_each_entry_safe(cb_pos, cb_next, &complete_list.list, list) {
  1169. cl = (struct mei_cl *)cb_pos->file_private;
  1170. list_del(&cb_pos->list);
  1171. if (cl) {
  1172. if (cl != &dev->iamthif_cl) {
  1173. dev_dbg(&dev->pdev->dev, "completing call back.\n");
  1174. _mei_cmpl(cl, cb_pos);
  1175. cb_pos = NULL;
  1176. } else if (cl == &dev->iamthif_cl) {
  1177. mei_amthif_complete(dev, cb_pos);
  1178. }
  1179. }
  1180. }
  1181. return IRQ_HANDLED;
  1182. }