Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 | /* ppa.c -- low level driver for the IOMEGA PPA3 * parallel port SCSI host adapter. * * (The PPA3 is the embedded controller in the ZIP drive.) * * (c) 1995,1996 Grant R. Guenther, grant@torque.net, * under the terms of the GNU Public License. * */ /* This driver was developed without the benefit of any technical * specifications for the interface. Instead, a modified version of * DOSemu was used to monitor the protocol used by the DOS driver * for this adapter. I have no idea how my programming model relates * to IOMEGA's design. * * IOMEGA's driver does not generate linked commands. I've never * observed a SCSI message byte in the protocol transactions, so * I am assuming that as long as linked commands are not used * we won't see any. * * For more information, see the file drivers/scsi/README.ppa. * */ /* * this driver has been hacked by Matteo Frigo (athena@theory.lcs.mit.edu) * to support EPP and scatter-gather. [0.26-athena] * * additional hacks by David Campbell (campbell@tirian.che.curtin.edu.au) * in response to this driver "mis-behaving" on his machine. * Fixed EPP to handle "software" changing of EPP port data direction. * Chased down EPP timeouts * Made this driver "kernel version friendly" [0.28-athena] * * Really hacked it out of existance (David Campbell) * EPP timeouts no longer occur (yet better handling) * Probes known parallel ports * Autodetects EPP / ECP / PS2 / NIBBLE * Support for multiple devices (does anyone need this??) * [0.29-Curtin] * [ Stuff removed ] * * Modified PEDANTIC for less PEDANTIC drivers as people * were complaining about speed (I received a report indicating * that PEDANTIC is necessary for WinBond chipsets. * Updated config_ppa and Makefile * [0.36b-Curtin] * * First round of cleanups * Remove prior 1.3.34 kernel support * SMC support changed * ECP+EPP detection always invoked. * If compat mode => PS/2 * else ecp_sync() called (ECP+EPP uses FIFO). * Added routine to detect interrupt channel for ECP (not used) * Changed version numbering * 1 Major number * 00 Minor revision number * ALPHA Expected stability (alpha, beta, stable) * [Curtin-1-00-ALPHA] * Second round of cleanups * Clean up timer queues * Fixed problem with non-detection of PS/2 ports * SMC ECP+EPP confirmed to work, remove option from config_ppa * [Curtin-1-01-ALPHA] * * Parport hits with a vengance!! * Several internal revisions have been made with huge amounts of * fixes including: * ioport_2_hostno removed (unique_id is quicker) * SMC compat option is history * Driver name / info hardwired * Played with inlines and saved 4k on module * Parport support * Using PnP Parport allows use of printer attached to * ZIP drive. * Numerous fixups for device registration and to allow * proper aborts. * Version jumps a few numbers here - considered BETA * Shipping Parport with monolithic driver :) * [Curtin-1-05-BETA] * * Fixed code to ensure SCSI abort will release the SCSI command * if the driver is STILL trying to claim the parport (PNP ver) * Now I have to fix the lp driver then there will NEVER be a * problem. * Got around to doing the ppa_queuecommand() clean up * Fixed bug relating to SMC EPP+ECP and monolithic driver * [Curtin-1-06-BETA] * * Where did the ppa_setup() code disappear to ?? * Back in now... * Distribution of ppa now independent of parport (less work for me). * Also cleaned up the port detection to allow for variations on * IO aliasing (in an attempt to fix a few problems with some * machines...) * [Curtin-1-07-BETA] * * Rewrote detection code for monolithic driver and ported changes to * parport driver. Result is more stable detection of hardware and * better immunity to port aliasing (old XT cards). * Parport 0.16 (or better) is required for parport operation and * ECP+EPP modes, otherwise the latest parport edition is recommended. * * When using EPP and writing to disk CPU usage > 40%, while reading <10%. * This is due to ZIP drive IO scheduling, the drive does a verify after * write to ensure data integrity (removable media is ALWAYS questionable * since you never know where it has been). * Some fancy programing *MAY* fix the problem but at 30 Mb/min is just * over 10 sectors per jiffy. * * Hmm... I think I know a way but it will send the driver into * ALPHA state again. * [Curtin-1-08-STABLE] */ #include <linux/config.h> /* The following #define is to avoid a clash with hosts.c */ #define PPA_CODE 1 #include "ppa.h" /* batteries not included :-) */ /* * modes in which the driver can operate */ #define PPA_AUTODETECT 0 /* Autodetect mode */ #define PPA_NIBBLE 1 /* work in standard 4 bit mode */ #define PPA_PS2 2 /* PS/2 byte mode */ #define PPA_EPP_8 3 /* EPP mode, 8 bit */ #define PPA_EPP_16 4 /* EPP mode, 16 bit */ #define PPA_EPP_32 5 /* EPP mode, 32 bit */ #define PPA_UNKNOWN 6 /* Just in case... */ static char *PPA_MODE_STRING[] = { "Autodetect", "SPP", "PS/2", "EPP 8 bit", "EPP 16 bit", "EPP 32 bit", "Unknown"}; typedef struct { struct pardevice *dev; /* Parport device entry */ int speed; /* General PPA delay constant */ int speed_fast; /* Const for nibble/byte modes */ int epp_speed; /* Reset time period */ int mode; /* Transfer mode */ int timeout; /* Number of timeouts */ int host; /* Host number (for proc) */ int abort_flag; /* Abort flag */ int error_code; /* Error code */ int ppa_failed; /* Failure flag */ Scsi_Cmnd *cur_cmd; /* Current queued command */ void (*done) (Scsi_Cmnd *); /* Done func for queuecommand */ struct tq_struct ppa_tq; /* Polling interupt stuff */ struct wait_queue *ppa_wait_q; /* Used for PnP stuff */ } ppa_struct; static void ppa_interrupt(void *data); /* I know that this is a mess but it works!! */ #define NO_HOSTS 4 static ppa_struct ppa_hosts[NO_HOSTS] = { {0, 6, 1, CONFIG_SCSI_PPA_EPP_TIME, PPA_AUTODETECT, 0, -1, 0, DID_ERROR, 1, NULL, NULL, {0, 0, ppa_interrupt, NULL}, NULL}, {0, 6, 1, CONFIG_SCSI_PPA_EPP_TIME, PPA_AUTODETECT, 0, -1, 0, DID_ERROR, 1, NULL, NULL, {0, 0, ppa_interrupt, NULL}, NULL}, {0, 6, 1, CONFIG_SCSI_PPA_EPP_TIME, PPA_AUTODETECT, 0, -1, 0, DID_ERROR, 1, NULL, NULL, {0, 0, ppa_interrupt, NULL}, NULL}, {0, 6, 1, CONFIG_SCSI_PPA_EPP_TIME, PPA_AUTODETECT, 0, -1, 0, DID_ERROR, 1, NULL, NULL, {0, 0, ppa_interrupt, NULL}, NULL} }; /* This is a global option */ static int ppa_speed = -1; /* Set to >0 to act as a global value */ static int ppa_speed_fast = -1; /* ditto.. */ static int ppa_sg = SG_ALL; /* enable/disable scatter-gather. */ /* other options */ #define PPA_CAN_QUEUE 1 /* use "queueing" interface */ #define PPA_BURST_SIZE 512 /* block size for bulk transfers */ #define PPA_SELECT_TMO 5000 /* how long to wait for target ? */ #define PPA_SPIN_TMO 500000 /* ppa_wait loop limiter */ #define IN_EPP_MODE(x) (x == PPA_EPP_8 || x == PPA_EPP_16 || x == PPA_EPP_32) /* args to ppa_connect */ #define CONNECT_EPP_MAYBE 1 #define CONNECT_NORMAL 0 #define PPA_BASE(x) ppa_hosts[(x)].dev->port->base /* Port IO - Sorry Grant but I prefer the following symbols */ #define r_dtr(x) inb(PPA_BASE(x)) #define r_str(x) inb(PPA_BASE(x)+1) #define r_ctr(x) inb(PPA_BASE(x)+2) #define r_epp(x) inb(PPA_BASE(x)+4) #define r_fifo(x) inb(PPA_BASE(x)+0x400) #define r_ecr(x) inb(PPA_BASE(x)+0x402) #define w_dtr(x,y) outb(y, PPA_BASE(x)) #define w_str(x,y) outb(y, PPA_BASE(x)+1) #define w_ctr(x,y) outb(y, PPA_BASE(x)+2);\ udelay( ppa_hosts[(x)].speed) #define w_epp(x,y) outb(y, PPA_BASE(x)+4) #define w_fifo(x,y) outb(y, PPA_BASE(x)+0x400) #define w_ecr(x,y) outb(y, PPA_BASE(x)+0x402) static void ppa_wakeup(void *ref) { ppa_struct *ppa_dev = (ppa_struct *) ref; if (!ppa_dev->ppa_wait_q) return; /* Wake up whom ? */ /* Claim the Parport */ if (parport_claim(ppa_dev->dev)) return; /* Shouldn't happen */ wake_up(&ppa_dev->ppa_wait_q); return; } static int ppa_release(struct Scsi_Host *host) { int host_no = host->unique_id; printk("Releasing ppa%i\n", host_no); parport_unregister_device(ppa_hosts[host_no].dev); return 0; } static int ppa_pb_claim(int host_no) { if (parport_claim(ppa_hosts[host_no].dev)) { sleep_on(&ppa_hosts[host_no].ppa_wait_q); ppa_hosts[host_no].ppa_wait_q = NULL; /* Check to see if we were aborted or reset */ if (ppa_hosts[host_no].dev->port->cad != ppa_hosts[host_no].dev) { printk("Abort detected on ppa%i\n", host_no); return 1; } } return 0; } static void ppa_pb_release(int host_no) { parport_release(ppa_hosts[host_no].dev); } /* Placed here so everyone knows what ecp_sync does.. */ static void ecp_sync(int host_no) { int i, r; r = r_ecr(host_no); if ((r & 0xe0) != 0x80) return; for (i = 0; i < 100; i++) { r = r_ecr(host_no); if (r & 0x01) return; udelay(5); } printk("ppa: ECP sync failed as data still present in FIFO.\n"); } static inline void ppa_d_pulse(int host_no, char b) { w_dtr(host_no, b); w_ctr(host_no, 0xc); w_ctr(host_no, 0xe); w_ctr(host_no, 0xc); w_ctr(host_no, 0x4); w_ctr(host_no, 0xc); } static void ppa_disconnect(int host_no) { ppa_d_pulse(host_no, 0); ppa_d_pulse(host_no, 0x3c); ppa_d_pulse(host_no, 0x20); ppa_d_pulse(host_no, 0xf); ppa_pb_release(host_no); } static inline void ppa_c_pulse(int host_no, char b) { w_dtr(host_no, b); w_ctr(host_no, 0x4); w_ctr(host_no, 0x6); w_ctr(host_no, 0x4); w_ctr(host_no, 0xc); } static int ppa_connect(int host_no, int flag) { int retv = ppa_pb_claim(host_no); ppa_c_pulse(host_no, 0); ppa_c_pulse(host_no, 0x3c); ppa_c_pulse(host_no, 0x20); if ((flag == CONNECT_EPP_MAYBE) && IN_EPP_MODE(ppa_hosts[host_no].mode)) ppa_c_pulse(host_no, 0xcf); else ppa_c_pulse(host_no, 0x8f); return retv; } static void ppa_do_reset(int host_no) { /* * SCSI reset taken from ppa_init and checked with * Iomega document that Grant has (via email :( */ ppa_pb_claim(host_no); ppa_disconnect(host_no); ppa_connect(host_no, CONNECT_NORMAL); w_ctr(host_no, 0x6); w_ctr(host_no, 0x4); w_dtr(host_no, 0x40); w_ctr(host_no, 0x8); udelay(50); w_ctr(host_no, 0xc); ppa_disconnect(host_no); } static char ppa_select(int host_no, int initiator, int target) { char r; int k; r = r_str(host_no); /* TODO */ w_dtr(host_no, (1 << target)); w_ctr(host_no, 0xe); w_ctr(host_no, 0xc); w_dtr(host_no, (1 << initiator)); w_ctr(host_no, 0x8); k = 0; while (!(r = (r_str(host_no) & 0xf0)) && (k++ < PPA_SELECT_TMO)) barrier(); if (k >= PPA_SELECT_TMO) return 0; return r; } static void ppa_fail(int host_no, int error_code) { ppa_hosts[host_no].error_code = error_code; ppa_hosts[host_no].ppa_failed = 1; ppa_disconnect(host_no); } /* * Wait for the high bit to be set. * * In principle, this could be tied to an interrupt, but the adapter * doesn't appear to be designed to support interrupts. We spin on * the 0x80 ready bit. */ static char ppa_wait(int host_no) { int k; char r; k = 0; while (!((r = r_str(host_no)) & 0x80) && (k++ < PPA_SPIN_TMO) && !ppa_hosts[host_no].abort_flag) barrier(); /* check if we were interrupted */ if (ppa_hosts[host_no].abort_flag) { if (ppa_hosts[host_no].abort_flag == 1) ppa_fail(host_no, DID_ABORT); else { ppa_do_reset(host_no); ppa_fail(host_no, DID_RESET); } return 0; } /* check if timed out */ if (k >= PPA_SPIN_TMO) { ppa_fail(host_no, DID_TIME_OUT); return 0; /* command timed out */ } /* * return some status information. * Semantics: 0xc0 = ZIP wants more data * 0xd0 = ZIP wants to send more data * 0xf0 = end of transfer, ZIP is sending status */ return (r & 0xf0); } /* * This is based on a trace of what the Iomega DOS 'guest' driver does. * I've tried several different kinds of parallel ports with guest and * coded this to react in the same ways that it does. * * The return value from this function is just a hint about where the * handshaking failed. * */ static int ppa_init(int host_no) { if (ppa_pb_claim(host_no)) return 1; ppa_disconnect(host_no); ppa_connect(host_no, CONNECT_NORMAL); w_ctr(host_no, 0x6); if ((r_str(host_no) & 0xf0) != 0xf0) { ppa_pb_release(host_no); return 2; } w_ctr(host_no, 0x4); if ((r_str(host_no) & 0xf0) != 0x80) { ppa_pb_release(host_no); return 3; } /* This is a SCSI reset signal */ w_dtr(host_no, 0x40); w_ctr(host_no, 0x8); udelay(50); w_ctr(host_no, 0xc); ppa_disconnect(host_no); return 0; } /* * check the epp status. After a EPP transfer, it should be true that * 1) the TIMEOUT bit (SPP_STR.0) is clear * 2) the READY bit (SPP_STR.7) is set */ static int ppa_check_epp_status(int host_no) { char r; r = r_str(host_no); if (r & 1) { /* EPP timeout, according to the PC87332 manual */ /* Semantics of clearing EPP timeout bit. * PC87332 - reading SPP_STR does it... * SMC - write 1 to EPP timeout bit * Others - (???) write 0 to EPP timeout bit */ w_str(host_no, r); w_str(host_no, r & 0xfe); ppa_hosts[host_no].timeout++; printk("PPA: EPP timeout on port 0x%04x\n", PPA_BASE(host_no)); ppa_fail(host_no, DID_BUS_BUSY); return 0; } if (!(r & 0x80)) { ppa_fail(host_no, DID_ERROR); return 0; } return 1; } static inline int ppa_force_epp_byte(int host_no, char x) { /* This routine forces a byte down the EPP data port whether the * device is ready or not... */ char r; w_epp(host_no, x); r = r_str(host_no); if (!(r & 1)) return 1; if (ppa_hosts[host_no].epp_speed > 0) { /* EPP timeout, according to the PC87332 manual */ /* Semantics of clearing EPP timeout bit. * PC87332 - reading SPP_STR does it... * SMC - write 1 to EPP timeout bit * Others - (???) write 0 to EPP timeout bit */ w_str(host_no, r); w_str(host_no, r & 0xfe); /* Take a deep breath, count to 10 and then... */ udelay(ppa_hosts[host_no].epp_speed); /* Second time around */ w_epp(host_no, x); r = r_str(host_no); } if (r & 1) { w_str(host_no, r); w_str(host_no, r & 0xfe); ppa_hosts[host_no].timeout++; printk("PPA: warning: EPP timeout\n"); ppa_fail(host_no, DID_BUS_BUSY); return 0; } else return 1; } static inline int ppa_send_command_epp(Scsi_Cmnd * cmd) { int host_no = cmd->host->unique_id; int k; w_ctr(host_no, 0x4); for (k = 0; k < cmd->cmd_len; k++) { /* send the command */ if (!ppa_force_epp_byte(host_no, cmd->cmnd[k])) return 0; } w_ctr(host_no, 0xc); ecp_sync(host_no); return 1; } static inline int ppa_send_command_normal(Scsi_Cmnd * cmd) { int host_no = cmd->host->unique_id; int k; w_ctr(host_no, 0xc); for (k = 0; k < cmd->cmd_len; k++) { /* send the command */ if (!ppa_wait(host_no)) return 0; w_dtr(host_no, cmd->cmnd[k]); w_ctr(host_no, 0xe); w_ctr(host_no, 0xc); } return 1; } static int ppa_start(Scsi_Cmnd * cmd) { int host_no = cmd->host->unique_id; /* * by default, the command failed, * unless explicitly completed in ppa_completion(). */ ppa_hosts[host_no].error_code = DID_ERROR; ppa_hosts[host_no].abort_flag = 0; ppa_hosts[host_no].ppa_failed = 0; if (cmd->target == PPA_INITIATOR) { ppa_hosts[host_no].error_code = DID_BAD_TARGET; ppa_hosts[host_no].ppa_failed = 1; return 0; } if (ppa_connect(host_no, CONNECT_EPP_MAYBE)) return 0; if (!ppa_select(host_no, PPA_INITIATOR, cmd->target)) { ppa_fail(host_no, DID_NO_CONNECT); return 0; } if (IN_EPP_MODE(ppa_hosts[host_no].mode)) return ppa_send_command_epp(cmd); else return ppa_send_command_normal(cmd); } /* * output a string, in whatever mode is available, according to the * PPA protocol. */ static inline int ppa_outs(int host_no, char *buffer, int len) { int k; #if CONFIG_SCSI_PPA_HAVE_PEDANTIC > 0 int r; #endif switch (ppa_hosts[host_no].mode) { case PPA_NIBBLE: case PPA_PS2: /* 8 bit output, with a loop */ for (k = len; k; k--) { w_dtr(host_no, *buffer++); w_ctr(host_no, 0xe); w_ctr(host_no, 0xc); } return 1; /* assume transfer went OK */ #if CONFIG_SCSI_PPA_HAVE_PEDANTIC > 0 case PPA_EPP_32: #if CONFIG_SCSI_PPA_HAVE_PEDANTIC < 2 w_ctr(host_no, 0x4); for (k = len; k; k -= 4) { w_epp(host_no, *buffer++); w_epp(host_no, *buffer++); w_epp(host_no, *buffer++); w_epp(host_no, *buffer++); r = ppa_check_epp_status(host_no); if (!r) return r; } w_ctr(host_no, 0xc); ecp_sync(host_no); return 1; #endif case PPA_EPP_16: #if CONFIG_SCSI_PPA_HAVE_PEDANTIC < 3 w_ctr(host_no, 0x4); for (k = len; k; k -= 2) { w_epp(host_no, *buffer++); w_epp(host_no, *buffer++); r = ppa_check_epp_status(host_no); if (!r) return r; } w_ctr(host_no, 0xc); ecp_sync(host_no); return 1; #endif case PPA_EPP_8: w_ctr(host_no, 0x4); for (k = len; k; k--) { w_epp(host_no, *buffer++); r = ppa_check_epp_status(host_no); if (!r) return r; } w_ctr(host_no, 0xc); ecp_sync(host_no); return 1; #else case PPA_EPP_32: case PPA_EPP_16: case PPA_EPP_8: w_ctr(host_no, 0x4); switch (ppa_hosts[host_no].mode) { case PPA_EPP_8: outsb(PPA_BASE(host_no) + 0x04, buffer, len); break; case PPA_EPP_16: outsw(PPA_BASE(host_no) + 0x04, buffer, len / 2); break; case PPA_EPP_32: outsl(PPA_BASE(host_no) + 0x04, buffer, len / 4); break; } k = ppa_check_epp_status(host_no); w_ctr(host_no, 0xc); ecp_sync(host_no); return k; #endif default: printk("PPA: bug in ppa_outs()\n"); } return 0; } static inline int ppa_outb(int host_no, char d) { int k; switch (ppa_hosts[host_no].mode) { case PPA_NIBBLE: case PPA_PS2: w_dtr(host_no, d); w_ctr(host_no, 0xe); w_ctr(host_no, 0xc); return 1; /* assume transfer went OK */ case PPA_EPP_8: case PPA_EPP_16: case PPA_EPP_32: w_ctr(host_no, 0x4); w_epp(host_no, d); k = ppa_check_epp_status(host_no); w_ctr(host_no, 0xc); ecp_sync(host_no); return k; default: printk("PPA: bug in ppa_outb()\n"); } return 0; } static inline int ppa_ins(int host_no, char *buffer, int len) { int k, h, l; #if CONFIG_SCSI_PPA_HAVE_PEDANTIC > 0 int r; #endif switch (ppa_hosts[host_no].mode) { case PPA_NIBBLE: /* 4 bit input, with a loop */ for (k = len; k; k--) { w_ctr(host_no, 0x4); h = r_str(host_no); w_ctr(host_no, 0x6); l = r_str(host_no); *buffer++ = ((l >> 4) & 0x0f) + (h & 0xf0); } w_ctr(host_no, 0xc); return 1; /* assume transfer went OK */ case PPA_PS2: /* 8 bit input, with a loop */ for (k = len; k; k--) { w_ctr(host_no, 0x25); *buffer++ = r_dtr(host_no); w_ctr(host_no, 0x27); } w_ctr(host_no, 0x5); w_ctr(host_no, 0x4); w_ctr(host_no, 0xc); return 1; /* assume transfer went OK */ #if CONFIG_SCSI_PPA_HAVE_PEDANTIC > 0 case PPA_EPP_32: #if CONFIG_SCSI_PPA_HAVE_PEDANTIC < 2 w_ctr(host_no, 0x24); for (k = len; k; k -= 4) { *buffer++ = r_epp(host_no); *buffer++ = r_epp(host_no); *buffer++ = r_epp(host_no); *buffer++ = r_epp(host_no); r = ppa_check_epp_status(host_no); if (!r) return r; } w_ctr(host_no, 0x2c); ecp_sync(host_no); return 1; #endif case PPA_EPP_16: #if CONFIG_SCSI_PPA_HAVE_PEDANTIC < 3 w_ctr(host_no, 0x24); for (k = len; k; k -= 2) { *buffer++ = r_epp(host_no); *buffer++ = r_epp(host_no); r = ppa_check_epp_status(host_no); if (!r) return r; } w_ctr(host_no, 0x2c); ecp_sync(host_no); return 1; #endif case PPA_EPP_8: w_ctr(host_no, 0x24); for (k = len; k; k--) { *buffer++ = r_epp(host_no); r = ppa_check_epp_status(host_no); if (!r) return r; } w_ctr(host_no, 0x2c); ecp_sync(host_no); return 1; break; #else case PPA_EPP_8: case PPA_EPP_16: case PPA_EPP_32: w_ctr(host_no, 0x24); switch (ppa_hosts[host_no].mode) { case PPA_EPP_8: insb(PPA_BASE(host_no) + 0x04, buffer, len); break; case PPA_EPP_16: insw(PPA_BASE(host_no) + 0x04, buffer, len / 2); break; case PPA_EPP_32: insl(PPA_BASE(host_no) + 0x04, buffer, len / 4); break; } k = ppa_check_epp_status(host_no); w_ctr(host_no, 0x2c); ecp_sync(host_no); return k; #endif default: printk("PPA: bug in ppa_ins()\n"); } return 0; } static int ppa_inb(int host_no, char *buffer) { int h, l, k; switch (ppa_hosts[host_no].mode) { case PPA_NIBBLE: /* 4 bit input */ w_ctr(host_no, 0x4); h = r_str(host_no); w_ctr(host_no, 0x6); l = r_str(host_no); *buffer = ((l >> 4) & 0x0f) + (h & 0xf0); w_ctr(host_no, 0xc); return 1; /* assume transfer went OK */ case PPA_PS2: /* 8 bit input */ w_ctr(host_no, 0x25); *buffer++ = r_dtr(host_no); w_ctr(host_no, 0x27); w_ctr(host_no, 0x5); w_ctr(host_no, 0x4); w_ctr(host_no, 0xc); return 1; /* assume transfer went OK */ case PPA_EPP_8: case PPA_EPP_16: case PPA_EPP_32: w_ctr(host_no, 0x24); *buffer = r_epp(host_no); k = ppa_check_epp_status(host_no); w_ctr(host_no, 0xc); ecp_sync(host_no); return k; default: printk("PPA: bug in ppa_inb()\n"); } return 0; } /* * The bulk flag enables some optimisations in the data transfer loops, * it should be true for any command that transfers data in integral * numbers of sectors. * * The driver appears to remain stable if we speed up the parallel port * i/o in this function, but not elsewhere. */ static int ppa_completion(Scsi_Cmnd * cmd) { int host_no = cmd->host->unique_id; char r, l, h, v; int dir, cnt, blen, fast, bulk, status; char *buffer; struct scatterlist *sl; int current_segment, nsegment; v = cmd->cmnd[0]; bulk = ((v == READ_6) || (v == READ_10) || (v == WRITE_6) || (v == WRITE_10)); /* code for scatter/gather: */ if (cmd->use_sg) { /* if many buffers are available, start filling the first */ sl = (struct scatterlist *) cmd->request_buffer; blen = sl->length; buffer = sl->address; } else { /* else fill the only available buffer */ sl = NULL; buffer = cmd->request_buffer; blen = cmd->request_bufflen; } current_segment = 0; nsegment = cmd->use_sg; cnt = 0; /* detect transfer direction */ dir = 0; if (!(r = ppa_wait(host_no))) return 0; if (r == (char) 0xc0) dir = 1; /* d0 = read c0 = write f0 = status */ while (r != (char) 0xf0) { if (((r & 0xc0) != 0xc0) || (cnt >= blen)) { ppa_fail(host_no, DID_ERROR); return 0; } /* determine if we should use burst I/O */ fast = (bulk && ((blen - cnt) >= PPA_BURST_SIZE) && ((((long)buffer + cnt)) & 0x3) == 0); if (fast) { if (dir) status = ppa_outs(host_no, &buffer[cnt], PPA_BURST_SIZE); else status = ppa_ins(host_no, &buffer[cnt], PPA_BURST_SIZE); cnt += PPA_BURST_SIZE; } else { if (dir) status = ppa_outb(host_no, buffer[cnt]); else status = ppa_inb(host_no, &buffer[cnt]); cnt++; } if (!status || !(r = ppa_wait(host_no))) return 0; if (sl && cnt == blen) { /* if scatter/gather, advance to the next segment */ if (++current_segment < nsegment) { ++sl; blen = sl->length; buffer = sl->address; cnt = 0; } /* * the else case will be captured by the (cnt >= blen) * test above. */ } } /* read status and message bytes */ if (!ppa_inb(host_no, &l)) /* read status byte */ return 0; if (!(ppa_wait(host_no))) return 0; if (!ppa_inb(host_no, &h)) /* read message byte */ return 0; ppa_disconnect(host_no); ppa_hosts[host_no].error_code = DID_OK; return (h << 8) | (l & STATUS_MASK); } /* deprecated synchronous interface */ int ppa_command(Scsi_Cmnd * cmd) { int host_no = cmd->host->unique_id; int s; sti(); s = 0; if (ppa_start(cmd)) if (ppa_wait(host_no)) s = ppa_completion(cmd); return s + (ppa_hosts[host_no].error_code << 16); } /* pseudo-interrupt queueing interface */ /* * Since the PPA itself doesn't generate interrupts, we use * the scheduler's task queue to generate a stream of call-backs and * complete the request when the drive is ready. */ static void ppa_interrupt(void *data) { ppa_struct *tmp = (ppa_struct *) data; Scsi_Cmnd *cmd = tmp->cur_cmd; void (*done) (Scsi_Cmnd *) = tmp->done; int host_no = cmd->host->unique_id; if (!cmd) { printk("PPA: bug in ppa_interrupt\n"); return; } /* First check for any errors that may of occured * Here we check for internal errors */ if (tmp->ppa_failed) { printk("PPA: ppa_failed bug: ppa_error_code = %d\n", tmp->error_code); cmd->result = DID_ERROR << 16; tmp->cur_cmd = 0; done(cmd); return; } /* Occasionally the mid level driver will abort a SCSI * command because we are taking to long, if this occurs * we should abort the command. */ if (tmp->abort_flag) { ppa_disconnect(host_no); if (tmp->abort_flag == 1) cmd->result = DID_ABORT << 16; else { ppa_do_reset(host_no); cmd->result = DID_RESET << 16; } tmp->cur_cmd = 0; done(cmd); return; } /* Check to see if the device is now free, if not * then throw this function onto the scheduler queue * to be called back in a jiffy. * (i386: 1 jiffy = 0.01 seconds) */ if (!(r_str(host_no) & 0x80)) { tmp->ppa_tq.data = (void *) tmp; queue_task(&tmp->ppa_tq, &tq_scheduler); return; } /* Device is now free and no errors have occured so * it is safe to do the data phase */ cmd->result = ppa_completion(cmd) + (tmp->error_code << 16); tmp->cur_cmd = 0; done(cmd); return; } int ppa_queuecommand(Scsi_Cmnd * cmd, void (*done) (Scsi_Cmnd *)) { int host_no = cmd->host->unique_id; if (ppa_hosts[host_no].cur_cmd) { printk("PPA: bug in ppa_queuecommand\n"); return 0; } sti(); ppa_hosts[host_no].cur_cmd = cmd; ppa_hosts[host_no].done = done; if (!ppa_start(cmd)) { cmd->result = ppa_hosts[host_no].error_code << 16; ppa_hosts[host_no].cur_cmd = 0; done(cmd); return 0; } ppa_interrupt(ppa_hosts + host_no); return 0; } /* * Apparently the the disk->capacity attribute is off by 1 sector * for all disk drives. We add the one here, but it should really * be done in sd.c. Even if it gets fixed there, this will still * work. */ int ppa_biosparam(Disk * disk, kdev_t dev, int ip[]) { ip[0] = 0x40; ip[1] = 0x20; ip[2] = (disk->capacity + 1) / (ip[0] * ip[1]); if (ip[2] > 1024) { ip[0] = 0xff; ip[1] = 0x3f; ip[2] = (disk->capacity + 1) / (ip[0] * ip[1]); if (ip[2] > 1023) ip[2] = 1023; } return 0; } int ppa_abort(Scsi_Cmnd * cmd) { int host_no = cmd->host->unique_id; ppa_hosts[host_no].abort_flag = 1; ppa_hosts[host_no].error_code = DID_ABORT; if (ppa_hosts[host_no].ppa_wait_q) wake_up(&ppa_hosts[host_no].ppa_wait_q); return SCSI_ABORT_SNOOZE; } int ppa_reset(Scsi_Cmnd * cmd, unsigned int x) { int host_no = cmd->host->unique_id; ppa_hosts[host_no].abort_flag = 2; ppa_hosts[host_no].error_code = DID_RESET; if (ppa_hosts[host_no].ppa_wait_q) wake_up(&ppa_hosts[host_no].ppa_wait_q); return SCSI_RESET_PUNT; } /*************************************************************************** * Parallel port probing routines * ***************************************************************************/ #ifdef MODULE Scsi_Host_Template driver_template = PPA; #include "scsi_module.c" #endif /* * Start of Chipset kludges */ int ppa_detect(Scsi_Host_Template * host) { struct Scsi_Host *hreg; int rs; int ports; int i, nhosts; struct parport *pb = parport_enumerate(); printk("PPA driver version: %s\n", PPA_VERSION); nhosts = 0; for (i = 0; pb; i++, pb=pb->next) { int modes = pb->modes; /* We only understand PC-style ports */ if (modes & PARPORT_MODE_PCSPP) { /* transfer global values here */ if (ppa_speed >= 0) ppa_hosts[i].speed = ppa_speed; if (ppa_speed_fast >= 0) ppa_hosts[i].speed_fast = ppa_speed_fast; ppa_hosts[i].dev = parport_register_device(pb, "ppa", NULL, ppa_wakeup, NULL, PARPORT_DEV_TRAN, (void *) &ppa_hosts[i]); /* Claim the bus so it remembers what we do to the * control registers. [ CTR and ECP ] */ ppa_pb_claim(i); w_ctr(i, 0x0c); ppa_hosts[i].mode = PPA_NIBBLE; if (modes & (PARPORT_MODE_PCEPP | PARPORT_MODE_PCECPEPP)) { ppa_hosts[i].mode = PPA_EPP_32; printk("PPA: Parport [ PCEPP ]\n"); } else if (modes & PARPORT_MODE_PCECP) { w_ecr(i, 0x20); ppa_hosts[i].mode = PPA_PS2; printk("PPA: Parport [ PCECP in PS2 submode ]\n"); } else if (modes & PARPORT_MODE_PCPS2) { ppa_hosts[i].mode = PPA_PS2; printk("PPA: Parport [ PCPS2 ]\n"); } /* Done configuration */ ppa_pb_release(i); rs = ppa_init(i); if (rs) { parport_unregister_device(ppa_hosts[i].dev); continue; } /* now the glue ... */ switch (ppa_hosts[i].mode) { case PPA_NIBBLE: case PPA_PS2: ports = 3; break; case PPA_EPP_8: case PPA_EPP_16: case PPA_EPP_32: ports = 8; break; default: /* Never gets here */ continue; } host->can_queue = PPA_CAN_QUEUE; host->sg_tablesize = ppa_sg; hreg = scsi_register(host, 0); hreg->io_port = pb->base; hreg->n_io_port = ports; hreg->dma_channel = -1; hreg->unique_id = i; ppa_hosts[i].host = hreg->host_no; nhosts++; } } if (nhosts == 0) return 0; else return 1; /* return number of hosts detected */ } /* This is to give the ppa driver a way to modify the timings (and other * parameters) by writing to the /proc/scsi/ppa/0 file. * Very simple method really... (To simple, no error checking :( ) * Reason: Kernel hackers HATE having to unload and reload modules for * testing... * Also gives a method to use a script to obtain optimum timings (TODO) */ static int ppa_strncmp(const char *a, const char *b, int len) { int loop; for (loop = 0; loop < len; loop++) if (a[loop] != b[loop]) return 1; return 0; } static int ppa_proc_write(int hostno, char *buffer, int length) { unsigned long x; const char *inv_num = "ppa /proc entry passed invalid number\n"; if ((length > 15) && (ppa_strncmp(buffer, "ppa_speed_fast=", 15) == 0)) { x = simple_strtoul(buffer + 15, NULL, 0); if (x <= ppa_hosts[hostno].speed) ppa_hosts[hostno].speed_fast = x; else printk(inv_num); return length; } if ((length > 10) && (ppa_strncmp(buffer, "ppa_speed=", 10) == 0)) { x = simple_strtoul(buffer + 10, NULL, 0); if (x >= ppa_hosts[hostno].speed_fast) ppa_hosts[hostno].speed = x; else printk(inv_num); return length; } if ((length > 10) && (ppa_strncmp(buffer, "epp_speed=", 10) == 0)) { x = simple_strtoul(buffer + 10, NULL, 0); ppa_hosts[hostno].epp_speed = x; return length; } if ((length > 12) && (ppa_strncmp(buffer, "epp_timeout=", 12) == 0)) { x = simple_strtoul(buffer + 12, NULL, 0); ppa_hosts[hostno].timeout = x; return length; } if ((length > 5) && (ppa_strncmp(buffer, "mode=", 5) == 0)) { x = simple_strtoul(buffer + 5, NULL, 0); ppa_hosts[hostno].mode = x; return length; } printk("ppa /proc: invalid variable\n"); return (-EINVAL); } int ppa_proc_info(char *buffer, char **start, off_t offset, int length, int hostno, int inout) { int i; int size, len = 0; off_t begin = 0; off_t pos = 0; for (i = 0; i < 4; i++) if (ppa_hosts[i].host == hostno) break; if (inout) return ppa_proc_write(i, buffer, length); size = sprintf(buffer + len, "Version : %s\n", PPA_VERSION); len += size; pos = begin + len; size = sprintf(buffer + len, "Parport : %s\n", ppa_hosts[i].dev->port->name); len += size; pos = begin + len; size = sprintf(buffer + len, "Mode : %s\n", PPA_MODE_STRING[ppa_hosts[i].mode]); len += size; pos = begin + len; size = sprintf(buffer + len, "\nTiming Parameters\n"); len += size; pos = begin + len; size = sprintf(buffer + len, "ppa_speed %i\n", ppa_hosts[i].speed); len += size; pos = begin + len; size = sprintf(buffer + len, "ppa_speed_fast %i\n", ppa_hosts[i].speed_fast); len += size; pos = begin + len; if (IN_EPP_MODE(ppa_hosts[i].mode)) { size = sprintf(buffer + len, "epp_speed %i\n", ppa_hosts[i].epp_speed); len += size; pos = begin + len; size = sprintf(buffer + len, "\nInternal Counters\n"); len += size; pos = begin + len; size = sprintf(buffer + len, "epp_timeout %i\n", ppa_hosts[i].timeout); len += size; pos = begin + len; } *start = buffer + (offset + begin); len -= (offset - begin); if (len > length) len = length; return len; } /* end of ppa.c */ |