bus.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785
  1. /*
  2. * ISHTP bus driver
  3. *
  4. * Copyright (c) 2012-2016, 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. #include <linux/module.h>
  16. #include <linux/init.h>
  17. #include <linux/kernel.h>
  18. #include <linux/device.h>
  19. #include <linux/sched.h>
  20. #include <linux/slab.h>
  21. #include "bus.h"
  22. #include "ishtp-dev.h"
  23. #include "client.h"
  24. #include "hbm.h"
  25. static int ishtp_use_dma;
  26. module_param_named(ishtp_use_dma, ishtp_use_dma, int, 0600);
  27. MODULE_PARM_DESC(ishtp_use_dma, "Use DMA to send messages");
  28. #define to_ishtp_cl_driver(d) container_of(d, struct ishtp_cl_driver, driver)
  29. #define to_ishtp_cl_device(d) container_of(d, struct ishtp_cl_device, dev)
  30. static bool ishtp_device_ready;
  31. /**
  32. * ishtp_recv() - process ishtp message
  33. * @dev: ishtp device
  34. *
  35. * If a message with valid header and size is received, then
  36. * this function calls appropriate handler. The host or firmware
  37. * address is zero, then they are host bus management message,
  38. * otherwise they are message fo clients.
  39. */
  40. void ishtp_recv(struct ishtp_device *dev)
  41. {
  42. uint32_t msg_hdr;
  43. struct ishtp_msg_hdr *ishtp_hdr;
  44. /* Read ISHTP header dword */
  45. msg_hdr = dev->ops->ishtp_read_hdr(dev);
  46. if (!msg_hdr)
  47. return;
  48. dev->ops->sync_fw_clock(dev);
  49. ishtp_hdr = (struct ishtp_msg_hdr *)&msg_hdr;
  50. dev->ishtp_msg_hdr = msg_hdr;
  51. /* Sanity check: ISHTP frag. length in header */
  52. if (ishtp_hdr->length > dev->mtu) {
  53. dev_err(dev->devc,
  54. "ISHTP hdr - bad length: %u; dropped [%08X]\n",
  55. (unsigned int)ishtp_hdr->length, msg_hdr);
  56. return;
  57. }
  58. /* ISHTP bus message */
  59. if (!ishtp_hdr->host_addr && !ishtp_hdr->fw_addr)
  60. recv_hbm(dev, ishtp_hdr);
  61. /* ISHTP fixed-client message */
  62. else if (!ishtp_hdr->host_addr)
  63. recv_fixed_cl_msg(dev, ishtp_hdr);
  64. else
  65. /* ISHTP client message */
  66. recv_ishtp_cl_msg(dev, ishtp_hdr);
  67. }
  68. EXPORT_SYMBOL(ishtp_recv);
  69. /**
  70. * ishtp_send_msg() - Send ishtp message
  71. * @dev: ishtp device
  72. * @hdr: Message header
  73. * @msg: Message contents
  74. * @ipc_send_compl: completion callback
  75. * @ipc_send_compl_prm: completion callback parameter
  76. *
  77. * Send a multi fragment message via IPC. After sending the first fragment
  78. * the completion callback is called to schedule transmit of next fragment.
  79. *
  80. * Return: This returns IPC send message status.
  81. */
  82. int ishtp_send_msg(struct ishtp_device *dev, struct ishtp_msg_hdr *hdr,
  83. void *msg, void(*ipc_send_compl)(void *),
  84. void *ipc_send_compl_prm)
  85. {
  86. unsigned char ipc_msg[IPC_FULL_MSG_SIZE];
  87. uint32_t drbl_val;
  88. drbl_val = dev->ops->ipc_get_header(dev, hdr->length +
  89. sizeof(struct ishtp_msg_hdr),
  90. 1);
  91. memcpy(ipc_msg, &drbl_val, sizeof(uint32_t));
  92. memcpy(ipc_msg + sizeof(uint32_t), hdr, sizeof(uint32_t));
  93. memcpy(ipc_msg + 2 * sizeof(uint32_t), msg, hdr->length);
  94. return dev->ops->write(dev, ipc_send_compl, ipc_send_compl_prm,
  95. ipc_msg, 2 * sizeof(uint32_t) + hdr->length);
  96. }
  97. /**
  98. * ishtp_write_message() - Send ishtp single fragment message
  99. * @dev: ishtp device
  100. * @hdr: Message header
  101. * @buf: message data
  102. *
  103. * Send a single fragment message via IPC. This returns IPC send message
  104. * status.
  105. *
  106. * Return: This returns IPC send message status.
  107. */
  108. int ishtp_write_message(struct ishtp_device *dev, struct ishtp_msg_hdr *hdr,
  109. unsigned char *buf)
  110. {
  111. return ishtp_send_msg(dev, hdr, buf, NULL, NULL);
  112. }
  113. /**
  114. * ishtp_fw_cl_by_uuid() - locate index of fw client
  115. * @dev: ishtp device
  116. * @uuid: uuid of the client to search
  117. *
  118. * Search firmware client using UUID.
  119. *
  120. * Return: fw client index or -ENOENT if not found
  121. */
  122. int ishtp_fw_cl_by_uuid(struct ishtp_device *dev, const uuid_le *uuid)
  123. {
  124. int i, res = -ENOENT;
  125. for (i = 0; i < dev->fw_clients_num; ++i) {
  126. if (uuid_le_cmp(*uuid, dev->fw_clients[i].props.protocol_name)
  127. == 0) {
  128. res = i;
  129. break;
  130. }
  131. }
  132. return res;
  133. }
  134. EXPORT_SYMBOL(ishtp_fw_cl_by_uuid);
  135. /**
  136. * ishtp_fw_cl_by_id() - return index to fw_clients for client_id
  137. * @dev: the ishtp device structure
  138. * @client_id: fw client id to search
  139. *
  140. * Search firmware client using client id.
  141. *
  142. * Return: index on success, -ENOENT on failure.
  143. */
  144. int ishtp_fw_cl_by_id(struct ishtp_device *dev, uint8_t client_id)
  145. {
  146. int i, res = -ENOENT;
  147. unsigned long flags;
  148. spin_lock_irqsave(&dev->fw_clients_lock, flags);
  149. for (i = 0; i < dev->fw_clients_num; i++) {
  150. if (dev->fw_clients[i].client_id == client_id) {
  151. res = i;
  152. break;
  153. }
  154. }
  155. spin_unlock_irqrestore(&dev->fw_clients_lock, flags);
  156. return res;
  157. }
  158. /**
  159. * ishtp_cl_device_probe() - Bus probe() callback
  160. * @dev: the device structure
  161. *
  162. * This is a bus probe callback and calls the drive probe function.
  163. *
  164. * Return: Return value from driver probe() call.
  165. */
  166. static int ishtp_cl_device_probe(struct device *dev)
  167. {
  168. struct ishtp_cl_device *device = to_ishtp_cl_device(dev);
  169. struct ishtp_cl_driver *driver;
  170. if (!device)
  171. return 0;
  172. driver = to_ishtp_cl_driver(dev->driver);
  173. if (!driver || !driver->probe)
  174. return -ENODEV;
  175. return driver->probe(device);
  176. }
  177. /**
  178. * ishtp_cl_device_remove() - Bus remove() callback
  179. * @dev: the device structure
  180. *
  181. * This is a bus remove callback and calls the drive remove function.
  182. * Since the ISH driver model supports only built in, this is
  183. * primarily can be called during pci driver init failure.
  184. *
  185. * Return: Return value from driver remove() call.
  186. */
  187. static int ishtp_cl_device_remove(struct device *dev)
  188. {
  189. struct ishtp_cl_device *device = to_ishtp_cl_device(dev);
  190. struct ishtp_cl_driver *driver;
  191. if (!device || !dev->driver)
  192. return 0;
  193. if (device->event_cb) {
  194. device->event_cb = NULL;
  195. cancel_work_sync(&device->event_work);
  196. }
  197. driver = to_ishtp_cl_driver(dev->driver);
  198. if (!driver->remove) {
  199. dev->driver = NULL;
  200. return 0;
  201. }
  202. return driver->remove(device);
  203. }
  204. /**
  205. * ishtp_cl_device_suspend() - Bus suspend callback
  206. * @dev: device
  207. *
  208. * Called during device suspend process.
  209. *
  210. * Return: Return value from driver suspend() call.
  211. */
  212. static int ishtp_cl_device_suspend(struct device *dev)
  213. {
  214. struct ishtp_cl_device *device = to_ishtp_cl_device(dev);
  215. struct ishtp_cl_driver *driver;
  216. int ret = 0;
  217. if (!device)
  218. return 0;
  219. driver = to_ishtp_cl_driver(dev->driver);
  220. if (driver && driver->driver.pm) {
  221. if (driver->driver.pm->suspend)
  222. ret = driver->driver.pm->suspend(dev);
  223. }
  224. return ret;
  225. }
  226. /**
  227. * ishtp_cl_device_resume() - Bus resume callback
  228. * @dev: device
  229. *
  230. * Called during device resume process.
  231. *
  232. * Return: Return value from driver resume() call.
  233. */
  234. static int ishtp_cl_device_resume(struct device *dev)
  235. {
  236. struct ishtp_cl_device *device = to_ishtp_cl_device(dev);
  237. struct ishtp_cl_driver *driver;
  238. int ret = 0;
  239. if (!device)
  240. return 0;
  241. /*
  242. * When ISH needs hard reset, it is done asynchrnously, hence bus
  243. * resume will be called before full ISH resume
  244. */
  245. if (device->ishtp_dev->resume_flag)
  246. return 0;
  247. driver = to_ishtp_cl_driver(dev->driver);
  248. if (driver && driver->driver.pm) {
  249. if (driver->driver.pm->resume)
  250. ret = driver->driver.pm->resume(dev);
  251. }
  252. return ret;
  253. }
  254. /**
  255. * ishtp_cl_device_reset() - Reset callback
  256. * @device: ishtp client device instance
  257. *
  258. * This is a callback when HW reset is done and the device need
  259. * reinit.
  260. *
  261. * Return: Return value from driver reset() call.
  262. */
  263. static int ishtp_cl_device_reset(struct ishtp_cl_device *device)
  264. {
  265. struct ishtp_cl_driver *driver;
  266. int ret = 0;
  267. device->event_cb = NULL;
  268. cancel_work_sync(&device->event_work);
  269. driver = to_ishtp_cl_driver(device->dev.driver);
  270. if (driver && driver->reset)
  271. ret = driver->reset(device);
  272. return ret;
  273. }
  274. static ssize_t modalias_show(struct device *dev, struct device_attribute *a,
  275. char *buf)
  276. {
  277. int len;
  278. len = snprintf(buf, PAGE_SIZE, "ishtp:%s\n", dev_name(dev));
  279. return (len >= PAGE_SIZE) ? (PAGE_SIZE - 1) : len;
  280. }
  281. static DEVICE_ATTR_RO(modalias);
  282. static struct attribute *ishtp_cl_dev_attrs[] = {
  283. &dev_attr_modalias.attr,
  284. NULL,
  285. };
  286. ATTRIBUTE_GROUPS(ishtp_cl_dev);
  287. static int ishtp_cl_uevent(struct device *dev, struct kobj_uevent_env *env)
  288. {
  289. if (add_uevent_var(env, "MODALIAS=ishtp:%s", dev_name(dev)))
  290. return -ENOMEM;
  291. return 0;
  292. }
  293. static const struct dev_pm_ops ishtp_cl_bus_dev_pm_ops = {
  294. /* Suspend callbacks */
  295. .suspend = ishtp_cl_device_suspend,
  296. .resume = ishtp_cl_device_resume,
  297. /* Hibernate callbacks */
  298. .freeze = ishtp_cl_device_suspend,
  299. .thaw = ishtp_cl_device_resume,
  300. .restore = ishtp_cl_device_resume,
  301. };
  302. static struct bus_type ishtp_cl_bus_type = {
  303. .name = "ishtp",
  304. .dev_groups = ishtp_cl_dev_groups,
  305. .probe = ishtp_cl_device_probe,
  306. .remove = ishtp_cl_device_remove,
  307. .pm = &ishtp_cl_bus_dev_pm_ops,
  308. .uevent = ishtp_cl_uevent,
  309. };
  310. static void ishtp_cl_dev_release(struct device *dev)
  311. {
  312. kfree(to_ishtp_cl_device(dev));
  313. }
  314. static const struct device_type ishtp_cl_device_type = {
  315. .release = ishtp_cl_dev_release,
  316. };
  317. /**
  318. * ishtp_bus_add_device() - Function to create device on bus
  319. * @dev: ishtp device
  320. * @uuid: uuid of the client
  321. * @name: Name of the client
  322. *
  323. * Allocate ISHTP bus client device, attach it to uuid
  324. * and register with ISHTP bus.
  325. *
  326. * Return: ishtp_cl_device pointer or NULL on failure
  327. */
  328. static struct ishtp_cl_device *ishtp_bus_add_device(struct ishtp_device *dev,
  329. uuid_le uuid, char *name)
  330. {
  331. struct ishtp_cl_device *device;
  332. int status;
  333. unsigned long flags;
  334. spin_lock_irqsave(&dev->device_list_lock, flags);
  335. list_for_each_entry(device, &dev->device_list, device_link) {
  336. if (!strcmp(name, dev_name(&device->dev))) {
  337. device->fw_client = &dev->fw_clients[
  338. dev->fw_client_presentation_num - 1];
  339. spin_unlock_irqrestore(&dev->device_list_lock, flags);
  340. ishtp_cl_device_reset(device);
  341. return device;
  342. }
  343. }
  344. spin_unlock_irqrestore(&dev->device_list_lock, flags);
  345. device = kzalloc(sizeof(struct ishtp_cl_device), GFP_KERNEL);
  346. if (!device)
  347. return NULL;
  348. device->dev.parent = dev->devc;
  349. device->dev.bus = &ishtp_cl_bus_type;
  350. device->dev.type = &ishtp_cl_device_type;
  351. device->ishtp_dev = dev;
  352. device->fw_client =
  353. &dev->fw_clients[dev->fw_client_presentation_num - 1];
  354. dev_set_name(&device->dev, "%s", name);
  355. spin_lock_irqsave(&dev->device_list_lock, flags);
  356. list_add_tail(&device->device_link, &dev->device_list);
  357. spin_unlock_irqrestore(&dev->device_list_lock, flags);
  358. status = device_register(&device->dev);
  359. if (status) {
  360. spin_lock_irqsave(&dev->device_list_lock, flags);
  361. list_del(&device->device_link);
  362. spin_unlock_irqrestore(&dev->device_list_lock, flags);
  363. dev_err(dev->devc, "Failed to register ISHTP client device\n");
  364. put_device(&device->dev);
  365. return NULL;
  366. }
  367. ishtp_device_ready = true;
  368. return device;
  369. }
  370. /**
  371. * ishtp_bus_remove_device() - Function to relase device on bus
  372. * @device: client device instance
  373. *
  374. * This is a counterpart of ishtp_bus_add_device.
  375. * Device is unregistered.
  376. * the device structure is freed in 'ishtp_cl_dev_release' function
  377. * Called only during error in pci driver init path.
  378. */
  379. static void ishtp_bus_remove_device(struct ishtp_cl_device *device)
  380. {
  381. device_unregister(&device->dev);
  382. }
  383. /**
  384. * __ishtp_cl_driver_register() - Client driver register
  385. * @driver: the client driver instance
  386. * @owner: Owner of this driver module
  387. *
  388. * Once a client driver is probed, it created a client
  389. * instance and registers with the bus.
  390. *
  391. * Return: Return value of driver_register or -ENODEV if not ready
  392. */
  393. int __ishtp_cl_driver_register(struct ishtp_cl_driver *driver,
  394. struct module *owner)
  395. {
  396. int err;
  397. if (!ishtp_device_ready)
  398. return -ENODEV;
  399. driver->driver.name = driver->name;
  400. driver->driver.owner = owner;
  401. driver->driver.bus = &ishtp_cl_bus_type;
  402. err = driver_register(&driver->driver);
  403. if (err)
  404. return err;
  405. return 0;
  406. }
  407. EXPORT_SYMBOL(__ishtp_cl_driver_register);
  408. /**
  409. * ishtp_cl_driver_unregister() - Client driver unregister
  410. * @driver: the client driver instance
  411. *
  412. * Unregister client during device removal process.
  413. */
  414. void ishtp_cl_driver_unregister(struct ishtp_cl_driver *driver)
  415. {
  416. driver_unregister(&driver->driver);
  417. }
  418. EXPORT_SYMBOL(ishtp_cl_driver_unregister);
  419. /**
  420. * ishtp_bus_event_work() - event work function
  421. * @work: work struct pointer
  422. *
  423. * Once an event is received for a client this work
  424. * function is called. If the device has registered a
  425. * callback then the callback is called.
  426. */
  427. static void ishtp_bus_event_work(struct work_struct *work)
  428. {
  429. struct ishtp_cl_device *device;
  430. device = container_of(work, struct ishtp_cl_device, event_work);
  431. if (device->event_cb)
  432. device->event_cb(device);
  433. }
  434. /**
  435. * ishtp_cl_bus_rx_event() - schedule event work
  436. * @device: client device instance
  437. *
  438. * Once an event is received for a client this schedules
  439. * a work function to process.
  440. */
  441. void ishtp_cl_bus_rx_event(struct ishtp_cl_device *device)
  442. {
  443. if (!device || !device->event_cb)
  444. return;
  445. if (device->event_cb)
  446. schedule_work(&device->event_work);
  447. }
  448. /**
  449. * ishtp_register_event_cb() - Register callback
  450. * @device: client device instance
  451. * @event_cb: Event processor for an client
  452. *
  453. * Register a callback for events, called from client driver
  454. *
  455. * Return: Return 0 or -EALREADY if already registered
  456. */
  457. int ishtp_register_event_cb(struct ishtp_cl_device *device,
  458. void (*event_cb)(struct ishtp_cl_device *))
  459. {
  460. if (device->event_cb)
  461. return -EALREADY;
  462. device->event_cb = event_cb;
  463. INIT_WORK(&device->event_work, ishtp_bus_event_work);
  464. return 0;
  465. }
  466. EXPORT_SYMBOL(ishtp_register_event_cb);
  467. /**
  468. * ishtp_get_device() - update usage count for the device
  469. * @cl_device: client device instance
  470. *
  471. * Increment the usage count. The device can't be deleted
  472. */
  473. void ishtp_get_device(struct ishtp_cl_device *cl_device)
  474. {
  475. cl_device->reference_count++;
  476. }
  477. EXPORT_SYMBOL(ishtp_get_device);
  478. /**
  479. * ishtp_put_device() - decrement usage count for the device
  480. * @cl_device: client device instance
  481. *
  482. * Decrement the usage count. The device can be deleted is count = 0
  483. */
  484. void ishtp_put_device(struct ishtp_cl_device *cl_device)
  485. {
  486. cl_device->reference_count--;
  487. }
  488. EXPORT_SYMBOL(ishtp_put_device);
  489. /**
  490. * ishtp_bus_new_client() - Create a new client
  491. * @dev: ISHTP device instance
  492. *
  493. * Once bus protocol enumerates a client, this is called
  494. * to add a device for the client.
  495. *
  496. * Return: 0 on success or error code on failure
  497. */
  498. int ishtp_bus_new_client(struct ishtp_device *dev)
  499. {
  500. int i;
  501. char *dev_name;
  502. struct ishtp_cl_device *cl_device;
  503. uuid_le device_uuid;
  504. /*
  505. * For all reported clients, create an unconnected client and add its
  506. * device to ISHTP bus.
  507. * If appropriate driver has loaded, this will trigger its probe().
  508. * Otherwise, probe() will be called when driver is loaded
  509. */
  510. i = dev->fw_client_presentation_num - 1;
  511. device_uuid = dev->fw_clients[i].props.protocol_name;
  512. dev_name = kasprintf(GFP_KERNEL, "{%pUL}", device_uuid.b);
  513. if (!dev_name)
  514. return -ENOMEM;
  515. cl_device = ishtp_bus_add_device(dev, device_uuid, dev_name);
  516. if (!cl_device) {
  517. kfree(dev_name);
  518. return -ENOENT;
  519. }
  520. kfree(dev_name);
  521. return 0;
  522. }
  523. /**
  524. * ishtp_cl_device_bind() - bind a device
  525. * @cl: ishtp client device
  526. *
  527. * Binds connected ishtp_cl to ISHTP bus device
  528. *
  529. * Return: 0 on success or fault code
  530. */
  531. int ishtp_cl_device_bind(struct ishtp_cl *cl)
  532. {
  533. struct ishtp_cl_device *cl_device;
  534. unsigned long flags;
  535. int rv;
  536. if (!cl->fw_client_id || cl->state != ISHTP_CL_CONNECTED)
  537. return -EFAULT;
  538. rv = -ENOENT;
  539. spin_lock_irqsave(&cl->dev->device_list_lock, flags);
  540. list_for_each_entry(cl_device, &cl->dev->device_list,
  541. device_link) {
  542. if (cl_device->fw_client &&
  543. cl_device->fw_client->client_id == cl->fw_client_id) {
  544. cl->device = cl_device;
  545. rv = 0;
  546. break;
  547. }
  548. }
  549. spin_unlock_irqrestore(&cl->dev->device_list_lock, flags);
  550. return rv;
  551. }
  552. /**
  553. * ishtp_bus_remove_all_clients() - Remove all clients
  554. * @ishtp_dev: ishtp device
  555. * @warm_reset: Reset due to FW reset dure to errors or S3 suspend
  556. *
  557. * This is part of reset/remove flow. This function the main processing
  558. * only targets error processing, if the FW has forced reset or
  559. * error to remove connected clients. When warm reset the client devices are
  560. * not removed.
  561. */
  562. void ishtp_bus_remove_all_clients(struct ishtp_device *ishtp_dev,
  563. bool warm_reset)
  564. {
  565. struct ishtp_cl_device *cl_device, *n;
  566. struct ishtp_cl *cl;
  567. unsigned long flags;
  568. spin_lock_irqsave(&ishtp_dev->cl_list_lock, flags);
  569. list_for_each_entry(cl, &ishtp_dev->cl_list, link) {
  570. cl->state = ISHTP_CL_DISCONNECTED;
  571. /*
  572. * Wake any pending process. The waiter would check dev->state
  573. * and determine that it's not enabled already,
  574. * and will return error to its caller
  575. */
  576. wake_up_interruptible(&cl->wait_ctrl_res);
  577. /* Disband any pending read/write requests and free rb */
  578. ishtp_cl_flush_queues(cl);
  579. /* Remove all free and in_process rings, both Rx and Tx */
  580. ishtp_cl_free_rx_ring(cl);
  581. ishtp_cl_free_tx_ring(cl);
  582. /*
  583. * Free client and ISHTP bus client device structures
  584. * don't free host client because it is part of the OS fd
  585. * structure
  586. */
  587. }
  588. spin_unlock_irqrestore(&ishtp_dev->cl_list_lock, flags);
  589. /* Release DMA buffers for client messages */
  590. ishtp_cl_free_dma_buf(ishtp_dev);
  591. /* remove bus clients */
  592. spin_lock_irqsave(&ishtp_dev->device_list_lock, flags);
  593. list_for_each_entry_safe(cl_device, n, &ishtp_dev->device_list,
  594. device_link) {
  595. cl_device->fw_client = NULL;
  596. if (warm_reset && cl_device->reference_count)
  597. continue;
  598. list_del(&cl_device->device_link);
  599. spin_unlock_irqrestore(&ishtp_dev->device_list_lock, flags);
  600. ishtp_bus_remove_device(cl_device);
  601. spin_lock_irqsave(&ishtp_dev->device_list_lock, flags);
  602. }
  603. spin_unlock_irqrestore(&ishtp_dev->device_list_lock, flags);
  604. /* Free all client structures */
  605. spin_lock_irqsave(&ishtp_dev->fw_clients_lock, flags);
  606. kfree(ishtp_dev->fw_clients);
  607. ishtp_dev->fw_clients = NULL;
  608. ishtp_dev->fw_clients_num = 0;
  609. ishtp_dev->fw_client_presentation_num = 0;
  610. ishtp_dev->fw_client_index = 0;
  611. bitmap_zero(ishtp_dev->fw_clients_map, ISHTP_CLIENTS_MAX);
  612. spin_unlock_irqrestore(&ishtp_dev->fw_clients_lock, flags);
  613. }
  614. EXPORT_SYMBOL(ishtp_bus_remove_all_clients);
  615. /**
  616. * ishtp_reset_handler() - IPC reset handler
  617. * @dev: ishtp device
  618. *
  619. * ISHTP Handler for IPC_RESET notification
  620. */
  621. void ishtp_reset_handler(struct ishtp_device *dev)
  622. {
  623. unsigned long flags;
  624. /* Handle FW-initiated reset */
  625. dev->dev_state = ISHTP_DEV_RESETTING;
  626. /* Clear BH processing queue - no further HBMs */
  627. spin_lock_irqsave(&dev->rd_msg_spinlock, flags);
  628. dev->rd_msg_fifo_head = dev->rd_msg_fifo_tail = 0;
  629. spin_unlock_irqrestore(&dev->rd_msg_spinlock, flags);
  630. /* Handle ISH FW reset against upper layers */
  631. ishtp_bus_remove_all_clients(dev, true);
  632. }
  633. EXPORT_SYMBOL(ishtp_reset_handler);
  634. /**
  635. * ishtp_reset_compl_handler() - Reset completion handler
  636. * @dev: ishtp device
  637. *
  638. * ISHTP handler for IPC_RESET sequence completion to start
  639. * host message bus start protocol sequence.
  640. */
  641. void ishtp_reset_compl_handler(struct ishtp_device *dev)
  642. {
  643. dev->dev_state = ISHTP_DEV_INIT_CLIENTS;
  644. dev->hbm_state = ISHTP_HBM_START;
  645. ishtp_hbm_start_req(dev);
  646. }
  647. EXPORT_SYMBOL(ishtp_reset_compl_handler);
  648. /**
  649. * ishtp_use_dma_transfer() - Function to use DMA
  650. *
  651. * This interface is used to enable usage of DMA
  652. *
  653. * Return non zero if DMA can be enabled
  654. */
  655. int ishtp_use_dma_transfer(void)
  656. {
  657. return ishtp_use_dma;
  658. }
  659. /**
  660. * ishtp_bus_register() - Function to register bus
  661. *
  662. * This register ishtp bus
  663. *
  664. * Return: Return output of bus_register
  665. */
  666. static int __init ishtp_bus_register(void)
  667. {
  668. return bus_register(&ishtp_cl_bus_type);
  669. }
  670. /**
  671. * ishtp_bus_unregister() - Function to unregister bus
  672. *
  673. * This unregister ishtp bus
  674. */
  675. static void __exit ishtp_bus_unregister(void)
  676. {
  677. bus_unregister(&ishtp_cl_bus_type);
  678. }
  679. module_init(ishtp_bus_register);
  680. module_exit(ishtp_bus_unregister);
  681. MODULE_LICENSE("GPL");