9 #define KMSG_COMPONENT "dasd-eckd"
13 #include <linux/kernel.h>
15 #include <linux/module.h>
17 #include <linux/device.h>
18 #include <linux/poll.h>
21 #include <linux/slab.h>
23 #include <asm/uaccess.h>
33 #define PRINTK_HEADER "dasd(eer):"
82 static int eer_pages = 5;
103 static int dasd_eer_get_free_bytes(
struct eerbuffer *eerb)
114 static int dasd_eer_get_filled_bytes(
struct eerbuffer *eerb)
128 static void dasd_eer_write_buffer(
struct eerbuffer *eerb,
132 unsigned long headindex,localhead;
142 memcpy(eerb->
buffer[headindex]+localhead, nextdata, len);
155 static int dasd_eer_read_buffer(
struct eerbuffer *eerb,
char *data,
int count)
158 unsigned long tailindex,localtail;
159 unsigned long rest, len, finalcount;
162 finalcount =
min(count, dasd_eer_get_filled_bytes(eerb));
169 memcpy(nextdata, eerb->
buffer[tailindex] + localtail, len);
187 static int dasd_eer_start_record(
struct eerbuffer *eerb,
int count)
193 while (dasd_eer_get_free_bytes(eerb) < count +
sizeof(count)) {
200 dasd_eer_read_buffer(eerb, (
char *) &tailcount,
202 eerb->
tail += tailcount;
206 dasd_eer_write_buffer(eerb, (
char*) &count,
sizeof(count));
214 static void dasd_eer_free_buffer_pages(
char **
buf,
int no_pages)
218 for (i = 0; i < no_pages; i++)
225 static int dasd_eer_allocate_buffer_pages(
char **buf,
int no_pages)
229 for (i = 0; i < no_pages; i++) {
232 dasd_eer_free_buffer_pages(buf, i);
274 #define SNSS_DATA_SIZE 44
276 #define DASD_EER_BUSID_SIZE 10
306 for (temp_cqr = cqr; temp_cqr; temp_cqr = temp_cqr->
refers)
310 header.
total_size =
sizeof(header) + data_size + 4;
320 dasd_eer_start_record(eerb, header.
total_size);
321 dasd_eer_write_buffer(eerb, (
char *) &header,
sizeof(header));
322 for (temp_cqr = cqr; temp_cqr; temp_cqr = temp_cqr->
refers) {
325 dasd_eer_write_buffer(eerb, sense, 32);
327 dasd_eer_write_buffer(eerb,
"EOR", 4);
329 spin_unlock_irqrestore(&bufferlock, flags);
356 header.tv_sec = tv.tv_sec;
357 header.tv_usec = tv.tv_usec;
363 dasd_eer_start_record(eerb,
header.total_size);
364 dasd_eer_write_buffer(eerb, (
char *) &
header ,
sizeof(
header));
367 dasd_eer_write_buffer(eerb,
"EOR", 4);
369 spin_unlock_irqrestore(&bufferlock, flags);
385 dasd_eer_write_standard_trigger(device, cqr,
id);
388 dasd_eer_write_standard_trigger(device,
NULL,
id);
391 dasd_eer_write_snss_trigger(device, cqr,
id);
394 dasd_eer_write_standard_trigger(device,
NULL,
id);
426 static void dasd_eer_snss_cb(
struct dasd_ccw_req *cqr,
void *data)
532 static int dasd_eer_open(
struct inode *
inp,
struct file *filp)
545 "parameter eer_pages is smaller than 1 or"
556 if (dasd_eer_allocate_buffer_pages(eerb->
buffer,
564 list_add(&eerb->
list, &bufferlist);
565 spin_unlock_irqrestore(&bufferlock, flags);
570 static int dasd_eer_close(
struct inode *inp,
struct file *filp)
578 spin_unlock_irqrestore(&bufferlock, flags);
586 static ssize_t dasd_eer_read(
struct file *filp,
char __user *buf,
587 size_t count, loff_t *ppos)
590 int tailcount,effective_count;
603 spin_unlock_irqrestore(&bufferlock, flags);
608 effective_count =
min(eerb->
residual, (
int) count);
613 tc = dasd_eer_read_buffer(eerb, (
char *) &tailcount,
617 spin_unlock_irqrestore(&bufferlock, flags);
622 dasd_eer_read_wait_queue,
631 WARN_ON(tc !=
sizeof(tailcount));
632 effective_count =
min(tailcount,(
int)count);
633 eerb->
residual = tailcount - effective_count;
636 tc = dasd_eer_read_buffer(eerb, readbuffer, effective_count);
637 WARN_ON(tc != effective_count);
639 spin_unlock_irqrestore(&bufferlock, flags);
647 return effective_count;
650 static unsigned int dasd_eer_poll(
struct file *filp,
poll_table *ptable)
657 poll_wait(filp, &dasd_eer_read_wait_queue, ptable);
663 spin_unlock_irqrestore(&bufferlock, flags);
668 .open = &dasd_eer_open,
669 .release = &dasd_eer_close,
670 .read = &dasd_eer_read,
671 .poll = &dasd_eer_poll,
682 dasd_eer_dev = kzalloc(
sizeof(*dasd_eer_dev),
GFP_KERNEL);
687 dasd_eer_dev->
name =
"dasd_eer";
688 dasd_eer_dev->
fops = &dasd_eer_fops;
695 "register misc device");