Lines Matching refs:ch
87 #define ch_printk(prefix, ch, fmt, a...) \ argument
88 sdev_prefix_printk(prefix, (ch)->device, (ch)->name, fmt, ##a)
93 ch_printk(KERN_DEBUG, ch, fmt, ##arg); \
98 ch_printk(level, ch, fmt, ##arg); \
186 ch_do_scsi(scsi_changer *ch, unsigned char *cmd, int cmd_len, in ch_do_scsi() argument
198 result = scsi_execute_req(ch->device, cmd, direction, buffer, in ch_do_scsi()
204 scsi_print_sense_hdr(ch->device, ch->name, &sshdr); in ch_do_scsi()
209 ch->unit_attention = 1; in ch_do_scsi()
221 ch_elem_to_typecode(scsi_changer *ch, u_int elem) in ch_elem_to_typecode() argument
226 if (elem >= ch->firsts[i] && in ch_elem_to_typecode()
227 elem < ch->firsts[i] + in ch_elem_to_typecode()
228 ch->counts[i]) in ch_elem_to_typecode()
235 ch_read_element_status(scsi_changer *ch, u_int elem, char *data) in ch_read_element_status() argument
248 cmd[1] = ((ch->device->lun & 0x7) << 5) | in ch_read_element_status()
249 (ch->voltags ? 0x10 : 0) | in ch_read_element_status()
250 ch_elem_to_typecode(ch,elem); in ch_read_element_status()
255 if (0 == (result = ch_do_scsi(ch, cmd, 12, in ch_read_element_status()
265 if (ch->voltags) { in ch_read_element_status()
266 ch->voltags = 0; in ch_read_element_status()
277 ch_init_elem(scsi_changer *ch) in ch_init_elem() argument
285 cmd[1] = (ch->device->lun & 0x7) << 5; in ch_init_elem()
286 err = ch_do_scsi(ch, cmd, 6, NULL, 0, DMA_NONE); in ch_init_elem()
292 ch_readconfig(scsi_changer *ch) in ch_readconfig() argument
305 cmd[1] = (ch->device->lun & 0x7) << 5; in ch_readconfig()
308 result = ch_do_scsi(ch, cmd, 10, buffer, 255, DMA_FROM_DEVICE); in ch_readconfig()
311 result = ch_do_scsi(ch, cmd, 10, buffer, 255, DMA_FROM_DEVICE); in ch_readconfig()
314 ch->firsts[CHET_MT] = in ch_readconfig()
316 ch->counts[CHET_MT] = in ch_readconfig()
318 ch->firsts[CHET_ST] = in ch_readconfig()
320 ch->counts[CHET_ST] = in ch_readconfig()
322 ch->firsts[CHET_IE] = in ch_readconfig()
324 ch->counts[CHET_IE] = in ch_readconfig()
326 ch->firsts[CHET_DT] = in ch_readconfig()
328 ch->counts[CHET_DT] = in ch_readconfig()
331 ch->firsts[CHET_MT], in ch_readconfig()
332 ch->counts[CHET_MT]); in ch_readconfig()
334 ch->firsts[CHET_ST], in ch_readconfig()
335 ch->counts[CHET_ST]); in ch_readconfig()
337 ch->firsts[CHET_IE], in ch_readconfig()
338 ch->counts[CHET_IE]); in ch_readconfig()
340 ch->firsts[CHET_DT], in ch_readconfig()
341 ch->counts[CHET_DT]); in ch_readconfig()
352 ch->firsts[CHET_V1+i] = vendor_firsts[i]; in ch_readconfig()
353 ch->counts[CHET_V1+i] = vendor_counts[i]; in ch_readconfig()
360 ch->dt = kcalloc(ch->counts[CHET_DT], sizeof(*ch->dt), in ch_readconfig()
363 if (!ch->dt) { in ch_readconfig()
368 for (elem = 0; elem < ch->counts[CHET_DT]; elem++) { in ch_readconfig()
375 elem+ch->firsts[CHET_DT]); in ch_readconfig()
377 (ch,elem+ch->firsts[CHET_DT],data)) { in ch_readconfig()
379 elem+ch->firsts[CHET_DT]); in ch_readconfig()
381 VPRINTK(KERN_INFO, "dt 0x%x: ",elem+ch->firsts[CHET_DT]); in ch_readconfig()
384 ch->dt[elem] = NULL; in ch_readconfig()
387 ch->dt[elem] = NULL; in ch_readconfig()
389 id = ch->device->id; in ch_readconfig()
397 ch->dt[elem] = in ch_readconfig()
398 scsi_device_lookup(ch->device->host, in ch_readconfig()
399 ch->device->channel, in ch_readconfig()
401 if (!ch->dt[elem]) { in ch_readconfig()
406 ch->dt[elem]->vendor, in ch_readconfig()
407 ch->dt[elem]->model, in ch_readconfig()
408 ch->dt[elem]->rev); in ch_readconfig()
412 ch->voltags = 1; in ch_readconfig()
421 ch_position(scsi_changer *ch, u_int trans, u_int elem, int rotate) in ch_position() argument
427 trans = ch->firsts[CHET_MT]; in ch_position()
430 cmd[1] = (ch->device->lun & 0x7) << 5; in ch_position()
436 return ch_do_scsi(ch, cmd, 10, NULL, 0, DMA_NONE); in ch_position()
440 ch_move(scsi_changer *ch, u_int trans, u_int src, u_int dest, int rotate) in ch_move() argument
446 trans = ch->firsts[CHET_MT]; in ch_move()
449 cmd[1] = (ch->device->lun & 0x7) << 5; in ch_move()
457 return ch_do_scsi(ch, cmd, 12, NULL,0, DMA_NONE); in ch_move()
461 ch_exchange(scsi_changer *ch, u_int trans, u_int src, in ch_exchange() argument
469 trans = ch->firsts[CHET_MT]; in ch_exchange()
472 cmd[1] = (ch->device->lun & 0x7) << 5; in ch_exchange()
483 return ch_do_scsi(ch, cmd, 12, NULL, 0, DMA_NONE); in ch_exchange()
503 ch_set_voltag(scsi_changer *ch, u_int elem, in ch_set_voltag() argument
520 cmd[1] = ((ch->device->lun & 0x7) << 5) | in ch_set_voltag()
521 ch_elem_to_typecode(ch,elem); in ch_set_voltag()
533 result = ch_do_scsi(ch, cmd, 12, buffer, 256, DMA_TO_DEVICE); in ch_set_voltag()
538 static int ch_gstatus(scsi_changer *ch, int type, unsigned char __user *dest) in ch_gstatus() argument
544 mutex_lock(&ch->lock); in ch_gstatus()
545 for (i = 0; i < ch->counts[type]; i++) { in ch_gstatus()
547 (ch, ch->firsts[type]+i,data)) { in ch_gstatus()
554 ch->firsts[type]+i, in ch_gstatus()
557 (ch, ch->firsts[type]+i,data); in ch_gstatus()
561 mutex_unlock(&ch->lock); in ch_gstatus()
569 scsi_changer *ch = container_of(ref, scsi_changer, ref); in ch_destroy() local
571 ch->device = NULL; in ch_destroy()
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
594 ch = idr_find(&ch_index_idr, minor); in ch_open()
596 if (ch == NULL || !kref_get_unless_zero(&ch->ref)) { in ch_open()
601 if (scsi_device_get(ch->device)) { in ch_open()
602 kref_put(&ch->ref, ch_destroy); in ch_open()
606 mutex_lock(&ch->lock); in ch_open()
607 file->private_data = ch; in ch_open()
608 mutex_unlock(&ch->lock); in ch_open()
613 ch_checkrange(scsi_changer *ch, unsigned int type, unsigned int unit) in ch_checkrange() argument
615 if (type >= CH_TYPES || unit >= ch->counts[type]) in ch_checkrange()
623 scsi_changer *ch = file->private_data; in ch_ioctl() local
627 retval = scsi_ioctl_block_when_processing_errors(ch->device, cmd, in ch_ioctl()
638 params.cp_npickers = ch->counts[CHET_MT]; in ch_ioctl()
639 params.cp_nslots = ch->counts[CHET_ST]; in ch_ioctl()
640 params.cp_nportals = ch->counts[CHET_IE]; in ch_ioctl()
641 params.cp_ndrives = ch->counts[CHET_DT]; in ch_ioctl()
652 if (ch->counts[CHET_V1]) { in ch_ioctl()
653 vparams.cvp_n1 = ch->counts[CHET_V1]; in ch_ioctl()
656 if (ch->counts[CHET_V2]) { in ch_ioctl()
657 vparams.cvp_n2 = ch->counts[CHET_V2]; in ch_ioctl()
660 if (ch->counts[CHET_V3]) { in ch_ioctl()
661 vparams.cvp_n3 = ch->counts[CHET_V3]; in ch_ioctl()
664 if (ch->counts[CHET_V4]) { in ch_ioctl()
665 vparams.cvp_n4 = ch->counts[CHET_V4]; in ch_ioctl()
680 if (0 != ch_checkrange(ch, pos.cp_type, pos.cp_unit)) { in ch_ioctl()
684 mutex_lock(&ch->lock); in ch_ioctl()
685 retval = ch_position(ch,0, in ch_ioctl()
686 ch->firsts[pos.cp_type] + pos.cp_unit, in ch_ioctl()
688 mutex_unlock(&ch->lock); in ch_ioctl()
699 if (0 != ch_checkrange(ch, mv.cm_fromtype, mv.cm_fromunit) || in ch_ioctl()
700 0 != ch_checkrange(ch, mv.cm_totype, mv.cm_tounit )) { in ch_ioctl()
705 mutex_lock(&ch->lock); in ch_ioctl()
706 retval = ch_move(ch,0, in ch_ioctl()
707 ch->firsts[mv.cm_fromtype] + mv.cm_fromunit, in ch_ioctl()
708 ch->firsts[mv.cm_totype] + mv.cm_tounit, in ch_ioctl()
710 mutex_unlock(&ch->lock); in ch_ioctl()
721 if (0 != ch_checkrange(ch, mv.ce_srctype, mv.ce_srcunit ) || in ch_ioctl()
722 0 != ch_checkrange(ch, mv.ce_fdsttype, mv.ce_fdstunit) || in ch_ioctl()
723 0 != ch_checkrange(ch, mv.ce_sdsttype, mv.ce_sdstunit)) { in ch_ioctl()
728 mutex_lock(&ch->lock); in ch_ioctl()
730 (ch,0, in ch_ioctl()
731 ch->firsts[mv.ce_srctype] + mv.ce_srcunit, in ch_ioctl()
732 ch->firsts[mv.ce_fdsttype] + mv.ce_fdstunit, in ch_ioctl()
733 ch->firsts[mv.ce_sdsttype] + mv.ce_sdstunit, in ch_ioctl()
735 mutex_unlock(&ch->lock); in ch_ioctl()
748 return ch_gstatus(ch, ces.ces_type, ces.ces_data); in ch_ioctl()
762 if (0 != ch_checkrange(ch, cge.cge_type, cge.cge_unit)) in ch_ioctl()
764 elem = ch->firsts[cge.cge_type] + cge.cge_unit; in ch_ioctl()
769 mutex_lock(&ch->lock); in ch_ioctl()
774 ch_cmd[1] = ((ch->device->lun & 0x7) << 5) | in ch_ioctl()
775 (ch->voltags ? 0x10 : 0) | in ch_ioctl()
776 ch_elem_to_typecode(ch,elem); in ch_ioctl()
782 result = ch_do_scsi(ch, ch_cmd, 12, in ch_ioctl()
796 if (elem >= ch->firsts[i] && in ch_ioctl()
797 elem < ch->firsts[i] + ch->counts[i]) { in ch_ioctl()
799 cge.cge_srcunit = elem-ch->firsts[i]; in ch_ioctl()
816 } else if (ch->voltags) { in ch_ioctl()
817 ch->voltags = 0; in ch_ioctl()
822 mutex_unlock(&ch->lock); in ch_ioctl()
831 mutex_lock(&ch->lock); in ch_ioctl()
832 retval = ch_init_elem(ch); in ch_ioctl()
833 mutex_unlock(&ch->lock); in ch_ioctl()
845 if (0 != ch_checkrange(ch, csv.csv_type, csv.csv_unit)) { in ch_ioctl()
849 elem = ch->firsts[csv.csv_type] + csv.csv_unit; in ch_ioctl()
850 mutex_lock(&ch->lock); in ch_ioctl()
851 retval = ch_set_voltag(ch, elem, in ch_ioctl()
855 mutex_unlock(&ch->lock); in ch_ioctl()
860 return scsi_ioctl(ch->device, cmd, argp); in ch_ioctl()
876 scsi_changer *ch = file->private_data; in ch_ioctl_compat() local
877 int retval = scsi_ioctl_block_when_processing_errors(ch->device, cmd, in ch_ioctl_compat()
904 return ch_gstatus(ch, ces32.ces_type, data); in ch_ioctl_compat()
907 return scsi_compat_ioctl(ch->device, cmd, compat_ptr(arg)); in ch_ioctl_compat()
920 scsi_changer *ch; in ch_probe() local
925 ch = kzalloc(sizeof(*ch), GFP_KERNEL); in ch_probe()
926 if (NULL == ch) in ch_probe()
931 ret = idr_alloc(&ch_index_idr, ch, 0, CH_MAX_DEVS + 1, GFP_NOWAIT); in ch_probe()
941 ch->minor = ret; in ch_probe()
942 sprintf(ch->name,"ch%d",ch->minor); in ch_probe()
946 ch->minor); in ch_probe()
950 mutex_init(&ch->lock); in ch_probe()
951 kref_init(&ch->ref); in ch_probe()
952 ch->device = sd; in ch_probe()
954 MKDEV(SCSI_CHANGER_MAJOR, ch->minor), ch, in ch_probe()
955 "s%s", ch->name); in ch_probe()
958 ch->minor); in ch_probe()
963 mutex_lock(&ch->lock); in ch_probe()
964 ret = ch_readconfig(ch); in ch_probe()
966 mutex_unlock(&ch->lock); in ch_probe()
970 ch_init_elem(ch); in ch_probe()
972 mutex_unlock(&ch->lock); in ch_probe()
973 dev_set_drvdata(dev, ch); in ch_probe()
974 sdev_printk(KERN_INFO, sd, "Attached scsi changer %s\n", ch->name); in ch_probe()
978 device_destroy(ch_sysfs_class, MKDEV(SCSI_CHANGER_MAJOR, ch->minor)); in ch_probe()
982 idr_remove(&ch_index_idr, ch->minor); in ch_probe()
984 kfree(ch); in ch_probe()
990 scsi_changer *ch = dev_get_drvdata(dev); in ch_remove() local
993 idr_remove(&ch_index_idr, ch->minor); in ch_remove()
997 device_destroy(ch_sysfs_class, MKDEV(SCSI_CHANGER_MAJOR,ch->minor)); in ch_remove()
998 scsi_device_put(ch->device); in ch_remove()
999 kref_put(&ch->ref, ch_destroy); in ch_remove()