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 "ishtp-dev.h"
24 * ishtp_dev_state_str() -Convert to string format
25 * @state: state to convert
27 * Convert state to string for prints
29 * Return: character pointer to converted string
31 const char *ishtp_dev_state_str(int state
)
34 case ISHTP_DEV_INITIALIZING
:
35 return "INITIALIZING";
36 case ISHTP_DEV_INIT_CLIENTS
:
37 return "INIT_CLIENTS";
38 case ISHTP_DEV_ENABLED
:
40 case ISHTP_DEV_RESETTING
:
42 case ISHTP_DEV_DISABLED
:
44 case ISHTP_DEV_POWER_DOWN
:
46 case ISHTP_DEV_POWER_UP
:
54 * ishtp_device_init() - ishtp device init
55 * @dev: ISHTP device instance
57 * After ISHTP device is alloacted, this function is used to initialize
58 * each field which includes spin lock, work struct and lists
60 void ishtp_device_init(struct ishtp_device
*dev
)
62 dev
->dev_state
= ISHTP_DEV_INITIALIZING
;
63 INIT_LIST_HEAD(&dev
->cl_list
);
64 INIT_LIST_HEAD(&dev
->device_list
);
65 dev
->rd_msg_fifo_head
= 0;
66 dev
->rd_msg_fifo_tail
= 0;
67 spin_lock_init(&dev
->rd_msg_spinlock
);
69 init_waitqueue_head(&dev
->wait_hbm_recvd_msg
);
70 spin_lock_init(&dev
->read_list_spinlock
);
71 spin_lock_init(&dev
->device_lock
);
72 spin_lock_init(&dev
->device_list_lock
);
73 spin_lock_init(&dev
->cl_list_lock
);
74 spin_lock_init(&dev
->fw_clients_lock
);
75 INIT_WORK(&dev
->bh_hbm_work
, bh_hbm_work_fn
);
77 bitmap_zero(dev
->host_clients_map
, ISHTP_CLIENTS_MAX
);
78 dev
->open_handle_count
= 0;
81 * Reserving client ID 0 for ISHTP Bus Message communications
83 bitmap_set(dev
->host_clients_map
, 0, 1);
85 INIT_LIST_HEAD(&dev
->read_list
.list
);
88 EXPORT_SYMBOL(ishtp_device_init
);
91 * ishtp_start() - Start ISH processing
92 * @dev: ISHTP device instance
94 * Start ISHTP processing by sending query subscriber message
96 * Return: 0 on success else -ENODEV
98 int ishtp_start(struct ishtp_device
*dev
)
100 if (ishtp_hbm_start_wait(dev
)) {
101 dev_err(dev
->devc
, "HBM haven't started");
105 /* suspend & resume notification - send QUERY_SUBSCRIBERS msg */
106 ishtp_query_subscribers(dev
);
110 dev_err(dev
->devc
, "link layer initialization failed.\n");
111 dev
->dev_state
= ISHTP_DEV_DISABLED
;
114 EXPORT_SYMBOL(ishtp_start
);