ibmvscsi: gadget: at91_udc: remove driver_data direct access of struct device
[safe/jmp/linux-2.6] / drivers / scsi / osst.c
index abef704..acb8358 100644 (file)
@@ -50,6 +50,7 @@ static const char * osst_version = "0.99.4";
 #include <linux/moduleparam.h>
 #include <linux/delay.h>
 #include <linux/jiffies.h>
+#include <linux/smp_lock.h>
 #include <asm/uaccess.h>
 #include <asm/dma.h>
 #include <asm/system.h>
@@ -279,8 +280,8 @@ static int osst_chk_result(struct osst_tape * STp, struct osst_request * SRpnt)
                        static  int     notyetprinted = 1;
 
                        printk(KERN_WARNING
-                            "%s:W: Warning %x (sugg. bt 0x%x, driver bt 0x%x, host bt 0x%x).\n",
-                            name, result, suggestion(result), driver_byte(result) & DRIVER_MASK,
+                            "%s:W: Warning %x (driver bt 0x%x, host bt 0x%x).\n",
+                            name, result, driver_byte(result),
                             host_byte(result));
                        if (notyetprinted) {
                                notyetprinted = 0;
@@ -316,18 +317,25 @@ static int osst_chk_result(struct osst_tape * STp, struct osst_request * SRpnt)
 
 
 /* Wakeup from interrupt */
-static void osst_sleep_done(void *data, char *sense, int result, int resid)
+static void osst_end_async(struct request *req, int update)
 {
-       struct osst_request *SRpnt = data;
+       struct osst_request *SRpnt = req->end_io_data;
        struct osst_tape *STp = SRpnt->stp;
+       struct rq_map_data *mdata = &SRpnt->stp->buffer->map_data;
 
-       memcpy(SRpnt->sense, sense, SCSI_SENSE_BUFFERSIZE);
-       STp->buffer->cmdstat.midlevel_result = SRpnt->result = result;
+       STp->buffer->cmdstat.midlevel_result = SRpnt->result = req->errors;
 #if DEBUG
        STp->write_pending = 0;
 #endif
        if (SRpnt->waiting)
                complete(SRpnt->waiting);
+
+       if (SRpnt->bio) {
+               kfree(mdata->pages);
+               blk_rq_unmap_user(SRpnt->bio);
+       }
+
+       __blk_put_request(req->q, req);
 }
 
 /* osst_request memory management */
@@ -341,6 +349,74 @@ static void osst_release_request(struct osst_request *streq)
        kfree(streq);
 }
 
+static int osst_execute(struct osst_request *SRpnt, const unsigned char *cmd,
+                       int cmd_len, int data_direction, void *buffer, unsigned bufflen,
+                       int use_sg, int timeout, int retries)
+{
+       struct request *req;
+       struct page **pages = NULL;
+       struct rq_map_data *mdata = &SRpnt->stp->buffer->map_data;
+
+       int err = 0;
+       int write = (data_direction == DMA_TO_DEVICE);
+
+       req = blk_get_request(SRpnt->stp->device->request_queue, write, GFP_KERNEL);
+       if (!req)
+               return DRIVER_ERROR << 24;
+
+       req->cmd_type = REQ_TYPE_BLOCK_PC;
+       req->cmd_flags |= REQ_QUIET;
+
+       SRpnt->bio = NULL;
+
+       if (use_sg) {
+               struct scatterlist *sg, *sgl = (struct scatterlist *)buffer;
+               int i;
+
+               pages = kzalloc(use_sg * sizeof(struct page *), GFP_KERNEL);
+               if (!pages)
+                       goto free_req;
+
+               for_each_sg(sgl, sg, use_sg, i)
+                       pages[i] = sg_page(sg);
+
+               mdata->null_mapped = 1;
+
+               mdata->page_order = get_order(sgl[0].length);
+               mdata->nr_entries =
+                       DIV_ROUND_UP(bufflen, PAGE_SIZE << mdata->page_order);
+               mdata->offset = 0;
+
+               err = blk_rq_map_user(req->q, req, mdata, NULL, bufflen, GFP_KERNEL);
+               if (err) {
+                       kfree(pages);
+                       goto free_req;
+               }
+               SRpnt->bio = req->bio;
+               mdata->pages = pages;
+
+       } else if (bufflen) {
+               err = blk_rq_map_kern(req->q, req, buffer, bufflen, GFP_KERNEL);
+               if (err)
+                       goto free_req;
+       }
+
+       req->cmd_len = cmd_len;
+       memset(req->cmd, 0, BLK_MAX_CDB); /* ATAPI hates garbage after CDB */
+       memcpy(req->cmd, cmd, req->cmd_len);
+       req->sense = SRpnt->sense;
+       req->sense_len = 0;
+       req->timeout = timeout;
+       req->retries = retries;
+       req->end_io_data = SRpnt;
+
+       blk_execute_rq_nowait(req->q, NULL, req, 1, osst_end_async);
+       return 0;
+free_req:
+       blk_put_request(req);
+       return DRIVER_ERROR << 24;
+}
+
 /* Do the scsi command. Waits until command performed if do_wait is true.
    Otherwise osst_write_behind_check() is used to check that the command
    has finished. */
@@ -402,8 +478,8 @@ static      struct osst_request * osst_do_scsi(struct osst_request *SRpnt, struct oss
        STp->buffer->cmdstat.have_sense = 0;
        STp->buffer->syscall_result = 0;
 
-       if (scsi_execute_async(STp->device, cmd, COMMAND_SIZE(cmd[0]), direction, bp, bytes,
-                       use_sg, timeout, retries, SRpnt, osst_sleep_done, GFP_KERNEL))
+       if (osst_execute(SRpnt, cmd, COMMAND_SIZE(cmd[0]), direction, bp, bytes,
+                        use_sg, timeout, retries))
                /* could not allocate the buffer or request was too large */
                (STp->buffer)->syscall_result = (-EBUSY);
        else if (do_wait) {
@@ -4359,7 +4435,7 @@ os_bypass:
 
 
 /* Open the device */
-static int os_scsi_tape_open(struct inode * inode, struct file * filp)
+static int __os_scsi_tape_open(struct inode * inode, struct file * filp)
 {
        unsigned short        flags;
        int                   i, b_size, new_session = 0, retval = 0;
@@ -4725,6 +4801,18 @@ err_out:
        return retval;
 }
 
+/* BKL pushdown: spaghetti avoidance wrapper */
+static int os_scsi_tape_open(struct inode * inode, struct file * filp)
+{
+       int ret;
+
+       lock_kernel();
+       ret = __os_scsi_tape_open(inode, filp);
+       unlock_kernel();
+       return ret;
+}
+
+
 
 /* Flush the tape buffer before close */
 static int os_scsi_tape_flush(struct file * filp, fl_owner_t id)
@@ -5273,11 +5361,6 @@ static int enlarge_buffer(struct osst_buffer *STbuffer, int need_dma)
                struct page *page = alloc_pages(priority, (OS_FRAME_SIZE - got <= PAGE_SIZE) ? 0 : order);
                STbuffer->sg[segs].offset = 0;
                if (page == NULL) {
-                       if (OS_FRAME_SIZE - got <= (max_segs - segs) * b_size / 2 && order) {
-                               b_size /= 2;  /* Large enough for the rest of the buffers */
-                               order--;
-                               continue;
-                       }
                        printk(KERN_WARNING "osst :W: Failed to enlarge buffer to %d bytes.\n",
                                                OS_FRAME_SIZE);
 #if DEBUG
@@ -5591,9 +5674,10 @@ static void osst_remove_sysfs_files(struct device_driver *sysfs)
  * sysfs support for accessing ADR header information
  */
 
-static ssize_t osst_adr_rev_show(struct class_device *class_dev, char *buf)
+static ssize_t osst_adr_rev_show(struct device *dev,
+                                struct device_attribute *attr, char *buf)
 {
-       struct osst_tape * STp = (struct osst_tape *) class_get_devdata (class_dev);
+       struct osst_tape * STp = (struct osst_tape *) dev_get_drvdata (dev);
        ssize_t l = 0;
 
        if (STp && STp->header_ok && STp->linux_media)
@@ -5601,11 +5685,13 @@ static ssize_t osst_adr_rev_show(struct class_device *class_dev, char *buf)
        return l;
 }
 
-CLASS_DEVICE_ATTR(ADR_rev, S_IRUGO, osst_adr_rev_show, NULL);
+DEVICE_ATTR(ADR_rev, S_IRUGO, osst_adr_rev_show, NULL);
 
-static ssize_t osst_linux_media_version_show(struct class_device *class_dev, char *buf)
+static ssize_t osst_linux_media_version_show(struct device *dev,
+                                            struct device_attribute *attr,
+                                            char *buf)
 {
-       struct osst_tape * STp = (struct osst_tape *) class_get_devdata (class_dev);
+       struct osst_tape * STp = (struct osst_tape *) dev_get_drvdata (dev);
        ssize_t l = 0;
 
        if (STp && STp->header_ok && STp->linux_media)
@@ -5613,11 +5699,12 @@ static ssize_t osst_linux_media_version_show(struct class_device *class_dev, cha
        return l;
 }
 
-CLASS_DEVICE_ATTR(media_version, S_IRUGO, osst_linux_media_version_show, NULL);
+DEVICE_ATTR(media_version, S_IRUGO, osst_linux_media_version_show, NULL);
 
-static ssize_t osst_capacity_show(struct class_device *class_dev, char *buf)
+static ssize_t osst_capacity_show(struct device *dev,
+                                 struct device_attribute *attr, char *buf)
 {
-       struct osst_tape * STp = (struct osst_tape *) class_get_devdata (class_dev);
+       struct osst_tape * STp = (struct osst_tape *) dev_get_drvdata (dev);
        ssize_t l = 0;
 
        if (STp && STp->header_ok && STp->linux_media)
@@ -5625,11 +5712,13 @@ static ssize_t osst_capacity_show(struct class_device *class_dev, char *buf)
        return l;
 }
 
-CLASS_DEVICE_ATTR(capacity, S_IRUGO, osst_capacity_show, NULL);
+DEVICE_ATTR(capacity, S_IRUGO, osst_capacity_show, NULL);
 
-static ssize_t osst_first_data_ppos_show(struct class_device *class_dev, char *buf)
+static ssize_t osst_first_data_ppos_show(struct device *dev,
+                                        struct device_attribute *attr,
+                                        char *buf)
 {
-       struct osst_tape * STp = (struct osst_tape *) class_get_devdata (class_dev);
+       struct osst_tape * STp = (struct osst_tape *) dev_get_drvdata (dev);
        ssize_t l = 0;
 
        if (STp && STp->header_ok && STp->linux_media)
@@ -5637,11 +5726,13 @@ static ssize_t osst_first_data_ppos_show(struct class_device *class_dev, char *b
        return l;
 }
 
-CLASS_DEVICE_ATTR(BOT_frame, S_IRUGO, osst_first_data_ppos_show, NULL);
+DEVICE_ATTR(BOT_frame, S_IRUGO, osst_first_data_ppos_show, NULL);
 
-static ssize_t osst_eod_frame_ppos_show(struct class_device *class_dev, char *buf)
+static ssize_t osst_eod_frame_ppos_show(struct device *dev,
+                                       struct device_attribute *attr,
+                                       char *buf)
 {
-       struct osst_tape * STp = (struct osst_tape *) class_get_devdata (class_dev);
+       struct osst_tape * STp = (struct osst_tape *) dev_get_drvdata (dev);
        ssize_t l = 0;
 
        if (STp && STp->header_ok && STp->linux_media)
@@ -5649,11 +5740,12 @@ static ssize_t osst_eod_frame_ppos_show(struct class_device *class_dev, char *bu
        return l;
 }
 
-CLASS_DEVICE_ATTR(EOD_frame, S_IRUGO, osst_eod_frame_ppos_show, NULL);
+DEVICE_ATTR(EOD_frame, S_IRUGO, osst_eod_frame_ppos_show, NULL);
 
-static ssize_t osst_filemark_cnt_show(struct class_device *class_dev, char *buf)
+static ssize_t osst_filemark_cnt_show(struct device *dev,
+                                     struct device_attribute *attr, char *buf)
 {
-       struct osst_tape * STp = (struct osst_tape *) class_get_devdata (class_dev);
+       struct osst_tape * STp = (struct osst_tape *) dev_get_drvdata (dev);
        ssize_t l = 0;
 
        if (STp && STp->header_ok && STp->linux_media)
@@ -5661,7 +5753,7 @@ static ssize_t osst_filemark_cnt_show(struct class_device *class_dev, char *buf)
        return l;
 }
 
-CLASS_DEVICE_ATTR(file_count, S_IRUGO, osst_filemark_cnt_show, NULL);
+DEVICE_ATTR(file_count, S_IRUGO, osst_filemark_cnt_show, NULL);
 
 static struct class *osst_sysfs_class;
 
@@ -5678,44 +5770,37 @@ static int osst_sysfs_init(void)
 
 static void osst_sysfs_destroy(dev_t dev)
 {
-       class_device_destroy(osst_sysfs_class, dev);
+       device_destroy(osst_sysfs_class, dev);
 }
 
 static int osst_sysfs_add(dev_t dev, struct device *device, struct osst_tape * STp, char * name)
 {
-       struct class_device *osst_class_member;
+       struct device *osst_member;
        int err;
 
-       osst_class_member = class_device_create(osst_sysfs_class, NULL, dev,
-                                               device, "%s", name);
-       if (IS_ERR(osst_class_member)) {
+       osst_member = device_create(osst_sysfs_class, device, dev, STp,
+                                   "%s", name);
+       if (IS_ERR(osst_member)) {
                printk(KERN_WARNING "osst :W: Unable to add sysfs class member %s\n", name);
-               return PTR_ERR(osst_class_member);
+               return PTR_ERR(osst_member);
        }
 
-       class_set_devdata(osst_class_member, STp);
-       err = class_device_create_file(osst_class_member,
-                                      &class_device_attr_ADR_rev);
+       err = device_create_file(osst_member, &dev_attr_ADR_rev);
        if (err)
                goto err_out;
-       err = class_device_create_file(osst_class_member,
-                                      &class_device_attr_media_version);
+       err = device_create_file(osst_member, &dev_attr_media_version);
        if (err)
                goto err_out;
-       err = class_device_create_file(osst_class_member,
-                                      &class_device_attr_capacity);
+       err = device_create_file(osst_member, &dev_attr_capacity);
        if (err)
                goto err_out;
-       err = class_device_create_file(osst_class_member,
-                                      &class_device_attr_BOT_frame);
+       err = device_create_file(osst_member, &dev_attr_BOT_frame);
        if (err)
                goto err_out;
-       err = class_device_create_file(osst_class_member,
-                                      &class_device_attr_EOD_frame);
+       err = device_create_file(osst_member, &dev_attr_EOD_frame);
        if (err)
                goto err_out;
-       err = class_device_create_file(osst_class_member,
-                                      &class_device_attr_file_count);
+       err = device_create_file(osst_member, &dev_attr_file_count);
        if (err)
                goto err_out;