hbm.c 19 KB

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