static int submit(int rw, pgoff_t page_off, void * page) { int error = 0; struct bio * bio; bio = bio_alloc(GFP_ATOMIC,1); if (!bio) return -ENOMEM; bio->bi_sector = page_off * (PAGE_SIZE >> 9); bio_get(bio); bio->bi_bdev = resume_bdev; bio->bi_end_io = end_io; if (bio_add_page(bio, virt_to_page(page), PAGE_SIZE, 0) < PAGE_SIZE) { printk("pmdisk: ERROR: adding page to bio at %ld\n",page_off); error = -EFAULT; goto Done; } if (rw == WRITE) bio_set_pages_dirty(bio); start_io(); submit_bio(rw | (1 << BIO_RW_SYNC), bio); wait_io(); Done: bio_put(bio); return error; }
/* * Write memory with number of blocks to start block */ static void writeblock(unsigned long blk, unsigned long addr, unsigned long blk_count, unsigned long zero_page) { unsigned long blk_end; blk_end = blk + blk_count; if (blk_end >= device.blk_end) panic(EMEM, "Device too small"); ccw_program.wrccw.count = b2m(blk_count); lodata.blk_ct = blk_count; lodata.blk_nr = blk; create_ida_list(ccw_program.ida_list, b2m(blk_count), addr, zero_page); start_io(IPL_SC, &irb, &orb); }
void disk_engine::write(aio_task_ptr& aio) { aio->aio()->type = AIO_Write; return start_io(aio); }
void disk_engine::read(aio_task_ptr& aio) { aio->aio()->type = AIO_Read; return start_io(aio); }
static void handle_control (int fd, struct usb_ctrlrequest *setup) { int status, tmp; __u8 buf [256]; __u16 value, index, length; value = __le16_to_cpu(setup->wValue); index = __le16_to_cpu(setup->wIndex); length = __le16_to_cpu(setup->wLength); if (verbose) fprintf (stderr, "SETUP %02x.%02x " "v%04x i%04x %d\n", setup->bRequestType, setup->bRequest, value, index, length); /* if ((setup->bRequestType & USB_TYPE_MASK) != USB_TYPE_STANDARD) goto special; */ switch (setup->bRequest) { /* usb 2.0 spec ch9 requests */ case USB_REQ_GET_DESCRIPTOR: if (setup->bRequestType != USB_DIR_IN) goto stall; switch (value >> 8) { case USB_DT_STRING: tmp = value & 0x0ff; if (verbose > 1) fprintf (stderr, "... get string %d lang %04x\n", tmp, index); if (tmp != 0 && index != strings.language) goto stall; status = usb_gadget_get_string (&strings, tmp, buf); if (status < 0) goto stall; tmp = status; if (length < tmp) tmp = length; status = write (fd, buf, tmp); if (status < 0) { if (errno == EIDRM) fprintf (stderr, "string timeout\n"); else perror ("write string data"); } else if (status != tmp) { fprintf (stderr, "short string write, %d\n", status); } break; default: goto stall; } return; case USB_REQ_SET_CONFIGURATION: if (setup->bRequestType != USB_DIR_OUT) goto stall; if (verbose) fprintf (stderr, "CONFIG #%d\n", value); /* Kernel is normally waiting for us to finish reconfiguring * the device. * * Some hardware can't, notably older PXA2xx hardware. (With * racey and restrictive config change automagic. PXA 255 is * OK, most PXA 250s aren't. If it has a UDC CFR register, * it can handle deferred response for SET_CONFIG.) To handle * such hardware, don't write code this way ... instead, keep * the endpoints always active and don't rely on seeing any * config change events, either this or SET_INTERFACE. */ switch (value) { case CONFIG_VALUE: start_io (); break; case 0: stop_io (); break; default: /* kernel bug -- "can't happen" */ fprintf (stderr, "? illegal config\n"); goto stall; } /* ... ack (a write would stall) */ status = read (fd, &status, 0); if (status) perror ("ack SET_CONFIGURATION"); return; case USB_REQ_GET_INTERFACE: if (setup->bRequestType != (USB_DIR_IN|USB_RECIP_INTERFACE) || index != 0 || length > 1) goto stall; /* only one altsetting in this driver */ buf [0] = 0; status = write (fd, buf, length); if (status < 0) { if (errno == EIDRM) fprintf (stderr, "GET_INTERFACE timeout\n"); else perror ("write GET_INTERFACE data"); } else if (status != length) { fprintf (stderr, "short GET_INTERFACE write, %d\n", status); } return; case USB_REQ_SET_INTERFACE: if (setup->bRequestType != USB_RECIP_INTERFACE || index != 0 || value != 0) goto stall; /* just reset toggle/halt for the interface's endpoints */ status = 0; if (ioctl (source_fd, GADGETFS_CLEAR_HALT) < 0) { status = errno; perror ("reset source fd"); } if (ioctl (sink_fd, GADGETFS_CLEAR_HALT) < 0) { status = errno; perror ("reset sink fd"); } /* FIXME eventually reset the status endpoint too */ if (status) goto stall; /* ... and ack (a write would stall) */ status = read (fd, &status, 0); if (status) perror ("ack SET_INTERFACE"); return; default: goto stall; } stall: if (verbose) fprintf (stderr, "... protocol stall %02x.%02x\n", setup->bRequestType, setup->bRequest); /* non-iso endpoints are stalled by issuing an i/o request * in the "wrong" direction. ep0 is special only because * the direction isn't fixed. */ if (setup->bRequestType & USB_DIR_IN) status = read (fd, &status, 0); else status = write (fd, &status, 0); if (status != -1) fprintf (stderr, "can't stall ep0 for %02x.%02x\n", setup->bRequestType, setup->bRequest); else if (errno != EL2HLT) perror ("ep0 stall"); }