Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * c 2001 PPC 64 Team, IBM Corp |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; either version |
| 7 | * 2 of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * /dev/nvram driver for PPC64 |
| 10 | * |
| 11 | * This perhaps should live in drivers/char |
| 12 | */ |
| 13 | |
| 14 | |
| 15 | #include <linux/types.h> |
| 16 | #include <linux/errno.h> |
| 17 | #include <linux/init.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <linux/spinlock.h> |
Jim Keniston | a5cf4b0 | 2011-02-09 13:00:09 +0000 | [diff] [blame] | 19 | #include <linux/slab.h> |
| 20 | #include <linux/kmsg_dump.h> |
Aruna Balakrishnaiah | d7563c9 | 2013-06-06 00:21:32 +0530 | [diff] [blame^] | 21 | #include <linux/pstore.h> |
Jim Keniston | 6c49368 | 2011-07-25 07:54:50 +0000 | [diff] [blame] | 22 | #include <linux/ctype.h> |
| 23 | #include <linux/zlib.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <asm/uaccess.h> |
| 25 | #include <asm/nvram.h> |
| 26 | #include <asm/rtas.h> |
| 27 | #include <asm/prom.h> |
| 28 | #include <asm/machdep.h> |
| 29 | |
Benjamin Herrenschmidt | 4e7c77a | 2010-07-29 15:28:20 +1000 | [diff] [blame] | 30 | /* Max bytes to read/write in one go */ |
| 31 | #define NVRW_CNT 0x20 |
| 32 | |
Aruna Balakrishnaiah | b1f70e1 | 2013-06-06 00:21:05 +0530 | [diff] [blame] | 33 | /* |
| 34 | * Set oops header version to distingush between old and new format header. |
| 35 | * lnx,oops-log partition max size is 4000, header version > 4000 will |
| 36 | * help in identifying new header. |
| 37 | */ |
| 38 | #define OOPS_HDR_VERSION 5000 |
| 39 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | static unsigned int nvram_size; |
| 41 | static int nvram_fetch, nvram_store; |
| 42 | static char nvram_buf[NVRW_CNT]; /* assume this is in the first 4GB */ |
| 43 | static DEFINE_SPINLOCK(nvram_lock); |
| 44 | |
Benjamin Herrenschmidt | edc79a2 | 2010-08-02 11:18:09 +1000 | [diff] [blame] | 45 | struct err_log_info { |
| 46 | int error_type; |
| 47 | unsigned int seq_num; |
| 48 | }; |
Benjamin Herrenschmidt | edc79a2 | 2010-08-02 11:18:09 +1000 | [diff] [blame] | 49 | |
Jim Keniston | 0f4ac13 | 2011-02-09 12:43:13 +0000 | [diff] [blame] | 50 | struct nvram_os_partition { |
| 51 | const char *name; |
| 52 | int req_size; /* desired size, in bytes */ |
| 53 | int min_size; /* minimum acceptable size (0 means req_size) */ |
Jim Keniston | a5cf4b0 | 2011-02-09 13:00:09 +0000 | [diff] [blame] | 54 | long size; /* size of data portion (excluding err_log_info) */ |
Jim Keniston | 0f4ac13 | 2011-02-09 12:43:13 +0000 | [diff] [blame] | 55 | long index; /* offset of data portion of partition */ |
| 56 | }; |
| 57 | |
| 58 | static struct nvram_os_partition rtas_log_partition = { |
| 59 | .name = "ibm,rtas-log", |
| 60 | .req_size = 2079, |
| 61 | .min_size = 1055, |
| 62 | .index = -1 |
| 63 | }; |
| 64 | |
Jim Keniston | a5cf4b0 | 2011-02-09 13:00:09 +0000 | [diff] [blame] | 65 | static struct nvram_os_partition oops_log_partition = { |
| 66 | .name = "lnx,oops-log", |
| 67 | .req_size = 4000, |
| 68 | .min_size = 2000, |
| 69 | .index = -1 |
| 70 | }; |
| 71 | |
Jim Keniston | 0f4ac13 | 2011-02-09 12:43:13 +0000 | [diff] [blame] | 72 | static const char *pseries_nvram_os_partitions[] = { |
| 73 | "ibm,rtas-log", |
Jim Keniston | a5cf4b0 | 2011-02-09 13:00:09 +0000 | [diff] [blame] | 74 | "lnx,oops-log", |
Jim Keniston | 0f4ac13 | 2011-02-09 12:43:13 +0000 | [diff] [blame] | 75 | NULL |
| 76 | }; |
Benjamin Herrenschmidt | 9a866b8 | 2010-08-02 10:51:25 +1000 | [diff] [blame] | 77 | |
Aruna Balakrishnaiah | b1f70e1 | 2013-06-06 00:21:05 +0530 | [diff] [blame] | 78 | struct oops_log_info { |
| 79 | u16 version; |
| 80 | u16 report_length; |
| 81 | u64 timestamp; |
| 82 | } __attribute__((packed)); |
| 83 | |
Jim Keniston | a5cf4b0 | 2011-02-09 13:00:09 +0000 | [diff] [blame] | 84 | static void oops_to_nvram(struct kmsg_dumper *dumper, |
Kay Sievers | e2ae715 | 2012-06-15 14:07:51 +0200 | [diff] [blame] | 85 | enum kmsg_dump_reason reason); |
Jim Keniston | a5cf4b0 | 2011-02-09 13:00:09 +0000 | [diff] [blame] | 86 | |
| 87 | static struct kmsg_dumper nvram_kmsg_dumper = { |
| 88 | .dump = oops_to_nvram |
| 89 | }; |
| 90 | |
| 91 | /* See clobbering_unread_rtas_event() */ |
| 92 | #define NVRAM_RTAS_READ_TIMEOUT 5 /* seconds */ |
| 93 | static unsigned long last_unread_rtas_event; /* timestamp */ |
| 94 | |
Jim Keniston | 6c49368 | 2011-07-25 07:54:50 +0000 | [diff] [blame] | 95 | /* |
| 96 | * For capturing and compressing an oops or panic report... |
| 97 | |
| 98 | * big_oops_buf[] holds the uncompressed text we're capturing. |
| 99 | * |
Aruna Balakrishnaiah | b1f70e1 | 2013-06-06 00:21:05 +0530 | [diff] [blame] | 100 | * oops_buf[] holds the compressed text, preceded by a oops header. |
| 101 | * oops header has u16 holding the version of oops header (to differentiate |
| 102 | * between old and new format header) followed by u16 holding the length of |
| 103 | * the compressed* text (*Or uncompressed, if compression fails.) and u64 |
| 104 | * holding the timestamp. oops_buf[] gets written to NVRAM. |
Jim Keniston | 6c49368 | 2011-07-25 07:54:50 +0000 | [diff] [blame] | 105 | * |
Aruna Balakrishnaiah | b1f70e1 | 2013-06-06 00:21:05 +0530 | [diff] [blame] | 106 | * oops_log_info points to the header. oops_data points to the compressed text. |
Jim Keniston | 6c49368 | 2011-07-25 07:54:50 +0000 | [diff] [blame] | 107 | * |
| 108 | * +- oops_buf |
Aruna Balakrishnaiah | b1f70e1 | 2013-06-06 00:21:05 +0530 | [diff] [blame] | 109 | * | +- oops_data |
| 110 | * v v |
| 111 | * +-----------+-----------+-----------+------------------------+ |
| 112 | * | version | length | timestamp | text | |
| 113 | * | (2 bytes) | (2 bytes) | (8 bytes) | (oops_data_sz bytes) | |
| 114 | * +-----------+-----------+-----------+------------------------+ |
Jim Keniston | 6c49368 | 2011-07-25 07:54:50 +0000 | [diff] [blame] | 115 | * ^ |
Aruna Balakrishnaiah | b1f70e1 | 2013-06-06 00:21:05 +0530 | [diff] [blame] | 116 | * +- oops_log_info |
Jim Keniston | 6c49368 | 2011-07-25 07:54:50 +0000 | [diff] [blame] | 117 | * |
| 118 | * We preallocate these buffers during init to avoid kmalloc during oops/panic. |
| 119 | */ |
| 120 | static size_t big_oops_buf_sz; |
| 121 | static char *big_oops_buf, *oops_buf; |
Jim Keniston | 6c49368 | 2011-07-25 07:54:50 +0000 | [diff] [blame] | 122 | static char *oops_data; |
| 123 | static size_t oops_data_sz; |
| 124 | |
| 125 | /* Compression parameters */ |
| 126 | #define COMPR_LEVEL 6 |
| 127 | #define WINDOW_BITS 12 |
| 128 | #define MEM_LEVEL 4 |
| 129 | static struct z_stream_s stream; |
Jim Keniston | a5cf4b0 | 2011-02-09 13:00:09 +0000 | [diff] [blame] | 130 | |
Aruna Balakrishnaiah | d7563c9 | 2013-06-06 00:21:32 +0530 | [diff] [blame^] | 131 | #ifdef CONFIG_PSTORE |
| 132 | static enum pstore_type_id nvram_type_ids[] = { |
| 133 | PSTORE_TYPE_DMESG, |
| 134 | -1 |
| 135 | }; |
| 136 | static int read_type; |
| 137 | #endif |
| 138 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | static ssize_t pSeries_nvram_read(char *buf, size_t count, loff_t *index) |
| 140 | { |
| 141 | unsigned int i; |
| 142 | unsigned long len; |
| 143 | int done; |
| 144 | unsigned long flags; |
| 145 | char *p = buf; |
| 146 | |
| 147 | |
| 148 | if (nvram_size == 0 || nvram_fetch == RTAS_UNKNOWN_SERVICE) |
| 149 | return -ENODEV; |
| 150 | |
| 151 | if (*index >= nvram_size) |
| 152 | return 0; |
| 153 | |
| 154 | i = *index; |
| 155 | if (i + count > nvram_size) |
| 156 | count = nvram_size - i; |
| 157 | |
| 158 | spin_lock_irqsave(&nvram_lock, flags); |
| 159 | |
| 160 | for (; count != 0; count -= len) { |
| 161 | len = count; |
| 162 | if (len > NVRW_CNT) |
| 163 | len = NVRW_CNT; |
| 164 | |
| 165 | if ((rtas_call(nvram_fetch, 3, 2, &done, i, __pa(nvram_buf), |
| 166 | len) != 0) || len != done) { |
| 167 | spin_unlock_irqrestore(&nvram_lock, flags); |
| 168 | return -EIO; |
| 169 | } |
| 170 | |
| 171 | memcpy(p, nvram_buf, len); |
| 172 | |
| 173 | p += len; |
| 174 | i += len; |
| 175 | } |
| 176 | |
| 177 | spin_unlock_irqrestore(&nvram_lock, flags); |
| 178 | |
| 179 | *index = i; |
| 180 | return p - buf; |
| 181 | } |
| 182 | |
| 183 | static ssize_t pSeries_nvram_write(char *buf, size_t count, loff_t *index) |
| 184 | { |
| 185 | unsigned int i; |
| 186 | unsigned long len; |
| 187 | int done; |
| 188 | unsigned long flags; |
| 189 | const char *p = buf; |
| 190 | |
| 191 | if (nvram_size == 0 || nvram_store == RTAS_UNKNOWN_SERVICE) |
| 192 | return -ENODEV; |
| 193 | |
| 194 | if (*index >= nvram_size) |
| 195 | return 0; |
| 196 | |
| 197 | i = *index; |
| 198 | if (i + count > nvram_size) |
| 199 | count = nvram_size - i; |
| 200 | |
| 201 | spin_lock_irqsave(&nvram_lock, flags); |
| 202 | |
| 203 | for (; count != 0; count -= len) { |
| 204 | len = count; |
| 205 | if (len > NVRW_CNT) |
| 206 | len = NVRW_CNT; |
| 207 | |
| 208 | memcpy(nvram_buf, p, len); |
| 209 | |
| 210 | if ((rtas_call(nvram_store, 3, 2, &done, i, __pa(nvram_buf), |
| 211 | len) != 0) || len != done) { |
| 212 | spin_unlock_irqrestore(&nvram_lock, flags); |
| 213 | return -EIO; |
| 214 | } |
| 215 | |
| 216 | p += len; |
| 217 | i += len; |
| 218 | } |
| 219 | spin_unlock_irqrestore(&nvram_lock, flags); |
| 220 | |
| 221 | *index = i; |
| 222 | return p - buf; |
| 223 | } |
| 224 | |
| 225 | static ssize_t pSeries_nvram_get_size(void) |
| 226 | { |
| 227 | return nvram_size ? nvram_size : -ENODEV; |
| 228 | } |
| 229 | |
Benjamin Herrenschmidt | edc79a2 | 2010-08-02 11:18:09 +1000 | [diff] [blame] | 230 | |
Jim Keniston | 0f4ac13 | 2011-02-09 12:43:13 +0000 | [diff] [blame] | 231 | /* nvram_write_os_partition, nvram_write_error_log |
Benjamin Herrenschmidt | edc79a2 | 2010-08-02 11:18:09 +1000 | [diff] [blame] | 232 | * |
| 233 | * We need to buffer the error logs into nvram to ensure that we have |
| 234 | * the failure information to decode. If we have a severe error there |
| 235 | * is no way to guarantee that the OS or the machine is in a state to |
| 236 | * get back to user land and write the error to disk. For example if |
| 237 | * the SCSI device driver causes a Machine Check by writing to a bad |
| 238 | * IO address, there is no way of guaranteeing that the device driver |
| 239 | * is in any state that is would also be able to write the error data |
| 240 | * captured to disk, thus we buffer it in NVRAM for analysis on the |
| 241 | * next boot. |
| 242 | * |
| 243 | * In NVRAM the partition containing the error log buffer will looks like: |
| 244 | * Header (in bytes): |
| 245 | * +-----------+----------+--------+------------+------------------+ |
| 246 | * | signature | checksum | length | name | data | |
| 247 | * |0 |1 |2 3|4 15|16 length-1| |
| 248 | * +-----------+----------+--------+------------+------------------+ |
| 249 | * |
| 250 | * The 'data' section would look like (in bytes): |
| 251 | * +--------------+------------+-----------------------------------+ |
| 252 | * | event_logged | sequence # | error log | |
Jim Keniston | 0f4ac13 | 2011-02-09 12:43:13 +0000 | [diff] [blame] | 253 | * |0 3|4 7|8 error_log_size-1| |
Benjamin Herrenschmidt | edc79a2 | 2010-08-02 11:18:09 +1000 | [diff] [blame] | 254 | * +--------------+------------+-----------------------------------+ |
| 255 | * |
| 256 | * event_logged: 0 if event has not been logged to syslog, 1 if it has |
| 257 | * sequence #: The unique sequence # for each event. (until it wraps) |
| 258 | * error log: The error log from event_scan |
| 259 | */ |
Jim Keniston | 0f4ac13 | 2011-02-09 12:43:13 +0000 | [diff] [blame] | 260 | int nvram_write_os_partition(struct nvram_os_partition *part, char * buff, |
| 261 | int length, unsigned int err_type, unsigned int error_log_cnt) |
Benjamin Herrenschmidt | edc79a2 | 2010-08-02 11:18:09 +1000 | [diff] [blame] | 262 | { |
| 263 | int rc; |
| 264 | loff_t tmp_index; |
| 265 | struct err_log_info info; |
| 266 | |
Jim Keniston | 0f4ac13 | 2011-02-09 12:43:13 +0000 | [diff] [blame] | 267 | if (part->index == -1) { |
Benjamin Herrenschmidt | edc79a2 | 2010-08-02 11:18:09 +1000 | [diff] [blame] | 268 | return -ESPIPE; |
| 269 | } |
| 270 | |
Jim Keniston | 0f4ac13 | 2011-02-09 12:43:13 +0000 | [diff] [blame] | 271 | if (length > part->size) { |
| 272 | length = part->size; |
Benjamin Herrenschmidt | edc79a2 | 2010-08-02 11:18:09 +1000 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | info.error_type = err_type; |
| 276 | info.seq_num = error_log_cnt; |
| 277 | |
Jim Keniston | 0f4ac13 | 2011-02-09 12:43:13 +0000 | [diff] [blame] | 278 | tmp_index = part->index; |
Benjamin Herrenschmidt | edc79a2 | 2010-08-02 11:18:09 +1000 | [diff] [blame] | 279 | |
| 280 | rc = ppc_md.nvram_write((char *)&info, sizeof(struct err_log_info), &tmp_index); |
| 281 | if (rc <= 0) { |
Jim Keniston | 0f4ac13 | 2011-02-09 12:43:13 +0000 | [diff] [blame] | 282 | pr_err("%s: Failed nvram_write (%d)\n", __FUNCTION__, rc); |
Benjamin Herrenschmidt | edc79a2 | 2010-08-02 11:18:09 +1000 | [diff] [blame] | 283 | return rc; |
| 284 | } |
| 285 | |
| 286 | rc = ppc_md.nvram_write(buff, length, &tmp_index); |
| 287 | if (rc <= 0) { |
Jim Keniston | 0f4ac13 | 2011-02-09 12:43:13 +0000 | [diff] [blame] | 288 | pr_err("%s: Failed nvram_write (%d)\n", __FUNCTION__, rc); |
Benjamin Herrenschmidt | edc79a2 | 2010-08-02 11:18:09 +1000 | [diff] [blame] | 289 | return rc; |
| 290 | } |
| 291 | |
| 292 | return 0; |
| 293 | } |
| 294 | |
Jim Keniston | 0f4ac13 | 2011-02-09 12:43:13 +0000 | [diff] [blame] | 295 | int nvram_write_error_log(char * buff, int length, |
| 296 | unsigned int err_type, unsigned int error_log_cnt) |
| 297 | { |
Jim Keniston | a5cf4b0 | 2011-02-09 13:00:09 +0000 | [diff] [blame] | 298 | int rc = nvram_write_os_partition(&rtas_log_partition, buff, length, |
Jim Keniston | 0f4ac13 | 2011-02-09 12:43:13 +0000 | [diff] [blame] | 299 | err_type, error_log_cnt); |
Jim Keniston | a5cf4b0 | 2011-02-09 13:00:09 +0000 | [diff] [blame] | 300 | if (!rc) |
| 301 | last_unread_rtas_event = get_seconds(); |
| 302 | return rc; |
Jim Keniston | 0f4ac13 | 2011-02-09 12:43:13 +0000 | [diff] [blame] | 303 | } |
| 304 | |
Aruna Balakrishnaiah | 1267461 | 2013-06-06 00:21:16 +0530 | [diff] [blame] | 305 | /* nvram_read_partition |
Benjamin Herrenschmidt | edc79a2 | 2010-08-02 11:18:09 +1000 | [diff] [blame] | 306 | * |
Aruna Balakrishnaiah | 1267461 | 2013-06-06 00:21:16 +0530 | [diff] [blame] | 307 | * Reads nvram partition for at most 'length' |
Benjamin Herrenschmidt | edc79a2 | 2010-08-02 11:18:09 +1000 | [diff] [blame] | 308 | */ |
Aruna Balakrishnaiah | 1267461 | 2013-06-06 00:21:16 +0530 | [diff] [blame] | 309 | int nvram_read_partition(struct nvram_os_partition *part, char *buff, |
| 310 | int length, unsigned int *err_type, |
| 311 | unsigned int *error_log_cnt) |
Benjamin Herrenschmidt | edc79a2 | 2010-08-02 11:18:09 +1000 | [diff] [blame] | 312 | { |
| 313 | int rc; |
| 314 | loff_t tmp_index; |
| 315 | struct err_log_info info; |
| 316 | |
Aruna Balakrishnaiah | 1267461 | 2013-06-06 00:21:16 +0530 | [diff] [blame] | 317 | if (part->index == -1) |
Benjamin Herrenschmidt | edc79a2 | 2010-08-02 11:18:09 +1000 | [diff] [blame] | 318 | return -1; |
| 319 | |
Aruna Balakrishnaiah | 1267461 | 2013-06-06 00:21:16 +0530 | [diff] [blame] | 320 | if (length > part->size) |
| 321 | length = part->size; |
Benjamin Herrenschmidt | edc79a2 | 2010-08-02 11:18:09 +1000 | [diff] [blame] | 322 | |
Aruna Balakrishnaiah | 1267461 | 2013-06-06 00:21:16 +0530 | [diff] [blame] | 323 | tmp_index = part->index; |
Benjamin Herrenschmidt | edc79a2 | 2010-08-02 11:18:09 +1000 | [diff] [blame] | 324 | |
| 325 | rc = ppc_md.nvram_read((char *)&info, sizeof(struct err_log_info), &tmp_index); |
| 326 | if (rc <= 0) { |
Aruna Balakrishnaiah | 1267461 | 2013-06-06 00:21:16 +0530 | [diff] [blame] | 327 | pr_err("%s: Failed nvram_read (%d)\n", __FUNCTION__, rc); |
Benjamin Herrenschmidt | edc79a2 | 2010-08-02 11:18:09 +1000 | [diff] [blame] | 328 | return rc; |
| 329 | } |
| 330 | |
| 331 | rc = ppc_md.nvram_read(buff, length, &tmp_index); |
| 332 | if (rc <= 0) { |
Aruna Balakrishnaiah | 1267461 | 2013-06-06 00:21:16 +0530 | [diff] [blame] | 333 | pr_err("%s: Failed nvram_read (%d)\n", __FUNCTION__, rc); |
Benjamin Herrenschmidt | edc79a2 | 2010-08-02 11:18:09 +1000 | [diff] [blame] | 334 | return rc; |
| 335 | } |
| 336 | |
| 337 | *error_log_cnt = info.seq_num; |
| 338 | *err_type = info.error_type; |
| 339 | |
| 340 | return 0; |
| 341 | } |
| 342 | |
Aruna Balakrishnaiah | 1267461 | 2013-06-06 00:21:16 +0530 | [diff] [blame] | 343 | /* nvram_read_error_log |
| 344 | * |
| 345 | * Reads nvram for error log for at most 'length' |
| 346 | */ |
| 347 | int nvram_read_error_log(char *buff, int length, |
| 348 | unsigned int *err_type, unsigned int *error_log_cnt) |
| 349 | { |
| 350 | return nvram_read_partition(&rtas_log_partition, buff, length, |
| 351 | err_type, error_log_cnt); |
| 352 | } |
| 353 | |
Benjamin Herrenschmidt | edc79a2 | 2010-08-02 11:18:09 +1000 | [diff] [blame] | 354 | /* This doesn't actually zero anything, but it sets the event_logged |
| 355 | * word to tell that this event is safely in syslog. |
| 356 | */ |
| 357 | int nvram_clear_error_log(void) |
| 358 | { |
| 359 | loff_t tmp_index; |
| 360 | int clear_word = ERR_FLAG_ALREADY_LOGGED; |
| 361 | int rc; |
| 362 | |
Jim Keniston | 0f4ac13 | 2011-02-09 12:43:13 +0000 | [diff] [blame] | 363 | if (rtas_log_partition.index == -1) |
Benjamin Herrenschmidt | edc79a2 | 2010-08-02 11:18:09 +1000 | [diff] [blame] | 364 | return -1; |
| 365 | |
Jim Keniston | 0f4ac13 | 2011-02-09 12:43:13 +0000 | [diff] [blame] | 366 | tmp_index = rtas_log_partition.index; |
Benjamin Herrenschmidt | edc79a2 | 2010-08-02 11:18:09 +1000 | [diff] [blame] | 367 | |
| 368 | rc = ppc_md.nvram_write((char *)&clear_word, sizeof(int), &tmp_index); |
| 369 | if (rc <= 0) { |
| 370 | printk(KERN_ERR "nvram_clear_error_log: Failed nvram_write (%d)\n", rc); |
| 371 | return rc; |
| 372 | } |
Jim Keniston | a5cf4b0 | 2011-02-09 13:00:09 +0000 | [diff] [blame] | 373 | last_unread_rtas_event = 0; |
Benjamin Herrenschmidt | edc79a2 | 2010-08-02 11:18:09 +1000 | [diff] [blame] | 374 | |
| 375 | return 0; |
| 376 | } |
| 377 | |
Jim Keniston | 0f4ac13 | 2011-02-09 12:43:13 +0000 | [diff] [blame] | 378 | /* pseries_nvram_init_os_partition |
Benjamin Herrenschmidt | edc79a2 | 2010-08-02 11:18:09 +1000 | [diff] [blame] | 379 | * |
Jim Keniston | 0f4ac13 | 2011-02-09 12:43:13 +0000 | [diff] [blame] | 380 | * This sets up a partition with an "OS" signature. |
Benjamin Herrenschmidt | edc79a2 | 2010-08-02 11:18:09 +1000 | [diff] [blame] | 381 | * |
| 382 | * The general strategy is the following: |
Jim Keniston | 0f4ac13 | 2011-02-09 12:43:13 +0000 | [diff] [blame] | 383 | * 1.) If a partition with the indicated name already exists... |
| 384 | * - If it's large enough, use it. |
| 385 | * - Otherwise, recycle it and keep going. |
| 386 | * 2.) Search for a free partition that is large enough. |
| 387 | * 3.) If there's not a free partition large enough, recycle any obsolete |
| 388 | * OS partitions and try again. |
| 389 | * 4.) Will first try getting a chunk that will satisfy the requested size. |
| 390 | * 5.) If a chunk of the requested size cannot be allocated, then try finding |
| 391 | * a chunk that will satisfy the minum needed. |
| 392 | * |
| 393 | * Returns 0 on success, else -1. |
Benjamin Herrenschmidt | edc79a2 | 2010-08-02 11:18:09 +1000 | [diff] [blame] | 394 | */ |
Jim Keniston | 0f4ac13 | 2011-02-09 12:43:13 +0000 | [diff] [blame] | 395 | static int __init pseries_nvram_init_os_partition(struct nvram_os_partition |
| 396 | *part) |
Benjamin Herrenschmidt | edc79a2 | 2010-08-02 11:18:09 +1000 | [diff] [blame] | 397 | { |
| 398 | loff_t p; |
| 399 | int size; |
| 400 | |
| 401 | /* Scan nvram for partitions */ |
| 402 | nvram_scan_partitions(); |
| 403 | |
Jim Keniston | 0f4ac13 | 2011-02-09 12:43:13 +0000 | [diff] [blame] | 404 | /* Look for ours */ |
| 405 | p = nvram_find_partition(part->name, NVRAM_SIG_OS, &size); |
Benjamin Herrenschmidt | edc79a2 | 2010-08-02 11:18:09 +1000 | [diff] [blame] | 406 | |
| 407 | /* Found one but too small, remove it */ |
Jim Keniston | 0f4ac13 | 2011-02-09 12:43:13 +0000 | [diff] [blame] | 408 | if (p && size < part->min_size) { |
| 409 | pr_info("nvram: Found too small %s partition," |
| 410 | " removing it...\n", part->name); |
| 411 | nvram_remove_partition(part->name, NVRAM_SIG_OS, NULL); |
Benjamin Herrenschmidt | edc79a2 | 2010-08-02 11:18:09 +1000 | [diff] [blame] | 412 | p = 0; |
| 413 | } |
| 414 | |
| 415 | /* Create one if we didn't find */ |
| 416 | if (!p) { |
Jim Keniston | 0f4ac13 | 2011-02-09 12:43:13 +0000 | [diff] [blame] | 417 | p = nvram_create_partition(part->name, NVRAM_SIG_OS, |
| 418 | part->req_size, part->min_size); |
Benjamin Herrenschmidt | edc79a2 | 2010-08-02 11:18:09 +1000 | [diff] [blame] | 419 | if (p == -ENOSPC) { |
Jim Keniston | 0f4ac13 | 2011-02-09 12:43:13 +0000 | [diff] [blame] | 420 | pr_info("nvram: No room to create %s partition, " |
| 421 | "deleting any obsolete OS partitions...\n", |
| 422 | part->name); |
| 423 | nvram_remove_partition(NULL, NVRAM_SIG_OS, |
| 424 | pseries_nvram_os_partitions); |
| 425 | p = nvram_create_partition(part->name, NVRAM_SIG_OS, |
| 426 | part->req_size, part->min_size); |
Benjamin Herrenschmidt | edc79a2 | 2010-08-02 11:18:09 +1000 | [diff] [blame] | 427 | } |
| 428 | } |
| 429 | |
| 430 | if (p <= 0) { |
Jim Keniston | 0f4ac13 | 2011-02-09 12:43:13 +0000 | [diff] [blame] | 431 | pr_err("nvram: Failed to find or create %s" |
| 432 | " partition, err %d\n", part->name, (int)p); |
| 433 | return -1; |
Benjamin Herrenschmidt | edc79a2 | 2010-08-02 11:18:09 +1000 | [diff] [blame] | 434 | } |
| 435 | |
Jim Keniston | 0f4ac13 | 2011-02-09 12:43:13 +0000 | [diff] [blame] | 436 | part->index = p; |
| 437 | part->size = nvram_get_partition_size(p) - sizeof(struct err_log_info); |
Benjamin Herrenschmidt | edc79a2 | 2010-08-02 11:18:09 +1000 | [diff] [blame] | 438 | |
| 439 | return 0; |
| 440 | } |
Jim Keniston | 0f4ac13 | 2011-02-09 12:43:13 +0000 | [diff] [blame] | 441 | |
Aruna Balakrishnaiah | d7563c9 | 2013-06-06 00:21:32 +0530 | [diff] [blame^] | 442 | /* |
| 443 | * Are we using the ibm,rtas-log for oops/panic reports? And if so, |
| 444 | * would logging this oops/panic overwrite an RTAS event that rtas_errd |
| 445 | * hasn't had a chance to read and process? Return 1 if so, else 0. |
| 446 | * |
| 447 | * We assume that if rtas_errd hasn't read the RTAS event in |
| 448 | * NVRAM_RTAS_READ_TIMEOUT seconds, it's probably not going to. |
| 449 | */ |
| 450 | static int clobbering_unread_rtas_event(void) |
| 451 | { |
| 452 | return (oops_log_partition.index == rtas_log_partition.index |
| 453 | && last_unread_rtas_event |
| 454 | && get_seconds() - last_unread_rtas_event <= |
| 455 | NVRAM_RTAS_READ_TIMEOUT); |
| 456 | } |
| 457 | |
| 458 | #ifdef CONFIG_PSTORE |
| 459 | static int nvram_pstore_open(struct pstore_info *psi) |
| 460 | { |
| 461 | /* Reset the iterator to start reading partitions again */ |
| 462 | read_type = -1; |
| 463 | return 0; |
| 464 | } |
| 465 | |
| 466 | /** |
| 467 | * nvram_pstore_write - pstore write callback for nvram |
| 468 | * @type: Type of message logged |
| 469 | * @reason: reason behind dump (oops/panic) |
| 470 | * @id: identifier to indicate the write performed |
| 471 | * @part: pstore writes data to registered buffer in parts, |
| 472 | * part number will indicate the same. |
| 473 | * @count: Indicates oops count |
| 474 | * @size: number of bytes written to the registered buffer |
| 475 | * @psi: registered pstore_info structure |
| 476 | * |
| 477 | * Called by pstore_dump() when an oops or panic report is logged in the |
| 478 | * printk buffer. |
| 479 | * Returns 0 on successful write. |
| 480 | */ |
| 481 | static int nvram_pstore_write(enum pstore_type_id type, |
| 482 | enum kmsg_dump_reason reason, |
| 483 | u64 *id, unsigned int part, int count, |
| 484 | size_t size, struct pstore_info *psi) |
| 485 | { |
| 486 | int rc; |
| 487 | struct oops_log_info *oops_hdr = (struct oops_log_info *) oops_buf; |
| 488 | |
| 489 | /* part 1 has the recent messages from printk buffer */ |
| 490 | if (part > 1 || type != PSTORE_TYPE_DMESG || |
| 491 | clobbering_unread_rtas_event()) |
| 492 | return -1; |
| 493 | |
| 494 | oops_hdr->version = OOPS_HDR_VERSION; |
| 495 | oops_hdr->report_length = (u16) size; |
| 496 | oops_hdr->timestamp = get_seconds(); |
| 497 | rc = nvram_write_os_partition(&oops_log_partition, oops_buf, |
| 498 | (int) (sizeof(*oops_hdr) + size), ERR_TYPE_KERNEL_PANIC, |
| 499 | count); |
| 500 | |
| 501 | if (rc != 0) |
| 502 | return rc; |
| 503 | |
| 504 | *id = part; |
| 505 | return 0; |
| 506 | } |
| 507 | |
| 508 | /* |
| 509 | * Reads the oops/panic report. |
| 510 | * Returns the length of the data we read from each partition. |
| 511 | * Returns 0 if we've been called before. |
| 512 | */ |
| 513 | static ssize_t nvram_pstore_read(u64 *id, enum pstore_type_id *type, |
| 514 | int *count, struct timespec *time, char **buf, |
| 515 | struct pstore_info *psi) |
| 516 | { |
| 517 | struct oops_log_info *oops_hdr; |
| 518 | unsigned int err_type, id_no; |
| 519 | struct nvram_os_partition *part = NULL; |
| 520 | char *buff = NULL; |
| 521 | |
| 522 | read_type++; |
| 523 | |
| 524 | switch (nvram_type_ids[read_type]) { |
| 525 | case PSTORE_TYPE_DMESG: |
| 526 | part = &oops_log_partition; |
| 527 | *type = PSTORE_TYPE_DMESG; |
| 528 | break; |
| 529 | default: |
| 530 | return 0; |
| 531 | } |
| 532 | |
| 533 | buff = kmalloc(part->size, GFP_KERNEL); |
| 534 | |
| 535 | if (!buff) |
| 536 | return -ENOMEM; |
| 537 | |
| 538 | if (nvram_read_partition(part, buff, part->size, &err_type, &id_no)) { |
| 539 | kfree(buff); |
| 540 | return 0; |
| 541 | } |
| 542 | |
| 543 | *count = 0; |
| 544 | *id = id_no; |
| 545 | oops_hdr = (struct oops_log_info *)buff; |
| 546 | *buf = buff + sizeof(*oops_hdr); |
| 547 | time->tv_sec = oops_hdr->timestamp; |
| 548 | time->tv_nsec = 0; |
| 549 | return oops_hdr->report_length; |
| 550 | } |
| 551 | |
| 552 | static struct pstore_info nvram_pstore_info = { |
| 553 | .owner = THIS_MODULE, |
| 554 | .name = "nvram", |
| 555 | .open = nvram_pstore_open, |
| 556 | .read = nvram_pstore_read, |
| 557 | .write = nvram_pstore_write, |
| 558 | }; |
| 559 | |
| 560 | static int nvram_pstore_init(void) |
| 561 | { |
| 562 | int rc = 0; |
| 563 | |
| 564 | nvram_pstore_info.buf = oops_data; |
| 565 | nvram_pstore_info.bufsize = oops_data_sz; |
| 566 | |
| 567 | rc = pstore_register(&nvram_pstore_info); |
| 568 | if (rc != 0) |
| 569 | pr_err("nvram: pstore_register() failed, defaults to " |
| 570 | "kmsg_dump; returned %d\n", rc); |
| 571 | else |
| 572 | /*TODO: Support compression when pstore is configured */ |
| 573 | pr_info("nvram: Compression of oops text supported only when " |
| 574 | "pstore is not configured"); |
| 575 | |
| 576 | return rc; |
| 577 | } |
| 578 | #else |
| 579 | static int nvram_pstore_init(void) |
| 580 | { |
| 581 | return -1; |
| 582 | } |
| 583 | #endif |
| 584 | |
Jim Keniston | a5cf4b0 | 2011-02-09 13:00:09 +0000 | [diff] [blame] | 585 | static void __init nvram_init_oops_partition(int rtas_partition_exists) |
| 586 | { |
| 587 | int rc; |
| 588 | |
| 589 | rc = pseries_nvram_init_os_partition(&oops_log_partition); |
| 590 | if (rc != 0) { |
| 591 | if (!rtas_partition_exists) |
| 592 | return; |
| 593 | pr_notice("nvram: Using %s partition to log both" |
| 594 | " RTAS errors and oops/panic reports\n", |
| 595 | rtas_log_partition.name); |
| 596 | memcpy(&oops_log_partition, &rtas_log_partition, |
| 597 | sizeof(rtas_log_partition)); |
| 598 | } |
| 599 | oops_buf = kmalloc(oops_log_partition.size, GFP_KERNEL); |
Jim Keniston | 6c49368 | 2011-07-25 07:54:50 +0000 | [diff] [blame] | 600 | if (!oops_buf) { |
| 601 | pr_err("nvram: No memory for %s partition\n", |
| 602 | oops_log_partition.name); |
| 603 | return; |
| 604 | } |
Aruna Balakrishnaiah | b1f70e1 | 2013-06-06 00:21:05 +0530 | [diff] [blame] | 605 | oops_data = oops_buf + sizeof(struct oops_log_info); |
| 606 | oops_data_sz = oops_log_partition.size - sizeof(struct oops_log_info); |
Jim Keniston | 6c49368 | 2011-07-25 07:54:50 +0000 | [diff] [blame] | 607 | |
Aruna Balakrishnaiah | d7563c9 | 2013-06-06 00:21:32 +0530 | [diff] [blame^] | 608 | rc = nvram_pstore_init(); |
| 609 | |
| 610 | if (!rc) |
| 611 | return; |
| 612 | |
Jim Keniston | 6c49368 | 2011-07-25 07:54:50 +0000 | [diff] [blame] | 613 | /* |
| 614 | * Figure compression (preceded by elimination of each line's <n> |
| 615 | * severity prefix) will reduce the oops/panic report to at most |
| 616 | * 45% of its original size. |
| 617 | */ |
| 618 | big_oops_buf_sz = (oops_data_sz * 100) / 45; |
| 619 | big_oops_buf = kmalloc(big_oops_buf_sz, GFP_KERNEL); |
| 620 | if (big_oops_buf) { |
| 621 | stream.workspace = kmalloc(zlib_deflate_workspacesize( |
| 622 | WINDOW_BITS, MEM_LEVEL), GFP_KERNEL); |
| 623 | if (!stream.workspace) { |
| 624 | pr_err("nvram: No memory for compression workspace; " |
| 625 | "skipping compression of %s partition data\n", |
| 626 | oops_log_partition.name); |
| 627 | kfree(big_oops_buf); |
| 628 | big_oops_buf = NULL; |
| 629 | } |
| 630 | } else { |
| 631 | pr_err("No memory for uncompressed %s data; " |
| 632 | "skipping compression\n", oops_log_partition.name); |
| 633 | stream.workspace = NULL; |
| 634 | } |
| 635 | |
Jim Keniston | a5cf4b0 | 2011-02-09 13:00:09 +0000 | [diff] [blame] | 636 | rc = kmsg_dump_register(&nvram_kmsg_dumper); |
| 637 | if (rc != 0) { |
| 638 | pr_err("nvram: kmsg_dump_register() failed; returned %d\n", rc); |
| 639 | kfree(oops_buf); |
Jim Keniston | 6c49368 | 2011-07-25 07:54:50 +0000 | [diff] [blame] | 640 | kfree(big_oops_buf); |
| 641 | kfree(stream.workspace); |
Jim Keniston | a5cf4b0 | 2011-02-09 13:00:09 +0000 | [diff] [blame] | 642 | } |
| 643 | } |
| 644 | |
Jim Keniston | 0f4ac13 | 2011-02-09 12:43:13 +0000 | [diff] [blame] | 645 | static int __init pseries_nvram_init_log_partitions(void) |
| 646 | { |
Jim Keniston | a5cf4b0 | 2011-02-09 13:00:09 +0000 | [diff] [blame] | 647 | int rc; |
| 648 | |
| 649 | rc = pseries_nvram_init_os_partition(&rtas_log_partition); |
| 650 | nvram_init_oops_partition(rc == 0); |
Jim Keniston | 0f4ac13 | 2011-02-09 12:43:13 +0000 | [diff] [blame] | 651 | return 0; |
| 652 | } |
| 653 | machine_arch_initcall(pseries, pseries_nvram_init_log_partitions); |
Benjamin Herrenschmidt | edc79a2 | 2010-08-02 11:18:09 +1000 | [diff] [blame] | 654 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | int __init pSeries_nvram_init(void) |
| 656 | { |
| 657 | struct device_node *nvram; |
Jeremy Kerr | 954a46e | 2006-07-12 15:39:43 +1000 | [diff] [blame] | 658 | const unsigned int *nbytes_p; |
| 659 | unsigned int proplen; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | |
| 661 | nvram = of_find_node_by_type(NULL, "nvram"); |
| 662 | if (nvram == NULL) |
| 663 | return -ENODEV; |
| 664 | |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 665 | nbytes_p = of_get_property(nvram, "#bytes", &proplen); |
Julia Lawall | bad5232 | 2008-06-09 22:20:04 +1000 | [diff] [blame] | 666 | if (nbytes_p == NULL || proplen != sizeof(unsigned int)) { |
| 667 | of_node_put(nvram); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | return -EIO; |
Julia Lawall | bad5232 | 2008-06-09 22:20:04 +1000 | [diff] [blame] | 669 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | |
| 671 | nvram_size = *nbytes_p; |
| 672 | |
| 673 | nvram_fetch = rtas_token("nvram-fetch"); |
| 674 | nvram_store = rtas_token("nvram-store"); |
| 675 | printk(KERN_INFO "PPC64 nvram contains %d bytes\n", nvram_size); |
| 676 | of_node_put(nvram); |
| 677 | |
| 678 | ppc_md.nvram_read = pSeries_nvram_read; |
| 679 | ppc_md.nvram_write = pSeries_nvram_write; |
| 680 | ppc_md.nvram_size = pSeries_nvram_get_size; |
| 681 | |
| 682 | return 0; |
| 683 | } |
Jim Keniston | a5cf4b0 | 2011-02-09 13:00:09 +0000 | [diff] [blame] | 684 | |
Jim Keniston | a5cf4b0 | 2011-02-09 13:00:09 +0000 | [diff] [blame] | 685 | |
Jim Keniston | 6c49368 | 2011-07-25 07:54:50 +0000 | [diff] [blame] | 686 | /* Derived from logfs_compress() */ |
| 687 | static int nvram_compress(const void *in, void *out, size_t inlen, |
| 688 | size_t outlen) |
| 689 | { |
| 690 | int err, ret; |
| 691 | |
| 692 | ret = -EIO; |
| 693 | err = zlib_deflateInit2(&stream, COMPR_LEVEL, Z_DEFLATED, WINDOW_BITS, |
| 694 | MEM_LEVEL, Z_DEFAULT_STRATEGY); |
| 695 | if (err != Z_OK) |
| 696 | goto error; |
| 697 | |
| 698 | stream.next_in = in; |
| 699 | stream.avail_in = inlen; |
| 700 | stream.total_in = 0; |
| 701 | stream.next_out = out; |
| 702 | stream.avail_out = outlen; |
| 703 | stream.total_out = 0; |
| 704 | |
| 705 | err = zlib_deflate(&stream, Z_FINISH); |
| 706 | if (err != Z_STREAM_END) |
| 707 | goto error; |
| 708 | |
| 709 | err = zlib_deflateEnd(&stream); |
| 710 | if (err != Z_OK) |
| 711 | goto error; |
| 712 | |
| 713 | if (stream.total_out >= stream.total_in) |
| 714 | goto error; |
| 715 | |
| 716 | ret = stream.total_out; |
| 717 | error: |
| 718 | return ret; |
| 719 | } |
| 720 | |
| 721 | /* Compress the text from big_oops_buf into oops_buf. */ |
| 722 | static int zip_oops(size_t text_len) |
| 723 | { |
Aruna Balakrishnaiah | b1f70e1 | 2013-06-06 00:21:05 +0530 | [diff] [blame] | 724 | struct oops_log_info *oops_hdr = (struct oops_log_info *)oops_buf; |
Jim Keniston | 6c49368 | 2011-07-25 07:54:50 +0000 | [diff] [blame] | 725 | int zipped_len = nvram_compress(big_oops_buf, oops_data, text_len, |
| 726 | oops_data_sz); |
| 727 | if (zipped_len < 0) { |
| 728 | pr_err("nvram: compression failed; returned %d\n", zipped_len); |
| 729 | pr_err("nvram: logging uncompressed oops/panic report\n"); |
| 730 | return -1; |
| 731 | } |
Aruna Balakrishnaiah | b1f70e1 | 2013-06-06 00:21:05 +0530 | [diff] [blame] | 732 | oops_hdr->version = OOPS_HDR_VERSION; |
| 733 | oops_hdr->report_length = (u16) zipped_len; |
| 734 | oops_hdr->timestamp = get_seconds(); |
Jim Keniston | 6c49368 | 2011-07-25 07:54:50 +0000 | [diff] [blame] | 735 | return 0; |
| 736 | } |
| 737 | |
| 738 | /* |
| 739 | * This is our kmsg_dump callback, called after an oops or panic report |
| 740 | * has been written to the printk buffer. We want to capture as much |
| 741 | * of the printk buffer as possible. First, capture as much as we can |
| 742 | * that we think will compress sufficiently to fit in the lnx,oops-log |
| 743 | * partition. If that's too much, go back and capture uncompressed text. |
| 744 | */ |
Jim Keniston | a5cf4b0 | 2011-02-09 13:00:09 +0000 | [diff] [blame] | 745 | static void oops_to_nvram(struct kmsg_dumper *dumper, |
Kay Sievers | e2ae715 | 2012-06-15 14:07:51 +0200 | [diff] [blame] | 746 | enum kmsg_dump_reason reason) |
Jim Keniston | a5cf4b0 | 2011-02-09 13:00:09 +0000 | [diff] [blame] | 747 | { |
Aruna Balakrishnaiah | b1f70e1 | 2013-06-06 00:21:05 +0530 | [diff] [blame] | 748 | struct oops_log_info *oops_hdr = (struct oops_log_info *)oops_buf; |
Jim Keniston | a5cf4b0 | 2011-02-09 13:00:09 +0000 | [diff] [blame] | 749 | static unsigned int oops_count = 0; |
Jim Keniston | 15d260b | 2011-03-25 12:47:58 +0000 | [diff] [blame] | 750 | static bool panicking = false; |
Anton Blanchard | 120a52c | 2011-11-30 15:46:45 +0000 | [diff] [blame] | 751 | static DEFINE_SPINLOCK(lock); |
| 752 | unsigned long flags; |
Jim Keniston | a5cf4b0 | 2011-02-09 13:00:09 +0000 | [diff] [blame] | 753 | size_t text_len; |
Jim Keniston | 6c49368 | 2011-07-25 07:54:50 +0000 | [diff] [blame] | 754 | unsigned int err_type = ERR_TYPE_KERNEL_PANIC_GZ; |
| 755 | int rc = -1; |
Jim Keniston | a5cf4b0 | 2011-02-09 13:00:09 +0000 | [diff] [blame] | 756 | |
Jim Keniston | 15d260b | 2011-03-25 12:47:58 +0000 | [diff] [blame] | 757 | switch (reason) { |
| 758 | case KMSG_DUMP_RESTART: |
| 759 | case KMSG_DUMP_HALT: |
| 760 | case KMSG_DUMP_POWEROFF: |
| 761 | /* These are almost always orderly shutdowns. */ |
| 762 | return; |
| 763 | case KMSG_DUMP_OOPS: |
Jim Keniston | 15d260b | 2011-03-25 12:47:58 +0000 | [diff] [blame] | 764 | break; |
| 765 | case KMSG_DUMP_PANIC: |
| 766 | panicking = true; |
| 767 | break; |
| 768 | case KMSG_DUMP_EMERG: |
| 769 | if (panicking) |
| 770 | /* Panic report already captured. */ |
| 771 | return; |
| 772 | break; |
| 773 | default: |
| 774 | pr_err("%s: ignoring unrecognized KMSG_DUMP_* reason %d\n", |
| 775 | __FUNCTION__, (int) reason); |
| 776 | return; |
| 777 | } |
| 778 | |
Jim Keniston | a5cf4b0 | 2011-02-09 13:00:09 +0000 | [diff] [blame] | 779 | if (clobbering_unread_rtas_event()) |
| 780 | return; |
| 781 | |
Anton Blanchard | 120a52c | 2011-11-30 15:46:45 +0000 | [diff] [blame] | 782 | if (!spin_trylock_irqsave(&lock, flags)) |
| 783 | return; |
| 784 | |
Jim Keniston | 6c49368 | 2011-07-25 07:54:50 +0000 | [diff] [blame] | 785 | if (big_oops_buf) { |
Kay Sievers | e2ae715 | 2012-06-15 14:07:51 +0200 | [diff] [blame] | 786 | kmsg_dump_get_buffer(dumper, false, |
| 787 | big_oops_buf, big_oops_buf_sz, &text_len); |
Jim Keniston | 6c49368 | 2011-07-25 07:54:50 +0000 | [diff] [blame] | 788 | rc = zip_oops(text_len); |
| 789 | } |
| 790 | if (rc != 0) { |
Kay Sievers | e2ae715 | 2012-06-15 14:07:51 +0200 | [diff] [blame] | 791 | kmsg_dump_rewind(dumper); |
Aruna Balakrishnaiah | 1bf247f | 2013-06-06 00:20:55 +0530 | [diff] [blame] | 792 | kmsg_dump_get_buffer(dumper, false, |
Kay Sievers | e2ae715 | 2012-06-15 14:07:51 +0200 | [diff] [blame] | 793 | oops_data, oops_data_sz, &text_len); |
Jim Keniston | 6c49368 | 2011-07-25 07:54:50 +0000 | [diff] [blame] | 794 | err_type = ERR_TYPE_KERNEL_PANIC; |
Aruna Balakrishnaiah | b1f70e1 | 2013-06-06 00:21:05 +0530 | [diff] [blame] | 795 | oops_hdr->version = OOPS_HDR_VERSION; |
| 796 | oops_hdr->report_length = (u16) text_len; |
| 797 | oops_hdr->timestamp = get_seconds(); |
Jim Keniston | 6c49368 | 2011-07-25 07:54:50 +0000 | [diff] [blame] | 798 | } |
| 799 | |
Jim Keniston | a5cf4b0 | 2011-02-09 13:00:09 +0000 | [diff] [blame] | 800 | (void) nvram_write_os_partition(&oops_log_partition, oops_buf, |
Aruna Balakrishnaiah | b1f70e1 | 2013-06-06 00:21:05 +0530 | [diff] [blame] | 801 | (int) (sizeof(*oops_hdr) + oops_hdr->report_length), err_type, |
| 802 | ++oops_count); |
Anton Blanchard | 120a52c | 2011-11-30 15:46:45 +0000 | [diff] [blame] | 803 | |
| 804 | spin_unlock_irqrestore(&lock, flags); |
Jim Keniston | a5cf4b0 | 2011-02-09 13:00:09 +0000 | [diff] [blame] | 805 | } |