Lines Matching refs:ch

87 #define ch_printk(prefix, ch, fmt, a...) \
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); \
187 ch_do_scsi(scsi_changer *ch, unsigned char *cmd, int cmd_len,
213 result = scsi_execute_cmd(ch->device, cmd, op, buffer, buflength,
219 scsi_print_sense_hdr(ch->device, ch->name, &sshdr);
228 ch_elem_to_typecode(scsi_changer *ch, u_int elem)
233 if (elem >= ch->firsts[i] &&
234 elem < ch->firsts[i] +
235 ch->counts[i])
242 ch_read_element_status(scsi_changer *ch, u_int elem, char *data)
255 cmd[1] = ((ch->device->lun & 0x7) << 5) |
256 (ch->voltags ? 0x10 : 0) |
257 ch_elem_to_typecode(ch,elem);
262 if (0 == (result = ch_do_scsi(ch, cmd, 12,
272 if (ch->voltags) {
273 ch->voltags = 0;
284 ch_init_elem(scsi_changer *ch)
292 cmd[1] = (ch->device->lun & 0x7) << 5;
293 err = ch_do_scsi(ch, cmd, 6, NULL, 0, REQ_OP_DRV_IN);
299 ch_readconfig(scsi_changer *ch)
312 cmd[1] = (ch->device->lun & 0x7) << 5;
315 result = ch_do_scsi(ch, cmd, 10, buffer, 255, REQ_OP_DRV_IN);
318 result = ch_do_scsi(ch, cmd, 10, buffer, 255, REQ_OP_DRV_IN);
321 ch->firsts[CHET_MT] =
323 ch->counts[CHET_MT] =
325 ch->firsts[CHET_ST] =
327 ch->counts[CHET_ST] =
329 ch->firsts[CHET_IE] =
331 ch->counts[CHET_IE] =
333 ch->firsts[CHET_DT] =
335 ch->counts[CHET_DT] =
338 ch->firsts[CHET_MT],
339 ch->counts[CHET_MT]);
341 ch->firsts[CHET_ST],
342 ch->counts[CHET_ST]);
344 ch->firsts[CHET_IE],
345 ch->counts[CHET_IE]);
347 ch->firsts[CHET_DT],
348 ch->counts[CHET_DT]);
359 ch->firsts[CHET_V1+i] = vendor_firsts[i];
360 ch->counts[CHET_V1+i] = vendor_counts[i];
367 ch->dt = kcalloc(ch->counts[CHET_DT], sizeof(*ch->dt),
370 if (!ch->dt) {
375 for (elem = 0; elem < ch->counts[CHET_DT]; elem++) {
382 elem+ch->firsts[CHET_DT]);
384 (ch,elem+ch->firsts[CHET_DT],data)) {
386 elem+ch->firsts[CHET_DT]);
388 VPRINTK(KERN_INFO, "dt 0x%x: ",elem+ch->firsts[CHET_DT]);
391 ch->dt[elem] = NULL;
394 ch->dt[elem] = NULL;
396 id = ch->device->id;
404 ch->dt[elem] =
405 scsi_device_lookup(ch->device->host,
406 ch->device->channel,
408 if (!ch->dt[elem]) {
413 ch->dt[elem]->vendor,
414 ch->dt[elem]->model,
415 ch->dt[elem]->rev);
419 ch->voltags = 1;
428 ch_position(scsi_changer *ch, u_int trans, u_int elem, int rotate)
434 trans = ch->firsts[CHET_MT];
437 cmd[1] = (ch->device->lun & 0x7) << 5;
443 return ch_do_scsi(ch, cmd, 10, NULL, 0, REQ_OP_DRV_IN);
447 ch_move(scsi_changer *ch, u_int trans, u_int src, u_int dest, int rotate)
453 trans = ch->firsts[CHET_MT];
456 cmd[1] = (ch->device->lun & 0x7) << 5;
464 return ch_do_scsi(ch, cmd, 12, NULL, 0, REQ_OP_DRV_IN);
468 ch_exchange(scsi_changer *ch, u_int trans, u_int src,
476 trans = ch->firsts[CHET_MT];
479 cmd[1] = (ch->device->lun & 0x7) << 5;
490 return ch_do_scsi(ch, cmd, 12, NULL, 0, REQ_OP_DRV_IN);
510 ch_set_voltag(scsi_changer *ch, u_int elem,
527 cmd[1] = ((ch->device->lun & 0x7) << 5) |
528 ch_elem_to_typecode(ch,elem);
540 result = ch_do_scsi(ch, cmd, 12, buffer, 256, REQ_OP_DRV_OUT);
545 static int ch_gstatus(scsi_changer *ch, int type, unsigned char __user *dest)
551 mutex_lock(&ch->lock);
552 for (i = 0; i < ch->counts[type]; i++) {
554 (ch, ch->firsts[type]+i,data)) {
561 ch->firsts[type]+i,
564 (ch, ch->firsts[type]+i,data);
568 mutex_unlock(&ch->lock);
576 scsi_changer *ch = container_of(ref, scsi_changer, ref);
578 ch->device = NULL;
579 kfree(ch->dt);
580 kfree(ch);
586 scsi_changer *ch = file->private_data;
588 scsi_device_put(ch->device);
590 kref_put(&ch->ref, ch_destroy);
597 scsi_changer *ch;
601 ch = idr_find(&ch_index_idr, minor);
603 if (ch == NULL || !kref_get_unless_zero(&ch->ref)) {
608 if (scsi_device_get(ch->device)) {
609 kref_put(&ch->ref, ch_destroy);
613 mutex_lock(&ch->lock);
614 file->private_data = ch;
615 mutex_unlock(&ch->lock);
620 ch_checkrange(scsi_changer *ch, unsigned int type, unsigned int unit)
622 if (type >= CH_TYPES || unit >= ch->counts[type])
636 scsi_changer *ch = file->private_data;
640 retval = scsi_ioctl_block_when_processing_errors(ch->device, cmd,
651 params.cp_npickers = ch->counts[CHET_MT];
652 params.cp_nslots = ch->counts[CHET_ST];
653 params.cp_nportals = ch->counts[CHET_IE];
654 params.cp_ndrives = ch->counts[CHET_DT];
665 if (ch->counts[CHET_V1]) {
666 vparams.cvp_n1 = ch->counts[CHET_V1];
670 if (ch->counts[CHET_V2]) {
671 vparams.cvp_n2 = ch->counts[CHET_V2];
675 if (ch->counts[CHET_V3]) {
676 vparams.cvp_n3 = ch->counts[CHET_V3];
680 if (ch->counts[CHET_V4]) {
681 vparams.cvp_n4 = ch->counts[CHET_V4];
697 if (0 != ch_checkrange(ch, pos.cp_type, pos.cp_unit)) {
701 mutex_lock(&ch->lock);
702 retval = ch_position(ch,0,
703 ch->firsts[pos.cp_type] + pos.cp_unit,
705 mutex_unlock(&ch->lock);
716 if (0 != ch_checkrange(ch, mv.cm_fromtype, mv.cm_fromunit) ||
717 0 != ch_checkrange(ch, mv.cm_totype, mv.cm_tounit )) {
722 mutex_lock(&ch->lock);
723 retval = ch_move(ch,0,
724 ch->firsts[mv.cm_fromtype] + mv.cm_fromunit,
725 ch->firsts[mv.cm_totype] + mv.cm_tounit,
727 mutex_unlock(&ch->lock);
738 if (0 != ch_checkrange(ch, mv.ce_srctype, mv.ce_srcunit ) ||
739 0 != ch_checkrange(ch, mv.ce_fdsttype, mv.ce_fdstunit) ||
740 0 != ch_checkrange(ch, mv.ce_sdsttype, mv.ce_sdstunit)) {
745 mutex_lock(&ch->lock);
747 (ch,0,
748 ch->firsts[mv.ce_srctype] + mv.ce_srcunit,
749 ch->firsts[mv.ce_fdsttype] + mv.ce_fdstunit,
750 ch->firsts[mv.ce_sdsttype] + mv.ce_sdstunit,
752 mutex_unlock(&ch->lock);
765 return ch_gstatus(ch, ces.ces_type, ces.ces_data);
777 return ch_gstatus(ch, ces32.ces_type,
792 if (0 != ch_checkrange(ch, cge.cge_type, cge.cge_unit))
794 elem = ch->firsts[cge.cge_type] + cge.cge_unit;
799 mutex_lock(&ch->lock);
804 ch_cmd[1] = ((ch->device->lun & 0x7) << 5) |
805 (ch->voltags ? 0x10 : 0) |
806 ch_elem_to_typecode(ch,elem);
812 result = ch_do_scsi(ch, ch_cmd, 12, buffer, 256, REQ_OP_DRV_IN);
825 if (elem >= ch->firsts[i] &&
826 elem < ch->firsts[i] + ch->counts[i]) {
828 cge.cge_srcunit = elem-ch->firsts[i];
845 } else if (ch->voltags) {
846 ch->voltags = 0;
851 mutex_unlock(&ch->lock);
860 mutex_lock(&ch->lock);
861 retval = ch_init_elem(ch);
862 mutex_unlock(&ch->lock);
874 if (0 != ch_checkrange(ch, csv.csv_type, csv.csv_unit)) {
878 elem = ch->firsts[csv.csv_type] + csv.csv_unit;
879 mutex_lock(&ch->lock);
880 retval = ch_set_voltag(ch, elem,
884 mutex_unlock(&ch->lock);
889 return scsi_ioctl(ch->device, file->f_mode & FMODE_WRITE, cmd,
902 scsi_changer *ch;
907 ch = kzalloc(sizeof(*ch), GFP_KERNEL);
908 if (NULL == ch)
913 ret = idr_alloc(&ch_index_idr, ch, 0, CH_MAX_DEVS + 1, GFP_NOWAIT);
923 ch->minor = ret;
924 sprintf(ch->name,"ch%d",ch->minor);
927 sdev_printk(KERN_WARNING, sd, "ch%d: failed to get device\n",
928 ch->minor);
932 mutex_init(&ch->lock);
933 kref_init(&ch->ref);
934 ch->device = sd;
936 MKDEV(SCSI_CHANGER_MAJOR, ch->minor), ch,
937 "s%s", ch->name);
939 sdev_printk(KERN_WARNING, sd, "ch%d: device_create failed\n",
940 ch->minor);
945 mutex_lock(&ch->lock);
946 ret = ch_readconfig(ch);
948 mutex_unlock(&ch->lock);
952 ch_init_elem(ch);
954 mutex_unlock(&ch->lock);
955 dev_set_drvdata(dev, ch);
956 sdev_printk(KERN_INFO, sd, "Attached scsi changer %s\n", ch->name);
960 device_destroy(&ch_sysfs_class, MKDEV(SCSI_CHANGER_MAJOR, ch->minor));
964 idr_remove(&ch_index_idr, ch->minor);
966 kfree(ch);
972 scsi_changer *ch = dev_get_drvdata(dev);
975 idr_remove(&ch_index_idr, ch->minor);
979 device_destroy(&ch_sysfs_class, MKDEV(SCSI_CHANGER_MAJOR, ch->minor));
980 scsi_device_put(ch->device);
981 kref_put(&ch->ref, ch_destroy);
987 .name = "ch",
1011 rc = register_chrdev(SCSI_CHANGER_MAJOR,"ch",&changer_fops);
1023 unregister_chrdev(SCSI_CHANGER_MAJOR, "ch");
1032 unregister_chrdev(SCSI_CHANGER_MAJOR, "ch");