Lines Matching refs:ch
88 #define ch_printk(prefix, ch, fmt, a...) \ argument
89 sdev_prefix_printk(prefix, (ch)->device, (ch)->name, fmt, ##a)
94 ch_printk(KERN_DEBUG, ch, fmt, ##arg); \
99 ch_printk(level, ch, fmt, ##arg); \
187 ch_do_scsi(scsi_changer *ch, unsigned char *cmd, int cmd_len, in ch_do_scsi() argument
199 result = scsi_execute_req(ch->device, cmd, direction, buffer, in ch_do_scsi()
205 scsi_print_sense_hdr(ch->device, ch->name, &sshdr); in ch_do_scsi()
210 ch->unit_attention = 1; in ch_do_scsi()
222 ch_elem_to_typecode(scsi_changer *ch, u_int elem) in ch_elem_to_typecode() argument
227 if (elem >= ch->firsts[i] && in ch_elem_to_typecode()
228 elem < ch->firsts[i] + in ch_elem_to_typecode()
229 ch->counts[i]) in ch_elem_to_typecode()
236 ch_read_element_status(scsi_changer *ch, u_int elem, char *data) in ch_read_element_status() argument
249 cmd[1] = ((ch->device->lun & 0x7) << 5) | in ch_read_element_status()
250 (ch->voltags ? 0x10 : 0) | in ch_read_element_status()
251 ch_elem_to_typecode(ch,elem); in ch_read_element_status()
256 if (0 == (result = ch_do_scsi(ch, cmd, 12, in ch_read_element_status()
266 if (ch->voltags) { in ch_read_element_status()
267 ch->voltags = 0; in ch_read_element_status()
278 ch_init_elem(scsi_changer *ch) in ch_init_elem() argument
286 cmd[1] = (ch->device->lun & 0x7) << 5; in ch_init_elem()
287 err = ch_do_scsi(ch, cmd, 6, NULL, 0, DMA_NONE); in ch_init_elem()
293 ch_readconfig(scsi_changer *ch) in ch_readconfig() argument
306 cmd[1] = (ch->device->lun & 0x7) << 5; in ch_readconfig()
309 result = ch_do_scsi(ch, cmd, 10, buffer, 255, DMA_FROM_DEVICE); in ch_readconfig()
312 result = ch_do_scsi(ch, cmd, 10, buffer, 255, DMA_FROM_DEVICE); in ch_readconfig()
315 ch->firsts[CHET_MT] = in ch_readconfig()
317 ch->counts[CHET_MT] = in ch_readconfig()
319 ch->firsts[CHET_ST] = in ch_readconfig()
321 ch->counts[CHET_ST] = in ch_readconfig()
323 ch->firsts[CHET_IE] = in ch_readconfig()
325 ch->counts[CHET_IE] = in ch_readconfig()
327 ch->firsts[CHET_DT] = in ch_readconfig()
329 ch->counts[CHET_DT] = in ch_readconfig()
332 ch->firsts[CHET_MT], in ch_readconfig()
333 ch->counts[CHET_MT]); in ch_readconfig()
335 ch->firsts[CHET_ST], in ch_readconfig()
336 ch->counts[CHET_ST]); in ch_readconfig()
338 ch->firsts[CHET_IE], in ch_readconfig()
339 ch->counts[CHET_IE]); in ch_readconfig()
341 ch->firsts[CHET_DT], in ch_readconfig()
342 ch->counts[CHET_DT]); in ch_readconfig()
353 ch->firsts[CHET_V1+i] = vendor_firsts[i]; in ch_readconfig()
354 ch->counts[CHET_V1+i] = vendor_counts[i]; in ch_readconfig()
361 ch->dt = kcalloc(ch->counts[CHET_DT], sizeof(*ch->dt), in ch_readconfig()
364 if (!ch->dt) { in ch_readconfig()
369 for (elem = 0; elem < ch->counts[CHET_DT]; elem++) { in ch_readconfig()
376 elem+ch->firsts[CHET_DT]); in ch_readconfig()
378 (ch,elem+ch->firsts[CHET_DT],data)) { in ch_readconfig()
380 elem+ch->firsts[CHET_DT]); in ch_readconfig()
382 VPRINTK(KERN_INFO, "dt 0x%x: ",elem+ch->firsts[CHET_DT]); in ch_readconfig()
385 ch->dt[elem] = NULL; in ch_readconfig()
388 ch->dt[elem] = NULL; in ch_readconfig()
390 id = ch->device->id; in ch_readconfig()
398 ch->dt[elem] = in ch_readconfig()
399 scsi_device_lookup(ch->device->host, in ch_readconfig()
400 ch->device->channel, in ch_readconfig()
402 if (!ch->dt[elem]) { in ch_readconfig()
407 ch->dt[elem]->vendor, in ch_readconfig()
408 ch->dt[elem]->model, in ch_readconfig()
409 ch->dt[elem]->rev); in ch_readconfig()
413 ch->voltags = 1; in ch_readconfig()
422 ch_position(scsi_changer *ch, u_int trans, u_int elem, int rotate) in ch_position() argument
428 trans = ch->firsts[CHET_MT]; in ch_position()
431 cmd[1] = (ch->device->lun & 0x7) << 5; in ch_position()
437 return ch_do_scsi(ch, cmd, 10, NULL, 0, DMA_NONE); in ch_position()
441 ch_move(scsi_changer *ch, u_int trans, u_int src, u_int dest, int rotate) in ch_move() argument
447 trans = ch->firsts[CHET_MT]; in ch_move()
450 cmd[1] = (ch->device->lun & 0x7) << 5; in ch_move()
458 return ch_do_scsi(ch, cmd, 12, NULL,0, DMA_NONE); in ch_move()
462 ch_exchange(scsi_changer *ch, u_int trans, u_int src, in ch_exchange() argument
470 trans = ch->firsts[CHET_MT]; in ch_exchange()
473 cmd[1] = (ch->device->lun & 0x7) << 5; in ch_exchange()
484 return ch_do_scsi(ch, cmd, 12, NULL, 0, DMA_NONE); in ch_exchange()
504 ch_set_voltag(scsi_changer *ch, u_int elem, in ch_set_voltag() argument
521 cmd[1] = ((ch->device->lun & 0x7) << 5) | in ch_set_voltag()
522 ch_elem_to_typecode(ch,elem); in ch_set_voltag()
534 result = ch_do_scsi(ch, cmd, 12, buffer, 256, DMA_TO_DEVICE); in ch_set_voltag()
539 static int ch_gstatus(scsi_changer *ch, int type, unsigned char __user *dest) in ch_gstatus() argument
545 mutex_lock(&ch->lock); in ch_gstatus()
546 for (i = 0; i < ch->counts[type]; i++) { in ch_gstatus()
548 (ch, ch->firsts[type]+i,data)) { in ch_gstatus()
555 ch->firsts[type]+i, in ch_gstatus()
558 (ch, ch->firsts[type]+i,data); in ch_gstatus()
562 mutex_unlock(&ch->lock); in ch_gstatus()
570 scsi_changer *ch = container_of(ref, scsi_changer, ref); in ch_destroy() local
572 kfree(ch->dt); in ch_destroy()
573 kfree(ch); in ch_destroy()
579 scsi_changer *ch = file->private_data; in ch_release() local
581 scsi_device_put(ch->device); in ch_release()
583 kref_put(&ch->ref, ch_destroy); in ch_release()
590 scsi_changer *ch; in ch_open() local
595 ch = idr_find(&ch_index_idr, minor); in ch_open()
597 if (NULL == ch || scsi_device_get(ch->device)) { in ch_open()
602 kref_get(&ch->ref); in ch_open()
605 file->private_data = ch; in ch_open()
611 ch_checkrange(scsi_changer *ch, unsigned int type, unsigned int unit) in ch_checkrange() argument
613 if (type >= CH_TYPES || unit >= ch->counts[type]) in ch_checkrange()
621 scsi_changer *ch = file->private_data; in ch_ioctl() local
625 retval = scsi_ioctl_block_when_processing_errors(ch->device, cmd, in ch_ioctl()
636 params.cp_npickers = ch->counts[CHET_MT]; in ch_ioctl()
637 params.cp_nslots = ch->counts[CHET_ST]; in ch_ioctl()
638 params.cp_nportals = ch->counts[CHET_IE]; in ch_ioctl()
639 params.cp_ndrives = ch->counts[CHET_DT]; in ch_ioctl()
650 if (ch->counts[CHET_V1]) { in ch_ioctl()
651 vparams.cvp_n1 = ch->counts[CHET_V1]; in ch_ioctl()
654 if (ch->counts[CHET_V2]) { in ch_ioctl()
655 vparams.cvp_n2 = ch->counts[CHET_V2]; in ch_ioctl()
658 if (ch->counts[CHET_V3]) { in ch_ioctl()
659 vparams.cvp_n3 = ch->counts[CHET_V3]; in ch_ioctl()
662 if (ch->counts[CHET_V4]) { in ch_ioctl()
663 vparams.cvp_n4 = ch->counts[CHET_V4]; in ch_ioctl()
678 if (0 != ch_checkrange(ch, pos.cp_type, pos.cp_unit)) { in ch_ioctl()
682 mutex_lock(&ch->lock); in ch_ioctl()
683 retval = ch_position(ch,0, in ch_ioctl()
684 ch->firsts[pos.cp_type] + pos.cp_unit, in ch_ioctl()
686 mutex_unlock(&ch->lock); in ch_ioctl()
697 if (0 != ch_checkrange(ch, mv.cm_fromtype, mv.cm_fromunit) || in ch_ioctl()
698 0 != ch_checkrange(ch, mv.cm_totype, mv.cm_tounit )) { in ch_ioctl()
703 mutex_lock(&ch->lock); in ch_ioctl()
704 retval = ch_move(ch,0, in ch_ioctl()
705 ch->firsts[mv.cm_fromtype] + mv.cm_fromunit, in ch_ioctl()
706 ch->firsts[mv.cm_totype] + mv.cm_tounit, in ch_ioctl()
708 mutex_unlock(&ch->lock); in ch_ioctl()
719 if (0 != ch_checkrange(ch, mv.ce_srctype, mv.ce_srcunit ) || in ch_ioctl()
720 0 != ch_checkrange(ch, mv.ce_fdsttype, mv.ce_fdstunit) || in ch_ioctl()
721 0 != ch_checkrange(ch, mv.ce_sdsttype, mv.ce_sdstunit)) { in ch_ioctl()
726 mutex_lock(&ch->lock); in ch_ioctl()
728 (ch,0, in ch_ioctl()
729 ch->firsts[mv.ce_srctype] + mv.ce_srcunit, in ch_ioctl()
730 ch->firsts[mv.ce_fdsttype] + mv.ce_fdstunit, in ch_ioctl()
731 ch->firsts[mv.ce_sdsttype] + mv.ce_sdstunit, in ch_ioctl()
733 mutex_unlock(&ch->lock); in ch_ioctl()
746 return ch_gstatus(ch, ces.ces_type, ces.ces_data); in ch_ioctl()
760 if (0 != ch_checkrange(ch, cge.cge_type, cge.cge_unit)) in ch_ioctl()
762 elem = ch->firsts[cge.cge_type] + cge.cge_unit; in ch_ioctl()
767 mutex_lock(&ch->lock); in ch_ioctl()
772 ch_cmd[1] = ((ch->device->lun & 0x7) << 5) | in ch_ioctl()
773 (ch->voltags ? 0x10 : 0) | in ch_ioctl()
774 ch_elem_to_typecode(ch,elem); in ch_ioctl()
780 result = ch_do_scsi(ch, ch_cmd, 12, in ch_ioctl()
794 if (elem >= ch->firsts[i] && in ch_ioctl()
795 elem < ch->firsts[i] + ch->counts[i]) { in ch_ioctl()
797 cge.cge_srcunit = elem-ch->firsts[i]; in ch_ioctl()
814 } else if (ch->voltags) { in ch_ioctl()
815 ch->voltags = 0; in ch_ioctl()
820 mutex_unlock(&ch->lock); in ch_ioctl()
829 mutex_lock(&ch->lock); in ch_ioctl()
830 retval = ch_init_elem(ch); in ch_ioctl()
831 mutex_unlock(&ch->lock); in ch_ioctl()
843 if (0 != ch_checkrange(ch, csv.csv_type, csv.csv_unit)) { in ch_ioctl()
847 elem = ch->firsts[csv.csv_type] + csv.csv_unit; in ch_ioctl()
848 mutex_lock(&ch->lock); in ch_ioctl()
849 retval = ch_set_voltag(ch, elem, in ch_ioctl()
853 mutex_unlock(&ch->lock); in ch_ioctl()
858 return scsi_ioctl(ch->device, cmd, argp); in ch_ioctl()
874 scsi_changer *ch = file->private_data; in ch_ioctl_compat() local
898 return ch_gstatus(ch, ces32.ces_type, data); in ch_ioctl_compat()
915 scsi_changer *ch; in ch_probe() local
920 ch = kzalloc(sizeof(*ch), GFP_KERNEL); in ch_probe()
921 if (NULL == ch) in ch_probe()
926 ret = idr_alloc(&ch_index_idr, ch, 0, CH_MAX_DEVS + 1, GFP_NOWAIT); in ch_probe()
936 ch->minor = ret; in ch_probe()
937 sprintf(ch->name,"ch%d",ch->minor); in ch_probe()
940 MKDEV(SCSI_CHANGER_MAJOR, ch->minor), ch, in ch_probe()
941 "s%s", ch->name); in ch_probe()
944 ch->minor); in ch_probe()
949 mutex_init(&ch->lock); in ch_probe()
950 kref_init(&ch->ref); in ch_probe()
951 ch->device = sd; in ch_probe()
952 ret = ch_readconfig(ch); in ch_probe()
956 ch_init_elem(ch); in ch_probe()
958 dev_set_drvdata(dev, ch); in ch_probe()
959 sdev_printk(KERN_INFO, sd, "Attached scsi changer %s\n", ch->name); in ch_probe()
963 device_destroy(ch_sysfs_class, MKDEV(SCSI_CHANGER_MAJOR, ch->minor)); in ch_probe()
965 idr_remove(&ch_index_idr, ch->minor); in ch_probe()
967 kfree(ch); in ch_probe()
973 scsi_changer *ch = dev_get_drvdata(dev); in ch_remove() local
976 idr_remove(&ch_index_idr, ch->minor); in ch_remove()
979 device_destroy(ch_sysfs_class, MKDEV(SCSI_CHANGER_MAJOR,ch->minor)); in ch_remove()
980 kref_put(&ch->ref, ch_destroy); in ch_remove()