Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 90e0b5f1 authored by Tomas Winkler's avatar Tomas Winkler Committed by Greg Kroah-Hartman
Browse files

mei: fix client functions names



Use common prefix for function names:

mei_cl_  - for host clients
mei_me_  - for me clients
mei_io_  - for io callback functions

Because mei_cl holds mei_device back pointer
we can also drop the dev argument from the client
functions

add client.h header to export the clients API

Signed-off-by: default avatarTomas Winkler <tomas.winkler@intel.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 9ca9050b
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@
#include "mei_dev.h"
#include "hbm.h"
#include "interface.h"
#include "client.h"

const uuid_le mei_amthi_guid  = UUID_LE(0x12f80028, 0xb4b7, 0x4b2d, 0xac,
						0xa8, 0x46, 0xe0, 0xff, 0x65,
@@ -73,7 +74,7 @@ void mei_amthif_host_init(struct mei_device *dev)
	dev->iamthif_cl.state = MEI_FILE_DISCONNECTED;

	/* find ME amthi client */
	i = mei_me_cl_link(dev, &dev->iamthif_cl,
	i = mei_cl_link_me(&dev->iamthif_cl,
			    &mei_amthi_guid, MEI_IAMTHIF_HOST_CLIENT_ID);
	if (i < 0) {
		dev_info(&dev->pdev->dev, "failed to find iamthif client.\n");
@@ -280,7 +281,7 @@ static int mei_amthif_send_cmd(struct mei_device *dev, struct mei_cl_cb *cb)
	memcpy(dev->iamthif_msg_buf, cb->request_buffer.data,
	       cb->request_buffer.size);

	ret = mei_flow_ctrl_creds(dev, &dev->iamthif_cl);
	ret = mei_cl_flow_ctrl_creds(&dev->iamthif_cl);
	if (ret < 0)
		return ret;

@@ -304,7 +305,7 @@ static int mei_amthif_send_cmd(struct mei_device *dev, struct mei_cl_cb *cb)
			return -ENODEV;

		if (mei_hdr.msg_complete) {
			if (mei_flow_ctrl_reduce(dev, &dev->iamthif_cl))
			if (mei_cl_flow_ctrl_reduce(&dev->iamthif_cl))
				return -ENODEV;
			dev->iamthif_flow_control_pending = true;
			dev->iamthif_state = MEI_IAMTHIF_FLOW_CONTROL;
@@ -467,7 +468,7 @@ int mei_amthif_irq_write_complete(struct mei_device *dev, s32 *slots,
			return -ENODEV;
	}

	if (mei_flow_ctrl_reduce(dev, cl))
	if (mei_cl_flow_ctrl_reduce(cl))
		return -ENODEV;

	dev->iamthif_msg_buf_index += mei_hdr.length;
+136 −85
Original line number Diff line number Diff line
@@ -24,6 +24,54 @@
#include "mei_dev.h"
#include "hbm.h"
#include "interface.h"
#include "client.h"

/**
 * mei_me_cl_by_uuid - locate index of me client
 *
 * @dev: mei device
 * returns me client index or -ENOENT if not found
 */
int mei_me_cl_by_uuid(const struct mei_device *dev, const uuid_le *uuid)
{
	int i, res = -ENOENT;

	for (i = 0; i < dev->me_clients_num; ++i)
		if (uuid_le_cmp(*uuid,
				dev->me_clients[i].props.protocol_name) == 0) {
			res = i;
			break;
		}

	return res;
}


/**
 * mei_me_cl_by_id return index to me_clients for client_id
 *
 * @dev: the device structure
 * @client_id: me client id
 *
 * Locking: called under "dev->device_lock" lock
 *
 * returns index on success, -ENOENT on failure.
 */

int mei_me_cl_by_id(struct mei_device *dev, u8 client_id)
{
	int i;
	for (i = 0; i < dev->me_clients_num; i++)
		if (dev->me_clients[i].client_id == client_id)
			break;
	if (WARN_ON(dev->me_clients[i].client_id != client_id))
		return -ENOENT;

	if (i == dev->me_clients_num)
		return -ENOENT;

	return i;
}


/**
@@ -141,7 +189,7 @@ int mei_io_cb_alloc_resp_buf(struct mei_cl_cb *cb, size_t length)
 */
int mei_cl_flush_queues(struct mei_cl *cl)
{
	if (!cl || !cl->dev)
	if (WARN_ON(!cl || !cl->dev))
		return -EINVAL;

	dev_dbg(&cl->dev->pdev->dev, "remove list entry belonging to cl\n");
@@ -155,52 +203,6 @@ int mei_cl_flush_queues(struct mei_cl *cl)
	return 0;
}

/**
 * mei_me_cl_by_uuid - locate index of me client
 *
 * @dev: mei device
 * returns me client index or -ENOENT if not found
 */
int mei_me_cl_by_uuid(const struct mei_device *dev, const uuid_le *uuid)
{
	int i, res = -ENOENT;

	for (i = 0; i < dev->me_clients_num; ++i)
		if (uuid_le_cmp(*uuid,
				dev->me_clients[i].props.protocol_name) == 0) {
			res = i;
			break;
		}

	return res;
}


/**
 * mei_me_cl_by_id return index to me_clients for client_id
 *
 * @dev: the device structure
 * @client_id: me client id
 *
 * Locking: called under "dev->device_lock" lock
 *
 * returns index on success, -ENOENT on failure.
 */

int mei_me_cl_by_id(struct mei_device *dev, u8 client_id)
{
	int i;
	for (i = 0; i < dev->me_clients_num; i++)
		if (dev->me_clients[i].client_id == client_id)
			break;
	if (WARN_ON(dev->me_clients[i].client_id != client_id))
		return -ENOENT;

	if (i == dev->me_clients_num)
		return -ENOENT;

	return i;
}

/**
 * mei_cl_init - initializes intialize cl.
@@ -239,12 +241,29 @@ struct mei_cl *mei_cl_allocate(struct mei_device *dev)
	return cl;
}

/**
 * mei_cl_find_read_cb - find this cl's callback in the read list
 *
 * @dev: device structure
 * returns cb on success, NULL on error
 */
struct mei_cl_cb *mei_cl_find_read_cb(struct mei_cl *cl)
{
	struct mei_device *dev = cl->dev;
	struct mei_cl_cb *cb = NULL;
	struct mei_cl_cb *next = NULL;

	list_for_each_entry_safe(cb, next, &dev->read_list.list, list)
		if (mei_cl_cmp_id(cl, cb->cl))
			return cb;
	return NULL;
}


/**
 * mei_me_cl_link - create link between host and me clinet and add
 *   me_cl to the list
 *
 * @dev: the device structure
 * @cl: link between me and host client assocated with opened file descriptor
 * @uuid: uuid of ME client
 * @client_id: id of the host client
@@ -253,14 +272,16 @@ struct mei_cl *mei_cl_allocate(struct mei_device *dev)
 *	-EINVAL on incorrect values
 *	-ENONET if client not found
 */
int mei_me_cl_link(struct mei_device *dev, struct mei_cl *cl,
			const uuid_le *uuid, u8 host_cl_id)
int mei_cl_link_me(struct mei_cl *cl, const uuid_le *uuid, u8 host_cl_id)
{
	struct mei_device *dev;
	int i;

	if (!dev || !cl || !uuid)
	if (WARN_ON(!cl || !cl->dev || !uuid))
		return -EINVAL;

	dev = cl->dev;

	/* check for valid client id */
	i = mei_me_cl_by_uuid(dev, uuid);
	if (i >= 0) {
@@ -275,14 +296,21 @@ int mei_me_cl_link(struct mei_device *dev, struct mei_cl *cl,
	return -ENOENT;
}
/**
 * mei_me_cl_unlink - remove me_cl from the list
 * mei_cl_unlink - remove me_cl from the list
 *
 * @dev: the device structure
 * @host_client_id: host client id to be removed
 */
void mei_me_cl_unlink(struct mei_device *dev, struct mei_cl *cl)
int mei_cl_unlink(struct mei_cl *cl)
{
	struct mei_device *dev;
	struct mei_cl *pos, *next;

	if (WARN_ON(!cl || !cl->dev))
		return -EINVAL;

	dev = cl->dev;

	list_for_each_entry_safe(pos, next, &dev->file_list, link) {
		if (cl->host_client_id == pos->host_client_id) {
			dev_dbg(&dev->pdev->dev, "remove host client = %d, ME client = %d\n",
@@ -291,6 +319,7 @@ void mei_me_cl_unlink(struct mei_device *dev, struct mei_cl *cl)
			break;
		}
	}
	return 0;
}


@@ -330,23 +359,25 @@ void mei_host_client_init(struct work_struct *work)


/**
 * mei_disconnect_host_client - sends disconnect message to fw from host client.
 * mei_cl_disconnect - disconnect host clinet form the me one
 *
 * @dev: the device structure
 * @cl: private data of the file object
 * @cl: host client
 *
 * Locking: called under "dev->device_lock" lock
 *
 * returns 0 on success, <0 on failure.
 */
int mei_disconnect_host_client(struct mei_device *dev, struct mei_cl *cl)
int mei_cl_disconnect(struct mei_cl *cl)
{
	struct mei_device *dev;
	struct mei_cl_cb *cb;
	int rets, err;

	if (!dev || !cl)
	if (WARN_ON(!cl || !cl->dev))
		return -ENODEV;

	dev = cl->dev;

	if (cl->state != MEI_FILE_DISCONNECTING)
		return 0;

@@ -401,32 +432,36 @@ int mei_disconnect_host_client(struct mei_device *dev, struct mei_cl *cl)


/**
 * mei_other_client_is_connecting - checks if other
 *    client with the same client id is connected.
 * mei_cl_is_other_connecting - checks if other
 *    client with the same me client id is connecting
 *
 * @dev: the device structure
 * @cl: private data of the file object
 *
 * returns 1 if other client is connected, 0 - otherwise.
 * returns ture if other client is connected, 0 - otherwise.
 */
int mei_other_client_is_connecting(struct mei_device *dev,
				struct mei_cl *cl)
bool mei_cl_is_other_connecting(struct mei_cl *cl)
{
	struct mei_cl *cl_pos = NULL;
	struct mei_cl *cl_next = NULL;
	struct mei_device *dev;
	struct mei_cl *pos;
	struct mei_cl *next;

	list_for_each_entry_safe(cl_pos, cl_next, &dev->file_list, link) {
		if ((cl_pos->state == MEI_FILE_CONNECTING) &&
			(cl_pos != cl) &&
			cl->me_client_id == cl_pos->me_client_id)
			return 1;
	if (WARN_ON(!cl || !cl->dev))
		return false;

	dev = cl->dev;

	list_for_each_entry_safe(pos, next, &dev->file_list, link) {
		if ((pos->state == MEI_FILE_CONNECTING) &&
		    (pos != cl) && cl->me_client_id == pos->me_client_id)
			return true;

	}
	return 0;

	return false;
}

/**
 * mei_flow_ctrl_creds - checks flow_control credentials.
 * mei_cl_flow_ctrl_creds - checks flow_control credits for cl.
 *
 * @dev: the device structure
 * @cl: private data of the file object
@@ -435,10 +470,16 @@ int mei_other_client_is_connecting(struct mei_device *dev,
 *	-ENOENT if mei_cl is not present
 *	-EINVAL if single_recv_buf == 0
 */
int mei_flow_ctrl_creds(struct mei_device *dev, struct mei_cl *cl)
int mei_cl_flow_ctrl_creds(struct mei_cl *cl)
{
	struct mei_device *dev;
	int i;

	if (WARN_ON(!cl || !cl->dev))
		return -EINVAL;

	dev = cl->dev;

	if (!dev->me_clients_num)
		return 0;

@@ -461,7 +502,7 @@ int mei_flow_ctrl_creds(struct mei_device *dev, struct mei_cl *cl)
}

/**
 * mei_flow_ctrl_reduce - reduces flow_control.
 * mei_cl_flow_ctrl_reduce - reduces flow_control.
 *
 * @dev: the device structure
 * @cl: private data of the file object
@@ -470,10 +511,16 @@ int mei_flow_ctrl_creds(struct mei_device *dev, struct mei_cl *cl)
 *	-ENOENT when me client is not found
 *	-EINVAL when ctrl credits are <= 0
 */
int mei_flow_ctrl_reduce(struct mei_device *dev, struct mei_cl *cl)
int mei_cl_flow_ctrl_reduce(struct mei_cl *cl)
{
	struct mei_device *dev;
	int i;

	if (WARN_ON(!cl || !cl->dev))
		return -EINVAL;

	dev = cl->dev;

	if (!dev->me_clients_num)
		return -ENOENT;

@@ -571,7 +618,7 @@ int mei_ioctl_connect_client(struct file *file,
			goto end;
		}
		clear_bit(cl->host_client_id, dev->host_clients_map);
		mei_me_cl_unlink(dev, cl);
		mei_cl_unlink(cl);

		kfree(cl);
		cl = NULL;
@@ -598,8 +645,8 @@ int mei_ioctl_connect_client(struct file *file,
	client->max_msg_length = dev->me_clients[i].props.max_msg_length;
	client->protocol_version = dev->me_clients[i].props.protocol_version;
	dev_dbg(&dev->pdev->dev, "Can connect?\n");
	if (dev->mei_host_buffer_is_empty
	    && !mei_other_client_is_connecting(dev, cl)) {
	if (dev->mei_host_buffer_is_empty &&
	    !mei_cl_is_other_connecting(cl)) {
		dev_dbg(&dev->pdev->dev, "Sending Connect Message\n");
		dev->mei_host_buffer_is_empty = false;
		if (mei_hbm_cl_connect_req(dev, cl)) {
@@ -650,20 +697,24 @@ int mei_ioctl_connect_client(struct file *file,
}

/**
 * mei_start_read - the start read client message function.
 * mei_cl_start_read - the start read client message function.
 *
 * @dev: the device structure
 * @if_num:  minor number
 * @cl: private data of the file object
 * @cl: host client
 *
 * returns 0 on success, <0 on failure.
 */
int mei_start_read(struct mei_device *dev, struct mei_cl *cl)
int mei_cl_read_start(struct mei_cl *cl)
{
	struct mei_device *dev;
	struct mei_cl_cb *cb;
	int rets;
	int i;

	if (WARN_ON(!cl || !cl->dev))
		return -ENODEV;

	dev = cl->dev;

	if (cl->state != MEI_FILE_CONNECTED)
		return -ENODEV;

+97 −0
Original line number Diff line number Diff line
/*
 *
 * Intel Management Engine Interface (Intel MEI) Linux driver
 * Copyright (c) 2003-2012, Intel Corporation.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms and conditions of the GNU General Public License,
 * version 2, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 */

#ifndef _MEI_CLIENT_H_
#define _MEI_CLIENT_H_

#include <linux/types.h>
#include <linux/watchdog.h>
#include <linux/poll.h>
#include <linux/mei.h>

#include "mei_dev.h"

int mei_me_cl_by_uuid(const struct mei_device *dev, const uuid_le *cuuid);
int mei_me_cl_by_id(struct mei_device *dev, u8 client_id);

/*
 * MEI IO Functions
 */
struct mei_cl_cb *mei_io_cb_init(struct mei_cl *cl, struct file *fp);
void mei_io_cb_free(struct mei_cl_cb *priv_cb);
int mei_io_cb_alloc_req_buf(struct mei_cl_cb *cb, size_t length);
int mei_io_cb_alloc_resp_buf(struct mei_cl_cb *cb, size_t length);


/**
 * mei_io_list_init - Sets up a queue list.
 *
 * @list: An instance cl callback structure
 */
static inline void mei_io_list_init(struct mei_cl_cb *list)
{
	INIT_LIST_HEAD(&list->list);
}
void mei_io_list_flush(struct mei_cl_cb *list, struct mei_cl *cl);

/*
 * MEI Host Client Functions
 */

struct mei_cl *mei_cl_allocate(struct mei_device *dev);
void mei_cl_init(struct mei_cl *cl, struct mei_device *dev);


int mei_cl_link_me(struct mei_cl *cl, const uuid_le *uuid, u8 host_cl_id);
int mei_cl_unlink(struct mei_cl *cl);

int mei_cl_flush_queues(struct mei_cl *cl);
struct mei_cl_cb *mei_cl_find_read_cb(struct mei_cl *cl);

/**
 * mei_cl_cmp_id - tells if file private data have same id
 *
 * @fe1: private data of 1. file object
 * @fe2: private data of 2. file object
 *
 * returns true  - if ids are the same and not NULL
 */
static inline bool mei_cl_cmp_id(const struct mei_cl *cl1,
				const struct mei_cl *cl2)
{
	return cl1 && cl2 &&
		(cl1->host_client_id == cl2->host_client_id) &&
		(cl1->me_client_id == cl2->me_client_id);
}


int mei_cl_flow_ctrl_creds(struct mei_cl *cl);

int mei_cl_flow_ctrl_reduce(struct mei_cl *cl);
/*
 *  MEI input output function prototype
 */
bool mei_cl_is_other_connecting(struct mei_cl *cl);
int mei_cl_disconnect(struct mei_cl *cl);

int mei_cl_read_start(struct mei_cl *cl);

int mei_cl_connect(struct mei_cl *cl, struct file *file);

void mei_host_client_init(struct work_struct *work);


#endif /* _MEI_CLIENT_H_ */
+3 −3
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@

#include "mei_dev.h"
#include "interface.h"
#include "client.h"

const char *mei_dev_state_str(int state)
{
@@ -241,9 +242,8 @@ void mei_reset(struct mei_device *dev, int interrupts_enabled)
		}
		/* remove entry if already in list */
		dev_dbg(&dev->pdev->dev, "remove iamthif and wd from the file list.\n");
		mei_me_cl_unlink(dev, &dev->wd_cl);

		mei_me_cl_unlink(dev, &dev->iamthif_cl);
		mei_cl_unlink(&dev->wd_cl);
		mei_cl_unlink(&dev->iamthif_cl);

		mei_amthif_reset_params(dev);
		memset(&dev->wr_ext_msg, 0, sizeof(dev->wr_ext_msg));
+0 −8
Original line number Diff line number Diff line
@@ -50,7 +50,6 @@ static inline unsigned char mei_data2slots(size_t length)
int mei_count_full_read_slots(struct mei_device *dev);


int mei_flow_ctrl_creds(struct mei_device *dev, struct mei_cl *cl);



@@ -69,12 +68,5 @@ void mei_watchdog_register(struct mei_device *dev);
 */
void mei_watchdog_unregister(struct mei_device *dev);

int mei_other_client_is_connecting(struct mei_device *dev, struct mei_cl *cl);
int mei_flow_ctrl_reduce(struct mei_device *dev, struct mei_cl *cl);

void mei_host_client_init(struct work_struct *work);




#endif /* _MEI_INTERFACE_H_ */
Loading