1
0

init.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * Initialization protocol for ISHTP driver
  3. *
  4. * Copyright (c) 2003-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/export.h>
  16. #include <linux/slab.h>
  17. #include <linux/sched.h>
  18. #include "ishtp-dev.h"
  19. #include "hbm.h"
  20. #include "client.h"
  21. /**
  22. * ishtp_dev_state_str() -Convert to string format
  23. * @state: state to convert
  24. *
  25. * Convert state to string for prints
  26. *
  27. * Return: character pointer to converted string
  28. */
  29. const char *ishtp_dev_state_str(int state)
  30. {
  31. switch (state) {
  32. case ISHTP_DEV_INITIALIZING:
  33. return "INITIALIZING";
  34. case ISHTP_DEV_INIT_CLIENTS:
  35. return "INIT_CLIENTS";
  36. case ISHTP_DEV_ENABLED:
  37. return "ENABLED";
  38. case ISHTP_DEV_RESETTING:
  39. return "RESETTING";
  40. case ISHTP_DEV_DISABLED:
  41. return "DISABLED";
  42. case ISHTP_DEV_POWER_DOWN:
  43. return "POWER_DOWN";
  44. case ISHTP_DEV_POWER_UP:
  45. return "POWER_UP";
  46. default:
  47. return "unknown";
  48. }
  49. }
  50. /**
  51. * ishtp_device_init() - ishtp device init
  52. * @dev: ISHTP device instance
  53. *
  54. * After ISHTP device is alloacted, this function is used to initialize
  55. * each field which includes spin lock, work struct and lists
  56. */
  57. void ishtp_device_init(struct ishtp_device *dev)
  58. {
  59. dev->dev_state = ISHTP_DEV_INITIALIZING;
  60. INIT_LIST_HEAD(&dev->cl_list);
  61. INIT_LIST_HEAD(&dev->device_list);
  62. dev->rd_msg_fifo_head = 0;
  63. dev->rd_msg_fifo_tail = 0;
  64. spin_lock_init(&dev->rd_msg_spinlock);
  65. init_waitqueue_head(&dev->wait_hbm_recvd_msg);
  66. spin_lock_init(&dev->read_list_spinlock);
  67. spin_lock_init(&dev->device_lock);
  68. spin_lock_init(&dev->device_list_lock);
  69. spin_lock_init(&dev->cl_list_lock);
  70. spin_lock_init(&dev->fw_clients_lock);
  71. INIT_WORK(&dev->bh_hbm_work, bh_hbm_work_fn);
  72. bitmap_zero(dev->host_clients_map, ISHTP_CLIENTS_MAX);
  73. dev->open_handle_count = 0;
  74. /*
  75. * Reserving client ID 0 for ISHTP Bus Message communications
  76. */
  77. bitmap_set(dev->host_clients_map, 0, 1);
  78. INIT_LIST_HEAD(&dev->read_list.list);
  79. }
  80. EXPORT_SYMBOL(ishtp_device_init);
  81. /**
  82. * ishtp_start() - Start ISH processing
  83. * @dev: ISHTP device instance
  84. *
  85. * Start ISHTP processing by sending query subscriber message
  86. *
  87. * Return: 0 on success else -ENODEV
  88. */
  89. int ishtp_start(struct ishtp_device *dev)
  90. {
  91. if (ishtp_hbm_start_wait(dev)) {
  92. dev_err(dev->devc, "HBM haven't started");
  93. goto err;
  94. }
  95. /* suspend & resume notification - send QUERY_SUBSCRIBERS msg */
  96. ishtp_query_subscribers(dev);
  97. return 0;
  98. err:
  99. dev_err(dev->devc, "link layer initialization failed.\n");
  100. dev->dev_state = ISHTP_DEV_DISABLED;
  101. return -ENODEV;
  102. }
  103. EXPORT_SYMBOL(ishtp_start);