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