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