4 * Userspace interface for accessing the
5 * Access Control Lists / Control File Data Channel
7 * Copyright IBM Corporation 2008
10 #include <linux/types.h>
11 #include <linux/miscdevice.h>
12 #include <asm/ccwdev.h>
17 #define ZFCP_CFDC_CMND_DOWNLOAD_NORMAL 0x00010001
18 #define ZFCP_CFDC_CMND_DOWNLOAD_FORCE 0x00010101
19 #define ZFCP_CFDC_CMND_FULL_ACCESS 0x00000201
20 #define ZFCP_CFDC_CMND_RESTRICTED_ACCESS 0x00000401
21 #define ZFCP_CFDC_CMND_UPLOAD 0x00010002
23 #define ZFCP_CFDC_DOWNLOAD 0x00000001
24 #define ZFCP_CFDC_UPLOAD 0x00000002
25 #define ZFCP_CFDC_WITH_CONTROL_FILE 0x00010000
27 #define ZFCP_CFDC_IOC_MAGIC 0xDD
28 #define ZFCP_CFDC_IOC \
29 _IOWR(ZFCP_CFDC_IOC_MAGIC, 0, struct zfcp_cfdc_data)
32 * struct zfcp_cfdc_data - data for ioctl cfdc interface
33 * @signature: request signature
34 * @devno: FCP adapter device number
35 * @command: command code
36 * @fsf_status: returns status of FSF command to userspace
37 * @fsf_status_qual: returned to userspace
38 * @payloads: access conflicts list
39 * @control_file: access control table
41 struct zfcp_cfdc_data {
46 u8 fsf_status_qual[FSF_STATUS_QUALIFIER_SIZE];
51 static int zfcp_cfdc_copy_from_user(struct scatterlist *sg,
52 void __user *user_buffer)
55 unsigned int size = ZFCP_CFDC_MAX_SIZE;
58 length = min((unsigned int)size, sg->length);
59 if (copy_from_user(sg_virt(sg++), user_buffer, length))
61 user_buffer += length;
67 static int zfcp_cfdc_copy_to_user(void __user *user_buffer,
68 struct scatterlist *sg)
71 unsigned int size = ZFCP_CFDC_MAX_SIZE;
74 length = min((unsigned int) size, sg->length);
75 if (copy_to_user(user_buffer, sg_virt(sg++), length))
77 user_buffer += length;
83 static struct zfcp_adapter *zfcp_cfdc_get_adapter(u32 devno)
85 struct zfcp_adapter *adapter = NULL, *cur_adapter;
86 struct ccw_dev_id dev_id;
88 read_lock_irq(&zfcp_data.config_lock);
89 list_for_each_entry(cur_adapter, &zfcp_data.adapter_list_head, list) {
90 ccw_device_get_id(cur_adapter->ccw_device, &dev_id);
91 if (dev_id.devno == devno) {
92 adapter = cur_adapter;
93 zfcp_adapter_get(adapter);
97 read_unlock_irq(&zfcp_data.config_lock);
101 static int zfcp_cfdc_set_fsf(struct zfcp_fsf_cfdc *fsf_cfdc, int command)
104 case ZFCP_CFDC_CMND_DOWNLOAD_NORMAL:
105 fsf_cfdc->command = FSF_QTCB_DOWNLOAD_CONTROL_FILE;
106 fsf_cfdc->option = FSF_CFDC_OPTION_NORMAL_MODE;
108 case ZFCP_CFDC_CMND_DOWNLOAD_FORCE:
109 fsf_cfdc->command = FSF_QTCB_DOWNLOAD_CONTROL_FILE;
110 fsf_cfdc->option = FSF_CFDC_OPTION_FORCE;
112 case ZFCP_CFDC_CMND_FULL_ACCESS:
113 fsf_cfdc->command = FSF_QTCB_DOWNLOAD_CONTROL_FILE;
114 fsf_cfdc->option = FSF_CFDC_OPTION_FULL_ACCESS;
116 case ZFCP_CFDC_CMND_RESTRICTED_ACCESS:
117 fsf_cfdc->command = FSF_QTCB_DOWNLOAD_CONTROL_FILE;
118 fsf_cfdc->option = FSF_CFDC_OPTION_RESTRICTED_ACCESS;
120 case ZFCP_CFDC_CMND_UPLOAD:
121 fsf_cfdc->command = FSF_QTCB_UPLOAD_CONTROL_FILE;
122 fsf_cfdc->option = 0;
131 static int zfcp_cfdc_sg_setup(int command, struct scatterlist *sg,
132 u8 __user *control_file)
135 retval = zfcp_sg_setup_table(sg, ZFCP_CFDC_PAGES);
139 sg[ZFCP_CFDC_PAGES - 1].length = ZFCP_CFDC_MAX_SIZE % PAGE_SIZE;
141 if (command & ZFCP_CFDC_WITH_CONTROL_FILE &&
142 command & ZFCP_CFDC_DOWNLOAD) {
143 retval = zfcp_cfdc_copy_from_user(sg, control_file);
145 zfcp_sg_free_table(sg, ZFCP_CFDC_PAGES);
153 static void zfcp_cfdc_req_to_sense(struct zfcp_cfdc_data *data,
154 struct zfcp_fsf_req *req)
156 data->fsf_status = req->qtcb->header.fsf_status;
157 memcpy(&data->fsf_status_qual, &req->qtcb->header.fsf_status_qual,
158 sizeof(union fsf_status_qual));
159 memcpy(&data->payloads, &req->qtcb->bottom.support.els,
160 sizeof(req->qtcb->bottom.support.els));
163 static long zfcp_cfdc_dev_ioctl(struct file *file, unsigned int command,
164 unsigned long buffer)
166 struct zfcp_cfdc_data *data;
167 struct zfcp_cfdc_data __user *data_user;
168 struct zfcp_adapter *adapter;
169 struct zfcp_fsf_req *req;
170 struct zfcp_fsf_cfdc *fsf_cfdc;
173 if (command != ZFCP_CFDC_IOC)
176 data_user = (void __user *) buffer;
180 fsf_cfdc = kmalloc(sizeof(struct zfcp_fsf_cfdc), GFP_KERNEL);
184 data = kmalloc(sizeof(struct zfcp_cfdc_data), GFP_KERNEL);
190 retval = copy_from_user(data, data_user, sizeof(*data));
196 if (data->signature != 0xCFDCACDF) {
201 retval = zfcp_cfdc_set_fsf(fsf_cfdc, data->command);
203 adapter = zfcp_cfdc_get_adapter(data->devno);
209 retval = zfcp_cfdc_sg_setup(data->command, fsf_cfdc->sg,
210 data_user->control_file);
213 req = zfcp_fsf_control_file(adapter, fsf_cfdc);
215 retval = PTR_ERR(req);
219 if (req->status & ZFCP_STATUS_FSFREQ_ERROR) {
224 zfcp_cfdc_req_to_sense(data, req);
225 retval = copy_to_user(data_user, data, sizeof(*data_user));
231 if (data->command & ZFCP_CFDC_UPLOAD)
232 retval = zfcp_cfdc_copy_to_user(&data_user->control_file,
236 zfcp_fsf_req_free(req);
238 zfcp_sg_free_table(fsf_cfdc->sg, ZFCP_CFDC_PAGES);
240 zfcp_adapter_put(adapter);
248 static const struct file_operations zfcp_cfdc_fops = {
249 .unlocked_ioctl = zfcp_cfdc_dev_ioctl,
251 .compat_ioctl = zfcp_cfdc_dev_ioctl
255 struct miscdevice zfcp_cfdc_misc = {
256 .minor = MISC_DYNAMIC_MINOR,
258 .fops = &zfcp_cfdc_fops,