Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * IBM ASM Service Processor Device Driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) IBM Corporation, 2004
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Author: Max Asböck <amax@us.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * Parts of this code are based on an article by Jonathan Corbet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  * that appeared in Linux Weekly News.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  * The IBMASM file virtual filesystem. It creates the following hierarchy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  * dynamically when mounted from user space:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  *    /ibmasm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  *    |-- 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  *    |   |-- command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  *    |   |-- event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  *    |   |-- reverse_heartbeat
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  *    |   `-- remote_video
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  *    |       |-- depth
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  *    |       |-- height
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  *    |       `-- width
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  *    .
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  *    .
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  *    .
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)  *    `-- n
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  *        |-- command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  *        |-- event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  *        |-- reverse_heartbeat
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)  *        `-- remote_video
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)  *            |-- depth
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)  *            |-- height
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)  *            `-- width
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41)  * For each service processor the following files are created:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43)  * command: execute dot commands
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44)  *	write: execute a dot command on the service processor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45)  *	read: return the result of a previously executed dot command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47)  * events: listen for service processor events
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)  *	read: sleep (interruptible) until an event occurs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49)  *      write: wakeup sleeping event listener
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51)  * reverse_heartbeat: send a heartbeat to the service processor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52)  *	read: sleep (interruptible) until the reverse heartbeat fails
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53)  *      write: wakeup sleeping heartbeat listener
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55)  * remote_video/width
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56)  * remote_video/height
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57)  * remote_video/width: control remote display settings
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58)  *	write: set value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59)  *	read: read value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) #include <linux/fs_context.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) #include <linux/pagemap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) #include <asm/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) #include "ibmasm.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) #include "remote.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) #include "dot_command.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) #define IBMASMFS_MAGIC 0x66726f67
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) static LIST_HEAD(service_processors);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) static struct inode *ibmasmfs_make_inode(struct super_block *sb, int mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) static void ibmasmfs_create_files (struct super_block *sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) static int ibmasmfs_fill_super(struct super_block *sb, struct fs_context *fc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) static int ibmasmfs_get_tree(struct fs_context *fc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	return get_tree_single(fc, ibmasmfs_fill_super);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) static const struct fs_context_operations ibmasmfs_context_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	.get_tree	= ibmasmfs_get_tree,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) static int ibmasmfs_init_fs_context(struct fs_context *fc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	fc->ops = &ibmasmfs_context_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) static const struct super_operations ibmasmfs_s_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	.statfs		= simple_statfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	.drop_inode	= generic_delete_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) static const struct file_operations *ibmasmfs_dir_ops = &simple_dir_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) static struct file_system_type ibmasmfs_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	.owner          = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	.name           = "ibmasmfs",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	.init_fs_context = ibmasmfs_init_fs_context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	.kill_sb        = kill_litter_super,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) MODULE_ALIAS_FS("ibmasmfs");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) static int ibmasmfs_fill_super(struct super_block *sb, struct fs_context *fc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	struct inode *root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	sb->s_blocksize = PAGE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	sb->s_blocksize_bits = PAGE_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	sb->s_magic = IBMASMFS_MAGIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	sb->s_op = &ibmasmfs_s_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	sb->s_time_gran = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	root = ibmasmfs_make_inode (sb, S_IFDIR | 0500);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	if (!root)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	root->i_op = &simple_dir_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	root->i_fop = ibmasmfs_dir_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	sb->s_root = d_make_root(root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	if (!sb->s_root)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	ibmasmfs_create_files(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) static struct inode *ibmasmfs_make_inode(struct super_block *sb, int mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	struct inode *ret = new_inode(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		ret->i_ino = get_next_ino();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		ret->i_mode = mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		ret->i_atime = ret->i_mtime = ret->i_ctime = current_time(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) static struct dentry *ibmasmfs_create_file(struct dentry *parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 			const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 			const struct file_operations *fops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 			void *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 			int mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	struct dentry *dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	dentry = d_alloc_name(parent, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	if (!dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	inode = ibmasmfs_make_inode(parent->d_sb, S_IFREG | mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	if (!inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		dput(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	inode->i_fop = fops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	inode->i_private = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	d_add(dentry, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	return dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) static struct dentry *ibmasmfs_create_dir(struct dentry *parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 				const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	struct dentry *dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	dentry = d_alloc_name(parent, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	if (!dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	inode = ibmasmfs_make_inode(parent->d_sb, S_IFDIR | 0500);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	if (!inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		dput(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	inode->i_op = &simple_dir_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	inode->i_fop = ibmasmfs_dir_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	d_add(dentry, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	return dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) int ibmasmfs_register(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	return register_filesystem(&ibmasmfs_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) void ibmasmfs_unregister(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	unregister_filesystem(&ibmasmfs_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) void ibmasmfs_add_sp(struct service_processor *sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	list_add(&sp->node, &service_processors);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) /* struct to save state between command file operations */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) struct ibmasmfs_command_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	struct service_processor	*sp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	struct command			*command;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) /* struct to save state between event file operations */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) struct ibmasmfs_event_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	struct service_processor	*sp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	struct event_reader		reader;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	int				active;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) /* struct to save state between reverse heartbeat file operations */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) struct ibmasmfs_heartbeat_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	struct service_processor	*sp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	struct reverse_heartbeat	heartbeat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	int				active;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) static int command_file_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	struct ibmasmfs_command_data *command_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	if (!inode->i_private)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	command_data = kmalloc(sizeof(struct ibmasmfs_command_data), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	if (!command_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	command_data->command = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	command_data->sp = inode->i_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	file->private_data = command_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) static int command_file_close(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	struct ibmasmfs_command_data *command_data = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	if (command_data->command)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 		command_put(command_data->command);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	kfree(command_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) static ssize_t command_file_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	struct ibmasmfs_command_data *command_data = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	struct command *cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	if (*offset < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	if (count == 0 || count > IBMASM_CMD_MAX_BUFFER_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	if (*offset != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	spin_lock_irqsave(&command_data->sp->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	cmd = command_data->command;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	if (cmd == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 		spin_unlock_irqrestore(&command_data->sp->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	command_data->command = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	spin_unlock_irqrestore(&command_data->sp->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	if (cmd->status != IBMASM_CMD_COMPLETE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 		command_put(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	len = min(count, cmd->buffer_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	if (copy_to_user(buf, cmd->buffer, len)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 		command_put(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	command_put(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) static ssize_t command_file_write(struct file *file, const char __user *ubuff, size_t count, loff_t *offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	struct ibmasmfs_command_data *command_data = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	struct command *cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	if (*offset < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	if (count == 0 || count > IBMASM_CMD_MAX_BUFFER_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	if (*offset != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	/* commands are executed sequentially, only one command at a time */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	if (command_data->command)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 		return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	cmd = ibmasm_new_command(command_data->sp, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	if (!cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	if (copy_from_user(cmd->buffer, ubuff, count)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 		command_put(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	spin_lock_irqsave(&command_data->sp->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	if (command_data->command) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 		spin_unlock_irqrestore(&command_data->sp->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 		command_put(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 		return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	command_data->command = cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	spin_unlock_irqrestore(&command_data->sp->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	ibmasm_exec_command(command_data->sp, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	ibmasm_wait_for_response(cmd, get_dot_command_timeout(cmd->buffer));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	return count;
^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) static int event_file_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	struct ibmasmfs_event_data *event_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	struct service_processor *sp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	if (!inode->i_private)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	sp = inode->i_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	event_data = kmalloc(sizeof(struct ibmasmfs_event_data), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	if (!event_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	ibmasm_event_reader_register(sp, &event_data->reader);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	event_data->sp = sp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	event_data->active = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	file->private_data = event_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) static int event_file_close(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	struct ibmasmfs_event_data *event_data = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	ibmasm_event_reader_unregister(event_data->sp, &event_data->reader);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	kfree(event_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) static ssize_t event_file_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	struct ibmasmfs_event_data *event_data = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	struct event_reader *reader = &event_data->reader;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	struct service_processor *sp = event_data->sp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	if (*offset < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	if (count == 0 || count > IBMASM_EVENT_MAX_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	if (*offset != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	spin_lock_irqsave(&sp->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	if (event_data->active) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 		spin_unlock_irqrestore(&sp->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	event_data->active = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	spin_unlock_irqrestore(&sp->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	ret = ibmasm_get_next_event(sp, reader);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	if (ret <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	if (count < reader->data_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 		ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400)         if (copy_to_user(buf, reader->data, reader->data_size)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 		ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	ret = reader->data_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	event_data->active = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) static ssize_t event_file_write(struct file *file, const char __user *buf, size_t count, loff_t *offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	struct ibmasmfs_event_data *event_data = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	if (*offset < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	if (count != 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	if (*offset != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 	ibmasm_cancel_next_event(&event_data->reader);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) static int r_heartbeat_file_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	struct ibmasmfs_heartbeat_data *rhbeat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	if (!inode->i_private)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	rhbeat = kmalloc(sizeof(struct ibmasmfs_heartbeat_data), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	if (!rhbeat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	rhbeat->sp = inode->i_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	rhbeat->active = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	ibmasm_init_reverse_heartbeat(rhbeat->sp, &rhbeat->heartbeat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	file->private_data = rhbeat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) static int r_heartbeat_file_close(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	struct ibmasmfs_heartbeat_data *rhbeat = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	kfree(rhbeat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) static ssize_t r_heartbeat_file_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	struct ibmasmfs_heartbeat_data *rhbeat = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	if (*offset < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	if (count == 0 || count > 1024)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	if (*offset != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 	/* allow only one reverse heartbeat per process */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	spin_lock_irqsave(&rhbeat->sp->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	if (rhbeat->active) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 		spin_unlock_irqrestore(&rhbeat->sp->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 	rhbeat->active = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	spin_unlock_irqrestore(&rhbeat->sp->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 	result = ibmasm_start_reverse_heartbeat(rhbeat->sp, &rhbeat->heartbeat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 	rhbeat->active = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 	return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) static ssize_t r_heartbeat_file_write(struct file *file, const char __user *buf, size_t count, loff_t *offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 	struct ibmasmfs_heartbeat_data *rhbeat = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	if (*offset < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 	if (count != 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 	if (*offset != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 	if (rhbeat->active)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 		ibmasm_stop_reverse_heartbeat(&rhbeat->heartbeat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) static int remote_settings_file_close(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) static ssize_t remote_settings_file_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 	void __iomem *address = (void __iomem *)file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 	int len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 	unsigned int value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 	char lbuf[20];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 	value = readl(address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 	len = snprintf(lbuf, sizeof(lbuf), "%d\n", value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 	return simple_read_from_buffer(buf, count, offset, lbuf, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) static ssize_t remote_settings_file_write(struct file *file, const char __user *ubuff, size_t count, loff_t *offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 	void __iomem *address = (void __iomem *)file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 	char *buff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 	unsigned int value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 	if (*offset < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 	if (count == 0 || count > 1024)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 	if (*offset != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 	buff = kzalloc (count + 1, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 	if (!buff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 	if (copy_from_user(buff, ubuff, count)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 		kfree(buff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 	value = simple_strtoul(buff, NULL, 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 	writel(value, address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 	kfree(buff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) static const struct file_operations command_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 	.open =		command_file_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 	.release =	command_file_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 	.read =		command_file_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 	.write =	command_file_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 	.llseek =	generic_file_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) static const struct file_operations event_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 	.open =		event_file_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 	.release =	event_file_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 	.read =		event_file_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 	.write =	event_file_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 	.llseek =	generic_file_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) static const struct file_operations r_heartbeat_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 	.open =		r_heartbeat_file_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 	.release =	r_heartbeat_file_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 	.read =		r_heartbeat_file_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 	.write =	r_heartbeat_file_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 	.llseek =	generic_file_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) static const struct file_operations remote_settings_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 	.open =		simple_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 	.release =	remote_settings_file_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 	.read =		remote_settings_file_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 	.write =	remote_settings_file_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 	.llseek =	generic_file_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) static void ibmasmfs_create_files (struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 	struct list_head *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 	struct service_processor *sp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 	list_for_each(entry, &service_processors) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 		struct dentry *dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 		struct dentry *remote_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 		sp = list_entry(entry, struct service_processor, node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 		dir = ibmasmfs_create_dir(sb->s_root, sp->dirname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 		if (!dir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 		ibmasmfs_create_file(dir, "command", &command_fops, sp, S_IRUSR|S_IWUSR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 		ibmasmfs_create_file(dir, "event", &event_fops, sp, S_IRUSR|S_IWUSR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 		ibmasmfs_create_file(dir, "reverse_heartbeat", &r_heartbeat_fops, sp, S_IRUSR|S_IWUSR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 		remote_dir = ibmasmfs_create_dir(dir, "remote_video");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 		if (!remote_dir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 		ibmasmfs_create_file(remote_dir, "width", &remote_settings_fops, (void *)display_width(sp), S_IRUSR|S_IWUSR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 		ibmasmfs_create_file(remote_dir, "height", &remote_settings_fops, (void *)display_height(sp), S_IRUSR|S_IWUSR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 		ibmasmfs_create_file(remote_dir, "depth", &remote_settings_fops, (void *)display_depth(sp), S_IRUSR|S_IWUSR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) }