Lines Matching refs:pf
248 static int pf_identify(struct pf_unit *pf);
249 static void pf_lock(struct pf_unit *pf, int func);
250 static void pf_eject(struct pf_unit *pf);
289 struct pf_unit *pf; in pf_init_units() local
293 for (unit = 0, pf = units; unit < PF_UNITS; unit++, pf++) { in pf_init_units()
300 disk->queue = blk_mq_init_sq_queue(&pf->tag_set, &pf_mq_ops, in pf_init_units()
308 INIT_LIST_HEAD(&pf->rq_list); in pf_init_units()
309 disk->queue->queuedata = pf; in pf_init_units()
312 pf->disk = disk; in pf_init_units()
313 pf->pi = &pf->pia; in pf_init_units()
314 pf->media_status = PF_NM; in pf_init_units()
315 pf->drive = (*drives[unit])[D_SLV]; in pf_init_units()
316 pf->lun = (*drives[unit])[D_LUN]; in pf_init_units()
317 snprintf(pf->name, PF_NAMELEN, "%s%d", name, unit); in pf_init_units()
320 strcpy(disk->disk_name, pf->name); in pf_init_units()
330 struct pf_unit *pf = bdev->bd_disk->private_data; in pf_open() local
334 pf_identify(pf); in pf_open()
337 if (pf->media_status == PF_NM) in pf_open()
341 if ((pf->media_status == PF_RO) && (mode & FMODE_WRITE)) in pf_open()
345 pf->access++; in pf_open()
346 if (pf->removable) in pf_open()
347 pf_lock(pf, 1); in pf_open()
355 struct pf_unit *pf = bdev->bd_disk->private_data; in pf_getgeo() local
356 sector_t capacity = get_capacity(pf->disk); in pf_getgeo()
373 struct pf_unit *pf = bdev->bd_disk->private_data; in pf_ioctl() local
378 if (pf->access != 1) in pf_ioctl()
381 pf_eject(pf); in pf_ioctl()
389 struct pf_unit *pf = disk->private_data; in pf_release() local
392 if (pf->access <= 0) { in pf_release()
398 pf->access--; in pf_release()
400 if (!pf->access && pf->removable) in pf_release()
401 pf_lock(pf, 0); in pf_release()
411 static inline int status_reg(struct pf_unit *pf) in status_reg() argument
413 return pi_read_regr(pf->pi, 1, 6); in status_reg()
416 static inline int read_reg(struct pf_unit *pf, int reg) in read_reg() argument
418 return pi_read_regr(pf->pi, 0, reg); in read_reg()
421 static inline void write_reg(struct pf_unit *pf, int reg, int val) in write_reg() argument
423 pi_write_regr(pf->pi, 0, reg, val); in write_reg()
426 static int pf_wait(struct pf_unit *pf, int go, int stop, char *fun, char *msg) in pf_wait() argument
431 while ((((r = status_reg(pf)) & go) || (stop && (!(r & stop)))) in pf_wait()
436 s = read_reg(pf, 7); in pf_wait()
437 e = read_reg(pf, 1); in pf_wait()
438 p = read_reg(pf, 2); in pf_wait()
444 pf->name, fun, msg, r, s, e, j, p); in pf_wait()
450 static int pf_command(struct pf_unit *pf, char *cmd, int dlen, char *fun) in pf_command() argument
452 pi_connect(pf->pi); in pf_command()
454 write_reg(pf, 6, 0xa0+0x10*pf->drive); in pf_command()
456 if (pf_wait(pf, STAT_BUSY | STAT_DRQ, 0, fun, "before command")) { in pf_command()
457 pi_disconnect(pf->pi); in pf_command()
461 write_reg(pf, 4, dlen % 256); in pf_command()
462 write_reg(pf, 5, dlen / 256); in pf_command()
463 write_reg(pf, 7, 0xa0); /* ATAPI packet command */ in pf_command()
465 if (pf_wait(pf, STAT_BUSY, STAT_DRQ, fun, "command DRQ")) { in pf_command()
466 pi_disconnect(pf->pi); in pf_command()
470 if (read_reg(pf, 2) != 1) { in pf_command()
471 printk("%s: %s: command phase error\n", pf->name, fun); in pf_command()
472 pi_disconnect(pf->pi); in pf_command()
476 pi_write_block(pf->pi, cmd, 12); in pf_command()
481 static int pf_completion(struct pf_unit *pf, char *buf, char *fun) in pf_completion() argument
485 r = pf_wait(pf, STAT_BUSY, STAT_DRQ | STAT_READY | STAT_ERR, in pf_completion()
488 if ((read_reg(pf, 2) & 2) && (read_reg(pf, 7) & STAT_DRQ)) { in pf_completion()
489 n = (((read_reg(pf, 4) + 256 * read_reg(pf, 5)) + in pf_completion()
491 pi_read_block(pf->pi, buf, n); in pf_completion()
494 s = pf_wait(pf, STAT_BUSY, STAT_READY | STAT_ERR, fun, "data done"); in pf_completion()
496 pi_disconnect(pf->pi); in pf_completion()
501 static void pf_req_sense(struct pf_unit *pf, int quiet) in pf_req_sense() argument
504 { ATAPI_REQ_SENSE, pf->lun << 5, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0 }; in pf_req_sense()
508 r = pf_command(pf, rs_cmd, 16, "Request sense"); in pf_req_sense()
511 pf_completion(pf, buf, "Request sense"); in pf_req_sense()
515 pf->name, buf[2] & 0xf, buf[12], buf[13]); in pf_req_sense()
518 static int pf_atapi(struct pf_unit *pf, char *cmd, int dlen, char *buf, char *fun) in pf_atapi() argument
522 r = pf_command(pf, cmd, dlen, fun); in pf_atapi()
525 r = pf_completion(pf, buf, fun); in pf_atapi()
527 pf_req_sense(pf, !fun); in pf_atapi()
532 static void pf_lock(struct pf_unit *pf, int func) in pf_lock() argument
534 char lo_cmd[12] = { ATAPI_LOCK, pf->lun << 5, 0, 0, func, 0, 0, 0, 0, 0, 0, 0 }; in pf_lock()
536 pf_atapi(pf, lo_cmd, 0, pf_scratch, func ? "lock" : "unlock"); in pf_lock()
539 static void pf_eject(struct pf_unit *pf) in pf_eject() argument
541 char ej_cmd[12] = { ATAPI_DOOR, pf->lun << 5, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0 }; in pf_eject()
543 pf_lock(pf, 0); in pf_eject()
544 pf_atapi(pf, ej_cmd, 0, pf_scratch, "eject"); in pf_eject()
559 static int pf_reset(struct pf_unit *pf) in pf_reset() argument
564 pi_connect(pf->pi); in pf_reset()
565 write_reg(pf, 6, 0xa0+0x10*pf->drive); in pf_reset()
566 write_reg(pf, 7, 8); in pf_reset()
571 while ((k++ < PF_RESET_TMO) && (status_reg(pf) & STAT_BUSY)) in pf_reset()
576 flg &= (read_reg(pf, i + 1) == expect[i]); in pf_reset()
579 printk("%s: Reset (%d) signature = ", pf->name, k); in pf_reset()
581 printk("%3x", read_reg(pf, i + 1)); in pf_reset()
587 pi_disconnect(pf->pi); in pf_reset()
591 static void pf_mode_sense(struct pf_unit *pf) in pf_mode_sense() argument
594 { ATAPI_MODE_SENSE, pf->lun << 5, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0 }; in pf_mode_sense()
597 pf_atapi(pf, ms_cmd, 8, buf, "mode sense"); in pf_mode_sense()
598 pf->media_status = PF_RW; in pf_mode_sense()
600 pf->media_status = PF_RO; in pf_mode_sense()
627 static void pf_get_capacity(struct pf_unit *pf) in pf_get_capacity() argument
629 char rc_cmd[12] = { ATAPI_CAPACITY, pf->lun << 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; in pf_get_capacity()
633 if (pf_atapi(pf, rc_cmd, 8, buf, "get capacity")) { in pf_get_capacity()
634 pf->media_status = PF_NM; in pf_get_capacity()
637 set_capacity(pf->disk, xl(buf, 0) + 1); in pf_get_capacity()
640 set_capacity(pf->disk, 0); in pf_get_capacity()
644 pf->name, pf->drive, pf->lun, bs); in pf_get_capacity()
648 static int pf_identify(struct pf_unit *pf) in pf_identify() argument
654 { ATAPI_IDENTIFY, pf->lun << 5, 0, 0, 36, 0, 0, 0, 0, 0, 0, 0 }; in pf_identify()
657 s = pf_atapi(pf, id_cmd, 36, buf, "identify"); in pf_identify()
665 pf->name, pf->drive, pf->lun, dt); in pf_identify()
672 pf->removable = (buf[1] & 0x80); in pf_identify()
674 pf_mode_sense(pf); in pf_identify()
675 pf_mode_sense(pf); in pf_identify()
676 pf_mode_sense(pf); in pf_identify()
678 pf_get_capacity(pf); in pf_identify()
681 pf->name, mf, id, ms[pf->drive], pf->lun, dt); in pf_identify()
682 if (pf->removable) in pf_identify()
684 if (pf->media_status == PF_NM) in pf_identify()
687 if (pf->media_status == PF_RO) in pf_identify()
690 (unsigned long long)get_capacity(pf->disk)); in pf_identify()
698 static int pf_probe(struct pf_unit *pf) in pf_probe() argument
700 if (pf->drive == -1) { in pf_probe()
701 for (pf->drive = 0; pf->drive <= 1; pf->drive++) in pf_probe()
702 if (!pf_reset(pf)) { in pf_probe()
703 if (pf->lun != -1) in pf_probe()
704 return pf_identify(pf); in pf_probe()
706 for (pf->lun = 0; pf->lun < 8; pf->lun++) in pf_probe()
707 if (!pf_identify(pf)) in pf_probe()
711 if (pf_reset(pf)) in pf_probe()
713 if (pf->lun != -1) in pf_probe()
714 return pf_identify(pf); in pf_probe()
715 for (pf->lun = 0; pf->lun < 8; pf->lun++) in pf_probe()
716 if (!pf_identify(pf)) in pf_probe()
724 struct pf_unit *pf = units; in pf_detect() local
737 if (pi_init(pf->pi, 1, -1, -1, -1, -1, -1, pf_scratch, PI_PF, in pf_detect()
738 verbose, pf->name)) { in pf_detect()
739 if (!pf_probe(pf) && pf->disk) { in pf_detect()
740 pf->present = 1; in pf_detect()
743 pi_release(pf->pi); in pf_detect()
747 for (unit = 0; unit < PF_UNITS; unit++, pf++) { in pf_detect()
751 if (pi_init(pf->pi, 0, conf[D_PRT], conf[D_MOD], in pf_detect()
753 pf_scratch, PI_PF, verbose, pf->name)) { in pf_detect()
754 if (pf->disk && !pf_probe(pf)) { in pf_detect()
755 pf->present = 1; in pf_detect()
758 pi_release(pf->pi); in pf_detect()
765 for (pf = units, unit = 0; unit < PF_UNITS; pf++, unit++) { in pf_detect()
766 if (!pf->disk) in pf_detect()
768 blk_cleanup_queue(pf->disk->queue); in pf_detect()
769 pf->disk->queue = NULL; in pf_detect()
770 blk_mq_free_tag_set(&pf->tag_set); in pf_detect()
771 put_disk(pf->disk); in pf_detect()
779 static int pf_start(struct pf_unit *pf, int cmd, int b, int c) in pf_start() argument
782 char io_cmd[12] = { cmd, pf->lun << 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; in pf_start()
792 i = pf_command(pf, io_cmd, c * 512, "start i/o"); in pf_start()
808 struct pf_unit *pf; in set_next_request() local
812 pf = &units[pf_queue]; in set_next_request()
815 if (pf->present && !list_empty(&pf->rq_list)) { in set_next_request()
816 pf_req = list_first_entry(&pf->rq_list, struct request, in set_next_request()
874 struct pf_unit *pf = hctx->queue->queuedata; in pf_queue_rq() local
877 list_add_tail(&bd->rq->queuelist, &pf->rq_list); in pf_queue_rq()
1022 struct pf_unit *pf; in pf_init() local
1035 for (pf = units, unit = 0; unit < PF_UNITS; pf++, unit++) { in pf_init()
1036 if (!pf->disk) in pf_init()
1038 blk_cleanup_queue(pf->disk->queue); in pf_init()
1039 blk_mq_free_tag_set(&pf->tag_set); in pf_init()
1040 put_disk(pf->disk); in pf_init()
1045 for (pf = units, unit = 0; unit < PF_UNITS; pf++, unit++) { in pf_init()
1046 struct gendisk *disk = pf->disk; in pf_init()
1048 if (!pf->present) in pf_init()
1050 disk->private_data = pf; in pf_init()
1058 struct pf_unit *pf; in pf_exit() local
1061 for (pf = units, unit = 0; unit < PF_UNITS; pf++, unit++) { in pf_exit()
1062 if (!pf->disk) in pf_exit()
1065 if (pf->present) in pf_exit()
1066 del_gendisk(pf->disk); in pf_exit()
1068 blk_cleanup_queue(pf->disk->queue); in pf_exit()
1069 blk_mq_free_tag_set(&pf->tag_set); in pf_exit()
1070 put_disk(pf->disk); in pf_exit()
1072 if (pf->present) in pf_exit()
1073 pi_release(pf->pi); in pf_exit()