18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Initialization protocol for ISHTP driver 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (c) 2003-2016, Intel Corporation. 68c2ecf20Sopenharmony_ci */ 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#include <linux/export.h> 98c2ecf20Sopenharmony_ci#include <linux/slab.h> 108c2ecf20Sopenharmony_ci#include <linux/sched.h> 118c2ecf20Sopenharmony_ci#include "ishtp-dev.h" 128c2ecf20Sopenharmony_ci#include "hbm.h" 138c2ecf20Sopenharmony_ci#include "client.h" 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci/** 168c2ecf20Sopenharmony_ci * ishtp_dev_state_str() -Convert to string format 178c2ecf20Sopenharmony_ci * @state: state to convert 188c2ecf20Sopenharmony_ci * 198c2ecf20Sopenharmony_ci * Convert state to string for prints 208c2ecf20Sopenharmony_ci * 218c2ecf20Sopenharmony_ci * Return: character pointer to converted string 228c2ecf20Sopenharmony_ci */ 238c2ecf20Sopenharmony_ciconst char *ishtp_dev_state_str(int state) 248c2ecf20Sopenharmony_ci{ 258c2ecf20Sopenharmony_ci switch (state) { 268c2ecf20Sopenharmony_ci case ISHTP_DEV_INITIALIZING: 278c2ecf20Sopenharmony_ci return "INITIALIZING"; 288c2ecf20Sopenharmony_ci case ISHTP_DEV_INIT_CLIENTS: 298c2ecf20Sopenharmony_ci return "INIT_CLIENTS"; 308c2ecf20Sopenharmony_ci case ISHTP_DEV_ENABLED: 318c2ecf20Sopenharmony_ci return "ENABLED"; 328c2ecf20Sopenharmony_ci case ISHTP_DEV_RESETTING: 338c2ecf20Sopenharmony_ci return "RESETTING"; 348c2ecf20Sopenharmony_ci case ISHTP_DEV_DISABLED: 358c2ecf20Sopenharmony_ci return "DISABLED"; 368c2ecf20Sopenharmony_ci case ISHTP_DEV_POWER_DOWN: 378c2ecf20Sopenharmony_ci return "POWER_DOWN"; 388c2ecf20Sopenharmony_ci case ISHTP_DEV_POWER_UP: 398c2ecf20Sopenharmony_ci return "POWER_UP"; 408c2ecf20Sopenharmony_ci default: 418c2ecf20Sopenharmony_ci return "unknown"; 428c2ecf20Sopenharmony_ci } 438c2ecf20Sopenharmony_ci} 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci/** 468c2ecf20Sopenharmony_ci * ishtp_device_init() - ishtp device init 478c2ecf20Sopenharmony_ci * @dev: ISHTP device instance 488c2ecf20Sopenharmony_ci * 498c2ecf20Sopenharmony_ci * After ISHTP device is alloacted, this function is used to initialize 508c2ecf20Sopenharmony_ci * each field which includes spin lock, work struct and lists 518c2ecf20Sopenharmony_ci */ 528c2ecf20Sopenharmony_civoid ishtp_device_init(struct ishtp_device *dev) 538c2ecf20Sopenharmony_ci{ 548c2ecf20Sopenharmony_ci dev->dev_state = ISHTP_DEV_INITIALIZING; 558c2ecf20Sopenharmony_ci INIT_LIST_HEAD(&dev->cl_list); 568c2ecf20Sopenharmony_ci INIT_LIST_HEAD(&dev->device_list); 578c2ecf20Sopenharmony_ci dev->rd_msg_fifo_head = 0; 588c2ecf20Sopenharmony_ci dev->rd_msg_fifo_tail = 0; 598c2ecf20Sopenharmony_ci spin_lock_init(&dev->rd_msg_spinlock); 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ci init_waitqueue_head(&dev->wait_hbm_recvd_msg); 628c2ecf20Sopenharmony_ci spin_lock_init(&dev->read_list_spinlock); 638c2ecf20Sopenharmony_ci spin_lock_init(&dev->device_lock); 648c2ecf20Sopenharmony_ci spin_lock_init(&dev->device_list_lock); 658c2ecf20Sopenharmony_ci spin_lock_init(&dev->cl_list_lock); 668c2ecf20Sopenharmony_ci spin_lock_init(&dev->fw_clients_lock); 678c2ecf20Sopenharmony_ci INIT_WORK(&dev->bh_hbm_work, bh_hbm_work_fn); 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ci bitmap_zero(dev->host_clients_map, ISHTP_CLIENTS_MAX); 708c2ecf20Sopenharmony_ci dev->open_handle_count = 0; 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_ci /* 738c2ecf20Sopenharmony_ci * Reserving client ID 0 for ISHTP Bus Message communications 748c2ecf20Sopenharmony_ci */ 758c2ecf20Sopenharmony_ci bitmap_set(dev->host_clients_map, 0, 1); 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ci INIT_LIST_HEAD(&dev->read_list.list); 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_ci} 808c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ishtp_device_init); 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci/** 838c2ecf20Sopenharmony_ci * ishtp_start() - Start ISH processing 848c2ecf20Sopenharmony_ci * @dev: ISHTP device instance 858c2ecf20Sopenharmony_ci * 868c2ecf20Sopenharmony_ci * Start ISHTP processing by sending query subscriber message 878c2ecf20Sopenharmony_ci * 888c2ecf20Sopenharmony_ci * Return: 0 on success else -ENODEV 898c2ecf20Sopenharmony_ci */ 908c2ecf20Sopenharmony_ciint ishtp_start(struct ishtp_device *dev) 918c2ecf20Sopenharmony_ci{ 928c2ecf20Sopenharmony_ci if (ishtp_hbm_start_wait(dev)) { 938c2ecf20Sopenharmony_ci dev_err(dev->devc, "HBM haven't started"); 948c2ecf20Sopenharmony_ci goto err; 958c2ecf20Sopenharmony_ci } 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_ci /* suspend & resume notification - send QUERY_SUBSCRIBERS msg */ 988c2ecf20Sopenharmony_ci ishtp_query_subscribers(dev); 998c2ecf20Sopenharmony_ci 1008c2ecf20Sopenharmony_ci return 0; 1018c2ecf20Sopenharmony_cierr: 1028c2ecf20Sopenharmony_ci dev_err(dev->devc, "link layer initialization failed.\n"); 1038c2ecf20Sopenharmony_ci dev->dev_state = ISHTP_DEV_DISABLED; 1048c2ecf20Sopenharmony_ci return -ENODEV; 1058c2ecf20Sopenharmony_ci} 1068c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ishtp_start); 107