0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <linux/init.h>
0010 #include <linux/export.h>
0011 #include <linux/timer.h>
0012 #include <linux/slab.h>
0013 #include <asm/facility.h>
0014 #include <asm/sysinfo.h>
0015 #include <asm/ebcdic.h>
0016 #include <asm/debug.h>
0017 #include <asm/ipl.h>
0018
0019 #define LGR_TIMER_INTERVAL_SECS (30 * 60)
0020 #define VM_LEVEL_MAX 2
0021
0022
0023
0024
0025 struct lgr_info {
0026
0027 u64 stfle_fac_list[4];
0028
0029 u32 level;
0030
0031 char manufacturer[16];
0032 char type[4];
0033 char sequence[16];
0034 char plant[4];
0035 char model[16];
0036
0037 u16 lpar_number;
0038 char name[8];
0039
0040 u8 vm_count;
0041 struct {
0042 char name[8];
0043 char cpi[16];
0044 } vm[VM_LEVEL_MAX];
0045 } __packed __aligned(8);
0046
0047
0048
0049
0050 static char lgr_page[PAGE_SIZE] __aligned(PAGE_SIZE);
0051 static struct lgr_info lgr_info_last;
0052 static struct lgr_info lgr_info_cur;
0053 static struct debug_info *lgr_dbf;
0054
0055
0056
0057
0058 static void cpascii(char *dst, char *src, int size)
0059 {
0060 memcpy(dst, src, size);
0061 EBCASC(dst, size);
0062 }
0063
0064
0065
0066
0067 static void lgr_stsi_1_1_1(struct lgr_info *lgr_info)
0068 {
0069 struct sysinfo_1_1_1 *si = (void *) lgr_page;
0070
0071 if (stsi(si, 1, 1, 1))
0072 return;
0073 cpascii(lgr_info->manufacturer, si->manufacturer,
0074 sizeof(si->manufacturer));
0075 cpascii(lgr_info->type, si->type, sizeof(si->type));
0076 cpascii(lgr_info->model, si->model, sizeof(si->model));
0077 cpascii(lgr_info->sequence, si->sequence, sizeof(si->sequence));
0078 cpascii(lgr_info->plant, si->plant, sizeof(si->plant));
0079 }
0080
0081
0082
0083
0084 static void lgr_stsi_2_2_2(struct lgr_info *lgr_info)
0085 {
0086 struct sysinfo_2_2_2 *si = (void *) lgr_page;
0087
0088 if (stsi(si, 2, 2, 2))
0089 return;
0090 cpascii(lgr_info->name, si->name, sizeof(si->name));
0091 lgr_info->lpar_number = si->lpar_number;
0092 }
0093
0094
0095
0096
0097 static void lgr_stsi_3_2_2(struct lgr_info *lgr_info)
0098 {
0099 struct sysinfo_3_2_2 *si = (void *) lgr_page;
0100 int i;
0101
0102 if (stsi(si, 3, 2, 2))
0103 return;
0104 for (i = 0; i < min_t(u8, si->count, VM_LEVEL_MAX); i++) {
0105 cpascii(lgr_info->vm[i].name, si->vm[i].name,
0106 sizeof(si->vm[i].name));
0107 cpascii(lgr_info->vm[i].cpi, si->vm[i].cpi,
0108 sizeof(si->vm[i].cpi));
0109 }
0110 lgr_info->vm_count = si->count;
0111 }
0112
0113
0114
0115
0116 static void lgr_info_get(struct lgr_info *lgr_info)
0117 {
0118 int level;
0119
0120 memset(lgr_info, 0, sizeof(*lgr_info));
0121 stfle(lgr_info->stfle_fac_list, ARRAY_SIZE(lgr_info->stfle_fac_list));
0122 level = stsi(NULL, 0, 0, 0);
0123 lgr_info->level = level;
0124 if (level >= 1)
0125 lgr_stsi_1_1_1(lgr_info);
0126 if (level >= 2)
0127 lgr_stsi_2_2_2(lgr_info);
0128 if (level >= 3)
0129 lgr_stsi_3_2_2(lgr_info);
0130 }
0131
0132
0133
0134
0135 void lgr_info_log(void)
0136 {
0137 static DEFINE_SPINLOCK(lgr_info_lock);
0138 unsigned long flags;
0139
0140 if (!spin_trylock_irqsave(&lgr_info_lock, flags))
0141 return;
0142 lgr_info_get(&lgr_info_cur);
0143 if (memcmp(&lgr_info_last, &lgr_info_cur, sizeof(lgr_info_cur)) != 0) {
0144 debug_event(lgr_dbf, 1, &lgr_info_cur, sizeof(lgr_info_cur));
0145 lgr_info_last = lgr_info_cur;
0146 }
0147 spin_unlock_irqrestore(&lgr_info_lock, flags);
0148 }
0149 EXPORT_SYMBOL_GPL(lgr_info_log);
0150
0151 static void lgr_timer_set(void);
0152
0153
0154
0155
0156 static void lgr_timer_fn(struct timer_list *unused)
0157 {
0158 lgr_info_log();
0159 lgr_timer_set();
0160 }
0161
0162 static struct timer_list lgr_timer;
0163
0164
0165
0166
0167 static void lgr_timer_set(void)
0168 {
0169 mod_timer(&lgr_timer, jiffies + msecs_to_jiffies(LGR_TIMER_INTERVAL_SECS * MSEC_PER_SEC));
0170 }
0171
0172
0173
0174
0175 static int __init lgr_init(void)
0176 {
0177 lgr_dbf = debug_register("lgr", 1, 1, sizeof(struct lgr_info));
0178 if (!lgr_dbf)
0179 return -ENOMEM;
0180 debug_register_view(lgr_dbf, &debug_hex_ascii_view);
0181 lgr_info_get(&lgr_info_last);
0182 debug_event(lgr_dbf, 1, &lgr_info_last, sizeof(lgr_info_last));
0183 timer_setup(&lgr_timer, lgr_timer_fn, TIMER_DEFERRABLE);
0184 lgr_timer_set();
0185 return 0;
0186 }
0187 device_initcall(lgr_init);