1 // SPDX-License-Identifier: GPL-2.0-only
3 * Initialization protocol for ISHTP driver
5 * Copyright (c) 2003-2016, Intel Corporation.
8 #include <linux/export.h>
9 #include <linux/slab.h>
10 #include <linux/sched.h>
11 #include "ishtp-dev.h"
16 * ishtp_dev_state_str() -Convert to string format
17 * @state: state to convert
19 * Convert state to string for prints
21 * Return: character pointer to converted string
23 const char *ishtp_dev_state_str(int state
)
26 case ISHTP_DEV_INITIALIZING
:
27 return "INITIALIZING";
28 case ISHTP_DEV_INIT_CLIENTS
:
29 return "INIT_CLIENTS";
30 case ISHTP_DEV_ENABLED
:
32 case ISHTP_DEV_RESETTING
:
34 case ISHTP_DEV_DISABLED
:
36 case ISHTP_DEV_POWER_DOWN
:
38 case ISHTP_DEV_POWER_UP
:
46 * ishtp_device_init() - ishtp device init
47 * @dev: ISHTP device instance
49 * After ISHTP device is alloacted, this function is used to initialize
50 * each field which includes spin lock, work struct and lists
52 void ishtp_device_init(struct ishtp_device
*dev
)
54 dev
->dev_state
= ISHTP_DEV_INITIALIZING
;
55 INIT_LIST_HEAD(&dev
->cl_list
);
56 INIT_LIST_HEAD(&dev
->device_list
);
57 dev
->rd_msg_fifo_head
= 0;
58 dev
->rd_msg_fifo_tail
= 0;
59 spin_lock_init(&dev
->rd_msg_spinlock
);
61 init_waitqueue_head(&dev
->wait_hbm_recvd_msg
);
62 spin_lock_init(&dev
->read_list_spinlock
);
63 spin_lock_init(&dev
->device_lock
);
64 spin_lock_init(&dev
->device_list_lock
);
65 spin_lock_init(&dev
->cl_list_lock
);
66 spin_lock_init(&dev
->fw_clients_lock
);
67 INIT_WORK(&dev
->bh_hbm_work
, bh_hbm_work_fn
);
69 bitmap_zero(dev
->host_clients_map
, ISHTP_CLIENTS_MAX
);
70 dev
->open_handle_count
= 0;
73 * Reserving client ID 0 for ISHTP Bus Message communications
75 bitmap_set(dev
->host_clients_map
, 0, 1);
77 INIT_LIST_HEAD(&dev
->read_list
.list
);
80 EXPORT_SYMBOL(ishtp_device_init
);
83 * ishtp_start() - Start ISH processing
84 * @dev: ISHTP device instance
86 * Start ISHTP processing by sending query subscriber message
88 * Return: 0 on success else -ENODEV
90 int ishtp_start(struct ishtp_device
*dev
)
92 if (ishtp_hbm_start_wait(dev
)) {
93 dev_err(dev
->devc
, "HBM haven't started");
97 /* suspend & resume notification - send QUERY_SUBSCRIBERS msg */
98 ishtp_query_subscribers(dev
);
102 dev_err(dev
->devc
, "link layer initialization failed.\n");
103 dev
->dev_state
= ISHTP_DEV_DISABLED
;
106 EXPORT_SYMBOL(ishtp_start
);