Lines Matching full:pf
2 pf.c (c) 1997-8 Grant R. Guenther <grant@torque.net>
12 The behaviour of the pf driver can be altered by setting
70 (default "pf").
91 pf.drive0
92 pf.drive1
93 pf.drive2
94 pf.drive3
95 pf.cluster
96 pf.nice
98 In addition, you can use the parameter pf.disable to disable
118 #define PF_NAME "pf"
247 static int pf_identify(struct pf_unit *pf);
248 static void pf_lock(struct pf_unit *pf, int func);
249 static void pf_eject(struct pf_unit *pf);
289 struct pf_unit *pf = bdev->bd_disk->private_data; in pf_open() local
293 pf_identify(pf); in pf_open()
296 if (pf->media_status == PF_NM) in pf_open()
300 if ((pf->media_status == PF_RO) && (mode & FMODE_WRITE)) in pf_open()
304 pf->access++; in pf_open()
305 if (pf->removable) in pf_open()
306 pf_lock(pf, 1); in pf_open()
314 struct pf_unit *pf = bdev->bd_disk->private_data; in pf_getgeo() local
315 sector_t capacity = get_capacity(pf->disk); in pf_getgeo()
332 struct pf_unit *pf = bdev->bd_disk->private_data; in pf_ioctl() local
337 if (pf->access != 1) in pf_ioctl()
340 pf_eject(pf); in pf_ioctl()
348 struct pf_unit *pf = disk->private_data; in pf_release() local
351 if (pf->access <= 0) { in pf_release()
357 pf->access--; in pf_release()
359 if (!pf->access && pf->removable) in pf_release()
360 pf_lock(pf, 0); in pf_release()
370 static inline int status_reg(struct pf_unit *pf) in status_reg() argument
372 return pi_read_regr(pf->pi, 1, 6); in status_reg()
375 static inline int read_reg(struct pf_unit *pf, int reg) in read_reg() argument
377 return pi_read_regr(pf->pi, 0, reg); in read_reg()
380 static inline void write_reg(struct pf_unit *pf, int reg, int val) in write_reg() argument
382 pi_write_regr(pf->pi, 0, reg, val); in write_reg()
385 static int pf_wait(struct pf_unit *pf, int go, int stop, char *fun, char *msg) in pf_wait() argument
390 while ((((r = status_reg(pf)) & go) || (stop && (!(r & stop)))) in pf_wait()
395 s = read_reg(pf, 7); in pf_wait()
396 e = read_reg(pf, 1); in pf_wait()
397 p = read_reg(pf, 2); in pf_wait()
403 pf->name, fun, msg, r, s, e, j, p); in pf_wait()
409 static int pf_command(struct pf_unit *pf, char *cmd, int dlen, char *fun) in pf_command() argument
411 pi_connect(pf->pi); in pf_command()
413 write_reg(pf, 6, 0xa0+0x10*pf->drive); in pf_command()
415 if (pf_wait(pf, STAT_BUSY | STAT_DRQ, 0, fun, "before command")) { in pf_command()
416 pi_disconnect(pf->pi); in pf_command()
420 write_reg(pf, 4, dlen % 256); in pf_command()
421 write_reg(pf, 5, dlen / 256); in pf_command()
422 write_reg(pf, 7, 0xa0); /* ATAPI packet command */ in pf_command()
424 if (pf_wait(pf, STAT_BUSY, STAT_DRQ, fun, "command DRQ")) { in pf_command()
425 pi_disconnect(pf->pi); in pf_command()
429 if (read_reg(pf, 2) != 1) { in pf_command()
430 printk("%s: %s: command phase error\n", pf->name, fun); in pf_command()
431 pi_disconnect(pf->pi); in pf_command()
435 pi_write_block(pf->pi, cmd, 12); in pf_command()
440 static int pf_completion(struct pf_unit *pf, char *buf, char *fun) in pf_completion() argument
444 r = pf_wait(pf, STAT_BUSY, STAT_DRQ | STAT_READY | STAT_ERR, in pf_completion()
447 if ((read_reg(pf, 2) & 2) && (read_reg(pf, 7) & STAT_DRQ)) { in pf_completion()
448 n = (((read_reg(pf, 4) + 256 * read_reg(pf, 5)) + in pf_completion()
450 pi_read_block(pf->pi, buf, n); in pf_completion()
453 s = pf_wait(pf, STAT_BUSY, STAT_READY | STAT_ERR, fun, "data done"); in pf_completion()
455 pi_disconnect(pf->pi); in pf_completion()
460 static void pf_req_sense(struct pf_unit *pf, int quiet) in pf_req_sense() argument
463 { ATAPI_REQ_SENSE, pf->lun << 5, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0 }; in pf_req_sense()
467 r = pf_command(pf, rs_cmd, 16, "Request sense"); in pf_req_sense()
470 pf_completion(pf, buf, "Request sense"); in pf_req_sense()
474 pf->name, buf[2] & 0xf, buf[12], buf[13]); in pf_req_sense()
477 static int pf_atapi(struct pf_unit *pf, char *cmd, int dlen, char *buf, char *fun) in pf_atapi() argument
481 r = pf_command(pf, cmd, dlen, fun); in pf_atapi()
484 r = pf_completion(pf, buf, fun); in pf_atapi()
486 pf_req_sense(pf, !fun); in pf_atapi()
491 static void pf_lock(struct pf_unit *pf, int func) in pf_lock() argument
493 char lo_cmd[12] = { ATAPI_LOCK, pf->lun << 5, 0, 0, func, 0, 0, 0, 0, 0, 0, 0 }; in pf_lock()
495 pf_atapi(pf, lo_cmd, 0, pf_scratch, func ? "lock" : "unlock"); in pf_lock()
498 static void pf_eject(struct pf_unit *pf) in pf_eject() argument
500 char ej_cmd[12] = { ATAPI_DOOR, pf->lun << 5, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0 }; in pf_eject()
502 pf_lock(pf, 0); in pf_eject()
503 pf_atapi(pf, ej_cmd, 0, pf_scratch, "eject"); in pf_eject()
518 static int pf_reset(struct pf_unit *pf) in pf_reset() argument
523 pi_connect(pf->pi); in pf_reset()
524 write_reg(pf, 6, 0xa0+0x10*pf->drive); in pf_reset()
525 write_reg(pf, 7, 8); in pf_reset()
530 while ((k++ < PF_RESET_TMO) && (status_reg(pf) & STAT_BUSY)) in pf_reset()
535 flg &= (read_reg(pf, i + 1) == expect[i]); in pf_reset()
538 printk("%s: Reset (%d) signature = ", pf->name, k); in pf_reset()
540 printk("%3x", read_reg(pf, i + 1)); in pf_reset()
546 pi_disconnect(pf->pi); in pf_reset()
550 static void pf_mode_sense(struct pf_unit *pf) in pf_mode_sense() argument
553 { ATAPI_MODE_SENSE, pf->lun << 5, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0 }; in pf_mode_sense()
556 pf_atapi(pf, ms_cmd, 8, buf, "mode sense"); in pf_mode_sense()
557 pf->media_status = PF_RW; in pf_mode_sense()
559 pf->media_status = PF_RO; in pf_mode_sense()
586 static void pf_get_capacity(struct pf_unit *pf) in pf_get_capacity() argument
588 char rc_cmd[12] = { ATAPI_CAPACITY, pf->lun << 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; in pf_get_capacity()
592 if (pf_atapi(pf, rc_cmd, 8, buf, "get capacity")) { in pf_get_capacity()
593 pf->media_status = PF_NM; in pf_get_capacity()
596 set_capacity(pf->disk, xl(buf, 0) + 1); in pf_get_capacity()
599 set_capacity(pf->disk, 0); in pf_get_capacity()
603 pf->name, pf->drive, pf->lun, bs); in pf_get_capacity()
607 static int pf_identify(struct pf_unit *pf) in pf_identify() argument
613 { ATAPI_IDENTIFY, pf->lun << 5, 0, 0, 36, 0, 0, 0, 0, 0, 0, 0 }; in pf_identify()
616 s = pf_atapi(pf, id_cmd, 36, buf, "identify"); in pf_identify()
624 pf->name, pf->drive, pf->lun, dt); in pf_identify()
631 pf->removable = (buf[1] & 0x80); in pf_identify()
633 pf_mode_sense(pf); in pf_identify()
634 pf_mode_sense(pf); in pf_identify()
635 pf_mode_sense(pf); in pf_identify()
637 pf_get_capacity(pf); in pf_identify()
640 pf->name, mf, id, ms[pf->drive], pf->lun, dt); in pf_identify()
641 if (pf->removable) in pf_identify()
643 if (pf->media_status == PF_NM) in pf_identify()
646 if (pf->media_status == PF_RO) in pf_identify()
649 (unsigned long long)get_capacity(pf->disk)); in pf_identify()
657 static int pf_probe(struct pf_unit *pf) in pf_probe() argument
659 if (pf->drive == -1) { in pf_probe()
660 for (pf->drive = 0; pf->drive <= 1; pf->drive++) in pf_probe()
661 if (!pf_reset(pf)) { in pf_probe()
662 if (pf->lun != -1) in pf_probe()
663 return pf_identify(pf); in pf_probe()
665 for (pf->lun = 0; pf->lun < 8; pf->lun++) in pf_probe()
666 if (!pf_identify(pf)) in pf_probe()
670 if (pf_reset(pf)) in pf_probe()
672 if (pf->lun != -1) in pf_probe()
673 return pf_identify(pf); in pf_probe()
674 for (pf->lun = 0; pf->lun < 8; pf->lun++) in pf_probe()
675 if (!pf_identify(pf)) in pf_probe()
683 static int pf_start(struct pf_unit *pf, int cmd, int b, int c) in pf_start() argument
686 char io_cmd[12] = { cmd, pf->lun << 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; in pf_start()
696 i = pf_command(pf, io_cmd, c * 512, "start i/o"); in pf_start()
712 struct pf_unit *pf; in set_next_request() local
716 pf = &units[pf_queue]; in set_next_request()
719 if (pf->present && !list_empty(&pf->rq_list)) { in set_next_request()
720 pf_req = list_first_entry(&pf->rq_list, struct request, in set_next_request()
778 struct pf_unit *pf = hctx->queue->queuedata; in pf_queue_rq() local
781 list_add_tail(&bd->rq->queuelist, &pf->rq_list); in pf_queue_rq()
924 static int __init pf_init_unit(struct pf_unit *pf, bool autoprobe, int port, in pf_init_unit() argument
930 ret = blk_mq_alloc_sq_tag_set(&pf->tag_set, &pf_mq_ops, 1, in pf_init_unit()
935 disk = blk_mq_alloc_disk(&pf->tag_set, pf); in pf_init_unit()
941 disk->first_minor = pf - units; in pf_init_unit()
943 strcpy(disk->disk_name, pf->name); in pf_init_unit()
947 disk->private_data = pf; in pf_init_unit()
952 INIT_LIST_HEAD(&pf->rq_list); in pf_init_unit()
953 pf->disk = disk; in pf_init_unit()
954 pf->pi = &pf->pia; in pf_init_unit()
955 pf->media_status = PF_NM; in pf_init_unit()
956 pf->drive = (*drives[disk->first_minor])[D_SLV]; in pf_init_unit()
957 pf->lun = (*drives[disk->first_minor])[D_LUN]; in pf_init_unit()
958 snprintf(pf->name, PF_NAMELEN, "%s%d", name, disk->first_minor); in pf_init_unit()
960 if (!pi_init(pf->pi, autoprobe, port, mode, unit, protocol, delay, in pf_init_unit()
961 pf_scratch, PI_PF, verbose, pf->name)) { in pf_init_unit()
965 ret = pf_probe(pf); in pf_init_unit()
972 pf->present = 1; in pf_init_unit()
976 pi_release(pf->pi); in pf_init_unit()
978 put_disk(pf->disk); in pf_init_unit()
980 blk_mq_free_tag_set(&pf->tag_set); in pf_init_unit()
986 struct pf_unit *pf; in pf_init() local
1009 pf = units; in pf_init()
1011 if (pf_init_unit(pf, 1, -1, -1, -1, -1, -1, verbose)) in pf_init()
1014 for (unit = 0; unit < PF_UNITS; unit++, pf++) { in pf_init()
1018 if (pf_init_unit(pf, 0, conf[D_PRT], conf[D_MOD], in pf_init()
1040 struct pf_unit *pf; in pf_exit() local
1043 for (pf = units, unit = 0; unit < PF_UNITS; pf++, unit++) { in pf_exit()
1044 if (!pf->present) in pf_exit()
1046 del_gendisk(pf->disk); in pf_exit()
1047 put_disk(pf->disk); in pf_exit()
1048 blk_mq_free_tag_set(&pf->tag_set); in pf_exit()
1049 pi_release(pf->pi); in pf_exit()