Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Initialization protocol for ISHTP driver
0004  *
0005  * Copyright (c) 2003-2016, Intel Corporation.
0006  */
0007 
0008 #include <linux/export.h>
0009 #include <linux/slab.h>
0010 #include <linux/sched.h>
0011 #include "ishtp-dev.h"
0012 #include "hbm.h"
0013 #include "client.h"
0014 
0015 /**
0016  * ishtp_dev_state_str() -Convert to string format
0017  * @state: state to convert
0018  *
0019  * Convert state to string for prints
0020  *
0021  * Return: character pointer to converted string
0022  */
0023 const char *ishtp_dev_state_str(int state)
0024 {
0025     switch (state) {
0026     case ISHTP_DEV_INITIALIZING:
0027         return  "INITIALIZING";
0028     case ISHTP_DEV_INIT_CLIENTS:
0029         return  "INIT_CLIENTS";
0030     case ISHTP_DEV_ENABLED:
0031         return  "ENABLED";
0032     case ISHTP_DEV_RESETTING:
0033         return  "RESETTING";
0034     case ISHTP_DEV_DISABLED:
0035         return  "DISABLED";
0036     case ISHTP_DEV_POWER_DOWN:
0037         return  "POWER_DOWN";
0038     case ISHTP_DEV_POWER_UP:
0039         return  "POWER_UP";
0040     default:
0041         return "unknown";
0042     }
0043 }
0044 
0045 /**
0046  * ishtp_device_init() - ishtp device init
0047  * @dev: ISHTP device instance
0048  *
0049  * After ISHTP device is alloacted, this function is used to initialize
0050  * each field which includes spin lock, work struct and lists
0051  */
0052 void ishtp_device_init(struct ishtp_device *dev)
0053 {
0054     dev->dev_state = ISHTP_DEV_INITIALIZING;
0055     INIT_LIST_HEAD(&dev->cl_list);
0056     INIT_LIST_HEAD(&dev->device_list);
0057     dev->rd_msg_fifo_head = 0;
0058     dev->rd_msg_fifo_tail = 0;
0059     spin_lock_init(&dev->rd_msg_spinlock);
0060 
0061     init_waitqueue_head(&dev->wait_hbm_recvd_msg);
0062     spin_lock_init(&dev->read_list_spinlock);
0063     spin_lock_init(&dev->device_lock);
0064     spin_lock_init(&dev->device_list_lock);
0065     spin_lock_init(&dev->cl_list_lock);
0066     spin_lock_init(&dev->fw_clients_lock);
0067     INIT_WORK(&dev->bh_hbm_work, bh_hbm_work_fn);
0068 
0069     bitmap_zero(dev->host_clients_map, ISHTP_CLIENTS_MAX);
0070     dev->open_handle_count = 0;
0071 
0072     /*
0073      * Reserving client ID 0 for ISHTP Bus Message communications
0074      */
0075     bitmap_set(dev->host_clients_map, 0, 1);
0076 
0077     INIT_LIST_HEAD(&dev->read_list.list);
0078 
0079 }
0080 EXPORT_SYMBOL(ishtp_device_init);
0081 
0082 /**
0083  * ishtp_start() - Start ISH processing
0084  * @dev: ISHTP device instance
0085  *
0086  * Start ISHTP processing by sending query subscriber message
0087  *
0088  * Return: 0 on success else -ENODEV
0089  */
0090 int ishtp_start(struct ishtp_device *dev)
0091 {
0092     if (ishtp_hbm_start_wait(dev)) {
0093         dev_err(dev->devc, "HBM haven't started");
0094         goto err;
0095     }
0096 
0097     /* suspend & resume notification - send QUERY_SUBSCRIBERS msg */
0098     ishtp_query_subscribers(dev);
0099 
0100     return 0;
0101 err:
0102     dev_err(dev->devc, "link layer initialization failed.\n");
0103     dev->dev_state = ISHTP_DEV_DISABLED;
0104     return -ENODEV;
0105 }
0106 EXPORT_SYMBOL(ishtp_start);