2 * Initialization protocol for ISHTP driver
4 * Copyright (c) 2003-2016, Intel Corporation.
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.
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
16 #include <linux/export.h>
17 #include <linux/slab.h>
18 #include <linux/sched.h>
19 #include <linux/miscdevice.h>
20 #include "ishtp-dev.h"
25 * ishtp_dev_state_str() -Convert to string format
26 * @state: state to convert
28 * Convert state to string for prints
30 * Return: character pointer to converted string
32 const char *ishtp_dev_state_str(int state)
35 case ISHTP_DEV_INITIALIZING:
36 return "INITIALIZING";
37 case ISHTP_DEV_INIT_CLIENTS:
38 return "INIT_CLIENTS";
39 case ISHTP_DEV_ENABLED:
41 case ISHTP_DEV_RESETTING:
43 case ISHTP_DEV_DISABLED:
45 case ISHTP_DEV_POWER_DOWN:
47 case ISHTP_DEV_POWER_UP:
55 * ishtp_device_init() - ishtp device init
56 * @dev: ISHTP device instance
58 * After ISHTP device is alloacted, this function is used to initialize
59 * each field which includes spin lock, work struct and lists
61 void ishtp_device_init(struct ishtp_device *dev)
63 dev->dev_state = ISHTP_DEV_INITIALIZING;
64 INIT_LIST_HEAD(&dev->cl_list);
65 INIT_LIST_HEAD(&dev->device_list);
66 dev->rd_msg_fifo_head = 0;
67 dev->rd_msg_fifo_tail = 0;
68 spin_lock_init(&dev->rd_msg_spinlock);
70 init_waitqueue_head(&dev->wait_hbm_recvd_msg);
71 spin_lock_init(&dev->read_list_spinlock);
72 spin_lock_init(&dev->device_lock);
73 spin_lock_init(&dev->device_list_lock);
74 spin_lock_init(&dev->cl_list_lock);
75 spin_lock_init(&dev->fw_clients_lock);
76 INIT_WORK(&dev->bh_hbm_work, bh_hbm_work_fn);
78 bitmap_zero(dev->host_clients_map, ISHTP_CLIENTS_MAX);
79 dev->open_handle_count = 0;
82 * Reserving client ID 0 for ISHTP Bus Message communications
84 bitmap_set(dev->host_clients_map, 0, 1);
86 INIT_LIST_HEAD(&dev->read_list.list);
89 EXPORT_SYMBOL(ishtp_device_init);
92 * ishtp_start() - Start ISH processing
93 * @dev: ISHTP device instance
95 * Start ISHTP processing by sending query subscriber message
97 * Return: 0 on success else -ENODEV
99 int ishtp_start(struct ishtp_device *dev)
101 if (ishtp_hbm_start_wait(dev)) {
102 dev_err(dev->devc, "HBM haven't started");
106 /* suspend & resume notification - send QUERY_SUBSCRIBERS msg */
107 ishtp_query_subscribers(dev);
111 dev_err(dev->devc, "link layer initialization failed.\n");
112 dev->dev_state = ISHTP_DEV_DISABLED;
115 EXPORT_SYMBOL(ishtp_start);