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