Lines Matching refs:pf
245 static int pf_identify(struct pf_unit *pf);
246 static void pf_lock(struct pf_unit *pf, int func);
247 static void pf_eject(struct pf_unit *pf);
282 struct pf_unit *pf; in pf_init_units() local
286 for (unit = 0, pf = units; unit < PF_UNITS; unit++, pf++) { in pf_init_units()
290 pf->disk = disk; in pf_init_units()
291 pf->pi = &pf->pia; in pf_init_units()
292 pf->media_status = PF_NM; in pf_init_units()
293 pf->drive = (*drives[unit])[D_SLV]; in pf_init_units()
294 pf->lun = (*drives[unit])[D_LUN]; in pf_init_units()
295 snprintf(pf->name, PF_NAMELEN, "%s%d", name, unit); in pf_init_units()
298 strcpy(disk->disk_name, pf->name); in pf_init_units()
307 struct pf_unit *pf = bdev->bd_disk->private_data; in pf_open() local
311 pf_identify(pf); in pf_open()
314 if (pf->media_status == PF_NM) in pf_open()
318 if ((pf->media_status == PF_RO) && (mode & FMODE_WRITE)) in pf_open()
322 pf->access++; in pf_open()
323 if (pf->removable) in pf_open()
324 pf_lock(pf, 1); in pf_open()
332 struct pf_unit *pf = bdev->bd_disk->private_data; in pf_getgeo() local
333 sector_t capacity = get_capacity(pf->disk); in pf_getgeo()
350 struct pf_unit *pf = bdev->bd_disk->private_data; in pf_ioctl() local
355 if (pf->access != 1) in pf_ioctl()
358 pf_eject(pf); in pf_ioctl()
366 struct pf_unit *pf = disk->private_data; in pf_release() local
369 if (pf->access <= 0) { in pf_release()
375 pf->access--; in pf_release()
377 if (!pf->access && pf->removable) in pf_release()
378 pf_lock(pf, 0); in pf_release()
388 static inline int status_reg(struct pf_unit *pf) in status_reg() argument
390 return pi_read_regr(pf->pi, 1, 6); in status_reg()
393 static inline int read_reg(struct pf_unit *pf, int reg) in read_reg() argument
395 return pi_read_regr(pf->pi, 0, reg); in read_reg()
398 static inline void write_reg(struct pf_unit *pf, int reg, int val) in write_reg() argument
400 pi_write_regr(pf->pi, 0, reg, val); in write_reg()
403 static int pf_wait(struct pf_unit *pf, int go, int stop, char *fun, char *msg) in pf_wait() argument
408 while ((((r = status_reg(pf)) & go) || (stop && (!(r & stop)))) in pf_wait()
413 s = read_reg(pf, 7); in pf_wait()
414 e = read_reg(pf, 1); in pf_wait()
415 p = read_reg(pf, 2); in pf_wait()
421 pf->name, fun, msg, r, s, e, j, p); in pf_wait()
427 static int pf_command(struct pf_unit *pf, char *cmd, int dlen, char *fun) in pf_command() argument
429 pi_connect(pf->pi); in pf_command()
431 write_reg(pf, 6, 0xa0+0x10*pf->drive); in pf_command()
433 if (pf_wait(pf, STAT_BUSY | STAT_DRQ, 0, fun, "before command")) { in pf_command()
434 pi_disconnect(pf->pi); in pf_command()
438 write_reg(pf, 4, dlen % 256); in pf_command()
439 write_reg(pf, 5, dlen / 256); in pf_command()
440 write_reg(pf, 7, 0xa0); /* ATAPI packet command */ in pf_command()
442 if (pf_wait(pf, STAT_BUSY, STAT_DRQ, fun, "command DRQ")) { in pf_command()
443 pi_disconnect(pf->pi); in pf_command()
447 if (read_reg(pf, 2) != 1) { in pf_command()
448 printk("%s: %s: command phase error\n", pf->name, fun); in pf_command()
449 pi_disconnect(pf->pi); in pf_command()
453 pi_write_block(pf->pi, cmd, 12); in pf_command()
458 static int pf_completion(struct pf_unit *pf, char *buf, char *fun) in pf_completion() argument
462 r = pf_wait(pf, STAT_BUSY, STAT_DRQ | STAT_READY | STAT_ERR, in pf_completion()
465 if ((read_reg(pf, 2) & 2) && (read_reg(pf, 7) & STAT_DRQ)) { in pf_completion()
466 n = (((read_reg(pf, 4) + 256 * read_reg(pf, 5)) + in pf_completion()
468 pi_read_block(pf->pi, buf, n); in pf_completion()
471 s = pf_wait(pf, STAT_BUSY, STAT_READY | STAT_ERR, fun, "data done"); in pf_completion()
473 pi_disconnect(pf->pi); in pf_completion()
478 static void pf_req_sense(struct pf_unit *pf, int quiet) in pf_req_sense() argument
481 { ATAPI_REQ_SENSE, pf->lun << 5, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0 }; in pf_req_sense()
485 r = pf_command(pf, rs_cmd, 16, "Request sense"); in pf_req_sense()
488 pf_completion(pf, buf, "Request sense"); in pf_req_sense()
492 pf->name, buf[2] & 0xf, buf[12], buf[13]); in pf_req_sense()
495 static int pf_atapi(struct pf_unit *pf, char *cmd, int dlen, char *buf, char *fun) in pf_atapi() argument
499 r = pf_command(pf, cmd, dlen, fun); in pf_atapi()
502 r = pf_completion(pf, buf, fun); in pf_atapi()
504 pf_req_sense(pf, !fun); in pf_atapi()
509 static void pf_lock(struct pf_unit *pf, int func) in pf_lock() argument
511 char lo_cmd[12] = { ATAPI_LOCK, pf->lun << 5, 0, 0, func, 0, 0, 0, 0, 0, 0, 0 }; in pf_lock()
513 pf_atapi(pf, lo_cmd, 0, pf_scratch, func ? "lock" : "unlock"); in pf_lock()
516 static void pf_eject(struct pf_unit *pf) in pf_eject() argument
518 char ej_cmd[12] = { ATAPI_DOOR, pf->lun << 5, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0 }; in pf_eject()
520 pf_lock(pf, 0); in pf_eject()
521 pf_atapi(pf, ej_cmd, 0, pf_scratch, "eject"); in pf_eject()
536 static int pf_reset(struct pf_unit *pf) in pf_reset() argument
541 pi_connect(pf->pi); in pf_reset()
542 write_reg(pf, 6, 0xa0+0x10*pf->drive); in pf_reset()
543 write_reg(pf, 7, 8); in pf_reset()
548 while ((k++ < PF_RESET_TMO) && (status_reg(pf) & STAT_BUSY)) in pf_reset()
553 flg &= (read_reg(pf, i + 1) == expect[i]); in pf_reset()
556 printk("%s: Reset (%d) signature = ", pf->name, k); in pf_reset()
558 printk("%3x", read_reg(pf, i + 1)); in pf_reset()
564 pi_disconnect(pf->pi); in pf_reset()
568 static void pf_mode_sense(struct pf_unit *pf) in pf_mode_sense() argument
571 { ATAPI_MODE_SENSE, pf->lun << 5, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0 }; in pf_mode_sense()
574 pf_atapi(pf, ms_cmd, 8, buf, "mode sense"); in pf_mode_sense()
575 pf->media_status = PF_RW; in pf_mode_sense()
577 pf->media_status = PF_RO; in pf_mode_sense()
604 static void pf_get_capacity(struct pf_unit *pf) in pf_get_capacity() argument
606 char rc_cmd[12] = { ATAPI_CAPACITY, pf->lun << 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; in pf_get_capacity()
610 if (pf_atapi(pf, rc_cmd, 8, buf, "get capacity")) { in pf_get_capacity()
611 pf->media_status = PF_NM; in pf_get_capacity()
614 set_capacity(pf->disk, xl(buf, 0) + 1); in pf_get_capacity()
617 set_capacity(pf->disk, 0); in pf_get_capacity()
621 pf->name, pf->drive, pf->lun, bs); in pf_get_capacity()
625 static int pf_identify(struct pf_unit *pf) in pf_identify() argument
631 { ATAPI_IDENTIFY, pf->lun << 5, 0, 0, 36, 0, 0, 0, 0, 0, 0, 0 }; in pf_identify()
634 s = pf_atapi(pf, id_cmd, 36, buf, "identify"); in pf_identify()
642 pf->name, pf->drive, pf->lun, dt); in pf_identify()
649 pf->removable = (buf[1] & 0x80); in pf_identify()
651 pf_mode_sense(pf); in pf_identify()
652 pf_mode_sense(pf); in pf_identify()
653 pf_mode_sense(pf); in pf_identify()
655 pf_get_capacity(pf); in pf_identify()
658 pf->name, mf, id, ms[pf->drive], pf->lun, dt); in pf_identify()
659 if (pf->removable) in pf_identify()
661 if (pf->media_status == PF_NM) in pf_identify()
664 if (pf->media_status == PF_RO) in pf_identify()
667 (unsigned long long)get_capacity(pf->disk)); in pf_identify()
675 static int pf_probe(struct pf_unit *pf) in pf_probe() argument
677 if (pf->drive == -1) { in pf_probe()
678 for (pf->drive = 0; pf->drive <= 1; pf->drive++) in pf_probe()
679 if (!pf_reset(pf)) { in pf_probe()
680 if (pf->lun != -1) in pf_probe()
681 return pf_identify(pf); in pf_probe()
683 for (pf->lun = 0; pf->lun < 8; pf->lun++) in pf_probe()
684 if (!pf_identify(pf)) in pf_probe()
688 if (pf_reset(pf)) in pf_probe()
690 if (pf->lun != -1) in pf_probe()
691 return pf_identify(pf); in pf_probe()
692 for (pf->lun = 0; pf->lun < 8; pf->lun++) in pf_probe()
693 if (!pf_identify(pf)) in pf_probe()
701 struct pf_unit *pf = units; in pf_detect() local
714 if (pi_init(pf->pi, 1, -1, -1, -1, -1, -1, pf_scratch, PI_PF, in pf_detect()
715 verbose, pf->name)) { in pf_detect()
716 if (!pf_probe(pf) && pf->disk) { in pf_detect()
717 pf->present = 1; in pf_detect()
720 pi_release(pf->pi); in pf_detect()
724 for (unit = 0; unit < PF_UNITS; unit++, pf++) { in pf_detect()
728 if (pi_init(pf->pi, 0, conf[D_PRT], conf[D_MOD], in pf_detect()
730 pf_scratch, PI_PF, verbose, pf->name)) { in pf_detect()
731 if (pf->disk && !pf_probe(pf)) { in pf_detect()
732 pf->present = 1; in pf_detect()
735 pi_release(pf->pi); in pf_detect()
742 for (pf = units, unit = 0; unit < PF_UNITS; pf++, unit++) in pf_detect()
743 put_disk(pf->disk); in pf_detect()
750 static int pf_start(struct pf_unit *pf, int cmd, int b, int c) in pf_start() argument
753 char io_cmd[12] = { cmd, pf->lun << 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; in pf_start()
763 i = pf_command(pf, io_cmd, c * 512, "start i/o"); in pf_start()
958 struct pf_unit *pf; in pf_init() local
971 for (pf = units, unit = 0; unit < PF_UNITS; pf++, unit++) in pf_init()
972 put_disk(pf->disk); in pf_init()
978 for (pf = units, unit = 0; unit < PF_UNITS; pf++, unit++) in pf_init()
979 put_disk(pf->disk); in pf_init()
985 for (pf = units, unit = 0; unit < PF_UNITS; pf++, unit++) { in pf_init()
986 struct gendisk *disk = pf->disk; in pf_init()
988 if (!pf->present) in pf_init()
990 disk->private_data = pf; in pf_init()
999 struct pf_unit *pf; in pf_exit() local
1002 for (pf = units, unit = 0; unit < PF_UNITS; pf++, unit++) { in pf_exit()
1003 if (!pf->present) in pf_exit()
1005 del_gendisk(pf->disk); in pf_exit()
1006 put_disk(pf->disk); in pf_exit()
1007 pi_release(pf->pi); in pf_exit()