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
200 result = scsi_execute_cmd(ch->device, cmd, op, buffer, buflength, in ch_do_scsi()
206 scsi_print_sense_hdr(ch->device, ch->name, &sshdr); in ch_do_scsi()
211 ch->unit_attention = 1; in ch_do_scsi()
223 ch_elem_to_typecode(scsi_changer *ch, u_int elem) in ch_elem_to_typecode() argument
228 if (elem >= ch->firsts[i] && in ch_elem_to_typecode()
229 elem < ch->firsts[i] + in ch_elem_to_typecode()
230 ch->counts[i]) in ch_elem_to_typecode()
237 ch_read_element_status(scsi_changer *ch, u_int elem, char *data) in ch_read_element_status() argument
250 cmd[1] = ((ch->device->lun & 0x7) << 5) | in ch_read_element_status()
251 (ch->voltags ? 0x10 : 0) | in ch_read_element_status()
252 ch_elem_to_typecode(ch,elem); in ch_read_element_status()
257 if (0 == (result = ch_do_scsi(ch, cmd, 12, in ch_read_element_status()
267 if (ch->voltags) { in ch_read_element_status()
268 ch->voltags = 0; in ch_read_element_status()
279 ch_init_elem(scsi_changer *ch) in ch_init_elem() argument
287 cmd[1] = (ch->device->lun & 0x7) << 5; in ch_init_elem()
288 err = ch_do_scsi(ch, cmd, 6, NULL, 0, REQ_OP_DRV_IN); in ch_init_elem()
294 ch_readconfig(scsi_changer *ch) in ch_readconfig() argument
307 cmd[1] = (ch->device->lun & 0x7) << 5; in ch_readconfig()
310 result = ch_do_scsi(ch, cmd, 10, buffer, 255, REQ_OP_DRV_IN); in ch_readconfig()
313 result = ch_do_scsi(ch, cmd, 10, buffer, 255, REQ_OP_DRV_IN); in ch_readconfig()
316 ch->firsts[CHET_MT] = in ch_readconfig()
318 ch->counts[CHET_MT] = in ch_readconfig()
320 ch->firsts[CHET_ST] = in ch_readconfig()
322 ch->counts[CHET_ST] = in ch_readconfig()
324 ch->firsts[CHET_IE] = in ch_readconfig()
326 ch->counts[CHET_IE] = in ch_readconfig()
328 ch->firsts[CHET_DT] = in ch_readconfig()
330 ch->counts[CHET_DT] = in ch_readconfig()
333 ch->firsts[CHET_MT], in ch_readconfig()
334 ch->counts[CHET_MT]); in ch_readconfig()
336 ch->firsts[CHET_ST], in ch_readconfig()
337 ch->counts[CHET_ST]); in ch_readconfig()
339 ch->firsts[CHET_IE], in ch_readconfig()
340 ch->counts[CHET_IE]); in ch_readconfig()
342 ch->firsts[CHET_DT], in ch_readconfig()
343 ch->counts[CHET_DT]); in ch_readconfig()
354 ch->firsts[CHET_V1+i] = vendor_firsts[i]; in ch_readconfig()
355 ch->counts[CHET_V1+i] = vendor_counts[i]; in ch_readconfig()
362 ch->dt = kcalloc(ch->counts[CHET_DT], sizeof(*ch->dt), in ch_readconfig()
365 if (!ch->dt) { in ch_readconfig()
370 for (elem = 0; elem < ch->counts[CHET_DT]; elem++) { in ch_readconfig()
377 elem+ch->firsts[CHET_DT]); in ch_readconfig()
379 (ch,elem+ch->firsts[CHET_DT],data)) { in ch_readconfig()
381 elem+ch->firsts[CHET_DT]); in ch_readconfig()
383 VPRINTK(KERN_INFO, "dt 0x%x: ",elem+ch->firsts[CHET_DT]); in ch_readconfig()
386 ch->dt[elem] = NULL; in ch_readconfig()
389 ch->dt[elem] = NULL; in ch_readconfig()
391 id = ch->device->id; in ch_readconfig()
399 ch->dt[elem] = in ch_readconfig()
400 scsi_device_lookup(ch->device->host, in ch_readconfig()
401 ch->device->channel, in ch_readconfig()
403 if (!ch->dt[elem]) { in ch_readconfig()
408 ch->dt[elem]->vendor, in ch_readconfig()
409 ch->dt[elem]->model, in ch_readconfig()
410 ch->dt[elem]->rev); in ch_readconfig()
414 ch->voltags = 1; in ch_readconfig()
423 ch_position(scsi_changer *ch, u_int trans, u_int elem, int rotate) in ch_position() argument
429 trans = ch->firsts[CHET_MT]; in ch_position()
432 cmd[1] = (ch->device->lun & 0x7) << 5; in ch_position()
438 return ch_do_scsi(ch, cmd, 10, NULL, 0, REQ_OP_DRV_IN); in ch_position()
442 ch_move(scsi_changer *ch, u_int trans, u_int src, u_int dest, int rotate) in ch_move() argument
448 trans = ch->firsts[CHET_MT]; in ch_move()
451 cmd[1] = (ch->device->lun & 0x7) << 5; in ch_move()
459 return ch_do_scsi(ch, cmd, 12, NULL, 0, REQ_OP_DRV_IN); in ch_move()
463 ch_exchange(scsi_changer *ch, u_int trans, u_int src, in ch_exchange() argument
471 trans = ch->firsts[CHET_MT]; in ch_exchange()
474 cmd[1] = (ch->device->lun & 0x7) << 5; in ch_exchange()
485 return ch_do_scsi(ch, cmd, 12, NULL, 0, REQ_OP_DRV_IN); in ch_exchange()
505 ch_set_voltag(scsi_changer *ch, u_int elem, in ch_set_voltag() argument
522 cmd[1] = ((ch->device->lun & 0x7) << 5) | in ch_set_voltag()
523 ch_elem_to_typecode(ch,elem); in ch_set_voltag()
535 result = ch_do_scsi(ch, cmd, 12, buffer, 256, REQ_OP_DRV_OUT); in ch_set_voltag()
540 static int ch_gstatus(scsi_changer *ch, int type, unsigned char __user *dest) in ch_gstatus() argument
546 mutex_lock(&ch->lock); in ch_gstatus()
547 for (i = 0; i < ch->counts[type]; i++) { in ch_gstatus()
549 (ch, ch->firsts[type]+i,data)) { in ch_gstatus()
556 ch->firsts[type]+i, in ch_gstatus()
559 (ch, ch->firsts[type]+i,data); in ch_gstatus()
563 mutex_unlock(&ch->lock); in ch_gstatus()
571 scsi_changer *ch = container_of(ref, scsi_changer, ref); in ch_destroy() local
573 ch->device = NULL; in ch_destroy()
574 kfree(ch->dt); in ch_destroy()
575 kfree(ch); in ch_destroy()
581 scsi_changer *ch = file->private_data; in ch_release() local
583 scsi_device_put(ch->device); in ch_release()
585 kref_put(&ch->ref, ch_destroy); in ch_release()
592 scsi_changer *ch; in ch_open() local
596 ch = idr_find(&ch_index_idr, minor); in ch_open()
598 if (ch == NULL || !kref_get_unless_zero(&ch->ref)) { in ch_open()
603 if (scsi_device_get(ch->device)) { in ch_open()
604 kref_put(&ch->ref, ch_destroy); in ch_open()
608 mutex_lock(&ch->lock); in ch_open()
609 file->private_data = ch; in ch_open()
610 mutex_unlock(&ch->lock); in ch_open()
615 ch_checkrange(scsi_changer *ch, unsigned int type, unsigned int unit) in ch_checkrange() argument
617 if (type >= CH_TYPES || unit >= ch->counts[type]) in ch_checkrange()
631 scsi_changer *ch = file->private_data; in ch_ioctl() local
635 retval = scsi_ioctl_block_when_processing_errors(ch->device, cmd, in ch_ioctl()
646 params.cp_npickers = ch->counts[CHET_MT]; in ch_ioctl()
647 params.cp_nslots = ch->counts[CHET_ST]; in ch_ioctl()
648 params.cp_nportals = ch->counts[CHET_IE]; in ch_ioctl()
649 params.cp_ndrives = ch->counts[CHET_DT]; in ch_ioctl()
660 if (ch->counts[CHET_V1]) { in ch_ioctl()
661 vparams.cvp_n1 = ch->counts[CHET_V1]; in ch_ioctl()
664 if (ch->counts[CHET_V2]) { in ch_ioctl()
665 vparams.cvp_n2 = ch->counts[CHET_V2]; in ch_ioctl()
668 if (ch->counts[CHET_V3]) { in ch_ioctl()
669 vparams.cvp_n3 = ch->counts[CHET_V3]; in ch_ioctl()
672 if (ch->counts[CHET_V4]) { in ch_ioctl()
673 vparams.cvp_n4 = ch->counts[CHET_V4]; in ch_ioctl()
688 if (0 != ch_checkrange(ch, pos.cp_type, pos.cp_unit)) { in ch_ioctl()
692 mutex_lock(&ch->lock); in ch_ioctl()
693 retval = ch_position(ch,0, in ch_ioctl()
694 ch->firsts[pos.cp_type] + pos.cp_unit, in ch_ioctl()
696 mutex_unlock(&ch->lock); in ch_ioctl()
707 if (0 != ch_checkrange(ch, mv.cm_fromtype, mv.cm_fromunit) || in ch_ioctl()
708 0 != ch_checkrange(ch, mv.cm_totype, mv.cm_tounit )) { in ch_ioctl()
713 mutex_lock(&ch->lock); in ch_ioctl()
714 retval = ch_move(ch,0, in ch_ioctl()
715 ch->firsts[mv.cm_fromtype] + mv.cm_fromunit, in ch_ioctl()
716 ch->firsts[mv.cm_totype] + mv.cm_tounit, in ch_ioctl()
718 mutex_unlock(&ch->lock); in ch_ioctl()
729 if (0 != ch_checkrange(ch, mv.ce_srctype, mv.ce_srcunit ) || in ch_ioctl()
730 0 != ch_checkrange(ch, mv.ce_fdsttype, mv.ce_fdstunit) || in ch_ioctl()
731 0 != ch_checkrange(ch, mv.ce_sdsttype, mv.ce_sdstunit)) { in ch_ioctl()
736 mutex_lock(&ch->lock); in ch_ioctl()
738 (ch,0, in ch_ioctl()
739 ch->firsts[mv.ce_srctype] + mv.ce_srcunit, in ch_ioctl()
740 ch->firsts[mv.ce_fdsttype] + mv.ce_fdstunit, in ch_ioctl()
741 ch->firsts[mv.ce_sdsttype] + mv.ce_sdstunit, in ch_ioctl()
743 mutex_unlock(&ch->lock); in ch_ioctl()
756 return ch_gstatus(ch, ces.ces_type, ces.ces_data); in ch_ioctl()
768 return ch_gstatus(ch, ces32.ces_type, in ch_ioctl()
783 if (0 != ch_checkrange(ch, cge.cge_type, cge.cge_unit)) in ch_ioctl()
785 elem = ch->firsts[cge.cge_type] + cge.cge_unit; in ch_ioctl()
790 mutex_lock(&ch->lock); in ch_ioctl()
795 ch_cmd[1] = ((ch->device->lun & 0x7) << 5) | in ch_ioctl()
796 (ch->voltags ? 0x10 : 0) | in ch_ioctl()
797 ch_elem_to_typecode(ch,elem); in ch_ioctl()
803 result = ch_do_scsi(ch, ch_cmd, 12, buffer, 256, REQ_OP_DRV_IN); in ch_ioctl()
816 if (elem >= ch->firsts[i] && in ch_ioctl()
817 elem < ch->firsts[i] + ch->counts[i]) { in ch_ioctl()
819 cge.cge_srcunit = elem-ch->firsts[i]; in ch_ioctl()
836 } else if (ch->voltags) { in ch_ioctl()
837 ch->voltags = 0; in ch_ioctl()
842 mutex_unlock(&ch->lock); in ch_ioctl()
851 mutex_lock(&ch->lock); in ch_ioctl()
852 retval = ch_init_elem(ch); in ch_ioctl()
853 mutex_unlock(&ch->lock); in ch_ioctl()
865 if (0 != ch_checkrange(ch, csv.csv_type, csv.csv_unit)) { in ch_ioctl()
869 elem = ch->firsts[csv.csv_type] + csv.csv_unit; in ch_ioctl()
870 mutex_lock(&ch->lock); in ch_ioctl()
871 retval = ch_set_voltag(ch, elem, in ch_ioctl()
875 mutex_unlock(&ch->lock); in ch_ioctl()
880 return scsi_ioctl(ch->device, file->f_mode & FMODE_WRITE, cmd, in ch_ioctl()
893 scsi_changer *ch; in ch_probe() local
898 ch = kzalloc(sizeof(*ch), GFP_KERNEL); in ch_probe()
899 if (NULL == ch) in ch_probe()
904 ret = idr_alloc(&ch_index_idr, ch, 0, CH_MAX_DEVS + 1, GFP_NOWAIT); in ch_probe()
914 ch->minor = ret; in ch_probe()
915 sprintf(ch->name,"ch%d",ch->minor); in ch_probe()
919 ch->minor); in ch_probe()
923 mutex_init(&ch->lock); in ch_probe()
924 kref_init(&ch->ref); in ch_probe()
925 ch->device = sd; in ch_probe()
927 MKDEV(SCSI_CHANGER_MAJOR, ch->minor), ch, in ch_probe()
928 "s%s", ch->name); in ch_probe()
931 ch->minor); in ch_probe()
936 mutex_lock(&ch->lock); in ch_probe()
937 ret = ch_readconfig(ch); in ch_probe()
939 mutex_unlock(&ch->lock); in ch_probe()
943 ch_init_elem(ch); in ch_probe()
945 mutex_unlock(&ch->lock); in ch_probe()
946 dev_set_drvdata(dev, ch); in ch_probe()
947 sdev_printk(KERN_INFO, sd, "Attached scsi changer %s\n", ch->name); in ch_probe()
951 device_destroy(ch_sysfs_class, MKDEV(SCSI_CHANGER_MAJOR, ch->minor)); in ch_probe()
955 idr_remove(&ch_index_idr, ch->minor); in ch_probe()
957 kfree(ch); in ch_probe()
963 scsi_changer *ch = dev_get_drvdata(dev); in ch_remove() local
966 idr_remove(&ch_index_idr, ch->minor); in ch_remove()
970 device_destroy(ch_sysfs_class, MKDEV(SCSI_CHANGER_MAJOR,ch->minor)); in ch_remove()
971 scsi_device_put(ch->device); in ch_remove()
972 kref_put(&ch->ref, ch_destroy); in ch_remove()