init.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  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/sched.h>
  18. #include <linux/wait.h>
  19. #include <linux/delay.h>
  20. #include "mei_dev.h"
  21. #include "hw.h"
  22. #include "interface.h"
  23. #include <linux/mei.h>
  24. const char *mei_dev_state_str(int state)
  25. {
  26. #define MEI_DEV_STATE(state) case MEI_DEV_##state: return #state
  27. switch (state) {
  28. MEI_DEV_STATE(INITIALIZING);
  29. MEI_DEV_STATE(INIT_CLIENTS);
  30. MEI_DEV_STATE(ENABLED);
  31. MEI_DEV_STATE(RESETING);
  32. MEI_DEV_STATE(DISABLED);
  33. MEI_DEV_STATE(RECOVERING_FROM_RESET);
  34. MEI_DEV_STATE(POWER_DOWN);
  35. MEI_DEV_STATE(POWER_UP);
  36. default:
  37. return "unkown";
  38. }
  39. #undef MEI_DEV_STATE
  40. }
  41. /**
  42. * mei_io_list_flush - removes list entry belonging to cl.
  43. *
  44. * @list: An instance of our list structure
  45. * @cl: private data of the file object
  46. */
  47. void mei_io_list_flush(struct mei_cl_cb *list, struct mei_cl *cl)
  48. {
  49. struct mei_cl_cb *pos;
  50. struct mei_cl_cb *next;
  51. list_for_each_entry_safe(pos, next, &list->list, list) {
  52. if (pos->cl) {
  53. if (mei_cl_cmp_id(cl, pos->cl))
  54. list_del(&pos->list);
  55. }
  56. }
  57. }
  58. /**
  59. * mei_cl_flush_queues - flushes queue lists belonging to cl.
  60. *
  61. * @dev: the device structure
  62. * @cl: private data of the file object
  63. */
  64. int mei_cl_flush_queues(struct mei_cl *cl)
  65. {
  66. if (!cl || !cl->dev)
  67. return -EINVAL;
  68. dev_dbg(&cl->dev->pdev->dev, "remove list entry belonging to cl\n");
  69. mei_io_list_flush(&cl->dev->read_list, cl);
  70. mei_io_list_flush(&cl->dev->write_list, cl);
  71. mei_io_list_flush(&cl->dev->write_waiting_list, cl);
  72. mei_io_list_flush(&cl->dev->ctrl_wr_list, cl);
  73. mei_io_list_flush(&cl->dev->ctrl_rd_list, cl);
  74. mei_io_list_flush(&cl->dev->amthif_cmd_list, cl);
  75. mei_io_list_flush(&cl->dev->amthif_rd_complete_list, cl);
  76. return 0;
  77. }
  78. /**
  79. * init_mei_device - allocates and initializes the mei device structure
  80. *
  81. * @pdev: The pci device structure
  82. *
  83. * returns The mei_device_device pointer on success, NULL on failure.
  84. */
  85. struct mei_device *mei_device_init(struct pci_dev *pdev)
  86. {
  87. struct mei_device *dev;
  88. dev = kzalloc(sizeof(struct mei_device), GFP_KERNEL);
  89. if (!dev)
  90. return NULL;
  91. /* setup our list array */
  92. INIT_LIST_HEAD(&dev->file_list);
  93. INIT_LIST_HEAD(&dev->wd_cl.link);
  94. INIT_LIST_HEAD(&dev->iamthif_cl.link);
  95. mutex_init(&dev->device_lock);
  96. init_waitqueue_head(&dev->wait_recvd_msg);
  97. init_waitqueue_head(&dev->wait_stop_wd);
  98. dev->dev_state = MEI_DEV_INITIALIZING;
  99. dev->iamthif_state = MEI_IAMTHIF_IDLE;
  100. mei_io_list_init(&dev->read_list);
  101. mei_io_list_init(&dev->write_list);
  102. mei_io_list_init(&dev->write_waiting_list);
  103. mei_io_list_init(&dev->ctrl_wr_list);
  104. mei_io_list_init(&dev->ctrl_rd_list);
  105. mei_io_list_init(&dev->amthif_cmd_list);
  106. mei_io_list_init(&dev->amthif_rd_complete_list);
  107. dev->pdev = pdev;
  108. return dev;
  109. }
  110. /**
  111. * mei_hw_init - initializes host and fw to start work.
  112. *
  113. * @dev: the device structure
  114. *
  115. * returns 0 on success, <0 on failure.
  116. */
  117. int mei_hw_init(struct mei_device *dev)
  118. {
  119. int err = 0;
  120. int ret;
  121. mutex_lock(&dev->device_lock);
  122. dev->host_hw_state = mei_hcsr_read(dev);
  123. dev->me_hw_state = mei_mecsr_read(dev);
  124. dev_dbg(&dev->pdev->dev, "host_hw_state = 0x%08x, mestate = 0x%08x.\n",
  125. dev->host_hw_state, dev->me_hw_state);
  126. /* acknowledge interrupt and stop interupts */
  127. if ((dev->host_hw_state & H_IS) == H_IS)
  128. mei_reg_write(dev, H_CSR, dev->host_hw_state);
  129. /* Doesn't change in runtime */
  130. dev->hbuf_depth = (dev->host_hw_state & H_CBD) >> 24;
  131. dev->recvd_msg = false;
  132. dev_dbg(&dev->pdev->dev, "reset in start the mei device.\n");
  133. mei_reset(dev, 1);
  134. dev_dbg(&dev->pdev->dev, "host_hw_state = 0x%08x, me_hw_state = 0x%08x.\n",
  135. dev->host_hw_state, dev->me_hw_state);
  136. /* wait for ME to turn on ME_RDY */
  137. if (!dev->recvd_msg) {
  138. mutex_unlock(&dev->device_lock);
  139. err = wait_event_interruptible_timeout(dev->wait_recvd_msg,
  140. dev->recvd_msg,
  141. mei_secs_to_jiffies(MEI_INTEROP_TIMEOUT));
  142. mutex_lock(&dev->device_lock);
  143. }
  144. if (err <= 0 && !dev->recvd_msg) {
  145. dev->dev_state = MEI_DEV_DISABLED;
  146. dev_dbg(&dev->pdev->dev,
  147. "wait_event_interruptible_timeout failed"
  148. "on wait for ME to turn on ME_RDY.\n");
  149. ret = -ENODEV;
  150. goto out;
  151. }
  152. if (!(((dev->host_hw_state & H_RDY) == H_RDY) &&
  153. ((dev->me_hw_state & ME_RDY_HRA) == ME_RDY_HRA))) {
  154. dev->dev_state = MEI_DEV_DISABLED;
  155. dev_dbg(&dev->pdev->dev,
  156. "host_hw_state = 0x%08x, me_hw_state = 0x%08x.\n",
  157. dev->host_hw_state, dev->me_hw_state);
  158. if (!(dev->host_hw_state & H_RDY))
  159. dev_dbg(&dev->pdev->dev, "host turn off H_RDY.\n");
  160. if (!(dev->me_hw_state & ME_RDY_HRA))
  161. dev_dbg(&dev->pdev->dev, "ME turn off ME_RDY.\n");
  162. dev_err(&dev->pdev->dev, "link layer initialization failed.\n");
  163. ret = -ENODEV;
  164. goto out;
  165. }
  166. if (dev->version.major_version != HBM_MAJOR_VERSION ||
  167. dev->version.minor_version != HBM_MINOR_VERSION) {
  168. dev_dbg(&dev->pdev->dev, "MEI start failed.\n");
  169. ret = -ENODEV;
  170. goto out;
  171. }
  172. dev->recvd_msg = false;
  173. dev_dbg(&dev->pdev->dev, "host_hw_state = 0x%08x, me_hw_state = 0x%08x.\n",
  174. dev->host_hw_state, dev->me_hw_state);
  175. dev_dbg(&dev->pdev->dev, "ME turn on ME_RDY and host turn on H_RDY.\n");
  176. dev_dbg(&dev->pdev->dev, "link layer has been established.\n");
  177. dev_dbg(&dev->pdev->dev, "MEI start success.\n");
  178. ret = 0;
  179. out:
  180. mutex_unlock(&dev->device_lock);
  181. return ret;
  182. }
  183. /**
  184. * mei_hw_reset - resets fw via mei csr register.
  185. *
  186. * @dev: the device structure
  187. * @interrupts_enabled: if interrupt should be enabled after reset.
  188. */
  189. static void mei_hw_reset(struct mei_device *dev, int interrupts_enabled)
  190. {
  191. dev->host_hw_state |= (H_RST | H_IG);
  192. if (interrupts_enabled)
  193. mei_enable_interrupts(dev);
  194. else
  195. mei_disable_interrupts(dev);
  196. }
  197. /**
  198. * mei_reset - resets host and fw.
  199. *
  200. * @dev: the device structure
  201. * @interrupts_enabled: if interrupt should be enabled after reset.
  202. */
  203. void mei_reset(struct mei_device *dev, int interrupts_enabled)
  204. {
  205. struct mei_cl *cl_pos = NULL;
  206. struct mei_cl *cl_next = NULL;
  207. struct mei_cl_cb *cb_pos = NULL;
  208. struct mei_cl_cb *cb_next = NULL;
  209. bool unexpected;
  210. if (dev->dev_state == MEI_DEV_RECOVERING_FROM_RESET) {
  211. dev->need_reset = true;
  212. return;
  213. }
  214. unexpected = (dev->dev_state != MEI_DEV_INITIALIZING &&
  215. dev->dev_state != MEI_DEV_DISABLED &&
  216. dev->dev_state != MEI_DEV_POWER_DOWN &&
  217. dev->dev_state != MEI_DEV_POWER_UP);
  218. dev->host_hw_state = mei_hcsr_read(dev);
  219. dev_dbg(&dev->pdev->dev, "before reset host_hw_state = 0x%08x.\n",
  220. dev->host_hw_state);
  221. mei_hw_reset(dev, interrupts_enabled);
  222. dev->host_hw_state &= ~H_RST;
  223. dev->host_hw_state |= H_IG;
  224. mei_hcsr_set(dev);
  225. dev_dbg(&dev->pdev->dev, "currently saved host_hw_state = 0x%08x.\n",
  226. dev->host_hw_state);
  227. dev->need_reset = false;
  228. if (dev->dev_state != MEI_DEV_INITIALIZING) {
  229. if (dev->dev_state != MEI_DEV_DISABLED &&
  230. dev->dev_state != MEI_DEV_POWER_DOWN)
  231. dev->dev_state = MEI_DEV_RESETING;
  232. list_for_each_entry_safe(cl_pos,
  233. cl_next, &dev->file_list, link) {
  234. cl_pos->state = MEI_FILE_DISCONNECTED;
  235. cl_pos->mei_flow_ctrl_creds = 0;
  236. cl_pos->read_cb = NULL;
  237. cl_pos->timer_count = 0;
  238. }
  239. /* remove entry if already in list */
  240. dev_dbg(&dev->pdev->dev, "list del iamthif and wd file list.\n");
  241. mei_remove_client_from_file_list(dev,
  242. dev->wd_cl.host_client_id);
  243. mei_remove_client_from_file_list(dev,
  244. dev->iamthif_cl.host_client_id);
  245. mei_amthif_reset_params(dev);
  246. dev->extra_write_index = 0;
  247. }
  248. dev->me_clients_num = 0;
  249. dev->rd_msg_hdr = 0;
  250. dev->wd_pending = false;
  251. /* update the state of the registers after reset */
  252. dev->host_hw_state = mei_hcsr_read(dev);
  253. dev->me_hw_state = mei_mecsr_read(dev);
  254. dev_dbg(&dev->pdev->dev, "after reset host_hw_state = 0x%08x, me_hw_state = 0x%08x.\n",
  255. dev->host_hw_state, dev->me_hw_state);
  256. if (unexpected)
  257. dev_warn(&dev->pdev->dev, "unexpected reset: dev_state = %s\n",
  258. mei_dev_state_str(dev->dev_state));
  259. /* Wake up all readings so they can be interrupted */
  260. list_for_each_entry_safe(cl_pos, cl_next, &dev->file_list, link) {
  261. if (waitqueue_active(&cl_pos->rx_wait)) {
  262. dev_dbg(&dev->pdev->dev, "Waking up client!\n");
  263. wake_up_interruptible(&cl_pos->rx_wait);
  264. }
  265. }
  266. /* remove all waiting requests */
  267. list_for_each_entry_safe(cb_pos, cb_next, &dev->write_list.list, list) {
  268. list_del(&cb_pos->list);
  269. mei_io_cb_free(cb_pos);
  270. }
  271. }
  272. /**
  273. * host_start_message - mei host sends start message.
  274. *
  275. * @dev: the device structure
  276. *
  277. * returns none.
  278. */
  279. void mei_host_start_message(struct mei_device *dev)
  280. {
  281. struct mei_msg_hdr *mei_hdr;
  282. struct hbm_host_version_request *host_start_req;
  283. /* host start message */
  284. mei_hdr = (struct mei_msg_hdr *) &dev->wr_msg_buf[0];
  285. mei_hdr->host_addr = 0;
  286. mei_hdr->me_addr = 0;
  287. mei_hdr->length = sizeof(struct hbm_host_version_request);
  288. mei_hdr->msg_complete = 1;
  289. mei_hdr->reserved = 0;
  290. host_start_req =
  291. (struct hbm_host_version_request *) &dev->wr_msg_buf[1];
  292. memset(host_start_req, 0, sizeof(struct hbm_host_version_request));
  293. host_start_req->hbm_cmd = HOST_START_REQ_CMD;
  294. host_start_req->host_version.major_version = HBM_MAJOR_VERSION;
  295. host_start_req->host_version.minor_version = HBM_MINOR_VERSION;
  296. dev->recvd_msg = false;
  297. if (mei_write_message(dev, mei_hdr, (unsigned char *)host_start_req,
  298. mei_hdr->length)) {
  299. dev_dbg(&dev->pdev->dev, "write send version message to FW fail.\n");
  300. dev->dev_state = MEI_DEV_RESETING;
  301. mei_reset(dev, 1);
  302. }
  303. dev->init_clients_state = MEI_START_MESSAGE;
  304. dev->init_clients_timer = MEI_CLIENTS_INIT_TIMEOUT;
  305. return ;
  306. }
  307. /**
  308. * host_enum_clients_message - host sends enumeration client request message.
  309. *
  310. * @dev: the device structure
  311. *
  312. * returns none.
  313. */
  314. void mei_host_enum_clients_message(struct mei_device *dev)
  315. {
  316. struct mei_msg_hdr *mei_hdr;
  317. struct hbm_host_enum_request *host_enum_req;
  318. mei_hdr = (struct mei_msg_hdr *) &dev->wr_msg_buf[0];
  319. /* enumerate clients */
  320. mei_hdr->host_addr = 0;
  321. mei_hdr->me_addr = 0;
  322. mei_hdr->length = sizeof(struct hbm_host_enum_request);
  323. mei_hdr->msg_complete = 1;
  324. mei_hdr->reserved = 0;
  325. host_enum_req = (struct hbm_host_enum_request *) &dev->wr_msg_buf[1];
  326. memset(host_enum_req, 0, sizeof(struct hbm_host_enum_request));
  327. host_enum_req->hbm_cmd = HOST_ENUM_REQ_CMD;
  328. if (mei_write_message(dev, mei_hdr, (unsigned char *)host_enum_req,
  329. mei_hdr->length)) {
  330. dev->dev_state = MEI_DEV_RESETING;
  331. dev_dbg(&dev->pdev->dev, "write send enumeration request message to FW fail.\n");
  332. mei_reset(dev, 1);
  333. }
  334. dev->init_clients_state = MEI_ENUM_CLIENTS_MESSAGE;
  335. dev->init_clients_timer = MEI_CLIENTS_INIT_TIMEOUT;
  336. return;
  337. }
  338. /**
  339. * allocate_me_clients_storage - allocates storage for me clients
  340. *
  341. * @dev: the device structure
  342. *
  343. * returns none.
  344. */
  345. void mei_allocate_me_clients_storage(struct mei_device *dev)
  346. {
  347. struct mei_me_client *clients;
  348. int b;
  349. /* count how many ME clients we have */
  350. for_each_set_bit(b, dev->me_clients_map, MEI_CLIENTS_MAX)
  351. dev->me_clients_num++;
  352. if (dev->me_clients_num <= 0)
  353. return ;
  354. if (dev->me_clients != NULL) {
  355. kfree(dev->me_clients);
  356. dev->me_clients = NULL;
  357. }
  358. dev_dbg(&dev->pdev->dev, "memory allocation for ME clients size=%zd.\n",
  359. dev->me_clients_num * sizeof(struct mei_me_client));
  360. /* allocate storage for ME clients representation */
  361. clients = kcalloc(dev->me_clients_num,
  362. sizeof(struct mei_me_client), GFP_KERNEL);
  363. if (!clients) {
  364. dev_dbg(&dev->pdev->dev, "memory allocation for ME clients failed.\n");
  365. dev->dev_state = MEI_DEV_RESETING;
  366. mei_reset(dev, 1);
  367. return ;
  368. }
  369. dev->me_clients = clients;
  370. return ;
  371. }
  372. /**
  373. * host_client_properties - reads properties for client
  374. *
  375. * @dev: the device structure
  376. *
  377. * returns:
  378. * < 0 - Error.
  379. * = 0 - no more clients.
  380. * = 1 - still have clients to send properties request.
  381. */
  382. int mei_host_client_properties(struct mei_device *dev)
  383. {
  384. struct mei_msg_hdr *mei_header;
  385. struct hbm_props_request *host_cli_req;
  386. int b;
  387. u8 client_num = dev->me_client_presentation_num;
  388. b = dev->me_client_index;
  389. b = find_next_bit(dev->me_clients_map, MEI_CLIENTS_MAX, b);
  390. if (b < MEI_CLIENTS_MAX) {
  391. dev->me_clients[client_num].client_id = b;
  392. dev->me_clients[client_num].mei_flow_ctrl_creds = 0;
  393. mei_header = (struct mei_msg_hdr *)&dev->wr_msg_buf[0];
  394. mei_header->host_addr = 0;
  395. mei_header->me_addr = 0;
  396. mei_header->length = sizeof(struct hbm_props_request);
  397. mei_header->msg_complete = 1;
  398. mei_header->reserved = 0;
  399. host_cli_req = (struct hbm_props_request *)&dev->wr_msg_buf[1];
  400. memset(host_cli_req, 0, sizeof(struct hbm_props_request));
  401. host_cli_req->hbm_cmd = HOST_CLIENT_PROPERTIES_REQ_CMD;
  402. host_cli_req->address = b;
  403. if (mei_write_message(dev, mei_header,
  404. (unsigned char *)host_cli_req,
  405. mei_header->length)) {
  406. dev->dev_state = MEI_DEV_RESETING;
  407. dev_dbg(&dev->pdev->dev, "write send enumeration request message to FW fail.\n");
  408. mei_reset(dev, 1);
  409. return -EIO;
  410. }
  411. dev->init_clients_timer = MEI_CLIENTS_INIT_TIMEOUT;
  412. dev->me_client_index = b;
  413. return 1;
  414. }
  415. return 0;
  416. }
  417. /**
  418. * mei_init_file_private - initializes private file structure.
  419. *
  420. * @priv: private file structure to be initialized
  421. * @file: the file structure
  422. */
  423. void mei_cl_init(struct mei_cl *priv, struct mei_device *dev)
  424. {
  425. memset(priv, 0, sizeof(struct mei_cl));
  426. init_waitqueue_head(&priv->wait);
  427. init_waitqueue_head(&priv->rx_wait);
  428. init_waitqueue_head(&priv->tx_wait);
  429. INIT_LIST_HEAD(&priv->link);
  430. priv->reading_state = MEI_IDLE;
  431. priv->writing_state = MEI_IDLE;
  432. priv->dev = dev;
  433. }
  434. int mei_me_cl_by_uuid(const struct mei_device *dev, const uuid_le *cuuid)
  435. {
  436. int i, res = -ENOENT;
  437. for (i = 0; i < dev->me_clients_num; ++i)
  438. if (uuid_le_cmp(*cuuid,
  439. dev->me_clients[i].props.protocol_name) == 0) {
  440. res = i;
  441. break;
  442. }
  443. return res;
  444. }
  445. /**
  446. * mei_me_cl_update_filext - searches for ME client guid
  447. * sets client_id in mei_file_private if found
  448. * @dev: the device structure
  449. * @cl: private file structure to set client_id in
  450. * @cuuid: searched uuid of ME client
  451. * @client_id: id of host client to be set in file private structure
  452. *
  453. * returns ME client index
  454. */
  455. int mei_me_cl_update_filext(struct mei_device *dev, struct mei_cl *cl,
  456. const uuid_le *cuuid, u8 host_cl_id)
  457. {
  458. int i;
  459. if (!dev || !cl || !cuuid)
  460. return -EINVAL;
  461. /* check for valid client id */
  462. i = mei_me_cl_by_uuid(dev, cuuid);
  463. if (i >= 0) {
  464. cl->me_client_id = dev->me_clients[i].client_id;
  465. cl->state = MEI_FILE_CONNECTING;
  466. cl->host_client_id = host_cl_id;
  467. list_add_tail(&cl->link, &dev->file_list);
  468. return (u8)i;
  469. }
  470. return -ENOENT;
  471. }
  472. /**
  473. * mei_alloc_file_private - allocates a private file structure and sets it up.
  474. * @file: the file structure
  475. *
  476. * returns The allocated file or NULL on failure
  477. */
  478. struct mei_cl *mei_cl_allocate(struct mei_device *dev)
  479. {
  480. struct mei_cl *cl;
  481. cl = kmalloc(sizeof(struct mei_cl), GFP_KERNEL);
  482. if (!cl)
  483. return NULL;
  484. mei_cl_init(cl, dev);
  485. return cl;
  486. }
  487. /**
  488. * mei_disconnect_host_client - sends disconnect message to fw from host client.
  489. *
  490. * @dev: the device structure
  491. * @cl: private data of the file object
  492. *
  493. * Locking: called under "dev->device_lock" lock
  494. *
  495. * returns 0 on success, <0 on failure.
  496. */
  497. int mei_disconnect_host_client(struct mei_device *dev, struct mei_cl *cl)
  498. {
  499. struct mei_cl_cb *cb;
  500. int rets, err;
  501. if (!dev || !cl)
  502. return -ENODEV;
  503. if (cl->state != MEI_FILE_DISCONNECTING)
  504. return 0;
  505. cb = mei_io_cb_init(cl, NULL);
  506. if (!cb)
  507. return -ENOMEM;
  508. cb->fop_type = MEI_FOP_CLOSE;
  509. if (dev->mei_host_buffer_is_empty) {
  510. dev->mei_host_buffer_is_empty = false;
  511. if (mei_disconnect(dev, cl)) {
  512. rets = -ENODEV;
  513. dev_dbg(&dev->pdev->dev, "failed to call mei_disconnect.\n");
  514. goto free;
  515. }
  516. mdelay(10); /* Wait for hardware disconnection ready */
  517. list_add_tail(&cb->list, &dev->ctrl_rd_list.list);
  518. } else {
  519. dev_dbg(&dev->pdev->dev, "add disconnect cb to control write list\n");
  520. list_add_tail(&cb->list, &dev->ctrl_wr_list.list);
  521. }
  522. mutex_unlock(&dev->device_lock);
  523. err = wait_event_timeout(dev->wait_recvd_msg,
  524. MEI_FILE_DISCONNECTED == cl->state,
  525. mei_secs_to_jiffies(MEI_CL_CONNECT_TIMEOUT));
  526. mutex_lock(&dev->device_lock);
  527. if (MEI_FILE_DISCONNECTED == cl->state) {
  528. rets = 0;
  529. dev_dbg(&dev->pdev->dev, "successfully disconnected from FW client.\n");
  530. } else {
  531. rets = -ENODEV;
  532. if (MEI_FILE_DISCONNECTED != cl->state)
  533. dev_dbg(&dev->pdev->dev, "wrong status client disconnect.\n");
  534. if (err)
  535. dev_dbg(&dev->pdev->dev,
  536. "wait failed disconnect err=%08x\n",
  537. err);
  538. dev_dbg(&dev->pdev->dev, "failed to disconnect from FW client.\n");
  539. }
  540. mei_io_list_flush(&dev->ctrl_rd_list, cl);
  541. mei_io_list_flush(&dev->ctrl_wr_list, cl);
  542. free:
  543. mei_io_cb_free(cb);
  544. return rets;
  545. }
  546. /**
  547. * mei_remove_client_from_file_list -
  548. * removes file private data from device file list
  549. *
  550. * @dev: the device structure
  551. * @host_client_id: host client id to be removed
  552. */
  553. void mei_remove_client_from_file_list(struct mei_device *dev,
  554. u8 host_client_id)
  555. {
  556. struct mei_cl *cl_pos = NULL;
  557. struct mei_cl *cl_next = NULL;
  558. list_for_each_entry_safe(cl_pos, cl_next, &dev->file_list, link) {
  559. if (host_client_id == cl_pos->host_client_id) {
  560. dev_dbg(&dev->pdev->dev, "remove host client = %d, ME client = %d\n",
  561. cl_pos->host_client_id,
  562. cl_pos->me_client_id);
  563. list_del_init(&cl_pos->link);
  564. break;
  565. }
  566. }
  567. }