26 #define KMSG_COMPONENT "cio"
27 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
30 #include <linux/device.h>
32 #include <linux/list.h>
33 #include <linux/module.h>
35 #include <linux/slab.h>
36 #include <linux/timex.h>
41 #include <asm/div64.h>
57 #define ARGSTRING "s390cmf"
125 void *(*align) (
void *);
145 return ((
u64)value) * 128000ull;
163 ret = time_to_nsec(value);
175 static inline void cmf_activate(
void *area,
unsigned int onoff)
177 register void * __gpr2
asm(
"2");
178 register long __gpr1
asm(
"1");
181 __gpr1 = onoff ? 2 : 0;
183 asm(
"schm" : :
"d" (__gpr2),
"d" (__gpr1) );
213 static void cmf_set_schib_release(
struct kref *
kref)
221 #define CMF_PENDING 1
224 int mbfc,
unsigned long address)
240 kref_init(&set_data->
kref);
245 ret = set_schib(cdev, mme, mbfc, address);
257 cdev->
private->cmb_wait = set_data;
259 spin_unlock_irq(cdev->
ccwlock);
268 spin_unlock_irq(cdev->
ccwlock);
274 kref_put(&set_data->
kref, cmf_set_schib_release);
276 spin_unlock_irq(cdev->
ccwlock);
284 set_data = cdev->
private->cmb_wait;
289 kref_get(&set_data->
kref);
290 set_data->
ret = set_schib(cdev, set_data->
mme, set_data->
mbfc,
293 kref_put(&set_data->
kref, cmf_set_schib_release);
296 static int cmf_copy_block(
struct ccw_device *cdev)
311 (scsw_actl(&sch->
schib.scsw) &
327 memcpy(reference_buf, hw_block, cmb_data->
size);
330 kfree(reference_buf);
340 static void cmf_copy_block_release(
struct kref *
kref)
348 static int cmf_cmb_copy_wait(
struct ccw_device *cdev)
365 kref_init(©_block->
kref);
367 ret = cmf_copy_block(cdev);
378 cdev->
private->cmb_wait = copy_block;
380 spin_unlock_irqrestore(cdev->
ccwlock, flags);
389 spin_unlock_irqrestore(cdev->
ccwlock, flags);
393 ret = copy_block->
ret;
395 kref_put(©_block->
kref, cmf_copy_block_release);
397 spin_unlock_irqrestore(cdev->
ccwlock, flags);
405 copy_block = cdev->
private->cmb_wait;
410 kref_get(©_block->
kref);
411 copy_block->
ret = cmf_copy_block(cdev);
413 kref_put(©_block->
kref, cmf_copy_block_release);
416 static void cmf_generic_reset(
struct ccw_device *cdev)
418 struct cmb_data *cmb_data;
432 spin_unlock_irq(cdev->
ccwlock);
453 .num_channels = 1024,
503 static int alloc_cmb_single(
struct ccw_device *cdev,
504 struct cmb_data *cmb_data)
511 if (!list_empty(&cdev->
private->cmb_list)) {
523 struct cmb_data *
data;
525 if ((
struct cmb*)data->
hw_block > cmb)
540 spin_unlock_irq(cdev->
ccwlock);
549 struct cmb_data *cmb_data;
552 cmb_data = kzalloc(
sizeof(
struct cmb_data),
GFP_KERNEL);
561 cmb_data->
size =
sizeof(
struct cmb);
562 spin_lock(&cmb_area.
lock);
569 spin_unlock(&cmb_area.
lock);
572 spin_lock(&cmb_area.
lock);
585 cmf_activate(cmb_area.
mem, 1);
590 ret = alloc_cmb_single(cdev, cmb_data);
592 spin_unlock(&cmb_area.
lock);
603 struct cmb_data *cmb_data;
605 spin_lock(&cmb_area.
lock);
615 cmb_data = priv->
cmb;
622 if (list_empty(&cmb_area.
list)) {
625 cmf_activate(
NULL, 0);
630 spin_unlock_irq(cdev->
ccwlock);
631 spin_unlock(&cmb_area.
lock);
637 struct cmb_data *cmb_data;
642 spin_unlock_irqrestore(cdev->
ccwlock, flags);
646 offset = mme ? (
struct cmb *)cmb_data->
hw_block - cmb_area.
mem : 0;
647 spin_unlock_irqrestore(cdev->
ccwlock, flags);
649 return set_schib_wait(cdev, mme, 0, offset);
659 ret = cmf_cmb_copy_wait(cdev);
668 cmb = ((
struct cmb_data *)cdev->
private->cmb)->last_block;
698 spin_unlock_irqrestore(cdev->
ccwlock, flags);
705 struct cmb_data *cmb_data;
710 ret = cmf_cmb_copy_wait(cdev);
749 spin_unlock_irqrestore(cdev->
ccwlock, flags);
753 static void reset_cmb(
struct ccw_device *cdev)
755 cmf_generic_reset(cdev);
758 static void * align_cmb(
void *area)
770 .readall = readall_cmb,
773 .attr_group = &cmf_attr_group,
814 static inline struct cmbe *cmbe_align(
struct cmbe *
c)
817 addr = ((
unsigned long)c +
sizeof (
struct cmbe) -
sizeof(
long)) &
818 ~(
sizeof (
struct cmbe) - sizeof(long));
822 static int alloc_cmbe(
struct ccw_device *cdev)
825 struct cmb_data *cmb_data;
828 cmbe = kzalloc (
sizeof (*cmbe) * 2,
GFP_KERNEL);
831 cmb_data = kzalloc(
sizeof(
struct cmb_data),
GFP_KERNEL);
841 cmb_data->
size =
sizeof(
struct cmbe);
844 spin_unlock_irq(cdev->
ccwlock);
850 spin_unlock_irq(cdev->
ccwlock);
853 spin_lock(&cmb_area.
lock);
854 if (list_empty(&cmb_area.
list))
855 cmf_activate(
NULL, 1);
857 spin_unlock(&cmb_area.
lock);
868 static void free_cmbe(
struct ccw_device *cdev)
870 struct cmb_data *cmb_data;
878 spin_unlock_irq(cdev->
ccwlock);
881 spin_lock(&cmb_area.
lock);
882 list_del_init(&cdev->
private->cmb_list);
883 if (list_empty(&cmb_area.
list))
884 cmf_activate(
NULL, 0);
885 spin_unlock(&cmb_area.
lock);
891 struct cmb_data *cmb_data;
896 spin_unlock_irqrestore(cdev->
ccwlock, flags);
900 mba = mme ? (
unsigned long) cmbe_align(cmb_data->
hw_block) : 0;
901 spin_unlock_irqrestore(cdev->
ccwlock, flags);
903 return set_schib_wait(cdev, mme, 1, mba);
910 struct cmb_data *cmb_data;
915 ret = cmf_cmb_copy_wait(cdev);
961 spin_unlock_irqrestore(cdev->
ccwlock, flags);
968 struct cmb_data *cmb_data;
973 ret = cmf_cmb_copy_wait(cdev);
1016 spin_unlock_irqrestore(cdev->
ccwlock, flags);
1020 static void reset_cmbe(
struct ccw_device *cdev)
1022 cmf_generic_reset(cdev);
1025 static void * align_cmbe(
void *area)
1027 return cmbe_align(area);
1033 .alloc = alloc_cmbe,
1037 .readall = readall_cmbe,
1038 .reset = reset_cmbe,
1039 .align = align_cmbe,
1040 .attr_group = &cmf_attr_group_ext,
1049 static ssize_t cmb_show_avg_sample_interval(
struct device *dev,
1055 unsigned long count;
1056 struct cmb_data *cmb_data;
1061 cmb_data = cdev->
private->cmb;
1064 cdev->
private->cmb_start_time;
1065 interval = (interval * 1000) >> 12;
1069 spin_unlock_irq(cdev->
ccwlock);
1070 return sprintf(buf,
"%ld\n", interval);
1101 u = (
unsigned long) utilization /
t;
1103 return sprintf(buf,
"%02ld.%01ld%%\n", u/ 10, u - (u/ 10) * 10);
1106 #define cmf_attr(name) \
1107 static ssize_t show_##name(struct device *dev, \
1108 struct device_attribute *attr, char *buf) \
1109 { return cmb_show_attr((dev), buf, cmb_##name); } \
1110 static DEVICE_ATTR(name, 0444, show_##name, NULL);
1112 #define cmf_attr_avg(name) \
1113 static ssize_t show_avg_##name(struct device *dev, \
1114 struct device_attribute *attr, char *buf) \
1115 { return cmb_show_attr((dev), buf, cmb_##name); } \
1116 static DEVICE_ATTR(avg_##name, 0444, show_avg_##name, NULL);
1128 static DEVICE_ATTR(avg_sample_interval, 0444, cmb_show_avg_sample_interval,
1130 static DEVICE_ATTR(avg_utilization, 0444, cmb_show_avg_utilization,
NULL);
1132 static struct attribute *cmf_attributes[] = {
1133 &dev_attr_avg_sample_interval.attr,
1134 &dev_attr_avg_utilization.attr,
1135 &dev_attr_ssch_rsch_count.attr,
1136 &dev_attr_sample_count.attr,
1137 &dev_attr_avg_device_connect_time.attr,
1138 &dev_attr_avg_function_pending_time.attr,
1139 &dev_attr_avg_device_disconnect_time.attr,
1140 &dev_attr_avg_control_unit_queuing_time.attr,
1141 &dev_attr_avg_device_active_only_time.attr,
1147 .attrs = cmf_attributes,
1150 static struct attribute *cmf_attributes_ext[] = {
1151 &dev_attr_avg_sample_interval.attr,
1152 &dev_attr_avg_utilization.attr,
1153 &dev_attr_ssch_rsch_count.attr,
1154 &dev_attr_sample_count.attr,
1155 &dev_attr_avg_device_connect_time.attr,
1156 &dev_attr_avg_function_pending_time.attr,
1157 &dev_attr_avg_device_disconnect_time.attr,
1158 &dev_attr_avg_control_unit_queuing_time.attr,
1159 &dev_attr_avg_device_active_only_time.attr,
1160 &dev_attr_avg_device_busy_time.attr,
1161 &dev_attr_avg_initial_command_response_time.attr,
1167 .attrs = cmf_attributes_ext,
1203 DEVICE_ATTR(cmb_enable, 0644, cmb_enable_show, cmb_enable_store);
1207 return cmbops->
set(cdev, enable ? 2 : 0);
1223 ret = cmbops->
alloc(cdev);
1224 cmbops->
reset(cdev);
1227 ret = cmbops->
set(cdev, 2);
1235 cmbops->
set(cdev, 0);
1253 ret = cmbops->
set(cdev, 0);
1273 return cmbops->
read(cdev, index);
1288 return cmbops->
readall(cdev, data);
1294 cmbops->
reset(cdev);
1295 return cmbops->
set(cdev, 2);
1298 static int __init init_cmf(
void)
1300 char *format_string;
1301 char *detect_string =
"parameter";
1314 detect_string =
"autodetected";
1316 detect_string =
"parameter";
1321 format_string =
"basic";
1322 cmbops = &cmbops_basic;
1325 format_string =
"extended";
1326 cmbops = &cmbops_extended;
1331 pr_info(
"Channel measurement facility initialized using format "
1332 "%s (mode %s)\n", format_string, detect_string);
1342 "Copyright IBM Corp. 2003\n");