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