hbm.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  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/mei.h>
  20. #include "mei_dev.h"
  21. #include "hbm.h"
  22. #include "hw-me.h"
  23. /**
  24. * mei_hbm_me_cl_allocate - allocates storage for me clients
  25. *
  26. * @dev: the device structure
  27. *
  28. * returns none.
  29. */
  30. static void mei_hbm_me_cl_allocate(struct mei_device *dev)
  31. {
  32. struct mei_me_client *clients;
  33. int b;
  34. /* count how many ME clients we have */
  35. for_each_set_bit(b, dev->me_clients_map, MEI_CLIENTS_MAX)
  36. dev->me_clients_num++;
  37. if (dev->me_clients_num <= 0)
  38. return;
  39. kfree(dev->me_clients);
  40. dev->me_clients = NULL;
  41. dev_dbg(&dev->pdev->dev, "memory allocation for ME clients size=%zd.\n",
  42. dev->me_clients_num * sizeof(struct mei_me_client));
  43. /* allocate storage for ME clients representation */
  44. clients = kcalloc(dev->me_clients_num,
  45. sizeof(struct mei_me_client), GFP_KERNEL);
  46. if (!clients) {
  47. dev_err(&dev->pdev->dev, "memory allocation for ME clients failed.\n");
  48. dev->dev_state = MEI_DEV_RESETTING;
  49. mei_reset(dev, 1);
  50. return;
  51. }
  52. dev->me_clients = clients;
  53. return;
  54. }
  55. /**
  56. * mei_hbm_cl_hdr - construct client hbm header
  57. *
  58. * @cl: - client
  59. * @hbm_cmd: host bus message command
  60. * @buf: buffer for cl header
  61. * @len: buffer length
  62. */
  63. static inline
  64. void mei_hbm_cl_hdr(struct mei_cl *cl, u8 hbm_cmd, void *buf, size_t len)
  65. {
  66. struct mei_hbm_cl_cmd *cmd = buf;
  67. memset(cmd, 0, len);
  68. cmd->hbm_cmd = hbm_cmd;
  69. cmd->host_addr = cl->host_client_id;
  70. cmd->me_addr = cl->me_client_id;
  71. }
  72. /**
  73. * same_disconn_addr - tells if they have the same address
  74. *
  75. * @file: private data of the file object.
  76. * @disconn: disconnection request.
  77. *
  78. * returns true if addres are same
  79. */
  80. static inline
  81. bool mei_hbm_cl_addr_equal(struct mei_cl *cl, void *buf)
  82. {
  83. struct mei_hbm_cl_cmd *cmd = buf;
  84. return cl->host_client_id == cmd->host_addr &&
  85. cl->me_client_id == cmd->me_addr;
  86. }
  87. /**
  88. * is_treat_specially_client - checks if the message belongs
  89. * to the file private data.
  90. *
  91. * @cl: private data of the file object
  92. * @rs: connect response bus message
  93. *
  94. */
  95. static bool is_treat_specially_client(struct mei_cl *cl,
  96. struct hbm_client_connect_response *rs)
  97. {
  98. if (mei_hbm_cl_addr_equal(cl, rs)) {
  99. if (!rs->status) {
  100. cl->state = MEI_FILE_CONNECTED;
  101. cl->status = 0;
  102. } else {
  103. cl->state = MEI_FILE_DISCONNECTED;
  104. cl->status = -ENODEV;
  105. }
  106. cl->timer_count = 0;
  107. return true;
  108. }
  109. return false;
  110. }
  111. int mei_hbm_start_wait(struct mei_device *dev)
  112. {
  113. int ret;
  114. if (dev->hbm_state > MEI_HBM_START)
  115. return 0;
  116. mutex_unlock(&dev->device_lock);
  117. ret = wait_event_interruptible_timeout(dev->wait_recvd_msg,
  118. dev->hbm_state == MEI_HBM_IDLE ||
  119. dev->hbm_state > MEI_HBM_START,
  120. mei_secs_to_jiffies(MEI_INTEROP_TIMEOUT));
  121. mutex_lock(&dev->device_lock);
  122. if (ret <= 0 && (dev->hbm_state <= MEI_HBM_START)) {
  123. dev->hbm_state = MEI_HBM_IDLE;
  124. dev_err(&dev->pdev->dev, "waiting for mei start failed\n");
  125. return -ETIMEDOUT;
  126. }
  127. return 0;
  128. }
  129. /**
  130. * mei_hbm_start_req - sends start request message.
  131. *
  132. * @dev: the device structure
  133. */
  134. int mei_hbm_start_req(struct mei_device *dev)
  135. {
  136. struct mei_msg_hdr *mei_hdr = &dev->wr_msg.hdr;
  137. struct hbm_host_version_request *start_req;
  138. const size_t len = sizeof(struct hbm_host_version_request);
  139. mei_hbm_hdr(mei_hdr, len);
  140. /* host start message */
  141. start_req = (struct hbm_host_version_request *)dev->wr_msg.data;
  142. memset(start_req, 0, len);
  143. start_req->hbm_cmd = HOST_START_REQ_CMD;
  144. start_req->host_version.major_version = HBM_MAJOR_VERSION;
  145. start_req->host_version.minor_version = HBM_MINOR_VERSION;
  146. dev->hbm_state = MEI_HBM_IDLE;
  147. if (mei_write_message(dev, mei_hdr, dev->wr_msg.data)) {
  148. dev_err(&dev->pdev->dev, "version message write failed\n");
  149. dev->dev_state = MEI_DEV_RESETTING;
  150. mei_reset(dev, 1);
  151. return -ENODEV;
  152. }
  153. dev->hbm_state = MEI_HBM_START;
  154. dev->init_clients_timer = MEI_CLIENTS_INIT_TIMEOUT;
  155. return 0;
  156. }
  157. /*
  158. * mei_hbm_enum_clients_req - sends enumeration client request message.
  159. *
  160. * @dev: the device structure
  161. *
  162. * returns none.
  163. */
  164. static void mei_hbm_enum_clients_req(struct mei_device *dev)
  165. {
  166. struct mei_msg_hdr *mei_hdr = &dev->wr_msg.hdr;
  167. struct hbm_host_enum_request *enum_req;
  168. const size_t len = sizeof(struct hbm_host_enum_request);
  169. /* enumerate clients */
  170. mei_hbm_hdr(mei_hdr, len);
  171. enum_req = (struct hbm_host_enum_request *)dev->wr_msg.data;
  172. memset(enum_req, 0, len);
  173. enum_req->hbm_cmd = HOST_ENUM_REQ_CMD;
  174. if (mei_write_message(dev, mei_hdr, dev->wr_msg.data)) {
  175. dev->dev_state = MEI_DEV_RESETTING;
  176. dev_err(&dev->pdev->dev, "enumeration request write failed.\n");
  177. mei_reset(dev, 1);
  178. }
  179. dev->hbm_state = MEI_HBM_ENUM_CLIENTS;
  180. dev->init_clients_timer = MEI_CLIENTS_INIT_TIMEOUT;
  181. return;
  182. }
  183. /**
  184. * mei_hbm_prop_req - request property for a single client
  185. *
  186. * @dev: the device structure
  187. *
  188. * returns none.
  189. */
  190. static int mei_hbm_prop_req(struct mei_device *dev)
  191. {
  192. struct mei_msg_hdr *mei_hdr = &dev->wr_msg.hdr;
  193. struct hbm_props_request *prop_req;
  194. const size_t len = sizeof(struct hbm_props_request);
  195. unsigned long next_client_index;
  196. u8 client_num;
  197. client_num = dev->me_client_presentation_num;
  198. next_client_index = find_next_bit(dev->me_clients_map, MEI_CLIENTS_MAX,
  199. dev->me_client_index);
  200. /* We got all client properties */
  201. if (next_client_index == MEI_CLIENTS_MAX) {
  202. dev->hbm_state = MEI_HBM_STARTED;
  203. schedule_work(&dev->init_work);
  204. return 0;
  205. }
  206. dev->me_clients[client_num].client_id = next_client_index;
  207. dev->me_clients[client_num].mei_flow_ctrl_creds = 0;
  208. mei_hbm_hdr(mei_hdr, len);
  209. prop_req = (struct hbm_props_request *)dev->wr_msg.data;
  210. memset(prop_req, 0, sizeof(struct hbm_props_request));
  211. prop_req->hbm_cmd = HOST_CLIENT_PROPERTIES_REQ_CMD;
  212. prop_req->address = next_client_index;
  213. if (mei_write_message(dev, mei_hdr, dev->wr_msg.data)) {
  214. dev->dev_state = MEI_DEV_RESETTING;
  215. dev_err(&dev->pdev->dev, "properties request write failed\n");
  216. mei_reset(dev, 1);
  217. return -EIO;
  218. }
  219. dev->init_clients_timer = MEI_CLIENTS_INIT_TIMEOUT;
  220. dev->me_client_index = next_client_index;
  221. return 0;
  222. }
  223. /**
  224. * mei_hbm_stop_req_prepare - perpare stop request message
  225. *
  226. * @dev - mei device
  227. * @mei_hdr - mei message header
  228. * @data - hbm message body buffer
  229. */
  230. static void mei_hbm_stop_req_prepare(struct mei_device *dev,
  231. struct mei_msg_hdr *mei_hdr, unsigned char *data)
  232. {
  233. struct hbm_host_stop_request *req =
  234. (struct hbm_host_stop_request *)data;
  235. const size_t len = sizeof(struct hbm_host_stop_request);
  236. mei_hbm_hdr(mei_hdr, len);
  237. memset(req, 0, len);
  238. req->hbm_cmd = HOST_STOP_REQ_CMD;
  239. req->reason = DRIVER_STOP_REQUEST;
  240. }
  241. /**
  242. * mei_hbm_cl_flow_control_req - sends flow control requst.
  243. *
  244. * @dev: the device structure
  245. * @cl: client info
  246. *
  247. * This function returns -EIO on write failure
  248. */
  249. int mei_hbm_cl_flow_control_req(struct mei_device *dev, struct mei_cl *cl)
  250. {
  251. struct mei_msg_hdr *mei_hdr = &dev->wr_msg.hdr;
  252. const size_t len = sizeof(struct hbm_flow_control);
  253. mei_hbm_hdr(mei_hdr, len);
  254. mei_hbm_cl_hdr(cl, MEI_FLOW_CONTROL_CMD, dev->wr_msg.data, len);
  255. dev_dbg(&dev->pdev->dev, "sending flow control host client = %d, ME client = %d\n",
  256. cl->host_client_id, cl->me_client_id);
  257. return mei_write_message(dev, mei_hdr, dev->wr_msg.data);
  258. }
  259. /**
  260. * mei_hbm_add_single_flow_creds - adds single buffer credentials.
  261. *
  262. * @dev: the device structure
  263. * @flow: flow control.
  264. */
  265. static void mei_hbm_add_single_flow_creds(struct mei_device *dev,
  266. struct hbm_flow_control *flow)
  267. {
  268. struct mei_me_client *client;
  269. int i;
  270. for (i = 0; i < dev->me_clients_num; i++) {
  271. client = &dev->me_clients[i];
  272. if (client && flow->me_addr == client->client_id) {
  273. if (client->props.single_recv_buf) {
  274. client->mei_flow_ctrl_creds++;
  275. dev_dbg(&dev->pdev->dev, "recv flow ctrl msg ME %d (single).\n",
  276. flow->me_addr);
  277. dev_dbg(&dev->pdev->dev, "flow control credentials =%d.\n",
  278. client->mei_flow_ctrl_creds);
  279. } else {
  280. BUG(); /* error in flow control */
  281. }
  282. }
  283. }
  284. }
  285. /**
  286. * mei_hbm_cl_flow_control_res - flow control response from me
  287. *
  288. * @dev: the device structure
  289. * @flow_control: flow control response bus message
  290. */
  291. static void mei_hbm_cl_flow_control_res(struct mei_device *dev,
  292. struct hbm_flow_control *flow_control)
  293. {
  294. struct mei_cl *cl = NULL;
  295. struct mei_cl *next = NULL;
  296. if (!flow_control->host_addr) {
  297. /* single receive buffer */
  298. mei_hbm_add_single_flow_creds(dev, flow_control);
  299. return;
  300. }
  301. /* normal connection */
  302. list_for_each_entry_safe(cl, next, &dev->file_list, link) {
  303. if (mei_hbm_cl_addr_equal(cl, flow_control)) {
  304. cl->mei_flow_ctrl_creds++;
  305. dev_dbg(&dev->pdev->dev, "flow ctrl msg for host %d ME %d.\n",
  306. flow_control->host_addr, flow_control->me_addr);
  307. dev_dbg(&dev->pdev->dev, "flow control credentials = %d.\n",
  308. cl->mei_flow_ctrl_creds);
  309. break;
  310. }
  311. }
  312. }
  313. /**
  314. * mei_hbm_cl_disconnect_req - sends disconnect message to fw.
  315. *
  316. * @dev: the device structure
  317. * @cl: a client to disconnect from
  318. *
  319. * This function returns -EIO on write failure
  320. */
  321. int mei_hbm_cl_disconnect_req(struct mei_device *dev, struct mei_cl *cl)
  322. {
  323. struct mei_msg_hdr *mei_hdr = &dev->wr_msg.hdr;
  324. const size_t len = sizeof(struct hbm_client_connect_request);
  325. mei_hbm_hdr(mei_hdr, len);
  326. mei_hbm_cl_hdr(cl, CLIENT_DISCONNECT_REQ_CMD, dev->wr_msg.data, len);
  327. return mei_write_message(dev, mei_hdr, dev->wr_msg.data);
  328. }
  329. /**
  330. * mei_hbm_cl_disconnect_res - disconnect response from ME
  331. *
  332. * @dev: the device structure
  333. * @rs: disconnect response bus message
  334. */
  335. static void mei_hbm_cl_disconnect_res(struct mei_device *dev,
  336. struct hbm_client_connect_response *rs)
  337. {
  338. struct mei_cl *cl;
  339. struct mei_cl_cb *pos = NULL, *next = NULL;
  340. dev_dbg(&dev->pdev->dev,
  341. "disconnect_response:\n"
  342. "ME Client = %d\n"
  343. "Host Client = %d\n"
  344. "Status = %d\n",
  345. rs->me_addr,
  346. rs->host_addr,
  347. rs->status);
  348. list_for_each_entry_safe(pos, next, &dev->ctrl_rd_list.list, list) {
  349. cl = pos->cl;
  350. if (!cl) {
  351. list_del(&pos->list);
  352. return;
  353. }
  354. dev_dbg(&dev->pdev->dev, "list_for_each_entry_safe in ctrl_rd_list.\n");
  355. if (mei_hbm_cl_addr_equal(cl, rs)) {
  356. list_del(&pos->list);
  357. if (!rs->status)
  358. cl->state = MEI_FILE_DISCONNECTED;
  359. cl->status = 0;
  360. cl->timer_count = 0;
  361. break;
  362. }
  363. }
  364. }
  365. /**
  366. * mei_hbm_cl_connect_req - send connection request to specific me client
  367. *
  368. * @dev: the device structure
  369. * @cl: a client to connect to
  370. *
  371. * returns -EIO on write failure
  372. */
  373. int mei_hbm_cl_connect_req(struct mei_device *dev, struct mei_cl *cl)
  374. {
  375. struct mei_msg_hdr *mei_hdr = &dev->wr_msg.hdr;
  376. const size_t len = sizeof(struct hbm_client_connect_request);
  377. mei_hbm_hdr(mei_hdr, len);
  378. mei_hbm_cl_hdr(cl, CLIENT_CONNECT_REQ_CMD, dev->wr_msg.data, len);
  379. return mei_write_message(dev, mei_hdr, dev->wr_msg.data);
  380. }
  381. /**
  382. * mei_hbm_cl_connect_res - connect resposne from the ME
  383. *
  384. * @dev: the device structure
  385. * @rs: connect response bus message
  386. */
  387. static void mei_hbm_cl_connect_res(struct mei_device *dev,
  388. struct hbm_client_connect_response *rs)
  389. {
  390. struct mei_cl *cl;
  391. struct mei_cl_cb *pos = NULL, *next = NULL;
  392. dev_dbg(&dev->pdev->dev,
  393. "connect_response:\n"
  394. "ME Client = %d\n"
  395. "Host Client = %d\n"
  396. "Status = %d\n",
  397. rs->me_addr,
  398. rs->host_addr,
  399. rs->status);
  400. /* if WD or iamthif client treat specially */
  401. if (is_treat_specially_client(&dev->wd_cl, rs)) {
  402. dev_dbg(&dev->pdev->dev, "successfully connected to WD client.\n");
  403. mei_watchdog_register(dev);
  404. return;
  405. }
  406. if (is_treat_specially_client(&dev->iamthif_cl, rs)) {
  407. dev->iamthif_state = MEI_IAMTHIF_IDLE;
  408. return;
  409. }
  410. list_for_each_entry_safe(pos, next, &dev->ctrl_rd_list.list, list) {
  411. cl = pos->cl;
  412. if (!cl) {
  413. list_del(&pos->list);
  414. return;
  415. }
  416. if (pos->fop_type == MEI_FOP_IOCTL) {
  417. if (is_treat_specially_client(cl, rs)) {
  418. list_del(&pos->list);
  419. cl->status = 0;
  420. cl->timer_count = 0;
  421. break;
  422. }
  423. }
  424. }
  425. }
  426. /**
  427. * mei_hbm_fw_disconnect_req - disconnect request initiated by me
  428. * host sends disoconnect response
  429. *
  430. * @dev: the device structure.
  431. * @disconnect_req: disconnect request bus message from the me
  432. */
  433. static void mei_hbm_fw_disconnect_req(struct mei_device *dev,
  434. struct hbm_client_connect_request *disconnect_req)
  435. {
  436. struct mei_cl *cl, *next;
  437. const size_t len = sizeof(struct hbm_client_connect_response);
  438. list_for_each_entry_safe(cl, next, &dev->file_list, link) {
  439. if (mei_hbm_cl_addr_equal(cl, disconnect_req)) {
  440. dev_dbg(&dev->pdev->dev, "disconnect request host client %d ME client %d.\n",
  441. disconnect_req->host_addr,
  442. disconnect_req->me_addr);
  443. cl->state = MEI_FILE_DISCONNECTED;
  444. cl->timer_count = 0;
  445. if (cl == &dev->wd_cl)
  446. dev->wd_pending = false;
  447. else if (cl == &dev->iamthif_cl)
  448. dev->iamthif_timer = 0;
  449. /* prepare disconnect response */
  450. mei_hbm_hdr(&dev->wr_ext_msg.hdr, len);
  451. mei_hbm_cl_hdr(cl, CLIENT_DISCONNECT_RES_CMD,
  452. dev->wr_ext_msg.data, len);
  453. break;
  454. }
  455. }
  456. }
  457. /**
  458. * mei_hbm_version_is_supported - checks whether the driver can
  459. * support the hbm version of the device
  460. *
  461. * @dev: the device structure
  462. * returns true if driver can support hbm version of the device
  463. */
  464. bool mei_hbm_version_is_supported(struct mei_device *dev)
  465. {
  466. return (dev->version.major_version < HBM_MAJOR_VERSION) ||
  467. (dev->version.major_version == HBM_MAJOR_VERSION &&
  468. dev->version.minor_version <= HBM_MINOR_VERSION);
  469. }
  470. /**
  471. * mei_hbm_dispatch - bottom half read routine after ISR to
  472. * handle the read bus message cmd processing.
  473. *
  474. * @dev: the device structure
  475. * @mei_hdr: header of bus message
  476. */
  477. void mei_hbm_dispatch(struct mei_device *dev, struct mei_msg_hdr *hdr)
  478. {
  479. struct mei_bus_message *mei_msg;
  480. struct mei_me_client *me_client;
  481. struct hbm_host_version_response *version_res;
  482. struct hbm_client_connect_response *connect_res;
  483. struct hbm_client_connect_response *disconnect_res;
  484. struct hbm_client_connect_request *disconnect_req;
  485. struct hbm_flow_control *flow_control;
  486. struct hbm_props_response *props_res;
  487. struct hbm_host_enum_response *enum_res;
  488. /* read the message to our buffer */
  489. BUG_ON(hdr->length >= sizeof(dev->rd_msg_buf));
  490. mei_read_slots(dev, dev->rd_msg_buf, hdr->length);
  491. mei_msg = (struct mei_bus_message *)dev->rd_msg_buf;
  492. switch (mei_msg->hbm_cmd) {
  493. case HOST_START_RES_CMD:
  494. version_res = (struct hbm_host_version_response *)mei_msg;
  495. dev_dbg(&dev->pdev->dev, "HBM VERSION: DRIVER=%02d:%02d DEVICE=%02d:%02d\n",
  496. HBM_MAJOR_VERSION, HBM_MINOR_VERSION,
  497. version_res->me_max_version.major_version,
  498. version_res->me_max_version.minor_version);
  499. if (version_res->host_version_supported) {
  500. dev->version.major_version = HBM_MAJOR_VERSION;
  501. dev->version.minor_version = HBM_MINOR_VERSION;
  502. } else {
  503. dev->version.major_version =
  504. version_res->me_max_version.major_version;
  505. dev->version.minor_version =
  506. version_res->me_max_version.minor_version;
  507. }
  508. if (!mei_hbm_version_is_supported(dev)) {
  509. dev_warn(&dev->pdev->dev, "hbm version mismatch: stopping the driver.\n");
  510. dev->hbm_state = MEI_HBM_STOP;
  511. mei_hbm_stop_req_prepare(dev, &dev->wr_msg.hdr,
  512. dev->wr_msg.data);
  513. mei_write_message(dev, &dev->wr_msg.hdr,
  514. dev->wr_msg.data);
  515. return;
  516. }
  517. if (dev->dev_state == MEI_DEV_INIT_CLIENTS &&
  518. dev->hbm_state == MEI_HBM_START) {
  519. dev->init_clients_timer = 0;
  520. mei_hbm_enum_clients_req(dev);
  521. } else {
  522. dev_err(&dev->pdev->dev, "reset: wrong host start response\n");
  523. mei_reset(dev, 1);
  524. return;
  525. }
  526. wake_up_interruptible(&dev->wait_recvd_msg);
  527. dev_dbg(&dev->pdev->dev, "host start response message received.\n");
  528. break;
  529. case CLIENT_CONNECT_RES_CMD:
  530. connect_res = (struct hbm_client_connect_response *) mei_msg;
  531. mei_hbm_cl_connect_res(dev, connect_res);
  532. dev_dbg(&dev->pdev->dev, "client connect response message received.\n");
  533. wake_up(&dev->wait_recvd_msg);
  534. break;
  535. case CLIENT_DISCONNECT_RES_CMD:
  536. disconnect_res = (struct hbm_client_connect_response *) mei_msg;
  537. mei_hbm_cl_disconnect_res(dev, disconnect_res);
  538. dev_dbg(&dev->pdev->dev, "client disconnect response message received.\n");
  539. wake_up(&dev->wait_recvd_msg);
  540. break;
  541. case MEI_FLOW_CONTROL_CMD:
  542. flow_control = (struct hbm_flow_control *) mei_msg;
  543. mei_hbm_cl_flow_control_res(dev, flow_control);
  544. dev_dbg(&dev->pdev->dev, "client flow control response message received.\n");
  545. break;
  546. case HOST_CLIENT_PROPERTIES_RES_CMD:
  547. props_res = (struct hbm_props_response *)mei_msg;
  548. me_client = &dev->me_clients[dev->me_client_presentation_num];
  549. if (props_res->status || !dev->me_clients) {
  550. dev_err(&dev->pdev->dev, "reset: properties response hbm wrong status.\n");
  551. mei_reset(dev, 1);
  552. return;
  553. }
  554. if (me_client->client_id != props_res->address) {
  555. dev_err(&dev->pdev->dev, "reset: host properties response address mismatch\n");
  556. mei_reset(dev, 1);
  557. return;
  558. }
  559. if (dev->dev_state != MEI_DEV_INIT_CLIENTS ||
  560. dev->hbm_state != MEI_HBM_CLIENT_PROPERTIES) {
  561. dev_err(&dev->pdev->dev, "reset: unexpected properties response\n");
  562. mei_reset(dev, 1);
  563. return;
  564. }
  565. me_client->props = props_res->client_properties;
  566. dev->me_client_index++;
  567. dev->me_client_presentation_num++;
  568. /* request property for the next client */
  569. mei_hbm_prop_req(dev);
  570. break;
  571. case HOST_ENUM_RES_CMD:
  572. enum_res = (struct hbm_host_enum_response *) mei_msg;
  573. memcpy(dev->me_clients_map, enum_res->valid_addresses, 32);
  574. if (dev->dev_state == MEI_DEV_INIT_CLIENTS &&
  575. dev->hbm_state == MEI_HBM_ENUM_CLIENTS) {
  576. dev->init_clients_timer = 0;
  577. dev->me_client_presentation_num = 0;
  578. dev->me_client_index = 0;
  579. mei_hbm_me_cl_allocate(dev);
  580. dev->hbm_state = MEI_HBM_CLIENT_PROPERTIES;
  581. /* first property reqeust */
  582. mei_hbm_prop_req(dev);
  583. } else {
  584. dev_err(&dev->pdev->dev, "reset: unexpected enumeration response hbm.\n");
  585. mei_reset(dev, 1);
  586. return;
  587. }
  588. break;
  589. case HOST_STOP_RES_CMD:
  590. if (dev->hbm_state != MEI_HBM_STOP)
  591. dev_err(&dev->pdev->dev, "unexpected stop response hbm.\n");
  592. dev->dev_state = MEI_DEV_DISABLED;
  593. dev_info(&dev->pdev->dev, "reset: FW stop response.\n");
  594. mei_reset(dev, 1);
  595. break;
  596. case CLIENT_DISCONNECT_REQ_CMD:
  597. /* search for client */
  598. disconnect_req = (struct hbm_client_connect_request *)mei_msg;
  599. mei_hbm_fw_disconnect_req(dev, disconnect_req);
  600. break;
  601. case ME_STOP_REQ_CMD:
  602. dev->hbm_state = MEI_HBM_STOP;
  603. mei_hbm_stop_req_prepare(dev, &dev->wr_ext_msg.hdr,
  604. dev->wr_ext_msg.data);
  605. break;
  606. default:
  607. BUG();
  608. break;
  609. }
  610. }