^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (c) 2003-2020, Intel Corporation. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Intel Management Engine Interface (Intel MEI) Linux driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/moduleparam.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/fcntl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/poll.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/ioctl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/cdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/sched/signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/uuid.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/compat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/jiffies.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/mei.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include "mei_dev.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include "client.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) static struct class *mei_class;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) static dev_t mei_devt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #define MEI_MAX_DEVS MINORMASK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) static DEFINE_MUTEX(mei_minor_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) static DEFINE_IDR(mei_idr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) * mei_open - the open function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) * @inode: pointer to inode structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) * @file: pointer to file structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * Return: 0 on success, <0 on error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) static int mei_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) struct mei_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) struct mei_cl *cl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) dev = container_of(inode->i_cdev, struct mei_device, cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) if (!dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) mutex_lock(&dev->device_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) if (dev->dev_state != MEI_DEV_ENABLED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) dev_dbg(dev->dev, "dev_state != MEI_ENABLED dev_state = %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) mei_dev_state_str(dev->dev_state));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) err = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) goto err_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) cl = mei_cl_alloc_linked(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) if (IS_ERR(cl)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) err = PTR_ERR(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) goto err_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) cl->fp = file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) file->private_data = cl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) mutex_unlock(&dev->device_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) return nonseekable_open(inode, file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) err_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) mutex_unlock(&dev->device_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) * mei_cl_vtag_remove_by_fp - remove vtag that corresponds to fp from list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) * @cl: host client
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) * @fp: pointer to file structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) static void mei_cl_vtag_remove_by_fp(const struct mei_cl *cl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) const struct file *fp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) struct mei_cl_vtag *vtag_l, *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) list_for_each_entry_safe(vtag_l, next, &cl->vtag_map, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) if (vtag_l->fp == fp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) list_del(&vtag_l->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) kfree(vtag_l);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) * mei_release - the release function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) * @inode: pointer to inode structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) * @file: pointer to file structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) * Return: 0 on success, <0 on error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) static int mei_release(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) struct mei_cl *cl = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) struct mei_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) int rets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) if (WARN_ON(!cl || !cl->dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) dev = cl->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) mutex_lock(&dev->device_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) mei_cl_vtag_remove_by_fp(cl, file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) if (!list_empty(&cl->vtag_map)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) cl_dbg(dev, cl, "not the last vtag\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) mei_cl_flush_queues(cl, file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) rets = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) rets = mei_cl_disconnect(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) * Check again: This is necessary since disconnect releases the lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) * and another client can connect in the meantime.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) if (!list_empty(&cl->vtag_map)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) cl_dbg(dev, cl, "not the last vtag after disconnect\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) mei_cl_flush_queues(cl, file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) mei_cl_flush_queues(cl, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) cl_dbg(dev, cl, "removing\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) mei_cl_unlink(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) kfree(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) file->private_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) mutex_unlock(&dev->device_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) return rets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) * mei_read - the read function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) * @file: pointer to file structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) * @ubuf: pointer to user buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) * @length: buffer length
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) * @offset: data offset in buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) * Return: >=0 data length on success , <0 on error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) static ssize_t mei_read(struct file *file, char __user *ubuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) size_t length, loff_t *offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) struct mei_cl *cl = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) struct mei_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) struct mei_cl_cb *cb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) bool nonblock = !!(file->f_flags & O_NONBLOCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) ssize_t rets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) if (WARN_ON(!cl || !cl->dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) dev = cl->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) mutex_lock(&dev->device_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) if (dev->dev_state != MEI_DEV_ENABLED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) rets = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) if (length == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) rets = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) if (ubuf == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) rets = -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) cb = mei_cl_read_cb(cl, file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) if (cb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) goto copy_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) if (*offset > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) *offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) rets = mei_cl_read_start(cl, length, file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) if (rets && rets != -EBUSY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) cl_dbg(dev, cl, "mei start read failure status = %zd\n", rets);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) if (nonblock) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) rets = -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) mutex_unlock(&dev->device_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) if (wait_event_interruptible(cl->rx_wait,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) mei_cl_read_cb(cl, file) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) !mei_cl_is_connected(cl))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) if (signal_pending(current))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) return -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) return -ERESTARTSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) mutex_lock(&dev->device_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) if (!mei_cl_is_connected(cl)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) rets = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) cb = mei_cl_read_cb(cl, file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) if (!cb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) rets = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) copy_buffer:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) /* now copy the data to user space */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) if (cb->status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) rets = cb->status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) cl_dbg(dev, cl, "read operation failed %zd\n", rets);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) goto free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) cl_dbg(dev, cl, "buf.size = %zu buf.idx = %zu offset = %lld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) cb->buf.size, cb->buf_idx, *offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) if (*offset >= cb->buf_idx) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) rets = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) goto free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) /* length is being truncated to PAGE_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) * however buf_idx may point beyond that */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) length = min_t(size_t, length, cb->buf_idx - *offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) if (copy_to_user(ubuf, cb->buf.data + *offset, length)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) dev_dbg(dev->dev, "failed to copy data to userland\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) rets = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) goto free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) rets = length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) *offset += length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) /* not all data was read, keep the cb */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) if (*offset < cb->buf_idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) mei_cl_del_rd_completed(cl, cb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) *offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) cl_dbg(dev, cl, "end mei read rets = %zd\n", rets);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) mutex_unlock(&dev->device_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) return rets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) * mei_cl_vtag_by_fp - obtain the vtag by file pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) * @cl: host client
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) * @fp: pointer to file structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) * Return: vtag value on success, otherwise 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) static u8 mei_cl_vtag_by_fp(const struct mei_cl *cl, const struct file *fp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) struct mei_cl_vtag *cl_vtag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) if (!fp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) list_for_each_entry(cl_vtag, &cl->vtag_map, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) if (cl_vtag->fp == fp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) return cl_vtag->vtag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) * mei_write - the write function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) * @file: pointer to file structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) * @ubuf: pointer to user buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) * @length: buffer length
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) * @offset: data offset in buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) * Return: >=0 data length on success , <0 on error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) static ssize_t mei_write(struct file *file, const char __user *ubuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) size_t length, loff_t *offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) struct mei_cl *cl = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) struct mei_cl_cb *cb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) struct mei_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) ssize_t rets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) if (WARN_ON(!cl || !cl->dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) dev = cl->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) mutex_lock(&dev->device_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) if (dev->dev_state != MEI_DEV_ENABLED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) rets = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) if (!mei_cl_is_connected(cl)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) cl_err(dev, cl, "is not connected");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) rets = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) if (!mei_me_cl_is_active(cl->me_cl)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) rets = -ENOTTY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) if (length > mei_cl_mtu(cl)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) rets = -EFBIG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) if (length == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) rets = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) while (cl->tx_cb_queued >= dev->tx_queue_limit) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) if (file->f_flags & O_NONBLOCK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) rets = -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) mutex_unlock(&dev->device_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) rets = wait_event_interruptible(cl->tx_wait,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) cl->writing_state == MEI_WRITE_COMPLETE ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) (!mei_cl_is_connected(cl)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) mutex_lock(&dev->device_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) if (rets) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) if (signal_pending(current))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) rets = -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) if (!mei_cl_is_connected(cl)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) rets = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) cb = mei_cl_alloc_cb(cl, length, MEI_FOP_WRITE, file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) if (!cb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) rets = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) cb->vtag = mei_cl_vtag_by_fp(cl, file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) rets = copy_from_user(cb->buf.data, ubuf, length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) if (rets) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) dev_dbg(dev->dev, "failed to copy data from userland\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) rets = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) mei_io_cb_free(cb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) rets = mei_cl_write(cl, cb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) mutex_unlock(&dev->device_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) return rets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) * mei_ioctl_connect_client - the connect to fw client IOCTL function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) * @file: private data of the file object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) * @in_client_uuid: requested UUID for connection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) * @client: IOCTL connect data, output parameters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) * Locking: called under "dev->device_lock" lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) * Return: 0 on success, <0 on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) static int mei_ioctl_connect_client(struct file *file,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) const uuid_le *in_client_uuid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) struct mei_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) struct mei_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) struct mei_me_client *me_cl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) struct mei_cl *cl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) int rets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) cl = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) dev = cl->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) if (cl->state != MEI_FILE_INITIALIZING &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) cl->state != MEI_FILE_DISCONNECTED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) /* find ME client we're trying to connect to */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) me_cl = mei_me_cl_by_uuid(dev, in_client_uuid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) if (!me_cl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) dev_dbg(dev->dev, "Cannot connect to FW Client UUID = %pUl\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) in_client_uuid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) rets = -ENOTTY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) goto end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) if (me_cl->props.fixed_address) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) bool forbidden = dev->override_fixed_address ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) !dev->allow_fixed_address : !dev->hbm_f_fa_supported;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) if (forbidden) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) dev_dbg(dev->dev, "Connection forbidden to FW Client UUID = %pUl\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) in_client_uuid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) rets = -ENOTTY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) goto end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) dev_dbg(dev->dev, "Connect to FW Client ID = %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) me_cl->client_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) dev_dbg(dev->dev, "FW Client - Protocol Version = %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) me_cl->props.protocol_version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) dev_dbg(dev->dev, "FW Client - Max Msg Len = %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) me_cl->props.max_msg_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) /* prepare the output buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) client->max_msg_length = me_cl->props.max_msg_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) client->protocol_version = me_cl->props.protocol_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) dev_dbg(dev->dev, "Can connect?\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) rets = mei_cl_connect(cl, me_cl, file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) end:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) mei_me_cl_put(me_cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) return rets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) * mei_vt_support_check - check if client support vtags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) * Locking: called under "dev->device_lock" lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) * @dev: mei_device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) * @uuid: client UUID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) * Return:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) * 0 - supported
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) * -ENOTTY - no such client
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) * -EOPNOTSUPP - vtags are not supported by client
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) static int mei_vt_support_check(struct mei_device *dev, const uuid_le *uuid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) struct mei_me_client *me_cl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) if (!dev->hbm_f_vt_supported)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) me_cl = mei_me_cl_by_uuid(dev, uuid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) if (!me_cl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) dev_dbg(dev->dev, "Cannot connect to FW Client UUID = %pUl\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) uuid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) return -ENOTTY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) ret = me_cl->props.vt_supported ? 0 : -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) mei_me_cl_put(me_cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) * mei_ioctl_connect_vtag - connect to fw client with vtag IOCTL function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) * @file: private data of the file object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) * @in_client_uuid: requested UUID for connection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) * @client: IOCTL connect data, output parameters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) * @vtag: vm tag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) * Locking: called under "dev->device_lock" lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) * Return: 0 on success, <0 on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) static int mei_ioctl_connect_vtag(struct file *file,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) const uuid_le *in_client_uuid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) struct mei_client *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) u8 vtag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) struct mei_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) struct mei_cl *cl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) struct mei_cl *pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) struct mei_cl_vtag *cl_vtag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) cl = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) dev = cl->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) dev_dbg(dev->dev, "FW Client %pUl vtag %d\n", in_client_uuid, vtag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) switch (cl->state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) case MEI_FILE_DISCONNECTED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) if (mei_cl_vtag_by_fp(cl, file) != vtag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) dev_err(dev->dev, "reconnect with different vtag\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) case MEI_FILE_INITIALIZING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) /* malicious connect from another thread may push vtag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) if (!IS_ERR(mei_cl_fp_by_vtag(cl, vtag))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) dev_err(dev->dev, "vtag already filled\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) list_for_each_entry(pos, &dev->file_list, link) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) if (pos == cl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) if (!pos->me_cl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) /* only search for same UUID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) if (uuid_le_cmp(*mei_cl_uuid(pos), *in_client_uuid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) /* if tag already exist try another fp */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) if (!IS_ERR(mei_cl_fp_by_vtag(pos, vtag)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) /* replace cl with acquired one */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) dev_dbg(dev->dev, "replacing with existing cl\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) mei_cl_unlink(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) kfree(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) file->private_data = pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) cl = pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) cl_vtag = mei_cl_vtag_alloc(file, vtag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) if (IS_ERR(cl_vtag))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) list_add_tail(&cl_vtag->list, &cl->vtag_map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) while (cl->state != MEI_FILE_INITIALIZING &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) cl->state != MEI_FILE_DISCONNECTED &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) cl->state != MEI_FILE_CONNECTED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) mutex_unlock(&dev->device_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) wait_event_timeout(cl->wait,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) (cl->state == MEI_FILE_CONNECTED ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) cl->state == MEI_FILE_DISCONNECTED ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) cl->state == MEI_FILE_DISCONNECT_REQUIRED ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) cl->state == MEI_FILE_DISCONNECT_REPLY),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) mei_secs_to_jiffies(MEI_CL_CONNECT_TIMEOUT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) mutex_lock(&dev->device_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) if (!mei_cl_is_connected(cl))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) return mei_ioctl_connect_client(file, in_client_uuid, client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) client->max_msg_length = cl->me_cl->props.max_msg_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) client->protocol_version = cl->me_cl->props.protocol_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) * mei_ioctl_client_notify_request -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) * propagate event notification request to client
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) * @file: pointer to file structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) * @request: 0 - disable, 1 - enable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) * Return: 0 on success , <0 on error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) static int mei_ioctl_client_notify_request(const struct file *file, u32 request)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) struct mei_cl *cl = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) if (request != MEI_HBM_NOTIFICATION_START &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) request != MEI_HBM_NOTIFICATION_STOP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) return mei_cl_notify_request(cl, file, (u8)request);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) * mei_ioctl_client_notify_get - wait for notification request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) * @file: pointer to file structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) * @notify_get: 0 - disable, 1 - enable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) * Return: 0 on success , <0 on error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) static int mei_ioctl_client_notify_get(const struct file *file, u32 *notify_get)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) struct mei_cl *cl = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) bool notify_ev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) bool block = (file->f_flags & O_NONBLOCK) == 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) int rets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) rets = mei_cl_notify_get(cl, block, ¬ify_ev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) if (rets)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) return rets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) *notify_get = notify_ev ? 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) * mei_ioctl - the IOCTL function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) * @file: pointer to file structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) * @cmd: ioctl command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) * @data: pointer to mei message structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) * Return: 0 on success , <0 on error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) static long mei_ioctl(struct file *file, unsigned int cmd, unsigned long data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) struct mei_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) struct mei_cl *cl = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) struct mei_connect_client_data conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) struct mei_connect_client_data_vtag conn_vtag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) const uuid_le *cl_uuid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) struct mei_client *props;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) u8 vtag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) u32 notify_get, notify_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) int rets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) if (WARN_ON(!cl || !cl->dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) dev = cl->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) dev_dbg(dev->dev, "IOCTL cmd = 0x%x", cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) mutex_lock(&dev->device_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) if (dev->dev_state != MEI_DEV_ENABLED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) rets = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) case IOCTL_MEI_CONNECT_CLIENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) dev_dbg(dev->dev, ": IOCTL_MEI_CONNECT_CLIENT.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) if (copy_from_user(&conn, (char __user *)data, sizeof(conn))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) dev_dbg(dev->dev, "failed to copy data from userland\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) rets = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) cl_uuid = &conn.in_client_uuid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) props = &conn.out_client_properties;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) vtag = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) rets = mei_vt_support_check(dev, cl_uuid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) if (rets == -ENOTTY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) if (!rets)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) rets = mei_ioctl_connect_vtag(file, cl_uuid, props,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) vtag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) rets = mei_ioctl_connect_client(file, cl_uuid, props);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) if (rets)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) /* if all is ok, copying the data back to user. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) if (copy_to_user((char __user *)data, &conn, sizeof(conn))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) dev_dbg(dev->dev, "failed to copy data to userland\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) rets = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) case IOCTL_MEI_CONNECT_CLIENT_VTAG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) dev_dbg(dev->dev, "IOCTL_MEI_CONNECT_CLIENT_VTAG\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) if (copy_from_user(&conn_vtag, (char __user *)data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) sizeof(conn_vtag))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) dev_dbg(dev->dev, "failed to copy data from userland\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) rets = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) cl_uuid = &conn_vtag.connect.in_client_uuid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) props = &conn_vtag.out_client_properties;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) vtag = conn_vtag.connect.vtag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) rets = mei_vt_support_check(dev, cl_uuid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) if (rets == -EOPNOTSUPP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) dev_dbg(dev->dev, "FW Client %pUl does not support vtags\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) cl_uuid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) if (rets)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) if (!vtag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) dev_dbg(dev->dev, "vtag can't be zero\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) rets = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) rets = mei_ioctl_connect_vtag(file, cl_uuid, props, vtag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) if (rets)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) /* if all is ok, copying the data back to user. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) if (copy_to_user((char __user *)data, &conn_vtag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) sizeof(conn_vtag))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) dev_dbg(dev->dev, "failed to copy data to userland\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) rets = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) case IOCTL_MEI_NOTIFY_SET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) dev_dbg(dev->dev, ": IOCTL_MEI_NOTIFY_SET.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) if (copy_from_user(¬ify_req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) (char __user *)data, sizeof(notify_req))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) dev_dbg(dev->dev, "failed to copy data from userland\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) rets = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) rets = mei_ioctl_client_notify_request(file, notify_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) case IOCTL_MEI_NOTIFY_GET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) dev_dbg(dev->dev, ": IOCTL_MEI_NOTIFY_GET.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) rets = mei_ioctl_client_notify_get(file, ¬ify_get);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) if (rets)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) dev_dbg(dev->dev, "copy connect data to user\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) if (copy_to_user((char __user *)data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) ¬ify_get, sizeof(notify_get))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) dev_dbg(dev->dev, "failed to copy data to userland\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) rets = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) rets = -ENOIOCTLCMD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) mutex_unlock(&dev->device_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) return rets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) * mei_poll - the poll function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) * @file: pointer to file structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) * @wait: pointer to poll_table structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) * Return: poll mask
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) static __poll_t mei_poll(struct file *file, poll_table *wait)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) __poll_t req_events = poll_requested_events(wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) struct mei_cl *cl = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) struct mei_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) __poll_t mask = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) bool notify_en;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) if (WARN_ON(!cl || !cl->dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) return EPOLLERR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) dev = cl->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) mutex_lock(&dev->device_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) notify_en = cl->notify_en && (req_events & EPOLLPRI);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) if (dev->dev_state != MEI_DEV_ENABLED ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) !mei_cl_is_connected(cl)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) mask = EPOLLERR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) if (notify_en) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) poll_wait(file, &cl->ev_wait, wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) if (cl->notify_ev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) mask |= EPOLLPRI;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) if (req_events & (EPOLLIN | EPOLLRDNORM)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) poll_wait(file, &cl->rx_wait, wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) if (mei_cl_read_cb(cl, file))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) mask |= EPOLLIN | EPOLLRDNORM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) mei_cl_read_start(cl, mei_cl_mtu(cl), file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) if (req_events & (EPOLLOUT | EPOLLWRNORM)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) poll_wait(file, &cl->tx_wait, wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) if (cl->tx_cb_queued < dev->tx_queue_limit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) mask |= EPOLLOUT | EPOLLWRNORM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) mutex_unlock(&dev->device_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) return mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) * mei_cl_is_write_queued - check if the client has pending writes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) * @cl: writing host client
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) * Return: true if client is writing, false otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) static bool mei_cl_is_write_queued(struct mei_cl *cl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) struct mei_device *dev = cl->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) struct mei_cl_cb *cb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) list_for_each_entry(cb, &dev->write_list, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) if (cb->cl == cl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) list_for_each_entry(cb, &dev->write_waiting_list, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) if (cb->cl == cl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) * mei_fsync - the fsync handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) * @fp: pointer to file structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) * @start: unused
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) * @end: unused
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) * @datasync: unused
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) * Return: 0 on success, -ENODEV if client is not connected
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) static int mei_fsync(struct file *fp, loff_t start, loff_t end, int datasync)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) struct mei_cl *cl = fp->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) struct mei_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) int rets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) if (WARN_ON(!cl || !cl->dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) dev = cl->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) mutex_lock(&dev->device_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) if (dev->dev_state != MEI_DEV_ENABLED || !mei_cl_is_connected(cl)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) rets = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) while (mei_cl_is_write_queued(cl)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) mutex_unlock(&dev->device_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) rets = wait_event_interruptible(cl->tx_wait,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) cl->writing_state == MEI_WRITE_COMPLETE ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) !mei_cl_is_connected(cl));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) mutex_lock(&dev->device_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) if (rets) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) if (signal_pending(current))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) rets = -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) if (!mei_cl_is_connected(cl)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) rets = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) rets = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) mutex_unlock(&dev->device_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) return rets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) * mei_fasync - asynchronous io support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) * @fd: file descriptor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) * @file: pointer to file structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) * @band: band bitmap
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) * Return: negative on error,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) * 0 if it did no changes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) * and positive a process was added or deleted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) static int mei_fasync(int fd, struct file *file, int band)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) struct mei_cl *cl = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) if (!mei_cl_is_connected(cl))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) return fasync_helper(fd, file, band, &cl->ev_async);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) * trc_show - mei device trc attribute show method
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) * @device: device pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) * @attr: attribute pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) * @buf: char out buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) * Return: number of the bytes printed into buf or error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) static ssize_t trc_show(struct device *device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) struct mei_device *dev = dev_get_drvdata(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) u32 trc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) ret = mei_trc_status(dev, &trc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) return sprintf(buf, "%08X\n", trc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) static DEVICE_ATTR_RO(trc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) * fw_status_show - mei device fw_status attribute show method
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) * @device: device pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) * @attr: attribute pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) * @buf: char out buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) * Return: number of the bytes printed into buf or error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) static ssize_t fw_status_show(struct device *device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) struct mei_device *dev = dev_get_drvdata(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) struct mei_fw_status fw_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) int err, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) ssize_t cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) mutex_lock(&dev->device_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) err = mei_fw_status(dev, &fw_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) mutex_unlock(&dev->device_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) dev_err(device, "read fw_status error = %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) for (i = 0; i < fw_status.count; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) cnt += scnprintf(buf + cnt, PAGE_SIZE - cnt, "%08X\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) fw_status.status[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) return cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) static DEVICE_ATTR_RO(fw_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) * hbm_ver_show - display HBM protocol version negotiated with FW
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) * @device: device pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) * @attr: attribute pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) * @buf: char out buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) * Return: number of the bytes printed into buf or error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) static ssize_t hbm_ver_show(struct device *device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) struct mei_device *dev = dev_get_drvdata(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) struct hbm_version ver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) mutex_lock(&dev->device_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) ver = dev->version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) mutex_unlock(&dev->device_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) return sprintf(buf, "%u.%u\n", ver.major_version, ver.minor_version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) static DEVICE_ATTR_RO(hbm_ver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) * hbm_ver_drv_show - display HBM protocol version advertised by driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) * @device: device pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) * @attr: attribute pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) * @buf: char out buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) * Return: number of the bytes printed into buf or error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) static ssize_t hbm_ver_drv_show(struct device *device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) return sprintf(buf, "%u.%u\n", HBM_MAJOR_VERSION, HBM_MINOR_VERSION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) static DEVICE_ATTR_RO(hbm_ver_drv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) static ssize_t tx_queue_limit_show(struct device *device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) struct mei_device *dev = dev_get_drvdata(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) u8 size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) mutex_lock(&dev->device_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) size = dev->tx_queue_limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) mutex_unlock(&dev->device_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) return snprintf(buf, PAGE_SIZE, "%u\n", size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) static ssize_t tx_queue_limit_store(struct device *device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) struct mei_device *dev = dev_get_drvdata(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) u8 limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) unsigned int inp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) err = kstrtouint(buf, 10, &inp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) if (inp > MEI_TX_QUEUE_LIMIT_MAX || inp < MEI_TX_QUEUE_LIMIT_MIN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) limit = inp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) mutex_lock(&dev->device_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) dev->tx_queue_limit = limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) mutex_unlock(&dev->device_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) static DEVICE_ATTR_RW(tx_queue_limit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) * fw_ver_show - display ME FW version
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) * @device: device pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) * @attr: attribute pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) * @buf: char out buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) * Return: number of the bytes printed into buf or error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) static ssize_t fw_ver_show(struct device *device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) struct mei_device *dev = dev_get_drvdata(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) struct mei_fw_version *ver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) ssize_t cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) ver = dev->fw_ver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) for (i = 0; i < MEI_MAX_FW_VER_BLOCKS; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) cnt += scnprintf(buf + cnt, PAGE_SIZE - cnt, "%u:%u.%u.%u.%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) ver[i].platform, ver[i].major, ver[i].minor,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) ver[i].hotfix, ver[i].buildno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) return cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) static DEVICE_ATTR_RO(fw_ver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) * dev_state_show - display device state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) * @device: device pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) * @attr: attribute pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) * @buf: char out buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) * Return: number of the bytes printed into buf or error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) static ssize_t dev_state_show(struct device *device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) struct mei_device *dev = dev_get_drvdata(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) enum mei_dev_state dev_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) mutex_lock(&dev->device_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) dev_state = dev->dev_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) mutex_unlock(&dev->device_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) return sprintf(buf, "%s", mei_dev_state_str(dev_state));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) static DEVICE_ATTR_RO(dev_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) * dev_set_devstate: set to new device state and notify sysfs file.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) * @dev: mei_device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) * @state: new device state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) void mei_set_devstate(struct mei_device *dev, enum mei_dev_state state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) struct device *clsdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) if (dev->dev_state == state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) dev->dev_state = state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) clsdev = class_find_device_by_devt(mei_class, dev->cdev.dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) if (clsdev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) sysfs_notify(&clsdev->kobj, NULL, "dev_state");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) put_device(clsdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) * kind_show - display device kind
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) * @device: device pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) * @attr: attribute pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) * @buf: char out buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) * Return: number of the bytes printed into buf or error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) static ssize_t kind_show(struct device *device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) struct mei_device *dev = dev_get_drvdata(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) ssize_t ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) if (dev->kind)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) ret = sprintf(buf, "%s\n", dev->kind);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) ret = sprintf(buf, "%s\n", "mei");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) static DEVICE_ATTR_RO(kind);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) static struct attribute *mei_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) &dev_attr_fw_status.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) &dev_attr_hbm_ver.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) &dev_attr_hbm_ver_drv.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) &dev_attr_tx_queue_limit.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) &dev_attr_fw_ver.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) &dev_attr_dev_state.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) &dev_attr_trc.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) &dev_attr_kind.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) ATTRIBUTE_GROUPS(mei);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) * file operations structure will be used for mei char device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) static const struct file_operations mei_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) .read = mei_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) .unlocked_ioctl = mei_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) .compat_ioctl = compat_ptr_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) .open = mei_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) .release = mei_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) .write = mei_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) .poll = mei_poll,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) .fsync = mei_fsync,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) .fasync = mei_fasync,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) .llseek = no_llseek
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) * mei_minor_get - obtain next free device minor number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) * @dev: device pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) * Return: allocated minor, or -ENOSPC if no free minor left
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) static int mei_minor_get(struct mei_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) mutex_lock(&mei_minor_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) ret = idr_alloc(&mei_idr, dev, 0, MEI_MAX_DEVS, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) if (ret >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) dev->minor = ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) else if (ret == -ENOSPC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) dev_err(dev->dev, "too many mei devices\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) mutex_unlock(&mei_minor_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) * mei_minor_free - mark device minor number as free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) * @dev: device pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) static void mei_minor_free(struct mei_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) mutex_lock(&mei_minor_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) idr_remove(&mei_idr, dev->minor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) mutex_unlock(&mei_minor_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) int mei_register(struct mei_device *dev, struct device *parent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) struct device *clsdev; /* class device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) int ret, devno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) ret = mei_minor_get(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) /* Fill in the data structures */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) devno = MKDEV(MAJOR(mei_devt), dev->minor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) cdev_init(&dev->cdev, &mei_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) dev->cdev.owner = parent->driver->owner;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) /* Add the device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) ret = cdev_add(&dev->cdev, devno, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) dev_err(parent, "unable to add device %d:%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) MAJOR(mei_devt), dev->minor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) goto err_dev_add;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) clsdev = device_create_with_groups(mei_class, parent, devno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) dev, mei_groups,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) "mei%d", dev->minor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) if (IS_ERR(clsdev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) dev_err(parent, "unable to create device %d:%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) MAJOR(mei_devt), dev->minor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) ret = PTR_ERR(clsdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) goto err_dev_create;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) mei_dbgfs_register(dev, dev_name(clsdev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) err_dev_create:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) cdev_del(&dev->cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) err_dev_add:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) mei_minor_free(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) EXPORT_SYMBOL_GPL(mei_register);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) void mei_deregister(struct mei_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) int devno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) devno = dev->cdev.dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) cdev_del(&dev->cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) mei_dbgfs_deregister(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) device_destroy(mei_class, devno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) mei_minor_free(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) EXPORT_SYMBOL_GPL(mei_deregister);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) static int __init mei_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) mei_class = class_create(THIS_MODULE, "mei");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) if (IS_ERR(mei_class)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) pr_err("couldn't create class\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) ret = PTR_ERR(mei_class);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) ret = alloc_chrdev_region(&mei_devt, 0, MEI_MAX_DEVS, "mei");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) pr_err("unable to allocate char dev region\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) goto err_class;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) ret = mei_cl_bus_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) pr_err("unable to initialize bus\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) goto err_chrdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) err_chrdev:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) unregister_chrdev_region(mei_devt, MEI_MAX_DEVS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) err_class:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) class_destroy(mei_class);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) static void __exit mei_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) unregister_chrdev_region(mei_devt, MEI_MAX_DEVS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) class_destroy(mei_class);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) mei_cl_bus_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) module_init(mei_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) module_exit(mei_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) MODULE_AUTHOR("Intel Corporation");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) MODULE_DESCRIPTION("Intel(R) Management Engine Interface");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) MODULE_LICENSE("GPL v2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322)