hbm.c 20 KB

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