Lines Matching full: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,
212 result = scsi_execute_cmd(ch->device, cmd, op, buffer, buflength,
218 scsi_print_sense_hdr(ch->device, ch->name, &sshdr);
227 ch_elem_to_typecode(scsi_changer *ch, u_int elem)
232 if (elem >= ch->firsts[i] &&
233 elem < ch->firsts[i] +
234 ch->counts[i])
241 ch_read_element_status(scsi_changer *ch, u_int elem, char *data)
254 cmd[1] = ((ch->device->lun & 0x7) << 5) |
255 (ch->voltags ? 0x10 : 0) |
256 ch_elem_to_typecode(ch,elem);
261 if (0 == (result = ch_do_scsi(ch, cmd, 12,
271 if (ch->voltags) {
272 ch->voltags = 0;
283 ch_init_elem(scsi_changer *ch)
291 cmd[1] = (ch->device->lun & 0x7) << 5;
292 err = ch_do_scsi(ch, cmd, 6, NULL, 0, REQ_OP_DRV_IN);
298 ch_readconfig(scsi_changer *ch)
311 cmd[1] = (ch->device->lun & 0x7) << 5;
314 result = ch_do_scsi(ch, cmd, 10, buffer, 255, REQ_OP_DRV_IN);
317 result = ch_do_scsi(ch, cmd, 10, buffer, 255, REQ_OP_DRV_IN);
320 ch->firsts[CHET_MT] =
322 ch->counts[CHET_MT] =
324 ch->firsts[CHET_ST] =
326 ch->counts[CHET_ST] =
328 ch->firsts[CHET_IE] =
330 ch->counts[CHET_IE] =
332 ch->firsts[CHET_DT] =
334 ch->counts[CHET_DT] =
337 ch->firsts[CHET_MT],
338 ch->counts[CHET_MT]);
340 ch->firsts[CHET_ST],
341 ch->counts[CHET_ST]);
343 ch->firsts[CHET_IE],
344 ch->counts[CHET_IE]);
346 ch->firsts[CHET_DT],
347 ch->counts[CHET_DT]);
358 ch->firsts[CHET_V1+i] = vendor_firsts[i];
359 ch->counts[CHET_V1+i] = vendor_counts[i];
366 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]);
387 id = ch->device->id;
395 sdev = scsi_device_lookup(ch->device->host,
396 ch->device->channel,
408 ch->voltags = 1;
417 ch_position(scsi_changer *ch, u_int trans, u_int elem, int rotate)
423 trans = ch->firsts[CHET_MT];
426 cmd[1] = (ch->device->lun & 0x7) << 5;
432 return ch_do_scsi(ch, cmd, 10, NULL, 0, REQ_OP_DRV_IN);
436 ch_move(scsi_changer *ch, u_int trans, u_int src, u_int dest, int rotate)
442 trans = ch->firsts[CHET_MT];
445 cmd[1] = (ch->device->lun & 0x7) << 5;
453 return ch_do_scsi(ch, cmd, 12, NULL, 0, REQ_OP_DRV_IN);
457 ch_exchange(scsi_changer *ch, u_int trans, u_int src,
465 trans = ch->firsts[CHET_MT];
468 cmd[1] = (ch->device->lun & 0x7) << 5;
479 return ch_do_scsi(ch, cmd, 12, NULL, 0, REQ_OP_DRV_IN);
499 ch_set_voltag(scsi_changer *ch, u_int elem,
516 cmd[1] = ((ch->device->lun & 0x7) << 5) |
517 ch_elem_to_typecode(ch,elem);
529 result = ch_do_scsi(ch, cmd, 12, buffer, 256, REQ_OP_DRV_OUT);
534 static int ch_gstatus(scsi_changer *ch, int type, unsigned char __user *dest)
540 mutex_lock(&ch->lock);
541 for (i = 0; i < ch->counts[type]; i++) {
543 (ch, ch->firsts[type]+i,data)) {
550 ch->firsts[type]+i,
553 (ch, ch->firsts[type]+i,data);
557 mutex_unlock(&ch->lock);
565 scsi_changer *ch = container_of(ref, scsi_changer, ref);
567 ch->device = NULL;
568 kfree(ch);
574 scsi_changer *ch = file->private_data;
576 scsi_device_put(ch->device);
578 kref_put(&ch->ref, ch_destroy);
585 scsi_changer *ch;
589 ch = idr_find(&ch_index_idr, minor);
591 if (ch == NULL || !kref_get_unless_zero(&ch->ref)) {
596 if (scsi_device_get(ch->device)) {
597 kref_put(&ch->ref, ch_destroy);
601 mutex_lock(&ch->lock);
602 file->private_data = ch;
603 mutex_unlock(&ch->lock);
608 ch_checkrange(scsi_changer *ch, unsigned int type, unsigned int unit)
610 if (type >= CH_TYPES || unit >= ch->counts[type])
624 scsi_changer *ch = file->private_data;
628 retval = scsi_ioctl_block_when_processing_errors(ch->device, cmd,
639 params.cp_npickers = ch->counts[CHET_MT];
640 params.cp_nslots = ch->counts[CHET_ST];
641 params.cp_nportals = ch->counts[CHET_IE];
642 params.cp_ndrives = ch->counts[CHET_DT];
653 if (ch->counts[CHET_V1]) {
654 vparams.cvp_n1 = ch->counts[CHET_V1];
658 if (ch->counts[CHET_V2]) {
659 vparams.cvp_n2 = ch->counts[CHET_V2];
663 if (ch->counts[CHET_V3]) {
664 vparams.cvp_n3 = ch->counts[CHET_V3];
668 if (ch->counts[CHET_V4]) {
669 vparams.cvp_n4 = ch->counts[CHET_V4];
685 if (0 != ch_checkrange(ch, pos.cp_type, pos.cp_unit)) {
689 mutex_lock(&ch->lock);
690 retval = ch_position(ch,0,
691 ch->firsts[pos.cp_type] + pos.cp_unit,
693 mutex_unlock(&ch->lock);
704 if (0 != ch_checkrange(ch, mv.cm_fromtype, mv.cm_fromunit) ||
705 0 != ch_checkrange(ch, mv.cm_totype, mv.cm_tounit )) {
710 mutex_lock(&ch->lock);
711 retval = ch_move(ch,0,
712 ch->firsts[mv.cm_fromtype] + mv.cm_fromunit,
713 ch->firsts[mv.cm_totype] + mv.cm_tounit,
715 mutex_unlock(&ch->lock);
726 if (0 != ch_checkrange(ch, mv.ce_srctype, mv.ce_srcunit ) ||
727 0 != ch_checkrange(ch, mv.ce_fdsttype, mv.ce_fdstunit) ||
728 0 != ch_checkrange(ch, mv.ce_sdsttype, mv.ce_sdstunit)) {
733 mutex_lock(&ch->lock);
735 (ch,0,
736 ch->firsts[mv.ce_srctype] + mv.ce_srcunit,
737 ch->firsts[mv.ce_fdsttype] + mv.ce_fdstunit,
738 ch->firsts[mv.ce_sdsttype] + mv.ce_sdstunit,
740 mutex_unlock(&ch->lock);
753 return ch_gstatus(ch, ces.ces_type, ces.ces_data);
765 return ch_gstatus(ch, ces32.ces_type,
780 if (0 != ch_checkrange(ch, cge.cge_type, cge.cge_unit))
782 elem = ch->firsts[cge.cge_type] + cge.cge_unit;
787 mutex_lock(&ch->lock);
792 ch_cmd[1] = ((ch->device->lun & 0x7) << 5) |
793 (ch->voltags ? 0x10 : 0) |
794 ch_elem_to_typecode(ch,elem);
800 result = ch_do_scsi(ch, ch_cmd, 12, buffer, 256, REQ_OP_DRV_IN);
813 if (elem >= ch->firsts[i] &&
814 elem < ch->firsts[i] + ch->counts[i]) {
816 cge.cge_srcunit = elem-ch->firsts[i];
833 } else if (ch->voltags) {
834 ch->voltags = 0;
839 mutex_unlock(&ch->lock);
848 mutex_lock(&ch->lock);
849 retval = ch_init_elem(ch);
850 mutex_unlock(&ch->lock);
862 if (0 != ch_checkrange(ch, csv.csv_type, csv.csv_unit)) {
866 elem = ch->firsts[csv.csv_type] + csv.csv_unit;
867 mutex_lock(&ch->lock);
868 retval = ch_set_voltag(ch, elem,
872 mutex_unlock(&ch->lock);
877 return scsi_ioctl(ch->device, file->f_mode & FMODE_WRITE, cmd,
890 scsi_changer *ch;
895 ch = kzalloc_obj(*ch);
896 if (NULL == ch)
901 ret = idr_alloc(&ch_index_idr, ch, 0, CH_MAX_DEVS + 1, GFP_NOWAIT);
911 ch->minor = ret;
912 sprintf(ch->name,"ch%d",ch->minor);
915 sdev_printk(KERN_WARNING, sd, "ch%d: failed to get device\n",
916 ch->minor);
920 mutex_init(&ch->lock);
921 kref_init(&ch->ref);
922 ch->device = sd;
924 MKDEV(SCSI_CHANGER_MAJOR, ch->minor), ch,
925 "s%s", ch->name);
927 sdev_printk(KERN_WARNING, sd, "ch%d: device_create failed\n",
928 ch->minor);
933 mutex_lock(&ch->lock);
934 ret = ch_readconfig(ch);
936 mutex_unlock(&ch->lock);
940 ch_init_elem(ch);
942 mutex_unlock(&ch->lock);
943 dev_set_drvdata(dev, ch);
944 sdev_printk(KERN_INFO, sd, "Attached scsi changer %s\n", ch->name);
948 device_destroy(&ch_sysfs_class, MKDEV(SCSI_CHANGER_MAJOR, ch->minor));
952 idr_remove(&ch_index_idr, ch->minor);
954 kfree(ch);
961 scsi_changer *ch = dev_get_drvdata(dev);
964 idr_remove(&ch_index_idr, ch->minor);
968 device_destroy(&ch_sysfs_class, MKDEV(SCSI_CHANGER_MAJOR, ch->minor));
969 scsi_device_put(ch->device);
970 kref_put(&ch->ref, ch_destroy);
977 .name = "ch",
999 rc = register_chrdev(SCSI_CHANGER_MAJOR,"ch",&changer_fops);
1011 unregister_chrdev(SCSI_CHANGER_MAJOR, "ch");
1020 unregister_chrdev(SCSI_CHANGER_MAJOR, "ch");