Lines Matching refs:eerb
104 static int dasd_eer_get_free_bytes(struct eerbuffer *eerb) in dasd_eer_get_free_bytes() argument
106 if (eerb->head < eerb->tail) in dasd_eer_get_free_bytes()
107 return eerb->tail - eerb->head - 1; in dasd_eer_get_free_bytes()
108 return eerb->buffersize - eerb->head + eerb->tail -1; in dasd_eer_get_free_bytes()
115 static int dasd_eer_get_filled_bytes(struct eerbuffer *eerb) in dasd_eer_get_filled_bytes() argument
118 if (eerb->head >= eerb->tail) in dasd_eer_get_filled_bytes()
119 return eerb->head - eerb->tail; in dasd_eer_get_filled_bytes()
120 return eerb->buffersize - eerb->tail + eerb->head; in dasd_eer_get_filled_bytes()
129 static void dasd_eer_write_buffer(struct eerbuffer *eerb, in dasd_eer_write_buffer() argument
140 headindex = eerb->head / PAGE_SIZE; in dasd_eer_write_buffer()
141 localhead = eerb->head % PAGE_SIZE; in dasd_eer_write_buffer()
143 memcpy(eerb->buffer[headindex]+localhead, nextdata, len); in dasd_eer_write_buffer()
146 eerb->head += len; in dasd_eer_write_buffer()
147 if (eerb->head == eerb->buffersize) in dasd_eer_write_buffer()
148 eerb->head = 0; /* wrap around */ in dasd_eer_write_buffer()
149 BUG_ON(eerb->head > eerb->buffersize); in dasd_eer_write_buffer()
156 static int dasd_eer_read_buffer(struct eerbuffer *eerb, char *data, int count) in dasd_eer_read_buffer() argument
163 finalcount = min(count, dasd_eer_get_filled_bytes(eerb)); in dasd_eer_read_buffer()
167 tailindex = eerb->tail / PAGE_SIZE; in dasd_eer_read_buffer()
168 localtail = eerb->tail % PAGE_SIZE; in dasd_eer_read_buffer()
170 memcpy(nextdata, eerb->buffer[tailindex] + localtail, len); in dasd_eer_read_buffer()
173 eerb->tail += len; in dasd_eer_read_buffer()
174 if (eerb->tail == eerb->buffersize) in dasd_eer_read_buffer()
175 eerb->tail = 0; /* wrap around */ in dasd_eer_read_buffer()
176 BUG_ON(eerb->tail > eerb->buffersize); in dasd_eer_read_buffer()
188 static int dasd_eer_start_record(struct eerbuffer *eerb, int count) in dasd_eer_start_record() argument
192 if (count + sizeof(count) > eerb->buffersize) in dasd_eer_start_record()
194 while (dasd_eer_get_free_bytes(eerb) < count + sizeof(count)) { in dasd_eer_start_record()
195 if (eerb->residual > 0) { in dasd_eer_start_record()
196 eerb->tail += eerb->residual; in dasd_eer_start_record()
197 if (eerb->tail >= eerb->buffersize) in dasd_eer_start_record()
198 eerb->tail -= eerb->buffersize; in dasd_eer_start_record()
199 eerb->residual = -1; in dasd_eer_start_record()
201 dasd_eer_read_buffer(eerb, (char *) &tailcount, in dasd_eer_start_record()
203 eerb->tail += tailcount; in dasd_eer_start_record()
204 if (eerb->tail >= eerb->buffersize) in dasd_eer_start_record()
205 eerb->tail -= eerb->buffersize; in dasd_eer_start_record()
207 dasd_eer_write_buffer(eerb, (char*) &count, sizeof(count)); in dasd_eer_start_record()
302 struct eerbuffer *eerb; in dasd_eer_write_standard_trigger() local
320 list_for_each_entry(eerb, &bufferlist, list) { in dasd_eer_write_standard_trigger()
321 dasd_eer_start_record(eerb, header.total_size); in dasd_eer_write_standard_trigger()
322 dasd_eer_write_buffer(eerb, (char *) &header, sizeof(header)); in dasd_eer_write_standard_trigger()
326 dasd_eer_write_buffer(eerb, sense, 32); in dasd_eer_write_standard_trigger()
328 dasd_eer_write_buffer(eerb, "EOR", 4); in dasd_eer_write_standard_trigger()
346 struct eerbuffer *eerb; in dasd_eer_write_snss_trigger() local
363 list_for_each_entry(eerb, &bufferlist, list) { in dasd_eer_write_snss_trigger()
364 dasd_eer_start_record(eerb, header.total_size); in dasd_eer_write_snss_trigger()
365 dasd_eer_write_buffer(eerb, (char *) &header , sizeof(header)); in dasd_eer_write_snss_trigger()
367 dasd_eer_write_buffer(eerb, cqr->data, SNSS_DATA_SIZE); in dasd_eer_write_snss_trigger()
368 dasd_eer_write_buffer(eerb, "EOR", 4); in dasd_eer_write_snss_trigger()
549 struct eerbuffer *eerb; in dasd_eer_open() local
552 eerb = kzalloc(sizeof(struct eerbuffer), GFP_KERNEL); in dasd_eer_open()
553 if (!eerb) in dasd_eer_open()
555 eerb->buffer_page_count = eer_pages; in dasd_eer_open()
556 if (eerb->buffer_page_count < 1 || in dasd_eer_open()
557 eerb->buffer_page_count > INT_MAX / PAGE_SIZE) { in dasd_eer_open()
558 kfree(eerb); in dasd_eer_open()
564 eerb->buffersize = eerb->buffer_page_count * PAGE_SIZE; in dasd_eer_open()
565 eerb->buffer = kmalloc_array(eerb->buffer_page_count, sizeof(char *), in dasd_eer_open()
567 if (!eerb->buffer) { in dasd_eer_open()
568 kfree(eerb); in dasd_eer_open()
571 if (dasd_eer_allocate_buffer_pages(eerb->buffer, in dasd_eer_open()
572 eerb->buffer_page_count)) { in dasd_eer_open()
573 kfree(eerb->buffer); in dasd_eer_open()
574 kfree(eerb); in dasd_eer_open()
577 filp->private_data = eerb; in dasd_eer_open()
579 list_add(&eerb->list, &bufferlist); in dasd_eer_open()
587 struct eerbuffer *eerb; in dasd_eer_close() local
590 eerb = (struct eerbuffer *) filp->private_data; in dasd_eer_close()
592 list_del(&eerb->list); in dasd_eer_close()
594 dasd_eer_free_buffer_pages(eerb->buffer, eerb->buffer_page_count); in dasd_eer_close()
595 kfree(eerb->buffer); in dasd_eer_close()
596 kfree(eerb); in dasd_eer_close()
607 struct eerbuffer *eerb; in dasd_eer_read() local
609 eerb = (struct eerbuffer *) filp->private_data; in dasd_eer_read()
615 if (eerb->residual < 0) { /* the remainder of this record */ in dasd_eer_read()
617 eerb->residual = 0; in dasd_eer_read()
621 } else if (eerb->residual > 0) { in dasd_eer_read()
623 effective_count = min(eerb->residual, (int) count); in dasd_eer_read()
624 eerb->residual -= effective_count; in dasd_eer_read()
628 tc = dasd_eer_read_buffer(eerb, (char *) &tailcount, in dasd_eer_read()
638 eerb->head != eerb->tail); in dasd_eer_read()
648 eerb->residual = tailcount - effective_count; in dasd_eer_read()
651 tc = dasd_eer_read_buffer(eerb, readbuffer, effective_count); in dasd_eer_read()
669 struct eerbuffer *eerb; in dasd_eer_poll() local
671 eerb = (struct eerbuffer *) filp->private_data; in dasd_eer_poll()
674 if (eerb->head != eerb->tail) in dasd_eer_poll()